From b0bf726fe37f936785ce0bc4ae1232b7c54d6ca4 Mon Sep 17 00:00:00 2001
From: drh
An SQLite database is maintained on disk using a B-tree implementation found in the btree.c source file. A separate B-tree is used for -each table and index in the database but all B-trees are stored in the -same disk file. Each page of a B-tree is 1024 bytes in size. The data -is stored with the key in an area called "payload". Up to 236 bytes of -payload can be stored with each B-tree entry. Any additional payload -is stored in a chain of overflow pages.
+each table and index in the database. All B-trees are stored in the +same disk file. Each page of a B-tree is 1024 bytes in size. The key +and data for an entry are stored together in an area called "payload". +Up to 236 bytes of payload can be stored on the same page as the B-tree +entry. Any additional payload is stored in a chain of overflow pages.The interface to the B-tree subsystem is defined by the header file btree.h. @@ -135,11 +135,11 @@ is stored in a chain of overflow pages.
The B-tree module requests information from the disk in 1024 byte chunks. The page cache is reponsible for reading, writing, and -caching these chunks for the B-tree module. +caching these chunks at the behest of the B-tree module. The page cache also provides the rollback and atomic commit abstraction and takes care of reader/writer locking of the database file. The B-tree driver requests particular pages from the page cache and notifies -the page cache when it wants to modify pages and commit or rollback its +the page cache when it wants to modify pages or commit or rollback changes and the page cache handles all the messy details of making sure the requests are handled quickly, safely, and efficiently.
diff --git a/www/c_interface.tcl b/www/c_interface.tcl index fdbd668fb9..c65f589188 100644 --- a/www/c_interface.tcl +++ b/www/c_interface.tcl @@ -1,7 +1,7 @@ # # Run this Tcl script to generate the sqlite.html file. # -set rcsid {$Id: c_interface.tcl,v 1.15 2001/09/20 01:44:43 drh Exp $} +set rcsid {$Id: c_interface.tcl,v 1.16 2001/09/28 23:11:24 drh Exp $} puts { @@ -41,22 +41,26 @@ int sqlite_exec( char **errmsg ); -#define SQLITE_OK 0 /* Successful result */ -#define SQLITE_ERROR 1 /* SQL error or missing database */ -#define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */ -#define SQLITE_PERM 3 /* Access permission denied */ -#define SQLITE_ABORT 4 /* Callback routine requested an abort */ -#define SQLITE_BUSY 5 /* One or more database files are locked */ -#define SQLITE_NOMEM 6 /* A malloc() failed */ -#define SQLITE_READONLY 7 /* Attempt to write a readonly database */ -#define SQLITE_INTERRUPT 8 /* Operation terminated by sqlite_interrupt() */ -#define SQLITE_IOERR 9 /* Some kind of disk I/O error occurred */ -#define SQLITE_CORRUPT 10 /* The database disk image is malformed */ -#define SQLITE_FULL 12 /* Insertion failed because database is full */ -#define SQLITE_CANTOPEN 13 /* Unable to open the database file */ -#define SQLITE_PROTOCOL 14 /* Database lock protocol error */ -#define SQLITE_SCHEMA 16 /* The database schema changed */ -#define SQLITE_TOOBIG 17 /* Too much data for one row of a table */ +#define SQLITE_OK 0 /* Successful result */ +#define SQLITE_ERROR 1 /* SQL error or missing database */ +#define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */ +#define SQLITE_PERM 3 /* Access permission denied */ +#define SQLITE_ABORT 4 /* Callback routine requested an abort */ +#define SQLITE_BUSY 5 /* The database file is locked */ +#define SQLITE_LOCKED 6 /* A table in the database is locked */ +#define SQLITE_NOMEM 7 /* A malloc() failed */ +#define SQLITE_READONLY 8 /* Attempt to write a readonly database */ +#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite_interrupt() */ +#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ +#define SQLITE_CORRUPT 11 /* The database disk image is malformed */ +#define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */ +#define SQLITE_FULL 13 /* Insertion failed because database is full */ +#define SQLITE_CANTOPEN 14 /* Unable to open the database file */ +#define SQLITE_PROTOCOL 15 /* Database lock protocol error */ +#define SQLITE_EMPTY 16 /* (Internal Only) Database table is empty */ +#define SQLITE_SCHEMA 17 /* The database schema changed */ +#define SQLITE_TOOBIG 18 /* Too much data for one row of a table */ +#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */Only the three core routines shown above are required to use @@ -259,6 +263,15 @@ database at the same time, but only one thread can have the database open for writing at the same time. Locking in SQLite is on the entire database.
+This return code is similar to SQLITE_BUSY in that it indicates +that the database is locked. But the source of the lock is a recursive +call to sqlite_exec(). This return can only occur if you attempt +to invoke sqlite_exec() from within a callback routine of a query +from a prior invocation of sqlite_exec(). Recursive calls to +sqlite_exec() are allowed as long as no more they all read-only or do +not attempt to write the same table. +
This value is returned if a call to malloc() fails.
This constant is returned if the SQL statement would have violated +a database constraint. +
-Precompiled binaries for Linux and Windows and the complete -source tree are available for download. -
-} - puts {A change history is available online. +The latest source code is +available for download. There are currently no known memory leaks or debilitating bugs -in the library. Gcov -is used to verify test coverage.
+in the library. + ++The file format used changed beginning with version 2.0.0. Version 1.0.X +of SQLite used GDBM as its database backend. Version 2.0.0 and later +use a built-in implementation of B-trees. If you have older 1.0 databases +you will need to convert them before they can be read using a 2.0 +release of SQLite. The following command will convert a legacy +database into the new 2.0 format: +
+ ++ ++echo .dump | sqlite1.0 old.db | sqlite2.0 new.db +
+The above command assumes that sqlite1.0 is sqlite version 1.0 +and sqlite2.0 is sqlite version 2.0. The old database is stored +in a directory named old.db and the new database is created in +the file new.db. +
@@ -75,8 +75,7 @@ the NDEBUG macro makes SQLite 2.0 run nearly twice as fast.
All tests are conducted on an otherwise quiescent machine. -A simple shell script generates and runs all the tests. -The shell script is named speedtest3.sh. +A simple shell script was used to generate and run all the tests. Each test reports three different times:
diff --git a/www/sqlite.tcl b/www/sqlite.tcl index 583a01f685..d8a23af3ed 100644 --- a/www/sqlite.tcl +++ b/www/sqlite.tcl @@ -1,7 +1,7 @@ # # Run this Tcl script to generate the sqlite.html file. # -set rcsid {$Id: sqlite.tcl,v 1.14 2001/09/28 18:14:17 drh Exp $} +set rcsid {$Id: sqlite.tcl,v 1.15 2001/09/28 23:11:24 drh Exp $} puts { @@ -28,8 +28,7 @@ the name the file that holds the SQLite database. If the file does not exist, a new one is created automatically. The sqlite program will then prompt you to enter SQL. Type in SQL statements (terminated by a -semicolon), press "Enter" and the SQL will be executed. It's as -simple as that! +semicolon), press "Enter" and the SQL will be executed.For example, to create a new SQLite database named "ex1" with a single table named "tbl1", you might do this:
@@ -48,6 +47,7 @@ proc Code {body} { Code { $ (((sqlite ex1))) +SQLite version 2.0.0 Enter ".help" for instructions sqlite> (((create table tbl1(one varchar(10), two smallint);))) sqlite> (((insert into tbl1 values('hello!',10);))) @@ -60,7 +60,7 @@ sqlite> puts {(In the example above, and in all subsequent examples, the commands -you type are underlined shown with a green tint and the responses +you type are underlined and shown with a green tint and the responses from the computer are shown in black without underlining.)
You can terminate the sqlite program by typing your systems @@ -85,31 +85,26 @@ sqlite> } puts { -
If you exit sqlite and look at the contents of the directory "ex1" -you'll see that it now contains two files: sqlite_master.tcl -and tbl1.tbl. The tbl1.tbl file contains all the -data for table "tbl1" in your database. The file -sqlite_master.tbl is a special table found on all SQLite -databases that records information about all other tables and -indices. In general, an SQLite database will contain one "*.tbl" -file for each table and index in your database, plus the extra -"sqlite_master.tbl" file used to store the database schema.
You can execute "SELECT" statements against the +
The database schema in an SQLite database is stored in +a special table named "sqlite_master". +You can execute "SELECT" statements against the special sqlite_master table just like any other table in an SQLite database. For example:
} Code { $ (((sqlite ex1))) +SQlite vresion 2.0.0 Enter ".help" for instructions sqlite> (((select * from sqlite_master;))) -type = table -name = tbl1 + type = table + name = tbl1 tbl_name = tbl1 -sql = create table tbl1(one varchar(10), two smallint) +rootpage = 3 + sql = create table tbl1(one varchar(10), two smallint) sqlite> } diff --git a/www/vdbe.tcl b/www/vdbe.tcl index 9e29fd2a63..95d5a8dc59 100644 --- a/www/vdbe.tcl +++ b/www/vdbe.tcl @@ -1,7 +1,7 @@ # # Run this Tcl script to generate the vdbe.html file. # -set rcsid {$Id: vdbe.tcl,v 1.6 2000/11/28 20:46:41 drh Exp $} +set rcsid {$Id: vdbe.tcl,v 1.7 2001/09/28 23:11:24 drh Exp $} puts { @@ -15,11 +15,15 @@ puts "(This page was last modified on [lrange $rcsid 3 4] GMT)
" -# puts { -#This document is -# currently under development. It is incomplete and contains -# errors. Use it accordingly.-# } +puts { +
+This document describes the +virtual machine used in SQLite version 1.0. It has not been +updated to reflect important changes that have occurred for +version 2.0. Some of the information presented below is +obsolete and/or incorrect. Use it accordingly. ++} puts {
If you want to know how the SQLite library works internally,