Skip to content

Commit

Permalink
Making DboSource::fetchAll return $this->_result if it is a boolean a…
Browse files Browse the repository at this point in the history
…nd $out is empty. Allows for Model::query() to return boolean values for operations that do not return recordsets. Fixes #6404
  • Loading branch information
markstory committed Oct 30, 2009
1 parent 5c4bc35 commit 5f1e6ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cake/libs/model/datasources/dbo_source.php
Expand Up @@ -383,8 +383,10 @@ function fetchAll($sql, $cache = true, $modelName = null) {
$this->_queryCache[$sql] = $out;
}
}
if (empty($out) && is_bool($this->_result)) {
return $this->_result;
}
return $out;

} else {
return false;
}
Expand Down
17 changes: 17 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo_source.test.php
Expand Up @@ -4047,6 +4047,23 @@ function testExecute() {
$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
*
Expand Down

0 comments on commit 5f1e6ba

Please sign in to comment.