Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f3a5a57ddb | |||
| 1832890357 | |||
| 97117601d2 | |||
| f9ec81c84d | |||
| 45041e263a | |||
| 3e5c826219 | |||
| 4e0e4d7a9e | |||
| 064cf76bb1 | |||
| a38518d673 |
+184
-267
@@ -26,7 +26,7 @@ BCC = @BUILD_CC@ @BUILD_CFLAGS@
|
||||
# will run on the target platform. (BCC and TCC are usually the
|
||||
# same unless your are cross-compiling.)
|
||||
#
|
||||
TCC = @TARGET_CC@ @TARGET_CFLAGS@ -I. -I${TOP}/src -DNDEBUG
|
||||
TCC = @TARGET_CC@ @TARGET_CFLAGS@ -I. -I${TOP}/src
|
||||
|
||||
# Some standard variables and programs
|
||||
#
|
||||
@@ -57,30 +57,44 @@ READLINE_FLAGS = -DHAVE_READLINE=@TARGET_HAVE_READLINE@ @TARGET_READLINE_INC@
|
||||
#
|
||||
LIBREADLINE = @TARGET_READLINE_LIBS@
|
||||
|
||||
# Should the database engine be compiled threadsafe
|
||||
# Should the database engine assume text is coded as UTF-8 or iso8859?
|
||||
#
|
||||
THREADSAFE = -DTHREADSAFE=@THREADSAFE@
|
||||
# ENCODING = UTF8
|
||||
# ENCODING = ISO8859
|
||||
ENCODING = @ENCODING@
|
||||
|
||||
# Flags controlling use of the in memory btree implementation
|
||||
#
|
||||
# SQLITE_OMIT_INMEMORYDB is defined in order to omit the in-memory
|
||||
# red/black tree driver in the file btree_rb.c
|
||||
#
|
||||
# TEMP_STORE is 0 to force temporary tables to be in a file, 1 to
|
||||
# default to file, 2 to default to memory, and 3 to force temporary
|
||||
# tables to always be in memory.
|
||||
#
|
||||
TEMP_STORE = -DTEMP_STORE=@TEMP_STORE@
|
||||
INMEMORYDB = @INMEMORYDB@
|
||||
INCOREFLAGS = -DTEMP_STORE=@TEMP_STORE@
|
||||
|
||||
ifeq (${INMEMORYDB},0)
|
||||
INCOREFLAGS += -DSQLITE_OMIT_INMEMORYDB=1
|
||||
endif
|
||||
|
||||
# You should not have to change anything below this line
|
||||
###############################################################################
|
||||
|
||||
# Object files for the SQLite library.
|
||||
#
|
||||
LIBOBJ = attach.lo auth.lo btree.lo build.lo date.lo delete.lo \
|
||||
expr.lo func.lo hash.lo insert.lo \
|
||||
main.lo opcodes.lo os_mac.lo os_unix.lo os_win.lo \
|
||||
pager.lo parse.lo pragma.lo printf.lo random.lo \
|
||||
select.lo table.lo tokenize.lo trigger.lo update.lo util.lo vacuum.lo \
|
||||
vdbe.lo vdbeapi.lo vdbeaux.lo vdbemem.lo \
|
||||
where.lo utf.lo legacy.lo
|
||||
LIBOBJ = attach.lo auth.lo btree.lo build.lo copy.lo date.lo \
|
||||
delete.lo encode.lo expr.lo func.lo hash.lo insert.lo \
|
||||
main.lo opcodes.lo os.lo pager.lo parse.lo pragma.lo \
|
||||
printf.lo random.lo select.lo table.lo tokenize.lo \
|
||||
update.lo util.lo vacuum.lo vdbe.lo vdbeaux.lo \
|
||||
where.lo trigger.lo
|
||||
|
||||
# Only build the in-core DB if it is required.
|
||||
ifeq (${INMEMORYDB},1)
|
||||
LIBOBJ += btree_rb.lo
|
||||
endif
|
||||
|
||||
# All of the source code files.
|
||||
#
|
||||
@@ -89,7 +103,9 @@ SRC = \
|
||||
$(TOP)/src/auth.c \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/btree.h \
|
||||
$(TOP)/src/btree_rb.c \
|
||||
$(TOP)/src/build.c \
|
||||
$(TOP)/src/copy.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/delete.c \
|
||||
$(TOP)/src/encode.c \
|
||||
@@ -98,11 +114,8 @@ SRC = \
|
||||
$(TOP)/src/hash.c \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os_mac.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pager.h \
|
||||
$(TOP)/src/parse.y \
|
||||
@@ -117,16 +130,12 @@ SRC = \
|
||||
$(TOP)/src/tclsqlite.c \
|
||||
$(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/trigger.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/update.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vacuum.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/vdbeapi.c \
|
||||
$(TOP)/src/vdbeaux.c \
|
||||
$(TOP)/src/vdbemem.c \
|
||||
$(TOP)/src/vdbeInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/where.c
|
||||
|
||||
# Source code to the test files.
|
||||
@@ -134,36 +143,26 @@ SRC = \
|
||||
TESTSRC = \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/os_mac.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/test5.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/md5.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
sqlite3.h \
|
||||
sqlite.h \
|
||||
$(TOP)/src/btree.h \
|
||||
config.h \
|
||||
$(TOP)/src/hash.h \
|
||||
opcodes.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/os_common.h \
|
||||
$(TOP)/src/os_mac.h \
|
||||
$(TOP)/src/os_unix.h \
|
||||
$(TOP)/src/os_win.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
parse.h
|
||||
|
||||
# Header files used by the VDBE submodule
|
||||
@@ -175,7 +174,7 @@ VDBEHDR = \
|
||||
# This is the default Makefile target. The objects listed here
|
||||
# are what get build when you type just "make" with no arguments.
|
||||
#
|
||||
all: sqlite3.h libsqlite3.la sqlite3@TARGET_EXEEXT@
|
||||
all: sqlite.h libsqlite.la sqlite@TARGET_EXEEXT@
|
||||
|
||||
Makefile: $(TOP)/Makefile.in
|
||||
./config.status
|
||||
@@ -187,18 +186,18 @@ last_change: $(SRC)
|
||||
cat $(SRC) | grep '$$Id: ' | sort +4 | tail -1 \
|
||||
| awk '{print $$5,$$6}' >last_change
|
||||
|
||||
libsqlite3.la: $(LIBOBJ)
|
||||
$(LTLINK) -o libsqlite3.la $(LIBOBJ) ${RELEASE} -rpath @exec_prefix@/lib \
|
||||
libsqlite.la: $(LIBOBJ)
|
||||
$(LTLINK) -o libsqlite.la $(LIBOBJ) ${RELEASE} -rpath @exec_prefix@/lib \
|
||||
-version-info "8:6:8"
|
||||
|
||||
libtclsqlite3.la: tclsqlite.lo libsqlite3.la
|
||||
$(LTLINK) -o libtclsqlite3.la tclsqlite.lo \
|
||||
libsqlite3.la $(LIBTCL) -rpath @exec_prefix@/lib/sqlite \
|
||||
libtclsqlite.la: tclsqlite.lo libsqlite.la
|
||||
$(LTLINK) -o libtclsqlite.la tclsqlite.lo \
|
||||
libsqlite.la $(LIBTCL) -rpath @exec_prefix@/lib/sqlite \
|
||||
-version-info "8:6:8"
|
||||
|
||||
sqlite3@TARGET_EXEEXT@: $(TOP)/src/shell.c libsqlite3.la sqlite3.h
|
||||
$(LTLINK) $(READLINE_FLAGS) -o sqlite3 $(TOP)/src/shell.c \
|
||||
libsqlite3.la $(LIBREADLINE)
|
||||
sqlite@TARGET_EXEEXT@: $(TOP)/src/shell.c libsqlite.la sqlite.h
|
||||
$(LTLINK) $(READLINE_FLAGS) -o sqlite $(TOP)/src/shell.c \
|
||||
libsqlite.la $(LIBREADLINE)
|
||||
|
||||
# This target creates a directory named "tsrc" and fills it with
|
||||
# copies of all of the C source code and header files needed to
|
||||
@@ -212,7 +211,6 @@ target_source: $(SRC) $(VDBEHDR)
|
||||
cp $(SRC) $(VDBEHDR) tsrc
|
||||
rm tsrc/sqlite.h.in tsrc/parse.y
|
||||
cp parse.c opcodes.c tsrc
|
||||
cp $(TOP)/sqlite3.def tsrc
|
||||
|
||||
# Rules to build the LEMON compiler generator
|
||||
#
|
||||
@@ -220,21 +218,49 @@ lemon@BUILD_EXEEXT@: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
$(BCC) -o lemon $(TOP)/tool/lemon.c
|
||||
cp $(TOP)/tool/lempar.c .
|
||||
|
||||
|
||||
# Rules to build individual files
|
||||
#
|
||||
attach.lo: $(TOP)/src/attach.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/attach.c
|
||||
|
||||
auth.lo: $(TOP)/src/auth.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/auth.c
|
||||
|
||||
btree.lo: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
|
||||
$(LTCOMPILE) -c $(TOP)/src/btree.c
|
||||
|
||||
btree_rb.lo: $(TOP)/src/btree_rb.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/btree_rb.c
|
||||
|
||||
build.lo: $(TOP)/src/build.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/build.c
|
||||
|
||||
main.lo: $(TOP)/src/main.c $(HDR)
|
||||
$(LTCOMPILE) -c ${INCOREFLAGS} $(TOP)/src/main.c
|
||||
|
||||
pager.lo: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
$(LTCOMPILE) -c $(TOP)/src/pager.c
|
||||
|
||||
opcodes.lo: opcodes.c
|
||||
$(LTCOMPILE) -c opcodes.c
|
||||
|
||||
opcodes.c: $(TOP)/src/vdbe.c
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.c
|
||||
echo 'char *sqliteOpcodeNames[] = { "???", ' >>opcodes.c
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/^.*OP_/ "/' -e 's/:.*$$/", /' >>opcodes.c
|
||||
echo '};' >>opcodes.c
|
||||
|
||||
opcodes.h: $(TOP)/src/vdbe.h
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.h
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/://' | \
|
||||
awk '{printf "#define %-30s %3d\n", $$2, ++cnt}' >>opcodes.h
|
||||
|
||||
os.lo: $(TOP)/src/os.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/os.c
|
||||
|
||||
parse.lo: parse.c $(HDR)
|
||||
$(LTCOMPILE) -c parse.c
|
||||
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon@BUILD_EXEEXT@
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon parse.y
|
||||
|
||||
# The config.h file will contain a single #define that tells us how
|
||||
# many bytes are in a pointer. This only works if a pointer is the
|
||||
# same size on the host as it is on the target. If you are cross-compiling
|
||||
@@ -251,6 +277,29 @@ config.h:
|
||||
echo >>config.h
|
||||
rm -f temp.c temp
|
||||
|
||||
sqlite.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||
-e s/--ENCODING--/$(ENCODING)/ \
|
||||
$(TOP)/src/sqlite.h.in >sqlite.h
|
||||
|
||||
tokenize.lo: $(TOP)/src/tokenize.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/tokenize.c
|
||||
|
||||
util.lo: $(TOP)/src/util.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/util.c
|
||||
|
||||
vdbe.lo: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbe.c
|
||||
|
||||
vdbeaux.lo: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbeaux.c
|
||||
|
||||
where.lo: $(TOP)/src/where.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/where.c
|
||||
|
||||
copy.lo: $(TOP)/src/copy.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/copy.c
|
||||
|
||||
date.lo: $(TOP)/src/date.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/date.c
|
||||
|
||||
@@ -272,203 +321,79 @@ hash.lo: $(TOP)/src/hash.c $(HDR)
|
||||
insert.lo: $(TOP)/src/insert.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/insert.c
|
||||
|
||||
legacy.lo: $(TOP)/src/legacy.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/legacy.c
|
||||
|
||||
main.lo: $(TOP)/src/main.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/main.c
|
||||
|
||||
pager.lo: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
$(LTCOMPILE) -c $(TOP)/src/pager.c
|
||||
|
||||
opcodes.lo: opcodes.c
|
||||
$(LTCOMPILE) -c opcodes.c
|
||||
|
||||
opcodes.c: $(TOP)/src/vdbe.c
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.c
|
||||
echo 'char *sqlite3OpcodeNames[] = { "???", ' >>opcodes.c
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/^.*OP_/ "/' -e 's/:.*$$/", /' >>opcodes.c
|
||||
echo '};' >>opcodes.c
|
||||
|
||||
opcodes.h: $(TOP)/src/vdbe.h
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.h
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/://' | \
|
||||
awk '{printf "#define %-30s %3d\n", $$2, ++cnt}' >>opcodes.h
|
||||
|
||||
os_mac.lo: $(TOP)/src/os_mac.c $(HDR)
|
||||
$(LTCOMPILE) $(THREADSAFE) -c $(TOP)/src/os_mac.c
|
||||
|
||||
os_unix.lo: $(TOP)/src/os_unix.c $(HDR)
|
||||
$(LTCOMPILE) $(THREADSAFE) -c $(TOP)/src/os_unix.c
|
||||
|
||||
os_win.lo: $(TOP)/src/os_win.c $(HDR)
|
||||
$(LTCOMPILE) $(THREADSAFE) -c $(TOP)/src/os_win.c
|
||||
|
||||
parse.lo: parse.c $(HDR)
|
||||
$(LTCOMPILE) -c parse.c
|
||||
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon@BUILD_EXEEXT@
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon parse.y
|
||||
|
||||
pragma.lo: $(TOP)/src/pragma.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
|
||||
|
||||
printf.lo: $(TOP)/src/printf.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
|
||||
random.lo: $(TOP)/src/random.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/random.c
|
||||
|
||||
select.lo: $(TOP)/src/select.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/select.c
|
||||
|
||||
sqlite3.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||
$(TOP)/src/sqlite.h.in >sqlite3.h
|
||||
|
||||
table.lo: $(TOP)/src/table.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/table.c
|
||||
|
||||
tclsqlite.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
tokenize.lo: $(TOP)/src/tokenize.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/tokenize.c
|
||||
|
||||
trigger.lo: $(TOP)/src/trigger.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/trigger.c
|
||||
|
||||
update.lo: $(TOP)/src/update.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/update.c
|
||||
|
||||
utf.lo: $(TOP)/src/utf.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/utf.c
|
||||
|
||||
util.lo: $(TOP)/src/util.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/util.c
|
||||
|
||||
vacuum.lo: $(TOP)/src/vacuum.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vacuum.c
|
||||
|
||||
vdbe.lo: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbe.c
|
||||
tclsqlite.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
vdbeapi.lo: $(TOP)/src/vdbeapi.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbeapi.c
|
||||
pragma.lo: $(TOP)/src/pragma.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
|
||||
|
||||
vdbeaux.lo: $(TOP)/src/vdbeaux.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbeaux.c
|
||||
printf.lo: $(TOP)/src/printf.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
|
||||
vdbemem.lo: $(TOP)/src/vdbemem.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbemem.c
|
||||
attach.lo: $(TOP)/src/attach.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/attach.c
|
||||
|
||||
where.lo: $(TOP)/src/where.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/where.c
|
||||
auth.lo: $(TOP)/src/auth.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/auth.c
|
||||
|
||||
tclsqlite-sh.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -DTCLSH=1 -o $@ -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
tclsqlite3: tclsqlite-sh.lo libsqlite3.la
|
||||
$(LTLINK) $(TCL_FLAGS) -o tclsqlite3 tclsqlite-sh.lo \
|
||||
libsqlite3.la $(LIBTCL)
|
||||
tclsqlite: tclsqlite-sh.lo libsqlite.la
|
||||
$(LTLINK) $(TCL_FLAGS) -o tclsqlite tclsqlite-sh.lo libsqlite.la $(LIBTCL)
|
||||
|
||||
testfixture@TARGET_EXEEXT@: $(TOP)/src/tclsqlite.c libtclsqlite3.la libsqlite3.la $(TESTSRC)
|
||||
testfixture@TARGET_EXEEXT@: $(TOP)/src/tclsqlite.c libtclsqlite.la libsqlite.la $(TESTSRC)
|
||||
$(LTLINK) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1\
|
||||
$(THREADSAFE) $(TEMP_STORE)\
|
||||
-o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libtclsqlite3.la libsqlite3.la $(LIBTCL)
|
||||
libtclsqlite.la libsqlite.la $(LIBTCL)
|
||||
|
||||
crashtest@TARGET_EXEEXT@: $(TOP)/src/tclsqlite.c libsqlite3.la $(TESTSRC) $(TOP)/src/os_test.c
|
||||
$(LTLINK) $(TCL_FLAGS) -DOS_TEST=1 -DTCLSH=1 -DSQLITE_TEST=1 \
|
||||
-o crashtest \
|
||||
$(TESTSRC) $(TOP)/src/os_test.c $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.la $(LIBTCL) $(THREADLIB)
|
||||
|
||||
|
||||
|
||||
fulltest: testfixture@TARGET_EXEEXT@ sqlite3@TARGET_EXEEXT@ crashtest@TARGET_EXEEXT@
|
||||
fulltest: testfixture@TARGET_EXEEXT@ sqlite@TARGET_EXEEXT@
|
||||
./testfixture $(TOP)/test/all.test
|
||||
|
||||
test: testfixture@TARGET_EXEEXT@ sqlite3@TARGET_EXEEXT@
|
||||
test: testfixture@TARGET_EXEEXT@ sqlite@TARGET_EXEEXT@
|
||||
./testfixture $(TOP)/test/quick.test
|
||||
|
||||
index.html: $(TOP)/www/index.tcl last_change
|
||||
tclsh $(TOP)/www/index.tcl `cat $(TOP)/VERSION` >index.html
|
||||
|
||||
# Rules used to build documentation
|
||||
#
|
||||
arch.html: $(TOP)/www/arch.tcl
|
||||
tclsh $(TOP)/www/arch.tcl >arch.html
|
||||
|
||||
arch2.gif: $(TOP)/www/arch2.gif
|
||||
cp $(TOP)/www/arch2.gif .
|
||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
|
||||
|
||||
c_interface.html: $(TOP)/www/c_interface.tcl
|
||||
tclsh $(TOP)/www/c_interface.tcl >c_interface.html
|
||||
|
||||
capi3.html: $(TOP)/www/capi3.tcl
|
||||
tclsh $(TOP)/www/capi3.tcl >capi3.html
|
||||
|
||||
capi3ref.html: $(TOP)/www/capi3ref.tcl
|
||||
tclsh $(TOP)/www/capi3ref.tcl >capi3ref.html
|
||||
|
||||
changes.html: $(TOP)/www/changes.tcl
|
||||
tclsh $(TOP)/www/changes.tcl >changes.html
|
||||
|
||||
copyright.html: $(TOP)/www/copyright.tcl
|
||||
tclsh $(TOP)/www/copyright.tcl >copyright.html
|
||||
|
||||
copyright-release.html: $(TOP)/www/copyright-release.html
|
||||
cp $(TOP)/www/copyright-release.html .
|
||||
|
||||
copyright-release.pdf: $(TOP)/www/copyright-release.pdf
|
||||
cp $(TOP)/www/copyright-release.pdf .
|
||||
|
||||
common.tcl: $(TOP)/www/common.tcl
|
||||
cp $(TOP)/www/common.tcl .
|
||||
|
||||
conflict.html: $(TOP)/www/conflict.tcl
|
||||
tclsh $(TOP)/www/conflict.tcl >conflict.html
|
||||
|
||||
datatypes.html: $(TOP)/www/datatypes.tcl
|
||||
tclsh $(TOP)/www/datatypes.tcl >datatypes.html
|
||||
|
||||
datatype3.html: $(TOP)/www/datatype3.tcl
|
||||
tclsh $(TOP)/www/datatype3.tcl >datatype3.html
|
||||
|
||||
docs.html: $(TOP)/www/docs.tcl
|
||||
tclsh $(TOP)/www/docs.tcl >docs.html
|
||||
|
||||
download.html: $(TOP)/www/download.tcl
|
||||
mkdir doc
|
||||
tclsh $(TOP)/www/download.tcl >download.html
|
||||
|
||||
faq.html: $(TOP)/www/faq.tcl
|
||||
tclsh $(TOP)/www/faq.tcl >faq.html
|
||||
|
||||
fileformat.html: $(TOP)/www/fileformat.tcl
|
||||
tclsh $(TOP)/www/fileformat.tcl >fileformat.html
|
||||
|
||||
formatchng.html: $(TOP)/www/formatchng.tcl
|
||||
tclsh $(TOP)/www/formatchng.tcl >formatchng.html
|
||||
|
||||
index.html: $(TOP)/www/index.tcl last_change
|
||||
tclsh $(TOP)/www/index.tcl >index.html
|
||||
|
||||
lang.html: $(TOP)/www/lang.tcl
|
||||
tclsh $(TOP)/www/lang.tcl >lang.html
|
||||
|
||||
lockingv3.html: $(TOP)/www/lockingv3.tcl
|
||||
tclsh $(TOP)/www/lockingv3.tcl >lockingv3.html
|
||||
vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
tclsh $(TOP)/www/vdbe.tcl >vdbe.html
|
||||
|
||||
oldnews.html: $(TOP)/www/oldnews.tcl
|
||||
tclsh $(TOP)/www/oldnews.tcl >oldnews.html
|
||||
arch.html: $(TOP)/www/arch.tcl
|
||||
tclsh $(TOP)/www/arch.tcl >arch.html
|
||||
|
||||
omitted.html: $(TOP)/www/omitted.tcl
|
||||
tclsh $(TOP)/www/omitted.tcl >omitted.html
|
||||
arch.png: $(TOP)/www/arch.png
|
||||
cp $(TOP)/www/arch.png .
|
||||
|
||||
opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
|
||||
tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
|
||||
@@ -476,116 +401,108 @@ opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
|
||||
mingw.html: $(TOP)/www/mingw.tcl
|
||||
tclsh $(TOP)/www/mingw.tcl >mingw.html
|
||||
|
||||
nulls.html: $(TOP)/www/nulls.tcl
|
||||
tclsh $(TOP)/www/nulls.tcl >nulls.html
|
||||
|
||||
quickstart.html: $(TOP)/www/quickstart.tcl
|
||||
tclsh $(TOP)/www/quickstart.tcl >quickstart.html
|
||||
tclsqlite.html: $(TOP)/www/tclsqlite.tcl
|
||||
tclsh $(TOP)/www/tclsqlite.tcl >tclsqlite.html
|
||||
|
||||
speed.html: $(TOP)/www/speed.tcl
|
||||
tclsh $(TOP)/www/speed.tcl >speed.html
|
||||
|
||||
sqlite.gif: $(TOP)/art/SQLite.gif
|
||||
cp $(TOP)/art/SQLite.gif sqlite.gif
|
||||
faq.html: $(TOP)/www/faq.tcl
|
||||
tclsh $(TOP)/www/faq.tcl >faq.html
|
||||
|
||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
|
||||
formatchng.html: $(TOP)/www/formatchng.tcl
|
||||
tclsh $(TOP)/www/formatchng.tcl >formatchng.html
|
||||
|
||||
support.html: $(TOP)/www/support.tcl
|
||||
tclsh $(TOP)/www/support.tcl >support.html
|
||||
conflict.html: $(TOP)/www/conflict.tcl
|
||||
tclsh $(TOP)/www/conflict.tcl >conflict.html
|
||||
|
||||
tclsqlite.html: $(TOP)/www/tclsqlite.tcl
|
||||
tclsh $(TOP)/www/tclsqlite.tcl >tclsqlite.html
|
||||
download.html: $(TOP)/www/download.tcl
|
||||
tclsh $(TOP)/www/download.tcl >download.html
|
||||
|
||||
vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
tclsh $(TOP)/www/vdbe.tcl >vdbe.html
|
||||
omitted.html: $(TOP)/www/omitted.tcl
|
||||
tclsh $(TOP)/www/omitted.tcl >omitted.html
|
||||
|
||||
version3.html: $(TOP)/www/version3.tcl
|
||||
tclsh $(TOP)/www/version3.tcl >version3.html
|
||||
datatypes.html: $(TOP)/www/datatypes.tcl
|
||||
tclsh $(TOP)/www/datatypes.tcl >datatypes.html
|
||||
|
||||
quickstart.html: $(TOP)/www/quickstart.tcl
|
||||
tclsh $(TOP)/www/quickstart.tcl >quickstart.html
|
||||
|
||||
fileformat.html: $(TOP)/www/fileformat.tcl
|
||||
tclsh $(TOP)/www/fileformat.tcl >fileformat.html
|
||||
|
||||
nulls.html: $(TOP)/www/nulls.tcl
|
||||
tclsh $(TOP)/www/nulls.tcl >nulls.html
|
||||
|
||||
|
||||
# Files to be published on the website.
|
||||
#
|
||||
DOC = \
|
||||
arch.html \
|
||||
arch2.gif \
|
||||
c_interface.html \
|
||||
capi3.html \
|
||||
capi3ref.html \
|
||||
changes.html \
|
||||
copyright.html \
|
||||
copyright-release.html \
|
||||
copyright-release.pdf \
|
||||
conflict.html \
|
||||
datatypes.html \
|
||||
datatype3.html \
|
||||
docs.html \
|
||||
download.html \
|
||||
faq.html \
|
||||
fileformat.html \
|
||||
formatchng.html \
|
||||
index.html \
|
||||
lang.html \
|
||||
lockingv3.html \
|
||||
mingw.html \
|
||||
nulls.html \
|
||||
oldnews.html \
|
||||
omitted.html \
|
||||
opcode.html \
|
||||
quickstart.html \
|
||||
speed.html \
|
||||
sqlite.gif \
|
||||
sqlite.html \
|
||||
support.html \
|
||||
tclsqlite.html \
|
||||
changes.html \
|
||||
lang.html \
|
||||
opcode.html \
|
||||
arch.html \
|
||||
arch.png \
|
||||
vdbe.html \
|
||||
version3.html
|
||||
c_interface.html \
|
||||
mingw.html \
|
||||
tclsqlite.html \
|
||||
download.html \
|
||||
speed.html \
|
||||
faq.html \
|
||||
formatchng.html \
|
||||
conflict.html \
|
||||
omitted.html \
|
||||
datatypes.html \
|
||||
quickstart.html \
|
||||
fileformat.html \
|
||||
nulls.html
|
||||
|
||||
doc: common.tcl $(DOC)
|
||||
doc: $(DOC)
|
||||
mkdir -p doc
|
||||
mv $(DOC) doc
|
||||
|
||||
install: sqlite3 libsqlite3.la sqlite3.h
|
||||
install: sqlite libsqlite.la sqlite.h
|
||||
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/lib
|
||||
$(LTINSTALL) libsqlite3.la $(DESTDIR)$(exec_prefix)/lib
|
||||
$(LTINSTALL) libsqlite.la $(DESTDIR)$(exec_prefix)/lib
|
||||
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/bin
|
||||
$(LTINSTALL) sqlite3 $(DESTDIR)$(exec_prefix)/bin
|
||||
$(LTINSTALL) sqlite $(DESTDIR)$(exec_prefix)/bin
|
||||
$(INSTALL) -d $(DESTDIR)$(prefix)/include
|
||||
$(INSTALL) -m 0644 sqlite3.h $(DESTDIR)$(prefix)/include
|
||||
$(INSTALL) -m 0644 sqlite.h $(DESTDIR)$(prefix)/include
|
||||
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/lib/pkgconfig;
|
||||
$(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(exec_prefix)/lib/pkgconfig;
|
||||
$(INSTALL) -m 0644 sqlite.pc $(DESTDIR)$(exec_prefix)/lib/pkgconfig;
|
||||
|
||||
clean:
|
||||
rm -f *.lo *.la *.o sqlite3@TARGET_EXEEXT@ libsqlite3.la
|
||||
rm -f sqlite3.h opcodes.*
|
||||
rm -f *.lo *.la *.o sqlite@TARGET_EXEEXT@ libsqlite.la sqlite.h opcodes.*
|
||||
rm -rf .libs .deps
|
||||
rm -f lemon@BUILD_EXEEXT@ lempar.c parse.* sqlite*.tar.gz
|
||||
rm -f $(PUBLISH)
|
||||
rm -f *.da *.bb *.bbg gmon.out
|
||||
rm -f testfixture@TARGET_EXEEXT@ test.db
|
||||
rm -rf doc
|
||||
rm -f common.tcl
|
||||
rm -f sqlite3.dll sqlite3.lib
|
||||
rm -f sqlite.dll sqlite.lib
|
||||
|
||||
#
|
||||
# Windows section; all this funky .dll stuff ;-)
|
||||
#
|
||||
dll: sqlite3.dll
|
||||
dll: sqlite.dll
|
||||
|
||||
REAL_LIBOBJ = $(LIBOBJ:%.lo=.libs/%.o)
|
||||
|
||||
sqlite3.dll: $(LIBOBJ) $(TOP)/sqlite3.def
|
||||
dllwrap --dllname sqlite3.dll --def $(TOP)/sqlite3.def $(REAL_LIBOBJ)
|
||||
strip sqlite3.dll
|
||||
sqlite.dll: $(LIBOBJ) $(TOP)/sqlite.def
|
||||
dllwrap --dllname sqlite.dll --def $(TOP)/sqlite.def $(REAL_LIBOBJ)
|
||||
strip sqlite.dll
|
||||
|
||||
#target for dll import libraries
|
||||
implib: sqlite3.lib
|
||||
implib: sqlite.lib
|
||||
|
||||
#make Borland C++ and/or Microsoft VC import library for the dll
|
||||
# ignore any errors (usually due to missing programs)
|
||||
sqlite3.lib: sqlite3.dll
|
||||
-implib -a sqlite3.lib sqlite3.dll
|
||||
-lib /machine:i386 /def:$(TOP)/sqlite3.def
|
||||
sqlite.lib: sqlite.dll
|
||||
-implib -a sqlite.lib sqlite.dll
|
||||
-lib /machine:i386 /def:$(TOP)/sqlite.def
|
||||
|
||||
distclean: clean
|
||||
rm -f config.log config.status libtool Makefile config.h
|
||||
|
||||
+4
-4
@@ -41,16 +41,16 @@ THREADSAFE = -DTHREADSAFE=0
|
||||
#THREADLIB = -lpthread
|
||||
THREADLIB =
|
||||
|
||||
#### Leave SQLITE_DEBUG undefined for maximum speed. Use SQLITE_DEBUG=1
|
||||
# to check for memory leaks. Use SQLITE_DEBUG=2 to print a log of all
|
||||
#### Leave MEMORY_DEBUG undefined for maximum speed. Use MEMORY_DEBUG=1
|
||||
# to check for memory leaks. Use MEMORY_DEBUG=2 to print a log of all
|
||||
# malloc()s and free()s in order to track down memory leaks.
|
||||
#
|
||||
# SQLite uses some expensive assert() statements in the inner loop.
|
||||
# You can make the library go almost twice as fast if you compile
|
||||
# with -DNDEBUG=1
|
||||
#
|
||||
#OPTS = -DSQLITE_DEBUG=2
|
||||
#OPTS = -DSQLITE_DEBUG=1
|
||||
#OPTS = -DMEMORY_DEBUG=2
|
||||
#OPTS = -DMEMORY_DEBUG=1
|
||||
#OPTS =
|
||||
OPTS = -DNDEBUG=1
|
||||
|
||||
|
||||
Binary file not shown.
@@ -463,7 +463,7 @@ ac_includes_default="\
|
||||
# include <unistd.h>
|
||||
#endif"
|
||||
|
||||
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP CPP CXX CXXFLAGS ac_ct_CXX CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA program_prefix VERSION BUILD_CC BUILD_CFLAGS BUILD_LIBS TARGET_CC TARGET_CFLAGS TARGET_LINK TARGET_LFLAGS TARGET_RANLIB TARGET_AR THREADSAFE ALLOWRELEASE TEMP_STORE BUILD_EXEEXT OS_UNIX OS_WIN TARGET_EXEEXT TARGET_LIBS TARGET_TCL_LIBS TARGET_TCL_INC TARGET_READLINE_LIBS TARGET_READLINE_INC TARGET_HAVE_READLINE LIBOBJS LTLIBOBJS'
|
||||
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP CPP CXX CXXFLAGS ac_ct_CXX CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA program_prefix VERSION BUILD_CC BUILD_CFLAGS BUILD_LIBS TARGET_CC TARGET_CFLAGS TARGET_LINK TARGET_LFLAGS TARGET_RANLIB TARGET_AR ENCODING ALLOWATTACHMEM ALLOWRELEASE INMEMORYDB TEMP_STORE BUILD_EXEEXT OS_UNIX OS_WIN TARGET_EXEEXT TARGET_LIBS TARGET_TCL_LIBS TARGET_TCL_INC TARGET_READLINE_LIBS TARGET_READLINE_INC TARGET_HAVE_READLINE LIBOBJS LTLIBOBJS'
|
||||
ac_subst_files=''
|
||||
|
||||
# Initialize some variables set by options.
|
||||
@@ -1025,9 +1025,10 @@ Optional Features:
|
||||
--enable-fast-install[=PKGS]
|
||||
optimize for fast installation [default=yes]
|
||||
--disable-libtool-lock avoid locking (might break parallel builds)
|
||||
--enable-threadsafe Support threadsafe operation
|
||||
--enable-utf8 Use UTF-8 encodings
|
||||
--enable-incore-db Support incore database
|
||||
--enable-releasemode Support libtool link to release mode
|
||||
--enable-tempstore Use an in-ram database for temporary tables (never,no,yes,always)
|
||||
--enable-tempdb-in-ram Use an in-ram database for temporary tables
|
||||
|
||||
Optional Packages:
|
||||
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
|
||||
@@ -1144,7 +1145,7 @@ esac
|
||||
else
|
||||
echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
|
||||
fi
|
||||
cd $ac_popdir
|
||||
cd "$ac_popdir"
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -1493,7 +1494,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
|
||||
# The following RCS revision string applies to configure.in
|
||||
# $Revision: 1.24 $
|
||||
# $Revision: 1.21 $
|
||||
|
||||
#########
|
||||
# Programs needed
|
||||
@@ -2217,8 +2218,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -2276,8 +2276,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -2393,8 +2392,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -2448,8 +2446,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -2494,8 +2491,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -2539,8 +2535,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -3052,7 +3047,7 @@ ia64-*-hpux*)
|
||||
;;
|
||||
*-*-irix6*)
|
||||
# Find out which ABI we are using.
|
||||
echo '#line 3055 "configure"' > conftest.$ac_ext
|
||||
echo '#line 3050 "configure"' > conftest.$ac_ext
|
||||
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
(eval $ac_compile) 2>&5
|
||||
ac_status=$?
|
||||
@@ -3172,8 +3167,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -3482,8 +3476,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -3653,8 +3646,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -3721,8 +3713,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -3982,8 +3973,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -4041,8 +4031,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -4113,8 +4102,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -4158,8 +4146,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -4515,7 +4502,7 @@ fi
|
||||
|
||||
|
||||
# Provide some information about the compiler.
|
||||
echo "$as_me:4518:" \
|
||||
echo "$as_me:4505:" \
|
||||
"checking for Fortran 77 compiler version" >&5
|
||||
ac_compiler=`set X $ac_compile; echo $2`
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
|
||||
@@ -4561,8 +4548,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_f77_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_f77_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -4611,8 +4597,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_f77_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_f77_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -5549,11 +5534,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:5552: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:5537: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:5556: \$? = $ac_status" >&5
|
||||
echo "$as_me:5541: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -5782,11 +5767,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:5785: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:5770: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:5789: \$? = $ac_status" >&5
|
||||
echo "$as_me:5774: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -5842,11 +5827,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:5845: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:5830: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:5849: \$? = $ac_status" >&5
|
||||
echo "$as_me:5834: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@@ -6233,8 +6218,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -6294,8 +6278,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -7486,8 +7469,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -7590,8 +7572,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -7656,8 +7637,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -7750,8 +7730,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -7816,8 +7795,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -7883,8 +7861,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -7950,8 +7927,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -8026,7 +8002,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 8029 "configure"
|
||||
#line 8005 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -8124,7 +8100,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 8127 "configure"
|
||||
#line 8103 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -9196,8 +9172,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -9258,8 +9233,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -10303,11 +10277,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:10306: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:10280: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:10310: \$? = $ac_status" >&5
|
||||
echo "$as_me:10284: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -10363,11 +10337,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:10366: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:10340: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:10370: \$? = $ac_status" >&5
|
||||
echo "$as_me:10344: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@@ -11184,8 +11158,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -11288,8 +11261,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -11354,8 +11326,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -11448,8 +11419,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -11514,8 +11484,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -11581,8 +11550,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -11648,8 +11616,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -11724,7 +11691,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 11727 "configure"
|
||||
#line 11694 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -11822,7 +11789,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 11825 "configure"
|
||||
#line 11792 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -12649,11 +12616,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:12652: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:12619: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:12656: \$? = $ac_status" >&5
|
||||
echo "$as_me:12623: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -12709,11 +12676,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:12712: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:12679: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:12716: \$? = $ac_status" >&5
|
||||
echo "$as_me:12683: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@@ -13090,8 +13057,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_f77_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_f77_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -13141,8 +13107,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_f77_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_f77_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -14743,11 +14708,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:14746: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:14711: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:14750: \$? = $ac_status" >&5
|
||||
echo "$as_me:14715: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -14976,11 +14941,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:14979: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:14944: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:14983: \$? = $ac_status" >&5
|
||||
echo "$as_me:14948: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -15036,11 +15001,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:15039: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:15004: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:15043: \$? = $ac_status" >&5
|
||||
echo "$as_me:15008: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@@ -15427,8 +15392,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -15488,8 +15452,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -16680,8 +16643,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -16784,8 +16746,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -16850,8 +16811,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -16944,8 +16904,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -17010,8 +16969,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -17077,8 +17035,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -17144,8 +17101,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -17220,7 +17176,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 17223 "configure"
|
||||
#line 17179 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -17318,7 +17274,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 17321 "configure"
|
||||
#line 17277 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -18838,8 +18794,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -18897,8 +18852,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -19014,8 +18968,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -19069,8 +19022,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -19115,8 +19067,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -19160,8 +19111,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -19385,23 +19335,46 @@ echo "${ECHO_T}no" >&6
|
||||
fi
|
||||
|
||||
##########
|
||||
# Do we want to support multithreaded use of sqlite
|
||||
# Are we using UTF-8 or iso8859 encodings?
|
||||
#
|
||||
# Check whether --enable-threadsafe or --disable-threadsafe was given.
|
||||
if test "${enable_threadsafe+set}" = set; then
|
||||
enableval="$enable_threadsafe"
|
||||
# Check whether --enable-utf8 or --disable-utf8 was given.
|
||||
if test "${enable_utf8+set}" = set; then
|
||||
enableval="$enable_utf8"
|
||||
|
||||
else
|
||||
enable_threadsafe=no
|
||||
enable_utf8=no
|
||||
fi;
|
||||
echo "$as_me:$LINENO: checking whether to support threadsafe operation" >&5
|
||||
echo $ECHO_N "checking whether to support threadsafe operation... $ECHO_C" >&6
|
||||
if test "$enable_threadsafe" = "no"; then
|
||||
THREADSAFE=0
|
||||
echo "$as_me:$LINENO: checking character encoding" >&5
|
||||
echo $ECHO_N "checking character encoding... $ECHO_C" >&6
|
||||
if test "$enable_utf8" = "no"; then
|
||||
ENCODING=ISO8859
|
||||
echo "$as_me:$LINENO: result: iso8859" >&5
|
||||
echo "${ECHO_T}iso8859" >&6
|
||||
else
|
||||
ENCODING=UTF8
|
||||
echo "$as_me:$LINENO: result: UTF-8" >&5
|
||||
echo "${ECHO_T}UTF-8" >&6
|
||||
fi
|
||||
|
||||
|
||||
##########
|
||||
# Do we want to support in-ram databases for ATTACH DATABASE and sqlite_open
|
||||
#
|
||||
# Check whether --enable-incore-db or --disable-incore-db was given.
|
||||
if test "${enable_incore_db+set}" = set; then
|
||||
enableval="$enable_incore_db"
|
||||
|
||||
else
|
||||
enable_incore_db=yes
|
||||
fi;
|
||||
echo "$as_me:$LINENO: checking whether to support incore databases for attach and open" >&5
|
||||
echo $ECHO_N "checking whether to support incore databases for attach and open... $ECHO_C" >&6
|
||||
if test "$enable_incore_db" = "no"; then
|
||||
INMEMORYDB=0
|
||||
echo "$as_me:$LINENO: result: no" >&5
|
||||
echo "${ECHO_T}no" >&6
|
||||
else
|
||||
THREADSAFE=1
|
||||
INMEMORYDB=1
|
||||
echo "$as_me:$LINENO: result: yes" >&5
|
||||
echo "${ECHO_T}yes" >&6
|
||||
fi
|
||||
@@ -19433,32 +19406,35 @@ fi
|
||||
##########
|
||||
# Do we want temporary databases in memory
|
||||
#
|
||||
# Check whether --enable-tempstore or --disable-tempstore was given.
|
||||
if test "${enable_tempstore+set}" = set; then
|
||||
enableval="$enable_tempstore"
|
||||
# Check whether --enable-tempdb-in-ram or --disable-tempdb-in-ram was given.
|
||||
if test "${enable_tempdb_in_ram+set}" = set; then
|
||||
enableval="$enable_tempdb_in_ram"
|
||||
|
||||
else
|
||||
enable_tempstore=yes
|
||||
enable_tempdb_in_ram=no
|
||||
fi;
|
||||
echo "$as_me:$LINENO: checking whether to use an in-ram database for temporary tables" >&5
|
||||
echo $ECHO_N "checking whether to use an in-ram database for temporary tables... $ECHO_C" >&6
|
||||
case "$enable_tempstore" in
|
||||
case "$enable_tempdb_in_ram" in
|
||||
never )
|
||||
TEMP_STORE=0
|
||||
echo "$as_me:$LINENO: result: never" >&5
|
||||
echo "${ECHO_T}never" >&6
|
||||
;;
|
||||
no )
|
||||
INMEMORYDB=1
|
||||
TEMP_STORE=1
|
||||
echo "$as_me:$LINENO: result: no" >&5
|
||||
echo "${ECHO_T}no" >&6
|
||||
;;
|
||||
always )
|
||||
TEMP_STORE=3
|
||||
INMEMORYDB=1
|
||||
TEMP_STORE=3
|
||||
echo "$as_me:$LINENO: result: always" >&5
|
||||
echo "${ECHO_T}always" >&6
|
||||
;;
|
||||
* )
|
||||
INMEMORYDB=1
|
||||
TEMP_STORE=2
|
||||
echo "$as_me:$LINENO: result: yes" >&5
|
||||
echo "${ECHO_T}yes" >&6
|
||||
@@ -19467,6 +19443,7 @@ esac
|
||||
|
||||
|
||||
|
||||
|
||||
###########
|
||||
# Lots of things are different if we are compiling for Windows using
|
||||
# the CYGWIN environment. So check for that special case and handle
|
||||
@@ -19504,13 +19481,12 @@ if test "$TARGET_EXEEXT" = ".exe"; then
|
||||
OS_UNIX=0
|
||||
OS_WIN=1
|
||||
tclsubdir=win
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DOS_WIN=1"
|
||||
else
|
||||
OS_UNIX=1
|
||||
OS_WIN=0
|
||||
tclsubdir=unix
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DOS_UNIX=1"
|
||||
fi
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DOS_UNIX=$OS_UNIX -DOS_WIN=$OS_WIN"
|
||||
|
||||
|
||||
|
||||
@@ -19602,8 +19578,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -19672,8 +19647,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -19750,8 +19724,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -19805,8 +19778,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -19897,8 +19869,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -20092,8 +20063,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -20147,8 +20117,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -20219,8 +20188,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -20304,8 +20272,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -20553,8 +20520,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
@@ -20586,7 +20552,7 @@ fi
|
||||
#########
|
||||
# Generate the output files.
|
||||
#
|
||||
ac_config_files="$ac_config_files Makefile sqlite3.pc"
|
||||
ac_config_files="$ac_config_files Makefile sqlite.pc"
|
||||
cat >confcache <<\_ACEOF
|
||||
# This file is a shell script that caches the results of configure
|
||||
# tests run on this system so they can be shared between configure
|
||||
@@ -21139,7 +21105,7 @@ do
|
||||
case "$ac_config_target" in
|
||||
# Handling of arguments.
|
||||
"Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
|
||||
"sqlite3.pc" ) CONFIG_FILES="$CONFIG_FILES sqlite3.pc" ;;
|
||||
"sqlite.pc" ) CONFIG_FILES="$CONFIG_FILES sqlite.pc" ;;
|
||||
*) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
|
||||
echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
|
||||
{ (exit 1); exit 1; }; };;
|
||||
@@ -21270,8 +21236,10 @@ s,@TARGET_LINK@,$TARGET_LINK,;t t
|
||||
s,@TARGET_LFLAGS@,$TARGET_LFLAGS,;t t
|
||||
s,@TARGET_RANLIB@,$TARGET_RANLIB,;t t
|
||||
s,@TARGET_AR@,$TARGET_AR,;t t
|
||||
s,@THREADSAFE@,$THREADSAFE,;t t
|
||||
s,@ENCODING@,$ENCODING,;t t
|
||||
s,@ALLOWATTACHMEM@,$ALLOWATTACHMEM,;t t
|
||||
s,@ALLOWRELEASE@,$ALLOWRELEASE,;t t
|
||||
s,@INMEMORYDB@,$INMEMORYDB,;t t
|
||||
s,@TEMP_STORE@,$TEMP_STORE,;t t
|
||||
s,@BUILD_EXEEXT@,$BUILD_EXEEXT,;t t
|
||||
s,@OS_UNIX@,$OS_UNIX,;t t
|
||||
@@ -21451,11 +21419,6 @@ esac
|
||||
*) ac_INSTALL=$ac_top_builddir$INSTALL ;;
|
||||
esac
|
||||
|
||||
if test x"$ac_file" != x-; then
|
||||
{ echo "$as_me:$LINENO: creating $ac_file" >&5
|
||||
echo "$as_me: creating $ac_file" >&6;}
|
||||
rm -f "$ac_file"
|
||||
fi
|
||||
# Let's still pretend it is `configure' which instantiates (i.e., don't
|
||||
# use $as_me), people would be surprised to read:
|
||||
# /* config.h. Generated by config.status. */
|
||||
@@ -21494,6 +21457,12 @@ echo "$as_me: error: cannot find input file: $f" >&2;}
|
||||
fi;;
|
||||
esac
|
||||
done` || { (exit 1); exit 1; }
|
||||
|
||||
if test x"$ac_file" != x-; then
|
||||
{ echo "$as_me:$LINENO: creating $ac_file" >&5
|
||||
echo "$as_me: creating $ac_file" >&6;}
|
||||
rm -f "$ac_file"
|
||||
fi
|
||||
_ACEOF
|
||||
cat >>$CONFIG_STATUS <<_ACEOF
|
||||
sed "$ac_vpsub
|
||||
|
||||
+34
-16
@@ -138,7 +138,7 @@ AC_INIT(src/sqlite.h.in)
|
||||
dnl Put the RCS revision string after AC_INIT so that it will also
|
||||
dnl show in in configure.
|
||||
# The following RCS revision string applies to configure.in
|
||||
# $Revision: 1.10 $
|
||||
# $Revision: 1.7 $
|
||||
|
||||
#########
|
||||
# Programs needed
|
||||
@@ -291,19 +291,34 @@ else
|
||||
fi
|
||||
|
||||
##########
|
||||
# Do we want to support multithreaded use of sqlite
|
||||
# Are we using UTF-8 or iso8859 encodings?
|
||||
#
|
||||
AC_ARG_ENABLE(threadsafe,
|
||||
[ --enable-threadsafe Support threadsafe operation],,enable_threadsafe=no)
|
||||
AC_MSG_CHECKING([whether to support threadsafe operation])
|
||||
if test "$enable_threadsafe" = "no"; then
|
||||
THREADSAFE=0
|
||||
AC_ARG_ENABLE(utf8,
|
||||
[ --enable-utf8 Use UTF-8 encodings],,enable_utf8=no)
|
||||
AC_MSG_CHECKING([character encoding])
|
||||
if test "$enable_utf8" = "no"; then
|
||||
ENCODING=ISO8859
|
||||
AC_MSG_RESULT([iso8859])
|
||||
else
|
||||
ENCODING=UTF8
|
||||
AC_MSG_RESULT([UTF-8])
|
||||
fi
|
||||
AC_SUBST(ENCODING)
|
||||
|
||||
##########
|
||||
# Do we want to support in-ram databases for ATTACH DATABASE and sqlite_open
|
||||
#
|
||||
AC_ARG_ENABLE(incore-db,
|
||||
[ --enable-incore-db Support incore database],,enable_incore_db=yes)
|
||||
AC_MSG_CHECKING([whether to support incore databases for attach and open])
|
||||
if test "$enable_incore_db" = "no"; then
|
||||
INMEMORYDB=0
|
||||
AC_MSG_RESULT([no])
|
||||
else
|
||||
THREADSAFE=1
|
||||
INMEMORYDB=1
|
||||
AC_MSG_RESULT([yes])
|
||||
fi
|
||||
AC_SUBST(THREADSAFE)
|
||||
AC_SUBST(ALLOWATTACHMEM)
|
||||
|
||||
##########
|
||||
# Do we want to support release
|
||||
@@ -323,28 +338,32 @@ AC_SUBST(ALLOWRELEASE)
|
||||
##########
|
||||
# Do we want temporary databases in memory
|
||||
#
|
||||
AC_ARG_ENABLE(tempstore,
|
||||
[ --enable-tempstore Use an in-ram database for temporary tables (never,no,yes,always)],,enable_tempstore=yes)
|
||||
AC_ARG_ENABLE(tempdb-in-ram,
|
||||
[ --enable-tempdb-in-ram Use an in-ram database for temporary tables],,enable_tempdb_in_ram=no)
|
||||
AC_MSG_CHECKING([whether to use an in-ram database for temporary tables])
|
||||
case "$enable_tempstore" in
|
||||
case "$enable_tempdb_in_ram" in
|
||||
never )
|
||||
TEMP_STORE=0
|
||||
AC_MSG_RESULT([never])
|
||||
;;
|
||||
no )
|
||||
INMEMORYDB=1
|
||||
TEMP_STORE=1
|
||||
AC_MSG_RESULT([no])
|
||||
;;
|
||||
always )
|
||||
TEMP_STORE=3
|
||||
INMEMORYDB=1
|
||||
TEMP_STORE=3
|
||||
AC_MSG_RESULT([always])
|
||||
;;
|
||||
* )
|
||||
INMEMORYDB=1
|
||||
TEMP_STORE=2
|
||||
AC_MSG_RESULT([yes])
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_SUBST(INMEMORYDB)
|
||||
AC_SUBST(TEMP_STORE)
|
||||
|
||||
###########
|
||||
@@ -376,13 +395,12 @@ if test "$TARGET_EXEEXT" = ".exe"; then
|
||||
OS_UNIX=0
|
||||
OS_WIN=1
|
||||
tclsubdir=win
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DOS_WIN=1"
|
||||
else
|
||||
OS_UNIX=1
|
||||
OS_WIN=0
|
||||
tclsubdir=unix
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DOS_UNIX=1"
|
||||
fi
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DOS_UNIX=$OS_UNIX -DOS_WIN=$OS_WIN"
|
||||
|
||||
AC_SUBST(BUILD_EXEEXT)
|
||||
AC_SUBST(OS_UNIX)
|
||||
@@ -526,5 +544,5 @@ AC_CHECK_FUNC(usleep, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_USLEEP=1"])
|
||||
#
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
sqlite3.pc
|
||||
sqlite.pc
|
||||
])
|
||||
|
||||
@@ -1,264 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
|
||||
<TITLE></TITLE>
|
||||
<META NAME="GENERATOR" CONTENT="OpenOffice.org 1.0.2 (Linux)">
|
||||
<META NAME="CREATED" CONTENT="20040515;10253700">
|
||||
<META NAME="CHANGED" CONTENT="20040517;11521700">
|
||||
<STYLE>
|
||||
<!--
|
||||
@page { size: 21.59cm 27.94cm; margin-left: 3.18cm; margin-right: 3.18cm; margin-top: 2.54cm; margin-bottom: 2.54cm }
|
||||
H1 { margin-bottom: 0.21cm }
|
||||
H1.western { font-family: "Luxi Sans", sans-serif; font-size: 16pt }
|
||||
H1.cjk { font-size: 16pt }
|
||||
H1.ctl { font-size: 16pt }
|
||||
P { margin-bottom: 0.21cm }
|
||||
H2 { margin-bottom: 0.21cm }
|
||||
H2.western { font-family: "Luxi Sans", sans-serif; font-size: 14pt; font-style: normal }
|
||||
H2.cjk { font-size: 14pt; font-style: italic }
|
||||
H2.ctl { font-size: 14pt; font-style: italic }
|
||||
-->
|
||||
</STYLE>
|
||||
</HEAD>
|
||||
<BODY LANG="en-US">
|
||||
<H1 CLASS="western" ALIGN=CENTER>SQLite v3 Value Storage and
|
||||
Collation</H1>
|
||||
<P>This document is a collection of notes describing the proposed
|
||||
SQLite v3 type affinity and collation sequence features.</P>
|
||||
<H2 CLASS="western">1. Storage Classes</H2>
|
||||
<P>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.</P>
|
||||
<P>Each value stored in an SQLite database (or manipulated by the
|
||||
database engine) has one of the following storage classes:</P>
|
||||
<UL>
|
||||
<LI><P><B>NULL</B>. The value is a NULL value.</P>
|
||||
<LI><P><B>INTEGER</B>. The value is a signed integer, stored in 1,
|
||||
2, 4 or 8 bytes depending on the magnitude of the value.</P>
|
||||
<LI><P><B>REAL</B>. The value is a floating point value, stored as
|
||||
an 8-byte IEEE floating point number.</P>
|
||||
<LI><P><B>TEXT</B>. The value is a text string, stored using the
|
||||
database encoding (UTF-8, UTF-16BE or UTF-16-LE).</P>
|
||||
<LI><P><B>BLOB</B>. The value is a blob of data, stored exactly as
|
||||
it was input.</P>
|
||||
</UL>
|
||||
<P>As in SQLite v2, normally any SQLite v3 column 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'.</P>
|
||||
<P>All values supplied to SQLite, whether as literals embedded in SQL
|
||||
statements, values bound to pre-compiled SQL statements or data read
|
||||
using the COPY command 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.
|
||||
</P>
|
||||
<P>Storage classes are initially assigned as follows:</P>
|
||||
<UL>
|
||||
<LI><P>Values read using the COPY command are assigned the storage
|
||||
class TEXT or NULL.</P>
|
||||
<LI><P>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.</P>
|
||||
<LI><P>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).</P>
|
||||
</UL>
|
||||
<P>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.</P>
|
||||
<H2 CLASS="western">2. Column Affinity</H2>
|
||||
<P>Each column in an SQLite 3 database is assigned one of the
|
||||
following type affinities:</P>
|
||||
<UL>
|
||||
<LI><P>TEXT.</P>
|
||||
<LI><P>NUMERIC.</P>
|
||||
<LI><P>INTEGER.</P>
|
||||
<LI><P>NONE.</P>
|
||||
</UL>
|
||||
<P>The affinity of a column determines the storage class used by
|
||||
values inserted into the column.</P>
|
||||
<P>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.</P>
|
||||
<P>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.</P>
|
||||
<P>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.</P>
|
||||
<P>A column with affinity NONE makes no attempt to coerce data before
|
||||
it is inserted.</P>
|
||||
<H3>2.1 Determination Of Column Affinity</H3>
|
||||
<P>The type affinity of a column is determined by the declared type
|
||||
of the column, according to the following rules:</P>
|
||||
<OL>
|
||||
<LI><P>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.</P>
|
||||
<LI><P>If the datatype contains the string "INT" then it
|
||||
is assigned INTEGER affinity.</P>
|
||||
<LI><P>If the datatype contains the string "BLOB" is is
|
||||
given an affinity of NONE.</P>
|
||||
<LI><P>Any column that does not matches the rules above, including
|
||||
columns that have no datatype specified, are given NUMERIC affinity.</P>
|
||||
</OL>
|
||||
<P>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.</P>
|
||||
<H3>2.2 Column Affinity Example</H3>
|
||||
<PRE>CREATE TABLE t1(
|
||||
t AFFINITY TEXT,
|
||||
nu AFFINITY NUMERIC,
|
||||
i AFFINITY INTEGER,
|
||||
no AFFINITY NONE
|
||||
);
|
||||
|
||||
-- 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);</PRE><H2 CLASS="western">
|
||||
3. Comparison Expressions</H2>
|
||||
<P>Like SQLite v2, v3 features the binary comparison operators '=',
|
||||
'<', '<=', '>=' and '!=', an operation to test for set
|
||||
membership, 'IN', and the ternary comparison operator 'BETWEEN'.</P>
|
||||
<P>The results of a comparison depend on the storage classes of the
|
||||
two values being compared, according to the following rules:</P>
|
||||
<UL>
|
||||
<LI><P>A value with storage class NULL is considered less than any
|
||||
other value (including another value with storage class NULL).</P>
|
||||
<LI><P>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.</P>
|
||||
<LI><P>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 overriden, as described
|
||||
under 'User-defined collation Sequences' below.</P>
|
||||
<LI><P>When two BLOB values are compared, the result is always
|
||||
determined using memcmp().</P>
|
||||
</UL>
|
||||
<P>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.</P>
|
||||
<UL>
|
||||
<LI><P>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.</P>
|
||||
<LI><P>When two column values are compared, if one column has
|
||||
INTEGER or NUMERIC affinity and the other does not, the NUMERIC
|
||||
affinity is applied to any values with storage class TEXT extracted
|
||||
from the non-NUMERIC column.</P>
|
||||
<LI><P>When the results of two expressions are compared, the NUMERIC
|
||||
affinity is applied to both values before the comparison takes
|
||||
place.</P>
|
||||
</UL>
|
||||
<H3>3.1 Comparison Example</H3>
|
||||
<PRE>CREATE TABLE t1(
|
||||
a AFFINITY TEXT,
|
||||
b AFFINITY NUMERIC,
|
||||
c AFFINITY NONE
|
||||
);
|
||||
|
||||
-- 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</PRE><P>
|
||||
In SQLite, the expression “a BETWEEN b AND c” is currently
|
||||
equivalent to “a >= b AND a <= c”. SQLite will continue to
|
||||
treat the two as exactly equivalent, even if this means that
|
||||
different affinities are applied to 'a' in each of the comparisons
|
||||
required to evaluate the expression.</P>
|
||||
<P>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.</P>
|
||||
<P>SQLite currently treats the expression “a IN (x, y, z)” as
|
||||
equivalent to “a = z OR a = y OR a = z”. SQLite will continue to
|
||||
treat the two as exactly equivalent, even if this means that
|
||||
different affinities are applied to 'a' in each of the comparisons
|
||||
required to evaluate the expression.</P>
|
||||
<H2 CLASS="western">4. Operators</H2>
|
||||
<P>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.</P>
|
||||
<P>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.</P>
|
||||
<H2 CLASS="western">5. Sorting, Grouping and Compound SELECTs</H2>
|
||||
<P>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.</P>
|
||||
<P>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.</P>
|
||||
<P STYLE="font-style: normal">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.</P>
|
||||
<H2 CLASS="western">6. Other Affinity Modes</H2>
|
||||
<P>The above sections describe the operation of the database engine
|
||||
in 'normal' affinity mode. SQLite v3 will feature two other affinity
|
||||
modes, as follows:</P>
|
||||
<UL>
|
||||
<LI><P><B>Strict affinity</B> 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.</P>
|
||||
<LI><P><B>No affinity</B> 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.</P>
|
||||
</UL>
|
||||
<H2 CLASS="western">7. User-defined Collation Sequences</H2>
|
||||
<P STYLE="font-style: normal">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().</P>
|
||||
<P STYLE="font-style: normal"><BR><BR>
|
||||
</P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -54,14 +54,11 @@ TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
|
||||
|
||||
# Object files for the SQLite library.
|
||||
#
|
||||
LIBOBJ+= attach.o auth.o btree.o build.o date.o delete.o \
|
||||
LIBOBJ = attach.o auth.o btree.o btree_rb.o build.o copy.o date.o delete.o \
|
||||
expr.o func.o hash.o insert.o \
|
||||
main.o opcodes.o os_mac.o os_unix.o os_win.o \
|
||||
pager.o parse.o pragma.o printf.o random.o \
|
||||
select.o table.o tclsqlite.o tokenize.o trigger.o \
|
||||
update.o util.o vacuum.o \
|
||||
vdbe.o vdbeapi.o vdbeaux.o vdbemem.o \
|
||||
where.o utf.o legacy.o
|
||||
main.o opcodes.o os.o pager.o parse.o pragma.o printf.o random.o \
|
||||
select.o table.o tokenize.o trigger.o update.o util.o \
|
||||
vacuum.o vdbe.o vdbeaux.o where.o tclsqlite.o
|
||||
|
||||
# All of the source code files.
|
||||
#
|
||||
@@ -70,7 +67,9 @@ SRC = \
|
||||
$(TOP)/src/auth.c \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/btree.h \
|
||||
$(TOP)/src/btree_rb.c \
|
||||
$(TOP)/src/build.c \
|
||||
$(TOP)/src/copy.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/delete.c \
|
||||
$(TOP)/src/encode.c \
|
||||
@@ -79,11 +78,8 @@ SRC = \
|
||||
$(TOP)/src/hash.c \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os_mac.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pager.h \
|
||||
$(TOP)/src/parse.y \
|
||||
@@ -98,15 +94,12 @@ SRC = \
|
||||
$(TOP)/src/tclsqlite.c \
|
||||
$(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/trigger.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/update.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vacuum.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/vdbeapi.c \
|
||||
$(TOP)/src/vdbeaux.c \
|
||||
$(TOP)/src/vdbemem.c \
|
||||
$(TOP)/src/vdbeInt.h \
|
||||
$(TOP)/src/where.c
|
||||
|
||||
@@ -115,34 +108,24 @@ SRC = \
|
||||
TESTSRC = \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/os_mac.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/test5.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/md5.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
sqlite3.h \
|
||||
sqlite.h \
|
||||
$(TOP)/src/btree.h \
|
||||
config.h \
|
||||
$(TOP)/src/hash.h \
|
||||
opcodes.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/os_common.h \
|
||||
$(TOP)/src/os_mac.h \
|
||||
$(TOP)/src/os_unix.h \
|
||||
$(TOP)/src/os_win.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
parse.h
|
||||
@@ -156,7 +139,7 @@ VDBEHDR = \
|
||||
# This is the default Makefile target. The objects listed here
|
||||
# are what get build when you type just "make" with no arguments.
|
||||
#
|
||||
all: sqlite3.h config.h libsqlite3.a sqlite3$(EXE)
|
||||
all: sqlite.h config.h libsqlite.a sqlite$(EXE)
|
||||
|
||||
# Generate the file "last_change" which contains the date of change
|
||||
# of the most recently modified source code file
|
||||
@@ -165,15 +148,13 @@ last_change: $(SRC)
|
||||
cat $(SRC) | grep '$$Id: ' | sort +4 | tail -1 \
|
||||
| awk '{print $$5,$$6}' >last_change
|
||||
|
||||
libsqlite3.a: $(LIBOBJ)
|
||||
$(AR) libsqlite3.a $(LIBOBJ)
|
||||
$(RANLIB) libsqlite3.a
|
||||
libsqlite.a: $(LIBOBJ)
|
||||
$(AR) libsqlite.a $(LIBOBJ)
|
||||
$(RANLIB) libsqlite.a
|
||||
|
||||
sqlite3$(EXE): $(TOP)/src/shell.c libsqlite3.a sqlite3.h
|
||||
$(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE) $(TOP)/src/shell.c \
|
||||
libsqlite3.a $(LIBREADLINE) $(THREADLIB)
|
||||
|
||||
objects: $(LIBOBJ_ORIG)
|
||||
sqlite$(EXE): $(TOP)/src/shell.c libsqlite.a sqlite.h
|
||||
$(TCCX) $(READLINE_FLAGS) -o sqlite$(EXE) $(TOP)/src/shell.c \
|
||||
libsqlite.a $(LIBREADLINE) $(THREADLIB)
|
||||
|
||||
# This target creates a directory named "tsrc" and fills it with
|
||||
# copies of all of the C source code and header files needed to
|
||||
@@ -187,7 +168,6 @@ target_source: $(SRC) $(VDBEHDR) opcodes.c
|
||||
cp $(SRC) $(VDBEHDR) tsrc
|
||||
rm tsrc/sqlite.h.in tsrc/parse.y
|
||||
cp parse.c opcodes.c tsrc
|
||||
cp $(TOP)/sqlite3.def tsrc
|
||||
|
||||
# Rules to build the LEMON compiler generator
|
||||
#
|
||||
@@ -195,20 +175,49 @@ lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
$(BCC) -o lemon $(TOP)/tool/lemon.c
|
||||
cp $(TOP)/tool/lempar.c .
|
||||
|
||||
# Rules to build individual files
|
||||
#
|
||||
attach.o: $(TOP)/src/attach.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/attach.c
|
||||
|
||||
auth.o: $(TOP)/src/auth.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/auth.c
|
||||
|
||||
btree.o: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
|
||||
$(TCCX) -c $(TOP)/src/btree.c
|
||||
|
||||
btree_rb.o: $(TOP)/src/btree_rb.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/btree_rb.c
|
||||
|
||||
build.o: $(TOP)/src/build.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/build.c
|
||||
|
||||
main.o: $(TOP)/src/main.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/main.c
|
||||
|
||||
pager.o: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
$(TCCX) -c $(TOP)/src/pager.c
|
||||
|
||||
opcodes.o: opcodes.c
|
||||
$(TCCX) -c opcodes.c
|
||||
|
||||
opcodes.c: $(TOP)/src/vdbe.c
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.c
|
||||
echo 'char *sqliteOpcodeNames[] = { "???", ' >>opcodes.c
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/^.*OP_/ "/' -e 's/:.*$$/", /' >>opcodes.c
|
||||
echo '};' >>opcodes.c
|
||||
|
||||
opcodes.h: $(TOP)/src/vdbe.h
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.h
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/://' | \
|
||||
awk '{printf "#define %-30s %3d\n", $$2, ++cnt}' >>opcodes.h
|
||||
|
||||
os.o: $(TOP)/src/os.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/os.c
|
||||
|
||||
parse.o: parse.c $(HDR)
|
||||
$(TCCX) -c parse.c
|
||||
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon parse.y
|
||||
|
||||
# The config.h file will contain a single #define that tells us how
|
||||
# many bytes are in a pointer. This only works if a pointer is the
|
||||
# same size on the host as it is on the target. If you are cross-compiling
|
||||
@@ -225,6 +234,35 @@ config.h:
|
||||
echo >>config.h
|
||||
rm -f temp.c temp
|
||||
|
||||
sqlite.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||
-e s/--ENCODING--/$(ENCODING)/ \
|
||||
$(TOP)/src/sqlite.h.in >sqlite.h
|
||||
|
||||
tokenize.o: $(TOP)/src/tokenize.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/tokenize.c
|
||||
|
||||
trigger.o: $(TOP)/src/trigger.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/trigger.c
|
||||
|
||||
util.o: $(TOP)/src/util.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/util.c
|
||||
|
||||
vacuum.o: $(TOP)/src/vacuum.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/vacuum.c
|
||||
|
||||
vdbe.o: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbe.c
|
||||
|
||||
vdbeaux.o: $(TOP)/src/vdbeaux.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbeaux.c
|
||||
|
||||
where.o: $(TOP)/src/where.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/where.c
|
||||
|
||||
copy.o: $(TOP)/src/copy.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/copy.c
|
||||
|
||||
date.o: $(TOP)/src/date.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/date.c
|
||||
|
||||
@@ -246,48 +284,20 @@ hash.o: $(TOP)/src/hash.c $(HDR)
|
||||
insert.o: $(TOP)/src/insert.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/insert.c
|
||||
|
||||
legacy.o: $(TOP)/src/legacy.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/legacy.c
|
||||
random.o: $(TOP)/src/random.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/random.c
|
||||
|
||||
main.o: $(TOP)/src/main.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/main.c
|
||||
select.o: $(TOP)/src/select.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/select.c
|
||||
|
||||
pager.o: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
$(TCCX) -c $(TOP)/src/pager.c
|
||||
table.o: $(TOP)/src/table.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/table.c
|
||||
|
||||
opcodes.o: opcodes.c
|
||||
$(TCCX) -c opcodes.c
|
||||
update.o: $(TOP)/src/update.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/update.c
|
||||
|
||||
opcodes.c: $(TOP)/src/vdbe.c
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.c
|
||||
echo 'char *sqlite3OpcodeNames[] = { "???", ' >>opcodes.c
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/^.*OP_/ "/' -e 's/:.*$$/", /' >>opcodes.c
|
||||
echo '};' >>opcodes.c
|
||||
|
||||
opcodes.h: $(TOP)/src/vdbe.h
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.h
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/://' | \
|
||||
awk '{printf "#define %-30s %3d\n", $$2, ++cnt}' >>opcodes.h
|
||||
|
||||
os_mac.o: $(TOP)/src/os_mac.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/os_mac.c
|
||||
|
||||
os_unix.o: $(TOP)/src/os_unix.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/os_unix.c
|
||||
|
||||
os_win.o: $(TOP)/src/os_win.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/os_win.c
|
||||
|
||||
parse.o: parse.c $(HDR)
|
||||
$(TCCX) -c parse.c
|
||||
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon parse.y
|
||||
tclsqlite.o: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
pragma.o: $(TOP)/src/pragma.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
|
||||
@@ -295,248 +305,127 @@ pragma.o: $(TOP)/src/pragma.c $(HDR)
|
||||
printf.o: $(TOP)/src/printf.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
|
||||
random.o: $(TOP)/src/random.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/random.c
|
||||
attach.o: $(TOP)/src/attach.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/attach.c
|
||||
|
||||
select.o: $(TOP)/src/select.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/select.c
|
||||
auth.o: $(TOP)/src/auth.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/auth.c
|
||||
|
||||
sqlite3.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||
-e s/--ENCODING--/$(ENCODING)/ \
|
||||
$(TOP)/src/sqlite.h.in >sqlite3.h
|
||||
tclsqlite: $(TOP)/src/tclsqlite.c libsqlite.a
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite \
|
||||
$(TOP)/src/tclsqlite.c libsqlite.a $(LIBTCL)
|
||||
|
||||
table.o: $(TOP)/src/table.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/table.c
|
||||
|
||||
tclsqlite.o: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
tokenize.o: $(TOP)/src/tokenize.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/tokenize.c
|
||||
|
||||
trigger.o: $(TOP)/src/trigger.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/trigger.c
|
||||
|
||||
update.o: $(TOP)/src/update.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/update.c
|
||||
|
||||
utf.o: $(TOP)/src/utf.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/utf.c
|
||||
|
||||
util.o: $(TOP)/src/util.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/util.c
|
||||
|
||||
vacuum.o: $(TOP)/src/vacuum.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/vacuum.c
|
||||
|
||||
vdbe.o: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbe.c
|
||||
|
||||
vdbeapi.o: $(TOP)/src/vdbeapi.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbeapi.c
|
||||
|
||||
vdbeaux.o: $(TOP)/src/vdbeaux.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbeaux.c
|
||||
|
||||
vdbemem.o: $(TOP)/src/vdbemem.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbemem.c
|
||||
|
||||
where.o: $(TOP)/src/where.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/where.c
|
||||
|
||||
# Rules for building test programs and for running tests
|
||||
#
|
||||
tclsqlite3: $(TOP)/src/tclsqlite.c libsqlite3.a
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite3 \
|
||||
$(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
testfixture$(EXE): $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC)
|
||||
testfixture$(EXE): $(TOP)/src/tclsqlite.c libsqlite.a $(TESTSRC)
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -o testfixture$(EXE) \
|
||||
$(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
libsqlite.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
crashtest: $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC) $(TOP)/src/os_test.c
|
||||
$(TCCX) $(TCL_FLAGS) -DOS_TEST=1 -DTCLSH=1 -DSQLITE_TEST=1 \
|
||||
-o crashtest \
|
||||
$(TESTSRC) $(TOP)/src/os_test.c $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
fulltest: testfixture$(EXE) sqlite3$(EXE) crashtest
|
||||
fulltest: testfixture$(EXE) sqlite$(EXE)
|
||||
./testfixture$(EXE) $(TOP)/test/all.test
|
||||
|
||||
test: testfixture$(EXE) sqlite3$(EXE)
|
||||
test: testfixture$(EXE) sqlite$(EXE)
|
||||
./testfixture$(EXE) $(TOP)/test/quick.test
|
||||
|
||||
sqlite3_analyzer$(EXE): $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC) \
|
||||
$(TOP)/tool/spaceanal.tcl
|
||||
sed \
|
||||
-e '/^#/d' \
|
||||
-e 's,\\,\\\\,g' \
|
||||
-e 's,",\\",g' \
|
||||
-e 's,^,",' \
|
||||
-e 's,$$,\\n",' \
|
||||
$(TOP)/tool/spaceanal.tcl >spaceanal_tcl.h
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=2 -DSQLITE_TEST=1 -static -o \
|
||||
sqlite3_analyzer$(EXE) $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
index.html: $(TOP)/www/index.tcl last_change
|
||||
tclsh $(TOP)/www/index.tcl `cat $(TOP)/VERSION` >index.html
|
||||
|
||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
|
||||
|
||||
c_interface.html: $(TOP)/www/c_interface.tcl
|
||||
tclsh $(TOP)/www/c_interface.tcl >c_interface.html
|
||||
|
||||
changes.html: $(TOP)/www/changes.tcl
|
||||
tclsh $(TOP)/www/changes.tcl >changes.html
|
||||
|
||||
lang.html: $(TOP)/www/lang.tcl
|
||||
tclsh $(TOP)/www/lang.tcl >lang.html
|
||||
|
||||
vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
tclsh $(TOP)/www/vdbe.tcl >vdbe.html
|
||||
|
||||
# Rules used to build documentation
|
||||
#
|
||||
arch.html: $(TOP)/www/arch.tcl
|
||||
tclsh $(TOP)/www/arch.tcl >arch.html
|
||||
|
||||
arch.png: $(TOP)/www/arch.png
|
||||
cp $(TOP)/www/arch.png .
|
||||
|
||||
c_interface.html: $(TOP)/www/c_interface.tcl
|
||||
tclsh $(TOP)/www/c_interface.tcl >c_interface.html
|
||||
|
||||
capi3.html: $(TOP)/www/capi3.tcl
|
||||
tclsh $(TOP)/www/capi3.tcl >capi3.html
|
||||
|
||||
capi3ref.html: $(TOP)/www/capi3ref.tcl
|
||||
tclsh $(TOP)/www/capi3ref.tcl >capi3ref.html
|
||||
|
||||
changes.html: $(TOP)/www/changes.tcl
|
||||
tclsh $(TOP)/www/changes.tcl >changes.html
|
||||
|
||||
copyright.html: $(TOP)/www/copyright.tcl
|
||||
tclsh $(TOP)/www/copyright.tcl >copyright.html
|
||||
|
||||
copyright-release.html: $(TOP)/www/copyright-release.html
|
||||
cp $(TOP)/www/copyright-release.html .
|
||||
|
||||
copyright-release.pdf: $(TOP)/www/copyright-release.pdf
|
||||
cp $(TOP)/www/copyright-release.pdf .
|
||||
|
||||
common.tcl: $(TOP)/www/common.tcl
|
||||
cp $(TOP)/www/common.tcl .
|
||||
|
||||
conflict.html: $(TOP)/www/conflict.tcl
|
||||
tclsh $(TOP)/www/conflict.tcl >conflict.html
|
||||
|
||||
datatypes.html: $(TOP)/www/datatypes.tcl
|
||||
tclsh $(TOP)/www/datatypes.tcl >datatypes.html
|
||||
|
||||
datatype3.html: $(TOP)/www/datatype3.tcl
|
||||
tclsh $(TOP)/www/datatype3.tcl >datatype3.html
|
||||
|
||||
docs.html: $(TOP)/www/docs.tcl
|
||||
tclsh $(TOP)/www/docs.tcl >docs.html
|
||||
|
||||
download.html: $(TOP)/www/download.tcl
|
||||
mkdir -p doc
|
||||
tclsh $(TOP)/www/download.tcl >download.html
|
||||
|
||||
faq.html: $(TOP)/www/faq.tcl
|
||||
tclsh $(TOP)/www/faq.tcl >faq.html
|
||||
|
||||
fileformat.html: $(TOP)/www/fileformat.tcl
|
||||
tclsh $(TOP)/www/fileformat.tcl >fileformat.html
|
||||
|
||||
formatchng.html: $(TOP)/www/formatchng.tcl
|
||||
tclsh $(TOP)/www/formatchng.tcl >formatchng.html
|
||||
|
||||
index.html: $(TOP)/www/index.tcl last_change
|
||||
tclsh $(TOP)/www/index.tcl >index.html
|
||||
|
||||
lang.html: $(TOP)/www/lang.tcl
|
||||
tclsh $(TOP)/www/lang.tcl >lang.html
|
||||
|
||||
lockingv3.html: $(TOP)/www/lockingv3.tcl
|
||||
tclsh $(TOP)/www/lockingv3.tcl >lockingv3.html
|
||||
|
||||
oldnews.html: $(TOP)/www/oldnews.tcl
|
||||
tclsh $(TOP)/www/oldnews.tcl >oldnews.html
|
||||
|
||||
omitted.html: $(TOP)/www/omitted.tcl
|
||||
tclsh $(TOP)/www/omitted.tcl >omitted.html
|
||||
|
||||
opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
|
||||
tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
|
||||
|
||||
mingw.html: $(TOP)/www/mingw.tcl
|
||||
tclsh $(TOP)/www/mingw.tcl >mingw.html
|
||||
|
||||
nulls.html: $(TOP)/www/nulls.tcl
|
||||
tclsh $(TOP)/www/nulls.tcl >nulls.html
|
||||
|
||||
quickstart.html: $(TOP)/www/quickstart.tcl
|
||||
tclsh $(TOP)/www/quickstart.tcl >quickstart.html
|
||||
tclsqlite.html: $(TOP)/www/tclsqlite.tcl
|
||||
tclsh $(TOP)/www/tclsqlite.tcl >tclsqlite.html
|
||||
|
||||
speed.html: $(TOP)/www/speed.tcl
|
||||
tclsh $(TOP)/www/speed.tcl >speed.html
|
||||
|
||||
sqlite.gif: $(TOP)/art/SQLite.gif
|
||||
cp $(TOP)/art/SQLite.gif sqlite.gif
|
||||
faq.html: $(TOP)/www/faq.tcl
|
||||
tclsh $(TOP)/www/faq.tcl >faq.html
|
||||
|
||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
|
||||
formatchng.html: $(TOP)/www/formatchng.tcl
|
||||
tclsh $(TOP)/www/formatchng.tcl >formatchng.html
|
||||
|
||||
support.html: $(TOP)/www/support.tcl
|
||||
tclsh $(TOP)/www/support.tcl >support.html
|
||||
conflict.html: $(TOP)/www/conflict.tcl
|
||||
tclsh $(TOP)/www/conflict.tcl >conflict.html
|
||||
|
||||
tclsqlite.html: $(TOP)/www/tclsqlite.tcl
|
||||
tclsh $(TOP)/www/tclsqlite.tcl >tclsqlite.html
|
||||
download.html: $(TOP)/www/download.tcl
|
||||
tclsh $(TOP)/www/download.tcl >download.html
|
||||
|
||||
vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
tclsh $(TOP)/www/vdbe.tcl >vdbe.html
|
||||
omitted.html: $(TOP)/www/omitted.tcl
|
||||
tclsh $(TOP)/www/omitted.tcl >omitted.html
|
||||
|
||||
version3.html: $(TOP)/www/version3.tcl
|
||||
tclsh $(TOP)/www/version3.tcl >version3.html
|
||||
datatypes.html: $(TOP)/www/datatypes.tcl
|
||||
tclsh $(TOP)/www/datatypes.tcl >datatypes.html
|
||||
|
||||
quickstart.html: $(TOP)/www/quickstart.tcl
|
||||
tclsh $(TOP)/www/quickstart.tcl >quickstart.html
|
||||
|
||||
fileformat.html: $(TOP)/www/fileformat.tcl
|
||||
tclsh $(TOP)/www/fileformat.tcl >fileformat.html
|
||||
|
||||
nulls.html: $(TOP)/www/nulls.tcl
|
||||
tclsh $(TOP)/www/nulls.tcl >nulls.html
|
||||
|
||||
|
||||
# Files to be published on the website.
|
||||
#
|
||||
DOC = \
|
||||
index.html \
|
||||
sqlite.html \
|
||||
changes.html \
|
||||
lang.html \
|
||||
opcode.html \
|
||||
arch.html \
|
||||
arch.png \
|
||||
c_interface.html \
|
||||
capi3.html \
|
||||
capi3ref.html \
|
||||
changes.html \
|
||||
copyright.html \
|
||||
copyright-release.html \
|
||||
copyright-release.pdf \
|
||||
conflict.html \
|
||||
datatypes.html \
|
||||
datatype3.html \
|
||||
docs.html \
|
||||
download.html \
|
||||
faq.html \
|
||||
fileformat.html \
|
||||
formatchng.html \
|
||||
index.html \
|
||||
lang.html \
|
||||
lockingv3.html \
|
||||
mingw.html \
|
||||
nulls.html \
|
||||
oldnews.html \
|
||||
omitted.html \
|
||||
opcode.html \
|
||||
quickstart.html \
|
||||
speed.html \
|
||||
sqlite.gif \
|
||||
sqlite.html \
|
||||
support.html \
|
||||
tclsqlite.html \
|
||||
vdbe.html \
|
||||
version3.html
|
||||
c_interface.html \
|
||||
mingw.html \
|
||||
tclsqlite.html \
|
||||
download.html \
|
||||
speed.html \
|
||||
faq.html \
|
||||
formatchng.html \
|
||||
conflict.html \
|
||||
omitted.html \
|
||||
datatypes.html \
|
||||
quickstart.html \
|
||||
fileformat.html \
|
||||
nulls.html
|
||||
|
||||
doc: common.tcl $(DOC)
|
||||
doc: $(DOC)
|
||||
mkdir -p doc
|
||||
mv $(DOC) doc
|
||||
|
||||
# Standard install and cleanup targets
|
||||
#
|
||||
install: sqlite3 libsqlite3.a sqlite3.h
|
||||
mv sqlite3 /usr/bin
|
||||
mv libsqlite3.a /usr/lib
|
||||
mv sqlite3.h /usr/include
|
||||
install: sqlite libsqlite.a sqlite.h
|
||||
mv sqlite /usr/bin
|
||||
mv libsqlite.a /usr/lib
|
||||
mv sqlite.h /usr/include
|
||||
|
||||
clean:
|
||||
rm -f *.o sqlite3 libsqlite3.a sqlite3.h opcodes.*
|
||||
rm -f *.o sqlite libsqlite.a sqlite.h opcodes.*
|
||||
rm -f lemon lempar.c parse.* sqlite*.tar.gz
|
||||
rm -f $(PUBLISH)
|
||||
rm -f *.da *.bb *.bbg gmon.out
|
||||
|
||||
@@ -1,254 +1,194 @@
|
||||
C Version\s3.0.6\s(beta)\s(CVS\s1934)
|
||||
D 2004-09-02T16:45:59
|
||||
F Makefile.in 65a7c43fcaf9a710d62f120b11b6e435eeb4a450
|
||||
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
||||
C Version\s2.8.14\s(CVS\s1554)
|
||||
D 2004-06-09T23:20:06
|
||||
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
|
||||
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||
F VERSION d28cfc2e7714a747851e50cc1a5ee8ab0ded7a78
|
||||
F VERSION f97edce65ceac3b00185ca009ed810a470837a50
|
||||
F aclocal.m4 7daea4c35e88de30d5a3f6f7a2ab99720e803bbd
|
||||
F art/SQLite.eps 9b43cc99cfd2be687d386faea6862ea68d6a72b2
|
||||
F art/SQLite.gif 1bbb94484963f1382e27e1c5e86dd0c1061eba2b
|
||||
F art/SQLiteLogo3.tiff b9e6bf022ae939bc986cddb8ab99583ca1b02cb3
|
||||
F config.guess 2103e94b15dc57112d7b9ee152c6fac5288895b4
|
||||
F config.sub 9bf686ec001ae7bc53f5b3563c90c62d4c6d48be
|
||||
F configure d3720624693e6b18264e7776f7250dd472659a10 x
|
||||
F configure.ac 82b4d26ae0234e87019b5783b67bd5b807eb5820
|
||||
F doc/affinity.html bdc7560fa3d2284af59d8fb52041cddbb14578f5
|
||||
F configure 6a156e79aaddba2e0e6816972d99989f48cc1699 x
|
||||
F configure.ac 684143ce9ee7bafc4291d0e17f2dfdc70514d1d6
|
||||
F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
|
||||
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
|
||||
F main.mk 2eb2826d6bd82d54e768902e5e1929e550409273
|
||||
F mkdll.sh 468d4f41d3ea98221371df4825cfbffbaac4d7e4
|
||||
F mkso.sh 7b67da1d63070875ba948e749aee9ef50ce36e3d
|
||||
F publish.sh 72bde067dda3fc2d33e92f20253b924e3b97da30
|
||||
F spec.template b2f6c4e488cbc3b993a57deba22cbc36203c4da3
|
||||
F main.mk 1b27efb94be53a96c4333584a00a59fcc87ddc37
|
||||
F publish.sh 1cd5c982388560fa91eedf6a338e210f713b35c8
|
||||
F spec.template a38492f1c1dd349fc24cb0565e08afc53045304b
|
||||
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
|
||||
F sqlite.def fc4f5734786fe4743cfe2aa98eb2da4b089edb5f
|
||||
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
|
||||
F sqlite3.def 84215604aa7b547d75e0f7b437966e7ad18fa8b2
|
||||
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
|
||||
F src/attach.c 0bd4f11da6999665da30625665a4096ba7898de6
|
||||
F src/auth.c 60db23b98bb94c8b0178180faaf49dc116674217
|
||||
F src/btree.c 598e7eccfa93194851f570c0ea146f6efe098ac3
|
||||
F src/btree.h 94dfec0a1722d33359b23e7e310f2b64ffedf029
|
||||
F src/build.c 35275654d9c5ce6c1c0c78e391f85e6915a8a66b
|
||||
F src/date.c edff4aa851eeca8abbc737dc3933a2f0671156ce
|
||||
F src/delete.c cebfdde83e7bf68d8118e1c13e40c99787302fbf
|
||||
F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37
|
||||
F src/expr.c d618305952f75567514824cf9bdd5de74db5e00a
|
||||
F src/func.c 54a095713dd117e5482b25fa829e241d6938f1b6
|
||||
F src/hash.c a97721a55440b7bea31ffe471bb2f6b4123cddd5
|
||||
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
|
||||
F src/insert.c fc1ce65a0fe68f226143de9b43c3582164a92aff
|
||||
F src/legacy.c 2f3617c61bcdcd1d776154a9cfebf99facda8ad8
|
||||
F src/main.c 981bbcf4521762ab9f8ecbda1a4260ef94d7234f
|
||||
F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
|
||||
F src/os.h d1780e0db95cad01f213d48da22ab490eb4fd345
|
||||
F src/os_common.h cd7eb025fdab7dc91e0e97bf6310f1648205857f
|
||||
F src/os_mac.c 3d31e26be1411acfb7961033098631b4f3486fdf
|
||||
F src/os_mac.h 51d2445f47e182ed32d3bd6937f81070c6fd9bd4
|
||||
F src/os_test.c d3cb336448d28cb6238f8c0d7a44b0ff010601ea
|
||||
F src/os_test.h 6a26a4978492e4bbdbf385554958418ff02db162
|
||||
F src/os_unix.c a5625eed7ab071d1715df783f4684945ae538a22
|
||||
F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13
|
||||
F src/os_win.c 9e2887825b1a32f0ceb1b73b93ffe29a112cd86f
|
||||
F src/os_win.h babd4e912967c6b09088cfe38a45e8005a07ba44
|
||||
F src/pager.c ae06c85de0db43f61a7a3e5eacad3fd5615daf59
|
||||
F src/pager.h 67739fe649f33be55dba522ca8a9cc4e42d14f71
|
||||
F src/parse.y 581a2ce014b843506805b2470c02b7865ad034d5
|
||||
F src/pragma.c 7156618038546ed4d09d733ceea231aebee3f2f8
|
||||
F src/printf.c 17b28a1eedfe8129b05de981719306c18c3f1327
|
||||
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
|
||||
F src/select.c 14534579535579a082fda8bbc7d621d7d170f406
|
||||
F src/shell.c 4f1a2760ced81c829defb47b0a3b61ffec61b604
|
||||
F src/sqlite.h.in b89ced1acc705bc9c79a2a4e725ac0eb64bd0614
|
||||
F src/sqliteInt.h 71de4b0400b50579d5dfab70b59adbb7776e77d8
|
||||
F src/table.c 4521c278892f60e4d630788c0ea5cf4db1e75c49
|
||||
F src/tclsqlite.c b7dd8b3531b70188d03354db530de0f2ffcac697
|
||||
F src/test1.c 3670f318c473b5a81cae548d9cc42da3f6a6efee
|
||||
F src/test2.c f4c2f3928f1998fd8cb75a81e33a60e025ea85d4
|
||||
F src/test3.c 94d0a2a90bccd85802488cb42c69ec8afd2e4646
|
||||
F src/test4.c c38766914e924091516030b6a8b677d849c08bf0
|
||||
F src/test5.c b001fa7f1b9e2dc5c2331de62fc641b5ab2bd7a1
|
||||
F src/tokenize.c 32171c3d576c7ec6acd6cf15e55c00ac0b314769
|
||||
F src/trigger.c 40e10f4b219b55e56478bc17480ce77654300e8d
|
||||
F src/update.c bbe126c67529bd699016af2d72bc4ceb8fd41527
|
||||
F src/utf.c 328890099db492dda5620ee5f924e244c6e57ff7
|
||||
F src/util.c d5aaf211543fb6e285654fada50252c857ac78aa
|
||||
F src/vacuum.c 47bf6837d39f5849b8eda7d037d3e21a26f736bc
|
||||
F src/vdbe.c 45f659497b479f001c2f4e8251474aba3975b9f8
|
||||
F src/vdbe.h e081c72cd0f7c19d49b1927460aeefcf0fbc85ac
|
||||
F src/vdbeInt.h f8df57a9dc272967991f806e612628e0aa57e705
|
||||
F src/vdbeapi.c 854732720c2cfc6ff76b28eef6253ac84a5408bc
|
||||
F src/vdbeaux.c 77eaaf62b8b3acad4a2ef351e3c44ecffc67faf6
|
||||
F src/vdbemem.c ef9ac7d32acfe4bce5c5b408b1294c8d9e0cdb56
|
||||
F src/where.c a84eee276cd072158224da6b5f30733df2d56027
|
||||
F test/all.test 929bfa932b55e75c96fe2203f7650ba451c1862c
|
||||
F test/attach.test feb2ce54e78688df4c84553416d5aec3b2a0112e
|
||||
F test/attach2.test 32ca2c1a5a347a7404219a11f9f84739a63d2582
|
||||
F test/attach3.test 6d060986ff004ebb89e1876a331d96c6bb62269e
|
||||
F test/auth.test e74b015545f608c06d5b84d17acdf7146eb818af
|
||||
F test/bigfile.test 62722ac4b420dfbcdceb137b8634e2cf2865fe27
|
||||
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
|
||||
F test/bind.test 7968edd61eb83b6e09165e4ba38e327dace6fb35
|
||||
F test/blob.test 8727a7b46b2073a369cfc9bcb6f54dd366b9d884
|
||||
F test/btree.test 97b563e1ab999bf8764b129e8c4b4be0a116a52a
|
||||
F test/btree2.test aa4a6d05b1ea90b1acaf83ba89039dd302a88635
|
||||
F test/btree4.test 3797b4305694c7af6828675b0f4b1424b8ca30e4
|
||||
F test/btree5.test 8e5ff32c02e685d36516c6499add9375fe1377f2
|
||||
F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027
|
||||
F test/btree7.test 429b96cfef5b51a7d512cfb4b5b3e453384af293
|
||||
F test/capi2.test 53e3f399074d5654f26d55b32ccaca7b5b619933
|
||||
F test/capi3.test 9258ca75fc98d89477015dcd70aa3d2757b142b8
|
||||
F test/capi3b.test 458044d8c250c129ddfd77c6265a6923bc008b5e
|
||||
F test/collate1.test f79736d2ebf5492167ee4d1f4ab4c09dda776b03
|
||||
F test/collate2.test c1a3b41f761b28853c5696037f92de928f93233b
|
||||
F test/collate3.test e60b428e07ec945492ba90ff1c895902ee3a8a50
|
||||
F test/collate4.test 4a7902b7560686af11d6cace717d876c6937b7ef
|
||||
F test/collate5.test 1dd5f0f508c46667f9d4606c7950c414b0bdc0d5
|
||||
F test/collate6.test 2a45768914f04c1447a69d1358bbede376552675
|
||||
F test/conflict.test c5b849b01cfbe0a4f63a90cba6f68e2fe3a75f87
|
||||
F test/corrupt.test 0080ddcece23e8ba47c44608c4fb73fd4d1d8ce2
|
||||
F test/crash.test a3f6d27f7cb7f7bd752461db1e14f7c781ecedc3
|
||||
F src/attach.c 026702566f941bf2bb158a0aaa86bfeb65910aa6
|
||||
F src/auth.c 4fa3b05bd19445d1c474d6751c4a508d6ea0abe1
|
||||
F src/btree.c 08a05b925b348c05d79b9b062b79e50d565678de
|
||||
F src/btree.h 41cb3ff6ebc3f6da2d0a074e39ff8c7a2287469f
|
||||
F src/btree_rb.c 99feb3ff835106d018a483a1ce403e5cf9c718bc
|
||||
F src/build.c 76fbca30081decd6615dee34b48c927ed5063752
|
||||
F src/copy.c 750e13828c3e4a293123e36aaa7cf0f22466248a
|
||||
F src/date.c f055419d602bde622c70f831350b6b52f2235de0
|
||||
F src/delete.c 82001c74882319f94dab5f6b92a27311b31092ae
|
||||
F src/encode.c fc8c51f0b61bc803ccdec092e130bebe762b0a2f
|
||||
F src/expr.c 8c3f5603c3e98b1c146d18076ba3e82cdbb59c11
|
||||
F src/func.c 34fead7a33e82095f6412d3fafd379d47864b3be
|
||||
F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e
|
||||
F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7
|
||||
F src/insert.c c0485ee2d1b99322894e2d1e0b576fd05ed75616
|
||||
F src/main.c 94dd355768e2a389e184a069b6880f4bac100307
|
||||
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
|
||||
F src/os.c edcd42ad1cf13e7322f814c50a3e6eb09d3915bb
|
||||
F src/os.h 250a3789be609adfee5c5aa20137ce8683276f24
|
||||
F src/pager.c b246986e5ba31b15aa3cf91d3b9ec2e608aceb8e
|
||||
F src/pager.h 82332878799280145639a48d88cdb4058925e3f6
|
||||
F src/parse.y 023720cb8c3bef74e51738bca78335d0dc6d2cfd
|
||||
F src/pragma.c f9c157b0591419d2d3407dac90222020d2a6d822
|
||||
F src/printf.c 8c58b7b6d4069eec6ebe2d46bdbc3a89a367bf95
|
||||
F src/random.c 775913e0b7fbd6295d21f12a7bd35b46387c44b2
|
||||
F src/select.c 3833e2b64cc6d249385ee44e13bf49c9ae5b903d
|
||||
F src/shell.c 920af040d3a33ea8919c82cee45b424ad841cee0
|
||||
F src/sqlite.h.in 35bec264dfb4965bbfeb7e75221f8658f210c30d
|
||||
F src/sqliteInt.h 235ce244b62bb26cc9ab394fb7a0724dd4e65c83
|
||||
F src/table.c d845cb101b5afc1f7fea083c99e3d2fa7998d895
|
||||
F src/tclsqlite.c 819d92d305756c4ea57de023c387d2fa8a256aff
|
||||
F src/test1.c 4ae20bc125b1a7d7824cccca55d538d81f0b4949
|
||||
F src/test2.c 75819b0f2c63c6a0fd6995445881f2eb94036996
|
||||
F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
|
||||
F src/test4.c 6e3e31acfaf21d66420fc35fda5b17dc0000cc8d
|
||||
F src/tokenize.c 6676b946fd8825b67ab52140af4fdc57a70bda48
|
||||
F src/trigger.c a9927b57c865b6f3df3fb5e40c9824d722660ded
|
||||
F src/update.c bd391079138e67d09c9af34528ca4137c29242d1
|
||||
F src/util.c 122bc174f6c8c2eb6a9127d9f13c4c74f83b85e4
|
||||
F src/vacuum.c 36a19aa877c696c4ec8b78300c19f4059d2617a7
|
||||
F src/vdbe.c 0853ab9983b7adbba8c012bb8b152d8453bf8a97
|
||||
F src/vdbe.h ac987945e4dd6f987bca534c6005899f089fc270
|
||||
F src/vdbeInt.h b40ff02ce39fd076e6ff3369e19c1bbfe1986682
|
||||
F src/vdbeaux.c e2cdd1ab63604a390612c73e26bdd2ef910e9438
|
||||
F src/where.c b58764861a96bab3f1d294200f9e53519b92c274
|
||||
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
|
||||
F test/attach.test ba8261d38da6b6a7d4f78ec543c548c4418582ef
|
||||
F test/attach2.test ce61e6185b3cd891cc0e9a4c868fcc65eb92fc55
|
||||
F test/auth.test 5c4d95cdaf539c0c236e20ce1f71a93e7dde9185
|
||||
F test/bigfile.test ea904b853ce2d703b16c5ce90e2b54951bc1ae81
|
||||
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
|
||||
F test/bind.test 56a57043b42c4664ca705f6050e56717a8a6699a
|
||||
F test/btree.test 677aeaac7b7b81980b446ca9cab15aa0cc5550d5
|
||||
F test/btree2.test e3b81ec33dc2f89b3e6087436dfe605b870c9080
|
||||
F test/btree3.test e597fb59be2ac0ea69c62aaa2064e998e528b665
|
||||
F test/btree3rb.test 127efcf5cdfcc352054e7db12622b01cdd8b36ac
|
||||
F test/btree4.test fa955a3d7a8bc91d6084b7f494f9e5d1bdfb15b6
|
||||
F test/btree4rb.test ae6f0438512edcb45cf483471cd6070a765963a9
|
||||
F test/capi2.test ec96e0e235d87b53cbaef3d8e3e0f8ccf32c71ca
|
||||
F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e
|
||||
F test/copy.test f07ea8d60878da7a67416ab62f78e9706b9d3c45
|
||||
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
|
||||
F test/date.test fd3db29bba089578b1b008e3511ea9e74840377a
|
||||
F test/delete.test ec0b455f2dcc0e189d96ee438438ba026c4e51d8
|
||||
F test/delete2.test 050a3a6e8ea0f83aed817d164b16af2a499fb452
|
||||
F test/enc.test 2f5463af488d50aef60c6110bec6b21b5efba961
|
||||
F test/enc2.test 7a60971a62748be6b607b4b4380eb4c5e151a6ec
|
||||
F test/enc3.test 2ae80b11adf5b2c171d2e17214dabd356b9672c1
|
||||
F test/expr.test 91358521f8ec41cd0fd1c5370c93104265f1fefc
|
||||
F test/date.test aed5030482ebc02bd8d386c6c86a29f694ab068d
|
||||
F test/delete.test 92256384f1801760180ded129f7427884cf28886
|
||||
F test/expr.test ad985242e140f87eeef329d98257b8369a2066dc
|
||||
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
|
||||
F test/func.test 830d352574c7f5cd15149a9be58a6dcc2b995c05
|
||||
F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda
|
||||
F test/in.test b92a2df9162e1cbd33c6449a29a05e6955b1741a
|
||||
F test/index.test 31ed90af028d1ec9a3a8a4f0d7021717ba05dd16
|
||||
F test/insert.test ebbab63db4ad69395a058514bccb3cdb0a029d48
|
||||
F test/insert2.test ea5d4f8dcbc68d8ad85eaa5f03d9812757610f90
|
||||
F test/interrupt.test 9142ce4448605127640eda5e283952f75f67ed91
|
||||
F test/intpkey.test c8efd06db62b8b27216558ef439cc867d113cfec
|
||||
F test/ioerr.test 7d087bfd1a1a53442940e000df936e0df0c5b886
|
||||
F test/format3.test 149cc166c97923fa60def047e90dd3fb32bba916
|
||||
F test/func.test 000515779001ac6899eec4b54e65c6e2501279d4
|
||||
F test/hook.test 1a67ce0cd64a6455d016962542f2822458dccc49
|
||||
F test/in.test 0de39b02ceeca90993b096822fb5a884661c5b47
|
||||
F test/index.test 9295deefbdb6dedbe01be8905f0c448fe5bd4079
|
||||
F test/insert.test a17b7f7017097afb2727aa5b67ceeb7ab0a120a1
|
||||
F test/insert2.test c288375a64dad3295044714f0dfed4a193cf067f
|
||||
F test/interrupt.test 0d50985f1aa6c39fe2cca4cf4a272c79ff1648e8
|
||||
F test/intpkey.test 9320af48415c594afd4e15f8ef0daa272e05502e
|
||||
F test/ioerr.test 5dbaf09f96b56ee01cf3edd762b96eb4ad2c9ca4
|
||||
F test/join.test 9ef6aabaac9de51d5fc41e68d1f4355da05a84cd
|
||||
F test/join2.test c97e4c5aa65dea462145529e58212a709b4722b8
|
||||
F test/join3.test 67dc0d7c8dab3fff25796d0f3c3fd9c999aeded3
|
||||
F test/join4.test 8dec387d06b3a4685e1104048065cf5236b99b93
|
||||
F test/lastinsert.test 31382f88b9b0270333ac9e4a17f2c2f4732da718
|
||||
F test/laststmtchanges.test 417aa27eb2b5cdfafb46e390e2c9ddd0a20eba43
|
||||
F test/limit.test f7c06fccd76755e8d083b61c06bc31cf461b9c35
|
||||
F test/lock.test 7cb9395919a0986ee4dd08bd49d34df93c8fc4fe
|
||||
F test/lock2.test 2213590d442147d09fd2334c905a755586c1c398
|
||||
F test/main.test 1430a4b5bd3a6d5e0294966b742d80a551f87211
|
||||
F test/malloc.test 769b240d89a7ef3320d88919fdb6765f9395a51f
|
||||
F test/memdb.test b8a13fa79f006bd087bbcf135ce8eb62056a6027
|
||||
F test/memleak.test a7efa33c7adc2762add028a4cc70a6bb04fe573e
|
||||
F test/minmax.test c0f92d3f7b11656221735385f2c8b1878bbbdaf6
|
||||
F test/misc1.test 1a20ea722dff15155e93948dc4ac3e8d80fec386
|
||||
F test/misc2.test 703734f5817215ca54e364833b3bf5ff36fcc21e
|
||||
F test/misc3.test 57c373aed45acdf45f8f78ea914ef8855841e6b7
|
||||
F test/misc4.test 9f8ab4896dd627f5f9ba893a7b57c9f0a95dfd64
|
||||
F test/misuse.test 2a64ce711419f2fd12806ed95af930fd4e7bb8f3
|
||||
F test/laststmtchanges.test cabd11bdfbaf73a4486c50b58297d9c2038ccc18
|
||||
F test/limit.test e28ce938ddacefdff860d082be45e1e5e2801441
|
||||
F test/lock.test 226ef831dad60ad4d200dc83e25479ba952aac7e
|
||||
F test/main.test 6a851b5992c4881a725a3d9647e629199df8de9d
|
||||
F test/malloc.test 2cfcffb7c858640e01e6520ee1cd54ca57d98e80
|
||||
F test/memdb.test 6ece25c7c0e6500199d3662607a3edca081abb2a
|
||||
F test/memleak.test 4d5d374c8ea1fc5ac634aed58cac1047848ce65e
|
||||
F test/minmax.test 9dcf52f713b1b9e61d0a88a51eb8bb2e3c52d0ab
|
||||
F test/misc1.test 0b98d493b0cf55cb5f53e1f3df8107c166eecb5a
|
||||
F test/misc2.test 10c2ce26407d37411b96273e552d5095393732be
|
||||
F test/misc3.test 3b5e369514a3ba3f919fb7eafa7d027440b5079e
|
||||
F test/misuse.test 1095f26d1aed406c65e1d2eba651c4bb7c38cbff
|
||||
F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
|
||||
F test/null.test 642428b6a5408cc5b954b49e1b6e5025e4458b2b
|
||||
F test/pager.test 059cc5c58d3b5a851343dff8c56cf7286425d03a
|
||||
F test/pager2.test 55469c7c1c1a54d6b32d7b3cc99001e90101a1ce
|
||||
F test/pager3.test 16f546293bb751b8151dc17df613fca938bbec8b
|
||||
F test/pagesize.test ada866e3d8bad7ec252d5131e2fd4d892b8fef8d
|
||||
F test/pragma.test 66a66b7f3b273b93325c9a5794acb418f52fdcbf
|
||||
F test/printf.test 5a30fb0d736148fca64cb1b7ed0390be7414e024
|
||||
F test/progress.test 76c722f090b1ccb575e7e4e203a71608c5763beb x
|
||||
F test/quick.test 212a9cd4c40c72c7c4780fef1c2fbe5d1cb34ce6
|
||||
F test/quote.test 6d75cf635d93ba2484dc9cb378d88cbae9dc2c62
|
||||
F test/rollback.test 4097328d44510277244ef4fa51b22b2f11d7ef4c
|
||||
F test/rowid.test b3d059f5c8d8874fa1c31030e0636f67405d20ea
|
||||
F test/select1.test 0e459a8066259445d707cc4f64ea00459441e29f
|
||||
F test/select2.test 91a2225926039b0d1687840735c284dbbf89f0bc
|
||||
F test/select3.test 9de435aa84fc406708cd8dc1b1d60e7f27cea685
|
||||
F test/select4.test 86e72fc3b07de4fe11439aa419e37db3c49467e2
|
||||
F test/select5.test 94db800bbeff2e426c0175e07f7a71d4617853b5
|
||||
F test/select6.test 7a4c572ada0c2f969cecacd76f1f5c1533a22bbb
|
||||
F test/select7.test c71c822a82c80bbd55558b4b69d35442dfe22ffd
|
||||
F test/sort.test 35e9d6bd6930969050606c8feb9c6745469720e3
|
||||
F test/subselect.test 50f98723f00e97b1839d36410ee63597ca82d775
|
||||
F test/table.test fd9a0f4992230e4ca89cd37ae3191a12750df1d0
|
||||
F test/tableapi.test b21ab097e87a5484bb61029e69e1a4e5c5e65ede
|
||||
F test/tclsqlite.test d84b91f5e8219bbaf7f960ce649806eb39cc703f
|
||||
F test/temptable.test 63a16e3ad19adf073cfbcdf7624c92ac5236522c
|
||||
F test/tester.tcl 1ff1170dd4203d87f572871080cdb64330dade99
|
||||
F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
|
||||
F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
|
||||
F test/threadtest2.c 97a830d53c24c42290501fdfba4a6e5bdd34748b
|
||||
F test/trace.test 0ed72787440d97c6de6b6ecb4c022e6f78d5d94a
|
||||
F test/trans.test 29645b344d2b9b6792793562b12340177ddd8f96
|
||||
F test/trigger1.test dc015c410161f1a6109fd52638dfac852e2a34de
|
||||
F test/trigger2.test a5d06e6e8e1e773cfcb5aaa75ab381b2ff35de63
|
||||
F test/trigger3.test 70931be83fa3f563f7a5ca9e88b86f476af73948
|
||||
F test/trigger4.test 97c11d3cf43d752b172809bb82536372ee5e399c
|
||||
F test/trigger5.test 25ba4d352282cd05753496a50f0bd23162cc97b9
|
||||
F test/types.test 1f5f0670cf07e44c0a5b03a31e31ec5ed39a482e
|
||||
F test/types2.test f23c147a2ab3e51d5dbcfa9987200db5acba7aa7
|
||||
F test/null.test c14d0f4739f21e929b8115b72bf0c765b6bb1721
|
||||
F test/pager.test 331519008889d45f6df6697395e5bce6ee602fd9
|
||||
F test/pragma.test 24a3f7a697b45cb90d664ebce5566bec7ac41571
|
||||
F test/printf.test 46b3d07d59d871d0831b4a657f6dfcafe0574850
|
||||
F test/progress.test 701b6115c2613128ececdfe1398a1bd0e1a4cfb3 x
|
||||
F test/quick.test 5a6bccf5c02f16841a79fbac7409a02138880c10
|
||||
F test/quote.test 08f23385c685d3dc7914ec760d492cacea7f6e3d
|
||||
F test/rowid.test 77f7e8c7ca626a15ff91a536595b695cfce7c845
|
||||
F test/select1.test 0d708cec567104653ec9aa49fecf3444a2e7d150
|
||||
F test/select2.test aceea74fd895b9d007512f72499db589735bd8e4
|
||||
F test/select3.test 445a1a3dde4e2fd32541b311f55da5e2f8079d76
|
||||
F test/select4.test e7e9a32fa745246cb99fadbeb63af4843a17925b
|
||||
F test/select5.test c2a6c4a003316ee42cbbd689eebef8fdce0db2ac
|
||||
F test/select6.test a9e31906e700e7c7592c4d0acfc022808f718baf
|
||||
F test/sort.test ba07b107c16070208e6aab3cadea66ba079d85ba
|
||||
F test/subselect.test f0fea8cf9f386d416d64d152e3c65f9116d0f50f
|
||||
F test/table.test 371a1fc1c470982b2f68f9732f903a5d96f949c4
|
||||
F test/tableapi.test e0c4cce61e58343caa84dab33fa6823cb35fe1e1
|
||||
F test/tclsqlite.test a684fc191b81e6cded8a81263663d5a130fbb013
|
||||
F test/temptable.test a770ba6308d7f7332fce985086b8e06bed6430c2
|
||||
F test/tester.tcl 2f1d43df1311c9dc06acaa7a82e87bfea85dea5f
|
||||
F test/thread1.test 53f050d5be6932d9430df7756edd379366508ff6
|
||||
F test/threadtest1.c f7f896e62ed46feae1dc411114a48c15a0f82ee2
|
||||
F test/threadtest2.c d94ca4114fd1504f7e0ae724bcd83d4b40931d86
|
||||
F test/trans.test 0cb8256daff1ae0da75321e00125338c6681158d
|
||||
F test/trigger1.test 4538c1c7d6bbca5dfe619ea6e1682b07ece95b21
|
||||
F test/trigger2.test 0767ab30cb5a2c8402c8524f3d566b410b6f5263
|
||||
F test/trigger3.test a95ccace88291449f5eae7139ec438a42f90654d
|
||||
F test/trigger4.test 542afce45774e8f8e1130b96b8675f414d6e4bd8
|
||||
F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b
|
||||
F test/update.test b29bd9061a1150426dab6959806fcc73a41b1217
|
||||
F test/utf16.test 459c2f5ab80c60092c603630a348c32d6e59c558
|
||||
F test/vacuum.test 6bce0f84fff255b943abed3b345c9e0ce287e2b6
|
||||
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
|
||||
F test/view.test ca5c296989d3045f121be9a67588ff88c64874a8
|
||||
F test/where.test 40dcffcb77ad0a00960cef2b5b1212c77fd02199
|
||||
F test/vacuum.test a2a44544df719666efb51afbfeb6062fd59a672a
|
||||
F test/version.test 92adee5d98cf6e3eb0d1cf5186952e8114931bf6
|
||||
F test/view.test 1ee12c6f8f4791a2c0655120d5562a49400cfe53
|
||||
F test/where.test cb3a2ed062ce4b5f08aff2d08027c6a46d68c47b
|
||||
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
|
||||
F tool/lemon.c ece41a3cd100e68fef5f136267cf02c44366c263
|
||||
F tool/lemon.c db6a3bfaf3388c0f7aea3adb5e05acddcd427016
|
||||
F tool/lempar.c 0b5e7a58634e0d448929b8e85f7981c2aa708d57
|
||||
F tool/memleak.awk b744b6109566206c746d826f6ecdba34662216bc
|
||||
F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
|
||||
F tool/memleak3.tcl 336eb50b0849dbf99b1d5462d9c37291b01b2b43
|
||||
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
|
||||
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
|
||||
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
|
||||
F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
|
||||
F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
|
||||
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
|
||||
F tool/spaceanal.tcl c8c39c466fbbc01dab10fc6c4a816db3c8168ab3
|
||||
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
|
||||
F www/arch.gif f845a64772062e82d17980a349f95f1f0b4c8054
|
||||
F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4
|
||||
F www/arch.tcl b833057e89aeb43335c0bf84a3d5b7f9d11df6fa
|
||||
F www/arch2.fig ae2432145c26cfa148fa0116589517ad3cd5fc65
|
||||
F www/arch.tcl b329ca2c8dc75cd1cf0dd714b8bb47bdd458d0da
|
||||
F www/arch2.fig 613b5ac63511109064c2f93c5754ee662219937d
|
||||
F www/arch2.gif 49c6bb36160f03ca2b89eaa5bfb1f560c7d68ee7
|
||||
F www/arch2b.fig d22a2c9642d584b89d4088b1e51e2bb0f7c04bed
|
||||
F www/audit.tcl 90e09d580f79c7efec0c7d6f447b7ec5c2dce5c0
|
||||
F www/c_interface.tcl 83b39203e1ded4c2dab97f42edf31279a308efcb
|
||||
F www/capi3.tcl 5c1cb163f4d2a54e2d0e22dcc399dd71245c8b89
|
||||
F www/capi3ref.tcl bead38516efb0227ffa6ac76beb3f7ea405bb389
|
||||
F www/changes.tcl 3641bc28b86b40c82d546727da45ea0f0aa9a9f4
|
||||
F www/common.tcl f786e6be86fb2627ceb30e770e9efa83b9c67a3a
|
||||
F www/conflict.tcl fb8a2ba83746c7fdfd9e52fa7f6aaf5c422b8246
|
||||
F www/copyright-release.html 294e011760c439c44951a6bfecd4c81a1ae359e8
|
||||
F www/copyright-release.pdf cfca3558fc97095e57c6117d08f1f5b80d95125a
|
||||
F www/copyright.tcl 82c9670c7ddb0311912ab7fe24703f33c531066c
|
||||
F www/datatype3.tcl 2bb7dbfa4dd518a6e5fb3cb1cd8296797976d205
|
||||
F www/datatypes.tcl 566004b81c36877397ddbe6e1907aae6065f6b41
|
||||
F www/docs.tcl 095b5718ec044156af477061566ea25632624b56
|
||||
F www/download.tcl 958931d67680a2ff7044d5ed77ced1825a2a8c63
|
||||
F www/c_interface.tcl 17d8bd9e7b4fbdca47c30c8b9bcb728c351d55c0
|
||||
F www/changes.tcl a3d043896631a14091dbafdb4068980974c3834c
|
||||
F www/conflict.tcl 81dd21f9a679e60aae049e9dd8ab53d59570cda2
|
||||
F www/datatypes.tcl 0fe2b810f114a909b844e50ad37a25e6ed8c7271
|
||||
F www/download.tcl 0932d7f4f0e8b2adbbd22fac73132f86e43ab4a9
|
||||
F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
|
||||
F www/faq.tcl 3a1776818d9bd973ab0c3048ec7ad6b1ad091ae5
|
||||
F www/fileformat.tcl f71a06a0d533c7df408539c64113b4adeaf29764
|
||||
F www/formatchng.tcl d1dfecedfb25e122ab513a1e0948b15cb4f0be46
|
||||
F www/index.tcl 7d0caef2a084b3f6e4881bee2485b1cc1458d9f6
|
||||
F www/lang.tcl b2ba401104a76e7842469b33a968f5eda9bd462b
|
||||
F www/lockingv3.tcl afcd22f0f063989cff2f4d57bbc38d719b4c6e75
|
||||
F www/faq.tcl 88d3b95d9cd8e374772daa3a646c4d107e7f3e9b
|
||||
F www/fileformat.tcl 56f77e435a6306b337b20b416e3b89500ba2d029
|
||||
F www/formatchng.tcl ca6cc1cb1bef9bc36f0619049d3c95e749bc6983
|
||||
F www/index.tcl bacb2a0d052845bbe3bf078765cce907ed7080a4
|
||||
F www/lang.tcl 17954f37c8bb1d25e026d97041ff6459fb89ac95
|
||||
F www/mingw.tcl d96b451568c5d28545fefe0c80bee3431c73f69c
|
||||
F www/nulls.tcl ede975a29def48838c606d4a0c0185d44f90a789
|
||||
F www/oldnews.tcl fbbdbb64ed602b0c92b03498578f7ac70f47753d
|
||||
F www/omitted.tcl 7bd62b6f0f53b60c5360895b16b3af8407bbca03
|
||||
F www/opcode.tcl e8c421fd2c70c503b25cedb3f9617a1f387ac7ea
|
||||
F www/nulls.tcl 38117d24afb81efd079b59723b985a6d654cc2e8
|
||||
F www/omitted.tcl 11037a1b557bd01405092d93dfa08898a4c26cd7
|
||||
F www/opcode.tcl b8d561f33597c62955796b797646f00144d97332
|
||||
F www/quickstart.tcl 4e97bef825e6a4153c43afb9f97235fc4da278ab
|
||||
F www/speed.tcl 19cf0c1bf73c4b534dfafc95b3eacff4825740b4
|
||||
F www/sqlite.tcl b51fd15f0531a54874de785a9efba323eecd5975
|
||||
F www/support.tcl 96c8324cea27b5ded53ff5c60c127ba2053f688e
|
||||
F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25
|
||||
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
|
||||
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
||||
F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3
|
||||
F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
|
||||
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
|
||||
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
|
||||
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
|
||||
P 67370926e374180b2de6e9ab60e5c9ddab4b1317
|
||||
R 11a68bf4bf2e4d26d945a2cfc6fe7c62
|
||||
P 7538d2e5297bdeaf07c6d6e37053c654501ef286
|
||||
R 4b97b7f3ad71d7fa0ea85a53f9d1556a
|
||||
U drh
|
||||
Z d1756bd08569789e6c48078c47ef61ea
|
||||
Z 6e7d236761f1e0f27c9fd9bb6ff1ebec
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
c190b95c30981d2a6026e501e21af675ff8a2d13
|
||||
7d3937743f88acad8859fbbbb1c03271a939bc0b
|
||||
@@ -1,42 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to compile SQLite into a DLL.
|
||||
#
|
||||
# Two separate DLLs are generated. "sqlite3.dll" is the core
|
||||
# library. "tclsqlite3.dll" contains the TCL bindings and is the
|
||||
# library that is loaded into TCL in order to run SQLite.
|
||||
#
|
||||
make target_source
|
||||
cd tsrc
|
||||
PATH=$PATH:/opt/mingw/bin
|
||||
TCLDIR=/home/drh/tcltk/846/win/846win
|
||||
TCLSTUBLIB=$TCLDIR/libtcl84stub.a
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1 -DTHREADSAFE=1'
|
||||
CC="i386-mingw32msvc-gcc -O2 $OPTS -I. -I$TCLDIR"
|
||||
rm shell.c
|
||||
for i in *.c; do
|
||||
CMD="$CC -c $i"
|
||||
echo $CMD
|
||||
$CMD
|
||||
done
|
||||
echo 'EXPORTS' >tclsqlite3.def
|
||||
echo 'Tclsqlite3_Init' >>tclsqlite3.def
|
||||
echo 'Sqlite3_Init' >>tclsqlite3.def
|
||||
i386-mingw32msvc-dllwrap \
|
||||
--def tclsqlite3.def -v --export-all \
|
||||
--driver-name i386-mingw32msvc-gcc \
|
||||
--dlltool-name i386-mingw32msvc-dlltool \
|
||||
--as i386-mingw32msvc-as \
|
||||
--target i386-mingw32 \
|
||||
-dllname tclsqlite3.dll -lmsvcrt *.o $TCLSTUBLIB
|
||||
i386-mingw32msvc-strip tclsqlite3.dll
|
||||
rm tclsqlite.o
|
||||
i386-mingw32msvc-dllwrap \
|
||||
--def sqlite3.def -v --export-all \
|
||||
--driver-name i386-mingw32msvc-gcc \
|
||||
--dlltool-name i386-mingw32msvc-dlltool \
|
||||
--as i386-mingw32msvc-as \
|
||||
--target i386-mingw32 \
|
||||
-dllname sqlite3.dll -lmsvcrt *.o
|
||||
i386-mingw32msvc-strip sqlite3.dll
|
||||
cd ..
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to compile SQLite into a shared library on Linux.
|
||||
#
|
||||
# Two separate shared libraries are generated. "sqlite3.so" is the core
|
||||
# library. "tclsqlite3.so" contains the TCL bindings and is the
|
||||
# library that is loaded into TCL in order to run SQLite.
|
||||
#
|
||||
make target_source
|
||||
cd tsrc
|
||||
rm shell.c
|
||||
TCLDIR=/home/drh/tcltk/846/linux/846linux
|
||||
TCLSTUBLIB=$TCLDIR/libtclstub8.4g.a
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1'
|
||||
for i in *.c; do
|
||||
CMD="cc -fPIC $OPTS -O2 -I. -I$TCLDIR -c $i"
|
||||
echo $CMD
|
||||
$CMD
|
||||
done
|
||||
echo gcc -shared *.o $TCLSTUBLIB -o tclsqlite3.so
|
||||
gcc -shared *.o $TCLSTUBLIB -o tclsqlite3.so
|
||||
strip tclsqlite3.so
|
||||
rm tclsqlite.c tclsqlite.o
|
||||
echo gcc -shared *.o -o sqlite3.so
|
||||
gcc -shared *.o -o sqlite3.so
|
||||
strip sqlite3.so
|
||||
cd ..
|
||||
+134
-45
@@ -16,49 +16,128 @@ srcdir=`echo "$0" | sed 's%\(^.*\)/[^/][^/]*$%\1%'`
|
||||
cp $srcdir/Makefile.linux-gcc ./Makefile
|
||||
chmod +x $srcdir/install-sh
|
||||
|
||||
# Get the current version number - needed to help build filenames
|
||||
#
|
||||
VERS=`cat $srcdir/VERSION`
|
||||
VERSW=`sed 's/\./_/g' $srcdir/VERSION`
|
||||
|
||||
# Start by building an sqlite shell for linux.
|
||||
# Start building stuff.
|
||||
#
|
||||
make clean
|
||||
make sqlite3
|
||||
strip sqlite3
|
||||
mv sqlite3 sqlite3-$VERS.bin
|
||||
gzip sqlite3-$VERS.bin
|
||||
mv sqlite3-$VERS.bin.gz doc
|
||||
make sqlite
|
||||
strip sqlite
|
||||
mv sqlite sqlite.bin
|
||||
rm -f sqlite.bin.gz
|
||||
gzip sqlite.bin
|
||||
|
||||
# Build a source archive useful for windows.
|
||||
# Build the tclsqlite.so shared library for import into tclsh or wish
|
||||
# under Linux
|
||||
#
|
||||
make target_source
|
||||
rm sqlite_source.zip
|
||||
cd tsrc
|
||||
zip ../sqlite_source.zip *
|
||||
rm shell.c
|
||||
TCLDIR=/home/drh/tcltk/8.2linux
|
||||
TCLSTUBLIB=$TCLDIR/libtclstub8.2g.a
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1'
|
||||
gcc -fPIC $OPTS -O2 -I. -I$TCLDIR -shared *.c $TCLSTUBLIB -o tclsqlite.so
|
||||
strip tclsqlite.so
|
||||
mv tclsqlite.so ..
|
||||
rm tclsqlite.c
|
||||
gcc -fPIC -DNDEBUG=1 -O2 -I. -shared *.c -o sqlite.so
|
||||
strip sqlite.so
|
||||
mv sqlite.so ..
|
||||
cd ..
|
||||
rm -f tclsqlite.so.gz sqlite.so.gz
|
||||
gzip tclsqlite.so
|
||||
gzip sqlite.so
|
||||
|
||||
# Build the tclsqlite.dll shared library that can be imported into tclsh
|
||||
# or wish on windows.
|
||||
#
|
||||
make target_source
|
||||
cd tsrc
|
||||
zip ../doc/sqlite-source-$VERSW.zip *
|
||||
cd ..
|
||||
|
||||
# Build the sqlite.so and tclsqlite.so shared libraries
|
||||
# under Linux
|
||||
#
|
||||
. $srcdir/mkso.sh
|
||||
cd tsrc
|
||||
mv tclsqlite3.so tclsqlite-$VERS.so
|
||||
gzip tclsqlite-$VERS.so
|
||||
mv tclsqlite-$VERS.so.gz ../doc
|
||||
mv sqlite3.so sqlite-$VERS.so
|
||||
gzip sqlite-$VERS.so
|
||||
mv sqlite-$VERS.so.gz ../doc
|
||||
cd ..
|
||||
|
||||
# Build the tclsqlite3.dll and sqlite3.dll shared libraries.
|
||||
#
|
||||
. $srcdir/mkdll.sh
|
||||
cd tsrc
|
||||
echo zip ../doc/tclsqlite-$VERSW.zip tclsqlite3.dll
|
||||
zip ../doc/tclsqlite-$VERSW.zip tclsqlite3.dll
|
||||
echo zip ../doc/sqlitedll-$VERSW.zip sqlite3.dll sqlite3.def
|
||||
zip ../doc/sqlitedll-$VERSW.zip sqlite3.dll sqlite3.def
|
||||
rm shell.c
|
||||
TCLDIR=/home/drh/tcltk/8.2win
|
||||
TCLSTUBLIB=$TCLDIR/tclstub82.a
|
||||
PATH=$PATH:/opt/mingw/bin
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1 -DTHREADSAFE=1'
|
||||
CC="i386-mingw32msvc-gcc -O2 $OPTS -I. -I$TCLDIR"
|
||||
rm shell.c
|
||||
for i in *.c; do
|
||||
CMD="$CC -c $i"
|
||||
echo $CMD
|
||||
$CMD
|
||||
done
|
||||
echo 'EXPORTS' >tclsqlite.def
|
||||
echo 'Tclsqlite_Init' >>tclsqlite.def
|
||||
echo 'Sqlite_Init' >>tclsqlite.def
|
||||
i386-mingw32msvc-dllwrap \
|
||||
--def tclsqlite.def -v --export-all \
|
||||
--driver-name i386-mingw32msvc-gcc \
|
||||
--dlltool-name i386-mingw32msvc-dlltool \
|
||||
--as i386-mingw32msvc-as \
|
||||
--target i386-mingw32 \
|
||||
-dllname tclsqlite.dll -lmsvcrt *.o $TCLSTUBLIB
|
||||
i386-mingw32msvc-strip tclsqlite.dll
|
||||
mv tclsqlite.dll ..
|
||||
rm tclsqlite.o
|
||||
cat >sqlite.def <<\END_OF_FILE
|
||||
EXPORTS
|
||||
sqlite_open
|
||||
sqlite_close
|
||||
sqlite_exec
|
||||
sqlite_last_insert_rowid
|
||||
sqlite_error_string
|
||||
sqlite_interrupt
|
||||
sqlite_complete
|
||||
sqlite_busy_handler
|
||||
sqlite_busy_timeout
|
||||
sqlite_get_table
|
||||
sqlite_free_table
|
||||
sqlite_mprintf
|
||||
sqlite_vmprintf
|
||||
sqlite_exec_printf
|
||||
sqlite_exec_vprintf
|
||||
sqlite_get_table_printf
|
||||
sqlite_get_table_vprintf
|
||||
sqlite_freemem
|
||||
sqlite_libversion
|
||||
sqlite_libencoding
|
||||
sqlite_changes
|
||||
sqlite_create_function
|
||||
sqlite_create_aggregate
|
||||
sqlite_function_type
|
||||
sqlite_user_data
|
||||
sqlite_aggregate_context
|
||||
sqlite_aggregate_count
|
||||
sqlite_set_result_string
|
||||
sqlite_set_result_int
|
||||
sqlite_set_result_double
|
||||
sqlite_set_result_error
|
||||
sqliteMalloc
|
||||
sqliteFree
|
||||
sqliteRealloc
|
||||
sqlite_set_authorizer
|
||||
sqlite_trace
|
||||
sqlite_compile
|
||||
sqlite_step
|
||||
sqlite_finalize
|
||||
sqlite_reset
|
||||
sqlite_bind
|
||||
sqlite_last_statement_changes
|
||||
sqlite_encode_binary
|
||||
sqlite_decode_binary
|
||||
END_OF_FILE
|
||||
i386-mingw32msvc-dllwrap \
|
||||
--def sqlite.def -v --export-all \
|
||||
--driver-name i386-mingw32msvc-gcc \
|
||||
--dlltool-name i386-mingw32msvc-dlltool \
|
||||
--as i386-mingw32msvc-as \
|
||||
--target i386-mingw32 \
|
||||
-dllname sqlite.dll -lmsvcrt *.o
|
||||
i386-mingw32msvc-strip sqlite.dll
|
||||
mv sqlite.dll sqlite.def ..
|
||||
cd ..
|
||||
rm -f tclsqlite.zip sqlitedll.zip
|
||||
zip tclsqlite.zip tclsqlite.dll
|
||||
zip sqlitedll.zip sqlite.dll sqlite.def
|
||||
|
||||
# Build the sqlite.exe executable for windows.
|
||||
#
|
||||
@@ -66,18 +145,23 @@ make target_source
|
||||
cd tsrc
|
||||
rm tclsqlite.c
|
||||
OPTS='-DSTATIC_BUILD=1 -DNDEBUG=1'
|
||||
i386-mingw32msvc-gcc -O2 $OPTS -I. -I$TCLDIR *.c -o sqlite3.exe
|
||||
zip ../doc/sqlite-$VERSW.zip sqlite3.exe
|
||||
i386-mingw32msvc-gcc -O2 $OPTS -I. -I$TCLDIR *.c -o sqlite.exe
|
||||
mv sqlite.exe ..
|
||||
cd ..
|
||||
rm -f sqlite.zip
|
||||
zip sqlite.zip sqlite.exe
|
||||
|
||||
# Construct a tarball of the source tree
|
||||
#
|
||||
ORIGIN=`pwd`
|
||||
cd $srcdir
|
||||
cd ..
|
||||
EXCLUDE=`find sqlite -print | grep CVS | sed 's,^, --exclude ,'`
|
||||
tar czf $ORIGIN/doc/sqlite-$VERS.tar.gz $EXCLUDE sqlite
|
||||
EXCLUDE=`find sqlite -print | grep CVS | sed 's,sqlite/, --exclude sqlite/,'`
|
||||
tar czf $ORIGIN/sqlite.tar.gz $EXCLUDE sqlite
|
||||
cd $ORIGIN
|
||||
vers=`cat $srcdir/VERSION`
|
||||
rm -f sqlite-$vers.tar.gz
|
||||
ln sqlite.tar.gz sqlite-$vers.tar.gz
|
||||
|
||||
#
|
||||
# Build RPMS (binary) and Source RPM
|
||||
@@ -95,19 +179,24 @@ mkdir $HOME/rpm/SRPMS
|
||||
mkdir $HOME/rpm/SPECS
|
||||
|
||||
# create the spec file from the template
|
||||
sed s/SQLITE_VERSION/$VERS/g $srcdir/spec.template > $HOME/rpm/SPECS/sqlite.spec
|
||||
sed s/SQLITE_VERSION/$vers/g $srcdir/spec.template > $HOME/rpm/SPECS/sqlite.spec
|
||||
|
||||
# copy the source tarball to the rpm directory
|
||||
cp doc/sqlite-$VERS.tar.gz $HOME/rpm/SOURCES/.
|
||||
cp sqlite-$vers.tar.gz $HOME/rpm/SOURCES/.
|
||||
|
||||
# build all the rpms
|
||||
rpm -ba $HOME/rpm/SPECS/sqlite.spec >& rpm-$vers.log
|
||||
|
||||
# copy the RPMs into the build directory.
|
||||
mv $HOME/rpm/RPMS/i386/sqlite*-$vers*.rpm doc
|
||||
mv $HOME/rpm/SRPMS/sqlite-$vers*.rpm doc
|
||||
ln $HOME/rpm/RPMS/i386/sqlite*-$vers*.rpm .
|
||||
ln $HOME/rpm/SRPMS/sqlite-$vers*.rpm .
|
||||
|
||||
|
||||
# Build the website
|
||||
#
|
||||
#cp $srcdir/../historical/* doc
|
||||
cp $srcdir/../historical/* .
|
||||
rm -rf doc
|
||||
make doc
|
||||
ln sqlite.bin.gz sqlite.zip sqlite*.tar.gz tclsqlite.so.gz tclsqlite.zip doc
|
||||
ln sqlitedll.zip sqlite.so.gz sqlite_source.zip doc
|
||||
ln *.rpm doc
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ rm -fr $RPM_BUILD_ROOT
|
||||
|
||||
%files -n %{name}-devel
|
||||
%defattr(-, root, root)
|
||||
%{_libdir}/pkgconfig/sqlite3.pc
|
||||
%{_libdir}/pkgconfig/sqlite.pc
|
||||
%{_libdir}/*.a
|
||||
%{_libdir}/*.la
|
||||
%{_includedir}/*
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
EXPORTS
|
||||
sqlite_open
|
||||
sqlite_close
|
||||
sqlite_exec
|
||||
sqlite_last_insert_rowid
|
||||
sqlite_error_string
|
||||
sqlite_interrupt
|
||||
sqlite_complete
|
||||
sqlite_busy_handler
|
||||
sqlite_busy_timeout
|
||||
sqlite_get_table
|
||||
sqlite_free_table
|
||||
sqlite_mprintf
|
||||
sqlite_vmprintf
|
||||
sqlite_exec_printf
|
||||
sqlite_exec_vprintf
|
||||
sqlite_get_table_printf
|
||||
sqlite_get_table_vprintf
|
||||
sqlite_freemem
|
||||
sqlite_libversion
|
||||
sqlite_libencoding
|
||||
sqlite_changes
|
||||
sqlite_create_function
|
||||
sqlite_create_aggregate
|
||||
sqlite_function_type
|
||||
sqlite_user_data
|
||||
sqlite_aggregate_context
|
||||
sqlite_aggregate_count
|
||||
sqlite_set_result_string
|
||||
sqlite_set_result_int
|
||||
sqlite_set_result_double
|
||||
sqlite_set_result_error
|
||||
sqliteMalloc
|
||||
sqliteFree
|
||||
sqliteRealloc
|
||||
sqlite_set_authorizer
|
||||
sqlite_trace
|
||||
sqlite_compile
|
||||
sqlite_step
|
||||
sqlite_finalize
|
||||
sqlite_reset
|
||||
sqlite_bind
|
||||
sqlite_last_statement_changes
|
||||
sqlite_encode_binary
|
||||
sqlite_decode_binary
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
EXPORTS
|
||||
sqlite3_aggregate_context
|
||||
sqlite3_aggregate_count
|
||||
sqlite3_bind_blob
|
||||
sqlite3_bind_double
|
||||
sqlite3_bind_int
|
||||
sqlite3_bind_int64
|
||||
sqlite3_bind_null
|
||||
sqlite3_bind_parameter_count
|
||||
sqlite3_bind_text
|
||||
sqlite3_bind_text16
|
||||
sqlite3_busy_handler
|
||||
sqlite3_busy_timeout
|
||||
sqlite3_changes
|
||||
sqlite3_close
|
||||
sqlite3_collation_needed
|
||||
sqlite3_collation_needed16
|
||||
sqlite3_column_blob
|
||||
sqlite3_column_bytes
|
||||
sqlite3_column_bytes16
|
||||
sqlite3_column_count
|
||||
sqlite3_column_decltype
|
||||
sqlite3_column_decltype16
|
||||
sqlite3_column_double
|
||||
sqlite3_column_int
|
||||
sqlite3_column_int64
|
||||
sqlite3_column_name
|
||||
sqlite3_column_name16
|
||||
sqlite3_column_text
|
||||
sqlite3_column_text16
|
||||
sqlite3_column_type
|
||||
sqlite3_commit_hook
|
||||
sqlite3_complete
|
||||
sqlite3_complete16
|
||||
sqlite3_create_collation
|
||||
sqlite3_create_collation16
|
||||
sqlite3_create_function
|
||||
sqlite3_create_function16
|
||||
sqlite3_data_count
|
||||
sqlite3_errcode
|
||||
sqlite3_errmsg
|
||||
sqlite3_errmsg16
|
||||
sqlite3_exec
|
||||
sqlite3_finalize
|
||||
sqlite3_free
|
||||
sqlite3_free_table
|
||||
sqlite3_get_auxdata
|
||||
sqlite3_get_table
|
||||
sqlite3_interrupt
|
||||
sqlite3_last_insert_rowid
|
||||
sqlite3_libversion
|
||||
sqlite3_mprintf
|
||||
sqlite3_open
|
||||
sqlite3_open16
|
||||
sqlite3_prepare
|
||||
sqlite3_prepare16
|
||||
sqlite3_progress_handler
|
||||
sqlite3_reset
|
||||
sqlite3_result_blob
|
||||
sqlite3_result_double
|
||||
sqlite3_result_error
|
||||
sqlite3_result_error16
|
||||
sqlite3_result_int
|
||||
sqlite3_result_int64
|
||||
sqlite3_result_null
|
||||
sqlite3_result_text
|
||||
sqlite3_result_text16
|
||||
sqlite3_result_text16be
|
||||
sqlite3_result_text16le
|
||||
sqlite3_result_value
|
||||
sqlite3_set_authorizer
|
||||
sqlite3_set_auxdata
|
||||
sqlite3_snprintf
|
||||
sqlite3_step
|
||||
sqlite3_total_changes
|
||||
sqlite3_trace
|
||||
sqlite3_user_data
|
||||
sqlite3_value_blob
|
||||
sqlite3_value_bytes
|
||||
sqlite3_value_bytes16
|
||||
sqlite3_value_double
|
||||
sqlite3_value_int
|
||||
sqlite3_value_int64
|
||||
sqlite3_value_text
|
||||
sqlite3_value_text16
|
||||
sqlite3_value_text16be
|
||||
sqlite3_value_text16le
|
||||
sqlite3_value_type
|
||||
sqlite3_vmprintf
|
||||
@@ -1,12 +0,0 @@
|
||||
# Package Information for pkg-config
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: SQLite
|
||||
Description: SQL database engine
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lsqlite3
|
||||
Cflags: -I${includedir}
|
||||
+81
-98
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.26 2004/08/01 03:52:18 drh Exp $
|
||||
** $Id: attach.c,v 1.10.2.1 2004/05/07 01:46:01 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -23,52 +23,48 @@
|
||||
** The pFilename and pDbname arguments are the tokens that define the
|
||||
** filename and dbname in the ATTACH statement.
|
||||
*/
|
||||
void sqlite3Attach(
|
||||
Parse *pParse, /* The parser context */
|
||||
Token *pFilename, /* Name of database file */
|
||||
Token *pDbname, /* Name of the database to use internally */
|
||||
int keyType, /* 0: no key. 1: TEXT, 2: BLOB */
|
||||
Token *pKey /* Text of the key for keytype 2 and 3 */
|
||||
){
|
||||
void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey){
|
||||
Db *aNew;
|
||||
int rc, i;
|
||||
char *zFile, *zName;
|
||||
sqlite *db;
|
||||
Vdbe *v;
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
|
||||
v = sqliteGetVdbe(pParse);
|
||||
sqliteVdbeAddOp(v, OP_Halt, 0, 0);
|
||||
if( pParse->explain ) return;
|
||||
db = pParse->db;
|
||||
if( db->file_format<4 ){
|
||||
sqliteErrorMsg(pParse, "cannot attach auxiliary databases to an "
|
||||
"older format master database", 0);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
if( db->nDb>=MAX_ATTACHED+2 ){
|
||||
sqlite3ErrorMsg(pParse, "too many attached databases - max %d",
|
||||
sqliteErrorMsg(pParse, "too many attached databases - max %d",
|
||||
MAX_ATTACHED);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
if( !db->autoCommit ){
|
||||
sqlite3ErrorMsg(pParse, "cannot ATTACH database within transaction");
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
zFile = sqlite3NameFromToken(pFilename);;
|
||||
zFile = 0;
|
||||
sqliteSetNString(&zFile, pFilename->z, pFilename->n, 0);
|
||||
if( zFile==0 ) return;
|
||||
sqliteDequote(zFile);
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
|
||||
if( sqliteAuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
|
||||
sqliteFree(zFile);
|
||||
return;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
zName = sqlite3NameFromToken(pDbname);
|
||||
zName = 0;
|
||||
sqliteSetNString(&zName, pDbname->z, pDbname->n, 0);
|
||||
if( zName==0 ) return;
|
||||
sqliteDequote(zName);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
char *z = db->aDb[i].zName;
|
||||
if( z && sqlite3StrICmp(z, zName)==0 ){
|
||||
sqlite3ErrorMsg(pParse, "database %z is already in use", zName);
|
||||
if( db->aDb[i].zName && sqliteStrICmp(db->aDb[i].zName, zName)==0 ){
|
||||
sqliteErrorMsg(pParse, "database %z is already in use", zName);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
sqliteFree(zFile);
|
||||
return;
|
||||
@@ -86,62 +82,47 @@ void sqlite3Attach(
|
||||
db->aDb = aNew;
|
||||
aNew = &db->aDb[db->nDb++];
|
||||
memset(aNew, 0, sizeof(*aNew));
|
||||
sqlite3HashInit(&aNew->tblHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&aNew->idxHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);
|
||||
sqliteHashInit(&aNew->tblHash, SQLITE_HASH_STRING, 0);
|
||||
sqliteHashInit(&aNew->idxHash, SQLITE_HASH_STRING, 0);
|
||||
sqliteHashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqliteHashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);
|
||||
aNew->zName = zName;
|
||||
aNew->safety_level = 3;
|
||||
rc = sqlite3BtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
|
||||
rc = sqliteBtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
|
||||
if( rc ){
|
||||
sqlite3ErrorMsg(pParse, "unable to open database: %s", zFile);
|
||||
sqliteErrorMsg(pParse, "unable to open database: %s", zFile);
|
||||
}
|
||||
#if SQLITE_HAS_CODEC
|
||||
{
|
||||
extern int sqlite3CodecAttach(sqlite3*, int, void*, int);
|
||||
char *zKey;
|
||||
extern int sqliteCodecAttach(sqlite*, int, void*, int);
|
||||
char *zKey = 0;
|
||||
int nKey;
|
||||
if( keyType==0 ){
|
||||
/* No key specified. Use the key from the main database */
|
||||
extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
|
||||
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
|
||||
}else if( keyType==1 ){
|
||||
/* Key specified as text */
|
||||
zKey = sqlite3NameFromToken(pKey);
|
||||
if( pKey && pKey->z && pKey->n ){
|
||||
sqliteSetNString(&zKey, pKey->z, pKey->n, 0);
|
||||
sqliteDequote(zKey);
|
||||
nKey = strlen(zKey);
|
||||
}else{
|
||||
/* Key specified as a BLOB */
|
||||
char *zTemp;
|
||||
assert( keyType==2 );
|
||||
pKey->z++;
|
||||
pKey->n--;
|
||||
zTemp = sqlite3NameFromToken(pKey);
|
||||
zKey = sqlite3HexToBlob(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
}
|
||||
sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
if( keyType ){
|
||||
sqliteFree(zKey);
|
||||
zKey = 0;
|
||||
nKey = 0;
|
||||
}
|
||||
sqliteCodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
}
|
||||
#endif
|
||||
sqliteFree(zFile);
|
||||
db->flags &= ~SQLITE_Initialized;
|
||||
if( pParse->nErr==0 && rc==SQLITE_OK ){
|
||||
rc = sqlite3ReadSchema(pParse);
|
||||
if( pParse->nErr ) return;
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqliteInit(pParse->db, &pParse->zErrMsg);
|
||||
}
|
||||
if( rc ){
|
||||
int i = db->nDb - 1;
|
||||
assert( i>=2 );
|
||||
if( db->aDb[i].pBt ){
|
||||
sqlite3BtreeClose(db->aDb[i].pBt);
|
||||
sqliteBtreeClose(db->aDb[i].pBt);
|
||||
db->aDb[i].pBt = 0;
|
||||
}
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
if( 0==pParse->nErr ){
|
||||
pParse->nErr++;
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
sqliteResetInternalSchema(db, 0);
|
||||
pParse->nErr++;
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,44 +133,46 @@ void sqlite3Attach(
|
||||
**
|
||||
** The pDbname argument is the name of the database in the DETACH statement.
|
||||
*/
|
||||
void sqlite3Detach(Parse *pParse, Token *pDbname){
|
||||
void sqliteDetach(Parse *pParse, Token *pDbname){
|
||||
int i;
|
||||
sqlite *db;
|
||||
Vdbe *v;
|
||||
Db *pDb = 0;
|
||||
Db *pDb;
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
|
||||
v = sqliteGetVdbe(pParse);
|
||||
sqliteVdbeAddOp(v, OP_Halt, 0, 0);
|
||||
if( pParse->explain ) return;
|
||||
db = pParse->db;
|
||||
for(i=0; i<db->nDb; i++){
|
||||
pDb = &db->aDb[i];
|
||||
if( pDb->pBt==0 || pDb->zName==0 ) continue;
|
||||
if( strlen(pDb->zName)!=pDbname->n ) continue;
|
||||
if( sqlite3StrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break;
|
||||
if( sqliteStrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break;
|
||||
}
|
||||
if( i>=db->nDb ){
|
||||
sqlite3ErrorMsg(pParse, "no such database: %T", pDbname);
|
||||
sqliteErrorMsg(pParse, "no such database: %T", pDbname);
|
||||
return;
|
||||
}
|
||||
if( i<2 ){
|
||||
sqlite3ErrorMsg(pParse, "cannot detach database %T", pDbname);
|
||||
return;
|
||||
}
|
||||
if( !db->autoCommit ){
|
||||
sqlite3ErrorMsg(pParse, "cannot DETACH database within transaction");
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
sqliteErrorMsg(pParse, "cannot detach database %T", pDbname);
|
||||
return;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqlite3AuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){
|
||||
if( sqliteAuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){
|
||||
return;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
sqlite3BtreeClose(pDb->pBt);
|
||||
sqliteBtreeClose(pDb->pBt);
|
||||
pDb->pBt = 0;
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
sqliteFree(pDb->zName);
|
||||
sqliteResetInternalSchema(db, i);
|
||||
if( pDb->pAux && pDb->xFreeAux ) pDb->xFreeAux(pDb->pAux);
|
||||
db->nDb--;
|
||||
if( i<db->nDb ){
|
||||
db->aDb[i] = db->aDb[db->nDb];
|
||||
memset(&db->aDb[db->nDb], 0, sizeof(db->aDb[0]));
|
||||
sqliteResetInternalSchema(db, i);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -199,7 +182,7 @@ void sqlite3Detach(Parse *pParse, Token *pDbname){
|
||||
** The return value indicates whether or not fixation is required. TRUE
|
||||
** means we do need to fix the database references, FALSE means we do not.
|
||||
*/
|
||||
int sqlite3FixInit(
|
||||
int sqliteFixInit(
|
||||
DbFixer *pFix, /* The fixer to be initialized */
|
||||
Parse *pParse, /* Error messages will be written here */
|
||||
int iDb, /* This is the database that must must be used */
|
||||
@@ -222,7 +205,7 @@ int sqlite3FixInit(
|
||||
** The following set of routines walk through the parse tree and assign
|
||||
** a specific database to all table references where the database name
|
||||
** was left unspecified in the original SQL statement. The pFix structure
|
||||
** must have been initialized by a prior call to sqlite3FixInit().
|
||||
** must have been initialized by a prior call to sqliteFixInit().
|
||||
**
|
||||
** These routines are used to make sure that an index, trigger, or
|
||||
** view in one database does not refer to objects in a different database.
|
||||
@@ -232,7 +215,7 @@ int sqlite3FixInit(
|
||||
** pParse->zErrMsg and these routines return non-zero. If everything
|
||||
** checks out, these routines return 0.
|
||||
*/
|
||||
int sqlite3FixSrcList(
|
||||
int sqliteFixSrcList(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
SrcList *pList /* The Source list to check and modify */
|
||||
){
|
||||
@@ -244,82 +227,82 @@ int sqlite3FixSrcList(
|
||||
for(i=0; i<pList->nSrc; i++){
|
||||
if( pList->a[i].zDatabase==0 ){
|
||||
pList->a[i].zDatabase = sqliteStrDup(zDb);
|
||||
}else if( sqlite3StrICmp(pList->a[i].zDatabase,zDb)!=0 ){
|
||||
sqlite3ErrorMsg(pFix->pParse,
|
||||
}else if( sqliteStrICmp(pList->a[i].zDatabase,zDb)!=0 ){
|
||||
sqliteErrorMsg(pFix->pParse,
|
||||
"%s %z cannot reference objects in database %s",
|
||||
pFix->zType, sqliteStrNDup(pFix->pName->z, pFix->pName->n),
|
||||
pList->a[i].zDatabase);
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixSelect(pFix, pList->a[i].pSelect) ) return 1;
|
||||
if( sqlite3FixExpr(pFix, pList->a[i].pOn) ) return 1;
|
||||
if( sqliteFixSelect(pFix, pList->a[i].pSelect) ) return 1;
|
||||
if( sqliteFixExpr(pFix, pList->a[i].pOn) ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqlite3FixSelect(
|
||||
int sqliteFixSelect(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
Select *pSelect /* The SELECT statement to be fixed to one database */
|
||||
){
|
||||
while( pSelect ){
|
||||
if( sqlite3FixExprList(pFix, pSelect->pEList) ){
|
||||
if( sqliteFixExprList(pFix, pSelect->pEList) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixSrcList(pFix, pSelect->pSrc) ){
|
||||
if( sqliteFixSrcList(pFix, pSelect->pSrc) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExpr(pFix, pSelect->pWhere) ){
|
||||
if( sqliteFixExpr(pFix, pSelect->pWhere) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExpr(pFix, pSelect->pHaving) ){
|
||||
if( sqliteFixExpr(pFix, pSelect->pHaving) ){
|
||||
return 1;
|
||||
}
|
||||
pSelect = pSelect->pPrior;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqlite3FixExpr(
|
||||
int sqliteFixExpr(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
Expr *pExpr /* The expression to be fixed to one database */
|
||||
){
|
||||
while( pExpr ){
|
||||
if( sqlite3FixSelect(pFix, pExpr->pSelect) ){
|
||||
if( sqliteFixSelect(pFix, pExpr->pSelect) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExprList(pFix, pExpr->pList) ){
|
||||
if( sqliteFixExprList(pFix, pExpr->pList) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExpr(pFix, pExpr->pRight) ){
|
||||
if( sqliteFixExpr(pFix, pExpr->pRight) ){
|
||||
return 1;
|
||||
}
|
||||
pExpr = pExpr->pLeft;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqlite3FixExprList(
|
||||
int sqliteFixExprList(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
ExprList *pList /* The expression to be fixed to one database */
|
||||
){
|
||||
int i;
|
||||
if( pList==0 ) return 0;
|
||||
for(i=0; i<pList->nExpr; i++){
|
||||
if( sqlite3FixExpr(pFix, pList->a[i].pExpr) ){
|
||||
if( sqliteFixExpr(pFix, pList->a[i].pExpr) ){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqlite3FixTriggerStep(
|
||||
int sqliteFixTriggerStep(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
TriggerStep *pStep /* The trigger step be fixed to one database */
|
||||
){
|
||||
while( pStep ){
|
||||
if( sqlite3FixSelect(pFix, pStep->pSelect) ){
|
||||
if( sqliteFixSelect(pFix, pStep->pSelect) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExpr(pFix, pStep->pWhere) ){
|
||||
if( sqliteFixExpr(pFix, pStep->pWhere) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExprList(pFix, pStep->pExprList) ){
|
||||
if( sqliteFixExprList(pFix, pStep->pExprList) ){
|
||||
return 1;
|
||||
}
|
||||
pStep = pStep->pNext;
|
||||
|
||||
+14
-18
@@ -9,12 +9,12 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the sqlite3_set_authorizer()
|
||||
** This file contains code used to implement the sqlite_set_authorizer()
|
||||
** API. This facility is an optional feature of the library. Embedded
|
||||
** systems that do not need this facility may omit it by recompiling
|
||||
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
|
||||
**
|
||||
** $Id: auth.c,v 1.16 2004/06/19 16:06:11 drh Exp $
|
||||
** $Id: auth.c,v 1.12 2004/02/22 18:40:57 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
** is a copy of the 3rd argument to this routine. The second argument
|
||||
** to the auth function is one of these constants:
|
||||
**
|
||||
** SQLITE_COPY
|
||||
** SQLITE_CREATE_INDEX
|
||||
** SQLITE_CREATE_TABLE
|
||||
** SQLITE_CREATE_TEMP_INDEX
|
||||
@@ -61,7 +62,7 @@
|
||||
** the table and the column that are being accessed. The auth function
|
||||
** should return either SQLITE_OK, SQLITE_DENY, or SQLITE_IGNORE. If
|
||||
** SQLITE_OK is returned, it means that access is allowed. SQLITE_DENY
|
||||
** means that the SQL statement will never-run - the sqlite3_exec() call
|
||||
** means that the SQL statement will never-run - the sqlite_exec() call
|
||||
** will return with an error. SQLITE_IGNORE means that the SQL statement
|
||||
** should run but attempts to read the specified column will return NULL
|
||||
** and attempts to write the column will be ignored.
|
||||
@@ -69,7 +70,7 @@
|
||||
** Setting the auth function to NULL disables this hook. The default
|
||||
** setting of the auth function is NULL.
|
||||
*/
|
||||
int sqlite3_set_authorizer(
|
||||
int sqlite_set_authorizer(
|
||||
sqlite *db,
|
||||
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
|
||||
void *pArg
|
||||
@@ -84,7 +85,7 @@ int sqlite3_set_authorizer(
|
||||
** user-supplied authorization function returned an illegal value.
|
||||
*/
|
||||
static void sqliteAuthBadReturnCode(Parse *pParse, int rc){
|
||||
sqlite3ErrorMsg(pParse, "illegal return value (%d) from the "
|
||||
sqliteErrorMsg(pParse, "illegal return value (%d) from the "
|
||||
"authorization function - should be SQLITE_OK, SQLITE_IGNORE, "
|
||||
"or SQLITE_DENY", rc);
|
||||
pParse->rc = SQLITE_MISUSE;
|
||||
@@ -99,7 +100,7 @@ static void sqliteAuthBadReturnCode(Parse *pParse, int rc){
|
||||
** instruction into a TK_NULL. If the auth function returns SQLITE_DENY,
|
||||
** then generate an error.
|
||||
*/
|
||||
void sqlite3AuthRead(
|
||||
void sqliteAuthRead(
|
||||
Parse *pParse, /* The parser context */
|
||||
Expr *pExpr, /* The expression to check authorization on */
|
||||
SrcList *pTabList /* All table that pExpr might refer to */
|
||||
@@ -146,10 +147,10 @@ void sqlite3AuthRead(
|
||||
pExpr->op = TK_NULL;
|
||||
}else if( rc==SQLITE_DENY ){
|
||||
if( db->nDb>2 || pExpr->iDb!=0 ){
|
||||
sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",
|
||||
sqliteErrorMsg(pParse, "access to %s.%s.%s is prohibited",
|
||||
zDBase, pTab->zName, zCol);
|
||||
}else{
|
||||
sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited",pTab->zName,zCol);
|
||||
sqliteErrorMsg(pParse, "access to %s.%s is prohibited", pTab->zName,zCol);
|
||||
}
|
||||
pParse->rc = SQLITE_AUTH;
|
||||
}else if( rc!=SQLITE_OK ){
|
||||
@@ -163,7 +164,7 @@ void sqlite3AuthRead(
|
||||
** is returned, then the error count and error message in pParse are
|
||||
** modified appropriately.
|
||||
*/
|
||||
int sqlite3AuthCheck(
|
||||
int sqliteAuthCheck(
|
||||
Parse *pParse,
|
||||
int code,
|
||||
const char *zArg1,
|
||||
@@ -173,17 +174,12 @@ int sqlite3AuthCheck(
|
||||
sqlite *db = pParse->db;
|
||||
int rc;
|
||||
|
||||
/* Don't do any authorization checks if the database is initialising. */
|
||||
if( db->init.busy ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
if( db->xAuth==0 ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
|
||||
if( rc==SQLITE_DENY ){
|
||||
sqlite3ErrorMsg(pParse, "not authorized");
|
||||
sqliteErrorMsg(pParse, "not authorized");
|
||||
pParse->rc = SQLITE_AUTH;
|
||||
}else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
|
||||
rc = SQLITE_DENY;
|
||||
@@ -197,7 +193,7 @@ int sqlite3AuthCheck(
|
||||
** zArg3 argument to authorization callbacks will be zContext until
|
||||
** popped. Or if pParse==0, this routine is a no-op.
|
||||
*/
|
||||
void sqlite3AuthContextPush(
|
||||
void sqliteAuthContextPush(
|
||||
Parse *pParse,
|
||||
AuthContext *pContext,
|
||||
const char *zContext
|
||||
@@ -211,9 +207,9 @@ void sqlite3AuthContextPush(
|
||||
|
||||
/*
|
||||
** Pop an authorization context that was previously pushed
|
||||
** by sqlite3AuthContextPush
|
||||
** by sqliteAuthContextPush
|
||||
*/
|
||||
void sqlite3AuthContextPop(AuthContext *pContext){
|
||||
void sqliteAuthContextPop(AuthContext *pContext){
|
||||
if( pContext->pParse ){
|
||||
pContext->pParse->zAuthContext = pContext->zAuthContext;
|
||||
pContext->pParse = 0;
|
||||
|
||||
+1931
-2757
File diff suppressed because it is too large
Load Diff
+118
-86
@@ -13,112 +13,144 @@
|
||||
** subsystem. See comments in the source code for a detailed description
|
||||
** of what each interface routine does.
|
||||
**
|
||||
** @(#) $Id: btree.h,v 1.58 2004/07/23 00:01:39 drh Exp $
|
||||
** @(#) $Id: btree.h,v 1.36 2004/02/10 02:57:59 drh Exp $
|
||||
*/
|
||||
#ifndef _BTREE_H_
|
||||
#define _BTREE_H_
|
||||
|
||||
/* TODO: This definition is just included so other modules compile. It
|
||||
** needs to be revisited.
|
||||
*/
|
||||
#define SQLITE_N_BTREE_META 10
|
||||
|
||||
/*
|
||||
** Forward declarations of structure
|
||||
*/
|
||||
typedef struct Btree Btree;
|
||||
typedef struct BtCursor BtCursor;
|
||||
typedef struct BtOps BtOps;
|
||||
typedef struct BtCursorOps BtCursorOps;
|
||||
|
||||
|
||||
int sqlite3BtreeOpen(
|
||||
const char *zFilename, /* Name of database file to open */
|
||||
Btree **, /* Return open Btree* here */
|
||||
int flags /* Flags */
|
||||
);
|
||||
|
||||
/* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
|
||||
** following values.
|
||||
/*
|
||||
** An instance of the following structure contains pointers to all
|
||||
** methods against an open BTree. Alternative BTree implementations
|
||||
** (examples: file based versus in-memory) can be created by substituting
|
||||
** different methods. Users of the BTree cannot tell the difference.
|
||||
**
|
||||
** In C++ we could do this by defining a virtual base class and then
|
||||
** creating subclasses for each different implementation. But this is
|
||||
** C not C++ so we have to be a little more explicit.
|
||||
*/
|
||||
#define BTREE_OMIT_JOURNAL 1 /* Do not use journal. No argument */
|
||||
#define BTREE_MEMORY 2 /* In-memory DB. No argument */
|
||||
struct BtOps {
|
||||
int (*Close)(Btree*);
|
||||
int (*SetCacheSize)(Btree*, int);
|
||||
int (*SetSafetyLevel)(Btree*, int);
|
||||
int (*BeginTrans)(Btree*);
|
||||
int (*Commit)(Btree*);
|
||||
int (*Rollback)(Btree*);
|
||||
int (*BeginCkpt)(Btree*);
|
||||
int (*CommitCkpt)(Btree*);
|
||||
int (*RollbackCkpt)(Btree*);
|
||||
int (*CreateTable)(Btree*, int*);
|
||||
int (*CreateIndex)(Btree*, int*);
|
||||
int (*DropTable)(Btree*, int);
|
||||
int (*ClearTable)(Btree*, int);
|
||||
int (*Cursor)(Btree*, int iTable, int wrFlag, BtCursor **ppCur);
|
||||
int (*GetMeta)(Btree*, int*);
|
||||
int (*UpdateMeta)(Btree*, int*);
|
||||
char *(*IntegrityCheck)(Btree*, int*, int);
|
||||
const char *(*GetFilename)(Btree*);
|
||||
int (*Copyfile)(Btree*,Btree*);
|
||||
struct Pager *(*Pager)(Btree*);
|
||||
#ifdef SQLITE_TEST
|
||||
int (*PageDump)(Btree*, int, int);
|
||||
#endif
|
||||
};
|
||||
|
||||
int sqlite3BtreeClose(Btree*);
|
||||
int sqlite3BtreeSetBusyHandler(Btree*,BusyHandler*);
|
||||
int sqlite3BtreeSetCacheSize(Btree*,int);
|
||||
int sqlite3BtreeSetSafetyLevel(Btree*,int);
|
||||
int sqlite3BtreeSetPageSize(Btree*,int,int);
|
||||
int sqlite3BtreeGetPageSize(Btree*);
|
||||
int sqlite3BtreeGetReserve(Btree*);
|
||||
int sqlite3BtreeBeginTrans(Btree*,int);
|
||||
int sqlite3BtreeCommit(Btree*);
|
||||
int sqlite3BtreeRollback(Btree*);
|
||||
int sqlite3BtreeBeginStmt(Btree*);
|
||||
int sqlite3BtreeCommitStmt(Btree*);
|
||||
int sqlite3BtreeRollbackStmt(Btree*);
|
||||
int sqlite3BtreeCreateTable(Btree*, int*, int flags);
|
||||
int sqlite3BtreeIsInTrans(Btree*);
|
||||
int sqlite3BtreeIsInStmt(Btree*);
|
||||
int sqlite3BtreeSync(Btree*, const char *zMaster);
|
||||
|
||||
const char *sqlite3BtreeGetFilename(Btree *);
|
||||
const char *sqlite3BtreeGetDirname(Btree *);
|
||||
const char *sqlite3BtreeGetJournalname(Btree *);
|
||||
int sqlite3BtreeCopyFile(Btree *, Btree *);
|
||||
|
||||
/* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
|
||||
** of the following flags:
|
||||
/*
|
||||
** An instance of this structure defines all of the methods that can
|
||||
** be executed against a cursor.
|
||||
*/
|
||||
#define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
|
||||
#define BTREE_ZERODATA 2 /* Table has keys only - no data */
|
||||
#define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */
|
||||
struct BtCursorOps {
|
||||
int (*Moveto)(BtCursor*, const void *pKey, int nKey, int *pRes);
|
||||
int (*Delete)(BtCursor*);
|
||||
int (*Insert)(BtCursor*, const void *pKey, int nKey,
|
||||
const void *pData, int nData);
|
||||
int (*First)(BtCursor*, int *pRes);
|
||||
int (*Last)(BtCursor*, int *pRes);
|
||||
int (*Next)(BtCursor*, int *pRes);
|
||||
int (*Previous)(BtCursor*, int *pRes);
|
||||
int (*KeySize)(BtCursor*, int *pSize);
|
||||
int (*Key)(BtCursor*, int offset, int amt, char *zBuf);
|
||||
int (*KeyCompare)(BtCursor*, const void *pKey, int nKey,
|
||||
int nIgnore, int *pRes);
|
||||
int (*DataSize)(BtCursor*, int *pSize);
|
||||
int (*Data)(BtCursor*, int offset, int amt, char *zBuf);
|
||||
int (*CloseCursor)(BtCursor*);
|
||||
#ifdef SQLITE_TEST
|
||||
int (*CursorDump)(BtCursor*, int*);
|
||||
#endif
|
||||
};
|
||||
|
||||
int sqlite3BtreeDropTable(Btree*, int);
|
||||
int sqlite3BtreeClearTable(Btree*, int);
|
||||
int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
|
||||
int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
|
||||
/*
|
||||
** The number of 4-byte "meta" values contained on the first page of each
|
||||
** database file.
|
||||
*/
|
||||
#define SQLITE_N_BTREE_META 10
|
||||
|
||||
int sqlite3BtreeCursor(
|
||||
Btree*, /* BTree containing table to open */
|
||||
int iTable, /* Index of root page */
|
||||
int wrFlag, /* 1 for writing. 0 for read-only */
|
||||
int(*)(void*,int,const void*,int,const void*), /* Key comparison function */
|
||||
void*, /* First argument to compare function */
|
||||
BtCursor **ppCursor /* Returned cursor */
|
||||
);
|
||||
int sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
|
||||
int sqliteRbtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
|
||||
|
||||
void sqlite3BtreeSetCompare(
|
||||
BtCursor *,
|
||||
int(*)(void*,int,const void*,int,const void*),
|
||||
void*
|
||||
);
|
||||
|
||||
int sqlite3BtreeCloseCursor(BtCursor*);
|
||||
int sqlite3BtreeMoveto(BtCursor*, const void *pKey, i64 nKey, int *pRes);
|
||||
int sqlite3BtreeDelete(BtCursor*);
|
||||
int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
|
||||
const void *pData, int nData);
|
||||
int sqlite3BtreeFirst(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeLast(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeNext(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeEof(BtCursor*);
|
||||
int sqlite3BtreeFlags(BtCursor*);
|
||||
int sqlite3BtreePrevious(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
|
||||
int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
|
||||
const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
|
||||
const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
|
||||
int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
|
||||
int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
|
||||
|
||||
char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot);
|
||||
struct Pager *sqlite3BtreePager(Btree*);
|
||||
#define btOps(pBt) (*((BtOps **)(pBt)))
|
||||
#define btCOps(pCur) (*((BtCursorOps **)(pCur)))
|
||||
|
||||
#define sqliteBtreeClose(pBt) (btOps(pBt)->Close(pBt))
|
||||
#define sqliteBtreeSetCacheSize(pBt, sz) (btOps(pBt)->SetCacheSize(pBt, sz))
|
||||
#define sqliteBtreeSetSafetyLevel(pBt, sl) (btOps(pBt)->SetSafetyLevel(pBt, sl))
|
||||
#define sqliteBtreeBeginTrans(pBt) (btOps(pBt)->BeginTrans(pBt))
|
||||
#define sqliteBtreeCommit(pBt) (btOps(pBt)->Commit(pBt))
|
||||
#define sqliteBtreeRollback(pBt) (btOps(pBt)->Rollback(pBt))
|
||||
#define sqliteBtreeBeginCkpt(pBt) (btOps(pBt)->BeginCkpt(pBt))
|
||||
#define sqliteBtreeCommitCkpt(pBt) (btOps(pBt)->CommitCkpt(pBt))
|
||||
#define sqliteBtreeRollbackCkpt(pBt) (btOps(pBt)->RollbackCkpt(pBt))
|
||||
#define sqliteBtreeCreateTable(pBt,piTable)\
|
||||
(btOps(pBt)->CreateTable(pBt,piTable))
|
||||
#define sqliteBtreeCreateIndex(pBt, piIndex)\
|
||||
(btOps(pBt)->CreateIndex(pBt, piIndex))
|
||||
#define sqliteBtreeDropTable(pBt, iTable) (btOps(pBt)->DropTable(pBt, iTable))
|
||||
#define sqliteBtreeClearTable(pBt, iTable)\
|
||||
(btOps(pBt)->ClearTable(pBt, iTable))
|
||||
#define sqliteBtreeCursor(pBt, iTable, wrFlag, ppCur)\
|
||||
(btOps(pBt)->Cursor(pBt, iTable, wrFlag, ppCur))
|
||||
#define sqliteBtreeMoveto(pCur, pKey, nKey, pRes)\
|
||||
(btCOps(pCur)->Moveto(pCur, pKey, nKey, pRes))
|
||||
#define sqliteBtreeDelete(pCur) (btCOps(pCur)->Delete(pCur))
|
||||
#define sqliteBtreeInsert(pCur, pKey, nKey, pData, nData) \
|
||||
(btCOps(pCur)->Insert(pCur, pKey, nKey, pData, nData))
|
||||
#define sqliteBtreeFirst(pCur, pRes) (btCOps(pCur)->First(pCur, pRes))
|
||||
#define sqliteBtreeLast(pCur, pRes) (btCOps(pCur)->Last(pCur, pRes))
|
||||
#define sqliteBtreeNext(pCur, pRes) (btCOps(pCur)->Next(pCur, pRes))
|
||||
#define sqliteBtreePrevious(pCur, pRes) (btCOps(pCur)->Previous(pCur, pRes))
|
||||
#define sqliteBtreeKeySize(pCur, pSize) (btCOps(pCur)->KeySize(pCur, pSize) )
|
||||
#define sqliteBtreeKey(pCur, offset, amt, zBuf)\
|
||||
(btCOps(pCur)->Key(pCur, offset, amt, zBuf))
|
||||
#define sqliteBtreeKeyCompare(pCur, pKey, nKey, nIgnore, pRes)\
|
||||
(btCOps(pCur)->KeyCompare(pCur, pKey, nKey, nIgnore, pRes))
|
||||
#define sqliteBtreeDataSize(pCur, pSize) (btCOps(pCur)->DataSize(pCur, pSize))
|
||||
#define sqliteBtreeData(pCur, offset, amt, zBuf)\
|
||||
(btCOps(pCur)->Data(pCur, offset, amt, zBuf))
|
||||
#define sqliteBtreeCloseCursor(pCur) (btCOps(pCur)->CloseCursor(pCur))
|
||||
#define sqliteBtreeGetMeta(pBt, aMeta) (btOps(pBt)->GetMeta(pBt, aMeta))
|
||||
#define sqliteBtreeUpdateMeta(pBt, aMeta) (btOps(pBt)->UpdateMeta(pBt, aMeta))
|
||||
#define sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot)\
|
||||
(btOps(pBt)->IntegrityCheck(pBt, aRoot, nRoot))
|
||||
#define sqliteBtreeGetFilename(pBt) (btOps(pBt)->GetFilename(pBt))
|
||||
#define sqliteBtreeCopyFile(pBt1, pBt2) (btOps(pBt1)->Copyfile(pBt1, pBt2))
|
||||
#define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt))
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
|
||||
void sqlite3BtreeCursorList(Btree*);
|
||||
int sqlite3BtreePageDump(Btree*, int, int recursive);
|
||||
#endif
|
||||
#define sqliteBtreePageDump(pBt, pgno, recursive)\
|
||||
(btOps(pBt)->PageDump(pBt, pgno, recursive))
|
||||
#define sqliteBtreeCursorDump(pCur, aResult)\
|
||||
(btCOps(pCur)->CursorDump(pCur, aResult))
|
||||
int btree_native_byte_order;
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
|
||||
#endif /* _BTREE_H_ */
|
||||
|
||||
+1488
File diff suppressed because it is too large
Load Diff
+791
-1219
File diff suppressed because it is too large
Load Diff
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
** 2003 April 6
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the COPY command.
|
||||
**
|
||||
** $Id: copy.c,v 1.9 2004/02/25 13:47:31 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** The COPY command is for compatibility with PostgreSQL and specificially
|
||||
** for the ability to read the output of pg_dump. The format is as
|
||||
** follows:
|
||||
**
|
||||
** COPY table FROM file [USING DELIMITERS string]
|
||||
**
|
||||
** "table" is an existing table name. We will read lines of code from
|
||||
** file to fill this table with data. File might be "stdin". The optional
|
||||
** delimiter string identifies the field separators. The default is a tab.
|
||||
*/
|
||||
void sqliteCopy(
|
||||
Parse *pParse, /* The parser context */
|
||||
SrcList *pTableName, /* The name of the table into which we will insert */
|
||||
Token *pFilename, /* The file from which to obtain information */
|
||||
Token *pDelimiter, /* Use this as the field delimiter */
|
||||
int onError /* What to do if a constraint fails */
|
||||
){
|
||||
Table *pTab;
|
||||
int i;
|
||||
Vdbe *v;
|
||||
int addr, end;
|
||||
char *zFile = 0;
|
||||
const char *zDb;
|
||||
sqlite *db = pParse->db;
|
||||
|
||||
|
||||
if( sqlite_malloc_failed ) goto copy_cleanup;
|
||||
assert( pTableName->nSrc==1 );
|
||||
pTab = sqliteSrcListLookup(pParse, pTableName);
|
||||
if( pTab==0 || sqliteIsReadOnly(pParse, pTab, 0) ) goto copy_cleanup;
|
||||
zFile = sqliteStrNDup(pFilename->z, pFilename->n);
|
||||
sqliteDequote(zFile);
|
||||
assert( pTab->iDb<db->nDb );
|
||||
zDb = db->aDb[pTab->iDb].zName;
|
||||
if( sqliteAuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb)
|
||||
|| sqliteAuthCheck(pParse, SQLITE_COPY, pTab->zName, zFile, zDb) ){
|
||||
goto copy_cleanup;
|
||||
}
|
||||
v = sqliteGetVdbe(pParse);
|
||||
if( v ){
|
||||
sqliteBeginWriteOperation(pParse, 1, pTab->iDb);
|
||||
addr = sqliteVdbeOp3(v, OP_FileOpen, 0, 0, pFilename->z, pFilename->n);
|
||||
sqliteVdbeDequoteP3(v, addr);
|
||||
sqliteOpenTableAndIndices(pParse, pTab, 0);
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0); /* Initialize the row count */
|
||||
}
|
||||
end = sqliteVdbeMakeLabel(v);
|
||||
addr = sqliteVdbeAddOp(v, OP_FileRead, pTab->nCol, end);
|
||||
if( pDelimiter ){
|
||||
sqliteVdbeChangeP3(v, addr, pDelimiter->z, pDelimiter->n);
|
||||
sqliteVdbeDequoteP3(v, addr);
|
||||
}else{
|
||||
sqliteVdbeChangeP3(v, addr, "\t", 1);
|
||||
}
|
||||
if( pTab->iPKey>=0 ){
|
||||
sqliteVdbeAddOp(v, OP_FileColumn, pTab->iPKey, 0);
|
||||
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_NewRecno, 0, 0);
|
||||
}
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
/* The integer primary key column is filled with NULL since its
|
||||
** value is always pulled from the record number */
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_FileColumn, i, 0);
|
||||
}
|
||||
}
|
||||
sqliteGenerateConstraintChecks(pParse, pTab, 0, 0, pTab->iPKey>=0,
|
||||
0, onError, addr);
|
||||
sqliteCompleteInsertion(pParse, pTab, 0, 0, 0, 0, -1);
|
||||
if( (db->flags & SQLITE_CountRows)!=0 ){
|
||||
sqliteVdbeAddOp(v, OP_AddImm, 1, 0); /* Increment row count */
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqliteVdbeResolveLabel(v, end);
|
||||
sqliteVdbeAddOp(v, OP_Noop, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
|
||||
sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
copy_cleanup:
|
||||
sqliteSrcListDelete(pTableName);
|
||||
sqliteFree(zFile);
|
||||
return;
|
||||
}
|
||||
+52
-72
@@ -13,10 +13,10 @@
|
||||
** functions for SQLite.
|
||||
**
|
||||
** There is only one exported symbol in this file - the function
|
||||
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
|
||||
** sqliteRegisterDateTimeFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: date.c,v 1.34 2004/08/17 10:42:55 drh Exp $
|
||||
** $Id: date.c,v 1.16 2004/02/29 01:08:18 drh Exp $
|
||||
**
|
||||
** NOTES:
|
||||
**
|
||||
@@ -104,7 +104,7 @@ static int getDigits(const char *zDate, ...){
|
||||
pVal = va_arg(ap, int*);
|
||||
val = 0;
|
||||
while( N-- ){
|
||||
if( !isdigit(*(u8*)zDate) ){
|
||||
if( !isdigit(*zDate) ){
|
||||
return cnt;
|
||||
}
|
||||
val = val*10 + *zDate - '0';
|
||||
@@ -126,7 +126,7 @@ static int getDigits(const char *zDate, ...){
|
||||
*/
|
||||
static int getValue(const char *z, double *pR){
|
||||
const char *zEnd;
|
||||
*pR = sqlite3AtoF(z, &zEnd);
|
||||
*pR = sqliteAtoF(z, &zEnd);
|
||||
return zEnd - z;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ static int getValue(const char *z, double *pR){
|
||||
static int parseTimezone(const char *zDate, DateTime *p){
|
||||
int sgn = 0;
|
||||
int nHr, nMn;
|
||||
while( isspace(*(u8*)zDate) ){ zDate++; }
|
||||
while( isspace(*zDate) ){ zDate++; }
|
||||
p->tz = 0;
|
||||
if( *zDate=='-' ){
|
||||
sgn = -1;
|
||||
@@ -160,7 +160,7 @@ static int parseTimezone(const char *zDate, DateTime *p){
|
||||
}
|
||||
zDate += 5;
|
||||
p->tz = sgn*(nMn + nHr*60);
|
||||
while( isspace(*(u8*)zDate) ){ zDate++; }
|
||||
while( isspace(*zDate) ){ zDate++; }
|
||||
return *zDate!=0;
|
||||
}
|
||||
|
||||
@@ -184,10 +184,10 @@ static int parseHhMmSs(const char *zDate, DateTime *p){
|
||||
return 1;
|
||||
}
|
||||
zDate += 2;
|
||||
if( *zDate=='.' && isdigit((u8)zDate[1]) ){
|
||||
if( *zDate=='.' && isdigit(zDate[1]) ){
|
||||
double rScale = 1.0;
|
||||
zDate++;
|
||||
while( isdigit(*(u8*)zDate) ){
|
||||
while( isdigit(*zDate) ){
|
||||
ms = ms*10.0 + *zDate - '0';
|
||||
rScale *= 10.0;
|
||||
zDate++;
|
||||
@@ -272,7 +272,7 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
||||
return 1;
|
||||
}
|
||||
zDate += 10;
|
||||
while( isspace(*(u8*)zDate) ){ zDate++; }
|
||||
while( isspace(*zDate) ){ zDate++; }
|
||||
if( parseHhMmSs(zDate, p)==0 ){
|
||||
/* We got the time */
|
||||
}else if( *zDate==0 ){
|
||||
@@ -313,16 +313,16 @@ static int parseDateOrTime(const char *zDate, DateTime *p){
|
||||
return 0;
|
||||
}else if( parseHhMmSs(zDate, p)==0 ){
|
||||
return 0;
|
||||
}else if( sqlite3StrICmp(zDate,"now")==0){
|
||||
}else if( sqliteStrICmp(zDate,"now")==0){
|
||||
double r;
|
||||
if( sqlite3OsCurrentTime(&r)==0 ){
|
||||
if( sqliteOsCurrentTime(&r)==0 ){
|
||||
p->rJD = r;
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}else if( sqlite3IsNumber(zDate, 0, SQLITE_UTF8) ){
|
||||
p->rJD = sqlite3AtoF(zDate, 0);
|
||||
}else if( sqliteIsNumber(zDate) ){
|
||||
p->rJD = sqliteAtoF(zDate, 0);
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -415,7 +415,7 @@ static double localtimeOffset(DateTime *p){
|
||||
x.validJD = 0;
|
||||
computeJD(&x);
|
||||
t = (x.rJD-2440587.5)*86400.0 + 0.5;
|
||||
sqlite3OsEnterMutex();
|
||||
sqliteOsEnterMutex();
|
||||
pTm = localtime(&t);
|
||||
y.Y = pTm->tm_year + 1900;
|
||||
y.M = pTm->tm_mon + 1;
|
||||
@@ -423,7 +423,7 @@ static double localtimeOffset(DateTime *p){
|
||||
y.h = pTm->tm_hour;
|
||||
y.m = pTm->tm_min;
|
||||
y.s = pTm->tm_sec;
|
||||
sqlite3OsLeaveMutex();
|
||||
sqliteOsLeaveMutex();
|
||||
y.validYMD = 1;
|
||||
y.validHMS = 1;
|
||||
y.validJD = 0;
|
||||
@@ -504,7 +504,7 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
/*
|
||||
** weekday N
|
||||
**
|
||||
** Move the date to the same time on the next occurrence of
|
||||
** Move the date to the same time on the next occurrance of
|
||||
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
|
||||
** date is already on the appropriate weekday, this is a no-op.
|
||||
*/
|
||||
@@ -575,7 +575,7 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
const char *z2 = z;
|
||||
DateTime tx;
|
||||
int day;
|
||||
if( !isdigit(*(u8*)z2) ) z2++;
|
||||
if( !isdigit(*z2) ) z2++;
|
||||
memset(&tx, 0, sizeof(tx));
|
||||
if( parseHhMmSs(z2, &tx) ) break;
|
||||
computeJD(&tx);
|
||||
@@ -590,7 +590,7 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
break;
|
||||
}
|
||||
z += n;
|
||||
while( isspace(*(u8*)z) ) z++;
|
||||
while( isspace(z[0]) ) z++;
|
||||
n = strlen(z);
|
||||
if( n>10 || n<3 ) break;
|
||||
if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
|
||||
@@ -641,14 +641,12 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
** the resulting time into the DateTime structure p. Return 0
|
||||
** on success and 1 if there are any errors.
|
||||
*/
|
||||
static int isDate(int argc, sqlite3_value **argv, DateTime *p){
|
||||
static int isDate(int argc, const char **argv, DateTime *p){
|
||||
int i;
|
||||
if( argc==0 ) return 1;
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[0]) ||
|
||||
parseDateOrTime(sqlite3_value_text(argv[0]), p) ) return 1;
|
||||
if( argv[0]==0 || parseDateOrTime(argv[0], p) ) return 1;
|
||||
for(i=1; i<argc; i++){
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[i]) ||
|
||||
parseModifier(sqlite3_value_text(argv[i]), p) ) return 1;
|
||||
if( argv[i]==0 || parseModifier(argv[i], p) ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -664,15 +662,11 @@ static int isDate(int argc, sqlite3_value **argv, DateTime *p){
|
||||
**
|
||||
** Return the julian day number of the date specified in the arguments
|
||||
*/
|
||||
static void juliandayFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
static void juliandayFunc(sqlite_func *context, int argc, const char **argv){
|
||||
DateTime x;
|
||||
if( isDate(argc, argv, &x)==0 ){
|
||||
computeJD(&x);
|
||||
sqlite3_result_double(context, x.rJD);
|
||||
sqlite_set_result_double(context, x.rJD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,18 +675,14 @@ static void juliandayFunc(
|
||||
**
|
||||
** Return YYYY-MM-DD HH:MM:SS
|
||||
*/
|
||||
static void datetimeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
static void datetimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
DateTime x;
|
||||
if( isDate(argc, argv, &x)==0 ){
|
||||
char zBuf[100];
|
||||
computeYMD_HMS(&x);
|
||||
sprintf(zBuf, "%04d-%02d-%02d %02d:%02d:%02d",x.Y, x.M, x.D, x.h, x.m,
|
||||
(int)(x.s));
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
sqlite_set_result_string(context, zBuf, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,17 +691,13 @@ static void datetimeFunc(
|
||||
**
|
||||
** Return HH:MM:SS
|
||||
*/
|
||||
static void timeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
static void timeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
DateTime x;
|
||||
if( isDate(argc, argv, &x)==0 ){
|
||||
char zBuf[100];
|
||||
computeHMS(&x);
|
||||
sprintf(zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
sqlite_set_result_string(context, zBuf, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -720,17 +706,13 @@ static void timeFunc(
|
||||
**
|
||||
** Return YYYY-MM-DD
|
||||
*/
|
||||
static void dateFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
static void dateFunc(sqlite_func *context, int argc, const char **argv){
|
||||
DateTime x;
|
||||
if( isDate(argc, argv, &x)==0 ){
|
||||
char zBuf[100];
|
||||
computeYMD(&x);
|
||||
sprintf(zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
sqlite_set_result_string(context, zBuf, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -753,17 +735,13 @@ static void dateFunc(
|
||||
** %Y year 0000-9999
|
||||
** %% %
|
||||
*/
|
||||
static void strftimeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
DateTime x;
|
||||
int n, i, j;
|
||||
char *z;
|
||||
const char *zFmt = sqlite3_value_text(argv[0]);
|
||||
const char *zFmt = argv[0];
|
||||
char zBuf[100];
|
||||
if( zFmt==0 || isDate(argc-1, argv+1, &x) ) return;
|
||||
if( argv[0]==0 || isDate(argc-1, argv+1, &x) ) return;
|
||||
for(i=0, n=1; zFmt[i]; i++, n++){
|
||||
if( zFmt[i]=='%' ){
|
||||
switch( zFmt[i+1] ){
|
||||
@@ -822,20 +800,18 @@ static void strftimeFunc(
|
||||
case 'H': sprintf(&z[j],"%02d",x.h); j+=2; break;
|
||||
case 'W': /* Fall thru */
|
||||
case 'j': {
|
||||
int n; /* Number of days since 1st day of year */
|
||||
int n;
|
||||
DateTime y = x;
|
||||
y.validJD = 0;
|
||||
y.M = 1;
|
||||
y.D = 1;
|
||||
computeJD(&y);
|
||||
n = x.rJD - y.rJD;
|
||||
n = x.rJD - y.rJD + 1;
|
||||
if( zFmt[i]=='W' ){
|
||||
int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */
|
||||
wd = ((int)(x.rJD+0.5)) % 7;
|
||||
sprintf(&z[j],"%02d",(n+7-wd)/7);
|
||||
sprintf(&z[j],"%02d",(n+6)/7);
|
||||
j += 2;
|
||||
}else{
|
||||
sprintf(&z[j],"%03d",n+1);
|
||||
sprintf(&z[j],"%03d",n);
|
||||
j += 3;
|
||||
}
|
||||
break;
|
||||
@@ -856,7 +832,7 @@ static void strftimeFunc(
|
||||
}
|
||||
}
|
||||
z[j] = 0;
|
||||
sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
|
||||
sqlite_set_result_string(context, z, -1);
|
||||
if( z!=zBuf ){
|
||||
sqliteFree(z);
|
||||
}
|
||||
@@ -870,24 +846,28 @@ static void strftimeFunc(
|
||||
** functions. This should be the only routine in this file with
|
||||
** external linkage.
|
||||
*/
|
||||
void sqlite3RegisterDateTimeFunctions(sqlite *db){
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
void sqliteRegisterDateTimeFunctions(sqlite *db){
|
||||
static struct {
|
||||
char *zName;
|
||||
int nArg;
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
|
||||
int dataType;
|
||||
void (*xFunc)(sqlite_func*,int,const char**);
|
||||
} aFuncs[] = {
|
||||
{ "julianday", -1, juliandayFunc },
|
||||
{ "date", -1, dateFunc },
|
||||
{ "time", -1, timeFunc },
|
||||
{ "datetime", -1, datetimeFunc },
|
||||
{ "strftime", -1, strftimeFunc },
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
{ "julianday", -1, SQLITE_NUMERIC, juliandayFunc },
|
||||
{ "date", -1, SQLITE_TEXT, dateFunc },
|
||||
{ "time", -1, SQLITE_TEXT, timeFunc },
|
||||
{ "datetime", -1, SQLITE_TEXT, datetimeFunc },
|
||||
{ "strftime", -1, SQLITE_TEXT, strftimeFunc },
|
||||
#endif
|
||||
};
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
|
||||
sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
|
||||
SQLITE_UTF8, 0, aFuncs[i].xFunc, 0, 0);
|
||||
sqlite_create_function(db, aFuncs[i].zName,
|
||||
aFuncs[i].nArg, aFuncs[i].xFunc, 0);
|
||||
if( aFuncs[i].xFunc ){
|
||||
sqlite_function_type(db, aFuncs[i].zName, aFuncs[i].dataType);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
+101
-117
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle DELETE FROM statements.
|
||||
**
|
||||
** $Id: delete.c,v 1.79 2004/08/31 13:45:12 drh Exp $
|
||||
** $Id: delete.c,v 1.61 2004/02/24 01:05:32 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -21,13 +21,14 @@
|
||||
** add an error message to pParse->zErrMsg and return NULL. If all tables
|
||||
** are found, return a pointer to the last table.
|
||||
*/
|
||||
Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
Table *sqliteSrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
Table *pTab = 0;
|
||||
int i;
|
||||
struct SrcList_item *pItem;
|
||||
for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
|
||||
pTab = sqlite3LocateTable(pParse, pItem->zName, pItem->zDatabase);
|
||||
pItem->pTab = pTab;
|
||||
for(i=0; i<pSrc->nSrc; i++){
|
||||
const char *zTab = pSrc->a[i].zName;
|
||||
const char *zDb = pSrc->a[i].zDatabase;
|
||||
pTab = sqliteLocateTable(pParse, zTab, zDb);
|
||||
pSrc->a[i].pTab = pTab;
|
||||
}
|
||||
return pTab;
|
||||
}
|
||||
@@ -37,13 +38,13 @@ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
** writable, generate an error message and return 1. If it is
|
||||
** writable return 0;
|
||||
*/
|
||||
int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
int sqliteIsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
if( pTab->readOnly ){
|
||||
sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
|
||||
sqliteErrorMsg(pParse, "table %s may not be modified", pTab->zName);
|
||||
return 1;
|
||||
}
|
||||
if( !viewOk && pTab->pSelect ){
|
||||
sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName);
|
||||
sqliteErrorMsg(pParse, "cannot modify %s because it is a view",pTab->zName);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -52,7 +53,7 @@ int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
/*
|
||||
** Process a DELETE FROM statement.
|
||||
*/
|
||||
void sqlite3DeleteFrom(
|
||||
void sqliteDeleteFrom(
|
||||
Parse *pParse, /* The parser context */
|
||||
SrcList *pTabList, /* The table from which we should delete things */
|
||||
Expr *pWhere /* The WHERE clause. May be null */
|
||||
@@ -60,7 +61,7 @@ void sqlite3DeleteFrom(
|
||||
Vdbe *v; /* The virtual database engine */
|
||||
Table *pTab; /* The table from which records will be deleted */
|
||||
const char *zDb; /* Name of database holding pTab */
|
||||
int end, addr = 0; /* A couple addresses of generated code */
|
||||
int end, addr; /* A couple addresses of generated code */
|
||||
int i; /* Loop counter */
|
||||
WhereInfo *pWInfo; /* Information about the WHERE clause */
|
||||
Index *pIdx; /* For looping over indices of the table */
|
||||
@@ -75,7 +76,7 @@ void sqlite3DeleteFrom(
|
||||
int oldIdx = -1; /* Cursor for the OLD table of AFTER triggers */
|
||||
|
||||
sContext.pParse = 0;
|
||||
if( pParse->nErr || sqlite3_malloc_failed ){
|
||||
if( pParse->nErr || sqlite_malloc_failed ){
|
||||
pTabList = 0;
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
@@ -87,26 +88,26 @@ void sqlite3DeleteFrom(
|
||||
** will be calling are designed to work with multiple tables and expect
|
||||
** an SrcList* parameter instead of just a Table* parameter.
|
||||
*/
|
||||
pTab = sqlite3SrcListLookup(pParse, pTabList);
|
||||
pTab = sqliteSrcListLookup(pParse, pTabList);
|
||||
if( pTab==0 ) goto delete_from_cleanup;
|
||||
before_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger,
|
||||
before_triggers = sqliteTriggersExist(pParse, pTab->pTrigger,
|
||||
TK_DELETE, TK_BEFORE, TK_ROW, 0);
|
||||
after_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger,
|
||||
after_triggers = sqliteTriggersExist(pParse, pTab->pTrigger,
|
||||
TK_DELETE, TK_AFTER, TK_ROW, 0);
|
||||
row_triggers_exist = before_triggers || after_triggers;
|
||||
isView = pTab->pSelect!=0;
|
||||
if( sqlite3IsReadOnly(pParse, pTab, before_triggers) ){
|
||||
if( sqliteIsReadOnly(pParse, pTab, before_triggers) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
assert( pTab->iDb<db->nDb );
|
||||
zDb = db->aDb[pTab->iDb].zName;
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
|
||||
if( sqliteAuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
|
||||
/* If pTab is really a view, make sure it has been initialized.
|
||||
*/
|
||||
if( isView && sqlite3ViewGetColumnNames(pParse, pTab) ){
|
||||
if( isView && sqliteViewGetColumnNames(pParse, pTab) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
|
||||
@@ -120,39 +121,43 @@ void sqlite3DeleteFrom(
|
||||
*/
|
||||
assert( pTabList->nSrc==1 );
|
||||
iCur = pTabList->a[0].iCursor = pParse->nTab++;
|
||||
if( sqlite3ExprResolveAndCheck(pParse, pTabList, 0, pWhere, 0, 0) ){
|
||||
goto delete_from_cleanup;
|
||||
if( pWhere ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, 0, pWhere) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Start the view context
|
||||
*/
|
||||
if( isView ){
|
||||
sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
|
||||
sqliteAuthContextPush(pParse, &sContext, pTab->zName);
|
||||
}
|
||||
|
||||
/* Begin generating code.
|
||||
*/
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
v = sqliteGetVdbe(pParse);
|
||||
if( v==0 ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, row_triggers_exist, pTab->iDb);
|
||||
sqliteBeginWriteOperation(pParse, row_triggers_exist, pTab->iDb);
|
||||
|
||||
/* If we are trying to delete from a view, construct that view into
|
||||
** a temporary table.
|
||||
*/
|
||||
if( isView ){
|
||||
Select *pView = sqlite3SelectDup(pTab->pSelect);
|
||||
sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(pView);
|
||||
Select *pView = sqliteSelectDup(pTab->pSelect);
|
||||
sqliteSelect(pParse, pView, SRT_TempTable, iCur, 0, 0, 0);
|
||||
sqliteSelectDelete(pView);
|
||||
}
|
||||
|
||||
/* Initialize the counter of the number of rows deleted, if
|
||||
** we are counting rows.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
}
|
||||
|
||||
/* Special case: A DELETE without a WHERE clause deletes everything.
|
||||
@@ -163,23 +168,22 @@ void sqlite3DeleteFrom(
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
/* If counting rows deleted, just count the total number of
|
||||
** entries in the table. */
|
||||
int endOfLoop = sqlite3VdbeMakeLabel(v);
|
||||
int endOfLoop = sqliteVdbeMakeLabel(v);
|
||||
int addr;
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, sqlite3VdbeCurrentAddr(v)+2);
|
||||
addr = sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Next, iCur, addr);
|
||||
sqlite3VdbeResolveLabel(v, endOfLoop);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Rewind, iCur, sqliteVdbeCurrentAddr(v)+2);
|
||||
addr = sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Next, iCur, addr);
|
||||
sqliteVdbeResolveLabel(v, endOfLoop);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pTab->tnum, pTab->iDb);
|
||||
sqliteVdbeAddOp(v, OP_Clear, pTab->tnum, pTab->iDb);
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pIdx->tnum, pIdx->iDb);
|
||||
sqliteVdbeAddOp(v, OP_Clear, pIdx->tnum, pIdx->iDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,63 +192,55 @@ void sqlite3DeleteFrom(
|
||||
** the table and pick which records to delete.
|
||||
*/
|
||||
else{
|
||||
/* Ensure all required collation sequences are available. */
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Begin the database scan
|
||||
*/
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 1, 0);
|
||||
pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 1, 0);
|
||||
if( pWInfo==0 ) goto delete_from_cleanup;
|
||||
|
||||
/* Remember the key of every item to be deleted.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
}
|
||||
|
||||
/* End the database scan loop.
|
||||
*/
|
||||
sqlite3WhereEnd(pWInfo);
|
||||
sqliteWhereEnd(pWInfo);
|
||||
|
||||
/* Open the pseudo-table used to store OLD if there are triggers.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
sqlite3VdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, oldIdx, pTab->nCol);
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
}
|
||||
|
||||
/* Delete every item whose key was written to the list during the
|
||||
** database scan. We have to delete items after the scan is complete
|
||||
** because deleting an item can change the scan order.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
end = sqlite3VdbeMakeLabel(v);
|
||||
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
end = sqliteVdbeMakeLabel(v);
|
||||
|
||||
/* This is the beginning of the delete loop when there are
|
||||
** row triggers.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
|
||||
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
|
||||
sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TK_BEFORE, pTab, -1,
|
||||
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_BEFORE, pTab, -1,
|
||||
oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
|
||||
addr);
|
||||
}
|
||||
@@ -256,16 +252,17 @@ void sqlite3DeleteFrom(
|
||||
** before the trigger fires. If there are no row triggers, the
|
||||
** cursors are opened only once on the outside the loop.
|
||||
*/
|
||||
sqlite3OpenTableAndIndices(pParse, pTab, iCur, OP_OpenWrite);
|
||||
pParse->nTab = iCur + 1;
|
||||
sqliteOpenTableAndIndices(pParse, pTab, iCur);
|
||||
|
||||
/* This is the beginning of the delete loop when there are no
|
||||
** row triggers */
|
||||
if( !row_triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end);
|
||||
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
|
||||
}
|
||||
|
||||
/* Delete the row */
|
||||
sqlite3GenerateRowDelete(db, v, pTab, iCur, 1);
|
||||
sqliteGenerateRowDelete(db, v, pTab, iCur, pParse->trigStack==0);
|
||||
}
|
||||
|
||||
/* If there are row triggers, close all cursors then invoke
|
||||
@@ -274,43 +271,45 @@ void sqlite3DeleteFrom(
|
||||
if( row_triggers_exist ){
|
||||
if( !isView ){
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1,
|
||||
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1,
|
||||
oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
|
||||
addr);
|
||||
}
|
||||
|
||||
/* End of the delete loop */
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqlite3VdbeResolveLabel(v, end);
|
||||
sqlite3VdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqliteVdbeResolveLabel(v, end);
|
||||
sqliteVdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
|
||||
/* Close the cursors after the loop if there are no row triggers */
|
||||
if( !row_triggers_exist ){
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
pParse->nTab = iCur;
|
||||
}
|
||||
}
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
sqliteVdbeAddOp(v, OP_SetCounts, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
|
||||
/*
|
||||
** Return the number of rows that were deleted.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "rows deleted", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
|
||||
sqliteVdbeChangeP3(v, -1, "rows deleted", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
|
||||
delete_from_cleanup:
|
||||
sqlite3AuthContextPop(&sContext);
|
||||
sqlite3SrcListDelete(pTabList);
|
||||
sqlite3ExprDelete(pWhere);
|
||||
sqliteAuthContextPop(&sContext);
|
||||
sqliteSrcListDelete(pTabList);
|
||||
sqliteExprDelete(pWhere);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -334,7 +333,7 @@ delete_from_cleanup:
|
||||
** and then generates code to remove both the table record and all index
|
||||
** entries that point to that record.
|
||||
*/
|
||||
void sqlite3GenerateRowDelete(
|
||||
void sqliteGenerateRowDelete(
|
||||
sqlite *db, /* The database containing the index */
|
||||
Vdbe *v, /* Generate code into this VDBE */
|
||||
Table *pTab, /* Table containing the row to be deleted */
|
||||
@@ -342,10 +341,11 @@ void sqlite3GenerateRowDelete(
|
||||
int count /* Increment the row change counter */
|
||||
){
|
||||
int addr;
|
||||
addr = sqlite3VdbeAddOp(v, OP_NotExists, iCur, 0);
|
||||
sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
|
||||
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
|
||||
addr = sqliteVdbeAddOp(v, OP_NotExists, iCur, 0);
|
||||
sqliteGenerateRowIndexDelete(db, v, pTab, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Delete, iCur,
|
||||
(count?OPFLAG_NCHANGE:0) | OPFLAG_CSCHANGE);
|
||||
sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -364,7 +364,7 @@ void sqlite3GenerateRowDelete(
|
||||
** 3. The "iCur" cursor must be pointing to the row that is to be
|
||||
** deleted.
|
||||
*/
|
||||
void sqlite3GenerateRowIndexDelete(
|
||||
void sqliteGenerateRowIndexDelete(
|
||||
sqlite *db, /* The database containing the index */
|
||||
Vdbe *v, /* Generate code into this VDBE */
|
||||
Table *pTab, /* Table containing the row to be deleted */
|
||||
@@ -375,35 +375,19 @@ void sqlite3GenerateRowIndexDelete(
|
||||
Index *pIdx;
|
||||
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
int j;
|
||||
if( aIdxUsed!=0 && aIdxUsed[i-1]==0 ) continue;
|
||||
sqlite3GenerateIndexKey(v, pIdx, iCur);
|
||||
sqlite3VdbeAddOp(v, OP_IdxDelete, iCur+i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code that will assemble an index key and put it on the top
|
||||
** of the tack. The key with be for index pIdx which is an index on pTab.
|
||||
** iCur is the index of a cursor open on the pTab table and pointing to
|
||||
** the entry that needs indexing.
|
||||
*/
|
||||
void sqlite3GenerateIndexKey(
|
||||
Vdbe *v, /* Generate code into this VDBE */
|
||||
Index *pIdx, /* The index for which to generate a key */
|
||||
int iCur /* Cursor number for the pIdx->pTable table */
|
||||
){
|
||||
int j;
|
||||
Table *pTab = pIdx->pTable;
|
||||
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
for(j=0; j<pIdx->nColumn; j++){
|
||||
int idx = pIdx->aiColumn[j];
|
||||
if( idx==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, j, 0);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, idx);
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
for(j=0; j<pIdx->nColumn; j++){
|
||||
int idx = pIdx->aiColumn[j];
|
||||
if( idx==pTab->iPKey ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, j, 0);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_Column, iCur, idx);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
|
||||
if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
|
||||
sqliteVdbeAddOp(v, OP_IdxDelete, iCur+i, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24));
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
}
|
||||
|
||||
+1
-4
@@ -15,7 +15,7 @@
|
||||
** data in an SQLite database. The code in this file is not used by any other
|
||||
** part of the SQLite library.
|
||||
**
|
||||
** $Id: encode.c,v 1.13 2004/05/08 08:23:24 danielk1977 Exp $
|
||||
** $Id: encode.c,v 1.12 2004/03/17 18:44:46 drh Exp $
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
@@ -252,6 +252,3 @@ int main(int argc, char **argv){
|
||||
(nByteOut-nByteIn)*100.0/(double)nByteIn);
|
||||
}
|
||||
#endif /* ENCODER_TEST */
|
||||
|
||||
|
||||
|
||||
|
||||
+498
-684
File diff suppressed because it is too large
Load Diff
+255
-627
File diff suppressed because it is too large
Load Diff
+63
-87
@@ -12,7 +12,7 @@
|
||||
** This is the implementation of generic hash-tables
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.c,v 1.15 2004/08/20 14:08:51 drh Exp $
|
||||
** $Id: hash.c,v 1.11 2004/01/08 02:17:33 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <assert.h>
|
||||
@@ -20,7 +20,7 @@
|
||||
/* Turn bulk memory into a hash table object by initializing the
|
||||
** fields of the Hash structure.
|
||||
**
|
||||
** "pNew" is a pointer to the hash table that is to be initialized.
|
||||
** "new" is a pointer to the hash table that is to be initialized.
|
||||
** keyClass is one of the constants SQLITE_HASH_INT, SQLITE_HASH_POINTER,
|
||||
** SQLITE_HASH_BINARY, or SQLITE_HASH_STRING. The value of keyClass
|
||||
** determines what kind of key the hash table will use. "copyKey" is
|
||||
@@ -29,25 +29,23 @@
|
||||
** sense for SQLITE_HASH_STRING and SQLITE_HASH_BINARY and is ignored
|
||||
** for other key classes.
|
||||
*/
|
||||
void sqlite3HashInit(Hash *pNew, int keyClass, int copyKey){
|
||||
assert( pNew!=0 );
|
||||
assert( keyClass>=SQLITE_HASH_STRING && keyClass<=SQLITE_HASH_BINARY );
|
||||
pNew->keyClass = keyClass;
|
||||
#if 0
|
||||
if( keyClass==SQLITE_HASH_POINTER || keyClass==SQLITE_HASH_INT ) copyKey = 0;
|
||||
#endif
|
||||
pNew->copyKey = copyKey;
|
||||
pNew->first = 0;
|
||||
pNew->count = 0;
|
||||
pNew->htsize = 0;
|
||||
pNew->ht = 0;
|
||||
void sqliteHashInit(Hash *new, int keyClass, int copyKey){
|
||||
assert( new!=0 );
|
||||
assert( keyClass>=SQLITE_HASH_INT && keyClass<=SQLITE_HASH_BINARY );
|
||||
new->keyClass = keyClass;
|
||||
new->copyKey = copyKey &&
|
||||
(keyClass==SQLITE_HASH_STRING || keyClass==SQLITE_HASH_BINARY);
|
||||
new->first = 0;
|
||||
new->count = 0;
|
||||
new->htsize = 0;
|
||||
new->ht = 0;
|
||||
}
|
||||
|
||||
/* Remove all entries from a hash table. Reclaim all memory.
|
||||
** Call this routine to delete a hash table or to reset a hash table
|
||||
** to the empty state.
|
||||
*/
|
||||
void sqlite3HashClear(Hash *pH){
|
||||
void sqliteHashClear(Hash *pH){
|
||||
HashElem *elem; /* For looping over all elements of the table */
|
||||
|
||||
assert( pH!=0 );
|
||||
@@ -67,7 +65,6 @@ void sqlite3HashClear(Hash *pH){
|
||||
pH->count = 0;
|
||||
}
|
||||
|
||||
#if 0 /* NOT USED */
|
||||
/*
|
||||
** Hash and comparison functions when the mode is SQLITE_HASH_INT
|
||||
*/
|
||||
@@ -77,7 +74,6 @@ static int intHash(const void *pKey, int nKey){
|
||||
static int intCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
return n2 - n1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 /* NOT USED */
|
||||
/*
|
||||
@@ -98,11 +94,11 @@ static int ptrCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
** Hash and comparison functions when the mode is SQLITE_HASH_STRING
|
||||
*/
|
||||
static int strHash(const void *pKey, int nKey){
|
||||
return sqlite3HashNoCase((const char*)pKey, nKey);
|
||||
return sqliteHashNoCase((const char*)pKey, nKey);
|
||||
}
|
||||
static int strCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
if( n1!=n2 ) return 1;
|
||||
return sqlite3StrNICmp((const char*)pKey1,(const char*)pKey2,n1);
|
||||
if( n1!=n2 ) return n2-n1;
|
||||
return sqliteStrNICmp((const char*)pKey1,(const char*)pKey2,n1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -117,7 +113,7 @@ static int binHash(const void *pKey, int nKey){
|
||||
return h & 0x7fffffff;
|
||||
}
|
||||
static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
if( n1!=n2 ) return 1;
|
||||
if( n1!=n2 ) return n2-n1;
|
||||
return memcmp(pKey1,pKey2,n1);
|
||||
}
|
||||
|
||||
@@ -134,23 +130,14 @@ static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
** with types "const void*" and "int" and returns an "int".
|
||||
*/
|
||||
static int (*hashFunction(int keyClass))(const void*,int){
|
||||
#if 0 /* HASH_INT and HASH_POINTER are never used */
|
||||
switch( keyClass ){
|
||||
case SQLITE_HASH_INT: return &intHash;
|
||||
case SQLITE_HASH_POINTER: return &ptrHash;
|
||||
/* case SQLITE_HASH_POINTER: return &ptrHash; // NOT USED */
|
||||
case SQLITE_HASH_STRING: return &strHash;
|
||||
case SQLITE_HASH_BINARY: return &binHash;;
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
if( keyClass==SQLITE_HASH_STRING ){
|
||||
return &strHash;
|
||||
}else{
|
||||
assert( keyClass==SQLITE_HASH_BINARY );
|
||||
return &binHash;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -160,48 +147,14 @@ static int (*hashFunction(int keyClass))(const void*,int){
|
||||
** see the header comment on the previous function.
|
||||
*/
|
||||
static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
|
||||
#if 0 /* HASH_INT and HASH_POINTER are never used */
|
||||
switch( keyClass ){
|
||||
case SQLITE_HASH_INT: return &intCompare;
|
||||
case SQLITE_HASH_POINTER: return &ptrCompare;
|
||||
/* case SQLITE_HASH_POINTER: return &ptrCompare; // NOT USED */
|
||||
case SQLITE_HASH_STRING: return &strCompare;
|
||||
case SQLITE_HASH_BINARY: return &binCompare;
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
if( keyClass==SQLITE_HASH_STRING ){
|
||||
return &strCompare;
|
||||
}else{
|
||||
assert( keyClass==SQLITE_HASH_BINARY );
|
||||
return &binCompare;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Link an element into the hash table
|
||||
*/
|
||||
static void insertElement(
|
||||
Hash *pH, /* The complete hash table */
|
||||
struct _ht *pEntry, /* The entry into which pNew is inserted */
|
||||
HashElem *pNew /* The element to be inserted */
|
||||
){
|
||||
HashElem *pHead; /* First element already in pEntry */
|
||||
pHead = pEntry->chain;
|
||||
if( pHead ){
|
||||
pNew->next = pHead;
|
||||
pNew->prev = pHead->prev;
|
||||
if( pHead->prev ){ pHead->prev->next = pNew; }
|
||||
else { pH->first = pNew; }
|
||||
pHead->prev = pNew;
|
||||
}else{
|
||||
pNew->next = pH->first;
|
||||
if( pH->first ){ pH->first->prev = pNew; }
|
||||
pNew->prev = 0;
|
||||
pH->first = pNew;
|
||||
}
|
||||
pEntry->count++;
|
||||
pEntry->chain = pNew;
|
||||
}
|
||||
|
||||
|
||||
@@ -212,6 +165,7 @@ static void insertElement(
|
||||
static void rehash(Hash *pH, int new_size){
|
||||
struct _ht *new_ht; /* The new hash table */
|
||||
HashElem *elem, *next_elem; /* For looping over existing elements */
|
||||
HashElem *x; /* Element being copied to new hash table */
|
||||
int (*xHash)(const void*,int); /* The hash function */
|
||||
|
||||
assert( (new_size & (new_size-1))==0 );
|
||||
@@ -224,7 +178,21 @@ static void rehash(Hash *pH, int new_size){
|
||||
for(elem=pH->first, pH->first=0; elem; elem = next_elem){
|
||||
int h = (*xHash)(elem->pKey, elem->nKey) & (new_size-1);
|
||||
next_elem = elem->next;
|
||||
insertElement(pH, &new_ht[h], elem);
|
||||
x = new_ht[h].chain;
|
||||
if( x ){
|
||||
elem->next = x;
|
||||
elem->prev = x->prev;
|
||||
if( x->prev ) x->prev->next = elem;
|
||||
else pH->first = elem;
|
||||
x->prev = elem;
|
||||
}else{
|
||||
elem->next = pH->first;
|
||||
if( pH->first ) pH->first->prev = elem;
|
||||
elem->prev = 0;
|
||||
pH->first = elem;
|
||||
}
|
||||
new_ht[h].chain = elem;
|
||||
new_ht[h].count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,9 +211,8 @@ static HashElem *findElementGivenHash(
|
||||
int (*xCompare)(const void*,int,const void*,int); /* comparison function */
|
||||
|
||||
if( pH->ht ){
|
||||
struct _ht *pEntry = &pH->ht[h];
|
||||
elem = pEntry->chain;
|
||||
count = pEntry->count;
|
||||
elem = pH->ht[h].chain;
|
||||
count = pH->ht[h].count;
|
||||
xCompare = compareFunction(pH->keyClass);
|
||||
while( count-- && elem ){
|
||||
if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){
|
||||
@@ -265,7 +232,6 @@ static void removeElementGivenHash(
|
||||
HashElem* elem, /* The element to be removed from the pH */
|
||||
int h /* Hash value for the element */
|
||||
){
|
||||
struct _ht *pEntry;
|
||||
if( elem->prev ){
|
||||
elem->prev->next = elem->next;
|
||||
}else{
|
||||
@@ -274,13 +240,12 @@ static void removeElementGivenHash(
|
||||
if( elem->next ){
|
||||
elem->next->prev = elem->prev;
|
||||
}
|
||||
pEntry = &pH->ht[h];
|
||||
if( pEntry->chain==elem ){
|
||||
pEntry->chain = elem->next;
|
||||
if( pH->ht[h].chain==elem ){
|
||||
pH->ht[h].chain = elem->next;
|
||||
}
|
||||
pEntry->count--;
|
||||
if( pEntry->count<=0 ){
|
||||
pEntry->chain = 0;
|
||||
pH->ht[h].count--;
|
||||
if( pH->ht[h].count<=0 ){
|
||||
pH->ht[h].chain = 0;
|
||||
}
|
||||
if( pH->copyKey && elem->pKey ){
|
||||
sqliteFree(elem->pKey);
|
||||
@@ -293,7 +258,7 @@ static void removeElementGivenHash(
|
||||
** that matches pKey,nKey. Return the data for this element if it is
|
||||
** found, or NULL if there is no match.
|
||||
*/
|
||||
void *sqlite3HashFind(const Hash *pH, const void *pKey, int nKey){
|
||||
void *sqliteHashFind(const Hash *pH, const void *pKey, int nKey){
|
||||
int h; /* A hash on key */
|
||||
HashElem *elem; /* The element that matches key */
|
||||
int (*xHash)(const void*,int); /* The hash function */
|
||||
@@ -322,7 +287,7 @@ void *sqlite3HashFind(const Hash *pH, const void *pKey, int nKey){
|
||||
** If the "data" parameter to this function is NULL, then the
|
||||
** element corresponding to "key" is removed from the hash table.
|
||||
*/
|
||||
void *sqlite3HashInsert(Hash *pH, const void *pKey, int nKey, void *data){
|
||||
void *sqliteHashInsert(Hash *pH, const void *pKey, int nKey, void *data){
|
||||
int hraw; /* Raw hash value of the key */
|
||||
int h; /* the hash of the key modulo hash table size */
|
||||
HashElem *elem; /* Used to loop thru the element list */
|
||||
@@ -360,21 +325,32 @@ void *sqlite3HashInsert(Hash *pH, const void *pKey, int nKey, void *data){
|
||||
}
|
||||
new_elem->nKey = nKey;
|
||||
pH->count++;
|
||||
if( pH->htsize==0 ) rehash(pH,8);
|
||||
if( pH->htsize==0 ){
|
||||
rehash(pH,8);
|
||||
if( pH->htsize==0 ){
|
||||
pH->count = 0;
|
||||
sqliteFree(new_elem);
|
||||
return data;
|
||||
}
|
||||
pH->count = 0;
|
||||
sqliteFree(new_elem);
|
||||
return data;
|
||||
}
|
||||
if( pH->count > pH->htsize ){
|
||||
rehash(pH,pH->htsize*2);
|
||||
}
|
||||
assert( pH->htsize>0 );
|
||||
assert( (pH->htsize & (pH->htsize-1))==0 );
|
||||
h = hraw & (pH->htsize-1);
|
||||
insertElement(pH, &pH->ht[h], new_elem);
|
||||
elem = pH->ht[h].chain;
|
||||
if( elem ){
|
||||
new_elem->next = elem;
|
||||
new_elem->prev = elem->prev;
|
||||
if( elem->prev ){ elem->prev->next = new_elem; }
|
||||
else { pH->first = new_elem; }
|
||||
elem->prev = new_elem;
|
||||
}else{
|
||||
new_elem->next = pH->first;
|
||||
new_elem->prev = 0;
|
||||
if( pH->first ){ pH->first->prev = new_elem; }
|
||||
pH->first = new_elem;
|
||||
}
|
||||
pH->ht[h].count++;
|
||||
pH->ht[h].chain = new_elem;
|
||||
new_elem->data = data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+6
-6
@@ -12,7 +12,7 @@
|
||||
** This is the header file for the generic hash-table implemenation
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.h,v 1.8 2004/08/20 14:08:51 drh Exp $
|
||||
** $Id: hash.h,v 1.6 2004/01/08 02:17:33 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_HASH_H_
|
||||
#define _SQLITE_HASH_H_
|
||||
@@ -70,7 +70,7 @@ struct HashElem {
|
||||
** A copy of the key is made for SQLITE_HASH_STRING and SQLITE_HASH_BINARY
|
||||
** if the copyKey parameter to HashInit is 1.
|
||||
*/
|
||||
/* #define SQLITE_HASH_INT 1 // NOT USED */
|
||||
#define SQLITE_HASH_INT 1
|
||||
/* #define SQLITE_HASH_POINTER 2 // NOT USED */
|
||||
#define SQLITE_HASH_STRING 3
|
||||
#define SQLITE_HASH_BINARY 4
|
||||
@@ -78,10 +78,10 @@ struct HashElem {
|
||||
/*
|
||||
** Access routines. To delete, insert a NULL pointer.
|
||||
*/
|
||||
void sqlite3HashInit(Hash*, int keytype, int copyKey);
|
||||
void *sqlite3HashInsert(Hash*, const void *pKey, int nKey, void *pData);
|
||||
void *sqlite3HashFind(const Hash*, const void *pKey, int nKey);
|
||||
void sqlite3HashClear(Hash*);
|
||||
void sqliteHashInit(Hash*, int keytype, int copyKey);
|
||||
void *sqliteHashInsert(Hash*, const void *pKey, int nKey, void *pData);
|
||||
void *sqliteHashFind(const Hash*, const void *pKey, int nKey);
|
||||
void sqliteHashClear(Hash*);
|
||||
|
||||
/*
|
||||
** Macros for looping over all elements of a hash table. The idiom is
|
||||
|
||||
+189
-286
@@ -12,89 +12,10 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle INSERT statements in SQLite.
|
||||
**
|
||||
** $Id: insert.c,v 1.115 2004/08/21 17:54:45 drh Exp $
|
||||
** $Id: insert.c,v 1.94 2004/02/24 01:05:33 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Set P3 of the most recently inserted opcode to a column affinity
|
||||
** string for index pIdx. A column affinity string has one character
|
||||
** for each column in the table, according to the affinity of the column:
|
||||
**
|
||||
** Character Column affinity
|
||||
** ------------------------------
|
||||
** 'n' NUMERIC
|
||||
** 'i' INTEGER
|
||||
** 't' TEXT
|
||||
** 'o' NONE
|
||||
*/
|
||||
void sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
|
||||
if( !pIdx->zColAff ){
|
||||
/* The first time a column affinity string for a particular index is
|
||||
** required, it is allocated and populated here. It is then stored as
|
||||
** a member of the Index structure for subsequent use.
|
||||
**
|
||||
** The column affinity string will eventually be deleted by
|
||||
** sqliteDeleteIndex() when the Index structure itself is cleaned
|
||||
** up.
|
||||
*/
|
||||
int n;
|
||||
Table *pTab = pIdx->pTable;
|
||||
pIdx->zColAff = (char *)sqliteMalloc(pIdx->nColumn+1);
|
||||
if( !pIdx->zColAff ){
|
||||
return;
|
||||
}
|
||||
for(n=0; n<pIdx->nColumn; n++){
|
||||
pIdx->zColAff[n] = pTab->aCol[pIdx->aiColumn[n]].affinity;
|
||||
}
|
||||
pIdx->zColAff[pIdx->nColumn] = '\0';
|
||||
}
|
||||
|
||||
sqlite3VdbeChangeP3(v, -1, pIdx->zColAff, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Set P3 of the most recently inserted opcode to a column affinity
|
||||
** string for table pTab. A column affinity string has one character
|
||||
** for each column indexed by the index, according to the affinity of the
|
||||
** column:
|
||||
**
|
||||
** Character Column affinity
|
||||
** ------------------------------
|
||||
** 'n' NUMERIC
|
||||
** 'i' INTEGER
|
||||
** 't' TEXT
|
||||
** 'o' NONE
|
||||
*/
|
||||
void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
|
||||
/* The first time a column affinity string for a particular table
|
||||
** is required, it is allocated and populated here. It is then
|
||||
** stored as a member of the Table structure for subsequent use.
|
||||
**
|
||||
** The column affinity string will eventually be deleted by
|
||||
** sqlite3DeleteTable() when the Table structure itself is cleaned up.
|
||||
*/
|
||||
if( !pTab->zColAff ){
|
||||
char *zColAff;
|
||||
int i;
|
||||
|
||||
zColAff = (char *)sqliteMalloc(pTab->nCol+1);
|
||||
if( !zColAff ){
|
||||
return;
|
||||
}
|
||||
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
zColAff[i] = pTab->aCol[i].affinity;
|
||||
}
|
||||
zColAff[pTab->nCol] = '\0';
|
||||
|
||||
pTab->zColAff = zColAff;
|
||||
}
|
||||
|
||||
sqlite3VdbeChangeP3(v, -1, pTab->zColAff, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This routine is call to handle SQL of the following forms:
|
||||
**
|
||||
@@ -162,7 +83,7 @@ void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
|
||||
** end the loop
|
||||
** cleanup
|
||||
*/
|
||||
void sqlite3Insert(
|
||||
void sqliteInsert(
|
||||
Parse *pParse, /* Parser context */
|
||||
SrcList *pTabList, /* Name of table into which we are inserting */
|
||||
ExprList *pList, /* List of values to be inserted */
|
||||
@@ -177,17 +98,17 @@ void sqlite3Insert(
|
||||
Vdbe *v; /* Generate code into this virtual machine */
|
||||
Index *pIdx; /* For looping over indices of the table */
|
||||
int nColumn; /* Number of columns in the data */
|
||||
int base = 0; /* VDBE Cursor number for pTab */
|
||||
int iCont=0,iBreak=0; /* Beginning and end of the loop over srcTab */
|
||||
int base; /* VDBE Cursor number for pTab */
|
||||
int iCont, iBreak; /* Beginning and end of the loop over srcTab */
|
||||
sqlite *db; /* The main database structure */
|
||||
int keyColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
|
||||
int endOfLoop; /* Label for the end of the insertion loop */
|
||||
int useTempTable; /* Store SELECT results in intermediate table */
|
||||
int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
|
||||
int iSelectLoop = 0; /* Address of code that implements the SELECT */
|
||||
int iCleanup = 0; /* Address of the cleanup code */
|
||||
int iInsertBlock = 0; /* Address of the subroutine used to insert data */
|
||||
int iCntMem = 0; /* Memory cell used for the row counter */
|
||||
int srcTab; /* Data comes from this temporary cursor if >=0 */
|
||||
int iSelectLoop; /* Address of code that implements the SELECT */
|
||||
int iCleanup; /* Address of the cleanup code */
|
||||
int iInsertBlock; /* Address of the subroutine used to insert data */
|
||||
int iCntMem; /* Memory cell used for the row counter */
|
||||
int isView; /* True if attempting to insert into a view */
|
||||
|
||||
int row_triggers_exist = 0; /* True if there are FOR EACH ROW triggers */
|
||||
@@ -195,7 +116,7 @@ void sqlite3Insert(
|
||||
int after_triggers; /* True if there are AFTER triggers */
|
||||
int newIdx = -1; /* Cursor for the NEW table */
|
||||
|
||||
if( pParse->nErr || sqlite3_malloc_failed ) goto insert_cleanup;
|
||||
if( pParse->nErr || sqlite_malloc_failed ) goto insert_cleanup;
|
||||
db = pParse->db;
|
||||
|
||||
/* Locate the table into which we will be inserting new information.
|
||||
@@ -203,13 +124,13 @@ void sqlite3Insert(
|
||||
assert( pTabList->nSrc==1 );
|
||||
zTab = pTabList->a[0].zName;
|
||||
if( zTab==0 ) goto insert_cleanup;
|
||||
pTab = sqlite3SrcListLookup(pParse, pTabList);
|
||||
pTab = sqliteSrcListLookup(pParse, pTabList);
|
||||
if( pTab==0 ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
assert( pTab->iDb<db->nDb );
|
||||
zDb = db->aDb[pTab->iDb].zName;
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
|
||||
if( sqliteAuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
|
||||
@@ -217,36 +138,28 @@ void sqlite3Insert(
|
||||
* (a) the table is not read-only,
|
||||
* (b) that if it is a view then ON INSERT triggers exist
|
||||
*/
|
||||
before_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger, TK_INSERT,
|
||||
before_triggers = sqliteTriggersExist(pParse, pTab->pTrigger, TK_INSERT,
|
||||
TK_BEFORE, TK_ROW, 0);
|
||||
after_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger, TK_INSERT,
|
||||
after_triggers = sqliteTriggersExist(pParse, pTab->pTrigger, TK_INSERT,
|
||||
TK_AFTER, TK_ROW, 0);
|
||||
row_triggers_exist = before_triggers || after_triggers;
|
||||
isView = pTab->pSelect!=0;
|
||||
if( sqlite3IsReadOnly(pParse, pTab, before_triggers) ){
|
||||
if( sqliteIsReadOnly(pParse, pTab, before_triggers) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( pTab==0 ) goto insert_cleanup;
|
||||
|
||||
/* If pTab is really a view, make sure it has been initialized.
|
||||
*/
|
||||
if( isView && sqlite3ViewGetColumnNames(pParse, pTab) ){
|
||||
if( isView && sqliteViewGetColumnNames(pParse, pTab) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
|
||||
/* Ensure all required collation sequences are available. */
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate a VDBE
|
||||
*/
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
v = sqliteGetVdbe(pParse);
|
||||
if( v==0 ) goto insert_cleanup;
|
||||
sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, pSelect || row_triggers_exist, pTab->iDb);
|
||||
sqliteBeginWriteOperation(pParse, pSelect || row_triggers_exist, pTab->iDb);
|
||||
|
||||
/* if there are row triggers, allocate a temp table for new.* references. */
|
||||
if( row_triggers_exist ){
|
||||
@@ -265,13 +178,13 @@ void sqlite3Insert(
|
||||
/* Data is coming from a SELECT. Generate code to implement that SELECT
|
||||
*/
|
||||
int rc, iInitCode;
|
||||
iInitCode = sqlite3VdbeAddOp(v, OP_Goto, 0, 0);
|
||||
iSelectLoop = sqlite3VdbeCurrentAddr(v);
|
||||
iInsertBlock = sqlite3VdbeMakeLabel(v);
|
||||
rc = sqlite3Select(pParse, pSelect, SRT_Subroutine, iInsertBlock, 0,0,0,0);
|
||||
if( rc || pParse->nErr || sqlite3_malloc_failed ) goto insert_cleanup;
|
||||
iCleanup = sqlite3VdbeMakeLabel(v);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, iCleanup);
|
||||
iInitCode = sqliteVdbeAddOp(v, OP_Goto, 0, 0);
|
||||
iSelectLoop = sqliteVdbeCurrentAddr(v);
|
||||
iInsertBlock = sqliteVdbeMakeLabel(v);
|
||||
rc = sqliteSelect(pParse, pSelect, SRT_Subroutine, iInsertBlock, 0,0,0);
|
||||
if( rc || pParse->nErr || sqlite_malloc_failed ) goto insert_cleanup;
|
||||
iCleanup = sqliteVdbeMakeLabel(v);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, iCleanup);
|
||||
assert( pSelect->pEList );
|
||||
nColumn = pSelect->pEList->nExpr;
|
||||
|
||||
@@ -286,10 +199,10 @@ void sqlite3Insert(
|
||||
if( row_triggers_exist ){
|
||||
useTempTable = 1;
|
||||
}else{
|
||||
int addr = sqlite3VdbeFindOp(v, 0, OP_OpenRead, pTab->tnum);
|
||||
int addr = sqliteVdbeFindOp(v, OP_OpenRead, pTab->tnum);
|
||||
useTempTable = 0;
|
||||
if( addr>0 ){
|
||||
VdbeOp *pOp = sqlite3VdbeGetOp(v, addr-2);
|
||||
VdbeOp *pOp = sqliteVdbeGetOp(v, addr-2);
|
||||
if( pOp->opcode==OP_Integer && pOp->p1==pTab->iDb ){
|
||||
useTempTable = 1;
|
||||
}
|
||||
@@ -301,25 +214,23 @@ void sqlite3Insert(
|
||||
** the result. Store the result in a temporary table
|
||||
*/
|
||||
srcTab = pParse->nTab++;
|
||||
sqlite3VdbeResolveLabel(v, iInsertBlock);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
sqlite3VdbeAddOp(v, OP_NewRecno, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Return, 0, 0);
|
||||
sqliteVdbeResolveLabel(v, iInsertBlock);
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, nColumn, 0);
|
||||
sqliteVdbeAddOp(v, OP_NewRecno, srcTab, 0);
|
||||
sqliteVdbeAddOp(v, OP_Pull, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, srcTab, 0);
|
||||
sqliteVdbeAddOp(v, OP_Return, 0, 0);
|
||||
|
||||
/* The following code runs first because the GOTO at the very top
|
||||
** of the program jumps to it. Create the temporary table, then jump
|
||||
** back up and execute the SELECT code above.
|
||||
*/
|
||||
sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeAddOp(v, OP_OpenTemp, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, nColumn);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop);
|
||||
sqlite3VdbeResolveLabel(v, iCleanup);
|
||||
sqliteVdbeChangeP2(v, iInitCode, sqliteVdbeCurrentAddr(v));
|
||||
sqliteVdbeAddOp(v, OP_OpenTemp, srcTab, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, iSelectLoop);
|
||||
sqliteVdbeResolveLabel(v, iCleanup);
|
||||
}else{
|
||||
sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
|
||||
sqliteVdbeChangeP2(v, iInitCode, sqliteVdbeCurrentAddr(v));
|
||||
}
|
||||
}else{
|
||||
/* This is the case if the data for the INSERT is coming from a VALUES
|
||||
@@ -333,7 +244,10 @@ void sqlite3Insert(
|
||||
nColumn = pList->nExpr;
|
||||
dummy.nSrc = 0;
|
||||
for(i=0; i<nColumn; i++){
|
||||
if( sqlite3ExprResolveAndCheck(pParse,&dummy,0,pList->a[i].pExpr,0,0) ){
|
||||
if( sqliteExprResolveIds(pParse, &dummy, 0, pList->a[i].pExpr) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pList->a[i].pExpr, 0, 0) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -343,13 +257,13 @@ void sqlite3Insert(
|
||||
** of columns to be inserted into the table.
|
||||
*/
|
||||
if( pColumn==0 && nColumn!=pTab->nCol ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
sqliteErrorMsg(pParse,
|
||||
"table %S has %d columns but %d values were supplied",
|
||||
pTabList, 0, pTab->nCol, nColumn);
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( pColumn!=0 && nColumn!=pColumn->nId ){
|
||||
sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
|
||||
sqliteErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
|
||||
goto insert_cleanup;
|
||||
}
|
||||
|
||||
@@ -370,7 +284,7 @@ void sqlite3Insert(
|
||||
}
|
||||
for(i=0; i<pColumn->nId; i++){
|
||||
for(j=0; j<pTab->nCol; j++){
|
||||
if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
|
||||
if( sqliteStrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
|
||||
pColumn->a[i].idx = j;
|
||||
if( j==pTab->iPKey ){
|
||||
keyColumn = i;
|
||||
@@ -379,10 +293,10 @@ void sqlite3Insert(
|
||||
}
|
||||
}
|
||||
if( j>=pTab->nCol ){
|
||||
if( sqlite3IsRowid(pColumn->a[i].zName) ){
|
||||
if( sqliteIsRowid(pColumn->a[i].zName) ){
|
||||
keyColumn = i;
|
||||
}else{
|
||||
sqlite3ErrorMsg(pParse, "table %S has no column named %s",
|
||||
sqliteErrorMsg(pParse, "table %S has no column named %s",
|
||||
pTabList, 0, pColumn->a[i].zName);
|
||||
pParse->nErr++;
|
||||
goto insert_cleanup;
|
||||
@@ -402,22 +316,22 @@ void sqlite3Insert(
|
||||
/* Open the temp table for FOR EACH ROW triggers
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
sqlite3VdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol);
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
|
||||
}
|
||||
|
||||
/* Initialize the count of rows to be inserted
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
iCntMem = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iCntMem, 1);
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, iCntMem, 1);
|
||||
}
|
||||
|
||||
/* Open tables and indices if there are no row triggers */
|
||||
if( !row_triggers_exist ){
|
||||
base = pParse->nTab;
|
||||
sqlite3OpenTableAndIndices(pParse, pTab, base, OP_OpenWrite);
|
||||
idx = sqliteOpenTableAndIndices(pParse, pTab, base);
|
||||
pParse->nTab += idx;
|
||||
}
|
||||
|
||||
/* If the data source is a temporary table, then we have to create
|
||||
@@ -426,17 +340,17 @@ void sqlite3Insert(
|
||||
** to launch the SELECT statement processing.
|
||||
*/
|
||||
if( useTempTable ){
|
||||
iBreak = sqlite3VdbeMakeLabel(v);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, srcTab, iBreak);
|
||||
iCont = sqlite3VdbeCurrentAddr(v);
|
||||
iBreak = sqliteVdbeMakeLabel(v);
|
||||
sqliteVdbeAddOp(v, OP_Rewind, srcTab, iBreak);
|
||||
iCont = sqliteVdbeCurrentAddr(v);
|
||||
}else if( pSelect ){
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop);
|
||||
sqlite3VdbeResolveLabel(v, iInsertBlock);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, iSelectLoop);
|
||||
sqliteVdbeResolveLabel(v, iInsertBlock);
|
||||
}
|
||||
|
||||
/* Run the BEFORE and INSTEAD OF triggers, if there are any
|
||||
*/
|
||||
endOfLoop = sqlite3VdbeMakeLabel(v);
|
||||
endOfLoop = sqliteVdbeMakeLabel(v);
|
||||
if( before_triggers ){
|
||||
|
||||
/* build the NEW.* reference row. Note that if there is an INTEGER
|
||||
@@ -446,17 +360,17 @@ void sqlite3Insert(
|
||||
** not happened yet) so we substitute a rowid of -1
|
||||
*/
|
||||
if( keyColumn<0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, -1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, -1, 0);
|
||||
}else if( useTempTable ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, srcTab, keyColumn);
|
||||
sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
|
||||
}else if( pSelect ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nColumn - keyColumn - 1, 1);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nColumn - keyColumn - 1, 1);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr);
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, -1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
sqliteExprCode(pParse, pList->a[keyColumn].pExpr);
|
||||
sqliteVdbeAddOp(v, OP_NotNull, -1, sqliteVdbeCurrentAddr(v)+3);
|
||||
sqliteVdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, -1, 0);
|
||||
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}
|
||||
|
||||
/* Create the new column data
|
||||
@@ -470,29 +384,20 @@ void sqlite3Insert(
|
||||
}
|
||||
}
|
||||
if( pColumn && j>=pColumn->nId ){
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
}else if( useTempTable ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, srcTab, j);
|
||||
sqliteVdbeAddOp(v, OP_Column, srcTab, j);
|
||||
}else if( pSelect ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nColumn-j-1, 1);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nColumn-j-1, 1);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pList->a[j].pExpr);
|
||||
sqliteExprCode(pParse, pList->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
|
||||
/* If this is an INSERT on a view with an INSTEAD OF INSERT trigger,
|
||||
** do not attempt any conversions before assembling the record.
|
||||
** If this is a real table, attempt conversions as required by the
|
||||
** table column affinities.
|
||||
*/
|
||||
if( !isView ){
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
|
||||
/* Fire BEFORE or INSTEAD OF triggers */
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab,
|
||||
if( sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab,
|
||||
newIdx, -1, onError, endOfLoop) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
@@ -503,7 +408,8 @@ void sqlite3Insert(
|
||||
*/
|
||||
if( row_triggers_exist && !isView ){
|
||||
base = pParse->nTab;
|
||||
sqlite3OpenTableAndIndices(pParse, pTab, base, OP_OpenWrite);
|
||||
idx = sqliteOpenTableAndIndices(pParse, pTab, base);
|
||||
pParse->nTab += idx;
|
||||
}
|
||||
|
||||
/* Push the record number for the new entry onto the stack. The
|
||||
@@ -514,21 +420,21 @@ void sqlite3Insert(
|
||||
if( !isView ){
|
||||
if( keyColumn>=0 ){
|
||||
if( useTempTable ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, srcTab, keyColumn);
|
||||
sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
|
||||
}else if( pSelect ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nColumn - keyColumn - 1, 1);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nColumn - keyColumn - 1, 1);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr);
|
||||
sqliteExprCode(pParse, pList->a[keyColumn].pExpr);
|
||||
}
|
||||
/* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
|
||||
** to generate a unique primary key value.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRecno, base, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_NotNull, -1, sqliteVdbeCurrentAddr(v)+3);
|
||||
sqliteVdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
|
||||
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_NewRecno, base, 0);
|
||||
sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
|
||||
}
|
||||
|
||||
/* Push onto the stack, data for all columns of the new entry, beginning
|
||||
@@ -540,7 +446,7 @@ void sqlite3Insert(
|
||||
** Whenever this column is read, the record number will be substituted
|
||||
** in its place. So will fill this column with a NULL to avoid
|
||||
** taking up data space with information that will never be used. */
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
continue;
|
||||
}
|
||||
if( pColumn==0 ){
|
||||
@@ -551,42 +457,42 @@ void sqlite3Insert(
|
||||
}
|
||||
}
|
||||
if( pColumn && j>=pColumn->nId ){
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
}else if( useTempTable ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, srcTab, j);
|
||||
sqliteVdbeAddOp(v, OP_Column, srcTab, j);
|
||||
}else if( pSelect ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, i+nColumn-j, 1);
|
||||
sqliteVdbeAddOp(v, OP_Dup, i+nColumn-j, 1);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pList->a[j].pExpr);
|
||||
sqliteExprCode(pParse, pList->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate code to check constraints and generate index keys and
|
||||
** do the insertion.
|
||||
*/
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, base, 0, keyColumn>=0,
|
||||
sqliteGenerateConstraintChecks(pParse, pTab, base, 0, keyColumn>=0,
|
||||
0, onError, endOfLoop);
|
||||
sqlite3CompleteInsertion(pParse, pTab, base, 0,0,0,
|
||||
sqliteCompleteInsertion(pParse, pTab, base, 0,0,0,
|
||||
after_triggers ? newIdx : -1);
|
||||
}
|
||||
|
||||
/* Update the count of rows that are inserted
|
||||
*/
|
||||
if( (db->flags & SQLITE_CountRows)!=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, iCntMem, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemIncr, iCntMem, 0);
|
||||
}
|
||||
|
||||
if( row_triggers_exist ){
|
||||
/* Close all tables opened */
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, base, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, base, 0);
|
||||
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
|
||||
sqlite3VdbeAddOp(v, OP_Close, idx+base, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, idx+base, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Code AFTER triggers */
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TK_AFTER, pTab, newIdx, -1,
|
||||
if( sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_AFTER, pTab, newIdx, -1,
|
||||
onError, endOfLoop) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
@@ -594,42 +500,42 @@ void sqlite3Insert(
|
||||
|
||||
/* The bottom of the loop, if the data source is a SELECT statement
|
||||
*/
|
||||
sqlite3VdbeResolveLabel(v, endOfLoop);
|
||||
sqliteVdbeResolveLabel(v, endOfLoop);
|
||||
if( useTempTable ){
|
||||
sqlite3VdbeAddOp(v, OP_Next, srcTab, iCont);
|
||||
sqlite3VdbeResolveLabel(v, iBreak);
|
||||
sqlite3VdbeAddOp(v, OP_Close, srcTab, 0);
|
||||
sqliteVdbeAddOp(v, OP_Next, srcTab, iCont);
|
||||
sqliteVdbeResolveLabel(v, iBreak);
|
||||
sqliteVdbeAddOp(v, OP_Close, srcTab, 0);
|
||||
}else if( pSelect ){
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Return, 0, 0);
|
||||
sqlite3VdbeResolveLabel(v, iCleanup);
|
||||
sqliteVdbeAddOp(v, OP_Pop, nColumn, 0);
|
||||
sqliteVdbeAddOp(v, OP_Return, 0, 0);
|
||||
sqliteVdbeResolveLabel(v, iCleanup);
|
||||
}
|
||||
|
||||
if( !row_triggers_exist ){
|
||||
/* Close all tables opened */
|
||||
sqlite3VdbeAddOp(v, OP_Close, base, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, base, 0);
|
||||
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
|
||||
sqlite3VdbeAddOp(v, OP_Close, idx+base, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, idx+base, 0);
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
sqliteVdbeAddOp(v, OP_SetCounts, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
|
||||
/*
|
||||
** Return the number of rows inserted.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iCntMem, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "rows inserted", P3_STATIC);
|
||||
sqliteVdbeOp3(v, OP_ColumnName, 0, 1, "rows inserted", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_MemLoad, iCntMem, 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
|
||||
insert_cleanup:
|
||||
sqlite3SrcListDelete(pTabList);
|
||||
if( pList ) sqlite3ExprListDelete(pList);
|
||||
if( pSelect ) sqlite3SelectDelete(pSelect);
|
||||
sqlite3IdListDelete(pColumn);
|
||||
sqliteSrcListDelete(pTabList);
|
||||
if( pList ) sqliteExprListDelete(pList);
|
||||
if( pSelect ) sqliteSelectDelete(pSelect);
|
||||
sqliteIdListDelete(pColumn);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -668,12 +574,12 @@ insert_cleanup:
|
||||
** Constraint type Action What Happens
|
||||
** --------------- ---------- ----------------------------------------
|
||||
** any ROLLBACK The current transaction is rolled back and
|
||||
** sqlite3_exec() returns immediately with a
|
||||
** sqlite_exec() returns immediately with a
|
||||
** return code of SQLITE_CONSTRAINT.
|
||||
**
|
||||
** any ABORT Back out changes from the current command
|
||||
** only (do not do a complete rollback) then
|
||||
** cause sqlite3_exec() to return immediately
|
||||
** cause sqlite_exec() to return immediately
|
||||
** with SQLITE_CONSTRAINT.
|
||||
**
|
||||
** any FAIL Sqlite_exec() returns immediately with a
|
||||
@@ -711,7 +617,7 @@ insert_cleanup:
|
||||
** is still pointing at the same entry after the routine returns.
|
||||
** Without the isUpdate flag, the "base" cursor might be moved.
|
||||
*/
|
||||
void sqlite3GenerateConstraintChecks(
|
||||
void sqliteGenerateConstraintChecks(
|
||||
Parse *pParse, /* The parser context */
|
||||
Table *pTab, /* the table into which we are inserting */
|
||||
int base, /* Index of a read/write cursor pointing at pTab */
|
||||
@@ -730,11 +636,11 @@ void sqlite3GenerateConstraintChecks(
|
||||
int iCur;
|
||||
Index *pIdx;
|
||||
int seenReplace = 0;
|
||||
int jumpInst1=0, jumpInst2;
|
||||
int jumpInst1, jumpInst2;
|
||||
int contAddr;
|
||||
int hasTwoRecnos = (isUpdate && recnoChng);
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
v = sqliteGetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
|
||||
nCol = pTab->nCol;
|
||||
@@ -749,38 +655,40 @@ void sqlite3GenerateConstraintChecks(
|
||||
if( onError==OE_None ) continue;
|
||||
if( overrideError!=OE_Default ){
|
||||
onError = overrideError;
|
||||
}else if( pParse->db->onError!=OE_Default ){
|
||||
onError = pParse->db->onError;
|
||||
}else if( onError==OE_Default ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
if( onError==OE_Replace && pTab->aCol[i].zDflt==0 ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol-1-i, 1);
|
||||
addr = sqlite3VdbeAddOp(v, OP_NotNull, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol-1-i, 1);
|
||||
addr = sqliteVdbeAddOp(v, OP_NotNull, 1, 0);
|
||||
switch( onError ){
|
||||
case OE_Rollback:
|
||||
case OE_Abort:
|
||||
case OE_Fail: {
|
||||
char *zMsg = 0;
|
||||
sqlite3VdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, onError);
|
||||
sqlite3SetString(&zMsg, pTab->zName, ".", pTab->aCol[i].zName,
|
||||
sqliteVdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, onError);
|
||||
sqliteSetString(&zMsg, pTab->zName, ".", pTab->aCol[i].zName,
|
||||
" may not be NULL", (char*)0);
|
||||
sqlite3VdbeChangeP3(v, -1, zMsg, P3_DYNAMIC);
|
||||
sqliteVdbeChangeP3(v, -1, zMsg, P3_DYNAMIC);
|
||||
break;
|
||||
}
|
||||
case OE_Ignore: {
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
sqliteVdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
case OE_Replace: {
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqlite3VdbeAddOp(v, OP_Push, nCol-i, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Push, nCol-i, 0);
|
||||
break;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
|
||||
sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
|
||||
}
|
||||
|
||||
/* Test all CHECK constraints
|
||||
@@ -795,17 +703,19 @@ void sqlite3GenerateConstraintChecks(
|
||||
onError = pTab->keyConf;
|
||||
if( overrideError!=OE_Default ){
|
||||
onError = overrideError;
|
||||
}else if( pParse->db->onError!=OE_Default ){
|
||||
onError = pParse->db->onError;
|
||||
}else if( onError==OE_Default ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
|
||||
if( isUpdate ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
jumpInst1 = sqlite3VdbeAddOp(v, OP_Eq, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
jumpInst1 = sqliteVdbeAddOp(v, OP_Eq, 0, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol, 1);
|
||||
jumpInst2 = sqlite3VdbeAddOp(v, OP_NotExists, base, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol, 1);
|
||||
jumpInst2 = sqliteVdbeAddOp(v, OP_NotExists, base, 0);
|
||||
switch( onError ){
|
||||
default: {
|
||||
onError = OE_Abort;
|
||||
@@ -814,32 +724,32 @@ void sqlite3GenerateConstraintChecks(
|
||||
case OE_Rollback:
|
||||
case OE_Abort:
|
||||
case OE_Fail: {
|
||||
sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError,
|
||||
sqliteVdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError,
|
||||
"PRIMARY KEY must be unique", P3_STATIC);
|
||||
break;
|
||||
}
|
||||
case OE_Replace: {
|
||||
sqlite3GenerateRowIndexDelete(pParse->db, v, pTab, base, 0);
|
||||
sqliteGenerateRowIndexDelete(pParse->db, v, pTab, base, 0);
|
||||
if( isUpdate ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+hasTwoRecnos, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+hasTwoRecnos, 1);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
|
||||
}
|
||||
seenReplace = 1;
|
||||
break;
|
||||
}
|
||||
case OE_Ignore: {
|
||||
assert( seenReplace==0 );
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
sqliteVdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
}
|
||||
contAddr = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3VdbeChangeP2(v, jumpInst2, contAddr);
|
||||
contAddr = sqliteVdbeCurrentAddr(v);
|
||||
sqliteVdbeChangeP2(v, jumpInst2, contAddr);
|
||||
if( isUpdate ){
|
||||
sqlite3VdbeChangeP2(v, jumpInst1, contAddr);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
|
||||
sqliteVdbeChangeP2(v, jumpInst1, contAddr);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -853,23 +763,25 @@ void sqlite3GenerateConstraintChecks(
|
||||
extra++;
|
||||
|
||||
/* Create a key for accessing the index entry */
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+extra, 1);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+extra, 1);
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
int idx = pIdx->aiColumn[i];
|
||||
if( idx==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, i+extra+nCol+1, 1);
|
||||
sqliteVdbeAddOp(v, OP_Dup, i+extra+nCol+1, 1);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Dup, i+extra+nCol-idx, 1);
|
||||
sqliteVdbeAddOp(v, OP_Dup, i+extra+nCol-idx, 1);
|
||||
}
|
||||
}
|
||||
jumpInst1 = sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24));
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
jumpInst1 = sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
|
||||
if( pParse->db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
|
||||
|
||||
/* Find out what action to take in case there is an indexing conflict */
|
||||
onError = pIdx->onError;
|
||||
if( onError==OE_None ) continue; /* pIdx is not a UNIQUE index */
|
||||
if( overrideError!=OE_Default ){
|
||||
onError = overrideError;
|
||||
}else if( pParse->db->onError!=OE_Default ){
|
||||
onError = pParse->db->onError;
|
||||
}else if( onError==OE_Default ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
@@ -880,8 +792,8 @@ void sqlite3GenerateConstraintChecks(
|
||||
|
||||
|
||||
/* Check to see if the new index entry will be unique */
|
||||
sqlite3VdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRecnos, 1);
|
||||
jumpInst2 = sqlite3VdbeAddOp(v, OP_IsUnique, base+iCur+1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRecnos, 1);
|
||||
jumpInst2 = sqliteVdbeAddOp(v, OP_IsUnique, base+iCur+1, 0);
|
||||
|
||||
/* Generate code that executes if the new index entry is not unique */
|
||||
switch( onError ){
|
||||
@@ -910,46 +822,45 @@ void sqlite3GenerateConstraintChecks(
|
||||
}
|
||||
strcpy(&zErrMsg[n1],
|
||||
pIdx->nColumn>1 ? " are not unique" : " is not unique");
|
||||
sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError, zErrMsg, 0);
|
||||
sqliteVdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError, zErrMsg, 0);
|
||||
break;
|
||||
}
|
||||
case OE_Ignore: {
|
||||
assert( seenReplace==0 );
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRecnos, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
sqliteVdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRecnos, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
case OE_Replace: {
|
||||
sqlite3GenerateRowDelete(pParse->db, v, pTab, base, 0);
|
||||
sqliteGenerateRowDelete(pParse->db, v, pTab, base, 0);
|
||||
if( isUpdate ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRecnos, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRecnos, 1);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
|
||||
}
|
||||
seenReplace = 1;
|
||||
break;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
contAddr = sqlite3VdbeCurrentAddr(v);
|
||||
assert( contAddr<(1<<24) );
|
||||
contAddr = sqliteVdbeCurrentAddr(v);
|
||||
#if NULL_DISTINCT_FOR_UNIQUE
|
||||
sqlite3VdbeChangeP2(v, jumpInst1, contAddr | (1<<24));
|
||||
sqliteVdbeChangeP2(v, jumpInst1, contAddr);
|
||||
#endif
|
||||
sqlite3VdbeChangeP2(v, jumpInst2, contAddr);
|
||||
sqliteVdbeChangeP2(v, jumpInst2, contAddr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine generates code to finish the INSERT or UPDATE operation
|
||||
** that was started by a prior call to sqlite3GenerateConstraintChecks.
|
||||
** that was started by a prior call to sqliteGenerateConstraintChecks.
|
||||
** The stack must contain keys for all active indices followed by data
|
||||
** and the recno for the new entry. This routine creates the new
|
||||
** entries in all indices and in the main table.
|
||||
**
|
||||
** The arguments to this routine should be the same as the first six
|
||||
** arguments to sqlite3GenerateConstraintChecks.
|
||||
** arguments to sqliteGenerateConstraintChecks.
|
||||
*/
|
||||
void sqlite3CompleteInsertion(
|
||||
void sqliteCompleteInsertion(
|
||||
Parse *pParse, /* The parser context */
|
||||
Table *pTab, /* the table into which we are inserting */
|
||||
int base, /* Index of a read/write cursor pointing at pTab */
|
||||
@@ -962,55 +873,47 @@ void sqlite3CompleteInsertion(
|
||||
Vdbe *v;
|
||||
int nIdx;
|
||||
Index *pIdx;
|
||||
int pik_flags;
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
v = sqliteGetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
|
||||
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
|
||||
for(i=nIdx-1; i>=0; i--){
|
||||
if( aIdxUsed && aIdxUsed[i]==0 ) continue;
|
||||
sqlite3VdbeAddOp(v, OP_IdxPut, base+i+1, 0);
|
||||
sqliteVdbeAddOp(v, OP_IdxPut, base+i+1, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
if( newIdx>=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
}
|
||||
pik_flags = (OPFLAG_NCHANGE|(isUpdate?0:OPFLAG_LASTROWID));
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, base, pik_flags);
|
||||
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, base,
|
||||
(pParse->trigStack?0:OPFLAG_NCHANGE) |
|
||||
(isUpdate?0:OPFLAG_LASTROWID) | OPFLAG_CSCHANGE);
|
||||
if( isUpdate && recnoChng ){
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Pop, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code that will open cursors for a table and for all
|
||||
** Generate code that will open write cursors for a table and for all
|
||||
** indices of that table. The "base" parameter is the cursor number used
|
||||
** for the table. Indices are opened on subsequent cursors.
|
||||
**
|
||||
** Return the total number of cursors opened. This is always at least
|
||||
** 1 (for the main table) plus more for each cursor.
|
||||
*/
|
||||
void sqlite3OpenTableAndIndices(
|
||||
Parse *pParse, /* Parsing context */
|
||||
Table *pTab, /* Table to be opened */
|
||||
int base, /* Cursor number assigned to the table */
|
||||
int op /* OP_OpenRead or OP_OpenWrite */
|
||||
){
|
||||
int sqliteOpenTableAndIndices(Parse *pParse, Table *pTab, int base){
|
||||
int i;
|
||||
Index *pIdx;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
Vdbe *v = sqliteGetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, op, base, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, base, pTab->nCol);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenWrite, base, pTab->tnum, pTab->zName, P3_STATIC);
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqlite3VdbeOp3(v, op, i+base, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
}
|
||||
if( pParse->nTab<=base+i ){
|
||||
pParse->nTab = base+i;
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenWrite, i+base, pIdx->tnum, pIdx->zName, P3_STATIC);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
-138
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
** 2001 September 15
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** Main file for the SQLite library. The routines in this file
|
||||
** implement the programmer interface to the library. Routines in
|
||||
** other files are for internal use by SQLite and should not be
|
||||
** accessed by users of the library.
|
||||
**
|
||||
** $Id: legacy.c,v 1.5 2004/08/08 23:39:19 drh Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
** 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 sqlite3_exec(
|
||||
sqlite *db, /* The database on which the SQL executes */
|
||||
const char *zSql, /* The SQL to be executed */
|
||||
sqlite_callback xCallback, /* Invoke this callback routine */
|
||||
void *pArg, /* First argument to xCallback() */
|
||||
char **pzErrMsg /* Write error messages here */
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
const char *zLeftover;
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
char **azCols = 0;
|
||||
|
||||
int nRetry = 0;
|
||||
int nChange = 0;
|
||||
int nCallback;
|
||||
|
||||
if( zSql==0 ) return SQLITE_OK;
|
||||
while( (rc==SQLITE_OK || (rc==SQLITE_SCHEMA && (++nRetry)<2)) && zSql[0] ){
|
||||
int nCol;
|
||||
char **azVals = 0;
|
||||
|
||||
pStmt = 0;
|
||||
rc = sqlite3_prepare(db, zSql, -1, &pStmt, &zLeftover);
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( pStmt ) sqlite3_finalize(pStmt);
|
||||
continue;
|
||||
}
|
||||
if( !pStmt ){
|
||||
/* this happens for a comment or white-space */
|
||||
zSql = zLeftover;
|
||||
continue;
|
||||
}
|
||||
|
||||
db->nChange += nChange;
|
||||
nCallback = 0;
|
||||
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
azCols = sqliteMalloc(2*nCol*sizeof(const char *));
|
||||
if( nCol && !azCols ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto exec_out;
|
||||
}
|
||||
|
||||
while( 1 ){
|
||||
int i;
|
||||
rc = sqlite3_step(pStmt);
|
||||
|
||||
/* Invoke the callback function if required */
|
||||
if( xCallback && (SQLITE_ROW==rc ||
|
||||
(SQLITE_DONE==rc && !nCallback && db->flags&SQLITE_NullCallback)) ){
|
||||
if( 0==nCallback ){
|
||||
for(i=0; i<nCol; i++){
|
||||
azCols[i] = (char *)sqlite3_column_name(pStmt, i);
|
||||
}
|
||||
nCallback++;
|
||||
}
|
||||
if( rc==SQLITE_ROW ){
|
||||
azVals = &azCols[nCol];
|
||||
for(i=0; i<nCol; i++){
|
||||
azVals[i] = (char *)sqlite3_column_text(pStmt, i);
|
||||
}
|
||||
}
|
||||
if( xCallback(pArg, nCol, azVals, azCols) ){
|
||||
rc = SQLITE_ABORT;
|
||||
goto exec_out;
|
||||
}
|
||||
}
|
||||
|
||||
if( rc!=SQLITE_ROW ){
|
||||
rc = sqlite3_finalize(pStmt);
|
||||
pStmt = 0;
|
||||
if( db->pVdbe==0 ){
|
||||
nChange = db->nChange;
|
||||
}
|
||||
if( rc!=SQLITE_SCHEMA ){
|
||||
nRetry = 0;
|
||||
zSql = zLeftover;
|
||||
while( isspace((unsigned char)zSql[0]) ) zSql++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sqliteFree(azCols);
|
||||
azCols = 0;
|
||||
}
|
||||
|
||||
exec_out:
|
||||
if( pStmt ) sqlite3_finalize(pStmt);
|
||||
if( azCols ) sqliteFree(azCols);
|
||||
|
||||
if( sqlite3_malloc_failed ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
|
||||
*pzErrMsg = malloc(1+strlen(sqlite3_errmsg(db)));
|
||||
if( *pzErrMsg ){
|
||||
strcpy(*pzErrMsg, sqlite3_errmsg(db));
|
||||
}
|
||||
}else if( pzErrMsg ){
|
||||
*pzErrMsg = 0;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
+711
-928
File diff suppressed because it is too large
Load Diff
@@ -30,7 +30,7 @@
|
||||
*/
|
||||
#include <tcl.h>
|
||||
#include <string.h>
|
||||
#include "sqlite3.h"
|
||||
#include "sqlite.h"
|
||||
|
||||
/*
|
||||
* If compiled on a machine that doesn't have a 32-bit integer,
|
||||
@@ -356,32 +356,30 @@ int Md5_Init(Tcl_Interp *interp){
|
||||
** During testing, the special md5sum() aggregate function is available.
|
||||
** inside SQLite. The following routines implement that function.
|
||||
*/
|
||||
static void md5step(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
static void md5step(sqlite_func *context, int argc, const char **argv){
|
||||
MD5Context *p;
|
||||
int i;
|
||||
if( argc<1 ) return;
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
if( p==0 ) return;
|
||||
if( sqlite3_aggregate_count(context)==1 ){
|
||||
if( sqlite_aggregate_count(context)==1 ){
|
||||
MD5Init(p);
|
||||
}
|
||||
for(i=0; i<argc; i++){
|
||||
const char *zData = sqlite3_value_text(argv[i]);
|
||||
if( zData ){
|
||||
MD5Update(p, zData, strlen(zData));
|
||||
if( argv[i] ){
|
||||
MD5Update(p, (unsigned char*)argv[i], strlen(argv[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
static void md5finalize(sqlite3_context *context){
|
||||
static void md5finalize(sqlite_func *context){
|
||||
MD5Context *p;
|
||||
unsigned char digest[16];
|
||||
char zBuf[33];
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
MD5Final(digest,p);
|
||||
DigestToBase16(digest, zBuf);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
sqlite_set_result_string(context, zBuf, strlen(zBuf));
|
||||
}
|
||||
void Md5_Register(sqlite3 *db){
|
||||
sqlite3_create_function(db, "md5sum", -1, SQLITE_UTF8, 0, 0,
|
||||
md5step, md5finalize);
|
||||
void Md5_Register(sqlite *db){
|
||||
sqlite_create_aggregate(db, "md5sum", -1, md5step, md5finalize, 0);
|
||||
}
|
||||
|
||||
@@ -17,13 +17,54 @@
|
||||
#ifndef _SQLITE_OS_H_
|
||||
#define _SQLITE_OS_H_
|
||||
|
||||
/*
|
||||
** Helpful hint: To get this to compile on HP/UX, add -D_INCLUDE_POSIX_SOURCE
|
||||
** to the compiler command line.
|
||||
*/
|
||||
|
||||
/*
|
||||
** These #defines should enable >2GB file support on Posix if the
|
||||
** underlying operating system supports it. If the OS lacks
|
||||
** large file support, or if the OS is windows, these should be no-ops.
|
||||
**
|
||||
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
|
||||
** on the compiler command line. This is necessary if you are compiling
|
||||
** on a recent machine (ex: RedHat 7.2) but you want your code to work
|
||||
** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2
|
||||
** without this option, LFS is enable. But LFS does not exist in the kernel
|
||||
** in RedHat 6.0, so the code won't work. Hence, for maximum binary
|
||||
** portability you should omit LFS.
|
||||
**
|
||||
** Similar is true for MacOS. LFS is only supported on MacOS 9 and later.
|
||||
*/
|
||||
#ifndef SQLITE_DISABLE_LFS
|
||||
# define _LARGE_FILE 1
|
||||
# ifndef _FILE_OFFSET_BITS
|
||||
# define _FILE_OFFSET_BITS 64
|
||||
# endif
|
||||
# define _LARGEFILE_SOURCE 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Temporary files are named starting with this prefix followed by 16 random
|
||||
** alphanumeric characters, and no file extension. They are stored in the
|
||||
** OS's standard temporary file directory, and are deleted prior to exit.
|
||||
** If sqlite is being embedded in another program, you may wish to change the
|
||||
** prefix to reflect your program's name, so that if your program exits
|
||||
** prematurely, old temporary files can be easily identified. This can be done
|
||||
** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
|
||||
*/
|
||||
#ifndef TEMP_FILE_PREFIX
|
||||
# define TEMP_FILE_PREFIX "sqlite_"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Figure out if we are dealing with Unix, Windows or MacOS.
|
||||
**
|
||||
** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
|
||||
** The MacOS build is designed to use CodeWarrior (tested with v8)
|
||||
*/
|
||||
#if !defined(OS_UNIX) && !defined(OS_TEST)
|
||||
#ifndef OS_UNIX
|
||||
# ifndef OS_WIN
|
||||
# ifndef OS_MAC
|
||||
# if defined(__MACOS__)
|
||||
@@ -55,143 +96,96 @@
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Invoke the appropriate operating-system specific header file.
|
||||
** A handle for an open file is stored in an OsFile object.
|
||||
*/
|
||||
#if OS_TEST
|
||||
# include "os_test.h"
|
||||
#endif
|
||||
#if OS_UNIX
|
||||
# include "os_unix.h"
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
struct openCnt *pOpen; /* Info about all open fd's on this inode */
|
||||
struct lockInfo *pLock; /* Info about locks on this inode */
|
||||
int fd; /* The file descriptor */
|
||||
int locked; /* True if this instance holds the lock */
|
||||
int dirfd; /* File descriptor for the directory */
|
||||
};
|
||||
# define SQLITE_TEMPNAME_SIZE 200
|
||||
# if defined(HAVE_USLEEP) && HAVE_USLEEP
|
||||
# define SQLITE_MIN_SLEEP_MS 1
|
||||
# else
|
||||
# define SQLITE_MIN_SLEEP_MS 1000
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if OS_WIN
|
||||
# include "os_win.h"
|
||||
#include <windows.h>
|
||||
#include <winbase.h>
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
HANDLE h; /* Handle for accessing the file */
|
||||
int locked; /* 0: unlocked, <0: write lock, >0: read lock */
|
||||
};
|
||||
# if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 off_t;
|
||||
# else
|
||||
# if !defined(_CYGWIN_TYPES_H)
|
||||
typedef long long off_t;
|
||||
# if defined(__MINGW32__)
|
||||
# define _OFF_T_
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
|
||||
# define SQLITE_MIN_SLEEP_MS 1
|
||||
#endif
|
||||
|
||||
#if OS_MAC
|
||||
# include "os_mac.h"
|
||||
# include <unistd.h>
|
||||
# include <Files.h>
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
SInt16 refNum; /* Data fork/file reference number */
|
||||
SInt16 refNumRF; /* Resource fork reference number (for locking) */
|
||||
int locked; /* 0: unlocked, <0: write lock, >0: read lock */
|
||||
int delOnClose; /* True if file is to be deleted on close */
|
||||
char *pathToDel; /* Name of file to delete on close */
|
||||
};
|
||||
# ifdef _LARGE_FILE
|
||||
typedef SInt64 off_t;
|
||||
# else
|
||||
typedef SInt32 off_t;
|
||||
# endif
|
||||
# define SQLITE_TEMPNAME_SIZE _MAX_PATH
|
||||
# define SQLITE_MIN_SLEEP_MS 17
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Temporary files are named starting with this prefix followed by 16 random
|
||||
** alphanumeric characters, and no file extension. They are stored in the
|
||||
** OS's standard temporary file directory, and are deleted prior to exit.
|
||||
** If sqlite is being embedded in another program, you may wish to change the
|
||||
** prefix to reflect your program's name, so that if your program exits
|
||||
** prematurely, old temporary files can be easily identified. This can be done
|
||||
** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
|
||||
*/
|
||||
#ifndef TEMP_FILE_PREFIX
|
||||
# define TEMP_FILE_PREFIX "sqlite_"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The following values may be passed as the second argument to
|
||||
** sqlite3OsLock(). The various locks exhibit the following semantics:
|
||||
**
|
||||
** SHARED: Any number of processes may hold a SHARED lock simultaneously.
|
||||
** RESERVED: A single process may hold a RESERVED lock on a file at
|
||||
** any time. Other processes may hold and obtain new SHARED locks.
|
||||
** PENDING: A single process may hold a PENDING lock on a file at
|
||||
** any one time. Existing SHARED locks may persist, but no new
|
||||
** SHARED locks may be obtained by other processes.
|
||||
** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
|
||||
**
|
||||
** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
|
||||
** process that requests an EXCLUSIVE lock may actually obtain a PENDING
|
||||
** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
|
||||
** sqlite3OsLock().
|
||||
*/
|
||||
#define NO_LOCK 0
|
||||
#define SHARED_LOCK 1
|
||||
#define RESERVED_LOCK 2
|
||||
#define PENDING_LOCK 3
|
||||
#define EXCLUSIVE_LOCK 4
|
||||
|
||||
/*
|
||||
** File Locking Notes: (Mostly about windows but also some info for Unix)
|
||||
**
|
||||
** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
|
||||
** those functions are not available. So we use only LockFile() and
|
||||
** UnlockFile().
|
||||
**
|
||||
** LockFile() prevents not just writing but also reading by other processes.
|
||||
** A SHARED_LOCK is obtained by locking a single randomly-chosen
|
||||
** byte out of a specific range of bytes. The lock byte is obtained at
|
||||
** random so two separate readers can probably access the file at the
|
||||
** same time, unless they are unlucky and choose the same lock byte.
|
||||
** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
|
||||
** There can only be one writer. A RESERVED_LOCK is obtained by locking
|
||||
** a single byte of the file that is designated as the reserved lock byte.
|
||||
** A PENDING_LOCK is obtained by locking a designated byte different from
|
||||
** the RESERVED_LOCK byte.
|
||||
**
|
||||
** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
|
||||
** which means we can use reader/writer locks. When reader/writer locks
|
||||
** are used, the lock is placed on the same range of bytes that is used
|
||||
** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
|
||||
** will support two or more Win95 readers or two or more WinNT readers.
|
||||
** But a single Win95 reader will lock out all WinNT readers and a single
|
||||
** WinNT reader will lock out all other Win95 readers.
|
||||
**
|
||||
** The following #defines specify the range of bytes used for locking.
|
||||
** SHARED_SIZE is the number of bytes available in the pool from which
|
||||
** a random byte is selected for a shared lock. The pool of bytes for
|
||||
** shared locks begins at SHARED_FIRST.
|
||||
**
|
||||
** These #defines are available in os.h so that Unix can use the same
|
||||
** byte ranges for locking. This leaves open the possiblity of having
|
||||
** clients on win95, winNT, and unix all talking to the same shared file
|
||||
** and all locking correctly. To do so would require that samba (or whatever
|
||||
** tool is being used for file sharing) implements locks correctly between
|
||||
** windows and unix. I'm guessing that isn't likely to happen, but by
|
||||
** using the same locking range we are at least open to the possibility.
|
||||
**
|
||||
** Locking in windows is manditory. For this reason, we cannot store
|
||||
** actual data in the bytes used for locking. The pager never allocates
|
||||
** the pages involved in locking therefore. SHARED_SIZE is selected so
|
||||
** that all locks will fit on a single page even at the minimum page size.
|
||||
** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
|
||||
** is set high so that we don't have to allocate an unused page except
|
||||
** for very large databases. But one should test the page skipping logic
|
||||
** by setting PENDING_BYTE low and running the entire regression suite.
|
||||
**
|
||||
** Changing the value of PENDING_BYTE results in a subtly incompatible
|
||||
** file format. Depending on how it is changed, you might not notice
|
||||
** the incompatibility right away, even running a full regression test.
|
||||
** The default location of PENDING_BYTE is the first byte past the
|
||||
** 1GB boundary.
|
||||
**
|
||||
*/
|
||||
#define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
|
||||
/* #define PENDING_BYTE 0x5400 // Page 20 - for testing */
|
||||
#define RESERVED_BYTE (PENDING_BYTE+1)
|
||||
#define SHARED_FIRST (PENDING_BYTE+2)
|
||||
#define SHARED_SIZE 510
|
||||
int sqliteOsDelete(const char*);
|
||||
int sqliteOsFileExists(const char*);
|
||||
int sqliteOsFileRename(const char*, const char*);
|
||||
int sqliteOsOpenReadWrite(const char*, OsFile*, int*);
|
||||
int sqliteOsOpenExclusive(const char*, OsFile*, int);
|
||||
int sqliteOsOpenReadOnly(const char*, OsFile*);
|
||||
int sqliteOsOpenDirectory(const char*, OsFile*);
|
||||
int sqliteOsTempFileName(char*);
|
||||
int sqliteOsClose(OsFile*);
|
||||
int sqliteOsRead(OsFile*, void*, int amt);
|
||||
int sqliteOsWrite(OsFile*, const void*, int amt);
|
||||
int sqliteOsSeek(OsFile*, off_t offset);
|
||||
int sqliteOsSync(OsFile*);
|
||||
int sqliteOsTruncate(OsFile*, off_t size);
|
||||
int sqliteOsFileSize(OsFile*, off_t *pSize);
|
||||
int sqliteOsReadLock(OsFile*);
|
||||
int sqliteOsWriteLock(OsFile*);
|
||||
int sqliteOsUnlock(OsFile*);
|
||||
int sqliteOsRandomSeed(char*);
|
||||
int sqliteOsSleep(int ms);
|
||||
int sqliteOsCurrentTime(double*);
|
||||
void sqliteOsEnterMutex(void);
|
||||
void sqliteOsLeaveMutex(void);
|
||||
char *sqliteOsFullPathname(const char*);
|
||||
|
||||
|
||||
int sqlite3OsDelete(const char*);
|
||||
int sqlite3OsFileExists(const char*);
|
||||
int sqlite3OsOpenReadWrite(const char*, OsFile*, int*);
|
||||
int sqlite3OsOpenExclusive(const char*, OsFile*, int);
|
||||
int sqlite3OsOpenReadOnly(const char*, OsFile*);
|
||||
int sqlite3OsOpenDirectory(const char*, OsFile*);
|
||||
int sqlite3OsSyncDirectory(const char*);
|
||||
int sqlite3OsTempFileName(char*);
|
||||
int sqlite3OsClose(OsFile*);
|
||||
int sqlite3OsRead(OsFile*, void*, int amt);
|
||||
int sqlite3OsWrite(OsFile*, const void*, int amt);
|
||||
int sqlite3OsSeek(OsFile*, off_t offset);
|
||||
int sqlite3OsSync(OsFile*);
|
||||
int sqlite3OsTruncate(OsFile*, off_t size);
|
||||
int sqlite3OsFileSize(OsFile*, off_t *pSize);
|
||||
int sqlite3OsRandomSeed(char*);
|
||||
int sqlite3OsSleep(int ms);
|
||||
int sqlite3OsCurrentTime(double*);
|
||||
int sqlite3OsFileModTime(OsFile*, double*);
|
||||
void sqlite3OsEnterMutex(void);
|
||||
void sqlite3OsLeaveMutex(void);
|
||||
char *sqlite3OsFullPathname(const char*);
|
||||
int sqlite3OsLock(OsFile*, int);
|
||||
int sqlite3OsUnlock(OsFile*, int);
|
||||
int sqlite3OsCheckReservedLock(OsFile *id);
|
||||
|
||||
#endif /* _SQLITE_OS_H_ */
|
||||
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
** 2004 May 22
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This file contains macros and a little bit of code that is common to
|
||||
** all of the platform-specific files (os_*.c) and is #included into those
|
||||
** files.
|
||||
**
|
||||
** This file should be #included by the os_*.c files only. It is not a
|
||||
** general purpose header file.
|
||||
*/
|
||||
|
||||
/*
|
||||
** At least two bugs have slipped in because we changed the MEMORY_DEBUG
|
||||
** macro to SQLITE_DEBUG and some older makefiles have not yet made the
|
||||
** switch. The following code should catch this problem at compile-time.
|
||||
*/
|
||||
#ifdef MEMORY_DEBUG
|
||||
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
|
||||
#endif
|
||||
|
||||
|
||||
int sqlite3_os_trace = 0;
|
||||
#ifdef SQLITE_DEBUG
|
||||
static int last_page = 0;
|
||||
#define SEEK(X) last_page=(X)
|
||||
#define TRACE1(X) if( sqlite3_os_trace ) sqlite3DebugPrintf(X)
|
||||
#define TRACE2(X,Y) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y)
|
||||
#define TRACE3(X,Y,Z) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z)
|
||||
#define TRACE4(X,Y,Z,A) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A)
|
||||
#define TRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B)
|
||||
#define TRACE6(X,Y,Z,A,B,C) if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C)
|
||||
#define TRACE7(X,Y,Z,A,B,C,D) \
|
||||
if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C,D)
|
||||
#else
|
||||
#define SEEK(X)
|
||||
#define TRACE1(X)
|
||||
#define TRACE2(X,Y)
|
||||
#define TRACE3(X,Y,Z)
|
||||
#define TRACE4(X,Y,Z,A)
|
||||
#define TRACE5(X,Y,Z,A,B)
|
||||
#define TRACE6(X,Y,Z,A,B,C)
|
||||
#define TRACE7(X,Y,Z,A,B,C,D)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Macros for performance tracing. Normally turned off. Only works
|
||||
** on i486 hardware.
|
||||
*/
|
||||
#ifdef SQLITE_PERFORMANCE_TRACE
|
||||
__inline__ unsigned long long int hwtime(void){
|
||||
unsigned long long int x;
|
||||
__asm__("rdtsc\n\t"
|
||||
"mov %%edx, %%ecx\n\t"
|
||||
:"=A" (x));
|
||||
return x;
|
||||
}
|
||||
static unsigned long long int g_start;
|
||||
static unsigned int elapse;
|
||||
#define TIMER_START g_start=hwtime()
|
||||
#define TIMER_END elapse=hwtime()-g_start
|
||||
#define TIMER_ELAPSED elapse
|
||||
#else
|
||||
#define TIMER_START
|
||||
#define TIMER_END
|
||||
#define TIMER_ELAPSED 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
** If we compile with the SQLITE_TEST macro set, then the following block
|
||||
** of code will give us the ability to simulate a disk I/O error. This
|
||||
** is used for testing the I/O recovery logic.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_io_error_pending = 0;
|
||||
#define SimulateIOError(A) \
|
||||
if( sqlite3_io_error_pending ) \
|
||||
if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
|
||||
static void local_ioerr(){
|
||||
sqlite3_io_error_pending = 0; /* Really just a place to set a breakpoint */
|
||||
}
|
||||
#else
|
||||
#define SimulateIOError(A)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** When testing, keep a count of the number of open files.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_open_file_count = 0;
|
||||
#define OpenCounter(X) sqlite3_open_file_count+=(X)
|
||||
#else
|
||||
#define OpenCounter(X)
|
||||
#endif
|
||||
-738
@@ -1,738 +0,0 @@
|
||||
/*
|
||||
** 2004 May 22
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This file contains code that is specific classic mac. Mac OS X
|
||||
** uses the os_unix.c file, not this one.
|
||||
*/
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
#if OS_MAC /* This file used on classic mac only */
|
||||
#include "sqliteInt.h"
|
||||
|
||||
#include <extras.h>
|
||||
#include <path2fss.h>
|
||||
#include <TextUtils.h>
|
||||
#include <FinderRegistry.h>
|
||||
#include <Folders.h>
|
||||
#include <Timer.h>
|
||||
#include <OSUtils.h>
|
||||
|
||||
/*
|
||||
** Macros used to determine whether or not to use threads.
|
||||
*/
|
||||
#if defined(THREADSAFE) && THREADSAFE
|
||||
# include <Multiprocessing.h>
|
||||
# define SQLITE_MACOS_MULTITASKING 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Include code that is common to all os_*.c files
|
||||
*/
|
||||
#include "os_common.h"
|
||||
|
||||
/*
|
||||
** Delete the named file
|
||||
*/
|
||||
int sqlite3OsDelete(const char *zFilename){
|
||||
unlink(zFilename);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return TRUE if the named file exists.
|
||||
*/
|
||||
int sqlite3OsFileExists(const char *zFilename){
|
||||
return access(zFilename, 0)==0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to open a file for both reading and writing. If that
|
||||
** fails, try opening it read-only. If the file does not exist,
|
||||
** try to create it.
|
||||
**
|
||||
** On success, a handle for the open file is written to *id
|
||||
** and *pReadonly is set to 0 if the file was opened for reading and
|
||||
** writing or 1 if the file was opened read-only. The function returns
|
||||
** SQLITE_OK.
|
||||
**
|
||||
** On failure, the function returns SQLITE_CANTOPEN and leaves
|
||||
** *id and *pReadonly unchanged.
|
||||
*/
|
||||
int sqlite3OsOpenReadWrite(
|
||||
const char *zFilename,
|
||||
OsFile *id,
|
||||
int *pReadonly
|
||||
){
|
||||
FSSpec fsSpec;
|
||||
# ifdef _LARGE_FILE
|
||||
HFSUniStr255 dfName;
|
||||
FSRef fsRef;
|
||||
if( __path2fss(zFilename, &fsSpec) != noErr ){
|
||||
if( HCreate(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, 'SQLI', cDocumentFile) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
if( FSpMakeFSRef(&fsSpec, &fsRef) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
FSGetDataForkName(&dfName);
|
||||
if( FSOpenFork(&fsRef, dfName.length, dfName.unicode,
|
||||
fsRdWrShPerm, &(id->refNum)) != noErr ){
|
||||
if( FSOpenFork(&fsRef, dfName.length, dfName.unicode,
|
||||
fsRdWrPerm, &(id->refNum)) != noErr ){
|
||||
if (FSOpenFork(&fsRef, dfName.length, dfName.unicode,
|
||||
fsRdPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
else
|
||||
*pReadonly = 1;
|
||||
} else
|
||||
*pReadonly = 0;
|
||||
} else
|
||||
*pReadonly = 0;
|
||||
# else
|
||||
__path2fss(zFilename, &fsSpec);
|
||||
if( !sqlite3OsFileExists(zFilename) ){
|
||||
if( HCreate(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, 'SQLI', cDocumentFile) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
if( HOpenDF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdWrShPerm, &(id->refNum)) != noErr ){
|
||||
if( HOpenDF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdWrPerm, &(id->refNum)) != noErr ){
|
||||
if( HOpenDF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
else
|
||||
*pReadonly = 1;
|
||||
} else
|
||||
*pReadonly = 0;
|
||||
} else
|
||||
*pReadonly = 0;
|
||||
# endif
|
||||
if( HOpenRF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdWrShPerm, &(id->refNumRF)) != noErr){
|
||||
id->refNumRF = -1;
|
||||
}
|
||||
id->locked = 0;
|
||||
id->delOnClose = 0;
|
||||
OpenCounter(+1);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Attempt to open a new file for exclusive access by this process.
|
||||
** The file will be opened for both reading and writing. To avoid
|
||||
** a potential security problem, we do not allow the file to have
|
||||
** previously existed. Nor do we allow the file to be a symbolic
|
||||
** link.
|
||||
**
|
||||
** If delFlag is true, then make arrangements to automatically delete
|
||||
** the file when it is closed.
|
||||
**
|
||||
** On success, write the file handle into *id and return SQLITE_OK.
|
||||
**
|
||||
** On failure, return SQLITE_CANTOPEN.
|
||||
*/
|
||||
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
FSSpec fsSpec;
|
||||
# ifdef _LARGE_FILE
|
||||
HFSUniStr255 dfName;
|
||||
FSRef fsRef;
|
||||
__path2fss(zFilename, &fsSpec);
|
||||
if( HCreate(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, 'SQLI', cDocumentFile) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
if( FSpMakeFSRef(&fsSpec, &fsRef) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
FSGetDataForkName(&dfName);
|
||||
if( FSOpenFork(&fsRef, dfName.length, dfName.unicode,
|
||||
fsRdWrPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
# else
|
||||
__path2fss(zFilename, &fsSpec);
|
||||
if( HCreate(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, 'SQLI', cDocumentFile) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
if( HOpenDF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdWrPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
# endif
|
||||
id->refNumRF = -1;
|
||||
id->locked = 0;
|
||||
id->delOnClose = delFlag;
|
||||
if (delFlag)
|
||||
id->pathToDel = sqlite3OsFullPathname(zFilename);
|
||||
OpenCounter(+1);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to open a new file for read-only access.
|
||||
**
|
||||
** On success, write the file handle into *id and return SQLITE_OK.
|
||||
**
|
||||
** On failure, return SQLITE_CANTOPEN.
|
||||
*/
|
||||
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
|
||||
FSSpec fsSpec;
|
||||
# ifdef _LARGE_FILE
|
||||
HFSUniStr255 dfName;
|
||||
FSRef fsRef;
|
||||
if( __path2fss(zFilename, &fsSpec) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
if( FSpMakeFSRef(&fsSpec, &fsRef) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
FSGetDataForkName(&dfName);
|
||||
if( FSOpenFork(&fsRef, dfName.length, dfName.unicode,
|
||||
fsRdPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
# else
|
||||
__path2fss(zFilename, &fsSpec);
|
||||
if( HOpenDF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
# endif
|
||||
if( HOpenRF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdWrShPerm, &(id->refNumRF)) != noErr){
|
||||
id->refNumRF = -1;
|
||||
}
|
||||
id->locked = 0;
|
||||
id->delOnClose = 0;
|
||||
OpenCounter(+1);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to open a file descriptor for the directory that contains a
|
||||
** file. This file descriptor can be used to fsync() the directory
|
||||
** in order to make sure the creation of a new file is actually written
|
||||
** to disk.
|
||||
**
|
||||
** This routine is only meaningful for Unix. It is a no-op under
|
||||
** windows since windows does not support hard links.
|
||||
**
|
||||
** On success, a handle for a previously open file is at *id is
|
||||
** updated with the new directory file descriptor and SQLITE_OK is
|
||||
** returned.
|
||||
**
|
||||
** On failure, the function returns SQLITE_CANTOPEN and leaves
|
||||
** *id unchanged.
|
||||
*/
|
||||
int sqlite3OsOpenDirectory(
|
||||
const char *zDirname,
|
||||
OsFile *id
|
||||
){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a temporary file name in zBuf. zBuf must be big enough to
|
||||
** hold at least SQLITE_TEMPNAME_SIZE characters.
|
||||
*/
|
||||
int sqlite3OsTempFileName(char *zBuf){
|
||||
static char zChars[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"0123456789";
|
||||
int i, j;
|
||||
char zTempPath[SQLITE_TEMPNAME_SIZE];
|
||||
char zdirName[32];
|
||||
CInfoPBRec infoRec;
|
||||
Str31 dirName;
|
||||
memset(&infoRec, 0, sizeof(infoRec));
|
||||
memset(zTempPath, 0, SQLITE_TEMPNAME_SIZE);
|
||||
if( FindFolder(kOnSystemDisk, kTemporaryFolderType, kCreateFolder,
|
||||
&(infoRec.dirInfo.ioVRefNum), &(infoRec.dirInfo.ioDrParID)) == noErr ){
|
||||
infoRec.dirInfo.ioNamePtr = dirName;
|
||||
do{
|
||||
infoRec.dirInfo.ioFDirIndex = -1;
|
||||
infoRec.dirInfo.ioDrDirID = infoRec.dirInfo.ioDrParID;
|
||||
if( PBGetCatInfoSync(&infoRec) == noErr ){
|
||||
CopyPascalStringToC(dirName, zdirName);
|
||||
i = strlen(zdirName);
|
||||
memmove(&(zTempPath[i+1]), zTempPath, strlen(zTempPath));
|
||||
strcpy(zTempPath, zdirName);
|
||||
zTempPath[i] = ':';
|
||||
}else{
|
||||
*zTempPath = 0;
|
||||
break;
|
||||
}
|
||||
} while( infoRec.dirInfo.ioDrDirID != fsRtDirID );
|
||||
}
|
||||
if( *zTempPath == 0 )
|
||||
getcwd(zTempPath, SQLITE_TEMPNAME_SIZE-24);
|
||||
for(;;){
|
||||
sprintf(zBuf, "%s"TEMP_FILE_PREFIX, zTempPath);
|
||||
j = strlen(zBuf);
|
||||
sqlite3Randomness(15, &zBuf[j]);
|
||||
for(i=0; i<15; i++, j++){
|
||||
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
|
||||
}
|
||||
zBuf[j] = 0;
|
||||
if( !sqlite3OsFileExists(zBuf) ) break;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close a file.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile *id){
|
||||
if( id->refNumRF!=-1 )
|
||||
FSClose(id->refNumRF);
|
||||
# ifdef _LARGE_FILE
|
||||
FSCloseFork(id->refNum);
|
||||
# else
|
||||
FSClose(id->refNum);
|
||||
# endif
|
||||
if( id->delOnClose ){
|
||||
unlink(id->pathToDel);
|
||||
sqliteFree(id->pathToDel);
|
||||
}
|
||||
OpenCounter(-1);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Read data from a file into a buffer. Return SQLITE_OK if all
|
||||
** bytes were read successfully and SQLITE_IOERR if anything goes
|
||||
** wrong.
|
||||
*/
|
||||
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
int got;
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
TRACE2("READ %d\n", last_page);
|
||||
# ifdef _LARGE_FILE
|
||||
FSReadFork(id->refNum, fsAtMark, 0, (ByteCount)amt, pBuf, (ByteCount*)&got);
|
||||
# else
|
||||
got = amt;
|
||||
FSRead(id->refNum, &got, pBuf);
|
||||
# endif
|
||||
if( got==amt ){
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Write data from a buffer into a file. Return SQLITE_OK on success
|
||||
** or some other error code on failure.
|
||||
*/
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
OSErr oserr;
|
||||
int wrote = 0;
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
TRACE2("WRITE %d\n", last_page);
|
||||
while( amt>0 ){
|
||||
# ifdef _LARGE_FILE
|
||||
oserr = FSWriteFork(id->refNum, fsAtMark, 0,
|
||||
(ByteCount)amt, pBuf, (ByteCount*)&wrote);
|
||||
# else
|
||||
wrote = amt;
|
||||
oserr = FSWrite(id->refNum, &wrote, pBuf);
|
||||
# endif
|
||||
if( wrote == 0 || oserr != noErr)
|
||||
break;
|
||||
amt -= wrote;
|
||||
pBuf = &((char*)pBuf)[wrote];
|
||||
}
|
||||
if( oserr != noErr || amt>wrote ){
|
||||
return SQLITE_FULL;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Move the read/write pointer in a file.
|
||||
*/
|
||||
int sqlite3OsSeek(OsFile *id, off_t offset){
|
||||
off_t curSize;
|
||||
SEEK(offset/1024 + 1);
|
||||
if( sqlite3OsFileSize(id, &curSize) != SQLITE_OK ){
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
if( offset >= curSize ){
|
||||
if( sqlite3OsTruncate(id, offset+1) != SQLITE_OK ){
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
}
|
||||
# ifdef _LARGE_FILE
|
||||
if( FSSetForkPosition(id->refNum, fsFromStart, offset) != noErr ){
|
||||
# else
|
||||
if( SetFPos(id->refNum, fsFromStart, offset) != noErr ){
|
||||
# endif
|
||||
return SQLITE_IOERR;
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Make sure all writes to a particular file are committed to disk.
|
||||
**
|
||||
** Under Unix, also make sure that the directory entry for the file
|
||||
** has been created by fsync-ing the directory that contains the file.
|
||||
** If we do not do this and we encounter a power failure, the directory
|
||||
** entry for the journal might not exist after we reboot. The next
|
||||
** SQLite to access the file will not know that the journal exists (because
|
||||
** the directory entry for the journal was never created) and the transaction
|
||||
** will not roll back - possibly leading to database corruption.
|
||||
*/
|
||||
int sqlite3OsSync(OsFile *id){
|
||||
# ifdef _LARGE_FILE
|
||||
if( FSFlushFork(id->refNum) != noErr ){
|
||||
# else
|
||||
ParamBlockRec params;
|
||||
memset(¶ms, 0, sizeof(ParamBlockRec));
|
||||
params.ioParam.ioRefNum = id->refNum;
|
||||
if( PBFlushFileSync(¶ms) != noErr ){
|
||||
# endif
|
||||
return SQLITE_IOERR;
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Sync the directory zDirname. This is a no-op on operating systems other
|
||||
** than UNIX.
|
||||
*/
|
||||
int sqlite3OsSyncDirectory(const char *zDirname){
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate an open file to a specified size
|
||||
*/
|
||||
int sqlite3OsTruncate(OsFile *id, off_t nByte){
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
# ifdef _LARGE_FILE
|
||||
if( FSSetForkSize(id->refNum, fsFromStart, nByte) != noErr){
|
||||
# else
|
||||
if( SetEOF(id->refNum, nByte) != noErr ){
|
||||
# endif
|
||||
return SQLITE_IOERR;
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Determine the current size of a file in bytes
|
||||
*/
|
||||
int sqlite3OsFileSize(OsFile *id, off_t *pSize){
|
||||
# ifdef _LARGE_FILE
|
||||
if( FSGetForkSize(id->refNum, pSize) != noErr){
|
||||
# else
|
||||
if( GetEOF(id->refNum, pSize) != noErr ){
|
||||
# endif
|
||||
return SQLITE_IOERR;
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Windows file locking notes: [similar issues apply to MacOS]
|
||||
**
|
||||
** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
|
||||
** those functions are not available. So we use only LockFile() and
|
||||
** UnlockFile().
|
||||
**
|
||||
** LockFile() prevents not just writing but also reading by other processes.
|
||||
** (This is a design error on the part of Windows, but there is nothing
|
||||
** we can do about that.) So the region used for locking is at the
|
||||
** end of the file where it is unlikely to ever interfere with an
|
||||
** actual read attempt.
|
||||
**
|
||||
** A database read lock is obtained by locking a single randomly-chosen
|
||||
** byte out of a specific range of bytes. The lock byte is obtained at
|
||||
** random so two separate readers can probably access the file at the
|
||||
** same time, unless they are unlucky and choose the same lock byte.
|
||||
** A database write lock is obtained by locking all bytes in the range.
|
||||
** There can only be one writer.
|
||||
**
|
||||
** A lock is obtained on the first byte of the lock range before acquiring
|
||||
** either a read lock or a write lock. This prevents two processes from
|
||||
** attempting to get a lock at a same time. The semantics of
|
||||
** sqlite3OsReadLock() require that if there is already a write lock, that
|
||||
** lock is converted into a read lock atomically. The lock on the first
|
||||
** byte allows us to drop the old write lock and get the read lock without
|
||||
** another process jumping into the middle and messing us up. The same
|
||||
** argument applies to sqlite3OsWriteLock().
|
||||
**
|
||||
** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
|
||||
** which means we can use reader/writer locks. When reader writer locks
|
||||
** are used, the lock is placed on the same range of bytes that is used
|
||||
** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
|
||||
** will support two or more Win95 readers or two or more WinNT readers.
|
||||
** But a single Win95 reader will lock out all WinNT readers and a single
|
||||
** WinNT reader will lock out all other Win95 readers.
|
||||
**
|
||||
** Note: On MacOS we use the resource fork for locking.
|
||||
**
|
||||
** The following #defines specify the range of bytes used for locking.
|
||||
** N_LOCKBYTE is the number of bytes available for doing the locking.
|
||||
** The first byte used to hold the lock while the lock is changing does
|
||||
** not count toward this number. FIRST_LOCKBYTE is the address of
|
||||
** the first byte in the range of bytes used for locking.
|
||||
*/
|
||||
#define N_LOCKBYTE 10239
|
||||
#define FIRST_LOCKBYTE (0x000fffff - N_LOCKBYTE)
|
||||
|
||||
/*
|
||||
** Change the status of the lock on the file "id" to be a readlock.
|
||||
** If the file was write locked, then this reduces the lock to a read.
|
||||
** If the file was read locked, then this acquires a new read lock.
|
||||
**
|
||||
** Return SQLITE_OK on success and SQLITE_BUSY on failure. If this
|
||||
** library was compiled with large file support (LFS) but LFS is not
|
||||
** available on the host, then an SQLITE_NOLFS is returned.
|
||||
*/
|
||||
int sqlite3OsReadLock(OsFile *id){
|
||||
int rc;
|
||||
if( id->locked>0 || id->refNumRF == -1 ){
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
int lk;
|
||||
OSErr res;
|
||||
int cnt = 5;
|
||||
ParamBlockRec params;
|
||||
sqlite3Randomness(sizeof(lk), &lk);
|
||||
lk = (lk & 0x7fffffff)%N_LOCKBYTE + 1;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.ioParam.ioRefNum = id->refNumRF;
|
||||
params.ioParam.ioPosMode = fsFromStart;
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
while( cnt-->0 && (res = PBLockRangeSync(¶ms))!=noErr ){
|
||||
UInt32 finalTicks;
|
||||
Delay(1, &finalTicks); /* 1/60 sec */
|
||||
}
|
||||
if( res == noErr ){
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE+1;
|
||||
params.ioParam.ioReqCount = N_LOCKBYTE;
|
||||
PBUnlockRangeSync(¶ms);
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE+lk;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
res = PBLockRangeSync(¶ms);
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
PBUnlockRangeSync(¶ms);
|
||||
}
|
||||
if( res == noErr ){
|
||||
id->locked = lk;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
rc = SQLITE_BUSY;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the lock status to be an exclusive or write lock. Return
|
||||
** SQLITE_OK on success and SQLITE_BUSY on a failure. If this
|
||||
** library was compiled with large file support (LFS) but LFS is not
|
||||
** available on the host, then an SQLITE_NOLFS is returned.
|
||||
*/
|
||||
int sqlite3OsWriteLock(OsFile *id){
|
||||
int rc;
|
||||
if( id->locked<0 || id->refNumRF == -1 ){
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
OSErr res;
|
||||
int cnt = 5;
|
||||
ParamBlockRec params;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.ioParam.ioRefNum = id->refNumRF;
|
||||
params.ioParam.ioPosMode = fsFromStart;
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
while( cnt-->0 && (res = PBLockRangeSync(¶ms))!=noErr ){
|
||||
UInt32 finalTicks;
|
||||
Delay(1, &finalTicks); /* 1/60 sec */
|
||||
}
|
||||
if( res == noErr ){
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE + id->locked;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
if( id->locked==0
|
||||
|| PBUnlockRangeSync(¶ms)==noErr ){
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE+1;
|
||||
params.ioParam.ioReqCount = N_LOCKBYTE;
|
||||
res = PBLockRangeSync(¶ms);
|
||||
}else{
|
||||
res = afpRangeNotLocked;
|
||||
}
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
PBUnlockRangeSync(¶ms);
|
||||
}
|
||||
if( res == noErr ){
|
||||
id->locked = -1;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
rc = SQLITE_BUSY;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Unlock the given file descriptor. If the file descriptor was
|
||||
** not previously locked, then this routine is a no-op. If this
|
||||
** library was compiled with large file support (LFS) but LFS is not
|
||||
** available on the host, then an SQLITE_NOLFS is returned.
|
||||
*/
|
||||
int sqlite3OsUnlock(OsFile *id){
|
||||
int rc;
|
||||
ParamBlockRec params;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.ioParam.ioRefNum = id->refNumRF;
|
||||
params.ioParam.ioPosMode = fsFromStart;
|
||||
if( id->locked==0 || id->refNumRF == -1 ){
|
||||
rc = SQLITE_OK;
|
||||
}else if( id->locked<0 ){
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE+1;
|
||||
params.ioParam.ioReqCount = N_LOCKBYTE;
|
||||
PBUnlockRangeSync(¶ms);
|
||||
rc = SQLITE_OK;
|
||||
id->locked = 0;
|
||||
}else{
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE+id->locked;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
PBUnlockRangeSync(¶ms);
|
||||
rc = SQLITE_OK;
|
||||
id->locked = 0;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Get information to seed the random number generator. The seed
|
||||
** is written into the buffer zBuf[256]. The calling function must
|
||||
** supply a sufficiently large buffer.
|
||||
*/
|
||||
int sqlite3OsRandomSeed(char *zBuf){
|
||||
/* We have to initialize zBuf to prevent valgrind from reporting
|
||||
** errors. The reports issued by valgrind are incorrect - we would
|
||||
** prefer that the randomness be increased by making use of the
|
||||
** uninitialized space in zBuf - but valgrind errors tend to worry
|
||||
** some users. Rather than argue, it seems easier just to initialize
|
||||
** the whole array and silence valgrind, even if that means less randomness
|
||||
** in the random seed.
|
||||
**
|
||||
** When testing, initializing zBuf[] to zero is all we do. That means
|
||||
** that we always use the same random number sequence.* This makes the
|
||||
** tests repeatable.
|
||||
*/
|
||||
memset(zBuf, 0, 256);
|
||||
#if !defined(SQLITE_TEST)
|
||||
{
|
||||
int pid;
|
||||
Microseconds((UnsignedWide*)zBuf);
|
||||
pid = getpid();
|
||||
memcpy(&zBuf[sizeof(UnsignedWide)], &pid, sizeof(pid));
|
||||
}
|
||||
#endif
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sleep for a little while. Return the amount of time slept.
|
||||
*/
|
||||
int sqlite3OsSleep(int ms){
|
||||
UInt32 finalTicks;
|
||||
UInt32 ticks = (((UInt32)ms+16)*3)/50; /* 1/60 sec per tick */
|
||||
Delay(ticks, &finalTicks);
|
||||
return (int)((ticks*50)/3);
|
||||
}
|
||||
|
||||
/*
|
||||
** Static variables used for thread synchronization
|
||||
*/
|
||||
static int inMutex = 0;
|
||||
#ifdef SQLITE_MACOS_MULTITASKING
|
||||
static MPCriticalRegionID criticalRegion;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The following pair of routine implement mutual exclusion for
|
||||
** multi-threaded processes. Only a single thread is allowed to
|
||||
** executed code that is surrounded by EnterMutex() and LeaveMutex().
|
||||
**
|
||||
** SQLite uses only a single Mutex. There is not much critical
|
||||
** code and what little there is executes quickly and without blocking.
|
||||
*/
|
||||
void sqlite3OsEnterMutex(){
|
||||
#ifdef SQLITE_MACOS_MULTITASKING
|
||||
static volatile int notInit = 1;
|
||||
if( notInit ){
|
||||
if( notInit == 2 ) /* as close as you can get to thread safe init */
|
||||
MPYield();
|
||||
else{
|
||||
notInit = 2;
|
||||
MPCreateCriticalRegion(&criticalRegion);
|
||||
notInit = 0;
|
||||
}
|
||||
}
|
||||
MPEnterCriticalRegion(criticalRegion, kDurationForever);
|
||||
#endif
|
||||
assert( !inMutex );
|
||||
inMutex = 1;
|
||||
}
|
||||
void sqlite3OsLeaveMutex(){
|
||||
assert( inMutex );
|
||||
inMutex = 0;
|
||||
#ifdef SQLITE_MACOS_MULTITASKING
|
||||
MPExitCriticalRegion(criticalRegion);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Turn a relative pathname into a full pathname. Return a pointer
|
||||
** to the full pathname stored in space obtained from sqliteMalloc().
|
||||
** The calling function is responsible for freeing this space once it
|
||||
** is no longer needed.
|
||||
*/
|
||||
char *sqlite3OsFullPathname(const char *zRelative){
|
||||
char *zFull = 0;
|
||||
if( zRelative[0]==':' ){
|
||||
char zBuf[_MAX_PATH+1];
|
||||
sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), &(zRelative[1]),
|
||||
(char*)0);
|
||||
}else{
|
||||
if( strchr(zRelative, ':') ){
|
||||
sqlite3SetString(&zFull, zRelative, (char*)0);
|
||||
}else{
|
||||
char zBuf[_MAX_PATH+1];
|
||||
sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), zRelative, (char*)0);
|
||||
}
|
||||
}
|
||||
return zFull;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following variable, if set to a non-zero value, becomes the result
|
||||
** returned from sqlite3OsCurrentTime(). This is used for testing.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_current_time = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Find the current time (in Universal Coordinated Time). Write the
|
||||
** current time and date as a Julian Day number into *prNow and
|
||||
** return 0. Return 1 if the time and date cannot be found.
|
||||
*/
|
||||
int sqlite3OsCurrentTime(double *prNow){
|
||||
*prNow = 0.0; /**** FIX ME *****/
|
||||
#ifdef SQLITE_TEST
|
||||
if( sqlite3_current_time ){
|
||||
*prNow = sqlite3_current_time/86400.0 + 2440587.5;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* OS_MAC */
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
** 2004 May 22
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This header file defines OS-specific features of classic Mac.
|
||||
** OS X uses the os_unix.h file, not this one.
|
||||
*/
|
||||
#ifndef _SQLITE_OS_MAC_H_
|
||||
#define _SQLITE_OS_MAC_H_
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <Files.h>
|
||||
#ifdef _LARGE_FILE
|
||||
typedef SInt64 off_t;
|
||||
#else
|
||||
typedef SInt32 off_t;
|
||||
#endif
|
||||
#define SQLITE_TEMPNAME_SIZE _MAX_PATH
|
||||
#define SQLITE_MIN_SLEEP_MS 17
|
||||
|
||||
/*
|
||||
** The OsFile structure is a operating-system independing representation
|
||||
** of an open file handle. It is defined differently for each architecture.
|
||||
**
|
||||
** This is the definition for class Mac.
|
||||
*/
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
SInt16 refNum; /* Data fork/file reference number */
|
||||
SInt16 refNumRF; /* Resource fork reference number (for locking) */
|
||||
int locked; /* 0: unlocked, <0: write lock, >0: read lock */
|
||||
int delOnClose; /* True if file is to be deleted on close */
|
||||
char *pathToDel; /* Name of file to delete on close */
|
||||
};
|
||||
|
||||
|
||||
#endif /* _SQLITE_OS_MAC_H_ */
|
||||
-461
@@ -1,461 +0,0 @@
|
||||
/*
|
||||
** 2004 May 22
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This file contains code that is specific to Unix systems. It is used
|
||||
** for testing SQLite only.
|
||||
*/
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
#if OS_TEST /* This file is used for the test backend only */
|
||||
#include "sqliteInt.h"
|
||||
|
||||
#define sqlite3OsOpenReadWrite sqlite3RealOpenReadWrite
|
||||
#define sqlite3OsOpenExclusive sqlite3RealOpenExclusive
|
||||
#define sqlite3OsOpenReadOnly sqlite3RealOpenReadOnly
|
||||
#define sqlite3OsOpenDirectory sqlite3RealOpenDirectory
|
||||
#define sqlite3OsClose sqlite3RealClose
|
||||
#define sqlite3OsRead sqlite3RealRead
|
||||
#define sqlite3OsWrite sqlite3RealWrite
|
||||
#define sqlite3OsSeek sqlite3RealSeek
|
||||
#define sqlite3OsSync sqlite3RealSync
|
||||
#define sqlite3OsTruncate sqlite3RealTruncate
|
||||
#define sqlite3OsFileSize sqlite3RealFileSize
|
||||
#define sqlite3OsLock sqlite3RealLock
|
||||
#define sqlite3OsUnlock sqlite3RealUnlock
|
||||
#define sqlite3OsCheckReservedLock sqlite3RealCheckReservedLock
|
||||
|
||||
#define OsFile OsRealFile
|
||||
#define OS_UNIX 1
|
||||
#include "os_unix.c"
|
||||
#undef OS_UNIX
|
||||
#undef OsFile
|
||||
|
||||
#undef sqlite3OsOpenReadWrite
|
||||
#undef sqlite3OsOpenExclusive
|
||||
#undef sqlite3OsOpenReadOnly
|
||||
#undef sqlite3OsOpenDirectory
|
||||
#undef sqlite3OsClose
|
||||
#undef sqlite3OsRead
|
||||
#undef sqlite3OsWrite
|
||||
#undef sqlite3OsSeek
|
||||
#undef sqlite3OsSync
|
||||
#undef sqlite3OsTruncate
|
||||
#undef sqlite3OsFileSize
|
||||
#undef sqlite3OsLock
|
||||
#undef sqlite3OsUnlock
|
||||
#undef sqlite3OsCheckReservedLock
|
||||
|
||||
#define BLOCKSIZE 512
|
||||
#define BLOCK_OFFSET(x) ((x) * BLOCKSIZE)
|
||||
|
||||
|
||||
/*
|
||||
** The following variables control when a simulated crash occurs.
|
||||
**
|
||||
** If iCrashDelay is non-zero, then zCrashFile contains (full path) name of
|
||||
** a file that SQLite will call sqlite3OsSync() on. Each time this happens
|
||||
** iCrashDelay is decremented. If iCrashDelay is zero after being
|
||||
** decremented, a "crash" occurs during the sync() operation.
|
||||
**
|
||||
** In other words, a crash occurs the iCrashDelay'th time zCrashFile is
|
||||
** synced.
|
||||
*/
|
||||
static int iCrashDelay = 0;
|
||||
char zCrashFile[256];
|
||||
|
||||
/*
|
||||
** Set the value of the two crash parameters.
|
||||
*/
|
||||
void sqlite3SetCrashParams(int iDelay, char const *zFile){
|
||||
sqlite3OsEnterMutex();
|
||||
assert( strlen(zFile)<256 );
|
||||
strcpy(zCrashFile, zFile);
|
||||
iCrashDelay = iDelay;
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
|
||||
/*
|
||||
** File zPath is being sync()ed. Return non-zero if this should
|
||||
** cause a crash.
|
||||
*/
|
||||
static int crashRequired(char const *zPath){
|
||||
int r;
|
||||
int n;
|
||||
sqlite3OsEnterMutex();
|
||||
n = strlen(zCrashFile);
|
||||
if( zCrashFile[n-1]=='*' ){
|
||||
n--;
|
||||
}else if( strlen(zPath)>n ){
|
||||
n = strlen(zPath);
|
||||
}
|
||||
r = 0;
|
||||
if( iCrashDelay>0 && strncmp(zPath, zCrashFile, n)==0 ){
|
||||
iCrashDelay--;
|
||||
if( iCrashDelay<=0 ){
|
||||
r = 1;
|
||||
}
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
static OsTestFile *pAllFiles = 0;
|
||||
|
||||
/*
|
||||
** Initialise the os_test.c specific fields of pFile.
|
||||
*/
|
||||
static void initFile(OsFile *id, char const *zName){
|
||||
OsTestFile *pFile = (OsTestFile *)
|
||||
sqliteMalloc(sizeof(OsTestFile) + strlen(zName)+1);
|
||||
pFile->nMaxWrite = 0;
|
||||
pFile->nBlk = 0;
|
||||
pFile->apBlk = 0;
|
||||
pFile->zName = (char *)(&pFile[1]);
|
||||
strcpy(pFile->zName, zName);
|
||||
*id = pFile;
|
||||
pFile->pNext = pAllFiles;
|
||||
pAllFiles = pFile;
|
||||
}
|
||||
|
||||
/*
|
||||
** Undo the work done by initFile. Delete the OsTestFile structure
|
||||
** and unlink the structure from the pAllFiles list.
|
||||
*/
|
||||
static void closeFile(OsFile *id){
|
||||
OsTestFile *pFile = *id;
|
||||
if( pFile==pAllFiles ){
|
||||
pAllFiles = pFile->pNext;
|
||||
}else{
|
||||
OsTestFile *p;
|
||||
for(p=pAllFiles; p->pNext!=pFile; p=p->pNext ){
|
||||
assert( p );
|
||||
}
|
||||
p->pNext = pFile->pNext;
|
||||
}
|
||||
sqliteFree(pFile);
|
||||
*id = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the current seek offset from the start of the file. This
|
||||
** is unix-only code.
|
||||
*/
|
||||
static off_t osTell(OsTestFile *pFile){
|
||||
return lseek(pFile->fd.h, 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
/*
|
||||
** Load block 'blk' into the cache of pFile.
|
||||
*/
|
||||
static int cacheBlock(OsTestFile *pFile, int blk){
|
||||
if( blk>=pFile->nBlk ){
|
||||
int n = ((pFile->nBlk * 2) + 100 + blk);
|
||||
/* if( pFile->nBlk==0 ){ printf("DIRTY %s\n", pFile->zName); } */
|
||||
pFile->apBlk = (u8 **)sqliteRealloc(pFile->apBlk, n * sizeof(u8*));
|
||||
if( !pFile->apBlk ) return SQLITE_NOMEM;
|
||||
memset(&pFile->apBlk[pFile->nBlk], 0, (n - pFile->nBlk)*sizeof(u8*));
|
||||
pFile->nBlk = n;
|
||||
}
|
||||
|
||||
if( !pFile->apBlk[blk] ){
|
||||
off_t filesize;
|
||||
int rc;
|
||||
|
||||
u8 *p = sqliteMalloc(BLOCKSIZE);
|
||||
if( !p ) return SQLITE_NOMEM;
|
||||
pFile->apBlk[blk] = p;
|
||||
|
||||
rc = sqlite3RealFileSize(&pFile->fd, &filesize);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
if( BLOCK_OFFSET(blk)<filesize ){
|
||||
int len = BLOCKSIZE;
|
||||
rc = sqlite3RealSeek(&pFile->fd, blk*BLOCKSIZE);
|
||||
if( BLOCK_OFFSET(blk+1)>filesize ){
|
||||
len = filesize - BLOCK_OFFSET(blk);
|
||||
}
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3RealRead(&pFile->fd, p, len);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* #define TRACE_WRITECACHE */
|
||||
|
||||
/*
|
||||
** Write the cache of pFile to disk. If crash is non-zero, randomly
|
||||
** skip blocks when writing. The cache is deleted before returning.
|
||||
*/
|
||||
static int writeCache2(OsTestFile *pFile, int crash){
|
||||
int i;
|
||||
int nMax = pFile->nMaxWrite;
|
||||
off_t offset;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
offset = osTell(pFile);
|
||||
for(i=0; i<pFile->nBlk; i++){
|
||||
u8 *p = pFile->apBlk[i];
|
||||
if( p ){
|
||||
int skip = 0;
|
||||
int trash = 0;
|
||||
if( crash ){
|
||||
char random;
|
||||
sqlite3Randomness(1, &random);
|
||||
if( random & 0x01 ){
|
||||
if( random & 0x02 ){
|
||||
trash = 1;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Trashing block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}else{
|
||||
skip = 1;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Skiping block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}
|
||||
}else{
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Writing block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3RealSeek(&pFile->fd, BLOCK_OFFSET(i));
|
||||
}
|
||||
if( rc==SQLITE_OK && !skip ){
|
||||
int len = BLOCKSIZE;
|
||||
if( BLOCK_OFFSET(i+1)>nMax ){
|
||||
len = nMax-BLOCK_OFFSET(i);
|
||||
}
|
||||
if( trash ){
|
||||
sqlite3Randomness(len, p);
|
||||
}
|
||||
rc = sqlite3RealWrite(&pFile->fd, p, len);
|
||||
}
|
||||
sqliteFree(p);
|
||||
}
|
||||
}
|
||||
sqliteFree(pFile->apBlk);
|
||||
pFile->nBlk = 0;
|
||||
pFile->apBlk = 0;
|
||||
pFile->nMaxWrite = 0;
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3RealSeek(&pFile->fd, offset);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write the cache to disk.
|
||||
*/
|
||||
static int writeCache(OsTestFile *pFile){
|
||||
if( pFile->apBlk ){
|
||||
int c = crashRequired(pFile->zName);
|
||||
if( c ){
|
||||
OsTestFile *p;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("\nCrash during sync of %s\n", pFile->zName);
|
||||
#endif
|
||||
for(p=pAllFiles; p; p=p->pNext){
|
||||
writeCache2(p, 1);
|
||||
}
|
||||
exit(-1);
|
||||
}else{
|
||||
return writeCache2(pFile, 0);
|
||||
}
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close the file.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile *id){
|
||||
if( !(*id) ) return SQLITE_OK;
|
||||
if( (*id)->fd.isOpen ){
|
||||
/* printf("CLOSE %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */
|
||||
writeCache(*id);
|
||||
sqlite3RealClose(&(*id)->fd);
|
||||
}
|
||||
closeFile(id);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
off_t offset; /* The current offset from the start of the file */
|
||||
off_t end; /* The byte just past the last byte read */
|
||||
int blk; /* Block number the read starts on */
|
||||
int i;
|
||||
u8 *zCsr;
|
||||
int rc = SQLITE_OK;
|
||||
OsTestFile *pFile = *id;
|
||||
|
||||
offset = osTell(pFile);
|
||||
end = offset+amt;
|
||||
blk = (offset/BLOCKSIZE);
|
||||
|
||||
zCsr = (u8 *)pBuf;
|
||||
for(i=blk; i*BLOCKSIZE<end; i++){
|
||||
int off = 0;
|
||||
int len = 0;
|
||||
|
||||
|
||||
if( BLOCK_OFFSET(i) < offset ){
|
||||
off = offset-BLOCK_OFFSET(i);
|
||||
}
|
||||
len = BLOCKSIZE - off;
|
||||
if( BLOCK_OFFSET(i+1) > end ){
|
||||
len = len - (BLOCK_OFFSET(i+1)-end);
|
||||
}
|
||||
|
||||
if( i<pFile->nBlk && pFile->apBlk[i]){
|
||||
u8 *pBlk = pFile->apBlk[i];
|
||||
memcpy(zCsr, &pBlk[off], len);
|
||||
}else{
|
||||
rc = sqlite3RealSeek(&pFile->fd, BLOCK_OFFSET(i) + off);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3RealRead(&pFile->fd, zCsr, len);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
|
||||
zCsr += len;
|
||||
}
|
||||
assert( zCsr==&((u8 *)pBuf)[amt] );
|
||||
|
||||
rc = sqlite3RealSeek(&pFile->fd, end);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
off_t offset; /* The current offset from the start of the file */
|
||||
off_t end; /* The byte just past the last byte written */
|
||||
int blk; /* Block number the write starts on */
|
||||
int i;
|
||||
const u8 *zCsr;
|
||||
int rc = SQLITE_OK;
|
||||
OsTestFile *pFile = *id;
|
||||
|
||||
offset = osTell(pFile);
|
||||
end = offset+amt;
|
||||
blk = (offset/BLOCKSIZE);
|
||||
|
||||
zCsr = (u8 *)pBuf;
|
||||
for(i=blk; i*BLOCKSIZE<end; i++){
|
||||
u8 *pBlk;
|
||||
int off = 0;
|
||||
int len = 0;
|
||||
|
||||
/* Make sure the block is in the cache */
|
||||
rc = cacheBlock(pFile, i);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
/* Write into the cache */
|
||||
pBlk = pFile->apBlk[i];
|
||||
assert( pBlk );
|
||||
|
||||
if( BLOCK_OFFSET(i) < offset ){
|
||||
off = offset-BLOCK_OFFSET(i);
|
||||
}
|
||||
len = BLOCKSIZE - off;
|
||||
if( BLOCK_OFFSET(i+1) > end ){
|
||||
len = len - (BLOCK_OFFSET(i+1)-end);
|
||||
}
|
||||
memcpy(&pBlk[off], zCsr, len);
|
||||
zCsr += len;
|
||||
}
|
||||
if( pFile->nMaxWrite<end ){
|
||||
pFile->nMaxWrite = end;
|
||||
}
|
||||
assert( zCsr==&((u8 *)pBuf)[amt] );
|
||||
|
||||
rc = sqlite3RealSeek(&pFile->fd, end);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sync the file. First flush the write-cache to disk, then call the
|
||||
** real sync() function.
|
||||
*/
|
||||
int sqlite3OsSync(OsFile *id){
|
||||
int rc;
|
||||
/* printf("SYNC %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */
|
||||
rc = writeCache(*id);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3RealSync(&(*id)->fd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate the file. Set the internal OsFile.nMaxWrite variable to the new
|
||||
** file size to ensure that nothing in the write-cache past this point
|
||||
** is written to disk.
|
||||
*/
|
||||
int sqlite3OsTruncate(OsFile *id, off_t nByte){
|
||||
(*id)->nMaxWrite = nByte;
|
||||
return sqlite3RealTruncate(&(*id)->fd, nByte);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the size of the file. If the cache contains a write that extended
|
||||
** the file, then return this size instead of the on-disk size.
|
||||
*/
|
||||
int sqlite3OsFileSize(OsFile *id, off_t *pSize){
|
||||
int rc = sqlite3RealFileSize(&(*id)->fd, pSize);
|
||||
if( rc==SQLITE_OK && pSize && *pSize<(*id)->nMaxWrite ){
|
||||
*pSize = (*id)->nMaxWrite;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** The three functions used to open files. All that is required is to
|
||||
** initialise the os_test.c specific fields and then call the corresponding
|
||||
** os_unix.c function to really open the file.
|
||||
*/
|
||||
int sqlite3OsOpenReadWrite(const char *zFilename, OsFile *id, int *pReadonly){
|
||||
initFile(id, zFilename);
|
||||
return sqlite3RealOpenReadWrite(zFilename, &(*id)->fd, pReadonly);
|
||||
}
|
||||
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
initFile(id, zFilename);
|
||||
return sqlite3RealOpenExclusive(zFilename, &(*id)->fd, delFlag);
|
||||
}
|
||||
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
|
||||
initFile(id, zFilename);
|
||||
return sqlite3RealOpenReadOnly(zFilename, &(*id)->fd);
|
||||
}
|
||||
|
||||
/*
|
||||
** These six function calls are passed straight through to the os_unix.c
|
||||
** backend.
|
||||
*/
|
||||
int sqlite3OsSeek(OsFile *id, off_t offset){
|
||||
return sqlite3RealSeek(&(*id)->fd, offset);
|
||||
}
|
||||
int sqlite3OsCheckReservedLock(OsFile *id){
|
||||
return sqlite3RealCheckReservedLock(&(*id)->fd);
|
||||
}
|
||||
int sqlite3OsLock(OsFile *id, int locktype){
|
||||
return sqlite3RealLock(&(*id)->fd, locktype);
|
||||
}
|
||||
int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
return sqlite3RealUnlock(&(*id)->fd, locktype);
|
||||
}
|
||||
int sqlite3OsOpenDirectory(const char *zDirname, OsFile *id){
|
||||
return sqlite3RealOpenDirectory(zDirname, &(*id)->fd);
|
||||
}
|
||||
|
||||
#endif /* OS_TEST */
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
** 2004 May 22
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
*/
|
||||
#ifndef _SQLITE_OS_TEST_H_
|
||||
#define _SQLITE_OS_TEST_H_
|
||||
|
||||
#define OsFile OsRealFile
|
||||
#define OS_UNIX 1
|
||||
#include "os_unix.h"
|
||||
#undef OS_UNIX
|
||||
#undef OsFile
|
||||
|
||||
/* Include sqliteInt.h now to get the type u8. */
|
||||
#include "sqliteInt.h"
|
||||
|
||||
typedef struct OsTestFile* OsFile;
|
||||
typedef struct OsTestFile OsTestFile;
|
||||
struct OsTestFile {
|
||||
u8 **apBlk; /* Array of blocks that have been written to. */
|
||||
int nBlk; /* Size of apBlock. */
|
||||
int nMaxWrite; /* Largest offset written to. */
|
||||
char *zName; /* File name */
|
||||
OsRealFile fd;
|
||||
OsTestFile *pNext;
|
||||
};
|
||||
|
||||
void sqlite3SetCrashParams(int iDelay, char const *zFile);
|
||||
|
||||
#endif /* _SQLITE_OS_UNIX_H_ */
|
||||
-1261
File diff suppressed because it is too large
Load Diff
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
** 2004 May 22
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This header file defined OS-specific features for Unix.
|
||||
*/
|
||||
#ifndef _SQLITE_OS_UNIX_H_
|
||||
#define _SQLITE_OS_UNIX_H_
|
||||
|
||||
/*
|
||||
** Helpful hint: To get this to compile on HP/UX, add -D_INCLUDE_POSIX_SOURCE
|
||||
** to the compiler command line.
|
||||
*/
|
||||
|
||||
/*
|
||||
** These #defines should enable >2GB file support on Posix if the
|
||||
** underlying operating system supports it. If the OS lacks
|
||||
** large file support, or if the OS is windows, these should be no-ops.
|
||||
**
|
||||
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
|
||||
** on the compiler command line. This is necessary if you are compiling
|
||||
** on a recent machine (ex: RedHat 7.2) but you want your code to work
|
||||
** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2
|
||||
** without this option, LFS is enable. But LFS does not exist in the kernel
|
||||
** in RedHat 6.0, so the code won't work. Hence, for maximum binary
|
||||
** portability you should omit LFS.
|
||||
**
|
||||
** Similar is true for MacOS. LFS is only supported on MacOS 9 and later.
|
||||
*/
|
||||
#ifndef SQLITE_DISABLE_LFS
|
||||
# define _LARGE_FILE 1
|
||||
# ifndef _FILE_OFFSET_BITS
|
||||
# define _FILE_OFFSET_BITS 64
|
||||
# endif
|
||||
# define _LARGEFILE_SOURCE 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** standard include files.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
** The OsFile structure is a operating-system independing representation
|
||||
** of an open file handle. It is defined differently for each architecture.
|
||||
**
|
||||
** This is the definition for Unix.
|
||||
**
|
||||
** OsFile.locktype takes one of the values SHARED_LOCK, RESERVED_LOCK,
|
||||
** PENDING_LOCK or EXCLUSIVE_LOCK.
|
||||
*/
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
struct Pager *pPager; /* The pager that owns this OsFile. Might be 0 */
|
||||
struct openCnt *pOpen; /* Info about all open fd's on this inode */
|
||||
struct lockInfo *pLock; /* Info about locks on this inode */
|
||||
int h; /* The file descriptor */
|
||||
unsigned char locktype; /* The type of lock held on this fd */
|
||||
unsigned char isOpen; /* True if needs to be closed */
|
||||
int dirfd; /* File descriptor for the directory */
|
||||
};
|
||||
|
||||
/*
|
||||
** Maximum number of characters in a temporary file name
|
||||
*/
|
||||
#define SQLITE_TEMPNAME_SIZE 200
|
||||
|
||||
/*
|
||||
** Minimum interval supported by sqlite3OsSleep().
|
||||
*/
|
||||
#if defined(HAVE_USLEEP) && HAVE_USLEEP
|
||||
# define SQLITE_MIN_SLEEP_MS 1
|
||||
#else
|
||||
# define SQLITE_MIN_SLEEP_MS 1000
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _SQLITE_OS_UNIX_H_ */
|
||||
-742
@@ -1,742 +0,0 @@
|
||||
/*
|
||||
** 2004 May 22
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This file contains code that is specific to windows.
|
||||
*/
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
#if OS_WIN /* This file is used for windows only */
|
||||
#include "sqliteInt.h"
|
||||
|
||||
#include <winbase.h>
|
||||
|
||||
/*
|
||||
** Macros used to determine whether or not to use threads.
|
||||
*/
|
||||
#if defined(THREADSAFE) && THREADSAFE
|
||||
# define SQLITE_W32_THREADS 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Include code that is common to all os_*.c files
|
||||
*/
|
||||
#include "os_common.h"
|
||||
|
||||
/*
|
||||
** Delete the named file
|
||||
*/
|
||||
int sqlite3OsDelete(const char *zFilename){
|
||||
DeleteFileA(zFilename);
|
||||
TRACE2("DELETE \"%s\"\n", zFilename);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return TRUE if the named file exists.
|
||||
*/
|
||||
int sqlite3OsFileExists(const char *zFilename){
|
||||
return GetFileAttributesA(zFilename) != 0xffffffff;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to open a file for both reading and writing. If that
|
||||
** fails, try opening it read-only. If the file does not exist,
|
||||
** try to create it.
|
||||
**
|
||||
** On success, a handle for the open file is written to *id
|
||||
** and *pReadonly is set to 0 if the file was opened for reading and
|
||||
** writing or 1 if the file was opened read-only. The function returns
|
||||
** SQLITE_OK.
|
||||
**
|
||||
** On failure, the function returns SQLITE_CANTOPEN and leaves
|
||||
** *id and *pReadonly unchanged.
|
||||
*/
|
||||
int sqlite3OsOpenReadWrite(
|
||||
const char *zFilename,
|
||||
OsFile *id,
|
||||
int *pReadonly
|
||||
){
|
||||
HANDLE h;
|
||||
assert( !id->isOpen );
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,
|
||||
NULL,
|
||||
OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
*pReadonly = 1;
|
||||
}else{
|
||||
*pReadonly = 0;
|
||||
}
|
||||
id->h = h;
|
||||
id->locktype = NO_LOCK;
|
||||
id->sharedLockByte = 0;
|
||||
id->isOpen = 1;
|
||||
OpenCounter(+1);
|
||||
TRACE3("OPEN R/W %d \"%s\"\n", h, zFilename);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Attempt to open a new file for exclusive access by this process.
|
||||
** The file will be opened for both reading and writing. To avoid
|
||||
** a potential security problem, we do not allow the file to have
|
||||
** previously existed. Nor do we allow the file to be a symbolic
|
||||
** link.
|
||||
**
|
||||
** If delFlag is true, then make arrangements to automatically delete
|
||||
** the file when it is closed.
|
||||
**
|
||||
** On success, write the file handle into *id and return SQLITE_OK.
|
||||
**
|
||||
** On failure, return SQLITE_CANTOPEN.
|
||||
*/
|
||||
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
HANDLE h;
|
||||
int fileflags;
|
||||
assert( !id->isOpen );
|
||||
if( delFlag ){
|
||||
fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS
|
||||
| FILE_FLAG_DELETE_ON_CLOSE;
|
||||
}else{
|
||||
fileflags = FILE_FLAG_RANDOM_ACCESS;
|
||||
}
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
CREATE_ALWAYS,
|
||||
fileflags,
|
||||
NULL
|
||||
);
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
id->h = h;
|
||||
id->locktype = NO_LOCK;
|
||||
id->sharedLockByte = 0;
|
||||
id->isOpen = 1;
|
||||
OpenCounter(+1);
|
||||
TRACE3("OPEN EX %d \"%s\"\n", h, zFilename);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to open a new file for read-only access.
|
||||
**
|
||||
** On success, write the file handle into *id and return SQLITE_OK.
|
||||
**
|
||||
** On failure, return SQLITE_CANTOPEN.
|
||||
*/
|
||||
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
|
||||
HANDLE h;
|
||||
assert( !id->isOpen );
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
id->h = h;
|
||||
id->locktype = NO_LOCK;
|
||||
id->sharedLockByte = 0;
|
||||
id->isOpen = 1;
|
||||
OpenCounter(+1);
|
||||
TRACE3("OPEN RO %d \"%s\"\n", h, zFilename);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to open a file descriptor for the directory that contains a
|
||||
** file. This file descriptor can be used to fsync() the directory
|
||||
** in order to make sure the creation of a new file is actually written
|
||||
** to disk.
|
||||
**
|
||||
** This routine is only meaningful for Unix. It is a no-op under
|
||||
** windows since windows does not support hard links.
|
||||
**
|
||||
** On success, a handle for a previously open file is at *id is
|
||||
** updated with the new directory file descriptor and SQLITE_OK is
|
||||
** returned.
|
||||
**
|
||||
** On failure, the function returns SQLITE_CANTOPEN and leaves
|
||||
** *id unchanged.
|
||||
*/
|
||||
int sqlite3OsOpenDirectory(
|
||||
const char *zDirname,
|
||||
OsFile *id
|
||||
){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** If the following global variable points to a string which is the
|
||||
** name of a directory, then that directory will be used to store
|
||||
** temporary files.
|
||||
*/
|
||||
const char *sqlite3_temp_directory = 0;
|
||||
|
||||
/*
|
||||
** Create a temporary file name in zBuf. zBuf must be big enough to
|
||||
** hold at least SQLITE_TEMPNAME_SIZE characters.
|
||||
*/
|
||||
int sqlite3OsTempFileName(char *zBuf){
|
||||
static char zChars[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"0123456789";
|
||||
int i, j;
|
||||
char zTempPath[SQLITE_TEMPNAME_SIZE];
|
||||
if( sqlite3_temp_directory ){
|
||||
strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30);
|
||||
zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
|
||||
}else{
|
||||
GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath);
|
||||
}
|
||||
for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
|
||||
zTempPath[i] = 0;
|
||||
for(;;){
|
||||
sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath);
|
||||
j = strlen(zBuf);
|
||||
sqlite3Randomness(15, &zBuf[j]);
|
||||
for(i=0; i<15; i++, j++){
|
||||
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
|
||||
}
|
||||
zBuf[j] = 0;
|
||||
if( !sqlite3OsFileExists(zBuf) ) break;
|
||||
}
|
||||
TRACE2("TEMP FILENAME: %s\n", zBuf);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close a file.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile *id){
|
||||
if( id->isOpen ){
|
||||
TRACE2("CLOSE %d\n", id->h);
|
||||
CloseHandle(id->h);
|
||||
OpenCounter(-1);
|
||||
id->isOpen = 0;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Read data from a file into a buffer. Return SQLITE_OK if all
|
||||
** bytes were read successfully and SQLITE_IOERR if anything goes
|
||||
** wrong.
|
||||
*/
|
||||
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
DWORD got;
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
TRACE3("READ %d lock=%d\n", id->h, id->locktype);
|
||||
if( !ReadFile(id->h, pBuf, amt, &got, 0) ){
|
||||
got = 0;
|
||||
}
|
||||
if( got==(DWORD)amt ){
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Write data from a buffer into a file. Return SQLITE_OK on success
|
||||
** or some other error code on failure.
|
||||
*/
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
int rc;
|
||||
DWORD wrote;
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
TRACE3("WRITE %d lock=%d\n", id->h, id->locktype);
|
||||
while( amt>0 && (rc = WriteFile(id->h, pBuf, amt, &wrote, 0))!=0 && wrote>0 ){
|
||||
amt -= wrote;
|
||||
pBuf = &((char*)pBuf)[wrote];
|
||||
}
|
||||
if( !rc || amt>(int)wrote ){
|
||||
return SQLITE_FULL;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Move the read/write pointer in a file.
|
||||
*/
|
||||
int sqlite3OsSeek(OsFile *id, off_t offset){
|
||||
LONG upperBits = offset>>32;
|
||||
LONG lowerBits = offset & 0xffffffff;
|
||||
DWORD rc;
|
||||
assert( id->isOpen );
|
||||
SEEK(offset/1024 + 1);
|
||||
rc = SetFilePointer(id->h, lowerBits, &upperBits, FILE_BEGIN);
|
||||
TRACE3("SEEK %d %lld\n", id->h, offset);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make sure all writes to a particular file are committed to disk.
|
||||
*/
|
||||
int sqlite3OsSync(OsFile *id){
|
||||
assert( id->isOpen );
|
||||
TRACE3("SYNC %d lock=%d\n", id->h, id->locktype);
|
||||
if( FlushFileBuffers(id->h) ){
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Sync the directory zDirname. This is a no-op on operating systems other
|
||||
** than UNIX.
|
||||
*/
|
||||
int sqlite3OsSyncDirectory(const char *zDirname){
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate an open file to a specified size
|
||||
*/
|
||||
int sqlite3OsTruncate(OsFile *id, off_t nByte){
|
||||
LONG upperBits = nByte>>32;
|
||||
assert( id->isOpen );
|
||||
TRACE3("TRUNCATE %d %lld\n", id->h, nByte);
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
SetFilePointer(id->h, nByte, &upperBits, FILE_BEGIN);
|
||||
SetEndOfFile(id->h);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Determine the current size of a file in bytes
|
||||
*/
|
||||
int sqlite3OsFileSize(OsFile *id, off_t *pSize){
|
||||
DWORD upperBits, lowerBits;
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
lowerBits = GetFileSize(id->h, &upperBits);
|
||||
*pSize = (((off_t)upperBits)<<32) + lowerBits;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return true (non-zero) if we are running under WinNT, Win2K or WinXP.
|
||||
** Return false (zero) for Win95, Win98, or WinME.
|
||||
**
|
||||
** Here is an interesting observation: Win95, Win98, and WinME lack
|
||||
** the LockFileEx() API. But we can still statically link against that
|
||||
** API as long as we don't call it win running Win95/98/ME. A call to
|
||||
** this routine is used to determine if the host is Win95/98/ME or
|
||||
** WinNT/2K/XP so that we will know whether or not we can safely call
|
||||
** the LockFileEx() API.
|
||||
*/
|
||||
static int isNT(void){
|
||||
static int osType = 0; /* 0=unknown 1=win95 2=winNT */
|
||||
if( osType==0 ){
|
||||
OSVERSIONINFO sInfo;
|
||||
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
|
||||
GetVersionEx(&sInfo);
|
||||
osType = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
|
||||
}
|
||||
return osType==2;
|
||||
}
|
||||
|
||||
/*
|
||||
** Acquire a reader lock on the range of bytes from iByte...iByte+nByte-1.
|
||||
** Different API routines are called depending on whether or not this
|
||||
** is Win95 or WinNT.
|
||||
*/
|
||||
static int getReadLock(HANDLE h, unsigned int iByte, unsigned int nByte){
|
||||
int res;
|
||||
if( isNT() ){
|
||||
OVERLAPPED ovlp;
|
||||
ovlp.Offset = iByte;
|
||||
ovlp.OffsetHigh = 0;
|
||||
ovlp.hEvent = 0;
|
||||
res = LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY, 0, nByte, 0, &ovlp);
|
||||
}else{
|
||||
res = LockFile(h, iByte, 0, nByte, 0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
** Undo a readlock
|
||||
*/
|
||||
static int unlockReadLock(OsFile *id){
|
||||
int res;
|
||||
if( isNT() ){
|
||||
res = UnlockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
}else{
|
||||
res = UnlockFile(id->h, SHARED_FIRST + id->sharedLockByte, 0, 1, 0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
** Lock the file with the lock specified by parameter locktype - one
|
||||
** of the following:
|
||||
**
|
||||
** (1) SHARED_LOCK
|
||||
** (2) RESERVED_LOCK
|
||||
** (3) PENDING_LOCK
|
||||
** (4) EXCLUSIVE_LOCK
|
||||
**
|
||||
** Sometimes when requesting one lock state, additional lock states
|
||||
** are inserted in between. The locking might fail on one of the later
|
||||
** transitions leaving the lock state different from what it started but
|
||||
** still short of its goal. The following chart shows the allowed
|
||||
** transitions and the inserted intermediate states:
|
||||
**
|
||||
** UNLOCKED -> SHARED
|
||||
** SHARED -> RESERVED
|
||||
** SHARED -> (PENDING) -> EXCLUSIVE
|
||||
** RESERVED -> (PENDING) -> EXCLUSIVE
|
||||
** PENDING -> EXCLUSIVE
|
||||
**
|
||||
** This routine will only increase a lock. The sqlite3OsUnlock() routine
|
||||
** erases all locks at once and returns us immediately to locking level 0.
|
||||
** It is not possible to lower the locking level one step at a time. You
|
||||
** must go straight to locking level 0.
|
||||
*/
|
||||
int sqlite3OsLock(OsFile *id, int locktype){
|
||||
int rc = SQLITE_OK; /* Return code from subroutines */
|
||||
int res = 1; /* Result of a windows lock call */
|
||||
int newLocktype; /* Set id->locktype to this value before exiting */
|
||||
int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
|
||||
|
||||
assert( id->isOpen );
|
||||
TRACE5("LOCK %d %d was %d(%d)\n",
|
||||
id->h, locktype, id->locktype, id->sharedLockByte);
|
||||
|
||||
/* If there is already a lock of this type or more restrictive on the
|
||||
** OsFile, do nothing. Don't use the end_lock: exit path, as
|
||||
** sqlite3OsEnterMutex() hasn't been called yet.
|
||||
*/
|
||||
if( id->locktype>=locktype ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* Make sure the locking sequence is correct
|
||||
*/
|
||||
assert( id->locktype!=NO_LOCK || locktype==SHARED_LOCK );
|
||||
assert( locktype!=PENDING_LOCK );
|
||||
assert( locktype!=RESERVED_LOCK || id->locktype==SHARED_LOCK );
|
||||
|
||||
/* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
|
||||
** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of
|
||||
** the PENDING_LOCK byte is temporary.
|
||||
*/
|
||||
newLocktype = id->locktype;
|
||||
if( id->locktype==NO_LOCK
|
||||
|| (locktype==EXCLUSIVE_LOCK && id->locktype==RESERVED_LOCK)
|
||||
){
|
||||
int cnt = 3;
|
||||
while( cnt-->0 && (res = LockFile(id->h, PENDING_BYTE, 0, 1, 0))==0 ){
|
||||
/* Try 3 times to get the pending lock. The pending lock might be
|
||||
** held by another reader process who will release it momentarily.
|
||||
*/
|
||||
TRACE2("could not get a PENDING lock. cnt=%d\n", cnt);
|
||||
Sleep(1);
|
||||
}
|
||||
gotPendingLock = res;
|
||||
}
|
||||
|
||||
/* Acquire a shared lock
|
||||
*/
|
||||
if( locktype==SHARED_LOCK && res ){
|
||||
assert( id->locktype==NO_LOCK );
|
||||
if( isNT() ){
|
||||
res = getReadLock(id->h, SHARED_FIRST, SHARED_SIZE);
|
||||
}else{
|
||||
int lk;
|
||||
sqlite3Randomness(sizeof(lk), &lk);
|
||||
id->sharedLockByte = (lk & 0x7fffffff)%(SHARED_SIZE - 1);
|
||||
res = LockFile(id->h, SHARED_FIRST+id->sharedLockByte, 0, 1, 0);
|
||||
}
|
||||
if( res ){
|
||||
newLocktype = SHARED_LOCK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Acquire a RESERVED lock
|
||||
*/
|
||||
if( locktype==RESERVED_LOCK && res ){
|
||||
assert( id->locktype==SHARED_LOCK );
|
||||
res = LockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
if( res ){
|
||||
newLocktype = RESERVED_LOCK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Acquire a PENDING lock
|
||||
*/
|
||||
if( locktype==EXCLUSIVE_LOCK && res ){
|
||||
newLocktype = PENDING_LOCK;
|
||||
gotPendingLock = 0;
|
||||
}
|
||||
|
||||
/* Acquire an EXCLUSIVE lock
|
||||
*/
|
||||
if( locktype==EXCLUSIVE_LOCK && res ){
|
||||
assert( id->locktype>=SHARED_LOCK );
|
||||
res = unlockReadLock(id);
|
||||
TRACE2("unreadlock = %d\n", res);
|
||||
res = LockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
if( res ){
|
||||
newLocktype = EXCLUSIVE_LOCK;
|
||||
}else{
|
||||
TRACE2("error-code = %d\n", GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
/* If we are holding a PENDING lock that ought to be released, then
|
||||
** release it now.
|
||||
*/
|
||||
if( gotPendingLock && locktype==SHARED_LOCK ){
|
||||
UnlockFile(id->h, PENDING_BYTE, 0, 1, 0);
|
||||
}
|
||||
|
||||
/* Update the state of the lock has held in the file descriptor then
|
||||
** return the appropriate result code.
|
||||
*/
|
||||
if( res ){
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
TRACE4("LOCK FAILED %d trying for %d but got %d\n", id->h,
|
||||
locktype, newLocktype);
|
||||
rc = SQLITE_BUSY;
|
||||
}
|
||||
id->locktype = newLocktype;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine checks if there is a RESERVED lock held on the specified
|
||||
** file by this or any other process. If such a lock is held, return
|
||||
** non-zero, otherwise zero.
|
||||
*/
|
||||
int sqlite3OsCheckReservedLock(OsFile *id){
|
||||
int rc;
|
||||
assert( id->isOpen );
|
||||
if( id->locktype>=RESERVED_LOCK ){
|
||||
rc = 1;
|
||||
TRACE3("TEST WR-LOCK %d %d (local)\n", id->h, rc);
|
||||
}else{
|
||||
rc = LockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
if( rc ){
|
||||
UnlockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
}
|
||||
rc = !rc;
|
||||
TRACE3("TEST WR-LOCK %d %d (remote)\n", id->h, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Lower the locking level on file descriptor id to locktype. locktype
|
||||
** must be either NO_LOCK or SHARED_LOCK.
|
||||
**
|
||||
** If the locking level of the file descriptor is already at or below
|
||||
** the requested locking level, this routine is a no-op.
|
||||
**
|
||||
** It is not possible for this routine to fail.
|
||||
*/
|
||||
int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
int rc, type;
|
||||
assert( id->isOpen );
|
||||
assert( locktype<=SHARED_LOCK );
|
||||
TRACE5("UNLOCK %d to %d was %d(%d)\n", id->h, locktype,
|
||||
id->locktype, id->sharedLockByte);
|
||||
type = id->locktype;
|
||||
if( type>=EXCLUSIVE_LOCK ){
|
||||
UnlockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
}
|
||||
if( type>=RESERVED_LOCK ){
|
||||
UnlockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
}
|
||||
if( locktype==NO_LOCK && type>=SHARED_LOCK && type<EXCLUSIVE_LOCK ){
|
||||
unlockReadLock(id);
|
||||
}
|
||||
if( type>=PENDING_LOCK ){
|
||||
UnlockFile(id->h, PENDING_BYTE, 0, 1, 0);
|
||||
}
|
||||
id->locktype = locktype;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Get information to seed the random number generator. The seed
|
||||
** is written into the buffer zBuf[256]. The calling function must
|
||||
** supply a sufficiently large buffer.
|
||||
*/
|
||||
int sqlite3OsRandomSeed(char *zBuf){
|
||||
/* We have to initialize zBuf to prevent valgrind from reporting
|
||||
** errors. The reports issued by valgrind are incorrect - we would
|
||||
** prefer that the randomness be increased by making use of the
|
||||
** uninitialized space in zBuf - but valgrind errors tend to worry
|
||||
** some users. Rather than argue, it seems easier just to initialize
|
||||
** the whole array and silence valgrind, even if that means less randomness
|
||||
** in the random seed.
|
||||
**
|
||||
** When testing, initializing zBuf[] to zero is all we do. That means
|
||||
** that we always use the same random number sequence.* This makes the
|
||||
** tests repeatable.
|
||||
*/
|
||||
memset(zBuf, 0, 256);
|
||||
GetSystemTime((LPSYSTEMTIME)zBuf);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sleep for a little while. Return the amount of time slept.
|
||||
*/
|
||||
int sqlite3OsSleep(int ms){
|
||||
Sleep(ms);
|
||||
return ms;
|
||||
}
|
||||
|
||||
/*
|
||||
** Static variables used for thread synchronization
|
||||
*/
|
||||
static int inMutex = 0;
|
||||
#ifdef SQLITE_W32_THREADS
|
||||
static CRITICAL_SECTION cs;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The following pair of routine implement mutual exclusion for
|
||||
** multi-threaded processes. Only a single thread is allowed to
|
||||
** executed code that is surrounded by EnterMutex() and LeaveMutex().
|
||||
**
|
||||
** SQLite uses only a single Mutex. There is not much critical
|
||||
** code and what little there is executes quickly and without blocking.
|
||||
*/
|
||||
void sqlite3OsEnterMutex(){
|
||||
#ifdef SQLITE_W32_THREADS
|
||||
static int isInit = 0;
|
||||
while( !isInit ){
|
||||
static long lock = 0;
|
||||
if( InterlockedIncrement(&lock)==1 ){
|
||||
InitializeCriticalSection(&cs);
|
||||
isInit = 1;
|
||||
}else{
|
||||
Sleep(1);
|
||||
}
|
||||
}
|
||||
EnterCriticalSection(&cs);
|
||||
#endif
|
||||
assert( !inMutex );
|
||||
inMutex = 1;
|
||||
}
|
||||
void sqlite3OsLeaveMutex(){
|
||||
assert( inMutex );
|
||||
inMutex = 0;
|
||||
#ifdef SQLITE_W32_THREADS
|
||||
LeaveCriticalSection(&cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Turn a relative pathname into a full pathname. Return a pointer
|
||||
** to the full pathname stored in space obtained from sqliteMalloc().
|
||||
** The calling function is responsible for freeing this space once it
|
||||
** is no longer needed.
|
||||
*/
|
||||
char *sqlite3OsFullPathname(const char *zRelative){
|
||||
char *zNotUsed;
|
||||
char *zFull;
|
||||
int nByte;
|
||||
nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
|
||||
zFull = sqliteMalloc( nByte );
|
||||
if( zFull==0 ) return 0;
|
||||
GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
|
||||
return zFull;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following variable, if set to a non-zero value, becomes the result
|
||||
** returned from sqlite3OsCurrentTime(). This is used for testing.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_current_time = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Find the current time (in Universal Coordinated Time). Write the
|
||||
** current time and date as a Julian Day number into *prNow and
|
||||
** return 0. Return 1 if the time and date cannot be found.
|
||||
*/
|
||||
int sqlite3OsCurrentTime(double *prNow){
|
||||
FILETIME ft;
|
||||
/* FILETIME structure is a 64-bit value representing the number of
|
||||
100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
|
||||
*/
|
||||
double now;
|
||||
GetSystemTimeAsFileTime( &ft );
|
||||
now = ((double)ft.dwHighDateTime) * 4294967296.0;
|
||||
*prNow = (now + ft.dwLowDateTime)/864000000000.0 + 2305813.5;
|
||||
#ifdef SQLITE_TEST
|
||||
if( sqlite3_current_time ){
|
||||
*prNow = sqlite3_current_time/86400.0 + 2440587.5;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Find the time that the file was last modified. Write the
|
||||
** modification time and date as a Julian Day number into *prNow and
|
||||
** return SQLITE_OK. Return SQLITE_ERROR if the modification
|
||||
** time cannot be found.
|
||||
*/
|
||||
int sqlite3OsFileModTime(OsFile *id, double *prMTime){
|
||||
int rc;
|
||||
FILETIME ft;
|
||||
/* FILETIME structure is a 64-bit value representing the number of
|
||||
** 100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
|
||||
*/
|
||||
if( GetFileTime(id->h, 0, 0, &ft) ){
|
||||
double t;
|
||||
t = ((double)ft.dwHighDateTime) * 4294967296.0;
|
||||
*prMTime = (t + ft.dwLowDateTime)/864000000000.0 + 2305813.5;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* OS_WIN */
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
** 2004 May 22
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This header file defines OS-specific features for Win32
|
||||
*/
|
||||
#ifndef _SQLITE_OS_WIN_H_
|
||||
#define _SQLITE_OS_WIN_H_
|
||||
|
||||
#include <windows.h>
|
||||
#include <winbase.h>
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 off_t;
|
||||
#else
|
||||
# if !defined(_CYGWIN_TYPES_H)
|
||||
typedef long long off_t;
|
||||
# if defined(__MINGW32__)
|
||||
# define _OFF_T_
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The OsFile structure is a operating-system independing representation
|
||||
** of an open file handle. It is defined differently for each architecture.
|
||||
**
|
||||
** This is the definition for Win32.
|
||||
*/
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
HANDLE h; /* Handle for accessing the file */
|
||||
unsigned char locktype; /* Type of lock currently held on this file */
|
||||
unsigned char isOpen; /* True if needs to be closed */
|
||||
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
|
||||
};
|
||||
|
||||
|
||||
#define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
|
||||
#define SQLITE_MIN_SLEEP_MS 1
|
||||
|
||||
|
||||
#endif /* _SQLITE_OS_WIN_H_ */
|
||||
+749
-1705
File diff suppressed because it is too large
Load Diff
+64
-59
@@ -13,29 +13,45 @@
|
||||
** subsystem. The page cache subsystem reads and writes a file a page
|
||||
** at a time and provides a journal for rollback.
|
||||
**
|
||||
** @(#) $Id: pager.h,v 1.37 2004/07/22 01:19:35 drh Exp $
|
||||
** @(#) $Id: pager.h,v 1.26 2004/02/11 02:18:07 drh Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
** The default size of a database page.
|
||||
** The size of one page
|
||||
**
|
||||
** You can change this value to another (reasonable) value you want.
|
||||
** It need not be a power of two, though the interface to the disk
|
||||
** will likely be faster if it is.
|
||||
**
|
||||
** Experiments show that a page size of 1024 gives the best speed
|
||||
** for common usages. The speed differences for different sizes
|
||||
** such as 512, 2048, 4096, an so forth, is minimal. Note, however,
|
||||
** that changing the page size results in a completely imcompatible
|
||||
** file format.
|
||||
*/
|
||||
#ifndef SQLITE_DEFAULT_PAGE_SIZE
|
||||
# define SQLITE_DEFAULT_PAGE_SIZE 1024
|
||||
#endif
|
||||
|
||||
/* Maximum page size. The upper bound on this value is 65536 (a limit
|
||||
** imposed by the 2-byte size of cell array pointers.) The
|
||||
** maximum page size determines the amount of stack space allocated
|
||||
** by many of the routines in pager.c and btree.c On embedded architectures
|
||||
** or any machine where memory and especially stack memory is limited,
|
||||
** one may wish to chose a smaller value for the maximum page size.
|
||||
*/
|
||||
#ifndef SQLITE_MAX_PAGE_SIZE
|
||||
# define SQLITE_MAX_PAGE_SIZE 8192
|
||||
#ifndef SQLITE_PAGE_SIZE
|
||||
#define SQLITE_PAGE_SIZE 1024
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Maximum number of pages in one database.
|
||||
** Number of extra bytes of data allocated at the end of each page and
|
||||
** stored on disk but not used by the higher level btree layer. Changing
|
||||
** this value results in a completely incompatible file format.
|
||||
*/
|
||||
#ifndef SQLITE_PAGE_RESERVE
|
||||
#define SQLITE_PAGE_RESERVE 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The total number of usable bytes stored on disk for each page.
|
||||
** The usable bytes come at the beginning of the page and the reserve
|
||||
** bytes come at the end.
|
||||
*/
|
||||
#define SQLITE_USABLE_SIZE (SQLITE_PAGE_SIZE-SQLITE_PAGE_RESERVE)
|
||||
|
||||
/*
|
||||
** Maximum number of pages in one database. (This is a limitation of
|
||||
** imposed by 4GB files size limits.)
|
||||
*/
|
||||
#define SQLITE_MAX_PAGE 1073741823
|
||||
|
||||
@@ -50,53 +66,42 @@ typedef unsigned int Pgno;
|
||||
*/
|
||||
typedef struct Pager Pager;
|
||||
|
||||
|
||||
/*
|
||||
** See source code comments for a detailed description of the following
|
||||
** routines:
|
||||
*/
|
||||
int sqlite3pager_open(Pager **ppPager, const char *zFilename,
|
||||
int nExtra, int useJournal);
|
||||
void sqlite3pager_set_busyhandler(Pager*, BusyHandler *pBusyHandler);
|
||||
void sqlite3pager_set_destructor(Pager*, void(*)(void*,int));
|
||||
void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int));
|
||||
void sqlite3pager_set_pagesize(Pager*, int);
|
||||
void sqlite3pager_read_fileheader(Pager*, int, unsigned char*);
|
||||
void sqlite3pager_set_cachesize(Pager*, int);
|
||||
int sqlite3pager_close(Pager *pPager);
|
||||
int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage);
|
||||
void *sqlite3pager_lookup(Pager *pPager, Pgno pgno);
|
||||
int sqlite3pager_ref(void*);
|
||||
int sqlite3pager_unref(void*);
|
||||
Pgno sqlite3pager_pagenumber(void*);
|
||||
int sqlite3pager_write(void*);
|
||||
int sqlite3pager_iswriteable(void*);
|
||||
int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void*);
|
||||
int sqlite3pager_pagecount(Pager*);
|
||||
int sqlite3pager_truncate(Pager*,Pgno);
|
||||
int sqlite3pager_begin(void*);
|
||||
int sqlite3pager_commit(Pager*);
|
||||
int sqlite3pager_sync(Pager*,const char *zMaster);
|
||||
int sqlite3pager_rollback(Pager*);
|
||||
int sqlite3pager_isreadonly(Pager*);
|
||||
int sqlite3pager_stmt_begin(Pager*);
|
||||
int sqlite3pager_stmt_commit(Pager*);
|
||||
int sqlite3pager_stmt_rollback(Pager*);
|
||||
void sqlite3pager_dont_rollback(void*);
|
||||
void sqlite3pager_dont_write(Pager*, Pgno);
|
||||
int *sqlite3pager_stats(Pager*);
|
||||
void sqlite3pager_set_safety_level(Pager*,int);
|
||||
const char *sqlite3pager_filename(Pager*);
|
||||
const char *sqlite3pager_dirname(Pager*);
|
||||
const char *sqlite3pager_journalname(Pager*);
|
||||
int sqlite3pager_rename(Pager*, const char *zNewName);
|
||||
void sqlite3pager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);
|
||||
|
||||
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
|
||||
int sqlite3pager_lockstate(Pager*);
|
||||
#endif
|
||||
int sqlitepager_open(Pager **ppPager, const char *zFilename,
|
||||
int nPage, int nExtra, int useJournal);
|
||||
void sqlitepager_set_destructor(Pager*, void(*)(void*));
|
||||
void sqlitepager_set_cachesize(Pager*, int);
|
||||
int sqlitepager_close(Pager *pPager);
|
||||
int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage);
|
||||
void *sqlitepager_lookup(Pager *pPager, Pgno pgno);
|
||||
int sqlitepager_ref(void*);
|
||||
int sqlitepager_unref(void*);
|
||||
Pgno sqlitepager_pagenumber(void*);
|
||||
int sqlitepager_write(void*);
|
||||
int sqlitepager_iswriteable(void*);
|
||||
int sqlitepager_overwrite(Pager *pPager, Pgno pgno, void*);
|
||||
int sqlitepager_pagecount(Pager*);
|
||||
int sqlitepager_truncate(Pager*,Pgno);
|
||||
int sqlitepager_begin(void*);
|
||||
int sqlitepager_commit(Pager*);
|
||||
int sqlitepager_rollback(Pager*);
|
||||
int sqlitepager_isreadonly(Pager*);
|
||||
int sqlitepager_ckpt_begin(Pager*);
|
||||
int sqlitepager_ckpt_commit(Pager*);
|
||||
int sqlitepager_ckpt_rollback(Pager*);
|
||||
void sqlitepager_dont_rollback(void*);
|
||||
void sqlitepager_dont_write(Pager*, Pgno);
|
||||
int *sqlitepager_stats(Pager*);
|
||||
void sqlitepager_set_safety_level(Pager*,int);
|
||||
const char *sqlitepager_filename(Pager*);
|
||||
int sqlitepager_rename(Pager*, const char *zNewName);
|
||||
void sqlitepager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
void sqlite3pager_refdump(Pager*);
|
||||
int pager3_refinfo_enable;
|
||||
void sqlitepager_refdump(Pager*);
|
||||
int pager_refinfo_enable;
|
||||
int journal_format;
|
||||
#endif
|
||||
|
||||
+272
-292
@@ -14,7 +14,7 @@
|
||||
** the parser. Lemon will also generate a header file containing
|
||||
** numeric codes for all of the tokens.
|
||||
**
|
||||
** @(#) $Id: parse.y,v 1.135 2004/08/25 04:07:02 drh Exp $
|
||||
** @(#) $Id: parse.y,v 1.112 2004/02/22 18:40:57 drh Exp $
|
||||
*/
|
||||
%token_prefix TK_
|
||||
%token_type {Token}
|
||||
@@ -23,13 +23,13 @@
|
||||
%syntax_error {
|
||||
if( pParse->zErrMsg==0 ){
|
||||
if( TOKEN.z[0] ){
|
||||
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
|
||||
sqliteErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
|
||||
}else{
|
||||
sqlite3ErrorMsg(pParse, "incomplete SQL statement");
|
||||
sqliteErrorMsg(pParse, "incomplete SQL statement");
|
||||
}
|
||||
}
|
||||
}
|
||||
%name sqlite3Parser
|
||||
%name sqliteParser
|
||||
%include {
|
||||
#include "sqliteInt.h"
|
||||
#include "parse.h"
|
||||
@@ -54,11 +54,6 @@ struct LimitVal {
|
||||
*/
|
||||
struct TrigEvent { int a; IdList * b; };
|
||||
|
||||
/*
|
||||
** An instance of this structure holds the ATTACH key and the key type.
|
||||
*/
|
||||
struct AttachKey { int type; Token key; };
|
||||
|
||||
} // end %include
|
||||
|
||||
// These are extra tokens used by the lexer but never seen by the
|
||||
@@ -74,36 +69,36 @@ cmdlist ::= cmdlist ecmd.
|
||||
cmdlist ::= ecmd.
|
||||
ecmd ::= explain cmdx SEMI.
|
||||
ecmd ::= SEMI.
|
||||
cmdx ::= cmd. { sqlite3FinishCoding(pParse); }
|
||||
explain ::= EXPLAIN. { sqlite3BeginParse(pParse, 1); }
|
||||
explain ::= . { sqlite3BeginParse(pParse, 0); }
|
||||
cmdx ::= cmd. { sqliteExec(pParse); }
|
||||
explain ::= EXPLAIN. { sqliteBeginParse(pParse, 1); }
|
||||
explain ::= . { sqliteBeginParse(pParse, 0); }
|
||||
|
||||
///////////////////// Begin and end transactions. ////////////////////////////
|
||||
//
|
||||
|
||||
cmd ::= BEGIN trans_opt. {sqlite3BeginTransaction(pParse);}
|
||||
cmd ::= BEGIN trans_opt onconf(R). {sqliteBeginTransaction(pParse,R);}
|
||||
trans_opt ::= .
|
||||
trans_opt ::= TRANSACTION.
|
||||
trans_opt ::= TRANSACTION nm.
|
||||
cmd ::= COMMIT trans_opt. {sqlite3CommitTransaction(pParse);}
|
||||
cmd ::= END trans_opt. {sqlite3CommitTransaction(pParse);}
|
||||
cmd ::= ROLLBACK trans_opt. {sqlite3RollbackTransaction(pParse);}
|
||||
cmd ::= COMMIT trans_opt. {sqliteCommitTransaction(pParse);}
|
||||
cmd ::= END trans_opt. {sqliteCommitTransaction(pParse);}
|
||||
cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);}
|
||||
|
||||
///////////////////// The CREATE TABLE statement ////////////////////////////
|
||||
//
|
||||
cmd ::= create_table create_table_args.
|
||||
create_table ::= CREATE(X) temp(T) TABLE nm(Y) dbnm(Z). {
|
||||
sqlite3StartTable(pParse,&X,&Y,&Z,T,0);
|
||||
create_table ::= CREATE(X) temp(T) TABLE nm(Y). {
|
||||
sqliteStartTable(pParse,&X,&Y,T,0);
|
||||
}
|
||||
%type temp {int}
|
||||
temp(A) ::= TEMP. {A = 1;}
|
||||
temp(A) ::= . {A = 0;}
|
||||
create_table_args ::= LP columnlist conslist_opt RP(X). {
|
||||
sqlite3EndTable(pParse,&X,0);
|
||||
sqliteEndTable(pParse,&X,0);
|
||||
}
|
||||
create_table_args ::= AS select(S). {
|
||||
sqlite3EndTable(pParse,0,S);
|
||||
sqlite3SelectDelete(S);
|
||||
sqliteEndTable(pParse,0,S);
|
||||
sqliteSelectDelete(S);
|
||||
}
|
||||
columnlist ::= columnlist COMMA column.
|
||||
columnlist ::= column.
|
||||
@@ -113,7 +108,7 @@ columnlist ::= column.
|
||||
// an elaborate typename. Perhaps someday we'll do something with it.
|
||||
//
|
||||
column ::= columnid type carglist.
|
||||
columnid ::= nm(X). {sqlite3AddColumn(pParse,&X);}
|
||||
columnid ::= nm(X). {sqliteAddColumn(pParse,&X);}
|
||||
|
||||
// An IDENTIFIER can be a generic identifier, or one of several
|
||||
// keywords. Any non-standard keyword can also be an identifier.
|
||||
@@ -127,7 +122,7 @@ id(A) ::= ID(X). {A = X;}
|
||||
//
|
||||
%fallback ID
|
||||
ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT
|
||||
DATABASE DEFERRED DESC DETACH EACH END EXPLAIN FAIL FOR
|
||||
COPY DATABASE DEFERRED DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR
|
||||
GLOB IGNORE IMMEDIATE INITIALLY INSTEAD LIKE MATCH KEY
|
||||
OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT
|
||||
TEMP TRIGGER VACUUM VIEW.
|
||||
@@ -162,13 +157,13 @@ nm(A) ::= STRING(X). {A = X;}
|
||||
nm(A) ::= JOIN_KW(X). {A = X;}
|
||||
|
||||
type ::= .
|
||||
type ::= typename(X). {sqlite3AddColumnType(pParse,&X,&X);}
|
||||
type ::= typename(X) LP signed RP(Y). {sqlite3AddColumnType(pParse,&X,&Y);}
|
||||
type ::= typename(X). {sqliteAddColumnType(pParse,&X,&X);}
|
||||
type ::= typename(X) LP signed RP(Y). {sqliteAddColumnType(pParse,&X,&Y);}
|
||||
type ::= typename(X) LP signed COMMA signed RP(Y).
|
||||
{sqlite3AddColumnType(pParse,&X,&Y);}
|
||||
{sqliteAddColumnType(pParse,&X,&Y);}
|
||||
%type typename {Token}
|
||||
typename(A) ::= ids(X). {A = X;}
|
||||
typename(A) ::= typename(X) ids(Y). {A.z=X.z; A.n=X.n+Addr(Y.z)-Addr(X.z);}
|
||||
typename(A) ::= ids(X). {A = X;}
|
||||
typename(A) ::= typename(X) ids. {A = X;}
|
||||
%type signed {int}
|
||||
signed(A) ::= INTEGER(X). { A = atoi(X.z); }
|
||||
signed(A) ::= PLUS INTEGER(X). { A = atoi(X.z); }
|
||||
@@ -177,28 +172,30 @@ carglist ::= carglist carg.
|
||||
carglist ::= .
|
||||
carg ::= CONSTRAINT nm ccons.
|
||||
carg ::= ccons.
|
||||
carg ::= DEFAULT STRING(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT ID(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT INTEGER(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT PLUS INTEGER(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT MINUS INTEGER(X). {sqlite3AddDefaultValue(pParse,&X,1);}
|
||||
carg ::= DEFAULT FLOAT(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT PLUS FLOAT(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT MINUS FLOAT(X). {sqlite3AddDefaultValue(pParse,&X,1);}
|
||||
carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
|
||||
carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
|
||||
carg ::= DEFAULT NULL.
|
||||
|
||||
// In addition to the type name, we also care about the primary key and
|
||||
// UNIQUE constraints.
|
||||
//
|
||||
ccons ::= NULL onconf.
|
||||
ccons ::= NOT NULL onconf(R). {sqlite3AddNotNull(pParse, R);}
|
||||
ccons ::= PRIMARY KEY sortorder onconf(R). {sqlite3AddPrimaryKey(pParse,0,R);}
|
||||
ccons ::= UNIQUE onconf(R). {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0);}
|
||||
ccons ::= NOT NULL onconf(R). {sqliteAddNotNull(pParse, R);}
|
||||
ccons ::= PRIMARY KEY sortorder onconf(R). {sqliteAddPrimaryKey(pParse,0,R);}
|
||||
ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);}
|
||||
ccons ::= CHECK LP expr RP onconf.
|
||||
ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R).
|
||||
{sqlite3CreateForeignKey(pParse,0,&T,TA,R);}
|
||||
ccons ::= defer_subclause(D). {sqlite3DeferForeignKey(pParse,D);}
|
||||
ccons ::= COLLATE id(C). {sqlite3AddCollateType(pParse, C.z, C.n);}
|
||||
{sqliteCreateForeignKey(pParse,0,&T,TA,R);}
|
||||
ccons ::= defer_subclause(D). {sqliteDeferForeignKey(pParse,D);}
|
||||
ccons ::= COLLATE id(C). {
|
||||
sqliteAddCollateType(pParse, sqliteCollateType(C.z, C.n));
|
||||
}
|
||||
|
||||
// The next group of rules parses the arguments to a REFERENCES clause
|
||||
// that determine if the referential integrity checking is deferred or
|
||||
@@ -236,14 +233,14 @@ conslist ::= conslist tcons.
|
||||
conslist ::= tcons.
|
||||
tcons ::= CONSTRAINT nm.
|
||||
tcons ::= PRIMARY KEY LP idxlist(X) RP onconf(R).
|
||||
{sqlite3AddPrimaryKey(pParse,X,R);}
|
||||
{sqliteAddPrimaryKey(pParse,X,R);}
|
||||
tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
|
||||
{sqlite3CreateIndex(pParse,0,0,0,X,R,0,0);}
|
||||
{sqliteCreateIndex(pParse,0,0,X,R,0,0);}
|
||||
tcons ::= CHECK expr onconf.
|
||||
tcons ::= FOREIGN KEY LP idxlist(FA) RP
|
||||
REFERENCES nm(T) idxlist_opt(TA) refargs(R) defer_subclause_opt(D). {
|
||||
sqlite3CreateForeignKey(pParse, FA, &T, TA, R);
|
||||
sqlite3DeferForeignKey(pParse, D);
|
||||
sqliteCreateForeignKey(pParse, FA, &T, TA, R);
|
||||
sqliteDeferForeignKey(pParse, D);
|
||||
}
|
||||
%type defer_subclause_opt {int}
|
||||
defer_subclause_opt(A) ::= . {A = 0;}
|
||||
@@ -267,30 +264,28 @@ resolvetype(A) ::= REPLACE. { A = OE_Replace; }
|
||||
|
||||
////////////////////////// The DROP TABLE /////////////////////////////////////
|
||||
//
|
||||
cmd ::= DROP TABLE nm(X) dbnm(Y). {
|
||||
sqlite3DropTable(pParse, sqlite3SrcListAppend(0,&X,&Y), 0);
|
||||
}
|
||||
cmd ::= DROP TABLE nm(X). {sqliteDropTable(pParse,&X,0);}
|
||||
|
||||
///////////////////// The CREATE VIEW statement /////////////////////////////
|
||||
//
|
||||
cmd ::= CREATE(X) temp(T) VIEW nm(Y) dbnm(Z) AS select(S). {
|
||||
sqlite3CreateView(pParse, &X, &Y, &Z, S, T);
|
||||
cmd ::= CREATE(X) temp(T) VIEW nm(Y) AS select(S). {
|
||||
sqliteCreateView(pParse, &X, &Y, S, T);
|
||||
}
|
||||
cmd ::= DROP VIEW nm(X) dbnm(Y). {
|
||||
sqlite3DropTable(pParse, sqlite3SrcListAppend(0,&X,&Y), 1);
|
||||
cmd ::= DROP VIEW nm(X). {
|
||||
sqliteDropTable(pParse, &X, 1);
|
||||
}
|
||||
|
||||
//////////////////////// The SELECT statement /////////////////////////////////
|
||||
//
|
||||
cmd ::= select(X). {
|
||||
sqlite3Select(pParse, X, SRT_Callback, 0, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(X);
|
||||
sqliteSelect(pParse, X, SRT_Callback, 0, 0, 0, 0);
|
||||
sqliteSelectDelete(X);
|
||||
}
|
||||
|
||||
%type select {Select*}
|
||||
%destructor select {sqlite3SelectDelete($$);}
|
||||
%destructor select {sqliteSelectDelete($$);}
|
||||
%type oneselect {Select*}
|
||||
%destructor oneselect {sqlite3SelectDelete($$);}
|
||||
%destructor oneselect {sqliteSelectDelete($$);}
|
||||
|
||||
select(A) ::= oneselect(X). {A = X;}
|
||||
select(A) ::= select(X) multiselect_op(Y) oneselect(Z). {
|
||||
@@ -307,7 +302,7 @@ multiselect_op(A) ::= INTERSECT. {A = TK_INTERSECT;}
|
||||
multiselect_op(A) ::= EXCEPT. {A = TK_EXCEPT;}
|
||||
oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
|
||||
groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
|
||||
A = sqlite3SelectNew(W,X,Y,P,Q,Z,D,L.limit,L.offset);
|
||||
A = sqliteSelectNew(W,X,Y,P,Q,Z,D,L.limit,L.offset);
|
||||
}
|
||||
|
||||
// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
|
||||
@@ -324,21 +319,21 @@ distinct(A) ::= . {A = 0;}
|
||||
// opcode of TK_ALL.
|
||||
//
|
||||
%type selcollist {ExprList*}
|
||||
%destructor selcollist {sqlite3ExprListDelete($$);}
|
||||
%destructor selcollist {sqliteExprListDelete($$);}
|
||||
%type sclp {ExprList*}
|
||||
%destructor sclp {sqlite3ExprListDelete($$);}
|
||||
%destructor sclp {sqliteExprListDelete($$);}
|
||||
sclp(A) ::= selcollist(X) COMMA. {A = X;}
|
||||
sclp(A) ::= . {A = 0;}
|
||||
selcollist(A) ::= sclp(P) expr(X) as(Y). {
|
||||
A = sqlite3ExprListAppend(P,X,Y.n?&Y:0);
|
||||
A = sqliteExprListAppend(P,X,Y.n?&Y:0);
|
||||
}
|
||||
selcollist(A) ::= sclp(P) STAR. {
|
||||
A = sqlite3ExprListAppend(P, sqlite3Expr(TK_ALL, 0, 0, 0), 0);
|
||||
A = sqliteExprListAppend(P, sqliteExpr(TK_ALL, 0, 0, 0), 0);
|
||||
}
|
||||
selcollist(A) ::= sclp(P) nm(X) DOT STAR. {
|
||||
Expr *pRight = sqlite3Expr(TK_ALL, 0, 0, 0);
|
||||
Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &X);
|
||||
A = sqlite3ExprListAppend(P, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0);
|
||||
Expr *pRight = sqliteExpr(TK_ALL, 0, 0, 0);
|
||||
Expr *pLeft = sqliteExpr(TK_ID, 0, 0, &X);
|
||||
A = sqliteExprListAppend(P, sqliteExpr(TK_DOT, pLeft, pRight, 0), 0);
|
||||
}
|
||||
|
||||
// An option "AS <id>" phrase that can follow one of the expressions that
|
||||
@@ -351,11 +346,11 @@ as(X) ::= . { X.n = 0; }
|
||||
|
||||
|
||||
%type seltablist {SrcList*}
|
||||
%destructor seltablist {sqlite3SrcListDelete($$);}
|
||||
%destructor seltablist {sqliteSrcListDelete($$);}
|
||||
%type stl_prefix {SrcList*}
|
||||
%destructor stl_prefix {sqlite3SrcListDelete($$);}
|
||||
%destructor stl_prefix {sqliteSrcListDelete($$);}
|
||||
%type from {SrcList*}
|
||||
%destructor from {sqlite3SrcListDelete($$);}
|
||||
%destructor from {sqliteSrcListDelete($$);}
|
||||
|
||||
// A complete FROM clause.
|
||||
//
|
||||
@@ -371,29 +366,29 @@ stl_prefix(A) ::= seltablist(X) joinop(Y). {
|
||||
}
|
||||
stl_prefix(A) ::= . {A = 0;}
|
||||
seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) on_opt(N) using_opt(U). {
|
||||
A = sqlite3SrcListAppend(X,&Y,&D);
|
||||
if( Z.n ) sqlite3SrcListAddAlias(A,&Z);
|
||||
A = sqliteSrcListAppend(X,&Y,&D);
|
||||
if( Z.n ) sqliteSrcListAddAlias(A,&Z);
|
||||
if( N ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
|
||||
else { sqlite3ExprDelete(N); }
|
||||
else { sqliteExprDelete(N); }
|
||||
}
|
||||
if( U ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
|
||||
else { sqlite3IdListDelete(U); }
|
||||
else { sqliteIdListDelete(U); }
|
||||
}
|
||||
}
|
||||
seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP
|
||||
as(Z) on_opt(N) using_opt(U). {
|
||||
A = sqlite3SrcListAppend(X,0,0);
|
||||
A = sqliteSrcListAppend(X,0,0);
|
||||
A->a[A->nSrc-1].pSelect = S;
|
||||
if( Z.n ) sqlite3SrcListAddAlias(A,&Z);
|
||||
if( Z.n ) sqliteSrcListAddAlias(A,&Z);
|
||||
if( N ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
|
||||
else { sqlite3ExprDelete(N); }
|
||||
else { sqliteExprDelete(N); }
|
||||
}
|
||||
if( U ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
|
||||
else { sqlite3IdListDelete(U); }
|
||||
else { sqliteIdListDelete(U); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,10 +397,10 @@ seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP
|
||||
// a grouping of table and subqueries.
|
||||
//
|
||||
%type seltablist_paren {Select*}
|
||||
%destructor seltablist_paren {sqlite3SelectDelete($$);}
|
||||
%destructor seltablist_paren {sqliteSelectDelete($$);}
|
||||
seltablist_paren(A) ::= select(S). {A = S;}
|
||||
seltablist_paren(A) ::= seltablist(F). {
|
||||
A = sqlite3SelectNew(0,F,0,0,0,0,0,-1,0);
|
||||
A = sqliteSelectNew(0,F,0,0,0,0,0,-1,0);
|
||||
}
|
||||
|
||||
%type dbnm {Token}
|
||||
@@ -416,57 +411,57 @@ dbnm(A) ::= DOT nm(X). {A = X;}
|
||||
%type joinop2 {int}
|
||||
joinop(X) ::= COMMA. { X = JT_INNER; }
|
||||
joinop(X) ::= JOIN. { X = JT_INNER; }
|
||||
joinop(X) ::= JOIN_KW(A) JOIN. { X = sqlite3JoinType(pParse,&A,0,0); }
|
||||
joinop(X) ::= JOIN_KW(A) nm(B) JOIN. { X = sqlite3JoinType(pParse,&A,&B,0); }
|
||||
joinop(X) ::= JOIN_KW(A) JOIN. { X = sqliteJoinType(pParse,&A,0,0); }
|
||||
joinop(X) ::= JOIN_KW(A) nm(B) JOIN. { X = sqliteJoinType(pParse,&A,&B,0); }
|
||||
joinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN.
|
||||
{ X = sqlite3JoinType(pParse,&A,&B,&C); }
|
||||
{ X = sqliteJoinType(pParse,&A,&B,&C); }
|
||||
|
||||
%type on_opt {Expr*}
|
||||
%destructor on_opt {sqlite3ExprDelete($$);}
|
||||
%destructor on_opt {sqliteExprDelete($$);}
|
||||
on_opt(N) ::= ON expr(E). {N = E;}
|
||||
on_opt(N) ::= . {N = 0;}
|
||||
|
||||
%type using_opt {IdList*}
|
||||
%destructor using_opt {sqlite3IdListDelete($$);}
|
||||
using_opt(U) ::= USING LP inscollist(L) RP. {U = L;}
|
||||
%destructor using_opt {sqliteIdListDelete($$);}
|
||||
using_opt(U) ::= USING LP idxlist(L) RP. {U = L;}
|
||||
using_opt(U) ::= . {U = 0;}
|
||||
|
||||
|
||||
%type orderby_opt {ExprList*}
|
||||
%destructor orderby_opt {sqlite3ExprListDelete($$);}
|
||||
%destructor orderby_opt {sqliteExprListDelete($$);}
|
||||
%type sortlist {ExprList*}
|
||||
%destructor sortlist {sqlite3ExprListDelete($$);}
|
||||
%destructor sortlist {sqliteExprListDelete($$);}
|
||||
%type sortitem {Expr*}
|
||||
%destructor sortitem {sqlite3ExprDelete($$);}
|
||||
%destructor sortitem {sqliteExprDelete($$);}
|
||||
|
||||
orderby_opt(A) ::= . {A = 0;}
|
||||
orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
|
||||
sortlist(A) ::= sortlist(X) COMMA sortitem(Y) collate(C) sortorder(Z). {
|
||||
A = sqlite3ExprListAppend(X,Y,C.n>0?&C:0);
|
||||
if( A ) A->a[A->nExpr-1].sortOrder = Z;
|
||||
A = sqliteExprListAppend(X,Y,0);
|
||||
if( A ) A->a[A->nExpr-1].sortOrder = C+Z;
|
||||
}
|
||||
sortlist(A) ::= sortitem(Y) collate(C) sortorder(Z). {
|
||||
A = sqlite3ExprListAppend(0,Y,C.n>0?&C:0);
|
||||
if( A && A->a ) A->a[0].sortOrder = Z;
|
||||
A = sqliteExprListAppend(0,Y,0);
|
||||
if( A ) A->a[0].sortOrder = C+Z;
|
||||
}
|
||||
sortitem(A) ::= expr(X). {A = X;}
|
||||
|
||||
%type sortorder {int}
|
||||
%type collate {Token}
|
||||
%type collate {int}
|
||||
|
||||
sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;}
|
||||
sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;}
|
||||
sortorder(A) ::= . {A = SQLITE_SO_ASC;}
|
||||
collate(C) ::= . {C.z = 0; C.n = 0;}
|
||||
collate(C) ::= COLLATE id(X). {C = X;}
|
||||
collate(C) ::= . {C = SQLITE_SO_UNK;}
|
||||
collate(C) ::= COLLATE id(X). {C = sqliteCollateType(X.z, X.n);}
|
||||
|
||||
%type groupby_opt {ExprList*}
|
||||
%destructor groupby_opt {sqlite3ExprListDelete($$);}
|
||||
%destructor groupby_opt {sqliteExprListDelete($$);}
|
||||
groupby_opt(A) ::= . {A = 0;}
|
||||
groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
|
||||
|
||||
%type having_opt {Expr*}
|
||||
%destructor having_opt {sqlite3ExprDelete($$);}
|
||||
%destructor having_opt {sqliteExprDelete($$);}
|
||||
having_opt(A) ::= . {A = 0;}
|
||||
having_opt(A) ::= HAVING expr(X). {A = X;}
|
||||
|
||||
@@ -481,34 +476,34 @@ limit_opt(A) ::= LIMIT signed(X) COMMA signed(Y).
|
||||
/////////////////////////// The DELETE statement /////////////////////////////
|
||||
//
|
||||
cmd ::= DELETE FROM nm(X) dbnm(D) where_opt(Y). {
|
||||
sqlite3DeleteFrom(pParse, sqlite3SrcListAppend(0,&X,&D), Y);
|
||||
sqliteDeleteFrom(pParse, sqliteSrcListAppend(0,&X,&D), Y);
|
||||
}
|
||||
|
||||
%type where_opt {Expr*}
|
||||
%destructor where_opt {sqlite3ExprDelete($$);}
|
||||
%destructor where_opt {sqliteExprDelete($$);}
|
||||
|
||||
where_opt(A) ::= . {A = 0;}
|
||||
where_opt(A) ::= WHERE expr(X). {A = X;}
|
||||
|
||||
%type setlist {ExprList*}
|
||||
%destructor setlist {sqlite3ExprListDelete($$);}
|
||||
%destructor setlist {sqliteExprListDelete($$);}
|
||||
|
||||
////////////////////////// The UPDATE command ////////////////////////////////
|
||||
//
|
||||
cmd ::= UPDATE orconf(R) nm(X) dbnm(D) SET setlist(Y) where_opt(Z).
|
||||
{sqlite3Update(pParse,sqlite3SrcListAppend(0,&X,&D),Y,Z,R);}
|
||||
{sqliteUpdate(pParse,sqliteSrcListAppend(0,&X,&D),Y,Z,R);}
|
||||
|
||||
setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y).
|
||||
{A = sqlite3ExprListAppend(Z,Y,&X);}
|
||||
setlist(A) ::= nm(X) EQ expr(Y). {A = sqlite3ExprListAppend(0,Y,&X);}
|
||||
{A = sqliteExprListAppend(Z,Y,&X);}
|
||||
setlist(A) ::= nm(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
|
||||
|
||||
////////////////////////// The INSERT command /////////////////////////////////
|
||||
//
|
||||
cmd ::= insert_cmd(R) INTO nm(X) dbnm(D) inscollist_opt(F)
|
||||
VALUES LP itemlist(Y) RP.
|
||||
{sqlite3Insert(pParse, sqlite3SrcListAppend(0,&X,&D), Y, 0, F, R);}
|
||||
{sqliteInsert(pParse, sqliteSrcListAppend(0,&X,&D), Y, 0, F, R);}
|
||||
cmd ::= insert_cmd(R) INTO nm(X) dbnm(D) inscollist_opt(F) select(S).
|
||||
{sqlite3Insert(pParse, sqlite3SrcListAppend(0,&X,&D), 0, S, F, R);}
|
||||
{sqliteInsert(pParse, sqliteSrcListAppend(0,&X,&D), 0, S, F, R);}
|
||||
|
||||
%type insert_cmd {int}
|
||||
insert_cmd(A) ::= INSERT orconf(R). {A = R;}
|
||||
@@ -516,206 +511,202 @@ insert_cmd(A) ::= REPLACE. {A = OE_Replace;}
|
||||
|
||||
|
||||
%type itemlist {ExprList*}
|
||||
%destructor itemlist {sqlite3ExprListDelete($$);}
|
||||
%destructor itemlist {sqliteExprListDelete($$);}
|
||||
|
||||
itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = sqlite3ExprListAppend(X,Y,0);}
|
||||
itemlist(A) ::= expr(X). {A = sqlite3ExprListAppend(0,X,0);}
|
||||
itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = sqliteExprListAppend(X,Y,0);}
|
||||
itemlist(A) ::= expr(X). {A = sqliteExprListAppend(0,X,0);}
|
||||
|
||||
%type inscollist_opt {IdList*}
|
||||
%destructor inscollist_opt {sqlite3IdListDelete($$);}
|
||||
%destructor inscollist_opt {sqliteIdListDelete($$);}
|
||||
%type inscollist {IdList*}
|
||||
%destructor inscollist {sqlite3IdListDelete($$);}
|
||||
%destructor inscollist {sqliteIdListDelete($$);}
|
||||
|
||||
inscollist_opt(A) ::= . {A = 0;}
|
||||
inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
|
||||
inscollist(A) ::= inscollist(X) COMMA nm(Y). {A = sqlite3IdListAppend(X,&Y);}
|
||||
inscollist(A) ::= nm(Y). {A = sqlite3IdListAppend(0,&Y);}
|
||||
inscollist(A) ::= inscollist(X) COMMA nm(Y). {A = sqliteIdListAppend(X,&Y);}
|
||||
inscollist(A) ::= nm(Y). {A = sqliteIdListAppend(0,&Y);}
|
||||
|
||||
/////////////////////////// Expression Processing /////////////////////////////
|
||||
//
|
||||
|
||||
%type expr {Expr*}
|
||||
%destructor expr {sqlite3ExprDelete($$);}
|
||||
%destructor expr {sqliteExprDelete($$);}
|
||||
|
||||
expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqlite3ExprSpan(A,&B,&E); }
|
||||
expr(A) ::= NULL(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= ID(X). {A = sqlite3Expr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= JOIN_KW(X). {A = sqlite3Expr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E); }
|
||||
expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
|
||||
expr(A) ::= ID(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= JOIN_KW(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= nm(X) DOT nm(Y). {
|
||||
Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &X);
|
||||
Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &Y);
|
||||
A = sqlite3Expr(TK_DOT, temp1, temp2, 0);
|
||||
Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
|
||||
Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
|
||||
A = sqliteExpr(TK_DOT, temp1, temp2, 0);
|
||||
}
|
||||
expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
|
||||
Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &X);
|
||||
Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &Y);
|
||||
Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &Z);
|
||||
Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0);
|
||||
A = sqlite3Expr(TK_DOT, temp1, temp4, 0);
|
||||
Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
|
||||
Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
|
||||
Expr *temp3 = sqliteExpr(TK_ID, 0, 0, &Z);
|
||||
Expr *temp4 = sqliteExpr(TK_DOT, temp2, temp3, 0);
|
||||
A = sqliteExpr(TK_DOT, temp1, temp4, 0);
|
||||
}
|
||||
expr(A) ::= INTEGER(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= FLOAT(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= STRING(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
|
||||
expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
|
||||
expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
|
||||
expr(A) ::= VARIABLE(X). {
|
||||
Token *pToken = &X;
|
||||
Expr *pExpr = A = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
|
||||
if( pExpr ){
|
||||
pExpr->iTable = ++pParse->nVar;
|
||||
}
|
||||
A = sqliteExpr(TK_VARIABLE, 0, 0, &X);
|
||||
if( A ) A->iTable = ++pParse->nVar;
|
||||
}
|
||||
expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
|
||||
A = sqlite3ExprFunction(Y, &X);
|
||||
sqlite3ExprSpan(A,&X,&E);
|
||||
A = sqliteExprFunction(Y, &X);
|
||||
sqliteExprSpan(A,&X,&E);
|
||||
}
|
||||
expr(A) ::= ID(X) LP STAR RP(E). {
|
||||
A = sqlite3ExprFunction(0, &X);
|
||||
sqlite3ExprSpan(A,&X,&E);
|
||||
A = sqliteExprFunction(0, &X);
|
||||
sqliteExprSpan(A,&X,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) GT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) GE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) NE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) EQ(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITAND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITOR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LSHIFT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) RSHIFT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
|
||||
expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
|
||||
expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
|
||||
expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
|
||||
expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITAND expr(Y). {A = sqliteExpr(TK_BITAND, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITOR expr(Y). {A = sqliteExpr(TK_BITOR, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LSHIFT expr(Y). {A = sqliteExpr(TK_LSHIFT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) RSHIFT expr(Y). {A = sqliteExpr(TK_RSHIFT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) likeop(OP) expr(Y). [LIKE] {
|
||||
ExprList *pList = sqlite3ExprListAppend(0, Y, 0);
|
||||
pList = sqlite3ExprListAppend(pList, X, 0);
|
||||
A = sqlite3ExprFunction(pList, 0);
|
||||
ExprList *pList = sqliteExprListAppend(0, Y, 0);
|
||||
pList = sqliteExprListAppend(pList, X, 0);
|
||||
A = sqliteExprFunction(pList, 0);
|
||||
if( A ) A->op = OP;
|
||||
sqlite3ExprSpan(A, &X->span, &Y->span);
|
||||
sqliteExprSpan(A, &X->span, &Y->span);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT likeop(OP) expr(Y). [LIKE] {
|
||||
ExprList *pList = sqlite3ExprListAppend(0, Y, 0);
|
||||
pList = sqlite3ExprListAppend(pList, X, 0);
|
||||
A = sqlite3ExprFunction(pList, 0);
|
||||
ExprList *pList = sqliteExprListAppend(0, Y, 0);
|
||||
pList = sqliteExprListAppend(pList, X, 0);
|
||||
A = sqliteExprFunction(pList, 0);
|
||||
if( A ) A->op = OP;
|
||||
A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&Y->span);
|
||||
A = sqliteExpr(TK_NOT, A, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&Y->span);
|
||||
}
|
||||
%type likeop {int}
|
||||
likeop(A) ::= LIKE. {A = TK_LIKE;}
|
||||
likeop(A) ::= GLOB. {A = TK_GLOB;}
|
||||
expr(A) ::= expr(X) PLUS(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) MINUS(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) STAR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) SLASH(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) REM(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
|
||||
expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
|
||||
expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
|
||||
expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
|
||||
expr(A) ::= expr(X) REM expr(Y). {A = sqliteExpr(TK_REM, X, Y, 0);}
|
||||
expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) ISNULL(E). {
|
||||
A = sqlite3Expr(TK_ISNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
A = sqliteExpr(TK_ISNULL, X, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) IS NULL(E). {
|
||||
A = sqlite3Expr(TK_ISNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
A = sqliteExpr(TK_ISNULL, X, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) NOTNULL(E). {
|
||||
A = sqlite3Expr(TK_NOTNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
A = sqliteExpr(TK_NOTNULL, X, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT NULL(E). {
|
||||
A = sqlite3Expr(TK_NOTNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
A = sqliteExpr(TK_NOTNULL, X, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) IS NOT NULL(E). {
|
||||
A = sqlite3Expr(TK_NOTNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
A = sqliteExpr(TK_NOTNULL, X, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= NOT(B) expr(X). {
|
||||
A = sqlite3Expr(@B, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&B,&X->span);
|
||||
A = sqliteExpr(TK_NOT, X, 0, 0);
|
||||
sqliteExprSpan(A,&B,&X->span);
|
||||
}
|
||||
expr(A) ::= BITNOT(B) expr(X). {
|
||||
A = sqlite3Expr(@B, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&B,&X->span);
|
||||
A = sqliteExpr(TK_BITNOT, X, 0, 0);
|
||||
sqliteExprSpan(A,&B,&X->span);
|
||||
}
|
||||
expr(A) ::= MINUS(B) expr(X). [UMINUS] {
|
||||
A = sqlite3Expr(TK_UMINUS, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&B,&X->span);
|
||||
A = sqliteExpr(TK_UMINUS, X, 0, 0);
|
||||
sqliteExprSpan(A,&B,&X->span);
|
||||
}
|
||||
expr(A) ::= PLUS(B) expr(X). [UPLUS] {
|
||||
A = sqlite3Expr(TK_UPLUS, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&B,&X->span);
|
||||
A = sqliteExpr(TK_UPLUS, X, 0, 0);
|
||||
sqliteExprSpan(A,&B,&X->span);
|
||||
}
|
||||
expr(A) ::= LP(B) select(X) RP(E). {
|
||||
A = sqlite3Expr(TK_SELECT, 0, 0, 0);
|
||||
A = sqliteExpr(TK_SELECT, 0, 0, 0);
|
||||
if( A ) A->pSelect = X;
|
||||
sqlite3ExprSpan(A,&B,&E);
|
||||
sqliteExprSpan(A,&B,&E);
|
||||
}
|
||||
expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
|
||||
ExprList *pList = sqlite3ExprListAppend(0, X, 0);
|
||||
pList = sqlite3ExprListAppend(pList, Y, 0);
|
||||
A = sqlite3Expr(TK_BETWEEN, W, 0, 0);
|
||||
ExprList *pList = sqliteExprListAppend(0, X, 0);
|
||||
pList = sqliteExprListAppend(pList, Y, 0);
|
||||
A = sqliteExpr(TK_BETWEEN, W, 0, 0);
|
||||
if( A ) A->pList = pList;
|
||||
sqlite3ExprSpan(A,&W->span,&Y->span);
|
||||
sqliteExprSpan(A,&W->span,&Y->span);
|
||||
}
|
||||
expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
|
||||
ExprList *pList = sqlite3ExprListAppend(0, X, 0);
|
||||
pList = sqlite3ExprListAppend(pList, Y, 0);
|
||||
A = sqlite3Expr(TK_BETWEEN, W, 0, 0);
|
||||
ExprList *pList = sqliteExprListAppend(0, X, 0);
|
||||
pList = sqliteExprListAppend(pList, Y, 0);
|
||||
A = sqliteExpr(TK_BETWEEN, W, 0, 0);
|
||||
if( A ) A->pList = pList;
|
||||
A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&W->span,&Y->span);
|
||||
A = sqliteExpr(TK_NOT, A, 0, 0);
|
||||
sqliteExprSpan(A,&W->span,&Y->span);
|
||||
}
|
||||
expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
A = sqliteExpr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pList = Y;
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) IN LP select(Y) RP(E). {
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
A = sqliteExpr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = Y;
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
A = sqliteExpr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pList = Y;
|
||||
A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
A = sqliteExpr(TK_NOT, A, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
A = sqliteExpr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = Y;
|
||||
A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
A = sqliteExpr(TK_NOT, A, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) IN nm(Y) dbnm(D). {
|
||||
SrcList *pSrc = sqlite3SrcListAppend(0, &Y, &D);
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,-1,0);
|
||||
sqlite3ExprSpan(A,&X->span,D.z?&D:&Y);
|
||||
SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D);
|
||||
A = sqliteExpr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = sqliteSelectNew(0,pSrc,0,0,0,0,0,-1,0);
|
||||
sqliteExprSpan(A,&X->span,D.z?&D:&Y);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT IN nm(Y) dbnm(D). {
|
||||
SrcList *pSrc = sqlite3SrcListAppend(0, &Y, &D);
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,-1,0);
|
||||
A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,D.z?&D:&Y);
|
||||
SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D);
|
||||
A = sqliteExpr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = sqliteSelectNew(0,pSrc,0,0,0,0,0,-1,0);
|
||||
A = sqliteExpr(TK_NOT, A, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,D.z?&D:&Y);
|
||||
}
|
||||
|
||||
|
||||
/* CASE expressions */
|
||||
expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
|
||||
A = sqlite3Expr(TK_CASE, X, Z, 0);
|
||||
A = sqliteExpr(TK_CASE, X, Z, 0);
|
||||
if( A ) A->pList = Y;
|
||||
sqlite3ExprSpan(A, &C, &E);
|
||||
sqliteExprSpan(A, &C, &E);
|
||||
}
|
||||
%type case_exprlist {ExprList*}
|
||||
%destructor case_exprlist {sqlite3ExprListDelete($$);}
|
||||
%destructor case_exprlist {sqliteExprListDelete($$);}
|
||||
case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). {
|
||||
A = sqlite3ExprListAppend(X, Y, 0);
|
||||
A = sqlite3ExprListAppend(A, Z, 0);
|
||||
A = sqliteExprListAppend(X, Y, 0);
|
||||
A = sqliteExprListAppend(A, Z, 0);
|
||||
}
|
||||
case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). {
|
||||
A = sqlite3ExprListAppend(0, Y, 0);
|
||||
A = sqlite3ExprListAppend(A, Z, 0);
|
||||
A = sqliteExprListAppend(0, Y, 0);
|
||||
A = sqliteExprListAppend(A, Z, 0);
|
||||
}
|
||||
%type case_else {Expr*}
|
||||
case_else(A) ::= ELSE expr(X). {A = X;}
|
||||
@@ -725,79 +716,70 @@ case_operand(A) ::= expr(X). {A = X;}
|
||||
case_operand(A) ::= . {A = 0;}
|
||||
|
||||
%type exprlist {ExprList*}
|
||||
%destructor exprlist {sqlite3ExprListDelete($$);}
|
||||
%destructor exprlist {sqliteExprListDelete($$);}
|
||||
%type expritem {Expr*}
|
||||
%destructor expritem {sqlite3ExprDelete($$);}
|
||||
%destructor expritem {sqliteExprDelete($$);}
|
||||
|
||||
exprlist(A) ::= exprlist(X) COMMA expritem(Y).
|
||||
{A = sqlite3ExprListAppend(X,Y,0);}
|
||||
exprlist(A) ::= expritem(X). {A = sqlite3ExprListAppend(0,X,0);}
|
||||
{A = sqliteExprListAppend(X,Y,0);}
|
||||
exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
|
||||
expritem(A) ::= expr(X). {A = X;}
|
||||
expritem(A) ::= . {A = 0;}
|
||||
|
||||
///////////////////////////// The CREATE INDEX command ///////////////////////
|
||||
//
|
||||
cmd ::= CREATE(S) uniqueflag(U) INDEX nm(X) dbnm(D)
|
||||
ON nm(Y) dbnm(C) LP idxlist(Z) RP(E) onconf(R). {
|
||||
cmd ::= CREATE(S) uniqueflag(U) INDEX nm(X)
|
||||
ON nm(Y) dbnm(D) LP idxlist(Z) RP(E) onconf(R). {
|
||||
SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D);
|
||||
if( U!=OE_None ) U = R;
|
||||
if( U==OE_Default) U = OE_Abort;
|
||||
sqlite3CreateIndex(pParse, &X, &D, sqlite3SrcListAppend(0,&Y,&C),
|
||||
Z, U, &S, &E);
|
||||
sqliteCreateIndex(pParse, &X, pSrc, Z, U, &S, &E);
|
||||
}
|
||||
|
||||
%type uniqueflag {int}
|
||||
uniqueflag(A) ::= UNIQUE. { A = OE_Abort; }
|
||||
uniqueflag(A) ::= . { A = OE_None; }
|
||||
|
||||
%type idxlist {ExprList*}
|
||||
%destructor idxlist {sqlite3ExprListDelete($$);}
|
||||
%type idxlist_opt {ExprList*}
|
||||
%destructor idxlist_opt {sqlite3ExprListDelete($$);}
|
||||
%type idxlist {IdList*}
|
||||
%destructor idxlist {sqliteIdListDelete($$);}
|
||||
%type idxlist_opt {IdList*}
|
||||
%destructor idxlist_opt {sqliteIdListDelete($$);}
|
||||
%type idxitem {Token}
|
||||
|
||||
idxlist_opt(A) ::= . {A = 0;}
|
||||
idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;}
|
||||
idxlist(A) ::= idxlist(X) COMMA idxitem(Y) collate(C) sortorder. {
|
||||
Expr *p = 0;
|
||||
if( C.n>0 ){
|
||||
p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
|
||||
if( p ) p->pColl = sqlite3LocateCollSeq(pParse, C.z, C.n);
|
||||
}
|
||||
A = sqlite3ExprListAppend(X, p, &Y);
|
||||
}
|
||||
idxlist(A) ::= idxitem(Y) collate(C) sortorder. {
|
||||
Expr *p = 0;
|
||||
if( C.n>0 ){
|
||||
p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
|
||||
if( p ) p->pColl = sqlite3LocateCollSeq(pParse, C.z, C.n);
|
||||
}
|
||||
A = sqlite3ExprListAppend(0, p, &Y);
|
||||
}
|
||||
idxitem(A) ::= nm(X). {A = X;}
|
||||
|
||||
idxlist(A) ::= idxlist(X) COMMA idxitem(Y). {A = sqliteIdListAppend(X,&Y);}
|
||||
idxlist(A) ::= idxitem(Y). {A = sqliteIdListAppend(0,&Y);}
|
||||
idxitem(A) ::= nm(X) sortorder. {A = X;}
|
||||
|
||||
///////////////////////////// The DROP INDEX command /////////////////////////
|
||||
//
|
||||
|
||||
cmd ::= DROP INDEX nm(X) dbnm(Y). {
|
||||
sqlite3DropIndex(pParse, sqlite3SrcListAppend(0,&X,&Y));
|
||||
sqliteDropIndex(pParse, sqliteSrcListAppend(0,&X,&Y));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////// The COPY command ///////////////////////////////
|
||||
//
|
||||
cmd ::= COPY orconf(R) nm(X) dbnm(D) FROM nm(Y) USING DELIMITERS STRING(Z).
|
||||
{sqliteCopy(pParse,sqliteSrcListAppend(0,&X,&D),&Y,&Z,R);}
|
||||
cmd ::= COPY orconf(R) nm(X) dbnm(D) FROM nm(Y).
|
||||
{sqliteCopy(pParse,sqliteSrcListAppend(0,&X,&D),&Y,0,R);}
|
||||
|
||||
///////////////////////////// The VACUUM command /////////////////////////////
|
||||
//
|
||||
cmd ::= VACUUM. {sqlite3Vacuum(pParse,0);}
|
||||
cmd ::= VACUUM nm(X). {sqlite3Vacuum(pParse,&X);}
|
||||
cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
|
||||
cmd ::= VACUUM nm(X). {sqliteVacuum(pParse,&X);}
|
||||
|
||||
///////////////////////////// The PRAGMA command /////////////////////////////
|
||||
//
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z) EQ nm(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z) EQ ON(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z) EQ plus_num(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z) EQ minus_num(Y). {
|
||||
sqlite3Pragma(pParse,&X,&Z,&Y,1);
|
||||
}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z) LP nm(Y) RP. {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z). {sqlite3Pragma(pParse,&X,&Z,0,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ nm(Y). {sqlitePragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlitePragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlitePragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlitePragma(pParse,&X,&Y,1);}
|
||||
cmd ::= PRAGMA ids(X) LP nm(Y) RP. {sqlitePragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X). {sqlitePragma(pParse,&X,&X,0);}
|
||||
plus_num(A) ::= plus_opt number(X). {A = X;}
|
||||
minus_num(A) ::= MINUS number(X). {A = X;}
|
||||
number(A) ::= INTEGER(X). {A = X;}
|
||||
@@ -807,18 +789,17 @@ plus_opt ::= .
|
||||
|
||||
//////////////////////////// The CREATE TRIGGER command /////////////////////
|
||||
|
||||
cmd ::= CREATE trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). {
|
||||
cmd ::= CREATE(A) trigger_decl BEGIN trigger_cmd_list(S) END(Z). {
|
||||
Token all;
|
||||
all.z = A.z;
|
||||
all.n = (Z.z - A.z) + Z.n;
|
||||
sqlite3FinishTrigger(pParse, S, &all);
|
||||
sqliteFinishTrigger(pParse, S, &all);
|
||||
}
|
||||
|
||||
trigger_decl(A) ::= temp(T) TRIGGER nm(B) dbnm(Z) trigger_time(C) trigger_event(D)
|
||||
trigger_decl ::= temp(T) TRIGGER nm(B) trigger_time(C) trigger_event(D)
|
||||
ON nm(E) dbnm(DB) foreach_clause(F) when_clause(G). {
|
||||
SrcList *pTab = sqlite3SrcListAppend(0, &E, &DB);
|
||||
sqlite3BeginTrigger(pParse, &B, &Z, C, D.a, D.b, pTab, F, G, T);
|
||||
A = (Z.n==0?B:Z);
|
||||
SrcList *pTab = sqliteSrcListAppend(0, &E, &DB);
|
||||
sqliteBeginTrigger(pParse, &B, C, D.a, D.b, pTab, F, G, T);
|
||||
}
|
||||
|
||||
%type trigger_time {int}
|
||||
@@ -828,7 +809,7 @@ trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;}
|
||||
trigger_time(A) ::= . { A = TK_BEFORE; }
|
||||
|
||||
%type trigger_event {struct TrigEvent}
|
||||
%destructor trigger_event {sqlite3IdListDelete($$.b);}
|
||||
%destructor trigger_event {sqliteIdListDelete($$.b);}
|
||||
trigger_event(A) ::= DELETE. { A.a = TK_DELETE; A.b = 0; }
|
||||
trigger_event(A) ::= INSERT. { A.a = TK_INSERT; A.b = 0; }
|
||||
trigger_event(A) ::= UPDATE. { A.a = TK_UPDATE; A.b = 0;}
|
||||
@@ -839,79 +820,78 @@ foreach_clause(A) ::= . { A = TK_ROW; }
|
||||
foreach_clause(A) ::= FOR EACH ROW. { A = TK_ROW; }
|
||||
foreach_clause(A) ::= FOR EACH STATEMENT. { A = TK_STATEMENT; }
|
||||
|
||||
%type when_clause {Expr*}
|
||||
%type when_clause {Expr *}
|
||||
when_clause(A) ::= . { A = 0; }
|
||||
when_clause(A) ::= WHEN expr(X). { A = X; }
|
||||
|
||||
%type trigger_cmd_list {TriggerStep*}
|
||||
%destructor trigger_cmd_list {sqlite3DeleteTriggerStep($$);}
|
||||
%type trigger_cmd_list {TriggerStep *}
|
||||
%destructor trigger_cmd_list {sqliteDeleteTriggerStep($$);}
|
||||
trigger_cmd_list(A) ::= trigger_cmd(X) SEMI trigger_cmd_list(Y). {
|
||||
X->pNext = Y;
|
||||
A = X;
|
||||
}
|
||||
trigger_cmd_list(A) ::= . { A = 0; }
|
||||
|
||||
%type trigger_cmd {TriggerStep*}
|
||||
%destructor trigger_cmd {sqlite3DeleteTriggerStep($$);}
|
||||
%type trigger_cmd {TriggerStep *}
|
||||
%destructor trigger_cmd {sqliteDeleteTriggerStep($$);}
|
||||
// UPDATE
|
||||
trigger_cmd(A) ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z).
|
||||
{ A = sqlite3TriggerUpdateStep(&X, Y, Z, R); }
|
||||
{ A = sqliteTriggerUpdateStep(&X, Y, Z, R); }
|
||||
|
||||
// INSERT
|
||||
trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F)
|
||||
VALUES LP itemlist(Y) RP.
|
||||
{A = sqlite3TriggerInsertStep(&X, F, Y, 0, R);}
|
||||
{A = sqliteTriggerInsertStep(&X, F, Y, 0, R);}
|
||||
|
||||
trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S).
|
||||
{A = sqlite3TriggerInsertStep(&X, F, 0, S, R);}
|
||||
{A = sqliteTriggerInsertStep(&X, F, 0, S, R);}
|
||||
|
||||
// DELETE
|
||||
trigger_cmd(A) ::= DELETE FROM nm(X) where_opt(Y).
|
||||
{A = sqlite3TriggerDeleteStep(&X, Y);}
|
||||
{A = sqliteTriggerDeleteStep(&X, Y);}
|
||||
|
||||
// SELECT
|
||||
trigger_cmd(A) ::= select(X). {A = sqlite3TriggerSelectStep(X); }
|
||||
trigger_cmd(A) ::= select(X). {A = sqliteTriggerSelectStep(X); }
|
||||
|
||||
// The special RAISE expression that may occur in trigger programs
|
||||
expr(A) ::= RAISE(X) LP IGNORE RP(Y). {
|
||||
A = sqlite3Expr(TK_RAISE, 0, 0, 0);
|
||||
A = sqliteExpr(TK_RAISE, 0, 0, 0);
|
||||
A->iColumn = OE_Ignore;
|
||||
sqlite3ExprSpan(A, &X, &Y);
|
||||
sqliteExprSpan(A, &X, &Y);
|
||||
}
|
||||
expr(A) ::= RAISE(X) LP ROLLBACK COMMA nm(Z) RP(Y). {
|
||||
A = sqlite3Expr(TK_RAISE, 0, 0, &Z);
|
||||
A = sqliteExpr(TK_RAISE, 0, 0, &Z);
|
||||
A->iColumn = OE_Rollback;
|
||||
sqlite3ExprSpan(A, &X, &Y);
|
||||
sqliteExprSpan(A, &X, &Y);
|
||||
}
|
||||
expr(A) ::= RAISE(X) LP ABORT COMMA nm(Z) RP(Y). {
|
||||
A = sqlite3Expr(TK_RAISE, 0, 0, &Z);
|
||||
A = sqliteExpr(TK_RAISE, 0, 0, &Z);
|
||||
A->iColumn = OE_Abort;
|
||||
sqlite3ExprSpan(A, &X, &Y);
|
||||
sqliteExprSpan(A, &X, &Y);
|
||||
}
|
||||
expr(A) ::= RAISE(X) LP FAIL COMMA nm(Z) RP(Y). {
|
||||
A = sqlite3Expr(TK_RAISE, 0, 0, &Z);
|
||||
A = sqliteExpr(TK_RAISE, 0, 0, &Z);
|
||||
A->iColumn = OE_Fail;
|
||||
sqlite3ExprSpan(A, &X, &Y);
|
||||
sqliteExprSpan(A, &X, &Y);
|
||||
}
|
||||
|
||||
//////////////////////// DROP TRIGGER statement //////////////////////////////
|
||||
cmd ::= DROP TRIGGER nm(X) dbnm(D). {
|
||||
sqlite3DropTrigger(pParse,sqlite3SrcListAppend(0,&X,&D));
|
||||
sqliteDropTrigger(pParse,sqliteSrcListAppend(0,&X,&D));
|
||||
}
|
||||
|
||||
//////////////////////// ATTACH DATABASE file AS name /////////////////////////
|
||||
cmd ::= ATTACH database_kw_opt ids(F) AS nm(D) key_opt(K). {
|
||||
sqlite3Attach(pParse, &F, &D, K.type, &K.key);
|
||||
sqliteAttach(pParse, &F, &D, &K);
|
||||
}
|
||||
%type key_opt {struct AttachKey}
|
||||
key_opt(A) ::= . { A.type = 0; }
|
||||
key_opt(A) ::= KEY ids(X). { A.type=1; A.key = X; }
|
||||
key_opt(A) ::= KEY BLOB(X). { A.type=2; A.key = X; }
|
||||
%type key_opt {Token}
|
||||
key_opt(A) ::= USING ids(X). { A = X; }
|
||||
key_opt(A) ::= . { A.z = 0; A.n = 0; }
|
||||
|
||||
database_kw_opt ::= DATABASE.
|
||||
database_kw_opt ::= .
|
||||
|
||||
//////////////////////// DETACH DATABASE name /////////////////////////////////
|
||||
cmd ::= DETACH database_kw_opt nm(D). {
|
||||
sqlite3Detach(pParse, &D);
|
||||
sqliteDetach(pParse, &D);
|
||||
}
|
||||
|
||||
+421
-465
File diff suppressed because it is too large
Load Diff
+100
-58
@@ -208,8 +208,7 @@ static int vxprintf(
|
||||
etByte flag_alternateform; /* True if "#" flag is present */
|
||||
etByte flag_zeropad; /* True if field width constant starts with zero */
|
||||
etByte flag_long; /* True if "l" flag is present */
|
||||
etByte flag_longlong; /* True if the "ll" flag is present */
|
||||
UINT64_TYPE longvalue; /* Value for integer types */
|
||||
unsigned long longvalue; /* Value for integer types */
|
||||
LONGDOUBLE_TYPE realvalue; /* Value for real types */
|
||||
et_info *infop; /* Pointer to the appropriate info structure */
|
||||
char buf[etBUFSIZE]; /* Conversion buffer */
|
||||
@@ -228,7 +227,6 @@ static int vxprintf(
|
||||
int nsd; /* Number of significant digits returned */
|
||||
#endif
|
||||
|
||||
func(arg,"",0);
|
||||
count = length = 0;
|
||||
bufpt = 0;
|
||||
for(; (c=(*fmt))!=0; ++fmt){
|
||||
@@ -301,14 +299,8 @@ static int vxprintf(
|
||||
if( c=='l' ){
|
||||
flag_long = 1;
|
||||
c = *++fmt;
|
||||
if( c=='l' ){
|
||||
flag_longlong = 1;
|
||||
c = *++fmt;
|
||||
}else{
|
||||
flag_longlong = 0;
|
||||
}
|
||||
}else{
|
||||
flag_long = flag_longlong = 0;
|
||||
flag_long = 0;
|
||||
}
|
||||
/* Fetch the info entry for the field */
|
||||
infop = 0;
|
||||
@@ -334,8 +326,6 @@ static int vxprintf(
|
||||
** flag_zeropad TRUE if the width began with 0.
|
||||
** flag_long TRUE if the letter 'l' (ell) prefixed
|
||||
** the conversion character.
|
||||
** flag_longlong TRUE if the letter 'll' (ell ell) prefixed
|
||||
** the conversion character.
|
||||
** flag_blanksign TRUE if a ' ' is present.
|
||||
** width The specified field width. This is
|
||||
** always non-negative. Zero is the default.
|
||||
@@ -346,27 +336,25 @@ static int vxprintf(
|
||||
*/
|
||||
switch( xtype ){
|
||||
case etRADIX:
|
||||
if( infop->flags & FLAG_SIGNED ){
|
||||
i64 v;
|
||||
if( flag_longlong ) v = va_arg(ap,i64);
|
||||
else if( flag_long ) v = va_arg(ap,long int);
|
||||
else v = va_arg(ap,int);
|
||||
if( v<0 ){
|
||||
longvalue = -v;
|
||||
prefix = '-';
|
||||
}else{
|
||||
longvalue = v;
|
||||
if( flag_plussign ) prefix = '+';
|
||||
else if( flag_blanksign ) prefix = ' ';
|
||||
else prefix = 0;
|
||||
}
|
||||
}else{
|
||||
if( flag_longlong ) longvalue = va_arg(ap,u64);
|
||||
else if( flag_long ) longvalue = va_arg(ap,unsigned long int);
|
||||
else longvalue = va_arg(ap,unsigned int);
|
||||
prefix = 0;
|
||||
}
|
||||
if( flag_long ) longvalue = va_arg(ap,long);
|
||||
else longvalue = va_arg(ap,int);
|
||||
#if 1
|
||||
/* For the format %#x, the value zero is printed "0" not "0x0".
|
||||
** I think this is stupid. */
|
||||
if( longvalue==0 ) flag_alternateform = 0;
|
||||
#else
|
||||
/* More sensible: turn off the prefix for octal (to prevent "00"),
|
||||
** but leave the prefix for hex. */
|
||||
if( longvalue==0 && infop->base==8 ) flag_alternateform = 0;
|
||||
#endif
|
||||
if( infop->flags & FLAG_SIGNED ){
|
||||
if( *(long*)&longvalue<0 ){
|
||||
longvalue = -*(long*)&longvalue;
|
||||
prefix = '-';
|
||||
}else if( flag_plussign ) prefix = '+';
|
||||
else if( flag_blanksign ) prefix = ' ';
|
||||
else prefix = 0;
|
||||
}else prefix = 0;
|
||||
if( flag_zeropad && precision<width-(prefix!=0) ){
|
||||
precision = width-(prefix!=0);
|
||||
}
|
||||
@@ -685,11 +673,9 @@ static void mout(void *arg, const char *zNewText, int nNewChar){
|
||||
}
|
||||
}
|
||||
}
|
||||
if( pM->zText ){
|
||||
if( nNewChar>0 ){
|
||||
memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
|
||||
pM->nChar += nNewChar;
|
||||
}
|
||||
if( pM->zText && nNewChar>0 ){
|
||||
memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
|
||||
pM->nChar += nNewChar;
|
||||
pM->zText[pM->nChar] = 0;
|
||||
}
|
||||
}
|
||||
@@ -715,9 +701,7 @@ static char *base_vprintf(
|
||||
if( xRealloc ){
|
||||
if( sM.zText==sM.zBase ){
|
||||
sM.zText = xRealloc(0, sM.nChar+1);
|
||||
if( sM.zText ){
|
||||
memcpy(sM.zText, sM.zBase, sM.nChar+1);
|
||||
}
|
||||
memcpy(sM.zText, sM.zBase, sM.nChar+1);
|
||||
}else if( sM.nAlloc>sM.nChar+10 ){
|
||||
sM.zText = xRealloc(sM.zText, sM.nChar+1);
|
||||
}
|
||||
@@ -736,7 +720,7 @@ static void *printf_realloc(void *old, int size){
|
||||
** Print into memory obtained from sqliteMalloc(). Use the internal
|
||||
** %-conversion extensions.
|
||||
*/
|
||||
char *sqlite3VMPrintf(const char *zFormat, va_list ap){
|
||||
char *sqliteVMPrintf(const char *zFormat, va_list ap){
|
||||
char zBase[1000];
|
||||
return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
|
||||
}
|
||||
@@ -745,7 +729,7 @@ char *sqlite3VMPrintf(const char *zFormat, va_list ap){
|
||||
** Print into memory obtained from sqliteMalloc(). Use the internal
|
||||
** %-conversion extensions.
|
||||
*/
|
||||
char *sqlite3MPrintf(const char *zFormat, ...){
|
||||
char *sqliteMPrintf(const char *zFormat, ...){
|
||||
va_list ap;
|
||||
char *z;
|
||||
char zBase[1000];
|
||||
@@ -759,7 +743,7 @@ char *sqlite3MPrintf(const char *zFormat, ...){
|
||||
** Print into memory obtained from malloc(). Do not use the internal
|
||||
** %-conversion extensions. This routine is for use by external users.
|
||||
*/
|
||||
char *sqlite3_mprintf(const char *zFormat, ...){
|
||||
char *sqlite_mprintf(const char *zFormat, ...){
|
||||
va_list ap;
|
||||
char *z;
|
||||
char zBuf[200];
|
||||
@@ -771,21 +755,21 @@ char *sqlite3_mprintf(const char *zFormat, ...){
|
||||
return z;
|
||||
}
|
||||
|
||||
/* This is the varargs version of sqlite3_mprintf.
|
||||
/* This is the varargs version of sqlite_mprintf.
|
||||
*/
|
||||
char *sqlite3_vmprintf(const char *zFormat, va_list ap){
|
||||
char *sqlite_vmprintf(const char *zFormat, va_list ap){
|
||||
char zBuf[200];
|
||||
return base_vprintf((void*(*)(void*,int))realloc, 0,
|
||||
zBuf, sizeof(zBuf), zFormat, ap);
|
||||
}
|
||||
|
||||
/*
|
||||
** sqlite3_snprintf() works like snprintf() except that it ignores the
|
||||
** sqlite_snprintf() works like snprintf() except that it ignores the
|
||||
** current locale settings. This is important for SQLite because we
|
||||
** are not able to use a "," as the decimal point in place of "." as
|
||||
** specified by some locales.
|
||||
*/
|
||||
char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
|
||||
char *sqlite_snprintf(int n, char *zBuf, const char *zFormat, ...){
|
||||
char *z;
|
||||
va_list ap;
|
||||
|
||||
@@ -795,19 +779,77 @@ char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
|
||||
return z;
|
||||
}
|
||||
|
||||
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
|
||||
/*
|
||||
** A version of printf() that understands %lld. Used for debugging.
|
||||
** The printf() built into some versions of windows does not understand %lld
|
||||
** and segfaults if you give it a long long int.
|
||||
** The following four routines implement the varargs versions of the
|
||||
** sqlite_exec() and sqlite_get_table() interfaces. See the sqlite.h
|
||||
** header files for a more detailed description of how these interfaces
|
||||
** work.
|
||||
**
|
||||
** These routines are all just simple wrappers.
|
||||
*/
|
||||
void sqlite3DebugPrintf(const char *zFormat, ...){
|
||||
int sqlite_exec_printf(
|
||||
sqlite *db, /* An open database */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
sqlite_callback xCallback, /* Callback function */
|
||||
void *pArg, /* 1st argument to callback function */
|
||||
char **errmsg, /* Error msg written here */
|
||||
... /* Arguments to the format string. */
|
||||
){
|
||||
va_list ap;
|
||||
char zBuf[500];
|
||||
va_start(ap, zFormat);
|
||||
base_vprintf(0, 0, zBuf, sizeof(zBuf), zFormat, ap);
|
||||
int rc;
|
||||
|
||||
va_start(ap, errmsg);
|
||||
rc = sqlite_exec_vprintf(db, sqlFormat, xCallback, pArg, errmsg, ap);
|
||||
va_end(ap);
|
||||
fprintf(stdout,"%s", zBuf);
|
||||
fflush(stdout);
|
||||
return rc;
|
||||
}
|
||||
int sqlite_exec_vprintf(
|
||||
sqlite *db, /* An open database */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
sqlite_callback xCallback, /* Callback function */
|
||||
void *pArg, /* 1st argument to callback function */
|
||||
char **errmsg, /* Error msg written here */
|
||||
va_list ap /* Arguments to the format string. */
|
||||
){
|
||||
char *zSql;
|
||||
int rc;
|
||||
|
||||
zSql = sqlite_vmprintf(sqlFormat, ap);
|
||||
rc = sqlite_exec(db, zSql, xCallback, pArg, errmsg);
|
||||
free(zSql);
|
||||
return rc;
|
||||
}
|
||||
int sqlite_get_table_printf(
|
||||
sqlite *db, /* An open database */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
char ***resultp, /* Result written to a char *[] that this points to */
|
||||
int *nrow, /* Number of result rows written here */
|
||||
int *ncol, /* Number of result columns written here */
|
||||
char **errmsg, /* Error msg written here */
|
||||
... /* Arguments to the format string */
|
||||
){
|
||||
va_list ap;
|
||||
int rc;
|
||||
|
||||
va_start(ap, errmsg);
|
||||
rc = sqlite_get_table_vprintf(db, sqlFormat, resultp, nrow, ncol, errmsg, ap);
|
||||
va_end(ap);
|
||||
return rc;
|
||||
}
|
||||
int sqlite_get_table_vprintf(
|
||||
sqlite *db, /* An open database */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
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 */
|
||||
va_list ap /* Arguments to the format string */
|
||||
){
|
||||
char *zSql;
|
||||
int rc;
|
||||
|
||||
zSql = sqlite_vmprintf(sqlFormat, ap);
|
||||
rc = sqlite_get_table(db, zSql, resultp, nrow, ncolumn, errmsg);
|
||||
free(zSql);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
+5
-8
@@ -15,7 +15,7 @@
|
||||
** Random numbers are used by some of the database backends in order
|
||||
** to generate random integer keys for tables or random filenames.
|
||||
**
|
||||
** $Id: random.c,v 1.12 2004/05/08 08:23:32 danielk1977 Exp $
|
||||
** $Id: random.c,v 1.11 2004/02/11 09:46:33 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -60,7 +60,7 @@ static int randomByte(){
|
||||
char k[256];
|
||||
prng.j = 0;
|
||||
prng.i = 0;
|
||||
sqlite3OsRandomSeed(k);
|
||||
sqliteOsRandomSeed(k);
|
||||
for(i=0; i<256; i++){
|
||||
prng.s[i] = i;
|
||||
}
|
||||
@@ -87,14 +87,11 @@ static int randomByte(){
|
||||
/*
|
||||
** Return N random bytes.
|
||||
*/
|
||||
void sqlite3Randomness(int N, void *pBuf){
|
||||
void sqliteRandomness(int N, void *pBuf){
|
||||
unsigned char *zBuf = pBuf;
|
||||
sqlite3OsEnterMutex();
|
||||
sqliteOsEnterMutex();
|
||||
while( N-- ){
|
||||
*(zBuf++) = randomByte();
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
sqliteOsLeaveMutex();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+650
-866
File diff suppressed because it is too large
Load Diff
+108
-505
@@ -12,13 +12,12 @@
|
||||
** This file contains code to implement the "sqlite" command line
|
||||
** utility for accessing SQLite databases.
|
||||
**
|
||||
** $Id: shell.c,v 1.113 2004/08/31 23:41:26 drh Exp $
|
||||
** $Id: shell.c,v 1.93 2004/03/17 23:42:13 drh Exp $
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "sqlite3.h"
|
||||
#include "sqlite.h"
|
||||
#include <ctype.h>
|
||||
|
||||
#if !defined(_WIN32) && !defined(WIN32) && !defined(__MACOS__)
|
||||
@@ -57,7 +56,7 @@ extern int isatty();
|
||||
** to this database a static variable so that it can be accessed
|
||||
** by the SIGINT handler to interrupt database processing.
|
||||
*/
|
||||
static sqlite3 *db = 0;
|
||||
static sqlite *db = 0;
|
||||
|
||||
/*
|
||||
** True if an interrupt (Control-C) has been received.
|
||||
@@ -81,52 +80,10 @@ static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */
|
||||
/*
|
||||
** Determines if a string is a number of not.
|
||||
*/
|
||||
static int isNumber(const unsigned char *z, int *realnum){
|
||||
if( *z=='-' || *z=='+' ) z++;
|
||||
if( !isdigit(*z) ){
|
||||
return 0;
|
||||
}
|
||||
z++;
|
||||
if( realnum ) *realnum = 0;
|
||||
while( isdigit(*z) ){ z++; }
|
||||
if( *z=='.' ){
|
||||
z++;
|
||||
if( !isdigit(*z) ) return 0;
|
||||
while( isdigit(*z) ){ z++; }
|
||||
if( realnum ) *realnum = 1;
|
||||
}
|
||||
if( *z=='e' || *z=='E' ){
|
||||
z++;
|
||||
if( *z=='+' || *z=='-' ) z++;
|
||||
if( !isdigit(*z) ) return 0;
|
||||
while( isdigit(*z) ){ z++; }
|
||||
if( realnum ) *realnum = 1;
|
||||
}
|
||||
return *z==0;
|
||||
}
|
||||
extern int sqliteIsNumber(const char*);
|
||||
|
||||
/*
|
||||
** A global char* and an SQL function to access its current value
|
||||
** from within an SQL statement. This program used to use the
|
||||
** sqlite_exec_printf() API to substitue a string into an SQL statement.
|
||||
** The correct way to do this with sqlite3 is to use the bind API, but
|
||||
** since the shell is built around the callback paradigm it would be a lot
|
||||
** of work. Instead just use this hack, which is quite harmless.
|
||||
*/
|
||||
static const char *zShellStatic = 0;
|
||||
static void shellstaticFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
assert( 0==argc );
|
||||
assert( zShellStatic );
|
||||
sqlite3_result_text(context, zShellStatic, -1, SQLITE_STATIC);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This routine reads a line of text from FILE in, stores
|
||||
** This routine reads a line of text from standard input, stores
|
||||
** the text in memory obtained from malloc() and returns a pointer
|
||||
** to the text. NULL is returned at end of file, or if malloc()
|
||||
** fails.
|
||||
@@ -212,7 +169,7 @@ struct previous_mode_data {
|
||||
** state and mode information.
|
||||
*/
|
||||
struct callback_data {
|
||||
sqlite3 *db; /* The database */
|
||||
sqlite *db; /* The database */
|
||||
int echoOn; /* True to echo input commands */
|
||||
int cnt; /* Number of records displayed so far */
|
||||
FILE *out; /* Write results here */
|
||||
@@ -241,8 +198,7 @@ struct callback_data {
|
||||
#define MODE_Semi 3 /* Same as MODE_List but append ";" to each line */
|
||||
#define MODE_Html 4 /* Generate an XHTML table */
|
||||
#define MODE_Insert 5 /* Generate SQL "insert" statements */
|
||||
#define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
|
||||
#define MODE_NUM_OF 7 /* The number of modes (not a mode itself) */
|
||||
#define MODE_NUM_OF 6 /* The number of modes (not a mode itself) */
|
||||
|
||||
char *modeDescr[MODE_NUM_OF] = {
|
||||
"line",
|
||||
@@ -250,8 +206,7 @@ char *modeDescr[MODE_NUM_OF] = {
|
||||
"list",
|
||||
"semi",
|
||||
"html",
|
||||
"insert",
|
||||
"tcl",
|
||||
"insert"
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -289,34 +244,6 @@ static void output_quoted_string(FILE *out, const char *z){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Output the given string as a quoted according to C or TCL quoting rules.
|
||||
*/
|
||||
static void output_c_string(FILE *out, const char *z){
|
||||
unsigned int c;
|
||||
fputc('"', out);
|
||||
while( (c = *(z++))!=0 ){
|
||||
if( c=='\\' ){
|
||||
fputc(c, out);
|
||||
fputc(c, out);
|
||||
}else if( c=='\t' ){
|
||||
fputc('\\', out);
|
||||
fputc('t', out);
|
||||
}else if( c=='\n' ){
|
||||
fputc('\\', out);
|
||||
fputc('n', out);
|
||||
}else if( c=='\r' ){
|
||||
fputc('\\', out);
|
||||
fputc('r', out);
|
||||
}else if( !isprint(c) ){
|
||||
fprintf(out, "\\%03o", c);
|
||||
}else{
|
||||
fputc(c, out);
|
||||
}
|
||||
}
|
||||
fputc('"', out);
|
||||
}
|
||||
|
||||
/*
|
||||
** Output the given string with characters that are special to
|
||||
** HTML escaped.
|
||||
@@ -344,7 +271,7 @@ static void output_html_string(FILE *out, const char *z){
|
||||
*/
|
||||
static void interrupt_handler(int NotUsed){
|
||||
seenInterrupt = 1;
|
||||
if( db ) sqlite3_interrupt(db);
|
||||
if( db ) sqlite_interrupt(db);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -458,22 +385,6 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
fprintf(p->out,"</TR>\n");
|
||||
break;
|
||||
}
|
||||
case MODE_Tcl: {
|
||||
if( p->cnt++==0 && p->showHeader ){
|
||||
for(i=0; i<nArg; i++){
|
||||
output_c_string(p->out,azCol[i]);
|
||||
fprintf(p->out, "%s", p->separator);
|
||||
}
|
||||
fprintf(p->out,"\n");
|
||||
}
|
||||
if( azArg==0 ) break;
|
||||
for(i=0; i<nArg; i++){
|
||||
output_c_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
|
||||
fprintf(p->out, "%s", p->separator);
|
||||
}
|
||||
fprintf(p->out,"\n");
|
||||
break;
|
||||
}
|
||||
case MODE_Insert: {
|
||||
if( azArg==0 ) break;
|
||||
fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
|
||||
@@ -481,7 +392,7 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
char *zSep = i>0 ? ",": "";
|
||||
if( azArg[i]==0 ){
|
||||
fprintf(p->out,"%sNULL",zSep);
|
||||
}else if( isNumber(azArg[i], 0) ){
|
||||
}else if( sqliteIsNumber(azArg[i]) ){
|
||||
fprintf(p->out,"%s%s",zSep, azArg[i]);
|
||||
}else{
|
||||
if( zSep[0] ) fprintf(p->out,"%s",zSep);
|
||||
@@ -510,9 +421,9 @@ static void set_table_name(struct callback_data *p, const char *zName){
|
||||
p->zDestTable = 0;
|
||||
}
|
||||
if( zName==0 ) return;
|
||||
needQuote = !isalpha((unsigned char)*zName) && *zName!='_';
|
||||
needQuote = !isalpha(*zName) && *zName!='_';
|
||||
for(i=n=0; zName[i]; i++, n++){
|
||||
if( !isalnum((unsigned char)zName[i]) && zName[i]!='_' ){
|
||||
if( !isalnum(zName[i]) && zName[i]!='_' ){
|
||||
needQuote = 1;
|
||||
if( zName[i]=='\'' ) n++;
|
||||
}
|
||||
@@ -533,72 +444,6 @@ static void set_table_name(struct callback_data *p, const char *zName){
|
||||
z[n] = 0;
|
||||
}
|
||||
|
||||
/* zIn is either a pointer to a NULL-terminated string in memory obtained
|
||||
** from malloc(), or a NULL pointer. The string pointed to by zAppend is
|
||||
** added to zIn, and the result returned in memory obtained from malloc().
|
||||
** zIn, if it was not NULL, is freed.
|
||||
**
|
||||
** If the third argument, quote, is not '\0', then it is used as a
|
||||
** quote character for zAppend.
|
||||
*/
|
||||
static char * appendText(char *zIn, char const *zAppend, char quote){
|
||||
int len;
|
||||
int i;
|
||||
int nAppend = strlen(zAppend);
|
||||
int nIn = (zIn?strlen(zIn):0);
|
||||
|
||||
len = nAppend+nIn+1;
|
||||
if( quote ){
|
||||
len += 2;
|
||||
for(i=0; i<nAppend; i++){
|
||||
if( zAppend[i]==quote ) len++;
|
||||
}
|
||||
}
|
||||
|
||||
zIn = (char *)realloc(zIn, len);
|
||||
if( !zIn ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( quote ){
|
||||
char *zCsr = &zIn[nIn];
|
||||
*zCsr++ = quote;
|
||||
for(i=0; i<nAppend; i++){
|
||||
*zCsr++ = zAppend[i];
|
||||
if( zAppend[i]==quote ) *zCsr++ = quote;
|
||||
}
|
||||
*zCsr++ = quote;
|
||||
*zCsr++ = '\0';
|
||||
assert( (zCsr-zIn)==len );
|
||||
}else{
|
||||
memcpy(&zIn[nIn], zAppend, nAppend);
|
||||
zIn[len-1] = '\0';
|
||||
}
|
||||
|
||||
return zIn;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Execute a query statement that has a single result column. Print
|
||||
** that result column on a line by itself with a semicolon terminator.
|
||||
*/
|
||||
static int run_table_dump_query(FILE *out, sqlite3 *db, const char *zSelect){
|
||||
sqlite3_stmt *pSelect;
|
||||
int rc;
|
||||
rc = sqlite3_prepare(db, zSelect, -1, &pSelect, 0);
|
||||
if( rc!=SQLITE_OK || !pSelect ){
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3_step(pSelect);
|
||||
while( rc==SQLITE_ROW ){
|
||||
fprintf(out, "%s;\n", sqlite3_column_text(pSelect, 0));
|
||||
rc = sqlite3_step(pSelect);
|
||||
}
|
||||
return sqlite3_finalize(pSelect);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This is a different callback routine used for dumping the database.
|
||||
** Each row received by this callback consists of a table name,
|
||||
@@ -606,121 +451,40 @@ static int run_table_dump_query(FILE *out, sqlite3 *db, const char *zSelect){
|
||||
** This routine should print text sufficient to recreate the table.
|
||||
*/
|
||||
static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
int rc;
|
||||
const char *zTable;
|
||||
const char *zType;
|
||||
const char *zSql;
|
||||
struct callback_data *p = (struct callback_data *)pArg;
|
||||
|
||||
if( nArg!=3 ) return 1;
|
||||
zTable = azArg[0];
|
||||
zType = azArg[1];
|
||||
zSql = azArg[2];
|
||||
|
||||
fprintf(p->out, "%s;\n", zSql);
|
||||
|
||||
if( strcmp(zType, "table")==0 ){
|
||||
sqlite3_stmt *pTableInfo = 0;
|
||||
char *zSelect = 0;
|
||||
char *zTableInfo = 0;
|
||||
char *zTmp = 0;
|
||||
|
||||
zTableInfo = appendText(zTableInfo, "PRAGMA table_info(", 0);
|
||||
zTableInfo = appendText(zTableInfo, zTable, '"');
|
||||
zTableInfo = appendText(zTableInfo, ");", 0);
|
||||
|
||||
rc = sqlite3_prepare(p->db, zTableInfo, -1, &pTableInfo, 0);
|
||||
if( zTableInfo ) free(zTableInfo);
|
||||
if( rc!=SQLITE_OK || !pTableInfo ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
zSelect = appendText(zSelect, "SELECT 'INSERT INTO ' || ", 0);
|
||||
zTmp = appendText(zTmp, zTable, '"');
|
||||
if( zTmp ){
|
||||
zSelect = appendText(zSelect, zTmp, '\'');
|
||||
}
|
||||
zSelect = appendText(zSelect, " || ' VALUES(' || ", 0);
|
||||
rc = sqlite3_step(pTableInfo);
|
||||
while( rc==SQLITE_ROW ){
|
||||
zSelect = appendText(zSelect, "quote(", 0);
|
||||
zSelect = appendText(zSelect, sqlite3_column_text(pTableInfo, 1), '"');
|
||||
rc = sqlite3_step(pTableInfo);
|
||||
if( rc==SQLITE_ROW ){
|
||||
zSelect = appendText(zSelect, ") || ', ' || ", 0);
|
||||
}else{
|
||||
zSelect = appendText(zSelect, ") ", 0);
|
||||
}
|
||||
}
|
||||
rc = sqlite3_finalize(pTableInfo);
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( zSelect ) free(zSelect);
|
||||
return 1;
|
||||
}
|
||||
zSelect = appendText(zSelect, "|| ')' FROM ", 0);
|
||||
zSelect = appendText(zSelect, zTable, '"');
|
||||
|
||||
rc = run_table_dump_query(p->out, p->db, zSelect);
|
||||
if( rc==SQLITE_CORRUPT ){
|
||||
zSelect = appendText(zSelect, " ORDER BY rowid DESC", 0);
|
||||
rc = run_table_dump_query(p->out, p->db, zSelect);
|
||||
}
|
||||
if( zSelect ) free(zSelect);
|
||||
if( rc!=SQLITE_OK ){
|
||||
return 1;
|
||||
}
|
||||
fprintf(p->out, "%s;\n", azArg[2]);
|
||||
if( strcmp(azArg[1],"table")==0 ){
|
||||
struct callback_data d2;
|
||||
d2 = *p;
|
||||
d2.mode = MODE_Insert;
|
||||
d2.zDestTable = 0;
|
||||
set_table_name(&d2, azArg[0]);
|
||||
sqlite_exec_printf(p->db,
|
||||
"SELECT * FROM '%q'",
|
||||
callback, &d2, 0, azArg[0]
|
||||
);
|
||||
set_table_name(&d2, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Run zQuery. Update dump_callback() as the callback routine.
|
||||
** If we get a SQLITE_CORRUPT error, rerun the query after appending
|
||||
** "ORDER BY rowid DESC" to the end.
|
||||
*/
|
||||
static int run_schema_dump_query(
|
||||
struct callback_data *p,
|
||||
const char *zQuery,
|
||||
char **pzErrMsg
|
||||
){
|
||||
int rc;
|
||||
rc = sqlite3_exec(p->db, zQuery, dump_callback, p, pzErrMsg);
|
||||
if( rc==SQLITE_CORRUPT ){
|
||||
char *zQ2;
|
||||
int len = strlen(zQuery);
|
||||
if( pzErrMsg ) sqlite3_free(*pzErrMsg);
|
||||
zQ2 = malloc( len+100 );
|
||||
if( zQ2==0 ) return rc;
|
||||
sprintf(zQ2, "%s ORDER BY rowid DESC", zQuery);
|
||||
rc = sqlite3_exec(p->db, zQ2, dump_callback, p, pzErrMsg);
|
||||
free(zQ2);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Text of a help message
|
||||
*/
|
||||
static char zHelp[] =
|
||||
".databases List names and files of attached databases\n"
|
||||
".dump ?TABLE? ... Dump the database in an SQL text format\n"
|
||||
".dump ?TABLE? ... Dump the database in a text format\n"
|
||||
".echo ON|OFF Turn command echo on or off\n"
|
||||
".exit Exit this program\n"
|
||||
".explain ON|OFF Turn output mode suitable for EXPLAIN on or off.\n"
|
||||
".header(s) ON|OFF Turn display of headers on or off\n"
|
||||
".help Show this message\n"
|
||||
".import FILE TABLE Import data from FILE into TABLE\n"
|
||||
".indices TABLE Show names of all indices on TABLE\n"
|
||||
".mode MODE ?TABLE? Set output mode where MODE is on of:\n"
|
||||
" cvs Comma-separated values\n"
|
||||
" column Left-aligned columns. (See .width)\n"
|
||||
" html HTML <table> code\n"
|
||||
" insert SQL insert statements for TABLE\n"
|
||||
" line One value per line\n"
|
||||
" list Values delimited by .separator string\n"
|
||||
" tabs Tab-separated values\n"
|
||||
" tcl TCL list elements\n"
|
||||
".nullvalue STRING Print STRING in place of NULL values\n"
|
||||
".mode MODE Set mode to one of \"line(s)\", \"column(s)\", \n"
|
||||
" \"insert\", \"list\", or \"html\"\n"
|
||||
".mode insert TABLE Generate SQL insert statements for TABLE\n"
|
||||
".nullvalue STRING Print STRING instead of nothing for NULL data\n"
|
||||
".output FILENAME Send output to FILENAME\n"
|
||||
".output stdout Send output to the screen\n"
|
||||
".prompt MAIN CONTINUE Replace the standard prompts\n"
|
||||
@@ -730,9 +494,9 @@ static char zHelp[] =
|
||||
".rekey OLD NEW NEW Change the encryption key\n"
|
||||
#endif
|
||||
".schema ?TABLE? Show the CREATE statements\n"
|
||||
".separator STRING Change separator used by output mode and .import\n"
|
||||
".separator STRING Change separator string for \"list\" mode\n"
|
||||
".show Show the current values for various settings\n"
|
||||
".tables ?PATTERN? List names of tables matching a LIKE pattern\n"
|
||||
".tables ?PATTERN? List names of tables matching a pattern\n"
|
||||
".timeout MS Try opening locked tables for MS milliseconds\n"
|
||||
".width NUM NUM ... Set column widths for \"column\" mode\n"
|
||||
;
|
||||
@@ -746,58 +510,25 @@ static void process_input(struct callback_data *p, FILE *in);
|
||||
*/
|
||||
static void open_db(struct callback_data *p){
|
||||
if( p->db==0 ){
|
||||
sqlite3_open(p->zDbFilename, &p->db);
|
||||
db = p->db;
|
||||
char *zErrMsg = 0;
|
||||
#ifdef SQLITE_HAS_CODEC
|
||||
sqlite3_key(p->db, p->zKey, p->zKey ? strlen(p->zKey) : 0);
|
||||
int n = p->zKey ? strlen(p->zKey) : 0;
|
||||
db = p->db = sqlite_open_encrypted(p->zDbFilename, p->zKey, n, 0, &zErrMsg);
|
||||
#else
|
||||
db = p->db = sqlite_open(p->zDbFilename, 0, &zErrMsg);
|
||||
#endif
|
||||
sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0,
|
||||
shellstaticFunc, 0, 0);
|
||||
if( SQLITE_OK!=sqlite3_errcode(db) ){
|
||||
fprintf(stderr,"Unable to open database \"%s\": %s\n",
|
||||
p->zDbFilename, sqlite3_errmsg(db));
|
||||
if( p->db==0 ){
|
||||
if( zErrMsg ){
|
||||
fprintf(stderr,"Unable to open database \"%s\": %s\n",
|
||||
p->zDbFilename, zErrMsg);
|
||||
}else{
|
||||
fprintf(stderr,"Unable to open database %s\n", p->zDbFilename);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Do C-language style dequoting.
|
||||
**
|
||||
** \t -> tab
|
||||
** \n -> newline
|
||||
** \r -> carriage return
|
||||
** \NNN -> ascii character NNN in octal
|
||||
** \\ -> backslash
|
||||
*/
|
||||
static void resolve_backslashes(char *z){
|
||||
int i, j, c;
|
||||
for(i=j=0; (c = z[i])!=0; i++, j++){
|
||||
if( c=='\\' ){
|
||||
c = z[++i];
|
||||
if( c=='n' ){
|
||||
c = '\n';
|
||||
}else if( c=='t' ){
|
||||
c = '\t';
|
||||
}else if( c=='r' ){
|
||||
c = '\r';
|
||||
}else if( c>='0' && c<='7' ){
|
||||
c =- '0';
|
||||
if( z[i+1]>='0' && z[i+1]<='7' ){
|
||||
i++;
|
||||
c = (c<<3) + z[i] - '0';
|
||||
if( z[i+1]>='0' && z[i+1]<='7' ){
|
||||
i++;
|
||||
c = (c<<3) + z[i] - '0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
z[j] = c;
|
||||
}
|
||||
z[j] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** If an input line begins with "." then invoke this routine to
|
||||
** process that line.
|
||||
@@ -814,7 +545,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
/* Parse the input line into tokens.
|
||||
*/
|
||||
while( zLine[i] && nArg<ArraySize(azArg) ){
|
||||
while( isspace((unsigned char)zLine[i]) ){ i++; }
|
||||
while( isspace(zLine[i]) ){ i++; }
|
||||
if( zLine[i]==0 ) break;
|
||||
if( zLine[i]=='\'' || zLine[i]=='"' ){
|
||||
int delim = zLine[i++];
|
||||
@@ -823,12 +554,10 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
if( zLine[i]==delim ){
|
||||
zLine[i++] = 0;
|
||||
}
|
||||
if( delim=='"' ) resolve_backslashes(azArg[nArg-1]);
|
||||
}else{
|
||||
azArg[nArg++] = &zLine[i];
|
||||
while( zLine[i] && !isspace((unsigned char)zLine[i]) ){ i++; }
|
||||
while( zLine[i] && !isspace(zLine[i]) ){ i++; }
|
||||
if( zLine[i] ) zLine[i++] = 0;
|
||||
resolve_backslashes(azArg[nArg-1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -847,10 +576,10 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
data.colWidth[0] = 3;
|
||||
data.colWidth[1] = 15;
|
||||
data.colWidth[2] = 58;
|
||||
sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
|
||||
sqlite_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
|
||||
if( zErrMsg ){
|
||||
fprintf(stderr,"Error: %s\n", zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
sqlite_freemem(zErrMsg);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -859,32 +588,26 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
open_db(p);
|
||||
fprintf(p->out, "BEGIN TRANSACTION;\n");
|
||||
if( nArg==1 ){
|
||||
run_schema_dump_query(p,
|
||||
sqlite_exec(p->db,
|
||||
"SELECT name, type, sql FROM sqlite_master "
|
||||
"WHERE sql NOT NULL AND type=='table'", 0
|
||||
);
|
||||
run_schema_dump_query(p,
|
||||
"SELECT name, type, sql FROM sqlite_master "
|
||||
"WHERE sql NOT NULL AND type!='table' AND type!='meta'", 0
|
||||
"WHERE type!='meta' AND sql NOT NULL "
|
||||
"ORDER BY substr(type,2,1), name",
|
||||
dump_callback, p, &zErrMsg
|
||||
);
|
||||
}else{
|
||||
int i;
|
||||
for(i=1; i<nArg; i++){
|
||||
zShellStatic = azArg[i];
|
||||
run_schema_dump_query(p,
|
||||
for(i=1; i<nArg && zErrMsg==0; i++){
|
||||
sqlite_exec_printf(p->db,
|
||||
"SELECT name, type, sql FROM sqlite_master "
|
||||
"WHERE tbl_name LIKE shellstatic() AND type=='table'"
|
||||
" AND sql NOT NULL", 0);
|
||||
run_schema_dump_query(p,
|
||||
"SELECT name, type, sql FROM sqlite_master "
|
||||
"WHERE tbl_name LIKE shellstatic() AND type!='table'"
|
||||
" AND type!='meta' AND sql NOT NULL", 0);
|
||||
zShellStatic = 0;
|
||||
"WHERE tbl_name LIKE '%q' AND type!='meta' AND sql NOT NULL "
|
||||
"ORDER BY substr(type,2,1), name",
|
||||
dump_callback, p, &zErrMsg, azArg[i]
|
||||
);
|
||||
}
|
||||
}
|
||||
if( zErrMsg ){
|
||||
fprintf(stderr,"Error: %s\n", zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
sqlite_freemem(zErrMsg);
|
||||
}else{
|
||||
fprintf(p->out, "COMMIT;\n");
|
||||
}
|
||||
@@ -895,7 +618,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
char *z = azArg[1];
|
||||
int val = atoi(azArg[1]);
|
||||
for(j=0; z[j]; j++){
|
||||
z[j] = tolower((unsigned char)z[j]);
|
||||
if( isupper(z[j]) ) z[j] = tolower(z[j]);
|
||||
}
|
||||
if( strcmp(z,"on")==0 ){
|
||||
val = 1;
|
||||
@@ -911,11 +634,10 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
|
||||
if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
|
||||
int j;
|
||||
static char zOne[] = "1";
|
||||
char *z = nArg>=2 ? azArg[1] : zOne;
|
||||
char *z = nArg>=2 ? azArg[1] : "1";
|
||||
int val = atoi(z);
|
||||
for(j=0; z[j]; j++){
|
||||
z[j] = tolower((unsigned char)z[j]);
|
||||
if( isupper(z[j]) ) z[j] = tolower(z[j]);
|
||||
}
|
||||
if( strcmp(z,"on")==0 ){
|
||||
val = 1;
|
||||
@@ -959,7 +681,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
char *z = azArg[1];
|
||||
int val = atoi(azArg[1]);
|
||||
for(j=0; z[j]; j++){
|
||||
z[j] = tolower((unsigned char)z[j]);
|
||||
if( isupper(z[j]) ) z[j] = tolower(z[j]);
|
||||
}
|
||||
if( strcmp(z,"on")==0 ){
|
||||
val = 1;
|
||||
@@ -973,106 +695,6 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
fprintf(stderr,zHelp);
|
||||
}else
|
||||
|
||||
if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg>=3 ){
|
||||
char *zTable = azArg[2]; /* Insert data into this table */
|
||||
char *zFile = azArg[1]; /* The file from which to extract data */
|
||||
sqlite3_stmt *pStmt; /* A statement */
|
||||
int rc; /* Result code */
|
||||
int nCol; /* Number of columns in the table */
|
||||
int nByte; /* Number of bytes in an SQL string */
|
||||
int i, j; /* Loop counters */
|
||||
int nSep; /* Number of bytes in p->separator[] */
|
||||
char *zSql; /* An SQL statement */
|
||||
char *zLine; /* A single line of input from the file */
|
||||
char **azCol; /* zLine[] broken up into columns */
|
||||
char *zCommit; /* How to commit changes */
|
||||
FILE *in; /* The input file */
|
||||
int lineno = 0; /* Line number of input file */
|
||||
|
||||
nSep = strlen(p->separator);
|
||||
if( nSep==0 ){
|
||||
fprintf(stderr, "non-null separator required for import\n");
|
||||
return 0;
|
||||
}
|
||||
zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable);
|
||||
if( zSql==0 ) return 0;
|
||||
nByte = strlen(zSql);
|
||||
rc = sqlite3_prepare(p->db, zSql, 0, &pStmt, 0);
|
||||
sqlite3_free(zSql);
|
||||
if( rc ){
|
||||
fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
|
||||
nCol = 0;
|
||||
}else{
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
}
|
||||
sqlite3_finalize(pStmt);
|
||||
if( nCol==0 ) return 0;
|
||||
zSql = malloc( nByte + 20 + nCol*2 );
|
||||
if( zSql==0 ) return 0;
|
||||
sqlite3_snprintf(nByte+20, zSql, "INSERT INTO '%q' VALUES(?", zTable);
|
||||
j = strlen(zSql);
|
||||
for(i=1; i<nCol; i++){
|
||||
zSql[j++] = ',';
|
||||
zSql[j++] = '?';
|
||||
}
|
||||
zSql[j++] = ')';
|
||||
zSql[j] = 0;
|
||||
rc = sqlite3_prepare(p->db, zSql, 0, &pStmt, 0);
|
||||
free(zSql);
|
||||
if( rc ){
|
||||
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(pStmt);
|
||||
return 0;
|
||||
}
|
||||
in = fopen(zFile, "rb");
|
||||
if( in==0 ){
|
||||
fprintf(stderr, "cannot open file: %s\n", zFile);
|
||||
sqlite3_finalize(pStmt);
|
||||
return 0;
|
||||
}
|
||||
azCol = malloc( sizeof(azCol[0])*(nCol+1) );
|
||||
if( azCol==0 ) return 0;
|
||||
sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
|
||||
zCommit = "COMMIT";
|
||||
while( (zLine = local_getline(0, in))!=0 ){
|
||||
char *z;
|
||||
i = 0;
|
||||
lineno++;
|
||||
azCol[0] = zLine;
|
||||
for(i=0, z=zLine; *z; z++){
|
||||
if( *z==p->separator[0] && strncmp(z, p->separator, nSep)==0 ){
|
||||
*z = 0;
|
||||
i++;
|
||||
if( i<nCol ){
|
||||
azCol[i] = &z[nSep];
|
||||
z += nSep-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( i+1!=nCol ){
|
||||
fprintf(stderr,"%s line %d: expected %d columns of data but found %d\n",
|
||||
zFile, lineno, nCol, i+1);
|
||||
zCommit = "ROLLBACK";
|
||||
break;
|
||||
}
|
||||
for(i=0; i<nCol; i++){
|
||||
sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
|
||||
}
|
||||
sqlite3_step(pStmt);
|
||||
rc = sqlite3_reset(pStmt);
|
||||
free(zLine);
|
||||
if( rc!=SQLITE_OK ){
|
||||
fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
|
||||
zCommit = "ROLLBACK";
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(azCol);
|
||||
fclose(in);
|
||||
sqlite3_finalize(pStmt);
|
||||
sqlite3_exec(p->db, zCommit, 0, 0, 0);
|
||||
}else
|
||||
|
||||
if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg>1 ){
|
||||
struct callback_data data;
|
||||
char *zErrMsg = 0;
|
||||
@@ -1080,20 +702,18 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
memcpy(&data, p, sizeof(data));
|
||||
data.showHeader = 0;
|
||||
data.mode = MODE_List;
|
||||
zShellStatic = azArg[1];
|
||||
sqlite3_exec(p->db,
|
||||
sqlite_exec_printf(p->db,
|
||||
"SELECT name FROM sqlite_master "
|
||||
"WHERE type='index' AND tbl_name LIKE shellstatic() "
|
||||
"WHERE type='index' AND tbl_name LIKE '%q' "
|
||||
"UNION ALL "
|
||||
"SELECT name FROM sqlite_temp_master "
|
||||
"WHERE type='index' AND tbl_name LIKE shellstatic() "
|
||||
"WHERE type='index' AND tbl_name LIKE '%q' "
|
||||
"ORDER BY 1",
|
||||
callback, &data, &zErrMsg
|
||||
callback, &data, &zErrMsg, azArg[1], azArg[1]
|
||||
);
|
||||
zShellStatic = 0;
|
||||
if( zErrMsg ){
|
||||
fprintf(stderr,"Error: %s\n", zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
sqlite_freemem(zErrMsg);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -1111,14 +731,6 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
p->mode = MODE_List;
|
||||
}else if( strncmp(azArg[1],"html",n2)==0 ){
|
||||
p->mode = MODE_Html;
|
||||
}else if( strncmp(azArg[1],"tcl",n2)==0 ){
|
||||
p->mode = MODE_Tcl;
|
||||
}else if( strncmp(azArg[1],"csv",n2)==0 ){
|
||||
p->mode = MODE_List;
|
||||
strcpy(p->separator, ",");
|
||||
}else if( strncmp(azArg[1],"tabs",n2)==0 ){
|
||||
p->mode = MODE_List;
|
||||
strcpy(p->separator, "\t");
|
||||
}else if( strncmp(azArg[1],"insert",n2)==0 ){
|
||||
p->mode = MODE_Insert;
|
||||
if( nArg>=3 ){
|
||||
@@ -1127,8 +739,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
set_table_name(p, "table");
|
||||
}
|
||||
}else {
|
||||
fprintf(stderr,"mode should be on of: "
|
||||
"column csv html insert line list tabs tcl\n");
|
||||
fprintf(stderr,"mode should be on of: column html insert line list\n");
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -1186,9 +797,9 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
}else if( strcmp(azArg[2], azArg[3]) ){
|
||||
fprintf(stderr,"2nd copy of new key does not match the 1st\n");
|
||||
}else{
|
||||
sqlite3_free(p->zKey);
|
||||
p->zKey = sqlite3_mprintf("%s", azArg[2]);
|
||||
sqlite3_rekey(p->db, p->zKey, strlen(p->zKey));
|
||||
sqlite_freemem(p->zKey);
|
||||
p->zKey = sqlite_mprintf("%s", azArg[2]);
|
||||
sqlite_rekey(p->db, p->zKey, strlen(p->zKey));
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
@@ -1201,9 +812,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
data.showHeader = 0;
|
||||
data.mode = MODE_Semi;
|
||||
if( nArg>1 ){
|
||||
int i;
|
||||
for(i=0; azArg[1][i]; i++) azArg[1][i] = tolower(azArg[1][i]);
|
||||
if( strcmp(azArg[1],"sqlite_master")==0 ){
|
||||
extern int sqliteStrICmp(const char*,const char*);
|
||||
if( sqliteStrICmp(azArg[1],"sqlite_master")==0 ){
|
||||
char *new_argv[2], *new_colv[2];
|
||||
new_argv[0] = "CREATE TABLE sqlite_master (\n"
|
||||
" type text,\n"
|
||||
@@ -1216,7 +826,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
new_colv[0] = "sql";
|
||||
new_colv[1] = 0;
|
||||
callback(&data, 1, new_argv, new_colv);
|
||||
}else if( strcmp(azArg[1],"sqlite_temp_master")==0 ){
|
||||
}else if( sqliteStrICmp(azArg[1],"sqlite_temp_master")==0 ){
|
||||
char *new_argv[2], *new_colv[2];
|
||||
new_argv[0] = "CREATE TEMP TABLE sqlite_temp_master (\n"
|
||||
" type text,\n"
|
||||
@@ -1230,18 +840,16 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
new_colv[1] = 0;
|
||||
callback(&data, 1, new_argv, new_colv);
|
||||
}else{
|
||||
zShellStatic = azArg[1];
|
||||
sqlite3_exec(p->db,
|
||||
sqlite_exec_printf(p->db,
|
||||
"SELECT sql FROM "
|
||||
" (SELECT * FROM sqlite_master UNION ALL"
|
||||
" SELECT * FROM sqlite_temp_master) "
|
||||
"WHERE tbl_name LIKE shellstatic() AND type!='meta' AND sql NOTNULL "
|
||||
"WHERE tbl_name LIKE '%q' AND type!='meta' AND sql NOTNULL "
|
||||
"ORDER BY substr(type,2,1), name",
|
||||
callback, &data, &zErrMsg);
|
||||
zShellStatic = 0;
|
||||
callback, &data, &zErrMsg, azArg[1]);
|
||||
}
|
||||
}else{
|
||||
sqlite3_exec(p->db,
|
||||
sqlite_exec(p->db,
|
||||
"SELECT sql FROM "
|
||||
" (SELECT * FROM sqlite_master UNION ALL"
|
||||
" SELECT * FROM sqlite_temp_master) "
|
||||
@@ -1252,7 +860,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
}
|
||||
if( zErrMsg ){
|
||||
fprintf(stderr,"Error: %s\n", zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
sqlite_freemem(zErrMsg);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -1266,19 +874,15 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
|
||||
fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
|
||||
fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
|
||||
fprintf(p->out,"%9.9s: ", "nullvalue");
|
||||
output_c_string(p->out, p->nullvalue);
|
||||
fprintf(p->out, "\n");
|
||||
fprintf(p->out,"%9.9s: %s\n","nullvalue", p->nullvalue);
|
||||
fprintf(p->out,"%9.9s: %s\n","output",
|
||||
strlen(p->outfile) ? p->outfile : "stdout");
|
||||
fprintf(p->out,"%9.9s: ", "separator");
|
||||
output_c_string(p->out, p->separator);
|
||||
fprintf(p->out, "\n");
|
||||
fprintf(p->out,"%9.9s: %s\n","separator", p->separator);
|
||||
fprintf(p->out,"%9.9s: ","width");
|
||||
for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
|
||||
fprintf(p->out,"%d ",p->colWidth[i]);
|
||||
fprintf(p->out,"%d ",p->colWidth[i]);
|
||||
}
|
||||
fprintf(p->out,"\n");
|
||||
fprintf(p->out,"\n\n");
|
||||
}else
|
||||
|
||||
if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){
|
||||
@@ -1287,7 +891,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
char *zErrMsg;
|
||||
open_db(p);
|
||||
if( nArg==1 ){
|
||||
rc = sqlite3_get_table(p->db,
|
||||
rc = sqlite_get_table(p->db,
|
||||
"SELECT name FROM sqlite_master "
|
||||
"WHERE type IN ('table','view') "
|
||||
"UNION ALL "
|
||||
@@ -1297,21 +901,19 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
&azResult, &nRow, 0, &zErrMsg
|
||||
);
|
||||
}else{
|
||||
zShellStatic = azArg[1];
|
||||
rc = sqlite3_get_table(p->db,
|
||||
rc = sqlite_get_table_printf(p->db,
|
||||
"SELECT name FROM sqlite_master "
|
||||
"WHERE type IN ('table','view') AND name LIKE '%'||shellstatic()||'%' "
|
||||
"WHERE type IN ('table','view') AND name LIKE '%%%q%%' "
|
||||
"UNION ALL "
|
||||
"SELECT name FROM sqlite_temp_master "
|
||||
"WHERE type IN ('table','view') AND name LIKE '%'||shellstatic()||'%' "
|
||||
"WHERE type IN ('table','view') AND name LIKE '%%%q%%' "
|
||||
"ORDER BY 1",
|
||||
&azResult, &nRow, 0, &zErrMsg
|
||||
&azResult, &nRow, 0, &zErrMsg, azArg[1], azArg[1]
|
||||
);
|
||||
zShellStatic = 0;
|
||||
}
|
||||
if( zErrMsg ){
|
||||
fprintf(stderr,"Error: %s\n", zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
sqlite_freemem(zErrMsg);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
int len, maxlen = 0;
|
||||
@@ -1333,12 +935,12 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
sqlite3_free_table(azResult);
|
||||
sqlite_free_table(azResult);
|
||||
}else
|
||||
|
||||
if( c=='t' && n>1 && strncmp(azArg[0], "timeout", n)==0 && nArg>=2 ){
|
||||
open_db(p);
|
||||
sqlite3_busy_timeout(p->db, atoi(azArg[1]));
|
||||
sqlite_busy_timeout(p->db, atoi(azArg[1]));
|
||||
}else
|
||||
|
||||
if( c=='w' && strncmp(azArg[0], "width", n)==0 ){
|
||||
@@ -1361,7 +963,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
** z[] is N characters long.
|
||||
*/
|
||||
static int _ends_with_semicolon(const char *z, int N){
|
||||
while( N>0 && isspace((unsigned char)z[N-1]) ){ N--; }
|
||||
while( N>0 && isspace(z[N-1]) ){ N--; }
|
||||
return N>0 && z[N-1]==';';
|
||||
}
|
||||
|
||||
@@ -1370,7 +972,7 @@ static int _ends_with_semicolon(const char *z, int N){
|
||||
*/
|
||||
static int _all_whitespace(const char *z){
|
||||
for(; *z; z++){
|
||||
if( isspace(*(unsigned char*)z) ) continue;
|
||||
if( isspace(*z) ) continue;
|
||||
if( *z=='/' && z[1]=='*' ){
|
||||
z += 2;
|
||||
while( *z && (*z!='*' || z[1]!='/') ){ z++; }
|
||||
@@ -1395,10 +997,10 @@ static int _all_whitespace(const char *z){
|
||||
** as is the Oracle "/".
|
||||
*/
|
||||
static int _is_command_terminator(const char *zLine){
|
||||
while( isspace(*(unsigned char*)zLine) ){ zLine++; };
|
||||
extern int sqliteStrNICmp(const char*,const char*,int);
|
||||
while( isspace(*zLine) ){ zLine++; };
|
||||
if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ) return 1; /* Oracle */
|
||||
if( tolower(zLine[0])=='g' && tolower(zLine[1])=='o'
|
||||
&& _all_whitespace(&zLine[2]) ){
|
||||
if( sqliteStrNICmp(zLine,"go",2)==0 && _all_whitespace(&zLine[2]) ){
|
||||
return 1; /* SQL Server */
|
||||
}
|
||||
return 0;
|
||||
@@ -1435,7 +1037,7 @@ static void process_input(struct callback_data *p, FILE *in){
|
||||
}
|
||||
if( zSql==0 ){
|
||||
int i;
|
||||
for(i=0; zLine[i] && isspace((unsigned char)zLine[i]); i++){}
|
||||
for(i=0; zLine[i] && isspace(zLine[i]); i++){}
|
||||
if( zLine[i]!=0 ){
|
||||
nSql = strlen(zLine);
|
||||
zSql = malloc( nSql+1 );
|
||||
@@ -1453,18 +1055,18 @@ static void process_input(struct callback_data *p, FILE *in){
|
||||
nSql += len;
|
||||
}
|
||||
free(zLine);
|
||||
if( zSql && _ends_with_semicolon(zSql, nSql) && sqlite3_complete(zSql) ){
|
||||
if( zSql && _ends_with_semicolon(zSql, nSql) && sqlite_complete(zSql) ){
|
||||
p->cnt = 0;
|
||||
open_db(p);
|
||||
rc = sqlite3_exec(p->db, zSql, callback, p, &zErrMsg);
|
||||
rc = sqlite_exec(p->db, zSql, callback, p, &zErrMsg);
|
||||
if( rc || zErrMsg ){
|
||||
if( in!=0 && !p->echoOn ) printf("%s\n",zSql);
|
||||
if( zErrMsg!=0 ){
|
||||
printf("SQL error: %s\n", zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
sqlite_freemem(zErrMsg);
|
||||
zErrMsg = 0;
|
||||
}else{
|
||||
printf("SQL error: %s\n", sqlite3_errmsg(p->db));
|
||||
printf("SQL error: %s\n", sqlite_error_string(rc));
|
||||
}
|
||||
}
|
||||
free(zSql);
|
||||
@@ -1608,6 +1210,7 @@ int main(int argc, char **argv){
|
||||
const char *zInitFile = 0;
|
||||
char *zFirstCmd = 0;
|
||||
int i;
|
||||
extern int sqliteOsFileExists(const char*);
|
||||
|
||||
#ifdef __MACOS__
|
||||
argc = ccommand(&argv);
|
||||
@@ -1636,7 +1239,7 @@ int main(int argc, char **argv){
|
||||
zInitFile = argv[i];
|
||||
}else if( strcmp(argv[i],"-key")==0 ){
|
||||
i++;
|
||||
data.zKey = sqlite3_mprintf("%s",argv[i]);
|
||||
data.zKey = sqlite_mprintf("%s",argv[i]);
|
||||
}
|
||||
}
|
||||
if( i<argc ){
|
||||
@@ -1654,7 +1257,7 @@ int main(int argc, char **argv){
|
||||
** files from being created if a user mistypes the database name argument
|
||||
** to the sqlite command-line tool.
|
||||
*/
|
||||
if( access(data.zDbFilename, 0)==0 ){
|
||||
if( sqliteOsFileExists(data.zDbFilename) ){
|
||||
open_db(&data);
|
||||
}
|
||||
|
||||
@@ -1694,7 +1297,7 @@ int main(int argc, char **argv){
|
||||
}else if( strcmp(z,"-echo")==0 ){
|
||||
data.echoOn = 1;
|
||||
}else if( strcmp(z,"-version")==0 ){
|
||||
printf("%s\n", sqlite3_libversion());
|
||||
printf("%s\n", sqlite_version);
|
||||
return 1;
|
||||
}else if( strcmp(z,"-help")==0 ){
|
||||
usage(1);
|
||||
@@ -1714,7 +1317,7 @@ int main(int argc, char **argv){
|
||||
}else{
|
||||
int rc;
|
||||
open_db(&data);
|
||||
rc = sqlite3_exec(data.db, zFirstCmd, callback, &data, &zErrMsg);
|
||||
rc = sqlite_exec(data.db, zFirstCmd, callback, &data, &zErrMsg);
|
||||
if( rc!=0 && zErrMsg!=0 ){
|
||||
fprintf(stderr,"SQL error: %s\n", zErrMsg);
|
||||
exit(1);
|
||||
@@ -1729,7 +1332,7 @@ int main(int argc, char **argv){
|
||||
printf(
|
||||
"SQLite version %s\n"
|
||||
"Enter \".help\" for instructions\n",
|
||||
sqlite3_libversion()
|
||||
sqlite_version
|
||||
);
|
||||
zHome = find_home_dir();
|
||||
if( zHome && (zHistory = malloc(strlen(zHome)+20))!=0 ){
|
||||
@@ -1746,6 +1349,6 @@ int main(int argc, char **argv){
|
||||
}
|
||||
}
|
||||
set_table_name(&data, 0);
|
||||
if( db ) sqlite3_close(db);
|
||||
if( db ) sqlite_close(db);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+455
-730
File diff suppressed because it is too large
Load Diff
+311
-438
File diff suppressed because it is too large
Load Diff
+31
-24
@@ -9,9 +9,9 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains the sqlite3_get_table() and sqlite3_free_table()
|
||||
** This file contains the sqlite_get_table() and sqlite_free_table()
|
||||
** interface routines. These are just wrappers around the main
|
||||
** interface routine of sqlite3_exec().
|
||||
** interface routine of sqlite_exec().
|
||||
**
|
||||
** These routines are in a separate files so that they will not be linked
|
||||
** if they are not used.
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This structure is used to pass data from sqlite3_get_table() through
|
||||
** This structure is used to pass data from sqlite_get_table() through
|
||||
** to the callback function is uses to build the result.
|
||||
*/
|
||||
typedef struct TabResult {
|
||||
@@ -40,7 +40,7 @@ typedef struct TabResult {
|
||||
** is to fill in the TabResult structure appropriately, allocating new
|
||||
** memory as necessary.
|
||||
*/
|
||||
static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
TabResult *p = (TabResult*)pArg;
|
||||
int need;
|
||||
int i;
|
||||
@@ -58,7 +58,10 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
char **azNew;
|
||||
p->nAlloc = p->nAlloc*2 + need + 1;
|
||||
azNew = realloc( p->azResult, sizeof(char*)*p->nAlloc );
|
||||
if( azNew==0 ) goto malloc_failed;
|
||||
if( azNew==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
p->azResult = azNew;
|
||||
}
|
||||
|
||||
@@ -72,14 +75,17 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
z = 0;
|
||||
}else{
|
||||
z = malloc( strlen(colv[i])+1 );
|
||||
if( z==0 ) goto malloc_failed;
|
||||
if( z==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
strcpy(z, colv[i]);
|
||||
}
|
||||
p->azResult[p->nData++] = z;
|
||||
}
|
||||
}else if( p->nColumn!=nCol ){
|
||||
sqlite3SetString(&p->zErrMsg,
|
||||
"sqlite3_get_table() called with two or more incompatible queries",
|
||||
sqliteSetString(&p->zErrMsg,
|
||||
"sqlite_get_table() called with two or more incompatible queries",
|
||||
(char*)0);
|
||||
p->rc = SQLITE_ERROR;
|
||||
return 1;
|
||||
@@ -93,7 +99,10 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
z = 0;
|
||||
}else{
|
||||
z = malloc( strlen(argv[i])+1 );
|
||||
if( z==0 ) goto malloc_failed;
|
||||
if( z==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
strcpy(z, argv[i]);
|
||||
}
|
||||
p->azResult[p->nData++] = z;
|
||||
@@ -101,10 +110,6 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
p->nRow++;
|
||||
}
|
||||
return 0;
|
||||
|
||||
malloc_failed:
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -114,10 +119,10 @@ malloc_failed:
|
||||
**
|
||||
** The result that is written to ***pazResult is held in memory obtained
|
||||
** from malloc(). But the caller cannot free this memory directly.
|
||||
** Instead, the entire table should be passed to sqlite3_free_table() when
|
||||
** Instead, the entire table should be passed to sqlite_free_table() when
|
||||
** the calling procedure is finished using it.
|
||||
*/
|
||||
int sqlite3_get_table(
|
||||
int sqlite_get_table(
|
||||
sqlite *db, /* The database on which the SQL executes */
|
||||
const char *zSql, /* The SQL to be executed */
|
||||
char ***pazResult, /* Write the result table here */
|
||||
@@ -139,19 +144,21 @@ int sqlite3_get_table(
|
||||
res.nAlloc = 20;
|
||||
res.rc = SQLITE_OK;
|
||||
res.azResult = malloc( sizeof(char*)*res.nAlloc );
|
||||
if( res.azResult==0 ) return SQLITE_NOMEM;
|
||||
if( res.azResult==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
res.azResult[0] = 0;
|
||||
rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
|
||||
rc = sqlite_exec(db, zSql, sqlite_get_table_cb, &res, pzErrMsg);
|
||||
if( res.azResult ){
|
||||
res.azResult[0] = (char*)res.nData;
|
||||
}
|
||||
if( rc==SQLITE_ABORT ){
|
||||
sqlite3_free_table(&res.azResult[1]);
|
||||
sqlite_free_table(&res.azResult[1]);
|
||||
if( res.zErrMsg ){
|
||||
if( pzErrMsg ){
|
||||
free(*pzErrMsg);
|
||||
*pzErrMsg = res.zErrMsg;
|
||||
sqlite3StrRealloc(pzErrMsg);
|
||||
sqliteStrRealloc(pzErrMsg);
|
||||
}else{
|
||||
sqliteFree(res.zErrMsg);
|
||||
}
|
||||
@@ -160,14 +167,14 @@ int sqlite3_get_table(
|
||||
}
|
||||
sqliteFree(res.zErrMsg);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3_free_table(&res.azResult[1]);
|
||||
sqlite_free_table(&res.azResult[1]);
|
||||
return rc;
|
||||
}
|
||||
if( res.nAlloc>res.nData ){
|
||||
char **azNew;
|
||||
azNew = realloc( res.azResult, sizeof(char*)*(res.nData+1) );
|
||||
if( azNew==0 ){
|
||||
sqlite3_free_table(&res.azResult[1]);
|
||||
sqlite_free_table(&res.azResult[1]);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
res.nAlloc = res.nData+1;
|
||||
@@ -180,10 +187,10 @@ int sqlite3_get_table(
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine frees the space the sqlite3_get_table() malloced.
|
||||
** This routine frees the space the sqlite_get_table() malloced.
|
||||
*/
|
||||
void sqlite3_free_table(
|
||||
char **azResult /* Result returned from from sqlite3_get_table() */
|
||||
void sqlite_free_table(
|
||||
char **azResult /* Result returned from from sqlite_get_table() */
|
||||
){
|
||||
if( azResult ){
|
||||
int i, n;
|
||||
|
||||
+365
-461
File diff suppressed because it is too large
Load Diff
+345
-1856
File diff suppressed because it is too large
Load Diff
+43
-42
@@ -13,7 +13,7 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test2.c,v 1.24 2004/07/22 01:19:35 drh Exp $
|
||||
** $Id: test2.c,v 1.16 2004/02/10 01:54:28 drh Exp $
|
||||
*/
|
||||
#include "os.h"
|
||||
#include "sqliteInt.h"
|
||||
@@ -55,11 +55,6 @@ static char *errorName(int rc){
|
||||
return zName;
|
||||
}
|
||||
|
||||
/*
|
||||
** Page size and reserved size used for testing.
|
||||
*/
|
||||
static int test_pagesize = 1024;
|
||||
|
||||
/*
|
||||
** Usage: pager_open FILENAME N-PAGE
|
||||
**
|
||||
@@ -81,13 +76,11 @@ static int pager_open(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_open(&pPager, argv[1], 0, 1);
|
||||
rc = sqlitepager_open(&pPager, argv[1], nPage, 0, 1);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sqlite3pager_set_cachesize(pPager, nPage);
|
||||
sqlite3pager_set_pagesize(pPager, test_pagesize);
|
||||
sprintf(zBuf,"0x%x",(int)pPager);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
@@ -112,7 +105,7 @@ static int pager_close(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_close(pPager);
|
||||
rc = sqlitepager_close(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -139,7 +132,7 @@ static int pager_rollback(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_rollback(pPager);
|
||||
rc = sqlitepager_rollback(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -166,7 +159,7 @@ static int pager_commit(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_commit(pPager);
|
||||
rc = sqlitepager_commit(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -175,11 +168,11 @@ static int pager_commit(
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_stmt_begin ID
|
||||
** Usage: pager_ckpt_begin ID
|
||||
**
|
||||
** Start a new checkpoint.
|
||||
*/
|
||||
static int pager_stmt_begin(
|
||||
static int pager_ckpt_begin(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
@@ -193,7 +186,7 @@ static int pager_stmt_begin(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_stmt_begin(pPager);
|
||||
rc = sqlitepager_ckpt_begin(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -202,11 +195,11 @@ static int pager_stmt_begin(
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_stmt_rollback ID
|
||||
** Usage: pager_ckpt_rollback ID
|
||||
**
|
||||
** Rollback changes to a checkpoint
|
||||
*/
|
||||
static int pager_stmt_rollback(
|
||||
static int pager_ckpt_rollback(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
@@ -220,7 +213,7 @@ static int pager_stmt_rollback(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_stmt_rollback(pPager);
|
||||
rc = sqlitepager_ckpt_rollback(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -229,11 +222,11 @@ static int pager_stmt_rollback(
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_stmt_commit ID
|
||||
** Usage: pager_ckpt_commit ID
|
||||
**
|
||||
** Commit changes to a checkpoint
|
||||
*/
|
||||
static int pager_stmt_commit(
|
||||
static int pager_ckpt_commit(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
@@ -247,7 +240,7 @@ static int pager_stmt_commit(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_stmt_commit(pPager);
|
||||
rc = sqlitepager_ckpt_commit(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -274,7 +267,7 @@ static int pager_stats(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
a = sqlite3pager_stats(pPager);
|
||||
a = sqlitepager_stats(pPager);
|
||||
for(i=0; i<9; i++){
|
||||
static char *zName[] = {
|
||||
"ref", "page", "max", "size", "state", "err",
|
||||
@@ -307,7 +300,7 @@ static int pager_pagecount(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
sprintf(zBuf,"%d",sqlite3pager_pagecount(pPager));
|
||||
sprintf(zBuf,"%d",sqlitepager_pagecount(pPager));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -335,7 +328,7 @@ static int page_get(
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_get(pPager, pgno, &pPage);
|
||||
rc = sqlitepager_get(pPager, pgno, &pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -368,7 +361,7 @@ static int page_lookup(
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
|
||||
pPage = sqlite3pager_lookup(pPager, pgno);
|
||||
pPage = sqlitepager_lookup(pPager, pgno);
|
||||
if( pPage ){
|
||||
sprintf(zBuf,"0x%x",(int)pPage);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
@@ -395,7 +388,7 @@ static int page_unref(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_unref(pPage);
|
||||
rc = sqlitepager_unref(pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -446,7 +439,7 @@ static int page_number(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
sprintf(zBuf, "%d", sqlite3pager_pagenumber(pPage));
|
||||
sprintf(zBuf, "%d", sqlitepager_pagenumber(pPage));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -470,13 +463,13 @@ static int page_write(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_write(pPage);
|
||||
rc = sqlitepager_write(pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
strncpy((char*)pPage, argv[2], test_pagesize-1);
|
||||
((char*)pPage)[test_pagesize-1] = 0;
|
||||
strncpy((char*)pPage, argv[2], SQLITE_USABLE_SIZE-1);
|
||||
((char*)pPage)[SQLITE_USABLE_SIZE-1] = 0;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -506,21 +499,20 @@ static int fake_big_file(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
|
||||
memset(&fd, 0, sizeof(fd));
|
||||
rc = sqlite3OsOpenReadWrite(argv[2], &fd, &readOnly);
|
||||
rc = sqliteOsOpenReadWrite(argv[2], &fd, &readOnly);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "open failed: ", errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
offset = n;
|
||||
offset *= 1024*1024;
|
||||
rc = sqlite3OsSeek(&fd, offset);
|
||||
rc = sqliteOsSeek(&fd, offset);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "seek failed: ", errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqlite3OsWrite(&fd, "Hello, World!", 14);
|
||||
sqlite3OsClose(&fd);
|
||||
rc = sqliteOsWrite(&fd, "Hello, World!", 14);
|
||||
sqliteOsClose(&fd);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "write failed: ", errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -532,7 +524,8 @@ static int fake_big_file(
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
extern int sqlite3_io_error_pending;
|
||||
extern int sqlite_io_error_pending;
|
||||
char zBuf[100];
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_CmdProc *xProc;
|
||||
@@ -541,9 +534,9 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
{ "pager_close", (Tcl_CmdProc*)pager_close },
|
||||
{ "pager_commit", (Tcl_CmdProc*)pager_commit },
|
||||
{ "pager_rollback", (Tcl_CmdProc*)pager_rollback },
|
||||
{ "pager_stmt_begin", (Tcl_CmdProc*)pager_stmt_begin },
|
||||
{ "pager_stmt_commit", (Tcl_CmdProc*)pager_stmt_commit },
|
||||
{ "pager_stmt_rollback", (Tcl_CmdProc*)pager_stmt_rollback },
|
||||
{ "pager_ckpt_begin", (Tcl_CmdProc*)pager_ckpt_begin },
|
||||
{ "pager_ckpt_commit", (Tcl_CmdProc*)pager_ckpt_commit },
|
||||
{ "pager_ckpt_rollback", (Tcl_CmdProc*)pager_ckpt_rollback },
|
||||
{ "pager_stats", (Tcl_CmdProc*)pager_stats },
|
||||
{ "pager_pagecount", (Tcl_CmdProc*)pager_pagecount },
|
||||
{ "page_get", (Tcl_CmdProc*)page_get },
|
||||
@@ -559,8 +552,16 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
||||
}
|
||||
Tcl_LinkVar(interp, "sqlite_io_error_pending",
|
||||
(char*)&sqlite3_io_error_pending, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "pager_pagesize",
|
||||
(char*)&test_pagesize, TCL_LINK_INT);
|
||||
(char*)&sqlite_io_error_pending, TCL_LINK_INT);
|
||||
#ifdef SQLITE_TEST
|
||||
Tcl_LinkVar(interp, "journal_format",
|
||||
(char*)&journal_format, TCL_LINK_INT);
|
||||
#endif
|
||||
sprintf(zBuf, "%d", SQLITE_PAGE_SIZE);
|
||||
Tcl_SetVar(interp, "SQLITE_PAGE_SIZE", zBuf, TCL_GLOBAL_ONLY);
|
||||
sprintf(zBuf, "%d", SQLITE_PAGE_RESERVE);
|
||||
Tcl_SetVar(interp, "SQLITE_PAGE_RESERVE", zBuf, TCL_GLOBAL_ONLY);
|
||||
sprintf(zBuf, "%d", SQLITE_USABLE_SIZE);
|
||||
Tcl_SetVar(interp, "SQLITE_USABLE_SIZE", zBuf, TCL_GLOBAL_ONLY);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
+90
-482
@@ -13,7 +13,7 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test3.c,v 1.50 2004/07/23 00:01:39 drh Exp $
|
||||
** $Id: test3.c,v 1.23 2003/04/13 18:26:52 paul Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "pager.h"
|
||||
@@ -43,14 +43,13 @@ static char *errorName(int rc){
|
||||
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
|
||||
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
|
||||
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
|
||||
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
|
||||
default: zName = "SQLITE_Unknown"; break;
|
||||
}
|
||||
return zName;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_open FILENAME NCACHE FLAGS
|
||||
** Usage: btree_open FILENAME
|
||||
**
|
||||
** Open a new database
|
||||
*/
|
||||
@@ -61,21 +60,18 @@ static int btree_open(
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc, nCache, flags;
|
||||
int rc;
|
||||
char zBuf[100];
|
||||
if( argc!=4 ){
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" FILENAME NCACHE FLAGS\"", 0);
|
||||
" FILENAME\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[3], &flags) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeOpen(argv[1], &pBt, flags);
|
||||
rc = sqliteBtreeFactory(0, argv[1], 0, 1000, &pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sqlite3BtreeSetCacheSize(pBt, nCache);
|
||||
sprintf(zBuf,"%p", pBt);
|
||||
if( strncmp(zBuf,"0x",2) ){
|
||||
sprintf(zBuf, "0x%p", pBt);
|
||||
@@ -103,7 +99,7 @@ static int btree_close(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeClose(pBt);
|
||||
rc = sqliteBtreeClose(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -130,7 +126,7 @@ static int btree_begin_transaction(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeBeginTrans(pBt, 1);
|
||||
rc = sqliteBtreeBeginTrans(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -157,7 +153,7 @@ static int btree_rollback(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeRollback(pBt);
|
||||
rc = sqliteBtreeRollback(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -184,7 +180,7 @@ static int btree_commit(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeCommit(pBt);
|
||||
rc = sqliteBtreeCommit(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -193,88 +189,7 @@ static int btree_commit(
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_begin_statement ID
|
||||
**
|
||||
** Start a new statement transaction
|
||||
*/
|
||||
static int btree_begin_statement(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeBeginStmt(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_rollback_statement ID
|
||||
**
|
||||
** Rollback changes
|
||||
*/
|
||||
static int btree_rollback_statement(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeRollbackStmt(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_commit_statement ID
|
||||
**
|
||||
** Commit all changes
|
||||
*/
|
||||
static int btree_commit_statement(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeCommitStmt(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_create_table ID FLAGS
|
||||
** Usage: btree_create_table ID
|
||||
**
|
||||
** Create a new table in the database
|
||||
*/
|
||||
@@ -285,16 +200,15 @@ static int btree_create_table(
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc, iTable, flags;
|
||||
int rc, iTable;
|
||||
char zBuf[30];
|
||||
if( argc!=3 ){
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID FLAGS\"", 0);
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &flags) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeCreateTable(pBt, &iTable, flags);
|
||||
rc = sqliteBtreeCreateTable(pBt, &iTable);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -325,7 +239,7 @@ static int btree_drop_table(
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeDropTable(pBt, iTable);
|
||||
rc = sqliteBtreeDropTable(pBt, iTable);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -354,7 +268,7 @@ static int btree_clear_table(
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeClearTable(pBt, iTable);
|
||||
rc = sqliteBtreeClearTable(pBt, iTable);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -376,21 +290,21 @@ static int btree_get_meta(
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
int i;
|
||||
int aMeta[SQLITE_N_BTREE_META];
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
rc = sqliteBtreeGetMeta(pBt, aMeta);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
for(i=0; i<SQLITE_N_BTREE_META; i++){
|
||||
char zBuf[30];
|
||||
unsigned int v;
|
||||
rc = sqlite3BtreeGetMeta(pBt, i, &v);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",v);
|
||||
sprintf(zBuf,"%d",aMeta[i]);
|
||||
Tcl_AppendElement(interp, zBuf);
|
||||
}
|
||||
return TCL_OK;
|
||||
@@ -420,15 +334,13 @@ static int btree_update_meta(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
for(i=1; i<SQLITE_N_BTREE_META; i++){
|
||||
for(i=0; i<SQLITE_N_BTREE_META; i++){
|
||||
if( Tcl_GetInt(interp, argv[i+2], &aMeta[i]) ) return TCL_ERROR;
|
||||
}
|
||||
for(i=1; i<SQLITE_N_BTREE_META; i++){
|
||||
rc = sqlite3BtreeUpdateMeta(pBt, i, aMeta[i]);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqliteBtreeUpdateMeta(pBt, aMeta);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -455,7 +367,7 @@ static int btree_page_dump(
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &iPage) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreePageDump(pBt, iPage, 0);
|
||||
rc = sqliteBtreePageDump(pBt, iPage, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -485,7 +397,7 @@ static int btree_tree_dump(
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &iPage) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreePageDump(pBt, iPage, 1);
|
||||
rc = sqliteBtreePageDump(pBt, iPage, 1);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -514,7 +426,7 @@ static int btree_pager_stats(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
a = sqlite3pager_stats(sqlite3BtreePager(pBt));
|
||||
a = sqlitepager_stats(sqliteBtreePager(pBt));
|
||||
for(i=0; i<9; i++){
|
||||
static char *zName[] = {
|
||||
"ref", "page", "max", "size", "state", "err",
|
||||
@@ -547,7 +459,7 @@ static int btree_pager_ref_dump(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
sqlite3pager_refdump(sqlite3BtreePager(pBt));
|
||||
sqlitepager_refdump(sqliteBtreePager(pBt));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -581,7 +493,7 @@ static int btree_integrity_check(
|
||||
for(i=0; i<argc-2; i++){
|
||||
if( Tcl_GetInt(interp, argv[i+2], &aRoot[i]) ) return TCL_ERROR;
|
||||
}
|
||||
zResult = sqlite3BtreeIntegrityCheck(pBt, aRoot, nRoot);
|
||||
zResult = sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot);
|
||||
if( zResult ){
|
||||
Tcl_AppendResult(interp, zResult, 0);
|
||||
sqliteFree(zResult);
|
||||
@@ -589,29 +501,6 @@ static int btree_integrity_check(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_cursor_list ID
|
||||
**
|
||||
** Print information about all cursors to standard output for debugging.
|
||||
*/
|
||||
static int btree_cursor_list(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
sqlite3BtreeCursorList(pBt);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_cursor ID TABLENUM WRITEABLE
|
||||
**
|
||||
@@ -638,7 +527,7 @@ static int btree_cursor(
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
|
||||
if( Tcl_GetBoolean(interp, argv[3], &wrFlag) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, 0, 0, &pCur);
|
||||
rc = sqliteBtreeCursor(pBt, iTable, wrFlag, &pCur);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -668,7 +557,7 @@ static int btree_close_cursor(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeCloseCursor(pCur);
|
||||
rc = sqliteBtreeCloseCursor(pCur);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -698,13 +587,7 @@ static int btree_move_to(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
|
||||
int iKey;
|
||||
if( Tcl_GetInt(interp, argv[2], &iKey) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeMoveto(pCur, 0, iKey, &res);
|
||||
}else{
|
||||
rc = sqlite3BtreeMoveto(pCur, argv[2], strlen(argv[2]), &res);
|
||||
}
|
||||
rc = sqliteBtreeMoveto(pCur, argv[2], strlen(argv[2]), &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -736,7 +619,7 @@ static int btree_delete(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeDelete(pCur);
|
||||
rc = sqliteBtreeDelete(pCur);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -751,36 +634,22 @@ static int btree_delete(
|
||||
** exists with the same key the old entry is overwritten.
|
||||
*/
|
||||
static int btree_insert(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
|
||||
if( objc!=4 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "ID KEY DATA");
|
||||
if( argc!=4 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID KEY DATA\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
|
||||
i64 iKey;
|
||||
int len;
|
||||
unsigned char *pBuf;
|
||||
if( Tcl_GetWideIntFromObj(interp, objv[2], &iKey) ) return TCL_ERROR;
|
||||
pBuf = Tcl_GetByteArrayFromObj(objv[3], &len);
|
||||
rc = sqlite3BtreeInsert(pCur, 0, iKey, pBuf, len);
|
||||
}else{
|
||||
int keylen;
|
||||
int dlen;
|
||||
unsigned char *pKBuf;
|
||||
unsigned char *pDBuf;
|
||||
pKBuf = Tcl_GetByteArrayFromObj(objv[2], &keylen);
|
||||
pDBuf = Tcl_GetByteArrayFromObj(objv[3], &dlen);
|
||||
rc = sqlite3BtreeInsert(pCur, pKBuf, keylen, pDBuf, dlen);
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqliteBtreeInsert(pCur, argv[2], strlen(argv[2]),
|
||||
argv[3], strlen(argv[3]));
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -812,7 +681,7 @@ static int btree_next(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeNext(pCur, &res);
|
||||
rc = sqliteBtreeNext(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -846,7 +715,7 @@ static int btree_prev(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreePrevious(pCur, &res);
|
||||
rc = sqliteBtreePrevious(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -879,7 +748,7 @@ static int btree_first(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeFirst(pCur, &res);
|
||||
rc = sqliteBtreeFirst(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -912,7 +781,7 @@ static int btree_last(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeLast(pCur, &res);
|
||||
rc = sqliteBtreeLast(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -922,60 +791,6 @@ static int btree_last(
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_eof ID
|
||||
**
|
||||
** Return TRUE if the given cursor is not pointing at a valid entry.
|
||||
** Return FALSE if the cursor does point to a valid entry.
|
||||
*/
|
||||
static int btree_eof(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
char zBuf[50];
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
sprintf(zBuf, "%d", sqlite3BtreeEof(pCur));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_keysize ID
|
||||
**
|
||||
** Return the number of bytes of key. For an INTKEY table, this
|
||||
** returns the key itself.
|
||||
*/
|
||||
static int btree_keysize(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
u64 n;
|
||||
char zBuf[50];
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
sqlite3BtreeKeySize(pCur, &n);
|
||||
sprintf(zBuf, "%llu", n);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_key ID
|
||||
**
|
||||
@@ -989,7 +804,7 @@ static int btree_key(
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
u64 n;
|
||||
int n;
|
||||
char *zBuf;
|
||||
|
||||
if( argc!=2 ){
|
||||
@@ -998,22 +813,19 @@ static int btree_key(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
sqlite3BtreeKeySize(pCur, &n);
|
||||
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
|
||||
char zBuf2[60];
|
||||
sprintf(zBuf2, "%llu", n);
|
||||
Tcl_AppendResult(interp, zBuf2, 0);
|
||||
}else{
|
||||
zBuf = malloc( n+1 );
|
||||
rc = sqlite3BtreeKey(pCur, 0, n, zBuf);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
zBuf[n] = 0;
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
sqliteBtreeKeySize(pCur, &n);
|
||||
zBuf = malloc( n+1 );
|
||||
rc = sqliteBtreeKey(pCur, 0, n, zBuf);
|
||||
if( rc!=n ){
|
||||
char zMsg[100];
|
||||
free(zBuf);
|
||||
sprintf(zMsg, "truncated key: got %d of %d bytes", rc, n);
|
||||
Tcl_AppendResult(interp, zMsg, 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
zBuf[n] = 0;
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
free(zBuf);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -1030,7 +842,7 @@ static int btree_data(
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
u32 n;
|
||||
int n;
|
||||
char *zBuf;
|
||||
|
||||
if( argc!=2 ){
|
||||
@@ -1039,11 +851,14 @@ static int btree_data(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
sqlite3BtreeDataSize(pCur, &n);
|
||||
sqliteBtreeDataSize(pCur, &n);
|
||||
zBuf = malloc( n+1 );
|
||||
rc = sqlite3BtreeData(pCur, 0, n, zBuf);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
rc = sqliteBtreeData(pCur, 0, n, zBuf);
|
||||
if( rc!=n ){
|
||||
char zMsg[100];
|
||||
free(zBuf);
|
||||
sprintf(zMsg, "truncated data: got %d of %d bytes", rc, n);
|
||||
Tcl_AppendResult(interp, zMsg, 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
zBuf[n] = 0;
|
||||
@@ -1052,82 +867,6 @@ static int btree_data(
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_fetch_key ID AMT
|
||||
**
|
||||
** Use the sqlite3BtreeKeyFetch() routine to get AMT bytes of the key.
|
||||
** If sqlite3BtreeKeyFetch() fails, return an empty string.
|
||||
*/
|
||||
static int btree_fetch_key(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int n;
|
||||
int amt;
|
||||
u64 nKey;
|
||||
const char *zBuf;
|
||||
char zStatic[1000];
|
||||
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID AMT\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
|
||||
sqlite3BtreeKeySize(pCur, &nKey);
|
||||
zBuf = sqlite3BtreeKeyFetch(pCur, &amt);
|
||||
if( zBuf && amt>=n ){
|
||||
assert( nKey<sizeof(zStatic) );
|
||||
if( n>0 ) nKey = n;
|
||||
memcpy(zStatic, zBuf, (int)nKey);
|
||||
zStatic[nKey] = 0;
|
||||
Tcl_AppendResult(interp, zStatic, 0);
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_fetch_data ID AMT
|
||||
**
|
||||
** Use the sqlite3BtreeDataFetch() routine to get AMT bytes of the key.
|
||||
** If sqlite3BtreeDataFetch() fails, return an empty string.
|
||||
*/
|
||||
static int btree_fetch_data(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int n;
|
||||
int amt;
|
||||
u32 nData;
|
||||
const char *zBuf;
|
||||
char zStatic[1000];
|
||||
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID AMT\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
|
||||
sqlite3BtreeDataSize(pCur, &nData);
|
||||
zBuf = sqlite3BtreeDataFetch(pCur, &amt);
|
||||
if( zBuf && amt>=n ){
|
||||
assert( nData<sizeof(zStatic) );
|
||||
if( n>0 ) nData = n;
|
||||
memcpy(zStatic, zBuf, (int)nData);
|
||||
zStatic[nData] = 0;
|
||||
Tcl_AppendResult(interp, zStatic, 0);
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_payload_size ID
|
||||
**
|
||||
@@ -1140,8 +879,7 @@ static int btree_payload_size(
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int n2;
|
||||
u64 n1;
|
||||
int n1, n2;
|
||||
char zBuf[50];
|
||||
|
||||
if( argc!=2 ){
|
||||
@@ -1150,35 +888,29 @@ static int btree_payload_size(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
|
||||
n1 = 0;
|
||||
}else{
|
||||
sqlite3BtreeKeySize(pCur, &n1);
|
||||
}
|
||||
sqlite3BtreeDataSize(pCur, &n2);
|
||||
sprintf(zBuf, "%d", (int)(n1+n2));
|
||||
sqliteBtreeKeySize(pCur, &n1);
|
||||
sqliteBtreeDataSize(pCur, &n2);
|
||||
sprintf(zBuf, "%d", n1+n2);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_cursor_info ID ?UP-CNT?
|
||||
** Usage: btree_cursor_dump ID
|
||||
**
|
||||
** Return integers containing information about the entry the
|
||||
** Return eight integers containing information about the entry the
|
||||
** cursor is pointing to:
|
||||
**
|
||||
** aResult[0] = The page number
|
||||
** aResult[1] = The entry number
|
||||
** aResult[2] = Total number of entries on this page
|
||||
** aResult[3] = Cell size (local payload + header)
|
||||
** aResult[3] = Size of this entry
|
||||
** aResult[4] = Number of free bytes on this page
|
||||
** aResult[5] = Number of free blocks on the page
|
||||
** aResult[6] = Total payload size (local + overflow)
|
||||
** aResult[7] = Header size in bytes
|
||||
** aResult[8] = Local payload size
|
||||
** aResult[9] = Parent page number
|
||||
** aResult[6] = Page number of the left child of this entry
|
||||
** aResult[7] = Page number of the right child for the whole page
|
||||
*/
|
||||
static int btree_cursor_info(
|
||||
static int btree_cursor_dump(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
@@ -1187,22 +919,16 @@ static int btree_cursor_info(
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
int i, j;
|
||||
int up;
|
||||
int aResult[10];
|
||||
int aResult[8];
|
||||
char zBuf[400];
|
||||
|
||||
if( argc!=2 && argc!=3 ){
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID ?UP-CNT?\"", 0);
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
if( argc==3 ){
|
||||
if( Tcl_GetInt(interp, argv[2], &up) ) return TCL_ERROR;
|
||||
}else{
|
||||
up = 0;
|
||||
}
|
||||
rc = sqlite3BtreeCursorInfo(pCur, aResult, up);
|
||||
rc = sqliteBtreeCursorDump(pCur, aResult);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -1216,113 +942,10 @@ static int btree_cursor_info(
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** The command is provided for the purpose of setting breakpoints.
|
||||
** in regression test scripts.
|
||||
**
|
||||
** By setting a GDB breakpoint on this procedure and executing the
|
||||
** btree_breakpoint command in a test script, we can stop GDB at
|
||||
** the point in the script where the btree_breakpoint command is
|
||||
** inserted. This is useful for debugging.
|
||||
*/
|
||||
static int btree_breakpoint(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** usage: varint_test START MULTIPLIER COUNT INCREMENT
|
||||
**
|
||||
** This command tests the sqlite3PutVarint() and sqlite3GetVarint()
|
||||
** routines, both for accuracy and for speed.
|
||||
**
|
||||
** An integer is written using PutVarint() and read back with
|
||||
** GetVarint() and varified to be unchanged. This repeats COUNT
|
||||
** times. The first integer is START*MULTIPLIER. Each iteration
|
||||
** increases the integer by INCREMENT.
|
||||
**
|
||||
** This command returns nothing if it works. It returns an error message
|
||||
** if something goes wrong.
|
||||
*/
|
||||
static int btree_varint_test(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
u32 start, mult, count, incr;
|
||||
u64 in, out;
|
||||
int n1, n2, i, j;
|
||||
unsigned char zBuf[100];
|
||||
if( argc!=5 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" START MULTIPLIER COUNT INCREMENT\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&start) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], (int*)&mult) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[3], (int*)&count) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[4], (int*)&incr) ) return TCL_ERROR;
|
||||
in = start;
|
||||
in *= mult;
|
||||
for(i=0; i<count; i++){
|
||||
char zErr[200];
|
||||
n1 = sqlite3PutVarint(zBuf, in);
|
||||
if( n1>9 || n1<1 ){
|
||||
sprintf(zErr, "PutVarint returned %d - should be between 1 and 9", n1);
|
||||
Tcl_AppendResult(interp, zErr, 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
n2 = sqlite3GetVarint(zBuf, &out);
|
||||
if( n1!=n2 ){
|
||||
sprintf(zErr, "PutVarint returned %d and GetVarint returned %d", n1, n2);
|
||||
Tcl_AppendResult(interp, zErr, 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( in!=out ){
|
||||
sprintf(zErr, "Wrote 0x%016llx and got back 0x%016llx", in, out);
|
||||
Tcl_AppendResult(interp, zErr, 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( (in & 0xffffffff)==in ){
|
||||
u32 out32;
|
||||
n2 = sqlite3GetVarint32(zBuf, &out32);
|
||||
out = out32;
|
||||
if( n1!=n2 ){
|
||||
sprintf(zErr, "PutVarint returned %d and GetVarint32 returned %d",
|
||||
n1, n2);
|
||||
Tcl_AppendResult(interp, zErr, 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( in!=out ){
|
||||
sprintf(zErr, "Wrote 0x%016llx and got back 0x%016llx from GetVarint32",
|
||||
in, out);
|
||||
Tcl_AppendResult(interp, zErr, 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* In order to get realistic timings, run getVarint 19 more times.
|
||||
** This is because getVarint is called about 20 times more often
|
||||
** than putVarint.
|
||||
*/
|
||||
for(j=0; j<19; j++){
|
||||
sqlite3GetVarint(zBuf, &out);
|
||||
}
|
||||
in += incr;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest3_Init(Tcl_Interp *interp){
|
||||
extern int sqlite3_btree_trace;
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_CmdProc *xProc;
|
||||
@@ -1345,40 +968,25 @@ int Sqlitetest3_Init(Tcl_Interp *interp){
|
||||
{ "btree_close_cursor", (Tcl_CmdProc*)btree_close_cursor },
|
||||
{ "btree_move_to", (Tcl_CmdProc*)btree_move_to },
|
||||
{ "btree_delete", (Tcl_CmdProc*)btree_delete },
|
||||
{ "btree_insert", (Tcl_CmdProc*)btree_insert },
|
||||
{ "btree_next", (Tcl_CmdProc*)btree_next },
|
||||
{ "btree_prev", (Tcl_CmdProc*)btree_prev },
|
||||
{ "btree_eof", (Tcl_CmdProc*)btree_eof },
|
||||
{ "btree_keysize", (Tcl_CmdProc*)btree_keysize },
|
||||
{ "btree_key", (Tcl_CmdProc*)btree_key },
|
||||
{ "btree_data", (Tcl_CmdProc*)btree_data },
|
||||
{ "btree_fetch_key", (Tcl_CmdProc*)btree_fetch_key },
|
||||
{ "btree_fetch_data", (Tcl_CmdProc*)btree_fetch_data },
|
||||
{ "btree_payload_size", (Tcl_CmdProc*)btree_payload_size },
|
||||
{ "btree_first", (Tcl_CmdProc*)btree_first },
|
||||
{ "btree_last", (Tcl_CmdProc*)btree_last },
|
||||
{ "btree_cursor_info", (Tcl_CmdProc*)btree_cursor_info },
|
||||
{ "btree_cursor_list", (Tcl_CmdProc*)btree_cursor_list },
|
||||
{ "btree_cursor_dump", (Tcl_CmdProc*)btree_cursor_dump },
|
||||
{ "btree_integrity_check", (Tcl_CmdProc*)btree_integrity_check },
|
||||
{ "btree_breakpoint", (Tcl_CmdProc*)btree_breakpoint },
|
||||
{ "btree_varint_test", (Tcl_CmdProc*)btree_varint_test },
|
||||
{ "btree_begin_statement", (Tcl_CmdProc*)btree_begin_statement },
|
||||
{ "btree_commit_statement", (Tcl_CmdProc*)btree_commit_statement },
|
||||
{ "btree_rollback_statement", (Tcl_CmdProc*)btree_rollback_statement },
|
||||
};
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
||||
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
||||
}
|
||||
Tcl_LinkVar(interp, "pager_refinfo_enable", (char*)&pager3_refinfo_enable,
|
||||
Tcl_LinkVar(interp, "pager_refinfo_enable", (char*)&pager_refinfo_enable,
|
||||
TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "btree_trace", (char*)&sqlite3_btree_trace,
|
||||
Tcl_LinkVar(interp, "btree_native_byte_order",(char*)&btree_native_byte_order,
|
||||
TCL_LINK_INT);
|
||||
|
||||
/* The btree_insert command is implemented using the tcl 'object'
|
||||
** interface, not the string interface like the other commands in this
|
||||
** file. This is so binary data can be inserted into btree tables.
|
||||
*/
|
||||
Tcl_CreateObjCommand(interp, "btree_insert", btree_insert, 0, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
+23
-39
@@ -11,11 +11,10 @@
|
||||
*************************************************************************
|
||||
** Code for testing the the SQLite library in a multithreaded environment.
|
||||
**
|
||||
** $Id: test4.c,v 1.11 2004/08/08 20:22:18 drh Exp $
|
||||
** $Id: test4.c,v 1.3 2004/04/23 17:04:45 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
#include "os.h"
|
||||
#if defined(OS_UNIX) && OS_UNIX==1 && defined(THREADSAFE) && THREADSAFE==1
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -41,13 +40,13 @@ struct Thread {
|
||||
** master. */
|
||||
int completed; /* Number of operations completed */
|
||||
sqlite *db; /* Open database */
|
||||
sqlite3_stmt *pStmt; /* Pending operation */
|
||||
sqlite_vm *vm; /* Pending operation */
|
||||
char *zErr; /* operation error */
|
||||
char *zStaticErr; /* Static error message */
|
||||
int rc; /* operation return code */
|
||||
int argc; /* number of columns in result */
|
||||
const char *argv[100]; /* result columns */
|
||||
const char *colv[100]; /* result column names */
|
||||
const char **argv; /* result columns */
|
||||
const char **colv; /* result column names */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -64,36 +63,31 @@ static Thread threadset[N_THREAD];
|
||||
static void *thread_main(void *pArg){
|
||||
Thread *p = (Thread*)pArg;
|
||||
if( p->db ){
|
||||
sqlite3_close(p->db);
|
||||
sqlite_close(p->db);
|
||||
}
|
||||
sqlite3_open(p->zFilename, &p->db);
|
||||
if( SQLITE_OK!=sqlite3_errcode(p->db) ){
|
||||
p->zErr = strdup(sqlite3_errmsg(p->db));
|
||||
sqlite3_close(p->db);
|
||||
p->db = 0;
|
||||
}
|
||||
p->pStmt = 0;
|
||||
p->db = sqlite_open(p->zFilename, 0, &p->zErr);
|
||||
p->vm = 0;
|
||||
p->completed = 1;
|
||||
while( p->opnum<=p->completed ) sched_yield();
|
||||
while( p->xOp ){
|
||||
if( p->zErr && p->zErr!=p->zStaticErr ){
|
||||
sqlite3_free(p->zErr);
|
||||
sqlite_freemem(p->zErr);
|
||||
p->zErr = 0;
|
||||
}
|
||||
(*p->xOp)(p);
|
||||
p->completed++;
|
||||
while( p->opnum<=p->completed ) sched_yield();
|
||||
}
|
||||
if( p->pStmt ){
|
||||
sqlite3_finalize(p->pStmt);
|
||||
p->pStmt = 0;
|
||||
if( p->vm ){
|
||||
sqlite_finalize(p->vm, 0);
|
||||
p->vm = 0;
|
||||
}
|
||||
if( p->db ){
|
||||
sqlite3_close(p->db);
|
||||
sqlite_close(p->db);
|
||||
p->db = 0;
|
||||
}
|
||||
if( p->zErr && p->zErr!=p->zStaticErr ){
|
||||
sqlite3_free(p->zErr);
|
||||
sqlite_freemem(p->zErr);
|
||||
p->zErr = 0;
|
||||
}
|
||||
p->completed++;
|
||||
@@ -106,7 +100,7 @@ static void *thread_main(void *pArg){
|
||||
** the interpreter and return -1.
|
||||
*/
|
||||
static int parse_thread_id(Tcl_Interp *interp, const char *zArg){
|
||||
if( zArg==0 || zArg[0]==0 || zArg[1]!=0 || !isupper((unsigned char)zArg[0]) ){
|
||||
if( zArg==0 || zArg[0]==0 || zArg[1]!=0 || !isupper(zArg[0]) ){
|
||||
Tcl_AppendResult(interp, "thread ID must be an upper case letter", 0);
|
||||
return -1;
|
||||
}
|
||||
@@ -446,11 +440,11 @@ static void do_compile(Thread *p){
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
if( p->pStmt ){
|
||||
sqlite3_finalize(p->pStmt);
|
||||
p->pStmt = 0;
|
||||
if( p->vm ){
|
||||
sqlite_finalize(p->vm, 0);
|
||||
p->vm = 0;
|
||||
}
|
||||
p->rc = sqlite3_prepare(p->db, p->zArg, -1, &p->pStmt, 0);
|
||||
p->rc = sqlite_compile(p->db, p->zArg, 0, &p->vm, &p->zErr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -488,22 +482,12 @@ static int tcl_thread_compile(
|
||||
** This procedure runs in the thread to step the virtual machine.
|
||||
*/
|
||||
static void do_step(Thread *p){
|
||||
int i;
|
||||
if( p->pStmt==0 ){
|
||||
if( p->vm==0 ){
|
||||
p->zErr = p->zStaticErr = "no virtual machine available";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
p->rc = sqlite3_step(p->pStmt);
|
||||
if( p->rc==SQLITE_ROW ){
|
||||
p->argc = sqlite3_column_count(p->pStmt);
|
||||
for(i=0; i<sqlite3_data_count(p->pStmt); i++){
|
||||
p->argv[i] = sqlite3_column_text(p->pStmt, i);
|
||||
}
|
||||
for(i=0; i<p->argc; i++){
|
||||
p->colv[i] = sqlite3_column_name(p->pStmt, i);
|
||||
}
|
||||
}
|
||||
p->rc = sqlite_step(p->vm, &p->argc, &p->argv, &p->colv);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -539,13 +523,13 @@ static int tcl_thread_step(
|
||||
** This procedure runs in the thread to finalize a virtual machine.
|
||||
*/
|
||||
static void do_finalize(Thread *p){
|
||||
if( p->pStmt==0 ){
|
||||
if( p->vm==0 ){
|
||||
p->zErr = p->zStaticErr = "no virtual machine available";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
p->rc = sqlite3_finalize(p->pStmt);
|
||||
p->pStmt = 0;
|
||||
p->rc = sqlite_finalize(p->vm, &p->zErr);
|
||||
p->vm = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
-217
@@ -1,217 +0,0 @@
|
||||
/*
|
||||
** 2001 September 15
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** Code for testing the utf.c module in SQLite. This code
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library. Specifically, the code in this file
|
||||
** is used for testing the SQLite routines for converting between
|
||||
** the various supported unicode encodings.
|
||||
**
|
||||
** $Id: test5.c,v 1.13 2004/06/25 02:38:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
#include "os.h" /* to get SQLITE_BIGENDIAN */
|
||||
#include "tcl.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
** The first argument is a TCL UTF-8 string. Return the byte array
|
||||
** object with the encoded representation of the string, including
|
||||
** the NULL terminator.
|
||||
*/
|
||||
static int binarize(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int len;
|
||||
char *bytes;
|
||||
Tcl_Obj *pRet;
|
||||
assert(objc==2);
|
||||
|
||||
bytes = Tcl_GetStringFromObj(objv[1], &len);
|
||||
pRet = Tcl_NewByteArrayObj(bytes, len+1);
|
||||
Tcl_SetObjResult(interp, pRet);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: test_value_overhead <repeat-count> <do-calls>.
|
||||
**
|
||||
** This routine is used to test the overhead of calls to
|
||||
** sqlite3_value_text(), on a value that contains a UTF-8 string. The idea
|
||||
** is to figure out whether or not it is a problem to use sqlite3_value
|
||||
** structures with collation sequence functions.
|
||||
**
|
||||
** If <do-calls> is 0, then the calls to sqlite3_value_text() are not
|
||||
** actually made.
|
||||
*/
|
||||
static int test_value_overhead(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int do_calls;
|
||||
int repeat_count;
|
||||
int i;
|
||||
Mem val;
|
||||
const char *zVal;
|
||||
|
||||
if( objc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0), " <repeat-count> <do-calls>", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], &repeat_count) ) return TCL_ERROR;
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &do_calls) ) return TCL_ERROR;
|
||||
|
||||
val.flags = MEM_Str|MEM_Term|MEM_Static;
|
||||
val.z = "hello world";
|
||||
val.type = SQLITE_TEXT;
|
||||
val.enc = SQLITE_UTF8;
|
||||
|
||||
for(i=0; i<repeat_count; i++){
|
||||
if( do_calls ){
|
||||
zVal = sqlite3_value_text(&val);
|
||||
}
|
||||
}
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
static u8 name_to_enc(Tcl_Interp *interp, Tcl_Obj *pObj){
|
||||
struct EncName {
|
||||
char *zName;
|
||||
u8 enc;
|
||||
} encnames[] = {
|
||||
{ "UTF8", SQLITE_UTF8 },
|
||||
{ "UTF16LE", SQLITE_UTF16LE },
|
||||
{ "UTF16BE", SQLITE_UTF16BE },
|
||||
{ "UTF16", SQLITE_UTF16NATIVE },
|
||||
{ 0, 0 }
|
||||
};
|
||||
struct EncName *pEnc;
|
||||
char *z = Tcl_GetString(pObj);
|
||||
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
|
||||
if( 0==sqlite3StrICmp(z, pEnc->zName) ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !pEnc->enc ){
|
||||
Tcl_AppendResult(interp, "No such encoding: ", z, 0);
|
||||
}
|
||||
return pEnc->enc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: test_translate <string/blob> <from enc> <to enc> ?<transient>?
|
||||
**
|
||||
*/
|
||||
static int test_translate(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
u8 enc_from;
|
||||
u8 enc_to;
|
||||
sqlite3_value *pVal;
|
||||
|
||||
char *z;
|
||||
int len;
|
||||
void (*xDel)(void *p) = SQLITE_STATIC;
|
||||
|
||||
if( objc!=4 && objc!=5 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0),
|
||||
" <string/blob> <from enc> <to enc>", 0
|
||||
);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( objc==5 ){
|
||||
xDel = sqlite3FreeX;
|
||||
}
|
||||
|
||||
enc_from = name_to_enc(interp, objv[2]);
|
||||
if( !enc_from ) return TCL_ERROR;
|
||||
enc_to = name_to_enc(interp, objv[3]);
|
||||
if( !enc_to ) return TCL_ERROR;
|
||||
|
||||
pVal = sqlite3ValueNew();
|
||||
|
||||
if( enc_from==SQLITE_UTF8 ){
|
||||
z = Tcl_GetString(objv[1]);
|
||||
if( objc==5 ){
|
||||
z = sqliteStrDup(z);
|
||||
}
|
||||
sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel);
|
||||
}else{
|
||||
z = Tcl_GetByteArrayFromObj(objv[1], &len);
|
||||
if( objc==5 ){
|
||||
char *zTmp = z;
|
||||
z = sqliteMalloc(len);
|
||||
memcpy(z, zTmp, len);
|
||||
}
|
||||
sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel);
|
||||
}
|
||||
|
||||
z = (char *)sqlite3ValueText(pVal, enc_to);
|
||||
len = sqlite3ValueBytes(pVal, enc_to) + (enc_to==SQLITE_UTF8?1:2);
|
||||
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(z, len));
|
||||
|
||||
sqlite3ValueFree(pVal);
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: translate_selftest
|
||||
**
|
||||
** Call sqlite3utfSelfTest() to run the internal tests for unicode
|
||||
** translation. If there is a problem an assert() will fail.
|
||||
**/
|
||||
void sqlite3utfSelfTest();
|
||||
static int test_translate_selftest(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3utfSelfTest();
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest5_Init(Tcl_Interp *interp){
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_ObjCmdProc *xProc;
|
||||
} aCmd[] = {
|
||||
{ "binarize", (Tcl_ObjCmdProc*)binarize },
|
||||
{ "test_value_overhead", (Tcl_ObjCmdProc*)test_value_overhead },
|
||||
{ "test_translate", (Tcl_ObjCmdProc*)test_translate },
|
||||
{ "translate_selftest", (Tcl_ObjCmdProc*)test_translate_selftest},
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
||||
Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
+36
-119
@@ -15,7 +15,7 @@
|
||||
** individual tokens and sends those tokens one-by-one over to the
|
||||
** parser for analysis.
|
||||
**
|
||||
** $Id: tokenize.c,v 1.84 2004/08/25 04:07:02 drh Exp $
|
||||
** $Id: tokenize.c,v 1.68 2004/02/14 23:59:58 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -57,6 +57,7 @@ static Keyword aKeywordTable[] = {
|
||||
{ "COMMIT", TK_COMMIT, },
|
||||
{ "CONFLICT", TK_CONFLICT, },
|
||||
{ "CONSTRAINT", TK_CONSTRAINT, },
|
||||
{ "COPY", TK_COPY, },
|
||||
{ "CREATE", TK_CREATE, },
|
||||
{ "CROSS", TK_JOIN_KW, },
|
||||
{ "DATABASE", TK_DATABASE, },
|
||||
@@ -64,6 +65,7 @@ static Keyword aKeywordTable[] = {
|
||||
{ "DEFERRED", TK_DEFERRED, },
|
||||
{ "DEFERRABLE", TK_DEFERRABLE, },
|
||||
{ "DELETE", TK_DELETE, },
|
||||
{ "DELIMITERS", TK_DELIMITERS, },
|
||||
{ "DESC", TK_DESC, },
|
||||
{ "DETACH", TK_DETACH, },
|
||||
{ "DISTINCT", TK_DISTINCT, },
|
||||
@@ -150,31 +152,31 @@ static u8 aiHashTable[KEY_HASH_SIZE];
|
||||
** keyword. If it is a keyword, the token code of that keyword is
|
||||
** returned. If the input is not a keyword, TK_ID is returned.
|
||||
*/
|
||||
int sqlite3KeywordCode(const char *z, int n){
|
||||
int sqliteKeywordCode(const char *z, int n){
|
||||
int h, i;
|
||||
Keyword *p;
|
||||
static char needInit = 1;
|
||||
if( needInit ){
|
||||
/* Initialize the keyword hash table */
|
||||
sqlite3OsEnterMutex();
|
||||
sqliteOsEnterMutex();
|
||||
if( needInit ){
|
||||
int nk;
|
||||
nk = sizeof(aKeywordTable)/sizeof(aKeywordTable[0]);
|
||||
for(i=0; i<nk; i++){
|
||||
aKeywordTable[i].len = strlen(aKeywordTable[i].zName);
|
||||
h = sqlite3HashNoCase(aKeywordTable[i].zName, aKeywordTable[i].len);
|
||||
h = sqliteHashNoCase(aKeywordTable[i].zName, aKeywordTable[i].len);
|
||||
h %= KEY_HASH_SIZE;
|
||||
aKeywordTable[i].iNext = aiHashTable[h];
|
||||
aiHashTable[h] = i+1;
|
||||
}
|
||||
needInit = 0;
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
sqliteOsLeaveMutex();
|
||||
}
|
||||
h = sqlite3HashNoCase(z, n) % KEY_HASH_SIZE;
|
||||
h = sqliteHashNoCase(z, n) % KEY_HASH_SIZE;
|
||||
for(i=aiHashTable[h]; i; i=p->iNext){
|
||||
p = &aKeywordTable[i-1];
|
||||
if( p->len==n && sqlite3StrNICmp(p->zName, z, n)==0 ){
|
||||
if( p->len==n && sqliteStrNICmp(p->zName, z, n)==0 ){
|
||||
return p->tokenType;
|
||||
}
|
||||
}
|
||||
@@ -373,74 +375,12 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
*tokenType = TK_VARIABLE;
|
||||
return 1;
|
||||
}
|
||||
case ':': {
|
||||
for(i=1; (z[i]&0x80)!=0 || isIdChar[z[i]]; i++){}
|
||||
*tokenType = i>1 ? TK_VARIABLE : TK_ILLEGAL;
|
||||
return i;
|
||||
}
|
||||
case '$': {
|
||||
int c;
|
||||
*tokenType = TK_VARIABLE;
|
||||
if( z[1]=='{' ){
|
||||
int nBrace = 1;
|
||||
for(i=2; (c=z[i])!=0 && nBrace; i++){
|
||||
if( c=='{' ){
|
||||
nBrace++;
|
||||
}else if( c=='}' ){
|
||||
nBrace--;
|
||||
}
|
||||
}
|
||||
if( c==0 ) *tokenType = TK_ILLEGAL;
|
||||
}else{
|
||||
int n = 0;
|
||||
for(i=1; (c=z[i])!=0; i++){
|
||||
if( isalnum(c) || c=='_' ){
|
||||
n++;
|
||||
}else if( c=='(' && n>0 ){
|
||||
do{
|
||||
i++;
|
||||
}while( (c=z[i])!=0 && !isspace(c) && c!=')' );
|
||||
if( c==')' ){
|
||||
i++;
|
||||
}else{
|
||||
*tokenType = TK_ILLEGAL;
|
||||
}
|
||||
break;
|
||||
}else if( c==':' && z[i+1]==':' ){
|
||||
i++;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( n==0 ) *tokenType = TK_ILLEGAL;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
case 'x': case 'X': {
|
||||
if( z[1]=='\'' || z[1]=='"' ){
|
||||
int delim = z[1];
|
||||
*tokenType = TK_BLOB;
|
||||
for(i=2; z[i]; i++){
|
||||
if( z[i]==delim ){
|
||||
if( i%2 ) *tokenType = TK_ILLEGAL;
|
||||
break;
|
||||
}
|
||||
if( !isxdigit(z[i]) ){
|
||||
*tokenType = TK_ILLEGAL;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
if( z[i] ) i++;
|
||||
return i;
|
||||
}
|
||||
/* Otherwise fall through to the next case */
|
||||
}
|
||||
default: {
|
||||
if( (*z&0x80)==0 && !isIdChar[*z] ){
|
||||
break;
|
||||
}
|
||||
for(i=1; (z[i]&0x80)!=0 || isIdChar[z[i]]; i++){}
|
||||
*tokenType = sqlite3KeywordCode((char*)z, i);
|
||||
*tokenType = sqliteKeywordCode((char*)z, i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -455,28 +395,28 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
** memory obtained from malloc() and *pzErrMsg made to point to that
|
||||
** error message. Or maybe not.
|
||||
*/
|
||||
int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
int sqliteRunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
int nErr = 0;
|
||||
int i;
|
||||
void *pEngine;
|
||||
int tokenType;
|
||||
int lastTokenParsed = -1;
|
||||
sqlite *db = pParse->db;
|
||||
extern void *sqlite3ParserAlloc(void*(*)(int));
|
||||
extern void sqlite3ParserFree(void*, void(*)(void*));
|
||||
extern int sqlite3Parser(void*, int, Token, Parse*);
|
||||
extern void *sqliteParserAlloc(void*(*)(int));
|
||||
extern void sqliteParserFree(void*, void(*)(void*));
|
||||
extern int sqliteParser(void*, int, Token, Parse*);
|
||||
|
||||
db->flags &= ~SQLITE_Interrupt;
|
||||
pParse->rc = SQLITE_OK;
|
||||
i = 0;
|
||||
pEngine = sqlite3ParserAlloc((void*(*)(int))malloc);
|
||||
pEngine = sqliteParserAlloc((void*(*)(int))malloc);
|
||||
if( pEngine==0 ){
|
||||
sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
|
||||
sqliteSetString(pzErrMsg, "out of memory", (char*)0);
|
||||
return 1;
|
||||
}
|
||||
pParse->sLastToken.dyn = 0;
|
||||
pParse->zTail = pParse->zSql = zSql;
|
||||
while( sqlite3_malloc_failed==0 && zSql[i]!=0 ){
|
||||
pParse->zTail = zSql;
|
||||
while( sqlite_malloc_failed==0 && zSql[i]!=0 ){
|
||||
assert( i>=0 );
|
||||
pParse->sLastToken.z = &zSql[i];
|
||||
assert( pParse->sLastToken.dyn==0 );
|
||||
@@ -487,13 +427,13 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
case TK_COMMENT: {
|
||||
if( (db->flags & SQLITE_Interrupt)!=0 ){
|
||||
pParse->rc = SQLITE_INTERRUPT;
|
||||
sqlite3SetString(pzErrMsg, "interrupt", (char*)0);
|
||||
sqliteSetString(pzErrMsg, "interrupt", (char*)0);
|
||||
goto abort_parse;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TK_ILLEGAL: {
|
||||
sqlite3SetNString(pzErrMsg, "unrecognized token: \"", -1,
|
||||
sqliteSetNString(pzErrMsg, "unrecognized token: \"", -1,
|
||||
pParse->sLastToken.z, pParse->sLastToken.n, "\"", 1, 0);
|
||||
nErr++;
|
||||
goto abort_parse;
|
||||
@@ -503,7 +443,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
/* Fall thru into the default case */
|
||||
}
|
||||
default: {
|
||||
sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse);
|
||||
sqliteParser(pEngine, tokenType, pParse->sLastToken, pParse);
|
||||
lastTokenParsed = tokenType;
|
||||
if( pParse->rc!=SQLITE_OK ){
|
||||
goto abort_parse;
|
||||
@@ -515,17 +455,14 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
abort_parse:
|
||||
if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
|
||||
if( lastTokenParsed!=TK_SEMI ){
|
||||
sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
|
||||
sqliteParser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
|
||||
pParse->zTail = &zSql[i];
|
||||
}
|
||||
sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
|
||||
}
|
||||
sqlite3ParserFree(pEngine, free);
|
||||
if( sqlite3_malloc_failed ){
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
sqliteParser(pEngine, 0, pParse->sLastToken, pParse);
|
||||
}
|
||||
sqliteParserFree(pEngine, free);
|
||||
if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
|
||||
sqlite3SetString(&pParse->zErrMsg, sqlite3ErrStr(pParse->rc),
|
||||
sqliteSetString(&pParse->zErrMsg, sqlite_error_string(pParse->rc),
|
||||
(char*)0);
|
||||
}
|
||||
if( pParse->zErrMsg ){
|
||||
@@ -538,15 +475,15 @@ abort_parse:
|
||||
if( !nErr ) nErr++;
|
||||
}
|
||||
if( pParse->pVdbe && pParse->nErr>0 ){
|
||||
sqlite3VdbeDelete(pParse->pVdbe);
|
||||
sqliteVdbeDelete(pParse->pVdbe);
|
||||
pParse->pVdbe = 0;
|
||||
}
|
||||
if( pParse->pNewTable ){
|
||||
sqlite3DeleteTable(pParse->db, pParse->pNewTable);
|
||||
sqliteDeleteTable(pParse->db, pParse->pNewTable);
|
||||
pParse->pNewTable = 0;
|
||||
}
|
||||
if( pParse->pNewTrigger ){
|
||||
sqlite3DeleteTrigger(pParse->pNewTrigger);
|
||||
sqliteDeleteTrigger(pParse->pNewTrigger);
|
||||
pParse->pNewTrigger = 0;
|
||||
}
|
||||
if( nErr>0 && (pParse->rc==SQLITE_OK || pParse->rc==SQLITE_DONE) ){
|
||||
@@ -556,7 +493,7 @@ abort_parse:
|
||||
}
|
||||
|
||||
/*
|
||||
** Token types used by the sqlite3_complete() routine. See the header
|
||||
** Token types used by the sqlite_complete() routine. See the header
|
||||
** comments on that procedure for additional information.
|
||||
*/
|
||||
#define tkEXPLAIN 0
|
||||
@@ -614,7 +551,7 @@ abort_parse:
|
||||
**
|
||||
** Whitespace never causes a state transition and is always ignored.
|
||||
*/
|
||||
int sqlite3_complete(const char *zSql){
|
||||
int sqlite_complete(const char *zSql){
|
||||
u8 state = 0; /* Current state, using numbers defined in header comment */
|
||||
u8 token; /* Value of the next token */
|
||||
|
||||
@@ -693,7 +630,7 @@ int sqlite3_complete(const char *zSql){
|
||||
for(nId=1; isIdChar[(u8)zSql[nId]]; nId++){}
|
||||
switch( *zSql ){
|
||||
case 'c': case 'C': {
|
||||
if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
|
||||
if( nId==6 && sqliteStrNICmp(zSql, "create", 6)==0 ){
|
||||
token = tkCREATE;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
@@ -701,11 +638,11 @@ int sqlite3_complete(const char *zSql){
|
||||
break;
|
||||
}
|
||||
case 't': case 'T': {
|
||||
if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
|
||||
if( nId==7 && sqliteStrNICmp(zSql, "trigger", 7)==0 ){
|
||||
token = tkTRIGGER;
|
||||
}else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
|
||||
}else if( nId==4 && sqliteStrNICmp(zSql, "temp", 4)==0 ){
|
||||
token = tkTEMP;
|
||||
}else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
|
||||
}else if( nId==9 && sqliteStrNICmp(zSql, "temporary", 9)==0 ){
|
||||
token = tkTEMP;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
@@ -713,9 +650,9 @@ int sqlite3_complete(const char *zSql){
|
||||
break;
|
||||
}
|
||||
case 'e': case 'E': {
|
||||
if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
|
||||
if( nId==3 && sqliteStrNICmp(zSql, "end", 3)==0 ){
|
||||
token = tkEND;
|
||||
}else if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
|
||||
}else if( nId==7 && sqliteStrNICmp(zSql, "explain", 7)==0 ){
|
||||
token = tkEXPLAIN;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
@@ -740,23 +677,3 @@ int sqlite3_complete(const char *zSql){
|
||||
}
|
||||
return state==0;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is the same as the sqlite3_complete() routine described
|
||||
** above, except that the parameter is required to be UTF-16 encoded, not
|
||||
** UTF-8.
|
||||
*/
|
||||
int sqlite3_complete16(const void *zSql){
|
||||
sqlite3_value *pVal;
|
||||
char const *zSql8;
|
||||
int rc = 0;
|
||||
|
||||
pVal = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
if( zSql8 ){
|
||||
rc = sqlite3_complete(zSql8);
|
||||
}
|
||||
sqlite3ValueFree(pVal);
|
||||
return rc;
|
||||
}
|
||||
|
||||
+202
-245
@@ -15,16 +15,16 @@
|
||||
/*
|
||||
** Delete a linked list of TriggerStep structures.
|
||||
*/
|
||||
void sqlite3DeleteTriggerStep(TriggerStep *pTriggerStep){
|
||||
void sqliteDeleteTriggerStep(TriggerStep *pTriggerStep){
|
||||
while( pTriggerStep ){
|
||||
TriggerStep * pTmp = pTriggerStep;
|
||||
pTriggerStep = pTriggerStep->pNext;
|
||||
|
||||
if( pTmp->target.dyn ) sqliteFree((char*)pTmp->target.z);
|
||||
sqlite3ExprDelete(pTmp->pWhere);
|
||||
sqlite3ExprListDelete(pTmp->pExprList);
|
||||
sqlite3SelectDelete(pTmp->pSelect);
|
||||
sqlite3IdListDelete(pTmp->pIdList);
|
||||
sqliteExprDelete(pTmp->pWhere);
|
||||
sqliteExprListDelete(pTmp->pExprList);
|
||||
sqliteSelectDelete(pTmp->pSelect);
|
||||
sqliteIdListDelete(pTmp->pIdList);
|
||||
|
||||
sqliteFree(pTmp);
|
||||
}
|
||||
@@ -35,13 +35,12 @@ void sqlite3DeleteTriggerStep(TriggerStep *pTriggerStep){
|
||||
** up to the point of the BEGIN before the trigger actions. A Trigger
|
||||
** structure is generated based on the information available and stored
|
||||
** in pParse->pNewTrigger. After the trigger actions have been parsed, the
|
||||
** sqlite3FinishTrigger() function is called to complete the trigger
|
||||
** sqliteFinishTrigger() function is called to complete the trigger
|
||||
** construction process.
|
||||
*/
|
||||
void sqlite3BeginTrigger(
|
||||
void sqliteBeginTrigger(
|
||||
Parse *pParse, /* The parse context of the CREATE TRIGGER statement */
|
||||
Token *pName1, /* The name of the trigger */
|
||||
Token *pName2, /* The name of the trigger */
|
||||
Token *pName, /* The name of the trigger */
|
||||
int tr_tm, /* One of TK_BEFORE, TK_AFTER, TK_INSTEAD */
|
||||
int op, /* One of TK_INSERT, TK_UPDATE, TK_DELETE */
|
||||
IdList *pColumns, /* column list if this is an UPDATE OF trigger */
|
||||
@@ -50,104 +49,76 @@ void sqlite3BeginTrigger(
|
||||
Expr *pWhen, /* WHEN clause */
|
||||
int isTemp /* True if the TEMPORARY keyword is present */
|
||||
){
|
||||
Trigger *pTrigger;
|
||||
Table *pTab;
|
||||
Trigger *nt;
|
||||
Table *tab;
|
||||
char *zName = 0; /* Name of the trigger */
|
||||
sqlite *db = pParse->db;
|
||||
int iDb; /* The database to store the trigger in */
|
||||
Token *pName; /* The unqualified db name */
|
||||
int iDb; /* When database to store the trigger in */
|
||||
DbFixer sFix;
|
||||
|
||||
if( isTemp ){
|
||||
/* If TEMP was specified, then the trigger name may not be qualified. */
|
||||
if( pName2 && pName2->n>0 ){
|
||||
sqlite3ErrorMsg(pParse, "temporary trigger may not have qualified name");
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
iDb = 1;
|
||||
pName = pName1;
|
||||
}else{
|
||||
/* Figure out the db that the the trigger will be created in */
|
||||
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
|
||||
if( iDb<0 ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the trigger name was unqualified, and the table is a temp table,
|
||||
** then set iDb to 1 to create the trigger in the temporary database.
|
||||
** If sqlite3SrcListLookup() returns 0, indicating the table does not
|
||||
** exist, the error is caught by the block below.
|
||||
/* Check that:
|
||||
** 1. the trigger name does not already exist.
|
||||
** 2. the table (or view) does exist in the same database as the trigger.
|
||||
** 3. that we are not trying to create a trigger on the sqlite_master table
|
||||
** 4. That we are not trying to create an INSTEAD OF trigger on a table.
|
||||
** 5. That we are not trying to create a BEFORE or AFTER trigger on a view.
|
||||
*/
|
||||
if( !pTableName || sqlite3_malloc_failed ) goto trigger_cleanup;
|
||||
pTab = sqlite3SrcListLookup(pParse, pTableName);
|
||||
if( pName2->n==0 && pTab && pTab->iDb==1 ){
|
||||
iDb = 1;
|
||||
}
|
||||
|
||||
/* Ensure the table name matches database name and that the table exists */
|
||||
if( sqlite3_malloc_failed ) goto trigger_cleanup;
|
||||
if( sqlite_malloc_failed ) goto trigger_cleanup;
|
||||
assert( pTableName->nSrc==1 );
|
||||
if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) &&
|
||||
sqlite3FixSrcList(&sFix, pTableName) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
pTab = sqlite3SrcListLookup(pParse, pTableName);
|
||||
if( !pTab ){
|
||||
/* The table does not exist. */
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
|
||||
/* Check that the trigger name is not reserved and that no trigger of the
|
||||
** specified name exists */
|
||||
zName = sqlite3NameFromToken(pName);
|
||||
if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqlite3HashFind(&(db->aDb[iDb].trigHash), zName,pName->n+1) ){
|
||||
sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
|
||||
/* Do not create a trigger on a system table */
|
||||
if( (iDb!=1 && sqlite3StrICmp(pTab->zName, MASTER_NAME)==0) ||
|
||||
(iDb==1 && sqlite3StrICmp(pTab->zName, TEMP_MASTER_NAME)==0)
|
||||
if( db->init.busy
|
||||
&& sqliteFixInit(&sFix, pParse, db->init.iDb, "trigger", pName)
|
||||
&& sqliteFixSrcList(&sFix, pTableName)
|
||||
){
|
||||
sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
tab = sqliteSrcListLookup(pParse, pTableName);
|
||||
if( !tab ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
iDb = isTemp ? 1 : tab->iDb;
|
||||
if( iDb>=2 && !db->init.busy ){
|
||||
sqliteErrorMsg(pParse, "triggers may not be added to auxiliary "
|
||||
"database %s", db->aDb[tab->iDb].zName);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
|
||||
zName = sqliteStrNDup(pName->z, pName->n);
|
||||
sqliteDequote(zName);
|
||||
if( sqliteHashFind(&(db->aDb[iDb].trigHash), zName,pName->n+1) ){
|
||||
sqliteErrorMsg(pParse, "trigger %T already exists", pName);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqliteStrNICmp(tab->zName, "sqlite_", 7)==0 ){
|
||||
sqliteErrorMsg(pParse, "cannot create trigger on system table");
|
||||
pParse->nErr++;
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
|
||||
/* INSTEAD of triggers are only for views and views only support INSTEAD
|
||||
** of triggers.
|
||||
*/
|
||||
if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
|
||||
sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
|
||||
if( tab->pSelect && tr_tm != TK_INSTEAD ){
|
||||
sqliteErrorMsg(pParse, "cannot create %s trigger on view: %S",
|
||||
(tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
|
||||
sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
|
||||
if( !tab->pSelect && tr_tm == TK_INSTEAD ){
|
||||
sqliteErrorMsg(pParse, "cannot create INSTEAD OF"
|
||||
" trigger on table: %S", pTableName, 0);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
int code = SQLITE_CREATE_TRIGGER;
|
||||
const char *zDb = db->aDb[pTab->iDb].zName;
|
||||
const char *zDb = db->aDb[tab->iDb].zName;
|
||||
const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
|
||||
if( pTab->iDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
|
||||
if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
|
||||
if( tab->iDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
|
||||
if( sqliteAuthCheck(pParse, code, zName, tab->zName, zDbTrig) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(pTab->iDb),0,zDb)){
|
||||
if( sqliteAuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(tab->iDb), 0, zDb)){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* INSTEAD OF triggers can only appear on views and BEFORE triggers
|
||||
/* INSTEAD OF triggers can only appear on views and BEGIN triggers
|
||||
** cannot appear on views. So we might as well translate every
|
||||
** INSTEAD OF trigger into a BEFORE trigger. It simplifies code
|
||||
** elsewhere.
|
||||
@@ -157,35 +128,35 @@ void sqlite3BeginTrigger(
|
||||
}
|
||||
|
||||
/* Build the Trigger object */
|
||||
pTrigger = (Trigger*)sqliteMalloc(sizeof(Trigger));
|
||||
if( pTrigger==0 ) goto trigger_cleanup;
|
||||
pTrigger->name = zName;
|
||||
nt = (Trigger*)sqliteMalloc(sizeof(Trigger));
|
||||
if( nt==0 ) goto trigger_cleanup;
|
||||
nt->name = zName;
|
||||
zName = 0;
|
||||
pTrigger->table = sqliteStrDup(pTableName->a[0].zName);
|
||||
if( sqlite3_malloc_failed ) goto trigger_cleanup;
|
||||
pTrigger->iDb = iDb;
|
||||
pTrigger->iTabDb = pTab->iDb;
|
||||
pTrigger->op = op;
|
||||
pTrigger->tr_tm = tr_tm;
|
||||
pTrigger->pWhen = sqlite3ExprDup(pWhen);
|
||||
pTrigger->pColumns = sqlite3IdListDup(pColumns);
|
||||
pTrigger->foreach = foreach;
|
||||
sqlite3TokenCopy(&pTrigger->nameToken,pName);
|
||||
nt->table = sqliteStrDup(pTableName->a[0].zName);
|
||||
if( sqlite_malloc_failed ) goto trigger_cleanup;
|
||||
nt->iDb = iDb;
|
||||
nt->iTabDb = tab->iDb;
|
||||
nt->op = op;
|
||||
nt->tr_tm = tr_tm;
|
||||
nt->pWhen = sqliteExprDup(pWhen);
|
||||
nt->pColumns = sqliteIdListDup(pColumns);
|
||||
nt->foreach = foreach;
|
||||
sqliteTokenCopy(&nt->nameToken,pName);
|
||||
assert( pParse->pNewTrigger==0 );
|
||||
pParse->pNewTrigger = pTrigger;
|
||||
pParse->pNewTrigger = nt;
|
||||
|
||||
trigger_cleanup:
|
||||
sqliteFree(zName);
|
||||
sqlite3SrcListDelete(pTableName);
|
||||
sqlite3IdListDelete(pColumns);
|
||||
sqlite3ExprDelete(pWhen);
|
||||
sqliteSrcListDelete(pTableName);
|
||||
sqliteIdListDelete(pColumns);
|
||||
sqliteExprDelete(pWhen);
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called after all of the trigger actions have been parsed
|
||||
** in order to complete the process of building the trigger.
|
||||
*/
|
||||
void sqlite3FinishTrigger(
|
||||
void sqliteFinishTrigger(
|
||||
Parse *pParse, /* Parser context */
|
||||
TriggerStep *pStepList, /* The triggered program */
|
||||
Token *pAll /* Token that describes the complete CREATE TRIGGER */
|
||||
@@ -202,8 +173,8 @@ void sqlite3FinishTrigger(
|
||||
pStepList->pTrig = nt;
|
||||
pStepList = pStepList->pNext;
|
||||
}
|
||||
if( sqlite3FixInit(&sFix, pParse, nt->iDb, "trigger", &nt->nameToken)
|
||||
&& sqlite3FixTriggerStep(&sFix, nt->step_list) ){
|
||||
if( sqliteFixInit(&sFix, pParse, nt->iDb, "trigger", &nt->nameToken)
|
||||
&& sqliteFixTriggerStep(&sFix, nt->step_list) ){
|
||||
goto triggerfinish_cleanup;
|
||||
}
|
||||
|
||||
@@ -213,42 +184,38 @@ void sqlite3FinishTrigger(
|
||||
if( !db->init.busy ){
|
||||
static VdbeOpList insertTrig[] = {
|
||||
{ OP_NewRecno, 0, 0, 0 },
|
||||
{ OP_String8, 0, 0, "trigger" },
|
||||
{ OP_String8, 0, 0, 0 }, /* 2: trigger name */
|
||||
{ OP_String8, 0, 0, 0 }, /* 3: table name */
|
||||
{ OP_String, 0, 0, "trigger" },
|
||||
{ OP_String, 0, 0, 0 }, /* 2: trigger name */
|
||||
{ OP_String, 0, 0, 0 }, /* 3: table name */
|
||||
{ OP_Integer, 0, 0, 0 },
|
||||
{ OP_String8, 0, 0, "CREATE TRIGGER "},
|
||||
{ OP_String8, 0, 0, 0 }, /* 6: SQL */
|
||||
{ OP_Concat, 0, 0, 0 },
|
||||
{ OP_MakeRecord, 5, 0, "tttit" },
|
||||
{ OP_String, 0, 0, 0 }, /* 5: SQL */
|
||||
{ OP_MakeRecord, 5, 0, 0 },
|
||||
{ OP_PutIntKey, 0, 0, 0 },
|
||||
};
|
||||
int addr;
|
||||
Vdbe *v;
|
||||
|
||||
/* Make an entry in the sqlite_master table */
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
v = sqliteGetVdbe(pParse);
|
||||
if( v==0 ) goto triggerfinish_cleanup;
|
||||
sqlite3BeginWriteOperation(pParse, 0, nt->iDb);
|
||||
sqlite3OpenMasterTable(v, nt->iDb);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(insertTrig), insertTrig);
|
||||
sqlite3VdbeChangeP3(v, addr+2, nt->name, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+3, nt->table, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+6, pAll->z, pAll->n);
|
||||
if( nt->iDb!=0 ){
|
||||
sqlite3ChangeCookie(db, v, nt->iDb);
|
||||
sqliteBeginWriteOperation(pParse, 0, 0);
|
||||
sqliteOpenMasterTable(v, nt->iDb);
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(insertTrig), insertTrig);
|
||||
sqliteVdbeChangeP3(v, addr+2, nt->name, 0);
|
||||
sqliteVdbeChangeP3(v, addr+3, nt->table, 0);
|
||||
sqliteVdbeChangeP3(v, addr+5, pAll->z, pAll->n);
|
||||
if( nt->iDb==0 ){
|
||||
sqliteChangeCookie(db, v);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, nt->iDb, 0,
|
||||
sqlite3MPrintf("type='trigger' AND name='%q'", nt->name), P3_DYNAMIC);
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
sqliteVdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
}
|
||||
|
||||
if( db->init.busy ){
|
||||
if( !pParse->explain ){
|
||||
Table *pTab;
|
||||
sqlite3HashInsert(&db->aDb[nt->iDb].trigHash,
|
||||
sqliteHashInsert(&db->aDb[nt->iDb].trigHash,
|
||||
nt->name, strlen(nt->name)+1, nt);
|
||||
pTab = sqlite3LocateTable(pParse, nt->table, db->aDb[nt->iTabDb].zName);
|
||||
pTab = sqliteLocateTable(pParse, nt->table, db->aDb[nt->iTabDb].zName);
|
||||
assert( pTab!=0 );
|
||||
nt->pNext = pTab->pTrigger;
|
||||
pTab->pTrigger = nt;
|
||||
@@ -256,10 +223,10 @@ void sqlite3FinishTrigger(
|
||||
}
|
||||
|
||||
triggerfinish_cleanup:
|
||||
sqlite3DeleteTrigger(nt);
|
||||
sqlite3DeleteTrigger(pParse->pNewTrigger);
|
||||
sqliteDeleteTrigger(nt);
|
||||
sqliteDeleteTrigger(pParse->pNewTrigger);
|
||||
pParse->pNewTrigger = 0;
|
||||
sqlite3DeleteTriggerStep(pStepList);
|
||||
sqliteDeleteTriggerStep(pStepList);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -267,10 +234,10 @@ triggerfinish_cleanup:
|
||||
** the effect of copying all Expr.token.z values into memory obtained
|
||||
** from sqliteMalloc(). As initially created, the Expr.token.z values
|
||||
** all point to the input string that was fed to the parser. But that
|
||||
** string is ephemeral - it will go away as soon as the sqlite3_exec()
|
||||
** string is ephemeral - it will go away as soon as the sqlite_exec()
|
||||
** call that started the parser exits. This routine makes a persistent
|
||||
** copy of all the Expr.token.z strings so that the TriggerStep structure
|
||||
** will be valid even after the sqlite3_exec() call returns.
|
||||
** will be valid even after the sqlite_exec() call returns.
|
||||
*/
|
||||
static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
if( p->target.z ){
|
||||
@@ -278,23 +245,23 @@ static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
p->target.dyn = 1;
|
||||
}
|
||||
if( p->pSelect ){
|
||||
Select *pNew = sqlite3SelectDup(p->pSelect);
|
||||
sqlite3SelectDelete(p->pSelect);
|
||||
Select *pNew = sqliteSelectDup(p->pSelect);
|
||||
sqliteSelectDelete(p->pSelect);
|
||||
p->pSelect = pNew;
|
||||
}
|
||||
if( p->pWhere ){
|
||||
Expr *pNew = sqlite3ExprDup(p->pWhere);
|
||||
sqlite3ExprDelete(p->pWhere);
|
||||
Expr *pNew = sqliteExprDup(p->pWhere);
|
||||
sqliteExprDelete(p->pWhere);
|
||||
p->pWhere = pNew;
|
||||
}
|
||||
if( p->pExprList ){
|
||||
ExprList *pNew = sqlite3ExprListDup(p->pExprList);
|
||||
sqlite3ExprListDelete(p->pExprList);
|
||||
ExprList *pNew = sqliteExprListDup(p->pExprList);
|
||||
sqliteExprListDelete(p->pExprList);
|
||||
p->pExprList = pNew;
|
||||
}
|
||||
if( p->pIdList ){
|
||||
IdList *pNew = sqlite3IdListDup(p->pIdList);
|
||||
sqlite3IdListDelete(p->pIdList);
|
||||
IdList *pNew = sqliteIdListDup(p->pIdList);
|
||||
sqliteIdListDelete(p->pIdList);
|
||||
p->pIdList = pNew;
|
||||
}
|
||||
}
|
||||
@@ -306,7 +273,7 @@ static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
** The parser calls this routine when it finds a SELECT statement in
|
||||
** body of a TRIGGER.
|
||||
*/
|
||||
TriggerStep *sqlite3TriggerSelectStep(Select *pSelect){
|
||||
TriggerStep *sqliteTriggerSelectStep(Select *pSelect){
|
||||
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
|
||||
if( pTriggerStep==0 ) return 0;
|
||||
|
||||
@@ -325,7 +292,7 @@ TriggerStep *sqlite3TriggerSelectStep(Select *pSelect){
|
||||
** The parser calls this routine when it sees an INSERT inside the
|
||||
** body of a trigger.
|
||||
*/
|
||||
TriggerStep *sqlite3TriggerInsertStep(
|
||||
TriggerStep *sqliteTriggerInsertStep(
|
||||
Token *pTableName, /* Name of the table into which we insert */
|
||||
IdList *pColumn, /* List of columns in pTableName to insert into */
|
||||
ExprList *pEList, /* The VALUE clause: a list of values to be inserted */
|
||||
@@ -354,7 +321,7 @@ TriggerStep *sqlite3TriggerInsertStep(
|
||||
** a pointer to that trigger step. The parser calls this routine when it
|
||||
** sees an UPDATE statement inside the body of a CREATE TRIGGER.
|
||||
*/
|
||||
TriggerStep *sqlite3TriggerUpdateStep(
|
||||
TriggerStep *sqliteTriggerUpdateStep(
|
||||
Token *pTableName, /* Name of the table to be updated */
|
||||
ExprList *pEList, /* The SET clause: list of column and new values */
|
||||
Expr *pWhere, /* The WHERE clause */
|
||||
@@ -378,7 +345,7 @@ TriggerStep *sqlite3TriggerUpdateStep(
|
||||
** a pointer to that trigger step. The parser calls this routine when it
|
||||
** sees a DELETE statement inside the body of a CREATE TRIGGER.
|
||||
*/
|
||||
TriggerStep *sqlite3TriggerDeleteStep(Token *pTableName, Expr *pWhere){
|
||||
TriggerStep *sqliteTriggerDeleteStep(Token *pTableName, Expr *pWhere){
|
||||
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
|
||||
if( pTriggerStep==0 ) return 0;
|
||||
|
||||
@@ -394,91 +361,86 @@ TriggerStep *sqlite3TriggerDeleteStep(Token *pTableName, Expr *pWhere){
|
||||
/*
|
||||
** Recursively delete a Trigger structure
|
||||
*/
|
||||
void sqlite3DeleteTrigger(Trigger *pTrigger){
|
||||
void sqliteDeleteTrigger(Trigger *pTrigger){
|
||||
if( pTrigger==0 ) return;
|
||||
sqlite3DeleteTriggerStep(pTrigger->step_list);
|
||||
sqliteDeleteTriggerStep(pTrigger->step_list);
|
||||
sqliteFree(pTrigger->name);
|
||||
sqliteFree(pTrigger->table);
|
||||
sqlite3ExprDelete(pTrigger->pWhen);
|
||||
sqlite3IdListDelete(pTrigger->pColumns);
|
||||
sqliteExprDelete(pTrigger->pWhen);
|
||||
sqliteIdListDelete(pTrigger->pColumns);
|
||||
if( pTrigger->nameToken.dyn ) sqliteFree((char*)pTrigger->nameToken.z);
|
||||
sqliteFree(pTrigger);
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is called to drop a trigger from the database schema.
|
||||
**
|
||||
** This may be called directly from the parser and therefore identifies
|
||||
** the trigger by name. The sqlite3DropTriggerPtr() routine does the
|
||||
** same job as this routine except it takes a pointer to the trigger
|
||||
** instead of the trigger name.
|
||||
**/
|
||||
void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
|
||||
Trigger *pTrigger = 0;
|
||||
* This function is called to drop a trigger from the database schema.
|
||||
*
|
||||
* This may be called directly from the parser and therefore identifies
|
||||
* the trigger by name. The sqliteDropTriggerPtr() routine does the
|
||||
* same job as this routine except it take a spointer to the trigger
|
||||
* instead of the trigger name.
|
||||
*
|
||||
* Note that this function does not delete the trigger entirely. Instead it
|
||||
* removes it from the internal schema and places it in the trigDrop hash
|
||||
* table. This is so that the trigger can be restored into the database schema
|
||||
* if the transaction is rolled back.
|
||||
*/
|
||||
void sqliteDropTrigger(Parse *pParse, SrcList *pName){
|
||||
Trigger *pTrigger;
|
||||
int i;
|
||||
const char *zDb;
|
||||
const char *zName;
|
||||
int nName;
|
||||
sqlite *db = pParse->db;
|
||||
|
||||
if( sqlite3_malloc_failed ) goto drop_trigger_cleanup;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
|
||||
goto drop_trigger_cleanup;
|
||||
}
|
||||
|
||||
if( sqlite_malloc_failed ) goto drop_trigger_cleanup;
|
||||
assert( pName->nSrc==1 );
|
||||
zDb = pName->a[0].zDatabase;
|
||||
zName = pName->a[0].zName;
|
||||
nName = strlen(zName);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
|
||||
if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
|
||||
pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1);
|
||||
if( zDb && sqliteStrICmp(db->aDb[j].zName, zDb) ) continue;
|
||||
pTrigger = sqliteHashFind(&(db->aDb[j].trigHash), zName, nName+1);
|
||||
if( pTrigger ) break;
|
||||
}
|
||||
if( !pTrigger ){
|
||||
sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
|
||||
sqliteErrorMsg(pParse, "no such trigger: %S", pName, 0);
|
||||
goto drop_trigger_cleanup;
|
||||
}
|
||||
sqlite3DropTriggerPtr(pParse, pTrigger, 0);
|
||||
sqliteDropTriggerPtr(pParse, pTrigger, 0);
|
||||
|
||||
drop_trigger_cleanup:
|
||||
sqlite3SrcListDelete(pName);
|
||||
sqliteSrcListDelete(pName);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return a pointer to the Table structure for the table that a trigger
|
||||
** is set on.
|
||||
*/
|
||||
static Table *tableOfTrigger(sqlite3 *db, Trigger *pTrigger){
|
||||
return sqlite3FindTable(db,pTrigger->table,db->aDb[pTrigger->iTabDb].zName);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Drop a trigger given a pointer to that trigger. If nested is false,
|
||||
** then also generate code to remove the trigger from the SQLITE_MASTER
|
||||
** table.
|
||||
*/
|
||||
void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
void sqliteDropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
Table *pTable;
|
||||
Vdbe *v;
|
||||
sqlite *db = pParse->db;
|
||||
int iDb;
|
||||
|
||||
iDb = pTrigger->iDb;
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
pTable = tableOfTrigger(db, pTrigger);
|
||||
assert( pTrigger->iDb<db->nDb );
|
||||
if( pTrigger->iDb>=2 ){
|
||||
sqliteErrorMsg(pParse, "triggers may not be removed from "
|
||||
"auxiliary database %s", db->aDb[pTrigger->iDb].zName);
|
||||
return;
|
||||
}
|
||||
pTable = sqliteFindTable(db, pTrigger->table,db->aDb[pTrigger->iTabDb].zName);
|
||||
assert(pTable);
|
||||
assert( pTable->iDb==iDb || iDb==1 );
|
||||
assert( pTable->iDb==pTrigger->iDb || pTrigger->iDb==1 );
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
int code = SQLITE_DROP_TRIGGER;
|
||||
const char *zDb = db->aDb[iDb].zName;
|
||||
const char *zTab = SCHEMA_TABLE(iDb);
|
||||
if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
|
||||
if( sqlite3AuthCheck(pParse, code, pTrigger->name, pTable->zName, zDb) ||
|
||||
sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
|
||||
const char *zDb = db->aDb[pTrigger->iDb].zName;
|
||||
const char *zTab = SCHEMA_TABLE(pTrigger->iDb);
|
||||
if( pTrigger->iDb ) code = SQLITE_DROP_TEMP_TRIGGER;
|
||||
if( sqliteAuthCheck(pParse, code, pTrigger->name, pTable->zName, zDb) ||
|
||||
sqliteAuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -486,40 +448,37 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
|
||||
/* Generate code to destroy the database record of the trigger.
|
||||
*/
|
||||
if( pTable!=0 && (v = sqlite3GetVdbe(pParse))!=0 ){
|
||||
if( pTable!=0 && !nested && (v = sqliteGetVdbe(pParse))!=0 ){
|
||||
int base;
|
||||
static VdbeOpList dropTrigger[] = {
|
||||
{ OP_Rewind, 0, ADDR(9), 0},
|
||||
{ OP_String8, 0, 0, 0}, /* 1 */
|
||||
{ OP_String, 0, 0, 0}, /* 1 */
|
||||
{ OP_Column, 0, 1, 0},
|
||||
{ OP_Ne, 0, ADDR(8), 0},
|
||||
{ OP_String8, 0, 0, "trigger"},
|
||||
{ OP_String, 0, 0, "trigger"},
|
||||
{ OP_Column, 0, 0, 0},
|
||||
{ OP_Ne, 0, ADDR(8), 0},
|
||||
{ OP_Delete, 0, 0, 0},
|
||||
{ OP_Next, 0, ADDR(1), 0}, /* 8 */
|
||||
};
|
||||
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
sqlite3OpenMasterTable(v, iDb);
|
||||
base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
|
||||
sqlite3VdbeChangeP3(v, base+1, pTrigger->name, 0);
|
||||
sqlite3ChangeCookie(db, v, iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqlite3VdbeOp3(v, OP_DropTrigger, iDb, 0, pTrigger->name, 0);
|
||||
sqliteBeginWriteOperation(pParse, 0, 0);
|
||||
sqliteOpenMasterTable(v, pTrigger->iDb);
|
||||
base = sqliteVdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
|
||||
sqliteVdbeChangeP3(v, base+1, pTrigger->name, 0);
|
||||
if( pTrigger->iDb==0 ){
|
||||
sqliteChangeCookie(db, v);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Remove a trigger from the hash tables of the sqlite* pointer.
|
||||
*/
|
||||
void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
|
||||
Trigger *pTrigger;
|
||||
int nName = strlen(zName);
|
||||
pTrigger = sqlite3HashInsert(&(db->aDb[iDb].trigHash), zName, nName+1, 0);
|
||||
if( pTrigger ){
|
||||
Table *pTable = tableOfTrigger(db, pTrigger);
|
||||
assert( pTable!=0 );
|
||||
/*
|
||||
* If this is not an "explain", then delete the trigger structure.
|
||||
*/
|
||||
if( !pParse->explain ){
|
||||
const char *zName = pTrigger->name;
|
||||
int nName = strlen(zName);
|
||||
if( pTable->pTrigger == pTrigger ){
|
||||
pTable->pTrigger = pTrigger->pNext;
|
||||
}else{
|
||||
@@ -533,8 +492,8 @@ void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
|
||||
}
|
||||
assert(cc);
|
||||
}
|
||||
sqlite3DeleteTrigger(pTrigger);
|
||||
db->flags |= SQLITE_InternChanges;
|
||||
sqliteHashInsert(&(db->aDb[pTrigger->iDb].trigHash), zName, nName+1, 0);
|
||||
sqliteDeleteTrigger(pTrigger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,7 +510,7 @@ static int checkColumnOverLap(IdList *pIdList, ExprList *pEList){
|
||||
int e;
|
||||
if( !pIdList || !pEList ) return 1;
|
||||
for(e=0; e<pEList->nExpr; e++){
|
||||
if( sqlite3IdListIndex(pIdList, pEList->a[e].zName)>=0 ) return 1;
|
||||
if( sqliteIdListIndex(pIdList, pEList->a[e].zName)>=0 ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -564,14 +523,14 @@ static int checkColumnOverLap(IdList *pIdList, ExprList *pEList){
|
||||
* The pragma is not documented since it is not really part of the interface
|
||||
* to SQLite, just the test procedure.
|
||||
*/
|
||||
int sqlite3_always_code_trigger_setup = 0;
|
||||
int always_code_trigger_setup = 0;
|
||||
|
||||
/*
|
||||
* Returns true if a trigger matching op, tr_tm and foreach that is NOT already
|
||||
* on the Parse objects trigger-stack (to prevent recursive trigger firing) is
|
||||
* found in the list specified as pTrigger.
|
||||
*/
|
||||
int sqlite3TriggersExist(
|
||||
int sqliteTriggersExist(
|
||||
Parse *pParse, /* Used to check for recursive triggers */
|
||||
Trigger *pTrigger, /* A list of triggers associated with a table */
|
||||
int op, /* one of TK_DELETE, TK_INSERT, TK_UPDATE */
|
||||
@@ -581,7 +540,7 @@ int sqlite3TriggersExist(
|
||||
){
|
||||
Trigger * pTriggerCursor;
|
||||
|
||||
if( sqlite3_always_code_trigger_setup ){
|
||||
if( always_code_trigger_setup ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -627,9 +586,9 @@ static SrcList *targetSrcList(
|
||||
assert( iDb<pParse->db->nDb );
|
||||
sDb.z = pParse->db->aDb[iDb].zName;
|
||||
sDb.n = strlen(sDb.z);
|
||||
pSrc = sqlite3SrcListAppend(0, &sDb, &pStep->target);
|
||||
pSrc = sqliteSrcListAppend(0, &sDb, &pStep->target);
|
||||
} else {
|
||||
pSrc = sqlite3SrcListAppend(0, &pStep->target, 0);
|
||||
pSrc = sqliteSrcListAppend(0, &pStep->target, 0);
|
||||
}
|
||||
return pSrc;
|
||||
}
|
||||
@@ -647,53 +606,50 @@ static int codeTriggerProgram(
|
||||
int orconf;
|
||||
|
||||
while( pTriggerStep ){
|
||||
int saveNTab = pParse->nTab;
|
||||
|
||||
orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
|
||||
pParse->trigStack->orconf = orconf;
|
||||
switch( pTriggerStep->op ){
|
||||
case TK_SELECT: {
|
||||
Select * ss = sqlite3SelectDup(pTriggerStep->pSelect);
|
||||
Select * ss = sqliteSelectDup(pTriggerStep->pSelect);
|
||||
assert(ss);
|
||||
assert(ss->pSrc);
|
||||
sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(ss);
|
||||
sqliteSelect(pParse, ss, SRT_Discard, 0, 0, 0, 0);
|
||||
sqliteSelectDelete(ss);
|
||||
break;
|
||||
}
|
||||
case TK_UPDATE: {
|
||||
SrcList *pSrc;
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 0, 0);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
|
||||
sqlite3Update(pParse, pSrc,
|
||||
sqlite3ExprListDup(pTriggerStep->pExprList),
|
||||
sqlite3ExprDup(pTriggerStep->pWhere), orconf);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 1, 0);
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
|
||||
sqliteUpdate(pParse, pSrc,
|
||||
sqliteExprListDup(pTriggerStep->pExprList),
|
||||
sqliteExprDup(pTriggerStep->pWhere), orconf);
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
|
||||
break;
|
||||
}
|
||||
case TK_INSERT: {
|
||||
SrcList *pSrc;
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 0, 0);
|
||||
sqlite3Insert(pParse, pSrc,
|
||||
sqlite3ExprListDup(pTriggerStep->pExprList),
|
||||
sqlite3SelectDup(pTriggerStep->pSelect),
|
||||
sqlite3IdListDup(pTriggerStep->pIdList), orconf);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 1, 0);
|
||||
sqliteInsert(pParse, pSrc,
|
||||
sqliteExprListDup(pTriggerStep->pExprList),
|
||||
sqliteSelectDup(pTriggerStep->pSelect),
|
||||
sqliteIdListDup(pTriggerStep->pIdList), orconf);
|
||||
break;
|
||||
}
|
||||
case TK_DELETE: {
|
||||
SrcList *pSrc;
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 0, 0);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqlite3DeleteFrom(pParse, pSrc, sqlite3ExprDup(pTriggerStep->pWhere));
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 1, 0);
|
||||
sqliteDeleteFrom(pParse, pSrc, sqliteExprDup(pTriggerStep->pWhere));
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
pParse->nTab = saveNTab;
|
||||
pTriggerStep = pTriggerStep->pNext;
|
||||
}
|
||||
|
||||
@@ -720,7 +676,7 @@ static int codeTriggerProgram(
|
||||
** trigger program(s).
|
||||
**
|
||||
*/
|
||||
int sqlite3CodeRowTrigger(
|
||||
int sqliteCodeRowTrigger(
|
||||
Parse *pParse, /* Parse context */
|
||||
int op, /* One of TK_UPDATE, TK_INSERT, TK_DELETE */
|
||||
ExprList *pChanges, /* Changes list for any UPDATE OF triggers */
|
||||
@@ -776,32 +732,33 @@ int sqlite3CodeRowTrigger(
|
||||
pTriggerStack->pNext = pParse->trigStack;
|
||||
pTriggerStack->ignoreJump = ignoreJump;
|
||||
pParse->trigStack = pTriggerStack;
|
||||
sqlite3AuthContextPush(pParse, &sContext, pTrigger->name);
|
||||
sqliteAuthContextPush(pParse, &sContext, pTrigger->name);
|
||||
|
||||
/* code the WHEN clause */
|
||||
endTrigger = sqlite3VdbeMakeLabel(pParse->pVdbe);
|
||||
whenExpr = sqlite3ExprDup(pTrigger->pWhen);
|
||||
if( sqlite3ExprResolveIds(pParse, &dummyTablist, 0, whenExpr) ){
|
||||
endTrigger = sqliteVdbeMakeLabel(pParse->pVdbe);
|
||||
whenExpr = sqliteExprDup(pTrigger->pWhen);
|
||||
if( sqliteExprResolveIds(pParse, &dummyTablist, 0, whenExpr) ){
|
||||
pParse->trigStack = pParse->trigStack->pNext;
|
||||
sqliteFree(pTriggerStack);
|
||||
sqlite3ExprDelete(whenExpr);
|
||||
sqliteExprDelete(whenExpr);
|
||||
return 1;
|
||||
}
|
||||
sqlite3ExprIfFalse(pParse, whenExpr, endTrigger, 1);
|
||||
sqlite3ExprDelete(whenExpr);
|
||||
sqliteExprIfFalse(pParse, whenExpr, endTrigger, 1);
|
||||
sqliteExprDelete(whenExpr);
|
||||
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ContextPush, 0, 0);
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ContextPush, 0, 0);
|
||||
codeTriggerProgram(pParse, pTrigger->step_list, orconf);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ContextPop, 0, 0);
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ContextPop, 0, 0);
|
||||
|
||||
/* Pop the entry off the trigger stack */
|
||||
pParse->trigStack = pParse->trigStack->pNext;
|
||||
sqlite3AuthContextPop(&sContext);
|
||||
sqliteAuthContextPop(&sContext);
|
||||
sqliteFree(pTriggerStack);
|
||||
|
||||
sqlite3VdbeResolveLabel(pParse->pVdbe, endTrigger);
|
||||
sqliteVdbeResolveLabel(pParse->pVdbe, endTrigger);
|
||||
}
|
||||
pTrigger = pTrigger->pNext;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+108
-103
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle UPDATE statements.
|
||||
**
|
||||
** $Id: update.c,v 1.87 2004/08/31 13:45:12 drh Exp $
|
||||
** $Id: update.c,v 1.70.2.1 2004/04/29 16:16:29 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
** \_______/ \________/ \______/ \________________/
|
||||
* onError pTabList pChanges pWhere
|
||||
*/
|
||||
void sqlite3Update(
|
||||
void sqliteUpdate(
|
||||
Parse *pParse, /* The parser context */
|
||||
SrcList *pTabList, /* The table in which we should change things */
|
||||
ExprList *pChanges, /* Things to be changed */
|
||||
@@ -32,7 +32,8 @@ void sqlite3Update(
|
||||
){
|
||||
int i, j; /* Loop counters */
|
||||
Table *pTab; /* The table to be updated */
|
||||
int addr = 0; /* VDBE instruction address of the start of the loop */
|
||||
int loopStart; /* VDBE instruction address of the start of the loop */
|
||||
int jumpInst; /* Addr of VDBE instruction to jump out of loop */
|
||||
WhereInfo *pWInfo; /* Information about the WHERE clause */
|
||||
Vdbe *v; /* The virtual database engine */
|
||||
Index *pIdx; /* For looping over indices */
|
||||
@@ -46,9 +47,10 @@ void sqlite3Update(
|
||||
** an expression for the i-th column of the table.
|
||||
** aXRef[i]==-1 if the i-th column is not changed. */
|
||||
int chngRecno; /* True if the record number is being changed */
|
||||
Expr *pRecnoExpr = 0; /* Expression defining the new record number */
|
||||
int openAll = 0; /* True if all indices need to be opened */
|
||||
Expr *pRecnoExpr; /* Expression defining the new record number */
|
||||
int openAll; /* True if all indices need to be opened */
|
||||
int isView; /* Trying to update a view */
|
||||
int iStackDepth; /* Index of memory cell holding stack depth */
|
||||
AuthContext sContext; /* The authorization context */
|
||||
|
||||
int before_triggers; /* True if there are any BEFORE triggers */
|
||||
@@ -59,29 +61,30 @@ void sqlite3Update(
|
||||
int oldIdx = -1; /* index of trigger "old" temp table */
|
||||
|
||||
sContext.pParse = 0;
|
||||
if( pParse->nErr || sqlite3_malloc_failed ) goto update_cleanup;
|
||||
if( pParse->nErr || sqlite_malloc_failed ) goto update_cleanup;
|
||||
db = pParse->db;
|
||||
assert( pTabList->nSrc==1 );
|
||||
iStackDepth = pParse->nMem++;
|
||||
|
||||
/* Locate the table which we want to update.
|
||||
*/
|
||||
pTab = sqlite3SrcListLookup(pParse, pTabList);
|
||||
pTab = sqliteSrcListLookup(pParse, pTabList);
|
||||
if( pTab==0 ) goto update_cleanup;
|
||||
before_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger,
|
||||
before_triggers = sqliteTriggersExist(pParse, pTab->pTrigger,
|
||||
TK_UPDATE, TK_BEFORE, TK_ROW, pChanges);
|
||||
after_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger,
|
||||
after_triggers = sqliteTriggersExist(pParse, pTab->pTrigger,
|
||||
TK_UPDATE, TK_AFTER, TK_ROW, pChanges);
|
||||
row_triggers_exist = before_triggers || after_triggers;
|
||||
isView = pTab->pSelect!=0;
|
||||
if( sqlite3IsReadOnly(pParse, pTab, before_triggers) ){
|
||||
if( sqliteIsReadOnly(pParse, pTab, before_triggers) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( isView ){
|
||||
if( sqlite3ViewGetColumnNames(pParse, pTab) ){
|
||||
if( sqliteViewGetColumnNames(pParse, pTab) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
aXRef = sqliteMallocRaw( sizeof(int) * pTab->nCol );
|
||||
aXRef = sqliteMalloc( sizeof(int) * pTab->nCol );
|
||||
if( aXRef==0 ) goto update_cleanup;
|
||||
for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
|
||||
|
||||
@@ -111,12 +114,14 @@ void sqlite3Update(
|
||||
*/
|
||||
chngRecno = 0;
|
||||
for(i=0; i<pChanges->nExpr; i++){
|
||||
if( sqlite3ExprResolveAndCheck(pParse, pTabList, 0,
|
||||
pChanges->a[i].pExpr, 0, 0) ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, 0, pChanges->a[i].pExpr) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pChanges->a[i].pExpr, 0, 0) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
for(j=0; j<pTab->nCol; j++){
|
||||
if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
|
||||
if( sqliteStrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
|
||||
if( j==pTab->iPKey ){
|
||||
chngRecno = 1;
|
||||
pRecnoExpr = pChanges->a[i].pExpr;
|
||||
@@ -126,18 +131,18 @@ void sqlite3Update(
|
||||
}
|
||||
}
|
||||
if( j>=pTab->nCol ){
|
||||
if( sqlite3IsRowid(pChanges->a[i].zName) ){
|
||||
if( sqliteIsRowid(pChanges->a[i].zName) ){
|
||||
chngRecno = 1;
|
||||
pRecnoExpr = pChanges->a[i].pExpr;
|
||||
}else{
|
||||
sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
|
||||
sqliteErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
int rc;
|
||||
rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
|
||||
rc = sqliteAuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
|
||||
pTab->aCol[j].zName, db->aDb[pTab->iDb].zName);
|
||||
if( rc==SQLITE_DENY ){
|
||||
goto update_cleanup;
|
||||
@@ -164,7 +169,7 @@ void sqlite3Update(
|
||||
if( i<pIdx->nColumn ) nIdx++;
|
||||
}
|
||||
if( nIdxTotal>0 ){
|
||||
apIdx = sqliteMallocRaw( sizeof(Index*) * nIdx + nIdxTotal );
|
||||
apIdx = sqliteMalloc( sizeof(Index*) * nIdx + nIdxTotal );
|
||||
if( apIdx==0 ) goto update_cleanup;
|
||||
aIdxUsed = (char*)&apIdx[nIdx];
|
||||
}
|
||||
@@ -177,7 +182,6 @@ void sqlite3Update(
|
||||
}
|
||||
}
|
||||
if( i<pIdx->nColumn ){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ) goto update_cleanup;
|
||||
apIdx[nIdx++] = pIdx;
|
||||
aIdxUsed[j] = 1;
|
||||
}else{
|
||||
@@ -188,116 +192,117 @@ void sqlite3Update(
|
||||
/* Resolve the column names in all the expressions in the
|
||||
** WHERE clause.
|
||||
*/
|
||||
if( sqlite3ExprResolveAndCheck(pParse, pTabList, 0, pWhere, 0, 0) ){
|
||||
goto update_cleanup;
|
||||
if( pWhere ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, 0, pWhere) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Start the view context
|
||||
*/
|
||||
if( isView ){
|
||||
sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
|
||||
sqliteAuthContextPush(pParse, &sContext, pTab->zName);
|
||||
}
|
||||
|
||||
/* Begin generating code.
|
||||
*/
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
v = sqliteGetVdbe(pParse);
|
||||
if( v==0 ) goto update_cleanup;
|
||||
sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, 1, pTab->iDb);
|
||||
sqliteBeginWriteOperation(pParse, 1, pTab->iDb);
|
||||
|
||||
/* If we are trying to update a view, construct that view into
|
||||
** a temporary table.
|
||||
*/
|
||||
if( isView ){
|
||||
Select *pView;
|
||||
pView = sqlite3SelectDup(pTab->pSelect);
|
||||
sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(pView);
|
||||
pView = sqliteSelectDup(pTab->pSelect);
|
||||
sqliteSelect(pParse, pView, SRT_TempTable, iCur, 0, 0, 0);
|
||||
sqliteSelectDelete(pView);
|
||||
}
|
||||
|
||||
/* Begin the database scan
|
||||
*/
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 1, 0);
|
||||
pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 1, 0);
|
||||
if( pWInfo==0 ) goto update_cleanup;
|
||||
|
||||
/* Remember the index of every item to be updated.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
|
||||
/* End the database scan loop.
|
||||
*/
|
||||
sqlite3WhereEnd(pWInfo);
|
||||
sqliteWhereEnd(pWInfo);
|
||||
|
||||
/* Initialize the count of updated rows
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
}
|
||||
|
||||
if( row_triggers_exist ){
|
||||
/* Create pseudo-tables for NEW and OLD
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, oldIdx, pTab->nCol);
|
||||
sqlite3VdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol);
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
|
||||
|
||||
/* The top of the update loop for when there are triggers.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_StackDepth, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, iStackDepth, 1);
|
||||
loopStart = sqliteVdbeAddOp(v, OP_MemLoad, iStackDepth, 0);
|
||||
sqliteVdbeAddOp(v, OP_StackReset, 0, 0);
|
||||
jumpInst = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
|
||||
/* Open a cursor and make it point to the record that is
|
||||
** being updated.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
|
||||
|
||||
/* Generate the OLD table
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
|
||||
/* Generate the NEW table
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqlite3ExprCode(pParse, pRecnoExpr);
|
||||
sqliteExprCode(pParse, pRecnoExpr);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
}
|
||||
for(i=0; i<pTab->nCol; i++){ /* TODO: Factor out this loop as common code */
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
continue;
|
||||
}
|
||||
j = aXRef[i];
|
||||
if( j<0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, i);
|
||||
sqliteVdbeAddOp(v, OP_Column, iCur, i);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pChanges->a[j].pExpr);
|
||||
sqliteExprCode(pParse, pChanges->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
if( !isView ){
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
}
|
||||
if( pParse->nErr ) goto update_cleanup;
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
|
||||
/* Fire the BEFORE and INSTEAD OF triggers
|
||||
*/
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, pTab,
|
||||
newIdx, oldIdx, onError, addr) ){
|
||||
if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, pTab,
|
||||
newIdx, oldIdx, onError, loopStart) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -309,9 +314,8 @@ void sqlite3Update(
|
||||
** action, then we need to open all indices because we might need
|
||||
** to be deleting some records.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum);
|
||||
if( onError==OE_Replace ){
|
||||
openAll = 1;
|
||||
}else{
|
||||
@@ -325,9 +329,8 @@ void sqlite3Update(
|
||||
}
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
if( openAll || aIdxUsed[i] ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqlite3VdbeOp3(v, OP_OpenWrite, iCur+i+1, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenWrite, iCur+i+1, pIdx->tnum);
|
||||
assert( pParse->nTab>iCur+i+1 );
|
||||
}
|
||||
}
|
||||
@@ -339,60 +342,60 @@ void sqlite3Update(
|
||||
** So make the cursor point at the old record.
|
||||
*/
|
||||
if( !row_triggers_exist ){
|
||||
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
jumpInst = loopStart = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_NotExists, iCur, addr);
|
||||
sqliteVdbeAddOp(v, OP_NotExists, iCur, loopStart);
|
||||
|
||||
/* If the record number will change, push the record number as it
|
||||
** will be after the update. (The old record number is currently
|
||||
** on top of the stack.)
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqlite3ExprCode(pParse, pRecnoExpr);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
sqliteExprCode(pParse, pRecnoExpr);
|
||||
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}
|
||||
|
||||
/* Compute new data for this record.
|
||||
*/
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
continue;
|
||||
}
|
||||
j = aXRef[i];
|
||||
if( j<0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, i);
|
||||
sqliteVdbeAddOp(v, OP_Column, iCur, i);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pChanges->a[j].pExpr);
|
||||
sqliteExprCode(pParse, pChanges->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Do constraint checks
|
||||
*/
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1,
|
||||
onError, addr);
|
||||
sqliteGenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1,
|
||||
onError, loopStart);
|
||||
|
||||
/* Delete the old indices for the current record.
|
||||
*/
|
||||
sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, aIdxUsed);
|
||||
sqliteGenerateRowIndexDelete(db, v, pTab, iCur, aIdxUsed);
|
||||
|
||||
/* If changing the record number, delete the old record.
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqlite3VdbeAddOp(v, OP_Delete, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Delete, iCur, 0);
|
||||
}
|
||||
|
||||
/* Create the new index entries and the new record.
|
||||
*/
|
||||
sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, -1);
|
||||
sqliteCompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, -1);
|
||||
}
|
||||
|
||||
/* Increment the row counter
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack){
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
}
|
||||
|
||||
/* If there are triggers, close all the cursors after each iteration
|
||||
@@ -402,12 +405,13 @@ void sqlite3Update(
|
||||
if( !isView ){
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
if( openAll || aIdxUsed[i] )
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur+i+1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur+i+1, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
pParse->nTab = iCur;
|
||||
}
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, pTab,
|
||||
newIdx, oldIdx, onError, addr) ){
|
||||
if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, pTab,
|
||||
newIdx, oldIdx, onError, loopStart) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -415,40 +419,41 @@ void sqlite3Update(
|
||||
/* Repeat the above with the next record to be updated, until
|
||||
** all record selected by the WHERE clause have been updated.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, loopStart);
|
||||
sqliteVdbeChangeP2(v, jumpInst, sqliteVdbeCurrentAddr(v));
|
||||
sqliteVdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
|
||||
/* Close all tables if there were no FOR EACH ROW triggers */
|
||||
if( !row_triggers_exist ){
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
if( openAll || aIdxUsed[i] ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur+i+1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur+i+1, 0);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
pParse->nTab = iCur;
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Close, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Close, oldIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, newIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, oldIdx, 0);
|
||||
}
|
||||
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
sqliteVdbeAddOp(v, OP_SetCounts, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
|
||||
/*
|
||||
** Return the number of rows that were changed.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "rows updated", P3_STATIC);
|
||||
sqliteVdbeOp3(v, OP_ColumnName, 0, 1, "rows updated", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
|
||||
update_cleanup:
|
||||
sqlite3AuthContextPop(&sContext);
|
||||
sqliteAuthContextPop(&sContext);
|
||||
sqliteFree(apIdx);
|
||||
sqliteFree(aXRef);
|
||||
sqlite3SrcListDelete(pTabList);
|
||||
sqlite3ExprListDelete(pChanges);
|
||||
sqlite3ExprDelete(pWhere);
|
||||
sqliteSrcListDelete(pTabList);
|
||||
sqliteExprListDelete(pChanges);
|
||||
sqliteExprDelete(pWhere);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,569 +0,0 @@
|
||||
/*
|
||||
** 2004 April 13
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains routines used to translate between UTF-8,
|
||||
** UTF-16, UTF-16BE, and UTF-16LE.
|
||||
**
|
||||
** $Id: utf.c,v 1.28 2004/08/31 00:52:37 drh Exp $
|
||||
**
|
||||
** Notes on UTF-8:
|
||||
**
|
||||
** Byte-0 Byte-1 Byte-2 Byte-3 Value
|
||||
** 0xxxxxxx 00000000 00000000 0xxxxxxx
|
||||
** 110yyyyy 10xxxxxx 00000000 00000yyy yyxxxxxx
|
||||
** 1110zzzz 10yyyyyy 10xxxxxx 00000000 zzzzyyyy yyxxxxxx
|
||||
** 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx 000uuuuu zzzzyyyy yyxxxxxx
|
||||
**
|
||||
**
|
||||
** Notes on UTF-16: (with wwww+1==uuuuu)
|
||||
**
|
||||
** Word-0 Word-1 Value
|
||||
** 110110ww wwzzzzyy 110111yy yyxxxxxx 000uuuuu zzzzyyyy yyxxxxxx
|
||||
** zzzzyyyy yyxxxxxx 00000000 zzzzyyyy yyxxxxxx
|
||||
**
|
||||
**
|
||||
** BOM or Byte Order Mark:
|
||||
** 0xff 0xfe little-endian utf-16 follows
|
||||
** 0xfe 0xff big-endian utf-16 follows
|
||||
**
|
||||
**
|
||||
** Handling of malformed strings:
|
||||
**
|
||||
** SQLite accepts and processes malformed strings without an error wherever
|
||||
** possible. However this is not possible when converting between UTF-8 and
|
||||
** UTF-16.
|
||||
**
|
||||
** When converting malformed UTF-8 strings to UTF-16, one instance of the
|
||||
** replacement character U+FFFD for each byte that cannot be interpeted as
|
||||
** part of a valid unicode character.
|
||||
**
|
||||
** When converting malformed UTF-16 strings to UTF-8, one instance of the
|
||||
** replacement character U+FFFD for each pair of bytes that cannot be
|
||||
** interpeted as part of a valid unicode character.
|
||||
**
|
||||
** This file contains the following public routines:
|
||||
**
|
||||
** sqlite3VdbeMemTranslate() - Translate the encoding used by a Mem* string.
|
||||
** sqlite3VdbeMemHandleBom() - Handle byte-order-marks in UTF16 Mem* strings.
|
||||
** sqlite3utf16ByteLen() - Calculate byte-length of a void* UTF16 string.
|
||||
** sqlite3utf8CharLen() - Calculate char-length of a char* UTF8 string.
|
||||
** sqlite3utf8LikeCompare() - Do a LIKE match given two UTF8 char* strings.
|
||||
**
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
|
||||
/*
|
||||
** This table maps from the first byte of a UTF-8 character to the number
|
||||
** of trailing bytes expected. A value '255' indicates that the table key
|
||||
** is not a legal first byte for a UTF-8 character.
|
||||
*/
|
||||
static const u8 xtra_utf8_bytes[256] = {
|
||||
/* 0xxxxxxx */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
/* 10wwwwww */
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
|
||||
/* 110yyyyy */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
|
||||
/* 1110zzzz */
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
|
||||
/* 11110yyy */
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
};
|
||||
|
||||
/*
|
||||
** This table maps from the number of trailing bytes in a UTF-8 character
|
||||
** to an integer constant that is effectively calculated for each character
|
||||
** read by a naive implementation of a UTF-8 character reader. The code
|
||||
** in the READ_UTF8 macro explains things best.
|
||||
*/
|
||||
static const int xtra_utf8_bits[4] = {
|
||||
0,
|
||||
12416, /* (0xC0 << 6) + (0x80) */
|
||||
925824, /* (0xE0 << 12) + (0x80 << 6) + (0x80) */
|
||||
63447168 /* (0xF0 << 18) + (0x80 << 12) + (0x80 << 6) + 0x80 */
|
||||
};
|
||||
|
||||
#define READ_UTF8(zIn, c) { \
|
||||
int xtra; \
|
||||
c = *(zIn)++; \
|
||||
xtra = xtra_utf8_bytes[c]; \
|
||||
switch( xtra ){ \
|
||||
case 255: c = (int)0xFFFD; break; \
|
||||
case 3: c = (c<<6) + *(zIn)++; \
|
||||
case 2: c = (c<<6) + *(zIn)++; \
|
||||
case 1: c = (c<<6) + *(zIn)++; \
|
||||
c -= xtra_utf8_bits[xtra]; \
|
||||
} \
|
||||
}
|
||||
int sqlite3ReadUtf8(const unsigned char *z){
|
||||
int c;
|
||||
READ_UTF8(z, c);
|
||||
return c;
|
||||
}
|
||||
|
||||
#define SKIP_UTF8(zIn) { \
|
||||
zIn += (xtra_utf8_bytes[*(u8 *)zIn] + 1); \
|
||||
}
|
||||
|
||||
#define WRITE_UTF8(zOut, c) { \
|
||||
if( c<0x00080 ){ \
|
||||
*zOut++ = (c&0xFF); \
|
||||
} \
|
||||
else if( c<0x00800 ){ \
|
||||
*zOut++ = 0xC0 + ((c>>6)&0x1F); \
|
||||
*zOut++ = 0x80 + (c & 0x3F); \
|
||||
} \
|
||||
else if( c<0x10000 ){ \
|
||||
*zOut++ = 0xE0 + ((c>>12)&0x0F); \
|
||||
*zOut++ = 0x80 + ((c>>6) & 0x3F); \
|
||||
*zOut++ = 0x80 + (c & 0x3F); \
|
||||
}else{ \
|
||||
*zOut++ = 0xF0 + ((c>>18) & 0x07); \
|
||||
*zOut++ = 0x80 + ((c>>12) & 0x3F); \
|
||||
*zOut++ = 0x80 + ((c>>6) & 0x3F); \
|
||||
*zOut++ = 0x80 + (c & 0x3F); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define WRITE_UTF16LE(zOut, c) { \
|
||||
if( c<=0xFFFF ){ \
|
||||
*zOut++ = (c&0x00FF); \
|
||||
*zOut++ = ((c>>8)&0x00FF); \
|
||||
}else{ \
|
||||
*zOut++ = (((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
|
||||
*zOut++ = (0x00D8 + (((c-0x10000)>>18)&0x03)); \
|
||||
*zOut++ = (c&0x00FF); \
|
||||
*zOut++ = (0x00DC + ((c>>8)&0x03)); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define WRITE_UTF16BE(zOut, c) { \
|
||||
if( c<=0xFFFF ){ \
|
||||
*zOut++ = ((c>>8)&0x00FF); \
|
||||
*zOut++ = (c&0x00FF); \
|
||||
}else{ \
|
||||
*zOut++ = (0x00D8 + (((c-0x10000)>>18)&0x03)); \
|
||||
*zOut++ = (((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
|
||||
*zOut++ = (0x00DC + ((c>>8)&0x03)); \
|
||||
*zOut++ = (c&0x00FF); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define READ_UTF16LE(zIn, c){ \
|
||||
c = (*zIn++); \
|
||||
c += ((*zIn++)<<8); \
|
||||
if( c>=0xD800 && c<=0xE000 ){ \
|
||||
int c2 = (*zIn++); \
|
||||
c2 += ((*zIn++)<<8); \
|
||||
c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define READ_UTF16BE(zIn, c){ \
|
||||
c = ((*zIn++)<<8); \
|
||||
c += (*zIn++); \
|
||||
if( c>=0xD800 && c<=0xE000 ){ \
|
||||
int c2 = ((*zIn++)<<8); \
|
||||
c2 += (*zIn++); \
|
||||
c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SKIP_UTF16BE(zIn){ \
|
||||
if( *zIn>=0xD8 && (*zIn<0xE0 || (*zIn==0xE0 && *(zIn+1)==0x00)) ){ \
|
||||
zIn += 4; \
|
||||
}else{ \
|
||||
zIn += 2; \
|
||||
} \
|
||||
}
|
||||
#define SKIP_UTF16LE(zIn){ \
|
||||
zIn++; \
|
||||
if( *zIn>=0xD8 && (*zIn<0xE0 || (*zIn==0xE0 && *(zIn-1)==0x00)) ){ \
|
||||
zIn += 3; \
|
||||
}else{ \
|
||||
zIn += 1; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define RSKIP_UTF16LE(zIn){ \
|
||||
if( *zIn>=0xD8 && (*zIn<0xE0 || (*zIn==0xE0 && *(zIn-1)==0x00)) ){ \
|
||||
zIn -= 4; \
|
||||
}else{ \
|
||||
zIn -= 2; \
|
||||
} \
|
||||
}
|
||||
#define RSKIP_UTF16BE(zIn){ \
|
||||
zIn--; \
|
||||
if( *zIn>=0xD8 && (*zIn<0xE0 || (*zIn==0xE0 && *(zIn+1)==0x00)) ){ \
|
||||
zIn -= 3; \
|
||||
}else{ \
|
||||
zIn -= 1; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
** If the TRANSLATE_TRACE macro is defined, the value of each Mem is
|
||||
** printed on stderr on the way into and out of sqlite3VdbeMemTranslate().
|
||||
*/
|
||||
/* #define TRANSLATE_TRACE 1 */
|
||||
|
||||
/*
|
||||
** This routine transforms the internal text encoding used by pMem to
|
||||
** desiredEnc. It is an error if the string is already of the desired
|
||||
** encoding, or if *pMem does not contain a string value.
|
||||
*/
|
||||
int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
unsigned char zShort[NBFS]; /* Temporary short output buffer */
|
||||
int len; /* Maximum length of output string in bytes */
|
||||
unsigned char *zOut; /* Output buffer */
|
||||
unsigned char *zIn; /* Input iterator */
|
||||
unsigned char *zTerm; /* End of input */
|
||||
unsigned char *z; /* Output iterator */
|
||||
int c;
|
||||
|
||||
assert( pMem->flags&MEM_Str );
|
||||
assert( pMem->enc!=desiredEnc );
|
||||
assert( pMem->enc!=0 );
|
||||
assert( pMem->n>=0 );
|
||||
|
||||
#ifdef TRANSLATE_TRACE
|
||||
{
|
||||
char zBuf[100];
|
||||
sqlite3VdbeMemPrettyPrint(pMem, zBuf, 100);
|
||||
fprintf(stderr, "INPUT: %s\n", zBuf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If the translation is between UTF-16 little and big endian, then
|
||||
** all that is required is to swap the byte order. This case is handled
|
||||
** differently from the others.
|
||||
*/
|
||||
if( pMem->enc!=SQLITE_UTF8 && desiredEnc!=SQLITE_UTF8 ){
|
||||
u8 temp;
|
||||
int rc;
|
||||
rc = sqlite3VdbeMemMakeWriteable(pMem);
|
||||
if( rc!=SQLITE_OK ){
|
||||
assert( rc==SQLITE_NOMEM );
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
zIn = pMem->z;
|
||||
zTerm = &zIn[pMem->n];
|
||||
while( zIn<zTerm ){
|
||||
temp = *zIn;
|
||||
*zIn = *(zIn+1);
|
||||
zIn++;
|
||||
*zIn++ = temp;
|
||||
}
|
||||
pMem->enc = desiredEnc;
|
||||
goto translate_out;
|
||||
}
|
||||
|
||||
/* Set len to the maximum number of bytes required in the output buffer. */
|
||||
if( desiredEnc==SQLITE_UTF8 ){
|
||||
/* When converting from UTF-16, the maximum growth results from
|
||||
** translating a 2-byte character to a 3-byte UTF-8 character (i.e.
|
||||
** code-point 0xFFFC). A single byte is required for the output string
|
||||
** nul-terminator.
|
||||
*/
|
||||
len = (pMem->n/2) * 3 + 1;
|
||||
}else{
|
||||
/* When converting from UTF-8 to UTF-16 the maximum growth is caused
|
||||
** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
|
||||
** character. Two bytes are required in the output buffer for the
|
||||
** nul-terminator.
|
||||
*/
|
||||
len = pMem->n * 2 + 2;
|
||||
}
|
||||
|
||||
/* Set zIn to point at the start of the input buffer and zTerm to point 1
|
||||
** byte past the end.
|
||||
**
|
||||
** Variable zOut is set to point at the output buffer. This may be space
|
||||
** obtained from malloc(), or Mem.zShort, if it large enough and not in
|
||||
** use, or the zShort array on the stack (see above).
|
||||
*/
|
||||
zIn = pMem->z;
|
||||
zTerm = &zIn[pMem->n];
|
||||
if( len>NBFS ){
|
||||
zOut = sqliteMallocRaw(len);
|
||||
if( !zOut ) return SQLITE_NOMEM;
|
||||
}else{
|
||||
zOut = zShort;
|
||||
}
|
||||
z = zOut;
|
||||
|
||||
if( pMem->enc==SQLITE_UTF8 ){
|
||||
if( desiredEnc==SQLITE_UTF16LE ){
|
||||
/* UTF-8 -> UTF-16 Little-endian */
|
||||
while( zIn<zTerm ){
|
||||
READ_UTF8(zIn, c);
|
||||
WRITE_UTF16LE(z, c);
|
||||
}
|
||||
WRITE_UTF16LE(z, 0);
|
||||
pMem->n = (z-zOut)-2;
|
||||
}else if( desiredEnc==SQLITE_UTF16BE ){
|
||||
/* UTF-8 -> UTF-16 Big-endian */
|
||||
while( zIn<zTerm ){
|
||||
READ_UTF8(zIn, c);
|
||||
WRITE_UTF16BE(z, c);
|
||||
}
|
||||
WRITE_UTF16BE(z, 0);
|
||||
pMem->n = (z-zOut)-2;
|
||||
}
|
||||
}else{
|
||||
assert( desiredEnc==SQLITE_UTF8 );
|
||||
if( pMem->enc==SQLITE_UTF16LE ){
|
||||
/* UTF-16 Little-endian -> UTF-8 */
|
||||
while( zIn<zTerm ){
|
||||
READ_UTF16LE(zIn, c);
|
||||
WRITE_UTF8(z, c);
|
||||
}
|
||||
WRITE_UTF8(z, 0);
|
||||
pMem->n = (z-zOut)-1;
|
||||
}else{
|
||||
/* UTF-16 Little-endian -> UTF-8 */
|
||||
while( zIn<zTerm ){
|
||||
READ_UTF16BE(zIn, c);
|
||||
WRITE_UTF8(z, c);
|
||||
}
|
||||
WRITE_UTF8(z, 0);
|
||||
pMem->n = (z-zOut)-1;
|
||||
}
|
||||
}
|
||||
assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
|
||||
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short);
|
||||
pMem->enc = desiredEnc;
|
||||
if( zOut==zShort ){
|
||||
memcpy(pMem->zShort, zOut, len);
|
||||
zOut = pMem->zShort;
|
||||
pMem->flags |= (MEM_Term|MEM_Short);
|
||||
}else{
|
||||
pMem->flags |= (MEM_Term|MEM_Dyn);
|
||||
}
|
||||
pMem->z = zOut;
|
||||
|
||||
translate_out:
|
||||
#ifdef TRANSLATE_TRACE
|
||||
{
|
||||
char zBuf[100];
|
||||
sqlite3VdbeMemPrettyPrint(pMem, zBuf, 100);
|
||||
fprintf(stderr, "OUTPUT: %s\n", zBuf);
|
||||
}
|
||||
#endif
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine checks for a byte-order mark at the beginning of the
|
||||
** UTF-16 string stored in *pMem. If one is present, it is removed and
|
||||
** the encoding of the Mem adjusted. This routine does not do any
|
||||
** byte-swapping, it just sets Mem.enc appropriately.
|
||||
**
|
||||
** The allocation (static, dynamic etc.) and encoding of the Mem may be
|
||||
** changed by this function.
|
||||
*/
|
||||
int sqlite3VdbeMemHandleBom(Mem *pMem){
|
||||
int rc = SQLITE_OK;
|
||||
u8 bom = 0;
|
||||
|
||||
if( pMem->n<0 || pMem->n>1 ){
|
||||
u8 b1 = *(u8 *)pMem->z;
|
||||
u8 b2 = *(((u8 *)pMem->z) + 1);
|
||||
if( b1==0xFE && b2==0xFF ){
|
||||
bom = SQLITE_UTF16BE;
|
||||
}
|
||||
if( b1==0xFF && b2==0xFE ){
|
||||
bom = SQLITE_UTF16LE;
|
||||
}
|
||||
}
|
||||
|
||||
if( bom ){
|
||||
/* This function is called as soon as a string is stored in a Mem*,
|
||||
** from within sqlite3VdbeMemSetStr(). At that point it is not possible
|
||||
** for the string to be stored in Mem.zShort, or for it to be stored
|
||||
** in dynamic memory with no destructor.
|
||||
*/
|
||||
assert( !(pMem->flags&MEM_Short) );
|
||||
assert( !(pMem->flags&MEM_Dyn) || pMem->xDel );
|
||||
if( pMem->flags & MEM_Dyn ){
|
||||
void (*xDel)(void*) = pMem->xDel;
|
||||
char *z = pMem->z;
|
||||
pMem->z = 0;
|
||||
pMem->xDel = 0;
|
||||
rc = sqlite3VdbeMemSetStr(pMem, &z[2], pMem->n-2, bom, SQLITE_TRANSIENT);
|
||||
xDel(z);
|
||||
}else{
|
||||
rc = sqlite3VdbeMemSetStr(pMem, &pMem->z[2], pMem->n-2, bom,
|
||||
SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** pZ is a UTF-8 encoded unicode string. If nByte is less than zero,
|
||||
** return the number of unicode characters in pZ up to (but not including)
|
||||
** the first 0x00 byte. If nByte is not less than zero, return the
|
||||
** number of unicode characters in the first nByte of pZ (or up to
|
||||
** the first 0x00, whichever comes first).
|
||||
*/
|
||||
int sqlite3utf8CharLen(const char *z, int nByte){
|
||||
int r = 0;
|
||||
const char *zTerm;
|
||||
if( nByte>=0 ){
|
||||
zTerm = &z[nByte];
|
||||
}else{
|
||||
zTerm = (const char *)(-1);
|
||||
}
|
||||
assert( z<=zTerm );
|
||||
while( *z!=0 && z<zTerm ){
|
||||
SKIP_UTF8(z);
|
||||
r++;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
** pZ is a UTF-16 encoded unicode string. If nChar is less than zero,
|
||||
** return the number of bytes up to (but not including), the first pair
|
||||
** of consecutive 0x00 bytes in pZ. If nChar is not less than zero,
|
||||
** then return the number of bytes in the first nChar unicode characters
|
||||
** in pZ (or up until the first pair of 0x00 bytes, whichever comes first).
|
||||
*/
|
||||
int sqlite3utf16ByteLen(const void *zIn, int nChar){
|
||||
int c = 1;
|
||||
char const *z = zIn;
|
||||
int n = 0;
|
||||
if( SQLITE_UTF16NATIVE==SQLITE_UTF16BE ){
|
||||
while( c && ((nChar<0) || n<nChar) ){
|
||||
READ_UTF16BE(z, c);
|
||||
n++;
|
||||
}
|
||||
}else{
|
||||
while( c && ((nChar<0) || n<nChar) ){
|
||||
READ_UTF16LE(z, c);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
return (z-(char const *)zIn)-((c==0)?2:0);
|
||||
}
|
||||
|
||||
/*
|
||||
** UTF-16 implementation of the substr()
|
||||
*/
|
||||
void sqlite3utf16Substr(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
int y, z;
|
||||
unsigned char const *zStr;
|
||||
unsigned char const *zStrEnd;
|
||||
unsigned char const *zStart;
|
||||
unsigned char const *zEnd;
|
||||
int i;
|
||||
|
||||
zStr = (unsigned char const *)sqlite3_value_text16(argv[0]);
|
||||
zStrEnd = &zStr[sqlite3_value_bytes16(argv[0])];
|
||||
y = sqlite3_value_int(argv[1]);
|
||||
z = sqlite3_value_int(argv[2]);
|
||||
|
||||
if( y>0 ){
|
||||
y = y-1;
|
||||
zStart = zStr;
|
||||
if( SQLITE_UTF16BE==SQLITE_UTF16NATIVE ){
|
||||
for(i=0; i<y && zStart<zStrEnd; i++) SKIP_UTF16BE(zStart);
|
||||
}else{
|
||||
for(i=0; i<y && zStart<zStrEnd; i++) SKIP_UTF16LE(zStart);
|
||||
}
|
||||
}else{
|
||||
zStart = zStrEnd;
|
||||
if( SQLITE_UTF16BE==SQLITE_UTF16NATIVE ){
|
||||
for(i=y; i<0 && zStart>zStr; i++) RSKIP_UTF16BE(zStart);
|
||||
}else{
|
||||
for(i=y; i<0 && zStart>zStr; i++) RSKIP_UTF16LE(zStart);
|
||||
}
|
||||
for(; i<0; i++) z -= 1;
|
||||
}
|
||||
|
||||
zEnd = zStart;
|
||||
if( SQLITE_UTF16BE==SQLITE_UTF16NATIVE ){
|
||||
for(i=0; i<z && zEnd<zStrEnd; i++) SKIP_UTF16BE(zEnd);
|
||||
}else{
|
||||
for(i=0; i<z && zEnd<zStrEnd; i++) SKIP_UTF16LE(zEnd);
|
||||
}
|
||||
|
||||
sqlite3_result_text16(context, zStart, zEnd-zStart, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
#if defined(SQLITE_TEST)
|
||||
/*
|
||||
** This routine is called from the TCL test function "translate_selftest".
|
||||
** It checks that the primitives for serializing and deserializing
|
||||
** characters in each encoding are inverses of each other.
|
||||
*/
|
||||
void sqlite3utfSelfTest(){
|
||||
int i;
|
||||
unsigned char zBuf[20];
|
||||
unsigned char *z;
|
||||
int n;
|
||||
int c;
|
||||
|
||||
for(i=0; i<0x00110000; i++){
|
||||
z = zBuf;
|
||||
WRITE_UTF8(z, i);
|
||||
n = z-zBuf;
|
||||
z = zBuf;
|
||||
READ_UTF8(z, c);
|
||||
assert( c==i );
|
||||
assert( (z-zBuf)==n );
|
||||
}
|
||||
for(i=0; i<0x00110000; i++){
|
||||
if( i>=0xD800 && i<=0xE000 ) continue;
|
||||
z = zBuf;
|
||||
WRITE_UTF16LE(z, i);
|
||||
n = z-zBuf;
|
||||
z = zBuf;
|
||||
READ_UTF16LE(z, c);
|
||||
assert( c==i );
|
||||
assert( (z-zBuf)==n );
|
||||
}
|
||||
for(i=0; i<0x00110000; i++){
|
||||
if( i>=0xD800 && i<=0xE000 ) continue;
|
||||
z = zBuf;
|
||||
WRITE_UTF16BE(z, i);
|
||||
n = z-zBuf;
|
||||
z = zBuf;
|
||||
READ_UTF16BE(z, c);
|
||||
assert( c==i );
|
||||
assert( (z-zBuf)==n );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+527
-388
File diff suppressed because it is too large
Load Diff
+248
-178
@@ -14,12 +14,173 @@
|
||||
** Most of the code in this file may be omitted by defining the
|
||||
** SQLITE_OMIT_VACUUM macro.
|
||||
**
|
||||
** $Id: vacuum.c,v 1.29 2004/09/02 15:27:42 drh Exp $
|
||||
** $Id: vacuum.c,v 1.13.2.2 2004/06/04 19:07:54 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** A structure for holding a dynamic string - a string that can grow
|
||||
** without bound.
|
||||
*/
|
||||
typedef struct dynStr dynStr;
|
||||
struct dynStr {
|
||||
char *z; /* Text of the string in space obtained from sqliteMalloc() */
|
||||
int nAlloc; /* Amount of space allocated to z[] */
|
||||
int nUsed; /* Next unused slot in z[] */
|
||||
};
|
||||
|
||||
/*
|
||||
** A structure that holds the vacuum context
|
||||
*/
|
||||
typedef struct vacuumStruct vacuumStruct;
|
||||
struct vacuumStruct {
|
||||
sqlite *dbOld; /* Original database */
|
||||
sqlite *dbNew; /* New database */
|
||||
char **pzErrMsg; /* Write errors here */
|
||||
int rc; /* Set to non-zero on an error */
|
||||
const char *zTable; /* Name of a table being copied */
|
||||
const char *zPragma; /* Pragma to execute with results */
|
||||
dynStr s1, s2; /* Two dynamic strings */
|
||||
};
|
||||
|
||||
#if !defined(SQLITE_OMIT_VACUUM) || SQLITE_OMIT_VACUUM
|
||||
/*
|
||||
** Append text to a dynamic string
|
||||
*/
|
||||
static void appendText(dynStr *p, const char *zText, int nText){
|
||||
if( nText<0 ) nText = strlen(zText);
|
||||
if( p->z==0 || p->nUsed + nText + 1 >= p->nAlloc ){
|
||||
char *zNew;
|
||||
p->nAlloc = p->nUsed + nText + 1000;
|
||||
zNew = sqliteRealloc(p->z, p->nAlloc);
|
||||
if( zNew==0 ){
|
||||
sqliteFree(p->z);
|
||||
memset(p, 0, sizeof(*p));
|
||||
return;
|
||||
}
|
||||
p->z = zNew;
|
||||
}
|
||||
memcpy(&p->z[p->nUsed], zText, nText+1);
|
||||
p->nUsed += nText;
|
||||
}
|
||||
|
||||
/*
|
||||
** Append text to a dynamic string, having first put the text in quotes.
|
||||
*/
|
||||
static void appendQuoted(dynStr *p, const char *zText){
|
||||
int i, j;
|
||||
appendText(p, "'", 1);
|
||||
for(i=j=0; zText[i]; i++){
|
||||
if( zText[i]=='\'' ){
|
||||
appendText(p, &zText[j], i-j+1);
|
||||
j = i + 1;
|
||||
appendText(p, "'", 1);
|
||||
}
|
||||
}
|
||||
if( j<i ){
|
||||
appendText(p, &zText[j], i-j);
|
||||
}
|
||||
appendText(p, "'", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
** Execute statements of SQL. If an error occurs, write the error
|
||||
** message into *pzErrMsg and return non-zero.
|
||||
*/
|
||||
static int execsql(char **pzErrMsg, sqlite *db, const char *zSql){
|
||||
char *zErrMsg = 0;
|
||||
int rc;
|
||||
|
||||
/* printf("***** executing *****\n%s\n", zSql); */
|
||||
rc = sqlite_exec(db, zSql, 0, 0, &zErrMsg);
|
||||
if( zErrMsg ){
|
||||
sqliteSetString(pzErrMsg, zErrMsg, (char*)0);
|
||||
sqlite_freemem(zErrMsg);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is the second stage callback. Each invocation contains all the
|
||||
** data for a single row of a single table in the original database. This
|
||||
** routine must write that information into the new database.
|
||||
*/
|
||||
static int vacuumCallback2(void *pArg, int argc, char **argv, char **NotUsed){
|
||||
vacuumStruct *p = (vacuumStruct*)pArg;
|
||||
const char *zSep = "(";
|
||||
int i;
|
||||
|
||||
if( argv==0 ) return 0;
|
||||
p->s2.nUsed = 0;
|
||||
appendText(&p->s2, "INSERT INTO ", -1);
|
||||
appendQuoted(&p->s2, p->zTable);
|
||||
appendText(&p->s2, " VALUES", -1);
|
||||
for(i=0; i<argc; i++){
|
||||
appendText(&p->s2, zSep, 1);
|
||||
zSep = ",";
|
||||
if( argv[i]==0 ){
|
||||
appendText(&p->s2, "NULL", 4);
|
||||
}else{
|
||||
appendQuoted(&p->s2, argv[i]);
|
||||
}
|
||||
}
|
||||
appendText(&p->s2,")", 1);
|
||||
p->rc = execsql(p->pzErrMsg, p->dbNew, p->s2.z);
|
||||
return p->rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is the first stage callback. Each invocation contains three
|
||||
** arguments where are taken from the SQLITE_MASTER table of the original
|
||||
** database: (1) the entry type, (2) the entry name, and (3) the SQL for
|
||||
** the entry. In all cases, execute the SQL of the third argument.
|
||||
** For tables, run a query to select all entries in that table and
|
||||
** transfer them to the second-stage callback.
|
||||
*/
|
||||
static int vacuumCallback1(void *pArg, int argc, char **argv, char **NotUsed){
|
||||
vacuumStruct *p = (vacuumStruct*)pArg;
|
||||
int rc = 0;
|
||||
assert( argc==3 );
|
||||
if( argv==0 ) return 0;
|
||||
assert( argv[0]!=0 );
|
||||
assert( argv[1]!=0 );
|
||||
assert( argv[2]!=0 );
|
||||
rc = execsql(p->pzErrMsg, p->dbNew, argv[2]);
|
||||
if( rc==SQLITE_OK && strcmp(argv[0],"table")==0 ){
|
||||
char *zErrMsg = 0;
|
||||
p->s1.nUsed = 0;
|
||||
appendText(&p->s1, "SELECT * FROM ", -1);
|
||||
appendQuoted(&p->s1, argv[1]);
|
||||
p->zTable = argv[1];
|
||||
rc = sqlite_exec(p->dbOld, p->s1.z, vacuumCallback2, p, &zErrMsg);
|
||||
if( zErrMsg ){
|
||||
sqliteSetString(p->pzErrMsg, zErrMsg, (char*)0);
|
||||
sqlite_freemem(zErrMsg);
|
||||
}
|
||||
}
|
||||
if( rc!=SQLITE_ABORT ) p->rc = rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This callback is used to transfer PRAGMA settings from one database
|
||||
** to the other. The value in argv[0] should be passed to a pragma
|
||||
** identified by ((vacuumStruct*)pArg)->zPragma.
|
||||
*/
|
||||
static int vacuumCallback3(void *pArg, int argc, char **argv, char **NotUsed){
|
||||
vacuumStruct *p = (vacuumStruct*)pArg;
|
||||
char zBuf[200];
|
||||
assert( argc==1 );
|
||||
if( argv==0 ) return 0;
|
||||
assert( argv[0]!=0 );
|
||||
assert( strlen(p->zPragma)<100 );
|
||||
assert( strlen(argv[0])<30 );
|
||||
sprintf(zBuf,"PRAGMA %s=%s;", p->zPragma, argv[0]);
|
||||
p->rc = execsql(p->pzErrMsg, p->dbNew, zBuf);
|
||||
return p->rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate a random name of 20 character in length.
|
||||
*/
|
||||
@@ -28,46 +189,11 @@ static void randomName(unsigned char *zBuf){
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789";
|
||||
int i;
|
||||
sqlite3Randomness(20, zBuf);
|
||||
sqliteRandomness(20, zBuf);
|
||||
for(i=0; i<20; i++){
|
||||
zBuf[i] = zChars[ zBuf[i]%(sizeof(zChars)-1) ];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Execute zSql on database db. Return an error code.
|
||||
*/
|
||||
static int execSql(sqlite3 *db, const char *zSql){
|
||||
sqlite3_stmt *pStmt;
|
||||
if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
|
||||
return sqlite3_errcode(db);
|
||||
}
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) );
|
||||
return sqlite3_finalize(pStmt);
|
||||
}
|
||||
|
||||
/*
|
||||
** Execute zSql on database db. The statement returns exactly
|
||||
** one column. Execute this as SQL on the same database.
|
||||
*/
|
||||
static int execExecSql(sqlite3 *db, const char *zSql){
|
||||
sqlite3_stmt *pStmt;
|
||||
int rc;
|
||||
|
||||
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
rc = execSql(db, sqlite3_column_text(pStmt, 0));
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3_finalize(pStmt);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return sqlite3_finalize(pStmt);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -80,178 +206,122 @@ static int execExecSql(sqlite3 *db, const char *zSql){
|
||||
** with 2.0.0, SQLite no longer uses GDBM so this command has
|
||||
** become a no-op.
|
||||
*/
|
||||
void sqlite3Vacuum(Parse *pParse, Token *pTableName){
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
if( v ){
|
||||
sqlite3VdbeAddOp(v, OP_Vacuum, 0, 0);
|
||||
}
|
||||
void sqliteVacuum(Parse *pParse, Token *pTableName){
|
||||
Vdbe *v = sqliteGetVdbe(pParse);
|
||||
sqliteVdbeAddOp(v, OP_Vacuum, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine implements the OP_Vacuum opcode of the VDBE.
|
||||
*/
|
||||
int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
|
||||
int rc = SQLITE_OK; /* Return code from service routines */
|
||||
int sqliteRunVacuum(char **pzErrMsg, sqlite *db){
|
||||
#if !defined(SQLITE_OMIT_VACUUM) || SQLITE_OMIT_VACUUM
|
||||
const char *zFilename; /* full pathname of the database file */
|
||||
int nFilename; /* number of characters in zFilename[] */
|
||||
char *zTemp = 0; /* a temporary file in same directory as zFilename */
|
||||
sqlite *dbNew = 0; /* The new vacuumed database */
|
||||
int rc = SQLITE_OK; /* Return code from service routines */
|
||||
int i; /* Loop counter */
|
||||
Btree *pTemp;
|
||||
char *zSql = 0;
|
||||
char *zErrMsg; /* Error message */
|
||||
vacuumStruct sVac; /* Information passed to callbacks */
|
||||
|
||||
if( !db->autoCommit ){
|
||||
sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction",
|
||||
/* These are all of the pragmas that need to be transferred over
|
||||
** to the new database */
|
||||
static const char *zPragma[] = {
|
||||
"default_synchronous",
|
||||
"default_cache_size",
|
||||
/* "default_temp_store", */
|
||||
};
|
||||
|
||||
if( db->flags & SQLITE_InTrans ){
|
||||
sqliteSetString(pzErrMsg, "cannot VACUUM from within a transaction",
|
||||
(char*)0);
|
||||
rc = SQLITE_ERROR;
|
||||
goto end_of_vacuum;
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
if( db->flags & SQLITE_Interrupt ){
|
||||
return SQLITE_INTERRUPT;
|
||||
}
|
||||
memset(&sVac, 0, sizeof(sVac));
|
||||
|
||||
/* Get the full pathname of the database file and create a
|
||||
** temporary filename in the same directory as the original file.
|
||||
/* Get the full pathname of the database file and create two
|
||||
** temporary filenames in the same directory as the original file.
|
||||
*/
|
||||
zFilename = sqlite3BtreeGetFilename(db->aDb[0].pBt);
|
||||
assert( zFilename );
|
||||
if( zFilename[0]=='\0' ){
|
||||
/* The in-memory database. Do nothing. Return directly to avoid causing
|
||||
** an error trying to DETACH the vacuum_db (which never got attached)
|
||||
** in the exit-handler.
|
||||
*/
|
||||
zFilename = sqliteBtreeGetFilename(db->aDb[0].pBt);
|
||||
if( zFilename==0 ){
|
||||
/* This only happens with the in-memory database. VACUUM is a no-op
|
||||
** there, so just return */
|
||||
return SQLITE_OK;
|
||||
}
|
||||
nFilename = strlen(zFilename);
|
||||
zTemp = sqliteMalloc( nFilename+100 );
|
||||
if( zTemp==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
if( zTemp==0 ) return SQLITE_NOMEM;
|
||||
strcpy(zTemp, zFilename);
|
||||
i = 0;
|
||||
do {
|
||||
for(i=0; i<10; i++){
|
||||
zTemp[nFilename] = '-';
|
||||
randomName((unsigned char*)&zTemp[nFilename+1]);
|
||||
} while( i<10 && sqlite3OsFileExists(zTemp) );
|
||||
|
||||
/* Attach the temporary database as 'vacuum_db'. The synchronous pragma
|
||||
** can be set to 'off' for this file, as it is not recovered if a crash
|
||||
** occurs anyway. The integrity of the database is maintained by a
|
||||
** (possibly synchronous) transaction opened on the main database before
|
||||
** sqlite3BtreeCopyFile() is called.
|
||||
**
|
||||
** An optimisation would be to use a non-journaled pager.
|
||||
*/
|
||||
zSql = sqlite3MPrintf("ATTACH '%q' AS vacuum_db;", zTemp);
|
||||
if( !zSql ){
|
||||
rc = SQLITE_NOMEM;
|
||||
if( !sqliteOsFileExists(zTemp) ) break;
|
||||
}
|
||||
if( i>=10 ){
|
||||
sqliteSetString(pzErrMsg, "unable to create a temporary database file "
|
||||
"in the same directory as the original database", (char*)0);
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
rc = execSql(db, zSql);
|
||||
sqliteFree(zSql);
|
||||
zSql = 0;
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
execSql(db, "PRAGMA vacuum_db.synchronous = off;");
|
||||
|
||||
/* Begin a transaction */
|
||||
rc = execSql(db, "BEGIN;");
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Query the schema of the main database. Create a mirror schema
|
||||
** in the temporary database.
|
||||
*/
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14,100000000) "
|
||||
" FROM sqlite_master WHERE type='table' "
|
||||
|
||||
dbNew = sqlite_open(zTemp, 0, &zErrMsg);
|
||||
if( dbNew==0 ){
|
||||
sqliteSetString(pzErrMsg, "unable to open a temporary database at ",
|
||||
zTemp, " - ", zErrMsg, (char*)0);
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
if( (rc = execsql(pzErrMsg, db, "BEGIN"))!=0 ) goto end_of_vacuum;
|
||||
if( (rc = execsql(pzErrMsg, dbNew, "PRAGMA synchronous=off; BEGIN"))!=0 ){
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
|
||||
sVac.dbOld = db;
|
||||
sVac.dbNew = dbNew;
|
||||
sVac.pzErrMsg = pzErrMsg;
|
||||
for(i=0; rc==SQLITE_OK && i<sizeof(zPragma)/sizeof(zPragma[0]); i++){
|
||||
char zBuf[200];
|
||||
assert( strlen(zPragma[i])<100 );
|
||||
sprintf(zBuf, "PRAGMA %s;", zPragma[i]);
|
||||
sVac.zPragma = zPragma[i];
|
||||
rc = sqlite_exec(db, zBuf, vacuumCallback3, &sVac, &zErrMsg);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite_exec(db,
|
||||
"SELECT type, name, sql FROM sqlite_master "
|
||||
"WHERE sql NOT NULL AND type!='view' "
|
||||
"UNION ALL "
|
||||
"SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14,100000000) "
|
||||
" FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' "
|
||||
"UNION ALL "
|
||||
"SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21,100000000) "
|
||||
" FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'"
|
||||
"UNION ALL "
|
||||
"SELECT 'CREATE VIEW vacuum_db.' || substr(sql,13,100000000) "
|
||||
" FROM sqlite_master WHERE type='view'"
|
||||
);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Loop through the tables in the main database. For each, do
|
||||
** an "INSERT INTO vacuum_db.xxx SELECT * FROM xxx;" to copy
|
||||
** the contents to the temporary database.
|
||||
*/
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
|
||||
"|| ' SELECT * FROM ' || quote(name) || ';'"
|
||||
"FROM sqlite_master "
|
||||
"WHERE type = 'table';"
|
||||
);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Copy the triggers from the main database to the temporary database.
|
||||
** This was deferred before in case the triggers interfered with copying
|
||||
** the data. It's possible the indices should be deferred until this
|
||||
** point also.
|
||||
*/
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'CREATE TRIGGER vacuum_db.' || substr(sql, 16, 1000000) "
|
||||
"FROM sqlite_master WHERE type='trigger'"
|
||||
);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
|
||||
/* At this point, unless the main db was completely empty, there is now a
|
||||
** transaction open on the vacuum database, but not on the main database.
|
||||
** Open a btree level transaction on the main database. This allows a
|
||||
** call to sqlite3BtreeCopyFile(). The main database btree level
|
||||
** transaction is then committed, so the SQL level never knows it was
|
||||
** opened for writing. This way, the SQL transaction used to create the
|
||||
** temporary database never needs to be committed.
|
||||
*/
|
||||
pTemp = db->aDb[db->nDb-1].pBt;
|
||||
if( sqlite3BtreeIsInTrans(pTemp) ){
|
||||
Btree *pMain = db->aDb[0].pBt;
|
||||
u32 meta;
|
||||
|
||||
assert( 0==sqlite3BtreeIsInTrans(pMain) );
|
||||
rc = sqlite3BtreeBeginTrans(pMain, 1);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Copy Btree meta values 3 and 4. These correspond to SQL layer meta
|
||||
** values 2 and 3, the default values of a couple of pragmas.
|
||||
*/
|
||||
rc = sqlite3BtreeGetMeta(pMain, 3, &meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeUpdateMeta(pTemp, 3, meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeGetMeta(pMain, 4, &meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeUpdateMeta(pTemp, 4, meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
rc = sqlite3BtreeCopyFile(pMain, pTemp);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeCommit(pMain);
|
||||
"SELECT type, name, sql FROM sqlite_master "
|
||||
"WHERE sql NOT NULL AND type=='view'",
|
||||
vacuumCallback1, &sVac, &zErrMsg);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqliteBtreeCopyFile(db->aDb[0].pBt, dbNew->aDb[0].pBt);
|
||||
sqlite_exec(db, "COMMIT", 0, 0, 0);
|
||||
sqliteResetInternalSchema(db, 0);
|
||||
}
|
||||
|
||||
end_of_vacuum:
|
||||
/* Currently there is an SQL level transaction open on the vacuum
|
||||
** database. No locks are held on any other files (since the main file
|
||||
** was committed at the btree level). So it safe to end the transaction
|
||||
** by manually setting the autoCommit flag to true and detaching the
|
||||
** vacuum database. The vacuum_db journal file is deleted when the pager
|
||||
** is closed by the DETACH.
|
||||
*/
|
||||
db->autoCommit = 1;
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = execSql(db, "DETACH vacuum_db;");
|
||||
}else{
|
||||
execSql(db, "DETACH vacuum_db;");
|
||||
if( rc && zErrMsg!=0 ){
|
||||
sqliteSetString(pzErrMsg, "unable to vacuum database - ",
|
||||
zErrMsg, (char*)0);
|
||||
}
|
||||
if( zTemp ){
|
||||
sqlite3OsDelete(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
sqlite_exec(db, "ROLLBACK", 0, 0, 0);
|
||||
if( (dbNew && (dbNew->flags & SQLITE_Interrupt))
|
||||
|| (db->flags & SQLITE_Interrupt) ){
|
||||
rc = SQLITE_INTERRUPT;
|
||||
}
|
||||
if( zSql ) sqliteFree( zSql );
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
if( dbNew ) sqlite_close(dbNew);
|
||||
sqliteOsDelete(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
sqliteFree(sVac.s1.z);
|
||||
sqliteFree(sVac.s2.z);
|
||||
if( zErrMsg ) sqlite_freemem(zErrMsg);
|
||||
if( rc==SQLITE_ABORT && sVac.rc!=SQLITE_INTERRUPT ) sVac.rc = SQLITE_ERROR;
|
||||
return sVac.rc;
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
+2232
-1825
File diff suppressed because it is too large
Load Diff
+25
-44
@@ -15,7 +15,7 @@
|
||||
** or VDBE. The VDBE implements an abstract machine that runs a
|
||||
** simple program to access and modify the underlying database.
|
||||
**
|
||||
** $Id: vdbe.h,v 1.90 2004/08/21 17:54:45 drh Exp $
|
||||
** $Id: vdbe.h,v 1.71 2004/02/22 20:05:02 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_VDBE_H_
|
||||
#define _SQLITE_VDBE_H_
|
||||
@@ -65,24 +65,11 @@ typedef struct VdbeOpList VdbeOpList;
|
||||
#define P3_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
|
||||
#define P3_STATIC (-2) /* Pointer to a static string */
|
||||
#define P3_POINTER (-3) /* P3 is a pointer to some structure or object */
|
||||
#define P3_COLLSEQ (-4) /* P3 is a pointer to a CollSeq structure */
|
||||
#define P3_FUNCDEF (-5) /* P3 is a pointer to a FuncDef structure */
|
||||
#define P3_KEYINFO (-6) /* P3 is a pointer to a KeyInfo structure */
|
||||
#define P3_VDBEFUNC (-7) /* P3 is a pointer to a VdbeFunc structure */
|
||||
|
||||
/* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
|
||||
** is made. That copy is freed when the Vdbe is finalized. But if the
|
||||
** argument is P3_KEYINFO_HANDOFF, the passed in pointer is used. It still
|
||||
** gets freed when the Vdbe is finalized so it still should be obtained
|
||||
** from a single sqliteMalloc(). But no copy is made and the calling
|
||||
** function should *not* try to free the KeyInfo.
|
||||
*/
|
||||
#define P3_KEYINFO_HANDOFF (-7)
|
||||
|
||||
/*
|
||||
** The following macro converts a relative address in the p2 field
|
||||
** of a VdbeOp structure into a negative number so that
|
||||
** sqlite3VdbeAddOpList() knows that the address is relative. Calling
|
||||
** sqliteVdbeAddOpList() knows that the address is relative. Calling
|
||||
** the macro again restores the address.
|
||||
*/
|
||||
#define ADDR(X) (-1-(X))
|
||||
@@ -97,35 +84,29 @@ typedef struct VdbeOpList VdbeOpList;
|
||||
** Prototypes for the VDBE interface. See comments on the implementation
|
||||
** for a description of what each of these routines does.
|
||||
*/
|
||||
Vdbe *sqlite3VdbeCreate(sqlite*);
|
||||
void sqlite3VdbeCreateCallback(Vdbe*, int*);
|
||||
int sqlite3VdbeAddOp(Vdbe*,int,int,int);
|
||||
int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
|
||||
int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
|
||||
void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
|
||||
void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
|
||||
void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
|
||||
void sqlite3VdbeDequoteP3(Vdbe*, int addr);
|
||||
int sqlite3VdbeFindOp(Vdbe*, int, int, int);
|
||||
VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
|
||||
int sqlite3VdbeMakeLabel(Vdbe*);
|
||||
void sqlite3VdbeDelete(Vdbe*);
|
||||
void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
|
||||
int sqlite3VdbeFinalize(Vdbe*);
|
||||
void sqlite3VdbeResolveLabel(Vdbe*, int);
|
||||
int sqlite3VdbeCurrentAddr(Vdbe*);
|
||||
void sqlite3VdbeTrace(Vdbe*,FILE*);
|
||||
int sqlite3VdbeReset(Vdbe*);
|
||||
Vdbe *sqliteVdbeCreate(sqlite*);
|
||||
void sqliteVdbeCreateCallback(Vdbe*, int*);
|
||||
int sqliteVdbeAddOp(Vdbe*,int,int,int);
|
||||
int sqliteVdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
|
||||
int sqliteVdbeCode(Vdbe*,...);
|
||||
int sqliteVdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
|
||||
void sqliteVdbeChangeP1(Vdbe*, int addr, int P1);
|
||||
void sqliteVdbeChangeP2(Vdbe*, int addr, int P2);
|
||||
void sqliteVdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
|
||||
void sqliteVdbeDequoteP3(Vdbe*, int addr);
|
||||
int sqliteVdbeFindOp(Vdbe*, int, int);
|
||||
VdbeOp *sqliteVdbeGetOp(Vdbe*, int);
|
||||
int sqliteVdbeMakeLabel(Vdbe*);
|
||||
void sqliteVdbeDelete(Vdbe*);
|
||||
void sqliteVdbeMakeReady(Vdbe*,int,int);
|
||||
int sqliteVdbeExec(Vdbe*);
|
||||
int sqliteVdbeList(Vdbe*);
|
||||
int sqliteVdbeFinalize(Vdbe*,char**);
|
||||
void sqliteVdbeResolveLabel(Vdbe*, int);
|
||||
int sqliteVdbeCurrentAddr(Vdbe*);
|
||||
void sqliteVdbeTrace(Vdbe*,FILE*);
|
||||
void sqliteVdbeCompressSpace(Vdbe*,int);
|
||||
int sqliteVdbeReset(Vdbe*,char **);
|
||||
int sqliteVdbeSetVariables(Vdbe*,int,const char**);
|
||||
void sqlite3VdbeSetNumCols(Vdbe*,int);
|
||||
int sqlite3VdbeSetColName(Vdbe*, int, const char *, int);
|
||||
void sqlite3VdbeCountChanges(Vdbe*);
|
||||
|
||||
#ifndef NDEBUG
|
||||
void sqlite3VdbeComment(Vdbe*, const char*, ...);
|
||||
# define VdbeComment(X) sqlite3VdbeComment X
|
||||
#else
|
||||
# define VdbeComment(X)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+77
-179
@@ -17,19 +17,21 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
** intToKey() and keyToInt() used to transform the rowid. But with
|
||||
** the latest versions of the design they are no-ops.
|
||||
** When converting from the native format to the key format and back
|
||||
** again, in addition to changing the byte order we invert the high-order
|
||||
** bit of the most significant byte. This causes negative numbers to
|
||||
** sort before positive numbers in the memcmp() function.
|
||||
*/
|
||||
#define keyToInt(X) (X)
|
||||
#define intToKey(X) (X)
|
||||
#define keyToInt(X) (sqliteVdbeByteSwap(X) ^ 0x80000000)
|
||||
#define intToKey(X) (sqliteVdbeByteSwap((X) ^ 0x80000000))
|
||||
|
||||
/*
|
||||
** The makefile scans the vdbe.c source file and creates the following
|
||||
** array of string constants which are the names of all VDBE opcodes. This
|
||||
** array is defined in a separate source code file named opcode.c which is
|
||||
** automatically generated by the makefile.
|
||||
** The makefile scans this source file and creates the following
|
||||
** array of string constants which are the names of all VDBE opcodes.
|
||||
** This array is defined in a separate source code file named opcode.c
|
||||
** which is automatically generated by the makefile.
|
||||
*/
|
||||
extern char *sqlite3OpcodeNames[];
|
||||
extern char *sqliteOpcodeNames[];
|
||||
|
||||
/*
|
||||
** SQL is translated into a sequence of instructions to be
|
||||
@@ -60,9 +62,8 @@ typedef unsigned char Bool;
|
||||
*/
|
||||
struct Cursor {
|
||||
BtCursor *pCursor; /* The cursor structure of the backend */
|
||||
i64 lastRecno; /* Last recno from a Next or NextIdx operation */
|
||||
i64 nextRowid; /* Next rowid returned by OP_NewRowid */
|
||||
Bool zeroed; /* True if zeroed out and ready for reuse */
|
||||
int lastRecno; /* Last recno from a Next or NextIdx operation */
|
||||
int nextRowid; /* Next rowid returned by OP_NewRowid */
|
||||
Bool recnoIsValid; /* True if lastRecno is valid */
|
||||
Bool keyAsData; /* The OP_Column command works on key instead of data */
|
||||
Bool atFirst; /* True if pointing to first entry */
|
||||
@@ -70,62 +71,15 @@ struct Cursor {
|
||||
Bool nullRow; /* True if pointing to a row with no data */
|
||||
Bool nextRowidValid; /* True if the nextRowid field is valid */
|
||||
Bool pseudoTable; /* This is a NEW or OLD pseudo-tables of a trigger */
|
||||
Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
|
||||
Bool intKey; /* True if the table requires integer keys */
|
||||
Bool zeroData; /* True if table contains keys only - no data */
|
||||
u8 bogusIncrKey; /* Something for pIncrKey to point to if pKeyInfo==0 */
|
||||
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
|
||||
Bool deferredMoveto; /* A call to sqliteBtreeMoveto() is needed */
|
||||
int movetoTarget; /* Argument to the deferred sqliteBtreeMoveto() */
|
||||
Btree *pBt; /* Separate file holding temporary table */
|
||||
int nData; /* Number of bytes in pData */
|
||||
char *pData; /* Data for a NEW or OLD pseudo-table */
|
||||
i64 iKey; /* Key for the NEW or OLD pseudo-table row */
|
||||
u8 *pIncrKey; /* Pointer to pKeyInfo->incrKey */
|
||||
KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
|
||||
int nField; /* Number of fields in the header */
|
||||
|
||||
/* Cached information about the header for the data record that the
|
||||
** cursor is currently pointing to. Only valid if cacheValid is true.
|
||||
** zRow might point to (ephemeral) data for the current row, or it might
|
||||
** be NULL. */
|
||||
Bool cacheValid; /* True if the cache is valid */
|
||||
int payloadSize; /* Total number of bytes in the record */
|
||||
u32 *aType; /* Type values for all entries in the record */
|
||||
u32 *aOffset; /* Cached offsets to the start of each columns data */
|
||||
u8 *aRow; /* Data for the current row, if all on one page */
|
||||
int iKey; /* Key for the NEW or OLD pseudo-table row */
|
||||
};
|
||||
typedef struct Cursor Cursor;
|
||||
|
||||
/*
|
||||
** Number of bytes of string storage space available to each stack
|
||||
** layer without having to malloc. NBFS is short for Number of Bytes
|
||||
** For Strings.
|
||||
*/
|
||||
#define NBFS 32
|
||||
|
||||
/*
|
||||
** Internally, the vdbe manipulates nearly all SQL values as Mem
|
||||
** structures. Each Mem struct may cache multiple representations (string,
|
||||
** integer etc.) of the same value. A value (and therefore Mem structure)
|
||||
** has the following properties:
|
||||
**
|
||||
** Each value has a manifest type. The manifest type of the value stored
|
||||
** in a Mem struct is returned by the MemType(Mem*) macro. The type is
|
||||
** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
|
||||
** SQLITE_BLOB.
|
||||
*/
|
||||
struct Mem {
|
||||
i64 i; /* Integer value */
|
||||
int n; /* Number of characters in string value, including '\0' */
|
||||
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
|
||||
u8 type; /* One of MEM_Null, MEM_Str, etc. */
|
||||
u8 enc; /* TEXT_Utf8, TEXT_Utf16le, or TEXT_Utf16be */
|
||||
double r; /* Real value */
|
||||
char *z; /* String or BLOB value */
|
||||
void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
|
||||
char zShort[NBFS]; /* Space for short strings */
|
||||
};
|
||||
typedef struct Mem Mem;
|
||||
|
||||
/*
|
||||
** A sorter builds a list of elements to be sorted. Each element of
|
||||
** the list is an instance of the following structure.
|
||||
@@ -134,7 +88,8 @@ typedef struct Sorter Sorter;
|
||||
struct Sorter {
|
||||
int nKey; /* Number of bytes in the key */
|
||||
char *zKey; /* The key by which we will sort */
|
||||
Mem data;
|
||||
int nData; /* Number of bytes in the data */
|
||||
char *pData; /* The data associated with this key */
|
||||
Sorter *pNext; /* Next in the list */
|
||||
};
|
||||
|
||||
@@ -143,63 +98,44 @@ struct Sorter {
|
||||
*/
|
||||
#define NSORT 30
|
||||
|
||||
/* One or more of the following flags are set to indicate the validOK
|
||||
** representations of the value stored in the Mem struct.
|
||||
**
|
||||
** If the MEM_Null flag is set, then the value is an SQL NULL value.
|
||||
** No other flags may be set in this case.
|
||||
**
|
||||
** If the MEM_Str flag is set then Mem.z points at a string representation.
|
||||
** Usually this is encoded in the same unicode encoding as the main
|
||||
** database (see below for exceptions). If the MEM_Term flag is also
|
||||
** set, then the string is nul terminated. The MEM_Int and MEM_Real
|
||||
** flags may coexist with the MEM_Str flag.
|
||||
**
|
||||
** Multiple of these values can appear in Mem.flags. But only one
|
||||
** at a time can appear in Mem.type.
|
||||
/*
|
||||
** Number of bytes of string storage space available to each stack
|
||||
** layer without having to malloc. NBFS is short for Number of Bytes
|
||||
** For Strings.
|
||||
*/
|
||||
#define NBFS 32
|
||||
|
||||
/*
|
||||
** A single level of the stack or a single memory cell
|
||||
** is an instance of the following structure.
|
||||
*/
|
||||
struct Mem {
|
||||
int i; /* Integer value */
|
||||
int n; /* Number of characters in string value, including '\0' */
|
||||
int flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
|
||||
double r; /* Real value */
|
||||
char *z; /* String value */
|
||||
char zShort[NBFS]; /* Space for short strings */
|
||||
};
|
||||
typedef struct Mem Mem;
|
||||
|
||||
/*
|
||||
** Allowed values for Mem.flags
|
||||
*/
|
||||
#define MEM_Null 0x0001 /* Value is NULL */
|
||||
#define MEM_Str 0x0002 /* Value is a string */
|
||||
#define MEM_Int 0x0004 /* Value is an integer */
|
||||
#define MEM_Real 0x0008 /* Value is a real number */
|
||||
#define MEM_Blob 0x0010 /* Value is a BLOB */
|
||||
|
||||
/* Whenever Mem contains a valid string or blob representation, one of
|
||||
** the following flags must be set to determine the memory management
|
||||
** policy for Mem.z. The MEM_Term flag tells us whether or not the
|
||||
** string is \000 or \u0000 terminated
|
||||
*/
|
||||
#define MEM_Term 0x0020 /* String rep is nul terminated */
|
||||
#define MEM_Dyn 0x0040 /* Need to call sqliteFree() on Mem.z */
|
||||
#define MEM_Static 0x0080 /* Mem.z points to a static string */
|
||||
#define MEM_Ephem 0x0100 /* Mem.z points to an ephemeral string */
|
||||
#define MEM_Short 0x0200 /* Mem.z points to Mem.zShort */
|
||||
#define MEM_Dyn 0x0010 /* Need to call sqliteFree() on Mem.z */
|
||||
#define MEM_Static 0x0020 /* Mem.z points to a static string */
|
||||
#define MEM_Ephem 0x0040 /* Mem.z points to an ephemeral string */
|
||||
#define MEM_Short 0x0080 /* Mem.z points to Mem.zShort */
|
||||
|
||||
/* The following MEM_ value appears only in AggElem.aMem.s.flag fields.
|
||||
** It indicates that the corresponding AggElem.aMem.z points to a
|
||||
** aggregate function context that needs to be finalized.
|
||||
*/
|
||||
#define MEM_AggCtx 0x0400 /* Mem.z points to an agg function context */
|
||||
|
||||
|
||||
/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
|
||||
** additional information about auxiliary information bound to arguments
|
||||
** of the function. This is used to implement the sqlite3_get_auxdata()
|
||||
** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
|
||||
** that can be associated with a constant argument to a function. This
|
||||
** allows functions such as "regexp" to compile their constant regular
|
||||
** expression argument once and reused the compiled code for multiple
|
||||
** invocations.
|
||||
*/
|
||||
struct VdbeFunc {
|
||||
FuncDef *pFunc; /* The definition of the function */
|
||||
int nAux; /* Number of entries allocated for apAux[] */
|
||||
struct AuxData {
|
||||
void *pAux; /* Aux data for the i-th argument */
|
||||
void (*xDelete)(void *); /* Destructor for the aux data */
|
||||
} apAux[1]; /* One slot for each function argument */
|
||||
};
|
||||
typedef struct VdbeFunc VdbeFunc;
|
||||
#define MEM_AggCtx 0x0100 /* Mem.z points to an agg function context */
|
||||
|
||||
/*
|
||||
** The "context" argument for a installable function. A pointer to an
|
||||
@@ -214,15 +150,13 @@ typedef struct VdbeFunc VdbeFunc;
|
||||
** This structure is defined inside of vdbe.c because it uses substructures
|
||||
** (Mem) which are only defined there.
|
||||
*/
|
||||
struct sqlite3_context {
|
||||
struct sqlite_func {
|
||||
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
|
||||
VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
|
||||
Mem s; /* The return value is stored here */
|
||||
void *pAgg; /* Aggregate context */
|
||||
u8 isError; /* Set to true for an error */
|
||||
u8 isStep; /* Current in the step function */
|
||||
int cnt; /* Number of times that the step function has been called */
|
||||
CollSeq *pColl;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -237,11 +171,9 @@ typedef struct AggElem AggElem;
|
||||
struct Agg {
|
||||
int nMem; /* Number of values stored in each AggElem */
|
||||
AggElem *pCurrent; /* The AggElem currently in focus */
|
||||
HashElem *pSearch; /* The hash element for pCurrent */
|
||||
Hash hash; /* Hash table of all aggregate elements */
|
||||
FuncDef **apFunc; /* Information about aggregate functions */
|
||||
Btree *pBtree; /* The tmp. btree used to group elements, if required. */
|
||||
BtCursor *pCsr; /* Read/write cursor to the table in pBtree */
|
||||
int nTab; /* Root page of the table in pBtree */
|
||||
u8 searching; /* True between the first AggNext and AggReset */
|
||||
};
|
||||
struct AggElem {
|
||||
char *zKey; /* The key to this AggElem */
|
||||
@@ -272,7 +204,7 @@ struct Keylist {
|
||||
int nUsed; /* Next unwritten slot in aKey[] */
|
||||
int nRead; /* Next unread slot in aKey[] */
|
||||
Keylist *pNext; /* Next block of keys */
|
||||
i64 aKey[1]; /* One or more keys. Extra space allocated as needed */
|
||||
int aKey[1]; /* One or more keys. Extra space allocated as needed */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -283,15 +215,16 @@ struct Keylist {
|
||||
*/
|
||||
typedef struct Context Context;
|
||||
struct Context {
|
||||
int lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
|
||||
int nChange; /* Statement changes (Vdbe.nChanges) */
|
||||
int lastRowid; /* Last insert rowid (from db->lastRowid) */
|
||||
int lsChange; /* Last statement change count (from db->lsChange) */
|
||||
int csChange; /* Current statement change count (from db->csChange) */
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of the virtual machine. This structure contains the complete
|
||||
** state of the virtual machine.
|
||||
**
|
||||
** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile()
|
||||
** The "sqlite_vm" structure pointer that is returned by sqlite_compile()
|
||||
** is really a pointer to an instance of this structure.
|
||||
*/
|
||||
struct Vdbe {
|
||||
@@ -306,19 +239,26 @@ struct Vdbe {
|
||||
int *aLabel; /* Space to hold the labels */
|
||||
Mem *aStack; /* The operand stack, except string values */
|
||||
Mem *pTos; /* Top entry in the operand stack */
|
||||
Mem **apArg; /* Arguments to currently executing user function */
|
||||
Mem *aColName; /* Column names to return */
|
||||
int nCursor; /* Number of slots in apCsr[] */
|
||||
Cursor **apCsr; /* One element of this array for each open cursor */
|
||||
char **zArgv; /* Text values used by the callback */
|
||||
char **azColName; /* Becomes the 4th parameter to callbacks */
|
||||
int nCursor; /* Number of slots in aCsr[] */
|
||||
Cursor *aCsr; /* One element of this array for each open cursor */
|
||||
Sorter *pSort; /* A linked list of objects to be sorted */
|
||||
int nVar; /* Number of entries in aVar[] */
|
||||
Mem *aVar; /* Values for the OP_Variable opcode. */
|
||||
char **azVar; /* Name of variables */
|
||||
int okVar; /* True if azVar[] has been initialized */
|
||||
FILE *pFile; /* At most one open file handler */
|
||||
int nField; /* Number of file fields */
|
||||
char **azField; /* Data for each file field */
|
||||
int nVar; /* Number of entries in azVariable[] */
|
||||
char **azVar; /* Values for the OP_Variable opcode */
|
||||
int *anVar; /* Length of each value in azVariable[] */
|
||||
u8 *abVar; /* TRUE if azVariable[i] needs to be sqliteFree()ed */
|
||||
char *zLine; /* A single line from the input file */
|
||||
int nLineAlloc; /* Number of spaces allocated for zLine */
|
||||
int magic; /* Magic number for sanity checking */
|
||||
int nMem; /* Number of memory locations currently allocated */
|
||||
Mem *aMem; /* The memory locations */
|
||||
Agg agg; /* Aggregate information */
|
||||
int nSet; /* Number of sets allocated */
|
||||
Set *aSet; /* An array of sets */
|
||||
int nCallback; /* Number of callbacks invoked so far */
|
||||
Keylist *pList; /* A list of ROWIDs */
|
||||
int keylistStackDepth; /* The size of the "keylist" stack */
|
||||
@@ -329,6 +269,7 @@ struct Vdbe {
|
||||
int rc; /* Value to return */
|
||||
unsigned uniqueCnt; /* Used by OP_MakeRecord when P2!=0 */
|
||||
int errorAction; /* Recovery action to do in case of an error */
|
||||
int undoTransOnError; /* If error, either ROLLBACK or COMMIT */
|
||||
int inTempTrans; /* True if temp database is transactioned */
|
||||
int returnStack[100]; /* Return address stack for OP_Gosub & OP_Return */
|
||||
int returnDepth; /* Next unused element in returnStack[] */
|
||||
@@ -336,11 +277,7 @@ struct Vdbe {
|
||||
char **azResColumn; /* Values for one row of result */
|
||||
int popStack; /* Pop the stack this much on entry to VdbeExec() */
|
||||
char *zErrMsg; /* Error message written here */
|
||||
u8 resOnStack; /* True if there are result values on the stack */
|
||||
u8 explain; /* True if EXPLAIN present on SQL command */
|
||||
u8 changeCntOn; /* True to update the change-counter */
|
||||
u8 aborted; /* True if ROLLBACK in another VM causes an abort */
|
||||
int nChange; /* Number of db changes made since last reset */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -354,52 +291,13 @@ struct Vdbe {
|
||||
/*
|
||||
** Function prototypes
|
||||
*/
|
||||
void sqlite3VdbeFreeCursor(Cursor*);
|
||||
void sqlite3VdbeSorterReset(Vdbe*);
|
||||
int sqlite3VdbeAggReset(sqlite *, Agg *, KeyInfo *);
|
||||
void sqlite3VdbeKeylistFree(Keylist*);
|
||||
void sqliteVdbeCleanupCursor(Cursor*);
|
||||
void sqliteVdbeSorterReset(Vdbe*);
|
||||
void sqliteVdbeAggReset(Agg*);
|
||||
void sqliteVdbeKeylistFree(Keylist*);
|
||||
void sqliteVdbePopStack(Vdbe*,int);
|
||||
int sqlite3VdbeCursorMoveto(Cursor*);
|
||||
int sqliteVdbeCursorMoveto(Cursor*);
|
||||
int sqliteVdbeByteSwap(int);
|
||||
#if !defined(NDEBUG) || defined(VDBE_PROFILE)
|
||||
void sqlite3VdbePrintOp(FILE*, int, Op*);
|
||||
void sqliteVdbePrintOp(FILE*, int, Op*);
|
||||
#endif
|
||||
void sqlite3VdbePrintSql(Vdbe*);
|
||||
int sqlite3VdbeSerialTypeLen(u32);
|
||||
u32 sqlite3VdbeSerialType(Mem*);
|
||||
int sqlite3VdbeSerialPut(unsigned char*, Mem*);
|
||||
int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
|
||||
void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
|
||||
|
||||
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
|
||||
int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int*);
|
||||
int sqlite3VdbeIdxRowid(BtCursor *, i64 *);
|
||||
int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
|
||||
int sqlite3VdbeRecordCompare(void*,int,const void*,int, const void*);
|
||||
int sqlite3VdbeIdxRowidLen(int,const u8*);
|
||||
int sqlite3VdbeExec(Vdbe*);
|
||||
int sqlite3VdbeList(Vdbe*);
|
||||
int sqlite3VdbeHalt(Vdbe*);
|
||||
int sqlite3VdbeChangeEncoding(Mem *, int);
|
||||
int sqlite3VdbeMemCopy(Mem*, const Mem*);
|
||||
void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
|
||||
int sqlite3VdbeMemMove(Mem*, Mem*);
|
||||
int sqlite3VdbeMemNulTerminate(Mem*);
|
||||
int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
|
||||
void sqlite3VdbeMemSetInt64(Mem*, i64);
|
||||
void sqlite3VdbeMemSetDouble(Mem*, double);
|
||||
void sqlite3VdbeMemSetNull(Mem*);
|
||||
int sqlite3VdbeMemMakeWriteable(Mem*);
|
||||
int sqlite3VdbeMemDynamicify(Mem*);
|
||||
int sqlite3VdbeMemStringify(Mem*, int);
|
||||
i64 sqlite3VdbeIntValue(Mem*);
|
||||
int sqlite3VdbeMemIntegerify(Mem*);
|
||||
double sqlite3VdbeRealValue(Mem*);
|
||||
int sqlite3VdbeMemRealify(Mem*);
|
||||
int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
|
||||
void sqlite3VdbeMemRelease(Mem *p);
|
||||
#ifndef NDEBUG
|
||||
void sqlite3VdbeMemSanity(Mem*, u8);
|
||||
#endif
|
||||
int sqlite3VdbeMemTranslate(Mem*, u8);
|
||||
void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf);
|
||||
int sqlite3VdbeMemHandleBom(Mem *pMem);
|
||||
|
||||
-550
@@ -1,550 +0,0 @@
|
||||
/*
|
||||
** 2004 May 26
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** This file contains code use to implement APIs that are part of the
|
||||
** VDBE.
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
|
||||
/**************************** sqlite3_value_ *******************************
|
||||
** The following routines extract information from a Mem or sqlite3_value
|
||||
** structure.
|
||||
*/
|
||||
const void *sqlite3_value_blob(sqlite3_value *pVal){
|
||||
Mem *p = (Mem*)pVal;
|
||||
if( p->flags & (MEM_Blob|MEM_Str) ){
|
||||
return p->z;
|
||||
}else{
|
||||
return sqlite3_value_text(pVal);
|
||||
}
|
||||
}
|
||||
int sqlite3_value_bytes(sqlite3_value *pVal){
|
||||
return sqlite3ValueBytes(pVal, SQLITE_UTF8);
|
||||
}
|
||||
int sqlite3_value_bytes16(sqlite3_value *pVal){
|
||||
return sqlite3ValueBytes(pVal, SQLITE_UTF16NATIVE);
|
||||
}
|
||||
double sqlite3_value_double(sqlite3_value *pVal){
|
||||
return sqlite3VdbeRealValue((Mem*)pVal);
|
||||
}
|
||||
int sqlite3_value_int(sqlite3_value *pVal){
|
||||
return sqlite3VdbeIntValue((Mem*)pVal);
|
||||
}
|
||||
sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
|
||||
return sqlite3VdbeIntValue((Mem*)pVal);
|
||||
}
|
||||
const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
|
||||
return (const char *)sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
}
|
||||
const void *sqlite3_value_text16(sqlite3_value* pVal){
|
||||
return sqlite3ValueText(pVal, SQLITE_UTF16NATIVE);
|
||||
}
|
||||
const void *sqlite3_value_text16be(sqlite3_value *pVal){
|
||||
return sqlite3ValueText(pVal, SQLITE_UTF16BE);
|
||||
}
|
||||
const void *sqlite3_value_text16le(sqlite3_value *pVal){
|
||||
return sqlite3ValueText(pVal, SQLITE_UTF16LE);
|
||||
}
|
||||
int sqlite3_value_type(sqlite3_value* pVal){
|
||||
return pVal->type;
|
||||
}
|
||||
|
||||
/**************************** sqlite3_result_ *******************************
|
||||
** The following routines are used by user-defined functions to specify
|
||||
** the function result.
|
||||
*/
|
||||
void sqlite3_result_blob(
|
||||
sqlite3_context *pCtx,
|
||||
const void *z,
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
assert( n>0 );
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, 0, xDel);
|
||||
}
|
||||
void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
|
||||
sqlite3VdbeMemSetDouble(&pCtx->s, rVal);
|
||||
}
|
||||
void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){
|
||||
pCtx->isError = 1;
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT);
|
||||
}
|
||||
void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){
|
||||
pCtx->isError = 1;
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT);
|
||||
}
|
||||
void sqlite3_result_int(sqlite3_context *pCtx, int iVal){
|
||||
sqlite3VdbeMemSetInt64(&pCtx->s, (i64)iVal);
|
||||
}
|
||||
void sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){
|
||||
sqlite3VdbeMemSetInt64(&pCtx->s, iVal);
|
||||
}
|
||||
void sqlite3_result_null(sqlite3_context *pCtx){
|
||||
sqlite3VdbeMemSetNull(&pCtx->s);
|
||||
}
|
||||
void sqlite3_result_text(
|
||||
sqlite3_context *pCtx,
|
||||
const char *z,
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, xDel);
|
||||
}
|
||||
void sqlite3_result_text16(
|
||||
sqlite3_context *pCtx,
|
||||
const void *z,
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, xDel);
|
||||
}
|
||||
void sqlite3_result_text16be(
|
||||
sqlite3_context *pCtx,
|
||||
const void *z,
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16BE, xDel);
|
||||
}
|
||||
void sqlite3_result_text16le(
|
||||
sqlite3_context *pCtx,
|
||||
const void *z,
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16LE, xDel);
|
||||
}
|
||||
void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
|
||||
sqlite3VdbeMemCopy(&pCtx->s, pValue);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Execute the statement pStmt, either until a row of data is ready, the
|
||||
** statement is completely executed or an error occurs.
|
||||
*/
|
||||
int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
sqlite *db;
|
||||
int rc;
|
||||
|
||||
if( p==0 || p->magic!=VDBE_MAGIC_RUN ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( p->aborted ){
|
||||
return SQLITE_ABORT;
|
||||
}
|
||||
db = p->db;
|
||||
if( sqlite3SafetyOn(db) ){
|
||||
p->rc = SQLITE_MISUSE;
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( p->pc<0 ){
|
||||
db->activeVdbeCnt++;
|
||||
p->pc = 0;
|
||||
}
|
||||
if( p->explain ){
|
||||
rc = sqlite3VdbeList(p);
|
||||
}else{
|
||||
rc = sqlite3VdbeExec(p);
|
||||
}
|
||||
|
||||
if( sqlite3SafetyOff(db) ){
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
|
||||
sqlite3Error(p->db, rc, p->zErrMsg);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Extract the user data from a sqlite3_context structure and return a
|
||||
** pointer to it.
|
||||
*/
|
||||
void *sqlite3_user_data(sqlite3_context *p){
|
||||
assert( p && p->pFunc );
|
||||
return p->pFunc->pUserData;
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate or return the aggregate context for a user function. A new
|
||||
** context is allocated on the first call. Subsequent calls return the
|
||||
** same context that was returned on prior calls.
|
||||
**
|
||||
** This routine is defined here in vdbe.c because it depends on knowing
|
||||
** the internals of the sqlite3_context structure which is only defined in
|
||||
** this source file.
|
||||
*/
|
||||
void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){
|
||||
assert( p && p->pFunc && p->pFunc->xStep );
|
||||
if( p->pAgg==0 ){
|
||||
if( nByte<=NBFS ){
|
||||
p->pAgg = (void*)p->s.z;
|
||||
memset(p->pAgg, 0, nByte);
|
||||
}else{
|
||||
p->pAgg = sqliteMalloc( nByte );
|
||||
}
|
||||
}
|
||||
return p->pAgg;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the auxilary data pointer, if any, for the iArg'th argument to
|
||||
** the user-function defined by pCtx.
|
||||
*/
|
||||
void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
|
||||
VdbeFunc *pVdbeFunc = pCtx->pVdbeFunc;
|
||||
if( !pVdbeFunc || iArg>=pVdbeFunc->nAux || iArg<0 ){
|
||||
return 0;
|
||||
}
|
||||
return pVdbeFunc->apAux[iArg].pAux;
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the auxilary data pointer and delete function, for the iArg'th
|
||||
** argument to the user-function defined by pCtx. Any previous value is
|
||||
** deleted by calling the delete function specified when it was set.
|
||||
*/
|
||||
void sqlite3_set_auxdata(
|
||||
sqlite3_context *pCtx,
|
||||
int iArg,
|
||||
void *pAux,
|
||||
void (*xDelete)(void*)
|
||||
){
|
||||
struct AuxData *pAuxData;
|
||||
VdbeFunc *pVdbeFunc;
|
||||
if( iArg<0 ) return;
|
||||
|
||||
pVdbeFunc = pCtx->pVdbeFunc;
|
||||
if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
|
||||
int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
|
||||
pCtx->pVdbeFunc = pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc);
|
||||
if( !pVdbeFunc ) return;
|
||||
memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0,
|
||||
sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux));
|
||||
pVdbeFunc->nAux = iArg+1;
|
||||
pVdbeFunc->pFunc = pCtx->pFunc;
|
||||
}
|
||||
|
||||
pAuxData = &pVdbeFunc->apAux[iArg];
|
||||
if( pAuxData->pAux && pAuxData->xDelete ){
|
||||
pAuxData->xDelete(pAuxData->pAux);
|
||||
}
|
||||
pAuxData->pAux = pAux;
|
||||
pAuxData->xDelete = xDelete;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of times the Step function of a aggregate has been
|
||||
** called.
|
||||
**
|
||||
** This routine is defined here in vdbe.c because it depends on knowing
|
||||
** the internals of the sqlite3_context structure which is only defined in
|
||||
** this source file.
|
||||
*/
|
||||
int sqlite3_aggregate_count(sqlite3_context *p){
|
||||
assert( p && p->pFunc && p->pFunc->xStep );
|
||||
return p->cnt;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of columns in the result set for the statement pStmt.
|
||||
*/
|
||||
int sqlite3_column_count(sqlite3_stmt *pStmt){
|
||||
Vdbe *pVm = (Vdbe *)pStmt;
|
||||
return pVm ? pVm->nResColumn : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of values available from the current row of the
|
||||
** currently executing statement pStmt.
|
||||
*/
|
||||
int sqlite3_data_count(sqlite3_stmt *pStmt){
|
||||
Vdbe *pVm = (Vdbe *)pStmt;
|
||||
if( pVm==0 || !pVm->resOnStack ) return 0;
|
||||
return pVm->nResColumn;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Check to see if column iCol of the given statement is valid. If
|
||||
** it is, return a pointer to the Mem for the value of that column.
|
||||
** If iCol is not valid, return a pointer to a Mem which has a value
|
||||
** of NULL.
|
||||
*/
|
||||
static Mem *columnMem(sqlite3_stmt *pStmt, int i){
|
||||
Vdbe *pVm = (Vdbe *)pStmt;
|
||||
int vals = sqlite3_data_count(pStmt);
|
||||
if( i>=vals || i<0 ){
|
||||
static Mem nullMem;
|
||||
if( nullMem.flags==0 ){ nullMem.flags = MEM_Null; }
|
||||
sqlite3Error(pVm->db, SQLITE_RANGE, 0);
|
||||
return &nullMem;
|
||||
}
|
||||
return &pVm->pTos[(1-vals)+i];
|
||||
}
|
||||
|
||||
/**************************** sqlite3_column_ *******************************
|
||||
** The following routines are used to access elements of the current row
|
||||
** in the result set.
|
||||
*/
|
||||
const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_blob( columnMem(pStmt,i) );
|
||||
}
|
||||
int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_bytes( columnMem(pStmt,i) );
|
||||
}
|
||||
int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_bytes16( columnMem(pStmt,i) );
|
||||
}
|
||||
double sqlite3_column_double(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_double( columnMem(pStmt,i) );
|
||||
}
|
||||
int sqlite3_column_int(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_int( columnMem(pStmt,i) );
|
||||
}
|
||||
sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_int64( columnMem(pStmt,i) );
|
||||
}
|
||||
const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_text( columnMem(pStmt,i) );
|
||||
}
|
||||
const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_text16( columnMem(pStmt,i) );
|
||||
}
|
||||
int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_type( columnMem(pStmt,i) );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Return the name of the Nth column of the result set returned by SQL
|
||||
** statement pStmt.
|
||||
*/
|
||||
const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pColName;
|
||||
|
||||
if( N>=sqlite3_column_count(pStmt) || N<0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
pColName = &(p->aColName[N]);
|
||||
return sqlite3_value_text(pColName);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the name of the 'i'th column of the result set of SQL statement
|
||||
** pStmt, encoded as UTF-16.
|
||||
*/
|
||||
const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pColName;
|
||||
|
||||
if( N>=sqlite3_column_count(pStmt) || N<0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
pColName = &(p->aColName[N]);
|
||||
return sqlite3_value_text16(pColName);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the column declaration type (if applicable) of the 'i'th column
|
||||
** of the result set of SQL statement pStmt, encoded as UTF-8.
|
||||
*/
|
||||
const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pColName;
|
||||
|
||||
if( N>=sqlite3_column_count(pStmt) || N<0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
pColName = &(p->aColName[N+sqlite3_column_count(pStmt)]);
|
||||
return sqlite3_value_text(pColName);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the column declaration type (if applicable) of the 'i'th column
|
||||
** of the result set of SQL statement pStmt, encoded as UTF-16.
|
||||
*/
|
||||
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pColName;
|
||||
|
||||
if( N>=sqlite3_column_count(pStmt) || N<0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
pColName = &(p->aColName[N+sqlite3_column_count(pStmt)]);
|
||||
return sqlite3_value_text16(pColName);
|
||||
}
|
||||
|
||||
/******************************* sqlite3_bind_ ***************************
|
||||
**
|
||||
** Routines used to attach values to wildcards in a compiled SQL statement.
|
||||
*/
|
||||
/*
|
||||
** Unbind the value bound to variable i in virtual machine p. This is the
|
||||
** the same as binding a NULL value to the column. If the "i" parameter is
|
||||
** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK.
|
||||
**
|
||||
** The error code stored in database p->db is overwritten with the return
|
||||
** value in any case.
|
||||
*/
|
||||
static int vdbeUnbind(Vdbe *p, int i){
|
||||
Mem *pVar;
|
||||
if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
|
||||
sqlite3Error(p->db, SQLITE_MISUSE, 0);
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( i<1 || i>p->nVar ){
|
||||
sqlite3Error(p->db, SQLITE_RANGE, 0);
|
||||
return SQLITE_RANGE;
|
||||
}
|
||||
i--;
|
||||
pVar = &p->aVar[i];
|
||||
sqlite3VdbeMemRelease(pVar);
|
||||
pVar->flags = MEM_Null;
|
||||
sqlite3Error(p->db, SQLITE_OK, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Bind a blob value to an SQL statement variable.
|
||||
*/
|
||||
int sqlite3_bind_blob(
|
||||
sqlite3_stmt *pStmt,
|
||||
int i,
|
||||
const void *zData,
|
||||
int nData,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pVar;
|
||||
int rc;
|
||||
|
||||
rc = vdbeUnbind(p, i);
|
||||
if( rc || zData==0 ){
|
||||
return rc;
|
||||
}
|
||||
pVar = &p->aVar[i-1];
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, 0, xDel);
|
||||
return rc;
|
||||
}
|
||||
int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
|
||||
int rc;
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
rc = vdbeUnbind(p, i);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
|
||||
return sqlite3_bind_int64(p, i, (i64)iValue);
|
||||
}
|
||||
int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
|
||||
int rc;
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
rc = vdbeUnbind(p, i);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
int sqlite3_bind_null(sqlite3_stmt* p, int i){
|
||||
return vdbeUnbind((Vdbe *)p, i);
|
||||
}
|
||||
int sqlite3_bind_text(
|
||||
sqlite3_stmt *pStmt,
|
||||
int i,
|
||||
const char *zData,
|
||||
int nData,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pVar;
|
||||
int rc;
|
||||
|
||||
rc = vdbeUnbind(p, i);
|
||||
if( rc || zData==0 ){
|
||||
return rc;
|
||||
}
|
||||
pVar = &p->aVar[i-1];
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, SQLITE_UTF8, xDel);
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc);
|
||||
return rc;
|
||||
}
|
||||
int sqlite3_bind_text16(
|
||||
sqlite3_stmt *pStmt,
|
||||
int i,
|
||||
const void *zData,
|
||||
int nData,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pVar;
|
||||
int rc;
|
||||
|
||||
rc = vdbeUnbind(p, i);
|
||||
if( rc || zData==0 ){
|
||||
return rc;
|
||||
}
|
||||
pVar = &p->aVar[i-1];
|
||||
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, SQLITE_UTF16NATIVE, xDel);
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of wildcards that can be potentially bound to.
|
||||
** This routine is added to support DBD::SQLite.
|
||||
*/
|
||||
int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
return p ? p->nVar : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the name of a wildcard parameter. Return NULL if the index
|
||||
** is out of range or if the wildcard is unnamed.
|
||||
**
|
||||
** The result is always UTF-8.
|
||||
*/
|
||||
const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
if( p==0 || i<1 || i>p->nVar ){
|
||||
return 0;
|
||||
}
|
||||
if( !p->okVar ){
|
||||
int j;
|
||||
Op *pOp;
|
||||
for(j=0, pOp=p->aOp; j<p->nOp; j++, pOp++){
|
||||
if( pOp->opcode==OP_Variable ){
|
||||
assert( pOp->p1>0 && pOp->p1<=p->nVar );
|
||||
p->azVar[pOp->p1-1] = pOp->p3;
|
||||
}
|
||||
}
|
||||
p->okVar = 1;
|
||||
}
|
||||
return p->azVar[i-1];
|
||||
}
|
||||
+465
-1203
File diff suppressed because it is too large
Load Diff
-724
@@ -1,724 +0,0 @@
|
||||
/*
|
||||
** 2004 May 26
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** This file contains code use to manipulate "Mem" structure. A "Mem"
|
||||
** stores a single value in the VDBE. Mem is an opaque structure visible
|
||||
** only within the VDBE. Interface routines refer to a Mem using the
|
||||
** name sqlite_value
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include <ctype.h>
|
||||
#include "vdbeInt.h"
|
||||
|
||||
/*
|
||||
** If pMem is an object with a valid string representation, this routine
|
||||
** ensures the internal encoding for the string representation is
|
||||
** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
|
||||
**
|
||||
** If pMem is not a string object, or the encoding of the string
|
||||
** representation is already stored using the requested encoding, then this
|
||||
** routine is a no-op.
|
||||
**
|
||||
** SQLITE_OK is returned if the conversion is successful (or not required).
|
||||
** SQLITE_NOMEM may be returned if a malloc() fails during conversion
|
||||
** between formats.
|
||||
*/
|
||||
int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
|
||||
if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
return sqlite3VdbeMemTranslate(pMem, desiredEnc);
|
||||
}
|
||||
|
||||
/*
|
||||
** Make the given Mem object MEM_Dyn.
|
||||
**
|
||||
** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
|
||||
*/
|
||||
int sqlite3VdbeMemDynamicify(Mem *pMem){
|
||||
int n = pMem->n;
|
||||
u8 *z;
|
||||
if( (pMem->flags & (MEM_Ephem|MEM_Static|MEM_Short))==0 ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
assert( (pMem->flags & MEM_Dyn)==0 );
|
||||
assert( pMem->flags & (MEM_Str|MEM_Blob) );
|
||||
z = sqliteMallocRaw( n+2 );
|
||||
if( z==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pMem->flags |= MEM_Dyn|MEM_Term;
|
||||
pMem->xDel = 0;
|
||||
memcpy(z, pMem->z, n );
|
||||
z[n] = 0;
|
||||
z[n+1] = 0;
|
||||
pMem->z = z;
|
||||
pMem->flags &= ~(MEM_Ephem|MEM_Static|MEM_Short);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make the given Mem object either MEM_Short or MEM_Dyn so that bytes
|
||||
** of the Mem.z[] array can be modified.
|
||||
**
|
||||
** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
|
||||
*/
|
||||
int sqlite3VdbeMemMakeWriteable(Mem *pMem){
|
||||
int n;
|
||||
u8 *z;
|
||||
if( (pMem->flags & (MEM_Ephem|MEM_Static))==0 ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
assert( (pMem->flags & MEM_Dyn)==0 );
|
||||
assert( pMem->flags & (MEM_Str|MEM_Blob) );
|
||||
if( (n = pMem->n)+2<sizeof(pMem->zShort) ){
|
||||
z = pMem->zShort;
|
||||
pMem->flags |= MEM_Short|MEM_Term;
|
||||
}else{
|
||||
z = sqliteMallocRaw( n+2 );
|
||||
if( z==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pMem->flags |= MEM_Dyn|MEM_Term;
|
||||
pMem->xDel = 0;
|
||||
}
|
||||
memcpy(z, pMem->z, n );
|
||||
z[n] = 0;
|
||||
z[n+1] = 0;
|
||||
pMem->z = z;
|
||||
pMem->flags &= ~(MEM_Ephem|MEM_Static);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make sure the given Mem is \u0000 terminated.
|
||||
*/
|
||||
int sqlite3VdbeMemNulTerminate(Mem *pMem){
|
||||
/* In SQLite, a string without a nul terminator occurs when a string
|
||||
** is loaded from disk (in this case the memory management is ephemeral),
|
||||
** or when it is supplied by the user as a bound variable or function
|
||||
** return value. Therefore, the memory management of the string must be
|
||||
** either ephemeral, static or controlled by a user-supplied destructor.
|
||||
*/
|
||||
assert(
|
||||
!(pMem->flags&MEM_Str) || /* it's not a string, or */
|
||||
(pMem->flags&MEM_Term) || /* it's nul term. already, or */
|
||||
(pMem->flags&(MEM_Ephem|MEM_Static)) || /* it's static or ephem, or */
|
||||
(pMem->flags&MEM_Dyn && pMem->xDel) /* external management */
|
||||
);
|
||||
if( (pMem->flags & MEM_Term)!=0 || (pMem->flags & MEM_Str)==0 ){
|
||||
return SQLITE_OK; /* Nothing to do */
|
||||
}
|
||||
|
||||
if( pMem->flags & (MEM_Static|MEM_Ephem) ){
|
||||
return sqlite3VdbeMemMakeWriteable(pMem);
|
||||
}else{
|
||||
char *z = sqliteMalloc(pMem->n+2);
|
||||
if( !z ) return SQLITE_NOMEM;
|
||||
memcpy(z, pMem->z, pMem->n);
|
||||
z[pMem->n] = 0;
|
||||
z[pMem->n+1] = 0;
|
||||
pMem->xDel(pMem->z);
|
||||
pMem->xDel = 0;
|
||||
pMem->z = z;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Add MEM_Str to the set of representations for the given Mem. Numbers
|
||||
** are converted using sqlite3_snprintf(). Converting a BLOB to a string
|
||||
** is a no-op.
|
||||
**
|
||||
** Existing representations MEM_Int and MEM_Real are *not* invalidated.
|
||||
**
|
||||
** A MEM_Null value will never be passed to this function. This function is
|
||||
** used for converting values to text for returning to the user (i.e. via
|
||||
** sqlite3_value_text()), or for ensuring that values to be used as btree
|
||||
** keys are strings. In the former case a NULL pointer is returned the
|
||||
** user and the later is an internal programming error.
|
||||
*/
|
||||
int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
int rc = SQLITE_OK;
|
||||
int fg = pMem->flags;
|
||||
u8 *z = pMem->zShort;
|
||||
|
||||
assert( !(fg&(MEM_Str|MEM_Blob)) );
|
||||
assert( fg&(MEM_Int|MEM_Real) );
|
||||
|
||||
/* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
|
||||
** string representation of the value. Then, if the required encoding
|
||||
** is UTF-16le or UTF-16be do a translation.
|
||||
**
|
||||
** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
|
||||
*/
|
||||
if( fg & MEM_Real ){
|
||||
sqlite3_snprintf(NBFS, z, "%.15g", pMem->r);
|
||||
}else{
|
||||
assert( fg & MEM_Int );
|
||||
sqlite3_snprintf(NBFS, z, "%lld", pMem->i);
|
||||
}
|
||||
pMem->n = strlen(z);
|
||||
pMem->z = z;
|
||||
pMem->enc = SQLITE_UTF8;
|
||||
pMem->flags |= MEM_Str | MEM_Short | MEM_Term;
|
||||
sqlite3VdbeChangeEncoding(pMem, enc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Release any memory held by the Mem. This may leave the Mem in an
|
||||
** inconsistent state, for example with (Mem.z==0) and
|
||||
** (Mem.type==SQLITE_TEXT).
|
||||
*/
|
||||
void sqlite3VdbeMemRelease(Mem *p){
|
||||
if( p->flags & MEM_Dyn ){
|
||||
if( p->xDel ){
|
||||
p->xDel((void *)p->z);
|
||||
}else{
|
||||
sqliteFree(p->z);
|
||||
}
|
||||
p->z = 0;
|
||||
p->xDel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Return some kind of integer value which is the best we can do
|
||||
** at representing the value that *pMem describes as an integer.
|
||||
** If pMem is an integer, then the value is exact. If pMem is
|
||||
** a floating-point then the value returned is the integer part.
|
||||
** If pMem is a string or blob, then we make an attempt to convert
|
||||
** it into a integer and return that. If pMem is NULL, return 0.
|
||||
**
|
||||
** If pMem is a string, its encoding might be changed.
|
||||
*/
|
||||
i64 sqlite3VdbeIntValue(Mem *pMem){
|
||||
int flags = pMem->flags;
|
||||
if( flags & MEM_Int ){
|
||||
return pMem->i;
|
||||
}else if( flags & MEM_Real ){
|
||||
return (i64)pMem->r;
|
||||
}else if( flags & (MEM_Str|MEM_Blob) ){
|
||||
i64 value;
|
||||
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|
||||
|| sqlite3VdbeMemNulTerminate(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( pMem->z );
|
||||
sqlite3atoi64(pMem->z, &value);
|
||||
return value;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem to type integer. Invalidate any prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
pMem->i = sqlite3VdbeIntValue(pMem);
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Int;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the best representation of pMem that we can get into a
|
||||
** double. If pMem is already a double or an integer, return its
|
||||
** value. If it is a string or blob, try to convert it to a double.
|
||||
** If it is a NULL, return 0.0.
|
||||
*/
|
||||
double sqlite3VdbeRealValue(Mem *pMem){
|
||||
if( pMem->flags & MEM_Real ){
|
||||
return pMem->r;
|
||||
}else if( pMem->flags & MEM_Int ){
|
||||
return (double)pMem->i;
|
||||
}else if( pMem->flags & (MEM_Str|MEM_Blob) ){
|
||||
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|
||||
|| sqlite3VdbeMemNulTerminate(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( pMem->z );
|
||||
return sqlite3AtoF(pMem->z, 0);
|
||||
}else{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem so that it is of type MEM_Real. Invalidate any
|
||||
** prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemRealify(Mem *pMem){
|
||||
pMem->r = sqlite3VdbeRealValue(pMem);
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Real;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete any previous value and set the value stored in *pMem to NULL.
|
||||
*/
|
||||
void sqlite3VdbeMemSetNull(Mem *pMem){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Null;
|
||||
pMem->type = SQLITE_NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete any previous value and set the value stored in *pMem to val,
|
||||
** manifest type INTEGER.
|
||||
*/
|
||||
void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->i = val;
|
||||
pMem->flags = MEM_Int;
|
||||
pMem->type = SQLITE_INTEGER;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete any previous value and set the value stored in *pMem to val,
|
||||
** manifest type REAL.
|
||||
*/
|
||||
void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->r = val;
|
||||
pMem->flags = MEM_Real;
|
||||
pMem->type = SQLITE_FLOAT;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make an shallow copy of pFrom into pTo. Prior contents of
|
||||
** pTo are overwritten. The pFrom->z field is not duplicated. If
|
||||
** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
|
||||
** and flags gets srcType (either MEM_Ephem or MEM_Static).
|
||||
*/
|
||||
void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
|
||||
memcpy(pTo, pFrom, sizeof(*pFrom)-sizeof(pFrom->zShort));
|
||||
pTo->xDel = 0;
|
||||
if( pTo->flags & (MEM_Str|MEM_Blob) ){
|
||||
pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Short|MEM_Ephem);
|
||||
assert( srcType==MEM_Ephem || srcType==MEM_Static );
|
||||
pTo->flags |= srcType;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Make a full copy of pFrom into pTo. Prior contents of pTo are
|
||||
** freed before the copy is made.
|
||||
*/
|
||||
int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
|
||||
int rc;
|
||||
if( pTo->flags & MEM_Dyn ){
|
||||
sqlite3VdbeMemRelease(pTo);
|
||||
}
|
||||
sqlite3VdbeMemShallowCopy(pTo, pFrom, MEM_Ephem);
|
||||
if( pTo->flags & MEM_Ephem ){
|
||||
rc = sqlite3VdbeMemMakeWriteable(pTo);
|
||||
}else{
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Transfer the contents of pFrom to pTo. Any existing value in pTo is
|
||||
** freed. If pFrom contains ephemeral data, a copy is made.
|
||||
**
|
||||
** pFrom contains an SQL NULL when this routine returns. SQLITE_NOMEM
|
||||
** might be returned if pFrom held ephemeral data and we were unable
|
||||
** to allocate enough space to make a copy.
|
||||
*/
|
||||
int sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){
|
||||
int rc;
|
||||
if( pTo->flags & MEM_Dyn ){
|
||||
sqlite3VdbeMemRelease(pTo);
|
||||
}
|
||||
memcpy(pTo, pFrom, sizeof(Mem));
|
||||
if( pFrom->flags & MEM_Short ){
|
||||
pTo->z = pTo->zShort;
|
||||
}
|
||||
pFrom->flags = MEM_Null;
|
||||
pFrom->xDel = 0;
|
||||
if( pTo->flags & MEM_Ephem ){
|
||||
rc = sqlite3VdbeMemMakeWriteable(pTo);
|
||||
}else{
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the value of a Mem to be a string or a BLOB.
|
||||
*/
|
||||
int sqlite3VdbeMemSetStr(
|
||||
Mem *pMem, /* Memory cell to set to string value */
|
||||
const char *z, /* String pointer */
|
||||
int n, /* Bytes in string, or negative */
|
||||
u8 enc, /* Encoding of z. 0 for BLOBs */
|
||||
void (*xDel)(void*) /* Destructor function */
|
||||
){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
if( !z ){
|
||||
pMem->flags = MEM_Null;
|
||||
pMem->type = SQLITE_NULL;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
pMem->z = (char *)z;
|
||||
if( xDel==SQLITE_STATIC ){
|
||||
pMem->flags = MEM_Static;
|
||||
}else if( xDel==SQLITE_TRANSIENT ){
|
||||
pMem->flags = MEM_Ephem;
|
||||
}else{
|
||||
pMem->flags = MEM_Dyn;
|
||||
pMem->xDel = xDel;
|
||||
}
|
||||
|
||||
pMem->enc = enc;
|
||||
pMem->type = enc==0 ? SQLITE_BLOB : SQLITE_TEXT;
|
||||
pMem->n = n;
|
||||
|
||||
switch( enc ){
|
||||
case 0:
|
||||
pMem->flags |= MEM_Blob;
|
||||
break;
|
||||
|
||||
case SQLITE_UTF8:
|
||||
pMem->flags |= MEM_Str;
|
||||
if( n<0 ){
|
||||
pMem->n = strlen(z);
|
||||
pMem->flags |= MEM_Term;
|
||||
}
|
||||
break;
|
||||
|
||||
case SQLITE_UTF16LE:
|
||||
case SQLITE_UTF16BE:
|
||||
pMem->flags |= MEM_Str;
|
||||
if( pMem->n<0 ){
|
||||
pMem->n = sqlite3utf16ByteLen(pMem->z,-1);
|
||||
pMem->flags |= MEM_Term;
|
||||
}
|
||||
if( sqlite3VdbeMemHandleBom(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
if( pMem->flags&MEM_Ephem ){
|
||||
return sqlite3VdbeMemMakeWriteable(pMem);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Compare the values contained by the two memory cells, returning
|
||||
** negative, zero or positive if pMem1 is less than, equal to, or greater
|
||||
** than pMem2. Sorting order is NULL's first, followed by numbers (integers
|
||||
** and reals) sorted numerically, followed by text ordered by the collating
|
||||
** sequence pColl and finally blob's ordered by memcmp().
|
||||
**
|
||||
** Two NULL values are considered equal by this function.
|
||||
*/
|
||||
int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
|
||||
int rc;
|
||||
int f1, f2;
|
||||
int combined_flags;
|
||||
|
||||
/* Interchange pMem1 and pMem2 if the collating sequence specifies
|
||||
** DESC order.
|
||||
*/
|
||||
f1 = pMem1->flags;
|
||||
f2 = pMem2->flags;
|
||||
combined_flags = f1|f2;
|
||||
|
||||
/* If one value is NULL, it is less than the other. If both values
|
||||
** are NULL, return 0.
|
||||
*/
|
||||
if( combined_flags&MEM_Null ){
|
||||
return (f2&MEM_Null) - (f1&MEM_Null);
|
||||
}
|
||||
|
||||
/* If one value is a number and the other is not, the number is less.
|
||||
** If both are numbers, compare as reals if one is a real, or as integers
|
||||
** if both values are integers.
|
||||
*/
|
||||
if( combined_flags&(MEM_Int|MEM_Real) ){
|
||||
if( !(f1&(MEM_Int|MEM_Real)) ){
|
||||
return 1;
|
||||
}
|
||||
if( !(f2&(MEM_Int|MEM_Real)) ){
|
||||
return -1;
|
||||
}
|
||||
if( (f1 & f2 & MEM_Int)==0 ){
|
||||
double r1, r2;
|
||||
if( (f1&MEM_Real)==0 ){
|
||||
r1 = pMem1->i;
|
||||
}else{
|
||||
r1 = pMem1->r;
|
||||
}
|
||||
if( (f2&MEM_Real)==0 ){
|
||||
r2 = pMem2->i;
|
||||
}else{
|
||||
r2 = pMem2->r;
|
||||
}
|
||||
if( r1<r2 ) return -1;
|
||||
if( r1>r2 ) return 1;
|
||||
return 0;
|
||||
}else{
|
||||
assert( f1&MEM_Int );
|
||||
assert( f2&MEM_Int );
|
||||
if( pMem1->i < pMem2->i ) return -1;
|
||||
if( pMem1->i > pMem2->i ) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* If one value is a string and the other is a blob, the string is less.
|
||||
** If both are strings, compare using the collating functions.
|
||||
*/
|
||||
if( combined_flags&MEM_Str ){
|
||||
if( (f1 & MEM_Str)==0 ){
|
||||
return 1;
|
||||
}
|
||||
if( (f2 & MEM_Str)==0 ){
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert( pMem1->enc==pMem2->enc );
|
||||
assert( pMem1->enc==SQLITE_UTF8 ||
|
||||
pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
|
||||
|
||||
/* This assert may fail if the collation sequence is deleted after this
|
||||
** vdbe program is compiled. The documentation defines this as an
|
||||
** undefined condition. A crash is usual result.
|
||||
*/
|
||||
assert( !pColl || pColl->xCmp );
|
||||
|
||||
if( pColl ){
|
||||
if( pMem1->enc==pColl->enc ){
|
||||
return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
|
||||
}else{
|
||||
u8 origEnc = pMem1->enc;
|
||||
rc = pColl->xCmp(
|
||||
pColl->pUser,
|
||||
sqlite3ValueBytes((sqlite3_value*)pMem1, pColl->enc),
|
||||
sqlite3ValueText((sqlite3_value*)pMem1, pColl->enc),
|
||||
sqlite3ValueBytes((sqlite3_value*)pMem2, pColl->enc),
|
||||
sqlite3ValueText((sqlite3_value*)pMem2, pColl->enc)
|
||||
);
|
||||
sqlite3ValueBytes((sqlite3_value*)pMem1, origEnc);
|
||||
sqlite3ValueText((sqlite3_value*)pMem1, origEnc);
|
||||
sqlite3ValueBytes((sqlite3_value*)pMem2, origEnc);
|
||||
sqlite3ValueText((sqlite3_value*)pMem2, origEnc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
/* If a NULL pointer was passed as the collate function, fall through
|
||||
** to the blob case and use memcmp(). */
|
||||
}
|
||||
|
||||
/* Both values must be blobs. Compare using memcmp(). */
|
||||
rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
|
||||
if( rc==0 ){
|
||||
rc = pMem1->n - pMem2->n;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Move data out of a btree key or data field and into a Mem structure.
|
||||
** The data or key is taken from the entry that pCur is currently pointing
|
||||
** to. offset and amt determine what portion of the data or key to retrieve.
|
||||
** key is true to get the key or false to get data. The result is written
|
||||
** into the pMem element.
|
||||
**
|
||||
** The pMem structure is assumed to be uninitialized. Any prior content
|
||||
** is overwritten without being freed.
|
||||
**
|
||||
** If this routine fails for any reason (malloc returns NULL or unable
|
||||
** to read from the disk) then the pMem is left in an inconsistent state.
|
||||
*/
|
||||
int sqlite3VdbeMemFromBtree(
|
||||
BtCursor *pCur, /* Cursor pointing at record to retrieve. */
|
||||
int offset, /* Offset from the start of data to return bytes from. */
|
||||
int amt, /* Number of bytes to return. */
|
||||
int key, /* If true, retrieve from the btree key, not data. */
|
||||
Mem *pMem /* OUT: Return data in this Mem structure. */
|
||||
){
|
||||
char *zData; /* Data from the btree layer */
|
||||
int available; /* Number of bytes available on the local btree page */
|
||||
|
||||
if( key ){
|
||||
zData = (char *)sqlite3BtreeKeyFetch(pCur, &available);
|
||||
}else{
|
||||
zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
|
||||
}
|
||||
|
||||
pMem->n = amt;
|
||||
if( offset+amt<=available ){
|
||||
pMem->z = &zData[offset];
|
||||
pMem->flags = MEM_Blob|MEM_Ephem;
|
||||
}else{
|
||||
int rc;
|
||||
if( amt>NBFS-2 ){
|
||||
zData = (char *)sqliteMallocRaw(amt+2);
|
||||
if( !zData ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
|
||||
pMem->xDel = 0;
|
||||
}else{
|
||||
zData = &(pMem->zShort[0]);
|
||||
pMem->flags = MEM_Blob|MEM_Short|MEM_Term;
|
||||
}
|
||||
pMem->z = zData;
|
||||
pMem->enc = 0;
|
||||
pMem->type = SQLITE_BLOB;
|
||||
|
||||
if( key ){
|
||||
rc = sqlite3BtreeKey(pCur, offset, amt, zData);
|
||||
}else{
|
||||
rc = sqlite3BtreeData(pCur, offset, amt, zData);
|
||||
}
|
||||
zData[amt] = 0;
|
||||
zData[amt+1] = 0;
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( amt>NBFS ){
|
||||
sqliteFree(zData);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
/*
|
||||
** Perform various checks on the memory cell pMem. An assert() will
|
||||
** fail if pMem is internally inconsistent.
|
||||
*/
|
||||
void sqlite3VdbeMemSanity(Mem *pMem, u8 db_enc){
|
||||
int flags = pMem->flags;
|
||||
assert( flags!=0 ); /* Must define some type */
|
||||
if( pMem->flags & (MEM_Str|MEM_Blob) ){
|
||||
int x = pMem->flags & (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short);
|
||||
assert( x!=0 ); /* Strings must define a string subtype */
|
||||
assert( (x & (x-1))==0 ); /* Only one string subtype can be defined */
|
||||
assert( pMem->z!=0 ); /* Strings must have a value */
|
||||
/* Mem.z points to Mem.zShort iff the subtype is MEM_Short */
|
||||
assert( (pMem->flags & MEM_Short)==0 || pMem->z==pMem->zShort );
|
||||
assert( (pMem->flags & MEM_Short)!=0 || pMem->z!=pMem->zShort );
|
||||
/* No destructor unless there is MEM_Dyn */
|
||||
assert( pMem->xDel==0 || (pMem->flags & MEM_Dyn)!=0 );
|
||||
|
||||
if( (flags & MEM_Str) ){
|
||||
assert( pMem->enc==SQLITE_UTF8 ||
|
||||
pMem->enc==SQLITE_UTF16BE ||
|
||||
pMem->enc==SQLITE_UTF16LE
|
||||
);
|
||||
/* If the string is UTF-8 encoded and nul terminated, then pMem->n
|
||||
** must be the length of the string. (Later:) If the database file
|
||||
** has been corrupted, '\000' characters might have been inserted
|
||||
** into the middle of the string. In that case, the strlen() might
|
||||
** be less.
|
||||
*/
|
||||
if( pMem->enc==SQLITE_UTF8 && (flags & MEM_Term) ){
|
||||
assert( strlen(pMem->z)<=pMem->n );
|
||||
assert( pMem->z[pMem->n]==0 );
|
||||
}
|
||||
}
|
||||
}else{
|
||||
/* Cannot define a string subtype for non-string objects */
|
||||
assert( (pMem->flags & (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short))==0 );
|
||||
assert( pMem->xDel==0 );
|
||||
}
|
||||
/* MEM_Null excludes all other types */
|
||||
assert( (pMem->flags&(MEM_Str|MEM_Int|MEM_Real|MEM_Blob))==0
|
||||
|| (pMem->flags&MEM_Null)==0 );
|
||||
if( (pMem->flags & (MEM_Int|MEM_Real))==(MEM_Int|MEM_Real) ){
|
||||
assert( pMem->r==pMem->i );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function is only available internally, it is not part of the
|
||||
** external API. It works in a similar way to sqlite3_value_text(),
|
||||
** except the data returned is in the encoding specified by the second
|
||||
** parameter, which must be one of SQLITE_UTF16BE, SQLITE_UTF16LE or
|
||||
** SQLITE_UTF8.
|
||||
*/
|
||||
const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
|
||||
if( !pVal ) return 0;
|
||||
assert( enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE || enc==SQLITE_UTF8);
|
||||
|
||||
if( pVal->flags&MEM_Null ){
|
||||
return 0;
|
||||
}
|
||||
if( pVal->flags&MEM_Str ){
|
||||
sqlite3VdbeChangeEncoding(pVal, enc);
|
||||
}else if( !(pVal->flags&MEM_Blob) ){
|
||||
sqlite3VdbeMemStringify(pVal, enc);
|
||||
}
|
||||
return (const void *)(pVal->z);
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a new sqlite3_value object.
|
||||
*/
|
||||
sqlite3_value* sqlite3ValueNew(){
|
||||
Mem *p = sqliteMalloc(sizeof(*p));
|
||||
if( p ){
|
||||
p->flags = MEM_Null;
|
||||
p->type = SQLITE_NULL;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the string value of an sqlite3_value object
|
||||
*/
|
||||
void sqlite3ValueSetStr(
|
||||
sqlite3_value *v,
|
||||
int n,
|
||||
const void *z,
|
||||
u8 enc,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
if( v ) sqlite3VdbeMemSetStr((Mem *)v, z, n, enc, xDel);
|
||||
}
|
||||
|
||||
/*
|
||||
** Free an sqlite3_value object
|
||||
*/
|
||||
void sqlite3ValueFree(sqlite3_value *v){
|
||||
if( !v ) return;
|
||||
sqlite3ValueSetStr(v, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
|
||||
sqliteFree(v);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of bytes in the sqlite3_value object assuming
|
||||
** that it uses the encoding "enc"
|
||||
*/
|
||||
int sqlite3ValueBytes(sqlite3_value *pVal, u8 enc){
|
||||
Mem *p = (Mem*)pVal;
|
||||
if( (p->flags & MEM_Blob)!=0 || sqlite3ValueText(pVal, enc) ){
|
||||
return p->n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+336
-344
File diff suppressed because it is too large
Load Diff
+4
-15
@@ -10,7 +10,7 @@
|
||||
#***********************************************************************
|
||||
# This file runs all tests.
|
||||
#
|
||||
# $Id: all.test,v 1.22 2004/08/31 13:45:12 drh Exp $
|
||||
# $Id: all.test,v 1.19 2003/02/16 22:21:33 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -20,7 +20,7 @@ proc finish_test {} {memleak_check}
|
||||
if {[file exists ./sqlite_test_count]} {
|
||||
set COUNT [exec cat ./sqlite_test_count]
|
||||
} else {
|
||||
set COUNT 3
|
||||
set COUNT 4
|
||||
}
|
||||
|
||||
if {[llength $argv]>0} {
|
||||
@@ -49,16 +49,15 @@ set LeakList {}
|
||||
|
||||
set EXCLUDE {
|
||||
all.test
|
||||
crash.test
|
||||
quick.test
|
||||
malloc.test
|
||||
misuse.test
|
||||
memleak.test
|
||||
corrupt.test
|
||||
}
|
||||
# btree2.test
|
||||
|
||||
for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} {
|
||||
set btree_native_byte_order [expr {($Counter>>1)&0x1}]
|
||||
if {$Counter%2} {
|
||||
set ::SETUP_SQL {PRAGMA default_synchronous=off;}
|
||||
} else {
|
||||
@@ -99,20 +98,10 @@ if {$LeakList!=""} {
|
||||
puts " Ok"
|
||||
}
|
||||
|
||||
# Run the crashtest only on unix and only once.
|
||||
#
|
||||
if {$tcl_platform(platform)=="unix"} {
|
||||
source $testdir/crash.test
|
||||
}
|
||||
|
||||
# Run the malloc tests and the misuse test after memory leak detection.
|
||||
# Both tests leak memory. Currently, misuse.test also leaks a handful of
|
||||
# file descriptors. This is not considered a problem, but can cause tests
|
||||
# in malloc.test to fail. So set the open-file count to zero before running
|
||||
# malloc.test to get around this.
|
||||
# Both tests leak memory.
|
||||
#
|
||||
catch {source $testdir/misuse.test}
|
||||
set sqlite_open_file_count 0
|
||||
catch {source $testdir/malloc.test}
|
||||
|
||||
catch {db close}
|
||||
|
||||
+25
-59
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach.test,v 1.26 2004/08/18 15:58:24 drh Exp $
|
||||
# $Id: attach.test,v 1.13 2004/02/14 01:39:50 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -23,7 +23,6 @@ for {set i 2} {$i<=15} {incr i} {
|
||||
file delete -force test$i.db-journal
|
||||
}
|
||||
|
||||
set btree_trace 0
|
||||
do_test attach-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b);
|
||||
@@ -33,7 +32,7 @@ do_test attach-1.1 {
|
||||
}
|
||||
} {1 2 3 4}
|
||||
do_test attach-1.2 {
|
||||
sqlite3 db2 test2.db
|
||||
sqlite db2 test2.db
|
||||
execsql {
|
||||
CREATE TABLE t2(x,y);
|
||||
INSERT INTO t2 VALUES(1,'x');
|
||||
@@ -72,17 +71,17 @@ do_test attach-1.8 {
|
||||
catchsql {
|
||||
ATTACH DATABASE 'test3.db' AS three;
|
||||
}
|
||||
} {0 {}}
|
||||
} {1 {cannot attach empty database: three}}
|
||||
do_test attach-1.9 {
|
||||
catchsql {
|
||||
SELECT * FROM three.sqlite_master;
|
||||
}
|
||||
} {0 {}}
|
||||
} {1 {no such table: three.sqlite_master}}
|
||||
do_test attach-1.10 {
|
||||
catchsql {
|
||||
DETACH DATABASE three;
|
||||
}
|
||||
} {0 {}}
|
||||
} {1 {no such database: three}}
|
||||
do_test attach-1.11 {
|
||||
execsql {
|
||||
ATTACH 'test.db' AS db2;
|
||||
@@ -104,7 +103,7 @@ proc db_list {db} {
|
||||
}
|
||||
do_test attach-1.11b {
|
||||
db_list db
|
||||
} {0 main 2 db2 3 db3 4 db4 5 db5 6 db6 7 db7 8 db8 9 db9}
|
||||
} {0 main 1 temp 2 db2 3 db3 4 db4 5 db5 6 db6 7 db7 8 db8 9 db9}
|
||||
do_test attach-1.12 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as db2;
|
||||
@@ -151,7 +150,7 @@ do_test attach-1.20.1 {
|
||||
DETACH db5;
|
||||
}
|
||||
db_list db
|
||||
} {0 main 2 db2 3 db3 4 db4 5 db6 6 db7 7 db8 8 db9 9 db10 10 db11}
|
||||
} {0 main 1 temp 2 db2 3 db3 4 db4 5 db11 6 db6 7 db7 8 db8 9 db9 10 db10}
|
||||
integrity_check attach-1.20.2
|
||||
do_test attach-1.21 {
|
||||
catchsql {
|
||||
@@ -286,7 +285,7 @@ do_test attach-2.15 {
|
||||
} {table t2 t2 table tx tx trigger r1 t2 index i2 t2}
|
||||
do_test attach-2.16 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
ATTACH 'test2.db' AS db2;
|
||||
SELECT type, name, tbl_name FROM db2.sqlite_master;
|
||||
@@ -296,8 +295,8 @@ do_test attach-2.16 {
|
||||
do_test attach-3.1 {
|
||||
db close
|
||||
db2 close
|
||||
sqlite3 db test.db
|
||||
sqlite3 db2 test2.db
|
||||
sqlite db test.db
|
||||
sqlite db2 test2.db
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
@@ -314,8 +313,7 @@ do_test attach-3.3 {
|
||||
}
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# Even though 'db' has started a transaction, it should not yet have
|
||||
# a lock on test2.db so 'db2' should be readable.
|
||||
# Even though main has a transaction, test2.db should not be locked.
|
||||
do_test attach-3.4 {
|
||||
execsql BEGIN
|
||||
catchsql {
|
||||
@@ -323,8 +321,7 @@ do_test attach-3.4 {
|
||||
} db2;
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# Reading from test2.db from db within a transaction should not
|
||||
# prevent test2.db from being read by db2.
|
||||
# Reading from db2 should not lock test2.db
|
||||
do_test attach-3.5 {
|
||||
execsql {SELECT * FROM t2}
|
||||
catchsql {
|
||||
@@ -332,8 +329,7 @@ do_test attach-3.5 {
|
||||
} db2;
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# Making a change to test2.db through db causes test2.db to get
|
||||
# a reserved lock. It should still be accessible through db2.
|
||||
# Making a change to db2 causes test2.ddb to become locked.
|
||||
do_test attach-3.6 {
|
||||
execsql {
|
||||
UPDATE t2 SET x=x+1 WHERE x=50;
|
||||
@@ -341,67 +337,47 @@ do_test attach-3.6 {
|
||||
catchsql {
|
||||
SELECT * FROM t2;
|
||||
} db2;
|
||||
} {0 {21 x 22 y}}
|
||||
} {1 {database is locked}}
|
||||
|
||||
do_test attach-3.7 {
|
||||
execsql ROLLBACK
|
||||
execsql {SELECT * FROM t2} db2
|
||||
} {21 x 22 y}
|
||||
|
||||
# Start transactions on both db and db2. Once again, just because
|
||||
# we make a change to test2.db using db2, only a RESERVED lock is
|
||||
# obtained, so test2.db should still be readable using db.
|
||||
#
|
||||
do_test attach-3.8 {
|
||||
execsql BEGIN
|
||||
execsql BEGIN db2
|
||||
execsql {UPDATE t2 SET x=0 WHERE 0} db2
|
||||
catchsql {SELECT * FROM t2}
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# It is also still accessible from db2.
|
||||
} {1 {database is locked}}
|
||||
do_test attach-3.9 {
|
||||
catchsql {SELECT * FROM t2} db2
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
do_test attach-3.10 {
|
||||
execsql {SELECT * FROM t1}
|
||||
} {1 2 3 4}
|
||||
|
||||
do_test attach-3.11 {
|
||||
catchsql {UPDATE t1 SET a=a+1}
|
||||
} {0 {}}
|
||||
do_test attach-3.12 {
|
||||
execsql {SELECT * FROM t1}
|
||||
} {2 2 4 4}
|
||||
|
||||
# db2 has a RESERVED lock on test2.db, so db cannot write to any tables
|
||||
# in test2.db.
|
||||
do_test attach-3.13 {
|
||||
catchsql {UPDATE t2 SET x=x+1 WHERE x=50}
|
||||
} {1 {database is locked}}
|
||||
|
||||
# Change for version 3. Transaction is no longer rolled back
|
||||
# for a locked database.
|
||||
execsql {ROLLBACK}
|
||||
|
||||
# db is able to reread its schema because db2 still only holds a
|
||||
# reserved lock.
|
||||
do_test attach-3.14 {
|
||||
# Unable to reinitialize the schema tables because the aux database
|
||||
# is still locked.
|
||||
catchsql {SELECT * FROM t1}
|
||||
} {0 {1 2 3 4}}
|
||||
} {1 {database is locked}}
|
||||
do_test attach-3.15 {
|
||||
execsql COMMIT db2
|
||||
execsql {SELECT * FROM t1}
|
||||
} {1 2 3 4}
|
||||
|
||||
#set btree_trace 1
|
||||
|
||||
# Ticket #323
|
||||
do_test attach-4.1 {
|
||||
execsql {DETACH db2}
|
||||
db2 close
|
||||
sqlite3 db2 test2.db
|
||||
sqlite db2 test2.db
|
||||
execsql {
|
||||
CREATE TABLE t3(x,y);
|
||||
CREATE UNIQUE INDEX t3i1 ON t3(x);
|
||||
@@ -457,14 +433,6 @@ do_test attach-4.7 {
|
||||
SELECT * FROM main.t4;
|
||||
}
|
||||
} {main.11}
|
||||
|
||||
# This one is tricky. On the UNION ALL select, we have to make sure
|
||||
# the schema for both main and db2 is valid before starting to execute
|
||||
# the first query of the UNION ALL. If we wait to test the validity of
|
||||
# the schema for main until after the first query has run, that test will
|
||||
# fail and the query will abort but we will have already output some
|
||||
# results. When the query is retried, the results will be repeated.
|
||||
#
|
||||
do_test attach-4.8 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS db2;
|
||||
@@ -472,7 +440,6 @@ do_test attach-4.8 {
|
||||
SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4;
|
||||
}
|
||||
} {db2.6 db2.13 main.11}
|
||||
|
||||
do_test attach-4.9 {
|
||||
execsql {
|
||||
INSERT INTO main.t3 VALUES(15,16);
|
||||
@@ -510,17 +477,17 @@ do_test attach-4.13 {
|
||||
#
|
||||
do_test attach-5.1 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
sqlite db test.db
|
||||
db2 close
|
||||
file delete -force test2.db
|
||||
sqlite3 db2 test2.db
|
||||
sqlite db2 test2.db
|
||||
catchsql {
|
||||
ATTACH DATABASE 'test.db' AS orig;
|
||||
CREATE TRIGGER r1 AFTER INSERT ON orig.t1 BEGIN;
|
||||
SELECT 'no-op';
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r1 cannot reference objects in database orig}}
|
||||
} {1 {triggers may not be added to auxiliary database orig}}
|
||||
do_test attach-5.2 {
|
||||
catchsql {
|
||||
CREATE TABLE t5(x,y);
|
||||
@@ -595,10 +562,11 @@ do_test attach-6.1 {
|
||||
catchsql {
|
||||
ATTACH DATABASE 'no-such-file' AS nosuch;
|
||||
}
|
||||
} {0 {}}
|
||||
} {1 {cannot attach empty database: nosuch}}
|
||||
file delete -force no-such-file
|
||||
if {$tcl_platform(platform)=="unix"} {
|
||||
do_test attach-6.2 {
|
||||
sqlite3 dbx cannot-read
|
||||
sqlite dbx cannot-read
|
||||
dbx eval {CREATE TABLE t1(a,b,c)}
|
||||
dbx close
|
||||
file attributes cannot-read -permission 0000
|
||||
@@ -612,9 +580,7 @@ if {$tcl_platform(platform)=="unix"} {
|
||||
for {set i 2} {$i<=15} {incr i} {
|
||||
catch {db$i close}
|
||||
}
|
||||
db close
|
||||
file delete -force test2.db
|
||||
file delete -force no-such-file
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
+25
-245
@@ -12,18 +12,15 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach2.test,v 1.26 2004/09/02 14:57:09 drh Exp $
|
||||
# $Id: attach2.test,v 1.5 2004/02/12 15:31:22 drh Exp $
|
||||
#
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
# Ticket #354
|
||||
#
|
||||
# Databases test.db and test2.db contain identical schemas. Make
|
||||
# sure we can attach test2.db from test.db.
|
||||
#
|
||||
do_test attach2-1.1 {
|
||||
db eval {
|
||||
CREATE TABLE t1(a,b);
|
||||
@@ -31,7 +28,7 @@ do_test attach2-1.1 {
|
||||
}
|
||||
file delete -force test2.db
|
||||
file delete -force test2.db-journal
|
||||
sqlite3 db2 test2.db
|
||||
sqlite db2 test2.db
|
||||
db2 eval {
|
||||
CREATE TABLE t1(a,b);
|
||||
CREATE INDEX x1 ON t1(a);
|
||||
@@ -52,37 +49,38 @@ proc db_list {db} {
|
||||
}
|
||||
db eval {DETACH t2}
|
||||
do_test attach2-2.1 {
|
||||
# lock test2.db then try to attach it. This is no longer an error because
|
||||
# db2 just RESERVES the database. It does not obtain a write-lock until
|
||||
# we COMMIT.
|
||||
# lock test2.db then try to attach it. Should get an error.
|
||||
db2 eval {BEGIN}
|
||||
db2 eval {UPDATE t1 SET a = 0 WHERE 0}
|
||||
catchsql {
|
||||
ATTACH 'test2.db' AS t2;
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
do_test attach2-2.2 {
|
||||
# make sure test2.db did not get attached.
|
||||
db_list db
|
||||
} {0 main 1 temp}
|
||||
do_test attach2-2.3 {
|
||||
# unlock test2.db and try to attach again. should work this time.
|
||||
db2 eval {COMMIT}
|
||||
catchsql {
|
||||
ATTACH 'test2.db' AS t2;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach2-2.2 {
|
||||
# make sure test2.db did get attached.
|
||||
do_test attach2-2.4 {
|
||||
db_list db
|
||||
} {0 main 2 t2}
|
||||
db2 eval {COMMIT}
|
||||
|
||||
} {0 main 1 temp 2 t2}
|
||||
do_test attach2-2.5 {
|
||||
# Make sure we can read test2.db from db
|
||||
catchsql {
|
||||
SELECT name FROM t2.sqlite_master;
|
||||
}
|
||||
} {0 {t1 x1}}
|
||||
do_test attach2-2.6 {
|
||||
# lock test2.db and try to read from it. This should still work because
|
||||
# the lock is only a RESERVED lock which does not prevent reading.
|
||||
#
|
||||
# lock test2.db and try to read from it. should get an error.
|
||||
db2 eval BEGIN
|
||||
db2 eval {UPDATE t1 SET a = 0 WHERE 0}
|
||||
catchsql {
|
||||
SELECT name FROM t2.sqlite_master;
|
||||
}
|
||||
} {0 {t1 x1}}
|
||||
} {1 {database is locked}}
|
||||
do_test attach2-2.7 {
|
||||
# but we can still read from test1.db even though test2.db is locked.
|
||||
catchsql {
|
||||
@@ -110,10 +108,6 @@ do_test attach2-2.10 {
|
||||
do_test attach2-2.11 {
|
||||
# when the write failed in the previous test, the transaction should
|
||||
# have rolled back.
|
||||
#
|
||||
# Update for version 3: A transaction is no longer rolled back if a
|
||||
# database is found to be busy.
|
||||
execsql {rollback}
|
||||
db2 eval ROLLBACK
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
@@ -125,20 +119,20 @@ do_test attach2-2.12 {
|
||||
}
|
||||
} {1 {cannot commit - no transaction is active}}
|
||||
|
||||
# Ticket #574: Make sure it works using the non-callback API
|
||||
# Ticket #574: Make sure it works usingi the non-callback API
|
||||
#
|
||||
do_test attach2-3.1 {
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
set rc [catch {sqlite3_prepare $DB "ATTACH 'test2.db' AS t2" -1 TAIL} VM]
|
||||
set DB [sqlite db test.db]
|
||||
set rc [catch {sqlite_compile $DB "ATTACH 'test2.db' AS t2" TAIL} VM]
|
||||
if {$rc} {lappend rc $VM}
|
||||
sqlite3_finalize $VM
|
||||
sqlite_finalize $VM
|
||||
set rc
|
||||
} {0}
|
||||
do_test attach2-3.2 {
|
||||
set rc [catch {sqlite3_prepare $DB "DETACH t2" -1 TAIL} VM]
|
||||
set rc [catch {sqlite_compile $DB "DETACH t2" TAIL} VM]
|
||||
if {$rc} {lappend rc $VM}
|
||||
sqlite3_finalize $VM
|
||||
sqlite_finalize $VM
|
||||
set rc
|
||||
} {0}
|
||||
|
||||
@@ -146,221 +140,7 @@ db close
|
||||
for {set i 2} {$i<=15} {incr i} {
|
||||
catch {db$i close}
|
||||
}
|
||||
|
||||
# A procedure to verify the status of locks on a database.
|
||||
#
|
||||
proc lock_status {testnum db expected_result} {
|
||||
do_test attach2-$testnum [subst {
|
||||
execsql {PRAGMA lock_status} $db
|
||||
}] $expected_result
|
||||
}
|
||||
set sqlite_os_trace 0
|
||||
|
||||
# Tests attach2-4.* test that read-locks work correctly with attached
|
||||
# databases.
|
||||
do_test attach2-4.1 {
|
||||
sqlite3 db test.db
|
||||
sqlite3 db2 test.db
|
||||
execsql {ATTACH 'test2.db' as file2}
|
||||
execsql {ATTACH 'test2.db' as file2} db2
|
||||
} {}
|
||||
|
||||
lock_status 4.1.1 db {main unlocked temp closed file2 unlocked}
|
||||
lock_status 4.1.2 db2 {main unlocked temp closed file2 unlocked}
|
||||
|
||||
do_test attach2-4.2 {
|
||||
# Handle 'db' read-locks test.db
|
||||
execsql {BEGIN}
|
||||
execsql {SELECT * FROM t1}
|
||||
# Lock status:
|
||||
# db - shared(main)
|
||||
# db2 -
|
||||
} {}
|
||||
|
||||
lock_status 4.2.1 db {main shared temp closed file2 unlocked}
|
||||
lock_status 4.2.2 db2 {main unlocked temp closed file2 unlocked}
|
||||
|
||||
do_test attach2-4.3 {
|
||||
# The read lock held by db does not prevent db2 from reading test.db
|
||||
execsql {SELECT * FROM t1} db2
|
||||
} {}
|
||||
|
||||
lock_status 4.3.1 db {main shared temp closed file2 unlocked}
|
||||
lock_status 4.3.2 db2 {main unlocked temp closed file2 unlocked}
|
||||
|
||||
do_test attach2-4.4 {
|
||||
# db is holding a read lock on test.db, so we should not be able
|
||||
# to commit a write to test.db from db2
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(1, 2)
|
||||
} db2
|
||||
} {1 {database is locked}}
|
||||
|
||||
lock_status 4.4.1 db {main shared temp closed file2 unlocked}
|
||||
lock_status 4.4.2 db2 {main unlocked temp closed file2 unlocked}
|
||||
|
||||
do_test attach2-4.5 {
|
||||
# Handle 'db2' reserves file2.
|
||||
execsql {BEGIN} db2
|
||||
execsql {INSERT INTO file2.t1 VALUES(1, 2)} db2
|
||||
# Lock status:
|
||||
# db - shared(main)
|
||||
# db2 - reserved(file2)
|
||||
} {}
|
||||
|
||||
lock_status 4.5.1 db {main shared temp closed file2 unlocked}
|
||||
lock_status 4.5.2 db2 {main unlocked temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.6.1 {
|
||||
# Reads are allowed against a reserved database.
|
||||
catchsql {
|
||||
SELECT * FROM file2.t1;
|
||||
}
|
||||
# Lock status:
|
||||
# db - shared(main), shared(file2)
|
||||
# db2 - reserved(file2)
|
||||
} {0 {}}
|
||||
|
||||
lock_status 4.6.1.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.6.1.2 db2 {main unlocked temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.6.2 {
|
||||
# Writes against a reserved database are not allowed.
|
||||
catchsql {
|
||||
UPDATE file2.t1 SET a=0;
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
|
||||
lock_status 4.6.2.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.6.2.2 db2 {main unlocked temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.7 {
|
||||
# Ensure handle 'db' retains the lock on the main file after
|
||||
# failing to obtain a write-lock on file2.
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(1, 2)
|
||||
} db2
|
||||
} {0 {}}
|
||||
|
||||
lock_status 4.7.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.7.2 db2 {main reserved temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.8 {
|
||||
# We should still be able to read test.db from db2
|
||||
execsql {SELECT * FROM t1} db2
|
||||
} {1 2}
|
||||
|
||||
lock_status 4.8.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.8.2 db2 {main reserved temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.9 {
|
||||
# Try to upgrade the handle 'db' lock.
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(1, 2)
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
|
||||
lock_status 4.9.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.9.2 db2 {main reserved temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.10 {
|
||||
# We cannot commit db2 while db is holding a read-lock
|
||||
catchsql {COMMIT} db2
|
||||
} {1 {database is locked}}
|
||||
|
||||
lock_status 4.10.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.10.2 db2 {main pending temp closed file2 reserved}
|
||||
|
||||
set sqlite_os_trace 0
|
||||
do_test attach2-4.11 {
|
||||
# db is able to commit.
|
||||
catchsql {COMMIT}
|
||||
} {0 {}}
|
||||
|
||||
lock_status 4.11.1 db {main unlocked temp closed file2 unlocked}
|
||||
lock_status 4.11.2 db2 {main pending temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.12 {
|
||||
# Now we can commit db2
|
||||
catchsql {COMMIT} db2
|
||||
} {0 {}}
|
||||
|
||||
lock_status 4.12.1 db {main unlocked temp closed file2 unlocked}
|
||||
lock_status 4.12.2 db2 {main unlocked temp closed file2 unlocked}
|
||||
|
||||
do_test attach2-4.13 {
|
||||
execsql {SELECT * FROM file2.t1}
|
||||
} {1 2}
|
||||
do_test attach2-4.14 {
|
||||
execsql {INSERT INTO t1 VALUES(1, 2)}
|
||||
} {}
|
||||
do_test attach2-4.15 {
|
||||
execsql {SELECT * FROM t1} db2
|
||||
} {1 2 1 2}
|
||||
|
||||
db close
|
||||
db2 close
|
||||
file delete -force test2.db
|
||||
|
||||
# These tests - attach2-5.* - check that the master journal file is deleted
|
||||
# correctly when a multi-file transaction is committed or rolled back.
|
||||
#
|
||||
# Update: It's not actually created if a rollback occurs, so that test
|
||||
# doesn't really prove too much.
|
||||
foreach f [glob test.db*] {file delete -force $f}
|
||||
do_test attach2-5.1 {
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
ATTACH 'test.db2' AS aux;
|
||||
}
|
||||
} {}
|
||||
do_test attach2-5.2 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE tbl(a, b, c);
|
||||
CREATE TABLE aux.tbl(a, b, c);
|
||||
COMMIT;
|
||||
}
|
||||
} {}
|
||||
do_test attach2-5.3 {
|
||||
glob test.db*
|
||||
} {test.db test.db2}
|
||||
do_test attach2-5.4 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
DROP TABLE aux.tbl;
|
||||
DROP TABLE tbl;
|
||||
ROLLBACK;
|
||||
}
|
||||
} {}
|
||||
do_test attach2-5.5 {
|
||||
glob test.db*
|
||||
} {test.db test.db2}
|
||||
|
||||
# Check that a database cannot be ATTACHed or DETACHed during a transaction.
|
||||
do_test attach2-6.1 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
}
|
||||
} {}
|
||||
do_test attach2-6.2 {
|
||||
catchsql {
|
||||
ATTACH 'test3.db' as aux2;
|
||||
}
|
||||
} {1 {cannot ATTACH database within transaction}}
|
||||
|
||||
do_test attach2-6.3 {
|
||||
catchsql {
|
||||
DETACH aux;
|
||||
}
|
||||
} {1 {cannot DETACH database within transaction}}
|
||||
do_test attach2-6.4 {
|
||||
execsql {
|
||||
COMMIT;
|
||||
DETACH aux;
|
||||
}
|
||||
} {}
|
||||
|
||||
db close
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,241 +0,0 @@
|
||||
# 2003 July 1
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and schema changes to attached databases.
|
||||
#
|
||||
# $Id: attach3.test,v 1.9 2004/07/19 00:56:24 drh Exp $
|
||||
#
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Create tables t1 and t2 in the main database
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE TABLE t2(c, d);
|
||||
}
|
||||
|
||||
# Create tables t1 and t2 in database file test2.db
|
||||
file delete -force test2.db
|
||||
sqlite3 db2 test2.db
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE TABLE t2(c, d);
|
||||
} db2
|
||||
db2 close
|
||||
|
||||
# Create a table in the auxilary database.
|
||||
do_test attach3-1.1 {
|
||||
execsql {
|
||||
ATTACH 'test2.db' AS aux;
|
||||
}
|
||||
} {}
|
||||
do_test attach3-1.2 {
|
||||
execsql {
|
||||
CREATE TABLE aux.t3(e, f);
|
||||
}
|
||||
} {}
|
||||
do_test attach3-1.3 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_master WHERE name = 't3';
|
||||
}
|
||||
} {}
|
||||
do_test attach3-1.4 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 't3';
|
||||
}
|
||||
} {table t3 t3 4 {CREATE TABLE t3(e, f)}}
|
||||
do_test attach3-1.5 {
|
||||
execsql {
|
||||
INSERT INTO t3 VALUES(1, 2);
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1 2}
|
||||
|
||||
# Create an index on the auxilary database table.
|
||||
do_test attach3-2.1 {
|
||||
execsql {
|
||||
CREATE INDEX aux.i1 on t3(e);
|
||||
}
|
||||
} {}
|
||||
execsql {
|
||||
pragma vdbe_trace = off;
|
||||
}
|
||||
do_test attach3-2.2 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} {}
|
||||
do_test attach3-2.3 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} {index i1 t3 5 {CREATE INDEX i1 on t3(e)}}
|
||||
|
||||
# Drop the index on the aux database table.
|
||||
do_test attach3-3.1 {
|
||||
execsql {
|
||||
DROP INDEX aux.i1;
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} {}
|
||||
do_test attach3-3.2 {
|
||||
execsql {
|
||||
CREATE INDEX aux.i1 on t3(e);
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} {index i1 t3 5 {CREATE INDEX i1 on t3(e)}}
|
||||
do_test attach3-3.3 {
|
||||
execsql {
|
||||
DROP INDEX i1;
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} {}
|
||||
|
||||
# Drop tables t1 and t2 in the auxilary database.
|
||||
do_test attach3-4.1 {
|
||||
execsql {
|
||||
DROP TABLE aux.t1;
|
||||
SELECT name FROM aux.sqlite_master;
|
||||
}
|
||||
} {t2 t3}
|
||||
do_test attach3-4.2 {
|
||||
# This will drop main.t2
|
||||
execsql {
|
||||
DROP TABLE t2;
|
||||
SELECT name FROM aux.sqlite_master;
|
||||
}
|
||||
} {t2 t3}
|
||||
do_test attach3-4.3 {
|
||||
execsql {
|
||||
DROP TABLE t2;
|
||||
SELECT name FROM aux.sqlite_master;
|
||||
}
|
||||
} {t3}
|
||||
|
||||
# Create a view in the auxilary database.
|
||||
do_test attach3-5.1 {
|
||||
execsql {
|
||||
CREATE VIEW aux.v1 AS SELECT * FROM t3;
|
||||
}
|
||||
} {}
|
||||
do_test attach3-5.2 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'v1';
|
||||
}
|
||||
} {view v1 v1 0 {CREATE VIEW v1 AS SELECT * FROM t3}}
|
||||
do_test attach3-5.3 {
|
||||
execsql {
|
||||
INSERT INTO aux.t3 VALUES('hello', 'world');
|
||||
SELECT * FROM v1;
|
||||
}
|
||||
} {1 2 hello world}
|
||||
|
||||
# Drop the view
|
||||
do_test attach3-6.1 {
|
||||
execsql {
|
||||
DROP VIEW aux.v1;
|
||||
}
|
||||
} {}
|
||||
do_test attach3-6.2 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'v1';
|
||||
}
|
||||
} {}
|
||||
|
||||
# Create a trigger in the auxilary database.
|
||||
do_test attach3-7.1 {
|
||||
execsql {
|
||||
CREATE TRIGGER aux.tr1 AFTER INSERT ON t3 BEGIN
|
||||
INSERT INTO t3 VALUES(new.e*2, new.f*2);
|
||||
END;
|
||||
}
|
||||
} {}
|
||||
do_test attach3-7.2 {
|
||||
execsql {
|
||||
DELETE FROM t3;
|
||||
INSERT INTO t3 VALUES(10, 20);
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {10 20 20 40}
|
||||
do_test attach3-5.3 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'tr1';
|
||||
}
|
||||
} {trigger tr1 t3 0 {CREATE TRIGGER tr1 AFTER INSERT ON t3 BEGIN
|
||||
INSERT INTO t3 VALUES(new.e*2, new.f*2);
|
||||
END}}
|
||||
|
||||
# Drop the trigger
|
||||
do_test attach3-8.1 {
|
||||
execsql {
|
||||
DROP TRIGGER aux.tr1;
|
||||
}
|
||||
} {}
|
||||
do_test attach3-8.2 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'tr1';
|
||||
}
|
||||
} {}
|
||||
|
||||
# Try to trick SQLite into dropping the wrong temp trigger.
|
||||
do_test attach3-9.0 {
|
||||
execsql {
|
||||
CREATE TABLE main.t4(a, b, c);
|
||||
CREATE TABLE aux.t4(a, b, c);
|
||||
CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN
|
||||
SELECT 'hello world';
|
||||
END;
|
||||
SELECT count(*) FROM sqlite_temp_master;
|
||||
}
|
||||
} {1}
|
||||
do_test attach3-9.1 {
|
||||
execsql {
|
||||
DROP TABLE main.t4;
|
||||
SELECT count(*) FROM sqlite_temp_master;
|
||||
}
|
||||
} {1}
|
||||
do_test attach3-9.2 {
|
||||
execsql {
|
||||
DROP TABLE aux.t4;
|
||||
SELECT count(*) FROM sqlite_temp_master;
|
||||
}
|
||||
} {0}
|
||||
|
||||
# Make sure the aux.sqlite_master table is read-only
|
||||
do_test attach3-10.0 {
|
||||
catchsql {
|
||||
INSERT INTO aux.sqlite_master VALUES(1, 2, 3, 4, 5);
|
||||
}
|
||||
} {1 {table sqlite_master may not be modified}}
|
||||
|
||||
# Failure to attach leaves us in a workable state.
|
||||
# Ticket #811
|
||||
#
|
||||
do_test attach3-11.0 {
|
||||
catchsql {
|
||||
ATTACH DATABASE '/nodir/nofile.x' AS notadb;
|
||||
}
|
||||
} {1 {unable to open database: /nodir/nofile.x}}
|
||||
do_test attach3-11.1 {
|
||||
catchsql {
|
||||
ATTACH DATABASE ':memory:' AS notadb;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach3-11.2 {
|
||||
catchsql {
|
||||
DETACH DATABASE notadb;
|
||||
}
|
||||
} {0 {}}
|
||||
|
||||
finish_test
|
||||
+49
-14
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: auth.test,v 1.17 2004/07/26 12:24:24 drh Exp $
|
||||
# $Id: auth.test,v 1.12 2003/12/07 00:24:35 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -20,14 +20,10 @@ source $testdir/tester.tcl
|
||||
|
||||
# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
|
||||
# defined during compilation.
|
||||
if {[catch {db auth {}} msg]} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_test auth-1.1.1 {
|
||||
db close
|
||||
set ::DB [sqlite3 db test.db]
|
||||
set ::DB [sqlite db test.db]
|
||||
proc auth {code arg1 arg2 arg3 arg4} {
|
||||
if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
|
||||
return SQLITE_DENY
|
||||
@@ -40,9 +36,6 @@ do_test auth-1.1.1 {
|
||||
do_test auth-1.1.2 {
|
||||
db errorcode
|
||||
} {23}
|
||||
do_test auth-1.1.3 {
|
||||
db authorizer
|
||||
} {::auth}
|
||||
do_test auth-1.2 {
|
||||
execsql {SELECT name FROM sqlite_master}
|
||||
} {}
|
||||
@@ -424,13 +417,55 @@ do_test auth-1.53 {
|
||||
catchsql {SELECT * FROM t2}
|
||||
} {0 {11 2 33}}
|
||||
|
||||
# Update for version 3: There used to be a handful of test here that
|
||||
# tested the authorisation callback with the COPY command. The following
|
||||
# test makes the same database modifications as they used to.
|
||||
set f [open data1.txt w]
|
||||
puts $f "7:8:9"
|
||||
close $f
|
||||
do_test auth-1.54 {
|
||||
execsql {INSERT INTO t2 VALUES(7, 8, 9);}
|
||||
} {}
|
||||
proc auth {code arg1 arg2 arg3 arg4} {
|
||||
if {$code=="SQLITE_COPY"} {
|
||||
set ::authargs [list $arg1 $arg2 $arg3 $arg4]
|
||||
return SQLITE_DENY
|
||||
}
|
||||
return SQLITE_OK
|
||||
}
|
||||
catchsql {COPY t2 FROM 'data1.txt' USING DELIMITERS ':'}
|
||||
} {1 {not authorized}}
|
||||
do_test auth-1.55 {
|
||||
set ::authargs
|
||||
} {t2 data1.txt main {}}
|
||||
do_test auth-1.56 {
|
||||
execsql {SELECT * FROM t2}
|
||||
} {11 2 33}
|
||||
do_test auth-1.57 {
|
||||
proc auth {code arg1 arg2 arg3 arg4} {
|
||||
if {$code=="SQLITE_COPY"} {
|
||||
set ::authargs [list $arg1 $arg2 $arg3 $arg4]
|
||||
return SQLITE_IGNORE
|
||||
}
|
||||
return SQLITE_OK
|
||||
}
|
||||
catchsql {COPY t2 FROM 'data1.txt' USING DELIMITERS ':'}
|
||||
} {0 {}}
|
||||
do_test auth-1.58 {
|
||||
set ::authargs
|
||||
} {t2 data1.txt main {}}
|
||||
do_test auth-1.59 {
|
||||
execsql {SELECT * FROM t2}
|
||||
} {11 2 33}
|
||||
do_test auth-1.60 {
|
||||
proc auth {code arg1 arg2 arg3 arg4} {
|
||||
if {$code=="SQLITE_COPY"} {
|
||||
set ::authargs [list $arg1 $arg2 $arg3 $arg4]
|
||||
return SQLITE_OK
|
||||
}
|
||||
return SQLITE_OK
|
||||
}
|
||||
catchsql {COPY t2 FROM 'data1.txt' USING DELIMITERS ':'}
|
||||
} {0 {}}
|
||||
do_test auth-1.61 {
|
||||
set ::authargs
|
||||
} {t2 data1.txt main {}}
|
||||
do_test auth-1.62 {
|
||||
execsql {SELECT * FROM t2}
|
||||
} {11 2 33 7 8 9}
|
||||
|
||||
|
||||
+7
-12
@@ -12,7 +12,7 @@
|
||||
# focus of this script testing the ability of SQLite to handle database
|
||||
# files larger than 4GB.
|
||||
#
|
||||
# $Id: bigfile.test,v 1.6 2004/06/30 11:28:13 drh Exp $
|
||||
# $Id: bigfile.test,v 1.3 2003/12/19 12:31:22 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -24,10 +24,6 @@ source $testdir/tester.tcl
|
||||
scan $::tcl_version %f vx
|
||||
if {$vx<8.4} return
|
||||
|
||||
# Mac OS X does not handle large files efficiently. So skip this test
|
||||
# on that platform.
|
||||
if {$tcl_platform(os)=="Darwin"} return
|
||||
|
||||
# This is the md5 checksum of all the data in table t1 as created
|
||||
# by the first test. We will use this number to make sure that data
|
||||
# never changes.
|
||||
@@ -65,13 +61,12 @@ if {[catch {fake_big_file 4096 test.db}]} {
|
||||
}
|
||||
|
||||
do_test bigfile-1.2 {
|
||||
sqlite3 db test.db
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
|
||||
|
||||
# The previous test may fail on some systems because they are unable
|
||||
# to handle large files. If that is so, then skip all of the following
|
||||
# tests. We will know the above test failed because the "db" command
|
||||
@@ -87,7 +82,7 @@ do_test bigfile-1.3 {
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.4 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
@@ -106,7 +101,7 @@ if {[catch {fake_big_file 8192 test.db}]} {
|
||||
}
|
||||
|
||||
do_test bigfile-1.6 {
|
||||
sqlite3 db test.db
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
@@ -119,7 +114,7 @@ do_test bigfile-1.7 {
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.8 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
@@ -143,7 +138,7 @@ if {[catch {fake_big_file 16384 test.db}]} {
|
||||
}
|
||||
|
||||
do_test bigfile-1.11 {
|
||||
sqlite3 db test.db
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
@@ -156,7 +151,7 @@ do_test bigfile-1.12 {
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.13 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
|
||||
+4
-12
@@ -12,7 +12,7 @@
|
||||
# focus of this file is stressing the library by putting large amounts
|
||||
# of data in a single row of a table.
|
||||
#
|
||||
# $Id: bigrow.test,v 1.5 2004/08/07 23:54:48 drh Exp $
|
||||
# $Id: bigrow.test,v 1.4 2001/11/24 00:31:47 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -205,18 +205,10 @@ for {set sz 60} {$sz<1048560} {incr sz $sz} {
|
||||
incr i
|
||||
}
|
||||
do_test bigrow-5.3 {
|
||||
catchsql {UPDATE t1 SET b=b||b}
|
||||
} {0 {}}
|
||||
set r [catch {execsql {UPDATE t1 SET b=b||b}} msg]
|
||||
lappend r $msg
|
||||
} {1 {too much data for one table row}}
|
||||
do_test bigrow-5.4 {
|
||||
execsql {SELECT length(b) FROM t1}
|
||||
} 1966080
|
||||
do_test bigrow-5.5 {
|
||||
catchsql {UPDATE t1 SET b=b||b}
|
||||
} {0 {}}
|
||||
do_test bigrow-5.6 {
|
||||
execsql {SELECT length(b) FROM t1}
|
||||
} 3932160
|
||||
do_test bigrow-5.99 {
|
||||
execsql {DROP TABLE t1}
|
||||
} {}
|
||||
|
||||
|
||||
+10
-227
@@ -11,48 +11,19 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the sqlite_bind API.
|
||||
#
|
||||
# $Id: bind.test,v 1.18 2004/08/25 04:07:03 drh Exp $
|
||||
# $Id: bind.test,v 1.1 2003/09/06 22:45:21 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
proc sqlite_step {stmt N VALS COLS} {
|
||||
upvar VALS vals
|
||||
upvar COLS cols
|
||||
set vals [list]
|
||||
set cols [list]
|
||||
|
||||
set rc [sqlite3_step $stmt]
|
||||
for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} {
|
||||
lappend cols [sqlite3_column_name $stmt $i]
|
||||
}
|
||||
for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} {
|
||||
lappend vals [sqlite3_column_text $stmt $i]
|
||||
}
|
||||
|
||||
return $rc
|
||||
}
|
||||
|
||||
do_test bind-1.1 {
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
execsql {CREATE TABLE t1(a,b,c);}
|
||||
set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:1,?,:abc)} -1 TAIL]
|
||||
set DB [sqlite db test.db]
|
||||
execsql {CREATE TABLE t1(a,b,c)}
|
||||
set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test bind-1.1.1 {
|
||||
sqlite3_bind_parameter_count $VM
|
||||
} 3
|
||||
do_test bind-1.1.2 {
|
||||
sqlite3_bind_parameter_name $VM 1
|
||||
} {:1}
|
||||
do_test bind-1.1.3 {
|
||||
sqlite3_bind_parameter_name $VM 2
|
||||
} {}
|
||||
do_test bind-1.1.4 {
|
||||
sqlite3_bind_parameter_name $VM 3
|
||||
} {:abc}
|
||||
do_test bind-1.2 {
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} {SQLITE_DONE}
|
||||
@@ -60,7 +31,7 @@ do_test bind-1.3 {
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 {} {} {}}
|
||||
do_test bind-1.4 {
|
||||
sqlite3_reset $VM
|
||||
sqlite_reset $VM
|
||||
sqlite_bind $VM 1 {test value 1} normal
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} SQLITE_DONE
|
||||
@@ -68,7 +39,7 @@ do_test bind-1.5 {
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 {} {} {} 2 {test value 1} {} {}}
|
||||
do_test bind-1.6 {
|
||||
sqlite3_reset $VM
|
||||
sqlite_reset $VM
|
||||
sqlite_bind $VM 3 {'test value 2'} normal
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} SQLITE_DONE
|
||||
@@ -76,7 +47,7 @@ do_test bind-1.7 {
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}}
|
||||
do_test bind-1.8 {
|
||||
sqlite3_reset $VM
|
||||
sqlite_reset $VM
|
||||
set sqlite_static_bind_value 123
|
||||
sqlite_bind $VM 1 {} static
|
||||
sqlite_bind $VM 2 {abcdefg} normal
|
||||
@@ -86,204 +57,16 @@ do_test bind-1.8 {
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 123 abcdefg {}}
|
||||
do_test bind-1.9 {
|
||||
sqlite3_reset $VM
|
||||
sqlite_reset $VM
|
||||
sqlite_bind $VM 1 {456} normal
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 123 abcdefg {} 2 456 abcdefg {}}
|
||||
|
||||
|
||||
do_test bind-1.99 {
|
||||
sqlite3_finalize $VM
|
||||
} SQLITE_OK
|
||||
|
||||
do_test bind-2.1 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
}
|
||||
set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES($one,$::two,${x})} -1 TAIL]
|
||||
set TAIL
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
do_test bind-2.1.1 {
|
||||
sqlite3_bind_parameter_count $VM
|
||||
} 3
|
||||
do_test bind-2.1.2 {
|
||||
sqlite3_bind_parameter_name $VM 1
|
||||
} {$one}
|
||||
do_test bind-2.1.3 {
|
||||
sqlite3_bind_parameter_name $VM 2
|
||||
} {$::two}
|
||||
do_test bind-2.1.4 {
|
||||
sqlite3_bind_parameter_name $VM 3
|
||||
} {${x}}
|
||||
|
||||
# 32 bit Integers
|
||||
do_test bind-2.2 {
|
||||
sqlite3_bind_int $VM 1 123
|
||||
sqlite3_bind_int $VM 2 456
|
||||
sqlite3_bind_int $VM 3 789
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
sqlite3_reset $VM
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 123 456 789}
|
||||
do_test bind-2.3 {
|
||||
sqlite3_bind_int $VM 2 -2000000000
|
||||
sqlite3_bind_int $VM 3 2000000000
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
sqlite3_reset $VM
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 123 456 789 2 123 -2000000000 2000000000}
|
||||
do_test bind-2.4 {
|
||||
execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
|
||||
} {integer integer integer integer integer integer}
|
||||
do_test bind-2.5 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# 64 bit Integers
|
||||
do_test bind-3.1 {
|
||||
sqlite3_bind_int64 $VM 1 32
|
||||
sqlite3_bind_int64 $VM 2 -2000000000000
|
||||
sqlite3_bind_int64 $VM 3 2000000000000
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
sqlite3_reset $VM
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 32 -2000000000000 2000000000000}
|
||||
do_test bind-3.2 {
|
||||
execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
|
||||
} {integer integer integer}
|
||||
do_test bind-3.3 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Doubles
|
||||
do_test bind-4.1 {
|
||||
sqlite3_bind_double $VM 1 1234.1234
|
||||
sqlite3_bind_double $VM 2 0.00001
|
||||
sqlite3_bind_double $VM 3 123456789
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
sqlite3_reset $VM
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 1234.1234 1e-05 123456789.0}
|
||||
do_test bind-4.2 {
|
||||
execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
|
||||
} {real real real}
|
||||
do_test bind-4.3 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# NULL
|
||||
do_test bind-5.1 {
|
||||
sqlite3_bind_null $VM 1
|
||||
sqlite3_bind_null $VM 2
|
||||
sqlite3_bind_null $VM 3
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
sqlite3_reset $VM
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 {} {} {}}
|
||||
do_test bind-5.2 {
|
||||
execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
|
||||
} {null null null}
|
||||
do_test bind-5.3 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# UTF-8 text
|
||||
do_test bind-6.1 {
|
||||
sqlite3_bind_text $VM 1 hellothere 5
|
||||
sqlite3_bind_text $VM 2 ".." 1
|
||||
sqlite3_bind_text $VM 3 world -1
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
sqlite3_reset $VM
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 hello . world}
|
||||
do_test bind-6.2 {
|
||||
execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
|
||||
} {text text text}
|
||||
do_test bind-6.3 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# UTF-16 text
|
||||
do_test bind-7.1 {
|
||||
sqlite3_bind_text16 $VM 1 [encoding convertto unicode hellothere] 10
|
||||
sqlite3_bind_text16 $VM 2 [encoding convertto unicode ""] 0
|
||||
sqlite3_bind_text16 $VM 3 [encoding convertto unicode world] 10
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
sqlite3_reset $VM
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 hello {} world}
|
||||
do_test bind-7.2 {
|
||||
execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
|
||||
} {text text text}
|
||||
do_test bind-7.3 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Test that the 'out of range' error works.
|
||||
do_test bind-8.1 {
|
||||
catch { sqlite3_bind_null $VM 0 }
|
||||
} {1}
|
||||
do_test bind-8.2 {
|
||||
sqlite3_errmsg $DB
|
||||
} {bind index out of range}
|
||||
do_test bind-8.3 {
|
||||
encoding convertfrom unicode [sqlite3_errmsg16 $DB]
|
||||
} {bind index out of range}
|
||||
do_test bind-8.4 {
|
||||
sqlite3_bind_null $VM 1
|
||||
sqlite3_errmsg $DB
|
||||
} {not an error}
|
||||
do_test bind-8.5 {
|
||||
catch { sqlite3_bind_null $VM 4 }
|
||||
} {1}
|
||||
do_test bind-8.6 {
|
||||
sqlite3_errmsg $DB
|
||||
} {bind index out of range}
|
||||
do_test bind-8.7 {
|
||||
encoding convertfrom unicode [sqlite3_errmsg16 $DB]
|
||||
} {bind index out of range}
|
||||
|
||||
do_test bind-8.8 {
|
||||
catch { sqlite3_bind_blob $VM 0 "abc" 3 }
|
||||
} {1}
|
||||
do_test bind-8.9 {
|
||||
catch { sqlite3_bind_blob $VM 4 "abc" 3 }
|
||||
} {1}
|
||||
do_test bind-8.10 {
|
||||
catch { sqlite3_bind_text $VM 0 "abc" 3 }
|
||||
} {1}
|
||||
do_test bind-8.11 {
|
||||
catch { sqlite3_bind_text16 $VM 4 "abc" 2 }
|
||||
} {1}
|
||||
do_test bind-8.12 {
|
||||
catch { sqlite3_bind_int $VM 0 5 }
|
||||
} {1}
|
||||
do_test bind-8.13 {
|
||||
catch { sqlite3_bind_int $VM 4 5 }
|
||||
} {1}
|
||||
do_test bind-8.14 {
|
||||
catch { sqlite3_bind_double $VM 0 5.0 }
|
||||
} {1}
|
||||
do_test bind-8.15 {
|
||||
catch { sqlite3_bind_double $VM 4 6.0 }
|
||||
} {1}
|
||||
|
||||
do_test bind-9.99 {
|
||||
sqlite3_finalize $VM
|
||||
} SQLITE_OK
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
-120
@@ -1,120 +0,0 @@
|
||||
# 2001 September 15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
# $Id: blob.test,v 1.2 2004/06/19 00:16:31 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
proc bin_to_hex {blob} {
|
||||
set bytes {}
|
||||
binary scan $blob \c* bytes
|
||||
set bytes2 [list]
|
||||
foreach b $bytes {lappend bytes2 [format %02X [expr $b & 0xFF]]}
|
||||
join $bytes2 {}
|
||||
}
|
||||
|
||||
# Simplest possible case. Specify a blob literal
|
||||
do_test blob-1.0 {
|
||||
set blob [execsql {SELECT X'01020304'}]
|
||||
bin_to_hex [lindex $blob 0]
|
||||
} {01020304}
|
||||
do_test blob-1.1 {
|
||||
set blob [execsql {SELECT x'ABCDEF'}]
|
||||
bin_to_hex [lindex $blob 0]
|
||||
} {ABCDEF}
|
||||
do_test blob-1.2 {
|
||||
set blob [execsql {SELECT x''}]
|
||||
bin_to_hex [lindex $blob 0]
|
||||
} {}
|
||||
do_test blob-1.3 {
|
||||
set blob [execsql {SELECT x'abcdEF12'}]
|
||||
bin_to_hex [lindex $blob 0]
|
||||
} {ABCDEF12}
|
||||
|
||||
# Try some syntax errors in blob literals.
|
||||
do_test blob-1.4 {
|
||||
catchsql {SELECT X'01020k304', 100}
|
||||
} {1 {unrecognized token: "X'01020"}}
|
||||
do_test blob-1.5 {
|
||||
catchsql {SELECT X'01020, 100}
|
||||
} {1 {unrecognized token: "X'01020"}}
|
||||
do_test blob-1.6 {
|
||||
catchsql {SELECT X'01020 100'}
|
||||
} {1 {unrecognized token: "X'01020"}}
|
||||
do_test blob-1.7 {
|
||||
catchsql {SELECT X'01001'}
|
||||
} {1 {unrecognized token: "X'01001'"}}
|
||||
|
||||
# Insert a blob into a table and retrieve it.
|
||||
do_test blob-2.0 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a BLOB, b BLOB);
|
||||
INSERT INTO t1 VALUES(X'123456', x'7890ab');
|
||||
INSERT INTO t1 VALUES(X'CDEF12', x'345678');
|
||||
}
|
||||
set blobs [execsql {SELECT * FROM t1}]
|
||||
set blobs2 [list]
|
||||
foreach b $blobs {lappend blobs2 [bin_to_hex $b]}
|
||||
set blobs2
|
||||
} {123456 7890AB CDEF12 345678}
|
||||
|
||||
# An index on a blob column
|
||||
do_test blob-2.1 {
|
||||
execsql {
|
||||
CREATE INDEX i1 ON t1(a);
|
||||
}
|
||||
set blobs [execsql {SELECT * FROM t1}]
|
||||
set blobs2 [list]
|
||||
foreach b $blobs {lappend blobs2 [bin_to_hex $b]}
|
||||
set blobs2
|
||||
} {123456 7890AB CDEF12 345678}
|
||||
do_test blob-2.2 {
|
||||
set blobs [execsql {SELECT * FROM t1 where a = X'123456'}]
|
||||
set blobs2 [list]
|
||||
foreach b $blobs {lappend blobs2 [bin_to_hex $b]}
|
||||
set blobs2
|
||||
} {123456 7890AB}
|
||||
do_test blob-2.3 {
|
||||
set blobs [execsql {SELECT * FROM t1 where a = X'CDEF12'}]
|
||||
set blobs2 [list]
|
||||
foreach b $blobs {lappend blobs2 [bin_to_hex $b]}
|
||||
set blobs2
|
||||
} {CDEF12 345678}
|
||||
do_test blob-2.4 {
|
||||
set blobs [execsql {SELECT * FROM t1 where a = X'CD12'}]
|
||||
set blobs2 [list]
|
||||
foreach b $blobs {lappend blobs2 [bin_to_hex $b]}
|
||||
set blobs2
|
||||
} {}
|
||||
|
||||
# Try to bind a blob value to a prepared statement.
|
||||
do_test blob-3.0 {
|
||||
set DB [sqlite3 db2 test.db]
|
||||
set STMT [sqlite3_prepare $DB "DELETE FROM t1 WHERE a = ?" -1 DUMMY]
|
||||
sqlite3_bind_blob $STMT 1 "\x12\x34\x56" 3
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test blob-3.1 {
|
||||
sqlite3_finalize $STMT
|
||||
db2 close
|
||||
} {}
|
||||
do_test blob-2.3 {
|
||||
set blobs [execsql {SELECT * FROM t1}]
|
||||
set blobs2 [list]
|
||||
foreach b $blobs {lappend blobs2 [bin_to_hex $b]}
|
||||
set blobs2
|
||||
} {CDEF12 345678}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
+256
-271
File diff suppressed because it is too large
Load Diff
+34
-72
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# $Id: btree2.test,v 1.13 2004/05/10 16:18:48 drh Exp $
|
||||
# $Id: btree2.test,v 1.10 2002/02/19 13:39:23 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -34,30 +34,26 @@ do_test btree2-1.1 {
|
||||
expr srand(1)
|
||||
file delete -force test2.bt
|
||||
file delete -force test2.bt-journal
|
||||
set ::b [btree_open test2.bt 2000 0]
|
||||
set ::b [btree_open test2.bt]
|
||||
btree_begin_transaction $::b
|
||||
btree_create_table $::b 0
|
||||
} {2}
|
||||
do_test btree2-1.2 {
|
||||
btree_create_table $::b 0
|
||||
btree_create_table $::b
|
||||
} {3}
|
||||
do_test btree2-1.3 {
|
||||
btree_create_table $::b 0
|
||||
do_test btree2-1.2 {
|
||||
btree_create_table $::b
|
||||
} {4}
|
||||
do_test btree2-1.4 {
|
||||
btree_create_table $::b 0
|
||||
do_test btree2-1.3 {
|
||||
btree_create_table $::b
|
||||
} {5}
|
||||
do_test btree2-1.5 {
|
||||
btree_create_table $::b 0
|
||||
do_test btree2-1.4 {
|
||||
btree_create_table $::b
|
||||
} {6}
|
||||
do_test btree2-1.6 {
|
||||
do_test btree2-1.5 {
|
||||
set ::c2 [btree_cursor $::b 2 1]
|
||||
btree_insert $::c2 {one} {1}
|
||||
btree_move_to $::c2 {one}
|
||||
btree_delete $::c2
|
||||
btree_close_cursor $::c2
|
||||
btree_commit $::b
|
||||
btree_integrity_check $::b 1 2 3 4 5 6
|
||||
btree_integrity_check $::b 2 3 4 5 6
|
||||
} {}
|
||||
|
||||
# This test module works by making lots of pseudo-random changes to a
|
||||
@@ -73,7 +69,7 @@ do_test btree2-1.6 {
|
||||
# for foreground and background tables.
|
||||
#
|
||||
# 2. The union of the foreground an background tables consists of N entries
|
||||
# where each entry has an L-digit key. (Actually, some keys can be longer
|
||||
# where each entry an L-digit key. (Actually, some keys can be longer
|
||||
# than L characters, but they always start with L digits.) The keys
|
||||
# cover all integers between 1 and N. Whenever an entry is added to
|
||||
# the foreground it is removed form the background and vice versa.
|
||||
@@ -129,7 +125,7 @@ proc make_payload {keynum L len} {
|
||||
# success or an error message if something is amiss.
|
||||
#
|
||||
proc check_invariants {} {
|
||||
set ck [btree_integrity_check $::b 1 2 3 4 5 6]
|
||||
set ck [btree_integrity_check $::b 2 3 4 5 6]
|
||||
if {$ck!=""} {
|
||||
puts "\n*** SANITY:\n$ck"
|
||||
exit
|
||||
@@ -149,6 +145,10 @@ proc check_invariants {} {
|
||||
set key [btree_key $::c4]
|
||||
if {[scan $key %d k]<1} {set k 0}
|
||||
if {$k!=$i} {
|
||||
# puts "MISSING $i"
|
||||
# puts {Page 3:}; btree_page_dump $::b 3
|
||||
# puts {Page 4:}; btree_page_dump $::b 4
|
||||
# exit
|
||||
return "Key $i is missing from both foreground and background"
|
||||
}
|
||||
set data [btree_data $::c4]
|
||||
@@ -185,32 +185,6 @@ proc check_invariants {} {
|
||||
}
|
||||
}
|
||||
|
||||
# Look at all elements in both the foreground and background tables.
|
||||
# Make sure the key is always the same as the prefix of the data.
|
||||
#
|
||||
# This routine was used for hunting bugs. It is not a part of standard
|
||||
# tests.
|
||||
#
|
||||
proc check_data {n key} {
|
||||
global c3 c4
|
||||
incr n -1
|
||||
foreach c [list $c3 $c4] {
|
||||
btree_first $c ;# move_to $c $key
|
||||
set cnt 0
|
||||
while {![btree_eof $c]} {
|
||||
set key [btree_key $c]
|
||||
set data [btree_data $c]
|
||||
if {[string range $key 0 $n] ne [string range $data 0 $n]} {
|
||||
puts "key=[list $key] data=[list $data] n=$n"
|
||||
puts "cursor info = [btree_cursor_info $c]"
|
||||
btree_page_dump $::b [lindex [btree_cursor_info $c] 0]
|
||||
exit
|
||||
}
|
||||
btree_next $c
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Make random changes to the database such that each change preserves
|
||||
# the invariants. The number of changes is $n*N where N is the parameter
|
||||
# from the descriptor table. Each changes begins with a random key.
|
||||
@@ -220,7 +194,6 @@ proc check_data {n key} {
|
||||
#
|
||||
set chngcnt 0
|
||||
proc random_changes {n I K D} {
|
||||
global chngcnt
|
||||
btree_move_to $::c2 N
|
||||
set N [btree_data $::c2]
|
||||
btree_move_to $::c2 L
|
||||
@@ -233,6 +206,9 @@ proc random_changes {n I K D} {
|
||||
set insert [expr {rand()<=$I}]
|
||||
set longkey [expr {rand()<=$K}]
|
||||
set longdata [expr {rand()<=$D}]
|
||||
# incr ::chngcnt
|
||||
# if {$::chngcnt==251} {btree_tree_dump $::b 3}
|
||||
# puts "CHANGE $::chngcnt: $k $insert $longkey $longdata"
|
||||
if {$longkey} {
|
||||
set x [expr {rand()}]
|
||||
set keylen [expr {int($x*$x*$x*$x*3000)+10}]
|
||||
@@ -268,17 +244,6 @@ proc random_changes {n I K D} {
|
||||
if {$kx==$k} {
|
||||
btree_delete $::c4
|
||||
}
|
||||
# For debugging - change the "0" to "1" to integrity check after
|
||||
# every change.
|
||||
if 0 {
|
||||
incr chngcnt
|
||||
puts check----$chngcnt
|
||||
set ck [btree_integrity_check $::b 1 2 3 4 5 6]
|
||||
if {$ck!=""} {
|
||||
puts "\nSANITY CHECK FAILED!\n$ck"
|
||||
exit
|
||||
}
|
||||
}
|
||||
if {$insert} {
|
||||
btree_insert $::c3 $key $data
|
||||
} else {
|
||||
@@ -294,20 +259,15 @@ proc random_changes {n I K D} {
|
||||
} elseif {[btree_move_to $::c6 $basekey]==0} {
|
||||
btree_delete $::c6
|
||||
}
|
||||
# For debugging - change the "0" to "1" to integrity check after
|
||||
# every change.
|
||||
if 0 {
|
||||
incr chngcnt
|
||||
puts check----$chngcnt
|
||||
set ck [btree_integrity_check $::b 1 2 3 4 5 6]
|
||||
if {$ck!=""} {
|
||||
puts "\nSANITY CHECK FAILED!\n$ck"
|
||||
exit
|
||||
}
|
||||
}
|
||||
# set ck [btree_integrity_check $::b 2 3 4 5 6]
|
||||
# if {$ck!=""} {
|
||||
# puts "\nSANITY CHECK FAILED!\n$ck"
|
||||
# exit
|
||||
# }
|
||||
# puts "PAGE 3:"; btree_page_dump $::b 3
|
||||
# puts "PAGE 4:"; btree_page_dump $::b 4
|
||||
}
|
||||
}
|
||||
set btree_trace 0
|
||||
|
||||
# Repeat this test sequence on database of various sizes
|
||||
#
|
||||
@@ -367,7 +327,7 @@ foreach {N L} {
|
||||
do_test btree2-$testno.7 {
|
||||
btree_close $::b
|
||||
} {}
|
||||
|
||||
after 100
|
||||
# For each database size, run various changes tests.
|
||||
#
|
||||
set num2 1
|
||||
@@ -383,7 +343,7 @@ foreach {N L} {
|
||||
set testid btree2-$testno.8.$num2
|
||||
set hash [md5file test2.bt]
|
||||
do_test $testid.0 {
|
||||
set ::b [btree_open test2.bt 2000 0]
|
||||
set ::b [btree_open test2.bt]
|
||||
set ::c2 [btree_cursor $::b 2 1]
|
||||
set ::c3 [btree_cursor $::b 3 1]
|
||||
set ::c4 [btree_cursor $::b 4 1]
|
||||
@@ -393,12 +353,13 @@ foreach {N L} {
|
||||
} {}
|
||||
set cnt 6
|
||||
for {set i 2} {$i<=6} {incr i} {
|
||||
if {[lindex [btree_cursor_info [set ::c$i]] 0]!=$i} {incr cnt}
|
||||
if {[lindex [btree_cursor_dump [set ::c$i]] 0]!=$i} {incr cnt}
|
||||
}
|
||||
do_test $testid.1 {
|
||||
btree_begin_transaction $::b
|
||||
lindex [btree_pager_stats $::b] 1
|
||||
} $cnt
|
||||
# exec cp test2.bt test2.bt.bu1
|
||||
do_test $testid.2 [subst {
|
||||
random_changes $n $I $K $D
|
||||
}] {}
|
||||
@@ -414,6 +375,7 @@ foreach {N L} {
|
||||
btree_rollback $::b
|
||||
md5file test2.bt
|
||||
} $hash
|
||||
# exec cp test2.bt test2.bt.bu2
|
||||
btree_begin_transaction $::b
|
||||
set ::c2 [btree_cursor $::b 2 1]
|
||||
set ::c3 [btree_cursor $::b 3 1]
|
||||
@@ -441,7 +403,7 @@ foreach {N L} {
|
||||
} {0}
|
||||
do_test $testid.9 {
|
||||
btree_close $::b
|
||||
set ::b [btree_open test2.bt 2000 0]
|
||||
set ::b [btree_open test2.bt]
|
||||
set ::c2 [btree_cursor $::b 2 1]
|
||||
set ::c3 [btree_cursor $::b 3 1]
|
||||
set ::c4 [btree_cursor $::b 4 1]
|
||||
@@ -463,7 +425,7 @@ foreach {N L} {
|
||||
incr num2
|
||||
}
|
||||
incr testno
|
||||
set ::b [btree_open test2.bt 2000 0]
|
||||
set ::b [btree_open test2.bt]
|
||||
}
|
||||
|
||||
# Testing is complete. Shut everything down.
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
# 2001 November 22
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# In particular, this file tests a small part of the Delete logic
|
||||
# for the BTree backend. When a row is deleted from a table, the
|
||||
# cursor is suppose to be left pointing at either the previous or
|
||||
# next entry in that table. If the cursor is left pointing at the
|
||||
# next entry, then the next Next operation is ignored. So the
|
||||
# sequence of operations (Delete, Next) should always leave the
|
||||
# cursor pointing at the first entry past the one that was deleted.
|
||||
# This test is designed to verify that behavior.
|
||||
#
|
||||
# $Id: btree3.test,v 1.2 2002/12/04 13:40:27 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
if {[info commands btree_open]!=""} {
|
||||
|
||||
# Open a test database.
|
||||
#
|
||||
file delete -force test1.bt
|
||||
file delete -force test1.bt-journal
|
||||
set b1 [btree_open test1.bt]
|
||||
btree_begin_transaction $::b1
|
||||
|
||||
# Insert a few one records
|
||||
#
|
||||
set data {abcdefghijklmnopqrstuvwxyz0123456789}
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
for {set k 2} {$k<=10} {incr k} {
|
||||
for {set j 1} {$j<=$k} {incr j} {
|
||||
set jkey [format %02d $j]
|
||||
btree_clear_table $::b1 2
|
||||
set ::c1 [btree_cursor $::b1 2 1]
|
||||
for {set i 1} {$i<=$k} {incr i} {
|
||||
set key [format %02d $i]
|
||||
do_test btree3-$k.$j.1.$i {
|
||||
btree_insert $::c1 $::key $::data
|
||||
} {}
|
||||
# btree_tree_dump $::b1 2
|
||||
}
|
||||
do_test btree3-$k.$j.2 {
|
||||
btree_move_to $::c1 $::jkey
|
||||
btree_key $::c1
|
||||
} $::jkey
|
||||
do_test btree3-$k.$j.3 {
|
||||
btree_delete $::c1
|
||||
} {}
|
||||
if {$j<$k} {
|
||||
do_test btree3-$k.$j.4 {
|
||||
btree_next $::c1
|
||||
btree_key $::c1
|
||||
} [format %02d [expr $j+1]]
|
||||
}
|
||||
if {$j>1} {
|
||||
do_test btree3-$k.$j.5 {
|
||||
btree_prev $::c1
|
||||
btree_key $::c1
|
||||
} [format %02d [expr $j-1]]
|
||||
}
|
||||
btree_close_cursor $::c1
|
||||
}
|
||||
}
|
||||
|
||||
btree_rollback $::b1
|
||||
btree_pager_ref_dump $::b1
|
||||
btree_close $::b1
|
||||
|
||||
} ;# end if( not mem: and has pager_open command );
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,84 @@
|
||||
# 2001 November 22
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# In particular, this file tests a small part of the Delete logic
|
||||
# for the BTree backend. When a row is deleted from a table, the
|
||||
# cursor is suppose to be left pointing at either the previous or
|
||||
# next entry in that table. If the cursor is left pointing at the
|
||||
# next entry, then the next Next operation is ignored. So the
|
||||
# sequence of operations (Delete, Next) should always leave the
|
||||
# cursor pointing at the first entry past the one that was deleted.
|
||||
# This test is designed to verify that behavior.
|
||||
#
|
||||
# $Id: btree3rb.test,v 1.1 2003/04/20 23:45:23 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
if {[info commands btree_open]!=""} {
|
||||
|
||||
# Open a test database.
|
||||
#
|
||||
set b1 [btree_open :memory:]
|
||||
btree_begin_transaction $::b1
|
||||
|
||||
# Insert a few one records
|
||||
#
|
||||
set data {abcdefghijklmnopqrstuvwxyz0123456789}
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
for {set k 2} {$k<=20} {incr k} {
|
||||
for {set j 1} {$j<=$k} {incr j} {
|
||||
set jkey [format %02d $j]
|
||||
btree_clear_table $::b1 2
|
||||
set ::c1 [btree_cursor $::b1 2 1]
|
||||
for {set i 1} {$i<=$k} {incr i} {
|
||||
set key [format %02d $i]
|
||||
do_test btree3rb-$k.$j.1.$i {
|
||||
btree_insert $::c1 $::key $::data
|
||||
} {}
|
||||
# btree_tree_dump $::b1 2
|
||||
}
|
||||
do_test btree3rb-$k.$j.2 {
|
||||
btree_move_to $::c1 $::jkey
|
||||
btree_key $::c1
|
||||
} $::jkey
|
||||
do_test btree3rb-$k.$j.3 {
|
||||
btree_delete $::c1
|
||||
} {}
|
||||
if {$j<$k} {
|
||||
do_test btree3rb-$k.$j.4 {
|
||||
btree_next $::c1
|
||||
btree_key $::c1
|
||||
} [format %02d [expr $j+1]]
|
||||
}
|
||||
if {$j>1} {
|
||||
do_test btree3rb-$k.$j.5 {
|
||||
btree_prev $::c1
|
||||
btree_key $::c1
|
||||
} [format %02d [expr $j-1]]
|
||||
}
|
||||
btree_close_cursor $::c1
|
||||
}
|
||||
}
|
||||
|
||||
btree_rollback $::b1
|
||||
#btree_pager_ref_dump $::b1
|
||||
btree_close $::b1
|
||||
|
||||
} ;# end if( not mem: and has pager_open command );
|
||||
|
||||
finish_test
|
||||
+3
-6
@@ -15,7 +15,7 @@
|
||||
# sqliteBtreePrevious() procedures and making sure they are able
|
||||
# to step through an entire table from either direction.
|
||||
#
|
||||
# $Id: btree4.test,v 1.2 2004/05/09 20:40:12 drh Exp $
|
||||
# $Id: btree4.test,v 1.1 2002/12/04 13:40:27 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -27,11 +27,8 @@ if {[info commands btree_open]!=""} {
|
||||
#
|
||||
file delete -force test1.bt
|
||||
file delete -force test1.bt-journal
|
||||
set b1 [btree_open test1.bt 2000 0]
|
||||
btree_begin_transaction $b1
|
||||
do_test btree4-0.1 {
|
||||
btree_create_table $b1 0
|
||||
} 2
|
||||
set b1 [btree_open test1.bt]
|
||||
btree_begin_transaction $::b1
|
||||
|
||||
set data {abcdefghijklmnopqrstuvwxyz0123456789}
|
||||
append data $data
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
# 2002 December 03
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# This file focuses on testing the sqliteBtreeNext() and
|
||||
# sqliteBtreePrevious() procedures and making sure they are able
|
||||
# to step through an entire table from either direction.
|
||||
#
|
||||
# $Id: btree4rb.test,v 1.1 2003/04/20 23:45:23 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
if {[info commands btree_open]!=""} {
|
||||
|
||||
# Open a test database.
|
||||
#
|
||||
set b1 [btree_open :memory:]
|
||||
btree_begin_transaction $::b1
|
||||
|
||||
set data {abcdefghijklmnopqrstuvwxyz0123456789}
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
|
||||
foreach N {10 100 1000} {
|
||||
btree_clear_table $::b1 2
|
||||
set ::c1 [btree_cursor $::b1 2 1]
|
||||
do_test btree4rb-$N.1 {
|
||||
for {set i 1} {$i<=$N} {incr i} {
|
||||
btree_insert $::c1 [format k-%05d $i] $::data-$i
|
||||
}
|
||||
btree_first $::c1
|
||||
btree_key $::c1
|
||||
} {k-00001}
|
||||
do_test btree4rb-$N.2 {
|
||||
btree_data $::c1
|
||||
} $::data-1
|
||||
for {set i 2} {$i<=$N} {incr i} {
|
||||
do_test btree-$N.3.$i.1 {
|
||||
btree_next $::c1
|
||||
} 0
|
||||
do_test btree-$N.3.$i.2 {
|
||||
btree_key $::c1
|
||||
} [format k-%05d $i]
|
||||
do_test btree-$N.3.$i.3 {
|
||||
btree_data $::c1
|
||||
} $::data-$i
|
||||
}
|
||||
do_test btree4rb-$N.4 {
|
||||
btree_next $::c1
|
||||
} 1
|
||||
do_test btree4rb-$N.5 {
|
||||
btree_last $::c1
|
||||
} 0
|
||||
do_test btree4rb-$N.6 {
|
||||
btree_key $::c1
|
||||
} [format k-%05d $N]
|
||||
do_test btree4rb-$N.7 {
|
||||
btree_data $::c1
|
||||
} $::data-$N
|
||||
for {set i [expr {$N-1}]} {$i>=1} {incr i -1} {
|
||||
do_test btree4rb-$N.8.$i.1 {
|
||||
btree_prev $::c1
|
||||
} 0
|
||||
do_test btree4rb-$N.8.$i.2 {
|
||||
btree_key $::c1
|
||||
} [format k-%05d $i]
|
||||
do_test btree4rb-$N.8.$i.3 {
|
||||
btree_data $::c1
|
||||
} $::data-$i
|
||||
}
|
||||
do_test btree4rb-$N.9 {
|
||||
btree_prev $::c1
|
||||
} 1
|
||||
btree_close_cursor $::c1
|
||||
}
|
||||
|
||||
btree_rollback $::b1
|
||||
btree_close $::b1
|
||||
|
||||
} ;# end if( not mem: and has pager_open command );
|
||||
|
||||
finish_test
|
||||
@@ -1,292 +0,0 @@
|
||||
# 2004 May 10
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# $Id: btree5.test,v 1.5 2004/05/14 12:17:46 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Attempting to read table 1 of an empty file gives an SQLITE_EMPTY
|
||||
# error.
|
||||
#
|
||||
do_test btree5-1.1 {
|
||||
file delete -force test1.bt
|
||||
file delete -force test1.bt-journal
|
||||
set rc [catch {btree_open test1.bt 2000 0} ::b1]
|
||||
} {0}
|
||||
do_test btree5-1.2 {
|
||||
set rc [catch {btree_cursor $::b1 1 0} ::c1]
|
||||
} {1}
|
||||
do_test btree5-1.3 {
|
||||
set ::c1
|
||||
} {SQLITE_EMPTY}
|
||||
do_test btree5-1.4 {
|
||||
set rc [catch {btree_cursor $::b1 1 1} ::c1]
|
||||
} {1}
|
||||
do_test btree5-1.5 {
|
||||
set ::c1
|
||||
} {SQLITE_EMPTY}
|
||||
|
||||
# Starting a transaction initializes the first page of the database
|
||||
# and the error goes away.
|
||||
#
|
||||
do_test btree5-1.6 {
|
||||
btree_begin_transaction $b1
|
||||
set rc [catch {btree_cursor $b1 1 0} c1]
|
||||
} {0}
|
||||
do_test btree5-1.7 {
|
||||
btree_first $c1
|
||||
} {1}
|
||||
do_test btree5-1.8 {
|
||||
btree_close_cursor $c1
|
||||
btree_rollback $b1
|
||||
set rc [catch {btree_cursor $b1 1 0} c1]
|
||||
} {1}
|
||||
do_test btree5-1.9 {
|
||||
set c1
|
||||
} {SQLITE_EMPTY}
|
||||
do_test btree5-1.10 {
|
||||
btree_begin_transaction $b1
|
||||
set rc [catch {btree_cursor $b1 1 0} c1]
|
||||
} {0}
|
||||
do_test btree5-1.11 {
|
||||
btree_first $c1
|
||||
} {1}
|
||||
do_test btree5-1.12 {
|
||||
btree_close_cursor $c1
|
||||
btree_commit $b1
|
||||
set rc [catch {btree_cursor $b1 1 0} c1]
|
||||
} {0}
|
||||
do_test btree5-1.13 {
|
||||
btree_first $c1
|
||||
} {1}
|
||||
do_test btree5-1.14 {
|
||||
btree_close_cursor $c1
|
||||
btree_integrity_check $b1 1
|
||||
} {}
|
||||
|
||||
# Insert many entries into table 1. This is designed to test the
|
||||
# virtual-root logic that comes into play for page one. It is also
|
||||
# a good test of INTKEY tables.
|
||||
#
|
||||
# Stagger the inserts. After the inserts complete, go back and do
|
||||
# deletes. Stagger the deletes too. Repeat this several times.
|
||||
#
|
||||
|
||||
# Do N inserts into table 1 using random keys between 0 and 1000000
|
||||
#
|
||||
proc random_inserts {N} {
|
||||
global c1
|
||||
while {$N>0} {
|
||||
set k [expr {int(rand()*1000000)}]
|
||||
if {[btree_move_to $c1 $k]==0} continue; # entry already exists
|
||||
btree_insert $c1 $k data-for-$k
|
||||
incr N -1
|
||||
}
|
||||
}
|
||||
|
||||
# Do N delete from table 1
|
||||
#
|
||||
proc random_deletes {N} {
|
||||
global c1
|
||||
while {$N>0} {
|
||||
set k [expr {int(rand()*1000000)}]
|
||||
btree_move_to $c1 $k
|
||||
btree_delete $c1
|
||||
incr N -1
|
||||
}
|
||||
}
|
||||
|
||||
# Make sure the table has exactly N entries. Make sure the data for
|
||||
# each entry agrees with its key.
|
||||
#
|
||||
proc check_table {N} {
|
||||
global c1
|
||||
btree_first $c1
|
||||
set cnt 0
|
||||
while {![btree_eof $c1]} {
|
||||
if {[set data [btree_data $c1]] ne "data-for-[btree_key $c1]"} {
|
||||
return "wrong data for entry $cnt"
|
||||
}
|
||||
set n [string length $data]
|
||||
set fdata1 [btree_fetch_data $c1 $n]
|
||||
set fdata2 [btree_fetch_data $c1 -1]
|
||||
if {$fdata1 ne "" && $fdata1 ne $data} {
|
||||
return "DataFetch returned the wrong value with amt=$n"
|
||||
}
|
||||
if {$fdata1 ne $fdata2} {
|
||||
return "DataFetch returned the wrong value when amt=-1"
|
||||
}
|
||||
if {$n>10} {
|
||||
set fdata3 [btree_fetch_data $c1 10]
|
||||
if {$fdata3 ne [string range $data 0 9]} {
|
||||
return "DataFetch returned the wrong value when amt=10"
|
||||
}
|
||||
}
|
||||
incr cnt
|
||||
btree_next $c1
|
||||
}
|
||||
if {$cnt!=$N} {
|
||||
return "wrong number of entries"
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
# Initialize the database
|
||||
#
|
||||
btree_begin_transaction $b1
|
||||
set c1 [btree_cursor $b1 1 1]
|
||||
set btree_trace 0
|
||||
|
||||
# Do the tests.
|
||||
#
|
||||
set cnt 0
|
||||
for {set i 1} {$i<=100} {incr i} {
|
||||
do_test btree5-2.$i.1 {
|
||||
random_inserts 200
|
||||
incr cnt 200
|
||||
check_table $cnt
|
||||
} {}
|
||||
do_test btree5-2.$i.2 {
|
||||
btree_integrity_check $b1 1
|
||||
} {}
|
||||
do_test btree5-2.$i.3 {
|
||||
random_deletes 190
|
||||
incr cnt -190
|
||||
check_table $cnt
|
||||
} {}
|
||||
do_test btree5-2.$i.4 {
|
||||
btree_integrity_check $b1 1
|
||||
} {}
|
||||
}
|
||||
|
||||
#btree_tree_dump $b1 1
|
||||
btree_close_cursor $c1
|
||||
btree_commit $b1
|
||||
btree_begin_transaction $b1
|
||||
|
||||
# This procedure converts an integer into a variable-length text key.
|
||||
# The conversion is reversible.
|
||||
#
|
||||
# The first two characters of the string are alphabetics derived from
|
||||
# the least significant bits of the number. Because they are derived
|
||||
# from least significant bits, the sort order of the resulting string
|
||||
# is different from numeric order. After the alphabetic prefix comes
|
||||
# the original number. A variable-length suffix follows. The length
|
||||
# of the suffix is based on a hash of the original number.
|
||||
#
|
||||
proc num_to_key {n} {
|
||||
global charset ncharset suffix
|
||||
set c1 [string index $charset [expr {$n%$ncharset}]]
|
||||
set c2 [string index $charset [expr {($n/$ncharset)%$ncharset}]]
|
||||
set nsuf [expr {($n*211)%593}]
|
||||
return $c1$c2-$n-[string range $suffix 0 $nsuf]
|
||||
}
|
||||
set charset {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}
|
||||
set ncharset [string length $charset]
|
||||
set suffix $charset$charset
|
||||
while {[string length $suffix]<1000} {append suffix $suffix}
|
||||
|
||||
# This procedures extracts the original integer used to create
|
||||
# a key by num_to_key
|
||||
#
|
||||
proc key_to_num {key} {
|
||||
regexp {^..-([0-9]+)} $key all n
|
||||
return $n
|
||||
}
|
||||
|
||||
# Insert into table $tab keys corresponding to all values between
|
||||
# $start and $end, inclusive.
|
||||
#
|
||||
proc insert_range {tab start end} {
|
||||
for {set i $start} {$i<=$end} {incr i} {
|
||||
btree_insert $tab [num_to_key $i] {}
|
||||
}
|
||||
}
|
||||
|
||||
# Delete from table $tab keys corresponding to all values between
|
||||
# $start and $end, inclusive.
|
||||
#
|
||||
proc delete_range {tab start end} {
|
||||
for {set i $start} {$i<=$end} {incr i} {
|
||||
if {[btree_move_to $tab [num_to_key $i]]==0} {
|
||||
btree_delete $tab
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Make sure table $tab contains exactly those keys corresponding
|
||||
# to values between $start and $end
|
||||
#
|
||||
proc check_range {tab start end} {
|
||||
btree_first $tab
|
||||
while {![btree_eof $tab]} {
|
||||
set key [btree_key $tab]
|
||||
set i [key_to_num $key]
|
||||
if {[num_to_key $i] ne $key} {
|
||||
return "malformed key: $key"
|
||||
}
|
||||
set got($i) 1
|
||||
btree_next $tab
|
||||
}
|
||||
set all [lsort -integer [array names got]]
|
||||
if {[llength $all]!=$end+1-$start} {
|
||||
return "table contains wrong number of values"
|
||||
}
|
||||
if {[lindex $all 0]!=$start} {
|
||||
return "wrong starting value"
|
||||
}
|
||||
if {[lindex $all end]!=$end} {
|
||||
return "wrong ending value"
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
# Create a zero-data table and test it out.
|
||||
#
|
||||
do_test btree5-3.1 {
|
||||
set rc [catch {btree_create_table $b1 2} t2]
|
||||
} {0}
|
||||
do_test btree5-3.2 {
|
||||
set rc [catch {btree_cursor $b1 $t2 1} c2]
|
||||
} {0}
|
||||
set start 1
|
||||
set end 100
|
||||
for {set i 1} {$i<=100} {incr i} {
|
||||
do_test btree5-3.3.$i.1 {
|
||||
insert_range $c2 $start $end
|
||||
btree_integrity_check $b1 1 $t2
|
||||
} {}
|
||||
do_test btree5-3.3.$i.2 {
|
||||
check_range $c2 $start $end
|
||||
} {}
|
||||
set nstart $start
|
||||
incr nstart 89
|
||||
do_test btree5-3.3.$i.3 {
|
||||
delete_range $c2 $start $nstart
|
||||
btree_integrity_check $b1 1 $t2
|
||||
} {}
|
||||
incr start 90
|
||||
do_test btree5-3.3.$i.4 {
|
||||
check_range $c2 $start $end
|
||||
} {}
|
||||
incr end 100
|
||||
}
|
||||
|
||||
|
||||
btree_close_cursor $c2
|
||||
btree_commit $b1
|
||||
btree_close $b1
|
||||
|
||||
finish_test
|
||||
@@ -1,128 +0,0 @@
|
||||
# 2004 May 10
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend - specifically
|
||||
# the B+tree tables. B+trees store all data on the leaves rather
|
||||
# that storing data with keys on interior nodes.
|
||||
#
|
||||
# $Id: btree6.test,v 1.4 2004/05/20 22:16:31 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
# Insert many entries into the table that cursor $cur points to.
|
||||
# The table should be an INTKEY table.
|
||||
#
|
||||
# Stagger the inserts. After the inserts complete, go back and do
|
||||
# deletes. Stagger the deletes too. Repeat this several times.
|
||||
#
|
||||
|
||||
# Do N inserts into table $tab using random keys between 0 and 1000000
|
||||
#
|
||||
proc random_inserts {cur N} {
|
||||
global inscnt
|
||||
while {$N>0} {
|
||||
set k [expr {int(rand()*1000000)}]
|
||||
if {[btree_move_to $cur $k]==0} {
|
||||
continue; # entry already exists
|
||||
}
|
||||
incr inscnt
|
||||
btree_insert $cur $k data-for-$k
|
||||
incr N -1
|
||||
}
|
||||
}
|
||||
set inscnt 0
|
||||
|
||||
# Do N delete from the table that $cur points to.
|
||||
#
|
||||
proc random_deletes {cur N} {
|
||||
while {$N>0} {
|
||||
set k [expr {int(rand()*1000000)}]
|
||||
btree_move_to $cur $k
|
||||
btree_delete $cur
|
||||
incr N -1
|
||||
}
|
||||
}
|
||||
|
||||
# Make sure the table that $cur points to has exactly N entries.
|
||||
# Make sure the data for each entry agrees with its key.
|
||||
#
|
||||
proc check_table {cur N} {
|
||||
btree_first $cur
|
||||
set cnt 0
|
||||
while {![btree_eof $cur]} {
|
||||
if {[set data [btree_data $cur]] ne "data-for-[btree_key $cur]"} {
|
||||
return "wrong data for entry $cnt"
|
||||
}
|
||||
set n [string length $data]
|
||||
set fdata1 [btree_fetch_data $cur $n]
|
||||
set fdata2 [btree_fetch_data $cur -1]
|
||||
if {$fdata1 ne "" && $fdata1 ne $data} {
|
||||
return "DataFetch returned the wrong value with amt=$n"
|
||||
}
|
||||
if {$fdata1 ne $fdata2} {
|
||||
return "DataFetch returned the wrong value when amt=-1"
|
||||
}
|
||||
if {$n>10} {
|
||||
set fdata3 [btree_fetch_data $cur 10]
|
||||
if {$fdata3 ne [string range $data 0 9]} {
|
||||
return "DataFetch returned the wrong value when amt=10"
|
||||
}
|
||||
}
|
||||
incr cnt
|
||||
btree_next $cur
|
||||
}
|
||||
if {$cnt!=$N} {
|
||||
return "wrong number of entries. Got $cnt. Looking for $N"
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
# Initialize the database
|
||||
#
|
||||
file delete -force test1.bt
|
||||
file delete -force test1.bt-journal
|
||||
set b1 [btree_open test1.bt 2000 0]
|
||||
btree_begin_transaction $b1
|
||||
set tab [btree_create_table $b1 5]
|
||||
set cur [btree_cursor $b1 $tab 1]
|
||||
set btree_trace 0
|
||||
expr srand(1)
|
||||
|
||||
# Do the tests.
|
||||
#
|
||||
set cnt 0
|
||||
for {set i 1} {$i<=40} {incr i} {
|
||||
do_test btree6-1.$i.1 {
|
||||
random_inserts $cur 200
|
||||
incr cnt 200
|
||||
check_table $cur $cnt
|
||||
} {}
|
||||
do_test btree6-1.$i.2 {
|
||||
btree_integrity_check $b1 1 $tab
|
||||
} {}
|
||||
do_test btree6-1.$i.3 {
|
||||
random_deletes $cur 90
|
||||
incr cnt -90
|
||||
check_table $cur $cnt
|
||||
} {}
|
||||
do_test btree6-1.$i.4 {
|
||||
btree_integrity_check $b1 1 $tab
|
||||
} {}
|
||||
}
|
||||
|
||||
btree_close_cursor $cur
|
||||
btree_commit $b1
|
||||
btree_close $b1
|
||||
|
||||
finish_test
|
||||
@@ -1,58 +0,0 @@
|
||||
# 2004 Jun 4
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend.
|
||||
#
|
||||
# $Id: btree7.test,v 1.1 2004/06/05 00:01:46 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Stress the balance routine by trying to create situations where
|
||||
# 3 neighboring nodes split into 5.
|
||||
#
|
||||
set bigdata _123456789 ;# 10
|
||||
append bigdata $bigdata ;# 20
|
||||
append bigdata $bigdata ;# 40
|
||||
append bigdata $bigdata ;# 80
|
||||
append bigdata $bigdata ;# 160
|
||||
append bigdata $bigdata ;# 320
|
||||
append bigdata $bigdata ;# 640
|
||||
set data450 [string range $bigdata 0 449]
|
||||
do_test btree7-1.1 {
|
||||
execsql "
|
||||
CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT);
|
||||
INSERT INTO t1 VALUES(1, '$bigdata');
|
||||
INSERT INTO t1 VALUES(2, '$bigdata');
|
||||
INSERT INTO t1 VALUES(3, '$data450');
|
||||
INSERT INTO t1 VALUES(5, '$data450');
|
||||
INSERT INTO t1 VALUES(8, '$bigdata');
|
||||
INSERT INTO t1 VALUES(9, '$bigdata');
|
||||
"
|
||||
} {}
|
||||
#puts [execsql {select * from sqlite_master}]
|
||||
#set bt [btree_open test.db 2000 0]
|
||||
#btree_tree_dump $bt 2
|
||||
do_test btree7-1.2 {
|
||||
execsql {PRAGMA integrity_check}
|
||||
} {ok}
|
||||
do_test btree7-1.3 {
|
||||
execsql "
|
||||
INSERT INTO t1 VALUES(4, '$bigdata');
|
||||
"
|
||||
} {}
|
||||
#btree_tree_dump $bt 2
|
||||
do_test btree7-1.4 {
|
||||
execsql {PRAGMA integrity_check}
|
||||
} {ok}
|
||||
|
||||
finish_test
|
||||
+142
-287
@@ -11,88 +11,57 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the callback-free C/C++ API.
|
||||
#
|
||||
# $Id: capi2.test,v 1.19 2004/09/02 14:57:09 drh Exp $
|
||||
# $Id: capi2.test,v 1.10 2003/08/05 13:13:38 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Return the text values from the current row pointed at by STMT as a list.
|
||||
proc get_row_values {STMT} {
|
||||
set VALUES [list]
|
||||
for {set i 0} {$i < [sqlite3_data_count $STMT]} {incr i} {
|
||||
lappend VALUES [sqlite3_column_text $STMT $i]
|
||||
}
|
||||
return $VALUES
|
||||
}
|
||||
|
||||
# Return the column names followed by declaration types for the result set
|
||||
# of the SQL statement STMT.
|
||||
#
|
||||
# i.e. for:
|
||||
# CREATE TABLE abc(a text, b integer);
|
||||
# SELECT * FROM abc;
|
||||
#
|
||||
# The result is {a b text integer}
|
||||
proc get_column_names {STMT} {
|
||||
set VALUES [list]
|
||||
for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} {
|
||||
lappend VALUES [sqlite3_column_name $STMT $i]
|
||||
}
|
||||
for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} {
|
||||
lappend VALUES [sqlite3_column_decltype $STMT $i]
|
||||
}
|
||||
return $VALUES
|
||||
}
|
||||
|
||||
# Check basic functionality
|
||||
#
|
||||
do_test capi2-1.1 {
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
set DB [sqlite db test.db]
|
||||
execsql {CREATE TABLE t1(a,b,c)}
|
||||
set VM [sqlite3_prepare $DB {SELECT name, rowid FROM sqlite_master} -1 TAIL]
|
||||
set VM [sqlite_compile $DB {SELECT name, rowid FROM sqlite_master} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-1.2 {
|
||||
sqlite3_step $VM
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} {SQLITE_ROW}
|
||||
do_test capi2-1.3 {
|
||||
sqlite3_data_count $VM
|
||||
set N
|
||||
} {2}
|
||||
do_test capi2-1.4 {
|
||||
get_row_values $VM
|
||||
set VALUES
|
||||
} {t1 1}
|
||||
do_test capi2-1.5 {
|
||||
get_column_names $VM
|
||||
set COLNAMES
|
||||
} {name rowid text INTEGER}
|
||||
do_test capi2-1.6 {
|
||||
sqlite3_step $VM
|
||||
set N x
|
||||
set VALUES y
|
||||
set COLNAMES z
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} {SQLITE_DONE}
|
||||
do_test capi2-1.7 {
|
||||
list [sqlite3_column_count $VM] [get_row_values $VM] [get_column_names $VM]
|
||||
list $N $VALUES $COLNAMES
|
||||
} {2 {} {name rowid text INTEGER}}
|
||||
do_test capi2-1.8 {
|
||||
sqlite3_step $VM
|
||||
set N x
|
||||
set VALUES y
|
||||
set COLNAMES z
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} {SQLITE_MISUSE}
|
||||
|
||||
# Update: In v2, once SQLITE_MISUSE is returned the statement handle cannot
|
||||
# be interrogated for more information. However in v3, since the column
|
||||
# count, names and types are determined at compile time, these are still
|
||||
# accessible after an SQLITE_MISUSE error.
|
||||
do_test capi2-1.9 {
|
||||
list [sqlite3_column_count $VM] [get_row_values $VM] [get_column_names $VM]
|
||||
} {2 {} {name rowid text INTEGER}}
|
||||
list $N $VALUES $COLNAMES
|
||||
} {0 {} {}}
|
||||
do_test capi2-1.10 {
|
||||
sqlite3_data_count $VM
|
||||
} {0}
|
||||
|
||||
do_test capi2-1.11 {
|
||||
sqlite3_finalize $VM
|
||||
} {SQLITE_OK}
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
|
||||
# Check to make sure that the "tail" of a multi-statement SQL script
|
||||
# is returned by sqlite3_prepare.
|
||||
# is returned by sqlite_compile.
|
||||
#
|
||||
do_test capi2-2.1 {
|
||||
set SQL {
|
||||
@@ -100,44 +69,38 @@ do_test capi2-2.1 {
|
||||
SELECT name, rowid FROM sqlite_temp_master;
|
||||
-- A comment at the end
|
||||
}
|
||||
set VM [sqlite3_prepare $DB $SQL -1 SQL]
|
||||
set VM [sqlite_compile $DB $SQL SQL]
|
||||
set SQL
|
||||
} {
|
||||
SELECT name, rowid FROM sqlite_temp_master;
|
||||
-- A comment at the end
|
||||
}
|
||||
do_test capi2-2.2 {
|
||||
set r [sqlite3_step $VM]
|
||||
lappend r [sqlite3_column_count $VM] \
|
||||
[get_row_values $VM] \
|
||||
[get_column_names $VM]
|
||||
set r [sqlite_step $VM n val colname]
|
||||
lappend r $n $val $colname
|
||||
} {SQLITE_ROW 2 {t1 1} {name rowid text INTEGER}}
|
||||
do_test capi2-2.3 {
|
||||
set r [sqlite3_step $VM]
|
||||
lappend r [sqlite3_column_count $VM] \
|
||||
[get_row_values $VM] \
|
||||
[get_column_names $VM]
|
||||
set r [sqlite_step $VM n val colname]
|
||||
lappend r $n $val $colname
|
||||
} {SQLITE_DONE 2 {} {name rowid text INTEGER}}
|
||||
do_test capi2-2.4 {
|
||||
sqlite3_finalize $VM
|
||||
} {SQLITE_OK}
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
do_test capi2-2.5 {
|
||||
set VM [sqlite3_prepare $DB $SQL -1 SQL]
|
||||
set VM [sqlite_compile $DB $SQL SQL]
|
||||
set SQL
|
||||
} {
|
||||
-- A comment at the end
|
||||
}
|
||||
do_test capi2-2.6 {
|
||||
set r [sqlite3_step $VM]
|
||||
lappend r [sqlite3_column_count $VM] \
|
||||
[get_row_values $VM] \
|
||||
[get_column_names $VM]
|
||||
set r [sqlite_step $VM n val colname]
|
||||
lappend r $n $val $colname
|
||||
} {SQLITE_DONE 2 {} {name rowid text INTEGER}}
|
||||
do_test capi2-2.7 {
|
||||
sqlite3_finalize $VM
|
||||
} {SQLITE_OK}
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
do_test capi2-2.8 {
|
||||
set VM [sqlite3_prepare $DB $SQL -1 SQL]
|
||||
set VM [sqlite_compile $DB $SQL SQL]
|
||||
list $SQL $VM
|
||||
} {{} {}}
|
||||
|
||||
@@ -145,238 +108,181 @@ do_test capi2-2.8 {
|
||||
#
|
||||
do_test capi2-3.1 {
|
||||
set rc [catch {
|
||||
sqlite3_prepare $DB {select bogus from sqlite_master} -1 TAIL
|
||||
sqlite_compile $DB {select bogus from sqlite_master} TAIL
|
||||
} msg]
|
||||
lappend rc $msg $TAIL
|
||||
} {1 {(1) no such column: bogus} {}}
|
||||
do_test capi2-3.2 {
|
||||
set rc [catch {
|
||||
sqlite3_prepare $DB {select bogus from } -1 TAIL
|
||||
sqlite_compile $DB {select bogus from } TAIL
|
||||
} msg]
|
||||
lappend rc $msg $TAIL
|
||||
} {1 {(1) near " ": syntax error} {}}
|
||||
do_test capi2-3.3 {
|
||||
set rc [catch {
|
||||
sqlite3_prepare $DB {;;;;select bogus from sqlite_master} -1 TAIL
|
||||
sqlite_compile $DB {;;;;select bogus from sqlite_master} TAIL
|
||||
} msg]
|
||||
lappend rc $msg $TAIL
|
||||
} {1 {(1) no such column: bogus} {}}
|
||||
do_test capi2-3.4 {
|
||||
set rc [catch {
|
||||
sqlite3_prepare $DB {select bogus from sqlite_master;x;} -1 TAIL
|
||||
sqlite_compile $DB {select bogus from sqlite_master;x;} TAIL
|
||||
} msg]
|
||||
lappend rc $msg $TAIL
|
||||
} {1 {(1) no such column: bogus} {x;}}
|
||||
do_test capi2-3.5 {
|
||||
set rc [catch {
|
||||
sqlite3_prepare $DB {select bogus from sqlite_master;;;x;} -1 TAIL
|
||||
sqlite_compile $DB {select bogus from sqlite_master;;;x;} TAIL
|
||||
} msg]
|
||||
lappend rc $msg $TAIL
|
||||
} {1 {(1) no such column: bogus} {;;x;}}
|
||||
do_test capi2-3.6 {
|
||||
set rc [catch {
|
||||
sqlite3_prepare $DB {select 5/0} -1 TAIL
|
||||
sqlite_compile $DB {select 5/0} TAIL
|
||||
} VM]
|
||||
lappend rc $TAIL
|
||||
} {0 {}}
|
||||
do_test capi2-3.7 {
|
||||
list [sqlite3_step $VM] \
|
||||
[sqlite3_column_count $VM] \
|
||||
[get_row_values $VM] \
|
||||
[get_column_names $VM]
|
||||
} {SQLITE_ROW 1 {{}} {5/0 {}}}
|
||||
set N {}
|
||||
set VALUE {}
|
||||
set COLNAME {}
|
||||
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 {{}} {5/0 NUMERIC}}
|
||||
do_test capi2-3.8 {
|
||||
sqlite3_finalize $VM
|
||||
} {SQLITE_OK}
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
do_test capi2-3.9 {
|
||||
execsql {CREATE UNIQUE INDEX i1 ON t1(a)}
|
||||
set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,2,3)} -1 TAIL]
|
||||
set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(1,2,3)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-3.9b {db changes} {0}
|
||||
do_test capi2-3.10 {
|
||||
list [sqlite3_step $VM] \
|
||||
[sqlite3_column_count $VM] \
|
||||
[get_row_values $VM] \
|
||||
[get_column_names $VM]
|
||||
set N {}
|
||||
set VALUE {}
|
||||
set COLNAME {}
|
||||
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 0 {} {}}
|
||||
|
||||
# Update for v3 - the change has not actually happened until the query is
|
||||
# finalized. Is this going to cause trouble for anyone? Lee Nelson maybe?
|
||||
# (Later:) The change now happens just before SQLITE_DONE is returned.
|
||||
do_test capi2-3.10b {db changes} {1}
|
||||
do_test capi2-3.11 {
|
||||
sqlite3_finalize $VM
|
||||
} {SQLITE_OK}
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
do_test capi2-3.11b {db changes} {1}
|
||||
do_test capi2-3.12 {
|
||||
sqlite3_finalize $VM
|
||||
} {SQLITE_MISUSE}
|
||||
list [catch {sqlite_finalize $VM} msg] [set msg]
|
||||
} {1 {(21) library routine called out of sequence}}
|
||||
do_test capi2-3.13 {
|
||||
set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,3,4)} -1 TAIL]
|
||||
list [sqlite3_step $VM] \
|
||||
[sqlite3_column_count $VM] \
|
||||
[get_row_values $VM] \
|
||||
[get_column_names $VM]
|
||||
set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(1,3,4)} TAIL]
|
||||
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ERROR 0 {} {}}
|
||||
|
||||
# Update for v3: Preparing a statement does not affect the change counter.
|
||||
# (Test result changes from 0 to 1). (Later:) change counter updates occur
|
||||
# when sqlite3_step returns, not at finalize time.
|
||||
do_test capi2-3.13b {db changes} {0}
|
||||
|
||||
do_test capi2-3.14 {
|
||||
list [sqlite3_finalize $VM] [sqlite3_errmsg $DB]
|
||||
} {SQLITE_CONSTRAINT {column a is not unique}}
|
||||
list [catch {sqlite_finalize $VM} msg] [set msg]
|
||||
} {1 {(19) column a is not unique}}
|
||||
do_test capi2-3.15 {
|
||||
set VM [sqlite3_prepare $DB {CREATE TABLE t2(a NOT NULL, b)} -1 TAIL]
|
||||
set VM [sqlite_compile $DB {CREATE TABLE t2(a NOT NULL, b)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-3.16 {
|
||||
list [sqlite3_step $VM] \
|
||||
[sqlite3_column_count $VM] \
|
||||
[get_row_values $VM] \
|
||||
[get_column_names $VM]
|
||||
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 0 {} {}}
|
||||
do_test capi2-3.17 {
|
||||
list [sqlite3_finalize $VM] [sqlite3_errmsg $DB]
|
||||
} {SQLITE_OK {not an error}}
|
||||
list [catch {sqlite_finalize $VM} msg] [set msg]
|
||||
} {0 {}}
|
||||
do_test capi2-3.18 {
|
||||
set VM [sqlite3_prepare $DB {INSERT INTO t2 VALUES(NULL,2)} -1 TAIL]
|
||||
list [sqlite3_step $VM] \
|
||||
[sqlite3_column_count $VM] \
|
||||
[get_row_values $VM] \
|
||||
[get_column_names $VM]
|
||||
set VM [sqlite_compile $DB {INSERT INTO t2 VALUES(NULL,2)} TAIL]
|
||||
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ERROR 0 {} {}}
|
||||
do_test capi2-3.19 {
|
||||
list [sqlite3_finalize $VM] [sqlite3_errmsg $DB]
|
||||
} {SQLITE_CONSTRAINT {t2.a may not be NULL}}
|
||||
list [catch {sqlite_finalize $VM} msg] [set msg]
|
||||
} {1 {(19) t2.a may not be NULL}}
|
||||
|
||||
# Two or more virtual machines exists at the same time.
|
||||
#
|
||||
do_test capi2-4.1 {
|
||||
set VM1 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(1,2)} -1 TAIL]
|
||||
set VM1 [sqlite_compile $DB {INSERT INTO t2 VALUES(1,2)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-4.2 {
|
||||
set VM2 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(2,3)} -1 TAIL]
|
||||
set VM2 [sqlite_compile $DB {INSERT INTO t2 VALUES(2,3)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-4.3 {
|
||||
set VM3 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(3,4)} -1 TAIL]
|
||||
set VM3 [sqlite_compile $DB {INSERT INTO t2 VALUES(3,4)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-4.4 {
|
||||
list [sqlite3_step $VM2] \
|
||||
[sqlite3_column_count $VM2] \
|
||||
[get_row_values $VM2] \
|
||||
[get_column_names $VM2]
|
||||
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 0 {} {}}
|
||||
do_test capi2-4.5 {
|
||||
execsql {SELECT * FROM t2 ORDER BY a}
|
||||
} {2 3}
|
||||
do_test capi2-4.6 {
|
||||
sqlite3_finalize $VM2
|
||||
} {SQLITE_OK}
|
||||
list [catch {sqlite_finalize $VM2} msg] [set msg]
|
||||
} {0 {}}
|
||||
do_test capi2-4.7 {
|
||||
list [sqlite3_step $VM3] \
|
||||
[sqlite3_column_count $VM3] \
|
||||
[get_row_values $VM3] \
|
||||
[get_column_names $VM3]
|
||||
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 0 {} {}}
|
||||
do_test capi2-4.8 {
|
||||
execsql {SELECT * FROM t2 ORDER BY a}
|
||||
} {2 3 3 4}
|
||||
do_test capi2-4.9 {
|
||||
sqlite3_finalize $VM3
|
||||
} {SQLITE_OK}
|
||||
list [catch {sqlite_finalize $VM3} msg] [set msg]
|
||||
} {0 {}}
|
||||
do_test capi2-4.10 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 0 {} {}}
|
||||
do_test capi2-4.11 {
|
||||
execsql {SELECT * FROM t2 ORDER BY a}
|
||||
} {1 2 2 3 3 4}
|
||||
do_test capi2-4.12 {
|
||||
sqlite3_finalize $VM1
|
||||
} {SQLITE_OK}
|
||||
list [catch {sqlite_finalize $VM1} msg] [set msg]
|
||||
} {0 {}}
|
||||
|
||||
# Interleaved SELECTs
|
||||
#
|
||||
do_test capi2-5.1 {
|
||||
set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
|
||||
set VM2 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
|
||||
set VM3 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
|
||||
set VM2 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
|
||||
set VM3 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {2 3} {a b {} {}}}
|
||||
do_test capi2-5.2 {
|
||||
list [sqlite3_step $VM2] \
|
||||
[sqlite3_column_count $VM2] \
|
||||
[get_row_values $VM2] \
|
||||
[get_column_names $VM2]
|
||||
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {2 3} {a b {} {}}}
|
||||
do_test capi2-5.3 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {3 4} {a b {} {}}}
|
||||
do_test capi2-5.4 {
|
||||
list [sqlite3_step $VM3] \
|
||||
[sqlite3_column_count $VM3] \
|
||||
[get_row_values $VM3] \
|
||||
[get_column_names $VM3]
|
||||
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {2 3} {a b {} {}}}
|
||||
do_test capi2-5.5 {
|
||||
list [sqlite3_step $VM3] \
|
||||
[sqlite3_column_count $VM3] \
|
||||
[get_row_values $VM3] \
|
||||
[get_column_names $VM3]
|
||||
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {3 4} {a b {} {}}}
|
||||
do_test capi2-5.6 {
|
||||
list [sqlite3_step $VM3] \
|
||||
[sqlite3_column_count $VM3] \
|
||||
[get_row_values $VM3] \
|
||||
[get_column_names $VM3]
|
||||
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {1 2} {a b {} {}}}
|
||||
do_test capi2-5.7 {
|
||||
list [sqlite3_step $VM3] \
|
||||
[sqlite3_column_count $VM3] \
|
||||
[get_row_values $VM3] \
|
||||
[get_column_names $VM3]
|
||||
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 2 {} {a b {} {}}}
|
||||
do_test capi2-5.8 {
|
||||
sqlite3_finalize $VM3
|
||||
} {SQLITE_OK}
|
||||
list [catch {sqlite_finalize $VM3} msg] [set msg]
|
||||
} {0 {}}
|
||||
do_test capi2-5.9 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {1 2} {a b {} {}}}
|
||||
do_test capi2-5.10 {
|
||||
sqlite3_finalize $VM1
|
||||
} {SQLITE_OK}
|
||||
list [catch {sqlite_finalize $VM1} msg] [set msg]
|
||||
} {0 {}}
|
||||
do_test capi2-5.11 {
|
||||
list [sqlite3_step $VM2] \
|
||||
[sqlite3_column_count $VM2] \
|
||||
[get_row_values $VM2] \
|
||||
[get_column_names $VM2]
|
||||
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {3 4} {a b {} {}}}
|
||||
do_test capi2-5.12 {
|
||||
list [sqlite3_step $VM2] \
|
||||
[sqlite3_column_count $VM2] \
|
||||
[get_row_values $VM2] \
|
||||
[get_column_names $VM2]
|
||||
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {1 2} {a b {} {}}}
|
||||
do_test capi2-5.11 {
|
||||
sqlite3_finalize $VM2
|
||||
} {SQLITE_OK}
|
||||
list [catch {sqlite_finalize $VM2} msg] [set msg]
|
||||
} {0 {}}
|
||||
|
||||
# Check for proper SQLITE_BUSY returns.
|
||||
#
|
||||
@@ -391,130 +297,89 @@ do_test capi2-6.1 {
|
||||
INSERT INTO t3 SELECT x+8 FROM t3;
|
||||
COMMIT;
|
||||
}
|
||||
set VM1 [sqlite3_prepare $DB {SELECT * FROM t3} -1 TAIL]
|
||||
sqlite3 db2 test.db
|
||||
set VM1 [sqlite_compile $DB {SELECT * FROM t3} TAIL]
|
||||
sqlite db2 test.db
|
||||
execsql {BEGIN} db2
|
||||
} {}
|
||||
# Update for v3: BEGIN doesn't write-lock the database. It is quite
|
||||
# difficult to get v3 to write-lock the database, which causes a few
|
||||
# problems for test scripts.
|
||||
#
|
||||
# do_test capi2-6.2 {
|
||||
# list [sqlite3_step $VM1] \
|
||||
# [sqlite3_column_count $VM1] \
|
||||
# [get_row_values $VM1] \
|
||||
# [get_column_names $VM1]
|
||||
# } {SQLITE_BUSY 0 {} {}}
|
||||
do_test capi2-6.2 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_BUSY 0 {} {}}
|
||||
do_test capi2-6.3 {
|
||||
execsql {COMMIT} db2
|
||||
} {}
|
||||
do_test capi2-6.4 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 1 {x counter}}
|
||||
do_test capi2-6.5 {
|
||||
catchsql {INSERT INTO t3 VALUES(10);} db2
|
||||
catchsql {BEGIN} db2
|
||||
} {1 {database is locked}}
|
||||
do_test capi2-6.6 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 2 {x counter}}
|
||||
do_test capi2-6.7 {
|
||||
execsql {SELECT * FROM t2} db2
|
||||
} {2 3 3 4 1 2}
|
||||
do_test capi2-6.8 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 3 {x counter}}
|
||||
do_test capi2-6.9 {
|
||||
execsql {SELECT * FROM t2}
|
||||
} {2 3 3 4 1 2}
|
||||
do_test capi2-6.10 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 4 {x counter}}
|
||||
do_test capi2-6.11 {
|
||||
execsql {BEGIN}
|
||||
} {}
|
||||
do_test capi2-6.12 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 5 {x counter}}
|
||||
# execsql {pragma vdbe_trace=on}
|
||||
do_test capi2-6.13 {
|
||||
catchsql {UPDATE t3 SET x=x+1}
|
||||
} {1 {database table is locked}}
|
||||
do_test capi2-6.14 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 6 {x counter}}
|
||||
# puts [list [catch {sqlite_finalize $VM1} msg] [set msg]]; exit
|
||||
do_test capi2-6.15 {
|
||||
execsql {SELECT * FROM t1}
|
||||
} {1 2 3}
|
||||
do_test capi2-6.16 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 7 {x counter}}
|
||||
do_test capi2-6.17 {
|
||||
catchsql {UPDATE t1 SET b=b+1}
|
||||
} {0 {}}
|
||||
do_test capi2-6.18 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 8 {x counter}}
|
||||
do_test capi2-6.19 {
|
||||
execsql {SELECT * FROM t1}
|
||||
} {1 3 3}
|
||||
do_test capi2-6.20 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 9 {x counter}}
|
||||
#do_test capi2-6.21 {
|
||||
# execsql {ROLLBACK; SELECT * FROM t1}
|
||||
#} {1 2 3}
|
||||
do_test capi2-6.21 {
|
||||
execsql {ROLLBACK; SELECT * FROM t1}
|
||||
} {1 2 3}
|
||||
do_test capi2-6.22 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 10 {x counter}}
|
||||
#do_test capi2-6.23 {
|
||||
# execsql {BEGIN TRANSACTION;}
|
||||
#} {}
|
||||
do_test capi2-6.23 {
|
||||
execsql {BEGIN TRANSACTION ON CONFLICT ROLLBACK;}
|
||||
} {}
|
||||
do_test capi2-6.24 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 11 {x counter}}
|
||||
do_test capi2-6.25 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(2,3,4);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 3 3 2 3 4}
|
||||
} {1 2 3 2 3 4}
|
||||
do_test capi2-6.26 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 12 {x counter}}
|
||||
do_test capi2-6.27 {
|
||||
catchsql {
|
||||
@@ -523,14 +388,11 @@ do_test capi2-6.27 {
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
do_test capi2-6.28 {
|
||||
list [sqlite3_step $VM1] \
|
||||
[sqlite3_column_count $VM1] \
|
||||
[get_row_values $VM1] \
|
||||
[get_column_names $VM1]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 13 {x counter}}
|
||||
do_test capi2-6.99 {
|
||||
sqlite3_finalize $VM1
|
||||
} {SQLITE_OK}
|
||||
list [catch {sqlite_finalize $VM1} msg] [set msg]
|
||||
} {0 {}}
|
||||
catchsql {ROLLBACK}
|
||||
|
||||
do_test capi2-7.1 {
|
||||
@@ -553,13 +415,13 @@ do_test capi2-7.4 {
|
||||
INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1;
|
||||
}
|
||||
} {0 1}
|
||||
do_test capi2-7.4b {sqlite3_changes $DB} {1}
|
||||
do_test capi2-7.4b {db changes} {1}
|
||||
do_test capi2-7.5 {
|
||||
stepsql $DB {
|
||||
UPDATE t1 SET a=a+10;
|
||||
}
|
||||
} {0 2}
|
||||
do_test capi2-7.5b {sqlite3_changes $DB} {2}
|
||||
do_test capi2-7.5b {db changes} {2}
|
||||
do_test capi2-7.6 {
|
||||
stepsql $DB {
|
||||
SELECT * FROM t1;
|
||||
@@ -571,7 +433,7 @@ do_test capi2-7.7 {
|
||||
}
|
||||
} {0 2}
|
||||
do_test capi2-7.8 {
|
||||
sqlite3_changes $DB
|
||||
db changes
|
||||
} {2}
|
||||
do_test capi2-7.9 {
|
||||
stepsql $DB {
|
||||
@@ -584,16 +446,9 @@ do_test capi2-7.10 {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 4 1 2 3 2 3 4 3 4 5 4 5 6}
|
||||
|
||||
# Update for version 3: A SELECT statement no longer resets the change
|
||||
# counter (Test result changes from 0 to 4).
|
||||
do_test capi2-7.11 {
|
||||
sqlite3_changes $DB
|
||||
} {4}
|
||||
do_test capi2-7.11a {
|
||||
execsql {SELECT count(*) FROM t1}
|
||||
} {4}
|
||||
|
||||
db changes
|
||||
} {0}
|
||||
do_test capi2-7.12 {
|
||||
set x [stepsql $DB {EXPLAIN SELECT * FROM t1}]
|
||||
lindex $x 0
|
||||
@@ -602,18 +457,18 @@ do_test capi2-7.12 {
|
||||
# Ticket #261 - make sure we can finalize before the end of a query.
|
||||
#
|
||||
do_test capi2-8.1 {
|
||||
set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
|
||||
sqlite3_finalize $VM1
|
||||
} {SQLITE_OK}
|
||||
set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
|
||||
sqlite_finalize $VM1
|
||||
} {}
|
||||
|
||||
# Tickets #384 and #385 - make sure the TAIL argument to sqlite3_prepare
|
||||
# Tickets #384 and #385 - make sure the TAIL argument to sqlite_compile
|
||||
# and all of the return pointers in sqlite_step can be null.
|
||||
#
|
||||
do_test capi2-9.1 {
|
||||
set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 DUMMY]
|
||||
sqlite3_step $VM1
|
||||
sqlite3_finalize $VM1
|
||||
} {SQLITE_OK}
|
||||
set VM1 [sqlite_compile $DB {SELECT * FROM t2}]
|
||||
sqlite_step $VM1
|
||||
sqlite_finalize $VM1
|
||||
} {}
|
||||
|
||||
db2 close
|
||||
|
||||
|
||||
-770
@@ -1,770 +0,0 @@
|
||||
# 2003 January 29
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the callback-free C/C++ API.
|
||||
#
|
||||
# $Id: capi3.test,v 1.21 2004/09/02 14:57:09 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Return the UTF-16 representation of the supplied UTF-8 string $str.
|
||||
# If $nt is true, append two 0x00 bytes as a nul terminator.
|
||||
proc utf16 {str {nt 1}} {
|
||||
set r [encoding convertto unicode $str]
|
||||
if {$nt} {
|
||||
append r "\x00\x00"
|
||||
}
|
||||
return $r
|
||||
}
|
||||
|
||||
# Return the UTF-8 representation of the supplied UTF-16 string $str.
|
||||
proc utf8 {str} {
|
||||
# If $str ends in two 0x00 0x00 bytes, knock these off before
|
||||
# converting to UTF-8 using TCL.
|
||||
binary scan $str \c* vals
|
||||
if {[lindex $vals end]==0 && [lindex $vals end-1]==0} {
|
||||
set str [binary format \c* [lrange $vals 0 end-2]]
|
||||
}
|
||||
|
||||
set r [encoding convertfrom unicode $str]
|
||||
return $r
|
||||
}
|
||||
|
||||
# These tests complement those in capi2.test. They are organized
|
||||
# as follows:
|
||||
#
|
||||
# capi3-1.*: Test sqlite3_prepare
|
||||
# capi3-2.*: Test sqlite3_prepare16
|
||||
# capi3-3.*: Test sqlite3_open
|
||||
# capi3-4.*: Test sqlite3_open16
|
||||
# capi3-5.*: Test the various sqlite3_result_* APIs
|
||||
# capi3-6.*: Test that sqlite3_close fails if there are outstanding VMs.
|
||||
#
|
||||
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
|
||||
do_test capi3-1.1 {
|
||||
set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL]
|
||||
sqlite3_finalize $STMT
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi3-1.2 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-1.3 {
|
||||
sqlite3_errmsg $DB
|
||||
} {not an error}
|
||||
do_test capi3-1.4 {
|
||||
set sql {SELECT name FROM sqlite_master;SELECT 10}
|
||||
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
|
||||
sqlite3_finalize $STMT
|
||||
set TAIL
|
||||
} {SELECT 10}
|
||||
do_test capi3-1.5 {
|
||||
set sql {SELECT namex FROM sqlite_master}
|
||||
catch {
|
||||
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
|
||||
}
|
||||
} {1}
|
||||
do_test capi3-1.6 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-1.7 {
|
||||
sqlite3_errmsg $DB
|
||||
} {no such column: namex}
|
||||
|
||||
do_test capi3-2.1 {
|
||||
set sql16 [utf16 {SELECT name FROM sqlite_master}]
|
||||
set STMT [sqlite3_prepare16 $DB $sql16 -1 ::TAIL]
|
||||
sqlite3_finalize $STMT
|
||||
utf8 $::TAIL
|
||||
} {}
|
||||
do_test capi3-2.2 {
|
||||
set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}]
|
||||
set STMT [sqlite3_prepare16 $DB $sql -1 TAIL]
|
||||
sqlite3_finalize $STMT
|
||||
utf8 $TAIL
|
||||
} {SELECT 10}
|
||||
do_test capi3-2.3 {
|
||||
set sql [utf16 {SELECT namex FROM sqlite_master}]
|
||||
catch {
|
||||
set STMT [sqlite3_prepare16 $DB $sql -1 TAIL]
|
||||
}
|
||||
} {1}
|
||||
do_test capi3-2.4 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-2.5 {
|
||||
sqlite3_errmsg $DB
|
||||
} {no such column: namex}
|
||||
|
||||
# rename sqlite3_open sqlite3_open_old
|
||||
# proc sqlite3_open {fname options} {sqlite3_open_new $fname $options}
|
||||
|
||||
do_test capi3-3.1 {
|
||||
set db2 [sqlite3_open test.db {}]
|
||||
sqlite3_errcode $db2
|
||||
} {SQLITE_OK}
|
||||
# FIX ME: Should test the db handle works.
|
||||
do_test capi3-3.2 {
|
||||
sqlite3_close $db2
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-3.3 {
|
||||
catch {
|
||||
set db2 [sqlite3_open /bogus/path/test.db {}]
|
||||
}
|
||||
sqlite3_errcode $db2
|
||||
} {SQLITE_CANTOPEN}
|
||||
do_test capi3-3.4 {
|
||||
sqlite3_errmsg $db2
|
||||
} {unable to open database file}
|
||||
do_test capi3-3.5 {
|
||||
sqlite3_close $db2
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-3.6 {
|
||||
sqlite3_close $db2
|
||||
} {SQLITE_MISUSE}
|
||||
do_test capi3-3.6 {
|
||||
sqlite3_errmsg $db2
|
||||
} {library routine called out of sequence}
|
||||
do_test capi3-3.6 {
|
||||
utf8 [sqlite3_errmsg16 $db2]
|
||||
} {library routine called out of sequence}
|
||||
|
||||
# rename sqlite3_open ""
|
||||
# rename sqlite3_open_old sqlite3_open
|
||||
|
||||
do_test capi3-4.1 {
|
||||
set db2 [sqlite3_open16 [utf16 test.db] {}]
|
||||
sqlite3_errcode $db2
|
||||
} {SQLITE_OK}
|
||||
# FIX ME: Should test the db handle works.
|
||||
do_test capi3-4.2 {
|
||||
sqlite3_close $db2
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-4.3 {
|
||||
catch {
|
||||
set db2 [sqlite3_open16 [utf16 /bogus/path/test.db] {}]
|
||||
}
|
||||
sqlite3_errcode $db2
|
||||
} {SQLITE_CANTOPEN}
|
||||
do_test capi3-4.4 {
|
||||
utf8 [sqlite3_errmsg16 $db2]
|
||||
} {unable to open database file}
|
||||
do_test capi3-4.5 {
|
||||
sqlite3_close $db2
|
||||
} {SQLITE_OK}
|
||||
|
||||
# This proc is used to test the following API calls:
|
||||
#
|
||||
# sqlite3_column_count
|
||||
# sqlite3_column_name
|
||||
# sqlite3_column_name16
|
||||
# sqlite3_column_decltype
|
||||
# sqlite3_column_decltype16
|
||||
#
|
||||
# $STMT is a compiled SQL statement. $test is a prefix
|
||||
# to use for test names within this proc. $names is a list
|
||||
# of the column names that should be returned by $STMT.
|
||||
# $decltypes is a list of column declaration types for $STMT.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY]
|
||||
# check_header test1.1 {1 2 3} {"" "" ""}
|
||||
#
|
||||
proc check_header {STMT test names decltypes} {
|
||||
|
||||
# Use the return value of sqlite3_column_count() to build
|
||||
# a list of column indexes. i.e. If sqlite3_column_count
|
||||
# is 3, build the list {0 1 2}.
|
||||
set ::idxlist [list]
|
||||
set ::numcols [sqlite3_column_count $STMT]
|
||||
for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i}
|
||||
|
||||
# Column names in UTF-8
|
||||
do_test $test.1 {
|
||||
set cnamelist [list]
|
||||
foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]}
|
||||
set cnamelist
|
||||
} $names
|
||||
|
||||
# Column names in UTF-16
|
||||
do_test $test.2 {
|
||||
set cnamelist [list]
|
||||
foreach i $idxlist {
|
||||
lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
|
||||
}
|
||||
set cnamelist
|
||||
} $names
|
||||
|
||||
# Column names in UTF-8
|
||||
do_test $test.3 {
|
||||
set cnamelist [list]
|
||||
foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]}
|
||||
set cnamelist
|
||||
} $names
|
||||
|
||||
# Column names in UTF-16
|
||||
do_test $test.4 {
|
||||
set cnamelist [list]
|
||||
foreach i $idxlist {
|
||||
lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
|
||||
}
|
||||
set cnamelist
|
||||
} $names
|
||||
|
||||
# Column names in UTF-8
|
||||
do_test $test.5 {
|
||||
set cnamelist [list]
|
||||
foreach i $idxlist {lappend cnamelist [sqlite3_column_decltype $STMT $i]}
|
||||
set cnamelist
|
||||
} $decltypes
|
||||
|
||||
# Column declaration types in UTF-16
|
||||
do_test $test.6 {
|
||||
set cnamelist [list]
|
||||
foreach i $idxlist {
|
||||
lappend cnamelist [utf8 [sqlite3_column_decltype16 $STMT $i]]
|
||||
}
|
||||
set cnamelist
|
||||
} $decltypes
|
||||
|
||||
|
||||
# Test some out of range conditions:
|
||||
do_test $test.7 {
|
||||
list \
|
||||
[sqlite3_column_name $STMT -1] \
|
||||
[sqlite3_column_name16 $STMT -1] \
|
||||
[sqlite3_column_decltype $STMT -1] \
|
||||
[sqlite3_column_decltype16 $STMT -1] \
|
||||
[sqlite3_column_name $STMT $numcols] \
|
||||
[sqlite3_column_name16 $STMT $numcols] \
|
||||
[sqlite3_column_decltype $STMT $numcols] \
|
||||
[sqlite3_column_decltype16 $STMT $numcols]
|
||||
} {{} {} {} {} {} {} {} {}}
|
||||
|
||||
}
|
||||
|
||||
# This proc is used to test the following APIs:
|
||||
#
|
||||
# sqlite3_data_count
|
||||
# sqlite3_column_type
|
||||
# sqlite3_column_int
|
||||
# sqlite3_column_text
|
||||
# sqlite3_column_text16
|
||||
# sqlite3_column_double
|
||||
#
|
||||
# $STMT is a compiled SQL statement for which the previous call
|
||||
# to sqlite3_step returned SQLITE_ROW. $test is a prefix to use
|
||||
# for test names within this proc. $types is a list of the
|
||||
# manifest types for the current row. $ints, $doubles and $strings
|
||||
# are lists of the integer, real and string representations of
|
||||
# the values in the current row.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# set STMT [sqlite3_prepare "SELECT 'hello', 1.1, NULL" -1 DUMMY]
|
||||
# sqlite3_step $STMT
|
||||
# check_data test1.2 {TEXT REAL NULL} {0 1 0} {0 1.1 0} {hello 1.1 {}}
|
||||
#
|
||||
proc check_data {STMT test types ints doubles strings} {
|
||||
|
||||
# Use the return value of sqlite3_column_count() to build
|
||||
# a list of column indexes. i.e. If sqlite3_column_count
|
||||
# is 3, build the list {0 1 2}.
|
||||
set ::idxlist [list]
|
||||
set numcols [sqlite3_data_count $STMT]
|
||||
for {set i 0} {$i < $numcols} {incr i} {lappend ::idxlist $i}
|
||||
|
||||
# types
|
||||
do_test $test.1 {
|
||||
set types [list]
|
||||
foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}
|
||||
set types
|
||||
} $types
|
||||
|
||||
# Integers
|
||||
do_test $test.2 {
|
||||
set ints [list]
|
||||
foreach i $idxlist {lappend ints [sqlite3_column_int64 $STMT $i]}
|
||||
set ints
|
||||
} $ints
|
||||
|
||||
# bytes
|
||||
set lens [list]
|
||||
foreach i $::idxlist {
|
||||
lappend lens [string length [lindex $strings $i]]
|
||||
}
|
||||
do_test $test.3 {
|
||||
set bytes [list]
|
||||
set lens [list]
|
||||
foreach i $idxlist {
|
||||
lappend bytes [sqlite3_column_bytes $STMT $i]
|
||||
}
|
||||
set bytes
|
||||
} $lens
|
||||
|
||||
# bytes16
|
||||
set lens [list]
|
||||
foreach i $::idxlist {
|
||||
lappend lens [expr 2 * [string length [lindex $strings $i]]]
|
||||
}
|
||||
do_test $test.4 {
|
||||
set bytes [list]
|
||||
set lens [list]
|
||||
foreach i $idxlist {
|
||||
lappend bytes [sqlite3_column_bytes16 $STMT $i]
|
||||
}
|
||||
set bytes
|
||||
} $lens
|
||||
|
||||
# Blob
|
||||
do_test $test.5 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [sqlite3_column_blob $STMT $i]}
|
||||
set utf8
|
||||
} $strings
|
||||
|
||||
# UTF-8
|
||||
do_test $test.6 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
|
||||
set utf8
|
||||
} $strings
|
||||
|
||||
# Floats
|
||||
do_test $test.7 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
|
||||
set utf8
|
||||
} $doubles
|
||||
|
||||
# UTF-16
|
||||
do_test $test.8 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]}
|
||||
set utf8
|
||||
} $strings
|
||||
|
||||
# Integers
|
||||
do_test $test.9 {
|
||||
set ints [list]
|
||||
foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]}
|
||||
set ints
|
||||
} $ints
|
||||
|
||||
# Floats
|
||||
do_test $test.10 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
|
||||
set utf8
|
||||
} $doubles
|
||||
|
||||
# UTF-8
|
||||
do_test $test.11 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
|
||||
set utf8
|
||||
} $strings
|
||||
|
||||
# Types
|
||||
do_test $test.12 {
|
||||
set types [list]
|
||||
foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}
|
||||
set types
|
||||
} $types
|
||||
|
||||
# Test that an out of range request returns the equivalent of NULL
|
||||
do_test $test.13 {
|
||||
sqlite3_column_int $STMT -1
|
||||
} {0}
|
||||
do_test $test.13 {
|
||||
sqlite3_column_text $STMT -1
|
||||
} {}
|
||||
|
||||
}
|
||||
|
||||
do_test capi3-5.0 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16));
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t1 VALUES('one', 'two', NULL);
|
||||
INSERT INTO t1 VALUES(1.2, 1.3, 1.4);
|
||||
}
|
||||
set sql "SELECT * FROM t1"
|
||||
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
|
||||
sqlite3_column_count $STMT
|
||||
} 3
|
||||
|
||||
check_header $STMT capi3-5.1 {a b c} {VARINT BLOB VARCHAR(16)}
|
||||
do_test capi3-5.2 {
|
||||
sqlite3_step $STMT
|
||||
} SQLITE_ROW
|
||||
|
||||
check_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)}
|
||||
check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}
|
||||
|
||||
do_test capi3-5.5 {
|
||||
sqlite3_step $STMT
|
||||
} SQLITE_ROW
|
||||
|
||||
check_header $STMT capi3-5.6 {a b c} {VARINT BLOB VARCHAR(16)}
|
||||
check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}}
|
||||
|
||||
do_test capi3-5.8 {
|
||||
sqlite3_step $STMT
|
||||
} SQLITE_ROW
|
||||
|
||||
check_header $STMT capi3-5.9 {a b c} {VARINT BLOB VARCHAR(16)}
|
||||
check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4}
|
||||
|
||||
do_test capi3-5.11 {
|
||||
sqlite3_step $STMT
|
||||
} SQLITE_DONE
|
||||
|
||||
do_test capi3-5.12 {
|
||||
sqlite3_finalize $STMT
|
||||
} SQLITE_OK
|
||||
|
||||
set ::ENC [execsql {pragma encoding}]
|
||||
db close
|
||||
|
||||
do_test capi3-6.0 {
|
||||
set DB [sqlite3_open test.db]
|
||||
sqlite3_key $DB xyzzy
|
||||
set sql {SELECT a FROM t1 order by rowid}
|
||||
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
|
||||
expr 0
|
||||
} {0}
|
||||
do_test capi3-6.1 {
|
||||
sqlite3_close $DB
|
||||
} {SQLITE_BUSY}
|
||||
do_test capi3-6.2 {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ROW}
|
||||
check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1}
|
||||
do_test capi3-6.3 {
|
||||
sqlite3_finalize $STMT
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-6.4 {
|
||||
sqlite3_close $DB
|
||||
} {SQLITE_OK}
|
||||
|
||||
if {![sqlite3 -has-codec]} {
|
||||
# Test what happens when the library encounters a newer file format.
|
||||
# Do this by updating the file format via the btree layer.
|
||||
do_test capi3-7.1 {
|
||||
set ::bt [btree_open test.db 10 0]
|
||||
btree_begin_transaction $::bt
|
||||
set meta [btree_get_meta $::bt]
|
||||
lset meta 2 2
|
||||
eval [concat btree_update_meta $::bt [lrange $meta 0 end]]
|
||||
btree_commit $::bt
|
||||
btree_close $::bt
|
||||
} {}
|
||||
do_test capi3-7.2 {
|
||||
sqlite3 db test.db
|
||||
catchsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
} {1 {unsupported file format}}
|
||||
db close
|
||||
}
|
||||
|
||||
if {![sqlite3 -has-codec]} {
|
||||
# Now test that the library correctly handles bogus entries in the
|
||||
# sqlite_master table (schema corruption).
|
||||
do_test capi3-8.1 {
|
||||
file delete -force test.db
|
||||
file delete -force test.db-journal
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
CREATE TABLE t1(a);
|
||||
}
|
||||
db close
|
||||
} {}
|
||||
do_test capi3-8.2 {
|
||||
set ::bt [btree_open test.db 10 0]
|
||||
btree_begin_transaction $::bt
|
||||
set ::bc [btree_cursor $::bt 1 1]
|
||||
|
||||
# Build a 5-field row record consisting of 5 null records. This is
|
||||
# officially black magic.
|
||||
catch {unset data}
|
||||
set data [binary format c6 {6 0 0 0 0 0}]
|
||||
btree_insert $::bc 5 $data
|
||||
|
||||
btree_close_cursor $::bc
|
||||
btree_commit $::bt
|
||||
btree_close $::bt
|
||||
} {}
|
||||
do_test capi3-8.3 {
|
||||
sqlite3 db test.db
|
||||
catchsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
} {1 {malformed database schema}}
|
||||
do_test capi3-8.4 {
|
||||
set ::bt [btree_open test.db 10 0]
|
||||
btree_begin_transaction $::bt
|
||||
set ::bc [btree_cursor $::bt 1 1]
|
||||
|
||||
# Build a 5-field row record. The first field is a string 'table', and
|
||||
# subsequent fields are all NULL. Replace the other broken record with
|
||||
# this one and try to read the schema again. The broken record uses
|
||||
# either UTF-8 or native UTF-16 (if this file is being run by
|
||||
# utf16.test).
|
||||
if { [string match UTF-16* $::ENC] } {
|
||||
set data [binary format c6a10 {6 33 0 0 0 0} [utf16 table]]
|
||||
} else {
|
||||
set data [binary format c6a5 {6 23 0 0 0 0} table]
|
||||
}
|
||||
btree_insert $::bc 5 $data
|
||||
|
||||
btree_close_cursor $::bc
|
||||
btree_commit $::bt
|
||||
btree_close $::bt
|
||||
} {};
|
||||
do_test capi3-8.5 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
catchsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
} {1 {malformed database schema}}
|
||||
db close
|
||||
}
|
||||
file delete -force test.db
|
||||
file delete -force test.db-journal
|
||||
|
||||
|
||||
# Test the english language string equivalents for sqlite error codes
|
||||
set code2english [list \
|
||||
SQLITE_OK {not an error} \
|
||||
SQLITE_ERROR {SQL logic error or missing database} \
|
||||
SQLITE_INTERNAL {internal SQLite implementation flaw} \
|
||||
SQLITE_PERM {access permission denied} \
|
||||
SQLITE_ABORT {callback requested query abort} \
|
||||
SQLITE_BUSY {database is locked} \
|
||||
SQLITE_LOCKED {database table is locked} \
|
||||
SQLITE_NOMEM {out of memory} \
|
||||
SQLITE_READONLY {attempt to write a readonly database} \
|
||||
SQLITE_INTERRUPT {interrupted} \
|
||||
SQLITE_IOERR {disk I/O error} \
|
||||
SQLITE_CORRUPT {database disk image is malformed} \
|
||||
SQLITE_NOTFOUND {table or record not found} \
|
||||
SQLITE_FULL {database is full} \
|
||||
SQLITE_CANTOPEN {unable to open database file} \
|
||||
SQLITE_PROTOCOL {database locking protocol failure} \
|
||||
SQLITE_EMPTY {table contains no data} \
|
||||
SQLITE_SCHEMA {database schema has changed} \
|
||||
SQLITE_TOOBIG {too much data for one table row} \
|
||||
SQLITE_CONSTRAINT {constraint failed} \
|
||||
SQLITE_MISMATCH {datatype mismatch} \
|
||||
SQLITE_MISUSE {library routine called out of sequence} \
|
||||
SQLITE_NOLFS {kernel lacks large file support} \
|
||||
SQLITE_AUTH {authorization denied} \
|
||||
SQLITE_FORMAT {auxiliary database format error} \
|
||||
SQLITE_RANGE {bind index out of range} \
|
||||
SQLITE_NOTADB {file is encrypted or is not a database} \
|
||||
unknownerror {unknown error} \
|
||||
]
|
||||
|
||||
set test_number 1
|
||||
foreach {code english} $code2english {
|
||||
do_test capi3-9.$test_number "sqlite3_test_errstr $code" $english
|
||||
incr test_number
|
||||
}
|
||||
|
||||
# Test the error message when a "real" out of memory occurs.
|
||||
if {[info command sqlite_malloc_stat]!=""} {
|
||||
set sqlite_malloc_fail 1
|
||||
do_test capi3-10-1 {
|
||||
set ::DB [sqlite3 db test.db]
|
||||
sqlite_malloc_fail 1
|
||||
catchsql {
|
||||
select * from sqlite_master;
|
||||
}
|
||||
} {1 {out of memory}}
|
||||
do_test capi3-10-2 {
|
||||
sqlite3_errmsg $::DB
|
||||
} {out of memory}
|
||||
do_test capi3-10-3 {
|
||||
utf8 [sqlite3_errmsg16 $::DB]
|
||||
} {out of memory}
|
||||
db close
|
||||
sqlite_malloc_fail 0
|
||||
}
|
||||
|
||||
# The following tests - capi3-11.* - test that a COMMIT or ROLLBACK
|
||||
# statement issued while there are still outstanding VMs that are part of
|
||||
# the transaction fails.
|
||||
set DB [sqlite3 db test.db]
|
||||
sqlite_register_test_function $DB func
|
||||
do_test capi3-11.1 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE t1(a, b);
|
||||
INSERT INTO t1 VALUES(1, 'int');
|
||||
INSERT INTO t1 VALUES(2, 'notatype');
|
||||
}
|
||||
} {}
|
||||
do_test capi3-11.2 {
|
||||
set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test capi3-11.3 {
|
||||
catchsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {1 {cannot commit transaction - SQL statements in progress}}
|
||||
do_test capi3-11.4 {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-11.5 {
|
||||
sqlite3_finalize $STMT
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-11.6 {
|
||||
catchsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 {1 int 2 notatype}}
|
||||
do_test capi3-11.7 {
|
||||
catchsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test capi3-11.8 {
|
||||
execsql {
|
||||
CREATE TABLE t2(a);
|
||||
INSERT INTO t2 VALUES(1);
|
||||
INSERT INTO t2 VALUES(2);
|
||||
BEGIN;
|
||||
INSERT INTO t2 VALUES(3);
|
||||
}
|
||||
} {}
|
||||
do_test capi3-11.9 {
|
||||
set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test capi3-11.3 {
|
||||
catchsql {
|
||||
ROLLBACK;
|
||||
}
|
||||
} {1 {cannot rollback transaction - SQL statements in progress}}
|
||||
do_test capi3-11.10 {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test capi3-11.11 {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test capi3-11.12 {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test capi3-11.13 {
|
||||
sqlite3_finalize $STMT
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-11.14 {
|
||||
execsql {
|
||||
SELECT a FROM t2;
|
||||
}
|
||||
} {1 2 3}
|
||||
do_test capi3-11.15 {
|
||||
catchsql {
|
||||
ROLLBACK;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test capi3-11.16 {
|
||||
execsql {
|
||||
SELECT a FROM t2;
|
||||
}
|
||||
} {1 2}
|
||||
|
||||
# Sanity check on the definition of 'outstanding VM'. This means any VM
|
||||
# that has had sqlite3_step() called more recently than sqlite3_finalize() or
|
||||
# sqlite3_reset(). So a VM that has just been prepared or reset does not
|
||||
# count as an active VM.
|
||||
do_test capi3-11.17 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
}
|
||||
} {}
|
||||
do_test capi3-11.18 {
|
||||
set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
|
||||
catchsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test capi3-11.19 {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test capi3-11.20 {
|
||||
catchsql {
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
}
|
||||
} {1 {cannot commit transaction - SQL statements in progress}}
|
||||
do_test capi3-11.20 {
|
||||
sqlite3_reset $STMT
|
||||
catchsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test capi3-11.21 {
|
||||
sqlite3_finalize $STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
# The following tests - capi3-12.* - check that it's Ok to start a
|
||||
# transaction while other VMs are active, and that it's Ok to execute
|
||||
# atomic updates in the same situation (so long as they are on a different
|
||||
# table).
|
||||
do_test capi3-12.1 {
|
||||
set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test capi3-12.2 {
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(3, NULL);
|
||||
}
|
||||
} {0 {}}
|
||||
do_test capi3-12.3 {
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(4);
|
||||
}
|
||||
} {1 {database table is locked}}
|
||||
do_test capi3-12.4 {
|
||||
catchsql {
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES(4, NULL);
|
||||
}
|
||||
} {0 {}}
|
||||
do_test capi3-12.5 {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test capi3-12.6 {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test capi3-12.7 {
|
||||
sqlite3_finalize $STMT
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-12.8 {
|
||||
execsql {
|
||||
COMMIT;
|
||||
SELECT a FROM t1;
|
||||
}
|
||||
} {1 2 3 4}
|
||||
|
||||
|
||||
finish_test
|
||||
@@ -1,90 +0,0 @@
|
||||
# 2004 September 2
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the callback-free C/C++ API and in
|
||||
# particular the behavior of sqlite3_step() when trying to commit
|
||||
# with lock contention.
|
||||
#
|
||||
# $Id: capi3b.test,v 1.1 2004/09/02 14:57:09 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
set DB2 [sqlite3 db2 test.db]
|
||||
|
||||
# Create some data in the database
|
||||
#
|
||||
do_test capi3b-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(x);
|
||||
INSERT INTO t1 VALUES(1);
|
||||
INSERT INTO t1 VALUES(2);
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 2}
|
||||
|
||||
# Make sure the second database connection can see the data
|
||||
#
|
||||
do_test capi3b-1.2 {
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
} db2
|
||||
} {1 2}
|
||||
|
||||
# First database connection acquires a shared lock
|
||||
#
|
||||
do_test capi3b-1.3 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 2}
|
||||
|
||||
# Second database connection tries to write. The sqlite3_step()
|
||||
# function returns SQLITE_BUSY because it cannot commit.
|
||||
#
|
||||
do_test capi3b-1.4 {
|
||||
set VM [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(3)} -1 TAIL]
|
||||
sqlite3_step $VM
|
||||
} SQLITE_BUSY
|
||||
|
||||
# The sqlite3_step call can be repeated multiple times.
|
||||
#
|
||||
do_test capi3b-1.5.1 {
|
||||
sqlite3_step $VM
|
||||
} SQLITE_BUSY
|
||||
do_test capi3b-1.5.2 {
|
||||
sqlite3_step $VM
|
||||
} SQLITE_BUSY
|
||||
|
||||
# The first connection closes its transaction. This allows the second
|
||||
# connections sqlite3_step to succeed.
|
||||
#
|
||||
do_test capi3b-1.6 {
|
||||
execsql COMMIT
|
||||
sqlite3_step $VM
|
||||
} SQLITE_DONE
|
||||
do_test capi3b-1.7 {
|
||||
sqlite3_finalize $VM
|
||||
} SQLITE_OK
|
||||
do_test capi3b-1.8 {
|
||||
execsql {SELECT * FROM t1} db2
|
||||
} {1 2 3}
|
||||
do_test capi3b-1.9 {
|
||||
execsql {SELECT * FROM t1}
|
||||
} {1 2 3}
|
||||
|
||||
catch {db2 close}
|
||||
finish_test
|
||||
@@ -1,229 +0,0 @@
|
||||
#
|
||||
# 2001 September 15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is page cache subsystem.
|
||||
#
|
||||
# $Id: collate1.test,v 1.3 2004/08/20 18:34:20 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
#
|
||||
# Tests are roughly organised as follows:
|
||||
#
|
||||
# collate1-1.* - Single-field ORDER BY with an explicit COLLATE clause.
|
||||
# collate1-2.* - Multi-field ORDER BY with an explicit COLLATE clause.
|
||||
# collate1-3.* - ORDER BY using a default collation type. Also that an
|
||||
# explict collate type overrides a default collate type.
|
||||
# collate1-4.* - ORDER BY using a data type.
|
||||
#
|
||||
|
||||
#
|
||||
# Collation type 'HEX'. If an argument can be interpreted as a hexadecimal
|
||||
# number, then it is converted to one before the comparison is performed.
|
||||
# Numbers are less than other strings. If neither argument is a number,
|
||||
# [string compare] is used.
|
||||
#
|
||||
db collate HEX hex_collate
|
||||
proc hex_collate {lhs rhs} {
|
||||
set lhs_ishex [regexp {^(0x|)[1234567890abcdefABCDEF]+$} $lhs]
|
||||
set rhs_ishex [regexp {^(0x|)[1234567890abcdefABCDEF]+$} $rhs]
|
||||
if {$lhs_ishex && $rhs_ishex} {
|
||||
set lhsx [scan $lhs %x]
|
||||
set rhsx [scan $rhs %x]
|
||||
if {$lhs < $rhs} {return -1}
|
||||
if {$lhs == $rhs} {return 0}
|
||||
if {$lhs > $rhs} {return 1}
|
||||
}
|
||||
if {$lhs_ishex} {
|
||||
return -1;
|
||||
}
|
||||
if {$rhs_ishex} {
|
||||
return 1;
|
||||
}
|
||||
return [string compare $lhs $rhs]
|
||||
}
|
||||
db function hex {format 0x%X}
|
||||
|
||||
# Mimic the SQLite 2 collation type NUMERIC.
|
||||
db collate numeric numeric_collate
|
||||
proc numeric_collate {lhs rhs} {
|
||||
if {$lhs == $rhs} {return 0}
|
||||
return [expr ($lhs>$rhs)?1:-1]
|
||||
}
|
||||
|
||||
do_test collate1-1.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate1t1(c1, c2);
|
||||
INSERT INTO collate1t1 VALUES(45, hex(45));
|
||||
INSERT INTO collate1t1 VALUES(NULL, NULL);
|
||||
INSERT INTO collate1t1 VALUES(281, hex(281));
|
||||
}
|
||||
} {}
|
||||
do_test collate1-1.1 {
|
||||
execsql {
|
||||
SELECT c2 FROM collate1t1 ORDER BY 1;
|
||||
}
|
||||
} {{} 0x119 0x2D}
|
||||
do_test collate1-1.2 {
|
||||
execsql {
|
||||
SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex;
|
||||
}
|
||||
} {{} 0x2D 0x119}
|
||||
do_test collate1-1.3 {
|
||||
execsql {
|
||||
SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex DESC;
|
||||
}
|
||||
} {0x119 0x2D {}}
|
||||
do_test collate1-1.4 {
|
||||
execsql {
|
||||
SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex ASC;
|
||||
}
|
||||
} {{} 0x2D 0x119}
|
||||
do_test collate1-1.5 {
|
||||
execsql {
|
||||
DROP TABLE collate1t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test collate1-2.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate1t1(c1, c2);
|
||||
INSERT INTO collate1t1 VALUES('5', '0x11');
|
||||
INSERT INTO collate1t1 VALUES('5', '0xA');
|
||||
INSERT INTO collate1t1 VALUES(NULL, NULL);
|
||||
INSERT INTO collate1t1 VALUES('7', '0xA');
|
||||
INSERT INTO collate1t1 VALUES('11', '0x11');
|
||||
INSERT INTO collate1t1 VALUES('11', '0x101');
|
||||
}
|
||||
} {}
|
||||
do_test collate1-2.2 {
|
||||
execsql {
|
||||
SELECT c1, c2 FROM collate1t1 ORDER BY 1 COLLATE numeric, 2 COLLATE hex;
|
||||
}
|
||||
} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101}
|
||||
do_test collate1-2.3 {
|
||||
execsql {
|
||||
SELECT c1, c2 FROM collate1t1 ORDER BY 1 COLLATE binary, 2 COLLATE hex;
|
||||
}
|
||||
} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA}
|
||||
do_test collate1-2.4 {
|
||||
execsql {
|
||||
SELECT c1, c2 FROM collate1t1 ORDER BY 1 COLLATE binary DESC, 2 COLLATE hex;
|
||||
}
|
||||
} {7 0xA 5 0xA 5 0x11 11 0x11 11 0x101 {} {}}
|
||||
do_test collate1-2.5 {
|
||||
execsql {
|
||||
SELECT c1, c2 FROM collate1t1
|
||||
ORDER BY 1 COLLATE binary DESC, 2 COLLATE hex DESC;
|
||||
}
|
||||
} {7 0xA 5 0x11 5 0xA 11 0x101 11 0x11 {} {}}
|
||||
do_test collate1-2.6 {
|
||||
execsql {
|
||||
SELECT c1, c2 FROM collate1t1
|
||||
ORDER BY 1 COLLATE binary ASC, 2 COLLATE hex ASC;
|
||||
}
|
||||
} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA}
|
||||
do_test collate1-2.7 {
|
||||
execsql {
|
||||
DROP TABLE collate1t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
#
|
||||
# These tests ensure that the default collation type for a column is used
|
||||
# by an ORDER BY clause correctly. The focus is all the different ways
|
||||
# the column can be referenced. i.e. a, collate2t1.a, main.collate2t1.a etc.
|
||||
#
|
||||
do_test collate1-3.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate1t1(a COLLATE hex, b);
|
||||
INSERT INTO collate1t1 VALUES( '0x5', 5 );
|
||||
INSERT INTO collate1t1 VALUES( '1', 1 );
|
||||
INSERT INTO collate1t1 VALUES( '0x45', 69 );
|
||||
INSERT INTO collate1t1 VALUES( NULL, NULL );
|
||||
SELECT * FROM collate1t1 ORDER BY a;
|
||||
}
|
||||
} {{} {} 1 1 0x5 5 0x45 69}
|
||||
|
||||
do_test collate1-3.1 {
|
||||
execsql {
|
||||
SELECT * FROM collate1t1 ORDER BY 1;
|
||||
}
|
||||
} {{} {} 1 1 0x5 5 0x45 69}
|
||||
do_test collate1-3.2 {
|
||||
execsql {
|
||||
SELECT * FROM collate1t1 ORDER BY collate1t1.a;
|
||||
}
|
||||
} {{} {} 1 1 0x5 5 0x45 69}
|
||||
do_test collate1-3.3 {
|
||||
execsql {
|
||||
SELECT * FROM collate1t1 ORDER BY main.collate1t1.a;
|
||||
}
|
||||
} {{} {} 1 1 0x5 5 0x45 69}
|
||||
do_test collate1-3.4 {
|
||||
execsql {
|
||||
SELECT a as c1, b as c2 FROM collate1t1 ORDER BY c1;
|
||||
}
|
||||
} {{} {} 1 1 0x5 5 0x45 69}
|
||||
do_test collate1-3.5 {
|
||||
execsql {
|
||||
SELECT a as c1, b as c2 FROM collate1t1 ORDER BY c1 COLLATE binary;
|
||||
}
|
||||
} {{} {} 0x45 69 0x5 5 1 1}
|
||||
do_test collate1-3.6 {
|
||||
execsql {
|
||||
DROP TABLE collate1t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Update for SQLite version 3. The collate1-4.* test cases were written
|
||||
# before manifest types were introduced. The following test cases still
|
||||
# work, due to the 'affinity' mechanism, but they don't prove anything
|
||||
# about collation sequences.
|
||||
#
|
||||
do_test collate1-4.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate1t1(c1 numeric, c2 text);
|
||||
INSERT INTO collate1t1 VALUES(1, 1);
|
||||
INSERT INTO collate1t1 VALUES(12, 12);
|
||||
INSERT INTO collate1t1 VALUES(NULL, NULL);
|
||||
INSERT INTO collate1t1 VALUES(101, 101);
|
||||
}
|
||||
} {}
|
||||
do_test collate1-4.1 {
|
||||
execsql {
|
||||
SELECT c1 FROM collate1t1 ORDER BY 1;
|
||||
}
|
||||
} {{} 1 12 101}
|
||||
do_test collate1-4.2 {
|
||||
execsql {
|
||||
SELECT c2 FROM collate1t1 ORDER BY 1;
|
||||
}
|
||||
} {{} 1 101 12}
|
||||
do_test collate1-4.3 {
|
||||
execsql {
|
||||
SELECT c2+0 FROM collate1t1 ORDER BY 1;
|
||||
}
|
||||
} {{} 1.0 12.0 101.0}
|
||||
do_test collate1-4.4 {
|
||||
execsql {
|
||||
SELECT c1||'' FROM collate1t1 ORDER BY 1;
|
||||
}
|
||||
} {{} 1 101 12}
|
||||
do_test collate1-4.5 {
|
||||
execsql {
|
||||
DROP TABLE collate1t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
finish_test
|
||||
@@ -1,608 +0,0 @@
|
||||
#
|
||||
# 2001 September 15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is page cache subsystem.
|
||||
#
|
||||
# $Id: collate2.test,v 1.2 2004/06/11 10:51:41 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
#
|
||||
# Tests are organised as follows:
|
||||
#
|
||||
# collate2-1.* WHERE <expr> expressions (sqliteExprIfTrue).
|
||||
# collate2-2.* WHERE NOT <expr> expressions (sqliteExprIfFalse).
|
||||
# collate2-3.* SELECT <expr> expressions (sqliteExprCode).
|
||||
# collate2-4.* Precedence of collation/data types in binary comparisons
|
||||
# collate2-5.* JOIN syntax.
|
||||
#
|
||||
|
||||
# Create a collation type BACKWARDS for use in testing. This collation type
|
||||
# is similar to the built-in TEXT collation type except the order of
|
||||
# characters in each string is reversed before the comparison is performed.
|
||||
db collate BACKWARDS backwards_collate
|
||||
proc backwards_collate {a b} {
|
||||
set ra {};
|
||||
set rb {}
|
||||
foreach c [split $a {}] { set ra $c$ra }
|
||||
foreach c [split $b {}] { set rb $c$rb }
|
||||
return [string compare $ra $rb]
|
||||
}
|
||||
|
||||
# The following values are used in these tests:
|
||||
# NULL aa ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB
|
||||
#
|
||||
# The collation orders for each of the tested collation types are:
|
||||
#
|
||||
# BINARY: NULL AA AB Aa Ab BA BB Ba Bb aA aB aa ab bA bB ba bb
|
||||
# NOCASE: NULL aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB
|
||||
# BACKWARDS: NULL AA BA aA bA AB BB aB bB Aa Ba aa ba Ab Bb ab bb
|
||||
#
|
||||
# These tests verify that the default collation type for a column is used
|
||||
# for comparison operators (<, >, <=, >=, =) involving that column and
|
||||
# an expression that is not a column with a default collation type.
|
||||
#
|
||||
# The collation sequences BINARY and NOCASE are built-in, the BACKWARDS
|
||||
# collation sequence is implemented by the TCL proc backwards_collate
|
||||
# above.
|
||||
#
|
||||
do_test collate2-1.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate2t1(
|
||||
a COLLATE BINARY,
|
||||
b COLLATE NOCASE,
|
||||
c COLLATE BACKWARDS
|
||||
);
|
||||
INSERT INTO collate2t1 VALUES( NULL, NULL, NULL );
|
||||
|
||||
INSERT INTO collate2t1 VALUES( 'aa', 'aa', 'aa' );
|
||||
INSERT INTO collate2t1 VALUES( 'ab', 'ab', 'ab' );
|
||||
INSERT INTO collate2t1 VALUES( 'ba', 'ba', 'ba' );
|
||||
INSERT INTO collate2t1 VALUES( 'bb', 'bb', 'bb' );
|
||||
|
||||
INSERT INTO collate2t1 VALUES( 'aA', 'aA', 'aA' );
|
||||
INSERT INTO collate2t1 VALUES( 'aB', 'aB', 'aB' );
|
||||
INSERT INTO collate2t1 VALUES( 'bA', 'bA', 'bA' );
|
||||
INSERT INTO collate2t1 VALUES( 'bB', 'bB', 'bB' );
|
||||
|
||||
INSERT INTO collate2t1 VALUES( 'Aa', 'Aa', 'Aa' );
|
||||
INSERT INTO collate2t1 VALUES( 'Ab', 'Ab', 'Ab' );
|
||||
INSERT INTO collate2t1 VALUES( 'Ba', 'Ba', 'Ba' );
|
||||
INSERT INTO collate2t1 VALUES( 'Bb', 'Bb', 'Bb' );
|
||||
|
||||
INSERT INTO collate2t1 VALUES( 'AA', 'AA', 'AA' );
|
||||
INSERT INTO collate2t1 VALUES( 'AB', 'AB', 'AB' );
|
||||
INSERT INTO collate2t1 VALUES( 'BA', 'BA', 'BA' );
|
||||
INSERT INTO collate2t1 VALUES( 'BB', 'BB', 'BB' );
|
||||
}
|
||||
if {[info exists collate_test_use_index]} {
|
||||
execsql {
|
||||
CREATE INDEX collate2t1_i1 ON collate2t1(a);
|
||||
CREATE INDEX collate2t1_i2 ON collate2t1(b);
|
||||
CREATE INDEX collate2t1_i3 ON collate2t1(c);
|
||||
}
|
||||
}
|
||||
} {}
|
||||
do_test collate2-1.1 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE a > 'aa' ORDER BY 1;
|
||||
}
|
||||
} {ab bA bB ba bb}
|
||||
do_test collate2-1.2 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE b > 'aa' ORDER BY 1, oid;
|
||||
}
|
||||
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
|
||||
do_test collate2-1.3 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE c > 'aa' ORDER BY 1;
|
||||
}
|
||||
} {ba Ab Bb ab bb}
|
||||
do_test collate2-1.4 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE a < 'aa' ORDER BY 1;
|
||||
}
|
||||
} {AA AB Aa Ab BA BB Ba Bb aA aB}
|
||||
do_test collate2-1.5 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE b < 'aa' ORDER BY 1, oid;
|
||||
}
|
||||
} {}
|
||||
do_test collate2-1.6 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE c < 'aa' ORDER BY 1;
|
||||
}
|
||||
} {AA BA aA bA AB BB aB bB Aa Ba}
|
||||
do_test collate2-1.7 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE a = 'aa';
|
||||
}
|
||||
} {aa}
|
||||
do_test collate2-1.8 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE b = 'aa' ORDER BY oid;
|
||||
}
|
||||
} {aa aA Aa AA}
|
||||
do_test collate2-1.9 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE c = 'aa';
|
||||
}
|
||||
} {aa}
|
||||
do_test collate2-1.10 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE a >= 'aa' ORDER BY 1;
|
||||
}
|
||||
} {aa ab bA bB ba bb}
|
||||
do_test collate2-1.11 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE b >= 'aa' ORDER BY 1, oid;
|
||||
}
|
||||
} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB}
|
||||
do_test collate2-1.12 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE c >= 'aa' ORDER BY 1;
|
||||
}
|
||||
} {aa ba Ab Bb ab bb}
|
||||
do_test collate2-1.13 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE a <= 'aa' ORDER BY 1;
|
||||
}
|
||||
} {AA AB Aa Ab BA BB Ba Bb aA aB aa}
|
||||
do_test collate2-1.14 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE b <= 'aa' ORDER BY 1, oid;
|
||||
}
|
||||
} {aa aA Aa AA}
|
||||
do_test collate2-1.15 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE c <= 'aa' ORDER BY 1;
|
||||
}
|
||||
} {AA BA aA bA AB BB aB bB Aa Ba aa}
|
||||
do_test collate2-1.16 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE a BETWEEN 'Aa' AND 'Bb' ORDER BY 1;
|
||||
}
|
||||
} {Aa Ab BA BB Ba Bb}
|
||||
do_test collate2-1.17 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE b BETWEEN 'Aa' AND 'Bb' ORDER BY 1, oid;
|
||||
}
|
||||
} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB}
|
||||
do_test collate2-1.18 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE c BETWEEN 'Aa' AND 'Bb' ORDER BY 1;
|
||||
}
|
||||
} {Aa Ba aa ba Ab Bb}
|
||||
do_test collate2-1.19 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE
|
||||
CASE a WHEN 'aa' THEN 1 ELSE 0 END
|
||||
ORDER BY 1, oid;
|
||||
}
|
||||
} {aa}
|
||||
do_test collate2-1.20 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE
|
||||
CASE b WHEN 'aa' THEN 1 ELSE 0 END
|
||||
ORDER BY 1, oid;
|
||||
}
|
||||
} {aa aA Aa AA}
|
||||
do_test collate2-1.21 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE
|
||||
CASE c WHEN 'aa' THEN 1 ELSE 0 END
|
||||
ORDER BY 1, oid;
|
||||
}
|
||||
} {aa}
|
||||
do_test collate2-1.22 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb') ORDER BY 1, oid;
|
||||
}
|
||||
} {aa bb}
|
||||
do_test collate2-1.23 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE b IN ('aa', 'bb') ORDER BY 1, oid;
|
||||
}
|
||||
} {aa aA Aa AA bb bB Bb BB}
|
||||
do_test collate2-1.24 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE c IN ('aa', 'bb') ORDER BY 1, oid;
|
||||
}
|
||||
} {aa bb}
|
||||
do_test collate2-1.25 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1
|
||||
WHERE a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
|
||||
}
|
||||
} {aa bb}
|
||||
do_test collate2-1.26 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1
|
||||
WHERE b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
|
||||
}
|
||||
} {aa bb aA bB Aa Bb AA BB}
|
||||
do_test collate2-1.27 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1
|
||||
WHERE c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
|
||||
}
|
||||
} {aa bb}
|
||||
|
||||
do_test collate2-2.1 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE NOT a > 'aa' ORDER BY 1;
|
||||
}
|
||||
} {AA AB Aa Ab BA BB Ba Bb aA aB aa}
|
||||
do_test collate2-2.2 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE NOT b > 'aa' ORDER BY 1, oid;
|
||||
}
|
||||
} {aa aA Aa AA}
|
||||
do_test collate2-2.3 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE NOT c > 'aa' ORDER BY 1;
|
||||
}
|
||||
} {AA BA aA bA AB BB aB bB Aa Ba aa}
|
||||
do_test collate2-2.4 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE NOT a < 'aa' ORDER BY 1;
|
||||
}
|
||||
} {aa ab bA bB ba bb}
|
||||
do_test collate2-2.5 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE NOT b < 'aa' ORDER BY 1, oid;
|
||||
}
|
||||
} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB}
|
||||
do_test collate2-2.6 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE NOT c < 'aa' ORDER BY 1;
|
||||
}
|
||||
} {aa ba Ab Bb ab bb}
|
||||
do_test collate2-2.7 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE NOT a = 'aa';
|
||||
}
|
||||
} {ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
|
||||
do_test collate2-2.8 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE NOT b = 'aa';
|
||||
}
|
||||
} {ab ba bb aB bA bB Ab Ba Bb AB BA BB}
|
||||
do_test collate2-2.9 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE NOT c = 'aa';
|
||||
}
|
||||
} {ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
|
||||
do_test collate2-2.10 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE NOT a >= 'aa' ORDER BY 1;
|
||||
}
|
||||
} {AA AB Aa Ab BA BB Ba Bb aA aB}
|
||||
do_test collate2-2.11 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE NOT b >= 'aa' ORDER BY 1, oid;
|
||||
}
|
||||
} {}
|
||||
do_test collate2-2.12 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE NOT c >= 'aa' ORDER BY 1;
|
||||
}
|
||||
} {AA BA aA bA AB BB aB bB Aa Ba}
|
||||
do_test collate2-2.13 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE NOT a <= 'aa' ORDER BY 1;
|
||||
}
|
||||
} {ab bA bB ba bb}
|
||||
do_test collate2-2.14 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE NOT b <= 'aa' ORDER BY 1, oid;
|
||||
}
|
||||
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
|
||||
do_test collate2-2.15 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE NOT c <= 'aa' ORDER BY 1;
|
||||
}
|
||||
} {ba Ab Bb ab bb}
|
||||
do_test collate2-2.16 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE a NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1;
|
||||
}
|
||||
} {AA AB aA aB aa ab bA bB ba bb}
|
||||
do_test collate2-2.17 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE b NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1, oid;
|
||||
}
|
||||
} {}
|
||||
do_test collate2-2.18 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE c NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1;
|
||||
}
|
||||
} {AA BA aA bA AB BB aB bB ab bb}
|
||||
do_test collate2-2.19 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE NOT CASE a WHEN 'aa' THEN 1 ELSE 0 END;
|
||||
}
|
||||
} {{} ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
|
||||
do_test collate2-2.20 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE NOT CASE b WHEN 'aa' THEN 1 ELSE 0 END;
|
||||
}
|
||||
} {{} ab ba bb aB bA bB Ab Ba Bb AB BA BB}
|
||||
do_test collate2-2.21 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE NOT CASE c WHEN 'aa' THEN 1 ELSE 0 END;
|
||||
}
|
||||
} {{} ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
|
||||
do_test collate2-2.22 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1 WHERE NOT a IN ('aa', 'bb');
|
||||
}
|
||||
} {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
|
||||
do_test collate2-2.23 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1 WHERE NOT b IN ('aa', 'bb');
|
||||
}
|
||||
} {ab ba aB bA Ab Ba AB BA}
|
||||
do_test collate2-2.24 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1 WHERE NOT c IN ('aa', 'bb');
|
||||
}
|
||||
} {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
|
||||
do_test collate2-2.25 {
|
||||
execsql {
|
||||
SELECT a FROM collate2t1
|
||||
WHERE NOT a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
|
||||
}
|
||||
} {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
|
||||
do_test collate2-2.26 {
|
||||
execsql {
|
||||
SELECT b FROM collate2t1
|
||||
WHERE NOT b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
|
||||
}
|
||||
} {ab ba aB bA Ab Ba AB BA}
|
||||
do_test collate2-2.27 {
|
||||
execsql {
|
||||
SELECT c FROM collate2t1
|
||||
WHERE NOT c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
|
||||
}
|
||||
} {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
|
||||
|
||||
do_test collate2-3.1 {
|
||||
execsql {
|
||||
SELECT a > 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 0 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0}
|
||||
do_test collate2-3.2 {
|
||||
execsql {
|
||||
SELECT b > 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1}
|
||||
do_test collate2-3.3 {
|
||||
execsql {
|
||||
SELECT c > 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 0 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0}
|
||||
do_test collate2-3.4 {
|
||||
execsql {
|
||||
SELECT a < 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1}
|
||||
do_test collate2-3.5 {
|
||||
execsql {
|
||||
SELECT b < 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
|
||||
do_test collate2-3.6 {
|
||||
execsql {
|
||||
SELECT c < 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 0 0 0 0 1 1 1 1 1 0 1 0 1 1 1 1}
|
||||
do_test collate2-3.7 {
|
||||
execsql {
|
||||
SELECT a = 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
|
||||
do_test collate2-3.8 {
|
||||
execsql {
|
||||
SELECT b = 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0}
|
||||
do_test collate2-3.9 {
|
||||
execsql {
|
||||
SELECT c = 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
|
||||
do_test collate2-3.10 {
|
||||
execsql {
|
||||
SELECT a <= 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1}
|
||||
do_test collate2-3.11 {
|
||||
execsql {
|
||||
SELECT b <= 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0}
|
||||
do_test collate2-3.12 {
|
||||
execsql {
|
||||
SELECT c <= 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 0 1 1 1 1 1 0 1 0 1 1 1 1}
|
||||
do_test collate2-3.13 {
|
||||
execsql {
|
||||
SELECT a >= 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0}
|
||||
do_test collate2-3.14 {
|
||||
execsql {
|
||||
SELECT b >= 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
|
||||
do_test collate2-3.15 {
|
||||
execsql {
|
||||
SELECT c >= 'aa' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0}
|
||||
do_test collate2-3.16 {
|
||||
execsql {
|
||||
SELECT a BETWEEN 'Aa' AND 'Bb' FROM collate2t1;
|
||||
}
|
||||
} {{} 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1}
|
||||
do_test collate2-3.17 {
|
||||
execsql {
|
||||
SELECT b BETWEEN 'Aa' AND 'Bb' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
|
||||
do_test collate2-3.18 {
|
||||
execsql {
|
||||
SELECT c BETWEEN 'Aa' AND 'Bb' FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 1 0 0 0 0 0 1 1 1 1 0 0 0 0}
|
||||
do_test collate2-3.19 {
|
||||
execsql {
|
||||
SELECT CASE a WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1;
|
||||
}
|
||||
} {0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
|
||||
do_test collate2-3.20 {
|
||||
execsql {
|
||||
SELECT CASE b WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1;
|
||||
}
|
||||
} {0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0}
|
||||
do_test collate2-3.21 {
|
||||
execsql {
|
||||
SELECT CASE c WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1;
|
||||
}
|
||||
} {0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
|
||||
do_test collate2-3.22 {
|
||||
execsql {
|
||||
SELECT a IN ('aa', 'bb') FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0}
|
||||
do_test collate2-3.23 {
|
||||
execsql {
|
||||
SELECT b IN ('aa', 'bb') FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1}
|
||||
do_test collate2-3.24 {
|
||||
execsql {
|
||||
SELECT c IN ('aa', 'bb') FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0}
|
||||
do_test collate2-3.25 {
|
||||
execsql {
|
||||
SELECT a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'))
|
||||
FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0}
|
||||
do_test collate2-3.26 {
|
||||
execsql {
|
||||
SELECT b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'))
|
||||
FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1}
|
||||
do_test collate2-3.27 {
|
||||
execsql {
|
||||
SELECT c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'))
|
||||
FROM collate2t1;
|
||||
}
|
||||
} {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0}
|
||||
|
||||
do_test collate2-4.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate2t2(b COLLATE binary);
|
||||
CREATE TABLE collate2t3(b text);
|
||||
INSERT INTO collate2t2 VALUES('aa');
|
||||
INSERT INTO collate2t3 VALUES('aa');
|
||||
}
|
||||
} {}
|
||||
|
||||
# Test that when both sides of a binary comparison operator have
|
||||
# default collation types, the collate type for the leftmost term
|
||||
# is used.
|
||||
do_test collate2-4.1 {
|
||||
execsql {
|
||||
SELECT collate2t1.a FROM collate2t1, collate2t2
|
||||
WHERE collate2t1.b = collate2t2.b;
|
||||
}
|
||||
} {aa aA Aa AA}
|
||||
do_test collate2-4.2 {
|
||||
execsql {
|
||||
SELECT collate2t1.a FROM collate2t1, collate2t2
|
||||
WHERE collate2t2.b = collate2t1.b;
|
||||
}
|
||||
} {aa}
|
||||
|
||||
# Test that when one side has a default collation type and the other
|
||||
# does not, the collation type is used.
|
||||
do_test collate2-4.3 {
|
||||
execsql {
|
||||
SELECT collate2t1.a FROM collate2t1, collate2t3
|
||||
WHERE collate2t1.b = collate2t3.b||'';
|
||||
}
|
||||
} {aa aA Aa AA}
|
||||
do_test collate2-4.4 {
|
||||
execsql {
|
||||
SELECT collate2t1.a FROM collate2t1, collate2t3
|
||||
WHERE collate2t3.b||'' = collate2t1.b;
|
||||
}
|
||||
} {aa aA Aa AA}
|
||||
|
||||
do_test collate2-4.5 {
|
||||
execsql {
|
||||
DROP TABLE collate2t3;
|
||||
}
|
||||
} {}
|
||||
|
||||
#
|
||||
# Test that the default collation types are used when the JOIN syntax
|
||||
# is used in place of a WHERE clause.
|
||||
#
|
||||
# SQLite transforms the JOIN syntax into a WHERE clause internally, so
|
||||
# the focus of these tests is to ensure that the table on the left-hand-side
|
||||
# of the join determines the collation type used.
|
||||
#
|
||||
do_test collate2-5.0 {
|
||||
execsql {
|
||||
SELECT collate2t1.b FROM collate2t1 JOIN collate2t2 USING (b);
|
||||
}
|
||||
} {aa aA Aa AA}
|
||||
do_test collate2-5.1 {
|
||||
execsql {
|
||||
SELECT collate2t1.b FROM collate2t2 JOIN collate2t1 USING (b);
|
||||
}
|
||||
} {aa}
|
||||
do_test collate2-5.2 {
|
||||
execsql {
|
||||
SELECT collate2t1.b FROM collate2t1 NATURAL JOIN collate2t2;
|
||||
}
|
||||
} {aa aA Aa AA}
|
||||
do_test collate2-5.3 {
|
||||
execsql {
|
||||
SELECT collate2t1.b FROM collate2t2 NATURAL JOIN collate2t1;
|
||||
}
|
||||
} {aa}
|
||||
do_test collate2-5.4 {
|
||||
execsql {
|
||||
SELECT collate2t2.b FROM collate2t1 LEFT OUTER JOIN collate2t2 USING (b) order by collate2t1.oid;
|
||||
}
|
||||
} {{} aa {} {} {} aa {} {} {} aa {} {} {} aa {} {} {}}
|
||||
do_test collate2-5.5 {
|
||||
execsql {
|
||||
SELECT collate2t1.b, collate2t2.b FROM collate2t2 LEFT OUTER JOIN collate2t1 USING (b);
|
||||
}
|
||||
} {aa aa}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,413 +0,0 @@
|
||||
# 2001 September 15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is page cache subsystem.
|
||||
#
|
||||
# $Id: collate3.test,v 1.3 2004/06/19 00:16:31 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
#
|
||||
# Tests are organised as follows:
|
||||
#
|
||||
# collate3.1.* - Errors related to unknown collation sequences.
|
||||
# collate3.2.* - Errors related to undefined collation sequences.
|
||||
# collate3.3.* - Writing to a table that has an index with an undefined c.s.
|
||||
# collate3.4.* - Misc errors.
|
||||
# collate3.5.* - Collation factory.
|
||||
#
|
||||
|
||||
#
|
||||
# These tests ensure that when a user executes a statement with an
|
||||
# unknown collation sequence an error is returned.
|
||||
#
|
||||
do_test collate3-1.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate3t1(c1);
|
||||
}
|
||||
} {}
|
||||
do_test collate3-1.1 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1 ORDER BY 1 collate garbage;
|
||||
}
|
||||
} {1 {no such collation sequence: garbage}}
|
||||
do_test collate3-1.2 {
|
||||
catchsql {
|
||||
CREATE TABLE collate3t2(c1 collate garbage);
|
||||
}
|
||||
} {1 {no such collation sequence: garbage}}
|
||||
do_test collate3-1.3 {
|
||||
catchsql {
|
||||
CREATE INDEX collate3i1 ON collate3t1(c1 COLLATE garbage);
|
||||
}
|
||||
} {1 {no such collation sequence: garbage}}
|
||||
|
||||
execsql {
|
||||
DROP TABLE collate3t1;
|
||||
}
|
||||
|
||||
#
|
||||
# Create a table with a default collation sequence, then close
|
||||
# and re-open the database without re-registering the collation
|
||||
# sequence. Then make sure the library stops us from using
|
||||
# the collation sequence in:
|
||||
# * an explicitly collated ORDER BY
|
||||
# * an ORDER BY that uses the default collation sequence
|
||||
# * an expression (=)
|
||||
# * a CREATE TABLE statement
|
||||
# * a CREATE INDEX statement that uses a default collation sequence
|
||||
# * a GROUP BY that uses the default collation sequence
|
||||
# * a SELECT DISTINCT that uses the default collation sequence
|
||||
# * Compound SELECTs that uses the default collation sequence
|
||||
# * An ORDER BY on a compound SELECT with an explicit ORDER BY.
|
||||
#
|
||||
do_test collate3-2.0 {
|
||||
db collate string_compare {string compare}
|
||||
execsql {
|
||||
CREATE TABLE collate3t1(c1 COLLATE string_compare, c2);
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
expr 0
|
||||
} 0
|
||||
do_test collate3-2.1 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1 ORDER BY 1 COLLATE string_compare;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.2 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1 ORDER BY c1;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.3 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1 WHERE c1 = 'xxx';
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.4 {
|
||||
catchsql {
|
||||
CREATE TABLE collate3t2(c1 COLLATE string_compare);
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.5 {
|
||||
catchsql {
|
||||
CREATE INDEX collate3t1_i1 ON collate3t1(c1);
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.6 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test collate3-2.7 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1 GROUP BY c1;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.8 {
|
||||
catchsql {
|
||||
SELECT DISTINCT c1 FROM collate3t1;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
|
||||
do_test collate3-2.9 {
|
||||
catchsql {
|
||||
SELECT c1 FROM collate3t1 UNION SELECT c1 FROM collate3t1;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.10 {
|
||||
catchsql {
|
||||
SELECT c1 FROM collate3t1 EXCEPT SELECT c1 FROM collate3t1;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.11 {
|
||||
catchsql {
|
||||
SELECT c1 FROM collate3t1 INTERSECT SELECT c1 FROM collate3t1;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.12 {
|
||||
catchsql {
|
||||
SELECT c1 FROM collate3t1 UNION ALL SELECT c1 FROM collate3t1;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test collate3-2.13 {
|
||||
catchsql {
|
||||
SELECT 10 UNION ALL SELECT 20 ORDER BY 1 COLLATE string_compare;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.14 {
|
||||
catchsql {
|
||||
SELECT 10 INTERSECT SELECT 20 ORDER BY 1 COLLATE string_compare;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.15 {
|
||||
catchsql {
|
||||
SELECT 10 EXCEPT SELECT 20 ORDER BY 1 COLLATE string_compare;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.16 {
|
||||
catchsql {
|
||||
SELECT 10 UNION SELECT 20 ORDER BY 1 COLLATE string_compare;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-2.17 {
|
||||
catchsql {
|
||||
SELECT c1 FROM collate3t1 UNION ALL SELECT c1 FROM collate3t1 ORDER BY 1;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
|
||||
#
|
||||
# Create an index that uses a collation sequence then close and
|
||||
# re-open the database without re-registering the collation
|
||||
# sequence. Then check that for the table with the index
|
||||
# * An INSERT fails,
|
||||
# * An UPDATE on the column with the index fails,
|
||||
# * An UPDATE on a different column succeeds.
|
||||
# * A DELETE with a WHERE clause fails
|
||||
# * A DELETE without a WHERE clause succeeds
|
||||
#
|
||||
# Also, ensure that the restrictions tested by collate3-2.* still
|
||||
# apply after the index has been created.
|
||||
#
|
||||
do_test collate3-3.0 {
|
||||
db collate string_compare {string compare}
|
||||
execsql {
|
||||
CREATE INDEX collate3t1_i1 ON collate3t1(c1);
|
||||
INSERT INTO collate3t1 VALUES('xxx', 'yyy');
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
expr 0
|
||||
} 0
|
||||
db eval {select * from collate3t1}
|
||||
breakpoint
|
||||
do_test collate3-3.1 {
|
||||
catchsql {
|
||||
INSERT INTO collate3t1 VALUES('xxx', 0);
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-3.2 {
|
||||
catchsql {
|
||||
UPDATE collate3t1 SET c1 = 'xxx';
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-3.3 {
|
||||
catchsql {
|
||||
UPDATE collate3t1 SET c2 = 'xxx';
|
||||
}
|
||||
} {0 {}}
|
||||
do_test collate3-3.4 {
|
||||
catchsql {
|
||||
DELETE FROM collate3t1 WHERE 1;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-3.5 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1;
|
||||
}
|
||||
} {0 {xxx xxx}}
|
||||
do_test collate3-3.6 {
|
||||
catchsql {
|
||||
DELETE FROM collate3t1;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test collate3-3.8 {
|
||||
catchsql {
|
||||
PRAGMA integrity_check
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-3.9 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test collate3-3.10 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1 ORDER BY 1 COLLATE string_compare;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-3.11 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1 ORDER BY c1;
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-3.12 {
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1 WHERE c1 = 'xxx';
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-3.13 {
|
||||
catchsql {
|
||||
CREATE TABLE collate3t2(c1 COLLATE string_compare);
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-3.14 {
|
||||
catchsql {
|
||||
CREATE INDEX collate3t1_i2 ON collate3t1(c1);
|
||||
}
|
||||
} {1 {no such collation sequence: string_compare}}
|
||||
do_test collate3-3.15 {
|
||||
execsql {
|
||||
DROP TABLE collate3t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Check we can create an index that uses an explicit collation
|
||||
# sequence and then close and re-open the database.
|
||||
do_test collate3-4.6 {
|
||||
db collate user_defined "string compare"
|
||||
execsql {
|
||||
CREATE TABLE collate3t1(a, b);
|
||||
INSERT INTO collate3t1 VALUES('hello', NULL);
|
||||
CREATE INDEX collate3i1 ON collate3t1(a COLLATE user_defined);
|
||||
}
|
||||
} {}
|
||||
do_test collate3-4.7 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1 ORDER BY a COLLATE user_defined;
|
||||
}
|
||||
} {1 {no such collation sequence: user_defined}}
|
||||
do_test collate3-4.8 {
|
||||
db collate user_defined "string compare"
|
||||
catchsql {
|
||||
SELECT * FROM collate3t1 ORDER BY a COLLATE user_defined;
|
||||
}
|
||||
} {0 {hello {}}}
|
||||
do_test collate3-4.8 {
|
||||
db close
|
||||
lindex [catch {
|
||||
sqlite3 db test.db
|
||||
}] 0
|
||||
} {0}
|
||||
do_test collate3-4.8 {
|
||||
execsql {
|
||||
DROP TABLE collate3t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Compare strings as numbers.
|
||||
proc numeric_compare {lhs rhs} {
|
||||
if {$rhs > $lhs} {
|
||||
set res -1
|
||||
} else {
|
||||
set res [expr ($lhs > $rhs)?1:0]
|
||||
}
|
||||
return $res
|
||||
}
|
||||
|
||||
# Check we can create a view that uses an explicit collation
|
||||
# sequence and then close and re-open the database.
|
||||
do_test collate3-4.9 {
|
||||
db collate user_defined numeric_compare
|
||||
execsql {
|
||||
CREATE TABLE collate3t1(a, b);
|
||||
INSERT INTO collate3t1 VALUES('2', NULL);
|
||||
INSERT INTO collate3t1 VALUES('101', NULL);
|
||||
INSERT INTO collate3t1 VALUES('12', NULL);
|
||||
CREATE VIEW collate3v1 AS SELECT * FROM collate3t1
|
||||
ORDER BY 1 COLLATE user_defined;
|
||||
SELECT * FROM collate3v1;
|
||||
}
|
||||
} {2 {} 12 {} 101 {}}
|
||||
do_test collate3-4.10 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
catchsql {
|
||||
SELECT * FROM collate3v1;
|
||||
}
|
||||
} {1 {no such collation sequence: user_defined}}
|
||||
do_test collate3-4.11 {
|
||||
db collate user_defined numeric_compare
|
||||
catchsql {
|
||||
SELECT * FROM collate3v1;
|
||||
}
|
||||
} {0 {2 {} 12 {} 101 {}}}
|
||||
do_test collate3-4.12 {
|
||||
execsql {
|
||||
DROP TABLE collate3t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
#
|
||||
# Test the collation factory. In the code, the "no such collation sequence"
|
||||
# message is only generated in two places. So these tests just test that
|
||||
# the collation factory can be called once from each of those points.
|
||||
#
|
||||
do_test collate3-5.0 {
|
||||
catchsql {
|
||||
CREATE TABLE collate3t1(a);
|
||||
INSERT INTO collate3t1 VALUES(10);
|
||||
SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk;
|
||||
}
|
||||
} {1 {no such collation sequence: unk}}
|
||||
do_test collate3-5.1 {
|
||||
set ::cfact_cnt 0
|
||||
proc cfact {nm} {
|
||||
db collate $nm {string compare}
|
||||
incr ::cfact_cnt
|
||||
}
|
||||
db collation_needed cfact
|
||||
} {}
|
||||
do_test collate3-5.2 {
|
||||
catchsql {
|
||||
SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk;
|
||||
}
|
||||
} {0 10}
|
||||
do_test collate3-5.3 {
|
||||
set ::cfact_cnt
|
||||
} {1}
|
||||
do_test collate3-5.4 {
|
||||
catchsql {
|
||||
SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk;
|
||||
}
|
||||
} {0 10}
|
||||
do_test collate3-5.5 {
|
||||
set ::cfact_cnt
|
||||
} {1}
|
||||
do_test collate3-5.6 {
|
||||
catchsql {
|
||||
SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk;
|
||||
}
|
||||
} {0 10}
|
||||
do_test collate3-5.7 {
|
||||
execsql {
|
||||
DROP TABLE collate3t1;
|
||||
CREATE TABLE collate3t1(a COLLATE unk);
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
catchsql {
|
||||
SELECT a FROM collate3t1 ORDER BY 1;
|
||||
}
|
||||
} {1 {no such collation sequence: unk}}
|
||||
do_test collate3-5.8 {
|
||||
set ::cfact_cnt 0
|
||||
proc cfact {nm} {
|
||||
db collate $nm {string compare}
|
||||
incr ::cfact_cnt
|
||||
}
|
||||
db collation_needed cfact
|
||||
catchsql {
|
||||
SELECT a FROM collate3t1 ORDER BY 1;
|
||||
}
|
||||
} {0 {}}
|
||||
|
||||
do_test collate3-5.9 {
|
||||
execsql {
|
||||
DROP TABLE collate3t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
finish_test
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user