From 11be65678ea96b7161323ae75560c404b23b2f99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 29 Jul 2023 17:06:35 +0200 Subject: [PATCH] Fixed order by FIELD emulation on sqlite via INSTR We need to search for the comma token separators at both ends of the search term, otherwise the ordering will be wrong. --- src/Doctrine/Helpers/FieldHelper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Doctrine/Helpers/FieldHelper.php b/src/Doctrine/Helpers/FieldHelper.php index 357fe1fc..49dc1475 100644 --- a/src/Doctrine/Helpers/FieldHelper.php +++ b/src/Doctrine/Helpers/FieldHelper.php @@ -66,9 +66,9 @@ final class FieldHelper private static function addSqliteOrderBy(QueryBuilder $qb, string $field_expr, string $key, array $values, ?string $order = null): void { //Otherwise we emulate it using - $qb->orderBy("LOCATE(CONCAT($field_expr, ','), :$key)", $order); - //The value have to end with a comma, otherwise the search using INSTR will fail - $qb->setParameter($key, implode(',', $values) . ','); + $qb->orderBy("LOCATE(CONCAT(',', $field_expr, ','), :$key)", $order); + //The string must be padded with a comma on both sides, otherwise the search using INSTR will fail + $qb->setParameter($key, ',' .implode(',', $values) . ','); } /**