@@ -157,6 +157,10 @@ int Database::EIO_Open(eio_req *req) {
157157 sqlite3_close (db->handle );
158158 db->handle = NULL ;
159159 }
160+ else {
161+ // Set default database handle values.
162+ sqlite3_busy_timeout (db->handle , 1000 );
163+ }
160164
161165 return 0 ;
162166}
@@ -324,6 +328,17 @@ Handle<Value> Database::Configure(const Arguments& args) {
324328 Baton* baton = new Baton (db, handle);
325329 db->Schedule (RegisterProfileCallback, baton);
326330 }
331+ else if (args[0 ]->Equals (String::NewSymbol (" busyTimeout" ))) {
332+ if (!args[1 ]->IsInt32 ()) {
333+ return ThrowException (Exception::TypeError (
334+ String::New (" Value must be an integer" ))
335+ );
336+ }
337+ Local<Function> handle;
338+ Baton* baton = new Baton (db, handle);
339+ baton->status = args[1 ]->Int32Value ();
340+ db->Schedule (SetBusyTimeout, baton);
341+ }
327342 else {
328343 return ThrowException (Exception::Error (String::Concat (
329344 args[0 ]->ToString (),
@@ -336,6 +351,16 @@ Handle<Value> Database::Configure(const Arguments& args) {
336351 return args.This ();
337352}
338353
354+ void Database::SetBusyTimeout (Baton* baton) {
355+ assert (baton->db ->open );
356+ assert (baton->db ->handle );
357+
358+ // Abuse the status field for passing the timeout.
359+ sqlite3_busy_timeout (baton->db ->handle , baton->status );
360+
361+ delete baton;
362+ }
363+
339364void Database::RegisterTraceCallback (Baton* baton) {
340365 assert (baton->db ->open );
341366 assert (baton->db ->handle );
0 commit comments