From: drh $desc
SQLite version 3.0 expands the size of the rowid to 64 bits.
} faq { What datatypes does SQLite support? } { -SQLite is typeless. All data is stored as null-terminated strings. - The datatype information that follows the column name in CREATE TABLE - statements is ignored (mostly). You can put any type of data you want +
SQLite ignores + the datatype information that follows the column name in CREATE TABLE. + You can put any type of data you want into any column, without regard to the declared datatype of that column.
@@ -70,14 +72,17 @@ faq { Such columns must hold an integer. An attempt to put a non-integer value into an INTEGER PRIMARY KEY column will generate an error. -There is a page on datatypes in SQLite +
There is a page on datatypes in SQLite + version 2.8 + and another for version 3.0 that explains this concept further.
} faq { SQLite lets me insert a string into a database column of type integer! } { -This is a feature, not a bug. SQLite is typeless. Any data can be +
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 @@ -106,7 +111,9 @@ INSERT INTO t1 VALUES('0.0'); INSERT INTO t2 VALUES(0.0); this case, the constants 0 and 0.0 are treated a strings which means that they are distinct.
-There is a page on datatypes in SQLite +
There is a page on datatypes in SQLite + version 2.8 + and another for version 3.0 that explains this concept further.
} @@ -138,7 +145,9 @@ SELECT count(*) FROM t3 WHERE b=='00'; is done against '00'. '0'!='00' so the WHERE clause returns FALSE and the count is zero. -There is a page on datatypes in SQLite +
There is a page on datatypes in SQLite + version 2.8 + and another for version 3.0 that explains this concept further.
} @@ -307,23 +316,14 @@ faq { Are there any known size limits to SQLite databases? } {As of version 2.7.4, - SQLite can handle databases up to 2^41 bytes (2 terabytes) + SQLite can handle databases up to 241 bytes (2 terabytes) in size on both Windows and Unix. Older version of SQLite - were limited to databases of 2^31 bytes (2 gigabytes).
- -SQLite arbitrarily limits the amount of data in one row to 1 megabyte. - There is a single #define in the source code that can be changed to raise - this limit as high as 16 megabytes if desired.
- -There is a theoretical limit of about 2^32 (4 billion) rows - in a single table, but this limit has never been tested.
- There is also a theoretical limit of about 2^32 - tables and indices. + were limited to databases of 231 bytes (2 gigabytes). -The name and "CREATE TABLE" statement for a table must fit entirely - within a 1-megabyte row of the SQLITE_MASTER table. Other than this, - there are no constraints on the length of the name of a table, or on the - number of columns, etc. Indices are similarly unconstrained.
+SQLite version 2.8 limits the amount of data in one row to + 1 megabyte. SQLite version 3.0 has no limit on the amount of + data that can be stored in a single row. +
The names of tables, indices, view, triggers, and columns can be as long as desired. However, the names of SQL functions (as created @@ -334,32 +334,21 @@ faq { faq { What is the maximum size of a VARCHAR in SQLite? } { -
Remember, SQLite is typeless. A VARCHAR column can hold as much - data as any other column. The total amount of data in a single row - of the database is limited to 1 megabyte. You can increase this limit - to 16 megabytes, if you need to, by adjusting a single #define in the - source tree and recompiling.
- -For maximum speed and space efficiency, you should try to keep the - amount of data in a single row below about 230 bytes.
+SQLite does not enforce datatype constraints. + A VARCHAR column can hold as much data as you care to put it in.
} faq { Does SQLite support a BLOB type? } { -You can declare a table column to be of type "BLOB" but it will still - only store null-terminated strings. This is because the only way to - insert information into an SQLite database is using an INSERT SQL statement, - and you can not include binary data in the middle of the ASCII text string - of an INSERT statement.
- -SQLite is 8-bit clean with regard to the data it stores as long as - the data does not contain any '\000' characters. If you want to store binary - data, consider encoding your data in such a way that it contains no NUL - characters and inserting it that way. You might use URL-style encoding: - encode NUL as "%00" and "%" as "%25". Or, you might consider encoding your - binary data using base-64. There is a source file named - "src/encode.c" in the SQLite distribution that contains +
SQLite version 3.0 lets you puts BLOB data into any column, even + columns that are declared to hold some other type.
+ +SQLite version 2.8 would hold store text data without embedded + '\000' characters. If you need to store BLOB data in SQLite version + 2.8 you'll want to encode that data first. + There is a source file named + "src/encode.c" in the SQLite version 2.8 distribution that contains implementations of functions named "sqlite_encode_binary() and sqlite_decode_binary() that can be used for converting binary data to ASCII and back again, if you like.
@@ -370,7 +359,7 @@ faq { faq { How do I add or delete columns from an existing table in SQLite. } { -SQLite does not support the "ALTER TABLE" SQL command. If you +
SQLite does yes not support the "ALTER TABLE" SQL command. If you what to change the structure of a table, you 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 @@ -419,6 +408,20 @@ faq { 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: +
+ ++} + # End of questions and answers. ############# diff --git a/www/index.tcl b/www/index.tcl index f80518d744..34f79c6b4a 100644 --- a/www/index.tcl +++ b/www/index.tcl @@ -14,17 +14,19 @@ Features include:+ INSERT INTO xyz VALUES('5 O''clock'); +
Here is what you do to start experimenting with SQLite without having to do a lot of tedious reading and configuration:
@@ -15,7 +11,7 @@ to do a lot of tedious reading and configuration:Get a copy of the prebuild binaries for your machine, or get a copy +
Get a copy of the prebuilt binaries for your machine, or get a copy of the sources and compile them yourself. Visit the download page for more information.
At a shell or DOS prompt, enter: "sqlite test.db". This will +
At a shell or DOS prompt, enter: "sqlite3 test.db". This will create a new database named "test.db". (You can use a different name if you like.)
Enter SQL commands at the prompt to create and populate the @@ -36,7 +32,7 @@ new database.
Below is a simple TCL program that demonstrates how to use the TCL interface to SQLite. The program executes the SQL statements given as the second argument on the database defined by the first -argument. The commands to watch for are the sqlite command +argument. The commands to watch for are the sqlite3 command on line 7 which opens an SQLite database and creates a new TCL command named "db" to access that database, the invocation of the db command on line 8 to execute @@ -49,8 +45,8 @@ if {$argc!=2} { puts stderr "Usage: %s DATABASE SQL-STATEMENT" exit 1 } -load /usr/lib/tclsqlite.so Sqlite -sqlite db [lindex $argv 0] +load /usr/lib/tclsqlite3.so Sqlite +sqlite3 db [lindex $argv 0] db eval [lindex $argv 1] x { foreach v $x(*) { puts "$v = $x($v)" @@ -65,14 +61,14 @@ load /usr/lib/tclsqlite.so Sqlite the C/C++ interface to SQLite. The name of a database is given by the first argument and the second argument is one or more SQL statements to execute against the database. The function calls to pay attention -to here are the call to sqlite_open() on line 22 which opens -the database, sqlite_exec() on line 27 that executes SQL -commands against the database, and sqlite_close() on line 31 +to here are the call to sqlite3_open() on line 22 which opens +the database, sqlite3_exec() on line 27 that executes SQL +commands against the database, and sqlite3_close() on line 31 that closes the database connection.
#include <stdio.h> -#include <sqlite.h> +#include <sqlite3.h> static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int i; @@ -84,7 +80,7 @@ static int callback(void *NotUsed, int argc, char **argv, char **azColName){ } int main(int argc, char **argv){ - sqlite *db; + sqlite3 *db; char *zErrMsg = 0; int rc; @@ -92,28 +88,21 @@ int main(int argc, char **argv){ fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]); exit(1); } - db = sqlite_open(argv[1], 0, &zErrMsg); - if( db==0 ){ - fprintf(stderr, "Can't open database: %s\n", zErrMsg); + rc = sqlite3_open(argv[1], &db); + if( rc ){ + fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); + sqlite3_close(db); exit(1); } - rc = sqlite_exec(db, argv[2], callback, 0, &zErrMsg); + rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg); if( rc!=SQLITE_OK ){ fprintf(stderr, "SQL error: %s\n", zErrMsg); } - sqlite_close(db); + sqlite3_close(db); return 0; }