Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'w51_MDL-37420_m23_pgschema' of git://github.com/skodak/…

…moodle into MOODLE_23_STABLE
  • Loading branch information...
commit cd7802517f65819a03381d5564a200d638ef8afb 2 parents 0cc875b + 090c684
@stronk7 stronk7 authored
View
24 lib/ddl/postgres_sql_generator.php
@@ -414,9 +414,11 @@ function getSequenceFromDB($xmldb_table) {
$tablename = $this->getTableName($xmldb_table);
$sequencename = $tablename . '_id_seq';
- if (!$this->mdb->get_record_sql("SELECT *
- FROM pg_class
- WHERE relname = ? AND relkind = 'S'",
+ if (!$this->mdb->get_record_sql("SELECT c.*
+ FROM pg_catalog.pg_class c
+ JOIN pg_catalog.pg_namespace as ns ON ns.oid = c.relnamespace
+ WHERE c.relname = ? AND c.relkind = 'S'
+ AND (ns.nspname = current_schema() OR ns.oid = pg_my_temp_schema())",
array($sequencename))) {
$sequencename = false;
}
@@ -442,9 +444,11 @@ public function isNameInUse($object_name, $type, $table_name) {
case 'ix':
case 'uix':
case 'seq':
- if ($check = $this->mdb->get_records_sql("SELECT relname
- FROM pg_class
- WHERE lower(relname) = ?", array(strtolower($object_name)))) {
+ if ($check = $this->mdb->get_records_sql("SELECT c.relname
+ FROM pg_class c
+ JOIN pg_catalog.pg_namespace as ns ON ns.oid = c.relnamespace
+ WHERE lower(c.relname) = ?
+ AND (ns.nspname = current_schema() OR ns.oid = pg_my_temp_schema())", array(strtolower($object_name)))) {
return true;
}
break;
@@ -452,9 +456,11 @@ public function isNameInUse($object_name, $type, $table_name) {
case 'uk':
case 'fk':
case 'ck':
- if ($check = $this->mdb->get_records_sql("SELECT conname
- FROM pg_constraint
- WHERE lower(conname) = ?", array(strtolower($object_name)))) {
+ if ($check = $this->mdb->get_records_sql("SELECT c.conname
+ FROM pg_constraint c
+ JOIN pg_catalog.pg_namespace as ns ON ns.oid = c.connamespace
+ WHERE lower(c.conname) = ?
+ AND (ns.nspname = current_schema() OR ns.oid = pg_my_temp_schema())", array(strtolower($object_name)))) {
return true;
}
break;
View
34 lib/dml/pgsql_native_moodle_database.php
@@ -181,6 +181,11 @@ public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dbop
$sql = "SET bytea_output = 'escape'; ";
}
+ // Select schema if specified, otherwise the first one wins.
+ if (isset($this->dboptions['dbschema'])) {
+ $sql .= "SET search_path = '".$this->dboptions['dbschema']."'; ";
+ }
+
// Find out the bytea oid.
$sql .= "SELECT oid FROM pg_type WHERE typname = 'bytea'";
$this->query_start($sql, null, SQL_QUERY_AUX);
@@ -292,21 +297,12 @@ public function get_tables($usecache=true) {
}
$this->tables = array();
$prefix = str_replace('_', '|_', $this->prefix);
- if ($this->is_min_version('9.1')) {
- // Use ANSI standard information_schema in recent versions where it is fast enough.
- $sql = "SELECT table_name
- FROM information_schema.tables
- WHERE table_name LIKE '$prefix%' ESCAPE '|'
- AND table_type IN ('BASE TABLE', 'LOCAL TEMPORARY')";
- } else {
- // information_schema is horribly slow in <= 9.0, so use pg internals.
- // Note the pg_is_other_temp_schema. We only want temp objects from our own session.
- $sql = "SELECT c.relname
- FROM pg_class c
- WHERE c.relname LIKE '$prefix%' ESCAPE '|'
+ $sql = "SELECT c.relname
+ FROM pg_catalog.pg_class c
+ JOIN pg_catalog.pg_namespace as ns ON ns.oid = c.relnamespace
+ WHERE c.relname LIKE '$prefix%' ESCAPE '|'
AND c.relkind = 'r'
- AND NOT pg_is_other_temp_schema(c.relnamespace)";
- }
+ AND (ns.nspname = current_schema() OR ns.oid = pg_my_temp_schema())";
$this->query_start($sql, null, SQL_QUERY_AUX);
$result = pg_query($this->pgsql, $sql);
$this->query_end($result);
@@ -336,9 +332,11 @@ public function get_indexes($table) {
$indexes = array();
$tablename = $this->prefix.$table;
- $sql = "SELECT *
- FROM pg_catalog.pg_indexes
- WHERE tablename = '$tablename'";
+ $sql = "SELECT i.*
+ FROM pg_catalog.pg_indexes i
+ JOIN pg_catalog.pg_namespace as ns ON ns.nspname = i.schemaname
+ WHERE i.tablename = '$tablename'
+ AND (i.schemaname = current_schema() OR ns.oid = pg_my_temp_schema())";
$this->query_start($sql, null, SQL_QUERY_AUX);
$result = pg_query($this->pgsql, $sql);
@@ -379,10 +377,12 @@ public function get_columns($table, $usecache=true) {
$sql = "SELECT a.attnum, a.attname AS field, t.typname AS type, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, d.adsrc
FROM pg_catalog.pg_class c
+ JOIN pg_catalog.pg_namespace as ns ON ns.oid = c.relnamespace
JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
JOIN pg_catalog.pg_type t ON t.oid = a.atttypid
LEFT JOIN pg_catalog.pg_attrdef d ON (d.adrelid = c.oid AND d.adnum = a.attnum)
WHERE relkind = 'r' AND c.relname = '$tablename' AND c.reltype > 0 AND a.attnum > 0
+ AND (ns.nspname = current_schema() OR ns.oid = pg_my_temp_schema())
ORDER BY a.attnum";
$this->query_start($sql, null, SQL_QUERY_AUX);
Please sign in to comment.
Something went wrong with that request. Please try again.