Commit 96208ca5 by Konstantin Käfer

make .run() accept bind parameters

parent e4ca9eeb
...@@ -391,9 +391,7 @@ Handle<Value> Statement::Run(const Arguments& args) { ...@@ -391,9 +391,7 @@ Handle<Value> Statement::Run(const Arguments& args) {
HandleScope scope; HandleScope scope;
Statement* stmt = ObjectWrap::Unwrap<Statement>(args.This()); Statement* stmt = ObjectWrap::Unwrap<Statement>(args.This());
OPTIONAL_ARGUMENT_FUNCTION(0, callback); Baton* baton = stmt->Bind<Baton>(args);
Baton* baton = new Baton(stmt, callback);
stmt->Schedule(EIO_BeginRun, baton); stmt->Schedule(EIO_BeginRun, baton);
return args.This(); return args.This();
...@@ -410,16 +408,21 @@ void Statement::EIO_BeginRun(Baton* baton) { ...@@ -410,16 +408,21 @@ void Statement::EIO_BeginRun(Baton* baton) {
int Statement::EIO_Run(eio_req *req) { int Statement::EIO_Run(eio_req *req) {
STATEMENT_INIT(Baton); STATEMENT_INIT(Baton);
sqlite3_reset(stmt->handle);
sqlite3_mutex* mtx = sqlite3_db_mutex(stmt->db->handle); sqlite3_mutex* mtx = sqlite3_db_mutex(stmt->db->handle);
sqlite3_mutex_enter(mtx); sqlite3_mutex_enter(mtx);
// Make sure that we also reset when there are no parameters.
if (!baton->parameters.size()) {
sqlite3_reset(stmt->handle);
}
if (stmt->Bind(baton->parameters)) {
stmt->status = sqlite3_step(stmt->handle); stmt->status = sqlite3_step(stmt->handle);
if (!(stmt->status == SQLITE_ROW || stmt->status == SQLITE_DONE)) { if (!(stmt->status == SQLITE_ROW || stmt->status == SQLITE_DONE)) {
stmt->message = std::string(sqlite3_errmsg(stmt->db->handle)); stmt->message = std::string(sqlite3_errmsg(stmt->db->handle));
} }
}
sqlite3_mutex_leave(mtx); sqlite3_mutex_leave(mtx);
......
...@@ -53,12 +53,13 @@ exports['test inserting and retrieving rows'] = function(beforeExit) { ...@@ -53,12 +53,13 @@ exports['test inserting and retrieving rows'] = function(beforeExit) {
var group = this.group(); var group = this.group();
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
db.prepare("INSERT INTO foo VALUES(?, ?, ?, ?)") db.prepare("INSERT INTO foo VALUES(?, ?, ?, ?)")
.bind( .run(
'String ' + i, 'String ' + i,
i, i,
i * Math.PI i * Math.PI,
// null (SQLite sets this implicitly) // null (SQLite sets this implicitly)
).run(group()); group()
);
} }
}, },
function(err, rows) { function(err, rows) {
......
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