SQLite checklist¶
Copy this list into a pull request, design review or project kickoff and tick what applies. Rules are grouped by level and sorted by score (criteria). Each links to the file that explains it and cites its sources. Automatable names tools that can check the rule in CI (see the file's "How to enforce" section).
Also apply the general checklist.
This file is generated by python3 scripts/rank.py fix from the guidelines. Don't edit it by hand.
Strongly recommended (9–10)¶
-
SQLITE-6(9) Bind values with SQLite's placeholders,?or:name, through the driver's parameter API, such as the second argument of Python'sexecute(). (specific/sqlite) Automatable: CodeQL, SQL query built from user-controlled sources, Ruffhardcoded-sql-expression(S608).
Recommended (6–8)¶
-
SQLITE-1(8) Use SQLite where the data is on the same machine as the code that queries it and writers can take turns; choose a client/server database, such as PostgreSQL, when the data is on another machine, many processes must write at the same instant, or the data is heading for terabytes. (specific/sqlite) -
SQLITE-2(8) Never share a database between processes or machines through a network file system, such as NFS or SMB. (specific/sqlite) -
SQLITE-3(8) Configure every connection in one place as soon as it opens:PRAGMA foreign_keys=ON, a busy timeout, andPRAGMA trusted_schema=OFF. (specific/sqlite) Automatable:PRAGMA foreign_key_check. -
SQLITE-11(8) Copy a live database only with the online backup API,VACUUM INTOorsqlite3_rsync, never copy the database file while a connection may be writing to it, and never delete, rename or separate it from its-walor-journalfile. (specific/sqlite) -
SQLITE-4(7) Use WAL mode (PRAGMA journal_mode=WAL) for databases that are read while they are written, setPRAGMA synchronous=NORMALwhen each connection opens, and never setsynchronous=OFFfor data you need to keep. (specific/sqlite) -
SQLITE-5(7) Send all writes through one connection or a serial queue, start transactions that will write withBEGIN IMMEDIATE, and keep write transactions short. (specific/sqlite) -
SQLITE-7(7) Record the schema version inPRAGMA user_version, and when the app opens a database, apply the missing migrations in order, each in a transaction. For changes thatALTER TABLEcan't make, follow SQLite's 12-step procedure for rebuilding a table and finish withPRAGMA foreign_key_check. (specific/sqlite) Automatable:PRAGMA foreign_key_check. -
SQLITE-8(6) Create new tables asSTRICTtables once every SQLite version that opens the file is 3.37.0 or later. (specific/sqlite) -
SQLITE-9(6) Group related writes into one explicit transaction instead of letting each statement commit on its own. (specific/sqlite) -
SQLITE-12(6) Check backups and saves withPRAGMA integrity_check, or the fasterquick_check, before you rely on them, and keep the previous good copy until the new one passes. (specific/sqlite) -
SQLITE-13(6) Treat a database file that someone else could have written, such as a shared save, a mod or a downloaded file, as untrusted input (SEC-10): keeptrusted_schemaoff, and in security-sensitive apps runPRAGMA quick_checkbefore any other statement, reject files that fail, and setPRAGMA cell_size_check=ONandPRAGMA mmap_size=0. (specific/sqlite)
Conditional (1–5)¶
-
SQLITE-10(5) Index the columns that frequent queries filter, sort or join on, including the child columns of foreign keys, check plans withEXPLAIN QUERY PLAN, and runPRAGMA optimizeas SQLite recommends: before closing short-lived connections, periodically on long-lived ones, and after schema changes. (specific/sqlite) -
SQLITE-14(5) If the app runs SQL written by users or mods, turn onSQLITE_DBCONFIG_DEFENSIVE, lower the limits withsqlite3_limit(), and restrict what statements may do with an authorizer callback. (specific/sqlite)