diff --git a/src/Pgsql/PgsqlDriver.php b/src/Pgsql/PgsqlDriver.php index 3b7c1c4ab..3d8bb8989 100644 --- a/src/Pgsql/PgsqlDriver.php +++ b/src/Pgsql/PgsqlDriver.php @@ -151,10 +151,26 @@ 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. * - * This is unsuported by PostgreSQL. + * This is unsupported by PostgreSQL. * * @param mixed $tables A table name or a list of table names. * @@ -187,6 +203,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 +225,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/src/Postgresql/PostgresqlDriver.php b/src/Postgresql/PostgresqlDriver.php index 54976131f..6dae635d4 100644 --- a/src/Postgresql/PostgresqlDriver.php +++ b/src/Postgresql/PostgresqlDriver.php @@ -415,7 +415,7 @@ public function getTableCreate($tables) /** * Retrieves field information about a given table. * - * @param string $table The name of the database table. + * @param string $table The name of the database table. For PostgreSQL may start with a schema. * @param boolean $typeOnly True to only return field types. * * @return array An array of fields for the database table. @@ -428,8 +428,18 @@ public function getTableColumns($table, $typeOnly = true) $this->connect(); $result = array(); - $tableSub = $this->replacePrefix($table); + $fn = explode('.', $tableSub); + + if (count($fn) === 2) + { + $schema = $fn[0]; + $tableSub = $fn[1]; + } + else + { + $schema = $this->getDefaultSchema(); + } $this->setQuery(' SELECT a.attname AS "column_name", @@ -451,7 +461,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($schema) . ') ) AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum' @@ -1636,4 +1646,20 @@ public function decodeBinary($data) return $data; } + + /** + * 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(); + } }