From 115cadb081227e40cb86a2b0c5cc2a06e3c13e3d Mon Sep 17 00:00:00 2001 From: zYne Date: Fri, 8 Jun 2007 20:17:17 +0000 Subject: [PATCH] complete support for DISTINCT keyword --- lib/Doctrine/Query.php | 10 ++++++++++ lib/Doctrine/Query/Abstract.php | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 9ac2b041c..cb3256821 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -339,6 +339,15 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable { $refs = Doctrine_Tokenizer::bracketExplode($dql, ','); + $pos = strpos(trim($refs[0]), ' '); + $first = substr($refs[0], 0, $pos); + + if ($first === 'DISTINCT') { + $this->parts['distinct'] = true; + + $refs[0] = substr($refs[0], ++$pos); + } + foreach ($refs as $reference) { $reference = trim($reference); if (strpos($reference, '(') !== false) { @@ -350,6 +359,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable } } else { + $e = explode('.', $reference); if (count($e) > 2) { $this->pendingFields[] = $reference; diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index 57e895d22..af0751c6e 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -118,8 +118,8 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate * @return Doctrine_Query */ public function distinct($flag = true) - { - $this->_parts['distinct'] = (bool) $flag; + { + $this->parts['distinct'] = (bool) $flag; return $this; } @@ -133,7 +133,7 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate */ public function forUpdate($flag = true) { - $this->_parts[self::FOR_UPDATE] = (bool) $flag; + $this->parts[self::FOR_UPDATE] = (bool) $flag; return $this; }