From 0ce7578de337ffa369635a7b93918e200e8d0496 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 25 May 2022 19:11:42 +0200 Subject: [PATCH] fix: the way how we test if there is a connection issue If there is a connection issue then PQexec returns a resultset now - older versions of PostgreSQL returned null pointer. --- src/modelenv.h | 2 +- src/postgresqlconnector.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/modelenv.h b/src/modelenv.h index a4ca60e..3361e04 100644 --- a/src/modelenv.h +++ b/src/modelenv.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2019-2021, Tomasz Sowa + * Copyright (c) 2019-2022, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/postgresqlconnector.cpp b/src/postgresqlconnector.cpp index 0dbd6bc..a077134 100644 --- a/src/postgresqlconnector.cpp +++ b/src/postgresqlconnector.cpp @@ -97,13 +97,15 @@ bool PostgreSQLConnector::do_query(const char * query_str, PostgreSQLQueryResult psql_result->psql_result = PQexec(pg_conn, query_str); - if( !psql_result->psql_result ) + /* + * in older versions of PostgreSQL when there was a connection issue then the psql_result pointer would be null + * + */ + if( !psql_result->psql_result || PQstatus(pg_conn) != CONNECTION_OK ) { - if( PQstatus(pg_conn) != CONNECTION_OK ) - { - assert_connection_is_working(); - psql_result->psql_result = PQexec(pg_conn, query_str); - } + psql_result->clear(); + assert_connection_is_working(); + psql_result->psql_result = PQexec(pg_conn, query_str); } if( psql_result->psql_result )