diff options
author | dan miller | 2007-10-20 02:49:29 +0000 |
---|---|---|
committer | dan miller | 2007-10-20 02:49:29 +0000 |
commit | e36d23a85ebff914d74bb541558c2b6082b78edb (patch) | |
tree | 54b58fdf162e78af64055282a6035c8d2443389d /libraries/sqlite/unix/sqlite-3.5.1/www/arch.tcl | |
parent | * Fixed an issue whereby avatar chat distances were being calculated against ... (diff) | |
download | opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.zip opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.gz opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.bz2 opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.xz |
sqlite source (unix build) added to libraries
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/www/arch.tcl')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/www/arch.tcl | 221 |
1 files changed, 221 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/www/arch.tcl b/libraries/sqlite/unix/sqlite-3.5.1/www/arch.tcl new file mode 100644 index 0000000..d6c8166 --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/www/arch.tcl | |||
@@ -0,0 +1,221 @@ | |||
1 | # | ||
2 | # Run this Tcl script to generate the sqlite.html file. | ||
3 | # | ||
4 | set rcsid {$Id: arch.tcl,v 1.16 2004/10/10 17:24:54 drh Exp $} | ||
5 | source common.tcl | ||
6 | header {Architecture of SQLite} | ||
7 | puts { | ||
8 | <h2>The Architecture Of SQLite</h2> | ||
9 | |||
10 | <h3>Introduction</h3> | ||
11 | |||
12 | <table align="right" border="1" cellpadding="15" cellspacing="1"> | ||
13 | <tr><th>Block Diagram Of SQLite</th></tr> | ||
14 | <tr><td><img src="arch2.gif"></td></tr> | ||
15 | </table> | ||
16 | <p>This document describes the architecture of the SQLite library. | ||
17 | The information here is useful to those who want to understand or | ||
18 | modify the inner workings of SQLite. | ||
19 | </p> | ||
20 | |||
21 | <p> | ||
22 | A block diagram showing the main components of SQLite | ||
23 | and how they interrelate is shown at the right. The text that | ||
24 | follows will provide a quick overview of each of these components. | ||
25 | </p> | ||
26 | |||
27 | |||
28 | <p> | ||
29 | This document describes SQLite version 3.0. Version 2.8 and | ||
30 | earlier are similar but the details differ. | ||
31 | </p> | ||
32 | |||
33 | <h3>Interface</h3> | ||
34 | |||
35 | <p>Much of the public interface to the SQLite library is implemented by | ||
36 | functions found in the <b>main.c</b>, <b>legacy.c</b>, and | ||
37 | <b>vdbeapi.c</b> source files | ||
38 | though some routines are | ||
39 | scattered about in other files where they can have access to data | ||
40 | structures with file scope. The | ||
41 | <b>sqlite3_get_table()</b> routine is implemented in <b>table.c</b>. | ||
42 | <b>sqlite3_mprintf()</b> is found in <b>printf.c</b>. | ||
43 | <b>sqlite3_complete()</b> is in <b>tokenize.c</b>. | ||
44 | The Tcl interface is implemented by <b>tclsqlite.c</b>. More | ||
45 | information on the C interface to SQLite is | ||
46 | <a href="capi3ref.html">available separately</a>.<p> | ||
47 | |||
48 | <p>To avoid name collisions with other software, all external | ||
49 | symbols in the SQLite library begin with the prefix <b>sqlite3</b>. | ||
50 | Those symbols that are intended for external use (in other words, | ||
51 | those symbols which form the API for SQLite) begin | ||
52 | with <b>sqlite3_</b>.</p> | ||
53 | |||
54 | <h3>Tokenizer</h3> | ||
55 | |||
56 | <p>When a string containing SQL statements is to be executed, the | ||
57 | interface passes that string to the tokenizer. The job of the tokenizer | ||
58 | is to break the original string up into tokens and pass those tokens | ||
59 | one by one to the parser. The tokenizer is hand-coded in C in | ||
60 | the file <b>tokenize.c</b>. | ||
61 | |||
62 | <p>Note that in this design, the tokenizer calls the parser. People | ||
63 | who are familiar with YACC and BISON may be used to doing things the | ||
64 | other way around -- having the parser call the tokenizer. The author | ||
65 | of SQLite | ||
66 | has done it both ways and finds things generally work out nicer for | ||
67 | the tokenizer to call the parser. YACC has it backwards.</p> | ||
68 | |||
69 | <h3>Parser</h3> | ||
70 | |||
71 | <p>The parser is the piece that assigns meaning to tokens based on | ||
72 | their context. The parser for SQLite is generated using the | ||
73 | <a href="http://www.hwaci.com/sw/lemon/">Lemon</a> LALR(1) parser | ||
74 | generator. Lemon does the same job as YACC/BISON, but it uses | ||
75 | a different input syntax which is less error-prone. | ||
76 | Lemon also generates a parser which is reentrant and thread-safe. | ||
77 | And lemon defines the concept of a non-terminal destructor so | ||
78 | that it does not leak memory when syntax errors are encountered. | ||
79 | The source file that drives Lemon is found in <b>parse.y</b>.</p> | ||
80 | |||
81 | <p>Because | ||
82 | lemon is a program not normally found on development machines, the | ||
83 | complete source code to lemon (just one C file) is included in the | ||
84 | SQLite distribution in the "tool" subdirectory. Documentation on | ||
85 | lemon is found in the "doc" subdirectory of the distribution. | ||
86 | </p> | ||
87 | |||
88 | <h3>Code Generator</h3> | ||
89 | |||
90 | <p>After the parser assembles tokens into complete SQL statements, | ||
91 | it calls the code generator to produce virtual machine code that | ||
92 | will do the work that the SQL statements request. There are many | ||
93 | files in the code generator: | ||
94 | <b>attach.c</b>, | ||
95 | <b>auth.c</b>, | ||
96 | <b>build.c</b>, | ||
97 | <b>delete.c</b>, | ||
98 | <b>expr.c</b>, | ||
99 | <b>insert.c</b>, | ||
100 | <b>pragma.c</b>, | ||
101 | <b>select.c</b>, | ||
102 | <b>trigger.c</b>, | ||
103 | <b>update.c</b>, | ||
104 | <b>vacuum.c</b> | ||
105 | and <b>where.c</b>. | ||
106 | In these files is where most of the serious magic happens. | ||
107 | <b>expr.c</b> handles code generation for expressions. | ||
108 | <b>where.c</b> handles code generation for WHERE clauses on | ||
109 | SELECT, UPDATE and DELETE statements. The files <b>attach.c</b>, | ||
110 | <b>delete.c</b>, <b>insert.c</b>, <b>select.c</b>, <b>trigger.c</b> | ||
111 | <b>update.c</b>, and <b>vacuum.c</b> handle the code generation | ||
112 | for SQL statements with the same names. (Each of these files calls routines | ||
113 | in <b>expr.c</b> and <b>where.c</b> as necessary.) All other | ||
114 | SQL statements are coded out of <b>build.c</b>. | ||
115 | The <b>auth.c</b> file implements the functionality of | ||
116 | <b>sqlite3_set_authorizer()</b>.</p> | ||
117 | |||
118 | <h3>Virtual Machine</h3> | ||
119 | |||
120 | <p>The program generated by the code generator is executed by | ||
121 | the virtual machine. Additional information about the virtual | ||
122 | machine is <a href="opcode.html">available separately</a>. | ||
123 | To summarize, the virtual machine implements an abstract computing | ||
124 | engine specifically designed to manipulate database files. The | ||
125 | machine has a stack which is used for intermediate storage. | ||
126 | Each instruction contains an opcode and | ||
127 | up to three additional operands.</p> | ||
128 | |||
129 | <p>The virtual machine itself is entirely contained in a single | ||
130 | source file <b>vdbe.c</b>. The virtual machine also has | ||
131 | its own header files: <b>vdbe.h</b> that defines an interface | ||
132 | between the virtual machine and the rest of the SQLite library and | ||
133 | <b>vdbeInt.h</b> which defines structure private the virtual machine. | ||
134 | The <b>vdbeaux.c</b> file contains utilities used by the virtual | ||
135 | machine and interface modules used by the rest of the library to | ||
136 | construct VM programs. The <b>vdbeapi.c</b> file contains external | ||
137 | interfaces to the virtual machine such as the | ||
138 | <b>sqlite3_bind_...</b> family of functions. Individual values | ||
139 | (strings, integer, floating point numbers, and BLOBs) are stored | ||
140 | in an internal object named "Mem" which is implemented by | ||
141 | <b>vdbemem.c</b>.</p> | ||
142 | |||
143 | <p> | ||
144 | SQLite implements SQL functions using callbacks to C-language routines. | ||
145 | Even the built-in SQL functions are implemented this way. Most of | ||
146 | the built-in SQL functions (ex: <b>coalesce()</b>, <b>count()</b>, | ||
147 | <b>substr()</b>, and so forth) can be found in <b>func.c</b>. | ||
148 | Date and time conversion functions are found in <b>date.c</b>. | ||
149 | </p> | ||
150 | |||
151 | <h3>B-Tree</h3> | ||
152 | |||
153 | <p>An SQLite database is maintained on disk using a B-tree implementation | ||
154 | found in the <b>btree.c</b> source file. A separate B-tree is used for | ||
155 | each table and index in the database. All B-trees are stored in the | ||
156 | same disk file. Details of the file format are recorded in a large | ||
157 | comment at the beginning of <b>btree.c</b>.</p> | ||
158 | |||
159 | <p>The interface to the B-tree subsystem is defined by the header file | ||
160 | <b>btree.h</b>. | ||
161 | </p> | ||
162 | |||
163 | <h3>Page Cache</h3> | ||
164 | |||
165 | <p>The B-tree module requests information from the disk in fixed-size | ||
166 | chunks. The default chunk size is 1024 bytes but can vary between 512 | ||
167 | and 65536 bytes. | ||
168 | The page cache is responsible for reading, writing, and | ||
169 | caching these chunks. | ||
170 | The page cache also provides the rollback and atomic commit abstraction | ||
171 | and takes care of locking of the database file. The | ||
172 | B-tree driver requests particular pages from the page cache and notifies | ||
173 | the page cache when it wants to modify pages or commit or rollback | ||
174 | changes and the page cache handles all the messy details of making sure | ||
175 | the requests are handled quickly, safely, and efficiently.</p> | ||
176 | |||
177 | <p>The code to implement the page cache is contained in the single C | ||
178 | source file <b>pager.c</b>. The interface to the page cache subsystem | ||
179 | is defined by the header file <b>pager.h</b>. | ||
180 | </p> | ||
181 | |||
182 | <h3>OS Interface</h3> | ||
183 | |||
184 | <p> | ||
185 | In order to provide portability between POSIX and Win32 operating systems, | ||
186 | SQLite uses an abstraction layer to interface with the operating system. | ||
187 | The interface to the OS abstraction layer is defined in | ||
188 | <b>os.h</b>. Each supported operating system has its own implementation: | ||
189 | <b>os_unix.c</b> for Unix, <b>os_win.c</b> for windows, and so forth. | ||
190 | Each of these operating-specific implements typically has its own | ||
191 | header file: <b>os_unix.h</b>, <b>os_win.h</b>, etc. | ||
192 | </p> | ||
193 | |||
194 | <h3>Utilities</h3> | ||
195 | |||
196 | <p> | ||
197 | Memory allocation and caseless string comparison routines are located | ||
198 | in <b>util.c</b>. | ||
199 | Symbol tables used by the parser are maintained by hash tables found | ||
200 | in <b>hash.c</b>. The <b>utf.c</b> source file contains Unicode | ||
201 | conversion subroutines. | ||
202 | SQLite has its own private implementation of <b>printf()</b> (with | ||
203 | some extensions) in <b>printf.c</b> and its own random number generator | ||
204 | in <b>random.c</b>. | ||
205 | </p> | ||
206 | |||
207 | <h3>Test Code</h3> | ||
208 | |||
209 | <p> | ||
210 | If you count regression test scripts, | ||
211 | more than half the total code base of SQLite is devoted to testing. | ||
212 | There are many <b>assert()</b> statements in the main code files. | ||
213 | In additional, the source files <b>test1.c</b> through <b>test5.c</b> | ||
214 | together with <b>md5.c</b> implement extensions used for testing | ||
215 | purposes only. The <b>os_test.c</b> backend interface is used to | ||
216 | simulate power failures to verify the crash-recovery mechanism in | ||
217 | the pager. | ||
218 | </p> | ||
219 | |||
220 | } | ||
221 | footer $rcsid | ||