From 5f1e6ba6a0b671dd6b72824a612a90ec41141f7c Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 20:31:29 -0400 Subject: [PATCH] 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 --- cake/libs/model/datasources/dbo_source.php | 4 +++- .../libs/model/datasources/dbo_source.test.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 5f2ac8de8..acb433063 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -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; } diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index c35a8314a..9e5c08d1f 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -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 *