From d59f1d3150a6fce02cc876a6bdb6c7968b652fe7 Mon Sep 17 00:00:00 2001 From: Russell Smith Date: Thu, 22 Sep 2016 08:40:03 +1000 Subject: [PATCH] MDL-55124 database: Mode connection test to after connection. To verify the client encoding and other data is correct then the connection must have been made first. --- lib/dml/pgsql_native_moodle_database.php | 28 +++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/dml/pgsql_native_moodle_database.php b/lib/dml/pgsql_native_moodle_database.php index f795343abef..aaac5c87ef8 100644 --- a/lib/dml/pgsql_native_moodle_database.php +++ b/lib/dml/pgsql_native_moodle_database.php @@ -163,19 +163,6 @@ class pgsql_native_moodle_database extends moodle_database { } $connection .= " options='" . implode(' ', $options) . "'"; - } else { - /* We don't trust people who just set the dbhandlesoptions, this code checks up on them. - * These functions do not talk to the server, they use the client library knowledge to determine state. - */ - if (!empty($this->dboptions['dbschema'])) { - throw new dml_connection_exception('You cannot specify a schema with dbhandlesoptions, use the database to set it.'); - } - if (pg_client_encoding($this->pgsql) != 'UTF8') { - throw new dml_connection_exception('client_encoding = UTF8 not set, it is: ' . pg_client_encoding($this->pgsql)); - } - if (pg_escape_string($this->pgsql, '\\') != '\\') { - throw new dml_connection_exception('standard_conforming_string = on, must be set at the database.'); - } } ob_start(); @@ -194,6 +181,21 @@ class pgsql_native_moodle_database extends moodle_database { throw new dml_connection_exception($dberr); } + if (!empty($this->dboptions['dbhandlesoptions'])) { + /* We don't trust people who just set the dbhandlesoptions, this code checks up on them. + * These functions do not talk to the server, they use the client library knowledge to determine state. + */ + if (!empty($this->dboptions['dbschema'])) { + throw new dml_connection_exception('You cannot specify a schema with dbhandlesoptions, use the database to set it.'); + } + if (pg_client_encoding($this->pgsql) != 'UTF8') { + throw new dml_connection_exception('client_encoding = UTF8 not set, it is: ' . pg_client_encoding($this->pgsql)); + } + if (pg_escape_string($this->pgsql, '\\') != '\\') { + throw new dml_connection_exception('standard_conforming_strings = on, must be set at the database.'); + } + } + // Connection stabilised and configured, going to instantiate the temptables controller $this->temptables = new pgsql_native_moodle_temptables($this);