From 51df4df9f1986be1fb695a424296b6ca6679b03d Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 2 Jun 2015 20:19:12 +1200 Subject: [PATCH] Fix merge regressions / errors --- dev/FixtureBlueprint.php | 2 +- model/queries/SQLSelect.php | 7 ++++++- tests/model/SQLQueryTest.php | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dev/FixtureBlueprint.php b/dev/FixtureBlueprint.php index 3c77b50d9..e7eb51d33 100644 --- a/dev/FixtureBlueprint.php +++ b/dev/FixtureBlueprint.php @@ -298,7 +298,7 @@ class FixtureBlueprint { DB::manipulate(array( $table => array( "command" => "update", "id" => $obj->ID, - "fields" => array($fieldName => is_string($value) ? "'$value'" : $value) + "fields" => array($fieldName => $value) ) )); $obj->$fieldName = $value; diff --git a/model/queries/SQLSelect.php b/model/queries/SQLSelect.php index 7dfbf015f..ee388d4f4 100644 --- a/model/queries/SQLSelect.php +++ b/model/queries/SQLSelect.php @@ -576,8 +576,13 @@ class SQLSelect extends SQLConditionalExpression { * @return int */ public function count( $column = null) { + // we can't clear the select if we're relying on its output by a HAVING clause + if(!empty($this->having)) { + $records = $this->execute(); + return $records->numRecords(); + } // Choose a default column - if($column == null) { + elseif($column == null) { if($this->groupby) { $column = 'DISTINCT ' . implode(", ", $this->groupby); } else { diff --git a/tests/model/SQLQueryTest.php b/tests/model/SQLQueryTest.php index 5341283b4..db65c35e1 100755 --- a/tests/model/SQLQueryTest.php +++ b/tests/model/SQLQueryTest.php @@ -596,7 +596,7 @@ class SQLQueryTest extends SapphireTest { public function testSelect() { $query = new SQLQuery('"Title"', '"MyTable"'); $query->addSelect('"TestField"'); - $this->assertEquals( + $this->assertSQLEquals( 'SELECT "Title", "TestField" FROM "MyTable"', $query->sql() ); @@ -606,7 +606,7 @@ class SQLQueryTest extends SapphireTest { 'Field' => '"Field"', 'AnotherAlias' => '"AnotherField"' )); - $this->assertEquals( + $this->assertSQLEquals( 'SELECT "Field", "AnotherField" AS "AnotherAlias" FROM "MyTable"', $query->sql() ); @@ -615,7 +615,7 @@ class SQLQueryTest extends SapphireTest { $query->addSelect(array( 'Relevance' => "MATCH (Title, MenuTitle) AGAINST ('Two as One')" )); - $this->assertEquals( + $this->assertSQLEquals( 'SELECT "Field", "AnotherField" AS "AnotherAlias", MATCH (Title, MenuTitle) AGAINST (' . '\'Two as One\') AS "Relevance" FROM "MyTable"', $query->sql()