00001
00005
00006
00007 #ifndef FBwFieldsH
00008 #define FBwFieldsH
00009 #include <ibase.h>
00010 #include <string>
00011 #include <FBwError.h>
00012 #include <FBwConect.h>
00013 #include <FBwDPB.h>
00014 #include <FBwTransac.h>
00015 #include <FBwBlob.h>
00016 #include <FBwDate.h>
00017
00018
00019
00021 namespace fbwrap
00022 {
00023
00024
00025 using std::string;
00026
00027
00028 class FBwDb;
00029 class FieldList;
00030 class FBwDateField;
00031 class FBwTimeField;
00032 class FBwDateTimeField;
00033
00035
00037 enum FBwFieldKind {
00038 masf_string,
00039 masf_short,
00040 masf_int,
00041 masf_int64,
00042 masf_double,
00043 masf_date,
00044 masf_time,
00045 masf_datetime,
00046 masf_currency,
00047 masf_blob,
00048 masf_array,
00049 masf_float,
00050 masf_exact16,
00051 masf_exact32,
00052 masf_exact64
00053 };
00054
00056
00057 {
00058 FBwFieldKind kind;
00059 string name;
00060 protected:
00061 short nullvalue;
00062 short scale;
00063 short sqltype;
00064 short sqllen;
00065 short subtype;
00066 bool hasnull;
00067 bool asigned;
00068
00069 virtual void *GetPtr()
00070 {
00071 return NULL;
00072 }
00074 virtual void BindPtr(char **p)
00075 {
00076 *p=NULL;
00077 }
00078 virtual void BindNullPtr(short **p)
00079 {
00080 *p=&nullvalue;
00081 hasnull=true;
00082 }
00083 virtual void bCopy(const FBwField *f);
00084 void LeftTrim(string &s);
00086
00090 virtual int ByteSize() const
00091 {
00092 return 0;
00093 }
00094 string dspformat;
00095
00096 public:
00098
00102 FBwField(string pname, FBwFieldKind pKind );
00104 FBwField(const FBwField &f);
00105 FBwField(const FBwField &f,FBwFieldKind pKind);
00106
00108 virtual string AsString() const
00109 {
00110 return "";
00111 }
00113
00116 virtual std::ostream &DisplayText(std::ostream &o) const
00117 {
00118 o << AsString();
00119 return o;
00120 }
00122 void SetName(const string &s)
00123 {
00124 name=s;
00125 LeftTrim(name);
00126 }
00127
00128 string Name() const
00129 {
00130 return name;
00131 }
00132 virtual bool IsNumeric() const;
00133 virtual bool IsDate() const
00134 {
00135 return false;
00136 }
00137 bool HasNull() const
00138 {
00139 return hasnull;
00140 }
00141
00143
00144 {
00145 return nullvalue==-1;
00146 }
00147 virtual double AsDouble() const;
00148 virtual short AsShort() const;
00149 virtual long AsInteger() const;
00150
00151 virtual long long int AsLongInteger() const;
00152 virtual FBwDate AsDate() const;
00153 virtual FBwTime AsTime() const;
00154 virtual FBwDateTime AsDateTime() const;
00155
00157
00158 { }
00160 virtual void SetAsDouble(double val)
00161 { }
00163 virtual void SetAsShort(short val)
00164 { }
00166 virtual void SetAsDate(const FBwDate &d)
00167 { }
00169 virtual void SetAsTime(const FBwTime &d)
00170 { }
00172 virtual void SetAsDateTime(const FBwDateTime &d)
00173 { }
00175 virtual void SetAsInteger(long val)
00176 { }
00178 virtual void SetAsLongInteger(long long int val)
00179 { }
00181 void SetNull()
00182 {
00183 nullvalue=-1;
00184 asigned=true;
00185 }
00187 void ClearNull()
00188 {
00189 nullvalue=0;
00190 asigned=true;
00191 }
00193 virtual void ConvertStoV()
00194 { }
00195 virtual void ConvertVtoS()
00196 { }
00197 short GetLen() const
00198 {
00199 return sqllen;
00200 }
00202 void SetLen(short len)
00203 {
00204 sqllen=len;
00205 }
00207 virtual void SetFormat(string fmt)
00208 {
00209 dspformat=fmt;
00210 }
00212 virtual void SetScale(short scal)
00213 {
00214 scale=scal;
00215 }
00217 short GetScale() const
00218 {
00219 return scale;
00220 }
00222 FBwFieldKind FieldKind() const
00223 {
00224 return kind;
00225 }
00227
00230 virtual void ValueCopy(const FBwField *fld)
00231 {
00232 if( fld->IsNull() )
00233 SetNull();
00234 else
00235 {
00236 bCopy(fld);
00237 ClearNull();
00238 }
00239 }
00240 friend class FieldList;
00241 virtual FBwField *Clone() const
00242 {
00243 return new FBwField(*this);
00244 }
00246 void SetAsigned(bool how=true)
00247 {
00248 asigned=how;
00249 }
00251 bool IsAsigned() const
00252 {
00253 return asigned;
00254 }
00256 virtual ~FBwField()
00257 {
00258 }
00259 };
00260
00261
00263
00264 {
00265 short value;
00266 protected:
00267 virtual void *GetPtr()
00268 {
00269 return &value;
00270 }
00271 virtual void bCopy(const FBwField *fld)
00272 {
00273 value = fld->AsShort();
00274 }
00275 public:
00277 FBwShortField(string pName);
00279 FBwShortField(const FBwShortField &f);
00281 virtual short AsShort() const
00282 {
00283 return value;
00284 }
00286 virtual std::ostream &DisplayText(std::ostream &o) const;
00288 virtual long AsInteger() const
00289 {
00290 return (long) value;
00291 }
00293 virtual double AsDouble() const
00294 {
00295 return (double)value;
00296 }
00298 virtual string AsString() const;
00300 virtual void SetAsShort(short pvalue)
00301 {
00302 ClearNull();
00303 value = pvalue;
00304 }
00306 virtual void SetAsInteger(long pvalue)
00307 {
00308 ClearNull();
00309 value = (short)pvalue;
00310 }
00312 virtual void SetAsLongInteger(long long int pvalue)
00313 {
00314 ClearNull();
00315 value = (short)pvalue;
00316 }
00318 virtual void SetAsDouble(double pvalue)
00319 {
00320 ClearNull();
00321 value = (short)pvalue;
00322 }
00324 virtual void SetAsString(const string &s);
00325 virtual void BindPtr(char **p)
00326 {
00327 *p=(char *)&value;
00328 }
00329 short &Value()
00330 {
00331 return value;
00332 }
00333 virtual void ConvertStoV()
00334 {
00335 if( IsNull() )
00336 value = 0;
00337 }
00338 virtual void ConvertVtoS()
00339 {
00340 }
00342 virtual FBwShortField *Clone() const
00343 {
00344 return new FBwShortField(*this);
00345 }
00347 virtual ~FBwShortField()
00348 {
00349 }
00351 virtual int ByteSize() const
00352 {
00353 return sizeof(value);
00354 }
00355 };
00356
00357
00359
00360 {
00361 long long int value;
00362 protected:
00363 virtual void *GetPtr()
00364 {
00365 return &value;
00366 }
00367 public:
00368 FBwLongIntegerField(string pName);
00369 FBwLongIntegerField(const FBwLongIntegerField &f);
00370 virtual short AsShort() const
00371 {
00372 return (short)value;
00373 }
00374 virtual long AsInteger() const
00375 {
00376 return (long) value;
00377 }
00378 virtual long long int AsLongInteger() const
00379 {
00380 return value;
00381 }
00382 virtual double AsDouble() const
00383 {
00384 return (double)value;
00385 }
00386 virtual void SetAsShort(short pvalue)
00387 {
00388 ClearNull();
00389 value = (long long int)pvalue;
00390 }
00391 virtual void SetAsDouble(double pvalue)
00392 {
00393 ClearNull();
00394 value = (long long int)pvalue;
00395 }
00396 virtual void SetAsInteger(long pvalue)
00397 {
00398 ClearNull();
00399 value = (long long int)pvalue;
00400 }
00401 virtual void SetAsLongInteger(long long int pvalue)
00402 {
00403 ClearNull();
00404 value = pvalue;
00405 }
00406 virtual void SetAsString(const string &pvalue);
00407 virtual long long int GetAsLongInteger()
00408 {
00409 return value;
00410 }
00411 virtual void BindPtr(char **p)
00412 {
00413 *p=(char *)&value;
00414 }
00415 virtual void ConvertStoV()
00416 {
00417 if( IsNull() )
00418 value = 0;
00419 }
00420 virtual void ConvertVtoS()
00421 {
00422 }
00423 virtual string AsString() const;
00424 FBwField *Clone() const
00425 {
00426 return new FBwLongIntegerField(*this);
00427 }
00428 virtual void bCopy(const FBwField *f)
00429 {
00430 value = f->AsLongInteger();
00431 }
00432 virtual ~FBwLongIntegerField()
00433 {
00434 }
00435 virtual int ByteSize() const
00436 {
00437 return sizeof(value);
00438 }
00439 };
00441 class FBwIntegerField : public FBwField
00442 {
00443 long value;
00444 protected:
00445 virtual void *GetPtr()
00446 {
00447 return &value;
00448 }
00449 virtual void bCopy(const FBwField *fld)
00450 {
00451 value = fld->AsInteger();
00452 }
00453 public:
00454 FBwIntegerField(string pName);
00455 FBwIntegerField(const FBwIntegerField &f);
00456 virtual short AsShort() const
00457 {
00458 return (short)value;
00459 }
00460 virtual long AsInteger() const
00461 {
00462 return (long) value;
00463 }
00464 virtual long long int AsLongInteger() const
00465 {
00466 return (long long int) value;
00467 }
00468 virtual double AsDouble() const
00469 {
00470 return (double)value;
00471 }
00472 virtual void SetAsShort(short pvalue)
00473 {
00474 ClearNull();
00475 value = (long)pvalue;
00476 }
00477 virtual void SetAsDouble(double pvalue)
00478 {
00479 ClearNull();
00480 value = (long)pvalue;
00481 }
00482 virtual void SetAsInteger(long pvalue)
00483 {
00484 ClearNull();
00485 value = pvalue;
00486 }
00487 virtual void SetAsLongInteger(long long int pvalue)
00488 {
00489 ClearNull();
00490 value = pvalue;
00491 }
00492 virtual void BindPtr(char **p)
00493 {
00494 *p=(char *)&value;
00495 }
00496 virtual void ConvertStoV()
00497 {
00498 if( IsNull() )
00499 value = 0;
00500 }
00501 virtual void ConvertVtoS()
00502 {
00503 }
00504 virtual string AsString() const;
00505 virtual std::ostream &DisplayText(std::ostream &o) const;
00506 virtual void SetAsString(const string &pvalue);
00507 FBwField *Clone() const
00508 {
00509 return new FBwIntegerField(*this);
00510 }
00511 virtual ~FBwIntegerField()
00512 {}
00513 virtual int ByteSize() const
00514 {
00515 return sizeof(value);
00516 }
00517 };
00518
00519
00520 }
00521 #endif