Realcodeart.com

SQLite

A public-domain database small enough to live inside the phone.

D. Richard Hipp

Get it on a mug or tee →

D. Richard Hipp started SQLite in 2000 because a database server had become a single point of failure. He was working on software for a damage-control system aboard United States Navy destroyers. The program talked to a server. When the server was down, the program was a passenger. Hipp wanted the database in the same process as the application, stored in an ordinary file, with no administrator in the loop. The result was a SQL engine that ships as a library.

That choice still looks strange to people who learned databases as a service you log into. SQLite has no separate daemon to start. An application links the library, opens a file, and runs statements. The file is the database. The process is the server. Phones do this. Browsers do this. Operating systems do this. A copy of the library is small enough to live next to the program that needs a table, which is why it ended up in places that never thought of themselves as database customers.

The authors dedicated the library to the public domain. There is no share-alike clause and no notice you must paste into every binary. The project also publishes a blessing, a short waiver for places whose law has no notion of a public-domain gift, so the same freedom survives a lawyer who cannot find the right statute. On this site the piece is marked clear. The dedication is the reason.

The bars are the opening of sqlite3_exec, the call most early programs used. You hand it a database handle, a string of SQL, and a callback. It prepares the statement, steps through the rows, and invokes the callback once per row. When the string holds several statements, it walks them. Then it finishes. Later style prefers prepare and step, because a program that will run the same statement a thousand times should not reparse it each time. The older function remains the front door in the picture: one call, a string, a walk.

The library grew far past that door. It gained transactions that survive a crash, a write-ahead log, a query planner that can be inspected, and a test suite larger than the code it tests. Hipp's company, Hwaci, still develops it. None of that later machinery is what the mug shows. The mug shows the function that made the idea legible: SQL, in-process, one file, a callback for each row.

Public domain is a strong claim, and it is the correct one here. You can read the amalgamation, ship it inside a product, or change a line, and you do not owe the authors a notice on your box. This page still names Hipp, because credit is not the same thing as a license condition. The bars carry neither the name nor the dedication. They carry the shape of the call.

The function is a good portrait because it hides the engine and shows the contract. A string goes in. Rows come out through a function pointer. Errors come back as a code. There is no network address in the signature, which is the design speaking. If you can call a C function, you can keep a table. That was the requirement on the ship, and it is the requirement in a browser that must remember a preference when no database administrator is employed.

Hipp has described the library as the most widely deployed database, a claim that sounds like marketing until you count the copies inside devices that never advertise it. This catalog does not need the census. It needs the legal fact and the visual one. The legal fact is the public-domain dedication. The visual fact is sqlite3_exec, drawn as bars, so the front door is the picture and the warranty, of which there is none, is not pretending to be printed on a cup.

There is a second reason the opening of that function is the right excerpt. SQLite's public interface is wide, and a wide interface makes a bad picture. The bars would become a catalog of names. sqlite3_exec is narrow. Prepare, step, callback, finalize: four beats, then the function is done. A narrow function can be a portrait. The rest of the library, the pager and the btree and the virtual machine that actually runs the bytecode of a query, stays off the object. Anyone who wants it can read the amalgamation. The dedication already told them they may.

Mug and tee of SQLite