summaryrefslogtreecommitdiff
path: root/src/database/postgresql_statement.hpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2018-09-03 22:26:57 +0200
committerlouiz’ <louiz@louiz.org>2018-09-03 22:26:57 +0200
commit193302b0de20df6adc090eaeaa84cfd286be724a (patch)
treeb9e0e0f75b5cd74911a42a7fcd0f1477971391ff /src/database/postgresql_statement.hpp
parent56651cb5c29cc50ddf3c62c37167fa0b9389bfde (diff)
parent28acbed948e1c281f9de6132164e42d0ed20c32f (diff)
downloadbiboumi-193302b0de20df6adc090eaeaa84cfd286be724a.tar.gz
biboumi-193302b0de20df6adc090eaeaa84cfd286be724a.tar.bz2
biboumi-193302b0de20df6adc090eaeaa84cfd286be724a.tar.xz
biboumi-193302b0de20df6adc090eaeaa84cfd286be724a.zip
Merge branch 'master' into debian
Diffstat (limited to 'src/database/postgresql_statement.hpp')
-rw-r--r--src/database/postgresql_statement.hpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/database/postgresql_statement.hpp b/src/database/postgresql_statement.hpp
index 571c8f1..37e8ea0 100644
--- a/src/database/postgresql_statement.hpp
+++ b/src/database/postgresql_statement.hpp
@@ -6,6 +6,8 @@
#include <libpq-fe.h>
+#include <cstring>
+
class PostgresqlStatement: public Statement
{
public:
@@ -90,7 +92,7 @@ class PostgresqlStatement: public Statement
private:
private:
- bool execute()
+ bool execute(const bool second_attempt=false)
{
std::vector<const char*> params;
params.reserve(this->params.size());
@@ -108,8 +110,20 @@ private:
const auto status = PQresultStatus(this->result);
if (status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK)
{
- log_error("Failed to execute command: ", PQresultErrorMessage(this->result));
- return false;
+ const char* original = PQerrorMessage(this->conn);
+ if (original && std::strlen(original) > 0)
+ log_error("Failed to execute command: ", std::string{original, std::strlen(original) - 1});
+ if (PQstatus(this->conn) != CONNECTION_OK && !second_attempt)
+ {
+ log_info("Trying to reconnect to PostgreSQL server and execute the query again.");
+ PQreset(this->conn);
+ return this->execute(true);
+ }
+ else
+ {
+ log_error("Givin up.");
+ return false;
+ }
}
return true;
}