nette / database

💾 A database layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.
https://doc.nette.org/database
Other
513 stars 108 forks source link

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

Closed KacerCZ closed 3 years ago

KacerCZ commented 3 years ago

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 3 years ago

fixed

KacerCZ commented 3 years ago

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