database icon indicating copy to clipboard operation
database copied to clipboard

🐛 Incorrect insertion of FragmentInterface parameters into WHERE IN queries

Open iGrog opened this issue 1 year ago • 4 comments

No duplicates 🥲.

  • [X] I have searched for a similar issue in our bug tracker and didn't find any solutions.

Database

MySQL

What happened?

Continue of #145

$products = $this->select()->andWhere('productGuid', 'IN', $productGuids)->fetchData();

with empty array $productGuids resulting the following sql:

AND `xxx`.`ProductGuid` IN() 

and database error is raised, as there is nothing in IN

Version

database 2.8.1
PHP 8.3

iGrog avatar Mar 09 '24 14:03 iGrog

Hi. What do you expect from ORM in case of passing an empty list?

roxblnfk avatar Mar 10 '24 19:03 roxblnfk

Hi, maybe not to generate AND xxx.ProductGuid IN() at all?

iGrog avatar Mar 11 '24 14:03 iGrog

Hi, maybe not to generate AND xxx.ProductGuid IN() at all?

or generate FALSE instead? because the IN operator is used to define a white list. And if the list is empty it equals to FALSE

roxblnfk avatar Mar 11 '24 14:03 roxblnfk

Yet another option -- generate xxx.ProductGuid is null. Wny not? The values list has no values. Shouldn't we check that field has no value too? :)

roxblnfk avatar Mar 11 '24 14:03 roxblnfk