diff --git a/libraries/joomla/database/driver/pgsql.php b/libraries/joomla/database/driver/pgsql.php index 18300179af467..9437ac4c93bf6 100644 --- a/libraries/joomla/database/driver/pgsql.php +++ b/libraries/joomla/database/driver/pgsql.php @@ -151,6 +151,23 @@ public function getConnectionCollation() return $array[0]['lc_collate']; } + /** + * Internal function to get the name of the default schema for the current PostgreSQL connection. + * That is the schema where tables are created by Joomla. + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + private function getDefaultSchema() + { + + // Supported since PostgreSQL 7.3 + $this->setQuery('SELECT (current_schemas(false))[1]'); + return $this->loadResult(); + + } + /** * Shows the table CREATE statement that creates the given tables. * @@ -187,6 +204,8 @@ public function getTableColumns($table, $typeOnly = true) $tableSub = $this->replacePrefix($table); + $defaultSchema = $this->getDefaultSchema(); + $this->setQuery(' SELECT a.attname AS "column_name", pg_catalog.format_type(a.atttypid, a.atttypmod) as "type", @@ -207,7 +226,7 @@ public function getTableColumns($table, $typeOnly = true) WHERE a.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname=' . $this->quote($tableSub) . ' AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE - nspname = \'public\') + nspname = ' . $this->quote($defaultSchema) . ') ) AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum' diff --git a/libraries/joomla/database/driver/postgresql.php b/libraries/joomla/database/driver/postgresql.php index 9b5cefedafd47..72574f1e015a1 100644 --- a/libraries/joomla/database/driver/postgresql.php +++ b/libraries/joomla/database/driver/postgresql.php @@ -414,7 +414,7 @@ public function getTableColumns($table, $typeOnly = true) } else { - $schema = 'public'; + $schema = $this->getDefaultSchema(); } $this->setQuery(' @@ -1624,4 +1624,21 @@ public function quoteBinary($data) { return "decode('" . bin2hex($data) . "', 'hex')"; } + + /** + * Internal function to get the name of the default schema for the current PostgreSQL connection. + * That is the schema where tables are created by Joomla. + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + private function getDefaultSchema() + { + + // Supported since PostgreSQL 7.3 + $this->setQuery('SELECT (current_schemas(false))[1]'); + return $this->loadResult(); + + } }