Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d6ae89c21 | |||
| 68c7fdb7c1 | |||
| 93dc177980 | |||
| 9513fc97a8 | |||
| 07444ecf8c | |||
| 6d373c89e0 |
+11
-16
@@ -180,7 +180,7 @@ LIBOBJS0 = alter.lo analyze.lo attach.lo auth.lo \
|
||||
fts3_unicode.lo fts3_unicode2.lo fts3_write.lo \
|
||||
fts5.lo \
|
||||
func.lo global.lo hash.lo \
|
||||
icu.lo insert.lo json.lo legacy.lo loadext.lo \
|
||||
icu.lo insert.lo json1.lo legacy.lo loadext.lo \
|
||||
main.lo malloc.lo mem0.lo mem1.lo mem2.lo mem3.lo mem5.lo \
|
||||
memdb.lo memjournal.lo \
|
||||
mutex.lo mutex_noop.lo mutex_unix.lo mutex_w32.lo \
|
||||
@@ -234,7 +234,6 @@ SRC = \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/hwtime.h \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/json.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/loadext.c \
|
||||
$(TOP)/src/main.c \
|
||||
@@ -367,6 +366,7 @@ SRC += \
|
||||
$(TOP)/ext/rbu/sqlite3rbu.h \
|
||||
$(TOP)/ext/rbu/sqlite3rbu.c
|
||||
SRC += \
|
||||
$(TOP)/ext/misc/json1.c \
|
||||
$(TOP)/ext/misc/stmt.c
|
||||
|
||||
# Generated source code files
|
||||
@@ -460,7 +460,6 @@ TESTSRC += \
|
||||
$(TOP)/ext/misc/normalize.c \
|
||||
$(TOP)/ext/misc/percentile.c \
|
||||
$(TOP)/ext/misc/prefixes.c \
|
||||
$(TOP)/ext/misc/qpvtab.c \
|
||||
$(TOP)/ext/misc/regexp.c \
|
||||
$(TOP)/ext/misc/remember.c \
|
||||
$(TOP)/ext/misc/series.c \
|
||||
@@ -469,8 +468,7 @@ TESTSRC += \
|
||||
$(TOP)/ext/misc/unionvtab.c \
|
||||
$(TOP)/ext/misc/wholenumber.c \
|
||||
$(TOP)/ext/misc/zipfile.c \
|
||||
$(TOP)/ext/userauth/userauth.c \
|
||||
$(TOP)/ext/rtree/test_rtreedoc.c
|
||||
$(TOP)/ext/userauth/userauth.c
|
||||
|
||||
# Source code to the library files needed by the test fixture
|
||||
#
|
||||
@@ -609,7 +607,7 @@ TESTOPTS = --verbose=file --output=test-out.txt
|
||||
|
||||
# Extra compiler options for various shell tools
|
||||
#
|
||||
SHELL_OPT = -DSQLITE_ENABLE_FTS4
|
||||
SHELL_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4
|
||||
#SHELL_OPT += -DSQLITE_ENABLE_FTS5
|
||||
SHELL_OPT += -DSQLITE_ENABLE_RTREE
|
||||
SHELL_OPT += -DSQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
@@ -619,13 +617,13 @@ SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
FUZZERSHELL_OPT =
|
||||
FUZZCHECK_OPT = -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
|
||||
FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
|
||||
FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
|
||||
FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
|
||||
FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS3_PARENTHESIS
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS5
|
||||
#FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS5
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
@@ -874,9 +872,6 @@ hash.lo: $(TOP)/src/hash.c $(HDR)
|
||||
insert.lo: $(TOP)/src/insert.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/insert.c
|
||||
|
||||
json.lo: $(TOP)/src/json.c
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/json.c
|
||||
|
||||
legacy.lo: $(TOP)/src/legacy.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/legacy.c
|
||||
|
||||
@@ -1180,6 +1175,9 @@ userauth.lo: $(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR)
|
||||
sqlite3session.lo: $(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR)
|
||||
$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/session/sqlite3session.c
|
||||
|
||||
json1.lo: $(TOP)/ext/misc/json1.c
|
||||
$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/json1.c
|
||||
|
||||
stmt.lo: $(TOP)/ext/misc/stmt.c
|
||||
$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/stmt.c
|
||||
|
||||
@@ -1252,10 +1250,7 @@ coretestprogs: $(TESTPROGS)
|
||||
testprogs: coretestprogs srcck1$(BEXE) fuzzcheck$(TEXE) sessionfuzz$(TEXE)
|
||||
|
||||
# A very detailed test running most or all test cases
|
||||
fulltest: alltest fuzztest
|
||||
|
||||
# Run most or all tcl test cases
|
||||
alltest: $(TESTPROGS)
|
||||
fulltest: $(TESTPROGS) fuzztest
|
||||
./testfixture$(TEXE) $(TOP)/test/all.test $(TESTOPTS)
|
||||
|
||||
# Really really long testing
|
||||
|
||||
+18
-25
@@ -363,6 +363,7 @@ SQLITE_TCL_DEP =
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS3=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RTREE=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_GEOPOLY=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_JSON1=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
|
||||
@@ -579,17 +580,17 @@ RCC = $(RC) -DSQLITE_OS_WIN=1 -I. -I$(TOP) -I$(TOP)\src $(RCOPTS) $(RCCOPTS)
|
||||
#
|
||||
!IF $(USE_STDCALL)!=0 || $(FOR_WIN10)!=0
|
||||
!IF "$(PLATFORM)"=="x86"
|
||||
CORE_CCONV_OPTS = -Gz -guard:cf -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
SHELL_CCONV_OPTS = -Gz -guard:cf -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
# <<mark>>
|
||||
TEST_CCONV_OPTS = -Gz -guard:cf -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall -DINCLUDE_SQLITE_TCL_H=1 -DSQLITE_TCLAPI=__cdecl
|
||||
TEST_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall -DINCLUDE_SQLITE_TCL_H=1 -DSQLITE_TCLAPI=__cdecl
|
||||
# <</mark>>
|
||||
!ELSE
|
||||
!IFNDEF PLATFORM
|
||||
CORE_CCONV_OPTS = -Gz -guard:cf -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
SHELL_CCONV_OPTS = -Gz -guard:cf -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
# <<mark>>
|
||||
TEST_CCONV_OPTS = -Gz -guard:cf -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall -DINCLUDE_SQLITE_TCL_H=1 -DSQLITE_TCLAPI=__cdecl
|
||||
TEST_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall -DINCLUDE_SQLITE_TCL_H=1 -DSQLITE_TCLAPI=__cdecl
|
||||
# <</mark>>
|
||||
!ELSE
|
||||
CORE_CCONV_OPTS =
|
||||
@@ -1247,7 +1248,7 @@ LIBOBJS0 = vdbe.lo parse.lo alter.lo analyze.lo attach.lo auth.lo \
|
||||
fts3_tokenize_vtab.lo fts3_unicode.lo fts3_unicode2.lo fts3_write.lo \
|
||||
fts5.lo \
|
||||
func.lo global.lo hash.lo \
|
||||
icu.lo insert.lo json.lo legacy.lo loadext.lo \
|
||||
icu.lo insert.lo json1.lo legacy.lo loadext.lo \
|
||||
main.lo malloc.lo mem0.lo mem1.lo mem2.lo mem3.lo mem5.lo \
|
||||
memdb.lo memjournal.lo \
|
||||
mutex.lo mutex_noop.lo mutex_unix.lo mutex_w32.lo \
|
||||
@@ -1314,7 +1315,6 @@ SRC00 = \
|
||||
$(TOP)\src\global.c \
|
||||
$(TOP)\src\hash.c \
|
||||
$(TOP)\src\insert.c \
|
||||
$(TOP)\src\json.c \
|
||||
$(TOP)\src\legacy.c \
|
||||
$(TOP)\src\loadext.c \
|
||||
$(TOP)\src\main.c \
|
||||
@@ -1445,6 +1445,7 @@ SRC07 = \
|
||||
$(TOP)\ext\rtree\rtree.c \
|
||||
$(TOP)\ext\session\sqlite3session.c \
|
||||
$(TOP)\ext\rbu\sqlite3rbu.c \
|
||||
$(TOP)\ext\misc\json1.c \
|
||||
$(TOP)\ext\misc\stmt.c
|
||||
|
||||
# Extension header files, part 1.
|
||||
@@ -1578,7 +1579,6 @@ TESTEXT = \
|
||||
$(TOP)\ext\misc\normalize.c \
|
||||
$(TOP)\ext\misc\percentile.c \
|
||||
$(TOP)\ext\misc\prefixes.c \
|
||||
$(TOP)\ext\misc\qpvtab.c \
|
||||
$(TOP)\ext\misc\regexp.c \
|
||||
$(TOP)\ext\misc\remember.c \
|
||||
$(TOP)\ext\misc\series.c \
|
||||
@@ -1586,7 +1586,6 @@ TESTEXT = \
|
||||
$(TOP)\ext\misc\totype.c \
|
||||
$(TOP)\ext\misc\unionvtab.c \
|
||||
$(TOP)\ext\misc\wholenumber.c \
|
||||
$(TOP)\ext\rtree\test_rtreedoc.c \
|
||||
fts5.c
|
||||
|
||||
# If use of zlib is enabled, add the "zipfile.c" source file.
|
||||
@@ -1695,11 +1694,10 @@ SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC=1
|
||||
# <<mark>>
|
||||
# Extra compiler options for various test tools.
|
||||
#
|
||||
MPTESTER_COMPILE_OPTS = -DSQLITE_ENABLE_FTS5
|
||||
FUZZERSHELL_COMPILE_OPTS =
|
||||
FUZZCHECK_OPTS = -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ -DSQLITE_MAX_MEMORY=50000000 -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
MPTESTER_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5
|
||||
FUZZERSHELL_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1
|
||||
FUZZCHECK_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ -DSQLITE_MAX_MEMORY=50000000 -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS4
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS5
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_RTREE
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_GEOPOLY
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
@@ -1990,9 +1988,6 @@ hash.lo: $(TOP)\src\hash.c $(HDR)
|
||||
insert.lo: $(TOP)\src\insert.c $(HDR)
|
||||
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\insert.c
|
||||
|
||||
json.lo: $(TOP)\src\json.c $(HDR)
|
||||
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\json.c
|
||||
|
||||
legacy.lo: $(TOP)\src\legacy.c $(HDR)
|
||||
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\legacy.c
|
||||
|
||||
@@ -2301,6 +2296,9 @@ fts3_unicode2.lo: $(TOP)\ext\fts3\fts3_unicode2.c $(HDR) $(EXTHDR)
|
||||
fts3_write.lo: $(TOP)\ext\fts3\fts3_write.c $(HDR) $(EXTHDR)
|
||||
$(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_write.c
|
||||
|
||||
json1.lo: $(TOP)\ext\misc\json1.c $(HDR) $(EXTHDR)
|
||||
$(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\misc\json1.c
|
||||
|
||||
stmt.lo: $(TOP)\ext\misc\stmt.c $(HDR) $(EXTHDR)
|
||||
$(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\misc\stmt.c
|
||||
|
||||
@@ -2392,6 +2390,7 @@ TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_DEFAULT_PAGE_SIZE=1024
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_JSON1=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_CKSUMVFS_STATIC=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) $(TEST_CCONV_OPTS)
|
||||
|
||||
@@ -2437,9 +2436,7 @@ coretestprogs: $(TESTPROGS)
|
||||
|
||||
testprogs: coretestprogs srcck1.exe fuzzcheck.exe sessionfuzz.exe
|
||||
|
||||
fulltest: alltest fuzztest
|
||||
|
||||
alltest: $(TESTPROGS)
|
||||
fulltest: $(TESTPROGS) fuzztest
|
||||
@set PATH=$(LIBTCLPATH);$(PATH)
|
||||
.\testfixture.exe $(TOP)\test\all.test $(TESTOPTS)
|
||||
|
||||
@@ -2467,11 +2464,7 @@ quicktest: testfixture.exe sourcetest
|
||||
# This is the common case. Run many tests that do not take too long,
|
||||
# including fuzzcheck, sqlite3_analyzer, and sqldiff tests.
|
||||
#
|
||||
test: $(TESTPROGS) sourcetest fuzztest tcltest
|
||||
|
||||
# The veryquick.test TCL tests.
|
||||
#
|
||||
tcltest: testfixture.exe
|
||||
test: $(TESTPROGS) sourcetest fuzztest
|
||||
@set PATH=$(LIBTCLPATH);$(PATH)
|
||||
.\testfixture.exe $(TOP)\test\veryquick.test $(TESTOPTS)
|
||||
|
||||
|
||||
@@ -309,11 +309,9 @@ describes its purpose and role within the larger system.
|
||||
The `manifest` file at the root directory of the source tree
|
||||
contains either a SHA3-256 hash (for newer files) or a SHA1 hash (for
|
||||
older files) for every source file in the repository.
|
||||
The name of the version of the entire source tree is just the
|
||||
SHA3-256 hash of the `manifest` file itself, possibly with the
|
||||
last line of that file omitted if the last line begins with
|
||||
"`# Remove this line`".
|
||||
The `manifest.uuid` file should contain the SHA3-256 hash of the
|
||||
The SHA3-256 hash of the `manifest`
|
||||
file itself is the official name of the version of the source tree that you
|
||||
have. The `manifest.uuid` file should contain the SHA3-256 hash of the
|
||||
`manifest` file. If all of the above hash comparisons are correct, then
|
||||
you can be confident that your source tree is authentic and unadulterated.
|
||||
|
||||
|
||||
@@ -285,6 +285,7 @@ SQLITE3EXEPDB = /pdb:sqlite3sh.pdb
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS3=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RTREE=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_GEOPOLY=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_JSON1=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
|
||||
@@ -501,12 +502,12 @@ RCC = $(RC) -DSQLITE_OS_WIN=1 -I. -I$(TOP) $(RCOPTS) $(RCCOPTS)
|
||||
#
|
||||
!IF $(USE_STDCALL)!=0 || $(FOR_WIN10)!=0
|
||||
!IF "$(PLATFORM)"=="x86"
|
||||
CORE_CCONV_OPTS = -Gz -guard:cf -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
SHELL_CCONV_OPTS = -Gz -guard:cf -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
!ELSE
|
||||
!IFNDEF PLATFORM
|
||||
CORE_CCONV_OPTS = -Gz -guard:cf -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
SHELL_CCONV_OPTS = -Gz -guard:cf -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall
|
||||
!ELSE
|
||||
CORE_CCONV_OPTS =
|
||||
SHELL_CCONV_OPTS =
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ may be specified in this manner as some require the amalgamation to be built
|
||||
with them enabled (see http://www.sqlite.org/compile.html). For example, the
|
||||
following will work:
|
||||
|
||||
"OPTS=-DSQLITE_ENABLE_STAT4=1 -DSQLITE_OMIT_JSON=1"
|
||||
"OPTS=-DSQLITE_ENABLE_STAT4=1 -DSQLITE_ENABLE_JSON1=1"
|
||||
|
||||
However, the following will not compile unless the amalgamation was built
|
||||
with it enabled:
|
||||
|
||||
@@ -173,6 +173,21 @@ else
|
||||
fi
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# --enable-json1
|
||||
#
|
||||
AC_ARG_ENABLE(json1, [AS_HELP_STRING(
|
||||
[--enable-json1], [include json1 support [default=yes]])],
|
||||
[],[enable_json1=yes])
|
||||
AC_MSG_CHECKING([JSON functions])
|
||||
if test x"$enable_json1" = "xyes"; then
|
||||
BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_JSON1"
|
||||
AC_MSG_RESULT([enabled])
|
||||
else
|
||||
AC_MSG_RESULT([disabled])
|
||||
fi
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# --enable-rtree
|
||||
#
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.39.0.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.37.0.
|
||||
#
|
||||
#
|
||||
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
|
||||
@@ -726,8 +726,8 @@ MAKEFLAGS=
|
||||
# Identity of this package.
|
||||
PACKAGE_NAME='sqlite'
|
||||
PACKAGE_TARNAME='sqlite'
|
||||
PACKAGE_VERSION='3.39.0'
|
||||
PACKAGE_STRING='sqlite 3.39.0'
|
||||
PACKAGE_VERSION='3.37.0'
|
||||
PACKAGE_STRING='sqlite 3.37.0'
|
||||
PACKAGE_BUGREPORT=''
|
||||
PACKAGE_URL=''
|
||||
|
||||
@@ -770,11 +770,11 @@ ac_includes_default="\
|
||||
ac_subst_vars='LTLIBOBJS
|
||||
LIBOBJS
|
||||
BUILD_CFLAGS
|
||||
AMALGAMATION_LINE_MACROS
|
||||
USE_GCOV
|
||||
OPT_FEATURE_FLAGS
|
||||
HAVE_ZLIB
|
||||
USE_AMALGAMATION
|
||||
AMALGAMATION_LINE_MACROS
|
||||
TARGET_DEBUG
|
||||
TARGET_HAVE_EDITLINE
|
||||
TARGET_HAVE_READLINE
|
||||
@@ -903,15 +903,16 @@ with_readline_lib
|
||||
with_readline_inc
|
||||
enable_debug
|
||||
enable_amalgamation
|
||||
amalgamation_line_macros
|
||||
enable_load_extension
|
||||
enable_math
|
||||
enable_json
|
||||
enable_all
|
||||
enable_memsys5
|
||||
enable_memsys3
|
||||
enable_fts3
|
||||
enable_fts4
|
||||
enable_fts5
|
||||
enable_json1
|
||||
enable_update_limit
|
||||
enable_geopoly
|
||||
enable_rtree
|
||||
@@ -1468,7 +1469,7 @@ if test "$ac_init_help" = "long"; then
|
||||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat <<_ACEOF
|
||||
\`configure' configures sqlite 3.39.0 to adapt to many kinds of systems.
|
||||
\`configure' configures sqlite 3.37.0 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -1533,7 +1534,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of sqlite 3.39.0:";;
|
||||
short | recursive ) echo "Configuration of sqlite 3.37.0:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@@ -1560,13 +1561,13 @@ Optional Features:
|
||||
--disable-load-extension
|
||||
Disable loading of external extensions
|
||||
--disable-math Disable math functions
|
||||
--disable-json Disable JSON functions
|
||||
--enable-all Enable FTS4, FTS5, Geopoly, RTree, Sessions
|
||||
--enable-all Enable FTS4, FTS5, Geopoly, JSON, RTree, Sessions
|
||||
--enable-memsys5 Enable MEMSYS5
|
||||
--enable-memsys3 Enable MEMSYS3
|
||||
--enable-fts3 Enable the FTS3 extension
|
||||
--enable-fts4 Enable the FTS4 extension
|
||||
--enable-fts5 Enable the FTS5 extension
|
||||
--enable-json1 Enable the JSON1 extension
|
||||
--enable-update-limit Enable the UPDATE/DELETE LIMIT clause
|
||||
--enable-geopoly Enable the GEOPOLY extension
|
||||
--enable-rtree Enable the RTREE extension
|
||||
@@ -1661,7 +1662,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
sqlite configure 3.39.0
|
||||
sqlite configure 3.37.0
|
||||
generated by GNU Autoconf 2.69
|
||||
|
||||
Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
@@ -2080,7 +2081,7 @@ cat >config.log <<_ACEOF
|
||||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by sqlite $as_me 3.39.0, which was
|
||||
It was created by sqlite $as_me 3.37.0, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
@@ -3938,13 +3939,13 @@ if ${lt_cv_nm_interface+:} false; then :
|
||||
else
|
||||
lt_cv_nm_interface="BSD nm"
|
||||
echo "int some_variable = 0;" > conftest.$ac_ext
|
||||
(eval echo "\"\$as_me:3941: $ac_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:3940: $ac_compile\"" >&5)
|
||||
(eval "$ac_compile" 2>conftest.err)
|
||||
cat conftest.err >&5
|
||||
(eval echo "\"\$as_me:3944: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
|
||||
(eval echo "\"\$as_me:3943: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
|
||||
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
|
||||
cat conftest.err >&5
|
||||
(eval echo "\"\$as_me:3947: output\"" >&5)
|
||||
(eval echo "\"\$as_me:3946: output\"" >&5)
|
||||
cat conftest.out >&5
|
||||
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
|
||||
lt_cv_nm_interface="MS dumpbin"
|
||||
@@ -5150,7 +5151,7 @@ ia64-*-hpux*)
|
||||
;;
|
||||
*-*-irix6*)
|
||||
# Find out which ABI we are using.
|
||||
echo '#line 5153 "configure"' > conftest.$ac_ext
|
||||
echo '#line 5152 "configure"' > conftest.$ac_ext
|
||||
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
|
||||
(eval $ac_compile) 2>&5
|
||||
ac_status=$?
|
||||
@@ -6675,11 +6676,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:6678: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:6677: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:6682: \$? = $ac_status" >&5
|
||||
echo "$as_me:6681: \$? = $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 other than the usual output.
|
||||
@@ -7014,11 +7015,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7017: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7016: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:7021: \$? = $ac_status" >&5
|
||||
echo "$as_me:7020: \$? = $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 other than the usual output.
|
||||
@@ -7119,11 +7120,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7122: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7121: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7126: \$? = $ac_status" >&5
|
||||
echo "$as_me:7125: \$? = $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
|
||||
@@ -7174,11 +7175,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7177: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7176: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7181: \$? = $ac_status" >&5
|
||||
echo "$as_me:7180: \$? = $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
|
||||
@@ -9554,7 +9555,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 9557 "configure"
|
||||
#line 9556 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -9650,7 +9651,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 9653 "configure"
|
||||
#line 9652 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -10306,6 +10307,13 @@ done
|
||||
#
|
||||
USE_AMALGAMATION=1
|
||||
|
||||
#########
|
||||
# By default, amalgamation sqlite3.c will have #line directives.
|
||||
# This is a build option not shown by ./configure --help
|
||||
# To control it, use configure option: amalgamation_line_macros=?
|
||||
# where ? is no to suppress #line directives or yes to create them.
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=0
|
||||
|
||||
#########
|
||||
# See whether we can run specific tclsh versions known to work well;
|
||||
# if not, then we fall back to plain tclsh.
|
||||
@@ -11276,6 +11284,19 @@ if test "${enable_amalgamation}" = "no" ; then
|
||||
USE_AMALGAMATION=0
|
||||
fi
|
||||
|
||||
########
|
||||
# See whether --disable
|
||||
if test "${amalgamation_line_macros+set}" = set; then :
|
||||
enableval=$amalgamation_line_macros;
|
||||
fi
|
||||
|
||||
if test "${amalgamation_line_macros}" = "yes" ; then
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=1
|
||||
fi
|
||||
if test "${amalgamation_line_macros}" = "no" ; then
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=0
|
||||
fi
|
||||
|
||||
|
||||
#########
|
||||
# Look for zlib. Only needed by extensions and by the sqlite3.exe shell
|
||||
@@ -11497,24 +11518,6 @@ fi
|
||||
|
||||
fi
|
||||
|
||||
##########
|
||||
# Do we want to support JSON functions
|
||||
#
|
||||
# Check whether --enable-json was given.
|
||||
if test "${enable_json+set}" = set; then :
|
||||
enableval=$enable_json;
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support JSON functions" >&5
|
||||
$as_echo_n "checking whether to support JSON functions... " >&6; }
|
||||
if test "$enable_json" = "no"; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_OMIT_JSON"
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
fi
|
||||
|
||||
########
|
||||
# The --enable-all argument is short-hand to enable
|
||||
@@ -11719,6 +11722,24 @@ else
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
#########
|
||||
# See whether we should enable JSON1
|
||||
# Check whether --enable-json1 was given.
|
||||
if test "${enable_json1+set}" = set; then :
|
||||
enableval=$enable_json1;
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support JSON" >&5
|
||||
$as_echo_n "checking whether to support JSON... " >&6; }
|
||||
if test "${enable_json1}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_JSON1"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
#########
|
||||
# See whether we should enable the LIMIT clause on UPDATE and DELETE
|
||||
# statements.
|
||||
@@ -11861,17 +11882,6 @@ else
|
||||
fi
|
||||
|
||||
|
||||
#########
|
||||
# Enable/disabled amalagamation line macros
|
||||
########
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=0
|
||||
if test "${amalgamation_line_macros}" = "yes" ; then
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=1
|
||||
fi
|
||||
if test "${amalgamation_line_macros}" = "no" ; then
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=0
|
||||
fi
|
||||
|
||||
|
||||
#########
|
||||
# Output the config header
|
||||
@@ -12390,7 +12400,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
||||
# report actual input values of CONFIG_FILES etc. instead of their
|
||||
# values after options handling.
|
||||
ac_log="
|
||||
This file was extended by sqlite $as_me 3.39.0, which was
|
||||
This file was extended by sqlite $as_me 3.37.0, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@@ -12456,7 +12466,7 @@ _ACEOF
|
||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
|
||||
ac_cs_version="\\
|
||||
sqlite config.status 3.39.0
|
||||
sqlite config.status 3.37.0
|
||||
configured by $0, generated by GNU Autoconf 2.69,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
|
||||
+12
-24
@@ -605,24 +605,12 @@ else
|
||||
AC_SEARCH_LIBS(ceil, m)
|
||||
fi
|
||||
|
||||
##########
|
||||
# Do we want to support JSON functions
|
||||
#
|
||||
AC_ARG_ENABLE(json,
|
||||
AC_HELP_STRING([--disable-json],[Disable JSON functions]))
|
||||
AC_MSG_CHECKING([whether to support JSON functions])
|
||||
if test "$enable_json" = "no"; then
|
||||
AC_MSG_RESULT([no])
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_OMIT_JSON"
|
||||
else
|
||||
AC_MSG_RESULT([yes])
|
||||
fi
|
||||
|
||||
########
|
||||
# The --enable-all argument is short-hand to enable
|
||||
# multiple extensions.
|
||||
AC_ARG_ENABLE(all, AC_HELP_STRING([--enable-all],
|
||||
[Enable FTS4, FTS5, Geopoly, RTree, Sessions]))
|
||||
[Enable FTS4, FTS5, Geopoly, JSON, RTree, Sessions]))
|
||||
|
||||
##########
|
||||
# Do we want to support memsys3 and/or memsys5
|
||||
@@ -678,6 +666,17 @@ else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
#########
|
||||
# See whether we should enable JSON1
|
||||
AC_ARG_ENABLE(json1, AC_HELP_STRING([--enable-json1],[Enable the JSON1 extension]))
|
||||
AC_MSG_CHECKING([whether to support JSON])
|
||||
if test "${enable_json1}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_JSON1"
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
#########
|
||||
# See whether we should enable the LIMIT clause on UPDATE and DELETE
|
||||
# statements.
|
||||
@@ -792,17 +791,6 @@ else
|
||||
fi
|
||||
AC_SUBST(USE_GCOV)
|
||||
|
||||
#########
|
||||
# Enable/disabled amalagamation line macros
|
||||
########
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=0
|
||||
if test "${amalgamation_line_macros}" = "yes" ; then
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=1
|
||||
fi
|
||||
if test "${amalgamation_line_macros}" = "no" ; then
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=0
|
||||
fi
|
||||
AC_SUBST(AMALGAMATION_LINE_MACROS)
|
||||
|
||||
#########
|
||||
# Output the config header
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
# JSON Functions Enhancements (2022)
|
||||
|
||||
This document summaries enhancements to the SQLite JSON support added in
|
||||
early 2022.
|
||||
|
||||
## 1.0 Change summary:
|
||||
|
||||
1. New **->** and **->>** operators that work like MySQL and PostgreSQL (PG).
|
||||
2. JSON functions are built-in rather than being an extension. They
|
||||
are included by default, but can be omitted using the
|
||||
-DSQLITE_OMIT_JSON compile-time option.
|
||||
|
||||
|
||||
## 2.0 New operators **->** and **->>**
|
||||
|
||||
The SQLite language adds two new binary operators **->** and **->>**.
|
||||
Both operators are similar to json_extract(). The left operand is
|
||||
JSON and the right operand is a JSON path expression (possibly abbreviated
|
||||
for compatibility with PG - see below). So they are similar to a
|
||||
two-argument call to json_extract().
|
||||
|
||||
The difference between -> and ->> (and json_extract()) is as follows:
|
||||
|
||||
* The -> operator always returns JSON.
|
||||
|
||||
* The ->> operator converts the answer into a primitive SQL datatype
|
||||
such as TEXT, INTEGER, REAL, or NULL. If a JSON object or array
|
||||
is selected, that object or array is rendered as text. If a JSON
|
||||
value is selected, that value is converted into its corresponding
|
||||
SQL type
|
||||
|
||||
* The json_extract() interface returns JSON when a JSON object or
|
||||
array is selected, or a primitive SQL datatype when a JSON value
|
||||
is selected. This is different from MySQL, in which json_extract()
|
||||
always returns JSON, but the difference is retained because it has
|
||||
worked that way for 6 years and changing it now would likely break
|
||||
a lot of legacy code.
|
||||
|
||||
In MySQL and PG, the ->> operator always returns TEXT (or NULL) and never
|
||||
INTEGER or REAL. This is due to limitations in the type handling capabilities
|
||||
of those systems. In MySQL and PG, the result type a function or operator
|
||||
may only depend on the type of its arguments, never the value of its arguments.
|
||||
But the underlying JSON type depends on the value of the JSON path
|
||||
expression, not the type of the JSON path expression (which is always TEXT).
|
||||
Hence, the result type of ->> in MySQL and PG is unable to vary according
|
||||
to the type of the JSON value being extracted.
|
||||
|
||||
The type system in SQLite is more general. Functions in SQLite are able
|
||||
to return different datatypes depending on the value of their arguments.
|
||||
So the ->> operator in SQLite is able to return TEXT, INTEGER, REAL, or NULL
|
||||
depending on the JSON type of the value being extracted. This means that
|
||||
the behavior of the ->> is slightly different in SQLite versus MySQL and PG
|
||||
in that it will sometimes return INTEGER and REAL values, depending on its
|
||||
inputs. It is possible to implement the ->> operator in SQLite so that it
|
||||
always operates exactly like MySQL and PG and always returns TEXT or NULL,
|
||||
but I have been unable to think of any situations where returning the
|
||||
actual JSON value this would cause problems, so I'm including the enhanced
|
||||
functionality in SQLite.
|
||||
|
||||
The table below attempts to summarize the differences between the
|
||||
-> and ->> operators and the json_extract() function, for SQLite, MySQL,
|
||||
and PG. JSON values are shown using their SQL text representation but
|
||||
in a bold font.
|
||||
|
||||
|
||||
<table border=1 cellpadding=5 cellspacing=0>
|
||||
<tr><th>JSON<th>PATH<th>-> operator<br>(all)<th>->> operator<br>(MySQL/PG)
|
||||
<th>->> operator<br>(SQLite)<th>json_extract()<br>(SQLite)
|
||||
<tr><td> **'{"a":123}'** <td>'$.a'<td> **'123'** <td> '123' <td> 123 <td> 123
|
||||
<tr><td> **'{"a":4.5}'** <td>'$.a'<td> **'4.5'** <td> '4.5' <td> 4.5 <td> 4.5
|
||||
<tr><td> **'{"a":"xyz"}'** <td>'$.a'<td> **'"xyz"'** <td> 'xyz' <td> 'xyz' <td> 'xyz'
|
||||
<tr><td> **'{"a":null}'** <td>'$.a'<td> **'null'** <td> NULL <td> NULL <td> NULL
|
||||
<tr><td> **'{"a":[6,7,8]}'** <td>'$.a'<td> **'[6,7,8]'** <td> '[6,7,8]' <td> '[6,7,8]' <td> **'[6,7,8]'**
|
||||
<tr><td> **'{"a":{"x":9}}'** <td>'$.a'<td> **'{"x":9}'** <td> '{"x":9}' <td> '{"x":9}' <td> **'{"x":9}'**
|
||||
<tr><td> **'{"b":999}'** <td>'$.a'<td> NULL <td> NULL <td> NULL <td> NULL
|
||||
</table>
|
||||
|
||||
Important points about the table above:
|
||||
|
||||
* The -> operator always returns either JSON or NULL.
|
||||
|
||||
* The ->> operator never returns JSON. It always returns TEXT or NULL, or in the
|
||||
case of SQLite, INTEGER or REAL.
|
||||
|
||||
* The MySQL json_extract() function works exactly the same
|
||||
as the MySQL -> operator.
|
||||
|
||||
* The SQLite json_extract() operator works like -> for JSON objects and
|
||||
arrays, and like ->> for JSON values.
|
||||
|
||||
* The -> operator works the same for all systems.
|
||||
|
||||
* The only difference in ->> between SQLite and other systems is that
|
||||
when the JSON value is numeric, SQLite returns a numeric SQL value,
|
||||
whereas the other systems return a text representation of the numeric
|
||||
value.
|
||||
|
||||
### 2.1 Abbreviated JSON path expressions for PG compatibility
|
||||
|
||||
The table above always shows the full JSON path expression: '$.a'. But
|
||||
PG does not accept this syntax. PG only allows a single JSON object label
|
||||
name or a single integer array index. In order to provide compatibility
|
||||
with PG, The -> and ->> operators in SQLite are extended to also support
|
||||
a JSON object label or an integer array index for the right-hand side
|
||||
operand, in addition to a full JSON path expression.
|
||||
|
||||
Thus, a -> or ->> operator that works on MySQL will work in
|
||||
SQLite. And a -> or ->> operator that works in PG will work in SQLite.
|
||||
But because SQLite supports the union of the disjoint capabilities of
|
||||
MySQL and PG, there will always be -> and ->> operators that work in
|
||||
SQLite that do not work in one of MySQL and PG. This is an unavoidable
|
||||
consequence of the different syntax for -> and ->> in MySQL and PG.
|
||||
|
||||
In the following table, assume that "value1" is a JSON object and
|
||||
"value2" is a JSON array.
|
||||
|
||||
<table border=1 cellpadding=5 cellspacing=0>
|
||||
<tr><th>SQL expression <th>Works in MySQL?<th>Works in PG?<th>Works in SQLite
|
||||
<tr><td>value1->'$.a' <td> yes <td> no <td> yes
|
||||
<tr><td>value1->'a' <td> no <td> yes <td> yes
|
||||
<tr><td>value2->'$[2]' <td> yes <td> no <td> yes
|
||||
<tr><td>value2->2 <td> no <td> yes <td> yes
|
||||
</table>
|
||||
|
||||
The abbreviated JSON path expressions only work for the -> and ->> operators
|
||||
in SQLite. The json_extract() function, and all other built-in SQLite
|
||||
JSON functions, continue to require complete JSON path expressions for their
|
||||
PATH arguments.
|
||||
|
||||
## 3.0 JSON moved into the core
|
||||
|
||||
The JSON interface is now moved into the SQLite core.
|
||||
|
||||
When originally written in 2015, the JSON functions were an extension
|
||||
that could be optionally included at compile-time, or loaded at run-time.
|
||||
The implementation was in a source file named ext/misc/json1.c in the
|
||||
source tree. JSON functions were only compiled in if the
|
||||
-DSQLITE_ENABLE_JSON1 compile-time option was used.
|
||||
|
||||
After these enhancements, the JSON functions are now built-ins.
|
||||
The source file that implements the JSON functions is moved to src/json.c.
|
||||
No special compile-time options are needed to load JSON into the build.
|
||||
Instead, there is a new -DSQLITE_OMIT_JSON compile-time option to leave
|
||||
them out.
|
||||
@@ -196,7 +196,7 @@ do_setup_rec_test $tn.9.1 {
|
||||
} {
|
||||
SELECT * FROM "t t" WHERE a=?
|
||||
} {
|
||||
CREATE INDEX "t t_idx_00000061" ON "t t"(a);
|
||||
CREATE INDEX 't t_idx_00000061' ON 't t'(a);
|
||||
SEARCH t t USING INDEX t t_idx_00000061 (a=?)
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ do_setup_rec_test $tn.9.2 {
|
||||
} {
|
||||
SELECT * FROM "t t" WHERE b BETWEEN ? AND ?
|
||||
} {
|
||||
CREATE INDEX "t t_idx_00000062" ON "t t"(b);
|
||||
CREATE INDEX 't t_idx_00000062' ON 't t'(b);
|
||||
SEARCH t t USING INDEX t t_idx_00000062 (b>? AND b<?)
|
||||
}
|
||||
|
||||
|
||||
+21
-99
@@ -15,23 +15,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if !defined(SQLITE_AMALGAMATION)
|
||||
#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
|
||||
# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1
|
||||
#endif
|
||||
#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS)
|
||||
# define ALWAYS(X) (1)
|
||||
# define NEVER(X) (0)
|
||||
#elif !defined(NDEBUG)
|
||||
# define ALWAYS(X) ((X)?1:(assert(0),0))
|
||||
# define NEVER(X) ((X)?(assert(0),1):0)
|
||||
#else
|
||||
# define ALWAYS(X) (X)
|
||||
# define NEVER(X) (X)
|
||||
#endif
|
||||
#endif /* !defined(SQLITE_AMALGAMATION) */
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
|
||||
typedef sqlite3_int64 i64;
|
||||
@@ -697,25 +680,17 @@ static int idxGetTableInfo(
|
||||
){
|
||||
sqlite3_stmt *p1 = 0;
|
||||
int nCol = 0;
|
||||
int nTab;
|
||||
int nByte;
|
||||
int nTab = STRLEN(zTab);
|
||||
int nByte = sizeof(IdxTable) + nTab + 1;
|
||||
IdxTable *pNew = 0;
|
||||
int rc, rc2;
|
||||
char *pCsr = 0;
|
||||
int nPk = 0;
|
||||
|
||||
*ppOut = 0;
|
||||
if( zTab==0 ) return SQLITE_ERROR;
|
||||
nTab = STRLEN(zTab);
|
||||
nByte = sizeof(IdxTable) + nTab + 1;
|
||||
rc = idxPrintfPrepareStmt(db, &p1, pzErrmsg, "PRAGMA table_xinfo=%Q", zTab);
|
||||
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(p1) ){
|
||||
const char *zCol = (const char*)sqlite3_column_text(p1, 1);
|
||||
const char *zColSeq = 0;
|
||||
if( zCol==0 ){
|
||||
rc = SQLITE_ERROR;
|
||||
break;
|
||||
}
|
||||
nByte += 1 + STRLEN(zCol);
|
||||
rc = sqlite3_table_column_metadata(
|
||||
db, "main", zTab, zCol, 0, &zColSeq, 0, 0, 0
|
||||
@@ -742,9 +717,7 @@ static int idxGetTableInfo(
|
||||
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(p1) ){
|
||||
const char *zCol = (const char*)sqlite3_column_text(p1, 1);
|
||||
const char *zColSeq = 0;
|
||||
int nCopy;
|
||||
if( zCol==0 ) continue;
|
||||
nCopy = STRLEN(zCol) + 1;
|
||||
int nCopy = STRLEN(zCol) + 1;
|
||||
pNew->aCol[nCol].zName = pCsr;
|
||||
pNew->aCol[nCol].iPk = (sqlite3_column_int(p1, 5)==1 && nPk==1);
|
||||
memcpy(pCsr, zCol, nCopy);
|
||||
@@ -768,9 +741,9 @@ static int idxGetTableInfo(
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3_free(pNew);
|
||||
pNew = 0;
|
||||
}else if( ALWAYS(pNew!=0) ){
|
||||
}else{
|
||||
pNew->zName = pCsr;
|
||||
if( ALWAYS(pNew->zName!=0) ) memcpy(pNew->zName, zTab, nTab+1);
|
||||
memcpy(pNew->zName, zTab, nTab+1);
|
||||
}
|
||||
|
||||
*ppOut = pNew;
|
||||
@@ -896,7 +869,6 @@ static int idxFindCompatible(
|
||||
IdxConstraint *pT = pTail;
|
||||
sqlite3_stmt *pInfo = 0;
|
||||
const char *zIdx = (const char*)sqlite3_column_text(pIdxList, 1);
|
||||
if( zIdx==0 ) continue;
|
||||
|
||||
/* Zero the IdxConstraint.bFlag values in the pEq list */
|
||||
for(pIter=pEq; pIter; pIter=pIter->pLink) pIter->bFlag = 0;
|
||||
@@ -942,19 +914,6 @@ static int idxFindCompatible(
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Callback for sqlite3_exec() with query with leading count(*) column.
|
||||
* The first argument is expected to be an int*, referent to be incremented
|
||||
* if that leading column is not exactly '0'.
|
||||
*/
|
||||
static int countNonzeros(void* pCount, int nc,
|
||||
char* azResults[], char* azColumns[]){
|
||||
(void)azColumns; /* Suppress unused parameter warning */
|
||||
if( nc>0 && (azResults[0][0]!='0' || azResults[0][1]!=0) ){
|
||||
*((int *)pCount) += 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int idxCreateFromCons(
|
||||
sqlite3expert *p,
|
||||
IdxScan *pScan,
|
||||
@@ -981,40 +940,17 @@ static int idxCreateFromCons(
|
||||
if( rc==SQLITE_OK ){
|
||||
/* Hash the list of columns to come up with a name for the index */
|
||||
const char *zTable = pScan->pTab->zName;
|
||||
int quoteTable = idxIdentifierRequiresQuotes(zTable);
|
||||
char *zName = 0; /* Index name */
|
||||
int collisions = 0;
|
||||
do{
|
||||
int i;
|
||||
char *zFind;
|
||||
for(i=0; zCols[i]; i++){
|
||||
h += ((h<<3) + zCols[i]);
|
||||
}
|
||||
sqlite3_free(zName);
|
||||
zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
|
||||
if( zName==0 ) break;
|
||||
/* Is is unique among table, view and index names? */
|
||||
zFmt = "SELECT count(*) FROM sqlite_schema WHERE name=%Q"
|
||||
" AND type in ('index','table','view')";
|
||||
zFind = sqlite3_mprintf(zFmt, zName);
|
||||
i = 0;
|
||||
rc = sqlite3_exec(dbm, zFind, countNonzeros, &i, 0);
|
||||
assert(rc==SQLITE_OK);
|
||||
sqlite3_free(zFind);
|
||||
if( i==0 ){
|
||||
collisions = 0;
|
||||
break;
|
||||
}
|
||||
++collisions;
|
||||
}while( collisions<50 && zName!=0 );
|
||||
if( collisions ){
|
||||
/* This return means "Gave up trying to find a unique index name." */
|
||||
rc = SQLITE_BUSY_TIMEOUT;
|
||||
}else if( zName==0 ){
|
||||
char *zName; /* Index name */
|
||||
int i;
|
||||
for(i=0; zCols[i]; i++){
|
||||
h += ((h<<3) + zCols[i]);
|
||||
}
|
||||
zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
|
||||
if( zName==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
if( quoteTable ){
|
||||
zFmt = "CREATE INDEX \"%w\" ON \"%w\"(%s)";
|
||||
if( idxIdentifierRequiresQuotes(zTable) ){
|
||||
zFmt = "CREATE INDEX '%q' ON %Q(%s)";
|
||||
}else{
|
||||
zFmt = "CREATE INDEX %s ON %s(%s)";
|
||||
}
|
||||
@@ -1023,11 +959,7 @@ static int idxCreateFromCons(
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
rc = sqlite3_exec(dbm, zIdx, 0, 0, p->pzErrmsg);
|
||||
if( rc!=SQLITE_OK ){
|
||||
rc = SQLITE_BUSY_TIMEOUT;
|
||||
}else{
|
||||
idxHashAdd(&rc, &p->hIdx, zName, zIdx);
|
||||
}
|
||||
idxHashAdd(&rc, &p->hIdx, zName, zIdx);
|
||||
}
|
||||
sqlite3_free(zName);
|
||||
sqlite3_free(zIdx);
|
||||
@@ -1179,7 +1111,7 @@ static void idxWriteFree(IdxWrite *pTab){
|
||||
** runs all the queries to see which indexes they prefer, and populates
|
||||
** IdxStatement.zIdx and IdxStatement.zEQP with the results.
|
||||
*/
|
||||
static int idxFindIndexes(
|
||||
int idxFindIndexes(
|
||||
sqlite3expert *p,
|
||||
char **pzErr /* OUT: Error message (sqlite3_malloc) */
|
||||
){
|
||||
@@ -1308,7 +1240,6 @@ static int idxProcessOneTrigger(
|
||||
rc = idxPrintfPrepareStmt(p->db, &pSelect, pzErr, zSql, zTab, zTab);
|
||||
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSelect) ){
|
||||
const char *zCreate = (const char*)sqlite3_column_text(pSelect, 0);
|
||||
if( zCreate==0 ) continue;
|
||||
rc = sqlite3_exec(p->dbv, zCreate, 0, 0, pzErr);
|
||||
}
|
||||
idxFinalize(&rc, pSelect);
|
||||
@@ -1411,9 +1342,8 @@ static int idxCreateVtabSchema(sqlite3expert *p, char **pzErrmsg){
|
||||
const char *zName = (const char*)sqlite3_column_text(pSchema, 1);
|
||||
const char *zSql = (const char*)sqlite3_column_text(pSchema, 2);
|
||||
|
||||
if( zType==0 || zName==0 ) continue;
|
||||
if( zType[0]=='v' || zType[1]=='r' ){
|
||||
if( zSql ) rc = sqlite3_exec(p->dbv, zSql, 0, 0, pzErrmsg);
|
||||
rc = sqlite3_exec(p->dbv, zSql, 0, 0, pzErrmsg);
|
||||
}else{
|
||||
IdxTable *pTab;
|
||||
rc = idxGetTableInfo(p->db, zName, &pTab, pzErrmsg);
|
||||
@@ -1550,7 +1480,6 @@ static void idxRemFunc(
|
||||
case SQLITE_BLOB:
|
||||
case SQLITE_TEXT: {
|
||||
int nByte = sqlite3_value_bytes(argv[1]);
|
||||
const void *pData = 0;
|
||||
if( nByte>pSlot->nByte ){
|
||||
char *zNew = (char*)sqlite3_realloc(pSlot->z, nByte*2);
|
||||
if( zNew==0 ){
|
||||
@@ -1562,11 +1491,9 @@ static void idxRemFunc(
|
||||
}
|
||||
pSlot->n = nByte;
|
||||
if( pSlot->eType==SQLITE_BLOB ){
|
||||
pData = sqlite3_value_blob(argv[1]);
|
||||
if( pData ) memcpy(pSlot->z, pData, nByte);
|
||||
memcpy(pSlot->z, sqlite3_value_blob(argv[1]), nByte);
|
||||
}else{
|
||||
pData = sqlite3_value_text(argv[1]);
|
||||
memcpy(pSlot->z, pData, nByte);
|
||||
memcpy(pSlot->z, sqlite3_value_text(argv[1]), nByte);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1777,7 +1704,6 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
|
||||
i64 iRowid = sqlite3_column_int64(pAllIndex, 0);
|
||||
const char *zTab = (const char*)sqlite3_column_text(pAllIndex, 1);
|
||||
const char *zIdx = (const char*)sqlite3_column_text(pAllIndex, 2);
|
||||
if( zTab==0 || zIdx==0 ) continue;
|
||||
if( p->iSample<100 && iPrev!=iRowid ){
|
||||
samplectx.target = (double)p->iSample / 100.0;
|
||||
samplectx.iTarget = p->iSample;
|
||||
@@ -1844,14 +1770,14 @@ sqlite3expert *sqlite3_expert_new(sqlite3 *db, char **pzErrmsg){
|
||||
|
||||
/* Copy the entire schema of database [db] into [dbm]. */
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_stmt *pSql = 0;
|
||||
sqlite3_stmt *pSql;
|
||||
rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
|
||||
"SELECT sql FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%%'"
|
||||
" AND sql NOT LIKE 'CREATE VIRTUAL %%'"
|
||||
);
|
||||
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
|
||||
const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
|
||||
if( zSql ) rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
|
||||
rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
|
||||
}
|
||||
idxFinalize(&rc, pSql);
|
||||
}
|
||||
@@ -1957,10 +1883,6 @@ int sqlite3_expert_analyze(sqlite3expert *p, char **pzErr){
|
||||
/* Create candidate indexes within the in-memory database file */
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = idxCreateCandidates(p);
|
||||
}else if ( rc==SQLITE_BUSY_TIMEOUT ){
|
||||
if( pzErr )
|
||||
*pzErr = sqlite3_mprintf("Cannot find a unique index name to propose.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Generate the stat1 data */
|
||||
|
||||
+26
-35
@@ -308,17 +308,18 @@
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#endif
|
||||
|
||||
typedef struct Fts3HashWrapper Fts3HashWrapper;
|
||||
struct Fts3HashWrapper {
|
||||
Fts3Hash hash; /* Hash table */
|
||||
int nRef; /* Number of pointers to this object */
|
||||
};
|
||||
|
||||
static int fts3EvalNext(Fts3Cursor *pCsr);
|
||||
static int fts3EvalStart(Fts3Cursor *pCsr);
|
||||
static int fts3TermSegReaderCursor(
|
||||
Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
|
||||
|
||||
#ifndef SQLITE_AMALGAMATION
|
||||
# if defined(SQLITE_DEBUG)
|
||||
int sqlite3Fts3Always(int b) { assert( b ); return b; }
|
||||
int sqlite3Fts3Never(int b) { assert( !b ); return b; }
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This variable is set to false when running tests for which the on disk
|
||||
** structures should not be corrupt. Otherwise, true. If it is false, extra
|
||||
@@ -1178,7 +1179,7 @@ static int fts3InitVtab(
|
||||
sqlite3_vtab **ppVTab, /* Write the resulting vtab structure here */
|
||||
char **pzErr /* Write any error message here */
|
||||
){
|
||||
Fts3Hash *pHash = &((Fts3HashWrapper*)pAux)->hash;
|
||||
Fts3Hash *pHash = (Fts3Hash *)pAux;
|
||||
Fts3Table *p = 0; /* Pointer to allocated vtab */
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
int i; /* Iterator variable */
|
||||
@@ -4013,12 +4014,9 @@ static const sqlite3_module fts3Module = {
|
||||
** allocated for the tokenizer hash table.
|
||||
*/
|
||||
static void hashDestroy(void *p){
|
||||
Fts3HashWrapper *pHash = (Fts3HashWrapper *)p;
|
||||
pHash->nRef--;
|
||||
if( pHash->nRef<=0 ){
|
||||
sqlite3Fts3HashClear(&pHash->hash);
|
||||
sqlite3_free(pHash);
|
||||
}
|
||||
Fts3Hash *pHash = (Fts3Hash *)p;
|
||||
sqlite3Fts3HashClear(pHash);
|
||||
sqlite3_free(pHash);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4048,7 +4046,7 @@ void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
|
||||
*/
|
||||
int sqlite3Fts3Init(sqlite3 *db){
|
||||
int rc = SQLITE_OK;
|
||||
Fts3HashWrapper *pHash = 0;
|
||||
Fts3Hash *pHash = 0;
|
||||
const sqlite3_tokenizer_module *pSimple = 0;
|
||||
const sqlite3_tokenizer_module *pPorter = 0;
|
||||
#ifndef SQLITE_DISABLE_FTS3_UNICODE
|
||||
@@ -4076,24 +4074,23 @@ int sqlite3Fts3Init(sqlite3 *db){
|
||||
sqlite3Fts3PorterTokenizerModule(&pPorter);
|
||||
|
||||
/* Allocate and initialize the hash-table used to store tokenizers. */
|
||||
pHash = sqlite3_malloc(sizeof(Fts3HashWrapper));
|
||||
pHash = sqlite3_malloc(sizeof(Fts3Hash));
|
||||
if( !pHash ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
sqlite3Fts3HashInit(&pHash->hash, FTS3_HASH_STRING, 1);
|
||||
pHash->nRef = 0;
|
||||
sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1);
|
||||
}
|
||||
|
||||
/* Load the built-in tokenizers into the hash table */
|
||||
if( rc==SQLITE_OK ){
|
||||
if( sqlite3Fts3HashInsert(&pHash->hash, "simple", 7, (void *)pSimple)
|
||||
|| sqlite3Fts3HashInsert(&pHash->hash, "porter", 7, (void *)pPorter)
|
||||
if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple)
|
||||
|| sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter)
|
||||
|
||||
#ifndef SQLITE_DISABLE_FTS3_UNICODE
|
||||
|| sqlite3Fts3HashInsert(&pHash->hash, "unicode61", 10, (void *)pUnicode)
|
||||
|| sqlite3Fts3HashInsert(pHash, "unicode61", 10, (void *)pUnicode)
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_ICU
|
||||
|| (pIcu && sqlite3Fts3HashInsert(&pHash->hash, "icu", 4, (void *)pIcu))
|
||||
|| (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
|
||||
#endif
|
||||
){
|
||||
rc = SQLITE_NOMEM;
|
||||
@@ -4102,7 +4099,7 @@ int sqlite3Fts3Init(sqlite3 *db){
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts3ExprInitTestInterface(db, &pHash->hash);
|
||||
rc = sqlite3Fts3ExprInitTestInterface(db, pHash);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4111,26 +4108,23 @@ int sqlite3Fts3Init(sqlite3 *db){
|
||||
** module with sqlite.
|
||||
*/
|
||||
if( SQLITE_OK==rc
|
||||
&& SQLITE_OK==(rc=sqlite3Fts3InitHashTable(db,&pHash->hash,"fts3_tokenizer"))
|
||||
&& SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
|
||||
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
|
||||
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
|
||||
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
|
||||
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
|
||||
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
|
||||
){
|
||||
pHash->nRef++;
|
||||
rc = sqlite3_create_module_v2(
|
||||
db, "fts3", &fts3Module, (void *)pHash, hashDestroy
|
||||
);
|
||||
if( rc==SQLITE_OK ){
|
||||
pHash->nRef++;
|
||||
rc = sqlite3_create_module_v2(
|
||||
db, "fts4", &fts3Module, (void *)pHash, hashDestroy
|
||||
db, "fts4", &fts3Module, (void *)pHash, 0
|
||||
);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
pHash->nRef++;
|
||||
rc = sqlite3Fts3InitTok(db, (void *)pHash, hashDestroy);
|
||||
rc = sqlite3Fts3InitTok(db, (void *)pHash);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -4139,7 +4133,7 @@ int sqlite3Fts3Init(sqlite3 *db){
|
||||
/* An error has occurred. Delete the hash table and return the error code. */
|
||||
assert( rc!=SQLITE_OK );
|
||||
if( pHash ){
|
||||
sqlite3Fts3HashClear(&pHash->hash);
|
||||
sqlite3Fts3HashClear(pHash);
|
||||
sqlite3_free(pHash);
|
||||
}
|
||||
return rc;
|
||||
@@ -4486,7 +4480,7 @@ void sqlite3Fts3DoclistPrev(
|
||||
|
||||
assert( nDoclist>0 );
|
||||
assert( *pbEof==0 );
|
||||
assert_fts3_nc( p || *piDocid==0 );
|
||||
assert( p || *piDocid==0 );
|
||||
assert( !p || (p>aDoclist && p<&aDoclist[nDoclist]) );
|
||||
|
||||
if( p==0 ){
|
||||
@@ -5350,8 +5344,8 @@ static void fts3EvalNextRow(
|
||||
Fts3Expr *pRight = pExpr->pRight;
|
||||
sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid);
|
||||
|
||||
assert_fts3_nc( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
|
||||
assert_fts3_nc( pRight->bStart || pLeft->iDocid==pRight->iDocid );
|
||||
assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
|
||||
assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
|
||||
|
||||
if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
|
||||
fts3EvalNextRow(pCsr, pLeft, pRc);
|
||||
@@ -5989,9 +5983,6 @@ int sqlite3Fts3EvalPhrasePoslist(
|
||||
if( bEofSave==0 && pNear->iDocid==iDocid ) break;
|
||||
}
|
||||
assert( rc!=SQLITE_OK || pPhrase->bIncr==0 );
|
||||
if( rc==SQLITE_OK && pNear->bEof!=bEofSave ){
|
||||
rc = FTS_CORRUPT_VTAB;
|
||||
}
|
||||
}
|
||||
if( bTreeEof ){
|
||||
while( rc==SQLITE_OK && !pNear->bEof ){
|
||||
|
||||
+11
-13
@@ -151,18 +151,17 @@ extern int sqlite3_fts3_may_be_corrupt;
|
||||
** Macros indicating that conditional expressions are always true or
|
||||
** false.
|
||||
*/
|
||||
#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
|
||||
# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1
|
||||
#endif
|
||||
#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS)
|
||||
# define ALWAYS(X) (1)
|
||||
# define NEVER(X) (0)
|
||||
#elif !defined(NDEBUG)
|
||||
# define ALWAYS(X) ((X)?1:(assert(0),0))
|
||||
# define NEVER(X) ((X)?(assert(0),1):0)
|
||||
#ifdef SQLITE_COVERAGE_TEST
|
||||
# define ALWAYS(x) (1)
|
||||
# define NEVER(X) (0)
|
||||
#elif defined(SQLITE_DEBUG)
|
||||
# define ALWAYS(x) sqlite3Fts3Always((x)!=0)
|
||||
# define NEVER(x) sqlite3Fts3Never((x)!=0)
|
||||
int sqlite3Fts3Always(int b);
|
||||
int sqlite3Fts3Never(int b);
|
||||
#else
|
||||
# define ALWAYS(X) (X)
|
||||
# define NEVER(X) (X)
|
||||
# define ALWAYS(x) (x)
|
||||
# define NEVER(x) (x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -621,7 +620,6 @@ void sqlite3Fts3ExprFree(Fts3Expr *);
|
||||
int sqlite3Fts3ExprInitTestInterface(sqlite3 *db, Fts3Hash*);
|
||||
int sqlite3Fts3InitTerm(sqlite3 *db);
|
||||
#endif
|
||||
void *sqlite3Fts3MallocZero(i64 nByte);
|
||||
|
||||
int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int,
|
||||
sqlite3_tokenizer_cursor **
|
||||
@@ -641,7 +639,7 @@ int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
|
||||
int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
|
||||
|
||||
/* fts3_tokenize_vtab.c */
|
||||
int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *, void(*xDestroy)(void*));
|
||||
int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *);
|
||||
|
||||
/* fts3_unicode2.c (functions generated by parsing unicode text files) */
|
||||
#ifndef SQLITE_DISABLE_FTS3_UNICODE
|
||||
|
||||
+1
-5
@@ -297,7 +297,6 @@ static int fts3auxNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
if( fts3auxGrowStatArray(pCsr, 2) ) return SQLITE_NOMEM;
|
||||
memset(pCsr->aStat, 0, sizeof(struct Fts3auxColstats) * pCsr->nStat);
|
||||
iCol = 0;
|
||||
rc = SQLITE_OK;
|
||||
|
||||
while( i<nDoclist ){
|
||||
sqlite3_int64 v = 0;
|
||||
@@ -341,10 +340,6 @@ static int fts3auxNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
/* State 3. The integer just read is a column number. */
|
||||
default: assert( eState==3 );
|
||||
iCol = (int)v;
|
||||
if( iCol<1 ){
|
||||
rc = SQLITE_CORRUPT_VTAB;
|
||||
break;
|
||||
}
|
||||
if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM;
|
||||
pCsr->aStat[iCol+1].nDoc++;
|
||||
eState = 2;
|
||||
@@ -353,6 +348,7 @@ static int fts3auxNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
}
|
||||
|
||||
pCsr->iCol = 0;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
pCsr->isEof = 1;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ static int fts3isspace(char c){
|
||||
** zero the memory before returning a pointer to it. If unsuccessful,
|
||||
** return NULL.
|
||||
*/
|
||||
void *sqlite3Fts3MallocZero(sqlite3_int64 nByte){
|
||||
static void *fts3MallocZero(sqlite3_int64 nByte){
|
||||
void *pRet = sqlite3_malloc64(nByte);
|
||||
if( pRet ) memset(pRet, 0, nByte);
|
||||
return pRet;
|
||||
@@ -203,7 +203,7 @@ static int getNextToken(
|
||||
rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
|
||||
if( rc==SQLITE_OK ){
|
||||
nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
|
||||
pRet = (Fts3Expr *)sqlite3Fts3MallocZero(nByte);
|
||||
pRet = (Fts3Expr *)fts3MallocZero(nByte);
|
||||
if( !pRet ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -458,7 +458,7 @@ static int getNextNode(
|
||||
if( fts3isspace(cNext)
|
||||
|| cNext=='"' || cNext=='(' || cNext==')' || cNext==0
|
||||
){
|
||||
pRet = (Fts3Expr *)sqlite3Fts3MallocZero(sizeof(Fts3Expr));
|
||||
pRet = (Fts3Expr *)fts3MallocZero(sizeof(Fts3Expr));
|
||||
if( !pRet ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -637,7 +637,7 @@ static int fts3ExprParse(
|
||||
&& p->eType==FTSQUERY_PHRASE && pParse->isNot
|
||||
){
|
||||
/* Create an implicit NOT operator. */
|
||||
Fts3Expr *pNot = sqlite3Fts3MallocZero(sizeof(Fts3Expr));
|
||||
Fts3Expr *pNot = fts3MallocZero(sizeof(Fts3Expr));
|
||||
if( !pNot ){
|
||||
sqlite3Fts3ExprFree(p);
|
||||
rc = SQLITE_NOMEM;
|
||||
@@ -671,7 +671,7 @@ static int fts3ExprParse(
|
||||
/* Insert an implicit AND operator. */
|
||||
Fts3Expr *pAnd;
|
||||
assert( pRet && pPrev );
|
||||
pAnd = sqlite3Fts3MallocZero(sizeof(Fts3Expr));
|
||||
pAnd = fts3MallocZero(sizeof(Fts3Expr));
|
||||
if( !pAnd ){
|
||||
sqlite3Fts3ExprFree(p);
|
||||
rc = SQLITE_NOMEM;
|
||||
|
||||
+12
-11
@@ -138,8 +138,9 @@ static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
|
||||
+ sizeof(MatchinfoBuffer);
|
||||
sqlite3_int64 nStr = strlen(zMatchinfo);
|
||||
|
||||
pRet = sqlite3Fts3MallocZero(nByte + nStr+1);
|
||||
pRet = sqlite3_malloc64(nByte + nStr+1);
|
||||
if( pRet ){
|
||||
memset(pRet, 0, nByte);
|
||||
pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
|
||||
pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
|
||||
+ sizeof(u32)*((int)nElem+1);
|
||||
@@ -543,10 +544,11 @@ static int fts3BestSnippet(
|
||||
** the required space using malloc().
|
||||
*/
|
||||
nByte = sizeof(SnippetPhrase) * nList;
|
||||
sIter.aPhrase = (SnippetPhrase *)sqlite3Fts3MallocZero(nByte);
|
||||
sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc64(nByte);
|
||||
if( !sIter.aPhrase ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
memset(sIter.aPhrase, 0, nByte);
|
||||
|
||||
/* Initialize the contents of the SnippetIter object. Then iterate through
|
||||
** the set of phrases in the expression to populate the aPhrase[] array.
|
||||
@@ -1110,12 +1112,10 @@ static int fts3MatchinfoLcsCb(
|
||||
** position list for the next column.
|
||||
*/
|
||||
static int fts3LcsIteratorAdvance(LcsIterator *pIter){
|
||||
char *pRead;
|
||||
char *pRead = pIter->pRead;
|
||||
sqlite3_int64 iRead;
|
||||
int rc = 0;
|
||||
|
||||
if( NEVER(pIter==0) ) return 1;
|
||||
pRead = pIter->pRead;
|
||||
pRead += sqlite3Fts3GetVarint(pRead, &iRead);
|
||||
if( iRead==0 || iRead==1 ){
|
||||
pRead = 0;
|
||||
@@ -1149,8 +1149,9 @@ static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
|
||||
/* Allocate and populate the array of LcsIterator objects. The array
|
||||
** contains one element for each matchable phrase in the query.
|
||||
**/
|
||||
aIter = sqlite3Fts3MallocZero(sizeof(LcsIterator) * pCsr->nPhrase);
|
||||
aIter = sqlite3_malloc64(sizeof(LcsIterator) * pCsr->nPhrase);
|
||||
if( !aIter ) return SQLITE_NOMEM;
|
||||
memset(aIter, 0, sizeof(LcsIterator) * pCsr->nPhrase);
|
||||
(void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
|
||||
|
||||
for(i=0; i<pInfo->nPhrase; i++){
|
||||
@@ -1611,7 +1612,7 @@ void sqlite3Fts3Offsets(
|
||||
if( rc!=SQLITE_OK ) goto offsets_out;
|
||||
|
||||
/* Allocate the array of TermOffset iterators. */
|
||||
sCtx.aTerm = (TermOffset *)sqlite3Fts3MallocZero(sizeof(TermOffset)*nToken);
|
||||
sCtx.aTerm = (TermOffset *)sqlite3_malloc64(sizeof(TermOffset)*nToken);
|
||||
if( 0==sCtx.aTerm ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto offsets_out;
|
||||
@@ -1632,13 +1633,13 @@ void sqlite3Fts3Offsets(
|
||||
const char *zDoc;
|
||||
int nDoc;
|
||||
|
||||
/* Initialize the contents of sCtx.aTerm[] for column iCol. This
|
||||
** operation may fail if the database contains corrupt records.
|
||||
/* Initialize the contents of sCtx.aTerm[] for column iCol. There is
|
||||
** no way that this operation can fail, so the return code from
|
||||
** fts3ExprIterate() can be discarded.
|
||||
*/
|
||||
sCtx.iCol = iCol;
|
||||
sCtx.iTerm = 0;
|
||||
rc = fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void*)&sCtx);
|
||||
if( rc!=SQLITE_OK ) goto offsets_out;
|
||||
(void)fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void*)&sCtx);
|
||||
|
||||
/* Retreive the text stored in column iCol. If an SQL NULL is stored
|
||||
** in column iCol, jump immediately to the next iteration of the loop.
|
||||
|
||||
@@ -420,7 +420,7 @@ static int fts3tokRowidMethod(
|
||||
** Register the fts3tok module with database connection db. Return SQLITE_OK
|
||||
** if successful or an error code if sqlite3_create_module() fails.
|
||||
*/
|
||||
int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash, void(*xDestroy)(void*)){
|
||||
int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash){
|
||||
static const sqlite3_module fts3tok_module = {
|
||||
0, /* iVersion */
|
||||
fts3tokConnectMethod, /* xCreate */
|
||||
@@ -449,9 +449,7 @@ int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash, void(*xDestroy)(void*)){
|
||||
};
|
||||
int rc; /* Return code */
|
||||
|
||||
rc = sqlite3_create_module_v2(
|
||||
db, "fts3tokenize", &fts3tok_module, (void*)pHash, xDestroy
|
||||
);
|
||||
rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, (void*)pHash);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
+8
-20
@@ -1335,18 +1335,8 @@ static int fts3SegReaderNext(
|
||||
char *aCopy;
|
||||
PendingList *pList = (PendingList *)fts3HashData(pElem);
|
||||
int nCopy = pList->nData+1;
|
||||
|
||||
int nTerm = fts3HashKeysize(pElem);
|
||||
if( (nTerm+1)>pReader->nTermAlloc ){
|
||||
sqlite3_free(pReader->zTerm);
|
||||
pReader->zTerm = (char*)sqlite3_malloc((nTerm+1)*2);
|
||||
if( !pReader->zTerm ) return SQLITE_NOMEM;
|
||||
pReader->nTermAlloc = (nTerm+1)*2;
|
||||
}
|
||||
memcpy(pReader->zTerm, fts3HashKey(pElem), nTerm);
|
||||
pReader->zTerm[nTerm] = '\0';
|
||||
pReader->nTerm = nTerm;
|
||||
|
||||
pReader->zTerm = (char *)fts3HashKey(pElem);
|
||||
pReader->nTerm = fts3HashKeysize(pElem);
|
||||
aCopy = (char*)sqlite3_malloc(nCopy);
|
||||
if( !aCopy ) return SQLITE_NOMEM;
|
||||
memcpy(aCopy, pList->aData, nCopy);
|
||||
@@ -1599,7 +1589,9 @@ int sqlite3Fts3MsrOvfl(
|
||||
*/
|
||||
void sqlite3Fts3SegReaderFree(Fts3SegReader *pReader){
|
||||
if( pReader ){
|
||||
sqlite3_free(pReader->zTerm);
|
||||
if( !fts3SegReaderIsPending(pReader) ){
|
||||
sqlite3_free(pReader->zTerm);
|
||||
}
|
||||
if( !fts3SegReaderIsRootOnly(pReader) ){
|
||||
sqlite3_free(pReader->aNode);
|
||||
}
|
||||
@@ -3791,7 +3783,7 @@ static int nodeReaderNext(NodeReader *p){
|
||||
return FTS_CORRUPT_VTAB;
|
||||
}
|
||||
blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc);
|
||||
if( rc==SQLITE_OK && ALWAYS(p->term.a!=0) ){
|
||||
if( rc==SQLITE_OK ){
|
||||
memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix);
|
||||
p->term.n = nPrefix+nSuffix;
|
||||
p->iOff += nSuffix;
|
||||
@@ -4185,11 +4177,7 @@ static int fts3TermCmp(
|
||||
int nCmp = MIN(nLhs, nRhs);
|
||||
int res;
|
||||
|
||||
if( nCmp && ALWAYS(zLhs) && ALWAYS(zRhs) ){
|
||||
res = memcmp(zLhs, zRhs, nCmp);
|
||||
}else{
|
||||
res = 0;
|
||||
}
|
||||
res = (nCmp ? memcmp(zLhs, zRhs, nCmp) : 0);
|
||||
if( res==0 ) res = nLhs - nRhs;
|
||||
|
||||
return res;
|
||||
@@ -4833,7 +4821,7 @@ static int fts3IncrmergeHintLoad(Fts3Table *p, Blob *pHint){
|
||||
if( aHint ){
|
||||
blobGrowBuffer(pHint, nHint, &rc);
|
||||
if( rc==SQLITE_OK ){
|
||||
if( ALWAYS(pHint->a!=0) ) memcpy(pHint->a, aHint, nHint);
|
||||
memcpy(pHint->a, aHint, nHint);
|
||||
pHint->n = nHint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/tclsh
|
||||
#
|
||||
# This script builds a single C code file holding all of FTS3 code.
|
||||
# The name of the output file is fts3amal.c. To build this file,
|
||||
# first do:
|
||||
#
|
||||
# make target_source
|
||||
#
|
||||
# The make target above moves all of the source code files into
|
||||
# a subdirectory named "tsrc". (This script expects to find the files
|
||||
# there and will not work if they are not found.)
|
||||
#
|
||||
# After the "tsrc" directory has been created and populated, run
|
||||
# this script:
|
||||
#
|
||||
# tclsh mkfts3amal.tcl
|
||||
#
|
||||
# The amalgamated FTS3 code will be written into fts3amal.c
|
||||
#
|
||||
|
||||
# Open the output file and write a header comment at the beginning
|
||||
# of the file.
|
||||
#
|
||||
set out [open fts3amal.c w]
|
||||
set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
|
||||
puts $out [subst \
|
||||
{/******************************************************************************
|
||||
** This file is an amalgamation of separate C source files from the SQLite
|
||||
** Full Text Search extension 2 (fts3). By combining all the individual C
|
||||
** code files into this single large file, the entire code can be compiled
|
||||
** as a one translation unit. This allows many compilers to do optimizations
|
||||
** that would not be possible if the files were compiled separately. It also
|
||||
** makes the code easier to import into other projects.
|
||||
**
|
||||
** This amalgamation was generated on $today.
|
||||
*/}]
|
||||
|
||||
# These are the header files used by FTS3. The first time any of these
|
||||
# files are seen in a #include statement in the C code, include the complete
|
||||
# text of the file in-line. The file only needs to be included once.
|
||||
#
|
||||
foreach hdr {
|
||||
fts3.h
|
||||
fts3_hash.h
|
||||
fts3_tokenizer.h
|
||||
sqlite3.h
|
||||
sqlite3ext.h
|
||||
} {
|
||||
set available_hdr($hdr) 1
|
||||
}
|
||||
|
||||
# 78 stars used for comment formatting.
|
||||
set s78 \
|
||||
{*****************************************************************************}
|
||||
|
||||
# Insert a comment into the code
|
||||
#
|
||||
proc section_comment {text} {
|
||||
global out s78
|
||||
set n [string length $text]
|
||||
set nstar [expr {60 - $n}]
|
||||
set stars [string range $s78 0 $nstar]
|
||||
puts $out "/************** $text $stars/"
|
||||
}
|
||||
|
||||
# Read the source file named $filename and write it into the
|
||||
# sqlite3.c output file. If any #include statements are seen,
|
||||
# process them approprately.
|
||||
#
|
||||
proc copy_file {filename} {
|
||||
global seen_hdr available_hdr out
|
||||
set tail [file tail $filename]
|
||||
section_comment "Begin file $tail"
|
||||
set in [open $filename r]
|
||||
while {![eof $in]} {
|
||||
set line [gets $in]
|
||||
if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
|
||||
if {[info exists available_hdr($hdr)]} {
|
||||
if {$available_hdr($hdr)} {
|
||||
section_comment "Include $hdr in the middle of $tail"
|
||||
copy_file tsrc/$hdr
|
||||
section_comment "Continuing where we left off in $tail"
|
||||
}
|
||||
} elseif {![info exists seen_hdr($hdr)]} {
|
||||
set seen_hdr($hdr) 1
|
||||
puts $out $line
|
||||
}
|
||||
} elseif {[regexp {^#ifdef __cplusplus} $line]} {
|
||||
puts $out "#if 0"
|
||||
} elseif {[regexp {^#line} $line]} {
|
||||
# Skip #line directives.
|
||||
} else {
|
||||
puts $out $line
|
||||
}
|
||||
}
|
||||
close $in
|
||||
section_comment "End of $tail"
|
||||
}
|
||||
|
||||
|
||||
# Process the source files. Process files containing commonly
|
||||
# used subroutines first in order to help the compiler find
|
||||
# inlining opportunities.
|
||||
#
|
||||
foreach file {
|
||||
fts3.c
|
||||
fts3_hash.c
|
||||
fts3_porter.c
|
||||
fts3_tokenizer.c
|
||||
fts3_tokenizer1.c
|
||||
} {
|
||||
copy_file tsrc/$file
|
||||
}
|
||||
|
||||
close $out
|
||||
+3
-15
@@ -35,20 +35,8 @@ typedef sqlite3_uint64 u64;
|
||||
#endif
|
||||
|
||||
#define testcase(x)
|
||||
|
||||
#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
|
||||
# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1
|
||||
#endif
|
||||
#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS)
|
||||
# define ALWAYS(X) (1)
|
||||
# define NEVER(X) (0)
|
||||
#elif !defined(NDEBUG)
|
||||
# define ALWAYS(X) ((X)?1:(assert(0),0))
|
||||
# define NEVER(X) ((X)?(assert(0),1):0)
|
||||
#else
|
||||
# define ALWAYS(X) (X)
|
||||
# define NEVER(X) (X)
|
||||
#endif
|
||||
#define ALWAYS(x) 1
|
||||
#define NEVER(x) 0
|
||||
|
||||
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
|
||||
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
|
||||
@@ -108,7 +96,7 @@ extern int sqlite3_fts5_may_be_corrupt;
|
||||
** A version of memcmp() that does not cause asan errors if one of the pointer
|
||||
** parameters is NULL and the number of bytes to compare is zero.
|
||||
*/
|
||||
#define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n)))
|
||||
#define fts5Memcmp(s1, s2, n) ((n)==0 ? 0 : memcmp((s1), (s2), (n)))
|
||||
|
||||
/* Mark a function parameter as unused, to suppress nuisance compiler
|
||||
** warnings. */
|
||||
|
||||
@@ -66,6 +66,7 @@ void sqlite3Fts5BufferAppendBlob(
|
||||
u32 nData,
|
||||
const u8 *pData
|
||||
){
|
||||
assert_nc( *pRc || nData>=0 );
|
||||
if( nData ){
|
||||
if( fts5BufferGrow(pRc, pBuf, nData) ) return;
|
||||
memcpy(&pBuf->p[pBuf->n], pData, nData);
|
||||
@@ -177,6 +178,7 @@ int sqlite3Fts5PoslistNext64(
|
||||
i64 iOff = *piOff;
|
||||
u32 iVal;
|
||||
fts5FastGetVarint32(a, i, iVal);
|
||||
assert( iVal>=0 );
|
||||
if( iVal<=1 ){
|
||||
if( iVal==0 ){
|
||||
*pi = i;
|
||||
|
||||
@@ -562,7 +562,6 @@ int sqlite3Fts5ConfigParse(
|
||||
z = fts5ConfigSkipWhitespace(z);
|
||||
if( z && *z=='=' ){
|
||||
bOption = 1;
|
||||
assert( zOne!=0 );
|
||||
z++;
|
||||
if( bMustBeCol ) z = 0;
|
||||
}
|
||||
@@ -579,11 +578,7 @@ int sqlite3Fts5ConfigParse(
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
if( bOption ){
|
||||
rc = fts5ConfigParseSpecial(pGlobal, pRet,
|
||||
ALWAYS(zOne)?zOne:"",
|
||||
zTwo?zTwo:"",
|
||||
pzErr
|
||||
);
|
||||
rc = fts5ConfigParseSpecial(pGlobal, pRet, zOne, zTwo?zTwo:"", pzErr);
|
||||
}else{
|
||||
rc = fts5ConfigParseColumn(pRet, zOne, zTwo, pzErr);
|
||||
zOne = 0;
|
||||
|
||||
+2
-12
@@ -434,7 +434,6 @@ static i64 fts5ExprSynonymRowid(Fts5ExprTerm *pTerm, int bDesc, int *pbEof){
|
||||
int bRetValid = 0;
|
||||
Fts5ExprTerm *p;
|
||||
|
||||
assert( pTerm );
|
||||
assert( pTerm->pSynonym );
|
||||
assert( bDesc==0 || bDesc==1 );
|
||||
for(p=pTerm; p; p=p->pSynonym){
|
||||
@@ -1875,7 +1874,7 @@ int sqlite3Fts5ExprClonePhrase(
|
||||
sCtx.pPhrase = sqlite3Fts5MallocZero(&rc, sizeof(Fts5ExprPhrase));
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK && ALWAYS(sCtx.pPhrase) ){
|
||||
if( rc==SQLITE_OK ){
|
||||
/* All the allocations succeeded. Put the expression object together. */
|
||||
pNew->pIndex = pExpr->pIndex;
|
||||
pNew->pConfig = pExpr->pConfig;
|
||||
@@ -2856,15 +2855,6 @@ struct Fts5PoslistPopulator {
|
||||
int bMiss;
|
||||
};
|
||||
|
||||
/*
|
||||
** Clear the position lists associated with all phrases in the expression
|
||||
** passed as the first argument. Argument bLive is true if the expression
|
||||
** might be pointing to a real entry, otherwise it has just been reset.
|
||||
**
|
||||
** At present this function is only used for detail=col and detail=none
|
||||
** fts5 tables. This implies that all phrases must be at most 1 token
|
||||
** in size, as phrase matches are not supported without detail=full.
|
||||
*/
|
||||
Fts5PoslistPopulator *sqlite3Fts5ExprClearPoslists(Fts5Expr *pExpr, int bLive){
|
||||
Fts5PoslistPopulator *pRet;
|
||||
pRet = sqlite3_malloc64(sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
|
||||
@@ -2874,7 +2864,7 @@ Fts5PoslistPopulator *sqlite3Fts5ExprClearPoslists(Fts5Expr *pExpr, int bLive){
|
||||
for(i=0; i<pExpr->nPhrase; i++){
|
||||
Fts5Buffer *pBuf = &pExpr->apExprPhrase[i]->poslist;
|
||||
Fts5ExprNode *pNode = pExpr->apExprPhrase[i]->pNode;
|
||||
assert( pExpr->apExprPhrase[i]->nTerm<=1 );
|
||||
assert( pExpr->apExprPhrase[i]->nTerm==1 );
|
||||
if( bLive &&
|
||||
(pBuf->n==0 || pNode->iRowid!=pExpr->pRoot->iRowid || pNode->bEof)
|
||||
){
|
||||
|
||||
@@ -356,7 +356,7 @@ int sqlite3Fts5HashWrite(
|
||||
p->bContent = 1;
|
||||
}else{
|
||||
/* Append a new column value, if necessary */
|
||||
assert_nc( iCol>=p->iCol );
|
||||
assert( iCol>=p->iCol );
|
||||
if( iCol!=p->iCol ){
|
||||
if( pHash->eDetail==FTS5_DETAIL_FULL ){
|
||||
pPtr[p->nData++] = 0x01;
|
||||
|
||||
+34
-103
@@ -600,11 +600,8 @@ static int fts5BufferCompareBlob(
|
||||
** res = *pLeft - *pRight
|
||||
*/
|
||||
static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
|
||||
int nCmp, res;
|
||||
nCmp = MIN(pLeft->n, pRight->n);
|
||||
assert( nCmp<=0 || pLeft->p!=0 );
|
||||
assert( nCmp<=0 || pRight->p!=0 );
|
||||
res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
|
||||
int nCmp = MIN(pLeft->n, pRight->n);
|
||||
int res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
|
||||
return (res==0 ? (pLeft->n - pRight->n) : res);
|
||||
}
|
||||
|
||||
@@ -700,7 +697,6 @@ static Fts5Data *fts5DataRead(Fts5Index *p, i64 iRowid){
|
||||
return pRet;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Release a reference to data record returned by an earlier call to
|
||||
** fts5DataRead().
|
||||
@@ -841,42 +837,6 @@ int sqlite3Fts5StructureTest(Fts5Index *p, void *pStruct){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Ensure that structure object (*pp) is writable.
|
||||
**
|
||||
** This function is a no-op if (*pRc) is not SQLITE_OK when it is called. If
|
||||
** an error occurs, (*pRc) is set to an SQLite error code before returning.
|
||||
*/
|
||||
static void fts5StructureMakeWritable(int *pRc, Fts5Structure **pp){
|
||||
Fts5Structure *p = *pp;
|
||||
if( *pRc==SQLITE_OK && p->nRef>1 ){
|
||||
i64 nByte = sizeof(Fts5Structure)+(p->nLevel-1)*sizeof(Fts5StructureLevel);
|
||||
Fts5Structure *pNew;
|
||||
pNew = (Fts5Structure*)sqlite3Fts5MallocZero(pRc, nByte);
|
||||
if( pNew ){
|
||||
int i;
|
||||
memcpy(pNew, p, nByte);
|
||||
for(i=0; i<p->nLevel; i++) pNew->aLevel[i].aSeg = 0;
|
||||
for(i=0; i<p->nLevel; i++){
|
||||
Fts5StructureLevel *pLvl = &pNew->aLevel[i];
|
||||
nByte = sizeof(Fts5StructureSegment) * pNew->aLevel[i].nSeg;
|
||||
pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(pRc, nByte);
|
||||
if( pLvl->aSeg==0 ){
|
||||
for(i=0; i<p->nLevel; i++){
|
||||
sqlite3_free(pNew->aLevel[i].aSeg);
|
||||
}
|
||||
sqlite3_free(pNew);
|
||||
return;
|
||||
}
|
||||
memcpy(pLvl->aSeg, p->aLevel[i].aSeg, nByte);
|
||||
}
|
||||
p->nRef--;
|
||||
pNew->nRef = 1;
|
||||
}
|
||||
*pp = pNew;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Deserialize and return the structure record currently stored in serialized
|
||||
** form within buffer pData/nData.
|
||||
@@ -978,11 +938,9 @@ static int fts5StructureDecode(
|
||||
}
|
||||
|
||||
/*
|
||||
** Add a level to the Fts5Structure.aLevel[] array of structure object
|
||||
** (*ppStruct).
|
||||
**
|
||||
*/
|
||||
static void fts5StructureAddLevel(int *pRc, Fts5Structure **ppStruct){
|
||||
fts5StructureMakeWritable(pRc, ppStruct);
|
||||
if( *pRc==SQLITE_OK ){
|
||||
Fts5Structure *pStruct = *ppStruct;
|
||||
int nLevel = pStruct->nLevel;
|
||||
@@ -1776,7 +1734,6 @@ static void fts5SegIterInit(
|
||||
|
||||
if( p->rc==SQLITE_OK ){
|
||||
pIter->iLeafOffset = 4;
|
||||
assert( pIter->pLeaf!=0 );
|
||||
assert_nc( pIter->pLeaf->nn>4 );
|
||||
assert_nc( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
|
||||
pIter->iPgidxOff = pIter->pLeaf->szLeaf+1;
|
||||
@@ -1879,12 +1836,8 @@ static void fts5SegIterReverseNewPage(Fts5Index *p, Fts5SegIter *pIter){
|
||||
int iRowidOff;
|
||||
iRowidOff = fts5LeafFirstRowidOff(pNew);
|
||||
if( iRowidOff ){
|
||||
if( iRowidOff>=pNew->szLeaf ){
|
||||
p->rc = FTS5_CORRUPT;
|
||||
}else{
|
||||
pIter->pLeaf = pNew;
|
||||
pIter->iLeafOffset = iRowidOff;
|
||||
}
|
||||
pIter->pLeaf = pNew;
|
||||
pIter->iLeafOffset = iRowidOff;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2164,7 +2117,7 @@ static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
|
||||
if( pDlidx ){
|
||||
int iSegid = pIter->pSeg->iSegid;
|
||||
pgnoLast = fts5DlidxIterPgno(pDlidx);
|
||||
pLast = fts5LeafRead(p, FTS5_SEGMENT_ROWID(iSegid, pgnoLast));
|
||||
pLast = fts5DataRead(p, FTS5_SEGMENT_ROWID(iSegid, pgnoLast));
|
||||
}else{
|
||||
Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */
|
||||
|
||||
@@ -2191,7 +2144,7 @@ static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
|
||||
** forward to find the page containing the last rowid. */
|
||||
for(pgno=pIter->iLeafPgno+1; !p->rc && pgno<=pSeg->pgnoLast; pgno++){
|
||||
i64 iAbs = FTS5_SEGMENT_ROWID(pSeg->iSegid, pgno);
|
||||
Fts5Data *pNew = fts5LeafRead(p, iAbs);
|
||||
Fts5Data *pNew = fts5DataRead(p, iAbs);
|
||||
if( pNew ){
|
||||
int iRowid, bTermless;
|
||||
iRowid = fts5LeafFirstRowidOff(pNew);
|
||||
@@ -2222,10 +2175,6 @@ static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
|
||||
pIter->pLeaf = pLast;
|
||||
pIter->iLeafPgno = pgnoLast;
|
||||
iOff = fts5LeafFirstRowidOff(pLast);
|
||||
if( iOff>pLast->szLeaf ){
|
||||
p->rc = FTS5_CORRUPT;
|
||||
return;
|
||||
}
|
||||
iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
|
||||
pIter->iLeafOffset = iOff;
|
||||
|
||||
@@ -2234,6 +2183,7 @@ static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
|
||||
}else{
|
||||
pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fts5SegIterReverseInitPage(p, pIter);
|
||||
@@ -2285,20 +2235,21 @@ static void fts5LeafSeek(
|
||||
Fts5SegIter *pIter, /* Iterator to seek */
|
||||
const u8 *pTerm, int nTerm /* Term to search for */
|
||||
){
|
||||
u32 iOff;
|
||||
int iOff;
|
||||
const u8 *a = pIter->pLeaf->p;
|
||||
u32 n = (u32)pIter->pLeaf->nn;
|
||||
int szLeaf = pIter->pLeaf->szLeaf;
|
||||
int n = pIter->pLeaf->nn;
|
||||
|
||||
u32 nMatch = 0;
|
||||
u32 nKeep = 0;
|
||||
u32 nNew = 0;
|
||||
u32 iTermOff;
|
||||
u32 iPgidx; /* Current offset in pgidx */
|
||||
int iPgidx; /* Current offset in pgidx */
|
||||
int bEndOfPage = 0;
|
||||
|
||||
assert( p->rc==SQLITE_OK );
|
||||
|
||||
iPgidx = (u32)pIter->pLeaf->szLeaf;
|
||||
iPgidx = szLeaf;
|
||||
iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
|
||||
iOff = iTermOff;
|
||||
if( iOff>n ){
|
||||
@@ -2364,15 +2315,15 @@ static void fts5LeafSeek(
|
||||
if( pIter->pLeaf==0 ) return;
|
||||
a = pIter->pLeaf->p;
|
||||
if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
|
||||
iPgidx = (u32)pIter->pLeaf->szLeaf;
|
||||
iPgidx = pIter->pLeaf->szLeaf;
|
||||
iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
|
||||
if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
|
||||
if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){
|
||||
p->rc = FTS5_CORRUPT;
|
||||
return;
|
||||
}else{
|
||||
nKeep = 0;
|
||||
iTermOff = iOff;
|
||||
n = (u32)pIter->pLeaf->nn;
|
||||
n = pIter->pLeaf->nn;
|
||||
iOff += fts5GetVarint32(&a[iOff], nNew);
|
||||
break;
|
||||
}
|
||||
@@ -2740,7 +2691,7 @@ static void fts5SegIterGotoPage(
|
||||
fts5SegIterNextPage(p, pIter);
|
||||
assert( p->rc!=SQLITE_OK || pIter->iLeafPgno==iLeafPgno );
|
||||
|
||||
if( p->rc==SQLITE_OK && ALWAYS(pIter->pLeaf!=0) ){
|
||||
if( p->rc==SQLITE_OK ){
|
||||
int iOff;
|
||||
u8 *a = pIter->pLeaf->p;
|
||||
int n = pIter->pLeaf->szLeaf;
|
||||
@@ -3172,11 +3123,7 @@ static void fts5SegiterPoslist(
|
||||
Fts5Colset *pColset,
|
||||
Fts5Buffer *pBuf
|
||||
){
|
||||
assert( pBuf!=0 );
|
||||
assert( pSeg!=0 );
|
||||
if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){
|
||||
assert( pBuf->p!=0 );
|
||||
assert( pBuf->nSpace >= pBuf->n+pSeg->nPos+FTS5_DATA_ZERO_PADDING );
|
||||
memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING);
|
||||
if( pColset==0 ){
|
||||
fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback);
|
||||
@@ -3400,7 +3347,6 @@ static void fts5IterSetOutputs_Full(Fts5Iter *pIter, Fts5SegIter *pSeg){
|
||||
}
|
||||
|
||||
static void fts5IterSetOutputCb(int *pRc, Fts5Iter *pIter){
|
||||
assert( pIter!=0 || (*pRc)!=SQLITE_OK );
|
||||
if( *pRc==SQLITE_OK ){
|
||||
Fts5Config *pConfig = pIter->pIndex->pConfig;
|
||||
if( pConfig->eDetail==FTS5_DETAIL_NONE ){
|
||||
@@ -3472,10 +3418,7 @@ static void fts5MultiIterNew(
|
||||
}
|
||||
}
|
||||
*ppOut = pNew = fts5MultiIterAlloc(p, nSeg);
|
||||
if( pNew==0 ){
|
||||
assert( p->rc!=SQLITE_OK );
|
||||
goto fts5MultiIterNew_post_check;
|
||||
}
|
||||
if( pNew==0 ) return;
|
||||
pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC));
|
||||
pNew->bSkipEmpty = (0!=(flags & FTS5INDEX_QUERY_SKIPEMPTY));
|
||||
pNew->pColset = pColset;
|
||||
@@ -3539,10 +3482,6 @@ static void fts5MultiIterNew(
|
||||
fts5MultiIterFree(pNew);
|
||||
*ppOut = 0;
|
||||
}
|
||||
|
||||
fts5MultiIterNew_post_check:
|
||||
assert( (*ppOut)!=0 || p->rc!=SQLITE_OK );
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3590,8 +3529,7 @@ static void fts5MultiIterNew2(
|
||||
** False otherwise.
|
||||
*/
|
||||
static int fts5MultiIterEof(Fts5Index *p, Fts5Iter *pIter){
|
||||
assert( pIter!=0 || p->rc!=SQLITE_OK );
|
||||
assert( p->rc!=SQLITE_OK
|
||||
assert( p->rc
|
||||
|| (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->base.bEof
|
||||
);
|
||||
return (p->rc || pIter->base.bEof);
|
||||
@@ -4395,7 +4333,6 @@ static void fts5IndexMergeLevel(
|
||||
** and last leaf page number at the same time. */
|
||||
fts5WriteFinish(p, &writer, &pSeg->pgnoLast);
|
||||
|
||||
assert( pIter!=0 || p->rc!=SQLITE_OK );
|
||||
if( fts5MultiIterEof(p, pIter) ){
|
||||
int i;
|
||||
|
||||
@@ -4496,7 +4433,7 @@ static void fts5IndexAutomerge(
|
||||
Fts5Structure **ppStruct, /* IN/OUT: Current structure of index */
|
||||
int nLeaf /* Number of output leaves just written */
|
||||
){
|
||||
if( p->rc==SQLITE_OK && p->pConfig->nAutomerge>0 && ALWAYS((*ppStruct)!=0) ){
|
||||
if( p->rc==SQLITE_OK && p->pConfig->nAutomerge>0 ){
|
||||
Fts5Structure *pStruct = *ppStruct;
|
||||
u64 nWrite; /* Initial value of write-counter */
|
||||
int nWork; /* Number of work-quanta to perform */
|
||||
@@ -5565,7 +5502,7 @@ int sqlite3Fts5IndexQuery(
|
||||
if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
|
||||
int iIdx = 0; /* Index to search */
|
||||
int iPrefixIdx = 0; /* +1 prefix index */
|
||||
if( nToken>0 ) memcpy(&buf.p[1], pToken, nToken);
|
||||
if( nToken ) memcpy(&buf.p[1], pToken, nToken);
|
||||
|
||||
/* Figure out which index to search and set iIdx accordingly. If this
|
||||
** is a prefix query for which there is no prefix index, set iIdx to
|
||||
@@ -5606,15 +5543,11 @@ int sqlite3Fts5IndexQuery(
|
||||
/* Scan multiple terms in the main index */
|
||||
int bDesc = (flags & FTS5INDEX_QUERY_DESC)!=0;
|
||||
fts5SetupPrefixIter(p, bDesc, iPrefixIdx, buf.p, nToken+1, pColset,&pRet);
|
||||
if( pRet==0 ){
|
||||
assert( p->rc!=SQLITE_OK );
|
||||
}else{
|
||||
assert( pRet->pColset==0 );
|
||||
fts5IterSetOutputCb(&p->rc, pRet);
|
||||
if( p->rc==SQLITE_OK ){
|
||||
Fts5SegIter *pSeg = &pRet->aSeg[pRet->aFirst[1].iFirst];
|
||||
if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg);
|
||||
}
|
||||
assert( p->rc!=SQLITE_OK || pRet->pColset==0 );
|
||||
fts5IterSetOutputCb(&p->rc, pRet);
|
||||
if( p->rc==SQLITE_OK ){
|
||||
Fts5SegIter *pSeg = &pRet->aSeg[pRet->aFirst[1].iFirst];
|
||||
if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5862,7 +5795,7 @@ static int fts5QueryCksum(
|
||||
Fts5IndexIter *pIter = 0;
|
||||
int rc = sqlite3Fts5IndexQuery(p, z, n, flags, 0, &pIter);
|
||||
|
||||
while( rc==SQLITE_OK && ALWAYS(pIter!=0) && 0==sqlite3Fts5IterEof(pIter) ){
|
||||
while( rc==SQLITE_OK && 0==sqlite3Fts5IterEof(pIter) ){
|
||||
i64 rowid = pIter->iRowid;
|
||||
|
||||
if( eDetail==FTS5_DETAIL_NONE ){
|
||||
@@ -6227,7 +6160,6 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
|
||||
Fts5Buffer poslist = {0,0,0}; /* Buffer used to hold a poslist */
|
||||
Fts5Iter *pIter; /* Used to iterate through entire index */
|
||||
Fts5Structure *pStruct; /* Index structure */
|
||||
int iLvl, iSeg;
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
/* Used by extra internal tests only run if NDEBUG is not defined */
|
||||
@@ -6238,16 +6170,15 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
|
||||
|
||||
/* Load the FTS index structure */
|
||||
pStruct = fts5StructureRead(p);
|
||||
if( pStruct==0 ){
|
||||
assert( p->rc!=SQLITE_OK );
|
||||
return fts5IndexReturn(p);
|
||||
}
|
||||
|
||||
/* Check that the internal nodes of each segment match the leaves */
|
||||
for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
|
||||
for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
|
||||
Fts5StructureSegment *pSeg = &pStruct->aLevel[iLvl].aSeg[iSeg];
|
||||
fts5IndexIntegrityCheckSegment(p, pSeg);
|
||||
if( pStruct ){
|
||||
int iLvl, iSeg;
|
||||
for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
|
||||
for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
|
||||
Fts5StructureSegment *pSeg = &pStruct->aLevel[iLvl].aSeg[iSeg];
|
||||
fts5IndexIntegrityCheckSegment(p, pSeg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -804,7 +804,7 @@ static int fts5SorterNext(Fts5Cursor *pCsr){
|
||||
rc = sqlite3_step(pSorter->pStmt);
|
||||
if( rc==SQLITE_DONE ){
|
||||
rc = SQLITE_OK;
|
||||
CsrFlagSet(pCsr, FTS5CSR_EOF|FTS5CSR_REQUIRE_CONTENT);
|
||||
CsrFlagSet(pCsr, FTS5CSR_EOF);
|
||||
}else if( rc==SQLITE_ROW ){
|
||||
const u8 *a;
|
||||
const u8 *aBlob;
|
||||
@@ -1374,8 +1374,7 @@ static int fts5FilterMethod(
|
||||
pTab->pStorage, fts5StmtType(pCsr), &pCsr->pStmt, &pTab->p.base.zErrMsg
|
||||
);
|
||||
if( rc==SQLITE_OK ){
|
||||
if( pRowidEq!=0 ){
|
||||
assert( pCsr->ePlan==FTS5_PLAN_ROWID );
|
||||
if( pCsr->ePlan==FTS5_PLAN_ROWID ){
|
||||
sqlite3_bind_value(pCsr->pStmt, 1, pRowidEq);
|
||||
}else{
|
||||
sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iFirstRowid);
|
||||
|
||||
@@ -417,16 +417,12 @@ static int fts5StorageDeleteFromIndex(
|
||||
if( pConfig->abUnindexed[iCol-1]==0 ){
|
||||
const char *zText;
|
||||
int nText;
|
||||
assert( pSeek==0 || apVal==0 );
|
||||
assert( pSeek!=0 || apVal!=0 );
|
||||
if( pSeek ){
|
||||
zText = (const char*)sqlite3_column_text(pSeek, iCol);
|
||||
nText = sqlite3_column_bytes(pSeek, iCol);
|
||||
}else if( ALWAYS(apVal) ){
|
||||
}else{
|
||||
zText = (const char*)sqlite3_value_text(apVal[iCol-1]);
|
||||
nText = sqlite3_value_bytes(apVal[iCol-1]);
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
ctx.szCol = 0;
|
||||
rc = sqlite3Fts5Tokenize(pConfig, FTS5_TOKENIZE_DOCUMENT,
|
||||
@@ -1062,9 +1058,8 @@ int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol){
|
||||
|
||||
assert( p->pConfig->bColumnsize );
|
||||
rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
|
||||
if( pLookup ){
|
||||
if( rc==SQLITE_OK ){
|
||||
int bCorrupt = 1;
|
||||
assert( rc==SQLITE_OK );
|
||||
sqlite3_bind_int64(pLookup, 1, iRowid);
|
||||
if( SQLITE_ROW==sqlite3_step(pLookup) ){
|
||||
const u8 *aBlob = sqlite3_column_blob(pLookup, 0);
|
||||
@@ -1077,8 +1072,6 @@ int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol){
|
||||
if( bCorrupt && rc==SQLITE_OK ){
|
||||
rc = FTS5_CORRUPT;
|
||||
}
|
||||
}else{
|
||||
assert( rc!=SQLITE_OK );
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
@@ -374,7 +374,7 @@ static int fts5VocabOpenMethod(
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
i64 nByte = pFts5->pConfig->nCol * sizeof(i64)*2 + sizeof(Fts5VocabCursor);
|
||||
int nByte = pFts5->pConfig->nCol * sizeof(i64)*2 + sizeof(Fts5VocabCursor);
|
||||
pCsr = (Fts5VocabCursor*)sqlite3Fts5MallocZero(&rc, nByte);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ do_execsql_test 4.0 {
|
||||
}
|
||||
|
||||
do_execsql_test 5.0 {
|
||||
CREATE VIRTUAL TABLE p1 USING fts5(a, b, detail=%DETAIL%);
|
||||
CREATE VIRTUAL TABLE p1 USING fts5(a, b);
|
||||
INSERT INTO p1 VALUES(
|
||||
'x a a a a a a a a a a',
|
||||
'a a a a a a a a a a a a a a a a a a a x'
|
||||
@@ -184,12 +184,6 @@ do_execsql_test 5.3 {
|
||||
do_execsql_test 5.4 {
|
||||
SELECT snippet(p1, 0, '[', NULL, '...', 6) FROM p1('x');
|
||||
} {{[x a a a a a...}}
|
||||
do_execsql_test 5.5 {
|
||||
SELECT snippet(p1, 0, '[', NULL, '...', 6) FROM p1('x OR ""');
|
||||
} {{[x a a a a a...}}
|
||||
do_execsql_test 5.6 {
|
||||
SELECT snippet(p1, 0, '[', NULL, '...', 6) FROM p1('x OR ' || x'DB');
|
||||
} {{[x a a a a a...}}
|
||||
|
||||
} ;# foreach_detail_mode
|
||||
|
||||
|
||||
@@ -15366,160 +15366,6 @@ do_catchsql_test 79.2 {
|
||||
INSERT INTO t1(t1) SELECT 'merge' FROM t2;
|
||||
} {1 {query aborted}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_test 80.0 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
.open --hexdb
|
||||
| size 40960 pagesize 4096 filename crash-f928a9c1ec68dd.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 0a .....@ ........
|
||||
| 32: 00 00 00 00 00 00 00 00 00 00 00 0d 00 00 00 04 ................
|
||||
| 96: 00 00 00 00 0d 00 00 00 0d 0b 6e 00 0f a3 0f 4c ..........n....L
|
||||
| 112: 0e e1 0e 81 0e 24 0d cc 0d 72 0d 1b 0c b0 0c 50 .....$...r.....P
|
||||
| 128: 0b f8 0b b3 0b 6e 00 00 00 00 00 00 00 00 00 00 .....n..........
|
||||
| 2912: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 43 0d ..............C.
|
||||
| 2928: 06 17 11 11 08 75 74 61 62 6c 65 74 34 74 34 43 .....utablet4t4C
|
||||
| 2944: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 REATE VIRTUAL TA
|
||||
| 2960: 42 4c 45 20 74 34 20 55 53 49 4e 47 20 66 74 73 BLE t4 USING fts
|
||||
| 2976: 35 76 6f 63 61 62 28 27 74 32 27 2c 20 27 72 6f 5vocab('t2', 'ro
|
||||
| 2992: 77 27 29 43 0c 06 17 11 11 08 75 74 61 62 6c 65 w')C......utable
|
||||
| 3008: 74 33 74 33 43 52 45 41 54 45 20 56 49 52 54 55 t3t3CREATE VIRTU
|
||||
| 3024: 41 4c 20 54 41 42 4c 45 20 74 33 20 55 53 49 4e AL TABLE t3 USIN
|
||||
| 3040: 47 20 66 74 73 35 76 6f 63 61 62 28 27 74 31 27 G fts5vocab('t1'
|
||||
| 3056: 2c 20 27 72 6f 77 27 29 56 0b 06 17 1f 1f 01 7d , 'row')V.......
|
||||
| 3072: 74 61 62 6c 65 74 32 5f 63 6f 6e 66 69 67 74 32 tablet2_configt2
|
||||
| 3088: 5f 63 6f 6e 66 69 67 0a 43 52 45 41 54 45 20 54 _config.CREATE T
|
||||
| 3104: 41 42 4c 45 20 27 74 32 5f 63 6f 6e 66 69 67 27 ABLE 't2_config'
|
||||
| 3120: 28 6b 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 (k PRIMARY KEY,
|
||||
| 3136: 76 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 v) WITHOUT ROWID
|
||||
| 3152: 5e 0a 07 17 21 21 01 81 07 74 61 62 6c 65 74 32 ^...!!...tablet2
|
||||
| 3168: 5f 63 6f 6e 74 65 6e 74 74 32 5f 63 6f 6e 74 65 _contentt2_conte
|
||||
| 3184: 6e 74 09 43 52 45 41 54 45 20 54 41 42 4c 45 20 nt.CREATE TABLE
|
||||
| 3200: 27 74 32 5f 63 6f 6e 74 65 6e 74 27 28 69 64 20 't2_content'(id
|
||||
| 3216: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 INTEGER PRIMARY
|
||||
| 3232: 4b 45 59 2c 20 63 30 2c 20 63 31 2c 20 63 32 29 KEY, c0, c1, c2)
|
||||
| 3248: 69 09 07 17 19 19 01 81 2d 74 61 62 6c 65 74 32 i.......-tablet2
|
||||
| 3264: 5f 69 64 78 74 32 5f 69 64 78 08 43 52 45 41 54 _idxt2_idx.CREAT
|
||||
| 3280: 45 20 54 41 42 4c 45 20 27 74 32 5f 69 64 78 27 E TABLE 't2_idx'
|
||||
| 3296: 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20 70 67 (segid, term, pg
|
||||
| 3312: 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 28 no, PRIMARY KEY(
|
||||
| 3328: 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20 57 49 segid, term)) WI
|
||||
| 3344: 54 48 4f 55 54 20 52 4f 57 49 44 55 08 07 17 1b THOUT ROWIDU....
|
||||
| 3360: 1b 01 81 01 74 61 62 6c 65 74 32 5f 64 61 74 61 ....tablet2_data
|
||||
| 3376: 74 32 5f 64 61 74 61 07 43 52 45 41 54 45 20 54 t2_data.CREATE T
|
||||
| 3392: 41 42 4c 45 20 27 74 32 5f 64 61 74 61 27 28 69 ABLE 't2_data'(i
|
||||
| 3408: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 d INTEGER PRIMAR
|
||||
| 3424: 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f Y KEY, block BLO
|
||||
| 3440: 42 29 58 07 07 17 11 11 08 81 1d 74 61 62 6c 65 B)X........table
|
||||
| 3456: 74 32 74 32 43 52 45 41 54 45 20 56 49 52 54 55 t2t2CREATE VIRTU
|
||||
| 3472: 41 4c 20 54 41 42 4c 45 20 74 32 20 55 53 49 4e AL TABLE t2 USIN
|
||||
| 3488: 47 20 66 74 73 35 28 27 61 27 2c 5b 62 5d 2c 22 G fts5('a',[b],.
|
||||
| 3504: 63 22 2c 64 65 74 61 69 6c 3d 6e 6f 6e 65 2c 63 c.,detail=none,c
|
||||
| 3520: 6f 6c 75 6d 6e 73 69 7a 65 3d 30 29 56 06 06 17 olumnsize=0)V...
|
||||
| 3536: 1f 1f 01 7d 74 61 62 6c 65 74 31 5f 63 6f 6e 66 ....tablet1_conf
|
||||
| 3552: 69 67 74 31 5f 63 6f 6e 66 69 67 06 43 52 45 41 igt1_config.CREA
|
||||
| 3568: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f 6e TE TABLE 't1_con
|
||||
| 3584: 66 69 67 27 28 6b 20 50 52 49 4d 41 52 59 20 4b fig'(k PRIMARY K
|
||||
| 3600: 45 59 2c 20 76 29 20 57 49 54 48 4f 55 54 20 52 EY, v) WITHOUT R
|
||||
| 3616: 4f 57 49 44 5b 05 07 17 21 21 01 81 01 74 61 62 OWID[...!!...tab
|
||||
| 3632: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64 let1_docsizet1_d
|
||||
| 3648: 6f 63 73 69 7a 65 05 43 52 45 41 54 45 20 54 41 ocsize.CREATE TA
|
||||
| 3664: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27 BLE 't1_docsize'
|
||||
| 3680: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d (id INTEGER PRIM
|
||||
| 3696: 41 52 59 20 4b 45 59 2c 20 73 7a 20 42 4c 4f 42 ARY KEY, sz BLOB
|
||||
| 3712: 29 5e 04 07 17 21 21 01 81 07 74 61 62 6c 65 74 )^...!!...tablet
|
||||
| 3728: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont
|
||||
| 3744: 65 6e 74 04 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE
|
||||
| 3760: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 69 64 't1_content'(id
|
||||
| 3776: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY
|
||||
| 3792: 20 4b 45 59 2c 20 63 30 2c 20 63 31 2c 20 63 32 KEY, c0, c1, c2
|
||||
| 3808: 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65 74 )i.......-tablet
|
||||
| 3824: 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45 41 1_idxt1_idx.CREA
|
||||
| 3840: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64 78 TE TABLE 't1_idx
|
||||
| 3856: 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20 70 '(segid, term, p
|
||||
| 3872: 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 gno, PRIMARY KEY
|
||||
| 3888: 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20 57 (segid, term)) W
|
||||
| 3904: 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07 17 ITHOUT ROWIDU...
|
||||
| 3920: 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61 74 .....tablet1_dat
|
||||
| 3936: 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45 20 at1_data.CREATE
|
||||
| 3952: 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27 28 TABLE 't1_data'(
|
||||
| 3968: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 id INTEGER PRIMA
|
||||
| 3984: 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c RY KEY, block BL
|
||||
| 4000: 4f 42 29 5b 01 07 17 11 11 08 81 23 74 61 62 6c OB)[.......#tabl
|
||||
| 4016: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54 et1t1CREATE VIRT
|
||||
| 4032: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49 UAL TABLE t1 USI
|
||||
| 4048: 4e 47 20 66 74 73 35 28 61 2c 62 20 75 6e 69 6e NG fts5(a,b unin
|
||||
| 4064: 64 65 78 65 64 2c 63 2c 74 6f 6b 65 6e 69 7a 65 dexed,c,tokenize
|
||||
| 4080: 3d 22 70 6f 72 74 65 72 20 61 73 63 69 69 22 29 =.porter ascii.)
|
||||
| page 2 offset 4096
|
||||
| 0: 0d 0f 68 00 05 0f 13 00 0f e6 0f 13 0f a8 0f 7c ..h............|
|
||||
| 16: 0f 2a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .*..............
|
||||
| 3856: 00 00 00 15 0a 03 00 30 00 00 00 00 01 03 03 00 .......0........
|
||||
| 3872: 03 01 01 01 02 01 01 03 01 01 37 8c 80 80 80 80 ..........7.....
|
||||
| 3888: 01 03 00 74 00 00 00 2e 02 30 61 03 02 02 01 01 ...t.....0a.....
|
||||
| 3904: 62 03 02 03 01 01 63 03 02 04 01 01 67 03 06 01 b.....c.....g...
|
||||
| 3920: 02 02 01 01 68 03 06 01 02 03 01 01 69 03 06 01 ....h.......i...
|
||||
| 3936: 02 04 04 06 06 06 08 08 0f ef 00 14 2a 00 00 00 ............*...
|
||||
| 3952: 00 01 02 02 00 02 01 01 01 02 01 01 25 88 80 80 ............%...
|
||||
| 3968: 80 80 01 03 00 50 00 00 00 1f 02 30 67 02 08 02 .....P.....0g...
|
||||
| 3984: 01 02 02 01 01 68 02 08 03 01 02 03 01 01 69 02 .....h........i.
|
||||
| 4000: 08 04 01 02 04 04 09 09 37 84 80 80 80 80 01 03 ........7.......
|
||||
| 4016: 00 74 00 00 00 2e 02 30 61 01 02 02 01 01 62 01 .t.....0a.....b.
|
||||
| 4032: 02 03 01 01 63 01 02 04 01 01 67 01 06 01 02 02 ....c.....g.....
|
||||
| 4048: 01 01 68 01 06 01 02 03 01 01 69 01 06 01 02 04 ..h.......i.....
|
||||
| 4064: 04 06 06 06 08 08 07 01 03 00 14 03 09 00 09 00 ................
|
||||
| 4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01 ...$............
|
||||
| page 3 offset 8192
|
||||
| 0: 0a 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c ................
|
||||
| 4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02 ................
|
||||
| page 4 offset 12288
|
||||
| 0: 0d 00 00 00 03 0f be 00 0f ea 0f d4 0f be 00 00 ................
|
||||
| 4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 03 ................
|
||||
| 4032: 05 00 17 17 17 61 20 62 20 63 67 20 68 20 69 67 .....a b cg h ig
|
||||
| 4048: 20 68 20 69 14 02 05 00 17 17 17 67 20 68 20 69 h i.......g h i
|
||||
| 4064: 61 20 62 20 63 67 20 68 20 69 14 01 05 00 17 17 a b cg h i......
|
||||
| 4080: 17 61 20 62 20 63 64 20 65 20 66 67 20 68 20 69 .a b cd e fg h i
|
||||
| page 5 offset 16384
|
||||
| 0: 0d 00 00 00 03 0f e8 00 0f f8 0f f0 0f e8 00 00 ................
|
||||
| 4064: 00 00 00 00 00 00 00 00 06 03 03 00 12 03 00 03 ................
|
||||
| 4080: 06 02 03 00 12 03 00 03 06 01 03 00 12 03 00 03 ................
|
||||
| page 6 offset 20480
|
||||
| 0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 01 00 00 00 ................
|
||||
| 4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04 ........version.
|
||||
| page 7 offset 24576
|
||||
| 0: 0d 00 00 00 03 0f 9e 00 0f e6 0f ef 00 00 00 00 ................
|
||||
| 3984: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 84 ..............A.
|
||||
| 4000: 80 80 80 80 01 04 00 81 06 00 00 00 34 02 30 61 ............4.0a
|
||||
| 4016: 01 01 01 01 01 62 01 01 01 01 01 63 01 01 01 01 .....b.....c....
|
||||
| 4032: 01 64 01 01 01 65 01 01 01 66 01 01 01 67 01 01 .d...e...f...g..
|
||||
| 4048: 01 01 01 68 01 01 01 01 01 69 01 01 01 04 06 06 ...h.....i......
|
||||
| 4064: 06 04 04 04 06 06 07 01 03 00 14 03 09 09 09 0f ................
|
||||
| 4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01 ...$............
|
||||
| page 8 offset 28672
|
||||
| 0: 0a 00 00 00 01 0f fa 00 00 00 00 00 00 00 00 00 ................
|
||||
| 4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 12 ................
|
||||
| page 9 offset 32768
|
||||
| 0: 0d 00 00 00 03 0f be 00 0f ea 0f d4 0f be 00 00 ................
|
||||
| 4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 03 ................
|
||||
| 4032: 05 00 17 17 17 61 20 62 20 63 67 20 68 20 69 67 .....a b cg h ig
|
||||
| 4048: 20 68 20 69 14 02 05 00 17 17 17 67 20 68 20 69 h i.......g h i
|
||||
| 4064: 61 20 62 20 63 67 20 68 20 69 14 01 05 00 17 17 a b cg h i......
|
||||
| 4080: 17 61 20 62 20 63 64 20 65 20 66 67 20 68 20 69 .a b cd e fg h i
|
||||
| page 10 offset 36864
|
||||
| 0: 0a 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 00 00 00 00 ........vers....
|
||||
| end crash-f928a9c1ec68dd.db
|
||||
}]} {}
|
||||
|
||||
do_catchsql_test 80.1 {
|
||||
SELECT snippet(rowid, -1, '.', '..', '[', '(]'),snippet(rowid, -1, '.', '.', '', '(]'), highlight(t1, 29, 1 , '') FROM t1('g+ h') WHERE rank MATCH 'bm25(1.0, 10)' ORDER BY NOT (SELECT 1 FROM t1('g+ æ') WHERE rank MATCH 'bm25(1.0, 10)' ORDER BY rank);
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
|
||||
sqlite3_fts5_may_be_corrupt 0
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -1,798 +0,0 @@
|
||||
# 2015 Apr 24
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file tests that FTS5 handles corrupt databases (i.e. internal
|
||||
# inconsistencies in the backing tables) correctly. In this case
|
||||
# "correctly" means without crashing.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5corrupt3
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
sqlite3_fts5_may_be_corrupt 1
|
||||
database_may_be_corrupt
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# dbsqlfuzz crash-0f47112aa7520cf08c6a835a88fdff8c2a32a188
|
||||
#
|
||||
reset_db
|
||||
do_test 1.0 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
.open --hexdb
|
||||
| size 24576 pagesize 4096 filename crash-0f47112aa7520c.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........
|
||||
| 96: 00 00 00 00 0d 00 00 00 06 0e 0f 00 0f aa 0f 53 ...............S
|
||||
| 112: 0e e8 0e 8b 0e 33 0e 0f 00 00 00 00 00 00 00 00 .....3..........
|
||||
| 3584: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 ................
|
||||
| 3600: 06 06 17 11 11 01 31 74 61 62 6c 65 62 62 62 62 ......1tablebbbb
|
||||
| 3616: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 62 62 .CREATE TABLE bb
|
||||
| 3632: 28 61 29 56 05 06 17 1f 1f 01 7d 74 61 62 6c 65 (a)V.......table
|
||||
| 3648: 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 6f 6e 66 t1_configt1_conf
|
||||
| 3664: 69 67 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 ig.CREATE TABLE
|
||||
| 3680: 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b 20 50 52 't1_config'(k PR
|
||||
| 3696: 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 20 57 49 IMARY KEY, v) WI
|
||||
| 3712: 54 48 4f 55 54 20 52 4f 57 49 44 5b 04 07 17 21 THOUT ROWID[...!
|
||||
| 3728: 21 01 81 01 74 61 62 6c 65 74 31 5f 64 6f 63 73 !...tablet1_docs
|
||||
| 3744: 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 04 43 52 izet1_docsize.CR
|
||||
| 3760: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64 EATE TABLE 't1_d
|
||||
| 3776: 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47 ocsize'(id INTEG
|
||||
| 3792: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
|
||||
| 3808: 73 7a 20 42 4c 4f 42 29 69 03 07 17 19 19 01 81 sz BLOB)i.......
|
||||
| 3824: 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 5f 69 -tablet1_idxt1_i
|
||||
| 3840: 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 dx.CREATE TABLE
|
||||
| 3856: 27 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20 't1_idx'(segid,
|
||||
| 3872: 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 4d term, pgno, PRIM
|
||||
| 3888: 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74 ARY KEY(segid, t
|
||||
| 3904: 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f erm)) WITHOUT RO
|
||||
| 3920: 57 49 44 55 02 07 17 1b 1b 01 81 01 74 61 62 6c WIDU........tabl
|
||||
| 3936: 65 74 31 5f 64 61 74 61 74 31 5f 64 61 74 61 02 et1_datat1_data.
|
||||
| 3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 CREATE TABLE 't1
|
||||
| 3968: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45 _data'(id INTEGE
|
||||
| 3984: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 R PRIMARY KEY, b
|
||||
| 4000: 6c 6f 63 6b 20 42 4c 4f 42 29 54 01 07 17 11 11 lock BLOB)T.....
|
||||
| 4016: 08 81 15 74 61 62 6c 65 74 31 74 31 43 52 45 41 ...tablet1t1CREA
|
||||
| 4032: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 TE VIRTUAL TABLE
|
||||
| 4048: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 61 t1 USING fts5(a
|
||||
| 4064: 2c 62 2c 70 72 65 66 69 78 3d 22 31 2c 32 2c 33 ,b,prefix=.1,2,3
|
||||
| 4080: 2c 34 22 2c 20 63 6f 6e 74 65 6e 74 3d 22 22 29 ,4., content=..)
|
||||
| page 2 offset 4096
|
||||
| 0: 0d 0b 6a 00 37 09 4c 02 0f e7 09 4c 0f c6 0f a4 ..j.7.L....L....
|
||||
| 16: 0f 88 0f 6d 0f 4b 0f 2c 0f 0e 0e ec 0e cd 0e ad ...m.K.,........
|
||||
| 32: 0e 8e 0e 6c 0e 4b 0e 29 0e 08 0d e6 0d c4 0d b5 ...l.K.)........
|
||||
| 48: 0d 97 0d 76 0d 54 0d 31 0d 15 0c f3 0c d3 0c b5 ...v.T.1........
|
||||
| 64: 0c 95 0c 73 0c 54 0c 32 0c 10 0b ee 0b cc 0b b0 ...s.T.2........
|
||||
| 80: 0b 8d 0b 7e 0b 48 0b 2e 0b 0b 0a ef 00 00 00 00 ...~.H..........
|
||||
| 2368: 00 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00 ................
|
||||
| 2384: 30 00 00 00 01 01 03 35 00 03 01 11 12 02 01 12 0......5........
|
||||
| 2400: 03 01 11 1c 8c 80 80 80 80 10 03 00 3e 00 00 00 ............>...
|
||||
| 2416: 17 01 05 05 34 74 61 62 6c 03 02 03 01 04 77 68 ....4tabl.....wh
|
||||
| 2432: 65 72 03 02 06 09 1b 8c 80 80 80 80 0f 03 00 3c er.............<
|
||||
| 2448: 00 00 00 16 05 34 66 74 73 34 03 02 02 01 04 6e .....4fts4.....n
|
||||
| 2464: 75 6d 62 03 06 01 04 09 1b 8c 80 80 80 80 0e 03 umb.............
|
||||
| 2480: 00 3c 00 00 00 16 04 33 74 68 65 03 06 01 01 04 .<.....3the.....
|
||||
| 2496: 01 03 77 68 65 03 02 04 04 0a 1b 8c 80 80 80 80 ..whe...........
|
||||
| 2512: 0d 03 00 3c 00 00 00 16 04 33 6e 75 6d 03 06 01 ...<.....3num...
|
||||
| 2528: 01 05 01 03 74 61 62 03 02 03 04 0a 19 8c 80 80 ....tab.........
|
||||
| 2544: 80 80 0c 03 00 38 00 00 00 14 03 32 77 68 03 02 .....8.....2wh..
|
||||
| 2560: 04 00 04 33 66 74 73 03 02 02 04 07 18 8c 80 80 ...3fts.........
|
||||
| 2576: 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 03 02 .....6.....2ta..
|
||||
| 2592: 03 02 01 68 03 06 01 01 04 04 07 1b 8c 80 80 80 ...h............
|
||||
| 2608: 80 0a 03 00 3c 00 00 00 16 03 32 6e 75 03 06 01 ....<.....2nu...
|
||||
| 2624: 01 05 01 02 6f 66 03 06 01 01 06 04 09 19 8c 80 ....of..........
|
||||
| 2640: 80 80 80 09 03 00 38 00 00 00 14 03 32 66 74 03 ......8.....2ft.
|
||||
| 2656: 02 02 01 02 69 73 03 06 01 01 03 04 07 18 8c 80 ....is..........
|
||||
| 2672: 80 80 80 08 03 00 36 00 00 00 13 02 31 74 03 08 ......6.....1t..
|
||||
| 2688: 03 01 01 04 01 01 77 03 02 04 04 09 1a 8c 80 80 ......w.........
|
||||
| 2704: 80 80 07 03 00 3a 00 00 00 15 02 31 6e 03 08 01 .....:.....1n...
|
||||
| 2720: 01 02 05 01 00 6f 03 06 01 01 06 04 09 18 8c 80 .....o..........
|
||||
| 2736: 80 80 80 06 03 00 36 00 00 00 03 04 02 31 66 03 ......6......1f.
|
||||
| 2752: 02 02 01 01 69 03 06 01 01 03 04 f6 1c 8c 80 80 ....i...........
|
||||
| 2768: 80 80 05 03 00 3e 00 00 00 17 04 30 74 68 65 03 .....>.....0the.
|
||||
| 2784: f6 01 01 04 01 05 77 68 65 72 65 03 02 04 0a 15 ......where.....
|
||||
| 2800: 8c 80 80 80 80 04 03 00 30 00 00 00 11 01 01 06 ........0.......
|
||||
| 2816: 06 30 74 61 62 6c 65 0f 42 03 07 1c 8c 81 80 80 .0table.B.......
|
||||
| 2832: 80 03 03 00 3e 00 00 00 17 07 30 6e 75 6d 62 65 ....>.....0numbe
|
||||
| 2848: 72 03 06 01 01 05 01 02 6f 66 03 06 04 0d 13 8c r.......of......
|
||||
| 2864: 80 80 80 80 02 03 00 2c 00 00 00 0f 01 01 03 02 .......,........
|
||||
| 2880: 30 6e 03 06 01 01 02 07 1b 8c 80 80 80 80 01 03 0n..............
|
||||
| 2896: 00 3c 00 00 00 16 08 30 66 74 73 34 61 75 78 03 .<.....0fts4aux.
|
||||
| 2912: 02 02 01 02 69 73 03 06 04 0c 00 00 00 14 2a 00 ....is........*.
|
||||
| 2928: 00 00 01 01 02 24 00 02 01 01 12 02 01 12 08 88 .....$..........
|
||||
| 2944: 80 80 80 80 12 03 00 16 00 00 00 05 02 1c 88 80 ................
|
||||
| 2960: 80 80 80 11 03 00 3e 00 00 00 17 05 34 72 6f 77 ......>.....4row
|
||||
| 2976: 73 02 06 01 01 05 01 04 74 68 65 72 02 02 04 0b s.......ther....
|
||||
| 2992: 15 88 80 80 80 80 10 03 00 30 00 00 00 11 02 01 .........0......
|
||||
| 3008: 01 07 05 34 62 65 74 77 02 02 04 08 1b 88 80 80 ...4betw........
|
||||
| 3024: 80 80 0f 03 00 3c 00 00 00 16 04 04 33 72 6f 77 .....<......3row
|
||||
| 3040: 02 06 01 01 05 01 03 74 68 65 02 08 05 0a 1b 88 .......the......
|
||||
| 3056: 80 80 80 80 0e 03 00 3c 00 00 00 16 01 01 02 04 .......<........
|
||||
| 3072: 33 61 72 65 02 02 03 01 03 62 65 74 02 02 07 08 3are.....bet....
|
||||
| 3088: 1b 88 80 80 80 80 0d 03 00 3c 00 00 00 16 13 32 .........<.....2
|
||||
| 3104: 74 68 02 08 02 01 01 07 00 04 33 61 6e 64 02 06 th........3and..
|
||||
| 3120: 04 0a 1b 88 80 80 80 80 0c 03 00 3c 00 00 00 16 ...........<....
|
||||
| 3136: 03 32 69 6e 02 06 01 01 06 01 02 72 6f 02 06 01 .2in.......ro...
|
||||
| 3152: 01 05 04 09 18 88 80 80 80 80 0b 03 00 36 00 00 .............6..
|
||||
| 3168: 00 13 02 03 32 61 72 02 02 03 01 02 62 65 02 02 ....2ar.....be..
|
||||
| 3184: 04 05 07 1b 88 80 80 80 80 0a 03 00 3c 00 9e 00 ............<...
|
||||
| 3200: 16 02 31 74 02 08 02 01 01 07 00 03 32 61 6e 02 ..1t........2an.
|
||||
| 3216: 06 01 01 04 09 19 88 80 80 80 80 09 03 00 38 00 ..............8.
|
||||
| 3232: 00 00 14 02 31 6e 02 06 01 01 03 01 01 72 02 06 ....1n.......r..
|
||||
| 3248: 01 01 05 04 08 17 88 80 80 80 80 08 03 00 34 00 ..............4.
|
||||
| 3264: 00 00 12 02 31 62 02 02 04 01 01 69 02 06 01 01 ....1b.....i....
|
||||
| 3280: 06 04 06 19 88 80 80 80 80 07 03 00 38 00 00 00 ............8...
|
||||
| 3296: 14 04 02 31 32 02 02 05 01 01 61 02 08 03 01 01 ...12.....a.....
|
||||
| 3312: 02 05 06 1b 88 80 80 80 80 06 03 00 3c 00 00 00 ............<...
|
||||
| 3328: 16 06 30 74 68 65 72 65 02 02 02 00 02 31 31 02 ..0there.....11.
|
||||
| 3344: 06 01 01 04 0a 15 88 80 80 80 80 05 03 00 30 00 ..............0.
|
||||
| 3360: 00 00 11 01 01 05 04 30 74 68 65 02 06 01 01 07 .......0the.....
|
||||
| 3376: 07 1c 88 80 80 80 80 04 03 00 3e 00 00 00 17 01 ..........>.....
|
||||
| 3392: 01 06 02 30 6e 02 06 01 01 03 01 04 72 6f 77 73 ...0n.......rows
|
||||
| 3408: 02 06 07 08 1b 88 80 80 80 80 03 03 00 3c 00 00 .............<..
|
||||
| 3424: 00 16 08 30 62 65 74 77 65 65 6e 02 02 04 01 02 ...0between.....
|
||||
| 3440: 69 6e 02 06 04 0c 1a 88 80 80 80 80 02 03 00 3a in.............:
|
||||
| 3456: 00 00 00 15 04 30 61 6e 64 02 06 01 01 02 02 02 .....0and.......
|
||||
| 3472: 72 65 02 02 03 04 0a 17 88 80 80 80 80 01 03 00 re..............
|
||||
| 3488: 34 00 00 00 12 02 30 31 02 06 01 01 04 01 01 32 4.....01.......2
|
||||
| 3504: 02 02 05 04 08 08 84 80 80 80 80 12 03 00 16 00 ................
|
||||
| 3520: 00 00 05 04 1b 84 80 80 80 80 11 03 00 3c 00 00 .............<..
|
||||
| 3536: 00 16 05 34 74 61 62 6c 01 06 01 01 05 02 03 65 ...4tabl.......e
|
||||
| 3552: 72 6d 01 02 04 0b 1b 84 80 80 80 80 10 03 00 3c rm.............<
|
||||
| 3568: 00 00 00 16 05 34 65 61 63 68 01 02 03 01 04 70 .....4each.....p
|
||||
| 3584: 72 65 73 01 02 05 04 08 1a 84 80 80 80 80 0f 03 res.............
|
||||
| 3600: 00 3a 00 00 00 15 04 33 74 65 72 01 02 04 02 02 .:.....3ter.....
|
||||
| 3616: 68 65 01 06 01 01 03 04 08 1b 84 80 80 80 80 0e he..............
|
||||
| 3632: 03 00 3c 00 00 00 16 04 33 80 72 65 01 02 05 01 ..<.....3.re....
|
||||
| 3648: 03 74 61 62 01 06 01 01 05 04 08 1a 84 80 80 80 .tab............
|
||||
| 3664: 80 0d 03 00 3a 00 00 00 15 04 33 66 6f 72 01 02 ....:.....3for..
|
||||
| 3680: 02 02 02 74 73 01 06 01 01 04 04 08 1b 84 80 80 ...ts...........
|
||||
| 3696: 80 80 0c 03 00 3c 00 00 00 17 03 32 74 68 01 06 .....<.....2th..
|
||||
| 3712: 01 01 03 00 04 33 65 61 63 01 02 03 04 09 18 84 .....3eac.......
|
||||
| 3728: 80 80 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 .......6.....2ta
|
||||
| 3744: 01 06 01 01 05 02 01 65 01 02 04 04 09 19 84 80 .......e........
|
||||
| 3760: 80 80 80 0a 03 00 38 00 00 00 14 03 32 69 6e 01 ......8.....2in.
|
||||
| 3776: 06 01 01 02 01 02 70 72 01 02 05 04 09 18 84 80 ......pr........
|
||||
| 3792: 80 80 80 09 03 00 36 00 00 00 13 03 32 66 6f 01 ......6.....2fo.
|
||||
| 3808: 02 02 02 01 74 01 06 01 01 04 04 07 1b 84 80 80 ....t...........
|
||||
| 3824: 80 80 08 03 00 3c 00 00 00 16 02 31 74 01 0a 04 .....<.....1t...
|
||||
| 3840: 01 01 03 04 00 03 32 65 61 01 02 03 04 0a 17 84 ......2ea.......
|
||||
| 3856: 80 80 80 80 07 03 00 34 00 00 00 12 02 31 69 01 .......4.....1i.
|
||||
| 3872: 06 01 01 02 01 01 70 01 02 05 04 08 18 84 80 80 ......p.........
|
||||
| 3888: 80 80 06 03 00 36 00 00 00 13 02 31 65 01 02 03 .....6.....1e...
|
||||
| 3904: 01 01 66 01 08 02 01 01 04 04 06 1b 84 80 80 80 ..f.............
|
||||
| 3920: 80 05 03 00 3c 00 00 00 16 05 30 74 65 72 6d 01 ....<.....0term.
|
||||
| 3936: 02 04 02 02 68 65 01 06 01 01 03 04 09 14 84 80 ....he..........
|
||||
| 3952: 80 80 80 04 03 00 2e 00 00 00 10 06 30 64 61 62 ............0dab
|
||||
| 3968: 6c 65 01 06 01 01 05 04 15 84 80 80 80 80 03 03 le..............
|
||||
| 3984: 00 30 00 00 00 11 02 08 30 70 72 65 73 65 6e 74 .0......0present
|
||||
| 4000: 01 02 05 05 1b 84 80 80 80 80 02 03 00 3c 00 00 .............<..
|
||||
| 4016: 00 16 04 30 66 74 73 01 06 01 01 04 01 02 69 6e ...0fts.......in
|
||||
| 4032: 01 06 01 01 04 0a 1a 84 80 80 80 80 01 03 00 3a ...............:
|
||||
| 4048: 00 00 00 15 05 30 65 61 63 68 01 02 03 01 13 66 .....0each.....f
|
||||
| 4064: 6f 72 01 02 02 04 09 06 01 03 00 12 03 0b 0f 00 or..............
|
||||
| 4080: 00 08 8c 80 80 80 80 11 03 00 16 00 00 00 05 04 ................
|
||||
| page 3 offset 8192
|
||||
| 0: 0a 00 00 00 32 0e 4f 00 0f fa 0f f1 0f e9 0f e1 ....2.O.........
|
||||
| 16: 0f d8 0f d1 0f c9 0f c1 0f b9 0f b1 0f a9 0f a0 ................
|
||||
| 32: 0f 98 0f 90 0f 87 0f 80 0f 78 0f 71 0f 68 0f 5f .........x.q.h._
|
||||
| 48: 0f 56 0f 4d 0f 41 0f 38 0f 2f 0f 26 0f 1d 0f 13 .V.M.A.8./.&....
|
||||
| 64: 0f 0a 0f 01 0e f7 0e ee 0e e6 0e dd 0e d6 0e cd ................
|
||||
| 80: 0e c3 0e ba 0e 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 3648: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 ................
|
||||
| 3664: 04 01 10 01 03 34 74 20 07 04 01 0e 01 03 34 1e .....4t ......4.
|
||||
| 3680: 09 04 01 12 01 03 33 74 68 1c 08 04 01 10 01 03 ......3th.......
|
||||
| 3696: 33 6e 1a 08 04 01 10 01 03 32 77 18 08 04 01 10 3n.......2w.....
|
||||
| 3712: 01 03 32 74 16 08 04 01 10 01 03 32 6e 14 07 04 ..2t.......2n...
|
||||
| 3728: 01 0e 01 03 32 12 08 04 01 10 01 03 31 74 10 08 ....2.......1t..
|
||||
| 3744: 04 01 10 01 03 31 6e 0e 07 04 01 0e 01 03 31 0c .....1n.......1.
|
||||
| 3760: 09 04 01 12 01 03 30 74 68 0a 08 04 01 10 01 03 ......0th.......
|
||||
| 3776: 30 74 08 09 04 01 12 01 03 30 6e 75 06 08 04 01 0t.......0nu....
|
||||
| 3792: 10 01 03 30 6e 04 06 04 01 0c 01 03 02 08 04 01 ...0n...........
|
||||
| 3808: 10 01 02 34 72 22 07 04 01 0e 01 02 34 20 08 04 ...4r.......4 ..
|
||||
| 3824: 01 10 01 02 33 72 1e 09 04 01 12 01 02 33 61 72 ....3r.......3ar
|
||||
| 3840: 1c 08 04 01 10 01 02 32 74 1a 08 04 01 10 01 02 .......2t.......
|
||||
| 3856: 32 69 18 09 04 01 12 01 02 32 61 72 16 08 04 01 2i.......2ar....
|
||||
| 3872: 10 01 02 31 74 14 08 04 01 10 01 02 31 6e 12 08 ...1t.......1n..
|
||||
| 3888: 04 01 10 01 02 31 62 10 08 04 01 10 01 02 31 32 .....1b.......12
|
||||
| 3904: 0e 0b 04 01 16 01 02 30 74 68 65 72 0c 08 04 01 .......0ther....
|
||||
| 3920: 10 01 02 30 74 0a 08 04 01 10 01 02 30 6e 08 08 ...0t.......0n..
|
||||
| 3936: 14 01 10 01 02 30 62 06 08 04 01 10 01 02 30 61 .....0b.......0a
|
||||
| 3952: 04 06 04 01 0c 01 02 02 07 04 09 10 01 34 74 22 .............4t.
|
||||
| 3968: 06 04 09 0e 01 34 20 08 04 09 12 01 33 74 65 1e .....4 .....3te.
|
||||
| 3984: 07 04 09 10 01 33 70 1c 07 04 09 10 01 33 66 1a .....3p......3f.
|
||||
| 4000: 08 04 09 12 01 32 74 68 18 07 04 09 10 01 32 74 .....2th......2t
|
||||
| 4016: 16 01 64 09 10 01 32 69 14 07 04 09 10 01 32 66 ..d...2i......2f
|
||||
| 4032: 12 07 04 09 10 01 31 74 10 07 04 09 10 01 31 69 ......1t......1i
|
||||
| 4048: 0e 06 04 09 0e 01 31 0c 08 04 09 12 01 30 74 65 ......1......0te
|
||||
| 4064: 0a 06 04 09 10 01 30 74 08 07 04 09 10 01 30 70 ......0t......0p
|
||||
| 4080: 06 08 04 09 12 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| page 4 offset 12288
|
||||
| 4064: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10 ................
|
||||
| 4080: 03 05 05 02 03 00 10 04 06 05 01 03 00 10 04 04 ................
|
||||
| page 5 offset 16384
|
||||
| 0: 0a 00 00 00 02 0f eb 00 0f eb 0f f4 00 00 00 00 ................
|
||||
| 4064: 00 00 00 00 00 00 00 00 00 00 00 08 03 15 01 70 ...............p
|
||||
| 4080: 67 73 7a 18 0b 03 1b 01 76 65 72 73 69 6f 6e 04 gsz.....version.
|
||||
| page 6 offset 20480
|
||||
| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 4080: 00 00 03 03 02 01 03 03 02 02 01 00 00 00 00 00 ................
|
||||
| end crash-0f47112aa7520c.db
|
||||
}]
|
||||
} {}
|
||||
|
||||
do_catchsql_test 1.1 {
|
||||
SELECT * FROM t1('R*') WHERE (a,b)<=(current_date,0) ORDER BY rowid DESC;
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
do_test 2.0 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
|
||||
.open --hexdb
|
||||
| size 24576 pagesize 4096 filename sql047467.txt.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........
|
||||
| 96: 00 00 00 00 0d 00 00 00 06 0e 0f 00 0f aa 0f 53 ...............S
|
||||
| 112: 0e e8 0e 8b 0e 33 0e 0f 01 00 00 00 00 00 00 00 .....3..........
|
||||
| 3584: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 ................
|
||||
| 3600: 06 06 17 11 11 01 31 74 61 62 6c 65 62 62 62 62 ......1tablebbbb
|
||||
| 3616: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 62 62 .CREATE TABLE bb
|
||||
| 3632: 28 61 29 56 05 06 17 1f 1f 01 7d 74 61 62 6c 65 (a)V.......table
|
||||
| 3648: 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 6f 6e 66 t1_configt1_conf
|
||||
| 3664: 69 67 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 ig.CREATE TABLE
|
||||
| 3680: 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b 20 50 52 't1_config'(k PR
|
||||
| 3696: 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 20 57 49 IMARY KEY, v) WI
|
||||
| 3712: 54 48 4f 55 54 20 52 4f 57 49 44 5b 04 07 17 21 THOUT ROWID[...!
|
||||
| 3728: 21 01 81 01 74 61 62 6c 65 74 31 5f 64 6f 63 73 !...tablet1_docs
|
||||
| 3744: 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 04 43 52 izet1_docsize.CR
|
||||
| 3760: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64 EATE TABLE 't1_d
|
||||
| 3776: 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47 ocsize'(id INTEG
|
||||
| 3792: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
|
||||
| 3808: 73 7a 20 42 4c 4f 42 29 69 03 07 17 19 19 01 81 sz BLOB)i.......
|
||||
| 3824: 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 5f 69 -tablet1_idxt1_i
|
||||
| 3840: 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 dx.CREATE TABLE
|
||||
| 3856: 27 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20 't1_idx'(segid,
|
||||
| 3872: 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 4d term, pgno, PRIM
|
||||
| 3888: 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74 ARY KEY(segid, t
|
||||
| 3904: 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f erm)) WITHOUT RO
|
||||
| 3920: 57 49 44 55 02 07 17 1b 1b 01 81 01 74 61 62 6c WIDU........tabl
|
||||
| 3936: 65 74 31 5f 64 61 74 61 74 31 5f 64 61 74 61 02 et1_datat1_data.
|
||||
| 3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 CREATE TABLE 't1
|
||||
| 3968: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45 _data'(id INTEGE
|
||||
| 3984: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 R PRIMARY KEY, b
|
||||
| 4000: 6c 6f 63 6b 20 42 4c 4f 42 29 54 01 07 17 11 11 lock BLOB)T.....
|
||||
| 4016: 08 81 15 74 61 62 6c 65 74 31 74 31 43 52 45 41 ...tablet1t1CREA
|
||||
| 4032: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 TE VIRTUAL TABLE
|
||||
| 4048: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 61 t1 USING fts5(a
|
||||
| 4064: 2c 62 2c 70 72 65 66 69 78 3d 22 31 2c 32 2c 33 ,b,prefix=.1,2,3
|
||||
| 4080: 2c 34 22 2c 20 63 6f 6e 74 65 6e 74 3d 22 22 29 ,4., content=..)
|
||||
| page 2 offset 4096
|
||||
| 0: 0d 0b 6a 00 37 09 4c 02 0f e7 09 4c 0f c6 0f a4 ..j.7.L....L....
|
||||
| 16: 0f 88 0f 6d 0f 4b 0f 2c 0f 0e 0e ec 0e cd 0e ad ...m.K.,........
|
||||
| 32: 0e 8e 0e 6c 0e 4b 0e 29 0e 08 0d e6 0d c4 0d b5 ...l.K.)........
|
||||
| 48: 0d 97 0d 76 0d 54 0d 31 0d 15 0c f3 0c d3 0c b5 ...v.T.1........
|
||||
| 64: 0c 95 0c 73 0c 54 0c 32 0c 10 0b ee 0b cc 0b b0 ...s.T.2........
|
||||
| 80: 0b 8d 0b 7e 0b 48 0b 2e 0b 0b 0a ef 00 00 00 00 ...~.H..........
|
||||
| 2368: 00 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00 ................
|
||||
| 2384: 30 00 00 00 01 01 03 35 00 03 01 11 12 02 01 12 0......5........
|
||||
| 2400: 03 01 11 1c 8c 80 80 80 80 10 03 00 3e 00 00 00 ............>...
|
||||
| 2416: 17 01 05 05 34 74 61 62 6c 03 02 03 01 04 77 68 ....4tabl.....wh
|
||||
| 2432: 65 72 03 02 06 09 1b 8c 80 80 80 80 0f 03 00 3c er.............<
|
||||
| 2448: 00 00 00 16 05 34 66 74 73 34 03 02 02 01 04 6e .....4fts4.....n
|
||||
| 2464: 75 6d 62 03 06 01 04 09 1b 8c 80 80 80 80 0e 03 umb.............
|
||||
| 2480: 00 3b ff f0 00 16 04 33 74 68 65 03 06 01 01 04 .;.....3the.....
|
||||
| 2496: 01 03 77 68 65 03 02 04 04 0a 1b 8c 80 80 80 80 ..whe...........
|
||||
| 2512: 0d 03 00 3c 00 00 00 16 04 33 6e 75 6d 03 06 01 ...<.....3num...
|
||||
| 2528: 01 05 01 03 74 61 62 03 02 03 04 0a 19 8c 80 80 ....tab.........
|
||||
| 2544: 80 80 0c 03 00 38 00 00 00 14 03 32 77 68 03 02 .....8.....2wh..
|
||||
| 2560: 04 00 04 33 66 74 73 03 02 02 04 07 18 8c 80 80 ...3fts.........
|
||||
| 2576: 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 03 02 .....6.....2ta..
|
||||
| 2592: 03 02 01 68 03 06 01 01 04 04 07 1b 8c 80 80 80 ...h............
|
||||
| 2608: 80 0a 03 00 3c 00 00 00 16 03 32 6e 75 03 06 01 ....<.....2nu...
|
||||
| 2624: 01 05 01 02 6f 66 03 06 01 01 06 04 09 19 8c 80 ....of..........
|
||||
| 2640: 80 80 80 09 03 00 38 00 00 00 14 03 32 66 74 03 ......8.....2ft.
|
||||
| 2656: 02 02 01 02 69 73 03 06 01 01 03 04 07 18 8c 80 ....is..........
|
||||
| 2672: 80 80 80 08 03 00 36 00 00 00 13 02 31 74 03 08 ......6.....1t..
|
||||
| 2688: 03 01 01 04 01 01 77 03 02 04 04 09 1a 8c 80 80 ......w.........
|
||||
| 2704: 80 80 07 03 00 3a 00 00 00 15 02 31 6e 03 08 01 .....:.....1n...
|
||||
| 2720: 01 02 05 01 00 6f 03 06 01 01 06 14 09 18 8c 80 .....o..........
|
||||
| 2736: 80 80 80 06 03 00 36 00 00 00 03 04 02 31 66 03 ......6......1f.
|
||||
| 2752: 02 02 01 01 69 03 06 01 01 03 04 f6 1c 8c 80 80 ....i...........
|
||||
| 2768: 80 80 05 03 00 3e 00 00 00 17 04 30 74 68 65 03 .....>.....0the.
|
||||
| 2784: f6 01 01 04 01 05 77 68 65 72 65 03 02 04 0a 15 ......where.....
|
||||
| 2800: 8c 80 80 80 80 04 03 00 30 00 00 00 11 01 01 06 ........0.......
|
||||
| 2816: 06 30 74 61 62 6c 65 0f 42 03 07 1c 8c 81 80 80 .0table.B.......
|
||||
| 2832: 80 03 03 00 3e 00 00 00 17 07 30 6e 75 6d 62 65 ....>.....0numbe
|
||||
| 2848: 72 03 06 01 01 05 01 02 6f 66 03 06 04 0d 13 8c r.......of......
|
||||
| 2864: 80 80 80 80 02 03 00 2c 00 00 00 0f 01 01 03 02 .......,........
|
||||
| 2880: 30 6e 03 06 01 01 02 07 1b 8c 80 80 80 80 01 03 0n..............
|
||||
| 2896: 00 3c 00 00 00 16 08 30 66 74 73 34 61 75 78 03 .<.....0fts4aux.
|
||||
| 2912: 02 02 01 02 69 73 03 06 04 0c 00 00 00 14 2a 00 ....is........*.
|
||||
| 2928: 00 00 01 01 02 24 00 02 01 01 12 02 01 12 08 88 .....$..........
|
||||
| 2944: 80 80 80 80 12 03 00 16 00 00 00 05 02 1c 88 80 ................
|
||||
| 2960: 80 80 80 11 03 00 3e 00 00 00 17 05 34 72 6f 77 ......>.....4row
|
||||
| 2976: 73 02 06 01 01 05 01 04 74 68 65 72 02 02 04 0b s.......ther....
|
||||
| 2992: 15 88 80 80 80 80 10 03 00 30 00 00 00 11 02 01 .........0......
|
||||
| 3008: 01 07 05 34 62 65 74 77 02 02 04 08 1b 88 80 80 ...4betw........
|
||||
| 3024: 80 80 0f 03 00 3c 00 00 00 16 04 04 33 72 6f 77 .....<......3row
|
||||
| 3040: 02 06 01 01 05 01 03 74 68 65 02 08 05 0a 1b 88 .......the......
|
||||
| 3056: 80 80 80 80 0e 03 00 3c 00 00 00 16 01 01 02 04 .......<........
|
||||
| 3072: 33 61 72 65 02 02 03 01 03 62 65 74 02 02 07 08 3are.....bet....
|
||||
| 3088: 1b 88 80 80 80 80 0d 03 00 3c 00 00 00 16 13 32 .........<.....2
|
||||
| 3104: 74 68 02 08 02 01 01 07 00 04 33 61 6e 64 02 06 th........3and..
|
||||
| 3120: 04 0a 1b 88 80 80 80 80 0c 03 00 3c 00 00 00 16 ...........<....
|
||||
| 3136: 03 32 69 6e 02 06 01 01 06 01 02 72 6f 02 06 01 .2in.......ro...
|
||||
| 3152: 01 05 04 09 18 88 80 80 80 80 0b 03 00 36 00 00 .............6..
|
||||
| 3168: 00 13 02 03 32 61 72 02 02 03 01 02 62 65 02 02 ....2ar.....be..
|
||||
| 3184: 04 05 07 1b 88 80 80 80 80 0a 03 00 3c 00 94 50 ............<..P
|
||||
| 3200: 16 02 31 74 02 08 02 01 01 07 00 03 32 61 6e 02 ..1t........2an.
|
||||
| 3216: 06 01 01 04 09 19 88 80 80 80 80 09 03 00 38 00 ..............8.
|
||||
| 3232: 00 00 14 02 31 6e 02 06 01 01 03 01 01 72 02 06 ....1n.......r..
|
||||
| 3248: 01 01 05 04 08 17 88 80 80 80 80 08 03 00 34 00 ..............4.
|
||||
| 3264: 00 00 12 02 31 62 02 02 04 01 01 69 02 06 01 01 ....1b.....i....
|
||||
| 3280: 06 04 06 19 88 80 80 80 80 07 03 00 38 00 00 00 ............8...
|
||||
| 3296: 14 04 02 31 32 02 02 05 01 01 61 02 08 03 01 01 ...12.....a.....
|
||||
| 3312: 02 05 06 1b 88 80 80 80 80 06 03 00 3c 00 00 00 ............<...
|
||||
| 3328: 16 06 30 74 68 65 72 65 02 02 02 00 02 31 31 02 ..0there.....11.
|
||||
| 3344: 06 01 01 04 0a 15 88 80 80 80 80 05 03 00 30 00 ..............0.
|
||||
| 3360: 00 00 11 01 01 05 04 30 74 68 65 02 06 01 01 07 .......0the.....
|
||||
| 3376: 07 1c 88 80 80 80 80 04 03 00 3e 00 00 00 17 01 ..........>.....
|
||||
| 3392: 01 06 02 30 6e 02 06 01 01 03 01 04 72 6f 77 73 ...0n.......rows
|
||||
| 3408: 02 06 07 08 1b 88 80 80 80 80 03 03 00 3c 00 00 .............<..
|
||||
| 3424: 00 16 08 30 62 65 74 77 65 65 6e 02 02 04 01 02 ...0between.....
|
||||
| 3440: 69 6e 02 06 04 0c 1a 88 80 80 80 80 02 03 00 3a in.............:
|
||||
| 3456: 00 00 00 15 04 30 61 6e 64 02 06 01 01 02 02 02 .....0and.......
|
||||
| 3472: 72 65 02 02 03 04 0a 17 88 80 80 80 80 01 03 00 re..............
|
||||
| 3488: 34 00 00 00 12 02 30 31 02 06 01 01 04 01 01 32 4.....01.......2
|
||||
| 3504: 02 02 05 04 08 08 84 80 80 80 80 12 03 00 16 00 ................
|
||||
| 3520: 00 00 05 04 1b 84 80 80 80 80 11 03 00 3c 00 00 .............<..
|
||||
| 3536: 00 16 05 34 74 61 62 6c 01 06 01 01 05 02 03 65 ...4tabl.......e
|
||||
| 3552: 72 6d 01 02 04 0b 1b 84 80 80 80 80 10 03 00 3c rm.............<
|
||||
| 3568: 00 00 00 16 05 34 65 61 63 68 01 02 03 01 04 70 .....4each.....p
|
||||
| 3584: 72 65 73 01 02 05 04 08 1a 84 80 80 80 80 0f 03 res.............
|
||||
| 3600: 00 3a 00 00 00 15 04 33 74 65 72 01 02 04 02 02 .:.....3ter.....
|
||||
| 3616: 68 65 01 06 01 01 03 04 08 1b 84 80 80 80 80 0e he..............
|
||||
| 3632: 03 00 3c 00 00 00 16 04 33 80 72 65 01 02 05 01 ..<.....3.re....
|
||||
| 3648: 03 74 61 62 01 06 01 01 05 04 08 1a 84 80 80 80 .tab............
|
||||
| 3664: 80 0d 03 00 3a 00 00 00 15 04 33 66 6f 72 01 02 ....:.....3for..
|
||||
| 3680: 02 02 02 74 73 01 06 01 01 04 04 08 1b 84 80 80 ...ts...........
|
||||
| 3696: 80 80 0c 03 00 3c 00 00 00 17 03 32 74 68 01 06 .....<.....2th..
|
||||
| 3712: 01 01 03 00 04 33 65 61 63 01 02 03 04 09 18 84 .....3eac.......
|
||||
| 3728: 80 80 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 .......6.....2ta
|
||||
| 3744: 01 06 01 01 05 02 01 65 01 02 04 04 09 19 84 80 .......e........
|
||||
| 3760: 80 80 80 0a 03 00 38 00 00 00 14 03 32 69 6e 01 ......8.....2in.
|
||||
| 3776: 06 01 01 02 01 02 70 72 01 02 05 04 09 18 84 80 ......pr........
|
||||
| 3792: 80 80 80 09 03 00 36 00 00 00 13 03 32 66 6f 01 ......6.....2fo.
|
||||
| 3808: 02 02 02 01 74 01 06 01 01 04 04 07 1b 84 80 80 ....t...........
|
||||
| 3824: 80 80 08 03 00 3c 00 00 00 16 02 31 74 01 0a 04 .....<.....1t...
|
||||
| 3840: 01 01 03 04 00 03 32 65 61 01 02 03 04 0a 17 84 ......2ea.......
|
||||
| 3856: 80 80 80 80 07 03 00 34 00 00 00 12 02 31 69 01 .......4.....1i.
|
||||
| 3872: 06 01 01 02 01 01 70 01 02 05 04 08 18 84 80 80 ......p.........
|
||||
| 3888: 80 80 06 03 00 36 00 00 00 13 02 31 65 01 02 03 .....6.....1e...
|
||||
| 3904: 01 01 66 01 08 02 01 01 04 04 06 1b 84 80 80 80 ..f.............
|
||||
| 3920: 80 05 03 00 3c 00 00 00 16 05 30 74 65 72 6d 01 ....<.....0term.
|
||||
| 3936: 02 04 02 02 68 65 01 06 01 01 03 04 09 14 84 80 ....he..........
|
||||
| 3952: 80 80 80 04 03 00 2e 00 00 00 10 06 30 64 61 62 ............0dab
|
||||
| 3968: 6c 65 01 06 01 01 05 04 15 84 80 80 80 80 03 03 le..............
|
||||
| 3984: 00 30 00 00 00 11 02 08 30 70 72 65 73 65 6e 74 .0......0present
|
||||
| 4000: 01 02 05 05 1b 84 80 80 80 80 02 03 00 3c 00 00 .............<..
|
||||
| 4016: 00 16 04 30 66 74 73 01 06 01 01 04 01 02 69 6e ...0fts.......in
|
||||
| 4032: 01 06 01 01 04 0a 1a 84 80 80 80 80 01 03 00 3a ...............:
|
||||
| 4048: 00 00 00 15 05 30 65 61 63 68 01 02 03 01 13 66 .....0each.....f
|
||||
| 4064: 6f 72 01 02 02 04 09 06 01 03 00 12 03 0b 0f 00 or..............
|
||||
| 4080: 00 08 8c 80 80 80 80 11 03 00 16 00 00 00 05 04 ................
|
||||
| page 3 offset 8192
|
||||
| 0: 0a 00 00 00 32 0e 4f 00 0f fa 0f f1 0f e9 0f e1 ....2.O.........
|
||||
| 16: 0f d8 0f d1 0f c9 0f c1 0f b9 0f b1 0f a9 0f a0 ................
|
||||
| 32: 0f 98 0f 90 0f 87 0f 80 0f 78 0f 71 0f 68 0f 5f .........x.q.h._
|
||||
| 48: 0f 56 0f 4d 0f 41 0f 38 0f 2f 0f 26 0f 1d 0f 13 .V.M.A.8./.&....
|
||||
| 64: 0f 0a 0f 01 0e f7 0e ee 0e e6 0e dd 0e d6 0e cd ................
|
||||
| 80: 0e c3 0e ba 0e 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 3648: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 ................
|
||||
| 3664: 04 01 10 01 03 34 74 20 07 04 01 0e 01 03 34 1e .....4t ......4.
|
||||
| 3680: 09 04 01 12 01 03 33 74 68 1c 08 04 01 10 01 03 ......3th.......
|
||||
| 3696: 33 6e 1a 08 04 01 10 01 03 32 77 18 08 04 01 10 3n.......2w.....
|
||||
| 3712: 01 03 32 74 16 08 04 01 10 01 03 32 6e 14 07 04 ..2t.......2n...
|
||||
| 3728: 01 0e 01 03 32 12 08 04 01 10 01 03 31 74 10 08 ....2.......1t..
|
||||
| 3744: 04 01 10 01 03 31 6e 0e 07 04 01 0e 01 03 31 0c .....1n.......1.
|
||||
| 3760: 09 04 01 12 01 03 30 74 68 0a 08 04 01 10 01 03 ......0th.......
|
||||
| 3776: 30 74 08 09 04 01 12 01 03 30 6e 75 06 08 04 01 0t.......0nu....
|
||||
| 3792: 10 01 03 30 6e 04 06 04 01 0c 01 03 02 08 04 01 ...0n...........
|
||||
| 3808: 10 01 02 34 72 22 07 04 01 0e 01 02 34 20 08 04 ...4r.......4 ..
|
||||
| 3824: 01 10 01 02 33 72 1e 09 04 01 12 01 02 33 61 72 ....3r.......3ar
|
||||
| 3840: 1c 08 04 01 10 01 02 32 74 1a 08 04 01 10 01 02 .......2t.......
|
||||
| 3856: 32 69 18 09 04 01 12 01 02 32 61 72 16 08 04 01 2i.......2ar....
|
||||
| 3872: 10 01 02 31 74 14 08 04 01 10 01 02 31 6e 12 08 ...1t.......1n..
|
||||
| 3888: 04 01 10 01 02 31 62 10 08 04 01 10 01 02 31 32 .....1b.......12
|
||||
| 3904: 0e 0b 04 01 16 01 02 30 74 68 65 72 0c 08 04 01 .......0ther....
|
||||
| 3920: 10 01 02 30 74 0a 08 04 01 10 01 02 30 6e 08 08 ...0t.......0n..
|
||||
| 3936: 14 01 10 01 02 30 62 06 08 04 01 10 01 02 30 61 .....0b.......0a
|
||||
| 3952: 04 06 04 01 0c 01 02 02 07 04 09 10 01 34 74 22 .............4t.
|
||||
| 3968: 06 04 09 0e 01 34 20 08 04 09 12 01 33 74 65 1e .....4 .....3te.
|
||||
| 3984: 07 04 09 10 01 33 70 1c 07 04 09 10 01 33 66 1a .....3p......3f.
|
||||
| 4000: 08 04 09 12 01 32 74 68 18 07 04 09 10 01 32 74 .....2th......2t
|
||||
| 4016: 16 01 64 09 10 01 32 69 14 07 04 09 10 01 32 66 ..d...2i......2f
|
||||
| 4032: 12 07 04 09 10 01 31 74 10 07 04 09 10 01 31 69 ......1t......1i
|
||||
| 4048: 0e 06 04 09 0e 01 31 0c 08 04 09 12 01 30 74 65 ......1......0te
|
||||
| 4064: 0a 06 04 09 10 01 30 74 08 07 04 09 10 01 30 70 ......0t......0p
|
||||
| 4080: 06 08 04 09 12 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| page 4 offset 12288
|
||||
| 4064: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10 ................
|
||||
| 4080: 03 05 05 02 03 00 10 04 06 05 01 03 00 10 04 04 ................
|
||||
| page 5 offset 16384
|
||||
| 0: 0a 00 00 00 02 0f eb 00 0f eb 0f f4 00 00 00 00 ................
|
||||
| 4064: 00 00 00 00 00 00 00 00 00 00 00 08 03 15 01 70 ...............p
|
||||
| 4080: 67 73 7a 18 0b 03 1b 01 76 65 72 73 69 6f 6e 04 gsz.....version.
|
||||
| page 6 offset 20480
|
||||
| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 4080: 00 00 03 03 02 01 03 03 02 02 01 00 00 00 00 00 ................
|
||||
| end sql047467.txt.db
|
||||
}]} {}
|
||||
|
||||
do_catchsql_test 2.1 {
|
||||
SELECT * FROM t1('R*R*R*R*') WHERE (a,b)<=(current_date,0) ORDER BY rowid DESC;
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_test 3.0 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
.open --hexdb
|
||||
| size 32768 pagesize 4096 filename crash-c69fcaceff1e50.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 08 .....@ ........
|
||||
| 32: 00 00 00 02 00 00 00 01 00 00 00 09 00 00 00 04 ................
|
||||
| 96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36 ...............6
|
||||
| 112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 0d 92 00 00 00 00 ...k............
|
||||
| 3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74 .........1tablet
|
||||
| 3488: 32 74 32 08 43 52 45 41 54 45 20 54 41 42 4c 45 2t2.CREATE TABLE
|
||||
| 3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61 t2(x)V.......ta
|
||||
| 3520: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 blet1_configt1_c
|
||||
| 3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42 onfig.CREATE TAB
|
||||
| 3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b LE 't1_config'(k
|
||||
| 3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 PRIMARY KEY, v)
|
||||
| 3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06 WITHOUT ROWID[.
|
||||
| 3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64 ..!!...tablet1_d
|
||||
| 3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 ocsizet1_docsize
|
||||
| 3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 .CREATE TABLE 't
|
||||
| 3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 1_docsize'(id IN
|
||||
| 3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 TEGER PRIMARY KE
|
||||
| 3680: 59 2c 20 73 7a 20 42 4c 4f 42 29 5e 05 07 17 21 Y, sz BLOB)^...!
|
||||
| 3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74 !...tablet1_cont
|
||||
| 3712: 65 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 05 43 52 entt1_content.CR
|
||||
| 3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 EATE TABLE 't1_c
|
||||
| 3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 ontent'(id INTEG
|
||||
| 3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
|
||||
| 3776: 63 30 2c 20 63 31 2c 20 63 32 29 69 04 07 17 19 c0, c1, c2)i....
|
||||
| 3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 ...-tablet1_idxt
|
||||
| 3808: 31 5f 69 64 78 04 43 52 45 41 54 45 20 54 41 42 1_idx.CREATE TAB
|
||||
| 3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69 LE 't1_idx'(segi
|
||||
| 3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 d, term, pgno, P
|
||||
| 3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64 RIMARY KEY(segid
|
||||
| 3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54 , term)) WITHOUT
|
||||
| 3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74 ROWIDU........t
|
||||
| 3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 64 61 ablet1_datat1_da
|
||||
| 3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 ta.CREATE TABLE
|
||||
| 3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54 't1_data'(id INT
|
||||
| 3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
|
||||
| 3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06 , block BLOB)8..
|
||||
| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR
|
||||
| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB
|
||||
| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 LE t1 USING fts5
|
||||
| 4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00 (a,b,c).........
|
||||
| page 3 offset 8192
|
||||
| 0: 0d 00 00 00 03 0c 94 00 0f e6 0f ef 0c 94 00 00 ................
|
||||
| 3216: 00 00 00 00 86 4a 84 80 80 80 80 01 04 00 8d 18 .....J..........
|
||||
| 3232: 00 00 01 bb 02 30 30 01 02 06 01 02 06 01 02 06 .....00.........
|
||||
| 3248: 1f 02 03 01 02 03 01 02 03 01 08 32 30 31 36 30 ...........20160
|
||||
| 3264: 36 30 39 01 02 07 01 02 07 01 02 07 01 01 34 01 609...........4.
|
||||
| 3280: 02 05 01 02 05 01 02 05 01 01 35 01 02 04 01 02 ..........5.....
|
||||
| 3296: 04 01 02 04 02 07 30 30 30 30 30 30 30 1c 02 04 ......0000000...
|
||||
| 3312: 01 02 04 01 02 04 01 06 62 69 6e 61 72 79 03 06 ........binary..
|
||||
| 3328: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 3344: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 3360: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 3376: 03 06 01 02 02 03 06 01 02 02 01 08 63 6f 6d 70 ............comp
|
||||
| 3392: 69 6c 65 72 01 02 02 01 02 02 01 02 02 01 06 64 iler...........d
|
||||
| 3408: 62 73 74 61 74 07 02 03 01 02 03 01 02 03 02 04 bstat...........
|
||||
| 3424: 65 62 75 67 04 02 02 01 02 02 01 02 02 01 06 65 ebug...........e
|
||||
| 3440: 6b b1 62 6c 65 07 02 02 01 02 02 01 02 02 01 02 k.ble...........
|
||||
| 3456: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
|
||||
| 3472: 01 02 02 01 02 02 05 02 02 01 02 02 01 02 02 01 ................
|
||||
| 3488: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
|
||||
| 3504: 02 01 02 02 02 08 78 74 65 6e 73 69 6f 6e 1f 02 ......xtension..
|
||||
| 3520: 04 01 02 04 01 02 04 01 04 66 74 73 34 1a 02 03 .........fts4...
|
||||
| 3536: 01 02 03 01 02 03 04 01 35 0d 02 03 01 02 03 01 ........5.......
|
||||
| 3552: 02 03 01 03 67 63 63 01 02 03 01 02 03 01 02 03 ....gcc.........
|
||||
| 3568: 02 06 65 6f 70 6f 6c 79 10 02 03 01 02 03 01 02 ..eopoly........
|
||||
| 3584: 03 01 05 6a 73 6f 6e 31 13 02 03 01 02 03 01 02 ...json1........
|
||||
| 3600: 03 01 04 6c 6f 61 64 1f 02 03 01 02 03 01 02 03 ...load.........
|
||||
| 3616: 01 03 6d 61 78 1c 02 02 01 02 02 01 02 02 02 05 ..max...........
|
||||
| 3632: 65 6d 6f 72 79 1c 02 03 01 02 03 01 02 03 04 04 emory...........
|
||||
| 3648: 73 79 73 35 16 02 03 01 02 03 01 02 03 01 06 6e sys5...........n
|
||||
| 3664: 6f 63 61 73 65 02 06 01 02 02 03 06 01 02 02 03 ocase...........
|
||||
| 3680: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 3696: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 3712: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 3728: 02 01 04 6f 6d 69 74 1f 02 02 01 02 02 01 02 01 ...omit.........
|
||||
| 3744: ff ff ff ff ff ff ff ff ff ff ff ff ff ff f1 02 ................
|
||||
| 3760: 58 81 96 4d 01 06 01 02 02 03 06 01 02 02 03 06 X..M............
|
||||
| 3776: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 3792: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 3808: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 3824: 01 0a 74 68 72 65 61 64 73 61 66 65 22 02 02 01 ..threadsafe....
|
||||
| 3840: 02 02 01 02 02 01 04 76 74 61 62 07 02 04 01 02 .......vtab.....
|
||||
| 3856: 04 01 02 04 01 01 78 01 06 01 01 02 01 06 01 01 ......x.........
|
||||
| 3872: 02 01 06 01 c6 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3888: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3904: 06 01 01 02 00 f6 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3920: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3936: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 3952: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3968: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3984: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 4000: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 4016: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 4032: 02 01 06 01 01 02 01 06 01 01 02 04 15 13 0c 0c ................
|
||||
| 4048: 12 44 13 11 0f 47 13 0f 0c 0e 11 10 0f 0e 10 0f .D...G..........
|
||||
| 4064: 44 0f 10 40 15 0f 07 01 03 00 14 24 5a 24 24 0f D..@.......$Z$$.
|
||||
| 4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01 ...$............
|
||||
| page 4 offset 12288
|
||||
| 0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00 ................
|
||||
| 4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02 ................
|
||||
| page 7 offset 24576
|
||||
| 0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00 ................
|
||||
| 4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04 ........version.
|
||||
| end crash-c69fcaceff1e50.db
|
||||
}]} {}
|
||||
|
||||
do_catchsql_test 3.1 {
|
||||
UPDATE t1 SET b=quote(zeroblob(200)) WHERE a MATCH 'thra*T';
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_test 4.0 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
.open --hexdb
|
||||
| size 24576 pagesize 4096 filename crash-ef6738247b1344.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 10 00 06 40 00 00 06 .....@ ....@...
|
||||
| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00 ................
|
||||
| 96: 00 00 00 00 0d 00 00 00 06 0e 0f 00 0f aa 0f 53 ...............S
|
||||
| 112: 0e e8 0e 8b 0e 33 0e 0f 00 00 00 00 00 00 00 00 .....3..........
|
||||
| 3584: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 ................
|
||||
| 3600: 06 06 17 11 11 01 31 74 61 62 6c 65 62 62 62 62 ......1tablebbbb
|
||||
| 3616: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 62 62 .CREATE TABLE bb
|
||||
| 3632: 28 61 29 56 05 06 17 1f 1f 01 7d 74 61 62 6c 65 (a)V.......table
|
||||
| 3648: 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 6f 6e 66 t1_configt1_conf
|
||||
| 3664: 69 67 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 ig.CREATE TABLE
|
||||
| 3680: 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b 20 50 52 't1_config'(k PR
|
||||
| 3696: 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 20 57 49 IMARY KEY, v) WI
|
||||
| 3712: 54 48 4f 55 54 20 52 4f 57 49 44 5b 04 07 17 21 THOUT ROWID[...!
|
||||
| 3728: 21 01 81 01 74 61 62 6c 65 74 31 5f 64 6f 63 73 !...tablet1_docs
|
||||
| 3744: 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 04 43 52 izet1_docsize.CR
|
||||
| 3760: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64 EATE TABLE 't1_d
|
||||
| 3776: 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47 ocsize'(id INTEG
|
||||
| 3792: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
|
||||
| 3808: 73 7a 20 42 4c 4f 42 29 69 03 07 17 19 19 01 81 sz BLOB)i.......
|
||||
| 3824: 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 5f 69 -tablet1_idxt1_i
|
||||
| 3840: 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 dx.CREATE TABLE
|
||||
| 3856: 27 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20 't1_idx'(segid,
|
||||
| 3872: 74 65 72 6d 2c 20 6f 67 6e 6f 2c 20 50 52 49 4d term, ogno, PRIM
|
||||
| 3888: 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74 ARY KEY(segid, t
|
||||
| 3904: 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f erm)) WITHOUT RO
|
||||
| 3920: 57 49 44 55 35 07 17 1b 1b 01 81 01 74 61 62 6c WIDU5.......tabl
|
||||
| 3936: 65 74 31 5f 64 61 74 61 74 31 5f 64 61 74 61 02 et1_datat1_data.
|
||||
| 3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 CREATE TABLE 't1
|
||||
| 3968: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45 _data'(id INTEGE
|
||||
| 3984: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 R PRIMARY KEY, b
|
||||
| 4000: 6c 6f 63 6b 20 42 4c 4f 42 29 54 01 07 17 11 11 lock BLOB)T.....
|
||||
| 4016: 08 81 15 74 61 62 6c 65 74 31 74 31 43 52 45 41 ...tablet1t1CREA
|
||||
| 4032: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 TE VIRTUAL TABLE
|
||||
| 4048: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 61 t1 USING fts5(a
|
||||
| 4064: 2c 62 2c 70 72 65 66 69 78 3d 22 31 2c 32 2c 33 ,b,prefix=.1,2,3
|
||||
| 4080: 2c 34 22 2c 20 63 6f 6e 74 65 6e 74 3d 22 22 29 ,4., content=..)
|
||||
| page 2 offset 4096
|
||||
| 0: 0d 0b 6a 00 37 09 4c 02 0f e7 09 4c 0f c6 0f a4 ..j.7.L....L....
|
||||
| 16: 0f 88 0f 6d 0f 4b 0f 2c 0f 0e 0e ec 0e cd 0e ad ...m.K.,........
|
||||
| 32: 0e 8e 0e 6c 0e 4b 0e 29 0e 08 0d e6 0d c4 0d b5 ...l.K.)........
|
||||
| 48: 0d 97 0d 76 0d 54 0d 31 0d 15 0c f3 0c d3 0c b5 ...v.T.1........
|
||||
| 64: 0c 95 0c 73 0c 54 0c 32 0c 10 0b ee 0b cc 0b b0 ...s.T.2........
|
||||
| 80: 0b 8d 0b 7e 0b 48 0b 2e 0b 0b 0a ef 0a cc 0a 00 ...~.H..........
|
||||
| 2368: 00 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00 ................
|
||||
| 2384: 30 00 00 00 01 01 03 35 00 03 01 01 12 02 01 12 0......5........
|
||||
| 2400: 03 01 11 1c 8c 80 80 80 80 10 02 9c 3e 00 00 00 ............>...
|
||||
| 2416: 17 01 05 05 34 74 61 62 6c 03 02 03 01 04 77 68 ....4tabl.....wh
|
||||
| 2432: 65 72 03 02 06 09 1b 8c 80 80 80 80 0f 03 00 3c er.............<
|
||||
| 2448: 00 00 00 16 05 34 66 74 73 34 03 02 02 01 04 6e .....4fts4.....n
|
||||
| 2464: 75 6d 62 03 06 01 04 09 1b 8c 80 80 80 80 0e 03 umb.............
|
||||
| 2480: 00 3c 00 00 00 16 04 33 74 68 65 03 06 01 01 04 .<.....3the.....
|
||||
| 2496: 01 03 77 68 65 03 02 04 04 0a 1b 8c 80 80 80 80 ..whe...........
|
||||
| 2512: 0d 03 00 3c 00 00 00 16 04 33 6e 75 6d 03 06 01 ...<.....3num...
|
||||
| 2528: 01 05 01 03 74 61 62 03 02 03 04 0a 19 8c 80 80 ....tab.........
|
||||
| 2544: 80 80 0c 03 00 38 00 00 00 14 03 32 77 68 03 02 .....8.....2wh..
|
||||
| 2560: 04 00 04 33 66 74 73 03 12 02 04 07 18 8c 80 80 ...3fts.........
|
||||
| 2576: 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 03 02 .....6.....2ta..
|
||||
| 2592: 03 02 01 68 03 06 01 01 04 04 07 1b 8c 80 80 80 ...h............
|
||||
| 2608: 80 0a 03 00 3c 00 00 00 16 03 32 6e 75 03 06 01 ....<.....2nu...
|
||||
| 2624: 01 05 01 02 6f 66 03 06 01 01 06 04 09 19 8c 80 ....of..........
|
||||
| 2640: 82 d0 80 09 03 00 38 00 00 00 14 03 32 66 74 03 ......8.....2ft.
|
||||
| 2656: 02 02 01 02 69 73 03 06 01 01 03 04 07 18 8c 80 ....is..........
|
||||
| 2672: 80 80 80 08 03 00 36 00 00 00 13 02 31 74 03 08 ......6.....1t..
|
||||
| 2688: 03 01 01 04 01 01 77 03 02 04 04 09 1a 8c 80 80 ......w.........
|
||||
| 2704: 80 80 07 03 00 3a 00 00 00 15 02 31 6e 03 08 01 .....:.....1n...
|
||||
| 2720: 01 02 05 01 01 6f 03 06 01 01 06 04 09 18 8c 80 .....o..........
|
||||
| 2736: 81 80 80 06 03 00 36 00 00 00 13 04 12 31 66 03 ......6......1f.
|
||||
| 2752: 02 02 01 01 69 03 06 01 01 03 05 06 1c 8c 80 80 ....i...........
|
||||
| 2768: 80 80 05 03 00 3e 00 00 00 17 04 30 74 68 65 03 .....>.....0the.
|
||||
| 2784: 06 01 01 04 01 05 77 68 65 72 65 03 02 04 0a 15 ......where.....
|
||||
| 2800: 8c 80 65 80 80 04 03 00 30 00 00 00 11 01 01 06 ..e.....0.......
|
||||
| 2816: 06 30 74 61 62 6c 65 03 02 03 07 1c 8c 80 80 80 .0table.........
|
||||
| 2832: 80 03 03 00 3e 00 00 00 17 07 30 6e 75 6d 62 65 ....>.....0numbe
|
||||
| 2848: 72 03 06 01 01 05 01 02 6f 66 03 06 04 0d 13 8c r.......of......
|
||||
| 2864: 80 80 80 80 02 03 00 2c 00 00 00 0f fc 01 03 02 .......,........
|
||||
| 2880: 30 6e 03 06 01 00 f2 07 1b 8c 80 80 80 80 01 03 0n..............
|
||||
| 2896: 00 3c 00 00 00 16 08 30 66 74 73 34 61 75 78 03 .<.....0fts4aux.
|
||||
| 2912: 03 02 01 02 69 73 03 06 04 0c 00 00 00 18 ea 00 ....is..........
|
||||
| 2928: 00 00 01 01 02 24 00 02 01 01 12 02 01 12 08 88 .....$..........
|
||||
| 2944: 80 80 80 80 12 03 00 12 10 00 00 05 02 1c 88 80 ................
|
||||
| 2960: 80 80 80 11 03 00 3e 00 00 00 17 05 34 72 6f 77 ......>.....4row
|
||||
| 2976: 73 02 06 01 01 05 01 04 74 68 65 72 02 02 04 0b s.......ther....
|
||||
| 2992: 15 88 80 80 80 80 10 03 00 2f ff ff f0 11 02 01 ........./......
|
||||
| 3008: 01 07 05 34 62 65 74 77 02 02 04 08 1b 88 80 80 ...4betw........
|
||||
| 3024: 80 80 0f cf 00 3c 00 00 00 16 04 04 33 72 6f 77 .....<......3row
|
||||
| 3040: 02 06 01 01 05 01 03 74 68 65 02 08 05 0a 1b 88 .......the......
|
||||
| 3056: 80 80 80 80 0d 03 00 3c 00 00 00 16 00 01 02 04 .......<........
|
||||
| 3072: 33 61 72 65 02 02 03 01 03 62 65 74 02 02 07 08 3are.....bet....
|
||||
| 3088: 1b 88 80 80 80 80 0d 03 00 3c 00 00 00 16 03 32 .........<.....2
|
||||
| 3104: 74 68 02 08 02 01 01 07 00 04 33 61 6e 64 02 06 th........3and..
|
||||
| 3120: 04 0a 1b 88 80 80 80 80 0c 03 00 3c 00 00 00 16 ...........<....
|
||||
| 3136: 03 32 69 6e 02 06 01 01 06 01 02 72 6f 02 06 01 .2in.......ro...
|
||||
| 3152: 01 05 04 09 18 88 80 80 80 80 0b 03 00 36 00 00 .............6..
|
||||
| 3168: 00 13 02 03 32 61 72 02 02 03 01 02 62 65 02 02 ....2ar.....be..
|
||||
| 3184: 04 05 07 1b 88 80 80 80 80 0a 03 00 3c 00 00 00 ............<...
|
||||
| 3200: 16 12 31 74 02 08 02 01 01 07 00 03 32 61 6e 02 ..1t........2an.
|
||||
| 3216: 06 01 01 04 09 19 88 80 80 80 80 09 03 00 38 00 ..............8.
|
||||
| 3232: 00 00 14 02 31 6e 02 06 01 01 03 01 01 72 02 06 ....1n.......r..
|
||||
| 3248: 01 01 05 04 08 17 78 80 80 80 80 08 03 00 34 10 ......x.......4.
|
||||
| 3264: 01 00 12 02 31 62 02 02 04 01 01 69 02 06 01 01 ....1b.....i....
|
||||
| 3280: 06 04 06 19 88 80 80 80 80 07 03 00 38 00 00 00 ............8...
|
||||
| 3296: 14 04 02 31 32 02 02 05 01 01 61 02 08 03 01 01 ...12.....a.....
|
||||
| 3312: 02 05 06 1b 88 80 80 80 80 06 03 00 3c 00 00 00 ............<...
|
||||
| 3328: 16 06 30 74 68 65 72 65 e7 02 02 00 02 31 31 02 ..0there.....11.
|
||||
| 3344: 06 01 01 04 0a 15 88 80 80 80 80 05 03 00 30 00 ..............0.
|
||||
| 3360: 00 00 11 01 01 05 e5 30 74 68 65 02 06 01 01 07 .......0the.....
|
||||
| 3376: 07 1c 88 80 80 80 80 04 03 00 3e 00 00 00 17 01 ..........>.....
|
||||
| 3392: 01 06 02 30 6e 02 06 01 01 03 01 04 72 6f 77 73 ...0n.......rows
|
||||
| 3408: 02 06 07 08 1b 88 80 80 80 80 03 03 00 3c 00 00 .............<..
|
||||
| 3424: 00 16 08 30 62 65 74 77 65 65 6e 02 02 04 01 02 ...0between.....
|
||||
| 3440: 69 6e 02 06 04 0c 1a 88 80 80 80 80 02 03 00 3a in.............:
|
||||
| 3456: 00 00 00 15 04 30 61 6e 64 02 06 01 01 02 02 02 .....0and.......
|
||||
| 3472: 72 65 02 02 03 04 0a 17 88 80 80 80 80 01 03 00 re..............
|
||||
| 3488: 34 01 00 00 12 02 30 31 02 06 01 01 04 01 01 32 4.....01.......2
|
||||
| 3504: 02 02 05 04 08 08 84 80 80 80 80 12 03 00 16 00 ................
|
||||
| 3520: 00 00 05 04 1b 84 80 80 80 80 11 03 00 3c 00 00 .............<..
|
||||
| 3536: 00 16 05 34 74 61 62 6c 01 06 01 01 05 02 03 65 ...4tabl.......e
|
||||
| 3552: 72 6d 01 02 04 0b 1b 84 80 80 80 80 10 03 00 3c rm.............<
|
||||
| 3568: 00 00 00 16 05 34 65 61 63 68 01 02 02 01 04 70 .....4each.....p
|
||||
| 3584: 72 65 73 01 02 05 04 09 1a 84 80 80 80 80 0f 03 res.............
|
||||
| 3600: 00 3a 00 00 00 15 04 33 74 65 72 01 02 04 02 02 .:.....3ter.....
|
||||
| 3616: 68 65 01 06 01 01 03 04 08 1b 84 80 80 80 80 0e he..............
|
||||
| 3632: 03 00 3c 00 00 00 16 04 33 70 72 65 01 02 05 01 ..<.....3pre....
|
||||
| 3648: 03 74 61 62 01 06 01 01 05 04 08 1a 84 80 80 80 .tab............
|
||||
| 3664: 80 0d 03 0d 1a 00 00 00 15 04 33 66 6e 72 01 02 ..........3fnr..
|
||||
| 3680: 02 02 02 74 73 01 06 01 01 04 04 08 1b 84 80 80 ...ts...........
|
||||
| 3696: 80 80 0c 03 00 3c 00 00 00 16 03 32 74 68 01 06 .....<.....2th..
|
||||
| 3712: 01 01 03 00 04 33 65 61 63 01 02 03 04 09 18 84 .....3eac.......
|
||||
| 3728: 80 80 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 .......6.....2ta
|
||||
| 3744: 01 06 01 01 05 02 01 65 01 02 04 04 09 19 84 80 .......e........
|
||||
| 3760: 80 80 80 0a 03 00 38 00 00 00 14 03 30 c9 6e 01 ......8.....0.n.
|
||||
| 3776: 06 01 01 02 01 02 70 72 01 02 05 04 09 18 84 80 ......pr........
|
||||
| 3792: 80 80 80 09 03 00 36 00 00 00 13 03 32 66 6f 01 ......6.....2fo.
|
||||
| 3808: 02 0b e2 01 74 01 06 01 01 04 04 07 1b 84 80 80 ....t...........
|
||||
| 3824: 86 f0 08 03 00 3c 00 00 00 16 02 31 74 01 0a 04 .....<.....1t...
|
||||
| 3840: 01 01 03 04 00 03 32 65 61 01 02 03 04 0a 17 84 ......2ea.......
|
||||
| 3856: 80 80 80 80 07 03 00 34 00 00 00 12 02 31 69 01 .......4.....1i.
|
||||
| 3872: 06 01 01 02 01 01 70 01 02 05 04 08 18 84 80 80 ......p.........
|
||||
| 3888: 80 80 06 03 00 36 00 00 00 13 02 31 65 01 02 03 .....6.....1e...
|
||||
| 3904: 01 01 66 01 08 02 01 01 04 04 06 1b 84 80 80 80 ..f.............
|
||||
| 3920: 80 05 03 00 3c 00 00 00 16 05 30 74 65 72 6d 01 ....<.....0term.
|
||||
| 3936: 02 04 02 02 68 65 01 06 01 01 03 04 09 14 84 80 ....he..........
|
||||
| 3952: 80 80 80 04 03 00 2e 00 00 00 10 06 30 74 61 62 ............0tab
|
||||
| 3968: 6c 65 01 06 01 01 05 04 15 84 7f 80 80 80 03 03 le..............
|
||||
| 3984: 00 30 00 00 00 11 02 08 30 70 72 65 73 65 6e 74 .0......0present
|
||||
| 4000: 01 02 05 05 1b 84 80 22 80 80 02 03 00 3c 00 00 .............<..
|
||||
| 4016: 00 16 04 30 66 74 73 01 06 01 01 04 01 02 69 6e ...0fts.......in
|
||||
| 4032: 01 06 01 01 04 0a 1a 84 80 80 80 80 01 03 00 3a ...............:
|
||||
| 4048: 00 00 00 15 05 30 65 61 63 68 01 02 03 01 03 66 .....0each.....f
|
||||
| 4064: 6f 72 01 02 02 04 09 06 01 03 00 12 03 0b 0f 00 or..............
|
||||
| 4080: 00 08 8c 80 80 80 80 11 03 00 16 00 00 00 05 04 ................
|
||||
| page 3 offset 8192
|
||||
| 0: 0a 00 00 00 32 0e 4f 00 0f fa 0f f1 0f e9 0f e1 ....2.O.........
|
||||
| 16: 0f d8 0f d1 0f c9 0f c1 0f b9 0f b1 0f a9 0f a0 ................
|
||||
| 32: 0f 98 0f 90 0f 87 0f 80 0f 78 0f 71 0f 68 0f 5f .........x.q.h._
|
||||
| 48: 0f 56 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 .V..............
|
||||
| 3392: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 ................
|
||||
| 3408: 04 01 10 01 03 34 74 20 07 04 01 0e 01 03 34 1e .....4t ......4.
|
||||
| 3424: 09 04 01 12 01 03 33 74 68 1c 08 04 01 10 01 03 ......3th.......
|
||||
| 3440: 34 6e 1a 08 04 01 10 01 03 32 67 18 08 04 01 10 4n.......2g.....
|
||||
| 3456: 01 03 32 74 16 08 04 01 10 01 03 32 6e 14 07 04 ..2t.......2n...
|
||||
| 3472: 01 0e 01 03 32 12 08 04 01 10 01 03 31 74 10 08 ....2.......1t..
|
||||
| 3488: 04 01 10 01 03 31 6e 0e 07 04 01 0e 01 03 31 0c .....1n.......1.
|
||||
| 3504: 09 04 01 12 01 03 30 74 68 0a 08 04 01 10 01 03 ......0th.......
|
||||
| 3520: 30 74 08 09 04 01 12 01 03 30 6e 75 06 08 04 01 0t.......0nu....
|
||||
| 3536: 10 01 03 30 6e 04 06 04 01 0c 01 03 02 08 04 01 ...0n...........
|
||||
| 3552: 10 01 02 34 72 22 07 04 01 0e 01 02 34 20 08 04 ...4r.......4 ..
|
||||
| 3568: 01 10 01 02 33 72 1e 09 04 01 12 01 02 33 61 72 ....3r.......3ar
|
||||
| 3584: 1c 18 04 01 10 01 02 32 74 1a 08 04 01 10 01 02 .......2t.......
|
||||
| 3600: 32 69 18 09 04 01 12 01 02 32 61 72 16 08 04 01 2i.......2ar....
|
||||
| 3616: 10 01 02 31 74 2a 08 04 01 0f 01 02 31 6e 12 0a ...1t*......1n..
|
||||
| 3632: d4 01 10 01 02 31 62 10 08 04 01 10 01 02 31 32 .....1b.......12
|
||||
| 3648: 0e 0b 04 01 16 01 02 30 74 68 65 72 0c 08 04 01 .......0ther....
|
||||
| 3664: 10 01 02 30 74 0a 08 04 01 10 01 02 30 6e 08 08 ...0t.......0n..
|
||||
| 3680: 04 01 10 01 02 30 62 06 08 04 01 10 01 02 30 61 .....0b.......0a
|
||||
| 3696: 04 06 03 f1 0c 01 02 02 07 04 09 10 01 34 74 22 .............4t.
|
||||
| 3712: 06 04 09 0e 01 34 20 08 04 09 12 01 33 74 65 1e .....4 .....3te.
|
||||
| 3728: 07 04 09 10 01 33 70 1c 07 04 09 10 01 33 66 1a .....3p......3f.
|
||||
| 3744: 08 04 09 12 01 32 74 68 18 07 04 09 10 01 32 74 .....2th......2t
|
||||
| 3760: 16 07 04 09 10 01 32 69 14 07 04 09 10 01 32 66 ......2i......2f
|
||||
| 3776: 12 07 04 09 10 01 31 74 10 07 04 09 10 01 31 69 ......1t......1i
|
||||
| 3792: 0e 06 04 09 0e 01 31 0c 08 04 09 12 01 30 74 65 ......1......0te
|
||||
| 3808: 0a 07 04 09 10 01 30 74 08 07 04 09 10 01 30 70 ......0t......0p
|
||||
| 3824: 06 08 04 09 1e 61 30 66 74 04 05 00 00 00 00 00 .....a0ft.......
|
||||
| page 4 offset 12288
|
||||
| 4064: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10 ................
|
||||
| 4080: 03 05 05 02 03 00 10 04 06 05 01 03 00 10 04 04 ................
|
||||
| page 5 offset 16384
|
||||
| 0: 0a 00 00 00 02 0f eb 00 0f eb 0f f4 00 00 00 00 ................
|
||||
| 4064: 00 00 00 00 00 00 00 00 00 00 00 08 03 15 01 70 ...............p
|
||||
| 4080: 67 73 7a 18 0b 03 1b 01 76 65 72 73 69 6f 6e 04 gsz.....version.
|
||||
| end crash-ef6738247b1344.db
|
||||
}]} {}
|
||||
|
||||
|
||||
do_catchsql_test 4.1 {
|
||||
BEGIN;
|
||||
REPLACE INTO t1(rowid,b,a,rowid) VALUES(200,1,2,3);
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
do_catchsql_test 4.2 {
|
||||
INSERT INTO t1(t1) VALUES('delete-all');
|
||||
} {1 {database disk image is malformed}}
|
||||
do_catchsql_test 4.3 {
|
||||
REPLACE INTO t1(rowid,b,rowid,a) VALUES(200,1,2,3);
|
||||
} {1 {database disk image is malformed}}
|
||||
do_catchsql_test 4.4 {
|
||||
REPLACE INTO t1(rowid,b,a,rowid) VALUES(0,1,2,3);
|
||||
} {1 {database disk image is malformed}}
|
||||
do_catchsql_test 4.5 {
|
||||
REPLACE INTO t1(rowid,a,b,rowid) VALUES(200,1,2,3);
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
sqlite3_fts5_may_be_corrupt 0
|
||||
finish_test
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
# 2015 Apr 24
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file tests that FTS5 handles corrupt databases (i.e. internal
|
||||
# inconsistencies in the backing tables) correctly. In this case
|
||||
# "correctly" means without crashing.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5corrupt6
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
sqlite3_fts5_may_be_corrupt 1
|
||||
database_may_be_corrupt
|
||||
|
||||
proc editblock {block} {
|
||||
binary format Sa* 20000 [string range $block 2 end]
|
||||
}
|
||||
db func editblock editblock
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(abc, def);
|
||||
WITH a(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM a WHERE i<1000
|
||||
)
|
||||
INSERT INTO ft SELECT
|
||||
'abc abc abc abc abc abc abc abc abc abc',
|
||||
'def def def def def def def def def def'
|
||||
FROM a;
|
||||
UPDATE ft_data SET block = editblock(block) WHERE id=(
|
||||
SELECT id FROM ft_data ORDER BY id LIMIT 1 OFFSET 5
|
||||
);
|
||||
}
|
||||
|
||||
do_catchsql_test 1.1 {
|
||||
SELECT rowid FROM ft('def') ORDER BY rowid DESC LIMIT 1 OFFSET 9999;
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
|
||||
sqlite3_fts5_may_be_corrupt 0
|
||||
finish_test
|
||||
|
||||
@@ -83,7 +83,7 @@ for {set i 0} {$i < 255} {incr i} {
|
||||
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE e1 USING fts5(text, tokenize = 'porter unicode61');
|
||||
INSERT INTO e1 VALUES ('just a few words with a / inside');
|
||||
INSERT INTO e1 VALUES ("just a few words with a / inside");
|
||||
}
|
||||
do_execsql_test 3.1 {
|
||||
SELECT rowid, bm25(e1) FROM e1 WHERE e1 MATCH '"just"' ORDER BY rank;
|
||||
|
||||
@@ -188,11 +188,11 @@ foreach {tn pgsz} {
|
||||
INSERT INTO hh(hh, rank) VALUES('pgsz', $pgsz);
|
||||
|
||||
WITH s(i) AS (SELECT 0 UNION ALL SELECT i+1 FROM s WHERE i<999)
|
||||
INSERT INTO hh SELECT printf('%.3d%.3d%.3d %.3d%.3d%.3d',i,i,i,i+1,i+1,i+1)
|
||||
INSERT INTO hh SELECT printf("%.3d%.3d%.3d %.3d%.3d%.3d",i,i,i,i+1,i+1,i+1)
|
||||
FROM s;
|
||||
|
||||
WITH s(i) AS (SELECT 0 UNION ALL SELECT i+1 FROM s WHERE i<999)
|
||||
INSERT INTO hh SELECT printf('%.3d%.3d%.3d %.3d%.3d%.3d',i,i,i,i+1,i+1,i+1)
|
||||
INSERT INTO hh SELECT printf("%.3d%.3d%.3d %.3d%.3d%.3d",i,i,i,i+1,i+1,i+1)
|
||||
FROM s;
|
||||
|
||||
INSERT INTO hh(hh) VALUES('optimize');
|
||||
|
||||
@@ -255,32 +255,6 @@ do_test 5.1 {
|
||||
do_execsql_test 5.2 {
|
||||
SELECT * FROM t1
|
||||
} {one two three four five}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Check that the fts5 table cannot be written while there are vocab
|
||||
# cursors open.
|
||||
reset_db
|
||||
do_execsql_test 5.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(a);
|
||||
CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
|
||||
WITH s(i) AS (
|
||||
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10000
|
||||
)
|
||||
INSERT INTO t1 SELECT
|
||||
'State Emergency Service (SES), Rural Fire Service (RFS) and Volunteers'
|
||||
FROM s;
|
||||
}
|
||||
|
||||
do_catchsql_test 5.1 {
|
||||
INSERT INTO t1 SELECT rowid FROM v1
|
||||
} {1 {query aborted}}
|
||||
|
||||
do_catchsql_test 5.2 {
|
||||
DELETE FROM t1 WHERE rowid>100;
|
||||
INSERT INTO t1 SELECT randomblob(3000) FROM v1
|
||||
} {1 {query aborted}}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
@@ -60,8 +60,7 @@ proc fts5_source_id {zDir} {
|
||||
|
||||
set L [split [readfile [file join $top manifest]]]
|
||||
set date [lindex $L [expr [lsearch -exact $L D]+1]]
|
||||
set idx [expr {[string last . $date]-1}]
|
||||
set date [string range $date 0 $idx]
|
||||
set date [string range $date 0 [string last . $date]-1]
|
||||
set date [string map {T { }} $date]
|
||||
|
||||
return "fts5: $date $uuid"
|
||||
|
||||
+10
-4
@@ -153,12 +153,18 @@ SQLite. Documentation follows.
|
||||
the ICU extension LIKE operator is 50000, defined in source
|
||||
file "icu.c".
|
||||
|
||||
3.3 Collation Sequence Security
|
||||
3.3 Collation Sequence Security Issue
|
||||
|
||||
Internally, SQLite assumes that indices stored in database files
|
||||
are sorted according to the collation sequence indicated by the
|
||||
SQL schema. Changing the definition of a collation sequence after
|
||||
an index has been built is therefore equivalent to database
|
||||
corruption. The SQLite library is well tested for robustness in
|
||||
the fact of database corruption. Database corruption may well
|
||||
lead to incorrect answers, but should not cause memory errors.
|
||||
corruption. The SQLite library is not very well tested under
|
||||
these conditions, and may contain potential buffer overruns
|
||||
or other programming errors that could be exploited by a malicious
|
||||
programmer.
|
||||
|
||||
If the ICU extension is used in an environment where potentially
|
||||
malicious users may execute arbitrary SQL (i.e. gears), they
|
||||
should be prevented from invoking the icu_load_collation() function,
|
||||
possibly using the authorisation callback.
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
**
|
||||
** The virtual table contains read-only hidden columns:
|
||||
**
|
||||
** lsm1_key A BLOB which is the raw LSM key. If the "keytype"
|
||||
** lsm1_key A BLOB which is the raw LSM key. If the "keytype"
|
||||
** is BLOB or TEXT then this column is exactly the
|
||||
** same as the key. For the UINT keytype, this column
|
||||
** will be a variable-length integer encoding of the key.
|
||||
|
||||
+1
-1
@@ -464,7 +464,7 @@ SQLITE_API int sqlite3_carray_bind(
|
||||
z += n+1;
|
||||
}
|
||||
}else{
|
||||
memcpy(pNew->aData, aData, sz);
|
||||
memcpy(pNew->aData, aData, sz*nData);
|
||||
}
|
||||
pNew->xDel = sqlite3_free;
|
||||
}else{
|
||||
|
||||
+1
-1
@@ -941,7 +941,7 @@ int sqlite3_csv_init(
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
int rc;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
rc = sqlite3_create_module(db, "csv", &CsvModule, 0);
|
||||
|
||||
+1
-31
@@ -72,11 +72,6 @@
|
||||
** $path is a relative path, then $path is interpreted relative to $dir.
|
||||
** And the paths returned in the "name" column of the table are also
|
||||
** relative to directory $dir.
|
||||
**
|
||||
** Notes on building this extension for Windows:
|
||||
** Unless linked statically with the SQLite library, a preprocessor
|
||||
** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
|
||||
** DLL form of this extension for WIN32. See its use below for details.
|
||||
*/
|
||||
#include "sqlite3ext.h"
|
||||
SQLITE_EXTENSION_INIT1
|
||||
@@ -230,22 +225,6 @@ static sqlite3_uint64 fileTimeToUnixTime(
|
||||
return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
|
||||
}
|
||||
|
||||
|
||||
#if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
|
||||
# /* To allow a standalone DLL, use this next replacement function: */
|
||||
# undef sqlite3_win32_utf8_to_unicode
|
||||
# define sqlite3_win32_utf8_to_unicode utf8_to_utf16
|
||||
#
|
||||
LPWSTR utf8_to_utf16(const char *z){
|
||||
int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0);
|
||||
LPWSTR rv = sqlite3_malloc(nAllot * sizeof(WCHAR));
|
||||
if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) )
|
||||
return rv;
|
||||
sqlite3_free(rv);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This function attempts to normalize the time values found in the stat()
|
||||
** buffer to UTC. This is necessary on Win32, where the runtime library
|
||||
@@ -368,11 +347,10 @@ static int writeFile(
|
||||
mode_t mode, /* MODE parameter passed to writefile() */
|
||||
sqlite3_int64 mtime /* MTIME parameter (or -1 to not set time) */
|
||||
){
|
||||
if( zFile==0 ) return 1;
|
||||
#if !defined(_WIN32) && !defined(WIN32)
|
||||
if( S_ISLNK(mode) ){
|
||||
const char *zTo = (const char*)sqlite3_value_text(pData);
|
||||
if( zTo==0 || symlink(zTo, zFile)<0 ) return 1;
|
||||
if( symlink(zTo, zFile)<0 ) return 1;
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
@@ -1020,11 +998,3 @@ int sqlite3_fileio_init(
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
|
||||
/* To allow a standalone DLL, make test_windirent.c use the same
|
||||
* redefined SQLite API calls as the above extension code does.
|
||||
* Just pull in this .c to accomplish this. As a beneficial side
|
||||
* effect, this extension becomes a single translation unit. */
|
||||
# include "test_windirent.c"
|
||||
#endif
|
||||
|
||||
+2
-6
@@ -194,11 +194,7 @@ static void ieee754func(
|
||||
e += 1075;
|
||||
if( e<=0 ){
|
||||
/* Subnormal */
|
||||
if( 1-e >= 64 ){
|
||||
m = 0;
|
||||
}else{
|
||||
m >>= 1-e;
|
||||
}
|
||||
m >>= 1-e;
|
||||
e = 0;
|
||||
}else if( e>0x7ff ){
|
||||
e = 0x7ff;
|
||||
@@ -284,7 +280,7 @@ int sqlite3_ieee_init(
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg; /* Unused parameter */
|
||||
for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
|
||||
rc = sqlite3_create_function(db, aFunc[i].zFName, aFunc[i].nArg,
|
||||
rc = sqlite3_create_function(db, aFunc[i].zFName, aFunc[i].nArg,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS,
|
||||
(void*)&aFunc[i].iAux,
|
||||
aFunc[i].xFunc, 0, 0);
|
||||
|
||||
+209
-252
@@ -10,10 +10,10 @@
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This SQLite JSON functions.
|
||||
** This SQLite extension implements JSON functions. The interface is
|
||||
** modeled after MySQL JSON functions:
|
||||
**
|
||||
** This file began as an extension in ext/misc/json1.c in 2015. That
|
||||
** extension proved so useful that it has now been moved into the core.
|
||||
** https://dev.mysql.com/doc/refman/5.7/en/json.html
|
||||
**
|
||||
** For the time being, all JSON is stored as pure text. (We might add
|
||||
** a JSONB type in the future which stores a binary encoding of JSON in
|
||||
@@ -21,8 +21,48 @@
|
||||
** This implementation parses JSON text at 250 MB/s, so it is hard to see
|
||||
** how JSONB might improve on that.)
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_JSON
|
||||
#include "sqliteInt.h"
|
||||
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1)
|
||||
#if !defined(SQLITEINT_H)
|
||||
#include "sqlite3ext.h"
|
||||
#endif
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Mark a function parameter as unused, to suppress nuisance compiler
|
||||
** warnings. */
|
||||
#ifndef UNUSED_PARAM
|
||||
# define UNUSED_PARAM(X) (void)(X)
|
||||
#endif
|
||||
|
||||
#ifndef LARGEST_INT64
|
||||
# define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))
|
||||
# define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
|
||||
#endif
|
||||
|
||||
#ifndef deliberate_fall_through
|
||||
# define deliberate_fall_through
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Versions of isspace(), isalnum() and isdigit() to which it is safe
|
||||
** to pass signed char values.
|
||||
*/
|
||||
#ifdef sqlite3Isdigit
|
||||
/* Use the SQLite core versions if this routine is part of the
|
||||
** SQLite amalgamation */
|
||||
# define safe_isdigit(x) sqlite3Isdigit(x)
|
||||
# define safe_isalnum(x) sqlite3Isalnum(x)
|
||||
# define safe_isxdigit(x) sqlite3Isxdigit(x)
|
||||
#else
|
||||
/* Use the standard library for separate compilation */
|
||||
#include <ctype.h> /* amalgamator: keep */
|
||||
# define safe_isdigit(x) isdigit((unsigned char)(x))
|
||||
# define safe_isalnum(x) isalnum((unsigned char)(x))
|
||||
# define safe_isxdigit(x) isxdigit((unsigned char)(x))
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Growing our own isspace() routine this way is twice as fast as
|
||||
@@ -47,12 +87,15 @@ static const char jsonIsSpace[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
#define fast_isspace(x) (jsonIsSpace[(unsigned char)x])
|
||||
#define safe_isspace(x) (jsonIsSpace[(unsigned char)x])
|
||||
|
||||
#if !defined(SQLITE_DEBUG) && !defined(SQLITE_COVERAGE_TEST)
|
||||
# define VVA(X)
|
||||
#else
|
||||
# define VVA(X) X
|
||||
#ifndef SQLITE_AMALGAMATION
|
||||
/* Unsigned integer types. These are already defined in the sqliteInt.h,
|
||||
** but the definitions need to be repeated for separate compilation. */
|
||||
typedef sqlite3_uint64 u64;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned short int u16;
|
||||
typedef unsigned char u8;
|
||||
#endif
|
||||
|
||||
/* Objects */
|
||||
@@ -111,14 +154,13 @@ static const char * const jsonType[] = {
|
||||
struct JsonNode {
|
||||
u8 eType; /* One of the JSON_ type values */
|
||||
u8 jnFlags; /* JNODE flags */
|
||||
u8 eU; /* Which union element to use */
|
||||
u32 n; /* Bytes of content, or number of sub-nodes */
|
||||
union {
|
||||
const char *zJContent; /* 1: Content for INT, REAL, and STRING */
|
||||
u32 iAppend; /* 2: More terms for ARRAY and OBJECT */
|
||||
u32 iKey; /* 3: Key for ARRAY objects in json_tree() */
|
||||
u32 iReplace; /* 4: Replacement content for JNODE_REPLACE */
|
||||
JsonNode *pPatch; /* 5: Node chain of patch for JNODE_PATCH */
|
||||
const char *zJContent; /* Content for INT, REAL, and STRING */
|
||||
u32 iAppend; /* More terms for ARRAY and OBJECT */
|
||||
u32 iKey; /* Key for ARRAY objects in json_tree() */
|
||||
u32 iReplace; /* Replacement content for JNODE_REPLACE */
|
||||
JsonNode *pPatch; /* Node chain of patch for JNODE_PATCH */
|
||||
} u;
|
||||
};
|
||||
|
||||
@@ -396,14 +438,11 @@ static void jsonRenderNode(
|
||||
JsonString *pOut, /* Write JSON here */
|
||||
sqlite3_value **aReplace /* Replacement values */
|
||||
){
|
||||
assert( pNode!=0 );
|
||||
if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){
|
||||
if( (pNode->jnFlags & JNODE_REPLACE)!=0 && ALWAYS(aReplace!=0) ){
|
||||
assert( pNode->eU==4 );
|
||||
if( pNode->jnFlags & JNODE_REPLACE ){
|
||||
jsonAppendValue(pOut, aReplace[pNode->u.iReplace]);
|
||||
return;
|
||||
}
|
||||
assert( pNode->eU==5 );
|
||||
pNode = pNode->u.pPatch;
|
||||
}
|
||||
switch( pNode->eType ){
|
||||
@@ -422,7 +461,6 @@ static void jsonRenderNode(
|
||||
}
|
||||
case JSON_STRING: {
|
||||
if( pNode->jnFlags & JNODE_RAW ){
|
||||
assert( pNode->eU==1 );
|
||||
jsonAppendString(pOut, pNode->u.zJContent, pNode->n);
|
||||
break;
|
||||
}
|
||||
@@ -430,7 +468,6 @@ static void jsonRenderNode(
|
||||
}
|
||||
case JSON_REAL:
|
||||
case JSON_INT: {
|
||||
assert( pNode->eU==1 );
|
||||
jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
|
||||
break;
|
||||
}
|
||||
@@ -446,7 +483,6 @@ static void jsonRenderNode(
|
||||
j += jsonNodeSize(&pNode[j]);
|
||||
}
|
||||
if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
|
||||
assert( pNode->eU==2 );
|
||||
pNode = &pNode[pNode->u.iAppend];
|
||||
j = 1;
|
||||
}
|
||||
@@ -467,7 +503,6 @@ static void jsonRenderNode(
|
||||
j += 1 + jsonNodeSize(&pNode[j+1]);
|
||||
}
|
||||
if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
|
||||
assert( pNode->eU==2 );
|
||||
pNode = &pNode[pNode->u.iAppend];
|
||||
j = 1;
|
||||
}
|
||||
@@ -512,10 +547,10 @@ static u8 jsonHexToInt(int h){
|
||||
*/
|
||||
static u32 jsonHexToInt4(const char *z){
|
||||
u32 v;
|
||||
assert( sqlite3Isxdigit(z[0]) );
|
||||
assert( sqlite3Isxdigit(z[1]) );
|
||||
assert( sqlite3Isxdigit(z[2]) );
|
||||
assert( sqlite3Isxdigit(z[3]) );
|
||||
assert( safe_isxdigit(z[0]) );
|
||||
assert( safe_isxdigit(z[1]) );
|
||||
assert( safe_isxdigit(z[2]) );
|
||||
assert( safe_isxdigit(z[3]) );
|
||||
v = (jsonHexToInt(z[0])<<12)
|
||||
+ (jsonHexToInt(z[1])<<8)
|
||||
+ (jsonHexToInt(z[2])<<4)
|
||||
@@ -547,9 +582,7 @@ static void jsonReturn(
|
||||
}
|
||||
case JSON_INT: {
|
||||
sqlite3_int64 i = 0;
|
||||
const char *z;
|
||||
assert( pNode->eU==1 );
|
||||
z = pNode->u.zJContent;
|
||||
const char *z = pNode->u.zJContent;
|
||||
if( z[0]=='-' ){ z++; }
|
||||
while( z[0]>='0' && z[0]<='9' ){
|
||||
unsigned v = *(z++) - '0';
|
||||
@@ -572,17 +605,14 @@ static void jsonReturn(
|
||||
sqlite3_result_int64(pCtx, i);
|
||||
int_done:
|
||||
break;
|
||||
int_as_real: ; /* no break */ deliberate_fall_through
|
||||
int_as_real: i=0; /* no break */ deliberate_fall_through
|
||||
}
|
||||
case JSON_REAL: {
|
||||
double r;
|
||||
#ifdef SQLITE_AMALGAMATION
|
||||
const char *z;
|
||||
assert( pNode->eU==1 );
|
||||
z = pNode->u.zJContent;
|
||||
const char *z = pNode->u.zJContent;
|
||||
sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
|
||||
#else
|
||||
assert( pNode->eU==1 );
|
||||
r = strtod(pNode->u.zJContent, 0);
|
||||
#endif
|
||||
sqlite3_result_double(pCtx, r);
|
||||
@@ -593,7 +623,6 @@ static void jsonReturn(
|
||||
** json_insert() and json_replace() and those routines do not
|
||||
** call jsonReturn() */
|
||||
if( pNode->jnFlags & JNODE_RAW ){
|
||||
assert( pNode->eU==1 );
|
||||
sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
|
||||
SQLITE_TRANSIENT);
|
||||
}else
|
||||
@@ -601,18 +630,15 @@ static void jsonReturn(
|
||||
assert( (pNode->jnFlags & JNODE_RAW)==0 );
|
||||
if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
|
||||
/* JSON formatted without any backslash-escapes */
|
||||
assert( pNode->eU==1 );
|
||||
sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2,
|
||||
SQLITE_TRANSIENT);
|
||||
}else{
|
||||
/* Translate JSON formatted string into raw text */
|
||||
u32 i;
|
||||
u32 n = pNode->n;
|
||||
const char *z;
|
||||
const char *z = pNode->u.zJContent;
|
||||
char *zOut;
|
||||
u32 j;
|
||||
assert( pNode->eU==1 );
|
||||
z = pNode->u.zJContent;
|
||||
zOut = sqlite3_malloc( n+1 );
|
||||
if( zOut==0 ){
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
@@ -733,13 +759,12 @@ static int jsonParseAddNode(
|
||||
const char *zContent /* Content */
|
||||
){
|
||||
JsonNode *p;
|
||||
if( pParse->aNode==0 || pParse->nNode>=pParse->nAlloc ){
|
||||
if( pParse->nNode>=pParse->nAlloc ){
|
||||
return jsonParseAddNodeExpand(pParse, eType, n, zContent);
|
||||
}
|
||||
p = &pParse->aNode[pParse->nNode];
|
||||
p->eType = (u8)eType;
|
||||
p->jnFlags = 0;
|
||||
VVA( p->eU = zContent ? 1 : 0 );
|
||||
p->n = n;
|
||||
p->u.zJContent = zContent;
|
||||
return pParse->nNode++;
|
||||
@@ -750,7 +775,7 @@ static int jsonParseAddNode(
|
||||
*/
|
||||
static int jsonIs4Hex(const char *z){
|
||||
int i;
|
||||
for(i=0; i<4; i++) if( !sqlite3Isxdigit(z[i]) ) return 0;
|
||||
for(i=0; i<4; i++) if( !safe_isxdigit(z[i]) ) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -769,13 +794,13 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
int x;
|
||||
JsonNode *pNode;
|
||||
const char *z = pParse->zJson;
|
||||
while( fast_isspace(z[i]) ){ i++; }
|
||||
while( safe_isspace(z[i]) ){ i++; }
|
||||
if( (c = z[i])=='{' ){
|
||||
/* Parse object */
|
||||
iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
|
||||
if( iThis<0 ) return -1;
|
||||
for(j=i+1;;j++){
|
||||
while( fast_isspace(z[j]) ){ j++; }
|
||||
while( safe_isspace(z[j]) ){ j++; }
|
||||
if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
|
||||
x = jsonParseValue(pParse, j);
|
||||
if( x<0 ){
|
||||
@@ -788,14 +813,14 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
if( pNode->eType!=JSON_STRING ) return -1;
|
||||
pNode->jnFlags |= JNODE_LABEL;
|
||||
j = x;
|
||||
while( fast_isspace(z[j]) ){ j++; }
|
||||
while( safe_isspace(z[j]) ){ j++; }
|
||||
if( z[j]!=':' ) return -1;
|
||||
j++;
|
||||
x = jsonParseValue(pParse, j);
|
||||
pParse->iDepth--;
|
||||
if( x<0 ) return -1;
|
||||
j = x;
|
||||
while( fast_isspace(z[j]) ){ j++; }
|
||||
while( safe_isspace(z[j]) ){ j++; }
|
||||
c = z[j];
|
||||
if( c==',' ) continue;
|
||||
if( c!='}' ) return -1;
|
||||
@@ -807,9 +832,8 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
/* Parse array */
|
||||
iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
|
||||
if( iThis<0 ) return -1;
|
||||
memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u));
|
||||
for(j=i+1;;j++){
|
||||
while( fast_isspace(z[j]) ){ j++; }
|
||||
while( safe_isspace(z[j]) ){ j++; }
|
||||
if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
|
||||
x = jsonParseValue(pParse, j);
|
||||
pParse->iDepth--;
|
||||
@@ -818,7 +842,7 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
return -1;
|
||||
}
|
||||
j = x;
|
||||
while( fast_isspace(z[j]) ){ j++; }
|
||||
while( safe_isspace(z[j]) ){ j++; }
|
||||
c = z[j];
|
||||
if( c==',' ) continue;
|
||||
if( c!=']' ) return -1;
|
||||
@@ -855,17 +879,17 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
return j+1;
|
||||
}else if( c=='n'
|
||||
&& strncmp(z+i,"null",4)==0
|
||||
&& !sqlite3Isalnum(z[i+4]) ){
|
||||
&& !safe_isalnum(z[i+4]) ){
|
||||
jsonParseAddNode(pParse, JSON_NULL, 0, 0);
|
||||
return i+4;
|
||||
}else if( c=='t'
|
||||
&& strncmp(z+i,"true",4)==0
|
||||
&& !sqlite3Isalnum(z[i+4]) ){
|
||||
&& !safe_isalnum(z[i+4]) ){
|
||||
jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
|
||||
return i+4;
|
||||
}else if( c=='f'
|
||||
&& strncmp(z+i,"false",5)==0
|
||||
&& !sqlite3Isalnum(z[i+5]) ){
|
||||
&& !safe_isalnum(z[i+5]) ){
|
||||
jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
|
||||
return i+5;
|
||||
}else if( c=='-' || (c>='0' && c<='9') ){
|
||||
@@ -936,7 +960,7 @@ static int jsonParse(
|
||||
if( pParse->oom ) i = -1;
|
||||
if( i>0 ){
|
||||
assert( pParse->iDepth==0 );
|
||||
while( fast_isspace(zJson[i]) ) i++;
|
||||
while( safe_isspace(zJson[i]) ) i++;
|
||||
if( zJson[i] ) i = -1;
|
||||
}
|
||||
if( i<=0 ){
|
||||
@@ -1072,7 +1096,6 @@ static JsonParse *jsonParseCached(
|
||||
** a match.
|
||||
*/
|
||||
static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
|
||||
assert( pNode->eU==1 );
|
||||
if( pNode->jnFlags & JNODE_RAW ){
|
||||
if( pNode->n!=nKey ) return 0;
|
||||
return strncmp(pNode->u.zJContent, zKey, nKey)==0;
|
||||
@@ -1138,7 +1161,6 @@ static JsonNode *jsonLookupStep(
|
||||
j += jsonNodeSize(&pRoot[j]);
|
||||
}
|
||||
if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
|
||||
assert( pRoot->eU==2 );
|
||||
iRoot += pRoot->u.iAppend;
|
||||
pRoot = &pParse->aNode[iRoot];
|
||||
j = 1;
|
||||
@@ -1153,10 +1175,8 @@ static JsonNode *jsonLookupStep(
|
||||
if( pParse->oom ) return 0;
|
||||
if( pNode ){
|
||||
pRoot = &pParse->aNode[iRoot];
|
||||
assert( pRoot->eU==0 );
|
||||
pRoot->u.iAppend = iStart - iRoot;
|
||||
pRoot->jnFlags |= JNODE_APPEND;
|
||||
VVA( pRoot->eU = 2 );
|
||||
pParse->aNode[iLabel].jnFlags |= JNODE_RAW;
|
||||
}
|
||||
return pNode;
|
||||
@@ -1164,7 +1184,7 @@ static JsonNode *jsonLookupStep(
|
||||
}else if( zPath[0]=='[' ){
|
||||
i = 0;
|
||||
j = 1;
|
||||
while( sqlite3Isdigit(zPath[j]) ){
|
||||
while( safe_isdigit(zPath[j]) ){
|
||||
i = i*10 + zPath[j] - '0';
|
||||
j++;
|
||||
}
|
||||
@@ -1179,19 +1199,18 @@ static JsonNode *jsonLookupStep(
|
||||
j += jsonNodeSize(&pBase[j]);
|
||||
}
|
||||
if( (pBase->jnFlags & JNODE_APPEND)==0 ) break;
|
||||
assert( pBase->eU==2 );
|
||||
iBase += pBase->u.iAppend;
|
||||
pBase = &pParse->aNode[iBase];
|
||||
j = 1;
|
||||
}
|
||||
j = 2;
|
||||
if( zPath[2]=='-' && sqlite3Isdigit(zPath[3]) ){
|
||||
if( zPath[2]=='-' && safe_isdigit(zPath[3]) ){
|
||||
unsigned int x = 0;
|
||||
j = 3;
|
||||
do{
|
||||
x = x*10 + zPath[j] - '0';
|
||||
j++;
|
||||
}while( sqlite3Isdigit(zPath[j]) );
|
||||
}while( safe_isdigit(zPath[j]) );
|
||||
if( x>i ) return 0;
|
||||
i -= x;
|
||||
}
|
||||
@@ -1213,7 +1232,6 @@ static JsonNode *jsonLookupStep(
|
||||
j += jsonNodeSize(&pRoot[j]);
|
||||
}
|
||||
if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
|
||||
assert( pRoot->eU==2 );
|
||||
iRoot += pRoot->u.iAppend;
|
||||
pRoot = &pParse->aNode[iRoot];
|
||||
j = 1;
|
||||
@@ -1229,10 +1247,8 @@ static JsonNode *jsonLookupStep(
|
||||
if( pParse->oom ) return 0;
|
||||
if( pNode ){
|
||||
pRoot = &pParse->aNode[iRoot];
|
||||
assert( pRoot->eU==0 );
|
||||
pRoot->u.iAppend = iStart - iRoot;
|
||||
pRoot->jnFlags |= JNODE_APPEND;
|
||||
VVA( pRoot->eU = 2 );
|
||||
}
|
||||
return pNode;
|
||||
}
|
||||
@@ -1386,13 +1402,9 @@ static void jsonParseFunc(
|
||||
}
|
||||
jsonPrintf(100, &s,"node %3u: %7s n=%-4d up=%-4d",
|
||||
i, zType, x.aNode[i].n, x.aUp[i]);
|
||||
assert( x.aNode[i].eU==0 || x.aNode[i].eU==1 );
|
||||
if( x.aNode[i].u.zJContent!=0 ){
|
||||
assert( x.aNode[i].eU==1 );
|
||||
jsonAppendRaw(&s, " ", 1);
|
||||
jsonAppendRaw(&s, x.aNode[i].u.zJContent, x.aNode[i].n);
|
||||
}else{
|
||||
assert( x.aNode[i].eU==0 );
|
||||
}
|
||||
jsonAppendRaw(&s, "\n", 1);
|
||||
}
|
||||
@@ -1410,7 +1422,7 @@ static void jsonTest1Func(
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAM(argc);
|
||||
sqlite3_result_int(ctx, sqlite3_value_subtype(argv[0])==JSON_SUBTYPE);
|
||||
}
|
||||
#endif /* SQLITE_DEBUG */
|
||||
@@ -1431,7 +1443,7 @@ static void jsonQuoteFunc(
|
||||
sqlite3_value **argv
|
||||
){
|
||||
JsonString jx;
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAM(argc);
|
||||
|
||||
jsonInit(&jx, ctx);
|
||||
jsonAppendValue(&jx, argv[0]);
|
||||
@@ -1502,34 +1514,13 @@ static void jsonArrayLengthFunc(
|
||||
sqlite3_result_int64(ctx, n);
|
||||
}
|
||||
|
||||
/*
|
||||
** Bit values for the flags passed into jsonExtractFunc() or
|
||||
** jsonSetFunc() via the user-data value.
|
||||
*/
|
||||
#define JSON_JSON 0x01 /* Result is always JSON */
|
||||
#define JSON_SQL 0x02 /* Result is always SQL */
|
||||
#define JSON_ABPATH 0x03 /* Allow abbreviated JSON path specs */
|
||||
#define JSON_ISSET 0x04 /* json_set(), not json_insert() */
|
||||
|
||||
/*
|
||||
** json_extract(JSON, PATH, ...)
|
||||
** "->"(JSON,PATH)
|
||||
** "->>"(JSON,PATH)
|
||||
**
|
||||
** Return the element described by PATH. Return NULL if that PATH element
|
||||
** is not found.
|
||||
**
|
||||
** If JSON_JSON is set or if more that one PATH argument is supplied then
|
||||
** always return a JSON representation of the result. If JSON_SQL is set,
|
||||
** then always return an SQL representation of the result. If neither flag
|
||||
** is present and argc==2, then return JSON for objects and arrays and SQL
|
||||
** for all other values.
|
||||
**
|
||||
** When multiple PATH arguments are supplied, the result is a JSON array
|
||||
** containing the result of each PATH.
|
||||
**
|
||||
** Abbreviated JSON path expressions are allows if JSON_ABPATH, for
|
||||
** compatibility with PG.
|
||||
** Return the element described by PATH. Return NULL if there is no
|
||||
** PATH element. If there are multiple PATHs, then return a JSON array
|
||||
** with the result from each path. Throw an error if the JSON or any PATH
|
||||
** is malformed.
|
||||
*/
|
||||
static void jsonExtractFunc(
|
||||
sqlite3_context *ctx,
|
||||
@@ -1539,77 +1530,35 @@ static void jsonExtractFunc(
|
||||
JsonParse *p; /* The parse */
|
||||
JsonNode *pNode;
|
||||
const char *zPath;
|
||||
int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
|
||||
JsonString jx;
|
||||
int i;
|
||||
|
||||
if( argc<2 ) return;
|
||||
p = jsonParseCached(ctx, argv, ctx);
|
||||
if( p==0 ) return;
|
||||
if( argc==2 ){
|
||||
/* With a single PATH argument */
|
||||
zPath = (const char*)sqlite3_value_text(argv[1]);
|
||||
if( zPath==0 ) return;
|
||||
if( flags & JSON_ABPATH ){
|
||||
if( zPath[0]!='$' ){
|
||||
/* The -> and ->> operators accept abbreviated PATH arguments. This
|
||||
** is mostly for compatibility with PostgreSQL, but also for
|
||||
** convenience.
|
||||
**
|
||||
** NUMBER ==> $[NUMBER] // PG compatible
|
||||
** LABEL ==> $.LABEL // PG compatible
|
||||
** [NUMBER] ==> $[NUMBER] // Not PG. Purely for convenience
|
||||
*/
|
||||
jsonInit(&jx, ctx);
|
||||
if( sqlite3Isdigit(zPath[0]) ){
|
||||
jsonAppendRaw(&jx, "$[", 2);
|
||||
jsonAppendRaw(&jx, zPath, (int)strlen(zPath));
|
||||
jsonAppendRaw(&jx, "]", 2);
|
||||
}else{
|
||||
jsonAppendRaw(&jx, "$.", 1 + (zPath[0]!='['));
|
||||
jsonAppendRaw(&jx, zPath, (int)strlen(zPath));
|
||||
jsonAppendChar(&jx, 0);
|
||||
}
|
||||
pNode = jx.bErr ? 0 : jsonLookup(p, jx.zBuf, 0, ctx);
|
||||
jsonReset(&jx);
|
||||
}else{
|
||||
pNode = jsonLookup(p, zPath, 0, ctx);
|
||||
}
|
||||
if( pNode ){
|
||||
if( flags & JSON_JSON ){
|
||||
jsonReturnJson(pNode, ctx, 0);
|
||||
}else{
|
||||
jsonReturn(pNode, ctx, 0);
|
||||
sqlite3_result_subtype(ctx, 0);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
pNode = jsonLookup(p, zPath, 0, ctx);
|
||||
if( p->nErr==0 && pNode ) jsonReturn(pNode, ctx, 0);
|
||||
}
|
||||
}else{
|
||||
/* Two or more PATH arguments results in a JSON array with each
|
||||
** element of the array being the value selected by one of the PATHs */
|
||||
int i;
|
||||
jsonInit(&jx, ctx);
|
||||
jsonAppendChar(&jx, '[');
|
||||
for(i=1; i<argc; i++){
|
||||
zPath = (const char*)sqlite3_value_text(argv[i]);
|
||||
pNode = jsonLookup(p, zPath, 0, ctx);
|
||||
if( p->nErr ) break;
|
||||
jsonInit(&jx, ctx);
|
||||
jsonAppendChar(&jx, '[');
|
||||
for(i=1; i<argc; i++){
|
||||
zPath = (const char*)sqlite3_value_text(argv[i]);
|
||||
pNode = jsonLookup(p, zPath, 0, ctx);
|
||||
if( p->nErr ) break;
|
||||
if( argc>2 ){
|
||||
jsonAppendSeparator(&jx);
|
||||
if( pNode ){
|
||||
jsonRenderNode(pNode, &jx, 0);
|
||||
}else{
|
||||
jsonAppendRaw(&jx, "null", 4);
|
||||
}
|
||||
}else if( pNode ){
|
||||
jsonReturn(pNode, ctx, 0);
|
||||
}
|
||||
if( i==argc ){
|
||||
jsonAppendChar(&jx, ']');
|
||||
jsonResult(&jx);
|
||||
sqlite3_result_subtype(ctx, JSON_SUBTYPE);
|
||||
}
|
||||
jsonReset(&jx);
|
||||
}
|
||||
if( argc>2 && i==argc ){
|
||||
jsonAppendChar(&jx, ']');
|
||||
jsonResult(&jx);
|
||||
sqlite3_result_subtype(ctx, JSON_SUBTYPE);
|
||||
}
|
||||
jsonReset(&jx);
|
||||
}
|
||||
|
||||
/* This is the RFC 7396 MergePatch algorithm.
|
||||
@@ -1625,7 +1574,7 @@ static JsonNode *jsonMergePatch(
|
||||
if( pPatch->eType!=JSON_OBJECT ){
|
||||
return pPatch;
|
||||
}
|
||||
assert( iTarget<pParse->nNode );
|
||||
assert( iTarget>=0 && iTarget<pParse->nNode );
|
||||
pTarget = &pParse->aNode[iTarget];
|
||||
assert( (pPatch->jnFlags & JNODE_APPEND)==0 );
|
||||
if( pTarget->eType!=JSON_OBJECT ){
|
||||
@@ -1638,7 +1587,6 @@ static JsonNode *jsonMergePatch(
|
||||
const char *zKey;
|
||||
assert( pPatch[i].eType==JSON_STRING );
|
||||
assert( pPatch[i].jnFlags & JNODE_LABEL );
|
||||
assert( pPatch[i].eU==1 );
|
||||
nKey = pPatch[i].n;
|
||||
zKey = pPatch[i].u.zJContent;
|
||||
assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
|
||||
@@ -1655,12 +1603,6 @@ static JsonNode *jsonMergePatch(
|
||||
if( pNew==0 ) return 0;
|
||||
pTarget = &pParse->aNode[iTarget];
|
||||
if( pNew!=&pTarget[j+1] ){
|
||||
assert( pTarget[j+1].eU==0
|
||||
|| pTarget[j+1].eU==1
|
||||
|| pTarget[j+1].eU==2 );
|
||||
testcase( pTarget[j+1].eU==1 );
|
||||
testcase( pTarget[j+1].eU==2 );
|
||||
VVA( pTarget[j+1].eU = 5 );
|
||||
pTarget[j+1].u.pPatch = pNew;
|
||||
pTarget[j+1].jnFlags |= JNODE_PATCH;
|
||||
}
|
||||
@@ -1676,14 +1618,9 @@ static JsonNode *jsonMergePatch(
|
||||
if( pParse->oom ) return 0;
|
||||
jsonRemoveAllNulls(pPatch);
|
||||
pTarget = &pParse->aNode[iTarget];
|
||||
assert( pParse->aNode[iRoot].eU==0 || pParse->aNode[iRoot].eU==2 );
|
||||
testcase( pParse->aNode[iRoot].eU==2 );
|
||||
pParse->aNode[iRoot].jnFlags |= JNODE_APPEND;
|
||||
VVA( pParse->aNode[iRoot].eU = 2 );
|
||||
pParse->aNode[iRoot].u.iAppend = iStart - iRoot;
|
||||
iRoot = iStart;
|
||||
assert( pParse->aNode[iPatch].eU==0 );
|
||||
VVA( pParse->aNode[iPatch].eU = 5 );
|
||||
pParse->aNode[iPatch].jnFlags |= JNODE_PATCH;
|
||||
pParse->aNode[iPatch].u.pPatch = &pPatch[i+1];
|
||||
}
|
||||
@@ -1705,7 +1642,7 @@ static void jsonPatchFunc(
|
||||
JsonParse y; /* The patch */
|
||||
JsonNode *pResult; /* The result of the merge */
|
||||
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAM(argc);
|
||||
if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
|
||||
if( jsonParse(&y, ctx, (const char*)sqlite3_value_text(argv[1])) ){
|
||||
jsonParseReset(&x);
|
||||
@@ -1825,15 +1762,11 @@ static void jsonReplaceFunc(
|
||||
pNode = jsonLookup(&x, zPath, 0, ctx);
|
||||
if( x.nErr ) goto replace_err;
|
||||
if( pNode ){
|
||||
assert( pNode->eU==0 || pNode->eU==1 || pNode->eU==4 );
|
||||
testcase( pNode->eU!=0 && pNode->eU!=1 );
|
||||
pNode->jnFlags |= (u8)JNODE_REPLACE;
|
||||
VVA( pNode->eU = 4 );
|
||||
pNode->u.iReplace = i + 1;
|
||||
}
|
||||
}
|
||||
if( x.aNode[0].jnFlags & JNODE_REPLACE ){
|
||||
assert( x.aNode[0].eU==4 );
|
||||
sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
|
||||
}else{
|
||||
jsonReturnJson(x.aNode, ctx, argv);
|
||||
@@ -1842,7 +1775,6 @@ replace_err:
|
||||
jsonParseReset(&x);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** json_set(JSON, PATH, VALUE, ...)
|
||||
**
|
||||
@@ -1865,7 +1797,7 @@ static void jsonSetFunc(
|
||||
const char *zPath;
|
||||
u32 i;
|
||||
int bApnd;
|
||||
int bIsSet = sqlite3_user_data(ctx)!=0;
|
||||
int bIsSet = *(int*)sqlite3_user_data(ctx);
|
||||
|
||||
if( argc<1 ) return;
|
||||
if( (argc&1)==0 ) {
|
||||
@@ -1884,15 +1816,11 @@ static void jsonSetFunc(
|
||||
}else if( x.nErr ){
|
||||
goto jsonSetDone;
|
||||
}else if( pNode && (bApnd || bIsSet) ){
|
||||
testcase( pNode->eU!=0 && pNode->eU!=1 );
|
||||
assert( pNode->eU!=3 && pNode->eU!=5 );
|
||||
VVA( pNode->eU = 4 );
|
||||
pNode->jnFlags |= (u8)JNODE_REPLACE;
|
||||
pNode->u.iReplace = i + 1;
|
||||
}
|
||||
}
|
||||
if( x.aNode[0].jnFlags & JNODE_REPLACE ){
|
||||
assert( x.aNode[0].eU==4 );
|
||||
sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
|
||||
}else{
|
||||
jsonReturnJson(x.aNode, ctx, argv);
|
||||
@@ -1905,8 +1833,8 @@ jsonSetDone:
|
||||
** json_type(JSON)
|
||||
** json_type(JSON, PATH)
|
||||
**
|
||||
** Return the top-level "type" of a JSON string. json_type() raises an
|
||||
** error if either the JSON or PATH inputs are not well-formed.
|
||||
** Return the top-level "type" of a JSON string. Throw an error if
|
||||
** either the JSON or PATH inputs are not well-formed.
|
||||
*/
|
||||
static void jsonTypeFunc(
|
||||
sqlite3_context *ctx,
|
||||
@@ -1942,7 +1870,7 @@ static void jsonValidFunc(
|
||||
sqlite3_value **argv
|
||||
){
|
||||
JsonParse *p; /* The parse */
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAM(argc);
|
||||
p = jsonParseCached(ctx, argv, 0);
|
||||
sqlite3_result_int(ctx, p!=0);
|
||||
}
|
||||
@@ -1962,7 +1890,7 @@ static void jsonArrayStep(
|
||||
sqlite3_value **argv
|
||||
){
|
||||
JsonString *pStr;
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAM(argc);
|
||||
pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr));
|
||||
if( pStr ){
|
||||
if( pStr->zBuf==0 ){
|
||||
@@ -2022,8 +1950,8 @@ static void jsonGroupInverse(
|
||||
char *z;
|
||||
char c;
|
||||
JsonString *pStr;
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAMETER(argv);
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAM(argv);
|
||||
pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
|
||||
#ifdef NEVER
|
||||
/* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
|
||||
@@ -2067,7 +1995,7 @@ static void jsonObjectStep(
|
||||
JsonString *pStr;
|
||||
const char *z;
|
||||
u32 n;
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAM(argc);
|
||||
pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr));
|
||||
if( pStr ){
|
||||
if( pStr->zBuf==0 ){
|
||||
@@ -2158,10 +2086,10 @@ static int jsonEachConnect(
|
||||
#define JEACH_JSON 8
|
||||
#define JEACH_ROOT 9
|
||||
|
||||
UNUSED_PARAMETER(pzErr);
|
||||
UNUSED_PARAMETER(argv);
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAMETER(pAux);
|
||||
UNUSED_PARAM(pzErr);
|
||||
UNUSED_PARAM(argv);
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAM(pAux);
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
"CREATE TABLE x(key,value,type,atom,id,parent,fullkey,path,"
|
||||
"json HIDDEN,root HIDDEN)");
|
||||
@@ -2184,7 +2112,7 @@ static int jsonEachDisconnect(sqlite3_vtab *pVtab){
|
||||
static int jsonEachOpenEach(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
|
||||
JsonEachCursor *pCur;
|
||||
|
||||
UNUSED_PARAMETER(p);
|
||||
UNUSED_PARAM(p);
|
||||
pCur = sqlite3_malloc( sizeof(*pCur) );
|
||||
if( pCur==0 ) return SQLITE_NOMEM;
|
||||
memset(pCur, 0, sizeof(*pCur));
|
||||
@@ -2243,9 +2171,6 @@ static int jsonEachNext(sqlite3_vtab_cursor *cur){
|
||||
JsonNode *pUp = &p->sParse.aNode[iUp];
|
||||
p->eType = pUp->eType;
|
||||
if( pUp->eType==JSON_ARRAY ){
|
||||
assert( pUp->eU==0 || pUp->eU==3 );
|
||||
testcase( pUp->eU==3 );
|
||||
VVA( pUp->eU = 3 );
|
||||
if( iUp==p->i-1 ){
|
||||
pUp->u.iKey = 0;
|
||||
}else{
|
||||
@@ -2292,15 +2217,12 @@ static void jsonEachComputePath(
|
||||
pNode = &p->sParse.aNode[i];
|
||||
pUp = &p->sParse.aNode[iUp];
|
||||
if( pUp->eType==JSON_ARRAY ){
|
||||
assert( pUp->eU==3 || (pUp->eU==0 && pUp->u.iKey==0) );
|
||||
testcase( pUp->eU==0 );
|
||||
jsonPrintf(30, pStr, "[%d]", pUp->u.iKey);
|
||||
}else{
|
||||
assert( pUp->eType==JSON_OBJECT );
|
||||
if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
|
||||
assert( pNode->eType==JSON_STRING );
|
||||
assert( pNode->jnFlags & JNODE_LABEL );
|
||||
assert( pNode->eU==1 );
|
||||
jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
|
||||
}
|
||||
}
|
||||
@@ -2322,7 +2244,6 @@ static int jsonEachColumn(
|
||||
u32 iKey;
|
||||
if( p->bRecursive ){
|
||||
if( p->iRowid==0 ) break;
|
||||
assert( p->sParse.aNode[p->sParse.aUp[p->i]].eU==3 );
|
||||
iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey;
|
||||
}else{
|
||||
iKey = p->iRowid;
|
||||
@@ -2372,7 +2293,6 @@ static int jsonEachColumn(
|
||||
if( p->eType==JSON_ARRAY ){
|
||||
jsonPrintf(30, &x, "[%d]", p->iRowid);
|
||||
}else if( p->eType==JSON_OBJECT ){
|
||||
assert( pThis->eU==1 );
|
||||
jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
|
||||
}
|
||||
}
|
||||
@@ -2431,7 +2351,7 @@ static int jsonEachBestIndex(
|
||||
/* This implementation assumes that JSON and ROOT are the last two
|
||||
** columns in the table */
|
||||
assert( JEACH_ROOT == JEACH_JSON+1 );
|
||||
UNUSED_PARAMETER(tab);
|
||||
UNUSED_PARAM(tab);
|
||||
aIdx[0] = aIdx[1] = -1;
|
||||
pConstraint = pIdxInfo->aConstraint;
|
||||
for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
|
||||
@@ -2440,7 +2360,6 @@ static int jsonEachBestIndex(
|
||||
if( pConstraint->iColumn < JEACH_JSON ) continue;
|
||||
iCol = pConstraint->iColumn - JEACH_JSON;
|
||||
assert( iCol==0 || iCol==1 );
|
||||
testcase( iCol==0 );
|
||||
iMask = 1 << iCol;
|
||||
if( pConstraint->usable==0 ){
|
||||
unusableMask |= iMask;
|
||||
@@ -2487,8 +2406,8 @@ static int jsonEachFilter(
|
||||
const char *zRoot = 0;
|
||||
sqlite3_int64 n;
|
||||
|
||||
UNUSED_PARAMETER(idxStr);
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAM(idxStr);
|
||||
UNUSED_PARAM(argc);
|
||||
jsonEachCursorReset(p);
|
||||
if( idxNum==0 ) return SQLITE_OK;
|
||||
z = (const char*)sqlite3_value_text(argv[0]);
|
||||
@@ -2538,8 +2457,6 @@ static int jsonEachFilter(
|
||||
p->iBegin = p->i = (int)(pNode - p->sParse.aNode);
|
||||
p->eType = pNode->eType;
|
||||
if( p->eType>=JSON_ARRAY ){
|
||||
assert( pNode->eU==0 );
|
||||
VVA( pNode->eU = 3 );
|
||||
pNode->u.iKey = 0;
|
||||
p->iEnd = p->i + pNode->n + 1;
|
||||
if( p->bRecursive ){
|
||||
@@ -2613,63 +2530,103 @@ static sqlite3_module jsonTreeModule = {
|
||||
0 /* xShadowName */
|
||||
};
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
#endif /* !defined(SQLITE_OMIT_JSON) */
|
||||
|
||||
/*
|
||||
** Register JSON functions.
|
||||
*/
|
||||
void sqlite3RegisterJsonFunctions(void){
|
||||
#ifndef SQLITE_OMIT_JSON
|
||||
static FuncDef aJsonFunc[] = {
|
||||
JFUNCTION(json, 1, 0, jsonRemoveFunc),
|
||||
JFUNCTION(json_array, -1, 0, jsonArrayFunc),
|
||||
JFUNCTION(json_array_length, 1, 0, jsonArrayLengthFunc),
|
||||
JFUNCTION(json_array_length, 2, 0, jsonArrayLengthFunc),
|
||||
JFUNCTION(json_extract, -1, 0, jsonExtractFunc),
|
||||
JFUNCTION(->, 2, JSON_JSON, jsonExtractFunc),
|
||||
JFUNCTION(->>, 2, JSON_SQL, jsonExtractFunc),
|
||||
JFUNCTION(json_insert, -1, 0, jsonSetFunc),
|
||||
JFUNCTION(json_object, -1, 0, jsonObjectFunc),
|
||||
JFUNCTION(json_patch, 2, 0, jsonPatchFunc),
|
||||
JFUNCTION(json_quote, 1, 0, jsonQuoteFunc),
|
||||
JFUNCTION(json_remove, -1, 0, jsonRemoveFunc),
|
||||
JFUNCTION(json_replace, -1, 0, jsonReplaceFunc),
|
||||
JFUNCTION(json_set, -1, JSON_ISSET, jsonSetFunc),
|
||||
JFUNCTION(json_type, 1, 0, jsonTypeFunc),
|
||||
JFUNCTION(json_type, 2, 0, jsonTypeFunc),
|
||||
JFUNCTION(json_valid, 1, 0, jsonValidFunc),
|
||||
#if SQLITE_DEBUG
|
||||
JFUNCTION(json_parse, 1, 0, jsonParseFunc),
|
||||
JFUNCTION(json_test1, 1, 0, jsonTest1Func),
|
||||
#endif
|
||||
WAGGREGATE(json_group_array, 1, 0, 0,
|
||||
jsonArrayStep, jsonArrayFinal, jsonArrayValue, jsonGroupInverse,
|
||||
SQLITE_SUBTYPE|SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS),
|
||||
WAGGREGATE(json_group_object, 2, 0, 0,
|
||||
jsonObjectStep, jsonObjectFinal, jsonObjectValue, jsonGroupInverse,
|
||||
SQLITE_SUBTYPE|SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS)
|
||||
};
|
||||
sqlite3InsertBuiltinFuncs(aJsonFunc, ArraySize(aJsonFunc));
|
||||
#endif
|
||||
}
|
||||
/****************************************************************************
|
||||
** The following routines are the only publically visible identifiers in this
|
||||
** file. Call the following routines in order to register the various SQL
|
||||
** functions and the virtual table implemented by this file.
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON)
|
||||
/*
|
||||
** Register the JSON table-valued functions
|
||||
*/
|
||||
int sqlite3JsonTableFunctions(sqlite3 *db){
|
||||
int sqlite3Json1Init(sqlite3 *db){
|
||||
int rc = SQLITE_OK;
|
||||
unsigned int i;
|
||||
static const struct {
|
||||
const char *zName;
|
||||
sqlite3_module *pModule;
|
||||
const char *zName;
|
||||
int nArg;
|
||||
int flag;
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
|
||||
} aFunc[] = {
|
||||
{ "json", 1, 0, jsonRemoveFunc },
|
||||
{ "json_array", -1, 0, jsonArrayFunc },
|
||||
{ "json_array_length", 1, 0, jsonArrayLengthFunc },
|
||||
{ "json_array_length", 2, 0, jsonArrayLengthFunc },
|
||||
{ "json_extract", -1, 0, jsonExtractFunc },
|
||||
{ "json_insert", -1, 0, jsonSetFunc },
|
||||
{ "json_object", -1, 0, jsonObjectFunc },
|
||||
{ "json_patch", 2, 0, jsonPatchFunc },
|
||||
{ "json_quote", 1, 0, jsonQuoteFunc },
|
||||
{ "json_remove", -1, 0, jsonRemoveFunc },
|
||||
{ "json_replace", -1, 0, jsonReplaceFunc },
|
||||
{ "json_set", -1, 1, jsonSetFunc },
|
||||
{ "json_type", 1, 0, jsonTypeFunc },
|
||||
{ "json_type", 2, 0, jsonTypeFunc },
|
||||
{ "json_valid", 1, 0, jsonValidFunc },
|
||||
|
||||
#if SQLITE_DEBUG
|
||||
/* DEBUG and TESTING functions */
|
||||
{ "json_parse", 1, 0, jsonParseFunc },
|
||||
{ "json_test1", 1, 0, jsonTest1Func },
|
||||
#endif
|
||||
};
|
||||
static const struct {
|
||||
const char *zName;
|
||||
int nArg;
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**);
|
||||
void (*xFinal)(sqlite3_context*);
|
||||
void (*xValue)(sqlite3_context*);
|
||||
} aAgg[] = {
|
||||
{ "json_group_array", 1,
|
||||
jsonArrayStep, jsonArrayFinal, jsonArrayValue },
|
||||
{ "json_group_object", 2,
|
||||
jsonObjectStep, jsonObjectFinal, jsonObjectValue },
|
||||
};
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
static const struct {
|
||||
const char *zName;
|
||||
sqlite3_module *pModule;
|
||||
} aMod[] = {
|
||||
{ "json_each", &jsonEachModule },
|
||||
{ "json_tree", &jsonTreeModule },
|
||||
};
|
||||
unsigned int i;
|
||||
#endif
|
||||
static const int enc =
|
||||
SQLITE_UTF8 |
|
||||
SQLITE_DETERMINISTIC |
|
||||
SQLITE_INNOCUOUS;
|
||||
for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
|
||||
rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg, enc,
|
||||
(void*)&aFunc[i].flag,
|
||||
aFunc[i].xFunc, 0, 0);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
|
||||
rc = sqlite3_create_window_function(db, aAgg[i].zName, aAgg[i].nArg,
|
||||
SQLITE_SUBTYPE | enc, 0,
|
||||
aAgg[i].xStep, aAgg[i].xFinal,
|
||||
aAgg[i].xValue, jsonGroupInverse, 0);
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
|
||||
rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
|
||||
}
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON) */
|
||||
|
||||
|
||||
#ifndef SQLITE_CORE
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_json_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg; /* Unused parameter */
|
||||
return sqlite3Json1Init(db);
|
||||
}
|
||||
#endif
|
||||
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1) */
|
||||
@@ -1,461 +0,0 @@
|
||||
/*
|
||||
** 2022-01-19
|
||||
**
|
||||
** 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 a virtual-table that returns information about
|
||||
** how the query planner called the xBestIndex method. This virtual table
|
||||
** is intended for testing and debugging only.
|
||||
**
|
||||
** The schema of the virtual table is this:
|
||||
**
|
||||
** CREATE TABLE qpvtab(
|
||||
** vn TEXT, -- Name of an sqlite3_index_info field
|
||||
** ix INTEGER, -- Array index or value
|
||||
** cn TEXT, -- Column name
|
||||
** op INTEGER, -- operator
|
||||
** ux BOOLEAN, -- "usable" field
|
||||
** rhs TEXT, -- sqlite3_vtab_rhs_value()
|
||||
**
|
||||
** a, b, c, d, e, -- Extra columns to attach constraints to
|
||||
**
|
||||
** flags INTEGER HIDDEN -- control flags
|
||||
** );
|
||||
**
|
||||
** The virtual table returns a description of the sqlite3_index_info object
|
||||
** that was provided to the (successful) xBestIndex method. There is one
|
||||
** row in the result table for each field in the sqlite3_index_info object.
|
||||
**
|
||||
** The values of the "a" through "e" columns are one of:
|
||||
**
|
||||
** 1. TEXT - the same as the column name
|
||||
** 2. INTEGER - 1 for "a", 2 for "b", and so forth
|
||||
**
|
||||
** Option 1 is the default behavior. 2 is use if there is a usable
|
||||
** constraint on "flags" with an integer right-hand side that where the
|
||||
** value of the right-hand side has its 0x001 bit set.
|
||||
**
|
||||
** All constraints on columns "a" through "e" are marked as "omit".
|
||||
**
|
||||
** If there is a usable constraint on "flags" that has a RHS value that
|
||||
** is an integer and that integer has its 0x02 bit set, then the
|
||||
** orderByConsumed flag is set.
|
||||
**
|
||||
** FLAGS SUMMARY:
|
||||
**
|
||||
** 0x001 Columns 'a' through 'e' have INT values
|
||||
** 0x002 orderByConsumed is set
|
||||
** 0x004 OFFSET and LIMIT have omit set
|
||||
**
|
||||
** COMPILE:
|
||||
**
|
||||
** gcc -Wall -g -shared -fPIC -I. qpvtab.c -o qqvtab.so
|
||||
**
|
||||
** EXAMPLE USAGE:
|
||||
**
|
||||
** .load ./qpvtab
|
||||
** SELECT rowid, *, flags FROM qpvtab(102)
|
||||
** WHERE a=19
|
||||
** AND b BETWEEN 4.5 and 'hello'
|
||||
** AND c<>x'aabbcc'
|
||||
** ORDER BY d, e DESC;
|
||||
*/
|
||||
#if !defined(SQLITEINT_H)
|
||||
#include "sqlite3ext.h"
|
||||
#endif
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !defined(SQLITE_OMIT_VIRTUALTABLE)
|
||||
|
||||
/* qpvtab_vtab is a subclass of sqlite3_vtab which is
|
||||
** underlying representation of the virtual table
|
||||
*/
|
||||
typedef struct qpvtab_vtab qpvtab_vtab;
|
||||
struct qpvtab_vtab {
|
||||
sqlite3_vtab base; /* Base class - must be first */
|
||||
};
|
||||
|
||||
/* qpvtab_cursor is a subclass of sqlite3_vtab_cursor which will
|
||||
** serve as the underlying representation of a cursor that scans
|
||||
** over rows of the result
|
||||
*/
|
||||
typedef struct qpvtab_cursor qpvtab_cursor;
|
||||
struct qpvtab_cursor {
|
||||
sqlite3_vtab_cursor base; /* Base class - must be first */
|
||||
sqlite3_int64 iRowid; /* The rowid */
|
||||
const char *zData; /* Data to return */
|
||||
int nData; /* Number of bytes of data */
|
||||
int flags; /* Flags value */
|
||||
};
|
||||
|
||||
/*
|
||||
** Names of columns
|
||||
*/
|
||||
static const char *azColname[] = {
|
||||
"vn",
|
||||
"ix",
|
||||
"cn",
|
||||
"op",
|
||||
"ux",
|
||||
"rhs",
|
||||
"a", "b", "c", "d", "e",
|
||||
"flags",
|
||||
""
|
||||
};
|
||||
|
||||
/*
|
||||
** The qpvtabConnect() method is invoked to create a new
|
||||
** qpvtab virtual table.
|
||||
*/
|
||||
static int qpvtabConnect(
|
||||
sqlite3 *db,
|
||||
void *pAux,
|
||||
int argc, const char *const*argv,
|
||||
sqlite3_vtab **ppVtab,
|
||||
char **pzErr
|
||||
){
|
||||
qpvtab_vtab *pNew;
|
||||
int rc;
|
||||
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
"CREATE TABLE x("
|
||||
" vn TEXT,"
|
||||
" ix INT,"
|
||||
" cn TEXT,"
|
||||
" op INT,"
|
||||
" ux BOOLEAN,"
|
||||
" rhs TEXT,"
|
||||
" a, b, c, d, e,"
|
||||
" flags INT HIDDEN)"
|
||||
);
|
||||
#define QPVTAB_VN 0
|
||||
#define QPVTAB_IX 1
|
||||
#define QPVTAB_CN 2
|
||||
#define QPVTAB_OP 3
|
||||
#define QPVTAB_UX 4
|
||||
#define QPVTAB_RHS 5
|
||||
#define QPVTAB_A 6
|
||||
#define QPVTAB_B 7
|
||||
#define QPVTAB_C 8
|
||||
#define QPVTAB_D 9
|
||||
#define QPVTAB_E 10
|
||||
#define QPVTAB_FLAGS 11
|
||||
#define QPVTAB_NONE 12
|
||||
if( rc==SQLITE_OK ){
|
||||
pNew = sqlite3_malloc( sizeof(*pNew) );
|
||||
*ppVtab = (sqlite3_vtab*)pNew;
|
||||
if( pNew==0 ) return SQLITE_NOMEM;
|
||||
memset(pNew, 0, sizeof(*pNew));
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This method is the destructor for qpvtab_vtab objects.
|
||||
*/
|
||||
static int qpvtabDisconnect(sqlite3_vtab *pVtab){
|
||||
qpvtab_vtab *p = (qpvtab_vtab*)pVtab;
|
||||
sqlite3_free(p);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Constructor for a new qpvtab_cursor object.
|
||||
*/
|
||||
static int qpvtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
|
||||
qpvtab_cursor *pCur;
|
||||
pCur = sqlite3_malloc( sizeof(*pCur) );
|
||||
if( pCur==0 ) return SQLITE_NOMEM;
|
||||
memset(pCur, 0, sizeof(*pCur));
|
||||
*ppCursor = &pCur->base;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Destructor for a qpvtab_cursor.
|
||||
*/
|
||||
static int qpvtabClose(sqlite3_vtab_cursor *cur){
|
||||
qpvtab_cursor *pCur = (qpvtab_cursor*)cur;
|
||||
sqlite3_free(pCur);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Advance a qpvtab_cursor to its next row of output.
|
||||
*/
|
||||
static int qpvtabNext(sqlite3_vtab_cursor *cur){
|
||||
qpvtab_cursor *pCur = (qpvtab_cursor*)cur;
|
||||
if( pCur->iRowid<pCur->nData ){
|
||||
const char *z = &pCur->zData[pCur->iRowid];
|
||||
const char *zEnd = strchr(z, '\n');
|
||||
if( zEnd ) zEnd++;
|
||||
pCur->iRowid = (int)(zEnd - pCur->zData);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return values of columns for the row at which the qpvtab_cursor
|
||||
** is currently pointing.
|
||||
*/
|
||||
static int qpvtabColumn(
|
||||
sqlite3_vtab_cursor *cur, /* The cursor */
|
||||
sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
|
||||
int i /* Which column to return */
|
||||
){
|
||||
qpvtab_cursor *pCur = (qpvtab_cursor*)cur;
|
||||
if( i>=QPVTAB_VN && i<=QPVTAB_RHS && pCur->iRowid<pCur->nData ){
|
||||
const char *z = &pCur->zData[pCur->iRowid];
|
||||
const char *zEnd;
|
||||
int j;
|
||||
j = QPVTAB_VN;
|
||||
while(1){
|
||||
zEnd = strchr(z, j==QPVTAB_RHS ? '\n' : ',');
|
||||
if( j==i || zEnd==0 ) break;
|
||||
z = zEnd+1;
|
||||
j++;
|
||||
}
|
||||
if( zEnd==z ){
|
||||
sqlite3_result_null(ctx);
|
||||
}else if( i==QPVTAB_IX || i==QPVTAB_OP || i==QPVTAB_UX ){
|
||||
sqlite3_result_int(ctx, atoi(z));
|
||||
}else{
|
||||
sqlite3_result_text64(ctx, z, zEnd-z, SQLITE_TRANSIENT, SQLITE_UTF8);
|
||||
}
|
||||
}else if( i>=QPVTAB_A && i<=QPVTAB_E ){
|
||||
if( pCur->flags & 0x001 ){
|
||||
sqlite3_result_int(ctx, i-QPVTAB_A+1);
|
||||
}else{
|
||||
char x = 'a'+i-QPVTAB_A;
|
||||
sqlite3_result_text64(ctx, &x, 1, SQLITE_TRANSIENT, SQLITE_UTF8);
|
||||
}
|
||||
}else if( i==QPVTAB_FLAGS ){
|
||||
sqlite3_result_int(ctx, pCur->flags);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the rowid for the current row. In this implementation, the
|
||||
** rowid is the same as the output value.
|
||||
*/
|
||||
static int qpvtabRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
|
||||
qpvtab_cursor *pCur = (qpvtab_cursor*)cur;
|
||||
*pRowid = pCur->iRowid;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return TRUE if the cursor has been moved off of the last
|
||||
** row of output.
|
||||
*/
|
||||
static int qpvtabEof(sqlite3_vtab_cursor *cur){
|
||||
qpvtab_cursor *pCur = (qpvtab_cursor*)cur;
|
||||
return pCur->iRowid>=pCur->nData;
|
||||
}
|
||||
|
||||
/*
|
||||
** This method is called to "rewind" the qpvtab_cursor object back
|
||||
** to the first row of output. This method is always called at least
|
||||
** once prior to any call to qpvtabColumn() or qpvtabRowid() or
|
||||
** qpvtabEof().
|
||||
*/
|
||||
static int qpvtabFilter(
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
qpvtab_cursor *pCur = (qpvtab_cursor *)pVtabCursor;
|
||||
pCur->iRowid = 0;
|
||||
pCur->zData = idxStr;
|
||||
pCur->nData = (int)strlen(idxStr);
|
||||
pCur->flags = idxNum;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Append the text of a value to pStr
|
||||
*/
|
||||
static void qpvtabStrAppendValue(
|
||||
sqlite3_str *pStr,
|
||||
sqlite3_value *pVal
|
||||
){
|
||||
switch( sqlite3_value_type(pVal) ){
|
||||
case SQLITE_NULL:
|
||||
sqlite3_str_appendf(pStr, "NULL");
|
||||
break;
|
||||
case SQLITE_INTEGER:
|
||||
sqlite3_str_appendf(pStr, "%lld", sqlite3_value_int64(pVal));
|
||||
break;
|
||||
case SQLITE_FLOAT:
|
||||
sqlite3_str_appendf(pStr, "%!f", sqlite3_value_double(pVal));
|
||||
break;
|
||||
case SQLITE_TEXT: {
|
||||
int i;
|
||||
const char *a = (const char*)sqlite3_value_text(pVal);
|
||||
int n = sqlite3_value_bytes(pVal);
|
||||
sqlite3_str_append(pStr, "'", 1);
|
||||
for(i=0; i<n; i++){
|
||||
char c = a[i];
|
||||
if( c=='\n' ) c = ' ';
|
||||
sqlite3_str_append(pStr, &c, 1);
|
||||
if( c=='\'' ) sqlite3_str_append(pStr, &c, 1);
|
||||
}
|
||||
sqlite3_str_append(pStr, "'", 1);
|
||||
break;
|
||||
}
|
||||
case SQLITE_BLOB: {
|
||||
int i;
|
||||
const unsigned char *a = sqlite3_value_blob(pVal);
|
||||
int n = sqlite3_value_bytes(pVal);
|
||||
sqlite3_str_append(pStr, "x'", 2);
|
||||
for(i=0; i<n; i++){
|
||||
sqlite3_str_appendf(pStr, "%02x", a[i]);
|
||||
}
|
||||
sqlite3_str_append(pStr, "'", 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** SQLite will invoke this method one or more times while planning a query
|
||||
** that uses the virtual table. This routine needs to create
|
||||
** a query plan for each invocation and compute an estimated cost for that
|
||||
** plan.
|
||||
*/
|
||||
static int qpvtabBestIndex(
|
||||
sqlite3_vtab *tab,
|
||||
sqlite3_index_info *pIdxInfo
|
||||
){
|
||||
sqlite3_str *pStr = sqlite3_str_new(0);
|
||||
int i, k = 0;
|
||||
int rc;
|
||||
sqlite3_str_appendf(pStr, "nConstraint,%d,,,,\n", pIdxInfo->nConstraint);
|
||||
for(i=0; i<pIdxInfo->nConstraint; i++){
|
||||
sqlite3_value *pVal;
|
||||
int iCol = pIdxInfo->aConstraint[i].iColumn;
|
||||
int op = pIdxInfo->aConstraint[i].op;
|
||||
if( iCol==QPVTAB_FLAGS && pIdxInfo->aConstraint[i].usable ){
|
||||
pVal = 0;
|
||||
rc = sqlite3_vtab_rhs_value(pIdxInfo, i, &pVal);
|
||||
assert( rc==SQLITE_OK || pVal==0 );
|
||||
if( pVal ){
|
||||
pIdxInfo->idxNum = sqlite3_value_int(pVal);
|
||||
if( pIdxInfo->idxNum & 0x002 ) pIdxInfo->orderByConsumed = 1;
|
||||
}
|
||||
}
|
||||
if( op==SQLITE_INDEX_CONSTRAINT_LIMIT
|
||||
|| op==SQLITE_INDEX_CONSTRAINT_OFFSET
|
||||
){
|
||||
iCol = QPVTAB_NONE;
|
||||
}
|
||||
sqlite3_str_appendf(pStr,"aConstraint,%d,%s,%d,%d,",
|
||||
i,
|
||||
azColname[iCol],
|
||||
op,
|
||||
pIdxInfo->aConstraint[i].usable);
|
||||
pVal = 0;
|
||||
rc = sqlite3_vtab_rhs_value(pIdxInfo, i, &pVal);
|
||||
assert( rc==SQLITE_OK || pVal==0 );
|
||||
if( pVal ){
|
||||
qpvtabStrAppendValue(pStr, pVal);
|
||||
}
|
||||
sqlite3_str_append(pStr, "\n", 1);
|
||||
}
|
||||
for(i=0; i<pIdxInfo->nConstraint; i++){
|
||||
int iCol = pIdxInfo->aConstraint[i].iColumn;
|
||||
int op = pIdxInfo->aConstraint[i].op;
|
||||
if( op==SQLITE_INDEX_CONSTRAINT_LIMIT
|
||||
|| op==SQLITE_INDEX_CONSTRAINT_OFFSET
|
||||
){
|
||||
iCol = QPVTAB_NONE;
|
||||
}
|
||||
if( iCol>=QPVTAB_A && pIdxInfo->aConstraint[i].usable ){
|
||||
pIdxInfo->aConstraintUsage[i].argvIndex = ++k;
|
||||
if( iCol<=QPVTAB_FLAGS || (pIdxInfo->idxNum & 0x004)!=0 ){
|
||||
pIdxInfo->aConstraintUsage[i].omit = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_str_appendf(pStr, "nOrderBy,%d,,,,\n", pIdxInfo->nOrderBy);
|
||||
for(i=0; i<pIdxInfo->nOrderBy; i++){
|
||||
int iCol = pIdxInfo->aOrderBy[i].iColumn;
|
||||
sqlite3_str_appendf(pStr, "aOrderBy,%d,%s,%d,,\n",i,
|
||||
iCol>=0 ? azColname[iCol] : "rowid",
|
||||
pIdxInfo->aOrderBy[i].desc
|
||||
);
|
||||
}
|
||||
sqlite3_str_appendf(pStr, "sqlite3_vtab_distinct,%d,,,,\n",
|
||||
sqlite3_vtab_distinct(pIdxInfo));
|
||||
sqlite3_str_appendf(pStr, "idxFlags,%d,,,,\n", pIdxInfo->idxFlags);
|
||||
sqlite3_str_appendf(pStr, "colUsed,%d,,,,\n", (int)pIdxInfo->colUsed);
|
||||
pIdxInfo->estimatedCost = (double)10;
|
||||
pIdxInfo->estimatedRows = 10;
|
||||
sqlite3_str_appendf(pStr, "idxNum,%d,,,,\n", pIdxInfo->idxNum);
|
||||
sqlite3_str_appendf(pStr, "orderByConsumed,%d,,,,\n",
|
||||
pIdxInfo->orderByConsumed);
|
||||
pIdxInfo->idxStr = sqlite3_str_finish(pStr);
|
||||
pIdxInfo->needToFreeIdxStr = 1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This following structure defines all the methods for the
|
||||
** virtual table.
|
||||
*/
|
||||
static sqlite3_module qpvtabModule = {
|
||||
/* iVersion */ 0,
|
||||
/* xCreate */ 0,
|
||||
/* xConnect */ qpvtabConnect,
|
||||
/* xBestIndex */ qpvtabBestIndex,
|
||||
/* xDisconnect */ qpvtabDisconnect,
|
||||
/* xDestroy */ 0,
|
||||
/* xOpen */ qpvtabOpen,
|
||||
/* xClose */ qpvtabClose,
|
||||
/* xFilter */ qpvtabFilter,
|
||||
/* xNext */ qpvtabNext,
|
||||
/* xEof */ qpvtabEof,
|
||||
/* xColumn */ qpvtabColumn,
|
||||
/* xRowid */ qpvtabRowid,
|
||||
/* xUpdate */ 0,
|
||||
/* xBegin */ 0,
|
||||
/* xSync */ 0,
|
||||
/* xCommit */ 0,
|
||||
/* xRollback */ 0,
|
||||
/* xFindMethod */ 0,
|
||||
/* xRename */ 0,
|
||||
/* xSavepoint */ 0,
|
||||
/* xRelease */ 0,
|
||||
/* xRollbackTo */ 0,
|
||||
/* xShadowName */ 0
|
||||
};
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_qpvtab_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
rc = sqlite3_create_module(db, "qpvtab", &qpvtabModule, 0);
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
+6
-8
@@ -299,9 +299,9 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
}
|
||||
case RE_OP_CC_EXC: {
|
||||
if( c==0 ) break;
|
||||
/* fall-through */ goto re_op_cc_inc;
|
||||
/* fall-through */
|
||||
}
|
||||
case RE_OP_CC_INC: re_op_cc_inc: {
|
||||
case RE_OP_CC_INC: {
|
||||
int j = 1;
|
||||
int n = pRe->aArg[x];
|
||||
int hit = 0;
|
||||
@@ -759,15 +759,13 @@ int sqlite3_regexp_init(
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg; /* Unused */
|
||||
rc = sqlite3_create_function(db, "regexp", 2,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
||||
0, re_sql_func, 0, 0);
|
||||
rc = sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8|SQLITE_INNOCUOUS,
|
||||
0, re_sql_func, 0, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
/* The regexpi(PATTERN,STRING) function is a case-insensitive version
|
||||
** of regexp(PATTERN,STRING). */
|
||||
rc = sqlite3_create_function(db, "regexpi", 2,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
||||
(void*)db, re_sql_func, 0, 0);
|
||||
rc = sqlite3_create_function(db, "regexpi", 2, SQLITE_UTF8|SQLITE_INNOCUOUS,
|
||||
(void*)db, re_sql_func, 0, 0);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
+2
-2
@@ -386,7 +386,7 @@ static int seriesBestIndex(
|
||||
** the preferred case */
|
||||
pIdxInfo->estimatedCost = (double)(2 - ((idxNum&4)!=0));
|
||||
pIdxInfo->estimatedRows = 1000;
|
||||
if( pIdxInfo->nOrderBy>=1 && pIdxInfo->aOrderBy[0].iColumn==0 ){
|
||||
if( pIdxInfo->nOrderBy==1 ){
|
||||
if( pIdxInfo->aOrderBy[0].desc ){
|
||||
idxNum |= 8;
|
||||
}else{
|
||||
@@ -448,7 +448,7 @@ int sqlite3_series_init(
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
if( sqlite3_libversion_number()<3008012 && pzErrMsg!=0 ){
|
||||
if( sqlite3_libversion_number()<3008012 ){
|
||||
*pzErrMsg = sqlite3_mprintf(
|
||||
"generate_series() requires SQLite 3.8.12 or later");
|
||||
return SQLITE_ERROR;
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ struct SHA1Context {
|
||||
/*
|
||||
* Hash a single 512-bit block. This is the core of the algorithm.
|
||||
*/
|
||||
static void SHA1Transform(unsigned int state[5], const unsigned char buffer[64]){
|
||||
void SHA1Transform(unsigned int state[5], const unsigned char buffer[64]){
|
||||
unsigned int qq[5]; /* a, b, c, d, e; */
|
||||
static int one = 1;
|
||||
unsigned int block[16];
|
||||
|
||||
+1
-2
@@ -19,7 +19,7 @@
|
||||
** The sha3(X) function computes the SHA3 hash of the input X, or NULL if
|
||||
** X is NULL.
|
||||
**
|
||||
** The sha3_query(Y) function evaluates all queries in the SQL statements of Y
|
||||
** The sha3_query(Y) function evalutes all queries in the SQL statements of Y
|
||||
** and returns a hash of their results.
|
||||
**
|
||||
** The SIZE argument is optional. If omitted, the SHA3-256 hash algorithm
|
||||
@@ -436,7 +436,6 @@ static void SHA3Update(
|
||||
unsigned int nData
|
||||
){
|
||||
unsigned int i = 0;
|
||||
if( aData==0 ) return;
|
||||
#if SHA3_BYTEORDER==1234
|
||||
if( (p->nLoaded % 8)==0 && ((aData - (const unsigned char*)0)&7)==0 ){
|
||||
for(; i+7<nData; i+=8){
|
||||
|
||||
+4
-12
@@ -57,9 +57,6 @@ typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
|
||||
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
||||
|
||||
#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
|
||||
# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1
|
||||
#endif
|
||||
#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS)
|
||||
# define ALWAYS(X) (1)
|
||||
# define NEVER(X) (0)
|
||||
#elif !defined(NDEBUG)
|
||||
@@ -564,7 +561,6 @@ static u16 zipfileGetU16(const u8 *aBuf){
|
||||
** Read and return a 32-bit little-endian unsigned integer from buffer aBuf.
|
||||
*/
|
||||
static u32 zipfileGetU32(const u8 *aBuf){
|
||||
if( aBuf==0 ) return 0;
|
||||
return ((u32)(aBuf[3]) << 24)
|
||||
+ ((u32)(aBuf[2]) << 16)
|
||||
+ ((u32)(aBuf[1]) << 8)
|
||||
@@ -867,7 +863,7 @@ static int zipfileGetEntry(
|
||||
aRead = (u8*)&aBlob[pNew->cds.iOffset];
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ) rc = zipfileReadLFH(aRead, &lfh);
|
||||
rc = zipfileReadLFH(aRead, &lfh);
|
||||
if( rc==SQLITE_OK ){
|
||||
pNew->iDataOff = pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ;
|
||||
pNew->iDataOff += lfh.nFile + lfh.nExtra;
|
||||
@@ -1143,13 +1139,13 @@ static int zipfileReadEOCD(
|
||||
int nRead; /* Bytes to read from file */
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
memset(pEOCD, 0, sizeof(ZipfileEOCD));
|
||||
if( aBlob==0 ){
|
||||
i64 iOff; /* Offset to read from */
|
||||
i64 szFile; /* Total size of file in bytes */
|
||||
fseek(pFile, 0, SEEK_END);
|
||||
szFile = (i64)ftell(pFile);
|
||||
if( szFile==0 ){
|
||||
memset(pEOCD, 0, sizeof(ZipfileEOCD));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
nRead = (int)(MIN(szFile, ZIPFILE_BUFFER_SIZE));
|
||||
@@ -1938,7 +1934,7 @@ static int zipfileBufferGrow(ZipfileBuffer *pBuf, int nByte){
|
||||
** SELECT zipfile(name,mode,mtime,data) ...
|
||||
** SELECT zipfile(name,mode,mtime,data,method) ...
|
||||
*/
|
||||
static void zipfileStep(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal){
|
||||
void zipfileStep(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal){
|
||||
ZipfileCtx *p; /* Aggregate function context */
|
||||
ZipfileEntry e; /* New entry to add to zip archive */
|
||||
|
||||
@@ -2113,7 +2109,7 @@ static void zipfileStep(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal){
|
||||
/*
|
||||
** xFinalize() callback for zipfile aggregate function.
|
||||
*/
|
||||
static void zipfileFinal(sqlite3_context *pCtx){
|
||||
void zipfileFinal(sqlite3_context *pCtx){
|
||||
ZipfileCtx *p;
|
||||
ZipfileEOCD eocd;
|
||||
sqlite3_int64 nZip;
|
||||
@@ -2170,10 +2166,6 @@ static int zipfileRegister(sqlite3 *db){
|
||||
zipfileRollback, /* xRollback */
|
||||
zipfileFindFunction, /* xFindMethod */
|
||||
0, /* xRename */
|
||||
0, /* xSavepoint */
|
||||
0, /* xRelease */
|
||||
0, /* xRollback */
|
||||
0 /* xShadowName */
|
||||
};
|
||||
|
||||
int rc = sqlite3_create_module(db, "zipfile" , &zipfileModule, 0);
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ do_test 1.1 {
|
||||
#
|
||||
ifcapable fts3 {
|
||||
do_execsql_test 2.0 {
|
||||
create virtual TABLE ft USING fts4(a, b, languageid='langid');
|
||||
CREATE VIRTUAL TABLE ft USING fts4(a, b, languageid='langid');
|
||||
}
|
||||
do_test 2.1 {
|
||||
apply_rbu {
|
||||
|
||||
@@ -1,207 +0,0 @@
|
||||
# 2021 November 06
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] rbu_common.tcl]
|
||||
set ::testprefix rbuexlock
|
||||
|
||||
db close
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_uri 1
|
||||
|
||||
# Create a simple RBU database. That expects to write to a table:
|
||||
#
|
||||
# CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
|
||||
#
|
||||
proc create_rbu {filename} {
|
||||
forcedelete $filename
|
||||
sqlite3 rbu1 $filename
|
||||
rbu1 eval {
|
||||
CREATE TABLE data_t1(a, b, c, rbu_control);
|
||||
INSERT INTO data_t1 VALUES(10, random(), random(), 0);
|
||||
INSERT INTO data_t1 VALUES(20, random(), random(), 0);
|
||||
INSERT INTO data_t1 VALUES(30, random(), random(), 0);
|
||||
INSERT INTO data_t1 VALUES(40, random(), random(), 0);
|
||||
INSERT INTO data_t1 VALUES(50, random(), random(), 0);
|
||||
INSERT INTO data_t1 VALUES(60, random(), random(), 0);
|
||||
INSERT INTO data_t1 VALUES(70, random(), random(), 0);
|
||||
INSERT INTO data_t1 VALUES(80, random(), random(), 0);
|
||||
}
|
||||
rbu1 close
|
||||
return $filename
|
||||
}
|
||||
|
||||
reset_db
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b INT, c INT);
|
||||
CREATE INDEX t1b ON t1(b);
|
||||
CREATE INDEX t1c ON t1(c);
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
}
|
||||
create_rbu rbu1.db
|
||||
|
||||
do_test 1.1.0 {
|
||||
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=1 rbu1.db
|
||||
rbu step
|
||||
} SQLITE_OK
|
||||
do_catchsql_test 1.1.1 { SELECT * FROM t1 } {0 {1 2 3}}
|
||||
|
||||
do_test 1.2.0 {
|
||||
for {set ii 0} {$ii < 10} {incr ii} {
|
||||
rbu step
|
||||
}
|
||||
rbu step
|
||||
} SQLITE_OK
|
||||
do_catchsql_test 1.2.1 { SELECT * FROM t1 } {0 {1 2 3}}
|
||||
do_test 1.2.2 {
|
||||
db eval {PRAGMA journal_mode}
|
||||
} {delete}
|
||||
|
||||
do_test 1.3.0 {
|
||||
while {[file exists test.db-wal]==0} {
|
||||
rbu step
|
||||
}
|
||||
} {}
|
||||
do_catchsql_test 1.3.1 { SELECT * FROM t1 } {1 {database is locked}}
|
||||
do_test 1.3.2 {
|
||||
db eval {PRAGMA journal_mode}
|
||||
} {delete}
|
||||
|
||||
|
||||
do_test 1.4.0 {
|
||||
rbu step
|
||||
} SQLITE_OK
|
||||
do_catchsql_test 1.4.1 { SELECT * FROM t1 } {1 {database is locked}}
|
||||
do_test 1.4.2 {
|
||||
db eval {PRAGMA journal_mode}
|
||||
} {delete}
|
||||
|
||||
|
||||
rbu close
|
||||
|
||||
do_test 1.5.0 {
|
||||
file exists test.db-wal
|
||||
} {1}
|
||||
do_test 1.5.1 {
|
||||
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=1 rbu1.db
|
||||
file exists test.db-wal
|
||||
} 1
|
||||
do_catchsql_test 1.5.2 { SELECT * FROM t1 } {1 {database is locked}}
|
||||
do_test 1.5.2 {
|
||||
db eval {PRAGMA journal_mode}
|
||||
} {delete}
|
||||
|
||||
|
||||
do_test 1.6.0 {
|
||||
rbu step
|
||||
} SQLITE_OK
|
||||
do_catchsql_test 1.6.1 { SELECT * FROM t1 } {1 {database is locked}}
|
||||
do_test 1.6.2 {
|
||||
db eval {PRAGMA journal_mode}
|
||||
} {delete}
|
||||
|
||||
do_test 1.7.0 {
|
||||
while {[rbu step]=="SQLITE_OK"} {}
|
||||
rbu close
|
||||
} SQLITE_DONE
|
||||
do_catchsql_test 1.7.2 { SELECT count(*) FROM t1 } {0 9}
|
||||
do_test 1.7.2 {
|
||||
db eval {PRAGMA journal_mode}
|
||||
} {delete}
|
||||
|
||||
reset_db
|
||||
do_execsql_test 2.0 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b INT, c INT);
|
||||
CREATE INDEX t1b ON t1(b);
|
||||
CREATE INDEX t1c ON t1(c);
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
}
|
||||
create_rbu rbu1.db
|
||||
|
||||
do_test 2.1.0 {
|
||||
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
|
||||
rbu step
|
||||
} SQLITE_OK
|
||||
do_catchsql_test 2.1.1 { SELECT * FROM t1 } {0 {1 2 3}}
|
||||
|
||||
do_test 2.2.0 {
|
||||
for {set ii 0} {$ii < 10} {incr ii} {
|
||||
rbu step
|
||||
}
|
||||
rbu step
|
||||
} SQLITE_OK
|
||||
do_catchsql_test 2.2.1 { SELECT * FROM t1 } {0 {1 2 3}}
|
||||
|
||||
do_test 2.3.0 {
|
||||
while {[file exists test.db-wal]==0} {
|
||||
rbu step
|
||||
}
|
||||
} {}
|
||||
do_test 2.3.1 {
|
||||
llength [db eval {SELECT * FROM t1}]
|
||||
} {27}
|
||||
do_test 2.3.2 {
|
||||
db eval {PRAGMA journal_mode}
|
||||
} {wal}
|
||||
|
||||
do_test 2.4.0 {
|
||||
rbu step
|
||||
} SQLITE_OK
|
||||
do_test 2.4.1 {
|
||||
llength [db eval {SELECT * FROM t1}]
|
||||
} {27}
|
||||
do_test 2.4.2 {
|
||||
db eval {PRAGMA journal_mode}
|
||||
} {wal}
|
||||
|
||||
rbu close
|
||||
|
||||
do_test 2.5.0 {
|
||||
db eval {PRAGMA journal_mode}
|
||||
} {wal}
|
||||
do_execsql_test 2.5.1 {
|
||||
DELETE FROM t1;
|
||||
} {}
|
||||
|
||||
create_rbu rbu1.db
|
||||
do_test 3.1.0 {
|
||||
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
|
||||
rbu step
|
||||
} SQLITE_ERROR
|
||||
|
||||
do_test 3.1.1 {
|
||||
set rc [catch {rbu close} msg]
|
||||
lappend rc $msg
|
||||
} {1 {SQLITE_ERROR - cannot update wal mode database}}
|
||||
db eval {PRAGMA journal_mode=DELETE}
|
||||
|
||||
create_rbu rbu1.db
|
||||
do_test 3.2.0 {
|
||||
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
|
||||
rbu step
|
||||
} SQLITE_OK
|
||||
|
||||
do_test 3.3.1 {
|
||||
set rc [catch {rbu close} msg]
|
||||
lappend rc $msg
|
||||
} {0 SQLITE_OK}
|
||||
|
||||
db close
|
||||
create_rbu rbu1.db
|
||||
do_test 3.4.0 {
|
||||
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
|
||||
rbu step
|
||||
} SQLITE_OK
|
||||
rbu close
|
||||
|
||||
|
||||
finish_test
|
||||
@@ -198,11 +198,7 @@ if {$::tcl_platform(platform)=="unix"} {
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test 5.$tn.2 { file exists test.db-vacuum } 1
|
||||
# The result pattern might be 00xxx or 0oxxx depending on which
|
||||
# version of TCL is being used. So make perm2 into a regexp that
|
||||
# will match either
|
||||
regsub {^00} $perm {0.} perm2
|
||||
do_test 5.$tn.3 { file attributes test.db-vacuum -permissions} /$perm2/
|
||||
do_test 5.$tn.3 { file attributes test.db-vacuum -permissions} $perm
|
||||
rbu close
|
||||
}
|
||||
}
|
||||
|
||||
+29
-81
@@ -110,13 +110,6 @@
|
||||
# define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Name of the URI option that causes RBU to take an exclusive lock as
|
||||
** part of the incremental checkpoint operation.
|
||||
*/
|
||||
#define RBU_EXCLUSIVE_CHECKPOINT "rbu_exclusive_checkpoint"
|
||||
|
||||
|
||||
/*
|
||||
** The rbu_state table is used to save the state of a partially applied
|
||||
** update so that it can be resumed later. The table consists of integer
|
||||
@@ -1201,9 +1194,7 @@ static void rbuTableType(
|
||||
assert( p->rc==SQLITE_OK );
|
||||
p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
|
||||
sqlite3_mprintf(
|
||||
"SELECT "
|
||||
" (sql COLLATE nocase BETWEEN 'CREATE VIRTUAL' AND 'CREATE VIRTUAM'),"
|
||||
" rootpage"
|
||||
"SELECT (sql LIKE 'create virtual%%'), rootpage"
|
||||
" FROM sqlite_schema"
|
||||
" WHERE name=%Q", zTab
|
||||
));
|
||||
@@ -1563,7 +1554,7 @@ static char *rbuVacuumTableStart(
|
||||
** the caller has to use an OFFSET clause to extract only the required
|
||||
** rows from the sourct table, just as it does for an RBU update operation.
|
||||
*/
|
||||
static char *rbuVacuumIndexStart(
|
||||
char *rbuVacuumIndexStart(
|
||||
sqlite3rbu *p, /* RBU handle */
|
||||
RbuObjIter *pIter /* RBU iterator object */
|
||||
){
|
||||
@@ -2736,7 +2727,7 @@ static RbuState *rbuLoadState(sqlite3rbu *p){
|
||||
break;
|
||||
|
||||
case RBU_STATE_OALSZ:
|
||||
pRet->iOalSz = sqlite3_column_int64(pStmt, 1);
|
||||
pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
|
||||
break;
|
||||
|
||||
case RBU_STATE_PHASEONESTEP:
|
||||
@@ -2763,19 +2754,13 @@ static RbuState *rbuLoadState(sqlite3rbu *p){
|
||||
/*
|
||||
** Open the database handle and attach the RBU database as "rbu". If an
|
||||
** error occurs, leave an error code and message in the RBU handle.
|
||||
**
|
||||
** If argument dbMain is not NULL, then it is a database handle already
|
||||
** open on the target database. Use this handle instead of opening a new
|
||||
** one.
|
||||
*/
|
||||
static void rbuOpenDatabase(sqlite3rbu *p, sqlite3 *dbMain, int *pbRetry){
|
||||
static void rbuOpenDatabase(sqlite3rbu *p, int *pbRetry){
|
||||
assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
|
||||
assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
|
||||
assert( dbMain==0 || rbuIsVacuum(p)==0 );
|
||||
|
||||
/* Open the RBU database */
|
||||
p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
|
||||
p->dbMain = dbMain;
|
||||
|
||||
if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
|
||||
sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
|
||||
@@ -3141,31 +3126,15 @@ static void rbuCheckpointFrame(sqlite3rbu *p, RbuFrame *pFrame){
|
||||
|
||||
|
||||
/*
|
||||
** Take an EXCLUSIVE lock on the database file. Return SQLITE_OK if
|
||||
** successful, or an SQLite error code otherwise.
|
||||
** Take an EXCLUSIVE lock on the database file.
|
||||
*/
|
||||
static int rbuLockDatabase(sqlite3 *db){
|
||||
int rc = SQLITE_OK;
|
||||
sqlite3_file *fd = 0;
|
||||
sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd);
|
||||
|
||||
if( fd->pMethods ){
|
||||
rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = fd->pMethods->xLock(fd, SQLITE_LOCK_EXCLUSIVE);
|
||||
}
|
||||
static void rbuLockDatabase(sqlite3rbu *p){
|
||||
sqlite3_file *pReal = p->pTargetFd->pReal;
|
||||
assert( p->rc==SQLITE_OK );
|
||||
p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_SHARED);
|
||||
if( p->rc==SQLITE_OK ){
|
||||
p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_EXCLUSIVE);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return true if the database handle passed as the only argument
|
||||
** was opened with the rbu_exclusive_checkpoint=1 URI parameter
|
||||
** specified. Or false otherwise.
|
||||
*/
|
||||
static int rbuExclusiveCheckpoint(sqlite3 *db){
|
||||
const char *zUri = sqlite3_db_filename(db, 0);
|
||||
return sqlite3_uri_boolean(zUri, RBU_EXCLUSIVE_CHECKPOINT, 0);
|
||||
}
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
@@ -3223,24 +3192,18 @@ static void rbuMoveOalFile(sqlite3rbu *p){
|
||||
** In order to ensure that there are no database readers, an EXCLUSIVE
|
||||
** lock is obtained here before the *-oal is moved to *-wal.
|
||||
*/
|
||||
sqlite3 *dbMain = 0;
|
||||
rbuFileSuffix3(zBase, zWal);
|
||||
rbuFileSuffix3(zBase, zOal);
|
||||
|
||||
/* Re-open the databases. */
|
||||
rbuObjIterFinalize(&p->objiter);
|
||||
sqlite3_close(p->dbRbu);
|
||||
sqlite3_close(p->dbMain);
|
||||
p->dbMain = 0;
|
||||
p->dbRbu = 0;
|
||||
|
||||
dbMain = rbuOpenDbhandle(p, p->zTarget, 1);
|
||||
if( dbMain ){
|
||||
assert( p->rc==SQLITE_OK );
|
||||
p->rc = rbuLockDatabase(dbMain);
|
||||
}
|
||||
|
||||
rbuLockDatabase(p);
|
||||
if( p->rc==SQLITE_OK ){
|
||||
rbuFileSuffix3(zBase, zWal);
|
||||
rbuFileSuffix3(zBase, zOal);
|
||||
|
||||
/* Re-open the databases. */
|
||||
rbuObjIterFinalize(&p->objiter);
|
||||
sqlite3_close(p->dbRbu);
|
||||
sqlite3_close(p->dbMain);
|
||||
p->dbMain = 0;
|
||||
p->dbRbu = 0;
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
{
|
||||
LPWSTR zWideOal;
|
||||
@@ -3267,19 +3230,11 @@ static void rbuMoveOalFile(sqlite3rbu *p){
|
||||
#else
|
||||
p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
if( p->rc!=SQLITE_OK
|
||||
|| rbuIsVacuum(p)
|
||||
|| rbuExclusiveCheckpoint(dbMain)==0
|
||||
){
|
||||
sqlite3_close(dbMain);
|
||||
dbMain = 0;
|
||||
}
|
||||
|
||||
if( p->rc==SQLITE_OK ){
|
||||
rbuOpenDatabase(p, dbMain, 0);
|
||||
rbuSetupCheckpoint(p, 0);
|
||||
if( p->rc==SQLITE_OK ){
|
||||
rbuOpenDatabase(p, 0);
|
||||
rbuSetupCheckpoint(p, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4030,9 +3985,9 @@ static sqlite3rbu *openRbuHandle(
|
||||
** If this is the case, it will have been checkpointed and deleted
|
||||
** when the handle was closed and a second attempt to open the
|
||||
** database may succeed. */
|
||||
rbuOpenDatabase(p, 0, &bRetry);
|
||||
rbuOpenDatabase(p, &bRetry);
|
||||
if( bRetry ){
|
||||
rbuOpenDatabase(p, 0, 0);
|
||||
rbuOpenDatabase(p, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4127,14 +4082,6 @@ static sqlite3rbu *openRbuHandle(
|
||||
}else if( p->eStage==RBU_STAGE_MOVE ){
|
||||
/* no-op */
|
||||
}else if( p->eStage==RBU_STAGE_CKPT ){
|
||||
if( !rbuIsVacuum(p) && rbuExclusiveCheckpoint(p->dbMain) ){
|
||||
/* If the rbu_exclusive_checkpoint=1 URI parameter was specified
|
||||
** and an incremental checkpoint is being resumed, attempt an
|
||||
** exclusive lock on the db file. If this fails, so be it. */
|
||||
p->eStage = RBU_STAGE_DONE;
|
||||
rbuLockDatabase(p->dbMain);
|
||||
p->eStage = RBU_STAGE_CKPT;
|
||||
}
|
||||
rbuSetupCheckpoint(p, pState);
|
||||
}else if( p->eStage==RBU_STAGE_DONE ){
|
||||
p->rc = SQLITE_DONE;
|
||||
@@ -4172,6 +4119,7 @@ sqlite3rbu *sqlite3rbu_open(
|
||||
const char *zState
|
||||
){
|
||||
if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); }
|
||||
/* TODO: Check that zTarget and zRbu are non-NULL */
|
||||
return openRbuHandle(zTarget, zRbu, zState);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,19 +44,8 @@ SQLITE_EXTENSION_INIT1
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <assert.h>
|
||||
# if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
|
||||
# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1
|
||||
# endif
|
||||
# if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS)
|
||||
# define ALWAYS(X) (1)
|
||||
# define NEVER(X) (0)
|
||||
# elif !defined(NDEBUG)
|
||||
# define ALWAYS(X) ((X)?1:(assert(0),0))
|
||||
# define NEVER(X) ((X)?(assert(0),1):0)
|
||||
# else
|
||||
# define ALWAYS(X) (X)
|
||||
# define NEVER(X) (X)
|
||||
# endif
|
||||
# define ALWAYS(X) 1
|
||||
# define NEVER(X) 0
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
#define TCLSH_INIT_PROC sqlite3_checker_init_proc
|
||||
#define SQLITE_ENABLE_DBPAGE_VTAB 1
|
||||
#define SQLITE_ENABLE_JSON1 1
|
||||
#undef SQLITE_THREADSAFE
|
||||
#define SQLITE_THREADSAFE 0
|
||||
#undef SQLITE_ENABLE_COLUMN_METADATA
|
||||
|
||||
+10
-10
@@ -26,7 +26,11 @@
|
||||
# define GEODEBUG(X)
|
||||
#endif
|
||||
|
||||
/* Character class routines */
|
||||
#ifndef JSON_NULL /* The following stuff repeats things found in json1 */
|
||||
/*
|
||||
** Versions of isspace(), isalnum() and isdigit() to which it is safe
|
||||
** to pass signed char values.
|
||||
*/
|
||||
#ifdef sqlite3Isdigit
|
||||
/* Use the SQLite core versions if this routine is part of the
|
||||
** SQLite amalgamation */
|
||||
@@ -41,7 +45,6 @@
|
||||
# define safe_isxdigit(x) isxdigit((unsigned char)(x))
|
||||
#endif
|
||||
|
||||
#ifndef JSON_NULL /* The following stuff repeats things found in json1 */
|
||||
/*
|
||||
** Growing our own isspace() routine this way is twice as fast as
|
||||
** the library isspace() function.
|
||||
@@ -64,7 +67,7 @@ static const char geopolyIsSpace[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
#define fast_isspace(x) (geopolyIsSpace[(unsigned char)x])
|
||||
#define safe_isspace(x) (geopolyIsSpace[(unsigned char)x])
|
||||
#endif /* JSON NULL - back to original code */
|
||||
|
||||
/* Compiler and version */
|
||||
@@ -153,7 +156,7 @@ static void geopolySwab32(unsigned char *a){
|
||||
|
||||
/* Skip whitespace. Return the next non-whitespace character. */
|
||||
static char geopolySkipSpace(GeoParse *p){
|
||||
while( fast_isspace(p->z[0]) ) p->z++;
|
||||
while( safe_isspace(p->z[0]) ) p->z++;
|
||||
return p->z[0];
|
||||
}
|
||||
|
||||
@@ -302,14 +305,13 @@ static GeoPoly *geopolyFuncParam(
|
||||
){
|
||||
GeoPoly *p = 0;
|
||||
int nByte;
|
||||
testcase( pCtx==0 );
|
||||
if( sqlite3_value_type(pVal)==SQLITE_BLOB
|
||||
&& (nByte = sqlite3_value_bytes(pVal))>=(4+6*sizeof(GeoCoord))
|
||||
){
|
||||
const unsigned char *a = sqlite3_value_blob(pVal);
|
||||
int nVertex;
|
||||
if( a==0 ){
|
||||
if( pCtx ) sqlite3_result_error_nomem(pCtx);
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
return 0;
|
||||
}
|
||||
nVertex = (a[1]<<16) + (a[2]<<8) + a[3];
|
||||
@@ -1136,11 +1138,11 @@ static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
|
||||
}else{
|
||||
/* Remove a segment */
|
||||
if( pActive==pThisEvent->pSeg ){
|
||||
pActive = ALWAYS(pActive) ? pActive->pNext : 0;
|
||||
pActive = pActive->pNext;
|
||||
}else{
|
||||
for(pSeg=pActive; pSeg; pSeg=pSeg->pNext){
|
||||
if( pSeg->pNext==pThisEvent->pSeg ){
|
||||
pSeg->pNext = ALWAYS(pSeg->pNext) ? pSeg->pNext->pNext : 0;
|
||||
pSeg->pNext = pSeg->pNext->pNext;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1384,7 +1386,6 @@ static int geopolyFilter(
|
||||
RtreeCoord bbox[4];
|
||||
RtreeConstraint *p;
|
||||
assert( argc==1 );
|
||||
assert( argv[0]!=0 );
|
||||
geopolyBBox(0, argv[0], bbox, &rc);
|
||||
if( rc ){
|
||||
goto geopoly_filter_end;
|
||||
@@ -1612,7 +1613,6 @@ static int geopolyUpdate(
|
||||
|| !sqlite3_value_nochange(aData[2]) /* UPDATE _shape */
|
||||
|| oldRowid!=newRowid) /* Rowid change */
|
||||
){
|
||||
assert( aData[2]!=0 );
|
||||
geopolyBBox(0, aData[2], cell.aCoord, &rc);
|
||||
if( rc ){
|
||||
if( rc==SQLITE_ERROR ){
|
||||
|
||||
+59
-91
@@ -64,11 +64,7 @@
|
||||
#endif
|
||||
int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
|
||||
|
||||
/*
|
||||
** If building separately, we will need some setup that is normally
|
||||
** found in sqliteInt.h
|
||||
*/
|
||||
#if !defined(SQLITE_AMALGAMATION)
|
||||
#ifndef SQLITE_AMALGAMATION
|
||||
#include "sqlite3rtree.h"
|
||||
typedef sqlite3_int64 i64;
|
||||
typedef sqlite3_uint64 u64;
|
||||
@@ -81,20 +77,7 @@ typedef unsigned int u32;
|
||||
#if defined(NDEBUG) && defined(SQLITE_DEBUG)
|
||||
# undef NDEBUG
|
||||
#endif
|
||||
#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
|
||||
# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1
|
||||
#endif
|
||||
#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS)
|
||||
# define ALWAYS(X) (1)
|
||||
# define NEVER(X) (0)
|
||||
#elif !defined(NDEBUG)
|
||||
# define ALWAYS(X) ((X)?1:(assert(0),0))
|
||||
# define NEVER(X) ((X)?(assert(0),1):0)
|
||||
#else
|
||||
# define ALWAYS(X) (X)
|
||||
# define NEVER(X) (X)
|
||||
#endif
|
||||
#endif /* !defined(SQLITE_AMALGAMATION) */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -152,9 +135,7 @@ struct Rtree {
|
||||
u8 nBytesPerCell; /* Bytes consumed per cell */
|
||||
u8 inWrTrans; /* True if inside write transaction */
|
||||
u8 nAux; /* # of auxiliary columns in %_rowid */
|
||||
#ifdef SQLITE_ENABLE_GEOPOLY
|
||||
u8 nAuxNotNull; /* Number of initial not-null aux columns */
|
||||
#endif
|
||||
#ifdef SQLITE_DEBUG
|
||||
u8 bCorrupt; /* Shadow table corruption detected */
|
||||
#endif
|
||||
@@ -436,12 +417,7 @@ struct RtreeMatchArg {
|
||||
** it is not, make it a no-op.
|
||||
*/
|
||||
#ifndef SQLITE_AMALGAMATION
|
||||
# if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
|
||||
unsigned int sqlite3RtreeTestcase = 0;
|
||||
# define testcase(X) if( X ){ sqlite3RtreeTestcase += __LINE__; }
|
||||
# else
|
||||
# define testcase(X)
|
||||
# endif
|
||||
# define testcase(X)
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -690,6 +666,18 @@ static void nodeBlobReset(Rtree *pRtree){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Check to see if pNode is the same as pParent or any of the parents
|
||||
** of pParent.
|
||||
*/
|
||||
static int nodeInParentChain(const RtreeNode *pNode, const RtreeNode *pParent){
|
||||
do{
|
||||
if( pNode==pParent ) return 1;
|
||||
pParent = pParent->pParent;
|
||||
}while( pParent );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Obtain a reference to an r-tree node.
|
||||
*/
|
||||
@@ -706,7 +694,14 @@ static int nodeAcquire(
|
||||
** increase its reference count and return it.
|
||||
*/
|
||||
if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
|
||||
if( pParent && pParent!=pNode->pParent ){
|
||||
if( pParent && !pNode->pParent ){
|
||||
if( nodeInParentChain(pNode, pParent) ){
|
||||
RTREE_IS_CORRUPT(pRtree);
|
||||
return SQLITE_CORRUPT_VTAB;
|
||||
}
|
||||
pParent->nRef++;
|
||||
pNode->pParent = pParent;
|
||||
}else if( pParent && pNode->pParent && pParent!=pNode->pParent ){
|
||||
RTREE_IS_CORRUPT(pRtree);
|
||||
return SQLITE_CORRUPT_VTAB;
|
||||
}
|
||||
@@ -764,7 +759,7 @@ static int nodeAcquire(
|
||||
** are the leaves, and so on. If the depth as specified on the root node
|
||||
** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
|
||||
*/
|
||||
if( rc==SQLITE_OK && pNode && iNode==1 ){
|
||||
if( pNode && rc==SQLITE_OK && iNode==1 ){
|
||||
pRtree->iDepth = readInt16(pNode->zData);
|
||||
if( pRtree->iDepth>RTREE_MAX_DEPTH ){
|
||||
rc = SQLITE_CORRUPT_VTAB;
|
||||
@@ -1287,29 +1282,20 @@ static void rtreeNonleafConstraint(
|
||||
switch( p->op ){
|
||||
case RTREE_TRUE: return; /* Always satisfied */
|
||||
case RTREE_FALSE: break; /* Never satisfied */
|
||||
case RTREE_LE:
|
||||
case RTREE_LT:
|
||||
case RTREE_EQ:
|
||||
RTREE_DECODE_COORD(eInt, pCellData, val);
|
||||
/* val now holds the lower bound of the coordinate pair */
|
||||
if( p->u.rValue>=val ){
|
||||
pCellData += 4;
|
||||
RTREE_DECODE_COORD(eInt, pCellData, val);
|
||||
/* val now holds the upper bound of the coordinate pair */
|
||||
if( p->u.rValue<=val ) return;
|
||||
}
|
||||
break;
|
||||
case RTREE_LE:
|
||||
case RTREE_LT:
|
||||
RTREE_DECODE_COORD(eInt, pCellData, val);
|
||||
/* val now holds the lower bound of the coordinate pair */
|
||||
if( p->u.rValue>=val ) return;
|
||||
break;
|
||||
if( p->op!=RTREE_EQ ) break; /* RTREE_LE and RTREE_LT end here */
|
||||
/* Fall through for the RTREE_EQ case */
|
||||
|
||||
default:
|
||||
default: /* RTREE_GT or RTREE_GE, or fallthrough of RTREE_EQ */
|
||||
pCellData += 4;
|
||||
RTREE_DECODE_COORD(eInt, pCellData, val);
|
||||
/* val now holds the upper bound of the coordinate pair */
|
||||
if( p->u.rValue<=val ) return;
|
||||
break;
|
||||
}
|
||||
*peWithin = NOT_WITHIN;
|
||||
}
|
||||
@@ -1379,12 +1365,11 @@ static int nodeRowidIndex(
|
||||
*/
|
||||
static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode, int *piIndex){
|
||||
RtreeNode *pParent = pNode->pParent;
|
||||
if( ALWAYS(pParent) ){
|
||||
if( pParent ){
|
||||
return nodeRowidIndex(pRtree, pParent, pNode->iNode, piIndex);
|
||||
}else{
|
||||
*piIndex = -1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
*piIndex = -1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1507,8 +1492,7 @@ static RtreeSearchPoint *rtreeSearchPointNew(
|
||||
pNew = rtreeEnqueue(pCur, rScore, iLevel);
|
||||
if( pNew==0 ) return 0;
|
||||
ii = (int)(pNew - pCur->aPoint) + 1;
|
||||
assert( ii==1 );
|
||||
if( ALWAYS(ii<RTREE_CACHE_SZ) ){
|
||||
if( ii<RTREE_CACHE_SZ ){
|
||||
assert( pCur->aNode[ii]==0 );
|
||||
pCur->aNode[ii] = pCur->aNode[0];
|
||||
}else{
|
||||
@@ -1569,7 +1553,7 @@ static void rtreeSearchPointPop(RtreeCursor *p){
|
||||
if( p->bPoint ){
|
||||
p->anQueue[p->sPoint.iLevel]--;
|
||||
p->bPoint = 0;
|
||||
}else if( ALWAYS(p->nPoint) ){
|
||||
}else if( p->nPoint ){
|
||||
p->anQueue[p->aPoint[0].iLevel]--;
|
||||
n = --p->nPoint;
|
||||
p->aPoint[0] = p->aPoint[n];
|
||||
@@ -1710,7 +1694,7 @@ static int rtreeRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *pRowid){
|
||||
RtreeSearchPoint *p = rtreeSearchPointFirst(pCsr);
|
||||
int rc = SQLITE_OK;
|
||||
RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
|
||||
if( rc==SQLITE_OK && ALWAYS(p) ){
|
||||
if( rc==SQLITE_OK && p ){
|
||||
*pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
|
||||
}
|
||||
return rc;
|
||||
@@ -1728,7 +1712,7 @@ static int rtreeColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
||||
RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
|
||||
|
||||
if( rc ) return rc;
|
||||
if( NEVER(p==0) ) return SQLITE_OK;
|
||||
if( p==0 ) return SQLITE_OK;
|
||||
if( i==0 ){
|
||||
sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
|
||||
}else if( i<=pRtree->nDim2 ){
|
||||
@@ -1927,11 +1911,8 @@ static int rtreeFilter(
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
RtreeSearchPoint *pNew;
|
||||
assert( pCsr->bPoint==0 ); /* Due to the resetCursor() call above */
|
||||
pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
|
||||
if( NEVER(pNew==0) ){ /* Because pCsr->bPoint was FALSE */
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
if( pNew==0 ) return SQLITE_NOMEM;
|
||||
pNew->id = 1;
|
||||
pNew->iCell = 0;
|
||||
pNew->eWithin = PARTLY_WITHIN;
|
||||
@@ -2008,7 +1989,7 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
|
||||
|
||||
if( bMatch==0 && p->usable
|
||||
&& p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
|
||||
&& p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ
|
||||
){
|
||||
/* We have an equality constraint on the rowid. Use strategy 1. */
|
||||
int jj;
|
||||
@@ -2214,7 +2195,7 @@ static int ChooseLeaf(
|
||||
|
||||
int nCell = NCELL(pNode);
|
||||
RtreeCell cell;
|
||||
RtreeNode *pChild = 0;
|
||||
RtreeNode *pChild;
|
||||
|
||||
RtreeCell *aCell = 0;
|
||||
|
||||
@@ -2261,19 +2242,12 @@ static int AdjustTree(
|
||||
){
|
||||
RtreeNode *p = pNode;
|
||||
int cnt = 0;
|
||||
int rc;
|
||||
while( p->pParent ){
|
||||
RtreeNode *pParent = p->pParent;
|
||||
RtreeCell cell;
|
||||
int iCell;
|
||||
|
||||
cnt++;
|
||||
if( NEVER(cnt>100) ){
|
||||
RTREE_IS_CORRUPT(pRtree);
|
||||
return SQLITE_CORRUPT_VTAB;
|
||||
}
|
||||
rc = nodeParentIndex(pRtree, p, &iCell);
|
||||
if( NEVER(rc!=SQLITE_OK) ){
|
||||
if( (++cnt)>1000 || nodeParentIndex(pRtree, p, &iCell) ){
|
||||
RTREE_IS_CORRUPT(pRtree);
|
||||
return SQLITE_CORRUPT_VTAB;
|
||||
}
|
||||
@@ -2562,17 +2536,12 @@ static int updateMapping(
|
||||
xSetMapping = ((iHeight==0)?rowidWrite:parentWrite);
|
||||
if( iHeight>0 ){
|
||||
RtreeNode *pChild = nodeHashLookup(pRtree, iRowid);
|
||||
RtreeNode *p;
|
||||
for(p=pNode; p; p=p->pParent){
|
||||
if( p==pChild ) return SQLITE_CORRUPT_VTAB;
|
||||
}
|
||||
if( pChild ){
|
||||
nodeRelease(pRtree, pChild->pParent);
|
||||
nodeReference(pNode);
|
||||
pChild->pParent = pNode;
|
||||
}
|
||||
}
|
||||
if( NEVER(pNode==0) ) return SQLITE_ERROR;
|
||||
return xSetMapping(pRtree, iRowid, pNode->iNode);
|
||||
}
|
||||
|
||||
@@ -2662,12 +2631,11 @@ static int SplitNode(
|
||||
RtreeNode *pParent = pLeft->pParent;
|
||||
int iCell;
|
||||
rc = nodeParentIndex(pRtree, pLeft, &iCell);
|
||||
if( ALWAYS(rc==SQLITE_OK) ){
|
||||
if( rc==SQLITE_OK ){
|
||||
nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
|
||||
rc = AdjustTree(pRtree, pParent, &leftbbox);
|
||||
assert( rc==SQLITE_OK );
|
||||
}
|
||||
if( NEVER(rc!=SQLITE_OK) ){
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto splitnode_out;
|
||||
}
|
||||
}
|
||||
@@ -2742,7 +2710,7 @@ static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
|
||||
*/
|
||||
iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
|
||||
for(pTest=pLeaf; pTest && pTest->iNode!=iNode; pTest=pTest->pParent);
|
||||
if( pTest==0 ){
|
||||
if( !pTest ){
|
||||
rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
|
||||
}
|
||||
}
|
||||
@@ -2773,7 +2741,6 @@ static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){
|
||||
pParent = pNode->pParent;
|
||||
pNode->pParent = 0;
|
||||
rc = deleteCell(pRtree, pParent, iCell, iHeight+1);
|
||||
testcase( rc!=SQLITE_OK );
|
||||
}
|
||||
rc2 = nodeRelease(pRtree, pParent);
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -2996,7 +2963,7 @@ static int rtreeInsertCell(
|
||||
}
|
||||
}else{
|
||||
rc = AdjustTree(pRtree, pNode, pCell);
|
||||
if( ALWAYS(rc==SQLITE_OK) ){
|
||||
if( rc==SQLITE_OK ){
|
||||
if( iHeight==0 ){
|
||||
rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
|
||||
}else{
|
||||
@@ -3102,7 +3069,7 @@ static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){
|
||||
int rc2;
|
||||
RtreeNode *pChild = 0;
|
||||
i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
|
||||
rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); /* tag-20210916a */
|
||||
rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
|
||||
}
|
||||
@@ -3437,7 +3404,7 @@ static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
|
||||
char *zSql;
|
||||
sqlite3_stmt *p;
|
||||
int rc;
|
||||
i64 nRow = RTREE_MIN_ROWEST;
|
||||
i64 nRow = 0;
|
||||
|
||||
rc = sqlite3_table_column_metadata(
|
||||
db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
|
||||
@@ -3454,10 +3421,20 @@ static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
|
||||
if( rc==SQLITE_OK ){
|
||||
if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
|
||||
rc = sqlite3_finalize(p);
|
||||
}else if( rc!=SQLITE_NOMEM ){
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
if( nRow==0 ){
|
||||
pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
|
||||
}else{
|
||||
pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
|
||||
}
|
||||
}
|
||||
sqlite3_free(zSql);
|
||||
}
|
||||
pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3607,12 +3584,9 @@ static int rtreeSqlInit(
|
||||
sqlite3_str_appendf(p, "UPDATE \"%w\".\"%w_rowid\"SET ", zDb, zPrefix);
|
||||
for(ii=0; ii<pRtree->nAux; ii++){
|
||||
if( ii ) sqlite3_str_append(p, ",", 1);
|
||||
#ifdef SQLITE_ENABLE_GEOPOLY
|
||||
if( ii<pRtree->nAuxNotNull ){
|
||||
sqlite3_str_appendf(p,"a%d=coalesce(?%d,a%d)",ii,ii+2,ii);
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
}else{
|
||||
sqlite3_str_appendf(p,"a%d=?%d",ii,ii+2);
|
||||
}
|
||||
}
|
||||
@@ -3877,7 +3851,6 @@ static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
|
||||
tree.nDim2 = tree.nDim*2;
|
||||
tree.nBytesPerCell = 8 + 8 * tree.nDim;
|
||||
node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
|
||||
if( node.zData==0 ) return;
|
||||
nData = sqlite3_value_bytes(apArg[1]);
|
||||
if( nData<4 ) return;
|
||||
if( nData<NCELL(&node)*tree.nBytesPerCell ) return;
|
||||
@@ -4292,10 +4265,8 @@ static int rtreeCheckTable(
|
||||
if( pStmt ){
|
||||
nAux = sqlite3_column_count(pStmt) - 2;
|
||||
sqlite3_finalize(pStmt);
|
||||
}else
|
||||
if( check.rc!=SQLITE_NOMEM ){
|
||||
check.rc = SQLITE_OK;
|
||||
}
|
||||
check.rc = SQLITE_OK;
|
||||
}
|
||||
|
||||
/* Find number of dimensions in the rtree table. */
|
||||
@@ -4552,10 +4523,7 @@ int sqlite3_rtree_query_callback(
|
||||
|
||||
/* Allocate and populate the context object. */
|
||||
pGeomCtx = (RtreeGeomCallback *)sqlite3_malloc(sizeof(RtreeGeomCallback));
|
||||
if( !pGeomCtx ){
|
||||
if( xDestructor ) xDestructor(pContext);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
if( !pGeomCtx ) return SQLITE_NOMEM;
|
||||
pGeomCtx->xGeom = 0;
|
||||
pGeomCtx->xQueryFunc = xQueryFunc;
|
||||
pGeomCtx->xDestructor = xDestructor;
|
||||
|
||||
@@ -57,12 +57,9 @@ ifcapable !rtree {
|
||||
do_test rtree-1.1.1 {
|
||||
execsql { CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2) }
|
||||
} {}
|
||||
do_test rtree-1.1.2a {
|
||||
do_test rtree-1.1.2 {
|
||||
execsql { SELECT name FROM sqlite_master ORDER BY name }
|
||||
} {t1 t1_node t1_parent t1_rowid}
|
||||
do_execsql_test rtree-1.1.2b {
|
||||
SELECT name FROM pragma_table_list WHERE type='shadow' ORDER BY name;
|
||||
} {t1_node t1_parent t1_rowid}
|
||||
do_test rtree-1.1.3 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
|
||||
@@ -36,7 +36,7 @@ do_execsql_test rtree9-1.4 {
|
||||
DELETE FROM rt;
|
||||
} {}
|
||||
|
||||
unset -nocomplain x
|
||||
|
||||
for {set i 0} {$i < 1000} {incr i} {
|
||||
set x [expr $i%10]
|
||||
set y [expr ($i/10)%10]
|
||||
|
||||
@@ -145,7 +145,7 @@ populate_t1
|
||||
do_test rtreeA-2.2.0 { truncate_node 1 200 } {}
|
||||
do_corruption_tests rtreeA-2.2 {
|
||||
1 "SELECT * FROM t1"
|
||||
2 "SELECT * FROM t1 WHERE +rowid=5"
|
||||
2 "SELECT * FROM t1 WHERE rowid=5"
|
||||
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
||||
4 "SELECT * FROM t1 WHERE x1<10 AND x2>12"
|
||||
}
|
||||
@@ -160,18 +160,18 @@ do_test rtreeA-3.1.0.1 { set_tree_depth t1 } {1}
|
||||
do_test rtreeA-3.1.0.2 { set_tree_depth t1 3 } {3}
|
||||
do_corruption_tests rtreeA-3.1 {
|
||||
1 "SELECT * FROM t1"
|
||||
2 "SELECT * FROM t1 WHERE +rowid=5"
|
||||
2 "SELECT * FROM t1 WHERE rowid=5"
|
||||
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
||||
}
|
||||
|
||||
do_execsql_test rtreeA-3.1.0.3 {
|
||||
SELECT rtreecheck('main', 't1')!='ok'
|
||||
SELECT rtreecheck('main', 't1')!="ok"
|
||||
} {1}
|
||||
|
||||
do_test rtreeA-3.2.0 { set_tree_depth t1 1000 } {1000}
|
||||
do_corruption_tests rtreeA-3.2 {
|
||||
1 "SELECT * FROM t1"
|
||||
2 "SELECT * FROM t1 WHERE +rowid=5"
|
||||
2 "SELECT * FROM t1 WHERE rowid=5"
|
||||
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ do_test rtreeA-3.3.0 {
|
||||
} {65535}
|
||||
do_corruption_tests rtreeA-3.3 {
|
||||
1 "SELECT * FROM t1"
|
||||
2 "SELECT * FROM t1 WHERE +rowid=5"
|
||||
2 "SELECT * FROM t1 WHERE rowid=5"
|
||||
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ do_test rtreeA-4.1.0 {
|
||||
} {4000}
|
||||
do_corruption_tests rtreeA-4.1 {
|
||||
1 "SELECT * FROM t1"
|
||||
2 "SELECT * FROM t1 WHERE +rowid=5"
|
||||
2 "SELECT * FROM t1 WHERE rowid=5"
|
||||
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
||||
4 "SELECT * FROM t1 WHERE x1<10 AND x2>12"
|
||||
}
|
||||
@@ -216,12 +216,12 @@ create_t1
|
||||
populate_t1
|
||||
do_execsql_test rtreeA-5.1.0 { DELETE FROM t1_parent } {}
|
||||
do_corruption_tests rtreeA-5.1 {
|
||||
1 "DELETE FROM t1 WHERE +rowid = 5"
|
||||
1 "DELETE FROM t1 WHERE rowid = 5"
|
||||
2 "DELETE FROM t1"
|
||||
}
|
||||
|
||||
do_execsql_test rtreeA-5.2 {
|
||||
SELECT rtreecheck('main', 't1')!='ok'
|
||||
SELECT rtreecheck('main', 't1')!="ok"
|
||||
} {1}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@@ -238,7 +238,7 @@ do_corruption_tests rtreeA-6.1 {
|
||||
}
|
||||
|
||||
do_execsql_test rtreeA-6.2 {
|
||||
SELECT rtreecheck('main', 't1')!='ok'
|
||||
SELECT rtreecheck('main', 't1')!="ok"
|
||||
} {1}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
@@ -117,13 +117,13 @@ sqlite3_db_config db DEFENSIVE 0
|
||||
do_execsql_test 3.2 {
|
||||
BEGIN;
|
||||
UPDATE r2_node SET data = X'123456';
|
||||
SELECT rtreecheck('r2')!='ok';
|
||||
SELECT rtreecheck('r2')!="ok";
|
||||
} {1}
|
||||
|
||||
do_execsql_test 3.3 {
|
||||
ROLLBACK;
|
||||
UPDATE r2_node SET data = X'00001234';
|
||||
SELECT rtreecheck('r2')!='ok';
|
||||
SELECT rtreecheck('r2')!="ok";
|
||||
} {1}
|
||||
|
||||
do_execsql_test 4.0 {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,346 +0,0 @@
|
||||
# 2021 September 13
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# The focus of this file is testing the r-tree extension.
|
||||
#
|
||||
|
||||
if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname [info script]] .. .. test]
|
||||
}
|
||||
source [file join [file dirname [info script]] rtree_util.tcl]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix rtreedoc2
|
||||
|
||||
ifcapable !rtree {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------
|
||||
# Section 6 of documentation.
|
||||
#-------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------
|
||||
set testprefix rtreedoc2-1
|
||||
|
||||
# EVIDENCE-OF: R-35254-48865 A call to one of the above APIs creates a
|
||||
# new SQL function named by the second parameter (zQueryFunc or zGeom).
|
||||
#
|
||||
# [register_circle_geom db] registers new geometry callback "Qcircle"
|
||||
# and legacy implementation "circle". Test that these do actually appear.
|
||||
#
|
||||
do_execsql_test 1.1.0 {
|
||||
SELECT * FROM pragma_function_list WHERE name IN('circle', 'qcircle');
|
||||
} {
|
||||
}
|
||||
do_test 1.1 {
|
||||
register_circle_geom db
|
||||
} {SQLITE_OK}
|
||||
do_execsql_test 1.1.2 {
|
||||
SELECT * FROM pragma_function_list WHERE name = 'circle' AND enc='utf8';
|
||||
} {
|
||||
circle 0 s utf8 -1 0
|
||||
}
|
||||
do_execsql_test 1.1.3 {
|
||||
SELECT * FROM pragma_function_list WHERE name = 'qcircle' AND enc='utf8';
|
||||
} {
|
||||
qcircle 0 s utf8 -1 0
|
||||
}
|
||||
|
||||
do_execsql_test 1.2.0 { SELECT circle(1, 2, 3); } {{}}
|
||||
do_execsql_test 1.2.1 { SELECT qcircle(1, 2, 3); } {{}}
|
||||
|
||||
# EVIDENCE-OF: R-61427-46983
|
||||
do_execsql_test 1.3.0 {
|
||||
CREATE VIRTUAL TABLE demo_index USING rtree(id, x1,x2, y1,y2);
|
||||
INSERT INTO demo_index VALUES(10, 45,45, 24,24);
|
||||
INSERT INTO demo_index VALUES(20, 50,50, 28,28);
|
||||
INSERT INTO demo_index VALUES(30, 43,43, 22,22);
|
||||
}
|
||||
do_execsql_test 1.3.1 {
|
||||
SELECT id FROM demo_index WHERE id MATCH circle(45.3, 22.9, 5.0)
|
||||
} {10 30}
|
||||
|
||||
# EVIDENCE-OF: R-16907-50223 The SQL syntax for custom queries is the
|
||||
# same regardless of which interface, sqlite3_rtree_geometry_callback()
|
||||
# or sqlite3_rtree_query_callback(), is used to register the SQL
|
||||
# function.
|
||||
do_execsql_test 1.3.2 {
|
||||
SELECT id FROM demo_index WHERE id MATCH qcircle(45.3, 22.9, 5.0, 1)
|
||||
} {10 30}
|
||||
|
||||
|
||||
# EVIDENCE-OF: R-59634-51678 When that SQL function appears on the
|
||||
# right-hand side of the MATCH operator and the left-hand side of the
|
||||
# MATCH operator is any column in the R*Tree virtual table, then the
|
||||
# callback defined by the third argument (xQueryFunc or xGeom) is
|
||||
# invoked to determine if a particular object or subtree overlaps the
|
||||
# desired region.
|
||||
proc box_geom {args} {
|
||||
lappend ::box_geom [concat [lindex $args 0] [lrange $args 2 end-1]]
|
||||
return ""
|
||||
}
|
||||
register_box_geom db box_geom
|
||||
set box_geom [list]
|
||||
do_execsql_test 1.3.2 {
|
||||
SELECT id FROM demo_index WHERE id MATCH box(43,46, 21,25);
|
||||
} {10 30}
|
||||
do_test 1.3.3 {
|
||||
set ::box_geom
|
||||
} [list {*}{
|
||||
{box {43.0 46.0 21.0 25.0} {45.0 45.0 24.0 24.0}}
|
||||
{box {43.0 46.0 21.0 25.0} {50.0 50.0 28.0 28.0}}
|
||||
{box {43.0 46.0 21.0 25.0} {43.0 43.0 22.0 22.0}}
|
||||
}]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------
|
||||
# Section 6 of documentation.
|
||||
#-------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------
|
||||
set testprefix rtreedoc2-2
|
||||
|
||||
# EVIDENCE-OF: R-02424-24769 The second argument is the number of
|
||||
# coordinates in each r-tree entry, and is always the same for any given
|
||||
# R*Tree.
|
||||
#
|
||||
# EVIDENCE-OF: R-40260-16838 The number of coordinates is 2 for a
|
||||
# 1-dimensional R*Tree, 4 for a 2-dimensional R*Tree, 6 for a
|
||||
# 3-dimensional R*Tree, and so forth.
|
||||
#
|
||||
# The second argument refered to above is the length of the list passed
|
||||
# as the 3rd parameter to the Tcl script.
|
||||
#
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE rt1 USING rtree(id, x1,x2);
|
||||
CREATE VIRTUAL TABLE rt2 USING rtree(id, x1,x2, y1,y2);
|
||||
CREATE VIRTUAL TABLE rt3 USING rtree(id, x1,x2, y1,y2, z1,z2);
|
||||
|
||||
INSERT INTO rt1 DEFAULT VALUES;
|
||||
INSERT INTO rt2 DEFAULT VALUES;
|
||||
INSERT INTO rt3 DEFAULT VALUES;
|
||||
}
|
||||
foreach {tn tbl nCoord} {
|
||||
1 rt1 2
|
||||
2 rt2 4
|
||||
3 rt3 6
|
||||
} {
|
||||
set ::box_geom [list]
|
||||
do_catchsql_test 1.$tn.1 "
|
||||
SELECT id FROM $tbl WHERE id MATCH box();
|
||||
" {1 {SQL logic error}}
|
||||
|
||||
do_test 1.$tn.2 {
|
||||
llength [lindex $::box_geom 0 2]
|
||||
} $nCoord
|
||||
}
|
||||
|
||||
# EVIDENCE-OF: R-28051-48608 If xGeom returns anything other than
|
||||
# SQLITE_OK, then the r-tree query will abort with an error.
|
||||
proc box_geom {args} {
|
||||
error "an error!"
|
||||
}
|
||||
do_catchsql_test 2.0 {
|
||||
SELECT * FROM rt2 WHERE id MATCH box(22,23, 24,25);
|
||||
} {1 {SQL logic error}}
|
||||
|
||||
do_execsql_test 3.0 {
|
||||
INSERT INTO rt1 VALUES(10, 10, 10);
|
||||
INSERT INTO rt1 VALUES(11, 11, 11);
|
||||
INSERT INTO rt1 VALUES(12, 12, 12);
|
||||
INSERT INTO rt1 VALUES(13, 13, 13);
|
||||
INSERT INTO rt1 VALUES(14, 14, 14);
|
||||
}
|
||||
|
||||
# EVIDENCE-OF: R-53759-57366 The exact same sqlite3_rtree_geometry
|
||||
# structure is used for every callback for same MATCH operator in the
|
||||
# same query.
|
||||
proc box_geom {args} {
|
||||
lappend ::ptr_list [lindex $args 4]
|
||||
return 0
|
||||
}
|
||||
set ::ptr_list [list]
|
||||
do_execsql_test 3.1 {
|
||||
SELECT * FROM rt1 WHERE id MATCH box(1,1);
|
||||
}
|
||||
do_test 3.2 {
|
||||
set val [lindex $::ptr_list 0]
|
||||
foreach p $::ptr_list {
|
||||
if {$p!=$val} {error "pointer mismatch"}
|
||||
}
|
||||
} {}
|
||||
|
||||
# EVIDENCE-OF: R-60247-35692 The contents of the sqlite3_rtree_geometry
|
||||
# structure are initialized by SQLite but are not subsequently modified.
|
||||
proc box_geom {args} {
|
||||
lappend ::box_geom [concat [lindex $args 0] [lrange $args 2 end-1]]
|
||||
if {[llength $::box_geom]==3} {
|
||||
return "zero"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
set ::box_geom [list]
|
||||
do_catchsql_test 3.2 {
|
||||
SELECT * FROM rt1 WHERE id MATCH box(1,1);
|
||||
} {1 {SQL logic error}}
|
||||
do_test 3.3 {
|
||||
set ::box_geom
|
||||
} [list {*}{
|
||||
{box {1.0 1.0} {0.0 0.0}}
|
||||
{box {1.0 1.0} {10.0 10.0}}
|
||||
{box {1.0 1.0} {11.0 11.0}}
|
||||
{box 0.0 {12.0 12.0}}
|
||||
}]
|
||||
|
||||
# EVIDENCE-OF: R-31246-29731 The pContext member of the
|
||||
# sqlite3_rtree_geometry structure is always set to a copy of the
|
||||
# pContext argument passed to sqlite3_rtree_geometry_callback() when the
|
||||
# callback is registered.
|
||||
reset_db
|
||||
do_execsql_test 4.0 {
|
||||
CREATE VIRTUAL TABLE r1 USING rtree(id, minX,maxX, minY,maxY);
|
||||
WITH s(i) AS (
|
||||
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<120
|
||||
)
|
||||
INSERT INTO r1 SELECT i,i,i+1, 200,201 FROM s;
|
||||
}
|
||||
set ctx [register_box_geom db box_geom]
|
||||
set ::box_geom [list]
|
||||
proc box_geom {args} {
|
||||
lappend ::box_geom [lindex $args 1]
|
||||
return ""
|
||||
}
|
||||
do_execsql_test 4.1 {
|
||||
SELECT count(*) FROM r1 WHERE id MATCH box(0,150,199,201)
|
||||
} 120
|
||||
do_test 4.2 {
|
||||
foreach g $::box_geom {
|
||||
if {$g!=$ctx} {error "pointer mismatch"}
|
||||
}
|
||||
} {}
|
||||
|
||||
# EVIDENCE-OF: R-09904-19077 The aParam[] array (size nParam) contains
|
||||
# the parameter values passed to the SQL function on the right-hand side
|
||||
# of the MATCH operator.
|
||||
proc box_geom {args} {
|
||||
set ::box_geom [lindex $args 2]
|
||||
}
|
||||
foreach {tn q vals} {
|
||||
1 "SELECT count(*) FROM r1 WHERE id MATCH box(1,2,3)" {1.0 2.0 3.0}
|
||||
2 "SELECT count(*) FROM r1 WHERE id MATCH box(10001)" {10001.0}
|
||||
3 "SELECT count(*) FROM r1 WHERE id MATCH box(-10001)" {-10001.0}
|
||||
} {
|
||||
do_catchsql_test 5.$tn.1 $q {1 {SQL logic error}}
|
||||
do_test 5.$tn.2 { set ::box_geom } $vals
|
||||
}
|
||||
|
||||
do_execsql_test 5.0 {
|
||||
CREATE VIRTUAL TABLE myrtree USING rtree(id, x1,x2);
|
||||
INSERT INTO myrtree VALUES(1, 1, 1);
|
||||
INSERT INTO myrtree VALUES(2, 2, 2);
|
||||
INSERT INTO myrtree VALUES(3, 3, 3);
|
||||
}
|
||||
|
||||
# EVIDENCE-OF: R-44448-00687 The pUser and xDelUser members of the
|
||||
# sqlite3_rtree_geometry structure are initially set to NULL.
|
||||
set ::box_geom_calls 0
|
||||
proc box_geom {args} {
|
||||
incr ::box_geom_calls
|
||||
return user_is_zero
|
||||
}
|
||||
do_execsql_test 5.1.1 {
|
||||
SELECT * FROM myrtree WHERE id MATCH box(4, 5);
|
||||
}
|
||||
do_test 5.1.2 { set ::box_geom_calls } 3
|
||||
|
||||
|
||||
# EVIDENCE-OF: R-55837-00155 The pUser variable may be set by the
|
||||
# callback implementation to any arbitrary value that may be useful to
|
||||
# subsequent invocations of the callback within the same query (for
|
||||
# example, a pointer to a complicated data structure used to test for
|
||||
# region intersection).
|
||||
#
|
||||
# EVIDENCE-OF: R-34745-08839 If the xDelUser variable is set to a
|
||||
# non-NULL value, then after the query has finished running SQLite
|
||||
# automatically invokes it with the value of the pUser variable as the
|
||||
# only argument.
|
||||
#
|
||||
set ::box_geom_calls 0
|
||||
proc box_geom {args} {
|
||||
incr ::box_geom_calls
|
||||
switch -- $::box_geom_calls {
|
||||
1 {
|
||||
return user_is_zero
|
||||
}
|
||||
2 {
|
||||
return [list user box_geom_finalizer]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
proc box_geom_finalizer {} {
|
||||
set ::box_geom_finalizer "::box_geom_calls is $::box_geom_calls"
|
||||
}
|
||||
do_execsql_test 5.1.1 {
|
||||
SELECT * FROM myrtree WHERE id MATCH box(4, 5);
|
||||
}
|
||||
do_test 5.1.2 { set ::box_geom_calls } 3
|
||||
do_test 5.1.3 {
|
||||
set ::box_geom_finalizer
|
||||
} {::box_geom_calls is 3}
|
||||
|
||||
|
||||
# EVIDENCE-OF: R-28176-28813 The xGeom callback always does a
|
||||
# depth-first search of the r-tree.
|
||||
#
|
||||
# For a breadth first search, final test case would return "B L" only.
|
||||
#
|
||||
do_execsql_test 6.0 {
|
||||
CREATE VIRTUAL TABLE xyz USING rtree(x, x1,x2, y1,y2);
|
||||
WITH s(i) AS (
|
||||
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<15
|
||||
)
|
||||
INSERT INTO xyz SELECT NULL, one.i,one.i+1, two.i,two.i+1 FROM s one, s two;
|
||||
}
|
||||
do_execsql_test 6.1 {
|
||||
SELECT count(*) FROM xyz_node
|
||||
} {10}
|
||||
proc box_geom {args} {
|
||||
set coords [lindex $args 3]
|
||||
set area [expr {
|
||||
([lindex $coords 1]-[lindex $coords 0]) *
|
||||
([lindex $coords 3]-[lindex $coords 2])
|
||||
}]
|
||||
if {$area==1} {
|
||||
lappend ::box_geom_calls L
|
||||
} else {
|
||||
lappend ::box_geom_calls B
|
||||
}
|
||||
}
|
||||
set ::box_geom_calls [list]
|
||||
do_execsql_test 6.2 {
|
||||
SELECT count(*) FROM xyz WHERE x MATCH box(0,20,0,20)
|
||||
} 225
|
||||
do_test 6.3 {
|
||||
set prev ""
|
||||
set box_calls [list]
|
||||
foreach c $::box_geom_calls {
|
||||
if {$c!=$prev} {
|
||||
lappend ::box_calls $c
|
||||
set prev $c
|
||||
}
|
||||
}
|
||||
set ::box_calls
|
||||
} {B L B L B L B L B L B L B L B L B L}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,292 +0,0 @@
|
||||
# 2021 September 13
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# The focus of this file is testing the r-tree extension.
|
||||
#
|
||||
|
||||
if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname [info script]] .. .. test]
|
||||
}
|
||||
source [file join [file dirname [info script]] rtree_util.tcl]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix rtreedoc3
|
||||
|
||||
ifcapable !rtree {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
# This command assumes that the argument is a node blob for a 2 dimensional
|
||||
# i32 r-tree table. It decodes and returns a list of cells from the node
|
||||
# as a list. Each cell is itself a list of the following form:
|
||||
#
|
||||
# {$rowid $minX $maxX $minY $maxY}
|
||||
#
|
||||
# For internal (non-leaf) nodes, the rowid is replaced by the child node
|
||||
# number.
|
||||
#
|
||||
proc rnode_cells {aData} {
|
||||
set nDim 2
|
||||
|
||||
set nData [string length $aData]
|
||||
set nBytePerCell [expr (8 + 2*$nDim*4)]
|
||||
binary scan [string range $aData 2 3] S nCell
|
||||
|
||||
set res [list]
|
||||
for {set i 0} {$i < $nCell} {incr i} {
|
||||
set iOff [expr $i*$nBytePerCell+4]
|
||||
set cell [string range $aData $iOff [expr $iOff+$nBytePerCell-1]]
|
||||
binary scan $cell WIIII rowid x1 x2 y1 y2
|
||||
lappend res [list $rowid $x1 $x2 $y1 $y2]
|
||||
}
|
||||
|
||||
return $res
|
||||
}
|
||||
|
||||
# Interpret the first two bytes of the blob passed as the only parameter
|
||||
# as a 16-bit big-endian integer and return the value. If this blob is
|
||||
# the root node of an r-tree, this value is the height of the tree.
|
||||
#
|
||||
proc rnode_height {aData} {
|
||||
binary scan [string range $aData 0 1] S nHeight
|
||||
return $nHeight
|
||||
}
|
||||
|
||||
# Return a blob containing node iNode of r-tree "rt".
|
||||
#
|
||||
proc rt_node_get {iNode} {
|
||||
db one { SELECT data FROM rt_node WHERE nodeno=$iNode }
|
||||
}
|
||||
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# API:
|
||||
#
|
||||
# pq_init
|
||||
# Initialize a new test.
|
||||
#
|
||||
# pq_test_callback
|
||||
# Invoked each time the xQueryCallback function is called. This Tcl
|
||||
# command checks that the arguments that SQLite passed to xQueryCallback
|
||||
# are as expected.
|
||||
#
|
||||
# pq_test_row
|
||||
# Invoked each time a row is returned. Checks that the row returned
|
||||
# was predicted by the documentation.
|
||||
#
|
||||
# DATA STRUCTURE:
|
||||
# The priority queue is stored as a Tcl list. The order of elements in
|
||||
# the list is unimportant - it is just used as a set here. Each element
|
||||
# in the priority queue is itself a list. The first element is the
|
||||
# priority value for the entry (a real). Following this is a list of
|
||||
# key-value pairs that make up the entries fields.
|
||||
#
|
||||
proc pq_init {} {
|
||||
global Q
|
||||
set Q(pri_queue) [list]
|
||||
|
||||
set nHeight [rnode_height [rt_node_get 1]]
|
||||
set nCell [llength [rnode_cells [rt_node_get 1]]]
|
||||
|
||||
# EVIDENCE-OF: R-54708-13595 An R*Tree query is initialized by making
|
||||
# the root node the only entry in a priority queue sorted by rScore.
|
||||
lappend Q(pri_queue) [list 0.0 [list \
|
||||
iLevel [expr $nHeight+1] \
|
||||
iChild 1 \
|
||||
iCurrent 0 \
|
||||
]]
|
||||
}
|
||||
|
||||
proc pq_extract {} {
|
||||
global Q
|
||||
if {[llength $Q(pri_queue)]==0} {
|
||||
error "priority queue is empty!"
|
||||
}
|
||||
|
||||
# Find the priority queue entry with the lowest score.
|
||||
#
|
||||
# EVIDENCE-OF: R-47257-47871 Smaller scores are processed first.
|
||||
set iBest 0
|
||||
set rBestScore [lindex $Q(pri_queue) 0 0]
|
||||
for {set ii 1} {$ii < [llength $Q(pri_queue)]} {incr ii} {
|
||||
set rScore [expr [lindex $Q(pri_queue) $ii 0]]
|
||||
if {$rScore<$rBestScore} {
|
||||
set rBestScore $rScore
|
||||
set iBest $ii
|
||||
}
|
||||
}
|
||||
|
||||
# Extract the entry with the lowest score from the queue and return it.
|
||||
#
|
||||
# EVIDENCE-OF: R-60002-49798 The query proceeds by extracting the entry
|
||||
# from the priority queue that has the lowest score.
|
||||
set ret [lindex $Q(pri_queue) $iBest]
|
||||
set Q(pri_queue) [lreplace $Q(pri_queue) $iBest $iBest]
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
||||
proc pq_new_entry {rScore iLevel cell} {
|
||||
global Q
|
||||
|
||||
set rowid_name "iChild"
|
||||
if {$iLevel==0} { set rowid_name "iRowid" }
|
||||
|
||||
set kv [list]
|
||||
lappend kv aCoord [lrange $cell 1 end]
|
||||
lappend kv iLevel $iLevel
|
||||
|
||||
if {$iLevel==0} {
|
||||
lappend kv iRowid [lindex $cell 0]
|
||||
} else {
|
||||
lappend kv iChild [lindex $cell 0]
|
||||
lappend kv iCurrent 0
|
||||
}
|
||||
|
||||
lappend Q(pri_queue) [list $rScore $kv]
|
||||
}
|
||||
|
||||
proc pq_test_callback {L res} {
|
||||
#pq_debug "pq_test_callback $L -> $res"
|
||||
global Q
|
||||
|
||||
array set G $L ;# "Got" - as in stuff passed to xQuery
|
||||
|
||||
# EVIDENCE-OF: R-65127-42665 If the extracted priority queue entry is a
|
||||
# node (a subtree), then the next child of that node is passed to the
|
||||
# xQueryFunc callback.
|
||||
#
|
||||
# If it had been a leaf, the row should have been returned, instead of
|
||||
# xQueryCallback being called on a child - as is happening here.
|
||||
foreach {rParentScore parent} [pq_extract] {}
|
||||
array set P $parent ;# "Parent" - as in parent of expected cell
|
||||
if {$P(iLevel)==0} { error "query callback mismatch (1)" }
|
||||
set child_node [rnode_cells [rt_node_get $P(iChild)]]
|
||||
set expected_cell [lindex $child_node $P(iCurrent)]
|
||||
set expected_coords [lrange $expected_cell 1 end]
|
||||
if {[llength $expected_coords] != [llength $G(aCoord)]} {
|
||||
puts [array get P]
|
||||
puts "E: $expected_coords G: $G(aCoord)"
|
||||
error "coordinate mismatch in query callback (1)"
|
||||
}
|
||||
foreach a [lrange $expected_cell 1 end] b $G(aCoord) {
|
||||
if {$a!=$b} { error "coordinate mismatch in query callback (2)" }
|
||||
}
|
||||
|
||||
# Check level is as expected
|
||||
#
|
||||
if {$G(iLevel) != $P(iLevel)-1} {
|
||||
error "iLevel mismatch in query callback (1)"
|
||||
}
|
||||
|
||||
# Unless the callback returned NOT_WITHIN, add the entry to the priority
|
||||
# queue.
|
||||
#
|
||||
# EVIDENCE-OF: R-28754-35153 Those subelements for which the xQueryFunc
|
||||
# callback sets eWithin to PARTLY_WITHIN or FULLY_WITHIN are added to
|
||||
# the priority queue using the score supplied by the callback.
|
||||
#
|
||||
# EVIDENCE-OF: R-08681-45277 Subelements that return NOT_WITHIN are
|
||||
# discarded.
|
||||
set r [lindex $res 0]
|
||||
set rScore [lindex $res 1]
|
||||
if {$r!="fully" && $r!="partly" && $r!="not"} {
|
||||
error "unknown result: $r - expected \"fully\", \"partly\" or \"not\""
|
||||
}
|
||||
if {$r!="not"} {
|
||||
pq_new_entry $rScore [expr $P(iLevel)-1] $expected_cell
|
||||
}
|
||||
|
||||
# EVIDENCE-OF: R-07194-63805 If the node has more children then it is
|
||||
# returned to the priority queue. Otherwise it is discarded.
|
||||
incr P(iCurrent)
|
||||
if {$P(iCurrent)<[llength $child_node]} {
|
||||
lappend Q(pri_queue) [list $rParentScore [array get P]]
|
||||
}
|
||||
}
|
||||
|
||||
proc pq_test_result {id x1 x2 y1 y2} {
|
||||
#pq_debug "pq_test_result $id $x1 $x2 $y1 $y2"
|
||||
foreach {rScore next} [pq_extract] {}
|
||||
|
||||
# The extracted entry must be a leaf (otherwise, xQueryCallback would
|
||||
# have been called on the extracted entries children instead of just
|
||||
# returning the data).
|
||||
#
|
||||
# EVIDENCE-OF: R-13214-54017 If that entry is a leaf (meaning that it is
|
||||
# an actual R*Tree entry and not a subtree) then that entry is returned
|
||||
# as one row of the query result.
|
||||
array set N $next
|
||||
if {$N(iLevel)!=0} { error "result row mismatch (1)" }
|
||||
|
||||
if {$x1!=[lindex $N(aCoord) 0] || $x2!=[lindex $N(aCoord) 1]
|
||||
|| $y1!=[lindex $N(aCoord) 2] || $y2!=[lindex $N(aCoord) 3]
|
||||
} {
|
||||
if {$N(iLevel)!=0} { error "result row mismatch (2)" }
|
||||
}
|
||||
|
||||
if {$id!=$N(iRowid)} { error "result row mismatch (3)" }
|
||||
}
|
||||
|
||||
proc pq_done {} {
|
||||
global Q
|
||||
# EVIDENCE-OF: R-57438-45968 The query runs until the priority queue is
|
||||
# empty.
|
||||
if {[llength $Q(pri_queue)]>0} {
|
||||
error "priority queue is not empty!"
|
||||
}
|
||||
}
|
||||
|
||||
proc pq_debug {caption} {
|
||||
global Q
|
||||
|
||||
puts "**** $caption ****"
|
||||
set i 0
|
||||
foreach q [lsort -real -index 0 $Q(pri_queue)] {
|
||||
puts "PQ $i: $q"
|
||||
incr i
|
||||
}
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------
|
||||
|
||||
proc box_query {a} {
|
||||
set res [list fully [expr rand()]]
|
||||
pq_test_callback $a $res
|
||||
return $res
|
||||
}
|
||||
|
||||
register_box_query db box_query
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE rt USING rtree_i32(id, x1,x2, y1,y2);
|
||||
WITH s(i) AS (
|
||||
SELECT 0 UNION ALL SELECT i+1 FROM s WHERE i<64
|
||||
)
|
||||
INSERT INTO rt SELECT NULL, a.i, a.i+1, b.i, b.i+1 FROM s a, s b;
|
||||
}
|
||||
|
||||
proc box_query {a} {
|
||||
set res [list fully [expr rand()]]
|
||||
pq_test_callback $a $res
|
||||
return $res
|
||||
}
|
||||
|
||||
pq_init
|
||||
db eval { SELECT id, x1,x2, y1,y2 FROM rt WHERE id MATCH qbox() } {
|
||||
pq_test_result $id $x1 $x2 $y1 $y2
|
||||
}
|
||||
pq_done
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -1,348 +0,0 @@
|
||||
/*
|
||||
** 2010 August 28
|
||||
**
|
||||
** 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 all sorts of SQLite interfaces. This code
|
||||
** is not included in the SQLite library.
|
||||
*/
|
||||
|
||||
#include "sqlite3.h"
|
||||
#if defined(INCLUDE_SQLITE_TCL_H)
|
||||
# include "sqlite_tcl.h"
|
||||
#else
|
||||
# include "tcl.h"
|
||||
#endif
|
||||
|
||||
/* Solely for the UNUSED_PARAMETER() macro. */
|
||||
#include "sqliteInt.h"
|
||||
|
||||
#ifdef SQLITE_ENABLE_RTREE
|
||||
|
||||
typedef struct BoxGeomCtx BoxGeomCtx;
|
||||
struct BoxGeomCtx {
|
||||
Tcl_Interp *interp;
|
||||
Tcl_Obj *pScript;
|
||||
};
|
||||
|
||||
typedef struct BoxQueryCtx BoxQueryCtx;
|
||||
struct BoxQueryCtx {
|
||||
Tcl_Interp *interp;
|
||||
Tcl_Obj *pScript;
|
||||
};
|
||||
|
||||
static void testDelUser(void *pCtx){
|
||||
BoxGeomCtx *p = (BoxGeomCtx*)pCtx;
|
||||
Tcl_EvalObjEx(p->interp, p->pScript, 0);
|
||||
Tcl_DecrRefCount(p->pScript);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
|
||||
static int invokeTclGeomCb(
|
||||
const char *zName,
|
||||
sqlite3_rtree_geometry *p,
|
||||
int nCoord,
|
||||
sqlite3_rtree_dbl *aCoord
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
if( p->pContext ){
|
||||
char aPtr[64];
|
||||
BoxGeomCtx *pCtx = (BoxGeomCtx*)p->pContext;
|
||||
Tcl_Interp *interp = pCtx->interp;
|
||||
Tcl_Obj *pScript = 0;
|
||||
Tcl_Obj *pParam = 0;
|
||||
Tcl_Obj *pCoord = 0;
|
||||
int ii;
|
||||
Tcl_Obj *pRes;
|
||||
|
||||
|
||||
pScript = Tcl_DuplicateObj(pCtx->pScript);
|
||||
Tcl_IncrRefCount(pScript);
|
||||
Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj(zName,-1));
|
||||
|
||||
sqlite3_snprintf(sizeof(aPtr)-1, aPtr, "%p", (void*)p->pContext);
|
||||
Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj(aPtr,-1));
|
||||
|
||||
pParam = Tcl_NewObj();
|
||||
for(ii=0; ii<p->nParam; ii++){
|
||||
Tcl_ListObjAppendElement(
|
||||
interp, pParam, Tcl_NewDoubleObj(p->aParam[ii])
|
||||
);
|
||||
}
|
||||
Tcl_ListObjAppendElement(interp, pScript, pParam);
|
||||
|
||||
pCoord = Tcl_NewObj();
|
||||
for(ii=0; ii<nCoord; ii++){
|
||||
Tcl_ListObjAppendElement(interp, pCoord, Tcl_NewDoubleObj(aCoord[ii]));
|
||||
}
|
||||
Tcl_ListObjAppendElement(interp, pScript, pCoord);
|
||||
|
||||
sqlite3_snprintf(sizeof(aPtr)-1, aPtr, "%p", (void*)p);
|
||||
Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj(aPtr,-1));
|
||||
|
||||
rc = Tcl_EvalObjEx(interp, pScript, 0);
|
||||
if( rc!=TCL_OK ){
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
int nObj = 0;
|
||||
Tcl_Obj **aObj = 0;
|
||||
|
||||
pRes = Tcl_GetObjResult(interp);
|
||||
if( Tcl_ListObjGetElements(interp, pRes, &nObj, &aObj) ) return TCL_ERROR;
|
||||
if( nObj>0 ){
|
||||
const char *zCmd = Tcl_GetString(aObj[0]);
|
||||
if( 0==sqlite3_stricmp(zCmd, "zero") ){
|
||||
p->aParam[0] = 0.0;
|
||||
p->nParam = 1;
|
||||
}
|
||||
else if( 0==sqlite3_stricmp(zCmd, "user") ){
|
||||
if( p->pUser || p->xDelUser ){
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
BoxGeomCtx *pBGCtx = sqlite3_malloc(sizeof(BoxGeomCtx));
|
||||
if( pBGCtx==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
pBGCtx->interp = interp;
|
||||
pBGCtx->pScript = Tcl_DuplicateObj(pRes);
|
||||
Tcl_IncrRefCount(pBGCtx->pScript);
|
||||
Tcl_ListObjReplace(interp, pBGCtx->pScript, 0, 1, 0, 0);
|
||||
p->pUser = (void*)pBGCtx;
|
||||
p->xDelUser = testDelUser;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( 0==sqlite3_stricmp(zCmd, "user_is_zero") ){
|
||||
if( p->pUser || p->xDelUser ) rc = SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
# EVIDENCE-OF: R-00693-36727 The legacy xGeom callback is invoked with
|
||||
# four arguments.
|
||||
|
||||
# EVIDENCE-OF: R-50437-53270 The first argument is a pointer to an
|
||||
# sqlite3_rtree_geometry structure which provides information about how
|
||||
# the SQL function was invoked.
|
||||
|
||||
# EVIDENCE-OF: R-00090-24248 The third argument, aCoord[], is an array
|
||||
# of nCoord coordinates that defines a bounding box to be tested.
|
||||
|
||||
# EVIDENCE-OF: R-28207-40885 The last argument is a pointer into which
|
||||
# the callback result should be written.
|
||||
|
||||
*/
|
||||
static int box_geom(
|
||||
sqlite3_rtree_geometry *p, /* R-50437-53270 */
|
||||
int nCoord, /* R-02424-24769 */
|
||||
sqlite3_rtree_dbl *aCoord, /* R-00090-24248 */
|
||||
int *pRes /* R-28207-40885 */
|
||||
){
|
||||
int ii;
|
||||
|
||||
if( p->nParam!=nCoord ){
|
||||
invokeTclGeomCb("box", p, nCoord, aCoord);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
if( invokeTclGeomCb("box", p, nCoord, aCoord) ) return SQLITE_ERROR;
|
||||
|
||||
for(ii=0; ii<nCoord; ii+=2){
|
||||
if( aCoord[ii]>p->aParam[ii+1] || aCoord[ii+1]<p->aParam[ii] ){
|
||||
/* R-28207-40885 */
|
||||
*pRes = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* R-28207-40885 */
|
||||
*pRes = 1;
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int SQLITE_TCLAPI register_box_geom(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
|
||||
extern const char *sqlite3ErrName(int);
|
||||
sqlite3 *db;
|
||||
BoxGeomCtx *pCtx;
|
||||
char aPtr[64];
|
||||
|
||||
if( objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "DB SCRIPT");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
|
||||
pCtx = (BoxGeomCtx*)ckalloc(sizeof(BoxGeomCtx*));
|
||||
pCtx->interp = interp;
|
||||
pCtx->pScript = Tcl_DuplicateObj(objv[2]);
|
||||
Tcl_IncrRefCount(pCtx->pScript);
|
||||
|
||||
sqlite3_rtree_geometry_callback(db, "box", box_geom, (void*)pCtx);
|
||||
|
||||
sqlite3_snprintf(64, aPtr, "%p", (void*)pCtx);
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj(aPtr, -1));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
static int box_query(sqlite3_rtree_query_info *pInfo){
|
||||
const char *azParentWithin[] = {"not", "partly", "fully", 0};
|
||||
BoxQueryCtx *pCtx = (BoxQueryCtx*)pInfo->pContext;
|
||||
Tcl_Interp *interp = pCtx->interp;
|
||||
Tcl_Obj *pEval;
|
||||
Tcl_Obj *pArg;
|
||||
Tcl_Obj *pTmp = 0;
|
||||
int rc;
|
||||
int ii;
|
||||
|
||||
pEval = Tcl_DuplicateObj(pCtx->pScript);
|
||||
Tcl_IncrRefCount(pEval);
|
||||
pArg = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pArg);
|
||||
|
||||
/* aParam[] */
|
||||
pTmp = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pTmp);
|
||||
for(ii=0; ii<pInfo->nParam; ii++){
|
||||
Tcl_Obj *p = Tcl_NewDoubleObj(pInfo->aParam[ii]);
|
||||
Tcl_ListObjAppendElement(interp, pTmp, p);
|
||||
}
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("aParam", -1));
|
||||
Tcl_ListObjAppendElement(interp, pArg, pTmp);
|
||||
Tcl_DecrRefCount(pTmp);
|
||||
|
||||
/* aCoord[] */
|
||||
pTmp = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pTmp);
|
||||
for(ii=0; ii<pInfo->nCoord; ii++){
|
||||
Tcl_Obj *p = Tcl_NewDoubleObj(pInfo->aCoord[ii]);
|
||||
Tcl_ListObjAppendElement(interp, pTmp, p);
|
||||
}
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("aCoord", -1));
|
||||
Tcl_ListObjAppendElement(interp, pArg, pTmp);
|
||||
Tcl_DecrRefCount(pTmp);
|
||||
|
||||
/* anQueue[] */
|
||||
pTmp = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pTmp);
|
||||
for(ii=0; ii<=pInfo->mxLevel; ii++){
|
||||
Tcl_Obj *p = Tcl_NewIntObj((int)pInfo->anQueue[ii]);
|
||||
Tcl_ListObjAppendElement(interp, pTmp, p);
|
||||
}
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("anQueue", -1));
|
||||
Tcl_ListObjAppendElement(interp, pArg, pTmp);
|
||||
Tcl_DecrRefCount(pTmp);
|
||||
|
||||
/* iLevel */
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("iLevel", -1));
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewIntObj(pInfo->iLevel));
|
||||
|
||||
/* mxLevel */
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("mxLevel", -1));
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewIntObj(pInfo->mxLevel));
|
||||
|
||||
/* iRowid */
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("iRowid", -1));
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewWideIntObj(pInfo->iRowid));
|
||||
|
||||
/* rParentScore */
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("rParentScore", -1));
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewDoubleObj(pInfo->rParentScore));
|
||||
|
||||
/* eParentWithin */
|
||||
assert( pInfo->eParentWithin==0
|
||||
|| pInfo->eParentWithin==1
|
||||
|| pInfo->eParentWithin==2
|
||||
);
|
||||
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("eParentWithin", -1));
|
||||
Tcl_ListObjAppendElement(interp, pArg,
|
||||
Tcl_NewStringObj(azParentWithin[pInfo->eParentWithin], -1)
|
||||
);
|
||||
|
||||
Tcl_ListObjAppendElement(interp, pEval, pArg);
|
||||
rc = Tcl_EvalObjEx(interp, pEval, 0) ? SQLITE_ERROR : SQLITE_OK;
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
double rScore = 0.0;
|
||||
int nObj = 0;
|
||||
int eP = 0;
|
||||
Tcl_Obj **aObj = 0;
|
||||
Tcl_Obj *pRes = Tcl_GetObjResult(interp);
|
||||
|
||||
if( Tcl_ListObjGetElements(interp, pRes, &nObj, &aObj)
|
||||
|| nObj!=2
|
||||
|| Tcl_GetDoubleFromObj(interp, aObj[1], &rScore)
|
||||
|| Tcl_GetIndexFromObj(interp, aObj[0], azParentWithin, "value", 0, &eP)
|
||||
){
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
pInfo->rScore = rScore;
|
||||
pInfo->eParentWithin = eP;
|
||||
}
|
||||
}
|
||||
|
||||
Tcl_DecrRefCount(pArg);
|
||||
Tcl_DecrRefCount(pEval);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void box_query_destroy(void *p){
|
||||
BoxQueryCtx *pCtx = (BoxQueryCtx*)p;
|
||||
Tcl_DecrRefCount(pCtx->pScript);
|
||||
ckfree((char*)pCtx);
|
||||
}
|
||||
|
||||
static int SQLITE_TCLAPI register_box_query(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
|
||||
extern const char *sqlite3ErrName(int);
|
||||
sqlite3 *db;
|
||||
BoxQueryCtx *pCtx;
|
||||
|
||||
if( objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "DB SCRIPT");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
|
||||
pCtx = (BoxQueryCtx*)ckalloc(sizeof(BoxQueryCtx));
|
||||
pCtx->interp = interp;
|
||||
pCtx->pScript = Tcl_DuplicateObj(objv[2]);
|
||||
Tcl_IncrRefCount(pCtx->pScript);
|
||||
|
||||
sqlite3_rtree_query_callback(
|
||||
db, "qbox", box_query, (void*)pCtx, box_query_destroy
|
||||
);
|
||||
|
||||
Tcl_ResetResult(interp);
|
||||
return TCL_OK;
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_RTREE */
|
||||
|
||||
|
||||
int Sqlitetestrtreedoc_Init(Tcl_Interp *interp){
|
||||
#ifdef SQLITE_ENABLE_RTREE
|
||||
Tcl_CreateObjCommand(interp, "register_box_geom", register_box_geom, 0, 0);
|
||||
Tcl_CreateObjCommand(interp, "register_box_query", register_box_query, 0, 0);
|
||||
#endif /* SQLITE_ENABLE_RTREE */
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -19,7 +19,6 @@ if {![info exists testdir]} {
|
||||
source [file join [file dirname [info script]] session_common.tcl]
|
||||
source $testdir/tester.tcl
|
||||
ifcapable !session {finish_test; return}
|
||||
ifcapable !incrblob {finish_test; return}
|
||||
|
||||
set testprefix session6
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ proc do_then_undo {tn sql} {
|
||||
do_execsql_test 1.1 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b);
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
INSERT INTO t1 VALUES('abc', 'xyz');
|
||||
INSERT INTO t1 VALUES("abc", "xyz");
|
||||
}
|
||||
do_then_undo 1.2 { INSERT INTO t1 VALUES(3, 4); }
|
||||
do_then_undo 1.3 { DELETE FROM t1 WHERE b=2; }
|
||||
|
||||
@@ -20,13 +20,8 @@ if {![info exists testdir]} {
|
||||
source [file join [file dirname [info script]] session_common.tcl]
|
||||
source $testdir/tester.tcl
|
||||
ifcapable !session {finish_test; return}
|
||||
set testprefix sessionat
|
||||
|
||||
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
|
||||
ifcapable !altertable {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
set testprefix sessionat
|
||||
|
||||
db close
|
||||
sqlite3_shutdown
|
||||
|
||||
@@ -420,7 +420,7 @@ static int sessionSerializeValue(
|
||||
|
||||
if( aBuf ){
|
||||
sessionVarintPut(&aBuf[1], n);
|
||||
if( n>0 ) memcpy(&aBuf[nVarint + 1], z, n);
|
||||
if( n ) memcpy(&aBuf[nVarint + 1], z, n);
|
||||
}
|
||||
|
||||
nByte = 1 + nVarint + n;
|
||||
@@ -1025,32 +1025,16 @@ static int sessionTableInfo(
|
||||
}else if( rc==SQLITE_ERROR ){
|
||||
zPragma = sqlite3_mprintf("");
|
||||
}else{
|
||||
*pazCol = 0;
|
||||
*pabPK = 0;
|
||||
*pnCol = 0;
|
||||
if( pzTab ) *pzTab = 0;
|
||||
return rc;
|
||||
}
|
||||
}else{
|
||||
zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
|
||||
}
|
||||
if( !zPragma ){
|
||||
*pazCol = 0;
|
||||
*pabPK = 0;
|
||||
*pnCol = 0;
|
||||
if( pzTab ) *pzTab = 0;
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
if( !zPragma ) return SQLITE_NOMEM;
|
||||
|
||||
rc = sqlite3_prepare_v2(db, zPragma, -1, &pStmt, 0);
|
||||
sqlite3_free(zPragma);
|
||||
if( rc!=SQLITE_OK ){
|
||||
*pazCol = 0;
|
||||
*pabPK = 0;
|
||||
*pnCol = 0;
|
||||
if( pzTab ) *pzTab = 0;
|
||||
return rc;
|
||||
}
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
nByte = nThis + 1;
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
@@ -1468,11 +1452,7 @@ static int sessionFindTable(
|
||||
){
|
||||
rc = sqlite3session_attach(pSession, zName);
|
||||
if( rc==SQLITE_OK ){
|
||||
pRet = pSession->pTable;
|
||||
while( ALWAYS(pRet) && pRet->pNext ){
|
||||
pRet = pRet->pNext;
|
||||
}
|
||||
assert( pRet!=0 );
|
||||
for(pRet=pSession->pTable; pRet->pNext; pRet=pRet->pNext);
|
||||
assert( 0==sqlite3_strnicmp(pRet->zName, zName, nName+1) );
|
||||
}
|
||||
}
|
||||
@@ -2245,7 +2225,6 @@ static int sessionAppendUpdate(
|
||||
int i; /* Used to iterate through columns */
|
||||
u8 *pCsr = p->aRecord; /* Used to iterate through old.* values */
|
||||
|
||||
assert( abPK!=0 );
|
||||
sessionAppendByte(pBuf, SQLITE_UPDATE, &rc);
|
||||
sessionAppendByte(pBuf, p->bIndirect, &rc);
|
||||
for(i=0; i<sqlite3_column_count(pStmt); i++){
|
||||
@@ -2550,14 +2529,12 @@ static int sessionGenerateChangeset(
|
||||
SessionBuffer buf = {0,0,0}; /* Buffer in which to accumlate changeset */
|
||||
int rc; /* Return code */
|
||||
|
||||
assert( xOutput==0 || (pnChangeset==0 && ppChangeset==0) );
|
||||
assert( xOutput!=0 || (pnChangeset!=0 && ppChangeset!=0) );
|
||||
assert( xOutput==0 || (pnChangeset==0 && ppChangeset==0 ) );
|
||||
|
||||
/* Zero the output variables in case an error occurs. If this session
|
||||
** object is already in the error state (sqlite3_session.rc != SQLITE_OK),
|
||||
** this call will be a no-op. */
|
||||
if( xOutput==0 ){
|
||||
assert( pnChangeset!=0 && ppChangeset!=0 );
|
||||
*pnChangeset = 0;
|
||||
*ppChangeset = 0;
|
||||
}
|
||||
@@ -2571,8 +2548,8 @@ static int sessionGenerateChangeset(
|
||||
for(pTab=pSession->pTable; rc==SQLITE_OK && pTab; pTab=pTab->pNext){
|
||||
if( pTab->nEntry ){
|
||||
const char *zName = pTab->zName;
|
||||
int nCol = 0; /* Number of columns in table */
|
||||
u8 *abPK = 0; /* Primary key array */
|
||||
int nCol; /* Number of columns in table */
|
||||
u8 *abPK; /* Primary key array */
|
||||
const char **azCol = 0; /* Table columns */
|
||||
int i; /* Used to iterate through hash buckets */
|
||||
sqlite3_stmt *pSel = 0; /* SELECT statement to query table pTab */
|
||||
@@ -2610,7 +2587,6 @@ static int sessionGenerateChangeset(
|
||||
sessionAppendCol(&buf, pSel, iCol, &rc);
|
||||
}
|
||||
}else{
|
||||
assert( abPK!=0 ); /* Because sessionSelectStmt() returned ok */
|
||||
rc = sessionAppendUpdate(&buf, bPatchset, pSel, p, abPK);
|
||||
}
|
||||
}else if( p->op!=SQLITE_INSERT ){
|
||||
@@ -2671,10 +2647,7 @@ int sqlite3session_changeset(
|
||||
int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
|
||||
void **ppChangeset /* OUT: Buffer containing changeset */
|
||||
){
|
||||
int rc;
|
||||
|
||||
if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE;
|
||||
rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset);
|
||||
int rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset);
|
||||
assert( rc || pnChangeset==0
|
||||
|| pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
|
||||
);
|
||||
@@ -2689,7 +2662,6 @@ int sqlite3session_changeset_strm(
|
||||
int (*xOutput)(void *pOut, const void *pData, int nData),
|
||||
void *pOut
|
||||
){
|
||||
if( xOutput==0 ) return SQLITE_MISUSE;
|
||||
return sessionGenerateChangeset(pSession, 0, xOutput, pOut, 0, 0);
|
||||
}
|
||||
|
||||
@@ -2701,7 +2673,6 @@ int sqlite3session_patchset_strm(
|
||||
int (*xOutput)(void *pOut, const void *pData, int nData),
|
||||
void *pOut
|
||||
){
|
||||
if( xOutput==0 ) return SQLITE_MISUSE;
|
||||
return sessionGenerateChangeset(pSession, 1, xOutput, pOut, 0, 0);
|
||||
}
|
||||
|
||||
@@ -2717,7 +2688,6 @@ int sqlite3session_patchset(
|
||||
int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
|
||||
void **ppPatchset /* OUT: Buffer containing changeset */
|
||||
){
|
||||
if( pnPatchset==0 || ppPatchset==0 ) return SQLITE_MISUSE;
|
||||
return sessionGenerateChangeset(pSession, 1, 0, 0, pnPatchset, ppPatchset);
|
||||
}
|
||||
|
||||
@@ -3681,11 +3651,11 @@ static int sessionChangesetInvert(
|
||||
}
|
||||
|
||||
assert( rc==SQLITE_OK );
|
||||
if( pnInverted && ALWAYS(ppInverted) ){
|
||||
if( pnInverted ){
|
||||
*pnInverted = sOut.nBuf;
|
||||
*ppInverted = sOut.aBuf;
|
||||
sOut.aBuf = 0;
|
||||
}else if( sOut.nBuf>0 && ALWAYS(xOutput!=0) ){
|
||||
}else if( sOut.nBuf>0 ){
|
||||
rc = xOutput(pOut, sOut.aBuf, sOut.nBuf);
|
||||
}
|
||||
|
||||
@@ -4141,7 +4111,7 @@ static int sessionBindRow(
|
||||
|
||||
for(i=0; rc==SQLITE_OK && i<nCol; i++){
|
||||
if( !abPK || abPK[i] ){
|
||||
sqlite3_value *pVal = 0;
|
||||
sqlite3_value *pVal;
|
||||
(void)xValue(pIter, i, &pVal);
|
||||
if( pVal==0 ){
|
||||
/* The value in the changeset was "undefined". This indicates a
|
||||
@@ -5284,9 +5254,9 @@ static int sessionChangegroupOutput(
|
||||
if( rc==SQLITE_OK ){
|
||||
if( xOutput ){
|
||||
if( buf.nBuf>0 ) rc = xOutput(pOut, buf.aBuf, buf.nBuf);
|
||||
}else if( ppOut ){
|
||||
}else{
|
||||
*ppOut = buf.aBuf;
|
||||
if( pnOut ) *pnOut = buf.nBuf;
|
||||
*pnOut = buf.nBuf;
|
||||
buf.aBuf = 0;
|
||||
}
|
||||
}
|
||||
@@ -5686,7 +5656,7 @@ static int sessionRebase(
|
||||
if( sOut.nBuf>0 ){
|
||||
rc = xOutput(pOut, sOut.aBuf, sOut.nBuf);
|
||||
}
|
||||
}else if( ppOut ){
|
||||
}else{
|
||||
*ppOut = (void*)sOut.aBuf;
|
||||
*pnOut = sOut.nBuf;
|
||||
sOut.aBuf = 0;
|
||||
|
||||
@@ -64,7 +64,7 @@ LIBOBJ+= vdbe.o parse.o \
|
||||
fts3_tokenize_vtab.o \
|
||||
fts3_unicode.o fts3_unicode2.o \
|
||||
fts3_write.o fts5.o func.o global.o hash.o \
|
||||
icu.o insert.o json.o legacy.o loadext.o \
|
||||
icu.o insert.o json1.o legacy.o loadext.o \
|
||||
main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.o \
|
||||
memdb.o memjournal.o \
|
||||
mutex.o mutex_noop.o mutex_unix.o mutex_w32.o \
|
||||
@@ -111,7 +111,6 @@ SRC = \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/hwtime.h \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/json.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/loadext.c \
|
||||
$(TOP)/src/main.c \
|
||||
@@ -245,6 +244,7 @@ SRC += \
|
||||
$(TOP)/ext/rbu/sqlite3rbu.c \
|
||||
$(TOP)/ext/rbu/sqlite3rbu.h
|
||||
SRC += \
|
||||
$(TOP)/ext/misc/json1.c \
|
||||
$(TOP)/ext/misc/stmt.c
|
||||
|
||||
|
||||
@@ -377,7 +377,6 @@ TESTSRC += \
|
||||
$(TOP)/ext/misc/normalize.c \
|
||||
$(TOP)/ext/misc/percentile.c \
|
||||
$(TOP)/ext/misc/prefixes.c \
|
||||
$(TOP)/ext/misc/qpvtab.c \
|
||||
$(TOP)/ext/misc/regexp.c \
|
||||
$(TOP)/ext/misc/remember.c \
|
||||
$(TOP)/ext/misc/series.c \
|
||||
@@ -388,8 +387,7 @@ TESTSRC += \
|
||||
$(TOP)/ext/misc/zipfile.c \
|
||||
$(TOP)/ext/fts5/fts5_tcl.c \
|
||||
$(TOP)/ext/fts5/fts5_test_mi.c \
|
||||
$(TOP)/ext/fts5/fts5_test_tok.c \
|
||||
$(TOP)/ext/rtree/test_rtreedoc.c
|
||||
$(TOP)/ext/fts5/fts5_test_tok.c
|
||||
|
||||
|
||||
#TESTSRC += $(TOP)/ext/fts2/fts2_tokenizer.c
|
||||
@@ -529,7 +527,7 @@ TESTOPTS = --verbose=file --output=test-out.txt
|
||||
|
||||
# Extra compiler options for various shell tools
|
||||
#
|
||||
SHELL_OPT += -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5
|
||||
SHELL_OPT += -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5
|
||||
SHELL_OPT += -DSQLITE_ENABLE_RTREE
|
||||
SHELL_OPT += -DSQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
SHELL_OPT += -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
|
||||
@@ -538,7 +536,8 @@ SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
FUZZCHECK_OPT = -DSQLITE_ENABLE_MEMSYS5
|
||||
FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
|
||||
FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5
|
||||
FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
|
||||
FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
|
||||
@@ -678,6 +677,9 @@ sqlite3-all.c: sqlite3.c $(TOP)/tool/split-sqlite3c.tcl
|
||||
fts2amal.c: target_source $(TOP)/ext/fts2/mkfts2amal.tcl
|
||||
tclsh $(TOP)/ext/fts2/mkfts2amal.tcl
|
||||
|
||||
fts3amal.c: target_source $(TOP)/ext/fts3/mkfts3amal.tcl
|
||||
tclsh $(TOP)/ext/fts3/mkfts3amal.tcl
|
||||
|
||||
# Rules to build the LEMON compiler generator
|
||||
#
|
||||
lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
@@ -828,6 +830,9 @@ fts3_write.o: $(TOP)/ext/fts3/fts3_write.c $(HDR) $(EXTHDR)
|
||||
fts5.o: fts5.c sqlite3ext.h sqlite3.h
|
||||
$(TCCX) -DSQLITE_CORE -c fts5.c
|
||||
|
||||
json1.o: $(TOP)/ext/misc/json1.c sqlite3ext.h sqlite3.h
|
||||
$(TCCX) -DSQLITE_CORE -c $(TOP)/ext/misc/json1.c
|
||||
|
||||
stmt.o: $(TOP)/ext/misc/stmt.c sqlite3ext.h sqlite3.h
|
||||
$(TCCX) -DSQLITE_CORE -c $(TOP)/ext/misc/stmt.c
|
||||
|
||||
@@ -925,6 +930,12 @@ amalgamation-testfixture$(EXE): sqlite3.c $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
$(TOP)/ext/session/test_session.c \
|
||||
-o testfixture$(EXE) $(LIBTCL) $(THREADLIB)
|
||||
|
||||
fts3-testfixture$(EXE): sqlite3.c fts3amal.c $(TESTSRC) $(TOP)/src/tclsqlite.c
|
||||
$(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \
|
||||
-DSQLITE_ENABLE_FTS3=1 \
|
||||
$(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c fts3amal.c \
|
||||
-o testfixture$(EXE) $(LIBTCL) $(THREADLIB)
|
||||
|
||||
coretestprogs: $(TESTPROGS)
|
||||
|
||||
testprogs: coretestprogs srcck1$(EXE) fuzzcheck$(EXE) sessionfuzz$(EXE)
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
0c5be14aac07222b9cd2404ae485b6587f8cb2899e776bc45f1f1117bdd7e9b7
|
||||
8498d7727c25859f1a48b85bec44a0b9ad6e8c48112498d6c71882458970c637
|
||||
+112
-159
@@ -60,7 +60,7 @@ static void renameTestSchema(
|
||||
pParse->colNamesSet = 1;
|
||||
sqlite3NestedParse(pParse,
|
||||
"SELECT 1 "
|
||||
"FROM \"%w\"." LEGACY_SCHEMA_TABLE " "
|
||||
"FROM \"%w\"." DFLT_SCHEMA_TABLE " "
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
" AND sql NOT LIKE 'create virtual%%'"
|
||||
" AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %d)=NULL ",
|
||||
@@ -71,7 +71,7 @@ static void renameTestSchema(
|
||||
if( bTemp==0 ){
|
||||
sqlite3NestedParse(pParse,
|
||||
"SELECT 1 "
|
||||
"FROM temp." LEGACY_SCHEMA_TABLE " "
|
||||
"FROM temp." DFLT_SCHEMA_TABLE " "
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
" AND sql NOT LIKE 'create virtual%%'"
|
||||
" AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %d)=NULL ",
|
||||
@@ -89,14 +89,14 @@ static void renameTestSchema(
|
||||
*/
|
||||
static void renameFixQuotes(Parse *pParse, const char *zDb, int bTemp){
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." LEGACY_SCHEMA_TABLE
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE
|
||||
" SET sql = sqlite_rename_quotefix(%Q, sql)"
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
" AND sql NOT LIKE 'create virtual%%'" , zDb, zDb
|
||||
);
|
||||
if( bTemp==0 ){
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE temp." LEGACY_SCHEMA_TABLE
|
||||
"UPDATE temp." DFLT_SCHEMA_TABLE
|
||||
" SET sql = sqlite_rename_quotefix('temp', sql)"
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
" AND sql NOT LIKE 'create virtual%%'"
|
||||
@@ -135,7 +135,9 @@ void sqlite3AlterRenameTable(
|
||||
const char *zTabName; /* Original name of the table */
|
||||
Vdbe *v;
|
||||
VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
|
||||
u32 savedDbFlags; /* Saved value of db->mDbFlags */
|
||||
|
||||
savedDbFlags = db->mDbFlags;
|
||||
if( NEVER(db->mallocFailed) ) goto exit_rename_table;
|
||||
assert( pSrc->nSrc==1 );
|
||||
assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
|
||||
@@ -144,6 +146,7 @@ void sqlite3AlterRenameTable(
|
||||
if( !pTab ) goto exit_rename_table;
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
zDb = db->aDb[iDb].zDbSName;
|
||||
db->mDbFlags |= DBFLAG_PreferBuiltin;
|
||||
|
||||
/* Get a NULL terminated version of the new table name. */
|
||||
zName = sqlite3NameFromToken(db, pName);
|
||||
@@ -172,7 +175,7 @@ void sqlite3AlterRenameTable(
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_VIEW
|
||||
if( IsView(pTab) ){
|
||||
if( pTab->pSelect ){
|
||||
sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);
|
||||
goto exit_rename_table;
|
||||
}
|
||||
@@ -214,7 +217,7 @@ void sqlite3AlterRenameTable(
|
||||
/* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
|
||||
** the schema to use the new table name. */
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET "
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) "
|
||||
"WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)"
|
||||
"AND name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
@@ -224,7 +227,7 @@ void sqlite3AlterRenameTable(
|
||||
/* Update the tbl_name and name columns of the sqlite_schema table
|
||||
** as required. */
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE %Q." LEGACY_SCHEMA_TABLE " SET "
|
||||
"UPDATE %Q." DFLT_SCHEMA_TABLE " SET "
|
||||
"tbl_name = %Q, "
|
||||
"name = CASE "
|
||||
"WHEN type='table' THEN %Q "
|
||||
@@ -284,6 +287,7 @@ void sqlite3AlterRenameTable(
|
||||
exit_rename_table:
|
||||
sqlite3SrcListDelete(db, pSrc);
|
||||
sqlite3DbFree(db, zName);
|
||||
db->mDbFlags = savedDbFlags;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -324,9 +328,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
int r1; /* Temporary registers */
|
||||
|
||||
db = pParse->db;
|
||||
assert( db->pParse==pParse );
|
||||
if( pParse->nErr ) return;
|
||||
assert( db->mallocFailed==0 );
|
||||
if( pParse->nErr || db->mallocFailed ) return;
|
||||
pNew = pParse->pNewTable;
|
||||
assert( pNew );
|
||||
|
||||
@@ -335,7 +337,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
zDb = db->aDb[iDb].zDbSName;
|
||||
zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */
|
||||
pCol = &pNew->aCol[pNew->nCol-1];
|
||||
pDflt = sqlite3ColumnExpr(pNew, pCol);
|
||||
pDflt = pCol->pDflt;
|
||||
pTab = sqlite3FindTable(db, zTab, zDb);
|
||||
assert( pTab );
|
||||
|
||||
@@ -369,8 +371,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
if( pDflt && pDflt->pLeft->op==TK_NULL ){
|
||||
pDflt = 0;
|
||||
}
|
||||
assert( IsOrdinaryTable(pNew) );
|
||||
if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){
|
||||
if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
|
||||
sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
|
||||
"Cannot add a REFERENCES column with non-NULL default value");
|
||||
}
|
||||
@@ -407,22 +408,23 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
|
||||
if( zCol ){
|
||||
char *zEnd = &zCol[pColDef->n-1];
|
||||
u32 savedDbFlags = db->mDbFlags;
|
||||
while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
|
||||
*zEnd-- = '\0';
|
||||
}
|
||||
db->mDbFlags |= DBFLAG_PreferBuiltin;
|
||||
/* substr() operations on characters, but addColOffset is in bytes. So we
|
||||
** have to use printf() to translate between these units: */
|
||||
assert( IsOrdinaryTable(pTab) );
|
||||
assert( IsOrdinaryTable(pNew) );
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET "
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = printf('%%.%ds, ',sql) || %Q"
|
||||
" || substr(sql,1+length(printf('%%.%ds',sql))) "
|
||||
"WHERE type = 'table' AND name = %Q",
|
||||
zDb, pNew->u.tab.addColOffset, zCol, pNew->u.tab.addColOffset,
|
||||
zDb, pNew->addColOffset, zCol, pNew->addColOffset,
|
||||
zTab
|
||||
);
|
||||
sqlite3DbFree(db, zCol);
|
||||
db->mDbFlags = savedDbFlags;
|
||||
}
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
@@ -441,7 +443,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
sqlite3ReleaseTempReg(pParse, r1);
|
||||
|
||||
/* Reload the table definition */
|
||||
renameReloadSchema(pParse, iDb, INITFLAG_AlterAdd);
|
||||
renameReloadSchema(pParse, iDb, INITFLAG_AlterRename);
|
||||
|
||||
/* Verify that constraints are still satisfied */
|
||||
if( pNew->pCheck!=0
|
||||
@@ -452,7 +454,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
" THEN raise(ABORT,'CHECK constraint failed')"
|
||||
" ELSE raise(ABORT,'NOT NULL constraint failed')"
|
||||
" END"
|
||||
" FROM pragma_quick_check(%Q,%Q)"
|
||||
" FROM pragma_quick_check(\"%w\",\"%w\")"
|
||||
" WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'",
|
||||
zTab, zDb
|
||||
);
|
||||
@@ -498,7 +500,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
#endif
|
||||
|
||||
/* Make sure this is not an attempt to ALTER a view. */
|
||||
if( IsView(pTab) ){
|
||||
if( pTab->pSelect ){
|
||||
sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
|
||||
goto exit_begin_add_column;
|
||||
}
|
||||
@@ -507,8 +509,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
}
|
||||
|
||||
sqlite3MayAbort(pParse);
|
||||
assert( IsOrdinaryTable(pTab) );
|
||||
assert( pTab->u.tab.addColOffset>0 );
|
||||
assert( pTab->addColOffset>0 );
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
|
||||
/* Put a copy of the Table struct in Parse.pNewTable for the
|
||||
@@ -535,13 +536,13 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
|
||||
for(i=0; i<pNew->nCol; i++){
|
||||
Column *pCol = &pNew->aCol[i];
|
||||
pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName);
|
||||
pCol->hName = sqlite3StrIHash(pCol->zCnName);
|
||||
pCol->zName = sqlite3DbStrDup(db, pCol->zName);
|
||||
pCol->hName = sqlite3StrIHash(pCol->zName);
|
||||
pCol->zColl = 0;
|
||||
pCol->pDflt = 0;
|
||||
}
|
||||
assert( IsOrdinaryTable(pNew) );
|
||||
pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
|
||||
pNew->pSchema = db->aDb[iDb].pSchema;
|
||||
pNew->u.tab.addColOffset = pTab->u.tab.addColOffset;
|
||||
pNew->addColOffset = pTab->addColOffset;
|
||||
pNew->nTabRef = 1;
|
||||
|
||||
exit_begin_add_column:
|
||||
@@ -561,7 +562,7 @@ exit_begin_add_column:
|
||||
static int isRealTable(Parse *pParse, Table *pTab, int bDrop){
|
||||
const char *zType = 0;
|
||||
#ifndef SQLITE_OMIT_VIEW
|
||||
if( IsView(pTab) ){
|
||||
if( pTab->pSelect ){
|
||||
zType = "view";
|
||||
}
|
||||
#endif
|
||||
@@ -628,10 +629,10 @@ void sqlite3AlterRenameColumn(
|
||||
zOld = sqlite3NameFromToken(db, pOld);
|
||||
if( !zOld ) goto exit_rename_column;
|
||||
for(iCol=0; iCol<pTab->nCol; iCol++){
|
||||
if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break;
|
||||
if( 0==sqlite3StrICmp(pTab->aCol[iCol].zName, zOld) ) break;
|
||||
}
|
||||
if( iCol==pTab->nCol ){
|
||||
sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld);
|
||||
sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
|
||||
goto exit_rename_column;
|
||||
}
|
||||
|
||||
@@ -649,17 +650,18 @@ void sqlite3AlterRenameColumn(
|
||||
assert( pNew->n>0 );
|
||||
bQuote = sqlite3Isquote(pNew->z[0]);
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET "
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' "
|
||||
" AND (type != 'index' OR tbl_name = %Q)",
|
||||
" AND (type != 'index' OR tbl_name = %Q)"
|
||||
" AND sql NOT LIKE 'create virtual%%'",
|
||||
zDb,
|
||||
zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1,
|
||||
pTab->zName
|
||||
);
|
||||
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE temp." LEGACY_SCHEMA_TABLE " SET "
|
||||
"UPDATE temp." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) "
|
||||
"WHERE type IN ('trigger', 'view')",
|
||||
zDb, pTab->zName, iCol, zNew, bQuote
|
||||
@@ -694,7 +696,7 @@ void sqlite3AlterRenameColumn(
|
||||
** the parse tree.
|
||||
*/
|
||||
struct RenameToken {
|
||||
const void *p; /* Parse tree element created by token t */
|
||||
void *p; /* Parse tree element created by token t */
|
||||
Token t; /* The token that created parse tree element p */
|
||||
RenameToken *pNext; /* Next is a list of all RenameToken objects */
|
||||
};
|
||||
@@ -736,11 +738,9 @@ struct RenameCtx {
|
||||
** Technically, as x no longer points into a valid object or to the byte
|
||||
** following a valid object, it may not be used in comparison operations.
|
||||
*/
|
||||
static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
|
||||
assert( pParse==pParse->db->pParse );
|
||||
assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
|
||||
if( pParse->nErr==0 ){
|
||||
const RenameToken *p;
|
||||
static void renameTokenCheckAll(Parse *pParse, void *pPtr){
|
||||
if( pParse->nErr==0 && pParse->db->mallocFailed==0 ){
|
||||
RenameToken *p;
|
||||
u8 i = 0;
|
||||
for(p=pParse->pRename; p; p=p->pNext){
|
||||
if( p->p ){
|
||||
@@ -766,11 +766,7 @@ static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
|
||||
** with tail recursion in tokenExpr() routine, for a small performance
|
||||
** improvement.
|
||||
*/
|
||||
const void *sqlite3RenameTokenMap(
|
||||
Parse *pParse,
|
||||
const void *pPtr,
|
||||
const Token *pToken
|
||||
){
|
||||
void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){
|
||||
RenameToken *pNew;
|
||||
assert( pPtr || pParse->db->mallocFailed );
|
||||
renameTokenCheckAll(pParse, pPtr);
|
||||
@@ -792,7 +788,7 @@ const void *sqlite3RenameTokenMap(
|
||||
** with parse tree element pFrom. This function remaps the associated token
|
||||
** to parse tree element pTo.
|
||||
*/
|
||||
void sqlite3RenameTokenRemap(Parse *pParse, const void *pTo, const void *pFrom){
|
||||
void sqlite3RenameTokenRemap(Parse *pParse, void *pTo, void *pFrom){
|
||||
RenameToken *p;
|
||||
renameTokenCheckAll(pParse, pTo);
|
||||
for(p=pParse->pRename; p; p=p->pNext){
|
||||
@@ -808,10 +804,7 @@ void sqlite3RenameTokenRemap(Parse *pParse, const void *pTo, const void *pFrom){
|
||||
*/
|
||||
static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
|
||||
Parse *pParse = pWalker->pParse;
|
||||
sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr);
|
||||
if( ExprUseYTab(pExpr) ){
|
||||
sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
|
||||
}
|
||||
sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
|
||||
return WRC_Continue;
|
||||
}
|
||||
|
||||
@@ -841,7 +834,6 @@ static void renameWalkWith(Walker *pWalker, Select *pSelect){
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pParse;
|
||||
if( pCopy ) sqlite3SelectPrep(sNC.pParse, p, &sNC);
|
||||
if( sNC.pParse->db->mallocFailed ) return;
|
||||
sqlite3WalkSelect(pWalker, p);
|
||||
sqlite3RenameExprlistUnmap(pParse, pWith->a[i].pCols);
|
||||
}
|
||||
@@ -856,12 +848,12 @@ static void renameWalkWith(Walker *pWalker, Select *pSelect){
|
||||
*/
|
||||
static void unmapColumnIdlistNames(
|
||||
Parse *pParse,
|
||||
const IdList *pIdList
|
||||
IdList *pIdList
|
||||
){
|
||||
if( pIdList ){
|
||||
int ii;
|
||||
for(ii=0; ii<pIdList->nId; ii++){
|
||||
sqlite3RenameTokenRemap(pParse, 0, (const void*)pIdList->a[ii].zName);
|
||||
sqlite3RenameTokenRemap(pParse, 0, (void*)pIdList->a[ii].zName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -873,9 +865,9 @@ static int renameUnmapSelectCb(Walker *pWalker, Select *p){
|
||||
Parse *pParse = pWalker->pParse;
|
||||
int i;
|
||||
if( pParse->nErr ) return WRC_Abort;
|
||||
testcase( p->selFlags & SF_View );
|
||||
testcase( p->selFlags & SF_CopyCte );
|
||||
if( p->selFlags & (SF_View|SF_CopyCte) ){
|
||||
testcase( p->selFlags & SF_View );
|
||||
testcase( p->selFlags & SF_CopyCte );
|
||||
return WRC_Prune;
|
||||
}
|
||||
if( ALWAYS(p->pEList) ){
|
||||
@@ -890,7 +882,7 @@ static int renameUnmapSelectCb(Walker *pWalker, Select *p){
|
||||
SrcList *pSrc = p->pSrc;
|
||||
for(i=0; i<pSrc->nSrc; i++){
|
||||
sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
|
||||
sqlite3WalkExpr(pWalker, pSrc->a[i].pOn);
|
||||
if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort;
|
||||
unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing);
|
||||
}
|
||||
}
|
||||
@@ -958,7 +950,7 @@ static void renameTokenFree(sqlite3 *db, RenameToken *pToken){
|
||||
static RenameToken *renameTokenFind(
|
||||
Parse *pParse,
|
||||
struct RenameCtx *pCtx,
|
||||
const void *pPtr
|
||||
void *pPtr
|
||||
){
|
||||
RenameToken **pp;
|
||||
if( NEVER(pPtr==0) ){
|
||||
@@ -1011,8 +1003,7 @@ static int renameColumnExprCb(Walker *pWalker, Expr *pExpr){
|
||||
){
|
||||
renameTokenFind(pWalker->pParse, p, (void*)pExpr);
|
||||
}else if( pExpr->op==TK_COLUMN
|
||||
&& pExpr->iColumn==p->iCol
|
||||
&& ALWAYS(ExprUseYTab(pExpr))
|
||||
&& pExpr->iColumn==p->iCol
|
||||
&& p->pTab==pExpr->y.pTab
|
||||
){
|
||||
renameTokenFind(pWalker->pParse, p, (void*)pExpr);
|
||||
@@ -1061,12 +1052,12 @@ static void renameColumnParseError(
|
||||
const char *zN = (const char*)sqlite3_value_text(pObject);
|
||||
char *zErr;
|
||||
|
||||
zErr = sqlite3MPrintf(pParse->db, "error in %s %s%s%s: %s",
|
||||
zErr = sqlite3_mprintf("error in %s %s%s%s: %s",
|
||||
zT, zN, (zWhen[0] ? " " : ""), zWhen,
|
||||
pParse->zErrMsg
|
||||
);
|
||||
sqlite3_result_error(pCtx, zErr, -1);
|
||||
sqlite3DbFree(pParse->db, zErr);
|
||||
sqlite3_free(zErr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1078,18 +1069,18 @@ static void renameColumnParseError(
|
||||
static void renameColumnElistNames(
|
||||
Parse *pParse,
|
||||
RenameCtx *pCtx,
|
||||
const ExprList *pEList,
|
||||
ExprList *pEList,
|
||||
const char *zOld
|
||||
){
|
||||
if( pEList ){
|
||||
int i;
|
||||
for(i=0; i<pEList->nExpr; i++){
|
||||
const char *zName = pEList->a[i].zEName;
|
||||
char *zName = pEList->a[i].zEName;
|
||||
if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
|
||||
&& ALWAYS(zName!=0)
|
||||
&& 0==sqlite3_stricmp(zName, zOld)
|
||||
){
|
||||
renameTokenFind(pParse, pCtx, (const void*)zName);
|
||||
renameTokenFind(pParse, pCtx, (void*)zName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1103,15 +1094,15 @@ static void renameColumnElistNames(
|
||||
static void renameColumnIdlistNames(
|
||||
Parse *pParse,
|
||||
RenameCtx *pCtx,
|
||||
const IdList *pIdList,
|
||||
IdList *pIdList,
|
||||
const char *zOld
|
||||
){
|
||||
if( pIdList ){
|
||||
int i;
|
||||
for(i=0; i<pIdList->nId; i++){
|
||||
const char *zName = pIdList->a[i].zName;
|
||||
char *zName = pIdList->a[i].zName;
|
||||
if( 0==sqlite3_stricmp(zName, zOld) ){
|
||||
renameTokenFind(pParse, pCtx, (const void*)zName);
|
||||
renameTokenFind(pParse, pCtx, (void*)zName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1130,22 +1121,24 @@ static int renameParseSql(
|
||||
int bTemp /* True if SQL is from temp schema */
|
||||
){
|
||||
int rc;
|
||||
char *zErr = 0;
|
||||
|
||||
sqlite3ParseObjectInit(p, db);
|
||||
if( zSql==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
if( sqlite3StrNICmp(zSql,"CREATE ",7)!=0 ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
|
||||
|
||||
/* Parse the SQL statement passed as the first argument. If no error
|
||||
** occurs and the parse does not result in a new table, index or
|
||||
** trigger object, the database must be corrupt. */
|
||||
memset(p, 0, sizeof(Parse));
|
||||
p->eParseMode = PARSE_MODE_RENAME;
|
||||
p->db = db;
|
||||
p->nQueryLoop = 1;
|
||||
rc = sqlite3RunParser(p, zSql);
|
||||
rc = zSql ? sqlite3RunParser(p, zSql, &zErr) : SQLITE_NOMEM;
|
||||
assert( p->zErrMsg==0 );
|
||||
assert( rc!=SQLITE_OK || zErr==0 );
|
||||
p->zErrMsg = zErr;
|
||||
if( db->mallocFailed ) rc = SQLITE_NOMEM;
|
||||
if( rc==SQLITE_OK
|
||||
&& NEVER(p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0)
|
||||
&& p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0
|
||||
){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
@@ -1335,9 +1328,6 @@ static int renameResolveTrigger(Parse *pParse){
|
||||
}
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE_OK && db->mallocFailed ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
sNC.pSrcList = pSrc;
|
||||
if( rc==SQLITE_OK && pStep->pWhere ){
|
||||
rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere);
|
||||
@@ -1423,13 +1413,13 @@ static void renameParseCleanup(Parse *pParse){
|
||||
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
|
||||
sqlite3DbFree(db, pParse->zErrMsg);
|
||||
renameTokenFree(db, pParse->pRename);
|
||||
sqlite3ParseObjectReset(pParse);
|
||||
sqlite3ParserReset(pParse);
|
||||
}
|
||||
|
||||
/*
|
||||
** SQL function:
|
||||
**
|
||||
** sqlite_rename_column(SQL,TYPE,OBJ,DB,TABLE,COL,NEWNAME,QUOTE,TEMP)
|
||||
** sqlite_rename_column(zSql, iCol, bQuote, zNew, zTable, zOld)
|
||||
**
|
||||
** 0. zSql: SQL statement to rewrite
|
||||
** 1. type: Type of object ("table", "view" etc.)
|
||||
@@ -1447,8 +1437,7 @@ static void renameParseCleanup(Parse *pParse){
|
||||
**
|
||||
** This function is used internally by the ALTER TABLE RENAME COLUMN command.
|
||||
** It is only accessible to SQL created using sqlite3NestedParse(). It is
|
||||
** not reachable from ordinary SQL passed into sqlite3_prepare() unless the
|
||||
** SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test setting is enabled.
|
||||
** not reachable from ordinary SQL passed into sqlite3_prepare().
|
||||
*/
|
||||
static void renameColumnFunc(
|
||||
sqlite3_context *context,
|
||||
@@ -1486,7 +1475,7 @@ static void renameColumnFunc(
|
||||
sqlite3BtreeLeaveAll(db);
|
||||
return;
|
||||
}
|
||||
zOld = pTab->aCol[iCol].zCnName;
|
||||
zOld = pTab->aCol[iCol].zName;
|
||||
memset(&sCtx, 0, sizeof(sCtx));
|
||||
sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
|
||||
|
||||
@@ -1505,8 +1494,8 @@ static void renameColumnFunc(
|
||||
sCtx.pTab = pTab;
|
||||
if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
|
||||
if( sParse.pNewTable ){
|
||||
if( IsView(sParse.pNewTable) ){
|
||||
Select *pSelect = sParse.pNewTable->u.view.pSelect;
|
||||
Select *pSelect = sParse.pNewTable->pSelect;
|
||||
if( pSelect ){
|
||||
pSelect->selFlags &= ~SF_View;
|
||||
sParse.rc = SQLITE_OK;
|
||||
sqlite3SelectPrep(&sParse, pSelect, 0);
|
||||
@@ -1515,15 +1504,16 @@ static void renameColumnFunc(
|
||||
sqlite3WalkSelect(&sWalker, pSelect);
|
||||
}
|
||||
if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
|
||||
}else if( IsOrdinaryTable(sParse.pNewTable) ){
|
||||
}else{
|
||||
/* A regular table */
|
||||
int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName);
|
||||
FKey *pFKey;
|
||||
assert( sParse.pNewTable->pSelect==0 );
|
||||
sCtx.pTab = sParse.pNewTable;
|
||||
if( bFKOnly==0 ){
|
||||
if( iCol<sParse.pNewTable->nCol ){
|
||||
renameTokenFind(
|
||||
&sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zCnName
|
||||
&sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zName
|
||||
);
|
||||
}
|
||||
if( sCtx.iCol<0 ){
|
||||
@@ -1538,15 +1528,12 @@ static void renameColumnFunc(
|
||||
}
|
||||
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
|
||||
for(i=0; i<sParse.pNewTable->nCol; i++){
|
||||
Expr *pExpr = sqlite3ColumnExpr(sParse.pNewTable,
|
||||
&sParse.pNewTable->aCol[i]);
|
||||
sqlite3WalkExpr(&sWalker, pExpr);
|
||||
sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
assert( IsOrdinaryTable(sParse.pNewTable) );
|
||||
for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
|
||||
for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){
|
||||
for(i=0; i<pFKey->nCol; i++){
|
||||
if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
|
||||
renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
|
||||
@@ -1597,9 +1584,7 @@ static void renameColumnFunc(
|
||||
|
||||
renameColumnFunc_done:
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){
|
||||
sqlite3_result_value(context, argv[0]);
|
||||
}else if( sParse.zErrMsg ){
|
||||
if( sParse.zErrMsg ){
|
||||
renameColumnParseError(context, "", argv[1], argv[2], &sParse);
|
||||
}else{
|
||||
sqlite3_result_error_code(context, rc);
|
||||
@@ -1619,10 +1604,7 @@ renameColumnFunc_done:
|
||||
*/
|
||||
static int renameTableExprCb(Walker *pWalker, Expr *pExpr){
|
||||
RenameCtx *p = pWalker->u.pRename;
|
||||
if( pExpr->op==TK_COLUMN
|
||||
&& ALWAYS(ExprUseYTab(pExpr))
|
||||
&& p->pTab==pExpr->y.pTab
|
||||
){
|
||||
if( pExpr->op==TK_COLUMN && p->pTab==pExpr->y.pTab ){
|
||||
renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab);
|
||||
}
|
||||
return WRC_Continue;
|
||||
@@ -1717,31 +1699,28 @@ static void renameTableFunc(
|
||||
if( sParse.pNewTable ){
|
||||
Table *pTab = sParse.pNewTable;
|
||||
|
||||
if( IsView(pTab) ){
|
||||
if( pTab->pSelect ){
|
||||
if( isLegacy==0 ){
|
||||
Select *pSelect = pTab->u.view.pSelect;
|
||||
Select *pSelect = pTab->pSelect;
|
||||
NameContext sNC;
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = &sParse;
|
||||
|
||||
assert( pSelect->selFlags & SF_View );
|
||||
pSelect->selFlags &= ~SF_View;
|
||||
sqlite3SelectPrep(&sParse, pTab->u.view.pSelect, &sNC);
|
||||
sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC);
|
||||
if( sParse.nErr ){
|
||||
rc = sParse.rc;
|
||||
}else{
|
||||
sqlite3WalkSelect(&sWalker, pTab->u.view.pSelect);
|
||||
sqlite3WalkSelect(&sWalker, pTab->pSelect);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
/* Modify any FK definitions to point to the new table. */
|
||||
#ifndef SQLITE_OMIT_FOREIGN_KEY
|
||||
if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
|
||||
&& !IsVirtual(pTab)
|
||||
){
|
||||
if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){
|
||||
FKey *pFKey;
|
||||
assert( IsOrdinaryTable(pTab) );
|
||||
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
|
||||
for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
|
||||
if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
|
||||
renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
|
||||
}
|
||||
@@ -1798,9 +1777,7 @@ static void renameTableFunc(
|
||||
rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote);
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){
|
||||
sqlite3_result_value(context, argv[3]);
|
||||
}else if( sParse.zErrMsg ){
|
||||
if( sParse.zErrMsg ){
|
||||
renameColumnParseError(context, "", argv[1], argv[2], &sParse);
|
||||
}else{
|
||||
sqlite3_result_error_code(context, rc);
|
||||
@@ -1820,15 +1797,15 @@ static void renameTableFunc(
|
||||
|
||||
static int renameQuotefixExprCb(Walker *pWalker, Expr *pExpr){
|
||||
if( pExpr->op==TK_STRING && (pExpr->flags & EP_DblQuoted) ){
|
||||
renameTokenFind(pWalker->pParse, pWalker->u.pRename, (const void*)pExpr);
|
||||
renameTokenFind(pWalker->pParse, pWalker->u.pRename, (void*)pExpr);
|
||||
}
|
||||
return WRC_Continue;
|
||||
}
|
||||
|
||||
/* SQL function: sqlite_rename_quotefix(DB,SQL)
|
||||
**
|
||||
** Rewrite the DDL statement "SQL" so that any string literals that use
|
||||
** double-quotes use single quotes instead.
|
||||
/*
|
||||
** The implementation of an SQL scalar function that rewrites DDL statements
|
||||
** so that any string literals that use double-quotes are modified so that
|
||||
** they use single quotes.
|
||||
**
|
||||
** Two arguments must be passed:
|
||||
**
|
||||
@@ -1847,10 +1824,6 @@ static int renameQuotefixExprCb(Walker *pWalker, Expr *pExpr){
|
||||
** returns the string:
|
||||
**
|
||||
** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1
|
||||
**
|
||||
** If there is a error in the input SQL, then raise an error, except
|
||||
** if PRAGMA writable_schema=ON, then just return the input string
|
||||
** unmodified following an error.
|
||||
*/
|
||||
static void renameQuotefixFunc(
|
||||
sqlite3_context *context,
|
||||
@@ -1887,8 +1860,8 @@ static void renameQuotefixFunc(
|
||||
sWalker.u.pRename = &sCtx;
|
||||
|
||||
if( sParse.pNewTable ){
|
||||
if( IsView(sParse.pNewTable) ){
|
||||
Select *pSelect = sParse.pNewTable->u.view.pSelect;
|
||||
Select *pSelect = sParse.pNewTable->pSelect;
|
||||
if( pSelect ){
|
||||
pSelect->selFlags &= ~SF_View;
|
||||
sParse.rc = SQLITE_OK;
|
||||
sqlite3SelectPrep(&sParse, pSelect, 0);
|
||||
@@ -1901,9 +1874,7 @@ static void renameQuotefixFunc(
|
||||
sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck);
|
||||
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
|
||||
for(i=0; i<sParse.pNewTable->nCol; i++){
|
||||
sqlite3WalkExpr(&sWalker,
|
||||
sqlite3ColumnExpr(sParse.pNewTable,
|
||||
&sParse.pNewTable->aCol[i]));
|
||||
sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
|
||||
}
|
||||
@@ -1925,11 +1896,7 @@ static void renameQuotefixFunc(
|
||||
renameTokenFree(db, sCtx.pList);
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( sqlite3WritableSchema(db) && rc==SQLITE_ERROR ){
|
||||
sqlite3_result_value(context, argv[1]);
|
||||
}else{
|
||||
sqlite3_result_error_code(context, rc);
|
||||
}
|
||||
sqlite3_result_error_code(context, rc);
|
||||
}
|
||||
renameParseCleanup(&sParse);
|
||||
}
|
||||
@@ -1941,8 +1908,7 @@ static void renameQuotefixFunc(
|
||||
sqlite3BtreeLeaveAll(db);
|
||||
}
|
||||
|
||||
/* Function: sqlite_rename_test(DB,SQL,TYPE,NAME,ISTEMP,WHEN,DQS)
|
||||
**
|
||||
/*
|
||||
** An SQL user function that checks that there are no parse or symbol
|
||||
** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement.
|
||||
** After an ALTER TABLE .. RENAME operation is performed and the schema
|
||||
@@ -1957,13 +1923,11 @@ static void renameQuotefixFunc(
|
||||
** 5: "when" part of error message.
|
||||
** 6: True to disable the DQS quirk when parsing SQL.
|
||||
**
|
||||
** The return value is computed as follows:
|
||||
** Unless it finds an error, this function normally returns NULL. However, it
|
||||
** returns integer value 1 if:
|
||||
**
|
||||
** A. If an error is seen and not in PRAGMA writable_schema=ON mode,
|
||||
** then raise the error.
|
||||
** B. Else if a trigger is created and the the table that the trigger is
|
||||
** attached to is in database zDb, then return 1.
|
||||
** C. Otherwise return NULL.
|
||||
** * the SQL argument creates a trigger, and
|
||||
** * the table that the trigger is attached to is in database zDb.
|
||||
*/
|
||||
static void renameTableTest(
|
||||
sqlite3_context *context,
|
||||
@@ -1993,11 +1957,11 @@ static void renameTableTest(
|
||||
rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
|
||||
db->flags |= (flags & (SQLITE_DqsDML|SQLITE_DqsDDL));
|
||||
if( rc==SQLITE_OK ){
|
||||
if( isLegacy==0 && sParse.pNewTable && IsView(sParse.pNewTable) ){
|
||||
if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
|
||||
NameContext sNC;
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = &sParse;
|
||||
sqlite3SelectPrep(&sParse, sParse.pNewTable->u.view.pSelect, &sNC);
|
||||
sqlite3SelectPrep(&sParse, sParse.pNewTable->pSelect, &sNC);
|
||||
if( sParse.nErr ) rc = sParse.rc;
|
||||
}
|
||||
|
||||
@@ -2008,16 +1972,12 @@ static void renameTableTest(
|
||||
if( rc==SQLITE_OK ){
|
||||
int i1 = sqlite3SchemaToIndex(db, sParse.pNewTrigger->pTabSchema);
|
||||
int i2 = sqlite3FindDbName(db, zDb);
|
||||
if( i1==i2 ){
|
||||
/* Handle output case B */
|
||||
sqlite3_result_int(context, 1);
|
||||
}
|
||||
if( i1==i2 ) sqlite3_result_int(context, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( rc!=SQLITE_OK && zWhen && !sqlite3WritableSchema(db) ){
|
||||
/* Output case A */
|
||||
if( rc!=SQLITE_OK && zWhen ){
|
||||
renameColumnParseError(context, zWhen, argv[2], argv[3],&sParse);
|
||||
}
|
||||
renameParseCleanup(&sParse);
|
||||
@@ -2072,14 +2032,13 @@ static void dropColumnFunc(
|
||||
goto drop_column_done;
|
||||
}
|
||||
|
||||
pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zCnName);
|
||||
pCol = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol].zName);
|
||||
if( iCol<pTab->nCol-1 ){
|
||||
RenameToken *pEnd;
|
||||
pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
|
||||
pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zName);
|
||||
zEnd = (const char*)pEnd->t.z;
|
||||
}else{
|
||||
assert( IsOrdinaryTable(pTab) );
|
||||
zEnd = (const char*)&zSql[pTab->u.tab.addColOffset];
|
||||
zEnd = (const char*)&zSql[pTab->addColOffset];
|
||||
while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
|
||||
}
|
||||
|
||||
@@ -2105,7 +2064,7 @@ drop_column_done:
|
||||
** statement. Argument pSrc contains the possibly qualified name of the
|
||||
** table being edited, and token pName the name of the column to drop.
|
||||
*/
|
||||
void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, const Token *pName){
|
||||
void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, Token *pName){
|
||||
sqlite3 *db = pParse->db; /* Database handle */
|
||||
Table *pTab; /* Table to modify */
|
||||
int iDb; /* Index of db containing pTab in aDb[] */
|
||||
@@ -2133,7 +2092,7 @@ void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, const Token *pName){
|
||||
}
|
||||
iCol = sqlite3ColumnIndex(pTab, zCol);
|
||||
if( iCol<0 ){
|
||||
sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pName);
|
||||
sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zCol);
|
||||
goto exit_drop_column;
|
||||
}
|
||||
|
||||
@@ -2157,16 +2116,10 @@ void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, const Token *pName){
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
assert( iDb>=0 );
|
||||
zDb = db->aDb[iDb].zDbSName;
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
/* Invoke the authorization callback. */
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, zCol) ){
|
||||
goto exit_drop_column;
|
||||
}
|
||||
#endif
|
||||
renameTestSchema(pParse, zDb, iDb==1, "", 0);
|
||||
renameFixQuotes(pParse, zDb, iDb==1);
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET "
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = sqlite_drop_column(%d, sql, %d) "
|
||||
"WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)"
|
||||
, zDb, iDb, iCol, pTab->zName
|
||||
|
||||
+37
-24
@@ -433,6 +433,7 @@ static void statInit(
|
||||
+ sizeof(tRowcnt)*3*nColUp*(nCol+mxSample);
|
||||
}
|
||||
#endif
|
||||
db = sqlite3_context_db_handle(context);
|
||||
p = sqlite3DbMallocZero(db, n);
|
||||
if( p==0 ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
@@ -851,19 +852,28 @@ static void statGet(
|
||||
**
|
||||
** I = (K+D-1)/D
|
||||
*/
|
||||
sqlite3_str sStat; /* Text of the constructed "stat" line */
|
||||
int i; /* Loop counter */
|
||||
char *z;
|
||||
int i;
|
||||
|
||||
sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
|
||||
sqlite3_str_appendf(&sStat, "%llu",
|
||||
char *zRet = sqlite3MallocZero( (p->nKeyCol+1)*25 );
|
||||
if( zRet==0 ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
return;
|
||||
}
|
||||
|
||||
sqlite3_snprintf(24, zRet, "%llu",
|
||||
p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
|
||||
z = zRet + sqlite3Strlen30(zRet);
|
||||
for(i=0; i<p->nKeyCol; i++){
|
||||
u64 nDistinct = p->current.anDLt[i] + 1;
|
||||
u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
|
||||
sqlite3_str_appendf(&sStat, " %llu", iVal);
|
||||
sqlite3_snprintf(24, z, " %llu", iVal);
|
||||
z += sqlite3Strlen30(z);
|
||||
assert( p->current.anEq[i] );
|
||||
}
|
||||
sqlite3ResultStrAccum(context, &sStat);
|
||||
assert( z[0]=='\0' && z>zRet );
|
||||
|
||||
sqlite3_result_text(context, zRet, -1, sqlite3_free);
|
||||
}
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
else if( eCall==STAT_GET_ROWID ){
|
||||
@@ -882,8 +892,6 @@ static void statGet(
|
||||
}
|
||||
}else{
|
||||
tRowcnt *aCnt = 0;
|
||||
sqlite3_str sStat;
|
||||
int i;
|
||||
|
||||
assert( p->iGet<p->nSample );
|
||||
switch( eCall ){
|
||||
@@ -895,12 +903,23 @@ static void statGet(
|
||||
break;
|
||||
}
|
||||
}
|
||||
sqlite3StrAccumInit(&sStat, 0, 0, 0, p->nCol*100);
|
||||
for(i=0; i<p->nCol; i++){
|
||||
sqlite3_str_appendf(&sStat, "%llu ", (u64)aCnt[i]);
|
||||
|
||||
{
|
||||
char *zRet = sqlite3MallocZero(p->nCol * 25);
|
||||
if( zRet==0 ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
}else{
|
||||
int i;
|
||||
char *z = zRet;
|
||||
for(i=0; i<p->nCol; i++){
|
||||
sqlite3_snprintf(24, z, "%llu ", (u64)aCnt[i]);
|
||||
z += sqlite3Strlen30(z);
|
||||
}
|
||||
assert( z[0]=='\0' && z>zRet );
|
||||
z[-1] = '\0';
|
||||
sqlite3_result_text(context, zRet, -1, sqlite3_free);
|
||||
}
|
||||
}
|
||||
if( sStat.nChar ) sStat.nChar--;
|
||||
sqlite3ResultStrAccum(context, &sStat);
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_STAT4 */
|
||||
#ifndef SQLITE_DEBUG
|
||||
@@ -949,7 +968,7 @@ static void analyzeVdbeCommentIndexWithColumnName(
|
||||
}else if( i==XN_EXPR ){
|
||||
VdbeComment((v,"%s.expr(%d)",pIdx->zName, k));
|
||||
}else{
|
||||
VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zCnName));
|
||||
VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zName));
|
||||
}
|
||||
}
|
||||
#else
|
||||
@@ -996,7 +1015,7 @@ static void analyzeOneTable(
|
||||
if( v==0 || NEVER(pTab==0) ){
|
||||
return;
|
||||
}
|
||||
if( !IsOrdinaryTable(pTab) ){
|
||||
if( pTab->tnum==0 ){
|
||||
/* Do not gather statistics on views or virtual tables */
|
||||
return;
|
||||
}
|
||||
@@ -1023,7 +1042,7 @@ static void analyzeOneTable(
|
||||
memcpy(pStat1->zName, "sqlite_stat1", 13);
|
||||
pStat1->nCol = 3;
|
||||
pStat1->iPKey = -1;
|
||||
sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNAMIC);
|
||||
sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1821,12 +1840,9 @@ static int loadStatTbl(
|
||||
*/
|
||||
static int loadStat4(sqlite3 *db, const char *zDb){
|
||||
int rc = SQLITE_OK; /* Result codes from subroutines */
|
||||
const Table *pStat4;
|
||||
|
||||
assert( db->lookaside.bDisable );
|
||||
if( (pStat4 = sqlite3FindTable(db, "sqlite_stat4", zDb))!=0
|
||||
&& IsOrdinaryTable(pStat4)
|
||||
){
|
||||
if( sqlite3FindTable(db, "sqlite_stat4", zDb) ){
|
||||
rc = loadStatTbl(db,
|
||||
"SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx",
|
||||
"SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4",
|
||||
@@ -1863,7 +1879,6 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
|
||||
char *zSql;
|
||||
int rc = SQLITE_OK;
|
||||
Schema *pSchema = db->aDb[iDb].pSchema;
|
||||
const Table *pStat1;
|
||||
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
assert( db->aDb[iDb].pBt!=0 );
|
||||
@@ -1886,9 +1901,7 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
|
||||
/* Load new statistics out of the sqlite_stat1 table */
|
||||
sInfo.db = db;
|
||||
sInfo.zDatabase = db->aDb[iDb].zDbSName;
|
||||
if( (pStat1 = sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase))
|
||||
&& IsOrdinaryTable(pStat1)
|
||||
){
|
||||
if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
|
||||
zSql = sqlite3MPrintf(db,
|
||||
"SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
|
||||
if( zSql==0 ){
|
||||
|
||||
+4
-5
@@ -346,18 +346,17 @@ static void codeAttach(
|
||||
sName.pParse = pParse;
|
||||
|
||||
if(
|
||||
SQLITE_OK!=resolveAttachExpr(&sName, pFilename) ||
|
||||
SQLITE_OK!=resolveAttachExpr(&sName, pDbname) ||
|
||||
SQLITE_OK!=resolveAttachExpr(&sName, pKey)
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
|
||||
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
|
||||
){
|
||||
goto attach_end;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( ALWAYS(pAuthArg) ){
|
||||
if( pAuthArg ){
|
||||
char *zAuthArg;
|
||||
if( pAuthArg->op==TK_STRING ){
|
||||
assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
|
||||
zAuthArg = pAuthArg->u.zToken;
|
||||
}else{
|
||||
zAuthArg = 0;
|
||||
|
||||
+2
-2
@@ -175,10 +175,10 @@ void sqlite3AuthRead(
|
||||
|
||||
if( iCol>=0 ){
|
||||
assert( iCol<pTab->nCol );
|
||||
zCol = pTab->aCol[iCol].zCnName;
|
||||
zCol = pTab->aCol[iCol].zName;
|
||||
}else if( pTab->iPKey>=0 ){
|
||||
assert( pTab->iPKey<pTab->nCol );
|
||||
zCol = pTab->aCol[pTab->iPKey].zCnName;
|
||||
zCol = pTab->aCol[pTab->iPKey].zName;
|
||||
}else{
|
||||
zCol = "ROWID";
|
||||
}
|
||||
|
||||
+3
-2
@@ -85,13 +85,14 @@ static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
|
||||
if( i==1 ){
|
||||
Parse sParse;
|
||||
int rc = 0;
|
||||
sqlite3ParseObjectInit(&sParse,pDb);
|
||||
memset(&sParse, 0, sizeof(sParse));
|
||||
sParse.db = pDb;
|
||||
if( sqlite3OpenTempDatabase(&sParse) ){
|
||||
sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg);
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
sqlite3DbFree(pErrorDb, sParse.zErrMsg);
|
||||
sqlite3ParseObjectReset(&sParse);
|
||||
sqlite3ParserReset(&sParse);
|
||||
if( rc ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -353,7 +353,7 @@ int sqlite3BitvecBuiltinTest(int sz, int *aOp){
|
||||
sqlite3BitvecClear(0, 1, pTmpSpace);
|
||||
|
||||
/* Run the program */
|
||||
pc = i = 0;
|
||||
pc = 0;
|
||||
while( (op = aOp[pc])!=0 ){
|
||||
switch( op ){
|
||||
case 1:
|
||||
|
||||
+146
-368
@@ -214,7 +214,7 @@ static int hasSharedCacheTableLock(
|
||||
int bSeen = 0;
|
||||
for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){
|
||||
Index *pIdx = (Index *)sqliteHashData(p);
|
||||
if( pIdx->tnum==iRoot ){
|
||||
if( pIdx->tnum==(int)iRoot ){
|
||||
if( bSeen ){
|
||||
/* Two or more indexes share the same root page. There must
|
||||
** be imposter tables. So just return true. The assert is not
|
||||
@@ -807,7 +807,7 @@ void sqlite3BtreeClearCursor(BtCursor *pCur){
|
||||
/*
|
||||
** In this version of BtreeMoveto, pKey is a packed index record
|
||||
** such as is generated by the OP_MakeRecord opcode. Unpack the
|
||||
** record and then call sqlite3BtreeIndexMoveto() to do the work.
|
||||
** record and then call BtreeMovetoUnpacked() to do the work.
|
||||
*/
|
||||
static int btreeMoveto(
|
||||
BtCursor *pCur, /* Cursor open on the btree to be searched */
|
||||
@@ -1225,32 +1225,18 @@ static void btreeParseCellPtr(
|
||||
**
|
||||
** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
|
||||
**
|
||||
** The code is inlined and the loop is unrolled for performance.
|
||||
** This routine is a high-runner.
|
||||
** The code is inlined to avoid a function call.
|
||||
*/
|
||||
iKey = *pIter;
|
||||
if( iKey>=0x80 ){
|
||||
u8 x;
|
||||
iKey = ((iKey&0x7f)<<7) | ((x = *++pIter) & 0x7f);
|
||||
if( x>=0x80 ){
|
||||
iKey = (iKey<<7) | ((x =*++pIter) & 0x7f);
|
||||
if( x>=0x80 ){
|
||||
iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
|
||||
if( x>=0x80 ){
|
||||
iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
|
||||
if( x>=0x80 ){
|
||||
iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
|
||||
if( x>=0x80 ){
|
||||
iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
|
||||
if( x>=0x80 ){
|
||||
iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
|
||||
if( x>=0x80 ){
|
||||
iKey = (iKey<<8) | (*++pIter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
u8 *pEnd = &pIter[7];
|
||||
iKey &= 0x7f;
|
||||
while(1){
|
||||
iKey = (iKey<<7) | (*++pIter & 0x7f);
|
||||
if( (*pIter)<0x80 ) break;
|
||||
if( pIter>=pEnd ){
|
||||
iKey = (iKey<<8) | *++pIter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1260,7 +1246,7 @@ static void btreeParseCellPtr(
|
||||
pInfo->nPayload = nPayload;
|
||||
pInfo->pPayload = pIter;
|
||||
testcase( nPayload==pPage->maxLocal );
|
||||
testcase( nPayload==(u32)pPage->maxLocal+1 );
|
||||
testcase( nPayload==pPage->maxLocal+1 );
|
||||
if( nPayload<=pPage->maxLocal ){
|
||||
/* This is the (easy) common case where the entire payload fits
|
||||
** on the local page. No overflow is required.
|
||||
@@ -1297,7 +1283,7 @@ static void btreeParseCellPtrIndex(
|
||||
pInfo->nPayload = nPayload;
|
||||
pInfo->pPayload = pIter;
|
||||
testcase( nPayload==pPage->maxLocal );
|
||||
testcase( nPayload==(u32)pPage->maxLocal+1 );
|
||||
testcase( nPayload==pPage->maxLocal+1 );
|
||||
if( nPayload<=pPage->maxLocal ){
|
||||
/* This is the (easy) common case where the entire payload fits
|
||||
** on the local page. No overflow is required.
|
||||
@@ -1327,7 +1313,6 @@ static void btreeParseCell(
|
||||
** the space used by the cell pointer.
|
||||
**
|
||||
** cellSizePtrNoPayload() => table internal nodes
|
||||
** cellSizePtrTableLeaf() => table leaf nodes
|
||||
** cellSizePtr() => all index nodes & table leaf nodes
|
||||
*/
|
||||
static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
|
||||
@@ -1353,8 +1338,15 @@ static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
|
||||
}while( *(pIter)>=0x80 && pIter<pEnd );
|
||||
}
|
||||
pIter++;
|
||||
if( pPage->intKey ){
|
||||
/* pIter now points at the 64-bit integer key value, a variable length
|
||||
** integer. The following block moves pIter to point at the first byte
|
||||
** past the end of the key value. */
|
||||
pEnd = &pIter[9];
|
||||
while( (*pIter++)&0x80 && pIter<pEnd );
|
||||
}
|
||||
testcase( nSize==pPage->maxLocal );
|
||||
testcase( nSize==(u32)pPage->maxLocal+1 );
|
||||
testcase( nSize==pPage->maxLocal+1 );
|
||||
if( nSize<=pPage->maxLocal ){
|
||||
nSize += (u32)(pIter - pCell);
|
||||
if( nSize<4 ) nSize = 4;
|
||||
@@ -1362,7 +1354,7 @@ static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
|
||||
int minLocal = pPage->minLocal;
|
||||
nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
|
||||
testcase( nSize==pPage->maxLocal );
|
||||
testcase( nSize==(u32)pPage->maxLocal+1 );
|
||||
testcase( nSize==pPage->maxLocal+1 );
|
||||
if( nSize>pPage->maxLocal ){
|
||||
nSize = minLocal;
|
||||
}
|
||||
@@ -1392,58 +1384,6 @@ static u16 cellSizePtrNoPayload(MemPage *pPage, u8 *pCell){
|
||||
assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB );
|
||||
return (u16)(pIter - pCell);
|
||||
}
|
||||
static u16 cellSizePtrTableLeaf(MemPage *pPage, u8 *pCell){
|
||||
u8 *pIter = pCell; /* For looping over bytes of pCell */
|
||||
u8 *pEnd; /* End mark for a varint */
|
||||
u32 nSize; /* Size value to return */
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
/* The value returned by this function should always be the same as
|
||||
** the (CellInfo.nSize) value found by doing a full parse of the
|
||||
** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of
|
||||
** this function verifies that this invariant is not violated. */
|
||||
CellInfo debuginfo;
|
||||
pPage->xParseCell(pPage, pCell, &debuginfo);
|
||||
#endif
|
||||
|
||||
nSize = *pIter;
|
||||
if( nSize>=0x80 ){
|
||||
pEnd = &pIter[8];
|
||||
nSize &= 0x7f;
|
||||
do{
|
||||
nSize = (nSize<<7) | (*++pIter & 0x7f);
|
||||
}while( *(pIter)>=0x80 && pIter<pEnd );
|
||||
}
|
||||
pIter++;
|
||||
/* pIter now points at the 64-bit integer key value, a variable length
|
||||
** integer. The following block moves pIter to point at the first byte
|
||||
** past the end of the key value. */
|
||||
if( (*pIter++)&0x80
|
||||
&& (*pIter++)&0x80
|
||||
&& (*pIter++)&0x80
|
||||
&& (*pIter++)&0x80
|
||||
&& (*pIter++)&0x80
|
||||
&& (*pIter++)&0x80
|
||||
&& (*pIter++)&0x80
|
||||
&& (*pIter++)&0x80 ){ pIter++; }
|
||||
testcase( nSize==pPage->maxLocal );
|
||||
testcase( nSize==(u32)pPage->maxLocal+1 );
|
||||
if( nSize<=pPage->maxLocal ){
|
||||
nSize += (u32)(pIter - pCell);
|
||||
if( nSize<4 ) nSize = 4;
|
||||
}else{
|
||||
int minLocal = pPage->minLocal;
|
||||
nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
|
||||
testcase( nSize==pPage->maxLocal );
|
||||
testcase( nSize==(u32)pPage->maxLocal+1 );
|
||||
if( nSize>pPage->maxLocal ){
|
||||
nSize = minLocal;
|
||||
}
|
||||
nSize += 4 + (u16)(pIter - pCell);
|
||||
}
|
||||
assert( nSize==debuginfo.nSize || CORRUPT_DB );
|
||||
return (u16)nSize;
|
||||
}
|
||||
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
@@ -1457,7 +1397,7 @@ static u16 cellSize(MemPage *pPage, int iCell){
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
/*
|
||||
** The cell pCell is currently part of page pSrc but will ultimately be part
|
||||
** of pPage. (pSrc and pPage are often the same.) If pCell contains a
|
||||
** of pPage. (pSrc and pPager are often the same.) If pCell contains a
|
||||
** pointer to an overflow page, insert an entry into the pointer-map for
|
||||
** the overflow page that will be valid after pCell has been moved to pPage.
|
||||
*/
|
||||
@@ -1548,7 +1488,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
|
||||
if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
|
||||
memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
|
||||
sz += sz2;
|
||||
}else if( NEVER(iFree+sz>usableSize) ){
|
||||
}else if( iFree+sz>usableSize ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
|
||||
@@ -1632,8 +1572,7 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
|
||||
const int hdr = pPg->hdrOffset; /* Offset to page header */
|
||||
u8 * const aData = pPg->aData; /* Page data */
|
||||
int iAddr = hdr + 1; /* Address of ptr to pc */
|
||||
u8 *pTmp = &aData[iAddr]; /* Temporary ptr into aData[] */
|
||||
int pc = get2byte(pTmp); /* Address of a free slot */
|
||||
int pc = get2byte(&aData[iAddr]); /* Address of a free slot */
|
||||
int x; /* Excess size of the slot */
|
||||
int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */
|
||||
int size; /* Size of the free slot */
|
||||
@@ -1643,8 +1582,7 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
|
||||
/* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
|
||||
** freeblock form a big-endian integer which is the size of the freeblock
|
||||
** in bytes, including the 4-byte header. */
|
||||
pTmp = &aData[pc+2];
|
||||
size = get2byte(pTmp);
|
||||
size = get2byte(&aData[pc+2]);
|
||||
if( (x = size - nByte)>=0 ){
|
||||
testcase( x==4 );
|
||||
testcase( x==3 );
|
||||
@@ -1669,8 +1607,7 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
|
||||
return &aData[pc + x];
|
||||
}
|
||||
iAddr = pc;
|
||||
pTmp = &aData[pc];
|
||||
pc = get2byte(pTmp);
|
||||
pc = get2byte(&aData[pc]);
|
||||
if( pc<=iAddr+size ){
|
||||
if( pc ){
|
||||
/* The next slot in the chain is not past the end of the current slot */
|
||||
@@ -1704,7 +1641,6 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
|
||||
u8 * const data = pPage->aData; /* Local cache of pPage->aData */
|
||||
int top; /* First byte of cell content area */
|
||||
int rc = SQLITE_OK; /* Integer return code */
|
||||
u8 *pTmp; /* Temp ptr into data[] */
|
||||
int gap; /* First byte of gap between cell pointers and cell content */
|
||||
|
||||
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
|
||||
@@ -1723,8 +1659,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
|
||||
** then the cell content offset of an empty page wants to be 65536.
|
||||
** However, that integer is too large to be stored in a 2-byte unsigned
|
||||
** integer, so a value of 0 is used in its place. */
|
||||
pTmp = &data[hdr+5];
|
||||
top = get2byte(pTmp);
|
||||
top = get2byte(&data[hdr+5]);
|
||||
assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */
|
||||
if( gap>top ){
|
||||
if( top==0 && pPage->pBt->usableSize==65536 ){
|
||||
@@ -1806,7 +1741,6 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
|
||||
u16 x; /* Offset to cell content area */
|
||||
u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */
|
||||
unsigned char *data = pPage->aData; /* Page content */
|
||||
u8 *pTmp; /* Temporary ptr into data[] */
|
||||
|
||||
assert( pPage->pBt!=0 );
|
||||
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
|
||||
@@ -1834,7 +1768,7 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
|
||||
if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
assert( iFreeBlk>iPtr || iFreeBlk==0 || CORRUPT_DB );
|
||||
assert( iFreeBlk>iPtr || iFreeBlk==0 );
|
||||
|
||||
/* At this point:
|
||||
** iFreeBlk: First freeblock after iStart, or zero if none
|
||||
@@ -1869,8 +1803,7 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
|
||||
if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage);
|
||||
data[hdr+7] -= nFrag;
|
||||
}
|
||||
pTmp = &data[hdr+5];
|
||||
x = get2byte(pTmp);
|
||||
x = get2byte(&data[hdr+5]);
|
||||
if( iStart<=x ){
|
||||
/* The new freeblock is at the beginning of the cell content area,
|
||||
** so just extend the cell content area rather than create another
|
||||
@@ -1914,6 +1847,7 @@ static int decodeFlags(MemPage *pPage, int flagByte){
|
||||
pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 );
|
||||
flagByte &= ~PTF_LEAF;
|
||||
pPage->childPtrSize = 4-4*pPage->leaf;
|
||||
pPage->xCellSize = cellSizePtr;
|
||||
pBt = pPage->pBt;
|
||||
if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
|
||||
/* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an
|
||||
@@ -1925,7 +1859,6 @@ static int decodeFlags(MemPage *pPage, int flagByte){
|
||||
pPage->intKey = 1;
|
||||
if( pPage->leaf ){
|
||||
pPage->intKeyLeaf = 1;
|
||||
pPage->xCellSize = cellSizePtrTableLeaf;
|
||||
pPage->xParseCell = btreeParseCellPtr;
|
||||
}else{
|
||||
pPage->intKeyLeaf = 0;
|
||||
@@ -1943,17 +1876,12 @@ static int decodeFlags(MemPage *pPage, int flagByte){
|
||||
assert( (PTF_ZERODATA|PTF_LEAF)==10 );
|
||||
pPage->intKey = 0;
|
||||
pPage->intKeyLeaf = 0;
|
||||
pPage->xCellSize = cellSizePtr;
|
||||
pPage->xParseCell = btreeParseCellPtrIndex;
|
||||
pPage->maxLocal = pBt->maxLocal;
|
||||
pPage->minLocal = pBt->minLocal;
|
||||
}else{
|
||||
/* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
|
||||
** an error. */
|
||||
pPage->intKey = 0;
|
||||
pPage->intKeyLeaf = 0;
|
||||
pPage->xCellSize = cellSizePtr;
|
||||
pPage->xParseCell = btreeParseCellPtrIndex;
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
pPage->max1bytePayload = pBt->max1bytePayload;
|
||||
@@ -2111,7 +2039,7 @@ static int btreeInitPage(MemPage *pPage){
|
||||
pPage->nOverflow = 0;
|
||||
pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize;
|
||||
pPage->aCellIdx = data + pPage->childPtrSize + 8;
|
||||
pPage->aDataEnd = pPage->aData + pBt->pageSize;
|
||||
pPage->aDataEnd = pPage->aData + pBt->usableSize;
|
||||
pPage->aDataOfst = pPage->aData + pPage->childPtrSize;
|
||||
/* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
|
||||
** number of cells on the page. */
|
||||
@@ -2146,7 +2074,7 @@ static void zeroPage(MemPage *pPage, int flags){
|
||||
u8 hdr = pPage->hdrOffset;
|
||||
u16 first;
|
||||
|
||||
assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno || CORRUPT_DB );
|
||||
assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
|
||||
assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
|
||||
assert( sqlite3PagerGetData(pPage->pDbPage) == data );
|
||||
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
|
||||
@@ -2162,7 +2090,7 @@ static void zeroPage(MemPage *pPage, int flags){
|
||||
pPage->nFree = (u16)(pBt->usableSize - first);
|
||||
decodeFlags(pPage, flags);
|
||||
pPage->cellOffset = first;
|
||||
pPage->aDataEnd = &data[pBt->pageSize];
|
||||
pPage->aDataEnd = &data[pBt->usableSize];
|
||||
pPage->aCellIdx = &data[first];
|
||||
pPage->aDataOfst = &data[pPage->childPtrSize];
|
||||
pPage->nOverflow = 0;
|
||||
@@ -2288,7 +2216,7 @@ static int getAndInitPage(
|
||||
goto getAndInitPage_error2;
|
||||
}
|
||||
}
|
||||
assert( (*ppPage)->pgno==pgno || CORRUPT_DB );
|
||||
assert( (*ppPage)->pgno==pgno );
|
||||
assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) );
|
||||
|
||||
/* If obtaining a child page for a cursor, we must verify that the page is
|
||||
@@ -2307,9 +2235,7 @@ getAndInitPage_error1:
|
||||
pCur->pPage = pCur->apPage[pCur->iPage];
|
||||
}
|
||||
testcase( pgno==0 );
|
||||
assert( pgno!=0 || rc==SQLITE_CORRUPT
|
||||
|| rc==SQLITE_IOERR_NOMEM
|
||||
|| rc==SQLITE_NOMEM );
|
||||
assert( pgno!=0 || rc==SQLITE_CORRUPT );
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2767,38 +2693,30 @@ static int removeFromSharingList(BtShared *pBt){
|
||||
** MX_CELL_SIZE(pBt) bytes with a 4-byte prefix for a left-child
|
||||
** pointer.
|
||||
*/
|
||||
static SQLITE_NOINLINE int allocateTempSpace(BtShared *pBt){
|
||||
assert( pBt!=0 );
|
||||
assert( pBt->pTmpSpace==0 );
|
||||
/* This routine is called only by btreeCursor() when allocating the
|
||||
** first write cursor for the BtShared object */
|
||||
assert( pBt->pCursor!=0 && (pBt->pCursor->curFlags & BTCF_WriteFlag)!=0 );
|
||||
pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize );
|
||||
if( pBt->pTmpSpace==0 ){
|
||||
BtCursor *pCur = pBt->pCursor;
|
||||
pBt->pCursor = pCur->pNext; /* Unlink the cursor */
|
||||
memset(pCur, 0, sizeof(*pCur));
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
static void allocateTempSpace(BtShared *pBt){
|
||||
if( !pBt->pTmpSpace ){
|
||||
pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize );
|
||||
|
||||
/* One of the uses of pBt->pTmpSpace is to format cells before
|
||||
** inserting them into a leaf page (function fillInCell()). If
|
||||
** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
|
||||
** by the various routines that manipulate binary cells. Which
|
||||
** can mean that fillInCell() only initializes the first 2 or 3
|
||||
** bytes of pTmpSpace, but that the first 4 bytes are copied from
|
||||
** it into a database page. This is not actually a problem, but it
|
||||
** does cause a valgrind error when the 1 or 2 bytes of unitialized
|
||||
** data is passed to system call write(). So to avoid this error,
|
||||
** zero the first 4 bytes of temp space here.
|
||||
**
|
||||
** Also: Provide four bytes of initialized space before the
|
||||
** beginning of pTmpSpace as an area available to prepend the
|
||||
** left-child pointer to the beginning of a cell.
|
||||
*/
|
||||
memset(pBt->pTmpSpace, 0, 8);
|
||||
pBt->pTmpSpace += 4;
|
||||
return SQLITE_OK;
|
||||
/* One of the uses of pBt->pTmpSpace is to format cells before
|
||||
** inserting them into a leaf page (function fillInCell()). If
|
||||
** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
|
||||
** by the various routines that manipulate binary cells. Which
|
||||
** can mean that fillInCell() only initializes the first 2 or 3
|
||||
** bytes of pTmpSpace, but that the first 4 bytes are copied from
|
||||
** it into a database page. This is not actually a problem, but it
|
||||
** does cause a valgrind error when the 1 or 2 bytes of unitialized
|
||||
** data is passed to system call write(). So to avoid this error,
|
||||
** zero the first 4 bytes of temp space here.
|
||||
**
|
||||
** Also: Provide four bytes of initialized space before the
|
||||
** beginning of pTmpSpace as an area available to prepend the
|
||||
** left-child pointer to the beginning of a cell.
|
||||
*/
|
||||
if( pBt->pTmpSpace ){
|
||||
memset(pBt->pTmpSpace, 0, 8);
|
||||
pBt->pTmpSpace += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3177,6 +3095,7 @@ static int lockBtree(BtShared *pBt){
|
||||
MemPage *pPage1; /* Page 1 of the database file */
|
||||
u32 nPage; /* Number of pages in the database */
|
||||
u32 nPageFile = 0; /* Number of pages in the database file */
|
||||
u32 nPageHeader; /* Number of pages in the database according to hdr */
|
||||
|
||||
assert( sqlite3_mutex_held(pBt->mutex) );
|
||||
assert( pBt->pPage1==0 );
|
||||
@@ -3188,7 +3107,7 @@ static int lockBtree(BtShared *pBt){
|
||||
/* Do some checking to help insure the file we opened really is
|
||||
** a valid database file.
|
||||
*/
|
||||
nPage = get4byte(28+(u8*)pPage1->aData);
|
||||
nPage = nPageHeader = get4byte(28+(u8*)pPage1->aData);
|
||||
sqlite3PagerPagecount(pBt->pPager, (int*)&nPageFile);
|
||||
if( nPage==0 || memcmp(24+(u8*)pPage1->aData, 92+(u8*)pPage1->aData,4)!=0 ){
|
||||
nPage = nPageFile;
|
||||
@@ -3223,7 +3142,7 @@ static int lockBtree(BtShared *pBt){
|
||||
goto page1_init_failed;
|
||||
}
|
||||
|
||||
/* If the read version is set to 2, this database should be accessed
|
||||
/* If the write version is set to 2, this database should be accessed
|
||||
** in WAL mode. If the log is not already open, open it now. Then
|
||||
** return SQLITE_OK and return without populating BtShared.pPage1.
|
||||
** The caller detects this and calls this function again. This is
|
||||
@@ -3295,13 +3214,9 @@ static int lockBtree(BtShared *pBt){
|
||||
pageSize-usableSize);
|
||||
return rc;
|
||||
}
|
||||
if( nPage>nPageFile ){
|
||||
if( sqlite3WritableSchema(pBt->db)==0 ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto page1_init_failed;
|
||||
}else{
|
||||
nPage = nPageFile;
|
||||
}
|
||||
if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto page1_init_failed;
|
||||
}
|
||||
/* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
|
||||
** be less than 480. In other words, if the page size is 512, then the
|
||||
@@ -4025,18 +3940,16 @@ int sqlite3BtreeIncrVacuum(Btree *p){
|
||||
/*
|
||||
** This routine is called prior to sqlite3PagerCommit when a transaction
|
||||
** is committed for an auto-vacuum database.
|
||||
**
|
||||
** If SQLITE_OK is returned, then *pnTrunc is set to the number of pages
|
||||
** the database file should be truncated to during the commit process.
|
||||
** i.e. the database has been reorganized so that only the first *pnTrunc
|
||||
** pages are in use.
|
||||
*/
|
||||
static int autoVacuumCommit(Btree *p){
|
||||
static int autoVacuumCommit(BtShared *pBt){
|
||||
int rc = SQLITE_OK;
|
||||
Pager *pPager;
|
||||
BtShared *pBt;
|
||||
sqlite3 *db;
|
||||
VVA_ONLY( int nRef );
|
||||
|
||||
assert( p!=0 );
|
||||
pBt = p->pBt;
|
||||
pPager = pBt->pPager;
|
||||
VVA_ONLY( nRef = sqlite3PagerRefcount(pPager); )
|
||||
Pager *pPager = pBt->pPager;
|
||||
VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager); )
|
||||
|
||||
assert( sqlite3_mutex_held(pBt->mutex) );
|
||||
invalidateAllOverflowCache(pBt);
|
||||
@@ -4044,7 +3957,6 @@ static int autoVacuumCommit(Btree *p){
|
||||
if( !pBt->incrVacuum ){
|
||||
Pgno nFin; /* Number of pages in database after autovacuuming */
|
||||
Pgno nFree; /* Number of pages on the freelist initially */
|
||||
Pgno nVac; /* Number of pages to vacuum */
|
||||
Pgno iFree; /* The next page to be freed */
|
||||
Pgno nOrig; /* Database size before freeing */
|
||||
|
||||
@@ -4058,42 +3970,18 @@ static int autoVacuumCommit(Btree *p){
|
||||
}
|
||||
|
||||
nFree = get4byte(&pBt->pPage1->aData[36]);
|
||||
db = p->db;
|
||||
if( db->xAutovacPages ){
|
||||
int iDb;
|
||||
for(iDb=0; ALWAYS(iDb<db->nDb); iDb++){
|
||||
if( db->aDb[iDb].pBt==p ) break;
|
||||
}
|
||||
nVac = db->xAutovacPages(
|
||||
db->pAutovacPagesArg,
|
||||
db->aDb[iDb].zDbSName,
|
||||
nOrig,
|
||||
nFree,
|
||||
pBt->pageSize
|
||||
);
|
||||
if( nVac>nFree ){
|
||||
nVac = nFree;
|
||||
}
|
||||
if( nVac==0 ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}else{
|
||||
nVac = nFree;
|
||||
}
|
||||
nFin = finalDbSize(pBt, nOrig, nVac);
|
||||
nFin = finalDbSize(pBt, nOrig, nFree);
|
||||
if( nFin>nOrig ) return SQLITE_CORRUPT_BKPT;
|
||||
if( nFin<nOrig ){
|
||||
rc = saveAllCursors(pBt, 0, 0);
|
||||
}
|
||||
for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
|
||||
rc = incrVacuumStep(pBt, nFin, iFree, nVac==nFree);
|
||||
rc = incrVacuumStep(pBt, nFin, iFree, 1);
|
||||
}
|
||||
if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
|
||||
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
|
||||
if( nVac==nFree ){
|
||||
put4byte(&pBt->pPage1->aData[32], 0);
|
||||
put4byte(&pBt->pPage1->aData[36], 0);
|
||||
}
|
||||
put4byte(&pBt->pPage1->aData[32], 0);
|
||||
put4byte(&pBt->pPage1->aData[36], 0);
|
||||
put4byte(&pBt->pPage1->aData[28], nFin);
|
||||
pBt->bDoTruncate = 1;
|
||||
pBt->nPage = nFin;
|
||||
@@ -4144,7 +4032,7 @@ int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zSuperJrnl){
|
||||
sqlite3BtreeEnter(p);
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
if( pBt->autoVacuum ){
|
||||
rc = autoVacuumCommit(p);
|
||||
rc = autoVacuumCommit(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3BtreeLeave(p);
|
||||
return rc;
|
||||
@@ -4331,7 +4219,7 @@ static void btreeSetNPage(BtShared *pBt, MemPage *pPage1){
|
||||
int nPage = get4byte(&pPage1->aData[28]);
|
||||
testcase( nPage==0 );
|
||||
if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
|
||||
testcase( pBt->nPage!=(u32)nPage );
|
||||
testcase( pBt->nPage!=nPage );
|
||||
pBt->nPage = nPage;
|
||||
}
|
||||
|
||||
@@ -4543,6 +4431,10 @@ static int btreeCursor(
|
||||
assert( pBt->pPage1 && pBt->pPage1->aData );
|
||||
assert( wrFlag==0 || (pBt->btsFlags & BTS_READ_ONLY)==0 );
|
||||
|
||||
if( wrFlag ){
|
||||
allocateTempSpace(pBt);
|
||||
if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
if( iTable<=1 ){
|
||||
if( iTable<1 ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
@@ -4559,25 +4451,19 @@ static int btreeCursor(
|
||||
pCur->pKeyInfo = pKeyInfo;
|
||||
pCur->pBtree = p;
|
||||
pCur->pBt = pBt;
|
||||
pCur->curFlags = 0;
|
||||
pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0;
|
||||
pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY;
|
||||
/* If there are two or more cursors on the same btree, then all such
|
||||
** cursors *must* have the BTCF_Multiple flag set. */
|
||||
for(pX=pBt->pCursor; pX; pX=pX->pNext){
|
||||
if( pX->pgnoRoot==iTable ){
|
||||
pX->curFlags |= BTCF_Multiple;
|
||||
pCur->curFlags = BTCF_Multiple;
|
||||
pCur->curFlags |= BTCF_Multiple;
|
||||
}
|
||||
}
|
||||
pCur->eState = CURSOR_INVALID;
|
||||
pCur->pNext = pBt->pCursor;
|
||||
pBt->pCursor = pCur;
|
||||
if( wrFlag ){
|
||||
pCur->curFlags |= BTCF_WriteFlag;
|
||||
pCur->curPagerFlags = 0;
|
||||
if( pBt->pTmpSpace==0 ) return allocateTempSpace(pBt);
|
||||
}else{
|
||||
pCur->curPagerFlags = PAGER_GET_READONLY;
|
||||
}
|
||||
pCur->eState = CURSOR_INVALID;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
static int btreeCursorWithLock(
|
||||
@@ -4951,9 +4837,7 @@ static int accessPayload(
|
||||
assert( pPage );
|
||||
assert( eOp==0 || eOp==1 );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
if( pCur->ix>=pPage->nCell ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
assert( pCur->ix<pPage->nCell );
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
|
||||
getCellInfo(pCur);
|
||||
@@ -5140,6 +5024,7 @@ int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( pCur->iPage>=0 && pCur->pPage );
|
||||
assert( pCur->ix<pCur->pPage->nCell );
|
||||
return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
|
||||
}
|
||||
|
||||
@@ -5201,7 +5086,7 @@ static const void *fetchPayload(
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
|
||||
assert( pCur->ix<pCur->pPage->nCell );
|
||||
assert( pCur->info.nSize>0 );
|
||||
assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
|
||||
assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
|
||||
@@ -5352,7 +5237,7 @@ static int moveToRoot(BtCursor *pCur){
|
||||
while( --pCur->iPage ){
|
||||
releasePageNotNull(pCur->apPage[pCur->iPage]);
|
||||
}
|
||||
pRoot = pCur->pPage = pCur->apPage[0];
|
||||
pCur->pPage = pCur->apPage[0];
|
||||
goto skip_init;
|
||||
}
|
||||
}else if( pCur->pgnoRoot==0 ){
|
||||
@@ -5377,7 +5262,7 @@ static int moveToRoot(BtCursor *pCur){
|
||||
pCur->curIntKey = pCur->pPage->intKey;
|
||||
}
|
||||
pRoot = pCur->pPage;
|
||||
assert( pRoot->pgno==pCur->pgnoRoot || CORRUPT_DB );
|
||||
assert( pRoot->pgno==pCur->pgnoRoot );
|
||||
|
||||
/* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
|
||||
** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
|
||||
@@ -5399,6 +5284,7 @@ skip_init:
|
||||
pCur->info.nSize = 0;
|
||||
pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
|
||||
|
||||
pRoot = pCur->pPage;
|
||||
if( pRoot->nCell>0 ){
|
||||
pCur->eState = CURSOR_VALID;
|
||||
}else if( !pRoot->leaf ){
|
||||
@@ -5594,7 +5480,9 @@ int sqlite3BtreeTableMoveto(
|
||||
if( pCur->info.nKey==intKey ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}else if( rc!=SQLITE_DONE ){
|
||||
}else if( rc==SQLITE_DONE ){
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -5639,6 +5527,7 @@ int sqlite3BtreeTableMoveto(
|
||||
upr = pPage->nCell-1;
|
||||
assert( biasRight==0 || biasRight==1 );
|
||||
idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
|
||||
pCur->ix = (u16)idx;
|
||||
for(;;){
|
||||
i64 nCellKey;
|
||||
pCell = findCellPastPtr(pPage, idx);
|
||||
@@ -5698,69 +5587,6 @@ moveto_table_finish:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Compare the "idx"-th cell on the page the cursor pCur is currently
|
||||
** pointing to to pIdxKey using xRecordCompare. Return negative or
|
||||
** zero if the cell is less than or equal pIdxKey. Return positive
|
||||
** if unknown.
|
||||
**
|
||||
** Return value negative: Cell at pCur[idx] less than pIdxKey
|
||||
**
|
||||
** Return value is zero: Cell at pCur[idx] equals pIdxKey
|
||||
**
|
||||
** Return value positive: Nothing is known about the relationship
|
||||
** of the cell at pCur[idx] and pIdxKey.
|
||||
**
|
||||
** This routine is part of an optimization. It is always safe to return
|
||||
** a positive value as that will cause the optimization to be skipped.
|
||||
*/
|
||||
static int indexCellCompare(
|
||||
BtCursor *pCur,
|
||||
int idx,
|
||||
UnpackedRecord *pIdxKey,
|
||||
RecordCompare xRecordCompare
|
||||
){
|
||||
MemPage *pPage = pCur->pPage;
|
||||
int c;
|
||||
int nCell; /* Size of the pCell cell in bytes */
|
||||
u8 *pCell = findCellPastPtr(pPage, idx);
|
||||
|
||||
nCell = pCell[0];
|
||||
if( nCell<=pPage->max1bytePayload ){
|
||||
/* This branch runs if the record-size field of the cell is a
|
||||
** single byte varint and the record fits entirely on the main
|
||||
** b-tree page. */
|
||||
testcase( pCell+nCell+1==pPage->aDataEnd );
|
||||
c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
|
||||
}else if( !(pCell[1] & 0x80)
|
||||
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
|
||||
){
|
||||
/* The record-size field is a 2 byte varint and the record
|
||||
** fits entirely on the main b-tree page. */
|
||||
testcase( pCell+nCell+2==pPage->aDataEnd );
|
||||
c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
|
||||
}else{
|
||||
/* If the record extends into overflow pages, do not attempt
|
||||
** the optimization. */
|
||||
c = 99;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return true (non-zero) if pCur is current pointing to the last
|
||||
** page of a table.
|
||||
*/
|
||||
static int cursorOnLastPage(BtCursor *pCur){
|
||||
int i;
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
for(i=0; i<pCur->iPage; i++){
|
||||
MemPage *pPage = pCur->apPage[i];
|
||||
if( pCur->aiIdx[i]<pPage->nCell ) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Move the cursor so that it points to an entry in an index table
|
||||
** near the key pIdxKey. Return a success code.
|
||||
**
|
||||
@@ -5811,40 +5637,6 @@ int sqlite3BtreeIndexMoveto(
|
||||
|| pIdxKey->default_rc==-1
|
||||
);
|
||||
|
||||
|
||||
/* Check to see if we can skip a lot of work. Two cases:
|
||||
**
|
||||
** (1) If the cursor is already pointing to the very last cell
|
||||
** in the table and the pIdxKey search key is greater than or
|
||||
** equal to that last cell, then no movement is required.
|
||||
**
|
||||
** (2) If the cursor is on the last page of the table and the first
|
||||
** cell on that last page is less than or equal to the pIdxKey
|
||||
** search key, then we can start the search on the current page
|
||||
** without needing to go back to root.
|
||||
*/
|
||||
if( pCur->eState==CURSOR_VALID
|
||||
&& pCur->pPage->leaf
|
||||
&& cursorOnLastPage(pCur)
|
||||
){
|
||||
int c;
|
||||
if( pCur->ix==pCur->pPage->nCell-1
|
||||
&& (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0
|
||||
&& pIdxKey->errCode==SQLITE_OK
|
||||
){
|
||||
*pRes = c;
|
||||
return SQLITE_OK; /* Cursor already pointing at the correct spot */
|
||||
}
|
||||
if( pCur->iPage>0
|
||||
&& indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0
|
||||
&& pIdxKey->errCode==SQLITE_OK
|
||||
){
|
||||
pCur->curFlags &= ~BTCF_ValidOvfl;
|
||||
goto bypass_moveto_root; /* Start search on the current page */
|
||||
}
|
||||
pIdxKey->errCode = SQLITE_OK;
|
||||
}
|
||||
|
||||
rc = moveToRoot(pCur);
|
||||
if( rc ){
|
||||
if( rc==SQLITE_EMPTY ){
|
||||
@@ -5854,14 +5646,12 @@ int sqlite3BtreeIndexMoveto(
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
bypass_moveto_root:
|
||||
assert( pCur->pPage );
|
||||
assert( pCur->pPage->isInit );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( pCur->pPage->nCell > 0 );
|
||||
assert( pCur->curIntKey==0 );
|
||||
assert( pIdxKey!=0 );
|
||||
assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey );
|
||||
assert( pCur->curIntKey || pIdxKey );
|
||||
for(;;){
|
||||
int lwr, upr, idx, c;
|
||||
Pgno chldPg;
|
||||
@@ -5875,10 +5665,11 @@ bypass_moveto_root:
|
||||
** be the right kind (index or table) of b-tree page. Otherwise
|
||||
** a moveToChild() or moveToRoot() call would have detected corruption. */
|
||||
assert( pPage->nCell>0 );
|
||||
assert( pPage->intKey==0 );
|
||||
assert( pPage->intKey==(pIdxKey==0) );
|
||||
lwr = 0;
|
||||
upr = pPage->nCell-1;
|
||||
idx = upr>>1; /* idx = (lwr+upr)/2; */
|
||||
pCur->ix = (u16)idx;
|
||||
for(;;){
|
||||
int nCell; /* Size of the pCell cell in bytes */
|
||||
pCell = findCellPastPtr(pPage, idx);
|
||||
@@ -6083,6 +5874,16 @@ static SQLITE_NOINLINE int btreeNext(BtCursor *pCur){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
|
||||
/* If the database file is corrupt, it is possible for the value of idx
|
||||
** to be invalid here. This can only occur if a second cursor modifies
|
||||
** the page while cursor pCur is holding a reference to it. Which can
|
||||
** only happen if the database is corrupt in such a way as to link the
|
||||
** page into more than one b-tree structure.
|
||||
**
|
||||
** Update 2019-12-23: appears to long longer be possible after the
|
||||
** addition of anotherValidCursor() condition on balance_deeper(). */
|
||||
harmless( idx>pPage->nCell );
|
||||
|
||||
if( idx>=pPage->nCell ){
|
||||
if( !pPage->leaf ){
|
||||
rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
|
||||
@@ -6994,24 +6795,16 @@ static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
|
||||
int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
|
||||
|
||||
if( *pRC ) return;
|
||||
assert( idx>=0 );
|
||||
assert( idx<pPage->nCell );
|
||||
assert( idx>=0 && idx<pPage->nCell );
|
||||
assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
|
||||
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
|
||||
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
|
||||
assert( pPage->nFree>=0 );
|
||||
data = pPage->aData;
|
||||
ptr = &pPage->aCellIdx[2*idx];
|
||||
assert( pPage->pBt->usableSize > (u32)(ptr-data) );
|
||||
pc = get2byte(ptr);
|
||||
hdr = pPage->hdrOffset;
|
||||
#if 0 /* Not required. Omit for efficiency */
|
||||
if( pc<hdr+pPage->nCell*2 ){
|
||||
*pRC = SQLITE_CORRUPT_BKPT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
testcase( pc==(u32)get2byte(&data[hdr+5]) );
|
||||
testcase( pc==get2byte(&data[hdr+5]) );
|
||||
testcase( pc+sz==pPage->pBt->usableSize );
|
||||
if( pc+sz > pPage->pBt->usableSize ){
|
||||
*pRC = SQLITE_CORRUPT_BKPT;
|
||||
@@ -7303,7 +7096,7 @@ static int rebuildPage(
|
||||
|
||||
assert( i<iEnd );
|
||||
j = get2byte(&aData[hdr+5]);
|
||||
if( j>(u32)usableSize ){ j = 0; }
|
||||
if( NEVER(j>(u32)usableSize) ){ j = 0; }
|
||||
memcpy(&pTmp[j], &aData[j], usableSize - j);
|
||||
|
||||
for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
|
||||
@@ -7534,7 +7327,6 @@ static int editPage(
|
||||
|
||||
pData = &aData[get2byteNotZero(&aData[hdr+5])];
|
||||
if( pData<pBegin ) goto editpage_fail;
|
||||
if( pData>pPg->aDataEnd ) goto editpage_fail;
|
||||
|
||||
/* Add cells to the start of the page */
|
||||
if( iNew<iOld ){
|
||||
@@ -7896,10 +7688,11 @@ static int balance_nonroot(
|
||||
Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
|
||||
Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */
|
||||
u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */
|
||||
CellArray b; /* Parsed information on cells being balanced */
|
||||
CellArray b; /* Parsed information on cells being balanced */
|
||||
|
||||
memset(abDone, 0, sizeof(abDone));
|
||||
memset(&b, 0, sizeof(b));
|
||||
b.nCell = 0;
|
||||
b.apCell = 0;
|
||||
pBt = pParent->pBt;
|
||||
assert( sqlite3_mutex_held(pBt->mutex) );
|
||||
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
|
||||
@@ -8710,7 +8503,7 @@ static int balance_deeper(MemPage *pRoot, MemPage **ppChild){
|
||||
** Return SQLITE_CORRUPT if any cursor other than pCur is currently valid
|
||||
** on the same B-tree as pCur.
|
||||
**
|
||||
** This can occur if a database is corrupt with two or more SQL tables
|
||||
** This can if a database is corrupt with two or more SQL tables
|
||||
** pointing to the same b-tree. If an insert occurs on one SQL table
|
||||
** and causes a BEFORE TRIGGER to do a secondary insert on the other SQL
|
||||
** table linked to the same b-tree. If the secondary insert causes a
|
||||
@@ -8939,7 +8732,7 @@ static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
|
||||
do{
|
||||
rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
|
||||
if( rc ) return rc;
|
||||
if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 || pPage->isInit ){
|
||||
if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}else{
|
||||
if( iOffset+ovflPageSize<(u32)nTotal ){
|
||||
@@ -8974,7 +8767,7 @@ static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
|
||||
** pX.pData,nData,nZero fields must be zero.
|
||||
**
|
||||
** If the seekResult parameter is non-zero, then a successful call to
|
||||
** sqlite3BtreeIndexMoveto() to seek cursor pCur to (pKey,nKey) has already
|
||||
** MovetoUnpacked() to seek cursor pCur to (pKey,nKey) has already
|
||||
** been performed. In other words, if seekResult!=0 then the cursor
|
||||
** is currently pointing to a cell that will be adjacent to the cell
|
||||
** to be inserted. If seekResult<0 then pCur points to a cell that is
|
||||
@@ -8992,7 +8785,7 @@ int sqlite3BtreeInsert(
|
||||
BtCursor *pCur, /* Insert data into the table of this cursor */
|
||||
const BtreePayload *pX, /* Content of the row to be inserted */
|
||||
int flags, /* True if this is likely an append */
|
||||
int seekResult /* Result of prior IndexMoveto() call */
|
||||
int seekResult /* Result of prior MovetoUnpacked() call */
|
||||
){
|
||||
int rc;
|
||||
int loc = seekResult; /* -1: before desired location +1: after */
|
||||
@@ -9144,7 +8937,7 @@ int sqlite3BtreeInsert(
|
||||
assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
|
||||
assert( pPage->leaf || !pPage->intKey );
|
||||
if( pPage->nFree<0 ){
|
||||
if( pCur->eState>CURSOR_INVALID ){
|
||||
if( NEVER(pCur->eState>CURSOR_INVALID) ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}else{
|
||||
rc = btreeComputeFreeSpace(pPage);
|
||||
@@ -9179,10 +8972,7 @@ int sqlite3BtreeInsert(
|
||||
idx = pCur->ix;
|
||||
if( loc==0 ){
|
||||
CellInfo info;
|
||||
assert( idx>=0 );
|
||||
if( idx>=pPage->nCell ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
assert( idx<pPage->nCell );
|
||||
rc = sqlite3PagerWrite(pPage->pDbPage);
|
||||
if( rc ){
|
||||
goto end_insert;
|
||||
@@ -9364,7 +9154,7 @@ int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 iKey){
|
||||
}
|
||||
}while( rc==SQLITE_OK && nOut>0 );
|
||||
|
||||
if( rc==SQLITE_OK && nRem>0 && ALWAYS(pPgnoOut) ){
|
||||
if( rc==SQLITE_OK && nRem>0 ){
|
||||
Pgno pgnoNew;
|
||||
MemPage *pNew = 0;
|
||||
rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
|
||||
@@ -9410,13 +9200,14 @@ int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 iKey){
|
||||
int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
Btree *p = pCur->pBtree;
|
||||
BtShared *pBt = p->pBt;
|
||||
int rc; /* Return code */
|
||||
MemPage *pPage; /* Page to delete cell from */
|
||||
unsigned char *pCell; /* Pointer to cell to delete */
|
||||
int iCellIdx; /* Index of cell to delete */
|
||||
int iCellDepth; /* Depth of node containing pCell */
|
||||
CellInfo info; /* Size of the cell being deleted */
|
||||
u8 bPreserve; /* Keep cursor valid. 2 for CURSOR_SKIPNEXT */
|
||||
int rc; /* Return code */
|
||||
MemPage *pPage; /* Page to delete cell from */
|
||||
unsigned char *pCell; /* Pointer to cell to delete */
|
||||
int iCellIdx; /* Index of cell to delete */
|
||||
int iCellDepth; /* Depth of node containing pCell */
|
||||
CellInfo info; /* Size of the cell being deleted */
|
||||
int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
|
||||
u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */
|
||||
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pBt->inTransaction==TRANS_WRITE );
|
||||
@@ -9435,34 +9226,21 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
iCellDepth = pCur->iPage;
|
||||
iCellIdx = pCur->ix;
|
||||
pPage = pCur->pPage;
|
||||
if( pPage->nCell<=iCellIdx ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
pCell = findCell(pPage, iCellIdx);
|
||||
if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ) return SQLITE_CORRUPT;
|
||||
|
||||
/* If the BTREE_SAVEPOSITION bit is on, then the cursor position must
|
||||
/* If the bPreserve flag is set to true, then the cursor position must
|
||||
** be preserved following this delete operation. If the current delete
|
||||
** will cause a b-tree rebalance, then this is done by saving the cursor
|
||||
** key and leaving the cursor in CURSOR_REQUIRESEEK state before
|
||||
** returning.
|
||||
**
|
||||
** If the current delete will not cause a rebalance, then the cursor
|
||||
** Or, if the current delete will not cause a rebalance, then the cursor
|
||||
** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
|
||||
** before or after the deleted entry.
|
||||
**
|
||||
** The bPreserve value records which path is required:
|
||||
**
|
||||
** bPreserve==0 Not necessary to save the cursor position
|
||||
** bPreserve==1 Use CURSOR_REQUIRESEEK to save the cursor position
|
||||
** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT.
|
||||
*/
|
||||
bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
|
||||
** before or after the deleted entry. In this case set bSkipnext to true. */
|
||||
if( bPreserve ){
|
||||
if( !pPage->leaf
|
||||
|| (pPage->nFree+pPage->xCellSize(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
|
||||
|| (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
|
||||
|| pPage->nCell==1 /* See dbfuzz001.test for a test case */
|
||||
){
|
||||
/* A b-tree rebalance will be required after deleting this entry.
|
||||
@@ -9470,7 +9248,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
rc = saveCursorKey(pCur);
|
||||
if( rc ) return rc;
|
||||
}else{
|
||||
bPreserve = 2;
|
||||
bSkipnext = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9570,8 +9348,8 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
if( bPreserve>1 ){
|
||||
assert( (pCur->iPage==iCellDepth || CORRUPT_DB) );
|
||||
if( bSkipnext ){
|
||||
assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) );
|
||||
assert( pPage==pCur->pPage || CORRUPT_DB );
|
||||
assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
|
||||
pCur->eState = CURSOR_SKIPNEXT;
|
||||
@@ -9780,12 +9558,11 @@ static int clearDatabasePage(
|
||||
}
|
||||
rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
|
||||
if( rc ) return rc;
|
||||
if( (pBt->openFlags & BTREE_SINGLE)==0
|
||||
&& sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
|
||||
){
|
||||
if( pPage->bBusy ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto cleardatabasepage_out;
|
||||
}
|
||||
pPage->bBusy = 1;
|
||||
hdr = pPage->hdrOffset;
|
||||
for(i=0; i<pPage->nCell; i++){
|
||||
pCell = findCell(pPage, i);
|
||||
@@ -9812,6 +9589,7 @@ static int clearDatabasePage(
|
||||
}
|
||||
|
||||
cleardatabasepage_out:
|
||||
pPage->bBusy = 0;
|
||||
releasePage(pPage);
|
||||
return rc;
|
||||
}
|
||||
@@ -9890,10 +9668,10 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
|
||||
rc = sqlite3BtreeClearTable(p, iTable, 0);
|
||||
if( rc ) return rc;
|
||||
rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
|
||||
if( NEVER(rc) ){
|
||||
if( rc ) return rc;
|
||||
rc = sqlite3BtreeClearTable(p, iTable, 0);
|
||||
if( rc ){
|
||||
releasePage(pPage);
|
||||
return rc;
|
||||
}
|
||||
|
||||
+3
-4
@@ -272,6 +272,7 @@ typedef struct CellInfo CellInfo;
|
||||
*/
|
||||
struct MemPage {
|
||||
u8 isInit; /* True if previously initialized. MUST BE FIRST! */
|
||||
u8 bBusy; /* Prevent endless loops on corrupt database files */
|
||||
u8 intKey; /* True if table b-trees. False for index b-trees */
|
||||
u8 intKeyLeaf; /* True if the leaf of an intKey table */
|
||||
Pgno pgno; /* Page number for this page */
|
||||
@@ -293,9 +294,7 @@ struct MemPage {
|
||||
u8 *apOvfl[4]; /* Pointers to the body of overflow cells */
|
||||
BtShared *pBt; /* Pointer to BtShared that this page is part of */
|
||||
u8 *aData; /* Pointer to disk image of the page data */
|
||||
u8 *aDataEnd; /* One byte past the end of the entire page - not just
|
||||
** the usable space, the entire page. Used to prevent
|
||||
** corruption-induced buffer overflow. */
|
||||
u8 *aDataEnd; /* One byte past the end of usable data */
|
||||
u8 *aCellIdx; /* The cell index area */
|
||||
u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */
|
||||
DbPage *pDbPage; /* Pager page handle */
|
||||
@@ -600,7 +599,7 @@ struct BtCursor {
|
||||
/*
|
||||
** The database page the PENDING_BYTE occupies. This page is never used.
|
||||
*/
|
||||
#define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/((pBt)->pageSize))+1))
|
||||
# define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt)
|
||||
|
||||
/*
|
||||
** These macros define the location of the pointer-map entry for a
|
||||
|
||||
+148
-402
File diff suppressed because it is too large
Load Diff
+1
-2
@@ -337,7 +337,6 @@ FuncDef *sqlite3FunctionSearch(
|
||||
){
|
||||
FuncDef *p;
|
||||
for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){
|
||||
assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
|
||||
if( sqlite3StrICmp(p->zName, zFunc)==0 ){
|
||||
return p;
|
||||
}
|
||||
@@ -358,7 +357,7 @@ void sqlite3InsertBuiltinFuncs(
|
||||
const char *zName = aDef[i].zName;
|
||||
int nName = sqlite3Strlen30(zName);
|
||||
int h = SQLITE_FUNC_HASH(zName[0], nName);
|
||||
assert( aDef[i].funcFlags & SQLITE_FUNC_BUILTIN );
|
||||
assert( zName[0]>='a' && zName[0]<='z' );
|
||||
pOther = sqlite3FunctionSearch(h, zName);
|
||||
if( pOther ){
|
||||
assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] );
|
||||
|
||||
+10
-13
@@ -1,11 +1,3 @@
|
||||
/* DO NOT EDIT!
|
||||
** This file is automatically generated by the script in the canonical
|
||||
** SQLite source tree at tool/mkctimec.tcl.
|
||||
**
|
||||
** To modify this header, edit any of the various lists in that script
|
||||
** which specify categories of generated conditionals in this file.
|
||||
*/
|
||||
|
||||
/*
|
||||
** 2010 February 23
|
||||
**
|
||||
@@ -54,6 +46,9 @@
|
||||
*/
|
||||
static const char * const sqlite3azCompileOpt[] = {
|
||||
|
||||
/*
|
||||
** BEGIN CODE GENERATED BY tool/mkctime.tcl
|
||||
*/
|
||||
#ifdef SQLITE_32BIT_ROWID
|
||||
"32BIT_ROWID",
|
||||
#endif
|
||||
@@ -262,6 +257,9 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_ENABLE_IOTRACE
|
||||
"ENABLE_IOTRACE",
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_JSON1
|
||||
"ENABLE_JSON1",
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_LOAD_EXTENSION
|
||||
"ENABLE_LOAD_EXTENSION",
|
||||
#endif
|
||||
@@ -585,9 +583,6 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS
|
||||
"OMIT_INTROSPECTION_PRAGMAS",
|
||||
#endif
|
||||
#ifdef SQLITE_OMIT_JSON
|
||||
"OMIT_JSON",
|
||||
#endif
|
||||
#ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
|
||||
"OMIT_LIKE_OPTIMIZATION",
|
||||
#endif
|
||||
@@ -776,8 +771,10 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_ZERO_MALLOC
|
||||
"ZERO_MALLOC",
|
||||
#endif
|
||||
|
||||
} ;
|
||||
/*
|
||||
** END CODE GENERATED BY tool/mkctime.tcl
|
||||
*/
|
||||
};
|
||||
|
||||
const char **sqlite3CompileOptions(int *pnOpt){
|
||||
*pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]);
|
||||
|
||||
+198
-305
@@ -503,10 +503,8 @@ static void clearYMD_HMS_TZ(DateTime *p){
|
||||
** is available. This routine returns 0 on success and
|
||||
** non-zero on any kind of error.
|
||||
**
|
||||
** If the sqlite3GlobalConfig.bLocaltimeFault variable is non-zero then this
|
||||
** routine will always fail. If bLocaltimeFault is nonzero and
|
||||
** sqlite3GlobalConfig.xAltLocaltime is not NULL, then xAltLocaltime() is
|
||||
** invoked in place of the OS-defined localtime() function.
|
||||
** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this
|
||||
** routine will always fail.
|
||||
**
|
||||
** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
|
||||
** library function localtime_r() is used to assist in the calculation of
|
||||
@@ -522,30 +520,14 @@ static int osLocaltime(time_t *t, struct tm *pTm){
|
||||
sqlite3_mutex_enter(mutex);
|
||||
pX = localtime(t);
|
||||
#ifndef SQLITE_UNTESTABLE
|
||||
if( sqlite3GlobalConfig.bLocaltimeFault ){
|
||||
if( sqlite3GlobalConfig.xAltLocaltime!=0
|
||||
&& 0==sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm)
|
||||
){
|
||||
pX = pTm;
|
||||
}else{
|
||||
pX = 0;
|
||||
}
|
||||
}
|
||||
if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
|
||||
#endif
|
||||
if( pX ) *pTm = *pX;
|
||||
#if SQLITE_THREADSAFE>0
|
||||
sqlite3_mutex_leave(mutex);
|
||||
#endif
|
||||
rc = pX==0;
|
||||
#else
|
||||
#ifndef SQLITE_UNTESTABLE
|
||||
if( sqlite3GlobalConfig.bLocaltimeFault ){
|
||||
if( sqlite3GlobalConfig.xAltLocaltime!=0 ){
|
||||
return sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm);
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
|
||||
#endif
|
||||
#if HAVE_LOCALTIME_R
|
||||
rc = localtime_r(t, pTm)==0;
|
||||
@@ -560,56 +542,67 @@ static int osLocaltime(time_t *t, struct tm *pTm){
|
||||
|
||||
#ifndef SQLITE_OMIT_LOCALTIME
|
||||
/*
|
||||
** Assuming the input DateTime is UTC, move it to its localtime equivalent.
|
||||
** Compute the difference (in milliseconds) between localtime and UTC
|
||||
** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
|
||||
** return this value and set *pRc to SQLITE_OK.
|
||||
**
|
||||
** Or, if an error does occur, set *pRc to SQLITE_ERROR. The returned value
|
||||
** is undefined in this case.
|
||||
*/
|
||||
static int toLocaltime(
|
||||
DateTime *p, /* Date at which to calculate offset */
|
||||
sqlite3_context *pCtx /* Write error here if one occurs */
|
||||
static sqlite3_int64 localtimeOffset(
|
||||
DateTime *p, /* Date at which to calculate offset */
|
||||
sqlite3_context *pCtx, /* Write error here if one occurs */
|
||||
int *pRc /* OUT: Error code. SQLITE_OK or ERROR */
|
||||
){
|
||||
DateTime x, y;
|
||||
time_t t;
|
||||
struct tm sLocal;
|
||||
int iYearDiff;
|
||||
|
||||
/* Initialize the contents of sLocal to avoid a compiler warning. */
|
||||
memset(&sLocal, 0, sizeof(sLocal));
|
||||
|
||||
computeJD(p);
|
||||
if( p->iJD<2108667600*(i64)100000 /* 1970-01-01 */
|
||||
|| p->iJD>2130141456*(i64)100000 /* 2038-01-18 */
|
||||
){
|
||||
x = *p;
|
||||
computeYMD_HMS(&x);
|
||||
if( x.Y<1971 || x.Y>=2038 ){
|
||||
/* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only
|
||||
** works for years between 1970 and 2037. For dates outside this range,
|
||||
** SQLite attempts to map the year into an equivalent year within this
|
||||
** range, do the calculation, then map the year back.
|
||||
*/
|
||||
DateTime x = *p;
|
||||
computeYMD_HMS(&x);
|
||||
iYearDiff = (2000 + x.Y%4) - x.Y;
|
||||
x.Y += iYearDiff;
|
||||
x.validJD = 0;
|
||||
computeJD(&x);
|
||||
t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
|
||||
}else{
|
||||
iYearDiff = 0;
|
||||
t = (time_t)(p->iJD/1000 - 21086676*(i64)10000);
|
||||
x.Y = 2000;
|
||||
x.M = 1;
|
||||
x.D = 1;
|
||||
x.h = 0;
|
||||
x.m = 0;
|
||||
x.s = 0.0;
|
||||
} else {
|
||||
int s = (int)(x.s + 0.5);
|
||||
x.s = s;
|
||||
}
|
||||
x.tz = 0;
|
||||
x.validJD = 0;
|
||||
computeJD(&x);
|
||||
t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
|
||||
if( osLocaltime(&t, &sLocal) ){
|
||||
sqlite3_result_error(pCtx, "local time unavailable", -1);
|
||||
return SQLITE_ERROR;
|
||||
*pRc = SQLITE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
p->Y = sLocal.tm_year + 1900 - iYearDiff;
|
||||
p->M = sLocal.tm_mon + 1;
|
||||
p->D = sLocal.tm_mday;
|
||||
p->h = sLocal.tm_hour;
|
||||
p->m = sLocal.tm_min;
|
||||
p->s = sLocal.tm_sec + (p->iJD%1000)*0.001;
|
||||
p->validYMD = 1;
|
||||
p->validHMS = 1;
|
||||
p->validJD = 0;
|
||||
p->rawS = 0;
|
||||
p->validTZ = 0;
|
||||
p->isError = 0;
|
||||
return SQLITE_OK;
|
||||
y.Y = sLocal.tm_year + 1900;
|
||||
y.M = sLocal.tm_mon + 1;
|
||||
y.D = sLocal.tm_mday;
|
||||
y.h = sLocal.tm_hour;
|
||||
y.m = sLocal.tm_min;
|
||||
y.s = sLocal.tm_sec;
|
||||
y.validYMD = 1;
|
||||
y.validHMS = 1;
|
||||
y.validJD = 0;
|
||||
y.rawS = 0;
|
||||
y.validTZ = 0;
|
||||
y.isError = 0;
|
||||
computeJD(&y);
|
||||
*pRc = SQLITE_OK;
|
||||
return y.iJD - x.iJD;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_LOCALTIME */
|
||||
|
||||
@@ -622,17 +615,18 @@ static int toLocaltime(
|
||||
** of several units of time.
|
||||
*/
|
||||
static const struct {
|
||||
u8 nName; /* Length of the name */
|
||||
char zName[7]; /* Name of the transformation */
|
||||
float rLimit; /* Maximum NNN value for this transform */
|
||||
float rXform; /* Constant used for this transform */
|
||||
u8 eType; /* Transformation type code */
|
||||
u8 nName; /* Length of th name */
|
||||
char *zName; /* Name of the transformation */
|
||||
double rLimit; /* Maximum NNN value for this transform */
|
||||
double rXform; /* Constant used for this transform */
|
||||
} aXformType[] = {
|
||||
{ 6, "second", 4.6427e+14, 1.0 },
|
||||
{ 6, "minute", 7.7379e+12, 60.0 },
|
||||
{ 4, "hour", 1.2897e+11, 3600.0 },
|
||||
{ 3, "day", 5373485.0, 86400.0 },
|
||||
{ 5, "month", 176546.0, 2592000.0 },
|
||||
{ 4, "year", 14713.0, 31536000.0 },
|
||||
{ 0, 6, "second", 464269060800.0, 1000.0 },
|
||||
{ 0, 6, "minute", 7737817680.0, 60000.0 },
|
||||
{ 0, 4, "hour", 128963628.0, 3600000.0 },
|
||||
{ 0, 3, "day", 5373485.0, 86400000.0 },
|
||||
{ 1, 5, "month", 176546.0, 2592000000.0 },
|
||||
{ 2, 4, "year", 14713.0, 31536000000.0 },
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -663,55 +657,11 @@ static int parseModifier(
|
||||
sqlite3_context *pCtx, /* Function context */
|
||||
const char *z, /* The text of the modifier */
|
||||
int n, /* Length of zMod in bytes */
|
||||
DateTime *p, /* The date/time value to be modified */
|
||||
int idx /* Parameter index of the modifier */
|
||||
DateTime *p /* The date/time value to be modified */
|
||||
){
|
||||
int rc = 1;
|
||||
double r;
|
||||
switch(sqlite3UpperToLower[(u8)z[0]] ){
|
||||
case 'a': {
|
||||
/*
|
||||
** auto
|
||||
**
|
||||
** If rawS is available, then interpret as a julian day number, or
|
||||
** a unix timestamp, depending on its magnitude.
|
||||
*/
|
||||
if( sqlite3_stricmp(z, "auto")==0 ){
|
||||
if( idx>1 ) return 1; /* IMP: R-33611-57934 */
|
||||
if( !p->rawS || p->validJD ){
|
||||
rc = 0;
|
||||
p->rawS = 0;
|
||||
}else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */
|
||||
&& p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */
|
||||
){
|
||||
r = p->s*1000.0 + 210866760000000.0;
|
||||
clearYMD_HMS_TZ(p);
|
||||
p->iJD = (sqlite3_int64)(r + 0.5);
|
||||
p->validJD = 1;
|
||||
p->rawS = 0;
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'j': {
|
||||
/*
|
||||
** julianday
|
||||
**
|
||||
** Always interpret the prior number as a julian-day value. If this
|
||||
** is not the first modifier, or if the prior argument is not a numeric
|
||||
** value in the allowed range of julian day numbers understood by
|
||||
** SQLite (0..5373484.5) then the result will be NULL.
|
||||
*/
|
||||
if( sqlite3_stricmp(z, "julianday")==0 ){
|
||||
if( idx>1 ) return 1; /* IMP: R-31176-64601 */
|
||||
if( p->validJD && p->rawS ){
|
||||
rc = 0;
|
||||
p->rawS = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_LOCALTIME
|
||||
case 'l': {
|
||||
/* localtime
|
||||
@@ -720,7 +670,9 @@ static int parseModifier(
|
||||
** show local time.
|
||||
*/
|
||||
if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){
|
||||
rc = toLocaltime(p, pCtx);
|
||||
computeJD(p);
|
||||
p->iJD += localtimeOffset(p, pCtx, &rc);
|
||||
clearYMD_HMS_TZ(p);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -733,7 +685,6 @@ static int parseModifier(
|
||||
** seconds since 1970. Convert to a real julian day number.
|
||||
*/
|
||||
if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
|
||||
if( idx>1 ) return 1; /* IMP: R-49255-55373 */
|
||||
r = p->s*1000.0 + 210866760000000.0;
|
||||
if( r>=0.0 && r<464269060800000.0 ){
|
||||
clearYMD_HMS_TZ(p);
|
||||
@@ -746,31 +697,18 @@ static int parseModifier(
|
||||
#ifndef SQLITE_OMIT_LOCALTIME
|
||||
else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){
|
||||
if( p->tzSet==0 ){
|
||||
i64 iOrigJD; /* Original localtime */
|
||||
i64 iGuess; /* Guess at the corresponding utc time */
|
||||
int cnt = 0; /* Safety to prevent infinite loop */
|
||||
int iErr; /* Guess is off by this much */
|
||||
|
||||
sqlite3_int64 c1;
|
||||
computeJD(p);
|
||||
iGuess = iOrigJD = p->iJD;
|
||||
iErr = 0;
|
||||
do{
|
||||
DateTime new;
|
||||
memset(&new, 0, sizeof(new));
|
||||
iGuess -= iErr;
|
||||
new.iJD = iGuess;
|
||||
new.validJD = 1;
|
||||
rc = toLocaltime(&new, pCtx);
|
||||
if( rc ) return rc;
|
||||
computeJD(&new);
|
||||
iErr = new.iJD - iOrigJD;
|
||||
}while( iErr && cnt++<3 );
|
||||
memset(p, 0, sizeof(*p));
|
||||
p->iJD = iGuess;
|
||||
p->validJD = 1;
|
||||
c1 = localtimeOffset(p, pCtx, &rc);
|
||||
if( rc==SQLITE_OK ){
|
||||
p->iJD -= c1;
|
||||
clearYMD_HMS_TZ(p);
|
||||
p->iJD += c1 - localtimeOffset(p, pCtx, &rc);
|
||||
}
|
||||
p->tzSet = 1;
|
||||
}else{
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
@@ -886,10 +824,9 @@ static int parseModifier(
|
||||
&& sqlite3_strnicmp(aXformType[i].zName, z, n)==0
|
||||
&& r>-aXformType[i].rLimit && r<aXformType[i].rLimit
|
||||
){
|
||||
switch( i ){
|
||||
case 4: { /* Special processing to add months */
|
||||
switch( aXformType[i].eType ){
|
||||
case 1: { /* Special processing to add months */
|
||||
int x;
|
||||
assert( strcmp(aXformType[i].zName,"month")==0 );
|
||||
computeYMD_HMS(p);
|
||||
p->M += (int)r;
|
||||
x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
|
||||
@@ -899,9 +836,8 @@ static int parseModifier(
|
||||
r -= (int)r;
|
||||
break;
|
||||
}
|
||||
case 5: { /* Special processing to add years */
|
||||
case 2: { /* Special processing to add years */
|
||||
int y = (int)r;
|
||||
assert( strcmp(aXformType[i].zName,"year")==0 );
|
||||
computeYMD_HMS(p);
|
||||
p->Y += y;
|
||||
p->validJD = 0;
|
||||
@@ -910,7 +846,7 @@ static int parseModifier(
|
||||
}
|
||||
}
|
||||
computeJD(p);
|
||||
p->iJD += (sqlite3_int64)(r*1000.0*aXformType[i].rXform + rRounder);
|
||||
p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder);
|
||||
rc = 0;
|
||||
break;
|
||||
}
|
||||
@@ -960,7 +896,7 @@ static int isDate(
|
||||
for(i=1; i<argc; i++){
|
||||
z = sqlite3_value_text(argv[i]);
|
||||
n = sqlite3_value_bytes(argv[i]);
|
||||
if( z==0 || parseModifier(context, (char*)z, n, p, i) ) return 1;
|
||||
if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
|
||||
}
|
||||
computeJD(p);
|
||||
if( p->isError || !validJulianDay(p->iJD) ) return 1;
|
||||
@@ -990,24 +926,6 @@ static void juliandayFunc(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** unixepoch( TIMESTRING, MOD, MOD, ...)
|
||||
**
|
||||
** Return the number of seconds (including fractional seconds) since
|
||||
** the unix epoch of 1970-01-01 00:00:00 GMT.
|
||||
*/
|
||||
static void unixepochFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(context, argc, argv, &x)==0 ){
|
||||
computeJD(&x);
|
||||
sqlite3_result_int64(context, x.iJD/1000 - 21086676*(i64)10000);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** datetime( TIMESTRING, MOD, MOD, ...)
|
||||
**
|
||||
@@ -1020,38 +938,11 @@ static void datetimeFunc(
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(context, argc, argv, &x)==0 ){
|
||||
int Y, s;
|
||||
char zBuf[24];
|
||||
char zBuf[100];
|
||||
computeYMD_HMS(&x);
|
||||
Y = x.Y;
|
||||
if( Y<0 ) Y = -Y;
|
||||
zBuf[1] = '0' + (Y/1000)%10;
|
||||
zBuf[2] = '0' + (Y/100)%10;
|
||||
zBuf[3] = '0' + (Y/10)%10;
|
||||
zBuf[4] = '0' + (Y)%10;
|
||||
zBuf[5] = '-';
|
||||
zBuf[6] = '0' + (x.M/10)%10;
|
||||
zBuf[7] = '0' + (x.M)%10;
|
||||
zBuf[8] = '-';
|
||||
zBuf[9] = '0' + (x.D/10)%10;
|
||||
zBuf[10] = '0' + (x.D)%10;
|
||||
zBuf[11] = ' ';
|
||||
zBuf[12] = '0' + (x.h/10)%10;
|
||||
zBuf[13] = '0' + (x.h)%10;
|
||||
zBuf[14] = ':';
|
||||
zBuf[15] = '0' + (x.m/10)%10;
|
||||
zBuf[16] = '0' + (x.m)%10;
|
||||
zBuf[17] = ':';
|
||||
s = (int)x.s;
|
||||
zBuf[18] = '0' + (s/10)%10;
|
||||
zBuf[19] = '0' + (s)%10;
|
||||
zBuf[20] = 0;
|
||||
if( x.Y<0 ){
|
||||
zBuf[0] = '-';
|
||||
sqlite3_result_text(context, zBuf, 20, SQLITE_TRANSIENT);
|
||||
}else{
|
||||
sqlite3_result_text(context, &zBuf[1], 19, SQLITE_TRANSIENT);
|
||||
}
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d %02d:%02d:%02d",
|
||||
x.Y, x.M, x.D, x.h, x.m, (int)(x.s));
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1067,20 +958,10 @@ static void timeFunc(
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(context, argc, argv, &x)==0 ){
|
||||
int s;
|
||||
char zBuf[16];
|
||||
char zBuf[100];
|
||||
computeHMS(&x);
|
||||
zBuf[0] = '0' + (x.h/10)%10;
|
||||
zBuf[1] = '0' + (x.h)%10;
|
||||
zBuf[2] = ':';
|
||||
zBuf[3] = '0' + (x.m/10)%10;
|
||||
zBuf[4] = '0' + (x.m)%10;
|
||||
zBuf[5] = ':';
|
||||
s = (int)x.s;
|
||||
zBuf[6] = '0' + (s/10)%10;
|
||||
zBuf[7] = '0' + (s)%10;
|
||||
zBuf[8] = 0;
|
||||
sqlite3_result_text(context, zBuf, 8, SQLITE_TRANSIENT);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1096,28 +977,10 @@ static void dateFunc(
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(context, argc, argv, &x)==0 ){
|
||||
int Y;
|
||||
char zBuf[16];
|
||||
char zBuf[100];
|
||||
computeYMD(&x);
|
||||
Y = x.Y;
|
||||
if( Y<0 ) Y = -Y;
|
||||
zBuf[1] = '0' + (Y/1000)%10;
|
||||
zBuf[2] = '0' + (Y/100)%10;
|
||||
zBuf[3] = '0' + (Y/10)%10;
|
||||
zBuf[4] = '0' + (Y)%10;
|
||||
zBuf[5] = '-';
|
||||
zBuf[6] = '0' + (x.M/10)%10;
|
||||
zBuf[7] = '0' + (x.M)%10;
|
||||
zBuf[8] = '-';
|
||||
zBuf[9] = '0' + (x.D/10)%10;
|
||||
zBuf[10] = '0' + (x.D)%10;
|
||||
zBuf[11] = 0;
|
||||
if( x.Y<0 ){
|
||||
zBuf[0] = '-';
|
||||
sqlite3_result_text(context, zBuf, 11, SQLITE_TRANSIENT);
|
||||
}else{
|
||||
sqlite3_result_text(context, &zBuf[1], 10, SQLITE_TRANSIENT);
|
||||
}
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1146,100 +1009,131 @@ static void strftimeFunc(
|
||||
sqlite3_value **argv
|
||||
){
|
||||
DateTime x;
|
||||
u64 n;
|
||||
size_t i,j;
|
||||
char *z;
|
||||
sqlite3 *db;
|
||||
const char *zFmt;
|
||||
sqlite3_str sRes;
|
||||
|
||||
|
||||
char zBuf[100];
|
||||
if( argc==0 ) return;
|
||||
zFmt = (const char*)sqlite3_value_text(argv[0]);
|
||||
if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
|
||||
db = sqlite3_context_db_handle(context);
|
||||
sqlite3StrAccumInit(&sRes, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
|
||||
|
||||
for(i=0, n=1; zFmt[i]; i++, n++){
|
||||
if( zFmt[i]=='%' ){
|
||||
switch( zFmt[i+1] ){
|
||||
case 'd':
|
||||
case 'H':
|
||||
case 'm':
|
||||
case 'M':
|
||||
case 'S':
|
||||
case 'W':
|
||||
n++;
|
||||
/* fall thru */
|
||||
case 'w':
|
||||
case '%':
|
||||
break;
|
||||
case 'f':
|
||||
n += 8;
|
||||
break;
|
||||
case 'j':
|
||||
n += 3;
|
||||
break;
|
||||
case 'Y':
|
||||
n += 8;
|
||||
break;
|
||||
case 's':
|
||||
case 'J':
|
||||
n += 50;
|
||||
break;
|
||||
default:
|
||||
return; /* ERROR. return a NULL */
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
testcase( n==sizeof(zBuf)-1 );
|
||||
testcase( n==sizeof(zBuf) );
|
||||
testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
|
||||
testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] );
|
||||
if( n<sizeof(zBuf) ){
|
||||
z = zBuf;
|
||||
}else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
|
||||
sqlite3_result_error_toobig(context);
|
||||
return;
|
||||
}else{
|
||||
z = sqlite3DbMallocRawNN(db, (int)n);
|
||||
if( z==0 ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
return;
|
||||
}
|
||||
}
|
||||
computeJD(&x);
|
||||
computeYMD_HMS(&x);
|
||||
for(i=j=0; zFmt[i]; i++){
|
||||
if( zFmt[i]!='%' ) continue;
|
||||
if( j<i ) sqlite3_str_append(&sRes, zFmt+j, (int)(i-j));
|
||||
i++;
|
||||
j = i + 1;
|
||||
switch( zFmt[i] ){
|
||||
case 'd': {
|
||||
sqlite3_str_appendf(&sRes, "%02d", x.D);
|
||||
break;
|
||||
}
|
||||
case 'f': {
|
||||
double s = x.s;
|
||||
if( s>59.999 ) s = 59.999;
|
||||
sqlite3_str_appendf(&sRes, "%06.3f", s);
|
||||
break;
|
||||
}
|
||||
case 'H': {
|
||||
sqlite3_str_appendf(&sRes, "%02d", x.h);
|
||||
break;
|
||||
}
|
||||
case 'W': /* Fall thru */
|
||||
case 'j': {
|
||||
int nDay; /* Number of days since 1st day of year */
|
||||
DateTime y = x;
|
||||
y.validJD = 0;
|
||||
y.M = 1;
|
||||
y.D = 1;
|
||||
computeJD(&y);
|
||||
nDay = (int)((x.iJD-y.iJD+43200000)/86400000);
|
||||
if( zFmt[i]=='W' ){
|
||||
int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */
|
||||
wd = (int)(((x.iJD+43200000)/86400000)%7);
|
||||
sqlite3_str_appendf(&sRes,"%02d",(nDay+7-wd)/7);
|
||||
}else{
|
||||
sqlite3_str_appendf(&sRes,"%03d",nDay+1);
|
||||
if( zFmt[i]!='%' ){
|
||||
z[j++] = zFmt[i];
|
||||
}else{
|
||||
i++;
|
||||
switch( zFmt[i] ){
|
||||
case 'd': sqlite3_snprintf(3, &z[j],"%02d",x.D); j+=2; break;
|
||||
case 'f': {
|
||||
double s = x.s;
|
||||
if( s>59.999 ) s = 59.999;
|
||||
sqlite3_snprintf(7, &z[j],"%06.3f", s);
|
||||
j += sqlite3Strlen30(&z[j]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'J': {
|
||||
sqlite3_str_appendf(&sRes,"%.16g",x.iJD/86400000.0);
|
||||
break;
|
||||
}
|
||||
case 'm': {
|
||||
sqlite3_str_appendf(&sRes,"%02d",x.M);
|
||||
break;
|
||||
}
|
||||
case 'M': {
|
||||
sqlite3_str_appendf(&sRes,"%02d",x.m);
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000);
|
||||
sqlite3_str_appendf(&sRes,"%lld",iS);
|
||||
break;
|
||||
}
|
||||
case 'S': {
|
||||
sqlite3_str_appendf(&sRes,"%02d",(int)x.s);
|
||||
break;
|
||||
}
|
||||
case 'w': {
|
||||
sqlite3_str_appendchar(&sRes, 1,
|
||||
(char)(((x.iJD+129600000)/86400000) % 7) + '0');
|
||||
break;
|
||||
}
|
||||
case 'Y': {
|
||||
sqlite3_str_appendf(&sRes,"%04d",x.Y);
|
||||
break;
|
||||
}
|
||||
case '%': {
|
||||
sqlite3_str_appendchar(&sRes, 1, '%');
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sqlite3_str_reset(&sRes);
|
||||
return;
|
||||
case 'H': sqlite3_snprintf(3, &z[j],"%02d",x.h); j+=2; break;
|
||||
case 'W': /* Fall thru */
|
||||
case 'j': {
|
||||
int nDay; /* Number of days since 1st day of year */
|
||||
DateTime y = x;
|
||||
y.validJD = 0;
|
||||
y.M = 1;
|
||||
y.D = 1;
|
||||
computeJD(&y);
|
||||
nDay = (int)((x.iJD-y.iJD+43200000)/86400000);
|
||||
if( zFmt[i]=='W' ){
|
||||
int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */
|
||||
wd = (int)(((x.iJD+43200000)/86400000)%7);
|
||||
sqlite3_snprintf(3, &z[j],"%02d",(nDay+7-wd)/7);
|
||||
j += 2;
|
||||
}else{
|
||||
sqlite3_snprintf(4, &z[j],"%03d",nDay+1);
|
||||
j += 3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'J': {
|
||||
sqlite3_snprintf(20, &z[j],"%.16g",x.iJD/86400000.0);
|
||||
j+=sqlite3Strlen30(&z[j]);
|
||||
break;
|
||||
}
|
||||
case 'm': sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break;
|
||||
case 'M': sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break;
|
||||
case 's': {
|
||||
i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000);
|
||||
sqlite3Int64ToText(iS, &z[j]);
|
||||
j += sqlite3Strlen30(&z[j]);
|
||||
break;
|
||||
}
|
||||
case 'S': sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break;
|
||||
case 'w': {
|
||||
z[j++] = (char)(((x.iJD+129600000)/86400000) % 7) + '0';
|
||||
break;
|
||||
}
|
||||
case 'Y': {
|
||||
sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=sqlite3Strlen30(&z[j]);
|
||||
break;
|
||||
}
|
||||
default: z[j++] = '%'; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( j<i ) sqlite3_str_append(&sRes, zFmt+j, (int)(i-j));
|
||||
sqlite3ResultStrAccum(context, &sRes);
|
||||
z[j] = 0;
|
||||
sqlite3_result_text(context, z, -1,
|
||||
z==zBuf ? SQLITE_TRANSIENT : SQLITE_DYNAMIC);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1339,7 +1233,6 @@ void sqlite3RegisterDateTimeFunctions(void){
|
||||
static FuncDef aDateTimeFuncs[] = {
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
PURE_DATE(julianday, -1, 0, 0, juliandayFunc ),
|
||||
PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ),
|
||||
PURE_DATE(date, -1, 0, 0, dateFunc ),
|
||||
PURE_DATE(time, -1, 0, 0, timeFunc ),
|
||||
PURE_DATE(datetime, -1, 0, 0, datetimeFunc ),
|
||||
|
||||
+1
-2
@@ -156,7 +156,6 @@ static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
){
|
||||
pIdxInfo->orderByConsumed = 1;
|
||||
}
|
||||
sqlite3VtabWriteAll(pIdxInfo);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -334,7 +333,7 @@ static int dbpageUpdate(
|
||||
goto update_fail;
|
||||
}
|
||||
pBt = pTab->db->aDb[iDb].pBt;
|
||||
if( pgno<1 || pBt==0 || pgno>sqlite3BtreeLastPage(pBt) ){
|
||||
if( pgno<1 || pBt==0 || pgno>(int)sqlite3BtreeLastPage(pBt) ){
|
||||
zErr = "bad page number";
|
||||
goto update_fail;
|
||||
}
|
||||
|
||||
+12
-59
@@ -25,15 +25,6 @@
|
||||
#if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
|
||||
&& !defined(SQLITE_OMIT_VIRTUALTABLE)
|
||||
|
||||
/*
|
||||
** The pager and btree modules arrange objects in memory so that there are
|
||||
** always approximately 200 bytes of addressable memory following each page
|
||||
** buffer. This way small buffer overreads caused by corrupt database pages
|
||||
** do not cause undefined behaviour. This module pads each page buffer
|
||||
** by the following number of bytes for the same purpose.
|
||||
*/
|
||||
#define DBSTAT_PAGE_PADDING_BYTES 256
|
||||
|
||||
/*
|
||||
** Page paths:
|
||||
**
|
||||
@@ -101,8 +92,9 @@ struct StatCell {
|
||||
/* Size information for a single btree page */
|
||||
struct StatPage {
|
||||
u32 iPgno; /* Page number */
|
||||
u8 *aPg; /* Page buffer from sqlite3_malloc() */
|
||||
DbPage *pPg; /* Page content */
|
||||
int iCell; /* Current cell */
|
||||
|
||||
char *zPath; /* Path to this page */
|
||||
|
||||
/* Variables populated by statDecodePage(): */
|
||||
@@ -314,25 +306,18 @@ static void statClearCells(StatPage *p){
|
||||
}
|
||||
|
||||
static void statClearPage(StatPage *p){
|
||||
u8 *aPg = p->aPg;
|
||||
statClearCells(p);
|
||||
sqlite3PagerUnref(p->pPg);
|
||||
sqlite3_free(p->zPath);
|
||||
memset(p, 0, sizeof(StatPage));
|
||||
p->aPg = aPg;
|
||||
}
|
||||
|
||||
static void statResetCsr(StatCursor *pCsr){
|
||||
int i;
|
||||
/* In some circumstances, specifically if an OOM has occurred, the call
|
||||
** to sqlite3_reset() may cause the pager to be reset (emptied). It is
|
||||
** important that statClearPage() is called to free any page refs before
|
||||
** this happens. dbsqlfuzz 9ed3e4e3816219d3509d711636c38542bf3f40b1. */
|
||||
sqlite3_reset(pCsr->pStmt);
|
||||
for(i=0; i<ArraySize(pCsr->aPage); i++){
|
||||
statClearPage(&pCsr->aPage[i]);
|
||||
sqlite3_free(pCsr->aPage[i].aPg);
|
||||
pCsr->aPage[i].aPg = 0;
|
||||
}
|
||||
sqlite3_reset(pCsr->pStmt);
|
||||
pCsr->iPage = 0;
|
||||
sqlite3_free(pCsr->zPath);
|
||||
pCsr->zPath = 0;
|
||||
@@ -397,7 +382,7 @@ static int statDecodePage(Btree *pBt, StatPage *p){
|
||||
int isLeaf;
|
||||
int szPage;
|
||||
|
||||
u8 *aData = p->aPg;
|
||||
u8 *aData = sqlite3PagerGetData(p->pPg);
|
||||
u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0];
|
||||
|
||||
p->flags = aHdr[0];
|
||||
@@ -468,7 +453,7 @@ static int statDecodePage(Btree *pBt, StatPage *p){
|
||||
if( nPayload>(u32)nLocal ){
|
||||
int j;
|
||||
int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
|
||||
if( iOff+nLocal+4>nUsable || nPayload>0x7fffffff ){
|
||||
if( iOff+nLocal>nUsable || nPayload>0x7fffffff ){
|
||||
goto statPageIsCorrupt;
|
||||
}
|
||||
pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
|
||||
@@ -527,38 +512,6 @@ static void statSizeAndOffset(StatCursor *pCsr){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Load a copy of the page data for page iPg into the buffer belonging
|
||||
** to page object pPg. Allocate the buffer if necessary. Return SQLITE_OK
|
||||
** if successful, or an SQLite error code otherwise.
|
||||
*/
|
||||
static int statGetPage(
|
||||
Btree *pBt, /* Load page from this b-tree */
|
||||
u32 iPg, /* Page number to load */
|
||||
StatPage *pPg /* Load page into this object */
|
||||
){
|
||||
int pgsz = sqlite3BtreeGetPageSize(pBt);
|
||||
DbPage *pDbPage = 0;
|
||||
int rc;
|
||||
|
||||
if( pPg->aPg==0 ){
|
||||
pPg->aPg = (u8*)sqlite3_malloc(pgsz + DBSTAT_PAGE_PADDING_BYTES);
|
||||
if( pPg->aPg==0 ){
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
memset(&pPg->aPg[pgsz], 0, DBSTAT_PAGE_PADDING_BYTES);
|
||||
}
|
||||
|
||||
rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPg, &pDbPage, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
const u8 *a = sqlite3PagerGetData(pDbPage);
|
||||
memcpy(pPg->aPg, a, pgsz);
|
||||
sqlite3PagerUnref(pDbPage);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Move a DBSTAT cursor to the next entry. Normally, the next
|
||||
** entry will be the next page, but in aggregated mode (pCsr->isAgg!=0),
|
||||
@@ -577,7 +530,7 @@ static int statNext(sqlite3_vtab_cursor *pCursor){
|
||||
pCsr->zPath = 0;
|
||||
|
||||
statNextRestart:
|
||||
if( pCsr->iPage<0 ){
|
||||
if( pCsr->aPage[0].pPg==0 ){
|
||||
/* Start measuring space on the next btree */
|
||||
statResetCounts(pCsr);
|
||||
rc = sqlite3_step(pCsr->pStmt);
|
||||
@@ -589,7 +542,7 @@ statNextRestart:
|
||||
pCsr->isEof = 1;
|
||||
return sqlite3_reset(pCsr->pStmt);
|
||||
}
|
||||
rc = statGetPage(pBt, iRoot, &pCsr->aPage[0]);
|
||||
rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg, 0);
|
||||
pCsr->aPage[0].iPgno = iRoot;
|
||||
pCsr->aPage[0].iCell = 0;
|
||||
if( !pCsr->isAgg ){
|
||||
@@ -640,8 +593,9 @@ statNextRestart:
|
||||
|
||||
if( !p->iRightChildPg || p->iCell>p->nCell ){
|
||||
statClearPage(p);
|
||||
pCsr->iPage--;
|
||||
if( pCsr->isAgg && pCsr->iPage<0 ){
|
||||
if( pCsr->iPage>0 ){
|
||||
pCsr->iPage--;
|
||||
}else if( pCsr->isAgg ){
|
||||
/* label-statNext-done: When computing aggregate space usage over
|
||||
** an entire btree, this is the exit point from this function */
|
||||
return SQLITE_OK;
|
||||
@@ -660,7 +614,7 @@ statNextRestart:
|
||||
}else{
|
||||
p[1].iPgno = p->aCell[p->iCell].iChildPg;
|
||||
}
|
||||
rc = statGetPage(pBt, p[1].iPgno, &p[1]);
|
||||
rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg, 0);
|
||||
pCsr->nPage++;
|
||||
p[1].iCell = 0;
|
||||
if( !pCsr->isAgg ){
|
||||
@@ -790,7 +744,6 @@ static int statFilter(
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
pCsr->iPage = -1;
|
||||
rc = statNext(pCursor);
|
||||
}
|
||||
return rc;
|
||||
|
||||
+11
-22
@@ -44,16 +44,6 @@ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
return pTab;
|
||||
}
|
||||
|
||||
/* Generate byte-code that will report the number of rows modified
|
||||
** by a DELETE, INSERT, or UPDATE statement.
|
||||
*/
|
||||
void sqlite3CodeChangeCount(Vdbe *v, int regCounter, const char *zColName){
|
||||
sqlite3VdbeAddOp0(v, OP_FkCheck);
|
||||
sqlite3VdbeAddOp2(v, OP_ResultRow, regCounter, 1);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zColName, SQLITE_STATIC);
|
||||
}
|
||||
|
||||
/* Return true if table pTab is read-only.
|
||||
**
|
||||
** A table is read-only if any of the following are true:
|
||||
@@ -94,7 +84,7 @@ int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
return 1;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_VIEW
|
||||
if( !viewOk && IsView(pTab) ){
|
||||
if( !viewOk && pTab->pSelect ){
|
||||
sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName);
|
||||
return 1;
|
||||
}
|
||||
@@ -198,13 +188,13 @@ Expr *sqlite3LimitWhere(
|
||||
}else{
|
||||
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
|
||||
if( pPk->nKeyCol==1 ){
|
||||
const char *zName = pTab->aCol[pPk->aiColumn[0]].zCnName;
|
||||
const char *zName = pTab->aCol[pPk->aiColumn[0]].zName;
|
||||
pLhs = sqlite3Expr(db, TK_ID, zName);
|
||||
pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
|
||||
}else{
|
||||
int i;
|
||||
for(i=0; i<pPk->nKeyCol; i++){
|
||||
Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName);
|
||||
Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zName);
|
||||
pEList = sqlite3ExprListAppend(pParse, pEList, p);
|
||||
}
|
||||
pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
|
||||
@@ -220,7 +210,6 @@ Expr *sqlite3LimitWhere(
|
||||
pSelectSrc = sqlite3SrcListDup(db, pSrc, 0);
|
||||
pSrc->a[0].pTab = pTab;
|
||||
if( pSrc->a[0].fg.isIndexedBy ){
|
||||
assert( pSrc->a[0].fg.isCte==0 );
|
||||
pSrc->a[0].u2.pIBIndex = 0;
|
||||
pSrc->a[0].fg.isIndexedBy = 0;
|
||||
sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy);
|
||||
@@ -293,11 +282,9 @@ void sqlite3DeleteFrom(
|
||||
|
||||
memset(&sContext, 0, sizeof(sContext));
|
||||
db = pParse->db;
|
||||
assert( db->pParse==pParse );
|
||||
if( pParse->nErr ){
|
||||
if( pParse->nErr || db->mallocFailed ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
assert( db->mallocFailed==0 );
|
||||
assert( pTabList->nSrc==1 );
|
||||
|
||||
|
||||
@@ -314,7 +301,7 @@ void sqlite3DeleteFrom(
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
|
||||
isView = IsView(pTab);
|
||||
isView = pTab->pSelect!=0;
|
||||
#else
|
||||
# define pTrigger 0
|
||||
# define isView 0
|
||||
@@ -478,7 +465,7 @@ void sqlite3DeleteFrom(
|
||||
** ONEPASS_SINGLE: One-pass approach - at most one row deleted.
|
||||
** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted.
|
||||
*/
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,0,wcf,iTabCur+1);
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, wcf, iTabCur+1);
|
||||
if( pWInfo==0 ) goto delete_from_cleanup;
|
||||
eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
|
||||
assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
|
||||
@@ -564,7 +551,7 @@ void sqlite3DeleteFrom(
|
||||
if( eOnePass!=ONEPASS_OFF ){
|
||||
assert( nKey==nPk ); /* OP_Found will use an unpacked key */
|
||||
if( !IsVirtual(pTab) && aToOpen[iDataCur-iTabCur] ){
|
||||
assert( pPk!=0 || IsView(pTab) );
|
||||
assert( pPk!=0 || pTab->pSelect!=0 );
|
||||
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
|
||||
VdbeCoverage(v);
|
||||
}
|
||||
@@ -631,7 +618,9 @@ void sqlite3DeleteFrom(
|
||||
** invoke the callback function.
|
||||
*/
|
||||
if( memCnt ){
|
||||
sqlite3CodeChangeCount(v, memCnt, "rows deleted");
|
||||
sqlite3VdbeAddOp2(v, OP_ChngCntRow, memCnt, 1);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC);
|
||||
}
|
||||
|
||||
delete_from_cleanup:
|
||||
@@ -796,7 +785,7 @@ void sqlite3GenerateRowDelete(
|
||||
** the update-hook is not invoked for rows removed by REPLACE, but the
|
||||
** pre-update-hook is.
|
||||
*/
|
||||
if( !IsView(pTab) ){
|
||||
if( pTab->pSelect==0 ){
|
||||
u8 p5 = 0;
|
||||
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
|
||||
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
|
||||
|
||||
+205
-335
File diff suppressed because it is too large
Load Diff
+24
-47
@@ -215,9 +215,7 @@ int sqlite3FkLocateIndex(
|
||||
*/
|
||||
if( pParent->iPKey>=0 ){
|
||||
if( !zKey ) return 0;
|
||||
if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zCnName, zKey) ){
|
||||
return 0;
|
||||
}
|
||||
if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zName, zKey) ) return 0;
|
||||
}
|
||||
}else if( paiCol ){
|
||||
assert( nCol>1 );
|
||||
@@ -259,11 +257,11 @@ int sqlite3FkLocateIndex(
|
||||
/* If the index uses a collation sequence that is different from
|
||||
** the default collation sequence for the column, this index is
|
||||
** unusable. Bail out early in this case. */
|
||||
zDfltColl = sqlite3ColumnColl(&pParent->aCol[iCol]);
|
||||
zDfltColl = pParent->aCol[iCol].zColl;
|
||||
if( !zDfltColl ) zDfltColl = sqlite3StrBINARY;
|
||||
if( sqlite3StrICmp(pIdx->azColl[i], zDfltColl) ) break;
|
||||
|
||||
zIdxCol = pParent->aCol[iCol].zCnName;
|
||||
zIdxCol = pParent->aCol[iCol].zName;
|
||||
for(j=0; j<nCol; j++){
|
||||
if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){
|
||||
if( aiCol ) aiCol[i] = pFKey->aCol[j].iFrom;
|
||||
@@ -487,7 +485,7 @@ static Expr *exprTableRegister(
|
||||
pCol = &pTab->aCol[iCol];
|
||||
pExpr->iTable = regBase + sqlite3TableColumnToStorage(pTab,iCol) + 1;
|
||||
pExpr->affExpr = pCol->affinity;
|
||||
zColl = sqlite3ColumnColl(pCol);
|
||||
zColl = pCol->zColl;
|
||||
if( zColl==0 ) zColl = db->pDfltColl->zName;
|
||||
pExpr = sqlite3ExprAddCollateString(pParse, pExpr, zColl);
|
||||
}else{
|
||||
@@ -510,7 +508,6 @@ static Expr *exprTableColumn(
|
||||
){
|
||||
Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
|
||||
if( pExpr ){
|
||||
assert( ExprUseYTab(pExpr) );
|
||||
pExpr->y.pTab = pTab;
|
||||
pExpr->iTable = iCursor;
|
||||
pExpr->iColumn = iCol;
|
||||
@@ -597,7 +594,7 @@ static void fkScanChildren(
|
||||
pLeft = exprTableRegister(pParse, pTab, regData, iCol);
|
||||
iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
|
||||
assert( iCol>=0 );
|
||||
zCol = pFKey->pFrom->aCol[iCol].zCnName;
|
||||
zCol = pFKey->pFrom->aCol[iCol].zName;
|
||||
pRight = sqlite3Expr(db, TK_ID, zCol);
|
||||
pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
|
||||
pWhere = sqlite3ExprAnd(pParse, pWhere, pEq);
|
||||
@@ -632,7 +629,7 @@ static void fkScanChildren(
|
||||
i16 iCol = pIdx->aiColumn[i];
|
||||
assert( iCol>=0 );
|
||||
pLeft = exprTableRegister(pParse, pTab, regData, iCol);
|
||||
pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zCnName);
|
||||
pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zName);
|
||||
pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight);
|
||||
pAll = sqlite3ExprAnd(pParse, pAll, pEq);
|
||||
}
|
||||
@@ -651,7 +648,7 @@ static void fkScanChildren(
|
||||
** clause. For each row found, increment either the deferred or immediate
|
||||
** foreign key constraint counter. */
|
||||
if( pParse->nErr==0 ){
|
||||
pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0, 0);
|
||||
pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
|
||||
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
|
||||
if( pWInfo ){
|
||||
sqlite3WhereEnd(pWInfo);
|
||||
@@ -702,25 +699,6 @@ static void fkTriggerDelete(sqlite3 *dbMem, Trigger *p){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Clear the apTrigger[] cache of CASCADE triggers for all foreign keys
|
||||
** in a particular database. This needs to happen when the schema
|
||||
** changes.
|
||||
*/
|
||||
void sqlite3FkClearTriggerCache(sqlite3 *db, int iDb){
|
||||
HashElem *k;
|
||||
Hash *pHash = &db->aDb[iDb].pSchema->tblHash;
|
||||
for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k)){
|
||||
Table *pTab = sqliteHashData(k);
|
||||
FKey *pFKey;
|
||||
if( !IsOrdinaryTable(pTab) ) continue;
|
||||
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
|
||||
fkTriggerDelete(db, pFKey->apTrigger[0]); pFKey->apTrigger[0] = 0;
|
||||
fkTriggerDelete(db, pFKey->apTrigger[1]); pFKey->apTrigger[1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is called to generate code that runs when table pTab is
|
||||
** being dropped from the database. The SrcList passed as the second argument
|
||||
@@ -740,12 +718,12 @@ void sqlite3FkClearTriggerCache(sqlite3 *db, int iDb){
|
||||
*/
|
||||
void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
|
||||
sqlite3 *db = pParse->db;
|
||||
if( (db->flags&SQLITE_ForeignKeys) && IsOrdinaryTable(pTab) ){
|
||||
if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){
|
||||
int iSkip = 0;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
|
||||
assert( v ); /* VDBE has already been allocated */
|
||||
assert( IsOrdinaryTable(pTab) );
|
||||
assert( pTab->pSelect==0 ); /* Not a view */
|
||||
if( sqlite3FkReferences(pTab)==0 ){
|
||||
/* Search for a deferred foreign key constraint for which this table
|
||||
** is the child table. If one cannot be found, return without
|
||||
@@ -753,7 +731,7 @@ void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
|
||||
** the entire DELETE if there are no outstanding deferred constraints
|
||||
** when this statement is run. */
|
||||
FKey *p;
|
||||
for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
|
||||
for(p=pTab->pFKey; p; p=p->pNextFrom){
|
||||
if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
|
||||
}
|
||||
if( !p ) return;
|
||||
@@ -842,7 +820,7 @@ static int fkParentIsModified(
|
||||
if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
|
||||
Column *pCol = &pTab->aCol[iKey];
|
||||
if( zKey ){
|
||||
if( 0==sqlite3StrICmp(pCol->zCnName, zKey) ) return 1;
|
||||
if( 0==sqlite3StrICmp(pCol->zName, zKey) ) return 1;
|
||||
}else if( pCol->colFlags & COLFLAG_PRIMKEY ){
|
||||
return 1;
|
||||
}
|
||||
@@ -909,14 +887,13 @@ void sqlite3FkCheck(
|
||||
|
||||
/* If foreign-keys are disabled, this function is a no-op. */
|
||||
if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
|
||||
if( !IsOrdinaryTable(pTab) ) return;
|
||||
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
zDb = db->aDb[iDb].zDbSName;
|
||||
|
||||
/* Loop through all the foreign key constraints for which pTab is the
|
||||
** child table (the table that the foreign key definition is part of). */
|
||||
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
|
||||
for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
|
||||
Table *pTo; /* Parent table of foreign key pFKey */
|
||||
Index *pIdx = 0; /* Index on key columns in pTo */
|
||||
int *aiFree = 0;
|
||||
@@ -983,7 +960,7 @@ void sqlite3FkCheck(
|
||||
** values read from the parent table are NULL. */
|
||||
if( db->xAuth ){
|
||||
int rcauth;
|
||||
char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zCnName;
|
||||
char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
|
||||
rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
|
||||
bIgnore = (rcauth==SQLITE_IGNORE);
|
||||
}
|
||||
@@ -1098,10 +1075,10 @@ u32 sqlite3FkOldmask(
|
||||
Table *pTab /* Table being modified */
|
||||
){
|
||||
u32 mask = 0;
|
||||
if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){
|
||||
if( pParse->db->flags&SQLITE_ForeignKeys ){
|
||||
FKey *p;
|
||||
int i;
|
||||
for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
|
||||
for(p=pTab->pFKey; p; p=p->pNextFrom){
|
||||
for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
|
||||
}
|
||||
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
|
||||
@@ -1151,19 +1128,19 @@ int sqlite3FkRequired(
|
||||
){
|
||||
int eRet = 1; /* Value to return if bHaveFK is true */
|
||||
int bHaveFK = 0; /* If FK processing is required */
|
||||
if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){
|
||||
if( pParse->db->flags&SQLITE_ForeignKeys ){
|
||||
if( !aChange ){
|
||||
/* A DELETE operation. Foreign key processing is required if the
|
||||
** table in question is either the child or parent table for any
|
||||
** foreign key constraint. */
|
||||
bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey);
|
||||
bHaveFK = (sqlite3FkReferences(pTab) || pTab->pFKey);
|
||||
}else{
|
||||
/* This is an UPDATE. Foreign key processing is only required if the
|
||||
** operation modifies one or more child or parent key columns. */
|
||||
FKey *p;
|
||||
|
||||
/* Check if any child key columns are being modified. */
|
||||
for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
|
||||
for(p=pTab->pFKey; p; p=p->pNextFrom){
|
||||
if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
|
||||
if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2;
|
||||
bHaveFK = 1;
|
||||
@@ -1256,8 +1233,8 @@ static Trigger *fkActionTrigger(
|
||||
assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
|
||||
assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
|
||||
sqlite3TokenInit(&tToCol,
|
||||
pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zCnName);
|
||||
sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zCnName);
|
||||
pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName);
|
||||
sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zName);
|
||||
|
||||
/* Create the expression "OLD.zToCol = zFromCol". It is important
|
||||
** that the "OLD.zToCol" term is on the LHS of the = operator, so
|
||||
@@ -1302,7 +1279,7 @@ static Trigger *fkActionTrigger(
|
||||
testcase( pCol->colFlags & COLFLAG_STORED );
|
||||
pDflt = 0;
|
||||
}else{
|
||||
pDflt = sqlite3ColumnExpr(pFKey->pFrom, pCol);
|
||||
pDflt = pCol->pDflt;
|
||||
}
|
||||
if( pDflt ){
|
||||
pNew = sqlite3ExprDup(db, pDflt, 0);
|
||||
@@ -1439,9 +1416,9 @@ void sqlite3FkDelete(sqlite3 *db, Table *pTab){
|
||||
FKey *pFKey; /* Iterator variable */
|
||||
FKey *pNext; /* Copy of pFKey->pNextFrom */
|
||||
|
||||
assert( IsOrdinaryTable(pTab) );
|
||||
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
|
||||
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
|
||||
assert( db==0 || IsVirtual(pTab)
|
||||
|| sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
|
||||
for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
|
||||
|
||||
/* Remove the FK from the fkeyHash hash table. */
|
||||
if( !db || db->pnBytesFreed==0 ){
|
||||
|
||||
+103
-200
@@ -97,18 +97,6 @@ static void typeofFunc(
|
||||
sqlite3_result_text(context, azType[i], -1, SQLITE_STATIC);
|
||||
}
|
||||
|
||||
/* subtype(X)
|
||||
**
|
||||
** Return the subtype of X
|
||||
*/
|
||||
static void subtypeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
UNUSED_PARAMETER(argc);
|
||||
sqlite3_result_int(context, sqlite3_value_subtype(argv[0]));
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the length() function
|
||||
@@ -270,7 +258,7 @@ endInstrOOM:
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the printf() (a.k.a. format()) SQL function.
|
||||
** Implementation of the printf() function.
|
||||
*/
|
||||
static void printfFunc(
|
||||
sqlite3_context *context,
|
||||
@@ -583,9 +571,9 @@ static void last_insert_rowid(
|
||||
/*
|
||||
** Implementation of the changes() SQL function.
|
||||
**
|
||||
** IMP: R-32760-32347 The changes() SQL function is a wrapper
|
||||
** around the sqlite3_changes64() C/C++ function and hence follows the
|
||||
** same rules for counting changes.
|
||||
** IMP: R-62073-11209 The changes() SQL function is a wrapper
|
||||
** around the sqlite3_changes64() C/C++ function and hence follows the same
|
||||
** rules for counting changes.
|
||||
*/
|
||||
static void changes(
|
||||
sqlite3_context *context,
|
||||
@@ -608,8 +596,8 @@ static void total_changes(
|
||||
){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
/* IMP: R-11217-42568 This function is a wrapper around the
|
||||
** sqlite3_total_changes64() C/C++ interface. */
|
||||
/* IMP: R-52756-41993 This function was a wrapper around the
|
||||
** sqlite3_total_changes() C/C++ interface. */
|
||||
sqlite3_result_int64(context, sqlite3_total_changes64(db));
|
||||
}
|
||||
|
||||
@@ -1039,42 +1027,39 @@ static const char hexdigits[] = {
|
||||
};
|
||||
|
||||
/*
|
||||
** Append to pStr text that is the SQL literal representation of the
|
||||
** value contained in pValue.
|
||||
** Implementation of the QUOTE() function. This function takes a single
|
||||
** argument. If the argument is numeric, the return value is the same as
|
||||
** the argument. If the argument is NULL, the return value is the string
|
||||
** "NULL". Otherwise, the argument is enclosed in single quotes with
|
||||
** single-quote escapes.
|
||||
*/
|
||||
void sqlite3QuoteValue(StrAccum *pStr, sqlite3_value *pValue){
|
||||
/* As currently implemented, the string must be initially empty.
|
||||
** we might relax this requirement in the future, but that will
|
||||
** require enhancements to the implementation. */
|
||||
assert( pStr!=0 && pStr->nChar==0 );
|
||||
|
||||
switch( sqlite3_value_type(pValue) ){
|
||||
static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
switch( sqlite3_value_type(argv[0]) ){
|
||||
case SQLITE_FLOAT: {
|
||||
double r1, r2;
|
||||
const char *zVal;
|
||||
r1 = sqlite3_value_double(pValue);
|
||||
sqlite3_str_appendf(pStr, "%!.15g", r1);
|
||||
zVal = sqlite3_str_value(pStr);
|
||||
if( zVal ){
|
||||
sqlite3AtoF(zVal, &r2, pStr->nChar, SQLITE_UTF8);
|
||||
if( r1!=r2 ){
|
||||
sqlite3_str_reset(pStr);
|
||||
sqlite3_str_appendf(pStr, "%!.20e", r1);
|
||||
}
|
||||
char zBuf[50];
|
||||
r1 = sqlite3_value_double(argv[0]);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.15g", r1);
|
||||
sqlite3AtoF(zBuf, &r2, 20, SQLITE_UTF8);
|
||||
if( r1!=r2 ){
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.20e", r1);
|
||||
}
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
break;
|
||||
}
|
||||
case SQLITE_INTEGER: {
|
||||
sqlite3_str_appendf(pStr, "%lld", sqlite3_value_int64(pValue));
|
||||
sqlite3_result_value(context, argv[0]);
|
||||
break;
|
||||
}
|
||||
case SQLITE_BLOB: {
|
||||
char const *zBlob = sqlite3_value_blob(pValue);
|
||||
int nBlob = sqlite3_value_bytes(pValue);
|
||||
assert( zBlob==sqlite3_value_blob(pValue) ); /* No encoding change */
|
||||
sqlite3StrAccumEnlarge(pStr, nBlob*2 + 4);
|
||||
if( pStr->accError==0 ){
|
||||
char *zText = pStr->zText;
|
||||
char *zText = 0;
|
||||
char const *zBlob = sqlite3_value_blob(argv[0]);
|
||||
int nBlob = sqlite3_value_bytes(argv[0]);
|
||||
assert( zBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
|
||||
zText = (char *)contextMalloc(context, (2*(i64)nBlob)+4);
|
||||
if( zText ){
|
||||
int i;
|
||||
for(i=0; i<nBlob; i++){
|
||||
zText[(i*2)+2] = hexdigits[(zBlob[i]>>4)&0x0F];
|
||||
@@ -1084,48 +1069,42 @@ void sqlite3QuoteValue(StrAccum *pStr, sqlite3_value *pValue){
|
||||
zText[(nBlob*2)+3] = '\0';
|
||||
zText[0] = 'X';
|
||||
zText[1] = '\'';
|
||||
pStr->nChar = nBlob*2 + 3;
|
||||
sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_free(zText);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SQLITE_TEXT: {
|
||||
const unsigned char *zArg = sqlite3_value_text(pValue);
|
||||
sqlite3_str_appendf(pStr, "%Q", zArg);
|
||||
int i,j;
|
||||
u64 n;
|
||||
const unsigned char *zArg = sqlite3_value_text(argv[0]);
|
||||
char *z;
|
||||
|
||||
if( zArg==0 ) return;
|
||||
for(i=0, n=0; zArg[i]; i++){ if( zArg[i]=='\'' ) n++; }
|
||||
z = contextMalloc(context, ((i64)i)+((i64)n)+3);
|
||||
if( z ){
|
||||
z[0] = '\'';
|
||||
for(i=0, j=1; zArg[i]; i++){
|
||||
z[j++] = zArg[i];
|
||||
if( zArg[i]=='\'' ){
|
||||
z[j++] = '\'';
|
||||
}
|
||||
}
|
||||
z[j++] = '\'';
|
||||
z[j] = 0;
|
||||
sqlite3_result_text(context, z, j, sqlite3_free);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
assert( sqlite3_value_type(pValue)==SQLITE_NULL );
|
||||
sqlite3_str_append(pStr, "NULL", 4);
|
||||
assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
|
||||
sqlite3_result_text(context, "NULL", 4, SQLITE_STATIC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the QUOTE() function.
|
||||
**
|
||||
** The quote(X) function returns the text of an SQL literal which is the
|
||||
** value of its argument suitable for inclusion into an SQL statement.
|
||||
** Strings are surrounded by single-quotes with escapes on interior quotes
|
||||
** as needed. BLOBs are encoded as hexadecimal literals. Strings with
|
||||
** embedded NUL characters cannot be represented as string literals in SQL
|
||||
** and hence the returned string literal is truncated prior to the first NUL.
|
||||
*/
|
||||
static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
sqlite3_str str;
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
|
||||
sqlite3QuoteValue(&str,argv[0]);
|
||||
sqlite3_result_text(context, sqlite3StrAccumFinish(&str), str.nChar,
|
||||
SQLITE_DYNAMIC);
|
||||
if( str.accError!=SQLITE_OK ){
|
||||
sqlite3_result_null(context);
|
||||
sqlite3_result_error_code(context, str.accError);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** The unicode() function. Return the integer unicode code-point value
|
||||
** for the first character of the input string.
|
||||
@@ -1736,167 +1715,97 @@ static void minMaxFinalize(sqlite3_context *context){
|
||||
|
||||
/*
|
||||
** group_concat(EXPR, ?SEPARATOR?)
|
||||
**
|
||||
** The SEPARATOR goes before the EXPR string. This is tragic. The
|
||||
** groupConcatInverse() implementation would have been easier if the
|
||||
** SEPARATOR were appended after EXPR. And the order is undocumented,
|
||||
** so we could change it, in theory. But the old behavior has been
|
||||
** around for so long that we dare not, for fear of breaking something.
|
||||
*/
|
||||
typedef struct {
|
||||
StrAccum str; /* The accumulated concatenation */
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
int nAccum; /* Number of strings presently concatenated */
|
||||
int nFirstSepLength; /* Used to detect separator length change */
|
||||
/* If pnSepLengths!=0, refs an array of inter-string separator lengths,
|
||||
** stored as actually incorporated into presently accumulated result.
|
||||
** (Hence, its slots in use number nAccum-1 between method calls.)
|
||||
** If pnSepLengths==0, nFirstSepLength is the length used throughout.
|
||||
*/
|
||||
int *pnSepLengths;
|
||||
#endif
|
||||
} GroupConcatCtx;
|
||||
|
||||
static void groupConcatStep(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *zVal;
|
||||
GroupConcatCtx *pGCC;
|
||||
StrAccum *pAccum;
|
||||
const char *zSep;
|
||||
int nVal, nSep;
|
||||
assert( argc==1 || argc==2 );
|
||||
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
|
||||
pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC));
|
||||
if( pGCC ){
|
||||
pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
|
||||
|
||||
if( pAccum ){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
int firstTerm = pGCC->str.mxAlloc==0;
|
||||
pGCC->str.mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
|
||||
if( argc==1 ){
|
||||
if( !firstTerm ){
|
||||
sqlite3_str_appendchar(&pGCC->str, 1, ',');
|
||||
int firstTerm = pAccum->mxAlloc==0;
|
||||
pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
|
||||
if( !firstTerm ){
|
||||
if( argc==2 ){
|
||||
zSep = (char*)sqlite3_value_text(argv[1]);
|
||||
nSep = sqlite3_value_bytes(argv[1]);
|
||||
}else{
|
||||
zSep = ",";
|
||||
nSep = 1;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
else{
|
||||
pGCC->nFirstSepLength = 1;
|
||||
}
|
||||
#endif
|
||||
}else if( !firstTerm ){
|
||||
zSep = (char*)sqlite3_value_text(argv[1]);
|
||||
nSep = sqlite3_value_bytes(argv[1]);
|
||||
if( zSep ){
|
||||
sqlite3_str_append(&pGCC->str, zSep, nSep);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
else{
|
||||
nSep = 0;
|
||||
}
|
||||
if( nSep != pGCC->nFirstSepLength || pGCC->pnSepLengths != 0 ){
|
||||
int *pnsl = pGCC->pnSepLengths;
|
||||
if( pnsl == 0 ){
|
||||
/* First separator length variation seen, start tracking them. */
|
||||
pnsl = (int*)sqlite3_malloc64((pGCC->nAccum+1) * sizeof(int));
|
||||
if( pnsl!=0 ){
|
||||
int i = 0, nA = pGCC->nAccum-1;
|
||||
while( i<nA ) pnsl[i++] = pGCC->nFirstSepLength;
|
||||
}
|
||||
}else{
|
||||
pnsl = (int*)sqlite3_realloc64(pnsl, pGCC->nAccum * sizeof(int));
|
||||
}
|
||||
if( pnsl!=0 ){
|
||||
if( ALWAYS(pGCC->nAccum>0) ){
|
||||
pnsl[pGCC->nAccum-1] = nSep;
|
||||
}
|
||||
pGCC->pnSepLengths = pnsl;
|
||||
}else{
|
||||
sqlite3StrAccumSetError(&pGCC->str, SQLITE_NOMEM);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if( zSep ) sqlite3_str_append(pAccum, zSep, nSep);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
else{
|
||||
pGCC->nFirstSepLength = sqlite3_value_bytes(argv[1]);
|
||||
}
|
||||
pGCC->nAccum += 1;
|
||||
#endif
|
||||
zVal = (char*)sqlite3_value_text(argv[0]);
|
||||
nVal = sqlite3_value_bytes(argv[0]);
|
||||
if( zVal ) sqlite3_str_append(&pGCC->str, zVal, nVal);
|
||||
if( zVal ) sqlite3_str_append(pAccum, zVal, nVal);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
static void groupConcatInverse(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
GroupConcatCtx *pGCC;
|
||||
int n;
|
||||
StrAccum *pAccum;
|
||||
assert( argc==1 || argc==2 );
|
||||
(void)argc; /* Suppress unused parameter warning */
|
||||
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
|
||||
pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC));
|
||||
/* pGCC is always non-NULL since groupConcatStep() will have always
|
||||
pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
|
||||
/* pAccum is always non-NULL since groupConcatStep() will have always
|
||||
** run frist to initialize it */
|
||||
if( ALWAYS(pGCC) ){
|
||||
int nVS;
|
||||
/* Must call sqlite3_value_text() to convert the argument into text prior
|
||||
** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */
|
||||
(void)sqlite3_value_text(argv[0]);
|
||||
nVS = sqlite3_value_bytes(argv[0]);
|
||||
pGCC->nAccum -= 1;
|
||||
if( pGCC->pnSepLengths!=0 ){
|
||||
assert(pGCC->nAccum >= 0);
|
||||
if( pGCC->nAccum>0 ){
|
||||
nVS += *pGCC->pnSepLengths;
|
||||
memmove(pGCC->pnSepLengths, pGCC->pnSepLengths+1,
|
||||
(pGCC->nAccum-1)*sizeof(int));
|
||||
}
|
||||
if( ALWAYS(pAccum) ){
|
||||
n = sqlite3_value_bytes(argv[0]);
|
||||
if( argc==2 ){
|
||||
n += sqlite3_value_bytes(argv[1]);
|
||||
}else{
|
||||
/* If removing single accumulated string, harmlessly over-do. */
|
||||
nVS += pGCC->nFirstSepLength;
|
||||
n++;
|
||||
}
|
||||
if( nVS>=(int)pGCC->str.nChar ){
|
||||
pGCC->str.nChar = 0;
|
||||
if( n>=(int)pAccum->nChar ){
|
||||
pAccum->nChar = 0;
|
||||
}else{
|
||||
pGCC->str.nChar -= nVS;
|
||||
memmove(pGCC->str.zText, &pGCC->str.zText[nVS], pGCC->str.nChar);
|
||||
}
|
||||
if( pGCC->str.nChar==0 ){
|
||||
pGCC->str.mxAlloc = 0;
|
||||
sqlite3_free(pGCC->pnSepLengths);
|
||||
pGCC->pnSepLengths = 0;
|
||||
pAccum->nChar -= n;
|
||||
memmove(pAccum->zText, &pAccum->zText[n], pAccum->nChar);
|
||||
}
|
||||
if( pAccum->nChar==0 ) pAccum->mxAlloc = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define groupConcatInverse 0
|
||||
#endif /* SQLITE_OMIT_WINDOWFUNC */
|
||||
static void groupConcatFinalize(sqlite3_context *context){
|
||||
GroupConcatCtx *pGCC
|
||||
= (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
|
||||
if( pGCC ){
|
||||
sqlite3ResultStrAccum(context, &pGCC->str);
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
sqlite3_free(pGCC->pnSepLengths);
|
||||
#endif
|
||||
StrAccum *pAccum;
|
||||
pAccum = sqlite3_aggregate_context(context, 0);
|
||||
if( pAccum ){
|
||||
if( pAccum->accError==SQLITE_TOOBIG ){
|
||||
sqlite3_result_error_toobig(context);
|
||||
}else if( pAccum->accError==SQLITE_NOMEM ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
}else{
|
||||
sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1,
|
||||
sqlite3_free);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
static void groupConcatValue(sqlite3_context *context){
|
||||
GroupConcatCtx *pGCC
|
||||
= (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
|
||||
if( pGCC ){
|
||||
StrAccum *pAccum = &pGCC->str;
|
||||
sqlite3_str *pAccum;
|
||||
pAccum = (sqlite3_str*)sqlite3_aggregate_context(context, 0);
|
||||
if( pAccum ){
|
||||
if( pAccum->accError==SQLITE_TOOBIG ){
|
||||
sqlite3_result_error_toobig(context);
|
||||
}else if( pAccum->accError==SQLITE_NOMEM ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
}else{
|
||||
const char *zText = sqlite3_str_value(pAccum);
|
||||
sqlite3_result_text(context, zText, pAccum->nChar, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1960,12 +1869,11 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
|
||||
int nExpr;
|
||||
assert( pExpr!=0 );
|
||||
assert( pExpr->op==TK_FUNCTION );
|
||||
assert( ExprUseXList(pExpr) );
|
||||
if( !pExpr->x.pList ){
|
||||
return 0;
|
||||
}
|
||||
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
|
||||
nExpr = pExpr->x.pList->nExpr;
|
||||
assert( !ExprHasProperty(pExpr, EP_IntValue) );
|
||||
pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
|
||||
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
|
||||
if( pDef==0 ) return 0;
|
||||
@@ -1989,7 +1897,6 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
|
||||
Expr *pEscape = pExpr->x.pList->a[2].pExpr;
|
||||
char *zEscape;
|
||||
if( pEscape->op!=TK_STRING ) return 0;
|
||||
assert( !ExprHasProperty(pEscape, EP_IntValue) );
|
||||
zEscape = pEscape->u.zToken;
|
||||
if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
|
||||
if( zEscape[0]==aWc[0] ) return 0;
|
||||
@@ -2216,12 +2123,12 @@ void sqlite3RegisterBuiltinFunctions(void){
|
||||
*/
|
||||
static FuncDef aBuiltinFunc[] = {
|
||||
/***** Functions only available with SQLITE_TESTCTRL_INTERNAL_FUNCTIONS *****/
|
||||
#if !defined(SQLITE_UNTESTABLE)
|
||||
TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0),
|
||||
TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0),
|
||||
TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0),
|
||||
TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
|
||||
#endif /* !defined(SQLITE_UNTESTABLE) */
|
||||
#ifdef SQLITE_DEBUG
|
||||
TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0),
|
||||
#endif
|
||||
/***** Regular functions *****/
|
||||
#ifdef SQLITE_SOUNDEX
|
||||
FUNCTION(soundex, 1, 0, 0, soundexFunc ),
|
||||
@@ -2241,8 +2148,8 @@ void sqlite3RegisterBuiltinFunctions(void){
|
||||
INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
|
||||
INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
|
||||
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
{1, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_OFFSET|SQLITE_FUNC_TYPEOF,
|
||||
0, 0, noopFunc, 0, 0, 0, "sqlite_offset", {0} },
|
||||
FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET|
|
||||
SQLITE_FUNC_TYPEOF),
|
||||
#endif
|
||||
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
|
||||
FUNCTION(ltrim, 2, 1, 0, trimFunc ),
|
||||
@@ -2259,11 +2166,9 @@ void sqlite3RegisterBuiltinFunctions(void){
|
||||
WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
|
||||
SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
|
||||
FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
|
||||
FUNCTION2(subtype, 1, 0, 0, subtypeFunc, SQLITE_FUNC_TYPEOF),
|
||||
FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
|
||||
FUNCTION(instr, 2, 0, 0, instrFunc ),
|
||||
FUNCTION(printf, -1, 0, 0, printfFunc ),
|
||||
FUNCTION(format, -1, 0, 0, printfFunc ),
|
||||
FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
|
||||
FUNCTION(char, -1, 0, 0, charFunc ),
|
||||
FUNCTION(abs, 1, 0, 0, absFunc ),
|
||||
@@ -2362,7 +2267,6 @@ void sqlite3RegisterBuiltinFunctions(void){
|
||||
#endif
|
||||
sqlite3WindowFunctions();
|
||||
sqlite3RegisterDateTimeFunctions();
|
||||
sqlite3RegisterJsonFunctions();
|
||||
sqlite3InsertBuiltinFuncs(aBuiltinFunc, ArraySize(aBuiltinFunc));
|
||||
|
||||
#if 0 /* Enable to print out how the built-in functions are hashed */
|
||||
@@ -2374,7 +2278,6 @@ void sqlite3RegisterBuiltinFunctions(void){
|
||||
for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash){
|
||||
int n = sqlite3Strlen30(p->zName);
|
||||
int h = p->zName[0] + n;
|
||||
assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
|
||||
printf(" %s(%d)", p->zName, h);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
@@ -286,13 +286,9 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = {
|
||||
0, /* xTestCallback */
|
||||
#endif
|
||||
0, /* bLocaltimeFault */
|
||||
0, /* xAltLocaltime */
|
||||
0x7ffffffe, /* iOnceResetThreshold */
|
||||
SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
|
||||
0, /* iPrngSeed */
|
||||
#ifdef SQLITE_DEBUG
|
||||
{0,0,0,0,0,0} /* aTune */
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -302,18 +298,6 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = {
|
||||
*/
|
||||
FuncDefHash sqlite3BuiltinFunctions;
|
||||
|
||||
#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
|
||||
/*
|
||||
** Counter used for coverage testing. Does not come into play for
|
||||
** release builds.
|
||||
**
|
||||
** Access to this global variable is not mutex protected. This might
|
||||
** result in TSAN warnings. But as the variable does not exist in
|
||||
** release builds, that should not be a concern.
|
||||
*/
|
||||
unsigned int sqlite3CoverageCounter;
|
||||
#endif /* SQLITE_COVERAGE_TEST || SQLITE_DEBUG */
|
||||
|
||||
#ifdef VDBE_PROFILE
|
||||
/*
|
||||
** The following performance counter can be used in place of
|
||||
@@ -363,45 +347,3 @@ const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER;
|
||||
** Name of the default collating sequence
|
||||
*/
|
||||
const char sqlite3StrBINARY[] = "BINARY";
|
||||
|
||||
/*
|
||||
** Standard typenames. These names must match the COLTYPE_* definitions.
|
||||
** Adjust the SQLITE_N_STDTYPE value if adding or removing entries.
|
||||
**
|
||||
** sqlite3StdType[] The actual names of the datatypes.
|
||||
**
|
||||
** sqlite3StdTypeLen[] The length (in bytes) of each entry
|
||||
** in sqlite3StdType[].
|
||||
**
|
||||
** sqlite3StdTypeAffinity[] The affinity associated with each entry
|
||||
** in sqlite3StdType[].
|
||||
**
|
||||
** sqlite3StdTypeMap[] The type value (as returned from
|
||||
** sqlite3_column_type() or sqlite3_value_type())
|
||||
** for each entry in sqlite3StdType[].
|
||||
*/
|
||||
const unsigned char sqlite3StdTypeLen[] = { 3, 4, 3, 7, 4, 4 };
|
||||
const char sqlite3StdTypeAffinity[] = {
|
||||
SQLITE_AFF_NUMERIC,
|
||||
SQLITE_AFF_BLOB,
|
||||
SQLITE_AFF_INTEGER,
|
||||
SQLITE_AFF_INTEGER,
|
||||
SQLITE_AFF_REAL,
|
||||
SQLITE_AFF_TEXT
|
||||
};
|
||||
const char sqlite3StdTypeMap[] = {
|
||||
0,
|
||||
SQLITE_BLOB,
|
||||
SQLITE_INTEGER,
|
||||
SQLITE_INTEGER,
|
||||
SQLITE_FLOAT,
|
||||
SQLITE_TEXT
|
||||
};
|
||||
const char *sqlite3StdType[] = {
|
||||
"ANY",
|
||||
"BLOB",
|
||||
"INT",
|
||||
"INTEGER",
|
||||
"REAL",
|
||||
"TEXT"
|
||||
};
|
||||
|
||||
+1
-1
@@ -91,6 +91,6 @@ void sqlite3HashClear(Hash*);
|
||||
/*
|
||||
** Number of entries in a hash table
|
||||
*/
|
||||
#define sqliteHashCount(H) ((H)->count)
|
||||
/* #define sqliteHashCount(H) ((H)->count) // NOT USED */
|
||||
|
||||
#endif /* SQLITE_HASH_H */
|
||||
|
||||
+81
-147
@@ -43,7 +43,7 @@ void sqlite3OpenTable(
|
||||
}else{
|
||||
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
|
||||
assert( pPk!=0 );
|
||||
assert( pPk->tnum==pTab->tnum || CORRUPT_DB );
|
||||
assert( pPk->tnum==pTab->tnum );
|
||||
sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb);
|
||||
sqlite3VdbeSetP4KeyInfo(pParse, pPk);
|
||||
VdbeComment((v, "%s", pTab->zName));
|
||||
@@ -110,68 +110,28 @@ const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
|
||||
}
|
||||
|
||||
/*
|
||||
** Make changes to the evolving bytecode to do affinity transformations
|
||||
** of values that are about to be gathered into a row for table pTab.
|
||||
**
|
||||
** For ordinary (legacy, non-strict) tables:
|
||||
** -----------------------------------------
|
||||
**
|
||||
** Compute the affinity string for table pTab, if it has not already been
|
||||
** computed. As an optimization, omit trailing SQLITE_AFF_BLOB affinities.
|
||||
**
|
||||
** If the affinity string is empty (because it was all SQLITE_AFF_BLOB entries
|
||||
** which were then optimized out) then this routine becomes a no-op.
|
||||
**
|
||||
** Otherwise if iReg>0 then code an OP_Affinity opcode that will set the
|
||||
** affinities for register iReg and following. Or if iReg==0,
|
||||
** If the affinity exists (if it is not entirely SQLITE_AFF_BLOB values) and
|
||||
** if iReg>0 then code an OP_Affinity opcode that will set the affinities
|
||||
** for register iReg and following. Or if affinities exists and iReg==0,
|
||||
** then just set the P4 operand of the previous opcode (which should be
|
||||
** an OP_MakeRecord) to the affinity string.
|
||||
**
|
||||
** A column affinity string has one character per column:
|
||||
**
|
||||
** Character Column affinity
|
||||
** --------- ---------------
|
||||
** 'A' BLOB
|
||||
** 'B' TEXT
|
||||
** 'C' NUMERIC
|
||||
** 'D' INTEGER
|
||||
** 'E' REAL
|
||||
**
|
||||
** For STRICT tables:
|
||||
** ------------------
|
||||
**
|
||||
** Generate an appropropriate OP_TypeCheck opcode that will verify the
|
||||
** datatypes against the column definitions in pTab. If iReg==0, that
|
||||
** means an OP_MakeRecord opcode has already been generated and should be
|
||||
** the last opcode generated. The new OP_TypeCheck needs to be inserted
|
||||
** before the OP_MakeRecord. The new OP_TypeCheck should use the same
|
||||
** register set as the OP_MakeRecord. If iReg>0 then register iReg is
|
||||
** the first of a series of registers that will form the new record.
|
||||
** Apply the type checking to that array of registers.
|
||||
** Character Column affinity
|
||||
** ------------------------------
|
||||
** 'A' BLOB
|
||||
** 'B' TEXT
|
||||
** 'C' NUMERIC
|
||||
** 'D' INTEGER
|
||||
** 'E' REAL
|
||||
*/
|
||||
void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
|
||||
int i, j;
|
||||
char *zColAff;
|
||||
if( pTab->tabFlags & TF_Strict ){
|
||||
if( iReg==0 ){
|
||||
/* Move the previous opcode (which should be OP_MakeRecord) forward
|
||||
** by one slot and insert a new OP_TypeCheck where the current
|
||||
** OP_MakeRecord is found */
|
||||
VdbeOp *pPrev;
|
||||
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
|
||||
pPrev = sqlite3VdbeGetOp(v, -1);
|
||||
assert( pPrev!=0 );
|
||||
assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
|
||||
pPrev->opcode = OP_TypeCheck;
|
||||
sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, pPrev->p3);
|
||||
}else{
|
||||
/* Insert an isolated OP_Typecheck */
|
||||
sqlite3VdbeAddOp2(v, OP_TypeCheck, iReg, pTab->nNVCol);
|
||||
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
zColAff = pTab->zColAff;
|
||||
char *zColAff = pTab->zColAff;
|
||||
if( zColAff==0 ){
|
||||
sqlite3 *db = sqlite3VdbeDb(v);
|
||||
zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
|
||||
@@ -197,8 +157,6 @@ void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
|
||||
if( iReg ){
|
||||
sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
|
||||
}else{
|
||||
assert( sqlite3VdbeGetOp(v, -1)->opcode==OP_MakeRecord
|
||||
|| sqlite3VdbeDb(v)->mallocFailed );
|
||||
sqlite3VdbeChangeP4(v, -1, zColAff, i);
|
||||
}
|
||||
}
|
||||
@@ -282,30 +240,24 @@ void sqlite3ComputeGeneratedColumns(
|
||||
** that appropriate affinity has been applied to the regular columns
|
||||
*/
|
||||
sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
|
||||
if( (pTab->tabFlags & TF_HasStored)!=0 ){
|
||||
pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
|
||||
if( pOp->opcode==OP_Affinity ){
|
||||
/* Change the OP_Affinity argument to '@' (NONE) for all stored
|
||||
** columns. '@' is the no-op affinity and those columns have not
|
||||
** yet been computed. */
|
||||
int ii, jj;
|
||||
char *zP4 = pOp->p4.z;
|
||||
assert( zP4!=0 );
|
||||
assert( pOp->p4type==P4_DYNAMIC );
|
||||
for(ii=jj=0; zP4[jj]; ii++){
|
||||
if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){
|
||||
continue;
|
||||
}
|
||||
if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){
|
||||
zP4[jj] = SQLITE_AFF_NONE;
|
||||
}
|
||||
jj++;
|
||||
if( (pTab->tabFlags & TF_HasStored)!=0
|
||||
&& (pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1))->opcode==OP_Affinity
|
||||
){
|
||||
/* Change the OP_Affinity argument to '@' (NONE) for all stored
|
||||
** columns. '@' is the no-op affinity and those columns have not
|
||||
** yet been computed. */
|
||||
int ii, jj;
|
||||
char *zP4 = pOp->p4.z;
|
||||
assert( zP4!=0 );
|
||||
assert( pOp->p4type==P4_DYNAMIC );
|
||||
for(ii=jj=0; zP4[jj]; ii++){
|
||||
if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){
|
||||
continue;
|
||||
}
|
||||
}else if( pOp->opcode==OP_TypeCheck ){
|
||||
/* If an OP_TypeCheck was generated because the table is STRICT,
|
||||
** then set the P3 operand to indicate that generated columns should
|
||||
** not be checked */
|
||||
pOp->p3 = 1;
|
||||
if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){
|
||||
zP4[jj] = SQLITE_AFF_NONE;
|
||||
}
|
||||
jj++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,7 +293,7 @@ void sqlite3ComputeGeneratedColumns(
|
||||
int x;
|
||||
pCol->colFlags |= COLFLAG_BUSY;
|
||||
w.eCode = 0;
|
||||
sqlite3WalkExpr(&w, sqlite3ColumnExpr(pTab, pCol));
|
||||
sqlite3WalkExpr(&w, pCol->pDflt);
|
||||
pCol->colFlags &= ~COLFLAG_BUSY;
|
||||
if( w.eCode & COLFLAG_NOTAVAIL ){
|
||||
pRedo = pCol;
|
||||
@@ -350,13 +302,13 @@ void sqlite3ComputeGeneratedColumns(
|
||||
eProgress = 1;
|
||||
assert( pCol->colFlags & COLFLAG_GENERATED );
|
||||
x = sqlite3TableColumnToStorage(pTab, i) + iRegStore;
|
||||
sqlite3ExprCodeGeneratedColumn(pParse, pTab, pCol, x);
|
||||
sqlite3ExprCodeGeneratedColumn(pParse, pCol, x);
|
||||
pCol->colFlags &= ~COLFLAG_NOTAVAIL;
|
||||
}
|
||||
}
|
||||
}while( pRedo && eProgress );
|
||||
if( pRedo ){
|
||||
sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pRedo->zCnName);
|
||||
sqlite3ErrorMsg(pParse, "generated column loop on \"%s\"", pRedo->zName);
|
||||
}
|
||||
pParse->iSelfTab = 0;
|
||||
}
|
||||
@@ -715,11 +667,9 @@ void sqlite3Insert(
|
||||
#endif
|
||||
|
||||
db = pParse->db;
|
||||
assert( db->pParse==pParse );
|
||||
if( pParse->nErr ){
|
||||
if( pParse->nErr || db->mallocFailed ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
assert( db->mallocFailed==0 );
|
||||
dest.iSDParm = 0; /* Suppress a harmless compiler warning */
|
||||
|
||||
/* If the Select object is really just a simple VALUES() list with a
|
||||
@@ -753,7 +703,7 @@ void sqlite3Insert(
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0, &tmask);
|
||||
isView = IsView(pTab);
|
||||
isView = pTab->pSelect!=0;
|
||||
#else
|
||||
# define pTrigger 0
|
||||
# define tmask 0
|
||||
@@ -795,11 +745,7 @@ void sqlite3Insert(
|
||||
**
|
||||
** This is the 2nd template.
|
||||
*/
|
||||
if( pColumn==0
|
||||
&& pSelect!=0
|
||||
&& pTrigger==0
|
||||
&& xferOptimization(pParse, pTab, pSelect, onError, iDb)
|
||||
){
|
||||
if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){
|
||||
assert( !pTrigger );
|
||||
assert( pList==0 );
|
||||
goto insert_end;
|
||||
@@ -848,7 +794,7 @@ void sqlite3Insert(
|
||||
}
|
||||
for(i=0; i<pColumn->nId; i++){
|
||||
for(j=0; j<pTab->nCol; j++){
|
||||
if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){
|
||||
if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
|
||||
pColumn->a[i].idx = j;
|
||||
if( i!=j ) bIdListInOrder = 0;
|
||||
if( j==pTab->iPKey ){
|
||||
@@ -858,7 +804,7 @@ void sqlite3Insert(
|
||||
if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"cannot INSERT into generated column \"%s\"",
|
||||
pTab->aCol[j].zCnName);
|
||||
pTab->aCol[j].zName);
|
||||
goto insert_cleanup;
|
||||
}
|
||||
#endif
|
||||
@@ -899,9 +845,7 @@ void sqlite3Insert(
|
||||
dest.nSdst = pTab->nCol;
|
||||
rc = sqlite3Select(pParse, pSelect, &dest);
|
||||
regFromSelect = dest.iSdst;
|
||||
assert( db->pParse==pParse );
|
||||
if( rc || pParse->nErr ) goto insert_cleanup;
|
||||
assert( db->mallocFailed==0 );
|
||||
if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
|
||||
sqlite3VdbeEndCoroutine(v, regYield);
|
||||
sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
|
||||
assert( pSelect->pEList );
|
||||
@@ -1045,7 +989,7 @@ void sqlite3Insert(
|
||||
pTab->zName);
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( IsView(pTab) ){
|
||||
if( pTab->pSelect ){
|
||||
sqlite3ErrorMsg(pParse, "cannot UPSERT a view");
|
||||
goto insert_cleanup;
|
||||
}
|
||||
@@ -1144,9 +1088,7 @@ void sqlite3Insert(
|
||||
}else if( pColumn==0 ){
|
||||
/* Hidden columns that are not explicitly named in the INSERT
|
||||
** get there default value */
|
||||
sqlite3ExprCodeFactorable(pParse,
|
||||
sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
|
||||
iRegStore);
|
||||
sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1155,17 +1097,13 @@ void sqlite3Insert(
|
||||
if( j>=pColumn->nId ){
|
||||
/* A column not named in the insert column list gets its
|
||||
** default value */
|
||||
sqlite3ExprCodeFactorable(pParse,
|
||||
sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
|
||||
iRegStore);
|
||||
sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
|
||||
continue;
|
||||
}
|
||||
k = j;
|
||||
}else if( nColumn==0 ){
|
||||
/* This is INSERT INTO ... DEFAULT VALUES. Load the default value. */
|
||||
sqlite3ExprCodeFactorable(pParse,
|
||||
sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
|
||||
iRegStore);
|
||||
sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
|
||||
continue;
|
||||
}else{
|
||||
k = i - nHidden;
|
||||
@@ -1390,7 +1328,9 @@ insert_end:
|
||||
** invoke the callback function.
|
||||
*/
|
||||
if( regRowCount ){
|
||||
sqlite3CodeChangeCount(v, regRowCount, "rows inserted");
|
||||
sqlite3VdbeAddOp2(v, OP_ChngCntRow, regRowCount, 1);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", SQLITE_STATIC);
|
||||
}
|
||||
|
||||
insert_cleanup:
|
||||
@@ -1678,7 +1618,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
db = pParse->db;
|
||||
v = pParse->pVdbe;
|
||||
assert( v!=0 );
|
||||
assert( !IsView(pTab) ); /* This table is not a VIEW */
|
||||
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
|
||||
nCol = pTab->nCol;
|
||||
|
||||
/* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
|
||||
@@ -1729,7 +1669,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
}
|
||||
if( onError==OE_Replace ){
|
||||
if( b2ndPass /* REPLACE becomes ABORT on the 2nd pass */
|
||||
|| pCol->iDflt==0 /* REPLACE is ABORT if no DEFAULT value */
|
||||
|| pCol->pDflt==0 /* REPLACE is ABORT if no DEFAULT value */
|
||||
){
|
||||
testcase( pCol->colFlags & COLFLAG_VIRTUAL );
|
||||
testcase( pCol->colFlags & COLFLAG_STORED );
|
||||
@@ -1751,8 +1691,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
VdbeCoverage(v);
|
||||
assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
|
||||
nSeenReplace++;
|
||||
sqlite3ExprCodeCopy(pParse,
|
||||
sqlite3ColumnExpr(pTab, pCol), iReg);
|
||||
sqlite3ExprCodeCopy(pParse, pCol->pDflt, iReg);
|
||||
sqlite3VdbeJumpHere(v, addr1);
|
||||
break;
|
||||
}
|
||||
@@ -1762,7 +1701,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
case OE_Rollback:
|
||||
case OE_Fail: {
|
||||
char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
|
||||
pCol->zCnName);
|
||||
pCol->zName);
|
||||
sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL,
|
||||
onError, iReg);
|
||||
sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
|
||||
@@ -2015,7 +1954,6 @@ void sqlite3GenerateConstraintChecks(
|
||||
if( onError==OE_Replace /* IPK rule is REPLACE */
|
||||
&& onError!=overrideError /* Rules for other constraints are different */
|
||||
&& pTab->pIndex /* There exist other constraints */
|
||||
&& !upsertIpkDelay /* IPK check already deferred by UPSERT */
|
||||
){
|
||||
ipkTop = sqlite3VdbeAddOp0(v, OP_Goto)+1;
|
||||
VdbeComment((v, "defer IPK REPLACE until last"));
|
||||
@@ -2181,7 +2119,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
testcase( sqlite3TableColumnToStorage(pTab, iField)!=iField );
|
||||
x = sqlite3TableColumnToStorage(pTab, iField) + regNewData + 1;
|
||||
sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
|
||||
VdbeComment((v, "%s", pTab->aCol[iField].zCnName));
|
||||
VdbeComment((v, "%s", pTab->aCol[iField].zName));
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
|
||||
@@ -2232,8 +2170,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
**
|
||||
** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
|
||||
** must be explicitly deleted in order to ensure any pre-update hook
|
||||
** is invoked. */
|
||||
assert( IsOrdinaryTable(pTab) );
|
||||
** is invoked. */
|
||||
#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
|
||||
&& pPk==pIdx /* Condition 2 */
|
||||
@@ -2241,7 +2178,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
&& ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
|
||||
0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0))
|
||||
&& ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */
|
||||
(0==pTab->u.tab.pFKey && 0==sqlite3FkReferences(pTab)))
|
||||
(0==pTab->pFKey && 0==sqlite3FkReferences(pTab)))
|
||||
){
|
||||
sqlite3VdbeResolveLabel(v, addrUniqueOk);
|
||||
continue;
|
||||
@@ -2276,13 +2213,13 @@ void sqlite3GenerateConstraintChecks(
|
||||
x = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]);
|
||||
sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
|
||||
VdbeComment((v, "%s.%s", pTab->zName,
|
||||
pTab->aCol[pPk->aiColumn[i]].zCnName));
|
||||
pTab->aCol[pPk->aiColumn[i]].zName));
|
||||
}
|
||||
}
|
||||
if( isUpdate ){
|
||||
/* If currently processing the PRIMARY KEY of a WITHOUT ROWID
|
||||
** table, only conflict if the new PRIMARY KEY values are actually
|
||||
** different from the old. See TH3 withoutrowid04.test.
|
||||
** different from the old.
|
||||
**
|
||||
** For a UNIQUE index, only conflict if the PRIMARY KEY values
|
||||
** of the matched index row are different from the original PRIMARY
|
||||
@@ -2340,8 +2277,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
|
||||
assert( onError==OE_Replace );
|
||||
nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk;
|
||||
assert( nConflictCk>0 || db->mallocFailed );
|
||||
testcase( nConflictCk<=0 );
|
||||
assert( nConflictCk>0 );
|
||||
testcase( nConflictCk>1 );
|
||||
if( regTrigCnt ){
|
||||
sqlite3MultiWrite(pParse);
|
||||
@@ -2424,7 +2360,6 @@ void sqlite3GenerateConstraintChecks(
|
||||
if( ipkTop ){
|
||||
sqlite3VdbeGoto(v, ipkTop);
|
||||
VdbeComment((v, "Do IPK REPLACE"));
|
||||
assert( ipkBottom>0 );
|
||||
sqlite3VdbeJumpHere(v, ipkBottom);
|
||||
}
|
||||
|
||||
@@ -2477,7 +2412,7 @@ void sqlite3SetMakeRecordP5(Vdbe *v, Table *pTab){
|
||||
if( pTab->pSchema->file_format<2 ) return;
|
||||
|
||||
for(i=pTab->nCol-1; i>0; i--){
|
||||
if( pTab->aCol[i].iDflt!=0 ) break;
|
||||
if( pTab->aCol[i].pDflt!=0 ) break;
|
||||
if( pTab->aCol[i].colFlags & COLFLAG_PRIMKEY ) break;
|
||||
}
|
||||
sqlite3VdbeChangeP5(v, i+1);
|
||||
@@ -2542,7 +2477,7 @@ void sqlite3CompleteInsertion(
|
||||
|
||||
v = pParse->pVdbe;
|
||||
assert( v!=0 );
|
||||
assert( !IsView(pTab) ); /* This table is not a VIEW */
|
||||
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
/* All REPLACE indexes are at the end of the list */
|
||||
assert( pIdx->onError!=OE_Replace
|
||||
@@ -2555,6 +2490,7 @@ void sqlite3CompleteInsertion(
|
||||
}
|
||||
pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
|
||||
if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
|
||||
assert( pParse->nested==0 );
|
||||
pik_flags |= OPFLAG_NCHANGE;
|
||||
pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
|
||||
if( update_flags==0 ){
|
||||
@@ -2627,9 +2563,8 @@ int sqlite3OpenTableAndIndices(
|
||||
assert( op==OP_OpenWrite || p5==0 );
|
||||
if( IsVirtual(pTab) ){
|
||||
/* This routine is a no-op for virtual tables. Leave the output
|
||||
** variables *piDataCur and *piIdxCur set to illegal cursor numbers
|
||||
** for improved error detection. */
|
||||
*piDataCur = *piIdxCur = -999;
|
||||
** variables *piDataCur and *piIdxCur uninitialized so that valgrind
|
||||
** can detect if they are used by mistake in the caller. */
|
||||
return 0;
|
||||
}
|
||||
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
@@ -2770,13 +2705,18 @@ static int xferOptimization(
|
||||
int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
|
||||
int regData, regRowid; /* Registers holding data and rowid */
|
||||
|
||||
assert( pSelect!=0 );
|
||||
if( pSelect==0 ){
|
||||
return 0; /* Must be of the form INSERT INTO ... SELECT ... */
|
||||
}
|
||||
if( pParse->pWith || pSelect->pWith ){
|
||||
/* Do not attempt to process this query if there are an WITH clauses
|
||||
** attached to it. Proceeding may generate a false "no such table: xxx"
|
||||
** error if pSelect reads from a CTE named "xxx". */
|
||||
return 0;
|
||||
}
|
||||
if( sqlite3TriggerList(pParse, pDest) ){
|
||||
return 0; /* tab1 must not have triggers */
|
||||
}
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
if( IsVirtual(pDest) ){
|
||||
return 0; /* tab1 must not be a virtual table */
|
||||
@@ -2839,8 +2779,13 @@ static int xferOptimization(
|
||||
if( HasRowid(pDest)!=HasRowid(pSrc) ){
|
||||
return 0; /* source and destination must both be WITHOUT ROWID or not */
|
||||
}
|
||||
if( !IsOrdinaryTable(pSrc) ){
|
||||
return 0; /* tab2 may not be a view or virtual table */
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
if( IsVirtual(pSrc) ){
|
||||
return 0; /* tab2 must not be a virtual table */
|
||||
}
|
||||
#endif
|
||||
if( pSrc->pSelect ){
|
||||
return 0; /* tab2 may not be a view */
|
||||
}
|
||||
if( pDest->nCol!=pSrc->nCol ){
|
||||
return 0; /* Number of columns must be the same in tab1 and tab2 */
|
||||
@@ -2848,9 +2793,6 @@ static int xferOptimization(
|
||||
if( pDest->iPKey!=pSrc->iPKey ){
|
||||
return 0; /* Both tables must have the same INTEGER PRIMARY KEY */
|
||||
}
|
||||
if( (pDest->tabFlags & TF_Strict)!=0 && (pSrc->tabFlags & TF_Strict)==0 ){
|
||||
return 0; /* Cannot feed from a non-strict into a strict table */
|
||||
}
|
||||
for(i=0; i<pDest->nCol; i++){
|
||||
Column *pDestCol = &pDest->aCol[i];
|
||||
Column *pSrcCol = &pSrc->aCol[i];
|
||||
@@ -2887,9 +2829,7 @@ static int xferOptimization(
|
||||
** This requirement could be relaxed for VIRTUAL columns, I suppose.
|
||||
*/
|
||||
if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){
|
||||
if( sqlite3ExprCompare(0,
|
||||
sqlite3ColumnExpr(pSrc, pSrcCol),
|
||||
sqlite3ColumnExpr(pDest, pDestCol), -1)!=0 ){
|
||||
if( sqlite3ExprCompare(0, pSrcCol->pDflt, pDestCol->pDflt, -1)!=0 ){
|
||||
testcase( pDestCol->colFlags & COLFLAG_VIRTUAL );
|
||||
testcase( pDestCol->colFlags & COLFLAG_STORED );
|
||||
return 0; /* Different generator expressions */
|
||||
@@ -2899,8 +2839,7 @@ static int xferOptimization(
|
||||
if( pDestCol->affinity!=pSrcCol->affinity ){
|
||||
return 0; /* Affinity must be the same on all columns */
|
||||
}
|
||||
if( sqlite3_stricmp(sqlite3ColumnColl(pDestCol),
|
||||
sqlite3ColumnColl(pSrcCol))!=0 ){
|
||||
if( sqlite3_stricmp(pDestCol->zColl, pSrcCol->zColl)!=0 ){
|
||||
return 0; /* Collating sequence must be the same on all columns */
|
||||
}
|
||||
if( pDestCol->notNull && !pSrcCol->notNull ){
|
||||
@@ -2908,15 +2847,11 @@ static int xferOptimization(
|
||||
}
|
||||
/* Default values for second and subsequent columns need to match. */
|
||||
if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
|
||||
Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol);
|
||||
Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol);
|
||||
assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
|
||||
assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) );
|
||||
assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
|
||||
assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) );
|
||||
if( (pDestExpr==0)!=(pSrcExpr==0)
|
||||
|| (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
|
||||
pSrcExpr->u.zToken)!=0)
|
||||
assert( pDestCol->pDflt==0 || pDestCol->pDflt->op==TK_SPAN );
|
||||
assert( pSrcCol->pDflt==0 || pSrcCol->pDflt->op==TK_SPAN );
|
||||
if( (pDestCol->pDflt==0)!=(pSrcCol->pDflt==0)
|
||||
|| (pDestCol->pDflt && strcmp(pDestCol->pDflt->u.zToken,
|
||||
pSrcCol->pDflt->u.zToken)!=0)
|
||||
){
|
||||
return 0; /* Default values must be the same for all columns */
|
||||
}
|
||||
@@ -2953,8 +2888,7 @@ static int xferOptimization(
|
||||
** the extra complication to make this rule less restrictive is probably
|
||||
** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
|
||||
*/
|
||||
assert( IsOrdinaryTable(pDest) );
|
||||
if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
|
||||
if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -483,15 +483,6 @@ static const sqlite3_api_routines sqlite3Apis = {
|
||||
/* Version 3.36.1 and later */
|
||||
sqlite3_changes64,
|
||||
sqlite3_total_changes64,
|
||||
/* Version 3.37.0 and later */
|
||||
sqlite3_autovacuum_pages,
|
||||
/* Version 3.38.0 and later */
|
||||
sqlite3_error_offset,
|
||||
sqlite3_vtab_rhs_value,
|
||||
sqlite3_vtab_distinct,
|
||||
sqlite3_vtab_in,
|
||||
sqlite3_vtab_in_first,
|
||||
sqlite3_vtab_in_next
|
||||
};
|
||||
|
||||
/* True if x is the directory separator character
|
||||
|
||||
+42
-141
@@ -50,6 +50,9 @@ int sqlite3Fts2Init(sqlite3*);
|
||||
#ifdef SQLITE_ENABLE_FTS5
|
||||
int sqlite3Fts5Init(sqlite3*);
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_JSON1
|
||||
int sqlite3Json1Init(sqlite3*);
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_STMTVTAB
|
||||
int sqlite3StmtVtabInit(sqlite3*);
|
||||
#endif
|
||||
@@ -84,8 +87,8 @@ static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = {
|
||||
sqlite3DbstatRegister,
|
||||
#endif
|
||||
sqlite3TestExtInit,
|
||||
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON)
|
||||
sqlite3JsonTableFunctions,
|
||||
#ifdef SQLITE_ENABLE_JSON1
|
||||
sqlite3Json1Init,
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_STMTVTAB
|
||||
sqlite3StmtVtabInit,
|
||||
@@ -1135,9 +1138,7 @@ void sqlite3CloseSavepoints(sqlite3 *db){
|
||||
** with SQLITE_ANY as the encoding.
|
||||
*/
|
||||
static void functionDestroy(sqlite3 *db, FuncDef *p){
|
||||
FuncDestructor *pDestructor;
|
||||
assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
|
||||
pDestructor = p->u.pDestructor;
|
||||
FuncDestructor *pDestructor = p->u.pDestructor;
|
||||
if( pDestructor ){
|
||||
pDestructor->nRef--;
|
||||
if( pDestructor->nRef==0 ){
|
||||
@@ -1241,7 +1242,7 @@ static int sqlite3Close(sqlite3 *db, int forceZombie){
|
||||
|
||||
/* Convert the connection into a zombie and then close it.
|
||||
*/
|
||||
db->eOpenState = SQLITE_STATE_ZOMBIE;
|
||||
db->magic = SQLITE_MAGIC_ZOMBIE;
|
||||
sqlite3LeaveMutexAndCloseZombie(db);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -1305,7 +1306,7 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
|
||||
** or if the connection has not yet been closed by sqlite3_close_v2(),
|
||||
** then just leave the mutex and return.
|
||||
*/
|
||||
if( db->eOpenState!=SQLITE_STATE_ZOMBIE || connectionIsBusy(db) ){
|
||||
if( db->magic!=SQLITE_MAGIC_ZOMBIE || connectionIsBusy(db) ){
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return;
|
||||
}
|
||||
@@ -1391,7 +1392,7 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
|
||||
sqlite3_free(db->auth.zAuthPW);
|
||||
#endif
|
||||
|
||||
db->eOpenState = SQLITE_STATE_ERROR;
|
||||
db->magic = SQLITE_MAGIC_ERROR;
|
||||
|
||||
/* The temp-database schema is allocated differently from the other schema
|
||||
** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
|
||||
@@ -1400,11 +1401,8 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
|
||||
** structure?
|
||||
*/
|
||||
sqlite3DbFree(db, db->aDb[1].pSchema);
|
||||
if( db->xAutovacDestr ){
|
||||
db->xAutovacDestr(db->pAutovacPagesArg);
|
||||
}
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
db->eOpenState = SQLITE_STATE_CLOSED;
|
||||
db->magic = SQLITE_MAGIC_CLOSED;
|
||||
sqlite3_mutex_free(db->mutex);
|
||||
assert( sqlite3LookasideUsed(db,0)==0 );
|
||||
if( db->lookaside.bMalloced ){
|
||||
@@ -1457,7 +1455,7 @@ void sqlite3RollbackAll(sqlite3 *db, int tripCode){
|
||||
/* Any deferred constraint violations have now been resolved. */
|
||||
db->nDeferredCons = 0;
|
||||
db->nDeferredImmCons = 0;
|
||||
db->flags &= ~(u64)(SQLITE_DeferFKs|SQLITE_CorruptRdOnly);
|
||||
db->flags &= ~(u64)SQLITE_DeferFKs;
|
||||
|
||||
/* If one has been configured, invoke the rollback-hook callback */
|
||||
if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
|
||||
@@ -1792,7 +1790,7 @@ int sqlite3_busy_timeout(sqlite3 *db, int ms){
|
||||
*/
|
||||
void sqlite3_interrupt(sqlite3 *db){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE) ){
|
||||
if( !sqlite3SafetyCheckOk(db) && (db==0 || db->magic!=SQLITE_MAGIC_ZOMBIE) ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return;
|
||||
}
|
||||
@@ -1821,6 +1819,7 @@ int sqlite3CreateFunc(
|
||||
FuncDestructor *pDestructor
|
||||
){
|
||||
FuncDef *p;
|
||||
int nName;
|
||||
int extraFlags;
|
||||
|
||||
assert( sqlite3_mutex_held(db->mutex) );
|
||||
@@ -1830,7 +1829,7 @@ int sqlite3CreateFunc(
|
||||
|| ((xFinal==0)!=(xStep==0)) /* Both or neither of xFinal and xStep */
|
||||
|| ((xValue==0)!=(xInverse==0)) /* Both or neither of xValue, xInverse */
|
||||
|| (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG)
|
||||
|| (255<sqlite3Strlen30(zFunctionName))
|
||||
|| (255<(nName = sqlite3Strlen30( zFunctionName)))
|
||||
){
|
||||
return SQLITE_MISUSE_BKPT;
|
||||
}
|
||||
@@ -2304,34 +2303,6 @@ void *sqlite3_preupdate_hook(
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
|
||||
|
||||
/*
|
||||
** Register a function to be invoked prior to each autovacuum that
|
||||
** determines the number of pages to vacuum.
|
||||
*/
|
||||
int sqlite3_autovacuum_pages(
|
||||
sqlite3 *db, /* Attach the hook to this database */
|
||||
unsigned int (*xCallback)(void*,const char*,u32,u32,u32),
|
||||
void *pArg, /* Argument to the function */
|
||||
void (*xDestructor)(void*) /* Destructor for pArg */
|
||||
){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ){
|
||||
if( xDestructor ) xDestructor(pArg);
|
||||
return SQLITE_MISUSE_BKPT;
|
||||
}
|
||||
#endif
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
if( db->xAutovacDestr ){
|
||||
db->xAutovacDestr(db->pAutovacPagesArg);
|
||||
}
|
||||
db->xAutovacPages = xCallback;
|
||||
db->pAutovacPagesArg = pArg;
|
||||
db->xAutovacDestr = xDestructor;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
/*
|
||||
** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
|
||||
@@ -2594,19 +2565,6 @@ const char *sqlite3_errmsg(sqlite3 *db){
|
||||
return z;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the byte offset of the most recent error
|
||||
*/
|
||||
int sqlite3_error_offset(sqlite3 *db){
|
||||
int iOffset = -1;
|
||||
if( db && sqlite3SafetyCheckSickOrOk(db) && db->errCode ){
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
iOffset = db->errByteOffset;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
}
|
||||
return iOffset;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** Return UTF-16 encoded English language explanation of the most recent
|
||||
@@ -2867,8 +2825,6 @@ int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
|
||||
if( newLimit>=0 ){ /* IMP: R-52476-28732 */
|
||||
if( newLimit>aHardLimit[limitId] ){
|
||||
newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */
|
||||
}else if( newLimit<1 && limitId==SQLITE_LIMIT_LENGTH ){
|
||||
newLimit = 1;
|
||||
}
|
||||
db->aLimit[limitId] = newLimit;
|
||||
}
|
||||
@@ -3140,7 +3096,7 @@ int sqlite3ParseUri(
|
||||
*/
|
||||
static const char *uriParameter(const char *zFilename, const char *zParam){
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
while( ALWAYS(zFilename!=0) && zFilename[0] ){
|
||||
while( zFilename[0] ){
|
||||
int x = strcmp(zFilename, zParam);
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
if( x==0 ) return zFilename;
|
||||
@@ -3200,11 +3156,10 @@ static int openDatabase(
|
||||
** dealt with in the previous code block. Besides these, the only
|
||||
** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
|
||||
** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
|
||||
** SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_EXRESCODE, and some reserved
|
||||
** bits. Silently mask off all other flags.
|
||||
** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
|
||||
** off all other flags.
|
||||
*/
|
||||
flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
|
||||
SQLITE_OPEN_EXCLUSIVE |
|
||||
SQLITE_OPEN_MAIN_DB |
|
||||
SQLITE_OPEN_TEMP_DB |
|
||||
SQLITE_OPEN_TRANSIENT_DB |
|
||||
@@ -3236,9 +3191,9 @@ static int openDatabase(
|
||||
}
|
||||
}
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
db->errMask = (flags & SQLITE_OPEN_EXRESCODE)!=0 ? 0xffffffff : 0xff;
|
||||
db->errMask = 0xff;
|
||||
db->nDb = 2;
|
||||
db->eOpenState = SQLITE_STATE_BUSY;
|
||||
db->magic = SQLITE_MAGIC_BUSY;
|
||||
db->aDb = db->aDbStatic;
|
||||
db->lookaside.bDisable = 1;
|
||||
db->lookaside.sz = 0;
|
||||
@@ -3250,15 +3205,7 @@ static int openDatabase(
|
||||
db->nextAutovac = -1;
|
||||
db->szMmap = sqlite3GlobalConfig.szMmap;
|
||||
db->nextPagesize = 0;
|
||||
db->init.azInit = sqlite3StdType; /* Any array of string ptrs will do */
|
||||
#ifdef SQLITE_ENABLE_SORTER_MMAP
|
||||
/* Beginning with version 3.37.0, using the VFS xFetch() API to memory-map
|
||||
** the temporary files used to do external sorts (see code in vdbesort.c)
|
||||
** is disabled. It can still be used either by defining
|
||||
** SQLITE_ENABLE_SORTER_MMAP at compile time or by using the
|
||||
** SQLITE_TESTCTRL_SORTER_MMAP test-control at runtime. */
|
||||
db->nMaxSorterMmap = 0x7FFFFFFF;
|
||||
#endif
|
||||
db->flags |= SQLITE_ShortColNames
|
||||
| SQLITE_EnableTrigger
|
||||
| SQLITE_EnableView
|
||||
@@ -3406,7 +3353,7 @@ static int openDatabase(
|
||||
db->aDb[1].zDbSName = "temp";
|
||||
db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF;
|
||||
|
||||
db->eOpenState = SQLITE_STATE_OPEN;
|
||||
db->magic = SQLITE_MAGIC_OPEN;
|
||||
if( db->mallocFailed ){
|
||||
goto opendb_out;
|
||||
}
|
||||
@@ -3468,12 +3415,12 @@ opendb_out:
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
}
|
||||
rc = sqlite3_errcode(db);
|
||||
assert( db!=0 || (rc&0xff)==SQLITE_NOMEM );
|
||||
if( (rc&0xff)==SQLITE_NOMEM ){
|
||||
assert( db!=0 || rc==SQLITE_NOMEM );
|
||||
if( rc==SQLITE_NOMEM ){
|
||||
sqlite3_close(db);
|
||||
db = 0;
|
||||
}else if( rc!=SQLITE_OK ){
|
||||
db->eOpenState = SQLITE_STATE_SICK;
|
||||
db->magic = SQLITE_MAGIC_SICK;
|
||||
}
|
||||
*ppDb = db;
|
||||
#ifdef SQLITE_ENABLE_SQLLOG
|
||||
@@ -3484,7 +3431,7 @@ opendb_out:
|
||||
}
|
||||
#endif
|
||||
sqlite3_free_filename(zOpen);
|
||||
return rc;
|
||||
return rc & 0xff;
|
||||
}
|
||||
|
||||
|
||||
@@ -3784,7 +3731,7 @@ int sqlite3_table_column_metadata(
|
||||
|
||||
/* Locate the table in question */
|
||||
pTab = sqlite3FindTable(db, zTableName, zDbName);
|
||||
if( !pTab || IsView(pTab) ){
|
||||
if( !pTab || pTab->pSelect ){
|
||||
pTab = 0;
|
||||
goto error_out;
|
||||
}
|
||||
@@ -3795,7 +3742,7 @@ int sqlite3_table_column_metadata(
|
||||
}else{
|
||||
for(iCol=0; iCol<pTab->nCol; iCol++){
|
||||
pCol = &pTab->aCol[iCol];
|
||||
if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){
|
||||
if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -3822,7 +3769,7 @@ int sqlite3_table_column_metadata(
|
||||
*/
|
||||
if( pCol ){
|
||||
zDataType = sqlite3ColumnType(pCol,0);
|
||||
zCollSeq = sqlite3ColumnColl(pCol);
|
||||
zCollSeq = pCol->zColl;
|
||||
notnull = pCol->notNull!=0;
|
||||
primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
|
||||
autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
|
||||
@@ -4029,16 +3976,12 @@ int sqlite3_test_control(int op, ...){
|
||||
** sqlite3_test_control().
|
||||
*/
|
||||
case SQLITE_TESTCTRL_FAULT_INSTALL: {
|
||||
/* A bug in MSVC prevents it from understanding pointers to functions
|
||||
** types in the second argument to va_arg(). Work around the problem
|
||||
** using a typedef.
|
||||
** http://support.microsoft.com/kb/47961 <-- dead hyperlink
|
||||
** Search at http://web.archive.org/ to find the 2015-03-16 archive
|
||||
** of the link above to see the original text.
|
||||
/* MSVC is picky about pulling func ptrs from va lists.
|
||||
** http://support.microsoft.com/kb/47961
|
||||
** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int));
|
||||
*/
|
||||
typedef int(*sqlite3FaultFuncType)(int);
|
||||
sqlite3GlobalConfig.xTestCallback = va_arg(ap, sqlite3FaultFuncType);
|
||||
typedef int(*TESTCALLBACKFUNC_t)(int);
|
||||
sqlite3GlobalConfig.xTestCallback = va_arg(ap, TESTCALLBACKFUNC_t);
|
||||
rc = sqlite3FaultSim(0);
|
||||
break;
|
||||
}
|
||||
@@ -4165,27 +4108,13 @@ int sqlite3_test_control(int op, ...){
|
||||
break;
|
||||
}
|
||||
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, onoff, xAlt);
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
|
||||
**
|
||||
** If parameter onoff is 1, subsequent calls to localtime() fail.
|
||||
** If 2, then invoke xAlt() instead of localtime(). If 0, normal
|
||||
** processing.
|
||||
**
|
||||
** xAlt arguments are void pointers, but they really want to be:
|
||||
**
|
||||
** int xAlt(const time_t*, struct tm*);
|
||||
**
|
||||
** xAlt should write results in to struct tm object of its 2nd argument
|
||||
** and return zero on success, or return non-zero on failure.
|
||||
** If parameter onoff is non-zero, subsequent calls to localtime()
|
||||
** and its variants fail. If onoff is zero, undo this setting.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
|
||||
sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
|
||||
if( sqlite3GlobalConfig.bLocaltimeFault==2 ){
|
||||
typedef int(*sqlite3LocaltimeType)(const void*,void*);
|
||||
sqlite3GlobalConfig.xAltLocaltime = va_arg(ap, sqlite3LocaltimeType);
|
||||
}else{
|
||||
sqlite3GlobalConfig.xAltLocaltime = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4290,16 +4219,12 @@ int sqlite3_test_control(int op, ...){
|
||||
*/
|
||||
case SQLITE_TESTCTRL_IMPOSTER: {
|
||||
sqlite3 *db = va_arg(ap, sqlite3*);
|
||||
int iDb;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
iDb = sqlite3FindDbName(db, va_arg(ap,const char*));
|
||||
if( iDb>=0 ){
|
||||
db->init.iDb = iDb;
|
||||
db->init.busy = db->init.imposterTable = va_arg(ap,int);
|
||||
db->init.newTnum = va_arg(ap,int);
|
||||
if( db->init.busy==0 && db->init.newTnum>0 ){
|
||||
sqlite3ResetAllSchemasOfConnection(db);
|
||||
}
|
||||
db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*));
|
||||
db->init.busy = db->init.imposterTable = va_arg(ap,int);
|
||||
db->init.newTnum = va_arg(ap,int);
|
||||
if( db->init.busy==0 && db->init.newTnum>0 ){
|
||||
sqlite3ResetAllSchemasOfConnection(db);
|
||||
}
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
break;
|
||||
@@ -4375,28 +4300,6 @@ int sqlite3_test_control(int op, ...){
|
||||
break;
|
||||
}
|
||||
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_LOGEST,
|
||||
** double fIn, // Input value
|
||||
** int *pLogEst, // sqlite3LogEstFromDouble(fIn)
|
||||
** u64 *pInt, // sqlite3LogEstToInt(*pLogEst)
|
||||
** int *pLogEst2 // sqlite3LogEst(*pInt)
|
||||
** );
|
||||
**
|
||||
** Test access for the LogEst conversion routines.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_LOGEST: {
|
||||
double rIn = va_arg(ap, double);
|
||||
LogEst rLogEst = sqlite3LogEstFromDouble(rIn);
|
||||
int *pI1 = va_arg(ap,int*);
|
||||
u64 *pU64 = va_arg(ap,u64*);
|
||||
int *pI2 = va_arg(ap,int*);
|
||||
*pI1 = rLogEst;
|
||||
*pU64 = sqlite3LogEstToInt(rLogEst);
|
||||
*pI2 = sqlite3LogEst(*pU64);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_WSD)
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_TUNE, id, *piValue)
|
||||
**
|
||||
@@ -4533,7 +4436,7 @@ const char *sqlite3_uri_key(const char *zFilename, int N){
|
||||
if( zFilename==0 || N<0 ) return 0;
|
||||
zFilename = databaseName(zFilename);
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
while( ALWAYS(zFilename) && zFilename[0] && (N--)>0 ){
|
||||
while( zFilename[0] && (N--)>0 ){
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
}
|
||||
@@ -4576,14 +4479,12 @@ sqlite3_int64 sqlite3_uri_int64(
|
||||
** corruption.
|
||||
*/
|
||||
const char *sqlite3_filename_database(const char *zFilename){
|
||||
if( zFilename==0 ) return 0;
|
||||
return databaseName(zFilename);
|
||||
}
|
||||
const char *sqlite3_filename_journal(const char *zFilename){
|
||||
if( zFilename==0 ) return 0;
|
||||
zFilename = databaseName(zFilename);
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
while( ALWAYS(zFilename) && zFilename[0] ){
|
||||
while( zFilename[0] ){
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
}
|
||||
@@ -4594,7 +4495,7 @@ const char *sqlite3_filename_wal(const char *zFilename){
|
||||
return 0;
|
||||
#else
|
||||
zFilename = sqlite3_filename_journal(zFilename);
|
||||
if( zFilename ) zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
return zFilename;
|
||||
#endif
|
||||
}
|
||||
|
||||
+7
-16
@@ -316,7 +316,7 @@ void *sqlite3_malloc64(sqlite3_uint64 n){
|
||||
** TRUE if p is a lookaside memory allocation from db
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_LOOKASIDE
|
||||
static int isLookaside(sqlite3 *db, const void *p){
|
||||
static int isLookaside(sqlite3 *db, void *p){
|
||||
return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd);
|
||||
}
|
||||
#else
|
||||
@@ -327,18 +327,18 @@ static int isLookaside(sqlite3 *db, const void *p){
|
||||
** Return the size of a memory allocation previously obtained from
|
||||
** sqlite3Malloc() or sqlite3_malloc().
|
||||
*/
|
||||
int sqlite3MallocSize(const void *p){
|
||||
int sqlite3MallocSize(void *p){
|
||||
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
|
||||
return sqlite3GlobalConfig.m.xSize((void*)p);
|
||||
return sqlite3GlobalConfig.m.xSize(p);
|
||||
}
|
||||
static int lookasideMallocSize(sqlite3 *db, const void *p){
|
||||
static int lookasideMallocSize(sqlite3 *db, void *p){
|
||||
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
|
||||
return p<db->lookaside.pMiddle ? db->lookaside.szTrue : LOOKASIDE_SMALL;
|
||||
#else
|
||||
return db->lookaside.szTrue;
|
||||
#endif
|
||||
}
|
||||
int sqlite3DbMallocSize(sqlite3 *db, const void *p){
|
||||
int sqlite3DbMallocSize(sqlite3 *db, void *p){
|
||||
assert( p!=0 );
|
||||
#ifdef SQLITE_DEBUG
|
||||
if( db==0 || !isLookaside(db,p) ){
|
||||
@@ -365,7 +365,7 @@ int sqlite3DbMallocSize(sqlite3 *db, const void *p){
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlite3GlobalConfig.m.xSize((void*)p);
|
||||
return sqlite3GlobalConfig.m.xSize(p);
|
||||
}
|
||||
sqlite3_uint64 sqlite3_msize(void *p){
|
||||
assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
|
||||
@@ -759,15 +759,8 @@ void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
|
||||
** has happened. This routine will set db->mallocFailed, and also
|
||||
** temporarily disable the lookaside memory allocator and interrupt
|
||||
** any running VDBEs.
|
||||
**
|
||||
** Always return a NULL pointer so that this routine can be invoked using
|
||||
**
|
||||
** return sqlite3OomFault(db);
|
||||
**
|
||||
** and thereby avoid unnecessary stack frame allocations for the overwhelmingly
|
||||
** common case where no OOM occurs.
|
||||
*/
|
||||
void *sqlite3OomFault(sqlite3 *db){
|
||||
void sqlite3OomFault(sqlite3 *db){
|
||||
if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
|
||||
db->mallocFailed = 1;
|
||||
if( db->nVdbeExec>0 ){
|
||||
@@ -775,11 +768,9 @@ void *sqlite3OomFault(sqlite3 *db){
|
||||
}
|
||||
DisableLookaside;
|
||||
if( db->pParse ){
|
||||
sqlite3ErrorMsg(db->pParse, "out of memory");
|
||||
db->pParse->rc = SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+3
-3
@@ -149,7 +149,7 @@ static void adjustStats(int iSize, int increment){
|
||||
** This routine checks the guards at either end of the allocation and
|
||||
** if they are incorrect it asserts.
|
||||
*/
|
||||
static struct MemBlockHdr *sqlite3MemsysGetHeader(const void *pAllocation){
|
||||
static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){
|
||||
struct MemBlockHdr *p;
|
||||
int *pInt;
|
||||
u8 *pU8;
|
||||
@@ -396,7 +396,7 @@ void sqlite3MemdebugSetType(void *p, u8 eType){
|
||||
**
|
||||
** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
|
||||
*/
|
||||
int sqlite3MemdebugHasType(const void *p, u8 eType){
|
||||
int sqlite3MemdebugHasType(void *p, u8 eType){
|
||||
int rc = 1;
|
||||
if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
|
||||
struct MemBlockHdr *pHdr;
|
||||
@@ -418,7 +418,7 @@ int sqlite3MemdebugHasType(const void *p, u8 eType){
|
||||
**
|
||||
** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
|
||||
*/
|
||||
int sqlite3MemdebugNoType(const void *p, u8 eType){
|
||||
int sqlite3MemdebugNoType(void *p, u8 eType){
|
||||
int rc = 1;
|
||||
if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
|
||||
struct MemBlockHdr *pHdr;
|
||||
|
||||
+10
-11
@@ -272,7 +272,7 @@ static int memdbRead(
|
||||
*/
|
||||
static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){
|
||||
unsigned char *pNew;
|
||||
if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || NEVER(p->nMmap>0) ){
|
||||
if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
|
||||
return SQLITE_FULL;
|
||||
}
|
||||
if( newSz>p->szMax ){
|
||||
@@ -331,9 +331,8 @@ static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){
|
||||
MemStore *p = ((MemFile*)pFile)->pStore;
|
||||
int rc = SQLITE_OK;
|
||||
memdbEnter(p);
|
||||
if( size>p->sz ){
|
||||
/* This can only happen with a corrupt wal mode db */
|
||||
rc = SQLITE_CORRUPT;
|
||||
if( NEVER(size>p->sz) ){
|
||||
rc = SQLITE_FULL;
|
||||
}else{
|
||||
p->sz = size;
|
||||
}
|
||||
@@ -472,7 +471,7 @@ static int memdbFetch(
|
||||
){
|
||||
MemStore *p = ((MemFile*)pFile)->pStore;
|
||||
memdbEnter(p);
|
||||
if( iOfst+iAmt>p->sz || (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)!=0 ){
|
||||
if( iOfst+iAmt>p->sz ){
|
||||
*pp = 0;
|
||||
}else{
|
||||
p->nMmap++;
|
||||
@@ -506,9 +505,10 @@ static int memdbOpen(
|
||||
MemFile *pFile = (MemFile*)pFd;
|
||||
MemStore *p = 0;
|
||||
int szName;
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
|
||||
memset(pFile, 0, sizeof(*pFile));
|
||||
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
|
||||
return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags);
|
||||
}
|
||||
memset(pFile, 0, sizeof(*p));
|
||||
szName = sqlite3Strlen30(zName);
|
||||
if( szName>1 && zName[0]=='/' ){
|
||||
int i;
|
||||
@@ -567,9 +567,8 @@ static int memdbOpen(
|
||||
p->szMax = sqlite3GlobalConfig.mxMemdbSize;
|
||||
}
|
||||
pFile->pStore = p;
|
||||
if( pOutFlags!=0 ){
|
||||
*pOutFlags = flags | SQLITE_OPEN_MEMORY;
|
||||
}
|
||||
assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
|
||||
*pOutFlags = flags | SQLITE_OPEN_MEMORY;
|
||||
pFd->pMethods = &memdb_io_methods;
|
||||
memdbLeave(p);
|
||||
return SQLITE_OK;
|
||||
|
||||
+12
-14
@@ -178,9 +178,6 @@ static int memjrnlCreateFile(MemJournal *p){
|
||||
}
|
||||
|
||||
|
||||
/* Forward reference */
|
||||
static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size);
|
||||
|
||||
/*
|
||||
** Write data to the file.
|
||||
*/
|
||||
@@ -210,21 +207,23 @@ static int memjrnlWrite(
|
||||
** access writes are not required. The only exception to this is when
|
||||
** the in-memory journal is being used by a connection using the
|
||||
** atomic-write optimization. In this case the first 28 bytes of the
|
||||
** journal file may be written as part of committing the transaction. */
|
||||
assert( iOfst<=p->endpoint.iOffset );
|
||||
if( iOfst>0 && iOfst!=p->endpoint.iOffset ){
|
||||
memjrnlTruncate(pJfd, iOfst);
|
||||
}
|
||||
** journal file may be written as part of committing the transaction. */
|
||||
assert( iOfst==p->endpoint.iOffset || iOfst==0 );
|
||||
#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
|
||||
|| defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
|
||||
if( iOfst==0 && p->pFirst ){
|
||||
assert( p->nChunkSize>iAmt );
|
||||
memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt);
|
||||
}else{
|
||||
}else
|
||||
#else
|
||||
assert( iOfst>0 || p->pFirst==0 );
|
||||
#endif
|
||||
{
|
||||
while( nWrite>0 ){
|
||||
FileChunk *pChunk = p->endpoint.pChunk;
|
||||
int iChunkOffset = (int)(p->endpoint.iOffset%p->nChunkSize);
|
||||
int iSpace = MIN(nWrite, p->nChunkSize - iChunkOffset);
|
||||
|
||||
assert( pChunk!=0 || iChunkOffset==0 );
|
||||
if( iChunkOffset==0 ){
|
||||
/* New chunk is required to extend the file. */
|
||||
FileChunk *pNew = sqlite3_malloc(fileChunkSize(p->nChunkSize));
|
||||
@@ -239,11 +238,10 @@ static int memjrnlWrite(
|
||||
assert( !p->pFirst );
|
||||
p->pFirst = pNew;
|
||||
}
|
||||
pChunk = p->endpoint.pChunk = pNew;
|
||||
p->endpoint.pChunk = pNew;
|
||||
}
|
||||
|
||||
assert( pChunk!=0 );
|
||||
memcpy((u8*)pChunk->zChunk + iChunkOffset, zWrite, iSpace);
|
||||
memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace);
|
||||
zWrite += iSpace;
|
||||
nWrite -= iSpace;
|
||||
p->endpoint.iOffset += iSpace;
|
||||
@@ -267,7 +265,7 @@ static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){
|
||||
p->pFirst = 0;
|
||||
}else{
|
||||
i64 iOff = p->nChunkSize;
|
||||
for(pIter=p->pFirst; ALWAYS(pIter) && iOff<size; pIter=pIter->pNext){
|
||||
for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){
|
||||
iOff += p->nChunkSize;
|
||||
}
|
||||
if( ALWAYS(pIter) ){
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user