Skip to content

Fix NULL handling when binding boolean parameter for native pgsql driver #7024

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

Open
wants to merge 3 commits into
base: 3.10.x
Choose a base branch
from

Conversation

ribeiropaulor
Copy link

Q A
Type bug/feature/improvement
Fixed issues #7022

Summary

PostgreSQL allows 3 values in a boolean column: TRUE, FALSE and NULL.

Previously, when binding NULL to a boolean column, it passed the value as FALSE to the database. It prevents having NULL values in the nullable boolean column.

This PR involves the changes below.

  • It fixes this issue by forwarding NULL to the database.
  • The test has been modified to guarantee correct behavior in this scenario.

PostgreSQL allows 3 values in a boolean column: TRUE, FALSE and NULL.

Previously, when binding `NULL` to a boolean column, it passed the value
as FALSE to the database. It prevents having NULL values in the column,
when using Doctrine DBAL.

It fixes this issue passing `NULL` forward to the database.

The test has been modified to test this scenario.
@ribeiropaulor
Copy link
Author

I have no idea why it CI Testing PHP 7.4 with SQLite failing. I tested in my dev machine and test passed.

What should I do to make it through?

@derrabus
Copy link
Member

I have no idea why it CI Testing PHP 7.4 with SQLite failing.

You're asserting that the database will return a real boolean. However, many databases don't know what a boolean is and even if they do, the corresponding drivers don't cast to boolean. You'll get 0 or 1 instead, either as integer or string.

@VincentLanglet
Copy link
Contributor

@ribeiropaulor did you try removing

assert($valueFromDatabase === null || is_bool($valueFromDatabase));

?

The correct assertion is done by

self::assertSame(
            $input,
            $this->connection->convertToPHPValue($valueFromDatabase, 'boolean'),
            'Must return from database the same value inserted.',
        );

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.

3 participants