Re: [Brahms-dev-l] database connections

From: Djamel Ouerdane <ouerdane@nbi.dk>
Date: Mon Mar 22 2004 - 09:46:00 EST
Hello Flemming,

Here is a simple example but not functionnal, it's just a sketsche. My 
script does something similar in essence. 

// ----
void main()
{
  do whatever
  ...
  ...

  if (!commitStuff()) {
    bla bla
    ...
    ...
  }

  // let's say you want to try again
  commitStuff();


}

// ----
Boot_t commitStuff() 
{
  if (!isConnected()) {
    BrMainDb* mainDb = BrMainDb::Instance();
    mainDb->SetUserName("query");
    mainDb->SetHostName("brahms-db0.rcf.bnl.gov");
    mainDb->SetDbName("BrahmsMain"); 
    
    if (!mainDb->Connect()) {
      cerr << " *** mainDB is not responding...sorry " << endl;
      return kFALSE;
    }
    if (!mainDb->ConnectToRun()) {
      cerr << " *** runDB is not responding...sorry " << endl;
      return kFALSE;
    }
    if (!mainDb->ConnectToCalib("insert")) {
      cerr << " *** calibDB is not responding...sorry " << endl;
      return kFALSE;
    }
  }    

  // do whatever with the DB

  if (did_not_do_what_you_ want)
   return kFALSE;

  return kTRUE;
}

// -----
Bool_t isConnected() 
{
  return (BrMainDb::Instance()->IsConnected() &
	  BrCalibrationsDb::Instance()->IsConnected() &
	  BrRunsDb::Instance()->IsConnected());
}


If you want a concrete script, I'll post it.
Djam


-- 
Djamel Ouerdane ------------------------------------------o
|  Niels Bohr Institute      |  Home:                     |
|  Blegdamsvej 17, DK-2100 Ø |  Jagtvej 141 2D,           |
|  Fax: +45 35 32 50 16      |  DK-2200 Copenhagen N      |
|  Tel: +45 35 32 52 69      |  +45 35 86 19 74           |
|                  http://www.nbi.dk/~ouerdane            |
|                  ouerdane@nbi.dk                        |
o---------------------------------------------------------o


_______________________________________________
Brahms-dev-l mailing list
Brahms-dev-l@lists.bnl.gov
http://lists.bnl.gov/mailman/listinfo/brahms-dev-l
Received on Mon Mar 22 09:46:31 2004

This archive was generated by hypermail 2.1.8 : Mon Mar 22 2004 - 09:46:51 EST