Loopback 3 pure SQL query with params not working with question marks (with Solution)
Loopback 3 pure SQL query with params not working with question marks (with Solution)
我的查询是这样的:
let query = `SELECT id, name FROM students WHERE school_code = "${schoolCode}" AND name REGEXP "${text}" `;
并带有参数:
let params = [ schoolCode, text ];
let query = `SELECT id, name FROM students WHERE school_code = "?" AND name REGEXP "?" `
Model.dataSource.connector.query(query, params, (err, res) => {} );
而且不行
(下面的解决方案)
我以为可能是 REGEXP 但
解决方案是:
删除问号两边的引号。
例如,这有效:
let params = [ schoolCode, text ];
let query = `SELECT id, name FROM students WHERE school_code = ? AND name REGEXP ? `
Model.dataSource.connector.query(query, params, (err, res) => {} );
我的查询是这样的:
let query = `SELECT id, name FROM students WHERE school_code = "${schoolCode}" AND name REGEXP "${text}" `;
并带有参数:
let params = [ schoolCode, text ];
let query = `SELECT id, name FROM students WHERE school_code = "?" AND name REGEXP "?" `
Model.dataSource.connector.query(query, params, (err, res) => {} );
而且不行
(下面的解决方案)
我以为可能是 REGEXP 但
解决方案是:
删除问号两边的引号。
例如,这有效:
let params = [ schoolCode, text ];
let query = `SELECT id, name FROM students WHERE school_code = ? AND name REGEXP ? `
Model.dataSource.connector.query(query, params, (err, res) => {} );