diff -Naur -X .ign vendor//doctrine/orm/lib/Doctrine/ORM/Query/AST/iLikeExpression.php bodyrep-vendor//doctrine/orm/lib/Doctrine/ORM/Query/AST/iLikeExpression.php --- vendor//doctrine/orm/lib/Doctrine/ORM/Query/AST/iLikeExpression.php 1970-01-01 10:00:00.000000000 +1000 +++ bodyrep-vendor//doctrine/orm/lib/Doctrine/ORM/Query/AST/iLikeExpression.php 2012-09-19 01:40:50.000000000 +1000 @@ -0,0 +1,49 @@ +. + */ +namespace Doctrine\ORM\Query\AST; + +/** + * iLikeExpression ::= StringExpression ["NOT"] "ILIKE" string ["ESCAPE" char] + * + * + * @link www.doctrine-project.org + * @since 2.0 + * @author Guilherme Blanco + * @author Jonathan Wage + * @author Roman Borschel + */ +class iLikeExpression extends Node +{ + public $not; + public $stringExpression; + public $stringPattern; + public $escapeChar; + + public function __construct($stringExpression, $stringPattern, $escapeChar = null) + { + $this->stringExpression = $stringExpression; + $this->stringPattern = $stringPattern; + $this->escapeChar = $escapeChar; + } + + public function dispatch($sqlWalker) + { + return $sqlWalker->walkiLikeExpression($this); + } +} diff -Naur -X .ign vendor//doctrine/orm/lib/Doctrine/ORM/Query/Expr.php bodyrep-vendor//doctrine/orm/lib/Doctrine/ORM/Query/Expr.php --- vendor//doctrine/orm/lib/Doctrine/ORM/Query/Expr.php 2012-09-18 02:35:14.000000000 +1000 +++ bodyrep-vendor//doctrine/orm/lib/Doctrine/ORM/Query/Expr.php 2012-09-19 01:28:50.000000000 +1000 @@ -479,6 +479,11 @@ return new Expr\Comparison($x, 'LIKE', $y); } + public function ilike($x, $y) + { + return new Expr\Comparison($x, 'ILIKE', $y); + } + /** * Creates a CONCAT() function expression with the given arguments. * diff -Naur -X .ign vendor//doctrine/orm/lib/Doctrine/ORM/Query/Lexer.php bodyrep-vendor//doctrine/orm/lib/Doctrine/ORM/Query/Lexer.php --- vendor//doctrine/orm/lib/Doctrine/ORM/Query/Lexer.php 2012-09-18 02:35:14.000000000 +1000 +++ bodyrep-vendor//doctrine/orm/lib/Doctrine/ORM/Query/Lexer.php 2012-09-19 01:38:54.000000000 +1000 @@ -86,6 +86,7 @@ const T_LEADING = 132; const T_LEFT = 133; const T_LIKE = 134; + const T_ILIKE = 157; const T_MAX = 135; const T_MEMBER = 136; const T_MIN = 137; diff -Naur -X .ign vendor//doctrine/orm/lib/Doctrine/ORM/Query/Parser.php bodyrep-vendor//doctrine/orm/lib/Doctrine/ORM/Query/Parser.php --- vendor//doctrine/orm/lib/Doctrine/ORM/Query/Parser.php 2012-09-18 02:35:14.000000000 +1000 +++ bodyrep-vendor//doctrine/orm/lib/Doctrine/ORM/Query/Parser.php 2012-09-19 01:38:04.000000000 +1000 @@ -2183,7 +2183,7 @@ $peek = $this->_peekBeyondClosingParenthesis(); if (in_array($peek['value'], array("=", "<", "<=", "<>", ">", ">=", "!=")) || - in_array($peek['type'], array(Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS)) || + in_array($peek['type'], array(Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_ILIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS)) || $this->_isMathOperator($peek)) { $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); @@ -2260,6 +2260,8 @@ switch ($token['type']) { case Lexer::T_BETWEEN: return $this->BetweenExpression(); + case Lexer::T_ILIKE: + return $this->iLikeExpression(); case Lexer::T_LIKE: return $this->LikeExpression(); case Lexer::T_IN: @@ -2889,6 +2891,45 @@ return $likeExpr; } + /** + * iLikeExpression ::= StringExpression ["NOT"] "ILIKE" StringPrimary ["ESCAPE" char] + * + * @return \Doctrine\ORM\Query\AST\iLikeExpression + */ + public function iLikeExpression() + { + $stringExpr = $this->StringExpression(); + $not = false; + + if ($this->_lexer->isNextToken(Lexer::T_NOT)) { + $this->match(Lexer::T_NOT); + $not = true; + } + + $this->match(Lexer::T_ILIKE); + + if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { + $this->match(Lexer::T_INPUT_PARAMETER); + $stringPattern = new AST\InputParameter($this->_lexer->token['value']); + } else { + $stringPattern = $this->StringPrimary(); + } + + $escapeChar = null; + + if ($this->_lexer->lookahead['type'] === Lexer::T_ESCAPE) { + $this->match(Lexer::T_ESCAPE); + $this->match(Lexer::T_STRING); + + $escapeChar = new AST\Literal(AST\Literal::STRING, $this->_lexer->token['value']); + } + + $likeExpr = new AST\iLikeExpression($stringExpr, $stringPattern, $escapeChar); + $likeExpr->not = $not; + + return $likeExpr; + } + /** * NullComparisonExpression ::= (SingleValuedPathExpression | InputParameter) "IS" ["NOT"] "NULL" diff -Naur -X .ign vendor//doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php bodyrep-vendor//doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php --- vendor//doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php 2012-09-18 02:35:14.000000000 +1000 +++ bodyrep-vendor//doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php 2012-09-19 01:41:30.000000000 +1000 @@ -2028,6 +2028,36 @@ return $sql; } + /** + * Walks down a iLikeExpression AST node, thereby generating the appropriate SQL. + * + * @param iLikeExpression + * @return string The SQL. + */ + public function walkiLikeExpression($likeExpr) + { + $stringExpr = $likeExpr->stringExpression; + $sql = $stringExpr->dispatch($this) . ($likeExpr->not ? ' NOT' : '') . ' ILIKE '; + + if ($likeExpr->stringPattern instanceof AST\InputParameter) { + $inputParam = $likeExpr->stringPattern; + $dqlParamKey = $inputParam->name; + $this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++); + $sql .= '?'; + } elseif ($likeExpr->stringPattern instanceof AST\Functions\FunctionNode ) { + $sql .= $this->walkFunction($likeExpr->stringPattern); + } elseif ($likeExpr->stringPattern instanceof AST\PathExpression) { + $sql .= $this->walkPathExpression($likeExpr->stringPattern); + } else { + $sql .= $this->walkLiteral($likeExpr->stringPattern); + } + + if ($likeExpr->escapeChar) { + $sql .= ' ESCAPE ' . $this->walkLiteral($likeExpr->escapeChar); + } + + return $sql; + } /** * Walks down a StateFieldPathExpression AST node, thereby generating the appropriate SQL. *