nette/database

BC break in 3.1 handling "IN (?)" in query

KacerCZ opened this issue · 2 comments

Version: 3.1.1

Bug Description

I tried to upgrade from 3.0.7 to 3.1.1 and found incompatibility in handling "IN (?)".
For simplicity in code I don't examine if array has single value or more values and I always insert placeholders with count matching values in array and then pass arguments to query.

Usually generated query looks like select name from table where id in (?,?,?) and parameters are [ 1, 2, 3 ].
If parameters contain single value then this bug appears, becasue query is select name from table where id in (?) and parameters are [ 1 ].

Steps To Reproduce

Use following code:

$database = new \Nette\Database\Connection(...);
$database->queryArgs( 'select name from table where id in (?)', [ 1 ] );

Exception with message "Placeholder ?list expects array or Traversable object, integer given" is thrown.
This snippet passed in older versions.

Expected Behavior

Query will pass as it did in 3.0.7 and older versions.

Possible Solution

Correctly handle case with single scalar value in parameters.

dg commented

fixed

I tested the fix and it works.
Thank you for prompt response.