Making DboSource::fetchAll return $this->_result if it is a boolean and $out is empty. Allows for Model::query() to return boolean values for operations that do not return recordsets. Fixes #6404

This commit is contained in:
mark_story 2009-10-29 20:31:29 -04:00
parent 5c4bc35259
commit 5f1e6ba6a0
2 changed files with 20 additions and 1 deletions

View file

@ -383,8 +383,10 @@ class DboSource extends DataSource {
$this->_queryCache[$sql] = $out;
}
}
if (empty($out) && is_bool($this->_result)) {
return $this->_result;
}
return $out;
} else {
return false;
}

View file

@ -4047,6 +4047,23 @@ class DboSourceTest extends CakeTestCase {
$this->assertNotNull($this->db->took, 'Stats were not set %s');
$this->assertNotNull($this->db->affected, 'Stats were not set %s');
}
/**
* test that query() returns boolean values from operations like CREATE TABLE
*
* @return void
**/
function testFetchAllBooleanReturns() {
$name = $this->db->fullTableName('test_query');
$query = "CREATE TABLE {$name} (name varchar(10));";
$result = $this->db->query($query);
$this->assertTrue($result, 'Query did not return a boolean. %s');
$query = "DROP TABLE {$name};";
$result = $this->db->fetchAll($query);
$this->assertTrue($result, 'Query did not return a boolean. %s');
}
/**
* test ShowQuery generation of regular and error messages
*