14TangoConnection::TangoConnection(TSQLServer* pSQLServer)
16 tango_db_server = pSQLServer;
19TangoConnection* TangoConnection::OpenConnection(
const TString& connect_string,
22 const char* db_password)
27 TSQLServer* pSQLServer =
nullptr;
30 pSQLServer = it->second;
33 for (
int i = 0;
i < 4;
i++) {
34 pSQLServer = TSQLServer::Connect(connect_string, db_user, db_password);
38 cout <<
"ERROR: database connection was not established (" << db_host <<
") for '" << db_user
42 unsigned int random_integer = pow(10,
i) + gRandom->Integer(pow(10,
i) * 2 + 1);
43 this_thread::sleep_for(chrono::seconds(random_integer));
62 const char* strDBHost,
63 const char* strDBName,
65 const char* strPassword)
68 switch (database_type) {
70 db_type = (
char*)
"mysql";
73 db_type = (
char*)
"pgsql";
76 cout <<
"ERROR: incorrect database type!" << endl;
80 TString conString = TString::Format(
"%s://%s/%s", db_type, strDBHost, strDBName);
81 return OpenConnection(conString, strDBHost, strUID, strPassword);
virtual ~TangoConnection()
static TangoConnection * Open()
static mapSQLServer * mapConnection
map< string, TSQLServer * > mapSQLServer
map< string, TSQLServer * >::iterator itSQLServer
const char *const TANGO_DB_HOST
const char *const TANGO_DB_USERNAME
const char *const TANGO_DB_PASSWORD
const char *const TANGO_DB_NAME
map< string, TSQLServer * > mapSQLServer
pair< string, TSQLServer * > pairSQLServer