Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

O3DBIDataField.cpp

Go to the documentation of this file.
00001 
00011 #include "O3DBITypes.h"
00012 #include "O3DBIDataField.h"
00013 #include "O3DBIError.h"
00014 #include "O3DBIException.h"
00015 
00016 #pragma warning(push, 4)
00017 
00018 // ----------------------------------------------------------------------------
00019 // O3DBIDataField construction/destruction
00020 
00021 O3DBIDataField::O3DBIDataField() :
00022     _isNullable(true),
00023     _isNull(true),
00024     _isModified(false),
00025     _type(O3DBI::UNDEFINED),
00026     _pchFieldname(NULL)
00027 {
00028 
00029 }
00030 
00031 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, TOracleDataType type) :
00032     _isNullable(true),
00033     _isNull(true),
00034     _isModified(false),
00035     _type(type)
00036 {
00037     if (! AllocateAndSetFieldname(pchFieldname))
00038         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00039             O3DBIErrorTxt::pchInvalidFieldname,
00040             _T("O3DBIDataField::O3DBIDataField"), this);    
00041 }
00042 
00043 O3DBIDataField::O3DBIDataField(const O3DBIDataField& other) :
00044     _isNullable(true),
00045     _isNull(true),
00046     _isModified(false),
00047     _type(O3DBI::UNDEFINED),
00048     _pchFieldname(NULL)
00049 {
00050     (*this) = other;
00051     _isModified = false;
00052 }
00053 
00054 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, int iValue) :
00055     _isNullable(true),
00056     _isNull(false),
00057     _pchFieldname(NULL),
00058     _type(O3DBI::NUMBER)
00059 {
00060     if (! AllocateAndSetFieldname(pchFieldname))
00061         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00062             O3DBIErrorTxt::pchInvalidFieldname,
00063             _T("O3DBIDataField::O3DBIDataField"), this);
00064     (*this) = iValue;
00065     _isModified = false;
00066 }
00067 
00068 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, unsigned int uValue) :
00069     _isNullable(true),
00070     _isNull(false),
00071     _pchFieldname(NULL),
00072     _type(O3DBI::NUMBER)
00073 {
00074     if (! AllocateAndSetFieldname(pchFieldname))
00075         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00076             O3DBIErrorTxt::pchInvalidFieldname,
00077             _T("O3DBIDataField::O3DBIDataField"), this);
00078     (*this) = uValue;
00079     _isModified = false;
00080 }
00081 
00082 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, long lValue) :
00083     _isNullable(true),
00084     _isNull(false),
00085     _pchFieldname(NULL),
00086     _type(O3DBI::NUMBER)
00087 {
00088     if (! AllocateAndSetFieldname(pchFieldname))
00089         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00090             O3DBIErrorTxt::pchInvalidFieldname,
00091             _T("O3DBIDataField::O3DBIDataField"), this);
00092     (*this) = lValue;
00093     _isModified = false;
00094 }
00095 
00096 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, unsigned long ulValue) :
00097     _isNullable(true),
00098     _isNull(false),
00099     _pchFieldname(NULL),
00100     _type(O3DBI::NUMBER)
00101 {
00102     if (! AllocateAndSetFieldname(pchFieldname))
00103         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00104             O3DBIErrorTxt::pchInvalidFieldname,
00105             _T("O3DBIDataField::O3DBIDataField"), this);
00106     (*this) = ulValue;
00107     _isModified = false;
00108 }
00109 
00110 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, float fValue) :
00111     _isNullable(true),
00112     _isNull(false),
00113     _pchFieldname(NULL),
00114     _type(O3DBI::FLOAT)
00115 {
00116     if (! AllocateAndSetFieldname(pchFieldname))
00117         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00118             O3DBIErrorTxt::pchInvalidFieldname,
00119             _T("O3DBIDataField::O3DBIDataField"), this);
00120     (*this) = fValue;
00121     _isModified = false;
00122 }
00123 
00124 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, double dValue) :
00125     _isNullable(true),
00126     _isNull(false),
00127     _pchFieldname(NULL),
00128     _type(O3DBI::FLOAT)
00129 {
00130     if (! AllocateAndSetFieldname(pchFieldname))
00131         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00132             O3DBIErrorTxt::pchInvalidFieldname,
00133             _T("O3DBIDataField::O3DBIDataField"), this);
00134     (*this) = dValue;
00135     _isModified = false;
00136 }
00137 
00138 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname,
00139                                const TO3DBIString& strValue) :
00140     _isNullable(true),
00141     _isNull(false),
00142     _pchFieldname(NULL),
00143     _type(O3DBI::VARCHAR2)
00144 {
00145     if (! AllocateAndSetFieldname(pchFieldname))
00146         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00147             O3DBIErrorTxt::pchInvalidFieldname,
00148             _T("O3DBIDataField::O3DBIDataField"), this);
00149     (*this) = strValue;
00150     _isModified = false;
00151 }
00152 
00153 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, const PC_TCHAR pchValue) :
00154     _isNullable(true),
00155     _isNull(false),
00156     _pchFieldname(NULL),
00157     _type(O3DBI::CHAR)
00158 {
00159     if (! AllocateAndSetFieldname(pchFieldname))
00160         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00161             O3DBIErrorTxt::pchInvalidFieldname,
00162             _T("O3DBIDataField::O3DBIDataField"), this);
00163     (*this) = pchValue;
00164     _isModified = false;
00165 }
00166 
00167 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, const O3DBIDate& dtValue) :
00168     _isNullable(true),
00169     _isNull(false),
00170     _pchFieldname(NULL),
00171     _type(O3DBI::DATE)
00172 {
00173     if (! AllocateAndSetFieldname(pchFieldname))
00174         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00175             O3DBIErrorTxt::pchInvalidFieldname,
00176             _T("O3DBIDataField::O3DBIDataField"), this);
00177     (*this) = dtValue;
00178     _isModified = false;
00179 }
00180 
00181 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname,
00182                                const O3DBITimestamp& tsValue) :
00183     _isNullable(true),
00184     _isNull(false),
00185     _pchFieldname(NULL),
00186     _type(O3DBI::TIMESTAMP)
00187 {
00188     if (! AllocateAndSetFieldname(pchFieldname))
00189         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00190             O3DBIErrorTxt::pchInvalidFieldname,
00191             _T("O3DBIDataField::O3DBIDataField"), this);
00192     (*this) = tsValue;
00193     _isModified = false;
00194 }
00195 
00196 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, const O3DBIClob& value) :
00197     _isNullable(true),
00198     _isNull(false),
00199     _pchFieldname(NULL),
00200     _type(O3DBI::CLOB)
00201 {
00202     if (! AllocateAndSetFieldname(pchFieldname))
00203         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00204             O3DBIErrorTxt::pchInvalidFieldname,
00205             _T("O3DBIDataField::O3DBIDataField"), this);
00206     (*this) = value;
00207     _isModified = false;
00208 }
00209 
00210 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, const O3DBIBlob& value) :
00211     _isNullable(true),
00212     _isNull(false),
00213     _pchFieldname(NULL),
00214     _type(O3DBI::BLOB)
00215 {
00216     if (! AllocateAndSetFieldname(pchFieldname))
00217         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00218             O3DBIErrorTxt::pchInvalidFieldname,
00219             _T("O3DBIDataField::O3DBIDataField"), this);
00220     (*this) = value;
00221     _isModified = false;
00222 }
00223 
00224 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, const O3DBIBfile& value) :
00225     _isNullable(true),
00226     _isNull(false),
00227     _pchFieldname(NULL),
00228     _type(O3DBI::BFILE)
00229 {
00230     if (! AllocateAndSetFieldname(pchFieldname))
00231         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00232             O3DBIErrorTxt::pchInvalidFieldname,
00233             _T("O3DBIDataField::O3DBIDataField"), this);
00234     (*this) = value;
00235     _isModified = false;
00236 }
00237 
00238 O3DBIDataField::O3DBIDataField(PC_TCHAR pchFieldname, const O3DBIXml& value) :
00239     _isNullable(true),
00240     _isNull(false),
00241     _pchFieldname(NULL),
00242     _type(O3DBI::XMLTYPE)
00243 {
00244     if (! AllocateAndSetFieldname(pchFieldname))
00245         throw new O3DBIException(O3DBI_INVALID_FIELDNAME,
00246             O3DBIErrorTxt::pchInvalidFieldname,
00247             _T("O3DBIDataField::O3DBIDataField"), this);
00248     (*this) = value;
00249     _isModified = false;
00250 }
00251 
00252 O3DBIDataField::~O3DBIDataField()
00253 {
00254     if (_pchFieldname != NULL)
00255     {
00256         ::free(reinterpret_cast<void*>(_pchFieldname));
00257         _pchFieldname = NULL;
00258     }
00259 }
00260 
00261 // ----------------------------------------------------------------------------
00262 // O3DBIDataField assignment
00263 
00264 O3DBIDataField& O3DBIDataField::operator=(const O3DBIDataField& other)
00265 {
00266     AllocateAndSetFieldname(other._pchFieldname);
00267     _type = other._type;
00268     _value = other._value;
00269     _isNull = other._isNull;
00270     _isNullable = other._isNullable;
00271     _isModified = true;
00272     return (*this);
00273 }
00274 
00275 O3DBIDataField& O3DBIDataField::operator=(int iValue)
00276 {
00277     if (_type == O3DBI::UNDEFINED)
00278         _type = O3DBI::NUMBER;
00279 
00280     switch (_type)
00281     {
00282     case O3DBI::NUMBER:
00283         _value._number = iValue;
00284         break;
00285         
00286     default:
00287         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00288             O3DBIErrorTxt::pchIncompatibleDatatypes,
00289             _T("O3DBIDataField::operator="), this);
00290     }
00291 
00292     _isNull = false;
00293     _isModified = true;
00294     return (*this);
00295 }
00296 
00297 O3DBIDataField& O3DBIDataField::operator=(unsigned int uValue)
00298 {
00299     if (_type == O3DBI::UNDEFINED)
00300         _type = O3DBI::NUMBER;
00301 
00302     switch (_type)
00303     {
00304     case O3DBI::NUMBER:
00305         _value._number = uValue;
00306         break;
00307         
00308     default:
00309         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00310             O3DBIErrorTxt::pchIncompatibleDatatypes,
00311             _T("O3DBIDataField::operator="), this);
00312     }
00313 
00314     _isNull = false;
00315     _isModified = true;
00316     return (*this);
00317 }
00318 
00319 O3DBIDataField& O3DBIDataField::operator=(long lValue)
00320 {
00321     if (_type == O3DBI::UNDEFINED)
00322         _type = O3DBI::NUMBER;
00323 
00324     switch (_type)
00325     {
00326     case O3DBI::NUMBER:
00327         _value._number = lValue;
00328         break;
00329         
00330     default:
00331         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00332             O3DBIErrorTxt::pchIncompatibleDatatypes,
00333             _T("O3DBIDataField::operator="), this);
00334     }
00335 
00336     _isNull = false;
00337     _isModified = true;
00338     return (*this);
00339 }
00340 
00341 O3DBIDataField& O3DBIDataField::operator=(unsigned long ulValue)
00342 {
00343     if (_type == O3DBI::UNDEFINED)
00344         _type = O3DBI::NUMBER;
00345 
00346     switch (_type)
00347     {
00348     case O3DBI::NUMBER:
00349         _value._number = ulValue;
00350         break;
00351         
00352     default:
00353         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00354             O3DBIErrorTxt::pchIncompatibleDatatypes,
00355             _T("O3DBIDataField::operator="), this);
00356     }
00357 
00358     _isNull = false;
00359     _isModified = true;
00360     return (*this);
00361 }
00362 
00363 O3DBIDataField& O3DBIDataField::operator=(float fValue)
00364 {
00365     if (_type == O3DBI::UNDEFINED)
00366         _type = O3DBI::FLOAT;
00367 
00368     switch (_type)
00369     {
00370     case O3DBI::FLOAT:
00371         _value._number = fValue;
00372         break;
00373         
00374     default:
00375         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00376             O3DBIErrorTxt::pchIncompatibleDatatypes,
00377             _T("O3DBIDataField::operator="), this);
00378     }
00379 
00380     _isNull = false;
00381     _isModified = true;
00382     return (*this);
00383 }
00384 
00385 O3DBIDataField& O3DBIDataField::operator=(double dValue)
00386 {
00387     if (_type == O3DBI::UNDEFINED)
00388         _type = O3DBI::FLOAT;
00389 
00390     switch (_type)
00391     {
00392     case O3DBI::FLOAT:
00393         _value._number = dValue;
00394         break;
00395         
00396     default:
00397         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00398             O3DBIErrorTxt::pchIncompatibleDatatypes,
00399             _T("O3DBIDataField::operator="), this);
00400     }
00401 
00402     _isNull = false;
00403     _isModified = true;
00404     return (*this);
00405 }
00406 
00407 O3DBIDataField& O3DBIDataField::operator=(const TO3DBIString& strValue)
00408 {
00409     if (_type == O3DBI::UNDEFINED)
00410         _type = O3DBI::VARCHAR2;
00411 
00412     switch (_type)
00413     {
00414     case O3DBI::VARCHAR2:
00415     case O3DBI::NVARCHAR2:
00416         _value._s = strValue;
00417         break;
00418         
00419     default:
00420         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00421             O3DBIErrorTxt::pchIncompatibleDatatypes,
00422             _T("O3DBIDataField::operator="), this);
00423     }
00424 
00425     _isNull = false;
00426     _isModified = true;
00427     return (*this);
00428 }
00429 
00430 O3DBIDataField& O3DBIDataField::operator=(const PC_TCHAR pchValue)
00431 {
00432     if (_type == O3DBI::UNDEFINED)
00433         _type = O3DBI::CHAR;
00434 
00435     switch (_type)
00436     {
00437     case O3DBI::CHAR:
00438     case O3DBI::NCHAR:
00439         _value._s = pchValue;
00440         break;
00441         
00442     default:
00443         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00444             O3DBIErrorTxt::pchIncompatibleDatatypes,
00445             _T("O3DBIDataField::operator="), this);
00446     }
00447 
00448     _isNull = false;
00449     _isModified = true;
00450     return (*this);
00451 }
00452 
00453 O3DBIDataField& O3DBIDataField::operator=(const O3DBIDate& dtValue)
00454 {
00455     if (_type == O3DBI::UNDEFINED)
00456         _type = O3DBI::DATE;
00457 
00458     switch (_type)
00459     {
00460     case O3DBI::DATE:
00461         _value._date = dtValue;
00462         break;
00463         
00464     default:
00465         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00466             O3DBIErrorTxt::pchIncompatibleDatatypes,
00467             _T("O3DBIDataField::operator="), this);
00468     }
00469 
00470     _isNull = false;
00471     _isModified = true;
00472     return (*this);
00473 }
00474 
00475 O3DBIDataField& O3DBIDataField::operator=(const O3DBITimestamp& tsValue)
00476 {
00477     if (_type == O3DBI::UNDEFINED)
00478         _type = O3DBI::TIMESTAMP;
00479 
00480     switch (_type)
00481     {
00482     case O3DBI::TIMESTAMP:
00483     case O3DBI::TIMESTAMP_W_LOCAL_TZ:
00484         _value._ts = tsValue;
00485         break;
00486         
00487     default:
00488         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00489             O3DBIErrorTxt::pchIncompatibleDatatypes,
00490             _T("O3DBIDataField::operator="), this);
00491     }
00492 
00493     _isNull = false;
00494     _isModified = true;
00495     return (*this);
00496 }
00497 
00498 O3DBIDataField& O3DBIDataField::operator=(const O3DBIClob& value)
00499 {
00500     if (_type == O3DBI::UNDEFINED)
00501         _type = O3DBI::CHAR;
00502 
00503     switch (_type)
00504     {
00505     case O3DBI::CHAR:
00506     case O3DBI::NCHAR:
00507         _value._clob = value;
00508         break;
00509         
00510     default:
00511         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00512             O3DBIErrorTxt::pchIncompatibleDatatypes,
00513             _T("O3DBIDataField::operator="), this);
00514     }
00515 
00516     _isNull = false;
00517     _isModified = true;
00518     return (*this);
00519 }
00520 
00521 O3DBIDataField& O3DBIDataField::operator=(const O3DBIBlob& value)
00522 {
00523     if (_type == O3DBI::UNDEFINED)
00524         _type = O3DBI::BLOB;
00525 
00526     switch (_type)
00527     {
00528     case O3DBI::BLOB:
00529         _value._blob = value;
00530         break;
00531         
00532     default:
00533         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00534             O3DBIErrorTxt::pchIncompatibleDatatypes,
00535             _T("O3DBIDataField::operator="), this);
00536     }
00537 
00538     _isNull = false;
00539     _isModified = true;
00540     return (*this);
00541 }
00542 
00543 O3DBIDataField& O3DBIDataField::operator=(const O3DBIBfile& value)
00544 {
00545     if (_type == O3DBI::UNDEFINED)
00546         _type = O3DBI::BFILE;
00547 
00548     switch (_type)
00549     {
00550     case O3DBI::BFILE:
00551         _value._bfile = value;
00552         break;
00553         
00554     default:
00555         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00556             O3DBIErrorTxt::pchIncompatibleDatatypes,
00557             _T("O3DBIDataField::operator="), this);
00558     }
00559 
00560     _isNull = false;
00561     _isModified = true;
00562     return (*this);
00563 }
00564 
00565 O3DBIDataField& O3DBIDataField::operator=(const O3DBIXml& value)
00566 {
00567     if (_type == O3DBI::UNDEFINED)
00568         _type = O3DBI::XMLTYPE;
00569 
00570     switch (_type)
00571     {
00572     case O3DBI::XMLTYPE:
00573         _value._xml = value;
00574         break;
00575         
00576     default:
00577         throw new O3DBIException(O3DBI_INCOMPATIBLE_DATATYPES,
00578             O3DBIErrorTxt::pchIncompatibleDatatypes,
00579             _T("O3DBIDataField::operator="), this);
00580     }
00581 
00582     _isNull = false;
00583     _isModified = true;
00584     return (*this);
00585 }
00586 
00587 // ----------------------------------------------------------------------------
00588 // O3DBIDataField public interface
00589 
00590 bool O3DBIDataField::IsNullable() const
00591 {
00592     return _isNullable;
00593 }
00594 
00595 bool O3DBIDataField::IsNull() const
00596 {
00597     return _isNull;
00598 }
00599 
00600 TO3DBIResult O3DBIDataField::SetNull()
00601 {
00602     _isNull = _isNullable;
00603     return (_isNull);
00604 }
00605 
00606 void O3DBIDataField::SetModified()
00607 {
00608     _isModified = true;
00609 }
00610 
00611 void O3DBIDataField::CancelModified()
00612 {
00613     _isModified = false;
00614 }
00615 
00616 bool O3DBIDataField::IsModified() const
00617 {
00618     return _isModified;
00619 }
00620 
00621 TOracleDataType O3DBIDataField::GetType() const
00622 {
00623     return _type;
00624 }
00625 
00626 int O3DBIDataField::GetInt() const
00627 {
00628     if (_type != O3DBI::NUMBER || _type != O3DBI::FLOAT)
00629         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00630             O3DBIErrorTxt::pchOperationNotpermitted,
00631             _T("O3DBIDataField::GetInt"), this);
00632     if (_isNull)
00633         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00634             O3DBIErrorTxt::pchAccessingNullvalue, _T("O3DBIDataField::GetInt"),
00635             this);
00636 
00637     return static_cast<int>(_value._number);
00638 }
00639 
00640 unsigned int O3DBIDataField::GetUnsignedInt() const
00641 {
00642     if (_type != O3DBI::NUMBER || _type != O3DBI::FLOAT)
00643         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00644             O3DBIErrorTxt::pchOperationNotpermitted,
00645             _T("O3DBIDataField::GetUnsignedInt"), this);
00646     if (_isNull)
00647         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00648             O3DBIErrorTxt::pchAccessingNullvalue,
00649             _T("O3DBIDataField::GetUnsignedInt"), this);
00650 
00651     return static_cast<unsigned int>(_value._number);
00652 }
00653 
00654 long O3DBIDataField::GetLong() const
00655 {
00656     if (_type != O3DBI::NUMBER || _type != O3DBI::FLOAT)
00657         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00658             O3DBIErrorTxt::pchOperationNotpermitted,
00659             _T("O3DBIDataField::GetLong"), this);
00660     if (_isNull)
00661         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00662             O3DBIErrorTxt::pchAccessingNullvalue,
00663             _T("O3DBIDataField::GetLong"), this);
00664 
00665     return static_cast<long>(_value._number);
00666 }
00667 
00668 unsigned long O3DBIDataField::GetUnsignedLong() const
00669 {
00670     if (_type != O3DBI::NUMBER || _type != O3DBI::FLOAT)
00671         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00672             O3DBIErrorTxt::pchOperationNotpermitted,
00673             _T("O3DBIDataField::GetUnsignedLong"), this);
00674     if (_isNull)
00675         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00676             O3DBIErrorTxt::pchAccessingNullvalue,
00677             _T("O3DBIDataField::GetUnsignedLong"), this);
00678 
00679     return static_cast<unsigned long>(_value._number);
00680 }
00681 
00682 float O3DBIDataField::GetFloat() const
00683 {
00684     if (_type != O3DBI::NUMBER || _type != O3DBI::FLOAT)
00685         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00686             O3DBIErrorTxt::pchOperationNotpermitted,
00687             _T("O3DBIDataField::GetFloat"), this);
00688     if (_isNull)
00689         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00690             O3DBIErrorTxt::pchAccessingNullvalue,
00691             _T("O3DBIDataField::GetFloat"), this);
00692 
00693     return static_cast<float>(_value._number);
00694 }
00695 
00696 double O3DBIDataField::GetDouble() const
00697 {
00698     if (_type != O3DBI::NUMBER || _type != O3DBI::FLOAT)
00699         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00700             O3DBIErrorTxt::pchOperationNotpermitted,
00701             _T("O3DBIDataField::GetDouble"), this);
00702     if (_isNull)
00703         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00704             O3DBIErrorTxt::pchAccessingNullvalue,
00705             _T("O3DBIDataField::GetDouble"), this);
00706 
00707     return _value._number;
00708 }
00709 
00710 TO3DBIString O3DBIDataField::GetString() const
00711 {
00712     if (_isNull)
00713         return TO3DBIString(_T("### NULL ###"));
00714     if (_type == O3DBI::UNDEFINED)
00715         return TO3DBIString();
00716     return ValueToString();
00717 }
00718 
00719 O3DBIDate O3DBIDataField::GetDate() const
00720 {
00721     if (_type != O3DBI::DATE)
00722         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00723             O3DBIErrorTxt::pchOperationNotpermitted,
00724             _T("O3DBIDataField::GetDate"), this);
00725     if (_isNull)
00726         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00727             O3DBIErrorTxt::pchAccessingNullvalue,
00728             _T("O3DBIDataField::GetDate"), this);
00729 
00730     return _value._date;
00731 }
00732 
00733 O3DBITimestamp O3DBIDataField::GetTimestamp() const
00734 {
00735     if (_type != O3DBI::TIMESTAMP)
00736         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00737             O3DBIErrorTxt::pchOperationNotpermitted,
00738             _T("O3DBIDataField::GetTimestamp"), this);
00739     if (_isNull)
00740         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00741             O3DBIErrorTxt::pchAccessingNullvalue,
00742             _T("O3DBIDataField::GetTimestamp"), this);
00743 
00744     return _value._ts;
00745 }
00746 
00747 O3DBIClob O3DBIDataField::GetClob() const
00748 {
00749     if (_type != O3DBI::CLOB)
00750         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00751             O3DBIErrorTxt::pchOperationNotpermitted,
00752             _T("O3DBIDataField::GetClob"), this);
00753     if (_isNull)
00754         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00755             O3DBIErrorTxt::pchAccessingNullvalue,
00756             _T("O3DBIDataField::GetClob"), this);
00757 
00758     return _value._clob;
00759 }
00760 
00761 O3DBIBlob O3DBIDataField::GetBlob() const
00762 {
00763     if (_type != O3DBI::BLOB)
00764         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00765             O3DBIErrorTxt::pchOperationNotpermitted,
00766             _T("O3DBIDataField::GetBlob"), this);
00767     if (_isNull)
00768         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00769             O3DBIErrorTxt::pchAccessingNullvalue,
00770             _T("O3DBIDataField::GetBlob"), this);
00771 
00772     return _value._blob;
00773 }
00774 
00775 O3DBIBfile O3DBIDataField::GetBfile() const
00776 {
00777     if (_type != O3DBI::BFILE)
00778         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00779             O3DBIErrorTxt::pchOperationNotpermitted,
00780             _T("O3DBIDataField::GetBfile"), this);
00781     if (_isNull)
00782         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00783             O3DBIErrorTxt::pchAccessingNullvalue,
00784             _T("O3DBIDataField::GetBfile"), this);
00785 
00786     return _value._bfile;
00787 }
00788 
00789 O3DBIXml O3DBIDataField::GetXml() const
00790 {
00791     if (_type != O3DBI::XMLTYPE)
00792         throw new O3DBIException(O3DBI_OPERATION_NOTPERMITTED,
00793             O3DBIErrorTxt::pchOperationNotpermitted,
00794             _T("O3DBIDataField::GetXml"), this);
00795     if (_isNull)
00796         throw new O3DBIException(O3DBI_ACCESSING_NULLVALUE,
00797             O3DBIErrorTxt::pchAccessingNullvalue,
00798             _T("O3DBIDataField::GetXml"), this);
00799 
00800     return _value._xml;
00801 }
00802 
00803 TO3DBIString O3DBIDataField::ToString() const
00804 {
00805     _TCHAR buffer[LARGESTRING_BUFFERSIZE];
00806     int p;
00807 
00808     p = ::_stprintf(buffer, _T("O3DBIDataField at 0x%x\n"), this);
00809     p += ::_stprintf(buffer + p, _T("\tField name: %s\n"), _pchFieldname);
00810     p += ::_stprintf(buffer + p, _T("\tType: %s\n"), TypeToString().c_str());
00811     p += ::_stprintf(buffer + p, _T("\tValue: %s\n"), _isNull
00812         ? _T("NULL") : ValueToString().c_str());
00813 
00814     return TO3DBIString(buffer);
00815 }
00816 
00817 // ----------------------------------------------------------------------------
00818 // O3DBIDataField comparison
00819 
00820 bool O3DBIDataField::operator==(const O3DBIDataField& other) const
00821 {
00822     if (_type != other._type)
00823         return false;       // Data types are not equal
00824     if (_isNull && other._isNull)
00825         return true;        // Both data fields are NULL
00826     if (_isNull || other._isNull)
00827         throw new O3DBIException(O3DBI_COMPARING_NULLVALUE,
00828             O3DBIErrorTxt::pchComparingNullvalue,
00829             _T("O3DBIDataField::operator=="), this);
00830     switch (_type)
00831     {
00832     case O3DBI::UNDEFINED:
00833         return (other._type == O3DBI::UNDEFINED);
00834 
00835     case O3DBI::CHAR:
00836     case O3DBI::NCHAR:
00837     case O3DBI::VARCHAR2:
00838     case O3DBI::NVARCHAR2:
00839         return (_value._s == other._value._s);
00840 
00841 
00842     case O3DBI::NUMBER:
00843     case O3DBI::FLOAT:
00844         return (_value._number == other._value._number);
00845 
00846     case O3DBI::DATE:
00847         return (_value._date == other._value._date);
00848 
00849     case O3DBI::TIMESTAMP:
00850     case O3DBI::TIMESTAMP_W_LOCAL_TZ:
00851         return (_value._ts == other._value._ts);
00852 
00853     case O3DBI::BLOB:
00854         return (_value._blob == other._value._blob);
00855 
00856     case O3DBI::CLOB:
00857     case O3DBI::NCLOB:
00858         return (_value._clob == other._value._clob);
00859 
00860     case O3DBI::BFILE:
00861         return (_value._bfile == other._value._bfile);
00862 
00863     case O3DBI::XMLTYPE:
00864         return (_value._xml == other._value._xml);
00865     }
00866     return false;   // This point should never be reached!
00867 }
00868 
00869 // ----------------------------------------------------------------------------
00870 // O3DBIDataField internal implementation
00871 
00872 void O3DBIDataField::SetNullable(bool bIsNullable /* = true */)
00873 {
00874     _isNullable = bIsNullable;
00875     if (! _isNullable)
00876         _isNull = false;
00877 }
00878 
00879 bool O3DBIDataField::AllocateAndSetFieldname(PC_TCHAR pchName)
00880 {
00881     if (pchName == NULL)
00882         return false;   // NULL pointers not allowed!
00883     unsigned int nLength = ::_tcslen(pchName);
00884     if (nLength == 0)
00885         return false;   // Zero-length strings are not allowed!
00886     if (_pchFieldname != NULL)
00887     {
00888         // Free previous allocated memory first
00889         ::free(reinterpret_cast<void*>(_pchFieldname));
00890     }
00891     _pchFieldname =
00892         reinterpret_cast<P_TCHAR>(::calloc(nLength + sizeof(_TCHAR),
00893         sizeof(_TCHAR)));
00894     if (_pchFieldname == NULL)
00895         return false;
00896     // Copy string
00897     ::_tcsncpy(_pchFieldname, pchName, nLength);
00898     return true;
00899 }
00900 
00901 TO3DBIString O3DBIDataField::TypeToString() const
00902 {
00903     switch (_type)
00904     {
00905     case O3DBI::UNDEFINED:
00906         return TO3DBIString(_T("UNDEFINED"));
00907     case O3DBI::CHAR:
00908         return TO3DBIString(_T("CHAR"));
00909     case O3DBI::NCHAR:
00910         return TO3DBIString(_T("NCHAR"));
00911     case O3DBI::VARCHAR2:
00912         return TO3DBIString(_T("VARCHAR2"));
00913     case O3DBI::NVARCHAR2:
00914         return TO3DBIString(_T("NVARCHAR2"));
00915     case O3DBI::NUMBER:
00916         return TO3DBIString(_T("NUMBER"));
00917     case O3DBI::FLOAT:
00918         return TO3DBIString(_T("FLOAT"));
00919     case O3DBI::DATE:
00920         return TO3DBIString(_T("DATE"));
00921     case O3DBI::TIMESTAMP:
00922         return TO3DBIString(_T("TIMESTAMP"));
00923     case O3DBI::TIMESTAMP_W_LOCAL_TZ:
00924         return TO3DBIString(_T("TIMESTAMP WITH LOCAL TIME ZONE"));
00925     case O3DBI::BLOB:
00926         return TO3DBIString(_T("BLOB"));
00927     case O3DBI::CLOB:
00928         return TO3DBIString(_T("CLOB"));
00929     case O3DBI::NCLOB:
00930         return TO3DBIString(_T("NCLOB"));
00931     case O3DBI::BFILE:
00932         return TO3DBIString(_T("BFILE"));
00933     case O3DBI::XMLTYPE:
00934         return TO3DBIString(_T("XMLTYPE"));
00935     }
00936     return TO3DBIString();  // This point should never be reached!
00937 }
00938 
00939 TO3DBIString O3DBIDataField::ValueToString() const
00940 {
00941     if (_isNull || _type == O3DBI::UNDEFINED)
00942         return TO3DBIString();
00943 
00944     _TCHAR buffer[SMALLSTRING_BUFFERSIZE];
00945     switch (_type)
00946     {
00947     case O3DBI::CHAR:
00948     case O3DBI::VARCHAR2:
00949         ::_tcsncpy(buffer, _value._s.c_str(), SMALLSTRING_BUFFERSIZE - 1);
00950         break;
00951 
00952     case O3DBI::NUMBER:
00953         ::_stprintf(buffer, _T("%.15f"), _value._number);
00954         break;
00955 
00956     case O3DBI::FLOAT:
00957         ::_stprintf(buffer, _T("%.15f"), _value._number);
00958         break;
00959 
00960     case O3DBI::DATE:
00961         ::_stprintf(buffer, _T("%s"), _value._date.ToString().c_str());
00962         break;
00963 
00964     case O3DBI::TIMESTAMP:
00965         ::_stprintf(buffer, _T("%s"), _value._ts.ToString().c_str());
00966         break;
00967 
00968     case O3DBI::BLOB:
00969         ::_stprintf(buffer, _T("%s"), _value._blob.ToString().c_str());
00970         break;
00971 
00972     case O3DBI::CLOB:
00973         ::_stprintf(buffer, _T("%s"), _value._clob.ToString().c_str());
00974         break;
00975 
00976     case O3DBI::BFILE:
00977         ::_stprintf(buffer, _T("%s"), _value._bfile.ToString().c_str());
00978         break;
00979     }
00980     if (buffer[SMALLSTRING_BUFFERSIZE - 4] != _T('\0'))
00981         ::_tcsncpy(buffer + SMALLSTRING_BUFFERSIZE - 4, _T("...\0"), 4);
00982 
00983     return TO3DBIString(buffer);
00984 }
00985 
00986 #pragma warning(pop)



SourceForge.net Logo Generated on Sun Jan 23 11:36:34 2005 for Oracle Object Oriented Database Interface (O3DBI) by  doxygen 1.3.9.1