SQLite is a great project but even with the nicest library you can make mistakes. I created a single-header inspection wrapper, to quickly and easily detect the most common issues in code using SQLite.
And since I know from experience that it would be a pain to instrumentize your code to do this, I decided to make this work with just a single #include.
So all you have to do is download and extract sqlite_inspect_amalgamation.h and store it in the same folder where sqlite3.h lives.
Then open sqlite3.h and append the following line:
There. All done. Just compile and run.
What SQLite-Inspect checks for
This is the list of currently supported checks.
Missing finalize calls for statements
The check will not only tell you that a statement wasn’t closed but also which statements they were.
Invalid/double finalize calls
In case sqlite3_finalize is called a second time on a statement or with some garbage pointer, SQLite-Inspect will tell you that.
Failure to close DB
Usually the reason for this is at least one unclosed statement. SQLite-Inspect will tell you that the database could not be closed along with the given error code and in case of open statements also a list of statements that prevented closing.
SQLite-Inspect will also give you a list of statements executed and the number of times they were prepared, which should give you a good hint about using statement-caches.
SQLite-Inspect result file
By default SQLite-Inspect will automatically write a report named sqlite-inspect-report.txt into the working directory of the instrumented binary.
Current state of the project
This is in a pre-alpha stage, meaning that you might encounter bugs, non-existing documentation or code comments and overall chaoticness.
But hey, it’s plug and play. So there’s a good chance that it might already work fine for you.
So if you find this interesting, give it a spin and please let me know your thoughts at inspect(funny a)thisdomain.