mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
GNU Lesser General Public License v2.1
363 stars 93 forks source link

namedPlaceholders and array #248

Open sbscan opened 1 year ago

sbscan commented 1 year ago

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.

rusher commented 1 year ago

That's the expected behavior : array permits sending multiple values. Example :

    await conn.query('CREATE TABLE namedPlaceholders1(t varchar(128))');
    await conn.query("INSERT INTO `namedPlaceholders1` value ('a'), ('b'), ('c')");
    const res = await conn.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.