#include <DbiResultSet.h>
Inheritance diagram for DbiResultSet:

Public Member Functions | |
| DbiResultSet (DbiStatement *stmtDb, const DbiString &sql, const DbiTableMetaData *metaData, const DbiTableProxy *tableProxy, UInt_t dbNo, const string &fillOpts="") | |
| virtual | ~DbiResultSet () |
| Bool_t | CurColExists () const |
| string | CurColString () const |
| string | CurColValue () const |
| UInt_t | CurRowNum () const |
| UInt_t | GetDbNo () const |
| Dbi::DbTypes | GetDBType () const |
| string | GetFillOpts () const |
| const DbiTableProxy * | GetTableProxy () const |
| Bool_t | IsBeforeFirst () const |
| Bool_t | IsExhausted () const |
| void | RowAsCsv (string &row) const |
| DbiResultSet & | operator>> (Bool_t &dest) |
| DbiResultSet & | operator>> (Char_t &dest) |
| DbiResultSet & | operator>> (Short_t &dest) |
| DbiResultSet & | operator>> (UShort_t &dest) |
| DbiResultSet & | operator>> (Int_t &dest) |
| DbiResultSet & | operator>> (UInt_t &dest) |
| DbiResultSet & | operator>> (Long_t &dest) |
| DbiResultSet & | operator>> (ULong_t &dest) |
| DbiResultSet & | operator>> (Float_t &dest) |
| DbiResultSet & | operator>> (Double_t &dest) |
| DbiResultSet & | operator>> (string &dest) |
| DbiResultSet & | operator>> (VldTimeStamp &dest) |
| Bool_t | FetchRow () |
Private Member Functions | |
| string & | AsString (Dbi::DataTypes type) |
| Bool_t | LoadCurValue () const |
| TString | GetStringFromTSQL (Int_t col) const |
Private Attributes | |
| Int_t | fCurRow |
| Current row in query (0...). | |
| UInt_t | fDbNo |
| Cascade no. of source. | |
| Dbi::DbTypes | fDbType |
| Type of database fDbNo. | |
| DbiStatement * | fStatement |
| TSQLStatement * | fTSQLStatement |
| Pointer to owned statement, may be 0. | |
| Bool_t | fExhausted |
| True is result set missing or exhausted. | |
| const DbiTableProxy * | fTableProxy |
| DbiTableProxy that produced this set. | |
| string | fValString |
| Buffer for assembling value. | |
| string | fFillOpts |
| Optional fill options. | |
DatabaseInterface
Contact: n.west1@physics.ox.ac.uk
Definition at line 45 of file DbiResultSet.h.
|
||||||||||||||||||||||||||||
|
Definition at line 34 of file DbiResultSet.cxx. 00039 : 00040 DbiRowStream(metaData), 00041 fCurRow(0), 00042 fDbNo(dbNo), 00043 fDbType(Dbi::kMySQL), 00044 fStatement(stmtDb), 00045 fTSQLStatement(0), 00046 fExhausted(true), 00047 fTableProxy(tableProxy), 00048 fFillOpts(fillOpts) 00049 { 00050 // 00051 // 00052 // Purpose: Default constructor 00053 // 00054 // Arguments: 00055 // stmtDb in DbiStatement to be used for query. May be zero. 00056 // sql in The query to be applied to the statement. 00057 // metaData in Meta data for query. 00058 // tableProxy in Source DbiTableProxy. 00059 // dbNo in Cascade no. of source. 00060 // 00061 // Return: n/a 00062 // 00063 // Contact: N. West 00064 // 00065 // Specification:- 00066 // ============= 00067 // 00068 // o Create ResultSet for query. 00069 00070 00071 // Program Notes:- 00072 // ============= 00073 00074 // None. 00075 00076 LEA_CTOR //Leak Checker 00077 00078 MSG("Dbi", Msg::kVerbose) << "Creating DbiResultSet" << endl; 00079 00080 if ( stmtDb ) { 00081 fDbType = stmtDb->GetDBType(); 00082 fTSQLStatement = stmtDb->ExecuteQuery(sql.c_str()); 00083 if ( fTSQLStatement && fTSQLStatement->NextResultRow() ) fExhausted = false; 00084 stmtDb->PrintExceptions(Msg::kDebug); 00085 } 00086 00087 }
|
|
|
Definition at line 92 of file DbiResultSet.cxx. References fStatement, fTSQLStatement, LEA_DTOR, and MSG. 00092 {
00093 //
00094 //
00095 // Purpose: Destructor
00096 //
00097 // Arguments:
00098 // None.
00099 //
00100 // Return: n/a
00101 //
00102 // Contact: N. West
00103 //
00104 // Specification:-
00105 // =============
00106 //
00107 // o Destroy ResultSet and owned DbiStatement if any.
00108
00109
00110 // Program Notes:-
00111 // =============
00112
00113 // None.
00114
00115 LEA_DTOR //Leak Checker
00116
00117 MSG("Dbi", Msg::kVerbose) << "Destroying DbiResultSet" << endl;
00118 delete fTSQLStatement;
00119 fTSQLStatement = 0;
00120 delete fStatement;
00121 fStatement = 0;
00122
00123 }
|
|
|
Definition at line 198 of file DbiResultSet.cxx. References DbiFieldType::AsString(), DbiTableMetaData::ColFieldType(), DbiTableMetaData::ColName(), DbiRowStream::CurColNum(), fCurRow, fValString, DbiFieldType::GetConcept(), DbiRowStream::IncrementCurCol(), DbiFieldType::IsCompatible(), DbiFieldType::IsSmaller(), LoadCurValue(), MAXMSG, DbiRowStream::MetaData(), DbiRowStream::TableNameTc(), and DbiFieldType::UndefinedValue(). Referenced by operator>>(). 00198 {
00199 //
00200 //
00201 // Purpose: Return current column value as a modifiable string and
00202 // move on.
00203 //
00204 // Arguments:
00205 // type in Required data type (as defined in Dbi.h).
00206 //
00207 // Return: Current column value as a string (null if missing)
00208 // Note: Caller must dispose of value before calling
00209 // this member function again as the value is
00210 // assembled into fValString.
00211 //
00212 // Contact: N. West
00213 //
00214 // Specification:-
00215 // =============
00216 //
00217 // o Return the datum at current (row,column) as a string and
00218 // increment column number.
00219 //
00220 // o Check for compatibility between required data type and table
00221 // data type, report problems and return default if incompatible.
00222
00223 // Program Notes:-
00224 // =============
00225
00226 // None.
00227
00228 DbiFieldType reqdt(type);
00229
00230 // Place table value string in value string buffer.
00231
00232 Bool_t fail = ! LoadCurValue();
00233 // Internally columns number from zero.
00234 UInt_t col = CurColNum();
00235 IncrementCurCol();
00236
00237 if ( fail ) {
00238 string udef = reqdt.UndefinedValue();
00239 MAXMSG("Dbi",Msg::kError,20)
00240 << "... value \"" << udef
00241 << "\" will be substitued." << endl;
00242 fValString = udef;
00243 return fValString;
00244 }
00245
00246 // Check for compatibility with required data type.
00247
00248 const DbiFieldType& actdt = MetaData()->ColFieldType(col);
00249
00250 if ( reqdt.IsCompatible(actdt) ) {
00251 Bool_t smaller = reqdt.IsSmaller(actdt);
00252 // Allow one character String to be stored in Char
00253 if ( reqdt.GetConcept() == Dbi::kChar && fValString.size() == 1
00254 ) smaller = kFALSE;
00255 if ( smaller ) {
00256 MAXMSG("Dbi",Msg::kWarning,20)
00257 << "In table " << TableNameTc()
00258 << " row " << fCurRow
00259 << " column "<< col
00260 << " (" << MetaData()->ColName(col) << ")"
00261 << " value \"" << fValString
00262 << "\" of type " << actdt.AsString()
00263 << " may be truncated before storing in " << reqdt.AsString()
00264 << endl;
00265 }
00266 }
00267 else {
00268 string udef = reqdt.UndefinedValue();
00269 MAXMSG("Dbi",Msg::kError,20)
00270 << "In table " << TableNameTc()
00271 << " row " << fCurRow
00272 << " column "<< col
00273 << " (" << MetaData()->ColName(col) << ")"
00274 << " value \"" << fValString
00275 << "\" of type " << actdt.AsString()
00276 << " is incompatible with user type " << reqdt.AsString()
00277 << ", value \"" << udef
00278 << "\" will be substituted." << endl;
00279 fValString = udef;
00280 }
00281
00282 return fValString;
00283 }
|
|
|
Definition at line 288 of file DbiResultSet.cxx. References DbiRowStream::CurColNum(), fCurRow, IsExhausted(), MAXMSG, DbiRowStream::NumCols(), and DbiRowStream::TableNameTc(). Referenced by CurColString(), and LoadCurValue(). 00288 {
00289 //
00290 //
00291 // Purpose: Test if current column exists.
00292 //
00293 // Arguments: None.
00294 //
00295 // Return: kTRUE if column exists.
00296 //
00297 // Contact: N. West
00298 //
00299 // Specification:-
00300 // =============
00301 //
00302 // o Test if current column exists.
00303
00304 // Program Notes:-
00305 // =============
00306
00307 // None.
00308
00309 Int_t col = CurColNum();
00310
00311 if ( IsExhausted() ) {
00312 MAXMSG("Dbi",Msg::kError,20)
00313 << "In table " << TableNameTc()
00314 << " attempting to access row " << fCurRow
00315 << " column " << col
00316 << " but only " << fCurRow << " rows in table." << endl;
00317 return kFALSE;
00318 }
00319
00320 int numCols = NumCols();
00321 if ( col > numCols ) {
00322 MAXMSG("Dbi",Msg::kError,20)
00323 << "In table " << TableNameTc()
00324 << " row " << fCurRow
00325 << " attempting to access column "<< col
00326 << " but only " << NumCols() << " in table ." << endl;
00327 return kFALSE;
00328 }
00329
00330 return kTRUE;
00331
00332 }
|
|
|
Definition at line 335 of file DbiResultSet.cxx. References CurColExists(), DbiRowStream::CurColNum(), and GetStringFromTSQL(). 00335 {
00336 //
00337 //
00338 // Purpose: Return current column as a string.
00339 //
00340 // Arguments: None.
00341 //
00342 // Return: Current column as a string (or null string if non-existant).
00343 //
00344 // Contact: N. West
00345 //
00346 // Specification:-
00347 // =============
00348 //
00349 // o Return current column as a string.
00350
00351 // Program Notes:-
00352 // =============
00353
00354 // None.
00355
00356 if ( ! CurColExists() ) return "";
00357
00358 TString valStr = this->GetStringFromTSQL(CurColNum());
00359 return valStr.Data();
00360
00361 }
|
|
|
Definition at line 62 of file DbiResultSet.h. References LoadCurValue(). Referenced by DbiConfigSet::Fill(), and DbiDBProxy::ReplaceSeqNoOracle(). 00062 { LoadCurValue(); return fValString;}
|
|
|
Definition at line 63 of file DbiResultSet.h. Referenced by DbiValidityRec::Fill(). 00063 { return fCurRow;}
|
|
|
Definition at line 365 of file DbiResultSet.cxx. References DbiRowStream::ClearCurCol(), fExhausted, fTSQLStatement, and IsExhausted(). Referenced by DbiResultNonAgg::DbiResultNonAgg(), DbiSqlValPacket::DbiSqlValPacket(), and DbiDBProxy::ReplaceSeqNoOracle(). 00365 {
00366
00367 //
00368 //
00369 // Purpose: Fetch next row of result set..
00370 //
00371 // Arguments: None.
00372 //
00373 // Return: kTRUE if row exists, kFALSE otherwise.
00374 //
00375 // Contact: N. West
00376 //
00377 // Specification:-
00378 // =============
00379 //
00380 // o Load next row with string lengths.
00381
00382 // Program Notes:-
00383 // =============
00384
00385 // None.
00386
00387 ClearCurCol();
00388 if ( IsExhausted() ) return kFALSE;
00389 ++fCurRow;
00390 if ( ! fTSQLStatement->NextResultRow() ) fExhausted = true;
00391 return ! fExhausted;
00392
00393 }
|
|
|
Definition at line 64 of file DbiResultSet.h. Referenced by DbiValidityRec::Fill(). 00064 { return fDbNo; }
|
|
|
Definition at line 65 of file DbiResultSet.h. Referenced by GetStringFromTSQL(). 00065 { return fDbType; }
|
|
|
Definition at line 66 of file DbiResultSet.h. 00066 { return fFillOpts;}
|
|
|
Definition at line 396 of file DbiResultSet.cxx. References DbiRowStream::ColFieldType(), fTSQLStatement, DbiFieldType::GetConcept(), GetDBType(), and MSG. Referenced by CurColString(), LoadCurValue(), and RowAsCsv(). 00396 {
00397 //
00398 //
00399 // Purpose: Get string from underlying TSQL interface
00400 //
00401 // N.B. No check that col is valid - caller beware.
00402 //
00403 // Specification:-
00404 // =============
00405 //
00406 // o Get string from underlying TSQL interface converting supported
00407 // binary characters for ORACLE text fields (ORACLE doesn't convert
00408 // external representation to binary on input).
00409 //
00410
00411 // Caution: Column numbering in TSQLStatement starts at 0.
00412 TString valStr = fTSQLStatement->GetString(col-1);
00413 if ( this->GetDBType() == Dbi::kOracle
00414 && this->ColFieldType(col).GetConcept() == Dbi::kString ) {
00415 MSG("Dbi",Msg::kDebug) << "ORACLE string conversion from: " << valStr << endl;
00416 valStr.ReplaceAll("\\n", "\n");
00417 valStr.ReplaceAll("\\t", "\t");
00418 valStr.ReplaceAll("\\\'","\'");
00419 valStr.ReplaceAll("\\\"","\"");
00420 valStr.ReplaceAll("\\\\","\\");
00421 MSG("Dbi",Msg::kDebug) << " to: " << valStr <<endl;
00422 }
00423 return valStr;
00424 }
|
|
|
Definition at line 67 of file DbiResultSet.h. Referenced by DbiValidityRec::Fill(). 00067 { return fTableProxy; }
|
|
|
IsBeforeFirst not needed for ROOT API, but leave a dummy for now so as not to disturb DbiResultSet API. Definition at line 70 of file DbiResultSet.h. Referenced by DbiResultNonAgg::DbiResultNonAgg(), and DbiDBProxy::ReplaceSeqNoOracle(). 00070 { return false; };
|
|
|
Definition at line 71 of file DbiResultSet.h. Referenced by CurColExists(), DbiResultAgg::DbiResultAgg(), DbiResultNonAgg::DbiResultNonAgg(), DbiSqlValPacket::DbiSqlValPacket(), FetchRow(), and DbiDBProxy::ReplaceSeqNoOracle(). 00071 { return fExhausted; }
|
|
|
Definition at line 428 of file DbiResultSet.cxx. References CurColExists(), DbiRowStream::CurColFieldType(), DbiRowStream::CurColNum(), fTSQLStatement, fValString, DbiFieldType::GetConcept(), GetStringFromTSQL(), DbiFieldType::GetType(), and len. Referenced by AsString(), and CurColValue(). 00428 {
00429 //
00430 //
00431 // Purpose: Load current value into buffer fValString
00432 //
00433 // Arguments: None.
00434 //
00435 // Return: kTRUE if current column in range, otherwise kFALSE.
00436 //
00437 // Contact: N. West
00438 //
00439 // Specification:-
00440 // =============
00441 //
00442 // o Load current value into buffer fValString stripping off any
00443 // enclosing quotes.
00444
00445
00446 fValString.clear();
00447
00448 if ( ! CurColExists() ) return kFALSE;
00449
00450 Int_t col = CurColNum();
00451 TString valStr = this->GetStringFromTSQL(col);
00452
00453 // For floating point, use binary interface to preserve precision
00454 // e.g.-1.234567890123457e-100 as string is -0.000000
00455 if ( CurColFieldType().GetConcept() == Dbi::kFloat ) {
00456 ostringstream out;
00457 out << setprecision(8);
00458 if ( CurColFieldType().GetType() == Dbi::kDouble ) out << setprecision(16);
00459 // Caution: Column numbering in TSQLStatement starts at 0.
00460 out << fTSQLStatement->GetDouble(col-1);
00461 valStr = out.str().c_str();
00462 }
00463 int len = valStr.Length();
00464
00465
00466
00467 const char* pVal = valStr.Data();
00468 // Remove leading and trailing quotes if dealing with a string.
00469 if ( len >= 2
00470 && ( *pVal == *(pVal+len-1) )
00471 && ( *pVal == '\'' || *pVal == '"' ) ) {
00472 ++pVal;
00473 len -= 2;
00474 }
00475 fValString.assign(pVal,len);
00476
00477 return kTRUE;
00478
00479 }
|
|
|
Definition at line 193 of file DbiResultSet.cxx. References AsString(), and Dbi::MakeTimeStamp(). 00193 {
00194 dest=Dbi::MakeTimeStamp(AsString(Dbi::kDate)); return *this;}
|
|
|
Definition at line 191 of file DbiResultSet.cxx. References AsString(). 00191 {
00192 dest = AsString(Dbi::kString); return *this;}
|
|
|
Definition at line 186 of file DbiResultSet.cxx. References IN2. 00186 {
00187 IN2(Dbi::kDouble,GetDouble);return *this;}
|
|
|
Definition at line 184 of file DbiResultSet.cxx. References IN2. 00184 {
00185 IN2(Dbi::kFloat,GetDouble); return *this;}
|
|
|
Definition at line 182 of file DbiResultSet.cxx. References IN3. 00182 {
00183 IN3(Long_t); return *this;}
|
|
|
Definition at line 180 of file DbiResultSet.cxx. References IN2. 00180 {
00181 IN2(Dbi::kLong, GetLong); return *this;}
|
|
|
Definition at line 178 of file DbiResultSet.cxx. References IN3. 00178 {
00179 IN3(Int_t); return *this;}
|
|
|
Definition at line 176 of file DbiResultSet.cxx. References IN2. 00176 {
00177 IN2(Dbi::kInt,GetInt); return *this;}
|
|
|
Definition at line 174 of file DbiResultSet.cxx. References IN3. 00174 {
00175 IN3(Short_t); return *this;}
|
|
|
Definition at line 172 of file DbiResultSet.cxx. References IN2. 00172 {
00173 IN2(Dbi::kInt,GetInt); return *this;}
|
|
|
Definition at line 170 of file DbiResultSet.cxx. References IN. 00170 {
00171 IN(Dbi::kChar) >> dest; return *this;}
|
|
|
Definition at line 168 of file DbiResultSet.cxx. References IN. 00168 {
00169 IN(Dbi::kBool) >> dest; return *this;}
|
|
|
Definition at line 482 of file DbiResultSet.cxx. References DbiTableMetaData::ColFieldConcept(), DbiTableMetaData::ColFieldType(), DbiTableMetaData::ColMustDelimit(), fTSQLStatement, GetStringFromTSQL(), DbiFieldType::GetType(), UtilString::MakePrintable(), DbiRowStream::MetaData(), and DbiRowStream::NumCols(). Referenced by DbiSqlValPacket::DbiSqlValPacket(). 00482 {
00483 //
00484 //
00485 // Purpose: Append row as a Comma Separated Values string.
00486 //
00487 // Arguments:
00488 // row in String to append to.
00489 //
00490
00491 const DbiTableMetaData* md = this->MetaData();
00492
00493 Int_t maxCol = this->NumCols();
00494 for (Int_t col = 1; col <= maxCol; ++col) {
00495 // Deal with NULL values. Caution: Column numbering in TSQLStatement starts at 0.
00496 if ( fTSQLStatement->IsNull(col-1) ) {
00497 row += "NULL";
00498 if ( col < maxCol ) row += ',';
00499 continue;
00500 }
00501 Bool_t mustDelimit = md->ColMustDelimit(col);
00502 UInt_t concept = md->ColFieldConcept(col);
00503 if ( mustDelimit ) row += '\'';
00504 TString str = this->GetStringFromTSQL(col);
00505 const char* value = str.Data();
00506
00507 // Make strings printable.
00508 if ( concept == Dbi::kString ) UtilString::MakePrintable(value,row);
00509
00510 // For floating point, use binary interface to preserve precision
00511 // e.g.-1.234567890123457e-100 as string is -0.000000
00512 else if ( concept == Dbi::kFloat ) {
00513 ostringstream out;
00514 out << setprecision(8);
00515 if ( md->ColFieldType(col).GetType() == Dbi::kDouble ) out << setprecision(16);
00516 out << fTSQLStatement->GetDouble(col-1);
00517 row += out.str();
00518 }
00519
00520 // Everything else (!) is O.K.
00521 else row += value;
00522
00523 if ( mustDelimit ) row += '\'';
00524 if ( col < maxCol ) row += ',';
00525 }
00526 }
|
|
|
Current row in query (0...).
Definition at line 100 of file DbiResultSet.h. Referenced by AsString(), and CurColExists(). |
|
|
Cascade no. of source.
Definition at line 103 of file DbiResultSet.h. |
|
|
Type of database fDbNo.
Definition at line 106 of file DbiResultSet.h. |
|
|
True is result set missing or exhausted.
Definition at line 118 of file DbiResultSet.h. Referenced by FetchRow(). |
|
|
Optional fill options.
Definition at line 127 of file DbiResultSet.h. |
|
|
Owned DbiStatement. May be 0. It's only use is to create a TSQLStatement in the ctor but it is not destroyed until the dtor to prevent a premature attempt to close the connection. Definition at line 112 of file DbiResultSet.h. Referenced by ~DbiResultSet(). |
|
|
DbiTableProxy that produced this set.
Definition at line 121 of file DbiResultSet.h. |
|
|
Pointer to owned statement, may be 0.
Definition at line 115 of file DbiResultSet.h. Referenced by FetchRow(), GetStringFromTSQL(), LoadCurValue(), RowAsCsv(), and ~DbiResultSet(). |
|
|
Buffer for assembling value.
Definition at line 124 of file DbiResultSet.h. Referenced by AsString(), and LoadCurValue(). |
1.3.9.1