You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using namedPlaceholders if we use array parameters it sterilize array without quotes.
My parameter is an array like role => ["Admin","Accounting"]
When I use it as a namedPlaceholder in an insert statement the resulting SQL is: 'role': Admin,Teklif
Which should be: 'role': 'Admin,Teklif'
So ends with an SQL error.
Quick fix is using toString and convert array to string.
The text was updated successfully, but these errors were encountered:
That's the expected behavior : array permits sending multiple values.
Example :
awaitconn.query('CREATE TABLE namedPlaceholders1(t varchar(128))');awaitconn.query("INSERT INTO `namedPlaceholders1` value ('a'), ('b'), ('c')");constres=awaitconn.query('select * from `namedPlaceholders1` where t IN (:possible)',{possible: ['a','c']});`
// res = [{ t: 'a' }, { t: 'c' }]
if your behavior is explicitly to have a string list, then, yes toString is the way to go.
I agree this is desired when the array placeholder is in a WHERE clause with the IN operator, however, when the array placeholder is an INSERT or UPDATE value for a JSON column, I expected the value to be [1,2,3] rather than 1,2,3
Would it be possible to check if the placeholder is in the WHERE clause or surrounded by parentheses and use [].toString() otherwise use JSON.stringify([])
When using namedPlaceholders if we use array parameters it sterilize array without quotes.
My parameter is an array like role => ["Admin","Accounting"]
When I use it as a namedPlaceholder in an insert statement the resulting SQL is: 'role': Admin,Teklif
Which should be: 'role': 'Admin,Teklif'
So ends with an SQL error.
Quick fix is using toString and convert array to string.
The text was updated successfully, but these errors were encountered: