Permalink
Browse files

Added support to CaseExpression. Added support to nest AndX and OrX Q…

…ueryBuilder composite expressions, since they do not mess with generated queries.
  • Loading branch information...
1 parent 1666d59 commit 816ce41f638d28934c79a12ef27f954124b2639e @guilhermeblanco guilhermeblanco committed Aug 8, 2011
@@ -0,0 +1,48 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\ORM\Query\AST;
+
+/**
+ * GeneralCaseExpression ::= "CASE" WhenClause {WhenClause}* "ELSE" ScalarExpression "END"
+ *
+ * @since 2.2
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @link www.doctrine-project.org
+ * @author Benjamin Eberlei <kontakt@beberlei.de>
+ * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
+ * @author Jonathan Wage <jonwage@gmail.com>
+ * @author Roman Borschel <roman@code-factory.org>
+ */
+class GeneralCaseExpression extends Node
+{
+ public $whenClauses = array();
+ public $elseScalarExpression = null;
+
+ public function __construct(array $whenClauses, $elseScalarExpression)
+ {
+ $this->whenClauses = $whenClauses;
+ $this->elseScalarExpression = $elseScalarExpression;
+ }
+
+ public function dispatch($sqlWalker)
+ {
+ return $sqlWalker->walkGeneralCaseExpression($this);
+ }
+}
@@ -0,0 +1,50 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\ORM\Query\AST;
+
+/**
+ * SimpleCaseExpression ::= "CASE" CaseOperand SimpleWhenClause {SimpleWhenClause}* "ELSE" ScalarExpression "END"
+ *
+ * @since 2.2
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @link www.doctrine-project.org
+ * @author Benjamin Eberlei <kontakt@beberlei.de>
+ * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
+ * @author Jonathan Wage <jonwage@gmail.com>
+ * @author Roman Borschel <roman@code-factory.org>
+ */
+class SimpleCaseExpression extends Node
+{
+ public $caseOperand = null;
+ public $simpleWhenClauses = array();
+ public $elseScalarExpression = null;
+
+ public function __construct($caseOperand, array $simpleWhenClauses, $elseScalarExpression)
+ {
+ $this->caseOperand = $caseOperand;
+ $this->simpleWhenClauses = $simpleWhenClauses;
+ $this->elseScalarExpression = $elseScalarExpression;
+ }
+
+ public function dispatch($sqlWalker)
+ {
+ return $sqlWalker->walkSimpleCaseExpression($this);
+ }
+}
@@ -0,0 +1,48 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\ORM\Query\AST;
+
+/**
+ * SimpleWhenClause ::= "WHEN" ScalarExpression "THEN" ScalarExpression
+ *
+ * @since 2.2
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @link www.doctrine-project.org
+ * @author Benjamin Eberlei <kontakt@beberlei.de>
+ * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
+ * @author Jonathan Wage <jonwage@gmail.com>
+ * @author Roman Borschel <roman@code-factory.org>
+ */
+class SimpleWhenClause extends Node
+{
+ public $caseScalarExpression = null;
+ public $thenScalarExpression = null;
+
+ public function __construct($caseScalarExpression, $thenScalarExpression)
+ {
+ $this->caseScalarExpression = $caseScalarExpression;
+ $this->thenScalarExpression = $thenScalarExpression;
+ }
+
+ public function dispatch($sqlWalker)
+ {
+ return $sqlWalker->walkWhenClauseExpression($this);
+ }
+}
@@ -0,0 +1,48 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\ORM\Query\AST;
+
+/**
+ * WhenClause ::= "WHEN" ConditionalExpression "THEN" ScalarExpression
+ *
+ * @since 2.2
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @link www.doctrine-project.org
+ * @author Benjamin Eberlei <kontakt@beberlei.de>
+ * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
+ * @author Jonathan Wage <jonwage@gmail.com>
+ * @author Roman Borschel <roman@code-factory.org>
+ */
+class WhenClause extends Node
+{
+ public $caseConditionExpression = null;
+ public $thenScalarExpression = null;
+
+ public function __construct($caseConditionExpression, $thenScalarExpression)
+ {
+ $this->caseConditionExpression = $caseConditionExpression;
+ $this->thenScalarExpression = $thenScalarExpression;
+ }
+
+ public function dispatch($sqlWalker)
+ {
+ return $sqlWalker->walkWhenClauseExpression($this);
+ }
+}
@@ -39,5 +39,6 @@ class Andx extends Composite
'Doctrine\ORM\Query\Expr\Comparison',
'Doctrine\ORM\Query\Expr\Func',
'Doctrine\ORM\Query\Expr\Orx',
+ 'Doctrine\ORM\Query\Expr\Andx',
@mathiasverraes

mathiasverraes Sep 20, 2011

Any chance of committing this change and the one in Orx.php to the 2.1.x branch? Thanks :-)

);
}
@@ -36,8 +36,9 @@ class Orx extends Composite
{
protected $_separator = ' OR ';
protected $_allowedClasses = array(
- 'Doctrine\ORM\Query\Expr\Andx',
'Doctrine\ORM\Query\Expr\Comparison',
'Doctrine\ORM\Query\Expr\Func',
+ 'Doctrine\ORM\Query\Expr\Andx',
+ 'Doctrine\ORM\Query\Expr\Orx',
);
}
@@ -67,46 +67,49 @@ class Lexer extends \Doctrine\Common\Lexer
const T_DELETE = 113;
const T_DESC = 114;
const T_DISTINCT = 115;
- const T_EMPTY = 116;
- const T_ESCAPE = 117;
- const T_EXISTS = 118;
- const T_FALSE = 119;
- const T_FROM = 120;
- const T_GROUP = 121;
- const T_HAVING = 122;
- const T_IN = 123;
- const T_INDEX = 124;
- const T_INNER = 125;
- const T_INSTANCE = 126;
- const T_IS = 127;
- const T_JOIN = 128;
- const T_LEADING = 129;
- const T_LEFT = 130;
- const T_LIKE = 131;
- const T_MAX = 132;
- const T_MEMBER = 133;
- const T_MIN = 134;
- const T_NOT = 135;
- const T_NULL = 136;
- const T_NULLIF = 137;
- const T_OF = 138;
- const T_OR = 139;
- const T_ORDER = 140;
- const T_OUTER = 141;
- const T_SELECT = 142;
- const T_SET = 143;
- const T_SIZE = 144;
- const T_SOME = 145;
- const T_SUM = 146;
- const T_TRAILING = 147;
- const T_TRUE = 148;
- const T_UPDATE = 149;
- const T_WHEN = 150;
- const T_WHERE = 151;
- const T_WITH = 153;
- const T_PARTIAL = 154;
- const T_MOD = 155;
-
+ const T_ELSE = 116;
+ const T_EMPTY = 117;
+ const T_END = 118;
+ const T_ESCAPE = 119;
+ const T_EXISTS = 120;
+ const T_FALSE = 121;
+ const T_FROM = 122;
+ const T_GROUP = 123;
+ const T_HAVING = 124;
+ const T_IN = 125;
+ const T_INDEX = 126;
+ const T_INNER = 127;
+ const T_INSTANCE = 128;
+ const T_IS = 129;
+ const T_JOIN = 130;
+ const T_LEADING = 131;
+ const T_LEFT = 132;
+ const T_LIKE = 133;
+ const T_MAX = 134;
+ const T_MEMBER = 135;
+ const T_MIN = 136;
+ const T_NOT = 137;
+ const T_NULL = 138;
+ const T_NULLIF = 139;
+ const T_OF = 140;
+ const T_OR = 141;
+ const T_ORDER = 142;
+ const T_OUTER = 143;
+ const T_SELECT = 144;
+ const T_SET = 145;
+ const T_SIZE = 146;
+ const T_SOME = 147;
+ const T_SUM = 148;
+ const T_THEN = 149;
+ const T_TRAILING = 150;
+ const T_TRUE = 151;
+ const T_UPDATE = 152;
+ const T_WHEN = 153;
+ const T_WHERE = 154;
+ const T_WITH = 155;
+ const T_PARTIAL = 156;
+ const T_MOD = 157;
+
/**
* Creates a new query scanner object.
*
Oops, something went wrong.

0 comments on commit 816ce41

Please sign in to comment.