StoreDbTable

 
#include "StDbManager.hh"
#include "StDbConfigNode.hh"
#include "StDbTable.h"
#include "StDbDefs.hh"
#include "RunLog/daqRunTag.h"

/////////////////////////////////////////////////////////////////////////////
//
//  Simple example code that connects to the database
//  & stores a specific c-struct of data... This process can
//  be "automated" for an ensemble of c-structs in 2 ways (after
//
//   mgr->setStoreTime(unsigned int t); // OR
//   mgr->setStoreTime(const char* dataTime); // year-mo-dy hr:mi:sc )  
//
//  1. Store the ensemble contained within StDbConfigNode 
//
//  2. This example: single table store
//
//
//  2. via user held list of c-structs
//     
//    MyCstruct* c = UseCodeFillItSomeHow();
//    StDbConfigNode* node= mgr->initConfig(dbType,dbDomain);
//    StDbTable* table=node->addDbTable("myName","myVersion");
//    table->SetTable((char*)c,nrows);
//    mgr->storeDbTable(table);
//
/////////////////////////////////////////////////////////////////////////////

int 
main(int argc, char** argv)
{


// Here I will store an instance of the daqRunTag table to the database RunLog_daq
//
//->get the singleton manager

StDbManager* dbManager = StDbManager::Instance();

//
//->set the db enumerations
//

StDbType type = RunLog;
StDbDomain domain = Daq; 

//
//-> connect to the db & get an empty container
//

StDbConfigNode* configNode = dbManager->initConfig(type,domain);

//
//-> add a table to the container with descriptor given by Database 
//
//   (Notes: 
//           configNode->addTable("daqRunTag"); doesn't get DB-descriptor
//           configNode->addDbTable("daqRunTag","aVersion"); gets a specific version )

StDbTable* tab1 = configNode->addDbTable("daqRunTag");

//
// Fill the c-struct somehow
//

daqRunTag b1 = { 10, 0, 81992051, 0, 1, 0,0,0,0,0,0,0,0, 1021, 11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66};


tab1->SetTable((char*)&b1,1);

//
// set the store time. (need to be only once for an ensemble of tables)
//
dbManager->setStoreTime("1999-09-20 00:00:11");

//
// store the table.  Note that the data will NOT be stored if the
// primary keys are duplicated for this particular c-struct. 
// e.g. each instance (row) is unique in table-name, version, beginTime, 
// & elementID.  Some have suggested that this also include 
// "entryTime" so that all "store-calls" will go through and apply
// the standard that the last entered is returned upon request.
// This is not the case now.
//
dbManager->storeDbTable(tab1);

}






ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.