PageRenderTime 49ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/v2/testdata/_sqlite/README.md

https://gitlab.com/zchee/ccgo
Markdown | 284 lines | 225 code | 59 blank | 0 comment | 0 complexity | c73f83c652ca2fad24fd25b610a6f063 MD5 | raw file
  1. <h1 align="center">SQLite Source Repository</h1>
  2. This repository contains the complete source code for the SQLite database
  3. engine. Some test scripts are also include. However, many other test scripts
  4. and most of the documentation are managed separately.
  5. If you are reading this on a Git mirror someplace, you are doing it wrong.
  6. The [official repository](https://www.sqlite.org/src/) is better. Go there
  7. now.
  8. ## Obtaining The Code
  9. SQLite sources are managed using the
  10. [Fossil](https://www.fossil-scm.org/), a distributed version control system
  11. that was specifically designed to support SQLite development.
  12. If you do not want to use Fossil, you can download tarballs or ZIP
  13. archives as follows:
  14. * Lastest trunk check-in:
  15. <https://www.sqlite.org/src/tarball/sqlite.tar.gz> or
  16. <https://www.sqlite.org/src/zip/sqlite.zip>.
  17. * Latest release:
  18. <https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release> or
  19. <https://www.sqlite.org/src/zip/sqlite.zip?r=release>.
  20. * For other check-ins, substitute an appropriate branch name or
  21. tag or hash prefix for "release" in the URLs of the previous
  22. bullet. Or browse the [timeline](https://www.sqlite.org/src/timeline)
  23. to locate the check-in desired, click on its information page link,
  24. then click on the "Tarball" or "ZIP Archive" links on the information
  25. page.
  26. If you do want to use Fossil to check out the source tree,
  27. first install Fossil version 2.0 or later.
  28. (Source tarballs and precompiled binaries available
  29. [here](https://www.fossil-scm.org/fossil/uv/download.html). Fossil is
  30. a stand-alone program. To install, simply download or build the single
  31. executable file and put that file someplace on your $PATH.)
  32. Then run commands like this:
  33. mkdir ~/sqlite
  34. cd ~/sqlite
  35. fossil clone https://www.sqlite.org/src sqlite.fossil
  36. fossil open sqlite.fossil
  37. After setting up a repository using the steps above, you can always
  38. update to the lastest version using:
  39. fossil update trunk ;# latest trunk check-in
  40. fossil update release ;# latest official release
  41. Or type "fossil ui" to get a web-based user interface.
  42. ## Compiling
  43. First create a directory in which to place
  44. the build products. It is recommended, but not required, that the
  45. build directory be separate from the source directory. Cd into the
  46. build directory and then from the build directory run the configure
  47. script found at the root of the source tree. Then run "make".
  48. For example:
  49. tar xzf sqlite.tar.gz ;# Unpack the source tree into "sqlite"
  50. mkdir bld ;# Build will occur in a sibling directory
  51. cd bld ;# Change to the build directory
  52. ../sqlite/configure ;# Run the configure script
  53. make ;# Run the makefile.
  54. make sqlite3.c ;# Build the "amalgamation" source file
  55. make test ;# Run some tests (requires Tcl)
  56. See the makefile for additional targets.
  57. The configure script uses autoconf 2.61 and libtool. If the configure
  58. script does not work out for you, there is a generic makefile named
  59. "Makefile.linux-gcc" in the top directory of the source tree that you
  60. can copy and edit to suit your needs. Comments on the generic makefile
  61. show what changes are needed.
  62. ## Using MSVC
  63. On Windows, all applicable build products can be compiled with MSVC.
  64. First open the command prompt window associated with the desired compiler
  65. version (e.g. "Developer Command Prompt for VS2013"). Next, use NMAKE
  66. with the provided "Makefile.msc" to build one of the supported targets.
  67. For example:
  68. mkdir bld
  69. cd bld
  70. nmake /f Makefile.msc TOP=..\sqlite
  71. nmake /f Makefile.msc sqlite3.c TOP=..\sqlite
  72. nmake /f Makefile.msc sqlite3.dll TOP=..\sqlite
  73. nmake /f Makefile.msc sqlite3.exe TOP=..\sqlite
  74. nmake /f Makefile.msc test TOP=..\sqlite
  75. There are several build options that can be set via the NMAKE command
  76. line. For example, to build for WinRT, simply add "FOR_WINRT=1" argument
  77. to the "sqlite3.dll" command line above. When debugging into the SQLite
  78. code, adding the "DEBUG=1" argument to one of the above command lines is
  79. recommended.
  80. SQLite does not require [Tcl](http://www.tcl.tk/) to run, but a Tcl installation
  81. is required by the makefiles (including those for MSVC). SQLite contains
  82. a lot of generated code and Tcl is used to do much of that code generation.
  83. The makefiles also require AWK.
  84. ## Source Code Tour
  85. Most of the core source files are in the **src/** subdirectory. The
  86. **src/** folder also contains files used to build the "testfixture" test
  87. harness. The names of the source files used by "testfixture" all begin
  88. with "test".
  89. The **src/** also contains the "shell.c" file
  90. which is the main program for the "sqlite3.exe"
  91. [command-line shell](https://sqlite.org/cli.html) and
  92. the "tclsqlite.c" file which implements the
  93. [TCL bindings](https://sqlite.org/tclsqlite.html) for SQLite.
  94. (Historical note: SQLite began as a Tcl
  95. extension and only later escaped to the wild as an independent library.)
  96. Test scripts and programs are found in the **test/** subdirectory.
  97. Addtional test code is found in other source repositories.
  98. See [How SQLite Is Tested](http://www.sqlite.org/testing.html) for
  99. additional information.
  100. The **ext/** subdirectory contains code for extensions. The
  101. Full-text search engine is in **ext/fts3**. The R-Tree engine is in
  102. **ext/rtree**. The **ext/misc** subdirectory contains a number of
  103. smaller, single-file extensions, such as a REGEXP operator.
  104. The **tool/** subdirectory contains various scripts and programs used
  105. for building generated source code files or for testing or for generating
  106. accessory programs such as "sqlite3_analyzer(.exe)".
  107. ### Generated Source Code Files
  108. Several of the C-language source files used by SQLite are generated from
  109. other sources rather than being typed in manually by a programmer. This
  110. section will summarize those automatically-generated files. To create all
  111. of the automatically-generated files, simply run "make target&#95;source".
  112. The "target&#95;source" make target will create a subdirectory "tsrc/" and
  113. fill it with all the source files needed to build SQLite, both
  114. manually-edited files and automatically-generated files.
  115. The SQLite interface is defined by the **sqlite3.h** header file, which is
  116. generated from src/sqlite.h.in, ./manifest.uuid, and ./VERSION. The
  117. [Tcl script](http://www.tcl.tk) at tool/mksqlite3h.tcl does the conversion.
  118. The manifest.uuid file contains the SHA3 hash of the particular check-in
  119. and is used to generate the SQLITE\_SOURCE\_ID macro. The VERSION file
  120. contains the current SQLite version number. The sqlite3.h header is really
  121. just a copy of src/sqlite.h.in with the source-id and version number inserted
  122. at just the right spots. Note that comment text in the sqlite3.h file is
  123. used to generate much of the SQLite API documentation. The Tcl scripts
  124. used to generate that documentation are in a separate source repository.
  125. The SQL language parser is **parse.c** which is generate from a grammar in
  126. the src/parse.y file. The conversion of "parse.y" into "parse.c" is done
  127. by the [lemon](./doc/lemon.html) LALR(1) parser generator. The source code
  128. for lemon is at tool/lemon.c. Lemon uses the tool/lempar.c file as a
  129. template for generating its parser.
  130. Lemon also generates the **parse.h** header file, at the same time it
  131. generates parse.c. But the parse.h header file is
  132. modified further (to add additional symbols) using the ./addopcodes.awk
  133. AWK script.
  134. The **opcodes.h** header file contains macros that define the numbers
  135. corresponding to opcodes in the "VDBE" virtual machine. The opcodes.h
  136. file is generated by the scanning the src/vdbe.c source file. The
  137. AWK script at ./mkopcodeh.awk does this scan and generates opcodes.h.
  138. A second AWK script, ./mkopcodec.awk, then scans opcodes.h to generate
  139. the **opcodes.c** source file, which contains a reverse mapping from
  140. opcode-number to opcode-name that is used for EXPLAIN output.
  141. The **keywordhash.h** header file contains the definition of a hash table
  142. that maps SQL language keywords (ex: "CREATE", "SELECT", "INDEX", etc.) into
  143. the numeric codes used by the parse.c parser. The keywordhash.h file is
  144. generated by a C-language program at tool mkkeywordhash.c.
  145. The **pragma.h** header file contains various definitions used to parse
  146. and implement the PRAGMA statements. The header is generated by a
  147. script **tool/mkpragmatab.tcl**. If you want to add a new PRAGMA, edit
  148. the **tool/mkpragmatab.tcl** file to insert the information needed by the
  149. parser for your new PRAGMA, then run the script to regenerate the
  150. **pragma.h** header file.
  151. ### The Amalgamation
  152. All of the individual C source code and header files (both manually-edited
  153. and automatically-generated) can be combined into a single big source file
  154. **sqlite3.c** called "the amalgamation". The amalgamation is the recommended
  155. way of using SQLite in a larger application. Combining all individual
  156. source code files into a single big source code file allows the C compiler
  157. to perform more cross-procedure analysis and generate better code. SQLite
  158. runs about 5% faster when compiled from the amalgamation versus when compiled
  159. from individual source files.
  160. The amalgamation is generated from the tool/mksqlite3c.tcl Tcl script.
  161. First, all of the individual source files must be gathered into the tsrc/
  162. subdirectory (using the equivalent of "make target_source") then the
  163. tool/mksqlite3c.tcl script is run to copy them all together in just the
  164. right order while resolving internal "#include" references.
  165. The amalgamation source file is more than 200K lines long. Some symbolic
  166. debuggers (most notably MSVC) are unable to deal with files longer than 64K
  167. lines. To work around this, a separate Tcl script, tool/split-sqlite3c.tcl,
  168. can be run on the amalgamation to break it up into a single small C file
  169. called **sqlite3-all.c** that does #include on about five other files
  170. named **sqlite3-1.c**, **sqlite3-2.c**, ..., **sqlite3-5.c**. In this way,
  171. all of the source code is contained within a single translation unit so
  172. that the compiler can do extra cross-procedure optimization, but no
  173. individual source file exceeds 32K lines in length.
  174. ## How It All Fits Together
  175. SQLite is modular in design.
  176. See the [architectural description](http://www.sqlite.org/arch.html)
  177. for details. Other documents that are useful in
  178. (helping to understand how SQLite works include the
  179. [file format](http://www.sqlite.org/fileformat2.html) description,
  180. the [virtual machine](http://www.sqlite.org/opcode.html) that runs
  181. prepared statements, the description of
  182. [how transactions work](http://www.sqlite.org/atomiccommit.html), and
  183. the [overview of the query planner](http://www.sqlite.org/optoverview.html).
  184. Years of effort have gone into optimizating SQLite, both
  185. for small size and high performance. And optimizations tend to result in
  186. complex code. So there is a lot of complexity in the current SQLite
  187. implementation. It will not be the easiest library in the world to hack.
  188. Key files:
  189. * **sqlite.h.in** - This file defines the public interface to the SQLite
  190. library. Readers will need to be familiar with this interface before
  191. trying to understand how the library works internally.
  192. * **sqliteInt.h** - this header file defines many of the data objects
  193. used internally by SQLite.
  194. * **parse.y** - This file describes the LALR(1) grammar that SQLite uses
  195. to parse SQL statements, and the actions that are taken at each step
  196. in the parsing process.
  197. * **vdbe.c** - This file implements the virtual machine that runs
  198. prepared statements. There are various helper files whose names
  199. begin with "vdbe". The VDBE has access to the vdbeInt.h header file
  200. which defines internal data objects. The rest of SQLite interacts
  201. with the VDBE through an interface defined by vdbe.h.
  202. * **where.c** - This file analyzes the WHERE clause and generates
  203. virtual machine code to run queries efficiently. This file is
  204. sometimes called the "query optimizer". It has its own private
  205. header file, whereInt.h, that defines data objects used internally.
  206. * **btree.c** - This file contains the implementation of the B-Tree
  207. storage engine used by SQLite.
  208. * **pager.c** - This file contains the "pager" implementation, the
  209. module that implements transactions.
  210. * **os_unix.c** and **os_win.c** - These two files implement the interface
  211. between SQLite and the underlying operating system using the run-time
  212. pluggable VFS interface.
  213. * **shell.c** - This file is not part of the core SQLite library. This
  214. is the file that, when linked against sqlite3.a, generates the
  215. "sqlite3.exe" command-line shell.
  216. * **tclsqlite.c** - This file implements the Tcl bindings for SQLite. It
  217. is not part of the core SQLite library. But as most of the tests in this
  218. repository are written in Tcl, the Tcl language bindings are important.
  219. There are many other source files. Each has a succinct header comment that
  220. describes its purpose and role within the larger system.
  221. ## Contacts
  222. The main SQLite webpage is [http://www.sqlite.org/](http://www.sqlite.org/)
  223. with geographically distributed backups at
  224. [http://www2.sqlite.org/](http://www2.sqlite.org) and
  225. [http://www3.sqlite.org/](http://www3.sqlite.org).