Commit e79ff0c4 by Orlando Vazquez

wip

parent 7fbb4ee5
...@@ -22,6 +22,9 @@ var Database = exports.Database = function () { ...@@ -22,6 +22,9 @@ var Database = exports.Database = function () {
var self = this; var self = this;
this.queue = []; this.queue = [];
this.db = new sqlite.Database(); this.db = new sqlite.Database();
this.db.addListener("ready", function () {
self.dispatch();
});
}; };
Database.prototype.dispatch = function () { Database.prototype.dispatch = function () {
...@@ -62,28 +65,24 @@ Database.prototype.executeQuery = function(sql, bindings, queryCallback) { ...@@ -62,28 +65,24 @@ Database.prototype.executeQuery = function(sql, bindings, queryCallback) {
// Iterate over the list of bindings. Since we can't use something as // Iterate over the list of bindings. Since we can't use something as
// simple as a for or while loop, we'll just chain them via the event loop // simple as a for or while loop, we'll just chain them via the event loop
function doBindingsByIndex(statement, bindings, queryCallback) { function doBindingsByIndex(statement, bindings, callback) {
(function (statement, bindings, bindIndex) { var innerFunction = function (statement, bindings, bindIndex) {
var innerFunction = arguments.callee;
if (!bindings.length) { if (!bindings.length) {
process.nextTick(function () { callback(statement);
queryCallback(statement);
});
return; return;
} }
bindIndex = bindIndex || 1; bindIndex = bindIndex || 1;
var value = bindings.shift(); var value = bindings.shift();
process.nextTick(function () {
statement.bind(bindIndex, value, function () { statement.bind(bindIndex, value, function () {
innerFunction(statement, bindings, bindIndex+1); innerFunction(statement, bindings, bindIndex+1);
}); });
}); };
})(statement, bindings, 1); innerFunction(statement, bindings, 1);
} }
function queryDone(statement, rows) { function queryDone(statement) {
if (statement.tail) { if (statement.tail) {
statement.finalize(function () { statement.finalize(function () {
self.db.prepare(statement.tail, onPrepare); self.db.prepare(statement.tail, onPrepare);
...@@ -93,30 +92,26 @@ Database.prototype.executeQuery = function(sql, bindings, queryCallback) { ...@@ -93,30 +92,26 @@ Database.prototype.executeQuery = function(sql, bindings, queryCallback) {
statement.finalize(function () { statement.finalize(function () {
self.currentQuery = undefined; self.currentQuery = undefined;
queryCallback(undefined, rows);
// if there are any queries queued, let them know it's safe to go // if there are any queries queued, let them know it's safe to go
self.db.emit("ready"); self.db.emit("ready");
}); });
} }
function doStep(statement) { function doStep(statement) {
var rows = []; var innerFunction = function () {
(function () {
var innerFunction = arguments.callee;
statement.step(function (error, row) { statement.step(function (error, row) {
if (error) throw error; if (error) throw error;
if (!row) { if (!row) {
// rows.rowsAffected = this.changes(); // rows.rowsAffected = this.changes();
// rows.insertId = this.lastInsertRowid(); // rows.insertId = this.lastInsertRowid();
process.nextTick(function () { queryDone(statement);
queryDone(statement, rows);
});
return; return;
} }
rows.push(row); queryCallback(row);
process.nextTick(innerFunction); innerFunction();
}); });
})(); };
innerFunction();
} }
function onPrepare(error, statement) { function onPrepare(error, statement) {
......
...@@ -775,6 +775,12 @@ protected: ...@@ -775,6 +775,12 @@ protected:
free((int*)(step_req->column_data[i])); free((int*)(step_req->column_data[i]));
break; break;
case SQLITE_FLOAT:
row->Set(String::New(step_req->column_names[i]),
Number::New(*(double*) (step_req->column_data[i])));
free((double*)(step_req->column_data[i]));
break;
case SQLITE_TEXT: case SQLITE_TEXT:
row->Set(String::New(step_req->column_names[i]), row->Set(String::New(step_req->column_names[i]),
String::New((char *) (step_req->column_data[i]))); String::New((char *) (step_req->column_data[i])));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment