From a2d242bc099bebfa2aa3b1064791deefd3cffc57 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 12 Feb 2011 16:16:52 +0100 Subject: [PATCH] MDL-26351 add support for postgresql running with standard_conforming_strings --- lib/ddl/postgres_sql_generator.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/ddl/postgres_sql_generator.php b/lib/ddl/postgres_sql_generator.php index 196113782033a..240a67bb07625 100644 --- a/lib/ddl/postgres_sql_generator.php +++ b/lib/ddl/postgres_sql_generator.php @@ -56,6 +56,8 @@ class postgres_sql_generator extends sql_generator { public $rename_key_sql = null; //SQL sentence to rename one key (PostgreSQL doesn't support this!) //TABLENAME, OLDKEYNAME, NEWKEYNAME are dynamically replaced + protected $strd_strings = null; // '' or \' quotes + /** * Reset a sequence to the id field of a table. * @param string $table name of table or xmldb_table object @@ -404,6 +406,24 @@ public function getCheckConstraintsFromDB($xmldb_table, $xmldb_field = null) { return $results; } + public function addslashes($s) { + // Postgres is gradually switching to ANSY quotes, we need to check what is expected + if (!isset($this->std_strings)) { + $this->std_strings = ($this->mdb->get_field_sql("select setting from pg_settings where name = 'standard_conforming_strings'") === 'on'); + } + + if ($this->std_strings) { + $s = str_replace("'", "''", $s); + } else { + // do not use php addslashes() because it depends on PHP quote settings! + $s = str_replace('\\','\\\\',$s); + $s = str_replace("\0","\\\0", $s); + $s = str_replace("'", "\\'", $s); + } + + return $s; + } + /** * Given one xmldb_table returns one string with the sequence of the table * in the table (fetched from DB)