From 58f1c8b773835cfba8683d3ed058966581c4f6a3 Mon Sep 17 00:00:00 2001
From: drh [subst -novar -noback $t3] This document describes the architecture of the SQLite library.
-The information here is useful to those who want to understand or
-modify the inner workings of SQLite.
-
-A block diagram showing the main components of SQLite
-and how they interrelate is shown at the right. The text that
-follows will provide a quick overview of each of these components.
-
-This document describes SQLite version 3.0. Version 2.8 and
-earlier are similar but the details differ.
- Much of the public interface to the SQLite library is implemented by
-functions found in the main.c, legacy.c, and
-vdbeapi.c source files
-though some routines are
-scattered about in other files where they can have access to data
-structures with file scope. The
-sqlite3_get_table() routine is implemented in table.c.
-sqlite3_mprintf() is found in printf.c.
-sqlite3_complete() is in tokenize.c.
-The Tcl interface is implemented by tclsqlite.c. More
-information on the C interface to SQLite is
-available separately.
-
- To avoid name collisions with other software, all external
-symbols in the SQLite library begin with the prefix sqlite3.
-Those symbols that are intended for external use (in other words,
-those symbols which form the API for SQLite) begin
-with sqlite3_. When a string containing SQL statements is to be executed, the
-interface passes that string to the tokenizer. The job of the tokenizer
-is to break the original string up into tokens and pass those tokens
-one by one to the parser. The tokenizer is hand-coded in C in
-the file tokenize.c.
-
- Note that in this design, the tokenizer calls the parser. People
-who are familiar with YACC and BISON may be used to doing things the
-other way around -- having the parser call the tokenizer. The author
-of SQLite
-has done it both ways and finds things generally work out nicer for
-the tokenizer to call the parser. YACC has it backwards. The parser is the piece that assigns meaning to tokens based on
-their context. The parser for SQLite is generated using the
-Lemon LALR(1) parser
-generator. Lemon does the same job as YACC/BISON, but it uses
-a different input syntax which is less error-prone.
-Lemon also generates a parser which is reentrant and thread-safe.
-And lemon defines the concept of a non-terminal destructor so
-that it does not leak memory when syntax errors are encountered.
-The source file that drives Lemon is found in parse.y. Because
-lemon is a program not normally found on development machines, the
-complete source code to lemon (just one C file) is included in the
-SQLite distribution in the "tool" subdirectory. Documentation on
-lemon is found in the "doc" subdirectory of the distribution.
- After the parser assembles tokens into complete SQL statements,
-it calls the code generator to produce virtual machine code that
-will do the work that the SQL statements request. There are many
-files in the code generator:
-attach.c,
-auth.c,
-build.c,
-delete.c,
-expr.c,
-insert.c,
-pragma.c,
-select.c,
-trigger.c,
-update.c,
-vacuum.c
-and where.c.
-In these files is where most of the serious magic happens.
-expr.c handles code generation for expressions.
-where.c handles code generation for WHERE clauses on
-SELECT, UPDATE and DELETE statements. The files attach.c,
-delete.c, insert.c, select.c, trigger.c
-update.c, and vacuum.c handle the code generation
-for SQL statements with the same names. (Each of these files calls routines
-in expr.c and where.c as necessary.) All other
-SQL statements are coded out of build.c.
-The auth.c file implements the functionality of
-sqlite3_set_authorizer(). The program generated by the code generator is executed by
-the virtual machine. Additional information about the virtual
-machine is available separately.
-To summarize, the virtual machine implements an abstract computing
-engine specifically designed to manipulate database files. The
-machine has a stack which is used for intermediate storage.
-Each instruction contains an opcode and
-up to three additional operands. The virtual machine itself is entirely contained in a single
-source file vdbe.c. The virtual machine also has
-its own header files: vdbe.h that defines an interface
-between the virtual machine and the rest of the SQLite library and
-vdbeInt.h which defines structure private the virtual machine.
-The vdbeaux.c file contains utilities used by the virtual
-machine and interface modules used by the rest of the library to
-construct VM programs. The vdbeapi.c file contains external
-interfaces to the virtual machine such as the
-sqlite3_bind_... family of functions. Individual values
-(strings, integer, floating point numbers, and BLOBs) are stored
-in an internal object named "Mem" which is implemented by
-vdbemem.c.
-SQLite implements SQL functions using callbacks to C-language routines.
-Even the built-in SQL functions are implemented this way. Most of
-the built-in SQL functions (ex: coalesce(), count(),
-substr(), and so forth) can be found in func.c.
-Date and time conversion functions are found in date.c.
- 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. All B-trees are stored in the
-same disk file. Details of the file format are recorded in a large
-comment at the beginning of btree.c. The interface to the B-tree subsystem is defined by the header file
-btree.h.
- The B-tree module requests information from the disk in fixed-size
-chunks. The default chunk size is 1024 bytes but can vary between 512
-and 65536 bytes.
-The page cache is responsible for reading, writing, and
-caching these chunks.
-The page cache also provides the rollback and atomic commit abstraction
-and takes care of 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 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. The code to implement the page cache is contained in the single C
-source file pager.c. The interface to the page cache subsystem
-is defined by the header file pager.h.
-
-In order to provide portability between POSIX and Win32 operating systems,
-SQLite uses an abstraction layer to interface with the operating system.
-The interface to the OS abstraction layer is defined in
-os.h. Each supported operating system has its own implementation:
-os_unix.c for Unix, os_win.c for windows, and so forth.
-Each of these operating-specific implements typically has its own
-header file: os_unix.h, os_win.h, etc.
-
-Memory allocation and caseless string comparison routines are located
-in util.c.
-Symbol tables used by the parser are maintained by hash tables found
-in hash.c. The utf.c source file contains Unicode
-conversion subroutines.
-SQLite has its own private implementation of printf() (with
-some extensions) in printf.c and its own random number generator
-in random.c.
-
-If you count regression test scripts,
-more than half the total code base of SQLite is devoted to testing.
-There are many assert() statements in the main code files.
-In additional, the source files test1.c through test5.c
-together with md5.c implement extensions used for testing
-purposes only. The os_test.c backend interface is used to
-simulate power failures to verify the crash-recovery mechanism in
-the pager.
- je8cuEBVlxblVh7#L<7s(p)xVe5X^@|LQpPk2SOa+|nd
zTek&Cg3$C(x^*jX%eR!P1b>UDQn7#AC@n8$E|I$$p8L6&vA8rEw}{KSP!PJS+oZ57
zs8}ky5$U=|db@#|ySi(Uyc?maQM
-(This page was last modified on [lrange $rcsid 3 4] UTC)
-
-A security audit for SQLite consists of two components. First, there is
-a check for common errors that often lead to security problems. Second,
-an attempt is made to construct a proof that SQLite has certain desirable
-security properties.
-
-Scan all source code and check for the following common errors:
-
-Verify that the destination buffer is large enough to hold its result
-in every call to the following routines:
-
-Verify that pointers returned by subroutines are not NULL before using
-the pointers. In particular, make sure the return values for the following
-routines are checked before they are used:
-
"
-}
-proc SYNTAX {text} {
- puts ""
- puts $text
- puts "
"
-}
-proc IMAGE {name {caption {}}} {
- puts ""
- set t2 [string map {& & < < > >} $text]
- regsub -all "/(\[^\n/\]+)/" $t2 {\1} t3
- puts "$t3"
- puts "
"
- if {$caption!=""} {
- puts "
$caption"
- }
- puts "
-
-}
-PARAGRAPH {
- Of these changes, only 1a and 2a through 2c are incompatibilities
- in any formal sense.
- But users who have previously made custom modifications to the
- SQLite source (for example to add a custom OS layer for embedded
- hardware) might find that these changes have a larger impact.
- On the other hand, an important goal of these changes is to make
- it much easier to customize SQLite for use on different operating
- systems.
-}
-
-HEADING 1 {The OS Interface Layer}
-
-PARAGRAPH {
- If your system defines a custom OS interface for SQLite or if you
- were using the undocumented sqlite3_os_switch()
- interface, then you will need to make modifications in order to
- upgrade to SQLite version 3.5.0. This may seem painful at first
- glance. But as you look more closely, you will probably discover
- that your changes are made smaller and easier to understand and manage
- by the new SQLite interface. It is likely that your changes will
- now also work seamlessly with the SQLite amalgamation. You will
- no longer need to make any changes to the code SQLite source code.
- All of your changes can be effected by application code and you can
- link against a standard, unmodified version of the SQLite amalgamation.
- Furthermore, the OS interface layer, which was formerly undocumented,
- is now an officially support interface for SQLite. So you have
- some assurance that this will be a one-time change and that your
- new backend will continue to work in future versions of SQLite.
-}
-
-HEADING 2 {The Virtual File System Object}
-
-PARAGRAPH {
- The new OS interface for SQLite is built around an object named
- [sqlite3_vfs]. The "vfs" standard for "Virtual File System".
- The sqlite3_vfs object is basically a structure containing pointers
- to functions that implement the primitive disk I/O operations that
- SQLite needs to perform in order to read and write databases.
- In this article, we will often refer a sqlite3_vfs objects as a "VFS".
-}
-
-PARAGRAPH {
- SQLite is able to use multiple VFSes at the same time. Each
- individual database connection is associated with just one VFS.
- But if you have multiple database connections, each connection
- can be associated with a different VFS.
-}
-
-PARAGRAPH {
- There is always a default VFS.
- The legacy interfaces [sqlite3_open()] and [sqlite3_open16()] always
- use the default VFS.
- The new interface for creating database connections,
- [sqlite3_open_v2()], allows you to specify which VFS you want to
- use by name.
-}
-
-HEADING 3 {Registering New VFS Objects}
-
-PARAGRAPH {
- Standard builds of SQLite for unix or windows come with a single
- VFS named "unix" or "win32", as appropriate. This one VFS is also
- the default. So if you are using the legacy open functions, everything
- will continue to operate as it has before. The change is that an application
- now has the flexibility of adding new VFS modules to implement a
- customized OS layer. The [sqlite3_vfs_register()] API can be used
- to tell SQLite about one or more application-defined VFS modules:
-}
-
-CODE {
-int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
-}
-
-PARAGRAPH {
- Applications can call sqlite3_vfs_register at any time, though of course
- a VFS needs to be registered before it can be used. The first argument
- is a pointer to a customized VFS object that the application has prepared.
- The second argument is true to make the new VFS the default VFS so that
- it will be used by the legacy [sqlite3_open()] and [sqlite3_open16()] APIs.
- If the new VFS is not the default, then you will probably have to use
- the new [sqlite3_open_v2()] API to use it. Note, however, that if
- a new VFS is the only VFS known to SQLite (if SQLite was compiled without
- its usual default VFS or if the pre-compiled default VFS was removed
- using [sqlite3_vfs_unregister()]) then the new VFS automatic becomes the
- default VFS regardless of the makeDflt argument to [sqlite3_vfs_register()].
-}
-
-PARAGRAPH {
- Standard builds include the default "unix" or "win32" VFSes.
- But if you use the -DOS_OTHER=1 compile-time option, then SQLite is
- built without a default VFS. In that case, the application must
- register at least one VFS prior to calling [sqlite3_open()].
- This is the approach that embedded applications should use.
- Rather than modifying the SQLite source to to insert an alternative
- OS layer as was done in prior releases of SQLite, instead compile
- an unmodified SQLite source file (preferably the amalgamation)
- with the -DOS_OTHER=1 option, then invoke [sqlite3_vfs_register()]
- to define the interface to the underlying filesystem prior to
- creating any database connections.
-}
-
-HEADING 3 {Additional Control Over VFS Objects}
-
-PARAGRAPH {
- The [sqlite3_vfs_unregister()] API is used to remove an existing
- VFS from the system.
-}
-
-CODE {
-int sqlite3_vfs_unregister(sqlite3_vfs*);
-}
-
-PARAGRAPH {
- The [sqlite3_vfs_find()] API is used to locate a particular VFS
- by name. Its prototype is as follows:
-}
-
-CODE {
-sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
-}
-
-PARAGRAPH {
- The argument is the symbolic name for the desired VFS. If the
- argument is a NULL pointer, then the default VFS is returned.
- The function returns a pointer to the [sqlite3_vfs] object that
- implements the VFS. Or it returns a NULL pointer if no object
- could be found that matched the search criteria.
-}
-
-HEADING 3 {Modifications Of Existing VFSes}
-
-PARAGRAPH {
- Once a VFS has been registered, it should never be modified. If
- a change in behavior is required, a new VFS should be registered.
- The application could, perhaps, use [sqlite3_vfs_find()] to locate
- the old VFS, make a copy of the old VFS into a new [sqlite3_vfs]
- object, make the desired modifications to the new VFS, unregister
- the old VFS, the register the new VFS in its place. Existing
- database connections would continue to use the old VFS even after
- it is unregistered, but new database connections would use the
- new VFS.
-}
-
-HEADING 3 {The VFS Object}
-
-PARAGRAPH {
- A VFS object is an instance of the following structure:
-}
-
-CODE {
-typedef struct sqlite3_vfs sqlite3_vfs;
-struct sqlite3_vfs {
- int iVersion; /* Structure version number */
- int szOsFile; /* Size of subclassed sqlite3_file */
- int mxPathname; /* Maximum file pathname length */
- sqlite3_vfs *pNext; /* Next registered VFS */
- const char *zName; /* Name of this virtual file system */
- void *pAppData; /* Pointer to application-specific data */
- int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
- int flags, int *pOutFlags);
- int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
- int (*xAccess)(sqlite3_vfs*, const char *zName, int flags);
- int (*xGetTempName)(sqlite3_vfs*, char *zOut);
- int (*xFullPathname)(sqlite3_vfs*, const char *zName, char *zOut);
- void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
- void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
- void *(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol);
- void (*xDlClose)(sqlite3_vfs*, void*);
- int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
- int (*xSleep)(sqlite3_vfs*, int microseconds);
- int (*xCurrentTime)(sqlite3_vfs*, double*);
- /* New fields may be appended in figure versions. The iVersion
- ** value will increment whenever this happens. */
-};
-}
-
-PARAGRAPH {
- To create a new VFS, an application fills in an instance of this
- structure with appropriate values and then calls [sqlite3_vfs_register()].
-}
-
-PARAGRAPH {
- The iVersion field of [sqlite3_vfs] should be 1 for SQLite version 3.5.0.
- This number may increase in future versions of SQLite if we have to
- modify the VFS object in some way. We hope that this never happens,
- but the provision is made in case it does.
-}
-
-PARAGRAPH {
- The szOsFile field is the size in bytes of the structure that defines
- an open file: the [sqlite3_file] object. This object will be described
- more fully below. The point here is that each VFS implementation can
- define its own [sqlite3_file] object containing whatever information
- the VFS implementation needs to store about an open file. SQLite needs
- to know how big this object is, however, in order to preallocate enough
- space to hold it.
-}
-
-PARAGRAPH {
- The mxPathname field is the maximum length of a file pathname that
- this VFS can use. SQLite sometimes has to preallocate buffers of
- this size, so it should be as small as reasonably possible. Some
- filesystems permit huge pathnames, but in practice pathnames rarely
- extend beyond 100 bytes or so. You do not have to put the longest
- pathname that the underlying filesystem can handle here. You only
- have to put the longest pathname that you want SQLite to be able to
- handle. A few hundred is a good value in most cases.
-}
-
-PARAGRAPH {
- The pNext field is used internally by SQLite. Specifically, SQLite
- uses this field to form a linked list of registered VFSes.
-}
-
-PARAGRAPH {
- The zName field is the symbolic name of the VFS. This is the name
- that the [sqlite3_vfs_find()] compares against when it is looking for
- a VFS.
-}
-
-PARAGRAPH {
- The pAppData pointer is unused by the SQLite core. The pointer is
- available to store auxiliary information that a VFS information might
- want to carry around.
-}
-
-PARAGRAPH {
- The remaining fields of the [sqlite3_vfs] object all store pointer
- to functions that implement primitive operations. We call these
- "methods". The first methods, xOpen, is used to open files on
- the underlying storage media. The result is an [sqlite3_file]
- object. There are additional methods, defined by the [sqlite3_file]
- object itself that are used to read and write and close the file.
- The additional methods are detailed below. The filename is in UTF-8.
- SQLite will guarantee that the zFilename string passed to
- xOpen() is a full pathname as generated by xFullPathname() and
- that the string will be valid and unchanged until xClose() is
- called. So the [sqlite3_file] can store a pointer to the
- filename if it needs to remember the filename for some reason.
- The flags argument to xOpen() is a copy of the flags argument
- to sqlite3_open_v2(). If sqlite3_open() or sqlite3_open16()
- is used, then flags is [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
- If xOpen() opens a file read-only then it sets *pOutFlags to
- include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be
- set.
- SQLite will also add one of the following flags to the xOpen()
- call, depending on the object being opened:
-
-
-
-
- The file I/O implementation can use the object type flags to
- changes the way it deals with files. For example, an application
- that does not care about crash recovery or rollback, might make
- the open of a journal file a no-op. Writes to this journal are
- also a no-op. Any attempt to read the journal returns [SQLITE_IOERR].
- Or the implementation might recognize the a database file will
- be doing page-aligned sector reads and writes in a random order
- and set up its I/O subsystem accordingly.
- SQLite might also add one of the following flags to the xOpen
- method:
-
-
- The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
- deleted when it is closed. This will always be set for TEMP
- databases and journals and for subjournals. The
- [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened
- for exclusive access. This flag is set for all files except
- for the main database file.
- The [sqlite3_file] structure passed as the third argument to
- xOpen is allocated by the caller. xOpen just fills it in. The
- caller allocates a minimum of szOsFile bytes for the [sqlite3_file]
- structure.
-}
-
-PARAGRAPH {
- The differences between an [SQLITE_OPEN_TEMP_DB] database and an
- [SQLITE_OPEN_TRANSIENT_DB] database is this: The [SQLITE_OPEN_TEMP_DB]
- is used for explicitly declared and named TEMP tables (using the
- CREATE TEMP TABLE syntax) or for named tables in a temporary database
- that is created by opening a database with a filename that is an empty
- string. An [SQLITE_OPEN_TRANSIENT_DB] holds an database table that
- SQLite creates automatically in order to evaluate a subquery or
- ORDER BY or GROUP BY clause. Both TEMP_DB and TRANSIENT_DB databases
- are private and are deleted automatically. TEMP_DB databases last
- for the duration of the database connection. TRANSIENT_DB databases
- last only for the duration of a single SQL statement.
-}
-
-PARAGRAPH {
- The xDelete method is used delete a file. The name of the file is
- given in the second parameter. The filename will be in UTF-8.
- The VFS must convert the filename into whatever character representation
- the underlying operating system expects. If the syncDir parameter is
- true, then the xDelete method should not return until the change
- to the directory contents for the directory containing the
- deleted file have been synced to disk in order to insure that the
- file does not "reappear" if a power failure occurs soon after.
-}
-
-PARAGRAPH {
- The xAccess method is used to check for access permissions on a file.
- The filename will be UTF-8 encoded. The flags argument will be
- [SQLITE_ACCESS_EXISTS] to check for the existence of the file,
- [SQLITE_ACCESS_READWRITE] to check to see if the file is both readable
- and writable, or [SQLITE_ACCESS_READ] to check to see if the file is
- at least readable. The "file" named by the second parameter might
- be a directory or folder name.
-}
-
-PARAGRAPH {
- The xGetTempName method computes the name of a temporary file that
- SQLite can use. The name should be written into the buffer given
- by the second parameter. SQLite will size that buffer to hold
- at least mxPathname bytes. The generated filename should be in UTF-8.
- To avoid security problems, the generated temporary filename should
- contain enough randomness to prevent an attacker from guessing the
- temporary filename in advance.
-}
-
-PARAGRAPH {
- The xFullPathname method is used to convert a relative pathname
- into a full pathname. The resulting full pathname is written into
- the buffer provided by the third parameter. SQLite will size the
- output buffer to at least mxPathname bytes. Both the input and
- output names should be in UTF-8.
-}
-
-PARAGRAPH {
- The xDlOpen, xDlError, xDlSym, and xDlClose methods are all used for
- accessing shared libraries at run-time. These methods may be omitted
- (and their pointers set to zero) if the library is compiled with
- SQLITE_OMIT_LOAD_EXTENSION or if the [sqlite3_enable_load_extension()]
- interface is never used to enable dynamic extension loading. The
- xDlOpen method opens a shared library or DLL and returns a pointer to
- a handle. NULL is returned if the open fails. If the open fails,
- the xDlError method can be used to obtain a text error message.
- The message is written into the zErrMsg buffer of the third parameter
- which is at least nByte bytes in length. The xDlSym returns a pointer
- to a symbol in the shared library. The name of the symbol is given
- by the second parameter. UTF-8 encoding is assumed. If the symbol
- is not found a NULL pointer is returned. The xDlClose routine closes
- the shared library.
-}
-
-PARAGRAPH {
- The xRandomness method is used exactly once to initialize the
- pseudo-random number generator (PRNG) inside of SQLite. Only
- the xRandomness method on the default VFS is used. The xRandomness
- methods on other VFSes are never accessed by SQLite.
- The xRandomness routine requests that nByte bytes of randomness
- be written into zOut. The routine returns the actual number of
- bytes of randomness obtained. The quality of the randomness so obtained
- will determine the quality of the randomness generated by built-in
- SQLite functions such as random() and randomblob(). SQLite also
- uses its PRNG to generate temporary file names.. On some platforms
- (ex: windows) SQLite assumes that temporary file names are unique
- without actually testing for collisions, so it is important to have
- good-quality randomness even if the random() and randomblob()
- functions are never used.
-}
-
-PARAGRAPH {
- The xSleep method is used to suspend the calling thread for at
- least the number of microseconds given. This method is used to
- implement the [sqlite3_sleep()] and [sqlite3_busy_timeout()] APIs.
- In the case of [sqlite3_sleep()] the xSleep method of the default
- VFS is always used. If the underlying system does not have a
- microsecond resolution sleep capability, then the sleep time should
- be rounded up. xSleep returns this rounded-up value.
-}
-
-PARAGRAPH {
- The xCurrentTime method finds the current time and date and writes
- the result as double-precision floating point value into pointer
- provided by the second parameter. The time and date is in
- coordinated universal time (UTC) and is a fractional julian day number.
-}
-
-HEADING 3 {The Open File Object}
-
-PARAGRAPH {
- The result of opening a file is an instance of an [sqlite3_file] object.
- The [sqlite3_file] object is an abstract base class defined as follows:
-}
-
-CODE {
-typedef struct sqlite3_file sqlite3_file;
-struct sqlite3_file {
- const struct sqlite3_io_methods *pMethods;
-};
-}
-
-PARAGRAPH {
- Each VFS implementation will subclass the [sqlite3_file] by adding
- additional fields at the end to hold whatever information the VFS
- needs to know about an open file. It does not matter what information
- is stored as long as the total size of the structure does not exceed
- the szOsFile value recorded in the [sqlite3_vfs] object.
-}
-
-PARAGRAPH {
- The [sqlite3_io_methods] object is a structure that contains pointers
- to methods for reading, writing, and otherwise dealing with files.
- This object is defined as follows:
-}
-
-CODE {
-typedef struct sqlite3_io_methods sqlite3_io_methods;
-struct sqlite3_io_methods {
- int iVersion;
- int (*xClose)(sqlite3_file*);
- int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
- int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
- int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
- int (*xSync)(sqlite3_file*, int flags);
- int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
- int (*xLock)(sqlite3_file*, int);
- int (*xUnlock)(sqlite3_file*, int);
- int (*xCheckReservedLock)(sqlite3_file*);
- int (*xFileControl)(sqlite3_file*, int op, void *pArg);
- int (*xSectorSize)(sqlite3_file*);
- int (*xDeviceCharacteristics)(sqlite3_file*);
- /* Additional methods may be added in future releases */
-};
-}
-
-PARAGRAPH {
- The iVersion field of [sqlite3_io_methods] is provided as insurance
- against future enhancements. The iVersion value should always be
- 1 for SQLite version 3.5.
-}
-
-PARAGRAPH {
- The xClose method closes the file. The space for the [sqlite3_file]
- structure is deallocated by the caller. But if the [sqlite3_file]
- contains pointers to other allocated memory or resources, those
- allocations should be released by the xClose method.
-}
-
-PARAGRAPH {
- The xRead method reads iAmt bytes from the file beginning at a byte
- offset to iOfst. The data read is stored in the pointer of the
- second parameter. xRead returns the [SQLITE_OK] on success,
- [SQLITE_IOERR_SHORT_READ] if it was not able to read the full number
- of bytes because it reached end-of-file, or [SQLITE_IOERR_READ] for
- any other error.
-}
-
-PARAGRAPH {
- The xWrite method writes iAmt bytes of data from the second parameter
- into the file beginning at an offset of iOfst bytes. If the size of
- the file is less than iOfst bytes prior to the write, then xWrite should
- ensure that the file is extended with zeros up to iOfst bytes prior
- to beginning its write. xWrite continues to extends the file as
- necessary so that the size of the file is at least iAmt+iOfst bytes
- at the conclusion of the xWrite call. The xWrite method returns
- [SQLITE_OK] on success. If the write cannot complete because the
- underlying storage medium is full, then [SQLITE_FULL] is returned.
- [SQLITE_IOERR_WRITE] should be returned for any other error.
-}
-
-PARAGRAPH {
- The xTruncate method truncates a file to be nByte bytes in length.
- If the file is already nByte bytes or less in length then this
- method is a no-op. The xTruncate method returns [SQLITE_OK] on
- success and [SQLITE_IOERR_TRUNCATE] if anything goes wrong.
-}
-
-PARAGRAPH {
- The xSync method is used to force previously written data out of
- operating system cache and into non-volatile memory. The second
- parameter is usually [SQLITE_SYNC_NORMAL]. If the second parameter
- is [SQLITE_SYNC_FULL] then the xSync method should make sure that
- data has also been flushed through the disk controllers cache.
- The [SQLITE_SYNC_FULL] parameter is the equivalent of the F_FULLSYNC
- ioctl() on Mac OS X. The xSync method returns
- [SQLITE_OK] on success and [SQLITE_IOERR_FSYNC] if anything goes wrong.
-}
-
-PARAGRAPH {
- The xFileSize() method determines the current size of the file
- in bytes and writes that value into *pSize. It returns [SQLITE_OK]
- on success and [SQLITE_IOERR_FSTAT] if something goes wrong.
-}
-
-PARAGRAPH {
- The xLock and xUnlock methods are used to set and clear file locks.
- SQLite supports five levels of file locks, in order:
-
-
- The underlying implementation can support some subset of these locking
- levels as long as it meets the other requirements of this paragraph.
- The locking level is specified as the second argument to both xLock
- and xUnlock. The xLock method increases the locking level to the
- specified locking level or higher. The xUnlock method decreases the
- locking level to no lower than the level specified.
- [SQLITE_LOCK_NONE] means that the file is unlocked. [SQLITE_LOCK_SHARED]
- gives permission to read the file. Multiple database connections can
- hold [SQLITE_LOCK_SHARED] at the same time.
- [SQLITE_LOCK_RESERVED] is like [SQLITE_LOCK_SHARED] in that its is permission
- to read the file. But only a single connection can hold a reserved lock
- at any point in time. The [SQLITE_LOCK_PENDING] is also permission to
- read the file. Other connections can continue to read the file as well,
- but no other connection is allowed to escalate a lock from none to shared.
- [SQLITE_LOCK_EXCLUSIVE] is permission to write on the file. Only a single
- connection can hold an exclusive lock and no other connection can hold
- any lock (other than "none") while one connection is hold an exclusive
- lock. The xLock returns [SQLITE_OK] on success, [SQLITE_BUSY] if it
- is unable to obtain the lock, or [SQLITE_IOERR_RDLOCK] if something else
- goes wrong. The xUnlock method returns [SQLITE_OK] on success and
- [SQLITE_IOERR_UNLOCK] for problems.
-}
-
-PARAGRAPH {
- The xCheckReservedLock method checks to see if another connection or
- another process is currently holding a reserved, pending, or exclusive
- lock on the file. It returns true or false.
-}
-
-PARAGRAPH {
- The xFileControl() method is a generic interface that allows custom
- VFS implementations to directly control an open file using the
- (new and experimental)
- [sqlite3_file_control()] interface. The second "op" argument
- is an integer opcode. The third
- argument is a generic pointer which is intended to be a pointer
- to a structure that may contain arguments or space in which to
- write return values. Potential uses for xFileControl() might be
- functions to enable blocking locks with timeouts, to change the
- locking strategy (for example to use dot-file locks), to inquire
- about the status of a lock, or to break stale locks. The SQLite
- core reserves opcodes less than 100 for its own use.
- A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
- Applications that define a custom xFileControl method should use opcodes
- greater than 100 to avoid conflicts.
-}
-
-PARAGRAPH {
- The xSectorSize returns the "sector size" of the underlying
- non-volatile media. A "sector" is defined as the smallest unit of
- storage that can be written without disturbing adjacent storage.
- On a disk drive the "sector size" has until recently been 512 bytes,
- though there is a push to increase this value to 4KiB. SQLite needs
- to know the sector size so that it can write a full sector at a
- time, and thus avoid corrupting adjacent storage space if a power
- lose occurs in the middle of a write.
-}
-
-PARAGRAPH {
- The xDeviceCharacteristics method returns an integer bit vector that
- defines any special properties that the underlying storage medium might
- have that SQLite can use to increase performance. The allowed return
- is the bit-wise OR of the following values:
-
-
- The [SQLITE_IOCAP_ATOMIC] bit means that all writes to this device are
- atomic in the sense that either the entire write occurs or none of it
- occurs. The other
- [SQLITE_IOCAP_ATOMIC | SQLITE_IOCAP_ATOMICnnn] values indicate that
- writes of aligned blocks of the indicated size are atomic.
- [SQLITE_IOCAP_SAFE_APPEND] means that when extending a file with new
- data, the new data is written first and then the file size is updated.
- So if a power failure occurs, there is no chance that the file might have
- been extended with randomness. The [SQLITE_IOCAP_SEQUENTIAL] bit means
- that all writes occur in the order that they are issued and are not
- reordered by the underlying file system.
-}
-
-HEADING 3 {Checklist For Constructing A New VFS}
-
-PARAGRAPH {
- The preceding paragraphs contain a lot of information.
- To ease the task of constructing
- a new VFS for SQLite we offer the following implementation checklist:
-}
-
-PARAGRAPH {
-
-
-}
-
-PARAGRAPH {
- Within your application, call the procedure implemented in the last
- step above as part of your initialization process before any
- database connections are opened.
-}
-
-HEADING 1 {The Memory Allocation Subsystem}
-
-PARAGRAPH {
- Beginning with version 3.5, SQLite obtains all of the heap memory it
- needs using the routines [sqlite3_malloc()], [sqlite3_free()], and
- [sqlite3_realloc()]. These routines have existed in prior versions
- of SQLite, but SQLite has previously bypassed these routines and used
- its own memory allocator. This all changes in version 3.5.0.
-}
-
-PARAGRAPH {
- The SQLite source tree actually contains multiple versions of the
- memory allocator. The default high-speed version found in the
- "mem1.c" source file is used for most builds. But if the SQLITE_MEMDEBUG
- flag is enabled, a separate memory allocator the "mem2.c" source file
- is used instead. The mem2.c allocator implements lots of hooks to
- do error checking and to simulate memory allocation failures for testing
- purposes. Both of these allocators use the malloc()/free() implementation
- in the standard C library.
-}
-
-PARAGRAPH {
- Applications are not required to use either of these standard memory
- allocators. If SQLite is compiled with SQLITE_OMIT_MEMORY_ALLOCATION
- then no implementation for the [sqlite3_malloc()], [sqlite3_realloc()],
- and [sqlite3_free()] functions is provided. Instead, the application
- that links against SQLite must provide its own implementation of these
- functions. The application provided memory allocator is not required
- to use the malloc()/free() implementation in the standard C library.
- An embedded application might provide an alternative memory allocator
- that uses memory for a fixed memory pool set aside for the exclusive
- use of SQLite, for example.
-}
-
-PARAGRAPH {
- Applications that implement their own memory allocator must provide
- implementation for the usual three allocation functions
- [sqlite3_malloc()], [sqlite3_realloc()], and [sqlite3_free()].
- And they must also implement a fourth function:
-}
-
-CODE {
-int sqlite3_memory_alarm(
- void(*xCallback)(void *pArg, sqlite3_int64 used, int N),
- void *pArg,
- sqlite3_int64 iThreshold
-);
-}
-
-PARAGRAPH {
- The [sqlite3_memory_alarm] routine is used to register
- a callback on memory allocation events.
- This routine registers or clears a callbacks that fires when
- the amount of memory allocated exceeds iThreshold. Only
- a single callback can be registered at a time. Each call
- to [sqlite3_memory_alarm()] overwrites the previous callback.
- The callback is disabled by setting xCallback to a NULL
- pointer.
-}
-
-PARAGRAPH {
- The parameters to the callback are the pArg value, the
- amount of memory currently in use, and the size of the
- allocation that provoked the callback. The callback will
- presumably invoke [sqlite3_free()] to free up memory space.
- The callback may invoke [sqlite3_malloc()] or [sqlite3_realloc()]
- but if it does, no additional callbacks will be invoked by
- the recursive calls.
-}
-
-PARAGRAPH {
- The [sqlite3_soft_heap_limit()] interface works by registering
- a memory alarm at the soft heap limit and invoking
- [sqlite3_release_memory()] in the alarm callback. Application
- programs should not attempt to use the [sqlite3_memory_alarm()]
- interface because doing so will interfere with the
- [sqlite3_soft_heap_limit()] module. This interface is exposed
- only so that applications can provide their own
- alternative implementation when the SQLite core is
- compiled with SQLITE_OMIT_MEMORY_ALLOCATION.
-}
-
-PARAGRAPH {
- The built-in memory allocators in SQLite also provide the following
- additional interfaces:
-}
-
-CODE {
-sqlite3_int64 sqlite3_memory_used(void);
-sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
-}
-
-PARAGRAPH {
- These interfaces can be used by an application to monitor how
- much memory SQLite is using. The [sqlite3_memory_used()] routine
- returns the number of bytes of memory currently in use and the
- [sqlite3_memory_highwater()] returns the maximum instantaneous
- memory usage. Neither routine includes the overhead associated
- with the memory allocator. These routines are provided for use
- by the application. SQLite never invokes them itself. So if
- the application is providing its own memory allocation subsystem,
- it can omit these interfaces if desired.
-}
-
-HEADING 1 {The Mutex Subsystem}
-
-PARAGRAPH {
- SQLite has always been threadsafe in the sense that it is safe to
- use different SQLite database connections in different threads at the
- same time. The constraint was that the same database connection
- could not be used in two separate threads at once. SQLite version 3.5.0
- relaxes this constraint.
-}
-
-PARAGRAPH {
- In order to allow multiple threads to use the same database connection
- at the same time, SQLite must make extensive use of mutexes. And for
- this reason a new mutex subsystem as been added. The mutex subsystem
- as the following interface:
-}
-
-CODE {
-sqlite3_mutex *sqlite3_mutex_alloc(int);
-void sqlite3_mutex_free(sqlite3_mutex*);
-void sqlite3_mutex_enter(sqlite3_mutex*);
-int sqlite3_mutex_try(sqlite3_mutex*);
-void sqlite3_mutex_leave(sqlite3_mutex*);
-}
-
-PARAGRAPH {
- Though these routines exist for the use of the SQLite core,
- application code is free to use these routines as well, if desired.
- A mutex is an [sqlite3_mutex] object. The [sqlite3_mutex_alloc()]
- routine allocates a new mutex object and returns a pointer to it.
- The argument to [sqlite3_mutex_alloc()] should be
- [SQLITE_MUTEX_FAST] or [SQLITE_MUTEX_RECURSIVE] for non-recursive
- and recursive mutexes, respectively. If the underlying system does
- not provide non-recursive mutexes, then a recursive mutex can be
- substituted in that case. The argument to [sqlite3_mutex_alloc()]
- can also be a constant designating one of several static mutexes:
-
-
- These static mutexes are reserved for use internally by SQLite
- and should not be used by the application. The static mutexes
- are all non-recursive.
-}
-
-PARAGRAPH {
- The [sqlite3_mutex_free()] routine should be used to deallocate
- a non-static mutex. If a static mutex is passed to this routine
- then the behavior is undefined.
-}
-
-PARAGRAPH {
- The [sqlite3_mutex_enter()] attempts to enter the mutex and blocks
- if another threads is already there. [sqlite3_mutex_try()] attempts
- to enter and returns [SQLITE_OK] on success or [SQLITE_BUSY] if another
- thread is already there. [sqlite3_mutex_leave()] exits a mutex.
- The mutex is held until the number of exits matches the number of
- entrances. If [sqlite3_mutex_leave()] is called on a mutex that
- the thread is not currently holding, then the behavior is undefined.
- If any routine is called for a deallocated mutex, then the behavior
- is undefined.
-}
-
-PARAGRAPH {
- The SQLite source code provides multiple implementations of these
- APIs, suitable for varying environments. If SQLite is compiled with
- the SQLITE_THREADSAFE=0 flag then a no-op mutex implementation that
- is fast but does no real mutual exclusion is provided. That
- implementation is suitable for use in single-threaded applications
- or applications that only use SQLite in a single thread. Other
- real mutex implementations are provided based on the underlying
- operating system.
-}
-
-PARAGRAPH {
- Embedded applications may wish to provide their own mutex implementation.
- If SQLite is compiled with the -DSQLITE_MUTEX_APPDEF=1 compile-time flag
- then the SQLite core provides no mutex subsystem and a mutex subsystem
- that matches the interface described above must be provided by the
- application that links against SQLite.
-}
-
-HEADING 1 {Other Interface Changes}
-
-PARAGRAPH {
- Version 3.5.0 of SQLite changes the behavior of a few APIs in ways
- that are technically incompatible. However, these APIs are seldom
- used and even when they are used it is difficult to imagine a
- scenario where the change might break something. The changes
- actually makes these interface much more useful and powerful.
-}
-
-PARAGRAPH {
- Prior to version 3.5.0, the [sqlite3_enable_shared_cache()] API
- would enable and disable the shared cache feature for all connections
- within a single thread - the same thread from which the
- sqlite3_enable_shared_cache() routine was called. Database connections
- that used the shared cache were restricted to running in the same
- thread in which they were opened. Beginning with version 3.5.0,
- the sqlite3_enable_shared_cache() applies to all database connections
- in all threads within the process. Now database connections running
- in separate threads can share a cache. And database connections that
- use shared cache can migrate from one thread to another.
-}
-
-PARAGRAPH {
- Prior to version 3.5.0 the [sqlite3_soft_heap_limit()] set an upper
- bound on heap memory usage for all database connections within a
- single thread. Each thread could have its own heap limit. Beginning
- in version 3.5.0, there is a single heap limit for the entire process.
- This seems more restrictive (one limit as opposed to many) but in
- practice it is what most users want.
-}
-
-PARAGRAPH {
- Prior to version 3.5.0 the [sqlite3_release_memory()] function would
- try to reclaim memory from all database connections in the same thread
- as the sqlite3_release_memory() call. Beginning with version 3.5.0,
- the sqlite3_release_memory() function will attempt to reclaim memory
- from all database connections in all threads.
-}
-
-HEADING 1 {Summary}
-
-PARAGRAPH {
- The transition from SQLite version 3.4.2 to 3.5.0 is a major change.
- Every source code file in the SQLite core had to be modified, some
- extensively. And the change introduced some minor incompatibilities
- in the C interface. But we feel that the benefits of the transition
- from 3.4.2 to 3.5.0 far outweigh the pain of porting. The new
- VFS layer is now well-defined and stable and should simplify future
- customizations. The VFS layer, and the separable memory allocator
- and mutex subsystems allow a standard SQLite source code amalgamation
- to be used in an embedded project without change, greatly simplifying
- configuration management. And the resulting system is much more
- tolerant of highly threaded designs.
-}
diff --git a/www/arch.fig b/www/arch.fig
deleted file mode 100644
index d127a276e9..0000000000
--- a/www/arch.fig
+++ /dev/null
@@ -1,64 +0,0 @@
-#FIG 3.2
-Portrait
-Center
-Inches
-Letter
-100.00
-Single
--2
-1200 2
-2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 0 2
- 1 1 3.00 75.00 135.00
- 3675 8550 3675 9075
-2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 0 2
- 1 1 3.00 75.00 135.00
- 3675 7200 3675 7725
-2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 0 2
- 1 1 3.00 75.00 135.00
- 3675 5775 3675 6300
-2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 0 2
- 1 1 3.00 75.00 135.00
- 3675 3975 3675 4500
-2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 0 2
- 1 1 3.00 75.00 135.00
- 3675 2625 3675 3150
-2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 0 2
- 1 1 3.00 75.00 135.00
- 3675 1275 3675 1800
-2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 0 2
- 1 1 3.00 75.00 135.00
- 3675 9900 3675 10425
-2 2 0 1 0 11 100 0 20 0.000 0 0 7 0 0 5
- 2550 10425 4875 10425 4875 11250 2550 11250 2550 10425
-2 2 0 1 0 11 100 0 20 0.000 0 0 7 0 0 5
- 2550 9075 4875 9075 4875 9900 2550 9900 2550 9075
-2 2 0 1 0 11 100 0 20 0.000 0 0 7 0 0 5
- 2550 7725 4875 7725 4875 8550 2550 8550 2550 7725
-2 2 0 1 0 11 100 0 20 0.000 0 0 7 0 0 5
- 2550 6300 4875 6300 4875 7200 2550 7200 2550 6300
-2 2 0 1 0 11 100 0 20 0.000 0 0 7 0 0 5
- 2550 4500 4875 4500 4875 5775 2550 5775 2550 4500
-2 2 0 1 0 11 100 0 20 0.000 0 0 7 0 0 5
- 2550 3150 4875 3150 4875 3975 2550 3975 2550 3150
-2 2 0 1 0 11 100 0 20 0.000 0 0 7 0 0 5
- 2550 1800 4875 1800 4875 2625 2550 2625 2550 1800
-2 2 0 1 0 11 100 0 20 0.000 0 0 7 0 0 5
- 2550 450 4875 450 4875 1275 2550 1275 2550 450
-4 1 0 100 0 0 20 0.0000 4 195 1020 3675 750 Interface\001
-4 1 0 100 0 0 14 0.0000 4 195 2040 3675 1125 main.c table.c tclsqlite.c\001
-4 1 0 100 0 0 20 0.0000 4 195 1920 3675 6675 Virtual Machine\001
-4 1 0 100 0 0 14 0.0000 4 150 570 3675 7050 vdbe.c\001
-4 1 0 100 0 0 20 0.0000 4 195 1830 3675 4875 Code Generator\001
-4 1 0 100 0 0 14 0.0000 4 195 1860 3675 5175 build.c delete.c expr.c\001
-4 1 0 100 0 0 14 0.0000 4 195 2115 3675 5400 insert.c select.c update.c\001
-4 1 0 100 0 0 14 0.0000 4 150 705 3675 5625 where.c\001
-4 1 0 100 0 0 20 0.0000 4 195 735 3675 3450 Parser\001
-4 1 0 100 0 0 20 0.0000 4 195 1140 3675 2100 Tokenizer\001
-4 1 0 100 0 0 14 0.0000 4 150 870 3675 2475 tokenize.c\001
-4 1 0 100 0 0 20 0.0000 4 255 1350 3675 9375 Page Cache\001
-4 1 0 100 0 0 14 0.0000 4 150 630 3675 3825 parse.y\001
-4 1 0 100 0 0 14 0.0000 4 150 600 3675 8400 btree.c\001
-4 1 0 100 0 0 14 0.0000 4 150 645 3675 9750 pager.c\001
-4 1 0 100 0 0 20 0.0000 4 195 1620 3675 8025 B-tree Driver\001
-4 1 0 100 0 0 14 0.0000 4 105 345 3675 11100 os.c\001
-4 1 0 100 0 0 20 0.0000 4 195 1470 3675 10725 OS Interface\001
diff --git a/www/arch.gif b/www/arch.gif
deleted file mode 100644
index 4dd8d1409acbdffb35e3ebc8536c05b7c105fc69..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc-jL100001
literal 6487
zc-jG18K~w*Nk%w1VL<_j0rCI<0001hgn-cO=-BMg;Oxlg*wFv~{{R30A^8LW000I6
zEC2ui06_tX0RRL4Xu90~Fv>}*y*TU5yZ>M)j$~<`XsWJk>%MR-&vb3yc&_h!@BhG{
za7Zi~kI1BQ$!t2G(5Q4uty-_xtai)odcWYXcuX#vYk;(R&2GEj@VI`ukb{o~*M>&iamc}(y1F2(rH;Wdu!@gD5{{_jkD;Q4;+l+N#teDDaL
z#_&Gr27l@iZ}0bR?7EHY$)3d)fAIhx-p>y1%C7B84)S$;;tRj=9B=acjq)j<<|}XO
z6wBy|p~@!@^M^d~IR3ZLyzM$a#Th^Iej2?#zp@|yAM`&Q@FTD9NUyX{KkZ5%#2Mf8
z43F~*gY_dm^&ubd9ZvE&+u%L_;_z(qh+)FLe(hjS<~a)7
The Architecture Of SQLite
-
-Introduction
-
-
-
-
-Block Diagram Of SQLite
-Interface
-
-Tokenizer
-
-Parser
-
-Code Generator
-
-Virtual Machine
-
-B-Tree
-
-Page Cache
-
-OS Interface
-
-Utilities
-
-Test Code
-
-
-SQLite Security Audit Procedure
-
}
-puts "Part I: Things to check
-
-
-
-
-
-
-
-On all functions and procedures, verify that pointer parameters are not NULL -before dereferencing those parameters. -
-Check to make sure that temporary files are opened safely: that the process -will not overwrite an existing file when opening the temp file and that -another process is unable to substitute a file for the temp file being -opened. -
-Prove that SQLite exhibits the characteristics outlined below: -
- --The following are preconditions:
--CREATE TABLE t1(a CLOB); -
The following statement of C code is executed:
---sqlite_exec_printf( - db, - "INSERT INTO t1(a) VALUES('%q');", - 0, 0, 0, Z -); -
Prove the following are true for all possible values of string Z:
--The call to sqlite_exec_printf() will -return in a length of time that is a polynomial in strlen(Z). -It might return an error code but it will not crash. -
-At most one new row will be inserted into table t1. -
-No preexisting rows of t1 will be deleted or modified. -
-No tables other than t1 will be altered in any way. -
-No preexisting files on the host computers filesystem, other than -the database file itself, will be deleted or modified. -
-For some constants K1 and K2, -if at least K1*strlen(Z) + K2 bytes of contiguous memory are -available to malloc(), then the call to sqlite_exec_printf() -will not return SQLITE_NOMEM. -
-The following are preconditions: -
The following statement of C code is executed:
---sqlite_exec(db, Z, cb, 0, 0); -
Prove the following are true for all possible values of string Z:
--The call to sqlite_exec() will -return in a length of time which is a polynomial in strlen(Z). -It might return an error code but it will not crash. -
-After sqlite_exec() returns, the buffer Y will not contain -any content from any preexisting file on the host computers file system, -except for the database file. -
-After the call to sqlite_exec() returns, the database file will -still be well-formed. It might not contain the same data, but it will -still be a properly constructed SQLite database file. -
-No preexisting files on the host computers filesystem, other than -the database file itself, will be deleted or modified. -
-For some constants K1 and K2, -if at least K1*strlen(Z) + K2 bytes of contiguous memory are -available to malloc(), then the call to sqlite_exec() -will not return SQLITE_NOMEM. -
-Back to the SQLite Home Page
-
-In SQLite, every row of every table has an integer ROWID. -The ROWID for each row is unique among all rows in the same table. -In SQLite version 2.8 the ROWID is a 32-bit signed integer. -Version 3.0 of SQLite expanded the ROWID to be a 64-bit signed integer. -
- --You can access the ROWID of an SQLite table using one the special column -names ROWID, _ROWID_, or OID. -Except if you declare an ordinary table column to use one of those special -names, then the use of that name will refer to the declared column not -to the internal ROWID. -
- --If a table contains a column of type INTEGER PRIMARY KEY, then that -column becomes an alias for the ROWID. You can then access the ROWID -using any of four different names, the original three names described above -or the name given to the INTEGER PRIMARY KEY column. All these names are -aliases for one another and work equally well in any context. -
- --When a new row is inserted into an SQLite table, the ROWID can either -be specified as part of the INSERT statement or it can be assigned -automatically by the database engine. To specify a ROWID manually, -just include it in the list of values to be inserted. For example: -
- -- --CREATE TABLE test1(a INT, b TEXT); -INSERT INTO test1(rowid, a, b) VALUES(123, 5, 'hello'); -
-If no ROWID is specified on the insert, an appropriate ROWID is created -automatically. The usual algorithm is to give the newly created row -a ROWID that is one larger than the largest ROWID in the table prior -to the insert. If the table is initially empty, then a ROWID of 1 is -used. If the largest ROWID is equal to the largest possible integer -(9223372036854775807 in SQLite version 3.0 and later) then the database -engine starts picking candidate ROWIDs at random until it finds one -that is not previously used. -
- --The normal ROWID selection algorithm described above -will generate monotonically increasing -unique ROWIDs as long as you never use the maximum ROWID value and you never -delete the entry in the table with the largest ROWID. -If you ever delete rows or if you ever create a row with the maximum possible -ROWID, then ROWIDs from previously deleted rows might be reused when creating -new rows and newly created ROWIDs might not be in strictly accending order. -
- - --If a column has the type INTEGER PRIMARY KEY AUTOINCREMENT then a slightly -different ROWID selection algorithm is used. -The ROWID chosen for the new row is one larger than the largest ROWID -that has ever before existed in that same table. If the table has never -before contained any data, then a ROWID of 1 is used. If the table -has previously held a row with the largest possible ROWID, then new INSERTs -are not allowed and any attempt to insert a new row will fail with an -SQLITE_FULL error. -
- --SQLite keeps track of the largest ROWID that a table has ever held using -the special SQLITE_SEQUENCE table. The SQLITE_SEQUENCE table is created -and initialized automatically whenever a normal table that contains an -AUTOINCREMENT column is created. The content of the SQLITE_SEQUENCE table -can be modified using ordinary UPDATE, INSERT, and DELETE statements. -But making modifications to this table will likely perturb the AUTOINCREMENT -key generation algorithm. Make sure you know what you are doing before -you undertake such changes. -
- --The behavior implemented by the AUTOINCREMENT keyword is subtly different -from the default behavior. With AUTOINCREMENT, rows with automatically -selected ROWIDs are guaranteed to have ROWIDs that have never been used -before by the same table in the same database. And the automatically generated -ROWIDs are guaranteed to be monotonically increasing. These are important -properties in certain applications. But if your application does not -need these properties, you should probably stay with the default behavior -since the use of AUTOINCREMENT requires additional work to be done -as each row is inserted and thus causes INSERTs to run a little slower. -} -footer $rcsid diff --git a/www/c_interface.tcl b/www/c_interface.tcl deleted file mode 100644 index c784ff0428..0000000000 --- a/www/c_interface.tcl +++ /dev/null @@ -1,1116 +0,0 @@ -# -# Run this Tcl script to generate the sqlite.html file. -# -set rcsid {$Id: c_interface.tcl,v 1.43 2004/11/19 11:59:24 danielk1977 Exp $} -source common.tcl -header {The C language interface to the SQLite library} -puts { -
The SQLite library is designed to be very easy to use from -a C or C++ program. This document gives an overview of the C/C++ -programming interface.
- -The interface to the SQLite library consists of three core functions, -one opaque data structure, and some constants used as return values. -The core interface is as follows:
- -- --typedef struct sqlite sqlite; -#define SQLITE_OK 0 /* Successful result */ - -sqlite *sqlite_open(const char *dbname, int mode, char **errmsg); - -void sqlite_close(sqlite *db); - -int sqlite_exec( - sqlite *db, - char *sql, - int (*xCallback)(void*,int,char**,char**), - void *pArg, - char **errmsg -); -
-The above is all you really need to know in order to use SQLite -in your C or C++ programs. There are other interface functions -available (and described below) but we will begin by describing -the core functions shown above. -
- - -Use the sqlite_open function to open an existing SQLite -database or to create a new SQLite database. The first argument -is the database name. The second argument is intended to signal -whether the database is going to be used for reading and writing -or just for reading. But in the current implementation, the -second argument to sqlite_open is ignored. -The third argument is a pointer to a string pointer. -If the third argument is not NULL and an error occurs -while trying to open the database, then an error message will be -written to memory obtained from malloc() and *errmsg will be made -to point to this error message. The calling function is responsible -for freeing the memory when it has finished with it.
- -The name of an SQLite database is the name of a file that will -contain the database. If the file does not exist, SQLite attempts -to create and initialize it. If the file is read-only (due to -permission bits or because it is located on read-only media like -a CD-ROM) then SQLite opens the database for reading only. The -entire SQL database is stored in a single file on the disk. But -additional temporary files may be created during the execution of -an SQL command in order to store the database rollback journal or -temporary and intermediate results of a query.
- -The return value of the sqlite_open function is a -pointer to an opaque sqlite structure. This pointer will -be the first argument to all subsequent SQLite function calls that -deal with the same database. NULL is returned if the open fails -for any reason.
- - -To close an SQLite database, call the sqlite_close -function passing it the sqlite structure pointer that was obtained -from a prior call to sqlite_open. -If a transaction is active when the database is closed, the transaction -is rolled back.
- - -The sqlite_exec function is used to process SQL statements -and queries. This function requires 5 parameters as follows:
- -A pointer to the sqlite structure obtained from a prior call - to sqlite_open.
A null-terminated string containing the text of one or more - SQL statements and/or queries to be processed.
A pointer to a callback function which is invoked once for each - row in the result of a query. This argument may be NULL, in which - case no callbacks will ever be invoked.
A pointer that is forwarded to become the first argument - to the callback function.
A pointer to an error string. Error messages are written to space - obtained from malloc() and the error string is made to point to - the malloced space. The calling function is responsible for freeing - this space when it has finished with it. - This argument may be NULL, in which case error messages are not - reported back to the calling function.
-The callback function is used to receive the results of a query. A -prototype for the callback function is as follows:
- -- - --int Callback(void *pArg, int argc, char **argv, char **columnNames){ - return 0; -} -
The first argument to the callback is just a copy of the fourth argument -to sqlite_exec This parameter can be used to pass arbitrary -information through to the callback function from client code. -The second argument is the number of columns in the query result. -The third argument is an array of pointers to strings where each string -is a single column of the result for that record. Note that the -callback function reports a NULL value in the database as a NULL pointer, -which is very different from an empty string. If the i-th parameter -is an empty string, we will get:
---argv[i][0] == 0 -
But if the i-th parameter is NULL we will get:
-- --argv[i] == 0 -
The names of the columns are contained in first argc -entries of the fourth argument. -If the SHOW_DATATYPES pragma -is on (it is off by default) then -the second argc entries in the 4th argument are the datatypes -for the corresponding columns. -
- -If the -EMPTY_RESULT_CALLBACKS pragma is set to ON and the result of -a query is an empty set, then the callback is invoked once with the -third parameter (argv) set to 0. In other words -
-The second parameter (argc) -and the fourth parameter (columnNames) are still valid -and can be used to determine the number and names of the result -columns if there had been a result. -The default behavior is not to invoke the callback at all if the -result set is empty. - - --argv == 0 -
The callback function should normally return 0. If the callback -function returns non-zero, the query is immediately aborted and -sqlite_exec will return SQLITE_ABORT.
- --The sqlite_exec function normally returns SQLITE_OK. But -if something goes wrong it can return a different value to indicate -the type of error. Here is a complete list of the return codes: -
- -- --#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 */ -#define SQLITE_MISMATCH 20 /* Data type mismatch */ -#define SQLITE_MISUSE 21 /* Library used incorrectly */ -#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ -#define SQLITE_AUTH 23 /* Authorization denied */ -#define SQLITE_ROW 100 /* sqlite_step() has another row ready */ -#define SQLITE_DONE 101 /* sqlite_step() has finished executing */ -
-The meanings of these various return values are as follows: -
- --- --
-- SQLITE_OK
-- -
This value is returned if everything worked and there were no errors. -
- SQLITE_INTERNAL
-- -
This value indicates that an internal consistency check within -the SQLite library failed. This can only happen if there is a bug in -the SQLite library. If you ever get an SQLITE_INTERNAL reply from -an sqlite_exec call, please report the problem on the SQLite -mailing list. -
- SQLITE_ERROR
-- -
This return value indicates that there was an error in the SQL -that was passed into the sqlite_exec. -
- SQLITE_PERM
-- -
This return value says that the access permissions on the database -file are such that the file cannot be opened. -
- SQLITE_ABORT
-- -
This value is returned if the callback function returns non-zero. -
- SQLITE_BUSY
-- -
This return code indicates that another program or thread has -the database locked. SQLite allows two or more threads to read the -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.
-- SQLITE_LOCKED
-- -
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 they do -not attempt to write the same table. -
- SQLITE_NOMEM
-- -
This value is returned if a call to malloc fails. -
- SQLITE_READONLY
-- -
This return code indicates that an attempt was made to write to -a database file that is opened for reading only. -
- SQLITE_INTERRUPT
-- -
This value is returned if a call to sqlite_interrupt -interrupts a database operation in progress. -
- SQLITE_IOERR
-- -
This value is returned if the operating system informs SQLite -that it is unable to perform some disk I/O operation. This could mean -that there is no more space left on the disk. -
- SQLITE_CORRUPT
-- -
This value is returned if SQLite detects that the database it is -working on has become corrupted. Corruption might occur due to a rogue -process writing to the database file or it might happen due to an -perviously undetected logic error in of SQLite. This value is also -returned if a disk I/O error occurs in such a way that SQLite is forced -to leave the database file in a corrupted state. The latter should only -happen due to a hardware or operating system malfunction. -
- SQLITE_FULL
-- -
This value is returned if an insertion failed because there is -no space left on the disk, or the database is too big to hold any -more information. The latter case should only occur for databases -that are larger than 2GB in size. -
- SQLITE_CANTOPEN
-- -
This value is returned if the database file could not be opened -for some reason. -
- SQLITE_PROTOCOL
-- -
This value is returned if some other process is messing with -file locks and has violated the file locking protocol that SQLite uses -on its rollback journal files. -
- SQLITE_SCHEMA
-- -
When the database first opened, SQLite reads the database schema -into memory and uses that schema to parse new SQL statements. If another -process changes the schema, the command currently being processed will -abort because the virtual machine code generated assumed the old -schema. This is the return code for such cases. Retrying the -command usually will clear the problem. -
- SQLITE_TOOBIG
-- -
SQLite will not store more than about 1 megabyte of data in a single -row of a single table. If you attempt to store more than 1 megabyte -in a single row, this is the return code you get. -
- SQLITE_CONSTRAINT
-- -
This constant is returned if the SQL statement would have violated -a database constraint. -
- SQLITE_MISMATCH
-- -
This error occurs when there is an attempt to insert non-integer -data into a column labeled INTEGER PRIMARY KEY. For most columns, SQLite -ignores the data type and allows any kind of data to be stored. But -an INTEGER PRIMARY KEY column is only allowed to store integer data. -
- SQLITE_MISUSE
-- -
This error might occur if one or more of the SQLite API routines -is used incorrectly. Examples of incorrect usage include calling -sqlite_exec after the database has been closed using -sqlite_close or -calling sqlite_exec with the same -database pointer simultaneously from two separate threads. -
- SQLITE_NOLFS
-- -
This error means that you have attempts to create or access a file -database file that is larger that 2GB on a legacy Unix machine that -lacks large file support. -
- SQLITE_AUTH
-- -
This error indicates that the authorizer callback -has disallowed the SQL you are attempting to execute. -
- SQLITE_ROW
-- -
This is one of the return codes from the -sqlite_step routine which is part of the non-callback API. -It indicates that another row of result data is available. -
- SQLITE_DONE
-- -
This is one of the return codes from the -sqlite_step routine which is part of the non-callback API. -It indicates that the SQL statement has been completely executed and -the sqlite_finalize routine is ready to be called. -
-The sqlite_exec routine described above used to be the only -way to retrieve data from an SQLite database. But many programmers found -it inconvenient to use a callback function to obtain results. So beginning -with SQLite version 2.7.7, a second access interface is available that -does not use callbacks. -
- --The new interface uses three separate functions to replace the single -sqlite_exec function. -
- -- --typedef struct sqlite_vm sqlite_vm; - -int sqlite_compile( - sqlite *db, /* The open database */ - const char *zSql, /* SQL statement to be compiled */ - const char **pzTail, /* OUT: uncompiled tail of zSql */ - sqlite_vm **ppVm, /* OUT: the virtual machine to execute zSql */ - char **pzErrmsg /* OUT: Error message. */ -); - -int sqlite_step( - sqlite_vm *pVm, /* The virtual machine to execute */ - int *pN, /* OUT: Number of columns in result */ - const char ***pazValue, /* OUT: Column data */ - const char ***pazColName /* OUT: Column names and datatypes */ -); - -int sqlite_finalize( - sqlite_vm *pVm, /* The virtual machine to be finalized */ - char **pzErrMsg /* OUT: Error message */ -); -
-The strategy is to compile a single SQL statement using -sqlite_compile then invoke sqlite_step multiple times, -once for each row of output, and finally call sqlite_finalize -to clean up after the SQL has finished execution. -
- --The sqlite_compile "compiles" a single SQL statement (specified -by the second parameter) and generates a virtual machine that is able -to execute that statement. -As with must interface routines, the first parameter must be a pointer -to an sqlite structure that was obtained from a prior call to -sqlite_open. - -
-A pointer to the virtual machine is stored in a pointer which is passed -in as the 4th parameter. -Space to hold the virtual machine is dynamically allocated. To avoid -a memory leak, the calling function must invoke -sqlite_finalize on the virtual machine after it has finished -with it. -The 4th parameter may be set to NULL if an error is encountered during -compilation. -
- --If any errors are encountered during compilation, an error message is -written into memory obtained from malloc and the 5th parameter -is made to point to that memory. If the 5th parameter is NULL, then -no error message is generated. If the 5th parameter is not NULL, then -the calling function should dispose of the memory containing the error -message by calling sqlite_freemem. -
- --If the 2nd parameter actually contains two or more statements of SQL, -only the first statement is compiled. (This is different from the -behavior of sqlite_exec which executes all SQL statements -in its input string.) The 3rd parameter to sqlite_compile -is made to point to the first character beyond the end of the first -statement of SQL in the input. If the 2nd parameter contains only -a single SQL statement, then the 3rd parameter will be made to point -to the '\000' terminator at the end of the 2nd parameter. -
- --On success, sqlite_compile returns SQLITE_OK. -Otherwise and error code is returned. -
- --After a virtual machine has been generated using sqlite_compile -it is executed by one or more calls to sqlite_step. Each -invocation of sqlite_step, except the last one, -returns a single row of the result. -The number of columns in the result is stored in the integer that -the 2nd parameter points to. -The pointer specified by the 3rd parameter is made to point -to an array of pointers to column values. -The pointer in the 4th parameter is made to point to an array -of pointers to column names and datatypes. -The 2nd through 4th parameters to sqlite_step convey the -same information as the 2nd through 4th parameters of the -callback routine when using -the sqlite_exec interface. Except, with sqlite_step -the column datatype information is always included in the in the -4th parameter regardless of whether or not the -SHOW_DATATYPES pragma -is on or off. -
- --Each invocation of sqlite_step returns an integer code that -indicates what happened during that step. This code may be -SQLITE_BUSY, SQLITE_ROW, SQLITE_DONE, SQLITE_ERROR, or -SQLITE_MISUSE. -
- --If the virtual machine is unable to open the database file because -it is locked by another thread or process, sqlite_step -will return SQLITE_BUSY. The calling function should do some other -activity, or sleep, for a short amount of time to give the lock a -chance to clear, then invoke sqlite_step again. This can -be repeated as many times as desired. -
- --Whenever another row of result data is available, -sqlite_step will return SQLITE_ROW. The row data is -stored in an array of pointers to strings and the 2nd parameter -is made to point to this array. -
- --When all processing is complete, sqlite_step will return -either SQLITE_DONE or SQLITE_ERROR. SQLITE_DONE indicates that the -statement completed successfully and SQLITE_ERROR indicates that there -was a run-time error. (The details of the error are obtained from -sqlite_finalize.) It is a misuse of the library to attempt -to call sqlite_step again after it has returned SQLITE_DONE -or SQLITE_ERROR. -
- --When sqlite_step returns SQLITE_DONE or SQLITE_ERROR, -the *pN and *pazColName values are set to the number of columns -in the result set and to the names of the columns, just as they -are for an SQLITE_ROW return. This allows the calling code to -find the number of result columns and the column names and datatypes -even if the result set is empty. The *pazValue parameter is always -set to NULL when the return codes is SQLITE_DONE or SQLITE_ERROR. -If the SQL being executed is a statement that does not -return a result (such as an INSERT or an UPDATE) then *pN will -be set to zero and *pazColName will be set to NULL. -
- --If you abuse the library by trying to call sqlite_step -inappropriately it will attempt return SQLITE_MISUSE. -This can happen if you call sqlite_step() on the same virtual machine -at the same -time from two or more threads or if you call sqlite_step() -again after it returned SQLITE_DONE or SQLITE_ERROR or if you -pass in an invalid virtual machine pointer to sqlite_step(). -You should not depend on the SQLITE_MISUSE return code to indicate -an error. It is possible that a misuse of the interface will go -undetected and result in a program crash. The SQLITE_MISUSE is -intended as a debugging aid only - to help you detect incorrect -usage prior to a mishap. The misuse detection logic is not guaranteed -to work in every case. -
- --Every virtual machine that sqlite_compile creates should -eventually be handed to sqlite_finalize. The sqlite_finalize() -procedure deallocates the memory and other resources that the virtual -machine uses. Failure to call sqlite_finalize() will result in -resource leaks in your program. -
- --The sqlite_finalize routine also returns the result code -that indicates success or failure of the SQL operation that the -virtual machine carried out. -The value returned by sqlite_finalize() will be the same as would -have been returned had the same SQL been executed by sqlite_exec. -The error message returned will also be the same. -
- --It is acceptable to call sqlite_finalize on a virtual machine -before sqlite_step has returned SQLITE_DONE. Doing so has -the effect of interrupting the operation in progress. Partially completed -changes will be rolled back and the database will be restored to its -original state (unless an alternative recovery algorithm is selected using -an ON CONFLICT clause in the SQL being executed.) The effect is the -same as if a callback function of sqlite_exec had returned -non-zero. -
- --It is also acceptable to call sqlite_finalize on a virtual machine -that has never been passed to sqlite_step even once. -
- -Only the three core routines described in section 1.0 are required to use -SQLite. But there are many other functions that provide -useful interfaces. These extended routines are as follows: -
- -- --int sqlite_last_insert_rowid(sqlite*); - -int sqlite_changes(sqlite*); - -int sqlite_get_table( - sqlite*, - char *sql, - char ***result, - int *nrow, - int *ncolumn, - char **errmsg -); - -void sqlite_free_table(char**); - -void sqlite_interrupt(sqlite*); - -int sqlite_complete(const char *sql); - -void sqlite_busy_handler(sqlite*, int (*)(void*,const char*,int), void*); - -void sqlite_busy_timeout(sqlite*, int ms); - -const char sqlite_version[]; - -const char sqlite_encoding[]; - -int sqlite_exec_printf( - sqlite*, - char *sql, - int (*)(void*,int,char**,char**), - void*, - char **errmsg, - ... -); - -int sqlite_exec_vprintf( - sqlite*, - char *sql, - int (*)(void*,int,char**,char**), - void*, - char **errmsg, - va_list -); - -int sqlite_get_table_printf( - sqlite*, - char *sql, - char ***result, - int *nrow, - int *ncolumn, - char **errmsg, - ... -); - -int sqlite_get_table_vprintf( - sqlite*, - char *sql, - char ***result, - int *nrow, - int *ncolumn, - char **errmsg, - va_list -); - -char *sqlite_mprintf(const char *zFormat, ...); - -char *sqlite_vmprintf(const char *zFormat, va_list); - -void sqlite_freemem(char*); - -void sqlite_progress_handler(sqlite*, int, int (*)(void*), void*); - -
All of the above definitions are included in the "sqlite.h" -header file that comes in the source tree.
- -Every row of an SQLite table has a unique integer key. If the -table has a column labeled INTEGER PRIMARY KEY, then that column -serves as the key. If there is no INTEGER PRIMARY KEY column then -the key is a unique integer. The key for a row can be accessed in -a SELECT statement or used in a WHERE or ORDER BY clause using any -of the names "ROWID", "OID", or "_ROWID_".
- -When you do an insert into a table that does not have an INTEGER PRIMARY -KEY column, or if the table does have an INTEGER PRIMARY KEY but the value -for that column is not specified in the VALUES clause of the insert, then -the key is automatically generated. You can find the value of the key -for the most recent INSERT statement using the -sqlite_last_insert_rowid API function.
- -The sqlite_changes API function returns the number of rows -that have been inserted, deleted, or modified since the database was -last quiescent. A "quiescent" database is one in which there are -no outstanding calls to sqlite_exec and no VMs created by -sqlite_compile that have not been finalized by sqlite_finalize. -In common usage, sqlite_changes returns the number -of rows inserted, deleted, or modified by the most recent sqlite_exec -call or since the most recent sqlite_compile. But if you have -nested calls to sqlite_exec (that is, if the callback routine -of one sqlite_exec invokes another sqlite_exec) or if -you invoke sqlite_compile to create a new VM while there is -still another VM in existance, then -the meaning of the number returned by sqlite_changes is more -complex. -The number reported includes any changes -that were later undone by a ROLLBACK or ABORT. But rows that are -deleted because of a DROP TABLE are not counted.
- -SQLite implements the command "DELETE FROM table" (without -a WHERE clause) by dropping the table then recreating it. -This is much faster than deleting the elements of the table individually. -But it also means that the value returned from sqlite_changes -will be zero regardless of the number of elements that were originally -in the table. If an accurate count of the number of elements deleted -is necessary, use "DELETE FROM table WHERE 1" instead.
- -The sqlite_get_table function is a wrapper around -sqlite_exec that collects all the information from successive -callbacks and writes it into memory obtained from malloc(). This -is a convenience function that allows the application to get the -entire result of a database query with a single function call.
- -The main result from sqlite_get_table is an array of pointers -to strings. There is one element in this array for each column of -each row in the result. NULL results are represented by a NULL -pointer. In addition to the regular data, there is an added row at the -beginning of the array that contains the name of each column of the -result.
- -As an example, consider the following query:
- --SELECT employee_name, login, host FROM users WHERE login LIKE 'd%'; -- -
This query will return the name, login and host computer name -for every employee whose login begins with the letter "d". If this -query is submitted to sqlite_get_table the result might -look like this:
- --nrow = 2- -
-ncolumn = 3
-result[0] = "employee_name"
-result[1] = "login"
-result[2] = "host"
-result[3] = "dummy"
-result[4] = "No such user"
-result[5] = 0
-result[6] = "D. Richard Hipp"
-result[7] = "drh"
-result[8] = "zadok" -
Notice that the "host" value for the "dummy" record is NULL so -the result[] array contains a NULL pointer at that slot.
- -If the result set of a query is empty, then by default -sqlite_get_table will set nrow to 0 and leave its -result parameter is set to NULL. But if the EMPTY_RESULT_CALLBACKS -pragma is ON then the result parameter is initialized to the names -of the columns only. For example, consider this query which has -an empty result set:
- --SELECT employee_name, login, host FROM users WHERE employee_name IS NULL; -- -
-The default behavior gives this results: -
- --nrow = 0- -
-ncolumn = 0
-result = 0
-
-But if the EMPTY_RESULT_CALLBACKS pragma is ON, then the following -is returned: -
- --nrow = 0- -
-ncolumn = 3
-result[0] = "employee_name"
-result[1] = "login"
-result[2] = "host"
-
Memory to hold the information returned by sqlite_get_table -is obtained from malloc(). But the calling function should not try -to free this information directly. Instead, pass the complete table -to sqlite_free_table when the table is no longer needed. -It is safe to call sqlite_free_table with a NULL pointer such -as would be returned if the result set is empty.
- -The sqlite_get_table routine returns the same integer -result code as sqlite_exec.
- -The sqlite_interrupt function can be called from a -different thread or from a signal handler to cause the current database -operation to exit at its first opportunity. When this happens, -the sqlite_exec routine (or the equivalent) that started -the database operation will return SQLITE_INTERRUPT.
- -The next interface routine to SQLite is a convenience function used -to test whether or not a string forms a complete SQL statement. -If the sqlite_complete function returns true when its input -is a string, then the argument forms a complete SQL statement. -There are no guarantees that the syntax of that statement is correct, -but we at least know the statement is complete. If sqlite_complete -returns false, then more text is required to complete the SQL statement.
- -For the purpose of the sqlite_complete function, an SQL -statement is complete if it ends in a semicolon.
- -The sqlite command-line utility uses the sqlite_complete -function to know when it needs to call sqlite_exec. After each -line of input is received, sqlite calls sqlite_complete -on all input in its buffer. If sqlite_complete returns true, -then sqlite_exec is called and the input buffer is reset. If -sqlite_complete returns false, then the prompt is changed to -the continuation prompt and another line of text is read and added to -the input buffer.
- -The SQLite library exports the string constant named -sqlite_version which contains the version number of the -library. The header file contains a macro SQLITE_VERSION -with the same information. If desired, a program can compare -the SQLITE_VERSION macro against the sqlite_version -string constant to verify that the version number of the -header file and the library match.
- -By default, SQLite assumes that all data uses a fixed-size -8-bit character (iso8859). But if you give the --enable-utf8 option -to the configure script, then the library assumes UTF-8 variable -sized characters. This makes a difference for the LIKE and GLOB -operators and the LENGTH() and SUBSTR() functions. The static -string sqlite_encoding will be set to either "UTF-8" or -"iso8859" to indicate how the library was compiled. In addition, -the sqlite.h header file will define one of the -macros SQLITE_UTF8 or SQLITE_ISO8859, as appropriate.
- -Note that the character encoding mechanism used by SQLite cannot -be changed at run-time. This is a compile-time option only. The -sqlite_encoding character string just tells you how the library -was compiled.
- -The sqlite_busy_handler procedure can be used to register -a busy callback with an open SQLite database. The busy callback will -be invoked whenever SQLite tries to access a database that is locked. -The callback will typically do some other useful work, or perhaps sleep, -in order to give the lock a chance to clear. If the callback returns -non-zero, then SQLite tries again to access the database and the cycle -repeats. If the callback returns zero, then SQLite aborts the current -operation and returns SQLITE_BUSY.
- -The arguments to sqlite_busy_handler are the opaque -structure returned from sqlite_open, a pointer to the busy -callback function, and a generic pointer that will be passed as -the first argument to the busy callback. When SQLite invokes the -busy callback, it sends it three arguments: the generic pointer -that was passed in as the third argument to sqlite_busy_handler, -the name of the database table or index that the library is trying -to access, and the number of times that the library has attempted to -access the database table or index.
- -For the common case where we want the busy callback to sleep, -the SQLite library provides a convenience routine sqlite_busy_timeout. -The first argument to sqlite_busy_timeout is a pointer to -an open SQLite database and the second argument is a number of milliseconds. -After sqlite_busy_timeout has been executed, the SQLite library -will wait for the lock to clear for at least the number of milliseconds -specified before it returns SQLITE_BUSY. Specifying zero milliseconds for -the timeout restores the default behavior.
- -The four utility functions
- --
implement the same query functionality as sqlite_exec -and sqlite_get_table. But instead of taking a complete -SQL statement as their second argument, the four _printf -routines take a printf-style format string. The SQL statement to -be executed is generated from this format string and from whatever -additional arguments are attached to the end of the function call.
- -There are two advantages to using the SQLite printf -functions instead of sprintf. First of all, with the -SQLite printf routines, there is never a danger of overflowing a -static buffer as there is with sprintf. The SQLite -printf routines automatically allocate (and later frees) -as much memory as is -necessary to hold the SQL statements generated.
- -The second advantage the SQLite printf routines have over -sprintf are two new formatting options specifically designed -to support string literals in SQL. Within the format string, -the %q formatting option works very much like %s in that it -reads a null-terminated string from the argument list and inserts -it into the result. But %q translates the inserted string by -making two copies of every single-quote (') character in the -substituted string. This has the effect of escaping the end-of-string -meaning of single-quote within a string literal. The %Q formatting -option works similar; it translates the single-quotes like %q and -additionally encloses the resulting string in single-quotes. -If the argument for the %Q formatting options is a NULL pointer, -the resulting string is NULL without single quotes. -
- -Consider an example. Suppose you are trying to insert a string -value into a database table where the string value was obtained from -user input. Suppose the string to be inserted is stored in a variable -named zString. The code to do the insertion might look like this:
- -- --sqlite_exec_printf(db, - "INSERT INTO table1 VALUES('%s')", - 0, 0, 0, zString); -
If the zString variable holds text like "Hello", then this statement -will work just fine. But suppose the user enters a string like -"Hi y'all!". The SQL statement generated reads as follows: - -
- --INSERT INTO table1 VALUES('Hi y'all') -
This is not valid SQL because of the apostrophy in the word "y'all". -But if the %q formatting option is used instead of %s, like this:
- -- --sqlite_exec_printf(db, - "INSERT INTO table1 VALUES('%q')", - 0, 0, 0, zString); -
Then the generated SQL will look like the following:
- -- --INSERT INTO table1 VALUES('Hi y''all') -
Here the apostrophy has been escaped and the SQL statement is well-formed. -When generating SQL on-the-fly from data that might contain a -single-quote character ('), it is always a good idea to use the -SQLite printf routines and the %q formatting option instead of sprintf. -
- -If the %Q formatting option is used instead of %q, like this:
- -- --sqlite_exec_printf(db, - "INSERT INTO table1 VALUES(%Q)", - 0, 0, 0, zString); -
Then the generated SQL will look like the following:
- -- --INSERT INTO table1 VALUES('Hi y''all') -
If the value of the zString variable is NULL, the generated SQL -will look like the following:
- -- --INSERT INTO table1 VALUES(NULL) -
All of the _printf() routines above are built around the following -two functions:
- -- --char *sqlite_mprintf(const char *zFormat, ...); -char *sqlite_vmprintf(const char *zFormat, va_list); -
The sqlite_mprintf() routine works like the the standard library -sprintf() except that it writes its results into memory obtained -from malloc() and returns a pointer to the malloced buffer. -sqlite_mprintf() also understands the %q and %Q extensions described -above. The sqlite_vmprintf() is a varargs version of the same -routine. The string pointer that these routines return should be freed -by passing it to sqlite_freemem(). -
- -The sqlite_progress_handler() routine can be used to register a -callback routine with an SQLite database to be invoked periodically during long -running calls to sqlite_exec(), sqlite_step() and the various -wrapper functions. -
- -The callback is invoked every N virtual machine operations, where N is -supplied as the second argument to sqlite_progress_handler(). The third -and fourth arguments to sqlite_progress_handler() are a pointer to the -routine to be invoked and a void pointer to be passed as the first argument to -it. -
- -The time taken to execute each virtual machine operation can vary based on -many factors. A typical value for a 1 GHz PC is between half and three million -per second but may be much higher or lower, depending on the query. As such it -is difficult to schedule background operations based on virtual machine -operations. Instead, it is recommended that a callback be scheduled relatively -frequently (say every 1000 instructions) and external timer routines used to -determine whether or not background jobs need to be run. -
- - -Beginning with version 2.4.0, SQLite allows the SQL language to be -extended with new functions implemented as C code. The following interface -is used: -
- -- --typedef struct sqlite_func sqlite_func; - -int sqlite_create_function( - sqlite *db, - const char *zName, - int nArg, - void (*xFunc)(sqlite_func*,int,const char**), - void *pUserData -); -int sqlite_create_aggregate( - sqlite *db, - const char *zName, - int nArg, - void (*xStep)(sqlite_func*,int,const char**), - void (*xFinalize)(sqlite_func*), - void *pUserData -); - -char *sqlite_set_result_string(sqlite_func*,const char*,int); -void sqlite_set_result_int(sqlite_func*,int); -void sqlite_set_result_double(sqlite_func*,double); -void sqlite_set_result_error(sqlite_func*,const char*,int); - -void *sqlite_user_data(sqlite_func*); -void *sqlite_aggregate_context(sqlite_func*, int nBytes); -int sqlite_aggregate_count(sqlite_func*); -
-The sqlite_create_function() interface is used to create -regular functions and sqlite_create_aggregate() is used to -create new aggregate functions. In both cases, the db -parameter is an open SQLite database on which the functions should -be registered, zName is the name of the new function, -nArg is the number of arguments, and pUserData is -a pointer which is passed through unchanged to the C implementation -of the function. Both routines return 0 on success and non-zero -if there are any errors. -
- --The length of a function name may not exceed 255 characters. -Any attempt to create a function whose name exceeds 255 characters -in length will result in an error. -
- --For regular functions, the xFunc callback is invoked once -for each function call. The implementation of xFunc should call -one of the sqlite_set_result_... interfaces to return its -result. The sqlite_user_data() routine can be used to -retrieve the pUserData pointer that was passed in when the -function was registered. -
- --For aggregate functions, the xStep callback is invoked once -for each row in the result and then xFinalize is invoked at the -end to compute a final answer. The xStep routine can use the -sqlite_aggregate_context() interface to allocate memory that -will be unique to that particular instance of the SQL function. -This memory will be automatically deleted after xFinalize is called. -The sqlite_aggregate_count() routine can be used to find out -how many rows of data were passed to the aggregate. The xFinalize -callback should invoke one of the sqlite_set_result_... -interfaces to set the final result of the aggregate. -
- --SQLite now implements all of its built-in functions using this -interface. For additional information and examples on how to create -new SQL functions, review the SQLite source code in the file -func.c. -
- --If SQLite is compiled with the THREADSAFE preprocessor macro set to 1, -then it is safe to use SQLite from two or more threads of the same process -at the same time. But each thread should have its own sqlite* -pointer returned from sqlite_open. It is never safe for two -or more threads to access the same sqlite* pointer at the same time. -
- --In precompiled SQLite libraries available on the website, the Unix -versions are compiled with THREADSAFE turned off but the windows -versions are compiled with THREADSAFE turned on. If you need something -different that this you will have to recompile. -
- --Under Unix, an sqlite* pointer should not be carried across a -fork() system call into the child process. The child process -should open its own copy of the database after the fork(). -
- -For examples of how the SQLite C/C++ interface can be used, -refer to the source code for the sqlite program in the -file src/shell.c of the source tree. -Additional information about sqlite is available at -sqlite.html. -See also the sources to the Tcl interface for SQLite in -the source file src/tclsqlite.c.
-} -footer $rcsid diff --git a/www/capi3.tcl b/www/capi3.tcl deleted file mode 100644 index 149cf7f0ad..0000000000 --- a/www/capi3.tcl +++ /dev/null @@ -1,516 +0,0 @@ -set rcsid {$Id: capi3.tcl,v 1.10 2007/04/27 17:16:22 drh Exp $} -source common.tcl -header {C/C++ Interface For SQLite Version 3} - -proc AddHyperlinks {txt} { - regsub -all {([^:alnum:>])(sqlite3_\w+)(\([^\)]*\))} $txt \ - {\1\2\3} t2 - puts $t2 -} - -AddHyperlinks { --SQLite version 3.0 is a new version of SQLite, derived from -the SQLite 2.8.13 code base, but with an incompatible file format -and API. -SQLite version 3.0 was created to answer demand for the following features: -
- --It was necessary to move to version 3.0 to implement these features because -each requires incompatible changes to the database file format. Other -incompatible changes, such as a cleanup of the API, were introduced at the -same time under the theory that it is best to get your incompatible changes -out of the way all at once. -
- --The API for version 3.0 is similar to the version 2.X API, -but with some important changes. Most noticeably, the "sqlite_" -prefix that occurs on the beginning of all API functions and data -structures are changed to "sqlite3_". -This avoids confusion between the two APIs and allows linking against both -SQLite 2.X and SQLite 3.0 at the same time. -
- --There is no agreement on what the C datatype for a UTF-16 -string should be. Therefore, SQLite uses a generic type of void* -to refer to UTF-16 strings. Client software can cast the void* -to whatever datatype is appropriate for their system. -
- --The API for SQLite 3.0 includes 83 separate functions in addition -to several data structures and #defines. (A complete -API reference is provided as a separate document.) -Fortunately, the interface is not nearly as complex as its size implies. -Simple programs can still make do with only 3 functions: -sqlite3_open(), -sqlite3_exec(), and -sqlite3_close(). -More control over the execution of the database engine is provided -using -sqlite3_prepare() -to compile an SQLite statement into byte code and -sqlite3_step() -to execute that bytecode. -A family of routines with names beginning with -sqlite3_column_ -is used to extract information about the result set of a query. -Many interface functions come in pairs, with both a UTF-8 and -UTF-16 version. And there is a collection of routines -used to implement user-defined SQL functions and user-defined -text collating sequences. -
- - -- -- typedef struct sqlite3 sqlite3; - int sqlite3_open(const char*, sqlite3**); - int sqlite3_open16(const void*, sqlite3**); - int sqlite3_close(sqlite3*); - const char *sqlite3_errmsg(sqlite3*); - const void *sqlite3_errmsg16(sqlite3*); - int sqlite3_errcode(sqlite3*); -
-The sqlite3_open() routine returns an integer error code rather than -a pointer to the sqlite3 structure as the version 2 interface did. -The difference between sqlite3_open() -and sqlite3_open16() is that sqlite3_open16() takes UTF-16 (in host native -byte order) for the name of the database file. If a new database file -needs to be created, then sqlite3_open16() sets the internal text -representation to UTF-16 whereas sqlite3_open() sets the text -representation to UTF-8. -
- --The opening and/or creating of the database file is deferred until the -file is actually needed. This allows options and parameters, such -as the native text representation and default page size, to be -set using PRAGMA statements. -
- --The sqlite3_errcode() routine returns a result code for the most -recent major API call. sqlite3_errmsg() returns an English-language -text error message for the most recent error. The error message is -represented in UTF-8 and will be ephemeral - it could disappear on -the next call to any SQLite API function. sqlite3_errmsg16() works like -sqlite3_errmsg() except that it returns the error message represented -as UTF-16 in host native byte order. -
- --The error codes for SQLite version 3 are unchanged from version 2. -They are as follows: -
- -- --#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 */ -#define SQLITE_MISMATCH 20 /* Data type mismatch */ -#define SQLITE_MISUSE 21 /* Library used incorrectly */ -#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ -#define SQLITE_AUTH 23 /* Authorization denied */ -#define SQLITE_ROW 100 /* sqlite_step() has another row ready */ -#define SQLITE_DONE 101 /* sqlite_step() has finished executing */ -
- -- typedef int (*sqlite_callback)(void*,int,char**, char**); - int sqlite3_exec(sqlite3*, const char *sql, sqlite_callback, void*, char**); -
-The sqlite3_exec function works much as it did in SQLite version 2. -Zero or more SQL statements specified in the second parameter are compiled -and executed. Query results are returned to a callback routine. -See the API reference for additional -information. -
- --In SQLite version 3, the sqlite3_exec routine is just a wrapper around -calls to the prepared statement interface. -
- -- -- typedef struct sqlite3_stmt sqlite3_stmt; - int sqlite3_prepare(sqlite3*, const char*, int, sqlite3_stmt**, const char**); - int sqlite3_prepare16(sqlite3*, const void*, int, sqlite3_stmt**, const void**); - int sqlite3_finalize(sqlite3_stmt*); - int sqlite3_reset(sqlite3_stmt*); -
-The sqlite3_prepare interface compiles a single SQL statement into byte code -for later execution. This interface is now the preferred way of accessing -the database. -
- --The SQL statement is a UTF-8 string for sqlite3_prepare(). -The sqlite3_prepare16() works the same way except -that it expects a UTF-16 string as SQL input. -Only the first SQL statement in the input string is compiled. -The fourth parameter is filled in with a pointer to the next (uncompiled) -SQLite statement in the input string, if any. -The sqlite3_finalize() routine deallocates a prepared SQL statement. -All prepared statements must be finalized before the database can be -closed. -The sqlite3_reset() routine resets a prepared SQL statement so that it -can be executed again. -
- --The SQL statement may contain tokens of the form "?" or "?nnn" or ":aaa" -where "nnn" is an integer and "aaa" is an identifier. -Such tokens represent unspecified literal values (or "wildcards") -to be filled in later by the -sqlite3_bind interface. -Each wildcard has an associated number which is its sequence in the -statement or the "nnn" in the case of a "?nnn" form. -It is allowed for the same wildcard -to occur more than once in the same SQL statement, in which case -all instance of that wildcard will be filled in with the same value. -Unbound wildcards have a value of NULL. -
- -- -- int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); - int sqlite3_bind_double(sqlite3_stmt*, int, double); - int sqlite3_bind_int(sqlite3_stmt*, int, int); - int sqlite3_bind_int64(sqlite3_stmt*, int, long long int); - int sqlite3_bind_null(sqlite3_stmt*, int); - int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); - int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); - int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); -
-There is an assortment of sqlite3_bind routines used to assign values -to wildcards in a prepared SQL statement. Unbound wildcards -are interpreted as NULLs. Bindings are not reset by sqlite3_reset(). -But wildcards can be rebound to new values after an sqlite3_reset(). -
- --After an SQL statement has been prepared (and optionally bound), it -is executed using: -
- -- -- int sqlite3_step(sqlite3_stmt*); -
-The sqlite3_step() routine return SQLITE_ROW if it is returning a single -row of the result set, or SQLITE_DONE if execution has completed, either -normally or due to an error. It might also return SQLITE_BUSY if it is -unable to open the database file. If the return value is SQLITE_ROW, then -the following routines can be used to extract information about that row -of the result set: -
- -- -- const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); - int sqlite3_column_bytes(sqlite3_stmt*, int iCol); - int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); - int sqlite3_column_count(sqlite3_stmt*); - const char *sqlite3_column_decltype(sqlite3_stmt *, int iCol); - const void *sqlite3_column_decltype16(sqlite3_stmt *, int iCol); - double sqlite3_column_double(sqlite3_stmt*, int iCol); - int sqlite3_column_int(sqlite3_stmt*, int iCol); - long long int sqlite3_column_int64(sqlite3_stmt*, int iCol); - const char *sqlite3_column_name(sqlite3_stmt*, int iCol); - const void *sqlite3_column_name16(sqlite3_stmt*, int iCol); - const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); - const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); - int sqlite3_column_type(sqlite3_stmt*, int iCol); -
-The -sqlite3_column_count() -function returns the number of columns in -the results set. sqlite3_column_count() can be called at any time after -sqlite3_prepare(). -sqlite3_data_count() -works similarly to -sqlite3_column_count() except that it only works following sqlite3_step(). -If the previous call to sqlite3_step() returned SQLITE_DONE or an error code, -then sqlite3_data_count() will return 0 whereas sqlite3_column_count() will -continue to return the number of columns in the result set. -
- -Returned data is examined using the other sqlite3_column_***() functions, -all of which take a column number as their second parameter. Columns are -zero-indexed from left to right. Note that this is different to parameters, -which are indexed starting at one. -
- --The sqlite3_column_type() function returns the -datatype for the value in the Nth column. The return value is one -of these: -
- -- -- #define SQLITE_INTEGER 1 - #define SQLITE_FLOAT 2 - #define SQLITE_TEXT 3 - #define SQLITE_BLOB 4 - #define SQLITE_NULL 5 -
-The sqlite3_column_decltype() routine returns text which is the -declared type of the column in the CREATE TABLE statement. For an -expression, the return type is an empty string. sqlite3_column_name() -returns the name of the Nth column. sqlite3_column_bytes() returns -the number of bytes in a column that has type BLOB or the number of bytes -in a TEXT string with UTF-8 encoding. sqlite3_column_bytes16() returns -the same value for BLOBs but for TEXT strings returns the number of bytes -in a UTF-16 encoding. -sqlite3_column_blob() return BLOB data. -sqlite3_column_text() return TEXT data as UTF-8. -sqlite3_column_text16() return TEXT data as UTF-16. -sqlite3_column_int() return INTEGER data in the host machines native -integer format. -sqlite3_column_int64() returns 64-bit INTEGER data. -Finally, sqlite3_column_double() return floating point data. -
- --It is not necessary to retrieve data in the format specify by -sqlite3_column_type(). If a different format is requested, the data -is converted automatically. -
- --Data format conversions can invalidate the pointer returned by -prior calls to sqlite3_column_blob(), sqlite3_column_text(), and/or -sqlite3_column_text16(). Pointers might be invalided in the following -cases: -
--The initial content is a BLOB and sqlite3_column_text() -or sqlite3_column_text16() -is called. A zero-terminator might need to be added to the string. -
-The initial content is UTF-8 text and sqlite3_column_bytes16() or -sqlite3_column_text16() is called. The content must be converted to UTF-16. -
-The initial content is UTF-16 text and sqlite3_column_bytes() or -sqlite3_column_text() is called. The content must be converted to UTF-8. -
-Note that conversions between UTF-16be and UTF-16le -are always done in place and do -not invalidate a prior pointer, though of course the content of the buffer -that the prior pointer points to will have been modified. Other kinds -of conversion are done in place when it is possible, but sometime it is -not possible and in those cases prior pointers are invalidated. -
- --The safest and easiest to remember policy is this: assume that any -result from -
-User defined functions can be created using the following routine: -
- -- -- typedef struct sqlite3_value sqlite3_value; - int sqlite3_create_function( - sqlite3 *, - const char *zFunctionName, - int nArg, - int eTextRep, - void*, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*) - ); - int sqlite3_create_function16( - sqlite3*, - const void *zFunctionName, - int nArg, - int eTextRep, - void*, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*) - ); - #define SQLITE_UTF8 1 - #define SQLITE_UTF16 2 - #define SQLITE_UTF16BE 3 - #define SQLITE_UTF16LE 4 - #define SQLITE_ANY 5 -
-The nArg parameter specifies the number of arguments to the function. -A value of 0 indicates that any number of arguments is allowed. The -eTextRep parameter specifies what representation text values are expected -to be in for arguments to this function. The value of this parameter should -be one of the parameters defined above. SQLite version 3 allows multiple -implementations of the same function using different text representations. -The database engine chooses the function that minimization the number -of text conversions required. -
- --Normal functions specify only xFunc and leave xStep and xFinal set to NULL. -Aggregate functions specify xStep and xFinal and leave xFunc set to NULL. -There is no separate sqlite3_create_aggregate() API. -
- --The function name is specified in UTF-8. A separate sqlite3_create_function16() -API works the same as sqlite_create_function() -except that the function name is specified in UTF-16 host byte order. -
- --Notice that the parameters to functions are now pointers to sqlite3_value -structures instead of pointers to strings as in SQLite version 2.X. -The following routines are used to extract useful information from these -"values": -
- -- -- const void *sqlite3_value_blob(sqlite3_value*); - int sqlite3_value_bytes(sqlite3_value*); - int sqlite3_value_bytes16(sqlite3_value*); - double sqlite3_value_double(sqlite3_value*); - int sqlite3_value_int(sqlite3_value*); - long long int sqlite3_value_int64(sqlite3_value*); - const unsigned char *sqlite3_value_text(sqlite3_value*); - const void *sqlite3_value_text16(sqlite3_value*); - int sqlite3_value_type(sqlite3_value*); -
-Function implementations use the following APIs to acquire context and -to report results: -
- -- -- void *sqlite3_aggregate_context(sqlite3_context*, int nbyte); - void *sqlite3_user_data(sqlite3_context*); - void sqlite3_result_blob(sqlite3_context*, const void*, int n, void(*)(void*)); - void sqlite3_result_double(sqlite3_context*, double); - void sqlite3_result_error(sqlite3_context*, const char*, int); - void sqlite3_result_error16(sqlite3_context*, const void*, int); - void sqlite3_result_int(sqlite3_context*, int); - void sqlite3_result_int64(sqlite3_context*, long long int); - void sqlite3_result_null(sqlite3_context*); - void sqlite3_result_text(sqlite3_context*, const char*, int n, void(*)(void*)); - void sqlite3_result_text16(sqlite3_context*, const void*, int n, void(*)(void*)); - void sqlite3_result_value(sqlite3_context*, sqlite3_value*); - void *sqlite3_get_auxdata(sqlite3_context*, int); - void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*)); -
-The following routines are used to implement user-defined -collating sequences: -
- -- -- sqlite3_create_collation(sqlite3*, const char *zName, int eTextRep, void*, - int(*xCompare)(void*,int,const void*,int,const void*)); - sqlite3_create_collation16(sqlite3*, const void *zName, int eTextRep, void*, - int(*xCompare)(void*,int,const void*,int,const void*)); - sqlite3_collation_needed(sqlite3*, void*, - void(*)(void*,sqlite3*,int eTextRep,const char*)); - sqlite3_collation_needed16(sqlite3*, void*, - void(*)(void*,sqlite3*,int eTextRep,const void*)); -
-The sqlite3_create_collation() function specifies a collating sequence name -and a comparison function to implement that collating sequence. The -comparison function is only used for comparing text values. The eTextRep -parameter is one of SQLITE_UTF8, SQLITE_UTF16LE, SQLITE_UTF16BE, or -SQLITE_ANY to specify which text representation the comparison function works -with. Separate comparison functions can exist for the same collating -sequence for each of the UTF-8, UTF-16LE and UTF-16BE text representations. -The sqlite3_create_collation16() works like sqlite3_create_collation() except -that the collation name is specified in UTF-16 host byte order instead of -in UTF-8. -
- --The sqlite3_collation_needed() routine registers a callback which the -database engine will invoke if it encounters an unknown collating sequence. -The callback can lookup an appropriate comparison function and invoke -sqlite_3_create_collation() as needed. The fourth parameter to the callback -is the name of the collating sequence in UTF-8. For sqlite3_collation_need16() -the callback sends the collating sequence name in UTF-16 host byte order. -
-} -footer $rcsid diff --git a/www/capi3ref.tcl b/www/capi3ref.tcl deleted file mode 100644 index 631acef35d..0000000000 --- a/www/capi3ref.tcl +++ /dev/null @@ -1,1882 +0,0 @@ -set rcsid {$Id: capi3ref.tcl,v 1.60 2007/05/19 06:48:43 danielk1977 Exp $} -source common.tcl -header {C/C++ Interface For SQLite Version 3} -puts { --- - Note that when type conversions occur, pointers returned by prior - calls to sqlite3_column_blob(), sqlite3_column_text(), and/or - sqlite3_column_text16() may be invalidated. - Type conversions and pointer invalidations might occur - in the following cases: - --
-- Internal Type Requested Type Conversion - NULL INTEGER Result is 0 - NULL FLOAT Result is 0.0 - NULL TEXT Result is NULL pointer - NULL BLOB Result is NULL pointer - INTEGER FLOAT Convert from integer to float - INTEGER TEXT ASCII rendering of the integer - INTEGER BLOB Same as for INTEGER->TEXT - FLOAT INTEGER Convert from float to integer - FLOAT TEXT ASCII rendering of the float - FLOAT BLOB Same as FLOAT->TEXT - TEXT INTEGER Use atoi() - TEXT FLOAT Use atof() - TEXT BLOB No change - BLOB INTEGER Convert to TEXT then use atoi() - BLOB FLOAT Convert to TEXT then use atof() - BLOB TEXT Add a \\000 terminator if needed
- The initial content is a BLOB and sqlite3_column_text() - or sqlite3_column_text16() - is called. A zero-terminator might need to be added to the string. -
- The initial content is UTF-8 text and sqlite3_column_bytes16() or - sqlite3_column_text16() is called. The content must be converted to UTF-16. -
- The initial content is UTF-16 text and sqlite3_column_bytes() or - sqlite3_column_text() is called. The content must be converted to UTF-8. -
- - And the following statement compiled: - -- CREATE TABLE t1(c1 INTEGER); -
- - Then this routine would return the string "INTEGER" for the second - result column (i==1), and a NULL pointer for the first result column - (i==0). - - If the following statements were compiled then this routine would - return "INTEGER" for the first (only) result column. - -- SELECT c1 + 1, c1 FROM t1; -
-} - -api {} { - int sqlite3_table_column_metadata( - sqlite3 *db, /* Connection handle */ - const char *zDbName, /* Database name or NULL */ - const char *zTableName, /* Table name */ - const char *zColumnName, /* Column name */ - char const **pzDataType, /* OUTPUT: Declared data type */ - char const **pzCollSeq, /* OUTPUT: Collation sequence name */ - int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ - int *pPrimaryKey, /* OUTPUT: True if column part of PK */ - int *pAutoinc /* OUTPUT: True if colums is auto-increment */ - ); -} { - This routine is used to obtain meta information about a specific column of a - specific database table accessible using the connection handle passed as the - first function argument. - - The column is identified by the second, third and fourth parameters to - this function. The second parameter is either the name of the database - (i.e. "main", "temp" or an attached database) containing the specified - table or NULL. If it is NULL, then all attached databases are searched - for the table using the same algorithm as the database engine uses to - resolve unqualified table references. - - The third and fourth parameters to this function are the table and column - name of the desired column, respectively. Neither of these parameters - may be NULL. - - Meta information is returned by writing to the memory locations passed as - the 5th and subsequent parameters to this function. Any of these - arguments may be NULL, in which case the corresponding element of meta - information is ommitted. - -- SELECT (SELECT c1) FROM t1; - SELECT (SELECT c1 FROM t1); - SELECT c1 FROM (SELECT c1 FROM t1); - SELECT * FROM (SELECT c1 FROM t1); - SELECT * FROM (SELECT * FROM t1); -
- Parameter Output Type Description - ----------------------------------- - 5th const char* Declared data type - 6th const char* Name of the columns default collation sequence - 7th int True if the column has a NOT NULL constraint - 8th int True if the column is part of the PRIMARY KEY - 9th int True if the column is AUTOINCREMENT -- - The memory pointed to by the character pointers returned for the - declaration type and collation sequence is valid only until the next - call to any sqlite API function. - - This function may load one or more schemas from database files. If an - error occurs during this process, or if the requested table or column - cannot be found, an SQLITE error code is returned and an error message - left in the database handle (to be retrieved using sqlite3_errmsg()). - Specifying an SQL view instead of a table as the third argument is also - considered an error. - - If the specified column is "rowid", "oid" or "_rowid_" and an - INTEGER PRIMARY KEY column has been explicitly declared, then the output - parameters are set for the explicitly declared column. If there is no - explicitly declared IPK column, then the data-type is "INTEGER", the - collation sequence "BINARY" and the primary-key flag is set. Both - the not-null and auto-increment flags are clear. - - This API is only available if the library was compiled with the - SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined. -} - -api {} { -const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N); -const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N); -} { -If the Nth column returned by statement pStmt is a column reference, -these functions may be used to access the name of the database (either -"main", "temp" or the name of an attached database) that contains -the column. If the Nth column is not a column reference, NULL is -returned. - -See the description of function sqlite3_column_decltype() for a -description of exactly which expressions are considered column references. - -Function sqlite3_column_database_name() returns a pointer to a UTF-8 -encoded string. sqlite3_column_database_name16() returns a pointer -to a UTF-16 encoded string. -} - -api {} { -const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N); -const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N); -} { -If the Nth column returned by statement pStmt is a column reference, -these functions may be used to access the schema name of the referenced -column in the database schema. If the Nth column is not a column -reference, NULL is returned. - -See the description of function sqlite3_column_decltype() for a -description of exactly which expressions are considered column references. - -Function sqlite3_column_origin_name() returns a pointer to a UTF-8 -encoded string. sqlite3_column_origin_name16() returns a pointer -to a UTF-16 encoded string. -} - -api {} { -const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N); -const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N); -} { -If the Nth column returned by statement pStmt is a column reference, -these functions may be used to access the name of the table that -contains the column. If the Nth column is not a column reference, -NULL is returned. - -See the description of function sqlite3_column_decltype() for a -description of exactly which expressions are considered column references. - -Function sqlite3_column_table_name() returns a pointer to a UTF-8 -encoded string. sqlite3_column_table_name16() returns a pointer -to a UTF-16 encoded string. -} - -api {} { -const char *sqlite3_column_name(sqlite3_stmt*,int); -const void *sqlite3_column_name16(sqlite3_stmt*,int); -} { - The first argument is a prepared SQL statement. This function returns - the column heading for the Nth column of that statement, where N is the - second function argument. The string returned is UTF-8 for - sqlite3_column_name() and UTF-16 for sqlite3_column_name16(). -} - -api {} { -void *sqlite3_commit_hook(sqlite3*, int(*xCallback)(void*), void *pArg); -} { - Experimental - - Register a callback function to be invoked whenever a new transaction - is committed. The pArg argument is passed through to the callback. - callback. If the callback function returns non-zero, then the commit - is converted into a rollback. - - If another function was previously registered, its pArg value is returned. - Otherwise NULL is returned. - - Registering a NULL function disables the callback. Only a single commit - hook callback can be registered at a time. -} - -api {} { -int sqlite3_complete(const char *sql); -int sqlite3_complete16(const void *sql); -} { - These functions return true if the given input string comprises - one or more complete SQL statements. - The argument must be a nul-terminated UTF-8 string for sqlite3_complete() - and a nul-terminated UTF-16 string for sqlite3_complete16(). - - These routines do not check to see if the SQL statement is well-formed. - They only check to see that the statement is terminated by a semicolon - that is not part of a string literal and is not inside - the body of a trigger. -} {} - -api {} { -int sqlite3_create_collation( - sqlite3*, - const char *zName, - int pref16, - void*, - int(*xCompare)(void*,int,const void*,int,const void*) -); -int sqlite3_create_collation16( - sqlite3*, - const char *zName, - int pref16, - void*, - int(*xCompare)(void*,int,const void*,int,const void*) -); -#define SQLITE_UTF8 1 -#define SQLITE_UTF16BE 2 -#define SQLITE_UTF16LE 3 -#define SQLITE_UTF16 4 -} { - These two functions are used to add new collation sequences to the - sqlite3 handle specified as the first argument. - - The name of the new collation sequence is specified as a UTF-8 string - for sqlite3_create_collation() and a UTF-16 string for - sqlite3_create_collation16(). In both cases the name is passed as the - second function argument. - - The third argument must be one of the constants SQLITE_UTF8, - SQLITE_UTF16LE or SQLITE_UTF16BE, indicating that the user-supplied - routine expects to be passed pointers to strings encoded using UTF-8, - UTF-16 little-endian or UTF-16 big-endian respectively. The - SQLITE_UTF16 constant indicates that text strings are expected in - UTF-16 in the native byte order of the host machine. - - A pointer to the user supplied routine must be passed as the fifth - argument. If it is NULL, this is the same as deleting the collation - sequence (so that SQLite cannot call it anymore). Each time the user - supplied function is invoked, it is passed a copy of the void* passed as - the fourth argument to sqlite3_create_collation() or - sqlite3_create_collation16() as its first argument. - - The remaining arguments to the user-supplied routine are two strings, - each represented by a [length, data] pair and encoded in the encoding - that was passed as the third argument when the collation sequence was - registered. The user routine should return negative, zero or positive if - the first string is less than, equal to, or greater than the second - string. i.e. (STRING1 - STRING2). -} - -api {} { -int sqlite3_collation_needed( - sqlite3*, - void*, - void(*)(void*,sqlite3*,int eTextRep,const char*) -); -int sqlite3_collation_needed16( - sqlite3*, - void*, - void(*)(void*,sqlite3*,int eTextRep,const void*) -); -} { - To avoid having to register all collation sequences before a database - can be used, a single callback function may be registered with the - database handle to be called whenever an undefined collation sequence is - required. - - If the function is registered using the sqlite3_collation_needed() API, - then it is passed the names of undefined collation sequences as strings - encoded in UTF-8. If sqlite3_collation_needed16() is used, the names - are passed as UTF-16 in machine native byte order. A call to either - function replaces any existing callback. - - When the user-function is invoked, the first argument passed is a copy - of the second argument to sqlite3_collation_needed() or - sqlite3_collation_needed16(). The second argument is the database - handle. The third argument is one of SQLITE_UTF8, SQLITE_UTF16BE or - SQLITE_UTF16LE, indicating the most desirable form of the collation - sequence function required. The fourth argument is the name of the - required collation sequence. - - The collation sequence is returned to SQLite by a collation-needed - callback using the sqlite3_create_collation() or - sqlite3_create_collation16() APIs, described above. -} - -api {} { -int sqlite3_create_function( - sqlite3 *, - const char *zFunctionName, - int nArg, - int eTextRep, - void *pUserData, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*) -); -int sqlite3_create_function16( - sqlite3*, - const void *zFunctionName, - int nArg, - int eTextRep, - void *pUserData, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*) -); -#define SQLITE_UTF8 1 -#define SQLITE_UTF16 2 -#define SQLITE_UTF16BE 3 -#define SQLITE_UTF16LE 4 -#define SQLITE_ANY 5 -} { - These two functions are used to add SQL functions or aggregates - implemented in C. The - only difference between these two routines is that the second argument, the - name of the (scalar) function or aggregate, is encoded in UTF-8 for - sqlite3_create_function() and UTF-16 for sqlite3_create_function16(). - The length of the name is limited to 255 bytes, exclusive of the - zero-terminator. Note that the name length limit is in bytes, not - characters. Any attempt to create a function with a longer name - will result in an SQLITE_ERROR error. - - The first argument is the database handle that the new function or - aggregate is to be added to. If a single program uses more than one - database handle internally, then user functions or aggregates must - be added individually to each database handle with which they will be - used. - - The third argument is the number of arguments that the function or - aggregate takes. If this argument is -1 then the function or - aggregate may take any number of arguments. The maximum number - of arguments to a new SQL function is 127. A number larger than - 127 for the third argument results in an SQLITE_ERROR error. - - The fourth argument, eTextRep, specifies what type of text arguments - this function prefers to receive. Any function should be able to work - work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be - more efficient with one representation than another. Users are allowed - to specify separate implementations for the same function which are called - depending on the text representation of the arguments. The the implementation - which provides the best match is used. If there is only a single - implementation which does not care what text representation is used, - then the fourth argument should be SQLITE_ANY. - - The fifth argument is an arbitrary pointer. The function implementations - can gain access to this pointer using the sqlite_user_data() API. - - The sixth, seventh and eighth argumens, xFunc, xStep and xFinal, are - pointers to user implemented C functions that implement the user - function or aggregate. A scalar function requires an implementation of - the xFunc callback only, NULL pointers should be passed as the xStep - and xFinal arguments. An aggregate function requires an implementation - of xStep and xFinal, and NULL should be passed for xFunc. To delete an - existing user function or aggregate, pass NULL for all three function - callbacks. Specifying an inconstant set of callback values, such as an - xFunc and an xFinal, or an xStep but no xFinal, results in an SQLITE_ERROR - return. -} - -api {} { -int sqlite3_data_count(sqlite3_stmt *pStmt); -} { - Return the number of values in the current row of the result set. - - After a call to sqlite3_step() that returns SQLITE_ROW, this routine - will return the same value as the sqlite3_column_count() function. - After sqlite3_step() has returned an SQLITE_DONE, SQLITE_BUSY or - error code, or before sqlite3_step() has been called on a - prepared SQL statement, this routine returns zero. -} - -api {} { -int sqlite3_errcode(sqlite3 *db); -} { - Return the error code for the most recent failed sqlite3_* API call associated - with sqlite3 handle 'db'. If a prior API call failed but the most recent - API call succeeded, the return value from this routine is undefined. - - Calls to many sqlite3_* functions set the error code and string returned - by sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16() - (overwriting the previous values). Note that calls to sqlite3_errcode(), - sqlite3_errmsg() and sqlite3_errmsg16() themselves do not affect the - results of future invocations. Calls to API routines that do not return - an error code (examples: sqlite3_data_count() or sqlite3_mprintf()) do - not change the error code returned by this routine. - - Assuming no other intervening sqlite3_* API calls are made, the error - code returned by this function is associated with the same error as - the strings returned by sqlite3_errmsg() and sqlite3_errmsg16(). -} {} - -api {} { -const char *sqlite3_errmsg(sqlite3*); -const void *sqlite3_errmsg16(sqlite3*); -} { - Return a pointer to a UTF-8 encoded string (sqlite3_errmsg) - or a UTF-16 encoded string (sqlite3_errmsg16) describing in English the - error condition for the most recent sqlite3_* API call. The returned - string is always terminated by an 0x00 byte. - - The string "not an error" is returned when the most recent API call was - successful. -} - -api {} { -int sqlite3_exec( - sqlite3*, /* An open database */ - const char *sql, /* SQL to be executed */ - sqlite_callback, /* Callback function */ - void *, /* 1st argument to callback function */ - char **errmsg /* Error msg written here */ -); -} { - A function to executes one or more statements of SQL. - - If one or more of the SQL statements are queries, then - the callback function specified by the 3rd argument is - invoked once for each row of the query result. This callback - should normally return 0. If the callback returns a non-zero - value then the query is aborted, all subsequent SQL statements - are skipped and the sqlite3_exec() function returns the SQLITE_ABORT. - - The 1st argument is an arbitrary pointer that is passed - to the callback function as its first argument. - - The 2nd argument to the callback function is the number of - columns in the query result. The 3rd argument to the callback - is an array of strings holding the values for each column. - The 4th argument to the callback is an array of strings holding - the names of each column. - - The callback function may be NULL, even for queries. A NULL - callback is not an error. It just means that no callback - will be invoked. - - If an error occurs while parsing or evaluating the SQL (but - not while executing the callback) then an appropriate error - message is written into memory obtained from malloc() and - *errmsg is made to point to that message. The calling function - is responsible for freeing the memory that holds the error - message. Use sqlite3_free() for this. If errmsg==NULL, - then no error message is ever written. - - The return value is is SQLITE_OK if there are no errors and - some other return code if there is an error. The particular - return value depends on the type of error. - - If the query could not be executed because a database file is - locked or busy, then this function returns SQLITE_BUSY. (This - behavior can be modified somewhat using the sqlite3_busy_handler() - and sqlite3_busy_timeout() functions.) -} {} - -api {} { -int sqlite3_finalize(sqlite3_stmt *pStmt); -} { - The sqlite3_finalize() function is called to delete a prepared - SQL statement obtained by a previous call to sqlite3_prepare(), - sqlite3_prepare_v2(), sqlite3_prepare16(), or sqlite3_prepare16_v2(). - If the statement was executed successfully, or - not executed at all, then SQLITE_OK is returned. If execution of the - statement failed then an error code is returned. - - After sqlite_finalize() has been called, the statement handle is - invalidated. Passing it to any other SQLite function may cause a - crash. - - All prepared statements must finalized before sqlite3_close() is - called or else the close will fail with a return code of SQLITE_BUSY. - - This routine can be called at any point during the execution of the - virtual machine. If the virtual machine has not completed execution - when this routine is called, that is like encountering an error or - an interrupt. (See sqlite3_interrupt().) Incomplete updates may be - rolled back and transactions canceled, depending on the circumstances, - and the result code returned will be SQLITE_ABORT. -} - -api {} { -void *sqlite3_malloc(int); -void *sqlite3_realloc(void*, int); -void sqlite3_free(void*); -} { - These routines provide access to the memory allocator used by SQLite. - Depending on how SQLite has been compiled and the OS-layer backend, - the memory allocator used by SQLite might be the standard system - malloc()/realloc()/free(), or it might be something different. With - certain compile-time flags, SQLite will add wrapper logic around the - memory allocator to add memory leak and buffer overrun detection. The - OS layer might substitute a completely different memory allocator. - Use these APIs to be sure you are always using the correct memory - allocator. - - The sqlite3_free() API, not the standard free() from the system library, - should always be used to free the memory buffer returned by - sqlite3_mprintf() or sqlite3_vmprintf() and to free the error message - string returned by sqlite3_exec(). Using free() instead of sqlite3_free() - might accidentally work on some systems and build configurations but - will fail on others. - - Compatibility Note: Prior to version 3.4.0, the sqlite3_free API - was prototyped to take a char* parameter rather than - void*. Like this: -
- The change to using void* might cause warnings when - compiling older code against - newer libraries, but everything should still work correctly. -} - -api {} { -int sqlite3_get_table( - sqlite3*, /* An open database */ - const char *sql, /* SQL to be executed */ - char ***resultp, /* Result written to a char *[] that this points to */ - int *nrow, /* Number of result rows written here */ - int *ncolumn, /* Number of result columns written here */ - char **errmsg /* Error msg written here */ -); -void sqlite3_free_table(char **result); -} { - This next routine is really just a wrapper around sqlite3_exec(). - Instead of invoking a user-supplied callback for each row of the - result, this routine remembers each row of the result in memory - obtained from malloc(), then returns all of the result after the - query has finished. - - As an example, suppose the query result where this table: - --void sqlite3_free(char*); -
- Name | Age - ----------------------- - Alice | 43 - Bob | 28 - Cindy | 21 -- - If the 3rd argument were &azResult then after the function returns - azResult will contain the following data: - -
- azResult[0] = "Name"; - azResult[1] = "Age"; - azResult[2] = "Alice"; - azResult[3] = "43"; - azResult[4] = "Bob"; - azResult[5] = "28"; - azResult[6] = "Cindy"; - azResult[7] = "21"; -- - Notice that there is an extra row of data containing the column - headers. But the *nrow return value is still 3. *ncolumn is - set to 2. In general, the number of values inserted into azResult - will be ((*nrow) + 1)*(*ncolumn). - - After the calling function has finished using the result, it should - pass the result data pointer to sqlite3_free_table() in order to - release the memory that was malloc-ed. Because of the way the - malloc() happens, the calling function must not try to call - malloc() directly. Only sqlite3_free_table() is able to release - the memory properly and safely. - - The return value of this routine is the same as from sqlite3_exec(). -} - -api {sqlite3_interrupt} { - void sqlite3_interrupt(sqlite3*); -} { - This function causes any pending database operation to abort and - return at its earliest opportunity. This routine is typically - called in response to a user action such as pressing "Cancel" - or Ctrl-C where the user wants a long query operation to halt - immediately. -} {} - -api {} { -long long int sqlite3_last_insert_rowid(sqlite3*); -} { - Each entry in an SQLite table has a unique integer key called the "rowid". - The rowid is always available as an undeclared column - named ROWID, OID, or _ROWID_. - If the table has a column of type INTEGER PRIMARY KEY then that column - is another an alias for the rowid. - - This routine - returns the rowid of the most recent INSERT into the database - from the database connection given in the first argument. If - no inserts have ever occurred on this database connection, zero - is returned. - - If an INSERT occurs within a trigger, then the rowid of the - inserted row is returned by this routine as long as the trigger - is running. But once the trigger terminates, the value returned - by this routine reverts to the last value inserted before the - trigger fired. -} {} - -api {} { -char *sqlite3_mprintf(const char*,...); -char *sqlite3_vmprintf(const char*, va_list); -} { - These routines are variants of the "sprintf()" from the - standard C library. The resulting string is written into memory - obtained from malloc() so that there is never a possibility of buffer - overflow. These routines also implement some additional formatting - options that are useful for constructing SQL statements. - - The strings returned by these routines should be freed by calling - sqlite3_free(). - - All of the usual printf formatting options apply. In addition, there - is a "%q" option. %q works like %s in that it substitutes a null-terminated - string from the argument list. But %q also doubles every '\\'' character. - %q is designed for use inside a string literal. By doubling each '\\'' - character it escapes that character and allows it to be inserted into - the string. - - For example, so some string variable contains text as follows: - -
- - One can use this text in an SQL statement as follows: - -- char *zText = "It's a happy day!"; -
- - Because the %q format string is used, the '\\'' character in zText - is escaped and the SQL generated is as follows: - -- sqlite3_exec_printf(db, "INSERT INTO table VALUES('%q')", - callback1, 0, 0, zText); -
- - This is correct. Had we used %s instead of %q, the generated SQL - would have looked like this: - -- INSERT INTO table1 VALUES('It''s a happy day!') -
- - This second example is an SQL syntax error. As a general rule you - should always use %q instead of %s when inserting text into a string - literal. -} {} - -api {} { -char *sqlite3_snprintf(int bufSize, char *buf, const char *zFormat, ...); -} { - This routine works like "sprintf()", writing a formatted string into - the buf[]. However, no more than bufSize characters will be written - into buf[]. This routine returns a pointer to buf[]. If bufSize is - greater than zero, then buf[] is guaranteed to be zero-terminated. - - This routine uses the same extended formatting options as - sqlite3_mprintf() and sqlite3_vmprintf(). - - Note these differences with the snprintf() function found in many - standard libraries: (1) sqlite3_snprintf() returns a pointer to the - buffer rather than the number of characters written. (It would, - arguably, be more useful to return the number of characters written, - but we discovered that after the interface had been published and - are unwilling to break backwards compatibility.) (2) The order - of the bufSize and buf parameter is reversed from snprintf(). - And (3) sqlite3_snprintf() always writes a zero-terminator if bufSize - is positive. - - Please do not use the return value of this routine. We may - decide to make the minor compatibility break and change this routine - to return the number of characters written rather than a pointer to - the buffer in a future minor version increment. -} - -api {} { -int sqlite3_open( - const char *filename, /* Database filename (UTF-8) */ - sqlite3 **ppDb /* OUT: SQLite db handle */ -); -int sqlite3_open16( - const void *filename, /* Database filename (UTF-16) */ - sqlite3 **ppDb /* OUT: SQLite db handle */ -); -} { - Open the sqlite database file "filename". The "filename" is UTF-8 - encoded for sqlite3_open() and UTF-16 encoded in the native byte order - for sqlite3_open16(). An sqlite3* handle is returned in *ppDb, even - if an error occurs. If the database is opened (or created) successfully, - then SQLITE_OK is returned. Otherwise an error code is returned. The - sqlite3_errmsg() or sqlite3_errmsg16() routines can be used to obtain - an English language description of the error. - - If the database file does not exist, then a new database will be created - as needed. - The encoding for the database will be UTF-8 if sqlite3_open() is called and - UTF-16 if sqlite3_open16 is used. - - Whether or not an error occurs when it is opened, resources associated - with the sqlite3* handle should be released by passing it to - sqlite3_close() when it is no longer required. - - The returned sqlite3* can only be used in the same thread in which it - was created. It is an error to call sqlite3_open() in one thread then - pass the resulting database handle off to another thread to use. This - restriction is due to goofy design decisions (bugs?) in the way some - threading implementations interact with file locks. - - Note to windows users: The encoding used for the filename argument - of sqlite3_open() must be UTF-8, not whatever codepage is currently - defined. Filenames containing international characters must be converted - to UTF-8 prior to passing them into sqlite3_open(). -} - -api {} { -int sqlite3_prepare_v2( - sqlite3 *db, /* Database handle */ - const char *zSql, /* SQL statement, UTF-8 encoded */ - int nBytes, /* Length of zSql in bytes. */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const char **pzTail /* OUT: Pointer to unused portion of zSql */ -); -int sqlite3_prepare16_v2( - sqlite3 *db, /* Database handle */ - const void *zSql, /* SQL statement, UTF-16 encoded */ - int nBytes, /* Length of zSql in bytes. */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const void **pzTail /* OUT: Pointer to unused portion of zSql */ -); - -/* Legacy Interfaces */ -int sqlite3_prepare( - sqlite3 *db, /* Database handle */ - const char *zSql, /* SQL statement, UTF-8 encoded */ - int nBytes, /* Length of zSql in bytes. */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const char **pzTail /* OUT: Pointer to unused portion of zSql */ -); -int sqlite3_prepare16( - sqlite3 *db, /* Database handle */ - const void *zSql, /* SQL statement, UTF-16 encoded */ - int nBytes, /* Length of zSql in bytes. */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const void **pzTail /* OUT: Pointer to unused portion of zSql */ -); -} { - To execute an SQL query, it must first be compiled into a byte-code - program using one of these routines. - - The first argument "db" is an SQLite database handle. The second - argument "zSql" is the statement to be compiled, encoded as either - UTF-8 or UTF-16. The sqlite3_prepare_v2() - interfaces uses UTF-8 and sqlite3_prepare16_v2() - use UTF-16. If the next argument, "nBytes", is less - than zero, then zSql is read up to the first nul terminator. If - "nBytes" is not less than zero, then it is the length of the string zSql - in bytes (not characters). - - *pzTail is made to point to the first byte past the end of the first - SQL statement in zSql. This routine only compiles the first statement - in zSql, so *pzTail is left pointing to what remains uncompiled. - - *ppStmt is left pointing to a compiled SQL statement that can be - executed using sqlite3_step(). Or if there is an error, *ppStmt may be - set to NULL. If the input text contained no SQL (if the input is and - empty string or a comment) then *ppStmt is set to NULL. The calling - procedure is responsible for deleting this compiled SQL statement - using sqlite3_finalize() after it has finished with it. - - On success, SQLITE_OK is returned. Otherwise an error code is returned. - - The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are - recommended for all new programs. The two older interfaces are retained - for backwards compatibility, but their use is discouraged. - In the "v2" interfaces, the prepared statement - that is returned (the sqlite3_stmt object) contains a copy of the original - SQL. This causes the sqlite3_step() interface to behave a differently in - two ways: - -- INSERT INTO table1 VALUES('It's a happy day!'); -
}} - puts { | }
- set limit [expr {$i+$nrow}]
- puts {
| }
-}
-puts "
" - regsub -all {\[} $desc {\[} desc - regsub -all {sqlite3_[a-z0-9_]+} $desc "\[resolve_name $name &\]" d2 - foreach x $specialname { - regsub -all $x $d2 "\[resolve_name $name &\]" d2 - } - regsub -all "\n( *\n)+" [subst $d2] "\n\n" - regsub "^( *\n)+" $prototype {} p2 - regsub "(\n *)+\$" $p2 {} p3 - puts $p3 - puts "
" d3 - puts "
$d3
" -} - -puts "-This page provides a high-level summary of changes to SQLite. -For more detail, refer the the checkin logs generated by -CVS at - -http://www.sqlite.org/cvstrac/timeline. -
- --
-![]() |
-- | - - | -- | - - | -- |
-
|
-
" - puts "$rule ::= | " - regsub -all < $body {%LT} body - regsub -all > $body {%GT} body - regsub -all %LT $body {} body - regsub -all %GT $body {} body - regsub -all {[]|[*?]} $body {&} body - regsub -all "\n" [string trim $body] "$body |
-For most purposes, SQLite can be built just fine using the default -compilation options. However, if required, the compile-time options -documented below can be used to -omit SQLite features (resulting in -a smaller compiled library size) or to change the -default values of some parameters. -
--Every effort has been made to ensure that the various combinations -of compilation options work harmoniously and produce a working library. -Nevertheless, it is strongly recommended that the SQLite test-suite -be executed to check for errors before using an SQLite library built -with non-standard compilation options. -
- -SQLITE_DEFAULT_AUTOVACUUM=<1 or 0>
-This macro determines if SQLite creates databases with the
-auto-vacuum
-flag set by default. The default value is 0 (do not create auto-vacuum
-databases). In any case the compile-time default may be overridden by the
-"PRAGMA auto_vacuum" command.
-
SQLITE_DEFAULT_CACHE_SIZE=<pages>
-This macro sets the default size of the page-cache for each attached
-database, in pages. This can be overridden by the "PRAGMA cache_size"
-comamnd. The default value is 2000.
-
SQLITE_DEFAULT_PAGE_SIZE=<bytes>
-This macro is used to set the default page-size used when a
-database is created. The value assigned must be a power of 2. The
-default value is 1024. The compile-time default may be overridden at
-runtime by the "PRAGMA page_size" command.
-
SQLITE_DEFAULT_TEMP_CACHE_SIZE=<pages>
-This macro sets the default size of the page-cache for temporary files
-created by SQLite to store intermediate results, in pages. It does
-not affect the page-cache for the temp database, where tables created
-using "CREATE TEMP TABLE" are stored. The default value is 500.
-
SQLITE_MAX_PAGE_SIZE=<bytes>
-This is used to set the maximum allowable page-size that can
-be specified by the "PRAGMA page_size" command. The default value
-is 8192.
-
The following options are used to reduce the size of the compiled -library by omiting optional features. This is probably only useful -in embedded systems where space is especially tight, as even with all -features included the SQLite library is relatively small. Don't forget -to tell your compiler to optimize for binary size! (the -Os option if -using GCC).
- -The macros in this section do not require values. The following
-compilation switches all have the same effect:
--DSQLITE_OMIT_ALTERTABLE
--DSQLITE_OMIT_ALTERTABLE=1
--DSQLITE_OMIT_ALTERTABLE=0
-
If any of these options are defined, then the same set of SQLITE_OMIT_XXX -options must also be defined when using the 'lemon' tool to generate a parse.c -file. Because of this, these options may only used when the library is built -from source, not from the collection of pre-packaged C files provided for -non-UNIX like platforms on the website. -
- -SQLITE_OMIT_ALTERTABLE
-When this option is defined, the
-ALTER TABLE command is not included in the
-library. Executing an ALTER TABLE statement causes a parse error.
-
SQLITE_OMIT_AUTHORIZATION
-Defining this option omits the authorization callback feature from the
-library. The
-sqlite3_set_authorizer() API function is not present in the library.
-
SQLITE_OMIT_AUTOVACUUM
-If this option is defined, the library cannot create or write to
-databases that support
-auto-vacuum. Executing a
-"PRAGMA auto_vacuum" statement is not an error, but does not return a value
-or modify the auto-vacuum flag in the database file. If a database that
-supports auto-vacuum is opened by a library compiled with this option, it
-is automatically opened in read-only mode.
-
SQLITE_OMIT_AUTOINCREMENT
-This option is used to omit the AUTOINCREMENT functionality. When this
-is macro is defined, columns declared as "INTEGER PRIMARY KEY AUTOINCREMENT"
-behave in the same way as columns declared as "INTEGER PRIMARY KEY" when a
-NULL is inserted. The sqlite_sequence system table is neither created, nor
-respected if it already exists.
-
TODO: Need a link here - AUTOINCREMENT is not yet documented
- -
SQLITE_OMIT_BLOB_LITERAL
-When this option is defined, it is not possible to specify a blob in
-an SQL statement using the X'ABCD' syntax.
WARNING: The VACUUM command depends on this syntax for vacuuming databases -#that contain blobs, so disabling this functionality may render a database -#unvacuumable. -#
-#TODO: Need a link here - is that syntax documented anywhere?
-puts { - -
SQLITE_OMIT_COMPLETE
-This option causes the
-sqlite3_complete API to be omitted.
-
SQLITE_OMIT_COMPOUND_SELECT
-This option is used to omit the compound SELECT functionality.
-SELECT statements that use the
-UNION, UNION ALL, INTERSECT or EXCEPT compound SELECT operators will
-cause a parse error.
-
SQLITE_OMIT_CONFLICT_CLAUSE
-In the future, this option will be used to omit the
-ON CONFLICT clause from the library.
-
SQLITE_OMIT_DATETIME_FUNCS
-If this option is defined, SQLite's built-in date and time manipulation
-functions are omitted. Specifically, the SQL functions julianday(), date(),
-time(), datetime() and strftime() are not available. The default column
-values CURRENT_TIME, CURRENT_DATE and CURRENT_DATETIME are still available.
-
SQLITE_OMIT_EXPLAIN
-Defining this option causes the EXPLAIN command to be omitted from the
-library. Attempting to execute an EXPLAIN statement will cause a parse
-error.
-
SQLITE_OMIT_FLOATING_POINT
-This option is used to omit floating-point number support from the SQLite
-library. When specified, specifying a floating point number as a literal
-(i.e. "1.01") results in a parse error.
-
In the future, this option may also disable other floating point -functionality, for example the sqlite3_result_double(), -sqlite3_bind_double(), sqlite3_value_double() and sqlite3_column_double() -API functions. -
- -SQLITE_OMIT_FOREIGN_KEY
-If this option is defined, FOREIGN KEY clauses in column declarations are
-ignored.
-
SQLITE_OMIT_INTEGRITY_CHECK
-This option may be used to omit the
-"PRAGMA integrity_check"
-command from the compiled library.
-
SQLITE_OMIT_MEMORYDB
-When this is defined, the library does not respect the special database
-name ":memory:" (normally used to create an in-memory database). If
-":memory:" is passed to sqlite3_open(), a file with this name will be
-opened or created.
-
SQLITE_OMIT_PAGER_PRAGMAS
-Defining this option omits pragmas related to the pager subsystem from
-the build. Currently, the
-default_cache_size and
-cache_size pragmas are omitted.
-
SQLITE_OMIT_PRAGMA
-This option is used to omit the PRAGMA command
-from the library. Note that it is useful to define the macros that omit
-specific pragmas in addition to this, as they may also remove supporting code
-in other sub-systems. This macro removes the PRAGMA command only.
-
SQLITE_OMIT_PROGRESS_CALLBACK
-This option may be defined to omit the capability to issue "progress"
-callbacks during long-running SQL statements. The
-sqlite3_progress_handler()
-API function is not present in the library.
-
-
SQLITE_OMIT_REINDEX
-When this option is defined, the REINDEX
-command is not included in the library. Executing a REINDEX statement causes
-a parse error.
-
SQLITE_OMIT_SCHEMA_PRAGMAS
-Defining this option omits pragmas for querying the database schema from
-the build. Currently, the
-table_info,
-index_info,
-index_list and
-database_list
-pragmas are omitted.
-
SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
-Defining this option omits pragmas for querying and modifying the
-database schema version and user version from the build. Specifically, the
-schema_version and
-user_version
-pragmas are omitted.
-
-
SQLITE_OMIT_SUBQUERY
-
If defined, support for sub-selects and the IN() operator are omitted. -
- -SQLITE_OMIT_TCL_VARIABLE
-
If this macro is defined, then the special "$
SQLITE_OMIT_TRIGGER
-Defining this option omits support for VIEW objects. Neither the
-CREATE TRIGGER or
-DROP TRIGGER
-commands are available in this case, attempting to execute either will result
-in a parse error.
-
-WARNING: If this macro is defined, it will not be possible to open a database -for which the schema contains TRIGGER objects. -
- -SQLITE_OMIT_UTF16
-This macro is used to omit support for UTF16 text encoding. When this is
-defined all API functions that return or accept UTF16 encoded text are
-unavailable. These functions can be identified by the fact that they end
-with '16', for example sqlite3_prepare16(), sqlite3_column_text16() and
-sqlite3_bind_text16().
-
SQLITE_OMIT_VACUUM
-When this option is defined, the VACUUM
-command is not included in the library. Executing a VACUUM statement causes
-a parse error.
-
SQLITE_OMIT_VIEW
-Defining this option omits support for VIEW objects. Neither the
-CREATE VIEW or
-DROP VIEW
-commands are available in this case, attempting to execute either will result
-in a parse error.
-
-WARNING: If this macro is defined, it will not be possible to open a database -for which the schema contains VIEW objects. -
-} -footer $rcsid diff --git a/www/conflict.tcl b/www/conflict.tcl deleted file mode 100644 index 2d11639bc3..0000000000 --- a/www/conflict.tcl +++ /dev/null @@ -1,91 +0,0 @@ -# -# Run this Tcl script to generate the constraint.html file. -# -set rcsid {$Id: conflict.tcl,v 1.4 2004/10/10 17:24:55 drh Exp $ } -source common.tcl -header {Constraint Conflict Resolution in SQLite} -puts { --In most SQL databases, if you have a UNIQUE constraint on -a table and you try to do an UPDATE or INSERT that violates -the constraint, the database will abort the operation in -progress, back out any prior changes associated with -UPDATE or INSERT command, and return an error. -This is the default behavior of SQLite. -Beginning with version 2.3.0, though, SQLite allows you to -define alternative ways for dealing with constraint violations. -This article describes those alternatives and how to use them. -
- --SQLite defines five constraint conflict resolution algorithms -as follows: -
- -When a constraint violation occurs, an immediate ROLLBACK -occurs, thus ending the current transaction, and the command aborts -with a return code of SQLITE_CONSTRAINT. If no transaction is -active (other than the implied transaction that is created on every -command) then this algorithm works the same as ABORT.
When a constraint violation occurs, the command backs out -any prior changes it might have made and aborts with a return code -of SQLITE_CONSTRAINT. But no ROLLBACK is executed so changes -from prior commands within the same transaction -are preserved. This is the default behavior for SQLite.
When a constraint violation occurs, the command aborts with a -return code SQLITE_CONSTRAINT. But any changes to the database that -the command made prior to encountering the constraint violation -are preserved and are not backed out. For example, if an UPDATE -statement encountered a constraint violation on the 100th row that -it attempts to update, then the first 99 row changes are preserved -by change to rows 100 and beyond never occur.
When a constraint violation occurs, the one row that contains -the constraint violation is not inserted or changed. But the command -continues executing normally. Other rows before and after the row that -contained the constraint violation continue to be inserted or updated -normally. No error is returned.
When a UNIQUE constraint violation occurs, the pre-existing row -that caused the constraint violation is removed prior to inserting -or updating the current row. Thus the insert or update always occurs. -The command continues executing normally. No error is returned.
SQLite provides multiple conflict resolution algorithms for a -couple of reasons. First, SQLite tries to be roughly compatible with as -many other SQL databases as possible, but different SQL database -engines exhibit different conflict resolution strategies. For -example, PostgreSQL always uses ROLLBACK, Oracle always uses ABORT, and -MySQL usually uses FAIL but can be instructed to use IGNORE or REPLACE. -By supporting all five alternatives, SQLite provides maximum -portability.
- -Another reason for supporting multiple algorithms is that sometimes -it is useful to use an algorithm other than the default. -Suppose, for example, you are -inserting 1000 records into a database, all within a single -transaction, but one of those records is malformed and causes -a constraint error. Under PostgreSQL or Oracle, none of the -1000 records would get inserted. In MySQL, some subset of the -records that appeared before the malformed record would be inserted -but the rest would not. Neither behavior is especially helpful. -What you really want is to use the IGNORE algorithm to insert -all but the malformed record.
- -} -footer $rcsid diff --git a/www/copyright-release.html b/www/copyright-release.html deleted file mode 100644 index bc0c764acd..0000000000 --- a/www/copyright-release.html +++ /dev/null @@ -1,109 +0,0 @@ - - --SQLite is software that implements an embeddable SQL database engine. -SQLite is available for free download from http://www.sqlite.org/. -The principal author and maintainer of SQLite has disclaimed all -copyright interest in his contributions to SQLite -and thus released his contributions into the public domain. -In order to keep the SQLite software unencumbered by copyright -claims, the principal author asks others who may from time to -time contribute changes and enhancements to likewise disclaim -their own individual copyright interest. -
- --Because the SQLite software found at http://www.sqlite.org/ is in the -public domain, anyone is free to download the SQLite software -from that website, make changes to the software, use, distribute, -or sell the modified software, under either the original name or -under some new name, without any need to obtain permission, pay -royalties, acknowledge the original source of the software, or -in any other way compensate, identify, or notify the original authors. -Nobody is in any way compelled to contribute their SQLite changes and -enhancements back to the SQLite website. This document concerns -only changes and enhancements to SQLite that are intentionally and -deliberately contributed back to the SQLite website. -
- --For the purposes of this document, "SQLite software" shall mean any -computer source code, documentation, makefiles, test scripts, or -other information that is published on the SQLite website, -http://www.sqlite.org/. Precompiled binaries are excluded from -the definition of "SQLite software" in this document because the -process of compiling the software may introduce information from -outside sources which is not properly a part of SQLite. -
- --The header comments on the SQLite source files exhort the reader to -share freely and to never take more than one gives. -In the spirit of that exhortation I make the following declarations: -
- --I dedicate to the public domain -any and all copyright interest in the SQLite software that -was publicly available on the SQLite website (http://www.sqlite.org/) prior -to the date of the signature below and any changes or enhancements to -the SQLite software -that I may cause to be published on that website in the future. -I make this dedication for the benefit of the public at large and -to the detriment of my heirs and successors. I intend this -dedication to be an overt act of relinquishment in perpetuity of -all present and future rights to the SQLite software under copyright -law. -
-To the best of my knowledge and belief, the changes and enhancements that -I have contributed to SQLite are either originally written by me -or are derived from prior works which I have verified are also -in the public domain and are not subject to claims of copyright -by other parties. -
-To the best of my knowledge and belief, no individual, business, organization, -government, or other entity has any copyright interest -in the SQLite software as it existed on the -SQLite website as of the date on the signature line below. -
-I agree never to publish any additional information -to the SQLite website (by CVS, email, scp, FTP, or any other means) unless -that information is an original work of authorship by me or is derived from -prior published versions of SQLite. -I agree never to copy and paste code into the SQLite code base from -other sources. -I agree never to publish on the SQLite website any information that -would violate a law or breach a contract. -
-
-Signature:
- - - - | -Date: - | -Name (printed): - | - -
-![]() -SQLite is in the -Public Domain - |
-All of the deliverable code in SQLite has been dedicated to the -public domain -by the authors. -All code authors, and representatives of the companies they work for, -have signed affidavits dedicating their contributions to -the public domain and originals of -those signed affidavits are stored in a firesafe at the main offices -of Hwaci. -Anyone is free to copy, modify, publish, use, compile, sell, or distribute -the original SQLite code, either in source code form or as a compiled binary, -for any purpose, commercial or non-commercial, and by any means. -
- --The previous paragraph applies to the deliverable code in SQLite - -those parts of the SQLite library that you actually bundle and -ship with a larger application. Portions of the documentation and -some code used as part of the build process might fall under -other licenses. The details here are unclear. We do not worry -about the licensing of the documentation and build code so much -because none of these things are part of the core deliverable -SQLite library. -
- --All of the deliverable code in SQLite has been written from scratch. -No code has been taken from other projects or from the open -internet. Every line of code can be traced back to its original -author, and all of those authors have public domain dedications -on file. So the SQLite code base is clean and is -uncontaminated with licensed code from other projects. -
- --Even though SQLite is in the public domain and does not require -a license, some users want to obtain a license anyway. Some reasons -for obtaining a license include: -
- --If you feel like you really have to purchase a license for SQLite, -Hwaci, the company that employs -the architect and principal developers of SQLite, will sell you -one. -Please contact: -
- --D. Richard Hipp- -
-Hwaci - Applied Software Research
-704.948.4565
-drh@hwaci.com -
-In order to keep SQLite completely free and unencumbered by copyright, -all new contributors to the SQLite code base are asked to dedicate -their contributions to the public domain. -If you want to send a patch or enhancement for possible inclusion in the -SQLite source tree, please accompany the patch with the following statement: -
- --The author or authors of this code dedicate any and all copyright interest -in this code to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and successors. -We intend this dedication to be an overt act of relinquishment in -perpetuity of all present and future rights to this code under copyright law. -- -
-We are not able to accept patches or changes to -SQLite that are not accompanied by a statement such as the above. -In addition, if you make -changes or enhancements as an employee, then a simple statement such as the -above is insufficient. You must also send by surface mail a copyright release -signed by a company officer. -A signed original of the copyright release should be mailed to:
- --Hwaci- -
-6200 Maple Cove Lane
-Charlotte, NC 28269
-USA -
-A template copyright release is available -in PDF or -HTML. -You can use this release to make future changes. -
-} -footer $rcsid diff --git a/www/datatype3.tcl b/www/datatype3.tcl deleted file mode 100644 index da400aefea..0000000000 --- a/www/datatype3.tcl +++ /dev/null @@ -1,440 +0,0 @@ -set rcsid {$Id: datatype3.tcl,v 1.17 2007/06/20 16:13:23 drh Exp $} -source common.tcl -header {Datatypes In SQLite Version 3} -puts { -Version 2 of SQLite stores all column values as ASCII text. -Version 3 enhances this by providing the ability to store integer and -real numbers in a more compact format and the capability to store -BLOB data.
- -Each value stored in an SQLite database (or manipulated by the -database engine) has one of the following storage classes:
-NULL. The value is a NULL value.
-INTEGER. The value is a signed integer, stored in 1, - 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
-REAL. The value is a floating point value, stored as - an 8-byte IEEE floating point number.
-TEXT. The value is a text string, stored using the - database encoding (UTF-8, UTF-16BE or UTF-16-LE).
-BLOB. The value is a blob of data, stored exactly as - it was input.
-As in SQLite version 2, any column in a version 3 database except an INTEGER -PRIMARY KEY may be used to store any type of value. The exception to -this rule is described below under 'Strict Affinity Mode'.
- -All values supplied to SQLite, whether as literals embedded in SQL -statements or values bound to pre-compiled SQL statements -are assigned a storage class before the SQL statement is executed. -Under circumstances described below, the -database engine may convert values between numeric storage classes -(INTEGER and REAL) and TEXT during query execution. -
- -Storage classes are initially assigned as follows:
-Values specified as literals as part of SQL statements are - assigned storage class TEXT if they are enclosed by single or double - quotes, INTEGER if the literal is specified as an unquoted number - with no decimal point or exponent, REAL if the literal is an - unquoted number with a decimal point or exponent and NULL if the - value is a NULL. Literals with storage class BLOB are specified - using the X'ABCD' notation.
-Values supplied using the sqlite3_bind_* APIs are assigned - the storage class that most closely matches the native type bound - (i.e. sqlite3_bind_blob() binds a value with storage class BLOB).
-The storage class of a value that is the result of an SQL scalar -operator depends on the outermost operator of the expression. -User-defined functions may return values with any storage class. It -is not generally possible to determine the storage class of the -result of an expression at compile time.
- - --In SQLite version 3, the type of a value is associated with the value -itself, not with the column or variable in which the value is stored. -(This is sometimes called - -manifest typing.) -All other SQL databases engines that we are aware of use the more -restrictive system of static typing where the type is associated with -the container, not the value. -
- --In order to maximize compatibility between SQLite and other database -engines, SQLite support the concept of "type affinity" on columns. -The type affinity of a column is the recommended type for data stored -in that column. The key here is that the type is recommended, not -required. Any column can still store any type of data, in theory. -It is just that some columns, given the choice, will prefer to use -one storage class over another. The preferred storage class for -a column is called its "affinity". -
- -Each column in an SQLite 3 database is assigned one of the -following type affinities:
-A column with TEXT affinity stores all data using storage classes -NULL, TEXT or BLOB. If numerical data is inserted into a column with -TEXT affinity it is converted to text form before being stored.
- -A column with NUMERIC affinity may contain values using all five -storage classes. When text data is inserted into a NUMERIC column, an -attempt is made to convert it to an integer or real number before it -is stored. If the conversion is successful, then the value is stored -using the INTEGER or REAL storage class. If the conversion cannot be -performed the value is stored using the TEXT storage class. No -attempt is made to convert NULL or blob values.
- -A column that uses INTEGER affinity behaves in the same way as a -column with NUMERIC affinity, except that if a real value with no -floating point component (or text value that converts to such) is -inserted it is converted to an integer and stored using the INTEGER -storage class.
- -A column with REAL affinity behaves like a column with NUMERIC -affinity except that it forces integer values into floating point -representation. (As an optimization, integer values are stored on -disk as integers in order to take up less space and are only converted -to floating point as the value is read out of the table.)
- -A column with affinity NONE does not prefer one storage class over -another. It makes no attempt to coerce data before -it is inserted.
- -The type affinity of a column is determined by the declared type -of the column, according to the following rules:
-If the datatype contains the string "INT" then it - is assigned INTEGER affinity.
- -If the datatype of the column contains any of the strings - "CHAR", "CLOB", or "TEXT" then that - column has TEXT affinity. Notice that the type VARCHAR contains the - string "CHAR" and is thus assigned TEXT affinity.
- -If the datatype for a column - contains the string "BLOB" or if - no datatype is specified then the column has affinity NONE.
- -If the datatype for a column - contains any of the strings "REAL", "FLOA", - or "DOUB" then the column has REAL affinity
- -Otherwise, the affinity is NUMERIC.
-If a table is created using a "CREATE TABLE <table> AS -SELECT..." statement, then all columns have no datatype specified -and they are given no affinity.
- --- - -CREATE TABLE t1( - t TEXT, - nu NUMERIC, - i INTEGER, - no BLOB -); - --- Storage classes for the following row: --- TEXT, REAL, INTEGER, TEXT -INSERT INTO t1 VALUES('500.0', '500.0', '500.0', '500.0'); - --- Storage classes for the following row: --- TEXT, REAL, INTEGER, REAL -INSERT INTO t1 VALUES(500.0, 500.0, 500.0, 500.0); --
Like SQLite version 2, version 3 -features the binary comparison operators '=', -'<', '<=', '>=' and '!=', an operation to test for set -membership, 'IN', and the ternary comparison operator 'BETWEEN'.
-The results of a comparison depend on the storage classes of the -two values being compared, according to the following rules:
-A value with storage class NULL is considered less than any - other value (including another value with storage class NULL).
- -An INTEGER or REAL value is less than any TEXT or BLOB value. - When an INTEGER or REAL is compared to another INTEGER or REAL, a - numerical comparison is performed.
- -A TEXT value is less than a BLOB value. When two TEXT values - are compared, the C library function memcmp() is usually used to - determine the result. However this can be overridden, as described - under 'User-defined collation Sequences' below.
- -When two BLOB values are compared, the result is always - determined using memcmp().
-SQLite may attempt to convert values between the numeric storage -classes (INTEGER and REAL) and TEXT before performing a comparison. -For binary comparisons, this is done in the cases enumerated below. -The term "expression" used in the bullet points below means any -SQL scalar expression or literal other than a column value. Note that -if X and Y.Z are a column names, then +X and +Y.Z are considered -expressions.
-When a column value is compared to the result of an - expression, the affinity of the column is applied to the result of - the expression before the comparison takes place.
- -When two column values are compared, if one column has - INTEGER or REAL or NUMERIC affinity and the other does not, - then NUMERIC affinity is applied to any values with storage - class TEXT extracted from the non-NUMERIC column.
- -When the results of two expressions are compared, no - conversions occur. The results are compared as is. If a string - is compared to a number, the number will always be less than the - string.
--In SQLite, the expression "a BETWEEN b AND c" is equivalent to "a >= b -AND a <= c", even if this means that different affinities are applied to -'a' in each of the comparisons required to evaluate the expression. -
- -Expressions of the type "a IN (SELECT b ....)" are handled by the three -rules enumerated above for binary comparisons (e.g. in a -similar manner to "a = b"). For example if 'b' is a column value -and 'a' is an expression, then the affinity of 'b' is applied to 'a' -before any comparisons take place.
- -SQLite treats the expression "a IN (x, y, z)" as equivalent to "a = +x OR -a = +y OR a = +z". The values to the right of the IN operator (the "x", "y", -and "z" values in this example) are considered to be expressions, even if they -happen to be column values. If the value of the left of the IN operator is -a column, then the affinity of that column is used. If the value is an -expression then no conversions occur. -
- ----CREATE TABLE t1( - a TEXT, - b NUMERIC, - c BLOB -); - --- Storage classes for the following row: --- TEXT, REAL, TEXT -INSERT INTO t1 VALUES('500', '500', '500'); - --- 60 and 40 are converted to '60' and '40' and values are compared as TEXT. -SELECT a < 60, a < 40 FROM t1; -1|0 - --- Comparisons are numeric. No conversions are required. -SELECT b < 60, b < 600 FROM t1; -0|1 - --- Both 60 and 600 (storage class NUMERIC) are less than '500' --- (storage class TEXT). -SELECT c < 60, c < 600 FROM t1; -0|0 --
All mathematical operators (which is to say, all operators other -than the concatenation operator "||") apply NUMERIC -affinity to all operands prior to being carried out. If one or both -operands cannot be converted to NUMERIC then the result of the -operation is NULL.
- -For the concatenation operator, TEXT affinity is applied to both -operands. If either operand cannot be converted to TEXT (because it -is NULL or a BLOB) then the result of the concatenation is NULL.
- -When values are sorted by an ORDER by clause, values with storage -class NULL come first, followed by INTEGER and REAL values -interspersed in numeric order, followed by TEXT values usually in -memcmp() order, and finally BLOB values in memcmp() order. No storage -class conversions occur before the sort.
- -When grouping values with the GROUP BY clause values with -different storage classes are considered distinct, except for INTEGER -and REAL values which are considered equal if they are numerically -equal. No affinities are applied to any values as the result of a -GROUP by clause.
- -The compound SELECT operators UNION, -INTERSECT and EXCEPT perform implicit comparisons between values. -Before these comparisons are performed an affinity may be applied to -each value. The same affinity, if any, is applied to all values that -may be returned in a single column of the compound SELECT result set. -The affinity applied is the affinity of the column returned by the -left most component SELECTs that has a column value (and not some -other kind of expression) in that position. If for a given compound -SELECT column none of the component SELECTs return a column value, no -affinity is applied to the values from that column before they are -compared.
- -The above sections describe the operation of the database engine -in 'normal' affinity mode. SQLite version 3 will feature two other affinity -modes, as follows:
-Strict affinity mode. In this mode if a conversion - between storage classes is ever required, the database engine - returns an error and the current statement is rolled back.
- -No affinity mode. In this mode no conversions between - storage classes are ever performed. Comparisons between values of - different storage classes (except for INTEGER and REAL) are always - false.
--By default, when SQLite compares two text values, the result of the -comparison is determined using memcmp(), regardless of the encoding of the -string. SQLite v3 provides the ability for users to supply arbitrary -comparison functions, known as user-defined collation sequences, to be used -instead of memcmp(). -
--Aside from the default collation sequence BINARY, implemented using -memcmp(), SQLite features one extra built-in collation sequences -intended for testing purposes, the NOCASE collation: -
--Each column of each table has a default collation type. If a collation type -other than BINARY is required, a COLLATE clause is specified as part of the -column definition to define it. -
- --Whenever two text values are compared by SQLite, a collation sequence is -used to determine the results of the comparison according to the following -rules. Sections 3 and 5 of this document describe the circumstances under -which such a comparison takes place. -
- --For binary comparison operators (=, <, >, <= and >=) if either operand is a -column, then the default collation type of the column determines the -collation sequence to use for the comparison. If both operands are columns, -then the collation type for the left operand determines the collation -sequence used. If neither operand is a column, then the BINARY collation -sequence is used. For the purposes of this paragraph, a column name -preceded by one or more unary "+" operators is considered a column name. -
- --The expression "x BETWEEN y and z" is equivalent to "x >= y AND x <= -z". The expression "x IN (SELECT y ...)" is handled in the same way as the -expression "x = y" for the purposes of determining the collation sequence -to use. The collation sequence used for expressions of the form "x IN (y, z -...)" is the default collation type of x if x is a column, or BINARY -otherwise. -
- --An ORDER BY clause that is part of a SELECT -statement may be assigned a collation sequence to be used for the sort -operation explicitly. In this case the explicit collation sequence is -always used. Otherwise, if the expression sorted by an ORDER BY clause is -a column, then the default collation type of the column is used to -determine sort order. If the expression is not a column, then the BINARY -collation sequence is used. -
- --The examples below identify the collation sequences that would be used to -determine the results of text comparisons that may be performed by various -SQL statements. Note that a text comparison may not be required, and no -collation sequence used, in the case of numeric, blob or NULL values. -
--- -} -footer $rcsid diff --git a/www/datatypes.tcl b/www/datatypes.tcl deleted file mode 100644 index 1b45fb6757..0000000000 --- a/www/datatypes.tcl +++ /dev/null @@ -1,243 +0,0 @@ -# -# Run this script to generated a datatypes.html output file -# -set rcsid {$Id: datatypes.tcl,v 1.8 2004/10/10 17:24:55 drh Exp $} -source common.tcl -header {Datatypes In SQLite version 2} -puts { --CREATE TABLE t1( - a, -- default collation type BINARY - b COLLATE BINARY, -- default collation type BINARY - c COLLATE REVERSE, -- default collation type REVERSE - d COLLATE NOCASE -- default collation type NOCASE -); - --- Text comparison is performed using the BINARY collation sequence. -SELECT (a = b) FROM t1; - --- Text comparison is performed using the NOCASE collation sequence. -SELECT (d = a) FROM t1; - --- Text comparison is performed using the BINARY collation sequence. -SELECT (a = d) FROM t1; - --- Text comparison is performed using the REVERSE collation sequence. -SELECT ('abc' = c) FROM t1; - --- Text comparison is performed using the REVERSE collation sequence. -SELECT (c = 'abc') FROM t1; - --- Grouping is performed using the NOCASE collation sequence (i.e. values --- 'abc' and 'ABC' are placed in the same group). -SELECT count(*) GROUP BY d FROM t1; - --- Grouping is performed using the BINARY collation sequence. -SELECT count(*) GROUP BY (d || '') FROM t1; - --- Sorting is performed using the REVERSE collation sequence. -SELECT * FROM t1 ORDER BY c; - --- Sorting is performed using the BINARY collation sequence. -SELECT * FROM t1 ORDER BY (c || ''); - --- Sorting is performed using the NOCASE collation sequence. -SELECT * FROM t1 ORDER BY c COLLATE NOCASE; - --
-SQLite is "typeless". This means that you can store any -kind of data you want in any column of any table, regardless of the -declared datatype of that column. -(See the one exception to this rule in section 2.0 below.) -This behavior is a feature, not -a bug. A database is suppose to store and retrieve data and it -should not matter to the database what format that data is in. -The strong typing system found in most other SQL engines and -codified in the SQL language spec is a misfeature - -it is an example of the implementation showing through into the -interface. SQLite seeks to overcome this misfeature by allowing -you to store any kind of data into any kind of column and by -allowing flexibility in the specification of datatypes. -
- --A datatype to SQLite is any sequence of zero or more names -optionally followed by a parenthesized lists of one or two -signed integers. Notice in particular that a datatype may -be zero or more names. That means that an empty -string is a valid datatype as far as SQLite is concerned. -So you can declare tables where the datatype of each column -is left unspecified, like this: -
- -- --CREATE TABLE ex1(a,b,c); -
-Even though SQLite allows the datatype to be omitted, it is -still a good idea to include it in your CREATE TABLE statements, -since the data type often serves as a good hint to other -programmers about what you intend to put in the column. And -if you ever port your code to another database engine, that -other engine will probably require a datatype of some kind. -SQLite accepts all the usual datatypes. For example: -
- -- --CREATE TABLE ex2( - a VARCHAR(10), - b NVARCHAR(15), - c TEXT, - d INTEGER, - e FLOAT, - f BOOLEAN, - g CLOB, - h BLOB, - i TIMESTAMP, - j NUMERIC(10,5) - k VARYING CHARACTER (24), - l NATIONAL VARYING CHARACTER(16) -); -
-And so forth. Basically any sequence of names optionally followed by -one or two signed integers in parentheses will do. -
- --One exception to the typelessness of SQLite is a column whose type -is INTEGER PRIMARY KEY. (And you must use "INTEGER" not "INT". -A column of type INT PRIMARY KEY is typeless just like any other.) -INTEGER PRIMARY KEY columns must contain a 32-bit signed integer. Any -attempt to insert non-integer data will result in an error. -
- --INTEGER PRIMARY KEY columns can be used to implement the equivalent -of AUTOINCREMENT. If you try to insert a NULL into an INTEGER PRIMARY -KEY column, the column will actually be filled with a integer that is -one greater than the largest key already in the table. Or if the -largest key is 2147483647, then the column will be filled with a -random integer. Either way, the INTEGER PRIMARY KEY column will be -assigned a unique integer. You can retrieve this integer using -the sqlite_last_insert_rowid() API function or using the -last_insert_rowid() SQL function in a subsequent SELECT statement. -
- --SQLite is typeless for the purpose of deciding what data is allowed -to be stored in a column. But some notion of type comes into play -when sorting and comparing data. For these purposes, a column or -an expression can be one of two types: numeric and text. -The sort or comparison may give different results depending on which -type of data is being sorted or compared. -
- --If data is of type text then the comparison is determined by -the standard C data comparison functions memcmp() or -strcmp(). The comparison looks at bytes from two inputs one -by one and returns the first non-zero difference. -Strings are '\000' terminated so shorter -strings sort before longer strings, as you would expect. -
- --For numeric data, this situation is more complex. If both inputs -look like well-formed numbers, then they are converted -into floating point values using atof() and compared numerically. -If one input is not a well-formed number but the other is, then the -number is considered to be less than the non-number. If neither inputs -is a well-formed number, then strcmp() is used to do the -comparison. -
- --Do not be confused by the fact that a column might have a "numeric" -datatype. This does not mean that the column can contain only numbers. -It merely means that if the column does contain a number, that number -will sort in numerical order. -
- --For both text and numeric values, NULL sorts before any other value. -A comparison of any value against NULL using operators like "<" or -">=" is always false. -
- --For SQLite version 2.6.3 and earlier, all values used the numeric datatype. -The text datatype appears in version 2.7.0 and later. In the sequel it -is assumed that you are using version 2.7.0 or later of SQLite. -
- --For an expression, the datatype of the result is often determined by -the outermost operator. For example, arithmetic operators ("+", "*", "%") -always return a numeric results. The string concatenation operator -("||") returns a text result. And so forth. If you are ever in doubt -about the datatype of an expression you can use the special typeof() -SQL function to determine what the datatype is. For example: -
- -- --sqlite> SELECT typeof('abc'+123); -numeric -sqlite> SELECT typeof('abc'||123); -text -
-For table columns, the datatype is determined by the type declaration -of the CREATE TABLE statement. The datatype is text if and only if -the type declaration contains one or more of the following strings: -
- --BLOB- -
-CHAR
-CLOB -TEXT -
-The search for these strings in the type declaration is case insensitive, -of course. If any of the above strings occur anywhere in the type -declaration, then the datatype of the column is text. Notice that -the type "VARCHAR" contains "CHAR" as a substring so it is considered -text.
- -If none of the strings above occur anywhere in the type declaration, -then the datatype is numeric. Note in particular that the datatype for columns -with an empty type declaration is numeric. -
- --Consider the following two command sequences: -
- -- --CREATE TABLE t1(a INTEGER UNIQUE); CREATE TABLE t2(b TEXT UNIQUE); -INSERT INTO t1 VALUES('0'); INSERT INTO t2 VALUES(0); -INSERT INTO t1 VALUES('0.0'); INSERT INTO t2 VALUES(0.0); -
In the sequence on the left, the second insert will fail. In this case, -the strings '0' and '0.0' are treated as numbers since they are being -inserted into a numeric column but 0==0.0 which violates the uniqueness -constraint. However, the second insert in the right-hand sequence works. In -this case, the constants 0 and 0.0 are treated a strings which means that -they are distinct.
- -SQLite always converts numbers into double-precision (64-bit) floats -for comparison purposes. This means that a long sequence of digits that -differ only in insignificant digits will compare equal if they -are in a numeric column but will compare unequal if they are in a text -column. We have:
- -- --INSERT INTO t1 INSERT INTO t2 - VALUES('12345678901234567890'); VALUES(12345678901234567890); -INSERT INTO t1 INSERT INTO t2 - VALUES('12345678901234567891'); VALUES(12345678901234567891); -
As before, the second insert on the left will fail because the comparison -will convert both strings into floating-point number first and the only -difference in the strings is in the 20-th digit which exceeds the resolution -of a 64-bit float. In contrast, the second insert on the right will work -because in that case, the numbers being inserted are strings and are -compared using memcmp().
- --Numeric and text types make a difference for the DISTINCT keyword too: -
- -- --CREATE TABLE t3(a INTEGER); CREATE TABLE t4(b TEXT); -INSERT INTO t3 VALUES('0'); INSERT INTO t4 VALUES(0); -INSERT INTO t3 VALUES('0.0'); INSERT INTO t4 VALUES(0.0); -SELECT DISTINCT * FROM t3; SELECT DISTINCT * FROM t4; -
-The SELECT statement on the left returns a single row since '0' and '0.0' -are treated as numbers and are therefore indistinct. But the SELECT -statement on the right returns two rows since 0 and 0.0 are treated -a strings which are different.
-} -footer $rcsid diff --git a/www/different.tcl b/www/different.tcl deleted file mode 100644 index 1858e6fb38..0000000000 --- a/www/different.tcl +++ /dev/null @@ -1,224 +0,0 @@ -set rcsid {$Id: different.tcl,v 1.8 2006/12/18 14:12:21 drh Exp $} -source common.tcl -header {Distinctive Features Of SQLite} -puts { --This page highlights some of the characteristics of SQLite that are -unusual and which make SQLite different from many other SQL -database engines. -
-} -proc feature {tag name text} { - puts "" - puts "$name
\n" - puts "$text\n" -} - -feature zeroconfig {Zero-Configuration} { - SQLite does not need to be "installed" before it is used. - There is no "setup" procedure. There is no - server process that needs to be started, stopped, or configured. - There is - no need for an administrator to create a new database instance or assign - access permissions to users. - SQLite uses no configuration files. - Nothing needs to be done to tell the system that SQLite is running. - No actions are required to recover after a system crash or power failure. - There is nothing to troubleshoot. -
- SQLite just works. -
- Other more familiar database engines run great once you get them going. - But doing the initial installation and configuration can be - intimidatingly complex. -} - -feature serverless {Serverless} { - Most SQL database engines are implemented as a separate server - process. Programs that want to access the database communicate - with the server using some kind of interprocess communcation - (typically TCP/IP) to send requests to the server and to receive - back results. SQLite does not work this way. With SQLite, the - process that wants to access the database reads and writes - directly from the database files on disk. There is no intermediary - server process. -
- There are advantages and disadvantages to being serverless. The - main advantage is that there is no separate server process - to install, setup, configure, initialize, manage, and troubleshoot. - This is one reason why SQLite is a "zero-configuration" database - engine. Programs that use SQLite require no administrative support - for setting up the database engine before they are run. Any program - that is able to access the disk is able to use an SQLite database. -
- On the other hand, a database engine that uses a server can provide - better protection from bugs in the client application - stray pointers - in a client cannot corrupt memory on the server. And because a server - is a single persistent process, it is able control database access with - more precision, allowing for finer grain locking and better concurrancy. -
- Most SQL database engines are client/server based. Of those that are - serverless, SQLite is the only one that this author knows of that - allows multiple applications to access the same database at the same time. -} - -feature onefile {Single Database File} { - An SQLite database is a single ordinary disk file that can be located - anywhere in the directory hierarchy. If SQLite can read - the disk file then it can read anything in the database. If the disk - file and its directory are writable, then SQLite can change anything - in the database. Database files can easily be copied onto a USB - memory stick or emailed for sharing. -
- Other SQL database engines tend to store data as a large collection of - files. Often these files are in a standard location that only the - database engine itself can access. This makes the data more secure, - but also makes it harder to access. Some SQL database engines provide - the option of writing directly to disk and bypassing the filesystem - all together. This provides added performance, but at the cost of - considerable setup and maintenance complexity. -} - -feature small {Compact} { - When optimized for size, the whole SQLite library with everything enabled - is less than 225KiB in size (as measured on an ix86 using the "size" - utility from the GNU compiler suite.) Unneeded features can be disabled - at compile-time to further reduce the size of the library to under - 170KiB if desired. -
- Most other SQL database engines are much larger than this. IBM boasts - that it's recently released CloudScape database engine is "only" a 2MiB - jar file - 10 times larger than SQLite even after it is compressed! - Firebird boasts that it's client-side library is only 350KiB. That's - 50% larger than SQLite and does not even contain the database engine. - The Berkeley DB library from Sleepycat is 450KiB and it omits SQL - support, providing the programmer with only simple key/value pairs. -} - -feature typing {Manifest typing} { - Most SQL database engines use static typing. A datatype is associated - with each column in a table and only values of that particular datatype - are allowed to be stored in that column. SQLite relaxes this restriction - by using manifest typing. - In manifest typing, the datatype is a property of the value itself, not - of the column in which the value is stored. - SQLite thus allows the user to store - any value of any datatype into any column regardless of the declared type - of that column. (There are some exceptions to this rule: An INTEGER - PRIMARY KEY column may only store integers. And SQLite attempts to coerce - values into the declared datatype of the column when it can.) -
- As far as we can tell, the SQL language specification allows the use - of manifest typing. Nevertheless, most other SQL database engines are - statically typed and so some people - feel that the use of manifest typing is a bug in SQLite. But the authors - of SQLite feel very strongly that this is a feature. The use of manifest - typing in SQLite is a deliberate design decision which has proven in practice - to make SQLite more reliable and easier to use, especially when used in - combination with dynamically typed programming languages such as Tcl and - Python. -} - -feature flex {Variable-length records} { - Most other SQL database engines allocated a fixed amount of disk space - for each row in most tables. They play special tricks for handling - BLOBs and CLOBs which can be of wildly varying length. But for most - tables, if you declare a column to be a VARCHAR(100) then the database - engine will allocate - 100 bytes of disk space regardless of how much information you actually - store in that column. -
- SQLite, in contrast, use only the amount of disk space actually - needed to store the information in a row. If you store a single - character in a VARCHAR(100) column, then only a single byte of disk - space is consumed. (Actually two bytes - there is some overhead at - the beginning of each column to record its datatype and length.) -
- The use of variable-length records by SQLite has a number of advantages. - It results in smaller database files, obviously. It also makes the - database run faster, since there is less information to move to and from - disk. And, the use of variable-length records makes it possible for - SQLite to employ manifest typing instead of static typing. -} - -feature readable {Readable source code} { - The source code to SQLite is designed to be readable and accessible to - the average programmer. All procedures and data structures and many - automatic variables are carefully commented with useful information about - what they do. Boilerplate commenting is omitted. -} - -feature vdbe {SQL statements compile into virtual machine code} { - Every SQL database engine compiles each SQL statement into some kind of - internal data structure which is then used to carry out the work of the - statement. But in most SQL engines that internal data structure is a - complex web of interlinked structures and objects. In SQLite, the compiled - form of statements is a short program in a machine-language like - representation. Users of the database can view this - virtual machine language - by prepending the EXPLAIN keyword - to a query. -
- The use of a virtual machine in SQLite has been a great benefit to - library's development. The virtual machine provides a crisp, well-defined - junction between the front-end of SQLite (the part that parses SQL - statements and generates virtual machine code) and the back-end (the - part that executes the virtual machine code and computes a result.) - The virtual machine allows the developers to see clearly and in an - easily readable form what SQLite is trying to do with each statement - it compiles, which is a tremendous help in debugging. - Depending on how it is compiled, SQLite also has the capability of - tracing the execution of the virtual machine - printing each - virtual machine instruction and its result as it executes. -} - -#feature binding {Tight bindings to dynamic languages} { -# Because it is embedded, SQLite can have a much tighter and more natural -# binding to high-level dynamic languages such as Tcl, Perl, Python, -# PHP, and Ruby. -# For example, -#} - -feature license {Public domain} { - The source code for SQLite is in the public domain. No claim of copyright - is made on any part of the core source code. (The documentation and test - code is a different matter - some sections of documentation and test logic - are governed by open-sources licenses.) All contributors to the - SQLite core software have signed affidavits specifically disavowing any - copyright interest in the code. This means that anybody is able to legally - do anything they want with the SQLite source code. -
- There are other SQL database engines with liberal licenses that allow - the code to be broadly and freely used. But those other engines are - still governed by copyright law. SQLite is different in that copyright - law simply does not apply. -
- The source code files for other SQL database engines typically begin - with a comment describing your license rights to view and copy that file. - The SQLite source code contains no license since it is not governed by - copyright. Instead of a license, the SQLite source code offers a blessing: -
- May you do good and not evil-} - -feature extensions {SQL language extensions} { - SQLite provides a number of enhancements to the SQL language - not normally found in other database engines. - The EXPLAIN keyword and manifest typing have already been mentioned - above. SQLite also provides statements such as - REPLACE and the - ON CONFLICT clause that allow for - added control over the resolution of constraint conflicts. - SQLite supports ATTACH and - DETACH commands that allow multiple - independent databases to be used together in the same query. - And SQLite defines APIs that allows the user to add new - SQL functions - and collating sequences. -} - - -footer $rcsid diff --git a/www/direct1b.gif b/www/direct1b.gif deleted file mode 100644 index 8999a84e5c4c43c98ec6c260dbe44235ccf9eded..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc-jL100001 literal 11439 zc-qC7_dnH-`~RP3I>$Wr&M6}@BI1}GE3##WI!5NPG9uy}95Wmv6cs5WDx0iqN65@5 zD|_!E>G-_f-+$tJ|KYlRecZ0wbzP6^cIn)@iBWWD2C;#TCxQQf)575hBoY9SbhPwL zC^}X;CN3rhW)>DUHWp4UW`1UN9zGr(9$_Dk$sm$|sbx%p-Ic`pfF5EhjL03jiv zi((T0AuJ_>zK#}D7Q8GYCn_s1F0Ul1s3IpPr>d%YO-
- May you find forgiveness for yourself and forgive others
- May you share freely, never taking more than you give. -
^`y0k2tSU~AI_JKt8cNn`T3a!n+H_7BwBpQh>_A>
-All SQLite source code is maintained in a
-CVS repository that is
-available for read-only access by anyone. You can
-interactively view the
-repository contents and download individual files
-by visiting
-
-http://www.sqlite.org/cvstrac/dir?d=sqlite.
-To access the repository directly, use the following
-commands:
-
-When the first command prompts you for a password, enter "anonymous".
-
-To access the SQLite version 2.8 sources, begin by getting the 3.0
-tree as described above. Then update to the "version_2" branch
-as follows:
-
-This note was contributed by
-Bill Saunders. Thanks, Bill!
-
-
-To compile the SQLite Tcl extension into a dynamically loaded module
-I did the following:
- Do a standard compile
-(I had a dir called bld at the same level as sqlite ie
- /root/bld
- /root/sqlite
-I followed the directions and did a standard build in the bld
-directory)
-Now do the following in the bld directory
-Available Documentation
-
-}
-
-proc doc {name url desc} {
- puts {
}
-footer $rcsid
diff --git a/www/download.tcl b/www/download.tcl
deleted file mode 100644
index b47cd5b2a2..0000000000
--- a/www/download.tcl
+++ /dev/null
@@ -1,236 +0,0 @@
-#
-# Run this TCL script to generate HTML for the download.html file.
-#
-set rcsid {$Id: download.tcl,v 1.27 2007/05/08 18:30:36 drh Exp $}
-source common.tcl
-header {SQLite Download Page}
-
-puts {
- }
-}
-
-doc {Appropriate Uses For SQLite} {whentouse.html} {
- This document describes situations where SQLite is an approriate
- database engine to use versus situations where a client/server
- database engine might be a better choice.
-}
-
-doc {Distinctive Features} {different.html} {
- This document enumerates and describes some of the features of
- SQLite that make it different from other SQL database engines.
-}
-
-doc {SQLite In 5 Minutes Or Less} {quickstart.html} {
- A very quick introduction to programming with SQLite.
-}
-
-doc {SQL Syntax} {lang.html} {
- This document describes the SQL language that is understood by
- SQLite.
-}
-doc {Version 3 C/C++ API}
- regsub -all { +} $name {\ } name
- puts "$name "
- puts {}
- puts { }
- puts $desc
- puts {
Reference} {capi3ref.html} {
- This document describes each API function separately.
-}
-doc {Sharing Cache Mode} {sharedcache.html} {
- Version 3.3.0 and later supports the ability for two or more
- database connections to share the same page and schema cache.
- This feature is useful for certain specialized applications.
-}
-doc {Tcl API} {tclsqlite.html} {
- A description of the TCL interface bindings for SQLite.
-}
-
-doc {How SQLite Implements Atomic Commit} {ac/atomiccommit.html} {
- A description of the logic within SQLite that implements
- transactions with atomic commit, even in the face of power
- failures.
-}
-doc {Moving From SQLite 3.4 to 3.5} {34to35.html} {
- A document describing the differences between SQLite version 3.4.2
- and 3.5.0.
-}
-
-doc {Pragma commands} {pragma.html} {
- This document describes SQLite performance tuning options and other
- special purpose database commands.
-}
-doc {SQLite Version 3} {version3.html} {
- A summary of of the changes between SQLite version 2.8 and SQLite version 3.0.
-}
-doc {Version 3 C/C++ API} {capi3.html} {
- A description of the C/C++ interface bindings for SQLite version 3.0.0
- and following.
-}
-doc {Version 3 DataTypes } {datatype3.html} {
- SQLite version 3 introduces the concept of manifest typing, where the
- type of a value is associated with the value itself, not the column that
- it is stored in.
- This page describes data typing for SQLite version 3 in further detail.
-}
-
-doc {Locking And Concurrency
In SQLite Version 3} {lockingv3.html} {
- A description of how the new locking code in version 3 increases
- concurrancy and decreases the problem of writer starvation.
-}
-
-doc {Overview Of The Optimizer} {optoverview.html} {
- A quick overview of the various query optimizations that are
- attempted by the SQLite code generator.
-}
-
-
-doc {Null Handling} {nulls.html} {
- Different SQL database engines handle NULLs in different ways. The
- SQL standards are ambiguous. This document describes how SQLite handles
- NULLs in comparison with other SQL database engines.
-}
-
-doc {Copyright} {copyright.html} {
- SQLite is in the public domain. This document describes what that means
- and the implications for contributors.
-}
-
-doc {Unsupported SQL} {omitted.html} {
- This page describes features of SQL that SQLite does not support.
-}
-
-doc {Version 2 C/C++ API} {c_interface.html} {
- A description of the C/C++ interface bindings for SQLite through version
- 2.8
-}
-
-
-doc {Version 2 DataTypes } {datatypes.html} {
- A description of how SQLite version 2 handles SQL datatypes.
- Short summary: Everything is a string.
-}
-
-doc {Release History} {changes.html} {
- A chronology of SQLite releases going back to version 1.0.0
-}
-
-
-doc {Speed Comparison} {speed.html} {
- The speed of version 2.7.6 of SQLite is compared against PostgreSQL and
- MySQL.
-}
-
-doc {Architecture} {arch.html} {
- An architectural overview of the SQLite library, useful for those who want
- to hack the code.
-}
-
-doc {VDBE Tutorial} {vdbe.html} {
- The VDBE is the subsystem within SQLite that does the actual work of
- executing SQL statements. This page describes the principles of operation
- for the VDBE in SQLite version 2.7. This is essential reading for anyone
- who want to modify the SQLite sources.
-}
-
-doc {VDBE Opcodes} {opcode.html} {
- This document is an automatically generated description of the various
- opcodes that the VDBE understands. Programmers can use this document as
- a reference to better understand the output of EXPLAIN listings from
- SQLite.
-}
-
-doc {Compilation Options} {compile.html} {
- This document describes the compile time options that may be set to
- modify the default behaviour of the library or omit optional features
- in order to reduce binary size.
-}
-
-doc {Backwards Compatibility} {formatchng.html} {
- This document details all of the incompatible changes to the SQLite
- file format that have occurred since version 1.0.0.
-}
-
-puts {SQLite Download Page
-
-}
-
-proc Product {pattern desc} {
- regsub {V[23]} $pattern {*} p3
- regsub V2 $pattern {(2[0-9a-z._]+)} pattern
- regsub V3 $pattern {(3[0-9a-z._]+)} pattern
- set p2 [string map {* .*} $pattern]
- set flist [glob -nocomplain $p3]
- foreach file [lsort -dict $flist] {
- if {![regexp ^$p2\$ $file all version]} continue
- regsub -all _ $version . version
- set size [file size $file]
- set units bytes
- if {$size>1024*1024} {
- set size [format %.2f [expr {$size/(1024.0*1024.0)}]]
- set units MiB
- } elseif {$size>1024} {
- set size [format %.2f [expr {$size/(1024.0)}]]
- set units KiB
- }
- puts "
-
-
- "
- }
-}
-cd doc
-
-proc Heading {title} {
- puts ""
- puts " "
- puts "$file "
- puts "
($size $units)"
- regsub -all VERSION $desc $version d2
- puts " [string trim $d2] "
-}
-
-Heading {Precompiled Binaries for Linux}
-
-Product sqlite3-V3.bin.gz {
- A command-line program for accessing and modifying
- SQLite version 3.* databases.
- See the documentation for additional information.
-}
-
-Product sqlite-V3.bin.gz {
- A command-line program for accessing and modifying
- SQLite databases.
- See the documentation for additional information.
-}
-
-Product tclsqlite-V3.so.gz {
- Bindings for Tcl/Tk.
- You can import this shared library into either
- tclsh or wish to get SQLite database access from Tcl/Tk.
- See the documentation for details.
-}
-
-Product sqlite-V3.so.gz {
- A precompiled shared-library for Linux without the TCL bindings.
-}
-
-Product fts1-V3.so.gz {
- A precompiled
- FTS1 Module
- for Linux.
-}
-
-Product fts2-V3.so.gz {
- A precompiled
- FTS2 Module
- for Linux.
-}
-
-Product sqlite-devel-V3.i386.rpm {
- RPM containing documentation, header files, and static library for
- SQLite version VERSION.
-}
-Product sqlite-V3-1.i386.rpm {
- RPM containing shared libraries and the sqlite command-line
- program for SQLite version VERSION.
-}
-
-Product sqlite*_analyzer-V3.bin.gz {
- An analysis program for database files compatible with SQLite
- version VERSION and later.
-}
-
-Heading {Precompiled Binaries For Windows}
-
-Product sqlite-V3.zip {
- A command-line program for accessing and modifing SQLite databases.
- See the documentation for additional information.
-}
-Product tclsqlite-V3.zip {
- Bindings for Tcl/Tk.
- You can import this shared library into either
- tclsh or wish to get SQLite database access from Tcl/Tk.
- See the documentation for details.
-}
-Product sqlitedll-V3.zip {
- This is a DLL of the SQLite library without the TCL bindings.
- The only external dependency is MSVCRT.DLL.
-}
-
-Product fts1dll-V3.zip {
- A precompiled
- FTS1 Module
- for win32.
-}
-
-Product fts2dll-V3.zip {
- A precompiled
- FTS2 Module
- for win32.
-}
-
-Product sqlite*_analyzer-V3.zip {
- An analysis program for database files compatible with SQLite version
- VERSION and later.
-}
-
-
-Heading {Source Code}
-
-Product {sqlite-V3.tar.gz} {
- A tarball of the complete source tree for SQLite version VERSION
- including all of the documentation.
-}
-
-Product {sqlite-source-V3.zip} {
- This ZIP archive contains preprocessed C code for the SQLite library as
- individual source files.
- Unlike the tarballs below, all of the preprocessing and automatic
- code generation has already been done on these C code files, so they
- can be converted to object code directly with any ordinary C compiler.
-}
-
-Product {sqlite-amalgamation-V3.zip} {
- This ZIP archive contains all preprocessed C code combined into a
- single source file (the
-
- amalgamation).
-}
-
-Product {sqlite-V3-tea.tar.gz} {
- A tarball of proprocessed source code together with a
- Tcl Extension Architecture (TEA)
- compatible configure script and makefile.
-}
-
-Product {sqlite-V3.src.rpm} {
- An RPM containing complete source code for SQLite version VERSION
-}
-
-Heading {Cross-Platform Binaries}
-
-Product {sqlite-V3.kit} {
- A starkit containing
- precompiled SQLite binaries and Tcl bindings for Linux-x86, Windows,
- and Mac OS-X ppc and x86.
-}
-
-Heading {Historical Binaries And Source Code}
-
-Product sqlite-V2.bin.gz {
- A command-line program for accessing and modifying
- SQLite version 2.* databases on Linux-x86.
-}
-Product sqlite-V2.zip {
- A command-line program for accessing and modifying
- SQLite version 2.* databases on win32.
-}
-
-Product sqlite*_analyzer-V2.bin.gz {
- An analysis program for version 2.* database files on Linux-x86
-}
-Product sqlite*_analyzer-V2.zip {
- An analysis program for version 2.* database files on win32.
-}
-Product {sqlite-source-V2.zip} {
- This ZIP archive contains C source code for the SQLite library
- version VERSION.
-}
-
-
-
-
-puts {
-$title Direct Access To The Sources Via Anonymous CVS
-
-
-
-
-cvs -d :pserver:anonymous@www.sqlite.org:/sqlite login
-cvs -d :pserver:anonymous@www.sqlite.org:/sqlite checkout sqlite
-
-
-}
-
-footer $rcsid
diff --git a/www/dynload.tcl b/www/dynload.tcl
deleted file mode 100644
index 3e12b7f9cb..0000000000
--- a/www/dynload.tcl
+++ /dev/null
@@ -1,70 +0,0 @@
-#
-# Run this Tcl script to generate the dynload.html file.
-#
-set rcsid {$Id: dynload.tcl,v 1.1 2001/02/11 16:58:22 drh Exp $}
-
-puts {
-
-
-cvs update -r version_2
-
-How To Build A Dynamically Loaded Tcl Extension
-
}
-puts {
-
-gcc -shared -I. -lgdbm ../sqlite/src/tclsqlite.c libsqlite.a -o sqlite.so
-
-This should produce the file sqlite.so in the bld directory
-Create a pkgIndex.tcl file that contains this line - -
-package ifneeded sqlite 1.0 [list load [file join $dir sqlite.so]] -
-To use this put sqlite.so and pkgIndex.tcl in the same directory
-From that directory start wish
-Execute the following tcl command (tells tcl where to fine loadable -modules) -
-lappend auto_path [exec pwd] -
-Load the package -
-package require sqlite -
-Have fun....
Short answer: A column declared INTEGER PRIMARY KEY will - autoincrement.
- -Here is the long answer: - If you declare a column of a table to be INTEGER PRIMARY KEY, then - whenever you insert a NULL - into that column of the table, the NULL is automatically converted - into an integer which is one greater than the largest value of that - column over all other rows in the table, or 1 if the table is empty. - (If the largest possible integer key, 9223372036854775807, then an - unused key value is chosen at random.) - For example, suppose you have a table like this: -
--CREATE TABLE t1( - a INTEGER PRIMARY KEY, - b INTEGER -); -
With this table, the statement
---INSERT INTO t1 VALUES(NULL,123); -
is logically equivalent to saying:
-- --INSERT INTO t1 VALUES((SELECT max(a) FROM t1)+1,123); -
There is a new API function named - - sqlite3_last_insert_rowid() which will return the integer key - for the most recent insert operation.
- -Note that the integer key is one greater than the largest - key that was in the table just prior to the insert. The new key - will be unique over all keys currently in the table, but it might - overlap with keys that have been previously deleted from the - table. To create keys that are unique over the lifetime of the - table, add the AUTOINCREMENT keyword to the INTEGER PRIMARY KEY - declaration. Then the key chosen will be one more than than the - largest key that has ever existed in that table. If the largest - possible key has previously existed in that table, then the INSERT - will fail with an SQLITE_FULL error code.
-} - -faq { - What datatypes does SQLite support? -} { -See http://www.sqlite.org/datatype3.html.
-} - -faq { - SQLite lets me insert a string into a database column of type integer! -} { -This is a feature, not a bug. SQLite does not enforce data type - constraints. Any data can be - inserted into any column. You can put arbitrary length strings into - integer columns, floating point numbers in boolean columns, or dates - in character columns. The datatype you assign to a column in the - CREATE TABLE command does not restrict what data can be put into - that column. Every column is able to hold - an arbitrary length string. (There is one exception: Columns of - type INTEGER PRIMARY KEY may only hold a 64-bit signed integer. - An error will result - if you try to put anything other than an integer into an - INTEGER PRIMARY KEY column.)
- -But SQLite does use the declared type of a column as a hint - that you prefer values in that format. So, for example, if a - column is of type INTEGER and you try to insert a string into - that column, SQLite will attempt to convert the string into an - integer. If it can, it inserts the integer instead. If not, - it inserts the string. This feature is sometimes - call type or column affinity. -
-} - -faq { - Why doesn't SQLite allow me to use '0' and '0.0' as the primary - key on two different rows of the same table? -} { -Your primary key must have a numeric type. Change the datatype of - your primary key to TEXT and it should work.
- -Every row must have a unique primary key. For a column with a - numeric type, SQLite thinks that '0' and '0.0' are the - same value because they compare equal to one another numerically. - (See the previous question.) Hence the values are not unique.
-} - - -faq { - Can multiple applications or multiple instances of the same - application access a single database file at the same time? -} { -Multiple processes can have the same database open at the same - time. Multiple processes can be doing a SELECT - at the same time. But only one process can be making changes to - the database at any moment in time, however.
- -SQLite uses reader/writer locks to control access to the database. - (Under Win95/98/ME which lacks support for reader/writer locks, a - probabilistic simulation is used instead.) - But use caution: this locking mechanism might - not work correctly if the database file is kept on an NFS filesystem. - This is because fcntl() file locking is broken on many NFS implementations. - You should avoid putting SQLite database files on NFS if multiple - processes might try to access the file at the same time. On Windows, - Microsoft's documentation says that locking may not work under FAT - filesystems if you are not running the Share.exe daemon. People who - have a lot of experience with Windows tell me that file locking of - network files is very buggy and is not dependable. If what they - say is true, sharing an SQLite database between two or more Windows - machines might cause unexpected problems.
- -We are aware of no other embedded SQL database engine that - supports as much concurrancy as SQLite. SQLite allows multiple processes - to have the database file open at once, and for multiple processes to - read the database at once. When any process wants to write, it must - lock the entire database file for the duration of its update. But that - normally only takes a few milliseconds. Other processes just wait on - the writer to finish then continue about their business. Other embedded - SQL database engines typically only allow a single process to connect to - the database at once.
- -However, client/server database engines (such as PostgreSQL, MySQL, - or Oracle) usually support a higher level of concurrency and allow - multiple processes to be writing to the same database at the same time. - This is possible in a client/server database because there is always a - single well-controlled server process available to coordinate access. - If your application has a need for a lot of concurrency, then you should - consider using a client/server database. But experience suggests that - most applications need much less concurrency than their designers imagine. -
- -When SQLite tries to access a file that is locked by another - process, the default behavior is to return SQLITE_BUSY. You can - adjust this behavior from C code using the - sqlite3_busy_handler() or - sqlite3_busy_timeout() - API functions.
-} - -faq { - Is SQLite threadsafe? -} { -Yes. Sometimes. In order to be thread-safe, SQLite must be compiled - with the SQLITE_THREADSAFE preprocessor macro set to 1. Both the windows - and linux precompiled binaries in the distribution are compiled this way. - If you are unsure if the SQLite library you are linking against is compiled - to be threadsafe you can call the - sqlite3_threadsafe() - interface to find out. -
- -Prior to version 3.3.1, - an sqlite3 structure could only be used in the same thread - that called sqlite3_open - to create it. - You could not open a - database in one thread then pass the handle off to another thread for - it to use. This was due to limitations (bugs?) in many common threading - implementations such as on RedHat9. Specifically, an fcntl() lock - created by one thread cannot be removed or modified by a different - thread on the troublesome systems. And since SQLite uses fcntl() - locks heavily for concurrency control, serious problems arose if you - start moving database connections across threads.
- -The restriction on moving database connections across threads - was relaxed somewhat in version 3.3.1. With that and subsequent - versions, it is safe to move a connection handle across threads - as long as the connection is not holding any fcntl() locks. You - can safely assume that no locks are being held if no - transaction is pending and all statements have been finalized.
- -Under UNIX, you should not carry an open SQLite database across - a fork() system call into the child process. Problems will result - if you do.
-} - -faq { - How do I list all tables/indices contained in an SQLite database -} { -If you are running the sqlite3 command-line access program - you can type ".tables" to get a list of all tables. Or you - can type ".schema" to see the complete database schema including - all tables and indices. Either of these commands can be followed by - a LIKE pattern that will restrict the tables that are displayed.
- -From within a C/C++ program (or a script using Tcl/Ruby/Perl/Python - bindings) you can get access to table and index names by doing a SELECT - on a special table named "SQLITE_MASTER". Every SQLite database - has an SQLITE_MASTER table that defines the schema for the database. - The SQLITE_MASTER table looks like this:
---CREATE TABLE sqlite_master ( - type TEXT, - name TEXT, - tbl_name TEXT, - rootpage INTEGER, - sql TEXT -); -
For tables, the type field will always be 'table' and the - name field will be the name of the table. So to get a list of - all tables in the database, use the following SELECT command:
---SELECT name FROM sqlite_master -WHERE type='table' -ORDER BY name; -
For indices, type is equal to 'index', name is the - name of the index and tbl_name is the name of the table to which - the index belongs. For both tables and indices, the sql field is - the text of the original CREATE TABLE or CREATE INDEX statement that - created the table or index. For automatically created indices (used - to implement the PRIMARY KEY or UNIQUE constraints) the sql field - is NULL.
- -The SQLITE_MASTER table is read-only. You cannot change this table - using UPDATE, INSERT, or DELETE. The table is automatically updated by - CREATE TABLE, CREATE INDEX, DROP TABLE, and DROP INDEX commands.
- -Temporary tables do not appear in the SQLITE_MASTER table. Temporary - tables and their indices and triggers occur in another special table - named SQLITE_TEMP_MASTER. SQLITE_TEMP_MASTER works just like SQLITE_MASTER - except that it is only visible to the application that created the - temporary tables. To get a list of all tables, both permanent and - temporary, one can use a command similar to the following: -
-} - -faq { - Are there any known size limits to SQLite databases? -} { --SELECT name FROM - (SELECT * FROM sqlite_master UNION ALL - SELECT * FROM sqlite_temp_master) -WHERE type='table' -ORDER BY name -
See limits.html for a full discussion of - the limits of SQLite.
-} - -faq { - What is the maximum size of a VARCHAR in SQLite? -} { -SQLite does not enforce the length of a VARCHAR. You can declare - a VARCHAR(10) and SQLite will be happy to let you put 500 characters - in it. And it will keep all 500 characters intact - it never truncates. -
-} - -faq { - Does SQLite support a BLOB type? -} { -SQLite versions 3.0 and later allow you to store BLOB data in any - column, even columns that are declared to hold some other type.
-} - -faq { - How do I add or delete columns from an existing table in SQLite. -} { -SQLite has limited - ALTER TABLE support that you can - use to add a column to the end of a table or to change the name of - a table. - If you what make more complex changes the structure of a table, - you will have to recreate the - table. You can save existing data to a temporary table, drop the - old table, create the new table, then copy the data back in from - the temporary table.
- -For example, suppose you have a table named "t1" with columns - names "a", "b", and "c" and that you want to delete column "c" from - this table. The following steps illustrate how this could be done: -
- --} - -faq { - I deleted a lot of data but the database file did not get any - smaller. Is this a bug? -} { --BEGIN TRANSACTION; -CREATE TEMPORARY TABLE t1_backup(a,b); -INSERT INTO t1_backup SELECT a,b FROM t1; -DROP TABLE t1; -CREATE TABLE t1(a,b); -INSERT INTO t1 SELECT a,b FROM t1_backup; -DROP TABLE t1_backup; -COMMIT; -
No. When you delete information from an SQLite database, the - unused disk space is added to an internal "free-list" and is reused - the next time you insert data. The disk space is not lost. But - neither is it returned to the operating system.
- -If you delete a lot of data and want to shrink the database file, - run the VACUUM command. - VACUUM will reconstruct - the database from scratch. This will leave the database with an empty - free-list and a file that is minimal in size. Note, however, that the - VACUUM can take some time to run (around a half second per megabyte - on the Linux box where SQLite is developed) and it can use up to twice - as much temporary disk space as the original file while it is running. -
- -As of SQLite version 3.1, an alternative to using the VACUUM command - is auto-vacuum mode, enabled using the - auto_vacuum pragma.
-} - -faq { - Can I use SQLite in my commercial product without paying royalties? -} { -Yes. SQLite is in the - public domain. No claim of ownership is made - to any part of the code. You can do anything you want with it.
-} - -faq { - How do I use a string literal that contains an embedded single-quote (') - character? -} { -The SQL standard specifies that single-quotes in strings are escaped - by putting two single quotes in a row. SQL works like the Pascal programming - language in the regard. SQLite follows this standard. Example: -
- --} - -faq {What is an SQLITE_SCHEMA error, and why am I getting one?} { -- INSERT INTO xyz VALUES('5 O''clock'); -
An SQLITE_SCHEMA error is returned when a - prepared SQL statement is no longer valid and cannot be executed. - When this occurs, the statement must be recompiled from SQL using - the - sqlite3_prepare() API. - In SQLite version 3, an SQLITE_SCHEMA error can - only occur when using the - sqlite3_prepare()/sqlite3_step()/sqlite3_finalize() - API to execute SQL, not when using the - sqlite3_exec(). This was not - the case in version 2.
- -The most common reason for a prepared statement to become invalid - is that the schema of the database was modified after the SQL was - prepared (possibly by another process). The other reasons this can - happen are:
-In all cases, the solution is to recompile the statement from SQL - and attempt to execute it again. Because a prepared statement can be - invalidated by another process changing the database schema, all code - that uses the - sqlite3_prepare()/sqlite3_step()/sqlite3_finalize() - API should be prepared to handle SQLITE_SCHEMA errors. An example - of one approach to this follows:
- --} - -faq {Why does ROUND(9.95,1) return 9.9 instead of 10.0? - Shouldn't 9.95 round up?} { -- - int rc; - sqlite3_stmt *pStmt; - char zSql[] = "SELECT ....."; - - do { - /* Compile the statement from SQL. Assume success. */ - sqlite3_prepare(pDb, zSql, -1, &pStmt, 0); - - while( SQLITE_ROW==sqlite3_step(pStmt) ){ - /* Do something with the row of available data */ - } - - /* Finalize the statement. If an SQLITE_SCHEMA error has - ** occured, then the above call to sqlite3_step() will have - ** returned SQLITE_ERROR. sqlite3_finalize() will return - ** SQLITE_SCHEMA. In this case the loop will execute again. - */ - rc = sqlite3_finalize(pStmt); - } while( rc==SQLITE_SCHEMA ); - -
SQLite uses binary arithmetic and in binary, there is no - way to write 9.95 in a finite number of bits. The closest to - you can get to 9.95 in a 64-bit IEEE float (which is what - SQLite uses) is 9.949999999999999289457264239899814128875732421875. - So when you type "9.95", SQLite really understands the number to be - the much longer value shown above. And that value rounds down.
- -This kind of problem comes up all the time when dealing with - floating point binary numbers. The general rule to remember is - that most fractional numbers that have a finite representation in decimal - (a.k.a "base-10") - do not have a finite representation in binary (a.k.a "base-2"). - And so they are - approximated using the closest binary number available. That - approximation is usually very close, but it will be slightly off - and in some cases can cause your results to be a little different - from what you might expect.
-} - -# End of questions and answers. -############# - -puts {($i) [lindex $faq($i) 0]
\n" - puts "[lindex $faq($i) 1]\n" -} - -puts {} -footer $rcsid diff --git a/www/fileformat.tcl b/www/fileformat.tcl deleted file mode 100644 index d143f0839b..0000000000 --- a/www/fileformat.tcl +++ /dev/null @@ -1,785 +0,0 @@ -# -# Run this script to generated a fileformat.html output file -# -set rcsid {$Id: fileformat.tcl,v 1.13 2004/10/10 17:24:55 drh Exp $} -source common.tcl -header {SQLite Database File Format (Version 2)} -puts { -
-This document describes the disk file format for SQLite versions 2.1 -through 2.8. SQLite version 3.0 and following uses a very different -format which is described separately. -
- --SQLite is implemented in layers. -(See the architecture description.) -The format of database files is determined by three different -layers in the architecture. -
- --We will describe each layer beginning with the bottom (pager) -layer and working upwards. -
- --An SQLite database consists of -"pages" of data. Each page is 1024 bytes in size. -Pages are numbered beginning with 1. -A page number of 0 is used to indicate "no such page" in the -B-Tree and Schema layers. -
- --The pager layer is responsible for implementing transactions -with atomic commit and rollback. It does this using a separate -journal file. Whenever a new transaction is started, a journal -file is created that records the original state of the database. -If the program terminates before completing the transaction, the next -process to open the database can use the journal file to restore -the database to its original state. -
- --The journal file is located in the same directory as the database -file and has the same name as the database file but with the -characters "-journal" appended. -
- --The pager layer does not impose any content restrictions on the -main database file. As far as the pager is concerned, each page -contains 1024 bytes of arbitrary data. But there is structure to -the journal file. -
- --A journal file begins with 8 bytes as follows: -0xd9, 0xd5, 0x05, 0xf9, 0x20, 0xa1, 0x63, and 0xd6. -Processes that are attempting to rollback a journal use these 8 bytes -as a sanity check to make sure the file they think is a journal really -is a valid journal. Prior version of SQLite used different journal -file formats. The magic numbers for these prior formats are different -so that if a new version of the library attempts to rollback a journal -created by an earlier version, it can detect that the journal uses -an obsolete format and make the necessary adjustments. This article -describes only the newest journal format - supported as of version -2.8.0. -
- --Following the 8 byte prefix is a three 4-byte integers that tell us -the number of pages that have been committed to the journal, -a magic number used for -sanity checking each page, and the -original size of the main database file before the transaction was -started. The number of committed pages is used to limit how far -into the journal to read. The use of the checksum magic number is -described below. -The original size of the database is used to restore the database -file back to its original size. -The size is expressed in pages (1024 bytes per page). -
- --All three integers in the journal header and all other multi-byte -numbers used in the journal file are big-endian. -That means that the most significant byte -occurs first. That way, a journal file that is -originally created on one machine can be rolled back by another -machine that uses a different byte order. So, for example, a -transaction that failed to complete on your big-endian SparcStation -can still be rolled back on your little-endian Linux box. -
- --After the 8-byte prefix and the three 4-byte integers, the -journal file consists of zero or more page records. Each page -record is a 4-byte (big-endian) page number followed by 1024 bytes -of data and a 4-byte checksum. -The data is the original content of the database page -before the transaction was started. So to roll back the transaction, -the data is simply written into the corresponding page of the -main database file. Pages can appear in the journal in any order, -but they are guaranteed to appear only once. All page numbers will be -between 1 and the maximum specified by the page size integer that -appeared at the beginning of the journal. -
- --The so-called checksum at the end of each record is not really a -checksum - it is the sum of the page number and the magic number which -was the second integer in the journal header. The purpose of this -value is to try to detect journal corruption that might have occurred -because of a power loss or OS crash that occurred which the journal -file was being written to disk. It could have been the case that the -meta-data for the journal file, specifically the size of the file, had -been written to the disk so that when the machine reboots it appears that -file is large enough to hold the current record. But even though the -file size has changed, the data for the file might not have made it to -the disk surface at the time of the OS crash or power loss. This means -that after reboot, the end of the journal file will contain quasi-random -garbage data. The checksum is an attempt to detect such corruption. If -the checksum does not match, that page of the journal is not rolled back. -
- --Here is a summary of the journal file format: -
- --The B-Tree layer builds on top of the pager layer to implement -one or more separate b-trees all in the same disk file. The -algorithms used are taken from Knuth's The Art Of Computer -Programming.
- --Page 1 of a database contains a header string used for sanity -checking, a few 32-bit words of configuration data, and a pointer -to the beginning of a list of unused pages in the database. -All other pages in the -database are either pages of a b-tree, overflow pages, or unused -pages on the freelist. -
- --Each b-tree page contains zero or more database entries. -Each entry has an unique key of one or more bytes and data of -zero or more bytes. -Both the key and data are arbitrary byte sequences. The combination -of key and data are collectively known as "payload". The current -implementation limits the amount of payload in a single entry to -1048576 bytes. This limit can be raised to 16777216 by adjusting -a single #define in the source code and recompiling. But most entries -contain less than a hundred bytes of payload so a megabyte limit seems -more than enough. -
- --Up to 238 bytes of payload for an entry can be held directly on -a b-tree page. Any additional payload is contained on a linked list -of overflow pages. This limit on the amount of payload held directly -on b-tree pages guarantees that each b-tree page can hold at least -4 entries. In practice, most entries are smaller than 238 bytes and -thus most pages can hold more than 4 entries. -
- --A single database file can hold any number of separate, independent b-trees. -Each b-tree is identified by its root page, which never changes. -Child pages of the b-tree may change as entries are added and removed -and pages split and combine. But the root page always stays the same. -The b-tree itself does not record which pages are root pages and which -are not. That information is handled entirely at the schema layer. -
- --Page 1 begins with the following 48-byte string: -
- -- --** This file contains an SQLite 2.1 database ** -
-If you count the number of characters in the string above, you will -see that there are only 47. A '\000' terminator byte is added to -bring the total to 48. -
- --A frequent question is why the string says version 2.1 when (as -of this writing) we are up to version 2.7.0 of SQLite and any -change to the second digit of the version is suppose to represent -a database format change. The answer to this is that the B-tree -layer has not changed any since version 2.1. There have been -database format changes since version 2.1 but those changes have -all been in the schema layer. Because the format of the b-tree -layer is unchanged since version 2.1.0, the header string still -says version 2.1. -
- --After the format string is a 4-byte integer used to determine the -byte-order of the database. The integer has a value of -0xdae37528. If this number is expressed as 0xda, 0xe3, 0x75, 0x28, then -the database is in a big-endian format and all 16 and 32-bit integers -elsewhere in the b-tree layer are also big-endian. If the number is -expressed as 0x28, 0x75, 0xe3, and 0xda, then the database is in a -little-endian format and all other multi-byte numbers in the b-tree -layer are also little-endian. -Prior to version 2.6.3, the SQLite engine was only able to read databases -that used the same byte order as the processor they were running on. -But beginning with 2.6.3, SQLite can read or write databases in any -byte order. -
- --After the byte-order code are six 4-byte integers. Each integer is in the -byte order determined by the byte-order code. The first integer is the -page number for the first page of the freelist. If there are no unused -pages in the database, then this integer is 0. The second integer is -the number of unused pages in the database. The last 4 integers are -not used by the b-tree layer. These are the so-called "meta" values that -are passed up to the schema layer -and used there for configuration and format version information. -All bytes of page 1 past beyond the meta-value integers are unused -and are initialized to zero. -
- --Here is a summary of the information contained on page 1 in the b-tree layer: -
- --Conceptually, a b-tree page contains N database entries and N+1 pointers -to other b-tree pages. -
- --- --
-- -Ptr -
0Entry -
0Ptr -
1Entry -
1... -Ptr -
N-1Entry -
N-1Ptr -
N
-The entries are arranged in increasing order. That is, the key to -Entry 0 is less than the key to Entry 1, and the key to Entry 1 is -less than the key of Entry 2, and so forth. The pointers point to -pages containing additional entries that have keys in between the -entries on either side. So Ptr 0 points to another b-tree page that -contains entries that all have keys less than Key 0, and Ptr 1 -points to a b-tree pages where all entries have keys greater than Key 0 -but less than Key 1, and so forth. -
- --Each b-tree page in SQLite consists of a header, zero or more "cells" -each holding a single entry and pointer, and zero or more "free blocks" -that represent unused space on the page. -
- --The header on a b-tree page is the first 8 bytes of the page. -The header contains the value -of the right-most pointer (Ptr N) and the byte offset into the page -of the first cell and the first free block. The pointer is a 32-bit -value and the offsets are each 16-bit values. We have: -
- --- --
-- -0 -1 -2 -3 -4 -5 -6 -7 -- -Ptr N -Cell 0 -Freeblock 0 -
-The 1016 bytes of a b-tree page that come after the header contain -cells and freeblocks. All 1016 bytes are covered by either a cell -or a freeblock. -
- --The cells are connected in a linked list. Cell 0 contains Ptr 0 and -Entry 0. Bytes 4 and 5 of the header point to Cell 0. Cell 0 then -points to Cell 1 which contains Ptr 1 and Entry 1. And so forth. -Cells vary in size. Every cell has a 12-byte header and at least 4 -bytes of payload space. Space is allocated to payload in increments -of 4 bytes. Thus the minimum size of a cell is 16 bytes and up to -63 cells can fit on a single page. The size of a cell is always a multiple -of 4 bytes. -A cell can have up to 238 bytes of payload space. If -the payload is more than 238 bytes, then an additional 4 byte page -number is appended to the cell which is the page number of the first -overflow page containing the additional payload. The maximum size -of a cell is thus 254 bytes, meaning that a least 4 cells can fit into -the 1016 bytes of space available on a b-tree page. -An average cell is usually around 52 to 100 bytes in size with about -10 or 20 cells to a page. -
- --The data layout of a cell looks like this: -
- --- --
-- -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 ... 249 -250 -251 -252 -253 -- -Ptr -Keysize -
(low)Next -Ksz -
(hi)Dsz -
(hi)Datasize -
(low)Payload -Overflow -
Pointer
-The first four bytes are the pointer. The size of the key is a 24-bit -where the upper 8 bits are taken from byte 8 and the lower 16 bits are -taken from bytes 4 and 5 (or bytes 5 and 4 on little-endian machines.) -The size of the data is another 24-bit value where the upper 8 bits -are taken from byte 9 and the lower 16 bits are taken from bytes 10 and -11 or 11 and 10, depending on the byte order. Bytes 6 and 7 are the -offset to the next cell in the linked list of all cells on the current -page. This offset is 0 for the last cell on the page. -
- --The payload itself can be any number of bytes between 1 and 1048576. -But space to hold the payload is allocated in 4-byte chunks up to -238 bytes. If the entry contains more than 238 bytes of payload, then -additional payload data is stored on a linked list of overflow pages. -A 4 byte page number is appended to the cell that contains the first -page of this linked list. -
- --Each overflow page begins with a 4-byte value which is the -page number of the next overflow page in the list. This value is -0 for the last page in the list. The remaining -1020 bytes of the overflow page are available for storing payload. -Note that a full page is allocated regardless of the number of overflow -bytes stored. Thus, if the total payload for an entry is 239 bytes, -the first 238 are stored in the cell and the overflow page stores just -one byte. -
- --The structure of an overflow page looks like this: -
- --- --
-- -0 -1 -2 -3 -4 ... 1023 -- -Next Page -Overflow Data -
-All space on a b-tree page which is not used by the header or by cells -is filled by freeblocks. Freeblocks, like cells, are variable in size. -The size of a freeblock is at least 4 bytes and is always a multiple of -4 bytes. -The first 4 bytes contain a header and the remaining bytes -are unused. The structure of the freeblock is as follows: -
- --- --
-- -0 -1 -2 -3 -4 ... 1015 -- -Size -Next -Unused -
-Freeblocks are stored in a linked list in increasing order. That is -to say, the first freeblock occurs at a lower index into the page than -the second free block, and so forth. The first 2 bytes of the header -are an integer which is the total number of bytes in the freeblock. -The second 2 bytes are the index into the page of the next freeblock -in the list. The last freeblock has a Next value of 0. -
- --When a new b-tree is created in a database, the root page of the b-tree -consist of a header and a single 1016 byte freeblock. As entries are -added, space is carved off of that freeblock and used to make cells. -When b-tree entries are deleted, the space used by their cells is converted -into freeblocks. Adjacent freeblocks are merged, but the page can still -become fragmented. The b-tree code will occasionally try to defragment -the page by moving all cells to the beginning and constructing a single -freeblock at the end to take up all remaining space. -
- --When information is removed from an SQLite database such that one or -more pages are no longer needed, those pages are added to a list of -free pages so that they can be reused later when new information is -added. This subsection describes the structure of this freelist. -
- --The 32-bit integer beginning at byte-offset 52 in page 1 of the database -contains the address of the first page in a linked list of free pages. -If there are no free pages available, this integer has a value of 0. -The 32-bit integer at byte-offset 56 in page 1 contains the number of -free pages on the freelist. -
- --The freelist contains a trunk and many branches. The trunk of -the freelist is composed of overflow pages. That is to say, each page -contains a single 32-bit integer at byte offset 0 which -is the page number of the next page on the freelist trunk. -The payload area -of each trunk page is used to record pointers to branch pages. -The first 32-bit integer in the payload area of a trunk page -is the number of branch pages to follow (between 0 and 254) -and each subsequent 32-bit integer is a page number for a branch page. -The following diagram shows the structure of a trunk freelist page: -
- --- --
-- -0 -1 -2 -3 -4 -5 -6 -7 -8 ... 1023 -- -Next trunk page -# of branch pages -Page numbers for branch pages -
-It is important to note that only the pages on the trunk of the freelist -contain pointers to other pages. The branch pages contain no -data whatsoever. The fact that the branch pages are completely -blank allows for an important optimization in the paging layer. When -a branch page is removed from the freelist to be reused, it is not -necessary to write the original content of that page into the rollback -journal. The branch page contained no data to begin with, so there is -no need to restore the page in the event of a rollback. Similarly, -when a page is not longer needed and is added to the freelist as a branch -page, it is not necessary to write the content of that page -into the database file. -Again, the page contains no real data so it is not necessary to record the -content of that page. By reducing the amount of disk I/O required, -these two optimizations allow some database operations -to go four to six times faster than they would otherwise. -
- --The schema layer implements an SQL database on top of one or more -b-trees and keeps track of the root page numbers for all b-trees. -Where the b-tree layer provides only unformatted data storage with -a unique key, the schema layer allows each entry to contain multiple -columns. The schema layer also allows indices and non-unique key values. -
- --The schema layer implements two separate data storage abstractions: -tables and indices. Each table and each index uses its own b-tree -but they use the b-tree capabilities in different ways. For a table, -the b-tree key is a unique 4-byte integer and the b-tree data is the -content of the table row, encoded so that columns can be separately -extracted. For indices, the b-tree key varies in size depending on the -size of the fields being indexed and the b-tree data is empty. -
- -Each row of an SQL table is stored in a single b-tree entry. -The b-tree key is a 4-byte big-endian integer that is the ROWID -or INTEGER PRIMARY KEY for that table row. -The key is stored in a big-endian format so -that keys will sort in numerical order using memcmp() function.
- -The content of a table row is stored in the data portion of -the corresponding b-tree table. The content is encoded to allow -individual columns of the row to be extracted as necessary. Assuming -that the table has N columns, the content is encoded as N+1 offsets -followed by N column values, as follows: -
- --- --
-- -offset 0 -offset 1 -... -offset N-1 -offset N -value 0 -value 1 -... -value N-1 -
-The offsets can be either 8-bit, 16-bit, or 24-bit integers depending -on how much data is to be stored. If the total size of the content -is less than 256 bytes then 8-bit offsets are used. If the total size -of the b-tree data is less than 65536 then 16-bit offsets are used. -24-bit offsets are used otherwise. Offsets are always little-endian, -which means that the least significant byte occurs first. -
- --Data is stored as a nul-terminated string. Any empty string consists -of just the nul terminator. A NULL value is an empty string with no -nul-terminator. Thus a NULL value occupies zero bytes and an empty string -occupies 1 byte. -
- --Column values are stored in the order that they appear in the CREATE TABLE -statement. The offsets at the beginning of the record contain the -byte index of the corresponding column value. Thus, Offset 0 contains -the byte index for Value 0, Offset 1 contains the byte offset -of Value 1, and so forth. The number of bytes in a column value can -always be found by subtracting offsets. This allows NULLs to be -recovered from the record unambiguously. -
- --Most columns are stored in the b-tree data as described above. -The one exception is column that has type INTEGER PRIMARY KEY. -INTEGER PRIMARY KEY columns correspond to the 4-byte b-tree key. -When an SQL statement attempts to read the INTEGER PRIMARY KEY, -the 4-byte b-tree key is read rather than information out of the -b-tree data. But there is still an Offset associated with the -INTEGER PRIMARY KEY, just like any other column. But the Value -associated with that offset is always NULL. -
- --SQL indices are implement using a b-tree in which the key is used -but the data is always empty. The purpose of an index is to map -one or more column values into the ROWID for the table entry that -contains those column values. -
- --Each b-tree in an index consists of one or more column values followed -by a 4-byte ROWID. Each column value is nul-terminated (even NULL values) -and begins with a single character that indicates the datatype for that -column value. Only three datatypes are supported: NULL, Number, and -Text. NULL values are encoded as the character 'a' followed by the -nul terminator. Numbers are encoded as the character 'b' followed by -a string that has been crafted so that sorting the string using memcmp() -will sort the corresponding numbers in numerical order. (See the -sqliteRealToSortable() function in util.c of the SQLite sources for -additional information on this encoding.) Numbers are also nul-terminated. -Text values consists of the character 'c' followed by a copy of the -text string and a nul-terminator. These encoding rules result in -NULLs being sorted first, followed by numerical values in numerical -order, followed by text values in lexicographical order. -
- --The database schema is stored in the database in a special tabled named -"sqlite_master" and which always has a root b-tree page number of 2. -This table contains the original CREATE TABLE, -CREATE INDEX, CREATE VIEW, and CREATE TRIGGER statements used to define -the database to begin with. Whenever an SQLite database is opened, -the sqlite_master table is scanned from beginning to end and -all the original CREATE statements are played back through the parser -in order to reconstruct an in-memory representation of the database -schema for use in subsequent command parsing. For each CREATE TABLE -and CREATE INDEX statement, the root page number for the corresponding -b-tree is also recorded in the sqlite_master table so that SQLite will -know where to look for the appropriate b-tree. -
- --SQLite users can query the sqlite_master table just like any other table -in the database. But the sqlite_master table cannot be directly written. -The sqlite_master table is automatically updated in response to CREATE -and DROP statements but it cannot be changed using INSERT, UPDATE, or -DELETE statements as that would risk corrupting the database. -
- --SQLite stores temporary tables and indices in a separate -file from the main database file. The temporary table database file -is the same structure as the main database file. The schema table -for the temporary tables is stored on page 2 just as in the main -database. But the schema table for the temporary database named -"sqlite_temp_master" instead of "sqlite_master". Other than the -name change, it works exactly the same. -
- --The nine 32-bit integers that are stored beginning at byte offset -60 of Page 1 in the b-tree layer are passed up into the schema layer -and used for versioning and configuration information. The meaning -of the first four integers is shown below. The other five are currently -unused. -
- --The first meta-value, the schema version number, is used to detect when -the schema of the database is changed by a CREATE or DROP statement. -Recall that when a database is first opened the sqlite_master table is -scanned and an internal representation of the tables, indices, views, -and triggers for the database is built in memory. This internal -representation is used for all subsequent SQL command parsing and -execution. But what if another process were to change the schema -by adding or removing a table, index, view, or trigger? If the original -process were to continue using the old schema, it could potentially -corrupt the database by writing to a table that no longer exists. -To avoid this problem, the schema version number is changed whenever -a CREATE or DROP statement is executed. Before each command is -executed, the current schema version number for the database file -is compared against the schema version number from when the sqlite_master -table was last read. If those numbers are different, the internal -schema representation is erased and the sqlite_master table is reread -to reconstruct the internal schema representation. -(Calls to sqlite_exec() generally return SQLITE_SCHEMA when this happens.) -
- --The second meta-value is the schema format version number. This -number tells what version of the schema layer should be used to -interpret the file. There have been changes to the schema layer -over time and this number is used to detect when an older database -file is being processed by a newer version of the library. -As of this writing (SQLite version 2.7.0) the current format version -is "4". -
- --The third meta-value is the recommended pager cache size as set -by the DEFAULT_CACHE_SIZE pragma. If the value is positive it -means that synchronous behavior is enable (via the DEFAULT_SYNCHRONOUS -pragma) and if negative it means that synchronous behavior is -disabled. -
- --The fourth meta-value is safety level added in version 2.8.0. -A value of 1 corresponds to a SYNCHRONOUS setting of OFF. In other -words, SQLite does not pause to wait for journal data to reach the disk -surface before overwriting pages of the database. A value of 2 corresponds -to a SYNCHRONOUS setting of NORMAL. A value of 3 corresponds to a -SYNCHRONOUS setting of FULL. If the value is 0, that means it has not -been initialized so the default synchronous setting of NORMAL is used. -
-} -footer $rcsid diff --git a/www/formatchng.tcl b/www/formatchng.tcl deleted file mode 100644 index 83a2dcfd03..0000000000 --- a/www/formatchng.tcl +++ /dev/null @@ -1,285 +0,0 @@ -# -# Run this Tcl script to generate the formatchng.html file. -# -set rcsid {$Id: formatchng.tcl,v 1.20 2007/09/03 20:32:45 drh Exp $ } -source common.tcl -header {File Format Changes in SQLite} -puts { --Every effort is made to keep SQLite fully backwards compatible from -one release to the next. Rarely, however, some -enhancements or bug fixes may require a change to -the underlying file format. When this happens and you -must convert the contents of your -databases into a portable ASCII representation using the old version -of the library then reload the data using the new version of the -library. -
- --You can tell if you should reload your databases by comparing the -version numbers of the old and new libraries. If the first digit -of the version number is different, then a reload of the database will -be required. If the second digit changes, newer versions of SQLite -will be able to read and write older database files, but older versions -of the library may have difficulty reading or writing newer database -files. -For example, upgrading from -version 2.8.14 to 3.0.0 requires a reload. Going from -version 3.0.8 to 3.1.0 is backwards compatible but not necessarily -forwards compatible. -
- --The following table summarizes the SQLite file format changes that have -occurred since version 1.0.0: -
- --- --
-- -Version Change -Approx. Date -Description Of File Format Change -- -1.0.32 to 2.0.0 -2001-Sep-20 -Version 1.0.X of SQLite used the GDBM library as its backend - interface to the disk. Beginning in version 2.0.0, GDBM was replaced - by a custom B-Tree library written especially for SQLite. The new - B-Tree backend is twice as fast as GDBM, supports atomic commits and - rollback, and stores an entire database in a single disk file instead - using a separate file for each table as GDBM does. The two - file formats are not even remotely similar. -- -2.0.8 to 2.1.0 -2001-Nov-12 -The same basic B-Tree format is used but the details of the - index keys were changed in order to provide better query - optimization opportunities. Some of the headers were also changed in order - to increase the maximum size of a row from 64KB to 24MB. -- - This change is an exception to the version number rule described above - in that it is neither forwards or backwards compatible. A complete - reload of the database is required. This is the only exception.
- -2.1.7 to 2.2.0 -2001-Dec-21 -Beginning with version 2.2.0, SQLite no longer builds an index for - an INTEGER PRIMARY KEY column. Instead, it uses that column as the actual - B-Tree key for the main table. Version 2.2.0 and later of the library - will automatically detect when it is reading a 2.1.x database and will - disable the new INTEGER PRIMARY KEY feature. In other words, version - 2.2.x is backwards compatible to version 2.1.x. But version 2.1.x is not - forward compatible with version 2.2.x. If you try to open - a 2.2.x database with an older 2.1.x library and that database contains - an INTEGER PRIMARY KEY, you will likely get a coredump. If the database - schema does not contain any INTEGER PRIMARY KEYs, then the version 2.1.x - and version 2.2.x database files will be identical and completely - interchangeable.
-- -2.2.5 to 2.3.0 -2002-Jan-30 -Beginning with version 2.3.0, SQLite supports some additional syntax - (the "ON CONFLICT" clause) in the CREATE TABLE and CREATE INDEX statements - that are stored in the SQLITE_MASTER table. If you create a database that - contains this new syntax, then try to read that database using version 2.2.5 - or earlier, the parser will not understand the new syntax and you will get - an error. Otherwise, databases for 2.2.x and 2.3.x are interchangeable. -- -2.3.3 to 2.4.0 -2002-Mar-10 -Beginning with version 2.4.0, SQLite added support for views. - Information about views is stored in the SQLITE_MASTER table. If an older - version of SQLite attempts to read a database that contains VIEW information - in the SQLITE_MASTER table, the parser will not understand the new syntax - and initialization will fail. Also, the - way SQLite keeps track of unused disk blocks in the database file - changed slightly. - If an older version of SQLite attempts to write a database that - was previously written by version 2.4.0 or later, then it may leak disk - blocks. -- -2.4.12 to 2.5.0 -2002-Jun-17 -Beginning with version 2.5.0, SQLite added support for triggers. - Information about triggers is stored in the SQLITE_MASTER table. If an older - version of SQLite attempts to read a database that contains a CREATE TRIGGER - in the SQLITE_MASTER table, the parser will not understand the new syntax - and initialization will fail. - -- -2.5.6 to 2.6.0 -2002-July-17 -A design flaw in the layout of indices required a file format change - to correct. This change appeared in version 2.6.0. -- - If you use version 2.6.0 or later of the library to open a database file - that was originally created by version 2.5.6 or earlier, an attempt to - rebuild the database into the new format will occur automatically. - This can take some time for a large database. (Allow 1 or 2 seconds - per megabyte of database under Unix - longer under Windows.) This format - conversion is irreversible. It is strongly suggested - that you make a backup copy of older database files prior to opening them - with version 2.6.0 or later of the library, in case there are errors in - the format conversion logic.
- - Version 2.6.0 or later of the library cannot open read-only database - files from version 2.5.6 or earlier, since read-only files cannot be - upgraded to the new format.
-- -2.6.3 to 2.7.0 -2002-Aug-13 -- Beginning with version 2.7.0, SQLite understands two different - datatypes: text and numeric. Text data sorts in memcmp() order. - Numeric data sorts in numerical order if it looks like a number, - or in memcmp() order if it does not.
- -When SQLite version 2.7.0 or later opens a 2.6.3 or earlier database, - it assumes all columns of all tables have type "numeric". For 2.7.0 - and later databases, columns have type "text" if their datatype - string contains the substrings "char" or "clob" or "blob" or "text". - Otherwise they are of type "numeric".
- -Because "text" columns have a different sort order from numeric, - indices on "text" columns occur in a different order for version - 2.7.0 and later database. Hence version 2.6.3 and earlier of SQLite - will be unable to read a 2.7.0 or later database. But version 2.7.0 - and later of SQLite will read earlier databases.
-- -2.7.6 to 2.8.0 -2003-Feb-14 -- Version 2.8.0 introduces a change to the format of the rollback - journal file. The main database file format is unchanged. Versions - 2.7.6 and earlier can read and write 2.8.0 databases and vice versa. - Version 2.8.0 can rollback a transaction that was started by version - 2.7.6 and earlier. But version 2.7.6 and earlier cannot rollback a - transaction started by version 2.8.0 or later.
- -The only time this would ever be an issue is when you have a program - using version 2.8.0 or later that crashes with an incomplete - transaction, then you try to examine the database using version 2.7.6 or - earlier. The 2.7.6 code will not be able to read the journal file - and thus will not be able to rollback the incomplete transaction - to restore the database.
-- -2.8.14 to 3.0.0 -2004-Jun-18 -- Version 3.0.0 is a major upgrade for SQLite that incorporates - support for UTF-16, BLOBs, and a more compact encoding that results - in database files that are typically 25% to 50% smaller. The new file - format is very different and is completely incompatible with the - version 2 file format.
-- -3.0.8 to 3.1.0 -2005-Jan-21 -- Version 3.1.0 adds support for - autovacuum mode. - Prior versions of SQLite will be able to read an autovacuumed - database but will not be able to write it. If autovaccum is disabled - (which is the default condition) - then databases are fully forwards and backwards compatible.
-- -3.1.6 to 3.2.0 -2005-Mar-19 -- Version 3.2.0 adds support for the - ALTER TABLE ADD COLUMN - command. A database that has been modified by this command can - not be read by a version of SQLite prior to 3.1.4. Running - VACUUM - after the ALTER TABLE - restores the database to a format such that it can be read by earlier - SQLite versions.
-- -3.2.8 to 3.3.0 -2006-Jan-10 -- Version 3.3.0 adds support for descending indices and - uses a new encoding for boolean values that requires - less disk space. Version 3.3.0 can read and write database - files created by prior versions of SQLite. But prior versions - of SQLite will not be able to read or write databases created - by Version 3.3.0
-If you need backwards and forwards capatibility, you can - compile with -DSQLITE_DEFAULT_FILE_FORMAT=1. Or at runtime - you can say "PRAGMA legacy_file_format=ON" prior to creating - a new database file
-Once a database file is created, its format is fixed. So - a database file created by SQLite 3.2.8 and merely modified - by version 3.3.0 or later will retain the old format. Except, - the VACUUM command recreates the database so running VACUUM - on 3.3.0 or later will change the file format to the latest - edition.
-- -3.3.6 to 3.3.7 -2006-Aug-12 -- The previous file format change has caused so much - grief that the default behavior has been changed back to - the original file format. This means that DESC option on - indices is ignored by default that the more efficient encoding - of boolean values is not used. In that way, older versions - of SQLite can read and write databases created by newer - versions. If the new features are desired, they can be - enabled using pragma: "PRAGMA legacy_file_format=OFF".
-To be clear: both old and new file formats continue to - be understood and continue to work. But the old file format - is used by default instead of the new. This might change - again in some future release - we may go back to generating - the new file format by default - but probably not until - all users have upgraded to a version of SQLite that will - understand the new file format. That might take several - years.
- -3.4.2 to 3.5.0 -2007-Sep-3 -- The design of the OS interface layer was changed for - release 3.5.0. Applications that implemented a custom OS - interface will need to be modified in order to upgrade. - There are also some subtly different semantics a few obscure - APIs. An article is avilable which - describing the changes in detail.
- -The on-disk file format is unchanged.
-
-To perform a database reload, have ready versions of the -sqlite command-line utility for both the old and new -version of SQLite. Call these two executables "sqlite-old" -and "sqlite-new". Suppose the name of your old database -is "old.db" and you want to create a new database with -the same information named "new.db". The command to do -this is as follows: -
- -- sqlite-old old.db .dump | sqlite-new new.db --} -footer $rcsid diff --git a/www/fullscanb.gif b/www/fullscanb.gif deleted file mode 100644 index becb5149bc90804f2524ff8dfd21cc2314620af2..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc-jL100001 literal 11946 zc-qaEbwkq+w8p
BmmQumTGIgkKA)s7V-gi~`kSb&uJa0K{=p-B#lMDjJ{rPEnoA60vji|n Ajh(Ky5qIi@FI%VeZ_23-)XA&UjDi6d
zcBNbT(-MTI;8eWQ#sTe@1d@}@3bE*YmAaUbji_79-bVeA*K*P@{F|88^_wY0wTQ3h
zG;S>KbBhZvECR1iCd-{w*3~I~|J#t3Yk2K`k4TD#vx?!OhMiKEE3L()JZ~Kr#j`*1
z*;aHP9Dr=OjwUbDY0ejSrtAtt#eHJwT(6ed43fS>{IGA_ELhAryun61H8n|Lx=8AL
ze9YgdH*JfPL~|zv$$y51`iooaQbS0SoG&&Y#9OOBJ{tF6{eydnh{i7`d_bdEK-BcQ
zBZ}P3XH6%*v1GR0og&2Y=lYDOhXsaa0-0*?o(N+`K
e_Sg604|iTq-s^bt2+sip_!f#R1Yi)NI=u$~rN+lw
zJw~u^A0a!jSL^LZu1`_YF3FOE_a$did=_a3LqltjMwwi8>r)$HNw*-w?N3jA*fU8H
zNPF0ZE-e`(`f-1H>iO>T+SB^yl{rW}u)ae?ztCKCHr|_i%+PMQBy#`gQ2DHw7=3$9
zMS+Kj^@tQqQ30&1n}T4i#C^Yi5#V{?>b@`-6zQGBS1B{Mn8Mih6;Fn_k`RGgCmKb;
zZXa{a^{-1AHHm*r$Zv_ra9Kn~x9~8_O`gSlh%X%V6#_Qd90gfJA-ybsk2MvYAx2|*
z=U0J5;zL?^wKlG64n#_4PBo3yWvNY=y~Am55?&QJrn}jN9L=t;0_Y1lk_yk-kxU*u
zcIjO-(`(-