php-sql-query-builder
php-sql-query-builder copied to clipboard
Comparison against empty string converted to 'NULL' string
Trying to use an empty string for a comparison causes the query builder to replace it with a string of NULL.
Example:
$builder = new \NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
$select = $builder->select('SomeTable');
$select->where()->equals('someField', '');
$sql = $builder->writeFormatted($select);
$parameters = $builder->getValues();
var_dump($sql, $parameters);
string(80) "SELECT
SomeTable.*
FROM
SomeTable
WHERE
(SomeTable.someField = :v1)
"
array(1) {
[":v1"]=>
string(4) "NULL"
}
This is caused by NilPortugues\Sql\QueryBuilder\Builder\Syntax\PlaceholderWriter@writeNullSqlString
where an empty string is converted to NULL
(presumably to be the sql keyword, however its treated as a string value). Given values as passed via paramter binding, the correct behaviour here would be to not convert the value at all (leaving null
as null
). This issue appears to hail back from the initial implementation.