Commit 96208ca5 by Konstantin Käfer

make .run() accept bind parameters

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