Skip to content

Commit d9d79e1

Browse files
fiescmarcoslucaboesch
authored andcommitted
MDL-81804 dml: Passing parameters with -c key=val on PostgreSQL.
1 parent 07881a5 commit d9d79e1

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

lib/dml/pgsql_native_moodle_database.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,15 @@ public function raw_connect(string $dbhost, string $dbuser, string $dbpass, stri
185185
$connection .= " connect_timeout=".$this->dboptions['connecttimeout'];
186186
}
187187

188+
// ALTER USER and ALTER DATABASE are overridden by these settings.
189+
$options = ['-c client_encoding=utf8', '-c standard_conforming_strings=on'];
188190
if (empty($this->dboptions['dbhandlesoptions'])) {
189-
// ALTER USER and ALTER DATABASE are overridden by these settings.
190-
$options = array('--client_encoding=utf8', '--standard_conforming_strings=on');
191191
// Select schema if specified, otherwise the first one wins.
192192
if (!empty($this->dboptions['dbschema'])) {
193193
$options[] = "-c search_path=" . addcslashes($this->dboptions['dbschema'], "'\\");
194194
}
195-
196-
$connection .= " options='" . implode(' ', $options) . "'";
197195
}
196+
$connection .= " options='" . implode(' ', $options) . "'";
198197

199198
if (isset($this->dboptions['ssl'])) {
200199
$sslmode = $this->dboptions['ssl'];
@@ -246,12 +245,6 @@ public function raw_connect(string $dbhost, string $dbuser, string $dbpass, stri
246245
if (!empty($this->dboptions['dbschema'])) {
247246
throw new dml_connection_exception('You cannot specify a schema with dbhandlesoptions, use the database to set it.');
248247
}
249-
if (pg_client_encoding($this->pgsql) != 'UTF8') {
250-
throw new dml_connection_exception('client_encoding = UTF8 not set, it is: ' . pg_client_encoding($this->pgsql));
251-
}
252-
if (pg_escape_string($this->pgsql, '\\') != '\\') {
253-
throw new dml_connection_exception('standard_conforming_strings = on, must be set at the database.');
254-
}
255248
}
256249

257250
// Connection stabilised and configured, going to instantiate the temptables controller

0 commit comments

Comments
 (0)