Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 739aab893a | |||
| 6a42c8f368 | |||
| 523de6a830 |
+16
-17
@@ -32,7 +32,7 @@ TCC = @TARGET_CC@ @TARGET_CFLAGS@ -I. -I${TOP}/src
|
||||
# Omitting the define will cause extra debugging code to be inserted and
|
||||
# includes extra comments when "EXPLAIN stmt" is used.
|
||||
#
|
||||
TCC += @TARGET_DEBUG@ @XTHREADCONNECT@
|
||||
TCC += @TARGET_DEBUG@
|
||||
|
||||
# Compiler options needed for programs that use the TCL library.
|
||||
#
|
||||
@@ -106,7 +106,7 @@ LTINSTALL = $(LIBTOOL) --mode=install $(INSTALL)
|
||||
|
||||
# You should not have to change anything below this line
|
||||
###############################################################################
|
||||
OPTS =
|
||||
|
||||
OPTS += -DSQLITE_OMIT_CURSOR # Cursors do not work at this time
|
||||
TCC += -DSQLITE_OMIT_CURSOR
|
||||
|
||||
@@ -115,7 +115,7 @@ TCC += -DSQLITE_OMIT_CURSOR
|
||||
LIBOBJ = alter.lo analyze.lo attach.lo auth.lo btree.lo build.lo \
|
||||
callback.lo complete.lo date.lo \
|
||||
delete.lo expr.lo func.lo hash.lo insert.lo \
|
||||
main.lo opcodes.lo os.lo os_unix.lo os_win.lo \
|
||||
main.lo opcodes.lo os_unix.lo os_win.lo \
|
||||
pager.lo parse.lo pragma.lo prepare.lo printf.lo random.lo \
|
||||
select.lo table.lo tokenize.lo trigger.lo update.lo \
|
||||
util.lo vacuum.lo \
|
||||
@@ -143,7 +143,6 @@ SRC = \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c \
|
||||
@@ -185,15 +184,11 @@ TESTSRC = \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/server.c \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/test5.c \
|
||||
$(TOP)/src/test6.c \
|
||||
$(TOP)/src/test7.c \
|
||||
$(TOP)/src/test_async.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
@@ -209,6 +204,8 @@ HDR = \
|
||||
opcodes.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/os_common.h \
|
||||
$(TOP)/src/os_unix.h \
|
||||
$(TOP)/src/os_win.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
parse.h
|
||||
@@ -331,9 +328,6 @@ opcodes.c: opcodes.h $(TOP)/mkopcodec.awk
|
||||
opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk
|
||||
cat parse.h $(TOP)/src/vdbe.c | awk -f $(TOP)/mkopcodeh.awk >opcodes.h
|
||||
|
||||
os.lo: $(TOP)/src/os.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/os.c
|
||||
|
||||
os_unix.lo: $(TOP)/src/os_unix.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/os_unix.c
|
||||
|
||||
@@ -345,11 +339,9 @@ parse.lo: parse.c $(HDR)
|
||||
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon$(BEXE) $(TOP)/addopcodes.awk
|
||||
parse.c: $(TOP)/src/parse.y lemon$(BEXE)
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon $(OPTS) parse.y
|
||||
mv parse.h parse.h.temp
|
||||
awk -f $(TOP)/addopcodes.awk parse.h.temp >parse.h
|
||||
|
||||
pragma.lo: $(TOP)/src/pragma.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/pragma.c
|
||||
@@ -427,12 +419,19 @@ tclsqlite3: tclsqlite-shell.lo libsqlite3.la
|
||||
libsqlite3.la $(LIBTCL)
|
||||
|
||||
testfixture$(TEXE): $(TOP)/src/tclsqlite.c libsqlite3.la $(TESTSRC)
|
||||
$(LTLINK) -DTCLSH=1 -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1 \
|
||||
$(TEMP_STORE) -o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
$(LTLINK) -DTCLSH=1 -DSQLITE_TEST=1 $(TEMP_STORE) \
|
||||
-o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.la $(LIBTCL)
|
||||
|
||||
crashtest$(TEXE): $(TOP)/src/tclsqlite.c libsqlite3.la $(TESTSRC) $(TOP)/src/os_test.c
|
||||
$(LTLINK) -DOS_TEST=1 -DTCLSH=1 -DSQLITE_TEST=1 \
|
||||
-o crashtest \
|
||||
$(TESTSRC) $(TOP)/src/os_test.c $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.la $(LIBTCL)
|
||||
|
||||
|
||||
fulltest: testfixture$(TEXE) sqlite3$(TEXE)
|
||||
|
||||
fulltest: testfixture$(TEXE) sqlite3$(TEXE) crashtest$(TEXE)
|
||||
./testfixture $(TOP)/test/all.test
|
||||
|
||||
test: testfixture$(TEXE) sqlite3$(TEXE)
|
||||
|
||||
@@ -53,7 +53,6 @@ THREADLIB =
|
||||
#OPTS = -DSQLITE_DEBUG=1
|
||||
#OPTS =
|
||||
OPTS = -DNDEBUG=1
|
||||
OPTS += -DHAVE_FDATASYNC=1
|
||||
|
||||
#### The suffix to add to executable files. ".exe" for windows.
|
||||
# Nothing for unix.
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#!/usr/bin/awk
|
||||
#
|
||||
# This script appends additional token codes to the end of the
|
||||
# parse.h file that lemon generates. These extra token codes are
|
||||
# not used by the parser. But they are used by the tokenizer and/or
|
||||
# the code generator.
|
||||
#
|
||||
#
|
||||
BEGIN {
|
||||
max = 0
|
||||
}
|
||||
/^#define TK_/ {
|
||||
print $0
|
||||
if( max<$3 ) max = $3
|
||||
}
|
||||
END {
|
||||
printf "#define TK_%-29s %4d\n", "TO_TEXT", max+1
|
||||
printf "#define TK_%-29s %4d\n", "TO_BLOB", max+2
|
||||
printf "#define TK_%-29s %4d\n", "TO_NUMERIC", max+3
|
||||
printf "#define TK_%-29s %4d\n", "TO_INT", max+4
|
||||
printf "#define TK_%-29s %4d\n", "TO_REAL", max+5
|
||||
printf "#define TK_%-29s %4d\n", "END_OF_FILE", max+6
|
||||
printf "#define TK_%-29s %4d\n", "ILLEGAL", max+7
|
||||
printf "#define TK_%-29s %4d\n", "SPACE", max+8
|
||||
printf "#define TK_%-29s %4d\n", "UNCLOSED_STRING", max+9
|
||||
printf "#define TK_%-29s %4d\n", "COMMENT", max+10
|
||||
printf "#define TK_%-29s %4d\n", "FUNCTION", max+11
|
||||
printf "#define TK_%-29s %4d\n", "COLUMN", max+12
|
||||
printf "#define TK_%-29s %4d\n", "AGG_FUNCTION", max+13
|
||||
printf "#define TK_%-29s %4d\n", "AGG_COLUMN", max+14
|
||||
printf "#define TK_%-29s %4d\n", "CONST_FUNC", max+15
|
||||
}
|
||||
@@ -463,7 +463,7 @@ ac_includes_default="\
|
||||
# include <unistd.h>
|
||||
#endif"
|
||||
|
||||
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP CPP CXX CXXFLAGS ac_ct_CXX CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA program_prefix VERSION RELEASE VERSION_NUMBER BUILD_CC BUILD_CFLAGS BUILD_LIBS TARGET_CC TARGET_CFLAGS TARGET_LINK TARGET_LFLAGS TARGET_RANLIB TARGET_AR THREADSAFE TARGET_THREAD_LIB XTHREADCONNECT ALLOWRELEASE TEMP_STORE BUILD_EXEEXT OS_UNIX OS_WIN TARGET_EXEEXT TARGET_LIBS TCL_VERSION TCL_BIN_DIR TCL_SRC_DIR TCL_LIBS TCL_INCLUDE_SPEC TCL_LIB_FILE TCL_LIB_FLAG TCL_LIB_SPEC TCL_STUB_LIB_FILE TCL_STUB_LIB_FLAG TCL_STUB_LIB_SPEC HAVE_TCL TARGET_READLINE_LIBS TARGET_READLINE_INC TARGET_HAVE_READLINE TARGET_DEBUG LIBOBJS LTLIBOBJS'
|
||||
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP CPP CXX CXXFLAGS ac_ct_CXX CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA program_prefix VERSION RELEASE VERSION_NUMBER BUILD_CC BUILD_CFLAGS BUILD_LIBS TARGET_CC TARGET_CFLAGS TARGET_LINK TARGET_LFLAGS TARGET_RANLIB TARGET_AR THREADSAFE TARGET_THREAD_LIB ALLOWRELEASE TEMP_STORE BUILD_EXEEXT OS_UNIX OS_WIN TARGET_EXEEXT TARGET_LIBS TCL_VERSION TCL_BIN_DIR TCL_SRC_DIR TCL_LIBS TCL_INCLUDE_SPEC TCL_LIB_FILE TCL_LIB_FLAG TCL_LIB_SPEC TCL_STUB_LIB_FILE TCL_STUB_LIB_FLAG TCL_STUB_LIB_SPEC HAVE_TCL TARGET_READLINE_LIBS TARGET_READLINE_INC TARGET_HAVE_READLINE TARGET_DEBUG LIBOBJS LTLIBOBJS'
|
||||
ac_subst_files=''
|
||||
|
||||
# Initialize some variables set by options.
|
||||
@@ -1026,7 +1026,6 @@ Optional Features:
|
||||
optimize for fast installation [default=yes]
|
||||
--disable-libtool-lock avoid locking (might break parallel builds)
|
||||
--enable-threadsafe Support threadsafe operation
|
||||
--enable-cross-thread-connections Allow connection sharing across threads
|
||||
--enable-releasemode Support libtool link to release mode
|
||||
--enable-tempstore Use an in-ram database for temporary tables (never,no,yes,always)
|
||||
--disable-tcl do not build TCL extension
|
||||
@@ -1497,7 +1496,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
|
||||
# The following RCS revision string applies to configure.in
|
||||
# $Revision: 1.35 $
|
||||
# $Revision: 1.31 $
|
||||
|
||||
#########
|
||||
# Programs needed
|
||||
@@ -3056,7 +3055,7 @@ ia64-*-hpux*)
|
||||
;;
|
||||
*-*-irix6*)
|
||||
# Find out which ABI we are using.
|
||||
echo '#line 3059 "configure"' > conftest.$ac_ext
|
||||
echo '#line 3058 "configure"' > conftest.$ac_ext
|
||||
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
(eval $ac_compile) 2>&5
|
||||
ac_status=$?
|
||||
@@ -4519,7 +4518,7 @@ fi
|
||||
|
||||
|
||||
# Provide some information about the compiler.
|
||||
echo "$as_me:4522:" \
|
||||
echo "$as_me:4521:" \
|
||||
"checking for Fortran 77 compiler version" >&5
|
||||
ac_compiler=`set X $ac_compile; echo $2`
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
|
||||
@@ -5553,11 +5552,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:5556: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:5555: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:5560: \$? = $ac_status" >&5
|
||||
echo "$as_me:5559: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -5786,11 +5785,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:5789: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:5788: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:5793: \$? = $ac_status" >&5
|
||||
echo "$as_me:5792: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -5846,11 +5845,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:5849: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:5848: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:5853: \$? = $ac_status" >&5
|
||||
echo "$as_me:5852: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@@ -8030,7 +8029,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 8033 "configure"
|
||||
#line 8032 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -8128,7 +8127,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 8131 "configure"
|
||||
#line 8130 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -10307,11 +10306,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:10310: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:10309: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:10314: \$? = $ac_status" >&5
|
||||
echo "$as_me:10313: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -10367,11 +10366,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:10370: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:10369: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:10374: \$? = $ac_status" >&5
|
||||
echo "$as_me:10373: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@@ -11728,7 +11727,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 11731 "configure"
|
||||
#line 11730 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -11826,7 +11825,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 11829 "configure"
|
||||
#line 11828 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -12653,11 +12652,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:12656: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:12655: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:12660: \$? = $ac_status" >&5
|
||||
echo "$as_me:12659: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -12713,11 +12712,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:12716: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:12715: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:12720: \$? = $ac_status" >&5
|
||||
echo "$as_me:12719: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@@ -14747,11 +14746,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:14750: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:14749: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:14754: \$? = $ac_status" >&5
|
||||
echo "$as_me:14753: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -14980,11 +14979,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:14983: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:14982: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:14987: \$? = $ac_status" >&5
|
||||
echo "$as_me:14986: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings
|
||||
@@ -15040,11 +15039,11 @@ else
|
||||
-e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:15043: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:15042: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:15047: \$? = $ac_status" >&5
|
||||
echo "$as_me:15046: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@@ -17224,7 +17223,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 17227 "configure"
|
||||
#line 17226 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -17322,7 +17321,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 17325 "configure"
|
||||
#line 17324 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -19500,31 +19499,6 @@ else
|
||||
fi
|
||||
|
||||
|
||||
##########
|
||||
# Do we want to allow a connection created in one thread to be used
|
||||
# in another thread. This does not work on many Linux systems (ex: RedHat 9)
|
||||
# due to bugs in the threading implementations. This is thus off by default.
|
||||
#
|
||||
# Check whether --enable-cross-thread-connections or --disable-cross-thread-connections was given.
|
||||
if test "${enable_cross_thread_connections+set}" = set; then
|
||||
enableval="$enable_cross_thread_connections"
|
||||
|
||||
else
|
||||
enable_xthreadconnect=no
|
||||
fi;
|
||||
echo "$as_me:$LINENO: checking whether to allow connections to be shared across threads" >&5
|
||||
echo $ECHO_N "checking whether to allow connections to be shared across threads... $ECHO_C" >&6
|
||||
if test "$enable_xthreadconnect" = "no"; then
|
||||
XTHREADCONNECT=''
|
||||
echo "$as_me:$LINENO: result: no" >&5
|
||||
echo "${ECHO_T}no" >&6
|
||||
else
|
||||
XTHREADCONNECT='-DSQLITE_ALLOW_XTHREAD_CONNECT=1'
|
||||
echo "$as_me:$LINENO: result: yes" >&5
|
||||
echo "${ECHO_T}yes" >&6
|
||||
fi
|
||||
|
||||
|
||||
##########
|
||||
# Do we want to support release
|
||||
#
|
||||
@@ -19556,7 +19530,7 @@ if test "${enable_tempstore+set}" = set; then
|
||||
enableval="$enable_tempstore"
|
||||
|
||||
else
|
||||
enable_tempstore=no
|
||||
enable_tempstore=yes
|
||||
fi;
|
||||
echo "$as_me:$LINENO: checking whether to use an in-ram database for temporary tables" >&5
|
||||
echo $ECHO_N "checking whether to use an in-ram database for temporary tables... $ECHO_C" >&6
|
||||
@@ -19574,15 +19548,10 @@ echo "${ECHO_T}no" >&6
|
||||
always )
|
||||
TEMP_STORE=3
|
||||
echo "$as_me:$LINENO: result: always" >&5
|
||||
echo "${ECHO_T}always" >&6
|
||||
;;
|
||||
yes )
|
||||
TEMP_STORE=3
|
||||
echo "$as_me:$LINENO: result: always" >&5
|
||||
echo "${ECHO_T}always" >&6
|
||||
;;
|
||||
* )
|
||||
TEMP_STORE=1
|
||||
TEMP_STORE=2
|
||||
echo "$as_me:$LINENO: result: yes" >&5
|
||||
echo "${ECHO_T}yes" >&6
|
||||
;;
|
||||
@@ -20371,105 +20340,6 @@ if test $ac_cv_func_usleep = yes; then
|
||||
fi
|
||||
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Redefine fdatasync as fsync on systems that lack fdatasync
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
echo "$as_me:$LINENO: checking for fdatasync" >&5
|
||||
echo $ECHO_N "checking for fdatasync... $ECHO_C" >&6
|
||||
if test "${ac_cv_func_fdatasync+set}" = set; then
|
||||
echo $ECHO_N "(cached) $ECHO_C" >&6
|
||||
else
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
/* confdefs.h. */
|
||||
_ACEOF
|
||||
cat confdefs.h >>conftest.$ac_ext
|
||||
cat >>conftest.$ac_ext <<_ACEOF
|
||||
/* end confdefs.h. */
|
||||
/* Define fdatasync to an innocuous variant, in case <limits.h> declares fdatasync.
|
||||
For example, HP-UX 11i <limits.h> declares gettimeofday. */
|
||||
#define fdatasync innocuous_fdatasync
|
||||
|
||||
/* System header to define __stub macros and hopefully few prototypes,
|
||||
which can conflict with char fdatasync (); below.
|
||||
Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
|
||||
<limits.h> exists even on freestanding compilers. */
|
||||
|
||||
#ifdef __STDC__
|
||||
# include <limits.h>
|
||||
#else
|
||||
# include <assert.h>
|
||||
#endif
|
||||
|
||||
#undef fdatasync
|
||||
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
builtin and then its argument prototype would still apply. */
|
||||
char fdatasync ();
|
||||
/* The GNU C library defines this for functions which it implements
|
||||
to always fail with ENOSYS. Some functions are actually named
|
||||
something starting with __ and the normal name is an alias. */
|
||||
#if defined (__stub_fdatasync) || defined (__stub___fdatasync)
|
||||
choke me
|
||||
#else
|
||||
char (*f) () = fdatasync;
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return f != fdatasync;
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
rm -f conftest.$ac_objext conftest$ac_exeext
|
||||
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
(eval $ac_link) 2>conftest.er1
|
||||
ac_status=$?
|
||||
grep -v '^ *+' conftest.er1 >conftest.err
|
||||
rm -f conftest.er1
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag"
|
||||
|| test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); }; } &&
|
||||
{ ac_try='test -s conftest$ac_exeext'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); }; }; then
|
||||
ac_cv_func_fdatasync=yes
|
||||
else
|
||||
echo "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_cv_func_fdatasync=no
|
||||
fi
|
||||
rm -f conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
fi
|
||||
echo "$as_me:$LINENO: result: $ac_cv_func_fdatasync" >&5
|
||||
echo "${ECHO_T}$ac_cv_func_fdatasync" >&6
|
||||
if test $ac_cv_func_fdatasync = yes; then
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_FDATASYNC=1"
|
||||
fi
|
||||
|
||||
|
||||
#########
|
||||
# Generate the output files.
|
||||
#
|
||||
@@ -21161,7 +21031,6 @@ s,@TARGET_RANLIB@,$TARGET_RANLIB,;t t
|
||||
s,@TARGET_AR@,$TARGET_AR,;t t
|
||||
s,@THREADSAFE@,$THREADSAFE,;t t
|
||||
s,@TARGET_THREAD_LIB@,$TARGET_THREAD_LIB,;t t
|
||||
s,@XTHREADCONNECT@,$XTHREADCONNECT,;t t
|
||||
s,@ALLOWRELEASE@,$ALLOWRELEASE,;t t
|
||||
s,@TEMP_STORE@,$TEMP_STORE,;t t
|
||||
s,@BUILD_EXEEXT@,$BUILD_EXEEXT,;t t
|
||||
|
||||
+3
-30
@@ -116,7 +116,7 @@ AC_INIT(src/sqlite.h.in)
|
||||
dnl Put the RCS revision string after AC_INIT so that it will also
|
||||
dnl show in in configure.
|
||||
# The following RCS revision string applies to configure.in
|
||||
# $Revision: 1.21 $
|
||||
# $Revision: 1.17 $
|
||||
|
||||
#########
|
||||
# Programs needed
|
||||
@@ -299,23 +299,6 @@ else
|
||||
fi
|
||||
AC_SUBST(TARGET_THREAD_LIB)
|
||||
|
||||
##########
|
||||
# Do we want to allow a connection created in one thread to be used
|
||||
# in another thread. This does not work on many Linux systems (ex: RedHat 9)
|
||||
# due to bugs in the threading implementations. This is thus off by default.
|
||||
#
|
||||
AC_ARG_ENABLE(cross-thread-connections,
|
||||
[ --enable-cross-thread-connections Allow connection sharing across threads],,enable_xthreadconnect=no)
|
||||
AC_MSG_CHECKING([whether to allow connections to be shared across threads])
|
||||
if test "$enable_xthreadconnect" = "no"; then
|
||||
XTHREADCONNECT=''
|
||||
AC_MSG_RESULT([no])
|
||||
else
|
||||
XTHREADCONNECT='-DSQLITE_ALLOW_XTHREAD_CONNECT=1'
|
||||
AC_MSG_RESULT([yes])
|
||||
fi
|
||||
AC_SUBST(XTHREADCONNECT)
|
||||
|
||||
##########
|
||||
# Do we want to support release
|
||||
#
|
||||
@@ -335,7 +318,7 @@ AC_SUBST(ALLOWRELEASE)
|
||||
# Do we want temporary databases in memory
|
||||
#
|
||||
AC_ARG_ENABLE(tempstore,
|
||||
[ --enable-tempstore Use an in-ram database for temporary tables (never,no,yes,always)],,enable_tempstore=no)
|
||||
[ --enable-tempstore Use an in-ram database for temporary tables (never,no,yes,always)],,enable_tempstore=yes)
|
||||
AC_MSG_CHECKING([whether to use an in-ram database for temporary tables])
|
||||
case "$enable_tempstore" in
|
||||
never )
|
||||
@@ -350,12 +333,8 @@ case "$enable_tempstore" in
|
||||
TEMP_STORE=3
|
||||
AC_MSG_RESULT([always])
|
||||
;;
|
||||
yes )
|
||||
TEMP_STORE=3
|
||||
AC_MSG_RESULT([always])
|
||||
;;
|
||||
* )
|
||||
TEMP_STORE=1
|
||||
TEMP_STORE=2
|
||||
AC_MSG_RESULT([yes])
|
||||
;;
|
||||
esac
|
||||
@@ -628,12 +607,6 @@ AC_SUBST(TARGET_DEBUG)
|
||||
#
|
||||
AC_CHECK_FUNC(usleep, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_USLEEP=1"])
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Redefine fdatasync as fsync on systems that lack fdatasync
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
AC_CHECK_FUNC(fdatasync, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_FDATASYNC=1"])
|
||||
|
||||
#########
|
||||
# Generate the output files.
|
||||
#
|
||||
|
||||
@@ -57,7 +57,7 @@ TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
|
||||
LIBOBJ+= alter.o analyze.o attach.o auth.o btree.o build.o \
|
||||
callback.o complete.o date.o delete.o \
|
||||
expr.o func.o hash.o insert.o \
|
||||
main.o opcodes.o os.o os_unix.o os_win.o \
|
||||
main.o opcodes.o os_unix.o os_win.o \
|
||||
pager.o parse.o pragma.o prepare.o printf.o random.o \
|
||||
select.o table.o tclsqlite.o tokenize.o trigger.o \
|
||||
update.o util.o vacuum.o \
|
||||
@@ -85,7 +85,6 @@ SRC = \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c \
|
||||
@@ -127,15 +126,11 @@ TESTSRC = \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/server.c \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/test5.c \
|
||||
$(TOP)/src/test6.c \
|
||||
$(TOP)/src/test7.c \
|
||||
$(TOP)/src/test_async.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
@@ -151,6 +146,8 @@ HDR = \
|
||||
opcodes.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/os_common.h \
|
||||
$(TOP)/src/os_unix.h \
|
||||
$(TOP)/src/os_win.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
parse.h
|
||||
@@ -265,9 +262,6 @@ opcodes.c: opcodes.h $(TOP)/mkopcodec.awk
|
||||
opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk
|
||||
cat parse.h $(TOP)/src/vdbe.c | awk -f $(TOP)/mkopcodeh.awk >opcodes.h
|
||||
|
||||
os.o: $(TOP)/src/os.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/os.c
|
||||
|
||||
os_unix.o: $(TOP)/src/os_unix.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/os_unix.c
|
||||
|
||||
@@ -279,11 +273,9 @@ parse.o: parse.c $(HDR)
|
||||
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon $(TOP)/addopcodes.awk
|
||||
parse.c: $(TOP)/src/parse.y lemon
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon $(OPTS) parse.y
|
||||
mv parse.h parse.h.temp
|
||||
awk -f $(TOP)/addopcodes.awk parse.h.temp >parse.h
|
||||
|
||||
pragma.o: $(TOP)/src/pragma.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
|
||||
@@ -358,12 +350,17 @@ tclsqlite3: $(TOP)/src/tclsqlite.c libsqlite3.a
|
||||
$(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
testfixture$(EXE): $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC)
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1 \
|
||||
-DSQLITE_SERVER=1 -o testfixture$(EXE) \
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -o testfixture$(EXE) \
|
||||
$(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
fulltest: testfixture$(EXE) sqlite3$(EXE)
|
||||
crashtest: $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC) $(TOP)/src/os_test.c
|
||||
$(TCCX) $(TCL_FLAGS) -DOS_TEST=1 -DTCLSH=1 -DSQLITE_TEST=1 \
|
||||
-o crashtest \
|
||||
$(TESTSRC) $(TOP)/src/os_test.c $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
fulltest: testfixture$(EXE) sqlite3$(EXE) crashtest
|
||||
./testfixture$(EXE) $(TOP)/test/all.test
|
||||
|
||||
test: testfixture$(EXE) sqlite3$(EXE)
|
||||
@@ -457,9 +454,6 @@ pragma.html: $(TOP)/www/pragma.tcl
|
||||
lockingv3.html: $(TOP)/www/lockingv3.tcl
|
||||
tclsh $(TOP)/www/lockingv3.tcl >lockingv3.html
|
||||
|
||||
sharedcache.html: $(TOP)/www/sharedcache.tcl
|
||||
tclsh $(TOP)/www/sharedcache.tcl >sharedcache.html
|
||||
|
||||
mingw.html: $(TOP)/www/mingw.tcl
|
||||
tclsh $(TOP)/www/mingw.tcl >mingw.html
|
||||
|
||||
@@ -540,7 +534,6 @@ DOC = \
|
||||
optoverview.html \
|
||||
pragma.html \
|
||||
quickstart.html \
|
||||
sharedcache.html \
|
||||
speed.html \
|
||||
sqlite.html \
|
||||
support.html \
|
||||
@@ -562,7 +555,7 @@ install: sqlite3 libsqlite3.a sqlite3.h
|
||||
mv sqlite3.h /usr/include
|
||||
|
||||
clean:
|
||||
rm -f *.o sqlite3 libsqlite3.a sqlite3.h opcodes.*
|
||||
rm -f *.o sqlite3 libsqlite3.a sqlite3.h opcodes.* crashtest
|
||||
rm -f lemon lempar.c parse.* sqlite*.tar.gz mkkeywordhash keywordhash.h
|
||||
rm -f $(PUBLISH)
|
||||
rm -f *.da *.bb *.bbg gmon.out
|
||||
|
||||
@@ -1,125 +1,113 @@
|
||||
C Version\s3.3.1\s(alpha)\s(CVS\s2953)
|
||||
D 2006-01-16T02:39:05
|
||||
F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967
|
||||
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
|
||||
C Version\s3.2.8\s(CVS\s2835)
|
||||
D 2005-12-19T17:27:00
|
||||
F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
|
||||
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
|
||||
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
|
||||
F VERSION c8f0db9f26a66d73b1a3a93e006fd0a5dc4cd764
|
||||
F VERSION 4cef1bf020a669a809eb9ae30b049af780c5b52b
|
||||
F aclocal.m4 7daea4c35e88de30d5a3f6f7a2ab99720e803bbd
|
||||
F addopcodes.awk 701697fae48376375ec8532c3d04e910cfeef352
|
||||
F art/2005osaward.gif 0d1851b2a7c1c9d0ccce545f3e14bca42d7fd248
|
||||
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 18b8afcd5b4df4408f19aef75c4f3fc4f0e65623 x
|
||||
F configure.ac e067b3abb59b29bdb4d784a8c9abb56a797c8da5
|
||||
F configure b36e5d4156002b857e4c741626a7ac8412c2885c x
|
||||
F configure.ac fe941d9e98fff7edecdaca36a730da76f397f378
|
||||
F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad
|
||||
F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
|
||||
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
|
||||
F main.mk f397e2343efec5f89f6481c694439e0f50c30ee1
|
||||
F mkdll.sh f80661ba5f9e23fb5d6e3da532433da766c917f5
|
||||
F main.mk 72176d7299c2fd6ca2850623195a6984f75380a6
|
||||
F mkdll.sh 5ec23622515d5bf8969404e80cfb5e220ddf0512
|
||||
F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d
|
||||
F mkopcodeh.awk 071dbba4eaf56c8d643baf4604a043af35683316
|
||||
F mkopcodeh.awk c5ed62f101d408e64bcad0a8c036d85e99905480
|
||||
F mkso.sh 125868def279650a07d3f0f5e8476fecf99613fd
|
||||
F publish.sh ed0aba4ffdfadb36597d03ce8efdae96efc038cb
|
||||
F spec.template b2f6c4e488cbc3b993a57deba22cbc36203c4da3
|
||||
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
|
||||
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||
F sqlite3.def f756049b1bf3e8442baf6862db393ca423225262
|
||||
F sqlite3.def c413e514217736884254739a105c8c942fdf0c2f
|
||||
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
|
||||
F src/alter.c 4139c8f1d0f12b1759e767b1d09dd594e2b5ac1d
|
||||
F src/analyze.c 7d2b7ab9a9c2fd6e55700f69064dfdd3e36d7a8a
|
||||
F src/attach.c d4b9d8bd71d72409720946355be41cafb6c09079
|
||||
F src/auth.c 9ae84d2d94eb96195e04515715e08e85963e96c2
|
||||
F src/btree.c a4c147937df5ab7d18cf8da67eb766a00c0be1b2
|
||||
F src/btree.h 5663c4f43e8521546ccebc8fc95acb013b8f3184
|
||||
F src/build.c 206c891028158668691f27bcbf7c3c4f15248a94
|
||||
F src/callback.c ba3e6cc7a6beb562e7a66f92e26fabcb21aab1e2
|
||||
F src/complete.c df1681cef40dec33a286006981845f87b194e7a4
|
||||
F src/date.c 5f5850c6b5da68fdc47d124573715ba948c9d8e0
|
||||
F src/delete.c c7bd5708a629585e073ce34cf3b1fcb52c2fef38
|
||||
F src/alter.c 26d755f2143719dd3f5b8aaf6cbe3c7f95332528
|
||||
F src/analyze.c 21a4cd125bedd3cb15857595c45c2a49c0556d26
|
||||
F src/attach.c 4b21689700a72ae281fa85dbaff06b2a62bd49ee
|
||||
F src/auth.c 31e2304bef67f44d635655f44234387ea7d21454
|
||||
F src/btree.c 236126155d5607da945d33514218cbec762d887e
|
||||
F src/btree.h 1ed561263ca0e335bc3e81d761c9d5ff8c22f61e
|
||||
F src/build.c aa9591839c00731370c1ba53a9c0045f70d764c4
|
||||
F src/callback.c 9a1162c8f9dae9fad6d548339669aacb5f6cf76b
|
||||
F src/complete.c 4de937dfdd4c79a501772ab2035b26082f337a79
|
||||
F src/date.c 7444b0900a28da77e57e3337a636873cff0ae940
|
||||
F src/delete.c 29dac493f4d83b05f91233b116827c133bcdab72
|
||||
F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
|
||||
F src/expr.c f885cfe73fb235635fba72e78bb858c64529771f
|
||||
F src/func.c be4c026c1d2401f14c3186611e1131a895a3ca6e
|
||||
F src/hash.c 8747cf51d12de46512880dfcf1b68b4e24072863
|
||||
F src/expr.c bb2cf5d5b065eaa23d5ae2620f6de0568768147d
|
||||
F src/func.c f63d417248808ff2632a3b576536abffcc21d858
|
||||
F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f
|
||||
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
|
||||
F src/insert.c a5595cf8d1d8ba087b676a63f1f7277ea44b5ac1
|
||||
F src/legacy.c 9bf7ee1b63c99aac6669533986a5240b16101458
|
||||
F src/main.c 39d073fb1f95f874ee0c98366e99005cf14742dd
|
||||
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
|
||||
F src/os.c 1d1a61cdf150e9f9520a3bc787c8465148ea2e78
|
||||
F src/os.h 9debc3d3ca4cdafde222a0ea74a4c8415aef4f22
|
||||
F src/os_common.h 6b76efa9b252e288de53b202ed5a0d48f48dc8db
|
||||
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
|
||||
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
|
||||
F src/os_unix.c 7daa1720d46bbc31c6138462b35876650eb1885e
|
||||
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
|
||||
F src/os_win.c cd4ca2753aeaad11f5c9b9b6ef28752f45ed4529
|
||||
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
|
||||
F src/pager.c 12da1f38d60a2c44925281d3a1bc2769fa36428b
|
||||
F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f
|
||||
F src/parse.y 83df51fea35f68f7e07384d75dce83d1ed30434c
|
||||
F src/pragma.c 4496cc77dc35824e1c978c3d1413b8a5a4c777d3
|
||||
F src/prepare.c 1058dcb102005a880d757551d52a0a2830c05f27
|
||||
F src/printf.c f47a2f4b5387cd2ebb12e9117a1a5d6bd9a2b812
|
||||
F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
|
||||
F src/select.c 28d449c7762dd580aaba49a9c6c16e93ca951e49
|
||||
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
|
||||
F src/shell.c 66b073375efbdee19045e7e0cd38b85f9aff71da
|
||||
F src/sqlite.h.in 492580f7e3ff71eb43193eb7bb98e2d549889ce3
|
||||
F src/sqliteInt.h ed482d6de58fa79000f9c3bb00d7740126fb55fb
|
||||
F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
|
||||
F src/tclsqlite.c d650bea0248fc0a310ddc2cb94273a3a5021fddf
|
||||
F src/test1.c d21e94ea95e76d8e838792806937332c5693dbf0
|
||||
F src/test2.c ca74a1d8aeb7d9606e8f6b762c5daf85c1a3f92b
|
||||
F src/test3.c 9742aa146eb750cab81c1d5605286c3a0eb88054
|
||||
F src/test4.c 6633cb7b4a7429e938804a34f688d118c8b7f8e1
|
||||
F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f
|
||||
F src/test6.c 74d91b487c68154156eded457925d96aa2a3fdbb
|
||||
F src/test7.c c87fd373a613986113717ba51e6a5ad86407c1f7
|
||||
F src/test_async.c 6776f5027ca6378c116ff5ccc2fe41b908e33772
|
||||
F src/tokenize.c 8b694d42b48f22c2037da7e1e716201aaaaa0f3a
|
||||
F src/trigger.c 694b247476d2fc0dce003af564f79e8752fc1158
|
||||
F src/update.c 261d75c702c2852d1a64274d7c414485e6f2d177
|
||||
F src/utf.c 5ab8ca05d4e9ec81174b010f01ab12a232f0087d
|
||||
F src/util.c 0d0dc8279d4d0f43eb5d02313b77ab0ffa70f96d
|
||||
F src/vacuum.c 21a3c7f6f7be86bb1182fbc3df416ad702435b9e
|
||||
F src/vdbe.c 4db1a9000e238e068de56108f5a9708cd4124d55
|
||||
F src/insert.c 1f51566d7cf4b243a2792f5fda37343d6e9377fa
|
||||
F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
|
||||
F src/main.c 422014201f22aa17b96c76650163178a91a825af
|
||||
F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
|
||||
F src/os.h c51f2747f7bd1840447e2c7d26db749604626814
|
||||
F src/os_common.h 1ff88c7e7e6bd3e5f85443106c91cc26a4f8600b
|
||||
F src/os_unix.c 407dd07818d13807c396acf3f7570af81cbb666c
|
||||
F src/os_win.c fbccc85e7011174068c27d54256746321a1f0059
|
||||
F src/pager.c b74ebe5aca00ad5f831e19ae17193fe7b83a7ddf
|
||||
F src/pager.h e7b41ce8e7b5f629d456708b7ad9a8c8ede37140
|
||||
F src/parse.y 5602d5cb894dda2932bf50b7e88782a4440ae3ae
|
||||
F src/pragma.c 126149668aa7086e86cfa3e32c8523513c19dd63
|
||||
F src/prepare.c fc098db25d2a121affb08686cf04833fd50452d4
|
||||
F src/printf.c bd421c1ad5e01013c89af63c60eab02852ccd15e
|
||||
F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
|
||||
F src/select.c 034c7f7447b8711f85bef578a437ea12ca7cac53
|
||||
F src/shell.c 3596c1e559b82663057940d19ba533ad421c7dd3
|
||||
F src/sqlite.h.in 461b2535550cf77aedfd44385da11ef7d63e57a2
|
||||
F src/sqliteInt.h 53daa72541b4336c5e89773cf39717ed695bd523
|
||||
F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
|
||||
F src/tclsqlite.c ac94682f9e601dd373912c46414a5a842db2089a
|
||||
F src/test1.c 0f1a66f65a54fba029f7e93b7500d49443dc959b
|
||||
F src/test2.c 4196848c845626e7df894470f27329e80bfe92aa
|
||||
F src/test3.c f4e6a16a602091696619a1171bda25c0e3df49f7
|
||||
F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
|
||||
F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5
|
||||
F src/tokenize.c e1faf5637f3f4f90933785a0ecf64595f3ac3530
|
||||
F src/trigger.c f51dec15921629591cb98bf2e350018e268b109a
|
||||
F src/update.c ac506fb7400158f826ec6c3a0dbe65e7ed3928d5
|
||||
F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c
|
||||
F src/util.c 55caaffbb2716f9928ab452d20f3e9cbbeab872d
|
||||
F src/vacuum.c 829d9e1a6d7c094b80e0899686670932eafd768c
|
||||
F src/vdbe.c 3f1adcf4535dd35e4244d19d332fb6b515491c0d
|
||||
F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
|
||||
F src/vdbeInt.h 5451cf71f229e366ac543607c0a17f36e5737ea9
|
||||
F src/vdbeapi.c afd3837cea0dec93dcb4724d073c84fa0da68e23
|
||||
F src/vdbeaux.c bfad18ca5d0372a34147ed98ac268b75ccb6858d
|
||||
F src/vdbeInt.h 7bedbb9553a10e86b53f75d99e197f3f00a732bf
|
||||
F src/vdbeapi.c 85bbe1d0243a89655433d60711b4bd71979b59cd
|
||||
F src/vdbeaux.c 2b728d82cf2095386a90051b66e7faf1a143f27d
|
||||
F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
|
||||
F src/vdbemem.c dd08a0eea4868ac4a2d91fdec32424308b1db772
|
||||
F src/where.c 9fd58a8f5525d036a088c92bb14e2885c2243bc8
|
||||
F src/vdbemem.c ff426ff6e72aa3f0300a56ec8c7f18099be96b43
|
||||
F src/where.c 3ed72ca029b3010a76e3a41b7b02ec1bdf849f00
|
||||
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
|
||||
F test/all.test a23fcbbf1f53515bde840d78732a6d94c673b327
|
||||
F test/alter.test 1ac1263c8436bce05143565ed79c3c3c7c4bacaa
|
||||
F test/alter2.test cc0b8832e4e98605dbc26910efd4bb89abe59cb2
|
||||
F test/alter3.test 6e144ea3dcc395afcc28e794bb532be83dc8fdcb
|
||||
F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
|
||||
F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
|
||||
F test/alter2.test 60ba0a7057dc71ad630a1cc7c487104346849d50
|
||||
F test/alter3.test d4eecd8dbd008d0e66f1c201fa6dc2edca853c38
|
||||
F test/altermalloc.test 6e1f404ec021eb2ba6582e3c77b0a35cf206b7af
|
||||
F test/analyze.test 2f55535aa335785db1a2f97d3f3831c16c09f8b0
|
||||
F test/async.test 0f71d47219311c1e7c65b95ef18faa7b65472913
|
||||
F test/attach.test dae07fa1554b618b9cc4c7bc349b3bc1a532180e
|
||||
F test/attach2.test 0e6a7c54343c85dd877a1e86073a05176043ed40
|
||||
F test/attach.test f320e98bcca68d100cab7666a0c9a93ac5f236bd
|
||||
F test/attach2.test 3396c012a39ddf7ba6b528d80bd79554168aa115
|
||||
F test/attach3.test 63013383adc4380af69779f34f4af19bd49f7cbe
|
||||
F test/attachmalloc.test cdb26c42850f04698377ccec05f5fa89d987837c
|
||||
F test/auth.test 487fdd95cf1f765815455012e7338d9019bf8852
|
||||
F test/autoinc.test 60005a676e3e4e17dfa9dbd08aa0b76587ff97e3
|
||||
F test/auth.test 973ae7274eae32c4453fbbcbd0ec2b80c5b1eeb3
|
||||
F test/autoinc.test 395fbac8bc158d3599995c73bfb15c418a5429f0
|
||||
F test/autovacuum.test 9471d58a08b14dc0d2c15b87583c46d1744343d6
|
||||
F test/autovacuum_crash.test 05a63b8805b20cfba7ace82856ce4ccdda075a31
|
||||
F test/autovacuum_ioerr.test 9cf27275ca47b72e188a47c53b61b6d583a01d24
|
||||
F test/autovacuum_ioerr2.test 2f8a3fb31f833fd0ca86ad4ad98913c73e807572
|
||||
F test/avtrans.test 507834a6e1ef4aeea9b8bc2b45f9246d7e66ad3f
|
||||
F test/between.test ca092fa28b665ca92172b182c6c360a92f7ca348
|
||||
F test/bigfile.test ebc9ce9216e08bead63734ab816d0f27858f3b80
|
||||
F test/bigfile.test f768fb6078604cefb73dba0690f0115cc60e6305
|
||||
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
|
||||
F test/bind.test 7c01e8a660e33586bc0c1d596d5a7a7f5e7523fe
|
||||
F test/bindxfer.test b76bfb7df68bb0b238039f4543a84e9612291b54
|
||||
F test/blob.test 28c3b25150684ee3d108bb78cfb67a472deef2f0
|
||||
F test/bind.test 3169339a9fb7aaa8244d0ed8651fe6b6796d809c
|
||||
F test/bindxfer.test 856830e9e5552b9882c9d5c6647f90e25bdae4ac
|
||||
F test/blob.test 0b4ee6fef7a50685b88d921e2992606999510881
|
||||
F test/btree.test 8aa7424aeec844df990273fe36447e5d7e407261
|
||||
F test/btree2.test dbce930b549d5ac883a7d8905c976209ea241db3
|
||||
F test/btree4.test 3797b4305694c7af6828675b0f4b1424b8ca30e4
|
||||
@@ -128,160 +116,141 @@ F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027
|
||||
F test/btree7.test a6d3b842db22af97dd14b989e90a2fd96066b72f
|
||||
F test/btree8.test fadc112bcbd6a0c622d34c813fc8a648eacf8804
|
||||
F test/busy.test 0271c854738e23ad76e10d4096a698e5af29d211
|
||||
F test/capi2.test b9354d6c37e6f8f858c08952ebc9709712581221
|
||||
F test/capi3.test 318098b606490b2e29c6228743e5c4b37da8c368
|
||||
F test/capi3b.test 5f0bc94b104e11086b1103b20277e1910f59c7f4
|
||||
F test/cast.test 2543165ced4249c89ce5f0352222df503a98b9e5
|
||||
F test/check.test 686df5fd9fb986198787f00a79d86b68feb02e32
|
||||
F test/collate1.test add9454cef160677bb8b34148b8f277ce7f9f1c4
|
||||
F test/capi2.test f897209386fb21cfdc9267595e0c667ebaca9164
|
||||
F test/capi3.test fc8e573467049add3bfaf81f53827e8ff153cf8f
|
||||
F test/capi3b.test 5b6a66f9f295f79f443b5d3f33187fa5ef6cf336
|
||||
F test/cast.test 937af85faabdb189b6cd05879977f2469223be59
|
||||
F test/collate1.test f79736d2ebf5492167ee4d1f4ab4c09dda776b03
|
||||
F test/collate2.test 224a632ba04907c049804b08162efd234aa7871f
|
||||
F test/collate3.test 947a77f5b8227e037a7094d0e338a5504f155cc4
|
||||
F test/collate4.test daf498e294dcd596b961d425c3f2dda117e4717e
|
||||
F test/collate5.test 8fb4e7e0241839356bd8710f437c32efb47bfff8
|
||||
F test/collate6.test 6c9470d1606ee3e564675b229653e320c49ec638
|
||||
F test/conflict.test bc7b81670abfd6ca51cbcbf46ef23cd52784fafd
|
||||
F test/conflict.test 774e10709f5e9a9a7352dc929b856929ec805e58
|
||||
F test/corrupt.test 18c7a995b1af76a8c8600b996257f2c7b7bff083
|
||||
F test/corrupt2.test 88342570828f2b8cbbd8369eff3891f5c0bdd5ba
|
||||
F test/crash.test 5f5f155393c5685b3842fef79b6fbafa55197d75
|
||||
F test/crash.test 131259005bb5dbe776eba8de99408a493c69c06c
|
||||
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
|
||||
F test/date.test 288b41dbcc7aa114a976c53b45b78b3aa7736940
|
||||
F test/date.test 30ca15e608a45d868fd419c901795382efe27020
|
||||
F test/default.test 252298e42a680146b1dd64f563b95bdf088d94fb
|
||||
F test/delete.test 525a6953bc3978780cae35f3eaf1027cf4ce887d
|
||||
F test/delete2.test d20b08733243f1890079f3b48f2356fbb62212b2
|
||||
F test/delete.test 33e1670049364fc3604217a6c2eda042a47115ab
|
||||
F test/delete2.test e382b6a97787197eb8b93dd4ccd37797c3725ea3
|
||||
F test/delete3.test 555e84a00a99230b7d049d477a324a631126a6ab
|
||||
F test/descidx1.test 616076c4fd7efb0098a69a53f965af6e1eb4e7ca
|
||||
F test/descidx2.test f9f73c562932b81207faa525cd52acdfd2fc0482
|
||||
F test/descidx3.test b826d067392d48387f19f70f2ea51a93fd0d4ec1
|
||||
F test/diskfull.test d828d72adfc9e2d1a194d25996718c1989152cf9
|
||||
F test/distinctagg.test 2b89d1c5220d966a30ba4b40430338669301188b
|
||||
F test/enc.test 7a03417a1051fe8bc6c7641cf4c8c3f7e0066d52
|
||||
F test/enc2.test 0c8d3142c032c4f907b546d99e00b787f9700bb7
|
||||
F test/enc3.test 890508efff6677345e93bf2a8adb0489b30df030
|
||||
F test/expr.test a513aceb5d89042232e0d07ac5a1591965cf3963
|
||||
F test/enc2.test 76c13b8c00beaf95b15c152e95dab51292eb1f0d
|
||||
F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837
|
||||
F test/expr.test 71b8cba7fe5c228147c93e530e098144565aaa46
|
||||
F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
|
||||
F test/format4.test 9f31d41d4f926cab97b2ebe6be00a6ab12dece87
|
||||
F test/func.test a7119afcc16abdf24b24486684fb888279008f75
|
||||
F test/hook.test fc6821544ab2e0aacb398b742cdca925d4fb884c
|
||||
F test/func.test 431f8e07a30aadf2a2a0c8c32f918a497bc4331d
|
||||
F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda
|
||||
F test/in.test cead6165aebbe0d451bb2263a307173acfeb6240
|
||||
F test/index.test c90ab389586dbddfeb6817cd137737b2de1b6522
|
||||
F test/index.test 51e01a0928b4b61228917ddd8c6c0e2466547f6f
|
||||
F test/index2.test 9ad98243fd7fe833795a9cc662f371f0eed4ff4f
|
||||
F test/index3.test f66718cd92ce1216819d47e6a156755e4b2c4ca1
|
||||
F test/insert.test b0a89e1568fe9890758f8f2b43b68e840e8f1a1a
|
||||
F test/insert2.test 5a20e1ace5fa0800b58d28284212290189b49aed
|
||||
F test/insert2.test 792ad079f59c7e14cf9397712725224e2112c838
|
||||
F test/insert3.test c67f0240b1c17e71fa2ed8bb6de064928f549f95
|
||||
F test/interrupt.test cd24dc5bedd02325be4bfa5d6209fae01c465157
|
||||
F test/interrupt.test 170f87c2819f0e56c76e0a754949ea103d05009c
|
||||
F test/intpkey.test af4fd826c4784ec5c93b444de07adea0254d0d30
|
||||
F test/ioerr.test aca09f9b303e2e69a42b61298e6e659d92e5c532
|
||||
F test/ioerr.test c3f71a60be73404bc5ae344e171b505d9af49320
|
||||
F test/join.test db3802739fb695bdfa2e88805e3d64ec5ffbebd1
|
||||
F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324
|
||||
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
|
||||
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
|
||||
F test/join5.test 2646825693a6e066ea89b498176d4a68df45ab68
|
||||
F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19
|
||||
F test/lastinsert.test 9d7241f562d7adcf61730de83176417d7e30d76b
|
||||
F test/lastinsert.test eaa89c6ee1f13062d87139fd32c1e56753d2fd89
|
||||
F test/laststmtchanges.test 19a6d0c11f7a31dc45465b495f7b845a62cbec17
|
||||
F test/like.test 145382e6a1f3d2edf266ca7d0236ab1b7c0ba66f
|
||||
F test/limit.test 4b538057d5b5c7ca10ec8d40d6c567e886c90bdd
|
||||
F test/limit.test 39f084f4e5f11e0b984cb517b56867cbf88df156
|
||||
F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107
|
||||
F test/lock2.test d83ba79d3c4fffdb5b926c7d8ca7a36c34288a55
|
||||
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
|
||||
F test/main.test b12f01d49a5c805a33fa6c0ef168691f63056e79
|
||||
F test/malloc.test 6245418d1b6635a2095d9ed0f5e84e029990da06
|
||||
F test/malloc2.test e6e321db96d6c94cb18bf82ad7215070c41e624e
|
||||
F test/malloc3.test 265644c655497242f7c0a1bb5b36c8500a5fc27c
|
||||
F test/malloc4.test 2e29d155eb4b4808019ef47eeedfcbe9e09e0f05
|
||||
F test/malloc5.test 1bac8c0dd98c387460920c1190f0996c5c62ea66
|
||||
F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
|
||||
F test/main.test 249f139ef2f75710db1b49bb79e8b27767eacae1
|
||||
F test/malloc.test 666c77a878ce50f5c22b9211ed43e889cabb63a6
|
||||
F test/malloc2.test 655b972372d2754a3f6c6ed54d7cfd18fde9bd32
|
||||
F test/memdb.test 1860e060be810bf0775bc57408a5b7c4954bcaea
|
||||
F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
|
||||
F test/minmax.test cad887abca5504396718e2cd5729ca40758743e8
|
||||
F test/misc1.test 7aabf32e698ef7cc1253f5e7fc216c65870ce485
|
||||
F test/misc2.test 17949ae34df8a60e318b2a14492b8cb62cd2072a
|
||||
F test/misc1.test c991617666991e11513e46cb646fd2e45ae68599
|
||||
F test/misc2.test 5c699af2fede2694736a9f45aea7e2f052686e15
|
||||
F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
|
||||
F test/misc4.test b043a05dea037cca5989f3ae09552fa16119bc80
|
||||
F test/misc5.test 129e19d3844bcc928051a30de34268e28a4bea6f
|
||||
F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
|
||||
F test/misc4.test fbb81c1d520f34deea819a5d94d787d3d38dc35b
|
||||
F test/misc5.test 24bd03404039ec727028ac9cf7fd9066fd209ec9
|
||||
F test/misuse.test 1c7fee3c4c0cb4008717ecccf5c72281fac0008e
|
||||
F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
|
||||
F test/null.test db52272f9628ae9e77ab451cf0fb3871a98c5f00
|
||||
F test/null.test 012fe5455f4fc3102490b4bad373a674e5741fdd
|
||||
F test/pager.test 1579e8f07291ae8e24db62ffade5c101c3e76597
|
||||
F test/pager2.test 49c0f57c7da0b060f0486b85fdd074025caa694e
|
||||
F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
|
||||
F test/pagesize.test cbc6a312b6f6c0f02619b189985df2a14164b690
|
||||
F test/pragma.test 8759b46702f6d8ee4f5dd520216c69dbc9080b60
|
||||
F test/pragma.test 95ea907adf68459e1be6f310c9ae94d1d59c465b
|
||||
F test/printf.test 9e10c74e16bf889f8495ddb3d6f5f891e75ff1b7
|
||||
F test/progress.test 16496001da445e6534afb94562c286708316d82f x
|
||||
F test/quick.test 2d2cf1b50e894b19b4029dd9a68ec59599b24f18
|
||||
F test/quote.test 5891f2338980916cf7415484b4ce785294044adb
|
||||
F test/quick.test a94d12658a2b590c1a5be580bef09bbb04c1266b
|
||||
F test/quote.test c1ca5e18800455f1c882baf5b0274755a3836549
|
||||
F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b
|
||||
F test/rollback.test fc6be5a5e4b1347fd96777c65484a24fc75e8f0e
|
||||
F test/rollback.test 94cd981ee3a627d9f6466f69dcf1f7dbfe695d7a
|
||||
F test/rowid.test 040a3bef06f970c45f5fcd14b2355f7f4d62f0cf
|
||||
F test/safety.test 4a06934e45d03b8b50ebcd8d174eb0367d2fd851
|
||||
F test/schema.test 8a2ae440fb15f5798a68059e8746402f3137be46
|
||||
F test/select1.test f4ab4b66e7089f0c64b6df954e75bafe05aabc0d
|
||||
F test/safety.test 907b64fee719554a3622853812af3886fddbbb4f
|
||||
F test/schema.test 21cbe7dac652f6d7eb058f3dec369bdbf46bbde6
|
||||
F test/select1.test 480233d4f5a81d7d59a55e40d05084d97e57ecdf
|
||||
F test/select2.test f3c2678c3a9f3cf08ec4988a3845bda64be6d9e3
|
||||
F test/select3.test 8fece41cd8f2955131b3f973a7123bec60b6e65e
|
||||
F test/select3.test 576df1a5cc5e01dadae9176384e2d506315afdcf
|
||||
F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca
|
||||
F test/select5.test 07a90ab3c7e3f0a241a9cdea1d997b2c8a89ff0b
|
||||
F test/select6.test f459a19bdac0501c4d3eb1a4df4b7a76f1bb8ad4
|
||||
F test/select6.test 21b72c56e7cbcefd063fdf9bc6c89342aedabccf
|
||||
F test/select7.test 1bf795b948c133a15a2a5e99d3270e652ec58ce6
|
||||
F test/server1.test e328b8e641ba8fe9273132cfef497383185dc1f5
|
||||
F test/shared.test 3c4be6c54a7b0938b9e513a1c78ca246e9fd954d
|
||||
F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
|
||||
F test/sort.test 0c33a8ae1c238377ad197387c3872175f40d3843
|
||||
F test/subquery.test e6de53332c0301b3cfa34edc3f3cd5fa1e859efd
|
||||
F test/subselect.test 2d13fb7f450db3595adcdd24079a0dd1d2d6abc2
|
||||
F test/sync.test 6e8b885cec5ccba2090e92c90f747a7142f53c88
|
||||
F test/table.test 6dc0dfa44dd429520e0e5a0c5e55025f730e9403
|
||||
F test/sync.test d769caaec48456119316775e35e0fdee2fa852d7
|
||||
F test/table.test ec0e6c2186bb8f6824f470caa118524dfd8fe057
|
||||
F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1
|
||||
F test/tclsqlite.test 2c4b5fb2f21e6740479463c263f3020f08e472d7
|
||||
F test/tclsqlite.test 2da3e4b3a79b13c1511c9d0cd995e08f8362e782
|
||||
F test/temptable.test 7927261befdbc7b0a7ffebb85ecc70a74fa7b15b
|
||||
F test/tester.tcl ed59b4eaa180728e4be1c55dc2823d66e03ae79a
|
||||
F test/tester.tcl 1e75553d320f5d2720613d8483c934488fc2c56f
|
||||
F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
|
||||
F test/thread2.test c88da55fb60d5975be91f1e2942a5e267c33f8ed
|
||||
F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
|
||||
F test/threadtest2.c 97a830d53c24c42290501fdfba4a6e5bdd34748b
|
||||
F test/tkt1435.test f768e5415d102fa1d8de3f548469d8fd1b79abd8
|
||||
F test/tkt1443.test bbd1fa7070783845aa42cdd35867a5ac73e5947a
|
||||
F test/tkt1444.test 5ef55d36dba1a39a96c728a519e66378a6f6816f
|
||||
F test/tkt1449.test 541021eb3c652848deb44f1407d692a9c42b6099
|
||||
F test/tkt1473.test 0c7f4e94946d5e420c0f4ce393d05703b729a848
|
||||
F test/tkt1501.test 0cf859299f0052ecfaf7db6f0984f122c7db5d15
|
||||
F test/tkt1512.test 8efd8d07e27e99d7462f75b5711de65eb7708baf
|
||||
F test/tkt1514.test baa587a69fa2e8d575ebdaf1460f711281dcba49
|
||||
F test/tkt1536.test 83ff7a7b6e248016f8d682d4f7a4ae114070d466
|
||||
F test/tkt1537.test e3a14332de9770be8ff14bd15c19a49cbec10808
|
||||
F test/tkt1567.test 18023cc3626a365f0118e17b66decedec93b1a6f
|
||||
F test/trace.test 75ffc1b992c780d054748a656e3e7fd674f18567
|
||||
F test/trans.test abd2f74c5685b156d79438e6e812db5bf984eea4
|
||||
F test/tkt1443.test 1e83b6a1e7f6e261682e67106ab3bc05f6c70e90
|
||||
F test/tkt1444.test 0f0fc1f277691f904dea2abece6db919dcae2351
|
||||
F test/tkt1449.test f8de8a84ec12ee805ed80055e1209560f8bee4d8
|
||||
F test/trace.test 9fd28695c463b90c2d32c387a432e01eb26e8ccf
|
||||
F test/trans.test 10506dc30305cfb8c4098359f7f6f64786f69c5e
|
||||
F test/trigger1.test 152aed5a1fa90709fe171f2ca501a6b7f7901479
|
||||
F test/trigger2.test dea71f4b05e22896e72527278bc8ef71b7475bf2
|
||||
F test/trigger3.test 9102fd3933db294dc654b5aee9edfe9e94f2b9e2
|
||||
F test/trigger4.test 4bed3705c9df4aaf7a7b164a2d573410d05ca025
|
||||
F test/trigger4.test 9615207f3746b1f3965113007869e45a895d2497
|
||||
F test/trigger5.test 619391a3e9fc194081d22cefd830d811e7badf83
|
||||
F test/trigger6.test 0e411654f122552da6590f0b4e6f781048a4a9b9
|
||||
F test/trigger7.test 0afa870be2ce1b132cdb85b17a4a4ef45aa8cece
|
||||
F test/types.test a74083427a73ff8af2723bae209d09cce5722c3a
|
||||
F test/types.test f0a98d10c5ecc9865d19dc94486f9873afc6bb6b
|
||||
F test/types2.test 81dd1897be8ef4b5b73d0006e6076abe40610de3
|
||||
F test/types3.test e5f789503849294de74a23b433168e8211523a25
|
||||
F test/types3.test 5c63c9cdbafe8fcb73a70a0beb0ecb65b7fa061d
|
||||
F test/unique.test 0253c4227a5dc533e312202ce21ecfad18058d18
|
||||
F test/update.test 7669ca789d62c258b678e8aa7a22a57eac10f2cf
|
||||
F test/utf16.test f9c13f4e2b48c42d0bfc96647d82fdf7bc11fc55
|
||||
F test/vacuum.test 37f998b841cb335397c26d9bbc3457182af2565f
|
||||
F test/utf16.test 5fb019e09601774743858ef7380b6c02103ff120
|
||||
F test/vacuum.test 5d4857ae2afc9c20d0edb8acc58bdc8d630126a9
|
||||
F test/vacuum2.test 5d77e98c458bcdbeecc6327de5107179ba1aa095
|
||||
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
|
||||
F test/view.test 354bd0ceb363e88da8ce98fb47e18550d7594b13
|
||||
F test/where.test ee7c9a6659b07e1ee61177f6e7ff71565ee2c9df
|
||||
F test/where2.test d85bd79cdd9e3226f25f7c4d1de3f211083a25e3
|
||||
F test/view.test ce0f0ad39fa4a3572acffcf1e634850ee151aae0
|
||||
F test/where.test ce21f4910ef6a0c08f8172857baecefca20a3b0c
|
||||
F test/where2.test 503e2e2b6abe14c5c10222e72d08ef84c1bf1ffb
|
||||
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
|
||||
F tool/lemon.c 26d271a753ef87fe1e6194f53c594ab5e6783d85
|
||||
F tool/lempar.c 424df14a48736bb961ed47acf30c26d66ed85a62
|
||||
F tool/lemon.c c88936c67f6411608db8fa4254d254f509fa40f6
|
||||
F tool/lempar.c f0c30abcae762a7d1eb37cd88b2232ab8dd625fb
|
||||
F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133
|
||||
F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
|
||||
F tool/memleak3.tcl 7707006ee908cffff210c98158788d85bb3fcdbf
|
||||
F tool/mkkeywordhash.c fa58d31c047fa3411761b01907d6df05781970d6
|
||||
F tool/memleak3.tcl 009da0ea82dc5893edca76cf1a21fb7260e9412e
|
||||
F tool/mkkeywordhash.c 5263a654e5c9fd8d6e3238fb39c2d5c3126be32f
|
||||
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
|
||||
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
|
||||
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
|
||||
F tool/showdb.c a086a3d788c7a23cb008317c3180ceb19f20bce0
|
||||
F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
|
||||
F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
|
||||
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
|
||||
F tool/spaceanal.tcl 5b47b70b9a0d216ec63a5b5547b3642dd308e53a
|
||||
@@ -298,9 +267,9 @@ F www/audit.tcl 90e09d580f79c7efec0c7d6f447b7ec5c2dce5c0
|
||||
F www/autoinc.tcl b357f5ba954b046ee35392ce0f884a2fcfcdea06
|
||||
F www/c_interface.tcl b51b08591554c16a0c3ef718364a508ac25abc7e
|
||||
F www/capi3.tcl 7a7cc225fe02eb7ab861a6019b08baa0014409e1
|
||||
F www/capi3ref.tcl a029fa712ebcc7b408160ee4fb0c1b182cceea06
|
||||
F www/changes.tcl fe45a019735518af9add1144bafd8ca3e30ad11b
|
||||
F www/common.tcl 14d121c28532ad20c3e349caa4db708b0b822083
|
||||
F www/capi3ref.tcl 885f2aa112e2e9b8822753bf2972d5afd0cfeba9
|
||||
F www/changes.tcl 5f09e69c5498cf388b3158978664db090708ed83
|
||||
F www/common.tcl de758130d54d95d151ea0d17a2ae5b92e1bb01de
|
||||
F www/compile.tcl 276546d7eb445add5a867193bbd80f6919a6b084
|
||||
F www/conflict.tcl cdd0f4b59b0ba6d61f67e6a38f3ae45853bacb30
|
||||
F www/copyright-release.html 294e011760c439c44951a6bfecd4c81a1ae359e8
|
||||
@@ -313,35 +282,34 @@ F www/direct1b.gif 32b48b764244817b6b591898dc52a04299a7b8a7
|
||||
F www/docs.tcl 4e2d716f004cc4c4dae773206ed58f50d4468a87
|
||||
F www/download.tcl d56a1c30b1c3c18f62926a806179976eb133ce94
|
||||
F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
|
||||
F www/faq.tcl ac2a8b0cc13d8697ebf90d1bce63c089c0149633
|
||||
F www/faq.tcl eb7fb7b7242ccfec65820f01b94d0d83956236c1
|
||||
F www/fileformat.tcl 900c95b9633abc3dcfc384d9ddd8eb4876793059
|
||||
F www/formatchng.tcl f4f5f32205c0a70d07784f7bf9ce33ed34bfcbf3
|
||||
F www/formatchng.tcl 053ddb73646701353a5b1c9ca6274d5900739b45
|
||||
F www/fullscanb.gif f7c94cb227f060511f8909e10f570157263e9a25
|
||||
F www/index-ex1-x-b.gif f9b1d85c3fa2435cf38b15970c7e3aa1edae23a3
|
||||
F www/index.tcl 5b3506a29f853f801fb36fdf2f64c20b4281d4fc
|
||||
F www/index.tcl 2fff45565fd52fba6746b27eb60ea1d7834042ec
|
||||
F www/indirect1b1.gif adfca361d2df59e34f9c5cac52a670c2bfc303a1
|
||||
F www/lang.tcl b3561af8d85d2d712d43b3604e4aadce9257e4d9
|
||||
F www/lang.tcl b04a87ce05cdbd8d356d6b760a9a0b6f6fce927e
|
||||
F www/lockingv3.tcl f59b19d6c8920a931f096699d6faaf61c05db55f
|
||||
F www/mingw.tcl d96b451568c5d28545fefe0c80bee3431c73f69c
|
||||
F www/nulls.tcl ec35193f92485b87b90a994a01d0171b58823fcf
|
||||
F www/oldnews.tcl 1a808d86882621557774bf7741ed81c7f4ef9f19
|
||||
F www/omitted.tcl ee6b46f83d513b2187869740da829a700e1a355e
|
||||
F www/omitted.tcl 658ebdc83781ac419dc8a08b3f6cf93929023470
|
||||
F www/opcode.tcl 5bd68059416b223515a680d410a9f7cb6736485f
|
||||
F www/optimizer.tcl d6812a10269bd0d7c488987aac0ad5036cace9dc
|
||||
F www/optimizing.tcl f0b2538988d1bbad16cbfe63ec6e8f48c9eb04e5
|
||||
F www/optoverview.tcl 815df406a38c9f69b27d37e8f7ede004c6d9f19e
|
||||
F www/optoverview.tcl 28b6f114a33bfd91bbe3440611ceed6090587211
|
||||
F www/pragma.tcl 44f7b665ca598ad24724f35991653638a36a6e3f
|
||||
F www/quickstart.tcl 2f3daf8038e82a102e1e8cc877aafa7a413f5f11
|
||||
F www/sharedcache.tcl ce211997860d9dd8fa9a6aa86cdfaf1235ccfcb6
|
||||
F www/quickstart.tcl 6f6f694b6139be2d967b1492eb9a6bdf7058aa60
|
||||
F www/speed.tcl 656ed5be8cc9d536353e1a96927b925634a62933
|
||||
F www/sqlite.tcl a883ed7b47371d31d471e6aea5ed1f972ae8e1be
|
||||
F www/support.tcl 7961ce16290692578d783bb11f0dc8391a9be9c3
|
||||
F www/sqlite.tcl b51fd15f0531a54874de785a9efba323eecd5975
|
||||
F www/support.tcl 3955da0fd82be68cc5c83d347c05095e80967051
|
||||
F www/table-ex1b2.gif a588d21a2d88bb2a2ef0431fcc5ed5aa48c0bbc5
|
||||
F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
|
||||
F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
|
||||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
|
||||
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
|
||||
P 6591d365d4ba1263c3bc48f5ab47633fae2b2a3a
|
||||
R 7d7be83f73b610d0efb0d6e55a70818a
|
||||
P d8e74af5b081a074173c470e9f2115be9b095777
|
||||
R 3ef1bc3892118ec529a39c9be34b97bf
|
||||
U drh
|
||||
Z 95511deea1a74daa9ad5dc683e2d355c
|
||||
Z ad60d4c3881558341fdd282b95f7c97a
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
bd7c5699939fda2bb792a0e2448df064a1171769
|
||||
e61382aed45a83ad688a0461948f9cd052a527fa
|
||||
@@ -31,7 +31,7 @@ i386-mingw32msvc-dllwrap \
|
||||
--as i386-mingw32msvc-as \
|
||||
--target i386-mingw32 \
|
||||
-dllname tclsqlite3.dll -lmsvcrt *.o $TCLSTUBLIB
|
||||
#i386-mingw32msvc-strip tclsqlite3.dll
|
||||
i386-mingw32msvc-strip tclsqlite3.dll
|
||||
rm tclsqlite.o
|
||||
i386-mingw32msvc-dllwrap \
|
||||
--def sqlite3.def -v --export-all \
|
||||
|
||||
@@ -23,20 +23,6 @@
|
||||
# code generator run (infinitesimally) faster and more importantly it makes
|
||||
# the total library smaller.
|
||||
#
|
||||
# This script also scans for lines of the form:
|
||||
#
|
||||
# case OP_aaaa: /* no-push */
|
||||
#
|
||||
# When the no-push comment is found on an opcode, it means that that
|
||||
# opcode does not leave a result on the stack. But identifying which
|
||||
# opcodes leave results on the stack it is possible to determine a
|
||||
# much smaller upper bound on the size of the stack. This allows
|
||||
# a smaller stack to be allocated, which is important to embedded
|
||||
# systems with limited memory space. This script generates a series
|
||||
# of "NOPUSH_MASK" defines that contain bitmaps of opcodes that leave
|
||||
# results on the stack. The NOPUSH_MASK defines are used in vdbeaux.c
|
||||
# to help determine the maximum stack size.
|
||||
#
|
||||
|
||||
|
||||
# Remember the TK_ values from the parse.h file
|
||||
|
||||
@@ -40,7 +40,6 @@ sqlite3_create_function
|
||||
sqlite3_create_function16
|
||||
sqlite3_data_count
|
||||
sqlite3_db_handle
|
||||
sqlite3_enable_shared_cache
|
||||
sqlite3_errcode
|
||||
sqlite3_errmsg
|
||||
sqlite3_errmsg16
|
||||
@@ -76,16 +75,13 @@ sqlite3_result_text16
|
||||
sqlite3_result_text16be
|
||||
sqlite3_result_text16le
|
||||
sqlite3_result_value
|
||||
sqlite3_rollback_hook
|
||||
sqlite3_set_authorizer
|
||||
sqlite3_set_auxdata
|
||||
sqlite3_snprintf
|
||||
sqlite3_step
|
||||
sqlite3_thread_cleanup
|
||||
sqlite3_total_changes
|
||||
sqlite3_trace
|
||||
sqlite3_transfer_bindings
|
||||
sqlite3_update_hook
|
||||
sqlite3_user_data
|
||||
sqlite3_value_blob
|
||||
sqlite3_value_bytes
|
||||
|
||||
+31
-28
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that used to generate VDBE code
|
||||
** that implements the ALTER TABLE command.
|
||||
**
|
||||
** $Id: alter.c,v 1.16 2006/01/11 21:41:21 drh Exp $
|
||||
** $Id: alter.c,v 1.8 2005/08/19 19:14:13 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -47,7 +47,7 @@ static void renameTableFunc(
|
||||
|
||||
int token;
|
||||
Token tname;
|
||||
unsigned char const *zCsr = zSql;
|
||||
char const *zCsr = zSql;
|
||||
int len = 0;
|
||||
char *zRet;
|
||||
|
||||
@@ -96,7 +96,7 @@ static void renameTriggerFunc(
|
||||
int token;
|
||||
Token tname;
|
||||
int dist = 3;
|
||||
unsigned char const *zCsr = zSql;
|
||||
char const *zCsr = zSql;
|
||||
int len = 0;
|
||||
char *zRet;
|
||||
|
||||
@@ -177,16 +177,9 @@ static char *whereTempTriggers(Parse *pParse, Table *pTab){
|
||||
Trigger *pTrig;
|
||||
char *zWhere = 0;
|
||||
char *tmp = 0;
|
||||
const Schema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */
|
||||
|
||||
/* If the table is not located in the temp-db (in which case NULL is
|
||||
** returned, loop through the tables list of triggers. For each trigger
|
||||
** that is not part of the temp-db schema, add a clause to the WHERE
|
||||
** expression being built up in zWhere.
|
||||
*/
|
||||
if( pTab->pSchema!=pTempSchema ){
|
||||
if( pTab->iDb!=1 ){
|
||||
for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
|
||||
if( pTrig->pSchema==pTempSchema ){
|
||||
if( pTrig->iDb==1 ){
|
||||
if( !zWhere ){
|
||||
zWhere = sqlite3MPrintf("name=%Q", pTrig->name);
|
||||
}else{
|
||||
@@ -211,22 +204,20 @@ static char *whereTempTriggers(Parse *pParse, Table *pTab){
|
||||
static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
|
||||
Vdbe *v;
|
||||
char *zWhere;
|
||||
int iDb; /* Index of database containing pTab */
|
||||
int iDb;
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
Trigger *pTrig;
|
||||
#endif
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
assert( iDb>=0 );
|
||||
iDb = pTab->iDb;
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/* Drop any table triggers from the internal schema. */
|
||||
for(pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext){
|
||||
int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
|
||||
assert( iTrigDb==iDb || iTrigDb==1 );
|
||||
sqlite3VdbeOp3(v, OP_DropTrigger, iTrigDb, 0, pTrig->name, 0);
|
||||
assert( pTrig->iDb==iDb || pTrig->iDb==1 );
|
||||
sqlite3VdbeOp3(v, OP_DropTrigger, pTrig->iDb, 0, pTrig->name, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -242,7 +233,7 @@ static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
|
||||
/* Now, if the table is not stored in the temp database, reload any temp
|
||||
** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined.
|
||||
*/
|
||||
if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){
|
||||
if( (zWhere=whereTempTriggers(pParse, pTab)) ){
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, 1, 0, zWhere, P3_DYNAMIC);
|
||||
}
|
||||
#endif
|
||||
@@ -267,12 +258,12 @@ void sqlite3AlterRenameTable(
|
||||
char *zWhere = 0; /* Where clause to locate temp triggers */
|
||||
#endif
|
||||
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ) goto exit_rename_table;
|
||||
if( sqlite3_malloc_failed ) goto exit_rename_table;
|
||||
assert( pSrc->nSrc==1 );
|
||||
|
||||
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
|
||||
if( !pTab ) goto exit_rename_table;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
iDb = pTab->iDb;
|
||||
zDb = db->aDb[iDb].zName;
|
||||
|
||||
/* Get a NULL terminated version of the new table name. */
|
||||
@@ -358,7 +349,7 @@ void sqlite3AlterRenameTable(
|
||||
** table. Don't do this if the table being ALTERed is itself located in
|
||||
** the temp database.
|
||||
*/
|
||||
if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){
|
||||
if( (zWhere=whereTempTriggers(pParse, pTab)) ){
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE sqlite_temp_master SET "
|
||||
"sql = sqlite_rename_trigger(sql, %Q), "
|
||||
@@ -394,12 +385,13 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
char *zCol; /* Null-terminated column definition */
|
||||
Column *pCol; /* The new column */
|
||||
Expr *pDflt; /* Default value for the new column */
|
||||
Vdbe *v;
|
||||
|
||||
if( pParse->nErr ) return;
|
||||
pNew = pParse->pNewTable;
|
||||
assert( pNew );
|
||||
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pNew->pSchema);
|
||||
iDb = pNew->iDb;
|
||||
zDb = pParse->db->aDb[iDb].zName;
|
||||
zTab = pNew->zName;
|
||||
pCol = &pNew->aCol[pNew->nCol-1];
|
||||
@@ -450,7 +442,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
}
|
||||
|
||||
/* Modify the CREATE TABLE statement. */
|
||||
zCol = sqliteStrNDup((char*)pColDef->z, pColDef->n);
|
||||
zCol = sqliteStrNDup(pColDef->z, pColDef->n);
|
||||
if( zCol ){
|
||||
char *zEnd = &zCol[pColDef->n-1];
|
||||
while( (zEnd>zCol && *zEnd==';') || isspace(*(unsigned char *)zEnd) ){
|
||||
@@ -470,12 +462,22 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
** format to 2. If the default value of the new column is not NULL,
|
||||
** the file format becomes 3.
|
||||
*/
|
||||
sqlite3MinimumFileFormat(pParse, iDb, pDflt ? 3 : 2);
|
||||
if( (v=sqlite3GetVdbe(pParse)) ){
|
||||
int f = (pDflt?3:2);
|
||||
|
||||
/* Only set the file format to $f if it is currently less than $f. */
|
||||
sqlite3VdbeAddOp(v, OP_ReadCookie, iDb, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, f, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ge, 0, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, f, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 1);
|
||||
}
|
||||
|
||||
/* Reload the schema of the modified table. */
|
||||
reloadTableSchema(pParse, pTab, pTab->zName);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This function is called by the parser after the table-name in
|
||||
** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
|
||||
@@ -499,9 +501,10 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
int i;
|
||||
int nAlloc;
|
||||
|
||||
|
||||
/* Look up the table being altered. */
|
||||
assert( pParse->pNewTable==0 );
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ) goto exit_begin_add_column;
|
||||
if( sqlite3_malloc_failed ) goto exit_begin_add_column;
|
||||
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
|
||||
if( !pTab ) goto exit_begin_add_column;
|
||||
|
||||
@@ -512,7 +515,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
}
|
||||
|
||||
assert( pTab->addColOffset>0 );
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
iDb = pTab->iDb;
|
||||
|
||||
/* Put a copy of the Table struct in Parse.pNewTable for the
|
||||
** sqlite3AddColumn() function and friends to modify.
|
||||
@@ -537,7 +540,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
pCol->zType = 0;
|
||||
pCol->pDflt = 0;
|
||||
}
|
||||
pNew->pSchema = pParse->db->aDb[iDb].pSchema;
|
||||
pNew->iDb = iDb;
|
||||
pNew->addColOffset = pTab->addColOffset;
|
||||
pNew->nRef = 1;
|
||||
|
||||
|
||||
+11
-28
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code associated with the ANALYZE command.
|
||||
**
|
||||
** @(#) $Id: analyze.c,v 1.16 2006/01/10 17:58:23 danielk1977 Exp $
|
||||
** @(#) $Id: analyze.c,v 1.9 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_ANALYZE
|
||||
#include "sqliteInt.h"
|
||||
@@ -61,14 +61,8 @@ static void openStatTable(
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pStat->tnum, iDb);
|
||||
}
|
||||
|
||||
/* Open the sqlite_stat1 table for writing. Unless it was created
|
||||
** by this vdbe program, lock it for writing at the shared-cache level.
|
||||
** If this vdbe did create the sqlite_stat1 table, then it must have
|
||||
** already obtained a schema-lock, making the write-lock redundant.
|
||||
/* Open the sqlite_stat1 table for writing.
|
||||
*/
|
||||
if( iRootPage>0 ){
|
||||
sqlite3TableLock(pParse, iDb, iRootPage, 1, "sqlite_stat1");
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenWrite, iStatCur, iRootPage);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iStatCur, 3);
|
||||
@@ -92,7 +86,6 @@ static void analyzeOneTable(
|
||||
int topOfLoop; /* The top of the loop */
|
||||
int endOfLoop; /* The end of the loop */
|
||||
int addr; /* The address of an instruction */
|
||||
int iDb; /* Index of database containing pTab */
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( pTab==0 || pTab->pIndex==0 ){
|
||||
@@ -100,29 +93,21 @@ static void analyzeOneTable(
|
||||
return;
|
||||
}
|
||||
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
assert( iDb>=0 );
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
|
||||
pParse->db->aDb[iDb].zName ) ){
|
||||
pParse->db->aDb[pTab->iDb].zName ) ){
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Establish a read-lock on the table at the shared-cache level. */
|
||||
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
|
||||
|
||||
iIdxCur = pParse->nTab;
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
|
||||
|
||||
/* Open a cursor to the index to be analyzed
|
||||
*/
|
||||
assert( iDb==sqlite3SchemaToIndex(pParse->db, pIdx->pSchema) );
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
VdbeComment((v, "# %s", pIdx->zName));
|
||||
sqlite3VdbeOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum,
|
||||
(char *)pKey, P3_KEYINFO_HANDOFF);
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
nCol = pIdx->nColumn;
|
||||
if( iMem+nCol*2>=pParse->nMem ){
|
||||
pParse->nMem = iMem+nCol*2+1;
|
||||
@@ -154,7 +139,7 @@ static void analyzeOneTable(
|
||||
endOfLoop = sqlite3VdbeMakeLabel(v);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, endOfLoop);
|
||||
topOfLoop = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, iMem);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, iMem, 0);
|
||||
for(i=0; i<nCol; i++){
|
||||
sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+nCol+i+1, 0);
|
||||
@@ -162,7 +147,7 @@ static void analyzeOneTable(
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, endOfLoop);
|
||||
for(i=0; i<nCol; i++){
|
||||
addr = sqlite3VdbeAddOp(v, OP_MemIncr, 1, iMem+i+1);
|
||||
addr = sqlite3VdbeAddOp(v, OP_MemIncr, iMem+i+1, 0);
|
||||
sqlite3VdbeChangeP2(v, topOfLoop + 3*i + 3, addr);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iMem+nCol+i+1, 1);
|
||||
@@ -203,14 +188,13 @@ static void analyzeOneTable(
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, -1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Divide, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ToInt, 0, 0);
|
||||
if( i==nCol-1 ){
|
||||
sqlite3VdbeAddOp(v, OP_Concat, nCol*2-1, 0);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "aaa", 0);
|
||||
sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "ttt", 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, iStatCur, 0);
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
@@ -230,7 +214,6 @@ static void loadAnalysis(Parse *pParse, int iDb){
|
||||
*/
|
||||
static void analyzeDatabase(Parse *pParse, int iDb){
|
||||
sqlite3 *db = pParse->db;
|
||||
Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
|
||||
HashElem *k;
|
||||
int iStatCur;
|
||||
int iMem;
|
||||
@@ -239,7 +222,7 @@ static void analyzeDatabase(Parse *pParse, int iDb){
|
||||
iStatCur = pParse->nTab++;
|
||||
openStatTable(pParse, iDb, iStatCur, 0);
|
||||
iMem = pParse->nMem;
|
||||
for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
|
||||
for(k=sqliteHashFirst(&db->aDb[iDb].tblHash); k; k=sqliteHashNext(k)){
|
||||
Table *pTab = (Table*)sqliteHashData(k);
|
||||
analyzeOneTable(pParse, pTab, iStatCur, iMem);
|
||||
}
|
||||
@@ -255,7 +238,7 @@ static void analyzeTable(Parse *pParse, Table *pTab){
|
||||
int iStatCur;
|
||||
|
||||
assert( pTab!=0 );
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
iDb = pTab->iDb;
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
iStatCur = pParse->nTab++;
|
||||
openStatTable(pParse, iDb, iStatCur, pTab->zName);
|
||||
@@ -377,7 +360,7 @@ void sqlite3AnalysisLoad(sqlite3 *db, int iDb){
|
||||
char *zSql;
|
||||
|
||||
/* Clear any prior statistics */
|
||||
for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
|
||||
for(i=sqliteHashFirst(&db->aDb[iDb].idxHash); i; i=sqliteHashNext(i)){
|
||||
Index *pIdx = sqliteHashData(i);
|
||||
sqlite3DefaultRowEst(pIdx);
|
||||
}
|
||||
|
||||
+120
-261
@@ -11,169 +11,132 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.46 2006/01/11 21:41:22 drh Exp $
|
||||
** $Id: attach.c,v 1.34 2005/08/20 03:03:04 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Resolve an expression that was part of an ATTACH or DETACH statement. This
|
||||
** is slightly different from resolving a normal SQL expression, because simple
|
||||
** identifiers are treated as strings, not possible column names or aliases.
|
||||
** This routine is called by the parser to process an ATTACH statement:
|
||||
**
|
||||
** i.e. if the parser sees:
|
||||
** ATTACH DATABASE filename AS dbname
|
||||
**
|
||||
** ATTACH DATABASE abc AS def
|
||||
**
|
||||
** it treats the two expressions as literal strings 'abc' and 'def' instead of
|
||||
** looking for columns of the same name.
|
||||
**
|
||||
** This only applies to the root node of pExpr, so the statement:
|
||||
**
|
||||
** ATTACH DATABASE abc||def AS 'db2'
|
||||
**
|
||||
** will fail because neither abc or def can be resolved.
|
||||
** The pFilename and pDbname arguments are the tokens that define the
|
||||
** filename and dbname in the ATTACH statement.
|
||||
*/
|
||||
int resolveAttachExpr(NameContext *pName, Expr *pExpr)
|
||||
{
|
||||
int rc = SQLITE_OK;
|
||||
if( pExpr ){
|
||||
if( pExpr->op!=TK_ID ){
|
||||
rc = sqlite3ExprResolveNames(pName, pExpr);
|
||||
}else{
|
||||
pExpr->op = TK_STRING;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** An SQL user-function registered to do the work of an ATTACH statement. The
|
||||
** three arguments to the function come directly from an attach statement:
|
||||
**
|
||||
** ATTACH DATABASE x AS y KEY z
|
||||
**
|
||||
** SELECT sqlite_attach(x, y, z)
|
||||
**
|
||||
** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the
|
||||
** third argument.
|
||||
*/
|
||||
static void attachFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
void sqlite3Attach(
|
||||
Parse *pParse, /* The parser context */
|
||||
Token *pFilename, /* Name of database file */
|
||||
Token *pDbname, /* Name of the database to use internally */
|
||||
int keyType, /* 0: no key. 1: TEXT, 2: BLOB */
|
||||
Token *pKey /* Text of the key for keytype 1 and 2 */
|
||||
){
|
||||
int i;
|
||||
int rc = 0;
|
||||
sqlite3 *db = sqlite3_user_data(context);
|
||||
const char *zName;
|
||||
const char *zFile;
|
||||
Db *aNew;
|
||||
char zErr[128];
|
||||
char *zErrDyn = 0;
|
||||
int rc, i;
|
||||
char *zFile = 0;
|
||||
char *zName = 0;
|
||||
sqlite3 *db;
|
||||
Vdbe *v;
|
||||
|
||||
zFile = (const char *)sqlite3_value_text(argv[0]);
|
||||
zName = (const char *)sqlite3_value_text(argv[1]);
|
||||
|
||||
/* Check for the following errors:
|
||||
**
|
||||
** * Too many attached databases,
|
||||
** * Transaction currently open
|
||||
** * Specified database name already being used.
|
||||
*/
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
|
||||
if( pParse->explain ) return;
|
||||
db = pParse->db;
|
||||
if( db->nDb>=MAX_ATTACHED+2 ){
|
||||
sqlite3_snprintf(
|
||||
127, zErr, "too many attached databases - max %d", MAX_ATTACHED
|
||||
);
|
||||
goto attach_error;
|
||||
sqlite3ErrorMsg(pParse, "too many attached databases - max %d",
|
||||
MAX_ATTACHED);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
if( !db->autoCommit ){
|
||||
strcpy(zErr, "cannot ATTACH database within transaction");
|
||||
goto attach_error;
|
||||
sqlite3ErrorMsg(pParse, "cannot ATTACH database within transaction");
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
zFile = sqlite3NameFromToken(pFilename);
|
||||
if( zFile==0 ){
|
||||
goto attach_end;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
|
||||
goto attach_end;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
zName = sqlite3NameFromToken(pDbname);
|
||||
if( zName==0 ){
|
||||
goto attach_end;
|
||||
}
|
||||
for(i=0; i<db->nDb; i++){
|
||||
char *z = db->aDb[i].zName;
|
||||
if( z && sqlite3StrICmp(z, zName)==0 ){
|
||||
sqlite3_snprintf(127, zErr, "database %s is already in use", zName);
|
||||
goto attach_error;
|
||||
sqlite3ErrorMsg(pParse, "database %s is already in use", zName);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
goto attach_end;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate the new entry in the db->aDb[] array and initialise the schema
|
||||
** hash tables.
|
||||
*/
|
||||
if( db->aDb==db->aDbStatic ){
|
||||
aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );
|
||||
if( aNew==0 ){
|
||||
return;
|
||||
goto attach_end;
|
||||
}
|
||||
memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
|
||||
}else{
|
||||
aNew = sqliteRealloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
|
||||
if( aNew==0 ){
|
||||
return;
|
||||
goto attach_end;
|
||||
}
|
||||
}
|
||||
db->aDb = aNew;
|
||||
aNew = &db->aDb[db->nDb++];
|
||||
memset(aNew, 0, sizeof(*aNew));
|
||||
|
||||
/* Open the database file. If the btree is successfully opened, use
|
||||
** it to obtain the database schema. At this point the schema may
|
||||
** or may not be initialised.
|
||||
*/
|
||||
rc = sqlite3BtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
|
||||
if( rc==SQLITE_OK ){
|
||||
aNew->pSchema = sqlite3SchemaGet(aNew->pBt);
|
||||
if( !aNew->pSchema ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
|
||||
strcpy(zErr,
|
||||
"attached databases must use the same text encoding as main database");
|
||||
goto attach_error;
|
||||
}
|
||||
}
|
||||
aNew->zName = sqliteStrDup(zName);
|
||||
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);
|
||||
aNew->zName = zName;
|
||||
zName = 0;
|
||||
aNew->safety_level = 3;
|
||||
|
||||
rc = sqlite3BtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
|
||||
if( rc ){
|
||||
sqlite3ErrorMsg(pParse, "unable to open database: %s", zFile);
|
||||
}
|
||||
#if SQLITE_HAS_CODEC
|
||||
{
|
||||
extern int sqlite3CodecAttach(sqlite3*, int, void*, int);
|
||||
extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
|
||||
int nKey;
|
||||
char *zKey;
|
||||
int t = sqlite3_value_type(argv[2]);
|
||||
switch( t ){
|
||||
case SQLITE_INTEGER:
|
||||
case SQLITE_FLOAT:
|
||||
zErrDyn = sqliteStrDup("Invalid key value");
|
||||
rc = SQLITE_ERROR;
|
||||
break;
|
||||
|
||||
case SQLITE_TEXT:
|
||||
case SQLITE_BLOB:
|
||||
nKey = sqlite3_value_bytes(argv[2]);
|
||||
zKey = (char *)sqlite3_value_blob(argv[2]);
|
||||
sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
break;
|
||||
|
||||
case SQLITE_NULL:
|
||||
/* No key specified. Use the key from the main database */
|
||||
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
|
||||
sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
break;
|
||||
int nKey;
|
||||
if( keyType==0 ){
|
||||
/* No key specified. Use the key from the main database */
|
||||
extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
|
||||
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
|
||||
}else if( keyType==1 ){
|
||||
/* Key specified as text */
|
||||
zKey = sqlite3NameFromToken(pKey);
|
||||
nKey = strlen(zKey);
|
||||
}else{
|
||||
/* Key specified as a BLOB */
|
||||
char *zTemp;
|
||||
assert( keyType==2 );
|
||||
pKey->z++;
|
||||
pKey->n--;
|
||||
zTemp = sqlite3NameFromToken(pKey);
|
||||
zKey = sqlite3HexToBlob(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
}
|
||||
sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
if( keyType ){
|
||||
sqliteFree(zKey);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If the file was opened successfully, read the schema for the new database.
|
||||
** If this fails, or if opening the file failed, then close the file and
|
||||
** remove the entry from the db->aDb[] array. i.e. put everything back the way
|
||||
** we found it.
|
||||
*/
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3SafetyOn(db);
|
||||
rc = sqlite3Init(db, &zErrDyn);
|
||||
sqlite3SafetyOff(db);
|
||||
db->flags &= ~SQLITE_Initialized;
|
||||
if( pParse->nErr==0 && rc==SQLITE_OK ){
|
||||
rc = sqlite3ReadSchema(pParse);
|
||||
}
|
||||
if( rc ){
|
||||
int i = db->nDb - 1;
|
||||
@@ -181,172 +144,68 @@ static void attachFunc(
|
||||
if( db->aDb[i].pBt ){
|
||||
sqlite3BtreeClose(db->aDb[i].pBt);
|
||||
db->aDb[i].pBt = 0;
|
||||
db->aDb[i].pSchema = 0;
|
||||
}
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
db->nDb = i;
|
||||
sqlite3_snprintf(127, zErr, "unable to open database: %s", zFile);
|
||||
goto attach_error;
|
||||
assert( pParse->nErr>0 ); /* Always set by sqlite3ReadSchema() */
|
||||
if( pParse->rc==SQLITE_OK ){
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
attach_error:
|
||||
/* Return an error if we get here */
|
||||
if( zErrDyn ){
|
||||
sqlite3_result_error(context, zErrDyn, -1);
|
||||
sqliteFree(zErrDyn);
|
||||
}else{
|
||||
zErr[sizeof(zErr)-1] = 0;
|
||||
sqlite3_result_error(context, zErr, -1);
|
||||
}
|
||||
attach_end:
|
||||
sqliteFree(zFile);
|
||||
sqliteFree(zName);
|
||||
}
|
||||
|
||||
/*
|
||||
** An SQL user-function registered to do the work of an DETACH statement. The
|
||||
** three arguments to the function come directly from a detach statement:
|
||||
** This routine is called by the parser to process a DETACH statement:
|
||||
**
|
||||
** DETACH DATABASE x
|
||||
** DETACH DATABASE dbname
|
||||
**
|
||||
** SELECT sqlite_detach(x)
|
||||
** The pDbname argument is the name of the database in the DETACH statement.
|
||||
*/
|
||||
static void detachFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *zName = (const char *)sqlite3_value_text(argv[0]);
|
||||
sqlite3 *db = sqlite3_user_data(context);
|
||||
void sqlite3Detach(Parse *pParse, Token *pDbname){
|
||||
int i;
|
||||
sqlite3 *db;
|
||||
Vdbe *v;
|
||||
Db *pDb = 0;
|
||||
char zErr[128];
|
||||
char *zName;
|
||||
|
||||
assert(zName);
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
|
||||
if( pParse->explain ) return;
|
||||
db = pParse->db;
|
||||
zName = sqlite3NameFromToken(pDbname);
|
||||
if( zName==0 ) return;
|
||||
for(i=0; i<db->nDb; i++){
|
||||
pDb = &db->aDb[i];
|
||||
if( pDb->pBt==0 ) continue;
|
||||
if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
|
||||
}
|
||||
|
||||
if( i>=db->nDb ){
|
||||
sqlite3_snprintf(sizeof(zErr), zErr, "no such database: %s", zName);
|
||||
goto detach_error;
|
||||
sqlite3ErrorMsg(pParse, "no such database: %z", zName);
|
||||
return;
|
||||
}
|
||||
if( i<2 ){
|
||||
sqlite3_snprintf(sizeof(zErr), zErr, "cannot detach database %s", zName);
|
||||
goto detach_error;
|
||||
sqlite3ErrorMsg(pParse, "cannot detach database %z", zName);
|
||||
return;
|
||||
}
|
||||
sqliteFree(zName);
|
||||
if( !db->autoCommit ){
|
||||
strcpy(zErr, "cannot DETACH database within transaction");
|
||||
goto detach_error;
|
||||
sqlite3ErrorMsg(pParse, "cannot DETACH database within transaction");
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
sqlite3BtreeClose(pDb->pBt);
|
||||
pDb->pBt = 0;
|
||||
pDb->pSchema = 0;
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
return;
|
||||
|
||||
detach_error:
|
||||
sqlite3_result_error(context, zErr, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
** This procedure generates VDBE code for a single invocation of either the
|
||||
** sqlite_detach() or sqlite_attach() SQL user functions.
|
||||
*/
|
||||
static void codeAttach(
|
||||
Parse *pParse, /* The parser context */
|
||||
int type, /* Either SQLITE_ATTACH or SQLITE_DETACH */
|
||||
const char *zFunc, /* Either "sqlite_attach" or "sqlite_detach */
|
||||
int nFunc, /* Number of args to pass to zFunc */
|
||||
Expr *pAuthArg, /* Expression to pass to authorization callback */
|
||||
Expr *pFilename, /* Name of database file */
|
||||
Expr *pDbname, /* Name of the database to use internally */
|
||||
Expr *pKey /* Database key for encryption extension */
|
||||
){
|
||||
int rc;
|
||||
NameContext sName;
|
||||
Vdbe *v;
|
||||
FuncDef *pFunc;
|
||||
sqlite3* db = pParse->db;
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
assert( sqlite3ThreadDataReadOnly()->mallocFailed || pAuthArg );
|
||||
if( pAuthArg ){
|
||||
char *zAuthArg = sqlite3NameFromToken(&pAuthArg->span);
|
||||
if( !zAuthArg ){
|
||||
goto attach_end;
|
||||
}
|
||||
rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
|
||||
sqliteFree(zAuthArg);
|
||||
if(rc!=SQLITE_OK ){
|
||||
goto attach_end;
|
||||
}
|
||||
if( sqlite3AuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){
|
||||
return;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
memset(&sName, 0, sizeof(NameContext));
|
||||
sName.pParse = pParse;
|
||||
|
||||
if(
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
|
||||
){
|
||||
pParse->nErr++;
|
||||
goto attach_end;
|
||||
}
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
sqlite3ExprCode(pParse, pFilename);
|
||||
sqlite3ExprCode(pParse, pDbname);
|
||||
sqlite3ExprCode(pParse, pKey);
|
||||
|
||||
assert(v || sqlite3ThreadDataReadOnly()->mallocFailed);
|
||||
if( v ){
|
||||
sqlite3VdbeAddOp(v, OP_Function, 0, nFunc);
|
||||
pFunc = sqlite3FindFunction(db, zFunc, strlen(zFunc), nFunc, SQLITE_UTF8,0);
|
||||
sqlite3VdbeChangeP3(v, -1, (char *)pFunc, P3_FUNCDEF);
|
||||
|
||||
/* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
|
||||
** statement only). For DETACH, set it to false (expire all existing
|
||||
** statements).
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Expire, (type==SQLITE_ATTACH), 0);
|
||||
}
|
||||
|
||||
attach_end:
|
||||
sqlite3ExprDelete(pFilename);
|
||||
sqlite3ExprDelete(pDbname);
|
||||
sqlite3ExprDelete(pKey);
|
||||
}
|
||||
|
||||
/*
|
||||
** Called by the parser to compile a DETACH statement.
|
||||
**
|
||||
** DETACH pDbname
|
||||
*/
|
||||
void sqlite3Detach(Parse *pParse, Expr *pDbname){
|
||||
codeAttach(pParse, SQLITE_DETACH, "sqlite_detach", 1, pDbname, 0, 0, pDbname);
|
||||
}
|
||||
|
||||
/*
|
||||
** Called by the parser to compile an ATTACH statement.
|
||||
**
|
||||
** ATTACH p AS pDbname KEY pKey
|
||||
*/
|
||||
void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
|
||||
codeAttach(pParse, SQLITE_ATTACH, "sqlite_attach", 3, p, p, pDbname, pKey);
|
||||
}
|
||||
|
||||
/*
|
||||
** Register the functions sqlite_attach and sqlite_detach.
|
||||
*/
|
||||
void sqlite3AttachFunctions(sqlite3 *db){
|
||||
static const int enc = SQLITE_UTF8;
|
||||
sqlite3_create_function(db, "sqlite_attach", 3, enc, db, attachFunc, 0, 0);
|
||||
sqlite3_create_function(db, "sqlite_detach", 1, enc, db, detachFunc, 0, 0);
|
||||
sqlite3BtreeClose(pDb->pBt);
|
||||
pDb->pBt = 0;
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+4
-11
@@ -14,7 +14,7 @@
|
||||
** systems that do not need this facility may omit it by recompiling
|
||||
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
|
||||
**
|
||||
** $Id: auth.c,v 1.24 2006/01/13 13:55:45 drh Exp $
|
||||
** $Id: auth.c,v 1.22 2005/07/29 15:36:15 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -112,17 +112,10 @@ void sqlite3AuthRead(
|
||||
int iSrc; /* Index in pTabList->a[] of table being read */
|
||||
const char *zDBase; /* Name of database being accessed */
|
||||
TriggerStack *pStack; /* The stack of current triggers */
|
||||
int iDb; /* The index of the database the expression refers to */
|
||||
|
||||
if( db->xAuth==0 ) return;
|
||||
if( pExpr->op==TK_AS ) return;
|
||||
assert( pExpr->op==TK_COLUMN );
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pExpr->pSchema);
|
||||
if( iDb<0 ){
|
||||
/* An attempt to read a column out of a subquery or other
|
||||
** temporary table. */
|
||||
return;
|
||||
}
|
||||
for(iSrc=0; pTabList && iSrc<pTabList->nSrc; iSrc++){
|
||||
if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break;
|
||||
}
|
||||
@@ -147,14 +140,14 @@ void sqlite3AuthRead(
|
||||
}else{
|
||||
zCol = "ROWID";
|
||||
}
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
zDBase = db->aDb[iDb].zName;
|
||||
assert( pExpr->iDb<db->nDb );
|
||||
zDBase = db->aDb[pExpr->iDb].zName;
|
||||
rc = db->xAuth(db->pAuthArg, SQLITE_READ, pTab->zName, zCol, zDBase,
|
||||
pParse->zAuthContext);
|
||||
if( rc==SQLITE_IGNORE ){
|
||||
pExpr->op = TK_NULL;
|
||||
}else if( rc==SQLITE_DENY ){
|
||||
if( db->nDb>2 || iDb!=0 ){
|
||||
if( db->nDb>2 || pExpr->iDb!=0 ){
|
||||
sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",
|
||||
zDBase, pTab->zName, zCol);
|
||||
}else{
|
||||
|
||||
+231
-953
File diff suppressed because it is too large
Load Diff
+2
-6
@@ -13,7 +13,7 @@
|
||||
** subsystem. See comments in the source code for a detailed description
|
||||
** of what each interface routine does.
|
||||
**
|
||||
** @(#) $Id: btree.h,v 1.69 2006/01/07 13:21:04 danielk1977 Exp $
|
||||
** @(#) $Id: btree.h,v 1.64 2005/08/27 16:36:49 drh Exp $
|
||||
*/
|
||||
#ifndef _BTREE_H_
|
||||
#define _BTREE_H_
|
||||
@@ -36,12 +36,10 @@
|
||||
*/
|
||||
typedef struct Btree Btree;
|
||||
typedef struct BtCursor BtCursor;
|
||||
typedef struct BtShared BtShared;
|
||||
|
||||
|
||||
int sqlite3BtreeOpen(
|
||||
const char *zFilename, /* Name of database file to open */
|
||||
sqlite3 *db, /* Associated database connection */
|
||||
Btree **, /* Return open Btree* here */
|
||||
int flags /* Flags */
|
||||
);
|
||||
@@ -76,9 +74,7 @@ int sqlite3BtreeCreateTable(Btree*, int*, int flags);
|
||||
int sqlite3BtreeIsInTrans(Btree*);
|
||||
int sqlite3BtreeIsInStmt(Btree*);
|
||||
int sqlite3BtreeSync(Btree*, const char *zMaster);
|
||||
void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
|
||||
int sqlite3BtreeSchemaLocked(Btree *);
|
||||
int sqlite3BtreeLockTable(Btree *, int, u8);
|
||||
int sqlite3BtreeReset(Btree *);
|
||||
|
||||
const char *sqlite3BtreeGetFilename(Btree *);
|
||||
const char *sqlite3BtreeGetDirname(Btree *);
|
||||
|
||||
+218
-499
File diff suppressed because it is too large
Load Diff
+11
-20
@@ -13,7 +13,7 @@
|
||||
** This file contains functions used to access the internal hash tables
|
||||
** of user defined functions and collation sequences.
|
||||
**
|
||||
** $Id: callback.c,v 1.11 2006/01/11 21:41:22 drh Exp $
|
||||
** $Id: callback.c,v 1.3 2005/08/14 01:20:38 drh Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
@@ -29,19 +29,17 @@ static void callCollNeeded(sqlite3 *db, const char *zName, int nName){
|
||||
if( db->xCollNeeded ){
|
||||
char *zExternal = sqliteStrNDup(zName, nName);
|
||||
if( !zExternal ) return;
|
||||
db->xCollNeeded(db->pCollNeededArg, db, (int)ENC(db), zExternal);
|
||||
db->xCollNeeded(db->pCollNeededArg, db, (int)db->enc, zExternal);
|
||||
sqliteFree(zExternal);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
if( db->xCollNeeded16 ){
|
||||
char const *zExternal;
|
||||
sqlite3_value *pTmp = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pTmp, nName, zName, SQLITE_UTF8, SQLITE_STATIC);
|
||||
sqlite3_value *pTmp = sqlite3GetTransientValue(db);
|
||||
sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF8, SQLITE_STATIC);
|
||||
zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
|
||||
if( zExternal ){
|
||||
db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
|
||||
}
|
||||
sqlite3ValueFree(pTmp);
|
||||
if( !zExternal ) return;
|
||||
db->xCollNeeded16(db->pCollNeededArg, db, (int)db->enc, zExternal);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -92,14 +90,14 @@ CollSeq *sqlite3GetCollSeq(
|
||||
|
||||
p = pColl;
|
||||
if( !p ){
|
||||
p = sqlite3FindCollSeq(db, ENC(db), zName, nName, 0);
|
||||
p = sqlite3FindCollSeq(db, db->enc, zName, nName, 0);
|
||||
}
|
||||
if( !p || !p->xCmp ){
|
||||
/* No collation sequence of this type for this encoding is registered.
|
||||
** Call the collation factory to see if it can supply us with one.
|
||||
*/
|
||||
callCollNeeded(db, zName, nName);
|
||||
p = sqlite3FindCollSeq(db, ENC(db), zName, nName, 0);
|
||||
p = sqlite3FindCollSeq(db, db->enc, zName, nName, 0);
|
||||
}
|
||||
if( p && !p->xCmp && synthCollSeq(db, p) ){
|
||||
p = 0;
|
||||
@@ -130,7 +128,6 @@ int sqlite3CheckCollSeq(Parse *pParse, CollSeq *pColl){
|
||||
pParse->nErr++;
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
assert( p==pColl );
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -178,8 +175,7 @@ static CollSeq *findCollSeqEntry(
|
||||
** return the pColl pointer to be deleted (because it wasn't added
|
||||
** to the hash table).
|
||||
*/
|
||||
assert( !pDel ||
|
||||
(sqlite3ThreadDataReadOnly()->mallocFailed && pDel==pColl) );
|
||||
assert( !pDel || (sqlite3_malloc_failed && pDel==pColl) );
|
||||
sqliteFree(pDel);
|
||||
}
|
||||
}
|
||||
@@ -201,12 +197,7 @@ CollSeq *sqlite3FindCollSeq(
|
||||
int nName,
|
||||
int create
|
||||
){
|
||||
CollSeq *pColl;
|
||||
if( zName ){
|
||||
pColl = findCollSeqEntry(db, zName, nName, create);
|
||||
}else{
|
||||
pColl = db->pDfltColl;
|
||||
}
|
||||
CollSeq *pColl = findCollSeqEntry(db, zName, nName, create);
|
||||
assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
|
||||
assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
|
||||
if( pColl ) pColl += enc-1;
|
||||
@@ -295,7 +286,7 @@ FuncDef *sqlite3FindFunction(
|
||||
** new entry to the hash table and return it.
|
||||
*/
|
||||
if( createFlag && bestmatch<6 &&
|
||||
(pBest = sqliteMalloc(sizeof(*pBest)+nName))!=0 ){
|
||||
(pBest = sqliteMalloc(sizeof(*pBest)+nName)) ){
|
||||
pBest->nArg = nArg;
|
||||
pBest->pNext = pFirst;
|
||||
pBest->iPrefEnc = enc;
|
||||
|
||||
+1
-4
@@ -16,7 +16,7 @@
|
||||
** separating it out, the code will be automatically omitted from
|
||||
** static links that do not use it.
|
||||
**
|
||||
** $Id: complete.c,v 1.2 2005/12/12 06:53:04 danielk1977 Exp $
|
||||
** $Id: complete.c,v 1.1 2005/08/14 17:53:21 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#ifndef SQLITE_OMIT_COMPLETE
|
||||
@@ -255,9 +255,6 @@ int sqlite3_complete16(const void *zSql){
|
||||
zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
if( zSql8 ){
|
||||
rc = sqlite3_complete(zSql8);
|
||||
}else if( zSql ){
|
||||
rc = SQLITE_NOMEM;
|
||||
sqlite3MallocClearFailed();
|
||||
}
|
||||
sqlite3ValueFree(pVal);
|
||||
return rc;
|
||||
|
||||
+7
-9
@@ -16,7 +16,7 @@
|
||||
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: date.c,v 1.51 2006/01/15 00:13:16 drh Exp $
|
||||
** $Id: date.c,v 1.45 2005/06/25 18:42:14 drh Exp $
|
||||
**
|
||||
** NOTES:
|
||||
**
|
||||
@@ -105,20 +105,18 @@ static int getDigits(const char *zDate, ...){
|
||||
val = 0;
|
||||
while( N-- ){
|
||||
if( !isdigit(*(u8*)zDate) ){
|
||||
goto end_getDigits;
|
||||
return cnt;
|
||||
}
|
||||
val = val*10 + *zDate - '0';
|
||||
zDate++;
|
||||
}
|
||||
if( val<min || val>max || (nextC!=0 && nextC!=*zDate) ){
|
||||
goto end_getDigits;
|
||||
return cnt;
|
||||
}
|
||||
*pVal = val;
|
||||
zDate++;
|
||||
cnt++;
|
||||
}while( nextC );
|
||||
va_end(ap);
|
||||
end_getDigits:
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -238,7 +236,7 @@ static void computeJD(DateTime *p){
|
||||
if( p->validHMS ){
|
||||
p->rJD += (p->h*3600.0 + p->m*60.0 + p->s)/86400.0;
|
||||
if( p->validTZ ){
|
||||
p->rJD -= p->tz*60/86400.0;
|
||||
p->rJD += p->tz*60/86400.0;
|
||||
p->validHMS = 0;
|
||||
p->validTZ = 0;
|
||||
}
|
||||
@@ -641,10 +639,10 @@ static int isDate(int argc, sqlite3_value **argv, DateTime *p){
|
||||
int i;
|
||||
if( argc==0 ) return 1;
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[0]) ||
|
||||
parseDateOrTime((char*)sqlite3_value_text(argv[0]), p) ) return 1;
|
||||
parseDateOrTime(sqlite3_value_text(argv[0]), p) ) return 1;
|
||||
for(i=1; i<argc; i++){
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[i]) ||
|
||||
parseModifier((char*)sqlite3_value_text(argv[i]), p) ) return 1;
|
||||
parseModifier(sqlite3_value_text(argv[i]), p) ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -757,7 +755,7 @@ static void strftimeFunc(
|
||||
DateTime x;
|
||||
int n, i, j;
|
||||
char *z;
|
||||
const char *zFmt = (const char*)sqlite3_value_text(argv[0]);
|
||||
const char *zFmt = sqlite3_value_text(argv[0]);
|
||||
char zBuf[100];
|
||||
if( zFmt==0 || isDate(argc-1, argv+1, &x) ) return;
|
||||
for(i=0, n=1; zFmt[i]; i++, n++){
|
||||
|
||||
+21
-28
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** in order to generate code for DELETE FROM statements.
|
||||
**
|
||||
** $Id: delete.c,v 1.118 2006/01/11 21:41:22 drh Exp $
|
||||
** $Id: delete.c,v 1.111 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -59,19 +59,14 @@ int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
/*
|
||||
** Generate code that will open a table for reading.
|
||||
*/
|
||||
void sqlite3OpenTable(
|
||||
Parse *p, /* Generate code into this VDBE */
|
||||
void sqlite3OpenTableForReading(
|
||||
Vdbe *v, /* Generate code into this VDBE */
|
||||
int iCur, /* The cursor number of the table */
|
||||
int iDb, /* The database index in sqlite3.aDb[] */
|
||||
Table *pTab, /* The table to be opened */
|
||||
int opcode /* OP_OpenRead or OP_OpenWrite */
|
||||
Table *pTab /* The table to be opened */
|
||||
){
|
||||
Vdbe *v = sqlite3GetVdbe(p);
|
||||
assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
|
||||
sqlite3TableLock(p, iDb, pTab->tnum, (opcode==OP_OpenWrite), pTab->zName);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
VdbeComment((v, "# %s", pTab->zName));
|
||||
sqlite3VdbeAddOp(v, opcode, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
}
|
||||
|
||||
@@ -100,7 +95,6 @@ void sqlite3DeleteFrom(
|
||||
AuthContext sContext; /* Authorization context */
|
||||
int oldIdx = -1; /* Cursor for the OLD table of AFTER triggers */
|
||||
NameContext sNC; /* Name context to resolve expressions in */
|
||||
int iDb;
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* True if attempting to delete from a view */
|
||||
@@ -108,7 +102,7 @@ void sqlite3DeleteFrom(
|
||||
#endif
|
||||
|
||||
sContext.pParse = 0;
|
||||
if( pParse->nErr || sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( pParse->nErr || sqlite3_malloc_failed ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
db = pParse->db;
|
||||
@@ -140,9 +134,8 @@ void sqlite3DeleteFrom(
|
||||
if( sqlite3IsReadOnly(pParse, pTab, triggers_exist) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
assert( iDb<db->nDb );
|
||||
zDb = db->aDb[iDb].zName;
|
||||
assert( pTab->iDb<db->nDb );
|
||||
zDb = db->aDb[pTab->iDb].zName;
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
@@ -183,7 +176,7 @@ void sqlite3DeleteFrom(
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, triggers_exist, iDb);
|
||||
sqlite3BeginWriteOperation(pParse, triggers_exist, pTab->iDb);
|
||||
|
||||
/* If we are trying to delete from a view, realize that view into
|
||||
** a ephemeral table.
|
||||
@@ -212,7 +205,7 @@ void sqlite3DeleteFrom(
|
||||
int endOfLoop = sqlite3VdbeMakeLabel(v);
|
||||
int addr;
|
||||
if( !isView ){
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, sqlite3VdbeCurrentAddr(v)+2);
|
||||
addr = sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
@@ -221,13 +214,9 @@ void sqlite3DeleteFrom(
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pTab->tnum, iDb);
|
||||
if( !pParse->nested ){
|
||||
sqlite3VdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pTab->tnum, pTab->iDb);
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
assert( pIdx->pSchema==pTab->pSchema );
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pIdx->tnum, iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pIdx->tnum, pIdx->iDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,6 +225,13 @@ 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, 0);
|
||||
@@ -273,7 +269,7 @@ void sqlite3DeleteFrom(
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
@@ -384,9 +380,6 @@ void sqlite3GenerateRowDelete(
|
||||
addr = sqlite3VdbeAddOp(v, OP_NotExists, iCur, 0);
|
||||
sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
|
||||
if( count ){
|
||||
sqlite3VdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
|
||||
}
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
|
||||
|
||||
+77
-133
@@ -12,7 +12,7 @@
|
||||
** This file contains routines used for analyzing expressions and
|
||||
** for generating VDBE code that evaluates expressions in SQLite.
|
||||
**
|
||||
** $Id: expr.c,v 1.249 2006/01/13 06:33:24 danielk1977 Exp $
|
||||
** $Id: expr.c,v 1.230 2005/09/23 21:11:54 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -75,10 +75,12 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){
|
||||
char sqlite3CompareAffinity(Expr *pExpr, char aff2){
|
||||
char aff1 = sqlite3ExprAffinity(pExpr);
|
||||
if( aff1 && aff2 ){
|
||||
/* Both sides of the comparison are columns. If one has numeric
|
||||
** affinity, use that. Otherwise use no affinity.
|
||||
/* Both sides of the comparison are columns. If one has numeric or
|
||||
** integer affinity, use that. Otherwise use no affinity.
|
||||
*/
|
||||
if( sqlite3IsNumericAffinity(aff1) || sqlite3IsNumericAffinity(aff2) ){
|
||||
if( aff1==SQLITE_AFF_INTEGER || aff2==SQLITE_AFF_INTEGER ){
|
||||
return SQLITE_AFF_INTEGER;
|
||||
}else if( aff1==SQLITE_AFF_NUMERIC || aff2==SQLITE_AFF_NUMERIC ){
|
||||
return SQLITE_AFF_NUMERIC;
|
||||
}else{
|
||||
return SQLITE_AFF_NONE;
|
||||
@@ -87,6 +89,7 @@ char sqlite3CompareAffinity(Expr *pExpr, char aff2){
|
||||
/* Neither side of the comparison is a column. Compare the
|
||||
** results directly.
|
||||
*/
|
||||
/* return SQLITE_AFF_NUMERIC; // Ticket #805 */
|
||||
return SQLITE_AFF_NONE;
|
||||
}else{
|
||||
/* One side is a column, the other is not. Use the columns affinity. */
|
||||
@@ -126,14 +129,11 @@ static char comparisonAffinity(Expr *pExpr){
|
||||
*/
|
||||
int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity){
|
||||
char aff = comparisonAffinity(pExpr);
|
||||
switch( aff ){
|
||||
case SQLITE_AFF_NONE:
|
||||
return 1;
|
||||
case SQLITE_AFF_TEXT:
|
||||
return idx_affinity==SQLITE_AFF_TEXT;
|
||||
default:
|
||||
return sqlite3IsNumericAffinity(idx_affinity);
|
||||
}
|
||||
return
|
||||
(aff==SQLITE_AFF_NONE) ||
|
||||
(aff==SQLITE_AFF_NUMERIC && idx_affinity==SQLITE_AFF_INTEGER) ||
|
||||
(aff==SQLITE_AFF_INTEGER && idx_affinity==SQLITE_AFF_NUMERIC) ||
|
||||
(aff==idx_affinity);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -235,7 +235,7 @@ Expr *sqlite3RegisterExpr(Parse *pParse, Token *pToken){
|
||||
if( p==0 ){
|
||||
return 0; /* Malloc failed */
|
||||
}
|
||||
depth = atoi((char*)&pToken->z[1]);
|
||||
depth = atoi(&pToken->z[1]);
|
||||
p->iTable = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_Dup, depth, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, p->iTable, 1);
|
||||
@@ -263,7 +263,7 @@ Expr *sqlite3ExprAnd(Expr *pLeft, Expr *pRight){
|
||||
void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
|
||||
assert( pRight!=0 );
|
||||
assert( pLeft!=0 );
|
||||
if( !sqlite3ThreadDataReadOnly()->mallocFailed && pRight->z && pLeft->z ){
|
||||
if( !sqlite3_malloc_failed && pRight->z && pLeft->z ){
|
||||
assert( pLeft->dyn==0 || pLeft->z[pLeft->n]==0 );
|
||||
if( pLeft->dyn==0 && pRight->dyn==0 ){
|
||||
pExpr->span.z = pLeft->z;
|
||||
@@ -327,7 +327,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
|
||||
/* Wildcard of the form "?nnn". Convert "nnn" to an integer and
|
||||
** use it as the variable number */
|
||||
int i;
|
||||
pExpr->iTable = i = atoi((char*)&pToken->z[1]);
|
||||
pExpr->iTable = i = atoi(&pToken->z[1]);
|
||||
if( i<1 || i>SQLITE_MAX_VARIABLE_NUMBER ){
|
||||
sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
|
||||
SQLITE_MAX_VARIABLE_NUMBER);
|
||||
@@ -355,10 +355,10 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
|
||||
pExpr->iTable = ++pParse->nVar;
|
||||
if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){
|
||||
pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10;
|
||||
sqliteReallocOrFree((void**)&pParse->apVarExpr,
|
||||
sqlite3ReallocOrFree((void**)&pParse->apVarExpr,
|
||||
pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) );
|
||||
}
|
||||
if( !sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( !sqlite3_malloc_failed ){
|
||||
assert( pParse->apVarExpr!=0 );
|
||||
pParse->apVarExpr[pParse->nVarExpr++] = pExpr;
|
||||
}
|
||||
@@ -415,7 +415,7 @@ Expr *sqlite3ExprDup(Expr *p){
|
||||
if( pNew==0 ) return 0;
|
||||
memcpy(pNew, p, sizeof(*pNew));
|
||||
if( p->token.z!=0 ){
|
||||
pNew->token.z = (u8*)sqliteStrNDup((char*)p->token.z, p->token.n);
|
||||
pNew->token.z = sqliteStrNDup(p->token.z, p->token.n);
|
||||
pNew->token.dyn = 1;
|
||||
}else{
|
||||
assert( pNew->token.z==0 );
|
||||
@@ -432,7 +432,7 @@ void sqlite3TokenCopy(Token *pTo, Token *pFrom){
|
||||
if( pTo->dyn ) sqliteFree((char*)pTo->z);
|
||||
if( pFrom->z ){
|
||||
pTo->n = pFrom->n;
|
||||
pTo->z = (u8*)sqliteStrNDup((char*)pFrom->z, pFrom->n);
|
||||
pTo->z = sqliteStrNDup(pFrom->z, pFrom->n);
|
||||
pTo->dyn = 1;
|
||||
}else{
|
||||
pTo->z = 0;
|
||||
@@ -462,8 +462,7 @@ ExprList *sqlite3ExprListDup(ExprList *p){
|
||||
sqlite3TokenCopy(&pNewExpr->span, &pOldExpr->span);
|
||||
}
|
||||
assert( pNewExpr==0 || pNewExpr->span.z!=0
|
||||
|| pOldExpr->span.z==0
|
||||
|| sqlite3ThreadDataReadOnly()->mallocFailed );
|
||||
|| pOldExpr->span.z==0 || sqlite3_malloc_failed );
|
||||
pItem->zName = sqliteStrDup(pOldItem->zName);
|
||||
pItem->sortOrder = pOldItem->sortOrder;
|
||||
pItem->isAgg = pOldItem->isAgg;
|
||||
@@ -753,7 +752,7 @@ int sqlite3ExprIsConstantOrFunction(Expr *p){
|
||||
int sqlite3ExprIsInteger(Expr *p, int *pValue){
|
||||
switch( p->op ){
|
||||
case TK_INTEGER: {
|
||||
if( sqlite3GetInt32((char*)p->token.z, pValue) ){
|
||||
if( sqlite3GetInt32(p->token.z, pValue) ){
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
@@ -810,7 +809,7 @@ int sqlite3IsRowid(const char *z){
|
||||
** in pParse and return non-zero. Return zero on success.
|
||||
*/
|
||||
static int lookupName(
|
||||
Parse *pParse, /* The parsing context */
|
||||
Parse *pParse, /* The parsing context */
|
||||
Token *pDbToken, /* Name of the database containing table, or NULL */
|
||||
Token *pTableToken, /* Name of table containing column, or NULL */
|
||||
Token *pColumnToken, /* Name of the column. */
|
||||
@@ -832,19 +831,19 @@ static int lookupName(
|
||||
zDb = sqlite3NameFromToken(pDbToken);
|
||||
zTab = sqlite3NameFromToken(pTableToken);
|
||||
zCol = sqlite3NameFromToken(pColumnToken);
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
goto lookupname_end;
|
||||
}
|
||||
|
||||
pExpr->iTable = -1;
|
||||
while( pNC && cnt==0 ){
|
||||
ExprList *pEList;
|
||||
SrcList *pSrcList = pNC->pSrcList;
|
||||
ExprList *pEList = pNC->pEList;
|
||||
|
||||
/* assert( zTab==0 || pEList==0 ); */
|
||||
if( pSrcList ){
|
||||
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
|
||||
Table *pTab = pItem->pTab;
|
||||
int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
Column *pCol;
|
||||
|
||||
if( pTab==0 ) continue;
|
||||
@@ -856,28 +855,27 @@ static int lookupName(
|
||||
}else{
|
||||
char *zTabName = pTab->zName;
|
||||
if( zTabName==0 || sqlite3StrICmp(zTabName, zTab)!=0 ) continue;
|
||||
if( zDb!=0 && sqlite3StrICmp(db->aDb[iDb].zName, zDb)!=0 ){
|
||||
if( zDb!=0 && sqlite3StrICmp(db->aDb[pTab->iDb].zName, zDb)!=0 ){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( 0==(cntTab++) ){
|
||||
pExpr->iTable = pItem->iCursor;
|
||||
pExpr->pSchema = pTab->pSchema;
|
||||
pExpr->iDb = pTab->iDb;
|
||||
pMatch = pItem;
|
||||
}
|
||||
for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
|
||||
if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
|
||||
const char *zColl = pTab->aCol[j].zColl;
|
||||
IdList *pUsing;
|
||||
cnt++;
|
||||
pExpr->iTable = pItem->iCursor;
|
||||
pMatch = pItem;
|
||||
pExpr->pSchema = pTab->pSchema;
|
||||
pExpr->iDb = pTab->iDb;
|
||||
/* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
|
||||
pExpr->iColumn = j==pTab->iPKey ? -1 : j;
|
||||
pExpr->affinity = pTab->aCol[j].affinity;
|
||||
pExpr->pColl = sqlite3FindCollSeq(db, ENC(db), zColl,-1, 0);
|
||||
pExpr->pColl = pTab->aCol[j].pColl;
|
||||
if( pItem->jointype & JT_NATURAL ){
|
||||
/* If this match occurred in the left table of a natural join,
|
||||
** then skip the right table to avoid a duplicate match */
|
||||
@@ -924,15 +922,14 @@ static int lookupName(
|
||||
int j;
|
||||
Column *pCol = pTab->aCol;
|
||||
|
||||
pExpr->pSchema = pTab->pSchema;
|
||||
pExpr->iDb = pTab->iDb;
|
||||
cntTab++;
|
||||
for(j=0; j < pTab->nCol; j++, pCol++) {
|
||||
if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
|
||||
const char *zColl = pTab->aCol[j].zColl;
|
||||
cnt++;
|
||||
pExpr->iColumn = j==pTab->iPKey ? -1 : j;
|
||||
pExpr->affinity = pTab->aCol[j].affinity;
|
||||
pExpr->pColl = sqlite3FindCollSeq(db, ENC(db), zColl,-1, 0);
|
||||
pExpr->pColl = pTab->aCol[j].pColl;
|
||||
pExpr->pTab = pTab;
|
||||
break;
|
||||
}
|
||||
@@ -962,7 +959,7 @@ static int lookupName(
|
||||
** Note that the expression in the result set should have already been
|
||||
** resolved by the time the WHERE clause is resolved.
|
||||
*/
|
||||
if( cnt==0 && (pEList = pNC->pEList)!=0 && zTab==0 ){
|
||||
if( cnt==0 && pEList!=0 && zTab==0 ){
|
||||
for(j=0; j<pEList->nExpr; j++){
|
||||
char *zAs = pEList->a[j].zName;
|
||||
if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
|
||||
@@ -1009,9 +1006,9 @@ static int lookupName(
|
||||
char *zErr;
|
||||
zErr = cnt==0 ? "no such column: %s" : "ambiguous column name: %s";
|
||||
if( zDb ){
|
||||
sqlite3SetString(&z, zDb, ".", zTab, ".", zCol, (char*)0);
|
||||
sqlite3SetString(&z, zDb, ".", zTab, ".", zCol, 0);
|
||||
}else if( zTab ){
|
||||
sqlite3SetString(&z, zTab, ".", zCol, (char*)0);
|
||||
sqlite3SetString(&z, zTab, ".", zCol, 0);
|
||||
}else{
|
||||
z = sqliteStrDup(zCol);
|
||||
}
|
||||
@@ -1091,7 +1088,7 @@ static int nameResolverStep(void *pArg, Expr *pExpr){
|
||||
if( ExprHasAnyProperty(pExpr, EP_Resolved) ) return 1;
|
||||
ExprSetProperty(pExpr, EP_Resolved);
|
||||
#ifndef NDEBUG
|
||||
if( pSrcList && pSrcList->nAlloc>0 ){
|
||||
if( pSrcList ){
|
||||
int i;
|
||||
for(i=0; i<pSrcList->nSrc; i++){
|
||||
assert( pSrcList->a[i].iCursor>=0 && pSrcList->a[i].iCursor<pParse->nTab);
|
||||
@@ -1152,9 +1149,9 @@ static int nameResolverStep(void *pArg, Expr *pExpr){
|
||||
int nId; /* Number of characters in function name */
|
||||
const char *zId; /* The function name. */
|
||||
FuncDef *pDef; /* Information about the function */
|
||||
int enc = ENC(pParse->db); /* The database encoding */
|
||||
int enc = pParse->db->enc; /* The database encoding */
|
||||
|
||||
zId = (char*)pExpr->token.z;
|
||||
zId = pExpr->token.z;
|
||||
nId = pExpr->token.n;
|
||||
pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
|
||||
if( pDef==0 ){
|
||||
@@ -1200,27 +1197,13 @@ static int nameResolverStep(void *pArg, Expr *pExpr){
|
||||
case TK_IN: {
|
||||
if( pExpr->pSelect ){
|
||||
int nRef = pNC->nRef;
|
||||
#ifndef SQLITE_OMIT_CHECK
|
||||
if( pNC->isCheck ){
|
||||
sqlite3ErrorMsg(pParse,"subqueries prohibited in CHECK constraints");
|
||||
}
|
||||
#endif
|
||||
sqlite3SelectResolve(pParse, pExpr->pSelect, pNC);
|
||||
assert( pNC->nRef>=nRef );
|
||||
if( nRef!=pNC->nRef ){
|
||||
ExprSetProperty(pExpr, EP_VarSelect);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_CHECK
|
||||
case TK_VARIABLE: {
|
||||
if( pNC->isCheck ){
|
||||
sqlite3ErrorMsg(pParse,"parameters prohibited in CHECK constraints");
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1278,16 +1261,17 @@ struct QueryCoder {
|
||||
|
||||
|
||||
/*
|
||||
** Generate code for scalar subqueries used as an expression
|
||||
** and IN operators. Examples:
|
||||
** Generate code for subqueries and IN operators.
|
||||
**
|
||||
** (SELECT a FROM b) -- subquery
|
||||
** EXISTS (SELECT a FROM b) -- EXISTS subquery
|
||||
** x IN (4,5,11) -- IN operator with list on right-hand side
|
||||
** x IN (SELECT a FROM b) -- IN operator with subquery on the right
|
||||
** IN operators comes in two forms:
|
||||
**
|
||||
** The pExpr parameter describes the expression that contains the IN
|
||||
** operator or subquery.
|
||||
** expr IN (exprlist)
|
||||
** and
|
||||
** expr IN (SELECT ...)
|
||||
**
|
||||
** The first form is handled by creating a set holding the list
|
||||
** of allowed values. The second form causes the SELECT to generate
|
||||
** a temporary table.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_SUBQUERY
|
||||
void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
@@ -1309,7 +1293,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
int mem = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, mem, 0);
|
||||
testAddr = sqlite3VdbeAddOp(v, OP_If, 0, 0);
|
||||
assert( testAddr>0 || sqlite3ThreadDataReadOnly()->mallocFailed );
|
||||
assert( testAddr>0 || sqlite3_malloc_failed );
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 1, mem);
|
||||
}
|
||||
|
||||
@@ -1406,25 +1390,21 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
** value of this select in a memory cell and record the number
|
||||
** of the memory cell in iColumn.
|
||||
*/
|
||||
static const Token one = { (u8*)"1", 0, 1 };
|
||||
Select *pSel;
|
||||
int iMem;
|
||||
int sop;
|
||||
Select *pSel;
|
||||
|
||||
pExpr->iColumn = iMem = pParse->nMem++;
|
||||
pExpr->iColumn = pParse->nMem++;
|
||||
pSel = pExpr->pSelect;
|
||||
if( pExpr->op==TK_SELECT ){
|
||||
sop = SRT_Mem;
|
||||
sqlite3VdbeAddOp(v, OP_MemNull, iMem, 0);
|
||||
VdbeComment((v, "# Init subquery result"));
|
||||
}else{
|
||||
static const Token one = { "1", 0, 1 };
|
||||
sop = SRT_Exists;
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, iMem);
|
||||
VdbeComment((v, "# Init EXISTS result"));
|
||||
sqlite3ExprListDelete(pSel->pEList);
|
||||
pSel->pEList = sqlite3ExprListAppend(0,
|
||||
sqlite3Expr(TK_INTEGER, 0, 0, &one), 0);
|
||||
}
|
||||
sqlite3ExprDelete(pSel->pLimit);
|
||||
pSel->pLimit = sqlite3Expr(TK_INTEGER, 0, 0, &one);
|
||||
sqlite3Select(pParse, pSel, sop, iMem, 0, 0, 0, 0);
|
||||
sqlite3Select(pParse, pSel, sop, pExpr->iColumn, 0, 0, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1464,8 +1444,6 @@ static void codeInteger(Vdbe *v, const char *z, int n){
|
||||
void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
Vdbe *v = pParse->pVdbe;
|
||||
int op;
|
||||
int stackChng = 1; /* Amount of change to stack depth */
|
||||
|
||||
if( v==0 ) return;
|
||||
if( pExpr==0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
|
||||
@@ -1487,27 +1465,16 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
/* Otherwise, fall thru into the TK_COLUMN case */
|
||||
}
|
||||
case TK_COLUMN: {
|
||||
if( pExpr->iTable<0 ){
|
||||
/* This only happens when coding check constraints */
|
||||
assert( pParse->ckOffset>0 );
|
||||
sqlite3VdbeAddOp(v, OP_Dup, pParse->ckOffset-pExpr->iColumn-1, 1);
|
||||
}else if( pExpr->iColumn>=0 ){
|
||||
Table *pTab = pExpr->pTab;
|
||||
int iCol = pExpr->iColumn;
|
||||
sqlite3VdbeAddOp(v, OP_Column, pExpr->iTable, iCol);
|
||||
sqlite3ColumnDefault(v, pTab, iCol);
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
if( pTab && pTab->aCol[iCol].affinity==SQLITE_AFF_REAL ){
|
||||
sqlite3VdbeAddOp(v, OP_RealAffinity, 0, 0);
|
||||
}
|
||||
#endif
|
||||
if( pExpr->iColumn>=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, pExpr->iTable, pExpr->iColumn);
|
||||
sqlite3ColumnDefault(v, pExpr->pTab, pExpr->iColumn);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, pExpr->iTable, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TK_INTEGER: {
|
||||
codeInteger(v, (char*)pExpr->token.z, pExpr->token.n);
|
||||
codeInteger(v, pExpr->token.z, pExpr->token.n);
|
||||
break;
|
||||
}
|
||||
case TK_FLOAT:
|
||||
@@ -1515,7 +1482,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
assert( TK_FLOAT==OP_Real );
|
||||
assert( TK_STRING==OP_String8 );
|
||||
sqlite3DequoteExpr(pExpr);
|
||||
sqlite3VdbeOp3(v, op, 0, 0, (char*)pExpr->token.z, pExpr->token.n);
|
||||
sqlite3VdbeOp3(v, op, 0, 0, pExpr->token.z, pExpr->token.n);
|
||||
break;
|
||||
}
|
||||
case TK_NULL: {
|
||||
@@ -1528,7 +1495,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
const char *z;
|
||||
assert( TK_BLOB==OP_HexBlob );
|
||||
n = pExpr->token.n - 3;
|
||||
z = (char*)pExpr->token.z + 2;
|
||||
z = pExpr->token.z + 2;
|
||||
assert( n>=0 );
|
||||
if( n==0 ){
|
||||
z = "";
|
||||
@@ -1540,7 +1507,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
case TK_VARIABLE: {
|
||||
sqlite3VdbeAddOp(v, OP_Variable, pExpr->iTable, 0);
|
||||
if( pExpr->token.n>1 ){
|
||||
sqlite3VdbeChangeP3(v, -1, (char*)pExpr->token.z, pExpr->token.n);
|
||||
sqlite3VdbeChangeP3(v, -1, pExpr->token.z, pExpr->token.n);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1554,14 +1521,13 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
int aff, op;
|
||||
sqlite3ExprCode(pParse, pExpr->pLeft);
|
||||
aff = sqlite3AffinityType(&pExpr->token);
|
||||
op = aff - SQLITE_AFF_TEXT + OP_ToText;
|
||||
assert( op==OP_ToText || aff!=SQLITE_AFF_TEXT );
|
||||
assert( op==OP_ToBlob || aff!=SQLITE_AFF_NONE );
|
||||
assert( op==OP_ToNumeric || aff!=SQLITE_AFF_NUMERIC );
|
||||
assert( op==OP_ToInt || aff!=SQLITE_AFF_INTEGER );
|
||||
assert( op==OP_ToReal || aff!=SQLITE_AFF_REAL );
|
||||
switch( aff ){
|
||||
case SQLITE_AFF_INTEGER: op = OP_ToInt; break;
|
||||
case SQLITE_AFF_NUMERIC: op = OP_ToNumeric; break;
|
||||
case SQLITE_AFF_TEXT: op = OP_ToText; break;
|
||||
case SQLITE_AFF_NONE: op = OP_ToBlob; break;
|
||||
}
|
||||
sqlite3VdbeAddOp(v, op, 0, 0);
|
||||
stackChng = 0;
|
||||
break;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_CAST */
|
||||
@@ -1580,7 +1546,6 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
sqlite3ExprCode(pParse, pExpr->pLeft);
|
||||
sqlite3ExprCode(pParse, pExpr->pRight);
|
||||
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op, 0, 0);
|
||||
stackChng = -1;
|
||||
break;
|
||||
}
|
||||
case TK_AND:
|
||||
@@ -1609,7 +1574,6 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
sqlite3ExprCode(pParse, pExpr->pLeft);
|
||||
sqlite3ExprCode(pParse, pExpr->pRight);
|
||||
sqlite3VdbeAddOp(v, op, 0, 0);
|
||||
stackChng = -1;
|
||||
break;
|
||||
}
|
||||
case TK_UMINUS: {
|
||||
@@ -1617,7 +1581,8 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
assert( pLeft );
|
||||
if( pLeft->op==TK_FLOAT || pLeft->op==TK_INTEGER ){
|
||||
Token *p = &pLeft->token;
|
||||
char *z = sqlite3MPrintf("-%.*s", p->n, p->z);
|
||||
char *z = sqliteMalloc( p->n + 2 );
|
||||
sprintf(z, "-%.*s", p->n, p->z);
|
||||
if( pLeft->op==TK_FLOAT ){
|
||||
sqlite3VdbeOp3(v, OP_Real, 0, 0, z, p->n+1);
|
||||
}else{
|
||||
@@ -1634,7 +1599,6 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
assert( TK_NOT==OP_Not );
|
||||
sqlite3ExprCode(pParse, pExpr->pLeft);
|
||||
sqlite3VdbeAddOp(v, op, 0, 0);
|
||||
stackChng = 0;
|
||||
break;
|
||||
}
|
||||
case TK_ISNULL:
|
||||
@@ -1647,17 +1611,11 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
dest = sqlite3VdbeCurrentAddr(v) + 2;
|
||||
sqlite3VdbeAddOp(v, op, 1, dest);
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, -1, 0);
|
||||
stackChng = 0;
|
||||
break;
|
||||
}
|
||||
case TK_AGG_FUNCTION: {
|
||||
AggInfo *pInfo = pExpr->pAggInfo;
|
||||
if( pInfo==0 ){
|
||||
sqlite3ErrorMsg(pParse, "misuse of aggregate: %T",
|
||||
&pExpr->span);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, pInfo->aFunc[pExpr->iAgg].iMem, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, pInfo->aFunc[pExpr->iAgg].iMem, 0);
|
||||
break;
|
||||
}
|
||||
case TK_CONST_FUNC:
|
||||
@@ -1669,9 +1627,9 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
const char *zId;
|
||||
int constMask = 0;
|
||||
int i;
|
||||
u8 enc = ENC(pParse->db);
|
||||
u8 enc = pParse->db->enc;
|
||||
CollSeq *pColl = 0;
|
||||
zId = (char*)pExpr->token.z;
|
||||
zId = pExpr->token.z;
|
||||
nId = pExpr->token.n;
|
||||
pDef = sqlite3FindFunction(pParse->db, zId, nId, nExpr, enc, 0);
|
||||
assert( pDef!=0 );
|
||||
@@ -1689,7 +1647,6 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ);
|
||||
}
|
||||
sqlite3VdbeOp3(v, OP_Function, constMask, nExpr, (char*)pDef, P3_FUNCDEF);
|
||||
stackChng = 1-nExpr;
|
||||
break;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_SUBQUERY
|
||||
@@ -1748,7 +1705,6 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
case TK_UPLUS:
|
||||
case TK_AS: {
|
||||
sqlite3ExprCode(pParse, pExpr->pLeft);
|
||||
stackChng = 0;
|
||||
break;
|
||||
}
|
||||
case TK_CASE: {
|
||||
@@ -1807,22 +1763,16 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
pExpr->iColumn == OE_Fail );
|
||||
sqlite3DequoteExpr(pExpr);
|
||||
sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn,
|
||||
(char*)pExpr->token.z, pExpr->token.n);
|
||||
pExpr->token.z, pExpr->token.n);
|
||||
} else {
|
||||
assert( pExpr->iColumn == OE_Ignore );
|
||||
sqlite3VdbeAddOp(v, OP_ContextPop, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, pParse->trigStack->ignoreJump);
|
||||
VdbeComment((v, "# raise(IGNORE)"));
|
||||
}
|
||||
stackChng = 0;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if( pParse->ckOffset ){
|
||||
pParse->ckOffset += stackChng;
|
||||
assert( pParse->ckOffset );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1890,7 +1840,6 @@ int sqlite3ExprCodeExprList(
|
||||
void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
|
||||
Vdbe *v = pParse->pVdbe;
|
||||
int op = 0;
|
||||
int ckOffset = pParse->ckOffset;
|
||||
if( v==0 || pExpr==0 ) return;
|
||||
op = pExpr->op;
|
||||
switch( op ){
|
||||
@@ -1965,7 +1914,6 @@ void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
|
||||
break;
|
||||
}
|
||||
}
|
||||
pParse->ckOffset = ckOffset;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1979,7 +1927,6 @@ void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
|
||||
void sqlite3ExprIfFalse(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
|
||||
Vdbe *v = pParse->pVdbe;
|
||||
int op = 0;
|
||||
int ckOffset = pParse->ckOffset;
|
||||
if( v==0 || pExpr==0 ) return;
|
||||
|
||||
/* The value of pExpr->op and op are related as follows:
|
||||
@@ -2076,7 +2023,6 @@ void sqlite3ExprIfFalse(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
|
||||
break;
|
||||
}
|
||||
}
|
||||
pParse->ckOffset = ckOffset;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2110,9 +2056,7 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB){
|
||||
if( pA->token.z ){
|
||||
if( pB->token.z==0 ) return 0;
|
||||
if( pB->token.n!=pA->token.n ) return 0;
|
||||
if( sqlite3StrNICmp((char*)pA->token.z,(char*)pB->token.z,pB->token.n)!=0 ){
|
||||
return 0;
|
||||
}
|
||||
if( sqlite3StrNICmp(pA->token.z, pB->token.z, pB->token.n)!=0 ) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -2236,14 +2180,14 @@ static int analyzeAggregate(void *pArg, Expr *pExpr){
|
||||
if( i>=pAggInfo->nFunc ){
|
||||
/* pExpr is original. Make a new entry in pAggInfo->aFunc[]
|
||||
*/
|
||||
u8 enc = ENC(pParse->db);
|
||||
u8 enc = pParse->db->enc;
|
||||
i = addAggInfoFunc(pAggInfo);
|
||||
if( i>=0 ){
|
||||
pItem = &pAggInfo->aFunc[i];
|
||||
pItem->pExpr = pExpr;
|
||||
pItem->iMem = pParse->nMem++;
|
||||
pItem->pFunc = sqlite3FindFunction(pParse->db,
|
||||
(char*)pExpr->token.z, pExpr->token.n,
|
||||
pExpr->token.z, pExpr->token.n,
|
||||
pExpr->pList ? pExpr->pList->nExpr : 0, enc, 0);
|
||||
if( pExpr->flags & EP_Distinct ){
|
||||
pItem->iDistinct = pParse->nTab++;
|
||||
|
||||
+21
-36
@@ -16,11 +16,11 @@
|
||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.116 2006/01/12 22:17:50 drh Exp $
|
||||
** $Id: func.c,v 1.110 2005/09/08 20:37:43 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
/* #include <math.h> */
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "vdbeInt.h"
|
||||
@@ -101,7 +101,7 @@ static void lengthFunc(
|
||||
break;
|
||||
}
|
||||
case SQLITE_TEXT: {
|
||||
const unsigned char *z = sqlite3_value_text(argv[0]);
|
||||
const char *z = sqlite3_value_text(argv[0]);
|
||||
for(len=0; *z; z++){ if( (0xc0&*z)!=0x80 ) len++; }
|
||||
sqlite3_result_int(context, len);
|
||||
break;
|
||||
@@ -146,8 +146,8 @@ static void substrFunc(
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const unsigned char *z;
|
||||
const unsigned char *z2;
|
||||
const char *z;
|
||||
const char *z2;
|
||||
int i;
|
||||
int p1, p2, len;
|
||||
|
||||
@@ -178,7 +178,7 @@ static void substrFunc(
|
||||
}
|
||||
while( z[i] && (z[i]&0xc0)==0x80 ){ i++; p2++; }
|
||||
if( p2<0 ) p2 = 0;
|
||||
sqlite3_result_text(context, (char*)&z[p1], p2, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, &z[p1], p2, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -210,11 +210,11 @@ static void upperFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
if( argc<1 || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return;
|
||||
z = sqliteMalloc(sqlite3_value_bytes(argv[0])+1);
|
||||
if( z==0 ) return;
|
||||
strcpy((char*)z, (char*)sqlite3_value_text(argv[0]));
|
||||
strcpy(z, sqlite3_value_text(argv[0]));
|
||||
for(i=0; z[i]; i++){
|
||||
z[i] = toupper(z[i]);
|
||||
}
|
||||
sqlite3_result_text(context, (char*)z, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
|
||||
sqliteFree(z);
|
||||
}
|
||||
static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
@@ -223,11 +223,11 @@ static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
if( argc<1 || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return;
|
||||
z = sqliteMalloc(sqlite3_value_bytes(argv[0])+1);
|
||||
if( z==0 ) return;
|
||||
strcpy((char*)z, (char*)sqlite3_value_text(argv[0]));
|
||||
strcpy(z, sqlite3_value_text(argv[0]));
|
||||
for(i=0; z[i]; i++){
|
||||
z[i] = tolower(z[i]);
|
||||
}
|
||||
sqlite3_result_text(context, (char*)z, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
|
||||
sqliteFree(z);
|
||||
}
|
||||
|
||||
@@ -495,7 +495,7 @@ static void likeFunc(
|
||||
** Otherwise, return an error.
|
||||
*/
|
||||
const unsigned char *zEsc = sqlite3_value_text(argv[2]);
|
||||
if( sqlite3utf8CharLen((char*)zEsc, -1)!=1 ){
|
||||
if( sqlite3utf8CharLen(zEsc, -1)!=1 ){
|
||||
sqlite3_result_error(context,
|
||||
"ESCAPE expression must be a single character", -1);
|
||||
return;
|
||||
@@ -592,7 +592,7 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
}
|
||||
case SQLITE_TEXT: {
|
||||
int i,j,n;
|
||||
const unsigned char *zArg = sqlite3_value_text(argv[0]);
|
||||
const char *zArg = sqlite3_value_text(argv[0]);
|
||||
char *z;
|
||||
|
||||
for(i=n=0; zArg[i]; i++){ if( zArg[i]=='\'' ) n++; }
|
||||
@@ -692,7 +692,7 @@ static void randStr(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
zBuf[i] = zSrc[zBuf[i]%(sizeof(zSrc)-1)];
|
||||
}
|
||||
zBuf[n] = 0;
|
||||
sqlite3_result_text(context, (char*)zBuf, n, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, zBuf, n, SQLITE_TRANSIENT);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
@@ -728,17 +728,17 @@ static void test_destructor(
|
||||
test_destructor_count_var++;
|
||||
assert( nArg==1 );
|
||||
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
|
||||
len = sqlite3ValueBytes(argv[0], ENC(db));
|
||||
len = sqlite3ValueBytes(argv[0], db->enc);
|
||||
zVal = sqliteMalloc(len+3);
|
||||
zVal[len] = 0;
|
||||
zVal[len-1] = 0;
|
||||
assert( zVal );
|
||||
zVal++;
|
||||
memcpy(zVal, sqlite3ValueText(argv[0], ENC(db)), len);
|
||||
if( ENC(db)==SQLITE_UTF8 ){
|
||||
memcpy(zVal, sqlite3ValueText(argv[0], db->enc), len);
|
||||
if( db->enc==SQLITE_UTF8 ){
|
||||
sqlite3_result_text(pCtx, zVal, -1, destructor);
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
}else if( ENC(db)==SQLITE_UTF16LE ){
|
||||
}else if( db->enc==SQLITE_UTF16LE ){
|
||||
sqlite3_result_text16le(pCtx, zVal, -1, destructor);
|
||||
}else{
|
||||
sqlite3_result_text16be(pCtx, zVal, -1, destructor);
|
||||
@@ -776,7 +776,7 @@ static void test_auxdata(
|
||||
char *zRet = sqliteMalloc(nArg*2);
|
||||
if( !zRet ) return;
|
||||
for(i=0; i<nArg; i++){
|
||||
char const *z = (char*)sqlite3_value_text(argv[i]);
|
||||
char const *z = sqlite3_value_text(argv[i]);
|
||||
if( z ){
|
||||
char *zAux = sqlite3_get_auxdata(pCtx, i);
|
||||
if( zAux ){
|
||||
@@ -807,7 +807,7 @@ static void test_error(
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_result_error(pCtx, (char*)sqlite3_value_text(argv[0]), 0);
|
||||
sqlite3_result_error(pCtx, sqlite3_value_text(argv[0]), 0);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
@@ -823,13 +823,7 @@ struct SumCtx {
|
||||
};
|
||||
|
||||
/*
|
||||
** Routines used to compute the sum, average, and total.
|
||||
**
|
||||
** The SUM() function follows the (broken) SQL standard which means
|
||||
** that it returns NULL if it sums over no inputs. TOTAL returns
|
||||
** 0.0 in that case. In addition, TOTAL always returns a float where
|
||||
** SUM might return an integer if it never encounters a floating point
|
||||
** value.
|
||||
** Routines used to compute the sum or average.
|
||||
*/
|
||||
static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
SumCtx *p;
|
||||
@@ -863,11 +857,6 @@ static void avgFinalize(sqlite3_context *context){
|
||||
sqlite3_result_double(context, p->sum/(double)p->cnt);
|
||||
}
|
||||
}
|
||||
static void totalFinalize(sqlite3_context *context){
|
||||
SumCtx *p;
|
||||
p = sqlite3_aggregate_context(context, 0);
|
||||
sqlite3_result_double(context, p ? p->sum : 0.0);
|
||||
}
|
||||
|
||||
/*
|
||||
** An instance of the following structure holds the context of a
|
||||
@@ -1011,7 +1000,6 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
{ "min", 1, 0, 1, minmaxStep, minMaxFinalize },
|
||||
{ "max", 1, 2, 1, minmaxStep, minMaxFinalize },
|
||||
{ "sum", 1, 0, 0, sumStep, sumFinalize },
|
||||
{ "total", 1, 0, 0, sumStep, totalFinalize },
|
||||
{ "avg", 1, 0, 0, sumStep, avgFinalize },
|
||||
{ "count", 0, 0, 0, countStep, countFinalize },
|
||||
{ "count", 1, 0, 0, countStep, countFinalize },
|
||||
@@ -1036,9 +1024,6 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
}
|
||||
#ifndef SQLITE_OMIT_ALTERTABLE
|
||||
sqlite3AlterFunctions(db);
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_PARSER
|
||||
sqlite3AttachFunctions(db);
|
||||
#endif
|
||||
for(i=0; i<sizeof(aAggs)/sizeof(aAggs[0]); i++){
|
||||
void *pArg = 0;
|
||||
@@ -1114,7 +1099,7 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
|
||||
if( pExpr->pList->nExpr!=2 ){
|
||||
return 0;
|
||||
}
|
||||
pDef = sqlite3FindFunction(db, (char*)pExpr->token.z, pExpr->token.n, 2,
|
||||
pDef = sqlite3FindFunction(db, pExpr->token.z, pExpr->token.n, 2,
|
||||
SQLITE_UTF8, 0);
|
||||
if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){
|
||||
return 0;
|
||||
|
||||
+1
-6
@@ -12,7 +12,7 @@
|
||||
** This is the implementation of generic hash-tables
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.c,v 1.17 2005/10/03 15:11:09 drh Exp $
|
||||
** $Id: hash.c,v 1.16 2005/01/31 12:56:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <assert.h>
|
||||
@@ -294,11 +294,6 @@ static void removeElementGivenHash(
|
||||
}
|
||||
sqliteFree( elem );
|
||||
pH->count--;
|
||||
if( pH->count<=0 ){
|
||||
assert( pH->first==0 );
|
||||
assert( pH->count==0 );
|
||||
sqlite3HashClear(pH);
|
||||
}
|
||||
}
|
||||
|
||||
/* Attempt to locate an element of the hash table pH with a key
|
||||
|
||||
+43
-53
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle INSERT statements in SQLite.
|
||||
**
|
||||
** $Id: insert.c,v 1.157 2006/01/11 21:41:22 drh Exp $
|
||||
** $Id: insert.c,v 1.143 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -23,11 +23,10 @@
|
||||
**
|
||||
** Character Column affinity
|
||||
** ------------------------------
|
||||
** 'a' TEXT
|
||||
** 'b' NONE
|
||||
** 'c' NUMERIC
|
||||
** 'd' INTEGER
|
||||
** 'e' REAL
|
||||
** 'n' NUMERIC
|
||||
** 'i' INTEGER
|
||||
** 't' TEXT
|
||||
** 'o' NONE
|
||||
*/
|
||||
void sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
|
||||
if( !pIdx->zColAff ){
|
||||
@@ -62,11 +61,10 @@ void sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
|
||||
**
|
||||
** Character Column affinity
|
||||
** ------------------------------
|
||||
** 'a' TEXT
|
||||
** 'b' NONE
|
||||
** 'c' NUMERIC
|
||||
** 'd' INTEGER
|
||||
** 'e' REAL
|
||||
** '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
|
||||
@@ -104,15 +102,15 @@ void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
|
||||
**
|
||||
** No checking is done for sub-selects that are part of expressions.
|
||||
*/
|
||||
static int selectReadsTable(Select *p, Schema *pSchema, int iTab){
|
||||
static int selectReadsTable(Select *p, int iDb, int iTab){
|
||||
int i;
|
||||
struct SrcList_item *pItem;
|
||||
if( p->pSrc==0 ) return 0;
|
||||
for(i=0, pItem=p->pSrc->a; i<p->pSrc->nSrc; i++, pItem++){
|
||||
if( pItem->pSelect ){
|
||||
if( selectReadsTable(pItem->pSelect, pSchema, iTab) ) return 1;
|
||||
if( selectReadsTable(pItem->pSelect, iDb, iTab) ) return 1;
|
||||
}else{
|
||||
if( pItem->pTab->pSchema==pSchema && pItem->pTab->tnum==iTab ) return 1;
|
||||
if( pItem->pTab->iDb==iDb && pItem->pTab->tnum==iTab ) return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -214,7 +212,6 @@ void sqlite3Insert(
|
||||
int newIdx = -1; /* Cursor for the NEW table */
|
||||
Db *pDb; /* The database containing table being inserted into */
|
||||
int counterMem = 0; /* Memory cell holding AUTOINCREMENT counter */
|
||||
int iDb;
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* True if attempting to insert into a view */
|
||||
@@ -225,9 +222,7 @@ void sqlite3Insert(
|
||||
int counterRowid; /* Memory cell holding rowid of autoinc counter */
|
||||
#endif
|
||||
|
||||
if( pParse->nErr || sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( pParse->nErr || sqlite3_malloc_failed ) goto insert_cleanup;
|
||||
db = pParse->db;
|
||||
|
||||
/* Locate the table into which we will be inserting new information.
|
||||
@@ -239,9 +234,8 @@ void sqlite3Insert(
|
||||
if( pTab==0 ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
assert( iDb<db->nDb );
|
||||
pDb = &db->aDb[iDb];
|
||||
assert( pTab->iDb<db->nDb );
|
||||
pDb = &db->aDb[pTab->iDb];
|
||||
zDb = pDb->zName;
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
|
||||
goto insert_cleanup;
|
||||
@@ -277,12 +271,19 @@ void sqlite3Insert(
|
||||
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);
|
||||
if( v==0 ) goto insert_cleanup;
|
||||
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, pSelect || triggers_exist, iDb);
|
||||
sqlite3BeginWriteOperation(pParse, pSelect || triggers_exist, pTab->iDb);
|
||||
|
||||
/* if there are row triggers, allocate a temp table for new.* references. */
|
||||
if( triggers_exist ){
|
||||
@@ -300,11 +301,13 @@ void sqlite3Insert(
|
||||
int base = sqlite3VdbeCurrentAddr(v);
|
||||
counterRowid = pParse->nMem++;
|
||||
counterMem = pParse->nMem++;
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pDb->pSeqTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, 2);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, base+13);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ne, 0x100, base+12);
|
||||
sqlite3VdbeAddOp(v, OP_Ne, 28417, base+12);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, counterRowid, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, 1);
|
||||
@@ -333,9 +336,7 @@ void sqlite3Insert(
|
||||
|
||||
/* Resolve the expressions in the SELECT statement and execute it. */
|
||||
rc = sqlite3Select(pParse, pSelect, SRT_Subroutine, iInsertBlock,0,0,0,0);
|
||||
if( rc || pParse->nErr || sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( rc || pParse->nErr || sqlite3_malloc_failed ) goto insert_cleanup;
|
||||
|
||||
iCleanup = sqlite3VdbeMakeLabel(v);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, iCleanup);
|
||||
@@ -350,7 +351,7 @@ void sqlite3Insert(
|
||||
** of the tables being read by the SELECT statement. Also use a
|
||||
** temp table in the case of row triggers.
|
||||
*/
|
||||
if( triggers_exist || selectReadsTable(pSelect,pTab->pSchema,pTab->tnum) ){
|
||||
if( triggers_exist || selectReadsTable(pSelect, pTab->iDb, pTab->tnum) ){
|
||||
useTempTable = 1;
|
||||
}
|
||||
|
||||
@@ -361,6 +362,7 @@ void sqlite3Insert(
|
||||
srcTab = pParse->nTab++;
|
||||
sqlite3VdbeResolveLabel(v, iInsertBlock);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, srcTab, 0);
|
||||
@@ -633,7 +635,7 @@ void sqlite3Insert(
|
||||
/* Update the count of rows that are inserted
|
||||
*/
|
||||
if( (db->flags & SQLITE_CountRows)!=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, iCntMem);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, iCntMem, 0);
|
||||
}
|
||||
|
||||
if( triggers_exist ){
|
||||
@@ -681,7 +683,9 @@ void sqlite3Insert(
|
||||
if( pTab->autoInc ){
|
||||
int iCur = pParse->nTab;
|
||||
int base = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenWrite, iCur, pDb->pSeqTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, 2);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, counterRowid, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -1, base+7);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
@@ -866,18 +870,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
|
||||
/* Test all CHECK constraints
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_CHECK
|
||||
if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){
|
||||
int allOk = sqlite3VdbeMakeLabel(v);
|
||||
assert( pParse->ckOffset==0 );
|
||||
pParse->ckOffset = nCol;
|
||||
sqlite3ExprIfTrue(pParse, pTab->pCheck, allOk, 1);
|
||||
assert( pParse->ckOffset==nCol );
|
||||
pParse->ckOffset = 0;
|
||||
sqlite3VdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort);
|
||||
sqlite3VdbeResolveLabel(v, allOk);
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_CHECK) */
|
||||
/**** TBD ****/
|
||||
|
||||
/* If we have an INTEGER PRIMARY KEY, make sure the primary key
|
||||
** of the new record does not previously exist. Except, if this
|
||||
@@ -1074,13 +1067,9 @@ void sqlite3CompleteInsertion(
|
||||
if( pParse->nested ){
|
||||
pik_flags = 0;
|
||||
}else{
|
||||
pik_flags = OPFLAG_NCHANGE;
|
||||
pik_flags |= (isUpdate?OPFLAG_ISUPDATE:OPFLAG_LASTROWID);
|
||||
pik_flags = (OPFLAG_NCHANGE|(isUpdate?0:OPFLAG_LASTROWID));
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Insert, base, pik_flags);
|
||||
if( !pParse->nested ){
|
||||
sqlite3VdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
|
||||
}
|
||||
|
||||
if( isUpdate && rowidChng ){
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
@@ -1099,17 +1088,18 @@ void sqlite3OpenTableAndIndices(
|
||||
int op /* OP_OpenRead or OP_OpenWrite */
|
||||
){
|
||||
int i;
|
||||
int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
Index *pIdx;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
sqlite3OpenTable(pParse, base, iDb, pTab, op);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
VdbeComment((v, "# %s", pTab->zName));
|
||||
sqlite3VdbeAddOp(v, op, base, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, base, pTab->nCol);
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
|
||||
assert( pIdx->pSchema==pTab->pSchema );
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
VdbeComment((v, "# %s", pIdx->zName));
|
||||
sqlite3VdbeOp3(v, op, i+base, pIdx->tnum, (char*)pKey, P3_KEYINFO_HANDOFF);
|
||||
sqlite3VdbeOp3(v, op, i+base, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
}
|
||||
if( pParse->nTab<=base+i ){
|
||||
pParse->nTab = base+i;
|
||||
|
||||
+3
-4
@@ -14,7 +14,7 @@
|
||||
** other files are for internal use by SQLite and should not be
|
||||
** accessed by users of the library.
|
||||
**
|
||||
** $Id: legacy.c,v 1.11 2006/01/11 21:41:22 drh Exp $
|
||||
** $Id: legacy.c,v 1.7 2004/09/06 17:34:13 drh Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
@@ -70,6 +70,7 @@ int sqlite3_exec(
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
azCols = sqliteMalloc(2*nCol*sizeof(const char *));
|
||||
if( nCol && !azCols ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto exec_out;
|
||||
}
|
||||
|
||||
@@ -121,11 +122,9 @@ exec_out:
|
||||
if( pStmt ) sqlite3_finalize(pStmt);
|
||||
if( azCols ) sqliteFree(azCols);
|
||||
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
rc = SQLITE_NOMEM;
|
||||
sqlite3MallocClearFailed();
|
||||
}
|
||||
|
||||
if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
|
||||
*pzErrMsg = malloc(1+strlen(sqlite3_errmsg(db)));
|
||||
if( *pzErrMsg ){
|
||||
|
||||
+115
-148
@@ -14,7 +14,7 @@
|
||||
** other files are for internal use by SQLite and should not be
|
||||
** accessed by users of the library.
|
||||
**
|
||||
** $Id: main.c,v 1.323 2006/01/11 21:41:22 drh Exp $
|
||||
** $Id: main.c,v 1.302 2005/09/17 15:20:27 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -26,6 +26,28 @@
|
||||
*/
|
||||
const int sqlite3one = 1;
|
||||
|
||||
#ifndef SQLITE_OMIT_GLOBALRECOVER
|
||||
/*
|
||||
** Linked list of all open database handles. This is used by the
|
||||
** sqlite3_global_recover() function. Entries are added to the list
|
||||
** by openDatabase() and removed by sqlite3_close().
|
||||
*/
|
||||
static sqlite3 *pDbList = 0;
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** Return the transient sqlite3_value object used for encoding conversions
|
||||
** during SQL compilation.
|
||||
*/
|
||||
sqlite3_value *sqlite3GetTransientValue(sqlite3 *db){
|
||||
if( !db->pValue ){
|
||||
db->pValue = sqlite3ValueNew();
|
||||
}
|
||||
return db->pValue;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The version of the library
|
||||
*/
|
||||
@@ -131,17 +153,11 @@ int sqlite3_close(sqlite3 *db){
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
/* sqlite3_close() may not invoke sqliteMalloc(). */
|
||||
sqlite3MallocDisallow();
|
||||
|
||||
for(j=0; j<db->nDb; j++){
|
||||
struct Db *pDb = &db->aDb[j];
|
||||
if( pDb->pBt ){
|
||||
sqlite3BtreeClose(pDb->pBt);
|
||||
pDb->pBt = 0;
|
||||
if( j!=1 ){
|
||||
pDb->pSchema = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
@@ -163,22 +179,33 @@ int sqlite3_close(sqlite3 *db){
|
||||
|
||||
sqlite3HashClear(&db->aFunc);
|
||||
sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
|
||||
if( db->pValue ){
|
||||
sqlite3ValueFree(db->pValue);
|
||||
}
|
||||
if( db->pErr ){
|
||||
sqlite3ValueFree(db->pErr);
|
||||
}
|
||||
|
||||
db->magic = SQLITE_MAGIC_ERROR;
|
||||
#ifndef SQLITE_OMIT_GLOBALRECOVER
|
||||
{
|
||||
sqlite3 *pPrev;
|
||||
sqlite3OsEnterMutex();
|
||||
pPrev = pDbList;
|
||||
while( pPrev && pPrev->pNext!=db ){
|
||||
pPrev = pPrev->pNext;
|
||||
}
|
||||
if( pPrev ){
|
||||
pPrev->pNext = db->pNext;
|
||||
}else{
|
||||
assert( pDbList==db );
|
||||
pDbList = db->pNext;
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The temp-database schema is allocated differently from the other schema
|
||||
** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
|
||||
** So it needs to be freed here. Todo: Why not roll the temp schema into
|
||||
** the same sqliteMalloc() as the one that allocates the database
|
||||
** structure?
|
||||
*/
|
||||
sqliteFree(db->aDb[1].pSchema);
|
||||
db->magic = SQLITE_MAGIC_ERROR;
|
||||
sqliteFree(db);
|
||||
sqlite3MallocAllow();
|
||||
sqlite3ReleaseThreadData();
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -187,24 +214,13 @@ int sqlite3_close(sqlite3 *db){
|
||||
*/
|
||||
void sqlite3RollbackAll(sqlite3 *db){
|
||||
int i;
|
||||
int inTrans = 0;
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( db->aDb[i].pBt ){
|
||||
if( sqlite3BtreeIsInTrans(db->aDb[i].pBt) ){
|
||||
inTrans = 1;
|
||||
}
|
||||
sqlite3BtreeRollback(db->aDb[i].pBt);
|
||||
db->aDb[i].inTrans = 0;
|
||||
}
|
||||
}
|
||||
if( db->flags&SQLITE_InternChanges ){
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
}
|
||||
|
||||
/* If one has been configured, invoke the rollback-hook callback */
|
||||
if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
|
||||
db->xRollbackCallback(db->pRollbackArg);
|
||||
}
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -474,18 +490,21 @@ int sqlite3_create_function16(
|
||||
void (*xFinal)(sqlite3_context*)
|
||||
){
|
||||
int rc;
|
||||
char *zFunc8;
|
||||
char const *zFunc8;
|
||||
sqlite3_value *pTmp;
|
||||
|
||||
if( sqlite3SafetyCheck(db) ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
zFunc8 = sqlite3utf16to8(zFunctionName, -1);
|
||||
pTmp = sqlite3GetTransientValue(db);
|
||||
sqlite3ValueSetStr(pTmp, -1, zFunctionName, SQLITE_UTF16NATIVE,SQLITE_STATIC);
|
||||
zFunc8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
|
||||
|
||||
if( !zFunc8 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
rc = sqlite3_create_function(db, zFunc8, nArg, eTextRep,
|
||||
pUserData, xFunc, xStep, xFinal);
|
||||
sqliteFree(zFunc8);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -528,7 +547,7 @@ void *sqlite3_profile(
|
||||
/*** EXPERIMENTAL ***
|
||||
**
|
||||
** Register a function to be invoked when a transaction comments.
|
||||
** If the invoked function returns non-zero, then the commit becomes a
|
||||
** If either function returns non-zero, then the commit becomes a
|
||||
** rollback.
|
||||
*/
|
||||
void *sqlite3_commit_hook(
|
||||
@@ -542,35 +561,6 @@ void *sqlite3_commit_hook(
|
||||
return pOld;
|
||||
}
|
||||
|
||||
/*
|
||||
** Register a callback to be invoked each time a row is updated,
|
||||
** inserted or deleted using this database connection.
|
||||
*/
|
||||
void *sqlite3_update_hook(
|
||||
sqlite3 *db, /* Attach the hook to this database */
|
||||
void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),
|
||||
void *pArg /* Argument to the function */
|
||||
){
|
||||
void *pRet = db->pUpdateArg;
|
||||
db->xUpdateCallback = xCallback;
|
||||
db->pUpdateArg = pArg;
|
||||
return pRet;
|
||||
}
|
||||
|
||||
/*
|
||||
** Register a callback to be invoked each time a transaction is rolled
|
||||
** back by this database connection.
|
||||
*/
|
||||
void *sqlite3_rollback_hook(
|
||||
sqlite3 *db, /* Attach the hook to this database */
|
||||
void (*xCallback)(void*), /* Callback function */
|
||||
void *pArg /* Argument to the function */
|
||||
){
|
||||
void *pRet = db->pRollbackArg;
|
||||
db->xRollbackCallback = xCallback;
|
||||
db->pRollbackArg = pArg;
|
||||
return pRet;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called to create a connection to a database BTree
|
||||
@@ -631,7 +621,7 @@ int sqlite3BtreeFactory(
|
||||
#endif /* SQLITE_OMIT_MEMORYDB */
|
||||
}
|
||||
|
||||
rc = sqlite3BtreeOpen(zFilename, (sqlite3 *)db, ppBtree, btree_flags);
|
||||
rc = sqlite3BtreeOpen(zFilename, ppBtree, btree_flags);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3BtreeSetBusyHandler(*ppBtree, (void*)&db->busyHandler);
|
||||
sqlite3BtreeSetCacheSize(*ppBtree, nCache);
|
||||
@@ -645,13 +635,13 @@ int sqlite3BtreeFactory(
|
||||
*/
|
||||
const char *sqlite3_errmsg(sqlite3 *db){
|
||||
const char *z;
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
return sqlite3ErrStr(SQLITE_NOMEM);
|
||||
}
|
||||
if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){
|
||||
return sqlite3ErrStr(SQLITE_MISUSE);
|
||||
}
|
||||
z = (char*)sqlite3_value_text(db->pErr);
|
||||
z = sqlite3_value_text(db->pErr);
|
||||
if( z==0 ){
|
||||
z = sqlite3ErrStr(db->errCode);
|
||||
}
|
||||
@@ -684,7 +674,7 @@ const void *sqlite3_errmsg16(sqlite3 *db){
|
||||
};
|
||||
|
||||
const void *z;
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
return (void *)(&outOfMemBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);
|
||||
}
|
||||
if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){
|
||||
@@ -701,11 +691,10 @@ const void *sqlite3_errmsg16(sqlite3 *db){
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
/*
|
||||
** Return the most recent error code generated by an SQLite routine. If NULL is
|
||||
** passed to this function, we assume a malloc() failed during sqlite3_open().
|
||||
** Return the most recent error code generated by an SQLite routine.
|
||||
*/
|
||||
int sqlite3_errcode(sqlite3 *db){
|
||||
if( !db || sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
if( sqlite3SafetyCheck(db) ){
|
||||
@@ -724,11 +713,9 @@ static int openDatabase(
|
||||
sqlite3 **ppDb /* OUT: Returned database handle */
|
||||
){
|
||||
sqlite3 *db;
|
||||
int rc;
|
||||
int rc, i;
|
||||
CollSeq *pColl;
|
||||
|
||||
assert( !sqlite3ThreadDataReadOnly()->mallocFailed );
|
||||
|
||||
/* Allocate the sqlite data structure */
|
||||
db = sqliteMalloc( sizeof(sqlite3) );
|
||||
if( db==0 ) goto opendb_out;
|
||||
@@ -736,32 +723,27 @@ static int openDatabase(
|
||||
db->magic = SQLITE_MAGIC_BUSY;
|
||||
db->nDb = 2;
|
||||
db->aDb = db->aDbStatic;
|
||||
db->enc = SQLITE_UTF8;
|
||||
db->autoCommit = 1;
|
||||
db->flags |= SQLITE_ShortColNames;
|
||||
sqlite3HashInit(&db->aFunc, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&db->aCollSeq, SQLITE_HASH_STRING, 0);
|
||||
|
||||
#if 0
|
||||
for(i=0; i<db->nDb; i++){
|
||||
sqlite3HashInit(&db->aDb[i].tblHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&db->aDb[i].idxHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&db->aDb[i].trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&db->aDb[i].aFKey, SQLITE_HASH_STRING, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Add the default collation sequence BINARY. BINARY works for both UTF-8
|
||||
** and UTF-16, so add a version for each to avoid any unnecessary
|
||||
** conversions. The only error that can occur here is a malloc() failure.
|
||||
*/
|
||||
if( sqlite3_create_collation(db, "BINARY", SQLITE_UTF8, 0,binCollFunc) ||
|
||||
sqlite3_create_collation(db, "BINARY", SQLITE_UTF16, 0,binCollFunc) ||
|
||||
(db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0))==0
|
||||
){
|
||||
/* sqlite3_create_collation() is an external API. So the mallocFailed flag
|
||||
** will have been cleared before returning. So set it explicitly here.
|
||||
*/
|
||||
sqlite3ThreadData()->mallocFailed = 1;
|
||||
!(db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0)) ){
|
||||
rc = db->errCode;
|
||||
assert( rc!=SQLITE_OK );
|
||||
db->magic = SQLITE_MAGIC_CLOSED;
|
||||
goto opendb_out;
|
||||
}
|
||||
@@ -783,14 +765,6 @@ static int openDatabase(
|
||||
db->magic = SQLITE_MAGIC_CLOSED;
|
||||
goto opendb_out;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_PARSER
|
||||
db->aDb[0].pSchema = sqlite3SchemaGet(db->aDb[0].pBt);
|
||||
db->aDb[1].pSchema = sqlite3SchemaGet(0);
|
||||
#endif
|
||||
|
||||
if( db->aDb[0].pSchema ){
|
||||
ENC(db) = SQLITE_UTF8;
|
||||
}
|
||||
|
||||
/* The default safety_level for the main database is 'full'; for the temp
|
||||
** database it is 'NONE'. This matches the pager layer defaults.
|
||||
@@ -802,6 +776,7 @@ static int openDatabase(
|
||||
db->aDb[1].safety_level = 1;
|
||||
#endif
|
||||
|
||||
|
||||
/* Register all built-in functions, but do not attempt to read the
|
||||
** database schema yet. This is delayed until the first time the database
|
||||
** is accessed.
|
||||
@@ -811,13 +786,19 @@ static int openDatabase(
|
||||
db->magic = SQLITE_MAGIC_OPEN;
|
||||
|
||||
opendb_out:
|
||||
if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){
|
||||
sqlite3_close(db);
|
||||
db = 0;
|
||||
if( sqlite3_errcode(db)==SQLITE_OK && sqlite3_malloc_failed ){
|
||||
sqlite3Error(db, SQLITE_NOMEM, 0);
|
||||
}
|
||||
*ppDb = db;
|
||||
sqlite3MallocClearFailed();
|
||||
return rc;
|
||||
#ifndef SQLITE_OMIT_GLOBALRECOVER
|
||||
if( db ){
|
||||
sqlite3OsEnterMutex();
|
||||
db->pNext = pDbList;
|
||||
pDbList = db;
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
#endif
|
||||
return sqlite3_errcode(db);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -842,7 +823,6 @@ int sqlite3_open16(
|
||||
int rc = SQLITE_NOMEM;
|
||||
sqlite3_value *pVal;
|
||||
|
||||
assert( zFilename );
|
||||
assert( ppDb );
|
||||
*ppDb = 0;
|
||||
pVal = sqlite3ValueNew();
|
||||
@@ -851,13 +831,12 @@ int sqlite3_open16(
|
||||
if( zFilename8 ){
|
||||
rc = openDatabase(zFilename8, ppDb);
|
||||
if( rc==SQLITE_OK && *ppDb ){
|
||||
rc = sqlite3_exec(*ppDb, "PRAGMA encoding = 'UTF-16'", 0, 0, 0);
|
||||
sqlite3_exec(*ppDb, "PRAGMA encoding = 'UTF-16'", 0, 0, 0);
|
||||
}
|
||||
}else{
|
||||
assert( sqlite3ThreadDataReadOnly()->mallocFailed );
|
||||
sqlite3MallocClearFailed();
|
||||
}
|
||||
sqlite3ValueFree(pVal);
|
||||
if( pVal ){
|
||||
sqlite3ValueFree(pVal);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -971,15 +950,15 @@ int sqlite3_create_collation16(
|
||||
void* pCtx,
|
||||
int(*xCompare)(void*,int,const void*,int,const void*)
|
||||
){
|
||||
char *zName8;
|
||||
int rc;
|
||||
char const *zName8;
|
||||
sqlite3_value *pTmp;
|
||||
if( sqlite3SafetyCheck(db) ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
zName8 = sqlite3utf16to8(zName, -1);
|
||||
rc = sqlite3_create_collation(db, zName8, enc, pCtx, xCompare);
|
||||
sqliteFree(zName8);
|
||||
return rc;
|
||||
pTmp = sqlite3GetTransientValue(db);
|
||||
sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zName8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
|
||||
return sqlite3_create_collation(db, zName8, enc, pCtx, xCompare);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
@@ -1023,11 +1002,37 @@ int sqlite3_collation_needed16(
|
||||
|
||||
#ifndef SQLITE_OMIT_GLOBALRECOVER
|
||||
/*
|
||||
** This function is now an anachronism. It used to be used to recover from a
|
||||
** malloc() failure, but SQLite now does this automatically.
|
||||
** This function is called to recover from a malloc failure that occured
|
||||
** within SQLite.
|
||||
**
|
||||
** This function is *not* threadsafe. Calling this from within a threaded
|
||||
** application when threads other than the caller have used SQLite is
|
||||
** dangerous and will almost certainly result in malfunctions.
|
||||
*/
|
||||
int sqlite3_global_recover(){
|
||||
return SQLITE_OK;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
if( sqlite3_malloc_failed ){
|
||||
sqlite3 *db;
|
||||
int i;
|
||||
sqlite3_malloc_failed = 0;
|
||||
for(db=pDbList; db; db=db->pNext ){
|
||||
sqlite3ExpirePreparedStatements(db);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
Btree *pBt = db->aDb[i].pBt;
|
||||
if( pBt && (rc=sqlite3BtreeReset(pBt)) ){
|
||||
goto recover_out;
|
||||
}
|
||||
}
|
||||
db->autoCommit = 1;
|
||||
}
|
||||
}
|
||||
|
||||
recover_out:
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3_malloc_failed = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1053,41 +1058,3 @@ int sqlite3Corrupt(void){
|
||||
return SQLITE_CORRUPT;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
/*
|
||||
** Enable or disable the shared pager and schema features for the
|
||||
** current thread.
|
||||
**
|
||||
** This routine should only be called when there are no open
|
||||
** database connections.
|
||||
*/
|
||||
int sqlite3_enable_shared_cache(int enable){
|
||||
ThreadData *pTd = sqlite3ThreadData();
|
||||
|
||||
/* It is only legal to call sqlite3_enable_shared_cache() when there
|
||||
** are no currently open b-trees that were opened by the calling thread.
|
||||
** This condition is only easy to detect if the shared-cache were
|
||||
** previously enabled (and is being disabled).
|
||||
*/
|
||||
if( pTd->pBtree && !enable ){
|
||||
assert( pTd->useSharedData );
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
|
||||
pTd->useSharedData = enable;
|
||||
sqlite3ReleaseThreadData();
|
||||
return SQLITE_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This is a convenience routine that makes sure that all thread-specific
|
||||
** data for this thread has been deallocated.
|
||||
*/
|
||||
void sqlite3_thread_cleanup(void){
|
||||
ThreadData *pTd = sqlite3ThreadData();
|
||||
memset(pTd, 0, sizeof(*pTd));
|
||||
sqlite3ReleaseThreadData();
|
||||
}
|
||||
|
||||
@@ -366,9 +366,9 @@ static void md5step(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
MD5Init(p);
|
||||
}
|
||||
for(i=0; i<argc; i++){
|
||||
const char *zData = (char*)sqlite3_value_text(argv[i]);
|
||||
const char *zData = sqlite3_value_text(argv[i]);
|
||||
if( zData ){
|
||||
MD5Update(p, (unsigned char*)zData, strlen(zData));
|
||||
MD5Update(p, zData, strlen(zData));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
** 2005 November 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 contains OS interface code that is common to all
|
||||
** architectures.
|
||||
*/
|
||||
#define _SQLITE_OS_C_ 1
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** The following routines are convenience wrappers around methods
|
||||
** of the OsFile object. This is mostly just syntactic sugar. All
|
||||
** of this would be completely automatic if SQLite were coded using
|
||||
** C++ instead of plain old C.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile **pId){
|
||||
OsFile *id;
|
||||
if( pId!=0 && (id = *pId)!=0 ){
|
||||
return id->pMethod->xClose(pId);
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
int sqlite3OsOpenDirectory(OsFile *id, const char *zName){
|
||||
return id->pMethod->xOpenDirectory(id, zName);
|
||||
}
|
||||
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
return id->pMethod->xRead(id, pBuf, amt);
|
||||
}
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
return id->pMethod->xWrite(id, pBuf, amt);
|
||||
}
|
||||
int sqlite3OsSeek(OsFile *id, i64 offset){
|
||||
return id->pMethod->xSeek(id, offset);
|
||||
}
|
||||
int sqlite3OsTruncate(OsFile *id, i64 size){
|
||||
return id->pMethod->xTruncate(id, size);
|
||||
}
|
||||
int sqlite3OsSync(OsFile *id, int fullsync){
|
||||
return id->pMethod->xSync(id, fullsync);
|
||||
}
|
||||
void sqlite3OsSetFullSync(OsFile *id, int value){
|
||||
id->pMethod->xSetFullSync(id, value);
|
||||
}
|
||||
int sqlite3OsFileHandle(OsFile *id){
|
||||
return id->pMethod->xFileHandle(id);
|
||||
}
|
||||
int sqlite3OsFileSize(OsFile *id, i64 *pSize){
|
||||
return id->pMethod->xFileSize(id, pSize);
|
||||
}
|
||||
int sqlite3OsLock(OsFile *id, int lockType){
|
||||
return id->pMethod->xLock(id, lockType);
|
||||
}
|
||||
int sqlite3OsUnlock(OsFile *id, int lockType){
|
||||
return id->pMethod->xUnlock(id, lockType);
|
||||
}
|
||||
int sqlite3OsLockState(OsFile *id){
|
||||
return id->pMethod->xLockState(id);
|
||||
}
|
||||
int sqlite3OsCheckReservedLock(OsFile *id){
|
||||
return id->pMethod->xCheckReservedLock(id);
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_REDEF_IO
|
||||
/*
|
||||
** A function to return a pointer to the virtual function table.
|
||||
** This routine really does not accomplish very much since the
|
||||
** virtual function table is a global variable and anybody who
|
||||
** can call this function can just as easily access the variable
|
||||
** for themselves. Nevertheless, we include this routine for
|
||||
** backwards compatibility with an earlier redefinable I/O
|
||||
** interface design.
|
||||
*/
|
||||
struct sqlite3OsVtbl *sqlite3_os_switch(void){
|
||||
return &sqlite3Os;
|
||||
}
|
||||
#endif
|
||||
@@ -18,10 +18,12 @@
|
||||
#define _SQLITE_OS_H_
|
||||
|
||||
/*
|
||||
** Figure out if we are dealing with Unix, Windows, or some other
|
||||
** operating system.
|
||||
** Figure out if we are dealing with Unix, Windows or MacOS.
|
||||
**
|
||||
** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
|
||||
** The MacOS build is designed to use CodeWarrior (tested with v8)
|
||||
*/
|
||||
#if !defined(OS_UNIX) && !defined(OS_OTHER)
|
||||
#if !defined(OS_UNIX) && !defined(OS_TEST) && !defined(OS_OTHER)
|
||||
# define OS_OTHER 0
|
||||
# ifndef OS_WIN
|
||||
# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
|
||||
@@ -40,15 +42,25 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Define the maximum size of a temporary filename
|
||||
** Invoke the appropriate operating-system specific header file.
|
||||
*/
|
||||
#if OS_TEST
|
||||
# include "os_test.h"
|
||||
#endif
|
||||
#if OS_UNIX
|
||||
# include "os_unix.h"
|
||||
#endif
|
||||
#if OS_WIN
|
||||
# include <windows.h>
|
||||
# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
|
||||
#else
|
||||
# define SQLITE_TEMPNAME_SIZE 200
|
||||
# include "os_win.h"
|
||||
#endif
|
||||
|
||||
/* os_other.c and os_other.h are not delivered with SQLite. These files
|
||||
** are place-holders that can be filled in by third-party developers to
|
||||
** implement backends to their on proprietary operating systems.
|
||||
*/
|
||||
#if OS_OTHER
|
||||
# include "os_other.h"
|
||||
#endif
|
||||
|
||||
/* If the SET_FULLSYNC macro is not defined above, then make it
|
||||
@@ -71,104 +83,6 @@
|
||||
# define TEMP_FILE_PREFIX "sqlite_"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Define the interfaces for Unix and for Windows.
|
||||
*/
|
||||
#if OS_UNIX
|
||||
#define sqlite3OsOpenReadWrite sqlite3UnixOpenReadWrite
|
||||
#define sqlite3OsOpenExclusive sqlite3UnixOpenExclusive
|
||||
#define sqlite3OsOpenReadOnly sqlite3UnixOpenReadOnly
|
||||
#define sqlite3OsDelete sqlite3UnixDelete
|
||||
#define sqlite3OsFileExists sqlite3UnixFileExists
|
||||
#define sqlite3OsFullPathname sqlite3UnixFullPathname
|
||||
#define sqlite3OsIsDirWritable sqlite3UnixIsDirWritable
|
||||
#define sqlite3OsSyncDirectory sqlite3UnixSyncDirectory
|
||||
#define sqlite3OsTempFileName sqlite3UnixTempFileName
|
||||
#define sqlite3OsRandomSeed sqlite3UnixRandomSeed
|
||||
#define sqlite3OsSleep sqlite3UnixSleep
|
||||
#define sqlite3OsCurrentTime sqlite3UnixCurrentTime
|
||||
#define sqlite3OsEnterMutex sqlite3UnixEnterMutex
|
||||
#define sqlite3OsLeaveMutex sqlite3UnixLeaveMutex
|
||||
#define sqlite3OsInMutex sqlite3UnixInMutex
|
||||
#define sqlite3OsThreadSpecificData sqlite3UnixThreadSpecificData
|
||||
#define sqlite3OsMalloc sqlite3GenericMalloc
|
||||
#define sqlite3OsRealloc sqlite3GenericRealloc
|
||||
#define sqlite3OsFree sqlite3GenericFree
|
||||
#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
|
||||
#endif
|
||||
#if OS_WIN
|
||||
#define sqlite3OsOpenReadWrite sqlite3WinOpenReadWrite
|
||||
#define sqlite3OsOpenExclusive sqlite3WinOpenExclusive
|
||||
#define sqlite3OsOpenReadOnly sqlite3WinOpenReadOnly
|
||||
#define sqlite3OsDelete sqlite3WinDelete
|
||||
#define sqlite3OsFileExists sqlite3WinFileExists
|
||||
#define sqlite3OsFullPathname sqlite3WinFullPathname
|
||||
#define sqlite3OsIsDirWritable sqlite3WinIsDirWritable
|
||||
#define sqlite3OsSyncDirectory sqlite3WinSyncDirectory
|
||||
#define sqlite3OsTempFileName sqlite3WinTempFileName
|
||||
#define sqlite3OsRandomSeed sqlite3WinRandomSeed
|
||||
#define sqlite3OsSleep sqlite3WinSleep
|
||||
#define sqlite3OsCurrentTime sqlite3WinCurrentTime
|
||||
#define sqlite3OsEnterMutex sqlite3WinEnterMutex
|
||||
#define sqlite3OsLeaveMutex sqlite3WinLeaveMutex
|
||||
#define sqlite3OsInMutex sqlite3WinInMutex
|
||||
#define sqlite3OsThreadSpecificData sqlite3WinThreadSpecificData
|
||||
#define sqlite3OsMalloc sqlite3GenericMalloc
|
||||
#define sqlite3OsRealloc sqlite3GenericRealloc
|
||||
#define sqlite3OsFree sqlite3GenericFree
|
||||
#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
|
||||
#endif
|
||||
|
||||
/*
|
||||
** If using an alternative OS interface, then we must have an "os_other.h"
|
||||
** header file available for that interface. Presumably the "os_other.h"
|
||||
** header file contains #defines similar to those above.
|
||||
*/
|
||||
#if OS_OTHER
|
||||
# include "os_other.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Forward declarations
|
||||
*/
|
||||
typedef struct OsFile OsFile;
|
||||
typedef struct IoMethod IoMethod;
|
||||
|
||||
/*
|
||||
** An instance of the following structure contains pointers to all
|
||||
** methods on an OsFile object.
|
||||
*/
|
||||
struct IoMethod {
|
||||
int (*xClose)(OsFile**);
|
||||
int (*xOpenDirectory)(OsFile*, const char*);
|
||||
int (*xRead)(OsFile*, void*, int amt);
|
||||
int (*xWrite)(OsFile*, const void*, int amt);
|
||||
int (*xSeek)(OsFile*, i64 offset);
|
||||
int (*xTruncate)(OsFile*, i64 size);
|
||||
int (*xSync)(OsFile*, int);
|
||||
void (*xSetFullSync)(OsFile *id, int setting);
|
||||
int (*xFileHandle)(OsFile *id);
|
||||
int (*xFileSize)(OsFile*, i64 *pSize);
|
||||
int (*xLock)(OsFile*, int);
|
||||
int (*xUnlock)(OsFile*, int);
|
||||
int (*xLockState)(OsFile *id);
|
||||
int (*xCheckReservedLock)(OsFile *id);
|
||||
};
|
||||
|
||||
/*
|
||||
** The OsFile object describes an open disk file in an OS-dependent way.
|
||||
** The version of OsFile defined here is a generic version. Each OS
|
||||
** implementation defines its own subclass of this structure that contains
|
||||
** additional information needed to handle file I/O. But the pMethod
|
||||
** entry (pointing to the virtual function table) always occurs first
|
||||
** so that we can always find the appropriate methods.
|
||||
*/
|
||||
struct OsFile {
|
||||
IoMethod const *pMethod;
|
||||
};
|
||||
|
||||
/*
|
||||
** The following values may be passed as the second argument to
|
||||
** sqlite3OsLock(). The various locks exhibit the following semantics:
|
||||
@@ -223,10 +137,8 @@ struct OsFile {
|
||||
** 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 sqlite_aux.h so that adaptors for
|
||||
** connecting SQLite to other operating systems can use the same byte
|
||||
** ranges for locking. In particular, the same locking strategy and
|
||||
** byte ranges are used for Unix. This leaves open the possiblity of having
|
||||
** 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
|
||||
@@ -260,181 +172,36 @@ extern unsigned int sqlite3_pending_byte;
|
||||
#define SHARED_FIRST (PENDING_BYTE+2)
|
||||
#define SHARED_SIZE 510
|
||||
|
||||
/*
|
||||
** Prototypes for operating system interface routines.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile**);
|
||||
int sqlite3OsOpenDirectory(OsFile*, const char*);
|
||||
|
||||
int sqlite3OsDelete(const char*);
|
||||
int sqlite3OsFileExists(const char*);
|
||||
int sqlite3OsOpenReadWrite(const char*, OsFile*, int*);
|
||||
int sqlite3OsOpenExclusive(const char*, OsFile*, int);
|
||||
int sqlite3OsOpenReadOnly(const char*, OsFile*);
|
||||
int sqlite3OsOpenDirectory(const char*, OsFile*);
|
||||
int sqlite3OsSyncDirectory(const char*);
|
||||
int sqlite3OsTempFileName(char*);
|
||||
int sqlite3OsIsDirWritable(char*);
|
||||
int sqlite3OsClose(OsFile*);
|
||||
int sqlite3OsRead(OsFile*, void*, int amt);
|
||||
int sqlite3OsWrite(OsFile*, const void*, int amt);
|
||||
int sqlite3OsSeek(OsFile*, i64 offset);
|
||||
int sqlite3OsTruncate(OsFile*, i64 size);
|
||||
int sqlite3OsSync(OsFile*, int);
|
||||
void sqlite3OsSetFullSync(OsFile *id, int setting);
|
||||
int sqlite3OsFileHandle(OsFile *id);
|
||||
int sqlite3OsTruncate(OsFile*, i64 size);
|
||||
int sqlite3OsFileSize(OsFile*, i64 *pSize);
|
||||
char *sqlite3OsFullPathname(const char*);
|
||||
int sqlite3OsLock(OsFile*, int);
|
||||
int sqlite3OsUnlock(OsFile*, int);
|
||||
int sqlite3OsLockState(OsFile *id);
|
||||
int sqlite3OsCheckReservedLock(OsFile *id);
|
||||
int sqlite3OsOpenReadWrite(const char*, OsFile**, int*);
|
||||
int sqlite3OsOpenExclusive(const char*, OsFile**, int);
|
||||
int sqlite3OsOpenReadOnly(const char*, OsFile**);
|
||||
int sqlite3OsDelete(const char*);
|
||||
int sqlite3OsFileExists(const char*);
|
||||
char *sqlite3OsFullPathname(const char*);
|
||||
int sqlite3OsIsDirWritable(char*);
|
||||
int sqlite3OsSyncDirectory(const char*);
|
||||
int sqlite3OsTempFileName(char*);
|
||||
|
||||
|
||||
/* The interface for file I/O is above. Other miscellaneous functions
|
||||
** are below */
|
||||
|
||||
int sqlite3OsRandomSeed(char*);
|
||||
int sqlite3OsSleep(int ms);
|
||||
int sqlite3OsCurrentTime(double*);
|
||||
void sqlite3OsEnterMutex(void);
|
||||
void sqlite3OsLeaveMutex(void);
|
||||
int sqlite3OsInMutex(void);
|
||||
ThreadData *sqlite3OsThreadSpecificData(int);
|
||||
void *sqlite3OsMalloc(int);
|
||||
void *sqlite3OsRealloc(void *, int);
|
||||
void sqlite3OsFree(void *);
|
||||
int sqlite3OsAllocationSize(void *);
|
||||
|
||||
/*
|
||||
** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer
|
||||
** interface routines are not called directly but are invoked using
|
||||
** pointers to functions. This allows the implementation of various
|
||||
** OS-layer interface routines to be modified at run-time. There are
|
||||
** obscure but legitimate reasons for wanting to do this. But for
|
||||
** most users, a direct call to the underlying interface is preferable
|
||||
** so the the redefinable I/O interface is turned off by default.
|
||||
*/
|
||||
#ifdef SQLITE_ENABLE_REDEF_IO
|
||||
|
||||
/*
|
||||
** When redefinable I/O is enabled, a single global instance of the
|
||||
** following structure holds pointers to the routines that SQLite
|
||||
** uses to talk with the underlying operating system. Modify this
|
||||
** structure (before using any SQLite API!) to accomodate perculiar
|
||||
** operating system interfaces or behaviors.
|
||||
*/
|
||||
struct sqlite3OsVtbl {
|
||||
int (*xOpenReadWrite)(const char*, OsFile**, int*);
|
||||
int (*xOpenExclusive)(const char*, OsFile**, int);
|
||||
int (*xOpenReadOnly)(const char*, OsFile**);
|
||||
|
||||
int (*xDelete)(const char*);
|
||||
int (*xFileExists)(const char*);
|
||||
char *(*xFullPathname)(const char*);
|
||||
int (*xIsDirWritable)(char*);
|
||||
int (*xSyncDirectory)(const char*);
|
||||
int (*xTempFileName)(char*);
|
||||
|
||||
int (*xRandomSeed)(char*);
|
||||
int (*xSleep)(int ms);
|
||||
int (*xCurrentTime)(double*);
|
||||
|
||||
void (*xEnterMutex)(void);
|
||||
void (*xLeaveMutex)(void);
|
||||
int (*xInMutex)(void);
|
||||
ThreadData *(*xThreadSpecificData)(int);
|
||||
|
||||
void *(*xMalloc)(int);
|
||||
void *(*xRealloc)(void *, int);
|
||||
void (*xFree)(void *);
|
||||
int (*xAllocationSize)(void *);
|
||||
};
|
||||
|
||||
/* Macro used to comment out routines that do not exists when there is
|
||||
** no disk I/O
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_DISKIO
|
||||
# define IF_DISKIO(X) 0
|
||||
#else
|
||||
# define IF_DISKIO(X) X
|
||||
#endif
|
||||
|
||||
#ifdef _SQLITE_OS_C_
|
||||
/*
|
||||
** The os.c file implements the global virtual function table.
|
||||
*/
|
||||
struct sqlite3OsVtbl sqlite3Os = {
|
||||
IF_DISKIO( sqlite3OsOpenReadWrite ),
|
||||
IF_DISKIO( sqlite3OsOpenExclusive ),
|
||||
IF_DISKIO( sqlite3OsOpenReadOnly ),
|
||||
IF_DISKIO( sqlite3OsDelete ),
|
||||
IF_DISKIO( sqlite3OsFileExists ),
|
||||
IF_DISKIO( sqlite3OsFullPathname ),
|
||||
IF_DISKIO( sqlite3OsIsDirWritable ),
|
||||
IF_DISKIO( sqlite3OsSyncDirectory ),
|
||||
IF_DISKIO( sqlite3OsTempFileName ),
|
||||
sqlite3OsRandomSeed,
|
||||
sqlite3OsSleep,
|
||||
sqlite3OsCurrentTime,
|
||||
sqlite3OsEnterMutex,
|
||||
sqlite3OsLeaveMutex,
|
||||
sqlite3OsInMutex,
|
||||
sqlite3OsThreadSpecificData,
|
||||
sqlite3OsMalloc,
|
||||
sqlite3OsRealloc,
|
||||
sqlite3OsFree,
|
||||
sqlite3OsAllocationSize
|
||||
};
|
||||
#else
|
||||
/*
|
||||
** Files other than os.c just reference the global virtual function table.
|
||||
*/
|
||||
extern struct sqlite3OsVtbl sqlite3Os;
|
||||
#endif /* _SQLITE_OS_C_ */
|
||||
|
||||
|
||||
/* This additional API routine is available with redefinable I/O */
|
||||
struct sqlite3OsVtbl *sqlite3_os_switch(void);
|
||||
|
||||
|
||||
/*
|
||||
** Redefine the OS interface to go through the virtual function table
|
||||
** rather than calling routines directly.
|
||||
*/
|
||||
#undef sqlite3OsOpenReadWrite
|
||||
#undef sqlite3OsOpenExclusive
|
||||
#undef sqlite3OsOpenReadOnly
|
||||
#undef sqlite3OsDelete
|
||||
#undef sqlite3OsFileExists
|
||||
#undef sqlite3OsFullPathname
|
||||
#undef sqlite3OsIsDirWritable
|
||||
#undef sqlite3OsSyncDirectory
|
||||
#undef sqlite3OsTempFileName
|
||||
#undef sqlite3OsRandomSeed
|
||||
#undef sqlite3OsSleep
|
||||
#undef sqlite3OsCurrentTime
|
||||
#undef sqlite3OsEnterMutex
|
||||
#undef sqlite3OsLeaveMutex
|
||||
#undef sqlite3OsInMutex
|
||||
#undef sqlite3OsThreadSpecificData
|
||||
#undef sqlite3OsMalloc
|
||||
#undef sqlite3OsRealloc
|
||||
#undef sqlite3OsFree
|
||||
#undef sqlite3OsAllocationSize
|
||||
#define sqlite3OsOpenReadWrite sqlite3Os.xOpenReadWrite
|
||||
#define sqlite3OsOpenExclusive sqlite3Os.xOpenExclusive
|
||||
#define sqlite3OsOpenReadOnly sqlite3Os.xOpenReadOnly
|
||||
#define sqlite3OsDelete sqlite3Os.xDelete
|
||||
#define sqlite3OsFileExists sqlite3Os.xFileExists
|
||||
#define sqlite3OsFullPathname sqlite3Os.xFullPathname
|
||||
#define sqlite3OsIsDirWritable sqlite3Os.xIsDirWritable
|
||||
#define sqlite3OsSyncDirectory sqlite3Os.xSyncDirectory
|
||||
#define sqlite3OsTempFileName sqlite3Os.xTempFileName
|
||||
#define sqlite3OsRandomSeed sqlite3Os.xRandomSeed
|
||||
#define sqlite3OsSleep sqlite3Os.xSleep
|
||||
#define sqlite3OsCurrentTime sqlite3Os.xCurrentTime
|
||||
#define sqlite3OsEnterMutex sqlite3Os.xEnterMutex
|
||||
#define sqlite3OsLeaveMutex sqlite3Os.xLeaveMutex
|
||||
#define sqlite3OsInMutex sqlite3Os.xInMutex
|
||||
#define sqlite3OsThreadSpecificData sqlite3Os.xThreadSpecificData
|
||||
#define sqlite3OsMalloc sqlite3Os.xMalloc
|
||||
#define sqlite3OsRealloc sqlite3Os.xRealloc
|
||||
#define sqlite3OsFree sqlite3Os.xFree
|
||||
#define sqlite3OsAllocationSize sqlite3Os.xAllocationSize
|
||||
|
||||
#endif /* SQLITE_ENABLE_REDEF_IO */
|
||||
|
||||
#endif /* _SQLITE_OS_H_ */
|
||||
|
||||
+1
-67
@@ -88,7 +88,6 @@ static unsigned int elapse;
|
||||
** is used for testing the I/O recovery logic.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_io_error_hit = 0;
|
||||
int sqlite3_io_error_pending = 0;
|
||||
int sqlite3_diskfull_pending = 0;
|
||||
int sqlite3_diskfull = 0;
|
||||
@@ -96,7 +95,7 @@ int sqlite3_diskfull = 0;
|
||||
if( sqlite3_io_error_pending ) \
|
||||
if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
|
||||
static void local_ioerr(){
|
||||
sqlite3_io_error_hit = 1; /* Really just a place to set a breakpoint */
|
||||
sqlite3_io_error_pending = 0; /* Really just a place to set a breakpoint */
|
||||
}
|
||||
#define SimulateDiskfullError \
|
||||
if( sqlite3_diskfull_pending ){ \
|
||||
@@ -122,68 +121,3 @@ int sqlite3_open_file_count = 0;
|
||||
#else
|
||||
#define OpenCounter(X)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** sqlite3GenericMalloc
|
||||
** sqlite3GenericRealloc
|
||||
** sqlite3GenericOsFree
|
||||
** sqlite3GenericAllocationSize
|
||||
**
|
||||
** Implementation of the os level dynamic memory allocation interface in terms
|
||||
** of the standard malloc(), realloc() and free() found in many operating
|
||||
** systems. No rocket science here.
|
||||
**
|
||||
** There are two versions of these four functions here. The version
|
||||
** implemented here is only used if memory-management or memory-debugging is
|
||||
** enabled. This version allocates an extra 8-bytes at the beginning of each
|
||||
** block and stores the size of the allocation there.
|
||||
**
|
||||
** If neither memory-management or debugging is enabled, the second
|
||||
** set of implementations is used instead.
|
||||
*/
|
||||
#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || defined (SQLITE_MEMDEBUG)
|
||||
void *sqlite3GenericMalloc(int n){
|
||||
char *p = (char *)malloc(n+8);
|
||||
assert(n>0);
|
||||
assert(sizeof(int)<=8);
|
||||
if( p ){
|
||||
*(int *)p = n;
|
||||
}
|
||||
return (void *)(p + 8);
|
||||
}
|
||||
void *sqlite3GenericRealloc(void *p, int n){
|
||||
char *p2 = ((char *)p - 8);
|
||||
assert(n>0);
|
||||
p2 = realloc(p2, n+8);
|
||||
if( p2 ){
|
||||
*(int *)p2 = n;
|
||||
}
|
||||
return (void *)((char *)p2 + 8);
|
||||
}
|
||||
void sqlite3GenericFree(void *p){
|
||||
assert(p);
|
||||
free((void *)((char *)p - 8));
|
||||
}
|
||||
int sqlite3GenericAllocationSize(void *p){
|
||||
return p ? *(int *)((char *)p - 8) : 0;
|
||||
}
|
||||
#else
|
||||
void *sqlite3GenericMalloc(int n){
|
||||
char *p = (char *)malloc(n);
|
||||
return (void *)p;
|
||||
}
|
||||
void *sqlite3GenericRealloc(void *p, int n){
|
||||
assert(n>0);
|
||||
p = realloc(p, n);
|
||||
return p;
|
||||
}
|
||||
void sqlite3GenericFree(void *p){
|
||||
assert(p);
|
||||
free(p);
|
||||
}
|
||||
#if 0 /* Never actually invoked */
|
||||
int sqlite3GenericAllocationSize(void *p){
|
||||
assert(0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
-463
@@ -1,463 +0,0 @@
|
||||
/*
|
||||
** 2004 May 22
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This file contains code that is specific to Unix systems. It is used
|
||||
** for testing SQLite only.
|
||||
*/
|
||||
#if OS_TEST /* This file is used for the test backend only */
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
|
||||
#define sqlite3OsOpenReadWrite sqlite3RealOpenReadWrite
|
||||
#define sqlite3OsOpenExclusive sqlite3RealOpenExclusive
|
||||
#define sqlite3OsOpenReadOnly sqlite3RealOpenReadOnly
|
||||
#define sqlite3OsOpenDirectory sqlite3RealOpenDirectory
|
||||
#define sqlite3OsClose sqlite3RealClose
|
||||
#define sqlite3OsRead sqlite3RealRead
|
||||
#define sqlite3OsWrite sqlite3RealWrite
|
||||
#define sqlite3OsSeek sqlite3RealSeek
|
||||
#define sqlite3OsSync sqlite3RealSync
|
||||
#define sqlite3OsTruncate sqlite3RealTruncate
|
||||
#define sqlite3OsFileSize sqlite3RealFileSize
|
||||
#define sqlite3OsLock sqlite3RealLock
|
||||
#define sqlite3OsUnlock sqlite3RealUnlock
|
||||
#define sqlite3OsCheckReservedLock sqlite3RealCheckReservedLock
|
||||
|
||||
#define OsFile OsRealFile
|
||||
#define OS_UNIX 1
|
||||
#include "os_unix.c"
|
||||
#undef OS_UNIX
|
||||
#undef OsFile
|
||||
|
||||
#undef sqlite3OsOpenReadWrite
|
||||
#undef sqlite3OsOpenExclusive
|
||||
#undef sqlite3OsOpenReadOnly
|
||||
#undef sqlite3OsOpenDirectory
|
||||
#undef sqlite3OsClose
|
||||
#undef sqlite3OsRead
|
||||
#undef sqlite3OsWrite
|
||||
#undef sqlite3OsSeek
|
||||
#undef sqlite3OsSync
|
||||
#undef sqlite3OsTruncate
|
||||
#undef sqlite3OsFileSize
|
||||
#undef sqlite3OsLock
|
||||
#undef sqlite3OsUnlock
|
||||
#undef sqlite3OsCheckReservedLock
|
||||
|
||||
#define BLOCKSIZE 512
|
||||
#define BLOCK_OFFSET(x) ((x) * BLOCKSIZE)
|
||||
|
||||
|
||||
/*
|
||||
** The following variables control when a simulated crash occurs.
|
||||
**
|
||||
** If iCrashDelay is non-zero, then zCrashFile contains (full path) name of
|
||||
** a file that SQLite will call sqlite3OsSync() on. Each time this happens
|
||||
** iCrashDelay is decremented. If iCrashDelay is zero after being
|
||||
** decremented, a "crash" occurs during the sync() operation.
|
||||
**
|
||||
** In other words, a crash occurs the iCrashDelay'th time zCrashFile is
|
||||
** synced.
|
||||
*/
|
||||
static int iCrashDelay = 0;
|
||||
char zCrashFile[256];
|
||||
|
||||
/*
|
||||
** Set the value of the two crash parameters.
|
||||
*/
|
||||
void sqlite3SetCrashParams(int iDelay, char const *zFile){
|
||||
sqlite3OsEnterMutex();
|
||||
assert( strlen(zFile)<256 );
|
||||
strcpy(zCrashFile, zFile);
|
||||
iCrashDelay = iDelay;
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
|
||||
/*
|
||||
** File zPath is being sync()ed. Return non-zero if this should
|
||||
** cause a crash.
|
||||
*/
|
||||
static int crashRequired(char const *zPath){
|
||||
int r;
|
||||
int n;
|
||||
sqlite3OsEnterMutex();
|
||||
n = strlen(zCrashFile);
|
||||
if( zCrashFile[n-1]=='*' ){
|
||||
n--;
|
||||
}else if( strlen(zPath)>n ){
|
||||
n = strlen(zPath);
|
||||
}
|
||||
r = 0;
|
||||
if( iCrashDelay>0 && strncmp(zPath, zCrashFile, n)==0 ){
|
||||
iCrashDelay--;
|
||||
if( iCrashDelay<=0 ){
|
||||
r = 1;
|
||||
}
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
static OsTestFile *pAllFiles = 0;
|
||||
|
||||
/*
|
||||
** Initialise the os_test.c specific fields of pFile.
|
||||
*/
|
||||
static void initFile(OsFile *id, char const *zName){
|
||||
OsTestFile *pFile = (OsTestFile *)
|
||||
sqliteMalloc(sizeof(OsTestFile) + strlen(zName)+1);
|
||||
pFile->nMaxWrite = 0;
|
||||
pFile->nBlk = 0;
|
||||
pFile->apBlk = 0;
|
||||
pFile->zName = (char *)(&pFile[1]);
|
||||
strcpy(pFile->zName, zName);
|
||||
*id = pFile;
|
||||
pFile->pNext = pAllFiles;
|
||||
pAllFiles = pFile;
|
||||
}
|
||||
|
||||
/*
|
||||
** Undo the work done by initFile. Delete the OsTestFile structure
|
||||
** and unlink the structure from the pAllFiles list.
|
||||
*/
|
||||
static void closeFile(OsFile *id){
|
||||
OsTestFile *pFile = *id;
|
||||
if( pFile==pAllFiles ){
|
||||
pAllFiles = pFile->pNext;
|
||||
}else{
|
||||
OsTestFile *p;
|
||||
for(p=pAllFiles; p->pNext!=pFile; p=p->pNext ){
|
||||
assert( p );
|
||||
}
|
||||
p->pNext = pFile->pNext;
|
||||
}
|
||||
sqliteFree(pFile);
|
||||
*id = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the current seek offset from the start of the file. This
|
||||
** is unix-only code.
|
||||
*/
|
||||
static i64 osTell(OsTestFile *pFile){
|
||||
return lseek(pFile->fd.h, 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
/*
|
||||
** Load block 'blk' into the cache of pFile.
|
||||
*/
|
||||
static int cacheBlock(OsTestFile *pFile, int blk){
|
||||
if( blk>=pFile->nBlk ){
|
||||
int n = ((pFile->nBlk * 2) + 100 + blk);
|
||||
/* if( pFile->nBlk==0 ){ printf("DIRTY %s\n", pFile->zName); } */
|
||||
pFile->apBlk = (u8 **)sqliteRealloc(pFile->apBlk, n * sizeof(u8*));
|
||||
if( !pFile->apBlk ) return SQLITE_NOMEM;
|
||||
memset(&pFile->apBlk[pFile->nBlk], 0, (n - pFile->nBlk)*sizeof(u8*));
|
||||
pFile->nBlk = n;
|
||||
}
|
||||
|
||||
if( !pFile->apBlk[blk] ){
|
||||
i64 filesize;
|
||||
int rc;
|
||||
|
||||
u8 *p = sqliteMalloc(BLOCKSIZE);
|
||||
if( !p ) return SQLITE_NOMEM;
|
||||
pFile->apBlk[blk] = p;
|
||||
|
||||
rc = sqlite3RealFileSize(&pFile->fd, &filesize);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
if( BLOCK_OFFSET(blk)<filesize ){
|
||||
int len = BLOCKSIZE;
|
||||
rc = sqlite3RealSeek(&pFile->fd, blk*BLOCKSIZE);
|
||||
if( BLOCK_OFFSET(blk+1)>filesize ){
|
||||
len = filesize - BLOCK_OFFSET(blk);
|
||||
}
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3RealRead(&pFile->fd, p, len);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* #define TRACE_WRITECACHE */
|
||||
|
||||
/*
|
||||
** Write the cache of pFile to disk. If crash is non-zero, randomly
|
||||
** skip blocks when writing. The cache is deleted before returning.
|
||||
*/
|
||||
static int writeCache2(OsTestFile *pFile, int crash){
|
||||
int i;
|
||||
int nMax = pFile->nMaxWrite;
|
||||
i64 offset;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
offset = osTell(pFile);
|
||||
for(i=0; i<pFile->nBlk; i++){
|
||||
u8 *p = pFile->apBlk[i];
|
||||
if( p ){
|
||||
int skip = 0;
|
||||
int trash = 0;
|
||||
if( crash ){
|
||||
char random;
|
||||
sqlite3Randomness(1, &random);
|
||||
if( random & 0x01 ){
|
||||
if( random & 0x02 ){
|
||||
trash = 1;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Trashing block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}else{
|
||||
skip = 1;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Skiping block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}
|
||||
}else{
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Writing block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3RealSeek(&pFile->fd, BLOCK_OFFSET(i));
|
||||
}
|
||||
if( rc==SQLITE_OK && !skip ){
|
||||
int len = BLOCKSIZE;
|
||||
if( BLOCK_OFFSET(i+1)>nMax ){
|
||||
len = nMax-BLOCK_OFFSET(i);
|
||||
}
|
||||
if( len>0 ){
|
||||
if( trash ){
|
||||
sqlite3Randomness(len, p);
|
||||
}
|
||||
rc = sqlite3RealWrite(&pFile->fd, p, len);
|
||||
}
|
||||
}
|
||||
sqliteFree(p);
|
||||
}
|
||||
}
|
||||
sqliteFree(pFile->apBlk);
|
||||
pFile->nBlk = 0;
|
||||
pFile->apBlk = 0;
|
||||
pFile->nMaxWrite = 0;
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3RealSeek(&pFile->fd, offset);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write the cache to disk.
|
||||
*/
|
||||
static int writeCache(OsTestFile *pFile){
|
||||
if( pFile->apBlk ){
|
||||
int c = crashRequired(pFile->zName);
|
||||
if( c ){
|
||||
OsTestFile *p;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("\nCrash during sync of %s\n", pFile->zName);
|
||||
#endif
|
||||
for(p=pAllFiles; p; p=p->pNext){
|
||||
writeCache2(p, 1);
|
||||
}
|
||||
exit(-1);
|
||||
}else{
|
||||
return writeCache2(pFile, 0);
|
||||
}
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close the file.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile *id){
|
||||
if( !(*id) ) return SQLITE_OK;
|
||||
if( (*id)->fd.isOpen ){
|
||||
/* printf("CLOSE %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */
|
||||
writeCache(*id);
|
||||
sqlite3RealClose(&(*id)->fd);
|
||||
}
|
||||
closeFile(id);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
i64 offset; /* The current offset from the start of the file */
|
||||
i64 end; /* The byte just past the last byte read */
|
||||
int blk; /* Block number the read starts on */
|
||||
int i;
|
||||
u8 *zCsr;
|
||||
int rc = SQLITE_OK;
|
||||
OsTestFile *pFile = *id;
|
||||
|
||||
offset = osTell(pFile);
|
||||
end = offset+amt;
|
||||
blk = (offset/BLOCKSIZE);
|
||||
|
||||
zCsr = (u8 *)pBuf;
|
||||
for(i=blk; i*BLOCKSIZE<end; i++){
|
||||
int off = 0;
|
||||
int len = 0;
|
||||
|
||||
|
||||
if( BLOCK_OFFSET(i) < offset ){
|
||||
off = offset-BLOCK_OFFSET(i);
|
||||
}
|
||||
len = BLOCKSIZE - off;
|
||||
if( BLOCK_OFFSET(i+1) > end ){
|
||||
len = len - (BLOCK_OFFSET(i+1)-end);
|
||||
}
|
||||
|
||||
if( i<pFile->nBlk && pFile->apBlk[i]){
|
||||
u8 *pBlk = pFile->apBlk[i];
|
||||
memcpy(zCsr, &pBlk[off], len);
|
||||
}else{
|
||||
rc = sqlite3RealSeek(&pFile->fd, BLOCK_OFFSET(i) + off);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3RealRead(&pFile->fd, zCsr, len);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
|
||||
zCsr += len;
|
||||
}
|
||||
assert( zCsr==&((u8 *)pBuf)[amt] );
|
||||
|
||||
rc = sqlite3RealSeek(&pFile->fd, end);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
i64 offset; /* The current offset from the start of the file */
|
||||
i64 end; /* The byte just past the last byte written */
|
||||
int blk; /* Block number the write starts on */
|
||||
int i;
|
||||
const u8 *zCsr;
|
||||
int rc = SQLITE_OK;
|
||||
OsTestFile *pFile = *id;
|
||||
|
||||
offset = osTell(pFile);
|
||||
end = offset+amt;
|
||||
blk = (offset/BLOCKSIZE);
|
||||
|
||||
zCsr = (u8 *)pBuf;
|
||||
for(i=blk; i*BLOCKSIZE<end; i++){
|
||||
u8 *pBlk;
|
||||
int off = 0;
|
||||
int len = 0;
|
||||
|
||||
/* Make sure the block is in the cache */
|
||||
rc = cacheBlock(pFile, i);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
/* Write into the cache */
|
||||
pBlk = pFile->apBlk[i];
|
||||
assert( pBlk );
|
||||
|
||||
if( BLOCK_OFFSET(i) < offset ){
|
||||
off = offset-BLOCK_OFFSET(i);
|
||||
}
|
||||
len = BLOCKSIZE - off;
|
||||
if( BLOCK_OFFSET(i+1) > end ){
|
||||
len = len - (BLOCK_OFFSET(i+1)-end);
|
||||
}
|
||||
memcpy(&pBlk[off], zCsr, len);
|
||||
zCsr += len;
|
||||
}
|
||||
if( pFile->nMaxWrite<end ){
|
||||
pFile->nMaxWrite = end;
|
||||
}
|
||||
assert( zCsr==&((u8 *)pBuf)[amt] );
|
||||
|
||||
rc = sqlite3RealSeek(&pFile->fd, end);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sync the file. First flush the write-cache to disk, then call the
|
||||
** real sync() function.
|
||||
*/
|
||||
int sqlite3OsSync(OsFile *id, int dataOnly){
|
||||
int rc;
|
||||
/* printf("SYNC %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */
|
||||
rc = writeCache(*id);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3RealSync(&(*id)->fd, dataOnly);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate the file. Set the internal OsFile.nMaxWrite variable to the new
|
||||
** file size to ensure that nothing in the write-cache past this point
|
||||
** is written to disk.
|
||||
*/
|
||||
int sqlite3OsTruncate(OsFile *id, i64 nByte){
|
||||
(*id)->nMaxWrite = nByte;
|
||||
return sqlite3RealTruncate(&(*id)->fd, nByte);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the size of the file. If the cache contains a write that extended
|
||||
** the file, then return this size instead of the on-disk size.
|
||||
*/
|
||||
int sqlite3OsFileSize(OsFile *id, i64 *pSize){
|
||||
int rc = sqlite3RealFileSize(&(*id)->fd, pSize);
|
||||
if( rc==SQLITE_OK && pSize && *pSize<(*id)->nMaxWrite ){
|
||||
*pSize = (*id)->nMaxWrite;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** The three functions used to open files. All that is required is to
|
||||
** initialise the os_test.c specific fields and then call the corresponding
|
||||
** os_unix.c function to really open the file.
|
||||
*/
|
||||
int sqlite3OsOpenReadWrite(const char *zFilename, OsFile *id, int *pReadonly){
|
||||
initFile(id, zFilename);
|
||||
return sqlite3RealOpenReadWrite(zFilename, &(*id)->fd, pReadonly);
|
||||
}
|
||||
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
initFile(id, zFilename);
|
||||
return sqlite3RealOpenExclusive(zFilename, &(*id)->fd, delFlag);
|
||||
}
|
||||
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
|
||||
initFile(id, zFilename);
|
||||
return sqlite3RealOpenReadOnly(zFilename, &(*id)->fd);
|
||||
}
|
||||
|
||||
/*
|
||||
** These six function calls are passed straight through to the os_unix.c
|
||||
** backend.
|
||||
*/
|
||||
int sqlite3OsSeek(OsFile *id, i64 offset){
|
||||
return sqlite3RealSeek(&(*id)->fd, offset);
|
||||
}
|
||||
int sqlite3OsCheckReservedLock(OsFile *id){
|
||||
return sqlite3RealCheckReservedLock(&(*id)->fd);
|
||||
}
|
||||
int sqlite3OsLock(OsFile *id, int locktype){
|
||||
return sqlite3RealLock(&(*id)->fd, locktype);
|
||||
}
|
||||
int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
return sqlite3RealUnlock(&(*id)->fd, locktype);
|
||||
}
|
||||
int sqlite3OsOpenDirectory(const char *zDirname, OsFile *id){
|
||||
return sqlite3RealOpenDirectory(zDirname, &(*id)->fd);
|
||||
}
|
||||
|
||||
#endif /* OS_TEST */
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
** 2004 May 22
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
*/
|
||||
#ifndef _SQLITE_OS_TEST_H_
|
||||
#define _SQLITE_OS_TEST_H_
|
||||
|
||||
#define OsFile OsRealFile
|
||||
#define OS_UNIX 1
|
||||
#include "os_unix.h"
|
||||
#undef OS_UNIX
|
||||
#undef OsFile
|
||||
#undef SET_FULLSYNC
|
||||
|
||||
/* Include sqliteInt.h now to get the type u8. */
|
||||
#include "sqliteInt.h"
|
||||
|
||||
typedef struct OsTestFile* OsFile;
|
||||
typedef struct OsTestFile OsTestFile;
|
||||
struct OsTestFile {
|
||||
u8 **apBlk; /* Array of blocks that have been written to. */
|
||||
int nBlk; /* Size of apBlock. */
|
||||
int nMaxWrite; /* Largest offset written to. */
|
||||
char *zName; /* File name */
|
||||
OsRealFile fd;
|
||||
OsTestFile *pNext;
|
||||
};
|
||||
|
||||
void sqlite3SetCrashParams(int iDelay, char const *zFile);
|
||||
|
||||
#endif /* _SQLITE_OS_UNIX_H_ */
|
||||
+219
-590
File diff suppressed because it is too large
Load Diff
-116
@@ -1,116 +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>
|
||||
|
||||
/*
|
||||
** Macros used to determine whether or not to use threads. The
|
||||
** SQLITE_UNIX_THREADS macro is defined if we are synchronizing for
|
||||
** Posix threads and SQLITE_W32_THREADS is defined if we are
|
||||
** synchronizing using Win32 threads.
|
||||
*/
|
||||
#if defined(THREADSAFE) && THREADSAFE
|
||||
# include <pthread.h>
|
||||
# define SQLITE_UNIX_THREADS 1
|
||||
#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 Unix.
|
||||
**
|
||||
** OsFile.locktype takes one of the values SHARED_LOCK, RESERVED_LOCK,
|
||||
** PENDING_LOCK or EXCLUSIVE_LOCK.
|
||||
*/
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
struct Pager *pPager; /* The pager that owns this OsFile. Might be 0 */
|
||||
struct openCnt *pOpen; /* Info about all open fd's on this inode */
|
||||
struct lockInfo *pLock; /* Info about locks on this inode */
|
||||
int h; /* The file descriptor */
|
||||
unsigned char locktype; /* The type of lock held on this fd */
|
||||
unsigned char isOpen; /* True if needs to be closed */
|
||||
unsigned char fullSync; /* Use F_FULLSYNC if available */
|
||||
int dirfd; /* File descriptor for the directory */
|
||||
#ifdef SQLITE_UNIX_THREADS
|
||||
pthread_t tid; /* The thread authorized to use this OsFile */
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
** A macro to set the OsFile.fullSync flag, if it exists.
|
||||
*/
|
||||
#define SET_FULLSYNC(x,y) ((x).fullSync = (y))
|
||||
|
||||
/*
|
||||
** 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
|
||||
|
||||
/*
|
||||
** Default permissions when creating a new file
|
||||
*/
|
||||
#ifndef SQLITE_DEFAULT_FILE_PERMISSIONS
|
||||
# define SQLITE_DEFAULT_FILE_PERMISSIONS 0644
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _SQLITE_OS_UNIX_H_ */
|
||||
+127
-405
@@ -34,32 +34,6 @@
|
||||
*/
|
||||
#include "os_common.h"
|
||||
|
||||
/*
|
||||
** Determine if we are dealing with WindowsCE - which has a much
|
||||
** reduced API.
|
||||
*/
|
||||
#if defined(_WIN32_WCE)
|
||||
# define OS_WINCE 1
|
||||
#else
|
||||
# define OS_WINCE 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The winFile structure is a subclass of OsFile specific to the win32
|
||||
** portability layer.
|
||||
*/
|
||||
typedef struct winFile winFile;
|
||||
struct winFile {
|
||||
IoMethod const *pMethod;/* Must be first */
|
||||
HANDLE h; /* Handle for accessing the file */
|
||||
unsigned char locktype; /* Type of lock currently held on this file */
|
||||
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
|
||||
#if OS_WINCE
|
||||
WCHAR *zDeleteOnClose; /* Name of file to delete when closing */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** Do not include any of the File I/O interface procedures if the
|
||||
** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
|
||||
@@ -82,8 +56,8 @@ struct winFile {
|
||||
int sqlite3_os_type = 0;
|
||||
|
||||
/*
|
||||
** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
|
||||
** or WinCE. Return false (zero) for Win95, Win98, or WinME.
|
||||
** 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
|
||||
@@ -92,63 +66,15 @@ int sqlite3_os_type = 0;
|
||||
** WinNT/2K/XP so that we will know whether or not we can safely call
|
||||
** the LockFileEx() API.
|
||||
*/
|
||||
#if OS_WINCE
|
||||
# define isNT() (1)
|
||||
#else
|
||||
static int isNT(void){
|
||||
if( sqlite3_os_type==0 ){
|
||||
OSVERSIONINFO sInfo;
|
||||
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
|
||||
GetVersionEx(&sInfo);
|
||||
sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
|
||||
}
|
||||
return sqlite3_os_type==2;
|
||||
static int isNT(void){
|
||||
if( sqlite3_os_type==0 ){
|
||||
OSVERSIONINFO sInfo;
|
||||
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
|
||||
GetVersionEx(&sInfo);
|
||||
sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
|
||||
}
|
||||
#endif /* OS_WINCE */
|
||||
|
||||
#if OS_WINCE
|
||||
/*
|
||||
** WindowsCE does not have a localtime() function. So create a
|
||||
** substitute.
|
||||
*/
|
||||
#include <time.h>
|
||||
struct tm *__cdecl localtime(const time_t *t)
|
||||
{
|
||||
static struct tm y;
|
||||
FILETIME uTm, lTm;
|
||||
SYSTEMTIME pTm;
|
||||
i64 t64;
|
||||
t64 = *t;
|
||||
t64 = (t64 + 11644473600)*10000000;
|
||||
uTm.dwLowDateTime = t64 & 0xFFFFFFFF;
|
||||
uTm.dwHighDateTime= t64 >> 32;
|
||||
FileTimeToLocalFileTime(&uTm,&lTm);
|
||||
FileTimeToSystemTime(&lTm,&pTm);
|
||||
y.tm_year = pTm.wYear - 1900;
|
||||
y.tm_mon = pTm.wMonth - 1;
|
||||
y.tm_wday = pTm.wDayOfWeek;
|
||||
y.tm_mday = pTm.wDay;
|
||||
y.tm_hour = pTm.wHour;
|
||||
y.tm_min = pTm.wMinute;
|
||||
y.tm_sec = pTm.wSecond;
|
||||
return &y;
|
||||
return sqlite3_os_type==2;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Compile with -DSQLITE_OMIT_WIN_LOCKS to disable file locking on
|
||||
** windows. If you do this and two or more connections attempt to
|
||||
** write the database at the same time, the database file will be
|
||||
** corrupted. But some versions of WindowsCE do not support locking,
|
||||
** in which case compiling with this option is required just to get
|
||||
** it to work at all.
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_WIN_LOCKS
|
||||
# define LockFile(a,b,c,d,e) (1)
|
||||
# define LockFileEx(a,b,c,d,e,f) (1)
|
||||
# define UnlockFile(a,b,c,d,e) (1)
|
||||
# define UnlockFileEx(a,b,c,d,e) (1)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Convert a UTF-8 string to UTF-32. Space to hold the returned string
|
||||
@@ -200,17 +126,13 @@ static char *unicodeToUtf8(const WCHAR *zWideFilename){
|
||||
/*
|
||||
** Delete the named file
|
||||
*/
|
||||
int sqlite3WinDelete(const char *zFilename){
|
||||
int sqlite3OsDelete(const char *zFilename){
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
if( zWide ){
|
||||
DeleteFileW(zWide);
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
#if OS_WINCE
|
||||
return SQLITE_NOMEM;
|
||||
#else
|
||||
DeleteFileA(zFilename);
|
||||
#endif
|
||||
}
|
||||
TRACE2("DELETE \"%s\"\n", zFilename);
|
||||
return SQLITE_OK;
|
||||
@@ -219,25 +141,18 @@ int sqlite3WinDelete(const char *zFilename){
|
||||
/*
|
||||
** Return TRUE if the named file exists.
|
||||
*/
|
||||
int sqlite3WinFileExists(const char *zFilename){
|
||||
int sqlite3OsFileExists(const char *zFilename){
|
||||
int exists = 0;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
if( zWide ){
|
||||
exists = GetFileAttributesW(zWide) != 0xffffffff;
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
#if OS_WINCE
|
||||
return SQLITE_NOMEM;
|
||||
#else
|
||||
exists = GetFileAttributesA(zFilename) != 0xffffffff;
|
||||
#endif
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
|
||||
/* Forward declaration */
|
||||
int allocateWinFile(winFile *pInit, OsFile **pId);
|
||||
|
||||
/*
|
||||
** Attempt to open a file for both reading and writing. If that
|
||||
** fails, try opening it read-only. If the file does not exist,
|
||||
@@ -251,15 +166,14 @@ int allocateWinFile(winFile *pInit, OsFile **pId);
|
||||
** On failure, the function returns SQLITE_CANTOPEN and leaves
|
||||
** *id and *pReadonly unchanged.
|
||||
*/
|
||||
int sqlite3WinOpenReadWrite(
|
||||
int sqlite3OsOpenReadWrite(
|
||||
const char *zFilename,
|
||||
OsFile **pId,
|
||||
OsFile *id,
|
||||
int *pReadonly
|
||||
){
|
||||
winFile f;
|
||||
HANDLE h;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
assert( *pId==0 );
|
||||
assert( !id->isOpen );
|
||||
if( zWide ){
|
||||
h = CreateFileW(zWide,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
@@ -288,9 +202,6 @@ int sqlite3WinOpenReadWrite(
|
||||
}
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
#if OS_WINCE
|
||||
return SQLITE_NOMEM;
|
||||
#else
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
@@ -315,16 +226,14 @@ int sqlite3WinOpenReadWrite(
|
||||
}else{
|
||||
*pReadonly = 0;
|
||||
}
|
||||
#endif /* OS_WINCE */
|
||||
}
|
||||
f.h = h;
|
||||
f.locktype = NO_LOCK;
|
||||
f.sharedLockByte = 0;
|
||||
#if OS_WINCE
|
||||
f.zDeleteOnClose = 0;
|
||||
#endif
|
||||
id->h = h;
|
||||
id->locktype = NO_LOCK;
|
||||
id->sharedLockByte = 0;
|
||||
id->isOpen = 1;
|
||||
OpenCounter(+1);
|
||||
TRACE3("OPEN R/W %d \"%s\"\n", h, zFilename);
|
||||
return allocateWinFile(&f, pId);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -342,18 +251,17 @@ int sqlite3WinOpenReadWrite(
|
||||
**
|
||||
** On failure, return SQLITE_CANTOPEN.
|
||||
*/
|
||||
int sqlite3WinOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
|
||||
winFile f;
|
||||
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
HANDLE h;
|
||||
int fileflags;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
assert( *pId == 0 );
|
||||
fileflags = FILE_FLAG_RANDOM_ACCESS;
|
||||
#if !OS_WINCE
|
||||
assert( !id->isOpen );
|
||||
if( delFlag ){
|
||||
fileflags |= FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE;
|
||||
fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS
|
||||
| FILE_FLAG_DELETE_ON_CLOSE;
|
||||
}else{
|
||||
fileflags = FILE_FLAG_RANDOM_ACCESS;
|
||||
}
|
||||
#endif
|
||||
if( zWide ){
|
||||
h = CreateFileW(zWide,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
@@ -365,9 +273,6 @@ int sqlite3WinOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
|
||||
);
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
#if OS_WINCE
|
||||
return SQLITE_NOMEM;
|
||||
#else
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
@@ -376,19 +281,17 @@ int sqlite3WinOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
|
||||
fileflags,
|
||||
NULL
|
||||
);
|
||||
#endif /* OS_WINCE */
|
||||
}
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
f.h = h;
|
||||
f.locktype = NO_LOCK;
|
||||
f.sharedLockByte = 0;
|
||||
#if OS_WINCE
|
||||
f.zDeleteOnClose = delFlag ? utf8ToUnicode(zFilename) : 0;
|
||||
#endif
|
||||
id->h = h;
|
||||
id->locktype = NO_LOCK;
|
||||
id->sharedLockByte = 0;
|
||||
id->isOpen = 1;
|
||||
OpenCounter(+1);
|
||||
TRACE3("OPEN EX %d \"%s\"\n", h, zFilename);
|
||||
return allocateWinFile(&f, pId);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -398,11 +301,10 @@ int sqlite3WinOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
|
||||
**
|
||||
** On failure, return SQLITE_CANTOPEN.
|
||||
*/
|
||||
int sqlite3WinOpenReadOnly(const char *zFilename, OsFile **pId){
|
||||
winFile f;
|
||||
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
|
||||
HANDLE h;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
assert( *pId==0 );
|
||||
assert( !id->isOpen );
|
||||
if( zWide ){
|
||||
h = CreateFileW(zWide,
|
||||
GENERIC_READ,
|
||||
@@ -414,9 +316,6 @@ int sqlite3WinOpenReadOnly(const char *zFilename, OsFile **pId){
|
||||
);
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
#if OS_WINCE
|
||||
return SQLITE_NOMEM;
|
||||
#else
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ,
|
||||
0,
|
||||
@@ -425,19 +324,17 @@ int sqlite3WinOpenReadOnly(const char *zFilename, OsFile **pId){
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
#endif
|
||||
}
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
f.h = h;
|
||||
f.locktype = NO_LOCK;
|
||||
f.sharedLockByte = 0;
|
||||
#if OS_WINCE
|
||||
f.zDeleteOnClose = 0;
|
||||
#endif
|
||||
id->h = h;
|
||||
id->locktype = NO_LOCK;
|
||||
id->sharedLockByte = 0;
|
||||
id->isOpen = 1;
|
||||
OpenCounter(+1);
|
||||
TRACE3("OPEN RO %d \"%s\"\n", h, zFilename);
|
||||
return allocateWinFile(&f, pId);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -456,9 +353,9 @@ int sqlite3WinOpenReadOnly(const char *zFilename, OsFile **pId){
|
||||
** On failure, the function returns SQLITE_CANTOPEN and leaves
|
||||
** *id unchanged.
|
||||
*/
|
||||
static int winOpenDirectory(
|
||||
OsFile *id,
|
||||
const char *zDirname
|
||||
int sqlite3OsOpenDirectory(
|
||||
const char *zDirname,
|
||||
OsFile *id
|
||||
){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -474,7 +371,7 @@ char *sqlite3_temp_directory = 0;
|
||||
** Create a temporary file name in zBuf. zBuf must be big enough to
|
||||
** hold at least SQLITE_TEMPNAME_SIZE characters.
|
||||
*/
|
||||
int sqlite3WinTempFileName(char *zBuf){
|
||||
int sqlite3OsTempFileName(char *zBuf){
|
||||
static char zChars[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
@@ -516,20 +413,12 @@ int sqlite3WinTempFileName(char *zBuf){
|
||||
/*
|
||||
** Close a file.
|
||||
*/
|
||||
static int winClose(OsFile **pId){
|
||||
winFile *pFile;
|
||||
if( pId && (pFile = (winFile*)*pId)!=0 ){
|
||||
TRACE2("CLOSE %d\n", pFile->h);
|
||||
CloseHandle(pFile->h);
|
||||
#if OS_WINCE
|
||||
if( pFile->zDeleteOnClose ){
|
||||
DeleteFileW(pFile->zDeleteOnClose);
|
||||
sqliteFree(pFile->zDeleteOnClose);
|
||||
}
|
||||
#endif
|
||||
int sqlite3OsClose(OsFile *id){
|
||||
if( id->isOpen ){
|
||||
TRACE2("CLOSE %d\n", id->h);
|
||||
CloseHandle(id->h);
|
||||
OpenCounter(-1);
|
||||
sqliteFree(pFile);
|
||||
*pId = 0;
|
||||
id->isOpen = 0;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -539,12 +428,12 @@ static int winClose(OsFile **pId){
|
||||
** bytes were read successfully and SQLITE_IOERR if anything goes
|
||||
** wrong.
|
||||
*/
|
||||
static int winRead(OsFile *id, void *pBuf, int amt){
|
||||
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
DWORD got;
|
||||
assert( id!=0 );
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
TRACE3("READ %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype);
|
||||
if( !ReadFile(((winFile*)id)->h, pBuf, amt, &got, 0) ){
|
||||
TRACE3("READ %d lock=%d\n", id->h, id->locktype);
|
||||
if( !ReadFile(id->h, pBuf, amt, &got, 0) ){
|
||||
got = 0;
|
||||
}
|
||||
if( got==(DWORD)amt ){
|
||||
@@ -558,16 +447,15 @@ static int winRead(OsFile *id, void *pBuf, int amt){
|
||||
** Write data from a buffer into a file. Return SQLITE_OK on success
|
||||
** or some other error code on failure.
|
||||
*/
|
||||
static int winWrite(OsFile *id, const void *pBuf, int amt){
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
int rc = 0;
|
||||
DWORD wrote;
|
||||
assert( id!=0 );
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
SimulateDiskfullError;
|
||||
TRACE3("WRITE %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype);
|
||||
TRACE3("WRITE %d lock=%d\n", id->h, id->locktype);
|
||||
assert( amt>0 );
|
||||
while( amt>0 && (rc = WriteFile(((winFile*)id)->h, pBuf, amt, &wrote, 0))!=0
|
||||
&& wrote>0 ){
|
||||
while( amt>0 && (rc = WriteFile(id->h, pBuf, amt, &wrote, 0))!=0 && wrote>0 ){
|
||||
amt -= wrote;
|
||||
pBuf = &((char*)pBuf)[wrote];
|
||||
}
|
||||
@@ -587,17 +475,17 @@ static int winWrite(OsFile *id, const void *pBuf, int amt){
|
||||
/*
|
||||
** Move the read/write pointer in a file.
|
||||
*/
|
||||
static int winSeek(OsFile *id, i64 offset){
|
||||
int sqlite3OsSeek(OsFile *id, i64 offset){
|
||||
LONG upperBits = offset>>32;
|
||||
LONG lowerBits = offset & 0xffffffff;
|
||||
DWORD rc;
|
||||
assert( id!=0 );
|
||||
assert( id->isOpen );
|
||||
#ifdef SQLITE_TEST
|
||||
if( offset ) SimulateDiskfullError
|
||||
#endif
|
||||
SEEK(offset/1024 + 1);
|
||||
rc = SetFilePointer(((winFile*)id)->h, lowerBits, &upperBits, FILE_BEGIN);
|
||||
TRACE3("SEEK %d %lld\n", ((winFile*)id)->h, offset);
|
||||
rc = SetFilePointer(id->h, lowerBits, &upperBits, FILE_BEGIN);
|
||||
TRACE3("SEEK %d %lld\n", id->h, offset);
|
||||
if( rc==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR ){
|
||||
return SQLITE_FULL;
|
||||
}
|
||||
@@ -607,10 +495,10 @@ static int winSeek(OsFile *id, i64 offset){
|
||||
/*
|
||||
** Make sure all writes to a particular file are committed to disk.
|
||||
*/
|
||||
static int winSync(OsFile *id, int dataOnly){
|
||||
assert( id!=0 );
|
||||
TRACE3("SYNC %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype);
|
||||
if( FlushFileBuffers(((winFile*)id)->h) ){
|
||||
int sqlite3OsSync(OsFile *id, int dataOnly){
|
||||
assert( id->isOpen );
|
||||
TRACE3("SYNC %d lock=%d\n", id->h, id->locktype);
|
||||
if( FlushFileBuffers(id->h) ){
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
return SQLITE_IOERR;
|
||||
@@ -621,7 +509,7 @@ static int winSync(OsFile *id, int dataOnly){
|
||||
** Sync the directory zDirname. This is a no-op on operating systems other
|
||||
** than UNIX.
|
||||
*/
|
||||
int sqlite3WinSyncDirectory(const char *zDirname){
|
||||
int sqlite3OsSyncDirectory(const char *zDirname){
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -629,41 +517,34 @@ int sqlite3WinSyncDirectory(const char *zDirname){
|
||||
/*
|
||||
** Truncate an open file to a specified size
|
||||
*/
|
||||
static int winTruncate(OsFile *id, i64 nByte){
|
||||
int sqlite3OsTruncate(OsFile *id, i64 nByte){
|
||||
LONG upperBits = nByte>>32;
|
||||
assert( id!=0 );
|
||||
TRACE3("TRUNCATE %d %lld\n", ((winFile*)id)->h, nByte);
|
||||
assert( id->isOpen );
|
||||
TRACE3("TRUNCATE %d %lld\n", id->h, nByte);
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
SetFilePointer(((winFile*)id)->h, nByte, &upperBits, FILE_BEGIN);
|
||||
SetEndOfFile(((winFile*)id)->h);
|
||||
SetFilePointer(id->h, nByte, &upperBits, FILE_BEGIN);
|
||||
SetEndOfFile(id->h);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Determine the current size of a file in bytes
|
||||
*/
|
||||
static int winFileSize(OsFile *id, i64 *pSize){
|
||||
int sqlite3OsFileSize(OsFile *id, i64 *pSize){
|
||||
DWORD upperBits, lowerBits;
|
||||
assert( id!=0 );
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
lowerBits = GetFileSize(((winFile*)id)->h, &upperBits);
|
||||
lowerBits = GetFileSize(id->h, &upperBits);
|
||||
*pSize = (((i64)upperBits)<<32) + lowerBits;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems.
|
||||
*/
|
||||
#ifndef LOCKFILE_FAIL_IMMEDIATELY
|
||||
# define LOCKFILE_FAIL_IMMEDIATELY 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Acquire a reader lock.
|
||||
** Different API routines are called depending on whether or not this
|
||||
** is Win95 or WinNT.
|
||||
*/
|
||||
static int getReadLock(winFile *id){
|
||||
static int getReadLock(OsFile *id){
|
||||
int res;
|
||||
if( isNT() ){
|
||||
OVERLAPPED ovlp;
|
||||
@@ -683,12 +564,12 @@ static int getReadLock(winFile *id){
|
||||
/*
|
||||
** Undo a readlock
|
||||
*/
|
||||
static int unlockReadLock(winFile *pFile){
|
||||
static int unlockReadLock(OsFile *id){
|
||||
int res;
|
||||
if( isNT() ){
|
||||
res = UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
res = UnlockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
}else{
|
||||
res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
|
||||
res = UnlockFile(id->h, SHARED_FIRST + id->sharedLockByte, 0, 1, 0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -698,7 +579,7 @@ static int unlockReadLock(winFile *pFile){
|
||||
** Check that a given pathname is a directory and is writable
|
||||
**
|
||||
*/
|
||||
int sqlite3WinIsDirWritable(char *zDirname){
|
||||
int sqlite3OsIsDirWritable(char *zDirname){
|
||||
int fileAttr;
|
||||
WCHAR *zWide;
|
||||
if( zDirname==0 ) return 0;
|
||||
@@ -708,11 +589,7 @@ int sqlite3WinIsDirWritable(char *zDirname){
|
||||
fileAttr = GetFileAttributesW(zWide);
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
#if OS_WINCE
|
||||
return 0;
|
||||
#else
|
||||
fileAttr = GetFileAttributesA(zDirname);
|
||||
#endif
|
||||
}
|
||||
if( fileAttr == 0xffffffff ) return 0;
|
||||
if( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ){
|
||||
@@ -743,46 +620,45 @@ int sqlite3WinIsDirWritable(char *zDirname){
|
||||
** RESERVED -> (PENDING) -> EXCLUSIVE
|
||||
** PENDING -> EXCLUSIVE
|
||||
**
|
||||
** This routine will only increase a lock. The winUnlock() routine
|
||||
** 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.
|
||||
*/
|
||||
static int winLock(OsFile *id, int locktype){
|
||||
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 */
|
||||
winFile *pFile = (winFile*)id;
|
||||
|
||||
assert( pFile!=0 );
|
||||
assert( id->isOpen );
|
||||
TRACE5("LOCK %d %d was %d(%d)\n",
|
||||
pFile->h, locktype, pFile->locktype, pFile->sharedLockByte);
|
||||
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( pFile->locktype>=locktype ){
|
||||
if( id->locktype>=locktype ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* Make sure the locking sequence is correct
|
||||
*/
|
||||
assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK );
|
||||
assert( id->locktype!=NO_LOCK || locktype==SHARED_LOCK );
|
||||
assert( locktype!=PENDING_LOCK );
|
||||
assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_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 = pFile->locktype;
|
||||
if( pFile->locktype==NO_LOCK
|
||||
|| (locktype==EXCLUSIVE_LOCK && pFile->locktype==RESERVED_LOCK)
|
||||
newLocktype = id->locktype;
|
||||
if( id->locktype==NO_LOCK
|
||||
|| (locktype==EXCLUSIVE_LOCK && id->locktype==RESERVED_LOCK)
|
||||
){
|
||||
int cnt = 3;
|
||||
while( cnt-->0 && (res = LockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
|
||||
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.
|
||||
*/
|
||||
@@ -795,8 +671,8 @@ static int winLock(OsFile *id, int locktype){
|
||||
/* Acquire a shared lock
|
||||
*/
|
||||
if( locktype==SHARED_LOCK && res ){
|
||||
assert( pFile->locktype==NO_LOCK );
|
||||
res = getReadLock(pFile);
|
||||
assert( id->locktype==NO_LOCK );
|
||||
res = getReadLock(id);
|
||||
if( res ){
|
||||
newLocktype = SHARED_LOCK;
|
||||
}
|
||||
@@ -805,8 +681,8 @@ static int winLock(OsFile *id, int locktype){
|
||||
/* Acquire a RESERVED lock
|
||||
*/
|
||||
if( locktype==RESERVED_LOCK && res ){
|
||||
assert( pFile->locktype==SHARED_LOCK );
|
||||
res = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
||||
assert( id->locktype==SHARED_LOCK );
|
||||
res = LockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
if( res ){
|
||||
newLocktype = RESERVED_LOCK;
|
||||
}
|
||||
@@ -822,10 +698,10 @@ static int winLock(OsFile *id, int locktype){
|
||||
/* Acquire an EXCLUSIVE lock
|
||||
*/
|
||||
if( locktype==EXCLUSIVE_LOCK && res ){
|
||||
assert( pFile->locktype>=SHARED_LOCK );
|
||||
res = unlockReadLock(pFile);
|
||||
assert( id->locktype>=SHARED_LOCK );
|
||||
res = unlockReadLock(id);
|
||||
TRACE2("unreadlock = %d\n", res);
|
||||
res = LockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
res = LockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
if( res ){
|
||||
newLocktype = EXCLUSIVE_LOCK;
|
||||
}else{
|
||||
@@ -837,7 +713,7 @@ static int winLock(OsFile *id, int locktype){
|
||||
** release it now.
|
||||
*/
|
||||
if( gotPendingLock && locktype==SHARED_LOCK ){
|
||||
UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
|
||||
UnlockFile(id->h, PENDING_BYTE, 0, 1, 0);
|
||||
}
|
||||
|
||||
/* Update the state of the lock has held in the file descriptor then
|
||||
@@ -846,11 +722,11 @@ static int winLock(OsFile *id, int locktype){
|
||||
if( res ){
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
TRACE4("LOCK FAILED %d trying for %d but got %d\n", pFile->h,
|
||||
TRACE4("LOCK FAILED %d trying for %d but got %d\n", id->h,
|
||||
locktype, newLocktype);
|
||||
rc = SQLITE_BUSY;
|
||||
}
|
||||
pFile->locktype = newLocktype;
|
||||
id->locktype = newLocktype;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -859,20 +735,19 @@ static int winLock(OsFile *id, int locktype){
|
||||
** file by this or any other process. If such a lock is held, return
|
||||
** non-zero, otherwise zero.
|
||||
*/
|
||||
static int winCheckReservedLock(OsFile *id){
|
||||
int sqlite3OsCheckReservedLock(OsFile *id){
|
||||
int rc;
|
||||
winFile *pFile = (winFile*)id;
|
||||
assert( pFile!=0 );
|
||||
if( pFile->locktype>=RESERVED_LOCK ){
|
||||
assert( id->isOpen );
|
||||
if( id->locktype>=RESERVED_LOCK ){
|
||||
rc = 1;
|
||||
TRACE3("TEST WR-LOCK %d %d (local)\n", pFile->h, rc);
|
||||
TRACE3("TEST WR-LOCK %d %d (local)\n", id->h, rc);
|
||||
}else{
|
||||
rc = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
||||
rc = LockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
if( rc ){
|
||||
UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
||||
UnlockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
}
|
||||
rc = !rc;
|
||||
TRACE3("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc);
|
||||
TRACE3("TEST WR-LOCK %d %d (remote)\n", id->h, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -888,33 +763,32 @@ static int winCheckReservedLock(OsFile *id){
|
||||
** is NO_LOCK. If the second argument is SHARED_LOCK then this routine
|
||||
** might return SQLITE_IOERR;
|
||||
*/
|
||||
static int winUnlock(OsFile *id, int locktype){
|
||||
int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
int type;
|
||||
int rc = SQLITE_OK;
|
||||
winFile *pFile = (winFile*)id;
|
||||
assert( pFile!=0 );
|
||||
assert( id->isOpen );
|
||||
assert( locktype<=SHARED_LOCK );
|
||||
TRACE5("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype,
|
||||
pFile->locktype, pFile->sharedLockByte);
|
||||
type = pFile->locktype;
|
||||
TRACE5("UNLOCK %d to %d was %d(%d)\n", id->h, locktype,
|
||||
id->locktype, id->sharedLockByte);
|
||||
type = id->locktype;
|
||||
if( type>=EXCLUSIVE_LOCK ){
|
||||
UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
|
||||
UnlockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
if( locktype==SHARED_LOCK && !getReadLock(id) ){
|
||||
/* This should never happen. We should always be able to
|
||||
** reacquire the read lock */
|
||||
rc = SQLITE_IOERR;
|
||||
}
|
||||
}
|
||||
if( type>=RESERVED_LOCK ){
|
||||
UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
||||
UnlockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
}
|
||||
if( locktype==NO_LOCK && type>=SHARED_LOCK ){
|
||||
unlockReadLock(pFile);
|
||||
unlockReadLock(id);
|
||||
}
|
||||
if( type>=PENDING_LOCK ){
|
||||
UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
|
||||
UnlockFile(id->h, PENDING_BYTE, 0, 1, 0);
|
||||
}
|
||||
pFile->locktype = locktype;
|
||||
id->locktype = locktype;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -924,21 +798,17 @@ static int winUnlock(OsFile *id, int locktype){
|
||||
** The calling function is responsible for freeing this space once it
|
||||
** is no longer needed.
|
||||
*/
|
||||
char *sqlite3WinFullPathname(const char *zRelative){
|
||||
char *sqlite3OsFullPathname(const char *zRelative){
|
||||
char *zNotUsed;
|
||||
char *zFull;
|
||||
#if defined(__CYGWIN__)
|
||||
WCHAR *zWide;
|
||||
int nByte;
|
||||
#ifdef __CYGWIN__
|
||||
nByte = strlen(zRelative) + MAX_PATH + 1001;
|
||||
zFull = sqliteMalloc( nByte );
|
||||
if( zFull==0 ) return 0;
|
||||
if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0;
|
||||
#elif OS_WINCE
|
||||
/* WinCE has no concept of a relative pathname, or so I am told. */
|
||||
zFull = sqliteStrDup(zRelative);
|
||||
#else
|
||||
char *zNotUsed;
|
||||
WCHAR *zWide;
|
||||
int nByte;
|
||||
zWide = utf8ToUnicode(zRelative);
|
||||
if( zWide ){
|
||||
WCHAR *zTemp, *zNotUsedW;
|
||||
@@ -959,73 +829,6 @@ char *sqlite3WinFullPathname(const char *zRelative){
|
||||
return zFull;
|
||||
}
|
||||
|
||||
/*
|
||||
** The fullSync option is meaningless on windows. This is a no-op.
|
||||
*/
|
||||
static void winSetFullSync(OsFile *id, int v){
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the underlying file handle for an OsFile
|
||||
*/
|
||||
static int winFileHandle(OsFile *id){
|
||||
return (int)((winFile*)id)->h;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return an integer that indices the type of lock currently held
|
||||
** by this handle. (Used for testing and analysis only.)
|
||||
*/
|
||||
static int winLockState(OsFile *id){
|
||||
return ((winFile*)id)->locktype;
|
||||
}
|
||||
|
||||
/*
|
||||
** This vector defines all the methods that can operate on an OsFile
|
||||
** for win32.
|
||||
*/
|
||||
static const IoMethod sqlite3WinIoMethod = {
|
||||
winClose,
|
||||
winOpenDirectory,
|
||||
winRead,
|
||||
winWrite,
|
||||
winSeek,
|
||||
winTruncate,
|
||||
winSync,
|
||||
winSetFullSync,
|
||||
winFileHandle,
|
||||
winFileSize,
|
||||
winLock,
|
||||
winUnlock,
|
||||
winLockState,
|
||||
winCheckReservedLock,
|
||||
};
|
||||
|
||||
/*
|
||||
** Allocate memory for an OsFile. Initialize the new OsFile
|
||||
** to the value given in pInit and return a pointer to the new
|
||||
** OsFile. If we run out of memory, close the file and return NULL.
|
||||
*/
|
||||
int allocateWinFile(winFile *pInit, OsFile **pId){
|
||||
winFile *pNew;
|
||||
pNew = sqliteMalloc( sizeof(*pNew) );
|
||||
if( pNew==0 ){
|
||||
CloseHandle(pInit->h);
|
||||
#if OS_WINCE
|
||||
sqliteFree(pInit->zDeleteOnClose);
|
||||
#endif
|
||||
*pId = 0;
|
||||
return SQLITE_NOMEM;
|
||||
}else{
|
||||
*pNew = *pInit;
|
||||
pNew->pMethod = &sqlite3WinIoMethod;
|
||||
*pId = (OsFile*)pNew;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* SQLITE_OMIT_DISKIO */
|
||||
/***************************************************************************
|
||||
** Everything above deals with file I/O. Everything that follows deals
|
||||
@@ -1037,7 +840,7 @@ int allocateWinFile(winFile *pInit, OsFile **pId){
|
||||
** is written into the buffer zBuf[256]. The calling function must
|
||||
** supply a sufficiently large buffer.
|
||||
*/
|
||||
int sqlite3WinRandomSeed(char *zBuf){
|
||||
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
|
||||
@@ -1058,7 +861,7 @@ int sqlite3WinRandomSeed(char *zBuf){
|
||||
/*
|
||||
** Sleep for a little while. Return the amount of time slept.
|
||||
*/
|
||||
int sqlite3WinSleep(int ms){
|
||||
int sqlite3OsSleep(int ms){
|
||||
Sleep(ms);
|
||||
return ms;
|
||||
}
|
||||
@@ -1079,7 +882,7 @@ static int inMutex = 0;
|
||||
** SQLite uses only a single Mutex. There is not much critical
|
||||
** code and what little there is executes quickly and without blocking.
|
||||
*/
|
||||
void sqlite3WinEnterMutex(){
|
||||
void sqlite3OsEnterMutex(){
|
||||
#ifdef SQLITE_W32_THREADS
|
||||
static int isInit = 0;
|
||||
while( !isInit ){
|
||||
@@ -1096,7 +899,7 @@ void sqlite3WinEnterMutex(){
|
||||
assert( !inMutex );
|
||||
inMutex = 1;
|
||||
}
|
||||
void sqlite3WinLeaveMutex(){
|
||||
void sqlite3OsLeaveMutex(){
|
||||
assert( inMutex );
|
||||
inMutex = 0;
|
||||
#ifdef SQLITE_W32_THREADS
|
||||
@@ -1104,14 +907,6 @@ void sqlite3WinLeaveMutex(){
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Return TRUE if we are currently within the mutex and FALSE if not.
|
||||
*/
|
||||
int sqlite3WinInMutex(){
|
||||
return inMutex;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** The following variable, if set to a non-zero value, becomes the result
|
||||
** returned from sqlite3OsCurrentTime(). This is used for testing.
|
||||
@@ -1125,19 +920,13 @@ int sqlite3_current_time = 0;
|
||||
** 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 sqlite3WinCurrentTime(double *prNow){
|
||||
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;
|
||||
#if OS_WINCE
|
||||
SYSTEMTIME time;
|
||||
GetSystemTime(&time);
|
||||
SystemTimeToFileTime(&time,&ft);
|
||||
#else
|
||||
GetSystemTimeAsFileTime( &ft );
|
||||
#endif
|
||||
now = ((double)ft.dwHighDateTime) * 4294967296.0;
|
||||
*prNow = (now + ft.dwLowDateTime)/864000000000.0 + 2305813.5;
|
||||
#ifdef SQLITE_TEST
|
||||
@@ -1148,71 +937,4 @@ int sqlite3WinCurrentTime(double *prNow){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Remember the number of thread-specific-data blocks allocated.
|
||||
** Use this to verify that we are not leaking thread-specific-data.
|
||||
** Ticket #1601
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_tsd_count = 0;
|
||||
# define TSD_COUNTER_INCR InterlockedIncrement(&sqlite3_tsd_count)
|
||||
# define TSD_COUNTER_DECR InterlockedDecrement(&sqlite3_tsd_count)
|
||||
#else
|
||||
# define TSD_COUNTER_INCR /* no-op */
|
||||
# define TSD_COUNTER_DECR /* no-op */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** If called with allocateFlag>1, then return a pointer to thread
|
||||
** specific data for the current thread. Allocate and zero the
|
||||
** thread-specific data if it does not already exist necessary.
|
||||
**
|
||||
** If called with allocateFlag==0, then check the current thread
|
||||
** specific data. Return it if it exists. If it does not exist,
|
||||
** then return NULL.
|
||||
**
|
||||
** If called with allocateFlag<0, check to see if the thread specific
|
||||
** data is allocated and is all zero. If it is then deallocate it.
|
||||
** Return a pointer to the thread specific data or NULL if it is
|
||||
** unallocated or gets deallocated.
|
||||
*/
|
||||
ThreadData *sqlite3WinThreadSpecificData(int allocateFlag){
|
||||
static int key;
|
||||
static int keyInit = 0;
|
||||
static const ThreadData zeroData;
|
||||
ThreadData *pTsd;
|
||||
|
||||
if( !keyInit ){
|
||||
sqlite3OsEnterMutex();
|
||||
if( !keyInit ){
|
||||
key = TlsAlloc();
|
||||
if( key==0xffffffff ){
|
||||
sqlite3OsLeaveMutex();
|
||||
return 0;
|
||||
}
|
||||
keyInit = 1;
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
pTsd = TlsGetValue(key);
|
||||
if( allocateFlag>0 ){
|
||||
if( !pTsd ){
|
||||
pTsd = sqlite3OsMalloc( sizeof(zeroData) );
|
||||
if( pTsd ){
|
||||
*pTsd = zeroData;
|
||||
TlsSetValue(key, pTsd);
|
||||
TSD_COUNTER_INCR;
|
||||
}
|
||||
}
|
||||
}else if( pTsd!=0 && allocateFlag<0
|
||||
&& memcmp(pTsd, &zeroData, sizeof(zeroData))==0 ){
|
||||
sqlite3OsFree(pTsd);
|
||||
TlsSetValue(key, 0);
|
||||
TSD_COUNTER_DECR;
|
||||
pTsd = 0;
|
||||
}
|
||||
return pTsd;
|
||||
}
|
||||
#endif /* OS_WIN */
|
||||
|
||||
@@ -1,40 +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>
|
||||
|
||||
/*
|
||||
** The OsFile structure is a operating-system independing representation
|
||||
** of an open file handle. It is defined differently for each architecture.
|
||||
**
|
||||
** This is the definition for Win32.
|
||||
*/
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
HANDLE h; /* Handle for accessing the file */
|
||||
unsigned char locktype; /* Type of lock currently held on this file */
|
||||
unsigned char isOpen; /* True if needs to be closed */
|
||||
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
|
||||
};
|
||||
|
||||
|
||||
#define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
|
||||
#define SQLITE_MIN_SLEEP_MS 1
|
||||
|
||||
|
||||
#endif /* _SQLITE_OS_WIN_H_ */
|
||||
+277
-476
File diff suppressed because it is too large
Load Diff
+1
-7
@@ -13,12 +13,9 @@
|
||||
** 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.48 2005/12/19 14:18:11 danielk1977 Exp $
|
||||
** @(#) $Id: pager.h,v 1.46 2005/09/19 19:05:21 drh Exp $
|
||||
*/
|
||||
|
||||
#ifndef _PAGER_H_
|
||||
#define _PAGER_H_
|
||||
|
||||
/*
|
||||
** The default size of a database page.
|
||||
*/
|
||||
@@ -108,7 +105,6 @@ int sqlite3pager_rename(Pager*, const char *zNewName);
|
||||
void sqlite3pager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);
|
||||
int sqlite3pager_movepage(Pager*,void*,Pgno);
|
||||
int sqlite3pager_reset(Pager*);
|
||||
int sqlite3pager_release_memory(int);
|
||||
|
||||
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
|
||||
int sqlite3pager_lockstate(Pager*);
|
||||
@@ -118,5 +114,3 @@ int sqlite3pager_lockstate(Pager*);
|
||||
void sqlite3pager_refdump(Pager*);
|
||||
int pager3_refinfo_enable;
|
||||
#endif
|
||||
|
||||
#endif /* _PAGER_H_ */
|
||||
|
||||
+84
-66
@@ -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.192 2006/01/07 14:02:27 danielk1977 Exp $
|
||||
** @(#) $Id: parse.y,v 1.180 2005/09/16 02:38:10 drh Exp $
|
||||
*/
|
||||
|
||||
// All token codes are small integers with #defines that begin with "TK_"
|
||||
@@ -88,6 +88,13 @@ struct AttachKey { int type; Token key; };
|
||||
|
||||
} // end %include
|
||||
|
||||
// These are extra tokens used by the lexer but never seen by the
|
||||
// parser. We put them in a rule so that the parser generator will
|
||||
// add them to the parse.h output file.
|
||||
//
|
||||
%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
|
||||
COLUMN AGG_FUNCTION AGG_COLUMN CONST_FUNC.
|
||||
|
||||
// Input is a single SQL command
|
||||
input ::= cmdlist.
|
||||
cmdlist ::= cmdlist ecmd.
|
||||
@@ -120,12 +127,9 @@ cmd ::= ROLLBACK trans_opt. {sqlite3RollbackTransaction(pParse);}
|
||||
///////////////////// The CREATE TABLE statement ////////////////////////////
|
||||
//
|
||||
cmd ::= create_table create_table_args.
|
||||
create_table ::= CREATE(X) temp(T) TABLE ifnotexists(E) nm(Y) dbnm(Z). {
|
||||
sqlite3StartTable(pParse,&X,&Y,&Z,T,0,E);
|
||||
create_table ::= CREATE(X) temp(T) TABLE nm(Y) dbnm(Z). {
|
||||
sqlite3StartTable(pParse,&X,&Y,&Z,T,0);
|
||||
}
|
||||
%type ifnotexists {int}
|
||||
ifnotexists(A) ::= . {A = 0;}
|
||||
ifnotexists(A) ::= IF NOT EXISTS. {A = 1;}
|
||||
%type temp {int}
|
||||
%ifndef SQLITE_OMIT_TEMPDB
|
||||
temp(A) ::= TEMP. {A = 1;}
|
||||
@@ -175,7 +179,7 @@ id(A) ::= ID(X). {A = X;}
|
||||
%ifdef SQLITE_OMIT_COMPOUND_SELECT
|
||||
EXCEPT INTERSECT UNION
|
||||
%endif
|
||||
REINDEX RENAME CTIME_KW IF
|
||||
REINDEX RENAME CTIME_KW ALTER
|
||||
.
|
||||
|
||||
// Define operator precedence early so that this is the first occurance
|
||||
@@ -204,7 +208,8 @@ id(A) ::= ID(X). {A = X;}
|
||||
// And "ids" is an identifer-or-string.
|
||||
//
|
||||
%type ids {Token}
|
||||
ids(A) ::= ID|STRING(X). {A = X;}
|
||||
ids(A) ::= ID(X). {A = X;}
|
||||
ids(A) ::= STRING(X). {A = X;}
|
||||
|
||||
// The name of a column or table can be any of the following:
|
||||
//
|
||||
@@ -233,8 +238,8 @@ typetoken(A) ::= typename(X) LP signed COMMA signed RP(Y). {
|
||||
typename(A) ::= ids(X). {A = X;}
|
||||
typename(A) ::= typename(X) ids(Y). {A.z=X.z; A.n=Y.n+(Y.z-X.z);}
|
||||
%type signed {int}
|
||||
signed(A) ::= plus_num(X). { A = atoi((char*)X.z); }
|
||||
signed(A) ::= minus_num(X). { A = -atoi((char*)X.z); }
|
||||
signed(A) ::= plus_num(X). { A = atoi(X.z); }
|
||||
signed(A) ::= minus_num(X). { A = -atoi(X.z); }
|
||||
|
||||
// "carglist" is a list of additional constraints that come after the
|
||||
// column name and column type in a CREATE TABLE statement.
|
||||
@@ -260,14 +265,14 @@ carg ::= DEFAULT id(X). {
|
||||
//
|
||||
ccons ::= NULL onconf.
|
||||
ccons ::= NOT NULL onconf(R). {sqlite3AddNotNull(pParse, R);}
|
||||
ccons ::= PRIMARY KEY sortorder(Z) onconf(R) autoinc(I).
|
||||
{sqlite3AddPrimaryKey(pParse,0,R,I,Z);}
|
||||
ccons ::= UNIQUE onconf(R). {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0,0,0);}
|
||||
ccons ::= CHECK LP expr(X) RP. {sqlite3AddCheckConstraint(pParse,X);}
|
||||
ccons ::= PRIMARY KEY sortorder onconf(R) autoinc(I).
|
||||
{sqlite3AddPrimaryKey(pParse,0,R,I);}
|
||||
ccons ::= UNIQUE onconf(R). {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0);}
|
||||
ccons ::= CHECK LP expr(X) RP onconf. {sqlite3ExprDelete(X);}
|
||||
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, (char*)C.z, C.n);}
|
||||
ccons ::= COLLATE id(C). {sqlite3AddCollateType(pParse, C.z, C.n);}
|
||||
|
||||
// The optional AUTOINCREMENT keyword
|
||||
%type autoinc {int}
|
||||
@@ -310,10 +315,10 @@ conslist ::= conslist tcons.
|
||||
conslist ::= tcons.
|
||||
tcons ::= CONSTRAINT nm.
|
||||
tcons ::= PRIMARY KEY LP idxlist(X) autoinc(I) RP onconf(R).
|
||||
{sqlite3AddPrimaryKey(pParse,X,R,I,0);}
|
||||
{sqlite3AddPrimaryKey(pParse,X,R,I);}
|
||||
tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
|
||||
{sqlite3CreateIndex(pParse,0,0,0,X,R,0,0,0,0);}
|
||||
tcons ::= CHECK LP expr(E) RP onconf. {sqlite3AddCheckConstraint(pParse,E);}
|
||||
{sqlite3CreateIndex(pParse,0,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);
|
||||
@@ -339,12 +344,9 @@ resolvetype(A) ::= REPLACE. {A = OE_Replace;}
|
||||
|
||||
////////////////////////// The DROP TABLE /////////////////////////////////////
|
||||
//
|
||||
cmd ::= DROP TABLE ifexists(E) fullname(X). {
|
||||
sqlite3DropTable(pParse, X, 0, E);
|
||||
cmd ::= DROP TABLE fullname(X). {
|
||||
sqlite3DropTable(pParse, X, 0);
|
||||
}
|
||||
%type ifexists {int}
|
||||
ifexists(A) ::= IF EXISTS. {A = 1;}
|
||||
ifexists(A) ::= . {A = 0;}
|
||||
|
||||
///////////////////// The CREATE VIEW statement /////////////////////////////
|
||||
//
|
||||
@@ -352,8 +354,8 @@ ifexists(A) ::= . {A = 0;}
|
||||
cmd ::= CREATE(X) temp(T) VIEW nm(Y) dbnm(Z) AS select(S). {
|
||||
sqlite3CreateView(pParse, &X, &Y, &Z, S, T);
|
||||
}
|
||||
cmd ::= DROP VIEW ifexists(E) fullname(X). {
|
||||
sqlite3DropTable(pParse, X, 1, E);
|
||||
cmd ::= DROP VIEW fullname(X). {
|
||||
sqlite3DropTable(pParse, X, 1);
|
||||
}
|
||||
%endif // SQLITE_OMIT_VIEW
|
||||
|
||||
@@ -379,9 +381,10 @@ select(A) ::= select(X) multiselect_op(Y) oneselect(Z). {
|
||||
A = Z;
|
||||
}
|
||||
%type multiselect_op {int}
|
||||
multiselect_op(A) ::= UNION(OP). {A = @OP;}
|
||||
multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
|
||||
multiselect_op(A) ::= EXCEPT|INTERSECT(OP). {A = @OP;}
|
||||
multiselect_op(A) ::= UNION(OP). {A = @OP;}
|
||||
multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
|
||||
multiselect_op(A) ::= INTERSECT(OP). {A = @OP;}
|
||||
multiselect_op(A) ::= EXCEPT(OP). {A = @OP;}
|
||||
%endif // SQLITE_OMIT_COMPOUND_SELECT
|
||||
oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
|
||||
groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
|
||||
@@ -498,7 +501,8 @@ fullname(A) ::= nm(X) dbnm(Y). {A = sqlite3SrcListAppend(0,&X,&Y);}
|
||||
|
||||
%type joinop {int}
|
||||
%type joinop2 {int}
|
||||
joinop(X) ::= COMMA|JOIN. { X = JT_INNER; }
|
||||
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) nm(B) nm(C) JOIN.
|
||||
@@ -641,8 +645,10 @@ expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
|
||||
Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0);
|
||||
A = sqlite3Expr(TK_DOT, temp1, temp4, 0);
|
||||
}
|
||||
term(A) ::= INTEGER|FLOAT|BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= INTEGER(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= FLOAT(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= STRING(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= REGISTER(X). {A = sqlite3RegisterExpr(pParse, &X);}
|
||||
expr(A) ::= VARIABLE(X). {
|
||||
Token *pToken = &X;
|
||||
@@ -672,20 +678,28 @@ term(A) ::= CTIME_KW(OP). {
|
||||
A = sqlite3ExprFunction(0,&OP);
|
||||
if( A ) A->op = TK_CONST_FUNC;
|
||||
}
|
||||
expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LT|GT|GE|LE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) EQ|NE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITAND|BITOR|LSHIFT|RSHIFT(OP) expr(Y).
|
||||
{A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) PLUS|MINUS(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) GT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) GE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) NE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) EQ(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITAND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITOR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LSHIFT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) RSHIFT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) PLUS(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) MINUS(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) STAR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) SLASH(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) REM(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
%type likeop {struct LikeOp}
|
||||
likeop(A) ::= LIKE_KW(X). {A.operator = X; A.not = 0;}
|
||||
likeop(A) ::= NOT LIKE_KW(X). {A.operator = X; A.not = 1;}
|
||||
%type escape {Expr*}
|
||||
%destructor escape {sqlite3ExprDelete($$);}
|
||||
escape(X) ::= ESCAPE expr(A). [ESCAPE] {X = A;}
|
||||
escape(X) ::= . [ESCAPE] {X = 0;}
|
||||
expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E). [LIKE_KW] {
|
||||
@@ -699,14 +713,18 @@ expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E). [LIKE_KW] {
|
||||
sqlite3ExprSpan(A, &X->span, &Y->span);
|
||||
}
|
||||
|
||||
expr(A) ::= expr(X) ISNULL|NOTNULL(E). {
|
||||
A = sqlite3Expr(@E, X, 0, 0);
|
||||
expr(A) ::= expr(X) ISNULL(E). {
|
||||
A = sqlite3Expr(TK_ISNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) IS NULL(E). {
|
||||
A = sqlite3Expr(TK_ISNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) NOTNULL(E). {
|
||||
A = sqlite3Expr(TK_NOTNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT NULL(E). {
|
||||
A = sqlite3Expr(TK_NOTNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
@@ -715,7 +733,11 @@ expr(A) ::= expr(X) IS NOT NULL(E). {
|
||||
A = sqlite3Expr(TK_NOTNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= NOT|BITNOT(B) expr(X). {
|
||||
expr(A) ::= NOT(B) expr(X). {
|
||||
A = sqlite3Expr(@B, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&B,&X->span);
|
||||
}
|
||||
expr(A) ::= BITNOT(B) expr(X). {
|
||||
A = sqlite3Expr(@B, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&B,&X->span);
|
||||
}
|
||||
@@ -818,11 +840,9 @@ case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). {
|
||||
A = sqlite3ExprListAppend(A, Z, 0);
|
||||
}
|
||||
%type case_else {Expr*}
|
||||
%destructor case_else {sqlite3ExprDelete($$);}
|
||||
case_else(A) ::= ELSE expr(X). {A = X;}
|
||||
case_else(A) ::= . {A = 0;}
|
||||
%type case_operand {Expr*}
|
||||
%destructor case_operand {sqlite3ExprDelete($$);}
|
||||
case_operand(A) ::= expr(X). {A = X;}
|
||||
case_operand(A) ::= . {A = 0;}
|
||||
|
||||
@@ -839,12 +859,11 @@ expritem(A) ::= . {A = 0;}
|
||||
|
||||
///////////////////////////// The CREATE INDEX command ///////////////////////
|
||||
//
|
||||
cmd ::= CREATE(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X) dbnm(D)
|
||||
cmd ::= CREATE(S) uniqueflag(U) INDEX nm(X) dbnm(D)
|
||||
ON nm(Y) LP idxlist(Z) RP(E) onconf(R). {
|
||||
if( U!=OE_None ) U = R;
|
||||
if( U==OE_Default) U = OE_Abort;
|
||||
sqlite3CreateIndex(pParse, &X, &D, sqlite3SrcListAppend(0,&Y,0), Z, U,
|
||||
&S, &E, SQLITE_SO_ASC, NE);
|
||||
sqlite3CreateIndex(pParse, &X, &D, sqlite3SrcListAppend(0,&Y,0),Z,U, &S, &E);
|
||||
}
|
||||
|
||||
%type uniqueflag {int}
|
||||
@@ -859,30 +878,28 @@ uniqueflag(A) ::= . {A = OE_None;}
|
||||
|
||||
idxlist_opt(A) ::= . {A = 0;}
|
||||
idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;}
|
||||
idxlist(A) ::= idxlist(X) COMMA idxitem(Y) collate(C) sortorder(Z). {
|
||||
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, (char*)C.z, C.n);
|
||||
if( p ) p->pColl = sqlite3LocateCollSeq(pParse, C.z, C.n);
|
||||
}
|
||||
A = sqlite3ExprListAppend(X, p, &Y);
|
||||
if( A ) A->a[A->nExpr-1].sortOrder = Z;
|
||||
}
|
||||
idxlist(A) ::= idxitem(Y) collate(C) sortorder(Z). {
|
||||
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, (char*)C.z, C.n);
|
||||
if( p ) p->pColl = sqlite3LocateCollSeq(pParse, C.z, C.n);
|
||||
}
|
||||
A = sqlite3ExprListAppend(0, p, &Y);
|
||||
if( A ) A->a[A->nExpr-1].sortOrder = Z;
|
||||
}
|
||||
idxitem(A) ::= nm(X). {A = X;}
|
||||
|
||||
|
||||
///////////////////////////// The DROP INDEX command /////////////////////////
|
||||
//
|
||||
cmd ::= DROP INDEX ifexists(E) fullname(X). {sqlite3DropIndex(pParse, X, E);}
|
||||
cmd ::= DROP INDEX fullname(X). {sqlite3DropIndex(pParse, X);}
|
||||
|
||||
///////////////////////////// The VACUUM command /////////////////////////////
|
||||
//
|
||||
@@ -903,7 +920,8 @@ cmd ::= PRAGMA nm(X) dbnm(Z). {sqlite3Pragma(pParse,&X,&Z,0,0);}
|
||||
%endif // SQLITE_OMIT_PRAGMA
|
||||
plus_num(A) ::= plus_opt number(X). {A = X;}
|
||||
minus_num(A) ::= MINUS number(X). {A = X;}
|
||||
number(A) ::= INTEGER|FLOAT(X). {A = X;}
|
||||
number(A) ::= INTEGER(X). {A = X;}
|
||||
number(A) ::= FLOAT(X). {A = X;}
|
||||
plus_opt ::= PLUS.
|
||||
plus_opt ::= .
|
||||
|
||||
@@ -933,7 +951,8 @@ trigger_time(A) ::= . { A = TK_BEFORE; }
|
||||
|
||||
%type trigger_event {struct TrigEvent}
|
||||
%destructor trigger_event {sqlite3IdListDelete($$.b);}
|
||||
trigger_event(A) ::= DELETE|INSERT(OP). {A.a = @OP; A.b = 0;}
|
||||
trigger_event(A) ::= DELETE(OP). {A.a = @OP; A.b = 0;}
|
||||
trigger_event(A) ::= INSERT(OP). {A.a = @OP; A.b = 0;}
|
||||
trigger_event(A) ::= UPDATE(OP). {A.a = @OP; A.b = 0;}
|
||||
trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X;}
|
||||
|
||||
@@ -943,7 +962,6 @@ foreach_clause(A) ::= FOR EACH ROW. { A = TK_ROW; }
|
||||
foreach_clause(A) ::= FOR EACH STATEMENT. { A = TK_STATEMENT; }
|
||||
|
||||
%type when_clause {Expr*}
|
||||
%destructor when_clause {sqlite3ExprDelete($$);}
|
||||
when_clause(A) ::= . { A = 0; }
|
||||
when_clause(A) ::= WHEN expr(X). { A = X; }
|
||||
|
||||
@@ -1003,20 +1021,20 @@ cmd ::= DROP TRIGGER fullname(X). {
|
||||
%endif // !SQLITE_OMIT_TRIGGER
|
||||
|
||||
//////////////////////// ATTACH DATABASE file AS name /////////////////////////
|
||||
cmd ::= ATTACH database_kw_opt expr(F) AS expr(D) key_opt(K). {
|
||||
sqlite3Attach(pParse, F, D, K);
|
||||
cmd ::= ATTACH database_kw_opt ids(F) AS nm(D) key_opt(K). {
|
||||
sqlite3Attach(pParse, &F, &D, K.type, &K.key);
|
||||
}
|
||||
%type key_opt {Expr *}
|
||||
%destructor key_opt {sqlite3ExprDelete($$);}
|
||||
key_opt(A) ::= . { A = 0; }
|
||||
key_opt(A) ::= KEY expr(X). { A = X; }
|
||||
%type key_opt {struct AttachKey}
|
||||
key_opt(A) ::= . { A.type = 0; }
|
||||
key_opt(A) ::= KEY ids(X). { A.type=1; A.key = X; }
|
||||
key_opt(A) ::= KEY BLOB(X). { A.type=2; A.key = X; }
|
||||
|
||||
database_kw_opt ::= DATABASE.
|
||||
database_kw_opt ::= .
|
||||
|
||||
//////////////////////// DETACH DATABASE name /////////////////////////////////
|
||||
cmd ::= DETACH database_kw_opt expr(D). {
|
||||
sqlite3Detach(pParse, D);
|
||||
cmd ::= DETACH database_kw_opt nm(D). {
|
||||
sqlite3Detach(pParse, &D);
|
||||
}
|
||||
|
||||
////////////////////////// REINDEX collation //////////////////////////////////
|
||||
|
||||
+19
-38
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the PRAGMA command.
|
||||
**
|
||||
** $Id: pragma.c,v 1.114 2006/01/12 01:56:44 drh Exp $
|
||||
** $Id: pragma.c,v 1.100 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -36,7 +36,7 @@
|
||||
** 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.
|
||||
*/
|
||||
static int getSafetyLevel(const char *z){
|
||||
static int getSafetyLevel(const u8 *z){
|
||||
/* 123456789 123456789 */
|
||||
static const char zText[] = "onoffalseyestruefull";
|
||||
static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
|
||||
@@ -58,7 +58,7 @@ static int getSafetyLevel(const char *z){
|
||||
/*
|
||||
** Interpret the given string as a boolean value.
|
||||
*/
|
||||
static int getBoolean(const char *z){
|
||||
static int getBoolean(const u8 *z){
|
||||
return getSafetyLevel(z)&1;
|
||||
}
|
||||
|
||||
@@ -151,17 +151,9 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
|
||||
{ "short_column_names", SQLITE_ShortColNames },
|
||||
{ "count_changes", SQLITE_CountRows },
|
||||
{ "empty_result_callbacks", SQLITE_NullCallback },
|
||||
{ "legacy_file_format", SQLITE_LegacyFileFmt },
|
||||
#ifndef SQLITE_OMIT_CHECK
|
||||
{ "ignore_check_constraints", SQLITE_IgnoreChecks },
|
||||
#endif
|
||||
/* The following is VERY experimental */
|
||||
{ "writable_schema", SQLITE_WriteSchema },
|
||||
{ "omit_readlock", SQLITE_NoReadlock },
|
||||
|
||||
/* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
|
||||
** flag if there are any active statements. */
|
||||
{ "read_uncommitted", SQLITE_ReadUncommitted },
|
||||
};
|
||||
int i;
|
||||
const struct sPragmaType *p;
|
||||
@@ -288,8 +280,8 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeAddOp(v, OP_Ge, 0, addr+3);
|
||||
sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 2);
|
||||
pDb->pSchema->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
|
||||
pDb->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->cache_size);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -350,12 +342,12 @@ void sqlite3Pragma(
|
||||
if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
if( !zRight ){
|
||||
returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
|
||||
returnSingleInt(pParse, "cache_size", pDb->cache_size);
|
||||
}else{
|
||||
int size = atoi(zRight);
|
||||
if( size<0 ) size = -size;
|
||||
pDb->pSchema->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
|
||||
pDb->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->cache_size);
|
||||
}
|
||||
}else
|
||||
|
||||
@@ -655,7 +647,6 @@ void sqlite3Pragma(
|
||||
/* Do an integrity check on each database file */
|
||||
for(i=0; i<db->nDb; i++){
|
||||
HashElem *x;
|
||||
Hash *pTbls;
|
||||
int cnt = 0;
|
||||
|
||||
if( OMIT_TEMPDB && i==1 ) continue;
|
||||
@@ -664,13 +655,13 @@ void sqlite3Pragma(
|
||||
|
||||
/* Do an integrity check of the B-Tree
|
||||
*/
|
||||
pTbls = &db->aDb[i].pSchema->tblHash;
|
||||
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
|
||||
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++;
|
||||
}
|
||||
@@ -679,19 +670,18 @@ void sqlite3Pragma(
|
||||
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+7);
|
||||
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, 0, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0);
|
||||
|
||||
/* Make sure all the indices are constructed correctly.
|
||||
*/
|
||||
sqlite3CodeVerifySchema(pParse, i);
|
||||
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
|
||||
for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
|
||||
Table *pTab = sqliteHashData(x);
|
||||
Index *pIdx;
|
||||
int loopTop;
|
||||
@@ -700,11 +690,11 @@ void sqlite3Pragma(
|
||||
sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, 1);
|
||||
loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0);
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
int jmp2;
|
||||
static const VdbeOpList idxErr[] = {
|
||||
{ OP_MemIncr, 1, 0, 0},
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_String8, 0, 0, "rowid "},
|
||||
{ OP_Rowid, 1, 0, 0},
|
||||
{ OP_String8, 0, 0, " missing from index "},
|
||||
@@ -724,12 +714,12 @@ void sqlite3Pragma(
|
||||
static const VdbeOpList cntIdx[] = {
|
||||
{ OP_MemInt, 0, 2, 0},
|
||||
{ OP_Rewind, 0, 0, 0}, /* 1 */
|
||||
{ OP_MemIncr, 1, 2, 0},
|
||||
{ OP_MemIncr, 2, 0, 0},
|
||||
{ OP_Next, 0, 0, 0}, /* 3 */
|
||||
{ OP_MemLoad, 1, 0, 0},
|
||||
{ OP_MemLoad, 2, 0, 0},
|
||||
{ OP_Eq, 0, 0, 0}, /* 6 */
|
||||
{ OP_MemIncr, 1, 0, 0},
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_String8, 0, 0, "wrong # of entries in index "},
|
||||
{ OP_String8, 0, 0, 0}, /* 9 */
|
||||
{ OP_Concat, 0, 0, 0},
|
||||
@@ -797,7 +787,7 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeSetColName(v, 0, "encoding", P3_STATIC);
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
|
||||
if( pEnc->enc==ENC(pParse->db) ){
|
||||
if( pEnc->enc==pParse->db->enc ){
|
||||
sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC);
|
||||
break;
|
||||
}
|
||||
@@ -809,13 +799,10 @@ void sqlite3Pragma(
|
||||
** 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(
|
||||
!(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
|
||||
DbHasProperty(db, 0, DB_Empty)
|
||||
){
|
||||
if( !(pParse->db->flags&SQLITE_Initialized) ){
|
||||
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
|
||||
if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
|
||||
ENC(pParse->db) = pEnc->enc;
|
||||
pParse->db->enc = pEnc->enc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -931,12 +918,6 @@ void sqlite3Pragma(
|
||||
}else
|
||||
#endif
|
||||
|
||||
#if SQLITE_HAS_CODEC
|
||||
if( sqlite3StrICmp(zLeft, "key")==0 ){
|
||||
sqlite3_key(db, zRight, strlen(zRight));
|
||||
}else
|
||||
#endif
|
||||
|
||||
{}
|
||||
|
||||
if( v ){
|
||||
|
||||
+70
-157
@@ -13,7 +13,7 @@
|
||||
** interface, and routines that contribute to loading the database schema
|
||||
** from disk.
|
||||
**
|
||||
** $Id: prepare.c,v 1.22 2006/01/13 06:33:24 danielk1977 Exp $
|
||||
** $Id: prepare.c,v 1.4 2005/09/10 16:46:13 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -24,7 +24,7 @@
|
||||
** that the database is corrupt.
|
||||
*/
|
||||
static void corruptSchema(InitData *pData, const char *zExtra){
|
||||
if( !sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( !sqlite3_malloc_failed ){
|
||||
sqlite3SetString(pData->pzErrMsg, "malformed database schema",
|
||||
zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0);
|
||||
}
|
||||
@@ -49,10 +49,6 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
|
||||
sqlite3 *db = pData->db;
|
||||
int iDb;
|
||||
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
assert( argc==4 );
|
||||
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
|
||||
if( argv[1]==0 || argv[3]==0 ){
|
||||
@@ -75,11 +71,7 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
|
||||
rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
|
||||
db->init.iDb = 0;
|
||||
if( SQLITE_OK!=rc ){
|
||||
if( rc==SQLITE_NOMEM ){
|
||||
sqlite3ThreadData()->mallocFailed = 1;
|
||||
}else{
|
||||
corruptSchema(pData, zErr);
|
||||
}
|
||||
corruptSchema(pData, zErr);
|
||||
sqlite3_free(zErr);
|
||||
return rc;
|
||||
}
|
||||
@@ -119,7 +111,6 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
BtCursor *curMain;
|
||||
int size;
|
||||
Table *pTab;
|
||||
Db *pDb;
|
||||
char const *azArg[5];
|
||||
char zDbNum[30];
|
||||
int meta[10];
|
||||
@@ -154,7 +145,6 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
#endif
|
||||
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
assert( db->aDb[iDb].pSchema );
|
||||
|
||||
/* zMasterSchema and zInitScript are set to point at the master schema
|
||||
** and initialisation script appropriate for the database being
|
||||
@@ -190,14 +180,11 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
|
||||
/* Create a cursor to hold the database open
|
||||
*/
|
||||
pDb = &db->aDb[iDb];
|
||||
if( pDb->pBt==0 ){
|
||||
if( !OMIT_TEMPDB && iDb==1 ){
|
||||
DbSetProperty(db, 1, DB_SchemaLoaded);
|
||||
}
|
||||
if( db->aDb[iDb].pBt==0 ){
|
||||
if( !OMIT_TEMPDB && iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
rc = sqlite3BtreeCursor(pDb->pBt, MASTER_ROOT, 0, 0, 0, &curMain);
|
||||
rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain);
|
||||
if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){
|
||||
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
|
||||
return rc;
|
||||
@@ -223,7 +210,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
if( rc==SQLITE_OK ){
|
||||
int i;
|
||||
for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){
|
||||
rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
|
||||
rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, i+1, (u32 *)&meta[i]);
|
||||
}
|
||||
if( rc ){
|
||||
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
|
||||
@@ -233,7 +220,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
}else{
|
||||
memset(meta, 0, sizeof(meta));
|
||||
}
|
||||
pDb->pSchema->schema_cookie = meta[0];
|
||||
db->aDb[iDb].schema_cookie = meta[0];
|
||||
|
||||
/* If opening a non-empty database, check the text encoding. For the
|
||||
** main database, set sqlite3.enc to the encoding of the main database.
|
||||
@@ -242,44 +229,55 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
*/
|
||||
if( meta[4] ){ /* text encoding */
|
||||
if( iDb==0 ){
|
||||
/* If opening the main database, set ENC(db). */
|
||||
ENC(db) = (u8)meta[4];
|
||||
db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0);
|
||||
/* If opening the main database, set db->enc. */
|
||||
db->enc = (u8)meta[4];
|
||||
db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0);
|
||||
}else{
|
||||
/* If opening an attached database, the encoding much match ENC(db) */
|
||||
if( meta[4]!=ENC(db) ){
|
||||
/* If opening an attached database, the encoding much match db->enc */
|
||||
if( meta[4]!=db->enc ){
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
sqlite3SetString(pzErrMsg, "attached databases must use the same"
|
||||
" text encoding as main database", (char*)0);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
DbSetProperty(db, iDb, DB_Empty);
|
||||
}
|
||||
pDb->pSchema->enc = ENC(db);
|
||||
|
||||
size = meta[2];
|
||||
if( size==0 ){ size = MAX_PAGES; }
|
||||
pDb->pSchema->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
|
||||
db->aDb[iDb].cache_size = size;
|
||||
|
||||
if( iDb==0 ){
|
||||
db->file_format = meta[1];
|
||||
if( db->file_format==0 ){
|
||||
/* This happens if the database was initially empty */
|
||||
db->file_format = 1;
|
||||
}
|
||||
|
||||
if( db->file_format==2 || db->file_format==3 ){
|
||||
/* File format 2 is treated exactly as file format 1. New
|
||||
** databases are created with file format 1.
|
||||
*/
|
||||
db->file_format = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** file_format==1 Version 3.0.0.
|
||||
** file_format==2 Version 3.1.3. // ALTER TABLE ADD COLUMN
|
||||
** file_format==3 Version 3.1.4. // ditto but with non-NULL defaults
|
||||
** file_format==4 Version 3.3.0. // DESC indices. Boolean constants
|
||||
** file_format==2 Version 3.1.3.
|
||||
** file_format==3 Version 3.1.4.
|
||||
**
|
||||
** Version 3.0 can only use files with file_format==1. Version 3.1.3
|
||||
** can read and write files with file_format==1 or file_format==2.
|
||||
** Version 3.1.4 can read and write file formats 1, 2 and 3.
|
||||
*/
|
||||
pDb->pSchema->file_format = meta[1];
|
||||
if( pDb->pSchema->file_format==0 ){
|
||||
pDb->pSchema->file_format = 1;
|
||||
}
|
||||
if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
|
||||
if( meta[1]>3 ){
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
sqlite3BtreeSetCacheSize(db->aDb[iDb].pBt, db->aDb[iDb].cache_size);
|
||||
|
||||
/* Read the schema information out of the schema tables
|
||||
*/
|
||||
@@ -303,7 +301,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
#endif
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
}
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
|
||||
rc = SQLITE_NOMEM;
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
@@ -322,15 +320,14 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
** created using ATTACH statements. Return a success code. If an
|
||||
** error occurs, write an error message into *pzErrMsg.
|
||||
**
|
||||
** After a database is initialized, the DB_SchemaLoaded bit is set
|
||||
** bit is set in the flags field of the Db structure. If the database
|
||||
** file was of zero-length, then the DB_Empty flag is also set.
|
||||
** After the database is initialized, the SQLITE_Initialized
|
||||
** bit is set in the flags field of the sqlite structure.
|
||||
*/
|
||||
int sqlite3Init(sqlite3 *db, char **pzErrMsg){
|
||||
int i, rc;
|
||||
int called_initone = 0;
|
||||
|
||||
if( db->init.busy ) return SQLITE_OK;
|
||||
assert( (db->flags & SQLITE_Initialized)==0 );
|
||||
rc = SQLITE_OK;
|
||||
db->init.busy = 1;
|
||||
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
|
||||
@@ -339,7 +336,6 @@ int sqlite3Init(sqlite3 *db, char **pzErrMsg){
|
||||
if( rc ){
|
||||
sqlite3ResetInternalSchema(db, i);
|
||||
}
|
||||
called_initone = 1;
|
||||
}
|
||||
|
||||
/* Once all the other databases have been initialised, load the schema
|
||||
@@ -352,16 +348,19 @@ int sqlite3Init(sqlite3 *db, char **pzErrMsg){
|
||||
if( rc ){
|
||||
sqlite3ResetInternalSchema(db, 1);
|
||||
}
|
||||
called_initone = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
db->init.busy = 0;
|
||||
if( rc==SQLITE_OK && called_initone ){
|
||||
if( rc==SQLITE_OK ){
|
||||
db->flags |= SQLITE_Initialized;
|
||||
sqlite3CommitInternalChanges(db);
|
||||
}
|
||||
|
||||
return rc;
|
||||
if( rc!=SQLITE_OK ){
|
||||
db->flags &= ~SQLITE_Initialized;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -372,8 +371,11 @@ int sqlite3ReadSchema(Parse *pParse){
|
||||
int rc = SQLITE_OK;
|
||||
sqlite3 *db = pParse->db;
|
||||
if( !db->init.busy ){
|
||||
rc = sqlite3Init(db, &pParse->zErrMsg);
|
||||
if( (db->flags & SQLITE_Initialized)==0 ){
|
||||
rc = sqlite3Init(db, &pParse->zErrMsg);
|
||||
}
|
||||
}
|
||||
assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized) || db->init.busy );
|
||||
if( rc!=SQLITE_OK ){
|
||||
pParse->rc = rc;
|
||||
pParse->nErr++;
|
||||
@@ -400,7 +402,7 @@ static int schemaIsValid(sqlite3 *db){
|
||||
rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, 0, &curTemp);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&cookie);
|
||||
if( rc==SQLITE_OK && cookie!=db->aDb[iDb].pSchema->schema_cookie ){
|
||||
if( rc==SQLITE_OK && cookie!=db->aDb[iDb].schema_cookie ){
|
||||
allOk = 0;
|
||||
}
|
||||
sqlite3BtreeCloseCursor(curTemp);
|
||||
@@ -409,77 +411,6 @@ static int schemaIsValid(sqlite3 *db){
|
||||
return allOk;
|
||||
}
|
||||
|
||||
/*
|
||||
** Free all resources held by the schema structure. The void* argument points
|
||||
** at a Schema struct. This function does not call sqliteFree() on the
|
||||
** pointer itself, it just cleans up subsiduary resources (i.e. the contents
|
||||
** of the schema hash tables).
|
||||
*/
|
||||
void sqlite3SchemaFree(void *p){
|
||||
Hash temp1;
|
||||
Hash temp2;
|
||||
HashElem *pElem;
|
||||
Schema *pSchema = (Schema *)p;
|
||||
|
||||
temp1 = pSchema->tblHash;
|
||||
temp2 = pSchema->trigHash;
|
||||
sqlite3HashInit(&pSchema->trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashClear(&pSchema->aFKey);
|
||||
sqlite3HashClear(&pSchema->idxHash);
|
||||
for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
|
||||
sqlite3DeleteTrigger((Trigger*)sqliteHashData(pElem));
|
||||
}
|
||||
sqlite3HashClear(&temp2);
|
||||
sqlite3HashInit(&pSchema->tblHash, SQLITE_HASH_STRING, 0);
|
||||
for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
|
||||
Table *pTab = sqliteHashData(pElem);
|
||||
sqlite3DeleteTable(0, pTab);
|
||||
}
|
||||
sqlite3HashClear(&temp1);
|
||||
pSchema->pSeqTab = 0;
|
||||
pSchema->flags &= ~DB_SchemaLoaded;
|
||||
}
|
||||
|
||||
Schema *sqlite3SchemaGet(Btree *pBt){
|
||||
Schema * p;
|
||||
if( pBt ){
|
||||
p = (Schema *)sqlite3BtreeSchema(pBt,sizeof(Schema),sqlite3SchemaFree);
|
||||
}else{
|
||||
p = (Schema *)sqliteMalloc(sizeof(Schema));
|
||||
}
|
||||
if( p && 0==p->file_format ){
|
||||
sqlite3HashInit(&p->tblHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&p->idxHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&p->trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&p->aFKey, SQLITE_HASH_STRING, 1);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
|
||||
int i = -1000000;
|
||||
|
||||
/* If pSchema is NULL, then return -1000000. This happens when code in
|
||||
** expr.c is trying to resolve a reference to a transient table (i.e. one
|
||||
** created by a sub-select). In this case the return value of this
|
||||
** function should never be used.
|
||||
**
|
||||
** We return -1000000 instead of the more usual -1 simply because using
|
||||
** -1000000 as incorrectly using -1000000 index into db->aDb[] is much
|
||||
** more likely to cause a segfault than -1 (of course there are assert()
|
||||
** statements too, but it never hurts to play the odds).
|
||||
*/
|
||||
if( pSchema ){
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( db->aDb[i].pSchema==pSchema ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert( i>=0 &&i>=0 && i<db->nDb );
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
|
||||
*/
|
||||
@@ -493,9 +424,10 @@ int sqlite3_prepare(
|
||||
Parse sParse;
|
||||
char *zErrMsg = 0;
|
||||
int rc = SQLITE_OK;
|
||||
int i;
|
||||
|
||||
assert( !sqlite3ThreadDataReadOnly()->mallocFailed );
|
||||
if( sqlite3_malloc_failed ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
assert( ppStmt );
|
||||
*ppStmt = 0;
|
||||
@@ -503,30 +435,19 @@ int sqlite3_prepare(
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
|
||||
/* If any attached database schemas are locked, do not proceed with
|
||||
** compilation. Instead return SQLITE_LOCKED immediately.
|
||||
*/
|
||||
for(i=0; i<db->nDb; i++) {
|
||||
Btree *pBt = db->aDb[i].pBt;
|
||||
if( pBt && sqlite3BtreeSchemaLocked(pBt) ){
|
||||
const char *zDb = db->aDb[i].zName;
|
||||
sqlite3Error(db, SQLITE_LOCKED, "database schema is locked: %s", zDb);
|
||||
sqlite3SafetyOff(db);
|
||||
return SQLITE_LOCKED;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&sParse, 0, sizeof(sParse));
|
||||
sParse.db = db;
|
||||
sParse.pTsd = sqlite3ThreadData();
|
||||
sParse.pTsd->nRef++;
|
||||
sqlite3RunParser(&sParse, zSql, &zErrMsg);
|
||||
|
||||
if( sParse.pTsd->mallocFailed ){
|
||||
sParse.rc = SQLITE_NOMEM;
|
||||
if( sqlite3_malloc_failed ){
|
||||
rc = SQLITE_NOMEM;
|
||||
sqlite3RollbackAll(db);
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
db->flags &= ~SQLITE_InTrans;
|
||||
goto prepare_out;
|
||||
}
|
||||
if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
|
||||
if( sParse.checkSchema && !schemaIsValid(db) ){
|
||||
if( sParse.rc!=SQLITE_OK && sParse.checkSchema && !schemaIsValid(db) ){
|
||||
sParse.rc = SQLITE_SCHEMA;
|
||||
}
|
||||
if( sParse.rc==SQLITE_SCHEMA ){
|
||||
@@ -553,6 +474,7 @@ int sqlite3_prepare(
|
||||
}
|
||||
#endif
|
||||
|
||||
prepare_out:
|
||||
if( sqlite3SafetyOff(db) ){
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
@@ -568,18 +490,6 @@ int sqlite3_prepare(
|
||||
}else{
|
||||
sqlite3Error(db, rc, 0);
|
||||
}
|
||||
|
||||
/* We must check for malloc failure last of all, in case malloc() failed
|
||||
** inside of the sqlite3Error() call above or something.
|
||||
*/
|
||||
if( sParse.pTsd->mallocFailed ){
|
||||
rc = SQLITE_NOMEM;
|
||||
sqlite3Error(db, rc, 0);
|
||||
}
|
||||
|
||||
sParse.pTsd->nRef--;
|
||||
sqlite3MallocClearFailed();
|
||||
sqlite3ReleaseThreadData();
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -598,14 +508,17 @@ int sqlite3_prepare16(
|
||||
** encoded string to UTF-8, then invoking sqlite3_prepare(). The
|
||||
** tricky bit is figuring out the pointer to return in *pzTail.
|
||||
*/
|
||||
char *zSql8 = 0;
|
||||
const char *zTail8 = 0;
|
||||
char const *zSql8 = 0;
|
||||
char const *zTail8 = 0;
|
||||
int rc;
|
||||
sqlite3_value *pTmp;
|
||||
|
||||
if( sqlite3SafetyCheck(db) ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
zSql8 = sqlite3utf16to8(zSql, nBytes);
|
||||
pTmp = sqlite3GetTransientValue(db);
|
||||
sqlite3ValueSetStr(pTmp, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zSql8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
|
||||
if( !zSql8 ){
|
||||
sqlite3Error(db, SQLITE_NOMEM, 0);
|
||||
return SQLITE_NOMEM;
|
||||
@@ -621,7 +534,7 @@ int sqlite3_prepare16(
|
||||
int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
|
||||
*pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
|
||||
}
|
||||
sqliteFree(zSql8);
|
||||
|
||||
return rc;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
+6
-8
@@ -120,12 +120,10 @@ static const et_info fmtinfo[] = {
|
||||
{ 'u', 10, 0, etRADIX, 0, 0 },
|
||||
{ 'x', 16, 0, etRADIX, 16, 1 },
|
||||
{ 'X', 16, 0, etRADIX, 0, 4 },
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
{ 'f', 0, 1, etFLOAT, 0, 0 },
|
||||
{ 'e', 0, 1, etEXP, 30, 0 },
|
||||
{ 'E', 0, 1, etEXP, 14, 0 },
|
||||
{ 'G', 0, 1, etGENERIC, 14, 0 },
|
||||
#endif
|
||||
{ 'i', 10, 1, etRADIX, 0, 0 },
|
||||
{ 'n', 0, 0, etSIZE, 0, 0 },
|
||||
{ '%', 0, 0, etPERCENT, 0, 0 },
|
||||
@@ -136,10 +134,10 @@ static const et_info fmtinfo[] = {
|
||||
#define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
|
||||
|
||||
/*
|
||||
** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
|
||||
** If NOFLOATINGPOINT is defined, then none of the floating point
|
||||
** conversions will work.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
#ifndef etNOFLOATINGPOINT
|
||||
/*
|
||||
** "*val" is a double such that 0.1 <= *val < 10.0
|
||||
** Return the ascii code for the leading digit of *val, then
|
||||
@@ -163,7 +161,7 @@ static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
|
||||
*val = (*val - d)*10.0;
|
||||
return digit;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_FLOATING_POINT */
|
||||
#endif
|
||||
|
||||
/*
|
||||
** On machines with a small stack size, you can redefine the
|
||||
@@ -236,7 +234,7 @@ static int vxprintf(
|
||||
static const char spaces[] =
|
||||
" ";
|
||||
#define etSPACESIZE (sizeof(spaces)-1)
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
#ifndef etNOFLOATINGPOINT
|
||||
int exp, e2; /* exponent of real numbers */
|
||||
double rounder; /* Used for rounding floating point values */
|
||||
etByte flag_dp; /* True if decimal point should be shown */
|
||||
@@ -427,7 +425,7 @@ static int vxprintf(
|
||||
case etEXP:
|
||||
case etGENERIC:
|
||||
realvalue = va_arg(ap,double);
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
#ifndef etNOFLOATINGPOINT
|
||||
if( precision<0 ) precision = 6; /* Set default precision */
|
||||
if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10;
|
||||
if( realvalue<0.0 ){
|
||||
@@ -627,7 +625,7 @@ static int vxprintf(
|
||||
case etTOKEN: {
|
||||
Token *pToken = va_arg(ap, Token*);
|
||||
if( pToken && pToken->z ){
|
||||
(*func)(arg, (char*)pToken->z, pToken->n);
|
||||
(*func)(arg, pToken->z, pToken->n);
|
||||
}
|
||||
length = width = 0;
|
||||
break;
|
||||
|
||||
+1
-1
@@ -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.15 2006/01/06 14:32:20 drh Exp $
|
||||
** $Id: random.c,v 1.13 2005/06/12 21:35:52 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
|
||||
+98
-172
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle SELECT statements in SQLite.
|
||||
**
|
||||
** $Id: select.c,v 1.294 2006/01/13 06:33:24 danielk1977 Exp $
|
||||
** $Id: select.c,v 1.276 2005/09/20 18:13:24 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -109,7 +109,7 @@ int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){
|
||||
p = apAll[i];
|
||||
for(j=0; j<sizeof(keywords)/sizeof(keywords[0]); j++){
|
||||
if( p->n==keywords[j].nChar
|
||||
&& sqlite3StrNICmp((char*)p->z, keywords[j].zKeyword, p->n)==0 ){
|
||||
&& sqlite3StrNICmp(p->z, keywords[j].zKeyword, p->n)==0 ){
|
||||
jointype |= keywords[j].code;
|
||||
break;
|
||||
}
|
||||
@@ -154,8 +154,8 @@ static int columnIndex(Table *pTab, const char *zCol){
|
||||
** Set the value of a token to a '\000'-terminated string.
|
||||
*/
|
||||
static void setToken(Token *p, const char *z){
|
||||
p->z = (u8*)z;
|
||||
p->n = z ? strlen(z) : 0;
|
||||
p->z = z;
|
||||
p->n = strlen(z);
|
||||
p->dyn = 0;
|
||||
}
|
||||
|
||||
@@ -351,49 +351,38 @@ void sqlite3SelectDelete(Select *p){
|
||||
** Insert code into "v" that will push the record on the top of the
|
||||
** stack into the sorter.
|
||||
*/
|
||||
static void pushOntoSorter(
|
||||
Parse *pParse, /* Parser context */
|
||||
ExprList *pOrderBy, /* The ORDER BY clause */
|
||||
Select *pSelect /* The whole SELECT statement */
|
||||
){
|
||||
Vdbe *v = pParse->pVdbe;
|
||||
static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){
|
||||
sqlite3ExprCodeExprList(pParse, pOrderBy);
|
||||
sqlite3VdbeAddOp(v, OP_Sequence, pOrderBy->iECursor, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pull, pOrderBy->nExpr + 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pOrderBy->nExpr + 2, 0);
|
||||
sqlite3VdbeAddOp(v, OP_IdxInsert, pOrderBy->iECursor, 0);
|
||||
if( pSelect->iLimit>=0 ){
|
||||
int addr1, addr2;
|
||||
addr1 = sqlite3VdbeAddOp(v, OP_IfMemZero, pSelect->iLimit+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, -1, pSelect->iLimit+1);
|
||||
addr2 = sqlite3VdbeAddOp(v, OP_Goto, 0, 0);
|
||||
sqlite3VdbeJumpHere(v, addr1);
|
||||
sqlite3VdbeAddOp(v, OP_Last, pOrderBy->iECursor, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Delete, pOrderBy->iECursor, 0);
|
||||
sqlite3VdbeJumpHere(v, addr2);
|
||||
pSelect->iLimit = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Add code to implement the OFFSET
|
||||
** Add code to implement the OFFSET and LIMIT
|
||||
*/
|
||||
static void codeOffset(
|
||||
static void codeLimiter(
|
||||
Vdbe *v, /* Generate code into this VM */
|
||||
Select *p, /* The SELECT statement being coded */
|
||||
int iContinue, /* Jump here to skip the current record */
|
||||
int iBreak, /* Jump here to end the loop */
|
||||
int nPop /* Number of times to pop stack when jumping */
|
||||
){
|
||||
if( p->iOffset>=0 && iContinue!=0 ){
|
||||
int addr;
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, -1, p->iOffset);
|
||||
addr = sqlite3VdbeAddOp(v, OP_IfMemNeg, p->iOffset, 0);
|
||||
int addr = sqlite3VdbeCurrentAddr(v) + 3;
|
||||
if( nPop>0 ) addr++;
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, p->iOffset, 0);
|
||||
sqlite3VdbeAddOp(v, OP_IfMemPos, p->iOffset, addr);
|
||||
if( nPop>0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nPop, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, iContinue);
|
||||
VdbeComment((v, "# skip OFFSET records"));
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
if( p->iLimit>=0 && iBreak!=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, p->iLimit, iBreak);
|
||||
VdbeComment((v, "# exit when LIMIT reached"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,7 +449,7 @@ static int selectInnerLoop(
|
||||
*/
|
||||
hasDistinct = distinct>=0 && pEList && pEList->nExpr>0;
|
||||
if( pOrderBy==0 && !hasDistinct ){
|
||||
codeOffset(v, p, iContinue, 0);
|
||||
codeLimiter(v, p, iContinue, iBreak, 0);
|
||||
}
|
||||
|
||||
/* Pull the requested columns.
|
||||
@@ -482,7 +471,7 @@ static int selectInnerLoop(
|
||||
int n = pEList->nExpr;
|
||||
codeDistinct(v, distinct, iContinue, n, n+1);
|
||||
if( pOrderBy==0 ){
|
||||
codeOffset(v, p, iContinue, nColumn);
|
||||
codeLimiter(v, p, iContinue, iBreak, nColumn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -520,7 +509,7 @@ static int selectInnerLoop(
|
||||
case SRT_VirtualTab: {
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
|
||||
if( pOrderBy ){
|
||||
pushOntoSorter(pParse, pOrderBy, p);
|
||||
pushOntoSorter(pParse, v, pOrderBy);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, iParm, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
|
||||
@@ -547,7 +536,7 @@ static int selectInnerLoop(
|
||||
** ORDER BY in this case since the order of entries in the set
|
||||
** does not matter. But there might be a LIMIT clause, in which
|
||||
** case the order does matter */
|
||||
pushOntoSorter(pParse, pOrderBy, p);
|
||||
pushOntoSorter(pParse, v, pOrderBy);
|
||||
}else{
|
||||
char aff = (iParm>>16)&0xFF;
|
||||
aff = sqlite3CompareAffinity(pEList->a[0].pExpr, aff);
|
||||
@@ -558,26 +547,18 @@ static int selectInnerLoop(
|
||||
break;
|
||||
}
|
||||
|
||||
/* If any row exists in the result set, record that fact and abort.
|
||||
*/
|
||||
case SRT_Exists: {
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 1, iParm);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0);
|
||||
/* The LIMIT clause will terminate the loop for us */
|
||||
break;
|
||||
}
|
||||
|
||||
/* If this is a scalar select that is part of an expression, then
|
||||
** store the results in the appropriate memory cell and break out
|
||||
** of the scan loop.
|
||||
*/
|
||||
case SRT_Exists:
|
||||
case SRT_Mem: {
|
||||
assert( nColumn==1 );
|
||||
if( pOrderBy ){
|
||||
pushOntoSorter(pParse, pOrderBy, p);
|
||||
pushOntoSorter(pParse, v, pOrderBy);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1);
|
||||
/* The LIMIT clause will jump out of the loop for us */
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, iBreak);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -591,7 +572,7 @@ static int selectInnerLoop(
|
||||
case SRT_Callback: {
|
||||
if( pOrderBy ){
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
|
||||
pushOntoSorter(pParse, pOrderBy, p);
|
||||
pushOntoSorter(pParse, v, pOrderBy);
|
||||
}else if( eDest==SRT_Subroutine ){
|
||||
sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm);
|
||||
}else{
|
||||
@@ -613,13 +594,6 @@ static int selectInnerLoop(
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Jump to the end of the loop if the LIMIT is reached.
|
||||
*/
|
||||
if( p->iLimit>=0 && pOrderBy==0 ){
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, -1, p->iLimit);
|
||||
sqlite3VdbeAddOp(v, OP_IfMemZero, p->iLimit, iBreak);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -648,9 +622,9 @@ static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
|
||||
nExpr = pList->nExpr;
|
||||
pInfo = sqliteMalloc( sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) );
|
||||
if( pInfo ){
|
||||
pInfo->aSortOrder = (u8*)&pInfo->aColl[nExpr];
|
||||
pInfo->aSortOrder = (char*)&pInfo->aColl[nExpr];
|
||||
pInfo->nField = nExpr;
|
||||
pInfo->enc = ENC(db);
|
||||
pInfo->enc = db->enc;
|
||||
for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
|
||||
CollSeq *pColl;
|
||||
pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
|
||||
@@ -687,7 +661,7 @@ static void generateSortTail(
|
||||
|
||||
iTab = pOrderBy->iECursor;
|
||||
addr = 1 + sqlite3VdbeAddOp(v, OP_Sort, iTab, brk);
|
||||
codeOffset(v, p, cont, 0);
|
||||
codeLimiter(v, p, cont, brk, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iTab, pOrderBy->nExpr + 1);
|
||||
switch( eDest ){
|
||||
case SRT_Table:
|
||||
@@ -703,14 +677,15 @@ static void generateSortTail(
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, "c", P3_STATIC);
|
||||
sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, "n", P3_STATIC);
|
||||
sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0);
|
||||
break;
|
||||
}
|
||||
case SRT_Exists:
|
||||
case SRT_Mem: {
|
||||
assert( nColumn==1 );
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1);
|
||||
/* The LIMIT clause will terminate the loop for us */
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, brk);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@@ -735,16 +710,6 @@ static void generateSortTail(
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Jump to the end of the loop when the LIMIT is reached
|
||||
*/
|
||||
if( p->iLimit>=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, -1, p->iLimit);
|
||||
sqlite3VdbeAddOp(v, OP_IfMemZero, p->iLimit, brk);
|
||||
}
|
||||
|
||||
/* The bottom of the loop
|
||||
*/
|
||||
sqlite3VdbeResolveLabel(v, cont);
|
||||
sqlite3VdbeAddOp(v, OP_Next, iTab, addr);
|
||||
sqlite3VdbeResolveLabel(v, brk);
|
||||
@@ -872,8 +837,7 @@ static void generateColumnNames(
|
||||
#endif
|
||||
|
||||
assert( v!=0 );
|
||||
if( pParse->colNamesSet || v==0
|
||||
|| sqlite3ThreadDataReadOnly()->mallocFailed ) return;
|
||||
if( pParse->colNamesSet || v==0 || sqlite3_malloc_failed ) return;
|
||||
pParse->colNamesSet = 1;
|
||||
fullNames = (db->flags & SQLITE_FullColNames)!=0;
|
||||
shortNames = (db->flags & SQLITE_ShortColNames)!=0;
|
||||
@@ -902,20 +866,20 @@ static void generateColumnNames(
|
||||
zCol = pTab->aCol[iCol].zName;
|
||||
}
|
||||
if( !shortNames && !fullNames && p->span.z && p->span.z[0] ){
|
||||
sqlite3VdbeSetColName(v, i, (char*)p->span.z, p->span.n);
|
||||
sqlite3VdbeSetColName(v, i, p->span.z, p->span.n);
|
||||
}else if( fullNames || (!shortNames && pTabList->nSrc>1) ){
|
||||
char *zName = 0;
|
||||
char *zTab;
|
||||
|
||||
zTab = pTabList->a[j].zAlias;
|
||||
if( fullNames || zTab==0 ) zTab = pTab->zName;
|
||||
sqlite3SetString(&zName, zTab, ".", zCol, (char*)0);
|
||||
sqlite3SetString(&zName, zTab, ".", zCol, 0);
|
||||
sqlite3VdbeSetColName(v, i, zName, P3_DYNAMIC);
|
||||
}else{
|
||||
sqlite3VdbeSetColName(v, i, zCol, strlen(zCol));
|
||||
}
|
||||
}else if( p->span.z && p->span.z[0] ){
|
||||
sqlite3VdbeSetColName(v, i, (char*)p->span.z, p->span.n);
|
||||
sqlite3VdbeSetColName(v, i, p->span.z, p->span.n);
|
||||
/* sqlite3VdbeCompressSpace(v, addr); */
|
||||
}else{
|
||||
char zName[30];
|
||||
@@ -979,7 +943,6 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
|
||||
char *zType;
|
||||
char *zName;
|
||||
char *zBasename;
|
||||
CollSeq *pColl;
|
||||
int cnt;
|
||||
NameContext sNC;
|
||||
|
||||
@@ -1002,7 +965,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
|
||||
zName = sqlite3MPrintf("column%d", i+1);
|
||||
}
|
||||
sqlite3Dequote(zName);
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
sqliteFree(zName);
|
||||
sqlite3DeleteTable(0, pTab);
|
||||
return 0;
|
||||
@@ -1032,9 +995,9 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
|
||||
zType = sqliteStrDup(columnType(&sNC, p));
|
||||
pCol->zType = zType;
|
||||
pCol->affinity = sqlite3ExprAffinity(p);
|
||||
pColl = sqlite3ExprCollSeq(pParse, p);
|
||||
if( pColl ){
|
||||
pCol->zColl = sqliteStrDup(pColl->zName);
|
||||
pCol->pColl = sqlite3ExprCollSeq(pParse, p);
|
||||
if( !pCol->pColl ){
|
||||
pCol->pColl = pParse->db->pDfltColl;
|
||||
}
|
||||
}
|
||||
pTab->iPKey = -1;
|
||||
@@ -1074,9 +1037,7 @@ static int prepSelectStmt(Parse *pParse, Select *p){
|
||||
Table *pTab;
|
||||
struct SrcList_item *pFrom;
|
||||
|
||||
if( p==0 || p->pSrc==0 || sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
return 1;
|
||||
}
|
||||
if( p==0 || p->pSrc==0 || sqlite3_malloc_failed ) return 1;
|
||||
pTabList = p->pSrc;
|
||||
pEList = p->pEList;
|
||||
|
||||
@@ -1184,11 +1145,7 @@ static int prepSelectStmt(Parse *pParse, Select *p){
|
||||
/* This particular expression does not need to be expanded.
|
||||
*/
|
||||
pNew = sqlite3ExprListAppend(pNew, a[k].pExpr, 0);
|
||||
if( pNew ){
|
||||
pNew->a[pNew->nExpr-1].zName = a[k].zName;
|
||||
}else{
|
||||
rc = 1;
|
||||
}
|
||||
pNew->a[pNew->nExpr-1].zName = a[k].zName;
|
||||
a[k].pExpr = 0;
|
||||
a[k].zName = 0;
|
||||
}else{
|
||||
@@ -1369,31 +1326,25 @@ Vdbe *sqlite3GetVdbe(Parse *pParse){
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Compute the iLimit and iOffset fields of the SELECT based on the
|
||||
** pLimit and pOffset expressions. pLimit and pOffset hold the expressions
|
||||
** pLimit and pOffset expressions. nLimit and nOffset hold the expressions
|
||||
** that appear in the original SQL statement after the LIMIT and OFFSET
|
||||
** keywords. Or NULL if those keywords are omitted. iLimit and iOffset
|
||||
** are the integer memory register numbers for counters used to compute
|
||||
** the limit and offset. If there is no limit and/or offset, then
|
||||
** iLimit and iOffset are negative.
|
||||
**
|
||||
** This routine changes the values of iLimit and iOffset only if
|
||||
** a limit or offset is defined by pLimit and pOffset. iLimit and
|
||||
** This routine changes the values if iLimit and iOffset only if
|
||||
** a limit or offset is defined by nLimit and nOffset. iLimit and
|
||||
** iOffset should have been preset to appropriate default values
|
||||
** (usually but not always -1) prior to calling this routine.
|
||||
** Only if pLimit!=0 or pOffset!=0 do the limit registers get
|
||||
** Only if nLimit>=0 or nOffset>0 do the limit registers get
|
||||
** redefined. The UNION ALL operator uses this property to force
|
||||
** the reuse of the same limit and offset registers across multiple
|
||||
** SELECT statements.
|
||||
*/
|
||||
static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){
|
||||
Vdbe *v;
|
||||
int iLimit;
|
||||
int iOffset;
|
||||
int addr1, addr2;
|
||||
|
||||
static void computeLimitRegisters(Parse *pParse, Select *p){
|
||||
/*
|
||||
** "LIMIT -1" always shows all rows. There is some
|
||||
** contraversy about what the correct behavior should be.
|
||||
@@ -1401,41 +1352,26 @@ static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){
|
||||
** no rows.
|
||||
*/
|
||||
if( p->pLimit ){
|
||||
p->iLimit = iLimit = pParse->nMem;
|
||||
pParse->nMem += 2;
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
int iMem = pParse->nMem++;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) return;
|
||||
sqlite3ExprCode(pParse, p->pLimit);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iLimit, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iMem, 1);
|
||||
VdbeComment((v, "# LIMIT counter"));
|
||||
sqlite3VdbeAddOp(v, OP_IfMemZero, iLimit, iBreak);
|
||||
p->iLimit = iMem;
|
||||
}
|
||||
if( p->pOffset ){
|
||||
p->iOffset = iOffset = pParse->nMem++;
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
int iMem = pParse->nMem++;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) return;
|
||||
sqlite3ExprCode(pParse, p->pOffset);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iOffset, p->pLimit==0);
|
||||
sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iMem, 1);
|
||||
VdbeComment((v, "# OFFSET counter"));
|
||||
addr1 = sqlite3VdbeAddOp(v, OP_IfMemPos, iOffset, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeJumpHere(v, addr1);
|
||||
if( p->pLimit ){
|
||||
sqlite3VdbeAddOp(v, OP_Add, 0, 0);
|
||||
}
|
||||
}
|
||||
if( p->pLimit ){
|
||||
addr1 = sqlite3VdbeAddOp(v, OP_IfMemPos, iLimit, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, -1, iLimit+1);
|
||||
addr2 = sqlite3VdbeAddOp(v, OP_Goto, 0, 0);
|
||||
sqlite3VdbeJumpHere(v, addr1);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iLimit+1, 1);
|
||||
VdbeComment((v, "# LIMIT+OFFSET"));
|
||||
sqlite3VdbeJumpHere(v, addr2);
|
||||
p->iOffset = iMem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1583,31 +1519,23 @@ static int multiSelect(
|
||||
switch( p->op ){
|
||||
case TK_ALL: {
|
||||
if( pOrderBy==0 ){
|
||||
int addr = 0;
|
||||
assert( !pPrior->pLimit );
|
||||
pPrior->pLimit = p->pLimit;
|
||||
pPrior->pOffset = p->pOffset;
|
||||
rc = sqlite3Select(pParse, pPrior, eDest, iParm, 0, 0, 0, aff);
|
||||
p->pLimit = 0;
|
||||
p->pOffset = 0;
|
||||
if( rc ){
|
||||
goto multi_select_end;
|
||||
}
|
||||
p->pPrior = 0;
|
||||
p->iLimit = pPrior->iLimit;
|
||||
p->iOffset = pPrior->iOffset;
|
||||
if( p->iLimit>=0 ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_IfMemZero, p->iLimit, 0);
|
||||
VdbeComment((v, "# Jump ahead if LIMIT reached"));
|
||||
}
|
||||
p->pLimit = 0;
|
||||
p->pOffset = 0;
|
||||
rc = sqlite3Select(pParse, p, eDest, iParm, 0, 0, 0, aff);
|
||||
p->pPrior = pPrior;
|
||||
if( rc ){
|
||||
goto multi_select_end;
|
||||
}
|
||||
if( addr ){
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* For UNION ALL ... ORDER BY fall through to the next case */
|
||||
@@ -1694,8 +1622,8 @@ static int multiSelect(
|
||||
}
|
||||
iBreak = sqlite3VdbeMakeLabel(v);
|
||||
iCont = sqlite3VdbeMakeLabel(v);
|
||||
computeLimitRegisters(pParse, p, iBreak);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, unionTab, iBreak);
|
||||
computeLimitRegisters(pParse, p);
|
||||
iStart = sqlite3VdbeCurrentAddr(v);
|
||||
rc = selectInnerLoop(pParse, p, p->pEList, unionTab, p->pEList->nExpr,
|
||||
pOrderBy, -1, eDest, iParm,
|
||||
@@ -1770,8 +1698,8 @@ static int multiSelect(
|
||||
}
|
||||
iBreak = sqlite3VdbeMakeLabel(v);
|
||||
iCont = sqlite3VdbeMakeLabel(v);
|
||||
computeLimitRegisters(pParse, p, iBreak);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, tab1, iBreak);
|
||||
computeLimitRegisters(pParse, p);
|
||||
iStart = sqlite3VdbeAddOp(v, OP_RowKey, tab1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NotFound, tab2, iCont);
|
||||
rc = selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr,
|
||||
@@ -1832,7 +1760,7 @@ static int multiSelect(
|
||||
goto multi_select_end;
|
||||
}
|
||||
|
||||
pKeyInfo->enc = ENC(pParse->db);
|
||||
pKeyInfo->enc = pParse->db->enc;
|
||||
pKeyInfo->nField = nCol;
|
||||
|
||||
for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
|
||||
@@ -1858,15 +1786,15 @@ static int multiSelect(
|
||||
|
||||
if( pOrderBy ){
|
||||
struct ExprList_item *pOTerm = pOrderBy->a;
|
||||
int nOrderByExpr = pOrderBy->nExpr;
|
||||
int nExpr = pOrderBy->nExpr;
|
||||
int addr;
|
||||
u8 *pSortOrder;
|
||||
|
||||
aCopy = (CollSeq**)&pKeyInfo[1];
|
||||
pSortOrder = pKeyInfo->aSortOrder = (u8*)&aCopy[nCol];
|
||||
pSortOrder = pKeyInfo->aSortOrder = (u8*)&aCopy[nExpr];
|
||||
memcpy(aCopy, pKeyInfo->aColl, nCol*sizeof(CollSeq*));
|
||||
apColl = pKeyInfo->aColl;
|
||||
for(i=0; i<nOrderByExpr; i++, pOTerm++, apColl++, pSortOrder++){
|
||||
for(i=0; i<pOrderBy->nExpr; i++, pOTerm++, apColl++, pSortOrder++){
|
||||
Expr *pExpr = pOTerm->pExpr;
|
||||
char *zName = pOTerm->zName;
|
||||
assert( pExpr->op==TK_COLUMN && pExpr->iColumn<nCol );
|
||||
@@ -1881,7 +1809,7 @@ static int multiSelect(
|
||||
assert( p->addrOpenVirt[2]>=0 );
|
||||
addr = p->addrOpenVirt[2];
|
||||
sqlite3VdbeChangeP2(v, addr, p->pEList->nExpr+2);
|
||||
pKeyInfo->nField = nOrderByExpr;
|
||||
pKeyInfo->nField = pOrderBy->nExpr;
|
||||
sqlite3VdbeChangeP3(v, addr, (char*)pKeyInfo, P3_KEYINFO_HANDOFF);
|
||||
pKeyInfo = 0;
|
||||
generateSortTail(pParse, p, v, p->pEList->nExpr, eDest, iParm);
|
||||
@@ -2157,7 +2085,7 @@ static int flattenSubquery(
|
||||
for(i=0; i<pList->nExpr; i++){
|
||||
Expr *pExpr;
|
||||
if( pList->a[i].zName==0 && (pExpr = pList->a[i].pExpr)->span.z!=0 ){
|
||||
pList->a[i].zName = sqliteStrNDup((char*)pExpr->span.z, pExpr->span.n);
|
||||
pList->a[i].zName = sqliteStrNDup(pExpr->span.z, pExpr->span.n);
|
||||
}
|
||||
}
|
||||
if( isAgg ){
|
||||
@@ -2238,11 +2166,10 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
|
||||
int base;
|
||||
Vdbe *v;
|
||||
int seekOp;
|
||||
int cont;
|
||||
ExprList *pEList, *pList, eList;
|
||||
struct ExprList_item eListItem;
|
||||
SrcList *pSrc;
|
||||
int brk;
|
||||
int iDb;
|
||||
|
||||
/* Check to see if this query is a simple min() or max() query. Return
|
||||
** zero if it is not.
|
||||
@@ -2257,9 +2184,9 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
|
||||
pList = pExpr->pList;
|
||||
if( pList==0 || pList->nExpr!=1 ) return 0;
|
||||
if( pExpr->token.n!=3 ) return 0;
|
||||
if( sqlite3StrNICmp((char*)pExpr->token.z,"min",3)==0 ){
|
||||
if( sqlite3StrNICmp(pExpr->token.z,"min",3)==0 ){
|
||||
seekOp = OP_Rewind;
|
||||
}else if( sqlite3StrNICmp((char*)pExpr->token.z,"max",3)==0 ){
|
||||
}else if( sqlite3StrNICmp(pExpr->token.z,"max",3)==0 ){
|
||||
seekOp = OP_Last;
|
||||
}else{
|
||||
return 0;
|
||||
@@ -2269,7 +2196,6 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
|
||||
iCol = pExpr->iColumn;
|
||||
pTab = pSrc->a[0].pTab;
|
||||
|
||||
|
||||
/* If we get to here, it means the query is of the correct form.
|
||||
** Check to make sure we have an index and make pIdx point to the
|
||||
** appropriate index. If the min() or max() is on an INTEGER PRIMARY
|
||||
@@ -2282,10 +2208,7 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
|
||||
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr);
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
assert( pIdx->nColumn>=1 );
|
||||
if( pIdx->aiColumn[0]==iCol &&
|
||||
0==sqlite3StrICmp(pIdx->azColl[0], pColl->zName) ){
|
||||
break;
|
||||
}
|
||||
if( pIdx->aiColumn[0]==iCol && pIdx->keyInfo.aColl[0]==pColl ) break;
|
||||
}
|
||||
if( pIdx==0 ) return 0;
|
||||
}
|
||||
@@ -2308,16 +2231,13 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
|
||||
** the min() or max() is on the INTEGER PRIMARY KEY, then find the first
|
||||
** or last entry in the main table.
|
||||
*/
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
assert( iDb>=0 || pTab->isTransient );
|
||||
sqlite3CodeVerifySchema(pParse, iDb);
|
||||
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
|
||||
sqlite3CodeVerifySchema(pParse, pTab->iDb);
|
||||
base = pSrc->a[0].iCursor;
|
||||
brk = sqlite3VdbeMakeLabel(v);
|
||||
computeLimitRegisters(pParse, p, brk);
|
||||
computeLimitRegisters(pParse, p);
|
||||
if( pSrc->a[0].pSelect==0 ){
|
||||
sqlite3OpenTable(pParse, base, iDb, pTab, OP_OpenRead);
|
||||
sqlite3OpenTableForReading(v, base, pTab);
|
||||
}
|
||||
cont = sqlite3VdbeMakeLabel(v);
|
||||
if( pIdx==0 ){
|
||||
sqlite3VdbeAddOp(v, seekOp, base, 0);
|
||||
}else{
|
||||
@@ -2328,12 +2248,10 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
|
||||
** "INSERT INTO x SELECT max() FROM x".
|
||||
*/
|
||||
int iIdx;
|
||||
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
|
||||
iIdx = pParse->nTab++;
|
||||
assert( pIdx->pSchema==pTab->pSchema );
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
sqlite3VdbeOp3(v, OP_OpenRead, iIdx, pIdx->tnum,
|
||||
(char*)pKey, P3_KEYINFO_HANDOFF);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqlite3VdbeOp3(v, OP_OpenRead, iIdx, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
if( seekOp==OP_Rewind ){
|
||||
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, 1, 0);
|
||||
@@ -2348,8 +2266,8 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
|
||||
memset(&eListItem, 0, sizeof(eListItem));
|
||||
eList.a = &eListItem;
|
||||
eList.a[0].pExpr = pExpr;
|
||||
selectInnerLoop(pParse, p, &eList, 0, 0, 0, -1, eDest, iParm, brk, brk, 0);
|
||||
sqlite3VdbeResolveLabel(v, brk);
|
||||
selectInnerLoop(pParse, p, &eList, 0, 0, 0, -1, eDest, iParm, cont, cont, 0);
|
||||
sqlite3VdbeResolveLabel(v, cont);
|
||||
sqlite3VdbeAddOp(v, OP_Close, base, 0);
|
||||
|
||||
return 1;
|
||||
@@ -2438,8 +2356,14 @@ int sqlite3SelectResolve(
|
||||
/* Resolve the expressions in the LIMIT and OFFSET clauses. These
|
||||
** are not allowed to refer to any names, so pass an empty NameContext.
|
||||
*/
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pParse;
|
||||
sNC.hasAgg = 0;
|
||||
sNC.nErr = 0;
|
||||
sNC.nRef = 0;
|
||||
sNC.pEList = 0;
|
||||
sNC.allowAgg = 0;
|
||||
sNC.pSrcList = 0;
|
||||
sNC.pNext = 0;
|
||||
if( sqlite3ExprResolveNames(&sNC, p->pLimit) ||
|
||||
sqlite3ExprResolveNames(&sNC, p->pOffset) ){
|
||||
return SQLITE_ERROR;
|
||||
@@ -2691,11 +2615,8 @@ int sqlite3Select(
|
||||
int rc = 1; /* Value to return from this function */
|
||||
int addrSortIndex; /* Address of an OP_OpenVirtual instruction */
|
||||
AggInfo sAggInfo; /* Information used by aggregate queries */
|
||||
int iEnd; /* Address of the end of the query */
|
||||
|
||||
if( p==0 || sqlite3ThreadDataReadOnly()->mallocFailed || pParse->nErr ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3_malloc_failed || pParse->nErr || p==0 ) return 1;
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
|
||||
memset(&sAggInfo, 0, sizeof(sAggInfo));
|
||||
|
||||
@@ -2742,6 +2663,7 @@ int sqlite3Select(
|
||||
/* If writing to memory or generating a set
|
||||
** only a single column may be output.
|
||||
*/
|
||||
assert( eDest!=SRT_Exists || pEList->nExpr==1 );
|
||||
#ifndef SQLITE_OMIT_SUBQUERY
|
||||
if( (eDest==SRT_Mem || eDest==SRT_Set) && pEList->nExpr>1 ){
|
||||
sqlite3ErrorMsg(pParse, "only a single result allowed for "
|
||||
@@ -2850,8 +2772,7 @@ int sqlite3Select(
|
||||
|
||||
/* Set the limiter.
|
||||
*/
|
||||
iEnd = sqlite3VdbeMakeLabel(v);
|
||||
computeLimitRegisters(pParse, p, iEnd);
|
||||
computeLimitRegisters(pParse, p);
|
||||
|
||||
/* If the output is destined for a temporary table, open that table.
|
||||
*/
|
||||
@@ -2859,6 +2780,15 @@ int sqlite3Select(
|
||||
sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, pEList->nExpr);
|
||||
}
|
||||
|
||||
|
||||
/* Initialize the memory cell to NULL for SRT_Mem or 0 for SRT_Exists
|
||||
*/
|
||||
if( eDest==SRT_Mem ){
|
||||
sqlite3VdbeAddOp(v, OP_MemNull, iParm, 0);
|
||||
}else if( eDest==SRT_Exists ){
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, iParm);
|
||||
}
|
||||
|
||||
/* Open a virtual index to use for the distinct set.
|
||||
*/
|
||||
if( isDistinct ){
|
||||
@@ -2949,7 +2879,7 @@ int sqlite3Select(
|
||||
goto select_end;
|
||||
}
|
||||
}
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ) goto select_end;
|
||||
if( sqlite3_malloc_failed ) goto select_end;
|
||||
|
||||
/* Processing for aggregates with GROUP BY is very different and
|
||||
** much more complex tha aggregates without a GROUP BY.
|
||||
@@ -3182,10 +3112,6 @@ int sqlite3Select(
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Jump here to skip this query
|
||||
*/
|
||||
sqlite3VdbeResolveLabel(v, iEnd);
|
||||
|
||||
/* The SELECT was successfully coded. Set the return code to 0
|
||||
** to indicate no errors.
|
||||
*/
|
||||
|
||||
-485
@@ -1,485 +0,0 @@
|
||||
/*
|
||||
** 2006 January 07
|
||||
**
|
||||
** 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 demonstration code. Nothing in this file gets compiled
|
||||
** or linked into the SQLite library unless you use a non-standard option:
|
||||
**
|
||||
** -DSQLITE_SERVER=1
|
||||
**
|
||||
** The configure script will never generate a Makefile with the option
|
||||
** above. You will need to manually modify the Makefile if you want to
|
||||
** include any of the code from this file in your project. Or, at your
|
||||
** option, you may copy and paste the code from this file and
|
||||
** thereby avoiding a recompile of SQLite.
|
||||
**
|
||||
**
|
||||
** This source file demonstrates how to use SQLite to create an SQL database
|
||||
** server thread in a multiple-threaded program. One or more client threads
|
||||
** send messages to the server thread and the server thread processes those
|
||||
** messages in the order received and returns the results to the client.
|
||||
**
|
||||
** One might ask: "Why bother? Why not just let each thread connect
|
||||
** to the database directly?" There are a several of reasons to
|
||||
** prefer the client/server approach.
|
||||
**
|
||||
** (1) Some systems (ex: Redhat9) have broken threading implementations
|
||||
** that prevent SQLite database connections from being used in
|
||||
** a thread different from the one where they were created. With
|
||||
** the client/server approach, all database connections are created
|
||||
** and used within the server thread. Client calls to the database
|
||||
** can be made from multiple threads (though not at the same time!)
|
||||
**
|
||||
** (2) Beginning with SQLite version 3.3.0, when two or more
|
||||
** connections to the same database occur within the same thread,
|
||||
** they can optionally share their database cache. This reduces
|
||||
** I/O and memory requirements. Cache shared is controlled using
|
||||
** the sqlite3_enable_shared_cache() API.
|
||||
**
|
||||
** (3) Database connections on a shared cache use table-level locking
|
||||
** instead of file-level locking for improved concurrency.
|
||||
**
|
||||
** (4) Database connections on a shared cache can by optionally
|
||||
** set to READ UNCOMMITTED isolation. (The default isolation for
|
||||
** SQLite is SERIALIZABLE.) When this occurs, readers will
|
||||
** never be blocked by a writer and writers will not be
|
||||
** blocked by readers. There can still only be a single writer
|
||||
** at a time, but multiple readers can simultaneously exist with
|
||||
** that writer. This is a huge increase in concurrency.
|
||||
**
|
||||
** To summarize the rational for using a client/server approach: prior
|
||||
** to SQLite version 3.3.0 it probably was not worth the trouble. But
|
||||
** with SQLite version 3.3.0 and beyond you can get significant performance
|
||||
** and concurrency improvements and memory usage reductions by going
|
||||
** client/server.
|
||||
**
|
||||
** Note: The extra features of version 3.3.0 described by points (2)
|
||||
** through (4) above are only available if you compile without the
|
||||
** option -DSQLITE_OMIT_SHARED_CACHE.
|
||||
**
|
||||
** Here is how the client/server approach works: The database server
|
||||
** thread is started on this procedure:
|
||||
**
|
||||
** void *sqlite3_server(void *NotUsed);
|
||||
**
|
||||
** The sqlite_server procedure runs as long as the g.serverHalt variable
|
||||
** is false. A mutex is used to make sure no more than one server runs
|
||||
** at a time. The server waits for messages to arrive on a message
|
||||
** queue and processes the messages in order.
|
||||
**
|
||||
** Two convenience routines are provided for starting and stopping the
|
||||
** server thread:
|
||||
**
|
||||
** void sqlite3_server_start(void);
|
||||
** void sqlite3_server_stop(void);
|
||||
**
|
||||
** Both of the convenience routines return immediately. Neither will
|
||||
** ever give an error. If a server is already started or already halted,
|
||||
** then the routines are effectively no-ops.
|
||||
**
|
||||
** Clients use the following interfaces:
|
||||
**
|
||||
** sqlite3_client_open
|
||||
** sqlite3_client_prepare
|
||||
** sqlite3_client_step
|
||||
** sqlite3_client_reset
|
||||
** sqlite3_client_finalize
|
||||
** sqlite3_client_close
|
||||
**
|
||||
** These interfaces work exactly like the standard core SQLite interfaces
|
||||
** having the same names without the "_client_" infix. Many other SQLite
|
||||
** interfaces can be used directly without having to send messages to the
|
||||
** server as long as SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined.
|
||||
** The following interfaces fall into this second category:
|
||||
**
|
||||
** sqlite3_bind_*
|
||||
** sqlite3_changes
|
||||
** sqlite3_clear_bindings
|
||||
** sqlite3_column_*
|
||||
** sqlite3_complete
|
||||
** sqlite3_create_collation
|
||||
** sqlite3_create_function
|
||||
** sqlite3_data_count
|
||||
** sqlite3_db_handle
|
||||
** sqlite3_errcode
|
||||
** sqlite3_errmsg
|
||||
** sqlite3_last_insert_rowid
|
||||
** sqlite3_total_changes
|
||||
** sqlite3_transfer_bindings
|
||||
**
|
||||
** A single SQLite connection (an sqlite3* object) or an SQLite statement
|
||||
** (an sqlite3_stmt* object) should only be passed to a single interface
|
||||
** function at a time. The connections and statements can be passed from
|
||||
** any thread to any of the functions listed in the second group above as
|
||||
** long as the same connection is not in use by two threads at once and
|
||||
** as long as SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined. Additional
|
||||
** information about the SQLITE_ENABLE_MEMORY_MANAGEMENT constraint is
|
||||
** below.
|
||||
**
|
||||
** The busy handler for all database connections should remain turned
|
||||
** off. That means that any lock contention will cause the associated
|
||||
** sqlite3_client_step() call to return immediately with an SQLITE_BUSY
|
||||
** error code. If a busy handler is enabled and lock contention occurs,
|
||||
** then the entire server thread will block. This will cause not only
|
||||
** the requesting client to block but every other database client as
|
||||
** well. It is possible to enhance the code below so that lock
|
||||
** contention will cause the message to be placed back on the top of
|
||||
** the queue to be tried again later. But such enhanced processing is
|
||||
** not included here, in order to keep the example simple.
|
||||
**
|
||||
** This example code assumes the use of pthreads. Pthreads
|
||||
** implementations are available for windows. (See, for example
|
||||
** http://sourceware.org/pthreads-win32/announcement.html.) Or, you
|
||||
** can translate the locking and thread synchronization code to use
|
||||
** windows primitives easily enough. The details are left as an
|
||||
** exercise to the reader.
|
||||
**
|
||||
**** Restrictions Associated With SQLITE_ENABLE_MEMORY_MANAGEMENT ****
|
||||
**
|
||||
** If you compile with SQLITE_ENABLE_MEMORY_MANAGEMENT defined, then
|
||||
** SQLite includes code that tracks how much memory is being used by
|
||||
** each thread. These memory counts can become confused if memory
|
||||
** is allocated by one thread and then freed by another. For that
|
||||
** reason, when SQLITE_ENABLE_MEMORY_MANAGEMENT is used, all operations
|
||||
** that might allocate or free memory should be performanced in the same
|
||||
** thread that originally created the database connection. In that case,
|
||||
** many of the operations that are listed above as safe to be performed
|
||||
** in separate threads would need to be sent over to the server to be
|
||||
** done there. If SQLITE_ENABLE_MEMORY_MANAGEMENT is defined, then
|
||||
** the following functions can be used safely from different threads
|
||||
** without messing up the allocation counts:
|
||||
**
|
||||
** sqlite3_bind_parameter_name
|
||||
** sqlite3_bind_parameter_index
|
||||
** sqlite3_changes
|
||||
** sqlite3_column_blob
|
||||
** sqlite3_column_count
|
||||
** sqlite3_complete
|
||||
** sqlite3_data_count
|
||||
** sqlite3_db_handle
|
||||
** sqlite3_errcode
|
||||
** sqlite3_errmsg
|
||||
** sqlite3_last_insert_rowid
|
||||
** sqlite3_total_changes
|
||||
**
|
||||
** The remaining functions are not thread-safe when memory management
|
||||
** is enabled. So one would have to define some new interface routines
|
||||
** along the following lines:
|
||||
**
|
||||
** sqlite3_client_bind_*
|
||||
** sqlite3_client_clear_bindings
|
||||
** sqlite3_client_column_*
|
||||
** sqlite3_client_create_collation
|
||||
** sqlite3_client_create_function
|
||||
** sqlite3_client_transfer_bindings
|
||||
**
|
||||
** The example code in this file is intended for use with memory
|
||||
** management turned off. So the implementation of these additional
|
||||
** client interfaces is left as an exercise to the reader.
|
||||
**
|
||||
** It may seem surprising to the reader that the list of safe functions
|
||||
** above does not include things like sqlite3_bind_int() or
|
||||
** sqlite3_column_int(). But those routines might, in fact, allocate
|
||||
** or deallocate memory. In the case of sqlite3_bind_int(), if the
|
||||
** parameter was previously bound to a string that string might need
|
||||
** to be deallocated before the new integer value is inserted. In
|
||||
** the case of sqlite3_column_int(), the value of the column might be
|
||||
** a UTF-16 string which will need to be converted to UTF-8 then into
|
||||
** an integer.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Only compile the code in this file on UNIX with a THREADSAFE build
|
||||
** and only if the SQLITE_SERVER macro is defined.
|
||||
*/
|
||||
#ifdef SQLITE_SERVER
|
||||
#if defined(OS_UNIX) && OS_UNIX && defined(THREADSAFE) && THREADSAFE
|
||||
|
||||
/*
|
||||
** We require only pthreads and the public interface of SQLite.
|
||||
*/
|
||||
#include <pthread.h>
|
||||
#include "sqlite3.h"
|
||||
|
||||
/*
|
||||
** Messages are passed from client to server and back again as
|
||||
** instances of the following structure.
|
||||
*/
|
||||
typedef struct SqlMessage SqlMessage;
|
||||
struct SqlMessage {
|
||||
int op; /* Opcode for the message */
|
||||
sqlite3 *pDb; /* The SQLite connection */
|
||||
sqlite3_stmt *pStmt; /* A specific statement */
|
||||
int errCode; /* Error code returned */
|
||||
const char *zIn; /* Input filename or SQL statement */
|
||||
int nByte; /* Size of the zIn parameter for prepare() */
|
||||
const char *zOut; /* Tail of the SQL statement */
|
||||
SqlMessage *pNext; /* Next message in the queue */
|
||||
SqlMessage *pPrev; /* Previous message in the queue */
|
||||
pthread_mutex_t clientMutex; /* Hold this mutex to access the message */
|
||||
pthread_cond_t clientWakeup; /* Signal to wake up the client */
|
||||
};
|
||||
|
||||
/*
|
||||
** Legal values for SqlMessage.op
|
||||
*/
|
||||
#define MSG_Open 1 /* sqlite3_open(zIn, &pDb) */
|
||||
#define MSG_Prepare 2 /* sqlite3_prepare(pDb, zIn, nByte, &pStmt, &zOut) */
|
||||
#define MSG_Step 3 /* sqlite3_step(pStmt) */
|
||||
#define MSG_Reset 4 /* sqlite3_reset(pStmt) */
|
||||
#define MSG_Finalize 5 /* sqlite3_finalize(pStmt) */
|
||||
#define MSG_Close 6 /* sqlite3_close(pDb) */
|
||||
#define MSG_Done 7 /* Server has finished with this message */
|
||||
|
||||
|
||||
/*
|
||||
** State information about the server is stored in a static variable
|
||||
** named "g" as follows:
|
||||
*/
|
||||
static struct ServerState {
|
||||
pthread_mutex_t queueMutex; /* Hold this mutex to access the msg queue */
|
||||
pthread_mutex_t serverMutex; /* Held by the server while it is running */
|
||||
pthread_cond_t serverWakeup; /* Signal this condvar to wake up the server */
|
||||
volatile int serverHalt; /* Server halts itself when true */
|
||||
SqlMessage *pQueueHead; /* Head of the message queue */
|
||||
SqlMessage *pQueueTail; /* Tail of the message queue */
|
||||
} g = {
|
||||
PTHREAD_MUTEX_INITIALIZER,
|
||||
PTHREAD_MUTEX_INITIALIZER,
|
||||
PTHREAD_COND_INITIALIZER,
|
||||
};
|
||||
|
||||
/*
|
||||
** Send a message to the server. Block until we get a reply.
|
||||
**
|
||||
** The mutex and condition variable in the message are uninitialized
|
||||
** when this routine is called. This routine takes care of
|
||||
** initializing them and destroying them when it has finished.
|
||||
*/
|
||||
static void sendToServer(SqlMessage *pMsg){
|
||||
/* Initialize the mutex and condition variable on the message
|
||||
*/
|
||||
pthread_mutex_init(&pMsg->clientMutex, 0);
|
||||
pthread_cond_init(&pMsg->clientWakeup, 0);
|
||||
|
||||
/* Add the message to the head of the server's message queue.
|
||||
*/
|
||||
pthread_mutex_lock(&g.queueMutex);
|
||||
pMsg->pNext = g.pQueueHead;
|
||||
if( g.pQueueHead==0 ){
|
||||
g.pQueueTail = pMsg;
|
||||
}else{
|
||||
g.pQueueHead->pPrev = pMsg;
|
||||
}
|
||||
pMsg->pPrev = 0;
|
||||
g.pQueueHead = pMsg;
|
||||
pthread_mutex_unlock(&g.queueMutex);
|
||||
|
||||
/* Signal the server that the new message has be queued, then
|
||||
** block waiting for the server to process the message.
|
||||
*/
|
||||
pthread_mutex_lock(&pMsg->clientMutex);
|
||||
pthread_cond_signal(&g.serverWakeup);
|
||||
while( pMsg->op!=MSG_Done ){
|
||||
pthread_cond_wait(&pMsg->clientWakeup, &pMsg->clientMutex);
|
||||
}
|
||||
pthread_mutex_unlock(&pMsg->clientMutex);
|
||||
|
||||
/* Destroy the mutex and condition variable of the message.
|
||||
*/
|
||||
pthread_mutex_destroy(&pMsg->clientMutex);
|
||||
pthread_cond_destroy(&pMsg->clientWakeup);
|
||||
}
|
||||
|
||||
/*
|
||||
** The following 6 routines are client-side implementations of the
|
||||
** core SQLite interfaces:
|
||||
**
|
||||
** sqlite3_open
|
||||
** sqlite3_prepare
|
||||
** sqlite3_step
|
||||
** sqlite3_reset
|
||||
** sqlite3_finalize
|
||||
** sqlite3_close
|
||||
**
|
||||
** Clients should use the following client-side routines instead of
|
||||
** the core routines above.
|
||||
**
|
||||
** sqlite3_client_open
|
||||
** sqlite3_client_prepare
|
||||
** sqlite3_client_step
|
||||
** sqlite3_client_reset
|
||||
** sqlite3_client_finalize
|
||||
** sqlite3_client_close
|
||||
**
|
||||
** Each of these routines creates a message for the desired operation,
|
||||
** sends that message to the server, waits for the server to process
|
||||
** then message and return a response.
|
||||
*/
|
||||
int sqlite3_client_open(const char *zDatabaseName, sqlite3 **ppDb){
|
||||
SqlMessage msg;
|
||||
msg.op = MSG_Open;
|
||||
msg.zIn = zDatabaseName;
|
||||
sendToServer(&msg);
|
||||
*ppDb = msg.pDb;
|
||||
return msg.errCode;
|
||||
}
|
||||
int sqlite3_client_prepare(
|
||||
sqlite3 *pDb,
|
||||
const char *zSql,
|
||||
int nByte,
|
||||
sqlite3_stmt **ppStmt,
|
||||
const char **pzTail
|
||||
){
|
||||
SqlMessage msg;
|
||||
msg.op = MSG_Prepare;
|
||||
msg.pDb = pDb;
|
||||
msg.zIn = zSql;
|
||||
msg.nByte = nByte;
|
||||
sendToServer(&msg);
|
||||
*ppStmt = msg.pStmt;
|
||||
if( pzTail ) *pzTail = msg.zOut;
|
||||
return msg.errCode;
|
||||
}
|
||||
int sqlite3_client_step(sqlite3_stmt *pStmt){
|
||||
SqlMessage msg;
|
||||
msg.op = MSG_Step;
|
||||
msg.pStmt = pStmt;
|
||||
sendToServer(&msg);
|
||||
return msg.errCode;
|
||||
}
|
||||
int sqlite3_client_reset(sqlite3_stmt *pStmt){
|
||||
SqlMessage msg;
|
||||
msg.op = MSG_Reset;
|
||||
msg.pStmt = pStmt;
|
||||
sendToServer(&msg);
|
||||
return msg.errCode;
|
||||
}
|
||||
int sqlite3_client_finalize(sqlite3_stmt *pStmt){
|
||||
SqlMessage msg;
|
||||
msg.op = MSG_Finalize;
|
||||
msg.pStmt = pStmt;
|
||||
sendToServer(&msg);
|
||||
return msg.errCode;
|
||||
}
|
||||
int sqlite3_client_close(sqlite3 *pDb){
|
||||
SqlMessage msg;
|
||||
msg.op = MSG_Close;
|
||||
msg.pDb = pDb;
|
||||
sendToServer(&msg);
|
||||
return msg.errCode;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine implements the server. To start the server, first
|
||||
** make sure g.serverHalt is false, then create a new detached thread
|
||||
** on this procedure. See the sqlite3_server_start() routine below
|
||||
** for an example. This procedure loops until g.serverHalt becomes
|
||||
** true.
|
||||
*/
|
||||
void *sqlite3_server(void *NotUsed){
|
||||
sqlite3_enable_shared_cache(1);
|
||||
if( pthread_mutex_trylock(&g.serverMutex) ){
|
||||
sqlite3_enable_shared_cache(0);
|
||||
return 0; /* Another server is already running */
|
||||
}
|
||||
while( !g.serverHalt ){
|
||||
SqlMessage *pMsg;
|
||||
|
||||
/* Remove the last message from the message queue.
|
||||
*/
|
||||
pthread_mutex_lock(&g.queueMutex);
|
||||
while( g.pQueueTail==0 && g.serverHalt==0 ){
|
||||
pthread_cond_wait(&g.serverWakeup, &g.queueMutex);
|
||||
}
|
||||
pMsg = g.pQueueTail;
|
||||
if( pMsg ){
|
||||
if( pMsg->pPrev ){
|
||||
pMsg->pPrev->pNext = 0;
|
||||
}else{
|
||||
g.pQueueHead = 0;
|
||||
}
|
||||
g.pQueueTail = pMsg->pPrev;
|
||||
}
|
||||
pthread_mutex_unlock(&g.queueMutex);
|
||||
if( pMsg==0 ) break;
|
||||
|
||||
/* Process the message just removed
|
||||
*/
|
||||
pthread_mutex_lock(&pMsg->clientMutex);
|
||||
switch( pMsg->op ){
|
||||
case MSG_Open: {
|
||||
pMsg->errCode = sqlite3_open(pMsg->zIn, &pMsg->pDb);
|
||||
break;
|
||||
}
|
||||
case MSG_Prepare: {
|
||||
pMsg->errCode = sqlite3_prepare(pMsg->pDb, pMsg->zIn, pMsg->nByte,
|
||||
&pMsg->pStmt, &pMsg->zOut);
|
||||
break;
|
||||
}
|
||||
case MSG_Step: {
|
||||
pMsg->errCode = sqlite3_step(pMsg->pStmt);
|
||||
break;
|
||||
}
|
||||
case MSG_Reset: {
|
||||
pMsg->errCode = sqlite3_reset(pMsg->pStmt);
|
||||
break;
|
||||
}
|
||||
case MSG_Finalize: {
|
||||
pMsg->errCode = sqlite3_finalize(pMsg->pStmt);
|
||||
break;
|
||||
}
|
||||
case MSG_Close: {
|
||||
pMsg->errCode = sqlite3_close(pMsg->pDb);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Signal the client that the message has been processed.
|
||||
*/
|
||||
pMsg->op = MSG_Done;
|
||||
pthread_mutex_unlock(&pMsg->clientMutex);
|
||||
pthread_cond_signal(&pMsg->clientWakeup);
|
||||
}
|
||||
pthread_mutex_unlock(&g.serverMutex);
|
||||
sqlite3_thread_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Start a server thread if one is not already running. If there
|
||||
** is aleady a server thread running, the new thread will quickly
|
||||
** die and this routine is effectively a no-op.
|
||||
*/
|
||||
void sqlite3_server_start(void){
|
||||
pthread_t x;
|
||||
int rc;
|
||||
g.serverHalt = 0;
|
||||
rc = pthread_create(&x, 0, sqlite3_server, 0);
|
||||
if( rc==0 ){
|
||||
pthread_detach(x);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** If a server thread is running, then stop it. If no server is
|
||||
** running, this routine is effectively a no-op.
|
||||
**
|
||||
** This routine returns immediately without waiting for the server
|
||||
** thread to stop. But be assured that the server will eventually stop.
|
||||
*/
|
||||
void sqlite3_server_stop(void){
|
||||
g.serverHalt = 1;
|
||||
pthread_cond_broadcast(&g.serverWakeup);
|
||||
}
|
||||
|
||||
#endif /* defined(OS_UNIX) && OS_UNIX && defined(THREADSAFE) && THREADSAFE */
|
||||
#endif /* defined(SQLITE_SERVER) */
|
||||
+4
-5
@@ -12,7 +12,7 @@
|
||||
** This file contains code to implement the "sqlite" command line
|
||||
** utility for accessing SQLite databases.
|
||||
**
|
||||
** $Id: shell.c,v 1.130 2005/12/29 12:53:10 drh Exp $
|
||||
** $Id: shell.c,v 1.128 2005/09/11 02:03:04 drh Exp $
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -81,7 +81,7 @@ static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */
|
||||
/*
|
||||
** Determines if a string is a number of not.
|
||||
*/
|
||||
static int isNumber(const char *z, int *realnum){
|
||||
static int isNumber(const unsigned char *z, int *realnum){
|
||||
if( *z=='-' || *z=='+' ) z++;
|
||||
if( !isdigit(*z) ){
|
||||
return 0;
|
||||
@@ -690,9 +690,8 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
zSelect = appendText(zSelect, " || ' VALUES(' || ", 0);
|
||||
rc = sqlite3_step(pTableInfo);
|
||||
while( rc==SQLITE_ROW ){
|
||||
const char *zText = (const char *)sqlite3_column_text(pTableInfo, 1);
|
||||
zSelect = appendText(zSelect, "quote(", 0);
|
||||
zSelect = appendText(zSelect, zText, '"');
|
||||
zSelect = appendText(zSelect, sqlite3_column_text(pTableInfo, 1), '"');
|
||||
rc = sqlite3_step(pTableInfo);
|
||||
if( rc==SQLITE_ROW ){
|
||||
zSelect = appendText(zSelect, ") || ', ' || ", 0);
|
||||
@@ -830,7 +829,7 @@ static void resolve_backslashes(char *z){
|
||||
}else if( c=='r' ){
|
||||
c = '\r';
|
||||
}else if( c>='0' && c<='7' ){
|
||||
c -= '0';
|
||||
c =- '0';
|
||||
if( z[i+1]>='0' && z[i+1]<='7' ){
|
||||
i++;
|
||||
c = (c<<3) + z[i] - '0';
|
||||
|
||||
+2
-110
@@ -12,7 +12,7 @@
|
||||
** This header file defines the interface that the SQLite library
|
||||
** presents to client programs.
|
||||
**
|
||||
** @(#) $Id: sqlite.h.in,v 1.156 2006/01/12 02:50:10 drh Exp $
|
||||
** @(#) $Id: sqlite.h.in,v 1.141 2005/09/08 10:58:52 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE3_H_
|
||||
#define _SQLITE3_H_
|
||||
@@ -86,13 +86,6 @@ typedef struct sqlite3 sqlite3;
|
||||
typedef unsigned long long int sqlite_uint64;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** If compiling for a processor that lacks floating point support,
|
||||
** substitute integer for floating-point
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_FLOATING_POINT
|
||||
# define double sqlite_int64
|
||||
#endif
|
||||
|
||||
/*
|
||||
** A function to close the database.
|
||||
@@ -192,7 +185,6 @@ int sqlite3_exec(
|
||||
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
|
||||
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
|
||||
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
|
||||
/* end-of-return-codes */
|
||||
|
||||
/*
|
||||
** Each entry in an SQLite table has a unique integer key. (The key is
|
||||
@@ -1259,7 +1251,7 @@ extern char *sqlite3_temp_directory;
|
||||
** This functionality can be omitted from a build by defining the
|
||||
** SQLITE_OMIT_GLOBALRECOVER at compile time.
|
||||
*/
|
||||
int sqlite3_global_recover(void);
|
||||
int sqlite3_global_recover();
|
||||
|
||||
/*
|
||||
** Test to see whether or not the database connection is in autocommit
|
||||
@@ -1277,106 +1269,6 @@ int sqlite3_get_autocommit(sqlite3*);
|
||||
*/
|
||||
sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
|
||||
|
||||
/*
|
||||
** Register a callback function with the database connection identified by the
|
||||
** first argument to be invoked whenever a row is updated, inserted or deleted.
|
||||
** Any callback set by a previous call to this function for the same
|
||||
** database connection is overridden.
|
||||
**
|
||||
** The second argument is a pointer to the function to invoke when a
|
||||
** row is updated, inserted or deleted. The first argument to the callback is
|
||||
** a copy of the third argument to sqlite3_update_hook. The second callback
|
||||
** argument is one of SQLITE_INSERT, SQLITE_DELETE or SQLITE_UPDATE, depending
|
||||
** on the operation that caused the callback to be invoked. The third and
|
||||
** fourth arguments to the callback contain pointers to the database and
|
||||
** table name containing the affected row. The final callback parameter is
|
||||
** the rowid of the row. In the case of an update, this is the rowid after
|
||||
** the update takes place.
|
||||
**
|
||||
** The update hook is not invoked when internal system tables are
|
||||
** modified (i.e. sqlite_master and sqlite_sequence).
|
||||
**
|
||||
** If another function was previously registered, its pArg value is returned.
|
||||
** Otherwise NULL is returned.
|
||||
*/
|
||||
void *sqlite3_update_hook(
|
||||
sqlite3*,
|
||||
void(*)(void *,int ,char const *,char const *,sqlite_int64),
|
||||
void*
|
||||
);
|
||||
|
||||
/*
|
||||
** Register a callback to be invoked whenever a transaction is rolled
|
||||
** back.
|
||||
**
|
||||
** The new callback function overrides any existing rollback-hook
|
||||
** callback. If there was an existing callback, then it's pArg value
|
||||
** (the third argument to sqlite3_rollback_hook() when it was registered)
|
||||
** is returned. Otherwise, NULL is returned.
|
||||
**
|
||||
** For the purposes of this API, a transaction is said to have been
|
||||
** rolled back if an explicit "ROLLBACK" statement is executed, or
|
||||
** an error or constraint causes an implicit rollback to occur. The
|
||||
** callback is not invoked if a transaction is automatically rolled
|
||||
** back because the database connection is closed.
|
||||
*/
|
||||
void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
|
||||
|
||||
/*
|
||||
** This function is only available if the library is compiled without
|
||||
** the SQLITE_OMIT_SHARED_CACHE macro defined. It is used to enable or
|
||||
** disable (if the argument is true or false, respectively) the
|
||||
** "shared pager" feature.
|
||||
*/
|
||||
int sqlite3_enable_shared_cache(int);
|
||||
|
||||
/*
|
||||
** Attempt to free N bytes of heap memory by deallocating non-essential
|
||||
** memory allocations held by the database library (example: memory
|
||||
** used to cache database pages to improve performance).
|
||||
**
|
||||
** This function is not a part of standard builds. It is only created
|
||||
** if SQLite is compiled with the SQLITE_ENABLE_MEMORY_MANAGEMENT macro.
|
||||
*/
|
||||
int sqlite3_release_memory(int);
|
||||
|
||||
/*
|
||||
** Place a "soft" limit on the amount of heap memory that may be allocated by
|
||||
** SQLite within the current thread. If an internal allocation is requested
|
||||
** that would exceed the specified limit, sqlite3_release_memory() is invoked
|
||||
** one or more times to free up some space before the allocation is made.
|
||||
**
|
||||
** The limit is called "soft", because if sqlite3_release_memory() cannot free
|
||||
** sufficient memory to prevent the limit from being exceeded, the memory is
|
||||
** allocated anyway and the current operation proceeds.
|
||||
**
|
||||
** This function is only available if the library was compiled with the
|
||||
** SQLITE_ENABLE_MEMORY_MANAGEMENT option set.
|
||||
** memory-management has been enabled.
|
||||
*/
|
||||
void sqlite3_soft_heap_limit(int);
|
||||
|
||||
/*
|
||||
** This routine makes sure that all thread-local storage has been
|
||||
** deallocated for the current thread.
|
||||
**
|
||||
** This routine is not technically necessary. All thread-local storage
|
||||
** will be automatically deallocated once memory-management and
|
||||
** shared-cache are disabled and the soft heap limit has been set
|
||||
** to zero. This routine is provided as a convenience for users who
|
||||
** want to make absolutely sure they have not forgotten something
|
||||
** prior to killing off a thread.
|
||||
*/
|
||||
void sqlite3_thread_cleanup(void);
|
||||
|
||||
/*
|
||||
** Undo the hack that converts floating point types to integer for
|
||||
** builds on processors without floating point support.
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_FLOATING_POINT
|
||||
# undef double
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* End of the 'extern "C"' block */
|
||||
#endif
|
||||
|
||||
+107
-212
@@ -11,18 +11,11 @@
|
||||
*************************************************************************
|
||||
** Internal interface definitions for SQLite.
|
||||
**
|
||||
** @(#) $Id: sqliteInt.h,v 1.467 2006/01/13 06:33:24 danielk1977 Exp $
|
||||
** @(#) $Id: sqliteInt.h,v 1.421 2005/09/19 21:05:49 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITEINT_H_
|
||||
#define _SQLITEINT_H_
|
||||
|
||||
/*
|
||||
** Extra interface definitions for those who need them
|
||||
*/
|
||||
#ifdef SQLITE_EXTRA
|
||||
# include "sqliteExtra.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
|
||||
** Setting NDEBUG makes the code smaller and run faster. So the following
|
||||
@@ -66,18 +59,6 @@
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
** If compiling for a processor that lacks floating point support,
|
||||
** substitute integer for floating-point
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_FLOATING_POINT
|
||||
# define double sqlite_int64
|
||||
# define LONGDOUBLE_TYPE sqlite_int64
|
||||
# define SQLITE_BIG_DBL (0x7fffffffffffffff)
|
||||
# define SQLITE_OMIT_DATETIME_FUNCS 1
|
||||
# define SQLITE_OMIT_TRACE 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The maximum number of in-memory pages to use for the main database
|
||||
** table and for temporary tables. Internally, the MAX_PAGES and
|
||||
@@ -148,15 +129,18 @@
|
||||
#define SQLITE_MAX_VARIABLE_NUMBER 999
|
||||
|
||||
/*
|
||||
** The "file format" number is an integer that is incremented whenever
|
||||
** the VDBE-level file format changes. The following macros define the
|
||||
** the default file format for new databases and the maximum file format
|
||||
** that the library can read.
|
||||
** When building SQLite for embedded systems where memory is scarce,
|
||||
** you can define one or more of the following macros to omit extra
|
||||
** features of the library and thus keep the size of the library to
|
||||
** a minimum.
|
||||
*/
|
||||
#define SQLITE_MAX_FILE_FORMAT 4
|
||||
#ifndef SQLITE_DEFAULT_FILE_FORMAT
|
||||
# define SQLITE_DEFAULT_FILE_FORMAT 4
|
||||
#endif
|
||||
/* #define SQLITE_OMIT_AUTHORIZATION 1 */
|
||||
/* #define SQLITE_OMIT_MEMORYDB 1 */
|
||||
/* #define SQLITE_OMIT_VACUUM 1 */
|
||||
/* #define SQLITE_OMIT_DATETIME_FUNCS 1 */
|
||||
/* #define SQLITE_OMIT_PROGRESS_CALLBACK 1 */
|
||||
/* #define SQLITE_OMIT_AUTOVACUUM */
|
||||
/* #define SQLITE_OMIT_ALTERTABLE */
|
||||
|
||||
/*
|
||||
** Provide a default value for TEMP_STORE in case it is not specified
|
||||
@@ -244,7 +228,6 @@ struct BusyHandler {
|
||||
*/
|
||||
#include "vdbe.h"
|
||||
#include "btree.h"
|
||||
#include "pager.h"
|
||||
|
||||
/*
|
||||
** This macro casts a pointer to an integer. Useful for doing
|
||||
@@ -252,73 +235,53 @@ struct BusyHandler {
|
||||
*/
|
||||
#define Addr(X) ((uptr)X)
|
||||
|
||||
/*
|
||||
** If memory allocation problems are found, recompile with
|
||||
**
|
||||
** -DSQLITE_DEBUG=1
|
||||
**
|
||||
** to enable some sanity checking on malloc() and free(). To
|
||||
** check for memory leaks, recompile with
|
||||
**
|
||||
** -DSQLITE_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_MEMDEBUG
|
||||
# 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__)
|
||||
#else
|
||||
# define sqliteFree sqlite3FreeX
|
||||
# define sqliteMalloc sqlite3Malloc
|
||||
# define sqliteMallocRaw sqlite3MallocRaw
|
||||
# define sqliteRealloc sqlite3Realloc
|
||||
# define sqliteStrDup sqlite3StrDup
|
||||
# define sqliteStrNDup sqlite3StrNDup
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This variable gets set if malloc() ever fails. After it gets set,
|
||||
** the SQLite library shuts down permanently.
|
||||
*/
|
||||
extern int sqlite3_malloc_failed;
|
||||
|
||||
/*
|
||||
** The following global variables are used for testing and debugging
|
||||
** only. They only work if SQLITE_MEMDEBUG is defined.
|
||||
** only. They only work if SQLITE_DEBUG is defined.
|
||||
*/
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
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 */
|
||||
extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
|
||||
#define ENTER_MALLOC (\
|
||||
sqlite3ThreadData()->zFile = __FILE__, sqlite3ThreadData()->iLine = __LINE__ \
|
||||
)
|
||||
#define sqliteMalloc(x) (ENTER_MALLOC, sqlite3Malloc(x))
|
||||
#define sqliteMallocRaw(x) (ENTER_MALLOC, sqlite3MallocRaw(x))
|
||||
#define sqliteRealloc(x,y) (ENTER_MALLOC, sqlite3Realloc(x,y))
|
||||
#define sqliteStrDup(x) (ENTER_MALLOC, sqlite3StrDup(x))
|
||||
#define sqliteStrNDup(x,y) (ENTER_MALLOC, sqlite3StrNDup(x,y))
|
||||
#define sqliteReallocOrFree(x,y) (ENTER_MALLOC, sqlite3ReallocOrFree(x,y))
|
||||
|
||||
#else
|
||||
|
||||
#define sqliteMalloc(x) sqlite3Malloc(x)
|
||||
#define sqliteMallocRaw(x) sqlite3MallocRaw(x)
|
||||
#define sqliteRealloc(x,y) sqlite3Realloc(x,y)
|
||||
#define sqliteStrDup(x) sqlite3StrDup(x)
|
||||
#define sqliteStrNDup(x,y) sqlite3StrNDup(x,y)
|
||||
#define sqliteReallocOrFree(x,y) sqlite3ReallocOrFree(x,y)
|
||||
|
||||
#endif
|
||||
|
||||
#define sqliteFree(x) sqlite3FreeX(x)
|
||||
#define sqliteAllocSize(x) sqlite3AllocSize(x)
|
||||
|
||||
|
||||
/*
|
||||
** An instance of this structure might be allocated to store information
|
||||
** specific to a single thread.
|
||||
**
|
||||
** To avoid a memory leak on windows, the content of this structure is
|
||||
** checked at the conclusion of each API call. If it is all zero, it
|
||||
** is deallocated.
|
||||
*/
|
||||
struct ThreadData {
|
||||
int mallocFailed; /* True after a malloc() has failed */
|
||||
int nRef; /* Number of users */
|
||||
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
int nSoftHeapLimit; /* Suggested max mem allocation. No limit if <0 */
|
||||
int nAlloc; /* Number of bytes currently allocated */
|
||||
Pager *pPager; /* Linked list of all pagers in this thread */
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
u8 useSharedData; /* True if shared pagers and schemas are enabled */
|
||||
BtShared *pBtree; /* Linked list of all currently open BTrees */
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
int nMaxAlloc; /* High water mark of ThreadData.nAlloc */
|
||||
int mallocDisallowed; /* assert() in sqlite3Malloc() if set */
|
||||
int isFail; /* True if all malloc() calls should fail */
|
||||
const char *zFile; /* Filename to associate debugging info with */
|
||||
int iLine; /* Line number to associate debugging info with */
|
||||
void *pFirst; /* Pointer to linked list of allocations */
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
** Name of the master database table. The master database table
|
||||
** is a special table that holds the names and attributes of all
|
||||
@@ -351,7 +314,6 @@ typedef struct AuthContext AuthContext;
|
||||
typedef struct CollSeq CollSeq;
|
||||
typedef struct Column Column;
|
||||
typedef struct Db Db;
|
||||
typedef struct Schema Schema;
|
||||
typedef struct Expr Expr;
|
||||
typedef struct ExprList ExprList;
|
||||
typedef struct FKey FKey;
|
||||
@@ -364,9 +326,7 @@ typedef struct NameContext NameContext;
|
||||
typedef struct Parse Parse;
|
||||
typedef struct Select Select;
|
||||
typedef struct SrcList SrcList;
|
||||
typedef struct ThreadData ThreadData;
|
||||
typedef struct Table Table;
|
||||
typedef struct TableLock TableLock;
|
||||
typedef struct Token Token;
|
||||
typedef struct TriggerStack TriggerStack;
|
||||
typedef struct TriggerStep TriggerStep;
|
||||
@@ -384,37 +344,28 @@ typedef struct WhereLevel WhereLevel;
|
||||
struct Db {
|
||||
char *zName; /* Name of this database */
|
||||
Btree *pBt; /* The B*Tree structure for this database file */
|
||||
u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */
|
||||
u8 safety_level; /* How aggressive at synching data to disk */
|
||||
void *pAux; /* Auxiliary data. Usually NULL */
|
||||
void (*xFreeAux)(void*); /* Routine to free pAux */
|
||||
Schema *pSchema; /* Pointer to database schema (possibly shared) */
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of the following structure stores a database schema.
|
||||
*/
|
||||
struct Schema {
|
||||
int schema_cookie; /* Database schema version number for this file */
|
||||
Hash tblHash; /* All tables indexed by name */
|
||||
Hash idxHash; /* All (named) indices indexed by name */
|
||||
Hash trigHash; /* All triggers indexed by name */
|
||||
Hash aFKey; /* Foreign keys indexed by to-table */
|
||||
Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
|
||||
u8 file_format; /* Schema format version for this file */
|
||||
u8 enc; /* Text encoding used by this database */
|
||||
u16 flags; /* Flags associated with this schema */
|
||||
u16 flags; /* Flags associated with this database */
|
||||
u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */
|
||||
u8 safety_level; /* How aggressive at synching data to disk */
|
||||
int cache_size; /* Number of pages to use in the cache */
|
||||
Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
|
||||
void *pAux; /* Auxiliary data. Usually NULL */
|
||||
void (*xFreeAux)(void*); /* Routine to free pAux */
|
||||
};
|
||||
|
||||
/*
|
||||
** These macros can be used to test, set, or clear bits in the
|
||||
** Db.flags field.
|
||||
*/
|
||||
#define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))==(P))
|
||||
#define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))!=0)
|
||||
#define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->flags|=(P)
|
||||
#define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->flags&=~(P)
|
||||
#define DbHasProperty(D,I,P) (((D)->aDb[I].flags&(P))==(P))
|
||||
#define DbHasAnyProperty(D,I,P) (((D)->aDb[I].flags&(P))!=0)
|
||||
#define DbSetProperty(D,I,P) (D)->aDb[I].flags|=(P)
|
||||
#define DbClearProperty(D,I,P) (D)->aDb[I].flags&=~(P)
|
||||
|
||||
/*
|
||||
** Allowed values for the DB.flags field.
|
||||
@@ -428,7 +379,6 @@ struct Schema {
|
||||
*/
|
||||
#define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
|
||||
#define DB_UnresetViews 0x0002 /* Some views have defined column names */
|
||||
#define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */
|
||||
|
||||
#define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
|
||||
|
||||
@@ -463,7 +413,9 @@ struct sqlite3 {
|
||||
Db *aDb; /* All backends */
|
||||
int flags; /* Miscellanous flags. See below */
|
||||
int errCode; /* Most recent error code (SQLITE_*) */
|
||||
u8 enc; /* Text encoding for this database. */
|
||||
u8 autoCommit; /* The auto-commit flag. */
|
||||
u8 file_format; /* What file format version is this database? */
|
||||
u8 temp_store; /* 1: file 2: memory 0: default */
|
||||
int nTable; /* Number of tables in the database */
|
||||
CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
|
||||
@@ -483,15 +435,12 @@ struct sqlite3 {
|
||||
void *pTraceArg; /* Argument to the trace function */
|
||||
void (*xProfile)(void*,const char*,u64); /* Profiling function */
|
||||
void *pProfileArg; /* Argument to profile function */
|
||||
void *pCommitArg; /* Argument to xCommitCallback() */
|
||||
int (*xCommitCallback)(void*); /* Invoked at every commit. */
|
||||
void *pRollbackArg; /* Argument to xRollbackCallback() */
|
||||
void (*xRollbackCallback)(void*); /* Invoked at every commit. */
|
||||
void *pUpdateArg;
|
||||
void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
|
||||
void *pCommitArg; /* Argument to xCommitCallback() */
|
||||
int (*xCommitCallback)(void*);/* Invoked at every commit. */
|
||||
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-16 encoded) */
|
||||
@@ -518,8 +467,6 @@ struct sqlite3 {
|
||||
#endif
|
||||
};
|
||||
|
||||
#define ENC(db) ((db)->aDb[0].pSchema->enc)
|
||||
|
||||
/*
|
||||
** Possible values for the sqlite.flags and or Db.flags fields.
|
||||
**
|
||||
@@ -528,6 +475,7 @@ struct sqlite3 {
|
||||
** transaction is active on that particular database file.
|
||||
*/
|
||||
#define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
|
||||
#define SQLITE_Initialized 0x00000002 /* True after initialization */
|
||||
#define SQLITE_Interrupt 0x00000004 /* Cancel current operation */
|
||||
#define SQLITE_InTrans 0x00000008 /* True if in a transaction */
|
||||
#define SQLITE_InternChanges 0x00000010 /* Uncommitted Hash table changes */
|
||||
@@ -543,9 +491,6 @@ struct sqlite3 {
|
||||
#define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */
|
||||
#define SQLITE_NoReadlock 0x00001000 /* Readlocks are omitted when
|
||||
** accessing read-only databases */
|
||||
#define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */
|
||||
#define SQLITE_ReadUncommitted 0x00004000 /* For shared-cache mode */
|
||||
#define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */
|
||||
|
||||
/*
|
||||
** Possible values for the sqlite.magic field.
|
||||
@@ -590,7 +535,7 @@ struct Column {
|
||||
char *zName; /* Name of this column */
|
||||
Expr *pDflt; /* Default value of this column */
|
||||
char *zType; /* Data type for this column */
|
||||
char *zColl; /* Collating sequence. If NULL, use the default */
|
||||
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 */
|
||||
@@ -606,7 +551,7 @@ struct Column {
|
||||
** 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
|
||||
** translations, if any.
|
||||
** 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.
|
||||
@@ -641,25 +586,12 @@ struct CollSeq {
|
||||
|
||||
/*
|
||||
** Column affinity types.
|
||||
**
|
||||
** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
|
||||
** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve
|
||||
** the speed a little by number the values consecutively.
|
||||
**
|
||||
** But rather than start with 0 or 1, we begin with 'a'. That way,
|
||||
** when multiple affinity types are concatenated into a string and
|
||||
** used as the P3 operand, they will be more readable.
|
||||
**
|
||||
** Note also that the numeric types are grouped together so that testing
|
||||
** for a numeric type is a single comparison.
|
||||
*/
|
||||
#define SQLITE_AFF_TEXT 'a'
|
||||
#define SQLITE_AFF_NONE 'b'
|
||||
#define SQLITE_AFF_NUMERIC 'c'
|
||||
#define SQLITE_AFF_INTEGER 'd'
|
||||
#define SQLITE_AFF_REAL 'e'
|
||||
#define SQLITE_AFF_INTEGER 'i'
|
||||
#define SQLITE_AFF_NUMERIC 'n'
|
||||
#define SQLITE_AFF_TEXT 't'
|
||||
#define SQLITE_AFF_NONE 'o'
|
||||
|
||||
#define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
|
||||
|
||||
/*
|
||||
** Each SQL table is represented in memory by an instance of the
|
||||
@@ -700,7 +632,7 @@ struct Table {
|
||||
int tnum; /* Root BTree node for this table (see note above) */
|
||||
Select *pSelect; /* NULL for tables. Points to definition if a view. */
|
||||
u8 readOnly; /* True if this table should not be written by the user */
|
||||
// u8 iDb; /* Index into sqlite.aDb[] of the backend for this table */
|
||||
u8 iDb; /* Index into sqlite.aDb[] of the backend for this table */
|
||||
u8 isTransient; /* True if automatically deleted when VDBE finishes */
|
||||
u8 hasPrimKey; /* True if there exists a primary key */
|
||||
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
|
||||
@@ -709,13 +641,9 @@ struct Table {
|
||||
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 */
|
||||
#ifndef SQLITE_OMIT_CHECK
|
||||
Expr *pCheck; /* The AND of all CHECK constraints */
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_ALTERTABLE
|
||||
int addColOffset; /* Offset in CREATE TABLE statement to add a new column */
|
||||
#endif
|
||||
Schema *pSchema;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -851,11 +779,10 @@ struct Index {
|
||||
int tnum; /* Page containing root of this index in database file */
|
||||
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 */
|
||||
Schema *pSchema; /* Schema containing this index */
|
||||
u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
|
||||
char **azColl; /* Array of collation sequence names for index */
|
||||
KeyInfo keyInfo; /* Info on how to order keys. MUST BE LAST */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -964,7 +891,7 @@ struct AggInfo {
|
||||
struct Expr {
|
||||
u8 op; /* Operation performed by this node */
|
||||
char affinity; /* The affinity of the column or 0 if not a column */
|
||||
//u8 iDb; /* Database referenced by this expression */
|
||||
u8 iDb; /* Database referenced by this expression */
|
||||
u8 flags; /* Various flags. See below */
|
||||
CollSeq *pColl; /* The collation type of the column or 0 */
|
||||
Expr *pLeft, *pRight; /* Left and right subnodes */
|
||||
@@ -980,7 +907,6 @@ struct Expr {
|
||||
Select *pSelect; /* When the expression is a sub-select. Also the
|
||||
** right side of "<expr> IN (<select>)" */
|
||||
Table *pTab; /* Table for OP_Column expressions. */
|
||||
Schema *pSchema;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -1161,7 +1087,6 @@ struct NameContext {
|
||||
int nErr; /* Number of errors encountered while resolving names */
|
||||
u8 allowAgg; /* Aggregate functions allowed here */
|
||||
u8 hasAgg; /* True if aggregates are seen */
|
||||
u8 isCheck; /* True if resolving names in a CHECK constraint */
|
||||
int nDepth; /* Depth of subquery recursion. 1 for no recursion */
|
||||
AggInfo *pAggInfo; /* Information about aggregates at this level */
|
||||
NameContext *pNext; /* Next outer name context. NULL for outermost */
|
||||
@@ -1224,7 +1149,7 @@ struct Select {
|
||||
#define SRT_Table 7 /* Store result as data with an automatic rowid */
|
||||
#define SRT_VirtualTab 8 /* Create virtual table and store like SRT_Table */
|
||||
#define SRT_Subroutine 9 /* Call a subroutine to handle results */
|
||||
#define SRT_Exists 10 /* Store 1 if the result is not empty */
|
||||
#define SRT_Exists 10 /* Put 0 or 1 in a memory cell */
|
||||
|
||||
/*
|
||||
** An SQL parser context. A copy of this structure is passed through
|
||||
@@ -1235,12 +1160,6 @@ struct Select {
|
||||
** generate call themselves recursively, the first part of the structure
|
||||
** is constant but the second part is reset at the beginning and end of
|
||||
** each recursion.
|
||||
**
|
||||
** The nTableLock and aTableLock variables are only used if the shared-cache
|
||||
** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are
|
||||
** used to store the set of table-locks required by the statement being
|
||||
** compiled. Function sqlite3TableLock() is used to add entries to the
|
||||
** list.
|
||||
*/
|
||||
struct Parse {
|
||||
sqlite3 *db; /* The main database structure */
|
||||
@@ -1255,16 +1174,10 @@ struct Parse {
|
||||
int nTab; /* Number of previously allocated VDBE cursors */
|
||||
int nMem; /* Number of memory cells used so far */
|
||||
int nSet; /* Number of sets used so far */
|
||||
int ckOffset; /* Stack offset to data used by CHECK constraints */
|
||||
u32 writeMask; /* Start a write transaction on these databases */
|
||||
u32 cookieMask; /* Bitmask of schema verified databases */
|
||||
ThreadData *pTsd; /* Thread specific data for this thread */
|
||||
int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
|
||||
int cookieValue[MAX_ATTACHED+2]; /* Values of cookies to verify */
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
int nTableLock; /* Number of locks in aTableLock */
|
||||
TableLock *aTableLock; /* Required table locks for shared-cache mode */
|
||||
#endif
|
||||
|
||||
/* Above is constant between recursions. Below is reset before and after
|
||||
** each recursion */
|
||||
@@ -1299,7 +1212,6 @@ struct AuthContext {
|
||||
*/
|
||||
#define OPFLAG_NCHANGE 1 /* Set to update db->nChange */
|
||||
#define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */
|
||||
#define OPFLAG_ISUPDATE 4 /* This OP_Insert is an sql UPDATE */
|
||||
|
||||
/*
|
||||
* Each trigger present in the database schema is stored as an instance of
|
||||
@@ -1319,6 +1231,8 @@ struct AuthContext {
|
||||
struct Trigger {
|
||||
char *name; /* The name of the trigger */
|
||||
char *table; /* The table or view to which the trigger applies */
|
||||
u8 iDb; /* Database containing this trigger */
|
||||
u8 iTabDb; /* Database containing Trigger.table */
|
||||
u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
|
||||
u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
|
||||
Expr *pWhen; /* The WHEN clause of the expresion (may be NULL) */
|
||||
@@ -1326,8 +1240,7 @@ struct Trigger {
|
||||
the <column-list> is stored here */
|
||||
int foreach; /* One of TK_ROW or TK_STATEMENT */
|
||||
Token nameToken; /* Token containing zName. Use during parsing only */
|
||||
Schema *pSchema; /* Schema containing the trigger */
|
||||
Schema *pTabSchema; /* Schema containing the table */
|
||||
|
||||
TriggerStep *step_list; /* Link list of trigger program steps */
|
||||
Trigger *pNext; /* Next trigger associated with the table */
|
||||
};
|
||||
@@ -1485,29 +1398,35 @@ int sqlite3IsNumber(const char*, int*, u8);
|
||||
int sqlite3Compare(const char *, const char *);
|
||||
int sqlite3SortCompare(const char *, const char *);
|
||||
void sqlite3RealToSortable(double r, char *);
|
||||
|
||||
void *sqlite3Malloc(int);
|
||||
void *sqlite3MallocRaw(int);
|
||||
void sqlite3Free(void*);
|
||||
void *sqlite3Realloc(void*,int);
|
||||
char *sqlite3StrDup(const char*);
|
||||
char *sqlite3StrNDup(const char*, int);
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
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);
|
||||
#else
|
||||
void *sqlite3Malloc(int);
|
||||
void *sqlite3MallocRaw(int);
|
||||
void sqlite3Free(void*);
|
||||
void *sqlite3Realloc(void*,int);
|
||||
char *sqlite3StrDup(const char*);
|
||||
char *sqlite3StrNDup(const char*, int);
|
||||
# define sqlite3CheckMemory(a,b)
|
||||
# define sqlite3MallocX sqlite3Malloc
|
||||
#endif
|
||||
void sqlite3ReallocOrFree(void**,int);
|
||||
void sqlite3FreeX(void*);
|
||||
void *sqlite3MallocX(int);
|
||||
int sqlite3AllocSize(void *);
|
||||
|
||||
char *sqlite3MPrintf(const char*, ...);
|
||||
char *sqlite3VMPrintf(const char*, va_list);
|
||||
void sqlite3DebugPrintf(const char*, ...);
|
||||
void *sqlite3TextToPtr(const char*);
|
||||
void sqlite3SetString(char **, ...);
|
||||
void sqlite3ErrorMsg(Parse*, const char*, ...);
|
||||
void sqlite3ErrorClear(Parse*);
|
||||
void sqlite3Dequote(char*);
|
||||
void sqlite3DequoteExpr(Expr*);
|
||||
int sqlite3KeywordCode(const unsigned char*, int);
|
||||
int sqlite3KeywordCode(const char*, int);
|
||||
int sqlite3RunParser(Parse*, const char*, char **);
|
||||
void sqlite3FinishCoding(Parse*);
|
||||
Expr *sqlite3Expr(int, Expr*, Expr*, const Token*);
|
||||
@@ -1527,12 +1446,11 @@ void sqlite3BeginParse(Parse*,int);
|
||||
void sqlite3RollbackInternalChanges(sqlite3*);
|
||||
void sqlite3CommitInternalChanges(sqlite3*);
|
||||
Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*);
|
||||
void sqlite3OpenMasterTable(Parse *, int);
|
||||
void sqlite3StartTable(Parse*,Token*,Token*,Token*,int,int,int);
|
||||
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, int, int);
|
||||
void sqlite3AddCheckConstraint(Parse*, Expr*);
|
||||
void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int);
|
||||
void sqlite3AddColumnType(Parse*,Token*);
|
||||
void sqlite3AddDefaultValue(Parse*,Expr*);
|
||||
void sqlite3AddCollateType(Parse*, const char*, int);
|
||||
@@ -1545,7 +1463,7 @@ void sqlite3EndTable(Parse*,Token*,Token*,Select*);
|
||||
# define sqlite3ViewGetColumnNames(A,B) 0
|
||||
#endif
|
||||
|
||||
void sqlite3DropTable(Parse*, SrcList*, int, int);
|
||||
void sqlite3DropTable(Parse*, SrcList*, int);
|
||||
void sqlite3DeleteTable(sqlite3*, Table*);
|
||||
void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
|
||||
int sqlite3ArrayAllocate(void**,int,int);
|
||||
@@ -1557,8 +1475,8 @@ void sqlite3SrcListAssignCursors(Parse*, SrcList*);
|
||||
void sqlite3IdListDelete(IdList*);
|
||||
void sqlite3SrcListDelete(SrcList*);
|
||||
void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
|
||||
Token*, int, int);
|
||||
void sqlite3DropIndex(Parse*, SrcList*, int);
|
||||
Token*);
|
||||
void sqlite3DropIndex(Parse*, SrcList*);
|
||||
void sqlite3AddKeyType(Vdbe*, ExprList*);
|
||||
void sqlite3AddIdxKeyType(Vdbe*, Index*);
|
||||
int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*, char *aff);
|
||||
@@ -1568,7 +1486,8 @@ void sqlite3SelectDelete(Select*);
|
||||
void sqlite3SelectUnbind(Select*);
|
||||
Table *sqlite3SrcListLookup(Parse*, SrcList*);
|
||||
int sqlite3IsReadOnly(Parse*, Table*, int);
|
||||
void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
|
||||
void sqlite3OpenTableForReading(Vdbe*, int iCur, Table*);
|
||||
void sqlite3OpenTable(Vdbe*, int iCur, Table*, int);
|
||||
void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
|
||||
void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
|
||||
WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**);
|
||||
@@ -1664,8 +1583,8 @@ void sqlite3DeferForeignKey(Parse*, int);
|
||||
# define sqlite3AuthContextPush(a,b,c)
|
||||
# define sqlite3AuthContextPop(a) ((void)(a))
|
||||
#endif
|
||||
void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
|
||||
void sqlite3Detach(Parse*, Expr*);
|
||||
void sqlite3Attach(Parse*, Token*, Token*, int, Token*);
|
||||
void sqlite3Detach(Parse*, Token*);
|
||||
int sqlite3BtreeFactory(const sqlite3 *db, const char *zFilename,
|
||||
int omitJournal, int nCache, Btree **ppBtree);
|
||||
int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
|
||||
@@ -1711,7 +1630,7 @@ int sqlite3ValueBytes(sqlite3_value*, u8);
|
||||
void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
|
||||
void sqlite3ValueFree(sqlite3_value*);
|
||||
sqlite3_value *sqlite3ValueNew(void);
|
||||
char *sqlite3utf16to8(const void*, int);
|
||||
sqlite3_value *sqlite3GetTransientValue(sqlite3*db);
|
||||
int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
|
||||
void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
|
||||
extern const unsigned char sqlite3UpperToLower[];
|
||||
@@ -1737,30 +1656,6 @@ void sqlite3AnalysisLoad(sqlite3*,int iDB);
|
||||
void sqlite3DefaultRowEst(Index*);
|
||||
void sqlite3RegisterLikeFunctions(sqlite3*, int);
|
||||
int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
|
||||
ThreadData *sqlite3ThreadData(void);
|
||||
const ThreadData *sqlite3ThreadDataReadOnly(void);
|
||||
void sqlite3ReleaseThreadData(void);
|
||||
void sqlite3AttachFunctions(sqlite3 *);
|
||||
void sqlite3MinimumFileFormat(Parse*, int, int);
|
||||
void sqlite3SchemaFree(void *);
|
||||
Schema *sqlite3SchemaGet(Btree *);
|
||||
int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
|
||||
KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
|
||||
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
void sqlite3TableLock(Parse *, int, int, u8, const char *);
|
||||
#else
|
||||
#define sqlite3TableLock(v,w,x,y,z)
|
||||
#endif
|
||||
|
||||
void sqlite3MallocClearFailed();
|
||||
#ifdef NDEBUG
|
||||
#define sqlite3MallocDisallow()
|
||||
#define sqlite3MallocAllow()
|
||||
#else
|
||||
void sqlite3MallocDisallow();
|
||||
void sqlite3MallocAllow();
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_SSE
|
||||
#include "sseInt.h"
|
||||
|
||||
+1
-5
@@ -16,11 +16,9 @@
|
||||
** These routines are in a separate files so that they will not be linked
|
||||
** if they are not used.
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef SQLITE_OMIT_GET_TABLE
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This structure is used to pass data from sqlite3_get_table() through
|
||||
@@ -195,5 +193,3 @@ void sqlite3_free_table(
|
||||
free(azResult);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_GET_TABLE */
|
||||
|
||||
+44
-160
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** A TCL Interface to SQLite
|
||||
**
|
||||
** $Id: tclsqlite.c,v 1.149 2006/01/09 23:40:25 drh Exp $
|
||||
** $Id: tclsqlite.c,v 1.132 2005/08/29 23:00:04 drh Exp $
|
||||
*/
|
||||
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
|
||||
|
||||
@@ -23,16 +23,6 @@
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
* Windows needs to know which symbols to export. Unix does not.
|
||||
* BUILD_sqlite should be undefined for Unix.
|
||||
*/
|
||||
|
||||
#ifdef BUILD_sqlite
|
||||
#undef TCL_STORAGE_CLASS
|
||||
#define TCL_STORAGE_CLASS DLLEXPORT
|
||||
#endif /* BUILD_sqlite */
|
||||
|
||||
#define NUM_PREPARED_STMTS 10
|
||||
#define MAX_PREPARED_STMTS 100
|
||||
|
||||
@@ -89,7 +79,7 @@ struct SqlPreparedStmt {
|
||||
*/
|
||||
typedef struct SqliteDb SqliteDb;
|
||||
struct SqliteDb {
|
||||
sqlite3 *db; /* The "real" database structure. MUST BE FIRST */
|
||||
sqlite3 *db; /* The "real" database structure */
|
||||
Tcl_Interp *interp; /* The interpreter used for this database */
|
||||
char *zBusy; /* The busy callback routine */
|
||||
char *zCommit; /* The commit hook callback routine */
|
||||
@@ -99,8 +89,6 @@ struct SqliteDb {
|
||||
char *zAuth; /* The authorization callback routine */
|
||||
char *zNull; /* Text to substitute for an SQL NULL value */
|
||||
SqlFunc *pFunc; /* List of SQL functions */
|
||||
Tcl_Obj *pUpdateHook; /* Update hook script (if any) */
|
||||
Tcl_Obj *pRollbackHook; /* Rollback hook script (if any) */
|
||||
SqlCollate *pCollate; /* List of SQL collation functions */
|
||||
int rc; /* Return code of most recent sqlite3_exec() */
|
||||
Tcl_Obj *pCollateNeeded; /* Collation needed script */
|
||||
@@ -212,15 +200,6 @@ static void DbDeleteCmd(void *db){
|
||||
if( pDb->zNull ){
|
||||
Tcl_Free(pDb->zNull);
|
||||
}
|
||||
if( pDb->pUpdateHook ){
|
||||
Tcl_DecrRefCount(pDb->pUpdateHook);
|
||||
}
|
||||
if( pDb->pRollbackHook ){
|
||||
Tcl_DecrRefCount(pDb->pRollbackHook);
|
||||
}
|
||||
if( pDb->pCollateNeeded ){
|
||||
Tcl_DecrRefCount(pDb->pCollateNeeded);
|
||||
}
|
||||
Tcl_Free((char*)pDb);
|
||||
}
|
||||
|
||||
@@ -308,37 +287,6 @@ static int DbCommitHandler(void *cd){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void DbRollbackHandler(void *clientData){
|
||||
SqliteDb *pDb = (SqliteDb*)clientData;
|
||||
assert(pDb->pRollbackHook);
|
||||
if( TCL_OK!=Tcl_EvalObjEx(pDb->interp, pDb->pRollbackHook, 0) ){
|
||||
Tcl_BackgroundError(pDb->interp);
|
||||
}
|
||||
}
|
||||
|
||||
static void DbUpdateHandler(
|
||||
void *p,
|
||||
int op,
|
||||
const char *zDb,
|
||||
const char *zTbl,
|
||||
sqlite_int64 rowid
|
||||
){
|
||||
SqliteDb *pDb = (SqliteDb *)p;
|
||||
Tcl_Obj *pCmd;
|
||||
|
||||
assert( pDb->pUpdateHook );
|
||||
assert( op==SQLITE_INSERT || op==SQLITE_UPDATE || op==SQLITE_DELETE );
|
||||
|
||||
pCmd = Tcl_DuplicateObj(pDb->pUpdateHook);
|
||||
Tcl_IncrRefCount(pCmd);
|
||||
Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(
|
||||
( (op==SQLITE_INSERT)?"INSERT":(op==SQLITE_UPDATE)?"UPDATE":"DELETE"), -1));
|
||||
Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zDb, -1));
|
||||
Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zTbl, -1));
|
||||
Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(rowid));
|
||||
Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT);
|
||||
}
|
||||
|
||||
static void tclCollateNeeded(
|
||||
void *pCtx,
|
||||
sqlite3 *db,
|
||||
@@ -444,7 +392,7 @@ static void tclSqlFunc(sqlite3_context *context, int argc, sqlite3_value**argv){
|
||||
}
|
||||
default: {
|
||||
int bytes = sqlite3_value_bytes(pIn);
|
||||
pVal = Tcl_NewStringObj((char *)sqlite3_value_text(pIn), bytes);
|
||||
pVal = Tcl_NewStringObj(sqlite3_value_text(pIn), bytes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -491,8 +439,8 @@ static void tclSqlFunc(sqlite3_context *context, int argc, sqlite3_value**argv){
|
||||
Tcl_GetWideIntFromObj(0, pVar, &v);
|
||||
sqlite3_result_int64(context, v);
|
||||
}else{
|
||||
data = (unsigned char *)Tcl_GetStringFromObj(pVar, &n);
|
||||
sqlite3_result_text(context, (char *)data, n, SQLITE_TRANSIENT);
|
||||
data = Tcl_GetStringFromObj(pVar, &n);
|
||||
sqlite3_result_text(context, data, n, SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -663,11 +611,10 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
"changes", "close", "collate",
|
||||
"collation_needed", "commit_hook", "complete",
|
||||
"copy", "errorcode", "eval",
|
||||
"exists", "function", "last_insert_rowid",
|
||||
"nullvalue", "onecolumn", "profile",
|
||||
"progress", "rekey", "rollback_hook",
|
||||
"timeout", "total_changes", "trace",
|
||||
"transaction", "update_hook", "version",
|
||||
"function", "last_insert_rowid", "nullvalue",
|
||||
"onecolumn", "profile", "progress",
|
||||
"rekey", "timeout", "total_changes",
|
||||
"trace", "transaction", "version",
|
||||
0
|
||||
};
|
||||
enum DB_enum {
|
||||
@@ -675,11 +622,10 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
DB_CHANGES, DB_CLOSE, DB_COLLATE,
|
||||
DB_COLLATION_NEEDED, DB_COMMIT_HOOK, DB_COMPLETE,
|
||||
DB_COPY, DB_ERRORCODE, DB_EVAL,
|
||||
DB_EXISTS, DB_FUNCTION, DB_LAST_INSERT_ROWID,
|
||||
DB_NULLVALUE, DB_ONECOLUMN, DB_PROFILE,
|
||||
DB_PROGRESS, DB_REKEY, DB_ROLLBACK_HOOK,
|
||||
DB_TIMEOUT, DB_TOTAL_CHANGES, DB_TRACE,
|
||||
DB_TRANSACTION, DB_UPDATE_HOOK, DB_VERSION
|
||||
DB_FUNCTION, DB_LAST_INSERT_ROWID,DB_NULLVALUE,
|
||||
DB_ONECOLUMN, DB_PROFILE, DB_PROGRESS,
|
||||
DB_REKEY, DB_TIMEOUT, DB_TOTAL_CHANGES,
|
||||
DB_TRACE, DB_TRANSACTION, DB_VERSION
|
||||
};
|
||||
/* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
|
||||
|
||||
@@ -1180,8 +1126,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
** lindex [$db eval $sql] 0
|
||||
*/
|
||||
case DB_ONECOLUMN:
|
||||
case DB_EVAL:
|
||||
case DB_EXISTS: {
|
||||
case DB_EVAL: {
|
||||
char const *zSql; /* Next SQL statement to execute */
|
||||
char const *zLeft; /* What is left after first stmt in zSql */
|
||||
sqlite3_stmt *pStmt; /* Compiled SQL statment */
|
||||
@@ -1194,24 +1139,19 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
SqlPreparedStmt *pPreStmt; /* Pointer to a prepared statement */
|
||||
int rc2;
|
||||
|
||||
if( choice==DB_EVAL ){
|
||||
if( choice==DB_ONECOLUMN ){
|
||||
if( objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "SQL");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
pRet = 0;
|
||||
}else{
|
||||
if( objc<3 || objc>5 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "SQL ?ARRAY-NAME? ?SCRIPT?");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
pRet = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pRet);
|
||||
}else{
|
||||
if( objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "SQL");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( choice==DB_EXISTS ){
|
||||
pRet = Tcl_NewBooleanObj(0);
|
||||
Tcl_IncrRefCount(pRet);
|
||||
}else{
|
||||
pRet = 0;
|
||||
}
|
||||
}
|
||||
if( objc==3 ){
|
||||
pArray = pScript = 0;
|
||||
@@ -1335,8 +1275,8 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
Tcl_GetWideIntFromObj(interp, pVar, &v);
|
||||
sqlite3_bind_int64(pStmt, i, v);
|
||||
}else{
|
||||
data = (unsigned char *)Tcl_GetStringFromObj(pVar, &n);
|
||||
sqlite3_bind_text(pStmt, i, (char *)data, n, SQLITE_STATIC);
|
||||
data = Tcl_GetStringFromObj(pVar, &n);
|
||||
sqlite3_bind_text(pStmt, i, data, n, SQLITE_STATIC);
|
||||
Tcl_IncrRefCount(pVar);
|
||||
apParm[nParm++] = pVar;
|
||||
}
|
||||
@@ -1404,7 +1344,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
pVal = dbTextToObj((char *)sqlite3_column_text(pStmt, i));
|
||||
pVal = dbTextToObj(sqlite3_column_text(pStmt, i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1416,19 +1356,11 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
Tcl_ObjSetVar2(interp, pArray, apColName[i], pVal, 0);
|
||||
}
|
||||
}else if( choice==DB_ONECOLUMN ){
|
||||
assert( pRet==0 );
|
||||
if( pRet==0 ){
|
||||
pRet = pVal;
|
||||
Tcl_IncrRefCount(pRet);
|
||||
}
|
||||
rc = TCL_BREAK;
|
||||
i = nCol;
|
||||
}else if( choice==DB_EXISTS ){
|
||||
Tcl_DecrRefCount(pRet);
|
||||
pRet = Tcl_NewBooleanObj(1);
|
||||
Tcl_IncrRefCount(pRet);
|
||||
rc = TCL_BREAK;
|
||||
i = nCol;
|
||||
}else{
|
||||
Tcl_ListObjAppendElement(interp, pRet, pVal);
|
||||
}
|
||||
@@ -1865,48 +1797,6 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** $db update_hook ?script?
|
||||
** $db rollback_hook ?script?
|
||||
*/
|
||||
case DB_UPDATE_HOOK:
|
||||
case DB_ROLLBACK_HOOK: {
|
||||
|
||||
/* set ppHook to point at pUpdateHook or pRollbackHook, depending on
|
||||
** whether [$db update_hook] or [$db rollback_hook] was invoked.
|
||||
*/
|
||||
Tcl_Obj **ppHook;
|
||||
if( choice==DB_UPDATE_HOOK ){
|
||||
ppHook = &pDb->pUpdateHook;
|
||||
}else{
|
||||
ppHook = &pDb->pRollbackHook;
|
||||
}
|
||||
|
||||
if( objc!=2 && objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( *ppHook ){
|
||||
Tcl_SetObjResult(interp, *ppHook);
|
||||
if( objc==3 ){
|
||||
Tcl_DecrRefCount(*ppHook);
|
||||
*ppHook = 0;
|
||||
}
|
||||
}
|
||||
if( objc==3 ){
|
||||
assert( !(*ppHook) );
|
||||
if( Tcl_GetCharLength(objv[2])>0 ){
|
||||
*ppHook = objv[2];
|
||||
Tcl_IncrRefCount(*ppHook);
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_update_hook(pDb->db, (pDb->pUpdateHook?DbUpdateHandler:0), pDb);
|
||||
sqlite3_rollback_hook(pDb->db,(pDb->pRollbackHook?DbRollbackHandler:0),pDb);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
/* $db version
|
||||
**
|
||||
** Return the version string for this database.
|
||||
@@ -1959,6 +1849,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
const char *zArg;
|
||||
char *zErrMsg;
|
||||
const char *zFile;
|
||||
char zBuf[80];
|
||||
if( objc==2 ){
|
||||
zArg = Tcl_GetStringFromObj(objv[1], 0);
|
||||
if( strcmp(zArg,"-version")==0 ){
|
||||
@@ -2026,6 +1917,14 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
zArg = Tcl_GetStringFromObj(objv[1], 0);
|
||||
Tcl_CreateObjCommand(interp, zArg, DbObjCmd, (char*)p, DbDeleteCmd);
|
||||
|
||||
/* The return value is the value of the sqlite* pointer
|
||||
*/
|
||||
sprintf(zBuf, "%p", p->db);
|
||||
if( strncmp(zBuf,"0x",2) ){
|
||||
sprintf(zBuf, "0x%p", p->db);
|
||||
}
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
|
||||
/* If compiled with SQLITE_TEST turned on, then register the "md5sum"
|
||||
** SQL function.
|
||||
*/
|
||||
@@ -2040,7 +1939,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
sqlite3_iMallocFail = mallocfail;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
p->interp = interp;
|
||||
return TCL_OK;
|
||||
@@ -2055,15 +1954,6 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
# define Tcl_InitStubs(a,b,c)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Make sure we have a PACKAGE_VERSION macro defined. This will be
|
||||
** defined automatically by the TEA makefile. But other makefiles
|
||||
** do not define it.
|
||||
*/
|
||||
#ifndef PACKAGE_VERSION
|
||||
# define PACKAGE_VERSION SQLITE_VERSION
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Initialize this module.
|
||||
**
|
||||
@@ -2073,23 +1963,23 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
|
||||
** used to open a new SQLite database. See the DbMain() routine above
|
||||
** for additional information.
|
||||
*/
|
||||
EXTERN int Sqlite3_Init(Tcl_Interp *interp){
|
||||
int Sqlite3_Init(Tcl_Interp *interp){
|
||||
Tcl_InitStubs(interp, "8.4", 0);
|
||||
Tcl_CreateObjCommand(interp, "sqlite3", (Tcl_ObjCmdProc*)DbMain, 0, 0);
|
||||
Tcl_PkgProvide(interp, "sqlite3", PACKAGE_VERSION);
|
||||
Tcl_PkgProvide(interp, "sqlite3", "3.0");
|
||||
Tcl_CreateObjCommand(interp, "sqlite", (Tcl_ObjCmdProc*)DbMain, 0, 0);
|
||||
Tcl_PkgProvide(interp, "sqlite", PACKAGE_VERSION);
|
||||
Tcl_PkgProvide(interp, "sqlite", "3.0");
|
||||
return TCL_OK;
|
||||
}
|
||||
EXTERN int Tclsqlite3_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
|
||||
EXTERN int Sqlite3_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
|
||||
EXTERN int Tclsqlite3_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
|
||||
int Tclsqlite3_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
|
||||
int Sqlite3_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
|
||||
int Tclsqlite3_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
|
||||
|
||||
#ifndef SQLITE_3_SUFFIX_ONLY
|
||||
EXTERN int Sqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
|
||||
EXTERN int Tclsqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
|
||||
EXTERN int Sqlite_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
|
||||
EXTERN int Tclsqlite_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
|
||||
int Sqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
|
||||
int Tclsqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
|
||||
int Sqlite_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
|
||||
int Tclsqlite_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
|
||||
#endif
|
||||
|
||||
#ifdef TCLSH
|
||||
@@ -2150,20 +2040,14 @@ int TCLSH_MAIN(int argc, char **argv){
|
||||
extern int Sqlitetest3_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest4_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest5_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest6_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest7_Init(Tcl_Interp*);
|
||||
extern int Md5_Init(Tcl_Interp*);
|
||||
extern int Sqlitetestsse_Init(Tcl_Interp*);
|
||||
extern int Sqlitetestasync_Init(Tcl_Interp*);
|
||||
|
||||
Sqlitetest1_Init(interp);
|
||||
Sqlitetest2_Init(interp);
|
||||
Sqlitetest3_Init(interp);
|
||||
Sqlitetest4_Init(interp);
|
||||
Sqlitetest5_Init(interp);
|
||||
Sqlitetest6_Init(interp);
|
||||
Sqlitetest7_Init(interp);
|
||||
Sqlitetestasync_Init(interp);
|
||||
Md5_Init(interp);
|
||||
#ifdef SQLITE_SSE
|
||||
Sqlitetestsse_Init(interp);
|
||||
|
||||
+61
-391
@@ -13,7 +13,7 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test1.c,v 1.191 2006/01/15 02:30:58 drh Exp $
|
||||
** $Id: test1.c,v 1.162 2005/09/19 13:15:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
@@ -21,48 +21,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
** This is a copy of the first part of the SqliteDb structure in
|
||||
** tclsqlite.c. We need it here so that the get_sqlite_pointer routine
|
||||
** can extract the sqlite3* pointer from an existing Tcl SQLite
|
||||
** connection.
|
||||
*/
|
||||
struct SqliteDb {
|
||||
sqlite3 *db;
|
||||
};
|
||||
|
||||
/*
|
||||
** A TCL command that returns the address of the sqlite* pointer
|
||||
** for an sqlite connection instance. Bad things happen if the
|
||||
** input is not an sqlite connection.
|
||||
*/
|
||||
static int get_sqlite_pointer(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
struct SqliteDb *p;
|
||||
Tcl_CmdInfo cmdInfo;
|
||||
char zBuf[100];
|
||||
if( objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "SQLITE-CONNECTION");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( !Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &cmdInfo) ){
|
||||
Tcl_AppendResult(interp, "command not found: ",
|
||||
Tcl_GetString(objv[1]), (char*)0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
p = (struct SqliteDb*)cmdInfo.objClientData;
|
||||
sprintf(zBuf, "%p", p->db);
|
||||
if( strncmp(zBuf,"0x",2) ){
|
||||
sprintf(zBuf, "0x%p", p->db);
|
||||
}
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
const char *sqlite3TestErrorName(int rc){
|
||||
const char *zName = 0;
|
||||
switch( rc ){
|
||||
@@ -166,7 +124,7 @@ static int getFilePointer(
|
||||
** understood by scanf, and if not, try prepending an "0x" to see if
|
||||
** that helps. If nothing works, a fatal error is generated.
|
||||
*/
|
||||
int sqlite3TestMakePointerStr(Tcl_Interp *interp, char *zPtr, void *p){
|
||||
static int makePointerStr(Tcl_Interp *interp, char *zPtr, void *p){
|
||||
sqlite3_snprintf(100, zPtr, "%p", p);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -415,8 +373,8 @@ static void ifnullFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
|
||||
int i;
|
||||
for(i=0; i<argc; i++){
|
||||
if( SQLITE_NULL!=sqlite3_value_type(argv[i]) ){
|
||||
sqlite3_result_text(context, (char*)sqlite3_value_text(argv[i]),
|
||||
sqlite3_value_bytes(argv[i]), SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, sqlite3_value_text(argv[i]), -1,
|
||||
SQLITE_TRANSIENT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -489,7 +447,7 @@ static void sqlite3ExecFunc(
|
||||
struct dstr x;
|
||||
memset(&x, 0, sizeof(x));
|
||||
sqlite3_exec((sqlite3*)sqlite3_user_data(context),
|
||||
(char*)sqlite3_value_text(argv[0]),
|
||||
sqlite3_value_text(argv[0]),
|
||||
execFuncCallback, &x, 0);
|
||||
sqlite3_result_text(context, x.z, x.nUsed, SQLITE_TRANSIENT);
|
||||
sqliteFree(x.z);
|
||||
@@ -829,7 +787,7 @@ static int sqlite3_mprintf_hexdouble(
|
||||
** first failure will continue to fail on every call. If REPEAT-INTERVAL is
|
||||
** 2 then every other malloc will fail. And so forth.
|
||||
**
|
||||
** Turn off this mechanism and reset the sqlite3ThreadData()->mallocFailed variable is N==0.
|
||||
** Turn off this mechanism and reset the sqlite3_malloc_failed variable is N==0.
|
||||
*/
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
static int sqlite_malloc_fail(
|
||||
@@ -852,6 +810,7 @@ static int sqlite_malloc_fail(
|
||||
}
|
||||
sqlite3_iMallocFail = n;
|
||||
sqlite3_iMallocReset = rep;
|
||||
sqlite3_malloc_failed = 0;
|
||||
return TCL_OK;
|
||||
}
|
||||
#endif
|
||||
@@ -869,101 +828,10 @@ static int sqlite_malloc_stat(
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
char zBuf[200];
|
||||
sprintf(zBuf, "%d %d %d", sqlite3_nMalloc,sqlite3_nFree,sqlite3_iMallocFail);
|
||||
sprintf(zBuf, "%d %d %d", sqlite3_nMalloc, sqlite3_nFree, sqlite3_iMallocFail);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function implements a Tcl command that may be invoked using any of
|
||||
** the four forms enumerated below.
|
||||
**
|
||||
** sqlite_malloc_outstanding
|
||||
** Return a summary of all unfreed blocks of memory allocated by the
|
||||
** current thread. See comments above function sqlite3OutstandingMallocs()
|
||||
** in util.c for a description of the returned value.
|
||||
**
|
||||
** sqlite_malloc_outstanding -bytes
|
||||
** Return the total amount of unfreed memory (in bytes) allocated by
|
||||
** this thread.
|
||||
**
|
||||
** sqlite_malloc_outstanding -maxbytes
|
||||
** Return the maximum amount of dynamic memory in use at one time
|
||||
** by this thread.
|
||||
**
|
||||
** sqlite_malloc_outstanding -clearmaxbytes
|
||||
** Set the value returned by [sqlite_malloc_outstanding -maxbytes]
|
||||
** to the current value of [sqlite_malloc_outstanding -bytes].
|
||||
*/
|
||||
static int sqlite_malloc_outstanding(
|
||||
ClientData clientData,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int objc, /* Number of arguments */
|
||||
Tcl_Obj *CONST objv[] /* Command arguments */
|
||||
){
|
||||
extern int sqlite3OutstandingMallocs(Tcl_Interp *interp);
|
||||
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
if( objc==2 ){
|
||||
const ThreadData *pTd = sqlite3ThreadDataReadOnly();
|
||||
const char *zArg = Tcl_GetString(objv[1]);
|
||||
if( 0==strcmp(zArg, "-bytes") ){
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(pTd->nAlloc));
|
||||
}else if( 0==strcmp(zArg, "-maxbytes") ){
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(pTd->nMaxAlloc));
|
||||
}else if( 0==strcmp(zArg, "-clearmaxbytes") ){
|
||||
pTd->nMaxAlloc = pTd->nAlloc;
|
||||
}else{
|
||||
Tcl_AppendResult(interp, "bad option \"", zArg,
|
||||
"\": must be -bytes, -maxbytes or -clearmaxbytes", 0
|
||||
);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( objc!=1 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "?-bytes?");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
return sqlite3OutstandingMallocs(interp);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_enable_shared_cache BOOLEAN
|
||||
**
|
||||
*/
|
||||
#if !defined(SQLITE_OMIT_SHARED_CACHE)
|
||||
static int test_enable_shared(
|
||||
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int objc, /* Number of arguments */
|
||||
Tcl_Obj *CONST objv[] /* Command arguments */
|
||||
){
|
||||
int rc;
|
||||
int enable;
|
||||
int ret = 0;
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetBooleanFromObj(interp, objv[1], &enable) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
ret = sqlite3ThreadDataReadOnly()->useSharedData;
|
||||
rc = sqlite3_enable_shared_cache(enable);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_SetResult(interp, (char *)sqlite3ErrStr(rc), TCL_STATIC);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(ret));
|
||||
return TCL_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -989,14 +857,14 @@ static int sqlite_abort(
|
||||
*/
|
||||
static void testFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
while( argc>=2 ){
|
||||
const char *zArg0 = (char*)sqlite3_value_text(argv[0]);
|
||||
const char *zArg0 = sqlite3_value_text(argv[0]);
|
||||
if( zArg0 ){
|
||||
if( 0==sqlite3StrICmp(zArg0, "int") ){
|
||||
sqlite3_result_int(context, sqlite3_value_int(argv[1]));
|
||||
}else if( sqlite3StrICmp(zArg0,"int64")==0 ){
|
||||
sqlite3_result_int64(context, sqlite3_value_int64(argv[1]));
|
||||
}else if( sqlite3StrICmp(zArg0,"string")==0 ){
|
||||
sqlite3_result_text(context, (char*)sqlite3_value_text(argv[1]), -1,
|
||||
sqlite3_result_text(context, sqlite3_value_text(argv[1]), -1,
|
||||
SQLITE_TRANSIENT);
|
||||
}else if( sqlite3StrICmp(zArg0,"double")==0 ){
|
||||
sqlite3_result_double(context, sqlite3_value_double(argv[1]));
|
||||
@@ -1084,7 +952,7 @@ static int test_finalize(
|
||||
/*
|
||||
** Usage: sqlite3_reset STMT
|
||||
**
|
||||
** Reset a statement handle.
|
||||
** Finalize a statement handle.
|
||||
*/
|
||||
static int test_reset(
|
||||
void * clientData,
|
||||
@@ -1104,15 +972,12 @@ static int test_reset(
|
||||
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
||||
|
||||
rc = sqlite3_reset(pStmt);
|
||||
if( pStmt && sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( pStmt &&
|
||||
sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
||||
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
||||
/*
|
||||
if( rc ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
*/
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -1199,8 +1064,7 @@ static char *sqlite_static_bind_value = 0;
|
||||
** ignored and the value is set to NULL. If FLAGS=="static" then
|
||||
** the value is set to the value of a static variable named
|
||||
** "sqlite_static_bind_value". If FLAGS=="normal" then a copy
|
||||
** of the VALUE is made. If FLAGS=="blob10" then a VALUE is ignored
|
||||
** an a 10-byte blob "abc\000xyz\000pq" is inserted.
|
||||
** of the VALUE is made.
|
||||
*/
|
||||
static int test_bind(
|
||||
void *NotUsed,
|
||||
@@ -1224,8 +1088,6 @@ static int test_bind(
|
||||
rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value, -1, 0);
|
||||
}else if( strcmp(argv[4],"normal")==0 ){
|
||||
rc = sqlite3_bind_text(pStmt, idx, argv[3], -1, SQLITE_TRANSIENT);
|
||||
}else if( strcmp(argv[4],"blob10")==0 ){
|
||||
rc = sqlite3_bind_text(pStmt, idx, "abc\000xyz\000pq", 10, SQLITE_STATIC);
|
||||
}else{
|
||||
Tcl_AppendResult(interp, "4th argument should be "
|
||||
"\"null\" or \"static\" or \"normal\"", 0);
|
||||
@@ -1304,12 +1166,10 @@ static int test_collate_func(
|
||||
pVal = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pVal, nA, zA, encin, SQLITE_STATIC);
|
||||
n = sqlite3_value_bytes(pVal);
|
||||
Tcl_ListObjAppendElement(i,pX,
|
||||
Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n));
|
||||
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj(sqlite3_value_text(pVal),n));
|
||||
sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC);
|
||||
n = sqlite3_value_bytes(pVal);
|
||||
Tcl_ListObjAppendElement(i,pX,
|
||||
Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n));
|
||||
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj(sqlite3_value_text(pVal),n));
|
||||
sqlite3ValueFree(pVal);
|
||||
|
||||
Tcl_EvalObjEx(i, pX, 0);
|
||||
@@ -1356,35 +1216,15 @@ bad_args:
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
** When the collation needed callback is invoked, record the name of
|
||||
** the requested collating function here. The recorded name is linked
|
||||
** to a TCL variable and used to make sure that the requested collation
|
||||
** name is correct.
|
||||
*/
|
||||
static char zNeededCollation[200];
|
||||
static char *pzNeededCollation = zNeededCollation;
|
||||
|
||||
|
||||
/*
|
||||
** Called when a collating sequence is needed. Registered using
|
||||
** sqlite3_collation_needed16().
|
||||
*/
|
||||
static void test_collate_needed_cb(
|
||||
void *pCtx,
|
||||
sqlite3 *db,
|
||||
int eTextRep,
|
||||
const void *pName
|
||||
const void *notUsed
|
||||
){
|
||||
int enc = ENC(db);
|
||||
int i;
|
||||
char *z;
|
||||
for(z = (char*)pName, i=0; *z || z[1]; z++){
|
||||
if( *z ) zNeededCollation[i++] = *z;
|
||||
}
|
||||
zNeededCollation[i] = 0;
|
||||
int enc = db->enc;
|
||||
sqlite3_create_collation(
|
||||
db, "test_collate", ENC(db), (void *)enc, test_collate_func);
|
||||
db, "test_collate", db->enc, (void *)enc, test_collate_func);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1402,7 +1242,6 @@ static int test_collate_needed(
|
||||
if( objc!=2 ) goto bad_args;
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
rc = sqlite3_collation_needed16(db, 0, test_collate_needed_cb);
|
||||
zNeededCollation[0] = 0;
|
||||
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
||||
return TCL_OK;
|
||||
|
||||
@@ -1451,7 +1290,7 @@ static void test_function_utf8(
|
||||
Tcl_IncrRefCount(pX);
|
||||
Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-8", -1));
|
||||
Tcl_ListObjAppendElement(interp, pX,
|
||||
Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1));
|
||||
Tcl_NewStringObj(sqlite3_value_text(argv[0]), -1));
|
||||
Tcl_EvalObjEx(interp, pX, 0);
|
||||
Tcl_DecrRefCount(pX);
|
||||
sqlite3_result_text(pCtx, Tcl_GetStringResult(interp), -1, SQLITE_TRANSIENT);
|
||||
@@ -1475,13 +1314,13 @@ static void test_function_utf16le(
|
||||
Tcl_IncrRefCount(pX);
|
||||
Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16LE", -1));
|
||||
Tcl_ListObjAppendElement(interp, pX,
|
||||
Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1));
|
||||
Tcl_NewStringObj(sqlite3_value_text(argv[0]), -1));
|
||||
Tcl_EvalObjEx(interp, pX, 0);
|
||||
Tcl_DecrRefCount(pX);
|
||||
pVal = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp),
|
||||
SQLITE_UTF8, SQLITE_STATIC);
|
||||
sqlite3_result_text(pCtx,(char*)sqlite3_value_text(pVal),-1,SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(pCtx,sqlite3_value_text(pVal),-1,SQLITE_TRANSIENT);
|
||||
sqlite3ValueFree(pVal);
|
||||
}
|
||||
static void test_function_utf16be(
|
||||
@@ -1497,7 +1336,7 @@ static void test_function_utf16be(
|
||||
Tcl_IncrRefCount(pX);
|
||||
Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16BE", -1));
|
||||
Tcl_ListObjAppendElement(interp, pX,
|
||||
Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1));
|
||||
Tcl_NewStringObj(sqlite3_value_text(argv[0]), -1));
|
||||
Tcl_EvalObjEx(interp, pX, 0);
|
||||
Tcl_DecrRefCount(pX);
|
||||
pVal = sqlite3ValueNew();
|
||||
@@ -1573,6 +1412,29 @@ static int test_errstr(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
static int sqlite3_crashparams(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
#ifdef OS_TEST
|
||||
int delay;
|
||||
if( objc!=3 ) goto bad_args;
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], &delay) ) return TCL_ERROR;
|
||||
sqlite3SetCrashParams(delay, Tcl_GetString(objv[2]));
|
||||
#endif
|
||||
return TCL_OK;
|
||||
|
||||
#ifdef OS_TEST
|
||||
bad_args:
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0), "<delay> <filename>", 0);
|
||||
return TCL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Usage: breakpoint
|
||||
**
|
||||
@@ -1813,7 +1675,7 @@ static int test_bind_text16(
|
||||
|
||||
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
||||
value = (char*)Tcl_GetByteArrayFromObj(objv[3], 0);
|
||||
value = Tcl_GetByteArrayFromObj(objv[3], 0);
|
||||
if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;
|
||||
|
||||
rc = sqlite3_bind_text16(pStmt, idx, (void *)value, bytes, SQLITE_TRANSIENT);
|
||||
@@ -2096,7 +1958,7 @@ static int test_prepare(
|
||||
}
|
||||
|
||||
if( pStmt ){
|
||||
if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
||||
if( makePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
}
|
||||
return TCL_OK;
|
||||
@@ -2153,7 +2015,7 @@ static int test_prepare16(
|
||||
Tcl_DecrRefCount(pTail);
|
||||
|
||||
if( pStmt ){
|
||||
if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
||||
if( makePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
||||
}
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
@@ -2183,7 +2045,7 @@ static int test_open(
|
||||
zFilename = Tcl_GetString(objv[1]);
|
||||
rc = sqlite3_open(zFilename, &db);
|
||||
|
||||
if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR;
|
||||
if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR;
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -2212,7 +2074,7 @@ static int test_open16(
|
||||
zFilename = Tcl_GetByteArrayFromObj(objv[1], 0);
|
||||
rc = sqlite3_open16(zFilename, &db);
|
||||
|
||||
if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR;
|
||||
if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR;
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
return TCL_OK;
|
||||
@@ -2238,7 +2100,7 @@ static int test_complete16(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
zBuf = (char*)Tcl_GetByteArrayFromObj(objv[1], 0);
|
||||
zBuf = Tcl_GetByteArrayFromObj(objv[1], 0);
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_complete16(zBuf)));
|
||||
#endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */
|
||||
return TCL_OK;
|
||||
@@ -2590,7 +2452,7 @@ static int test_sqlite3OsOpenReadWrite(
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
OsFile *pFile;
|
||||
OsFile * pFile;
|
||||
int rc;
|
||||
int dummy;
|
||||
char zBuf[100];
|
||||
@@ -2601,12 +2463,14 @@ static int test_sqlite3OsOpenReadWrite(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
rc = sqlite3OsOpenReadWrite(Tcl_GetString(objv[1]), &pFile, &dummy);
|
||||
pFile = sqliteMalloc(sizeof(OsFile));
|
||||
rc = sqlite3OsOpenReadWrite(Tcl_GetString(objv[1]), pFile, &dummy);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqliteFree(pFile);
|
||||
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sqlite3TestMakePointerStr(interp, zBuf, pFile);
|
||||
makePointerStr(interp, zBuf, pFile);
|
||||
Tcl_SetResult(interp, zBuf, 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
@@ -2620,7 +2484,7 @@ static int test_sqlite3OsClose(
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
OsFile *pFile;
|
||||
OsFile * pFile;
|
||||
int rc;
|
||||
|
||||
if( objc!=2 ){
|
||||
@@ -2632,11 +2496,12 @@ static int test_sqlite3OsClose(
|
||||
if( getFilePointer(interp, Tcl_GetString(objv[1]), &pFile) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqlite3OsClose(&pFile);
|
||||
rc = sqlite3OsClose(pFile);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sqliteFree(pFile);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -2940,121 +2805,6 @@ static int tcl_variable_type(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_release_memory ?N?
|
||||
**
|
||||
** Attempt to release memory currently held but not actually required.
|
||||
** The integer N is the number of bytes we are trying to release. The
|
||||
** return value is the amount of memory actually released.
|
||||
*/
|
||||
static int test_release_memory(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
|
||||
int N;
|
||||
int amt;
|
||||
if( objc!=1 && objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "?N?");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( objc==2 ){
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
|
||||
}else{
|
||||
N = -1;
|
||||
}
|
||||
amt = sqlite3_release_memory(N);
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(amt));
|
||||
#endif
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_soft_heap_limit ?N?
|
||||
**
|
||||
** Query or set the soft heap limit for the current thread. The
|
||||
** limit is only changed if the N is present. The previous limit
|
||||
** is returned.
|
||||
*/
|
||||
static int test_soft_heap_limit(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
|
||||
int amt;
|
||||
if( objc!=1 && objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "?N?");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
amt = sqlite3ThreadDataReadOnly()->nSoftHeapLimit;
|
||||
if( objc==2 ){
|
||||
int N;
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
|
||||
sqlite3_soft_heap_limit(N);
|
||||
}
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(amt));
|
||||
#endif
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_clear_tsd_memdebug
|
||||
**
|
||||
** Clear all of the MEMDEBUG information out of thread-specific data.
|
||||
** This will allow it to be deallocated.
|
||||
*/
|
||||
static int test_clear_tsd_memdebug(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
#if defined(SQLITE_MEMDEBUG)
|
||||
ThreadData *pTd = sqlite3ThreadData();
|
||||
pTd->nMaxAlloc = 0;
|
||||
pTd->zFile = 0;
|
||||
pTd->iLine = 0;
|
||||
#endif
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_tsd_release
|
||||
**
|
||||
** Call sqlite3ReleaseThreadData.
|
||||
*/
|
||||
static int test_tsd_release(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
#if defined(SQLITE_MEMDEBUG)
|
||||
sqlite3ReleaseThreadData();
|
||||
#endif
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_thread_cleanup
|
||||
**
|
||||
** Call the sqlite3_thread_cleanup API.
|
||||
*/
|
||||
static int test_thread_cleanup(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3_thread_cleanup();
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This routine sets entries in the global ::sqlite_options() array variable
|
||||
** according to the compile-time configuration of the database. Test
|
||||
@@ -3073,18 +2823,6 @@ static void set_options(Tcl_Interp *interp){
|
||||
Tcl_SetVar2(interp, "sqlite_options","casesensitivelike","0",TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_DISABLE_DIRSYNC
|
||||
Tcl_SetVar2(interp, "sqlite_options", "dirsync", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
Tcl_SetVar2(interp, "sqlite_options", "dirsync", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_DISABLE_LFS
|
||||
Tcl_SetVar2(interp, "sqlite_options", "lfs", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
Tcl_SetVar2(interp, "sqlite_options", "lfs", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_ALTERTABLE
|
||||
Tcl_SetVar2(interp, "sqlite_options", "altertable", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
@@ -3138,12 +2876,6 @@ static void set_options(Tcl_Interp *interp){
|
||||
Tcl_SetVar2(interp, "sqlite_options", "cast", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_CHECK
|
||||
Tcl_SetVar2(interp, "sqlite_options", "check", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
Tcl_SetVar2(interp, "sqlite_options", "check", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_COMPLETE
|
||||
Tcl_SetVar2(interp, "sqlite_options", "complete", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
@@ -3162,12 +2894,6 @@ static void set_options(Tcl_Interp *interp){
|
||||
Tcl_SetVar2(interp, "sqlite_options", "conflict", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#if OS_UNIX
|
||||
Tcl_SetVar2(interp, "sqlite_options", "crashtest", "1", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
Tcl_SetVar2(interp, "sqlite_options", "crashtest", "0", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_DATETIME_FUNCS
|
||||
Tcl_SetVar2(interp, "sqlite_options", "datetime", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
@@ -3222,12 +2948,6 @@ static void set_options(Tcl_Interp *interp){
|
||||
Tcl_SetVar2(interp, "sqlite_options", "memorydb", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
Tcl_SetVar2(interp, "sqlite_options", "memorymanage", "1", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
Tcl_SetVar2(interp, "sqlite_options", "memorymanage", "0", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_OR_OPTIMIZATION
|
||||
Tcl_SetVar2(interp, "sqlite_options", "or_opt", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
@@ -3259,12 +2979,6 @@ static void set_options(Tcl_Interp *interp){
|
||||
Tcl_SetVar2(interp, "sqlite_options", "progress", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_ENABLE_REDEF_IO
|
||||
Tcl_SetVar2(interp, "sqlite_options", "redefio", "1", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
Tcl_SetVar2(interp, "sqlite_options", "redefio", "0", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_REINDEX
|
||||
Tcl_SetVar2(interp, "sqlite_options", "reindex", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
@@ -3283,12 +2997,6 @@ static void set_options(Tcl_Interp *interp){
|
||||
Tcl_SetVar2(interp, "sqlite_options", "schema_version", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_SHARED_CACHE
|
||||
Tcl_SetVar2(interp, "sqlite_options", "shared_cache", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
Tcl_SetVar2(interp, "sqlite_options", "shared_cache", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_SUBQUERY
|
||||
Tcl_SetVar2(interp, "sqlite_options", "subquery", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
@@ -3396,7 +3104,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
Tcl_ObjCmdProc *xProc;
|
||||
void *clientData;
|
||||
} aObjCmd[] = {
|
||||
{ "sqlite3_connection_pointer", get_sqlite_pointer, 0 },
|
||||
{ "sqlite3_bind_int", test_bind_int, 0 },
|
||||
{ "sqlite3_bind_int64", test_bind_int64, 0 },
|
||||
{ "sqlite3_bind_double", test_bind_double, 0 },
|
||||
@@ -3426,12 +3133,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
{ "sqlite3_changes", test_changes ,0 },
|
||||
{ "sqlite3_step", test_step ,0 },
|
||||
|
||||
{ "sqlite3_release_memory", test_release_memory, 0},
|
||||
{ "sqlite3_soft_heap_limit", test_soft_heap_limit, 0},
|
||||
{ "sqlite3_clear_tsd_memdebug", test_clear_tsd_memdebug, 0},
|
||||
{ "sqlite3_tsd_release", test_tsd_release, 0},
|
||||
{ "sqlite3_thread_cleanup", test_thread_cleanup, 0},
|
||||
|
||||
/* sqlite3_column_*() API */
|
||||
{ "sqlite3_column_count", test_column_count ,0 },
|
||||
{ "sqlite3_data_count", test_data_count ,0 },
|
||||
@@ -3467,14 +3168,9 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
{ "add_test_collate_needed", test_collate_needed, 0 },
|
||||
{ "add_test_function", test_function, 0 },
|
||||
#endif
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
{ "sqlite_malloc_outstanding", sqlite_malloc_outstanding, 0},
|
||||
#endif
|
||||
{ "sqlite3_crashparams", sqlite3_crashparams, 0 },
|
||||
{ "sqlite3_test_errstr", test_errstr, 0 },
|
||||
{ "tcl_variable_type", tcl_variable_type, 0 },
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
{ "sqlite3_enable_shared_cache", test_enable_shared, 0 },
|
||||
#endif
|
||||
};
|
||||
static int bitmask_size = sizeof(Bitmask)*8;
|
||||
int i;
|
||||
@@ -3483,13 +3179,8 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
extern int sqlite3_sync_count, sqlite3_fullsync_count;
|
||||
extern int sqlite3_opentemp_count;
|
||||
extern int sqlite3_memUsed;
|
||||
extern int sqlite3_malloc_id;
|
||||
extern int sqlite3_memMax;
|
||||
extern int sqlite3_like_count;
|
||||
extern int sqlite3_tsd_count;
|
||||
#if OS_UNIX && defined(SQLITE_TEST) && defined(THREADSAFE) && THREADSAFE
|
||||
extern int threadsOverrideEachOthersLocks;
|
||||
#endif
|
||||
#if OS_WIN
|
||||
extern int sqlite3_os_type;
|
||||
#endif
|
||||
@@ -3522,20 +3213,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
(char*)&sqlite3_current_time, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_os_trace",
|
||||
(char*)&sqlite3_os_trace, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite3_tsd_count",
|
||||
(char*)&sqlite3_tsd_count, TCL_LINK_INT);
|
||||
#if OS_UNIX && defined(SQLITE_TEST) && defined(THREADSAFE) && THREADSAFE
|
||||
Tcl_LinkVar(interp, "threadsOverrideEachOthersLocks",
|
||||
(char*)&threadsOverrideEachOthersLocks, TCL_LINK_INT);
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
Tcl_LinkVar(interp, "sqlite_last_needed_collation",
|
||||
(char*)&pzNeededCollation, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
|
||||
#endif
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
Tcl_LinkVar(interp, "sqlite_malloc_id",
|
||||
(char*)&sqlite3_malloc_id, TCL_LINK_STRING);
|
||||
#endif
|
||||
#if OS_WIN
|
||||
Tcl_LinkVar(interp, "sqlite_os_type",
|
||||
(char*)&sqlite3_os_type, TCL_LINK_INT);
|
||||
@@ -3573,12 +3250,5 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
(char*)&sqlite3_fullsync_count, TCL_LINK_INT);
|
||||
#endif /* OS_UNIX */
|
||||
set_options(interp);
|
||||
|
||||
{
|
||||
extern int sqlite3_shared_cache_report(void *, Tcl_Interp *,
|
||||
int, Tcl_Obj *CONST[]);
|
||||
Tcl_CreateObjCommand(interp, "sqlite_shared_cache_report",
|
||||
sqlite3_shared_cache_report, 0, 0);
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
+5
-7
@@ -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.39 2006/01/06 14:32:20 drh Exp $
|
||||
** $Id: test2.c,v 1.34 2005/09/16 10:13:42 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -524,7 +524,7 @@ static int fake_big_file(
|
||||
int rc;
|
||||
int n;
|
||||
i64 offset;
|
||||
OsFile *fd = 0;
|
||||
OsFile fd;
|
||||
int readOnly = 0;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
@@ -532,6 +532,7 @@ static int fake_big_file(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
|
||||
memset(&fd, 0, sizeof(fd));
|
||||
rc = sqlite3OsOpenReadWrite(argv[2], &fd, &readOnly);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "open failed: ", errorName(rc), 0);
|
||||
@@ -539,12 +540,12 @@ static int fake_big_file(
|
||||
}
|
||||
offset = n;
|
||||
offset *= 1024*1024;
|
||||
rc = sqlite3OsSeek(fd, offset);
|
||||
rc = sqlite3OsSeek(&fd, offset);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "seek failed: ", errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqlite3OsWrite(fd, "Hello, World!", 14);
|
||||
rc = sqlite3OsWrite(&fd, "Hello, World!", 14);
|
||||
sqlite3OsClose(&fd);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "write failed: ", errorName(rc), 0);
|
||||
@@ -559,7 +560,6 @@ static int fake_big_file(
|
||||
*/
|
||||
int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
extern int sqlite3_io_error_pending;
|
||||
extern int sqlite3_io_error_hit;
|
||||
extern int sqlite3_diskfull_pending;
|
||||
extern int sqlite3_diskfull;
|
||||
static struct {
|
||||
@@ -592,8 +592,6 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
}
|
||||
Tcl_LinkVar(interp, "sqlite_io_error_pending",
|
||||
(char*)&sqlite3_io_error_pending, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_io_error_hit",
|
||||
(char*)&sqlite3_io_error_hit, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_diskfull_pending",
|
||||
(char*)&sqlite3_diskfull_pending, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_diskfull",
|
||||
|
||||
+7
-7
@@ -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.64 2005/12/30 16:28:02 danielk1977 Exp $
|
||||
** $Id: test3.c,v 1.62 2005/08/11 02:10:19 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "pager.h"
|
||||
@@ -69,7 +69,7 @@ static int btree_open(
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[3], &flags) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeOpen(argv[1], 0, &pBt, flags);
|
||||
rc = sqlite3BtreeOpen(argv[1], &pBt, flags);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -972,7 +972,7 @@ static int btree_keysize(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
sqlite3BtreeKeySize(pCur, (i64*)&n);
|
||||
sqlite3BtreeKeySize(pCur, &n);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf, "%llu", n);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
@@ -1000,7 +1000,7 @@ static int btree_key(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
sqlite3BtreeKeySize(pCur, (i64*)&n);
|
||||
sqlite3BtreeKeySize(pCur, &n);
|
||||
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
|
||||
char zBuf2[60];
|
||||
sqlite3_snprintf(sizeof(zBuf2),zBuf2, "%llu", n);
|
||||
@@ -1084,7 +1084,7 @@ static int btree_fetch_key(
|
||||
}
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
|
||||
sqlite3BtreeKeySize(pCur, (i64*)&nKey);
|
||||
sqlite3BtreeKeySize(pCur, &nKey);
|
||||
zBuf = sqlite3BtreeKeyFetch(pCur, &amt);
|
||||
if( zBuf && amt>=n ){
|
||||
assert( nKey<sizeof(zStatic) );
|
||||
@@ -1159,9 +1159,9 @@ static int btree_payload_size(
|
||||
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
|
||||
n1 = 0;
|
||||
}else{
|
||||
sqlite3BtreeKeySize(pCur, (i64*)&n1);
|
||||
sqlite3BtreeKeySize(pCur, &n1);
|
||||
}
|
||||
sqlite3BtreeDataSize(pCur, (u32*)&n2);
|
||||
sqlite3BtreeDataSize(pCur, &n2);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", (int)(n1+n2));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
|
||||
+1
-71
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** Code for testing the the SQLite library in a multithreaded environment.
|
||||
**
|
||||
** $Id: test4.c,v 1.15 2006/01/15 02:30:58 drh Exp $
|
||||
** $Id: test4.c,v 1.13 2005/08/11 02:10:19 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
@@ -97,7 +97,6 @@ static void *thread_main(void *pArg){
|
||||
p->zErr = 0;
|
||||
}
|
||||
p->completed++;
|
||||
sqlite3_thread_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -615,73 +614,6 @@ static int tcl_thread_swap(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_db_get ID
|
||||
**
|
||||
** Return the database connection pointer for the given thread. Then
|
||||
** remove the pointer from the thread itself. Afterwards, the thread
|
||||
** can be stopped and the connection can be used by the main thread.
|
||||
*/
|
||||
static int tcl_thread_db_get(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
char zBuf[100];
|
||||
extern int sqlite3TestMakePointerStr(Tcl_Interp*, char*, void*);
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[i]);
|
||||
sqlite3TestMakePointerStr(interp, zBuf, threadset[i].db);
|
||||
threadset[i].db = 0;
|
||||
Tcl_SetResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_stmt_get ID
|
||||
**
|
||||
** Return the database stmt pointer for the given thread. Then
|
||||
** remove the pointer from the thread itself.
|
||||
*/
|
||||
static int tcl_thread_stmt_get(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
char zBuf[100];
|
||||
extern int sqlite3TestMakePointerStr(Tcl_Interp*, char*, void*);
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[i]);
|
||||
sqlite3TestMakePointerStr(interp, zBuf, threadset[i].pStmt);
|
||||
threadset[i].pStmt = 0;
|
||||
Tcl_SetResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
@@ -702,8 +634,6 @@ int Sqlitetest4_Init(Tcl_Interp *interp){
|
||||
{ "thread_step", (Tcl_CmdProc*)tcl_thread_step },
|
||||
{ "thread_finalize", (Tcl_CmdProc*)tcl_thread_finalize },
|
||||
{ "thread_swap", (Tcl_CmdProc*)tcl_thread_swap },
|
||||
{ "thread_db_get", (Tcl_CmdProc*)tcl_thread_db_get },
|
||||
{ "thread_stmt_get", (Tcl_CmdProc*)tcl_thread_stmt_get },
|
||||
};
|
||||
int i;
|
||||
|
||||
|
||||
+5
-5
@@ -15,7 +15,7 @@
|
||||
** is used for testing the SQLite routines for converting between
|
||||
** the various supported unicode encodings.
|
||||
**
|
||||
** $Id: test5.c,v 1.15 2005/12/09 20:21:59 drh Exp $
|
||||
** $Id: test5.c,v 1.14 2004/11/14 21:56:30 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
@@ -41,7 +41,7 @@ static int binarize(
|
||||
assert(objc==2);
|
||||
|
||||
bytes = Tcl_GetStringFromObj(objv[1], &len);
|
||||
pRet = Tcl_NewByteArrayObj((u8*)bytes, len+1);
|
||||
pRet = Tcl_NewByteArrayObj(bytes, len+1);
|
||||
Tcl_SetObjResult(interp, pRet);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ static int test_value_overhead(
|
||||
|
||||
for(i=0; i<repeat_count; i++){
|
||||
if( do_calls ){
|
||||
zVal = (char*)sqlite3_value_text(&val);
|
||||
zVal = sqlite3_value_text(&val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ static int test_translate(
|
||||
}
|
||||
sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel);
|
||||
}else{
|
||||
z = (char*)Tcl_GetByteArrayFromObj(objv[1], &len);
|
||||
z = Tcl_GetByteArrayFromObj(objv[1], &len);
|
||||
if( objc==5 ){
|
||||
char *zTmp = z;
|
||||
z = sqliteMalloc(len);
|
||||
@@ -170,7 +170,7 @@ static int test_translate(
|
||||
|
||||
z = (char *)sqlite3ValueText(pVal, enc_to);
|
||||
len = sqlite3ValueBytes(pVal, enc_to) + (enc_to==SQLITE_UTF8?1:2);
|
||||
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj((u8*)z, len));
|
||||
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(z, len));
|
||||
|
||||
sqlite3ValueFree(pVal);
|
||||
|
||||
|
||||
-551
@@ -1,551 +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 modified the OS layer in order to simulate
|
||||
** the effect on the database file of an OS crash or power failure. This
|
||||
** is used to test the ability of SQLite to recover from those situations.
|
||||
*/
|
||||
#if SQLITE_TEST /* This file is used for the testing only */
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include "tcl.h"
|
||||
|
||||
#ifndef SQLITE_OMIT_DISKIO /* This file is a no-op if disk I/O is disabled */
|
||||
|
||||
/*
|
||||
** crashFile is a subclass of OsFile that is taylored for the
|
||||
** crash test module.
|
||||
*/
|
||||
typedef struct crashFile crashFile;
|
||||
struct crashFile {
|
||||
IoMethod const *pMethod; /* Must be first */
|
||||
u8 **apBlk; /* Array of blocks that have been written to. */
|
||||
int nBlk; /* Size of apBlock. */
|
||||
i64 offset; /* Next character to be read from the file */
|
||||
int nMaxWrite; /* Largest offset written to. */
|
||||
char *zName; /* File name */
|
||||
OsFile *pBase; /* The real file */
|
||||
crashFile *pNext; /* Next in a list of them all */
|
||||
};
|
||||
|
||||
/*
|
||||
** Size of a simulated disk block
|
||||
*/
|
||||
#define BLOCKSIZE 512
|
||||
#define BLOCK_OFFSET(x) ((x) * BLOCKSIZE)
|
||||
|
||||
|
||||
/*
|
||||
** The following variables control when a simulated crash occurs.
|
||||
**
|
||||
** If iCrashDelay is non-zero, then zCrashFile contains (full path) name of
|
||||
** a file that SQLite will call sqlite3OsSync() on. Each time this happens
|
||||
** iCrashDelay is decremented. If iCrashDelay is zero after being
|
||||
** decremented, a "crash" occurs during the sync() operation.
|
||||
**
|
||||
** In other words, a crash occurs the iCrashDelay'th time zCrashFile is
|
||||
** synced.
|
||||
*/
|
||||
static int iCrashDelay = 0;
|
||||
static char zCrashFile[500];
|
||||
|
||||
/*
|
||||
** Set the value of the two crash parameters.
|
||||
*/
|
||||
static void setCrashParams(int iDelay, char const *zFile){
|
||||
sqlite3OsEnterMutex();
|
||||
assert( strlen(zFile)<sizeof(zCrashFile) );
|
||||
strcpy(zCrashFile, zFile);
|
||||
iCrashDelay = iDelay;
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
|
||||
/*
|
||||
** File zPath is being sync()ed. Return non-zero if this should
|
||||
** cause a crash.
|
||||
*/
|
||||
static int crashRequired(char const *zPath){
|
||||
int r;
|
||||
int n;
|
||||
sqlite3OsEnterMutex();
|
||||
n = strlen(zCrashFile);
|
||||
if( zCrashFile[n-1]=='*' ){
|
||||
n--;
|
||||
}else if( strlen(zPath)>n ){
|
||||
n = strlen(zPath);
|
||||
}
|
||||
r = 0;
|
||||
if( iCrashDelay>0 && strncmp(zPath, zCrashFile, n)==0 ){
|
||||
iCrashDelay--;
|
||||
if( iCrashDelay<=0 ){
|
||||
r = 1;
|
||||
}
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
** A list of all open files.
|
||||
*/
|
||||
static crashFile *pAllFiles = 0;
|
||||
|
||||
/* Forward reference */
|
||||
static void initFile(OsFile **pId, char const *zName, OsFile *pBase);
|
||||
|
||||
/*
|
||||
** Undo the work done by initFile. Delete the OsFile structure
|
||||
** and unlink the structure from the pAllFiles list.
|
||||
*/
|
||||
static void closeFile(crashFile **pId){
|
||||
crashFile *pFile = *pId;
|
||||
if( pFile==pAllFiles ){
|
||||
pAllFiles = pFile->pNext;
|
||||
}else{
|
||||
crashFile *p;
|
||||
for(p=pAllFiles; p->pNext!=pFile; p=p->pNext ){
|
||||
assert( p );
|
||||
}
|
||||
p->pNext = pFile->pNext;
|
||||
}
|
||||
sqliteFree(*pId);
|
||||
*pId = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Read block 'blk' off of the real disk file and into the cache of pFile.
|
||||
*/
|
||||
static int readBlockIntoCache(crashFile *pFile, int blk){
|
||||
if( blk>=pFile->nBlk ){
|
||||
int n = ((pFile->nBlk * 2) + 100 + blk);
|
||||
/* if( pFile->nBlk==0 ){ printf("DIRTY %s\n", pFile->zName); } */
|
||||
pFile->apBlk = (u8 **)sqliteRealloc(pFile->apBlk, n * sizeof(u8*));
|
||||
if( !pFile->apBlk ) return SQLITE_NOMEM;
|
||||
memset(&pFile->apBlk[pFile->nBlk], 0, (n - pFile->nBlk)*sizeof(u8*));
|
||||
pFile->nBlk = n;
|
||||
}
|
||||
|
||||
if( !pFile->apBlk[blk] ){
|
||||
i64 filesize;
|
||||
int rc;
|
||||
|
||||
u8 *p = sqliteMalloc(BLOCKSIZE);
|
||||
if( !p ) return SQLITE_NOMEM;
|
||||
pFile->apBlk[blk] = p;
|
||||
|
||||
rc = sqlite3OsFileSize(pFile->pBase, &filesize);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
if( BLOCK_OFFSET(blk)<filesize ){
|
||||
int len = BLOCKSIZE;
|
||||
rc = sqlite3OsSeek(pFile->pBase, blk*BLOCKSIZE);
|
||||
if( BLOCK_OFFSET(blk+1)>filesize ){
|
||||
len = filesize - BLOCK_OFFSET(blk);
|
||||
}
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3OsRead(pFile->pBase, p, len);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write the cache of pFile to disk. If crash is non-zero, randomly
|
||||
** skip blocks when writing. The cache is deleted before returning.
|
||||
*/
|
||||
static int writeCache2(crashFile *pFile, int crash){
|
||||
int i;
|
||||
int nMax = pFile->nMaxWrite;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
for(i=0; i<pFile->nBlk; i++){
|
||||
u8 *p = pFile->apBlk[i];
|
||||
if( p ){
|
||||
int skip = 0;
|
||||
int trash = 0;
|
||||
if( crash ){
|
||||
char random;
|
||||
sqlite3Randomness(1, &random);
|
||||
if( random & 0x01 ){
|
||||
if( random & 0x02 ){
|
||||
trash = 1;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Trashing block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}else{
|
||||
skip = 1;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Skiping block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}
|
||||
}else{
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Writing block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3OsSeek(pFile->pBase, BLOCK_OFFSET(i));
|
||||
}
|
||||
if( rc==SQLITE_OK && !skip ){
|
||||
int len = BLOCKSIZE;
|
||||
if( BLOCK_OFFSET(i+1)>nMax ){
|
||||
len = nMax-BLOCK_OFFSET(i);
|
||||
}
|
||||
if( len>0 ){
|
||||
if( trash ){
|
||||
sqlite3Randomness(len, p);
|
||||
}
|
||||
rc = sqlite3OsWrite(pFile->pBase, p, len);
|
||||
}
|
||||
}
|
||||
sqliteFree(p);
|
||||
}
|
||||
}
|
||||
sqliteFree(pFile->apBlk);
|
||||
pFile->nBlk = 0;
|
||||
pFile->apBlk = 0;
|
||||
pFile->nMaxWrite = 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write the cache to disk.
|
||||
*/
|
||||
static int writeCache(crashFile *pFile){
|
||||
if( pFile->apBlk ){
|
||||
int c = crashRequired(pFile->zName);
|
||||
if( c ){
|
||||
crashFile *p;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("\nCrash during sync of %s\n", pFile->zName);
|
||||
#endif
|
||||
for(p=pAllFiles; p; p=p->pNext){
|
||||
writeCache2(p, 1);
|
||||
}
|
||||
exit(-1);
|
||||
}else{
|
||||
return writeCache2(pFile, 0);
|
||||
}
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close the file.
|
||||
*/
|
||||
static int crashClose(OsFile **pId){
|
||||
crashFile *pFile = (crashFile*)*pId;
|
||||
if( pFile ){
|
||||
/* printf("CLOSE %s (%d blocks)\n", pFile->zName, pFile->nBlk); */
|
||||
writeCache(pFile);
|
||||
sqlite3OsClose(&pFile->pBase);
|
||||
}
|
||||
closeFile(&pFile);
|
||||
*pId = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int crashSeek(OsFile *id, i64 offset){
|
||||
((crashFile*)id)->offset = offset;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int crashRead(OsFile *id, void *pBuf, int amt){
|
||||
i64 offset; /* The current offset from the start of the file */
|
||||
i64 end; /* The byte just past the last byte read */
|
||||
int blk; /* Block number the read starts on */
|
||||
int i;
|
||||
u8 *zCsr;
|
||||
int rc = SQLITE_OK;
|
||||
crashFile *pFile = (crashFile*)id;
|
||||
|
||||
offset = pFile->offset;
|
||||
end = offset+amt;
|
||||
blk = (offset/BLOCKSIZE);
|
||||
|
||||
zCsr = (u8 *)pBuf;
|
||||
for(i=blk; i*BLOCKSIZE<end; i++){
|
||||
int off = 0;
|
||||
int len = 0;
|
||||
|
||||
|
||||
if( BLOCK_OFFSET(i) < offset ){
|
||||
off = offset-BLOCK_OFFSET(i);
|
||||
}
|
||||
len = BLOCKSIZE - off;
|
||||
if( BLOCK_OFFSET(i+1) > end ){
|
||||
len = len - (BLOCK_OFFSET(i+1)-end);
|
||||
}
|
||||
|
||||
if( i<pFile->nBlk && pFile->apBlk[i]){
|
||||
u8 *pBlk = pFile->apBlk[i];
|
||||
memcpy(zCsr, &pBlk[off], len);
|
||||
}else{
|
||||
rc = sqlite3OsSeek(pFile->pBase, BLOCK_OFFSET(i) + off);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3OsRead(pFile->pBase, zCsr, len);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
|
||||
zCsr += len;
|
||||
}
|
||||
assert( zCsr==&((u8 *)pBuf)[amt] );
|
||||
|
||||
pFile->offset = end;
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int crashWrite(OsFile *id, const void *pBuf, int amt){
|
||||
i64 offset; /* The current offset from the start of the file */
|
||||
i64 end; /* The byte just past the last byte written */
|
||||
int blk; /* Block number the write starts on */
|
||||
int i;
|
||||
const u8 *zCsr;
|
||||
int rc = SQLITE_OK;
|
||||
crashFile *pFile = (crashFile*)id;
|
||||
|
||||
offset = pFile->offset;
|
||||
end = offset+amt;
|
||||
blk = (offset/BLOCKSIZE);
|
||||
|
||||
zCsr = (u8 *)pBuf;
|
||||
for(i=blk; i*BLOCKSIZE<end; i++){
|
||||
u8 *pBlk;
|
||||
int off = 0;
|
||||
int len = 0;
|
||||
|
||||
/* Make sure the block is in the cache */
|
||||
rc = readBlockIntoCache(pFile, i);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
/* Write into the cache */
|
||||
pBlk = pFile->apBlk[i];
|
||||
assert( pBlk );
|
||||
|
||||
if( BLOCK_OFFSET(i) < offset ){
|
||||
off = offset-BLOCK_OFFSET(i);
|
||||
}
|
||||
len = BLOCKSIZE - off;
|
||||
if( BLOCK_OFFSET(i+1) > end ){
|
||||
len = len - (BLOCK_OFFSET(i+1)-end);
|
||||
}
|
||||
memcpy(&pBlk[off], zCsr, len);
|
||||
zCsr += len;
|
||||
}
|
||||
if( pFile->nMaxWrite<end ){
|
||||
pFile->nMaxWrite = end;
|
||||
}
|
||||
assert( zCsr==&((u8 *)pBuf)[amt] );
|
||||
pFile->offset = end;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sync the file. First flush the write-cache to disk, then call the
|
||||
** real sync() function.
|
||||
*/
|
||||
static int crashSync(OsFile *id, int dataOnly){
|
||||
return writeCache((crashFile*)id);
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate the file. Set the internal OsFile.nMaxWrite variable to the new
|
||||
** file size to ensure that nothing in the write-cache past this point
|
||||
** is written to disk.
|
||||
*/
|
||||
static int crashTruncate(OsFile *id, i64 nByte){
|
||||
crashFile *pFile = (crashFile*)id;
|
||||
pFile->nMaxWrite = nByte;
|
||||
return sqlite3OsTruncate(pFile->pBase, nByte);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the size of the file. If the cache contains a write that extended
|
||||
** the file, then return this size instead of the on-disk size.
|
||||
*/
|
||||
static int crashFileSize(OsFile *id, i64 *pSize){
|
||||
crashFile *pFile = (crashFile*)id;
|
||||
int rc = sqlite3OsFileSize(pFile->pBase, pSize);
|
||||
if( rc==SQLITE_OK && pSize && *pSize<pFile->nMaxWrite ){
|
||||
*pSize = pFile->nMaxWrite;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Set this global variable to 1 to enable crash testing.
|
||||
*/
|
||||
int sqlite3CrashTestEnable = 0;
|
||||
|
||||
/*
|
||||
** The three functions used to open files. All that is required is to
|
||||
** initialise the os_test.c specific fields and then call the corresponding
|
||||
** os_unix.c function to really open the file.
|
||||
*/
|
||||
int sqlite3CrashOpenReadWrite(const char *zFilename, OsFile **pId,int *pRdonly){
|
||||
OsFile *pBase = 0;
|
||||
int rc;
|
||||
|
||||
sqlite3CrashTestEnable = 0;
|
||||
rc = sqlite3OsOpenReadWrite(zFilename, &pBase, pRdonly);
|
||||
sqlite3CrashTestEnable = 1;
|
||||
if( !rc ){
|
||||
initFile(pId, zFilename, pBase);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
int sqlite3CrashOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
|
||||
OsFile *pBase = 0;
|
||||
int rc;
|
||||
|
||||
sqlite3CrashTestEnable = 0;
|
||||
rc = sqlite3OsOpenExclusive(zFilename, &pBase, delFlag);
|
||||
sqlite3CrashTestEnable = 1;
|
||||
if( !rc ){
|
||||
initFile(pId, zFilename, pBase);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
int sqlite3CrashOpenReadOnly(const char *zFilename, OsFile **pId, int NotUsed){
|
||||
OsFile *pBase = 0;
|
||||
int rc;
|
||||
|
||||
sqlite3CrashTestEnable = 0;
|
||||
rc = sqlite3OsOpenReadOnly(zFilename, &pBase);
|
||||
sqlite3CrashTestEnable = 1;
|
||||
if( !rc ){
|
||||
initFile(pId, zFilename, pBase);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** OpenDirectory is a no-op
|
||||
*/
|
||||
static int crashOpenDir(OsFile *id, const char *zName){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Locking primitives are passed through into the underlying
|
||||
** file descriptor.
|
||||
*/
|
||||
int crashLock(OsFile *id, int lockType){
|
||||
return sqlite3OsLock(((crashFile*)id)->pBase, lockType);
|
||||
}
|
||||
int crashUnlock(OsFile *id, int lockType){
|
||||
return sqlite3OsUnlock(((crashFile*)id)->pBase, lockType);
|
||||
}
|
||||
int crashCheckReservedLock(OsFile *id){
|
||||
return sqlite3OsCheckReservedLock(((crashFile*)id)->pBase);
|
||||
}
|
||||
void crashSetFullSync(OsFile *id, int setting){
|
||||
return; /* This is a no-op */
|
||||
}
|
||||
int crashLockState(OsFile *id){
|
||||
return sqlite3OsLockState(((crashFile*)id)->pBase);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the underlying file handle.
|
||||
*/
|
||||
int crashFileHandle(OsFile *id){
|
||||
return sqlite3OsFileHandle(((crashFile*)id)->pBase);
|
||||
}
|
||||
|
||||
/*
|
||||
** This vector defines all the methods that can operate on an OsFile
|
||||
** for the crash tester.
|
||||
*/
|
||||
static const IoMethod crashIoMethod = {
|
||||
crashClose,
|
||||
crashOpenDir,
|
||||
crashRead,
|
||||
crashWrite,
|
||||
crashSeek,
|
||||
crashTruncate,
|
||||
crashSync,
|
||||
crashSetFullSync,
|
||||
crashFileHandle,
|
||||
crashFileSize,
|
||||
crashLock,
|
||||
crashUnlock,
|
||||
crashLockState,
|
||||
crashCheckReservedLock,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** Initialise the os_test.c specific fields of pFile.
|
||||
*/
|
||||
static void initFile(OsFile **pId, char const *zName, OsFile *pBase){
|
||||
crashFile *pFile = sqliteMalloc(sizeof(crashFile) + strlen(zName)+1);
|
||||
pFile->pMethod = &crashIoMethod;
|
||||
pFile->nMaxWrite = 0;
|
||||
pFile->offset = 0;
|
||||
pFile->nBlk = 0;
|
||||
pFile->apBlk = 0;
|
||||
pFile->zName = (char *)(&pFile[1]);
|
||||
strcpy(pFile->zName, zName);
|
||||
pFile->pBase = pBase;
|
||||
pFile->pNext = pAllFiles;
|
||||
pAllFiles = pFile;
|
||||
*pId = (OsFile*)pFile;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** tclcmd: sqlite_crashparams DELAY CRASHFILE
|
||||
**
|
||||
** This procedure implements a TCL command that enables crash testing
|
||||
** in testfixture. Once enabled, crash testing cannot be disabled.
|
||||
*/
|
||||
static int crashParamsObjCmd(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int delay;
|
||||
const char *zFile;
|
||||
int nFile;
|
||||
if( objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "DELAY CRASHFILE");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], &delay) ) return TCL_ERROR;
|
||||
zFile = Tcl_GetStringFromObj(objv[2], &nFile);
|
||||
if( nFile>=sizeof(zCrashFile)-1 ){
|
||||
Tcl_AppendResult(interp, "crash file name too big", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
setCrashParams(delay, zFile);
|
||||
sqlite3CrashTestEnable = 1;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_DISKIO */
|
||||
|
||||
/*
|
||||
** This procedure registers the TCL procedures defined in this file.
|
||||
*/
|
||||
int Sqlitetest6_Init(Tcl_Interp *interp){
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
Tcl_CreateObjCommand(interp, "sqlite3_crashparams", crashParamsObjCmd, 0, 0);
|
||||
#endif
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
#endif /* SQLITE_TEST */
|
||||
-723
@@ -1,723 +0,0 @@
|
||||
/*
|
||||
** 2006 January 09
|
||||
**
|
||||
** 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 client/server version of the SQLite library.
|
||||
** Derived from test4.c.
|
||||
**
|
||||
** $Id: test7.c,v 1.2 2006/01/11 23:40:34 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** This test only works on UNIX with a THREADSAFE build that includes
|
||||
** the SQLITE_SERVER option.
|
||||
*/
|
||||
#if OS_UNIX && defined(THREADSAFE) && THREADSAFE==1 && defined(SQLITE_SERVER)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
** Interfaces defined in server.c
|
||||
*/
|
||||
int sqlite3_client_open(const char*, sqlite3**);
|
||||
int sqlite3_client_prepare(sqlite3*,const char*,int,
|
||||
sqlite3_stmt**,const char**);
|
||||
int sqlite3_client_step(sqlite3_stmt*);
|
||||
int sqlite3_client_reset(sqlite3_stmt*);
|
||||
int sqlite3_client_finalize(sqlite3_stmt*);
|
||||
int sqlite3_client_close(sqlite3*);
|
||||
int sqlite3_server_start(void);
|
||||
int sqlite3_server_stop(void);
|
||||
|
||||
/*
|
||||
** Each thread is controlled by an instance of the following
|
||||
** structure.
|
||||
*/
|
||||
typedef struct Thread Thread;
|
||||
struct Thread {
|
||||
/* The first group of fields are writable by the supervisor thread
|
||||
** and read-only to the client threads
|
||||
*/
|
||||
char *zFilename; /* Name of database file */
|
||||
void (*xOp)(Thread*); /* next operation to do */
|
||||
char *zArg; /* argument usable by xOp */
|
||||
volatile int opnum; /* Operation number */
|
||||
volatile int busy; /* True if this thread is in use */
|
||||
|
||||
/* The next group of fields are writable by the client threads
|
||||
** but read-only to the superviser thread.
|
||||
*/
|
||||
volatile int completed; /* Number of operations completed */
|
||||
sqlite3 *db; /* Open database */
|
||||
sqlite3_stmt *pStmt; /* 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 */
|
||||
};
|
||||
|
||||
/*
|
||||
** There can be as many as 26 threads running at once. Each is named
|
||||
** by a capital letter: A, B, C, ..., Y, Z.
|
||||
*/
|
||||
#define N_THREAD 26
|
||||
static Thread threadset[N_THREAD];
|
||||
|
||||
/*
|
||||
** The main loop for a thread. Threads use busy waiting.
|
||||
*/
|
||||
static void *client_main(void *pArg){
|
||||
Thread *p = (Thread*)pArg;
|
||||
if( p->db ){
|
||||
sqlite3_client_close(p->db);
|
||||
}
|
||||
sqlite3_client_open(p->zFilename, &p->db);
|
||||
if( SQLITE_OK!=sqlite3_errcode(p->db) ){
|
||||
p->zErr = strdup(sqlite3_errmsg(p->db));
|
||||
sqlite3_client_close(p->db);
|
||||
p->db = 0;
|
||||
}
|
||||
p->pStmt = 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);
|
||||
p->zErr = 0;
|
||||
}
|
||||
(*p->xOp)(p);
|
||||
p->completed++;
|
||||
while( p->opnum<=p->completed ) sched_yield();
|
||||
}
|
||||
if( p->pStmt ){
|
||||
sqlite3_client_finalize(p->pStmt);
|
||||
p->pStmt = 0;
|
||||
}
|
||||
if( p->db ){
|
||||
sqlite3_client_close(p->db);
|
||||
p->db = 0;
|
||||
}
|
||||
if( p->zErr && p->zErr!=p->zStaticErr ){
|
||||
sqlite3_free(p->zErr);
|
||||
p->zErr = 0;
|
||||
}
|
||||
p->completed++;
|
||||
sqlite3_thread_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Get a thread ID which is an upper case letter. Return the index.
|
||||
** If the argument is not a valid thread ID put an error message in
|
||||
** the interpreter and return -1.
|
||||
*/
|
||||
static int parse_client_id(Tcl_Interp *interp, const char *zArg){
|
||||
if( zArg==0 || zArg[0]==0 || zArg[1]!=0 || !isupper((unsigned char)zArg[0]) ){
|
||||
Tcl_AppendResult(interp, "thread ID must be an upper case letter", 0);
|
||||
return -1;
|
||||
}
|
||||
return zArg[0] - 'A';
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_create NAME FILENAME
|
||||
**
|
||||
** NAME should be an upper case letter. Start the thread running with
|
||||
** an open connection to the given database.
|
||||
*/
|
||||
static int tcl_client_create(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
pthread_t x;
|
||||
int rc;
|
||||
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID FILENAME", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "thread ", argv[1], " is already running", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
threadset[i].busy = 1;
|
||||
sqliteFree(threadset[i].zFilename);
|
||||
threadset[i].zFilename = sqliteStrDup(argv[2]);
|
||||
threadset[i].opnum = 1;
|
||||
threadset[i].completed = 0;
|
||||
rc = pthread_create(&x, 0, client_main, &threadset[i]);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "failed to create the thread", 0);
|
||||
sqliteFree(threadset[i].zFilename);
|
||||
threadset[i].busy = 0;
|
||||
return TCL_ERROR;
|
||||
}
|
||||
pthread_detach(x);
|
||||
sqlite3_server_start();
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Wait for a thread to reach its idle state.
|
||||
*/
|
||||
static void client_wait(Thread *p){
|
||||
while( p->opnum>p->completed ) sched_yield();
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_wait ID
|
||||
**
|
||||
** Wait on thread ID to reach its idle state.
|
||||
*/
|
||||
static int tcl_client_wait(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
client_wait(&threadset[i]);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Stop a thread.
|
||||
*/
|
||||
static void stop_thread(Thread *p){
|
||||
client_wait(p);
|
||||
p->xOp = 0;
|
||||
p->opnum++;
|
||||
client_wait(p);
|
||||
sqliteFree(p->zArg);
|
||||
p->zArg = 0;
|
||||
sqliteFree(p->zFilename);
|
||||
p->zFilename = 0;
|
||||
p->busy = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_halt ID
|
||||
**
|
||||
** Cause a client thread to shut itself down. Wait for the shutdown to be
|
||||
** completed. If ID is "*" then stop all client threads.
|
||||
*/
|
||||
static int tcl_client_halt(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( argv[1][0]=='*' && argv[1][1]==0 ){
|
||||
for(i=0; i<N_THREAD; i++){
|
||||
if( threadset[i].busy ){
|
||||
stop_thread(&threadset[i]);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
stop_thread(&threadset[i]);
|
||||
}
|
||||
|
||||
/* If no client threads are still running, also stop the server */
|
||||
for(i=0; i<N_THREAD && threadset[i].busy==0; i++){}
|
||||
if( i>=N_THREAD ){
|
||||
sqlite3_server_stop();
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_argc ID
|
||||
**
|
||||
** Wait on the most recent client_step to complete, then return the
|
||||
** number of columns in the result set.
|
||||
*/
|
||||
static int tcl_client_argc(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
char zBuf[100];
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
client_wait(&threadset[i]);
|
||||
sprintf(zBuf, "%d", threadset[i].argc);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_argv ID N
|
||||
**
|
||||
** Wait on the most recent client_step to complete, then return the
|
||||
** value of the N-th columns in the result set.
|
||||
*/
|
||||
static int tcl_client_argv(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
int n;
|
||||
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID N", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
|
||||
client_wait(&threadset[i]);
|
||||
if( n<0 || n>=threadset[i].argc ){
|
||||
Tcl_AppendResult(interp, "column number out of range", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
Tcl_AppendResult(interp, threadset[i].argv[n], 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_colname ID N
|
||||
**
|
||||
** Wait on the most recent client_step to complete, then return the
|
||||
** name of the N-th columns in the result set.
|
||||
*/
|
||||
static int tcl_client_colname(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
int n;
|
||||
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID N", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
|
||||
client_wait(&threadset[i]);
|
||||
if( n<0 || n>=threadset[i].argc ){
|
||||
Tcl_AppendResult(interp, "column number out of range", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
Tcl_AppendResult(interp, threadset[i].colv[n], 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_result ID
|
||||
**
|
||||
** Wait on the most recent operation to complete, then return the
|
||||
** result code from that operation.
|
||||
*/
|
||||
static int tcl_client_result(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
const char *zName;
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
client_wait(&threadset[i]);
|
||||
switch( threadset[i].rc ){
|
||||
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
||||
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
||||
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
||||
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
||||
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
||||
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
|
||||
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
|
||||
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
|
||||
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
||||
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
||||
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
|
||||
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;
|
||||
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
|
||||
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
|
||||
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
|
||||
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
|
||||
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
|
||||
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
|
||||
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
|
||||
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
|
||||
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
|
||||
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
|
||||
default: zName = "SQLITE_Unknown"; break;
|
||||
}
|
||||
Tcl_AppendResult(interp, zName, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_error ID
|
||||
**
|
||||
** Wait on the most recent operation to complete, then return the
|
||||
** error string.
|
||||
*/
|
||||
static int tcl_client_error(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
client_wait(&threadset[i]);
|
||||
Tcl_AppendResult(interp, threadset[i].zErr, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This procedure runs in the thread to compile an SQL statement.
|
||||
*/
|
||||
static void do_compile(Thread *p){
|
||||
if( p->db==0 ){
|
||||
p->zErr = p->zStaticErr = "no database is open";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
if( p->pStmt ){
|
||||
sqlite3_client_finalize(p->pStmt);
|
||||
p->pStmt = 0;
|
||||
}
|
||||
p->rc = sqlite3_client_prepare(p->db, p->zArg, -1, &p->pStmt, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_compile ID SQL
|
||||
**
|
||||
** Compile a new virtual machine.
|
||||
*/
|
||||
static int tcl_client_compile(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID SQL", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
client_wait(&threadset[i]);
|
||||
threadset[i].xOp = do_compile;
|
||||
sqliteFree(threadset[i].zArg);
|
||||
threadset[i].zArg = sqliteStrDup(argv[2]);
|
||||
threadset[i].opnum++;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This procedure runs in the thread to step the virtual machine.
|
||||
*/
|
||||
static void do_step(Thread *p){
|
||||
int i;
|
||||
if( p->pStmt==0 ){
|
||||
p->zErr = p->zStaticErr = "no virtual machine available";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
p->rc = sqlite3_client_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_step ID
|
||||
**
|
||||
** Advance the virtual machine by one step
|
||||
*/
|
||||
static int tcl_client_step(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" IDL", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
client_wait(&threadset[i]);
|
||||
threadset[i].xOp = do_step;
|
||||
threadset[i].opnum++;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This procedure runs in the thread to finalize a virtual machine.
|
||||
*/
|
||||
static void do_finalize(Thread *p){
|
||||
if( p->pStmt==0 ){
|
||||
p->zErr = p->zStaticErr = "no virtual machine available";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
p->rc = sqlite3_client_finalize(p->pStmt);
|
||||
p->pStmt = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_finalize ID
|
||||
**
|
||||
** Finalize the virtual machine.
|
||||
*/
|
||||
static int tcl_client_finalize(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" IDL", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
client_wait(&threadset[i]);
|
||||
threadset[i].xOp = do_finalize;
|
||||
sqliteFree(threadset[i].zArg);
|
||||
threadset[i].zArg = 0;
|
||||
threadset[i].opnum++;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This procedure runs in the thread to reset a virtual machine.
|
||||
*/
|
||||
static void do_reset(Thread *p){
|
||||
if( p->pStmt==0 ){
|
||||
p->zErr = p->zStaticErr = "no virtual machine available";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
p->rc = sqlite3_client_reset(p->pStmt);
|
||||
p->pStmt = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_reset ID
|
||||
**
|
||||
** Finalize the virtual machine.
|
||||
*/
|
||||
static int tcl_client_reset(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" IDL", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
client_wait(&threadset[i]);
|
||||
threadset[i].xOp = do_reset;
|
||||
sqliteFree(threadset[i].zArg);
|
||||
threadset[i].zArg = 0;
|
||||
threadset[i].opnum++;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: client_swap ID ID
|
||||
**
|
||||
** Interchange the sqlite* pointer between two threads.
|
||||
*/
|
||||
static int tcl_client_swap(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i, j;
|
||||
sqlite3 *temp;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID1 ID2", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_client_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
client_wait(&threadset[i]);
|
||||
j = parse_client_id(interp, argv[2]);
|
||||
if( j<0 ) return TCL_ERROR;
|
||||
if( !threadset[j].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
client_wait(&threadset[j]);
|
||||
temp = threadset[i].db;
|
||||
threadset[i].db = threadset[j].db;
|
||||
threadset[j].db = temp;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest7_Init(Tcl_Interp *interp){
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_CmdProc *xProc;
|
||||
} aCmd[] = {
|
||||
{ "client_create", (Tcl_CmdProc*)tcl_client_create },
|
||||
{ "client_wait", (Tcl_CmdProc*)tcl_client_wait },
|
||||
{ "client_halt", (Tcl_CmdProc*)tcl_client_halt },
|
||||
{ "client_argc", (Tcl_CmdProc*)tcl_client_argc },
|
||||
{ "client_argv", (Tcl_CmdProc*)tcl_client_argv },
|
||||
{ "client_colname", (Tcl_CmdProc*)tcl_client_colname },
|
||||
{ "client_result", (Tcl_CmdProc*)tcl_client_result },
|
||||
{ "client_error", (Tcl_CmdProc*)tcl_client_error },
|
||||
{ "client_compile", (Tcl_CmdProc*)tcl_client_compile },
|
||||
{ "client_step", (Tcl_CmdProc*)tcl_client_step },
|
||||
{ "client_reset", (Tcl_CmdProc*)tcl_client_reset },
|
||||
{ "client_finalize", (Tcl_CmdProc*)tcl_client_finalize },
|
||||
{ "client_swap", (Tcl_CmdProc*)tcl_client_swap },
|
||||
};
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
||||
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
#else
|
||||
int Sqlitetest7_Init(Tcl_Interp *interp){ return TCL_OK; }
|
||||
#endif /* OS_UNIX */
|
||||
-1112
File diff suppressed because it is too large
Load Diff
+10
-20
@@ -15,7 +15,7 @@
|
||||
** individual tokens and sends those tokens one-by-one over to the
|
||||
** parser for analysis.
|
||||
**
|
||||
** $Id: tokenize.c,v 1.114 2006/01/12 12:43:36 drh Exp $
|
||||
** $Id: tokenize.c,v 1.107 2005/08/23 11:31:26 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -196,13 +196,9 @@ static int getToken(const unsigned char *z, int *tokenType){
|
||||
}
|
||||
}
|
||||
}
|
||||
if( c ){
|
||||
*tokenType = TK_STRING;
|
||||
return i+1;
|
||||
}else{
|
||||
*tokenType = TK_ILLEGAL;
|
||||
return i;
|
||||
}
|
||||
if( c ) i++;
|
||||
*tokenType = TK_STRING;
|
||||
return i;
|
||||
}
|
||||
case '.': {
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
@@ -339,7 +335,6 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
int tokenType;
|
||||
int lastTokenParsed = -1;
|
||||
sqlite3 *db = pParse->db;
|
||||
ThreadData *pTsd = pParse->pTsd;
|
||||
extern void *sqlite3ParserAlloc(void*(*)(int));
|
||||
extern void sqlite3ParserFree(void*, void(*)(void*));
|
||||
extern int sqlite3Parser(void*, int, Token, Parse*);
|
||||
@@ -349,6 +344,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
i = 0;
|
||||
pEngine = sqlite3ParserAlloc((void*(*)(int))sqlite3MallocX);
|
||||
if( pEngine==0 ){
|
||||
sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( pParse->sLastToken.dyn==0 );
|
||||
@@ -359,9 +355,9 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
assert( pParse->nVarExprAlloc==0 );
|
||||
assert( pParse->apVarExpr==0 );
|
||||
pParse->zTail = pParse->zSql = zSql;
|
||||
while( pTsd->mallocFailed==0 && zSql[i]!=0 ){
|
||||
while( sqlite3_malloc_failed==0 && zSql[i]!=0 ){
|
||||
assert( i>=0 );
|
||||
pParse->sLastToken.z = (u8*)&zSql[i];
|
||||
pParse->sLastToken.z = &zSql[i];
|
||||
assert( pParse->sLastToken.dyn==0 );
|
||||
pParse->sLastToken.n = getToken((unsigned char*)&zSql[i],&tokenType);
|
||||
i += pParse->sLastToken.n;
|
||||
@@ -407,11 +403,12 @@ abort_parse:
|
||||
sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
|
||||
}
|
||||
sqlite3ParserFree(pEngine, sqlite3FreeX);
|
||||
if( pTsd->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
}
|
||||
if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
|
||||
sqlite3SetString(&pParse->zErrMsg, sqlite3ErrStr(pParse->rc), (char*)0);
|
||||
sqlite3SetString(&pParse->zErrMsg, sqlite3ErrStr(pParse->rc),
|
||||
(char*)0);
|
||||
}
|
||||
if( pParse->zErrMsg ){
|
||||
if( pzErrMsg && *pzErrMsg==0 ){
|
||||
@@ -426,13 +423,6 @@ abort_parse:
|
||||
sqlite3VdbeDelete(pParse->pVdbe);
|
||||
pParse->pVdbe = 0;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
if( pParse->nested==0 ){
|
||||
sqliteFree(pParse->aTableLock);
|
||||
pParse->aTableLock = 0;
|
||||
pParse->nTableLock = 0;
|
||||
}
|
||||
#endif
|
||||
sqlite3DeleteTable(pParse->db, pParse->pNewTable);
|
||||
sqlite3DeleteTrigger(pParse->pNewTrigger);
|
||||
sqliteFree(pParse->apVarExpr);
|
||||
|
||||
+52
-61
@@ -58,7 +58,6 @@ void sqlite3BeginTrigger(
|
||||
int iDb; /* The database to store the trigger in */
|
||||
Token *pName; /* The unqualified db name */
|
||||
DbFixer sFix;
|
||||
int iTabDb;
|
||||
|
||||
if( isTemp ){
|
||||
/* If TEMP was specified, then the trigger name may not be qualified. */
|
||||
@@ -81,16 +80,14 @@ void sqlite3BeginTrigger(
|
||||
** If sqlite3SrcListLookup() returns 0, indicating the table does not
|
||||
** exist, the error is caught by the block below.
|
||||
*/
|
||||
if( !pTableName || sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( !pTableName || sqlite3_malloc_failed ) goto trigger_cleanup;
|
||||
pTab = sqlite3SrcListLookup(pParse, pTableName);
|
||||
if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
|
||||
if( pName2->n==0 && pTab && pTab->iDb==1 ){
|
||||
iDb = 1;
|
||||
}
|
||||
|
||||
/* Ensure the table name matches database name and that the table exists */
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ) goto trigger_cleanup;
|
||||
if( sqlite3_malloc_failed ) goto trigger_cleanup;
|
||||
assert( pTableName->nSrc==1 );
|
||||
if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) &&
|
||||
sqlite3FixSrcList(&sFix, pTableName) ){
|
||||
@@ -108,7 +105,7 @@ void sqlite3BeginTrigger(
|
||||
if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash), zName,pName->n+1) ){
|
||||
if( sqlite3HashFind(&(db->aDb[iDb].trigHash), zName,pName->n+1) ){
|
||||
sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
@@ -133,18 +130,17 @@ void sqlite3BeginTrigger(
|
||||
" trigger on table: %S", pTableName, 0);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
int code = SQLITE_CREATE_TRIGGER;
|
||||
const char *zDb = db->aDb[iTabDb].zName;
|
||||
const char *zDb = db->aDb[pTab->iDb].zName;
|
||||
const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
|
||||
if( iTabDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
|
||||
if( pTab->iDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
|
||||
if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iTabDb),0,zDb)){
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(pTab->iDb),0,zDb)){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -165,8 +161,8 @@ void sqlite3BeginTrigger(
|
||||
pTrigger->name = zName;
|
||||
zName = 0;
|
||||
pTrigger->table = sqliteStrDup(pTableName->a[0].zName);
|
||||
pTrigger->pSchema = db->aDb[iDb].pSchema;
|
||||
pTrigger->pTabSchema = pTab->pSchema;
|
||||
pTrigger->iDb = iDb;
|
||||
pTrigger->iTabDb = pTab->iDb;
|
||||
pTrigger->op = op;
|
||||
pTrigger->tr_tm = tr_tm==TK_BEFORE ? TRIGGER_BEFORE : TRIGGER_AFTER;
|
||||
pTrigger->pWhen = sqlite3ExprDup(pWhen);
|
||||
@@ -200,18 +196,16 @@ void sqlite3FinishTrigger(
|
||||
Trigger *pTrig = 0; /* The trigger whose construction is finishing up */
|
||||
sqlite3 *db = pParse->db; /* The database */
|
||||
DbFixer sFix;
|
||||
int iDb; /* Database containing the trigger */
|
||||
|
||||
pTrig = pParse->pNewTrigger;
|
||||
pParse->pNewTrigger = 0;
|
||||
if( pParse->nErr || !pTrig ) goto triggerfinish_cleanup;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
|
||||
if( pParse->nErr || pTrig==0 ) goto triggerfinish_cleanup;
|
||||
pTrig->step_list = pStepList;
|
||||
while( pStepList ){
|
||||
pStepList->pTrig = pTrig;
|
||||
pStepList = pStepList->pNext;
|
||||
}
|
||||
if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", &pTrig->nameToken)
|
||||
if( sqlite3FixInit(&sFix, pParse, pTrig->iDb, "trigger", &pTrig->nameToken)
|
||||
&& sqlite3FixTriggerStep(&sFix, pTrig->step_list) ){
|
||||
goto triggerfinish_cleanup;
|
||||
}
|
||||
@@ -229,7 +223,7 @@ void sqlite3FinishTrigger(
|
||||
{ OP_String8, 0, 0, "CREATE TRIGGER "},
|
||||
{ OP_String8, 0, 0, 0 }, /* 6: SQL */
|
||||
{ OP_Concat, 0, 0, 0 },
|
||||
{ OP_MakeRecord, 5, 0, "aaada" },
|
||||
{ OP_MakeRecord, 5, 0, "tttit" },
|
||||
{ OP_Insert, 0, 0, 0 },
|
||||
};
|
||||
int addr;
|
||||
@@ -238,30 +232,28 @@ void sqlite3FinishTrigger(
|
||||
/* Make an entry in the sqlite_master table */
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) goto triggerfinish_cleanup;
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
sqlite3OpenMasterTable(pParse, iDb);
|
||||
sqlite3BeginWriteOperation(pParse, 0, pTrig->iDb);
|
||||
sqlite3OpenMasterTable(v, pTrig->iDb);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(insertTrig), insertTrig);
|
||||
sqlite3VdbeChangeP3(v, addr+2, pTrig->name, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+3, pTrig->table, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+6, (char*)pAll->z, pAll->n);
|
||||
sqlite3ChangeCookie(db, v, iDb);
|
||||
sqlite3VdbeChangeP3(v, addr+6, pAll->z, pAll->n);
|
||||
sqlite3ChangeCookie(db, v, pTrig->iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0,
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, pTrig->iDb, 0,
|
||||
sqlite3MPrintf("type='trigger' AND name='%q'", pTrig->name), P3_DYNAMIC);
|
||||
}
|
||||
|
||||
if( db->init.busy ){
|
||||
int n;
|
||||
Table *pTab;
|
||||
Trigger *pDel;
|
||||
pDel = sqlite3HashInsert(&db->aDb[iDb].pSchema->trigHash,
|
||||
pDel = sqlite3HashInsert(&db->aDb[pTrig->iDb].trigHash,
|
||||
pTrig->name, strlen(pTrig->name)+1, pTrig);
|
||||
if( pDel ){
|
||||
assert( sqlite3ThreadDataReadOnly()->mallocFailed && pDel==pTrig );
|
||||
assert( sqlite3_malloc_failed && pDel==pTrig );
|
||||
goto triggerfinish_cleanup;
|
||||
}
|
||||
n = strlen(pTrig->table) + 1;
|
||||
pTab = sqlite3HashFind(&pTrig->pTabSchema->tblHash, pTrig->table, n);
|
||||
pTab = sqlite3LocateTable(pParse,pTrig->table,db->aDb[pTrig->iTabDb].zName);
|
||||
assert( pTab!=0 );
|
||||
pTrig->pNext = pTab->pTrigger;
|
||||
pTab->pTrigger = pTrig;
|
||||
@@ -286,7 +278,7 @@ triggerfinish_cleanup:
|
||||
*/
|
||||
static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
if( p->target.z ){
|
||||
p->target.z = (u8*)sqliteStrNDup((char*)p->target.z, p->target.n);
|
||||
p->target.z = sqliteStrNDup(p->target.z, p->target.n);
|
||||
p->target.dyn = 1;
|
||||
}
|
||||
if( p->pSelect ){
|
||||
@@ -320,10 +312,7 @@ static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
*/
|
||||
TriggerStep *sqlite3TriggerSelectStep(Select *pSelect){
|
||||
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
|
||||
if( pTriggerStep==0 ) {
|
||||
sqlite3SelectDelete(pSelect);
|
||||
return 0;
|
||||
}
|
||||
if( pTriggerStep==0 ) return 0;
|
||||
|
||||
pTriggerStep->op = TK_SELECT;
|
||||
pTriggerStep->pSelect = pSelect;
|
||||
@@ -441,7 +430,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
|
||||
int nName;
|
||||
sqlite3 *db = pParse->db;
|
||||
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ) goto drop_trigger_cleanup;
|
||||
if( sqlite3_malloc_failed ) goto drop_trigger_cleanup;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
|
||||
goto drop_trigger_cleanup;
|
||||
}
|
||||
@@ -453,7 +442,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
|
||||
for(i=OMIT_TEMPDB; 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].pSchema->trigHash), zName, nName+1);
|
||||
pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1);
|
||||
if( pTrigger ) break;
|
||||
}
|
||||
if( !pTrigger ){
|
||||
@@ -471,8 +460,7 @@ drop_trigger_cleanup:
|
||||
** is set on.
|
||||
*/
|
||||
static Table *tableOfTrigger(sqlite3 *db, Trigger *pTrigger){
|
||||
int n = strlen(pTrigger->table) + 1;
|
||||
return sqlite3HashFind(&pTrigger->pTabSchema->tblHash, pTrigger->table, n);
|
||||
return sqlite3FindTable(db,pTrigger->table,db->aDb[pTrigger->iTabDb].zName);
|
||||
}
|
||||
|
||||
|
||||
@@ -487,11 +475,11 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb;
|
||||
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);
|
||||
iDb = pTrigger->iDb;
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
pTable = tableOfTrigger(db, pTrigger);
|
||||
assert(pTable);
|
||||
assert( pTable->pSchema==pTrigger->pSchema || iDb==1 );
|
||||
assert( pTable->iDb==iDb || iDb==1 );
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
int code = SQLITE_DROP_TRIGGER;
|
||||
@@ -522,7 +510,7 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
};
|
||||
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
sqlite3OpenMasterTable(pParse, iDb);
|
||||
sqlite3OpenMasterTable(v, iDb);
|
||||
base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
|
||||
sqlite3VdbeChangeP3(v, base+1, pTrigger->name, 0);
|
||||
sqlite3ChangeCookie(db, v, iDb);
|
||||
@@ -537,7 +525,7 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
|
||||
Trigger *pTrigger;
|
||||
int nName = strlen(zName);
|
||||
pTrigger = sqlite3HashInsert(&(db->aDb[iDb].pSchema->trigHash), zName, nName+1, 0);
|
||||
pTrigger = sqlite3HashInsert(&(db->aDb[iDb].trigHash), zName, nName+1, 0);
|
||||
if( pTrigger ){
|
||||
Table *pTable = tableOfTrigger(db, pTrigger);
|
||||
assert( pTable!=0 );
|
||||
@@ -629,11 +617,11 @@ static SrcList *targetSrcList(
|
||||
int iDb; /* Index of the database to use */
|
||||
SrcList *pSrc; /* SrcList to be returned */
|
||||
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
|
||||
iDb = pStep->pTrig->iDb;
|
||||
if( iDb==0 || iDb>=2 ){
|
||||
assert( iDb<pParse->db->nDb );
|
||||
sDb.z = (u8*)pParse->db->aDb[iDb].zName;
|
||||
sDb.n = strlen((char*)sDb.z);
|
||||
sDb.z = pParse->db->aDb[iDb].zName;
|
||||
sDb.n = strlen(sDb.z);
|
||||
pSrc = sqlite3SrcListAppend(0, &sDb, &pStep->target);
|
||||
} else {
|
||||
pSrc = sqlite3SrcListAppend(0, &pStep->target, 0);
|
||||
@@ -742,7 +730,8 @@ int sqlite3CodeRowTrigger(
|
||||
int orconf, /* ON CONFLICT policy */
|
||||
int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
|
||||
){
|
||||
Trigger *p;
|
||||
Trigger *pTrigger;
|
||||
TriggerStack *pStack;
|
||||
TriggerStack trigStackEntry;
|
||||
|
||||
assert(op == TK_UPDATE || op == TK_INSERT || op == TK_DELETE);
|
||||
@@ -750,20 +739,21 @@ int sqlite3CodeRowTrigger(
|
||||
|
||||
assert(newIdx != -1 || oldIdx != -1);
|
||||
|
||||
for(p=pTab->pTrigger; p; p=p->pNext){
|
||||
pTrigger = pTab->pTrigger;
|
||||
while( pTrigger ){
|
||||
int fire_this = 0;
|
||||
|
||||
/* Determine whether we should code this trigger */
|
||||
if(
|
||||
p->op==op &&
|
||||
p->tr_tm==tr_tm &&
|
||||
(p->pSchema==p->pTabSchema || p->pSchema==pParse->db->aDb[1].pSchema) &&
|
||||
(op!=TK_UPDATE||!p->pColumns||checkColumnOverLap(p->pColumns,pChanges))
|
||||
){
|
||||
TriggerStack *pS; /* Pointer to trigger-stack entry */
|
||||
for(pS=pParse->trigStack; pS && p!=pS->pTrigger; pS=pS->pNext);
|
||||
if( !pS ){
|
||||
fire_this = 1;
|
||||
/* determine whether we should code this trigger */
|
||||
if( pTrigger->op == op && pTrigger->tr_tm == tr_tm ){
|
||||
fire_this = 1;
|
||||
for(pStack=pParse->trigStack; pStack; pStack=pStack->pNext){
|
||||
if( pStack->pTrigger==pTrigger ){
|
||||
fire_this = 0;
|
||||
}
|
||||
}
|
||||
if( op == TK_UPDATE && pTrigger->pColumns &&
|
||||
!checkColumnOverLap(pTrigger->pColumns, pChanges) ){
|
||||
fire_this = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,18 +767,18 @@ int sqlite3CodeRowTrigger(
|
||||
sNC.pParse = pParse;
|
||||
|
||||
/* Push an entry on to the trigger stack */
|
||||
trigStackEntry.pTrigger = p;
|
||||
trigStackEntry.pTrigger = pTrigger;
|
||||
trigStackEntry.newIdx = newIdx;
|
||||
trigStackEntry.oldIdx = oldIdx;
|
||||
trigStackEntry.pTab = pTab;
|
||||
trigStackEntry.pNext = pParse->trigStack;
|
||||
trigStackEntry.ignoreJump = ignoreJump;
|
||||
pParse->trigStack = &trigStackEntry;
|
||||
sqlite3AuthContextPush(pParse, &sContext, p->name);
|
||||
sqlite3AuthContextPush(pParse, &sContext, pTrigger->name);
|
||||
|
||||
/* code the WHEN clause */
|
||||
endTrigger = sqlite3VdbeMakeLabel(pParse->pVdbe);
|
||||
whenExpr = sqlite3ExprDup(p->pWhen);
|
||||
whenExpr = sqlite3ExprDup(pTrigger->pWhen);
|
||||
if( sqlite3ExprResolveNames(&sNC, whenExpr) ){
|
||||
pParse->trigStack = trigStackEntry.pNext;
|
||||
sqlite3ExprDelete(whenExpr);
|
||||
@@ -797,7 +787,7 @@ int sqlite3CodeRowTrigger(
|
||||
sqlite3ExprIfFalse(pParse, whenExpr, endTrigger, 1);
|
||||
sqlite3ExprDelete(whenExpr);
|
||||
|
||||
codeTriggerProgram(pParse, p->step_list, orconf);
|
||||
codeTriggerProgram(pParse, pTrigger->step_list, orconf);
|
||||
|
||||
/* Pop the entry off the trigger stack */
|
||||
pParse->trigStack = trigStackEntry.pNext;
|
||||
@@ -805,6 +795,7 @@ int sqlite3CodeRowTrigger(
|
||||
|
||||
sqlite3VdbeResolveLabel(pParse->pVdbe, endTrigger);
|
||||
}
|
||||
pTrigger = pTrigger->pNext;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+14
-16
@@ -12,13 +12,13 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle UPDATE statements.
|
||||
**
|
||||
** $Id: update.c,v 1.120 2006/01/11 21:41:22 drh Exp $
|
||||
** $Id: update.c,v 1.112 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** The most recently coded instruction was an OP_Column to retrieve the
|
||||
** i-th column of table pTab. This routine sets the P3 parameter of the
|
||||
** The most recently coded instruction was an OP_Column to retrieve column
|
||||
** 'i' of table pTab. This routine sets the P3 parameter of the
|
||||
** OP_Column to the default value, if any.
|
||||
**
|
||||
** The default value of a column is specified by a DEFAULT clause in the
|
||||
@@ -44,7 +44,7 @@
|
||||
void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i){
|
||||
if( pTab && !pTab->pSelect ){
|
||||
sqlite3_value *pValue;
|
||||
u8 enc = ENC(sqlite3VdbeDb(v));
|
||||
u8 enc = sqlite3VdbeDb(v)->enc;
|
||||
Column *pCol = &pTab->aCol[i];
|
||||
sqlite3ValueFromExpr(pCol->pDflt, enc, pCol->affinity, &pValue);
|
||||
if( pValue ){
|
||||
@@ -89,7 +89,6 @@ void sqlite3Update(
|
||||
int openAll = 0; /* True if all indices need to be opened */
|
||||
AuthContext sContext; /* The authorization context */
|
||||
NameContext sNC; /* The name-context to resolve expressions in */
|
||||
int iDb; /* Database containing the table being updated */
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* Trying to update a view */
|
||||
@@ -100,9 +99,7 @@ void sqlite3Update(
|
||||
int oldIdx = -1; /* index of trigger "old" temp table */
|
||||
|
||||
sContext.pParse = 0;
|
||||
if( pParse->nErr || sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( pParse->nErr || sqlite3_malloc_failed ) goto update_cleanup;
|
||||
db = pParse->db;
|
||||
assert( pTabList->nSrc==1 );
|
||||
|
||||
@@ -110,7 +107,6 @@ void sqlite3Update(
|
||||
*/
|
||||
pTab = sqlite3SrcListLookup(pParse, pTabList);
|
||||
if( pTab==0 ) goto update_cleanup;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
|
||||
/* Figure out if we have any triggers and if the table being
|
||||
** updated is a view
|
||||
@@ -196,7 +192,7 @@ void sqlite3Update(
|
||||
{
|
||||
int rc;
|
||||
rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
|
||||
pTab->aCol[j].zName, db->aDb[iDb].zName);
|
||||
pTab->aCol[j].zName, db->aDb[pTab->iDb].zName);
|
||||
if( rc==SQLITE_DENY ){
|
||||
goto update_cleanup;
|
||||
}else if( rc==SQLITE_IGNORE ){
|
||||
@@ -235,6 +231,7 @@ void sqlite3Update(
|
||||
}
|
||||
}
|
||||
if( i<pIdx->nColumn ){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ) goto update_cleanup;
|
||||
apIdx[nIdx++] = pIdx;
|
||||
aIdxUsed[j] = 1;
|
||||
}else{
|
||||
@@ -260,7 +257,7 @@ void sqlite3Update(
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) goto update_cleanup;
|
||||
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, 1, iDb);
|
||||
sqlite3BeginWriteOperation(pParse, 1, pTab->iDb);
|
||||
|
||||
/* If we are trying to update a view, realize that view into
|
||||
** a ephemeral table.
|
||||
@@ -310,7 +307,7 @@ void sqlite3Update(
|
||||
/* Open a cursor and make it point to the record that is
|
||||
** being updated.
|
||||
*/
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
|
||||
@@ -365,7 +362,9 @@ void sqlite3Update(
|
||||
** action, then we need to open all indices because we might need
|
||||
** to be deleting some records.
|
||||
*/
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
if( onError==OE_Replace ){
|
||||
openAll = 1;
|
||||
}else{
|
||||
@@ -379,10 +378,9 @@ void sqlite3Update(
|
||||
}
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
if( openAll || aIdxUsed[i] ){
|
||||
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqlite3VdbeOp3(v, OP_OpenWrite, iCur+i+1, pIdx->tnum,
|
||||
(char*)pKey, P3_KEYINFO_HANDOFF);
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
assert( pParse->nTab>iCur+i+1 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
** This file contains routines used to translate between UTF-8,
|
||||
** UTF-16, UTF-16BE, and UTF-16LE.
|
||||
**
|
||||
** $Id: utf.c,v 1.36 2006/01/13 06:33:24 danielk1977 Exp $
|
||||
** $Id: utf.c,v 1.32 2005/01/28 01:29:08 drh Exp $
|
||||
**
|
||||
** Notes on UTF-8:
|
||||
**
|
||||
@@ -272,7 +272,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
assert( rc==SQLITE_NOMEM );
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
zIn = (u8*)pMem->z;
|
||||
zIn = pMem->z;
|
||||
zTerm = &zIn[pMem->n];
|
||||
while( zIn<zTerm ){
|
||||
temp = *zIn;
|
||||
@@ -308,7 +308,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
** obtained from malloc(), or Mem.zShort, if it large enough and not in
|
||||
** use, or the zShort array on the stack (see above).
|
||||
*/
|
||||
zIn = (u8*)pMem->z;
|
||||
zIn = pMem->z;
|
||||
zTerm = &zIn[pMem->n];
|
||||
if( len>NBFS ){
|
||||
zOut = sqliteMallocRaw(len);
|
||||
@@ -360,12 +360,12 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
pMem->enc = desiredEnc;
|
||||
if( zOut==zShort ){
|
||||
memcpy(pMem->zShort, zOut, len);
|
||||
zOut = (u8*)pMem->zShort;
|
||||
zOut = pMem->zShort;
|
||||
pMem->flags |= (MEM_Term|MEM_Short);
|
||||
}else{
|
||||
pMem->flags |= (MEM_Term|MEM_Dyn);
|
||||
}
|
||||
pMem->z = (char*)zOut;
|
||||
pMem->z = zOut;
|
||||
|
||||
translate_out:
|
||||
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
|
||||
@@ -450,23 +450,6 @@ int sqlite3utf8CharLen(const char *z, int nByte){
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** Convert a UTF-16 string in the native encoding into a UTF-8 string.
|
||||
** Memory to hold the UTF-8 string is obtained from malloc and must be
|
||||
** freed by the calling function.
|
||||
**
|
||||
** NULL is returned if there is an allocation error.
|
||||
*/
|
||||
char *sqlite3utf16to8(const void *z, int nByte){
|
||||
Mem m;
|
||||
memset(&m, 0, sizeof(m));
|
||||
sqlite3VdbeMemSetStr(&m, z, nByte, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
sqlite3VdbeChangeEncoding(&m, SQLITE_UTF8);
|
||||
assert( m.flags & MEM_Term );
|
||||
assert( m.flags & MEM_Str );
|
||||
return (m.flags & MEM_Dyn)!=0 ? m.z : sqliteStrDup(m.z);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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
|
||||
|
||||
+290
-655
File diff suppressed because it is too large
Load Diff
+19
-38
@@ -14,10 +14,9 @@
|
||||
** Most of the code in this file may be omitted by defining the
|
||||
** SQLITE_OMIT_VACUUM macro.
|
||||
**
|
||||
** $Id: vacuum.c,v 1.57 2006/01/13 01:48:59 drh Exp $
|
||||
** $Id: vacuum.c,v 1.45 2005/06/07 09:21:07 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
#include "os.h"
|
||||
|
||||
#ifndef SQLITE_OMIT_VACUUM
|
||||
@@ -59,7 +58,7 @@ static int execExecSql(sqlite3 *db, const char *zSql){
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
rc = execSql(db, (char*)sqlite3_column_text(pStmt, 0));
|
||||
rc = execSql(db, sqlite3_column_text(pStmt, 0));
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3_finalize(pStmt);
|
||||
return rc;
|
||||
@@ -101,12 +100,11 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
Btree *pMain; /* The database being vacuumed */
|
||||
Btree *pTemp;
|
||||
char *zSql = 0;
|
||||
int saved_flags; /* Saved value of the db->flags */
|
||||
Db *pDb = 0; /* Database to detach at end of vacuum */
|
||||
int writeschema_flag; /* Saved value of the write-schema flag */
|
||||
|
||||
/* Save the current value of the write-schema flag before setting it. */
|
||||
saved_flags = db->flags;
|
||||
db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
|
||||
writeschema_flag = db->flags&SQLITE_WriteSchema;
|
||||
db->flags |= SQLITE_WriteSchema;
|
||||
|
||||
if( !db->autoCommit ){
|
||||
sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction",
|
||||
@@ -166,23 +164,19 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
sqliteFree(zSql);
|
||||
zSql = 0;
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
pDb = &db->aDb[db->nDb-1];
|
||||
assert( strcmp(db->aDb[db->nDb-1].zName,"vacuum_db")==0 );
|
||||
pTemp = db->aDb[db->nDb-1].pBt;
|
||||
sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain),
|
||||
sqlite3BtreeGetReserve(pMain));
|
||||
assert( sqlite3BtreeGetPageSize(pTemp)==sqlite3BtreeGetPageSize(pMain) );
|
||||
rc = execSql(db, "PRAGMA vacuum_db.synchronous=OFF");
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
execSql(db, "PRAGMA vacuum_db.synchronous=OFF");
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
sqlite3BtreeSetAutoVacuum(pTemp, sqlite3BtreeGetAutoVacuum(pMain));
|
||||
#endif
|
||||
|
||||
/* Begin a transaction */
|
||||
rc = execSql(db, "BEGIN EXCLUSIVE;");
|
||||
rc = execSql(db, "BEGIN;");
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Query the schema of the main database. Create a mirror schema
|
||||
@@ -253,7 +247,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
** opened for writing. This way, the SQL transaction used to create the
|
||||
** temporary database never needs to be committed.
|
||||
*/
|
||||
if( rc==SQLITE_OK ){
|
||||
if( sqlite3BtreeIsInTrans(pTemp) ){
|
||||
u32 meta;
|
||||
int i;
|
||||
|
||||
@@ -270,27 +264,26 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
6, 0, /* Preserve the user version */
|
||||
};
|
||||
|
||||
assert( 1==sqlite3BtreeIsInTrans(pTemp) );
|
||||
assert( 1==sqlite3BtreeIsInTrans(pMain) );
|
||||
assert( 0==sqlite3BtreeIsInTrans(pMain) );
|
||||
rc = sqlite3BtreeBeginTrans(pMain, 1);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Copy Btree meta values */
|
||||
for(i=0; i<sizeof(aCopy)/sizeof(aCopy[0]); i+=2){
|
||||
rc = sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
}
|
||||
|
||||
rc = sqlite3BtreeCopyFile(pMain, pTemp);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeCommit(pTemp);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeCommit(pMain);
|
||||
}
|
||||
|
||||
end_of_vacuum:
|
||||
/* Restore the original value of db->flags */
|
||||
db->flags = saved_flags;
|
||||
/* Restore the original value of the write-schema flag. */
|
||||
db->flags &= ~SQLITE_WriteSchema;
|
||||
db->flags |= writeschema_flag;
|
||||
|
||||
/* Currently there is an SQL level transaction open on the vacuum
|
||||
** database. No locks are held on any other files (since the main file
|
||||
@@ -300,28 +293,16 @@ end_of_vacuum:
|
||||
** is closed by the DETACH.
|
||||
*/
|
||||
db->autoCommit = 1;
|
||||
|
||||
if( pDb ){
|
||||
sqlite3MallocDisallow();
|
||||
sqlite3BtreeClose(pDb->pBt);
|
||||
sqlite3MallocAllow();
|
||||
pDb->pBt = 0;
|
||||
pDb->pSchema = 0;
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = execSql(db, "DETACH vacuum_db;");
|
||||
}else{
|
||||
execSql(db, "DETACH vacuum_db;");
|
||||
}
|
||||
|
||||
/* If one of the execSql() calls above returned SQLITE_NOMEM, then the
|
||||
** mallocFailed flag will be clear (because execSql() calls sqlite3_exec()).
|
||||
** Fix this so the flag and return code match.
|
||||
*/
|
||||
if( rc==SQLITE_NOMEM ){
|
||||
sqlite3ThreadData()->mallocFailed = 1;
|
||||
}
|
||||
|
||||
if( zTemp ){
|
||||
sqlite3OsDelete(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
}
|
||||
sqliteFree( zSql );
|
||||
if( zSql ) sqliteFree( zSql );
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
#endif
|
||||
|
||||
|
||||
+275
-502
File diff suppressed because it is too large
Load Diff
+6
-17
@@ -60,7 +60,6 @@ typedef unsigned char Bool;
|
||||
*/
|
||||
struct Cursor {
|
||||
BtCursor *pCursor; /* The cursor structure of the backend */
|
||||
int iDb; /* Index of cursor database in db->aDb[] (or -1) */
|
||||
i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
|
||||
i64 nextRowid; /* Next rowid returned by OP_NewRowid */
|
||||
Bool zeroed; /* True if zeroed out and ready for reuse */
|
||||
@@ -86,10 +85,9 @@ struct Cursor {
|
||||
|
||||
/* Cached information about the header for the data record that the
|
||||
** cursor is currently pointing to. Only valid if cacheValid is true.
|
||||
** aRow might point to (ephemeral) data for the current row, or it might
|
||||
** be NULL.
|
||||
*/
|
||||
int cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
|
||||
** 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 */
|
||||
@@ -104,11 +102,6 @@ typedef struct Cursor Cursor;
|
||||
*/
|
||||
#define NBFS 32
|
||||
|
||||
/*
|
||||
** A value for Cursor.cacheValid that means the cache is always invalid.
|
||||
*/
|
||||
#define CACHE_STALE 0
|
||||
|
||||
/*
|
||||
** Internally, the vdbe manipulates nearly all SQL values as Mem
|
||||
** structures. Each Mem struct may cache multiple representations (string,
|
||||
@@ -257,7 +250,7 @@ struct Fifo {
|
||||
*/
|
||||
typedef struct Context Context;
|
||||
struct Context {
|
||||
i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
|
||||
int lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
|
||||
int nChange; /* Statement changes (Vdbe.nChanges) */
|
||||
Fifo sFifo; /* Records that will participate in a DELETE or UPDATE */
|
||||
};
|
||||
@@ -293,7 +286,6 @@ struct Vdbe {
|
||||
int nMem; /* Number of memory locations currently allocated */
|
||||
Mem *aMem; /* The memory locations */
|
||||
int nCallback; /* Number of callbacks invoked so far */
|
||||
int cacheCtr; /* Cursor row cache generation counter */
|
||||
Fifo sFifo; /* A list of ROWIDs */
|
||||
int contextStackTop; /* Index of top element in the context stack */
|
||||
int contextStackDepth; /* The size of the "context" stack */
|
||||
@@ -314,7 +306,6 @@ struct Vdbe {
|
||||
u8 changeCntOn; /* True to update the change-counter */
|
||||
u8 aborted; /* True if ROLLBACK in another VM causes an abort */
|
||||
u8 expired; /* True if the VM needs to be recompiled */
|
||||
u8 minWriteFileFormat; /* Minimum file format for writable database files */
|
||||
int nChange; /* Number of db changes made since last reset */
|
||||
i64 startTime; /* Time when query started - used for profiling */
|
||||
};
|
||||
@@ -340,8 +331,8 @@ void sqlite3VdbePrintOp(FILE*, int, Op*);
|
||||
void sqlite3VdbePrintSql(Vdbe*);
|
||||
#endif
|
||||
int sqlite3VdbeSerialTypeLen(u32);
|
||||
u32 sqlite3VdbeSerialType(Mem*, int);
|
||||
int sqlite3VdbeSerialPut(unsigned char*, Mem*, int);
|
||||
u32 sqlite3VdbeSerialType(Mem*);
|
||||
int sqlite3VdbeSerialPut(unsigned char*, Mem*);
|
||||
int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
|
||||
void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
|
||||
|
||||
@@ -369,9 +360,7 @@ int sqlite3VdbeMemStringify(Mem*, int);
|
||||
i64 sqlite3VdbeIntValue(Mem*);
|
||||
int sqlite3VdbeMemIntegerify(Mem*);
|
||||
double sqlite3VdbeRealValue(Mem*);
|
||||
void sqlite3VdbeIntegerAffinity(Mem*);
|
||||
int sqlite3VdbeMemRealify(Mem*);
|
||||
int sqlite3VdbeMemNumerify(Mem*);
|
||||
int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
|
||||
void sqlite3VdbeMemRelease(Mem *p);
|
||||
void sqlite3VdbeMemFinalize(Mem*, FuncDef*);
|
||||
|
||||
+12
-71
@@ -58,7 +58,7 @@ sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
|
||||
return sqlite3VdbeIntValue((Mem*)pVal);
|
||||
}
|
||||
const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
|
||||
return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
return (const char *)sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_value_text16(sqlite3_value* pVal){
|
||||
@@ -156,8 +156,6 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
sqlite3 *db;
|
||||
int rc;
|
||||
|
||||
assert(!sqlite3ThreadDataReadOnly()->mallocFailed);
|
||||
|
||||
if( p==0 || p->magic!=VDBE_MAGIC_RUN ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
@@ -241,7 +239,6 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
#endif
|
||||
|
||||
sqlite3Error(p->db, rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
|
||||
sqlite3MallocClearFailed();
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -378,78 +375,30 @@ static Mem *columnMem(sqlite3_stmt *pStmt, int i){
|
||||
return &pVm->pTos[(1-vals)+i];
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is called after invoking an sqlite3_value_XXX function on a
|
||||
** column value (i.e. a value returned by evaluating an SQL expression in the
|
||||
** select list of a SELECT statement) that may cause a malloc() failure. If
|
||||
** malloc() has failed, the threads mallocFailed flag is cleared and the result
|
||||
** code of statement pStmt set to SQLITE_NOMEM.
|
||||
**
|
||||
** Specificly, this is called from within:
|
||||
**
|
||||
** sqlite3_column_int()
|
||||
** sqlite3_column_int64()
|
||||
** sqlite3_column_text()
|
||||
** sqlite3_column_text16()
|
||||
** sqlite3_column_real()
|
||||
** sqlite3_column_bytes()
|
||||
** sqlite3_column_bytes16()
|
||||
**
|
||||
** But not for sqlite3_column_blob(), which never calls malloc().
|
||||
*/
|
||||
static void columnMallocFailure(sqlite3_stmt *pStmt)
|
||||
{
|
||||
/* If malloc() failed during an encoding conversion within an
|
||||
** sqlite3_column_XXX API, then set the return code of the statement to
|
||||
** SQLITE_NOMEM. The next call to _step() (if any) will return SQLITE_ERROR
|
||||
** and _finalize() will return NOMEM.
|
||||
*/
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
((Vdbe *)pStmt)->rc = SQLITE_NOMEM;
|
||||
sqlite3MallocClearFailed();
|
||||
}
|
||||
}
|
||||
|
||||
/**************************** 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){
|
||||
const void *val;
|
||||
sqlite3MallocDisallow();
|
||||
val = sqlite3_value_blob( columnMem(pStmt,i) );
|
||||
sqlite3MallocAllow();
|
||||
return val;
|
||||
return sqlite3_value_blob( columnMem(pStmt,i) );
|
||||
}
|
||||
int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
|
||||
int val = sqlite3_value_bytes( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
return sqlite3_value_bytes( columnMem(pStmt,i) );
|
||||
}
|
||||
int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
|
||||
int val = sqlite3_value_bytes16( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
return sqlite3_value_bytes16( columnMem(pStmt,i) );
|
||||
}
|
||||
double sqlite3_column_double(sqlite3_stmt *pStmt, int i){
|
||||
double val = sqlite3_value_double( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
return sqlite3_value_double( columnMem(pStmt,i) );
|
||||
}
|
||||
int sqlite3_column_int(sqlite3_stmt *pStmt, int i){
|
||||
int val = sqlite3_value_int( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
return sqlite3_value_int( columnMem(pStmt,i) );
|
||||
}
|
||||
sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
|
||||
sqlite_int64 val = sqlite3_value_int64( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
return sqlite3_value_int64( columnMem(pStmt,i) );
|
||||
}
|
||||
const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
|
||||
const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
return sqlite3_value_text( columnMem(pStmt,i) );
|
||||
}
|
||||
#if 0
|
||||
sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
|
||||
@@ -458,9 +407,7 @@ sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
|
||||
const void *val = sqlite3_value_text16( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
return sqlite3_value_text16( columnMem(pStmt,i) );
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
|
||||
@@ -489,7 +436,6 @@ static const void *columnName(
|
||||
const void *(*xFunc)(Mem*),
|
||||
int useType
|
||||
){
|
||||
const void *ret;
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
int n = sqlite3_column_count(pStmt);
|
||||
|
||||
@@ -497,15 +443,10 @@ static const void *columnName(
|
||||
return 0;
|
||||
}
|
||||
N += useType*n;
|
||||
ret = xFunc(&p->aColName[N]);
|
||||
|
||||
/* A malloc may have failed inside of the xFunc() call. If this is the case,
|
||||
** clear the mallocFailed flag and return NULL.
|
||||
*/
|
||||
sqlite3MallocClearFailed();
|
||||
return ret;
|
||||
return xFunc(&p->aColName[N]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Return the name of the Nth column of the result set returned by SQL
|
||||
** statement pStmt.
|
||||
@@ -634,7 +575,7 @@ static int bindText(
|
||||
return rc;
|
||||
}
|
||||
if( rc==SQLITE_OK && encoding!=0 ){
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
+62
-143
@@ -102,7 +102,7 @@ int sqlite3VdbeAddOp(Vdbe *p, int op, int p1, int p2){
|
||||
p->nOp++;
|
||||
assert( p->magic==VDBE_MAGIC_INIT );
|
||||
resizeOpArray(p, i+1);
|
||||
if( p->aOp==0 || p->nOpAlloc<=i ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
return 0;
|
||||
}
|
||||
pOp = &p->aOp[i];
|
||||
@@ -147,7 +147,7 @@ int sqlite3VdbeMakeLabel(Vdbe *p){
|
||||
assert( p->magic==VDBE_MAGIC_INIT );
|
||||
if( i>=p->nLabelAlloc ){
|
||||
p->nLabelAlloc = p->nLabelAlloc*2 + 10;
|
||||
sqliteReallocOrFree((void**)&p->aLabel,
|
||||
sqlite3ReallocOrFree((void**)&p->aLabel,
|
||||
p->nLabelAlloc*sizeof(p->aLabel[0]));
|
||||
}
|
||||
if( p->aLabel ){
|
||||
@@ -202,7 +202,6 @@ static int opcodeNoPush(u8 op){
|
||||
NOPUSH_MASK_6 + (NOPUSH_MASK_7<<16),
|
||||
NOPUSH_MASK_8 + (NOPUSH_MASK_9<<16)
|
||||
};
|
||||
assert( op<32*5 );
|
||||
return (masks[op>>5] & (1<<(op&0x1F)));
|
||||
}
|
||||
|
||||
@@ -301,7 +300,7 @@ int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
|
||||
int addr;
|
||||
assert( p->magic==VDBE_MAGIC_INIT );
|
||||
resizeOpArray(p, p->nOp + nOp);
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
return 0;
|
||||
}
|
||||
addr = p->nOp;
|
||||
@@ -415,10 +414,8 @@ static void freeP3(int p3type, void *p3){
|
||||
void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
|
||||
Op *pOp;
|
||||
assert( p->magic==VDBE_MAGIC_INIT );
|
||||
if( p==0 || p->aOp==0 || sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if (n != P3_KEYINFO) {
|
||||
freeP3(n, (void*)*(char**)&zP3);
|
||||
}
|
||||
if( p==0 || p->aOp==0 ){
|
||||
freeP3(n, (void*)*(char**)&zP3);
|
||||
return;
|
||||
}
|
||||
if( addr<0 || addr>=p->nOp ){
|
||||
@@ -435,18 +432,16 @@ void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
|
||||
KeyInfo *pKeyInfo;
|
||||
int nField, nByte;
|
||||
|
||||
/* KeyInfo structures that include an KeyInfo.aSortOrder are always
|
||||
** sent in using P3_KEYINFO_HANDOFF. The KeyInfo.aSortOrder array
|
||||
** is not duplicated when P3_KEYINFO is used. */
|
||||
/* assert( pKeyInfo->aSortOrder==0 ); */
|
||||
nField = ((KeyInfo*)zP3)->nField;
|
||||
nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
|
||||
nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]);
|
||||
pKeyInfo = sqliteMallocRaw( nByte );
|
||||
pOp->p3 = (char*)pKeyInfo;
|
||||
if( pKeyInfo ){
|
||||
char *aSortOrder;
|
||||
memcpy(pKeyInfo, zP3, nByte);
|
||||
aSortOrder = pKeyInfo->aSortOrder;
|
||||
if( aSortOrder ){
|
||||
pKeyInfo->aSortOrder = (char*)&pKeyInfo->aColl[nField];
|
||||
memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
|
||||
}
|
||||
pOp->p3type = P3_KEYINFO;
|
||||
}else{
|
||||
pOp->p3type = P3_NOTUSED;
|
||||
@@ -472,8 +467,7 @@ void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
|
||||
void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
|
||||
va_list ap;
|
||||
assert( p->nOp>0 );
|
||||
assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0
|
||||
|| sqlite3ThreadDataReadOnly()->mallocFailed );
|
||||
assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 );
|
||||
va_start(ap, zFormat);
|
||||
sqlite3VdbeChangeP3(p, -1, sqlite3VMPrintf(zFormat, ap), P3_DYNAMIC);
|
||||
va_end(ap);
|
||||
@@ -739,7 +733,7 @@ void sqlite3VdbeMakeReady(
|
||||
+ nMem*sizeof(Mem) /* aMem */
|
||||
+ nCursor*sizeof(Cursor*) /* apCsr */
|
||||
);
|
||||
if( !sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( !sqlite3_malloc_failed ){
|
||||
p->aMem = &p->aStack[nStack];
|
||||
p->nMem = nMem;
|
||||
p->aVar = &p->aMem[nMem];
|
||||
@@ -783,8 +777,6 @@ void sqlite3VdbeMakeReady(
|
||||
p->explain |= isExplain;
|
||||
p->magic = VDBE_MAGIC_RUN;
|
||||
p->nChange = 0;
|
||||
p->cacheCtr = 1;
|
||||
p->minWriteFileFormat = 255;
|
||||
#ifdef VDBE_PROFILE
|
||||
{
|
||||
int i;
|
||||
@@ -865,10 +857,9 @@ static void Cleanup(Vdbe *p){
|
||||
void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){
|
||||
Mem *pColName;
|
||||
int n;
|
||||
releaseMemArray(p->aColName, p->nResColumn*2);
|
||||
sqliteFree(p->aColName);
|
||||
n = nResColumn*2;
|
||||
assert( 0==p->nResColumn );
|
||||
p->nResColumn = nResColumn;
|
||||
n = nResColumn*2;
|
||||
p->aColName = pColName = (Mem*)sqliteMalloc( sizeof(Mem)*n );
|
||||
if( p->aColName==0 ) return;
|
||||
while( n-- > 0 ){
|
||||
@@ -891,7 +882,7 @@ int sqlite3VdbeSetColName(Vdbe *p, int idx, const char *zName, int N){
|
||||
int rc;
|
||||
Mem *pColName;
|
||||
assert( idx<(2*p->nResColumn) );
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ) return SQLITE_NOMEM;
|
||||
if( sqlite3_malloc_failed ) return SQLITE_NOMEM;
|
||||
assert( p->aColName!=0 );
|
||||
pColName = &(p->aColName[idx]);
|
||||
if( N==P3_DYNAMIC || N==P3_STATIC ){
|
||||
@@ -928,6 +919,7 @@ static int vdbeCommit(sqlite3 *db){
|
||||
|
||||
/* If there are any write-transactions at all, invoke the commit hook */
|
||||
if( needXcommit && db->xCommitCallback ){
|
||||
int rc;
|
||||
sqlite3SafetyOff(db);
|
||||
rc = db->xCommitCallback(db->pCommitArg);
|
||||
sqlite3SafetyOn(db);
|
||||
@@ -973,7 +965,7 @@ static int vdbeCommit(sqlite3 *db){
|
||||
int needSync = 0;
|
||||
char *zMaster = 0; /* File-name for the master journal */
|
||||
char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
|
||||
OsFile *master = 0;
|
||||
OsFile master;
|
||||
|
||||
/* Select a master journal file name */
|
||||
do {
|
||||
@@ -987,6 +979,7 @@ static int vdbeCommit(sqlite3 *db){
|
||||
}while( sqlite3OsFileExists(zMaster) );
|
||||
|
||||
/* Open the master journal. */
|
||||
memset(&master, 0, sizeof(master));
|
||||
rc = sqlite3OsOpenExclusive(zMaster, &master, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqliteFree(zMaster);
|
||||
@@ -1008,7 +1001,7 @@ static int vdbeCommit(sqlite3 *db){
|
||||
if( !needSync && !sqlite3BtreeSyncDisabled(pBt) ){
|
||||
needSync = 1;
|
||||
}
|
||||
rc = sqlite3OsWrite(master, zFile, strlen(zFile)+1);
|
||||
rc = sqlite3OsWrite(&master, zFile, strlen(zFile)+1);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3OsClose(&master);
|
||||
sqlite3OsDelete(zMaster);
|
||||
@@ -1023,9 +1016,9 @@ static int vdbeCommit(sqlite3 *db){
|
||||
** the master journal file is store in so that it gets synced too.
|
||||
*/
|
||||
zMainFile = sqlite3BtreeGetDirname(db->aDb[0].pBt);
|
||||
rc = sqlite3OsOpenDirectory(master, zMainFile);
|
||||
rc = sqlite3OsOpenDirectory(zMainFile, &master);
|
||||
if( rc!=SQLITE_OK ||
|
||||
(needSync && (rc=sqlite3OsSync(master,0))!=SQLITE_OK) ){
|
||||
(needSync && (rc=sqlite3OsSync(&master,0))!=SQLITE_OK) ){
|
||||
sqlite3OsClose(&master);
|
||||
sqlite3OsDelete(zMaster);
|
||||
sqliteFree(zMaster);
|
||||
@@ -1154,10 +1147,6 @@ int sqlite3VdbeHalt(Vdbe *p){
|
||||
int i;
|
||||
int (*xFunc)(Btree *pBt) = 0; /* Function to call on each btree backend */
|
||||
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
if( p->magic!=VDBE_MAGIC_RUN ){
|
||||
/* Already halted. Nothing to do. */
|
||||
assert( p->magic==VDBE_MAGIC_HALT );
|
||||
@@ -1168,8 +1157,7 @@ int sqlite3VdbeHalt(Vdbe *p){
|
||||
if( p->pc<0 ){
|
||||
/* No commit or rollback needed if the program never started */
|
||||
}else if( db->autoCommit && db->activeVdbeCnt==1 ){
|
||||
|
||||
if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && p->rc!=SQLITE_NOMEM)){
|
||||
if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
|
||||
/* The auto-commit flag is true, there are no other active queries
|
||||
** using this handle and the vdbe program was successful or hit an
|
||||
** 'OR FAIL' constraint. This means a commit is required.
|
||||
@@ -1179,71 +1167,28 @@ int sqlite3VdbeHalt(Vdbe *p){
|
||||
return SQLITE_BUSY;
|
||||
}else if( rc!=SQLITE_OK ){
|
||||
p->rc = rc;
|
||||
sqlite3RollbackAll(db);
|
||||
}else{
|
||||
sqlite3CommitInternalChanges(db);
|
||||
xFunc = sqlite3BtreeRollback;
|
||||
}
|
||||
}else{
|
||||
sqlite3RollbackAll(db);
|
||||
xFunc = sqlite3BtreeRollback;
|
||||
}
|
||||
}else{
|
||||
|
||||
if( p->rc==SQLITE_NOMEM ){
|
||||
/* This loop does static analysis of the query to see which of the
|
||||
** following three categories it falls into:
|
||||
**
|
||||
** Read-only
|
||||
** Query with statement journal -> rollback statement
|
||||
** Query without statement journal -> rollback transaction
|
||||
**
|
||||
** We could do something more elegant than this static analysis (i.e.
|
||||
** store the type of query as part of the compliation phase), but
|
||||
** handling malloc() failure is a fairly obscure edge case so this is
|
||||
** probably easier.
|
||||
**
|
||||
** Todo: This means we always override the p->errorAction value for a
|
||||
** malloc() failure. Is there any other choice here though?
|
||||
*/
|
||||
int isReadOnly = 1;
|
||||
int isStatement = 0;
|
||||
assert(p->aOp || p->nOp==0);
|
||||
for(i=0; i<p->nOp; i++){
|
||||
switch( p->aOp[i].opcode ){
|
||||
case OP_Transaction:
|
||||
isReadOnly = 0;
|
||||
break;
|
||||
case OP_Statement:
|
||||
isStatement = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( (isReadOnly||isStatement) && p->errorAction!=OE_Rollback ){
|
||||
p->errorAction = OE_Abort;
|
||||
}else{
|
||||
p->errorAction = OE_Rollback;
|
||||
}
|
||||
}
|
||||
|
||||
if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
|
||||
xFunc = sqlite3BtreeCommitStmt;
|
||||
}else if( p->errorAction==OE_Abort ){
|
||||
xFunc = sqlite3BtreeRollbackStmt;
|
||||
}else{
|
||||
abortOtherActiveVdbes(p);
|
||||
sqlite3RollbackAll(db);
|
||||
xFunc = sqlite3BtreeRollback;
|
||||
db->autoCommit = 1;
|
||||
abortOtherActiveVdbes(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* If xFunc is not NULL, then it is one of
|
||||
/* If xFunc is not NULL, then it is one of sqlite3BtreeRollback,
|
||||
** sqlite3BtreeRollbackStmt or sqlite3BtreeCommitStmt. Call it once on
|
||||
** each backend. If an error occurs and the return code is still
|
||||
** SQLITE_OK, set the return code to the new error value.
|
||||
*/
|
||||
assert(!xFunc ||
|
||||
xFunc==sqlite3BtreeCommitStmt ||
|
||||
xFunc==sqlite3BtreeRollbackStmt
|
||||
);
|
||||
for(i=0; xFunc && i<db->nDb; i++){
|
||||
int rc;
|
||||
Btree *pBt = db->aDb[i].pBt;
|
||||
@@ -1264,9 +1209,10 @@ int sqlite3VdbeHalt(Vdbe *p){
|
||||
}
|
||||
|
||||
/* Rollback or commit any schema changes that occurred. */
|
||||
if( p->rc!=SQLITE_OK && db->flags&SQLITE_InternChanges ){
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
db->flags = (db->flags | SQLITE_InternChanges);
|
||||
if( p->rc!=SQLITE_OK ){
|
||||
sqlite3RollbackInternalChanges(db);
|
||||
}else if( db->flags & SQLITE_InternChanges ){
|
||||
sqlite3CommitInternalChanges(db);
|
||||
}
|
||||
|
||||
/* We have successfully halted and closed the VM. Record this fact. */
|
||||
@@ -1331,7 +1277,7 @@ int sqlite3VdbeReset(Vdbe *p){
|
||||
|
||||
/* Save profiling information from this VDBE run.
|
||||
*/
|
||||
assert( p->pTos<&p->aStack[p->pc<0?0:p->pc] || !p->aStack );
|
||||
assert( p->pTos<&p->aStack[p->pc<0?0:p->pc] || sqlite3_malloc_failed==1 );
|
||||
#ifdef VDBE_PROFILE
|
||||
{
|
||||
FILE *out = fopen("vdbe_profile.out", "a");
|
||||
@@ -1455,7 +1401,7 @@ int sqlite3VdbeCursorMoveto(Cursor *p){
|
||||
}
|
||||
sqlite3_search_count++;
|
||||
p->deferredMoveto = 0;
|
||||
p->cacheStatus = CACHE_STALE;
|
||||
p->cacheValid = 0;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -1492,20 +1438,16 @@ int sqlite3VdbeCursorMoveto(Cursor *p){
|
||||
** 5 6 signed integer
|
||||
** 6 8 signed integer
|
||||
** 7 8 IEEE float
|
||||
** 8 0 Integer constant 0
|
||||
** 9 0 Integer constant 1
|
||||
** 10,11 reserved for expansion
|
||||
** 8-11 reserved for expansion
|
||||
** N>=12 and even (N-12)/2 BLOB
|
||||
** N>=13 and odd (N-13)/2 text
|
||||
**
|
||||
** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
|
||||
** of SQLite will not understand those serial types.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Return the serial-type for the value stored in pMem.
|
||||
*/
|
||||
u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){
|
||||
u32 sqlite3VdbeSerialType(Mem *pMem){
|
||||
int flags = pMem->flags;
|
||||
|
||||
if( flags&MEM_Null ){
|
||||
@@ -1515,11 +1457,7 @@ u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){
|
||||
/* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
|
||||
# define MAX_6BYTE ((((i64)0x00001000)<<32)-1)
|
||||
i64 i = pMem->i;
|
||||
u64 u;
|
||||
if( file_format>=4 && (i&1)==i ){
|
||||
return 8+i;
|
||||
}
|
||||
u = i<0 ? -i : i;
|
||||
u64 u = i<0 ? -i : i;
|
||||
if( u<=127 ) return 1;
|
||||
if( u<=32767 ) return 2;
|
||||
if( u<=8388607 ) return 3;
|
||||
@@ -1558,12 +1496,17 @@ int sqlite3VdbeSerialTypeLen(u32 serial_type){
|
||||
** buf. It is assumed that the caller has allocated sufficient space.
|
||||
** Return the number of bytes written.
|
||||
*/
|
||||
int sqlite3VdbeSerialPut(unsigned char *buf, Mem *pMem, int file_format){
|
||||
u32 serial_type = sqlite3VdbeSerialType(pMem, file_format);
|
||||
int sqlite3VdbeSerialPut(unsigned char *buf, Mem *pMem){
|
||||
u32 serial_type = sqlite3VdbeSerialType(pMem);
|
||||
int len;
|
||||
|
||||
/* NULL */
|
||||
if( serial_type==0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Integer and Real */
|
||||
if( serial_type<=7 && serial_type>0 ){
|
||||
if( serial_type<=7 ){
|
||||
u64 v;
|
||||
int i;
|
||||
if( serial_type==7 ){
|
||||
@@ -1578,16 +1521,12 @@ int sqlite3VdbeSerialPut(unsigned char *buf, Mem *pMem, int file_format){
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
/* String or blob */
|
||||
if( serial_type>=12 ){
|
||||
len = sqlite3VdbeSerialTypeLen(serial_type);
|
||||
memcpy(buf, pMem->z, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
/* NULL or constants 0 or 1 */
|
||||
return 0;
|
||||
assert( serial_type>=12 );
|
||||
len = sqlite3VdbeSerialTypeLen(serial_type);
|
||||
memcpy(buf, pMem->z, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1600,6 +1539,8 @@ int sqlite3VdbeSerialGet(
|
||||
Mem *pMem /* Memory cell to write value into */
|
||||
){
|
||||
switch( serial_type ){
|
||||
case 8: /* Reserved for future use */
|
||||
case 9: /* Reserved for future use */
|
||||
case 10: /* Reserved for future use */
|
||||
case 11: /* Reserved for future use */
|
||||
case 0: { /* NULL */
|
||||
@@ -1658,12 +1599,6 @@ int sqlite3VdbeSerialGet(
|
||||
}
|
||||
return 8;
|
||||
}
|
||||
case 8: /* Integer 0 */
|
||||
case 9: { /* Integer 1 */
|
||||
pMem->i = serial_type-8;
|
||||
pMem->flags = MEM_Int;
|
||||
return 0;
|
||||
}
|
||||
default: {
|
||||
int len = (serial_type-12)/2;
|
||||
pMem->z = (char *)buf;
|
||||
@@ -1680,23 +1615,6 @@ int sqlite3VdbeSerialGet(
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** The header of a record consists of a sequence variable-length integers.
|
||||
** These integers are almost always small and are encoded as a single byte.
|
||||
** The following macro takes advantage this fact to provide a fast decode
|
||||
** of the integers in a record header. It is faster for the common case
|
||||
** where the integer is a single byte. It is a little slower when the
|
||||
** integer is two or more bytes. But overall it is faster.
|
||||
**
|
||||
** The following expressions are equivalent:
|
||||
**
|
||||
** x = sqlite3GetVarint32( A, &B );
|
||||
**
|
||||
** x = GetVarint( A, B );
|
||||
**
|
||||
*/
|
||||
#define GetVarint(A,B) ((B = *(A))<=0x7f ? 1 : sqlite3GetVarint32(A, &B))
|
||||
|
||||
/*
|
||||
** This function compares the two table rows or index records specified by
|
||||
** {nKey1, pKey1} and {nKey2, pKey2}, returning a negative, zero
|
||||
@@ -1724,9 +1642,9 @@ int sqlite3VdbeRecordCompare(
|
||||
mem1.enc = pKeyInfo->enc;
|
||||
mem2.enc = pKeyInfo->enc;
|
||||
|
||||
idx1 = GetVarint(aKey1, szHdr1);
|
||||
idx1 = sqlite3GetVarint32(pKey1, &szHdr1);
|
||||
d1 = szHdr1;
|
||||
idx2 = GetVarint(aKey2, szHdr2);
|
||||
idx2 = sqlite3GetVarint32(pKey2, &szHdr2);
|
||||
d2 = szHdr2;
|
||||
nField = pKeyInfo->nField;
|
||||
while( idx1<szHdr1 && idx2<szHdr2 ){
|
||||
@@ -1734,9 +1652,9 @@ int sqlite3VdbeRecordCompare(
|
||||
u32 serial_type2;
|
||||
|
||||
/* Read the serial types for the next element in each key. */
|
||||
idx1 += GetVarint( aKey1+idx1, serial_type1 );
|
||||
idx1 += sqlite3GetVarint32(&aKey1[idx1], &serial_type1);
|
||||
if( d1>=nKey1 && sqlite3VdbeSerialTypeLen(serial_type1)>0 ) break;
|
||||
idx2 += GetVarint( aKey2+idx2, serial_type2 );
|
||||
idx2 += sqlite3GetVarint32(&aKey2[idx2], &serial_type2);
|
||||
if( d2>=nKey2 && sqlite3VdbeSerialTypeLen(serial_type2)>0 ) break;
|
||||
|
||||
/* Assert that there is enough space left in each key for the blob of
|
||||
@@ -1768,8 +1686,9 @@ int sqlite3VdbeRecordCompare(
|
||||
}else if( d2<nKey2 ){
|
||||
rc = -1;
|
||||
}
|
||||
}else if( pKeyInfo->aSortOrder && i<pKeyInfo->nField
|
||||
&& pKeyInfo->aSortOrder[i] ){
|
||||
}
|
||||
|
||||
if( pKeyInfo->aSortOrder && i<pKeyInfo->nField && pKeyInfo->aSortOrder[i] ){
|
||||
rc = -rc;
|
||||
}
|
||||
|
||||
@@ -1813,10 +1732,10 @@ int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
sqlite3GetVarint32((u8*)m.z, &szHdr);
|
||||
sqlite3GetVarint32((u8*)&m.z[szHdr-1], &typeRowid);
|
||||
sqlite3GetVarint32(m.z, &szHdr);
|
||||
sqlite3GetVarint32(&m.z[szHdr-1], &typeRowid);
|
||||
lenRowid = sqlite3VdbeSerialTypeLen(typeRowid);
|
||||
sqlite3VdbeSerialGet((u8*)&m.z[m.n-lenRowid], typeRowid, &v);
|
||||
sqlite3VdbeSerialGet(&m.z[m.n-lenRowid], typeRowid, &v);
|
||||
*rowid = v.i;
|
||||
sqlite3VdbeMemRelease(&m);
|
||||
return SQLITE_OK;
|
||||
@@ -1852,7 +1771,7 @@ int sqlite3VdbeIdxKeyCompare(
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
lenRowid = sqlite3VdbeIdxRowidLen(m.n, (u8*)m.z);
|
||||
lenRowid = sqlite3VdbeIdxRowidLen(m.n, m.z);
|
||||
*res = sqlite3VdbeRecordCompare(pC->pKeyInfo, m.n-lenRowid, m.z, nKey, pKey);
|
||||
sqlite3VdbeMemRelease(&m);
|
||||
return SQLITE_OK;
|
||||
|
||||
+28
-63
@@ -41,21 +41,11 @@ int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
|
||||
#ifdef SQLITE_OMIT_UTF16
|
||||
return SQLITE_ERROR;
|
||||
#else
|
||||
|
||||
/* MemTranslate() may return SQLITE_OK or SQLITE_NOMEM. If NOMEM is returned,
|
||||
** then the encoding of the value may not have changed.
|
||||
*/
|
||||
rc = sqlite3VdbeMemTranslate(pMem, desiredEnc);
|
||||
assert(rc==SQLITE_OK || rc==SQLITE_NOMEM);
|
||||
assert(rc==SQLITE_OK || pMem->enc!=desiredEnc);
|
||||
assert(rc==SQLITE_NOMEM || pMem->enc==desiredEnc);
|
||||
|
||||
if( rc==SQLITE_NOMEM ){
|
||||
/*
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Null;
|
||||
pMem->z = 0;
|
||||
*/
|
||||
}
|
||||
return rc;
|
||||
#endif
|
||||
@@ -83,7 +73,7 @@ int sqlite3VdbeMemDynamicify(Mem *pMem){
|
||||
memcpy(z, pMem->z, n );
|
||||
z[n] = 0;
|
||||
z[n+1] = 0;
|
||||
pMem->z = (char*)z;
|
||||
pMem->z = z;
|
||||
pMem->flags &= ~(MEM_Ephem|MEM_Static|MEM_Short);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -103,7 +93,7 @@ int sqlite3VdbeMemMakeWriteable(Mem *pMem){
|
||||
assert( (pMem->flags & MEM_Dyn)==0 );
|
||||
assert( pMem->flags & (MEM_Str|MEM_Blob) );
|
||||
if( (n = pMem->n)+2<sizeof(pMem->zShort) ){
|
||||
z = (u8*)pMem->zShort;
|
||||
z = pMem->zShort;
|
||||
pMem->flags |= MEM_Short|MEM_Term;
|
||||
}else{
|
||||
z = sqliteMallocRaw( n+2 );
|
||||
@@ -116,7 +106,7 @@ int sqlite3VdbeMemMakeWriteable(Mem *pMem){
|
||||
memcpy(z, pMem->z, n );
|
||||
z[n] = 0;
|
||||
z[n+1] = 0;
|
||||
pMem->z = (char*)z;
|
||||
pMem->z = z;
|
||||
pMem->flags &= ~(MEM_Ephem|MEM_Static);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -172,7 +162,7 @@ int sqlite3VdbeMemNulTerminate(Mem *pMem){
|
||||
int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
int rc = SQLITE_OK;
|
||||
int fg = pMem->flags;
|
||||
char *z = pMem->zShort;
|
||||
u8 *z = pMem->zShort;
|
||||
|
||||
assert( !(fg&(MEM_Str|MEM_Blob)) );
|
||||
assert( fg&(MEM_Int|MEM_Real) );
|
||||
@@ -183,11 +173,11 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
**
|
||||
** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
|
||||
*/
|
||||
if( fg & MEM_Int ){
|
||||
sqlite3_snprintf(NBFS, z, "%lld", pMem->i);
|
||||
}else{
|
||||
assert( fg & MEM_Real );
|
||||
if( fg & MEM_Real ){
|
||||
sqlite3_snprintf(NBFS, z, "%!.15g", pMem->r);
|
||||
}else{
|
||||
assert( fg & MEM_Int );
|
||||
sqlite3_snprintf(NBFS, z, "%lld", pMem->i);
|
||||
}
|
||||
pMem->n = strlen(z);
|
||||
pMem->z = z;
|
||||
@@ -264,7 +254,7 @@ i64 sqlite3VdbeIntValue(Mem *pMem){
|
||||
i64 value;
|
||||
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|
||||
|| sqlite3VdbeMemNulTerminate(pMem) ){
|
||||
return 0;
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( pMem->z );
|
||||
sqlite3atoi64(pMem->z, &value);
|
||||
@@ -274,6 +264,16 @@ i64 sqlite3VdbeIntValue(Mem *pMem){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem to type integer. Invalidate any prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
pMem->i = sqlite3VdbeIntValue(pMem);
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Int;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the best representation of pMem that we can get into a
|
||||
** double. If pMem is already a double or an integer, return its
|
||||
@@ -289,7 +289,7 @@ double sqlite3VdbeRealValue(Mem *pMem){
|
||||
double val = 0.0;
|
||||
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|
||||
|| sqlite3VdbeMemNulTerminate(pMem) ){
|
||||
return 0.0;
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( pMem->z );
|
||||
sqlite3AtoF(pMem->z, &val);
|
||||
@@ -300,30 +300,8 @@ double sqlite3VdbeRealValue(Mem *pMem){
|
||||
}
|
||||
|
||||
/*
|
||||
** The MEM structure is already a MEM_Real. Try to also make it a
|
||||
** MEM_Int if we can.
|
||||
*/
|
||||
void sqlite3VdbeIntegerAffinity(Mem *pMem){
|
||||
assert( pMem->flags & MEM_Real );
|
||||
pMem->i = pMem->r;
|
||||
if( ((double)pMem->i)==pMem->r ){
|
||||
pMem->flags |= MEM_Int;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem to type integer. Invalidate any prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
pMem->i = sqlite3VdbeIntValue(pMem);
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Int;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem so that it is of type MEM_Real.
|
||||
** Invalidate any prior representations.
|
||||
** Convert pMem so that it is of type MEM_Real. Invalidate any
|
||||
** prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemRealify(Mem *pMem){
|
||||
pMem->r = sqlite3VdbeRealValue(pMem);
|
||||
@@ -332,16 +310,6 @@ int sqlite3VdbeMemRealify(Mem *pMem){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem so that it has types MEM_Real or MEM_Int or both.
|
||||
** Invalidate any prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemNumerify(Mem *pMem){
|
||||
sqlite3VdbeMemRealify(pMem);
|
||||
sqlite3VdbeIntegerAffinity(pMem);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete any previous value and set the value stored in *pMem to NULL.
|
||||
*/
|
||||
@@ -579,9 +547,9 @@ int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
|
||||
assert( pMem1->enc==SQLITE_UTF8 ||
|
||||
pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
|
||||
|
||||
/* The collation sequence must be defined at this point, even if
|
||||
** the user deletes the collation sequence after the vdbe program is
|
||||
** compiled (this was not always the case).
|
||||
/* 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 );
|
||||
|
||||
@@ -751,15 +719,12 @@ const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
|
||||
if( pVal->flags&MEM_Null ){
|
||||
return 0;
|
||||
}
|
||||
assert( (MEM_Blob>>3) == MEM_Str );
|
||||
pVal->flags |= (pVal->flags & MEM_Blob)>>3;
|
||||
if( pVal->flags&MEM_Str ){
|
||||
sqlite3VdbeChangeEncoding(pVal, enc);
|
||||
}else if( !(pVal->flags&MEM_Blob) ){
|
||||
sqlite3VdbeMemStringify(pVal, enc);
|
||||
}
|
||||
assert(pVal->enc==enc || sqlite3ThreadDataReadOnly()->mallocFailed);
|
||||
return (const void *)(pVal->enc==enc ? (pVal->z) : 0);
|
||||
return (const void *)(pVal->z);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -801,7 +766,7 @@ int sqlite3ValueFromExpr(
|
||||
op = pExpr->op;
|
||||
|
||||
if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
|
||||
zVal = sqliteStrNDup((char*)pExpr->token.z, pExpr->token.n);
|
||||
zVal = sqliteStrNDup(pExpr->token.z, pExpr->token.n);
|
||||
pVal = sqlite3ValueNew();
|
||||
if( !zVal || !pVal ) goto no_mem;
|
||||
sqlite3Dequote(zVal);
|
||||
@@ -821,7 +786,7 @@ int sqlite3ValueFromExpr(
|
||||
else if( op==TK_BLOB ){
|
||||
int nVal;
|
||||
pVal = sqlite3ValueNew();
|
||||
zVal = sqliteStrNDup((char*)pExpr->token.z+1, pExpr->token.n-1);
|
||||
zVal = sqliteStrNDup(pExpr->token.z+1, pExpr->token.n-1);
|
||||
if( !zVal || !pVal ) goto no_mem;
|
||||
sqlite3Dequote(zVal);
|
||||
nVal = strlen(zVal)/2;
|
||||
|
||||
+57
-134
@@ -16,7 +16,7 @@
|
||||
** so is applicable. Because this module is responsible for selecting
|
||||
** indices, you might also think of this module as the "query optimizer".
|
||||
**
|
||||
** $Id: where.c,v 1.198 2006/01/14 08:02:28 danielk1977 Exp $
|
||||
** $Id: where.c,v 1.179 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -40,16 +40,6 @@ int sqlite3_where_trace = 0;
|
||||
# define TRACE(X)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** A large value which is the maximum cost of using an index.
|
||||
** By default this is a large floating point value. When compiling
|
||||
** SQLite for a processor that lacks floating point support, simply
|
||||
** redefine this constant to a large integer.
|
||||
*/
|
||||
#ifndef SQLITE_BIG_DBL
|
||||
# define SQLITE_BIG_DBL (1.0e+99)
|
||||
#endif
|
||||
|
||||
/* Forward reference
|
||||
*/
|
||||
typedef struct WhereClause WhereClause;
|
||||
@@ -450,7 +440,7 @@ static WhereTerm *findTerm(
|
||||
}
|
||||
for(k=0; k<pIdx->nColumn && pIdx->aiColumn[k]!=iColumn; k++){}
|
||||
assert( k<pIdx->nColumn );
|
||||
if( sqlite3StrICmp(pColl->zName, pIdx->azColl[k]) ) continue;
|
||||
if( pColl!=pIdx->keyInfo.aColl[k] ) continue;
|
||||
}
|
||||
return pTerm;
|
||||
}
|
||||
@@ -521,7 +511,7 @@ static int isLikeOrGlob(
|
||||
return 0;
|
||||
}
|
||||
sqlite3DequoteExpr(pRight);
|
||||
z = (char *)pRight->token.z;
|
||||
z = pRight->token.z;
|
||||
for(cnt=0; (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2]; cnt++){}
|
||||
if( cnt==0 || 255==(u8)z[cnt] ){
|
||||
return 0;
|
||||
@@ -532,16 +522,6 @@ static int isLikeOrGlob(
|
||||
}
|
||||
#endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
|
||||
|
||||
/*
|
||||
** If the pBase expression originated in the ON or USING clause of
|
||||
** a join, then transfer the appropriate markings over to derived.
|
||||
*/
|
||||
static void transferJoinMarkings(Expr *pDerived, Expr *pBase){
|
||||
pDerived->flags |= pBase->flags & EP_FromJoin;
|
||||
pDerived->iRightJoinTable = pBase->iRightJoinTable;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** The input to this routine is an WhereTerm structure with only the
|
||||
** "pExpr" field filled in. The job of this routine is to analyze the
|
||||
@@ -567,7 +547,7 @@ static void exprAnalyze(
|
||||
int nPattern;
|
||||
int isComplete;
|
||||
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ) return;
|
||||
if( sqlite3_malloc_failed ) return;
|
||||
prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft);
|
||||
if( pExpr->op==TK_IN ){
|
||||
assert( pExpr->pRight==0 );
|
||||
@@ -643,7 +623,7 @@ static void exprAnalyze(
|
||||
}
|
||||
#endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
|
||||
|
||||
#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
|
||||
#ifndef SQLITE_OMIT_OR_OPTIMIZATION
|
||||
/* Attempt to convert OR-connected terms into an IN operator so that
|
||||
** they can make use of indices. Example:
|
||||
**
|
||||
@@ -652,9 +632,6 @@ static void exprAnalyze(
|
||||
** is converted into
|
||||
**
|
||||
** x IN (expr1,expr2,expr3)
|
||||
**
|
||||
** This optimization must be omitted if OMIT_SUBQUERY is defined because
|
||||
** the compiler for the the IN operator is part of sub-queries.
|
||||
*/
|
||||
else if( pExpr->op==TK_OR ){
|
||||
int ok;
|
||||
@@ -703,17 +680,14 @@ static void exprAnalyze(
|
||||
}
|
||||
pNew = sqlite3Expr(TK_IN, pDup, 0, 0);
|
||||
if( pNew ){
|
||||
int idxNew;
|
||||
transferJoinMarkings(pNew, pExpr);
|
||||
pNew->pList = pList;
|
||||
idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
|
||||
exprAnalyze(pSrc, pMaskSet, pWC, idxNew);
|
||||
pTerm = &pWC->a[idxTerm];
|
||||
pWC->a[idxNew].iParent = idxTerm;
|
||||
pTerm->nChild = 1;
|
||||
}else{
|
||||
sqlite3ExprListDelete(pList);
|
||||
}
|
||||
pTerm->pExpr = pNew;
|
||||
pTerm->flags |= TERM_DYNAMIC;
|
||||
exprAnalyze(pSrc, pMaskSet, pWC, idxTerm);
|
||||
pTerm = &pWC->a[idxTerm];
|
||||
}
|
||||
or_not_possible:
|
||||
whereClauseClear(&sOr);
|
||||
@@ -788,7 +762,7 @@ static int isSortingIndex(
|
||||
int *pbRev /* Set to 1 if ORDER BY is DESC */
|
||||
){
|
||||
int i, j; /* Loop counters */
|
||||
int sortOrder = 0; /* XOR of index and ORDER BY sort direction */
|
||||
int sortOrder = SQLITE_SO_ASC; /* Which direction we are sorting */
|
||||
int nTerm; /* Number of ORDER BY terms */
|
||||
struct ExprList_item *pTerm; /* A term of the ORDER BY clause */
|
||||
sqlite3 *db = pParse->db;
|
||||
@@ -803,7 +777,6 @@ static int isSortingIndex(
|
||||
for(i=j=0, pTerm=pOrderBy->a; j<nTerm && i<pIdx->nColumn; i++){
|
||||
Expr *pExpr; /* The expression of the ORDER BY pTerm */
|
||||
CollSeq *pColl; /* The collating sequence of pExpr */
|
||||
int termSortOrder; /* Sort order for this term */
|
||||
|
||||
pExpr = pTerm->pExpr;
|
||||
if( pExpr->op!=TK_COLUMN || pExpr->iTable!=base ){
|
||||
@@ -813,8 +786,7 @@ static int isSortingIndex(
|
||||
}
|
||||
pColl = sqlite3ExprCollSeq(pParse, pExpr);
|
||||
if( !pColl ) pColl = db->pDfltColl;
|
||||
if( pExpr->iColumn!=pIdx->aiColumn[i] ||
|
||||
sqlite3StrICmp(pColl->zName, pIdx->azColl[i]) ){
|
||||
if( pExpr->iColumn!=pIdx->aiColumn[i] || pColl!=pIdx->keyInfo.aColl[i] ){
|
||||
/* Term j of the ORDER BY clause does not match column i of the index */
|
||||
if( i<nEqCol ){
|
||||
/* If an index column that is constrained by == fails to match an
|
||||
@@ -828,18 +800,14 @@ static int isSortingIndex(
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
assert( pIdx->aSortOrder!=0 );
|
||||
assert( pTerm->sortOrder==0 || pTerm->sortOrder==1 );
|
||||
assert( pIdx->aSortOrder[i]==0 || pIdx->aSortOrder[i]==1 );
|
||||
termSortOrder = pIdx->aSortOrder[i] ^ pTerm->sortOrder;
|
||||
if( i>nEqCol ){
|
||||
if( termSortOrder!=sortOrder ){
|
||||
if( pTerm->sortOrder!=sortOrder ){
|
||||
/* Indices can only be used if all ORDER BY terms past the
|
||||
** equality constraints are all either DESC or ASC. */
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
sortOrder = termSortOrder;
|
||||
sortOrder = pTerm->sortOrder;
|
||||
}
|
||||
j++;
|
||||
pTerm++;
|
||||
@@ -849,7 +817,7 @@ static int isSortingIndex(
|
||||
** are covered.
|
||||
*/
|
||||
if( j>=nTerm ){
|
||||
*pbRev = sortOrder!=0;
|
||||
*pbRev = sortOrder==SQLITE_SO_DESC;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -886,10 +854,10 @@ static int sortableByRowid(
|
||||
** logN is a little off.
|
||||
*/
|
||||
static double estLog(double N){
|
||||
double logN = 1;
|
||||
double x = 10;
|
||||
double logN = 1.0;
|
||||
double x = 10.0;
|
||||
while( N>x ){
|
||||
logN += 1;
|
||||
logN += 1.0;
|
||||
x *= 10;
|
||||
}
|
||||
return logN;
|
||||
@@ -925,7 +893,7 @@ static double bestIndex(
|
||||
){
|
||||
WhereTerm *pTerm;
|
||||
Index *bestIdx = 0; /* Index that gives the lowest cost */
|
||||
double lowestCost; /* The cost of using bestIdx */
|
||||
double lowestCost = 1.0e99; /* The cost of using bestIdx */
|
||||
int bestFlags = 0; /* Flags associated with bestIdx */
|
||||
int bestNEq = 0; /* Best value for nEq */
|
||||
int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
|
||||
@@ -936,7 +904,6 @@ static double bestIndex(
|
||||
double cost; /* Cost of using pProbe */
|
||||
|
||||
TRACE(("bestIndex: tbl=%s notReady=%x\n", pSrc->pTab->zName, notReady));
|
||||
lowestCost = SQLITE_BIG_DBL;
|
||||
|
||||
/* Check for a rowid=EXPR or rowid IN (...) constraints
|
||||
*/
|
||||
@@ -961,7 +928,7 @@ static double bestIndex(
|
||||
/* Rowid IN (SELECT): cost is NlogN where N is the number of rows
|
||||
** in the result of the inner select. We have no way to estimate
|
||||
** that value so make a wild guess. */
|
||||
lowestCost = 200;
|
||||
lowestCost = 200.0;
|
||||
}
|
||||
TRACE(("... rowid IN cost: %.9g\n", lowestCost));
|
||||
}
|
||||
@@ -970,7 +937,7 @@ static double bestIndex(
|
||||
** entries are in the table, use 1 million as a guess.
|
||||
*/
|
||||
pProbe = pSrc->pTab->pIndex;
|
||||
cost = pProbe ? pProbe->aiRowEst[0] : 1000000;
|
||||
cost = pProbe ? pProbe->aiRowEst[0] : 1000000.0;
|
||||
TRACE(("... table scan base cost: %.9g\n", cost));
|
||||
flags = WHERE_ROWID_RANGE;
|
||||
|
||||
@@ -980,11 +947,11 @@ static double bestIndex(
|
||||
if( pTerm ){
|
||||
if( findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0) ){
|
||||
flags |= WHERE_TOP_LIMIT;
|
||||
cost /= 3; /* Guess that rowid<EXPR eliminates two-thirds or rows */
|
||||
cost *= 0.333; /* Guess that rowid<EXPR eliminates two-thirds or rows */
|
||||
}
|
||||
if( findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0) ){
|
||||
flags |= WHERE_BTM_LIMIT;
|
||||
cost /= 3; /* Guess that rowid>EXPR eliminates two-thirds of rows */
|
||||
cost *= 0.333; /* Guess that rowid>EXPR eliminates two-thirds of rows */
|
||||
}
|
||||
TRACE(("... rowid range reduces cost to %.9g\n", cost));
|
||||
}else{
|
||||
@@ -1013,7 +980,7 @@ static double bestIndex(
|
||||
*/
|
||||
for(; pProbe; pProbe=pProbe->pNext){
|
||||
int i; /* Loop counter */
|
||||
double inMultiplier = 1;
|
||||
double inMultiplier = 1.0;
|
||||
|
||||
TRACE(("... index %s:\n", pProbe->zName));
|
||||
|
||||
@@ -1030,9 +997,9 @@ static double bestIndex(
|
||||
Expr *pExpr = pTerm->pExpr;
|
||||
flags |= WHERE_COLUMN_IN;
|
||||
if( pExpr->pSelect!=0 ){
|
||||
inMultiplier *= 100;
|
||||
inMultiplier *= 100.0;
|
||||
}else if( pExpr->pList!=0 ){
|
||||
inMultiplier *= pExpr->pList->nExpr + 1;
|
||||
inMultiplier *= pExpr->pList->nExpr + 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1053,11 +1020,11 @@ static double bestIndex(
|
||||
flags |= WHERE_COLUMN_RANGE;
|
||||
if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pProbe) ){
|
||||
flags |= WHERE_TOP_LIMIT;
|
||||
cost /= 3;
|
||||
cost *= 0.333;
|
||||
}
|
||||
if( findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pProbe) ){
|
||||
flags |= WHERE_BTM_LIMIT;
|
||||
cost /= 3;
|
||||
cost *= 0.333;
|
||||
}
|
||||
TRACE(("...... range reduces cost to %.9g\n", cost));
|
||||
}
|
||||
@@ -1096,7 +1063,7 @@ static double bestIndex(
|
||||
}
|
||||
if( m==0 ){
|
||||
flags |= WHERE_IDX_ONLY;
|
||||
cost /= 2;
|
||||
cost *= 0.5;
|
||||
TRACE(("...... idx-only reduces cost to %.9g\n", cost));
|
||||
}
|
||||
}
|
||||
@@ -1167,24 +1134,14 @@ static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
|
||||
** * Check the top nColumn entries on the stack. If any
|
||||
** of those entries are NULL, jump immediately to brk,
|
||||
** which is the loop exit, since no index entry will match
|
||||
** if any part of the key is NULL. Pop (nColumn+nExtra)
|
||||
** elements from the stack.
|
||||
** if any part of the key is NULL.
|
||||
**
|
||||
** * Construct a probe entry from the top nColumn entries in
|
||||
** the stack with affinities appropriate for index pIdx.
|
||||
** Only nColumn elements are popped from the stack in this case
|
||||
** (by OP_MakeRecord).
|
||||
**
|
||||
** the stack with affinities appropriate for index pIdx.
|
||||
*/
|
||||
static void buildIndexProbe(
|
||||
Vdbe *v,
|
||||
int nColumn,
|
||||
int nExtra,
|
||||
int brk,
|
||||
Index *pIdx
|
||||
){
|
||||
static void buildIndexProbe(Vdbe *v, int nColumn, int brk, Index *pIdx){
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -nColumn, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nColumn+nExtra, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, brk);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
@@ -1223,7 +1180,7 @@ static void codeEqualityTerm(
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iTab, brk);
|
||||
VdbeComment((v, "# %.*s", pX->span.n, pX->span.z));
|
||||
pLevel->nIn++;
|
||||
sqliteReallocOrFree((void**)&pLevel->aInLoop,
|
||||
sqlite3ReallocOrFree((void**)&pLevel->aInLoop,
|
||||
sizeof(pLevel->aInLoop[0])*3*pLevel->nIn);
|
||||
aIn = pLevel->aInLoop;
|
||||
if( aIn ){
|
||||
@@ -1451,7 +1408,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
** return value.
|
||||
*/
|
||||
pWInfo = sqliteMalloc( sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel));
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
goto whereBeginNoMem;
|
||||
}
|
||||
pWInfo->pParse = pParse;
|
||||
@@ -1475,7 +1432,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
createMask(&maskSet, pTabList->a[i].iCursor);
|
||||
}
|
||||
exprAnalyzeAll(pTabList, &maskSet, &wc);
|
||||
if( sqlite3ThreadDataReadOnly()->mallocFailed ){
|
||||
if( sqlite3_malloc_failed ){
|
||||
goto whereBeginNoMem;
|
||||
}
|
||||
|
||||
@@ -1507,11 +1464,10 @@ WhereInfo *sqlite3WhereBegin(
|
||||
Index *pBest = 0; /* The best index seen so far */
|
||||
int bestFlags = 0; /* Flags associated with pBest */
|
||||
int bestNEq = 0; /* nEq associated with pBest */
|
||||
double lowestCost; /* Cost of the pBest */
|
||||
double lowestCost = 1.0e99; /* Cost of the pBest */
|
||||
int bestJ; /* The value of j */
|
||||
Bitmask m; /* Bitmask value for j or bestJ */
|
||||
|
||||
lowestCost = SQLITE_BIG_DBL;
|
||||
for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){
|
||||
m = getMask(&maskSet, pTabItem->iCursor);
|
||||
if( (m & notReady)==0 ){
|
||||
@@ -1568,9 +1524,8 @@ WhereInfo *sqlite3WhereBegin(
|
||||
sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
|
||||
pLevel = pWInfo->a;
|
||||
for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
|
||||
Table *pTab; /* Table to open */
|
||||
Index *pIx; /* Index used to access pTab (if any) */
|
||||
int iDb; /* Index of database containing table/index */
|
||||
Table *pTab;
|
||||
Index *pIx;
|
||||
int iIdxCur = pLevel->iIdxCur;
|
||||
|
||||
#ifndef SQLITE_OMIT_EXPLAIN
|
||||
@@ -1583,41 +1538,27 @@ WhereInfo *sqlite3WhereBegin(
|
||||
}
|
||||
if( (pIx = pLevel->pIdx)!=0 ){
|
||||
zMsg = sqlite3MPrintf("%z WITH INDEX %s", zMsg, pIx->zName);
|
||||
}else if( pLevel->flags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
|
||||
zMsg = sqlite3MPrintf("%z USING PRIMARY KEY", zMsg);
|
||||
}
|
||||
sqlite3VdbeOp3(v, OP_Explain, i, pLevel->iFrom, zMsg, P3_DYNAMIC);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_EXPLAIN */
|
||||
pTabItem = &pTabList->a[pLevel->iFrom];
|
||||
pTab = pTabItem->pTab;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
if( pTab->isTransient || pTab->pSelect ) continue;
|
||||
if( (pLevel->flags & WHERE_IDX_ONLY)==0 ){
|
||||
sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, OP_OpenRead);
|
||||
if( pTab->nCol<(sizeof(Bitmask)*8) ){
|
||||
Bitmask b = pTabItem->colUsed;
|
||||
int n = 0;
|
||||
for(; b; b=b>>1, n++);
|
||||
sqlite3VdbeChangeP2(v, sqlite3VdbeCurrentAddr(v)-1, n);
|
||||
assert( n<=pTab->nCol );
|
||||
}
|
||||
}else{
|
||||
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
|
||||
sqlite3OpenTableForReading(v, pTabItem->iCursor, pTab);
|
||||
}
|
||||
pLevel->iTabCur = pTabItem->iCursor;
|
||||
if( (pIx = pLevel->pIdx)!=0 ){
|
||||
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
|
||||
assert( pIx->pSchema==pTab->pSchema );
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIx->iDb, 0);
|
||||
VdbeComment((v, "# %s", pIx->zName));
|
||||
sqlite3VdbeOp3(v, OP_OpenRead, iIdxCur, pIx->tnum,
|
||||
(char*)pKey, P3_KEYINFO_HANDOFF);
|
||||
(char*)&pIx->keyInfo, P3_KEYINFO);
|
||||
}
|
||||
if( (pLevel->flags & WHERE_IDX_ONLY)!=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iIdxCur, pIx->nColumn+1);
|
||||
}
|
||||
sqlite3CodeVerifySchema(pParse, iDb);
|
||||
sqlite3CodeVerifySchema(pParse, pTab->iDb);
|
||||
}
|
||||
pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
|
||||
|
||||
@@ -1726,7 +1667,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
if( testOp!=OP_Noop ){
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
|
||||
sqlite3VdbeAddOp(v, testOp, SQLITE_AFF_NUMERIC, brk);
|
||||
sqlite3VdbeAddOp(v, testOp, 'n', brk);
|
||||
}
|
||||
}else if( pLevel->flags & WHERE_COLUMN_RANGE ){
|
||||
/* Case 3: The WHERE clause term that refers to the right-most
|
||||
@@ -1742,11 +1683,8 @@ WhereInfo *sqlite3WhereBegin(
|
||||
*/
|
||||
int start;
|
||||
int nEq = pLevel->nEq;
|
||||
int topEq=0; /* True if top limit uses ==. False is strictly < */
|
||||
int btmEq=0; /* True if btm limit uses ==. False if strictly > */
|
||||
int topOp, btmOp; /* Operators for the top and bottom search bounds */
|
||||
int leFlag=0, geFlag=0;
|
||||
int testOp;
|
||||
int nNotNull; /* Number of rows of index that must be non-NULL */
|
||||
int topLimit = (pLevel->flags & WHERE_TOP_LIMIT)!=0;
|
||||
int btmLimit = (pLevel->flags & WHERE_BTM_LIMIT)!=0;
|
||||
|
||||
@@ -1763,21 +1701,6 @@ WhereInfo *sqlite3WhereBegin(
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nEq-1, 0);
|
||||
}
|
||||
|
||||
/* Figure out what comparison operators to use for top and bottom
|
||||
** search bounds. For an ascending index, the bottom bound is a > or >=
|
||||
** operator and the top bound is a < or <= operator. For a descending
|
||||
** index the operators are reversed.
|
||||
*/
|
||||
nNotNull = nEq + topLimit;
|
||||
if( pIdx->aSortOrder[nEq]==SQLITE_SO_ASC ){
|
||||
topOp = WO_LT|WO_LE;
|
||||
btmOp = WO_GT|WO_GE;
|
||||
}else{
|
||||
topOp = WO_GT|WO_GE;
|
||||
btmOp = WO_LT|WO_LE;
|
||||
SWAP(int, topLimit, btmLimit);
|
||||
}
|
||||
|
||||
/* Generate the termination key. This is the key value that
|
||||
** will end the search. There is no termination key if there
|
||||
** are no equality terms and no "X<..." term.
|
||||
@@ -1788,24 +1711,24 @@ WhereInfo *sqlite3WhereBegin(
|
||||
if( topLimit ){
|
||||
Expr *pX;
|
||||
int k = pIdx->aiColumn[j];
|
||||
pTerm = findTerm(&wc, iCur, k, notReady, topOp, pIdx);
|
||||
pTerm = findTerm(&wc, iCur, k, notReady, WO_LT|WO_LE, pIdx);
|
||||
assert( pTerm!=0 );
|
||||
pX = pTerm->pExpr;
|
||||
assert( (pTerm->flags & TERM_CODED)==0 );
|
||||
sqlite3ExprCode(pParse, pX->pRight);
|
||||
topEq = pTerm->operator & (WO_LE|WO_GE);
|
||||
leFlag = pX->op==TK_LE;
|
||||
disableTerm(pLevel, pTerm);
|
||||
testOp = OP_IdxGE;
|
||||
}else{
|
||||
testOp = nEq>0 ? OP_IdxGE : OP_Noop;
|
||||
topEq = 1;
|
||||
leFlag = 1;
|
||||
}
|
||||
if( testOp!=OP_Noop ){
|
||||
int nCol = nEq + topLimit;
|
||||
pLevel->iMem = pParse->nMem++;
|
||||
buildIndexProbe(v, nCol, nEq, brk, pIdx);
|
||||
buildIndexProbe(v, nCol, brk, pIdx);
|
||||
if( bRev ){
|
||||
int op = topEq ? OP_MoveLe : OP_MoveLt;
|
||||
int op = leFlag ? OP_MoveLe : OP_MoveLt;
|
||||
sqlite3VdbeAddOp(v, op, iIdxCur, brk);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
|
||||
@@ -1826,25 +1749,25 @@ WhereInfo *sqlite3WhereBegin(
|
||||
if( btmLimit ){
|
||||
Expr *pX;
|
||||
int k = pIdx->aiColumn[j];
|
||||
pTerm = findTerm(&wc, iCur, k, notReady, btmOp, pIdx);
|
||||
pTerm = findTerm(&wc, iCur, k, notReady, WO_GT|WO_GE, pIdx);
|
||||
assert( pTerm!=0 );
|
||||
pX = pTerm->pExpr;
|
||||
assert( (pTerm->flags & TERM_CODED)==0 );
|
||||
sqlite3ExprCode(pParse, pX->pRight);
|
||||
btmEq = pTerm->operator & (WO_LE|WO_GE);
|
||||
geFlag = pX->op==TK_GE;
|
||||
disableTerm(pLevel, pTerm);
|
||||
}else{
|
||||
btmEq = 1;
|
||||
geFlag = 1;
|
||||
}
|
||||
if( nEq>0 || btmLimit ){
|
||||
int nCol = nEq + btmLimit;
|
||||
buildIndexProbe(v, nCol, 0, brk, pIdx);
|
||||
buildIndexProbe(v, nCol, brk, pIdx);
|
||||
if( bRev ){
|
||||
pLevel->iMem = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
|
||||
testOp = OP_IdxLT;
|
||||
}else{
|
||||
int op = btmEq ? OP_MoveGe : OP_MoveGt;
|
||||
int op = geFlag ? OP_MoveGe : OP_MoveGt;
|
||||
sqlite3VdbeAddOp(v, op, iIdxCur, brk);
|
||||
}
|
||||
}else if( bRev ){
|
||||
@@ -1861,12 +1784,12 @@ WhereInfo *sqlite3WhereBegin(
|
||||
if( testOp!=OP_Noop ){
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
|
||||
sqlite3VdbeAddOp(v, testOp, iIdxCur, brk);
|
||||
if( (topEq && !bRev) || (!btmEq && bRev) ){
|
||||
if( (leFlag && !bRev) || (!geFlag && bRev) ){
|
||||
sqlite3VdbeChangeP3(v, -1, "+", P3_STATIC);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_RowKey, iIdxCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_IdxIsNull, nNotNull, cont);
|
||||
sqlite3VdbeAddOp(v, OP_IdxIsNull, nEq + topLimit, cont);
|
||||
if( !omitTable ){
|
||||
sqlite3VdbeAddOp(v, OP_IdxRowid, iIdxCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
@@ -1892,7 +1815,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
/* Generate a single key that will be used to both start and terminate
|
||||
** the search
|
||||
*/
|
||||
buildIndexProbe(v, nEq, 0, brk, pIdx);
|
||||
buildIndexProbe(v, nEq, brk, pIdx);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 0);
|
||||
|
||||
/* Generate code (1) to move to the first matching element of the table.
|
||||
|
||||
+2
-10
@@ -10,7 +10,7 @@
|
||||
#***********************************************************************
|
||||
# This file runs all tests.
|
||||
#
|
||||
# $Id: all.test,v 1.34 2006/01/11 01:08:34 drh Exp $
|
||||
# $Id: all.test,v 1.30 2005/01/17 07:53:44 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -49,7 +49,6 @@ set LeakList {}
|
||||
|
||||
set EXCLUDE {
|
||||
all.test
|
||||
async.test
|
||||
crash.test
|
||||
autovacuum_crash.test
|
||||
quick.test
|
||||
@@ -58,12 +57,6 @@ set EXCLUDE {
|
||||
memleak.test
|
||||
}
|
||||
|
||||
# Files to include in the test. If this list is empty then everything
|
||||
# that is not in the EXCLUDE list is run.
|
||||
#
|
||||
set INCLUDE {
|
||||
}
|
||||
|
||||
# Test files btree2.test and btree4.test don't work if the
|
||||
# SQLITE_DEFAULT_AUTOVACUUM macro is defined to true (because they depend
|
||||
# on tables being allocated starting at page 2).
|
||||
@@ -82,7 +75,6 @@ for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} {
|
||||
foreach testfile [lsort -dictionary [glob $testdir/*.test]] {
|
||||
set tail [file tail $testfile]
|
||||
if {[lsearch -exact $EXCLUDE $tail]>=0} continue
|
||||
if {[llength $INCLUDE]>0 && [lsearch -exact $INCLUDE $tail]<0} continue
|
||||
source $testfile
|
||||
catch {db close}
|
||||
if {$sqlite_open_file_count>0} {
|
||||
@@ -133,7 +125,7 @@ if {$::tcl_platform(platform)=="unix"} {
|
||||
#
|
||||
catch {source $testdir/misuse.test}
|
||||
set sqlite_open_file_count 0
|
||||
# catch {source $testdir/malloc.test}
|
||||
catch {source $testdir/malloc.test}
|
||||
|
||||
catch {db close}
|
||||
set sqlite_open_file_count 0
|
||||
|
||||
+2
-70
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing the ALTER TABLE statement.
|
||||
#
|
||||
# $Id: alter.test,v 1.15 2006/01/15 14:11:49 danielk1977 Exp $
|
||||
# $Id: alter.test,v 1.11 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -144,8 +144,7 @@ do_test alter-1.5 {
|
||||
ifcapable tempdb {
|
||||
do_test alter-1.6 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
set DB [sqlite3 db test.db]
|
||||
execsql {
|
||||
CREATE TEMP TABLE objlist(type, name, tbl_name);
|
||||
INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
|
||||
@@ -552,71 +551,4 @@ do_test alter-5.3 {
|
||||
db2 close
|
||||
} {}
|
||||
|
||||
foreach tblname [execsql {
|
||||
SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite%'
|
||||
}] {
|
||||
execsql "DROP TABLE \"$tblname\""
|
||||
}
|
||||
|
||||
set ::tbl_name "abc\uABCDdef"
|
||||
do_test alter-6.1 {
|
||||
string length $::tbl_name
|
||||
} {7}
|
||||
do_test alter-6.2 {
|
||||
execsql "
|
||||
CREATE TABLE ${tbl_name}(a, b, c);
|
||||
"
|
||||
set ::oid [execsql {SELECT max(oid) FROM sqlite_master}]
|
||||
execsql {
|
||||
SELECT sql FROM sqlite_master WHERE oid = $::oid;
|
||||
}
|
||||
} "{CREATE TABLE ${::tbl_name}(a, b, c)}"
|
||||
execsql "
|
||||
SELECT * FROM ${::tbl_name}
|
||||
"
|
||||
set ::tbl_name2 "abcXdef"
|
||||
do_test alter-6.3 {
|
||||
execsql "
|
||||
ALTER TABLE $::tbl_name RENAME TO $::tbl_name2
|
||||
"
|
||||
execsql {
|
||||
SELECT sql FROM sqlite_master WHERE oid = $::oid;
|
||||
}
|
||||
} "{CREATE TABLE '${::tbl_name2}'(a, b, c)}"
|
||||
do_test alter-6.4 {
|
||||
execsql "
|
||||
ALTER TABLE $::tbl_name2 RENAME TO $::tbl_name
|
||||
"
|
||||
execsql {
|
||||
SELECT sql FROM sqlite_master WHERE oid = $::oid;
|
||||
}
|
||||
} "{CREATE TABLE '${::tbl_name}'(a, b, c)}"
|
||||
set ::col_name ghi\1234\jkl
|
||||
do_test alter-6.5 {
|
||||
execsql "
|
||||
ALTER TABLE $::tbl_name ADD COLUMN $::col_name VARCHAR
|
||||
"
|
||||
execsql {
|
||||
SELECT sql FROM sqlite_master WHERE oid = $::oid;
|
||||
}
|
||||
} "{CREATE TABLE '${::tbl_name}'(a, b, c, $::col_name VARCHAR)}"
|
||||
set ::col_name2 B\3421\A
|
||||
do_test alter-6.6 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
execsql "
|
||||
ALTER TABLE $::tbl_name ADD COLUMN $::col_name2
|
||||
"
|
||||
execsql {
|
||||
SELECT sql FROM sqlite_master WHERE oid = $::oid;
|
||||
}
|
||||
} "{CREATE TABLE '${::tbl_name}'(a, b, c, $::col_name VARCHAR, $::col_name2)}"
|
||||
do_test alter-6.7 {
|
||||
execsql "
|
||||
INSERT INTO ${::tbl_name} VALUES(1, 2, 3, 4, 5);
|
||||
SELECT $::col_name, $::col_name2 FROM $::tbl_name;
|
||||
"
|
||||
} {4 5}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
+4
-4
@@ -13,7 +13,7 @@
|
||||
# file format change that may be used in the future to implement
|
||||
# "ALTER TABLE ... ADD COLUMN".
|
||||
#
|
||||
# $Id: alter2.test,v 1.5 2006/01/03 00:33:50 drh Exp $
|
||||
# $Id: alter2.test,v 1.4 2005/03/10 12:52:47 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -250,7 +250,8 @@ do_test alter2-4.3 {
|
||||
sqlite3_errcode $::DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test alter2-4.4 {
|
||||
set ::DB [sqlite3_connection_pointer db]
|
||||
db close
|
||||
set ::DB [sqlite3 db test.db]
|
||||
catchsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
@@ -283,8 +284,7 @@ do_test alter2-5.3 {
|
||||
do_test alter2-6.1 {
|
||||
db close
|
||||
set_file_format 2
|
||||
sqlite3 db test.db
|
||||
set ::DB [sqlite3_connection_pointer db]
|
||||
set ::DB [sqlite3 db test.db]
|
||||
get_file_format
|
||||
} {2}
|
||||
do_test alter2-6.2 {
|
||||
|
||||
+1
-2
@@ -13,7 +13,7 @@
|
||||
# file format change that may be used in the future to implement
|
||||
# "ALTER TABLE ... ADD COLUMN".
|
||||
#
|
||||
# $Id: alter3.test,v 1.7 2005/12/30 16:28:02 danielk1977 Exp $
|
||||
# $Id: alter3.test,v 1.6 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -360,7 +360,6 @@ do_test alter3-8.1 {
|
||||
CREATE TABLE t4(c1);
|
||||
}
|
||||
} {}
|
||||
set ::sql ""
|
||||
do_test alter3-8.2 {
|
||||
set cols c1
|
||||
for {set i 2} {$i < 100} {incr i} {
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
#
|
||||
# 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 runs all tests.
|
||||
#
|
||||
# $Id: async.test,v 1.3 2006/01/09 17:29:53 drh Exp $
|
||||
|
||||
|
||||
if {[catch {sqlite3async_enable}]} {
|
||||
# The async logic is not built into this system
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
rename finish_test really_finish_test
|
||||
proc finish_test {} {}
|
||||
set ISQUICK 1
|
||||
|
||||
set INCLUDE {
|
||||
select1.test
|
||||
select2.test
|
||||
select3.test
|
||||
select4.test
|
||||
insert.test
|
||||
insert2.test
|
||||
insert3.test
|
||||
}
|
||||
#set INCLUDE [lrange $INCLUDE 0 0]
|
||||
|
||||
# Enable asynchronous IO.
|
||||
sqlite3async_enable 1
|
||||
sqlite3async_halt never
|
||||
sqlite3async_start
|
||||
|
||||
rename do_test really_do_test
|
||||
proc do_test {name args} {
|
||||
uplevel really_do_test async_io-$name $args
|
||||
sqlite3async_halt idle
|
||||
sqlite3async_wait
|
||||
sqlite3async_halt never
|
||||
sqlite3async_start
|
||||
}
|
||||
|
||||
foreach testfile [lsort -dictionary [glob $testdir/*.test]] {
|
||||
set tail [file tail $testfile]
|
||||
if {[lsearch -exact $INCLUDE $tail]<0} continue
|
||||
source $testfile
|
||||
catch {db close}
|
||||
}
|
||||
|
||||
|
||||
set sqlite_open_file_count 0
|
||||
really_finish_test
|
||||
sqlite3async_halt now
|
||||
sqlite3async_wait
|
||||
sqlite3async_enable 0
|
||||
rename really_do_test do_test
|
||||
rename really_finish_test finish_test
|
||||
+2
-1
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach.test,v 1.41 2005/11/29 03:13:22 drh Exp $
|
||||
# $Id: attach.test,v 1.40 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -742,4 +742,5 @@ db close
|
||||
file delete -force test2.db
|
||||
file delete -force no-such-file
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
+5
-5
@@ -12,12 +12,13 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach2.test,v 1.35 2006/01/03 00:33:50 drh Exp $
|
||||
# $Id: attach2.test,v 1.32 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
# Ticket #354
|
||||
#
|
||||
# Databases test.db and test2.db contain identical schemas. Make
|
||||
@@ -129,17 +130,16 @@ do_test attach2-2.12 {
|
||||
# Ticket #574: Make sure it works using the non-callback API
|
||||
#
|
||||
do_test attach2-3.1 {
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
set rc [catch {sqlite3_prepare $DB "ATTACH 'test2.db' AS t2" -1 TAIL} VM]
|
||||
if {$rc} {lappend rc $VM}
|
||||
sqlite3_step $VM
|
||||
sqlite3_finalize $VM
|
||||
set rc
|
||||
} {0}
|
||||
do_test attach2-3.2 {
|
||||
set rc [catch {sqlite3_prepare $DB "DETACH t2" -1 TAIL} VM]
|
||||
if {$rc} {lappend rc $VM}
|
||||
sqlite3_step $VM
|
||||
sqlite3_finalize $VM
|
||||
set rc
|
||||
} {0}
|
||||
@@ -155,7 +155,7 @@ proc lock_status {testnum db expected_result} {
|
||||
# If the database was compiled with OMIT_TEMPDB set, then
|
||||
# the lock_status list will not contain an entry for the temp
|
||||
# db. But the test code doesn't know this, so it's easiest
|
||||
# to filter it out of the $expected_result list here.
|
||||
# to filter it out here.
|
||||
ifcapable !tempdb {
|
||||
set expected_result [concat \
|
||||
[lrange $expected_result 0 1] \
|
||||
|
||||
+1
-12
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: auth.test,v 1.30 2006/01/13 13:55:45 drh Exp $
|
||||
# $Id: auth.test,v 1.29 2005/07/29 15:36:15 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -2207,17 +2207,6 @@ do_test auth-5.1 {
|
||||
}
|
||||
} {1}
|
||||
|
||||
# Ticket #1607
|
||||
#
|
||||
do_test auth-5.2 {
|
||||
execsql {
|
||||
SELECT name FROM (
|
||||
SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master)
|
||||
WHERE type='table'
|
||||
ORDER BY name
|
||||
}
|
||||
} {sqlite_stat1 t1 t2 t3 t4 tx v1chng}
|
||||
|
||||
|
||||
rename proc {}
|
||||
rename proc_real proc
|
||||
|
||||
+3
-4
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing the AUTOINCREMENT features.
|
||||
#
|
||||
# $Id: autoinc.test,v 1.9 2006/01/03 00:33:50 drh Exp $
|
||||
# $Id: autoinc.test,v 1.7 2005/08/11 02:10:19 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -494,7 +494,7 @@ do_test autoinc-7.1 {
|
||||
INSERT INTO t7(y) VALUES(345);
|
||||
SELECT * FROM t7;
|
||||
}
|
||||
} {3 345.0}
|
||||
} {3 345}
|
||||
|
||||
# Test that if the AUTOINCREMENT is applied to a non integer primary key
|
||||
# the error message is sensible.
|
||||
@@ -512,8 +512,7 @@ do_test autoinc-8.1 {
|
||||
catch {db2 close}
|
||||
catch {db close}
|
||||
file delete -force test.db
|
||||
sqlite3 db test.db
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
set DB [sqlite3 db test.db]
|
||||
set STMT [sqlite3_prepare $DB {
|
||||
CREATE TABLE t1(
|
||||
x INTEGER PRIMARY KEY AUTOINCREMENT
|
||||
|
||||
@@ -1,908 +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. This
|
||||
# file is a copy of "trans.test" modified to run under autovacuum mode.
|
||||
# the point is to stress the autovacuum logic and try to get it to fail.
|
||||
#
|
||||
# $Id: avtrans.test,v 1.1 2005/12/09 02:35:54 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
# Create several tables to work with.
|
||||
#
|
||||
do_test avtrans-1.0 {
|
||||
execsql {
|
||||
PRAGMA auto_vacuum=ON;
|
||||
CREATE TABLE one(a int PRIMARY KEY, b text);
|
||||
INSERT INTO one VALUES(1,'one');
|
||||
INSERT INTO one VALUES(2,'two');
|
||||
INSERT INTO one VALUES(3,'three');
|
||||
SELECT b FROM one ORDER BY a;
|
||||
}
|
||||
} {one two three}
|
||||
do_test avtrans-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE two(a int PRIMARY KEY, b text);
|
||||
INSERT INTO two VALUES(1,'I');
|
||||
INSERT INTO two VALUES(5,'V');
|
||||
INSERT INTO two VALUES(10,'X');
|
||||
SELECT b FROM two ORDER BY a;
|
||||
}
|
||||
} {I V X}
|
||||
do_test avtrans-1.9 {
|
||||
sqlite3 altdb test.db
|
||||
execsql {SELECT b FROM one ORDER BY a} altdb
|
||||
} {one two three}
|
||||
do_test avtrans-1.10 {
|
||||
execsql {SELECT b FROM two ORDER BY a} altdb
|
||||
} {I V X}
|
||||
integrity_check avtrans-1.11
|
||||
|
||||
# Basic transactions
|
||||
#
|
||||
do_test avtrans-2.1 {
|
||||
set v [catch {execsql {BEGIN}} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test avtrans-2.2 {
|
||||
set v [catch {execsql {END}} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test avtrans-2.3 {
|
||||
set v [catch {execsql {BEGIN TRANSACTION}} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test avtrans-2.4 {
|
||||
set v [catch {execsql {COMMIT TRANSACTION}} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test avtrans-2.5 {
|
||||
set v [catch {execsql {BEGIN TRANSACTION 'foo'}} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test avtrans-2.6 {
|
||||
set v [catch {execsql {ROLLBACK TRANSACTION 'foo'}} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test avtrans-2.10 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
SELECT a FROM one ORDER BY a;
|
||||
SELECT a FROM two ORDER BY a;
|
||||
END;
|
||||
}
|
||||
} {1 2 3 1 5 10}
|
||||
integrity_check avtrans-2.11
|
||||
|
||||
# Check the locking behavior
|
||||
#
|
||||
do_test avtrans-3.1 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
UPDATE one SET a = 0 WHERE 0;
|
||||
SELECT a FROM one ORDER BY a;
|
||||
}
|
||||
} {1 2 3}
|
||||
do_test avtrans-3.2 {
|
||||
catchsql {
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 5 10}}
|
||||
do_test avtrans-3.3 {
|
||||
catchsql {
|
||||
SELECT a FROM one ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 2 3}}
|
||||
do_test avtrans-3.4 {
|
||||
catchsql {
|
||||
INSERT INTO one VALUES(4,'four');
|
||||
}
|
||||
} {0 {}}
|
||||
do_test avtrans-3.5 {
|
||||
catchsql {
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 5 10}}
|
||||
do_test avtrans-3.6 {
|
||||
catchsql {
|
||||
SELECT a FROM one ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 2 3}}
|
||||
do_test avtrans-3.7 {
|
||||
catchsql {
|
||||
INSERT INTO two VALUES(4,'IV');
|
||||
}
|
||||
} {0 {}}
|
||||
do_test avtrans-3.8 {
|
||||
catchsql {
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 5 10}}
|
||||
do_test avtrans-3.9 {
|
||||
catchsql {
|
||||
SELECT a FROM one ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 2 3}}
|
||||
do_test avtrans-3.10 {
|
||||
execsql {END TRANSACTION}
|
||||
} {}
|
||||
do_test avtrans-3.11 {
|
||||
set v [catch {execsql {
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} altdb} msg]
|
||||
lappend v $msg
|
||||
} {0 {1 4 5 10}}
|
||||
do_test avtrans-3.12 {
|
||||
set v [catch {execsql {
|
||||
SELECT a FROM one ORDER BY a;
|
||||
} altdb} msg]
|
||||
lappend v $msg
|
||||
} {0 {1 2 3 4}}
|
||||
do_test avtrans-3.13 {
|
||||
set v [catch {execsql {
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} db} msg]
|
||||
lappend v $msg
|
||||
} {0 {1 4 5 10}}
|
||||
do_test avtrans-3.14 {
|
||||
set v [catch {execsql {
|
||||
SELECT a FROM one ORDER BY a;
|
||||
} db} msg]
|
||||
lappend v $msg
|
||||
} {0 {1 2 3 4}}
|
||||
integrity_check avtrans-3.15
|
||||
|
||||
do_test avtrans-4.1 {
|
||||
set v [catch {execsql {
|
||||
COMMIT;
|
||||
} db} msg]
|
||||
lappend v $msg
|
||||
} {1 {cannot commit - no transaction is active}}
|
||||
do_test avtrans-4.2 {
|
||||
set v [catch {execsql {
|
||||
ROLLBACK;
|
||||
} db} msg]
|
||||
lappend v $msg
|
||||
} {1 {cannot rollback - no transaction is active}}
|
||||
do_test avtrans-4.3 {
|
||||
catchsql {
|
||||
BEGIN TRANSACTION;
|
||||
UPDATE two SET a = 0 WHERE 0;
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} db
|
||||
} {0 {1 4 5 10}}
|
||||
do_test avtrans-4.4 {
|
||||
catchsql {
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 4 5 10}}
|
||||
do_test avtrans-4.5 {
|
||||
catchsql {
|
||||
SELECT a FROM one ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 2 3 4}}
|
||||
do_test avtrans-4.6 {
|
||||
catchsql {
|
||||
BEGIN TRANSACTION;
|
||||
SELECT a FROM one ORDER BY a;
|
||||
} db
|
||||
} {1 {cannot start a transaction within a transaction}}
|
||||
do_test avtrans-4.7 {
|
||||
catchsql {
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 4 5 10}}
|
||||
do_test avtrans-4.8 {
|
||||
catchsql {
|
||||
SELECT a FROM one ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 2 3 4}}
|
||||
do_test avtrans-4.9 {
|
||||
set v [catch {execsql {
|
||||
END TRANSACTION;
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} db} msg]
|
||||
lappend v $msg
|
||||
} {0 {1 4 5 10}}
|
||||
do_test avtrans-4.10 {
|
||||
set v [catch {execsql {
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} altdb} msg]
|
||||
lappend v $msg
|
||||
} {0 {1 4 5 10}}
|
||||
do_test avtrans-4.11 {
|
||||
set v [catch {execsql {
|
||||
SELECT a FROM one ORDER BY a;
|
||||
} altdb} msg]
|
||||
lappend v $msg
|
||||
} {0 {1 2 3 4}}
|
||||
integrity_check avtrans-4.12
|
||||
do_test avtrans-4.98 {
|
||||
altdb close
|
||||
execsql {
|
||||
DROP TABLE one;
|
||||
DROP TABLE two;
|
||||
}
|
||||
} {}
|
||||
integrity_check avtrans-4.99
|
||||
|
||||
# Check out the commit/rollback behavior of the database
|
||||
#
|
||||
do_test avtrans-5.1 {
|
||||
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
|
||||
} {}
|
||||
do_test avtrans-5.2 {
|
||||
execsql {BEGIN TRANSACTION}
|
||||
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
|
||||
} {}
|
||||
do_test avtrans-5.3 {
|
||||
execsql {CREATE TABLE one(a text, b int)}
|
||||
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
|
||||
} {one}
|
||||
do_test avtrans-5.4 {
|
||||
execsql {SELECT a,b FROM one ORDER BY b}
|
||||
} {}
|
||||
do_test avtrans-5.5 {
|
||||
execsql {INSERT INTO one(a,b) VALUES('hello', 1)}
|
||||
execsql {SELECT a,b FROM one ORDER BY b}
|
||||
} {hello 1}
|
||||
do_test avtrans-5.6 {
|
||||
execsql {ROLLBACK}
|
||||
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
|
||||
} {}
|
||||
do_test avtrans-5.7 {
|
||||
set v [catch {
|
||||
execsql {SELECT a,b FROM one ORDER BY b}
|
||||
} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such table: one}}
|
||||
|
||||
# Test commits and rollbacks of table CREATE TABLEs, CREATE INDEXs
|
||||
# DROP TABLEs and DROP INDEXs
|
||||
#
|
||||
do_test avtrans-5.8 {
|
||||
execsql {
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name
|
||||
}
|
||||
} {}
|
||||
do_test avtrans-5.9 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
CREATE TABLE t1(a int, b int, c int);
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {t1}
|
||||
do_test avtrans-5.10 {
|
||||
execsql {
|
||||
CREATE INDEX i1 ON t1(a);
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {i1 t1}
|
||||
do_test avtrans-5.11 {
|
||||
execsql {
|
||||
COMMIT;
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {i1 t1}
|
||||
do_test avtrans-5.12 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
CREATE TABLE t2(a int, b int, c int);
|
||||
CREATE INDEX i2a ON t2(a);
|
||||
CREATE INDEX i2b ON t2(b);
|
||||
DROP TABLE t1;
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {i2a i2b t2}
|
||||
do_test avtrans-5.13 {
|
||||
execsql {
|
||||
ROLLBACK;
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {i1 t1}
|
||||
do_test avtrans-5.14 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
DROP INDEX i1;
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {t1}
|
||||
do_test avtrans-5.15 {
|
||||
execsql {
|
||||
ROLLBACK;
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {i1 t1}
|
||||
do_test avtrans-5.16 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
DROP INDEX i1;
|
||||
CREATE TABLE t2(x int, y int, z int);
|
||||
CREATE INDEX i2x ON t2(x);
|
||||
CREATE INDEX i2y ON t2(y);
|
||||
INSERT INTO t2 VALUES(1,2,3);
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {i2x i2y t1 t2}
|
||||
do_test avtrans-5.17 {
|
||||
execsql {
|
||||
COMMIT;
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {i2x i2y t1 t2}
|
||||
do_test avtrans-5.18 {
|
||||
execsql {
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 2 3}
|
||||
do_test avtrans-5.19 {
|
||||
execsql {
|
||||
SELECT x FROM t2 WHERE y=2;
|
||||
}
|
||||
} {1}
|
||||
do_test avtrans-5.20 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {}
|
||||
do_test avtrans-5.21 {
|
||||
set r [catch {execsql {
|
||||
SELECT * FROM t2
|
||||
}} msg]
|
||||
lappend r $msg
|
||||
} {1 {no such table: t2}}
|
||||
do_test avtrans-5.22 {
|
||||
execsql {
|
||||
ROLLBACK;
|
||||
SELECT name fROM sqlite_master
|
||||
WHERE type='table' OR type='index'
|
||||
ORDER BY name;
|
||||
}
|
||||
} {i2x i2y t1 t2}
|
||||
do_test avtrans-5.23 {
|
||||
execsql {
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 2 3}
|
||||
integrity_check avtrans-5.23
|
||||
|
||||
|
||||
# Try to DROP and CREATE tables and indices with the same name
|
||||
# within a transaction. Make sure ROLLBACK works.
|
||||
#
|
||||
do_test avtrans-6.1 {
|
||||
execsql2 {
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(p,q,r);
|
||||
ROLLBACK;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {a 1 b 2 c 3}
|
||||
do_test avtrans-6.2 {
|
||||
execsql2 {
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(p,q,r);
|
||||
COMMIT;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {}
|
||||
do_test avtrans-6.3 {
|
||||
execsql2 {
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {p 1 q 2 r 3}
|
||||
do_test avtrans-6.4 {
|
||||
execsql2 {
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a,b,c);
|
||||
INSERT INTO t1 VALUES(4,5,6);
|
||||
SELECT * FROM t1;
|
||||
DROP TABLE t1;
|
||||
}
|
||||
} {a 4 b 5 c 6}
|
||||
do_test avtrans-6.5 {
|
||||
execsql2 {
|
||||
ROLLBACK;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {p 1 q 2 r 3}
|
||||
do_test avtrans-6.6 {
|
||||
execsql2 {
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a,b,c);
|
||||
INSERT INTO t1 VALUES(4,5,6);
|
||||
SELECT * FROM t1;
|
||||
DROP TABLE t1;
|
||||
}
|
||||
} {a 4 b 5 c 6}
|
||||
do_test avtrans-6.7 {
|
||||
catchsql {
|
||||
COMMIT;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 {no such table: t1}}
|
||||
|
||||
# Repeat on a table with an automatically generated index.
|
||||
#
|
||||
do_test avtrans-6.10 {
|
||||
execsql2 {
|
||||
CREATE TABLE t1(a unique,b,c);
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(p unique,q,r);
|
||||
ROLLBACK;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {a 1 b 2 c 3}
|
||||
do_test avtrans-6.11 {
|
||||
execsql2 {
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(p unique,q,r);
|
||||
COMMIT;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {}
|
||||
do_test avtrans-6.12 {
|
||||
execsql2 {
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {p 1 q 2 r 3}
|
||||
do_test avtrans-6.13 {
|
||||
execsql2 {
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a unique,b,c);
|
||||
INSERT INTO t1 VALUES(4,5,6);
|
||||
SELECT * FROM t1;
|
||||
DROP TABLE t1;
|
||||
}
|
||||
} {a 4 b 5 c 6}
|
||||
do_test avtrans-6.14 {
|
||||
execsql2 {
|
||||
ROLLBACK;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {p 1 q 2 r 3}
|
||||
do_test avtrans-6.15 {
|
||||
execsql2 {
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a unique,b,c);
|
||||
INSERT INTO t1 VALUES(4,5,6);
|
||||
SELECT * FROM t1;
|
||||
DROP TABLE t1;
|
||||
}
|
||||
} {a 4 b 5 c 6}
|
||||
do_test avtrans-6.16 {
|
||||
catchsql {
|
||||
COMMIT;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 {no such table: t1}}
|
||||
|
||||
do_test avtrans-6.20 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a integer primary key,b,c);
|
||||
INSERT INTO t1 VALUES(1,-2,-3);
|
||||
INSERT INTO t1 VALUES(4,-5,-6);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 -2 -3 4 -5 -6}
|
||||
do_test avtrans-6.21 {
|
||||
execsql {
|
||||
CREATE INDEX i1 ON t1(b);
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
}
|
||||
} {4 -5 -6 1 -2 -3}
|
||||
do_test avtrans-6.22 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
DROP INDEX i1;
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
ROLLBACK;
|
||||
}
|
||||
} {1 -2 -3 4 -5 -6}
|
||||
do_test avtrans-6.23 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
}
|
||||
} {4 -5 -6 1 -2 -3}
|
||||
do_test avtrans-6.24 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
ROLLBACK;
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
}
|
||||
} {4 -5 -6 1 -2 -3}
|
||||
|
||||
do_test avtrans-6.25 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
DROP INDEX i1;
|
||||
CREATE INDEX i1 ON t1(c);
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
}
|
||||
} {1 -2 -3 4 -5 -6}
|
||||
do_test avtrans-6.26 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE c<1;
|
||||
}
|
||||
} {4 -5 -6 1 -2 -3}
|
||||
do_test avtrans-6.27 {
|
||||
execsql {
|
||||
ROLLBACK;
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
}
|
||||
} {4 -5 -6 1 -2 -3}
|
||||
do_test avtrans-6.28 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE c<1;
|
||||
}
|
||||
} {1 -2 -3 4 -5 -6}
|
||||
|
||||
# The following repeats steps 6.20 through 6.28, but puts a "unique"
|
||||
# constraint the first field of the table in order to generate an
|
||||
# automatic index.
|
||||
#
|
||||
do_test avtrans-6.30 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a int unique,b,c);
|
||||
COMMIT;
|
||||
INSERT INTO t1 VALUES(1,-2,-3);
|
||||
INSERT INTO t1 VALUES(4,-5,-6);
|
||||
SELECT * FROM t1 ORDER BY a;
|
||||
}
|
||||
} {1 -2 -3 4 -5 -6}
|
||||
do_test avtrans-6.31 {
|
||||
execsql {
|
||||
CREATE INDEX i1 ON t1(b);
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
}
|
||||
} {4 -5 -6 1 -2 -3}
|
||||
do_test avtrans-6.32 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
DROP INDEX i1;
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
ROLLBACK;
|
||||
}
|
||||
} {1 -2 -3 4 -5 -6}
|
||||
do_test avtrans-6.33 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
}
|
||||
} {4 -5 -6 1 -2 -3}
|
||||
do_test avtrans-6.34 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
DROP TABLE t1;
|
||||
ROLLBACK;
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
}
|
||||
} {4 -5 -6 1 -2 -3}
|
||||
|
||||
do_test avtrans-6.35 {
|
||||
execsql {
|
||||
BEGIN TRANSACTION;
|
||||
DROP INDEX i1;
|
||||
CREATE INDEX i1 ON t1(c);
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
}
|
||||
} {1 -2 -3 4 -5 -6}
|
||||
do_test avtrans-6.36 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE c<1;
|
||||
}
|
||||
} {4 -5 -6 1 -2 -3}
|
||||
do_test avtrans-6.37 {
|
||||
execsql {
|
||||
DROP INDEX i1;
|
||||
SELECT * FROM t1 WHERE c<1;
|
||||
}
|
||||
} {1 -2 -3 4 -5 -6}
|
||||
do_test avtrans-6.38 {
|
||||
execsql {
|
||||
ROLLBACK;
|
||||
SELECT * FROM t1 WHERE b<1;
|
||||
}
|
||||
} {4 -5 -6 1 -2 -3}
|
||||
do_test avtrans-6.39 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE c<1;
|
||||
}
|
||||
} {1 -2 -3 4 -5 -6}
|
||||
integrity_check avtrans-6.40
|
||||
|
||||
# Test to make sure rollback restores the database back to its original
|
||||
# state.
|
||||
#
|
||||
do_test avtrans-7.1 {
|
||||
execsql {BEGIN}
|
||||
for {set i 0} {$i<1000} {incr i} {
|
||||
set r1 [expr {rand()}]
|
||||
set r2 [expr {rand()}]
|
||||
set r3 [expr {rand()}]
|
||||
execsql "INSERT INTO t2 VALUES($r1,$r2,$r3)"
|
||||
}
|
||||
execsql {COMMIT}
|
||||
set ::checksum [execsql {SELECT md5sum(x,y,z) FROM t2}]
|
||||
set ::checksum2 [
|
||||
execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
|
||||
]
|
||||
execsql {SELECT count(*) FROM t2}
|
||||
} {1001}
|
||||
do_test avtrans-7.2 {
|
||||
execsql {SELECT md5sum(x,y,z) FROM t2}
|
||||
} $checksum
|
||||
do_test avtrans-7.2.1 {
|
||||
execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
|
||||
} $checksum2
|
||||
do_test avtrans-7.3 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
DELETE FROM t2;
|
||||
ROLLBACK;
|
||||
SELECT md5sum(x,y,z) FROM t2;
|
||||
}
|
||||
} $checksum
|
||||
do_test avtrans-7.4 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO t2 SELECT * FROM t2;
|
||||
ROLLBACK;
|
||||
SELECT md5sum(x,y,z) FROM t2;
|
||||
}
|
||||
} $checksum
|
||||
do_test avtrans-7.5 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
DELETE FROM t2;
|
||||
ROLLBACK;
|
||||
SELECT md5sum(x,y,z) FROM t2;
|
||||
}
|
||||
} $checksum
|
||||
do_test avtrans-7.6 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO t2 SELECT * FROM t2;
|
||||
ROLLBACK;
|
||||
SELECT md5sum(x,y,z) FROM t2;
|
||||
}
|
||||
} $checksum
|
||||
do_test avtrans-7.7 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE t3 AS SELECT * FROM t2;
|
||||
INSERT INTO t2 SELECT * FROM t3;
|
||||
ROLLBACK;
|
||||
SELECT md5sum(x,y,z) FROM t2;
|
||||
}
|
||||
} $checksum
|
||||
do_test avtrans-7.8 {
|
||||
execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
|
||||
} $checksum2
|
||||
ifcapable tempdb {
|
||||
do_test avtrans-7.9 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TEMP TABLE t3 AS SELECT * FROM t2;
|
||||
INSERT INTO t2 SELECT * FROM t3;
|
||||
ROLLBACK;
|
||||
SELECT md5sum(x,y,z) FROM t2;
|
||||
}
|
||||
} $checksum
|
||||
}
|
||||
do_test avtrans-7.10 {
|
||||
execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
|
||||
} $checksum2
|
||||
ifcapable tempdb {
|
||||
do_test avtrans-7.11 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TEMP TABLE t3 AS SELECT * FROM t2;
|
||||
INSERT INTO t2 SELECT * FROM t3;
|
||||
DROP INDEX i2x;
|
||||
DROP INDEX i2y;
|
||||
CREATE INDEX i3a ON t3(x);
|
||||
ROLLBACK;
|
||||
SELECT md5sum(x,y,z) FROM t2;
|
||||
}
|
||||
} $checksum
|
||||
}
|
||||
do_test avtrans-7.12 {
|
||||
execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
|
||||
} $checksum2
|
||||
ifcapable tempdb {
|
||||
do_test avtrans-7.13 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
DROP TABLE t2;
|
||||
ROLLBACK;
|
||||
SELECT md5sum(x,y,z) FROM t2;
|
||||
}
|
||||
} $checksum
|
||||
}
|
||||
do_test avtrans-7.14 {
|
||||
execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
|
||||
} $checksum2
|
||||
integrity_check avtrans-7.15
|
||||
|
||||
# Arrange for another process to begin modifying the database but abort
|
||||
# and die in the middle of the modification. Then have this process read
|
||||
# the database. This process should detect the journal file and roll it
|
||||
# back. Verify that this happens correctly.
|
||||
#
|
||||
set fd [open test.tcl w]
|
||||
puts $fd {
|
||||
sqlite3 db test.db
|
||||
db eval {
|
||||
PRAGMA default_cache_size=20;
|
||||
BEGIN;
|
||||
CREATE TABLE t3 AS SELECT * FROM t2;
|
||||
DELETE FROM t2;
|
||||
}
|
||||
sqlite_abort
|
||||
}
|
||||
close $fd
|
||||
do_test avtrans-8.1 {
|
||||
catch {exec [info nameofexec] test.tcl}
|
||||
execsql {SELECT md5sum(x,y,z) FROM t2}
|
||||
} $checksum
|
||||
do_test avtrans-8.2 {
|
||||
execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master}
|
||||
} $checksum2
|
||||
integrity_check avtrans-8.3
|
||||
|
||||
# In the following sequence of tests, compute the MD5 sum of the content
|
||||
# of a table, make lots of modifications to that table, then do a rollback.
|
||||
# Verify that after the rollback, the MD5 checksum is unchanged.
|
||||
#
|
||||
do_test avtrans-9.1 {
|
||||
execsql {
|
||||
PRAGMA default_cache_size=10;
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE t3(x TEXT);
|
||||
INSERT INTO t3 VALUES(randstr(10,400));
|
||||
INSERT INTO t3 VALUES(randstr(10,400));
|
||||
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
|
||||
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
|
||||
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
|
||||
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
|
||||
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
|
||||
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
|
||||
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
|
||||
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
|
||||
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
|
||||
COMMIT;
|
||||
SELECT count(*) FROM t3;
|
||||
}
|
||||
} {1024}
|
||||
|
||||
# The following procedure computes a "signature" for table "t3". If
|
||||
# T3 changes in any way, the signature should change.
|
||||
#
|
||||
# This is used to test ROLLBACK. We gather a signature for t3, then
|
||||
# make lots of changes to t3, then rollback and take another signature.
|
||||
# The two signatures should be the same.
|
||||
#
|
||||
proc signature {} {
|
||||
return [db eval {SELECT count(*), md5sum(x) FROM t3}]
|
||||
}
|
||||
|
||||
# Repeat the following group of tests 20 times for quick testing and
|
||||
# 40 times for full testing. Each iteration of the test makes table
|
||||
# t3 a little larger, and thus takes a little longer, so doing 40 tests
|
||||
# is more than 2.0 times slower than doing 20 tests. Considerably more.
|
||||
#
|
||||
if {[info exists ISQUICK]} {
|
||||
set limit 20
|
||||
} else {
|
||||
set limit 40
|
||||
}
|
||||
|
||||
# Do rollbacks. Make sure the signature does not change.
|
||||
#
|
||||
for {set i 2} {$i<=$limit} {incr i} {
|
||||
set ::sig [signature]
|
||||
set cnt [lindex $::sig 0]
|
||||
if {$i%2==0} {
|
||||
execsql {PRAGMA synchronous=FULL}
|
||||
} else {
|
||||
execsql {PRAGMA synchronous=NORMAL}
|
||||
}
|
||||
set sqlite_sync_count 0
|
||||
set sqlite_fullsync_count 0
|
||||
do_test avtrans-9.$i.1-$cnt {
|
||||
execsql {
|
||||
BEGIN;
|
||||
DELETE FROM t3 WHERE random()%10!=0;
|
||||
INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
|
||||
INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
|
||||
ROLLBACK;
|
||||
}
|
||||
signature
|
||||
} $sig
|
||||
do_test avtrans-9.$i.2-$cnt {
|
||||
execsql {
|
||||
BEGIN;
|
||||
DELETE FROM t3 WHERE random()%10!=0;
|
||||
INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
|
||||
DELETE FROM t3 WHERE random()%10!=0;
|
||||
INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
|
||||
ROLLBACK;
|
||||
}
|
||||
signature
|
||||
} $sig
|
||||
if {$i<$limit} {
|
||||
do_test avtrans-9.$i.3-$cnt {
|
||||
execsql {
|
||||
INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0;
|
||||
}
|
||||
} {}
|
||||
if {$tcl_platform(platform)=="unix"} {
|
||||
do_test avtrans-9.$i.4-$cnt {
|
||||
expr {$sqlite_sync_count>0}
|
||||
} 1
|
||||
do_test avtrans-9.$i.5-$cnt {
|
||||
expr {$sqlite_fullsync_count>0}
|
||||
} [expr {$i%2==0}]
|
||||
}
|
||||
}
|
||||
set ::pager_old_format 0
|
||||
}
|
||||
integrity_check avtrans-10.1
|
||||
|
||||
finish_test
|
||||
+1
-7
@@ -12,18 +12,12 @@
|
||||
# focus of this script testing the ability of SQLite to handle database
|
||||
# files larger than 4GB.
|
||||
#
|
||||
# $Id: bigfile.test,v 1.9 2005/11/25 09:01:24 danielk1977 Exp $
|
||||
# $Id: bigfile.test,v 1.8 2005/09/07 23:05:22 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_DISABLE_LFS is defined, omit this file.
|
||||
ifcapable !lfs {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# These tests only work for Tcl version 8.4 and later. Prior to 8.4,
|
||||
# Tcl was unable to handle large files.
|
||||
#
|
||||
|
||||
+3
-27
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the sqlite_bind API.
|
||||
#
|
||||
# $Id: bind.test,v 1.36 2006/01/03 00:33:50 drh Exp $
|
||||
# $Id: bind.test,v 1.32 2005/06/22 08:48:07 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -35,7 +35,8 @@ proc sqlite_step {stmt N VALS COLS} {
|
||||
}
|
||||
|
||||
do_test bind-1.1 {
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
execsql {CREATE TABLE t1(a,b,c);}
|
||||
set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:1,?,:abc)} -1 TAIL]
|
||||
set TAIL
|
||||
@@ -499,29 +500,4 @@ ifcapable tclvar {
|
||||
} {1 {unrecognized token: "$abc(123"}}
|
||||
}
|
||||
|
||||
if {[execsql {pragma encoding}]=="UTF-8"} {
|
||||
# Test the ability to bind text that contains embedded '\000' characters.
|
||||
# Make sure we can recover the enter input string.
|
||||
#
|
||||
do_test bind-12.1 {
|
||||
execsql {
|
||||
CREATE TABLE t3(x BLOB);
|
||||
}
|
||||
set VM [sqlite3_prepare $DB {INSERT INTO t3 VALUES(?)} -1 TAIL]
|
||||
sqlite_bind $VM 1 not-used blob10
|
||||
sqlite3_step $VM
|
||||
sqlite3_finalize $VM
|
||||
execsql {
|
||||
SELECT typeof(x), length(x), quote(x),
|
||||
length(cast(x AS BLOB)), quote(cast(x AS BLOB)) FROM t3
|
||||
}
|
||||
} {text 3 'abc' 10 X'6162630078797A007071'}
|
||||
do_test bind-12.2 {
|
||||
sqlite3_create_function $DB
|
||||
execsql {
|
||||
SELECT quote(cast(x_coalesce(x) AS blob)) FROM t3
|
||||
}
|
||||
} {X'6162630078797A007071'}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
+3
-2
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the sqlite_transfer_bindings() API.
|
||||
#
|
||||
# $Id: bindxfer.test,v 1.2 2006/01/03 00:33:50 drh Exp $
|
||||
# $Id: bindxfer.test,v 1.1 2005/04/22 02:38:39 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -35,7 +35,8 @@ proc sqlite_step {stmt VALS COLS} {
|
||||
}
|
||||
|
||||
do_test bindxfer-1.1 {
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
execsql {CREATE TABLE t1(a,b,c);}
|
||||
set VM1 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL]
|
||||
set TAIL
|
||||
|
||||
+2
-3
@@ -10,7 +10,7 @@
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
# $Id: blob.test,v 1.5 2006/01/03 00:33:50 drh Exp $
|
||||
# $Id: blob.test,v 1.4 2005/08/23 11:17:59 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -104,8 +104,7 @@ do_test blob-2.4 {
|
||||
|
||||
# Try to bind a blob value to a prepared statement.
|
||||
do_test blob-3.0 {
|
||||
sqlite3 db2 test.db
|
||||
set DB [sqlite3_connection_pointer db2]
|
||||
set DB [sqlite3 db2 test.db]
|
||||
set STMT [sqlite3_prepare $DB "DELETE FROM t1 WHERE a = ?" -1 DUMMY]
|
||||
sqlite3_bind_blob $STMT 1 "\x12\x34\x56" 3
|
||||
sqlite3_step $STMT
|
||||
|
||||
+3
-2
@@ -11,7 +11,7 @@
|
||||
# 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.27 2006/01/03 00:33:50 drh Exp $
|
||||
# $Id: capi2.test,v 1.26 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -48,7 +48,8 @@ proc get_column_names {STMT} {
|
||||
# Check basic functionality
|
||||
#
|
||||
do_test capi2-1.1 {
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
execsql {CREATE TABLE t1(a,b,c)}
|
||||
set VM [sqlite3_prepare $DB {SELECT name, rowid FROM sqlite_master} -1 TAIL]
|
||||
set TAIL
|
||||
|
||||
+30
-49
@@ -11,7 +11,7 @@
|
||||
# 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.38 2006/01/13 01:25:06 drh Exp $
|
||||
# $Id: capi3.test,v 1.34 2005/08/11 02:10:19 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -51,7 +51,8 @@ proc utf8 {str} {
|
||||
# capi3-6.*: Test that sqlite3_close fails if there are outstanding VMs.
|
||||
#
|
||||
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
|
||||
do_test capi3-1.0 {
|
||||
sqlite3_get_autocommit $DB
|
||||
@@ -87,42 +88,30 @@ do_test capi3-1.7 {
|
||||
} {no such column: namex}
|
||||
|
||||
ifcapable {utf16} {
|
||||
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}]
|
||||
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]
|
||||
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}
|
||||
do_test capi3-2.6 {
|
||||
execsql {CREATE TABLE tablename(x)}
|
||||
set sql16 [utf16 {PRAGMA table_info("TableName")}]
|
||||
set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL]
|
||||
sqlite3_step $STMT
|
||||
} SQLITE_ROW
|
||||
do_test capi3-2.7 {
|
||||
sqlite3_step $STMT
|
||||
} SQLITE_DONE
|
||||
do_test capi3-2.8 {
|
||||
sqlite3_finalize $STMT
|
||||
} SQLITE_OK
|
||||
}
|
||||
} {1}
|
||||
do_test capi3-2.4 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-2.5 {
|
||||
sqlite3_errmsg $DB
|
||||
} {no such column: namex}
|
||||
} ;# endif utf16
|
||||
|
||||
# rename sqlite3_open sqlite3_open_old
|
||||
@@ -474,17 +463,13 @@ set ::ENC [execsql {pragma encoding}]
|
||||
db close
|
||||
|
||||
do_test capi3-6.0 {
|
||||
btree_breakpoint
|
||||
sqlite3 db test.db
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
btree_breakpoint
|
||||
set DB [sqlite3_open test.db]
|
||||
sqlite3_key $DB xyzzy
|
||||
set sql {SELECT a FROM t1 order by rowid}
|
||||
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
|
||||
expr 0
|
||||
} {0}
|
||||
do_test capi3-6.1 {
|
||||
db cache flush
|
||||
sqlite3_close $DB
|
||||
} {SQLITE_BUSY}
|
||||
do_test capi3-6.2 {
|
||||
@@ -495,10 +480,8 @@ do_test capi3-6.3 {
|
||||
sqlite3_finalize $STMT
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-6.4 {
|
||||
db cache flush
|
||||
sqlite3_close $DB
|
||||
} {SQLITE_OK}
|
||||
db close
|
||||
|
||||
if {![sqlite3 -has-codec]} {
|
||||
# Test what happens when the library encounters a newer file format.
|
||||
@@ -507,7 +490,7 @@ if {![sqlite3 -has-codec]} {
|
||||
set ::bt [btree_open test.db 10 0]
|
||||
btree_begin_transaction $::bt
|
||||
set meta [btree_get_meta $::bt]
|
||||
lset meta 2 5
|
||||
lset meta 2 4
|
||||
eval [concat btree_update_meta $::bt [lrange $meta 0 end]]
|
||||
btree_commit $::bt
|
||||
btree_close $::bt
|
||||
@@ -627,8 +610,7 @@ foreach {code english} $code2english {
|
||||
if {[info command sqlite_malloc_stat]!=""} {
|
||||
set sqlite_malloc_fail 1
|
||||
do_test capi3-10-1 {
|
||||
sqlite3 db test.db
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
set ::DB [sqlite3 db test.db]
|
||||
sqlite_malloc_fail 1
|
||||
catchsql {
|
||||
select * from sqlite_master;
|
||||
@@ -649,8 +631,7 @@ sqlite_malloc_fail 0
|
||||
# The following tests - capi3-11.* - test that a COMMIT or ROLLBACK
|
||||
# statement issued while there are still outstanding VMs that are part of
|
||||
# the transaction fails.
|
||||
sqlite3 db test.db
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
set DB [sqlite3 db test.db]
|
||||
sqlite_register_test_function $DB func
|
||||
do_test capi3-11.1 {
|
||||
execsql {
|
||||
|
||||
+4
-4
@@ -13,16 +13,16 @@
|
||||
# particular the behavior of sqlite3_step() when trying to commit
|
||||
# with lock contention.
|
||||
#
|
||||
# $Id: capi3b.test,v 1.3 2006/01/03 00:33:50 drh Exp $
|
||||
# $Id: capi3b.test,v 1.2 2004/09/03 00:27:57 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
sqlite3 db2 test.db
|
||||
set DB2 [sqlite3_connection_pointer db2]
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
set DB2 [sqlite3 db2 test.db]
|
||||
|
||||
# Create some data in the database
|
||||
#
|
||||
|
||||
+5
-5
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the CAST operator.
|
||||
#
|
||||
# $Id: cast.test,v 1.3 2005/11/01 15:48:25 drh Exp $
|
||||
# $Id: cast.test,v 1.2 2005/06/25 19:31:48 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -38,10 +38,10 @@ do_test cast-1.4 {
|
||||
} text
|
||||
do_test cast-1.5 {
|
||||
execsql {SELECT CAST(x'616263' AS numeric)}
|
||||
} 0
|
||||
} 0.0
|
||||
do_test cast-1.6 {
|
||||
execsql {SELECT typeof(CAST(x'616263' AS numeric))}
|
||||
} integer
|
||||
} real
|
||||
do_test cast-1.7 {
|
||||
execsql {SELECT CAST(x'616263' AS blob)}
|
||||
} abc
|
||||
@@ -158,10 +158,10 @@ do_test cast-1.44 {
|
||||
} text
|
||||
do_test cast-1.45 {
|
||||
execsql {SELECT CAST('123abc' AS numeric)}
|
||||
} 123
|
||||
} 123.0
|
||||
do_test cast-1.46 {
|
||||
execsql {SELECT typeof(CAST('123abc' AS numeric))}
|
||||
} integer
|
||||
} real
|
||||
do_test cast-1.47 {
|
||||
execsql {SELECT CAST('123abc' AS blob)}
|
||||
} {123abc}
|
||||
|
||||
-298
@@ -1,298 +0,0 @@
|
||||
# 2005 November 2
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing CHECK constraints
|
||||
#
|
||||
# $Id: check.test,v 1.7 2006/01/14 08:02:28 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Only run these tests if the build includes support for CHECK constraints
|
||||
ifcapable !check {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_test check-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(
|
||||
x INTEGER CHECK( x<5 ),
|
||||
y REAL CHECK( y>x )
|
||||
);
|
||||
}
|
||||
} {}
|
||||
do_test check-1.2 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(3,4);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {3 4.0}
|
||||
do_test check-1.3 {
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(6,7);
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test check-1.4 {
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {3 4.0}
|
||||
do_test check-1.5 {
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(4,3);
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test check-1.6 {
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {3 4.0}
|
||||
do_test check-1.7 {
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(NULL,6);
|
||||
}
|
||||
} {0 {}}
|
||||
do_test check-1.8 {
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {3 4.0 {} 6.0}
|
||||
do_test check-1.9 {
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(2,NULL);
|
||||
}
|
||||
} {0 {}}
|
||||
do_test check-1.10 {
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {3 4.0 {} 6.0 2 {}}
|
||||
do_test check-1.11 {
|
||||
execsql {
|
||||
DELETE FROM t1 WHERE x IS NULL OR x!=3;
|
||||
UPDATE t1 SET x=2 WHERE x==3;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {2 4.0}
|
||||
do_test check-1.12 {
|
||||
catchsql {
|
||||
UPDATE t1 SET x=7 WHERE x==2
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test check-1.13 {
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {2 4.0}
|
||||
do_test check-1.14 {
|
||||
catchsql {
|
||||
UPDATE t1 SET x=5 WHERE x==2
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test check-1.15 {
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {2 4.0}
|
||||
do_test check-1.16 {
|
||||
catchsql {
|
||||
UPDATE t1 SET x=4, y=11 WHERE x==2
|
||||
}
|
||||
} {0 {}}
|
||||
do_test check-1.17 {
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {4 11.0}
|
||||
|
||||
do_test check-2.1 {
|
||||
execsql {
|
||||
CREATE TABLE t2(
|
||||
x INTEGER CHECK( typeof(coalesce(x,0))=="integer" ),
|
||||
y REAL CHECK( typeof(coalesce(y,0.1))=="real" ),
|
||||
z TEXT CHECK( typeof(coalesce(z,''))=="text" )
|
||||
);
|
||||
}
|
||||
} {}
|
||||
do_test check-2.2 {
|
||||
execsql {
|
||||
INSERT INTO t2 VALUES(1,2.2,'three');
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 2.2 three}
|
||||
do_test check-2.3 {
|
||||
execsql {
|
||||
INSERT INTO t2 VALUES(NULL, NULL, NULL);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 2.2 three {} {} {}}
|
||||
do_test check-2.4 {
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(1.1, NULL, NULL);
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test check-2.5 {
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(NULL, 5, NULL);
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test check-2.6 {
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(NULL, NULL, 3.14159);
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
|
||||
ifcapable subquery {
|
||||
do_test check-3.1 {
|
||||
catchsql {
|
||||
CREATE TABLE t3(
|
||||
x, y, z,
|
||||
CHECK( x<(SELECT min(x) FROM t1) )
|
||||
);
|
||||
}
|
||||
} {1 {subqueries prohibited in CHECK constraints}}
|
||||
}
|
||||
|
||||
do_test check-3.2 {
|
||||
execsql {
|
||||
SELECT name FROM sqlite_master ORDER BY name
|
||||
}
|
||||
} {t1 t2}
|
||||
do_test check-3.3 {
|
||||
catchsql {
|
||||
CREATE TABLE t3(
|
||||
x, y, z,
|
||||
CHECK( q<x )
|
||||
);
|
||||
}
|
||||
} {1 {no such column: q}}
|
||||
do_test check-3.4 {
|
||||
execsql {
|
||||
SELECT name FROM sqlite_master ORDER BY name
|
||||
}
|
||||
} {t1 t2}
|
||||
do_test check-3.5 {
|
||||
catchsql {
|
||||
CREATE TABLE t3(
|
||||
x, y, z,
|
||||
CHECK( t2.x<x )
|
||||
);
|
||||
}
|
||||
} {1 {no such column: t2.x}}
|
||||
do_test check-3.6 {
|
||||
execsql {
|
||||
SELECT name FROM sqlite_master ORDER BY name
|
||||
}
|
||||
} {t1 t2}
|
||||
do_test check-3.7 {
|
||||
catchsql {
|
||||
CREATE TABLE t3(
|
||||
x, y, z,
|
||||
CHECK( t3.x<25 )
|
||||
);
|
||||
}
|
||||
} {0 {}}
|
||||
do_test check-3.8 {
|
||||
execsql {
|
||||
INSERT INTO t3 VALUES(1,2,3);
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1 2 3}
|
||||
do_test check-3.9 {
|
||||
catchsql {
|
||||
INSERT INTO t3 VALUES(111,222,333);
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
|
||||
do_test check-4.1 {
|
||||
execsql {
|
||||
CREATE TABLE t4(x, y,
|
||||
CHECK (
|
||||
x+y==11
|
||||
OR x*y==12
|
||||
OR x/y BETWEEN 5 AND 8
|
||||
OR -x==y+10
|
||||
)
|
||||
);
|
||||
}
|
||||
} {}
|
||||
do_test check-4.2 {
|
||||
execsql {
|
||||
INSERT INTO t4 VALUES(1,10);
|
||||
SELECT * FROM t4
|
||||
}
|
||||
} {1 10}
|
||||
do_test check-4.3 {
|
||||
execsql {
|
||||
UPDATE t4 SET x=4, y=3;
|
||||
SELECT * FROM t4
|
||||
}
|
||||
} {4 3}
|
||||
do_test check-4.3 {
|
||||
execsql {
|
||||
UPDATE t4 SET x=12, y=2;
|
||||
SELECT * FROM t4
|
||||
}
|
||||
} {12 2}
|
||||
do_test check-4.4 {
|
||||
execsql {
|
||||
UPDATE t4 SET x=12, y=-22;
|
||||
SELECT * FROM t4
|
||||
}
|
||||
} {12 -22}
|
||||
do_test check-4.5 {
|
||||
catchsql {
|
||||
UPDATE t4 SET x=0, y=1;
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test check-4.6 {
|
||||
execsql {
|
||||
SELECT * FROM t4;
|
||||
}
|
||||
} {12 -22}
|
||||
do_test check-4.7 {
|
||||
execsql {
|
||||
PRAGMA ignore_check_constraints=ON;
|
||||
UPDATE t4 SET x=0, y=1;
|
||||
SELECT * FROM t4;
|
||||
}
|
||||
} {0 1}
|
||||
do_test check-4.8 {
|
||||
catchsql {
|
||||
PRAGMA ignore_check_constraints=OFF;
|
||||
UPDATE t4 SET x=0, y=2;
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test check_4.9 {
|
||||
catchsql {
|
||||
VACUUM
|
||||
}
|
||||
} {0 {}}
|
||||
|
||||
do_test check-5.1 {
|
||||
catchsql {
|
||||
CREATE TABLE t5(x, y,
|
||||
CHECK( x*y<:abc )
|
||||
);
|
||||
}
|
||||
} {1 {parameters prohibited in CHECK constraints}}
|
||||
do_test check-5.2 {
|
||||
catchsql {
|
||||
CREATE TABLE t5(x, y,
|
||||
CHECK( x*y<? )
|
||||
);
|
||||
}
|
||||
} {1 {parameters prohibited in CHECK constraints}}
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
+2
-2
@@ -12,7 +12,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is page cache subsystem.
|
||||
#
|
||||
# $Id: collate1.test,v 1.4 2005/11/01 15:48:25 drh Exp $
|
||||
# $Id: collate1.test,v 1.3 2004/08/20 18:34:20 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -214,7 +214,7 @@ do_test collate1-4.3 {
|
||||
execsql {
|
||||
SELECT c2+0 FROM collate1t1 ORDER BY 1;
|
||||
}
|
||||
} {{} 1 12 101}
|
||||
} {{} 1.0 12.0 101.0}
|
||||
do_test collate1-4.4 {
|
||||
execsql {
|
||||
SELECT c1||'' FROM collate1t1 ORDER BY 1;
|
||||
|
||||
+1
-2
@@ -13,7 +13,7 @@
|
||||
# This file implements tests for the conflict resolution extension
|
||||
# to SQLite.
|
||||
#
|
||||
# $Id: conflict.test,v 1.26 2005/09/25 01:13:09 drh Exp $
|
||||
# $Id: conflict.test,v 1.25 2005/09/01 03:07:45 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -302,7 +302,6 @@ foreach {i conf1 cmd t0 t1 t2 t3} {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
|
||||
execsql {pragma temp_store=file}
|
||||
set ::sqlite_opentemp_count 0
|
||||
set r0 [catch {execsql [subst {
|
||||
DROP TABLE t1;
|
||||
|
||||
+9
-11
@@ -12,21 +12,19 @@
|
||||
#
|
||||
# The focus of this file is testing the ability of the database to
|
||||
# uses its rollback journal to recover intact (no database corruption)
|
||||
# from a power failure during the middle of a COMMIT. The OS interface
|
||||
# modules are overloaded in a separate instance of testfixture using
|
||||
# the modified I/O routines found in test6.c. These routines allow us
|
||||
# to simulate the kind of file damage that occurs after a power failure.
|
||||
# from a power failure during the middle of a COMMIT. The special test
|
||||
# module "crashtest" compiled with the special "os_test.c" backend is used.
|
||||
# The os_test.c simulates the kind of file corruption that can occur
|
||||
# when writes are happening at the moment of power loss.
|
||||
#
|
||||
# The special crash-test module with its os_test.c backend only works
|
||||
# on Unix.
|
||||
#
|
||||
# $Id: crash.test,v 1.21 2006/01/06 14:32:20 drh Exp $
|
||||
# $Id: crash.test,v 1.19 2005/09/17 17:05:19 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
ifcapable !crashtest {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# set repeats 100
|
||||
set repeats 10
|
||||
|
||||
@@ -64,7 +62,7 @@ proc crashsql {crashdelay crashfile sql} {
|
||||
close $f
|
||||
|
||||
set r [catch {
|
||||
exec [info nameofexec] crash.tcl >@stdout
|
||||
exec [file join . crashtest] crash.tcl >@stdout
|
||||
} msg]
|
||||
lappend r $msg
|
||||
}
|
||||
|
||||
+6
-6
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing date and time functions.
|
||||
#
|
||||
# $Id: date.test,v 1.14 2006/01/09 00:18:03 drh Exp $
|
||||
# $Id: date.test,v 1.13 2005/03/21 00:43:44 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -142,11 +142,11 @@ datetest 3.17 "strftime('[repeat 200 abc%m123]','2003-10-31')" \
|
||||
set now [clock format [clock seconds] -format "%Y-%m-%d" -gmt 1]
|
||||
datetest 4.1 {date('now')} $now
|
||||
|
||||
datetest 5.1 {datetime('1994-04-16 14:00:00 +05:00')} {1994-04-16 09:00:00}
|
||||
datetest 5.2 {datetime('1994-04-16 14:00:00 -05:15')} {1994-04-16 19:15:00}
|
||||
datetest 5.3 {datetime('1994-04-16 05:00:00 +08:30')} {1994-04-15 20:30:00}
|
||||
datetest 5.4 {datetime('1994-04-16 14:00:00 -11:55')} {1994-04-17 01:55:00}
|
||||
datetest 5.5 {datetime('1994-04-16 14:00:00 -11:60')} NULL
|
||||
datetest 5.1 {datetime('1994-04-16 14:00:00 -05:00')} {1994-04-16 09:00:00}
|
||||
datetest 5.2 {datetime('1994-04-16 14:00:00 +05:15')} {1994-04-16 19:15:00}
|
||||
datetest 5.3 {datetime('1994-04-16 05:00:00 -08:30')} {1994-04-15 20:30:00}
|
||||
datetest 5.4 {datetime('1994-04-16 14:00:00 +11:55')} {1994-04-17 01:55:00}
|
||||
datetest 5.5 {datetime('1994-04-16 14:00:00 +11:60')} NULL
|
||||
|
||||
# localtime->utc and utc->localtime conversions. These tests only work
|
||||
# if the localtime is in the US Eastern Time (the time in Charlotte, NC
|
||||
|
||||
+2
-6
@@ -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.21 2006/01/03 00:33:50 drh Exp $
|
||||
# $Id: delete.test,v 1.19 2005/05/27 09:41:13 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -49,9 +49,6 @@ do_test delete-3.1.3 {
|
||||
do_test delete-3.1.4 {
|
||||
execsql {CREATE INDEX index1 ON table1(f1)}
|
||||
execsql {PRAGMA count_changes=on}
|
||||
ifcapable explain {
|
||||
execsql {EXPLAIN DELETE FROM table1 WHERE f1=3}
|
||||
}
|
||||
execsql {DELETE FROM 'table1' WHERE f1=3}
|
||||
} {0}
|
||||
do_test delete-3.1.5 {
|
||||
@@ -277,8 +274,7 @@ do_test delete-8.0 {
|
||||
db close
|
||||
catch {file attributes test.db -permissions 0444}
|
||||
catch {file attributes test.db -readonly 1}
|
||||
sqlite3 db test.db
|
||||
set ::DB [sqlite3_connection_pointer db]
|
||||
set ::DB [sqlite3 db test.db]
|
||||
do_test delete-8.1 {
|
||||
catchsql {
|
||||
DELETE FROM t3;
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@
|
||||
# The solution to the problem was to detect that the table is locked
|
||||
# before the index entry is deleted.
|
||||
#
|
||||
# $Id: delete2.test,v 1.6 2006/01/05 11:34:34 danielk1977 Exp $
|
||||
# $Id: delete2.test,v 1.4 2004/11/22 10:02:23 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -38,7 +38,8 @@ source $testdir/tester.tcl
|
||||
# Create a table that has an index.
|
||||
#
|
||||
do_test delete2-1.1 {
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
execsql {
|
||||
CREATE TABLE q(s string, id string, constraint pk_q primary key(id));
|
||||
BEGIN;
|
||||
@@ -67,7 +68,6 @@ integrity_check delete2-1.5
|
||||
|
||||
# Try to delete a row from the table. The delete should fail.
|
||||
#
|
||||
breakpoint
|
||||
do_test delete2-1.6 {
|
||||
catchsql {
|
||||
DELETE FROM q WHERE rowid=1
|
||||
|
||||
@@ -1,311 +0,0 @@
|
||||
# 2005 December 21
|
||||
#
|
||||
# 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 descending indices.
|
||||
#
|
||||
# $Id: descidx1.test,v 1.4 2006/01/12 01:56:44 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# This procedure sets the value of the file-format in file 'test.db'
|
||||
# to $newval. Also, the schema cookie is incremented.
|
||||
#
|
||||
proc set_file_format {newval} {
|
||||
set bt [btree_open test.db 10 0]
|
||||
btree_begin_transaction $bt
|
||||
set meta [btree_get_meta $bt]
|
||||
lset meta 2 $newval ;# File format
|
||||
lset meta 1 [expr [lindex $meta 1]+1] ;# Schema cookie
|
||||
eval "btree_update_meta $bt $meta"
|
||||
btree_commit $bt
|
||||
btree_close $bt
|
||||
}
|
||||
|
||||
# This procedure returns the value of the file-format in file 'test.db'.
|
||||
#
|
||||
proc get_file_format {{fname test.db}} {
|
||||
set bt [btree_open $fname 10 0]
|
||||
set meta [btree_get_meta $bt]
|
||||
btree_close $bt
|
||||
lindex $meta 2
|
||||
}
|
||||
|
||||
# Verify that the file format starts as 4.
|
||||
#
|
||||
do_test descidx1-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b);
|
||||
CREATE INDEX i1 ON t1(b ASC);
|
||||
}
|
||||
get_file_format
|
||||
} {4}
|
||||
do_test descidx1-1.2 {
|
||||
execsql {
|
||||
CREATE INDEX i2 ON t1(a DESC);
|
||||
}
|
||||
get_file_format
|
||||
} {4}
|
||||
|
||||
# Put some information in the table and verify that the descending
|
||||
# index actually works.
|
||||
#
|
||||
do_test descidx1-2.1 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(1,1);
|
||||
INSERT INTO t1 VALUES(2,2);
|
||||
INSERT INTO t1 SELECT a+2, a+2 FROM t1;
|
||||
INSERT INTO t1 SELECT a+4, a+4 FROM t1;
|
||||
SELECT b FROM t1 WHERE a>3 AND a<7;
|
||||
}
|
||||
} {6 5 4}
|
||||
do_test descidx1-2.2 {
|
||||
execsql {
|
||||
SELECT a FROM t1 WHERE b>3 AND b<7;
|
||||
}
|
||||
} {4 5 6}
|
||||
do_test descidx1-2.3 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a>=3 AND a<7;
|
||||
}
|
||||
} {6 5 4 3}
|
||||
do_test descidx1-2.4 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a>3 AND a<=7;
|
||||
}
|
||||
} {7 6 5 4}
|
||||
do_test descidx1-2.5 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a>=3 AND a<=7;
|
||||
}
|
||||
} {7 6 5 4 3}
|
||||
do_test descidx1-2.6 {
|
||||
execsql {
|
||||
SELECT a FROM t1 WHERE b>=3 AND b<=7;
|
||||
}
|
||||
} {3 4 5 6 7}
|
||||
|
||||
# This procedure executes the SQL. Then it checks to see if the OP_Sort
|
||||
# opcode was executed. If an OP_Sort did occur, then "sort" is appended
|
||||
# to the result. If no OP_Sort happened, then "nosort" is appended.
|
||||
#
|
||||
# This procedure is used to check to make sure sorting is or is not
|
||||
# occurring as expected.
|
||||
#
|
||||
proc cksort {sql} {
|
||||
set ::sqlite_sort_count 0
|
||||
set data [execsql $sql]
|
||||
if {$::sqlite_sort_count} {set x sort} {set x nosort}
|
||||
lappend data $x
|
||||
return $data
|
||||
}
|
||||
|
||||
# Test sorting using a descending index.
|
||||
#
|
||||
do_test descidx1-3.1 {
|
||||
cksort {SELECT a FROM t1 ORDER BY a}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx1-3.2 {
|
||||
cksort {SELECT a FROM t1 ORDER BY a ASC}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx1-3.3 {
|
||||
cksort {SELECT a FROM t1 ORDER BY a DESC}
|
||||
} {8 7 6 5 4 3 2 1 nosort}
|
||||
do_test descidx1-3.4 {
|
||||
cksort {SELECT b FROM t1 ORDER BY a}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx1-3.5 {
|
||||
cksort {SELECT b FROM t1 ORDER BY a ASC}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx1-3.6 {
|
||||
cksort {SELECT b FROM t1 ORDER BY a DESC}
|
||||
} {8 7 6 5 4 3 2 1 nosort}
|
||||
do_test descidx1-3.7 {
|
||||
cksort {SELECT a FROM t1 ORDER BY b}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx1-3.8 {
|
||||
cksort {SELECT a FROM t1 ORDER BY b ASC}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx1-3.9 {
|
||||
cksort {SELECT a FROM t1 ORDER BY b DESC}
|
||||
} {8 7 6 5 4 3 2 1 nosort}
|
||||
do_test descidx1-3.10 {
|
||||
cksort {SELECT b FROM t1 ORDER BY b}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx1-3.11 {
|
||||
cksort {SELECT b FROM t1 ORDER BY b ASC}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx1-3.12 {
|
||||
cksort {SELECT b FROM t1 ORDER BY b DESC}
|
||||
} {8 7 6 5 4 3 2 1 nosort}
|
||||
|
||||
do_test descidx1-3.21 {
|
||||
cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a}
|
||||
} {4 5 6 7 nosort}
|
||||
do_test descidx1-3.22 {
|
||||
cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC}
|
||||
} {4 5 6 7 nosort}
|
||||
do_test descidx1-3.23 {
|
||||
cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC}
|
||||
} {7 6 5 4 nosort}
|
||||
do_test descidx1-3.24 {
|
||||
cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a}
|
||||
} {4 5 6 7 nosort}
|
||||
do_test descidx1-3.25 {
|
||||
cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC}
|
||||
} {4 5 6 7 nosort}
|
||||
do_test descidx1-3.26 {
|
||||
cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC}
|
||||
} {7 6 5 4 nosort}
|
||||
|
||||
# Create a table with indices that are descending on some terms and
|
||||
# ascending on others.
|
||||
#
|
||||
do_test descidx1-4.1 {
|
||||
execsql {
|
||||
CREATE TABLE t2(a INT, b TEXT, c BLOB, d REAL);
|
||||
CREATE INDEX i3 ON t2(a ASC, b DESC, c ASC);
|
||||
CREATE INDEX i4 ON t2(b DESC, a ASC, d DESC);
|
||||
INSERT INTO t2 VALUES(1,'one',x'31',1.0);
|
||||
INSERT INTO t2 VALUES(2,'two',x'3232',2.0);
|
||||
INSERT INTO t2 VALUES(3,'three',x'333333',3.0);
|
||||
INSERT INTO t2 VALUES(4,'four',x'34343434',4.0);
|
||||
INSERT INTO t2 VALUES(5,'five',x'3535353535',5.0);
|
||||
INSERT INTO t2 VALUES(6,'six',x'363636363636',6.0);
|
||||
INSERT INTO t2 VALUES(2,'two',x'323232',2.1);
|
||||
INSERT INTO t2 VALUES(2,'zwei',x'3232',2.2);
|
||||
INSERT INTO t2 VALUES(2,NULL,NULL,2.3);
|
||||
SELECT count(*) FROM t2;
|
||||
}
|
||||
} {9}
|
||||
do_test descidx1-4.2 {
|
||||
execsql {
|
||||
SELECT d FROM t2 ORDER BY a;
|
||||
}
|
||||
} {1.0 2.2 2.0 2.1 2.3 3.0 4.0 5.0 6.0}
|
||||
do_test descidx1-4.3 {
|
||||
execsql {
|
||||
SELECT d FROM t2 WHERE a>=2;
|
||||
}
|
||||
} {2.2 2.0 2.1 2.3 3.0 4.0 5.0 6.0}
|
||||
do_test descidx1-4.4 {
|
||||
execsql {
|
||||
SELECT d FROM t2 WHERE a>2;
|
||||
}
|
||||
} {3.0 4.0 5.0 6.0}
|
||||
do_test descidx1-4.5 {
|
||||
execsql {
|
||||
SELECT d FROM t2 WHERE a=2 AND b>'two';
|
||||
}
|
||||
} {2.2}
|
||||
do_test descidx1-4.6 {
|
||||
execsql {
|
||||
SELECT d FROM t2 WHERE a=2 AND b>='two';
|
||||
}
|
||||
} {2.2 2.0 2.1}
|
||||
do_test descidx1-4.7 {
|
||||
execsql {
|
||||
SELECT d FROM t2 WHERE a=2 AND b<'two';
|
||||
}
|
||||
} {}
|
||||
do_test descidx1-4.8 {
|
||||
execsql {
|
||||
SELECT d FROM t2 WHERE a=2 AND b<='two';
|
||||
}
|
||||
} {2.0 2.1}
|
||||
|
||||
do_test descidx1-5.1 {
|
||||
execsql {
|
||||
CREATE TABLE t3(a,b,c,d);
|
||||
CREATE INDEX t3i1 ON t3(a DESC, b ASC, c DESC, d ASC);
|
||||
INSERT INTO t3 VALUES(0,0,0,0);
|
||||
INSERT INTO t3 VALUES(0,0,0,1);
|
||||
INSERT INTO t3 VALUES(0,0,1,0);
|
||||
INSERT INTO t3 VALUES(0,0,1,1);
|
||||
INSERT INTO t3 VALUES(0,1,0,0);
|
||||
INSERT INTO t3 VALUES(0,1,0,1);
|
||||
INSERT INTO t3 VALUES(0,1,1,0);
|
||||
INSERT INTO t3 VALUES(0,1,1,1);
|
||||
INSERT INTO t3 VALUES(1,0,0,0);
|
||||
INSERT INTO t3 VALUES(1,0,0,1);
|
||||
INSERT INTO t3 VALUES(1,0,1,0);
|
||||
INSERT INTO t3 VALUES(1,0,1,1);
|
||||
INSERT INTO t3 VALUES(1,1,0,0);
|
||||
INSERT INTO t3 VALUES(1,1,0,1);
|
||||
INSERT INTO t3 VALUES(1,1,1,0);
|
||||
INSERT INTO t3 VALUES(1,1,1,1);
|
||||
SELECT count(*) FROM t3;
|
||||
}
|
||||
} {16}
|
||||
do_test descidx1-5.2 {
|
||||
cksort {
|
||||
SELECT a||b||c||d FROM t3 ORDER BY a,b,c,d;
|
||||
}
|
||||
} {0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 sort}
|
||||
do_test descidx1-5.3 {
|
||||
cksort {
|
||||
SELECT a||b||c||d FROM t3 ORDER BY a DESC, b ASC, c DESC, d ASC;
|
||||
}
|
||||
} {1010 1011 1000 1001 1110 1111 1100 1101 0010 0011 0000 0001 0110 0111 0100 0101 nosort}
|
||||
do_test descidx1-5.4 {
|
||||
cksort {
|
||||
SELECT a||b||c||d FROM t3 ORDER BY a ASC, b DESC, c ASC, d DESC;
|
||||
}
|
||||
} {0101 0100 0111 0110 0001 0000 0011 0010 1101 1100 1111 1110 1001 1000 1011 1010 nosort}
|
||||
do_test descidx1-5.5 {
|
||||
cksort {
|
||||
SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a DESC, b ASC, c DESC
|
||||
}
|
||||
} {101 100 111 110 001 000 011 010 nosort}
|
||||
do_test descidx1-5.6 {
|
||||
cksort {
|
||||
SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a ASC, b DESC, c ASC
|
||||
}
|
||||
} {010 011 000 001 110 111 100 101 nosort}
|
||||
do_test descidx1-5.7 {
|
||||
cksort {
|
||||
SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a ASC, b DESC, c DESC
|
||||
}
|
||||
} {011 010 001 000 111 110 101 100 sort}
|
||||
do_test descidx1-5.8 {
|
||||
cksort {
|
||||
SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a ASC, b ASC, c ASC
|
||||
}
|
||||
} {000 001 010 011 100 101 110 111 sort}
|
||||
do_test descidx1-5.9 {
|
||||
cksort {
|
||||
SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a DESC, b DESC, c ASC
|
||||
}
|
||||
} {110 111 100 101 010 011 000 001 sort}
|
||||
|
||||
# Test the legacy_file_format pragma here because we have access to
|
||||
# the get_file_format command.
|
||||
#
|
||||
do_test descidx1-6.1 {
|
||||
db close
|
||||
file delete -force test.db test.db-journal
|
||||
sqlite3 db test.db
|
||||
execsql {PRAGMA legacy_file_format}
|
||||
} {0}
|
||||
do_test descidx1-6.2 {
|
||||
execsql {PRAGMA legacy_file_format=YES}
|
||||
execsql {PRAGMA legacy_file_format}
|
||||
} {1}
|
||||
do_test descidx1-6.3 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b,c);
|
||||
}
|
||||
get_file_format
|
||||
} {1}
|
||||
|
||||
|
||||
finish_test
|
||||
@@ -1,182 +0,0 @@
|
||||
# 2005 December 21
|
||||
#
|
||||
# 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 descending indices.
|
||||
#
|
||||
# $Id: descidx2.test,v 1.2 2005/12/29 19:23:07 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# This procedure sets the value of the file-format in file 'test.db'
|
||||
# to $newval. Also, the schema cookie is incremented.
|
||||
#
|
||||
proc set_file_format {newval} {
|
||||
set bt [btree_open test.db 10 0]
|
||||
btree_begin_transaction $bt
|
||||
set meta [btree_get_meta $bt]
|
||||
lset meta 2 $newval ;# File format
|
||||
lset meta 1 [expr [lindex $meta 1]+1] ;# Schema cookie
|
||||
eval "btree_update_meta $bt $meta"
|
||||
btree_commit $bt
|
||||
btree_close $bt
|
||||
}
|
||||
|
||||
# This procedure returns the value of the file-format in file 'test.db'.
|
||||
#
|
||||
proc get_file_format {{fname test.db}} {
|
||||
set bt [btree_open $fname 10 0]
|
||||
set meta [btree_get_meta $bt]
|
||||
btree_close $bt
|
||||
lindex $meta 2
|
||||
}
|
||||
|
||||
# Verify that the file format starts as 4
|
||||
#
|
||||
do_test descidx2-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b);
|
||||
CREATE INDEX i1 ON t1(b ASC);
|
||||
}
|
||||
get_file_format
|
||||
} {4}
|
||||
do_test descidx2-1.2 {
|
||||
execsql {
|
||||
CREATE INDEX i2 ON t1(a DESC);
|
||||
}
|
||||
get_file_format
|
||||
} {4}
|
||||
|
||||
# Before adding any information to the database, set the file format
|
||||
# back to three. Then close and reopen the database. With the file
|
||||
# format set to three, SQLite should ignore the DESC argument on the
|
||||
# index.
|
||||
#
|
||||
do_test descidx2-2.0 {
|
||||
set_file_format 3
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
get_file_format
|
||||
} {3}
|
||||
|
||||
# Put some information in the table and verify that the DESC
|
||||
# on the index is ignored.
|
||||
#
|
||||
do_test descidx2-2.1 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(1,1);
|
||||
INSERT INTO t1 VALUES(2,2);
|
||||
INSERT INTO t1 SELECT a+2, a+2 FROM t1;
|
||||
INSERT INTO t1 SELECT a+4, a+4 FROM t1;
|
||||
SELECT b FROM t1 WHERE a>3 AND a<7;
|
||||
}
|
||||
} {4 5 6}
|
||||
do_test descidx2-2.2 {
|
||||
execsql {
|
||||
SELECT a FROM t1 WHERE b>3 AND b<7;
|
||||
}
|
||||
} {4 5 6}
|
||||
do_test descidx2-2.3 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a>=3 AND a<7;
|
||||
}
|
||||
} {3 4 5 6}
|
||||
do_test descidx2-2.4 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a>3 AND a<=7;
|
||||
}
|
||||
} {4 5 6 7}
|
||||
do_test descidx2-2.5 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a>=3 AND a<=7;
|
||||
}
|
||||
} {3 4 5 6 7}
|
||||
do_test descidx2-2.6 {
|
||||
execsql {
|
||||
SELECT a FROM t1 WHERE b>=3 AND b<=7;
|
||||
}
|
||||
} {3 4 5 6 7}
|
||||
|
||||
# This procedure executes the SQL. Then it checks to see if the OP_Sort
|
||||
# opcode was executed. If an OP_Sort did occur, then "sort" is appended
|
||||
# to the result. If no OP_Sort happened, then "nosort" is appended.
|
||||
#
|
||||
# This procedure is used to check to make sure sorting is or is not
|
||||
# occurring as expected.
|
||||
#
|
||||
proc cksort {sql} {
|
||||
set ::sqlite_sort_count 0
|
||||
set data [execsql $sql]
|
||||
if {$::sqlite_sort_count} {set x sort} {set x nosort}
|
||||
lappend data $x
|
||||
return $data
|
||||
}
|
||||
|
||||
# Test sorting using a descending index.
|
||||
#
|
||||
do_test descidx2-3.1 {
|
||||
cksort {SELECT a FROM t1 ORDER BY a}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx2-3.2 {
|
||||
cksort {SELECT a FROM t1 ORDER BY a ASC}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx2-3.3 {
|
||||
cksort {SELECT a FROM t1 ORDER BY a DESC}
|
||||
} {8 7 6 5 4 3 2 1 nosort}
|
||||
do_test descidx2-3.4 {
|
||||
cksort {SELECT b FROM t1 ORDER BY a}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx2-3.5 {
|
||||
cksort {SELECT b FROM t1 ORDER BY a ASC}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx2-3.6 {
|
||||
cksort {SELECT b FROM t1 ORDER BY a DESC}
|
||||
} {8 7 6 5 4 3 2 1 nosort}
|
||||
do_test descidx2-3.7 {
|
||||
cksort {SELECT a FROM t1 ORDER BY b}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx2-3.8 {
|
||||
cksort {SELECT a FROM t1 ORDER BY b ASC}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx2-3.9 {
|
||||
cksort {SELECT a FROM t1 ORDER BY b DESC}
|
||||
} {8 7 6 5 4 3 2 1 nosort}
|
||||
do_test descidx2-3.10 {
|
||||
cksort {SELECT b FROM t1 ORDER BY b}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx2-3.11 {
|
||||
cksort {SELECT b FROM t1 ORDER BY b ASC}
|
||||
} {1 2 3 4 5 6 7 8 nosort}
|
||||
do_test descidx2-3.12 {
|
||||
cksort {SELECT b FROM t1 ORDER BY b DESC}
|
||||
} {8 7 6 5 4 3 2 1 nosort}
|
||||
|
||||
do_test descidx2-3.21 {
|
||||
cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a}
|
||||
} {4 5 6 7 nosort}
|
||||
do_test descidx2-3.22 {
|
||||
cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC}
|
||||
} {4 5 6 7 nosort}
|
||||
do_test descidx2-3.23 {
|
||||
cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC}
|
||||
} {7 6 5 4 nosort}
|
||||
do_test descidx2-3.24 {
|
||||
cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a}
|
||||
} {4 5 6 7 nosort}
|
||||
do_test descidx2-3.25 {
|
||||
cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC}
|
||||
} {4 5 6 7 nosort}
|
||||
do_test descidx2-3.26 {
|
||||
cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC}
|
||||
} {7 6 5 4 nosort}
|
||||
|
||||
finish_test
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user