mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
parent
9ddd72499c
commit
8f82badc23
@ -202,6 +202,9 @@ MySqlDB::MySqlDB(const string& s, int p, const string& u, const string& _p,
|
||||
{
|
||||
connections[i] = mysql_init(NULL);
|
||||
|
||||
bool reconnect = true;
|
||||
mysql_options(connections[i], MYSQL_OPT_RECONNECT, &reconnect);
|
||||
|
||||
rc = mysql_real_connect(connections[i], server.c_str(), user.c_str(),
|
||||
password.c_str(), 0, port, NULL, 0);
|
||||
|
||||
|
@ -163,6 +163,29 @@ int PostgreSqlDB::exec_ext(std::ostringstream& cmd, Callbackable *obj, bool quie
|
||||
|
||||
PGresult* res = PQexec(conn, c_str);
|
||||
|
||||
if ( PQstatus(conn) == CONNECTION_BAD )
|
||||
{
|
||||
PQreset(conn);
|
||||
|
||||
if ( PQstatus(conn) == CONNECTION_BAD )
|
||||
{
|
||||
NebulaLog::error("ONE", "Lost connection to DB, unable to reconnect");
|
||||
|
||||
PQclear(res);
|
||||
free_db_connection(conn);
|
||||
|
||||
return SqlDB::CONNECTION;
|
||||
}
|
||||
else
|
||||
{
|
||||
NebulaLog::info("ONE", "Succesfully reconnected to DB");
|
||||
|
||||
// Re-execute the query
|
||||
PQclear(res);
|
||||
res = PQexec(conn, c_str);
|
||||
}
|
||||
}
|
||||
|
||||
if ( PQresultStatus(res) != PGRES_COMMAND_OK &&
|
||||
PQresultStatus(res) != PGRES_TUPLES_OK )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user