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

[pgsql] invalid input syntax for type boolean: "" #6780

Open
fabpico opened this issue Feb 11, 2025 · 0 comments
Open

[pgsql] invalid input syntax for type boolean: "" #6780

fabpico opened this issue Feb 11, 2025 · 0 comments

Comments

@fabpico
Copy link

fabpico commented Feb 11, 2025

Bug Report

Q A
Version 3.9.3

Summary

I usually use $queryBuilder->createNamedParameter($value) to create queries with prepared statements. Even for boolean values.
It was never a problem in mysql, mariadb and mssql in my cases years ago. Sometimes I had to add a type as second parameter.
pgsql now fails when the value ist false.

Current behavior

When I run one of following code, and the value is false

$queryBuilder->insert(self::TABLE)->values([
    'is_anonymous' => $queryBuilder->createNamedParameter($entity->isAnonymous()),
    // ..
])->executeQuery();
$queryBuilder->insert(self::TABLE)->values([
    'is_anonymous' => $queryBuilder->createNamedParameter($entity->isAnonymous(), ParameterType::BOOLEAN),
    // ..
])->executeQuery();

Following happens

Doctrine\DBAL\Exception\DriverException:
An exception occurred while executing a query: invalid input syntax for type boolean: ""

  at vendor/doctrine/dbal/src/Driver/API/PostgreSQL/ExceptionConverter.php:87
  at Doctrine\DBAL\Driver\API\PostgreSQL\ExceptionConverter->convert(object(Exception), object(Query))
     (vendor/doctrine/dbal/src/Connection.php:1939)
  at Doctrine\DBAL\Connection->handleDriverException(object(Exception), object(Query))
     (vendor/doctrine/dbal/src/Connection.php:1881)
...

After some debugging, I worked around to pass a literal 'false' string.

    private function booleanToLiteral(bool $value): string
    {
        return $value ? 'true' : 'false';
    }
$queryBuilder->insert(self::TABLE)->values([
    'is_anonymous' => $queryBuilder->createNamedParameter($this->booleanToLiteral($entity->isAnonymous())),
    // ..
])->executeQuery();

Expected behavior

The Query should succeed with one of these (without having to do an own conversion).

$queryBuilder->insert(self::TABLE)->values([
    'is_anonymous' => $queryBuilder->createNamedParameter($entity->isAnonymous()),
    // ..
])->executeQuery();
$queryBuilder->insert(self::TABLE)->values([
    'is_anonymous' => $queryBuilder->createNamedParameter($entity->isAnonymous(), ParameterType::BOOLEAN),
    // ..
])->executeQuery();

How to reproduce

See the code snippets.

Further

I searched for this issue and found some related issues, but they didn't talk directly about createNamedParameter: #1847, #564, #625,

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

1 participant