Loading backends/pgsql/pgsql.cpp +13 −1 Original line number Diff line number Diff line Loading @@ -38,8 +38,20 @@ namespace dbpp{ dbpp::Postgresql::Postgresql(const char *constr) { _dbconn = PQconnectdb(constr); if (_dbconn == nullptr) { // PQconnectdb returns NULL only when libpq could not allocate the // connection object. PQstatus()/PQerrorMessage() would dereference the // NULL conn and crash, so handle it explicitly. throw std::runtime_error("PQconnectdb returned NULL (out of memory)"); } if (PQstatus(_dbconn) != CONNECTION_OK){ std::string errmsg = PQerrorMessage(_dbconn); const char *pqErrMsg = PQerrorMessage(_dbconn); std::string errmsg = "Connection to database failed: "; if (pqErrMsg) { errmsg += pqErrMsg; } else { errmsg += "Unknown error (PQerrorMessage returned NULL)"; } PQfinish(_dbconn); _dbconn = nullptr; throw std::runtime_error(errmsg); Loading Loading
backends/pgsql/pgsql.cpp +13 −1 Original line number Diff line number Diff line Loading @@ -38,8 +38,20 @@ namespace dbpp{ dbpp::Postgresql::Postgresql(const char *constr) { _dbconn = PQconnectdb(constr); if (_dbconn == nullptr) { // PQconnectdb returns NULL only when libpq could not allocate the // connection object. PQstatus()/PQerrorMessage() would dereference the // NULL conn and crash, so handle it explicitly. throw std::runtime_error("PQconnectdb returned NULL (out of memory)"); } if (PQstatus(_dbconn) != CONNECTION_OK){ std::string errmsg = PQerrorMessage(_dbconn); const char *pqErrMsg = PQerrorMessage(_dbconn); std::string errmsg = "Connection to database failed: "; if (pqErrMsg) { errmsg += pqErrMsg; } else { errmsg += "Unknown error (PQerrorMessage returned NULL)"; } PQfinish(_dbconn); _dbconn = nullptr; throw std::runtime_error(errmsg); Loading