Skip to content

Commit

Permalink
PostgreSQL setparameter() compatibility
Browse files Browse the repository at this point in the history
Using PostgreSQL, Doctrine will use UUID field type. If you don't specify the parameter type it will try to send a string instead of the binary content and fail with an error :

```
SQLSTATE[22021]: Character not in repertoire: 7 ERROR:  invalid byte sequence for encoding \"UTF8\": ...
CONTEXT:  unnamed portal parameter $1
```
  • Loading branch information
Prometee authored and javiereguiluz committed Mar 5, 2024
1 parent 4d1cb25 commit d566ad4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion components/uid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ of the UUID parameters::
// src/Repository/ProductRepository.php

// ...
use Doctrine\DBAL\ParameterType;
use Symfony\Bridge\Doctrine\Types\UuidType;

class ProductRepository extends ServiceEntityRepository
Expand All @@ -300,7 +301,8 @@ of the UUID parameters::

// alternatively, you can convert it to a value compatible with
// the type inferred by Doctrine
->setParameter('user', $user->getUuid()->toBinary())
// Note: ParameterType::BINARY is required to query PostgreSQL
->setParameter('user', $user->getUuid()->toBinary(), ParameterType::BINARY)
;

// ...
Expand Down

0 comments on commit d566ad4

Please sign in to comment.