@@ -413,6 +413,51 @@ void Database::ProfileCallback(Database *db, ProfileInfo* info) {
413413 delete info;
414414}
415415
416+ void Database::RegisterUpdateCallback (Baton* baton) {
417+ assert (baton->db ->open );
418+ assert (baton->db ->handle );
419+ Database* db = baton->db ;
420+
421+ if (db->update_event == NULL ) {
422+ // Add it.
423+ db->update_event = new AsyncUpdate (db, UpdateCallback);
424+ sqlite3_update_hook (db->handle , UpdateCallback, db);
425+ }
426+ else {
427+ // Remove it.
428+ sqlite3_update_hook (db->handle , NULL , NULL );
429+ delete db->update_event ;
430+ db->update_event = NULL ;
431+ }
432+
433+ delete baton;
434+ }
435+
436+ void Database::UpdateCallback (void * db, int type, const char * database,
437+ const char * table, sqlite3_int64 rowid) {
438+ // Note: This function is called in the thread pool.
439+ // Note: Some queries, such as "EXPLAIN" queries, are not sent through this.
440+ UpdateInfo* info = new UpdateInfo ();
441+ info->type = type;
442+ info->database = std::string (database);
443+ info->table = std::string (table);
444+ info->rowid = rowid;
445+ static_cast <Database*>(db)->update_event ->send (info);
446+ }
447+
448+ void Database::UpdateCallback (Database *db, UpdateInfo* info) {
449+ HandleScope scope;
450+
451+ Local<Value> argv[] = {
452+ String::NewSymbol (sqlite_authorizer_string (info->type )),
453+ String::New (info->database .c_str ()),
454+ String::New (info->table .c_str ()),
455+ Integer::New (info->rowid ),
456+ };
457+ EMIT_EVENT (db->handle_ , 4 , argv);
458+ delete info;
459+ }
460+
416461Handle<Value> Database::Exec (const Arguments& args) {
417462 HandleScope scope;
418463 Database* db = ObjectWrap::Unwrap<Database>(args.This ());
0 commit comments