Cloud9上的Sqlite3 / Node语法错误

时间:2016-09-15 01:46:42

标签: node.js sqlite cloud9

我在节点项目中运行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)

提前致谢!

1 个答案:

答案 0 :(得分:1)

Primary是sqlite中的保留关键字/列名。整天在键盘上敲打我的头,在我发布后两分钟解决了。谢谢你是一只橡皮鸭,StackOverflow!