From d566ad44e6ba669621367b4d3ca7637794c3d4c4 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 28 Feb 2024 16:53:14 +0100 Subject: [PATCH] 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 ``` --- components/uid.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/uid.rst b/components/uid.rst index f27977a8296..8febdc1ff88 100644 --- a/components/uid.rst +++ b/components/uid.rst @@ -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 @@ -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) ; // ...