Changeset 4877 for trunk/MagicSoft/Mars/msql
- Timestamp:
- 09/07/04 11:43:43 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/msql
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/msql/MSQLServer.cc
r4694 r4877 46 46 47 47 #include <TH1.h> 48 #include <TEnv.h> 48 49 49 50 #include <TSQLResult.h> … … 503 504 } 504 505 505 void MSQLServer::Init(const char *connection, const char *user, const char *password) /*FOLD00*/ 506 { 507 fType = kIsZombie; 508 509 fServ = TSQLServer::Connect(connection, user, password); 510 if (fServ) 511 { 512 gROOT->GetListOfBrowsables()->Add(this, connection); 513 fType = kIsServer; 514 } 515 else 516 SetBit(kZombie); 517 518 fList.SetOwner(); 519 } 520 521 MSQLServer::MSQLServer(const char *connection, const char *user, const char *password) /*FOLD00*/ 522 { 523 Init(connection, user, password); 524 } 525 526 MSQLServer::MSQLServer(const char *u) : fType(kIsZombie) /*FOLD00*/ 527 { 528 TString url(u); 529 506 Bool_t MSQLServer::Split(TString &url, TString &user, TString &pasw) const 507 { 530 508 const Ssiz_t pos1 = url.First("://")+3; 531 509 const Ssiz_t pos2 = url.Last(':') +1; … … 533 511 534 512 if (pos1<0 || pos2<0 || pos3<0 || pos1>pos2 || pos2>pos3) 535 { 513 return kFALSE; 514 515 user = url(pos1, pos2-pos1-1); 516 pasw = url(pos2, pos3-pos2); 517 518 url.Remove(pos1, pos3+1-pos1); 519 520 return kTRUE; 521 } 522 523 void MSQLServer::Init(const char *connection, const char *user, const char *password) /*FOLD00*/ 524 { 525 fType = kIsZombie; 526 527 fServ = TSQLServer::Connect(connection, user, password); 528 if (fServ) 529 { 530 gROOT->GetListOfBrowsables()->Add(this, connection); 531 fType = kIsServer; 532 } 533 else 536 534 SetBit(kZombie); 535 536 fList.SetOwner(); 537 } 538 539 void MSQLServer::InitEnv(TEnv &env, const char *prefix) 540 { 541 TString url; 542 TString user; 543 TString pass; 544 545 if (prefix) 546 { 547 url = env.GetValue(Form("%s.URL", prefix), ""); 548 user = env.GetValue(Form("%s.User", prefix), ""); 549 pass = env.GetValue(Form("%s.Password", prefix), ""); 550 } 551 if (url.IsNull()) 552 url = env.GetValue("URL", ""); 553 if (user.IsNull()) 554 user = env.GetValue("User", ""); 555 if (pass.IsNull()) 556 pass = env.GetValue("Password", ""); 557 558 if (user.IsNull() && pass.IsNull()) 559 { 560 if (!Split(url, user, pass)) 561 { 562 SetBit(kIsZombie); 563 return; 564 } 565 } 566 567 Init(url, user, pass); 568 } 569 570 MSQLServer::MSQLServer(const char *connection, const char *user, const char *password) /*FOLD00*/ 571 { 572 Init(connection, user, password); 573 } 574 575 MSQLServer::MSQLServer(const char *u) : fType(kIsZombie) /*FOLD00*/ 576 { 577 TString url(u); 578 TString user, pasw; 579 580 if (!Split(url, user, pasw)) 581 { 582 SetBit(kIsZombie); 537 583 return; 538 584 } 539 540 const TString user = url(pos1, pos2-pos1-1);541 const TString pasw = url(pos2, pos3-pos2);542 543 url.Remove(pos1, pos3+1-pos1);544 545 585 Init(url, user, pasw); 586 } 587 588 MSQLServer::MSQLServer(TEnv &env, const char *prefix) 589 { 590 InitEnv(env, prefix); 591 } 592 593 MSQLServer::MSQLServer() 594 { 595 if (gEnv) 596 InitEnv(*gEnv); 546 597 } 547 598 -
trunk/MagicSoft/Mars/msql/MSQLServer.h
r4577 r4877 6 6 #endif 7 7 8 class TEnv; 8 9 class TArrayI; 10 9 11 class TSQLServer; 10 12 class TSQLResult; … … 55 57 const char *GetNameColumn() const { return Form("%s/%s/%s", (const char*)fDataBase, (const char*)fTable, (const char*)fColumn); } 56 58 59 Bool_t Split(TString &url, TString &user, TString &pasw) const; 60 57 61 void Init(const char *connection, const char *user, const char *password); 62 void InitEnv(TEnv &env, const char *prefix=0); 58 63 59 64 public: … … 80 85 MSQLServer(const char *connection, const char *user, const char *password); 81 86 MSQLServer(const char *link); 87 MSQLServer(TEnv &env, const char *prefix=0); 88 MSQLServer(); 82 89 ~MSQLServer(); 83 90
Note:
See TracChangeset
for help on using the changeset viewer.