Skip to content

Commit d566ad4

Browse files
Prometeejaviereguiluz
authored andcommitted
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 4d1cb25 commit d566ad4

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
@@ -285,6 +285,7 @@ of the UUID parameters::
285285
// src/Repository/ProductRepository.php
286286

287287
// ...
288+
use Doctrine\DBAL\ParameterType;
288289
use Symfony\Bridge\Doctrine\Types\UuidType;
289290

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

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

306308
// ...

0 commit comments

Comments
 (0)