#011784: Database: in() expression quotes sub-selects incorrectly for MySQL handler

Description:

When using a a sub select with the IN expression of the Database SQL abstraction, one needs to manually switch off quoting of values to make it work.

Instead of


$q = // Some ezcDbMysqlSelectQuery

$qQuestions = $q->subSelect();
$qQuestions->select( 'id' )->from( 'question' )->where( $qQuestions->expr->eq( 'quiz', $qQuestions->bindValue( (int) $quiz->id ) ) );

$q->where(
    $q->expr->in( 'question', $qQuestions )
);

you need to do


$q = // Some ezcDbMysqlSelectQuery

$qQuestions = $q->subSelect();
$qQuestions->select( 'id' )->from( 'question' )->where( $qQuestions->expr->eq( 'quiz', $qQuestions->bindValue( (int) $quiz->id ) ) );

$q->expr->setValuesQuoting( false );
$q->where(
    $q->expr->in( 'question', $qQuestions )
);
$q->expr->setValuesQuoting( true );

to make the sub-select be executed and not be handled like a value. Quoting should be turned off for any sub-selects that are submitted to an expression and I asume this gives errors with almost any other RDBS, too.


Environment:

Operating System:
PHP Version: (please be specific, like '4.4.3' or '5.1.5')
Database and version:
Browser (and version):


Steps to Reproduce:

This example shows the incorrectly quoted query.


$q = $db->createSelectQuery();
$q->select( 'somecol' )->from( 'quiz' );

$qQuestions = $q->subSelect();
$qQuestions->select( 'id' )->from( 'question' )->where(
    $qQuestions->expr->eq( 'quiz', $qQuestions->bindValue( 1 ) )
);

$q->where(
    $q->expr->in( 'question', $qQuestions )
);

echo $q->getQuery();

- Attachments

No attachments for this issue.


- Comments

It apparently is already fixed earlier. Please re-open if you can reproduce this issue later. I added a test case for this in rev. 7060.

#255309 by Derick Rethans on January 3rd, 2008 [Permanent Link]

Exists with PHP > 5.2 since explode() casts the sub-select to a string.

#257055 by Tobias Schlitt on June 12th, 2008 [Permanent Link]

This Bug appears still in the current version.

#261402 by Sebastian Blank on April 27th, 2009 [Permanent Link]

I'm sorry, but I can't reproduce this here. I added another test case in rev. #10233 to make sure the issue is gone. I tested it with PHP 5.2.8 against SQLite memory and MySQL and it worked fine. Please re-open this bug with a reproducing code snippet and further environment information, if you still experience problems.

#261513 by Tobias Schlitt on May 8th, 2009 [Permanent Link]

See test case added in rev. #10233.

#261514 by Tobias Schlitt on May 8th, 2009 [Permanent Link]

I could reproduce the problem. Fixing now.

#262287 by Tobias Schlitt on July 15th, 2009 [Permanent Link]

Fixed in rev. #10656.

#262288 by Tobias Schlitt on July 15th, 2009 [Permanent Link]

- History
Properties
Type Bug
Priority Medium
Component Components » Database
Affects Unknown
Fix Versions 2007.2.1 - eZ components 2007.2.1
2008.2.3 - eZ components 2008.2.3
2009.1.1 - eZ components 2009.1.1
2009.2 sprint 1 - eZ components 2009.2 sprint 1
Reporter Tobias Schlitt
Responsible Tobias Schlitt
Status 0 Closed
Resolution Fixed
Created October 30th, 2007
Updated July 28th, 2009
Resolved July 15th, 2009
 
Navigation [Permanent Link]
Previous Issue
Back to Issues List
Next Issue: #015537
  Graph shows to small and truncated rotated axis labels