nilportugues / php-sql-query-builder

An elegant lightweight and efficient SQL Query Builder with fluid interface SQL syntax supporting bindings and complicated query generation.
http://nilportugues.com
MIT License
418 stars 115 forks source link

Do not filter values in AbstractCreationalQuery #113

Closed makeey closed 4 years ago

makeey commented 4 years ago

Hi @nilportugues !

Thank you for your great package, I really enjoy using it.

I have a problem with a query when my query should contain something which is not == to true (except the "0"). For example, I have a table which has the next structure:

CREATE TABLE IF NOT EXISTS `Example`
(
    `Id`          int(1)       NOT NULL,
    `Tittle`      VARCHAR(255) NOT NULL,
    `Description` LONGTEXT     NULL DEFAULT NULL,
    `IsSomething` bool not null default TRUE,

) ENGINE = InnoDB;

The problem is the description was set you can't set it to null anymore, and also you can't change IsSomething on false.

Reproduce the issue:

$genericBuilder = new GenericBuilder();
echo $genericBuilder->write(
    $genericBuilder->update()
        ->setTable('Example')
        ->setValues([
            'Title' => "example title",
            'isSomething' => false,
            'Description' => null
        ])
        ->where()
        ->equals('id', 5)
        ->end()
);
// ACTUAL: UPDATE Example SET  Example.Title = :v1 WHERE (Example.id = :v2)
// EXPECTED: UPDATE Example SET  Example.Title = :v1, Example.isSomething = :v2, Example.Description = :v3 WHERE (Example.id = :v4)

The issue was occurred before in the issue #82 but wasn't completely solve, only the integer case. Also a related issue: #92

makeey commented 4 years ago

Hi, @nilportugues have you had a chance to take a look at the PR?