Skip to content

Commit

Permalink
minor symfony#19615 PostgreSQL setparameter() compatibility (Prometee)
Browse files Browse the repository at this point in the history
This PR was submitted for the 7.0 branch but it was merged into the 6.4 branch instead.

Discussion
----------

PostgreSQL setparameter() compatibility

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
```

Commits
-------

d566ad4 PostgreSQL setparameter() compatibility
  • Loading branch information
javiereguiluz committed Mar 5, 2024
2 parents 4d1cb25 + d566ad4 commit 7f9ea29
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 7f9ea29

Please sign in to comment.