Browse Source

Add tests for postgres + sqlserver schema.table names.

Both postgres and sqlserver databases frequently use multiple schemas.
As per #3924 and #3914 both sqlserver and postgres support
`schema.table` style table names allowing specific models to use tables
on schemas outside of the default schema.
mark_story 11 years ago
parent
commit
3497a494d7

+ 0 - 6
src/Database/Schema/Collection.php

@@ -111,12 +111,6 @@ class Collection {
 		if (strpos($name, '.')) {
 			list($config['schema'], $name) = explode('.', $name);
 		}
-
-		list($sql, $params) = $this->_dialect->describeTableSql($name, $config);
-		$statement = $this->_executeSql($sql, $params);
-		if (count($statement) === 0) {
-			throw new Exception(sprintf('Cannot describe %s. It has 0 columns.', $name));
-		}
 		$table = new Table($name);
 
 		$this->_reflect('Column', $name, $config, $table);

+ 15 - 0
tests/TestCase/Database/Schema/PostgresSchemaTest.php

@@ -241,6 +241,21 @@ SQL;
 	}
 
 /**
+ * Test that describe accepts tablenames containing `schema.table`.
+ *
+ * @return void
+ */
+	public function testDescribeWithSchemaName() {
+		$connection = ConnectionManager::get('test');
+		$this->_createTables($connection);
+
+		$schema = new SchemaCollection($connection);
+		$result = $schema->describe('public.schema_articles');
+		$this->assertEquals(['id'], $result->primaryKey());
+		$this->assertEquals('schema_articles', $result->name());
+	}
+
+/**
  * Test describing a table with Postgres
  *
  * @return void

+ 15 - 0
tests/TestCase/Database/Schema/SqlserverSchemaTest.php

@@ -358,6 +358,21 @@ SQL;
 	}
 
 /**
+ * Test that describe accepts tablenames containing `schema.table`.
+ *
+ * @return void
+ */
+	public function testDescribeWithSchemaName() {
+		$connection = ConnectionManager::get('test');
+		$this->_createTables($connection);
+
+		$schema = new SchemaCollection($connection);
+		$result = $schema->describe('dbo.schema_articles');
+		$this->assertEquals(['id'], $result->primaryKey());
+		$this->assertEquals('schema_articles', $result->name());
+	}
+
+/**
  * Test describing a table with indexes
  *
  * @return void