Node-MySQL 无法插入 TIME

Node-MySQL unable to insert TIME

我正在尝试在 Express.JS 中构建一个 API,后台有一个 MySQL-Server 运行。其中一个 table 包含类型为 TIME 的列。但是,当尝试插入 table 时,我得到 {code: 'ER_PARSE_ERROR', errno: 1064, sqlState: '42000'}

使用单个 ?,消息是:

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 \'\'23:00:41\'\' at line 1

使用双 ??,消息是:

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 \'`23:00:41`\' at line 1

实际的代码行是这样的:

let query = "INSERT INTO Zeiterfassung (Break_Start) VALUES ? ";
let data = Break_Start; //Break_Start is a string like "23:40:39"
dbConn.query(query, data, (err, rows) => {...});

MySQL-版本:8.0.22-0ubuntu0.20.04.2

节点版本:v10.19.0

如果你有一个字符串参数,那么你需要用括号把?括起来:

let query = "INSERT INTO Zeiterfassung (Break_Start) VALUES (?)";
dbConn.query(query, [ Break_Start ], function(err, rows) => {...});

带有单个 ? 且不带括号的语法旨在传递对象。