Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/AGENTS.md # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / AGENTS.md` 152 lines · 6220 bytes Raw Blame History Rendered 1 # AGENTS.md 2 3 Guidance for AI coding agents working in this repository. 4 5 ## Project nature 6 7 SQLite is a self-contained, serverless SQL database engine written in C. The 8 source is **public domain**. 9 10 SQLite does not accept pull requests without prior agreement and/or 11 accompanying legal paperwork that places the pull request in the public domain. 12 However, the human SQLite developers will review a concise and well-written 13 pull request as a proof-of-concept prior to reimplementing the changes 14 themselves. 15 16 Agentic code is acceptable as long as nobody can tell that the code 17 is agentic. The code must looks as if was written by the original human 18 authors of SQLite, with the same coding style, variable naming style, 19 commenting style, and so forth. 20 21 SQLite uses the [Fossil](https://fossil-scm.org/) for version control, 22 not Git. The GitHub repository for SQLite is a mirror and is not 23 canonical. The canonical repository is at . 24 25 To send patches to the SQLite developers, the ideal format is a Fossil 26 patch created using the 27 "[fossil patch create](https://fossil-scm.org/home/help/patch)" command. 28 The second best approach is an ordinary context diff. 29 30 ## Reporting Bugs 31 32 Send bug reports to , not the SQLite user forum. 33 34 Bug reports should include a reproducible test case, written according 35 to the rules outlined at 36 [doc/writing-test-cases.md](https://sqlite.org/src/doc/trunk/doc/writing-test-cases.md). 37 38 Include suggested fixes and/or patches with bug reports, if possible. 39 40 ## Build 41 42 The configure script uses [autosetup](https://msteveb.github.io/autosetup/), 43 not GNU Autoconf. 44 45 ```bash 46 apt install gcc make tcl-dev # prerequisites (Debian/Ubuntu) 47 48 ./configure --dev # debug build 49 make sqlite3 # CLI shell 50 make sqlite3d # Debugging variant of the CLI shell 51 make sqlite3.c # amalgamation (single-file distribution form) 52 make testfixture # test runner binary (requires tcl-dev) 53 make tclextension-install # install TCL extension before running tests 54 ``` 55 56 ## Testing 57 58 Test cases in the SQLite source tree are written as SQL scripts, TCL 59 scripts, or separate C programs. There are many thousands of tests in 60 the canonical source tree. 61 62 Run individual SQL tests using the [CLI](https://sqlite.org/cli.html). 63 Run individual TCL test scripts using the "testfixture" program. 64 Use the test/testrunner.tcl script to run collections 65 of tests, including SQL tests, TCL scripts, and C test programs, 66 in parallel across multiple cores. 67 68 ```bash 69 # From the build directory: 70 ./sqlite3 test/misc01.sql # single SQL test script 71 ./testfixture test/main.test # single TCL test script 72 test/testrunner.tcl # quick suite 73 test/testrunner.tcl full # full suite 74 test/testrunner.tcl fts5% # pattern match 75 ``` 76 77 Check for failures from testrunner.tcl using: 78 79 * `grep '!' testrunner.log` 80 * `test/testrunner.tcl errors` 81 * `test/testrunner.tcl errors -v` 82 83 "`make test`" is an easy way to run a reasonably complete subset of tests. 84 85 ## Architecture 86 87 SQL text → **tokenizer** (`tokenize.c`) → **parser** (`parse.y` / Lemon) → 88 **code generator** (`build.c`, `select.c`, `insert.c`, `update.c`, `delete.c`, 89 `expr.c`) → **optimizer** (`where*.c`) → **VDBE** (`vdbe.c`) → **B-Tree** 90 (`btree.c`) → **Pager** (`pager.c`) → **WAL** (`wal.c`) → **VFS** 91 (`os_unix.c`, `os_win.c`). 92 93 The master internal header is `src/sqliteInt.h`. Major subsystems have private 94 headers: `vdbeInt.h`, `btreeInt.h`, `whereInt.h`. The public API is defined in 95 `src/sqlite.h.in` (template) which generates `sqlite3.h`. 96 97 ## Do not edit generated files 98 99 These files are produced by scripts and must not be edited by hand: 100 101 | File | Regenerate with | 102 |---|---| 103 | `sqlite3.h` | `tool/mksqlite3h.tcl` | 104 | `parse.c`, `parse.h` | build lemon (`tool/lemon.c`) then run on `src/parse.y` | 105 | `opcodes.h` | `tool/mkopcodeh.tcl` (reads `src/vdbe.c`) | 106 | `opcodes.c` | `tool/mkopcodec.tcl` (reads `opcodes.h`) | 107 | `keywordhash.h` | `tool/mkkeywordhash.c` | 108 | `pragma.h` | `tool/mkpragmatab.tcl` | 109 | `sqlite3.c` | `tool/mksqlite3c.tcl` (the amalgamation) | 110 111 Editing rules: 112 - To add a PRAGMA: edit `tool/mkpragmatab.tcl`, then regenerate `pragma.h`. 113 - To add a VDBE opcode: add the `case OP_Xxx:` handler in `src/vdbe.c`; the 114 opcode number and name are extracted automatically by `mkopcodeh.tcl`. 115 - To change the SQL grammar: edit `src/parse.y`, not `parse.c`. 116 117 ## Coding conventions 118 119 - C89/C99 compatible C only. No C++, no STL, no exceptions, no VLAs. 120 - All memory allocation goes through `sqlite3Malloc` / `sqlite3_malloc64` 121 (never raw `malloc`). The `sqlite3MallocZero` variant zero-initializes. 122 - Integer widths: use `i64` (`sqlite3_int64`) for 64-bit values, `u32`/`u64` 123 for unsigned. Avoid bare `long` or `int` for values that could exceed 2G. 124 - Error propagation: functions return `SQLITE_OK` (0) on success and a 125 `SQLITE_*` error code on failure. Many routines also set `db->mallocFailed` 126 on OOM, allowing deferred error checking. 127 - Assert liberally for invariants that must hold in correct code; use 128 `ALWAYS(x)` / `NEVER(x)` for conditions that are logically always 129 true/false but that the compiler cannot prove. 130 - All code should match. It should not be possible to identify the author 131 of a section of code based on its style. 132 133 ## Extensions (`ext/`) 134 135 Extensions are compiled separately from the core and are not part of the 136 amalgamation by default (except where explicitly included). Major subsystems: 137 138 - `ext/fts5/` — Full-Text Search 5 (current) 139 - `ext/rtree/` — R-Tree spatial indexing 140 - `ext/session/` — Changesets and sessions 141 - `ext/recover/` — Database file recovery 142 - `ext/misc/` — Single-file utility extensions (many included in the CLI) 143 - `ext/qrf/` — Query Result Formatter utility library 144 145 ## Useful references 146 147 - Architecture: 148 - File format: 149 - VDBE opcodes: 150 - Query planner: 151 - Lemon parser generator: 152 - Compile-time options: