32 const
string& fillOpts) :
40 fTableProxy(tableProxy),
46 fDbType = stmtDb->GetDBType();
47 fTSQLStatement = stmtDb->ExecuteQuery(sql.c_str());
48 if ( fTSQLStatement && fTSQLStatement->NextResultRow() ) { fExhausted =
false; }
62 #define IN(t) istringstream in(AsString(t)); in
67 int col = CurColNum()-1; \
68 if ( CurRowNum() == 0 ) { \
69 istringstream in(AsString(t)); \
73 dest = fTSQLStatement->m(col); \
87 int col = this->CurColNum()-1; \
88 const FairDbFieldType& fType = this->ColFieldType(col+1); \
89 if ( fType.GetSize() == 8 ) { \
90 dest=fTSQLStatement->GetUInt(col); \
94 *this >> dest_signed; \
96 if ( fType.GetSize() == 1 ) dest &= 0xff; \
97 if ( fType.GetSize() == 2 ) dest &= 0xffff; \
98 if ( fType.GetSize() == 4 ) dest &= 0xffffffff; \
178 cout <<
"-I- FairDbResultSet "
179 <<
"... value \"" << udef
180 <<
"\" will be substitued." << endl;
193 ) { smaller = kFALSE; }
196 cout <<
"-I- FairDbResultSet "
202 <<
"\" of type " << actdt.
AsString()
203 <<
" may be truncated before storing in " << reqdt.
AsString()
208 cout <<
"-I- FairDbResultSet "
214 <<
"\" of type " << actdt.
AsString()
215 <<
" is incompatible with user type " << reqdt.
AsString()
216 <<
", value \"" << udef
217 <<
"\" will be substituted." << endl;
230 cout <<
"-I- FairDbResultSet "
232 <<
" attempting to access row " <<
fCurRow
234 <<
" but only " <<
fCurRow <<
" rows in table." << endl;
239 if ( col > numCols ) {
240 cout <<
"-I- FairDbResultSet "
243 <<
" attempting to access column "<< col
244 <<
" but only " <<
NumCols() <<
" in table ." << endl;
257 return valStr.Data();
275 cout <<
"-I- FairDbResultSet" <<
276 "ORACLE string conversion from: " << valStr << endl;
277 valStr.ReplaceAll(
"\\n",
"\n");
278 valStr.ReplaceAll(
"\\t",
"\t");
279 valStr.ReplaceAll(
"\\\'",
"\'");
280 valStr.ReplaceAll(
"\\\"",
"\"");
281 valStr.ReplaceAll(
"\\\\",
"\\");
282 cout <<
" to: " << valStr <<endl;
304 valStr = out.str().c_str();
306 int len = valStr.Length();
310 const char* pVal = valStr.Data();
313 && ( *pVal == *(pVal+len-1) )
314 && ( *pVal ==
'\'' || *pVal ==
'"' ) ) {
327 Int_t maxCol = this->
NumCols();
328 for (Int_t col = 1; col <= maxCol; ++col) {
332 if ( col < maxCol ) { row +=
','; }
337 if ( mustDelimit ) { row +=
'\''; }
339 const char*
value = str.Data();
355 else { row +=
value; }
357 if ( mustDelimit ) { row +=
'\''; }
358 if ( col < maxCol ) { row +=
','; }
381 if ( that ) { *
this = *that; }
390 fTableName(tableName),
430 if (
fVRecKeys.empty() ) { os <<
" No vrecs"; }
433 if ( fNumVRecKeys > 1 ) { os <<
"s (seqno min..max;creationdate min..max):"; }
434 else { os <<
" (seqno;creationdate):"; }
436 std::list<VRecKey>::const_iterator itr =
fVRecKeys.begin();
437 std::list<VRecKey>::const_iterator itrEnd =
fVRecKeys.end();
438 UInt_t seqnoMin = itr->SeqNo;
439 UInt_t seqnoMax = seqnoMin;
443 while ( itr != itrEnd ) {
444 UInt_t seqno = itr->SeqNo;
446 if ( seqno < seqnoMin ) { seqnoMin = seqno; }
447 if ( seqno > seqnoMax ) { seqnoMax = seqno; }
448 if ( ts < tsMin ) { tsMin = ts; }
449 if ( ts > tsMax ) { tsMax = ts; }
453 if ( seqnoMin < seqnoMax ) { os <<
".." << seqnoMax; }
455 if ( tsMin < tsMax ) { os <<
".." << tsMax.
AsString(
"s"); }
457 return string(os.str());
471 cout <<
"Comparing " << *
this <<
" to "
481 if ( numVrecs == 0 ) {
return 0.; }
483 std::map<UInt_t,ValTimeStamp> seqnoToCreationDate;
484 std::list<FairDbResultKey::VRecKey>::const_iterator itrEnd = keyBig->
fVRecKeys.end();
485 for ( std::list<FairDbResultKey::VRecKey>::const_iterator itr = keyBig->
fVRecKeys.begin();
487 ++itr ) { seqnoToCreationDate[itr->SeqNo] = itr->CreationDate; }
490 for ( std::list<FairDbResultKey::VRecKey>::const_iterator itr = keySmall->
fVRecKeys.begin();
493 cout <<
"Comparing seqno " << itr->SeqNo <<
" with creation date " << itr->CreationDate
494 <<
" to " << seqnoToCreationDate[itr->SeqNo] << endl;
495 if ( seqnoToCreationDate[itr->SeqNo] == itr->CreationDate ) { ++match; }
497 cout <<
"Match results: " << match <<
" out of " << numVrecs << endl;
499 return match/numVrecs;
525 const
string& sqlQualifiers) :
531 typedef map<UInt_t,UInt_t> seqToRow_t;
533 SetTableName(tableName);
534 if ( ! tableRow || ! cache || ! vrecBuilder || ! proxy ) {
return; }
540 string::size_type loc = sqlQualifiers.find(
';');
541 string::size_type loc2 = sqlQualifiers.find(
';',loc+1);
542 string sqlData = string(sqlQualifiers,loc+1,loc2-loc-1);
543 string fillOpts = string(sqlQualifiers,loc2+1);
548 vector<UInt_t> reqSeqNos;
553 Int_t maxRowNo = vrecBuilder->GetNumValidityRec() - 1;
557 for ( Int_t rowNo = 1; rowNo <= maxRowNo; ++rowNo ) {
561 const FairDbResult* res = cache->Search(vrecRow,sqlQualifiers);
562 cout <<
"Checking validity rec " << rowNo
564 <<
"SQL qual: " << sqlQualifiers
565 <<
" cache search: " << (
void*) res << endl;
567 fResults.push_back(res);
574 else if ( vrecRow.
IsGap() ) {
576 cache->Adopt(newRes,
false);
577 fResults.push_back(newRes);
584 reqSeqNos.push_back(seqNo);
585 seqToRow[seqNo] = rowNo;
586 fResults.push_back(0);
596 if ( reqSeqNos.size() ) {
599 sort(reqSeqNos.begin(),reqSeqNos.end());
600 FairDbResultSet* rs = proxy->QuerySeqNos(reqSeqNos,dbNo,sqlData,fillOpts);
602 this->SetResultsFromDb();
604 while ( ! rs->IsExhausted() ) {
607 rs->DecrementCurCol();
609 if ( seqToRow.find(seqNo) == seqToRow.end() ) {
611 cout <<
"Unexpected SeqNo: " << seqNo << endl;
614 rowNo = seqToRow[seqNo];
616 <<
"Procesing SeqNo: " << seqNo
617 <<
" for row " << rowNo << endl;
623 if ( this->IsExtendedContext() ) { newRes->
SetCanReuse(
false); }
628 <<
"SeqNo: " << seqNo
629 <<
" produced " << newRes->
GetNumRows() <<
" rows" << endl;
632 cache->Adopt(newRes,
false);
633 fResults[rowNo-1] = newRes;
647 fRowKeys.reserve(fSize);
650 for ( Int_t rowNo = 1; rowNo <= maxRowNo; ++rowNo ) {
656 const FairDbResult* res = fResults[rowNo-1];
659 for (UInt_t entNo = 0; entNo < numEnt; ++entNo ) {
667 this->BuildLookUpTable();
671 SetValidityRec(vRec);
674 <<
"Aggregate contains " << fSize <<
" entries. vRec:-" << endl
677 cout <<
"Created aggregated result set no. of rows: "
678 << this->GetNumRows() << endl;
684 for ( ConstResultItr_t itr = fResults.begin();
685 itr != fResults.end();
686 ++itr)
if ( *itr ) { (*itr)->Disconnect(); }
699 for ( ConstResultItr_t itr = fResults.begin();
700 itr != fResults.end();
702 const FairDbResult* result = *itr;
705 if ( ! key ) { key = result->
CreateKey(); }
724 return ( row >= fRowKeys.size() ) ? 0 : fRowKeys[row];
734 FairDbResult* owner = row->
GetOwner();
742 <<
"Trying to satisfy: SQL: " << sqlQualifiers
743 <<
"\n with CanReuse: " << this->
CanReuse()
753 vector<const FairDbResult*>::const_iterator itr = fResults.begin();
754 vector<const FairDbResult*>::const_iterator end = fResults.end();
756 UInt_t numNonAgg = 0;
757 for (; itr != end; ++itr) {
764 for (itr = fResults.begin(); itr != end; ++itr) {
779 Int_t FairDbResult::fgLastID(0);
784 FairDbResult& res_tmp =
const_cast< FairDbResult&
>(res);
800 const string& sqlQualifiers) :
806 fResultsFromDb(kFALSE),
808 fTableName(
"Unknown"),
809 fSqlQualifiers(sqlQualifiers),
820 fCanReuse(from.fCanReuse),
821 fEffVRec(from.fEffVRec),
822 fIndexKeys(from.fIndexKeys),
824 fResultsFromDb(from.fResultsFromDb),
825 fNumClients(from.fNumClients),
826 fTableName(from.fTableName),
827 fSqlQualifiers(from.fSqlQualifiers),
828 fExceptionLog(from.fExceptionLog)
837 cout <<
"Warning: Destroying FairDbResult with " <<
fNumClients
838 <<
" clients " << endl;
862 cout <<
"Building look-uptable. Allow duplicates: "
863 << duplicatesOK << endl;
869 UInt_t index = row->
GetIndex(rowNo);
877 <<
"Look-up. Row no " << rowNo
878 <<
" index " << index
879 <<
" row,row2 " << (
void*) row <<
"," << (
void*) row2 << endl;
881 if ( row2 != 0 && row2 != row && ! duplicatesOK ) {
882 std::ostringstream msg;
883 msg <<
"Duplicated row natural index: " << index
884 <<
" Found at row " << rowNo
890 cout << msg.str() << endl;
912 if ( !
fKey ) {
return; }
934 IndexToRow_t::const_iterator idx =
fIndexKeys.find(index);
935 return ( idx ==
fIndexKeys.end() ) ? 0 : (*idx).second;
972 <<
" Checking result with FairDbValidityRec:- \n " << this->
GetValidityRec()
973 <<
" With extended context: " << isExtendedContext
974 <<
" CanReuse: " << canReuse
975 <<
" Is Compatible: " << isCompatible
976 <<
" HasExpired: " << hasExpired
977 <<
" number of clients: " << numClients
980 if ( isExtendedContext ) {
return kFALSE; }
982 if ( canReuse && isCompatible ) {
return kTRUE; }
988 if ( canReuse && hasExpired && numClients == 0 ) {
989 cout <<
" Marking result as not reusable" << endl;
1001 cout <<
" Restoring FairDbResult ..." << endl;
1004 cout <<
" Restored " <<
fEffVRec << endl;
1008 cout <<
" Restored string " << fTableName << endl;
1010 cout <<
" Saving FairDbResult ..." << endl;
1012 cout <<
" Saving " <<
fEffVRec << endl;
1014 cout <<
" Saving string " <<
fTableName << endl;
1026 const
string& sqlQualifiers)
1027 : FairDbResult(resultSet,vrec,sqlQualifiers),
1033 if ( ! resultSet || resultSet->IsExhausted() || ! tableRow ) {
return; }
1044 if ( dropSeqNo && rs.
CurColName() ==
"SEQNO" ) {
1061 if ( nextSeqNo != seqNo ) {
1074 fRows.push_back(row);
1080 this->SetResultsFromDb();
1082 cout <<
"Created unaggregated VAL result set no. of rows: "
1083 << this->GetNumRows() << endl;
1084 else cout <<
"Created unaggregated result set for SeqNo: " << seqNo
1085 <<
" no. of rows: " << this->GetNumRows() << endl;
1093 if ( !
fBuffer )
for ( vector<FairDbTableRow*>::iterator itr =
fRows.begin();
1095 ++itr) {
delete *itr; }
1105 string rowName(
"empty_table");
1107 if ( row ) { rowName = row->GetName(); }
1118 if (
this == that ) {
1119 cout <<
"debug " << (
void*)
this << endl;
1126 if ( rowNum >=
fRows.size() ) {
return 0; }
1127 return fRows[rowNum];
1139 vector<FairDbTableRow*>::const_iterator itr =
fRows.begin();
1140 vector<FairDbTableRow*>::const_iterator itrEnd =
fRows.end();
1142 for (; itr != itrEnd; ++itr)
if ( *itr == row ) {
return kTRUE; }
1150 const string& sqlQualifiers)
1152 cout <<
"Trying to satisfy: Vrec " << vrec <<
" SQL: " << sqlQualifiers
1153 <<
"\n with CanReuse: " << this->
CanReuse()
1174 cout <<
" Restoring FairDbResultNonAgg ..." << endl;
1179 cout <<
" Restored FairDbResultNonAgg. Size:"
1180 << fRows.size() <<
" rows" << endl;
1183 cout <<
" Saving FairDbResultNonAgg. Size:"
1184 <<
fRows.size() <<
" rows" << endl;