Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f3a5a57ddb | |||
| 1832890357 | |||
| 97117601d2 | |||
| f9ec81c84d | |||
| 45041e263a | |||
| 3e5c826219 | |||
| 4e0e4d7a9e | |||
| 064cf76bb1 | |||
| a38518d673 |
+164
-243
@@ -84,13 +84,17 @@ endif
|
||||
|
||||
# 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.
|
||||
#
|
||||
@@ -99,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 \
|
||||
@@ -108,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 \
|
||||
@@ -127,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.
|
||||
@@ -144,33 +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/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/test5.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
|
||||
@@ -182,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
|
||||
@@ -194,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
|
||||
@@ -226,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
|
||||
@@ -257,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
|
||||
|
||||
@@ -278,116 +321,49 @@ 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) -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) -c $(TOP)/src/os_mac.c
|
||||
|
||||
os_unix.lo: $(TOP)/src/os_unix.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/os_unix.c
|
||||
|
||||
os_win.lo: $(TOP)/src/os_win.c $(HDR)
|
||||
$(LTCOMPILE) -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
|
||||
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`/ \
|
||||
-e s/--ENCODING--/$(ENCODING)/ \
|
||||
$(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\
|
||||
-o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libtclsqlite3.la libsqlite3.la $(LIBTCL)
|
||||
libtclsqlite.la libsqlite.la $(LIBTCL)
|
||||
|
||||
fulltest: testfixture@TARGET_EXEEXT@ sqlite@TARGET_EXEEXT@
|
||||
./testfixture $(TOP)/test/all.test
|
||||
@@ -395,166 +371,111 @@ fulltest: testfixture@TARGET_EXEEXT@ sqlite@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
|
||||
|
||||
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
|
||||
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: $(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 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)
|
||||
|
||||
+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.
@@ -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,13 +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 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.
|
||||
#
|
||||
@@ -69,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 \
|
||||
@@ -78,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 \
|
||||
@@ -97,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
|
||||
|
||||
@@ -114,31 +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/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/test5.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
|
||||
@@ -152,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
|
||||
@@ -161,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
|
||||
@@ -190,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
|
||||
@@ -220,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
|
||||
|
||||
@@ -241,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
|
||||
@@ -290,228 +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)
|
||||
|
||||
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)
|
||||
|
||||
fulltest: testfixture$(EXE) sqlite3$(EXE)
|
||||
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
|
||||
|
||||
# Rules used to build documentation
|
||||
#
|
||||
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
|
||||
|
||||
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
|
||||
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,183 +1,158 @@
|
||||
C Version\s3.0.0\s(ALPHA)\s(CVS\s1619)
|
||||
D 2004-06-18T12:29:23
|
||||
F Makefile.in 5125bd6b92fca76275a6fc6c6ff425484b8cec0a
|
||||
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 8c6981d7f982c3e2986fda2f34282264a4db344c
|
||||
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 6a156e79aaddba2e0e6816972d99989f48cc1699 x
|
||||
F configure.ac 684143ce9ee7bafc4291d0e17f2dfdc70514d1d6
|
||||
F doc/affinity.html bdc7560fa3d2284af59d8fb52041cddbb14578f5
|
||||
F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
|
||||
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
|
||||
F main.mk 6004a81e05581a6b51e4f37a62ed45db089c47cf
|
||||
F mkdll.sh 68d34a961a1fdfa15ef27fc4f4740be583112124
|
||||
F publish.sh e772c09c4fb72f2323a1fb522259640e52040b15
|
||||
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 src/attach.c 93b8ecec4a8d7b4e9f2479e2327d90c9d01765e8
|
||||
F src/auth.c 204e1e9c45e64315589bc8b62cba5d9de29b6a3c
|
||||
F src/btree.c 0cf8a52a57a7eb13d50719114ee1fa353e89d7d3
|
||||
F src/btree.h 32f96abef464cf8765b23ca669acfe90d191fcc5
|
||||
F src/build.c 44057a0aba7c57fb7a32ee4addd2e981fcb9de60
|
||||
F src/date.c 65b483caeb0e4dd663667d2f927caa058168ebff
|
||||
F src/delete.c a5191011b7429dff939df631b8bdcc1714b8d7aa
|
||||
F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37
|
||||
F src/expr.c 01cdf6a632ff66acfff667932c41bb79d18d5077
|
||||
F src/func.c 1959a0c2f5328b2b9934620f9492964f080f4a71
|
||||
F src/hash.c 440c2f8cb373ee1b4e13a0988489c7cd95d55b6f
|
||||
F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb
|
||||
F src/insert.c 1428887f4a7515a7d34e82aaeb76297c79ba378b
|
||||
F src/legacy.c ad23746f15f67e34577621b1875f639c94839e1f
|
||||
F src/main.c a7cee3b75b74aec795e26175cd3070fe0909b297
|
||||
F src/md5.c d77a389955759c8329bb357e3d71bac3d6eb710b
|
||||
F src/os.h 1cb5f0293a30288451fe3c0c73815cf208212ed1
|
||||
F src/os_common.h ba1b7306e16e2091718f2c48db0fe6c1d7a31bb8
|
||||
F src/os_mac.c 3d31e26be1411acfb7961033098631b4f3486fdf
|
||||
F src/os_mac.h 51d2445f47e182ed32d3bd6937f81070c6fd9bd4
|
||||
F src/os_unix.c add5af1cc4ff726297338e4e96ac36d1a5658d2c
|
||||
F src/os_unix.h 1cd6133cf66dea704b8646b70b2dfdcbdd9b3738
|
||||
F src/os_win.c 337e973ee77797aaab4787e3477a5945fcd97266
|
||||
F src/os_win.h 004eec47b1780fcaf07420ddc2072294b698d48c
|
||||
F src/pager.c 453099416c10669365ca70f12f13e67e6ef11000
|
||||
F src/pager.h bc58d32a9dee464f7268fb68652c130a4216e438
|
||||
F src/parse.y 097438674976355a10cf177bd97326c548820b86
|
||||
F src/pragma.c 83b86b2942d7f1b202644ac4e2559965e23a8a7b
|
||||
F src/printf.c 7e7f83a747bbd0601dcb4ee2885fb3ce3e994a9f
|
||||
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
|
||||
F src/select.c 91570af7f13d1c5584f3b711676e1226ee12194e
|
||||
F src/shell.c ca519519dcbbc582f6d88f7d0e7583b857fd3469
|
||||
F src/sqlite.h.in eacd23af3280603cd8b48979c6f9297b3ac2935c
|
||||
F src/sqliteInt.h 7d8145b6828826683f44b8c40930c34c8ec1f3c3
|
||||
F src/table.c af14284fa36c8d41f6829e3f2819dce07d3e2de2
|
||||
F src/tclsqlite.c 6f88be282a3617c6739c043fd13571b5f2fe9922
|
||||
F src/test1.c 963f4417d1770f5238672ff5b817a9103842eeb7
|
||||
F src/test2.c db0a0c30b59f1639cb8c2572be06439402833cc8
|
||||
F src/test3.c 7247090d15a5a43823079b6fd8dad1ed3cccdedf
|
||||
F src/test4.c a921a69821fd30209589228e64f94e9f715b6fe2
|
||||
F src/test5.c 1b7c275b2929dbd034a567255d2aca339410d1d6
|
||||
F src/tokenize.c 900374b6b37f04748bcd48c2d29a41c251542935
|
||||
F src/trigger.c 3325207ea41d2d429e70370ce2ff987fd49b7ada
|
||||
F src/update.c f9a03233577e0c3d57234d1957963875fc941da2
|
||||
F src/utf.c 7464315fd4b627b96801444f3671f3e9930879c6
|
||||
F src/util.c 9d9ef854e9a8744a7ebaee02ee26eb0aaa8a9987
|
||||
F src/vacuum.c f9561c8095407a970af4e6a304b77c4083433d3e
|
||||
F src/vdbe.c 2a0e908e46ea6822f215cb0f35ec31f5c2832629
|
||||
F src/vdbe.h 46f74444a213129bc4b5ce40124dd8ed613b0cde
|
||||
F src/vdbeInt.h 54af2e00301cde7573b86ea8a9b29a2152e762f7
|
||||
F src/vdbeapi.c 1601fb2d015fc88ce3dd6a6a50cf44b6419fdbbf
|
||||
F src/vdbeaux.c dc0e7d3bdf3b6f322448b4bee29fe5bec656b4d4
|
||||
F src/vdbemem.c 9359c53386e070fea9f5403cab0c6f0cfe36496b
|
||||
F src/where.c 6507074d8ce3f78e7a4cd33f667f11e62020553e
|
||||
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 aed659e52635662bcd5069599aaca823533edf5a
|
||||
F test/attach2.test 579d6cb94cb944e0d87a2bf8d6696e2036847e6a
|
||||
F test/attach3.test 8259ab833b5dcdf4acd75d9653f42f703ce2e013
|
||||
F test/auth.test 4077c84a150579eefb38e47e2b66f010d221d76a
|
||||
F test/bigfile.test 5b079dfe7354a6c43b92a3ea5e49e4e5d88c789e
|
||||
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 4f5a19e84077b61ea797644b4942bb98b17bdd42
|
||||
F test/blob.test b6474275536614352d6e1c729f23a18ba1082ae9
|
||||
F test/btree.test 77209dd37bb12ae501a0588b4c69bd7079ebdf1a
|
||||
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 b161d9d80899192d3e5e809cf3db98248b5bdc04
|
||||
F test/capi3.test b6fe8a66d2ffe28d4faaaec154a143131e8ff631
|
||||
F test/collate1.test 2ee4fa3a47a652ccf56c5ddf65dcc44d9bad82ef
|
||||
F test/collate2.test c1a3b41f761b28853c5696037f92de928f93233b
|
||||
F test/collate3.test 47cf6b393cadbad845f34ddfc04692bb3930986a
|
||||
F test/collate4.test 0e9fc08ffcf6eddf72e354a15de06688fa86db31
|
||||
F test/collate5.test 1dd5f0f508c46667f9d4606c7950c414b0bdc0d5
|
||||
F test/collate6.test 2a45768914f04c1447a69d1358bbede376552675
|
||||
F test/conflict.test 45ce1e44ea748944aed233df8c278a9e1c4c87cc
|
||||
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 aed5030482ebc02bd8d386c6c86a29f694ab068d
|
||||
F test/delete.test ac14bd6df5f1581d646eebc013d6b844a885dcf6
|
||||
F test/enc.test dfdde0f660b592acbdafd107d15b2b7dd2a54f45
|
||||
F test/enc2.test ffd3dbef6949c33f85b7152e465c88e29cbfbd81
|
||||
F test/expr.test 2262ade5e4e98e359b11e40b01cb3498ac7fa42b
|
||||
F test/delete.test 92256384f1801760180ded129f7427884cf28886
|
||||
F test/expr.test ad985242e140f87eeef329d98257b8369a2066dc
|
||||
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
|
||||
F test/func.test 5fb6008f8805f8ff1f41cf269cf675aff8923c04
|
||||
F test/hook.test c4102c672d67f8fb60ea459842805abcba69a747
|
||||
F test/in.test b92a2df9162e1cbd33c6449a29a05e6955b1741a
|
||||
F test/index.test 4bd370c6edff316916a3a9d934ef0c2cabad65b1
|
||||
F test/insert.test 6ec324659656f4a86e4abfcf1a1fd2795ba6b603
|
||||
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 9142ce4448605127640eda5e283952f75f67ed91
|
||||
F test/intpkey.test e6e0d7cca0e64ec09cbf683a4712ed2196073742
|
||||
F test/ioerr.test ab1319619f4d90a0f5c0f9835dff48ac30e9c3dc
|
||||
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/lastinsert.test 31382f88b9b0270333ac9e4a17f2c2f4732da718
|
||||
F test/laststmtchanges.test cabd11bdfbaf73a4486c50b58297d9c2038ccc18
|
||||
F test/limit.test 60d7f856ee7846f7130dee67f10f0e726cd70b5d
|
||||
F test/lock.test 3dca2c865d83fd1ab5730e8ad2fa69f81e0079e0
|
||||
F test/limit.test e28ce938ddacefdff860d082be45e1e5e2801441
|
||||
F test/lock.test 226ef831dad60ad4d200dc83e25479ba952aac7e
|
||||
F test/main.test 6a851b5992c4881a725a3d9647e629199df8de9d
|
||||
F test/malloc.test 4e19b96d9cd7d61f4826e6fce03849ad5ad526dd
|
||||
F test/memdb.test ec2abdcf03c3497236d499b289c4b7eacde8c336
|
||||
F test/malloc.test 2cfcffb7c858640e01e6520ee1cd54ca57d98e80
|
||||
F test/memdb.test 6ece25c7c0e6500199d3662607a3edca081abb2a
|
||||
F test/memleak.test 4d5d374c8ea1fc5ac634aed58cac1047848ce65e
|
||||
F test/minmax.test 9dcf52f713b1b9e61d0a88a51eb8bb2e3c52d0ab
|
||||
F test/misc1.test 8472d2133c33efa29d514b464c4129f638b9cd31
|
||||
F test/misc1.test 0b98d493b0cf55cb5f53e1f3df8107c166eecb5a
|
||||
F test/misc2.test 10c2ce26407d37411b96273e552d5095393732be
|
||||
F test/misc3.test eb488314990bfc0959221a1acc465013238bf168
|
||||
F test/misc3.test 3b5e369514a3ba3f919fb7eafa7d027440b5079e
|
||||
F test/misuse.test 1095f26d1aed406c65e1d2eba651c4bb7c38cbff
|
||||
F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
|
||||
F test/null.test c14d0f4739f21e929b8115b72bf0c765b6bb1721
|
||||
F test/pager.test b17ce7d4e89ab3618f6903f0ec318a13f855a849
|
||||
F test/pager2.test 55469c7c1c1a54d6b32d7b3cc99001e90101a1ce
|
||||
F test/pragma.test 1b6792d4af550ca4973096d77fc278dd6c32c4dd
|
||||
F test/printf.test 31ac25b4f85fbc7fb507be34c6c0731adbefcf80
|
||||
F test/progress.test 7542a6ac7894a1b7730c1f9a27f3f8b9388a4d25 x
|
||||
F test/quick.test 32f64124a83c2a3b1de1444e253bc95e51e14048
|
||||
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 863e6e75878cccf03d166fe52023f20e09508683
|
||||
F test/select1.test 2f161f9cdf9fb577336bc8c930edade538567123
|
||||
F test/select2.test 91a2225926039b0d1687840735c284dbbf89f0bc
|
||||
F test/select3.test ab2e583154ee230fa4b46b06512775a38cd9d8b0
|
||||
F test/select4.test 86e72fc3b07de4fe11439aa419e37db3c49467e2
|
||||
F test/select5.test 3f3f0f31e674fa61f8a3bdb6af1517dfae674081
|
||||
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 dbd94673b05054e44ca3f08a80faa1e890ef06d8
|
||||
F test/sort.test ba07b107c16070208e6aab3cadea66ba079d85ba
|
||||
F test/subselect.test f0fea8cf9f386d416d64d152e3c65f9116d0f50f
|
||||
F test/table.test bbae9f267e947963f8951e72516667ab16c5810c
|
||||
F test/tableapi.test 8651d6d1b043217aa851632b515ab68f185fb430
|
||||
F test/tclsqlite.test 2ff5abfd1e133cddcfc61ad5850e3b93f4a7ff40
|
||||
F test/temptable.test 3109726251fb4961010eb4d47e5c4df2af6b958d
|
||||
F test/tester.tcl a3f5b6de9fa92b13aad2d3cac972b77638ce6e26
|
||||
F test/thread1.test fba29da98397c7f657008cf164b9212c1ad33f37
|
||||
F test/threadtest1.c f5c7d628d5b23a1418816351b3cd8fe06e146250
|
||||
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 4a26c6fa3639202c334521954c17d8abe8a1c8e8
|
||||
F test/trigger1.test 99b7cd9a568ac60aa04bbc3b9db9575ffa97709a
|
||||
F test/trans.test 0cb8256daff1ae0da75321e00125338c6681158d
|
||||
F test/trigger1.test 4538c1c7d6bbca5dfe619ea6e1682b07ece95b21
|
||||
F test/trigger2.test 0767ab30cb5a2c8402c8524f3d566b410b6f5263
|
||||
F test/trigger3.test 70931be83fa3f563f7a5ca9e88b86f476af73948
|
||||
F test/trigger3.test a95ccace88291449f5eae7139ec438a42f90654d
|
||||
F test/trigger4.test 542afce45774e8f8e1130b96b8675f414d6e4bd8
|
||||
F test/types.test 6c49e574970866558365a025b44c9fd8a162ef0d
|
||||
F test/types2.test 5d725fcb68dbd032c6d4950d568d75fa33872687
|
||||
F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b
|
||||
F test/update.test b29bd9061a1150426dab6959806fcc73a41b1217
|
||||
F test/vacuum.test c11b73769bf1d6d607acf0227c3ce925dd20e41d
|
||||
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
|
||||
F test/vacuum.test a2a44544df719666efb51afbfeb6062fd59a672a
|
||||
F test/version.test 92adee5d98cf6e3eb0d1cf5186952e8114931bf6
|
||||
F test/view.test 1ee12c6f8f4791a2c0655120d5562a49400cfe53
|
||||
F test/where.test 9c5752b807b78078fab8da6f52e689832579ca20
|
||||
F test/where.test cb3a2ed062ce4b5f08aff2d08027c6a46d68c47b
|
||||
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
|
||||
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
|
||||
@@ -188,44 +163,32 @@ F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
|
||||
F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4
|
||||
F www/arch.tcl 3f4f9173a3b7dc05b0ea67ae0c942866558ad35d
|
||||
F www/arch.tcl b329ca2c8dc75cd1cf0dd714b8bb47bdd458d0da
|
||||
F www/arch2.fig 613b5ac63511109064c2f93c5754ee662219937d
|
||||
F www/arch2.gif 49c6bb36160f03ca2b89eaa5bfb1f560c7d68ee7
|
||||
F www/audit.tcl 90e09d580f79c7efec0c7d6f447b7ec5c2dce5c0
|
||||
F www/c_interface.tcl 2176519fc2bd2d2cf6fe74fd806fc2d8362de2c8
|
||||
F www/capi3.tcl af6938cc417fe323d7570b95d2e9a019bbff637e
|
||||
F www/capi3ref.tcl 68a03fa5c15f01d04fbb073f8153078f1ba6f672
|
||||
F www/changes.tcl 4d75f4c2a8bba2bb26b0fd4f3a48999e06b4025f
|
||||
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 dadcd0b09dc6fdf86d0c38499e310ae94cb586d7
|
||||
F www/datatypes.tcl 566004b81c36877397ddbe6e1907aae6065f6b41
|
||||
F www/docs.tcl 095b5718ec044156af477061566ea25632624b56
|
||||
F www/download.tcl 3868640b7a898df260ca3bb94c37e956fe0183d4
|
||||
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 9783a8370bf16dfc20e81f1cf14489f95408353e
|
||||
F www/lang.tcl 5193e27d5ab92ffa98427ef0fcc55d7a7c0e3ac3
|
||||
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 f31330db8c978e675f5cd263067b32b822effa6f
|
||||
F www/oldnews.tcl 3cfc9685d9d25eb26a69c2ce979432b26d5ae75e
|
||||
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 1801397edd271cc39a2aadd54e701184b5181248
|
||||
F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075
|
||||
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
|
||||
F www/version3.tcl f9a4c1a12864e129f6717d22313be01d5657e3aa
|
||||
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 9e0e530f10bf70996471650496173dee074c2732
|
||||
R e652117e65d118a6c36b9df849e95e4a
|
||||
P 7538d2e5297bdeaf07c6d6e37053c654501ef286
|
||||
R 4b97b7f3ad71d7fa0ea85a53f9d1556a
|
||||
U drh
|
||||
Z a6276db799a30487f4c5e98319787ced
|
||||
Z 6e7d236761f1e0f27c9fd9bb6ff1ebec
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
8b409aaae42cc36d96536531da41f05bd0cdd29c
|
||||
7d3937743f88acad8859fbbbb1c03271a939bc0b
|
||||
@@ -1,104 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to compile SQLite and all its documentation and
|
||||
# ship everything up to the SQLite website. This script will only work
|
||||
# on the system "zadok" at the Hwaci offices. But others might find
|
||||
# the script useful as an example.
|
||||
#
|
||||
|
||||
# Build the tclsqlite.dll shared library that can be imported into tclsh
|
||||
# or wish on windows.
|
||||
#
|
||||
make target_source
|
||||
cd tsrc
|
||||
PATH=$PATH:/opt/mingw/bin
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1 -DTHREADSAFE=1'
|
||||
CC="i386-mingw32msvc-gcc -O2 $OPTS -I."
|
||||
rm shell.c
|
||||
rm tclsqlite.c
|
||||
for i in *.c; do
|
||||
CMD="$CC -c $i"
|
||||
echo $CMD
|
||||
$CMD
|
||||
done
|
||||
cat >sqlite3.def <<\END_OF_FILE
|
||||
EXPORTS
|
||||
sqlite3_aggregate_context
|
||||
sqlite3_aggregate_count
|
||||
sqlite3_bind_blob
|
||||
sqlite3_bind_double
|
||||
sqlite3_bind_int
|
||||
sqlite3_bind_int64
|
||||
sqlite3_bind_null
|
||||
sqlite3_bind_text
|
||||
sqlite3_bind_text16
|
||||
sqlite3_busy_handler
|
||||
sqlite3_busy_timeout
|
||||
sqlite3_close
|
||||
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_complete
|
||||
sqlite3_complete16
|
||||
sqlite3_create_function
|
||||
sqlite3_create_function16
|
||||
sqlite3_errcode
|
||||
sqlite3_errmsg
|
||||
sqlite3_errmsg16
|
||||
sqlite3_finalize
|
||||
sqlite3_free
|
||||
sqlite3_interrupt
|
||||
sqlite3_last_insert_rowid
|
||||
sqlite3_mprintf
|
||||
sqlite3_open
|
||||
sqlite3_open16
|
||||
sqlite3_prepare
|
||||
sqlite3_prepare16
|
||||
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_value
|
||||
sqlite3_set_authorizer
|
||||
sqlite3_step
|
||||
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_type
|
||||
sqlite3_vmprintf
|
||||
END_OF_FILE
|
||||
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
|
||||
mv sqlite3.dll sqlite3.def ..
|
||||
cd ..
|
||||
rm -f sqlite3dll.zip
|
||||
zip sqlite3dll.zip sqlite3.dll sqlite3.def
|
||||
+76
-92
@@ -16,19 +16,14 @@ 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 the tclsqlite.so shared library for import into tclsh or wish
|
||||
# under Linux
|
||||
@@ -43,16 +38,15 @@ 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 tclsqlite-$VERS.so
|
||||
gzip tclsqlite-$VERS.so
|
||||
mv tclsqlite-$VERS.so.gz ../doc
|
||||
mv tclsqlite.so ..
|
||||
rm tclsqlite.c
|
||||
gcc -fPIC -DNDEBUG=1 -O2 -I. -shared *.c -o sqlite.so
|
||||
strip sqlite.so
|
||||
mv sqlite.so sqlite-$VERS.so
|
||||
gzip sqlite-$VERS.so
|
||||
mv sqlite-$VERS.so.gz ../doc
|
||||
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.
|
||||
@@ -86,72 +80,50 @@ mv tclsqlite.dll ..
|
||||
rm tclsqlite.o
|
||||
cat >sqlite.def <<\END_OF_FILE
|
||||
EXPORTS
|
||||
sqlite3_aggregate_context
|
||||
sqlite3_aggregate_count
|
||||
sqlite3_bind_blob
|
||||
sqlite3_bind_double
|
||||
sqlite3_bind_int
|
||||
sqlite3_bind_int64
|
||||
sqlite3_bind_null
|
||||
sqlite3_bind_text
|
||||
sqlite3_bind_text16
|
||||
sqlite3_busy_handler
|
||||
sqlite3_busy_timeout
|
||||
sqlite3_close
|
||||
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_complete
|
||||
sqlite3_complete16
|
||||
sqlite3_create_function
|
||||
sqlite3_create_function16
|
||||
sqlite3_errcode
|
||||
sqlite3_errmsg
|
||||
sqlite3_errmsg16
|
||||
sqlite3_finalize
|
||||
sqlite3_free
|
||||
sqlite3_interrupt
|
||||
sqlite3_last_insert_rowid
|
||||
sqlite3_mprintf
|
||||
sqlite3_open
|
||||
sqlite3_open16
|
||||
sqlite3_prepare
|
||||
sqlite3_prepare16
|
||||
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_value
|
||||
sqlite3_set_authorizer
|
||||
sqlite3_step
|
||||
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_type
|
||||
sqlite3_vmprintf
|
||||
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 \
|
||||
@@ -161,9 +133,11 @@ i386-mingw32msvc-dllwrap \
|
||||
--target i386-mingw32 \
|
||||
-dllname sqlite.dll -lmsvcrt *.o
|
||||
i386-mingw32msvc-strip sqlite.dll
|
||||
zip ../doc/tclsqlite-$VERSW.zip tclsqlite.dll
|
||||
zip ../doc/sqlitedll-$VERSW.zip sqlite.dll sqlite.def
|
||||
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.
|
||||
#
|
||||
@@ -172,8 +146,10 @@ cd tsrc
|
||||
rm tclsqlite.c
|
||||
OPTS='-DSTATIC_BUILD=1 -DNDEBUG=1'
|
||||
i386-mingw32msvc-gcc -O2 $OPTS -I. -I$TCLDIR *.c -o sqlite.exe
|
||||
zip ../doc/sqlite-$VERSW.zip sqlite.exe
|
||||
mv sqlite.exe ..
|
||||
cd ..
|
||||
rm -f sqlite.zip
|
||||
zip sqlite.zip sqlite.exe
|
||||
|
||||
# Construct a tarball of the source tree
|
||||
#
|
||||
@@ -181,8 +157,11 @@ ORIGIN=`pwd`
|
||||
cd $srcdir
|
||||
cd ..
|
||||
EXCLUDE=`find sqlite -print | grep CVS | sed 's,sqlite/, --exclude sqlite/,'`
|
||||
tar czf $ORIGIN/doc/sqlite-$VERS.tar.gz $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
|
||||
@@ -200,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
|
||||
|
||||
+68
-62
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.14 2004/06/09 12:30:05 danielk1977 Exp $
|
||||
** $Id: attach.c,v 1.10.2.1 2004/05/07 01:46:01 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -23,42 +23,48 @@
|
||||
** The pFilename and pDbname arguments are the tokens that define the
|
||||
** filename and dbname in the ATTACH statement.
|
||||
*/
|
||||
void sqlite3Attach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey){
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
zFile = 0;
|
||||
sqlite3SetNString(&zFile, pFilename->z, pFilename->n, 0);
|
||||
sqliteSetNString(&zFile, pFilename->z, pFilename->n, 0);
|
||||
if( zFile==0 ) return;
|
||||
sqlite3Dequote(zFile);
|
||||
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 = 0;
|
||||
sqlite3SetNString(&zName, pDbname->z, pDbname->n, 0);
|
||||
sqliteSetNString(&zName, pDbname->z, pDbname->n, 0);
|
||||
if( zName==0 ) return;
|
||||
sqlite3Dequote(zName);
|
||||
sqliteDequote(zName);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( db->aDb[i].zName && sqlite3StrICmp(db->aDb[i].zName, 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;
|
||||
@@ -76,14 +82,14 @@ void sqlite3Attach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey)
|
||||
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;
|
||||
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
|
||||
{
|
||||
@@ -91,8 +97,8 @@ void sqlite3Attach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey)
|
||||
char *zKey = 0;
|
||||
int nKey;
|
||||
if( pKey && pKey->z && pKey->n ){
|
||||
sqlite3SetNString(&zKey, pKey->z, pKey->n, 0);
|
||||
sqlite3Dequote(zKey);
|
||||
sqliteSetNString(&zKey, pKey->z, pKey->n, 0);
|
||||
sqliteDequote(zKey);
|
||||
nKey = strlen(zKey);
|
||||
}else{
|
||||
zKey = 0;
|
||||
@@ -105,16 +111,16 @@ void sqlite3Attach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey)
|
||||
db->flags &= ~SQLITE_Initialized;
|
||||
if( pParse->nErr ) return;
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3ReadSchema(pParse->db, &pParse->zErrMsg);
|
||||
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);
|
||||
sqliteResetInternalSchema(db, 0);
|
||||
pParse->nErr++;
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
@@ -127,42 +133,45 @@ void sqlite3Attach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey)
|
||||
**
|
||||
** 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;
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
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++){
|
||||
if( db->aDb[i].pBt==0 || db->aDb[i].zName==0 ) continue;
|
||||
if( strlen(db->aDb[i].zName)!=pDbname->n ) continue;
|
||||
if( sqlite3StrNICmp(db->aDb[i].zName, pDbname->z, pDbname->n)==0 ) break;
|
||||
pDb = &db->aDb[i];
|
||||
if( pDb->pBt==0 || pDb->zName==0 ) continue;
|
||||
if( strlen(pDb->zName)!=pDbname->n ) continue;
|
||||
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);
|
||||
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(db->aDb[i].pBt);
|
||||
db->aDb[i].pBt = 0;
|
||||
sqliteFree(db->aDb[i].zName);
|
||||
sqlite3ResetInternalSchema(db, i);
|
||||
sqliteBtreeClose(pDb->pBt);
|
||||
pDb->pBt = 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]));
|
||||
sqlite3ResetInternalSchema(db, i);
|
||||
sqliteResetInternalSchema(db, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,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 */
|
||||
@@ -196,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.
|
||||
@@ -206,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 */
|
||||
){
|
||||
@@ -218,88 +227,85 @@ 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;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+13
-21
@@ -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.15 2004/06/14 11:35:18 danielk1977 Exp $
|
||||
** $Id: auth.c,v 1.12 2004/02/22 18:40:57 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -62,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.
|
||||
@@ -70,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
|
||||
@@ -85,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;
|
||||
@@ -100,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 */
|
||||
@@ -147,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 ){
|
||||
@@ -164,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,
|
||||
@@ -174,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;
|
||||
@@ -198,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
|
||||
@@ -212,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;
|
||||
@@ -222,6 +217,3 @@ void sqlite3AuthContextPop(AuthContext *pContext){
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
|
||||
|
||||
|
||||
+1890
-2623
File diff suppressed because it is too large
Load Diff
+118
-84
@@ -13,110 +13,144 @@
|
||||
** subsystem. See comments in the source code for a detailed description
|
||||
** of what each interface routine does.
|
||||
**
|
||||
** @(#) $Id: btree.h,v 1.54 2004/06/14 06:03:57 danielk1977 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,
|
||||
Btree **,
|
||||
int nCache,
|
||||
int flags,
|
||||
void *pBusyHandler
|
||||
);
|
||||
|
||||
/* 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 sqlite3BtreeSetCacheSize(Btree*,int);
|
||||
int sqlite3BtreeSetSafetyLevel(Btree*,int);
|
||||
int sqlite3BtreeBeginTrans(Btree*,int,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*);
|
||||
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
+600
-1082
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;
|
||||
}
|
||||
+37
-55
@@ -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.29 2004/06/12 09:25:14 danielk1977 Exp $
|
||||
** $Id: date.c,v 1.16 2004/02/29 01:08:18 drh Exp $
|
||||
**
|
||||
** NOTES:
|
||||
**
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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] ){
|
||||
@@ -854,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);
|
||||
}
|
||||
@@ -868,24 +846,28 @@ static void strftimeFunc(
|
||||
** functions. This should be the only routine in this file with
|
||||
** external linkage.
|
||||
*/
|
||||
void sqlite3RegisterDateTimeFunctions(sqlite *db){
|
||||
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[] = {
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
{ "julianday", -1, juliandayFunc },
|
||||
{ "date", -1, dateFunc },
|
||||
{ "time", -1, timeFunc },
|
||||
{ "datetime", -1, datetimeFunc },
|
||||
{ "strftime", -1, strftimeFunc },
|
||||
{ "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, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+89
-114
@@ -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.75 2004/06/17 07:53:02 danielk1977 Exp $
|
||||
** $Id: delete.c,v 1.61 2004/02/24 01:05:32 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
** 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;
|
||||
for(i=0; i<pSrc->nSrc; i++){
|
||||
const char *zTab = pSrc->a[i].zName;
|
||||
const char *zDb = pSrc->a[i].zDatabase;
|
||||
pTab = sqlite3LocateTable(pParse, zTab, zDb);
|
||||
pTab = sqliteLocateTable(pParse, zTab, zDb);
|
||||
pSrc->a[i].pTab = pTab;
|
||||
}
|
||||
return pTab;
|
||||
@@ -38,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;
|
||||
@@ -53,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 */
|
||||
@@ -61,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 */
|
||||
@@ -76,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;
|
||||
}
|
||||
@@ -88,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;
|
||||
}
|
||||
|
||||
@@ -122,10 +122,10 @@ void sqlite3DeleteFrom(
|
||||
assert( pTabList->nSrc==1 );
|
||||
iCur = pTabList->a[0].iCursor = pParse->nTab++;
|
||||
if( pWhere ){
|
||||
if( sqlite3ExprResolveIds(pParse, pTabList, 0, pWhere) ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, 0, pWhere) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
if( sqlite3ExprCheck(pParse, pWhere, 0, 0) ){
|
||||
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -133,31 +133,31 @@ void sqlite3DeleteFrom(
|
||||
/* 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;
|
||||
}
|
||||
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.
|
||||
@@ -168,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,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);
|
||||
}
|
||||
@@ -262,16 +253,16 @@ void sqlite3DeleteFrom(
|
||||
** cursors are opened only once on the outside the loop.
|
||||
*/
|
||||
pParse->nTab = iCur + 1;
|
||||
sqlite3OpenTableAndIndices(pParse, pTab, iCur);
|
||||
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, pParse->trigStack==0);
|
||||
sqliteGenerateRowDelete(db, v, pTab, iCur, pParse->trigStack==0);
|
||||
}
|
||||
|
||||
/* If there are row triggers, close all cursors then invoke
|
||||
@@ -280,45 +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;
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_SetCounts, 0, 0);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -342,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 */
|
||||
@@ -350,11 +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,
|
||||
addr = sqliteVdbeAddOp(v, OP_NotExists, iCur, 0);
|
||||
sqliteGenerateRowIndexDelete(db, v, pTab, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Delete, iCur,
|
||||
(count?OPFLAG_NCHANGE:0) | OPFLAG_CSCHANGE);
|
||||
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
|
||||
sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -373,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 */
|
||||
@@ -384,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 */
|
||||
|
||||
|
||||
|
||||
|
||||
+462
-662
File diff suppressed because it is too large
Load Diff
+246
-696
File diff suppressed because it is too large
Load Diff
+7
-10
@@ -12,7 +12,7 @@
|
||||
** This is the implementation of generic hash-tables
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.c,v 1.12 2004/05/08 08:23:25 danielk1977 Exp $
|
||||
** $Id: hash.c,v 1.11 2004/01/08 02:17:33 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <assert.h>
|
||||
@@ -29,7 +29,7 @@
|
||||
** sense for SQLITE_HASH_STRING and SQLITE_HASH_BINARY and is ignored
|
||||
** for other key classes.
|
||||
*/
|
||||
void sqlite3HashInit(Hash *new, int keyClass, int copyKey){
|
||||
void sqliteHashInit(Hash *new, int keyClass, int copyKey){
|
||||
assert( new!=0 );
|
||||
assert( keyClass>=SQLITE_HASH_INT && keyClass<=SQLITE_HASH_BINARY );
|
||||
new->keyClass = keyClass;
|
||||
@@ -45,7 +45,7 @@ void sqlite3HashInit(Hash *new, int keyClass, int copyKey){
|
||||
** 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 );
|
||||
@@ -94,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 n2-n1;
|
||||
return sqlite3StrNICmp((const char*)pKey1,(const char*)pKey2,n1);
|
||||
return sqliteStrNICmp((const char*)pKey1,(const char*)pKey2,n1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -258,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 */
|
||||
@@ -287,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 */
|
||||
@@ -354,6 +354,3 @@ void *sqlite3HashInsert(Hash *pH, const void *pKey, int nKey, void *data){
|
||||
new_elem->data = data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+5
-8
@@ -12,7 +12,7 @@
|
||||
** This is the header file for the generic hash-table implemenation
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.h,v 1.7 2004/05/08 08:23:25 danielk1977 Exp $
|
||||
** $Id: hash.h,v 1.6 2004/01/08 02:17:33 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_HASH_H_
|
||||
#define _SQLITE_HASH_H_
|
||||
@@ -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
|
||||
@@ -107,6 +107,3 @@ void sqlite3HashClear(Hash*);
|
||||
#define sqliteHashCount(H) ((H)->count)
|
||||
|
||||
#endif /* _SQLITE_HASH_H_ */
|
||||
|
||||
|
||||
|
||||
|
||||
+178
-275
@@ -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.112 2004/06/17 07:53:03 danielk1977 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, P3_STATIC);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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, P3_STATIC);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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,35 +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;
|
||||
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 ){
|
||||
@@ -264,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;
|
||||
|
||||
@@ -285,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;
|
||||
}
|
||||
@@ -300,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
|
||||
@@ -332,10 +244,10 @@ void sqlite3Insert(
|
||||
nColumn = pList->nExpr;
|
||||
dummy.nSrc = 0;
|
||||
for(i=0; i<nColumn; i++){
|
||||
if( sqlite3ExprResolveIds(pParse, &dummy, 0, pList->a[i].pExpr) ){
|
||||
if( sqliteExprResolveIds(pParse, &dummy, 0, pList->a[i].pExpr) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( sqlite3ExprCheck(pParse, pList->a[i].pExpr, 0, 0) ){
|
||||
if( sqliteExprCheck(pParse, pList->a[i].pExpr, 0, 0) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -345,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;
|
||||
}
|
||||
|
||||
@@ -372,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;
|
||||
@@ -381,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;
|
||||
@@ -404,22 +316,21 @@ 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;
|
||||
idx = sqlite3OpenTableAndIndices(pParse, pTab, base);
|
||||
idx = sqliteOpenTableAndIndices(pParse, pTab, base);
|
||||
pParse->nTab += idx;
|
||||
}
|
||||
|
||||
@@ -429,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
|
||||
@@ -449,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
|
||||
@@ -473,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;
|
||||
}
|
||||
@@ -506,7 +408,7 @@ void sqlite3Insert(
|
||||
*/
|
||||
if( row_triggers_exist && !isView ){
|
||||
base = pParse->nTab;
|
||||
idx = sqlite3OpenTableAndIndices(pParse, pTab, base);
|
||||
idx = sqliteOpenTableAndIndices(pParse, pTab, base);
|
||||
pParse->nTab += idx;
|
||||
}
|
||||
|
||||
@@ -518,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
|
||||
@@ -544,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 ){
|
||||
@@ -555,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;
|
||||
}
|
||||
@@ -598,43 +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);
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3VdbeAddOp(v, OP_SetCounts, 0, 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);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -673,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
|
||||
@@ -716,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 */
|
||||
@@ -735,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;
|
||||
@@ -754,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
|
||||
@@ -800,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;
|
||||
@@ -819,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -858,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;
|
||||
}
|
||||
@@ -885,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 ){
|
||||
@@ -915,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 */
|
||||
@@ -968,26 +874,25 @@ void sqlite3CompleteInsertion(
|
||||
int nIdx;
|
||||
Index *pIdx;
|
||||
|
||||
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);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, base,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -999,18 +904,16 @@ void sqlite3CompleteInsertion(
|
||||
** Return the total number of cursors opened. This is always at least
|
||||
** 1 (for the main table) plus more for each cursor.
|
||||
*/
|
||||
int sqlite3OpenTableAndIndices(Parse *pParse, Table *pTab, int base){
|
||||
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_OpenWrite, 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_OpenWrite, i+base, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenWrite, i+base, pIdx->tnum, pIdx->zName, P3_STATIC);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
-135
@@ -1,135 +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.3 2004/05/26 23:25:31 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(zSql[0]) ) zSql++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sqliteFree(azCols);
|
||||
azCols = 0;
|
||||
}
|
||||
|
||||
exec_out:
|
||||
if( pStmt ) sqlite3_finalize(pStmt);
|
||||
if( azCols ) sqliteFree(azCols);
|
||||
|
||||
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;
|
||||
}
|
||||
+601
-781
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(sqlite *db){
|
||||
sqlite3_create_function(db, "md5sum", -1, SQLITE_UTF8, 0, 0, 0,
|
||||
md5step, md5finalize);
|
||||
sqlite_create_aggregate(db, "md5sum", -1, md5step, md5finalize, 0);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,47 @@
|
||||
#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.
|
||||
**
|
||||
@@ -55,128 +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_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().
|
||||
*/
|
||||
#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 sqlite3OsDelete(const char*);
|
||||
int sqlite3OsFileExists(const char*);
|
||||
int sqliteOsDelete(const char*);
|
||||
int sqliteOsFileExists(const char*);
|
||||
int sqliteOsFileRename(const char*, 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);
|
||||
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*);
|
||||
|
||||
|
||||
|
||||
#endif /* _SQLITE_OS_H_ */
|
||||
|
||||
@@ -1,85 +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.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Macros for performance tracing. Normally turned off. Only works
|
||||
** on i486 hardware.
|
||||
*/
|
||||
int sqlite3_os_trace = 0;
|
||||
#ifdef SQLITE_DEBUG
|
||||
static int last_page = 0;
|
||||
__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 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)
|
||||
#else
|
||||
#define TIMER_START
|
||||
#define TIMER_END
|
||||
#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)
|
||||
#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_ */
|
||||
-1064
File diff suppressed because it is too large
Load Diff
@@ -1,87 +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 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 */
|
||||
int locktype; /* The type of lock held on this fd */
|
||||
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_ */
|
||||
-710
@@ -1,710 +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){
|
||||
DeleteFile(zFilename);
|
||||
TRACE2("DELETE \"%s\"\n", zFilename);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return TRUE if the named file exists.
|
||||
*/
|
||||
int sqlite3OsFileExists(const char *zFilename){
|
||||
return GetFileAttributes(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 = CreateFile(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 = CreateFile(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;
|
||||
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;
|
||||
if( delFlag ){
|
||||
fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS
|
||||
| FILE_FLAG_DELETE_ON_CLOSE;
|
||||
}else{
|
||||
fileflags = FILE_FLAG_RANDOM_ACCESS;
|
||||
}
|
||||
h = CreateFile(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;
|
||||
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 = CreateFile(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;
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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];
|
||||
GetTempPath(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){
|
||||
TRACE2("CLOSE %d\n", id->h);
|
||||
CloseHandle(id->h);
|
||||
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){
|
||||
DWORD got;
|
||||
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;
|
||||
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;
|
||||
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){
|
||||
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;
|
||||
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;
|
||||
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 */
|
||||
|
||||
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;
|
||||
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( 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 = GetFullPathName(zRelative, 0, 0, &zNotUsed) + 1;
|
||||
zFull = sqliteMalloc( nByte );
|
||||
if( zFull==0 ) return 0;
|
||||
GetFullPathName(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,50 +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 */
|
||||
int locktype; /* Type of lock currently held on this file */
|
||||
int 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_ */
|
||||
+668
-1252
File diff suppressed because it is too large
Load Diff
+36
-43
@@ -13,11 +13,11 @@
|
||||
** 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.34 2004/06/14 06:03:57 danielk1977 Exp $
|
||||
** @(#) $Id: pager.h,v 1.26 2004/02/11 02:18:07 drh Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
** The size of a 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
|
||||
@@ -50,7 +50,8 @@
|
||||
#define SQLITE_USABLE_SIZE (SQLITE_PAGE_SIZE-SQLITE_PAGE_RESERVE)
|
||||
|
||||
/*
|
||||
** Maximum number of pages in one database.
|
||||
** Maximum number of pages in one database. (This is a limitation of
|
||||
** imposed by 4GB files size limits.)
|
||||
*/
|
||||
#define SQLITE_MAX_PAGE 1073741823
|
||||
|
||||
@@ -69,46 +70,38 @@ 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 nPage, int nExtra, int useJournal,
|
||||
void *pBusyHandler);
|
||||
void sqlite3pager_set_destructor(Pager*, void(*)(void*,int));
|
||||
void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int));
|
||||
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);
|
||||
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*);
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
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
|
||||
|
||||
+265
-274
@@ -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.127 2004/06/09 09:55:18 danielk1977 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"
|
||||
@@ -69,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.
|
||||
@@ -108,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.
|
||||
@@ -122,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.
|
||||
@@ -157,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); }
|
||||
@@ -172,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
|
||||
@@ -231,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;}
|
||||
@@ -262,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). {
|
||||
@@ -302,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
|
||||
@@ -319,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
|
||||
@@ -346,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.
|
||||
//
|
||||
@@ -366,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); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,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}
|
||||
@@ -411,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[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;}
|
||||
|
||||
@@ -476,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;}
|
||||
@@ -511,203 +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(TK_NULL, 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(TK_INTEGER, 0, 0, &X);}
|
||||
expr(A) ::= FLOAT(X). {A = sqlite3Expr(TK_FLOAT, 0, 0, &X);}
|
||||
expr(A) ::= STRING(X). {A = sqlite3Expr(TK_STRING, 0, 0, &X);}
|
||||
expr(A) ::= BLOB(X). {A = sqlite3Expr(TK_BLOB, 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). {
|
||||
A = sqlite3Expr(TK_VARIABLE, 0, 0, &X);
|
||||
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 expr(Y). {A = sqlite3Expr(TK_AND, X, Y, 0);}
|
||||
expr(A) ::= expr(X) OR expr(Y). {A = sqlite3Expr(TK_OR, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LT expr(Y). {A = sqlite3Expr(TK_LT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) GT expr(Y). {A = sqlite3Expr(TK_GT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LE expr(Y). {A = sqlite3Expr(TK_LE, X, Y, 0);}
|
||||
expr(A) ::= expr(X) GE expr(Y). {A = sqlite3Expr(TK_GE, X, Y, 0);}
|
||||
expr(A) ::= expr(X) NE expr(Y). {A = sqlite3Expr(TK_NE, X, Y, 0);}
|
||||
expr(A) ::= expr(X) EQ expr(Y). {A = sqlite3Expr(TK_EQ, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITAND expr(Y). {A = sqlite3Expr(TK_BITAND, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITOR expr(Y). {A = sqlite3Expr(TK_BITOR, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LSHIFT expr(Y). {A = sqlite3Expr(TK_LSHIFT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) RSHIFT expr(Y). {A = sqlite3Expr(TK_RSHIFT, 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 expr(Y). {A = sqlite3Expr(TK_PLUS, X, Y, 0);}
|
||||
expr(A) ::= expr(X) MINUS expr(Y). {A = sqlite3Expr(TK_MINUS, X, Y, 0);}
|
||||
expr(A) ::= expr(X) STAR expr(Y). {A = sqlite3Expr(TK_STAR, X, Y, 0);}
|
||||
expr(A) ::= expr(X) SLASH expr(Y). {A = sqlite3Expr(TK_SLASH, X, Y, 0);}
|
||||
expr(A) ::= expr(X) REM expr(Y). {A = sqlite3Expr(TK_REM, X, Y, 0);}
|
||||
expr(A) ::= expr(X) CONCAT expr(Y). {A = sqlite3Expr(TK_CONCAT, 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(TK_NOT, 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(TK_BITNOT, 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;}
|
||||
@@ -717,77 +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 ids(X) EQ nm(Y). {sqlite3Pragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlite3Pragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlite3Pragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlite3Pragma(pParse,&X,&Y,1);}
|
||||
cmd ::= PRAGMA ids(X) LP nm(Y) RP. {sqlite3Pragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X). {sqlite3Pragma(pParse,&X,&X,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;}
|
||||
@@ -797,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}
|
||||
@@ -818,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;}
|
||||
@@ -834,7 +825,7 @@ when_clause(A) ::= . { A = 0; }
|
||||
when_clause(A) ::= WHEN expr(X). { A = X; }
|
||||
|
||||
%type trigger_cmd_list {TriggerStep *}
|
||||
%destructor trigger_cmd_list {sqlite3DeleteTriggerStep($$);}
|
||||
%destructor trigger_cmd_list {sqliteDeleteTriggerStep($$);}
|
||||
trigger_cmd_list(A) ::= trigger_cmd(X) SEMI trigger_cmd_list(Y). {
|
||||
X->pNext = Y;
|
||||
A = X;
|
||||
@@ -842,56 +833,56 @@ trigger_cmd_list(A) ::= trigger_cmd(X) SEMI trigger_cmd_list(Y). {
|
||||
trigger_cmd_list(A) ::= . { A = 0; }
|
||||
|
||||
%type trigger_cmd {TriggerStep *}
|
||||
%destructor trigger_cmd {sqlite3DeleteTriggerStep($$);}
|
||||
%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);
|
||||
sqliteAttach(pParse, &F, &D, &K);
|
||||
}
|
||||
%type key_opt {Token}
|
||||
key_opt(A) ::= USING ids(X). { A = X; }
|
||||
@@ -902,5 +893,5 @@ database_kw_opt ::= .
|
||||
|
||||
//////////////////////// DETACH DATABASE name /////////////////////////////////
|
||||
cmd ::= DETACH database_kw_opt nm(D). {
|
||||
sqlite3Detach(pParse, &D);
|
||||
sqliteDetach(pParse, &D);
|
||||
}
|
||||
|
||||
+254
-396
@@ -11,16 +11,11 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the PRAGMA command.
|
||||
**
|
||||
** $Id: pragma.c,v 1.46 2004/06/17 19:04:17 drh Exp $
|
||||
** $Id: pragma.c,v 1.19 2004/04/23 17:04:45 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
# include "pager.h"
|
||||
# include "btree.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Interpret the given string as a boolean value.
|
||||
*/
|
||||
@@ -32,7 +27,7 @@ static int getBoolean(const char *z){
|
||||
return atoi(z);
|
||||
}
|
||||
for(i=0; i<sizeof(azTrue)/sizeof(azTrue[0]); i++){
|
||||
if( sqlite3StrICmp(z,azTrue[i])==0 ) return 1;
|
||||
if( sqliteStrICmp(z,azTrue[i])==0 ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -43,7 +38,7 @@ static int getBoolean(const char *z){
|
||||
** unrecognized string argument.
|
||||
**
|
||||
** Note that the values returned are one less that the values that
|
||||
** should be passed into sqlite3BtreeSetSafetyLevel(). The is done
|
||||
** should be passed into sqliteBtreeSetSafetyLevel(). The is done
|
||||
** to support legacy SQL code. The safety level used to be boolean
|
||||
** and older scripts may have used numbers 0 for OFF and 1 for ON.
|
||||
*/
|
||||
@@ -66,7 +61,7 @@ static int getSafetyLevel(char *z){
|
||||
return atoi(z);
|
||||
}
|
||||
for(i=0; i<sizeof(aKey)/sizeof(aKey[0]); i++){
|
||||
if( sqlite3StrICmp(z,aKey[i].zWord)==0 ) return aKey[i].val;
|
||||
if( sqliteStrICmp(z,aKey[i].zWord)==0 ) return aKey[i].val;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -79,9 +74,9 @@ static int getSafetyLevel(char *z){
|
||||
static int getTempStore(const char *z){
|
||||
if( z[0]>='0' && z[0]<='2' ){
|
||||
return z[0] - '0';
|
||||
}else if( sqlite3StrICmp(z, "file")==0 ){
|
||||
}else if( sqliteStrICmp(z, "file")==0 ){
|
||||
return 1;
|
||||
}else if( sqlite3StrICmp(z, "memory")==0 ){
|
||||
}else if( sqliteStrICmp(z, "memory")==0 ){
|
||||
return 2;
|
||||
}else{
|
||||
return 0;
|
||||
@@ -98,14 +93,14 @@ static int changeTempStorage(Parse *pParse, const char *zStorageType){
|
||||
sqlite *db = pParse->db;
|
||||
if( db->temp_store==ts ) return SQLITE_OK;
|
||||
if( db->aDb[1].pBt!=0 ){
|
||||
if( !db->autoCommit ){
|
||||
sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
|
||||
if( db->flags & SQLITE_InTrans ){
|
||||
sqliteErrorMsg(pParse, "temporary storage cannot be changed "
|
||||
"from within a transaction");
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
sqlite3BtreeClose(db->aDb[1].pBt);
|
||||
sqliteBtreeClose(db->aDb[1].pBt);
|
||||
db->aDb[1].pBt = 0;
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
sqliteResetInternalSchema(db, 0);
|
||||
}
|
||||
db->temp_store = ts;
|
||||
return SQLITE_OK;
|
||||
@@ -122,25 +117,23 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
|
||||
int mask; /* Mask for the db->flags value */
|
||||
} aPragma[] = {
|
||||
{ "vdbe_trace", SQLITE_VdbeTrace },
|
||||
{ "sql_trace", SQLITE_SqlTrace },
|
||||
{ "vdbe_listing", SQLITE_VdbeListing },
|
||||
#if 1 /* FIX ME: Remove the following pragmas */
|
||||
{ "full_column_names", SQLITE_FullColNames },
|
||||
{ "short_column_names", SQLITE_ShortColNames },
|
||||
{ "show_datatypes", SQLITE_ReportTypes },
|
||||
{ "count_changes", SQLITE_CountRows },
|
||||
{ "empty_result_callbacks", SQLITE_NullCallback },
|
||||
#endif
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aPragma)/sizeof(aPragma[0]); i++){
|
||||
if( sqlite3StrICmp(zLeft, aPragma[i].zName)==0 ){
|
||||
if( sqliteStrICmp(zLeft, aPragma[i].zName)==0 ){
|
||||
sqlite *db = pParse->db;
|
||||
Vdbe *v;
|
||||
if( strcmp(zLeft,zRight)==0 && (v = sqlite3GetVdbe(pParse))!=0 ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, aPragma[i].zName, P3_STATIC);
|
||||
sqlite3VdbeCode(v, OP_Integer, (db->flags & aPragma[i].mask)!=0, 0,
|
||||
OP_Callback, 1, 0, 0);
|
||||
if( strcmp(zLeft,zRight)==0 && (v = sqliteGetVdbe(pParse))!=0 ){
|
||||
sqliteVdbeOp3(v, OP_ColumnName, 0, 1, aPragma[i].zName, P3_STATIC);
|
||||
sqliteVdbeOp3(v, OP_ColumnName, 1, 0, "boolean", P3_STATIC);
|
||||
sqliteVdbeCode(v, OP_Integer, (db->flags & aPragma[i].mask)!=0, 0,
|
||||
OP_Callback, 1, 0,
|
||||
0);
|
||||
}else if( getBoolean(zRight) ){
|
||||
db->flags |= aPragma[i].mask;
|
||||
}else{
|
||||
@@ -163,24 +156,26 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
|
||||
** identifier, or a number. If minusFlag is true, then the value is
|
||||
** a number that was preceded by a minus sign.
|
||||
*/
|
||||
void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
char *zLeft = 0;
|
||||
char *zRight = 0;
|
||||
sqlite *db = pParse->db;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
Vdbe *v = sqliteGetVdbe(pParse);
|
||||
if( v==0 ) return;
|
||||
|
||||
zLeft = sqliteStrNDup(pLeft->z, pLeft->n);
|
||||
sqlite3Dequote(zLeft);
|
||||
sqliteDequote(zLeft);
|
||||
if( minusFlag ){
|
||||
zRight = 0;
|
||||
sqlite3SetNString(&zRight, "-", 1, pRight->z, pRight->n, 0);
|
||||
sqliteSetNString(&zRight, "-", 1, pRight->z, pRight->n, 0);
|
||||
}else{
|
||||
zRight = sqliteStrNDup(pRight->z, pRight->n);
|
||||
sqlite3Dequote(zRight);
|
||||
sqliteDequote(zRight);
|
||||
}
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, 0) ){
|
||||
goto pragma_out;
|
||||
if( sqliteAuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, 0) ){
|
||||
sqliteFree(zLeft);
|
||||
sqliteFree(zRight);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -199,7 +194,7 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
** synchronous setting. A negative value means synchronous is off
|
||||
** and a positive value means synchronous is on.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
|
||||
if( sqliteStrICmp(zLeft,"default_cache_size")==0 ){
|
||||
static VdbeOpList getCacheSize[] = {
|
||||
{ OP_ReadCookie, 0, 2, 0},
|
||||
{ OP_AbsValue, 0, 0, 0},
|
||||
@@ -207,31 +202,26 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_Ne, 0, 6, 0},
|
||||
{ OP_Integer, 0, 0, 0}, /* 5 */
|
||||
{ OP_ColumnName, 0, 1, "cache_size"},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
int addr;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
if( pRight->z==pLeft->z ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "cache_size", P3_STATIC);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
|
||||
sqlite3VdbeChangeP1(v, addr+5, MAX_PAGES);
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
|
||||
sqliteVdbeChangeP1(v, addr+5, MAX_PAGES);
|
||||
}else{
|
||||
int size = atoi(zRight);
|
||||
if( size<0 ) size = -size;
|
||||
sqlite3BeginWriteOperation(pParse, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, size, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ReadCookie, 0, 2);
|
||||
addr = sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ge, 0, addr+3);
|
||||
sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetCookie, 0, 2);
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
sqliteBeginWriteOperation(pParse, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, size, 0);
|
||||
sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2);
|
||||
addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Ge, 0, addr+3);
|
||||
sqliteVdbeAddOp(v, OP_Negative, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_SetCookie, 0, 2);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
db->cache_size = db->cache_size<0 ? -size : size;
|
||||
sqlite3BtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -249,27 +239,22 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
** to its default value when the database is closed and reopened.
|
||||
** N should be a positive integer.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
|
||||
if( sqliteStrICmp(zLeft,"cache_size")==0 ){
|
||||
static VdbeOpList getCacheSize[] = {
|
||||
{ OP_ColumnName, 0, 1, "cache_size"},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
if( pRight->z==pLeft->z ){
|
||||
int size = db->cache_size;;
|
||||
if( size<0 ) size = -size;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, size, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "cache_size", P3_STATIC);
|
||||
sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
|
||||
sqliteVdbeAddOp(v, OP_Integer, size, 0);
|
||||
sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
|
||||
}else{
|
||||
int size = atoi(zRight);
|
||||
if( size<0 ) size = -size;
|
||||
if( db->cache_size<0 ) size = -size;
|
||||
db->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -292,52 +277,47 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
** is FULL, extra fsync()s occur to reduce the risk of corruption to near
|
||||
** zero, but with a write performance penalty. The default mode is NORMAL.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft,"default_synchronous")==0 ){
|
||||
if( sqliteStrICmp(zLeft,"default_synchronous")==0 ){
|
||||
static VdbeOpList getSync[] = {
|
||||
{ OP_ColumnName, 0, 1, "synchronous"},
|
||||
{ OP_ReadCookie, 0, 3, 0},
|
||||
{ OP_Dup, 0, 0, 0},
|
||||
{ OP_If, 0, 0, 0}, /* 2 */
|
||||
{ OP_If, 0, 0, 0}, /* 3 */
|
||||
{ OP_ReadCookie, 0, 2, 0},
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_Lt, 0, 5, 0},
|
||||
{ OP_AddImm, 1, 0, 0},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
{ OP_Halt, 0, 0, 0},
|
||||
{ OP_AddImm, -1, 0, 0}, /* 9 */
|
||||
{ OP_AddImm, -1, 0, 0}, /* 10 */
|
||||
{ OP_Callback, 1, 0, 0}
|
||||
};
|
||||
int addr;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
if( pRight->z==pLeft->z ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "synchronous", P3_STATIC);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(getSync), getSync);
|
||||
sqlite3VdbeChangeP2(v, addr+2, addr+9);
|
||||
int addr = sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
|
||||
sqliteVdbeChangeP2(v, addr+3, addr+10);
|
||||
}else{
|
||||
int addr;
|
||||
int size = db->cache_size;
|
||||
if( size<0 ) size = -size;
|
||||
sqlite3BeginWriteOperation(pParse, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ReadCookie, 0, 2);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ne, 0, addr+3);
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, MAX_PAGES, 0);
|
||||
sqlite3VdbeAddOp(v, OP_AbsValue, 0, 0);
|
||||
sqliteBeginWriteOperation(pParse, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Ne, 0, addr+3);
|
||||
sqliteVdbeAddOp(v, OP_AddImm, MAX_PAGES, 0);
|
||||
sqliteVdbeAddOp(v, OP_AbsValue, 0, 0);
|
||||
db->safety_level = getSafetyLevel(zRight)+1;
|
||||
if( db->safety_level==1 ){
|
||||
sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Negative, 0, 0);
|
||||
size = -size;
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_SetCookie, 0, 2);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, db->safety_level, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetCookie, 0, 3);
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
sqliteVdbeAddOp(v, OP_SetCookie, 0, 2);
|
||||
sqliteVdbeAddOp(v, OP_Integer, db->safety_level, 0);
|
||||
sqliteVdbeAddOp(v, OP_SetCookie, 0, 3);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
db->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
sqlite3BtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
|
||||
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -350,32 +330,27 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
** default value will be restored the next time the database is
|
||||
** opened.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft,"synchronous")==0 ){
|
||||
if( sqliteStrICmp(zLeft,"synchronous")==0 ){
|
||||
static VdbeOpList getSync[] = {
|
||||
{ OP_ColumnName, 0, 1, "synchronous"},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
if( pRight->z==pLeft->z ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "synchronous", P3_STATIC);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, db->safety_level-1, 0);
|
||||
sqlite3VdbeAddOpList(v, ArraySize(getSync), getSync);
|
||||
sqliteVdbeAddOp(v, OP_Integer, db->safety_level-1, 0);
|
||||
sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
|
||||
}else{
|
||||
int size = db->cache_size;
|
||||
if( size<0 ) size = -size;
|
||||
db->safety_level = getSafetyLevel(zRight)+1;
|
||||
if( db->safety_level==1 ) size = -size;
|
||||
db->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
sqlite3BtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
|
||||
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
|
||||
}
|
||||
}else
|
||||
|
||||
#ifndef NDEBUG
|
||||
if( sqlite3StrICmp(zLeft, "trigger_overhead_test")==0 ){
|
||||
if( sqliteStrICmp(zLeft, "trigger_overhead_test")==0 ){
|
||||
if( getBoolean(zRight) ){
|
||||
always_code_trigger_setup = 1;
|
||||
}else{
|
||||
@@ -388,147 +363,140 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
/* The flagPragma() call also generates any necessary code */
|
||||
}else
|
||||
|
||||
if( sqlite3StrICmp(zLeft, "table_info")==0 ){
|
||||
if( sqliteStrICmp(zLeft, "table_info")==0 ){
|
||||
Table *pTab;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
pTab = sqlite3FindTable(db, zRight, 0);
|
||||
pTab = sqliteFindTable(db, zRight, 0);
|
||||
if( pTab ){
|
||||
static VdbeOpList tableInfoPreface[] = {
|
||||
{ OP_ColumnName, 0, 0, "cid"},
|
||||
{ OP_ColumnName, 1, 0, "name"},
|
||||
{ OP_ColumnName, 2, 0, "type"},
|
||||
{ OP_ColumnName, 3, 0, "notnull"},
|
||||
{ OP_ColumnName, 4, 0, "dflt_value"},
|
||||
{ OP_ColumnName, 5, 1, "pk"},
|
||||
};
|
||||
int i;
|
||||
sqlite3VdbeSetNumCols(v, 6);
|
||||
sqlite3VdbeSetColName(v, 0, "cid", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "type", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, "notnull", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, "dflt_value", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 5, "pk", P3_STATIC);
|
||||
sqlite3ViewGetColumnNames(pParse, pTab);
|
||||
sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
|
||||
sqliteViewGetColumnNames(pParse, pTab);
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zName, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zName, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0,
|
||||
pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0,
|
||||
pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 6, 0);
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqlite3StrICmp(zLeft, "index_info")==0 ){
|
||||
if( sqliteStrICmp(zLeft, "index_info")==0 ){
|
||||
Index *pIdx;
|
||||
Table *pTab;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
pIdx = sqlite3FindIndex(db, zRight, 0);
|
||||
pIdx = sqliteFindIndex(db, zRight, 0);
|
||||
if( pIdx ){
|
||||
static VdbeOpList tableInfoPreface[] = {
|
||||
{ OP_ColumnName, 0, 0, "seqno"},
|
||||
{ OP_ColumnName, 1, 0, "cid"},
|
||||
{ OP_ColumnName, 2, 1, "name"},
|
||||
};
|
||||
int i;
|
||||
pTab = pIdx->pTable;
|
||||
sqlite3VdbeSetNumCols(v, 3);
|
||||
sqlite3VdbeSetColName(v, 0, "seqno", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "cid", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "name", P3_STATIC);
|
||||
sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
int cnum = pIdx->aiColumn[i];
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, cnum, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, cnum, 0);
|
||||
assert( pTab->nCol>cnum );
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[cnum].zName, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[cnum].zName, 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqlite3StrICmp(zLeft, "index_list")==0 ){
|
||||
if( sqliteStrICmp(zLeft, "index_list")==0 ){
|
||||
Index *pIdx;
|
||||
Table *pTab;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
pTab = sqlite3FindTable(db, zRight, 0);
|
||||
pTab = sqliteFindTable(db, zRight, 0);
|
||||
if( pTab ){
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
v = sqliteGetVdbe(pParse);
|
||||
pIdx = pTab->pIndex;
|
||||
if( pIdx ){
|
||||
int i = 0;
|
||||
sqlite3VdbeSetNumCols(v, 3);
|
||||
sqlite3VdbeSetColName(v, 0, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "unique", P3_STATIC);
|
||||
while(pIdx){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
|
||||
++i;
|
||||
pIdx = pIdx->pNext;
|
||||
}
|
||||
}
|
||||
if( pTab && pIdx ){
|
||||
int i = 0;
|
||||
static VdbeOpList indexListPreface[] = {
|
||||
{ OP_ColumnName, 0, 0, "seq"},
|
||||
{ OP_ColumnName, 1, 0, "name"},
|
||||
{ OP_ColumnName, 2, 1, "unique"},
|
||||
};
|
||||
|
||||
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
|
||||
while(pIdx){
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pIdx->zName, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
|
||||
++i;
|
||||
pIdx = pIdx->pNext;
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 ){
|
||||
if( sqliteStrICmp(zLeft, "foreign_key_list")==0 ){
|
||||
FKey *pFK;
|
||||
Table *pTab;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
pTab = sqlite3FindTable(db, zRight, 0);
|
||||
pTab = sqliteFindTable(db, zRight, 0);
|
||||
if( pTab ){
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
v = sqliteGetVdbe(pParse);
|
||||
pFK = pTab->pFKey;
|
||||
if( pFK ){
|
||||
int i = 0;
|
||||
sqlite3VdbeSetNumCols(v, 5);
|
||||
sqlite3VdbeSetColName(v, 0, "id", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "table", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, "from", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, "to", P3_STATIC);
|
||||
while(pFK){
|
||||
int j;
|
||||
for(j=0; j<pFK->nCol; j++){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, j, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->aCol[j].zCol, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 5, 0);
|
||||
}
|
||||
++i;
|
||||
pFK = pFK->pNextFrom;
|
||||
}
|
||||
if( pTab && pFK ){
|
||||
int i = 0;
|
||||
static VdbeOpList indexListPreface[] = {
|
||||
{ OP_ColumnName, 0, 0, "id"},
|
||||
{ OP_ColumnName, 1, 0, "seq"},
|
||||
{ OP_ColumnName, 2, 0, "table"},
|
||||
{ OP_ColumnName, 3, 0, "from"},
|
||||
{ OP_ColumnName, 4, 1, "to"},
|
||||
};
|
||||
|
||||
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
|
||||
while(pFK){
|
||||
int j;
|
||||
for(j=0; j<pFK->nCol; j++){
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, j, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pFK->zTo, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0,
|
||||
pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pFK->aCol[j].zCol, 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 5, 0);
|
||||
}
|
||||
++i;
|
||||
pFK = pFK->pNextFrom;
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqlite3StrICmp(zLeft, "database_list")==0 ){
|
||||
if( sqliteStrICmp(zLeft, "database_list")==0 ){
|
||||
int i;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
sqlite3VdbeSetNumCols(v, 3);
|
||||
sqlite3VdbeSetColName(v, 0, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "file", P3_STATIC);
|
||||
static VdbeOpList indexListPreface[] = {
|
||||
{ OP_ColumnName, 0, 0, "seq"},
|
||||
{ OP_ColumnName, 1, 0, "name"},
|
||||
{ OP_ColumnName, 2, 1, "file"},
|
||||
};
|
||||
|
||||
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( db->aDb[i].pBt==0 ) continue;
|
||||
assert( db->aDb[i].zName!=0 );
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0,
|
||||
sqliteBtreeGetFilename(db->aDb[i].pBt), 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -544,19 +512,14 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
** Note that it is possible for the library compile-time options to
|
||||
** override this setting
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "temp_store")==0 ){
|
||||
if( sqliteStrICmp(zLeft, "temp_store")==0 ){
|
||||
static VdbeOpList getTmpDbLoc[] = {
|
||||
{ OP_ColumnName, 0, 1, "temp_store"},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
if( pRight->z==pLeft->z ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, db->temp_store, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "temp_store", P3_STATIC);
|
||||
sqlite3VdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
|
||||
sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0);
|
||||
sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
|
||||
}else{
|
||||
changeTempStorage(pParse, zRight);
|
||||
}
|
||||
@@ -573,42 +536,33 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
** Note that it is possible for the library compile-time options to
|
||||
** override this setting
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "default_temp_store")==0 ){
|
||||
if( sqliteStrICmp(zLeft, "default_temp_store")==0 ){
|
||||
static VdbeOpList getTmpDbLoc[] = {
|
||||
{ OP_ColumnName, 0, 1, "temp_store"},
|
||||
{ OP_ReadCookie, 0, 5, 0},
|
||||
{ OP_Callback, 1, 0, 0}};
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
if( pRight->z==pLeft->z ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "temp_store", P3_STATIC);
|
||||
sqlite3VdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
|
||||
sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
|
||||
}else{
|
||||
sqlite3BeginWriteOperation(pParse, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, getTempStore(zRight), 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetCookie, 0, 5);
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
sqliteBeginWriteOperation(pParse, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, getTempStore(zRight), 0);
|
||||
sqliteVdbeAddOp(v, OP_SetCookie, 0, 5);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
}
|
||||
}else
|
||||
|
||||
#ifndef NDEBUG
|
||||
if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
|
||||
extern void sqlite3ParserTrace(FILE*, char *);
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
if( sqliteStrICmp(zLeft, "parser_trace")==0 ){
|
||||
extern void sqliteParserTrace(FILE*, char *);
|
||||
if( getBoolean(zRight) ){
|
||||
sqlite3ParserTrace(stdout, "parser: ");
|
||||
sqliteParserTrace(stdout, "parser: ");
|
||||
}else{
|
||||
sqlite3ParserTrace(0, 0);
|
||||
sqliteParserTrace(0, 0);
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
|
||||
if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){
|
||||
if( sqliteStrICmp(zLeft, "integrity_check")==0 ){
|
||||
int i, j, addr;
|
||||
|
||||
/* Code that initializes the integrity check program. Set the
|
||||
@@ -617,6 +571,30 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
static VdbeOpList initCode[] = {
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_MemStore, 0, 1, 0},
|
||||
{ OP_ColumnName, 0, 1, "integrity_check"},
|
||||
};
|
||||
|
||||
/* Code to do an BTree integrity check on a single database file.
|
||||
*/
|
||||
static VdbeOpList checkDb[] = {
|
||||
{ OP_SetInsert, 0, 0, "2"},
|
||||
{ OP_Integer, 0, 0, 0}, /* 1 */
|
||||
{ OP_OpenRead, 0, 2, 0},
|
||||
{ OP_Rewind, 0, 7, 0}, /* 3 */
|
||||
{ OP_Column, 0, 3, 0}, /* 4 */
|
||||
{ OP_SetInsert, 0, 0, 0},
|
||||
{ OP_Next, 0, 4, 0}, /* 6 */
|
||||
{ OP_IntegrityCk, 0, 0, 0}, /* 7 */
|
||||
{ OP_Dup, 0, 1, 0},
|
||||
{ OP_String, 0, 0, "ok"},
|
||||
{ OP_StrEq, 0, 12, 0}, /* 10 */
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_String, 0, 0, "*** in database "},
|
||||
{ OP_String, 0, 0, 0}, /* 13 */
|
||||
{ OP_String, 0, 0, " ***\n"},
|
||||
{ OP_Pull, 3, 0, 0},
|
||||
{ OP_Concat, 4, 1, 0},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
|
||||
/* Code that appears at the end of the integrity check. If no error
|
||||
@@ -627,91 +605,76 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
{ OP_MemLoad, 0, 0, 0},
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_Ne, 0, 0, 0}, /* 2 */
|
||||
{ OP_String8, 0, 0, "ok"},
|
||||
{ OP_String, 0, 0, "ok"},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
|
||||
/* Initialize the VDBE program */
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "integrity_check", P3_STATIC);
|
||||
sqlite3VdbeAddOpList(v, ArraySize(initCode), initCode);
|
||||
sqliteVdbeAddOpList(v, ArraySize(initCode), initCode);
|
||||
|
||||
/* Do an integrity check on each database file */
|
||||
for(i=0; i<db->nDb; i++){
|
||||
HashElem *x;
|
||||
int cnt = 0;
|
||||
|
||||
sqlite3CodeVerifySchema(pParse, i);
|
||||
|
||||
/* Do an integrity check of the B-Tree
|
||||
*/
|
||||
for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
|
||||
Table *pTab = sqliteHashData(x);
|
||||
Index *pIdx;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->tnum, 0);
|
||||
cnt++;
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ) goto pragma_out;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->tnum, 0);
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_IntegrityCk, cnt, i);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 1);
|
||||
addr = sqlite3VdbeOp3(v, OP_String8, 0, 0, "ok", P3_STATIC);
|
||||
sqlite3VdbeAddOp(v, OP_Eq, 0, addr+6);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
sqlite3MPrintf("*** in database %s ***\n", db->aDb[i].zName),
|
||||
P3_DYNAMIC);
|
||||
sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Concat, 2, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb);
|
||||
sqliteVdbeChangeP1(v, addr+1, i);
|
||||
sqliteVdbeChangeP2(v, addr+3, addr+7);
|
||||
sqliteVdbeChangeP2(v, addr+6, addr+4);
|
||||
sqliteVdbeChangeP2(v, addr+7, i);
|
||||
sqliteVdbeChangeP2(v, addr+10, addr+ArraySize(checkDb));
|
||||
sqliteVdbeChangeP3(v, addr+13, db->aDb[i].zName, P3_STATIC);
|
||||
|
||||
/* Make sure all the indices are constructed correctly.
|
||||
*/
|
||||
sqlite3CodeVerifySchema(pParse, i);
|
||||
sqliteCodeVerifySchema(pParse, i);
|
||||
for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
|
||||
Table *pTab = sqliteHashData(x);
|
||||
Index *pIdx;
|
||||
int loopTop;
|
||||
|
||||
if( pTab->pIndex==0 ) continue;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, 1, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, 1, pTab->nCol);
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenRead, 1, pTab->tnum, pTab->zName, 0);
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
if( pIdx->tnum==0 ) continue;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqlite3VdbeOp3(v, OP_OpenRead, j+2, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenRead, j+2, pIdx->tnum, pIdx->zName, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, 1, 1);
|
||||
loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, 1, 1);
|
||||
loopTop = sqliteVdbeAddOp(v, OP_Rewind, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemIncr, 1, 0);
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
int jmp2;
|
||||
int k, jmp2;
|
||||
static VdbeOpList idxErr[] = {
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_String8, 0, 0, "rowid "},
|
||||
{ OP_String, 0, 0, "rowid "},
|
||||
{ OP_Recno, 1, 0, 0},
|
||||
{ OP_String8, 0, 0, " missing from index "},
|
||||
{ OP_String8, 0, 0, 0}, /* 4 */
|
||||
{ OP_String, 0, 0, " missing from index "},
|
||||
{ OP_String, 0, 0, 0}, /* 4 */
|
||||
{ OP_Concat, 4, 0, 0},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
sqlite3GenerateIndexKey(v, pIdx, 1);
|
||||
jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
|
||||
sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
|
||||
sqlite3VdbeChangeP2(v, jmp2, sqlite3VdbeCurrentAddr(v));
|
||||
sqliteVdbeAddOp(v, OP_Recno, 1, 0);
|
||||
for(k=0; k<pIdx->nColumn; k++){
|
||||
int idx = pIdx->aiColumn[k];
|
||||
if( idx==pTab->iPKey ){
|
||||
sqliteVdbeAddOp(v, OP_Recno, 1, 0);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_Column, 1, idx);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
|
||||
if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
|
||||
jmp2 = sqliteVdbeAddOp(v, OP_Found, j+2, 0);
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(idxErr), idxErr);
|
||||
sqliteVdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
|
||||
sqliteVdbeChangeP2(v, jmp2, sqliteVdbeCurrentAddr(v));
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1);
|
||||
sqlite3VdbeChangeP2(v, loopTop, sqlite3VdbeCurrentAddr(v));
|
||||
sqliteVdbeAddOp(v, OP_Next, 1, loopTop+1);
|
||||
sqliteVdbeChangeP2(v, loopTop, sqliteVdbeCurrentAddr(v));
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
static VdbeOpList cntIdx[] = {
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
@@ -723,132 +686,27 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
{ OP_MemLoad, 2, 0, 0},
|
||||
{ OP_Eq, 0, 0, 0}, /* 7 */
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_String8, 0, 0, "wrong # of entries in index "},
|
||||
{ OP_String8, 0, 0, 0}, /* 10 */
|
||||
{ OP_String, 0, 0, "wrong # of entries in index "},
|
||||
{ OP_String, 0, 0, 0}, /* 10 */
|
||||
{ OP_Concat, 2, 0, 0},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
if( pIdx->tnum==0 ) continue;
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
|
||||
sqlite3VdbeChangeP1(v, addr+2, j+2);
|
||||
sqlite3VdbeChangeP2(v, addr+2, addr+5);
|
||||
sqlite3VdbeChangeP1(v, addr+4, j+2);
|
||||
sqlite3VdbeChangeP2(v, addr+4, addr+3);
|
||||
sqlite3VdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
|
||||
sqlite3VdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
|
||||
sqliteVdbeChangeP1(v, addr+2, j+2);
|
||||
sqliteVdbeChangeP2(v, addr+2, addr+5);
|
||||
sqliteVdbeChangeP1(v, addr+4, j+2);
|
||||
sqliteVdbeChangeP2(v, addr+4, addr+3);
|
||||
sqliteVdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
|
||||
sqliteVdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
|
||||
}
|
||||
}
|
||||
}
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
|
||||
sqlite3VdbeChangeP2(v, addr+2, addr+ArraySize(endCode));
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(endCode), endCode);
|
||||
sqliteVdbeChangeP2(v, addr+2, addr+ArraySize(endCode));
|
||||
}else
|
||||
/*
|
||||
** PRAGMA encoding
|
||||
** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
|
||||
**
|
||||
** In it's first form, this pragma returns the encoding of the main
|
||||
** database. If the database is not initialized, it is initialized now.
|
||||
**
|
||||
** The second form of this pragma is a no-op if the main database file
|
||||
** has not already been initialized. In this case it sets the default
|
||||
** encoding that will be used for the main database file if a new file
|
||||
** is created. If an existing main database file is opened, then the
|
||||
** default text encoding for the existing database is used.
|
||||
**
|
||||
** In all cases new databases created using the ATTACH command are
|
||||
** created to use the same default text encoding as the main database. If
|
||||
** the main database has not been initialized and/or created when ATTACH
|
||||
** is executed, this is done before the ATTACH operation.
|
||||
**
|
||||
** In the second form this pragma sets the text encoding to be used in
|
||||
** new database files created using this database handle. It is only
|
||||
** useful if invoked immediately after the main database i
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "encoding")==0 ){
|
||||
struct EncName {
|
||||
char *zName;
|
||||
u8 enc;
|
||||
} encnames[] = {
|
||||
{ "UTF-8", SQLITE_UTF8 },
|
||||
{ "UTF-16le", SQLITE_UTF16LE },
|
||||
{ "UTF-16be", SQLITE_UTF16BE },
|
||||
{ "UTF-16", SQLITE_UTF16NATIVE },
|
||||
{ "UTF8", SQLITE_UTF8 },
|
||||
{ "UTF16le", SQLITE_UTF16LE },
|
||||
{ "UTF16be", SQLITE_UTF16BE },
|
||||
{ "UTF16", SQLITE_UTF16NATIVE },
|
||||
{ 0, 0 }
|
||||
};
|
||||
struct EncName *pEnc;
|
||||
if( pRight->z==pLeft->z ){ /* "PRAGMA encoding" */
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
goto pragma_out;
|
||||
}
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "encoding", P3_STATIC);
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
|
||||
if( pEnc->enc==pParse->db->enc ){
|
||||
sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}else{ /* "PRAGMA encoding = XXX" */
|
||||
/* Only change the value of sqlite.enc if the database handle is not
|
||||
** initialized. If the main database exists, the new sqlite.enc value
|
||||
** will be overwritten when the schema is next loaded. If it does not
|
||||
** already exists, it will be created to use the new encoding value.
|
||||
*/
|
||||
if( !(pParse->db->flags&SQLITE_Initialized) ){
|
||||
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
|
||||
if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
|
||||
pParse->db->enc = pEnc->enc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !pEnc->zName ){
|
||||
sqlite3Error(pParse->db, SQLITE_ERROR,
|
||||
"Unsupported encoding: %s", zRight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
/*
|
||||
** Report the current state of file logs for all databases
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
|
||||
static char *azLockName[] = {
|
||||
"unlocked", "shared", "reserved", "pending", "exclusive"
|
||||
};
|
||||
int i;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
sqlite3VdbeSetNumCols(v, 2);
|
||||
sqlite3VdbeSetColName(v, 0, "database", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "status", P3_STATIC);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
Btree *pBt;
|
||||
Pager *pPager;
|
||||
if( db->aDb[i].zName==0 ) continue;
|
||||
sqlite3VdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, P3_STATIC);
|
||||
pBt = db->aDb[i].pBt;
|
||||
if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
|
||||
sqlite3VdbeOp3(v, OP_String, 0, 0, "closed", P3_STATIC);
|
||||
}else{
|
||||
int j = sqlite3pager_lockstate(pPager);
|
||||
sqlite3VdbeOp3(v, OP_String, 0, 0,
|
||||
(j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
|
||||
{}
|
||||
pragma_out:
|
||||
sqliteFree(zLeft);
|
||||
sqliteFree(zRight);
|
||||
}
|
||||
|
||||
+49
-87
@@ -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 */
|
||||
@@ -300,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;
|
||||
@@ -333,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.
|
||||
@@ -345,9 +336,8 @@ static int vxprintf(
|
||||
*/
|
||||
switch( xtype ){
|
||||
case etRADIX:
|
||||
if( flag_longlong ) longvalue = va_arg(ap,INT64_TYPE);
|
||||
else if( flag_long ) longvalue = va_arg(ap,long int);
|
||||
else longvalue = va_arg(ap,int);
|
||||
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. */
|
||||
@@ -358,21 +348,12 @@ static int vxprintf(
|
||||
if( longvalue==0 && infop->base==8 ) flag_alternateform = 0;
|
||||
#endif
|
||||
if( infop->flags & FLAG_SIGNED ){
|
||||
if( flag_longlong ){
|
||||
if( *(i64*)&longvalue<0 ){
|
||||
longvalue = -*(i64*)&longvalue;
|
||||
prefix = '-';
|
||||
}else if( flag_plussign ) prefix = '+';
|
||||
else if( flag_blanksign ) prefix = ' ';
|
||||
else prefix = 0;
|
||||
}else{
|
||||
if( *(long*)&longvalue<0 ){
|
||||
longvalue = -*(long*)&longvalue;
|
||||
prefix = '-';
|
||||
}else if( flag_plussign ) prefix = '+';
|
||||
else if( flag_blanksign ) prefix = ' ';
|
||||
else prefix = 0;
|
||||
}
|
||||
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);
|
||||
@@ -720,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);
|
||||
}
|
||||
@@ -741,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);
|
||||
}
|
||||
@@ -750,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];
|
||||
@@ -764,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];
|
||||
@@ -776,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;
|
||||
|
||||
@@ -800,48 +779,15 @@ char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
|
||||
return z;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
/*
|
||||
** 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.
|
||||
*/
|
||||
void sqlite3DebugPrintf(const char *zFormat, ...){
|
||||
va_list ap;
|
||||
char zBuf[500];
|
||||
va_start(ap, zFormat);
|
||||
base_vprintf(0, 0, zBuf, sizeof(zBuf), zFormat, ap);
|
||||
va_end(ap);
|
||||
fprintf(stdout,"%s", zBuf);
|
||||
fflush(stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The following four routines implement the varargs versions of the
|
||||
** sqlite3_exec() and sqlite3_get_table() interfaces. See the sqlite.h
|
||||
** 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.
|
||||
*/
|
||||
int sqlite3_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 = sqlite3_vmprintf(sqlFormat, ap);
|
||||
rc = sqlite3_exec(db, zSql, xCallback, pArg, errmsg);
|
||||
free(zSql);
|
||||
return rc;
|
||||
}
|
||||
int sqlite3_exec_printf(
|
||||
int sqlite_exec_printf(
|
||||
sqlite *db, /* An open database */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
sqlite_callback xCallback, /* Callback function */
|
||||
@@ -853,28 +799,27 @@ int sqlite3_exec_printf(
|
||||
int rc;
|
||||
|
||||
va_start(ap, errmsg);
|
||||
rc = sqlite3_exec_vprintf(db, sqlFormat, xCallback, pArg, errmsg, ap);
|
||||
rc = sqlite_exec_vprintf(db, sqlFormat, xCallback, pArg, errmsg, ap);
|
||||
va_end(ap);
|
||||
return rc;
|
||||
}
|
||||
int sqlite3_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 */
|
||||
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 = sqlite3_vmprintf(sqlFormat, ap);
|
||||
rc = sqlite3_get_table(db, zSql, resultp, nrow, ncolumn, errmsg);
|
||||
zSql = sqlite_vmprintf(sqlFormat, ap);
|
||||
rc = sqlite_exec(db, zSql, xCallback, pArg, errmsg);
|
||||
free(zSql);
|
||||
return rc;
|
||||
}
|
||||
int sqlite3_get_table_printf(
|
||||
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 */
|
||||
@@ -887,7 +832,24 @@ int sqlite3_get_table_printf(
|
||||
int rc;
|
||||
|
||||
va_start(ap, errmsg);
|
||||
rc = sqlite3_get_table_vprintf(db, sqlFormat, resultp, nrow, ncol, errmsg, ap);
|
||||
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;
|
||||
}
|
||||
|
||||
+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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+475
-674
File diff suppressed because it is too large
Load Diff
+60
-160
@@ -12,13 +12,12 @@
|
||||
** This file contains code to implement the "sqlite" command line
|
||||
** utility for accessing SQLite databases.
|
||||
**
|
||||
** $Id: shell.c,v 1.104 2004/06/08 00:39:01 danielk1977 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__)
|
||||
@@ -81,7 +80,7 @@ static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */
|
||||
/*
|
||||
** Determines if a string is a number of not.
|
||||
*/
|
||||
extern int sqlite3IsNumber(const char*, int*, unsigned char);
|
||||
extern int sqliteIsNumber(const char*);
|
||||
|
||||
/*
|
||||
** This routine reads a line of text from standard input, stores
|
||||
@@ -272,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);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -393,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( sqlite3IsNumber(azArg[i], 0, 1) ){
|
||||
}else if( sqliteIsNumber(azArg[i]) ){
|
||||
fprintf(p->out,"%s%s",zSep, azArg[i]);
|
||||
}else{
|
||||
if( zSep[0] ) fprintf(p->out,"%s",zSep);
|
||||
@@ -445,51 +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;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a different callback routine used for dumping the database.
|
||||
** Each row received by this callback consists of a table name,
|
||||
@@ -497,78 +451,21 @@ static char * appendText(char *zIn, char const *zAppend, char quote){
|
||||
** 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;
|
||||
sqlite3_stmt *pSelect = 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 = sqlite3_prepare(p->db, zSelect, -1, &pSelect, 0);
|
||||
if( zSelect ) free(zSelect);
|
||||
if( rc!=SQLITE_OK || !pSelect ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = sqlite3_step(pSelect);
|
||||
while( rc==SQLITE_ROW ){
|
||||
fprintf(p->out, "%s;\n", sqlite3_column_text(pSelect, 0));
|
||||
rc = sqlite3_step(pSelect);
|
||||
}
|
||||
rc = sqlite3_finalize(pSelect);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -613,17 +510,20 @@ static void process_input(struct callback_data *p, FILE *in);
|
||||
*/
|
||||
static void open_db(struct callback_data *p){
|
||||
if( p->db==0 ){
|
||||
char *zErrMsg = 0;
|
||||
#ifdef SQLITE_HAS_CODEC
|
||||
int n = p->zKey ? strlen(p->zKey) : 0;
|
||||
db = p->db = sqlite3_open_encrypted(p->zDbFilename, p->zKey, n, 0, &zErrMsg);
|
||||
assert(0); /* Encrypted databases are broken in SQLite 3 */
|
||||
db = p->db = sqlite_open_encrypted(p->zDbFilename, p->zKey, n, 0, &zErrMsg);
|
||||
#else
|
||||
sqlite3_open(p->zDbFilename, &p->db);
|
||||
db = p->db;
|
||||
db = p->db = sqlite_open(p->zDbFilename, 0, &zErrMsg);
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -676,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
|
||||
|
||||
@@ -688,7 +588,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
open_db(p);
|
||||
fprintf(p->out, "BEGIN TRANSACTION;\n");
|
||||
if( nArg==1 ){
|
||||
sqlite3_exec(p->db,
|
||||
sqlite_exec(p->db,
|
||||
"SELECT name, type, sql FROM sqlite_master "
|
||||
"WHERE type!='meta' AND sql NOT NULL "
|
||||
"ORDER BY substr(type,2,1), name",
|
||||
@@ -697,7 +597,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
}else{
|
||||
int i;
|
||||
for(i=1; i<nArg && zErrMsg==0; i++){
|
||||
sqlite3_exec_printf(p->db,
|
||||
sqlite_exec_printf(p->db,
|
||||
"SELECT name, type, sql FROM sqlite_master "
|
||||
"WHERE tbl_name LIKE '%q' AND type!='meta' AND sql NOT NULL "
|
||||
"ORDER BY substr(type,2,1), name",
|
||||
@@ -707,7 +607,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{
|
||||
fprintf(p->out, "COMMIT;\n");
|
||||
}
|
||||
@@ -802,7 +702,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
memcpy(&data, p, sizeof(data));
|
||||
data.showHeader = 0;
|
||||
data.mode = MODE_List;
|
||||
sqlite3_exec_printf(p->db,
|
||||
sqlite_exec_printf(p->db,
|
||||
"SELECT name FROM sqlite_master "
|
||||
"WHERE type='index' AND tbl_name LIKE '%q' "
|
||||
"UNION ALL "
|
||||
@@ -813,7 +713,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
|
||||
|
||||
@@ -897,8 +797,8 @@ 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]);
|
||||
sqlite_freemem(p->zKey);
|
||||
p->zKey = sqlite_mprintf("%s", azArg[2]);
|
||||
sqlite_rekey(p->db, p->zKey, strlen(p->zKey));
|
||||
}
|
||||
}else
|
||||
@@ -912,8 +812,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
data.showHeader = 0;
|
||||
data.mode = MODE_Semi;
|
||||
if( nArg>1 ){
|
||||
extern int sqlite3StrICmp(const char*,const char*);
|
||||
if( sqlite3StrICmp(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"
|
||||
@@ -926,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( sqlite3StrICmp(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"
|
||||
@@ -940,7 +840,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
new_colv[1] = 0;
|
||||
callback(&data, 1, new_argv, new_colv);
|
||||
}else{
|
||||
sqlite3_exec_printf(p->db,
|
||||
sqlite_exec_printf(p->db,
|
||||
"SELECT sql FROM "
|
||||
" (SELECT * FROM sqlite_master UNION ALL"
|
||||
" SELECT * FROM sqlite_temp_master) "
|
||||
@@ -949,7 +849,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
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) "
|
||||
@@ -960,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
|
||||
|
||||
@@ -991,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 "
|
||||
@@ -1001,7 +901,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
&azResult, &nRow, 0, &zErrMsg
|
||||
);
|
||||
}else{
|
||||
rc = sqlite3_get_table_printf(p->db,
|
||||
rc = sqlite_get_table_printf(p->db,
|
||||
"SELECT name FROM sqlite_master "
|
||||
"WHERE type IN ('table','view') AND name LIKE '%%%q%%' "
|
||||
"UNION ALL "
|
||||
@@ -1013,7 +913,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);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
int len, maxlen = 0;
|
||||
@@ -1035,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 ){
|
||||
@@ -1097,10 +997,10 @@ static int _all_whitespace(const char *z){
|
||||
** as is the Oracle "/".
|
||||
*/
|
||||
static int _is_command_terminator(const char *zLine){
|
||||
extern int sqlite3StrNICmp(const char*,const char*,int);
|
||||
extern int sqliteStrNICmp(const char*,const char*,int);
|
||||
while( isspace(*zLine) ){ zLine++; };
|
||||
if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ) return 1; /* Oracle */
|
||||
if( sqlite3StrNICmp(zLine,"go",2)==0 && _all_whitespace(&zLine[2]) ){
|
||||
if( sqliteStrNICmp(zLine,"go",2)==0 && _all_whitespace(&zLine[2]) ){
|
||||
return 1; /* SQL Server */
|
||||
}
|
||||
return 0;
|
||||
@@ -1155,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);
|
||||
@@ -1310,7 +1210,7 @@ int main(int argc, char **argv){
|
||||
const char *zInitFile = 0;
|
||||
char *zFirstCmd = 0;
|
||||
int i;
|
||||
extern int sqlite3OsFileExists(const char*);
|
||||
extern int sqliteOsFileExists(const char*);
|
||||
|
||||
#ifdef __MACOS__
|
||||
argc = ccommand(&argv);
|
||||
@@ -1339,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 ){
|
||||
@@ -1357,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( sqlite3OsFileExists(data.zDbFilename) ){
|
||||
if( sqliteOsFileExists(data.zDbFilename) ){
|
||||
open_db(&data);
|
||||
}
|
||||
|
||||
@@ -1397,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_version);
|
||||
printf("%s\n", sqlite_version);
|
||||
return 1;
|
||||
}else if( strcmp(z,"-help")==0 ){
|
||||
usage(1);
|
||||
@@ -1417,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);
|
||||
@@ -1432,7 +1332,7 @@ int main(int argc, char **argv){
|
||||
printf(
|
||||
"SQLite version %s\n"
|
||||
"Enter \".help\" for instructions\n",
|
||||
sqlite3_version
|
||||
sqlite_version
|
||||
);
|
||||
zHome = find_home_dir();
|
||||
if( zHome && (zHistory = malloc(strlen(zHome)+20))!=0 ){
|
||||
@@ -1449,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;
|
||||
}
|
||||
|
||||
+445
-652
File diff suppressed because it is too large
Load Diff
+233
-383
@@ -11,12 +11,13 @@
|
||||
*************************************************************************
|
||||
** Internal interface definitions for SQLite.
|
||||
**
|
||||
** @(#) $Id: sqliteInt.h,v 1.287 2004/06/18 04:24:54 danielk1977 Exp $
|
||||
** @(#) $Id: sqliteInt.h,v 1.220 2004/02/25 13:47:33 drh Exp $
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "sqlite3.h"
|
||||
#include "sqlite.h"
|
||||
#include "hash.h"
|
||||
#include "parse.h"
|
||||
#include "btree.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -58,9 +59,8 @@
|
||||
/*
|
||||
** The maximum number of attached databases. This must be at least 2
|
||||
** in order to support the main database file (0) and the file used to
|
||||
** hold temporary tables (1). And it must be less than 32 because
|
||||
** we use a bitmask of databases with a u32 in places (for example
|
||||
** the Parse.cookieMask field).
|
||||
** hold temporary tables (1). And it must be less than 256 because
|
||||
** an unsigned character is used to stored the database index.
|
||||
*/
|
||||
#define MAX_ATTACHED 10
|
||||
|
||||
@@ -96,12 +96,6 @@
|
||||
**
|
||||
** cc '-DUINTPTR_TYPE=long long int' ...
|
||||
*/
|
||||
#ifndef INT64_TYPE
|
||||
# define INT64_TYPE long long int
|
||||
#endif
|
||||
#ifndef UINT64_TYPE
|
||||
# define UINT64_TYPE unsigned long long int
|
||||
#endif
|
||||
#ifndef UINT32_TYPE
|
||||
# define UINT32_TYPE unsigned int
|
||||
#endif
|
||||
@@ -121,8 +115,6 @@
|
||||
# define INTPTR_TYPE long long
|
||||
# endif
|
||||
#endif
|
||||
typedef INT64_TYPE i64; /* 8-byte signed integer */
|
||||
typedef UINT64_TYPE u64; /* 8-byte unsigned integer */
|
||||
typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
|
||||
typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
|
||||
typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
|
||||
@@ -130,19 +122,10 @@ typedef UINT8_TYPE i8; /* 1-byte signed integer */
|
||||
typedef INTPTR_TYPE ptr; /* Big enough to hold a pointer */
|
||||
typedef unsigned INTPTR_TYPE uptr; /* Big enough to hold a pointer */
|
||||
|
||||
/*
|
||||
** Macros to determine whether the machine is big or little endian,
|
||||
** evaluated at runtime.
|
||||
*/
|
||||
extern const int sqlite3one;
|
||||
#define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
|
||||
#define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
|
||||
|
||||
/*
|
||||
** Defer sourcing vdbe.h until after the "u8" typedef is defined.
|
||||
*/
|
||||
#include "vdbe.h"
|
||||
#include "btree.h"
|
||||
|
||||
/*
|
||||
** Most C compilers these days recognize "long double", don't they?
|
||||
@@ -161,58 +144,62 @@ extern const int sqlite3one;
|
||||
|
||||
/*
|
||||
** The maximum number of bytes of data that can be put into a single
|
||||
** row of a single table. The upper bound on this limit is
|
||||
** 9223372036854775808 bytes (or 2**63). We have arbitrarily set the
|
||||
** limit to just 1MB here because the overflow page chain is inefficient
|
||||
** for really big records and we want to discourage people from thinking that
|
||||
** row of a single table. The upper bound on this limit is 16777215
|
||||
** bytes (or 16MB-1). We have arbitrarily set the limit to just 1MB
|
||||
** here because the overflow page chain is inefficient for really big
|
||||
** records and we want to discourage people from thinking that
|
||||
** multi-megabyte records are OK. If your needs are different, you can
|
||||
** change this define and recompile to increase or decrease the record
|
||||
** size.
|
||||
**
|
||||
** The 16777198 is computed as follows: 238 bytes of payload on the
|
||||
** original pages plus 16448 overflow pages each holding 1020 bytes of
|
||||
** data.
|
||||
*/
|
||||
#define MAX_BYTES_PER_ROW 1048576
|
||||
/* #define MAX_BYTES_PER_ROW 16777198 */
|
||||
|
||||
/*
|
||||
** If memory allocation problems are found, recompile with
|
||||
**
|
||||
** -DSQLITE_DEBUG=1
|
||||
** -DMEMORY_DEBUG=1
|
||||
**
|
||||
** to enable some sanity checking on malloc() and free(). To
|
||||
** check for memory leaks, recompile with
|
||||
**
|
||||
** -DSQLITE_DEBUG=2
|
||||
** -DMEMORY_DEBUG=2
|
||||
**
|
||||
** and a line of text will be written to standard error for
|
||||
** each malloc() and free(). This output can be analyzed
|
||||
** by an AWK script to determine if there are any leaks.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
# define sqliteMalloc(X) sqlite3Malloc_(X,1,__FILE__,__LINE__)
|
||||
# define sqliteMallocRaw(X) sqlite3Malloc_(X,0,__FILE__,__LINE__)
|
||||
# define sqliteFree(X) sqlite3Free_(X,__FILE__,__LINE__)
|
||||
# define sqliteRealloc(X,Y) sqlite3Realloc_(X,Y,__FILE__,__LINE__)
|
||||
# define sqliteStrDup(X) sqlite3StrDup_(X,__FILE__,__LINE__)
|
||||
# define sqliteStrNDup(X,Y) sqlite3StrNDup_(X,Y,__FILE__,__LINE__)
|
||||
void sqlite3StrRealloc(char**);
|
||||
#ifdef MEMORY_DEBUG
|
||||
# define sqliteMalloc(X) sqliteMalloc_(X,1,__FILE__,__LINE__)
|
||||
# define sqliteMallocRaw(X) sqliteMalloc_(X,0,__FILE__,__LINE__)
|
||||
# define sqliteFree(X) sqliteFree_(X,__FILE__,__LINE__)
|
||||
# define sqliteRealloc(X,Y) sqliteRealloc_(X,Y,__FILE__,__LINE__)
|
||||
# define sqliteStrDup(X) sqliteStrDup_(X,__FILE__,__LINE__)
|
||||
# define sqliteStrNDup(X,Y) sqliteStrNDup_(X,Y,__FILE__,__LINE__)
|
||||
void sqliteStrRealloc(char**);
|
||||
#else
|
||||
# define sqlite3FreeX sqliteFree
|
||||
# define sqlite3Realloc_(X,Y) sqliteRealloc(X,Y)
|
||||
# define sqlite3StrRealloc(X)
|
||||
# define sqliteRealloc_(X,Y) sqliteRealloc(X,Y)
|
||||
# define sqliteStrRealloc(X)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This variable gets set if malloc() ever fails. After it gets set,
|
||||
** the SQLite library shuts down permanently.
|
||||
*/
|
||||
extern int sqlite3_malloc_failed;
|
||||
extern int sqlite_malloc_failed;
|
||||
|
||||
/*
|
||||
** The following global variables are used for testing and debugging
|
||||
** only. They only work if SQLITE_DEBUG is defined.
|
||||
** only. They only work if MEMORY_DEBUG is defined.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
extern int sqlite3_nMalloc; /* Number of sqliteMalloc() calls */
|
||||
extern int sqlite3_nFree; /* Number of sqliteFree() calls */
|
||||
extern int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls */
|
||||
#ifdef MEMORY_DEBUG
|
||||
extern int sqlite_nMalloc; /* Number of sqliteMalloc() calls */
|
||||
extern int sqlite_nFree; /* Number of sqliteFree() calls */
|
||||
extern int sqlite_iMallocFail; /* Fail sqliteMalloc() after this many calls */
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -223,15 +210,10 @@ extern int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls *
|
||||
#define MASTER_NAME "sqlite_master"
|
||||
#define TEMP_MASTER_NAME "sqlite_temp_master"
|
||||
|
||||
/*
|
||||
** The root-page of the master database table.
|
||||
*/
|
||||
#define MASTER_ROOT 1
|
||||
|
||||
/*
|
||||
** The name of the schema table.
|
||||
*/
|
||||
#define SCHEMA_TABLE(x) (x==1?TEMP_MASTER_NAME:MASTER_NAME)
|
||||
#define SCHEMA_TABLE(x) (x?TEMP_MASTER_NAME:MASTER_NAME)
|
||||
|
||||
/*
|
||||
** A convenience macro that returns the number of elements in
|
||||
@@ -263,11 +245,6 @@ typedef struct TriggerStack TriggerStack;
|
||||
typedef struct FKey FKey;
|
||||
typedef struct Db Db;
|
||||
typedef struct AuthContext AuthContext;
|
||||
typedef struct KeyClass KeyClass;
|
||||
typedef struct CollSeq CollSeq;
|
||||
typedef struct KeyInfo KeyInfo;
|
||||
typedef struct BusyHandler BusyHandler;
|
||||
|
||||
|
||||
/*
|
||||
** Each database file to be accessed by the system is an instance
|
||||
@@ -321,35 +298,22 @@ struct Db {
|
||||
#define DB_SchemaLoaded 0x0004 /* The schema has been loaded */
|
||||
#define DB_UnresetViews 0x0008 /* Some views have defined column names */
|
||||
|
||||
#if 0
|
||||
/*
|
||||
** Possible values for the Db.textEnc field.
|
||||
*/
|
||||
#define TEXT_Utf8 1
|
||||
#define TEXT_Utf16le 2
|
||||
#define TEXT_Utf16be 3
|
||||
#define TEXT_Utf16 (SQLITE_BIGENDIAN?TEXT_Utf16be:TEXT_Utf16le)
|
||||
#endif
|
||||
|
||||
#define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
|
||||
|
||||
/*
|
||||
** An instance of the following structure is used to store the busy-handler
|
||||
** callback for a given sqlite handle.
|
||||
**
|
||||
** The sqlite.busyHandler member of the sqlite struct contains the busy
|
||||
** callback for the database handle. Each pager opened via the sqlite
|
||||
** handle is passed a pointer to sqlite.busyHandler. The busy-handler
|
||||
** callback is currently invoked only from within pager.c.
|
||||
*/
|
||||
struct BusyHandler {
|
||||
int (*xFunc)(void *,int); /* The busy callback */
|
||||
void *pArg; /* First arg to busy callback */
|
||||
};
|
||||
|
||||
/*
|
||||
** Each database is an instance of the following structure.
|
||||
**
|
||||
** The sqlite.file_format is initialized by the database file
|
||||
** and helps determines how the data in the database file is
|
||||
** represented. This field allows newer versions of the library
|
||||
** to read and write older databases. The various file formats
|
||||
** are as follows:
|
||||
**
|
||||
** file_format==1 Version 2.1.0.
|
||||
** file_format==2 Version 2.2.0. Add support for INTEGER PRIMARY KEY.
|
||||
** file_format==3 Version 2.6.0. Fix empty-string index bug.
|
||||
** file_format==4 Version 2.7.0. Add support for separate numeric and
|
||||
** text datatypes.
|
||||
**
|
||||
** The sqlite.temp_store determines where temporary database files
|
||||
** are stored. If 1, then a file is created to hold those tables. If
|
||||
** 2, then they are held in memory. 0 means use the default value in
|
||||
@@ -363,7 +327,7 @@ struct BusyHandler {
|
||||
** longer (since after version 2.8.12) reset to -1.
|
||||
**
|
||||
** The sqlite.nChange does not count changes within triggers and keeps no
|
||||
** context. It is reset at start of sqlite3_exec.
|
||||
** context. It is reset at start of sqlite_exec.
|
||||
** The sqlite.lsChange represents the number of changes made by the last
|
||||
** insert, update, or delete statement. It remains constant throughout the
|
||||
** length of a statement and is then updated by OP_SetCounts. It keeps a
|
||||
@@ -372,11 +336,6 @@ struct BusyHandler {
|
||||
** affect the value of lsChange.
|
||||
** The sqlite.csChange keeps track of the number of current changes (since
|
||||
** the last statement) and is used to update sqlite_lsChange.
|
||||
**
|
||||
** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16
|
||||
** store the most recent error code and, if applicable, string. The
|
||||
** internal function sqlite3Error() is used to set these variables
|
||||
** consistently.
|
||||
*/
|
||||
struct sqlite {
|
||||
int nDb; /* Number of backends currently in use */
|
||||
@@ -387,28 +346,27 @@ struct sqlite {
|
||||
u8 safety_level; /* How aggressive at synching data to disk */
|
||||
u8 want_to_close; /* Close after all VDBEs are deallocated */
|
||||
u8 temp_store; /* 1=file, 2=memory, 0=compile-time default */
|
||||
u8 onError; /* Default conflict algorithm */
|
||||
int next_cookie; /* Next value of aDb[0].schema_cookie */
|
||||
int cache_size; /* Number of pages to use in the cache */
|
||||
int nTable; /* Number of tables in the database */
|
||||
BusyHandler busyHandler; /* Busy callback */
|
||||
void *pBusyArg; /* 1st Argument to the busy callback */
|
||||
int (*xBusyCallback)(void *,const char*,int); /* The busy callback */
|
||||
void *pCommitArg; /* Argument to xCommitCallback() */
|
||||
int (*xCommitCallback)(void*);/* Invoked at every commit. */
|
||||
Hash aFunc; /* All functions that can be in SQL exprs */
|
||||
Hash aCollSeq; /* All collating sequences */
|
||||
CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
|
||||
i64 lastRowid; /* ROWID of most recent insert (see above) */
|
||||
i64 priorNewRowid; /* Last randomly generated ROWID */
|
||||
int lastRowid; /* ROWID of most recent insert (see above) */
|
||||
int priorNewRowid; /* Last randomly generated ROWID */
|
||||
int magic; /* Magic number for detect library misuse */
|
||||
int nChange; /* Number of rows changed (see above) */
|
||||
int lsChange; /* Last statement change count (see above) */
|
||||
int csChange; /* Current statement change count (see above) */
|
||||
struct sqlite3InitInfo { /* Information used during initialization */
|
||||
struct sqliteInitInfo { /* Information used during initialization */
|
||||
int iDb; /* When back is being initialized */
|
||||
int newTnum; /* Rootpage of table being initialized */
|
||||
u8 busy; /* TRUE if currently initializing */
|
||||
} init;
|
||||
struct Vdbe *pVdbe; /* List of active virtual machines */
|
||||
int activeVdbeCnt; /* Number of vdbes currently executing */
|
||||
void (*xTrace)(void*,const char*); /* Trace function */
|
||||
void *pTraceArg; /* Argument to the trace function */
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
@@ -421,19 +379,6 @@ struct sqlite {
|
||||
void *pProgressArg; /* Argument to the progress callback */
|
||||
int nProgressOps; /* Number of opcodes for progress callback */
|
||||
#endif
|
||||
|
||||
int errCode; /* Most recent error code (SQLITE_*) */
|
||||
u8 enc; /* Text encoding for this database. */
|
||||
u8 autoCommit; /* The auto-commit flag. */
|
||||
int nMaster; /* Length of master journal name. -1=unknown */
|
||||
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
|
||||
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
|
||||
void *pCollNeededArg;
|
||||
sqlite3_value *pValue; /* Value used for transient conversions */
|
||||
sqlite3_value *pErr; /* Most recent error message */
|
||||
|
||||
char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
|
||||
char *zErrMsg16; /* Most recent error message (UTF-8 encoded) */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -455,8 +400,8 @@ struct sqlite {
|
||||
/* the count using a callback. */
|
||||
#define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
|
||||
/* result set is empty */
|
||||
#define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */
|
||||
#define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */
|
||||
#define SQLITE_ReportTypes 0x00000200 /* Include information on datatypes */
|
||||
/* in 4th argument of callback */
|
||||
|
||||
/*
|
||||
** Possible values for the sqlite.magic field.
|
||||
@@ -475,15 +420,15 @@ struct sqlite {
|
||||
** points to a linked list of these structures.
|
||||
*/
|
||||
struct FuncDef {
|
||||
char *zName; /* SQL name of the function */
|
||||
int nArg; /* Number of arguments. -1 means unlimited */
|
||||
u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
|
||||
void *pUserData; /* User data parameter */
|
||||
FuncDef *pNext; /* Next function with same name */
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
|
||||
void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */
|
||||
u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */
|
||||
void (*xFunc)(sqlite_func*,int,const char**); /* Regular function */
|
||||
void (*xStep)(sqlite_func*,int,const char**); /* Aggregate function step */
|
||||
void (*xFinalize)(sqlite_func*); /* Aggregate function finializer */
|
||||
signed char nArg; /* Number of arguments. -1 means unlimited */
|
||||
signed char dataType; /* Arg that determines datatype. -1=NUMERIC, */
|
||||
/* -2=TEXT. -3=SQLITE_ARGS */
|
||||
u8 includeTypes; /* Add datatypes to args of xFunc and xStep */
|
||||
void *pUserData; /* User data parameter */
|
||||
FuncDef *pNext; /* Next function with same name */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -494,55 +439,25 @@ struct Column {
|
||||
char *zName; /* Name of this column */
|
||||
char *zDflt; /* Default value of this column */
|
||||
char *zType; /* Data type for this column */
|
||||
CollSeq *pColl; /* Collating sequence. If NULL, use the default */
|
||||
u8 notNull; /* True if there is a NOT NULL constraint */
|
||||
u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */
|
||||
char affinity; /* One of the SQLITE_AFF_... values */
|
||||
u8 sortOrder; /* Some combination of SQLITE_SO_... values */
|
||||
u8 dottedName; /* True if zName contains a "." character */
|
||||
};
|
||||
|
||||
/*
|
||||
** A "Collating Sequence" is defined by an instance of the following
|
||||
** structure. Conceptually, a collating sequence consists of a name and
|
||||
** a comparison routine that defines the order of that sequence.
|
||||
** The allowed sort orders.
|
||||
**
|
||||
** There may two seperate implementations of the collation function, one
|
||||
** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that
|
||||
** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine
|
||||
** native byte order. When a collation sequence is invoked, SQLite selects
|
||||
** the version that will require the least expensive encoding
|
||||
** transalations, if any.
|
||||
**
|
||||
** The CollSeq.pUser member variable is an extra parameter that passed in
|
||||
** as the first argument to the UTF-8 comparison function, xCmp.
|
||||
** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function,
|
||||
** xCmp16.
|
||||
**
|
||||
** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
|
||||
** collating sequence is undefined. Indices built on an undefined
|
||||
** collating sequence may not be read or written.
|
||||
*/
|
||||
struct CollSeq {
|
||||
char *zName; /* Name of the collating sequence, UTF-8 encoded */
|
||||
u8 enc; /* Text encoding handled by xCmp() */
|
||||
void *pUser; /* First argument to xCmp() */
|
||||
int (*xCmp)(void*,int, const void*, int, const void*);
|
||||
};
|
||||
|
||||
/*
|
||||
** A sort order can be either ASC or DESC.
|
||||
** The TEXT and NUM values use bits that do not overlap with DESC and ASC.
|
||||
** That way the two can be combined into a single number.
|
||||
*/
|
||||
#define SQLITE_SO_UNK 0 /* Use the default collating type. (SCT_NUM) */
|
||||
#define SQLITE_SO_TEXT 2 /* Sort using memcmp() */
|
||||
#define SQLITE_SO_NUM 4 /* Sort using sqliteCompare() */
|
||||
#define SQLITE_SO_TYPEMASK 6 /* Mask to extract the collating sequence */
|
||||
#define SQLITE_SO_ASC 0 /* Sort in ascending order */
|
||||
#define SQLITE_SO_DESC 1 /* Sort in ascending order */
|
||||
|
||||
/*
|
||||
** Column affinity types.
|
||||
*/
|
||||
#define SQLITE_AFF_INTEGER 'i'
|
||||
#define SQLITE_AFF_NUMERIC 'n'
|
||||
#define SQLITE_AFF_TEXT 't'
|
||||
#define SQLITE_AFF_NONE 'o'
|
||||
|
||||
#define SQLITE_SO_DESC 1 /* Sort in descending order */
|
||||
#define SQLITE_SO_DIRMASK 1 /* Mask to extract the sort direction */
|
||||
|
||||
/*
|
||||
** Each SQL table is represented in memory by an instance of the
|
||||
@@ -589,7 +504,6 @@ struct Table {
|
||||
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
|
||||
Trigger *pTrigger; /* List of SQL triggers on this table */
|
||||
FKey *pFKey; /* Linked list of all foreign keys in this table */
|
||||
char *zColAff; /* String defining the affinity of each column */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -672,23 +586,6 @@ struct FKey {
|
||||
|
||||
#define OE_Default 99 /* Do whatever the default action is */
|
||||
|
||||
|
||||
/*
|
||||
** An instance of the following structure is passed as the first
|
||||
** argument to sqlite3VdbeKeyCompare and is used to control the
|
||||
** comparison of the two index keys.
|
||||
**
|
||||
** If the KeyInfo.incrKey value is true and the comparison would
|
||||
** otherwise be equal, then return a result as if the second key larger.
|
||||
*/
|
||||
struct KeyInfo {
|
||||
u8 enc; /* Text encoding - one of the TEXT_Utf* values */
|
||||
u8 incrKey; /* Increase 2nd key by epsilon before comparison */
|
||||
int nField; /* Number of entries in aColl[] */
|
||||
u8 *aSortOrder; /* If defined an aSortOrder[i] is true, sort DESC */
|
||||
CollSeq *aColl[1]; /* Collating sequence for each term of the key */
|
||||
};
|
||||
|
||||
/*
|
||||
** Each SQL index is represented in memory by an
|
||||
** instance of the following structure.
|
||||
@@ -724,9 +621,7 @@ struct Index {
|
||||
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
|
||||
u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
|
||||
u8 iDb; /* Index in sqlite.aDb[] of where this index is stored */
|
||||
char *zColAff; /* String defining the affinity of each column */
|
||||
Index *pNext; /* The next index associated with the same table */
|
||||
KeyInfo keyInfo; /* Info on how to order keys. MUST BE LAST */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -781,8 +676,7 @@ struct Token {
|
||||
*/
|
||||
struct Expr {
|
||||
u8 op; /* Operation performed by this node */
|
||||
char affinity; /* The affinity of the column or 0 if not a column */
|
||||
CollSeq *pColl; /* The collation type of the column or 0 */
|
||||
u8 dataType; /* Either SQLITE_SO_TEXT or SQLITE_SO_NUM */
|
||||
u8 iDb; /* Database referenced by this expression */
|
||||
u8 flags; /* Various flags. See below */
|
||||
Expr *pLeft, *pRight; /* Left and right subnodes */
|
||||
@@ -962,7 +856,6 @@ struct Select {
|
||||
int nLimit, nOffset; /* LIMIT and OFFSET values. -1 means not used */
|
||||
int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
|
||||
char *zSelect; /* Complete text of the SELECT command */
|
||||
IdList **ppOpenTemp; /* OP_OpenTemp addresses used by multi-selects */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -1014,7 +907,7 @@ struct Parse {
|
||||
int rc; /* Return code from execution */
|
||||
char *zErrMsg; /* An error message */
|
||||
Token sErrToken; /* The token at which the error occurred */
|
||||
Token sNameToken; /* Token with unqualified schema object name */
|
||||
Token sFirstToken; /* The first token parsed */
|
||||
Token sLastToken; /* The last token parsed */
|
||||
const char *zTail; /* All SQL text past the last semicolon parsed */
|
||||
Table *pNewTable; /* A table being constructed by CREATE TABLE */
|
||||
@@ -1024,7 +917,6 @@ struct Parse {
|
||||
u8 nameClash; /* A permanent table name clashes with temp table name */
|
||||
u8 useAgg; /* If true, extract field values from the aggregator
|
||||
** while generating expressions. Normally false */
|
||||
u8 checkSchema; /* Causes schema cookie check after an error */
|
||||
int nErr; /* Number of errors seen */
|
||||
int nTab; /* Number of previously allocated VDBE cursors */
|
||||
int nMem; /* Number of memory cells used so far */
|
||||
@@ -1035,10 +927,6 @@ struct Parse {
|
||||
const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
|
||||
Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
|
||||
TriggerStack *trigStack; /* Trigger actions being coded */
|
||||
u32 cookieMask; /* Bitmask of schema verified databases */
|
||||
int cookieValue[MAX_ATTACHED+2]; /* Values of cookies to verify */
|
||||
int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
|
||||
u32 writeMask; /* Start a write transaction on these databases */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -1123,7 +1011,7 @@ struct Trigger {
|
||||
* pWhere -> The WHERE clause of the UPDATE statement if one is specified.
|
||||
* Otherwise NULL.
|
||||
* pExprList -> A list of the columns to update and the expressions to update
|
||||
* them to. See sqlite3Update() documentation of "pChanges"
|
||||
* them to. See sqliteUpdate() documentation of "pChanges"
|
||||
* argument.
|
||||
*
|
||||
*/
|
||||
@@ -1203,21 +1091,20 @@ extern int always_code_trigger_setup;
|
||||
/*
|
||||
** Internal function prototypes
|
||||
*/
|
||||
int sqlite3StrICmp(const char *, const char *);
|
||||
int sqlite3StrNICmp(const char *, const char *, int);
|
||||
int sqlite3HashNoCase(const char *, int);
|
||||
int sqlite3IsNumber(const char*, int*, u8);
|
||||
int sqlite3Compare(const char *, const char *);
|
||||
int sqlite3SortCompare(const char *, const char *);
|
||||
void sqlite3RealToSortable(double r, char *);
|
||||
#ifdef SQLITE_DEBUG
|
||||
void *sqlite3Malloc_(int,int,char*,int);
|
||||
void sqlite3Free_(void*,char*,int);
|
||||
void *sqlite3Realloc_(void*,int,char*,int);
|
||||
char *sqlite3StrDup_(const char*,char*,int);
|
||||
char *sqlite3StrNDup_(const char*, int,char*,int);
|
||||
void sqlite3CheckMemory(void*,int);
|
||||
void sqlite3FreeX(void *p);
|
||||
int sqliteStrICmp(const char *, const char *);
|
||||
int sqliteStrNICmp(const char *, const char *, int);
|
||||
int sqliteHashNoCase(const char *, int);
|
||||
int sqliteIsNumber(const char*);
|
||||
int sqliteCompare(const char *, const char *);
|
||||
int sqliteSortCompare(const char *, const char *);
|
||||
void sqliteRealToSortable(double r, char *);
|
||||
#ifdef MEMORY_DEBUG
|
||||
void *sqliteMalloc_(int,int,char*,int);
|
||||
void sqliteFree_(void*,char*,int);
|
||||
void *sqliteRealloc_(void*,int,char*,int);
|
||||
char *sqliteStrDup_(const char*,char*,int);
|
||||
char *sqliteStrNDup_(const char*, int,char*,int);
|
||||
void sqliteCheckMemory(void*,int);
|
||||
#else
|
||||
void *sqliteMalloc(int);
|
||||
void *sqliteMallocRaw(int);
|
||||
@@ -1225,192 +1112,155 @@ void sqlite3RealToSortable(double r, char *);
|
||||
void *sqliteRealloc(void*,int);
|
||||
char *sqliteStrDup(const char*);
|
||||
char *sqliteStrNDup(const char*, int);
|
||||
# define sqlite3CheckMemory(a,b)
|
||||
# define sqliteCheckMemory(a,b)
|
||||
#endif
|
||||
char *sqlite3MPrintf(const char*, ...);
|
||||
char *sqlite3VMPrintf(const char*, va_list);
|
||||
void sqlite3DebugPrintf(const char*, ...);
|
||||
void sqlite3SetString(char **, const char *, ...);
|
||||
void sqlite3SetNString(char **, ...);
|
||||
void sqlite3ErrorMsg(Parse*, const char*, ...);
|
||||
void sqlite3Dequote(char*);
|
||||
int sqlite3KeywordCode(const char*, int);
|
||||
int sqlite3RunParser(Parse*, const char*, char **);
|
||||
void sqlite3FinishCoding(Parse*);
|
||||
Expr *sqlite3Expr(int, Expr*, Expr*, Token*);
|
||||
void sqlite3ExprSpan(Expr*,Token*,Token*);
|
||||
Expr *sqlite3ExprFunction(ExprList*, Token*);
|
||||
void sqlite3ExprDelete(Expr*);
|
||||
ExprList *sqlite3ExprListAppend(ExprList*,Expr*,Token*);
|
||||
void sqlite3ExprListDelete(ExprList*);
|
||||
int sqlite3Init(sqlite*, char**);
|
||||
void sqlite3Pragma(Parse*,Token*,Token*,int);
|
||||
void sqlite3ResetInternalSchema(sqlite*, int);
|
||||
void sqlite3BeginParse(Parse*,int);
|
||||
void sqlite3RollbackInternalChanges(sqlite*);
|
||||
void sqlite3CommitInternalChanges(sqlite*);
|
||||
Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*);
|
||||
void sqlite3OpenMasterTable(Vdbe *v, int);
|
||||
void sqlite3StartTable(Parse*,Token*,Token*,Token*,int,int);
|
||||
void sqlite3AddColumn(Parse*,Token*);
|
||||
void sqlite3AddNotNull(Parse*, int);
|
||||
void sqlite3AddPrimaryKey(Parse*, ExprList*, int);
|
||||
void sqlite3AddColumnType(Parse*,Token*,Token*);
|
||||
void sqlite3AddDefaultValue(Parse*,Token*,int);
|
||||
void sqlite3AddCollateType(Parse*, const char*, int);
|
||||
void sqlite3EndTable(Parse*,Token*,Select*);
|
||||
void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int);
|
||||
int sqlite3ViewGetColumnNames(Parse*,Table*);
|
||||
void sqlite3DropTable(Parse*, SrcList*, int);
|
||||
void sqlite3DeleteTable(sqlite*, Table*);
|
||||
void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
|
||||
IdList *sqlite3IdListAppend(IdList*, Token*);
|
||||
int sqlite3IdListIndex(IdList*,const char*);
|
||||
SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
|
||||
void sqlite3SrcListAddAlias(SrcList*, Token*);
|
||||
void sqlite3SrcListAssignCursors(Parse*, SrcList*);
|
||||
void sqlite3IdListDelete(IdList*);
|
||||
void sqlite3SrcListDelete(SrcList*);
|
||||
void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
|
||||
Token*);
|
||||
void sqlite3DropIndex(Parse*, SrcList*);
|
||||
void sqlite3AddKeyType(Vdbe*, ExprList*);
|
||||
void sqlite3AddIdxKeyType(Vdbe*, Index*);
|
||||
int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*, char *aff);
|
||||
Select *sqlite3SelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*,
|
||||
char *sqliteMPrintf(const char*, ...);
|
||||
char *sqliteVMPrintf(const char*, va_list);
|
||||
void sqliteSetString(char **, const char *, ...);
|
||||
void sqliteSetNString(char **, ...);
|
||||
void sqliteErrorMsg(Parse*, const char*, ...);
|
||||
void sqliteDequote(char*);
|
||||
int sqliteKeywordCode(const char*, int);
|
||||
int sqliteRunParser(Parse*, const char*, char **);
|
||||
void sqliteExec(Parse*);
|
||||
Expr *sqliteExpr(int, Expr*, Expr*, Token*);
|
||||
void sqliteExprSpan(Expr*,Token*,Token*);
|
||||
Expr *sqliteExprFunction(ExprList*, Token*);
|
||||
void sqliteExprDelete(Expr*);
|
||||
ExprList *sqliteExprListAppend(ExprList*,Expr*,Token*);
|
||||
void sqliteExprListDelete(ExprList*);
|
||||
int sqliteInit(sqlite*, char**);
|
||||
void sqlitePragma(Parse*,Token*,Token*,int);
|
||||
void sqliteResetInternalSchema(sqlite*, int);
|
||||
void sqliteBeginParse(Parse*,int);
|
||||
void sqliteRollbackInternalChanges(sqlite*);
|
||||
void sqliteCommitInternalChanges(sqlite*);
|
||||
Table *sqliteResultSetOfSelect(Parse*,char*,Select*);
|
||||
void sqliteOpenMasterTable(Vdbe *v, int);
|
||||
void sqliteStartTable(Parse*,Token*,Token*,int,int);
|
||||
void sqliteAddColumn(Parse*,Token*);
|
||||
void sqliteAddNotNull(Parse*, int);
|
||||
void sqliteAddPrimaryKey(Parse*, IdList*, int);
|
||||
void sqliteAddColumnType(Parse*,Token*,Token*);
|
||||
void sqliteAddDefaultValue(Parse*,Token*,int);
|
||||
int sqliteCollateType(const char*, int);
|
||||
void sqliteAddCollateType(Parse*, int);
|
||||
void sqliteEndTable(Parse*,Token*,Select*);
|
||||
void sqliteCreateView(Parse*,Token*,Token*,Select*,int);
|
||||
int sqliteViewGetColumnNames(Parse*,Table*);
|
||||
void sqliteDropTable(Parse*, Token*, int);
|
||||
void sqliteDeleteTable(sqlite*, Table*);
|
||||
void sqliteInsert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
|
||||
IdList *sqliteIdListAppend(IdList*, Token*);
|
||||
int sqliteIdListIndex(IdList*,const char*);
|
||||
SrcList *sqliteSrcListAppend(SrcList*, Token*, Token*);
|
||||
void sqliteSrcListAddAlias(SrcList*, Token*);
|
||||
void sqliteSrcListAssignCursors(Parse*, SrcList*);
|
||||
void sqliteIdListDelete(IdList*);
|
||||
void sqliteSrcListDelete(SrcList*);
|
||||
void sqliteCreateIndex(Parse*,Token*,SrcList*,IdList*,int,Token*,Token*);
|
||||
void sqliteDropIndex(Parse*, SrcList*);
|
||||
void sqliteAddKeyType(Vdbe*, ExprList*);
|
||||
void sqliteAddIdxKeyType(Vdbe*, Index*);
|
||||
int sqliteSelect(Parse*, Select*, int, int, Select*, int, int*);
|
||||
Select *sqliteSelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*,
|
||||
int,int,int);
|
||||
void sqlite3SelectDelete(Select*);
|
||||
void sqlite3SelectUnbind(Select*);
|
||||
Table *sqlite3SrcListLookup(Parse*, SrcList*);
|
||||
int sqlite3IsReadOnly(Parse*, Table*, int);
|
||||
void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
|
||||
void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
|
||||
WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, int, ExprList**);
|
||||
void sqlite3WhereEnd(WhereInfo*);
|
||||
void sqlite3ExprCode(Parse*, Expr*);
|
||||
int sqlite3ExprCodeExprList(Parse*, ExprList*);
|
||||
void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
|
||||
void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
|
||||
Table *sqlite3FindTable(sqlite*,const char*, const char*);
|
||||
Table *sqlite3LocateTable(Parse*,const char*, const char*);
|
||||
Index *sqlite3FindIndex(sqlite*,const char*, const char*);
|
||||
void sqlite3UnlinkAndDeleteIndex(sqlite*,Index*);
|
||||
void sqlite3Vacuum(Parse*, Token*);
|
||||
int sqlite3RunVacuum(char**, sqlite*);
|
||||
int sqlite3GlobCompare(const unsigned char*,const unsigned char*);
|
||||
char *sqlite3TableNameFromToken(Token*);
|
||||
int sqlite3ExprCheck(Parse*, Expr*, int, int*);
|
||||
int sqlite3ExprType(Expr*);
|
||||
int sqlite3ExprCompare(Expr*, Expr*);
|
||||
void sqliteSelectDelete(Select*);
|
||||
void sqliteSelectUnbind(Select*);
|
||||
Table *sqliteSrcListLookup(Parse*, SrcList*);
|
||||
int sqliteIsReadOnly(Parse*, Table*, int);
|
||||
void sqliteDeleteFrom(Parse*, SrcList*, Expr*);
|
||||
void sqliteUpdate(Parse*, SrcList*, ExprList*, Expr*, int);
|
||||
WhereInfo *sqliteWhereBegin(Parse*, SrcList*, Expr*, int, ExprList**);
|
||||
void sqliteWhereEnd(WhereInfo*);
|
||||
void sqliteExprCode(Parse*, Expr*);
|
||||
int sqliteExprCodeExprList(Parse*, ExprList*, int);
|
||||
void sqliteExprIfTrue(Parse*, Expr*, int, int);
|
||||
void sqliteExprIfFalse(Parse*, Expr*, int, int);
|
||||
Table *sqliteFindTable(sqlite*,const char*, const char*);
|
||||
Table *sqliteLocateTable(Parse*,const char*, const char*);
|
||||
Index *sqliteFindIndex(sqlite*,const char*, const char*);
|
||||
void sqliteUnlinkAndDeleteIndex(sqlite*,Index*);
|
||||
void sqliteCopy(Parse*, SrcList*, Token*, Token*, int);
|
||||
void sqliteVacuum(Parse*, Token*);
|
||||
int sqliteRunVacuum(char**, sqlite*);
|
||||
int sqliteGlobCompare(const unsigned char*,const unsigned char*);
|
||||
int sqliteLikeCompare(const unsigned char*,const unsigned char*);
|
||||
char *sqliteTableNameFromToken(Token*);
|
||||
int sqliteExprCheck(Parse*, Expr*, int, int*);
|
||||
int sqliteExprType(Expr*);
|
||||
int sqliteExprCompare(Expr*, Expr*);
|
||||
int sqliteFuncId(Token*);
|
||||
int sqlite3ExprResolveIds(Parse*, SrcList*, ExprList*, Expr*);
|
||||
int sqlite3ExprAnalyzeAggregates(Parse*, Expr*);
|
||||
Vdbe *sqlite3GetVdbe(Parse*);
|
||||
void sqlite3Randomness(int, void*);
|
||||
void sqlite3RollbackAll(sqlite*);
|
||||
void sqlite3CodeVerifySchema(Parse*, int);
|
||||
void sqlite3BeginTransaction(Parse*);
|
||||
void sqlite3CommitTransaction(Parse*);
|
||||
void sqlite3RollbackTransaction(Parse*);
|
||||
int sqlite3ExprIsConstant(Expr*);
|
||||
int sqlite3ExprIsInteger(Expr*, int*);
|
||||
int sqlite3IsRowid(const char*);
|
||||
void sqlite3GenerateRowDelete(sqlite*, Vdbe*, Table*, int, int);
|
||||
void sqlite3GenerateRowIndexDelete(sqlite*, Vdbe*, Table*, int, char*);
|
||||
void sqlite3GenerateIndexKey(Vdbe*, Index*, int);
|
||||
void sqlite3GenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
|
||||
void sqlite3CompleteInsertion(Parse*, Table*, int, char*, int, int, int);
|
||||
int sqlite3OpenTableAndIndices(Parse*, Table*, int);
|
||||
void sqlite3BeginWriteOperation(Parse*, int, int);
|
||||
void sqlite3EndWriteOperation(Parse*);
|
||||
Expr *sqlite3ExprDup(Expr*);
|
||||
void sqlite3TokenCopy(Token*, Token*);
|
||||
ExprList *sqlite3ExprListDup(ExprList*);
|
||||
SrcList *sqlite3SrcListDup(SrcList*);
|
||||
IdList *sqlite3IdListDup(IdList*);
|
||||
Select *sqlite3SelectDup(Select*);
|
||||
FuncDef *sqlite3FindFunction(sqlite*,const char*,int,int,u8,int);
|
||||
void sqlite3RegisterBuiltinFunctions(sqlite*);
|
||||
void sqlite3RegisterDateTimeFunctions(sqlite*);
|
||||
int sqlite3SafetyOn(sqlite*);
|
||||
int sqlite3SafetyOff(sqlite*);
|
||||
int sqlite3SafetyCheck(sqlite*);
|
||||
void sqlite3ChangeCookie(sqlite*, Vdbe*, int);
|
||||
void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
|
||||
int,Expr*,int);
|
||||
void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
|
||||
void sqlite3DropTrigger(Parse*, SrcList*);
|
||||
void sqlite3DropTriggerPtr(Parse*, Trigger*, int);
|
||||
int sqlite3TriggersExist(Parse* , Trigger* , int , int , int, ExprList*);
|
||||
int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int,
|
||||
int sqliteExprResolveIds(Parse*, SrcList*, ExprList*, Expr*);
|
||||
int sqliteExprAnalyzeAggregates(Parse*, Expr*);
|
||||
Vdbe *sqliteGetVdbe(Parse*);
|
||||
void sqliteRandomness(int, void*);
|
||||
void sqliteRollbackAll(sqlite*);
|
||||
void sqliteCodeVerifySchema(Parse*, int);
|
||||
void sqliteBeginTransaction(Parse*, int);
|
||||
void sqliteCommitTransaction(Parse*);
|
||||
void sqliteRollbackTransaction(Parse*);
|
||||
int sqliteExprIsConstant(Expr*);
|
||||
int sqliteExprIsInteger(Expr*, int*);
|
||||
int sqliteIsRowid(const char*);
|
||||
void sqliteGenerateRowDelete(sqlite*, Vdbe*, Table*, int, int);
|
||||
void sqliteGenerateRowIndexDelete(sqlite*, Vdbe*, Table*, int, char*);
|
||||
void sqliteGenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
|
||||
void sqliteCompleteInsertion(Parse*, Table*, int, char*, int, int, int);
|
||||
int sqliteOpenTableAndIndices(Parse*, Table*, int);
|
||||
void sqliteBeginWriteOperation(Parse*, int, int);
|
||||
void sqliteEndWriteOperation(Parse*);
|
||||
Expr *sqliteExprDup(Expr*);
|
||||
void sqliteTokenCopy(Token*, Token*);
|
||||
ExprList *sqliteExprListDup(ExprList*);
|
||||
SrcList *sqliteSrcListDup(SrcList*);
|
||||
IdList *sqliteIdListDup(IdList*);
|
||||
Select *sqliteSelectDup(Select*);
|
||||
FuncDef *sqliteFindFunction(sqlite*,const char*,int,int,int);
|
||||
void sqliteRegisterBuiltinFunctions(sqlite*);
|
||||
void sqliteRegisterDateTimeFunctions(sqlite*);
|
||||
int sqliteSafetyOn(sqlite*);
|
||||
int sqliteSafetyOff(sqlite*);
|
||||
int sqliteSafetyCheck(sqlite*);
|
||||
void sqliteChangeCookie(sqlite*, Vdbe*);
|
||||
void sqliteBeginTrigger(Parse*, Token*,int,int,IdList*,SrcList*,int,Expr*,int);
|
||||
void sqliteFinishTrigger(Parse*, TriggerStep*, Token*);
|
||||
void sqliteDropTrigger(Parse*, SrcList*);
|
||||
void sqliteDropTriggerPtr(Parse*, Trigger*, int);
|
||||
int sqliteTriggersExist(Parse* , Trigger* , int , int , int, ExprList*);
|
||||
int sqliteCodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int,
|
||||
int, int);
|
||||
void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
|
||||
void sqlite3DeleteTriggerStep(TriggerStep*);
|
||||
TriggerStep *sqlite3TriggerSelectStep(Select*);
|
||||
TriggerStep *sqlite3TriggerInsertStep(Token*, IdList*, ExprList*, Select*, int);
|
||||
TriggerStep *sqlite3TriggerUpdateStep(Token*, ExprList*, Expr*, int);
|
||||
TriggerStep *sqlite3TriggerDeleteStep(Token*, Expr*);
|
||||
void sqlite3DeleteTrigger(Trigger*);
|
||||
int sqlite3JoinType(Parse*, Token*, Token*, Token*);
|
||||
void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
|
||||
void sqlite3DeferForeignKey(Parse*, int);
|
||||
void sqliteDeleteTriggerStep(TriggerStep*);
|
||||
TriggerStep *sqliteTriggerSelectStep(Select*);
|
||||
TriggerStep *sqliteTriggerInsertStep(Token*, IdList*, ExprList*, Select*, int);
|
||||
TriggerStep *sqliteTriggerUpdateStep(Token*, ExprList*, Expr*, int);
|
||||
TriggerStep *sqliteTriggerDeleteStep(Token*, Expr*);
|
||||
void sqliteDeleteTrigger(Trigger*);
|
||||
int sqliteJoinType(Parse*, Token*, Token*, Token*);
|
||||
void sqliteCreateForeignKey(Parse*, IdList*, Token*, IdList*, int);
|
||||
void sqliteDeferForeignKey(Parse*, int);
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
void sqlite3AuthRead(Parse*,Expr*,SrcList*);
|
||||
int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*);
|
||||
void sqlite3AuthContextPush(Parse*, AuthContext*, const char*);
|
||||
void sqlite3AuthContextPop(AuthContext*);
|
||||
void sqliteAuthRead(Parse*,Expr*,SrcList*);
|
||||
int sqliteAuthCheck(Parse*,int, const char*, const char*, const char*);
|
||||
void sqliteAuthContextPush(Parse*, AuthContext*, const char*);
|
||||
void sqliteAuthContextPop(AuthContext*);
|
||||
#else
|
||||
# define sqlite3AuthRead(a,b,c)
|
||||
# define sqlite3AuthCheck(a,b,c,d,e) SQLITE_OK
|
||||
# define sqlite3AuthContextPush(a,b,c)
|
||||
# define sqlite3AuthContextPop(a) ((void)(a))
|
||||
# define sqliteAuthRead(a,b,c)
|
||||
# define sqliteAuthCheck(a,b,c,d,e) SQLITE_OK
|
||||
# define sqliteAuthContextPush(a,b,c)
|
||||
# define sqliteAuthContextPop(a) ((void)(a))
|
||||
#endif
|
||||
void sqlite3Attach(Parse*, Token*, Token*, Token*);
|
||||
void sqlite3Detach(Parse*, Token*);
|
||||
int sqlite3BtreeFactory(const sqlite *db, const char *zFilename,
|
||||
void sqliteAttach(Parse*, Token*, Token*, Token*);
|
||||
void sqliteDetach(Parse*, Token*);
|
||||
int sqliteBtreeFactory(const sqlite *db, const char *zFilename,
|
||||
int mode, int nPg, Btree **ppBtree);
|
||||
int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
|
||||
int sqlite3FixSrcList(DbFixer*, SrcList*);
|
||||
int sqlite3FixSelect(DbFixer*, Select*);
|
||||
int sqlite3FixExpr(DbFixer*, Expr*);
|
||||
int sqlite3FixExprList(DbFixer*, ExprList*);
|
||||
int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
|
||||
double sqlite3AtoF(const char *z, const char **);
|
||||
char *sqlite3_snprintf(int,char*,const char*,...);
|
||||
int sqlite3GetInt32(const char *, int*);
|
||||
int sqlite3GetInt64(const char *, i64*);
|
||||
int sqlite3FitsIn64Bits(const char *);
|
||||
int sqlite3utf16ByteLen(const void *pData, int nChar);
|
||||
int sqlite3utf8CharLen(const char *pData, int nByte);
|
||||
int sqlite3utf8LikeCompare(const unsigned char*, const unsigned char*);
|
||||
int sqlite3PutVarint(unsigned char *, u64);
|
||||
int sqlite3GetVarint(const unsigned char *, u64 *);
|
||||
int sqlite3GetVarint32(const unsigned char *, u32 *);
|
||||
int sqlite3VarintLen(u64 v);
|
||||
char sqlite3AffinityType(const char *, int);
|
||||
void sqlite3IndexAffinityStr(Vdbe *, Index *);
|
||||
void sqlite3TableAffinityStr(Vdbe *, Table *);
|
||||
char sqlite3CompareAffinity(Expr *pExpr, char aff2);
|
||||
char const *sqlite3AffinityString(char affinity);
|
||||
int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
|
||||
char sqlite3ExprAffinity(Expr *pExpr);
|
||||
int sqlite3atoi64(const char*, i64*);
|
||||
void sqlite3Error(sqlite *, int, const char*,...);
|
||||
void *sqlite3HexToBlob(const char *z);
|
||||
int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
|
||||
const char *sqlite3ErrStr(int);
|
||||
int sqlite3ReadUniChar(const char *zStr, int *pOffset, u8 *pEnc, int fold);
|
||||
int sqlite3ReadSchema(sqlite *db, char **);
|
||||
CollSeq *sqlite3FindCollSeq(sqlite *,u8 enc, const char *,int,int);
|
||||
CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName);
|
||||
CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
|
||||
int sqlite3CheckCollSeq(Parse *, CollSeq *);
|
||||
int sqlite3CheckIndexCollSeq(Parse *, Index *);
|
||||
int sqlite3CheckObjectName(Parse *, const char *);
|
||||
|
||||
const void *sqlite3ValueText(sqlite3_value*, u8);
|
||||
int sqlite3ValueBytes(sqlite3_value*, u8);
|
||||
void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
|
||||
void sqlite3ValueFree(sqlite3_value*);
|
||||
sqlite3_value *sqlite3ValueNew();
|
||||
sqlite3_value *sqlite3GetTransientValue(sqlite *db);
|
||||
int sqliteFixInit(DbFixer*, Parse*, int, const char*, const Token*);
|
||||
int sqliteFixSrcList(DbFixer*, SrcList*);
|
||||
int sqliteFixSelect(DbFixer*, Select*);
|
||||
int sqliteFixExpr(DbFixer*, Expr*);
|
||||
int sqliteFixExprList(DbFixer*, ExprList*);
|
||||
int sqliteFixTriggerStep(DbFixer*, TriggerStep*);
|
||||
double sqliteAtoF(const char *z, const char **);
|
||||
char *sqlite_snprintf(int,char*,const char*,...);
|
||||
int sqliteFitsIn32Bits(const char *);
|
||||
|
||||
+16
-19
@@ -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;
|
||||
@@ -84,8 +84,8 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
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;
|
||||
@@ -119,10 +119,10 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
**
|
||||
** 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 */
|
||||
@@ -148,17 +148,17 @@ int sqlite3_get_table(
|
||||
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);
|
||||
}
|
||||
@@ -167,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;
|
||||
@@ -187,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;
|
||||
@@ -201,6 +201,3 @@ void sqlite3_free_table(
|
||||
free(azResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+283
-257
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** A TCL Interface to SQLite
|
||||
**
|
||||
** $Id: tclsqlite.c,v 1.86 2004/06/14 11:43:46 danielk1977 Exp $
|
||||
** $Id: tclsqlite.c,v 1.59 2004/02/25 22:51:06 rdc Exp $
|
||||
*/
|
||||
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
|
||||
|
||||
@@ -42,17 +42,6 @@ struct SqlFunc {
|
||||
SqlFunc *pNext; /* Next function on the list of them all */
|
||||
};
|
||||
|
||||
/*
|
||||
** New collation sequences function can be created as TCL scripts. Each such
|
||||
** function is described by an instance of the following structure.
|
||||
*/
|
||||
typedef struct SqlCollate SqlCollate;
|
||||
struct SqlCollate {
|
||||
Tcl_Interp *interp; /* The TCL interpret to execute the function */
|
||||
char *zScript; /* The script to be run */
|
||||
SqlCollate *pNext; /* Next function on the list of them all */
|
||||
};
|
||||
|
||||
/*
|
||||
** There is one instance of this structure for each SQLite database
|
||||
** that has been opened by the SQLite TCL interface.
|
||||
@@ -67,10 +56,7 @@ struct SqliteDb {
|
||||
char *zProgress; /* The progress callback routine */
|
||||
char *zAuth; /* The authorization callback routine */
|
||||
SqlFunc *pFunc; /* List of SQL functions */
|
||||
SqlCollate *pCollate; /* List of SQL collation functions */
|
||||
int rc; /* Return code of most recent sqlite3_exec() */
|
||||
int nChange; /* Database changes for the most recent eval */
|
||||
Tcl_Obj *pCollateNeeded; /* Collation needed script */
|
||||
int rc; /* Return code of most recent sqlite_exec() */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -88,6 +74,182 @@ struct CallbackData {
|
||||
char **azColName; /* Column names translated to UTF-8 */
|
||||
};
|
||||
|
||||
#ifdef UTF_TRANSLATION_NEEDED
|
||||
/*
|
||||
** Called for each row of the result.
|
||||
**
|
||||
** This version is used when TCL expects UTF-8 data but the database
|
||||
** uses the ISO8859 format. A translation must occur from ISO8859 into
|
||||
** UTF-8.
|
||||
*/
|
||||
static int DbEvalCallback(
|
||||
void *clientData, /* An instance of CallbackData */
|
||||
int nCol, /* Number of columns in the result */
|
||||
char ** azCol, /* Data for each column */
|
||||
char ** azN /* Name for each column */
|
||||
){
|
||||
CallbackData *cbData = (CallbackData*)clientData;
|
||||
int i, rc;
|
||||
Tcl_DString dCol;
|
||||
Tcl_DStringInit(&dCol);
|
||||
if( cbData->azColName==0 ){
|
||||
assert( cbData->once );
|
||||
cbData->once = 0;
|
||||
if( cbData->zArray[0] ){
|
||||
Tcl_SetVar2(cbData->interp, cbData->zArray, "*", "", 0);
|
||||
}
|
||||
cbData->azColName = malloc( nCol*sizeof(char*) );
|
||||
if( cbData->azColName==0 ){ return 1; }
|
||||
cbData->nColName = nCol;
|
||||
for(i=0; i<nCol; i++){
|
||||
Tcl_ExternalToUtfDString(NULL, azN[i], -1, &dCol);
|
||||
cbData->azColName[i] = malloc( Tcl_DStringLength(&dCol) + 1 );
|
||||
if( cbData->azColName[i] ){
|
||||
strcpy(cbData->azColName[i], Tcl_DStringValue(&dCol));
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
if( cbData->zArray[0] ){
|
||||
Tcl_SetVar2(cbData->interp, cbData->zArray, "*",
|
||||
Tcl_DStringValue(&dCol), TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
|
||||
if( azN[nCol]!=0 ){
|
||||
Tcl_DString dType;
|
||||
Tcl_DStringInit(&dType);
|
||||
Tcl_DStringAppend(&dType, "typeof:", -1);
|
||||
Tcl_DStringAppend(&dType, Tcl_DStringValue(&dCol), -1);
|
||||
Tcl_DStringFree(&dCol);
|
||||
Tcl_ExternalToUtfDString(NULL, azN[i+nCol], -1, &dCol);
|
||||
Tcl_SetVar2(cbData->interp, cbData->zArray,
|
||||
Tcl_DStringValue(&dType), Tcl_DStringValue(&dCol),
|
||||
TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
|
||||
Tcl_DStringFree(&dType);
|
||||
}
|
||||
}
|
||||
|
||||
Tcl_DStringFree(&dCol);
|
||||
}
|
||||
}
|
||||
if( azCol!=0 ){
|
||||
if( cbData->zArray[0] ){
|
||||
for(i=0; i<nCol; i++){
|
||||
char *z = azCol[i];
|
||||
if( z==0 ) z = "";
|
||||
Tcl_DStringInit(&dCol);
|
||||
Tcl_ExternalToUtfDString(NULL, z, -1, &dCol);
|
||||
Tcl_SetVar2(cbData->interp, cbData->zArray, cbData->azColName[i],
|
||||
Tcl_DStringValue(&dCol), 0);
|
||||
Tcl_DStringFree(&dCol);
|
||||
}
|
||||
}else{
|
||||
for(i=0; i<nCol; i++){
|
||||
char *z = azCol[i];
|
||||
if( z==0 ) z = "";
|
||||
Tcl_DStringInit(&dCol);
|
||||
Tcl_ExternalToUtfDString(NULL, z, -1, &dCol);
|
||||
Tcl_SetVar(cbData->interp, cbData->azColName[i],
|
||||
Tcl_DStringValue(&dCol), 0);
|
||||
Tcl_DStringFree(&dCol);
|
||||
}
|
||||
}
|
||||
}
|
||||
rc = Tcl_EvalObj(cbData->interp, cbData->pCode);
|
||||
if( rc==TCL_CONTINUE ) rc = TCL_OK;
|
||||
cbData->tcl_rc = rc;
|
||||
return rc!=TCL_OK;
|
||||
}
|
||||
#endif /* UTF_TRANSLATION_NEEDED */
|
||||
|
||||
#ifndef UTF_TRANSLATION_NEEDED
|
||||
/*
|
||||
** Called for each row of the result.
|
||||
**
|
||||
** This version is used when either of the following is true:
|
||||
**
|
||||
** (1) This version of TCL uses UTF-8 and the data in the
|
||||
** SQLite database is already in the UTF-8 format.
|
||||
**
|
||||
** (2) This version of TCL uses ISO8859 and the data in the
|
||||
** SQLite database is already in the ISO8859 format.
|
||||
*/
|
||||
static int DbEvalCallback(
|
||||
void *clientData, /* An instance of CallbackData */
|
||||
int nCol, /* Number of columns in the result */
|
||||
char ** azCol, /* Data for each column */
|
||||
char ** azN /* Name for each column */
|
||||
){
|
||||
CallbackData *cbData = (CallbackData*)clientData;
|
||||
int i, rc;
|
||||
if( azCol==0 || (cbData->once && cbData->zArray[0]) ){
|
||||
Tcl_SetVar2(cbData->interp, cbData->zArray, "*", "", 0);
|
||||
for(i=0; i<nCol; i++){
|
||||
Tcl_SetVar2(cbData->interp, cbData->zArray, "*", azN[i],
|
||||
TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
|
||||
if( azN[nCol] ){
|
||||
char *z = sqlite_mprintf("typeof:%s", azN[i]);
|
||||
Tcl_SetVar2(cbData->interp, cbData->zArray, z, azN[i+nCol],
|
||||
TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
|
||||
sqlite_freemem(z);
|
||||
}
|
||||
}
|
||||
cbData->once = 0;
|
||||
}
|
||||
if( azCol!=0 ){
|
||||
if( cbData->zArray[0] ){
|
||||
for(i=0; i<nCol; i++){
|
||||
char *z = azCol[i];
|
||||
if( z==0 ) z = "";
|
||||
Tcl_SetVar2(cbData->interp, cbData->zArray, azN[i], z, 0);
|
||||
}
|
||||
}else{
|
||||
for(i=0; i<nCol; i++){
|
||||
char *z = azCol[i];
|
||||
if( z==0 ) z = "";
|
||||
Tcl_SetVar(cbData->interp, azN[i], z, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
rc = Tcl_EvalObj(cbData->interp, cbData->pCode);
|
||||
if( rc==TCL_CONTINUE ) rc = TCL_OK;
|
||||
cbData->tcl_rc = rc;
|
||||
return rc!=TCL_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This is an alternative callback for database queries. Instead
|
||||
** of invoking a TCL script to handle the result, this callback just
|
||||
** appends each column of the result to a list. After the query
|
||||
** is complete, the list is returned.
|
||||
*/
|
||||
static int DbEvalCallback2(
|
||||
void *clientData, /* An instance of CallbackData */
|
||||
int nCol, /* Number of columns in the result */
|
||||
char ** azCol, /* Data for each column */
|
||||
char ** azN /* Name for each column */
|
||||
){
|
||||
Tcl_Obj *pList = (Tcl_Obj*)clientData;
|
||||
int i;
|
||||
if( azCol==0 ) return 0;
|
||||
for(i=0; i<nCol; i++){
|
||||
Tcl_Obj *pElem;
|
||||
if( azCol[i] && *azCol[i] ){
|
||||
#ifdef UTF_TRANSLATION_NEEDED
|
||||
Tcl_DString dCol;
|
||||
Tcl_DStringInit(&dCol);
|
||||
Tcl_ExternalToUtfDString(NULL, azCol[i], -1, &dCol);
|
||||
pElem = Tcl_NewStringObj(Tcl_DStringValue(&dCol), -1);
|
||||
Tcl_DStringFree(&dCol);
|
||||
#else
|
||||
pElem = Tcl_NewStringObj(azCol[i], -1);
|
||||
#endif
|
||||
}else{
|
||||
pElem = Tcl_NewObj();
|
||||
}
|
||||
Tcl_ListObjAppendElement(0, pList, pElem);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a second alternative callback for database queries. A the
|
||||
** first column of the first row of the result is made the TCL result.
|
||||
@@ -122,17 +284,12 @@ static int DbEvalCallback3(
|
||||
*/
|
||||
static void DbDeleteCmd(void *db){
|
||||
SqliteDb *pDb = (SqliteDb*)db;
|
||||
sqlite3_close(pDb->db);
|
||||
sqlite_close(pDb->db);
|
||||
while( pDb->pFunc ){
|
||||
SqlFunc *pFunc = pDb->pFunc;
|
||||
pDb->pFunc = pFunc->pNext;
|
||||
Tcl_Free((char*)pFunc);
|
||||
}
|
||||
while( pDb->pCollate ){
|
||||
SqlCollate *pCollate = pDb->pCollate;
|
||||
pDb->pCollate = pCollate->pNext;
|
||||
Tcl_Free((char*)pCollate);
|
||||
}
|
||||
if( pDb->zBusy ){
|
||||
Tcl_Free(pDb->zBusy);
|
||||
}
|
||||
@@ -149,7 +306,7 @@ static void DbDeleteCmd(void *db){
|
||||
** This routine is called when a database file is locked while trying
|
||||
** to execute SQL.
|
||||
*/
|
||||
static int DbBusyHandler(void *cd, int nTries){
|
||||
static int DbBusyHandler(void *cd, const char *zTable, int nTries){
|
||||
SqliteDb *pDb = (SqliteDb*)cd;
|
||||
int rc;
|
||||
char zVal[30];
|
||||
@@ -158,8 +315,9 @@ static int DbBusyHandler(void *cd, int nTries){
|
||||
|
||||
Tcl_DStringInit(&cmd);
|
||||
Tcl_DStringAppend(&cmd, pDb->zBusy, -1);
|
||||
sprintf(zVal, "%d", nTries);
|
||||
Tcl_DStringAppendElement(&cmd, zVal);
|
||||
Tcl_DStringAppendElement(&cmd, zTable);
|
||||
sprintf(zVal, " %d", nTries);
|
||||
Tcl_DStringAppend(&cmd, zVal, -1);
|
||||
zCmd = Tcl_DStringValue(&cmd);
|
||||
rc = Tcl_Eval(pDb->interp, zCmd);
|
||||
Tcl_DStringFree(&cmd);
|
||||
@@ -217,49 +375,12 @@ static int DbCommitHandler(void *cd){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tclCollateNeeded(
|
||||
void *pCtx,
|
||||
sqlite *db,
|
||||
int enc,
|
||||
const char *zName
|
||||
){
|
||||
SqliteDb *pDb = (SqliteDb *)pCtx;
|
||||
Tcl_Obj *pScript = Tcl_DuplicateObj(pDb->pCollateNeeded);
|
||||
Tcl_IncrRefCount(pScript);
|
||||
Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj(zName, -1));
|
||||
Tcl_EvalObjEx(pDb->interp, pScript, 0);
|
||||
Tcl_DecrRefCount(pScript);
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called to evaluate an SQL collation function implemented
|
||||
** using TCL script.
|
||||
*/
|
||||
static int tclSqlCollate(
|
||||
void *pCtx,
|
||||
int nA,
|
||||
const void *zA,
|
||||
int nB,
|
||||
const void *zB
|
||||
){
|
||||
SqlCollate *p = (SqlCollate *)pCtx;
|
||||
Tcl_Obj *pCmd;
|
||||
|
||||
pCmd = Tcl_NewStringObj(p->zScript, -1);
|
||||
Tcl_IncrRefCount(pCmd);
|
||||
Tcl_ListObjAppendElement(p->interp, pCmd, Tcl_NewStringObj(zA, nA));
|
||||
Tcl_ListObjAppendElement(p->interp, pCmd, Tcl_NewStringObj(zB, nB));
|
||||
Tcl_EvalObjEx(p->interp, pCmd, 0);
|
||||
Tcl_DecrRefCount(pCmd);
|
||||
return (atoi(Tcl_GetStringResult(p->interp)));
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called to evaluate an SQL function implemented
|
||||
** using TCL script.
|
||||
*/
|
||||
static void tclSqlFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
SqlFunc *p = sqlite3_user_data(context);
|
||||
static void tclSqlFunc(sqlite_func *context, int argc, const char **argv){
|
||||
SqlFunc *p = sqlite_user_data(context);
|
||||
Tcl_DString cmd;
|
||||
int i;
|
||||
int rc;
|
||||
@@ -267,18 +388,13 @@ static void tclSqlFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
|
||||
Tcl_DStringInit(&cmd);
|
||||
Tcl_DStringAppend(&cmd, p->zScript, -1);
|
||||
for(i=0; i<argc; i++){
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[i]) ){
|
||||
Tcl_DStringAppendElement(&cmd, "");
|
||||
}else{
|
||||
Tcl_DStringAppendElement(&cmd, sqlite3_value_text(argv[i]));
|
||||
}
|
||||
Tcl_DStringAppendElement(&cmd, argv[i] ? argv[i] : "");
|
||||
}
|
||||
rc = Tcl_Eval(p->interp, Tcl_DStringValue(&cmd));
|
||||
if( rc ){
|
||||
sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1);
|
||||
sqlite_set_result_error(context, Tcl_GetStringResult(p->interp), -1);
|
||||
}else{
|
||||
sqlite3_result_text(context, Tcl_GetStringResult(p->interp), -1,
|
||||
SQLITE_TRANSIENT);
|
||||
sqlite_set_result_string(context, Tcl_GetStringResult(p->interp), -1);
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
@@ -354,26 +470,6 @@ static int auth_callback(
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
/*
|
||||
** zText is a pointer to text obtained via an sqlite3_result_text()
|
||||
** or similar interface. This routine returns a Tcl string object,
|
||||
** reference count set to 0, containing the text. If a translation
|
||||
** between iso8859 and UTF-8 is required, it is preformed.
|
||||
*/
|
||||
static Tcl_Obj *dbTextToObj(char const *zText){
|
||||
Tcl_Obj *pVal;
|
||||
#ifdef UTF_TRANSLATION_NEEDED
|
||||
Tcl_DString dCol;
|
||||
Tcl_DStringInit(&dCol);
|
||||
Tcl_ExternalToUtfDString(NULL, zText, -1, &dCol);
|
||||
pVal = Tcl_NewStringObj(Tcl_DStringValue(&dCol), -1);
|
||||
Tcl_DStringFree(&dCol);
|
||||
#else
|
||||
pVal = Tcl_NewStringObj(zText, -1);
|
||||
#endif
|
||||
return pVal;
|
||||
}
|
||||
|
||||
/*
|
||||
** The "sqlite" command below creates a new Tcl command for each
|
||||
** connection it opens to an SQLite database. This routine is invoked
|
||||
@@ -397,7 +493,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
"errorcode", "eval", "function",
|
||||
"last_insert_rowid", "last_statement_changes", "onecolumn",
|
||||
"progress", "rekey", "timeout",
|
||||
"trace", "collate", "collation_needed",
|
||||
"trace",
|
||||
0
|
||||
};
|
||||
enum DB_enum {
|
||||
@@ -406,7 +502,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
DB_ERRORCODE, DB_EVAL, DB_FUNCTION,
|
||||
DB_LAST_INSERT_ROWID, DB_LAST_STATEMENT_CHANGES, DB_ONECOLUMN,
|
||||
DB_PROGRESS, DB_REKEY, DB_TIMEOUT,
|
||||
DB_TRACE, DB_COLLATE, DB_COLLATION_NEEDED
|
||||
DB_TRACE
|
||||
};
|
||||
|
||||
if( objc<2 ){
|
||||
@@ -460,9 +556,9 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( pDb->zAuth ){
|
||||
pDb->interp = interp;
|
||||
sqlite3_set_authorizer(pDb->db, auth_callback, pDb);
|
||||
sqlite_set_authorizer(pDb->db, auth_callback, pDb);
|
||||
}else{
|
||||
sqlite3_set_authorizer(pDb->db, 0, 0);
|
||||
sqlite_set_authorizer(pDb->db, 0, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -497,9 +593,9 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
}
|
||||
if( pDb->zBusy ){
|
||||
pDb->interp = interp;
|
||||
sqlite3_busy_handler(pDb->db, DbBusyHandler, pDb);
|
||||
sqlite_busy_handler(pDb->db, DbBusyHandler, pDb);
|
||||
}else{
|
||||
sqlite3_busy_handler(pDb->db, 0, 0);
|
||||
sqlite_busy_handler(pDb->db, 0, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -535,9 +631,9 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
|
||||
if( pDb->zProgress ){
|
||||
pDb->interp = interp;
|
||||
sqlite3_progress_handler(pDb->db, N, DbProgressHandler, pDb);
|
||||
sqlite_progress_handler(pDb->db, N, DbProgressHandler, pDb);
|
||||
}else{
|
||||
sqlite3_progress_handler(pDb->db, 0, 0, 0);
|
||||
sqlite_progress_handler(pDb->db, 0, 0, 0);
|
||||
}
|
||||
#endif
|
||||
}else{
|
||||
@@ -560,8 +656,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
/* nChange = sqlite3_changes(pDb->db); */
|
||||
nChange = pDb->nChange;
|
||||
nChange = sqlite_changes(pDb->db);
|
||||
pResult = Tcl_GetObjResult(interp);
|
||||
Tcl_SetIntObj(pResult, nChange);
|
||||
break;
|
||||
@@ -581,7 +676,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
lsChange = sqlite3_last_statement_changes(pDb->db);
|
||||
lsChange = sqlite_last_statement_changes(pDb->db);
|
||||
pResult = Tcl_GetObjResult(interp);
|
||||
Tcl_SetIntObj(pResult, lsChange);
|
||||
break;
|
||||
@@ -625,9 +720,9 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
}
|
||||
if( pDb->zCommit ){
|
||||
pDb->interp = interp;
|
||||
sqlite3_commit_hook(pDb->db, DbCommitHandler, pDb);
|
||||
sqlite_commit_hook(pDb->db, DbCommitHandler, pDb);
|
||||
}else{
|
||||
sqlite3_commit_hook(pDb->db, 0, 0);
|
||||
sqlite_commit_hook(pDb->db, 0, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -646,7 +741,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "SQL");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
isComplete = sqlite3_complete( Tcl_GetStringFromObj(objv[2], 0) );
|
||||
isComplete = sqlite_complete( Tcl_GetStringFromObj(objv[2], 0) );
|
||||
pResult = Tcl_GetObjResult(interp);
|
||||
Tcl_SetBooleanObj(pResult, isComplete);
|
||||
break;
|
||||
@@ -656,10 +751,10 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
** $db errorcode
|
||||
**
|
||||
** Return the numeric error code that was returned by the most recent
|
||||
** call to sqlite3_exec().
|
||||
** call to sqlite_exec().
|
||||
*/
|
||||
case DB_ERRORCODE: {
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_errcode(pDb->db)));
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(pDb->rc));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -673,93 +768,72 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
** that have the same name as the fields extracted by the query.
|
||||
*/
|
||||
case DB_EVAL: {
|
||||
char const *zSql;
|
||||
char const *zLeft;
|
||||
sqlite3_stmt *pStmt;
|
||||
|
||||
Tcl_Obj *pRet = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pRet);
|
||||
CallbackData cbData;
|
||||
char *zErrMsg;
|
||||
char *zSql;
|
||||
#ifdef UTF_TRANSLATION_NEEDED
|
||||
Tcl_DString dSql;
|
||||
int i;
|
||||
#endif
|
||||
|
||||
if( objc!=5 && objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "SQL ?ARRAY-NAME CODE?");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
pDb->nChange = 0;
|
||||
pDb->interp = interp;
|
||||
zSql = Tcl_GetStringFromObj(objv[2], 0);
|
||||
while( zSql[0] ){
|
||||
int i;
|
||||
|
||||
if( SQLITE_OK!=sqlite3_prepare(pDb->db, zSql, -1, &pStmt, &zLeft) ){
|
||||
Tcl_SetObjResult(interp, dbTextToObj(sqlite3_errmsg(pDb->db)));
|
||||
rc = TCL_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
if( pStmt && objc==5 ){
|
||||
Tcl_Obj *pColList = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pColList);
|
||||
|
||||
for(i=0; i<sqlite3_column_count(pStmt); i++){
|
||||
Tcl_ListObjAppendElement(interp, pColList,
|
||||
dbTextToObj(sqlite3_column_name(pStmt, i))
|
||||
);
|
||||
}
|
||||
Tcl_ObjSetVar2(interp,objv[3],Tcl_NewStringObj("*",-1),pColList,0);
|
||||
}
|
||||
|
||||
while( pStmt && SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
for(i=0; i<sqlite3_column_count(pStmt); i++){
|
||||
Tcl_Obj *pVal;
|
||||
|
||||
/* Set pVal to contain the i'th column of this row. */
|
||||
if( SQLITE_BLOB!=sqlite3_column_type(pStmt, i) ){
|
||||
pVal = dbTextToObj(sqlite3_column_text(pStmt, i));
|
||||
}else{
|
||||
int bytes = sqlite3_column_bytes(pStmt, i);
|
||||
pVal = Tcl_NewByteArrayObj(sqlite3_column_blob(pStmt, i), bytes);
|
||||
}
|
||||
|
||||
if( objc==5 ){
|
||||
Tcl_Obj *pName = dbTextToObj(sqlite3_column_name(pStmt, i));
|
||||
Tcl_IncrRefCount(pName);
|
||||
if( !strcmp("", Tcl_GetString(objv[3])) ){
|
||||
Tcl_ObjSetVar2(interp, pName, 0, pVal, 0);
|
||||
}else{
|
||||
Tcl_ObjSetVar2(interp, objv[3], pName, pVal, 0);
|
||||
}
|
||||
Tcl_DecrRefCount(pName);
|
||||
}else{
|
||||
Tcl_ListObjAppendElement(interp, pRet, pVal);
|
||||
}
|
||||
}
|
||||
|
||||
if( objc==5 ){
|
||||
rc = Tcl_EvalObjEx(interp, objv[4], 0);
|
||||
if( rc!=TCL_ERROR ) rc = TCL_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if( pStmt && SQLITE_SCHEMA==sqlite3_finalize(pStmt) ){
|
||||
continue;
|
||||
}
|
||||
|
||||
if( pStmt && SQLITE_OK!=sqlite3_errcode(pDb->db) ){
|
||||
Tcl_SetObjResult(interp, dbTextToObj(sqlite3_errmsg(pDb->db)));
|
||||
rc = TCL_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
pDb->nChange += sqlite3_changes(pDb->db);
|
||||
zSql = zLeft;
|
||||
#ifdef UTF_TRANSLATION_NEEDED
|
||||
Tcl_DStringInit(&dSql);
|
||||
Tcl_UtfToExternalDString(NULL, zSql, -1, &dSql);
|
||||
zSql = Tcl_DStringValue(&dSql);
|
||||
#endif
|
||||
Tcl_IncrRefCount(objv[2]);
|
||||
if( objc==5 ){
|
||||
cbData.interp = interp;
|
||||
cbData.once = 1;
|
||||
cbData.zArray = Tcl_GetStringFromObj(objv[3], 0);
|
||||
cbData.pCode = objv[4];
|
||||
cbData.tcl_rc = TCL_OK;
|
||||
cbData.nColName = 0;
|
||||
cbData.azColName = 0;
|
||||
zErrMsg = 0;
|
||||
Tcl_IncrRefCount(objv[3]);
|
||||
Tcl_IncrRefCount(objv[4]);
|
||||
rc = sqlite_exec(pDb->db, zSql, DbEvalCallback, &cbData, &zErrMsg);
|
||||
Tcl_DecrRefCount(objv[4]);
|
||||
Tcl_DecrRefCount(objv[3]);
|
||||
if( cbData.tcl_rc==TCL_BREAK ){ cbData.tcl_rc = TCL_OK; }
|
||||
}else{
|
||||
Tcl_Obj *pList = Tcl_NewObj();
|
||||
cbData.tcl_rc = TCL_OK;
|
||||
rc = sqlite_exec(pDb->db, zSql, DbEvalCallback2, pList, &zErrMsg);
|
||||
Tcl_SetObjResult(interp, pList);
|
||||
}
|
||||
|
||||
if( rc==TCL_OK ){
|
||||
Tcl_SetObjResult(interp, pRet);
|
||||
pDb->rc = rc;
|
||||
if( rc==SQLITE_ABORT ){
|
||||
if( zErrMsg ) free(zErrMsg);
|
||||
rc = cbData.tcl_rc;
|
||||
}else if( zErrMsg ){
|
||||
Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
|
||||
free(zErrMsg);
|
||||
rc = TCL_ERROR;
|
||||
}else if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
|
||||
rc = TCL_ERROR;
|
||||
}else{
|
||||
}
|
||||
Tcl_DecrRefCount(pRet);
|
||||
|
||||
break;
|
||||
Tcl_DecrRefCount(objv[2]);
|
||||
#ifdef UTF_TRANSLATION_NEEDED
|
||||
Tcl_DStringFree(&dSql);
|
||||
if( objc==5 && cbData.azColName ){
|
||||
for(i=0; i<cbData.nColName; i++){
|
||||
if( cbData.azColName[i] ) free(cbData.azColName[i]);
|
||||
}
|
||||
free(cbData.azColName);
|
||||
cbData.azColName = 0;
|
||||
}
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -785,8 +859,8 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
pFunc->pNext = pDb->pFunc;
|
||||
pFunc->zScript = (char*)&pFunc[1];
|
||||
strcpy(pFunc->zScript, zScript);
|
||||
sqlite3_create_function(pDb->db, zName, -1, SQLITE_UTF8, 0,
|
||||
pFunc, tclSqlFunc, 0, 0);
|
||||
sqlite_create_function(pDb->db, zName, -1, tclSqlFunc, pFunc);
|
||||
sqlite_function_type(pDb->db, zName, SQLITE_NUMERIC);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -802,7 +876,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rowid = sqlite3_last_insert_rowid(pDb->db);
|
||||
rowid = sqlite_last_insert_rowid(pDb->db);
|
||||
pResult = Tcl_GetObjResult(interp);
|
||||
Tcl_SetIntObj(pResult, rowid);
|
||||
break;
|
||||
@@ -821,7 +895,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
zSql = Tcl_GetStringFromObj(objv[2], 0);
|
||||
rc = sqlite3_exec(pDb->db, zSql, DbEvalCallback3, interp, &zErrMsg);
|
||||
rc = sqlite_exec(pDb->db, zSql, DbEvalCallback3, interp, &zErrMsg);
|
||||
if( rc==SQLITE_ABORT ){
|
||||
rc = SQLITE_OK;
|
||||
}else if( zErrMsg ){
|
||||
@@ -829,7 +903,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
free(zErrMsg);
|
||||
rc = TCL_ERROR;
|
||||
}else if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, sqlite3ErrStr(rc), 0);
|
||||
Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
|
||||
rc = TCL_ERROR;
|
||||
}
|
||||
break;
|
||||
@@ -851,7 +925,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
#ifdef SQLITE_HAS_CODEC
|
||||
rc = sqlite_rekey(pDb->db, pKey, nKey);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, sqlite3ErrStr(rc), 0);
|
||||
Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
|
||||
rc = TCL_ERROR;
|
||||
}
|
||||
#endif
|
||||
@@ -870,7 +944,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &ms) ) return TCL_ERROR;
|
||||
sqlite3_busy_timeout(pDb->db, ms);
|
||||
sqlite_busy_timeout(pDb->db, ms);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -902,64 +976,14 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
}
|
||||
if( pDb->zTrace ){
|
||||
pDb->interp = interp;
|
||||
sqlite3_trace(pDb->db, DbTraceHandler, pDb);
|
||||
sqlite_trace(pDb->db, DbTraceHandler, pDb);
|
||||
}else{
|
||||
sqlite3_trace(pDb->db, 0, 0);
|
||||
sqlite_trace(pDb->db, 0, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** $db collate NAME SCRIPT
|
||||
**
|
||||
** Create a new SQL collation function called NAME. Whenever
|
||||
** that function is called, invoke SCRIPT to evaluate the function.
|
||||
*/
|
||||
case DB_COLLATE: {
|
||||
SqlCollate *pCollate;
|
||||
char *zName;
|
||||
char *zScript;
|
||||
int nScript;
|
||||
if( objc!=4 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "NAME SCRIPT");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
zName = Tcl_GetStringFromObj(objv[2], 0);
|
||||
zScript = Tcl_GetStringFromObj(objv[3], &nScript);
|
||||
pCollate = (SqlCollate*)Tcl_Alloc( sizeof(*pCollate) + nScript + 1 );
|
||||
if( pCollate==0 ) return TCL_ERROR;
|
||||
pCollate->interp = interp;
|
||||
pCollate->pNext = pDb->pCollate;
|
||||
pCollate->zScript = (char*)&pCollate[1];
|
||||
strcpy(pCollate->zScript, zScript);
|
||||
if( sqlite3_create_collation(pDb->db, zName, SQLITE_UTF8,
|
||||
pCollate, tclSqlCollate) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** $db collate_needed SCRIPT
|
||||
**
|
||||
** Create a new SQL collation function called NAME. Whenever
|
||||
** that function is called, invoke SCRIPT to evaluate the function.
|
||||
*/
|
||||
case DB_COLLATION_NEEDED: {
|
||||
if( objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "SCRIPT");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( pDb->pCollateNeeded ){
|
||||
Tcl_DecrRefCount(pDb->pCollateNeeded);
|
||||
}
|
||||
pDb->pCollateNeeded = Tcl_DuplicateObj(objv[2]);
|
||||
Tcl_IncrRefCount(pDb->pCollateNeeded);
|
||||
sqlite3_collation_needed(pDb->db, pDb, tclCollateNeeded);
|
||||
break;
|
||||
}
|
||||
|
||||
} /* End of the SWITCH statement */
|
||||
return rc;
|
||||
}
|
||||
@@ -996,6 +1020,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
** correctly.
|
||||
*/
|
||||
static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
int mode;
|
||||
SqliteDb *p;
|
||||
void *pKey = 0;
|
||||
int nKey = 0;
|
||||
@@ -1005,8 +1030,12 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
char zBuf[80];
|
||||
if( objc==2 ){
|
||||
zArg = Tcl_GetStringFromObj(objv[1], 0);
|
||||
if( strcmp(zArg,"-encoding")==0 ){
|
||||
Tcl_AppendResult(interp,sqlite_encoding,0);
|
||||
return TCL_OK;
|
||||
}
|
||||
if( strcmp(zArg,"-version")==0 ){
|
||||
Tcl_AppendResult(interp,sqlite3_version,0);
|
||||
Tcl_AppendResult(interp,sqlite_version,0);
|
||||
return TCL_OK;
|
||||
}
|
||||
if( strcmp(zArg,"-has-codec")==0 ){
|
||||
@@ -1043,6 +1072,11 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( objc==3 ){
|
||||
mode = 0666;
|
||||
}else if( Tcl_GetIntFromObj(interp, objv[3], &mode)!=TCL_OK ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
zErrMsg = 0;
|
||||
p = (SqliteDb*)Tcl_Alloc( sizeof(*p) );
|
||||
if( p==0 ){
|
||||
@@ -1052,14 +1086,9 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
memset(p, 0, sizeof(*p));
|
||||
zFile = Tcl_GetStringFromObj(objv[2], 0);
|
||||
#ifdef SQLITE_HAS_CODEC
|
||||
p->db = sqlite3_open_encrypted(zFile, pKey, nKey, 0, &zErrMsg);
|
||||
p->db = sqlite_open_encrypted(zFile, pKey, nKey, 0, &zErrMsg);
|
||||
#else
|
||||
sqlite3_open(zFile, &p->db);
|
||||
if( SQLITE_OK!=sqlite3_errcode(p->db) ){
|
||||
zErrMsg = strdup(sqlite3_errmsg(p->db));
|
||||
sqlite3_close(p->db);
|
||||
p->db = 0;
|
||||
}
|
||||
p->db = sqlite_open(zFile, mode, &zErrMsg);
|
||||
#endif
|
||||
if( p->db==0 ){
|
||||
Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
|
||||
@@ -1087,7 +1116,6 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
Md5_Register(p->db);
|
||||
}
|
||||
#endif
|
||||
p->interp = interp;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -1178,13 +1206,11 @@ int TCLSH_MAIN(int argc, char **argv){
|
||||
extern int Sqlitetest2_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest3_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest4_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest5_Init(Tcl_Interp*);
|
||||
extern int Md5_Init(Tcl_Interp*);
|
||||
Sqlitetest1_Init(interp);
|
||||
Sqlitetest2_Init(interp);
|
||||
Sqlitetest3_Init(interp);
|
||||
Sqlitetest4_Init(interp);
|
||||
Sqlitetest5_Init(interp);
|
||||
Md5_Init(interp);
|
||||
}
|
||||
#endif
|
||||
|
||||
+344
-1338
File diff suppressed because it is too large
Load Diff
+34
-30
@@ -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.22 2004/06/15 11:40:09 danielk1977 Exp $
|
||||
** $Id: test2.c,v 1.16 2004/02/10 01:54:28 drh Exp $
|
||||
*/
|
||||
#include "os.h"
|
||||
#include "sqliteInt.h"
|
||||
@@ -76,7 +76,7 @@ static int pager_open(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_open(&pPager, argv[1], nPage, 0, 1, 0);
|
||||
rc = sqlitepager_open(&pPager, argv[1], nPage, 0, 1);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -105,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;
|
||||
@@ -132,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;
|
||||
@@ -159,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;
|
||||
@@ -168,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 */
|
||||
@@ -186,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;
|
||||
@@ -195,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 */
|
||||
@@ -213,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;
|
||||
@@ -222,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 */
|
||||
@@ -240,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;
|
||||
@@ -267,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",
|
||||
@@ -300,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;
|
||||
}
|
||||
@@ -328,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;
|
||||
@@ -361,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);
|
||||
@@ -388,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;
|
||||
@@ -439,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;
|
||||
}
|
||||
@@ -463,7 +463,7 @@ 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;
|
||||
@@ -499,20 +499,20 @@ static int fake_big_file(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
|
||||
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;
|
||||
@@ -524,7 +524,7 @@ 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;
|
||||
@@ -534,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 },
|
||||
@@ -552,7 +552,11 @@ 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);
|
||||
(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);
|
||||
|
||||
+74
-435
@@ -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.44 2004/06/17 00:01:21 danielk1977 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,16 +60,14 @@ 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, nCache, flags, 0);
|
||||
rc = sqliteBtreeFactory(0, argv[1], 0, 1000, &pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -102,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;
|
||||
@@ -129,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, 0);
|
||||
rc = sqliteBtreeBeginTrans(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -156,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;
|
||||
@@ -183,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;
|
||||
@@ -192,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
|
||||
*/
|
||||
@@ -284,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;
|
||||
@@ -324,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;
|
||||
@@ -353,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;
|
||||
@@ -375,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;
|
||||
@@ -419,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++){
|
||||
if( Tcl_GetInt(interp, argv[i+1], &aMeta[i]) ) return TCL_ERROR;
|
||||
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;
|
||||
}
|
||||
@@ -454,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;
|
||||
@@ -484,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;
|
||||
@@ -513,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",
|
||||
@@ -546,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;
|
||||
}
|
||||
|
||||
@@ -580,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);
|
||||
@@ -588,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
|
||||
**
|
||||
@@ -637,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;
|
||||
@@ -667,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;
|
||||
@@ -697,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;
|
||||
@@ -735,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;
|
||||
@@ -764,22 +648,8 @@ static int btree_insert(
|
||||
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;
|
||||
*/
|
||||
i64 iKey;
|
||||
Tcl_Obj *obj = Tcl_NewStringObj(argv[2], -1);
|
||||
Tcl_IncrRefCount(obj);
|
||||
if( Tcl_GetWideIntFromObj(interp, obj, &iKey) ) return TCL_ERROR;
|
||||
Tcl_DecrRefCount(obj);
|
||||
|
||||
rc = sqlite3BtreeInsert(pCur, 0, iKey, argv[3], strlen(argv[3]));
|
||||
}else{
|
||||
rc = sqlite3BtreeInsert(pCur, argv[2], strlen(argv[2]),
|
||||
rc = sqliteBtreeInsert(pCur, argv[2], strlen(argv[2]),
|
||||
argv[3], strlen(argv[3]));
|
||||
}
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -811,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;
|
||||
@@ -845,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;
|
||||
@@ -878,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;
|
||||
@@ -911,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;
|
||||
@@ -921,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
|
||||
**
|
||||
@@ -988,7 +804,7 @@ static int btree_key(
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
u64 n;
|
||||
int n;
|
||||
char *zBuf;
|
||||
|
||||
if( argc!=2 ){
|
||||
@@ -997,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;
|
||||
}
|
||||
|
||||
@@ -1029,7 +842,7 @@ static int btree_data(
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
u32 n;
|
||||
int n;
|
||||
char *zBuf;
|
||||
|
||||
if( argc!=2 ){
|
||||
@@ -1038,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;
|
||||
@@ -1051,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
|
||||
**
|
||||
@@ -1139,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 ){
|
||||
@@ -1149,19 +888,15 @@ 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
|
||||
** Usage: btree_cursor_dump ID
|
||||
**
|
||||
** Return eight integers containing information about the entry the
|
||||
** cursor is pointing to:
|
||||
@@ -1175,7 +910,7 @@ static int btree_payload_size(
|
||||
** 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 */
|
||||
@@ -1193,7 +928,7 @@ static int btree_cursor_info(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeCursorInfo(pCur, aResult);
|
||||
rc = sqliteBtreeCursorDump(pCur, aResult);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -1207,96 +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;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
@@ -1322,32 +971,22 @@ int Sqlitetest3_Init(Tcl_Interp *interp){
|
||||
{ "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);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
+22
-38
@@ -11,11 +11,10 @@
|
||||
*************************************************************************
|
||||
** Code for testing the the SQLite library in a multithreaded environment.
|
||||
**
|
||||
** $Id: test4.c,v 1.10 2004/06/08 00:02:35 danielk1977 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++;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
-201
@@ -1,201 +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.11 2004/06/18 04:24: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;
|
||||
}
|
||||
|
||||
static int test_translate(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
u8 enc_from;
|
||||
u8 enc_to;
|
||||
sqlite3_value *pVal;
|
||||
|
||||
const char *z;
|
||||
int len;
|
||||
|
||||
if( objc!=4 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0),
|
||||
" <string/blob> <from enc> <to enc>", 0
|
||||
);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
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]);
|
||||
sqlite3ValueSetStr(pVal, -1, z, enc_from, SQLITE_STATIC);
|
||||
}else{
|
||||
z = Tcl_GetByteArrayFromObj(objv[1], &len);
|
||||
sqlite3ValueSetStr(pVal, -1, z, enc_from, SQLITE_STATIC);
|
||||
}
|
||||
|
||||
z = 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;
|
||||
}
|
||||
|
||||
+35
-73
@@ -15,7 +15,7 @@
|
||||
** individual tokens and sends those tokens one-by-one over to the
|
||||
** parser for analysis.
|
||||
**
|
||||
** $Id: tokenize.c,v 1.78 2004/06/18 06:02:35 danielk1977 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,31 +375,12 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
*tokenType = TK_VARIABLE;
|
||||
return 1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -412,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 = zSql;
|
||||
while( sqlite3_malloc_failed==0 && zSql[i]!=0 ){
|
||||
while( sqlite_malloc_failed==0 && zSql[i]!=0 ){
|
||||
assert( i>=0 );
|
||||
pParse->sLastToken.z = &zSql[i];
|
||||
assert( pParse->sLastToken.dyn==0 );
|
||||
@@ -444,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;
|
||||
@@ -460,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;
|
||||
@@ -472,14 +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);
|
||||
sqliteParser(pEngine, 0, pParse->sLastToken, pParse);
|
||||
}
|
||||
sqlite3ParserFree(pEngine, free);
|
||||
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 ){
|
||||
@@ -492,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) ){
|
||||
@@ -510,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
|
||||
@@ -568,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 */
|
||||
|
||||
@@ -647,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;
|
||||
@@ -655,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;
|
||||
@@ -667,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;
|
||||
@@ -694,24 +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;
|
||||
}
|
||||
|
||||
|
||||
+177
-204
@@ -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 ) 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 = sqlite3TableNameFromToken(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,40 +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, 2, 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);
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
sqliteVdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -254,10 +223,10 @@ void sqlite3FinishTrigger(
|
||||
}
|
||||
|
||||
triggerfinish_cleanup:
|
||||
sqlite3DeleteTrigger(nt);
|
||||
sqlite3DeleteTrigger(pParse->pNewTrigger);
|
||||
sqliteDeleteTrigger(nt);
|
||||
sqliteDeleteTrigger(pParse->pNewTrigger);
|
||||
pParse->pNewTrigger = 0;
|
||||
sqlite3DeleteTriggerStep(pStepList);
|
||||
sqliteDeleteTriggerStep(pStepList);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -265,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 ){
|
||||
@@ -276,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;
|
||||
}
|
||||
}
|
||||
@@ -304,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;
|
||||
|
||||
@@ -323,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 */
|
||||
@@ -352,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 */
|
||||
@@ -376,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;
|
||||
|
||||
@@ -392,13 +361,13 @@ 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);
|
||||
}
|
||||
@@ -407,7 +376,7 @@ void sqlite3DeleteTrigger(Trigger *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
|
||||
* 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.
|
||||
*
|
||||
@@ -416,38 +385,33 @@ void sqlite3DeleteTrigger(Trigger *pTrigger){
|
||||
* table. This is so that the trigger can be restored into the database schema
|
||||
* if the transaction is rolled back.
|
||||
*/
|
||||
void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
|
||||
Trigger *pTrigger = 0;
|
||||
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(db, &pParse->zErrMsg) ){
|
||||
pParse->nErr++;
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -455,13 +419,18 @@ drop_trigger_cleanup:
|
||||
** 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;
|
||||
|
||||
assert( pTrigger->iDb<db->nDb );
|
||||
pTable = sqlite3FindTable(db, pTrigger->table,db->aDb[pTrigger->iTabDb].zName);
|
||||
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==pTrigger->iDb || pTrigger->iDb==1 );
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
@@ -469,9 +438,9 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
int code = SQLITE_DROP_TRIGGER;
|
||||
const char *zDb = db->aDb[pTrigger->iDb].zName;
|
||||
const char *zTab = SCHEMA_TABLE(pTrigger->iDb);
|
||||
if( pTrigger->iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
|
||||
if( sqlite3AuthCheck(pParse, code, pTrigger->name, pTable->zName, zDb) ||
|
||||
sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -479,31 +448,34 @@ 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, pTrigger->iDb);
|
||||
sqlite3OpenMasterTable(v, pTrigger->iDb);
|
||||
base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
|
||||
sqlite3VdbeChangeP3(v, base+1, pTrigger->name, 0);
|
||||
sqlite3ChangeCookie(db, v, pTrigger->iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Close, 0, 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);
|
||||
}
|
||||
|
||||
/*
|
||||
** If this is not an "explain", then delete the trigger structure.
|
||||
*/
|
||||
* If this is not an "explain", then delete the trigger structure.
|
||||
*/
|
||||
if( !pParse->explain ){
|
||||
const char *zName = pTrigger->name;
|
||||
int nName = strlen(zName);
|
||||
@@ -520,8 +492,8 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
}
|
||||
assert(cc);
|
||||
}
|
||||
sqlite3HashInsert(&(db->aDb[pTrigger->iDb].trigHash), zName, nName+1, 0);
|
||||
sqlite3DeleteTrigger(pTrigger);
|
||||
sqliteHashInsert(&(db->aDb[pTrigger->iDb].trigHash), zName, nName+1, 0);
|
||||
sqliteDeleteTrigger(pTrigger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,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;
|
||||
}
|
||||
@@ -558,7 +530,7 @@ int always_code_trigger_setup = 0;
|
||||
* 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 */
|
||||
@@ -614,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;
|
||||
}
|
||||
@@ -640,38 +612,38 @@ static int codeTriggerProgram(
|
||||
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_ListPush, 0, 0);
|
||||
sqlite3Update(pParse, pSrc,
|
||||
sqlite3ExprListDup(pTriggerStep->pExprList),
|
||||
sqlite3ExprDup(pTriggerStep->pWhere), orconf);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 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);
|
||||
sqlite3Insert(pParse, pSrc,
|
||||
sqlite3ExprListDup(pTriggerStep->pExprList),
|
||||
sqlite3SelectDup(pTriggerStep->pSelect),
|
||||
sqlite3IdListDup(pTriggerStep->pIdList), orconf);
|
||||
sqliteInsert(pParse, pSrc,
|
||||
sqliteExprListDup(pTriggerStep->pExprList),
|
||||
sqliteSelectDup(pTriggerStep->pSelect),
|
||||
sqliteIdListDup(pTriggerStep->pIdList), orconf);
|
||||
break;
|
||||
}
|
||||
case TK_DELETE: {
|
||||
SrcList *pSrc;
|
||||
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);
|
||||
sqliteDeleteFrom(pParse, pSrc, sqliteExprDup(pTriggerStep->pWhere));
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -704,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 */
|
||||
@@ -760,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;
|
||||
}
|
||||
|
||||
+98
-102
@@ -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.84 2004/06/16 12:02:52 danielk1977 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,14 +114,14 @@ void sqlite3Update(
|
||||
*/
|
||||
chngRecno = 0;
|
||||
for(i=0; i<pChanges->nExpr; i++){
|
||||
if( sqlite3ExprResolveIds(pParse, pTabList, 0, pChanges->a[i].pExpr) ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, 0, pChanges->a[i].pExpr) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( sqlite3ExprCheck(pParse, pChanges->a[i].pExpr, 0, 0) ){
|
||||
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;
|
||||
@@ -128,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;
|
||||
@@ -166,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];
|
||||
}
|
||||
@@ -179,7 +182,6 @@ void sqlite3Update(
|
||||
}
|
||||
}
|
||||
if( i<pIdx->nColumn ){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ) goto update_cleanup;
|
||||
apIdx[nIdx++] = pIdx;
|
||||
aIdxUsed[j] = 1;
|
||||
}else{
|
||||
@@ -191,10 +193,10 @@ void sqlite3Update(
|
||||
** WHERE clause.
|
||||
*/
|
||||
if( pWhere ){
|
||||
if( sqlite3ExprResolveIds(pParse, pTabList, 0, pWhere) ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, 0, pWhere) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( sqlite3ExprCheck(pParse, pWhere, 0, 0) ){
|
||||
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -202,108 +204,105 @@ void sqlite3Update(
|
||||
/* 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;
|
||||
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++){
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -315,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{
|
||||
@@ -331,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 );
|
||||
}
|
||||
}
|
||||
@@ -345,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
|
||||
@@ -408,13 +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;
|
||||
}
|
||||
}
|
||||
@@ -422,42 +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);
|
||||
}
|
||||
|
||||
sqlite3VdbeAddOp(v, OP_SetCounts, 0, 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,546 +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.21 2004/06/18 04:24:55 danielk1977 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"
|
||||
|
||||
/*
|
||||
** The following macro, LOWERCASE(x), takes an integer representing a
|
||||
** unicode code point. The value returned is the same code point folded to
|
||||
** lower case, if applicable. SQLite currently understands the upper/lower
|
||||
** case relationship between the 26 characters used in the English
|
||||
** language only.
|
||||
**
|
||||
** This means that characters with umlauts etc. will not be folded
|
||||
** correctly (unless they are encoded as composite characters, which would
|
||||
** doubtless cause much trouble).
|
||||
*/
|
||||
#define LOWERCASE(x) (x<91?(int)(UpperToLower[x]):x)
|
||||
static unsigned char UpperToLower[91] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
|
||||
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103,
|
||||
104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,
|
||||
122,
|
||||
};
|
||||
|
||||
/*
|
||||
** 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]; \
|
||||
} \
|
||||
}
|
||||
|
||||
#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); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
** 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;
|
||||
sqlite3VdbeMemMakeWriteable(pMem);
|
||||
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 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];
|
||||
len = pMem->n*2 + 2;
|
||||
if( len>NBFS ){
|
||||
zOut = sqliteMallocRaw(len);
|
||||
if( !zOut ) return SQLITE_NOMEM;
|
||||
}else{
|
||||
if( pMem->z==pMem->zShort ){
|
||||
zOut = zShort;
|
||||
}else{
|
||||
zOut = pMem->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;
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short);
|
||||
pMem->enc = desiredEnc;
|
||||
if( (char *)zOut==pMem->zShort ){
|
||||
pMem->flags |= (MEM_Term|MEM_Short);
|
||||
}else 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 ){
|
||||
if( pMem->flags & MEM_Short ){
|
||||
memmove(pMem->zShort, &pMem->zShort[2], NBFS-2);
|
||||
pMem->n -= 2;
|
||||
pMem->enc = bom;
|
||||
}
|
||||
else 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);
|
||||
if( xDel ){
|
||||
xDel(z);
|
||||
}else{
|
||||
sqliteFree(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);
|
||||
}
|
||||
|
||||
/*
|
||||
** Compare two UTF-8 strings for equality using the "LIKE" operator of
|
||||
** SQL. The '%' character matches any sequence of 0 or more
|
||||
** characters and '_' matches any single character. Case is
|
||||
** not significant.
|
||||
*/
|
||||
int sqlite3utf8LikeCompare(
|
||||
const unsigned char *zPattern,
|
||||
const unsigned char *zString
|
||||
){
|
||||
register int c;
|
||||
int c2;
|
||||
|
||||
while( (c = LOWERCASE(*zPattern))!=0 ){
|
||||
switch( c ){
|
||||
case '%': {
|
||||
while( (c=zPattern[1]) == '%' || c == '_' ){
|
||||
if( c=='_' ){
|
||||
if( *zString==0 ) return 0;
|
||||
SKIP_UTF8(zString);
|
||||
}
|
||||
zPattern++;
|
||||
}
|
||||
if( c==0 ) return 1;
|
||||
c = LOWERCASE(c);
|
||||
while( (c2=LOWERCASE(*zString))!=0 ){
|
||||
while( c2 != 0 && c2 != c ){
|
||||
zString++;
|
||||
c2 = LOWERCASE(*zString);
|
||||
}
|
||||
if( c2==0 ) return 0;
|
||||
if( sqlite3utf8LikeCompare(&zPattern[1],zString) ) return 1;
|
||||
SKIP_UTF8(zString);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
case '_': {
|
||||
if( *zString==0 ) return 0;
|
||||
SKIP_UTF8(zString);
|
||||
zPattern++;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if( c != LOWERCASE(*zString) ) return 0;
|
||||
zPattern++;
|
||||
zString++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return *zString==0;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
/*
|
||||
** 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; 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
|
||||
|
||||
|
||||
+228
-410
File diff suppressed because it is too large
Load Diff
+248
-151
@@ -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.22 2004/06/15 11:40:09 danielk1977 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,151 +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);
|
||||
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 *zErrMsg; /* Error message */
|
||||
vacuumStruct sVac; /* Information passed to callbacks */
|
||||
|
||||
char *zSql = 0;
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
/* 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->autoCommit ){
|
||||
sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction",
|
||||
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);
|
||||
zFilename = sqliteBtreeGetFilename(db->aDb[0].pBt);
|
||||
if( zFilename==0 ){
|
||||
/* The in-memory database. Do nothing. */
|
||||
goto end_of_vacuum;
|
||||
/* 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);
|
||||
for(i=0; i<10; i++){
|
||||
zTemp[nFilename] = '-';
|
||||
randomName((unsigned char*)&zTemp[nFilename+1]);
|
||||
if( !sqlite3OsFileExists(zTemp) ) break;
|
||||
if( !sqliteOsFileExists(zTemp) ) break;
|
||||
}
|
||||
|
||||
/* Attach the temporary database as 'vacuum' */
|
||||
zSql = sqlite3MPrintf("ATTACH '%s' AS vacuum_db;", zTemp);
|
||||
if( !zSql ){
|
||||
rc = SQLITE_NOMEM;
|
||||
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;
|
||||
|
||||
/* 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 ' || type || ' vacuum_db.' || "
|
||||
"substr(sql, length(type)+9, 1000000) "
|
||||
"FROM sqlite_master "
|
||||
"WHERE type != 'trigger' AND sql IS NOT NULL "
|
||||
"ORDER BY (type != 'table');"
|
||||
);
|
||||
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 ' || type || ' vacuum_db.' || "
|
||||
"substr(sql, length(type)+9, 1000000) "
|
||||
"FROM sqlite_master "
|
||||
"WHERE type = 'trigger' AND sql IS NOT NULL;"
|
||||
);
|
||||
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, 0);
|
||||
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);
|
||||
|
||||
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 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:
|
||||
execSql(db, "DETACH vacuum_db;");
|
||||
execSql(db, "ROLLBACK;");
|
||||
if( zTemp ){
|
||||
sqlite3OsDelete(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
if( rc && zErrMsg!=0 ){
|
||||
sqliteSetString(pzErrMsg, "unable to vacuum database - ",
|
||||
zErrMsg, (char*)0);
|
||||
}
|
||||
if( zSql ) sqliteFree( zSql );
|
||||
if( pStmt ) sqlite3_finalize( pStmt );
|
||||
sqlite_exec(db, "ROLLBACK", 0, 0, 0);
|
||||
if( (dbNew && (dbNew->flags & SQLITE_Interrupt))
|
||||
|| (db->flags & SQLITE_Interrupt) ){
|
||||
rc = SQLITE_INTERRUPT;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+2022
-1754
File diff suppressed because it is too large
Load Diff
+25
-48
@@ -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.85 2004/06/05 10:22:18 danielk1977 Exp $
|
||||
** $Id: vdbe.h,v 1.71 2004/02/22 20:05:02 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_VDBE_H_
|
||||
#define _SQLITE_VDBE_H_
|
||||
@@ -39,9 +39,6 @@ struct VdbeOp {
|
||||
int p2; /* Second parameter (often the jump destination) */
|
||||
char *p3; /* Third parameter */
|
||||
int p3type; /* P3_STATIC, P3_DYNAMIC or P3_POINTER */
|
||||
#ifndef NDEBUG
|
||||
char *zComment; /* Comments explaining what this opcode does */
|
||||
#endif
|
||||
#ifdef VDBE_PROFILE
|
||||
int cnt; /* Number of times this instruction was executed */
|
||||
long long cycles; /* Total time spend executing this instruction */
|
||||
@@ -68,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))
|
||||
@@ -100,36 +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 sqlite3VdbeCode(Vdbe*,...);
|
||||
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 sqlite3VdbeFinalize(Vdbe*,char**);
|
||||
void sqlite3VdbeResolveLabel(Vdbe*, int);
|
||||
int sqlite3VdbeCurrentAddr(Vdbe*);
|
||||
void sqlite3VdbeTrace(Vdbe*,FILE*);
|
||||
void sqlite3VdbeCompressSpace(Vdbe*,int);
|
||||
int sqlite3VdbeReset(Vdbe*,char **);
|
||||
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);
|
||||
|
||||
#ifndef NDEBUG
|
||||
void sqlite3VdbeComment(Vdbe*, const char*, ...);
|
||||
# define VdbeComment(X) sqlite3VdbeComment X
|
||||
#else
|
||||
# define VdbeComment(X)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+68
-160
@@ -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 */
|
||||
char zShort[NBFS]; /* Space for short strings */
|
||||
void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
|
||||
};
|
||||
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,53 +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 */
|
||||
|
||||
struct VdbeFunc {
|
||||
FuncDef *pFunc;
|
||||
int nAux;
|
||||
struct AuxData {
|
||||
void *pAux;
|
||||
void (*xDelete)(void *);
|
||||
} apAux[0];
|
||||
};
|
||||
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
|
||||
@@ -204,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;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -227,15 +171,9 @@ typedef struct AggElem AggElem;
|
||||
struct Agg {
|
||||
int nMem; /* Number of values stored in each AggElem */
|
||||
AggElem *pCurrent; /* The AggElem currently in focus */
|
||||
FuncDef **apFunc; /* Information about aggregate functions */
|
||||
#if 0
|
||||
HashElem *pSearch; /* The hash element for pCurrent */
|
||||
Hash hash; /* Hash table of all aggregate elements */
|
||||
#endif
|
||||
Btree *pBtree; /* The temporary btree used to group elements */
|
||||
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 */
|
||||
FuncDef **apFunc; /* Information about aggregate functions */
|
||||
};
|
||||
struct AggElem {
|
||||
char *zKey; /* The key to this AggElem */
|
||||
@@ -266,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 */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -286,7 +224,7 @@ struct Context {
|
||||
** 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 {
|
||||
@@ -301,22 +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 */
|
||||
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 apVar[] */
|
||||
Mem *apVar; /* Values for the OP_Variable opcode. */
|
||||
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 */
|
||||
@@ -327,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[] */
|
||||
@@ -334,9 +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 autoCommitOn; /* True if autocommit got turned on by this program */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -350,46 +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
|
||||
int sqlite3VdbeSerialTypeLen(u32);
|
||||
u32 sqlite3VdbeSerialType(Mem*);
|
||||
int sqlite3VdbeSerialPut(unsigned char*, Mem*);
|
||||
int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
|
||||
|
||||
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 sqlite3VdbeChangeEncoding(Mem *, int);
|
||||
int sqlite3VdbeMemCopy(Mem*, const Mem*);
|
||||
int sqlite3VdbeMemMove(Mem*, Mem*);
|
||||
int sqlite3VdbeMemNulTerminate(Mem*);
|
||||
int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
|
||||
void sqlite3VdbeMemSetInt64(Mem*, long long int);
|
||||
void sqlite3VdbeMemSetDouble(Mem*, double);
|
||||
void sqlite3VdbeMemSetNull(Mem*);
|
||||
int sqlite3VdbeMemMakeWriteable(Mem*);
|
||||
int sqlite3VdbeMemDynamicify(Mem*);
|
||||
int sqlite3VdbeMemStringify(Mem*, int);
|
||||
int sqlite3VdbeMemIntegerify(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);
|
||||
|
||||
-527
@@ -1,527 +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){
|
||||
Mem *p = (Mem*)pVal;
|
||||
if( (p->flags & MEM_Blob)!=0 || sqlite3_value_text(pVal) ){
|
||||
return p->n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqlite3_value_bytes16(sqlite3_value *pVal){
|
||||
Mem *p = (Mem*)pVal;
|
||||
if( (p->flags & MEM_Blob)!=0 || sqlite3_value_text16(pVal) ){
|
||||
return ((Mem *)pVal)->n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
double sqlite3_value_double(sqlite3_value *pVal){
|
||||
Mem *pMem = (Mem *)pVal;
|
||||
sqlite3VdbeMemRealify(pMem);
|
||||
return pMem->r;
|
||||
}
|
||||
int sqlite3_value_int(sqlite3_value *pVal){
|
||||
Mem *pMem = (Mem *)pVal;
|
||||
sqlite3VdbeMemIntegerify(pMem);
|
||||
return (int)pVal->i;
|
||||
}
|
||||
long long int sqlite3_value_int64(sqlite3_value *pVal){
|
||||
Mem *pMem = (Mem *)pVal;
|
||||
sqlite3VdbeMemIntegerify(pMem);
|
||||
return pVal->i;
|
||||
}
|
||||
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->magic!=VDBE_MAGIC_RUN ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
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 pCtx->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;
|
||||
if( iArg<0 ) return;
|
||||
|
||||
if( !pCtx->pVdbeFunc || pCtx->pVdbeFunc->nAux<=iArg ){
|
||||
int nMalloc = sizeof(VdbeFunc)+sizeof(struct AuxData)*(iArg+1);
|
||||
pCtx->pVdbeFunc = sqliteRealloc(pCtx->pVdbeFunc, nMalloc);
|
||||
if( !pCtx->pVdbeFunc ) return;
|
||||
pCtx->pVdbeFunc->nAux = iArg+1;
|
||||
pCtx->pVdbeFunc->pFunc = pCtx->pFunc;
|
||||
}
|
||||
|
||||
pAuxData = &pCtx->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->nResColumn;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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->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) );
|
||||
}
|
||||
long long int 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 ){
|
||||
sqlite3Error(p->db, SQLITE_RANGE, 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 ){
|
||||
sqlite3Error(p->db, SQLITE_RANGE, 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 ){
|
||||
sqlite3Error(p->db, SQLITE_RANGE, 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 ){
|
||||
sqlite3Error(p->db, SQLITE_RANGE, 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->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->apVar[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 ){
|
||||
return rc;
|
||||
}
|
||||
pVar = &p->apVar[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->apVar[i-1], rValue);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
|
||||
return sqlite3_bind_int64(p, i, (long long int)iValue);
|
||||
}
|
||||
int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, long long int iValue){
|
||||
int rc;
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
rc = vdbeUnbind(p, i);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3VdbeMemSetInt64(&p->apVar[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 ){
|
||||
return rc;
|
||||
}
|
||||
pVar = &p->apVar[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 ){
|
||||
return rc;
|
||||
}
|
||||
pVar = &p->apVar[i-1];
|
||||
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, SQLITE_UTF16NATIVE, xDel);
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc);
|
||||
return rc;
|
||||
}
|
||||
+380
-1085
File diff suppressed because it is too large
Load Diff
-654
@@ -1,654 +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){
|
||||
if( (pMem->flags & MEM_Term)!=0 || (pMem->flags & (MEM_Str|MEM_Blob))==0 ){
|
||||
return SQLITE_OK; /* Nothing to do */
|
||||
}
|
||||
|
||||
if( pMem->flags & (MEM_Static|MEM_Ephem) ){
|
||||
return sqlite3VdbeMemMakeWriteable(pMem);
|
||||
}else{
|
||||
if( pMem->flags & MEM_Dyn ){
|
||||
if( pMem->xDel ){
|
||||
char *z = sqliteMalloc(pMem->n+2);
|
||||
if( !z ) return SQLITE_NOMEM;
|
||||
memcpy(z, pMem->z, pMem->n);
|
||||
pMem->xDel(pMem->z);
|
||||
pMem->xDel = 0;
|
||||
pMem->z = z;
|
||||
}else{
|
||||
pMem->z = sqliteRealloc(pMem->z, pMem->n+2);
|
||||
if( !pMem->z ) return SQLITE_NOMEM;
|
||||
}
|
||||
}else{
|
||||
assert( pMem->flags & MEM_Short );
|
||||
if( pMem->n+2>NBFS ){
|
||||
char *z = sqliteMalloc(pMem->n+2);
|
||||
if( !z ) return SQLITE_NOMEM;
|
||||
memcpy(z, pMem->z, pMem->n);
|
||||
pMem->flags &= !(MEM_Short);
|
||||
pMem->flags |= MEM_Dyn;
|
||||
pMem->xDel = 0;
|
||||
pMem->z = z;
|
||||
}
|
||||
}
|
||||
pMem->z[pMem->n++] = 0;
|
||||
pMem->z[pMem->n++] = 0;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Add MEM_Str to the set of representations for the given Mem.
|
||||
** A NULL is converted into an empty string. 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.
|
||||
** But MEM_Null is.
|
||||
*/
|
||||
int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
int rc = SQLITE_OK;
|
||||
int fg = pMem->flags;
|
||||
|
||||
assert( !(fg&(MEM_Str|MEM_Blob)) );
|
||||
assert( fg&(MEM_Int|MEM_Real|MEM_Null) );
|
||||
|
||||
if( fg & MEM_Null ){
|
||||
/* A NULL value is converted to a zero length string */
|
||||
u8 *z = pMem->zShort;
|
||||
z[0] = 0;
|
||||
z[1] = 0;
|
||||
pMem->flags = MEM_Str | MEM_Short | MEM_Term;
|
||||
pMem->z = z;
|
||||
pMem->n = 0;
|
||||
pMem->enc = enc;
|
||||
}else{
|
||||
/* 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.
|
||||
*/
|
||||
u8 *z = pMem->zShort;
|
||||
if( fg & MEM_Real || (pMem->type==SQLITE_FLOAT) ){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert the Mem to have representation MEM_Int only. All
|
||||
** prior representations are invalidated. NULL is converted into 0.
|
||||
*/
|
||||
int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
int flags = pMem->flags;
|
||||
if( flags & MEM_Int ){
|
||||
/* Do nothing */
|
||||
}else if( flags & MEM_Real ){
|
||||
pMem->i = (i64)pMem->r;
|
||||
}else if( flags & (MEM_Str|MEM_Blob) ){
|
||||
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|
||||
|| sqlite3VdbeMemNulTerminate(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( pMem->z );
|
||||
sqlite3atoi64(pMem->z, &pMem->i);
|
||||
}else{
|
||||
pMem->i = 0;
|
||||
}
|
||||
pMem->flags |= MEM_Int;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Add MEM_Real to the set of representations for pMem. Prior
|
||||
** prior representations other than MEM_Null retained. NULL is
|
||||
** converted into 0.0.
|
||||
*/
|
||||
int sqlite3VdbeMemRealify(Mem *pMem){
|
||||
if( pMem->flags & MEM_Real ){
|
||||
/* Do nothing */
|
||||
}else if( (pMem->flags & MEM_Int) && pMem->type!=SQLITE_TEXT ){
|
||||
pMem->r = pMem->i;
|
||||
}else if( pMem->flags & (MEM_Str|MEM_Blob) ){
|
||||
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|
||||
|| sqlite3VdbeMemNulTerminate(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( pMem->z );
|
||||
pMem->r = sqlite3AtoF(pMem->z, 0);
|
||||
}else{
|
||||
pMem->r = 0.0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
** Copy the contents of memory cell pFrom into pTo.
|
||||
*/
|
||||
int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
|
||||
sqlite3VdbeMemRelease(pTo);
|
||||
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);
|
||||
pTo->flags |= MEM_Ephem;
|
||||
sqlite3VdbeMemMakeWriteable(pTo);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Transfer the contents of pFrom to pTo. Any existing value in pTo is
|
||||
** deleted. pFrom contains an SQL NULL when this routine returns.
|
||||
*/
|
||||
int sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){
|
||||
int rc = SQLITE_OK;
|
||||
if( !(pFrom->flags&MEM_Dyn && pFrom->xDel) ){
|
||||
memcpy(pTo, pFrom, sizeof(Mem));
|
||||
if( pFrom->flags & MEM_Short ){
|
||||
pTo->z = pTo->zShort;
|
||||
}
|
||||
}else{
|
||||
rc = sqlite3VdbeMemCopy(pTo, pFrom);
|
||||
sqlite3VdbeMemRelease(pFrom);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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{
|
||||
return 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
/* 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 );
|
||||
|
||||
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.
|
||||
*/
|
||||
if( pMem->enc==SQLITE_UTF8 && (flags & MEM_Term) ){
|
||||
assert( strlen(pMem->z)==pMem->n );
|
||||
}
|
||||
}
|
||||
}else{
|
||||
/* Cannot define a string subtype for non-string objects */
|
||||
assert( (pMem->flags & (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short))==0 );
|
||||
}
|
||||
/* MEM_Null excludes all other types */
|
||||
assert( (pMem->flags&(MEM_Str|MEM_Int|MEM_Real|MEM_Blob))==0
|
||||
|| (pMem->flags&MEM_Null)==0 );
|
||||
}
|
||||
#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);
|
||||
}
|
||||
|
||||
sqlite3_value* sqlite3ValueNew(){
|
||||
Mem *p = sqliteMalloc(sizeof(*p));
|
||||
if( p ){
|
||||
p->flags = MEM_Null;
|
||||
p->type = SQLITE_NULL;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void sqlite3ValueSetStr(
|
||||
sqlite3_value *v,
|
||||
int n,
|
||||
const void *z,
|
||||
u8 enc,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
if( v ) sqlite3VdbeMemSetStr((Mem *)v, z, n, enc, xDel);
|
||||
}
|
||||
|
||||
void sqlite3ValueFree(sqlite3_value *v){
|
||||
if( !v ) return;
|
||||
sqlite3ValueSetStr(v, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
|
||||
sqliteFree(v);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
+176
-202
@@ -12,7 +12,7 @@
|
||||
** This module contains C code that generates VDBE code used to process
|
||||
** the WHERE clause of SQL statements.
|
||||
**
|
||||
** $Id: where.c,v 1.107 2004/06/17 07:53:04 danielk1977 Exp $
|
||||
** $Id: where.c,v 1.89 2004/02/22 20:05:02 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -113,9 +113,9 @@ static int getMask(ExprMaskSet *pMaskSet, int iCursor){
|
||||
** tree.
|
||||
**
|
||||
** In order for this routine to work, the calling function must have
|
||||
** previously invoked sqlite3ExprResolveIds() on the expression. See
|
||||
** previously invoked sqliteExprResolveIds() on the expression. See
|
||||
** the header comment on that routine for additional information.
|
||||
** The sqlite3ExprResolveIds() routines looks for column names and
|
||||
** The sqliteExprResolveIds() routines looks for column names and
|
||||
** sets their opcodes to TK_COLUMN and their Expr.iTable fields to
|
||||
** the VDBE cursor number of the table.
|
||||
*/
|
||||
@@ -208,7 +208,6 @@ static void exprAnalyze(ExprMaskSet *pMaskSet, ExprInfo *pInfo){
|
||||
** set to 0 if the ORDER BY clause is all ASC.
|
||||
*/
|
||||
static Index *findSortingIndex(
|
||||
Parse *pParse,
|
||||
Table *pTab, /* The table to be sorted */
|
||||
int base, /* Cursor number for pTab */
|
||||
ExprList *pOrderBy, /* The ORDER BY clause */
|
||||
@@ -220,18 +219,21 @@ static Index *findSortingIndex(
|
||||
Index *pMatch;
|
||||
Index *pIdx;
|
||||
int sortOrder;
|
||||
sqlite *db = pParse->db;
|
||||
|
||||
assert( pOrderBy!=0 );
|
||||
assert( pOrderBy->nExpr>0 );
|
||||
sortOrder = pOrderBy->a[0].sortOrder;
|
||||
sortOrder = pOrderBy->a[0].sortOrder & SQLITE_SO_DIRMASK;
|
||||
for(i=0; i<pOrderBy->nExpr; i++){
|
||||
Expr *p;
|
||||
if( pOrderBy->a[i].sortOrder!=sortOrder ){
|
||||
if( (pOrderBy->a[i].sortOrder & SQLITE_SO_DIRMASK)!=sortOrder ){
|
||||
/* Indices can only be used if all ORDER BY terms are either
|
||||
** DESC or ASC. Indices cannot be used on a mixture. */
|
||||
return 0;
|
||||
}
|
||||
if( (pOrderBy->a[i].sortOrder & SQLITE_SO_TYPEMASK)!=SQLITE_SO_UNK ){
|
||||
/* Do not sort by index if there is a COLLATE clause */
|
||||
return 0;
|
||||
}
|
||||
p = pOrderBy->a[i].pExpr;
|
||||
if( p->op!=TK_COLUMN || p->iTable!=base ){
|
||||
/* Can not use an index sort on anything that is not a column in the
|
||||
@@ -239,7 +241,7 @@ static Index *findSortingIndex(
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* If we get this far, it means the ORDER BY clause consists only of
|
||||
** ascending columns in the left-most table of the FROM clause. Now
|
||||
** check for a matching index.
|
||||
@@ -249,23 +251,12 @@ static Index *findSortingIndex(
|
||||
int nExpr = pOrderBy->nExpr;
|
||||
if( pIdx->nColumn < nEqCol || pIdx->nColumn < nExpr ) continue;
|
||||
for(i=j=0; i<nEqCol; i++){
|
||||
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pOrderBy->a[j].pExpr);
|
||||
if( !pColl ) pColl = db->pDfltColl;
|
||||
if( pPreferredIdx->aiColumn[i]!=pIdx->aiColumn[i] ) break;
|
||||
if( pPreferredIdx->keyInfo.aColl[i]!=pIdx->keyInfo.aColl[i] ) break;
|
||||
if( j<nExpr &&
|
||||
pOrderBy->a[j].pExpr->iColumn==pIdx->aiColumn[i] &&
|
||||
pColl==pIdx->keyInfo.aColl[i]
|
||||
){
|
||||
j++;
|
||||
}
|
||||
if( j<nExpr && pOrderBy->a[j].pExpr->iColumn==pIdx->aiColumn[i] ){ j++; }
|
||||
}
|
||||
if( i<nEqCol ) continue;
|
||||
for(i=0; i+j<nExpr; i++){
|
||||
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pOrderBy->a[i+j].pExpr);
|
||||
if( !pColl ) pColl = db->pDfltColl;
|
||||
if( pOrderBy->a[i+j].pExpr->iColumn!=pIdx->aiColumn[i+nEqCol] ||
|
||||
pColl!=pIdx->keyInfo.aColl[i+nEqCol] ) break;
|
||||
if( pOrderBy->a[i+j].pExpr->iColumn!=pIdx->aiColumn[i+nEqCol] ) break;
|
||||
}
|
||||
if( i+j>=nExpr ){
|
||||
pMatch = pIdx;
|
||||
@@ -282,7 +273,7 @@ static Index *findSortingIndex(
|
||||
** Generate the beginning of the loop used for WHERE clause processing.
|
||||
** The return value is a pointer to an (opaque) structure that contains
|
||||
** information needed to terminate the loop. Later, the calling routine
|
||||
** should invoke sqlite3WhereEnd() with the return value of this function
|
||||
** should invoke sqliteWhereEnd() with the return value of this function
|
||||
** in order to complete the WHERE clause processing.
|
||||
**
|
||||
** If an error occurs, this routine returns NULL.
|
||||
@@ -297,17 +288,17 @@ static Index *findSortingIndex(
|
||||
** Then the code generated is conceptually like the following:
|
||||
**
|
||||
** foreach row1 in t1 do \ Code generated
|
||||
** foreach row2 in t2 do |-- by sqlite3WhereBegin()
|
||||
** foreach row2 in t2 do |-- by sqliteWhereBegin()
|
||||
** foreach row3 in t3 do /
|
||||
** ...
|
||||
** end \ Code generated
|
||||
** end |-- by sqlite3WhereEnd()
|
||||
** end |-- by sqliteWhereEnd()
|
||||
** end /
|
||||
**
|
||||
** There are Btree cursors associated with each table. t1 uses cursor
|
||||
** number pTabList->a[0].iCursor. t2 uses the cursor pTabList->a[1].iCursor.
|
||||
** And so forth. This routine generates code to open those VDBE cursors
|
||||
** and sqlite3WhereEnd() generates the code to close them.
|
||||
** and sqliteWhereEnd() generates the code to close them.
|
||||
**
|
||||
** If the WHERE clause is empty, the foreach loops must each scan their
|
||||
** entire tables. Thus a three-way join is an O(N^3) operation. But if
|
||||
@@ -355,7 +346,7 @@ static Index *findSortingIndex(
|
||||
** If the where clause loops cannot be arranged to provide the correct
|
||||
** output order, then the *ppOrderBy is unchanged.
|
||||
*/
|
||||
WhereInfo *sqlite3WhereBegin(
|
||||
WhereInfo *sqliteWhereBegin(
|
||||
Parse *pParse, /* The parser context */
|
||||
SrcList *pTabList, /* A list of all tables to be scanned */
|
||||
Expr *pWhere, /* The WHERE clause */
|
||||
@@ -368,7 +359,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
int brk, cont = 0; /* Addresses used during code generation */
|
||||
int nExpr; /* Number of subexpressions in the WHERE clause */
|
||||
int loopMask; /* One bit set for each outer loop */
|
||||
int haveKey = 0; /* True if KEY is on the stack */
|
||||
int haveKey; /* True if KEY is on the stack */
|
||||
ExprMaskSet maskSet; /* The expression mask set */
|
||||
int iDirectEq[32]; /* Term of the form ROWID==X for the N-th table */
|
||||
int iDirectLt[32]; /* Term of the form ROWID<X or ROWID<=X */
|
||||
@@ -389,7 +380,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
memset(aExpr, 0, sizeof(aExpr));
|
||||
nExpr = exprSplit(ARRAYSIZE(aExpr), aExpr, pWhere);
|
||||
if( nExpr==ARRAYSIZE(aExpr) ){
|
||||
sqlite3ErrorMsg(pParse, "WHERE clause too complex - no more "
|
||||
sqliteErrorMsg(pParse, "WHERE clause too complex - no more "
|
||||
"than %d terms allowed", (int)ARRAYSIZE(aExpr)-1);
|
||||
return 0;
|
||||
}
|
||||
@@ -398,20 +389,20 @@ WhereInfo *sqlite3WhereBegin(
|
||||
** return value.
|
||||
*/
|
||||
pWInfo = sqliteMalloc( sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel));
|
||||
if( sqlite3_malloc_failed ){
|
||||
if( sqlite_malloc_failed ){
|
||||
sqliteFree(pWInfo);
|
||||
return 0;
|
||||
}
|
||||
pWInfo->pParse = pParse;
|
||||
pWInfo->pTabList = pTabList;
|
||||
pWInfo->peakNTab = pWInfo->savedNTab = pParse->nTab;
|
||||
pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
|
||||
pWInfo->iBreak = sqliteVdbeMakeLabel(v);
|
||||
|
||||
/* Special case: a WHERE clause that is constant. Evaluate the
|
||||
** expression and either jump over all of the code or fall thru.
|
||||
*/
|
||||
if( pWhere && (pTabList->nSrc==0 || sqlite3ExprIsConstant(pWhere)) ){
|
||||
sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, 1);
|
||||
if( pWhere && (pTabList->nSrc==0 || sqliteExprIsConstant(pWhere)) ){
|
||||
sqliteExprIfFalse(pParse, pWhere, pWInfo->iBreak, 1);
|
||||
pWhere = 0;
|
||||
}
|
||||
|
||||
@@ -541,23 +532,11 @@ WhereInfo *sqlite3WhereBegin(
|
||||
|
||||
if( pIdx->nColumn>32 ) continue; /* Ignore indices too many columns */
|
||||
for(j=0; j<nExpr; j++){
|
||||
CollSeq *pColl = sqlite3ExprCollSeq(pParse, aExpr[j].p->pLeft);
|
||||
if( !pColl && aExpr[j].p->pRight ){
|
||||
pColl = sqlite3ExprCollSeq(pParse, aExpr[j].p->pRight);
|
||||
}
|
||||
if( !pColl ){
|
||||
pColl = pParse->db->pDfltColl;
|
||||
}
|
||||
if( aExpr[j].idxLeft==iCur
|
||||
&& (aExpr[j].prereqRight & loopMask)==aExpr[j].prereqRight ){
|
||||
int iColumn = aExpr[j].p->pLeft->iColumn;
|
||||
int k;
|
||||
char idxaff = pIdx->pTable->aCol[iColumn].affinity;
|
||||
for(k=0; k<pIdx->nColumn; k++){
|
||||
/* If the collating sequences or affinities don't match,
|
||||
** ignore this index. */
|
||||
if( pColl!=pIdx->keyInfo.aColl[k] ) continue;
|
||||
if( !sqlite3IndexAffinityOk(aExpr[j].p, idxaff) ) continue;
|
||||
if( pIdx->aiColumn[k]==iColumn ){
|
||||
switch( aExpr[j].p->op ){
|
||||
case TK_IN: {
|
||||
@@ -592,12 +571,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
&& (aExpr[j].prereqLeft & loopMask)==aExpr[j].prereqLeft ){
|
||||
int iColumn = aExpr[j].p->pRight->iColumn;
|
||||
int k;
|
||||
char idxaff = pIdx->pTable->aCol[iColumn].affinity;
|
||||
for(k=0; k<pIdx->nColumn; k++){
|
||||
/* If the collating sequences or affinities don't match,
|
||||
** ignore this index. */
|
||||
if( pColl!=pIdx->keyInfo.aColl[k] ) continue;
|
||||
if( !sqlite3IndexAffinityOk(aExpr[j].p, idxaff) ) continue;
|
||||
if( pIdx->aiColumn[k]==iColumn ){
|
||||
switch( aExpr[j].p->op ){
|
||||
case TK_EQ: {
|
||||
@@ -677,7 +651,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
pSortIdx = 0;
|
||||
}else{
|
||||
int nEqCol = (pWInfo->a[0].score+4)/8;
|
||||
pSortIdx = findSortingIndex(pParse, pTab, pTabList->a[0].iCursor,
|
||||
pSortIdx = findSortingIndex(pTab, pTabList->a[0].iCursor,
|
||||
*ppOrderBy, pIdx, nEqCol, &bRev);
|
||||
}
|
||||
if( pSortIdx && (pIdx==0 || pIdx==pSortIdx) ){
|
||||
@@ -693,21 +667,19 @@ WhereInfo *sqlite3WhereBegin(
|
||||
|
||||
/* Open all tables in the pTabList and all indices used by those tables.
|
||||
*/
|
||||
sqlite3CodeVerifySchema(pParse, 1); /* Inserts the cookie verifier Goto */
|
||||
for(i=0; i<pTabList->nSrc; i++){
|
||||
Table *pTab;
|
||||
Index *pIx;
|
||||
|
||||
pTab = pTabList->a[i].pTab;
|
||||
if( pTab->isTransient || pTab->pSelect ) continue;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, pTabList->a[i].iCursor, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, pTabList->a[i].iCursor, pTab->nCol);
|
||||
sqlite3CodeVerifySchema(pParse, pTab->iDb);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenRead, pTabList->a[i].iCursor, pTab->tnum,
|
||||
pTab->zName, P3_STATIC);
|
||||
sqliteCodeVerifySchema(pParse, pTab->iDb);
|
||||
if( (pIx = pWInfo->a[i].pIdx)!=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIx->iDb, 0);
|
||||
sqlite3VdbeOp3(v, OP_OpenRead, pWInfo->a[i].iCur, pIx->tnum,
|
||||
(char*)&pIx->keyInfo, P3_KEYINFO);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIx->iDb, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenRead, pWInfo->a[i].iCur, pIx->tnum, pIx->zName,0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -727,8 +699,8 @@ WhereInfo *sqlite3WhereBegin(
|
||||
if( i>0 && (pTabList->a[i-1].jointype & JT_LEFT)!=0 ){
|
||||
if( !pParse->nMem ) pParse->nMem++;
|
||||
pLevel->iLeftJoin = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iLeftJoin, 1);
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iLeftJoin, 1);
|
||||
}
|
||||
|
||||
pIdx = pLevel->pIdx;
|
||||
@@ -743,38 +715,41 @@ WhereInfo *sqlite3WhereBegin(
|
||||
assert( k<nExpr );
|
||||
assert( aExpr[k].p!=0 );
|
||||
assert( aExpr[k].idxLeft==iCur || aExpr[k].idxRight==iCur );
|
||||
brk = pLevel->brk = sqlite3VdbeMakeLabel(v);
|
||||
brk = pLevel->brk = sqliteVdbeMakeLabel(v);
|
||||
if( aExpr[k].idxLeft==iCur ){
|
||||
Expr *pX = aExpr[k].p;
|
||||
if( pX->op!=TK_IN ){
|
||||
sqlite3ExprCode(pParse, aExpr[k].p->pRight);
|
||||
sqliteExprCode(pParse, aExpr[k].p->pRight);
|
||||
}else if( pX->pList ){
|
||||
sqliteVdbeAddOp(v, OP_SetFirst, pX->iTable, brk);
|
||||
pLevel->inOp = OP_SetNext;
|
||||
pLevel->inP1 = pX->iTable;
|
||||
pLevel->inP2 = sqliteVdbeCurrentAddr(v);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, pX->iTable, brk);
|
||||
sqlite3VdbeAddOp(v, OP_KeyAsData, pX->iTable, 1);
|
||||
pLevel->inP2 = sqlite3VdbeAddOp(v, OP_IdxColumn, pX->iTable, 0);
|
||||
assert( pX->pSelect );
|
||||
sqliteVdbeAddOp(v, OP_Rewind, pX->iTable, brk);
|
||||
sqliteVdbeAddOp(v, OP_KeyAsData, pX->iTable, 1);
|
||||
pLevel->inP2 = sqliteVdbeAddOp(v, OP_FullKey, pX->iTable, 0);
|
||||
pLevel->inOp = OP_Next;
|
||||
pLevel->inP1 = pX->iTable;
|
||||
}
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, aExpr[k].p->pLeft);
|
||||
sqliteExprCode(pParse, aExpr[k].p->pLeft);
|
||||
}
|
||||
aExpr[k].p = 0;
|
||||
cont = pLevel->cont = sqlite3VdbeMakeLabel(v);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 1, brk);
|
||||
cont = pLevel->cont = sqliteVdbeMakeLabel(v);
|
||||
sqliteVdbeAddOp(v, OP_MustBeInt, 1, brk);
|
||||
haveKey = 0;
|
||||
sqlite3VdbeAddOp(v, OP_NotExists, iCur, brk);
|
||||
sqliteVdbeAddOp(v, OP_NotExists, iCur, brk);
|
||||
pLevel->op = OP_Noop;
|
||||
}else if( pIdx!=0 && pLevel->score>0 && pLevel->score%4==0 ){
|
||||
/* Case 2: There is an index and all terms of the WHERE clause that
|
||||
** refer to the index use the "==" or "IN" operators.
|
||||
*/
|
||||
int start;
|
||||
int testOp;
|
||||
int nColumn = (pLevel->score+4)/8;
|
||||
brk = pLevel->brk = sqlite3VdbeMakeLabel(v);
|
||||
|
||||
/* For each column of the index, find the term of the WHERE clause that
|
||||
** constraints that column. If the WHERE clause term is X=expr, then
|
||||
** evaluation expr and leave the result on the stack */
|
||||
brk = pLevel->brk = sqliteVdbeMakeLabel(v);
|
||||
for(j=0; j<nColumn; j++){
|
||||
for(k=0; k<nExpr; k++){
|
||||
Expr *pX = aExpr[k].p;
|
||||
@@ -783,22 +758,27 @@ WhereInfo *sqlite3WhereBegin(
|
||||
&& (aExpr[k].prereqRight & loopMask)==aExpr[k].prereqRight
|
||||
&& pX->pLeft->iColumn==pIdx->aiColumn[j]
|
||||
){
|
||||
char idxaff = pIdx->pTable->aCol[pX->pLeft->iColumn].affinity;
|
||||
if( sqlite3IndexAffinityOk(aExpr[k].p, idxaff) ){
|
||||
if( pX->op==TK_EQ ){
|
||||
sqlite3ExprCode(pParse, pX->pRight);
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
}
|
||||
if( pX->op==TK_IN && nColumn==1 ){
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, pX->iTable, brk);
|
||||
sqlite3VdbeAddOp(v, OP_KeyAsData, pX->iTable, 1);
|
||||
pLevel->inP2 = sqlite3VdbeAddOp(v, OP_IdxColumn, pX->iTable, 0);
|
||||
if( pX->op==TK_EQ ){
|
||||
sqliteExprCode(pParse, pX->pRight);
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
}
|
||||
if( pX->op==TK_IN && nColumn==1 ){
|
||||
if( pX->pList ){
|
||||
sqliteVdbeAddOp(v, OP_SetFirst, pX->iTable, brk);
|
||||
pLevel->inOp = OP_SetNext;
|
||||
pLevel->inP1 = pX->iTable;
|
||||
pLevel->inP2 = sqliteVdbeCurrentAddr(v);
|
||||
}else{
|
||||
assert( pX->pSelect );
|
||||
sqliteVdbeAddOp(v, OP_Rewind, pX->iTable, brk);
|
||||
sqliteVdbeAddOp(v, OP_KeyAsData, pX->iTable, 1);
|
||||
pLevel->inP2 = sqliteVdbeAddOp(v, OP_FullKey, pX->iTable, 0);
|
||||
pLevel->inOp = OP_Next;
|
||||
pLevel->inP1 = pX->iTable;
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
}
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( aExpr[k].idxRight==iCur
|
||||
@@ -806,56 +786,49 @@ WhereInfo *sqlite3WhereBegin(
|
||||
&& (aExpr[k].prereqLeft & loopMask)==aExpr[k].prereqLeft
|
||||
&& aExpr[k].p->pRight->iColumn==pIdx->aiColumn[j]
|
||||
){
|
||||
char idxaff = pIdx->pTable->aCol[pX->pRight->iColumn].affinity;
|
||||
if( sqlite3IndexAffinityOk(aExpr[k].p, idxaff) ){
|
||||
sqlite3ExprCode(pParse, aExpr[k].p->pLeft);
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
}
|
||||
sqliteExprCode(pParse, aExpr[k].p->pLeft);
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
pLevel->iMem = pParse->nMem++;
|
||||
cont = pLevel->cont = sqlite3VdbeMakeLabel(v);
|
||||
|
||||
/* At this point, the top nColumn elements of the stack are the
|
||||
** values of columns in the index we are using. Check to see if
|
||||
** any of these values are NULL. If they are, they will not match any
|
||||
** index entries, so skip immediately to the next iteration of the loop */
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -nColumn, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, brk);
|
||||
|
||||
/* Generate an index key from the top nColumn elements of the stack */
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 0);
|
||||
|
||||
/* Generate code (1) to move to the first matching element of the table.
|
||||
** Then generate code (2) that jumps to "brk" after the cursor is past
|
||||
** the last matching element of the table. The code (1) is executed
|
||||
** once to initialize the search, the code (2) is executed before each
|
||||
** iteration of the scan to see if the scan has finished. */
|
||||
cont = pLevel->cont = sqliteVdbeMakeLabel(v);
|
||||
sqliteVdbeAddOp(v, OP_NotNull, -nColumn, sqliteVdbeCurrentAddr(v)+3);
|
||||
sqliteVdbeAddOp(v, OP_Pop, nColumn, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, brk);
|
||||
sqliteVdbeAddOp(v, OP_MakeKey, nColumn, 0);
|
||||
sqliteAddIdxKeyType(v, pIdx);
|
||||
if( nColumn==pIdx->nColumn || pLevel->bRev ){
|
||||
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 0);
|
||||
testOp = OP_IdxGT;
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_IncrKey, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
|
||||
testOp = OP_IdxGE;
|
||||
}
|
||||
if( pLevel->bRev ){
|
||||
/* Scan in reverse order */
|
||||
sqlite3VdbeAddOp(v, OP_MoveLe, pLevel->iCur, brk);
|
||||
start = sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
|
||||
sqlite3VdbeAddOp(v, OP_IdxLT, pLevel->iCur, brk);
|
||||
sqliteVdbeAddOp(v, OP_IncrKey, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MoveLt, pLevel->iCur, brk);
|
||||
start = sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
|
||||
sqliteVdbeAddOp(v, OP_IdxLT, pLevel->iCur, brk);
|
||||
pLevel->op = OP_Prev;
|
||||
}else{
|
||||
/* Scan in the forward order */
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, pLevel->iCur, brk);
|
||||
start = sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
|
||||
sqlite3VdbeOp3(v, OP_IdxGE, pLevel->iCur, brk, "+", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, pLevel->iCur, brk);
|
||||
start = sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
|
||||
sqliteVdbeAddOp(v, testOp, pLevel->iCur, brk);
|
||||
pLevel->op = OP_Next;
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_RowKey, pLevel->iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_IdxIsNull, nColumn, cont);
|
||||
sqlite3VdbeAddOp(v, OP_IdxRecno, pLevel->iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_RowKey, pLevel->iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_IdxIsNull, nColumn, cont);
|
||||
sqliteVdbeAddOp(v, OP_IdxRecno, pLevel->iCur, 0);
|
||||
if( i==pTabList->nSrc-1 && pushKey ){
|
||||
haveKey = 1;
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
|
||||
haveKey = 0;
|
||||
}
|
||||
pLevel->p1 = pLevel->iCur;
|
||||
@@ -866,24 +839,24 @@ WhereInfo *sqlite3WhereBegin(
|
||||
int testOp = OP_Noop;
|
||||
int start;
|
||||
|
||||
brk = pLevel->brk = sqlite3VdbeMakeLabel(v);
|
||||
cont = pLevel->cont = sqlite3VdbeMakeLabel(v);
|
||||
brk = pLevel->brk = sqliteVdbeMakeLabel(v);
|
||||
cont = pLevel->cont = sqliteVdbeMakeLabel(v);
|
||||
if( iDirectGt[i]>=0 ){
|
||||
k = iDirectGt[i];
|
||||
assert( k<nExpr );
|
||||
assert( aExpr[k].p!=0 );
|
||||
assert( aExpr[k].idxLeft==iCur || aExpr[k].idxRight==iCur );
|
||||
if( aExpr[k].idxLeft==iCur ){
|
||||
sqlite3ExprCode(pParse, aExpr[k].p->pRight);
|
||||
sqliteExprCode(pParse, aExpr[k].p->pRight);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, aExpr[k].p->pLeft);
|
||||
sqliteExprCode(pParse, aExpr[k].p->pLeft);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_ForceInt,
|
||||
sqliteVdbeAddOp(v, OP_ForceInt,
|
||||
aExpr[k].p->op==TK_LT || aExpr[k].p->op==TK_GT, brk);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, brk);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, brk);
|
||||
aExpr[k].p = 0;
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, brk);
|
||||
sqliteVdbeAddOp(v, OP_Rewind, iCur, brk);
|
||||
}
|
||||
if( iDirectLt[i]>=0 ){
|
||||
k = iDirectLt[i];
|
||||
@@ -891,13 +864,13 @@ WhereInfo *sqlite3WhereBegin(
|
||||
assert( aExpr[k].p!=0 );
|
||||
assert( aExpr[k].idxLeft==iCur || aExpr[k].idxRight==iCur );
|
||||
if( aExpr[k].idxLeft==iCur ){
|
||||
sqlite3ExprCode(pParse, aExpr[k].p->pRight);
|
||||
sqliteExprCode(pParse, aExpr[k].p->pRight);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, aExpr[k].p->pLeft);
|
||||
sqliteExprCode(pParse, aExpr[k].p->pLeft);
|
||||
}
|
||||
/* sqlite3VdbeAddOp(v, OP_MustBeInt, 0, sqlite3VdbeCurrentAddr(v)+1); */
|
||||
/* sqliteVdbeAddOp(v, OP_MustBeInt, 0, sqliteVdbeCurrentAddr(v)+1); */
|
||||
pLevel->iMem = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
|
||||
if( aExpr[k].p->op==TK_LT || aExpr[k].p->op==TK_GT ){
|
||||
testOp = OP_Ge;
|
||||
}else{
|
||||
@@ -905,14 +878,14 @@ WhereInfo *sqlite3WhereBegin(
|
||||
}
|
||||
aExpr[k].p = 0;
|
||||
}
|
||||
start = sqlite3VdbeCurrentAddr(v);
|
||||
start = sqliteVdbeCurrentAddr(v);
|
||||
pLevel->op = OP_Next;
|
||||
pLevel->p1 = iCur;
|
||||
pLevel->p2 = start;
|
||||
if( testOp!=OP_Noop ){
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
|
||||
sqlite3VdbeAddOp(v, testOp, 0, brk);
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
|
||||
sqliteVdbeAddOp(v, testOp, 0, brk);
|
||||
}
|
||||
haveKey = 0;
|
||||
}else if( pIdx==0 ){
|
||||
@@ -921,10 +894,10 @@ WhereInfo *sqlite3WhereBegin(
|
||||
*/
|
||||
int start;
|
||||
|
||||
brk = pLevel->brk = sqlite3VdbeMakeLabel(v);
|
||||
cont = pLevel->cont = sqlite3VdbeMakeLabel(v);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, brk);
|
||||
start = sqlite3VdbeCurrentAddr(v);
|
||||
brk = pLevel->brk = sqliteVdbeMakeLabel(v);
|
||||
cont = pLevel->cont = sqliteVdbeMakeLabel(v);
|
||||
sqliteVdbeAddOp(v, OP_Rewind, iCur, brk);
|
||||
start = sqliteVdbeCurrentAddr(v);
|
||||
pLevel->op = OP_Next;
|
||||
pLevel->p1 = iCur;
|
||||
pLevel->p2 = start;
|
||||
@@ -944,7 +917,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
int score = pLevel->score;
|
||||
int nEqColumn = score/8;
|
||||
int start;
|
||||
int leFlag=0, geFlag=0;
|
||||
int leFlag, geFlag;
|
||||
int testOp;
|
||||
|
||||
/* Evaluate the equality constraints
|
||||
@@ -957,7 +930,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
&& (aExpr[k].prereqRight & loopMask)==aExpr[k].prereqRight
|
||||
&& aExpr[k].p->pLeft->iColumn==pIdx->aiColumn[j]
|
||||
){
|
||||
sqlite3ExprCode(pParse, aExpr[k].p->pRight);
|
||||
sqliteExprCode(pParse, aExpr[k].p->pRight);
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
}
|
||||
@@ -966,7 +939,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
&& (aExpr[k].prereqLeft & loopMask)==aExpr[k].prereqLeft
|
||||
&& aExpr[k].p->pRight->iColumn==pIdx->aiColumn[j]
|
||||
){
|
||||
sqlite3ExprCode(pParse, aExpr[k].p->pLeft);
|
||||
sqliteExprCode(pParse, aExpr[k].p->pLeft);
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
}
|
||||
@@ -978,13 +951,13 @@ WhereInfo *sqlite3WhereBegin(
|
||||
** start key.
|
||||
*/
|
||||
for(j=0; j<nEqColumn; j++){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nEqColumn-1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nEqColumn-1, 0);
|
||||
}
|
||||
|
||||
/* Labels for the beginning and end of the loop
|
||||
*/
|
||||
cont = pLevel->cont = sqlite3VdbeMakeLabel(v);
|
||||
brk = pLevel->brk = sqlite3VdbeMakeLabel(v);
|
||||
cont = pLevel->cont = sqliteVdbeMakeLabel(v);
|
||||
brk = pLevel->brk = sqliteVdbeMakeLabel(v);
|
||||
|
||||
/* Generate the termination key. This is the key value that
|
||||
** will end the search. There is no termination key if there
|
||||
@@ -1002,7 +975,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
&& (aExpr[k].prereqRight & loopMask)==aExpr[k].prereqRight
|
||||
&& pExpr->pLeft->iColumn==pIdx->aiColumn[j]
|
||||
){
|
||||
sqlite3ExprCode(pParse, pExpr->pRight);
|
||||
sqliteExprCode(pParse, pExpr->pRight);
|
||||
leFlag = pExpr->op==TK_LE;
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
@@ -1012,7 +985,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
&& (aExpr[k].prereqLeft & loopMask)==aExpr[k].prereqLeft
|
||||
&& pExpr->pRight->iColumn==pIdx->aiColumn[j]
|
||||
){
|
||||
sqlite3ExprCode(pParse, pExpr->pLeft);
|
||||
sqliteExprCode(pParse, pExpr->pLeft);
|
||||
leFlag = pExpr->op==TK_GE;
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
@@ -1026,19 +999,21 @@ WhereInfo *sqlite3WhereBegin(
|
||||
if( testOp!=OP_Noop ){
|
||||
int nCol = nEqColumn + (score & 1);
|
||||
pLevel->iMem = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -nCol, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, brk);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, nCol, 0);
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
sqliteVdbeAddOp(v, OP_NotNull, -nCol, sqliteVdbeCurrentAddr(v)+3);
|
||||
sqliteVdbeAddOp(v, OP_Pop, nCol, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, brk);
|
||||
sqliteVdbeAddOp(v, OP_MakeKey, nCol, 0);
|
||||
sqliteAddIdxKeyType(v, pIdx);
|
||||
if( leFlag ){
|
||||
sqliteVdbeAddOp(v, OP_IncrKey, 0, 0);
|
||||
}
|
||||
if( pLevel->bRev ){
|
||||
int op = leFlag ? OP_MoveLe : OP_MoveLt;
|
||||
sqlite3VdbeAddOp(v, op, pLevel->iCur, brk);
|
||||
sqliteVdbeAddOp(v, OP_MoveLt, pLevel->iCur, brk);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
|
||||
}
|
||||
}else if( pLevel->bRev ){
|
||||
sqlite3VdbeAddOp(v, OP_Last, pLevel->iCur, brk);
|
||||
sqliteVdbeAddOp(v, OP_Last, pLevel->iCur, brk);
|
||||
}
|
||||
|
||||
/* Generate the start key. This is the key that defines the lower
|
||||
@@ -1059,7 +1034,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
&& (aExpr[k].prereqRight & loopMask)==aExpr[k].prereqRight
|
||||
&& pExpr->pLeft->iColumn==pIdx->aiColumn[j]
|
||||
){
|
||||
sqlite3ExprCode(pParse, pExpr->pRight);
|
||||
sqliteExprCode(pParse, pExpr->pRight);
|
||||
geFlag = pExpr->op==TK_GE;
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
@@ -1069,7 +1044,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
&& (aExpr[k].prereqLeft & loopMask)==aExpr[k].prereqLeft
|
||||
&& pExpr->pRight->iColumn==pIdx->aiColumn[j]
|
||||
){
|
||||
sqlite3ExprCode(pParse, pExpr->pLeft);
|
||||
sqliteExprCode(pParse, pExpr->pLeft);
|
||||
geFlag = pExpr->op==TK_LE;
|
||||
aExpr[k].p = 0;
|
||||
break;
|
||||
@@ -1080,44 +1055,43 @@ WhereInfo *sqlite3WhereBegin(
|
||||
}
|
||||
if( nEqColumn>0 || (score&2)!=0 ){
|
||||
int nCol = nEqColumn + ((score&2)!=0);
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -nCol, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, brk);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, nCol, 0);
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
sqliteVdbeAddOp(v, OP_NotNull, -nCol, sqliteVdbeCurrentAddr(v)+3);
|
||||
sqliteVdbeAddOp(v, OP_Pop, nCol, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, brk);
|
||||
sqliteVdbeAddOp(v, OP_MakeKey, nCol, 0);
|
||||
sqliteAddIdxKeyType(v, pIdx);
|
||||
if( !geFlag ){
|
||||
sqliteVdbeAddOp(v, OP_IncrKey, 0, 0);
|
||||
}
|
||||
if( pLevel->bRev ){
|
||||
pLevel->iMem = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
|
||||
testOp = OP_IdxLT;
|
||||
}else{
|
||||
int op = geFlag ? OP_MoveGe : OP_MoveGt;
|
||||
sqlite3VdbeAddOp(v, op, pLevel->iCur, brk);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, pLevel->iCur, brk);
|
||||
}
|
||||
}else if( pLevel->bRev ){
|
||||
testOp = OP_Noop;
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, pLevel->iCur, brk);
|
||||
sqliteVdbeAddOp(v, OP_Rewind, pLevel->iCur, brk);
|
||||
}
|
||||
|
||||
/* Generate the the top of the loop. If there is a termination
|
||||
** key we have to test for that key and abort at the top of the
|
||||
** loop.
|
||||
*/
|
||||
start = sqlite3VdbeCurrentAddr(v);
|
||||
start = sqliteVdbeCurrentAddr(v);
|
||||
if( testOp!=OP_Noop ){
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
|
||||
sqlite3VdbeAddOp(v, testOp, pLevel->iCur, brk);
|
||||
if( (leFlag && !pLevel->bRev) || (!geFlag && pLevel->bRev) ){
|
||||
sqlite3VdbeChangeP3(v, -1, "+", P3_STATIC);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
|
||||
sqliteVdbeAddOp(v, testOp, pLevel->iCur, brk);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_RowKey, pLevel->iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_IdxIsNull, nEqColumn + (score & 1), cont);
|
||||
sqlite3VdbeAddOp(v, OP_IdxRecno, pLevel->iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_RowKey, pLevel->iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_IdxIsNull, nEqColumn + (score & 1), cont);
|
||||
sqliteVdbeAddOp(v, OP_IdxRecno, pLevel->iCur, 0);
|
||||
if( i==pTabList->nSrc-1 && pushKey ){
|
||||
haveKey = 1;
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
|
||||
haveKey = 0;
|
||||
}
|
||||
|
||||
@@ -1140,9 +1114,9 @@ WhereInfo *sqlite3WhereBegin(
|
||||
}
|
||||
if( haveKey ){
|
||||
haveKey = 0;
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
|
||||
}
|
||||
sqlite3ExprIfFalse(pParse, aExpr[j].p, cont, 1);
|
||||
sqliteExprIfFalse(pParse, aExpr[j].p, cont, 1);
|
||||
aExpr[j].p = 0;
|
||||
}
|
||||
brk = cont;
|
||||
@@ -1151,9 +1125,9 @@ WhereInfo *sqlite3WhereBegin(
|
||||
** at least one row of the right table has matched the left table.
|
||||
*/
|
||||
if( pLevel->iLeftJoin ){
|
||||
pLevel->top = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iLeftJoin, 1);
|
||||
pLevel->top = sqliteVdbeCurrentAddr(v);
|
||||
sqliteVdbeAddOp(v, OP_Integer, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iLeftJoin, 1);
|
||||
for(j=0; j<nExpr; j++){
|
||||
if( aExpr[j].p==0 ) continue;
|
||||
if( (aExpr[j].prereqAll & loopMask)!=aExpr[j].prereqAll ) continue;
|
||||
@@ -1163,16 +1137,16 @@ WhereInfo *sqlite3WhereBegin(
|
||||
** no outer joins with DELETE and UPDATE.
|
||||
*/
|
||||
haveKey = 0;
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
|
||||
}
|
||||
sqlite3ExprIfFalse(pParse, aExpr[j].p, cont, 1);
|
||||
sqliteExprIfFalse(pParse, aExpr[j].p, cont, 1);
|
||||
aExpr[j].p = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
pWInfo->iContinue = cont;
|
||||
if( pushKey && !haveKey ){
|
||||
sqlite3VdbeAddOp(v, OP_Recno, pTabList->a[0].iCursor, 0);
|
||||
sqliteVdbeAddOp(v, OP_Recno, pTabList->a[0].iCursor, 0);
|
||||
}
|
||||
freeMaskSet(&maskSet);
|
||||
return pWInfo;
|
||||
@@ -1180,9 +1154,9 @@ WhereInfo *sqlite3WhereBegin(
|
||||
|
||||
/*
|
||||
** Generate the end of the WHERE loop. See comments on
|
||||
** sqlite3WhereBegin() for additional information.
|
||||
** sqliteWhereBegin() for additional information.
|
||||
*/
|
||||
void sqlite3WhereEnd(WhereInfo *pWInfo){
|
||||
void sqliteWhereEnd(WhereInfo *pWInfo){
|
||||
Vdbe *v = pWInfo->pParse->pVdbe;
|
||||
int i;
|
||||
WhereLevel *pLevel;
|
||||
@@ -1190,34 +1164,34 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
|
||||
|
||||
for(i=pTabList->nSrc-1; i>=0; i--){
|
||||
pLevel = &pWInfo->a[i];
|
||||
sqlite3VdbeResolveLabel(v, pLevel->cont);
|
||||
sqliteVdbeResolveLabel(v, pLevel->cont);
|
||||
if( pLevel->op!=OP_Noop ){
|
||||
sqlite3VdbeAddOp(v, pLevel->op, pLevel->p1, pLevel->p2);
|
||||
sqliteVdbeAddOp(v, pLevel->op, pLevel->p1, pLevel->p2);
|
||||
}
|
||||
sqlite3VdbeResolveLabel(v, pLevel->brk);
|
||||
sqliteVdbeResolveLabel(v, pLevel->brk);
|
||||
if( pLevel->inOp!=OP_Noop ){
|
||||
sqlite3VdbeAddOp(v, pLevel->inOp, pLevel->inP1, pLevel->inP2);
|
||||
sqliteVdbeAddOp(v, pLevel->inOp, pLevel->inP1, pLevel->inP2);
|
||||
}
|
||||
if( pLevel->iLeftJoin ){
|
||||
int addr;
|
||||
addr = sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iLeftJoin, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, 1, addr+4 + (pLevel->iCur>=0));
|
||||
sqlite3VdbeAddOp(v, OP_NullRow, pTabList->a[i].iCursor, 0);
|
||||
addr = sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iLeftJoin, 0);
|
||||
sqliteVdbeAddOp(v, OP_NotNull, 1, addr+4 + (pLevel->iCur>=0));
|
||||
sqliteVdbeAddOp(v, OP_NullRow, pTabList->a[i].iCursor, 0);
|
||||
if( pLevel->iCur>=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_NullRow, pLevel->iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_NullRow, pLevel->iCur, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, pLevel->top);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, pLevel->top);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
|
||||
sqliteVdbeResolveLabel(v, pWInfo->iBreak);
|
||||
for(i=0; i<pTabList->nSrc; i++){
|
||||
Table *pTab = pTabList->a[i].pTab;
|
||||
assert( pTab!=0 );
|
||||
if( pTab->isTransient || pTab->pSelect ) continue;
|
||||
pLevel = &pWInfo->a[i];
|
||||
sqlite3VdbeAddOp(v, OP_Close, pTabList->a[i].iCursor, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, pTabList->a[i].iCursor, 0);
|
||||
if( pLevel->pIdx!=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, pLevel->iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, pLevel->iCur, 0);
|
||||
}
|
||||
}
|
||||
#if 0 /* Never reuse a cursor */
|
||||
|
||||
+15
-49
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach.test,v 1.23 2004/06/09 00:48:15 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);
|
||||
@@ -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;
|
||||
@@ -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,62 +337,42 @@ 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}
|
||||
@@ -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);
|
||||
@@ -520,7 +487,7 @@ do_test attach-5.1 {
|
||||
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,7 +562,8 @@ 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 {
|
||||
sqlite dbx cannot-read
|
||||
@@ -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
|
||||
|
||||
+22
-226
@@ -12,18 +12,15 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach2.test,v 1.18 2004/06/14 09:41:18 danielk1977 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);
|
||||
@@ -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 1 temp 2 t2}
|
||||
db2 eval {COMMIT}
|
||||
|
||||
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 [sqlite db test.db]
|
||||
set rc [catch {sqlite3_prepare $DB "ATTACH 'test2.db' AS t2" -1 TAIL} VM]
|
||||
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,205 +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 {
|
||||
sqlite db test.db
|
||||
sqlite 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 unlocked file2 unlocked}
|
||||
lock_status 4.1.2 db2 {main unlocked temp unlocked 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 shared file2 unlocked}
|
||||
lock_status 4.2.2 db2 {main unlocked temp unlocked 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 shared file2 unlocked}
|
||||
lock_status 4.3.2 db2 {main unlocked temp unlocked 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 shared file2 unlocked}
|
||||
lock_status 4.4.2 db2 {main unlocked temp unlocked 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 shared file2 unlocked}
|
||||
lock_status 4.5.2 db2 {main unlocked temp reserved 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 shared file2 shared}
|
||||
lock_status 4.6.1.2 db2 {main unlocked temp reserved 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 reserved file2 shared}
|
||||
lock_status 4.6.2.2 db2 {main unlocked temp reserved 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 reserved file2 shared}
|
||||
lock_status 4.7.2 db2 {main reserved temp reserved 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 reserved file2 shared}
|
||||
lock_status 4.8.2 db2 {main reserved temp reserved 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 reserved file2 shared}
|
||||
lock_status 4.9.2 db2 {main reserved temp reserved file2 reserved}
|
||||
|
||||
btree_breakpoint
|
||||
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 reserved file2 shared}
|
||||
lock_status 4.10.2 db2 {main pending temp reserved file2 reserved}
|
||||
|
||||
set sqlite_os_trace 0
|
||||
btree_breakpoint
|
||||
do_test attach2-4.11 {
|
||||
# db is able to commit.
|
||||
catchsql {COMMIT}
|
||||
} {0 {}}
|
||||
|
||||
lock_status 4.11.1 db {main unlocked temp unlocked file2 unlocked}
|
||||
lock_status 4.11.2 db2 {main pending temp reserved 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 unlocked file2 unlocked}
|
||||
lock_status 4.12.2 db2 {main unlocked temp unlocked 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 {
|
||||
sqlite 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}
|
||||
|
||||
db close
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,219 +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.6 2004/06/07 07:52:19 danielk1977 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
|
||||
sqlite 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}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
|
||||
+48
-6
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: auth.test,v 1.14 2004/06/14 11:54:18 danielk1977 Exp $
|
||||
# $Id: auth.test,v 1.12 2003/12/07 00:24:35 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -417,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}
|
||||
|
||||
|
||||
+1
-2
@@ -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.4 2004/06/13 23:07:04 drh Exp $
|
||||
# $Id: bigfile.test,v 1.3 2003/12/19 12:31:22 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -67,7 +67,6 @@ do_test bigfile-1.2 {
|
||||
}
|
||||
} $::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
|
||||
|
||||
+8
-177
@@ -11,34 +11,17 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the sqlite_bind API.
|
||||
#
|
||||
# $Id: bind.test,v 1.11 2004/05/27 09:28:44 danielk1977 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 [sqlite db test.db]
|
||||
execsql {CREATE TABLE t1(a,b,c)}
|
||||
set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(?,?,?)} -1 TAIL]
|
||||
set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test bind-1.2 {
|
||||
@@ -48,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
|
||||
@@ -56,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
|
||||
@@ -64,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
|
||||
@@ -74,168 +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(?,?,?)} -1 TAIL]
|
||||
set TAIL
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
|
||||
# 32 bit Integers
|
||||
do_test bind-2.2 {
|
||||
sqlite3_bind_int32 $VM 1 123
|
||||
sqlite3_bind_int32 $VM 2 456
|
||||
sqlite3_bind_int32 $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_int32 $VM 2 -2000000000
|
||||
sqlite3_bind_int32 $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}
|
||||
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-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.1 2004/05/27 13:55:27 danielk1977 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 [sqlite 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
|
||||
|
||||
|
||||
+255
-270
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
|
||||
+134
-290
@@ -11,112 +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.13 2004/06/15 02:44:20 danielk1977 Exp $
|
||||
# $Id: capi2.test,v 1.10 2003/08/05 13:13:38 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# proc sqlite_step {stmt N VALS COLS} {
|
||||
# upvar $VALS vals
|
||||
# upvar $COLS cols
|
||||
# upvar $N n
|
||||
# set vals [list]
|
||||
# set cols [list]
|
||||
#
|
||||
# set n [sqlite3_column_count $stmt]
|
||||
#
|
||||
# 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_column_count $stmt]} {incr i} {
|
||||
# lappend cols [sqlite3_column_decltype $stmt $i]
|
||||
# }
|
||||
#
|
||||
# for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} {
|
||||
# lappend vals [sqlite3_column_text $stmt $i]
|
||||
# }
|
||||
#
|
||||
# return $rc
|
||||
# }
|
||||
|
||||
# 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 [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 {
|
||||
@@ -124,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
|
||||
} {{} {}}
|
||||
|
||||
@@ -169,232 +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]
|
||||
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?
|
||||
do_test capi2-3.10b {sqlite3_changes $DB} {1}
|
||||
do_test capi2-3.10b {db changes} {1}
|
||||
do_test capi2-3.11 {
|
||||
sqlite3_finalize $VM
|
||||
} {SQLITE_OK}
|
||||
do_test capi2-3.11b {sqlite3_changes $DB} {1}
|
||||
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 {} {}}
|
||||
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.
|
||||
#
|
||||
@@ -409,118 +297,80 @@ do_test capi2-6.1 {
|
||||
INSERT INTO t3 SELECT x+8 FROM t3;
|
||||
COMMIT;
|
||||
}
|
||||
set VM1 [sqlite3_prepare $DB {SELECT * FROM t3} -1 TAIL]
|
||||
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.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;}
|
||||
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 {
|
||||
@@ -529,10 +379,7 @@ do_test capi2-6.25 {
|
||||
}
|
||||
} {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 {
|
||||
@@ -541,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 {
|
||||
@@ -571,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;
|
||||
@@ -589,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 {
|
||||
@@ -603,7 +447,7 @@ do_test capi2-7.10 {
|
||||
}
|
||||
} {0 4 1 2 3 2 3 4 3 4 5 4 5 6}
|
||||
do_test capi2-7.11 {
|
||||
sqlite3_changes $DB
|
||||
db changes
|
||||
} {0}
|
||||
do_test capi2-7.12 {
|
||||
set x [stepsql $DB {EXPLAIN SELECT * FROM t1}]
|
||||
@@ -613,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
|
||||
|
||||
|
||||
-380
@@ -1,380 +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.10 2004/05/28 13:13:04 danielk1977 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
|
||||
#
|
||||
|
||||
db close
|
||||
set DB [sqlite 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
|
||||
} {}
|
||||
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.4 {
|
||||
sqlite3_close $db2
|
||||
} {}
|
||||
|
||||
# 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
|
||||
} {}
|
||||
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
|
||||
} {}
|
||||
|
||||
# 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
|
||||
|
||||
}
|
||||
|
||||
# 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_int $STMT $i]}
|
||||
set ints
|
||||
} $ints
|
||||
|
||||
# UTF-8
|
||||
do_test $test.3 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
|
||||
set utf8
|
||||
} $strings
|
||||
|
||||
# Floats
|
||||
do_test $test.4 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
|
||||
set utf8
|
||||
} $doubles
|
||||
|
||||
# UTF-16
|
||||
do_test $test.5 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]}
|
||||
set utf8
|
||||
} $strings
|
||||
|
||||
# Integers
|
||||
do_test $test.6 {
|
||||
set ints [list]
|
||||
foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]}
|
||||
set ints
|
||||
} $ints
|
||||
|
||||
# Floats
|
||||
do_test $test.7 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
|
||||
set utf8
|
||||
} $doubles
|
||||
|
||||
# UTF-8
|
||||
do_test $test.8 {
|
||||
set utf8 [list]
|
||||
foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
|
||||
set utf8
|
||||
} $strings
|
||||
|
||||
# Types
|
||||
do_test $test.9 {
|
||||
set types [list]
|
||||
foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}
|
||||
set types
|
||||
} $types
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
db 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.2 2004/06/11 10:51:41 danielk1977 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 12 101}
|
||||
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.2 2004/06/11 10:51:41 danielk1977 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
|
||||
sqlite 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
|
||||
sqlite 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
|
||||
sqlite 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 {
|
||||
sqlite 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
|
||||
sqlite 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
|
||||
sqlite 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
|
||||
@@ -1,697 +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: collate4.test,v 1.2 2004/06/11 10:51:41 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
db collate TEXT text_collate
|
||||
proc text_collate {a b} {
|
||||
return [string compare $a $b]
|
||||
}
|
||||
|
||||
# Do an SQL statement. Append the search count to the end of the result.
|
||||
#
|
||||
proc count sql {
|
||||
set ::sqlite_search_count 0
|
||||
return [concat [execsql $sql] $::sqlite_search_count]
|
||||
}
|
||||
|
||||
# This procedure executes the SQL. Then it checks the generated program
|
||||
# for the SQL and appends a "nosort" to the result if the program contains the
|
||||
# SortCallback opcode. If the program does not contain the SortCallback
|
||||
# opcode it appends "sort"
|
||||
#
|
||||
proc cksort {sql} {
|
||||
set data [execsql $sql]
|
||||
set prog [execsql "EXPLAIN $sql"]
|
||||
if {[regexp Sort $prog]} {set x sort} {set x nosort}
|
||||
lappend data $x
|
||||
return $data
|
||||
}
|
||||
|
||||
#
|
||||
# Test cases are organized roughly as follows:
|
||||
#
|
||||
# collate4-1.* ORDER BY.
|
||||
# collate4-2.* WHERE clauses.
|
||||
# collate4-3.* constraints (primary key, unique).
|
||||
# collate4-4.* simple min() or max() queries.
|
||||
# collate4-5.* REINDEX command
|
||||
# collate4-6.* INTEGER PRIMARY KEY indices.
|
||||
#
|
||||
|
||||
#
|
||||
# These tests - collate4-1.* - check that indices are correctly
|
||||
# selected or not selected to implement ORDER BY clauses when
|
||||
# user defined collation sequences are involved.
|
||||
#
|
||||
# Because these tests also exercise all the different ways indices
|
||||
# can be created, they also serve to verify that indices are correctly
|
||||
# initialised with user-defined collation sequences when they are
|
||||
# created.
|
||||
#
|
||||
# Tests named collate4-1.1.* use indices with a single column. Tests
|
||||
# collate4-1.2.* use indices with two columns.
|
||||
#
|
||||
do_test collate4-1.1.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t1(a COLLATE NOCASE, b COLLATE TEXT);
|
||||
INSERT INTO collate4t1 VALUES( 'a', 'a' );
|
||||
INSERT INTO collate4t1 VALUES( 'b', 'b' );
|
||||
INSERT INTO collate4t1 VALUES( NULL, NULL );
|
||||
INSERT INTO collate4t1 VALUES( 'B', 'B' );
|
||||
INSERT INTO collate4t1 VALUES( 'A', 'A' );
|
||||
CREATE INDEX collate4i1 ON collate4t1(a);
|
||||
CREATE INDEX collate4i2 ON collate4t1(b);
|
||||
}
|
||||
} {}
|
||||
do_test collate4-1.1.1 {
|
||||
cksort {SELECT a FROM collate4t1 ORDER BY a}
|
||||
} {{} a A b B nosort}
|
||||
do_test collate4-1.1.2 {
|
||||
cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE NOCASE}
|
||||
} {{} a A b B nosort}
|
||||
do_test collate4-1.1.3 {
|
||||
cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE TEXT}
|
||||
} {{} A B a b sort}
|
||||
do_test collate4-1.1.4 {
|
||||
cksort {SELECT b FROM collate4t1 ORDER BY b}
|
||||
} {{} A B a b nosort}
|
||||
do_test collate4-1.1.5 {
|
||||
cksort {SELECT b FROM collate4t1 ORDER BY b COLLATE TEXT}
|
||||
} {{} A B a b nosort}
|
||||
do_test collate4-1.1.6 {
|
||||
cksort {SELECT b FROM collate4t1 ORDER BY b COLLATE NOCASE}
|
||||
} {{} A a B b sort}
|
||||
|
||||
do_test collate4-1.1.7 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t2(
|
||||
a PRIMARY KEY COLLATE NOCASE,
|
||||
b UNIQUE COLLATE TEXT
|
||||
);
|
||||
INSERT INTO collate4t2 VALUES( 'a', 'a' );
|
||||
INSERT INTO collate4t2 VALUES( NULL, NULL );
|
||||
INSERT INTO collate4t2 VALUES( 'B', 'B' );
|
||||
}
|
||||
} {}
|
||||
do_test collate4-1.1.8 {
|
||||
cksort {SELECT a FROM collate4t2 ORDER BY a}
|
||||
} {{} a B nosort}
|
||||
do_test collate4-1.1.9 {
|
||||
cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE NOCASE}
|
||||
} {{} a B nosort}
|
||||
do_test collate4-1.1.10 {
|
||||
cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE TEXT}
|
||||
} {{} B a sort}
|
||||
do_test collate4-1.1.11 {
|
||||
cksort {SELECT b FROM collate4t2 ORDER BY b}
|
||||
} {{} B a nosort}
|
||||
do_test collate4-1.1.12 {
|
||||
cksort {SELECT b FROM collate4t2 ORDER BY b COLLATE TEXT}
|
||||
} {{} B a nosort}
|
||||
do_test collate4-1.1.13 {
|
||||
cksort {SELECT b FROM collate4t2 ORDER BY b COLLATE NOCASE}
|
||||
} {{} a B sort}
|
||||
|
||||
do_test collate4-1.1.14 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t3(
|
||||
b COLLATE TEXT,
|
||||
a COLLATE NOCASE,
|
||||
UNIQUE(a), PRIMARY KEY(b)
|
||||
);
|
||||
INSERT INTO collate4t3 VALUES( 'a', 'a' );
|
||||
INSERT INTO collate4t3 VALUES( NULL, NULL );
|
||||
INSERT INTO collate4t3 VALUES( 'B', 'B' );
|
||||
}
|
||||
} {}
|
||||
do_test collate4-1.1.15 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a}
|
||||
} {{} a B nosort}
|
||||
do_test collate4-1.1.16 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE NOCASE}
|
||||
} {{} a B nosort}
|
||||
do_test collate4-1.1.17 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE TEXT}
|
||||
} {{} B a sort}
|
||||
do_test collate4-1.1.18 {
|
||||
cksort {SELECT b FROM collate4t3 ORDER BY b}
|
||||
} {{} B a nosort}
|
||||
do_test collate4-1.1.19 {
|
||||
cksort {SELECT b FROM collate4t3 ORDER BY b COLLATE TEXT}
|
||||
} {{} B a nosort}
|
||||
do_test collate4-1.1.20 {
|
||||
cksort {SELECT b FROM collate4t3 ORDER BY b COLLATE NOCASE}
|
||||
} {{} a B sort}
|
||||
|
||||
do_test collate4-1.1.21 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t4(a COLLATE NOCASE, b COLLATE TEXT);
|
||||
INSERT INTO collate4t4 VALUES( 'a', 'a' );
|
||||
INSERT INTO collate4t4 VALUES( 'b', 'b' );
|
||||
INSERT INTO collate4t4 VALUES( NULL, NULL );
|
||||
INSERT INTO collate4t4 VALUES( 'B', 'B' );
|
||||
INSERT INTO collate4t4 VALUES( 'A', 'A' );
|
||||
CREATE INDEX collate4i3 ON collate4t4(a COLLATE TEXT);
|
||||
CREATE INDEX collate4i4 ON collate4t4(b COLLATE NOCASE);
|
||||
}
|
||||
} {}
|
||||
do_test collate4-1.1.22 {
|
||||
cksort {SELECT a FROM collate4t4 ORDER BY a}
|
||||
} {{} A a B b sort}
|
||||
do_test collate4-1.1.23 {
|
||||
cksort {SELECT a FROM collate4t4 ORDER BY a COLLATE NOCASE}
|
||||
} {{} A a B b sort}
|
||||
do_test collate4-1.1.24 {
|
||||
cksort {SELECT a FROM collate4t4 ORDER BY a COLLATE TEXT}
|
||||
} {{} A B a b nosort}
|
||||
do_test collate4-1.1.25 {
|
||||
cksort {SELECT b FROM collate4t4 ORDER BY b}
|
||||
} {{} A B a b sort}
|
||||
do_test collate4-1.1.26 {
|
||||
cksort {SELECT b FROM collate4t4 ORDER BY b COLLATE TEXT}
|
||||
} {{} A B a b sort}
|
||||
do_test collate4-1.1.27 {
|
||||
cksort {SELECT b FROM collate4t4 ORDER BY b COLLATE NOCASE}
|
||||
} {{} a A b B nosort}
|
||||
|
||||
do_test collate4-1.1.30 {
|
||||
execsql {
|
||||
DROP TABLE collate4t1;
|
||||
DROP TABLE collate4t2;
|
||||
DROP TABLE collate4t3;
|
||||
DROP TABLE collate4t4;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test collate4-1.2.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t1(a COLLATE NOCASE, b COLLATE TEXT);
|
||||
INSERT INTO collate4t1 VALUES( 'a', 'a' );
|
||||
INSERT INTO collate4t1 VALUES( 'b', 'b' );
|
||||
INSERT INTO collate4t1 VALUES( NULL, NULL );
|
||||
INSERT INTO collate4t1 VALUES( 'B', 'B' );
|
||||
INSERT INTO collate4t1 VALUES( 'A', 'A' );
|
||||
CREATE INDEX collate4i1 ON collate4t1(a, b);
|
||||
}
|
||||
} {}
|
||||
do_test collate4-1.2.1 {
|
||||
cksort {SELECT a FROM collate4t1 ORDER BY a}
|
||||
} {{} A a B b nosort}
|
||||
do_test collate4-1.2.2 {
|
||||
cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE nocase}
|
||||
} {{} A a B b nosort}
|
||||
do_test collate4-1.2.3 {
|
||||
cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE text}
|
||||
} {{} A B a b sort}
|
||||
do_test collate4-1.2.4 {
|
||||
cksort {SELECT a FROM collate4t1 ORDER BY a, b}
|
||||
} {{} A a B b nosort}
|
||||
do_test collate4-1.2.5 {
|
||||
cksort {SELECT a FROM collate4t1 ORDER BY a, b COLLATE nocase}
|
||||
} {{} A a B b sort}
|
||||
do_test collate4-1.2.6 {
|
||||
cksort {SELECT a FROM collate4t1 ORDER BY a, b COLLATE text}
|
||||
} {{} A a B b nosort}
|
||||
|
||||
do_test collate4-1.2.7 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t2(
|
||||
a COLLATE NOCASE,
|
||||
b COLLATE TEXT,
|
||||
PRIMARY KEY(a, b)
|
||||
);
|
||||
INSERT INTO collate4t2 VALUES( 'a', 'a' );
|
||||
INSERT INTO collate4t2 VALUES( NULL, NULL );
|
||||
INSERT INTO collate4t2 VALUES( 'B', 'B' );
|
||||
}
|
||||
} {}
|
||||
do_test collate4-1.2.8 {
|
||||
cksort {SELECT a FROM collate4t2 ORDER BY a}
|
||||
} {{} a B nosort}
|
||||
do_test collate4-1.2.9 {
|
||||
cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE nocase}
|
||||
} {{} a B nosort}
|
||||
do_test collate4-1.2.10 {
|
||||
cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE text}
|
||||
} {{} B a sort}
|
||||
do_test collate4-1.2.11 {
|
||||
cksort {SELECT a FROM collate4t2 ORDER BY a, b}
|
||||
} {{} a B nosort}
|
||||
do_test collate4-1.2.12 {
|
||||
cksort {SELECT a FROM collate4t2 ORDER BY a, b COLLATE nocase}
|
||||
} {{} a B sort}
|
||||
do_test collate4-1.2.13 {
|
||||
cksort {SELECT a FROM collate4t2 ORDER BY a, b COLLATE text}
|
||||
} {{} a B nosort}
|
||||
|
||||
do_test collate4-1.2.14 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t3(a COLLATE NOCASE, b COLLATE TEXT);
|
||||
INSERT INTO collate4t3 VALUES( 'a', 'a' );
|
||||
INSERT INTO collate4t3 VALUES( 'b', 'b' );
|
||||
INSERT INTO collate4t3 VALUES( NULL, NULL );
|
||||
INSERT INTO collate4t3 VALUES( 'B', 'B' );
|
||||
INSERT INTO collate4t3 VALUES( 'A', 'A' );
|
||||
CREATE INDEX collate4i2 ON collate4t3(a COLLATE TEXT, b COLLATE NOCASE);
|
||||
}
|
||||
} {}
|
||||
do_test collate4-1.2.15 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a}
|
||||
} {{} A a B b sort}
|
||||
do_test collate4-1.2.16 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE nocase}
|
||||
} {{} A a B b sort}
|
||||
do_test collate4-1.2.17 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text}
|
||||
} {{} A B a b nosort}
|
||||
do_test collate4-1.2.18 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text, b}
|
||||
} {{} A B a b sort}
|
||||
do_test collate4-1.2.19 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text, b COLLATE nocase}
|
||||
} {{} A B a b nosort}
|
||||
do_test collate4-1.2.20 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text, b COLLATE text}
|
||||
} {{} A B a b sort}
|
||||
do_test collate4-1.2.21 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text DESC}
|
||||
} {b a B A {} nosort}
|
||||
do_test collate4-1.2.22 {
|
||||
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text DESC, b}
|
||||
} {b a B A {} sort}
|
||||
do_test collate4-1.2.23 {
|
||||
cksort {SELECT a FROM collate4t3
|
||||
ORDER BY a COLLATE text DESC, b COLLATE nocase}
|
||||
} {b a B A {} sort}
|
||||
do_test collate4-1.2.24 {
|
||||
cksort {SELECT a FROM collate4t3
|
||||
ORDER BY a COLLATE text DESC, b COLLATE nocase DESC}
|
||||
} {b a B A {} nosort}
|
||||
|
||||
do_test collate4-1.2.25 {
|
||||
execsql {
|
||||
DROP TABLE collate4t1;
|
||||
DROP TABLE collate4t2;
|
||||
DROP TABLE collate4t3;
|
||||
}
|
||||
} {}
|
||||
|
||||
#
|
||||
# These tests - collate4-2.* - check that indices are correctly
|
||||
# selected or not selected to implement WHERE clauses when user
|
||||
# defined collation sequences are involved.
|
||||
#
|
||||
# Indices may optimise WHERE clauses using <, >, <=, >=, = or IN
|
||||
# operators.
|
||||
#
|
||||
do_test collate4-2.1.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t1(a COLLATE NOCASE);
|
||||
CREATE TABLE collate4t2(b COLLATE TEXT);
|
||||
|
||||
INSERT INTO collate4t1 VALUES('a');
|
||||
INSERT INTO collate4t1 VALUES('A');
|
||||
INSERT INTO collate4t1 VALUES('b');
|
||||
INSERT INTO collate4t1 VALUES('B');
|
||||
INSERT INTO collate4t1 VALUES('c');
|
||||
INSERT INTO collate4t1 VALUES('C');
|
||||
INSERT INTO collate4t1 VALUES('d');
|
||||
INSERT INTO collate4t1 VALUES('D');
|
||||
INSERT INTO collate4t1 VALUES('e');
|
||||
INSERT INTO collate4t1 VALUES('D');
|
||||
|
||||
INSERT INTO collate4t2 VALUES('A');
|
||||
INSERT INTO collate4t2 VALUES('Z');
|
||||
}
|
||||
} {}
|
||||
do_test collate4-2.1.1 {
|
||||
count {
|
||||
SELECT * FROM collate4t2, collate4t1 WHERE a = b;
|
||||
}
|
||||
} {A a A A 19}
|
||||
do_test collate4-2.1.2 {
|
||||
execsql {
|
||||
CREATE INDEX collate4i1 ON collate4t1(a);
|
||||
}
|
||||
count {
|
||||
SELECT * FROM collate4t2, collate4t1 WHERE a = b;
|
||||
}
|
||||
} {A a A A 7}
|
||||
do_test collate4-2.1.3 {
|
||||
count {
|
||||
SELECT * FROM collate4t2, collate4t1 WHERE b = a;
|
||||
}
|
||||
} {A A 19}
|
||||
do_test collate4-2.1.4 {
|
||||
execsql {
|
||||
DROP INDEX collate4i1;
|
||||
CREATE INDEX collate4i1 ON collate4t1(a COLLATE TEXT);
|
||||
}
|
||||
count {
|
||||
SELECT * FROM collate4t2, collate4t1 WHERE a = b;
|
||||
}
|
||||
} {A a A A 19}
|
||||
do_test collate4-2.1.5 {
|
||||
count {
|
||||
SELECT * FROM collate4t2, collate4t1 WHERE b = a;
|
||||
}
|
||||
} {A A 5}
|
||||
do_test collate4-2.1.6 {
|
||||
count {
|
||||
SELECT a FROM collate4t1 WHERE a IN (SELECT * FROM collate4t2);
|
||||
}
|
||||
} {a A 10}
|
||||
do_test collate4-2.1.7 {
|
||||
execsql {
|
||||
DROP INDEX collate4i1;
|
||||
CREATE INDEX collate4i1 ON collate4t1(a);
|
||||
}
|
||||
count {
|
||||
SELECT a FROM collate4t1 WHERE a IN (SELECT * FROM collate4t2);
|
||||
}
|
||||
} {a A 8}
|
||||
do_test collate4-2.1.8 {
|
||||
count {
|
||||
SELECT a FROM collate4t1 WHERE a IN ('z', 'a');
|
||||
}
|
||||
} {a A 7}
|
||||
do_test collate4-2.1.9 {
|
||||
execsql {
|
||||
DROP INDEX collate4i1;
|
||||
CREATE INDEX collate4i1 ON collate4t1(a COLLATE TEXT);
|
||||
}
|
||||
count {
|
||||
SELECT a FROM collate4t1 WHERE a IN ('z', 'a');
|
||||
}
|
||||
} {a A 9}
|
||||
do_test collate4-2.1.10 {
|
||||
execsql {
|
||||
DROP TABLE collate4t1;
|
||||
DROP TABLE collate4t2;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test collate4-2.2.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t1(a COLLATE nocase, b COLLATE text, c);
|
||||
CREATE TABLE collate4t2(a COLLATE nocase, b COLLATE text, c COLLATE TEXT);
|
||||
|
||||
INSERT INTO collate4t1 VALUES('0', '0', '0');
|
||||
INSERT INTO collate4t1 VALUES('0', '0', '1');
|
||||
INSERT INTO collate4t1 VALUES('0', '1', '0');
|
||||
INSERT INTO collate4t1 VALUES('0', '1', '1');
|
||||
INSERT INTO collate4t1 VALUES('1', '0', '0');
|
||||
INSERT INTO collate4t1 VALUES('1', '0', '1');
|
||||
INSERT INTO collate4t1 VALUES('1', '1', '0');
|
||||
INSERT INTO collate4t1 VALUES('1', '1', '1');
|
||||
insert into collate4t2 SELECT * FROM collate4t1;
|
||||
}
|
||||
} {}
|
||||
do_test collate4-2.2.1 {
|
||||
count {
|
||||
SELECT * FROM collate4t2 NATURAL JOIN collate4t1;
|
||||
}
|
||||
} {0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 63}
|
||||
do_test collate4-2.2.1 {
|
||||
execsql {
|
||||
CREATE INDEX collate4i1 ON collate4t1(a, b, c);
|
||||
}
|
||||
count {
|
||||
SELECT * FROM collate4t2 NATURAL JOIN collate4t1;
|
||||
}
|
||||
} {0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 45}
|
||||
do_test collate4-2.2.2 {
|
||||
execsql {
|
||||
DROP INDEX collate4i1;
|
||||
CREATE INDEX collate4i1 ON collate4t1(a, b, c COLLATE text);
|
||||
}
|
||||
count {
|
||||
SELECT * FROM collate4t2 NATURAL JOIN collate4t1;
|
||||
}
|
||||
} {0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 22}
|
||||
|
||||
do_test collate4-2.2.10 {
|
||||
execsql {
|
||||
DROP TABLE collate4t1;
|
||||
DROP TABLE collate4t2;
|
||||
}
|
||||
} {}
|
||||
|
||||
#
|
||||
# These tests - collate4-3.* verify that indices that implement
|
||||
# UNIQUE and PRIMARY KEY constraints operate correctly with user
|
||||
# defined collation sequences.
|
||||
#
|
||||
do_test collate4-3.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t1(a PRIMARY KEY COLLATE NOCASE);
|
||||
}
|
||||
} {}
|
||||
do_test collate4-3.1 {
|
||||
catchsql {
|
||||
INSERT INTO collate4t1 VALUES('abc');
|
||||
INSERT INTO collate4t1 VALUES('ABC');
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
do_test collate4-3.2 {
|
||||
execsql {
|
||||
SELECT * FROM collate4t1;
|
||||
}
|
||||
} {abc}
|
||||
do_test collate4-3.3 {
|
||||
catchsql {
|
||||
INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1;
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
do_test collate4-3.4 {
|
||||
catchsql {
|
||||
INSERT INTO collate4t1 VALUES(1);
|
||||
UPDATE collate4t1 SET a = 'abc';
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
do_test collate4-3.5 {
|
||||
execsql {
|
||||
DROP TABLE collate4t1;
|
||||
CREATE TABLE collate4t1(a COLLATE NOCASE UNIQUE);
|
||||
}
|
||||
} {}
|
||||
do_test collate4-3.6 {
|
||||
catchsql {
|
||||
INSERT INTO collate4t1 VALUES('abc');
|
||||
INSERT INTO collate4t1 VALUES('ABC');
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
do_test collate4-3.7 {
|
||||
execsql {
|
||||
SELECT * FROM collate4t1;
|
||||
}
|
||||
} {abc}
|
||||
do_test collate4-3.8 {
|
||||
catchsql {
|
||||
INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1;
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
do_test collate4-3.9 {
|
||||
catchsql {
|
||||
INSERT INTO collate4t1 VALUES(1);
|
||||
UPDATE collate4t1 SET a = 'abc';
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
do_test collate4-3.10 {
|
||||
execsql {
|
||||
DROP TABLE collate4t1;
|
||||
CREATE TABLE collate4t1(a);
|
||||
CREATE UNIQUE INDEX collate4i1 ON collate4t1(a COLLATE NOCASE);
|
||||
}
|
||||
} {}
|
||||
do_test collate4-3.11 {
|
||||
catchsql {
|
||||
INSERT INTO collate4t1 VALUES('abc');
|
||||
INSERT INTO collate4t1 VALUES('ABC');
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
do_test collate4-3.12 {
|
||||
execsql {
|
||||
SELECT * FROM collate4t1;
|
||||
}
|
||||
} {abc}
|
||||
do_test collate4-3.13 {
|
||||
catchsql {
|
||||
INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1;
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
do_test collate4-3.14 {
|
||||
catchsql {
|
||||
INSERT INTO collate4t1 VALUES(1);
|
||||
UPDATE collate4t1 SET a = 'abc';
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
|
||||
do_test collate4-3.15 {
|
||||
execsql {
|
||||
DROP TABLE collate4t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# 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]
|
||||
}
|
||||
|
||||
#
|
||||
# These tests - collate4-4.* check that min() and max() only ever
|
||||
# use indices constructed with built-in collation type numeric.
|
||||
#
|
||||
# CHANGED: min() and max() now use the collation type. If there
|
||||
# is an indice that can be used, it is used.
|
||||
#
|
||||
do_test collate4-4.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t1(a COLLATE TEXT);
|
||||
INSERT INTO collate4t1 VALUES('2');
|
||||
INSERT INTO collate4t1 VALUES('10');
|
||||
INSERT INTO collate4t1 VALUES('20');
|
||||
INSERT INTO collate4t1 VALUES('104');
|
||||
}
|
||||
} {}
|
||||
do_test collate4-4.1 {
|
||||
count {
|
||||
SELECT max(a) FROM collate4t1
|
||||
}
|
||||
} {20 3}
|
||||
do_test collate4-4.2 {
|
||||
count {
|
||||
SELECT min(a) FROM collate4t1
|
||||
}
|
||||
} {10 3}
|
||||
do_test collate4-4.3 {
|
||||
# Test that the index with collation type TEXT is used.
|
||||
execsql {
|
||||
CREATE INDEX collate4i1 ON collate4t1(a);
|
||||
}
|
||||
count {
|
||||
SELECT min(a) FROM collate4t1;
|
||||
}
|
||||
} {10 1}
|
||||
do_test collate4-4.4 {
|
||||
count {
|
||||
SELECT max(a) FROM collate4t1;
|
||||
}
|
||||
} {20 1}
|
||||
do_test collate4-4.5 {
|
||||
# Test that the index with collation type NUMERIC is not used.
|
||||
execsql {
|
||||
DROP INDEX collate4i1;
|
||||
CREATE INDEX collate4i1 ON collate4t1(a COLLATE NUMERIC);
|
||||
}
|
||||
count {
|
||||
SELECT min(a) FROM collate4t1;
|
||||
}
|
||||
} {10 3}
|
||||
do_test collate4-4.6 {
|
||||
count {
|
||||
SELECT max(a) FROM collate4t1;
|
||||
}
|
||||
} {20 3}
|
||||
do_test collate4-4.7 {
|
||||
execsql {
|
||||
DROP TABLE collate4t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Also test the scalar min() and max() functions.
|
||||
#
|
||||
do_test collate4-4.8 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t1(a COLLATE TEXT, b COLLATE NUMERIC);
|
||||
INSERT INTO collate4t1 VALUES('11', '101');
|
||||
INSERT INTO collate4t1 VALUES('101', '11')
|
||||
}
|
||||
} {}
|
||||
do_test collate4-4.9 {
|
||||
execsql {
|
||||
SELECT max(a, b) FROM collate4t1;
|
||||
}
|
||||
} {11 11}
|
||||
do_test collate4-4.10 {
|
||||
execsql {
|
||||
SELECT max(b, a) FROM collate4t1;
|
||||
}
|
||||
} {101 101}
|
||||
do_test collate4-4.11 {
|
||||
execsql {
|
||||
SELECT max(a, '101') FROM collate4t1;
|
||||
}
|
||||
} {11 101}
|
||||
do_test collate4-4.12 {
|
||||
execsql {
|
||||
SELECT max('101', a) FROM collate4t1;
|
||||
}
|
||||
} {11 101}
|
||||
do_test collate4-4.13 {
|
||||
execsql {
|
||||
SELECT max(b, '101') FROM collate4t1;
|
||||
}
|
||||
} {101 101}
|
||||
do_test collate4-4.14 {
|
||||
execsql {
|
||||
SELECT max('101', b) FROM collate4t1;
|
||||
}
|
||||
} {101 101}
|
||||
|
||||
do_test collate4-4.15 {
|
||||
execsql {
|
||||
DROP TABLE collate4t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
#
|
||||
# These tests - collate4.6.* - ensure that implict INTEGER PRIMARY KEY
|
||||
# indices do not confuse collation sequences.
|
||||
#
|
||||
# These indices are never used for sorting in SQLite. And you can't
|
||||
# create another index on an INTEGER PRIMARY KEY column, so we don't have
|
||||
# to test that.
|
||||
#
|
||||
do_test collate4-6.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate4t1(a INTEGER PRIMARY KEY);
|
||||
INSERT INTO collate4t1 VALUES(101);
|
||||
INSERT INTO collate4t1 VALUES(10);
|
||||
INSERT INTO collate4t1 VALUES(15);
|
||||
}
|
||||
} {}
|
||||
do_test collate4-6.1 {
|
||||
cksort {
|
||||
SELECT * FROM collate4t1 ORDER BY 1;
|
||||
}
|
||||
} {10 15 101 sort}
|
||||
do_test collate4-6.2 {
|
||||
cksort {
|
||||
SELECT * FROM collate4t1 ORDER BY oid;
|
||||
}
|
||||
} {10 15 101 sort}
|
||||
do_test collate4-6.3 {
|
||||
cksort {
|
||||
SELECT * FROM collate4t1 ORDER BY oid||'' COLLATE TEXT;
|
||||
}
|
||||
} {10 101 15 sort}
|
||||
|
||||
finish_test
|
||||
@@ -1,264 +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 file is testing DISTINCT, UNION, INTERSECT and EXCEPT
|
||||
# SELECT statements that use user-defined collation sequences. Also
|
||||
# GROUP BY clauses that use user-defined collation sequences.
|
||||
#
|
||||
# $Id: collate5.test,v 1.1 2004/06/11 10:51:41 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
#
|
||||
# Tests are organised as follows:
|
||||
# collate5-1.* - DISTINCT
|
||||
# collate5-2.* - Compound SELECT
|
||||
# collate5-3.* - ORDER BY on compound SELECT
|
||||
# collate5-4.* - GROUP BY
|
||||
|
||||
# Create the collation sequence 'TEXT', purely for asthetic reasons. The
|
||||
# test cases in this script could just as easily use BINARY.
|
||||
db collate TEXT [list string compare]
|
||||
|
||||
# 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]
|
||||
}
|
||||
|
||||
#
|
||||
# These tests - collate5-1.* - focus on the DISTINCT keyword.
|
||||
#
|
||||
do_test collate5-1.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate5t1(a COLLATE nocase, b COLLATE text);
|
||||
|
||||
INSERT INTO collate5t1 VALUES('a', 'apple');
|
||||
INSERT INTO collate5t1 VALUES('A', 'Apple');
|
||||
INSERT INTO collate5t1 VALUES('b', 'banana');
|
||||
INSERT INTO collate5t1 VALUES('B', 'banana');
|
||||
INSERT INTO collate5t1 VALUES('n', NULL);
|
||||
INSERT INTO collate5t1 VALUES('N', NULL);
|
||||
}
|
||||
} {}
|
||||
do_test collate5-1.1 {
|
||||
execsql {
|
||||
SELECT DISTINCT a FROM collate5t1;
|
||||
}
|
||||
} {a b n}
|
||||
do_test collate5-1.2 {
|
||||
execsql {
|
||||
SELECT DISTINCT b FROM collate5t1;
|
||||
}
|
||||
} {apple Apple banana {}}
|
||||
do_test collate5-1.3 {
|
||||
execsql {
|
||||
SELECT DISTINCT a, b FROM collate5t1;
|
||||
}
|
||||
} {a apple A Apple b banana n {}}
|
||||
|
||||
|
||||
#
|
||||
# Tests named collate5-2.* focus on UNION, EXCEPT and INTERSECT
|
||||
# queries that use user-defined collation sequences.
|
||||
#
|
||||
# collate5-2.1.* - UNION
|
||||
# collate5-2.2.* - INTERSECT
|
||||
# collate5-2.3.* - EXCEPT
|
||||
#
|
||||
do_test collate5-2.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate5t2(a COLLATE text, b COLLATE nocase);
|
||||
|
||||
INSERT INTO collate5t2 VALUES('a', 'apple');
|
||||
INSERT INTO collate5t2 VALUES('A', 'apple');
|
||||
INSERT INTO collate5t2 VALUES('b', 'banana');
|
||||
INSERT INTO collate5t2 VALUES('B', 'Banana');
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test collate5-2.1.1 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t1 UNION select a FROM collate5t2;
|
||||
}
|
||||
} {A B N}
|
||||
do_test collate5-2.1.2 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t2 UNION select a FROM collate5t1;
|
||||
}
|
||||
} {A B N a b n}
|
||||
do_test collate5-2.1.3 {
|
||||
execsql {
|
||||
SELECT a, b FROM collate5t1 UNION select a, b FROM collate5t2;
|
||||
}
|
||||
} {A Apple A apple B Banana b banana N {}}
|
||||
do_test collate5-2.1.4 {
|
||||
execsql {
|
||||
SELECT a, b FROM collate5t2 UNION select a, b FROM collate5t1;
|
||||
}
|
||||
} {A Apple B banana N {} a apple b banana n {}}
|
||||
|
||||
do_test collate5-2.2.1 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t1 EXCEPT select a FROM collate5t2;
|
||||
}
|
||||
} {N}
|
||||
do_test collate5-2.2.2 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t2 EXCEPT select a FROM collate5t1 WHERE a != 'a';
|
||||
}
|
||||
} {A a}
|
||||
do_test collate5-2.2.3 {
|
||||
execsql {
|
||||
SELECT a, b FROM collate5t1 EXCEPT select a, b FROM collate5t2;
|
||||
}
|
||||
} {A Apple N {}}
|
||||
do_test collate5-2.2.4 {
|
||||
execsql {
|
||||
SELECT a, b FROM collate5t2 EXCEPT select a, b FROM collate5t1
|
||||
where a != 'a';
|
||||
}
|
||||
} {A apple a apple}
|
||||
|
||||
do_test collate5-2.3.1 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t1 INTERSECT select a FROM collate5t2;
|
||||
}
|
||||
} {A B}
|
||||
do_test collate5-2.3.2 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t2 INTERSECT select a FROM collate5t1 WHERE a != 'a';
|
||||
}
|
||||
} {B b}
|
||||
do_test collate5-2.3.3 {
|
||||
execsql {
|
||||
SELECT a, b FROM collate5t1 INTERSECT select a, b FROM collate5t2;
|
||||
}
|
||||
} {a apple B banana}
|
||||
do_test collate5-2.3.4 {
|
||||
execsql {
|
||||
SELECT a, b FROM collate5t2 INTERSECT select a, b FROM collate5t1;
|
||||
}
|
||||
} {A apple B Banana a apple b banana}
|
||||
|
||||
#
|
||||
# This test ensures performs a UNION operation with a bunch of different
|
||||
# length records. The goal is to test that the logic that compares records
|
||||
# for the compound SELECT operators works with record lengths that lie
|
||||
# either side of the troublesome 256 and 65536 byte marks.
|
||||
#
|
||||
set ::lens [list \
|
||||
0 1 2 3 4 5 6 7 8 9 \
|
||||
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 \
|
||||
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 \
|
||||
65520 65521 65522 65523 65524 65525 65526 65527 65528 65529 65530 \
|
||||
65531 65532 65533 65534 65535 65536 65537 65538 65539 65540 65541 \
|
||||
65542 65543 65544 65545 65546 65547 65548 65549 65550 65551 ]
|
||||
do_test collate5-2.4.0 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE collate5t3(a, b);
|
||||
}
|
||||
foreach ii $::lens {
|
||||
execsql "INSERT INTO collate5t3 VALUES($ii, '[string repeat a $ii]');"
|
||||
}
|
||||
execsql {
|
||||
COMMIT;
|
||||
SELECT count(*) FROM
|
||||
(SELECT * FROM collate5t3 UNION SELECT * FROM collate5t3);
|
||||
}
|
||||
} [llength $::lens]
|
||||
do_test collate5-2.4.1 {
|
||||
execsql {DROP TABLE collate5t3;}
|
||||
} {}
|
||||
unset ::lens
|
||||
|
||||
#
|
||||
# These tests - collate5-3.* - focus on compound SELECT queries that
|
||||
# feature ORDER BY clauses.
|
||||
#
|
||||
do_test collate5-3.0 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t1 UNION ALL SELECT a FROM collate5t2 ORDER BY 1;
|
||||
}
|
||||
} {A a A a B b B b N n}
|
||||
do_test collate5-3.1 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t2 UNION ALL SELECT a FROM collate5t1 ORDER BY 1;
|
||||
}
|
||||
} {A A B B N a a b b n}
|
||||
do_test collate5-3.2 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t1 UNION ALL SELECT a FROM collate5t2
|
||||
ORDER BY 1 COLLATE TEXT;
|
||||
}
|
||||
} {A A B B N a a b b n}
|
||||
|
||||
do_test collate5-3.3 {
|
||||
execsql {
|
||||
CREATE TABLE collate5t_cn(a COLLATE NUMERIC);
|
||||
CREATE TABLE collate5t_ct(a COLLATE TEXT);
|
||||
INSERT INTO collate5t_cn VALUES('1');
|
||||
INSERT INTO collate5t_cn VALUES('11');
|
||||
INSERT INTO collate5t_cn VALUES('101');
|
||||
INSERT INTO collate5t_ct SELECT * FROM collate5t_cn;
|
||||
}
|
||||
} {}
|
||||
do_test collate5-3.4 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t_cn INTERSECT SELECT a FROM collate5t_ct ORDER BY 1;
|
||||
}
|
||||
} {1 11 101}
|
||||
do_test collate5-3.5 {
|
||||
execsql {
|
||||
SELECT a FROM collate5t_ct INTERSECT SELECT a FROM collate5t_cn ORDER BY 1;
|
||||
}
|
||||
} {1 101 11}
|
||||
|
||||
do_test collate5-3.20 {
|
||||
execsql {
|
||||
DROP TABLE collate5t_cn;
|
||||
DROP TABLE collate5t_ct;
|
||||
DROP TABLE collate5t1;
|
||||
DROP TABLE collate5t2;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test collate5-4.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate5t1(a COLLATE NOCASE, b COLLATE NUMERIC);
|
||||
INSERT INTO collate5t1 VALUES('a', '1');
|
||||
INSERT INTO collate5t1 VALUES('A', '1.0');
|
||||
INSERT INTO collate5t1 VALUES('b', '2');
|
||||
INSERT INTO collate5t1 VALUES('B', '3');
|
||||
}
|
||||
} {}
|
||||
do_test collate5-4.1 {
|
||||
execsql {
|
||||
SELECT a, count(*) FROM collate5t1 GROUP BY a;
|
||||
}
|
||||
} {a 2 b 2}
|
||||
do_test collate5-4.2 {
|
||||
execsql {
|
||||
SELECT a, b, count(*) FROM collate5t1 GROUP BY a, b;
|
||||
}
|
||||
} {a 1 2 b 2 1 B 3 1}
|
||||
do_test collate5-4.3 {
|
||||
execsql {
|
||||
DROP TABLE collate5t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
finish_test
|
||||
@@ -1,106 +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 collation sequences in concert with triggers.
|
||||
#
|
||||
# $Id: collate6.test,v 1.1 2004/06/11 10:51:41 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Create a case-insensitive collation type NOCASE for use in testing.
|
||||
# Normally, capital letters are less than their lower-case counterparts.
|
||||
db collate NOCASE nocase_collate
|
||||
proc nocase_collate {a b} {
|
||||
return [string compare -nocase $a $b]
|
||||
}
|
||||
|
||||
#
|
||||
# Tests are organized as follows:
|
||||
# collate6-1.* - triggers.
|
||||
#
|
||||
|
||||
do_test collate6-1.0 {
|
||||
execsql {
|
||||
CREATE TABLE collate6log(a, b);
|
||||
CREATE TABLE collate6tab(a COLLATE NOCASE, b COLLATE BINARY);
|
||||
}
|
||||
} {}
|
||||
|
||||
# Test that the default collation sequence applies to new.* references
|
||||
# in WHEN clauses.
|
||||
do_test collate6-1.1 {
|
||||
execsql {
|
||||
CREATE TRIGGER collate6trig BEFORE INSERT ON collate6tab
|
||||
WHEN new.a = 'a' BEGIN
|
||||
INSERT INTO collate6log VALUES(new.a, new.b);
|
||||
END;
|
||||
}
|
||||
} {}
|
||||
do_test collate6-1.2 {
|
||||
execsql {
|
||||
INSERT INTO collate6tab VALUES('a', 'b');
|
||||
SELECT * FROM collate6log;
|
||||
}
|
||||
} {a b}
|
||||
do_test collate6-1.3 {
|
||||
execsql {
|
||||
INSERT INTO collate6tab VALUES('A', 'B');
|
||||
SELECT * FROM collate6log;
|
||||
}
|
||||
} {a b A B}
|
||||
do_test collate6-1.4 {
|
||||
execsql {
|
||||
DROP TRIGGER collate6trig;
|
||||
DELETE FROM collate6log;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Test that the default collation sequence applies to new.* references
|
||||
# in the body of triggers.
|
||||
do_test collate6-1.5 {
|
||||
execsql {
|
||||
CREATE TRIGGER collate6trig BEFORE INSERT ON collate6tab BEGIN
|
||||
INSERT INTO collate6log VALUES(new.a='a', new.b='b');
|
||||
END;
|
||||
}
|
||||
} {}
|
||||
do_test collate6-1.6 {
|
||||
execsql {
|
||||
INSERT INTO collate6tab VALUES('a', 'b');
|
||||
SELECT * FROM collate6log;
|
||||
}
|
||||
} {1 1}
|
||||
do_test collate6-1.7 {
|
||||
execsql {
|
||||
INSERT INTO collate6tab VALUES('A', 'B');
|
||||
SELECT * FROM collate6log;
|
||||
}
|
||||
} {1 1 1 0}
|
||||
do_test collate6-1.8 {
|
||||
execsql {
|
||||
DROP TRIGGER collate6trig;
|
||||
DELETE FROM collate6log;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test collate6-1.9 {
|
||||
execsql {
|
||||
DROP TABLE collate6tab;
|
||||
}
|
||||
} {}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
+66
-11
@@ -13,7 +13,7 @@
|
||||
# This file implements tests for the conflict resolution extension
|
||||
# to SQLite.
|
||||
#
|
||||
# $Id: conflict.test,v 1.21 2004/05/31 08:55:34 danielk1977 Exp $
|
||||
# $Id: conflict.test,v 1.19 2003/08/05 13:13:39 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -45,9 +45,18 @@ foreach {i conf cmd t0 t1 t2} {
|
||||
5 {} {INSERT OR FAIL} 1 {} 1
|
||||
6 {} {INSERT OR ABORT} 1 {} 1
|
||||
7 {} {INSERT OR ROLLBACK} 1 {} {}
|
||||
8 IGNORE INSERT 0 3 1
|
||||
9 IGNORE {INSERT OR IGNORE} 0 3 1
|
||||
10 IGNORE {INSERT OR REPLACE} 0 4 1
|
||||
11 IGNORE REPLACE 0 4 1
|
||||
12 IGNORE {INSERT OR FAIL} 1 {} 1
|
||||
13 IGNORE {INSERT OR ABORT} 1 {} 1
|
||||
14 IGNORE {INSERT OR ROLLBACK} 1 {} {}
|
||||
15 REPLACE INSERT 0 4 1
|
||||
16 FAIL INSERT 1 {} 1
|
||||
17 ABORT INSERT 1 {} 1
|
||||
18 ROLLBACK INSERT 1 {} {}
|
||||
} {
|
||||
if { $conf=={} } {
|
||||
|
||||
do_test conflict-1.$i {
|
||||
if {$conf!=""} {set conf "ON CONFLICT $conf"}
|
||||
set r0 [catch {execsql [subst {
|
||||
@@ -63,8 +72,6 @@ foreach {i conf cmd t0 t1 t2} {
|
||||
set r2 [execsql {SELECT x FROM t2}]
|
||||
list $r0 $r1 $r2
|
||||
} [list $t0 $t1 $t2]
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
# Create tables for the first group of tests.
|
||||
@@ -96,6 +103,17 @@ foreach {i conf cmd t0 t1 t2} {
|
||||
5 {} {INSERT OR FAIL} 1 {} 1
|
||||
6 {} {INSERT OR ABORT} 1 {} 1
|
||||
7 {} {INSERT OR ROLLBACK} 1 {} {}
|
||||
8 IGNORE INSERT 0 3 1
|
||||
9 IGNORE {INSERT OR IGNORE} 0 3 1
|
||||
10 IGNORE {INSERT OR REPLACE} 0 4 1
|
||||
11 IGNORE REPLACE 0 4 1
|
||||
12 IGNORE {INSERT OR FAIL} 1 {} 1
|
||||
13 IGNORE {INSERT OR ABORT} 1 {} 1
|
||||
14 IGNORE {INSERT OR ROLLBACK} 1 {} {}
|
||||
15 REPLACE INSERT 0 4 1
|
||||
16 FAIL INSERT 1 {} 1
|
||||
17 ABORT INSERT 1 {} 1
|
||||
18 ROLLBACK INSERT 1 {} {}
|
||||
} {
|
||||
do_test conflict-2.$i {
|
||||
if {$conf!=""} {set conf "ON CONFLICT $conf"}
|
||||
@@ -143,6 +161,17 @@ foreach {i conf cmd t0 t1 t2} {
|
||||
5 {} {INSERT OR FAIL} 1 {} 1
|
||||
6 {} {INSERT OR ABORT} 1 {} 1
|
||||
7 {} {INSERT OR ROLLBACK} 1 {} {}
|
||||
8 IGNORE INSERT 0 3 1
|
||||
9 IGNORE {INSERT OR IGNORE} 0 3 1
|
||||
10 IGNORE {INSERT OR REPLACE} 0 4 1
|
||||
11 IGNORE REPLACE 0 4 1
|
||||
12 IGNORE {INSERT OR FAIL} 1 {} 1
|
||||
13 IGNORE {INSERT OR ABORT} 1 {} 1
|
||||
14 IGNORE {INSERT OR ROLLBACK} 1 {} {}
|
||||
15 REPLACE INSERT 0 4 1
|
||||
16 FAIL INSERT 1 {} 1
|
||||
17 ABORT INSERT 1 {} 1
|
||||
18 ROLLBACK INSERT 1 {} {}
|
||||
} {
|
||||
do_test conflict-3.$i {
|
||||
if {$conf!=""} {set conf "ON CONFLICT $conf"}
|
||||
@@ -191,6 +220,15 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
|
||||
9 FAIL {} {INSERT OR IGNORE} 0 3 1
|
||||
10 ABORT {} {INSERT OR REPLACE} 0 4 1
|
||||
11 ROLLBACK {} {INSERT OR IGNORE } 0 3 1
|
||||
12 REPLACE IGNORE INSERT 0 3 1
|
||||
13 IGNORE REPLACE INSERT 0 4 1
|
||||
14 FAIL IGNORE INSERT 0 3 1
|
||||
15 ABORT REPLACE INSERT 0 4 1
|
||||
16 ROLLBACK IGNORE INSERT 0 3 1
|
||||
12 IGNORE REPLACE INSERT 0 4 1
|
||||
13 IGNORE FAIL INSERT 1 {} 1
|
||||
14 IGNORE ABORT INSERT 1 {} 1
|
||||
15 IGNORE ROLLBACK INSERT 1 {} {}
|
||||
} {
|
||||
do_test conflict-4.$i {
|
||||
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
|
||||
@@ -246,6 +284,13 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
|
||||
14 {} {} {INSERT OR FAIL} 1 {} 1
|
||||
15 {} {} {INSERT OR ABORT} 1 {} 1
|
||||
16 {} {} {INSERT OR ROLLBACK} 1 {} {}
|
||||
17 {} IGNORE INSERT 0 {} 1
|
||||
18 {} REPLACE INSERT 0 5 1
|
||||
19 {} FAIL INSERT 1 {} 1
|
||||
20 {} ABORT INSERT 1 {} 1
|
||||
21 {} ROLLBACK INSERT 1 {} {}
|
||||
22 REPLACE FAIL INSERT 1 {} 1
|
||||
23 IGNORE ROLLBACK INSERT 1 {} {}
|
||||
} {
|
||||
if {$t0} {set t1 {t1.c may not be NULL}}
|
||||
do_test conflict-5.$i {
|
||||
@@ -307,6 +352,16 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
|
||||
14 {} {} {UPDATE OR FAIL} 1 {6 7 3 4} 1
|
||||
15 {} {} {UPDATE OR ABORT} 1 {1 2 3 4} 1
|
||||
16 {} {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0
|
||||
17 {} IGNORE UPDATE 0 {6 7 3 9} 1
|
||||
18 {} REPLACE UPDATE 0 {7 6 9} 1
|
||||
19 {} FAIL UPDATE 1 {6 7 3 4} 1
|
||||
20 {} ABORT UPDATE 1 {1 2 3 4} 1
|
||||
21 {} ROLLBACK UPDATE 1 {1 2 3 4} 0
|
||||
22 REPLACE IGNORE UPDATE 0 {6 7 3 9} 1
|
||||
23 IGNORE REPLACE UPDATE 0 {7 6 9} 1
|
||||
24 REPLACE FAIL UPDATE 1 {6 7 3 4} 1
|
||||
25 IGNORE ABORT UPDATE 1 {1 2 3 4} 1
|
||||
26 REPLACE ROLLBACK UPDATE 1 {1 2 3 4} 0
|
||||
} {
|
||||
if {$t0} {set t1 {column a is not unique}}
|
||||
do_test conflict-6.$i {
|
||||
@@ -615,9 +670,9 @@ do_test conflict-9.26 {
|
||||
do_test conflict-10.1 {
|
||||
catchsql {
|
||||
DELETE FROM t1;
|
||||
BEGIN;
|
||||
INSERT OR ROLLBACK INTO t1 VALUES(1,2);
|
||||
INSERT OR ROLLBACK INTO t1 VALUES(1,3);
|
||||
BEGIN ON CONFLICT ROLLBACK;
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
INSERT INTO t1 VALUES(1,3);
|
||||
COMMIT;
|
||||
}
|
||||
execsql {SELECT * FROM t1}
|
||||
@@ -626,9 +681,9 @@ do_test conflict-10.2 {
|
||||
catchsql {
|
||||
CREATE TABLE t4(x);
|
||||
CREATE UNIQUE INDEX t4x ON t4(x);
|
||||
BEGIN;
|
||||
INSERT OR ROLLBACK INTO t4 VALUES(1);
|
||||
INSERT OR ROLLBACK INTO t4 VALUES(1);
|
||||
BEGIN ON CONFLICT ROLLBACK;
|
||||
INSERT INTO t4 VALUES(1);
|
||||
INSERT INTO t4 VALUES(1);
|
||||
COMMIT;
|
||||
}
|
||||
execsql {SELECT * FROM t4}
|
||||
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
# 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 file is testing the COPY statement.
|
||||
#
|
||||
# $Id: copy.test,v 1.17 2004/02/17 18:26:57 dougcurrie Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Create a file of data from which to copy.
|
||||
#
|
||||
set f [open data1.txt w]
|
||||
puts $f "11\t22\t33"
|
||||
puts $f "22\t33\t11"
|
||||
close $f
|
||||
set f [open data2.txt w]
|
||||
puts $f "11\t22\t33"
|
||||
puts $f "\\."
|
||||
puts $f "22\t33\t11"
|
||||
close $f
|
||||
set f [open data3.txt w]
|
||||
puts $f "11\t22\t33\t44"
|
||||
puts $f "22\t33\t11"
|
||||
close $f
|
||||
set f [open data4.txt w]
|
||||
puts $f "11 | 22 | 33"
|
||||
puts $f "22 | 33 | 11"
|
||||
close $f
|
||||
set f [open data5.txt w]
|
||||
puts $f "11|22|33"
|
||||
puts $f "22|33|11"
|
||||
close $f
|
||||
set f [open dataX.txt w]
|
||||
fconfigure $f -translation binary
|
||||
puts -nonewline $f "11|22|33\r"
|
||||
puts -nonewline $f "22|33|44\r\n"
|
||||
puts -nonewline $f "33|44|55\n"
|
||||
puts -nonewline $f "44|55|66\r"
|
||||
puts -nonewline $f "55|66|77\r\n"
|
||||
puts -nonewline $f "66|77|88\n"
|
||||
close $f
|
||||
|
||||
# Try to COPY into a non-existant table.
|
||||
#
|
||||
do_test copy-1.1 {
|
||||
set v [catch {execsql {COPY test1 FROM 'data1.txt'}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such table: test1}}
|
||||
|
||||
# Try to insert into sqlite_master
|
||||
#
|
||||
do_test copy-1.2 {
|
||||
set v [catch {execsql {COPY sqlite_master FROM 'data2.txt'}} msg]
|
||||
lappend v $msg
|
||||
} {1 {table sqlite_master may not be modified}}
|
||||
|
||||
# Do some actual inserts
|
||||
#
|
||||
do_test copy-1.3 {
|
||||
execsql {CREATE TABLE test1(one int, two int, three int)}
|
||||
execsql {COPY test1 FROM 'data1.txt'}
|
||||
execsql {SELECT * FROM test1 ORDER BY one}
|
||||
} {11 22 33 22 33 11}
|
||||
|
||||
# Make sure input terminates at \.
|
||||
#
|
||||
do_test copy-1.4 {
|
||||
execsql {DELETE FROM test1}
|
||||
execsql {COPY test1 FROM 'data2.txt'}
|
||||
execsql {SELECT * FROM test1 ORDER BY one}
|
||||
} {11 22 33}
|
||||
|
||||
# Test out the USING DELIMITERS clause
|
||||
#
|
||||
do_test copy-1.5 {
|
||||
execsql {DELETE FROM test1}
|
||||
execsql {COPY test1 FROM 'data4.txt' USING DELIMITERS ' | '}
|
||||
execsql {SELECT * FROM test1 ORDER BY one}
|
||||
} {11 22 33 22 33 11}
|
||||
do_test copy-1.6 {
|
||||
execsql {DELETE FROM test1}
|
||||
execsql {COPY test1 FROM 'data5.txt' USING DELIMITERS '|'}
|
||||
execsql {SELECT * FROM test1 ORDER BY one}
|
||||
} {11 22 33 22 33 11}
|
||||
do_test copy-1.7 {
|
||||
execsql {DELETE FROM test1}
|
||||
execsql {COPY test1 FROM 'data4.txt' USING DELIMITERS '|'}
|
||||
execsql {SELECT * FROM test1 ORDER BY one}
|
||||
} {{11 } { 22 } { 33} {22 } { 33 } { 11}}
|
||||
|
||||
# Try copying into a table that has one or more indices.
|
||||
#
|
||||
do_test copy-1.8 {
|
||||
execsql {DELETE FROM test1}
|
||||
execsql {CREATE INDEX index1 ON test1(one)}
|
||||
execsql {CREATE INDEX index2 ON test1(two)}
|
||||
execsql {CREATE INDEX index3 ON test1(three)}
|
||||
execsql {COPY test1 from 'data1.txt'}
|
||||
execsql {SELECT * FROM test1 WHERE one=11}
|
||||
} {11 22 33}
|
||||
do_test copy-1.8b {
|
||||
execsql {SELECT * FROM test1 WHERE one=22}
|
||||
} {22 33 11}
|
||||
do_test copy-1.8c {
|
||||
execsql {SELECT * FROM test1 WHERE two=22}
|
||||
} {11 22 33}
|
||||
do_test copy-1.8d {
|
||||
execsql {SELECT * FROM test1 WHERE three=11}
|
||||
} {22 33 11}
|
||||
|
||||
|
||||
# Try inserting really long data
|
||||
#
|
||||
set x {}
|
||||
for {set i 0} {$i<100} {incr i} {
|
||||
append x "($i)-abcdefghijklmnopqrstyvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-"
|
||||
}
|
||||
do_test copy-2.1 {
|
||||
execsql {CREATE TABLE test2(a int, x text)}
|
||||
set f [open data21.txt w]
|
||||
puts $f "123\t$x"
|
||||
close $f
|
||||
execsql {COPY test2 FROM 'data21.txt'}
|
||||
execsql {SELECT x from test2}
|
||||
} $x
|
||||
file delete -force data21.txt
|
||||
|
||||
# Test the escape character mechanism
|
||||
#
|
||||
do_test copy-3.1 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "hello\\\tworld\t1"
|
||||
puts $fd "hello\tworld\\\t2"
|
||||
close $fd
|
||||
execsql {
|
||||
CREATE TABLE t1(a text, b text);
|
||||
COPY t1 FROM 'data6.txt';
|
||||
SELECT * FROM t1 ORDER BY a;
|
||||
}
|
||||
} {hello {world 2} {hello world} 1}
|
||||
do_test copy-3.2 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "1\thello\\\nworld"
|
||||
puts $fd "2\thello world"
|
||||
close $fd
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
COPY t1 FROM 'data6.txt';
|
||||
SELECT * FROM t1 ORDER BY a;
|
||||
}
|
||||
} {1 {hello
|
||||
world} 2 {hello world}}
|
||||
do_test copy-3.3 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "1:hello\\b\\f\\n\\r\\t\\vworld"
|
||||
puts $fd "2:hello world"
|
||||
close $fd
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
COPY t1 FROM 'data6.txt' USING DELIMITERS ':';
|
||||
SELECT * FROM t1 ORDER BY a;
|
||||
}
|
||||
} [list 1 "hello\b\f\n\r\t\vworld" 2 "hello world"]
|
||||
|
||||
# Test the embedded NULL logic.
|
||||
#
|
||||
do_test copy-4.1 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "1\t\\N"
|
||||
puts $fd "\\N\thello world"
|
||||
close $fd
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
COPY t1 FROM 'data6.txt';
|
||||
SELECT * FROM t1 WHERE a IS NULL;
|
||||
}
|
||||
} {{} {hello world}}
|
||||
do_test copy-4.2 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE b IS NULL;
|
||||
}
|
||||
} {1 {}}
|
||||
|
||||
# Test the conflict resolution logic for COPY
|
||||
#
|
||||
do_test copy-5.1 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE, c);
|
||||
COPY t1 FROM 'data5.txt' USING DELIMITERS '|';
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {11 22 33 22 33 11}
|
||||
do_test copy-5.2 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "33|22|44"
|
||||
close $fd
|
||||
catchsql {
|
||||
COPY t1 FROM 'data6.txt' USING DELIMITERS '|';
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 {column b is not unique}}
|
||||
do_test copy-5.3 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "33|22|44"
|
||||
close $fd
|
||||
catchsql {
|
||||
COPY OR IGNORE t1 FROM 'data6.txt' USING DELIMITERS '|';
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 {11 22 33 22 33 11}}
|
||||
do_test copy-5.4 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "33|22|44"
|
||||
close $fd
|
||||
catchsql {
|
||||
COPY OR REPLACE t1 FROM 'data6.txt' USING DELIMITERS '|';
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 {22 33 11 33 22 44}}
|
||||
|
||||
do_test copy-5.5 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
PRAGMA count_changes=on;
|
||||
COPY t1 FROM 'data5.txt' USING DELIMITERS '|';
|
||||
}
|
||||
} {2}
|
||||
do_test copy-5.6 {
|
||||
execsql {
|
||||
COPY OR REPLACE t1 FROM 'data5.txt' USING DELIMITERS '|';
|
||||
}
|
||||
} {2}
|
||||
do_test copy-5.7 {
|
||||
execsql {
|
||||
COPY OR IGNORE t1 FROM 'data5.txt' USING DELIMITERS '|';
|
||||
}
|
||||
} {0}
|
||||
|
||||
do_test copy-6.1 {
|
||||
execsql {
|
||||
PRAGMA count_changes=off;
|
||||
CREATE TABLE t2(a,b,c);
|
||||
COPY t2 FROM 'dataX.txt' USING DELIMITERS '|';
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {11 22 33 22 33 44 33 44 55 44 55 66 55 66 77 66 77 88}
|
||||
|
||||
integrity_check copy-7.1
|
||||
|
||||
# Cleanup
|
||||
#
|
||||
#file delete -force data1.txt data2.txt data3.txt data4.txt data5.txt \
|
||||
data6.txt dataX.txt
|
||||
|
||||
finish_test
|
||||
+9
-13
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the DELETE FROM statement.
|
||||
#
|
||||
# $Id: delete.test,v 1.15 2004/06/10 05:59:25 danielk1977 Exp $
|
||||
# $Id: delete.test,v 1.13 2003/06/15 23:42:25 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -152,15 +152,16 @@ integrity_check delete-5.8
|
||||
# mechanism in the vdbe.
|
||||
#
|
||||
do_test delete-6.1 {
|
||||
execsql {BEGIN; DELETE FROM table1}
|
||||
set fd [open data1.txt w]
|
||||
for {set i 1} {$i<=3000} {incr i} {
|
||||
execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])"
|
||||
puts $fd "[expr {$i}]\t[expr {$i*$i}]"
|
||||
}
|
||||
close $fd
|
||||
execsql {DELETE FROM table1}
|
||||
execsql {COPY table1 FROM 'data1.txt'}
|
||||
execsql {DELETE FROM table2}
|
||||
for {set i 1} {$i<=3000} {incr i} {
|
||||
execsql "INSERT INTO table2 VALUES($i,[expr {$i*$i}])"
|
||||
}
|
||||
execsql {COMMIT}
|
||||
execsql {COPY table2 FROM 'data1.txt'}
|
||||
file delete data1.txt
|
||||
execsql {SELECT count(*) FROM table1}
|
||||
} {3000}
|
||||
do_test delete-6.2 {
|
||||
@@ -277,16 +278,11 @@ do_test delete-8.3 {
|
||||
do_test delete-8.4 {
|
||||
execsql {SELECT * FROM t3}
|
||||
} {123}
|
||||
|
||||
# Update for v3: In v2 the DELETE statement would succeed because no
|
||||
# database writes actually occur. Version 3 refuses to open a transaction
|
||||
# on a read-only file, so the statement fails.
|
||||
do_test delete-8.5 {
|
||||
catchsql {
|
||||
DELETE FROM t3 WHERE a<100;
|
||||
}
|
||||
# v2 result: {0 {}}
|
||||
} {1 {attempt to write a readonly database}}
|
||||
} {0 {}}
|
||||
do_test delete-8.6 {
|
||||
execsql {SELECT * FROM t3}
|
||||
} {123}
|
||||
|
||||
-148
@@ -1,148 +0,0 @@
|
||||
# 2002 May 24
|
||||
#
|
||||
# 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 file is testing the SQLite routines used for converting between the
|
||||
# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
|
||||
# UTF-16be).
|
||||
#
|
||||
# $Id: enc.test,v 1.2 2004/06/18 04:24:56 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
proc do_bincmp_test {testname got expect} {
|
||||
binary scan $expect \c* expectvals
|
||||
binary scan $got \c* gotvals
|
||||
do_test $testname [list set dummy $gotvals] $expectvals
|
||||
}
|
||||
|
||||
# $utf16 is a UTF-16 encoded string. Swap each pair of bytes around
|
||||
# to change the byte-order of the string.
|
||||
proc swap_byte_order {utf16} {
|
||||
binary scan $utf16 \c* ints
|
||||
|
||||
foreach {a b} $ints {
|
||||
lappend ints2 $b
|
||||
lappend ints2 $a
|
||||
}
|
||||
|
||||
return [binary format \c* $ints2]
|
||||
}
|
||||
|
||||
#
|
||||
# Test that the SQLite routines for converting between UTF encodings
|
||||
# produce the same results as their TCL counterparts.
|
||||
#
|
||||
# $testname is the prefix to be used for the test names.
|
||||
# $str is a string to use for testing (encoded in UTF-8, as normal for TCL).
|
||||
#
|
||||
# The test procedure is:
|
||||
# 1. Convert the string from UTF-8 to UTF-16le and check that the TCL and
|
||||
# SQLite routines produce the same results.
|
||||
#
|
||||
# 2. Convert the string from UTF-8 to UTF-16be and check that the TCL and
|
||||
# SQLite routines produce the same results.
|
||||
#
|
||||
# 3. Use the SQLite routines to convert the native machine order UTF-16
|
||||
# representation back to the original UTF-8. Check that the result
|
||||
# matches the original representation.
|
||||
#
|
||||
# 4. Add a byte-order mark to each of the UTF-16 representations and
|
||||
# check that the SQLite routines can convert them back to UTF-8. For
|
||||
# byte-order mark info, refer to section 3.10 of the unicode standard.
|
||||
#
|
||||
# 5. Take the byte-order marked UTF-16 strings from step 4 and ensure
|
||||
# that SQLite can convert them both to native byte order UTF-16
|
||||
# strings, sans BOM.
|
||||
#
|
||||
# Coverage:
|
||||
#
|
||||
# sqlite_utf8to16be (step 2)
|
||||
# sqlite_utf8to16le (step 1)
|
||||
# sqlite_utf16to8 (steps 3, 4)
|
||||
# sqlite_utf16to16le (step 5)
|
||||
# sqlite_utf16to16be (step 5)
|
||||
#
|
||||
proc test_conversion {testname str} {
|
||||
|
||||
# Step 1.
|
||||
set utf16le_sqlite [test_translate $str UTF8 UTF16LE]
|
||||
set utf16le_tcl [encoding convertto unicode $str]
|
||||
append utf16le_tcl "\x00\x00"
|
||||
if { $::tcl_platform(byteOrder)!="littleEndian" } {
|
||||
set utf16le_tcl [swap_byte_order $utf16le_tcl]
|
||||
}
|
||||
do_bincmp_test $testname.1 $utf16le_sqlite $utf16le_tcl
|
||||
set utf16le $utf16le_tcl
|
||||
|
||||
# Step 2.
|
||||
set utf16be_sqlite [test_translate $str UTF8 UTF16BE]
|
||||
set utf16be_tcl [encoding convertto unicode $str]
|
||||
append utf16be_tcl "\x00\x00"
|
||||
if { $::tcl_platform(byteOrder)=="littleEndian" } {
|
||||
set utf16be_tcl [swap_byte_order $utf16be_tcl]
|
||||
}
|
||||
do_bincmp_test $testname.2 $utf16be_sqlite $utf16be_tcl
|
||||
set utf16be $utf16be_tcl
|
||||
|
||||
# Step 3.
|
||||
if { $::tcl_platform(byteOrder)=="littleEndian" } {
|
||||
set utf16 $utf16le
|
||||
} else {
|
||||
set utf16 $utf16be
|
||||
}
|
||||
set utf8_sqlite [test_translate $utf16 UTF16 UTF8]
|
||||
do_bincmp_test $testname.3 $utf8_sqlite [binarize $str]
|
||||
|
||||
# Step 4 (little endian).
|
||||
append utf16le_bom "\xFF\xFE" $utf16le
|
||||
set utf8_sqlite [test_translate $utf16le_bom UTF16 UTF8]
|
||||
do_bincmp_test $testname.4.le $utf8_sqlite [binarize $str]
|
||||
|
||||
# Step 4 (big endian).
|
||||
append utf16be_bom "\xFE\xFF" $utf16be
|
||||
set utf8_sqlite [test_translate $utf16be_bom UTF16 UTF8]
|
||||
do_bincmp_test $testname.4.be $utf8_sqlite [binarize $str]
|
||||
|
||||
# Step 5 (little endian to little endian).
|
||||
set utf16_sqlite [test_translate $utf16le_bom UTF16LE UTF16LE]
|
||||
do_bincmp_test $testname.5.le.le $utf16_sqlite $utf16le
|
||||
|
||||
# Step 5 (big endian to big endian).
|
||||
set utf16_sqlite [test_translate $utf16be_bom UTF16 UTF16BE]
|
||||
do_bincmp_test $testname.5.be.be $utf16_sqlite $utf16be
|
||||
|
||||
# Step 5 (big endian to little endian).
|
||||
set utf16_sqlite [test_translate $utf16be_bom UTF16 UTF16LE]
|
||||
do_bincmp_test $testname.5.be.le $utf16_sqlite $utf16le
|
||||
|
||||
# Step 5 (little endian to big endian).
|
||||
set utf16_sqlite [test_translate $utf16le_bom UTF16 UTF16BE]
|
||||
do_bincmp_test $testname.5.le.be $utf16_sqlite $utf16be
|
||||
}
|
||||
|
||||
translate_selftest
|
||||
|
||||
test_conversion enc-1 "hello world"
|
||||
test_conversion enc-2 "sqlite"
|
||||
test_conversion enc-3 ""
|
||||
test_conversion enc-X "\u0100"
|
||||
test_conversion enc-4 "\u1234"
|
||||
test_conversion enc-5 "\u4321abc"
|
||||
test_conversion enc-6 "\u4321\u1234"
|
||||
test_conversion enc-7 [string repeat "abcde\u00EF\u00EE\uFFFCabc" 100]
|
||||
test_conversion enc-8 [string repeat "\u007E\u007F\u0080\u0081" 100]
|
||||
test_conversion enc-9 [string repeat "\u07FE\u07FF\u0800\u0801\uFFF0" 100]
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
-314
@@ -1,314 +0,0 @@
|
||||
# 2002 May 24
|
||||
#
|
||||
# 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 file is testing the SQLite routines used for converting between the
|
||||
# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
|
||||
# UTF-16be).
|
||||
#
|
||||
# $Id: enc2.test,v 1.11 2004/06/18 06:02:35 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# The rough organisation of tests in this file is:
|
||||
#
|
||||
# enc2.1.*: Simple tests with a UTF-8 db.
|
||||
# enc2.2.*: Simple tests with a UTF-16LE db.
|
||||
# enc2.3.*: Simple tests with a UTF-16BE db.
|
||||
# enc2.4.*: Test that attached databases must have the same text encoding
|
||||
# as the main database.
|
||||
# enc2.5.*: Test the behaviour of the library when a collation sequence is
|
||||
# not available for the most desirable text encoding.
|
||||
# enc2.6.*: Test that the VerifyCookie opcode protects against assuming the
|
||||
# wrong text encoding for the database.
|
||||
|
||||
db close
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
#
|
||||
# This proc contains all the tests in this file. It is run
|
||||
# three times. Each time the file 'test.db' contains a database
|
||||
# with the following contents:
|
||||
set dbcontents {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b, c);
|
||||
INSERT INTO t1 VALUES('one', 'I', 1);
|
||||
}
|
||||
# This proc tests that we can open and manipulate the test.db
|
||||
# database, and that it is possible to retreive values in
|
||||
# various text encodings.
|
||||
#
|
||||
proc run_test_script {t enc} {
|
||||
|
||||
# Open the database and pull out a (the) row.
|
||||
do_test $t.1 {
|
||||
set DB [sqlite db test.db]
|
||||
execsql {SELECT * FROM t1}
|
||||
} {one I 1}
|
||||
|
||||
# Insert some data
|
||||
do_test $t.2 {
|
||||
execsql {INSERT INTO t1 VALUES('two', 'II', 2);}
|
||||
execsql {SELECT * FROM t1}
|
||||
} {one I 1 two II 2}
|
||||
|
||||
# Insert some data
|
||||
do_test $t.3 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES('three','III',3);
|
||||
INSERT INTO t1 VALUES('four','IV',4);
|
||||
INSERT INTO t1 VALUES('five','V',5);
|
||||
}
|
||||
execsql {SELECT * FROM t1}
|
||||
} {one I 1 two II 2 three III 3 four IV 4 five V 5}
|
||||
|
||||
# Use the index
|
||||
do_test $t.4 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE a = 'one';
|
||||
}
|
||||
} {one I 1}
|
||||
do_test $t.5 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE a = 'four';
|
||||
}
|
||||
} {four IV 4}
|
||||
do_test $t.6 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE a IN ('one', 'two');
|
||||
}
|
||||
} {one I 1 two II 2}
|
||||
|
||||
# Now check that we can retrieve data in both UTF-16 and UTF-8
|
||||
do_test $t.7 {
|
||||
set STMT [sqlite3_prepare $DB "SELECT a FROM t1 WHERE c>3;" -1 TAIL]
|
||||
sqlite3_step $STMT
|
||||
sqlite3_column_text $STMT 0
|
||||
} {four}
|
||||
|
||||
do_test $t.8 {
|
||||
sqlite3_step $STMT
|
||||
utf8 [sqlite3_column_text16 $STMT 0]
|
||||
} {five}
|
||||
|
||||
do_test $t.9 {
|
||||
sqlite3_finalize $STMT
|
||||
} SQLITE_OK
|
||||
|
||||
do_test $t.10 {
|
||||
db eval {PRAGMA encoding}
|
||||
} $enc
|
||||
|
||||
}
|
||||
|
||||
# The three unicode encodings understood by SQLite.
|
||||
set encodings [list UTF-8 UTF-16le UTF-16be]
|
||||
|
||||
set sqlite_os_trace 0
|
||||
set i 1
|
||||
foreach enc $encodings {
|
||||
file delete -force test.db
|
||||
sqlite db test.db
|
||||
db eval "PRAGMA encoding = \"$enc\""
|
||||
execsql $dbcontents
|
||||
db close
|
||||
run_test_script enc2-$i $enc
|
||||
db close
|
||||
incr i
|
||||
}
|
||||
|
||||
# Test that it is an error to try to attach a database with a different
|
||||
# encoding to the main database.
|
||||
do_test enc2-4.1 {
|
||||
file delete -force test.db
|
||||
sqlite db test.db
|
||||
db eval "PRAGMA encoding = 'UTF-8'"
|
||||
db eval "CREATE TABLE abc(a, b, c);"
|
||||
} {}
|
||||
do_test enc2-4.2 {
|
||||
file delete -force test2.db
|
||||
sqlite db2 test2.db
|
||||
db2 eval "PRAGMA encoding = 'UTF-16'"
|
||||
db2 eval "CREATE TABLE abc(a, b, c);"
|
||||
} {}
|
||||
do_test enc2-4.3 {
|
||||
catchsql {
|
||||
ATTACH 'test2.db' as aux;
|
||||
}
|
||||
} {1 {attached databases must use the same text encoding as main database}}
|
||||
|
||||
db2 close
|
||||
db close
|
||||
|
||||
# The following tests - enc2-5.* - test that SQLite selects the correct
|
||||
# collation sequence when more than one is available.
|
||||
|
||||
set ::values [list one two three four five]
|
||||
set ::test_collate_enc INVALID
|
||||
proc test_collate {enc lhs rhs} {
|
||||
set ::test_collate_enc $enc
|
||||
set l [lsearch -exact $::values $lhs]
|
||||
set r [lsearch -exact $::values $rhs]
|
||||
set res [expr $l - $r]
|
||||
return $res
|
||||
}
|
||||
|
||||
file delete -force test.db
|
||||
set DB [sqlite db test.db]
|
||||
do_test enc2-5.0 {
|
||||
execsql {
|
||||
CREATE TABLE t5(a);
|
||||
INSERT INTO t5 VALUES('one');
|
||||
INSERT INTO t5 VALUES('two');
|
||||
INSERT INTO t5 VALUES('five');
|
||||
INSERT INTO t5 VALUES('three');
|
||||
INSERT INTO t5 VALUES('four');
|
||||
}
|
||||
} {}
|
||||
do_test enc2-5.1 {
|
||||
add_test_collate $DB 1 1 1
|
||||
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
|
||||
lappend res $::test_collate_enc
|
||||
} {one two three four five UTF-8}
|
||||
do_test enc2-5.2 {
|
||||
add_test_collate $DB 0 1 0
|
||||
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
|
||||
lappend res $::test_collate_enc
|
||||
} {one two three four five UTF-16LE}
|
||||
do_test enc2-5.3 {
|
||||
add_test_collate $DB 0 0 1
|
||||
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
|
||||
lappend res $::test_collate_enc
|
||||
} {one two three four five UTF-16BE}
|
||||
|
||||
db close
|
||||
file delete -force test.db
|
||||
set DB [sqlite db test.db]
|
||||
execsql {pragma encoding = 'UTF-16LE'}
|
||||
do_test enc2-5.4 {
|
||||
execsql {
|
||||
CREATE TABLE t5(a);
|
||||
INSERT INTO t5 VALUES('one');
|
||||
INSERT INTO t5 VALUES('two');
|
||||
INSERT INTO t5 VALUES('five');
|
||||
INSERT INTO t5 VALUES('three');
|
||||
INSERT INTO t5 VALUES('four');
|
||||
}
|
||||
} {}
|
||||
do_test enc2-5.5 {
|
||||
add_test_collate $DB 1 1 1
|
||||
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
|
||||
lappend res $::test_collate_enc
|
||||
} {one two three four five UTF-16LE}
|
||||
do_test enc2-5.6 {
|
||||
add_test_collate $DB 1 0 1
|
||||
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
|
||||
lappend res $::test_collate_enc
|
||||
} {one two three four five UTF-16BE}
|
||||
do_test enc2-5.7 {
|
||||
add_test_collate $DB 1 0 0
|
||||
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
|
||||
lappend res $::test_collate_enc
|
||||
} {one two three four five UTF-8}
|
||||
|
||||
db close
|
||||
file delete -force test.db
|
||||
set DB [sqlite db test.db]
|
||||
execsql {pragma encoding = 'UTF-16BE'}
|
||||
do_test enc2-5.8 {
|
||||
execsql {
|
||||
CREATE TABLE t5(a);
|
||||
INSERT INTO t5 VALUES('one');
|
||||
INSERT INTO t5 VALUES('two');
|
||||
INSERT INTO t5 VALUES('five');
|
||||
INSERT INTO t5 VALUES('three');
|
||||
INSERT INTO t5 VALUES('four');
|
||||
}
|
||||
} {}
|
||||
do_test enc2-5.9 {
|
||||
add_test_collate $DB 1 1 1
|
||||
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
|
||||
lappend res $::test_collate_enc
|
||||
} {one two three four five UTF-16BE}
|
||||
do_test enc2-5.10 {
|
||||
add_test_collate $DB 1 1 0
|
||||
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
|
||||
lappend res $::test_collate_enc
|
||||
} {one two three four five UTF-16LE}
|
||||
do_test enc2-5.11 {
|
||||
add_test_collate $DB 1 0 0
|
||||
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
|
||||
lappend res $::test_collate_enc
|
||||
} {one two three four five UTF-8}
|
||||
|
||||
db close
|
||||
file delete -force test.db
|
||||
|
||||
# The following tests - enc2-6.* - function as follows:
|
||||
#
|
||||
# 1: Open an empty database file assuming UTF-16 encoding.
|
||||
# 2: Open the same database with a different handle assuming UTF-8. Create
|
||||
# a table using this handle.
|
||||
# 3: Read the sqlite_master table from the first handle.
|
||||
# 4: Ensure the first handle recognises the database encoding is UTF-8.
|
||||
#
|
||||
do_test enc2-6.1 {
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
PRAGMA encoding = 'UTF-16';
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
} {}
|
||||
do_test enc2-6.2 {
|
||||
set enc [execsql {
|
||||
PRAGMA encoding;
|
||||
}]
|
||||
string range $enc 0 end-2 ;# Chop off the "le" or "be"
|
||||
} {UTF-16}
|
||||
do_test enc2-6.3 {
|
||||
sqlite db2 test.db
|
||||
execsql {
|
||||
PRAGMA encoding = 'UTF-8';
|
||||
CREATE TABLE abc(a, b, c);
|
||||
} db2
|
||||
} {}
|
||||
do_test enc2-6.4 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
} {table abc abc 2 {CREATE TABLE abc(a, b, c)}}
|
||||
do_test enc2-6.5 {
|
||||
execsql {
|
||||
PRAGMA encoding;
|
||||
}
|
||||
} {UTF-8}
|
||||
|
||||
db close
|
||||
db2 close
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+49
-7
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing expressions.
|
||||
#
|
||||
# $Id: expr.test,v 1.34 2004/06/17 05:36:45 danielk1977 Exp $
|
||||
# $Id: expr.test,v 1.31 2004/03/03 01:51:25 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -29,8 +29,7 @@ proc test_expr {name settings expr result} {
|
||||
test_expr expr-1.1 {i1=10, i2=20} {i1+i2} 30
|
||||
test_expr expr-1.2 {i1=10, i2=20} {i1-i2} -10
|
||||
test_expr expr-1.3 {i1=10, i2=20} {i1*i2} 200
|
||||
# update for sqlite v3: Change 0.5 to 0 in expr1.4 due to manifest types.
|
||||
test_expr expr-1.4 {i1=10, i2=20} {i1/i2} 0
|
||||
test_expr expr-1.4 {i1=10, i2=20} {i1/i2} 0.5
|
||||
test_expr expr-1.5 {i1=10, i2=20} {i2/i1} 2
|
||||
test_expr expr-1.6 {i1=10, i2=20} {i2<i1} 0
|
||||
test_expr expr-1.7 {i1=10, i2=20} {i2<=i1} 0
|
||||
@@ -232,7 +231,6 @@ test_expr expr-5.2 {t1='abc', t2='ABC'} {t1 LIKE t2} 1
|
||||
test_expr expr-5.3 {t1='abc', t2='A_C'} {t1 LIKE t2} 1
|
||||
test_expr expr-5.4 {t1='abc', t2='abc_'} {t1 LIKE t2} 0
|
||||
test_expr expr-5.5 {t1='abc', t2='A%C'} {t1 LIKE t2} 1
|
||||
test_expr expr-5.5a {t1='abdc', t2='a%c'} {t1 LIKE t2} 1
|
||||
test_expr expr-5.5b {t1='ac', t2='A%C'} {t1 LIKE t2} 1
|
||||
test_expr expr-5.6 {t1='abxyzzyc', t2='A%C'} {t1 LIKE t2} 1
|
||||
test_expr expr-5.7 {t1='abxyzzy', t2='A%C'} {t1 LIKE t2} 0
|
||||
@@ -244,9 +242,10 @@ test_expr expr-5.10 {t1='abxyzzyc', t2='A%_C'} {t1 LIKE t2} 1
|
||||
test_expr expr-5.11 {t1='abc', t2='xyz'} {t1 NOT LIKE t2} 1
|
||||
test_expr expr-5.12 {t1='abc', t2='ABC'} {t1 NOT LIKE t2} 0
|
||||
|
||||
# The following tests only work on versions of TCL that support Unicode
|
||||
# The following tests only work on versions of TCL that support
|
||||
# Unicode and SQLite configured for UTF-8 support.
|
||||
#
|
||||
if {"\u1234"!="u1234"} {
|
||||
if {"\u1234"!="u1234" && [sqlite -encoding]=="UTF-8"} {
|
||||
test_expr expr-5.13 "t1='a\u0080c', t2='A_C'" {t1 LIKE t2} 1
|
||||
test_expr expr-5.14 "t1='a\u07FFc', t2='A_C'" {t1 LIKE t2} 1
|
||||
test_expr expr-5.15 "t1='a\u0800c', t2='A_C'" {t1 LIKE t2} 1
|
||||
@@ -261,6 +260,23 @@ if {"\u1234"!="u1234"} {
|
||||
test_expr expr-5.24 "t1='ax\uFEDCy\uFEDC', t2='A%\uFEDC'" {t1 LIKE t2} 1
|
||||
}
|
||||
|
||||
# Theses tests are for when SQLite assumes iso8859 characters.
|
||||
#
|
||||
if {[sqlite -encoding]=="iso8859"} {
|
||||
set go 1
|
||||
if {[info command encoding]!=""} {
|
||||
if {[catch {encoding system iso8859-1} msg]} {
|
||||
puts "skipping tests of LIKE operator: $msg"
|
||||
set go 0
|
||||
}
|
||||
}
|
||||
if {$go} {
|
||||
test_expr expr-5.50 "t1='a\266c', t2='A_C'" {t1 LIKE t2} 1
|
||||
test_expr expr-5.51 "t1='a\347', t2='A_'" {t1 LIKE t2} 1
|
||||
test_expr expr-5.52 "t1='ax\351', t2='A_\351'" {t1 LIKE t2} 1
|
||||
test_expr expr-5.53 "t1='ax\241', t2='A_%'" {t1 LIKE t2} 1
|
||||
}
|
||||
}
|
||||
test_expr expr-5.54 {t1='abc', t2=NULL} {t1 LIKE t2} {{}}
|
||||
test_expr expr-5.55 {t1='abc', t2=NULL} {t1 NOT LIKE t2} {{}}
|
||||
test_expr expr-5.56 {t1='abc', t2=NULL} {t2 LIKE t1} {{}}
|
||||
@@ -300,7 +316,7 @@ test_expr expr-6.25 {t1='ac', t2='a*?c'} {t1 GLOB t2} 0
|
||||
|
||||
# These tests only work on versions of TCL that support Unicode
|
||||
#
|
||||
if {"\u1234"!="u1234"} {
|
||||
if {"\u1234"!="u1234" && [sqlite -encoding]=="UTF-8"} {
|
||||
test_expr expr-6.26 "t1='a\u0080c', t2='a?c'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.27 "t1='a\u07ffc', t2='a?c'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.28 "t1='a\u0800c', t2='a?c'" {t1 GLOB t2} 1
|
||||
@@ -348,6 +364,32 @@ test_expr expr-6.73 {t1='ABCDEFG', t2='A*?G'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.74 {t1='AC', t2='A*C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.75 {t1='AC', t2='A*?C'} {t1 GLOB t2} 0
|
||||
|
||||
# Theses tests are for when SQLite assumes iso8859 characters.
|
||||
#
|
||||
if {[sqlite -encoding]=="iso8859"} {
|
||||
set go 1
|
||||
if {[info command encoding]!=""} {
|
||||
if {[catch {encoding system iso8859-1} msg]} {
|
||||
puts "skipping tests of GLOB operator: $msg"
|
||||
set go 0
|
||||
}
|
||||
}
|
||||
if {$go} {
|
||||
test_expr expr-6.50 "t1='a\266c', t2='a?c'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.51 "t1='a\266', t2='a?'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.52 "t1='a\266', t2='a??'" {t1 GLOB t2} 0
|
||||
test_expr expr-6.53 "t1='ax\266', t2='a??'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.54 "t1='ax\266', t2='a?\266'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.55 "t1='ax\266y\266', t2='a*\266'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.56 "t1='a\266b', t2='a\[x\266y\]b'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.57 "t1='a\266b', t2='a\[\260-\270\]b'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.58 "t1='a\266b', t2='a\[\266-\270\]b'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.59 "t1='a\266b', t2='a\[\267-\270\]b'" {t1 GLOB t2} 0
|
||||
test_expr expr-6.60 "t1='a\266b', t2='a\[x-\267\]b'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.61 "t1='a\266b', t2='a\[x-\266\]b'" {t1 GLOB t2} 1
|
||||
test_expr expr-6.62 "t1='a\266b', t2='a\[x-\265\]b'" {t1 GLOB t2} 0
|
||||
}
|
||||
}
|
||||
test_expr expr-6.63 {t1=NULL, t2='a*?c'} {t1 GLOB t2} {{}}
|
||||
test_expr expr-6.64 {t1='ac', t2=NULL} {t1 GLOB t2} {{}}
|
||||
test_expr expr-6.65 {t1=NULL, t2='a*?c'} {t1 NOT GLOB t2} {{}}
|
||||
|
||||
@@ -0,0 +1,738 @@
|
||||
# 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 file is testing the the library is able to correctly
|
||||
# handle file-format 3 (version 2.6.x) databases.
|
||||
#
|
||||
# $Id: format3.test,v 1.4 2003/12/23 02:17:35 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Create a bunch of data to sort against
|
||||
#
|
||||
do_test format3-1.0 {
|
||||
set fd [open data.txt w]
|
||||
puts $fd "1\tone\t0\tI\t3.141592653"
|
||||
puts $fd "2\ttwo\t1\tII\t2.15"
|
||||
puts $fd "3\tthree\t1\tIII\t4221.0"
|
||||
puts $fd "4\tfour\t2\tIV\t-0.0013442"
|
||||
puts $fd "5\tfive\t2\tV\t-11"
|
||||
puts $fd "6\tsix\t2\tVI\t0.123"
|
||||
puts $fd "7\tseven\t2\tVII\t123.0"
|
||||
puts $fd "8\teight\t3\tVIII\t-1.6"
|
||||
close $fd
|
||||
execsql {
|
||||
CREATE TABLE t1(
|
||||
n int,
|
||||
v varchar(10),
|
||||
log int,
|
||||
roman varchar(10),
|
||||
flt real
|
||||
);
|
||||
COPY t1 FROM 'data.txt'
|
||||
}
|
||||
file delete data.txt
|
||||
db close
|
||||
set ::bt [btree_open test.db]
|
||||
btree_begin_transaction $::bt
|
||||
set m [btree_get_meta $::bt]
|
||||
set m [lreplace $m 2 2 3]
|
||||
eval btree_update_meta $::bt $m
|
||||
btree_commit $::bt
|
||||
btree_close $::bt
|
||||
sqlite db test.db
|
||||
execsql {SELECT count(*) FROM t1}
|
||||
} {8}
|
||||
|
||||
do_test format3-1.1 {
|
||||
execsql {SELECT n FROM t1 ORDER BY n}
|
||||
} {1 2 3 4 5 6 7 8}
|
||||
do_test format3-1.1.1 {
|
||||
execsql {SELECT n FROM t1 ORDER BY n ASC}
|
||||
} {1 2 3 4 5 6 7 8}
|
||||
do_test format3-1.1.1 {
|
||||
execsql {SELECT ALL n FROM t1 ORDER BY n ASC}
|
||||
} {1 2 3 4 5 6 7 8}
|
||||
do_test format3-1.2 {
|
||||
execsql {SELECT n FROM t1 ORDER BY n DESC}
|
||||
} {8 7 6 5 4 3 2 1}
|
||||
do_test format3-1.3a {
|
||||
execsql {SELECT v FROM t1 ORDER BY v}
|
||||
} {eight five four one seven six three two}
|
||||
do_test format3-1.3b {
|
||||
execsql {SELECT n FROM t1 ORDER BY v}
|
||||
} {8 5 4 1 7 6 3 2}
|
||||
do_test format3-1.4 {
|
||||
execsql {SELECT n FROM t1 ORDER BY v DESC}
|
||||
} {2 3 6 7 1 4 5 8}
|
||||
do_test format3-1.5 {
|
||||
execsql {SELECT flt FROM t1 ORDER BY flt}
|
||||
} {-11 -1.6 -0.0013442 0.123 2.15 3.141592653 123.0 4221.0}
|
||||
do_test format3-1.6 {
|
||||
execsql {SELECT flt FROM t1 ORDER BY flt DESC}
|
||||
} {4221.0 123.0 3.141592653 2.15 0.123 -0.0013442 -1.6 -11}
|
||||
do_test format3-1.7 {
|
||||
execsql {SELECT roman FROM t1 ORDER BY roman}
|
||||
} {I II III IV V VI VII VIII}
|
||||
do_test format3-1.8 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log, flt}
|
||||
} {1 2 3 5 4 6 7 8}
|
||||
do_test format3-1.8.1 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log asc, flt}
|
||||
} {1 2 3 5 4 6 7 8}
|
||||
do_test format3-1.8.2 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log, flt ASC}
|
||||
} {1 2 3 5 4 6 7 8}
|
||||
do_test format3-1.8.3 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log ASC, flt asc}
|
||||
} {1 2 3 5 4 6 7 8}
|
||||
do_test format3-1.9 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log, flt DESC}
|
||||
} {1 3 2 7 6 4 5 8}
|
||||
do_test format3-1.9.1 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log ASC, flt DESC}
|
||||
} {1 3 2 7 6 4 5 8}
|
||||
do_test format3-1.10 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log DESC, flt}
|
||||
} {8 5 4 6 7 2 3 1}
|
||||
do_test format3-1.11 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log DESC, flt DESC}
|
||||
} {8 7 6 4 5 3 2 1}
|
||||
|
||||
# These tests are designed to reach some hard-to-reach places
|
||||
# inside the string comparison routines.
|
||||
#
|
||||
# (Later) The sorting behavior changed in 2.7.0. But we will
|
||||
# keep these tests. You can never have too many test cases!
|
||||
#
|
||||
do_test format3-2.1.1 {
|
||||
execsql {
|
||||
UPDATE t1 SET v='x' || -flt;
|
||||
UPDATE t1 SET v='x-2b' where v=='x-0.123';
|
||||
SELECT v FROM t1 ORDER BY v;
|
||||
}
|
||||
} {x-123 x-2.15 x-2b x-3.141592653 x-4221 x0.0013442 x1.6 x11}
|
||||
do_test format3-2.1.2 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY substr(v,2,999);
|
||||
}
|
||||
} {x-4221 x-123 x-3.141592653 x-2.15 x0.0013442 x1.6 x11 x-2b}
|
||||
do_test format3-2.1.3 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY substr(v,2,999)+0.0;
|
||||
}
|
||||
} {x-4221 x-123 x-3.141592653 x-2.15 x-2b x0.0013442 x1.6 x11}
|
||||
do_test format3-2.1.4 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY substr(v,2,999) DESC;
|
||||
}
|
||||
} {x-2b x11 x1.6 x0.0013442 x-2.15 x-3.141592653 x-123 x-4221}
|
||||
do_test format3-2.1.5 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY substr(v,2,999)+0.0 DESC;
|
||||
}
|
||||
} {x11 x1.6 x0.0013442 x-2b x-2.15 x-3.141592653 x-123 x-4221}
|
||||
|
||||
# This is a bug fix for 2.2.4.
|
||||
# Strings are normally mapped to upper-case for a caseless comparison.
|
||||
# But this can cause problems for characters in between 'Z' and 'a'.
|
||||
#
|
||||
do_test format3-3.1 {
|
||||
execsql {
|
||||
CREATE TABLE t2(a,b);
|
||||
INSERT INTO t2 VALUES('AGLIENTU',1);
|
||||
INSERT INTO t2 VALUES('AGLIE`',2);
|
||||
INSERT INTO t2 VALUES('AGNA',3);
|
||||
SELECT a, b FROM t2 ORDER BY a;
|
||||
}
|
||||
} {AGLIENTU 1 AGLIE` 2 AGNA 3}
|
||||
do_test format3-3.2 {
|
||||
execsql {
|
||||
SELECT a, b FROM t2 ORDER BY a DESC;
|
||||
}
|
||||
} {AGNA 3 AGLIE` 2 AGLIENTU 1}
|
||||
do_test format3-3.3 {
|
||||
execsql {
|
||||
DELETE FROM t2;
|
||||
INSERT INTO t2 VALUES('aglientu',1);
|
||||
INSERT INTO t2 VALUES('aglie`',2);
|
||||
INSERT INTO t2 VALUES('agna',3);
|
||||
SELECT a, b FROM t2 ORDER BY a;
|
||||
}
|
||||
} {aglie` 2 aglientu 1 agna 3}
|
||||
do_test format3-3.4 {
|
||||
execsql {
|
||||
SELECT a, b FROM t2 ORDER BY a DESC;
|
||||
}
|
||||
} {agna 3 aglientu 1 aglie` 2}
|
||||
|
||||
# Version 2.7.0 testing.
|
||||
#
|
||||
do_test format3-4.1 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(9,'x2.7',3,'IX',4.0e5);
|
||||
INSERT INTO t1 VALUES(10,'x5.0e10',3,'X',-4.0e5);
|
||||
INSERT INTO t1 VALUES(11,'x-4.0e9',3,'XI',4.1e4);
|
||||
INSERT INTO t1 VALUES(12,'x01234567890123456789',3,'XII',-4.2e3);
|
||||
SELECT n FROM t1 ORDER BY n;
|
||||
}
|
||||
} {1 2 3 4 5 6 7 8 9 10 11 12}
|
||||
do_test format3-4.2 {
|
||||
execsql {
|
||||
SELECT n||'' FROM t1 ORDER BY 1;
|
||||
}
|
||||
} {1 2 3 4 5 6 7 8 9 10 11 12}
|
||||
do_test format3-4.3 {
|
||||
execsql {
|
||||
SELECT n+0 FROM t1 ORDER BY 1;
|
||||
}
|
||||
} {1 2 3 4 5 6 7 8 9 10 11 12}
|
||||
do_test format3-4.4 {
|
||||
execsql {
|
||||
SELECT n||'' FROM t1 ORDER BY 1 DESC;
|
||||
}
|
||||
} {12 11 10 9 8 7 6 5 4 3 2 1}
|
||||
do_test format3-4.5 {
|
||||
execsql {
|
||||
SELECT n+0 FROM t1 ORDER BY 1 DESC;
|
||||
}
|
||||
} {12 11 10 9 8 7 6 5 4 3 2 1}
|
||||
do_test format3-4.6 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY 1;
|
||||
}
|
||||
} {x-123 x-2.15 x-2b x-3.141592653 x-4.0e9 x-4221 x0.0013442 x01234567890123456789 x1.6 x11 x2.7 x5.0e10}
|
||||
do_test format3-4.7 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY 1 DESC;
|
||||
}
|
||||
} {x5.0e10 x2.7 x11 x1.6 x01234567890123456789 x0.0013442 x-4221 x-4.0e9 x-3.141592653 x-2b x-2.15 x-123}
|
||||
do_test format3-4.8 {
|
||||
execsql {
|
||||
SELECT substr(v,2,99) FROM t1 ORDER BY 1;
|
||||
}
|
||||
} {-4.0e9 -4221 -123 -3.141592653 -2.15 0.0013442 1.6 2.7 11 5.0e10 01234567890123456789 -2b}
|
||||
|
||||
# Build some new test data, this time with indices.
|
||||
#
|
||||
do_test format3-5.0 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(w int, x text, y blob);
|
||||
DROP TABLE t2;
|
||||
CREATE TABLE t2(p varchar(1), q clob, r real, s numeric(8));
|
||||
}
|
||||
for {set i 1} {$i<=100} {incr i} {
|
||||
set w $i
|
||||
set x [expr {int(log($i)/log(2))}]
|
||||
set y [expr {$i*$i + 2*$i + 1}]
|
||||
execsql "INSERT INTO t1 VALUES($w,$x,$y)"
|
||||
}
|
||||
execsql {
|
||||
INSERT INTO t2 SELECT 101-w, x, (SELECT max(y) FROM t1)+1-y, y FROM t1;
|
||||
CREATE INDEX i1w ON t1(w);
|
||||
CREATE INDEX i1xy ON t1(x,y);
|
||||
CREATE INDEX i2p ON t2(p);
|
||||
CREATE INDEX i2r ON t2(r);
|
||||
CREATE INDEX i2qs ON t2(q, s);
|
||||
}
|
||||
} {}
|
||||
|
||||
# Do an SQL statement. Append the search count to the end of the result.
|
||||
#
|
||||
proc count sql {
|
||||
set ::sqlite_search_count 0
|
||||
return [concat [execsql $sql] $::sqlite_search_count]
|
||||
}
|
||||
|
||||
# Verify that queries use an index. We are using the special variable
|
||||
# "sqlite_search_count" which tallys the number of executions of MoveTo
|
||||
# and Next operators in the VDBE. By verifing that the search count is
|
||||
# small we can be assured that indices are being used properly.
|
||||
#
|
||||
do_test format3-5.1 {
|
||||
db close
|
||||
sqlite db test.db
|
||||
count {SELECT x, y FROM t1 WHERE w=10}
|
||||
} {3 121 3}
|
||||
do_test format3-5.2 {
|
||||
count {SELECT x, y FROM t1 WHERE w=11}
|
||||
} {3 144 3}
|
||||
do_test format3-5.3 {
|
||||
count {SELECT x, y FROM t1 WHERE 11=w}
|
||||
} {3 144 3}
|
||||
do_test format3-5.4 {
|
||||
count {SELECT x, y FROM t1 WHERE 11=w AND x>2}
|
||||
} {3 144 3}
|
||||
do_test format3-5.5 {
|
||||
count {SELECT x, y FROM t1 WHERE y<200 AND w=11 AND x>2}
|
||||
} {3 144 3}
|
||||
do_test format3-5.6 {
|
||||
count {SELECT x, y FROM t1 WHERE y<200 AND x>2 AND w=11}
|
||||
} {3 144 3}
|
||||
do_test format3-5.7 {
|
||||
count {SELECT x, y FROM t1 WHERE w=11 AND y<200 AND x>2}
|
||||
} {3 144 3}
|
||||
do_test format3-5.8 {
|
||||
count {SELECT x, y FROM t1 WHERE w>10 AND y=144 AND x=3}
|
||||
} {3 144 3}
|
||||
do_test format3-5.9 {
|
||||
count {SELECT x, y FROM t1 WHERE y=144 AND w>10 AND x=3}
|
||||
} {3 144 3}
|
||||
do_test format3-5.10 {
|
||||
count {SELECT x, y FROM t1 WHERE x=3 AND w>=10 AND y=121}
|
||||
} {3 121 3}
|
||||
do_test format3-5.11 {
|
||||
count {SELECT x, y FROM t1 WHERE x=3 AND y=100 AND w<10}
|
||||
} {3 100 3}
|
||||
|
||||
# New for SQLite version 2.1: Verify that that inequality constraints
|
||||
# are used correctly.
|
||||
#
|
||||
do_test format3-5.12 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y<100}
|
||||
} {8 3}
|
||||
do_test format3-5.13 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 100>y}
|
||||
} {8 3}
|
||||
do_test format3-5.14 {
|
||||
count {SELECT w FROM t1 WHERE 3=x AND y<100}
|
||||
} {8 3}
|
||||
do_test format3-5.15 {
|
||||
count {SELECT w FROM t1 WHERE 3=x AND 100>y}
|
||||
} {8 3}
|
||||
do_test format3-5.16 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y<=100}
|
||||
} {8 9 5}
|
||||
do_test format3-5.17 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 100>=y}
|
||||
} {8 9 5}
|
||||
do_test format3-5.18 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y>225}
|
||||
} {15 3}
|
||||
do_test format3-5.19 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 225<y}
|
||||
} {15 3}
|
||||
do_test format3-5.20 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y>=225}
|
||||
} {14 15 5}
|
||||
do_test format3-5.21 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 225<=y}
|
||||
} {14 15 5}
|
||||
do_test format3-5.22 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y>121 AND y<196}
|
||||
} {11 12 5}
|
||||
do_test format3-5.23 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<=196}
|
||||
} {10 11 12 13 9}
|
||||
do_test format3-5.24 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 121<y AND 196>y}
|
||||
} {11 12 5}
|
||||
do_test format3-5.25 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 121<=y AND 196>=y}
|
||||
} {10 11 12 13 9}
|
||||
|
||||
# Need to work on optimizing the BETWEEN operator.
|
||||
#
|
||||
# do_test format3-5.26 {
|
||||
# count {SELECT w FROM t1 WHERE x=3 AND y BETWEEN 121 AND 196}
|
||||
# } {10 11 12 13 9}
|
||||
|
||||
do_test format3-5.27 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y+1==122}
|
||||
} {10 17}
|
||||
do_test format3-5.28 {
|
||||
count {SELECT w FROM t1 WHERE x+1=4 AND y+1==122}
|
||||
} {10 99}
|
||||
do_test format3-5.29 {
|
||||
count {SELECT w FROM t1 WHERE y==121}
|
||||
} {10 99}
|
||||
|
||||
|
||||
do_test format3-5.30 {
|
||||
count {SELECT w FROM t1 WHERE w>97}
|
||||
} {98 99 100 6}
|
||||
do_test format3-5.31 {
|
||||
count {SELECT w FROM t1 WHERE w>=97}
|
||||
} {97 98 99 100 8}
|
||||
do_test format3-5.33 {
|
||||
count {SELECT w FROM t1 WHERE w==97}
|
||||
} {97 3}
|
||||
do_test format3-5.34 {
|
||||
count {SELECT w FROM t1 WHERE w+1==98}
|
||||
} {97 99}
|
||||
do_test format3-5.35 {
|
||||
count {SELECT w FROM t1 WHERE w<3}
|
||||
} {1 2 4}
|
||||
do_test format3-5.36 {
|
||||
count {SELECT w FROM t1 WHERE w<=3}
|
||||
} {1 2 3 6}
|
||||
do_test format3-5.37 {
|
||||
count {SELECT w FROM t1 WHERE w+1<=4 ORDER BY w}
|
||||
} {1 2 3 199}
|
||||
|
||||
|
||||
# Do the same kind of thing except use a join as the data source.
|
||||
#
|
||||
do_test format3-6.1 {
|
||||
db close
|
||||
sqlite db test.db
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE x=q AND y=s AND r=8977
|
||||
}
|
||||
} {34 67 6}
|
||||
do_test format3-6.2 {
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE x=q AND s=y AND r=8977
|
||||
}
|
||||
} {34 67 6}
|
||||
do_test format3-6.3 {
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE x=q AND s=y AND r=8977 AND w>10
|
||||
}
|
||||
} {34 67 6}
|
||||
do_test format3-6.4 {
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE p<80 AND x=q AND s=y AND r=8977 AND w>10
|
||||
}
|
||||
} {34 67 6}
|
||||
do_test format3-6.5 {
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE p<80 AND x=q AND 8977=r AND s=y AND w>10
|
||||
}
|
||||
} {34 67 6}
|
||||
do_test format3-6.6 {
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE x=q AND p=77 AND s=y AND w>5
|
||||
}
|
||||
} {24 77 6}
|
||||
do_test format3-6.7 {
|
||||
count {
|
||||
SELECT w, p FROM t1, t2
|
||||
WHERE x=q AND p>77 AND s=y AND w=5
|
||||
}
|
||||
} {5 96 6}
|
||||
|
||||
# Lets do a 3-way join.
|
||||
#
|
||||
do_test format3-7.1 {
|
||||
count {
|
||||
SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C
|
||||
WHERE C.w=101-B.p AND B.r=10202-A.y AND A.w=11
|
||||
}
|
||||
} {11 90 11 9}
|
||||
do_test format3-7.2 {
|
||||
count {
|
||||
SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C
|
||||
WHERE C.w=101-B.p AND B.r=10202-A.y AND A.w=12
|
||||
}
|
||||
} {12 89 12 9}
|
||||
do_test format3-7.3 {
|
||||
count {
|
||||
SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C
|
||||
WHERE A.w=15 AND B.p=C.w AND B.r=10202-A.y
|
||||
}
|
||||
} {15 86 86 9}
|
||||
|
||||
# Test to see that the special case of a constant WHERE clause is
|
||||
# handled.
|
||||
#
|
||||
do_test format3-8.1 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE 0
|
||||
}
|
||||
} {0}
|
||||
do_test format3-8.2 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE 1 LIMIT 1
|
||||
}
|
||||
} {1 0 4 1}
|
||||
do_test format3-8.3 {
|
||||
execsql {
|
||||
SELECT 99 WHERE 0
|
||||
}
|
||||
} {}
|
||||
do_test format3-8.4 {
|
||||
execsql {
|
||||
SELECT 99 WHERE 1
|
||||
}
|
||||
} {99}
|
||||
|
||||
# Verify that IN operators in a WHERE clause are handled correctly.
|
||||
#
|
||||
do_test format3-9.1 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE rowid IN (1,2,3,1234) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 0}
|
||||
do_test format3-9.2 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE rowid+0 IN (1,2,3,1234) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 199}
|
||||
do_test format3-9.3 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 10}
|
||||
do_test format3-9.4 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w+0 IN (-1,1,2,3) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 199}
|
||||
do_test format3-9.5 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE rowid IN
|
||||
(select rowid from t1 where rowid IN (-1,2,4))
|
||||
ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 4 2 25 1}
|
||||
do_test format3-9.6 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE rowid+0 IN
|
||||
(select rowid from t1 where rowid IN (-1,2,4))
|
||||
ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 4 2 25 199}
|
||||
do_test format3-9.7 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w IN
|
||||
(select rowid from t1 where rowid IN (-1,2,4))
|
||||
ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 4 2 25 7}
|
||||
do_test format3-9.8 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w+0 IN
|
||||
(select rowid from t1 where rowid IN (-1,2,4))
|
||||
ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 4 2 25 199}
|
||||
do_test format3-9.9 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE x IN (1,7) ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 3 1 16 6}
|
||||
do_test format3-9.10 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE x+0 IN (1,7) ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 3 1 16 199}
|
||||
do_test format3-9.11 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE y IN (6400,8100) ORDER BY 1;
|
||||
}
|
||||
} {79 6 6400 89 6 8100 199}
|
||||
do_test format3-9.12 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE x=6 AND y IN (6400,8100) ORDER BY 1;
|
||||
}
|
||||
} {79 6 6400 89 6 8100 74}
|
||||
do_test format3-9.13 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE x IN (1,7) AND y NOT IN (6400,8100) ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 3 1 16 6}
|
||||
do_test format3-9.14 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,10) ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 6}
|
||||
|
||||
# This procedure executes the SQL. Then it checks the generated program
|
||||
# for the SQL and appends a "nosort" to the result if the program contains the
|
||||
# SortCallback opcode. If the program does not contain the SortCallback
|
||||
# opcode it appends "sort"
|
||||
#
|
||||
proc cksort {sql} {
|
||||
set data [execsql $sql]
|
||||
set prog [execsql "EXPLAIN $sql"]
|
||||
if {[regexp SortCallback $prog]} {set x sort} {set x nosort}
|
||||
lappend data $x
|
||||
return $data
|
||||
}
|
||||
# Check out the logic that attempts to implement the ORDER BY clause
|
||||
# using an index rather than by sorting.
|
||||
#
|
||||
do_test format3-10.1 {
|
||||
execsql {
|
||||
CREATE TABLE t3(a,b,c);
|
||||
CREATE INDEX t3a ON t3(a);
|
||||
CREATE INDEX t3bc ON t3(b,c);
|
||||
CREATE INDEX t3acb ON t3(a,c,b);
|
||||
INSERT INTO t3 SELECT w, 101-w, y FROM t1;
|
||||
SELECT count(*), sum(a), sum(b), sum(c) FROM t3;
|
||||
}
|
||||
} {100 5050 5050 348550}
|
||||
do_test format3-10.2 {
|
||||
cksort {
|
||||
SELECT * FROM t3 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 nosort}
|
||||
do_test format3-10.3 {
|
||||
cksort {
|
||||
SELECT * FROM t3 ORDER BY a+1 LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 sort}
|
||||
do_test format3-10.4 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a<10 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 nosort}
|
||||
do_test format3-10.5 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a>0 AND a<10 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 nosort}
|
||||
do_test format3-10.6 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a>0 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 nosort}
|
||||
do_test format3-10.7 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE b>0 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 sort}
|
||||
do_test format3-10.8 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a IN (3,5,7,1,9,4,2) ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 sort}
|
||||
do_test format3-10.9 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 nosort}
|
||||
do_test format3-10.10 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 nosort}
|
||||
do_test format3-10.11 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c LIMIT 3
|
||||
}
|
||||
} {1 100 4 nosort}
|
||||
do_test format3-10.12 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c,b LIMIT 3
|
||||
}
|
||||
} {1 100 4 nosort}
|
||||
do_test format3-10.13 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a>0 ORDER BY a DESC LIMIT 3
|
||||
}
|
||||
} {100 1 10201 99 2 10000 98 3 9801 nosort}
|
||||
do_test format3-10.13.1 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a>0 ORDER BY a+1 DESC LIMIT 3
|
||||
}
|
||||
} {100 1 10201 99 2 10000 98 3 9801 sort}
|
||||
do_test format3-10.14 {
|
||||
cksort {
|
||||
SELECT * FROM t3 ORDER BY b LIMIT 3
|
||||
}
|
||||
} {100 1 10201 99 2 10000 98 3 9801 nosort}
|
||||
do_test format3-10.15 {
|
||||
cksort {
|
||||
SELECT t3.a, t1.x FROM t3, t1 WHERE t3.a=t1.w ORDER BY t3.a LIMIT 3
|
||||
}
|
||||
} {1 0 2 1 3 1 nosort}
|
||||
do_test format3-10.16 {
|
||||
cksort {
|
||||
SELECT t3.a, t1.x FROM t3, t1 WHERE t3.a=t1.w ORDER BY t1.x, t3.a LIMIT 3
|
||||
}
|
||||
} {1 0 2 1 3 1 sort}
|
||||
do_test format3-10.17 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY w COLLATE text LIMIT 3;
|
||||
}
|
||||
} {4 121 10201 sort}
|
||||
do_test format3-10.18 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY w COLLATE numeric LIMIT 3;
|
||||
}
|
||||
} {4 9 16 sort}
|
||||
do_test format3-10.19 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY w LIMIT 3;
|
||||
}
|
||||
} {4 9 16 nosort}
|
||||
|
||||
# Check that all comparisons are numeric. Similar tests in misc1.test
|
||||
# check the same comparisons on a format4+ database and find that some
|
||||
# are numeric and some are text.
|
||||
#
|
||||
do_test format3-11.1 {
|
||||
execsql {SELECT '0'=='0.0'}
|
||||
} {1}
|
||||
do_test format3-11.2 {
|
||||
execsql {SELECT '0'==0.0}
|
||||
} {1}
|
||||
do_test format3-11.3 {
|
||||
execsql {SELECT '123456789012345678901'=='123456789012345678900'}
|
||||
} {1}
|
||||
do_test format3-11.4 {
|
||||
execsql {
|
||||
CREATE TABLE t6(a INT UNIQUE, b TEXT UNIQUE);
|
||||
INSERT INTO t6 VALUES('0','0.0');
|
||||
SELECT * FROM t6;
|
||||
}
|
||||
} {0 0.0}
|
||||
do_test format3-11.5 {
|
||||
execsql {
|
||||
INSERT OR IGNORE INTO t6 VALUES(0.0,'x');
|
||||
SELECT * FROM t6;
|
||||
}
|
||||
} {0 0.0}
|
||||
do_test format3-11.6 {
|
||||
execsql {
|
||||
INSERT OR IGNORE INTO t6 VALUES('y',0);
|
||||
SELECT * FROM t6;
|
||||
}
|
||||
} {0 0.0}
|
||||
do_test format3-11.7 {
|
||||
execsql {
|
||||
CREATE TABLE t7(x INTEGER, y TEXT, z);
|
||||
INSERT INTO t7 VALUES(0,0,1);
|
||||
INSERT INTO t7 VALUES(0.0,0,2);
|
||||
INSERT INTO t7 VALUES(0,0.0,3);
|
||||
INSERT INTO t7 VALUES(0.0,0.0,4);
|
||||
SELECT DISTINCT x, y FROM t7 ORDER BY z;
|
||||
}
|
||||
} {0 0}
|
||||
|
||||
# Make sure attempts to attach a format 3 database fail.
|
||||
#
|
||||
do_test format3-12.1 {
|
||||
file delete -force test2.db
|
||||
sqlite db2 test2.db
|
||||
catchsql {
|
||||
CREATE TABLE t8(x,y);
|
||||
ATTACH DATABASE 'test.db' AS format3;
|
||||
} db2;
|
||||
} {1 {incompatible file format in auxiliary database: format3}}
|
||||
do_test format3-12.2 {
|
||||
catchsql {
|
||||
ATTACH DATABASE 'test2.db' AS test2;
|
||||
}
|
||||
} {1 {cannot attach auxiliary databases to an older format master database}}
|
||||
db2 close
|
||||
|
||||
finish_test
|
||||
+8
-109
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing built-in functions.
|
||||
#
|
||||
# $Id: func.test,v 1.22 2004/06/17 05:36:45 danielk1977 Exp $
|
||||
# $Id: func.test,v 1.16 2002/11/04 19:32:26 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -94,9 +94,10 @@ do_test func-2.10 {
|
||||
execsql {SELECT substr(a,2,2) FROM t2}
|
||||
} {{} {} 45 {} 78}
|
||||
|
||||
# Only do the following tests if TCL has UTF-8 capabilities
|
||||
# Only do the following tests if TCL has UTF-8 capabilities and
|
||||
# the UTF-8 encoding is turned on in the SQLite library.
|
||||
#
|
||||
if {"\u1234"!="u1234"} {
|
||||
if {[sqlite -encoding]=="UTF-8" && "\u1234"!="u1234"} {
|
||||
|
||||
# Put some UTF-8 characters in the database
|
||||
#
|
||||
@@ -145,7 +146,7 @@ do_test func-3.99 {
|
||||
execsql {SELECT t1 FROM tbl1}
|
||||
} {this program is free software}
|
||||
|
||||
} ;# End \u1234!=u1234
|
||||
} ;# End [sqlite -encoding]==UTF-8 and \u1234!=u1234
|
||||
|
||||
# Test the abs() and round() functions.
|
||||
#
|
||||
@@ -166,13 +167,13 @@ do_test func-4.3 {
|
||||
} {0 {2 1.2345678901234 2}}
|
||||
do_test func-4.4 {
|
||||
catchsql {SELECT abs(c) FROM t1 ORDER BY a}
|
||||
} {0 {3 12345.6789 5}}
|
||||
} {0 {3 12345.67890 5}}
|
||||
do_test func-4.4.1 {
|
||||
execsql {SELECT abs(a) FROM t2}
|
||||
} {1 {} 345 {} 67890}
|
||||
do_test func-4.4.2 {
|
||||
execsql {SELECT abs(t1) FROM tbl1}
|
||||
} {0 0 0 0 0}
|
||||
} {this program is free software}
|
||||
|
||||
do_test func-4.5 {
|
||||
catchsql {SELECT round(a,b,c) FROM t1}
|
||||
@@ -284,7 +285,7 @@ do_test func-10.1 {
|
||||
catchsql {
|
||||
SELECT testfunc(NULL,NULL);
|
||||
}
|
||||
} {1 {first argument should be one of: int int64 string double null value}}
|
||||
} {1 {first argument to test function may not be NULL}}
|
||||
do_test func-10.2 {
|
||||
execsql {
|
||||
SELECT testfunc(
|
||||
@@ -336,106 +337,4 @@ do_test func-11.1 {
|
||||
}
|
||||
} [sqlite -version]
|
||||
|
||||
# Test that destructors passed to sqlite by calls to sqlite3_result_text()
|
||||
# etc. are called. These tests use two special user-defined functions
|
||||
# (implemented in func.c) only available in test builds.
|
||||
#
|
||||
# Function test_destructor() takes one argument and returns a copy of the
|
||||
# text form of that argument. A destructor is associated with the return
|
||||
# value. Function test_destructor_count() returns the number of outstanding
|
||||
# destructor calls for values returned by test_destructor().
|
||||
#
|
||||
do_test func-12.1 {
|
||||
execsql {
|
||||
SELECT test_destructor('hello world'), test_destructor_count();
|
||||
}
|
||||
} {{hello world} 1}
|
||||
do_test func-12.2 {
|
||||
execsql {
|
||||
SELECT test_destructor_count();
|
||||
}
|
||||
} {0}
|
||||
do_test func-12.3 {
|
||||
execsql {
|
||||
SELECT test_destructor('hello')||' world', test_destructor_count();
|
||||
}
|
||||
} {{hello world} 0}
|
||||
do_test func-12.4 {
|
||||
execsql {
|
||||
SELECT test_destructor_count();
|
||||
}
|
||||
} {0}
|
||||
do_test func-12.5 {
|
||||
execsql {
|
||||
CREATE TABLE t4(x);
|
||||
INSERT INTO t4 VALUES(test_destructor('hello'));
|
||||
INSERT INTO t4 VALUES(test_destructor('world'));
|
||||
SELECT min(test_destructor(x)), max(test_destructor(x)) FROM t4;
|
||||
}
|
||||
} {hello world}
|
||||
do_test func-12.6 {
|
||||
execsql {
|
||||
SELECT test_destructor_count();
|
||||
}
|
||||
} {0}
|
||||
do_test func-12.7 {
|
||||
execsql {
|
||||
DROP TABLE t4;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Test that the auxdata API for scalar functions works. This test uses
|
||||
# a special user-defined function only available in test builds,
|
||||
# test_auxdata(). Function test_auxdata() takes any number of arguments.
|
||||
do_test func-13.1 {
|
||||
execsql {
|
||||
SELECT test_auxdata('hello world');
|
||||
}
|
||||
} {0}
|
||||
do_test func-13.2 {
|
||||
execsql {
|
||||
CREATE TABLE t4(a, b);
|
||||
INSERT INTO t4 VALUES('abc', 'def');
|
||||
INSERT INTO t4 VALUES('ghi', 'jkl');
|
||||
}
|
||||
} {}
|
||||
do_test func-13.3 {
|
||||
execsql {
|
||||
SELECT test_auxdata('hello world') FROM t4;
|
||||
}
|
||||
} {0 1}
|
||||
do_test func-13.4 {
|
||||
execsql {
|
||||
SELECT test_auxdata('hello world', 123) FROM t4;
|
||||
}
|
||||
} {{0 0} {1 1}}
|
||||
do_test func-13.5 {
|
||||
execsql {
|
||||
SELECT test_auxdata('hello world', a) FROM t4;
|
||||
}
|
||||
} {{0 0} {1 0}}
|
||||
do_test func-13.6 {
|
||||
execsql {
|
||||
SELECT test_auxdata('hello'||'world', a) FROM t4;
|
||||
}
|
||||
} {{0 0} {1 0}}
|
||||
|
||||
# Test that auxilary data is preserved between calls for SQL variables.
|
||||
do_test func-13.7 {
|
||||
db close
|
||||
set DB [sqlite db test.db]
|
||||
set sql "SELECT test_auxdata( ? , a ) FROM t4;"
|
||||
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
|
||||
sqlite3_bind_text $STMT 1 hello -1
|
||||
set res [list]
|
||||
while { "SQLITE_ROW"==[sqlite3_step $STMT] } {
|
||||
lappend res [sqlite3_column_text $STMT 0]
|
||||
}
|
||||
lappend res [sqlite3_finalize $STMT]
|
||||
} {{0 0} {1 0} SQLITE_OK}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -15,7 +15,7 @@
|
||||
#
|
||||
# sqlite_commit_hook
|
||||
#
|
||||
# $Id: hook.test,v 1.4 2004/05/31 08:26:49 danielk1977 Exp $
|
||||
# $Id: hook.test,v 1.3 2004/01/15 02:44:03 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -65,7 +65,7 @@ do_test hook-3.5 {
|
||||
do_test hook-3.6 {
|
||||
set commit_cnt {}
|
||||
proc commit_hook {} {
|
||||
set ::commit_cnt [execsql {SELECT * FROM t2}]
|
||||
set ::commit_cnt [execsql {SELECT * FROM t2}]
|
||||
return 1
|
||||
}
|
||||
catchsql {
|
||||
@@ -73,7 +73,7 @@ do_test hook-3.6 {
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test hook-3.7 {
|
||||
set ::commit_cnt
|
||||
set commit_cnt
|
||||
} {1 2 2 3 3 4 4 5 5 6 6 7}
|
||||
do_test hook-3.8 {
|
||||
execsql {SELECT * FROM t2}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user