首页 > 解决方案 > 使用 NodeJS 在 mySQL 表中插入多个值时出现 ER_PARSE_ERROR

问题描述

我正在使用 NodeJS 将我的数据插入到表中。我不断收到这个奇怪的错误。

代码如下所示:

fs.watch('./Assetto1/results/', (eventType, filename) => {
 console.log("EventType:"+eventType);
 if (eventType == "rename") {
    //Gets most recent .json file loads it using require
    console.log("Debug: Rename");
    console.log("./Assetto1/results/"+filename);
    Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1000);
    result = require("./Assetto1/results/"+filename);
    console.log(result.TrackName);

    //extracts the data out of the file and puts it in mySQL table
    connection.query('INSERT INTO results(1GUID, 1NAME, 1NATION, 1CARMODEL, 
        1CARSKIN, 1BESTTIME, 1TOTALTIME) VALUES (' + 
        race.getResultDriverGuid(result, 0) 
        + ',' + race.getResultDriverName(result, 0) + ',' + 
        race.getResultDriverNation(result, 0) + ',' + 
        race.getResultDriverCarModel(result, 0) + ',' + 
        race.getResultDriverCarSkin(result, 0) + ',' + 
        race.getResultDriverBestLap(result, 0) + ',' + 
        race.getResultDriverTotalTime(result, 0) + ');');

 }
})

错误看起来像这样:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual th                                                                                                                                                             at corresponds to your MySQL server version for the right syntax to use near '!,                                                                                                                                                             -,mercedes_sls_gt3,Black_Falcon_Dubai_24H_2,159303,688052)' at line 1
at Query.Sequence._packetToError (/home/node_modules/mysql/lib/protocol/sequ                                                                                                                                                             ences/Sequence.js:47:14)
at Query.ErrorPacket (/home/node_modules/mysql/lib/protocol/sequences/Query.                                                                                                                                                             js:77:18)
at Protocol._parsePacket (/home/node_modules/mysql/lib/protocol/Protocol.js:                                                                                                                                                             278:23)
at Parser.write (/home/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/home/node_modules/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/home/node_modules/mysql/lib/Connection.js:502:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
--------------------
at Protocol._enqueue (/home/node_modules/mysql/lib/protocol/Protocol.js:144:                                                                                                                                                             48)
at Connection.query (/home/node_modules/mysql/lib/Connection.js:200:25)
at FSWatcher.fs.watch (/home/main.js:49:14)
at FSWatcher.emit (events.js:182:13)
at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:130:12)
Emitted 'error' event at:
at Connection._handleProtocolError (/home/node_modules/mysql/lib/Connection.                                                                                                                                                             
js:425:8)
at Protocol.emit (events.js:182:13)
at Protocol._delegateError (/home/node_modules/mysql/lib/protocol/Protocol.j                                                                                                                                                             
s:390:10)
at Query.<anonymous> (/home/node_modules/mysql/lib/protocol/Protocol.js:153:                                                                                                                                                             
12)
at Query.emit (events.js:182:13)
at Query.Sequence.end (/home/node_modules/mysql/lib/protocol/sequences/Seque                                                                                                                                                             
nce.js:78:12)
at Query.ErrorPacket (/home/node_modules/mysql/lib/protocol/sequences/Query.                                                                                                                                                             
js:90:8)
at Protocol._parsePacket (/home/node_modules/mysql/lib/protocol/Protocol.js:                                                                                                                                                             
278:23)
at Parser.write (/home/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/node_modules/mysql/lib/protocol/Protocol.js:38:16)

看起来它从 json 中获取了正确的信息——显然,这不是问题所在。但它不会将它插入我的表中。我真的不明白怎么了。希望你们能帮助我。

标签: mysqlnode.jsparsinginsert

解决方案


推荐阅读