打开APP
userphoto
未登录

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

开通VIP
keeping a log table in sqlite database?

I'm looking for a way to set up (via SQL) a log table containing everything that had been done to my sqlite database (preferably in terms of the insert, create table etc. statements as issued to the database). I'm sure there are way to do it via setting trigger on each table, but that is just WAY too much work and does not bode well if I change the database's schema later. Is there a catch-all global thing that work on the database (like trigger on database itself)?

I'm also open for other suggestions for keeping records of changes done to sqlite database so that I can look back months later on the changes.

(Programatically of course there are ways but I can't be sure that my program is the only program writing to the database).

share|improve this question

79% accept rate
If there was a trigger on the database, wouldn't it fire itself? – recursive Jan 8 '09 at 2:28
feedback

2 Answers

Though the following doesn't meet all your requirements, you may wish to see one way to do it. Mike Chirico's SQLite Tutorial has a section on Logging All Inserts, Updates, and Deletes that mimics the functionality of MySQL's binlog.

It relies on triggers that must match the schema for each table whose changes you wish to track. That is, if your table has a field called "a", then the logging table needs to keep track of "aOLD" and "aNEW". In this way, the trigger is able to record updates, inserts, and deletes made to the fields in that particular table.

share|improve this answer
I've never used SQL Lite but you shoule be able to retrive the schema and then you could make a script that updates your triggers and history tables. – Richard L Jan 30 '09 at 9:08
Thank you, that's exacly what I needed! – GvS May 20 at 21:29
feedback

these function may be useful

void *sqlite3_update_hook(  sqlite3*,   void(*)(void *,int ,char const *,char const *,sqlite3_int64),  void*);void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);void *sqlite3_profile(   sqlite3*,   void(*xProfile)(void*,const char*,sqlite3_uint64), void*);

they seem to act on individual dbs

the only global way I can see is to use

sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);int sqlite3_vfs_unregister(sqlite3_vfs*);
share|improve this answer
The functions seem to work only when someone who writes to the database using their api explicitly hook up, but I'm looking for ways that also leaves a record when anyone (potentially not my program) writes to the database. – polyglot Jan 8 '09 at 21:04
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
SQLite剖析(3):C/C++接口介绍
vfs 3
linux的VFS详解
Ubuntu下安装SQLite3 (转)
ios简单sqlite使用
sqlite运用总结
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服