From dd4570bb45e7c0cc768132b0de47ec1091c77965 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Tue, 24 Nov 2020 14:08:42 +0100 Subject: [PATCH 1/4] Allow other schema than "public" on PostgreSQL databases --- src/Pgsql/PgsqlDriver.php | 23 +++++++++++++++++++++-- src/Postgresql/PostgresqlDriver.php | 16 +++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Pgsql/PgsqlDriver.php b/src/Pgsql/PgsqlDriver.php index 3b7c1c4ab..ed5330212 100644 --- a/src/Pgsql/PgsqlDriver.php +++ b/src/Pgsql/PgsqlDriver.php @@ -151,10 +151,27 @@ public function getConnectionCollation() return $array[0]['lc_collate']; } + /** + * Internal function to get the name of the default schema for the current PostgreSQL connexion. + * 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 +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/src/Postgresql/PostgresqlDriver.php b/src/Postgresql/PostgresqlDriver.php index 54976131f..e88e6fcde 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' From ee7fffda45310a4e800bef3d0e3bc7ff1a929208 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Thu, 26 Nov 2020 17:28:18 +0000 Subject: [PATCH 2/4] Codestyle --- src/Pgsql/PgsqlDriver.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Pgsql/PgsqlDriver.php b/src/Pgsql/PgsqlDriver.php index ed5330212..4d56e8415 100644 --- a/src/Pgsql/PgsqlDriver.php +++ b/src/Pgsql/PgsqlDriver.php @@ -161,11 +161,10 @@ public function getConnectionCollation() */ private function getDefaultSchema() { - // Supported since PostgreSQL 7.3 $this->setQuery('SELECT (current_schemas(false))[1]'); - return $this->loadResult(); + return $this->loadResult(); } /** From 7d790348559848d7d51813f33134ffe7cbc14085 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Thu, 26 Nov 2020 19:09:03 +0100 Subject: [PATCH 3/4] Add forgotten backintegration --- src/Postgresql/PostgresqlDriver.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Postgresql/PostgresqlDriver.php b/src/Postgresql/PostgresqlDriver.php index e88e6fcde..5d242666d 100644 --- a/src/Postgresql/PostgresqlDriver.php +++ b/src/Postgresql/PostgresqlDriver.php @@ -1646,4 +1646,20 @@ public function decodeBinary($data) return $data; } + + /** + * Internal function to get the name of the default schema for the current PostgreSQL connexion. + * 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(); + } } From 2043179cc96a1d40917d9c7c5a21a572c734a808 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Thu, 26 Nov 2020 19:16:34 +0100 Subject: [PATCH 4/4] Connect French language being used in code comment --- src/Pgsql/PgsqlDriver.php | 2 +- src/Postgresql/PostgresqlDriver.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pgsql/PgsqlDriver.php b/src/Pgsql/PgsqlDriver.php index 4d56e8415..3d8bb8989 100644 --- a/src/Pgsql/PgsqlDriver.php +++ b/src/Pgsql/PgsqlDriver.php @@ -152,7 +152,7 @@ public function getConnectionCollation() } /** - * Internal function to get the name of the default schema for the current PostgreSQL connexion. + * 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 diff --git a/src/Postgresql/PostgresqlDriver.php b/src/Postgresql/PostgresqlDriver.php index 5d242666d..6dae635d4 100644 --- a/src/Postgresql/PostgresqlDriver.php +++ b/src/Postgresql/PostgresqlDriver.php @@ -1648,7 +1648,7 @@ public function decodeBinary($data) } /** - * Internal function to get the name of the default schema for the current PostgreSQL connexion. + * 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