Add SQLITE_EXTRA_AUTOEXT, similar to SQLITE_EXTRA_INIT but adds a builtin auto-extens...
[sqlite.git] / README.md
blob9c221fff29812e0f1153db517acf2f57ca9b9aa5
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/).  Some test scripts
5 are also included.  However, many other test scripts
6 and most of the documentation are managed separately.
8 ## Version Control
10 SQLite sources are managed using
11 [Fossil](https://www.fossil-scm.org/), a distributed version control system
12 that was specifically designed and written to support SQLite development.
13 The [Fossil repository](https://sqlite.org/src/timeline) contains the urtext.
15 If you are reading this on GitHub or some other Git repository or service,
16 then you are looking at a mirror.  The names of check-ins and
17 other artifacts in a Git mirror are different from the official
18 names for those objects.  The official names for check-ins are
19 found in a footer on the check-in comment for authorized mirrors.
20 The official check-in name can also be seen in the `manifest.uuid` file
21 in the root of the tree.  Always use the official name, not  the
22 Git-name, when communicating about an SQLite check-in.
24 If you pulled your SQLite source code from a secondary source and want to
25 verify its integrity, there are hints on how to do that in the
26 [Verifying Code Authenticity](#vauth) section below.
28 ## Contacting The SQLite Developers
30 The preferred way to ask questions or make comments about SQLite or to
31 report bugs against SQLite is to visit the 
32 [SQLite Forum](https://sqlite.org/forum) at <https://sqlite.org/forum/>.
33 Anonymous postings are permitted.
35 If you think you have found a bug that has security implications and
36 you do not want to report it on the public forum, you can send a private
37 email to drh at sqlite dot org.
39 ## Public Domain
41 The SQLite source code is in the public domain.  See
42 <https://sqlite.org/copyright.html> for details. 
44 Because SQLite is in the public domain,
45 we cannot accept pull requests, because
46 if we did accept a pull request, the changes in that pull request would
47 carry a copyright and the SQLite source code would no longer be fully in
48 the public domain.
50 ## Obtaining The SQLite Source Code
52 If you do not want to use Fossil, you can download tarballs or ZIP
53 archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
55   *  Latest trunk check-in as
56      [Tarball](https://www.sqlite.org/src/tarball/sqlite.tar.gz),
57      [ZIP-archive](https://www.sqlite.org/src/zip/sqlite.zip), or
58      [SQLite-archive](https://www.sqlite.org/src/sqlar/sqlite.sqlar).
60   *  Latest release as
61      [Tarball](https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release),
62      [ZIP-archive](https://www.sqlite.org/src/zip/sqlite.zip?r=release), or
63      [SQLite-archive](https://www.sqlite.org/src/sqlar/sqlite.sqlar?r=release).
65   *  For other check-ins, substitute an appropriate branch name or
66      tag or hash prefix in place of "release" in the URLs of the previous
67      bullet.  Or browse the [timeline](https://www.sqlite.org/src/timeline)
68      to locate the check-in desired, click on its information page link,
69      then click on the "Tarball" or "ZIP Archive" links on the information
70      page.
72 If you do want to use Fossil to check out the source tree,
73 first install Fossil version 2.0 or later.
74 (Source tarballs and precompiled binaries available
75 [here](https://www.fossil-scm.org/fossil/uv/download.html).  Fossil is
76 a stand-alone program.  To install, simply download or build the single
77 executable file and put that file someplace on your $PATH.)
78 Then run commands like this:
80         mkdir -p ~/sqlite ~/Fossils
81         cd ~/sqlite
82         fossil clone https://www.sqlite.org/src ~/Fossils/sqlite.fossil
83         fossil open ~/Fossils/sqlite.fossil
85 After setting up a repository using the steps above, you can always
86 update to the latest version using:
88         fossil update trunk   ;# latest trunk check-in
89         fossil update release ;# latest official release
91 Or type "fossil ui" to get a web-based user interface.
93 ## Compiling for Unix-like systems
95 First create a directory in which to place
96 the build products.  It is recommended, but not required, that the
97 build directory be separate from the source directory.  Cd into the
98 build directory and then from the build directory run the configure
99 script found at the root of the source tree.  Then run "make".
101 For example:
103         tar xzf sqlite.tar.gz    ;#  Unpack the source tree into "sqlite"
104         mkdir bld                ;#  Build will occur in a sibling directory
105         cd bld                   ;#  Change to the build directory
106         ../sqlite/configure      ;#  Run the configure script
107         make                     ;#  Builds the "sqlite3" command-line tool
108         make sqlite3.c           ;#  Build the "amalgamation" source file
109         make devtest             ;#  Run some tests (requires Tcl)
111 See the makefile for additional targets.
113 The configure script uses autoconf 2.61 and libtool.  If the configure
114 script does not work out for you, there is a generic makefile named
115 "Makefile.linux-gcc" in the top directory of the source tree that you
116 can copy and edit to suit your needs.  Comments on the generic makefile
117 show what changes are needed.
119 ## Using MSVC for Windows systems
121 On Windows, all applicable build products can be compiled with MSVC.
122 You will also need a working installation of TCL.
123 See the [compile-for-windows.md](doc/compile-for-windows.md) document for
124 additional information about how to install MSVC and TCL and configure your
125 build environment.
127 If you want to run tests, you need to let SQLite know the location of your
128 TCL library, using a command like this:
130         set TCLDIR=c:\Tcl
132 SQLite uses "tclsh.exe" as part of the build process, and so that utility
133 program will need to be somewhere on your %PATH%.  The finished SQLite library
134 does not contain any TCL code, but it does use TCL to help with the build process
135 and to run tests.
137 Build using Makefile.msc.  Example:
139         nmake /f Makefile.msc
140         nmake /f Makefile.msc sqlite3.c
141         nmake /f Makefile.msc devtest
142         nmake /f Makefile.msc releasetest
144 There are many other makefile targets.  See comments in Makefile.msc for
145 details.
147 ## Source Code Tour
149 Most of the core source files are in the **src/** subdirectory.  The
150 **src/** folder also contains files used to build the "testfixture" test
151 harness. The names of the source files used by "testfixture" all begin
152 with "test".
153 The **src/** also contains the "shell.c" file
154 which is the main program for the "sqlite3.exe"
155 [command-line shell](https://sqlite.org/cli.html) and
156 the "tclsqlite.c" file which implements the
157 [Tcl bindings](https://sqlite.org/tclsqlite.html) for SQLite.
158 (Historical note:  SQLite began as a Tcl
159 extension and only later escaped to the wild as an independent library.)
161 Test scripts and programs are found in the **test/** subdirectory.
162 Additional test code is found in other source repositories.
163 See [How SQLite Is Tested](http://www.sqlite.org/testing.html) for
164 additional information.
166 The **ext/** subdirectory contains code for extensions.  The
167 Full-text search engine is in **ext/fts3**.  The R-Tree engine is in
168 **ext/rtree**.  The **ext/misc** subdirectory contains a number of
169 smaller, single-file extensions, such as a REGEXP operator.
171 The **tool/** subdirectory contains various scripts and programs used
172 for building generated source code files or for testing or for generating
173 accessory programs such as "sqlite3_analyzer(.exe)".
175 ### Generated Source Code Files
177 Several of the C-language source files used by SQLite are generated from
178 other sources rather than being typed in manually by a programmer.  This
179 section will summarize those automatically-generated files.  To create all
180 of the automatically-generated files, simply run "make target&#95;source".
181 The "target&#95;source" make target will create a subdirectory "tsrc/" and
182 fill it with all the source files needed to build SQLite, both
183 manually-edited files and automatically-generated files.
185 The SQLite interface is defined by the **sqlite3.h** header file, which is
186 generated from src/sqlite.h.in, ./manifest.uuid, and ./VERSION.  The
187 [Tcl script](http://www.tcl.tk) at tool/mksqlite3h.tcl does the conversion.
188 The manifest.uuid file contains the SHA3 hash of the particular check-in
189 and is used to generate the SQLITE\_SOURCE\_ID macro.  The VERSION file
190 contains the current SQLite version number.  The sqlite3.h header is really
191 just a copy of src/sqlite.h.in with the source-id and version number inserted
192 at just the right spots. Note that comment text in the sqlite3.h file is
193 used to generate much of the SQLite API documentation.  The Tcl scripts
194 used to generate that documentation are in a separate source repository.
196 The SQL language parser is **parse.c** which is generated from a grammar in
197 the src/parse.y file.  The conversion of "parse.y" into "parse.c" is done
198 by the [lemon](./doc/lemon.html) LALR(1) parser generator.  The source code
199 for lemon is at tool/lemon.c.  Lemon uses the tool/lempar.c file as a
200 template for generating its parser.
201 Lemon also generates the **parse.h** header file, at the same time it
202 generates parse.c.
204 The **opcodes.h** header file contains macros that define the numbers
205 corresponding to opcodes in the "VDBE" virtual machine.  The opcodes.h
206 file is generated by scanning the src/vdbe.c source file.  The
207 Tcl script at ./mkopcodeh.tcl does this scan and generates opcodes.h.
208 A second Tcl script, ./mkopcodec.tcl, then scans opcodes.h to generate
209 the **opcodes.c** source file, which contains a reverse mapping from
210 opcode-number to opcode-name that is used for EXPLAIN output.
212 The **keywordhash.h** header file contains the definition of a hash table
213 that maps SQL language keywords (ex: "CREATE", "SELECT", "INDEX", etc.) into
214 the numeric codes used by the parse.c parser.  The keywordhash.h file is
215 generated by a C-language program at tool mkkeywordhash.c.
217 The **pragma.h** header file contains various definitions used to parse
218 and implement the PRAGMA statements.  The header is generated by a
219 script **tool/mkpragmatab.tcl**. If you want to add a new PRAGMA, edit
220 the **tool/mkpragmatab.tcl** file to insert the information needed by the
221 parser for your new PRAGMA, then run the script to regenerate the
222 **pragma.h** header file.
224 ### The Amalgamation
226 All of the individual C source code and header files (both manually-edited
227 and automatically-generated) can be combined into a single big source file
228 **sqlite3.c** called "the amalgamation".  The amalgamation is the recommended
229 way of using SQLite in a larger application.  Combining all individual
230 source code files into a single big source code file allows the C compiler
231 to perform more cross-procedure analysis and generate better code.  SQLite
232 runs about 5% faster when compiled from the amalgamation versus when compiled
233 from individual source files.
235 The amalgamation is generated from the tool/mksqlite3c.tcl Tcl script.
236 First, all of the individual source files must be gathered into the tsrc/
237 subdirectory (using the equivalent of "make target_source") then the
238 tool/mksqlite3c.tcl script is run to copy them all together in just the
239 right order while resolving internal "#include" references.
241 The amalgamation source file is more than 200K lines long.  Some symbolic
242 debuggers (most notably MSVC) are unable to deal with files longer than 64K
243 lines.  To work around this, a separate Tcl script, tool/split-sqlite3c.tcl,
244 can be run on the amalgamation to break it up into a single small C file
245 called **sqlite3-all.c** that does #include on about seven other files
246 named **sqlite3-1.c**, **sqlite3-2.c**, ..., **sqlite3-7.c**.  In this way,
247 all of the source code is contained within a single translation unit so
248 that the compiler can do extra cross-procedure optimization, but no
249 individual source file exceeds 32K lines in length.
251 ## How It All Fits Together
253 SQLite is modular in design.
254 See the [architectural description](http://www.sqlite.org/arch.html)
255 for details. Other documents that are useful in
256 (helping to understand how SQLite works include the
257 [file format](http://www.sqlite.org/fileformat2.html) description,
258 the [virtual machine](http://www.sqlite.org/opcode.html) that runs
259 prepared statements, the description of
260 [how transactions work](http://www.sqlite.org/atomiccommit.html), and
261 the [overview of the query planner](http://www.sqlite.org/optoverview.html).
263 Years of effort have gone into optimizing SQLite, both
264 for small size and high performance.  And optimizations tend to result in
265 complex code.  So there is a lot of complexity in the current SQLite
266 implementation.  It will not be the easiest library in the world to hack.
268 Key files:
270   *  **sqlite.h.in** - This file defines the public interface to the SQLite
271      library.  Readers will need to be familiar with this interface before
272      trying to understand how the library works internally.
274   *  **sqliteInt.h** - this header file defines many of the data objects
275      used internally by SQLite.  In addition to "sqliteInt.h", some
276      subsystems have their own header files.
278   *  **parse.y** - This file describes the LALR(1) grammar that SQLite uses
279      to parse SQL statements, and the actions that are taken at each step
280      in the parsing process.
282   *  **vdbe.c** - This file implements the virtual machine that runs
283      prepared statements.  There are various helper files whose names
284      begin with "vdbe".  The VDBE has access to the vdbeInt.h header file
285      which defines internal data objects.  The rest of SQLite interacts
286      with the VDBE through an interface defined by vdbe.h.
288   *  **where.c** - This file (together with its helper files named
289      by "where*.c") analyzes the WHERE clause and generates
290      virtual machine code to run queries efficiently.  This file is
291      sometimes called the "query optimizer".  It has its own private
292      header file, whereInt.h, that defines data objects used internally.
294   *  **btree.c** - This file contains the implementation of the B-Tree
295      storage engine used by SQLite.  The interface to the rest of the system
296      is defined by "btree.h".  The "btreeInt.h" header defines objects
297      used internally by btree.c and not published to the rest of the system.
299   *  **pager.c** - This file contains the "pager" implementation, the
300      module that implements transactions.  The "pager.h" header file
301      defines the interface between pager.c and the rest of the system.
303   *  **os_unix.c** and **os_win.c** - These two files implement the interface
304      between SQLite and the underlying operating system using the run-time
305      pluggable VFS interface.
307   *  **shell.c.in** - This file is not part of the core SQLite library.  This
308      is the file that, when linked against sqlite3.a, generates the
309      "sqlite3.exe" command-line shell.  The "shell.c.in" file is transformed
310      into "shell.c" as part of the build process.
312   *  **tclsqlite.c** - This file implements the Tcl bindings for SQLite.  It
313      is not part of the core SQLite library.  But as most of the tests in this
314      repository are written in Tcl, the Tcl language bindings are important.
316   *  **test\*.c** - Files in the src/ folder that begin with "test" go into
317      building the "testfixture.exe" program.  The testfixture.exe program is
318      an enhanced Tcl shell.  The testfixture.exe program runs scripts in the
319      test/ folder to validate the core SQLite code.  The testfixture program
320      (and some other test programs too) is built and run when you type
321      "make test".
323 There are many other source files.  Each has a succinct header comment that
324 describes its purpose and role within the larger system.
326 <a name="vauth"></a>
327 ## Verifying Code Authenticity
329 The `manifest` file at the root directory of the source tree
330 contains either a SHA3-256 hash or a SHA1 hash
331 for every source file in the repository.
332 The name of the version of the entire source tree is just the
333 SHA3-256 hash of the `manifest` file itself, possibly with the
334 last line of that file omitted if the last line begins with
335 "`# Remove this line`".
336 The `manifest.uuid` file should contain the SHA3-256 hash of the
337 `manifest` file. If all of the above hash comparisons are correct, then
338 you can be confident that your source tree is authentic and unadulterated.
339 Details on the format for the `manifest` files are available
340 [on the Fossil website](https://fossil-scm.org/fossil/doc/trunk/www/fileformat.wiki#manifest).
342 The process of checking source code authenticity is automated by the 
343 makefile:
345 >   make verify-source
347 Or on windows:
349 >   nmake /f Makefile.msc verify-source
351 Using the makefile to verify source integrity is good for detecting
352 accidental changes to the source tree, but malicious changes could be
353 hidden by also modifying the makefiles.
355 ## Contacts
357 The main SQLite website is [http:/sqlite.org/](http://sqlite.org/)
358 with geographically distributed backups at
359 [http://www2.sqlite.org/](http://www2.sqlite.org) and
360 [http://www3.sqlite.org/](http://www3.sqlite.org).