Skip to content

Commit

Permalink
Automatically quoting strings passed to isNull and isNotNull
Browse files Browse the repository at this point in the history
All other methods in QueryExpression had the same behavior so it
made sense to support that here too. Fixes #3836
  • Loading branch information
lorenzo committed Jun 30, 2014
1 parent ee0eb63 commit 06cc54c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Database/Expression/QueryExpression.php
Expand Up @@ -202,7 +202,8 @@ public function lte($field, $value, $type = null) {
/**
* Adds a new condition to the expression object in the form "field IS NULL".
*
* @param string|ExpressionInterface $field database field to be tested for null
* @param string|\Cake\Database\ExpressionInteface $field database field to be
* tested for null
* @return QueryExpression
*/
public function isNull($field) {
Expand All @@ -215,7 +216,8 @@ public function isNull($field) {
/**
* Adds a new condition to the expression object in the form "field IS NOT NULL".
*
* @param string $field database field to be tested for not null
* @param string|\Cake\Database\ExpressionInteface $field database field to be
* tested for not null
* @return QueryExpression
*/
public function isNotNull($field) {
Expand Down
21 changes: 21 additions & 0 deletions tests/TestCase/Database/QueryTest.php
Expand Up @@ -2515,6 +2515,27 @@ public function testIsNullWithExpressions() {
$this->assertEmpty($result->fetchAll('assoc'));
}

/**
* Tests that strings passed to isNull and isNotNull will be treaded as identifiers
* when using autoQuoting
*
* @return void
*/
public function testIsNullAutoQuoting() {
$this->connection->driver()->autoQuoting(true);
$query = new Query($this->connection);
$query->select('*')->from('things')->where(function($exp) {
return $exp->isNull('field');
});
$this->assertQuotedQuery('WHERE \(<field>\) IS NULL', $query->sql());

$query = new Query($this->connection);
$query->select('*')->from('things')->where(function($exp) {
return $exp->isNotNull('field');
});
$this->assertQuotedQuery('WHERE \(<field>\) IS NOT NULL', $query->sql());
}

/**
* Assertion for comparing a table's contents with what is in it.
*
Expand Down

0 comments on commit 06cc54c

Please sign in to comment.