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

Comparison against empty string converted to 'NULL' string #106

Open
russell-pa opened this issue May 16, 2019 · 1 comment
Open

Comparison against empty string converted to 'NULL' string #106

russell-pa opened this issue May 16, 2019 · 1 comment

Comments

@russell-pa
Copy link

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"
}
@Silic0nS0ldier
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants