From fa6c0fe17320473b8079dc33c8d34492c499c070 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Sat, 5 Sep 2015 14:08:35 +0200 Subject: [PATCH] Fix string escape problem with PostgreSQL >= 9.1 and standard_conforming_strings=on fixes #9244 --- doc/2-getting-started.md | 3 ++- lib/db_ido_pgsql/idopgsqlconnection.cpp | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/2-getting-started.md b/doc/2-getting-started.md index 6ed72997e..276e043fd 100644 --- a/doc/2-getting-started.md +++ b/doc/2-getting-started.md @@ -408,6 +408,7 @@ RHEL/CentOS 5/6: RHEL/CentOS 7: # yum install postgresql-server postgresql + # postgresql-setup --initdb # systemctl enable postgresql # systemctl start postgresql @@ -471,7 +472,7 @@ authentication method and restart the postgresql server. # IPv6 local connections: host all all ::1/128 ident - # /etc/init.d/postgresql restart + # service postgresql restart After creating the database and permissions you can import the Icinga 2 IDO diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index db9e7a6ed..8b28930c9 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -215,8 +215,16 @@ void IdoPgsqlConnection::Reconnect(void) SetConnected(true); + IdoPgsqlResult result; + + /* explicitely require legacy mode for string escaping in PostgreSQL >= 9.1 + * changing standard_conforming_strings to on by default + */ + if (PQserverVersion(m_Connection) >= 90100) + result = Query("SET standard_conforming_strings TO off"); + String dbVersionName = "idoutils"; - IdoPgsqlResult result = Query("SELECT version FROM " + GetTablePrefix() + "dbversion WHERE name=E'" + Escape(dbVersionName) + "'"); + result = Query("SELECT version FROM " + GetTablePrefix() + "dbversion WHERE name=E'" + Escape(dbVersionName) + "'"); Dictionary::Ptr row = FetchRow(result, 0); -- 2.40.0