Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Query Logging in SQLite 3

Tags:

logging

sqlite

Is there any built-in function to enable query log in SQLite.

I am familiar with Trace API, but I want to know if there is any predefined function for it.

like image 809
AnonGeek Avatar asked Jun 06 '12 07:06

AnonGeek


People also ask

Does SQLite have a log?

The SQLite library logs most error conditions, to assist with debugging. Custom extensions (including custom SQL functions, collations, and virtual tables) may also log messages.

Does SQLite support SQL queries?

SQL As Understood By SQLite. SQLite understands most of the standard SQL language. But it does omit some features while at the same time adding a few features of its own.

What is the use of SQLite 3?

SQLite is used to develop embedded software for devices like televisions, cell phones, cameras, etc. It can manage low to medium-traffic HTTP requests. SQLite can change files into smaller size archives with lesser metadata. SQLite is used as a temporary dataset to get processed with some data within an application.


1 Answers

There is no easy way to do this like with MySQL, but there are some options:

One:

Some wrapper-libraries have something like this built-in. But to find a wrapper library you would probably first need to identify the target language. Perl DBI? Python? C++?

Two:

I would not (in any way) recommend the following for a "production-grade" solution, but if you are mainly experimenting and/or debugging, then you might try examining the rollback journal just prior to the end of each transaction. See here about the rollback journal: http://www.sqlite.org/tempfiles.html How you would detect 'the end of each transaction' would be up to your code and/or the breakpoints in your debugger.

I must emphasize again: what I just mentioned above would be a total hack-around, and I feel dirty even having mentioned it.

Three:

You could ask on the (very active and gracious) sqlite mailing list, but they would probably just reemphasize sqlite3_trace.

... other random thing:

On a somewhat (barely?) related note, when you start a './sqlite3' command prompt session, you can type:

.explain 

which enables interesting and instructive verbose output for each query executed at the prompt.

More Info I Just Found:

One of the flags that can be passed to 'sqlite3_config()' is SQLITE_CONFIG_LOG. This is another way (in addition to the trace API) to set a callback and receive status information from the sqlite library periodically. I think it is mainly for error log messages.

like image 187
pestophagous Avatar answered Oct 21 '22 14:10

pestophagous