我在节点项目中运行 sqlite3 时遇到语法错误。如果重要的话,我会在 Cloud9 工作站上运行它。我想我的代码很简单。
var fs = require('fs');
var fileGens = 'generators.db';
var existsGens = fs.existsSync(fileGens);
if(!existsGens) {
console.log("Creating DB file 'generators'...");
fs.openSync(fileGens, 'w');
}
var sqlite3 = require('sqlite3').verbose();
var dbGens = new sqlite3.Database(fileGens);
dbGens.serialize(function() {
if(!existsGens) {
console.log('Creating db...');
}
dbGens.run("CREATE TABLE TerrainFrequencies (Primary TEXT, Secondary TEXT, Tertiary TEXT, WildCards TEXT)");
dbGens.run("INSERT INTO TerrainFrequencies VALUES (?, ?, ?, ?)", 'Water', 'Hills', 'Forest', 'Mountains,Desert');
console.log('About to select *');
dbGens.all("SELECT * FROM TerrainFrequencies", function(err, row) {
console.log('Selected...');
console.log(row);
});
});
dbGens.close();
我使用node index.js运行它,我的错误......
Creating DB file 'generators'...
Creating db...
About to select *
events.js:141
throw er; // Unhandled 'error' event
^
Error: SQLITE_ERROR: near "Primary": syntax error
at Error (native)
提前致谢!