Permalink
Browse files

Merge branch 'w07_MDL-26351_20_instquotes' of git://github.com/skodak…

…/moodle
  • Loading branch information...
2 parents 345f417 + a2d242b commit 64ff7d5c14c8dc1df14adef021b4c0314126fc4e @stronk7 stronk7 committed Feb 14, 2011
Showing with 20 additions and 0 deletions.
  1. +20 −0 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)

0 comments on commit 64ff7d5

Please sign in to comment.