Hello ! After seem the question about "how to sync sqlite3 databases" and proposed the creation/extension of sqlite3_trace function to make it easy to log changes to the database I implemented what I'll call sqlite3_trace_v2 that has an extra parameter to indicate if we only want to log sql statements that modify the database:
void *sqlite3_trace_v2(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg, int onlyMod); If the "onlyMod" parameter is not zero than only sql statements that do not return true to "sqlite3_stmt_readonly" call will be traced. This is a link to a gist on github https://gist.github.com/mingodad/f32b680c901e360803bb The license for this contribution is the same of sqlite. Cheers ! ==================== diff -urB sqlite-src-3081101/src/loadext.c sqlite-src-3081101-2/src/loadext.c --- sqlite-src-3081101/src/loadext.c??? 2015-07-29 21:06:55.000000000 +0100 +++ sqlite-src-3081101-2/src/loadext.c??? 2015-08-14 11:07:01.779944573 +0100 @@ -94,6 +94,7 @@ ?#ifdef SQLITE_OMIT_TRACE ?# define sqlite3_profile?????? 0 ?# define sqlite3_trace???????? 0 +# define sqlite3_trace_v2???????? 0 ?#endif ? ?#ifdef SQLITE_OMIT_GET_TABLE @@ -238,6 +239,7 @@ ?#endif ?? sqlite3_total_changes, ?? sqlite3_trace, +? sqlite3_trace_v2, ?#ifndef SQLITE_OMIT_DEPRECATED ?? sqlite3_transfer_bindings, ?#else diff -urB sqlite-src-3081101/src/main.c sqlite-src-3081101-2/src/main.c --- sqlite-src-3081101/src/main.c??? 2015-07-29 21:06:55.000000000 +0100 +++ sqlite-src-3081101-2/src/main.c??? 2015-08-14 11:07:36613070869 +0100 @@ -1748,7 +1748,7 @@ ?** trace is a pointer to a function that is invoked at the start of each ?** SQL statement. ?*/ -void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ +void *sqlite3_trace_v2(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg, int onlyMod){ ?? void *pOld; ? ?#ifdef SQLITE_ENABLE_API_ARMOR @@ -1758,12 +1758,17 @@ ?? } ?#endif ?? sqlite3_mutex_enter(db->mutex); +? if(onlyMod) db->flags |= SQLITE_SqlTraceModOnly; +? else db->flags &= ~SQLITE_SqlTraceModOnly; ?? pOld = db->pTraceArg; ?? db->xTrace = xTrace; ?? db->pTraceArg = pArg; ?? sqlite3_mutex_leave(db->mutex); ?? return pOld; ?} +void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ +? return sqlite3_trace_v2(db, xTrace, pArg, 0); +} ?/* ?** Register a profile function.? The pArg from the previously registered ?** profile function is returned.? diff -urB sqlite-src-3081101/src/sqlite3ext.h sqlite-src-3081101-2/src/sqlite3ext.h --- sqlite-src-3081101/src/sqlite3ext.h??? 2015-07-29 21:06:55.000000000 +0100 +++ sqlite-src-3081101-2/src/sqlite3ext.h??? 2015-08-14 11:08:19.798466419 +0100 @@ -143,6 +143,7 @@ ?? void? (*thread_cleanup)(void); ?? int? (*total_changes)(sqlite3*); ?? void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*); +? void * (*trace_v2)(sqlite3*,void(*xTrace)(void*,const char*),void*,int); ?? int? (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*); ?? void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*, ??????????????????????????????????????? ?? sqlite_int64),void*); @@ -394,6 +395,7 @@ ?#define sqlite3_thread_cleanup???????? sqlite3_api->thread_cleanup ?#define sqlite3_total_changes????????? sqlite3_api->total_changes ?#define sqlite3_trace????????????????? sqlite3_api->trace +#define sqlite3_trace_v2?????????????? sqlite3_api->trace_v2 ?#ifndef SQLITE_OMIT_DEPRECATED ?#define sqlite3_transfer_bindings????? sqlite3_api->transfer_bindings ?#endif diff -urB sqlite-src-3081101/src/sqlite.h.in sqlite-src-3081101-2/src/sqlite.h.in --- sqlite-src-3081101/src/sqlite.h.in??? 2015-07-29 21:06:55.000000000 +0100 +++ sqlite-src-3081101-2/src/sqlite.h.in??? 2015-08-14 11:05:14.484471489 +0100 @@ -2708,6 +2708,7 @@ ?** subject to change in future versions of SQLite. ?*/ ?void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); +void *sqlite3_trace_v2(sqlite3*, void(*xTrace)(void*,const char*), void*, int); ?SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, ??? void(*xProfile)(void*,const char*,sqlite3_uint64), void*); ? diff -urB sqlite-src-3081101/src/sqliteInt.h sqlite-src-3081101-2/src/sqliteInt.h --- sqlite-src-3081101/src/sqliteInt.h??? 2015-07-29 21:06:55.000000000 +0100 +++ sqlite-src-3081101-2/src/sqliteInt.h??? 2015-08-14 11:09:56.661611593 +0100 @@ -1287,6 +1287,7 @@ ?#define SQLITE_VdbeEQP??????? 0x04000000? /* Debug EXPLAIN QUERY PLAN */ ?#define SQLITE_Vacuum???????? 0x08000000? /* Currently in a VACUUM */ ?#define SQLITE_CellSizeCk???? 0x10000000? /* Check btree cell sizes on load */ +#define SQLITE_SqlTraceModOnly???? 0x80000000? /* Only output queries that modify the database */ ? ? ?/* ====================