用于SQLite的SQL查询日志记录? [英] SQL query logging for SQLite?
问题描述
我需要从许多使用SQLite的应用程序中记录查询,不仅要插入/更新/删除查询,还要记录选择查询和其他查询.在实际情况下,在应用程序中引入日志记录将不是可行的解决方案.那么如何在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?
推荐答案
看看sqlite 跟踪 API.您必须自己实现回调.
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*);
当
sqlite3_step()
运行SQL语句时,在不同时间调用sqlite3_trace()
注册的回调函数.在该语句首次开始执行时,该回调返回SQL语句文本的UTF-8呈现.输入每个触发的子程序时,还会发生其他回调.
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.
这篇关于用于SQLite的SQL查询日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!