-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
Bug Report
Q | A |
---|---|
Version | 3.10.x |
Summary
PostgreSQL allows 3 values in a boolean column: TRUE, FALSE and NULL.
I cannot set NULL to a nullable boolean column using PostgreSQL.
Current behavior
Instead of passing NULL to PostgreSQL, it forwards as FALSE.
Expected behavior
I should pass as NULL, so, when I fetch the row, I get NULL as result.
How to reproduce
The functional test Doctrine\DBAL\Tests\Functional\BooleanBindingTest
could be modified to test the insertion of NULL values. Then it would certainly fail. The following excerpt of Doctrine\DBAL\Driver\PgSQL\Statement
is responsible for mishandling NULL values. It does not care about NULL values as it chooses between TRUE or FALSE to forward the value.
/** {@inheritDoc} */
public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
{
if (! isset($this->parameterMap[$param])) {
throw UnknownParameter::new((string) $param);
}
if ($type === ParameterType::BOOLEAN) {
$this->parameters[$this->parameterMap[$param]] = (bool) $value === false ? 'f' : 't';
$this->parameterTypes[$this->parameterMap[$param]] = ParameterType::STRING;
} else {
$this->parameters[$this->parameterMap[$param]] = $value;
$this->parameterTypes[$this->parameterMap[$param]] = $type;
}
}