Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented multiple enhancements in InExpression support for DQL. Fi…

…xed DDC-1472 and DDC-1416.
  • Loading branch information...
commit 0380d5ae580dcbefd63051028fc1ab78599fda6c 1 parent a26990c
@guilhermeblanco guilhermeblanco authored
View
6 lib/Doctrine/ORM/Query/AST/InExpression.php
@@ -35,13 +35,13 @@
class InExpression extends Node
{
public $not;
- public $pathExpression;
+ public $expression;
public $literals = array();
public $subselect;
- public function __construct($pathExpression)
+ public function __construct($expression)
{
- $this->pathExpression = $pathExpression;
+ $this->expression = $expression;
}
public function dispatch($sqlWalker)
View
2  lib/Doctrine/ORM/Query/Parser.php
@@ -2720,7 +2720,7 @@ public function ComparisonExpression()
*/
public function InExpression()
{
- $inExpression = new AST\InExpression($this->SingleValuedPathExpression());
+ $inExpression = new AST\InExpression($this->ArithmeticExpression());
if ($this->_lexer->isNextToken(Lexer::T_NOT)) {
$this->match(Lexer::T_NOT);
View
3  lib/Doctrine/ORM/Query/SqlWalker.php
@@ -1727,8 +1727,7 @@ public function walkNullComparisonExpression($nullCompExpr)
*/
public function walkInExpression($inExpr)
{
- $sql = $this->walkPathExpression($inExpr->pathExpression)
- . ($inExpr->not ? ' NOT' : '') . ' IN (';
+ $sql = $this->walkArithmeticExpression($inExpr->expression) . ($inExpr->not ? ' NOT' : '') . ' IN (';
$sql .= ($inExpr->subselect)
? $this->walkSubselect($inExpr->subselect)
View
8 tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -451,8 +451,8 @@ public function testSupportsInstanceOfExpressionsUsingInputParameterInWherePart(
public function testSupportsSingleValuedInExpressionWithoutSpacesInWherePart()
{
$this->assertSqlGeneration(
- "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN(46)",
- "SELECT c0_.name AS name0 FROM cms_users c0_ WHERE c0_.id IN (46)"
+ "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE IDENTITY(u.email) IN(46)",
@Koc
Koc added a note

What is the function IDENTITY? I cann't find it here http://www.doctrine-project.org/docs/orm/2.1/en/reference/dql-doctrine-query-language.html#dql-functions . Does it avalible since 2.2 only?

@guilhermeblanco Owner

IDENTITY() should only be used in SelectExpressions. I added there to illustrate support for functions.
The idea of IDENTITY() is to retrieve fk columns only of a single valued association.
Example:

SELECT IDENTITY(u.Group) FROM User u
===
SELECT c0_.group_id FROM users u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ "SELECT c0_.name AS name0 FROM cms_users c0_ WHERE c0_.email_id IN (46)"
);
}
@@ -467,8 +467,8 @@ public function testSupportsMultipleValuedInExpressionInWherePart()
public function testSupportsNotInExpressionInWherePart()
{
$this->assertSqlGeneration(
- 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT IN (1)',
- 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.id NOT IN (1)'
+ 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :id NOT IN (1)',
@Koc
Koc added a note

I'm wrinting custon function DISTANCE(latFrom, lngFrom, latTo, lngTo). In function handler I'm using ArithmeticExpression method call, but when put into function named parameters it thows exception (unexpected token). With columns and scalars all ok.

What do I wrong, can you advice?

@guilhermeblanco Owner

Can you open a ticket about this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE ? NOT IN (1)'
);
}

8 comments on commit 0380d5a

@beberlei
Owner

There was a ticket for this aswell or not?

@guilhermeblanco

@beberlei Yes, two! I already closed them. I even added the references in my commit message! =P DDC-1472 and DDC-1416

@merk

This commit appears to break the KnpPaginator (and maybe other things), I end up with a fatal error:

( ! ) Fatal error: Call to undefined method Doctrine\ORM\Query\AST\PathExpression::isSimpleArithmeticExpression() in /Users/tim/Sites/ibms.dev/vendor/doctrine/lib/Doctrine/ORM/Query/SqlWalker.php on line 1942

@stof

the SqlWalker needs to be updated. And it will also impact @beberlei's Paginate extension and Pagerfanta as they all use @beberlei's walker.

@guilhermeblanco

@merk @stof Someone else reported me yesterday about this issue.
I don't know what to consider here. Functions should work since the beginning, so it's a bug. But at the same time I improved it, so it's an enhancement.
Is it possible for you all update your Paginators?

Thanks

@beberlei
Owner

@guilhermeblanco there a way to make this BC until at least 2.3?

@l3pp4rd

I have added a fix in knp_components if the bug is worth fixing, I guess not many people used query walkers that much for daily projects

@stof

and I've ported the fix to Pagerfanta. So only @beberlei's paginator is missing for the 3 main ones.

Please sign in to comment.
Something went wrong with that request. Please try again.