I need to log queries from a number of applications that use SQLite. Introducing logging to the applications would in this case not be a feasible solution in practice. So how can I enable query logging in SQLite itself?
+2
A:
Take a look at the sqlite Trace API. You have to implement the callback yourself.
void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
The callback function registered by
sqlite3_trace()
is invoked at various times when an SQL statement is being run bysqlite3_step()
. The callback returns a UTF-8 rendering of the SQL statement text as the statement first begins executing. Additional callbacks occur as each triggered subprogram is entered.
pierr
2009-10-22 14:00:57
Ok, so you are basically saying that I would need to write the code for logging. I wonder if someone has already done that, for a common use case like this?
Eemeli Kantola
2009-10-22 14:04:34
You have to write the COMMAND to invoke the **inbuilt** trace mechanism.
Raj More
2009-10-22 14:15:01
The sqlite3_trace api doesn't show you bindings. If your using a wrapper class, you may want to put in your own logging of the sql statements and the parameters.
i_like_caffeine
2009-10-22 14:53:08
Ok, after reading SQLite docs a bit more I think this answer is good enough for the original question, which was a bit poorly formed from my side. So marking this as accepted :)
Eemeli Kantola
2009-10-22 22:08:55