我是节点的新手,我正在尝试我的覆盆子pi。 我安装了最新版本(http://nodejs.org/dist/v0.9.9/node-v0.9.9-linux-arm-pi.tar.gz)
和npm安装了sqlite3(制作和安装)
我现在正在尝试运行以下代码:
var http = require("http");
var sqlite3 = require("sqlite3").verbose();
var port = 1337;
var ip = "192.168.2.15";
http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"});
var db = new sqlite3.Database(":memory:");
db.serialize(function() {
db.run("CREATE TABLE lorem (info TEXT)");
console.log("CREATE");
var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
for (var i = 0; i < 10; i++) {
stmt.run("Ipsum " + i);
}
stmt.finalize();
console.log("START SELECT [");
db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
console.log(row.id + ": " + row.info);
});
console.log("] END SELECT");
});
console.log("CLOSE");
db.close();
res.end("Hello World.");
}).listen(port, ip);
console.log("Server running at http://" + ip + ":" + port);
我得到的输出是:
Server running at http://192.168.2.15:1337
CREATE
START SELECT [
] END SELECT
CLOSE
1: Ipsum 0
2: Ipsum 1
3: Ipsum 2
4: Ipsum 3
5: Ipsum 4
6: Ipsum 5
7: Ipsum 6
8: Ipsum 7
9: Ipsum 8
10: Ipsum 9
*** glibc detected *** node: free(): corrupted unsorted chunks: 0x0072fe28 ***
Aborted
我的假设是,即使我使用db.serialize
,我也有竞争条件,或者这不会在pi上工作(尽管sqlite3编译好了)
由于
答案 0 :(得分:0)
我最近遇到过这个问题。我意识到我没有使用node.js的稳定/推荐版本。降级为0.8.15