Skip to content

Commit ff75ef3

Browse files
authored
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 ```
1 parent 8387867 commit ff75ef3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

components/uid.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ of the UUID parameters::
273273
// src/Repository/ProductRepository.php
274274

275275
// ...
276+
use Doctrine\DBAL\ParameterType;
276277
use Symfony\Bridge\Doctrine\Types\UuidType;
277278

278279
class ProductRepository extends ServiceEntityRepository
@@ -288,7 +289,8 @@ of the UUID parameters::
288289

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

294296
// ...

0 commit comments

Comments
 (0)