Skip to content

Commit

Permalink
- Fixed issue #11784: Fixed quoting of sub-selects in "IN" expression.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.ez.no/svn/ezcomponents/trunk/Database@10656 bc0e7bdc-f0fc-0310-8ff6-f601c06e1256
  • Loading branch information
ts committed Jul 15, 2009
1 parent 3baf692 commit 4488a13
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.4.6 - [RELEASEDATE]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Fixed issue #11784: Fixed quoting of sub-selects in "IN" expression.


1.4.5 - Monday 11 May 2009
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
15 changes: 8 additions & 7 deletions src/sqlabstraction/expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,20 +597,21 @@ public function in( $column )

$values = ezcQuerySelect::arrayFlatten( array_slice( $args, 1 ) );

$values = $this->getIdentifiers( $values );
$column = $this->getIdentifier( $column );

if ( count( $values ) == 0 )
{
throw new ezcQueryVariableParameterException( 'in', count( $args ), 2 );
}


// Special handling of sub selects to avoid double braces
if ( count( $values ) === 1 && $values[0] instanceof ezcQuerySubSelect )
{
return "{$column} IN " . $values[0]->getQuery();
}

$values = $this->getIdentifiers( $values );

if ( count( $values ) == 0 )
{
throw new ezcQueryVariableParameterException( 'in', count( $args ), 2 );
}

if ( $this->quoteValues )
{
foreach ( $values as $key => $value )
Expand Down
17 changes: 16 additions & 1 deletion tests/sqlabstraction/query_subselect_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ public function testSubSelect()
$this->assertEquals( $reference, $q2->getQuery() );
}

public function testSubSelectNotQuoted()
{
$reference = 'SELECT * FROM test_table WHERE id IN ( SELECT column FROM sub_table WHERE id = 1 )';
$this->q->select( '*' )
->from( 'test_table' );

$subQ = $this->q->subSelect();
$subQ->select( 'column' )
->from( 'sub_table' )
->where( $subQ->expr->eq( 'id', 1 ) );

$this->q->where( $this->q->expr->in( 'id', $subQ ) );

$this->assertEquals( $reference, $this->q->getQuery() );
}

public function testSubSubSelect()
{
$reference = '( SELECT column FROM table WHERE id = ( SELECT * FROM table2 ) )';
Expand All @@ -93,7 +109,6 @@ public function testSubSubSelect()
$q2->select( 'column' )->from( 'table' )->where($q2->expr->eq('id', $q3->getQuery() ) );

$this->assertEquals( $reference, $q2->getQuery() );

}

public function testDistinctSubSelect()
Expand Down

0 comments on commit 4488a13

Please sign in to comment.