00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021 #include "Riostream.h"
00022 #include "TError.h"
00023
00024 #include "TBasketSQL.h"
00025 #include "TBufferSQL.h"
00026 #include "TSQLResult.h"
00027 #include "TSQLRow.h"
00028 #include <stdlib.h>
00029
00030 ClassImp(TBufferSQL);
00031
00032
00033 TBufferSQL::TBufferSQL(TBuffer::EMode mode, vector<Int_t> *vc,
00034 TString *insert_query, TSQLRow ** r) :
00035 TBufferFile(mode),
00036 fColumnVec(vc), fInsertQuery(insert_query), fRowPtr(r)
00037 {
00038
00039
00040 fIter = fColumnVec->begin();
00041 }
00042
00043
00044 TBufferSQL::TBufferSQL(TBuffer::EMode mode, Int_t bufsiz, vector<Int_t> *vc,
00045 TString *insert_query, TSQLRow ** r) :
00046 TBufferFile(mode,bufsiz),
00047 fColumnVec(vc), fInsertQuery(insert_query), fRowPtr(r)
00048 {
00049
00050
00051 fIter = fColumnVec->begin();
00052 }
00053
00054
00055 TBufferSQL::TBufferSQL(TBuffer::EMode mode, Int_t bufsiz, vector<Int_t> *vc,
00056 TString *insert_query, TSQLRow ** r,
00057 void *buf, Bool_t adopt) :
00058 TBufferFile(mode,bufsiz,buf,adopt),
00059 fColumnVec(vc), fInsertQuery(insert_query), fRowPtr(r)
00060 {
00061
00062
00063 fIter = fColumnVec->begin();
00064 }
00065
00066
00067 TBufferSQL::TBufferSQL() : TBufferFile(), fColumnVec(0),fInsertQuery(0),fRowPtr(0)
00068 {
00069
00070
00071 }
00072
00073
00074 TBufferSQL::~TBufferSQL()
00075 {
00076
00077
00078 delete fColumnVec;
00079 }
00080
00081
00082 void TBufferSQL::ReadBool(Bool_t &b)
00083 {
00084
00085
00086 b = (Bool_t)atoi((*fRowPtr)->GetField(*fIter));
00087
00088 if (fIter != fColumnVec->end()) ++fIter;
00089 }
00090
00091
00092 void TBufferSQL::ReadChar(Char_t &c)
00093 {
00094
00095
00096 c = (Char_t)atoi((*fRowPtr)->GetField(*fIter));
00097
00098 if (fIter != fColumnVec->end()) ++fIter;
00099 }
00100
00101
00102 void TBufferSQL::ReadShort(Short_t &h)
00103 {
00104
00105
00106 h = (Short_t)atoi((*fRowPtr)->GetField(*fIter));
00107
00108 if (fIter != fColumnVec->end()) ++fIter;
00109 }
00110
00111
00112 void TBufferSQL::ReadInt(Int_t &i)
00113 {
00114
00115
00116 i = atoi((*fRowPtr)->GetField(*fIter));
00117
00118 if (fIter != fColumnVec->end()) ++fIter;
00119 }
00120
00121
00122 void TBufferSQL::ReadFloat(Float_t &f)
00123 {
00124
00125
00126 f = atof((*fRowPtr)->GetField(*fIter));
00127
00128 if (fIter != fColumnVec->end()) ++fIter;
00129 }
00130
00131
00132 void TBufferSQL::ReadLong(Long_t &l)
00133 {
00134
00135
00136 l = atol((*fRowPtr)->GetField(*fIter));
00137
00138 if (fIter != fColumnVec->end()) ++fIter;
00139 }
00140
00141
00142 void TBufferSQL::ReadDouble(Double_t &d)
00143 {
00144
00145
00146 d = atof((*fRowPtr)->GetField(*fIter));
00147
00148 if (fIter != fColumnVec->end()) ++fIter;
00149 }
00150
00151
00152
00153 void TBufferSQL::WriteBool(Bool_t b)
00154 {
00155
00156
00157 (*fInsertQuery) += b;
00158 (*fInsertQuery) += ",";
00159 if (fIter != fColumnVec->end()) ++fIter;
00160 }
00161
00162
00163 void TBufferSQL::WriteChar(Char_t c)
00164 {
00165
00166
00167 (*fInsertQuery) += c;
00168 (*fInsertQuery) += ",";
00169 if (fIter != fColumnVec->end()) ++fIter;
00170 }
00171
00172
00173 void TBufferSQL::WriteShort(Short_t h)
00174 {
00175
00176
00177 (*fInsertQuery) += h;
00178 (*fInsertQuery) += ",";
00179 if (fIter != fColumnVec->end()) ++fIter;
00180 }
00181
00182
00183 void TBufferSQL::WriteInt(Int_t i)
00184 {
00185
00186
00187 (*fInsertQuery) += i;
00188 (*fInsertQuery) += ",";
00189 if (fIter != fColumnVec->end()) ++fIter;
00190 }
00191
00192
00193 void TBufferSQL::WriteLong(Long_t l)
00194 {
00195
00196
00197 (*fInsertQuery) += l;
00198 (*fInsertQuery) += ",";
00199 if (fIter != fColumnVec->end()) ++fIter;
00200 }
00201
00202
00203 void TBufferSQL::WriteFloat(Float_t f)
00204 {
00205
00206
00207 (*fInsertQuery) += f;
00208 (*fInsertQuery) += ",";
00209 if (fIter != fColumnVec->end()) ++fIter;
00210 }
00211
00212
00213 void TBufferSQL::WriteDouble(Double_t d)
00214 {
00215
00216
00217 (*fInsertQuery) += d;
00218 (*fInsertQuery) += ",";
00219 if (fIter != fColumnVec->end()) ++fIter;
00220 }
00221
00222
00223 void TBufferSQL::ReadUChar(UChar_t& uc)
00224 {
00225
00226
00227 uc = (UChar_t)atoi((*fRowPtr)->GetField(*fIter));
00228
00229 if (fIter != fColumnVec->end()) ++fIter;
00230 }
00231
00232
00233 void TBufferSQL::ReadUShort(UShort_t& us)
00234 {
00235
00236
00237 us = (UShort_t)atoi((*fRowPtr)->GetField(*fIter));
00238
00239 if (fIter != fColumnVec->end()) ++fIter;
00240 }
00241
00242
00243 void TBufferSQL::ReadUInt(UInt_t& ui)
00244 {
00245
00246
00247 TString val = (*fRowPtr)->GetField(*fIter);
00248 Int_t code = sscanf(val.Data(), "%u",&ui);
00249 if(code == 0) Error("operator>>(UInt_t&)","Error reading UInt_t");
00250
00251 if (fIter != fColumnVec->end()) ++fIter;
00252 }
00253
00254
00255 void TBufferSQL::ReadULong(ULong_t& ul)
00256 {
00257
00258
00259 TString val = (*fRowPtr)->GetField(*fIter);
00260 Int_t code = sscanf(val.Data(), "%lu",&ul);
00261 if(code == 0) Error("operator>>(ULong_t&)","Error reading ULong_t");
00262
00263 if (fIter != fColumnVec->end()) ++fIter;
00264 }
00265
00266
00267 void TBufferSQL::ReadLong64(Long64_t &ll)
00268 {
00269
00270
00271 TString val = (*fRowPtr)->GetField(*fIter);
00272 Int_t code = sscanf(val.Data(), "%lld",&ll);
00273 if(code == 0) Error("operator>>(ULong_t&)","Error reading Long64_t");
00274
00275 if (fIter != fColumnVec->end()) ++fIter;
00276 }
00277
00278
00279 void TBufferSQL::ReadULong64(ULong64_t &ull)
00280 {
00281
00282
00283 TString val = (*fRowPtr)->GetField(*fIter);
00284 Int_t code = sscanf(val.Data(), "%llu",&ull);
00285 if(code == 0) Error("operator>>(ULong_t&)","Error reading ULong64_t");
00286
00287 if (fIter != fColumnVec->end()) ++fIter;
00288 }
00289
00290
00291 void TBufferSQL::ReadCharP(Char_t *str)
00292 {
00293
00294
00295 strcpy(str,(*fRowPtr)->GetField(*fIter));
00296 if (fIter != fColumnVec->end()) ++fIter;
00297 }
00298
00299
00300 void TBufferSQL::ReadTString(TString &)
00301 {
00302
00303
00304
00305
00306 printf("ERROR NOT IMPLEMENTED\n");
00307 }
00308
00309
00310 void TBufferSQL::WriteTString(const TString &)
00311 {
00312
00313
00314
00315
00316 printf("ERROR NOT IMPLEMENTED\n");
00317 }
00318
00319
00320
00321
00322 void TBufferSQL::WriteUChar(UChar_t uc)
00323 {
00324
00325
00326 (*fInsertQuery) += uc;
00327 (*fInsertQuery) += ",";
00328 ++fIter;
00329 }
00330
00331
00332 void TBufferSQL::WriteUShort(UShort_t us)
00333 {
00334
00335
00336 (*fInsertQuery) += us;
00337 (*fInsertQuery) += ",";
00338 ++fIter;
00339 }
00340
00341
00342 void TBufferSQL::WriteUInt(UInt_t ui)
00343 {
00344
00345
00346 (*fInsertQuery) += ui;
00347 (*fInsertQuery) += ",";
00348 ++fIter;
00349 }
00350
00351
00352 void TBufferSQL::WriteULong(ULong_t ul)
00353 {
00354
00355
00356 (*fInsertQuery) += ul;
00357 (*fInsertQuery) += ",";
00358 ++fIter;
00359 }
00360
00361
00362 void TBufferSQL::WriteLong64(Long64_t ll)
00363 {
00364
00365
00366 (*fInsertQuery) += ll;
00367 (*fInsertQuery) += ",";
00368 ++fIter;
00369 }
00370
00371
00372 void TBufferSQL::WriteULong64(ULong64_t ull)
00373 {
00374
00375
00376 (*fInsertQuery) += ull;
00377 (*fInsertQuery) += ",";
00378 ++fIter;
00379 }
00380
00381
00382 void TBufferSQL::WriteCharP(const Char_t *str)
00383 {
00384
00385
00386 (*fInsertQuery) += "\"";
00387 (*fInsertQuery) += str;
00388 (*fInsertQuery) += "\",";
00389 ++fIter;
00390 }
00391
00392
00393 void TBufferSQL::WriteFastArray(const Bool_t *b, Int_t n)
00394 {
00395
00396 for(int i=0; i<n; ++i) {
00397 (*fInsertQuery) += b[i];
00398 (*fInsertQuery) += ",";
00399 ++fIter;
00400 }
00401 }
00402
00403
00404 void TBufferSQL::WriteFastArray(const Char_t *c, Int_t n)
00405 {
00406
00407
00408 for(int i=0; i<n; ++i) {
00409 (*fInsertQuery) += (Short_t)c[i];
00410 (*fInsertQuery) += ",";
00411 ++fIter;
00412 }
00413 }
00414
00415
00416 void TBufferSQL::WriteFastArrayString(const Char_t *c, Int_t )
00417 {
00418
00419
00420 (*fInsertQuery) += "\"";
00421 (*fInsertQuery) += c;
00422 (*fInsertQuery) += "\",";
00423 ++fIter;
00424 }
00425
00426
00427 void TBufferSQL::WriteFastArray(const UChar_t *uc, Int_t n)
00428 {
00429
00430
00431 for(int i=0; i<n; ++i) {
00432 (*fInsertQuery) += uc[i];
00433 (*fInsertQuery) += ",";
00434 ++fIter;
00435 }
00436 }
00437
00438
00439 void TBufferSQL::WriteFastArray(const Short_t *h, Int_t n)
00440 {
00441
00442
00443 for(int i=0; i<n; ++i) {
00444 (*fInsertQuery) += h[i];
00445 (*fInsertQuery) += ",";
00446 ++fIter;
00447 }
00448 }
00449
00450
00451 void TBufferSQL::WriteFastArray(const UShort_t *us, Int_t n)
00452 {
00453
00454
00455 for(int i=0; i<n; ++i) {
00456 (*fInsertQuery) += us[i];
00457 (*fInsertQuery) += ",";
00458 ++fIter;
00459 }
00460 }
00461
00462
00463 void TBufferSQL::WriteFastArray(const Int_t *ii, Int_t n)
00464 {
00465
00466
00467
00468 for(int i=0; i<n; ++i) {
00469 (*fInsertQuery) += ii[i];
00470 (*fInsertQuery) += ",";
00471 ++fIter;
00472 }
00473 }
00474
00475
00476 void TBufferSQL::WriteFastArray(const UInt_t *ui, Int_t n)
00477 {
00478
00479
00480 for(int i=0; i<n; ++i) {
00481 (*fInsertQuery) += ui[i];
00482 (*fInsertQuery) += ",";
00483 ++fIter;
00484 }
00485 }
00486
00487
00488 void TBufferSQL::WriteFastArray(const Long_t *l, Int_t n)
00489 {
00490
00491
00492 for(int i=0; i<n; ++i) {
00493 (*fInsertQuery)+= l[i];
00494 (*fInsertQuery)+= ",";
00495 ++fIter;
00496 }
00497 }
00498
00499
00500 void TBufferSQL::WriteFastArray(const ULong_t *ul, Int_t n)
00501 {
00502
00503
00504 for(int i=0; i<n; ++i) {
00505 (*fInsertQuery) += ul[i];
00506 (*fInsertQuery) += ",";
00507 ++fIter;
00508 }
00509 }
00510
00511
00512 void TBufferSQL::WriteFastArray(const Long64_t *l, Int_t n)
00513 {
00514
00515
00516 for(int i=0; i<n; ++i) {
00517 (*fInsertQuery) += l[i];
00518 (*fInsertQuery) += ",";
00519 ++fIter;
00520 }
00521 }
00522
00523
00524 void TBufferSQL::WriteFastArray(const ULong64_t *ul, Int_t n)
00525 {
00526
00527
00528 for(int i=0; i<n; ++i) {
00529 (*fInsertQuery) += ul[i];
00530 (*fInsertQuery) += ",";
00531 ++fIter;
00532 }
00533 }
00534
00535
00536 void TBufferSQL::WriteFastArray(const Float_t *f, Int_t n)
00537 {
00538
00539
00540 for(int i=0; i<n; ++i) {
00541 (*fInsertQuery) += f[i];
00542 (*fInsertQuery) += ",";
00543 ++fIter;
00544 }
00545 }
00546
00547
00548 void TBufferSQL::WriteFastArray(const Double_t *d, Int_t n)
00549 {
00550
00551
00552 for(int i=0; i<n; ++i) {
00553 (*fInsertQuery) += d[i];
00554 (*fInsertQuery )+= ",";
00555 ++fIter;
00556 }
00557 }
00558
00559
00560 void TBufferSQL::WriteFastArray(void*, const TClass*, Int_t, TMemberStreamer *)
00561 {
00562
00563
00564 Fatal("riteFastArray(void*, const TClass*, Int_t, TMemberStreamer *)","Not implemented yet");
00565 }
00566
00567
00568 Int_t TBufferSQL::WriteFastArray(void **, const TClass*, Int_t, Bool_t, TMemberStreamer*)
00569 {
00570
00571
00572 Fatal("WriteFastArray(void **, const TClass*, Int_t, Bool_t, TMemberStreamer*)","Not implemented yet");
00573 return 0;
00574 }
00575
00576
00577 void TBufferSQL::ReadFastArray(Bool_t *b, Int_t n)
00578 {
00579
00580
00581 for(int i=0; i<n; ++i) {
00582 b[i] = (Bool_t)atoi((*fRowPtr)->GetField(*fIter));
00583 ++fIter;
00584 }
00585 }
00586
00587
00588 void TBufferSQL::ReadFastArray(Char_t *c, Int_t n)
00589 {
00590
00591 for(int i=0; i<n; ++i) {
00592 c[i] = (Char_t)atoi((*fRowPtr)->GetField(*fIter));
00593 ++fIter;
00594 }
00595 }
00596
00597
00598 void TBufferSQL::ReadFastArrayString(Char_t *c, Int_t )
00599 {
00600
00601 strcpy(c,((*fRowPtr)->GetField(*fIter)));
00602 ++fIter;
00603 }
00604
00605
00606 void TBufferSQL::ReadFastArray(UChar_t *uc, Int_t n)
00607 {
00608
00609 for(int i=0; i<n; ++i) {
00610 uc[i] = (UChar_t)atoi((*fRowPtr)->GetField(*fIter));
00611 ++fIter;
00612 }
00613 }
00614
00615
00616 void TBufferSQL::ReadFastArray(Short_t *s, Int_t n)
00617 {
00618
00619 for(int i=0; i<n; ++i) {
00620 s[i] = (Short_t)atoi((*fRowPtr)->GetField(*fIter));
00621 ++fIter;
00622 }
00623 }
00624
00625
00626 void TBufferSQL::ReadFastArray(UShort_t *us, Int_t n)
00627 {
00628
00629 for(int i=0; i<n; ++i) {
00630 us[i] = (UShort_t)atoi((*fRowPtr)->GetField(*fIter));
00631 ++fIter;
00632 }
00633 }
00634
00635
00636 void TBufferSQL::ReadFastArray(Int_t *in, Int_t n)
00637 {
00638
00639 for(int i=0; i<n; ++i) {
00640 in[i] = atoi((*fRowPtr)->GetField(*fIter));
00641 ++fIter;
00642 }
00643 }
00644
00645
00646 void TBufferSQL::ReadFastArray(UInt_t *ui, Int_t n)
00647 {
00648
00649 for(int i=0; i<n; ++i) {
00650 ui[i] = atoi((*fRowPtr)->GetField(*fIter));
00651 ++fIter;
00652 }
00653 }
00654
00655
00656 void TBufferSQL::ReadFastArray(Long_t *l, Int_t n)
00657 {
00658
00659 for(int i=0; i<n; ++i) {
00660 l[i] = atol((*fRowPtr)->GetField(*fIter));
00661 ++fIter;
00662 }
00663 }
00664
00665
00666 void TBufferSQL::ReadFastArray(ULong_t *ul, Int_t n)
00667 {
00668
00669 for(int i=0; i<n; ++i) {
00670 (*this) >> ul[i];
00671 }
00672 }
00673
00674
00675 void TBufferSQL::ReadFastArray(Long64_t *ll, Int_t n)
00676 {
00677
00678 for(int i=0; i<n; ++i) {
00679 (*this) >> ll[i];
00680 }
00681 }
00682
00683
00684 void TBufferSQL::ReadFastArray(ULong64_t *ull, Int_t n)
00685 {
00686
00687 for(int i=0; i<n; ++i) {
00688 (*this) >> ull[i];
00689 }
00690 }
00691
00692
00693 void TBufferSQL::ReadFastArray(Float_t *f, Int_t n)
00694 {
00695
00696 for(int i=0; i<n; ++i) {
00697 f[i] = atof((*fRowPtr)->GetField(*fIter));
00698 ++fIter;
00699 }
00700 }
00701
00702
00703 void TBufferSQL::ReadFastArray(Double_t *d, Int_t n)
00704 {
00705
00706 for(int i=0; i<n; ++i) {
00707 d[i] = atof((*fRowPtr)->GetField(*fIter));
00708 ++fIter;
00709 }
00710 }
00711
00712
00713 void TBufferSQL::ReadFastArrayFloat16(Float_t *, Int_t , TStreamerElement *)
00714 {
00715
00716 Fatal("ReadFastArrayFloat16(Float_t *, Int_t , TStreamerElement *)","Not implemented yet");
00717 }
00718
00719
00720 void TBufferSQL::ReadFastArrayDouble32(Double_t *, Int_t , TStreamerElement *)
00721 {
00722
00723 Fatal("ReadFastArrayDouble32(Double_t *, Int_t , TStreamerElement *)","Not implemented yet");
00724 }
00725
00726
00727 void TBufferSQL::ReadFastArray(void *, const TClass *, Int_t, TMemberStreamer *, const TClass *)
00728 {
00729
00730 Fatal("ReadFastArray(void *, const TClass *, Int_t, TMemberStreamer *, const TClass *)","Not implemented yet");
00731 }
00732
00733
00734 void TBufferSQL::ReadFastArray(void **, const TClass *, Int_t, Bool_t, TMemberStreamer *, const TClass *)
00735 {
00736
00737 Fatal("ReadFastArray(void **, const TClass *, Int_t, Bool_t, TMemberStreamer *, const TClass *)","Not implemented yet");
00738 }
00739
00740
00741 void TBufferSQL::ResetOffset()
00742 {
00743
00744 fIter = fColumnVec->begin();
00745 }
00746
00747 #if 0
00748
00749 void TBufferSQL::insert_test(const char* dsn, const char* usr,
00750 const char* pwd, const TString& tblname)
00751 {
00752 TString str;
00753 TString select = "select * from ";
00754 TString sql;
00755 TSQLStatement* stmt;
00756 sql = select + "ins";
00757
00758 con = gSQLDriverManager->GetConnection(dsn,usr,pwd);
00759
00760 if(!con)
00761 printf("\n\n\nConnection NOT Successful\n\n\n");
00762 else
00763 printf("\n\n\nConnection Sucessful\n\n\n");
00764
00765
00766
00767 stmt = con->CreateStatement(0, odbc::ResultSet::CONCUR_READ_ONLY);
00768
00769 ptr = stmt->ExecuteQuery(sql.Data());
00770 if(!ptr) printf("No recorSet found!");
00771
00772 ptr->Next();
00773 ptr->MoveToInsertRow();
00774 cerr << "IsAfterLast(): " << ptr->IsAfterLast() << endl;
00775 ptr->UpdateInt(1, 5555);
00776 ptr->InsertRow();
00777 con->Commit();
00778
00779 ptr1 = stmt->ExecuteQuery(sql.Data());
00780
00781 }
00782 #endif