Skip to content

Commit

Permalink
Merge branch 'w07_MDL-26351_20_instquotes' of git://github.com/skodak…
Browse files Browse the repository at this point in the history
…/moodle
  • Loading branch information
stronk7 committed Feb 14, 2011
2 parents 345f417 + a2d242b commit 64ff7d5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/ddl/postgres_sql_generator.php
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 64ff7d5

Please sign in to comment.