Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query logging for SQLite?

I need to log queries, not only inserts/updates/deletes but also selects and other 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?

like image 749
Eemeli Kantola Avatar asked Oct 22 '09 13:10

Eemeli Kantola


People also ask

Does SQLite have a transaction log?

SQLite is a transactional database that all changes and queries are atomic, consistent, isolated, and durable (ACID). SQLite guarantees all the transactions are ACID compliant even if the transaction is interrupted by a program crash, operation system dump, or power failure to the computer.

Is there a GUI for SQLite?

The SQLiteStudio tool is a free GUI tool for managing SQLite databases. It is free, portable, intuitive, and cross-platform. SQLite tool also provides some of the most important features to work with SQLite databases such as importing, exporting data in various formats including CSV, XML, and JSON.


1 Answers

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 by sqlite3_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.

like image 95
pierrotlefou Avatar answered Oct 13 '22 15:10

pierrotlefou