Skip to content

Commit

Permalink
Fixing notice error caused when looking for info on tables that don't…
Browse files Browse the repository at this point in the history
… exist.
  • Loading branch information
markstory committed Feb 12, 2011
1 parent e042093 commit 26c5f78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cake/libs/model/datasources/dbo/dbo_mysql.php
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php
Expand Up @@ -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
Expand Down

0 comments on commit 26c5f78

Please sign in to comment.