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) {
if (callback) callback(db);
}
else {
// puts("got a row" + inspect(arguments));
rows++;
}
});
}
function writeTest(db, callback) {
var t0 = new Date;
var count = i = 100000;
function innerFunction () {
function writeTest(db, i, callback) {
db.query("INSERT INTO t1 VALUES (1)", function (row) {
if (!i--) {
// end of results
......@@ -36,19 +33,22 @@ function writeTest(db, callback) {
if (callback) callback(db);
}
else {
innerFunction();
writeTest(db, i--, callback);
}
});
}
innerFunction();
}
var count = 100000;
var t0;
db.open(":memory:", function () {
puts(inspect(arguments));
puts("open cb");
db.query("CREATE TABLE t1 (alpha INTEGER)", function () {
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) {
function _setBindingsByIndex(db,
statement, bindings, nextCallback, rowCallback, bindIndex) {
puts("setting bindings");
if (!bindings.length) {
nextCallback(db, statement, rowCallback);
return;
......@@ -69,7 +68,7 @@ function _setBindingsByIndex(db,
var value = bindings.shift();
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:
Local<Value> argv[2];
int argc = 0;
bool err = false;
if (req->result != SQLITE_OK) {
err = true;
argv[0] = Exception::Error(String::New("Error preparing statement"));
argc = 1;
}
......@@ -383,15 +381,22 @@ protected:
req->result = rc;
req->int1 = -1;
if (rc == SQLITE_OK) {
// 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);
req->int1 = rc;
if (rc == SQLITE_DONE) {
rc = sqlite3_finalize(prep_req->stmt);
prep_req->stmt = NULL;
assert(rc == SQLITE_OK);
}
else {
rc = sqlite3_reset(prep_req->stmt);
}
}
return 0;
......@@ -850,7 +855,7 @@ protected:
sqlite3_stmt *stmt = *sto;
int rc;
if (step_req->first_rc < 0) {
if (step_req->first_rc != -1) {
rc = req->result = step_req->first_rc;
} else {
rc = req->result = sqlite3_step(stmt);
......@@ -903,7 +908,8 @@ protected:
}
}
}
else if (SQLITE_DONE) {
else if (rc == SQLITE_DONE) {
// printf("no more results");
// no more results
}
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