SQLite Inspect – Find misuse of SQLite – Alpha

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 with code using SQLite.

And since I know from experience that it would be a major pain to instrument your code by hand, I decided to make this work with just a single #include. Please note that this is a C++ header.

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:

#include "sqlite_inspect_amalgamation.h"

There. All done. Just compile and run.

By the way, you’ll also find a readme file with some additional explanation in the archive.

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.

Failure to close DB

Usually the reason for this is at least one unclosed statement. The report will tell you which database could not be closed along with the given error code. If open statements prevented the close-operation you’ll also get a list of those statements.

Statistics overview

In addition to common errors you also get a report about executed statements and the number of times they were prepared. This should give you a good hint which statements should be handled by statement-caches.

SQLite-Inspect result file

By default a report named sqlite-inspect-report-{hex-value}.txt is automatically written into the working directory of the instrumented binary. The „random“ number at the end of the report is necessary to avoid collisions of reports when running code that has dynamic libraries which also uses SQLite.

Current state of the project

This is in a alpha stage, meaning that you might encounter bugs, insufficient documentation or code comments and overall chaoticness.

But hey, it’s plug and play. So there’s Lille risk in trying it and a good chance that it’ll work fine for you.

The most recent version is 0.7

Feedback appreciated

So if you find this interesting, give it a spin and please let me know your thoughts at inspect(funny a)thisdomain.