Changeset 7940 for trunk/MagicSoft/Mars
- Timestamp:
- 08/25/06 17:17:50 (18 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r7939 r7940 65 65 * resources/sequences.rc: 66 66 - resource file how to build sequences... added. 67 68 * msql/MSQLMagic.[h,cc]: 69 - added 70 71 * msql/MSQLServer.[h,cc]: 72 - added copy constructor 73 - allow fServ to be NULL (added sanity checks) 74 - Implemented Exec-command 75 76 * msql/Makefile, msql/SqlLinkDef.h: 77 - added MSQLMagic 67 78 68 79 -
trunk/MagicSoft/Mars/msql/MSQLServer.cc
r7842 r7940 64 64 void MSQLServer::BrowseColumn(TBrowser *b) /*FOLD00*/ 65 65 { 66 if (!fServ) 67 return; 68 66 69 const TString query0(Form("EXPLAIN %s.%s %s", (const char*)fDataBase, (const char*)fTable, (const char*)fColumn)); 67 70 const TString query1(Form("SELECT %s FROM %s.%s", (const char*)fColumn, (const char*)fDataBase, (const char*)fTable)); … … 161 164 void MSQLServer::BrowseTable(TBrowser *b) /*FOLD00*/ 162 165 { 166 if (!fServ) 167 return; 168 163 169 TSQLResult *res = fServ->GetColumns(fDataBase, fTable); 164 170 if (!res) … … 182 188 void MSQLServer::BrowseDataBase(TBrowser *b) /*FOLD00*/ 183 189 { 190 if (!fServ) 191 return; 192 184 193 TSQLResult *res = fServ->GetTables(fDataBase); 185 194 if (!res) … … 203 212 void MSQLServer::BrowseServer(TBrowser *b) /*FOLD00*/ 204 213 { 214 if (!fServ) 215 return; 216 205 217 TSQLResult *res = fServ->GetDataBases(); 206 218 if (!res) … … 278 290 TString MSQLServer::GetFields() const /*FOLD00*/ 279 291 { 292 if (!fServ) 293 return ""; 294 280 295 TSQLResult *res = fServ->GetColumns(fDataBase, fTable); 281 296 if (!res) … … 303 318 void MSQLServer::PrintQuery(const char *query) const /*FOLD00*/ 304 319 { 320 if (!fServ) 321 return; 322 305 323 TSQLResult *res = fServ->Query(query); 306 324 if (res) … … 407 425 void MSQLServer::Close(Option_t *option) /*FOLD00*/ 408 426 { 409 if (fType==kIsServer) 427 if (fType==kIsServer && fServ) 428 { 410 429 fServ->Close(option); 430 if (TestBit(kIsOwner)) 431 { 432 delete fServ; 433 fServ=0; 434 ResetBit(kIsOwner); 435 fType=kIsZombie; 436 } 437 } 411 438 } 412 439 413 440 // -------------------------------------------------------------------------- 414 441 // 415 // Send a SQL query to the SQ lserver.442 // Send a SQL query to the SQL server. 416 443 // 417 444 // If MSQLServer is no server (column, row, ...) NULL is returned and an … … 426 453 TSQLResult *MSQLServer::Query(const char *sql) /*FOLD00*/ 427 454 { 455 if (!fServ) 456 return NULL; 457 428 458 if (fType!=kIsServer) 429 459 { … … 435 465 if (!res) 436 466 { 437 cout << "ERROR: MSQLServer::Query - Query failed: " <<sql << endl;467 cout << /*"ERROR: MSQLServer::Query - Query failed: " <<*/ sql << endl; 438 468 return NULL; 439 469 } … … 442 472 } 443 473 474 // -------------------------------------------------------------------------- 475 // 476 // Send a SQL query to the SQL server. 477 // 478 // If MSQLServer is no server (column, row, ...) NULL is returned and an 479 // error message is send to stdout. 480 // 481 // If the query failed kFALSE is returned. 482 // 483 // On success kTRUE is returned. 484 // 485 Bool_t MSQLServer::Exec(const char* sql) 486 { 487 if (!fServ) 488 return kFALSE; 489 490 #if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00) 491 TSQLResult *res = fServ->Query(sql); 492 if (!res) 493 { 494 cout << "ERROR: MSQLServer::Exec - Query failed: " << sql << endl; 495 return kFALSE; 496 } 497 delete res; 498 return kTRUE; 499 #else 500 if (fType!=kIsServer) 501 { 502 cout << "ERROR: MSQLServer::Exec - this is not a server!" << endl; 503 return kFALSE; 504 } 505 506 return fServ->Exec(sql); 507 #endif 508 } 509 444 510 Int_t MSQLServer::SelectDataBase(const char *dbname) /*FOLD00*/ 445 511 { 446 512 fDataBase = dbname; 447 return fType==kIsServer ? fServ->SelectDataBase(dbname) : 0;513 return fType==kIsServer && fServ ? fServ->SelectDataBase(dbname) : 0; 448 514 } 449 515 450 516 TSQLResult *MSQLServer::GetDataBases(const char *wild) /*FOLD00*/ 451 517 { 452 return fType==kIsServer ? fServ->GetDataBases(wild) : NULL;518 return fType==kIsServer && fServ ? fServ->GetDataBases(wild) : NULL; 453 519 } 454 520 455 521 TSQLResult *MSQLServer::GetTables(const char *dbname, const char *wild) /*FOLD00*/ 456 522 { 457 return fType==kIsServer ? fServ->GetTables(dbname, wild) : NULL;523 return fType==kIsServer && fServ ? fServ->GetTables(dbname, wild) : NULL; 458 524 } 459 525 460 526 TSQLResult *MSQLServer::GetColumns(const char *dbname, const char *table, const char *wild) /*FOLD00*/ 461 527 { 462 return fType==kIsServer ? fServ->GetColumns(dbname, table, wild) : NULL;528 return fType==kIsServer && fServ ? fServ->GetColumns(dbname, table, wild) : NULL; 463 529 } 464 530 465 531 Int_t MSQLServer::CreateDataBase(const char *dbname) /*FOLD00*/ 466 532 { 467 return fType==kIsServer ? fServ->CreateDataBase(dbname) : 0;533 return fType==kIsServer && fServ ? fServ->CreateDataBase(dbname) : 0; 468 534 } 469 535 470 536 Int_t MSQLServer::DropDataBase(const char *dbname) /*FOLD00*/ 471 537 { 472 return fType==kIsServer ? fServ->DropDataBase(dbname) : 0;538 return fType==kIsServer && fServ ? fServ->DropDataBase(dbname) : 0; 473 539 } 474 540 475 541 Int_t MSQLServer::Reload() /*FOLD00*/ 476 542 { 477 return fType==kIsServer ? fServ->Reload() : 0;543 return fType==kIsServer && fServ ? fServ->Reload() : 0; 478 544 } 479 545 480 546 Int_t MSQLServer::Shutdown() /*FOLD00*/ 481 547 { 482 return fType==kIsServer ? fServ->Shutdown() : 0;548 return fType==kIsServer && fServ ? fServ->Shutdown() : 0; 483 549 } 484 550 485 551 const char *MSQLServer::ServerInfo() /*FOLD00*/ 486 552 { 487 return fType==kIsServer ? fServ->ServerInfo() : "";553 return fType==kIsServer && fServ ? fServ->ServerInfo() : ""; 488 554 } 489 555 490 556 Bool_t MSQLServer::IsConnected() const 491 557 { 492 return fType==kIsServer ? fServ->IsConnected() : kFALSE;558 return fType==kIsServer && fServ ? fServ->IsConnected() : kFALSE; 493 559 } 494 560 495 561 const char *MSQLServer::GetName() const 496 562 { 563 if (!fServ) 564 return "Unconnected!"; 565 497 566 switch (fType) 498 567 { … … 531 600 gROOT->GetListOfBrowsables()->Add(this, connection); 532 601 fType = kIsServer; 602 SetBit(kIsOwner); 603 SetBit(kMustCleanup); 533 604 } 534 605 else … … 567 638 if (!Split(url, user, pass)) 568 639 { 569 SetBit(kIsZombie);640 fType = kIsZombie; 570 641 return; 571 642 } … … 590 661 if (!Split(url, user, pasw)) 591 662 { 592 SetBit(kIsZombie);663 fType = kIsZombie; 593 664 return; 594 665 } … … 607 678 } 608 679 680 MSQLServer::MSQLServer(MSQLServer &serv) 681 { 682 fServ = serv.fServ; 683 684 fDataBase = serv.fDataBase; 685 fTable = serv.fTable; 686 fColumn = serv.fColumn; 687 688 fType = serv.fType; 689 } 690 609 691 MSQLServer::~MSQLServer() /*FOLD00*/ 610 692 { 611 Close();612 693 if (gDebug>0) 613 694 cout << "Delete: " << GetName() << endl; 695 Close(); 614 696 } 615 697 … … 666 748 return rc; 667 749 } 750 751 void MSQLServer::RecursiveRemove(TObject *obj) 752 { 753 if (fServ==obj) 754 { 755 fServ=NULL; 756 fType = kIsZombie; 757 ResetBit(kIsOwner); 758 } 759 } -
trunk/MagicSoft/Mars/msql/MSQLServer.h
r7388 r7940 14 14 class MSQLServer : public TObject 15 15 { 16 private: 16 17 TSQLServer *fServ; 17 18 … … 25 26 26 27 Type_t fType; 28 29 enum { kIsOwner=BIT(14) }; 27 30 28 31 Bool_t IsFolder() const { return kTRUE; } … … 85 88 MSQLServer(const char *link); 86 89 MSQLServer(TEnv &env, const char *prefix=0); 90 MSQLServer(MSQLServer &serv); 87 91 MSQLServer(); 88 92 ~MSQLServer(); … … 106 110 void Close(Option_t *option=""); 107 111 TSQLResult *Query(const char *sql); 112 Bool_t Exec(const char* sql); 108 113 Int_t SelectDataBase(const char *dbname); 109 114 TSQLResult *GetDataBases(const char *wild = 0); … … 118 123 119 124 TString GetEntry(const char *where, const char *col=0, const char *table=0) const; 125 126 void RecursiveRemove(TObject *obj); 120 127 121 128 ClassDef(MSQLServer, 0) // An enhancement of TSQLServer -
trunk/MagicSoft/Mars/msql/Makefile
r6849 r7940 22 22 23 23 SRCFILES = \ 24 MSQLServer.cc 24 MSQLServer.cc \ 25 MSQLMagic.cc 25 26 26 27 ############################################################ -
trunk/MagicSoft/Mars/msql/SqlLinkDef.h
r6856 r7940 8 8 #pragma link C++ class MSQLServer+; 9 9 10 #pragma link C++ class MSQLMagic+; 11 10 12 #endif
Note:
See TracChangeset
for help on using the changeset viewer.