打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
SQL query logging for SQLite

I need to log 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?

share|improve this question

Just to add a bit more info, if you're using SQLite in your application, you should probably use a different logging system for the app as a whole, rather than asking for built-in SQLite functions. – David Souther Dec 23 '10 at 21:07
feedback
up vote 7 down vote accepted

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.

share|improve this answer
Ok, so you are basically saying that I would need to write the code for logging. I wonder if someone has already done that, for a common use case like this? – Eemeli Kantola Oct 22 '09 at 14:04
You have to write the COMMAND to invoke the inbuilt trace mechanism. – Raj More Oct 22 '09 at 14:15
The sqlite3_trace api doesn't show you bindings. If your using a wrapper class, you may want to put in your own logging of the sql statements and the parameters. – eodonohoe Oct 22 '09 at 14:53
Ok, after reading SQLite docs a bit more I think this answer is good enough for the original question, which was a bit poorly formed from my side. So marking this as accepted :) – Eemeli Kantola Oct 22 '09 at 22:08
3 
Just wanted to drop in a small snippet for basic logging : void trace_callback( void* udp, const char* sql ) { printf("{SQL} [%s]\n", sql);} sqlite3_trace(g_dbConf, trace_callback, NULL); – Reflog Jul 13 '11 at
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
[系列] Go - 基于 GORM 获取当前请求所执行的 SQL 信息
如何用C语言操作sqlite3,一文搞懂
SQLite PRAGMA | w3cschool菜鸟教程
sqlite 事务代码
嵌入式数据库SQLite3相关操作
sqlite3——sqlite3应用相关函数
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服