← SQLite
SQLite·Format guide
All tools

SQLite in mobile apps

Most apps keep local data in SQLite: caches, offline copies of the user's data, analytics queues, tokens, and the stores behind Room (Android), Core Data (iOS), Realm-compatibility layers and many SDKs. The tool reads the file format directly, with no SQL engine, so it also opens databases it can't write to and shows changes that are still in the WAL file. Everything runs in your browser and nothing is uploaded.

Contents

  1. The file format
  2. WAL files
  3. Encrypted databases
  4. Browsing
  5. Values and dates
  6. Deleted rows
  7. Limits
  8. The SQLite library

1The file format

A database is a sequence of fixed-size pages (512 bytes to 64 KB, 4 KB by default). The first 100 bytes are the header: the magic SQLite format 3, the page size, the text encoding, the page count, the start of the freelist and a few version numbers. Each table is a b-tree of pages keyed by rowid; each index (and each WITHOUT ROWID table) is a b-tree keyed by its columns. Page 1 holds sqlite_schema, the table of every object and its CREATE statement.

A row is stored as a record: a header of serial types (NULL, 1–8-byte integers, a float, text or blob of a given length) followed by the values. Values that don't fit in their page continue on overflow pages. An INTEGER PRIMARY KEY column isn't stored at all: it is the rowid, and the tool shows it in its column.

Free pages are pages freed by deletions. Until the database is vacuumed they often still hold the old rows. The Overview gives their count.

2WAL files

In write-ahead-log mode (the default for Room and Core Data), changes are first appended to <name>-wal and copied into the database only at a checkpoint. A database copied without its WAL can be minutes or days behind. Select both files when opening, and the tool applies every committed frame on top of the database, so the newest version of each page wins. Frames after the last commit are left out and counted. The -shm file is only an index and isn't needed.

When the header says WAL mode and no WAL file was given, the Overview warns about it.

3Encrypted databases

SQLCipher, and SQLite's own encryption extensions, encrypt every page including the first, so the file has no readable header and looks like random bytes. The tool recognises this and says so. Reading it needs the key, which the app passes to sqlite3_key, PRAGMA key or the SQLCipher open call (in .NET apps, the SQLiteConnectionString / SQLitePCLRaw setup). Find it in the code, or capture it at run time, then decrypt with SQLCipher and open the result here.

4Browsing

5Values and dates

Click a cell to inspect it in full. Text is shown whole (JSON is pretty-printed). Blobs show their size, a guess at their kind (binary plist, PNG, JPEG, gzip, zip, an embedded SQLite database…), any readable text and a hex dump. A blob can be downloaded, opened in the Plist tool, or opened as a database.

Apps store dates as plain numbers, so for numbers the inspector lists the plausible readings between 1990 and 2045: Unix seconds, milliseconds or microseconds, Core Data's seconds since 2001, WebKit/Chrome microseconds since 1601, .NET ticks and Julian days.

6Deleted rows

SQLite doesn't wipe what it deletes (unless secure_delete is on). A deleted row's cell becomes a freeblock on its page, whose first 4 bytes are overwritten with the freeblock's own bookkeeping; when the page is rearranged the old bytes stay in its unused space; a page left empty goes to the freelist with its cells intact. Updates leave the old version of a row behind the same way.

After the tables are counted, the tool reads records from those places: each table's pages (including interior pages that were once leaves), and the free pages. A record is kept only when it parses exactly, has the table's number of columns, stores the INTEGER PRIMARY KEY column as NULL as SQLite does, and its text looks like text. In a freeblock, the overwritten bytes held the record's length and rowid (and sometimes the start of its header), so those rows come back without their rowid; the rest of the header is rebuilt when the lost part can only be one thing, and the record must end exactly where the next one begins. Rows on free pages are matched to a table by their columns' types. Copies identical to a live row are left out; a different version of a live row is marked as an older version.

They are listed under Recovered (deleted rows), one entry per table, with a found in column (the page and where on it). They can be filtered, inspected and exported like any table. What was overwritten since is gone: vacuuming, or new rows reusing the space, destroys deleted data.

7Limits

8The SQLite library

The reader is lib/sqlite.js, a JavaScript module with no dependencies and no user interface. It exports SqliteDatabase: an instance is an opened database, and the static methods are helpers. It also runs in a Web Worker (the tool uses it in sqlite/sqlite-worker.js, started with new WorkerClient(new URL("./sqlite-worker.js", import.meta.url)) from lib/worker-channel.js) or in jsc.

import { SqliteDatabase } from "../lib/sqlite.js";
Method / propertyWhat it does
SqliteDatabase.open(bytes, walBytes)Opens a database from an ArrayBuffer or Uint8Array, applying the committed frames of the optional -wal file. Throws an Error with code "encrypted" or "notsqlite" and the entropy of the first 4 KB.
database.headerpageSize, pageCount, encoding (1 UTF-8, 2 UTF-16le, 3 UTF-16be), journal ("WAL" or "rollback"), wal ({ frames, committed, uncommitted, pages } or null), userVersion, applicationId, sqliteVersion, freelistTrunk, freelistCount, fileSize and the other header fields.
database.schema()Every object, sqlite_schema itself first: { type, name, tableName, rootPage, sql, columns: [{ name, type, primaryKey }], rowidColumn, withoutRowid, virtual }. rowidColumn is the index of the INTEGER PRIMARY KEY column, or -1.
database.locate(object)Where the rows of a table or index are, in rowid or key order: { pages, cells, count }. Cached.
database.row(object, location, index, full){ rowid, values } for the row at that position. Values are null, numbers, BigInts (beyond 253), strings, { real } for REAL values, { blob: Uint8Array }, or, with full false, { text, cut } for a text over 4096 bytes. The INTEGER PRIMARY KEY column is filled with the rowid.
database.recover(progress)Deleted rows and older versions of changed rows (see Deleted rows): a Map from table name to [{ table, rowid, values, where, page, offset, partial, types, note }]. rowid is null when it was overwritten; note is "", "rowid lost" or "older version of a live row". progress(done, total) is optional.
database.freelist()The numbers of the free pages (trunks and leaves).
database.page(n), database.btree(n)Page n's bytes (the WAL version if there is one), and a b-tree page's header: { bytes, type, cellCount, pointersStart, rightChild, cell(i) }.
database.text(bytes), database.problemsBytes decoded in the database's encoding; the problems met while reading, as sentences.
SqliteDatabase.isSqlite(bytes), SqliteDatabase.entropy(bytes)Whether the bytes start with the SQLite header; bits per byte of the first 4 KB (close to 8 for an encrypted file).
SqliteDatabase.varint(bytes, offset)A SQLite varint: [value, next offset].
SqliteDatabase.parseCreate(sql, type)The columns of a CREATE TABLE statement: { columns, rowidColumn, withoutRowid, virtual }.
<script type="module">
import { SqliteDatabase } from "../lib/sqlite.js";

const database = SqliteDatabase.open(databaseBytes, walBytes);
const users = database.schema().find(object => object.name === "users");
const location = database.locate(users);
for (let index = 0; index < location.count; index++) {
	const row = database.row(users, location, index, true);
	console.log(row.rowid, row.values);
}
for (const [table, rows] of database.recover()) {
	console.log(table, rows.length, "deleted rows");
}
</script>