Commit 180dde44 by Konstantin Käfer

add busyTimeout and set default busy timeout to 1 second

parent 26835aca
......@@ -157,6 +157,10 @@ int Database::EIO_Open(eio_req *req) {
sqlite3_close(db->handle);
db->handle = NULL;
}
else {
// Set default database handle values.
sqlite3_busy_timeout(db->handle, 1000);
}
return 0;
}
......@@ -324,6 +328,17 @@ Handle<Value> Database::Configure(const Arguments& args) {
Baton* baton = new Baton(db, handle);
db->Schedule(RegisterProfileCallback, baton);
}
else if (args[0]->Equals(String::NewSymbol("busyTimeout"))) {
if (!args[1]->IsInt32()) {
return ThrowException(Exception::TypeError(
String::New("Value must be an integer"))
);
}
Local<Function> handle;
Baton* baton = new Baton(db, handle);
baton->status = args[1]->Int32Value();
db->Schedule(SetBusyTimeout, baton);
}
else {
return ThrowException(Exception::Error(String::Concat(
args[0]->ToString(),
......@@ -336,6 +351,16 @@ Handle<Value> Database::Configure(const Arguments& args) {
return args.This();
}
void Database::SetBusyTimeout(Baton* baton) {
assert(baton->db->open);
assert(baton->db->handle);
// Abuse the status field for passing the timeout.
sqlite3_busy_timeout(baton->db->handle, baton->status);
delete baton;
}
void Database::RegisterTraceCallback(Baton* baton) {
assert(baton->db->open);
assert(baton->db->handle);
......
......@@ -149,6 +149,8 @@ protected:
static Handle<Value> Configure(const Arguments& args);
static void SetBusyTimeout(Baton* baton);
static void RegisterTraceCallback(Baton* baton);
static void TraceCallback(void* db, const char* sql);
static void TraceCallback(Database* db, std::string* sql);
......
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