Closed gregGit closed 2 weeks ago
@gregGit thanks for reporting this error and for the detailed explanation.
I'm using your proposed fix in #6292. I'd like to rework this to use a different solution that doesn't require that concatenation ... but I need this bug fix urgently, so let's use it for now. Thanks!
Describe the bug When you a search is done using the search bar, on postgresql a SQL error is thrown when a searchable field is an integer
To Reproduce Every search with easyadmin 4.10.0 when a integer field is inclued in the search, and using a postgresql database. Why ? Because postgresql doesn't support lower(field) if field is a int, because lower function in postsgresql require a varchar value (and so postgresql throw a error ERROR: function lower(integer) does not exist)
(OPTIONAL) Additional context The bug is on the file EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository On recent version L123 was modified from
elseif ($propertyConfig['is_text'])
toelseif ($propertyConfig['is_text'] || $propertyConfig['is_integer'])
So you add the ability to use a like search on a integer field, but this doesn't work on postgresql DB. (but probably work fine on Mysql/mariaDb)
A solution can be to modify L125 from
$queryTermConditions->add(sprintf('LOWER(%s.%s) LIKE :%s', $entityName, $propertyConfig['property_name'], $parameterName));
to$queryTermConditions->add(sprintf("LOWER(CONCAT(%s.%s, '')) LIKE :%s", $entityName, $propertyConfig['property_name'], $parameterName));
Explanation : By using CONCAT(%s.%s, '') we don't change the fied value, but the result of concat is a varchar, so LOWER works fine.