Commit 039c18ce authored by jan.koester's avatar jan.koester
Browse files

better failure handling

parent 3408a0fc
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#include <stdexcept>
#include <mutex>

#include <libpq-fe.h>
@@ -39,7 +40,7 @@ dbpp::Postgresql::Postgresql(const char *constr) {
    _dbconn = PQconnectdb(constr);
    if (PQstatus(_dbconn) != CONNECTION_OK){
        PQfinish(_dbconn);
        throw static_cast<const char*>(PQerrorMessage(_dbconn));
        throw std::runtime_error(PQerrorMessage(_dbconn));
    }
}

@@ -53,7 +54,7 @@ int dbpp::Postgresql::exec(const SQL &sql,DBResult &res){

    if(pstate==PGRES_FATAL_ERROR || pstate==PGRES_BAD_RESPONSE) {
        PQclear(pres);
        throw static_cast<const char*>(PQerrorMessage(_dbconn));
        throw std::runtime_error(PQerrorMessage(_dbconn));
    }

    res.clear();