rogerbinns / apsw

Another Python SQLite wrapper
https://rogerbinns.github.io/apsw/
Other
740 stars 97 forks source link

Allow multiple tracing/profile callbacks #502

Closed rogerbinns closed 1 month ago

rogerbinns commented 12 months ago

Currently there can only be one profiler, one authorizer, one collation needed callback etc.

This is especially problematic with the profiler because apswtrace needs it, but if any other code installs a tracer then apswtrace sees nothing.

The simplest approach would be to add a name parameter when they are registered/unregistered. The default is None. Internally APSW would keep a list for the callback and invoke the appropriate ones.

As an example the sqlite3_tracev2 would be a array of:

PyObject *name;
unsigned mask;
PyObject *callback;

Then when a trace event fires the list is traversed and any whose mask matches the event is called.

Some additional things:

rogerbinns commented 1 month ago

Implemented for sqlite3_trace_v2 calls where I already had to handle thesqlite3_profile deprecation co-existence.

It doesn't make sense for auth - what if one callback says yes and one says no and one says ignore?

The progress callback might be useful, but I'll wait till someone asks.