mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
:-) (CVS 37)
FossilOrigin-Name: 2b55f9b790e2914bbd2fd27ef23bbab79fa76937
This commit is contained in:
32
Makefile.in
32
Makefile.in
@ -51,11 +51,41 @@ LIBOBJ = build.o dbbe.o delete.o expr.o insert.o \
|
|||||||
main.o parse.o select.o tokenize.o update.o \
|
main.o parse.o select.o tokenize.o update.o \
|
||||||
util.o vdbe.o where.o
|
util.o vdbe.o where.o
|
||||||
|
|
||||||
|
# All of the source code files.
|
||||||
|
#
|
||||||
|
SRC = \
|
||||||
|
$(TOP)/src/build.c \
|
||||||
|
$(TOP)/src/dbbe.c \
|
||||||
|
$(TOP)/src/dbbe.h \
|
||||||
|
$(TOP)/src/delete.c \
|
||||||
|
$(TOP)/src/expr.c \
|
||||||
|
$(TOP)/src/insert.c \
|
||||||
|
$(TOP)/src/main.c \
|
||||||
|
$(TOP)/src/parse.y \
|
||||||
|
$(TOP)/src/select.c \
|
||||||
|
$(TOP)/src/shell.c \
|
||||||
|
$(TOP)/src/sqlite.h \
|
||||||
|
$(TOP)/src/sqliteInt.h \
|
||||||
|
$(TOP)/src/tclsqlite.c \
|
||||||
|
$(TOP)/src/tokenize.c \
|
||||||
|
$(TOP)/src/update.c \
|
||||||
|
$(TOP)/src/util.c \
|
||||||
|
$(TOP)/src/vdbe.c \
|
||||||
|
$(TOP)/src/vdbe.h \
|
||||||
|
$(TOP)/src/where.c
|
||||||
|
|
||||||
# This is the default Makefile target. The objects listed here
|
# This is the default Makefile target. The objects listed here
|
||||||
# are what get build when you type just "make" with no arguments.
|
# are what get build when you type just "make" with no arguments.
|
||||||
#
|
#
|
||||||
all: libsqlite.a sqlite.h sqlite
|
all: libsqlite.a sqlite.h sqlite
|
||||||
|
|
||||||
|
# Generate the file "last_change" which contains the date of change
|
||||||
|
# of the most recently modified source code file
|
||||||
|
#
|
||||||
|
last_change: $(SRC)
|
||||||
|
cat $(SRC) | grep '$$Id: ' | sort +4 | tail -1 \
|
||||||
|
| awk '{print $$5,$$6}' >last_change
|
||||||
|
|
||||||
libsqlite.a: $(LIBOBJ)
|
libsqlite.a: $(LIBOBJ)
|
||||||
$(AR) libsqlite.a $(LIBOBJ)
|
$(AR) libsqlite.a $(LIBOBJ)
|
||||||
$(RANLIB) libsqlite.a
|
$(RANLIB) libsqlite.a
|
||||||
@ -153,7 +183,7 @@ sqlite.tar.gz:
|
|||||||
all.tar.gz:
|
all.tar.gz:
|
||||||
pwd=`pwd`; cd $(TOP)/..; tar czf $$pwd/all.tar.gz sqlite
|
pwd=`pwd`; cd $(TOP)/..; tar czf $$pwd/all.tar.gz sqlite
|
||||||
|
|
||||||
index.html: $(TOP)/www/index.tcl sqlite.tar.gz all.tar.gz
|
index.html: $(TOP)/www/index.tcl sqlite.tar.gz all.tar.gz last_change
|
||||||
tclsh $(TOP)/www/index.tcl >index.html
|
tclsh $(TOP)/www/index.tcl >index.html
|
||||||
|
|
||||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||||
|
2
README
2
README
@ -1,6 +1,6 @@
|
|||||||
This directory contains source code to
|
This directory contains source code to
|
||||||
|
|
||||||
SQLite: An SQL Frontend To GDBM
|
SQLite: An SQL Database Built Upon GDBM
|
||||||
|
|
||||||
To compile the project, first create a directory in which to place
|
To compile the project, first create a directory in which to place
|
||||||
the build products. The build directory must be separate from the
|
the build products. The build directory must be separate from the
|
||||||
|
39
manifest
39
manifest
@ -1,27 +1,27 @@
|
|||||||
C :-)\s(CVS\s1696)
|
C :-)\s(CVS\s37)
|
||||||
D 2000-06-02T02:09:23
|
D 2000-06-02T13:27:59
|
||||||
F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
|
F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
|
||||||
F Makefile.in 7ac2fef265940d93a544cb454efa836451559a71
|
F Makefile.in b0553e870e5daa6279af4dc09101322db16a49f1
|
||||||
F README 6b5960603c7f8bf42fc022b4b6436f242f238dbb
|
F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
|
||||||
F configure 00a5b5c82147a576fa6e82d7c1b0d55c321d6d2c x
|
F configure 00a5b5c82147a576fa6e82d7c1b0d55c321d6d2c x
|
||||||
F configure.in 6ccfd5fc80517f7cfe605a7fc7e0f62d962a233c
|
F configure.in 6ccfd5fc80517f7cfe605a7fc7e0f62d962a233c
|
||||||
F doc/lemon.html e233a3e97a779c7a87e1bc4528c664a58e49dd47
|
F doc/lemon.html e233a3e97a779c7a87e1bc4528c664a58e49dd47
|
||||||
F src/build.c f56c47f08c2f01fd640abb920c5da6b6614fbf3f
|
F src/build.c 44a99167e5aebd04a65c607dc8556c13d9bccdb0
|
||||||
F src/dbbe.c ce2d78a92a14c874443fda3069fde06d330807df
|
F src/dbbe.c ae8b5d2cdb4fa7dd11313059984be9457fa77f63
|
||||||
F src/dbbe.h a8a46f71238e0f09f3ec08fd9d1c8c7f4cdc49bf
|
F src/dbbe.h a8a46f71238e0f09f3ec08fd9d1c8c7f4cdc49bf
|
||||||
F src/delete.c e11433c14ed5cc8553cba14296b3baa3c23054bc
|
F src/delete.c e11433c14ed5cc8553cba14296b3baa3c23054bc
|
||||||
F src/expr.c 91970700e3e39b2b725b028c166f588a5bb0c038
|
F src/expr.c fb0972a54cc0230b6d4ce02c80ae07d0e1876e01
|
||||||
F src/insert.c 5d713f4a05cef76a188207aa986776e02349ba70
|
F src/insert.c 747aad76e48a811c6fd30336514df84104587c3f
|
||||||
F src/main.c 9123ef6567b6a5255643040b0832b9d70ae2b4ed
|
F src/main.c e0fb4de58091f7421793e9b93571cf2d64caf3c3
|
||||||
F src/parse.y 16322c46ec117082ef745715f7a4761f2491a0b2
|
F src/parse.y 16322c46ec117082ef745715f7a4761f2491a0b2
|
||||||
F src/select.c ce21eb2db2c621c097f03c21ff8d18804fb9897d
|
F src/select.c ce21eb2db2c621c097f03c21ff8d18804fb9897d
|
||||||
F src/shell.c 9a42923e9c8ec1654dd1ef1aa113eca26dcf30db
|
F src/shell.c bd658f9208bc20ce565c3f687836155772ca939a
|
||||||
F src/sqlite.h 58da0a8590133777b741f9836beaef3d58f40268
|
F src/sqlite.h 58da0a8590133777b741f9836beaef3d58f40268
|
||||||
F src/sqliteInt.h fe26be33f20aea88378301998b2f5c308005bf4c
|
F src/sqliteInt.h 0b7a533a389ccead699ea149ff3f8d61831d0c0a
|
||||||
F src/tclsqlite.c 10c00c460246cfba375b768c90b22bfe3c774c8f
|
F src/tclsqlite.c 10c00c460246cfba375b768c90b22bfe3c774c8f
|
||||||
F src/tokenize.c 15c229fee77325334c6814652e429b0930eba6c1
|
F src/tokenize.c 15c229fee77325334c6814652e429b0930eba6c1
|
||||||
F src/update.c 1f7284e00921352c3ae699fb60f2c2fbf8098212
|
F src/update.c 1f7284e00921352c3ae699fb60f2c2fbf8098212
|
||||||
F src/util.c da47fe65efa6ff4c5e663cc7c832964bd599c0d2
|
F src/util.c c22846f23b9311ca0e68f076686493bac7b20d5d
|
||||||
F src/vdbe.c a92f66fa70d1df99ff29795fe8f18e9ea51f8f4c
|
F src/vdbe.c a92f66fa70d1df99ff29795fe8f18e9ea51f8f4c
|
||||||
F src/vdbe.h ab574c91c6328c5795f68b84074fbcf860eae70e
|
F src/vdbe.h ab574c91c6328c5795f68b84074fbcf860eae70e
|
||||||
F src/where.c bed9a8360cbfbf712bdc397c8e22216a5e5f9800
|
F src/where.c bed9a8360cbfbf712bdc397c8e22216a5e5f9800
|
||||||
@ -32,6 +32,7 @@ F test/expr.test f3fc925935533082911dfa5fde9b22e382b3132f
|
|||||||
F test/index.test 8d4f26901a5582daa353fe3c8266cbf4a53af830
|
F test/index.test 8d4f26901a5582daa353fe3c8266cbf4a53af830
|
||||||
F test/insert.test 161bc67a4189738c559e3569323ceae31f4d49d6
|
F test/insert.test 161bc67a4189738c559e3569323ceae31f4d49d6
|
||||||
F test/select1.test a0b00df77e85adff75c338e487718c5d31f69e3a
|
F test/select1.test a0b00df77e85adff75c338e487718c5d31f69e3a
|
||||||
|
F test/select2.test 33a53530dc011bcf970068f79674b2272fda5917
|
||||||
F test/table.test 85d6f410d127ec508c6640f02d7c40d218414e81
|
F test/table.test 85d6f410d127ec508c6640f02d7c40d218414e81
|
||||||
F test/tester.tcl 44690d463c1dc83a4c76ccde07cc146a988600f6
|
F test/tester.tcl 44690d463c1dc83a4c76ccde07cc146a988600f6
|
||||||
F test/update.test 69459302ea75cafac1479e60b0e36efb88123c0e
|
F test/update.test 69459302ea75cafac1479e60b0e36efb88123c0e
|
||||||
@ -41,11 +42,11 @@ F tool/lempar.c a1eec94d6eacc12332368660ec65f3b248853833
|
|||||||
F tool/opNames.awk 2bd9071a138e4e2be13dc98fe066398a61219e1e
|
F tool/opNames.awk 2bd9071a138e4e2be13dc98fe066398a61219e1e
|
||||||
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
|
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
|
||||||
F tool/renumberOps.awk 6d067177ad5f8d711b79577b462da9b3634bd0a9
|
F tool/renumberOps.awk 6d067177ad5f8d711b79577b462da9b3634bd0a9
|
||||||
F www/c_interface.tcl f875864edf7974157d1c257ca08de854660882a5
|
F www/c_interface.tcl 8867d76ddd416d2fbd41e4cb3de8efa9cef105a5
|
||||||
F www/changes.tcl 37f4906f0b03f2160d2b2e4ed3cedb0b91d253cb
|
F www/changes.tcl 7d6ed774362dea0c9687d4efbafd939c1c48fd81
|
||||||
F www/index.tcl 001f8c8c4edbe20e25c508005a12f2f265f84c9c
|
F www/index.tcl 95bab9c95813c2222265532e4e0340a8c1d4e354
|
||||||
F www/sqlite.tcl 2a0056dd6d78839636176b770d9f37d12e66660e
|
F www/sqlite.tcl 2f933ce18cffd34a0a020a82435ab937137970fd
|
||||||
P d3c31defbaf25f470d0977c39325890ab8bad054
|
P 80d925b82b176df7f73a1747a6ed711ac3d9a0d3
|
||||||
R 1972cc5d0dec5079acb55afe886914ee
|
R e8a51bd00aae9034f42802ab343d2bb5
|
||||||
U drh
|
U drh
|
||||||
Z b89a6085ec647850e84316905c71acda
|
Z aaac793e5f9c2c3602d5040dcac36c63
|
||||||
|
@ -1 +1 @@
|
|||||||
80d925b82b176df7f73a1747a6ed711ac3d9a0d3
|
2b55f9b790e2914bbd2fd27ef23bbab79fa76937
|
27
src/build.c
27
src/build.c
@ -22,9 +22,18 @@
|
|||||||
**
|
**
|
||||||
*************************************************************************
|
*************************************************************************
|
||||||
** This file contains C code routines that are called by the parser
|
** This file contains C code routines that are called by the parser
|
||||||
** when syntax rules are reduced.
|
** when syntax rules are reduced. The routines in this file handle
|
||||||
|
** the following kinds of rules:
|
||||||
**
|
**
|
||||||
** $Id: build.c,v 1.12 2000/06/02 01:17:37 drh Exp $
|
** CREATE TABLE
|
||||||
|
** DROP TABLE
|
||||||
|
** CREATE INDEX
|
||||||
|
** DROP INDEX
|
||||||
|
** creating expressions and ID lists
|
||||||
|
** COPY
|
||||||
|
** VACUUM
|
||||||
|
**
|
||||||
|
** $Id: build.c,v 1.13 2000/06/02 13:27:59 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
|
|
||||||
@ -529,15 +538,15 @@ void sqliteCreateIndex(
|
|||||||
*/
|
*/
|
||||||
if( pParse->initFlag==0 ){
|
if( pParse->initFlag==0 ){
|
||||||
static VdbeOp addTable[] = {
|
static VdbeOp addTable[] = {
|
||||||
{ OP_Open, 0, 1, MASTER_NAME},
|
{ OP_Open, 2, 1, MASTER_NAME},
|
||||||
{ OP_New, 0, 0, 0},
|
{ OP_New, 2, 0, 0},
|
||||||
{ OP_String, 0, 0, "index"},
|
{ OP_String, 0, 0, "index"},
|
||||||
{ OP_String, 0, 0, 0}, /* 3 */
|
{ OP_String, 0, 0, 0}, /* 3 */
|
||||||
{ OP_String, 0, 0, 0}, /* 4 */
|
{ OP_String, 0, 0, 0}, /* 4 */
|
||||||
{ OP_String, 0, 0, 0}, /* 5 */
|
{ OP_String, 0, 0, 0}, /* 5 */
|
||||||
{ OP_MakeRecord, 4, 0, 0},
|
{ OP_MakeRecord, 4, 0, 0},
|
||||||
{ OP_Put, 0, 0, 0},
|
{ OP_Put, 2, 0, 0},
|
||||||
{ OP_Close, 0, 0, 0},
|
{ OP_Close, 2, 0, 0},
|
||||||
};
|
};
|
||||||
int n;
|
int n;
|
||||||
Vdbe *v = pParse->pVdbe;
|
Vdbe *v = pParse->pVdbe;
|
||||||
@ -548,6 +557,8 @@ void sqliteCreateIndex(
|
|||||||
v = pParse->pVdbe = sqliteVdbeCreate(pParse->db->pBe);
|
v = pParse->pVdbe = sqliteVdbeCreate(pParse->db->pBe);
|
||||||
}
|
}
|
||||||
if( v==0 ) goto exit_create_index;
|
if( v==0 ) goto exit_create_index;
|
||||||
|
sqliteVdbeAddOp(v, OP_Open, 0, 0, pTab->zName, 0);
|
||||||
|
sqliteVdbeAddOp(v, OP_Open, 1, 1, pIndex->zName, 0);
|
||||||
if( pStart && pEnd ){
|
if( pStart && pEnd ){
|
||||||
int base;
|
int base;
|
||||||
n = (int)pEnd->z - (int)pStart->z + 1;
|
n = (int)pEnd->z - (int)pStart->z + 1;
|
||||||
@ -556,8 +567,6 @@ void sqliteCreateIndex(
|
|||||||
sqliteVdbeChangeP3(v, base+4, pTab->zName, 0);
|
sqliteVdbeChangeP3(v, base+4, pTab->zName, 0);
|
||||||
sqliteVdbeChangeP3(v, base+5, pStart->z, n);
|
sqliteVdbeChangeP3(v, base+5, pStart->z, n);
|
||||||
}
|
}
|
||||||
sqliteVdbeAddOp(v, OP_Open, 0, 0, pTab->zName, 0);
|
|
||||||
sqliteVdbeAddOp(v, OP_Open, 1, 1, pIndex->zName, 0);
|
|
||||||
lbl1 = sqliteVdbeMakeLabel(v);
|
lbl1 = sqliteVdbeMakeLabel(v);
|
||||||
lbl2 = sqliteVdbeMakeLabel(v);
|
lbl2 = sqliteVdbeMakeLabel(v);
|
||||||
sqliteVdbeAddOp(v, OP_Next, 0, lbl2, 0, lbl1);
|
sqliteVdbeAddOp(v, OP_Next, 0, lbl2, 0, lbl1);
|
||||||
@ -569,8 +578,8 @@ void sqliteCreateIndex(
|
|||||||
sqliteVdbeAddOp(v, OP_PutIdx, 1, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_PutIdx, 1, 0, 0, 0);
|
||||||
sqliteVdbeAddOp(v, OP_Goto, 0, lbl1, 0, 0);
|
sqliteVdbeAddOp(v, OP_Goto, 0, lbl1, 0, 0);
|
||||||
sqliteVdbeAddOp(v, OP_Noop, 0, 0, 0, lbl2);
|
sqliteVdbeAddOp(v, OP_Noop, 0, 0, 0, lbl2);
|
||||||
sqliteVdbeAddOp(v, OP_Close, 0, 0, 0, 0);
|
|
||||||
sqliteVdbeAddOp(v, OP_Close, 1, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_Close, 1, 0, 0, 0);
|
||||||
|
sqliteVdbeAddOp(v, OP_Close, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reclaim memory on an EXPLAIN call.
|
/* Reclaim memory on an EXPLAIN call.
|
||||||
|
59
src/dbbe.c
59
src/dbbe.c
@ -30,7 +30,7 @@
|
|||||||
** relatively simple to convert to a different database such
|
** relatively simple to convert to a different database such
|
||||||
** as NDBM, SDBM, or BerkeleyDB.
|
** as NDBM, SDBM, or BerkeleyDB.
|
||||||
**
|
**
|
||||||
** $Id: dbbe.c,v 1.10 2000/06/02 02:09:23 drh Exp $
|
** $Id: dbbe.c,v 1.11 2000/06/02 13:27:59 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include <gdbm.h>
|
#include <gdbm.h>
|
||||||
@ -124,9 +124,13 @@ static int rc4byte(struct rc4 *p){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** This routine opens a new database. For the current driver scheme,
|
** This routine opens a new database. For the GDBM driver
|
||||||
** the database name is the name of the directory
|
** implemented here, the database name is the name of the directory
|
||||||
** containing all the files of the database.
|
** containing all the files of the database.
|
||||||
|
**
|
||||||
|
** If successful, a pointer to the Dbbe structure is returned.
|
||||||
|
** If there are errors, an appropriate error message is left
|
||||||
|
** in *pzErrMsg and NULL is returned.
|
||||||
*/
|
*/
|
||||||
Dbbe *sqliteDbbeOpen(
|
Dbbe *sqliteDbbeOpen(
|
||||||
const char *zName, /* The name of the database */
|
const char *zName, /* The name of the database */
|
||||||
@ -142,7 +146,8 @@ Dbbe *sqliteDbbeOpen(
|
|||||||
if( stat(zName, &statbuf)!=0 ){
|
if( stat(zName, &statbuf)!=0 ){
|
||||||
if( createFlag ) mkdir(zName, 0750);
|
if( createFlag ) mkdir(zName, 0750);
|
||||||
if( stat(zName, &statbuf)!=0 ){
|
if( stat(zName, &statbuf)!=0 ){
|
||||||
sqliteSetString(pzErrMsg, "can't find or make directory \"",
|
sqliteSetString(pzErrMsg, createFlag ?
|
||||||
|
"can't find or create directory \"" : "can't find directory \"",
|
||||||
zName, "\"", 0);
|
zName, "\"", 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -229,6 +234,9 @@ static char *sqliteFileOfTable(Dbbe *pBe, const char *zTable){
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
** Generate a random filename with the given prefix.
|
** Generate a random filename with the given prefix.
|
||||||
|
**
|
||||||
|
** Very random names are chosen so that the chance of a
|
||||||
|
** collision with an existing filename is very very small.
|
||||||
*/
|
*/
|
||||||
static void randomName(struct rc4 *pRc4, char *zBuf, char *zPrefix){
|
static void randomName(struct rc4 *pRc4, char *zBuf, char *zPrefix){
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -242,9 +250,28 @@ static void randomName(struct rc4 *pRc4, char *zBuf, char *zPrefix){
|
|||||||
zBuf[j] = 0;
|
zBuf[j] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Open a new table cursor
|
** Open a new table cursor. Write a pointer to the corresponding
|
||||||
|
** DbbeTable structure into *ppTable. Return an integer success
|
||||||
|
** code:
|
||||||
|
**
|
||||||
|
** SQLITE_OK It worked!
|
||||||
|
**
|
||||||
|
** SQLITE_NOMEM sqliteMalloc() failed
|
||||||
|
**
|
||||||
|
** SQLITE_PERM Attempt to access a file for which file
|
||||||
|
** access permission is denied
|
||||||
|
**
|
||||||
|
** SQLITE_BUSY Another thread or process is already using
|
||||||
|
** the corresponding file and has that file locked.
|
||||||
|
**
|
||||||
|
** SQLITE_READONLY The current thread already has this file open
|
||||||
|
** readonly but you are trying to open for writing.
|
||||||
|
** (This can happen if a SELECT callback tries to
|
||||||
|
** do an UPDATE or DELETE.)
|
||||||
|
**
|
||||||
|
** If zTable is 0 or "", then a temporary table is created and opened.
|
||||||
|
** This table will be deleted from the disk when it is closed.
|
||||||
*/
|
*/
|
||||||
int sqliteDbbeOpenTable(
|
int sqliteDbbeOpenTable(
|
||||||
Dbbe *pBe, /* The database the table belongs to */
|
Dbbe *pBe, /* The database the table belongs to */
|
||||||
@ -335,7 +362,8 @@ int sqliteDbbeOpenTable(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Drop a table from the database.
|
** Drop a table from the database. The file on the disk that corresponds
|
||||||
|
** to this table is deleted.
|
||||||
*/
|
*/
|
||||||
void sqliteDbbeDropTable(Dbbe *pBe, const char *zTable){
|
void sqliteDbbeDropTable(Dbbe *pBe, const char *zTable){
|
||||||
char *zFile; /* Name of the table file */
|
char *zFile; /* Name of the table file */
|
||||||
@ -349,7 +377,6 @@ void sqliteDbbeDropTable(Dbbe *pBe, const char *zTable){
|
|||||||
** Reorganize a table to reduce search times and disk usage.
|
** Reorganize a table to reduce search times and disk usage.
|
||||||
*/
|
*/
|
||||||
void sqliteDbbeReorganizeTable(Dbbe *pBe, const char *zTable){
|
void sqliteDbbeReorganizeTable(Dbbe *pBe, const char *zTable){
|
||||||
char *zFile; /* Name of the table file */
|
|
||||||
DbbeTable *pTab;
|
DbbeTable *pTab;
|
||||||
|
|
||||||
if( sqliteDbbeOpenTable(pBe, zTable, 1, &pTab)!=SQLITE_OK ){
|
if( sqliteDbbeOpenTable(pBe, zTable, 1, &pTab)!=SQLITE_OK ){
|
||||||
@ -603,14 +630,18 @@ int sqliteDbbeDelete(DbbeTable *pTable, int nKey, char *pKey){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Open a temporary file.
|
** Open a temporary file. The file should be deleted when closed.
|
||||||
|
**
|
||||||
|
** Note that we can't use the old Unix trick of opening the file
|
||||||
|
** and then immediately unlinking the file. That works great
|
||||||
|
** under Unix, but fails when we try to port to Windows.
|
||||||
*/
|
*/
|
||||||
int sqliteDbbeOpenTempFile(Dbbe *pBe, FILE **ppFile){
|
int sqliteDbbeOpenTempFile(Dbbe *pBe, FILE **ppFile){
|
||||||
char *zFile;
|
char *zFile; /* Full name of the temporary file */
|
||||||
char zBuf[50];
|
char zBuf[50]; /* Base name of the temporary file */
|
||||||
int i, j;
|
int i; /* Loop counter */
|
||||||
int limit;
|
int limit; /* Prevent an infinite loop */
|
||||||
int rc = SQLITE_OK;
|
int rc = SQLITE_OK; /* Value returned by this function */
|
||||||
|
|
||||||
for(i=0; i<pBe->nTemp; i++){
|
for(i=0; i<pBe->nTemp; i++){
|
||||||
if( pBe->apTemp[i]==0 ) break;
|
if( pBe->apTemp[i]==0 ) break;
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*************************************************************************
|
*************************************************************************
|
||||||
** This file contains C code routines used for processing expressions
|
** This file contains C code routines used for processing expressions
|
||||||
**
|
**
|
||||||
** $Id: expr.c,v 1.1 2000/05/31 15:34:53 drh Exp $
|
** $Id: expr.c,v 1.2 2000/06/02 13:27:59 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
|
|
||||||
@ -77,10 +77,9 @@ int sqliteExprResolveIds(Parse *pParse, IdList *pTabList, Expr *pExpr){
|
|||||||
|
|
||||||
/* A table name and field name: ID.ID */
|
/* A table name and field name: ID.ID */
|
||||||
case TK_DOT: {
|
case TK_DOT: {
|
||||||
int cnt = 0; /* Number of matches */
|
int cnt = 0; /* Number of matches */
|
||||||
int i; /* Loop counter */
|
int i; /* Loop counter */
|
||||||
Expr *pLeft, *pRight; /* Left and right subbranches of the expr */
|
Expr *pLeft, *pRight; /* Left and right subbranches of the expr */
|
||||||
int n; /* Length of an identifier */
|
|
||||||
char *zLeft, *zRight; /* Text of an identifier */
|
char *zLeft, *zRight; /* Text of an identifier */
|
||||||
|
|
||||||
pLeft = pExpr->pLeft;
|
pLeft = pExpr->pLeft;
|
||||||
|
14
src/insert.c
14
src/insert.c
@ -24,7 +24,7 @@
|
|||||||
** This file contains C code routines that are called by the parser
|
** This file contains C code routines that are called by the parser
|
||||||
** to handle INSERT statements.
|
** to handle INSERT statements.
|
||||||
**
|
**
|
||||||
** $Id: insert.c,v 1.2 2000/06/02 01:17:37 drh Exp $
|
** $Id: insert.c,v 1.3 2000/06/02 13:27:59 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ void sqliteInsert(
|
|||||||
){
|
){
|
||||||
Table *pTab;
|
Table *pTab;
|
||||||
char *zTab;
|
char *zTab;
|
||||||
int i, j;
|
int i, j, idx;
|
||||||
Vdbe *v;
|
Vdbe *v;
|
||||||
|
|
||||||
zTab = sqliteTableNameFromToken(pTableName);
|
zTab = sqliteTableNameFromToken(pTableName);
|
||||||
@ -105,6 +105,9 @@ void sqliteInsert(
|
|||||||
if( v ){
|
if( v ){
|
||||||
Index *pIdx;
|
Index *pIdx;
|
||||||
sqliteVdbeAddOp(v, OP_Open, 0, 1, pTab->zName, 0);
|
sqliteVdbeAddOp(v, OP_Open, 0, 1, pTab->zName, 0);
|
||||||
|
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
|
||||||
|
sqliteVdbeAddOp(v, OP_Open, idx, 1, pIdx->zName, 0);
|
||||||
|
}
|
||||||
sqliteVdbeAddOp(v, OP_New, 0, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_New, 0, 0, 0, 0);
|
||||||
if( pTab->pIndex ){
|
if( pTab->pIndex ){
|
||||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_Dup, 0, 0, 0, 0);
|
||||||
@ -126,11 +129,10 @@ void sqliteInsert(
|
|||||||
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0, 0, 0);
|
||||||
sqliteVdbeAddOp(v, OP_Put, 0, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_Put, 0, 0, 0, 0);
|
||||||
sqliteVdbeAddOp(v, OP_Close, 0, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_Close, 0, 0, 0, 0);
|
||||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
|
||||||
if( pIdx->pNext ){
|
if( pIdx->pNext ){
|
||||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_Dup, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
sqliteVdbeAddOp(v, OP_Open, 0, 1, pIdx->zName, 0);
|
|
||||||
for(i=0; i<pIdx->nField; i++){
|
for(i=0; i<pIdx->nField; i++){
|
||||||
int idx = pIdx->aiField[i];
|
int idx = pIdx->aiField[i];
|
||||||
if( pField==0 ){
|
if( pField==0 ){
|
||||||
@ -147,8 +149,8 @@ void sqliteInsert(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sqliteVdbeAddOp(v, OP_MakeKey, pIdx->nField, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_MakeKey, pIdx->nField, 0, 0, 0);
|
||||||
sqliteVdbeAddOp(v, OP_PutIdx, 0, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_PutIdx, idx, 0, 0, 0);
|
||||||
sqliteVdbeAddOp(v, OP_Close, 0, 0, 0, 0);
|
sqliteVdbeAddOp(v, OP_Close, idx, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
src/main.c
21
src/main.c
@ -26,7 +26,7 @@
|
|||||||
** other files are for internal use by SQLite and should not be
|
** other files are for internal use by SQLite and should not be
|
||||||
** accessed by users of the library.
|
** accessed by users of the library.
|
||||||
**
|
**
|
||||||
** $Id: main.c,v 1.5 2000/06/02 01:51:20 drh Exp $
|
** $Id: main.c,v 1.6 2000/06/02 13:27:59 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
|
|
||||||
@ -54,6 +54,13 @@ static int sqliteOpenCb(void *pDb, int argc, char **argv, char **azColName){
|
|||||||
** Attempt to read the database schema and initialize internal
|
** Attempt to read the database schema and initialize internal
|
||||||
** data structures. Return one of the SQLITE_ error codes to
|
** data structures. Return one of the SQLITE_ error codes to
|
||||||
** indicate success or failure.
|
** indicate success or failure.
|
||||||
|
**
|
||||||
|
** After the database is initialized, the SQLITE_Initialized
|
||||||
|
** bit is set in the flags field of the sqlite structure. An
|
||||||
|
** attempt is made to initialize the database as soon as it
|
||||||
|
** is opened. If that fails (perhaps because another process
|
||||||
|
** has the sqlite_master table locked) than another attempt
|
||||||
|
** is made the first time the database is accessed.
|
||||||
*/
|
*/
|
||||||
static int sqliteInit(sqlite *db, char **pzErrMsg){
|
static int sqliteInit(sqlite *db, char **pzErrMsg){
|
||||||
Vdbe *vdbe;
|
Vdbe *vdbe;
|
||||||
@ -177,6 +184,9 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){
|
|||||||
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
|
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
|
||||||
sqlite_close(db);
|
sqlite_close(db);
|
||||||
return 0;
|
return 0;
|
||||||
|
}else{
|
||||||
|
sqliteFree(pzErrMsg);
|
||||||
|
*pzErrMsg = 0;
|
||||||
}
|
}
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
@ -230,7 +240,14 @@ int sqlite_complete(const char *zSql){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Execute SQL code
|
** Execute SQL code. Return one of the SQLITE_ success/failure
|
||||||
|
** codes. Also write an error message into memory obtained from
|
||||||
|
** malloc() and make *pzErrMsg point to that message.
|
||||||
|
**
|
||||||
|
** If the SQL is a query, then for each row in the query result
|
||||||
|
** the xCallback() function is called. pArg becomes the first
|
||||||
|
** argument to xCallback(). If xCallback=NULL then no callback
|
||||||
|
** is invoked, even for queries.
|
||||||
*/
|
*/
|
||||||
int sqlite_exec(
|
int sqlite_exec(
|
||||||
sqlite *db, /* The database on which the SQL executes */
|
sqlite *db, /* The database on which the SQL executes */
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
** This file contains code to implement the "sqlite" command line
|
** This file contains code to implement the "sqlite" command line
|
||||||
** utility for accessing SQLite databases.
|
** utility for accessing SQLite databases.
|
||||||
**
|
**
|
||||||
** $Id: shell.c,v 1.5 2000/05/31 23:33:17 drh Exp $
|
** $Id: shell.c,v 1.6 2000/06/02 13:27:59 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -53,7 +53,6 @@
|
|||||||
static char *getline(char *zPrompt){
|
static char *getline(char *zPrompt){
|
||||||
char *zLine;
|
char *zLine;
|
||||||
int nLine;
|
int nLine;
|
||||||
char *z;
|
|
||||||
int n;
|
int n;
|
||||||
int eol;
|
int eol;
|
||||||
|
|
||||||
@ -433,7 +432,7 @@ int main(int argc, char **argv){
|
|||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
}else if( argc>=3 && strcmp(argv[0],"-separator")==0 ){
|
}else if( argc>=3 && strcmp(argv[0],"-separator")==0 ){
|
||||||
sprintf(data.separator,"%.*s",sizeof(data.separator)-1,argv[2]);
|
sprintf(data.separator,"%.*s",(int)sizeof(data.separator)-1,argv[2]);
|
||||||
argc -= 2;
|
argc -= 2;
|
||||||
argv += 2;
|
argv += 2;
|
||||||
}else if( strcmp(argv[1],"-header")==0 ){
|
}else if( strcmp(argv[1],"-header")==0 ){
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*************************************************************************
|
*************************************************************************
|
||||||
** Internal interface definitions for SQLite.
|
** Internal interface definitions for SQLite.
|
||||||
**
|
**
|
||||||
** @(#) $Id: sqliteInt.h,v 1.9 2000/06/02 01:51:20 drh Exp $
|
** @(#) $Id: sqliteInt.h,v 1.10 2000/06/02 13:28:00 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqlite.h"
|
#include "sqlite.h"
|
||||||
#include "dbbe.h"
|
#include "dbbe.h"
|
||||||
@ -269,3 +269,4 @@ int sqliteLikeCompare(const unsigned char*,const unsigned char*);
|
|||||||
char *sqliteTableNameFromToken(Token*);
|
char *sqliteTableNameFromToken(Token*);
|
||||||
int sqliteExprCheck(Parse*, Expr*, int, int*);
|
int sqliteExprCheck(Parse*, Expr*, int, int*);
|
||||||
int sqliteFuncId(Token*);
|
int sqliteFuncId(Token*);
|
||||||
|
int sqliteExprResolveIds(Parse*, IdList*, Expr*);
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
** This file contains functions for allocating memory, comparing
|
** This file contains functions for allocating memory, comparing
|
||||||
** strings, and stuff like that.
|
** strings, and stuff like that.
|
||||||
**
|
**
|
||||||
** $Id: util.c,v 1.8 2000/05/31 22:58:39 drh Exp $
|
** $Id: util.c,v 1.9 2000/06/02 13:28:00 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@ -683,8 +683,6 @@ int sqliteGlobCompare(const char *zPattern, const char *zString){
|
|||||||
int
|
int
|
||||||
sqliteLikeCompare(const unsigned char *zPattern, const unsigned char *zString){
|
sqliteLikeCompare(const unsigned char *zPattern, const unsigned char *zString){
|
||||||
register char c;
|
register char c;
|
||||||
int invert;
|
|
||||||
int seen;
|
|
||||||
char c2;
|
char c2;
|
||||||
|
|
||||||
while( (c = UpperToLower[*zPattern])!=0 ){
|
while( (c = UpperToLower[*zPattern])!=0 ){
|
||||||
|
67
test/select2.test
Normal file
67
test/select2.test
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# Copyright (c) 1999, 2000 D. Richard Hipp
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2 of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public
|
||||||
|
# License along with this library; if not, write to the
|
||||||
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
# Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
# Author contact information:
|
||||||
|
# drh@hwaci.com
|
||||||
|
# http://www.hwaci.com/drh/
|
||||||
|
#
|
||||||
|
#***********************************************************************
|
||||||
|
# This file implements regression tests for SQLite library. The
|
||||||
|
# focus of this file is testing the SELECT statement.
|
||||||
|
#
|
||||||
|
# $Id: select2.test,v 1.1 2000/06/02 13:28:16 drh Exp $
|
||||||
|
|
||||||
|
set testdir [file dirname $argv0]
|
||||||
|
source $testdir/tester.tcl
|
||||||
|
|
||||||
|
execsql {CREATE TABLE tbl1(f1 int, f2 int)}
|
||||||
|
for {set i 0} {$i<=30} {incr i} {
|
||||||
|
execsql "INSERT INTO tbl1 VALUES([expr {$i%9}],[expr {$i%10}])"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Do a second query inside a first.
|
||||||
|
#
|
||||||
|
do_test select2-1.1 {
|
||||||
|
set sql {SELECT DISTINCT f1 FROM tbl1 ORDER BY f1}
|
||||||
|
set r {}
|
||||||
|
db eval $sql data {
|
||||||
|
set f1 $data(f1)
|
||||||
|
lappend r $f1:
|
||||||
|
set sql2 "SELECT f2 FROM tbl1 WHERE f1=$f1 ORDER BY f2"
|
||||||
|
db eval $sql2 d2 {
|
||||||
|
lappend r $d2(f2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set r
|
||||||
|
} {0: 0 7 8 9 1: 0 1 8 9 2: 0 1 2 9 3: 0 1 2 3 4: 2 3 4 5: 3 4 5 6: 4 5 6 7: 5 6 7 8: 6 7 8}
|
||||||
|
|
||||||
|
|
||||||
|
do_test select2-1.2 {
|
||||||
|
set sql {SELECT DISTINCT f1 FROM tbl1 WHERE f1>3 AND f1<5}
|
||||||
|
set r {}
|
||||||
|
db eval $sql data {
|
||||||
|
set f1 $data(f1)
|
||||||
|
lappend r $f1:
|
||||||
|
set sql2 "SELECT f2 FROM tbl1 WHERE f1=$f1 ORDER BY f2"
|
||||||
|
db eval $sql2 d2 {
|
||||||
|
lappend r $d2(f2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set r
|
||||||
|
} {4: 2 3 4}
|
||||||
|
|
||||||
|
finish_test
|
@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# Run this Tcl script to generate the sqlite.html file.
|
# Run this Tcl script to generate the sqlite.html file.
|
||||||
#
|
#
|
||||||
set rcsid {$Id: c_interface.tcl,v 1.2 2000/05/29 18:32:17 drh Exp $}
|
set rcsid {$Id: c_interface.tcl,v 1.3 2000/06/02 13:28:00 drh Exp $}
|
||||||
|
|
||||||
puts {<html>
|
puts {<html>
|
||||||
<head>
|
<head>
|
||||||
@ -22,8 +22,9 @@ programming interface.</p>
|
|||||||
|
|
||||||
<h2>The API</h2>
|
<h2>The API</h2>
|
||||||
|
|
||||||
<p>The interface to the SQLite library consists of 4 functions
|
<p>The interface to the SQLite library consists of 4 functions,
|
||||||
and one opaque data structure.</p>
|
one opaque data structure, and some constants used as return
|
||||||
|
values from sqlite_exec():</p>
|
||||||
|
|
||||||
<blockquote><pre>
|
<blockquote><pre>
|
||||||
typedef struct sqlite sqlite;
|
typedef struct sqlite sqlite;
|
||||||
@ -41,6 +42,15 @@ int sqlite_exec(
|
|||||||
);
|
);
|
||||||
|
|
||||||
int sqlite_complete(const char *sql);
|
int sqlite_complete(const char *sql);
|
||||||
|
|
||||||
|
#define SQLITE_OK 0 /* Successful result */
|
||||||
|
#define SQLITE_INTERNAL 1 /* An internal logic error in SQLite */
|
||||||
|
#define SQLITE_ERROR 2 /* SQL error or missing database */
|
||||||
|
#define SQLITE_PERM 3 /* Access permission denied */
|
||||||
|
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
|
||||||
|
#define SQLITE_BUSY 5 /* One or more database files are locked */
|
||||||
|
#define SQLITE_NOMEM 6 /* A malloc() failed */
|
||||||
|
#define SQLITE_READONLY 7 /* Attempt to write a readonly database */
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
<p>All of the above definitions are included in the "sqlite.h"
|
<p>All of the above definitions are included in the "sqlite.h"
|
||||||
@ -48,7 +58,7 @@ header file that comes in the source tree.</p>
|
|||||||
|
|
||||||
<h2>Opening a database</h2>
|
<h2>Opening a database</h2>
|
||||||
|
|
||||||
<p>Use the <b>sqlite_open</b> function to open an existing SQLite
|
<p>Use the <b>sqlite_open()</b> function to open an existing SQLite
|
||||||
database or to create a new SQLite database. The first argument
|
database or to create a new SQLite database. The first argument
|
||||||
is the database name. The second argument is a constant 0666 to
|
is the database name. The second argument is a constant 0666 to
|
||||||
open the database for reading and writing and 0444 to open the
|
open the database for reading and writing and 0444 to open the
|
||||||
@ -73,7 +83,8 @@ an empty directory and the second parameter set to 0666.</p>
|
|||||||
<p>The return value of the <b>sqlite_open()</b> function is a
|
<p>The return value of the <b>sqlite_open()</b> function is a
|
||||||
pointer to an opaque <b>sqlite</b> structure. This pointer will
|
pointer to an opaque <b>sqlite</b> structure. This pointer will
|
||||||
be the first argument to all subsequent SQLite function calls that
|
be the first argument to all subsequent SQLite function calls that
|
||||||
deal with the same database.</p>
|
deal with the same database. NULL is returned if the open fails
|
||||||
|
for any reason.</p>
|
||||||
|
|
||||||
<h2>Closing the database</h2>
|
<h2>Closing the database</h2>
|
||||||
|
|
||||||
@ -89,14 +100,17 @@ and queries. This function requires 5 parameters as follows:</p>
|
|||||||
<ol>
|
<ol>
|
||||||
<li><p>A pointer to the sqlite structure obtained from a prior call
|
<li><p>A pointer to the sqlite structure obtained from a prior call
|
||||||
to <b>sqlite_open()</b>.</p></li>
|
to <b>sqlite_open()</b>.</p></li>
|
||||||
<li><p>A null-terminated string containing the text of the SQL statements
|
<li><p>A null-terminated string containing the text of one or more
|
||||||
and/or queries to be processed.</p></li>
|
SQL statements and/or queries to be processed.</p></li>
|
||||||
<li><p>A pointer to a callback function which is invoked once for each
|
<li><p>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
|
row in the result of a query. This argument may be NULL, in which
|
||||||
case no callbacks will ever be invoked.</p></li>
|
case no callbacks will ever be invoked.</p></li>
|
||||||
<li><p>A pointer to anything that is forward to become the first argument
|
<li><p>A pointer that is forwarded to become the first argument
|
||||||
to the callback function.</p></li>
|
to the callback function.</p></li>
|
||||||
<li><p>A pointer to a string pointer into which error messages are written.
|
<li><p>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
|
This argument may be NULL, in which case error messages are not
|
||||||
reported back to the calling function.</p></li>
|
reported back to the calling function.</p></li>
|
||||||
</ol>
|
</ol>
|
||||||
@ -115,34 +129,43 @@ int Callback(void *pArg, int argc, char **argv, char **columnNames){
|
|||||||
to <b>sqlite_exec()</b> This parameter can be used to pass arbitrary
|
to <b>sqlite_exec()</b> This parameter can be used to pass arbitrary
|
||||||
information through to the callback function from client code.
|
information through to the callback function from client code.
|
||||||
The second argument is the number columns in the query result.
|
The second argument is the number columns in the query result.
|
||||||
The third argument is an array of pointers to string where each string
|
The third argument is an array of pointers to strings where each string
|
||||||
is a single column of the result for that record. The names of the
|
is a single column of the result for that record. The names of the
|
||||||
columns are contained in the fourth argument.</p>
|
columns are contained in the fourth argument.</p>
|
||||||
|
|
||||||
<p>The callback function should normally return 0. If the callback
|
<p>The callback function should normally return 0. If the callback
|
||||||
function returns non-zero, the query is immediately aborted and the
|
function returns non-zero, the query is immediately aborted and
|
||||||
return value of the callback is returned from <b>sqlite_exec()</b>.
|
<b>sqlite_exec()</b> will return SQLITE_ABORT.</p>
|
||||||
|
|
||||||
<h2>Testing for a complete SQL statement</h2>
|
<h2>Testing for a complete SQL statement</h2>
|
||||||
|
|
||||||
<p>The last interface routine to SQLite is a convenience function used
|
<p>The last interface routine to SQLite is a convenience function used
|
||||||
to test whether or not a string forms a complete SQL statement.
|
to test whether or not a string forms a complete SQL statement.
|
||||||
If the <b>sqlite_complete</b> function returns true when its input
|
If the <b>sqlite_complete()</b> function returns true when its input
|
||||||
is a string, then the argument forms a complete SQL statement.
|
is a string, then the argument forms a complete SQL statement.
|
||||||
There are no guarantees that the syntax of that statement is correct,
|
There are no guarantees that the syntax of that statement is correct,
|
||||||
but we at least know the statement is complete. If <b>sqlite_complete</b>
|
but we at least know the statement is complete. If <b>sqlite_complete()</b>
|
||||||
returns false, then more text is required to complete the SQL statement.</p>
|
returns false, then more text is required to complete the SQL statement.</p>
|
||||||
|
|
||||||
<p>For the purpose of the <b>sqlite_complete()</b> function, an SQL
|
<p>For the purpose of the <b>sqlite_complete()</b> function, an SQL
|
||||||
statement is complete if it ends in a semicolon.</p>
|
statement is complete if it ends in a semicolon.</p>
|
||||||
|
|
||||||
|
<p>The <b>sqlite</b> command-line utility uses the <b>sqlite_complete()</b>
|
||||||
|
function to know when it needs to call <b>sqlite_exec()</b>. After each
|
||||||
|
line of input is received, <b>sqlite</b> calls <b>sqlite_complete()</b>
|
||||||
|
on all input in its buffer. If <b>sqlite_complete()</b> returns true,
|
||||||
|
then <b>sqlite_exec()</b> is called and the input buffer is reset. If
|
||||||
|
<b>sqlite_complete()</b> returns false, then the prompt is changed to
|
||||||
|
the continuation prompt and another line of text is read and added to
|
||||||
|
the input buffer.</p>
|
||||||
|
|
||||||
<h2>Usage Examples</h2>
|
<h2>Usage Examples</h2>
|
||||||
|
|
||||||
<p>For examples of how the SQLite C/C++ interface can be used,
|
<p>For examples of how the SQLite C/C++ interface can be used,
|
||||||
refer to the source code for the "sqlite" program in the
|
refer to the source code for the <b>sqlite</b> program in the
|
||||||
file <b>src/shell.c</b> of the source tree.
|
file <b>src/shell.c</b> of the source tree.
|
||||||
(Additional information about sqlite is available at
|
Additional information about sqlite is available at
|
||||||
<a href="sqlite.html">sqlite.html</a>.)
|
<a href="sqlite.html">sqlite.html</a>.
|
||||||
See also the sources to the Tcl interface for SQLite in
|
See also the sources to the Tcl interface for SQLite in
|
||||||
the source file <b>src/tclsqlite.c</b>.</p>
|
the source file <b>src/tclsqlite.c</b>.</p>
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,21 @@ proc chng {date desc} {
|
|||||||
puts "<DD><P><UL>$desc</UL></P></DD>"
|
puts "<DD><P><UL>$desc</UL></P></DD>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chng {2000 June 2} {
|
||||||
|
<li>All database files to be modified by an UPDATE, INSERT or DELETE are
|
||||||
|
now locked before any changes are made to any files.
|
||||||
|
This makes it safe (I think) to access
|
||||||
|
the same database simultaneously from multiple processes.</li>
|
||||||
|
<li>The code appears stable so we are now calling it "beta".</li>
|
||||||
|
}
|
||||||
|
|
||||||
|
chng {2000 June 1} {
|
||||||
|
<li>Better support for file locking so that two or more processes
|
||||||
|
(or threads)
|
||||||
|
can access the same database simultaneously. More work needed in
|
||||||
|
this area, though.</li>
|
||||||
|
}
|
||||||
|
|
||||||
chng {2000 May 31} {
|
chng {2000 May 31} {
|
||||||
<li>Added support for aggregate functions (Ex: <b>COUNT(*)</b>, <b>MIN(...)</b>)
|
<li>Added support for aggregate functions (Ex: <b>COUNT(*)</b>, <b>MIN(...)</b>)
|
||||||
to the SELECT statement.</li>
|
to the SELECT statement.</li>
|
||||||
|
@ -1,49 +1,54 @@
|
|||||||
#
|
#
|
||||||
# Run this TCL script to generate HTML for the index.html file.
|
# Run this TCL script to generate HTML for the index.html file.
|
||||||
#
|
#
|
||||||
set rcsid {$Id: index.tcl,v 1.9 2000/06/01 00:04:41 drh Exp $}
|
set rcsid {$Id: index.tcl,v 1.10 2000/06/02 13:28:00 drh Exp $}
|
||||||
|
|
||||||
puts {<html>
|
puts {<html>
|
||||||
<head><title>SQLite: An SQL Frontend For GDBM</title></head>
|
<head><title>SQLite: An SQL Database Built Atop GDBM</title></head>
|
||||||
<body bgcolor=white>
|
<body bgcolor=white>
|
||||||
<h1 align=center>SQLite: An SQL Frontend For GDBM</h1>
|
<h1 align=center>SQLite: An SQL Database Built Upon
|
||||||
|
<a href="http://www.gnu.org/software/gdbm/gdbm.html">GDBM</a></h1>
|
||||||
<p align=center>}
|
<p align=center>}
|
||||||
puts "Last modified [lrange $rcsid 3 4] GMT"
|
puts "This page was last modified on [lrange $rcsid 3 4] GMT<br>"
|
||||||
|
puts "The SQLite source code was last modifed on [exec cat last_change] GMT"
|
||||||
puts {</p>}
|
puts {</p>}
|
||||||
|
|
||||||
puts {
|
puts {
|
||||||
<blockquote><em><p>
|
<h2>News</h2>
|
||||||
The SQLite code base is rapidly becoming usable. Most of the commonly
|
<p>
|
||||||
used features of SQL (at least the features of SQL that this author
|
Though still relatively new,
|
||||||
commonly uses) are now supported. There are currently no known
|
the SQLite code base appears to be working well and has therefore
|
||||||
errors in the code. (There are known omissions but that is another
|
been upgraded to "beta" status.
|
||||||
matter.)
|
There are currently no known errors in the code.
|
||||||
One very large database (1M+ records in 50+ separate tables) has
|
One very large database (1M+ records in 50+ separate tables) has
|
||||||
been converted from PostgreSQL and gives every appearance of working
|
been converted from PostgreSQL and gives every appearance of working
|
||||||
correctly. We are rapidly approaching a "beta" release, I think...</p>
|
correctly.</p>
|
||||||
|
|
||||||
<p>Your constructive comments are still very important to us.
|
<p>Your constructive comments are still very important to us.
|
||||||
Please visit the
|
Please visit the
|
||||||
<a href="#mailinglist">mailing list</a> to offer your feedback.</p>
|
<a href="#mailinglist">mailing list</a> to offer feedback.</p>
|
||||||
</em></blockquote>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
puts {<h2>Introduction</h2>
|
puts {<h2>Introduction</h2>
|
||||||
|
|
||||||
<p>SQLite is a C library that implements an SQL frontend to GDBM.
|
<p>SQLite is an SQL database built atop the
|
||||||
SQLite is intended for use in standalone programs that need
|
<a href="http://www.gnu.org/software/gdbm/gdbm.html">GDBM library</a>.
|
||||||
to use an SQL database but which do not have access to a full-blown
|
The SQLite distribution includes both a interactive command-line
|
||||||
SQL RDBMS.</p>
|
access program (<b>sqlite</b>) and a C library (<b>libsqlite.a</b>)
|
||||||
|
that can be linked
|
||||||
|
with a C/C++ program to provide SQL database access without having
|
||||||
|
to rely on an external RDBMS.</p>
|
||||||
|
|
||||||
<p>The C interface to SQLite is very simple, consisting of only
|
<p>The C interface to SQLite is very simple, consisting of only
|
||||||
four functions and a single opaque data structure.
|
four functions, a single opaque data structure, and a handful of
|
||||||
|
constants that define error return codes.
|
||||||
See <a href="c_interface.html">c_interface.html</a> for details.
|
See <a href="c_interface.html">c_interface.html</a> for details.
|
||||||
A Tcl interface
|
A Tcl interface
|
||||||
to SQLite is also available and is included in the source tree.
|
to SQLite is also available and is included in the source tree.
|
||||||
Documentation on the Tcl interface is pending.
|
Documentation on the Tcl interface is pending.
|
||||||
Interfaces for perl and python may be supplied in future releases.</p>
|
Interfaces for perl and python may be supplied in future releases.</p>
|
||||||
|
|
||||||
<p>There is a standalone C program named "sqlite" that can be used
|
<p>The standalone program <b>sqlite</b> can be used
|
||||||
to interactively create, update and/or query an SQLite database.
|
to interactively create, update and/or query an SQLite database.
|
||||||
The sources to the sqlite program are part of the source tree and
|
The sources to the sqlite program are part of the source tree and
|
||||||
can be used as an example of how to interact with the SQLite C
|
can be used as an example of how to interact with the SQLite C
|
||||||
@ -53,7 +58,8 @@ see <a href="sqlite.html">sqlite.html</a>.</p>
|
|||||||
<p>A history of changes to SQLite is found
|
<p>A history of changes to SQLite is found
|
||||||
<a href="changes.html">here</a>.</p>
|
<a href="changes.html">here</a>.</p>
|
||||||
|
|
||||||
<p>SQLite does not try to implement every feature of SQL.
|
<p>SQLite is intended to be small and light-weight.
|
||||||
|
It does not try to implement every feature of SQL.
|
||||||
A few of the many SQL features that SQLite does not (currently)
|
A few of the many SQL features that SQLite does not (currently)
|
||||||
implement are as follows:</p>
|
implement are as follows:</p>
|
||||||
|
|
||||||
@ -97,6 +103,19 @@ puts "This is a [file size sqlite.tar.gz] byte download. The
|
|||||||
tarball was last modified at [clock format [file mtime sqlite.tar.gz]]"
|
tarball was last modified at [clock format [file mtime sqlite.tar.gz]]"
|
||||||
puts {</p>
|
puts {</p>
|
||||||
|
|
||||||
|
<p>To build sqlite, just unwrap the tarball, create a separate
|
||||||
|
build directory, run configure from the build directory and then
|
||||||
|
type "make". For example:</p>
|
||||||
|
|
||||||
|
<blockquote><pre>
|
||||||
|
$ tar xzf sqlite.tar.gz ;# Unpacks into directory named "sqlite"
|
||||||
|
$ mkdir bld ;# Create a separate build directory
|
||||||
|
$ cd bld
|
||||||
|
$ ../sqlite/configure
|
||||||
|
$ make ;# Builds "sqlite" and "libsqlite.a"
|
||||||
|
$ make test ;# Optional: run regression tests
|
||||||
|
</pre></blockquote>
|
||||||
|
|
||||||
<p>You can also download a larger tarball that contains everything
|
<p>You can also download a larger tarball that contains everything
|
||||||
in the source tarball plus all of the sources for the text that
|
in the source tarball plus all of the sources for the text that
|
||||||
appears on this website, and other miscellaneous files. The
|
appears on this website, and other miscellaneous files. The
|
||||||
@ -117,8 +136,11 @@ puts {<h2>Related Sites</h2>
|
|||||||
<a href="http://www.sleepycat.com/">http://www.sleepycat.com/</a>
|
<a href="http://www.sleepycat.com/">http://www.sleepycat.com/</a>
|
||||||
</p></li>
|
</p></li>
|
||||||
|
|
||||||
<li><p>Here is a <a href="http://w3.one.net/~jhoffman/sqltut.htm">
|
<li><p>Here is a good <a href="http://w3.one.net/~jhoffman/sqltut.htm">
|
||||||
tutorial on SQL</a>.</p></li>
|
tutorial on SQL</a>.</p></li>
|
||||||
|
|
||||||
|
<li><p><a href="http://www.postgresql.org/">PostgreSQL</a> is a
|
||||||
|
full-blown SQL RDBMS that is also open source.</p></li>
|
||||||
</ul>}
|
</ul>}
|
||||||
|
|
||||||
puts {
|
puts {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# Run this Tcl script to generate the sqlite.html file.
|
# Run this Tcl script to generate the sqlite.html file.
|
||||||
#
|
#
|
||||||
set rcsid {$Id: sqlite.tcl,v 1.5 2000/06/01 00:03:44 drh Exp $}
|
set rcsid {$Id: sqlite.tcl,v 1.6 2000/06/02 13:28:00 drh Exp $}
|
||||||
|
|
||||||
puts {<html>
|
puts {<html>
|
||||||
<head>
|
<head>
|
||||||
@ -30,7 +30,7 @@ should really be the name of a directory on your disk. If that
|
|||||||
directory did not previously contain an SQLite database, a new one
|
directory did not previously contain an SQLite database, a new one
|
||||||
is created for you automatically. The <b>sqlite</b> program will
|
is created for you automatically. The <b>sqlite</b> program will
|
||||||
prompt you to enter SQL. Type in SQL statements (terminated by a
|
prompt you to enter SQL. Type in SQL statements (terminated by a
|
||||||
semicolon, press "Enter" and the SQL will be executed. It's as
|
semicolon), press "Enter" and the SQL will be executed. It's as
|
||||||
simple as that!</p>
|
simple as that!</p>
|
||||||
|
|
||||||
<p>For example, to create a new SQLite database named "ex1"
|
<p>For example, to create a new SQLite database named "ex1"
|
||||||
@ -56,11 +56,8 @@ sql> (((create table tbl1(one varchar(10), two smallint);)))
|
|||||||
sql> (((insert into tbl1 values('hello!',10);)))
|
sql> (((insert into tbl1 values('hello!',10);)))
|
||||||
sql> (((insert into tbl1 values('goodbye', 20);)))
|
sql> (((insert into tbl1 values('goodbye', 20);)))
|
||||||
sql> (((select * from tbl1;)))
|
sql> (((select * from tbl1;)))
|
||||||
one = hello!
|
hello!|10
|
||||||
two = 10
|
goodbye|20
|
||||||
|
|
||||||
one = goodbye
|
|
||||||
two = 20
|
|
||||||
sql>
|
sql>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +70,7 @@ from the computer are shown in black with a constant-width font.)</p>
|
|||||||
End-Of-File character (usually a Control-D) or the interrupt
|
End-Of-File character (usually a Control-D) or the interrupt
|
||||||
character (usually a Control-C).</p>
|
character (usually a Control-C).</p>
|
||||||
|
|
||||||
<p>Make sure you type a semicolon at the end of each SQL command.
|
<p>Make sure you type a semicolon at the end of each SQL command!
|
||||||
The sqlite looks for a semicolon to know when your SQL command is
|
The sqlite looks for a semicolon to know when your SQL command is
|
||||||
complete. If you omit the semicolon, sqlite will give you a
|
complete. If you omit the semicolon, sqlite will give you a
|
||||||
continuation prompt and wait for you to enter more text to be
|
continuation prompt and wait for you to enter more text to be
|
||||||
@ -122,10 +119,10 @@ sql>
|
|||||||
puts {
|
puts {
|
||||||
<p>
|
<p>
|
||||||
But you cannot execute DROP TABLE, UPDATE, INSERT or DELETE against
|
But you cannot execute DROP TABLE, UPDATE, INSERT or DELETE against
|
||||||
the sqlite_master table. At least not directly. The sqlite_master
|
the sqlite_master table. The sqlite_master
|
||||||
table is updated automatically as you create or drop tables and
|
table is updated automatically as you create or drop tables and
|
||||||
indices from the database, but you can not modify sqlite_master
|
indices from the database. You can not make manual changes
|
||||||
directly.
|
to the sqlite_master table.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2>Special commands to sqlite</h2>
|
<h2>Special commands to sqlite</h2>
|
||||||
@ -136,7 +133,7 @@ on to the SQLite library for execution.
|
|||||||
But if an input line begins with a dot ("."), then
|
But if an input line begins with a dot ("."), then
|
||||||
that line is intercepted and interpreted by the sqlite program itself.
|
that line is intercepted and interpreted by the sqlite program itself.
|
||||||
These "dot commands" are typically used to change the output format
|
These "dot commands" are typically used to change the output format
|
||||||
of queries, or to execute certain command prepackaged query statements.
|
of queries, or to execute certain prepackaged query statements.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -187,8 +184,9 @@ sql>
|
|||||||
}
|
}
|
||||||
|
|
||||||
puts {
|
puts {
|
||||||
<p>Line mode used to be the default mode setting. But recently the
|
<p>Line mode used to be the default mode setting. But after some
|
||||||
default mode was changed to "list".</p>
|
experience using the utility, it was decided that "list" mode made
|
||||||
|
a better default and so now the default mode is "list".</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
puts {
|
puts {
|
||||||
@ -221,7 +219,7 @@ sql>
|
|||||||
}
|
}
|
||||||
|
|
||||||
puts {
|
puts {
|
||||||
<p>The ".width" command in the example above set the width of the first
|
<p>The ".width" command in the example above sets the width of the first
|
||||||
column to 12 and the width of the second column to 6. All other column
|
column to 12 and the width of the second column to 6. All other column
|
||||||
widths were unaltered. You can gives as many arguments to ".width" as
|
widths were unaltered. You can gives as many arguments to ".width" as
|
||||||
necessary to specify the widths of as many columns as are in your
|
necessary to specify the widths of as many columns as are in your
|
||||||
@ -246,7 +244,7 @@ list mode, each record of a query result is written on one line of
|
|||||||
output and each field within that record is separated by a specific
|
output and each field within that record is separated by a specific
|
||||||
separator string. The default separator is a pipe symbol ("|").
|
separator string. The default separator is a pipe symbol ("|").
|
||||||
List mode is especially useful when you are going to send the output
|
List mode is especially useful when you are going to send the output
|
||||||
of a query to another program (such as AWK) for additional process.</p>}
|
of a query to another program (such as AWK) for additional processing.</p>}
|
||||||
|
|
||||||
Code {
|
Code {
|
||||||
sql> (((.mode list)))
|
sql> (((.mode list)))
|
||||||
@ -368,8 +366,8 @@ SELECT sql FROM sqlite_master
|
|||||||
ORDER BY tbl_name, type DESC, name
|
ORDER BY tbl_name, type DESC, name
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
<p>Of, if you give an argument to ".schema" because you only
|
<p>Or, if you give an argument to ".schema" because you only
|
||||||
one the schema for a single table, the query looks like this:</p>
|
want the schema for a single table, the query looks like this:</p>
|
||||||
|
|
||||||
<blockquote><pre>
|
<blockquote><pre>
|
||||||
SELECT sql FROM sqlite_master
|
SELECT sql FROM sqlite_master
|
||||||
@ -385,7 +383,7 @@ to ".schema", of course.</p>
|
|||||||
<p>The ".explain" dot command can be used to set the output mode
|
<p>The ".explain" dot command can be used to set the output mode
|
||||||
to "column" and to set the column widths to values that are reasonable
|
to "column" and to set the column widths to values that are reasonable
|
||||||
for looking at the output of an EXPLAIN command. The EXPLAIN command
|
for looking at the output of an EXPLAIN command. The EXPLAIN command
|
||||||
is an SQLite-specific command that is useful for debugging. If any
|
is an SQLite-specific SQL extension that is useful for debugging. If any
|
||||||
regular SQL is prefaced by EXPLAIN, then the SQL command is parsed and
|
regular SQL is prefaced by EXPLAIN, then the SQL command is parsed and
|
||||||
analyzed but is not executed. Instead, the sequence of virtual machine
|
analyzed but is not executed. Instead, the sequence of virtual machine
|
||||||
instructions that would have been used to execute the SQL command are
|
instructions that would have been used to execute the SQL command are
|
||||||
@ -397,7 +395,7 @@ sql> (((explain delete from tbl1 where two<20;)))
|
|||||||
addr opcode p1 p2 p3
|
addr opcode p1 p2 p3
|
||||||
---- ------------ ----- ----- -------------------------------------
|
---- ------------ ----- ----- -------------------------------------
|
||||||
0 ListOpen 0 0
|
0 ListOpen 0 0
|
||||||
1 Open 0 0 tbl1
|
1 Open 0 1 tbl1
|
||||||
2 Next 0 9
|
2 Next 0 9
|
||||||
3 Field 0 1
|
3 Field 0 1
|
||||||
4 Integer 20 0
|
4 Integer 20 0
|
||||||
|
Reference in New Issue
Block a user