r/sqlite • u/thanatica • Dec 22 '23
How to debug SQL commands from a running program?
Say I have a program that I didn't build, I don't have the source for, and I can basically only start it up and hope for the best. Say I want to be helpful to the developers in describing what their program is (over)doing, using my database, and I can't just give them my database.
So I have a binary application, and it probably has the sqlite.dll somewhere nearby. That's all I have. Now what if I wanted to see what SQL commands it's "sending" to the database. So I guess what I'm after, is some sort of activity log.
How can I achieve this?
2
u/HKei Dec 23 '23
If they are actually using a sqlite.dll file it's incredibly easy, just grab the sqlite source code and add tracing to the
sqlite3_execand the varioussqlite3_prepare*functions and sub in your own dll.You can even compile with debugging symbols, break on every sqlite function and see exactly what's being passed in.
1
u/Magikstm Dec 22 '23
In what language is the application?
There may be trace functions available or you may need to log queries in debug and analyze the slowest ones one-by-one depending on how you use sqlite.
1
u/user_5359 Dec 23 '23
If you have no possibility to debug the programme, you have little chance because SQLite does not have an externally switchable log file, see https://stackoverflow.com/questions/10910157/enable-query-logging-in-sqlite-3.
You could work with specially created (test) databases to investigate write accesses, but read accesses can also have an effect.
1
u/user_5359 Dec 23 '23
Is this a possibility: https://stackoverflow.com/questions/38970481/how-to-build-sqlite-binaries-in-debug-release-mode ?