Skip to content
Permalink
Browse files

Automatically quoting strings passed to isNull and isNotNull

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 06cc54c0f8c31ec7bc02c15351f8bff677105a1d
Showing with 25 additions and 2 deletions.
  1. +4 −2 src/Database/Expression/QueryExpression.php
  2. +21 −0 tests/TestCase/Database/QueryTest.php
@@ -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) {
@@ -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) {
@@ -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.
*

0 comments on commit 06cc54c

Please sign in to comment.
You can’t perform that action at this time.