【发布时间】:2022-01-11 16:40:07
【问题描述】:
在使用 Lambda 函数时,我尝试运行以下查询,但它会引发 ER_PARSE_ERROR 错误。
{
"errorType": "错误",
"errorMessage": "ER_PARSE_ERROR: 您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的 'SELECT DISTINCT Aj FROM ...' 附近使用的正确语法",
“跟踪”:[
const vandium = require('vandium');
var mysql = require('mysql');
var connection = mysql.createConnection({ multipleStatements: true });
exports.handler = vandium.generic()
.handler((event, context, callback) => {
var connection = mysql.createConnection({
host: 'xjxj',
user: 'xjxj',
password: 'xjxj',
database: 'xjxj'
});
var x = connection.escape(event.x);
var y= connection.escape(event.y);
var z = connection.escape(event.z);
connection.query("SET @"+y+"=2; SELECT DISTINCT A.j FROM A INNER JOIN B, C WHERE A.j = B.j and C.x= " + x + " and C.y="+y+" and C.z= " + z + "", function (error, results, fields) {
if (error) {
connection.destroy();
throw error;
}
else {
console.log(results);
callback(null, results);
}
});
});
我还想到了类似的东西:
... "SET @y=2;..." 但是否定的
我正在尝试在类似的线路上实现一些东西:
SET @y := @k :=79;SELECT DISTINCT A.j FROM A INNER JOIN B, C WHERE A.j = B.j and C.x= " + x + " and C.y="+y+" and C.z= " + z + "
当然,第一个代码块中没有 k,但这是粗略的想法。
出了什么问题?
【问题讨论】:
-
为什么 SQL 语法错误标记为
javascript? -
@Andreas,因为这段代码在 javascript 中
-
请添加完整的错误信息并显示连接字符串
-
@nbk 已编辑,请检查
-
更新您的问题并为您的查询添加完整的 sql 代码 ..(也是 where 之后的代码.....)
标签: javascript mysql node.js amazon-web-services node-mysql