Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExpressionBuilder in and notIn methods #192

Merged
merged 3 commits into from
Aug 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,32 @@ public function like($x, $y)
return $this->comparison($x, 'LIKE', $y);
}

/**
* Creates a IN () comparison expression with the given arguments.
*
* @param string $x field in string format to be inspected by IN() comparison.
* @param array $y Array of values to be used by IN() comparison.
*
* @return string
*/
public function in($x, array $y)
{
return $this->comparison($x, 'IN', '('.implode(', ', $y).')');
}

/**
* Creates a NOT IN () comparison expression with the given arguments.
*
* @param string $x field in string format to be inspected by NOT IN() comparison.
* @param array $y Array of values to be used by NOT IN() comparison.
*
* @return string
*/
public function notIn($x, array $y)
{
return $this->comparison($x, 'NOT IN', '('.implode(', ', $y).')');
}

/**
* Quotes a given input parameter.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,14 @@ public function testIsNotNull()
{
$this->assertEquals('u.updated IS NOT NULL', $this->expr->isNotNull('u.updated'));
}

public function testIn()
{
$this->assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', array(1,3,4,7)));
}

public function testNotIn()
{
$this->assertEquals('u.groups NOT IN (1, 3, 4, 7)', $this->expr->notIn('u.groups', array(1,3,4,7)));
}
}