From 612793d9cb2f3e5fe2f3b703a70844ae678361b9 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 25 Jun 2007 20:08:16 +0000 Subject: [PATCH] fixes #359 --- lib/Doctrine/Hydrate.php | 10 +++++++--- lib/Doctrine/Query.php | 12 ++++++++++-- tests/EnumTestCase.php | 38 ++++++++++++++++++++------------------ tests/run.php | 8 ++++---- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/lib/Doctrine/Hydrate.php b/lib/Doctrine/Hydrate.php index 30be228c7..240611ff4 100644 --- a/lib/Doctrine/Hydrate.php +++ b/lib/Doctrine/Hydrate.php @@ -102,6 +102,10 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable 'parserCache' => false, 'resultSetCache' => false, ); + /** + * @var string $_sql cached SQL query + */ + protected $_sql; /** * @var array $parts SQL query string parts */ @@ -643,14 +647,14 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable public function _execute($params, $return = Doctrine::FETCH_RECORD) { $params = $this->_conn->convertBooleans(array_merge($this->_params, $params)); - $params = $this->convertEnums($params); - + if ( ! $this->_view) { $query = $this->getQuery($params); } else { $query = $this->_view->getSelectSql(); } + $params = $this->convertEnums($params); if ($this->isLimitSubqueryUsed() && $this->_conn->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') { @@ -662,7 +666,7 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable return $this->_conn->exec($query, $params); } - $stmt = $this->_conn->execute($query, $params); + $stmt = $this->_conn->execute($query, $params); return $stmt; } /** diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index d90d7913f..dab7350aa 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -111,7 +111,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable } public function reset() { - $this->_enumParams = array(); $this->_pendingJoinConditions = array(); $this->pendingSubqueries = array(); $this->pendingFields = array(); @@ -304,7 +303,9 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable } } } - + + $this->_state = Doctrine_Query::STATE_DIRTY; + return $this; } /** @@ -688,6 +689,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable */ public function getQuery($params = array()) { + if ($this->_state !== self::STATE_DIRTY) { + return $this->_sql; + } + $parts = $this->_dqlParts; // reset the state @@ -722,6 +727,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable } } } + $params = $this->convertEnums($params); + $this->_state = self::STATE_DIRECT; // invoke the preQuery hook @@ -814,6 +821,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable if ($needsSubQuery) { array_shift($this->parts['where']); } + $this->_sql = $q; return $q; } diff --git a/tests/EnumTestCase.php b/tests/EnumTestCase.php index a96d69f43..11567511d 100644 --- a/tests/EnumTestCase.php +++ b/tests/EnumTestCase.php @@ -49,7 +49,9 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase try { $query = new Doctrine_Query($this->connection); - $ret = $query->query('FROM EnumTest WHERE EnumTest.status = ?', array('open')); + $ret = $query->parseQuery('FROM EnumTest WHERE EnumTest.status = ?') + ->execute(array('open')); + $this->assertEqual(count($ret), 1); } catch (Exception $e) { $this->fail(); @@ -108,22 +110,22 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase { $enum = new EnumTest(); - $enum->status = "open"; - $this->assertEqual($enum->status, "open"); + $enum->status = 'open'; + $this->assertEqual($enum->status, 'open'); $enum->save(); - $this->assertEqual($enum->status, "open"); + $this->assertEqual($enum->status, 'open'); $enum->refresh(); - $this->assertEqual($enum->status, "open"); + $this->assertEqual($enum->status, 'open'); - $enum->status = "closed"; + $enum->status = 'closed'; - $this->assertEqual($enum->status, "closed"); + $this->assertEqual($enum->status, 'closed'); $enum->save(); - $this->assertEqual($enum->status, "closed"); + $this->assertEqual($enum->status, 'closed'); $this->assertTrue(is_numeric($enum->id)); $enum->refresh(); - $this->assertEqual($enum->status, "closed"); + $this->assertEqual($enum->status, 'closed'); } public function testEnumTypeWithCaseConversion() @@ -132,25 +134,25 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase $enum = new EnumTest(); - $enum->status = "open"; - $this->assertEqual($enum->status, "open"); + $enum->status = 'open'; + $this->assertEqual($enum->status, 'open'); $enum->save(); - $this->assertEqual($enum->status, "open"); + $this->assertEqual($enum->status, 'open'); $enum->refresh(); - $this->assertEqual($enum->status, "open"); + $this->assertEqual($enum->status, 'open'); - $enum->status = "closed"; + $enum->status = 'closed'; - $this->assertEqual($enum->status, "closed"); + $this->assertEqual($enum->status, 'closed'); $enum->save(); - $this->assertEqual($enum->status, "closed"); + $this->assertEqual($enum->status, 'closed'); $enum->refresh(); - $this->assertEqual($enum->status, "closed"); - + $this->assertEqual($enum->status, 'closed'); + $this->conn->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); } diff --git a/tests/run.php b/tests/run.php index c81040f35..95a81d5c3 100644 --- a/tests/run.php +++ b/tests/run.php @@ -72,7 +72,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests'); $test->addTestCase(new Doctrine_Ticket330_TestCase()); */ - /** + /** */ // Connection drivers (not yet fully tested) $test->addTestCase(new Doctrine_Connection_Pgsql_TestCase()); $test->addTestCase(new Doctrine_Connection_Oracle_TestCase()); @@ -150,7 +150,7 @@ $test->addTestCase(new Doctrine_Expression_Oracle_TestCase()); $test->addTestCase(new Doctrine_Expression_Sqlite_TestCase()); // Core - */ + $test->addTestCase(new Doctrine_Access_TestCase()); //$test->addTestCase(new Doctrine_Configurable_TestCase()); @@ -179,10 +179,10 @@ $test->addTestCase(new Doctrine_Relation_Parser_TestCase()); // Datatypes $test->addTestCase(new Doctrine_Enum_TestCase()); + $test->addTestCase(new Doctrine_Boolean_TestCase()); - // Utility components //$test->addTestCase(new Doctrine_PessimisticLocking_TestCase()); @@ -299,7 +299,7 @@ $test->addTestCase(new Doctrine_Query_JoinCondition_TestCase()); $test->addTestCase(new Doctrine_Query_MultipleAggregateValue_TestCase()); $test->addTestCase(new Doctrine_Query_TestCase()); -/** */ + //$test->addTestCase(new Doctrine_IntegrityAction_TestCase()); //$test->addTestCase(new Doctrine_AuditLog_TestCase());