mysql - 最大长度的sql语句
问题描述
我有一个节点 js 应用程序,我通过 express 连接到 mysql 数据库。
现在我正在尝试锁定一个表,调用一个函数并解锁这些表。
当我打印字符串时一切正常,但是当我在 connection.query(sqlStatement) 中调用它时,字符串会以某种方式被切片?
这是节点js函数:
exports.participateTournament = function(req, res){
const {pid, tid} = req.body;
let sqlStatement = `lock Tables Tournament_Participant WRITE, Tournament_Approved READ;
select participate_Tournament('${pid}', '${tid}') as 'result';
unlock tables;`;
console.log(sqlStatement);
connection.query(sqlStatement, function(error, rows){
if(error){
console.log(error.message);
return res.status(400).send();
} else {
return res.status(200).send(rows[0].result);
}
})
};
当我打印出字符串时,这是输出
lock Tables Tournament_Participant WRITE, Tournament_Approved READ;
select participate_Tournament('0780b926a41bd17877894771841e6179', 'a9f0e61a137d86aa9db53465e0801612') as 'result';
unlock tables;
但我从 mysql 收到此错误消息:
ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select participate_Tournament('0780
b926a41bd17877894771841e6179', 'a9f0e61a137d8' at line 2
这是participant_Tournament 函数:我需要检查是否达到了锦标赛参与者的最大限制
create function participate_Tournament(
pidP varchar(64),
tidP varchar(64)
)
returns smallint
BEGIN
declare par_amount int;
declare max_amount int;
select count(TID) into par_amount from Tournament_Participant where TID = tidP;
select max_participants into max_amount from Tournament_Approved where TID = tidP;
if(par_amount < max_amount) then
insert into Tournament_Participant(TID,PID) values(tidP, pidP);
return 1; #true
end if;
return 0;
end;
```
Thanks in Advance.
解决方案
我现在已经这样解决了,对我有用
const {pid, tid} = req.body;
let tmpResult;
connection.beginTransaction(function(err){
if(err){
res.status(400).send();
return;
}
sqlStatement = `lock Tables Tournament_Participant WRITE, Tournament_Approved READ;`;
connection.query(sqlStatement, function(err, rows){
if(err){
console.log(err);
res.status(400).send();
}else{
sqlStatement = `select participate_Tournament('${pid}', '${tid}') as 'result';`;
connection.query(sqlStatement, function(err, rows){
if(err){
console.log(err);
res.status(400).send();
}else{
tmpResult = rows[0].result;
sqlStatement = `unlock tables;`;
connection.query(sqlStatement, function(err, rows){
if(err){
console.log(err);
res.status(400).send();
}else{
connection.commit(function(err){
if(err){
connection.rollback(function(){
res.status(400).send();
});
}else{
res.status(200).send(tmpResult.toString());
}
})
}
})
}
})
}
})
})
};
推荐阅读
- git - Eclipse 预构建步骤不会执行 git 命令
- airflow - Airflow 如何确定任务是失败还是成功,并安排重试?
- prettier - 制造商“更漂亮”的多行包装json?
- sharepoint - SharePoint 计算字段 If 语句添加前导零
- node.js - 关于 G Suite 电子邮件最大发送限制的问题
- javascript - 为什么 React Re 渲染没有更新 JSX 的返回值?
- cookies - MirageJs:读取请求对象内的 cookie
- java - 如何在 Wiremock 中使用相同的标头响应?
- python - pythons“socket”库中的“recvfrom”在 UDP 实现中找不到通过以太网电缆成功发送的消息
- sharepoint-online - 将 Sharepoint 列表连接到 Sharepoint 网页