Fixing notice error caused when looking for info on tables that don't exist.

This commit is contained in:
mark_story 2011-02-11 22:37:56 -05:00
parent e0420937a7
commit 26c5f78a14
2 changed files with 19 additions and 1 deletions

View file

@ -298,6 +298,9 @@ class DboMysql extends DboSource {
}
$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 @@ class DboMysql extends DboSource {
}
}
$result->closeCursor();
if (is_string($name)) {
if (is_string($name) && isset($tables[$name])) {
return $tables[$name];
}
return $tables;

View file

@ -795,6 +795,21 @@ class DboMysqlTest extends CakeTestCase {
$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