Commit a9cc58e0 by Orlando Vazquez

add a check to ensure we don't step after a prepare if there are placeholders/bindings

parent 11883bc0
...@@ -17,16 +17,13 @@ function readTest(db, callback) { ...@@ -17,16 +17,13 @@ function readTest(db, callback) {
if (callback) callback(db); if (callback) callback(db);
} }
else { else {
// puts("got a row" + inspect(arguments));
rows++; rows++;
} }
}); });
} }
function writeTest(db, callback) { function writeTest(db, i, callback) {
var t0 = new Date;
var count = i = 100000;
function innerFunction () {
db.query("INSERT INTO t1 VALUES (1)", function (row) { db.query("INSERT INTO t1 VALUES (1)", function (row) {
if (!i--) { if (!i--) {
// end of results // end of results
...@@ -36,19 +33,22 @@ function writeTest(db, callback) { ...@@ -36,19 +33,22 @@ function writeTest(db, callback) {
if (callback) callback(db); if (callback) callback(db);
} }
else { else {
innerFunction(); writeTest(db, i--, callback);
} }
}); });
}
innerFunction();
} }
var count = 100000;
var t0;
db.open(":memory:", function () { db.open(":memory:", function () {
puts(inspect(arguments)); puts(inspect(arguments));
puts("open cb"); puts("open cb");
db.query("CREATE TABLE t1 (alpha INTEGER)", function () { db.query("CREATE TABLE t1 (alpha INTEGER)", function () {
puts("create table callback" + inspect(arguments)); puts("create table callback" + inspect(arguments));
writeTest(db, readTest); // writeTest(db, readTest);
t0 = new Date;
writeTest(db, count, readTest);
}); });
}); });
...@@ -59,7 +59,6 @@ Database.prototype.query = function (sql, bindings, queryCallback) { ...@@ -59,7 +59,6 @@ Database.prototype.query = function (sql, bindings, queryCallback) {
function _setBindingsByIndex(db, function _setBindingsByIndex(db,
statement, bindings, nextCallback, rowCallback, bindIndex) { statement, bindings, nextCallback, rowCallback, bindIndex) {
puts("setting bindings");
if (!bindings.length) { if (!bindings.length) {
nextCallback(db, statement, rowCallback); nextCallback(db, statement, rowCallback);
return; return;
...@@ -69,7 +68,7 @@ function _setBindingsByIndex(db, ...@@ -69,7 +68,7 @@ function _setBindingsByIndex(db,
var value = bindings.shift(); var value = bindings.shift();
statement.bind(bindIndex, value, function () { statement.bind(bindIndex, value, function () {
_setBindingsByIndex(statement, bindings, nextCallback, rowCallback, bindIndex+1); _setBindingsByIndex(db, statement, bindings, nextCallback, rowCallback, bindIndex+1);
}); });
} }
......
...@@ -329,10 +329,8 @@ protected: ...@@ -329,10 +329,8 @@ protected:
Local<Value> argv[2]; Local<Value> argv[2];
int argc = 0; int argc = 0;
bool err = false;
if (req->result != SQLITE_OK) { if (req->result != SQLITE_OK) {
err = true;
argv[0] = Exception::Error(String::New("Error preparing statement")); argv[0] = Exception::Error(String::New("Error preparing statement"));
argc = 1; argc = 1;
} }
...@@ -383,15 +381,22 @@ protected: ...@@ -383,15 +381,22 @@ protected:
req->result = rc; req->result = rc;
req->int1 = -1; req->int1 = -1;
if (rc == SQLITE_OK) {
// This might be a INSERT statement. Let's try to get the first row. // This might be a INSERT statement. Let's try to get the first row.
// This is to optimize out further calls to the thread pool. // This is to optimize out further calls to the thread pool. This is only
// possible in the case where there are no variable placeholders/bindings
// in the SQL.
if (rc == SQLITE_OK && !sqlite3_bind_parameter_count(prep_req->stmt)) {
// if (rc == SQLITE_OK) {
rc = sqlite3_step(prep_req->stmt); rc = sqlite3_step(prep_req->stmt);
req->int1 = rc; req->int1 = rc;
if (rc == SQLITE_DONE) { if (rc == SQLITE_DONE) {
rc = sqlite3_finalize(prep_req->stmt); rc = sqlite3_finalize(prep_req->stmt);
prep_req->stmt = NULL;
assert(rc == SQLITE_OK); assert(rc == SQLITE_OK);
} }
else {
rc = sqlite3_reset(prep_req->stmt);
}
} }
return 0; return 0;
...@@ -850,7 +855,7 @@ protected: ...@@ -850,7 +855,7 @@ protected:
sqlite3_stmt *stmt = *sto; sqlite3_stmt *stmt = *sto;
int rc; int rc;
if (step_req->first_rc < 0) { if (step_req->first_rc != -1) {
rc = req->result = step_req->first_rc; rc = req->result = step_req->first_rc;
} else { } else {
rc = req->result = sqlite3_step(stmt); rc = req->result = sqlite3_step(stmt);
...@@ -903,7 +908,8 @@ protected: ...@@ -903,7 +908,8 @@ protected:
} }
} }
} }
else if (SQLITE_DONE) { else if (rc == SQLITE_DONE) {
// printf("no more results");
// no more results // no more results
} }
else { else {
......
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