From 26c5f78a140076b9d993d73b276194430a4b584f Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 11 Feb 2011 22:37:56 -0500 Subject: [PATCH] Fixing notice error caused when looking for info on tables that don't exist. --- cake/libs/model/datasources/dbo/dbo_mysql.php | 5 ++++- .../libs/model/datasources/dbo/dbo_mysql.test.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 749b9d0a65f..19d030b837d 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -298,6 +298,9 @@ function describe($model) { } $fields = false; $cols = $this->_execute('SHOW FULL COLUMNS FROM ' . $this->fullTableName($model)); + if (!$cols) { + throw new CakeException(__('Could not describe table for %s', $model->name)); + } foreach ($cols as $column) { $fields[$column->Field] = array( @@ -609,7 +612,7 @@ function listDetailedSources($name = null) { } } $result->closeCursor(); - if (is_string($name)) { + if (is_string($name) && isset($tables[$name])) { return $tables[$name]; } return $tables; diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index ff462f86eb3..f9f05dc6bfc 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -795,6 +795,21 @@ public function testListSources() { $this->assertEqual($tables, array('cake_table', 'another_table')); } +/** + * test that listDetailedSources with a named table that doesn't exist. + * + * @return void + */ + function testListDetailedSourcesNamed() { + $this->loadFixtures('Apple'); + + $result = $this->Dbo->listDetailedSources('imaginary'); + $this->assertEquals(array(), $result, 'Should be empty when table does not exist.'); + + $result = $this->Dbo->listDetailedSources(); + $this->assertTrue(isset($result['apples']), 'Key should exist'); + } + /** * Tests that getVersion method sends the correct query for getting the mysql version * @return void