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

Do not insert null string in sql query if string is '0' #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

makeey
Copy link
Contributor

@makeey makeey commented Oct 22, 2020

Hello @nilportugues!
I run into an issue during using the query builder, I have next table structure.

CREATE TABLE IF NOT EXISTS `Table` (
  `UserID` int(1) NOT NULL,
  `EnumValue` ENUM("0", "1", "2") NOT NULL
) ENGINE = InnoDB;

If I'll use "0" as the value of enums (it says for status), the result will be "NULL" in the query.
Code to reproduce the issue

$genericQueryBuilder = new \NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder();

$query = $genericQueryBuilder->update()
    ->setTable('table')
    ->setValues(
        [
            'EnumValue' => '0'
        ]
    )->where()
    ->equals('UserId', 1)
    ->end();
echo $genericQueryBuilder->write($query);
//UPDATE table SET  table.EnumValue = :v1 WHERE (table.UserId = :v2)
var_dump($genericQueryBuilder->getValues());
/*
array(2) {
  [":v1"]=>
  string(1) "NULL"
  [":v2"]=>
  int(1)
}

*/

As you can see '0' becomes NULL in the end, and it isn't a valid enum value in this case
expected values would be

/*
array(2) {
  [":v1"]=>
  string(1) "0"
  [":v2"]=>
  int(1)
}
*/

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

Successfully merging this pull request may close these issues.

None yet

1 participant