Skip to content

Commit

Permalink
bug #6242 Fixed invalid DQL (alshenetsky)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.x branch.

Discussion
----------

Fixed invalid DQL

Fixes #6223

When searching text having only integer fields, an invalid DQL like `SELECT entity FROM App\Entity\Product entity WHERE ` is generated because there are no any `$queryTermConditions`.  This PR should fix the issue.

Commits
-------

6511215 Fixed invalid DQL
  • Loading branch information
javiereguiluz committed Apr 16, 2024
2 parents ecfb473 + 6511215 commit 5e1e6d0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Orm/EntityRepository.php
Expand Up @@ -120,7 +120,7 @@ private function addSearchClause(QueryBuilder $queryBuilder, SearchDto $searchDt
$parameterName = sprintf('query_for_ulids_%d', $queryTermIndex);
$queryTermConditions->add(sprintf('%s.%s = :%s', $entityName, $propertyConfig['property_name'], $parameterName));
$queryBuilder->setParameter($parameterName, $dqlParameters['uuid_query'], 'ulid');
} elseif ($propertyConfig['is_text']) {
} elseif ($propertyConfig['is_text'] || $propertyConfig['is_integer']) {
$parameterName = sprintf('query_for_text_%d', $queryTermIndex);
$queryTermConditions->add(sprintf('LOWER(%s.%s) LIKE :%s', $entityName, $propertyConfig['property_name'], $parameterName));

This comment has been minimized.

Copy link
@hellomedia

hellomedia Apr 20, 2024

@javiereguiluz In my app, it triggers this postgresql error :
Undefined function: 7 ERROR: function lower(integer) does not exist.
LOWER() requires a string parameter.

This comment has been minimized.

Copy link
@hellomedia

hellomedia Apr 20, 2024

I suppose casting %s.%s to a string would fix it, but it is not clear to me what is the best way to do that in doctrine.

This comment has been minimized.

Copy link
@hellomedia

hellomedia Apr 20, 2024

It's fixed in #6227

$queryBuilder->setParameter($parameterName, $dqlParameters['text_query']);
Expand Down

0 comments on commit 5e1e6d0

Please sign in to comment.