- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 652
Description
Description
When any SQL query includes a command containing the syntax for a parameter and is passed to the execute function, the library gives an SQL error. I would expect the SQL parser in the library to properly identify that it is inside an command expression and handle the situation gracefully.
Reproducing:
Run the following code:
import mysql from 'mysql2';
const pool = mysql.createPool(....);
const db = await pool.promise();
const sql = `
     SELECT
        -- The following code return the value of the :input parameter as a single row
        :input as input
     FROM
           DUAL
 `;
const params = {
    input: 1234,
};
const [resultSet] = await db.execute(sql, params);
Expected
I get a result set back which contains [ { input: 1234 } ]
Actual:
I receive the following error
Error: Incorrect arguments to mysqld_stmt_execute
at PromisePoolConnection.execute (<hidden>/node_modules/mysql2/promise.js:110:22) {
  code: 'ER_WRONG_ARGUMENTS',
  errno: 1210,
  sqlState: 'HY000',
  sqlMessage: 'Incorrect arguments to mysqld_stmt_execute'
}
Use case
In my use case, I get complex queries from third parties, which sometimes includes comments using --, or /* */ or //. The MySQL2 library just refuses to run the queries with comments containing parameter strings with the above error, needing me to use workarounds
Current workaround
For every SQL query that I get from my third party, I have to inspect every comment and add a space after : if text follows this symbol. Missing any means I get a production crash