mysqljs / mysql

A pure node.js JavaScript Client implementing the MySQL protocol.
MIT License
18.28k stars 2.52k forks source link

Parameter 'values' is not executed correctly #2439

Closed dabaii closed 3 years ago

dabaii commented 3 years ago

// code 1 connection.query(SELECT * FROM shop_product WHERE productid in(1,2,3,4,5)` ,(error, results, fields)=> {...})
// results length is 5

//code 2 connection.query(SELECT * FROM shop_product WHERE productid in(?)`,["1,2,3,4,5"] ,(error, results, fields)=> {...})
// results length is 1

The results are different???

dougwilson commented 3 years ago

Hi @dabaii this is because in your first example, you have a list of numbers, but in your second, you have a single string. You can see the same results in the second if you used strings in the first like

SELECT * FROM shop_product WHERE productid in('1,2,3,4,5')

You want to use an array of numbers in your values, like the following:

connection.query('SELECT * FROM shop_product WHERE productid in(?)`,[[1,2,3,4,5]] ,(error, results, fields)=> {...})
dabaii commented 3 years ago

👍