From a702aa44a055274a5cc8363e596c7bf944915613 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Sun, 26 Jul 2009 18:04:03 +0200 Subject: [PATCH] Fixes #692 - double escaping of backslashes when using Postgres It is strongly recommended that Postgres users do upgrade to this version. --- src/core/abstractsqlstorage.cpp | 2 ++ src/core/abstractsqlstorage.h | 10 ++++++++++ src/core/postgresqlstorage.cpp | 10 ++++------ src/core/postgresqlstorage.h | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core/abstractsqlstorage.cpp b/src/core/abstractsqlstorage.cpp index d8992df1..92f03cb3 100644 --- a/src/core/abstractsqlstorage.cpp +++ b/src/core/abstractsqlstorage.cpp @@ -86,6 +86,8 @@ void AbstractSqlStorage::addConnectionToPool() { if(!db.open()) { qWarning() << "Unable to open database" << displayName() << "for thread" << QThread::currentThread(); qWarning() << "-" << db.lastError().text(); + } else { + initDbSession(db); } } diff --git a/src/core/abstractsqlstorage.h b/src/core/abstractsqlstorage.h index cc9f619a..c6c55212 100644 --- a/src/core/abstractsqlstorage.h +++ b/src/core/abstractsqlstorage.h @@ -72,6 +72,16 @@ protected: inline virtual QString userName() { return QString(); } inline virtual QString password() { return QString(); } + + //! Initialize db specific features on connect + /** This is called every time a connection to a specific SQL backend is established + * the default implementation does nothing. + * + * When reimplementing this method, don't use logDB() inside this function as + * this would cause as we're just about to initialize that DB connection. + */ + inline virtual void initDbSession(QSqlDatabase & /* db */) {} + private slots: void connectionDestroyed(); diff --git a/src/core/postgresqlstorage.cpp b/src/core/postgresqlstorage.cpp index 13aa8c94..d8a62846 100644 --- a/src/core/postgresqlstorage.cpp +++ b/src/core/postgresqlstorage.cpp @@ -79,12 +79,10 @@ QVariantMap PostgreSqlStorage::setupDefaults() const { return map; } -bool PostgreSqlStorage::setup(const QVariantMap &settings) { - bool success = AbstractSqlStorage::setup(settings); - if(success) { - logDb().exec(QString("ALTER USER %1 SET standard_conforming_strings TO on").arg(userName())); - } - return success; +void PostgreSqlStorage::initDbSession(QSqlDatabase &db) { + // this blows... but unfortunately Qt's PG driver forces us to this... + db.exec("set standard_conforming_strings = off"); + db.exec("set escape_string_warning = off"); } void PostgreSqlStorage::setConnectionProperties(const QVariantMap &properties) { diff --git a/src/core/postgresqlstorage.h b/src/core/postgresqlstorage.h index de196cd6..4d18d114 100644 --- a/src/core/postgresqlstorage.h +++ b/src/core/postgresqlstorage.h @@ -42,7 +42,6 @@ public slots: virtual QString description() const; virtual QStringList setupKeys() const; virtual QVariantMap setupDefaults() const; - virtual bool setup(const QVariantMap &settings = QVariantMap()); // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc @@ -101,6 +100,7 @@ public slots: virtual QList requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1); protected: + virtual void initDbSession(QSqlDatabase &db); virtual void setConnectionProperties(const QVariantMap &properties); inline virtual QString driverName() { return "QPSQL"; } inline virtual QString hostName() { return _hostName; } -- 2.20.1