4 #include "TCollection.h"
6 #include "TSQLColumnInfo.h"
7 #include "TSQLStatement.h"
8 #include "TSQLServer.h"
9 #include "TSQLTableInfo.h"
30 const
string& tableName,
34 fMultConnector(cascader),
36 fMetaValid(metaValid),
38 fTableName(tableName),
39 fTableNameUc(FairUtilString::
ToUpper(tableName)),
40 fTableProxy(tableProxy),
43 if ( fTableName != fTableNameUc ) { fValSuffix =
"Validity"; }
59 cout <<
"FindTimeBoundaries for table " <<
fTableName
62 <<
" Earliest creation date " << earliestCreate
63 <<
" database " << dbNo << endl;
73 time_t vcSec = curVTS.
GetSec() - timeGate;
89 for (
int i_limit =1; i_limit <= 4; ++i_limit ) {
91 if ( i_limit == 1 ) sql <<
"min(TIMESTART) from " <<
fTableName
92 <<
"VAL where TIMESTART > '" << endGateString <<
"' ";
93 if ( i_limit == 2 ) sql <<
"min(TIMEEND) from " <<
fTableName
94 <<
"VAL where TIMEEND > '" << endGateString <<
"' ";
95 if ( i_limit == 3 ) sql <<
"max(TIMESTART) from " <<
fTableName
96 <<
"VAL where TIMESTART < '" << startGateString <<
"' ";
97 if ( i_limit == 4 ) sql <<
"max(TIMEEND) from " <<
fTableName
98 <<
"VAL where TIMEEND < '" << startGateString <<
"' ";
99 sql <<
" and DetectorMask & " <<
static_cast<unsigned int>(detType)
100 <<
" and SimMask & " << static_cast<unsigned int>(simFlg)
101 <<
" and CREATIONDATE >= '" << earliestCreateString <<
"'"
102 <<
" and Task = " << task;
103 cout <<
" FindTimeBoundaries query no. " << i_limit
104 <<
" SQL:" <<sql.
c_str() << endl;
106 auto_ptr<TSQLStatement> stmt(stmtDb->ExecuteQuery(sql.
c_str()));
107 stmtDb->PrintExceptions(0);
111 if ( ! stmt.get() || ! stmt->NextResultRow() || stmt->IsNull(0) ) {
continue; }
112 date = stmt->GetString(0);
113 if ( date.IsNull() ) {
continue; }
115 cout <<
" FindTimeBoundaries query result: " << ts << endl;
116 if ( i_limit <= 2 && ts < end ) { end = ts; }
117 if ( i_limit >= 3 && ts > start ) { start = ts; }
121 cout <<
"FindTimeBoundaries for table " <<
fTableName
122 <<
" found " << start <<
" .. " << end << endl;
140 else { sql <<
" and "; }
141 sql <<
"seqno = " << seqNo;
145 cout <<
"Database: " << dbNo
146 <<
" query: " << sql.
GetString() << endl;
161 sql <<
"select * from " <<
fTableName <<
" where "
162 <<
" SEQNO= " << seqNo;
165 sql <<
" order by ROW_COUNTER";
168 cout <<
"Database: " << dbNo
169 <<
" SeqNo query: " << sql.
c_str() << endl;
178 const string& sqlData,
179 const string& fillOpts)
const
181 if ( seqNos.size() == 0 ) {
return 0; }
185 sql <<
"select * from " <<
fTableName <<
" where ";
187 if ( sqlData !=
"" ) { sql <<
"( "; }
188 Bool_t first = kTRUE;
189 SeqList_t::const_iterator itr1 = seqNos.begin();
191 while ( itr1 != seqNos.end() ) {
194 SeqList_t::const_iterator itr2 = itr1;
195 while ( itr2 != seqNos.end() && seq2 == *itr2 ) {
204 if ( seq2 > seq1 + 1) {
205 sql <<
"SEQNO between " << seq1 <<
" and " << seq2-1 <<
' ';
208 sql <<
"SEQNO = " << seq1 <<
' ';
213 if ( sqlData !=
"" ) { sql <<
") and " <<
"(" << sqlData <<
")" <<
" "; }
215 sql <<
"order by SEQNO";
218 sql <<
",ROW_COUNTER";
221 cout <<
"Database: " << dbNo
222 <<
" SeqNos query: " << sql.
c_str() << endl;
236 time_t vcSec = curVTS.
GetSec() - timeGate;
251 context <<
" TimeStart <= '" << endGateString <<
"' "
252 <<
"and TimeEnd > '" << startGateString <<
"' "
253 <<
"and DetectorMask & " <<
static_cast<unsigned int>(detType)
254 <<
" and SimMask & " << static_cast<unsigned int>(simFlg);
278 string orderByName(
"CREATIONDATE");
280 orderByName =
"TIMESTART";
288 ) sql <<
" and Task = " << task
289 <<
" order by " << orderByName <<
" desc;" <<
'\0';
291 cout <<
"Database: " << dbNo
292 <<
" query: " << sql.
c_str() << endl;
310 sql <<
"SEQNO = " << seqNo <<
";";
312 cout <<
"Database: " << dbNo
313 <<
" SEQNO query: " << sql.
c_str() << endl;
328 <<
" where SEQNO = " << seqNo <<
";"
331 cout <<
"Database: " << dbNo
332 <<
" RemoveSeqNo SQL: " << sql.
c_str() << endl;
336 if ( ! stmtDb.get() ) {
return false; }
337 if ( ! stmtDb->ExecuteUpdate(sql.
c_str()) || stmtDb->PrintExceptions() ) {
338 cout <<
"SQL: " << sql.
c_str()
339 <<
" Failed. " << endl;
346 <<
" where SEQNO = " << seqNo <<
";"
349 cout <<
"Database: " << dbNo
350 <<
" RemoveSeqNo SQL: " << sql.
c_str() << endl;
353 if ( ! stmtDb->ExecuteUpdate(sql.
c_str()) || stmtDb->PrintExceptions() ) {
354 cout <<
"SQL: " << sql.
c_str()
355 <<
" Failed. " << endl;
371 <<
" set INSERTDATE = \'" << ts.
AsString(
"s")
372 <<
"\' where SEQNO = " << SeqNo <<
";"
375 cout <<
"Database: " << dbNo
376 <<
" ReplaceInsertDate SQL: "
377 << sql.
c_str() << endl;
381 if ( ! stmtDb.get() ) {
return false; }
382 if (! stmtDb->ExecuteUpdate(sql.
c_str()) || stmtDb->PrintExceptions() ) {
383 cout <<
"SQL: " << sql.
c_str()
384 <<
" Failed. " << endl;
400 <<
"Cannot renumber " << oldSeqNo
401 <<
" no connection to cascade entry " << dbNo << endl;
412 <<
" set SEQNO = " << newSeqNo
413 <<
" where SEQNO = " << oldSeqNo <<
";"
416 cout <<
"Database: " << dbNo
417 <<
" ReplaceSeqNo SQL: " << sql.
c_str() << endl;
421 if ( ! stmtDb.get() ) {
return false; }
422 if ( ! stmtDb->ExecuteUpdate(sql.
c_str()) || stmtDb->PrintExceptions() ) {
423 cout <<
"SQL: " << sql.
c_str()
424 <<
" Failed. " << endl;
431 <<
" set SEQNO = " << newSeqNo
432 <<
" where SEQNO = " << oldSeqNo <<
";"
435 cout <<
"Database: " << dbNo
436 <<
" ReplaceSeqNo SQL: " << sql.
c_str() << endl;
439 if ( ! stmtDb->ExecuteUpdate(sql.
c_str()) || stmtDb->PrintExceptions() ) {
440 cout <<
"SQL: " << sql.
c_str()
441 <<
" Failed. " << endl;
457 cout <<
"Cannot renumber " << oldSeqNo
458 <<
" it does not exist" << endl;
467 <<
" values (" << newSeqNo;
470 UInt_t numCols =rsOld->
NumCols();
471 for (UInt_t iCol = 2; iCol <= numCols; ++iCol) {
477 sql <<
"," << delim << rsOld->
CurColValue() << delim ;
481 cout <<
"Database: " << dbNo
482 <<
" ReplaceSeqNo SQL (insert new VAL): " << sql.
c_str() << endl;
487 if ( ! stmtDb.get() ) {
return false; }
488 if ( ! stmtDb->ExecuteUpdate(sql.
c_str()) || stmtDb->PrintExceptions() ) {
489 cout <<
"SQL: " << sql.
c_str()
490 <<
" Failed. " << endl;
497 <<
" set SEQNO = " << newSeqNo
498 <<
" where SEQNO = " << oldSeqNo <<
";";
500 cout <<
"Database: " << dbNo
501 <<
" ReplaceSeqNo SQL (rename main entry): " << sql.
c_str() << endl;
504 if ( ! stmtDb->ExecuteUpdate(sql.
c_str()) || stmtDb->PrintExceptions() ) {
505 cout <<
"SQL: " << sql.
c_str()
506 <<
" Failed. " << endl;
513 <<
" where SEQNO = " << oldSeqNo <<
";";
515 cout <<
"Database: " << dbNo
516 <<
" ReplaceSeqNo SQL (delete old VAL): " << sql.
c_str() << endl;
519 if ( ! stmtDb->ExecuteUpdate(sql.
c_str()) || stmtDb->PrintExceptions() ) {
520 cout <<
"SQL: " << sql.
c_str()
521 <<
" Failed. " << endl;
533 const char* tableName = metaData.
TableName().c_str();
534 cout <<
"Get meta-data for table: " << tableName << endl;
540 TSQLServer* server = connection->
GetServer();
541 if ( ! server ) {
continue; }
543 TSQLTableInfo* meta = server->GetTableInfo(tableName);
548 cout <<
"Meta-data query succeeded on cascade entry " << dbNo << endl;
553 const TList* cols = meta->GetColumns();
556 while ( TSQLColumnInfo* colInfo = dynamic_cast<TSQLColumnInfo*>(colItr.Next()) ) {
559 string name(colInfo->GetName());
564 colInfo->GetLength(),
565 colInfo->GetTypeName());
568 if ( !colInfo->IsSigned() ) { fldType.
SetUnsigned(); }
574 cout <<
"Column " << col <<
" " << name
575 <<
" SQL type " << colInfo->GetSQLType()
576 <<
" SQL type name " << colInfo->GetTypeName()
577 <<
" DBI type " << fldType.AsString()
578 <<
" data size: " << fldType.GetSize()
579 <<
" col size: " << colInfo->GetLength() << endl;