16UniConnection::UniConnection(TSQLServer* pSQLServer)
18 db_server = pSQLServer;
21UniConnection* UniConnection::OpenConnection(
const TString& connect_string,
24 const char* db_password)
29 TSQLServer* pSQLServer =
nullptr;
32 pSQLServer = it->second;
35 for (
int i = 0;
i < 4;
i++) {
36 pSQLServer = TSQLServer::Connect(connect_string, db_user, db_password);
40 cout <<
"ERROR: database connection was not established (" << db_host <<
") for '" << db_user
44 unsigned int random_integer = pow(10,
i) + gRandom->Integer(pow(10,
i) * 2 + 1);
45 this_thread::sleep_for(chrono::seconds(random_integer));
62 const char *db_username = gSystem->Getenv(
"UNICONDA_USERNAME"), *db_password = gSystem->Getenv(
"UNICONDA_PASSWORD");
64 if ((db_username ==
nullptr) || (db_password ==
nullptr)) {
69 return OpenConnection(conString,
UNI_DB_HOST, db_username, db_password);
74 const char* strDBHost,
75 const char* strDBName,
77 const char* strPassword)
80 switch (database_type) {
82 db_type = (
char*)
"mysql";
85 db_type = (
char*)
"pgsql";
88 cout <<
"ERROR: incorrect database type!" << endl;
93 TString conString = TString::Format(
"%s://%s/%s", db_type, strDBHost, strDBName);
94 return OpenConnection(conString, strDBHost, strUID, strPassword);
static UniConnection * Open()
static mapSQLServer * mapConnection
map< string, TSQLServer * > mapSQLServer
map< string, TSQLServer * >::iterator itSQLServer
const char *const UNI_DB_HOST
const char *const UNI_DB_NAME
const char *const UNI_DB_PASSWORD
const char *const UNI_DB_USERNAME
map< string, TSQLServer * > mapSQLServer
pair< string, TSQLServer * > pairSQLServer