-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexey Pechnikov wrote:
> I want to build a universal extension for logging all user queries. I can 
> write
> this with trace function but it's difficult or impossible to split system and
> user queries.

There are two ways that can be done.  The first is to require your extension
and its API be used at which you can then filter and log as needed.

The way I would go about it is not using a SQLite extension, but instead
provide a shared library with logging functions.  You can ensure the shared
library is loaded before SQLite (use LD_PRELOAD on Linux/Unix and something
similar on Windows) and hook the SQLite APIs.  This requires no change to
the application.

For apswtrace I can output all SQL and bindings, rows returned, how long
each query took, most popular queries, queries that took the longest
(individually and ones that have the same text) etc.  This doesn't require
any code changes in the Python application.

This unobtrusive mechanism also allows you to get more detailed.  For
example you can track how often SQLite is busy (install a busy handler,
transparently call the user one if needed).  You can even use it to fake
things.  For example historically this mechanism has been used to fake the
current time, but you could fake busy results to help with testing.  If you
also intercept read and write system calls you can even correspond I/O
activity to the queries that cause it.  You can even capture stack
backtraces when tying them to SQL calls.  There are so many possibilities.

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAksgSSIACgkQmOOfHg372QRXzgCfUfQ/9uG0KBMIC5876ATFkgDC
y08An0GalZmCSVg23pNBTSSrGKSilPm3
=zPiv
-----END PGP SIGNATURE-----
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to