diff options
author | louiz’ <louiz@louiz.org> | 2018-03-19 00:16:16 +0100 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2018-03-19 00:16:16 +0100 |
commit | d7427fc9ca4c06fda458e4951559f57163d90b94 (patch) | |
tree | f9922c71e45499d887e8e1a57daa19904027c879 /src/database | |
parent | 8f74d4dd400becc92558e35d8b09c940b4f068eb (diff) | |
download | biboumi-d7427fc9ca4c06fda458e4951559f57163d90b94.tar.gz biboumi-d7427fc9ca4c06fda458e4951559f57163d90b94.tar.bz2 biboumi-d7427fc9ca4c06fda458e4951559f57163d90b94.tar.xz biboumi-d7427fc9ca4c06fda458e4951559f57163d90b94.zip |
Re-connect to postgresql when the connection is lost
fix #3336
Diffstat (limited to 'src/database')
-rw-r--r-- | src/database/postgresql_statement.hpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/database/postgresql_statement.hpp b/src/database/postgresql_statement.hpp index 5665aed..37e8ea0 100644 --- a/src/database/postgresql_statement.hpp +++ b/src/database/postgresql_statement.hpp @@ -92,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()); @@ -113,7 +113,17 @@ private: 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}); - return false; + 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; } |