70 fSeqNo(vrec.GetSeqNo()),
75 fTableName(vrec.GetTableProxy()->GetTableName()),
76 fCreationDate(vrec.GetCreationDate())
84 this->
AddRow(tableProxy,0,vrec);
119 cout <<
"Cannot add data row - packet does not have a VAL row" << endl;
124 return this->
AddRow(tblProxy,vrec,row);
133 string sql(
"INSERT INTO ");
136 sql +=
" VALUES (" + row +
");";
163 row.
Store(outRow,vrec);
167 cout <<
"Incomplete data supplied for row " << this->
GetNumSqlStmts()-1
182 const Char_t* thisName,
183 const Char_t* thatName )
const
191 std::vector<std::string> valuesThis = this->
GetStmtValues(0);
195 int comp = valuesThis[7].compare(valuesThat[7]);
199 cout <<
" Difference classified as Update" << endl;
202 }
else if ( comp > 0 ) {
204 cout <<
" Difference classified as OutOfDate" << endl;
223 .CreateStatement(dbNo));
224 if ( ! stmtDb.get() ) {
226 cout <<
"Attempting to write to non-existant cascade entry " << dbNo
232 cout <<
"No SQL available to create table " <<
fTableName
233 <<
" in cascade entry: " << dbNo << endl;
253 enum { kLOOKING_FOR_HEADER,
255 } state = kLOOKING_FOR_HEADER;
263 UInt_t seqNoHead = 0;
264 UInt_t seqNoTrail = 0;
274 while ( ! is.eof() ) {
278 if (line.size() == 0 ) {
continue; }
281 if ( state == kLOOKING_FOR_HEADER ) {
282 if ( line.substr(0,5) ==
">>>>>" ) {
283 if ( line.size() >= kHEADER_TRAILER_MAX_LEN ) {
284 Report(
"Bad header",lineNum,line);
289 if ( line.find(
"Metadata") != string::npos ) {
299 if ( line.substr(0,5) !=
"<<<<<"
300 || line.find(
"Metadata") == string::npos ) {
301 Report(
"Bad metadata",lineNum,line);
306 if ( line.size() >= kHEADER_TRAILER_MAX_LEN ) {
307 Report(
"Bad header",lineNum,line);
313 istringstream istr(line.substr(5));
315 istr >> nameHead >> seqNoHead;
316 if ( ! istr.eof() ) {
317 Report(
"Input error",lineNum,line);
322 state = kLOOKING_FOR_TRAILER;
325 Report(
"Not header",lineNum,line);
332 if ( line.substr(0,5) ==
"<<<<<" ) {
333 if ( line.size() >= kHEADER_TRAILER_MAX_LEN
334 ) { msg =
"Bad trailer"; }
339 istringstream istr(line.substr(5));
341 istr >> nameTrail >> seqNoTrail;
342 if ( ! istr.eof() ) { msg =
"Input error"; }
344 else if ( nameTrail != nameHead
345 || seqNoHead != seqNoTrail ) {
346 msg =
"Header/Trailer mismatch: Header: ";
349 ) { msg =
"No SQL statements between Header/Trailer"; }
360 date.erase(date.size()-1,1);
364 std::vector<std::string> ls;
367 if (ls.size() >= 7 && ls[6] !=
"-1") {
368 static bool warnOnce =
true;
371 cout <<
"Setting aggregate number for DBUSUBRUNSUMMARY = -1\n"
372 <<
" Expect this message once. DBUSUBRUNSUMMARY needs to be "
373 <<
" fixed!" << endl;
378 for (
unsigned i=1; i<ls.size(); ++i ) { sql +=
"," + ls[i]; }
389 Report(msg.c_str(),lineNum,line);
390 state = kLOOKING_FOR_HEADER;
397 if ( sql[sql.size()-1] ==
';') {
407 if ( state != kLOOKING_FOR_HEADER
408 ) {
Report(
"Unexpected EOF",lineNum,
"EOF"); }
422 std::list<std::string>::const_iterator itr =
fSqlStmts.begin();
423 while ( stmtNo ) { ++itr; --stmtNo; }
433 std::vector<std::string> vec;
437 std::string str = this->
GetStmt(stmtNo);
440 std::string::size_type
pos = str.find(
'(');
442 std::string::size_type
n = str.find(
')') -
pos;
453 const Char_t* thisName,
454 const Char_t* thatName )
const
460 if ( log ) cout <<
"Conflict found:"
461 <<
" for : " << thisName <<
" , " << thatName <<
" :-\n"
469 list<string>::const_iterator itrThisBegin =
fSqlStmts.begin();
470 list<string>::const_iterator itrThisEnd =
fSqlStmts.end();
471 list<string>::const_iterator itrThatBegin = that.
fSqlStmts.begin();
472 list<string>::const_iterator itrThatEnd = that.
fSqlStmts.end();
474 list<string>::const_iterator itrThis = itrThisBegin;
475 list<string>::const_iterator itrThat = itrThatBegin;
477 Bool_t isEqual = kTRUE;
482 string strThis = (*itrThis).substr(0,(*itrThis).rfind(
','));
483 string strThat = (*itrThat).substr(0,(*itrThat).rfind(
','));
484 if ( strThis != strThat ) {
485 if ( ! log ) {
return kFALSE; }
488 cout <<
"Difference on VAL record " <<
":-\n"
489 <<
" " << thisName <<
": " << strThis << endl
490 <<
" " << thatName <<
": " << strThat << endl;
501 while ( itrThis != itrThisEnd && (*itrThis) == (*itrThat) ) {
507 if ( itrThis == itrThisEnd ) {
return isEqual; }
509 itrThis = itrThisBegin;
510 itrThat = itrThatEnd;
514 while ( itrThis != itrThisEnd && (*itrThis) == (*itrThat) ) {
520 if ( itrThis == itrThisEnd ) {
return isEqual; }
525 typedef vector<const string*> shadow_list_t;
526 typedef shadow_list_t::iterator shadow_list_itr_t;
528 shadow_list_t shadowThis;
529 shadow_list_t shadowThat;
531 itrThis = itrThisBegin;
532 itrThat = itrThatBegin;
536 while ( itrThis != itrThisEnd ) {
537 shadowThis.push_back(&(*itrThis));
538 shadowThat.push_back(&(*itrThat));
543 shadow_list_itr_t shadowThisItr = shadowThis.begin();
544 shadow_list_itr_t shadowThisItrEnd = shadowThis.end();
545 shadow_list_itr_t shadowThatItr = shadowThat.begin();
546 shadow_list_itr_t shadowThatItrEnd = shadowThat.end();
551 while ( shadowThisItr != shadowThisItrEnd ) {
552 if ( (**shadowThisItr) != (**shadowThatItr) ) {
553 if ( ! log ) {
return kFALSE; }
555 cout <<
"Difference on data record "
557 <<
" " << thisName <<
": " << **shadowThisItr << endl
558 <<
" " << thatName <<
": " << **shadowThatItr << endl;
574 cout <<
"FairDbSQLValPacket:"
586 cout <<
" MySQL VAL table creation: \"" <<
fSqlMySqlMetaVal <<
"\"" << endl;
589 std::list<string>::const_iterator itr =
fSqlStmts.begin();
590 std::list<string>::const_iterator itrEnd =
fSqlStmts.end();
591 for (; itr != itrEnd; ++itr)
594 cout <<
" SqlStmt \"" << *itr <<
"\"" << endl;
597 cout <<
" No SqlStmts." << endl;
618 cout <<
"Cannot create packet - table " << tableName
619 <<
" does not exist." << endl;
648 cout << msg <<
" on line " << lineNum
649 <<
":- \n " << line << endl;
679 string::size_type locEnd = vldRow.rfind(
',');
680 if ( locEnd == string::npos ) {
return; }
682 string::size_type locStart = vldRow.rfind(
',',locEnd);
683 if ( locStart == string::npos ) {
return; }
685 vldRow.replace(locStart,locEnd-locStart+1,ts.
AsString(
"s"));
699 if ( dbNo < 0 ) {
return; }
725 const string seqnoStr = tmp.str();
727 std::list<string>::iterator itr =
fSqlStmts.begin();
728 std::list<string>::iterator itrEnd =
fSqlStmts.end();
729 for (; itr != itrEnd; ++itr) {
SetSeqNoOnRow(*itr,seqnoStr); }
738 string::size_type locStart = row.find(
'(');
739 if ( locStart == string::npos ) {
return; }
741 string::size_type locEnd = row.find(
',',locStart);
742 if ( locEnd == string::npos ) {
return; }
743 row.replace(locStart,locEnd-locStart,seqno);
766 .CreateStatement(dbNo));
767 if ( ! stmtDb.get() ) {
769 cout <<
"Attempting to write to non-existant cascade entry " << dbNo
782 Bool_t first = kTRUE;
783 int combineInserts = 0;
788 for (list<string>::const_iterator itr =
fSqlStmts.begin();
794 list<string>::size_type locDate = sql.rfind(
",\'");
795 if ( locDate != string::npos ) {
808 if (removeRowCounter) {
809 list<string>::size_type locStart = sql.find(
',');
811 list<string>::size_type locEnd = sql.find(
',',locStart);
812 if ( locEnd != string::npos ) {
813 list<string>::size_type numChars = locEnd - locStart + 1;
814 sql.erase(locStart,numChars);
820 string::size_type insertIndex = sql.find(
"VALUES (");
821 if ( insertIndex == string::npos) {
822 cout <<
"Unexpected SQL : " << sql
823 <<
"\n should be of form INSERT INTO ... VALUES (...);" << endl;
827 if ( combineInserts == 1 ) { sqlInserts = sql; }
829 sqlInserts[sqlInserts.size()-1] =
',';
830 sqlInserts += sql.substr(insertIndex+7);
832 if ( combineInserts >= maxInserts ) {
840 if ( combineInserts ) {
851 Bool_t addMetadata)
const
860 cout<<
"Cannot write metadata; no associated FairDbTableProxy "
865 ios <<
">>>>>" <<
GetTableName() <<
" Metadata [MySQL]" << endl;
868 ios <<
"<<<<<" <<
GetTableName() <<
" Metadata" << endl;
874 for ( list<string>::const_iterator itr =
fSqlStmts.begin();
876 ++itr) { ios << (*itr) << endl; }