Adjust the new truncation behavior of sqlite_dbpage(N,null) such that it causes
[sqlite.git] / README.md
blob689b52dabd0d4ca08d53a62a88e6cac9068aa296
1 <h1 align="center">SQLite Source Repository</h1>
3 This repository contains the complete source code for the
4 [SQLite database engine](https://sqlite.org/), including
5 many test scripts.  However, other test scripts
6 and most of the documentation are managed separately.
8 See the [on-line documentation](https://sqlite.org/) for more information
9 about what SQLite is and how it works from a user's perspective.  This
10 README file is about the source code that goes into building SQLite,
11 not about how SQLite is used.
13 ## Version Control
15 SQLite sources are managed using
16 [Fossil](https://fossil-scm.org/), a distributed version control system
17 that was specifically designed and written to support SQLite development.
18 The [Fossil repository](https://sqlite.org/src/timeline) contains the urtext.
20 If you are reading this on GitHub or some other Git repository or service,
21 then you are looking at a mirror.  The names of check-ins and
22 other artifacts in a Git mirror are different from the official
23 names for those objects.  The official names for check-ins are
24 found in a footer on the check-in comment for authorized mirrors.
25 The official check-in name can also be seen in the `manifest.uuid` file
26 in the root of the tree.  Always use the official name, not  the
27 Git-name, when communicating about an SQLite check-in.
29 If you pulled your SQLite source code from a secondary source and want to
30 verify its integrity, there are hints on how to do that in the
31 [Verifying Code Authenticity](#vauth) section below.
33 ## Contacting The SQLite Developers
35 The preferred way to ask questions or make comments about SQLite or to
36 report bugs against SQLite is to visit the 
37 [SQLite Forum](https://sqlite.org/forum) at <https://sqlite.org/forum/>.
38 Anonymous postings are permitted.
40 If you think you have found a bug that has security implications and
41 you do not want to report it on the public forum, you can send a private
42 email to drh at sqlite dot org.
44 ## Public Domain
46 The SQLite source code is in the public domain.  See
47 <https://sqlite.org/copyright.html> for details. 
49 Because SQLite is in the public domain, we do not normally accept pull
50 requests, because if we did take a pull request, the changes in that
51 pull request might carry a copyright and the SQLite source code would
52 then no longer be fully in the public domain.
54 ## Obtaining The SQLite Source Code
56 If you do not want to use Fossil, you can download tarballs or ZIP
57 archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
59   *  Latest trunk check-in as
60      [Tarball](https://www.sqlite.org/src/tarball/sqlite.tar.gz),
61      [ZIP-archive](https://www.sqlite.org/src/zip/sqlite.zip), or
62      [SQLite-archive](https://www.sqlite.org/src/sqlar/sqlite.sqlar).
64   *  Latest release as
65      [Tarball](https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release),
66      [ZIP-archive](https://www.sqlite.org/src/zip/sqlite.zip?r=release), or
67      [SQLite-archive](https://www.sqlite.org/src/sqlar/sqlite.sqlar?r=release).
69   *  For other check-ins, substitute an appropriate branch name or
70      tag or hash prefix in place of "release" in the URLs of the previous
71      bullet.  Or browse the [timeline](https://www.sqlite.org/src/timeline)
72      to locate the check-in desired, click on its information page link,
73      then click on the "Tarball" or "ZIP Archive" links on the information
74      page.
76 To access sources directly using [Fossil](https://fossil-scm.org/home),
77 first install Fossil version 2.0 or later.
78 Source tarballs and precompiled binaries available at
79 <https://fossil-scm.org/home/uv/download.html>.  Fossil is
80 a stand-alone program.  To install, simply download or build the single
81 executable file and put that file someplace on your $PATH.
82 Then run commands like this:
84         mkdir -p ~/sqlite
85         cd ~/sqlite
86         fossil open https://sqlite.org/src
88 The "fossil open" command will take two or three minutes.  Afterwards,
89 you can do fast, bandwidth-efficient updates to the whatever versions
90 of SQLite you like.  Some examples:
92         fossil update trunk             ;# latest trunk check-in
93         fossil update release           ;# latest official release
94         fossil update trunk:2024-01-01  ;# First trunk check-in after 2024-01-01
95         fossil update version-3.39.0    ;# Version 3.39.0
97 Or type "fossil ui" to get a web-based user interface.
99 ## Compiling for Unix-like systems
101 First create a directory in which to place
102 the build products.  It is recommended, but not required, that the
103 build directory be separate from the source directory.  Cd into the
104 build directory and then from the build directory run the configure
105 script found at the root of the source tree.  Then run "make".
107 For example:
109         apt install gcc make tcl-dev  ;#  Make sure you have all the necessary build tools
110         tar xzf sqlite.tar.gz         ;#  Unpack the source tree into "sqlite"
111         mkdir bld                     ;#  Build will occur in a sibling directory
112         cd bld                        ;#  Change to the build directory
113         ../sqlite/configure           ;#  Run the configure script
114         make sqlite3                  ;#  Builds the "sqlite3" command-line tool
115         make sqlite3.c                ;#  Build the "amalgamation" source file
116         make sqldiff                  ;#  Builds the "sqldiff" command-line tool
117         # Makefile targets below this point require tcl-dev
118         make tclextension-install     ;#  Build and install the SQLite TCL extension
119         make devtest                  ;#  Run development tests
120         make releasetest              ;#  Run full release tests
121         make sqlite3_analyzer         ;#  Builds the "sqlite3_analyzer" tool
123 See the makefile for additional targets.  For debugging builds, the
124 core developers typically run "configure" with options like this:
126         ../sqlite/configure --enable-all --enable-debug CFLAGS='-O0 -g'
128 For release builds, the core developers usually do:
130         ../sqlite/configure --enable-all
132 Almost all makefile targets require a "tclsh" TCL interpreter version 8.6 or
133 later.  The "tclextension-install" target and the test targets that follow
134 all require TCL development libraries too.  ("apt install tcl-dev").  It is
135 helpful, but is not required, to install the SQLite TCL extension (the
136 "tclextension-install" target) prior to running tests.  The "releasetest"
137 target has additional requiremenst, such as "valgrind".
139 On "make" command-lines, one can add "OPTIONS=..." to specify additional
140 compile-time options over and above those set by ./configure.  For example,
141 to compile with the SQLITE_OMIT_DEPRECATED compile-time option, one could say:
143         ./configure --enable-all
144         make OPTIONS=-DSQLITE_OMIT_DEPRECATED sqlite3
146 The configure script uses autoconf 2.61 and libtool.  If the configure
147 script does not work out for you, there is a generic makefile named
148 "Makefile.linux-gcc" in the top directory of the source tree that you
149 can copy and edit to suit your needs.  Comments on the generic makefile
150 show what changes are needed.
152 ## Compiling for Windows Using MSVC
154 On Windows, everything can be compiled with MSVC.
155 You will also need a working installation of TCL.
156 See the [compile-for-windows.md](doc/compile-for-windows.md) document for
157 additional information about how to install MSVC and TCL and configure your
158 build environment.
160 If you want to run tests, you need to let SQLite know the location of your
161 TCL library, using a command like this:
163         set TCLDIR=c:\Tcl
165 SQLite uses "tclsh.exe" as part of the build process, and so that
166 program will need to be somewhere on your %PATH%.  SQLite itself
167 does not contain any TCL code, but it does use TCL to help with the
168 build process and to run tests.  You may need to install TCL development
169 libraries in order to successfully complete some makefile targets.
170 It is helpful, but is not required, to install the SQLite TCL extension
171 (the "tclextension-install" target) prior to running tests.
173 Build using Makefile.msc.  Example:
175         nmake /f Makefile.msc sqlite3.exe
176         nmake /f Makefile.msc sqlite3.c
177         nmake /f Makefile.msc sqldiff.exe
178         # Makefile targets below this point require TCL development libraries
179         nmake /f Makefile.msc tclextension-install
180         nmake /f Makefile.msc devtest
181         nmake /f Makefile.msc releasetest
182         nmake /f Makefile.msc sqlite3_analyzer.exe
184 There are many other makefile targets.  See comments in Makefile.msc for
185 details.
187 As with the unix Makefile, the OPTIONS=... argument can be passed on the nmake
188 command-line to enable new compile-time options.  For example:
190         nmake /f Makefile.msc OPTIONS=-DSQLITE_OMIT_DEPRECATED sqlite3.exe
192 ## Source Tree Map
194   *  **src/** - This directory contains the primary source code for the
195      SQLite core.  For historical reasons, C-code used for testing is
196      also found here.  Source files intended for testing begin with "`test`".
197      The `tclsqlite3.c` and `tclsqlite3.h` files are the TCL interface
198      for SQLite and are also not part of the core.
200   *  **test/** - This directory and its subdirectories contains code used
201      for testing.  Files that end in "`.test`" are TCL scripts that run
202      tests using an augmented TCL interpreter named "testfixture".  Use
203      a command like "`make testfixture`" (unix) or 
204      "`nmake /f Makefile.msc testfixture.exe`" (windows) to build that
205      augmented TCL interpreter, then run individual tests using commands like
206      "`testfixture test/main.test`".  This test/ subdirectory also contains
207      additional C code modules and scripts for other kinds of testing.
209   *  **tool/** - This directory contains programs and scripts used to
210      build some of the machine-generated code that goes into the SQLite
211      core, as well as to build and run tests and perform diagnostics.
212      The source code to [the Lemon parser generator](./doc/lemon.html) is
213      found here.  There are also TCL scripts used to build and/or transform
214      source code files.  For example, the tool/mksqlite3h.tcl script reads
215      the src/sqlite.h.in file and uses it as a template to construct
216      the deliverable "sqlite3.h" file that defines the SQLite interface.
218   *  **ext/** - Various extensions to SQLite are found under this
219      directory.  For example, the FTS5 subsystem is in "ext/fts5/".
220      Some of these extensions (ex: FTS3/4, FTS5, RTREE) might get built
221      into the SQLite amalgamation, but not all of them.  The
222      "ext/misc/" subdirectory contains an assortment of one-file extensions,
223      many of which are omitted from the SQLite core, but which are included
224      in the [SQLite CLI](https://sqlite.org/cli.html).
225      
226   *  **doc/** - Some documentation files about SQLite internals are found
227      here.  Note, however, that the primary documentation designed for
228      application developers and users of SQLite is in a completely separate
229      repository.  Note also that the primary API documentation is derived
230      from specially constructed comments in the src/sqlite.h.in file.
232 ### Generated Source Code Files
234 Several of the C-language source files used by SQLite are generated from
235 other sources rather than being typed in manually by a programmer.  This
236 section will summarize those automatically-generated files.  To create all
237 of the automatically-generated files, simply run "make target&#95;source".
238 The "target&#95;source" make target will create a subdirectory "tsrc/" and
239 fill it with all the source files needed to build SQLite, both
240 manually-edited files and automatically-generated files.
242 The SQLite interface is defined by the **sqlite3.h** header file, which is
243 generated from src/sqlite.h.in, ./manifest.uuid, and ./VERSION.  The
244 [Tcl script](https://www.tcl.tk) at tool/mksqlite3h.tcl does the conversion.
245 The manifest.uuid file contains the SHA3 hash of the particular check-in
246 and is used to generate the SQLITE\_SOURCE\_ID macro.  The VERSION file
247 contains the current SQLite version number.  The sqlite3.h header is really
248 just a copy of src/sqlite.h.in with the source-id and version number inserted
249 at just the right spots. Note that comment text in the sqlite3.h file is
250 used to generate much of the SQLite API documentation.  The Tcl scripts
251 used to generate that documentation are in a separate source repository.
253 The SQL language parser is **parse.c** which is generated from a grammar in
254 the src/parse.y file.  The conversion of "parse.y" into "parse.c" is done
255 by the [lemon](./doc/lemon.html) LALR(1) parser generator.  The source code
256 for lemon is at tool/lemon.c.  Lemon uses the tool/lempar.c file as a
257 template for generating its parser.
258 Lemon also generates the **parse.h** header file, at the same time it
259 generates parse.c.
261 The **opcodes.h** header file contains macros that define the numbers
262 corresponding to opcodes in the "VDBE" virtual machine.  The opcodes.h
263 file is generated by scanning the src/vdbe.c source file.  The
264 Tcl script at ./mkopcodeh.tcl does this scan and generates opcodes.h.
265 A second Tcl script, ./mkopcodec.tcl, then scans opcodes.h to generate
266 the **opcodes.c** source file, which contains a reverse mapping from
267 opcode-number to opcode-name that is used for EXPLAIN output.
269 The **keywordhash.h** header file contains the definition of a hash table
270 that maps SQL language keywords (ex: "CREATE", "SELECT", "INDEX", etc.) into
271 the numeric codes used by the parse.c parser.  The keywordhash.h file is
272 generated by a C-language program at tool mkkeywordhash.c.
274 The **pragma.h** header file contains various definitions used to parse
275 and implement the PRAGMA statements.  The header is generated by a
276 script **tool/mkpragmatab.tcl**. If you want to add a new PRAGMA, edit
277 the **tool/mkpragmatab.tcl** file to insert the information needed by the
278 parser for your new PRAGMA, then run the script to regenerate the
279 **pragma.h** header file.
281 ### The Amalgamation
283 All of the individual C source code and header files (both manually-edited
284 and automatically-generated) can be combined into a single big source file
285 **sqlite3.c** called "the amalgamation".  The amalgamation is the recommended
286 way of using SQLite in a larger application.  Combining all individual
287 source code files into a single big source code file allows the C compiler
288 to perform more cross-procedure analysis and generate better code.  SQLite
289 runs about 5% faster when compiled from the amalgamation versus when compiled
290 from individual source files.
292 The amalgamation is generated from the tool/mksqlite3c.tcl Tcl script.
293 First, all of the individual source files must be gathered into the tsrc/
294 subdirectory (using the equivalent of "make target_source") then the
295 tool/mksqlite3c.tcl script is run to copy them all together in just the
296 right order while resolving internal "#include" references.
298 The amalgamation source file is more than 200K lines long.  Some symbolic
299 debuggers (most notably MSVC) are unable to deal with files longer than 64K
300 lines.  To work around this, a separate Tcl script, tool/split-sqlite3c.tcl,
301 can be run on the amalgamation to break it up into a single small C file
302 called **sqlite3-all.c** that does #include on about seven other files
303 named **sqlite3-1.c**, **sqlite3-2.c**, ..., **sqlite3-7.c**.  In this way,
304 all of the source code is contained within a single translation unit so
305 that the compiler can do extra cross-procedure optimization, but no
306 individual source file exceeds 32K lines in length.
308 ## How It All Fits Together
310 SQLite is modular in design.
311 See the [architectural description](https://www.sqlite.org/arch.html)
312 for details. Other documents that are useful in
313 helping to understand how SQLite works include the
314 [file format](https://www.sqlite.org/fileformat2.html) description,
315 the [virtual machine](https://www.sqlite.org/opcode.html) that runs
316 prepared statements, the description of
317 [how transactions work](https://www.sqlite.org/atomiccommit.html), and
318 the [overview of the query planner](https://www.sqlite.org/optoverview.html).
320 Decades of effort have gone into optimizing SQLite, both
321 for small size and high performance.  And optimizations tend to result in
322 complex code.  So there is a lot of complexity in the current SQLite
323 implementation.  It will not be the easiest library in the world to hack.
325 ### Key source code files
327   *  **sqlite.h.in** - This file defines the public interface to the SQLite
328      library.  Readers will need to be familiar with this interface before
329      trying to understand how the library works internally.  This file is
330      really a template that is transformed into the "sqlite3.h" deliverable
331      using a script invoked by the makefile.
333   *  **sqliteInt.h** - this header file defines many of the data objects
334      used internally by SQLite.  In addition to "sqliteInt.h", some
335      subsystems inside of sQLite have their own header files.  These internal
336      interfaces are not for use by applications.  They can and do change
337      from one release of SQLite to the next.
339   *  **parse.y** - This file describes the LALR(1) grammar that SQLite uses
340      to parse SQL statements, and the actions that are taken at each step
341      in the parsing process.  The file is processed by the
342      [Lemon Parser Generator](./doc/lemon.html) to produce the actual C code
343      used for parsing.
345   *  **vdbe.c** - This file implements the virtual machine that runs
346      prepared statements.  There are various helper files whose names
347      begin with "vdbe".  The VDBE has access to the vdbeInt.h header file
348      which defines internal data objects.  The rest of SQLite interacts
349      with the VDBE through an interface defined by vdbe.h.
351   *  **where.c** - This file (together with its helper files named
352      by "where*.c") analyzes the WHERE clause and generates
353      virtual machine code to run queries efficiently.  This file is
354      sometimes called the "query optimizer".  It has its own private
355      header file, whereInt.h, that defines data objects used internally.
357   *  **btree.c** - This file contains the implementation of the B-Tree
358      storage engine used by SQLite.  The interface to the rest of the system
359      is defined by "btree.h".  The "btreeInt.h" header defines objects
360      used internally by btree.c and not published to the rest of the system.
362   *  **pager.c** - This file contains the "pager" implementation, the
363      module that implements transactions.  The "pager.h" header file
364      defines the interface between pager.c and the rest of the system.
366   *  **os_unix.c** and **os_win.c** - These two files implement the interface
367      between SQLite and the underlying operating system using the run-time
368      pluggable VFS interface.
370   *  **shell.c.in** - This file is not part of the core SQLite library.  This
371      is the file that, when linked against sqlite3.a, generates the
372      "sqlite3.exe" command-line shell.  The "shell.c.in" file is transformed
373      into "shell.c" as part of the build process.
375   *  **tclsqlite.c** - This file implements the Tcl bindings for SQLite.  It
376      is not part of the core SQLite library.  But as most of the tests in this
377      repository are written in Tcl, the Tcl language bindings are important.
379   *  **test\*.c** - Files in the src/ folder that begin with "test" go into
380      building the "testfixture.exe" program.  The testfixture.exe program is
381      an enhanced Tcl shell.  The testfixture.exe program runs scripts in the
382      test/ folder to validate the core SQLite code.  The testfixture program
383      (and some other test programs too) is built and run when you type
384      "make test".
386   *  **VERSION**, **manifest**, and **manifest.uuid** - These files define
387      the current SQLite version number.  The "VERSION" file is human generated,
388      but the "manifest" and "manifest.uuid" files are automatically generated
389      by the [Fossil version control system](https://fossil-scm.org/).
391 There are many other source files.  Each has a succinct header comment that
392 describes its purpose and role within the larger system.
394 <a name="vauth"></a>
395 ## Verifying Code Authenticity
397 The `manifest` file at the root directory of the source tree
398 contains either a SHA3-256 hash or a SHA1 hash
399 for every source file in the repository.
400 The name of the version of the entire source tree is just the
401 SHA3-256 hash of the `manifest` file itself, possibly with the
402 last line of that file omitted if the last line begins with
403 "`# Remove this line`".
404 The `manifest.uuid` file should contain the SHA3-256 hash of the
405 `manifest` file. If all of the above hash comparisons are correct, then
406 you can be confident that your source tree is authentic and unadulterated.
407 Details on the format for the `manifest` files are available
408 [on the Fossil website](https://fossil-scm.org/home/doc/trunk/www/fileformat.wiki#manifest).
410 The process of checking source code authenticity is automated by the 
411 makefile:
413 >   make verify-source
415 Or on windows:
417 >   nmake /f Makefile.msc verify-source
419 Using the makefile to verify source integrity is good for detecting
420 accidental changes to the source tree, but malicious changes could be
421 hidden by also modifying the makefiles.
423 ## Contacts
425 The main SQLite website is [https://sqlite.org/](https://sqlite.org/)
426 with geographically distributed backups at
427 [https://www2.sqlite.org/](https://www2.sqlite.org) and
428 [https://www3.sqlite.org/](https://www3.sqlite.org).
430 Contact the SQLite developers through the
431 [SQLite Forum](https://sqlite.org/forum/).  In an emergency, you
432 can send private email to the lead developer at drh at sqlite dot org.