MDL-26351 add support for postgresql running with standard_conforming_strings
This commit is contained in:
@@ -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 @@ class postgres_sql_generator extends sql_generator {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user