$select = $this;
return preg_replace_callback('/([#!@])([a-zA-Z0-9_]+)/', function($m) use ($select, $args) {
- if (isset($args[$m[2]])) {
+ if (array_key_exists($m[2], $args)) {
$values = $args[$m[2]];
}
- elseif (isset($args[$m[1] . $m[2]])) {
+ elseif (array_key_exists($m[1] . $m[2], $args)) {
// Backward compat. Keys in $args look like "#myNumber" or "@myString".
$values = $args[$m[1] . $m[2]];
}
$this->assertLike('DELETE FROM foo WHERE (foo = "not\\"valid") AND (whiz > "in\\"valid") AND (frob != "in\\"valid")', $del->toSQL());
}
+ public function testWhereNullArg() {
+ $del = CRM_Utils_SQL_Delete::from('foo')
+ ->where('foo IS @value', array('@value' => NULL))
+ ->where('nonexistent IS @nonexistent', [])
+ ->where('morenonexistent IS @nonexistent', NULL)
+ ->where('bar IS @value', array('@value' => 'null'));
+ $this->assertLike('DELETE FROM foo WHERE (foo IS NULL) AND (nonexistent IS @nonexistent) AND (morenonexistent IS @nonexistent) AND (bar IS "null")', $del->toSQL());
+ }
+
/**
* @param $expected
* @param $actual
array('second' => '2b', 'first' => '1b'),
array('first' => '1c', 'second' => '2c'),
))
- ->row(array('second' => '2d', 'first' => '1d'));
+ ->row(array('second' => '2d', 'first' => '1d'))
+ ->row(array('first' => NULL, 'second' => '2e'));
$expected = '
INSERT INTO foo (`first`,`second`) VALUES
("1","2"),
("1b","2b"),
("1c","2c"),
- ("1d","2d")
+ ("1d","2d"),
+ (NULL,"2e")
';
$this->assertLike($expected, $insert->toSQL());
}
$this->assertLike('SELECT * FROM foo WHERE (foo = "not\\"valid") AND (whiz > "in\\"valid") AND (frob != "in\\"valid")', $select->toSQL());
}
+ public function testWhereNullArg() {
+ $select = CRM_Utils_SQL_Select::from('foo')
+ ->where('foo IS @value', array('@value' => NULL))
+ ->where('nonexistent IS @nonexistent', [])
+ ->where('morenonexistent IS @nonexistent', NULL)
+ ->where('bar IS @value', array('@value' => 'null'));
+ $this->assertLike('SELECT * FROM foo WHERE (foo IS NULL) AND (nonexistent IS @nonexistent) AND (morenonexistent IS @nonexistent) AND (bar IS "null")', $select->toSQL());
+ }
+
public function testGroupByPlain() {
$select = CRM_Utils_SQL_Select::from('foo')
->groupBy("bar_id")