Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepared statements format error when filed is JSON type #3481

Open
serveryang opened this issue Mar 13, 2025 · 0 comments
Open

prepared statements format error when filed is JSON type #3481

serveryang opened this issue Mar 13, 2025 · 0 comments

Comments

@serveryang
Copy link

serveryang commented Mar 13, 2025

let query='select  *  from ??  where (??=?) limit ?,? '
let params = ['certification', "cert->>'$.name'", 'myname', 0, 20];
let pool = mysql.createPool(poolOption);
let sql = pool.format(query, params);
//  the sql is not correct.
// correct query sql should be: select * from certification where cert->>'$.name' = ‘myname’ limit 0, 20

pool.format method will finally call escapeId(val, forbidQualified) in SqlString.
the sqlstring module not update now.
file: node_modules\sqlstring\lib\SqlString.js#18, code below:

SqlString.escapeId = function escapeId(val, forbidQualified) {
  if (Array.isArray(val)) {
    var sql = '';

    for (var i = 0; i < val.length; i++) {
      sql += (i === 0 ? '' : ', ') + SqlString.escapeId(val[i], forbidQualified);
    }

    return sql;
  } else if (forbidQualified) {
    return '`' + String(val).replace(ID_GLOBAL_REGEXP, '``') + '`';
  } else {
    return '`' + String(val).replace(ID_GLOBAL_REGEXP, '``').replace(QUAL_GLOBAL_REGEXP, '`.`') + '`';
  }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants