Commit 0db8772b authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

DBServer_PostgresSQL: fixed "ping" and "is_open" processing

parent e77967fc
...@@ -383,7 +383,7 @@ void DBServer_PostgreSQL::initDBServer() ...@@ -383,7 +383,7 @@ void DBServer_PostgreSQL::initDBServer()
<< " pingTime=" << PingTime << " pingTime=" << PingTime
<< " ReconnectTime=" << ReconnectTime << endl; << " ReconnectTime=" << ReconnectTime << endl;
if( !db->nconnect(dbnode, dbuser, dbpass, dbname, dbport) ) if( !db->reconnect(dbnode, dbuser, dbpass, dbname, dbport) )
{ {
dbwarn << myname << "(init): DB connection error: " << db->error() << endl; dbwarn << myname << "(init): DB connection error: " << db->error() << endl;
askTimer(DBServer_PostgreSQL::ReconnectTimer, ReconnectTime); askTimer(DBServer_PostgreSQL::ReconnectTimer, ReconnectTime);
......
...@@ -47,7 +47,32 @@ PostgreSQLInterface::~PostgreSQLInterface() ...@@ -47,7 +47,32 @@ PostgreSQLInterface::~PostgreSQLInterface()
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::ping() const bool PostgreSQLInterface::ping() const
{ {
return db && db->is_open(); if( !db )
return false;
try
{
nontransaction n(*(db.get()));
n.exec("select version();");
return true;
}
catch( const std::exception& e )
{
// lastE = string(e.what());
}
return false;
// return db && db->is_open();
}
// -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::reconnect(const string& host, const string& user, const string& pswd, const string& dbname, unsigned int port )
{
if( db )
close();
return nconnect(host,user,pswd, dbname, port);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::nconnect(const string& host, const string& user, const string& pswd, const string& dbname, unsigned int port ) bool PostgreSQLInterface::nconnect(const string& host, const string& user, const string& pswd, const string& dbname, unsigned int port )
...@@ -224,7 +249,8 @@ void PostgreSQLInterface::save_inserted_id( const pqxx::result& res ) ...@@ -224,7 +249,8 @@ void PostgreSQLInterface::save_inserted_id( const pqxx::result& res )
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::isConnection() const bool PostgreSQLInterface::isConnection() const
{ {
return (db && db->is_open()); return db && ping();
// return (db && db->is_open())
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
DBResult PostgreSQLInterface::makeResult( const pqxx::result& res ) DBResult PostgreSQLInterface::makeResult( const pqxx::result& res )
......
...@@ -61,6 +61,10 @@ namespace uniset ...@@ -61,6 +61,10 @@ namespace uniset
virtual const std::string error() override; virtual const std::string error() override;
bool reconnect(const std::string& host, const std::string& user,
const std::string& pswd, const std::string& dbname,
unsigned int port = 5432);
protected: protected:
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment