From 8284872b8267bde9b2f88f8f34f6a99a22e7c40e Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 1 Aug 2008 06:33:01 +0000 Subject: [PATCH] Adding schema scoping to table description queries in DboPostgres, fixes #5006 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7409 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../model/datasources/dbo/dbo_postgres.php | 9 +++++++- .../datasources/dbo/dbo_postgres.test.php | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 634752f2e..e47d9ac1a 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -193,7 +193,14 @@ class DboPostgres extends DboSource { $this->_sequenceMap[$table] = array(); if ($fields === null) { - $cols = $this->fetchAll("SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null, column_default AS default, ordinal_position AS position, character_maximum_length AS char_length, character_octet_length AS oct_length FROM information_schema.columns WHERE table_name =" . $this->value($table) . " ORDER BY position", false); + $cols = $this->fetchAll( + "SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null, + column_default AS default, ordinal_position AS position, character_maximum_length AS char_length, + character_octet_length AS oct_length FROM information_schema.columns + WHERE table_name = " . $this->value($table) . " AND table_schema = " . + $this->value($this->config['schema'])." ORDER BY position", + false + ); foreach ($cols as $column) { $colKey = array_keys($column); diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php index 7cf11d2ff..4351ab2c8 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php @@ -327,6 +327,27 @@ class DboPostgresTest extends CakeTestCase { $this->assertEqual($db1->lastInsertId($table), 1); $this->assertEqual($db2->lastInsertId($table), 2); } + +/** + * Tests that table lists and descriptions are scoped to the proper Postgres schema + * + * @access public + * @return void + */ + function testSchemaScoping() { + $db1 =& ConnectionManager::getDataSource('test_suite'); + $db1->cacheSources = false; + $db1->reconnect(array('persistent' => false)); + $db1->query('CREATE SCHEMA _scope_test'); + + $db2 =& ConnectionManager::create( + 'test_suite_2', + array_merge($db1->config, array('driver' => 'postgres', 'schema' => '_scope_test')) + ); + $db2->cacheSources = false; + + $db2->query('DROP SCHEMA _scope_test'); + } } ?> \ No newline at end of file