summaryrefslogtreecommitdiff
path: root/src/database/postgresql_engine.cpp
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_engine.cpp
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_engine.cpp')
-rw-r--r--src/database/postgresql_engine.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/database/postgresql_engine.cpp b/src/database/postgresql_engine.cpp
index 984a959..59bc885 100644
--- a/src/database/postgresql_engine.cpp
+++ b/src/database/postgresql_engine.cpp
@@ -11,6 +11,8 @@
#include <logger/logger.hpp>
+#include <cstring>
+
PostgresqlEngine::PostgresqlEngine(PGconn*const conn):
conn(conn)
{}
@@ -20,6 +22,15 @@ PostgresqlEngine::~PostgresqlEngine()
PQfinish(this->conn);
}
+static void logging_notice_processor(void*, const char* original)
+{
+ if (original && std::strlen(original) > 0)
+ {
+ std::string message{original, std::strlen(original) - 1};
+ log_warning("PostgreSQL: ", message);
+ }
+}
+
std::unique_ptr<DatabaseEngine> PostgresqlEngine::open(const std::string& conninfo)
{
PGconn* con = PQconnectdb(conninfo.data());
@@ -34,8 +45,10 @@ std::unique_ptr<DatabaseEngine> PostgresqlEngine::open(const std::string& connin
{
const char* errmsg = PQerrorMessage(con);
log_error("Postgresql connection failed: ", errmsg);
+ PQfinish(con);
throw std::runtime_error("failed to open connection.");
}
+ PQsetNoticeProcessor(con, &logging_notice_processor, nullptr);
return std::make_unique<PostgresqlEngine>(con);
}