Compare commits
428 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d6df8550b2 | |||
| 247d09462e | |||
| 2f3e34624a | |||
| ece092e728 | |||
| c6e2f2e64d | |||
| 836652952f | |||
| d024eca323 | |||
| 1a25be1a9a | |||
| 90402d4d54 | |||
| 5a1f761218 | |||
| 27e456458e | |||
| 605137aae6 | |||
| 7ef4d75bd2 | |||
| 3946561a7f | |||
| 463edb6275 | |||
| fde3043200 | |||
| 551b650236 | |||
| 5e121a50b3 | |||
| 105dcaa503 | |||
| 7931f0a3d8 | |||
| a1d60e6c8c | |||
| 6a51e70c5f | |||
| 6563d0c11a | |||
| 46dc631a32 | |||
| b528a5a04e | |||
| 577f0a1e45 | |||
| 32135d7e0a | |||
| e684ac6f12 | |||
| ec9b622fbf | |||
| 42bb09c412 | |||
| 4c460bbffd | |||
| 6d6ea42a25 | |||
| c5a55db75d | |||
| 41f46703b8 | |||
| 53e1186da9 | |||
| eab1064f04 | |||
| 97a985e0c5 | |||
| dc9513601e | |||
| ea840117af | |||
| 8f32d92786 | |||
| a275e76696 | |||
| 768ab1f296 | |||
| ff55da360d | |||
| 6f9d68817c | |||
| 07559b2716 | |||
| 4f12271780 | |||
| c9bcc5aab7 | |||
| 1902516d16 | |||
| 5694569591 | |||
| fc854505b4 | |||
| 5308d3931e | |||
| e3994f2975 | |||
| ceff761521 | |||
| 86af59830f | |||
| a055abb8c4 | |||
| 3b4cb719c0 | |||
| 3703429cdb | |||
| e7fae604a0 | |||
| 90368c5dcb | |||
| 935c37229c | |||
| 8552b10c45 | |||
| 74a12dd6fd | |||
| 0150c81cd3 | |||
| 4296357c90 | |||
| c9373e86e8 | |||
| b3d981c3b7 | |||
| f357cafaf5 | |||
| a1e951fa48 | |||
| a0318fd7b4 | |||
| 9090df6f73 | |||
| fc56950337 | |||
| a10be3da20 | |||
| 7fd6a7761f | |||
| d1f0a86c12 | |||
| 9606a13432 | |||
| c45924ebc2 | |||
| a7c9dd546b | |||
| b2d594a19b | |||
| cdc59c82ad | |||
| fc4fe5a837 | |||
| 19ae01be13 | |||
| 009a48e0ad | |||
| eac750e9a6 | |||
| 584bfcaeb6 | |||
| f2a777fa5d | |||
| 98095e3949 | |||
| 60f3657b4a | |||
| 16f56e8416 | |||
| a12500005f | |||
| 91260dcf83 | |||
| d01a1bd94a | |||
| a7919add6a | |||
| 1ff855b22e | |||
| b15a3940d1 | |||
| dedd51aed4 | |||
| 24ea5fb3e8 | |||
| be4e3c88f5 | |||
| 537a6bf189 | |||
| 0ca0988355 | |||
| e63b7bdac8 | |||
| 7d5113f0a3 | |||
| 9a4e88604c | |||
| 0aa0945111 | |||
| 3363386145 | |||
| 42de1c52dd | |||
| dfcb11de18 | |||
| 02ede43da2 | |||
| 8443505dc9 | |||
| af7b8dcb58 | |||
| 43a196a3bb | |||
| 0a704c3145 | |||
| 78138397b5 | |||
| f17f607556 | |||
| 7b57aa3da9 | |||
| eba21cd4be | |||
| 11fc3c0fa7 | |||
| 4ba1c5cc49 | |||
| 63a47336af | |||
| 85548fac8d | |||
| a03372745e | |||
| fa3ee3b10b | |||
| 0d58ae010c | |||
| 4c5c6214b1 | |||
| b30af022da | |||
| d7e185ce5d | |||
| eadccaa926 | |||
| 522608d3a2 | |||
| ddd3fe6fc4 | |||
| 58a53d6e7b | |||
| 208b7141d0 | |||
| 0d36368601 | |||
| e2adc0eea1 | |||
| 252fe67bdd | |||
| 9f4ce3b19f | |||
| 4e532958c1 | |||
| 07fc85a2bf | |||
| 633c798283 | |||
| 3e46db21d4 | |||
| e1c4743121 | |||
| 6e85b27cbb | |||
| 5d20a21814 | |||
| 51896e6fd7 | |||
| 89e9baa2ca | |||
| 2ef111168f | |||
| 17a93ae1b8 | |||
| 62fc069eb4 | |||
| 4f77c9208a | |||
| 796588ae07 | |||
| 4734b3f9b7 | |||
| dfce5b6dd5 | |||
| 569c10566e | |||
| 6c758900c2 | |||
| d515ea5b56 | |||
| bcd60d20a3 | |||
| 10d29c7a94 | |||
| 0fab10991b | |||
| 5a80050dd3 | |||
| 69b0ce33fd | |||
| 02e3e04134 | |||
| 7f1c111948 | |||
| 697c50b947 | |||
| 3832c3c10f | |||
| 19eef9af64 | |||
| 044a017abc | |||
| cc0db61364 | |||
| d96ab99588 | |||
| 2725db836b | |||
| 3d7a69e5ef | |||
| 38d1e44350 | |||
| 30e314e4cb | |||
| 9ede896ac1 | |||
| b30298d3ea | |||
| a9f18f0172 | |||
| 0fe7e7d924 | |||
| e66532a63b | |||
| ca1776b5f3 | |||
| cc4d55c9cb | |||
| 5aabdaebd5 | |||
| 47741b8de9 | |||
| 3769501235 | |||
| 5dce6f96d1 | |||
| 87fb37efce | |||
| e40f28618c | |||
| 92ecf306ec | |||
| b617219bac | |||
| 09a39ed522 | |||
| e229ca0307 | |||
| ddd166a350 | |||
| 86c756015b | |||
| 665b6b6b35 | |||
| f6f7888622 | |||
| 75863ec11c | |||
| cee5cb484d | |||
| d0c7baf505 | |||
| 0ae56fbdd0 | |||
| 8f2c0b59da | |||
| 233ba1b8eb | |||
| 895bab3383 | |||
| 4b51e8bd68 | |||
| a5c9a70757 | |||
| 15b01def1e | |||
| a2417ec75c | |||
| b32b30930f | |||
| 1da88b5ce6 | |||
| 0c7d3d399d | |||
| c692df2784 | |||
| b5d4473221 | |||
| 3cdb1394b9 | |||
| f5bc444077 | |||
| d48e88e56d | |||
| bcba3655ee | |||
| 68dc8151e0 | |||
| 9b9fc74f2e | |||
| 57c58b4de8 | |||
| ec778d2724 | |||
| 4d7f335e8b | |||
| a1c8151bab | |||
| e482fde6ee | |||
| d323a3a515 | |||
| 991d1085e3 | |||
| bd3a247c73 | |||
| fdb6f44fac | |||
| 82801a5b72 | |||
| f208abdd99 | |||
| 98bb34c501 | |||
| d6b44ec32a | |||
| 29a7bbffba | |||
| 85b70e009f | |||
| 1f3366cd68 | |||
| 14818366c7 | |||
| 5a6f818d84 | |||
| 7d44b22d45 | |||
| 72e30421c8 | |||
| ddbb3cb5ec | |||
| c4bb999962 | |||
| ce0b5e44b7 | |||
| 738d7b9fc0 | |||
| 8efc6a8c09 | |||
| 04f97602e2 | |||
| c5432c43e8 | |||
| beacaac2b5 | |||
| bbf647e64f | |||
| a6c596b194 | |||
| aa97b57b11 | |||
| 875912c246 | |||
| d83c90bd63 | |||
| d3c6c3459b | |||
| 18ccc5c5ab | |||
| f2afe4e888 | |||
| d3110034dc | |||
| cd379b8a53 | |||
| 9d44f18b3c | |||
| 5622c7f971 | |||
| 6bcd58572b | |||
| daefcd9e00 | |||
| dc60c68cc0 | |||
| 4f3557e4c9 | |||
| a3f51d7b3e | |||
| 9956c18a81 | |||
| 338b1fde62 | |||
| a4e4e18494 | |||
| 12b9fa979c | |||
| d5326c333f | |||
| 3c64888253 | |||
| 9dbf96bd70 | |||
| 10f7365748 | |||
| c6977c1c0d | |||
| ebc4434e99 | |||
| d0a9a46215 | |||
| b248668bc9 | |||
| 80d99e19b6 | |||
| 5d1bf4f560 | |||
| bda4d20080 | |||
| d0fa3484c6 | |||
| 29bbc2b51f | |||
| 7e17a3abbe | |||
| 44a5c0257f | |||
| 2dfe9664a9 | |||
| 24a82eadb3 | |||
| 4ce289d088 | |||
| a6ca90c38c | |||
| 0f42f71da2 | |||
| 3ea82384ea | |||
| 3907560848 | |||
| 017e363787 | |||
| 54bc63815a | |||
| c158c07a22 | |||
| 2b5fbb2836 | |||
| 16118265ca | |||
| b296ab6f6a | |||
| 9aff824090 | |||
| e1961c55c3 | |||
| 66306d86ab | |||
| 38cebe07bb | |||
| 092ba22cca | |||
| 41584df573 | |||
| 9ebe43c120 | |||
| 44c44cd7c5 | |||
| 412a59f56e | |||
| 9169d0cb0f | |||
| a2ba25b508 | |||
| d66d5c2d35 | |||
| a98c868a10 | |||
| 5cec7e1a5f | |||
| f62641e91c | |||
| c320e062a3 | |||
| ceeb04bf90 | |||
| b131bf7039 | |||
| 8b6dfc474b | |||
| f3c33c6235 | |||
| 62e9c352eb | |||
| b6592f6563 | |||
| 6e627c44de | |||
| a91734894e | |||
| fe46317e26 | |||
| 621a5e0c47 | |||
| aca5e49caa | |||
| 2999068d2c | |||
| 61fd4b9c3d | |||
| b71a485386 | |||
| e0adf60241 | |||
| 511b118dd2 | |||
| e3e2565daa | |||
| 8a95d3d433 | |||
| 52576b78f6 | |||
| 22f018c938 | |||
| 06164b2340 | |||
| 7f8f659260 | |||
| 4f2006ddec | |||
| c5860af006 | |||
| 089a9ff48a | |||
| dc56dc93a5 | |||
| ef95d5583b | |||
| 27a9e1f615 | |||
| b574acb94f | |||
| 5a4ac1cc30 | |||
| a11c5e22b5 | |||
| 59285ed788 | |||
| 5d88be8f48 | |||
| 92704681a1 | |||
| 15561b916d | |||
| 7e910f6422 | |||
| 969c46486c | |||
| fb82caf0be | |||
| 46658d7f9a | |||
| c491a25631 | |||
| 132f96fc75 | |||
| 761d64b73b | |||
| 3bd7cd736d | |||
| 23d41e63f2 | |||
| 50fb7e09b4 | |||
| 8c1c3e5e37 | |||
| c436b3056d | |||
| f6a4ef144e | |||
| 38ed1ceb5a | |||
| 39addd0a3f | |||
| 5baaf40af1 | |||
| 6ae49e67cc | |||
| 35685d3e5e | |||
| fecbf0a179 | |||
| 067c60cfc9 | |||
| 770dade262 | |||
| 19ce9aafdb | |||
| fa35f5c5a7 | |||
| 7439d3580c | |||
| 70b403b667 | |||
| 2b05905521 | |||
| 60a8e1b43c | |||
| 11e4fdb948 | |||
| fd4bf7746b | |||
| 2f0bc1d41b | |||
| 65a3c8508d | |||
| daebb0f9a0 | |||
| 1872c5bd43 | |||
| cbb7746caa | |||
| cdd9050396 | |||
| 844a89b518 | |||
| dae2a10934 | |||
| 79ab384121 | |||
| 9b3bfa00cd | |||
| 879ac4d673 | |||
| 3b26b2b56b | |||
| 2db144c33b | |||
| 4baf43ff64 | |||
| c1085ea412 | |||
| 78679a4950 | |||
| 4a0a98d3fd | |||
| 1312a9c908 | |||
| 6df8c0cd3b | |||
| 315e3122c3 | |||
| 14851b9a14 | |||
| 855a165fec | |||
| 913306a53a | |||
| e574a9233c | |||
| 2df026a549 | |||
| 622bd63c33 | |||
| b0906b6088 | |||
| 7907d372bc | |||
| 619a5f5572 | |||
| 70a05e9168 | |||
| b127d0fd2a | |||
| c7b29b0ce7 | |||
| 42ac4c2e5f | |||
| b670fd5545 | |||
| 81258cc911 | |||
| 9f9bdf9345 | |||
| 156d44104a | |||
| bb0c54283d | |||
| 6f991147bd | |||
| a51e60079f | |||
| d9137e3be0 | |||
| 5e90794b67 | |||
| 826ec6013c | |||
| 895c807a6d | |||
| 9cd0c3d4c5 | |||
| e41d30ffdd | |||
| 488b55856e | |||
| 9dc718856f | |||
| 3ce76a0bbb | |||
| 8745f8a3c3 | |||
| 5b001cc25d | |||
| a2852ac4d2 | |||
| 146121f5cb | |||
| 9135ebb7db | |||
| f9241a5fd0 | |||
| 3ab4ffce1f | |||
| 34e71830de | |||
| 46c425b4dd |
+9
-8
@@ -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 json1.lo legacy.lo loadext.lo \
|
||||
icu.lo insert.lo json.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,6 +234,7 @@ 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 \
|
||||
@@ -366,7 +367,6 @@ 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,6 +460,7 @@ 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 \
|
||||
@@ -608,7 +609,7 @@ TESTOPTS = --verbose=file --output=test-out.txt
|
||||
|
||||
# Extra compiler options for various shell tools
|
||||
#
|
||||
SHELL_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4
|
||||
SHELL_OPT = -DSQLITE_ENABLE_FTS4
|
||||
#SHELL_OPT += -DSQLITE_ENABLE_FTS5
|
||||
SHELL_OPT += -DSQLITE_ENABLE_RTREE
|
||||
SHELL_OPT += -DSQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
@@ -618,8 +619,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
|
||||
FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
|
||||
FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
|
||||
FUZZERSHELL_OPT =
|
||||
FUZZCHECK_OPT = -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
|
||||
FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
|
||||
FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
|
||||
@@ -873,6 +874,9 @@ 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
|
||||
|
||||
@@ -1176,9 +1180,6 @@ 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
|
||||
|
||||
|
||||
+20
-17
@@ -363,7 +363,6 @@ 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
|
||||
@@ -580,17 +579,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 -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
|
||||
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
|
||||
# <<mark>>
|
||||
TEST_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall -DINCLUDE_SQLITE_TCL_H=1 -DSQLITE_TCLAPI=__cdecl
|
||||
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
|
||||
# <</mark>>
|
||||
!ELSE
|
||||
!IFNDEF PLATFORM
|
||||
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
|
||||
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
|
||||
# <<mark>>
|
||||
TEST_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall -DINCLUDE_SQLITE_TCL_H=1 -DSQLITE_TCLAPI=__cdecl
|
||||
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
|
||||
# <</mark>>
|
||||
!ELSE
|
||||
CORE_CCONV_OPTS =
|
||||
@@ -1248,7 +1247,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 json1.lo legacy.lo loadext.lo \
|
||||
icu.lo insert.lo json.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 \
|
||||
@@ -1315,6 +1314,7 @@ 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,7 +1445,6 @@ 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.
|
||||
@@ -1579,6 +1578,7 @@ 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 \
|
||||
@@ -1695,9 +1695,9 @@ 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_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
|
||||
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
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS4
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS5
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_RTREE
|
||||
@@ -1990,6 +1990,9 @@ 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
|
||||
|
||||
@@ -2298,9 +2301,6 @@ 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,7 +2392,6 @@ 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)
|
||||
|
||||
@@ -2468,7 +2467,11 @@ 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
|
||||
test: $(TESTPROGS) sourcetest fuzztest tcltest
|
||||
|
||||
# The veryquick.test TCL tests.
|
||||
#
|
||||
tcltest: testfixture.exe
|
||||
@set PATH=$(LIBTCLPATH);$(PATH)
|
||||
.\testfixture.exe $(TOP)\test\veryquick.test $(TESTOPTS)
|
||||
|
||||
|
||||
@@ -309,9 +309,11 @@ 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 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
|
||||
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
|
||||
`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,7 +285,6 @@ 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
|
||||
@@ -502,12 +501,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 -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
|
||||
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
|
||||
!ELSE
|
||||
!IFNDEF PLATFORM
|
||||
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
|
||||
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
|
||||
!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_ENABLE_JSON1=1"
|
||||
"OPTS=-DSQLITE_ENABLE_STAT4=1 -DSQLITE_OMIT_JSON=1"
|
||||
|
||||
However, the following will not compile unless the amalgamation was built
|
||||
with it enabled:
|
||||
|
||||
@@ -173,21 +173,6 @@ 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.37.0.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.39.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.37.0'
|
||||
PACKAGE_STRING='sqlite 3.37.0'
|
||||
PACKAGE_VERSION='3.39.0'
|
||||
PACKAGE_STRING='sqlite 3.39.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,16 +903,15 @@ 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
|
||||
@@ -1469,7 +1468,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.37.0 to adapt to many kinds of systems.
|
||||
\`configure' configures sqlite 3.39.0 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -1534,7 +1533,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of sqlite 3.37.0:";;
|
||||
short | recursive ) echo "Configuration of sqlite 3.39.0:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@@ -1561,13 +1560,13 @@ Optional Features:
|
||||
--disable-load-extension
|
||||
Disable loading of external extensions
|
||||
--disable-math Disable math functions
|
||||
--enable-all Enable FTS4, FTS5, Geopoly, JSON, RTree, Sessions
|
||||
--disable-json Disable JSON functions
|
||||
--enable-all Enable FTS4, FTS5, Geopoly, 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
|
||||
@@ -1662,7 +1661,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
sqlite configure 3.37.0
|
||||
sqlite configure 3.39.0
|
||||
generated by GNU Autoconf 2.69
|
||||
|
||||
Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
@@ -2081,7 +2080,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.37.0, which was
|
||||
It was created by sqlite $as_me 3.39.0, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
@@ -3939,13 +3938,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:3940: $ac_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:3941: $ac_compile\"" >&5)
|
||||
(eval "$ac_compile" 2>conftest.err)
|
||||
cat conftest.err >&5
|
||||
(eval echo "\"\$as_me:3943: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
|
||||
(eval echo "\"\$as_me:3944: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
|
||||
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
|
||||
cat conftest.err >&5
|
||||
(eval echo "\"\$as_me:3946: output\"" >&5)
|
||||
(eval echo "\"\$as_me:3947: output\"" >&5)
|
||||
cat conftest.out >&5
|
||||
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
|
||||
lt_cv_nm_interface="MS dumpbin"
|
||||
@@ -5151,7 +5150,7 @@ ia64-*-hpux*)
|
||||
;;
|
||||
*-*-irix6*)
|
||||
# Find out which ABI we are using.
|
||||
echo '#line 5152 "configure"' > conftest.$ac_ext
|
||||
echo '#line 5153 "configure"' > conftest.$ac_ext
|
||||
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
|
||||
(eval $ac_compile) 2>&5
|
||||
ac_status=$?
|
||||
@@ -6676,11 +6675,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:6677: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:6678: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:6681: \$? = $ac_status" >&5
|
||||
echo "$as_me:6682: \$? = $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.
|
||||
@@ -7015,11 +7014,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:7016: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7017: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:7020: \$? = $ac_status" >&5
|
||||
echo "$as_me:7021: \$? = $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.
|
||||
@@ -7120,11 +7119,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:7121: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7122: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7125: \$? = $ac_status" >&5
|
||||
echo "$as_me:7126: \$? = $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
|
||||
@@ -7175,11 +7174,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:7176: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7177: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7180: \$? = $ac_status" >&5
|
||||
echo "$as_me:7181: \$? = $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
|
||||
@@ -9555,7 +9554,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 9556 "configure"
|
||||
#line 9557 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -9651,7 +9650,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 9652 "configure"
|
||||
#line 9653 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -10307,13 +10306,6 @@ 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.
|
||||
@@ -11284,19 +11276,6 @@ 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
|
||||
@@ -11518,6 +11497,24 @@ 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
|
||||
@@ -11722,24 +11719,6 @@ 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.
|
||||
@@ -11882,6 +11861,17 @@ 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
|
||||
@@ -12400,7 +12390,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.37.0, which was
|
||||
This file was extended by sqlite $as_me 3.39.0, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@@ -12466,7 +12456,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.37.0
|
||||
sqlite config.status 3.39.0
|
||||
configured by $0, generated by GNU Autoconf 2.69,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
|
||||
+24
-12
@@ -605,12 +605,24 @@ 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, JSON, RTree, Sessions]))
|
||||
[Enable FTS4, FTS5, Geopoly, RTree, Sessions]))
|
||||
|
||||
##########
|
||||
# Do we want to support memsys3 and/or memsys5
|
||||
@@ -666,17 +678,6 @@ 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.
|
||||
@@ -791,6 +792,17 @@ 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
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
# 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.
|
||||
@@ -697,17 +697,25 @@ static int idxGetTableInfo(
|
||||
){
|
||||
sqlite3_stmt *p1 = 0;
|
||||
int nCol = 0;
|
||||
int nTab = STRLEN(zTab);
|
||||
int nByte = sizeof(IdxTable) + nTab + 1;
|
||||
int nTab;
|
||||
int nByte;
|
||||
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
|
||||
@@ -734,7 +742,9 @@ 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 = STRLEN(zCol) + 1;
|
||||
int nCopy;
|
||||
if( zCol==0 ) continue;
|
||||
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);
|
||||
@@ -886,6 +896,7 @@ 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;
|
||||
@@ -1168,7 +1179,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.
|
||||
*/
|
||||
int idxFindIndexes(
|
||||
static int idxFindIndexes(
|
||||
sqlite3expert *p,
|
||||
char **pzErr /* OUT: Error message (sqlite3_malloc) */
|
||||
){
|
||||
@@ -1297,6 +1308,7 @@ 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);
|
||||
@@ -1399,8 +1411,9 @@ 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' ){
|
||||
rc = sqlite3_exec(p->dbv, zSql, 0, 0, pzErrmsg);
|
||||
if( zSql ) rc = sqlite3_exec(p->dbv, zSql, 0, 0, pzErrmsg);
|
||||
}else{
|
||||
IdxTable *pTab;
|
||||
rc = idxGetTableInfo(p->db, zName, &pTab, pzErrmsg);
|
||||
@@ -1537,6 +1550,7 @@ 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 ){
|
||||
@@ -1548,9 +1562,11 @@ static void idxRemFunc(
|
||||
}
|
||||
pSlot->n = nByte;
|
||||
if( pSlot->eType==SQLITE_BLOB ){
|
||||
memcpy(pSlot->z, sqlite3_value_blob(argv[1]), nByte);
|
||||
pData = sqlite3_value_blob(argv[1]);
|
||||
if( pData ) memcpy(pSlot->z, pData, nByte);
|
||||
}else{
|
||||
memcpy(pSlot->z, sqlite3_value_text(argv[1]), nByte);
|
||||
pData = sqlite3_value_text(argv[1]);
|
||||
memcpy(pSlot->z, pData, nByte);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1761,6 +1777,7 @@ 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;
|
||||
@@ -1827,14 +1844,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;
|
||||
sqlite3_stmt *pSql = 0;
|
||||
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);
|
||||
rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
|
||||
if( zSql ) rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
|
||||
}
|
||||
idxFinalize(&rc, pSql);
|
||||
}
|
||||
|
||||
+30
-17
@@ -308,6 +308,12 @@
|
||||
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(
|
||||
@@ -1172,7 +1178,7 @@ static int fts3InitVtab(
|
||||
sqlite3_vtab **ppVTab, /* Write the resulting vtab structure here */
|
||||
char **pzErr /* Write any error message here */
|
||||
){
|
||||
Fts3Hash *pHash = (Fts3Hash *)pAux;
|
||||
Fts3Hash *pHash = &((Fts3HashWrapper*)pAux)->hash;
|
||||
Fts3Table *p = 0; /* Pointer to allocated vtab */
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
int i; /* Iterator variable */
|
||||
@@ -4007,9 +4013,12 @@ static const sqlite3_module fts3Module = {
|
||||
** allocated for the tokenizer hash table.
|
||||
*/
|
||||
static void hashDestroy(void *p){
|
||||
Fts3Hash *pHash = (Fts3Hash *)p;
|
||||
sqlite3Fts3HashClear(pHash);
|
||||
sqlite3_free(pHash);
|
||||
Fts3HashWrapper *pHash = (Fts3HashWrapper *)p;
|
||||
pHash->nRef--;
|
||||
if( pHash->nRef<=0 ){
|
||||
sqlite3Fts3HashClear(&pHash->hash);
|
||||
sqlite3_free(pHash);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4039,7 +4048,7 @@ void sqlite3Fts3IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
|
||||
*/
|
||||
int sqlite3Fts3Init(sqlite3 *db){
|
||||
int rc = SQLITE_OK;
|
||||
Fts3Hash *pHash = 0;
|
||||
Fts3HashWrapper *pHash = 0;
|
||||
const sqlite3_tokenizer_module *pSimple = 0;
|
||||
const sqlite3_tokenizer_module *pPorter = 0;
|
||||
#ifndef SQLITE_DISABLE_FTS3_UNICODE
|
||||
@@ -4067,23 +4076,24 @@ int sqlite3Fts3Init(sqlite3 *db){
|
||||
sqlite3Fts3PorterTokenizerModule(&pPorter);
|
||||
|
||||
/* Allocate and initialize the hash-table used to store tokenizers. */
|
||||
pHash = sqlite3_malloc(sizeof(Fts3Hash));
|
||||
pHash = sqlite3_malloc(sizeof(Fts3HashWrapper));
|
||||
if( !pHash ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1);
|
||||
sqlite3Fts3HashInit(&pHash->hash, FTS3_HASH_STRING, 1);
|
||||
pHash->nRef = 0;
|
||||
}
|
||||
|
||||
/* Load the built-in tokenizers into the hash table */
|
||||
if( rc==SQLITE_OK ){
|
||||
if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple)
|
||||
|| sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter)
|
||||
if( sqlite3Fts3HashInsert(&pHash->hash, "simple", 7, (void *)pSimple)
|
||||
|| sqlite3Fts3HashInsert(&pHash->hash, "porter", 7, (void *)pPorter)
|
||||
|
||||
#ifndef SQLITE_DISABLE_FTS3_UNICODE
|
||||
|| sqlite3Fts3HashInsert(pHash, "unicode61", 10, (void *)pUnicode)
|
||||
|| sqlite3Fts3HashInsert(&pHash->hash, "unicode61", 10, (void *)pUnicode)
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_ICU
|
||||
|| (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu))
|
||||
|| (pIcu && sqlite3Fts3HashInsert(&pHash->hash, "icu", 4, (void *)pIcu))
|
||||
#endif
|
||||
){
|
||||
rc = SQLITE_NOMEM;
|
||||
@@ -4092,7 +4102,7 @@ int sqlite3Fts3Init(sqlite3 *db){
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts3ExprInitTestInterface(db, pHash);
|
||||
rc = sqlite3Fts3ExprInitTestInterface(db, &pHash->hash);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4101,23 +4111,26 @@ int sqlite3Fts3Init(sqlite3 *db){
|
||||
** module with sqlite.
|
||||
*/
|
||||
if( SQLITE_OK==rc
|
||||
&& SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
|
||||
&& SQLITE_OK==(rc=sqlite3Fts3InitHashTable(db,&pHash->hash,"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, 0
|
||||
db, "fts4", &fts3Module, (void *)pHash, hashDestroy
|
||||
);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts3InitTok(db, (void *)pHash);
|
||||
pHash->nRef++;
|
||||
rc = sqlite3Fts3InitTok(db, (void *)pHash, hashDestroy);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -4126,7 +4139,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);
|
||||
sqlite3Fts3HashClear(&pHash->hash);
|
||||
sqlite3_free(pHash);
|
||||
}
|
||||
return rc;
|
||||
@@ -4473,7 +4486,7 @@ void sqlite3Fts3DoclistPrev(
|
||||
|
||||
assert( nDoclist>0 );
|
||||
assert( *pbEof==0 );
|
||||
assert( p || *piDocid==0 );
|
||||
assert_fts3_nc( p || *piDocid==0 );
|
||||
assert( !p || (p>aDoclist && p<&aDoclist[nDoclist]) );
|
||||
|
||||
if( p==0 ){
|
||||
|
||||
+1
-1
@@ -641,7 +641,7 @@ int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
|
||||
int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
|
||||
|
||||
/* fts3_tokenize_vtab.c */
|
||||
int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *);
|
||||
int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *, void(*xDestroy)(void*));
|
||||
|
||||
/* fts3_unicode2.c (functions generated by parsing unicode text files) */
|
||||
#ifndef SQLITE_DISABLE_FTS3_UNICODE
|
||||
|
||||
+5
-1
@@ -297,6 +297,7 @@ 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;
|
||||
@@ -340,6 +341,10 @@ 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;
|
||||
@@ -348,7 +353,6 @@ static int fts3auxNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
}
|
||||
|
||||
pCsr->iCol = 0;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
pCsr->isEof = 1;
|
||||
}
|
||||
|
||||
@@ -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){
|
||||
int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash, void(*xDestroy)(void*)){
|
||||
static const sqlite3_module fts3tok_module = {
|
||||
0, /* iVersion */
|
||||
fts3tokConnectMethod, /* xCreate */
|
||||
@@ -449,7 +449,9 @@ int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash){
|
||||
};
|
||||
int rc; /* Return code */
|
||||
|
||||
rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, (void*)pHash);
|
||||
rc = sqlite3_create_module_v2(
|
||||
db, "fts3tokenize", &fts3tok_module, (void*)pHash, xDestroy
|
||||
);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
#!/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
|
||||
@@ -850,7 +850,7 @@ int sqlite3Fts5StructureTest(Fts5Index *p, void *pStruct){
|
||||
static void fts5StructureMakeWritable(int *pRc, Fts5Structure **pp){
|
||||
Fts5Structure *p = *pp;
|
||||
if( *pRc==SQLITE_OK && p->nRef>1 ){
|
||||
int nByte = sizeof(Fts5Structure)+(p->nLevel-1)*sizeof(Fts5StructureLevel);
|
||||
i64 nByte = sizeof(Fts5Structure)+(p->nLevel-1)*sizeof(Fts5StructureLevel);
|
||||
Fts5Structure *pNew;
|
||||
pNew = (Fts5Structure*)sqlite3Fts5MallocZero(pRc, nByte);
|
||||
if( pNew ){
|
||||
@@ -1879,8 +1879,12 @@ static void fts5SegIterReverseNewPage(Fts5Index *p, Fts5SegIter *pIter){
|
||||
int iRowidOff;
|
||||
iRowidOff = fts5LeafFirstRowidOff(pNew);
|
||||
if( iRowidOff ){
|
||||
pIter->pLeaf = pNew;
|
||||
pIter->iLeafOffset = iRowidOff;
|
||||
if( iRowidOff>=pNew->szLeaf ){
|
||||
p->rc = FTS5_CORRUPT;
|
||||
}else{
|
||||
pIter->pLeaf = pNew;
|
||||
pIter->iLeafOffset = iRowidOff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5561,7 +5565,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 ) memcpy(&buf.p[1], pToken, nToken);
|
||||
if( nToken>0 ) 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
|
||||
|
||||
@@ -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);
|
||||
CsrFlagSet(pCsr, FTS5CSR_EOF|FTS5CSR_REQUIRE_CONTENT);
|
||||
}else if( rc==SQLITE_ROW ){
|
||||
const u8 *a;
|
||||
const u8 *aBlob;
|
||||
|
||||
@@ -374,7 +374,7 @@ static int fts5VocabOpenMethod(
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
int nByte = pFts5->pConfig->nCol * sizeof(i64)*2 + sizeof(Fts5VocabCursor);
|
||||
i64 nByte = pFts5->pConfig->nCol * sizeof(i64)*2 + sizeof(Fts5VocabCursor);
|
||||
pCsr = (Fts5VocabCursor*)sqlite3Fts5MallocZero(&rc, nByte);
|
||||
}
|
||||
|
||||
|
||||
@@ -15366,6 +15366,160 @@ 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
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# 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');
|
||||
|
||||
+4
-10
@@ -153,18 +153,12 @@ SQLite. Documentation follows.
|
||||
the ICU extension LIKE operator is 50000, defined in source
|
||||
file "icu.c".
|
||||
|
||||
3.3 Collation Sequence Security Issue
|
||||
3.3 Collation Sequence Security
|
||||
|
||||
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 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.
|
||||
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.
|
||||
|
||||
+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
@@ -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);
|
||||
|
||||
+2
-1
@@ -368,10 +368,11 @@ 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( symlink(zTo, zFile)<0 ) return 1;
|
||||
if( zTo==0 || symlink(zTo, zFile)<0 ) return 1;
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
|
||||
+1
-1
@@ -284,7 +284,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);
|
||||
|
||||
@@ -0,0 +1,461 @@
|
||||
/*
|
||||
** 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
-4
@@ -759,13 +759,15 @@ 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,
|
||||
0, re_sql_func, 0, 0);
|
||||
rc = sqlite3_create_function(db, "regexp", 2,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
||||
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,
|
||||
(void*)db, re_sql_func, 0, 0);
|
||||
rc = sqlite3_create_function(db, "regexpi", 2,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
||||
(void*)db, re_sql_func, 0, 0);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
+1
-1
@@ -386,7 +386,7 @@ static int seriesBestIndex(
|
||||
** the preferred case */
|
||||
pIdxInfo->estimatedCost = (double)(2 - ((idxNum&4)!=0));
|
||||
pIdxInfo->estimatedRows = 1000;
|
||||
if( pIdxInfo->nOrderBy==1 ){
|
||||
if( pIdxInfo->nOrderBy>=1 && pIdxInfo->aOrderBy[0].iColumn==0 ){
|
||||
if( pIdxInfo->aOrderBy[0].desc ){
|
||||
idxNum |= 8;
|
||||
}else{
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ struct SHA1Context {
|
||||
/*
|
||||
* Hash a single 512-bit block. This is the core of the algorithm.
|
||||
*/
|
||||
void SHA1Transform(unsigned int state[5], const unsigned char buffer[64]){
|
||||
static 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];
|
||||
|
||||
+2
-1
@@ -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 evalutes all queries in the SQL statements of Y
|
||||
** The sha3_query(Y) function evaluates 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,6 +436,7 @@ 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){
|
||||
|
||||
+6
-2
@@ -1938,7 +1938,7 @@ static int zipfileBufferGrow(ZipfileBuffer *pBuf, int nByte){
|
||||
** SELECT zipfile(name,mode,mtime,data) ...
|
||||
** SELECT zipfile(name,mode,mtime,data,method) ...
|
||||
*/
|
||||
void zipfileStep(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal){
|
||||
static 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 +2113,7 @@ void zipfileStep(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal){
|
||||
/*
|
||||
** xFinalize() callback for zipfile aggregate function.
|
||||
*/
|
||||
void zipfileFinal(sqlite3_context *pCtx){
|
||||
static void zipfileFinal(sqlite3_context *pCtx){
|
||||
ZipfileCtx *p;
|
||||
ZipfileEOCD eocd;
|
||||
sqlite3_int64 nZip;
|
||||
@@ -2170,6 +2170,10 @@ 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);
|
||||
|
||||
@@ -198,7 +198,11 @@ if {$::tcl_platform(platform)=="unix"} {
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test 5.$tn.2 { file exists test.db-vacuum } 1
|
||||
do_test 5.$tn.3 { file attributes test.db-vacuum -permissions} $perm
|
||||
# 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/
|
||||
rbu close
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1563,7 +1563,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.
|
||||
*/
|
||||
char *rbuVacuumIndexStart(
|
||||
static char *rbuVacuumIndexStart(
|
||||
sqlite3rbu *p, /* RBU handle */
|
||||
RbuObjIter *pIter /* RBU iterator object */
|
||||
){
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
#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
|
||||
|
||||
+4
-7
@@ -26,11 +26,7 @@
|
||||
# define GEODEBUG(X)
|
||||
#endif
|
||||
|
||||
#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.
|
||||
*/
|
||||
/* Character class routines */
|
||||
#ifdef sqlite3Isdigit
|
||||
/* Use the SQLite core versions if this routine is part of the
|
||||
** SQLite amalgamation */
|
||||
@@ -45,6 +41,7 @@
|
||||
# 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.
|
||||
@@ -67,7 +64,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 safe_isspace(x) (geopolyIsSpace[(unsigned char)x])
|
||||
#define fast_isspace(x) (geopolyIsSpace[(unsigned char)x])
|
||||
#endif /* JSON NULL - back to original code */
|
||||
|
||||
/* Compiler and version */
|
||||
@@ -156,7 +153,7 @@ static void geopolySwab32(unsigned char *a){
|
||||
|
||||
/* Skip whitespace. Return the next non-whitespace character. */
|
||||
static char geopolySkipSpace(GeoParse *p){
|
||||
while( safe_isspace(p->z[0]) ) p->z++;
|
||||
while( fast_isspace(p->z[0]) ) p->z++;
|
||||
return p->z[0];
|
||||
}
|
||||
|
||||
|
||||
+14
-5
@@ -1287,20 +1287,29 @@ 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;
|
||||
if( p->op!=RTREE_EQ ) break; /* RTREE_LE and RTREE_LT end here */
|
||||
/* Fall through for the RTREE_EQ case */
|
||||
break;
|
||||
|
||||
default: /* RTREE_GT or RTREE_GE, or fallthrough of RTREE_EQ */
|
||||
default:
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ do_corruption_tests rtreeA-3.1 {
|
||||
}
|
||||
|
||||
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}
|
||||
@@ -221,7 +221,7 @@ do_corruption_tests rtreeA-5.1 {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@@ -304,7 +304,7 @@ static int box_query(sqlite3_rtree_query_info *pInfo){
|
||||
static void box_query_destroy(void *p){
|
||||
BoxQueryCtx *pCtx = (BoxQueryCtx*)p;
|
||||
Tcl_DecrRefCount(pCtx->pScript);
|
||||
ckfree(pCtx);
|
||||
ckfree((char*)pCtx);
|
||||
}
|
||||
|
||||
static int SQLITE_TCLAPI register_box_query(
|
||||
@@ -324,7 +324,7 @@ static int SQLITE_TCLAPI register_box_query(
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
|
||||
pCtx = (BoxQueryCtx*)ckalloc(sizeof(BoxQueryCtx*));
|
||||
pCtx = (BoxQueryCtx*)ckalloc(sizeof(BoxQueryCtx));
|
||||
pCtx->interp = interp;
|
||||
pCtx->pScript = Tcl_DuplicateObj(objv[2]);
|
||||
Tcl_IncrRefCount(pCtx->pScript);
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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 json1.o legacy.o loadext.o \
|
||||
icu.o insert.o json.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,6 +111,7 @@ 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 \
|
||||
@@ -244,7 +245,6 @@ SRC += \
|
||||
$(TOP)/ext/rbu/sqlite3rbu.c \
|
||||
$(TOP)/ext/rbu/sqlite3rbu.h
|
||||
SRC += \
|
||||
$(TOP)/ext/misc/json1.c \
|
||||
$(TOP)/ext/misc/stmt.c
|
||||
|
||||
|
||||
@@ -377,6 +377,7 @@ 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 \
|
||||
@@ -528,7 +529,7 @@ TESTOPTS = --verbose=file --output=test-out.txt
|
||||
|
||||
# Extra compiler options for various shell tools
|
||||
#
|
||||
SHELL_OPT += -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5
|
||||
SHELL_OPT += -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5
|
||||
SHELL_OPT += -DSQLITE_ENABLE_RTREE
|
||||
SHELL_OPT += -DSQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
SHELL_OPT += -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
|
||||
@@ -537,8 +538,7 @@ 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 = -DSQLITE_ENABLE_JSON1
|
||||
FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5
|
||||
FUZZCHECK_OPT = -DSQLITE_ENABLE_MEMSYS5
|
||||
FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
|
||||
FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
|
||||
@@ -678,9 +678,6 @@ 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
|
||||
@@ -831,9 +828,6 @@ 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
|
||||
|
||||
@@ -931,12 +925,6 @@ 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 @@
|
||||
de10795a1cf70925088e9652998e813665b2e147ffa4a4edab18c7e2c66bf5ae
|
||||
0c5be14aac07222b9cd2404ae485b6587f8cb2899e776bc45f1f1117bdd7e9b7
|
||||
+63
-35
@@ -324,7 +324,9 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
int r1; /* Temporary registers */
|
||||
|
||||
db = pParse->db;
|
||||
if( pParse->nErr || db->mallocFailed ) return;
|
||||
assert( db->pParse==pParse );
|
||||
if( pParse->nErr ) return;
|
||||
assert( db->mallocFailed==0 );
|
||||
pNew = pParse->pNewTable;
|
||||
assert( pNew );
|
||||
|
||||
@@ -450,7 +452,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(\"%w\",\"%w\")"
|
||||
" FROM pragma_quick_check(%Q,%Q)"
|
||||
" WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'",
|
||||
zTab, zDb
|
||||
);
|
||||
@@ -629,7 +631,7 @@ void sqlite3AlterRenameColumn(
|
||||
if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break;
|
||||
}
|
||||
if( iCol==pTab->nCol ){
|
||||
sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
|
||||
sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld);
|
||||
goto exit_rename_column;
|
||||
}
|
||||
|
||||
@@ -735,7 +737,9 @@ struct RenameCtx {
|
||||
** following a valid object, it may not be used in comparison operations.
|
||||
*/
|
||||
static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
|
||||
if( pParse->nErr==0 && pParse->db->mallocFailed==0 ){
|
||||
assert( pParse==pParse->db->pParse );
|
||||
assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
|
||||
if( pParse->nErr==0 ){
|
||||
const RenameToken *p;
|
||||
u8 i = 0;
|
||||
for(p=pParse->pRename; p; p=p->pNext){
|
||||
@@ -1057,12 +1061,12 @@ static void renameColumnParseError(
|
||||
const char *zN = (const char*)sqlite3_value_text(pObject);
|
||||
char *zErr;
|
||||
|
||||
zErr = sqlite3_mprintf("error in %s %s%s%s: %s",
|
||||
zErr = sqlite3MPrintf(pParse->db, "error in %s %s%s%s: %s",
|
||||
zT, zN, (zWhen[0] ? " " : ""), zWhen,
|
||||
pParse->zErrMsg
|
||||
);
|
||||
sqlite3_result_error(pCtx, zErr, -1);
|
||||
sqlite3_free(zErr);
|
||||
sqlite3DbFree(pParse->db, zErr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1126,24 +1130,22 @@ 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 = zSql ? sqlite3RunParser(p, zSql, &zErr) : SQLITE_NOMEM;
|
||||
assert( p->zErrMsg==0 );
|
||||
assert( rc!=SQLITE_OK || zErr==0 );
|
||||
p->zErrMsg = zErr;
|
||||
rc = sqlite3RunParser(p, zSql);
|
||||
if( db->mallocFailed ) rc = SQLITE_NOMEM;
|
||||
if( rc==SQLITE_OK
|
||||
&& p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0
|
||||
&& NEVER(p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0)
|
||||
){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
@@ -1421,13 +1423,13 @@ static void renameParseCleanup(Parse *pParse){
|
||||
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
|
||||
sqlite3DbFree(db, pParse->zErrMsg);
|
||||
renameTokenFree(db, pParse->pRename);
|
||||
sqlite3ParserReset(pParse);
|
||||
sqlite3ParseObjectReset(pParse);
|
||||
}
|
||||
|
||||
/*
|
||||
** SQL function:
|
||||
**
|
||||
** sqlite_rename_column(zSql, iCol, bQuote, zNew, zTable, zOld)
|
||||
** sqlite_rename_column(SQL,TYPE,OBJ,DB,TABLE,COL,NEWNAME,QUOTE,TEMP)
|
||||
**
|
||||
** 0. zSql: SQL statement to rewrite
|
||||
** 1. type: Type of object ("table", "view" etc.)
|
||||
@@ -1445,7 +1447,8 @@ 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().
|
||||
** not reachable from ordinary SQL passed into sqlite3_prepare() unless the
|
||||
** SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test setting is enabled.
|
||||
*/
|
||||
static void renameColumnFunc(
|
||||
sqlite3_context *context,
|
||||
@@ -1594,7 +1597,9 @@ static void renameColumnFunc(
|
||||
|
||||
renameColumnFunc_done:
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( sParse.zErrMsg ){
|
||||
if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){
|
||||
sqlite3_result_value(context, argv[0]);
|
||||
}else if( sParse.zErrMsg ){
|
||||
renameColumnParseError(context, "", argv[1], argv[2], &sParse);
|
||||
}else{
|
||||
sqlite3_result_error_code(context, rc);
|
||||
@@ -1793,7 +1798,9 @@ static void renameTableFunc(
|
||||
rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote);
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( sParse.zErrMsg ){
|
||||
if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){
|
||||
sqlite3_result_value(context, argv[3]);
|
||||
}else if( sParse.zErrMsg ){
|
||||
renameColumnParseError(context, "", argv[1], argv[2], &sParse);
|
||||
}else{
|
||||
sqlite3_result_error_code(context, rc);
|
||||
@@ -1818,10 +1825,10 @@ static int renameQuotefixExprCb(Walker *pWalker, Expr *pExpr){
|
||||
return WRC_Continue;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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.
|
||||
/* 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.
|
||||
**
|
||||
** Two arguments must be passed:
|
||||
**
|
||||
@@ -1840,6 +1847,10 @@ 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,
|
||||
@@ -1914,7 +1925,11 @@ static void renameQuotefixFunc(
|
||||
renameTokenFree(db, sCtx.pList);
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3_result_error_code(context, rc);
|
||||
if( sqlite3WritableSchema(db) && rc==SQLITE_ERROR ){
|
||||
sqlite3_result_value(context, argv[1]);
|
||||
}else{
|
||||
sqlite3_result_error_code(context, rc);
|
||||
}
|
||||
}
|
||||
renameParseCleanup(&sParse);
|
||||
}
|
||||
@@ -1926,7 +1941,8 @@ 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
|
||||
@@ -1941,11 +1957,13 @@ static void renameQuotefixFunc(
|
||||
** 5: "when" part of error message.
|
||||
** 6: True to disable the DQS quirk when parsing SQL.
|
||||
**
|
||||
** Unless it finds an error, this function normally returns NULL. However, it
|
||||
** returns integer value 1 if:
|
||||
** The return value is computed as follows:
|
||||
**
|
||||
** * the SQL argument creates a trigger, and
|
||||
** * the table that the trigger is attached to is in database zDb.
|
||||
** 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.
|
||||
*/
|
||||
static void renameTableTest(
|
||||
sqlite3_context *context,
|
||||
@@ -1990,12 +2008,16 @@ static void renameTableTest(
|
||||
if( rc==SQLITE_OK ){
|
||||
int i1 = sqlite3SchemaToIndex(db, sParse.pNewTrigger->pTabSchema);
|
||||
int i2 = sqlite3FindDbName(db, zDb);
|
||||
if( i1==i2 ) sqlite3_result_int(context, 1);
|
||||
if( i1==i2 ){
|
||||
/* Handle output case B */
|
||||
sqlite3_result_int(context, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( rc!=SQLITE_OK && zWhen ){
|
||||
if( rc!=SQLITE_OK && zWhen && !sqlite3WritableSchema(db) ){
|
||||
/* Output case A */
|
||||
renameColumnParseError(context, zWhen, argv[2], argv[3],&sParse);
|
||||
}
|
||||
renameParseCleanup(&sParse);
|
||||
@@ -2111,7 +2133,7 @@ void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, const Token *pName){
|
||||
}
|
||||
iCol = sqlite3ColumnIndex(pTab, zCol);
|
||||
if( iCol<0 ){
|
||||
sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zCol);
|
||||
sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pName);
|
||||
goto exit_drop_column;
|
||||
}
|
||||
|
||||
@@ -2135,6 +2157,12 @@ 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,
|
||||
|
||||
+1
-1
@@ -1023,7 +1023,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_DYNBLOB);
|
||||
sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNAMIC);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+1
-1
@@ -354,7 +354,7 @@ static void codeAttach(
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( pAuthArg ){
|
||||
if( ALWAYS(pAuthArg) ){
|
||||
char *zAuthArg;
|
||||
if( pAuthArg->op==TK_STRING ){
|
||||
assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
|
||||
|
||||
+2
-3
@@ -85,14 +85,13 @@ static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
|
||||
if( i==1 ){
|
||||
Parse sParse;
|
||||
int rc = 0;
|
||||
memset(&sParse, 0, sizeof(sParse));
|
||||
sParse.db = pDb;
|
||||
sqlite3ParseObjectInit(&sParse,pDb);
|
||||
if( sqlite3OpenTempDatabase(&sParse) ){
|
||||
sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg);
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
sqlite3DbFree(pErrorDb, sParse.zErrMsg);
|
||||
sqlite3ParserReset(&sParse);
|
||||
sqlite3ParseObjectReset(&sParse);
|
||||
if( rc ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
+307
-103
@@ -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==(int)iRoot ){
|
||||
if( pIdx->tnum==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 BtreeMovetoUnpacked() to do the work.
|
||||
** record and then call sqlite3BtreeIndexMoveto() to do the work.
|
||||
*/
|
||||
static int btreeMoveto(
|
||||
BtCursor *pCur, /* Cursor open on the btree to be searched */
|
||||
@@ -1225,18 +1225,32 @@ static void btreeParseCellPtr(
|
||||
**
|
||||
** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
|
||||
**
|
||||
** The code is inlined to avoid a function call.
|
||||
** The code is inlined and the loop is unrolled for performance.
|
||||
** This routine is a high-runner.
|
||||
*/
|
||||
iKey = *pIter;
|
||||
if( iKey>=0x80 ){
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1246,7 +1260,7 @@ static void btreeParseCellPtr(
|
||||
pInfo->nPayload = nPayload;
|
||||
pInfo->pPayload = pIter;
|
||||
testcase( nPayload==pPage->maxLocal );
|
||||
testcase( nPayload==pPage->maxLocal+1 );
|
||||
testcase( nPayload==(u32)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.
|
||||
@@ -1283,7 +1297,7 @@ static void btreeParseCellPtrIndex(
|
||||
pInfo->nPayload = nPayload;
|
||||
pInfo->pPayload = pIter;
|
||||
testcase( nPayload==pPage->maxLocal );
|
||||
testcase( nPayload==pPage->maxLocal+1 );
|
||||
testcase( nPayload==(u32)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.
|
||||
@@ -1313,6 +1327,7 @@ 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){
|
||||
@@ -1338,15 +1353,8 @@ 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==pPage->maxLocal+1 );
|
||||
testcase( nSize==(u32)pPage->maxLocal+1 );
|
||||
if( nSize<=pPage->maxLocal ){
|
||||
nSize += (u32)(pIter - pCell);
|
||||
if( nSize<4 ) nSize = 4;
|
||||
@@ -1354,7 +1362,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==pPage->maxLocal+1 );
|
||||
testcase( nSize==(u32)pPage->maxLocal+1 );
|
||||
if( nSize>pPage->maxLocal ){
|
||||
nSize = minLocal;
|
||||
}
|
||||
@@ -1384,6 +1392,58 @@ 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
|
||||
@@ -1397,7 +1457,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 pPager are often the same.) If pCell contains a
|
||||
** of pPage. (pSrc and pPage 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.
|
||||
*/
|
||||
@@ -1488,7 +1548,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( iFree+sz>usableSize ){
|
||||
}else if( NEVER(iFree+sz>usableSize) ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
|
||||
@@ -1572,7 +1632,8 @@ 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 */
|
||||
int pc = get2byte(&aData[iAddr]); /* Address of a free slot */
|
||||
u8 *pTmp = &aData[iAddr]; /* Temporary ptr into aData[] */
|
||||
int pc = get2byte(pTmp); /* 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 */
|
||||
@@ -1582,7 +1643,8 @@ 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. */
|
||||
size = get2byte(&aData[pc+2]);
|
||||
pTmp = &aData[pc+2];
|
||||
size = get2byte(pTmp);
|
||||
if( (x = size - nByte)>=0 ){
|
||||
testcase( x==4 );
|
||||
testcase( x==3 );
|
||||
@@ -1607,7 +1669,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
|
||||
return &aData[pc + x];
|
||||
}
|
||||
iAddr = pc;
|
||||
pc = get2byte(&aData[pc]);
|
||||
pTmp = &aData[pc];
|
||||
pc = get2byte(pTmp);
|
||||
if( pc<=iAddr+size ){
|
||||
if( pc ){
|
||||
/* The next slot in the chain is not past the end of the current slot */
|
||||
@@ -1641,6 +1704,7 @@ 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) );
|
||||
@@ -1659,7 +1723,8 @@ 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. */
|
||||
top = get2byte(&data[hdr+5]);
|
||||
pTmp = &data[hdr+5];
|
||||
top = get2byte(pTmp);
|
||||
assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */
|
||||
if( gap>top ){
|
||||
if( top==0 && pPage->pBt->usableSize==65536 ){
|
||||
@@ -1741,6 +1806,7 @@ 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) );
|
||||
@@ -1768,7 +1834,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 );
|
||||
assert( iFreeBlk>iPtr || iFreeBlk==0 || CORRUPT_DB );
|
||||
|
||||
/* At this point:
|
||||
** iFreeBlk: First freeblock after iStart, or zero if none
|
||||
@@ -1803,7 +1869,8 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
|
||||
if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage);
|
||||
data[hdr+7] -= nFrag;
|
||||
}
|
||||
x = get2byte(&data[hdr+5]);
|
||||
pTmp = &data[hdr+5];
|
||||
x = get2byte(pTmp);
|
||||
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
|
||||
@@ -1847,7 +1914,6 @@ 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
|
||||
@@ -1859,6 +1925,7 @@ 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;
|
||||
@@ -1876,12 +1943,17 @@ 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;
|
||||
@@ -2039,7 +2111,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->usableSize;
|
||||
pPage->aDataEnd = pPage->aData + pBt->pageSize;
|
||||
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. */
|
||||
@@ -2074,7 +2146,7 @@ static void zeroPage(MemPage *pPage, int flags){
|
||||
u8 hdr = pPage->hdrOffset;
|
||||
u16 first;
|
||||
|
||||
assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
|
||||
assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno || CORRUPT_DB );
|
||||
assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
|
||||
assert( sqlite3PagerGetData(pPage->pDbPage) == data );
|
||||
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
|
||||
@@ -2090,7 +2162,7 @@ static void zeroPage(MemPage *pPage, int flags){
|
||||
pPage->nFree = (u16)(pBt->usableSize - first);
|
||||
decodeFlags(pPage, flags);
|
||||
pPage->cellOffset = first;
|
||||
pPage->aDataEnd = &data[pBt->usableSize];
|
||||
pPage->aDataEnd = &data[pBt->pageSize];
|
||||
pPage->aCellIdx = &data[first];
|
||||
pPage->aDataOfst = &data[pPage->childPtrSize];
|
||||
pPage->nOverflow = 0;
|
||||
@@ -2216,7 +2288,7 @@ static int getAndInitPage(
|
||||
goto getAndInitPage_error2;
|
||||
}
|
||||
}
|
||||
assert( (*ppPage)->pgno==pgno );
|
||||
assert( (*ppPage)->pgno==pgno || CORRUPT_DB );
|
||||
assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) );
|
||||
|
||||
/* If obtaining a child page for a cursor, we must verify that the page is
|
||||
@@ -2235,7 +2307,9 @@ getAndInitPage_error1:
|
||||
pCur->pPage = pCur->apPage[pCur->iPage];
|
||||
}
|
||||
testcase( pgno==0 );
|
||||
assert( pgno!=0 || rc==SQLITE_CORRUPT );
|
||||
assert( pgno!=0 || rc==SQLITE_CORRUPT
|
||||
|| rc==SQLITE_IOERR_NOMEM
|
||||
|| rc==SQLITE_NOMEM );
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2693,30 +2767,38 @@ static int removeFromSharingList(BtShared *pBt){
|
||||
** MX_CELL_SIZE(pBt) bytes with a 4-byte prefix for a left-child
|
||||
** pointer.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
if( pBt->pTmpSpace ){
|
||||
memset(pBt->pTmpSpace, 0, 8);
|
||||
pBt->pTmpSpace += 4;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3213,9 +3295,13 @@ static int lockBtree(BtShared *pBt){
|
||||
pageSize-usableSize);
|
||||
return rc;
|
||||
}
|
||||
if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto page1_init_failed;
|
||||
if( nPage>nPageFile ){
|
||||
if( sqlite3WritableSchema(pBt->db)==0 ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto page1_init_failed;
|
||||
}else{
|
||||
nPage = nPageFile;
|
||||
}
|
||||
}
|
||||
/* 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
|
||||
@@ -4245,7 +4331,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!=nPage );
|
||||
testcase( pBt->nPage!=(u32)nPage );
|
||||
pBt->nPage = nPage;
|
||||
}
|
||||
|
||||
@@ -4457,10 +4543,6 @@ 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;
|
||||
@@ -4477,19 +4559,25 @@ static int btreeCursor(
|
||||
pCur->pKeyInfo = pKeyInfo;
|
||||
pCur->pBtree = p;
|
||||
pCur->pBt = pBt;
|
||||
pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0;
|
||||
pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY;
|
||||
pCur->curFlags = 0;
|
||||
/* 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;
|
||||
pCur->eState = CURSOR_INVALID;
|
||||
if( wrFlag ){
|
||||
pCur->curFlags |= BTCF_WriteFlag;
|
||||
pCur->curPagerFlags = 0;
|
||||
if( pBt->pTmpSpace==0 ) return allocateTempSpace(pBt);
|
||||
}else{
|
||||
pCur->curPagerFlags = PAGER_GET_READONLY;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
static int btreeCursorWithLock(
|
||||
@@ -5264,7 +5352,7 @@ static int moveToRoot(BtCursor *pCur){
|
||||
while( --pCur->iPage ){
|
||||
releasePageNotNull(pCur->apPage[pCur->iPage]);
|
||||
}
|
||||
pCur->pPage = pCur->apPage[0];
|
||||
pRoot = pCur->pPage = pCur->apPage[0];
|
||||
goto skip_init;
|
||||
}
|
||||
}else if( pCur->pgnoRoot==0 ){
|
||||
@@ -5289,7 +5377,7 @@ static int moveToRoot(BtCursor *pCur){
|
||||
pCur->curIntKey = pCur->pPage->intKey;
|
||||
}
|
||||
pRoot = pCur->pPage;
|
||||
assert( pRoot->pgno==pCur->pgnoRoot );
|
||||
assert( pRoot->pgno==pCur->pgnoRoot || CORRUPT_DB );
|
||||
|
||||
/* 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
|
||||
@@ -5311,7 +5399,6 @@ 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 ){
|
||||
@@ -5552,7 +5639,6 @@ 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);
|
||||
@@ -5612,6 +5698,69 @@ 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.
|
||||
**
|
||||
@@ -5662,6 +5811,40 @@ 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 ){
|
||||
@@ -5671,12 +5854,14 @@ 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->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey );
|
||||
assert( pCur->curIntKey || pIdxKey );
|
||||
assert( pCur->curIntKey==0 );
|
||||
assert( pIdxKey!=0 );
|
||||
for(;;){
|
||||
int lwr, upr, idx, c;
|
||||
Pgno chldPg;
|
||||
@@ -5690,11 +5875,10 @@ int sqlite3BtreeIndexMoveto(
|
||||
** 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==(pIdxKey==0) );
|
||||
assert( pPage->intKey==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);
|
||||
@@ -6386,7 +6570,7 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
|
||||
assert( CORRUPT_DB || iPage>1 );
|
||||
assert( !pMemPage || pMemPage->pgno==iPage );
|
||||
|
||||
if( NEVER(iPage<2) || iPage>pBt->nPage ){
|
||||
if( iPage<2 || iPage>pBt->nPage ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
if( pMemPage ){
|
||||
@@ -6810,16 +6994,24 @@ 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 && idx<pPage->nCell );
|
||||
assert( idx>=0 );
|
||||
assert( 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;
|
||||
testcase( pc==get2byte(&data[hdr+5]) );
|
||||
#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+sz==pPage->pBt->usableSize );
|
||||
if( pc+sz > pPage->pBt->usableSize ){
|
||||
*pRC = SQLITE_CORRUPT_BKPT;
|
||||
@@ -7342,7 +7534,7 @@ static int editPage(
|
||||
|
||||
pData = &aData[get2byteNotZero(&aData[hdr+5])];
|
||||
if( pData<pBegin ) goto editpage_fail;
|
||||
if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail;
|
||||
if( pData>pPg->aDataEnd ) goto editpage_fail;
|
||||
|
||||
/* Add cells to the start of the page */
|
||||
if( iNew<iOld ){
|
||||
@@ -8782,7 +8974,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
|
||||
** MovetoUnpacked() to seek cursor pCur to (pKey,nKey) has already
|
||||
** sqlite3BtreeIndexMoveto() 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
|
||||
@@ -8800,7 +8992,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 MovetoUnpacked() call */
|
||||
int seekResult /* Result of prior IndexMoveto() call */
|
||||
){
|
||||
int rc;
|
||||
int loc = seekResult; /* -1: before desired location +1: after */
|
||||
@@ -8952,7 +9144,7 @@ int sqlite3BtreeInsert(
|
||||
assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
|
||||
assert( pPage->leaf || !pPage->intKey );
|
||||
if( pPage->nFree<0 ){
|
||||
if( NEVER(pCur->eState>CURSOR_INVALID) ){
|
||||
if( pCur->eState>CURSOR_INVALID ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}else{
|
||||
rc = btreeComputeFreeSpace(pPage);
|
||||
@@ -9218,14 +9410,13 @@ 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 */
|
||||
int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
|
||||
u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */
|
||||
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 */
|
||||
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pBt->inTransaction==TRANS_WRITE );
|
||||
@@ -9244,21 +9435,34 @@ 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;
|
||||
if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
|
||||
/* If the bPreserve flag is set to true, then the cursor position must
|
||||
/* If the BTREE_SAVEPOSITION bit is on, 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.
|
||||
**
|
||||
** Or, if the current delete will not cause a rebalance, then the cursor
|
||||
** 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. In this case set bSkipnext to true. */
|
||||
** 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;
|
||||
if( bPreserve ){
|
||||
if( !pPage->leaf
|
||||
|| (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
|
||||
|| (pPage->nFree+pPage->xCellSize(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.
|
||||
@@ -9266,7 +9470,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
rc = saveCursorKey(pCur);
|
||||
if( rc ) return rc;
|
||||
}else{
|
||||
bSkipnext = 1;
|
||||
bPreserve = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9366,8 +9570,8 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
if( bSkipnext ){
|
||||
assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) );
|
||||
if( bPreserve>1 ){
|
||||
assert( (pCur->iPage==iCellDepth || CORRUPT_DB) );
|
||||
assert( pPage==pCur->pPage || CORRUPT_DB );
|
||||
assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
|
||||
pCur->eState = CURSOR_SKIPNEXT;
|
||||
@@ -9577,7 +9781,7 @@ static int clearDatabasePage(
|
||||
rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
|
||||
if( rc ) return rc;
|
||||
if( (pBt->openFlags & BTREE_SINGLE)==0
|
||||
&& sqlite3PagerPageRefcount(pPage->pDbPage)!=1
|
||||
&& sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
|
||||
){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto cleardatabasepage_out;
|
||||
|
||||
+4
-2
@@ -293,7 +293,9 @@ 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 usable 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 *aCellIdx; /* The cell index area */
|
||||
u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */
|
||||
DbPage *pDbPage; /* Pager page handle */
|
||||
@@ -598,7 +600,7 @@ struct BtCursor {
|
||||
/*
|
||||
** The database page the PENDING_BYTE occupies. This page is never used.
|
||||
*/
|
||||
# define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt)
|
||||
#define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/((pBt)->pageSize))+1))
|
||||
|
||||
/*
|
||||
** These macros define the location of the pointer-map entry for a
|
||||
|
||||
+42
-29
@@ -143,11 +143,13 @@ void sqlite3FinishCoding(Parse *pParse){
|
||||
|
||||
assert( pParse->pToplevel==0 );
|
||||
db = pParse->db;
|
||||
assert( db->pParse==pParse );
|
||||
if( pParse->nested ) return;
|
||||
if( db->mallocFailed || pParse->nErr ){
|
||||
if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
|
||||
if( pParse->nErr ){
|
||||
if( db->mallocFailed ) pParse->rc = SQLITE_NOMEM;
|
||||
return;
|
||||
}
|
||||
assert( db->mallocFailed==0 );
|
||||
|
||||
/* Begin by generating some termination code at the end of the
|
||||
** vdbe program
|
||||
@@ -170,9 +172,10 @@ void sqlite3FinishCoding(Parse *pParse){
|
||||
int i;
|
||||
int reg;
|
||||
|
||||
if( pReturning->nRetCol==0 ){
|
||||
if( NEVER(pReturning->nRetCol==0) ){
|
||||
assert( CORRUPT_DB );
|
||||
}else{
|
||||
sqlite3VdbeAddOp0(v, OP_FkCheck);
|
||||
addrRewind =
|
||||
sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
|
||||
VdbeCoverage(v);
|
||||
@@ -265,7 +268,7 @@ void sqlite3FinishCoding(Parse *pParse){
|
||||
|
||||
if( pParse->bReturning ){
|
||||
Returning *pRet = pParse->u1.pReturning;
|
||||
if( pRet->nRetCol==0 ){
|
||||
if( NEVER(pRet->nRetCol==0) ){
|
||||
assert( CORRUPT_DB );
|
||||
}else{
|
||||
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
|
||||
@@ -279,7 +282,9 @@ void sqlite3FinishCoding(Parse *pParse){
|
||||
|
||||
/* Get the VDBE program ready for execution
|
||||
*/
|
||||
if( v && pParse->nErr==0 && !db->mallocFailed ){
|
||||
assert( v!=0 || pParse->nErr );
|
||||
assert( db->mallocFailed==0 || pParse->nErr );
|
||||
if( pParse->nErr==0 ){
|
||||
/* A minimum of one cursor is required if autoincrement is used
|
||||
* See ticket [a696379c1f08866] */
|
||||
assert( pParse->pAinc==0 || pParse->nTab>0 );
|
||||
@@ -306,7 +311,6 @@ void sqlite3FinishCoding(Parse *pParse){
|
||||
void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
|
||||
va_list ap;
|
||||
char *zSql;
|
||||
char *zErrMsg = 0;
|
||||
sqlite3 *db = pParse->db;
|
||||
u32 savedDbFlags = db->mDbFlags;
|
||||
char saveBuf[PARSE_TAIL_SZ];
|
||||
@@ -328,9 +332,10 @@ void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
|
||||
memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
|
||||
memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
|
||||
db->mDbFlags |= DBFLAG_PreferBuiltin;
|
||||
sqlite3RunParser(pParse, zSql, &zErrMsg);
|
||||
sqlite3RunParser(pParse, zSql);
|
||||
sqlite3DbFree(db, pParse->zErrMsg);
|
||||
pParse->zErrMsg = 0;
|
||||
db->mDbFlags = savedDbFlags;
|
||||
sqlite3DbFree(db, zErrMsg);
|
||||
sqlite3DbFree(db, zSql);
|
||||
memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ);
|
||||
pParse->nested--;
|
||||
@@ -742,8 +747,8 @@ void sqlite3ColumnSetColl(
|
||||
Column *pCol,
|
||||
const char *zColl
|
||||
){
|
||||
int nColl;
|
||||
int n;
|
||||
i64 nColl;
|
||||
i64 n;
|
||||
char *zNew;
|
||||
assert( zColl!=0 );
|
||||
n = sqlite3Strlen30(pCol->zCnName) + 1;
|
||||
@@ -1290,7 +1295,8 @@ void sqlite3StartTable(
|
||||
pTable = sqlite3FindTable(db, zName, zDb);
|
||||
if( pTable ){
|
||||
if( !noErr ){
|
||||
sqlite3ErrorMsg(pParse, "table %T already exists", pName);
|
||||
sqlite3ErrorMsg(pParse, "%s %T already exists",
|
||||
(IsView(pTable)? "view" : "table"), pName);
|
||||
}else{
|
||||
assert( !db->init.busy || CORRUPT_DB );
|
||||
sqlite3CodeVerifySchema(pParse, iDb);
|
||||
@@ -1548,7 +1554,7 @@ void sqlite3AddColumn(Parse *pParse, Token sName, Token sType){
|
||||
}
|
||||
}
|
||||
|
||||
z = sqlite3DbMallocRaw(db, sName.n + 1 + sType.n + (sType.n>0) );
|
||||
z = sqlite3DbMallocRaw(db, (i64)sName.n + 1 + (i64)sType.n + (sType.n>0) );
|
||||
if( z==0 ) return;
|
||||
if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName);
|
||||
memcpy(z, sName.z, sName.n);
|
||||
@@ -1562,7 +1568,7 @@ void sqlite3AddColumn(Parse *pParse, Token sName, Token sType){
|
||||
return;
|
||||
}
|
||||
}
|
||||
aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+1)*sizeof(p->aCol[0]));
|
||||
aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0]));
|
||||
if( aNew==0 ){
|
||||
sqlite3DbFree(db, z);
|
||||
return;
|
||||
@@ -2385,10 +2391,11 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
pTab->iPKey = -1;
|
||||
sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
|
||||
SQLITE_IDXTYPE_PRIMARYKEY);
|
||||
if( db->mallocFailed || pParse->nErr ){
|
||||
if( pParse->nErr ){
|
||||
pTab->tabFlags &= ~TF_WithoutRowid;
|
||||
return;
|
||||
}
|
||||
assert( db->mallocFailed==0 );
|
||||
pPk = sqlite3PrimaryKeyIndex(pTab);
|
||||
assert( pPk->nKeyCol==1 );
|
||||
}else{
|
||||
@@ -2819,6 +2826,11 @@ void sqlite3EndTable(
|
||||
int addrInsLoop; /* Top of the loop for inserting rows */
|
||||
Table *pSelTab; /* A table that describes the SELECT results */
|
||||
|
||||
if( IN_SPECIAL_PARSE ){
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
pParse->nErr++;
|
||||
return;
|
||||
}
|
||||
regYield = ++pParse->nMem;
|
||||
regRec = ++pParse->nMem;
|
||||
regRowid = ++pParse->nMem;
|
||||
@@ -3129,10 +3141,10 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
||||
*/
|
||||
sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
|
||||
&pTable->nCol, &pTable->aCol);
|
||||
if( db->mallocFailed==0
|
||||
&& pParse->nErr==0
|
||||
if( pParse->nErr==0
|
||||
&& pTable->nCol==pSel->pEList->nExpr
|
||||
){
|
||||
assert( db->mallocFailed==0 );
|
||||
sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
|
||||
SQLITE_AFF_NONE);
|
||||
}
|
||||
@@ -3575,7 +3587,7 @@ void sqlite3CreateForeignKey(
|
||||
FKey *pFKey = 0;
|
||||
FKey *pNextTo;
|
||||
Table *p = pParse->pNewTable;
|
||||
int nByte;
|
||||
i64 nByte;
|
||||
int i;
|
||||
int nCol;
|
||||
char *z;
|
||||
@@ -3751,7 +3763,7 @@ static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
|
||||
tnum = pIndex->tnum;
|
||||
}
|
||||
pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
|
||||
assert( pKey!=0 || db->mallocFailed || pParse->nErr );
|
||||
assert( pKey!=0 || pParse->nErr );
|
||||
|
||||
/* Open the sorter cursor if we are to use one. */
|
||||
iSorter = pParse->nTab++;
|
||||
@@ -3915,9 +3927,11 @@ void sqlite3CreateIndex(
|
||||
char *zExtra = 0; /* Extra space after the Index object */
|
||||
Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
|
||||
|
||||
if( db->mallocFailed || pParse->nErr>0 ){
|
||||
assert( db->pParse==pParse );
|
||||
if( pParse->nErr ){
|
||||
goto exit_create_index;
|
||||
}
|
||||
assert( db->mallocFailed==0 );
|
||||
if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
|
||||
goto exit_create_index;
|
||||
}
|
||||
@@ -3981,7 +3995,6 @@ void sqlite3CreateIndex(
|
||||
pDb = &db->aDb[iDb];
|
||||
|
||||
assert( pTab!=0 );
|
||||
assert( pParse->nErr==0 );
|
||||
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
|
||||
&& db->init.busy==0
|
||||
&& pTblName!=0
|
||||
@@ -4405,13 +4418,13 @@ void sqlite3CreateIndex(
|
||||
/* Add an entry in sqlite_schema for this index
|
||||
*/
|
||||
sqlite3NestedParse(pParse,
|
||||
"INSERT INTO %Q." LEGACY_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);",
|
||||
db->aDb[iDb].zDbSName,
|
||||
pIndex->zName,
|
||||
pTab->zName,
|
||||
iMem,
|
||||
zStmt
|
||||
);
|
||||
"INSERT INTO %Q." LEGACY_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);",
|
||||
db->aDb[iDb].zDbSName,
|
||||
pIndex->zName,
|
||||
pTab->zName,
|
||||
iMem,
|
||||
zStmt
|
||||
);
|
||||
sqlite3DbFree(db, zStmt);
|
||||
|
||||
/* Fill the index with data and reparse the schema. Code an OP_Expire
|
||||
@@ -4545,10 +4558,10 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName, int ifExists){
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb;
|
||||
|
||||
assert( pParse->nErr==0 ); /* Never called with prior errors */
|
||||
if( db->mallocFailed ){
|
||||
goto exit_drop_index;
|
||||
}
|
||||
assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */
|
||||
assert( pName->nSrc==1 );
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
|
||||
goto exit_drop_index;
|
||||
@@ -4959,7 +4972,7 @@ SrcList *sqlite3SrcListAppendFromTerm(
|
||||
pItem->pUsing = pUsing;
|
||||
return p;
|
||||
|
||||
append_from_error:
|
||||
append_from_error:
|
||||
assert( p==0 );
|
||||
sqlite3ExprDelete(db, pOn);
|
||||
sqlite3IdListDelete(db, pUsing);
|
||||
|
||||
@@ -358,7 +358,6 @@ void sqlite3InsertBuiltinFuncs(
|
||||
const char *zName = aDef[i].zName;
|
||||
int nName = sqlite3Strlen30(zName);
|
||||
int h = SQLITE_FUNC_HASH(zName[0], nName);
|
||||
assert( zName[0]>='a' && zName[0]<='z' );
|
||||
assert( aDef[i].funcFlags & SQLITE_FUNC_BUILTIN );
|
||||
pOther = sqlite3FunctionSearch(h, zName);
|
||||
if( pOther ){
|
||||
|
||||
+13
-10
@@ -1,3 +1,11 @@
|
||||
/* 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
|
||||
**
|
||||
@@ -46,9 +54,6 @@
|
||||
*/
|
||||
static const char * const sqlite3azCompileOpt[] = {
|
||||
|
||||
/*
|
||||
** BEGIN CODE GENERATED BY tool/mkctime.tcl
|
||||
*/
|
||||
#ifdef SQLITE_32BIT_ROWID
|
||||
"32BIT_ROWID",
|
||||
#endif
|
||||
@@ -257,9 +262,6 @@ 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
|
||||
@@ -583,6 +585,9 @@ 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
|
||||
@@ -771,10 +776,8 @@ 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]);
|
||||
|
||||
+225
-87
@@ -503,8 +503,10 @@ 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 true then this
|
||||
** routine will always fail.
|
||||
** 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.
|
||||
**
|
||||
** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
|
||||
** library function localtime_r() is used to assist in the calculation of
|
||||
@@ -520,14 +522,30 @@ static int osLocaltime(time_t *t, struct tm *pTm){
|
||||
sqlite3_mutex_enter(mutex);
|
||||
pX = localtime(t);
|
||||
#ifndef SQLITE_UNTESTABLE
|
||||
if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
|
||||
if( sqlite3GlobalConfig.bLocaltimeFault ){
|
||||
if( sqlite3GlobalConfig.xAltLocaltime!=0
|
||||
&& 0==sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm)
|
||||
){
|
||||
pX = pTm;
|
||||
}else{
|
||||
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 ) return 1;
|
||||
if( sqlite3GlobalConfig.bLocaltimeFault ){
|
||||
if( sqlite3GlobalConfig.xAltLocaltime!=0 ){
|
||||
return sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm);
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if HAVE_LOCALTIME_R
|
||||
rc = localtime_r(t, pTm)==0;
|
||||
@@ -542,67 +560,56 @@ static int osLocaltime(time_t *t, struct tm *pTm){
|
||||
|
||||
#ifndef SQLITE_OMIT_LOCALTIME
|
||||
/*
|
||||
** 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.
|
||||
** Assuming the input DateTime is UTC, move it to its localtime equivalent.
|
||||
*/
|
||||
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 */
|
||||
static int toLocaltime(
|
||||
DateTime *p, /* Date at which to calculate offset */
|
||||
sqlite3_context *pCtx /* Write error here if one occurs */
|
||||
){
|
||||
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));
|
||||
|
||||
x = *p;
|
||||
computeYMD_HMS(&x);
|
||||
if( x.Y<1971 || x.Y>=2038 ){
|
||||
computeJD(p);
|
||||
if( p->iJD<2108667600*(i64)100000 /* 1970-01-01 */
|
||||
|| p->iJD>2130141456*(i64)100000 /* 2038-01-18 */
|
||||
){
|
||||
/* 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.
|
||||
*/
|
||||
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;
|
||||
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.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);
|
||||
*pRc = SQLITE_ERROR;
|
||||
return 0;
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
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;
|
||||
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;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_LOCALTIME */
|
||||
|
||||
@@ -615,18 +622,17 @@ static sqlite3_int64 localtimeOffset(
|
||||
** of several units of time.
|
||||
*/
|
||||
static const struct {
|
||||
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 */
|
||||
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 */
|
||||
} aXformType[] = {
|
||||
{ 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 },
|
||||
{ 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 },
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -657,11 +663,55 @@ 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 */
|
||||
DateTime *p, /* The date/time value to be modified */
|
||||
int idx /* Parameter index of the modifier */
|
||||
){
|
||||
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
|
||||
@@ -670,9 +720,7 @@ static int parseModifier(
|
||||
** show local time.
|
||||
*/
|
||||
if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){
|
||||
computeJD(p);
|
||||
p->iJD += localtimeOffset(p, pCtx, &rc);
|
||||
clearYMD_HMS_TZ(p);
|
||||
rc = toLocaltime(p, pCtx);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -685,6 +733,7 @@ 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);
|
||||
@@ -697,18 +746,31 @@ static int parseModifier(
|
||||
#ifndef SQLITE_OMIT_LOCALTIME
|
||||
else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){
|
||||
if( p->tzSet==0 ){
|
||||
sqlite3_int64 c1;
|
||||
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 */
|
||||
|
||||
computeJD(p);
|
||||
c1 = localtimeOffset(p, pCtx, &rc);
|
||||
if( rc==SQLITE_OK ){
|
||||
p->iJD -= c1;
|
||||
clearYMD_HMS_TZ(p);
|
||||
p->iJD += c1 - localtimeOffset(p, pCtx, &rc);
|
||||
}
|
||||
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;
|
||||
p->tzSet = 1;
|
||||
}else{
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
@@ -824,9 +886,10 @@ static int parseModifier(
|
||||
&& sqlite3_strnicmp(aXformType[i].zName, z, n)==0
|
||||
&& r>-aXformType[i].rLimit && r<aXformType[i].rLimit
|
||||
){
|
||||
switch( aXformType[i].eType ){
|
||||
case 1: { /* Special processing to add months */
|
||||
switch( i ){
|
||||
case 4: { /* 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;
|
||||
@@ -836,8 +899,9 @@ static int parseModifier(
|
||||
r -= (int)r;
|
||||
break;
|
||||
}
|
||||
case 2: { /* Special processing to add years */
|
||||
case 5: { /* 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;
|
||||
@@ -846,7 +910,7 @@ static int parseModifier(
|
||||
}
|
||||
}
|
||||
computeJD(p);
|
||||
p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder);
|
||||
p->iJD += (sqlite3_int64)(r*1000.0*aXformType[i].rXform + rRounder);
|
||||
rc = 0;
|
||||
break;
|
||||
}
|
||||
@@ -896,7 +960,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) ) return 1;
|
||||
if( z==0 || parseModifier(context, (char*)z, n, p, i) ) return 1;
|
||||
}
|
||||
computeJD(p);
|
||||
if( p->isError || !validJulianDay(p->iJD) ) return 1;
|
||||
@@ -926,6 +990,24 @@ 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, ...)
|
||||
**
|
||||
@@ -938,11 +1020,38 @@ static void datetimeFunc(
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(context, argc, argv, &x)==0 ){
|
||||
char zBuf[100];
|
||||
int Y, s;
|
||||
char zBuf[24];
|
||||
computeYMD_HMS(&x);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -958,10 +1067,20 @@ static void timeFunc(
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(context, argc, argv, &x)==0 ){
|
||||
char zBuf[100];
|
||||
int s;
|
||||
char zBuf[16];
|
||||
computeHMS(&x);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -977,10 +1096,28 @@ static void dateFunc(
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(context, argc, argv, &x)==0 ){
|
||||
char zBuf[100];
|
||||
int Y;
|
||||
char zBuf[16];
|
||||
computeYMD(&x);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1202,6 +1339,7 @@ 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 ),
|
||||
|
||||
+2
-1
@@ -156,6 +156,7 @@ static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
){
|
||||
pIdxInfo->orderByConsumed = 1;
|
||||
}
|
||||
sqlite3VtabWriteAll(pIdxInfo);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -333,7 +334,7 @@ static int dbpageUpdate(
|
||||
goto update_fail;
|
||||
}
|
||||
pBt = pTab->db->aDb[iDb].pBt;
|
||||
if( pgno<1 || pBt==0 || pgno>(int)sqlite3BtreeLastPage(pBt) ){
|
||||
if( pgno<1 || pBt==0 || pgno>sqlite3BtreeLastPage(pBt) ){
|
||||
zErr = "bad page number";
|
||||
goto update_fail;
|
||||
}
|
||||
|
||||
+15
-5
@@ -44,6 +44,16 @@ 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:
|
||||
@@ -283,9 +293,11 @@ void sqlite3DeleteFrom(
|
||||
|
||||
memset(&sContext, 0, sizeof(sContext));
|
||||
db = pParse->db;
|
||||
if( pParse->nErr || db->mallocFailed ){
|
||||
assert( db->pParse==pParse );
|
||||
if( pParse->nErr ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
assert( db->mallocFailed==0 );
|
||||
assert( pTabList->nSrc==1 );
|
||||
|
||||
|
||||
@@ -466,7 +478,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, wcf, iTabCur+1);
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,0,wcf,iTabCur+1);
|
||||
if( pWInfo==0 ) goto delete_from_cleanup;
|
||||
eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
|
||||
assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
|
||||
@@ -619,9 +631,7 @@ void sqlite3DeleteFrom(
|
||||
** invoke the callback function.
|
||||
*/
|
||||
if( memCnt ){
|
||||
sqlite3VdbeAddOp2(v, OP_ChngCntRow, memCnt, 1);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC);
|
||||
sqlite3CodeChangeCount(v, memCnt, "rows deleted");
|
||||
}
|
||||
|
||||
delete_from_cleanup:
|
||||
|
||||
+38
-31
@@ -769,9 +769,8 @@ static void heightOfSelect(const Select *pSelect, int *pnHeight){
|
||||
** if appropriate.
|
||||
*/
|
||||
static void exprSetHeight(Expr *p){
|
||||
int nHeight = 0;
|
||||
heightOfExpr(p->pLeft, &nHeight);
|
||||
heightOfExpr(p->pRight, &nHeight);
|
||||
int nHeight = p->pLeft ? p->pLeft->nHeight : 0;
|
||||
if( p->pRight && p->pRight->nHeight>nHeight ) nHeight = p->pRight->nHeight;
|
||||
if( ExprUseXSelect(p) ){
|
||||
heightOfSelect(p->x.pSelect, &nHeight);
|
||||
}else if( p->x.pList ){
|
||||
@@ -1070,6 +1069,7 @@ Expr *sqlite3ExprFunction(
|
||||
sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
|
||||
return 0;
|
||||
}
|
||||
pNew->w.iOfst = (int)(pToken->z - pParse->zTail);
|
||||
if( pList
|
||||
&& pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG]
|
||||
&& !pParse->nested
|
||||
@@ -1113,7 +1113,7 @@ void sqlite3ExprFunctionUsable(
|
||||
** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning
|
||||
** that the schema is possibly tainted).
|
||||
*/
|
||||
sqlite3ErrorMsg(pParse, "unsafe use of %s()", pDef->zName);
|
||||
sqlite3ErrorMsg(pParse, "unsafe use of %#T()", pExpr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1169,6 +1169,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
|
||||
if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
|
||||
sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
|
||||
db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
|
||||
sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
|
||||
return;
|
||||
}
|
||||
x = (ynVar)i;
|
||||
@@ -1196,6 +1197,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
|
||||
pExpr->iColumn = x;
|
||||
if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
|
||||
sqlite3ErrorMsg(pParse, "too many SQL variables");
|
||||
sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2457,7 +2459,7 @@ int sqlite3ExprCanBeNull(const Expr *p){
|
||||
return ExprHasProperty(p, EP_CanBeNull) ||
|
||||
p->y.pTab==0 || /* Reference to column of index on expression */
|
||||
(p->iColumn>=0
|
||||
&& ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */
|
||||
&& p->y.pTab->aCol!=0 /* Possible due to prior error */
|
||||
&& p->y.pTab->aCol[p->iColumn].notNull==0);
|
||||
default:
|
||||
return 1;
|
||||
@@ -3038,8 +3040,7 @@ void sqlite3CodeRhsOfIN(
|
||||
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
|
||||
pExpr->y.sub.regReturn = ++pParse->nMem;
|
||||
pExpr->y.sub.iAddr =
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
|
||||
VdbeComment((v, "return address"));
|
||||
sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
|
||||
|
||||
addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
|
||||
}
|
||||
@@ -3141,6 +3142,7 @@ void sqlite3CodeRhsOfIN(
|
||||
** expression we need to rerun this code each time.
|
||||
*/
|
||||
if( addrOnce && !sqlite3ExprIsConstant(pE2) ){
|
||||
sqlite3VdbeChangeToNoop(v, addrOnce-1);
|
||||
sqlite3VdbeChangeToNoop(v, addrOnce);
|
||||
ExprClearProperty(pExpr, EP_Subrtn);
|
||||
addrOnce = 0;
|
||||
@@ -3161,7 +3163,10 @@ void sqlite3CodeRhsOfIN(
|
||||
sqlite3VdbeJumpHere(v, addrOnce);
|
||||
/* Subroutine return */
|
||||
assert( ExprUseYSub(pExpr) );
|
||||
sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
|
||||
assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
|
||||
|| pParse->nErr );
|
||||
sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn, 0,
|
||||
pExpr->y.sub.iAddr-1);
|
||||
sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
|
||||
sqlite3ClearTempRegCache(pParse);
|
||||
}
|
||||
@@ -3216,9 +3221,7 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
ExprSetProperty(pExpr, EP_Subrtn);
|
||||
pExpr->y.sub.regReturn = ++pParse->nMem;
|
||||
pExpr->y.sub.iAddr =
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
|
||||
VdbeComment((v, "return address"));
|
||||
|
||||
sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
|
||||
|
||||
/* The evaluation of the EXISTS/SELECT must be repeated every time it
|
||||
** is encountered if any of the following is true:
|
||||
@@ -3279,10 +3282,8 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
}
|
||||
pSel->iLimit = 0;
|
||||
if( sqlite3Select(pParse, pSel, &dest) ){
|
||||
if( pParse->nErr ){
|
||||
pExpr->op2 = pExpr->op;
|
||||
pExpr->op = TK_ERROR;
|
||||
}
|
||||
pExpr->op2 = pExpr->op;
|
||||
pExpr->op = TK_ERROR;
|
||||
return 0;
|
||||
}
|
||||
pExpr->iTable = rReg = dest.iSDParm;
|
||||
@@ -3293,7 +3294,10 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
|
||||
/* Subroutine return */
|
||||
assert( ExprUseYSub(pExpr) );
|
||||
sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
|
||||
assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
|
||||
|| pParse->nErr );
|
||||
sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn, 0,
|
||||
pExpr->y.sub.iAddr-1);
|
||||
sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
|
||||
sqlite3ClearTempRegCache(pParse);
|
||||
return rReg;
|
||||
@@ -3499,10 +3503,9 @@ static void sqlite3ExprCodeIN(
|
||||
}else{
|
||||
destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
|
||||
}
|
||||
if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
|
||||
for(i=0; i<nVector; i++){
|
||||
Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
|
||||
if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
|
||||
if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error;
|
||||
if( sqlite3ExprCanBeNull(p) ){
|
||||
sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
|
||||
VdbeCoverage(v);
|
||||
@@ -3640,11 +3643,12 @@ static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){
|
||||
c = sqlite3DecOrHexToI64(z, &value);
|
||||
if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){
|
||||
#ifdef SQLITE_OMIT_FLOATING_POINT
|
||||
sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
|
||||
sqlite3ErrorMsg(pParse, "oversized integer: %s%#T", negFlag?"-":"",pExpr);
|
||||
#else
|
||||
#ifndef SQLITE_OMIT_HEX_INTEGER
|
||||
if( sqlite3_strnicmp(z,"0x",2)==0 ){
|
||||
sqlite3ErrorMsg(pParse, "hex literal too big: %s%s", negFlag?"-":"",z);
|
||||
sqlite3ErrorMsg(pParse, "hex literal too big: %s%#T",
|
||||
negFlag?"-":"",pExpr);
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
@@ -4320,7 +4324,7 @@ expr_code_doover:
|
||||
|| NEVER(pExpr->iAgg>=pInfo->nFunc)
|
||||
){
|
||||
assert( !ExprHasProperty(pExpr, EP_IntValue) );
|
||||
sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken);
|
||||
sqlite3ErrorMsg(pParse, "misuse of aggregate: %#T()", pExpr);
|
||||
}else{
|
||||
return pInfo->aFunc[pExpr->iAgg].iMem;
|
||||
}
|
||||
@@ -4361,7 +4365,7 @@ expr_code_doover:
|
||||
}
|
||||
#endif
|
||||
if( pDef==0 || pDef->xFinalize!=0 ){
|
||||
sqlite3ErrorMsg(pParse, "unknown function: %s()", zId);
|
||||
sqlite3ErrorMsg(pParse, "unknown function: %#T()", pExpr);
|
||||
break;
|
||||
}
|
||||
if( pDef->funcFlags & SQLITE_FUNC_INLINE ){
|
||||
@@ -5468,12 +5472,9 @@ int sqlite3ExprCompare(
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
if( pA->op!=TK_COLUMN
|
||||
&& pA->op!=TK_AGG_COLUMN
|
||||
&& ALWAYS(!ExprHasProperty(pA, EP_IntValue))
|
||||
&& pA->u.zToken
|
||||
){
|
||||
assert( !ExprHasProperty(pB, EP_IntValue) );
|
||||
assert( !ExprHasProperty(pA, EP_IntValue) );
|
||||
assert( !ExprHasProperty(pB, EP_IntValue) );
|
||||
if( pA->u.zToken ){
|
||||
if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){
|
||||
if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
@@ -5491,7 +5492,12 @@ int sqlite3ExprCompare(
|
||||
return 0;
|
||||
}else if( pA->op==TK_COLLATE ){
|
||||
if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
|
||||
}else if( ALWAYS(pB->u.zToken!=0) && strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
|
||||
}else
|
||||
if( pB->u.zToken!=0
|
||||
&& pA->op!=TK_COLUMN
|
||||
&& pA->op!=TK_AGG_COLUMN
|
||||
&& strcmp(pA->u.zToken,pB->u.zToken)!=0
|
||||
){
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -5885,7 +5891,7 @@ int sqlite3ExprCoveredByIndex(
|
||||
struct RefSrcList {
|
||||
sqlite3 *db; /* Database connection used for sqlite3DbRealloc() */
|
||||
SrcList *pRef; /* Looking for references to these tables */
|
||||
int nExclude; /* Number of tables to exclude from the search */
|
||||
i64 nExclude; /* Number of tables to exclude from the search */
|
||||
int *aiExclude; /* Cursor IDs for tables to exclude from the search */
|
||||
};
|
||||
|
||||
@@ -5900,7 +5906,8 @@ struct RefSrcList {
|
||||
static int selectRefEnter(Walker *pWalker, Select *pSelect){
|
||||
struct RefSrcList *p = pWalker->u.pRefSrcList;
|
||||
SrcList *pSrc = pSelect->pSrc;
|
||||
int i, j, *piNew;
|
||||
i64 i, j;
|
||||
int *piNew;
|
||||
if( pSrc->nSrc==0 ) return WRC_Continue;
|
||||
j = p->nExclude;
|
||||
p->nExclude += pSrc->nSrc;
|
||||
|
||||
+20
-1
@@ -651,7 +651,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);
|
||||
pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0, 0);
|
||||
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
|
||||
if( pWInfo ){
|
||||
sqlite3WhereEnd(pWInfo);
|
||||
@@ -702,6 +702,25 @@ 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
|
||||
|
||||
+74
-50
@@ -97,6 +97,18 @@ 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
|
||||
@@ -258,7 +270,7 @@ endInstrOOM:
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the printf() function.
|
||||
** Implementation of the printf() (a.k.a. format()) SQL function.
|
||||
*/
|
||||
static void printfFunc(
|
||||
sqlite3_context *context,
|
||||
@@ -1027,39 +1039,42 @@ static const char hexdigits[] = {
|
||||
};
|
||||
|
||||
/*
|
||||
** 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.
|
||||
** Append to pStr text that is the SQL literal representation of the
|
||||
** value contained in pValue.
|
||||
*/
|
||||
static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
switch( sqlite3_value_type(argv[0]) ){
|
||||
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) ){
|
||||
case SQLITE_FLOAT: {
|
||||
double r1, r2;
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
break;
|
||||
}
|
||||
case SQLITE_INTEGER: {
|
||||
sqlite3_result_value(context, argv[0]);
|
||||
sqlite3_str_appendf(pStr, "%lld", sqlite3_value_int64(pValue));
|
||||
break;
|
||||
}
|
||||
case SQLITE_BLOB: {
|
||||
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 ){
|
||||
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;
|
||||
int i;
|
||||
for(i=0; i<nBlob; i++){
|
||||
zText[(i*2)+2] = hexdigits[(zBlob[i]>>4)&0x0F];
|
||||
@@ -1069,42 +1084,48 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
zText[(nBlob*2)+3] = '\0';
|
||||
zText[0] = 'X';
|
||||
zText[1] = '\'';
|
||||
sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_free(zText);
|
||||
pStr->nChar = nBlob*2 + 3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SQLITE_TEXT: {
|
||||
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);
|
||||
}
|
||||
const unsigned char *zArg = sqlite3_value_text(pValue);
|
||||
sqlite3_str_appendf(pStr, "%Q", zArg);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
|
||||
sqlite3_result_text(context, "NULL", 4, SQLITE_STATIC);
|
||||
assert( sqlite3_value_type(pValue)==SQLITE_NULL );
|
||||
sqlite3_str_append(pStr, "NULL", 4);
|
||||
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.
|
||||
@@ -2220,8 +2241,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
|
||||
FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET|
|
||||
SQLITE_FUNC_TYPEOF),
|
||||
{1, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_OFFSET|SQLITE_FUNC_TYPEOF,
|
||||
0, 0, noopFunc, 0, 0, 0, "sqlite_offset", {0} },
|
||||
#endif
|
||||
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
|
||||
FUNCTION(ltrim, 2, 1, 0, trimFunc ),
|
||||
@@ -2238,9 +2259,11 @@ 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 ),
|
||||
@@ -2339,6 +2362,7 @@ void sqlite3RegisterBuiltinFunctions(void){
|
||||
#endif
|
||||
sqlite3WindowFunctions();
|
||||
sqlite3RegisterDateTimeFunctions();
|
||||
sqlite3RegisterJsonFunctions();
|
||||
sqlite3InsertBuiltinFuncs(aBuiltinFunc, ArraySize(aBuiltinFunc));
|
||||
|
||||
#if 0 /* Enable to print out how the built-in functions are hashed */
|
||||
|
||||
@@ -286,9 +286,13 @@ 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
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
+17
-15
@@ -43,7 +43,7 @@ void sqlite3OpenTable(
|
||||
}else{
|
||||
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
|
||||
assert( pPk!=0 );
|
||||
assert( pPk->tnum==pTab->tnum );
|
||||
assert( pPk->tnum==pTab->tnum || CORRUPT_DB );
|
||||
sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb);
|
||||
sqlite3VdbeSetP4KeyInfo(pParse, pPk);
|
||||
VdbeComment((v, "%s", pTab->zName));
|
||||
@@ -715,9 +715,11 @@ void sqlite3Insert(
|
||||
#endif
|
||||
|
||||
db = pParse->db;
|
||||
if( pParse->nErr || db->mallocFailed ){
|
||||
assert( db->pParse==pParse );
|
||||
if( pParse->nErr ){
|
||||
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
|
||||
@@ -793,7 +795,11 @@ void sqlite3Insert(
|
||||
**
|
||||
** This is the 2nd template.
|
||||
*/
|
||||
if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){
|
||||
if( pColumn==0
|
||||
&& pSelect!=0
|
||||
&& pTrigger==0
|
||||
&& xferOptimization(pParse, pTab, pSelect, onError, iDb)
|
||||
){
|
||||
assert( !pTrigger );
|
||||
assert( pList==0 );
|
||||
goto insert_end;
|
||||
@@ -893,7 +899,9 @@ void sqlite3Insert(
|
||||
dest.nSdst = pTab->nCol;
|
||||
rc = sqlite3Select(pParse, pSelect, &dest);
|
||||
regFromSelect = dest.iSdst;
|
||||
if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
|
||||
assert( db->pParse==pParse );
|
||||
if( rc || pParse->nErr ) goto insert_cleanup;
|
||||
assert( db->mallocFailed==0 );
|
||||
sqlite3VdbeEndCoroutine(v, regYield);
|
||||
sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
|
||||
assert( pSelect->pEList );
|
||||
@@ -1382,9 +1390,7 @@ insert_end:
|
||||
** invoke the callback function.
|
||||
*/
|
||||
if( regRowCount ){
|
||||
sqlite3VdbeAddOp2(v, OP_ChngCntRow, regRowCount, 1);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", SQLITE_STATIC);
|
||||
sqlite3CodeChangeCount(v, regRowCount, "rows inserted");
|
||||
}
|
||||
|
||||
insert_cleanup:
|
||||
@@ -2009,6 +2015,7 @@ 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"));
|
||||
@@ -2275,7 +2282,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
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.
|
||||
** different from the old. See TH3 withoutrowid04.test.
|
||||
**
|
||||
** For a UNIQUE index, only conflict if the PRIMARY KEY values
|
||||
** of the matched index row are different from the original PRIMARY
|
||||
@@ -2417,6 +2424,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
if( ipkTop ){
|
||||
sqlite3VdbeGoto(v, ipkTop);
|
||||
VdbeComment((v, "Do IPK REPLACE"));
|
||||
assert( ipkBottom>0 );
|
||||
sqlite3VdbeJumpHere(v, ipkBottom);
|
||||
}
|
||||
|
||||
@@ -2547,7 +2555,6 @@ 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 ){
|
||||
@@ -2763,18 +2770,13 @@ static int xferOptimization(
|
||||
int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
|
||||
int regData, regRowid; /* Registers holding data and rowid */
|
||||
|
||||
if( pSelect==0 ){
|
||||
return 0; /* Must be of the form INSERT INTO ... SELECT ... */
|
||||
}
|
||||
assert( pSelect!=0 );
|
||||
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 */
|
||||
|
||||
+182
-225
@@ -10,10 +10,10 @@
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This SQLite extension implements JSON functions. The interface is
|
||||
** modeled after MySQL JSON functions:
|
||||
** This SQLite JSON functions.
|
||||
**
|
||||
** https://dev.mysql.com/doc/refman/5.7/en/json.html
|
||||
** 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.
|
||||
**
|
||||
** 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,48 +21,8 @@
|
||||
** This implementation parses JSON text at 250 MB/s, so it is hard to see
|
||||
** how JSONB might improve on that.)
|
||||
*/
|
||||
#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
|
||||
#ifndef SQLITE_OMIT_JSON
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Growing our own isspace() routine this way is twice as fast as
|
||||
@@ -87,44 +47,14 @@ 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 safe_isspace(x) (jsonIsSpace[(unsigned char)x])
|
||||
#define fast_isspace(x) (jsonIsSpace[(unsigned char)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;
|
||||
# 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 testcase(X)
|
||||
#endif
|
||||
#if !defined(SQLITE_DEBUG) && !defined(SQLITE_COVERAGE_TEST)
|
||||
# define VVA(X)
|
||||
#else
|
||||
# define VVA(X) X
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Some of the testcase() macros in this file are problematic for gcov
|
||||
** in that they generate false-miss errors randomly. This is a gcov problem,
|
||||
** not a problem in this case. But to work around it, we disable the
|
||||
** problematic test cases for production builds.
|
||||
*/
|
||||
#define json_testcase(X)
|
||||
|
||||
/* Objects */
|
||||
typedef struct JsonString JsonString;
|
||||
typedef struct JsonNode JsonNode;
|
||||
@@ -582,10 +512,10 @@ static u8 jsonHexToInt(int h){
|
||||
*/
|
||||
static u32 jsonHexToInt4(const char *z){
|
||||
u32 v;
|
||||
assert( safe_isxdigit(z[0]) );
|
||||
assert( safe_isxdigit(z[1]) );
|
||||
assert( safe_isxdigit(z[2]) );
|
||||
assert( safe_isxdigit(z[3]) );
|
||||
assert( sqlite3Isxdigit(z[0]) );
|
||||
assert( sqlite3Isxdigit(z[1]) );
|
||||
assert( sqlite3Isxdigit(z[2]) );
|
||||
assert( sqlite3Isxdigit(z[3]) );
|
||||
v = (jsonHexToInt(z[0])<<12)
|
||||
+ (jsonHexToInt(z[1])<<8)
|
||||
+ (jsonHexToInt(z[2])<<4)
|
||||
@@ -820,7 +750,7 @@ static int jsonParseAddNode(
|
||||
*/
|
||||
static int jsonIs4Hex(const char *z){
|
||||
int i;
|
||||
for(i=0; i<4; i++) if( !safe_isxdigit(z[i]) ) return 0;
|
||||
for(i=0; i<4; i++) if( !sqlite3Isxdigit(z[i]) ) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -839,13 +769,13 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
int x;
|
||||
JsonNode *pNode;
|
||||
const char *z = pParse->zJson;
|
||||
while( safe_isspace(z[i]) ){ i++; }
|
||||
while( fast_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( safe_isspace(z[j]) ){ j++; }
|
||||
while( fast_isspace(z[j]) ){ j++; }
|
||||
if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
|
||||
x = jsonParseValue(pParse, j);
|
||||
if( x<0 ){
|
||||
@@ -858,14 +788,14 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
if( pNode->eType!=JSON_STRING ) return -1;
|
||||
pNode->jnFlags |= JNODE_LABEL;
|
||||
j = x;
|
||||
while( safe_isspace(z[j]) ){ j++; }
|
||||
while( fast_isspace(z[j]) ){ j++; }
|
||||
if( z[j]!=':' ) return -1;
|
||||
j++;
|
||||
x = jsonParseValue(pParse, j);
|
||||
pParse->iDepth--;
|
||||
if( x<0 ) return -1;
|
||||
j = x;
|
||||
while( safe_isspace(z[j]) ){ j++; }
|
||||
while( fast_isspace(z[j]) ){ j++; }
|
||||
c = z[j];
|
||||
if( c==',' ) continue;
|
||||
if( c!='}' ) return -1;
|
||||
@@ -879,7 +809,7 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
if( iThis<0 ) return -1;
|
||||
memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u));
|
||||
for(j=i+1;;j++){
|
||||
while( safe_isspace(z[j]) ){ j++; }
|
||||
while( fast_isspace(z[j]) ){ j++; }
|
||||
if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
|
||||
x = jsonParseValue(pParse, j);
|
||||
pParse->iDepth--;
|
||||
@@ -888,7 +818,7 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
return -1;
|
||||
}
|
||||
j = x;
|
||||
while( safe_isspace(z[j]) ){ j++; }
|
||||
while( fast_isspace(z[j]) ){ j++; }
|
||||
c = z[j];
|
||||
if( c==',' ) continue;
|
||||
if( c!=']' ) return -1;
|
||||
@@ -925,17 +855,17 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
return j+1;
|
||||
}else if( c=='n'
|
||||
&& strncmp(z+i,"null",4)==0
|
||||
&& !safe_isalnum(z[i+4]) ){
|
||||
&& !sqlite3Isalnum(z[i+4]) ){
|
||||
jsonParseAddNode(pParse, JSON_NULL, 0, 0);
|
||||
return i+4;
|
||||
}else if( c=='t'
|
||||
&& strncmp(z+i,"true",4)==0
|
||||
&& !safe_isalnum(z[i+4]) ){
|
||||
&& !sqlite3Isalnum(z[i+4]) ){
|
||||
jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
|
||||
return i+4;
|
||||
}else if( c=='f'
|
||||
&& strncmp(z+i,"false",5)==0
|
||||
&& !safe_isalnum(z[i+5]) ){
|
||||
&& !sqlite3Isalnum(z[i+5]) ){
|
||||
jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
|
||||
return i+5;
|
||||
}else if( c=='-' || (c>='0' && c<='9') ){
|
||||
@@ -1006,7 +936,7 @@ static int jsonParse(
|
||||
if( pParse->oom ) i = -1;
|
||||
if( i>0 ){
|
||||
assert( pParse->iDepth==0 );
|
||||
while( safe_isspace(zJson[i]) ) i++;
|
||||
while( fast_isspace(zJson[i]) ) i++;
|
||||
if( zJson[i] ) i = -1;
|
||||
}
|
||||
if( i<=0 ){
|
||||
@@ -1234,7 +1164,7 @@ static JsonNode *jsonLookupStep(
|
||||
}else if( zPath[0]=='[' ){
|
||||
i = 0;
|
||||
j = 1;
|
||||
while( safe_isdigit(zPath[j]) ){
|
||||
while( sqlite3Isdigit(zPath[j]) ){
|
||||
i = i*10 + zPath[j] - '0';
|
||||
j++;
|
||||
}
|
||||
@@ -1255,13 +1185,13 @@ static JsonNode *jsonLookupStep(
|
||||
j = 1;
|
||||
}
|
||||
j = 2;
|
||||
if( zPath[2]=='-' && safe_isdigit(zPath[3]) ){
|
||||
if( zPath[2]=='-' && sqlite3Isdigit(zPath[3]) ){
|
||||
unsigned int x = 0;
|
||||
j = 3;
|
||||
do{
|
||||
x = x*10 + zPath[j] - '0';
|
||||
j++;
|
||||
}while( safe_isdigit(zPath[j]) );
|
||||
}while( sqlite3Isdigit(zPath[j]) );
|
||||
if( x>i ) return 0;
|
||||
i -= x;
|
||||
}
|
||||
@@ -1480,7 +1410,7 @@ static void jsonTest1Func(
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAMETER(argc);
|
||||
sqlite3_result_int(ctx, sqlite3_value_subtype(argv[0])==JSON_SUBTYPE);
|
||||
}
|
||||
#endif /* SQLITE_DEBUG */
|
||||
@@ -1501,7 +1431,7 @@ static void jsonQuoteFunc(
|
||||
sqlite3_value **argv
|
||||
){
|
||||
JsonString jx;
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAMETER(argc);
|
||||
|
||||
jsonInit(&jx, ctx);
|
||||
jsonAppendValue(&jx, argv[0]);
|
||||
@@ -1572,13 +1502,34 @@ 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 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.
|
||||
** 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.
|
||||
*/
|
||||
static void jsonExtractFunc(
|
||||
sqlite3_context *ctx,
|
||||
@@ -1588,35 +1539,77 @@ 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;
|
||||
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 ){
|
||||
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;
|
||||
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.
|
||||
@@ -1632,7 +1625,7 @@ static JsonNode *jsonMergePatch(
|
||||
if( pPatch->eType!=JSON_OBJECT ){
|
||||
return pPatch;
|
||||
}
|
||||
assert( iTarget>=0 && iTarget<pParse->nNode );
|
||||
assert( iTarget<pParse->nNode );
|
||||
pTarget = &pParse->aNode[iTarget];
|
||||
assert( (pPatch->jnFlags & JNODE_APPEND)==0 );
|
||||
if( pTarget->eType!=JSON_OBJECT ){
|
||||
@@ -1662,8 +1655,11 @@ 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 );
|
||||
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;
|
||||
@@ -1709,7 +1705,7 @@ static void jsonPatchFunc(
|
||||
JsonParse y; /* The patch */
|
||||
JsonNode *pResult; /* The result of the merge */
|
||||
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAMETER(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);
|
||||
@@ -1830,7 +1826,7 @@ static void jsonReplaceFunc(
|
||||
if( x.nErr ) goto replace_err;
|
||||
if( pNode ){
|
||||
assert( pNode->eU==0 || pNode->eU==1 || pNode->eU==4 );
|
||||
json_testcase( pNode->eU!=0 && pNode->eU!=1 );
|
||||
testcase( pNode->eU!=0 && pNode->eU!=1 );
|
||||
pNode->jnFlags |= (u8)JNODE_REPLACE;
|
||||
VVA( pNode->eU = 4 );
|
||||
pNode->u.iReplace = i + 1;
|
||||
@@ -1846,6 +1842,7 @@ replace_err:
|
||||
jsonParseReset(&x);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** json_set(JSON, PATH, VALUE, ...)
|
||||
**
|
||||
@@ -1868,7 +1865,7 @@ static void jsonSetFunc(
|
||||
const char *zPath;
|
||||
u32 i;
|
||||
int bApnd;
|
||||
int bIsSet = *(int*)sqlite3_user_data(ctx);
|
||||
int bIsSet = sqlite3_user_data(ctx)!=0;
|
||||
|
||||
if( argc<1 ) return;
|
||||
if( (argc&1)==0 ) {
|
||||
@@ -1887,8 +1884,8 @@ static void jsonSetFunc(
|
||||
}else if( x.nErr ){
|
||||
goto jsonSetDone;
|
||||
}else if( pNode && (bApnd || bIsSet) ){
|
||||
json_testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 );
|
||||
assert( pNode->eU!=3 || pNode->eU!=5 );
|
||||
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;
|
||||
@@ -1908,8 +1905,8 @@ jsonSetDone:
|
||||
** json_type(JSON)
|
||||
** json_type(JSON, PATH)
|
||||
**
|
||||
** Return the top-level "type" of a JSON string. Throw an error if
|
||||
** either the JSON or PATH inputs are not well-formed.
|
||||
** 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.
|
||||
*/
|
||||
static void jsonTypeFunc(
|
||||
sqlite3_context *ctx,
|
||||
@@ -1945,7 +1942,7 @@ static void jsonValidFunc(
|
||||
sqlite3_value **argv
|
||||
){
|
||||
JsonParse *p; /* The parse */
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAMETER(argc);
|
||||
p = jsonParseCached(ctx, argv, 0);
|
||||
sqlite3_result_int(ctx, p!=0);
|
||||
}
|
||||
@@ -1965,7 +1962,7 @@ static void jsonArrayStep(
|
||||
sqlite3_value **argv
|
||||
){
|
||||
JsonString *pStr;
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAMETER(argc);
|
||||
pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr));
|
||||
if( pStr ){
|
||||
if( pStr->zBuf==0 ){
|
||||
@@ -2025,8 +2022,8 @@ static void jsonGroupInverse(
|
||||
char *z;
|
||||
char c;
|
||||
JsonString *pStr;
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAM(argv);
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAMETER(argv);
|
||||
pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
|
||||
#ifdef NEVER
|
||||
/* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
|
||||
@@ -2070,7 +2067,7 @@ static void jsonObjectStep(
|
||||
JsonString *pStr;
|
||||
const char *z;
|
||||
u32 n;
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAMETER(argc);
|
||||
pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr));
|
||||
if( pStr ){
|
||||
if( pStr->zBuf==0 ){
|
||||
@@ -2161,10 +2158,10 @@ static int jsonEachConnect(
|
||||
#define JEACH_JSON 8
|
||||
#define JEACH_ROOT 9
|
||||
|
||||
UNUSED_PARAM(pzErr);
|
||||
UNUSED_PARAM(argv);
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAM(pAux);
|
||||
UNUSED_PARAMETER(pzErr);
|
||||
UNUSED_PARAMETER(argv);
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAMETER(pAux);
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
"CREATE TABLE x(key,value,type,atom,id,parent,fullkey,path,"
|
||||
"json HIDDEN,root HIDDEN)");
|
||||
@@ -2187,7 +2184,7 @@ static int jsonEachDisconnect(sqlite3_vtab *pVtab){
|
||||
static int jsonEachOpenEach(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
|
||||
JsonEachCursor *pCur;
|
||||
|
||||
UNUSED_PARAM(p);
|
||||
UNUSED_PARAMETER(p);
|
||||
pCur = sqlite3_malloc( sizeof(*pCur) );
|
||||
if( pCur==0 ) return SQLITE_NOMEM;
|
||||
memset(pCur, 0, sizeof(*pCur));
|
||||
@@ -2247,7 +2244,7 @@ static int jsonEachNext(sqlite3_vtab_cursor *cur){
|
||||
p->eType = pUp->eType;
|
||||
if( pUp->eType==JSON_ARRAY ){
|
||||
assert( pUp->eU==0 || pUp->eU==3 );
|
||||
json_testcase( pUp->eU==3 );
|
||||
testcase( pUp->eU==3 );
|
||||
VVA( pUp->eU = 3 );
|
||||
if( iUp==p->i-1 ){
|
||||
pUp->u.iKey = 0;
|
||||
@@ -2434,7 +2431,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_PARAM(tab);
|
||||
UNUSED_PARAMETER(tab);
|
||||
aIdx[0] = aIdx[1] = -1;
|
||||
pConstraint = pIdxInfo->aConstraint;
|
||||
for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
|
||||
@@ -2490,8 +2487,8 @@ static int jsonEachFilter(
|
||||
const char *zRoot = 0;
|
||||
sqlite3_int64 n;
|
||||
|
||||
UNUSED_PARAM(idxStr);
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAMETER(idxStr);
|
||||
UNUSED_PARAMETER(argc);
|
||||
jsonEachCursorReset(p);
|
||||
if( idxNum==0 ) return SQLITE_OK;
|
||||
z = (const char*)sqlite3_value_text(argv[0]);
|
||||
@@ -2616,103 +2613,63 @@ static sqlite3_module jsonTreeModule = {
|
||||
0 /* xShadowName */
|
||||
};
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
#endif /* !defined(SQLITE_OMIT_JSON) */
|
||||
|
||||
/****************************************************************************
|
||||
** 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.
|
||||
****************************************************************************/
|
||||
|
||||
int sqlite3Json1Init(sqlite3 *db){
|
||||
int rc = SQLITE_OK;
|
||||
unsigned int i;
|
||||
static const struct {
|
||||
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 },
|
||||
|
||||
/*
|
||||
** 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
|
||||
/* DEBUG and TESTING functions */
|
||||
{ "json_parse", 1, 0, jsonParseFunc },
|
||||
{ "json_test1", 1, 0, jsonTest1Func },
|
||||
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
|
||||
}
|
||||
|
||||
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON)
|
||||
/*
|
||||
** Register the JSON table-valued functions
|
||||
*/
|
||||
int sqlite3JsonTableFunctions(sqlite3 *db){
|
||||
int rc = SQLITE_OK;
|
||||
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;
|
||||
const char *zName;
|
||||
sqlite3_module *pModule;
|
||||
} aMod[] = {
|
||||
{ "json_each", &jsonEachModule },
|
||||
{ "json_tree", &jsonTreeModule },
|
||||
};
|
||||
#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
|
||||
unsigned int i;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
#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) */
|
||||
#endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON) */
|
||||
@@ -485,6 +485,13 @@ static const sqlite3_api_routines sqlite3Apis = {
|
||||
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
|
||||
|
||||
+74
-18
@@ -50,9 +50,6 @@ 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
|
||||
@@ -87,8 +84,8 @@ static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = {
|
||||
sqlite3DbstatRegister,
|
||||
#endif
|
||||
sqlite3TestExtInit,
|
||||
#ifdef SQLITE_ENABLE_JSON1
|
||||
sqlite3Json1Init,
|
||||
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON)
|
||||
sqlite3JsonTableFunctions,
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_STMTVTAB
|
||||
sqlite3StmtVtabInit,
|
||||
@@ -1460,7 +1457,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;
|
||||
db->flags &= ~(u64)(SQLITE_DeferFKs|SQLITE_CorruptRdOnly);
|
||||
|
||||
/* If one has been configured, invoke the rollback-hook callback */
|
||||
if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
|
||||
@@ -2597,6 +2594,19 @@ 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
|
||||
@@ -2857,6 +2867,8 @@ 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;
|
||||
}
|
||||
@@ -4017,12 +4029,16 @@ int sqlite3_test_control(int op, ...){
|
||||
** sqlite3_test_control().
|
||||
*/
|
||||
case SQLITE_TESTCTRL_FAULT_INSTALL: {
|
||||
/* MSVC is picky about pulling func ptrs from va lists.
|
||||
** http://support.microsoft.com/kb/47961
|
||||
/* 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.
|
||||
** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int));
|
||||
*/
|
||||
typedef int(*TESTCALLBACKFUNC_t)(int);
|
||||
sqlite3GlobalConfig.xTestCallback = va_arg(ap, TESTCALLBACKFUNC_t);
|
||||
typedef int(*sqlite3FaultFuncType)(int);
|
||||
sqlite3GlobalConfig.xTestCallback = va_arg(ap, sqlite3FaultFuncType);
|
||||
rc = sqlite3FaultSim(0);
|
||||
break;
|
||||
}
|
||||
@@ -4149,13 +4165,27 @@ int sqlite3_test_control(int op, ...){
|
||||
break;
|
||||
}
|
||||
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, onoff, xAlt);
|
||||
**
|
||||
** If parameter onoff is non-zero, subsequent calls to localtime()
|
||||
** and its variants fail. If onoff is zero, undo this setting.
|
||||
** 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.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -4260,12 +4290,16 @@ int sqlite3_test_control(int op, ...){
|
||||
*/
|
||||
case SQLITE_TESTCTRL_IMPOSTER: {
|
||||
sqlite3 *db = va_arg(ap, sqlite3*);
|
||||
int iDb;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
break;
|
||||
@@ -4341,6 +4375,28 @@ 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)
|
||||
**
|
||||
|
||||
+10
-1
@@ -759,8 +759,15 @@ 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 ){
|
||||
@@ -768,9 +775,11 @@ void sqlite3OomFault(sqlite3 *db){
|
||||
}
|
||||
DisableLookaside;
|
||||
if( db->pParse ){
|
||||
sqlite3ErrorMsg(db->pParse, "out of memory");
|
||||
db->pParse->rc = SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+14
-12
@@ -178,6 +178,9 @@ static int memjrnlCreateFile(MemJournal *p){
|
||||
}
|
||||
|
||||
|
||||
/* Forward reference */
|
||||
static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size);
|
||||
|
||||
/*
|
||||
** Write data to the file.
|
||||
*/
|
||||
@@ -207,23 +210,21 @@ 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 || iOfst==0 );
|
||||
#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
|
||||
|| defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
|
||||
** 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);
|
||||
}
|
||||
if( iOfst==0 && p->pFirst ){
|
||||
assert( p->nChunkSize>iAmt );
|
||||
memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt);
|
||||
}else
|
||||
#else
|
||||
assert( iOfst>0 || p->pFirst==0 );
|
||||
#endif
|
||||
{
|
||||
}else{
|
||||
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));
|
||||
@@ -238,10 +239,11 @@ static int memjrnlWrite(
|
||||
assert( !p->pFirst );
|
||||
p->pFirst = pNew;
|
||||
}
|
||||
p->endpoint.pChunk = pNew;
|
||||
pChunk = p->endpoint.pChunk = pNew;
|
||||
}
|
||||
|
||||
memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace);
|
||||
assert( pChunk!=0 );
|
||||
memcpy((u8*)pChunk->zChunk + iChunkOffset, zWrite, iSpace);
|
||||
zWrite += iSpace;
|
||||
nWrite -= iSpace;
|
||||
p->endpoint.iOffset += iSpace;
|
||||
@@ -265,7 +267,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) ){
|
||||
|
||||
+39
-23
@@ -5798,25 +5798,35 @@ static int fillInUnixFile(
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Directories to consider for temp files.
|
||||
*/
|
||||
static const char *azTempDirs[] = {
|
||||
0,
|
||||
0,
|
||||
"/var/tmp",
|
||||
"/usr/tmp",
|
||||
"/tmp",
|
||||
"."
|
||||
};
|
||||
|
||||
/*
|
||||
** Initialize first two members of azTempDirs[] array.
|
||||
*/
|
||||
static void unixTempFileInit(void){
|
||||
azTempDirs[0] = getenv("SQLITE_TMPDIR");
|
||||
azTempDirs[1] = getenv("TMPDIR");
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the name of a directory in which to put temporary files.
|
||||
** If no suitable temporary file directory can be found, return NULL.
|
||||
*/
|
||||
static const char *unixTempFileDir(void){
|
||||
static const char *azDirs[] = {
|
||||
0,
|
||||
0,
|
||||
"/var/tmp",
|
||||
"/usr/tmp",
|
||||
"/tmp",
|
||||
"."
|
||||
};
|
||||
unsigned int i = 0;
|
||||
struct stat buf;
|
||||
const char *zDir = sqlite3_temp_directory;
|
||||
|
||||
if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
|
||||
if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
|
||||
while(1){
|
||||
if( zDir!=0
|
||||
&& osStat(zDir, &buf)==0
|
||||
@@ -5825,8 +5835,8 @@ static const char *unixTempFileDir(void){
|
||||
){
|
||||
return zDir;
|
||||
}
|
||||
if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break;
|
||||
zDir = azDirs[i++];
|
||||
if( i>=sizeof(azTempDirs)/sizeof(azTempDirs[0]) ) break;
|
||||
zDir = azTempDirs[i++];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -6001,20 +6011,23 @@ static int findCreateFileMode(
|
||||
**
|
||||
** where NN is a decimal number. The NN naming schemes are
|
||||
** used by the test_multiplex.c module.
|
||||
**
|
||||
** In normal operation, the journal file name will always contain
|
||||
** a '-' character. However in 8+3 filename mode, or if a corrupt
|
||||
** rollback journal specifies a super-journal with a goofy name, then
|
||||
** the '-' might be missing or the '-' might be the first character in
|
||||
** the filename. In that case, just return SQLITE_OK with *pMode==0.
|
||||
*/
|
||||
nDb = sqlite3Strlen30(zPath) - 1;
|
||||
while( zPath[nDb]!='-' ){
|
||||
/* In normal operation, the journal file name will always contain
|
||||
** a '-' character. However in 8+3 filename mode, or if a corrupt
|
||||
** rollback journal specifies a super-journal with a goofy name, then
|
||||
** the '-' might be missing. */
|
||||
if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK;
|
||||
nDb = sqlite3Strlen30(zPath) - 1;
|
||||
while( nDb>0 && zPath[nDb]!='.' ){
|
||||
if( zPath[nDb]=='-' ){
|
||||
memcpy(zDb, zPath, nDb);
|
||||
zDb[nDb] = '\0';
|
||||
rc = getFileMode(zDb, pMode, pUid, pGid);
|
||||
break;
|
||||
}
|
||||
nDb--;
|
||||
}
|
||||
memcpy(zDb, zPath, nDb);
|
||||
zDb[nDb] = '\0';
|
||||
|
||||
rc = getFileMode(zDb, pMode, pUid, pGid);
|
||||
}else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
|
||||
*pMode = 0600;
|
||||
}else if( flags & SQLITE_OPEN_URI ){
|
||||
@@ -8098,6 +8111,9 @@ int sqlite3_os_init(void){
|
||||
assert( UNIX_SHM_DMS==128 ); /* Byte offset of the deadman-switch */
|
||||
#endif
|
||||
|
||||
/* Initialize temp file dir array. */
|
||||
unixTempFileInit();
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
+44
-21
@@ -681,6 +681,7 @@ struct Pager {
|
||||
u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
|
||||
u32 sectorSize; /* Assumed sector size during rollback */
|
||||
Pgno mxPgno; /* Maximum allowed size of the database */
|
||||
Pgno lckPgno; /* Page number for the locking page */
|
||||
i64 pageSize; /* Number of bytes in a page */
|
||||
i64 journalSizeLimit; /* Size limit for persistent journal files */
|
||||
char *zFilename; /* Name of the database file */
|
||||
@@ -1667,7 +1668,7 @@ static int readJournalHdr(
|
||||
** journal file descriptor is advanced to the next sector boundary before
|
||||
** anything is written. The format is:
|
||||
**
|
||||
** + 4 bytes: PAGER_MJ_PGNO.
|
||||
** + 4 bytes: PAGER_SJ_PGNO.
|
||||
** + N bytes: super-journal filename in utf-8.
|
||||
** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator).
|
||||
** + 4 bytes: super-journal name checksum.
|
||||
@@ -1715,7 +1716,7 @@ static int writeSuperJournal(Pager *pPager, const char *zSuper){
|
||||
/* Write the super-journal data to the end of the journal file. If
|
||||
** an error occurs, return the error code to the caller.
|
||||
*/
|
||||
if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager))))
|
||||
if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_SJ_PGNO(pPager))))
|
||||
|| (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4)))
|
||||
|| (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper)))
|
||||
|| (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum)))
|
||||
@@ -2225,7 +2226,7 @@ static u32 pager_cksum(Pager *pPager, const u8 *aData){
|
||||
** corrupted, SQLITE_DONE is returned. Data is considered corrupted in
|
||||
** two circumstances:
|
||||
**
|
||||
** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or
|
||||
** * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or
|
||||
** * If the record is being rolled back from the main journal file
|
||||
** and the checksum field does not match the record content.
|
||||
**
|
||||
@@ -2285,7 +2286,7 @@ static int pager_playback_one_page(
|
||||
** it could cause invalid data to be written into the journal. We need to
|
||||
** detect this invalid data (with high probability) and ignore it.
|
||||
*/
|
||||
if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
|
||||
if( pgno==0 || pgno==PAGER_SJ_PGNO(pPager) ){
|
||||
assert( !isSavepnt );
|
||||
return SQLITE_DONE;
|
||||
}
|
||||
@@ -2844,6 +2845,9 @@ static int pager_playback(Pager *pPager, int isHot){
|
||||
goto end_playback;
|
||||
}
|
||||
pPager->dbSize = mxPg;
|
||||
if( pPager->mxPgno<mxPg ){
|
||||
pPager->mxPgno = mxPg;
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy original pages out of the journal and back into the
|
||||
@@ -3740,6 +3744,7 @@ int sqlite3PagerSetPagesize(Pager *pPager, u32 *pPageSize, int nReserve){
|
||||
pPager->pTmpSpace = pNew;
|
||||
pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
|
||||
pPager->pageSize = pageSize;
|
||||
pPager->lckPgno = (Pgno)(PENDING_BYTE/pageSize) + 1;
|
||||
}else{
|
||||
sqlite3PageFree(pNew);
|
||||
}
|
||||
@@ -3900,8 +3905,7 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
|
||||
** current database image, in pages, OR
|
||||
**
|
||||
** b) if the page content were written at this time, it would not
|
||||
** be necessary to write the current content out to the sub-journal
|
||||
** (as determined by function subjRequiresPage()).
|
||||
** be necessary to write the current content out to the sub-journal.
|
||||
**
|
||||
** If the condition asserted by this function were not true, and the
|
||||
** dirty page were to be discarded from the cache via the pagerStress()
|
||||
@@ -3916,8 +3920,16 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
|
||||
*/
|
||||
#if defined(SQLITE_DEBUG)
|
||||
static void assertTruncateConstraintCb(PgHdr *pPg){
|
||||
Pager *pPager = pPg->pPager;
|
||||
assert( pPg->flags&PGHDR_DIRTY );
|
||||
assert( !subjRequiresPage(pPg) || pPg->pgno<=pPg->pPager->dbSize );
|
||||
if( pPg->pgno>pPager->dbSize ){ /* if (a) is false */
|
||||
Pgno pgno = pPg->pgno;
|
||||
int i;
|
||||
for(i=0; i<pPg->pPager->nSavepoint; i++){
|
||||
PagerSavepoint *p = &pPager->aSavepoint[i];
|
||||
assert( p->nOrig<pgno || sqlite3BitvecTestNotNull(p->pInSavepoint,pgno) );
|
||||
}
|
||||
}
|
||||
}
|
||||
static void assertTruncateConstraint(Pager *pPager){
|
||||
sqlite3PcacheIterateDirty(pPager->pPCache, assertTruncateConstraintCb);
|
||||
@@ -3939,7 +3951,6 @@ static void assertTruncateConstraint(Pager *pPager){
|
||||
*/
|
||||
void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
|
||||
assert( pPager->dbSize>=nPage || CORRUPT_DB );
|
||||
testcase( pPager->dbSize<nPage );
|
||||
assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
|
||||
pPager->dbSize = nPage;
|
||||
|
||||
@@ -5258,7 +5269,7 @@ int sqlite3PagerSharedLock(Pager *pPager){
|
||||
** may mean that the pager was in the error-state when this
|
||||
** function was called and the journal file does not exist.
|
||||
*/
|
||||
if( !isOpen(pPager->jfd) ){
|
||||
if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
|
||||
sqlite3_vfs * const pVfs = pPager->pVfs;
|
||||
int bExists; /* True if journal file exists */
|
||||
rc = sqlite3OsAccess(
|
||||
@@ -5503,7 +5514,7 @@ static int getPageNormal(
|
||||
if( pPg->pPager && !noContent ){
|
||||
/* In this case the pcache already contains an initialized copy of
|
||||
** the page. Return without further ado. */
|
||||
assert( pgno!=PAGER_MJ_PGNO(pPager) );
|
||||
assert( pgno!=PAGER_SJ_PGNO(pPager) );
|
||||
pPager->aStat[PAGER_STAT_HIT]++;
|
||||
return SQLITE_OK;
|
||||
|
||||
@@ -5514,7 +5525,7 @@ static int getPageNormal(
|
||||
** (*) obsolete. Was: maximum page number is 2^31
|
||||
** (2) Never try to fetch the locking page
|
||||
*/
|
||||
if( pgno==PAGER_MJ_PGNO(pPager) ){
|
||||
if( pgno==PAGER_SJ_PGNO(pPager) ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto pager_acquire_err;
|
||||
}
|
||||
@@ -5660,6 +5671,7 @@ int sqlite3PagerGet(
|
||||
DbPage **ppPage, /* Write a pointer to the page here */
|
||||
int flags /* PAGER_GET_XXX flags */
|
||||
){
|
||||
/* printf("PAGE %u\n", pgno); fflush(stdout); */
|
||||
return pPager->xGet(pPager, pgno, ppPage, flags);
|
||||
}
|
||||
|
||||
@@ -5912,7 +5924,7 @@ static SQLITE_NOINLINE int pagerAddPageToRollbackJournal(PgHdr *pPg){
|
||||
/* We should never write to the journal file the page that
|
||||
** contains the database locks. The following assert verifies
|
||||
** that we do not. */
|
||||
assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
|
||||
assert( pPg->pgno!=PAGER_SJ_PGNO(pPager) );
|
||||
|
||||
assert( pPager->journalHdr<=pPager->journalOff );
|
||||
pData2 = pPg->pData;
|
||||
@@ -6091,7 +6103,7 @@ static SQLITE_NOINLINE int pagerWriteLargeSector(PgHdr *pPg){
|
||||
Pgno pg = pg1+ii;
|
||||
PgHdr *pPage;
|
||||
if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){
|
||||
if( pg!=PAGER_MJ_PGNO(pPager) ){
|
||||
if( pg!=PAGER_SJ_PGNO(pPager) ){
|
||||
rc = sqlite3PagerGet(pPager, pg, &pPage, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = pager_write(pPage);
|
||||
@@ -6569,7 +6581,7 @@ int sqlite3PagerCommitPhaseOne(
|
||||
** last page is never written out to disk, leaving the database file
|
||||
** undersized. Fix this now if it is the case. */
|
||||
if( pPager->dbSize>pPager->dbFileSize ){
|
||||
Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_MJ_PGNO(pPager));
|
||||
Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_SJ_PGNO(pPager));
|
||||
assert( pPager->eState==PAGER_WRITER_DBMOD );
|
||||
rc = pager_truncate(pPager, nNew);
|
||||
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
|
||||
@@ -7265,12 +7277,12 @@ int sqlite3PagerSetJournalMode(Pager *pPager, int eMode){
|
||||
u8 eOld = pPager->journalMode; /* Prior journalmode */
|
||||
|
||||
/* The eMode parameter is always valid */
|
||||
assert( eMode==PAGER_JOURNALMODE_DELETE
|
||||
|| eMode==PAGER_JOURNALMODE_TRUNCATE
|
||||
|| eMode==PAGER_JOURNALMODE_PERSIST
|
||||
|| eMode==PAGER_JOURNALMODE_OFF
|
||||
|| eMode==PAGER_JOURNALMODE_WAL
|
||||
|| eMode==PAGER_JOURNALMODE_MEMORY );
|
||||
assert( eMode==PAGER_JOURNALMODE_DELETE /* 0 */
|
||||
|| eMode==PAGER_JOURNALMODE_PERSIST /* 1 */
|
||||
|| eMode==PAGER_JOURNALMODE_OFF /* 2 */
|
||||
|| eMode==PAGER_JOURNALMODE_TRUNCATE /* 3 */
|
||||
|| eMode==PAGER_JOURNALMODE_MEMORY /* 4 */
|
||||
|| eMode==PAGER_JOURNALMODE_WAL /* 5 */ );
|
||||
|
||||
/* This routine is only called from the OP_JournalMode opcode, and
|
||||
** the logic there will never allow a temporary file to be changed
|
||||
@@ -7307,7 +7319,6 @@ int sqlite3PagerSetJournalMode(Pager *pPager, int eMode){
|
||||
|
||||
assert( isOpen(pPager->fd) || pPager->exclusiveMode );
|
||||
if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){
|
||||
|
||||
/* In this case we would like to delete the journal file. If it is
|
||||
** not possible, then that is not a problem. Deleting the journal file
|
||||
** here is an optimization only.
|
||||
@@ -7419,6 +7430,18 @@ int sqlite3PagerCheckpoint(
|
||||
int *pnCkpt /* OUT: Final number of checkpointed frames */
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
if( pPager->pWal==0 && pPager->journalMode==PAGER_JOURNALMODE_WAL ){
|
||||
/* This only happens when a database file is zero bytes in size opened and
|
||||
** then "PRAGMA journal_mode=WAL" is run and then sqlite3_wal_checkpoint()
|
||||
** is invoked without any intervening transactions. We need to start
|
||||
** a transaction to initialize pWal. The PRAGMA table_list statement is
|
||||
** used for this since it starts transactions on every database file,
|
||||
** including all ATTACHed databases. This seems expensive for a single
|
||||
** sqlite3_wal_checkpoint() call, but it happens very rarely.
|
||||
** https://sqlite.org/forum/forumpost/fd0f19d229156939
|
||||
*/
|
||||
sqlite3_exec(db, "PRAGMA table_list",0,0,0);
|
||||
}
|
||||
if( pPager->pWal ){
|
||||
rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
|
||||
(eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
|
||||
|
||||
+3
-2
@@ -43,14 +43,15 @@ typedef struct Pager Pager;
|
||||
typedef struct PgHdr DbPage;
|
||||
|
||||
/*
|
||||
** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
|
||||
** Page number PAGER_SJ_PGNO is never used in an SQLite database (it is
|
||||
** reserved for working around a windows/posix incompatibility). It is
|
||||
** used in the journal to signify that the remainder of the journal file
|
||||
** is devoted to storing a super-journal name - there are no more pages to
|
||||
** roll back. See comments for function writeSuperJournal() in pager.c
|
||||
** for details.
|
||||
*/
|
||||
#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
|
||||
#define PAGER_SJ_PGNO_COMPUTED(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
|
||||
#define PAGER_SJ_PGNO(x) ((x)->lckPgno)
|
||||
|
||||
/*
|
||||
** Allowed values for the flags parameter to sqlite3PagerOpen().
|
||||
|
||||
+18
-18
@@ -286,7 +286,7 @@ columnname(A) ::= nm(A) typetoken(Y). {sqlite3AddColumn(pParse,A,Y);}
|
||||
%left BITAND BITOR LSHIFT RSHIFT.
|
||||
%left PLUS MINUS.
|
||||
%left STAR SLASH REM.
|
||||
%left CONCAT.
|
||||
%left CONCAT PTR.
|
||||
%left COLLATE.
|
||||
%right BITNOT.
|
||||
%nonassoc ON.
|
||||
@@ -659,7 +659,7 @@ selcollist(A) ::= sclp(A) scanpt STAR. {
|
||||
}
|
||||
selcollist(A) ::= sclp(A) scanpt nm(X) DOT STAR. {
|
||||
Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
|
||||
Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
|
||||
Expr *pLeft = tokenExpr(pParse, TK_ID, X);
|
||||
Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
|
||||
A = sqlite3ExprListAppend(pParse,A, pDot);
|
||||
}
|
||||
@@ -1025,10 +1025,7 @@ idlist(A) ::= nm(Y).
|
||||
|
||||
%include {
|
||||
|
||||
/* Construct a new Expr object from a single identifier. Use the
|
||||
** new Expr to populate pOut. Set the span of pOut to be the identifier
|
||||
** that created the expression.
|
||||
*/
|
||||
/* Construct a new Expr object from a single token */
|
||||
static Expr *tokenExpr(Parse *pParse, int op, Token t){
|
||||
Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
|
||||
if( p ){
|
||||
@@ -1048,6 +1045,7 @@ idlist(A) ::= nm(Y).
|
||||
p->u.zToken = (char*)&p[1];
|
||||
memcpy(p->u.zToken, t.z, t.n);
|
||||
p->u.zToken[t.n] = 0;
|
||||
p->w.iOfst = (int)(t.z - pParse->zTail);
|
||||
if( sqlite3Isquote(p->u.zToken[0]) ){
|
||||
sqlite3DequoteExpr(p);
|
||||
}
|
||||
@@ -1068,22 +1066,17 @@ expr(A) ::= LP expr(X) RP. {A = X;}
|
||||
expr(A) ::= id(X). {A=tokenExpr(pParse,TK_ID,X); /*A-overwrites-X*/}
|
||||
expr(A) ::= JOIN_KW(X). {A=tokenExpr(pParse,TK_ID,X); /*A-overwrites-X*/}
|
||||
expr(A) ::= nm(X) DOT nm(Y). {
|
||||
Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
|
||||
Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &Y, 1);
|
||||
if( IN_RENAME_OBJECT ){
|
||||
sqlite3RenameTokenMap(pParse, (void*)temp2, &Y);
|
||||
sqlite3RenameTokenMap(pParse, (void*)temp1, &X);
|
||||
}
|
||||
Expr *temp1 = tokenExpr(pParse,TK_ID,X);
|
||||
Expr *temp2 = tokenExpr(pParse,TK_ID,Y);
|
||||
A = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
|
||||
}
|
||||
expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
|
||||
Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
|
||||
Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &Y, 1);
|
||||
Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &Z, 1);
|
||||
Expr *temp1 = tokenExpr(pParse,TK_ID,X);
|
||||
Expr *temp2 = tokenExpr(pParse,TK_ID,Y);
|
||||
Expr *temp3 = tokenExpr(pParse,TK_ID,Z);
|
||||
Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
|
||||
if( IN_RENAME_OBJECT ){
|
||||
sqlite3RenameTokenMap(pParse, (void*)temp3, &Z);
|
||||
sqlite3RenameTokenMap(pParse, (void*)temp2, &Y);
|
||||
sqlite3RenameTokenRemap(pParse, 0, temp1);
|
||||
}
|
||||
A = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
|
||||
}
|
||||
@@ -1091,6 +1084,7 @@ term(A) ::= NULL|FLOAT|BLOB(X). {A=tokenExpr(pParse,@X,X); /*A-overwrites-X*/}
|
||||
term(A) ::= STRING(X). {A=tokenExpr(pParse,@X,X); /*A-overwrites-X*/}
|
||||
term(A) ::= INTEGER(X). {
|
||||
A = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &X, 1);
|
||||
if( A ) A->w.iOfst = (int)(X.z - pParse->zTail);
|
||||
}
|
||||
expr(A) ::= VARIABLE(X). {
|
||||
if( !(X.z[0]=='#' && sqlite3Isdigit(X.z[1])) ){
|
||||
@@ -1235,6 +1229,12 @@ expr(A) ::= PLUS|MINUS(B) expr(X). [BITNOT] {
|
||||
/*A-overwrites-B*/
|
||||
}
|
||||
|
||||
expr(A) ::= expr(B) PTR(C) expr(D). {
|
||||
ExprList *pList = sqlite3ExprListAppend(pParse, 0, B);
|
||||
pList = sqlite3ExprListAppend(pParse, pList, D);
|
||||
A = sqlite3ExprFunction(pParse, pList, &C, 0);
|
||||
}
|
||||
|
||||
%type between_op {int}
|
||||
between_op(A) ::= BETWEEN. {A = 0;}
|
||||
between_op(A) ::= NOT BETWEEN. {A = 1;}
|
||||
@@ -1587,7 +1587,7 @@ expr(A) ::= RAISE LP IGNORE RP. {
|
||||
}
|
||||
}
|
||||
expr(A) ::= RAISE LP raisetype(T) COMMA nm(Z) RP. {
|
||||
A = sqlite3ExprAlloc(pParse->db, TK_RAISE, &Z, 1);
|
||||
A = sqlite3ExprAlloc(pParse->db, TK_RAISE, &Z, 1);
|
||||
if( A ) {
|
||||
A->affExpr = (char)T;
|
||||
}
|
||||
|
||||
+2
-1
@@ -551,7 +551,8 @@ void sqlite3PcacheDrop(PgHdr *p){
|
||||
** make it so.
|
||||
*/
|
||||
void sqlite3PcacheMakeDirty(PgHdr *p){
|
||||
assert( p->nRef>0 );
|
||||
assert( p->nRef>0 || p->pCache->bPurgeable==0 );
|
||||
testcase( p->nRef==0 );
|
||||
assert( sqlite3PcachePageSanity(p) );
|
||||
if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
|
||||
p->flags &= ~PGHDR_DONT_WRITE;
|
||||
|
||||
+12
-7
@@ -307,15 +307,16 @@ static void pragmaFunclistLine(
|
||||
int isBuiltin, /* True if this is a built-in function */
|
||||
int showInternFuncs /* True if showing internal functions */
|
||||
){
|
||||
u32 mask =
|
||||
SQLITE_DETERMINISTIC |
|
||||
SQLITE_DIRECTONLY |
|
||||
SQLITE_SUBTYPE |
|
||||
SQLITE_INNOCUOUS |
|
||||
SQLITE_FUNC_INTERNAL
|
||||
;
|
||||
if( showInternFuncs ) mask = 0xffffffff;
|
||||
for(; p; p=p->pNext){
|
||||
const char *zType;
|
||||
static const u32 mask =
|
||||
SQLITE_DETERMINISTIC |
|
||||
SQLITE_DIRECTONLY |
|
||||
SQLITE_SUBTYPE |
|
||||
SQLITE_INNOCUOUS |
|
||||
SQLITE_FUNC_INTERNAL
|
||||
;
|
||||
static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" };
|
||||
|
||||
assert( SQLITE_FUNC_ENCMASK==0x3 );
|
||||
@@ -1250,6 +1251,10 @@ void sqlite3Pragma(
|
||||
(void)sqlite3_finalize(pDummy);
|
||||
sqlite3DbFree(db, zSql);
|
||||
}
|
||||
if( db->mallocFailed ){
|
||||
sqlite3ErrorMsg(db->pParse, "out of memory");
|
||||
db->pParse->rc = SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
pHash = &db->aDb[ii].pSchema->tblHash;
|
||||
break;
|
||||
}
|
||||
|
||||
+1
-1
@@ -251,7 +251,7 @@ static const PragmaName aPragmaName[] = {
|
||||
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
|
||||
{/* zName: */ "database_list",
|
||||
/* ePragTyp: */ PragTyp_DATABASE_LIST,
|
||||
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
|
||||
/* ePragFlg: */ PragFlg_Result0,
|
||||
/* ColNames: */ 47, 3,
|
||||
/* iArg: */ 0 },
|
||||
#endif
|
||||
|
||||
+48
-19
@@ -568,8 +568,14 @@ int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
|
||||
/*
|
||||
** Free all memory allocations in the pParse object
|
||||
*/
|
||||
void sqlite3ParserReset(Parse *pParse){
|
||||
void sqlite3ParseObjectReset(Parse *pParse){
|
||||
sqlite3 *db = pParse->db;
|
||||
assert( db!=0 );
|
||||
assert( db->pParse==pParse );
|
||||
assert( pParse->nested==0 );
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
sqlite3DbFree(db, pParse->aTableLock);
|
||||
#endif
|
||||
while( pParse->pCleanup ){
|
||||
ParseCleanup *pCleanup = pParse->pCleanup;
|
||||
pParse->pCleanup = pCleanup->pNext;
|
||||
@@ -580,11 +586,12 @@ void sqlite3ParserReset(Parse *pParse){
|
||||
if( pParse->pConstExpr ){
|
||||
sqlite3ExprListDelete(db, pParse->pConstExpr);
|
||||
}
|
||||
if( db ){
|
||||
assert( db->lookaside.bDisable >= pParse->disableLookaside );
|
||||
db->lookaside.bDisable -= pParse->disableLookaside;
|
||||
db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
|
||||
}
|
||||
assert( db->lookaside.bDisable >= pParse->disableLookaside );
|
||||
db->lookaside.bDisable -= pParse->disableLookaside;
|
||||
db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
|
||||
assert( pParse->db->pParse==pParse );
|
||||
db->pParse = pParse->pOuterParse;
|
||||
pParse->db = 0;
|
||||
pParse->disableLookaside = 0;
|
||||
}
|
||||
|
||||
@@ -597,7 +604,7 @@ void sqlite3ParserReset(Parse *pParse){
|
||||
** cost for this mechansim (an extra malloc), so it should not be used
|
||||
** for common cleanups that happen on most calls. But for less
|
||||
** common cleanups, we save a single NULL-pointer comparison in
|
||||
** sqlite3ParserReset(), which reduces the total CPU cycle count.
|
||||
** sqlite3ParseObjectReset(), which reduces the total CPU cycle count.
|
||||
**
|
||||
** If a memory allocation error occurs, then the cleanup happens immediately.
|
||||
** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
|
||||
@@ -637,6 +644,25 @@ void *sqlite3ParserAddCleanup(
|
||||
return pPtr;
|
||||
}
|
||||
|
||||
/*
|
||||
** Turn bulk memory into a valid Parse object and link that Parse object
|
||||
** into database connection db.
|
||||
**
|
||||
** Call sqlite3ParseObjectReset() to undo this operation.
|
||||
**
|
||||
** Caution: Do not confuse this routine with sqlite3ParseObjectInit() which
|
||||
** is generated by Lemon.
|
||||
*/
|
||||
void sqlite3ParseObjectInit(Parse *pParse, sqlite3 *db){
|
||||
memset(PARSE_HDR(pParse), 0, PARSE_HDR_SZ);
|
||||
memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
|
||||
assert( db->pParse!=pParse );
|
||||
pParse->pOuterParse = db->pParse;
|
||||
db->pParse = pParse;
|
||||
pParse->db = db;
|
||||
if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
|
||||
}
|
||||
|
||||
/*
|
||||
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
|
||||
*/
|
||||
@@ -649,16 +675,19 @@ static int sqlite3Prepare(
|
||||
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
|
||||
const char **pzTail /* OUT: End of parsed string */
|
||||
){
|
||||
char *zErrMsg = 0; /* Error message */
|
||||
int rc = SQLITE_OK; /* Result code */
|
||||
int i; /* Loop counter */
|
||||
Parse sParse; /* Parsing context */
|
||||
|
||||
memset(&sParse, 0, PARSE_HDR_SZ);
|
||||
/* sqlite3ParseObjectInit(&sParse, db); // inlined for performance */
|
||||
memset(PARSE_HDR(&sParse), 0, PARSE_HDR_SZ);
|
||||
memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
|
||||
sParse.pOuterParse = db->pParse;
|
||||
db->pParse = &sParse;
|
||||
sParse.db = db;
|
||||
sParse.pReprepare = pReprepare;
|
||||
assert( ppStmt && *ppStmt==0 );
|
||||
/* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */
|
||||
if( db->mallocFailed ) sqlite3ErrorMsg(&sParse, "out of memory");
|
||||
assert( sqlite3_mutex_held(db->mutex) );
|
||||
|
||||
/* For a long-term use prepared statement avoid the use of
|
||||
@@ -711,7 +740,6 @@ static int sqlite3Prepare(
|
||||
|
||||
sqlite3VtabUnlockList(db);
|
||||
|
||||
sParse.db = db;
|
||||
if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
|
||||
char *zSqlCopy;
|
||||
int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
|
||||
@@ -724,14 +752,14 @@ static int sqlite3Prepare(
|
||||
}
|
||||
zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
|
||||
if( zSqlCopy ){
|
||||
sqlite3RunParser(&sParse, zSqlCopy, &zErrMsg);
|
||||
sqlite3RunParser(&sParse, zSqlCopy);
|
||||
sParse.zTail = &zSql[sParse.zTail-zSqlCopy];
|
||||
sqlite3DbFree(db, zSqlCopy);
|
||||
}else{
|
||||
sParse.zTail = &zSql[nBytes];
|
||||
}
|
||||
}else{
|
||||
sqlite3RunParser(&sParse, zSql, &zErrMsg);
|
||||
sqlite3RunParser(&sParse, zSql);
|
||||
}
|
||||
assert( 0==sParse.nQueryLoop );
|
||||
|
||||
@@ -747,7 +775,7 @@ static int sqlite3Prepare(
|
||||
sParse.checkSchema = 0;
|
||||
}
|
||||
if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){
|
||||
if( sParse.checkSchema ){
|
||||
if( sParse.checkSchema && db->init.busy==0 ){
|
||||
schemaIsValid(&sParse);
|
||||
}
|
||||
if( sParse.pVdbe ){
|
||||
@@ -755,14 +783,14 @@ static int sqlite3Prepare(
|
||||
}
|
||||
assert( 0==(*ppStmt) );
|
||||
rc = sParse.rc;
|
||||
if( zErrMsg ){
|
||||
sqlite3ErrorWithMsg(db, rc, "%s", zErrMsg);
|
||||
sqlite3DbFree(db, zErrMsg);
|
||||
if( sParse.zErrMsg ){
|
||||
sqlite3ErrorWithMsg(db, rc, "%s", sParse.zErrMsg);
|
||||
sqlite3DbFree(db, sParse.zErrMsg);
|
||||
}else{
|
||||
sqlite3Error(db, rc);
|
||||
}
|
||||
}else{
|
||||
assert( zErrMsg==0 );
|
||||
assert( sParse.zErrMsg==0 );
|
||||
*ppStmt = (sqlite3_stmt*)sParse.pVdbe;
|
||||
rc = SQLITE_OK;
|
||||
sqlite3ErrorClear(db);
|
||||
@@ -778,7 +806,7 @@ static int sqlite3Prepare(
|
||||
|
||||
end_prepare:
|
||||
|
||||
sqlite3ParserReset(&sParse);
|
||||
sqlite3ParseObjectReset(&sParse);
|
||||
return rc;
|
||||
}
|
||||
static int sqlite3LockAndPrepare(
|
||||
@@ -808,6 +836,7 @@ static int sqlite3LockAndPrepare(
|
||||
** reset is considered a permanent error. */
|
||||
rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
|
||||
assert( rc==SQLITE_OK || *ppStmt==0 );
|
||||
if( rc==SQLITE_OK || db->mallocFailed ) break;
|
||||
}while( rc==SQLITE_ERROR_RETRY
|
||||
|| (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
|
||||
sqlite3BtreeLeaveAll(db);
|
||||
|
||||
+52
-6
@@ -849,12 +849,22 @@ void sqlite3_str_vappendf(
|
||||
goto adjust_width_for_utf8;
|
||||
}
|
||||
case etTOKEN: {
|
||||
Token *pToken;
|
||||
if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
|
||||
pToken = va_arg(ap, Token*);
|
||||
assert( bArgList==0 );
|
||||
if( pToken && pToken->n ){
|
||||
sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
|
||||
if( flag_alternateform ){
|
||||
/* %#T means an Expr pointer that uses Expr.u.zToken */
|
||||
Expr *pExpr = va_arg(ap,Expr*);
|
||||
if( ALWAYS(pExpr) && ALWAYS(!ExprHasProperty(pExpr,EP_IntValue)) ){
|
||||
sqlite3_str_appendall(pAccum, (const char*)pExpr->u.zToken);
|
||||
sqlite3RecordErrorOffsetOfExpr(pAccum->db, pExpr);
|
||||
}
|
||||
}else{
|
||||
/* %T means a Token pointer */
|
||||
Token *pToken = va_arg(ap, Token*);
|
||||
assert( bArgList==0 );
|
||||
if( pToken && pToken->n ){
|
||||
sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
|
||||
sqlite3RecordErrorByteOffset(pAccum->db, pToken->z);
|
||||
}
|
||||
}
|
||||
length = width = 0;
|
||||
break;
|
||||
@@ -909,6 +919,42 @@ void sqlite3_str_vappendf(
|
||||
}/* End for loop over the format string */
|
||||
} /* End of function */
|
||||
|
||||
|
||||
/*
|
||||
** The z string points to the first character of a token that is
|
||||
** associated with an error. If db does not already have an error
|
||||
** byte offset recorded, try to compute the error byte offset for
|
||||
** z and set the error byte offset in db.
|
||||
*/
|
||||
void sqlite3RecordErrorByteOffset(sqlite3 *db, const char *z){
|
||||
const Parse *pParse;
|
||||
const char *zText;
|
||||
const char *zEnd;
|
||||
assert( z!=0 );
|
||||
if( NEVER(db==0) ) return;
|
||||
if( db->errByteOffset!=(-2) ) return;
|
||||
pParse = db->pParse;
|
||||
if( NEVER(pParse==0) ) return;
|
||||
zText =pParse->zTail;
|
||||
if( NEVER(zText==0) ) return;
|
||||
zEnd = &zText[strlen(zText)];
|
||||
if( SQLITE_WITHIN(z,zText,zEnd) ){
|
||||
db->errByteOffset = (int)(z-zText);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** If pExpr has a byte offset for the start of a token, record that as
|
||||
** as the error offset.
|
||||
*/
|
||||
void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){
|
||||
while( pExpr && (ExprHasProperty(pExpr,EP_FromJoin) || pExpr->w.iOfst<=0) ){
|
||||
pExpr = pExpr->pLeft;
|
||||
}
|
||||
if( pExpr==0 ) return;
|
||||
db->errByteOffset = pExpr->w.iOfst;
|
||||
}
|
||||
|
||||
/*
|
||||
** Enlarge the memory allocation on a StrAccum object so that it is
|
||||
** able to accept at least N more bytes of text.
|
||||
@@ -916,7 +962,7 @@ void sqlite3_str_vappendf(
|
||||
** Return the number of bytes of text that StrAccum is able to accept
|
||||
** after the attempted enlargement. The value returned might be zero.
|
||||
*/
|
||||
static int sqlite3StrAccumEnlarge(StrAccum *p, int N){
|
||||
int sqlite3StrAccumEnlarge(StrAccum *p, int N){
|
||||
char *zNew;
|
||||
assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
|
||||
if( p->accError ){
|
||||
|
||||
+39
-31
@@ -320,8 +320,9 @@ static int lookupName(
|
||||
}
|
||||
if( hit || zTab==0 ) continue;
|
||||
}
|
||||
if( zDb && pTab->pSchema!=pSchema ){
|
||||
continue;
|
||||
if( zDb ){
|
||||
if( pTab->pSchema!=pSchema ) continue;
|
||||
if( pSchema==0 && strcmp(zDb,"*")!=0 ) continue;
|
||||
}
|
||||
if( zTab ){
|
||||
const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
|
||||
@@ -452,6 +453,7 @@ static int lookupName(
|
||||
pExpr->y.pTab = pTab;
|
||||
if( pParse->bReturning ){
|
||||
eNewExprOp = TK_REGISTER;
|
||||
pExpr->op2 = TK_COLUMN;
|
||||
pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
|
||||
sqlite3TableColumnToStorage(pTab, iCol) + 1;
|
||||
}else{
|
||||
@@ -618,6 +620,7 @@ static int lookupName(
|
||||
}else{
|
||||
sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
|
||||
}
|
||||
sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
|
||||
pParse->checkSchema = 1;
|
||||
pTopNC->nNcErr++;
|
||||
}
|
||||
@@ -726,7 +729,8 @@ static void notValidImpl(
|
||||
Parse *pParse, /* Leave error message here */
|
||||
NameContext *pNC, /* The name context */
|
||||
const char *zMsg, /* Type of error */
|
||||
Expr *pExpr /* Invalidate this expression on error */
|
||||
Expr *pExpr, /* Invalidate this expression on error */
|
||||
Expr *pError /* Associate error with this expression */
|
||||
){
|
||||
const char *zIn = "partial index WHERE clauses";
|
||||
if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
|
||||
@@ -738,10 +742,11 @@ static void notValidImpl(
|
||||
#endif
|
||||
sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
|
||||
if( pExpr ) pExpr->op = TK_NULL;
|
||||
sqlite3RecordErrorOffsetOfExpr(pParse->db, pError);
|
||||
}
|
||||
#define sqlite3ResolveNotValid(P,N,M,X,E) \
|
||||
#define sqlite3ResolveNotValid(P,N,M,X,E,R) \
|
||||
assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \
|
||||
if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E);
|
||||
if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E,R);
|
||||
|
||||
/*
|
||||
** Expression p should encode a floating point value between 1.0 and 0.0.
|
||||
@@ -876,7 +881,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
testcase( pNC->ncFlags & NC_IdxExpr );
|
||||
testcase( pNC->ncFlags & NC_GenCol );
|
||||
sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator",
|
||||
NC_IdxExpr|NC_GenCol, 0);
|
||||
NC_IdxExpr|NC_GenCol, 0, pExpr);
|
||||
pRight = pExpr->pRight;
|
||||
if( pRight->op==TK_ID ){
|
||||
zDb = 0;
|
||||
@@ -907,7 +912,6 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
int no_such_func = 0; /* True if no such function exists */
|
||||
int wrong_num_args = 0; /* True if wrong number of arguments */
|
||||
int is_agg = 0; /* True if is an aggregate function */
|
||||
int nId; /* Number of characters in function name */
|
||||
const char *zId; /* The function name. */
|
||||
FuncDef *pDef; /* Information about the function */
|
||||
u8 enc = ENC(pParse->db); /* The database encoding */
|
||||
@@ -917,7 +921,6 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
#endif
|
||||
assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) );
|
||||
zId = pExpr->u.zToken;
|
||||
nId = sqlite3Strlen30(zId);
|
||||
pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
|
||||
if( pDef==0 ){
|
||||
pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
|
||||
@@ -934,8 +937,8 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
pExpr->iTable = exprProbability(pList->a[1].pExpr);
|
||||
if( pExpr->iTable<0 ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"second argument to likelihood() must be a "
|
||||
"constant between 0.0 and 1.0");
|
||||
"second argument to %#T() must be a "
|
||||
"constant between 0.0 and 1.0", pExpr);
|
||||
pNC->nNcErr++;
|
||||
}
|
||||
}else{
|
||||
@@ -956,8 +959,8 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
|
||||
if( auth!=SQLITE_OK ){
|
||||
if( auth==SQLITE_DENY ){
|
||||
sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
|
||||
pDef->zName);
|
||||
sqlite3ErrorMsg(pParse, "not authorized to use function: %#T",
|
||||
pExpr);
|
||||
pNC->nNcErr++;
|
||||
}
|
||||
pExpr->op = TK_NULL;
|
||||
@@ -980,7 +983,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all
|
||||
** all this. */
|
||||
sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
|
||||
NC_IdxExpr|NC_PartIdx|NC_GenCol, 0);
|
||||
NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr);
|
||||
}else{
|
||||
assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
|
||||
pExpr->op2 = pNC->ncFlags & NC_SelfRef;
|
||||
@@ -993,7 +996,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
/* Internal-use-only functions are disallowed unless the
|
||||
** SQL is being compiled using sqlite3NestedParse() or
|
||||
** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
|
||||
** used to activate internal functionsn for testing purposes */
|
||||
** used to activate internal functions for testing purposes */
|
||||
no_such_func = 1;
|
||||
pDef = 0;
|
||||
}else
|
||||
@@ -1012,7 +1015,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
);
|
||||
if( pDef && pDef->xValue==0 && pWin ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"%.*s() may not be used as a window function", nId, zId
|
||||
"%#T() may not be used as a window function", pExpr
|
||||
);
|
||||
pNC->nNcErr++;
|
||||
}else if(
|
||||
@@ -1026,13 +1029,13 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
}else{
|
||||
zType = "aggregate";
|
||||
}
|
||||
sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId);
|
||||
sqlite3ErrorMsg(pParse, "misuse of %s function %#T()",zType,pExpr);
|
||||
pNC->nNcErr++;
|
||||
is_agg = 0;
|
||||
}
|
||||
#else
|
||||
if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
|
||||
sqlite3ErrorMsg(pParse,"misuse of aggregate function %.*s()",nId,zId);
|
||||
sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr);
|
||||
pNC->nNcErr++;
|
||||
is_agg = 0;
|
||||
}
|
||||
@@ -1042,18 +1045,18 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
&& pParse->explain==0
|
||||
#endif
|
||||
){
|
||||
sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
|
||||
sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr);
|
||||
pNC->nNcErr++;
|
||||
}else if( wrong_num_args ){
|
||||
sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
|
||||
nId, zId);
|
||||
sqlite3ErrorMsg(pParse,"wrong number of arguments to function %#T()",
|
||||
pExpr);
|
||||
pNC->nNcErr++;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"FILTER may not be used with non-aggregate %.*s()",
|
||||
nId, zId
|
||||
"FILTER may not be used with non-aggregate %#T()",
|
||||
pExpr
|
||||
);
|
||||
pNC->nNcErr++;
|
||||
}
|
||||
@@ -1138,7 +1141,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
testcase( pNC->ncFlags & NC_IdxExpr );
|
||||
testcase( pNC->ncFlags & NC_GenCol );
|
||||
if( pNC->ncFlags & NC_SelfRef ){
|
||||
notValidImpl(pParse, pNC, "subqueries", pExpr);
|
||||
notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr);
|
||||
}else{
|
||||
sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
|
||||
}
|
||||
@@ -1156,7 +1159,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
testcase( pNC->ncFlags & NC_IdxExpr );
|
||||
testcase( pNC->ncFlags & NC_GenCol );
|
||||
sqlite3ResolveNotValid(pParse, pNC, "parameters",
|
||||
NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr);
|
||||
NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr, pExpr);
|
||||
break;
|
||||
}
|
||||
case TK_IS:
|
||||
@@ -1208,11 +1211,13 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
testcase( pExpr->op==TK_ISNOT );
|
||||
testcase( pExpr->op==TK_BETWEEN );
|
||||
sqlite3ErrorMsg(pParse, "row value misused");
|
||||
sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
|
||||
assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
|
||||
return pParse->nErr ? WRC_Abort : WRC_Continue;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1320,11 +1325,13 @@ static void resolveOutOfRangeError(
|
||||
Parse *pParse, /* The error context into which to write the error */
|
||||
const char *zType, /* "ORDER" or "GROUP" */
|
||||
int i, /* The index (1-based) of the term out of range */
|
||||
int mx /* Largest permissible value of i */
|
||||
int mx, /* Largest permissible value of i */
|
||||
Expr *pError /* Associate the error with the expression */
|
||||
){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"%r %s BY term out of range - should be "
|
||||
"between 1 and %d", i, zType, mx);
|
||||
sqlite3RecordErrorOffsetOfExpr(pParse->db, pError);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1380,7 +1387,7 @@ static int resolveCompoundOrderBy(
|
||||
if( NEVER(pE==0) ) continue;
|
||||
if( sqlite3ExprIsInteger(pE, &iCol) ){
|
||||
if( iCol<=0 || iCol>pEList->nExpr ){
|
||||
resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr);
|
||||
resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
|
||||
return 1;
|
||||
}
|
||||
}else{
|
||||
@@ -1476,7 +1483,7 @@ int sqlite3ResolveOrderGroupBy(
|
||||
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
|
||||
if( pItem->u.x.iOrderByCol ){
|
||||
if( pItem->u.x.iOrderByCol>pEList->nExpr ){
|
||||
resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
|
||||
resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr, 0);
|
||||
return 1;
|
||||
}
|
||||
resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,0);
|
||||
@@ -1568,7 +1575,7 @@ static int resolveOrderGroupBy(
|
||||
** number so that sqlite3ResolveOrderGroupBy() will convert the
|
||||
** order-by term to a copy of the result-set expression */
|
||||
if( iCol<1 || iCol>0xffff ){
|
||||
resolveOutOfRangeError(pParse, zType, i+1, nResult);
|
||||
resolveOutOfRangeError(pParse, zType, i+1, nResult, pE2);
|
||||
return 1;
|
||||
}
|
||||
pItem->u.x.iOrderByCol = (u16)iCol;
|
||||
@@ -1626,7 +1633,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
||||
*/
|
||||
if( (p->selFlags & SF_Expanded)==0 ){
|
||||
sqlite3SelectPrep(pParse, p, pOuterNC);
|
||||
return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
|
||||
return pParse->nErr ? WRC_Abort : WRC_Prune;
|
||||
}
|
||||
|
||||
isCompound = p->pPrior!=0;
|
||||
@@ -1674,7 +1681,8 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
|
||||
if( pItem->zName ) pParse->zAuthContext = pItem->zName;
|
||||
sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
|
||||
pParse->zAuthContext = zSavedContext;
|
||||
if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
|
||||
if( pParse->nErr ) return WRC_Abort;
|
||||
assert( db->mallocFailed==0 );
|
||||
|
||||
/* If the number of references to the outer context changed when
|
||||
** expressions in the sub-select were resolved, the sub-select
|
||||
|
||||
+83
-52
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
typedef struct DistinctCtx DistinctCtx;
|
||||
struct DistinctCtx {
|
||||
u8 isTnct; /* True if the DISTINCT keyword is present */
|
||||
u8 isTnct; /* 0: Not distinct. 1: DISTICT 2: DISTINCT and ORDER BY */
|
||||
u8 eTnctType; /* One of the WHERE_DISTINCT_* operators */
|
||||
int tabTnct; /* Ephemeral table used for DISTINCT processing */
|
||||
int addrTnct; /* Address of OP_OpenEphemeral opcode for tabTnct */
|
||||
@@ -354,14 +354,14 @@ static void addWhereTerm(
|
||||
ExprSetProperty(pEq, EP_FromJoin);
|
||||
assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
|
||||
ExprSetVVAProperty(pEq, EP_NoReduce);
|
||||
pEq->iRightJoinTable = pE2->iTable;
|
||||
pEq->w.iRightJoinTable = pE2->iTable;
|
||||
}
|
||||
*ppWhere = sqlite3ExprAnd(pParse, *ppWhere, pEq);
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the EP_FromJoin property on all terms of the given expression.
|
||||
** And set the Expr.iRightJoinTable to iTable for every term in the
|
||||
** And set the Expr.w.iRightJoinTable to iTable for every term in the
|
||||
** expression.
|
||||
**
|
||||
** The EP_FromJoin property is used on terms of an expression to tell
|
||||
@@ -371,8 +371,8 @@ static void addWhereTerm(
|
||||
** WHERE clause during join processing but we need to remember that they
|
||||
** originated in the ON or USING clause.
|
||||
**
|
||||
** The Expr.iRightJoinTable tells the WHERE clause processing that the
|
||||
** expression depends on table iRightJoinTable even if that table is not
|
||||
** The Expr.w.iRightJoinTable tells the WHERE clause processing that the
|
||||
** expression depends on table w.iRightJoinTable even if that table is not
|
||||
** explicitly mentioned in the expression. That information is needed
|
||||
** for cases like this:
|
||||
**
|
||||
@@ -390,7 +390,7 @@ void sqlite3SetJoinExpr(Expr *p, int iTable){
|
||||
ExprSetProperty(p, EP_FromJoin);
|
||||
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
|
||||
ExprSetVVAProperty(p, EP_NoReduce);
|
||||
p->iRightJoinTable = iTable;
|
||||
p->w.iRightJoinTable = iTable;
|
||||
if( p->op==TK_FUNCTION ){
|
||||
assert( ExprUseXList(p) );
|
||||
if( p->x.pList ){
|
||||
@@ -406,7 +406,7 @@ void sqlite3SetJoinExpr(Expr *p, int iTable){
|
||||
}
|
||||
|
||||
/* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
|
||||
** term that is marked with EP_FromJoin and iRightJoinTable==iTable into
|
||||
** term that is marked with EP_FromJoin and w.iRightJoinTable==iTable into
|
||||
** an ordinary term that omits the EP_FromJoin mark.
|
||||
**
|
||||
** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
|
||||
@@ -414,7 +414,7 @@ void sqlite3SetJoinExpr(Expr *p, int iTable){
|
||||
static void unsetJoinExpr(Expr *p, int iTable){
|
||||
while( p ){
|
||||
if( ExprHasProperty(p, EP_FromJoin)
|
||||
&& (iTable<0 || p->iRightJoinTable==iTable) ){
|
||||
&& (iTable<0 || p->w.iRightJoinTable==iTable) ){
|
||||
ExprClearProperty(p, EP_FromJoin);
|
||||
}
|
||||
if( p->op==TK_COLUMN && p->iTable==iTable ){
|
||||
@@ -1404,7 +1404,7 @@ KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
|
||||
p->nRef = 1;
|
||||
memset(&p[1], 0, nExtra);
|
||||
}else{
|
||||
sqlite3OomFault(db);
|
||||
return (KeyInfo*)sqlite3OomFault(db);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@@ -1575,6 +1575,9 @@ static void generateSortTail(
|
||||
|
||||
iTab = pSort->iECursor;
|
||||
if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){
|
||||
if( eDest==SRT_Mem && p->iOffset ){
|
||||
sqlite3VdbeAddOp2(v, OP_Null, 0, pDest->iSdst);
|
||||
}
|
||||
regRowid = 0;
|
||||
regRow = pDest->iSdst;
|
||||
}else{
|
||||
@@ -2196,7 +2199,7 @@ void sqlite3SelectAddColumnTypeAndCollation(
|
||||
a = pSelect->pEList->a;
|
||||
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
|
||||
const char *zType;
|
||||
int n, m;
|
||||
i64 n, m;
|
||||
pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
|
||||
p = a[i].pExpr;
|
||||
zType = columnType(&sNC, p, 0, 0, 0);
|
||||
@@ -2209,6 +2212,9 @@ void sqlite3SelectAddColumnTypeAndCollation(
|
||||
if( pCol->zCnName ){
|
||||
memcpy(&pCol->zCnName[n+1], zType, m+1);
|
||||
pCol->colFlags |= COLFLAG_HASTYPE;
|
||||
}else{
|
||||
testcase( pCol->colFlags & COLFLAG_HASTYPE );
|
||||
pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
|
||||
}
|
||||
}
|
||||
if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff;
|
||||
@@ -2617,7 +2623,7 @@ static int multiSelectOrderBy(
|
||||
** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES
|
||||
** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))").
|
||||
** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case.
|
||||
** Since the limit is exactly 1, we only need to evalutes the left-most VALUES.
|
||||
** Since the limit is exactly 1, we only need to evaluate the left-most VALUES.
|
||||
*/
|
||||
static int multiSelectValues(
|
||||
Parse *pParse, /* Parsing context */
|
||||
@@ -3293,6 +3299,8 @@ static int multiSelectOrderBy(
|
||||
){
|
||||
int i, j; /* Loop counters */
|
||||
Select *pPrior; /* Another SELECT immediately to our left */
|
||||
Select *pSplit; /* Left-most SELECT in the right-hand group */
|
||||
int nSelect; /* Number of SELECT statements in the compound */
|
||||
Vdbe *v; /* Generate code to this VDBE */
|
||||
SelectDest destA; /* Destination for coroutine A */
|
||||
SelectDest destB; /* Destination for coroutine B */
|
||||
@@ -3338,8 +3346,7 @@ static int multiSelectOrderBy(
|
||||
/* Patch up the ORDER BY clause
|
||||
*/
|
||||
op = p->op;
|
||||
pPrior = p->pPrior;
|
||||
assert( pPrior->pOrderBy==0 );
|
||||
assert( p->pPrior->pOrderBy==0 );
|
||||
pOrderBy = p->pOrderBy;
|
||||
assert( pOrderBy );
|
||||
nOrderBy = pOrderBy->nExpr;
|
||||
@@ -3389,11 +3396,6 @@ static int multiSelectOrderBy(
|
||||
pKeyMerge = 0;
|
||||
}
|
||||
|
||||
/* Reattach the ORDER BY clause to the query.
|
||||
*/
|
||||
p->pOrderBy = pOrderBy;
|
||||
pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
|
||||
|
||||
/* Allocate a range of temporary registers and the KeyInfo needed
|
||||
** for the logic that removes duplicate result rows when the
|
||||
** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL).
|
||||
@@ -3418,12 +3420,30 @@ static int multiSelectOrderBy(
|
||||
|
||||
/* Separate the left and the right query from one another
|
||||
*/
|
||||
p->pPrior = 0;
|
||||
pPrior->pNext = 0;
|
||||
sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER");
|
||||
if( pPrior->pPrior==0 ){
|
||||
sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER");
|
||||
nSelect = 1;
|
||||
if( (op==TK_ALL || op==TK_UNION)
|
||||
&& OptimizationEnabled(db, SQLITE_BalancedMerge)
|
||||
){
|
||||
for(pSplit=p; pSplit->pPrior!=0 && pSplit->op==op; pSplit=pSplit->pPrior){
|
||||
nSelect++;
|
||||
assert( pSplit->pPrior->pNext==pSplit );
|
||||
}
|
||||
}
|
||||
if( nSelect<=3 ){
|
||||
pSplit = p;
|
||||
}else{
|
||||
pSplit = p;
|
||||
for(i=2; i<nSelect; i+=2){ pSplit = pSplit->pPrior; }
|
||||
}
|
||||
pPrior = pSplit->pPrior;
|
||||
assert( pPrior!=0 );
|
||||
pSplit->pPrior = 0;
|
||||
pPrior->pNext = 0;
|
||||
assert( p->pOrderBy == pOrderBy );
|
||||
assert( pOrderBy!=0 || db->mallocFailed );
|
||||
pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
|
||||
sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER");
|
||||
sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER");
|
||||
|
||||
/* Compute the limit registers */
|
||||
computeLimitRegisters(pParse, p, labelEnd);
|
||||
@@ -3574,12 +3594,11 @@ static int multiSelectOrderBy(
|
||||
|
||||
/* Reassembly the compound query so that it will be freed correctly
|
||||
** by the calling function */
|
||||
if( p->pPrior ){
|
||||
sqlite3SelectDelete(db, p->pPrior);
|
||||
if( pSplit->pPrior ){
|
||||
sqlite3SelectDelete(db, pSplit->pPrior);
|
||||
}
|
||||
p->pPrior = pPrior;
|
||||
pPrior->pNext = p;
|
||||
|
||||
pSplit->pPrior = pPrior;
|
||||
pPrior->pNext = pSplit;
|
||||
sqlite3ExprListDelete(db, pPrior->pOrderBy);
|
||||
pPrior->pOrderBy = 0;
|
||||
|
||||
@@ -3629,9 +3648,9 @@ static Expr *substExpr(
|
||||
){
|
||||
if( pExpr==0 ) return 0;
|
||||
if( ExprHasProperty(pExpr, EP_FromJoin)
|
||||
&& pExpr->iRightJoinTable==pSubst->iTable
|
||||
&& pExpr->w.iRightJoinTable==pSubst->iTable
|
||||
){
|
||||
pExpr->iRightJoinTable = pSubst->iNewTable;
|
||||
pExpr->w.iRightJoinTable = pSubst->iNewTable;
|
||||
}
|
||||
if( pExpr->op==TK_COLUMN
|
||||
&& pExpr->iTable==pSubst->iTable
|
||||
@@ -3670,7 +3689,7 @@ static Expr *substExpr(
|
||||
ExprSetProperty(pNew, EP_CanBeNull);
|
||||
}
|
||||
if( ExprHasProperty(pExpr,EP_FromJoin) ){
|
||||
sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable);
|
||||
sqlite3SetJoinExpr(pNew, pExpr->w.iRightJoinTable);
|
||||
}
|
||||
sqlite3ExprDelete(db, pExpr);
|
||||
pExpr = pNew;
|
||||
@@ -3835,7 +3854,7 @@ static int renumberCursorsCb(Walker *pWalker, Expr *pExpr){
|
||||
renumberCursorDoMapping(pWalker, &pExpr->iTable);
|
||||
}
|
||||
if( ExprHasProperty(pExpr, EP_FromJoin) ){
|
||||
renumberCursorDoMapping(pWalker, &pExpr->iRightJoinTable);
|
||||
renumberCursorDoMapping(pWalker, &pExpr->w.iRightJoinTable);
|
||||
}
|
||||
return WRC_Continue;
|
||||
}
|
||||
@@ -4179,7 +4198,7 @@ static int flattenSubquery(
|
||||
|
||||
if( pSrc->nSrc>1 ){
|
||||
if( pParse->nSelect>500 ) return 0;
|
||||
aCsrMap = sqlite3DbMallocZero(db, (pParse->nTab+1)*sizeof(int));
|
||||
aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int));
|
||||
if( aCsrMap ) aCsrMap[0] = pParse->nTab;
|
||||
}
|
||||
}
|
||||
@@ -4845,11 +4864,13 @@ static int pushDownWhereTerms(
|
||||
}
|
||||
if( isLeftJoin
|
||||
&& (ExprHasProperty(pWhere,EP_FromJoin)==0
|
||||
|| pWhere->iRightJoinTable!=iCursor)
|
||||
|| pWhere->w.iRightJoinTable!=iCursor)
|
||||
){
|
||||
return 0; /* restriction (4) */
|
||||
}
|
||||
if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){
|
||||
if( ExprHasProperty(pWhere,EP_FromJoin)
|
||||
&& pWhere->w.iRightJoinTable!=iCursor
|
||||
){
|
||||
return 0; /* restriction (5) */
|
||||
}
|
||||
if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
|
||||
@@ -4950,11 +4971,11 @@ static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
|
||||
** does match this pattern, then a pointer to the Table object representing
|
||||
** <tbl> is returned. Otherwise, NULL is returned.
|
||||
**
|
||||
** This routine a condition for the count optimization. A correct answer
|
||||
** is obtained (though perhaps more slowly) if this routine returns NULL when
|
||||
** it could have returned a table pointer. But returning the pointer when
|
||||
** NULL should have been returned can result in incorrect answers and/or
|
||||
** crashes. So, when in doubt, return NULL.
|
||||
** This routine checks to see if it is safe to use the count optimization.
|
||||
** A correct answer is still obtained (though perhaps more slowly) if
|
||||
** this routine returns NULL when it could have returned a table pointer.
|
||||
** But returning the pointer when NULL should have been returned can
|
||||
** result in incorrect answers and/or crashes. So, when in doubt, return NULL.
|
||||
*/
|
||||
static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
|
||||
Table *pTab;
|
||||
@@ -4977,6 +4998,7 @@ static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
|
||||
pExpr = p->pEList->a[0].pExpr;
|
||||
assert( pExpr!=0 );
|
||||
if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
|
||||
if( pExpr->pAggInfo!=pAggInfo ) return 0;
|
||||
if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
|
||||
assert( pAggInfo->aFunc[0].pFExpr==pExpr );
|
||||
testcase( ExprHasProperty(pExpr, EP_Distinct) );
|
||||
@@ -5568,7 +5590,8 @@ static int selectExpander(Walker *pWalker, Select *p){
|
||||
|
||||
/* Process NATURAL keywords, and ON and USING clauses of joins.
|
||||
*/
|
||||
if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){
|
||||
assert( db->mallocFailed==0 || pParse->nErr!=0 );
|
||||
if( pParse->nErr || sqliteProcessJoin(pParse, p) ){
|
||||
return WRC_Abort;
|
||||
}
|
||||
|
||||
@@ -5865,12 +5888,13 @@ void sqlite3SelectPrep(
|
||||
NameContext *pOuterNC /* Name context for container */
|
||||
){
|
||||
assert( p!=0 || pParse->db->mallocFailed );
|
||||
assert( pParse->db->pParse==pParse );
|
||||
if( pParse->db->mallocFailed ) return;
|
||||
if( p->selFlags & SF_HasTypeInfo ) return;
|
||||
sqlite3SelectExpand(pParse, p);
|
||||
if( pParse->nErr || pParse->db->mallocFailed ) return;
|
||||
if( pParse->nErr ) return;
|
||||
sqlite3ResolveSelectNames(pParse, p, pOuterNC);
|
||||
if( pParse->nErr || pParse->db->mallocFailed ) return;
|
||||
if( pParse->nErr ) return;
|
||||
sqlite3SelectAddTypeInfo(pParse, p);
|
||||
}
|
||||
|
||||
@@ -5887,8 +5911,10 @@ static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
|
||||
int i;
|
||||
struct AggInfo_func *pFunc;
|
||||
int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
|
||||
assert( pParse->db->pParse==pParse );
|
||||
assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
|
||||
if( nReg==0 ) return;
|
||||
if( pParse->nErr || pParse->db->mallocFailed ) return;
|
||||
if( pParse->nErr ) return;
|
||||
#ifdef SQLITE_DEBUG
|
||||
/* Verify that all AggInfo registers are within the range specified by
|
||||
** AggInfo.mnReg..AggInfo.mxReg */
|
||||
@@ -6311,10 +6337,12 @@ int sqlite3Select(
|
||||
u8 minMaxFlag; /* Flag for min/max queries */
|
||||
|
||||
db = pParse->db;
|
||||
assert( pParse==db->pParse );
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( p==0 || db->mallocFailed || pParse->nErr ){
|
||||
if( p==0 || pParse->nErr ){
|
||||
return 1;
|
||||
}
|
||||
assert( db->mallocFailed==0 );
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
|
||||
#if SELECTTRACE_ENABLED
|
||||
SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
|
||||
@@ -6349,9 +6377,10 @@ int sqlite3Select(
|
||||
p->selFlags |= SF_NoopOrderBy;
|
||||
}
|
||||
sqlite3SelectPrep(pParse, p, 0);
|
||||
if( pParse->nErr || db->mallocFailed ){
|
||||
if( pParse->nErr ){
|
||||
goto select_end;
|
||||
}
|
||||
assert( db->mallocFailed==0 );
|
||||
assert( p->pEList!=0 );
|
||||
#if SELECTTRACE_ENABLED
|
||||
if( sqlite3SelectTrace & 0x104 ){
|
||||
@@ -6395,7 +6424,7 @@ int sqlite3Select(
|
||||
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
if( sqlite3WindowRewrite(pParse, p) ){
|
||||
assert( db->mallocFailed || pParse->nErr>0 );
|
||||
assert( pParse->nErr );
|
||||
goto select_end;
|
||||
}
|
||||
#if SELECTTRACE_ENABLED
|
||||
@@ -6792,6 +6821,7 @@ int sqlite3Select(
|
||||
** the sDistinct.isTnct is still set. Hence, isTnct represents the
|
||||
** original setting of the SF_Distinct flag, not the current setting */
|
||||
assert( sDistinct.isTnct );
|
||||
sDistinct.isTnct = 2;
|
||||
|
||||
#if SELECTTRACE_ENABLED
|
||||
if( sqlite3SelectTrace & 0x400 ){
|
||||
@@ -6871,7 +6901,7 @@ int sqlite3Select(
|
||||
/* Begin the database scan. */
|
||||
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
|
||||
p->pEList, wctrlFlags, p->nSelectRow);
|
||||
p->pEList, p, wctrlFlags, p->nSelectRow);
|
||||
if( pWInfo==0 ) goto select_end;
|
||||
if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
|
||||
p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
|
||||
@@ -7135,7 +7165,8 @@ int sqlite3Select(
|
||||
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
|
||||
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
|
||||
WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
|
||||
0, (sDistinct.isTnct==2 ? WHERE_DISTINCTBY : WHERE_GROUPBY)
|
||||
| (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
|
||||
);
|
||||
if( pWInfo==0 ){
|
||||
sqlite3ExprListDelete(db, pDistinct);
|
||||
@@ -7317,7 +7348,7 @@ int sqlite3Select(
|
||||
VdbeComment((v, "indicate accumulator empty"));
|
||||
sqlite3VdbeAddOp1(v, OP_Return, regReset);
|
||||
|
||||
if( eDist!=WHERE_DISTINCT_NOOP ){
|
||||
if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){
|
||||
struct AggInfo_func *pF = &pAggInfo->aFunc[0];
|
||||
fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
|
||||
}
|
||||
@@ -7433,7 +7464,7 @@ int sqlite3Select(
|
||||
|
||||
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
|
||||
pDistinct, minMaxFlag|distFlag, 0);
|
||||
pDistinct, 0, minMaxFlag|distFlag, 0);
|
||||
if( pWInfo==0 ){
|
||||
goto select_end;
|
||||
}
|
||||
@@ -7490,7 +7521,7 @@ int sqlite3Select(
|
||||
*/
|
||||
select_end:
|
||||
assert( db->mallocFailed==0 || db->mallocFailed==1 );
|
||||
pParse->nErr += db->mallocFailed;
|
||||
assert( db->mallocFailed==0 || pParse->nErr!=0 );
|
||||
sqlite3ExprListDelete(db, pMinMaxOrderBy);
|
||||
#ifdef SQLITE_DEBUG
|
||||
if( pAggInfo && !db->mallocFailed ){
|
||||
|
||||
+902
-292
File diff suppressed because it is too large
Load Diff
+352
-30
@@ -566,7 +566,7 @@ int sqlite3_exec(
|
||||
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
|
||||
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
|
||||
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
|
||||
#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
|
||||
#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
|
||||
|
||||
/*
|
||||
** CAPI3REF: Flags For File Open Operations
|
||||
@@ -3824,13 +3824,14 @@ void sqlite3_free_filename(char*);
|
||||
** sqlite3_extended_errcode() might change with each API call.
|
||||
** Except, there are some interfaces that are guaranteed to never
|
||||
** change the value of the error code. The error-code preserving
|
||||
** interfaces are:
|
||||
** interfaces include the following:
|
||||
**
|
||||
** <ul>
|
||||
** <li> sqlite3_errcode()
|
||||
** <li> sqlite3_extended_errcode()
|
||||
** <li> sqlite3_errmsg()
|
||||
** <li> sqlite3_errmsg16()
|
||||
** <li> sqlite3_error_offset()
|
||||
** </ul>
|
||||
**
|
||||
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
|
||||
@@ -3845,6 +3846,13 @@ void sqlite3_free_filename(char*);
|
||||
** ^(Memory to hold the error message string is managed internally
|
||||
** and must not be freed by the application)^.
|
||||
**
|
||||
** ^If the most recent error references a specific token in the input
|
||||
** SQL, the sqlite3_error_offset() interface returns the byte offset
|
||||
** of the start of that token. ^The byte offset returned by
|
||||
** sqlite3_error_offset() assumes that the input SQL is UTF8.
|
||||
** ^If the most recent error does not reference a specific token in the input
|
||||
** SQL, then the sqlite3_error_offset() function returns -1.
|
||||
**
|
||||
** When the serialized [threading mode] is in use, it might be the
|
||||
** case that a second error occurs on a separate thread in between
|
||||
** the time of the first error and the call to these interfaces.
|
||||
@@ -3864,6 +3872,7 @@ int sqlite3_extended_errcode(sqlite3 *db);
|
||||
const char *sqlite3_errmsg(sqlite3*);
|
||||
const void *sqlite3_errmsg16(sqlite3*);
|
||||
const char *sqlite3_errstr(int);
|
||||
int sqlite3_error_offset(sqlite3 *db);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Prepared Statement Object
|
||||
@@ -4275,6 +4284,10 @@ const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
|
||||
** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
|
||||
** read-only no-op if the table already exists, but
|
||||
** sqlite3_stmt_readonly() still returns false for such a statement.
|
||||
**
|
||||
** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN]
|
||||
** statement, then sqlite3_stmt_readonly(X) returns the same value as
|
||||
** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted.
|
||||
*/
|
||||
int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
|
||||
|
||||
@@ -4343,6 +4356,8 @@ int sqlite3_stmt_busy(sqlite3_stmt*);
|
||||
**
|
||||
** ^The sqlite3_value objects that are passed as parameters into the
|
||||
** implementation of [application-defined SQL functions] are protected.
|
||||
** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
|
||||
** are protected.
|
||||
** ^The sqlite3_value object returned by
|
||||
** [sqlite3_column_value()] is unprotected.
|
||||
** Unprotected sqlite3_value objects may only be used as arguments
|
||||
@@ -4964,6 +4979,10 @@ int sqlite3_data_count(sqlite3_stmt *pStmt);
|
||||
** even empty strings, are always zero-terminated. ^The return
|
||||
** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
|
||||
**
|
||||
** ^Strings returned by sqlite3_column_text16() always have the endianness
|
||||
** which is native to the platform, regardless of the text encoding set
|
||||
** for the database.
|
||||
**
|
||||
** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
|
||||
** [unprotected sqlite3_value] object. In a multithreaded environment,
|
||||
** an unprotected sqlite3_value object may only be used safely with
|
||||
@@ -4977,7 +4996,7 @@ int sqlite3_data_count(sqlite3_stmt *pStmt);
|
||||
** [application-defined SQL functions] or [virtual tables], not within
|
||||
** top-level application code.
|
||||
**
|
||||
** The these routines may attempt to convert the datatype of the result.
|
||||
** These routines may attempt to convert the datatype of the result.
|
||||
** ^For example, if the internal representation is FLOAT and a text result
|
||||
** is requested, [sqlite3_snprintf()] is used internally to perform the
|
||||
** conversion automatically. ^(The following table details the conversions
|
||||
@@ -5002,7 +5021,7 @@ int sqlite3_data_count(sqlite3_stmt *pStmt);
|
||||
** <tr><td> TEXT <td> BLOB <td> No change
|
||||
** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
|
||||
** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
|
||||
** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
|
||||
** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator
|
||||
** </table>
|
||||
** </blockquote>)^
|
||||
**
|
||||
@@ -5574,7 +5593,8 @@ unsigned int sqlite3_value_subtype(sqlite3_value*);
|
||||
** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
|
||||
** is a [protected sqlite3_value] object even if the input is not.
|
||||
** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
|
||||
** memory allocation fails.
|
||||
** memory allocation fails. ^If V is a [pointer value], then the result
|
||||
** of sqlite3_value_dup(V) is a NULL value.
|
||||
**
|
||||
** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
|
||||
** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
|
||||
@@ -7122,24 +7142,56 @@ struct sqlite3_index_info {
|
||||
**
|
||||
** These macros define the allowed values for the
|
||||
** [sqlite3_index_info].aConstraint[].op field. Each value represents
|
||||
** an operator that is part of a constraint term in the wHERE clause of
|
||||
** an operator that is part of a constraint term in the WHERE clause of
|
||||
** a query that uses a [virtual table].
|
||||
**
|
||||
** ^The left-hand operand of the operator is given by the corresponding
|
||||
** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand
|
||||
** operand is the rowid.
|
||||
** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET
|
||||
** operators have no left-hand operand, and so for those operators the
|
||||
** corresponding aConstraint[].iColumn is meaningless and should not be
|
||||
** used.
|
||||
**
|
||||
** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through
|
||||
** value 255 are reserved to represent functions that are overloaded
|
||||
** by the [xFindFunction|xFindFunction method] of the virtual table
|
||||
** implementation.
|
||||
**
|
||||
** The right-hand operands for each constraint might be accessible using
|
||||
** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand
|
||||
** operand is only available if it appears as a single constant literal
|
||||
** in the input SQL. If the right-hand operand is another column or an
|
||||
** expression (even a constant expression) or a parameter, then the
|
||||
** sqlite3_vtab_rhs_value() probably will not be able to extract it.
|
||||
** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and
|
||||
** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand
|
||||
** and hence calls to sqlite3_vtab_rhs_value() for those operators will
|
||||
** always return SQLITE_NOTFOUND.
|
||||
**
|
||||
** The collating sequence to be used for comparison can be found using
|
||||
** the [sqlite3_vtab_collation()] interface. For most real-world virtual
|
||||
** tables, the collating sequence of constraints does not matter (for example
|
||||
** because the constraints are numeric) and so the sqlite3_vtab_collation()
|
||||
** interface is no commonly needed.
|
||||
*/
|
||||
#define SQLITE_INDEX_CONSTRAINT_EQ 2
|
||||
#define SQLITE_INDEX_CONSTRAINT_GT 4
|
||||
#define SQLITE_INDEX_CONSTRAINT_LE 8
|
||||
#define SQLITE_INDEX_CONSTRAINT_LT 16
|
||||
#define SQLITE_INDEX_CONSTRAINT_GE 32
|
||||
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
|
||||
#define SQLITE_INDEX_CONSTRAINT_LIKE 65
|
||||
#define SQLITE_INDEX_CONSTRAINT_GLOB 66
|
||||
#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
|
||||
#define SQLITE_INDEX_CONSTRAINT_NE 68
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNOT 69
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNULL 71
|
||||
#define SQLITE_INDEX_CONSTRAINT_IS 72
|
||||
#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
|
||||
#define SQLITE_INDEX_CONSTRAINT_EQ 2
|
||||
#define SQLITE_INDEX_CONSTRAINT_GT 4
|
||||
#define SQLITE_INDEX_CONSTRAINT_LE 8
|
||||
#define SQLITE_INDEX_CONSTRAINT_LT 16
|
||||
#define SQLITE_INDEX_CONSTRAINT_GE 32
|
||||
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
|
||||
#define SQLITE_INDEX_CONSTRAINT_LIKE 65
|
||||
#define SQLITE_INDEX_CONSTRAINT_GLOB 66
|
||||
#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
|
||||
#define SQLITE_INDEX_CONSTRAINT_NE 68
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNOT 69
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNULL 71
|
||||
#define SQLITE_INDEX_CONSTRAINT_IS 72
|
||||
#define SQLITE_INDEX_CONSTRAINT_LIMIT 73
|
||||
#define SQLITE_INDEX_CONSTRAINT_OFFSET 74
|
||||
#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
|
||||
|
||||
/*
|
||||
** CAPI3REF: Register A Virtual Table Implementation
|
||||
@@ -7168,7 +7220,7 @@ struct sqlite3_index_info {
|
||||
** destructor.
|
||||
**
|
||||
** ^If the third parameter (the pointer to the sqlite3_module object) is
|
||||
** NULL then no new module is create and any existing modules with the
|
||||
** NULL then no new module is created and any existing modules with the
|
||||
** same name are dropped.
|
||||
**
|
||||
** See also: [sqlite3_drop_modules()]
|
||||
@@ -7944,7 +7996,8 @@ int sqlite3_test_control(int op, ...);
|
||||
#define SQLITE_TESTCTRL_SEEK_COUNT 30
|
||||
#define SQLITE_TESTCTRL_TRACEFLAGS 31
|
||||
#define SQLITE_TESTCTRL_TUNE 32
|
||||
#define SQLITE_TESTCTRL_LAST 32 /* Largest TESTCTRL */
|
||||
#define SQLITE_TESTCTRL_LOGEST 33
|
||||
#define SQLITE_TESTCTRL_LAST 33 /* Largest TESTCTRL */
|
||||
|
||||
/*
|
||||
** CAPI3REF: SQL Keyword Checking
|
||||
@@ -8467,6 +8520,16 @@ int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
|
||||
** The counter is incremented on the first [sqlite3_step()] call of each
|
||||
** cycle.
|
||||
**
|
||||
** [[SQLITE_STMTSTATUS_FILTER_MISS]]
|
||||
** [[SQLITE_STMTSTATUS_FILTER HIT]]
|
||||
** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
|
||||
** SQLITE_STMTSTATUS_FILTER_MISS</dt>
|
||||
** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
|
||||
** step was bypassed because a Bloom filter returned not-found. The
|
||||
** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
|
||||
** times that the Bloom filter returned a find, and thus the join step
|
||||
** had to be processed as normal.
|
||||
**
|
||||
** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
|
||||
** <dd>^This is the approximate number of bytes of heap memory
|
||||
** used to store the prepared statement. ^This value is not actually
|
||||
@@ -8481,6 +8544,8 @@ int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
|
||||
#define SQLITE_STMTSTATUS_VM_STEP 4
|
||||
#define SQLITE_STMTSTATUS_REPREPARE 5
|
||||
#define SQLITE_STMTSTATUS_RUN 6
|
||||
#define SQLITE_STMTSTATUS_FILTER_MISS 7
|
||||
#define SQLITE_STMTSTATUS_FILTER_HIT 8
|
||||
#define SQLITE_STMTSTATUS_MEMUSED 99
|
||||
|
||||
/*
|
||||
@@ -9449,19 +9514,276 @@ int sqlite3_vtab_nochange(sqlite3_context*);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Determine The Collation For a Virtual Table Constraint
|
||||
** METHOD: sqlite3_index_info
|
||||
**
|
||||
** This function may only be called from within a call to the [xBestIndex]
|
||||
** method of a [virtual table].
|
||||
** method of a [virtual table]. This function returns a pointer to a string
|
||||
** that is the name of the appropriate collation sequence to use for text
|
||||
** comparisons on the constraint identified by its arguments.
|
||||
**
|
||||
** The first argument must be the sqlite3_index_info object that is the
|
||||
** first parameter to the xBestIndex() method. The second argument must be
|
||||
** an index into the aConstraint[] array belonging to the sqlite3_index_info
|
||||
** structure passed to xBestIndex. This function returns a pointer to a buffer
|
||||
** containing the name of the collation sequence for the corresponding
|
||||
** constraint.
|
||||
** The first argument must be the pointer to the [sqlite3_index_info] object
|
||||
** that is the first parameter to the xBestIndex() method. The second argument
|
||||
** must be an index into the aConstraint[] array belonging to the
|
||||
** sqlite3_index_info structure passed to xBestIndex.
|
||||
**
|
||||
** Important:
|
||||
** The first parameter must be the same pointer that is passed into the
|
||||
** xBestMethod() method. The first parameter may not be a pointer to a
|
||||
** different [sqlite3_index_info] object, even an exact copy.
|
||||
**
|
||||
** The return value is computed as follows:
|
||||
**
|
||||
** <ol>
|
||||
** <li><p> If the constraint comes from a WHERE clause expression that contains
|
||||
** a [COLLATE operator], then the name of the collation specified by
|
||||
** that COLLATE operator is returned.
|
||||
** <li><p> If there is no COLLATE operator, but the column that is the subject
|
||||
** of the constraint specifies an alternative collating sequence via
|
||||
** a [COLLATE clause] on the column definition within the CREATE TABLE
|
||||
** statement that was passed into [sqlite3_declare_vtab()], then the
|
||||
** name of that alternative collating sequence is returned.
|
||||
** <li><p> Otherwise, "BINARY" is returned.
|
||||
** </ol>
|
||||
*/
|
||||
SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Determine if a virtual table query is DISTINCT
|
||||
** METHOD: sqlite3_index_info
|
||||
**
|
||||
** This API may only be used from within an [xBestIndex|xBestIndex method]
|
||||
** of a [virtual table] implementation. The result of calling this
|
||||
** interface from outside of xBestIndex() is undefined and probably harmful.
|
||||
**
|
||||
** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
|
||||
** 3. The integer returned by sqlite3_vtab_distinct()
|
||||
** gives the virtual table additional information about how the query
|
||||
** planner wants the output to be ordered. As long as the virtual table
|
||||
** can meet the ordering requirements of the query planner, it may set
|
||||
** the "orderByConsumed" flag.
|
||||
**
|
||||
** <ol><li value="0"><p>
|
||||
** ^If the sqlite3_vtab_distinct() interface returns 0, that means
|
||||
** that the query planner needs the virtual table to return all rows in the
|
||||
** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
|
||||
** [sqlite3_index_info] object. This is the default expectation. If the
|
||||
** virtual table outputs all rows in sorted order, then it is always safe for
|
||||
** the xBestIndex method to set the "orderByConsumed" flag, regardless of
|
||||
** the return value from sqlite3_vtab_distinct().
|
||||
** <li value="1"><p>
|
||||
** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
|
||||
** that the query planner does not need the rows to be returned in sorted order
|
||||
** as long as all rows with the same values in all columns identified by the
|
||||
** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
|
||||
** is doing a GROUP BY.
|
||||
** <li value="2"><p>
|
||||
** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
|
||||
** that the query planner does not need the rows returned in any particular
|
||||
** order, as long as rows with the same values in all "aOrderBy" columns
|
||||
** are adjacent.)^ ^(Furthermore, only a single row for each particular
|
||||
** combination of values in the columns identified by the "aOrderBy" field
|
||||
** needs to be returned.)^ ^It is always ok for two or more rows with the same
|
||||
** values in all "aOrderBy" columns to be returned, as long as all such rows
|
||||
** are adjacent. ^The virtual table may, if it chooses, omit extra rows
|
||||
** that have the same value for all columns identified by "aOrderBy".
|
||||
** ^However omitting the extra rows is optional.
|
||||
** This mode is used for a DISTINCT query.
|
||||
** <li value="3"><p>
|
||||
** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
|
||||
** that the query planner needs only distinct rows but it does need the
|
||||
** rows to be sorted.)^ ^The virtual table implementation is free to omit
|
||||
** rows that are identical in all aOrderBy columns, if it wants to, but
|
||||
** it is not required to omit any rows. This mode is used for queries
|
||||
** that have both DISTINCT and ORDER BY clauses.
|
||||
** </ol>
|
||||
**
|
||||
** ^For the purposes of comparing virtual table output values to see if the
|
||||
** values are same value for sorting purposes, two NULL values are considered
|
||||
** to be the same. In other words, the comparison operator is "IS"
|
||||
** (or "IS NOT DISTINCT FROM") and not "==".
|
||||
**
|
||||
** If a virtual table implementation is unable to meet the requirements
|
||||
** specified above, then it must not set the "orderByConsumed" flag in the
|
||||
** [sqlite3_index_info] object or an incorrect answer may result.
|
||||
**
|
||||
** ^A virtual table implementation is always free to return rows in any order
|
||||
** it wants, as long as the "orderByConsumed" flag is not set. ^When the
|
||||
** the "orderByConsumed" flag is unset, the query planner will add extra
|
||||
** [bytecode] to ensure that the final results returned by the SQL query are
|
||||
** ordered correctly. The use of the "orderByConsumed" flag and the
|
||||
** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
|
||||
** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
|
||||
** flag might help queries against a virtual table to run faster. Being
|
||||
** overly aggressive and setting the "orderByConsumed" flag when it is not
|
||||
** valid to do so, on the other hand, might cause SQLite to return incorrect
|
||||
** results.
|
||||
*/
|
||||
int sqlite3_vtab_distinct(sqlite3_index_info*);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Identify and handle IN constraints in xBestIndex
|
||||
**
|
||||
** This interface may only be used from within an
|
||||
** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
|
||||
** The result of invoking this interface from any other context is
|
||||
** undefined and probably harmful.
|
||||
**
|
||||
** ^(A constraint on a virtual table of the form
|
||||
** "[IN operator|column IN (...)]" is
|
||||
** communicated to the xBestIndex method as a
|
||||
** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
|
||||
** this constraint, it must set the corresponding
|
||||
** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
|
||||
** the usual mode of handling IN operators, SQLite generates [bytecode]
|
||||
** that invokes the [xFilter|xFilter() method] once for each value
|
||||
** on the right-hand side of the IN operator.)^ Thus the virtual table
|
||||
** only sees a single value from the right-hand side of the IN operator
|
||||
** at a time.
|
||||
**
|
||||
** In some cases, however, it would be advantageous for the virtual
|
||||
** table to see all values on the right-hand of the IN operator all at
|
||||
** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
|
||||
**
|
||||
** <ol>
|
||||
** <li><p>
|
||||
** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
|
||||
** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
|
||||
** is an [IN operator] that can be processed all at once. ^In other words,
|
||||
** sqlite3_vtab_in() with -1 in the third argument is a mechanism
|
||||
** by which the virtual table can ask SQLite if all-at-once processing
|
||||
** of the IN operator is even possible.
|
||||
**
|
||||
** <li><p>
|
||||
** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
|
||||
** to SQLite that the virtual table does or does not want to process
|
||||
** the IN operator all-at-once, respectively. ^Thus when the third
|
||||
** parameter (F) is non-negative, this interface is the mechanism by
|
||||
** which the virtual table tells SQLite how it wants to process the
|
||||
** IN operator.
|
||||
** </ol>
|
||||
**
|
||||
** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
|
||||
** within the same xBestIndex method call. ^For any given P,N pair,
|
||||
** the return value from sqlite3_vtab_in(P,N,F) will always be the same
|
||||
** within the same xBestIndex call. ^If the interface returns true
|
||||
** (non-zero), that means that the constraint is an IN operator
|
||||
** that can be processed all-at-once. ^If the constraint is not an IN
|
||||
** operator or cannot be processed all-at-once, then the interface returns
|
||||
** false.
|
||||
**
|
||||
** ^(All-at-once processing of the IN operator is selected if both of the
|
||||
** following conditions are met:
|
||||
**
|
||||
** <ol>
|
||||
** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
|
||||
** integer. This is how the virtual table tells SQLite that it wants to
|
||||
** use the N-th constraint.
|
||||
**
|
||||
** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
|
||||
** non-negative had F>=1.
|
||||
** </ol>)^
|
||||
**
|
||||
** ^If either or both of the conditions above are false, then SQLite uses
|
||||
** the traditional one-at-a-time processing strategy for the IN constraint.
|
||||
** ^If both conditions are true, then the argvIndex-th parameter to the
|
||||
** xFilter method will be an [sqlite3_value] that appears to be NULL,
|
||||
** but which can be passed to [sqlite3_vtab_in_first()] and
|
||||
** [sqlite3_vtab_in_next()] to find all values on the right-hand side
|
||||
** of the IN constraint.
|
||||
*/
|
||||
int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
|
||||
**
|
||||
** These interfaces are only useful from within the
|
||||
** [xFilter|xFilter() method] of a [virtual table] implementation.
|
||||
** The result of invoking these interfaces from any other context
|
||||
** is undefined and probably harmful.
|
||||
**
|
||||
** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
|
||||
** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
|
||||
** xFilter method which invokes these routines, and specifically
|
||||
** a parameter that was previously selected for all-at-once IN constraint
|
||||
** processing use the [sqlite3_vtab_in()] interface in the
|
||||
** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
|
||||
** an xFilter argument that was selected for all-at-once IN constraint
|
||||
** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
|
||||
** exhibit some other undefined or harmful behavior.
|
||||
**
|
||||
** ^(Use these routines to access all values on the right-hand side
|
||||
** of the IN constraint using code like the following:
|
||||
**
|
||||
** <blockquote><pre>
|
||||
** for(rc=sqlite3_vtab_in_first(pList, &pVal);
|
||||
** rc==SQLITE_OK && pVal
|
||||
** rc=sqlite3_vtab_in_next(pList, &pVal)
|
||||
** ){
|
||||
** // do something with pVal
|
||||
** }
|
||||
** if( rc!=SQLITE_OK ){
|
||||
** // an error has occurred
|
||||
** }
|
||||
** </pre></blockquote>)^
|
||||
**
|
||||
** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
|
||||
** routines return SQLITE_OK and set *P to point to the first or next value
|
||||
** on the RHS of the IN constraint. ^If there are no more values on the
|
||||
** right hand side of the IN constraint, then *P is set to NULL and these
|
||||
** routines return [SQLITE_DONE]. ^The return value might be
|
||||
** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
|
||||
**
|
||||
** The *ppOut values returned by these routines are only valid until the
|
||||
** next call to either of these routines or until the end of the xFilter
|
||||
** method from which these routines were called. If the virtual table
|
||||
** implementation needs to retain the *ppOut values for longer, it must make
|
||||
** copies. The *ppOut values are [protected sqlite3_value|protected].
|
||||
*/
|
||||
int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
|
||||
int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Constraint values in xBestIndex()
|
||||
** METHOD: sqlite3_index_info
|
||||
**
|
||||
** This API may only be used from within the [xBestIndex|xBestIndex method]
|
||||
** of a [virtual table] implementation. The result of calling this interface
|
||||
** from outside of an xBestIndex method are undefined and probably harmful.
|
||||
**
|
||||
** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
|
||||
** the [xBestIndex] method of a [virtual table] implementation, with P being
|
||||
** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
|
||||
** J being a 0-based index into P->aConstraint[], then this routine
|
||||
** attempts to set *V to the value of the right-hand operand of
|
||||
** that constraint if the right-hand operand is known. ^If the
|
||||
** right-hand operand is not known, then *V is set to a NULL pointer.
|
||||
** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
|
||||
** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
|
||||
** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
|
||||
** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
|
||||
** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
|
||||
** something goes wrong.
|
||||
**
|
||||
** The sqlite3_vtab_rhs_value() interface is usually only successful if
|
||||
** the right-hand operand of a constraint is a literal value in the original
|
||||
** SQL statement. If the right-hand operand is an expression or a reference
|
||||
** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()
|
||||
** will probably return [SQLITE_NOTFOUND].
|
||||
**
|
||||
** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and
|
||||
** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such
|
||||
** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^
|
||||
**
|
||||
** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value
|
||||
** and remains valid for the duration of the xBestIndex method call.
|
||||
** ^When xBestIndex returns, the sqlite3_value object returned by
|
||||
** sqlite3_vtab_rhs_value() is automatically deallocated.
|
||||
**
|
||||
** The "_rhs_" in the name of this routine is an abbreviation for
|
||||
** "Right-Hand Side".
|
||||
*/
|
||||
int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Conflict resolution modes
|
||||
** KEYWORDS: {conflict resolution mode}
|
||||
|
||||
@@ -344,6 +344,13 @@ struct sqlite3_api_routines {
|
||||
int (*autovacuum_pages)(sqlite3*,
|
||||
unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
|
||||
void*, void(*)(void*));
|
||||
/* Version 3.38.0 and later */
|
||||
int (*error_offset)(sqlite3*);
|
||||
int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
|
||||
int (*vtab_distinct)(sqlite3_index_info*);
|
||||
int (*vtab_in)(sqlite3_index_info*,int,int);
|
||||
int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
|
||||
int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -655,6 +662,13 @@ typedef int (*sqlite3_loadext_entry)(
|
||||
#define sqlite3_total_changes64 sqlite3_api->total_changes64
|
||||
/* Version 3.37.0 and later */
|
||||
#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
|
||||
/* Version 3.38.0 and later */
|
||||
#define sqlite3_error_offset sqlite3_api->error_offset
|
||||
#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
|
||||
#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
|
||||
#define sqlite3_vtab_in sqlite3_api->vtab_in
|
||||
#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
|
||||
#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
|
||||
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
|
||||
|
||||
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
|
||||
+56
-24
@@ -695,7 +695,7 @@
|
||||
** number of pages. A negative number N translations means that a buffer
|
||||
** of -1024*N bytes is allocated and used for as many pages as it will hold.
|
||||
**
|
||||
** The default value of "20" was choosen to minimize the run-time of the
|
||||
** The default value of "20" was chosen to minimize the run-time of the
|
||||
** speedtest1 test program with options: --shrink-memory --reprepare
|
||||
*/
|
||||
#ifndef SQLITE_DEFAULT_PCACHE_INITSZ
|
||||
@@ -1103,7 +1103,7 @@ struct BusyHandler {
|
||||
** pointer will work here as long as it is distinct from SQLITE_STATIC
|
||||
** and SQLITE_TRANSIENT.
|
||||
*/
|
||||
#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomFault)
|
||||
#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear)
|
||||
|
||||
/*
|
||||
** When SQLITE_OMIT_WSD is defined, it means that the target platform does
|
||||
@@ -1231,10 +1231,11 @@ typedef struct With With;
|
||||
/*
|
||||
** A bit in a Bitmask
|
||||
*/
|
||||
#define MASKBIT(n) (((Bitmask)1)<<(n))
|
||||
#define MASKBIT64(n) (((u64)1)<<(n))
|
||||
#define MASKBIT32(n) (((unsigned int)1)<<(n))
|
||||
#define ALLBITS ((Bitmask)-1)
|
||||
#define MASKBIT(n) (((Bitmask)1)<<(n))
|
||||
#define MASKBIT64(n) (((u64)1)<<(n))
|
||||
#define MASKBIT32(n) (((unsigned int)1)<<(n))
|
||||
#define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0)
|
||||
#define ALLBITS ((Bitmask)-1)
|
||||
|
||||
/* A VList object records a mapping between parameters/variables/wildcards
|
||||
** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
|
||||
@@ -1527,6 +1528,7 @@ struct sqlite3 {
|
||||
u32 nSchemaLock; /* Do not reset the schema when non-zero */
|
||||
unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
|
||||
int errCode; /* Most recent error code (SQLITE_*) */
|
||||
int errByteOffset; /* Byte offset of error in SQL statement */
|
||||
int errMask; /* & result codes with this before returning */
|
||||
int iSysErrno; /* Errno value from last system error */
|
||||
u32 dbOptFlags; /* Flags to enable/disable optimizations */
|
||||
@@ -1712,6 +1714,7 @@ struct sqlite3 {
|
||||
#define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */
|
||||
/* DELETE, or UPDATE and return */
|
||||
/* the count using a callback. */
|
||||
#define SQLITE_CorruptRdOnly HI(0x00002) /* Prohibit writes due to error */
|
||||
|
||||
/* Flags used only if debugging */
|
||||
#ifdef SQLITE_DEBUG
|
||||
@@ -1760,6 +1763,9 @@ struct sqlite3 {
|
||||
#define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */
|
||||
#define SQLITE_OmitOrderBy 0x00040000 /* Omit pointless ORDER BY */
|
||||
/* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */
|
||||
#define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
|
||||
#define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
|
||||
#define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
|
||||
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
|
||||
|
||||
/*
|
||||
@@ -1933,7 +1939,7 @@ struct FuncDestructor {
|
||||
** are interpreted in the same way as the first 4 parameters to
|
||||
** FUNCTION().
|
||||
**
|
||||
** WFUNCTION(zName, nArg, iArg, xStep, xFinal, xValue, xInverse)
|
||||
** WAGGREGATE(zName, nArg, iArg, xStep, xFinal, xValue, xInverse)
|
||||
** Used to create an aggregate function definition implemented by
|
||||
** the C functions xStep and xFinal. The first four parameters
|
||||
** are interpreted in the same way as the first 4 parameters to
|
||||
@@ -1960,6 +1966,10 @@ struct FuncDestructor {
|
||||
#define MFUNCTION(zName, nArg, xPtr, xFunc) \
|
||||
{nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
|
||||
xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
|
||||
#define JFUNCTION(zName, nArg, iArg, xFunc) \
|
||||
{nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|\
|
||||
SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
|
||||
#define INLINE_FUNC(zName, nArg, iArg, mFlags) \
|
||||
{nArg, SQLITE_FUNC_BUILTIN|\
|
||||
SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
|
||||
@@ -2507,6 +2517,11 @@ struct KeyInfo {
|
||||
struct UnpackedRecord {
|
||||
KeyInfo *pKeyInfo; /* Collation and sort-order information */
|
||||
Mem *aMem; /* Values */
|
||||
union {
|
||||
char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
|
||||
i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
|
||||
} u;
|
||||
int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
|
||||
u16 nField; /* Number of entries in apMem[] */
|
||||
i8 default_rc; /* Comparison result if keys are equal */
|
||||
u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */
|
||||
@@ -2814,7 +2829,10 @@ struct Expr {
|
||||
** TK_VARIABLE: variable number (always >= 1).
|
||||
** TK_SELECT_COLUMN: column of the result vector */
|
||||
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
|
||||
int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
|
||||
union {
|
||||
int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
|
||||
int iOfst; /* else: start of token from start of statement */
|
||||
} w;
|
||||
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
|
||||
union {
|
||||
Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
|
||||
@@ -3554,7 +3572,8 @@ struct Parse {
|
||||
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
|
||||
Parse *pToplevel; /* Parse structure for main program (or NULL) */
|
||||
Table *pTriggerTab; /* Table triggers are being coded for */
|
||||
Parse *pParentParse; /* Parent parser if this parser is nested */
|
||||
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
|
||||
ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
|
||||
union {
|
||||
int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */
|
||||
Returning *pReturning; /* The RETURNING clause */
|
||||
@@ -3575,6 +3594,7 @@ struct Parse {
|
||||
**************************************************************************/
|
||||
|
||||
int aTempReg[8]; /* Holding area for temporary registers */
|
||||
Parse *pOuterParse; /* Outer Parse object when nested */
|
||||
Token sNameToken; /* Token with unqualified schema object name */
|
||||
|
||||
/************************************************************************
|
||||
@@ -3609,9 +3629,7 @@ struct Parse {
|
||||
Token sArg; /* Complete text of a module argument */
|
||||
Table **apVtabLock; /* Pointer to virtual tables needing locking */
|
||||
#endif
|
||||
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
|
||||
With *pWith; /* Current WITH clause, or NULL */
|
||||
ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
|
||||
#ifndef SQLITE_OMIT_ALTERTABLE
|
||||
RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */
|
||||
#endif
|
||||
@@ -3627,7 +3645,8 @@ struct Parse {
|
||||
/*
|
||||
** Sizes and pointers of various parts of the Parse object.
|
||||
*/
|
||||
#define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
|
||||
#define PARSE_HDR(X) (((char*)(X))+offsetof(Parse,zErrMsg))
|
||||
#define PARSE_HDR_SZ (offsetof(Parse,aTempReg)-offsetof(Parse,zErrMsg)) /* Recursive part w/o aColCache*/
|
||||
#define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
|
||||
#define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
|
||||
#define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
|
||||
@@ -3922,6 +3941,7 @@ struct Sqlite3Config {
|
||||
int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
|
||||
#endif
|
||||
int bLocaltimeFault; /* True to fail localtime() calls */
|
||||
int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */
|
||||
int iOnceResetThreshold; /* When to reset OP_Once counters */
|
||||
u32 szSorterRef; /* Min size in bytes to use sorter-refs */
|
||||
unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
|
||||
@@ -4126,7 +4146,7 @@ struct Window {
|
||||
Window **ppThis; /* Pointer to this object in Select.pWin list */
|
||||
Window *pNextWin; /* Next window function belonging to this SELECT */
|
||||
Expr *pFilter; /* The FILTER expression */
|
||||
FuncDef *pFunc; /* The function */
|
||||
FuncDef *pWFunc; /* The function */
|
||||
int iEphCsr; /* Partition buffer or Peer buffer */
|
||||
int regAccum; /* Accumulator */
|
||||
int regResult; /* Interim result */
|
||||
@@ -4402,7 +4422,7 @@ void sqlite3DequoteExpr(Expr*);
|
||||
void sqlite3DequoteToken(Token*);
|
||||
void sqlite3TokenInit(Token*,char*);
|
||||
int sqlite3KeywordCode(const unsigned char*, int);
|
||||
int sqlite3RunParser(Parse*, const char*, char **);
|
||||
int sqlite3RunParser(Parse*, const char*);
|
||||
void sqlite3FinishCoding(Parse*);
|
||||
int sqlite3GetTempReg(Parse*);
|
||||
void sqlite3ReleaseTempReg(Parse*,int);
|
||||
@@ -4563,10 +4583,12 @@ void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
|
||||
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
|
||||
Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
|
||||
#endif
|
||||
void sqlite3CodeChangeCount(Vdbe*,int,const char*);
|
||||
void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*);
|
||||
void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*,
|
||||
Upsert*);
|
||||
WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
|
||||
WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,
|
||||
ExprList*,Select*,u16,int);
|
||||
void sqlite3WhereEnd(WhereInfo*);
|
||||
LogEst sqlite3WhereOutputRowCount(WhereInfo*);
|
||||
int sqlite3WhereIsDistinct(WhereInfo*);
|
||||
@@ -4681,9 +4703,14 @@ Select *sqlite3SelectDup(sqlite3*,const Select*,int);
|
||||
FuncDef *sqlite3FunctionSearch(int,const char*);
|
||||
void sqlite3InsertBuiltinFuncs(FuncDef*,int);
|
||||
FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8);
|
||||
void sqlite3QuoteValue(StrAccum*,sqlite3_value*);
|
||||
void sqlite3RegisterBuiltinFunctions(void);
|
||||
void sqlite3RegisterDateTimeFunctions(void);
|
||||
void sqlite3RegisterJsonFunctions(void);
|
||||
void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*);
|
||||
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON)
|
||||
int sqlite3JsonTableFunctions(sqlite3*);
|
||||
#endif
|
||||
int sqlite3SafetyCheckOk(sqlite3*);
|
||||
int sqlite3SafetyCheckSickOrOk(sqlite3*);
|
||||
void sqlite3ChangeCookie(Parse*, int);
|
||||
@@ -4773,14 +4800,8 @@ int sqlite3Utf8CharLen(const char *pData, int nByte);
|
||||
u32 sqlite3Utf8Read(const u8**);
|
||||
LogEst sqlite3LogEst(u64);
|
||||
LogEst sqlite3LogEstAdd(LogEst,LogEst);
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
LogEst sqlite3LogEstFromDouble(double);
|
||||
#endif
|
||||
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \
|
||||
defined(SQLITE_ENABLE_STAT4) || \
|
||||
defined(SQLITE_EXPLAIN_ESTIMATED_ROWS)
|
||||
u64 sqlite3LogEstToInt(LogEst);
|
||||
#endif
|
||||
VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int);
|
||||
const char *sqlite3VListNumToName(VList*,int);
|
||||
int sqlite3VListNameToNum(VList*,const char*,int);
|
||||
@@ -4967,17 +4988,20 @@ int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
|
||||
FuncDestructor *pDestructor
|
||||
);
|
||||
void sqlite3NoopDestructor(void*);
|
||||
void sqlite3OomFault(sqlite3*);
|
||||
void *sqlite3OomFault(sqlite3*);
|
||||
void sqlite3OomClear(sqlite3*);
|
||||
int sqlite3ApiExit(sqlite3 *db, int);
|
||||
int sqlite3OpenTempDatabase(Parse *);
|
||||
|
||||
void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
|
||||
int sqlite3StrAccumEnlarge(StrAccum*, int);
|
||||
char *sqlite3StrAccumFinish(StrAccum*);
|
||||
void sqlite3StrAccumSetError(StrAccum*, u8);
|
||||
void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*);
|
||||
void sqlite3SelectDestInit(SelectDest*,int,int);
|
||||
Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
|
||||
void sqlite3RecordErrorByteOffset(sqlite3*,const char*);
|
||||
void sqlite3RecordErrorOffsetOfExpr(sqlite3*,const Expr*);
|
||||
|
||||
void sqlite3BackupRestart(sqlite3_backup *);
|
||||
void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
|
||||
@@ -5082,11 +5106,17 @@ int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
|
||||
int sqlite3VtabCallConnect(Parse*, Table*);
|
||||
int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
|
||||
int sqlite3VtabBegin(sqlite3 *, VTable *);
|
||||
|
||||
FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
|
||||
#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \
|
||||
&& !defined(SQLITE_OMIT_VIRTUALTABLE)
|
||||
void sqlite3VtabWriteAll(sqlite3_index_info*);
|
||||
#endif
|
||||
sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
|
||||
int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
|
||||
int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
|
||||
void sqlite3ParserReset(Parse*);
|
||||
void sqlite3ParseObjectInit(Parse*,sqlite3*);
|
||||
void sqlite3ParseObjectReset(Parse*);
|
||||
void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*);
|
||||
#ifdef SQLITE_ENABLE_NORMALIZE
|
||||
char *sqlite3Normalize(Vdbe*, const char*);
|
||||
@@ -5112,7 +5142,7 @@ const char *sqlite3JournalModename(int);
|
||||
# define sqlite3CteDelete(D,C)
|
||||
# define sqlite3CteWithAdd(P,W,C) ((void*)0)
|
||||
# define sqlite3WithDelete(x,y)
|
||||
# define sqlite3WithPush(x,y,z)
|
||||
# define sqlite3WithPush(x,y,z) ((void*)0)
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_UPSERT
|
||||
Upsert *sqlite3UpsertNew(sqlite3*,ExprList*,Expr*,ExprList*,Expr*,Upsert*);
|
||||
@@ -5145,6 +5175,7 @@ const char *sqlite3JournalModename(int);
|
||||
int sqlite3FkRequired(Parse*, Table*, int*, int);
|
||||
u32 sqlite3FkOldmask(Parse*, Table*);
|
||||
FKey *sqlite3FkReferences(Table *);
|
||||
void sqlite3FkClearTriggerCache(sqlite3*,int);
|
||||
#else
|
||||
#define sqlite3FkActions(a,b,c,d,e,f)
|
||||
#define sqlite3FkCheck(a,b,c,d,e,f)
|
||||
@@ -5152,6 +5183,7 @@ const char *sqlite3JournalModename(int);
|
||||
#define sqlite3FkOldmask(a,b) 0
|
||||
#define sqlite3FkRequired(a,b,c,d) 0
|
||||
#define sqlite3FkReferences(a) 0
|
||||
#define sqlite3FkClearTriggerCache(a,b)
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_FOREIGN_KEY
|
||||
void sqlite3FkDelete(sqlite3 *, Table*);
|
||||
|
||||
+36
-20
@@ -1943,15 +1943,16 @@ static int SQLITE_TCLAPI DbObjCmd(
|
||||
"close", "collate", "collation_needed",
|
||||
"commit_hook", "complete", "config",
|
||||
"copy", "deserialize", "enable_load_extension",
|
||||
"errorcode", "eval", "exists",
|
||||
"function", "incrblob", "interrupt",
|
||||
"last_insert_rowid", "nullvalue", "onecolumn",
|
||||
"preupdate", "profile", "progress",
|
||||
"rekey", "restore", "rollback_hook",
|
||||
"serialize", "status", "timeout",
|
||||
"total_changes", "trace", "trace_v2",
|
||||
"transaction", "unlock_notify", "update_hook",
|
||||
"version", "wal_hook", 0
|
||||
"errorcode", "erroroffset", "eval",
|
||||
"exists", "function", "incrblob",
|
||||
"interrupt", "last_insert_rowid", "nullvalue",
|
||||
"onecolumn", "preupdate", "profile",
|
||||
"progress", "rekey", "restore",
|
||||
"rollback_hook", "serialize", "status",
|
||||
"timeout", "total_changes", "trace",
|
||||
"trace_v2", "transaction", "unlock_notify",
|
||||
"update_hook", "version", "wal_hook",
|
||||
0
|
||||
};
|
||||
enum DB_enum {
|
||||
DB_AUTHORIZER, DB_BACKUP, DB_BIND_FALLBACK,
|
||||
@@ -1959,15 +1960,15 @@ static int SQLITE_TCLAPI DbObjCmd(
|
||||
DB_CLOSE, DB_COLLATE, DB_COLLATION_NEEDED,
|
||||
DB_COMMIT_HOOK, DB_COMPLETE, DB_CONFIG,
|
||||
DB_COPY, DB_DESERIALIZE, DB_ENABLE_LOAD_EXTENSION,
|
||||
DB_ERRORCODE, DB_EVAL, DB_EXISTS,
|
||||
DB_FUNCTION, DB_INCRBLOB, DB_INTERRUPT,
|
||||
DB_LAST_INSERT_ROWID, DB_NULLVALUE, DB_ONECOLUMN,
|
||||
DB_PREUPDATE, DB_PROFILE, DB_PROGRESS,
|
||||
DB_REKEY, DB_RESTORE, DB_ROLLBACK_HOOK,
|
||||
DB_SERIALIZE, DB_STATUS, DB_TIMEOUT,
|
||||
DB_TOTAL_CHANGES, DB_TRACE, DB_TRACE_V2,
|
||||
DB_TRANSACTION, DB_UNLOCK_NOTIFY, DB_UPDATE_HOOK,
|
||||
DB_VERSION, DB_WAL_HOOK
|
||||
DB_ERRORCODE, DB_ERROROFFSET, DB_EVAL,
|
||||
DB_EXISTS, DB_FUNCTION, DB_INCRBLOB,
|
||||
DB_INTERRUPT, DB_LAST_INSERT_ROWID, DB_NULLVALUE,
|
||||
DB_ONECOLUMN, DB_PREUPDATE, DB_PROFILE,
|
||||
DB_PROGRESS, DB_REKEY, DB_RESTORE,
|
||||
DB_ROLLBACK_HOOK, DB_SERIALIZE, DB_STATUS,
|
||||
DB_TIMEOUT, DB_TOTAL_CHANGES, DB_TRACE,
|
||||
DB_TRACE_V2, DB_TRANSACTION, DB_UNLOCK_NOTIFY,
|
||||
DB_UPDATE_HOOK, DB_VERSION, DB_WAL_HOOK,
|
||||
};
|
||||
/* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
|
||||
|
||||
@@ -2647,8 +2648,10 @@ static int SQLITE_TCLAPI DbObjCmd(
|
||||
for(i=2; i<objc-1; i++){
|
||||
const char *z = Tcl_GetString(objv[i]);
|
||||
if( strcmp(z,"-maxsize")==0 && i<objc-2 ){
|
||||
rc = Tcl_GetWideIntFromObj(interp, objv[++i], &mxSize);
|
||||
Tcl_WideInt x;
|
||||
rc = Tcl_GetWideIntFromObj(interp, objv[++i], &x);
|
||||
if( rc ) goto deserialize_error;
|
||||
mxSize = x;
|
||||
continue;
|
||||
}
|
||||
if( strcmp(z,"-readonly")==0 && i<objc-2 ){
|
||||
@@ -2728,6 +2731,17 @@ deserialize_error:
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** $db erroroffset
|
||||
**
|
||||
** Return the numeric error code that was returned by the most recent
|
||||
** call to sqlite3_exec().
|
||||
*/
|
||||
case DB_ERROROFFSET: {
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_error_offset(pDb->db)));
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** $db exists $sql
|
||||
** $db onecolumn $sql
|
||||
@@ -3975,7 +3989,9 @@ static const char *tclsh_main_loop(void){
|
||||
return zMainloop;
|
||||
}
|
||||
|
||||
#define TCLSH_MAIN main /* Needed to fake out mktclapp */
|
||||
#ifndef TCLSH_MAIN
|
||||
# define TCLSH_MAIN main
|
||||
#endif
|
||||
int SQLITE_CDECL TCLSH_MAIN(int argc, char **argv){
|
||||
Tcl_Interp *interp;
|
||||
int i;
|
||||
|
||||
+183
-4
@@ -1097,7 +1097,7 @@ static int SQLITE_TCLAPI test_drop_modules(
|
||||
){
|
||||
sqlite3 *db;
|
||||
|
||||
if( argc!=2 ){
|
||||
if( argc<2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" DB\"", 0);
|
||||
return TCL_ERROR;
|
||||
@@ -3977,6 +3977,102 @@ static int SQLITE_TCLAPI test_bind_blob(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_bind_value_from_preupdate STMT N NEW|OLD IDX
|
||||
**
|
||||
** Test the sqlite3_bind_value interface using sqlite3_value objects
|
||||
** obtained from either sqlite3_preupdate_new() (if arg[3]=="new") or
|
||||
** sqlite3_preupdate_old() if (arg[3]=="old"). IDX is the index to
|
||||
** pass to the sqlite3_preupdate_xxx() function.
|
||||
*/
|
||||
static int SQLITE_TCLAPI test_bind_value_from_preupdate(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3_stmt *pStmt;
|
||||
int idx;
|
||||
int bidx;
|
||||
const char *z3 = 0;
|
||||
sqlite3 *db = 0;
|
||||
sqlite3_value *pVal = 0;
|
||||
|
||||
if( objc!=5 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "STMT N NEW|OLD IDX");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
||||
z3 = Tcl_GetString(objv[3]);
|
||||
if( Tcl_GetIntFromObj(interp, objv[4], &bidx) ) return TCL_ERROR;
|
||||
db = sqlite3_db_handle(pStmt);
|
||||
|
||||
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
if( z3[0]=='n' ){
|
||||
sqlite3_preupdate_new(db, bidx, &pVal);
|
||||
}else if( z3[0]=='o' ){
|
||||
sqlite3_preupdate_old(db, bidx, &pVal);
|
||||
}else{
|
||||
Tcl_AppendResult(interp, "expected new or old, got: ", z3, (char*)0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sqlite3_bind_value(pStmt, idx, pVal);
|
||||
#endif
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_bind_value_from_select STMT N SELECT
|
||||
**
|
||||
** Test the sqlite3_bind_value interface. STMT is a prepared statement.
|
||||
** N is the index of a wildcard in the prepared statement.
|
||||
*/
|
||||
static int SQLITE_TCLAPI test_bind_value_from_select(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3_stmt *pStmt;
|
||||
sqlite3_stmt *pStmt2;
|
||||
int idx;
|
||||
const char *zSql = 0;
|
||||
sqlite3 *db = 0;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
if( objc!=4 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "STMT N SELECT");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
||||
zSql = Tcl_GetString(objv[3]);
|
||||
db = sqlite3_db_handle(pStmt);
|
||||
|
||||
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt2, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, "error in SQL: ", sqlite3_errmsg(db), (char*)0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( sqlite3_step(pStmt2)==SQLITE_ROW ){
|
||||
sqlite3_value *pVal = sqlite3_column_value(pStmt2, 0);
|
||||
sqlite3_bind_value(pStmt, idx, pVal);
|
||||
}
|
||||
rc = sqlite3_finalize(pStmt2);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp,
|
||||
"error runnning SQL: ", sqlite3_errmsg(db), (char*)0
|
||||
);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
/*
|
||||
@@ -4366,6 +4462,34 @@ static int SQLITE_TCLAPI test_errmsg(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_error_offset DB
|
||||
**
|
||||
** Return the byte offset into the input UTF8 SQL for the most recent
|
||||
** error, or -1 of the error does not refer to a specific token.
|
||||
*/
|
||||
static int SQLITE_TCLAPI test_error_offset(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3 *db;
|
||||
int iByteOffset;
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetString(objv[0]), " DB", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
|
||||
iByteOffset = sqlite3_error_offset(db);
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(iByteOffset));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: test_errmsg16 DB
|
||||
**
|
||||
@@ -7083,6 +7207,55 @@ static int SQLITE_TCLAPI test_print_eqp(
|
||||
}
|
||||
#endif /* SQLITE_OMIT_EXPLAIN */
|
||||
|
||||
#include <time.h>
|
||||
/*
|
||||
** This is an alternative localtime_r() implementation used for testing
|
||||
** the 'localtime' and 'utc' modifiers of date-time functions. Because
|
||||
** the OS-supplied localtime_r() is locale-dependent, this alternative is
|
||||
** provided as a stable test platform.
|
||||
**
|
||||
** Operation:
|
||||
**
|
||||
** (1) Localtime is 30 minutes earlier than (west of) UTC on
|
||||
** even days (counting from 1970-01-01)
|
||||
**
|
||||
** (2) Localtime is 30 minutes later than (east of) UTC on odd days.
|
||||
**
|
||||
** (3) The function fails for the specific date/time value
|
||||
** of 2000-05-29 14:16:00 in order to test the ability of
|
||||
** SQLite to deal with localtime_r() failures.
|
||||
*/
|
||||
static int testLocaltime(const void *aliasT, void *aliasTM){
|
||||
const time_t t = *(const time_t*)aliasT;
|
||||
struct tm *pTm = (struct tm *)aliasTM;
|
||||
time_t altT;
|
||||
sqlite3_int64 iJD;
|
||||
int Z, A, B, C, D, E, X1, S;
|
||||
|
||||
if( (t/86400) & 1 ){
|
||||
altT = t + 1800; /* 30 minutes later on odd days */
|
||||
}else{
|
||||
altT = t - 1800; /* 30 minutes earlier on even days */
|
||||
}
|
||||
iJD = (sqlite3_int64)(altT + 210866760000);
|
||||
Z = (int)((iJD + 43200)/86400);
|
||||
A = (int)((Z - 1867216.25)/36524.25);
|
||||
A = Z + 1 + A - (A/4);
|
||||
B = A + 1524;
|
||||
C = (int)((B - 122.1)/365.25);
|
||||
D = (36525*(C&32767))/100;
|
||||
E = (int)((B-D)/30.6001);
|
||||
X1 = (int)(30.6001*E);
|
||||
pTm->tm_mday = B - D - X1;
|
||||
pTm->tm_mon = E<14 ? E-2 : E-14;
|
||||
pTm->tm_year = (pTm->tm_mon>1 ? C - 4716 : C - 4715) - 1900;
|
||||
S = (int)((iJD + 43200)%86400);
|
||||
pTm->tm_hour = S/3600;
|
||||
pTm->tm_min = (S/60)%60;
|
||||
pTm->tm_sec = S % 60;
|
||||
return t==959609760; /* Special case: 2000-05-29 14:16:00 fails */
|
||||
}
|
||||
|
||||
/*
|
||||
** sqlite3_test_control VERB ARGS...
|
||||
*/
|
||||
@@ -7130,11 +7303,11 @@ static int SQLITE_TCLAPI test_test_control(
|
||||
case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
|
||||
int val;
|
||||
if( objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "ONOFF");
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "0|1|2");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR;
|
||||
sqlite3_test_control(iFlag, val);
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &val) ) return TCL_ERROR;
|
||||
sqlite3_test_control(iFlag, val, testLocaltime);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -7484,6 +7657,7 @@ static int SQLITE_TCLAPI optimization_control(
|
||||
{ "stat4", SQLITE_Stat4 },
|
||||
{ "skip-scan", SQLITE_SkipScan },
|
||||
{ "push-down", SQLITE_PushDown },
|
||||
{ "balanced-merge", SQLITE_BalancedMerge },
|
||||
};
|
||||
|
||||
if( objc!=4 ){
|
||||
@@ -7539,6 +7713,7 @@ static int SQLITE_TCLAPI tclLoadStaticExtensionCmd(
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
extern int sqlite3_prefixes_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
#endif
|
||||
extern int sqlite3_qpvtab_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
extern int sqlite3_regexp_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
extern int sqlite3_remember_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
extern int sqlite3_series_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
@@ -7569,6 +7744,7 @@ static int SQLITE_TCLAPI tclLoadStaticExtensionCmd(
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
{ "prefixes", sqlite3_prefixes_init },
|
||||
#endif
|
||||
{ "qpvtab", sqlite3_qpvtab_init },
|
||||
{ "regexp", sqlite3_regexp_init },
|
||||
{ "remember", sqlite3_remember_init },
|
||||
{ "series", sqlite3_series_init },
|
||||
@@ -8411,6 +8587,8 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
{ "sqlite3_bind_text", test_bind_text ,0 },
|
||||
{ "sqlite3_bind_text16", test_bind_text16 ,0 },
|
||||
{ "sqlite3_bind_blob", test_bind_blob ,0 },
|
||||
{ "sqlite3_bind_value_from_select",test_bind_value_from_select ,0 },
|
||||
{ "sqlite3_bind_value_from_preupdate",test_bind_value_from_preupdate ,0 },
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
{ "sqlite3_carray_bind", test_carray_bind ,0 },
|
||||
#endif
|
||||
@@ -8422,6 +8600,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
{ "sqlite3_errcode", test_errcode ,0 },
|
||||
{ "sqlite3_extended_errcode", test_ex_errcode ,0 },
|
||||
{ "sqlite3_errmsg", test_errmsg ,0 },
|
||||
{ "sqlite3_error_offset", test_error_offset ,0 },
|
||||
{ "sqlite3_errmsg16", test_errmsg16 ,0 },
|
||||
{ "sqlite3_open", test_open ,0 },
|
||||
{ "sqlite3_open16", test_open16 ,0 },
|
||||
|
||||
+173
-22
@@ -299,7 +299,21 @@ static int tclFilter(
|
||||
const char *zVal = (const char*)sqlite3_value_text(argv[ii]);
|
||||
Tcl_Obj *pVal;
|
||||
if( zVal==0 ){
|
||||
sqlite3_value *pMem;
|
||||
pVal = Tcl_NewObj();
|
||||
for(rc=sqlite3_vtab_in_first(argv[ii], &pMem);
|
||||
rc==SQLITE_OK && pMem;
|
||||
rc=sqlite3_vtab_in_next(argv[ii], &pMem)
|
||||
){
|
||||
Tcl_Obj *pVal2 = 0;
|
||||
zVal = (const char*)sqlite3_value_text(pMem);
|
||||
if( zVal ){
|
||||
pVal2 = Tcl_NewStringObj(zVal, -1);
|
||||
}else{
|
||||
pVal2 = Tcl_NewObj();
|
||||
}
|
||||
Tcl_ListObjAppendElement(interp, pVal, pVal2);
|
||||
}
|
||||
}else{
|
||||
pVal = Tcl_NewStringObj(zVal, -1);
|
||||
}
|
||||
@@ -374,20 +388,13 @@ static int tclEof(sqlite3_vtab_cursor *pVtabCursor){
|
||||
return (pCsr->pStmt==0);
|
||||
}
|
||||
|
||||
static int tclBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
tcl_vtab *pTab = (tcl_vtab*)tab;
|
||||
Tcl_Interp *interp = pTab->interp;
|
||||
Tcl_Obj *pArg;
|
||||
Tcl_Obj *pScript;
|
||||
static void testBestIndexObjConstraints(
|
||||
Tcl_Interp *interp,
|
||||
sqlite3_index_info *pIdxInfo
|
||||
){
|
||||
int ii;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
pScript = Tcl_DuplicateObj(pTab->pCmd);
|
||||
Tcl_IncrRefCount(pScript);
|
||||
Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj("xBestIndex", -1));
|
||||
|
||||
pArg = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pArg);
|
||||
Tcl_Obj *pRes = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pRes);
|
||||
for(ii=0; ii<pIdxInfo->nConstraint; ii++){
|
||||
struct sqlite3_index_constraint const *pCons = &pIdxInfo->aConstraint[ii];
|
||||
Tcl_Obj *pElem = Tcl_NewObj();
|
||||
@@ -424,6 +431,10 @@ static int tclBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
zOp = "isnull"; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_IS:
|
||||
zOp = "is"; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_LIMIT:
|
||||
zOp = "limit"; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_OFFSET:
|
||||
zOp = "offset"; break;
|
||||
}
|
||||
|
||||
Tcl_ListObjAppendElement(0, pElem, Tcl_NewStringObj("op", -1));
|
||||
@@ -433,15 +444,21 @@ static int tclBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
Tcl_ListObjAppendElement(0, pElem, Tcl_NewStringObj("usable", -1));
|
||||
Tcl_ListObjAppendElement(0, pElem, Tcl_NewIntObj(pCons->usable));
|
||||
|
||||
Tcl_ListObjAppendElement(0, pArg, pElem);
|
||||
Tcl_ListObjAppendElement(0, pRes, pElem);
|
||||
Tcl_DecrRefCount(pElem);
|
||||
}
|
||||
|
||||
Tcl_ListObjAppendElement(0, pScript, pArg);
|
||||
Tcl_DecrRefCount(pArg);
|
||||
Tcl_SetObjResult(interp, pRes);
|
||||
Tcl_DecrRefCount(pRes);
|
||||
}
|
||||
|
||||
pArg = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pArg);
|
||||
static void testBestIndexObjOrderby(
|
||||
Tcl_Interp *interp,
|
||||
sqlite3_index_info *pIdxInfo
|
||||
){
|
||||
int ii;
|
||||
Tcl_Obj *pRes = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pRes);
|
||||
for(ii=0; ii<pIdxInfo->nOrderBy; ii++){
|
||||
struct sqlite3_index_orderby const *pOrder = &pIdxInfo->aOrderBy[ii];
|
||||
Tcl_Obj *pElem = Tcl_NewObj();
|
||||
@@ -452,17 +469,150 @@ static int tclBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
Tcl_ListObjAppendElement(0, pElem, Tcl_NewStringObj("desc", -1));
|
||||
Tcl_ListObjAppendElement(0, pElem, Tcl_NewIntObj(pOrder->desc));
|
||||
|
||||
Tcl_ListObjAppendElement(0, pArg, pElem);
|
||||
Tcl_ListObjAppendElement(0, pRes, pElem);
|
||||
Tcl_DecrRefCount(pElem);
|
||||
}
|
||||
|
||||
Tcl_ListObjAppendElement(0, pScript, pArg);
|
||||
Tcl_DecrRefCount(pArg);
|
||||
Tcl_SetObjResult(interp, pRes);
|
||||
Tcl_DecrRefCount(pRes);
|
||||
}
|
||||
|
||||
Tcl_ListObjAppendElement(0, pScript, Tcl_NewWideIntObj(pIdxInfo->colUsed));
|
||||
/*
|
||||
** Implementation of the handle passed to each xBestIndex callback. This
|
||||
** object features the following sub-commands:
|
||||
**
|
||||
** $hdl constraints
|
||||
** $hdl orderby
|
||||
** $hdl mask
|
||||
**
|
||||
** $hdl distinct
|
||||
** Return the result (an integer) of calling sqlite3_vtab_distinct()
|
||||
** on the index-info structure.
|
||||
**
|
||||
** $hdl in IDX BOOLEAN
|
||||
** Wrapper around sqlite3_vtab_in(). Returns an integer.
|
||||
**
|
||||
** $hdl rhs_value IDX ?DEFAULT?
|
||||
** Wrapper around sqlite3_vtab_rhs_value().
|
||||
*/
|
||||
static int SQLITE_TCLAPI testBestIndexObj(
|
||||
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int objc, /* Number of arguments */
|
||||
Tcl_Obj *CONST objv[] /* Command arguments */
|
||||
){
|
||||
const char *azSub[] = {
|
||||
"constraints", /* 0 */
|
||||
"orderby", /* 1 */
|
||||
"mask", /* 2 */
|
||||
"distinct", /* 3 */
|
||||
"in", /* 4 */
|
||||
"rhs_value", /* 5 */
|
||||
0
|
||||
};
|
||||
int ii;
|
||||
sqlite3_index_info *pIdxInfo = (sqlite3_index_info*)clientData;
|
||||
|
||||
if( objc<2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "SUB-COMMAND");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetIndexFromObj(interp, objv[1], azSub, "sub-command", 0, &ii) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if( ii<4 && objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( ii==4 && objc!=4 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "INDEX BOOLEAN");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( ii==5 && objc!=3 && objc!=4 ){
|
||||
Tcl_WrongNumArgs(interp, 2, objv, "INDEX ?DEFAULT?");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
switch( ii ){
|
||||
case 0: assert( sqlite3_stricmp(azSub[ii], "constraints")==0 );
|
||||
testBestIndexObjConstraints(interp, pIdxInfo);
|
||||
break;
|
||||
|
||||
case 1: assert( sqlite3_stricmp(azSub[ii], "orderby")==0 );
|
||||
testBestIndexObjOrderby(interp, pIdxInfo);
|
||||
break;
|
||||
|
||||
case 2: assert( sqlite3_stricmp(azSub[ii], "mask")==0 );
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(pIdxInfo->colUsed));
|
||||
break;
|
||||
|
||||
case 3: assert( sqlite3_stricmp(azSub[ii], "distinct")==0 ); {
|
||||
int bDistinct = sqlite3_vtab_distinct(pIdxInfo);
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(bDistinct));
|
||||
break;
|
||||
}
|
||||
|
||||
case 4: assert( sqlite3_stricmp(azSub[ii], "in")==0 ); {
|
||||
int iCons;
|
||||
int bHandle;
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &iCons)
|
||||
|| Tcl_GetBooleanFromObj(interp, objv[3], &bHandle)
|
||||
){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
Tcl_SetObjResult(interp,
|
||||
Tcl_NewIntObj(sqlite3_vtab_in(pIdxInfo, iCons, bHandle))
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case 5: assert( sqlite3_stricmp(azSub[ii], "rhs_value")==0 ); {
|
||||
int iCons = 0;
|
||||
int rc;
|
||||
sqlite3_value *pVal = 0;
|
||||
const char *zVal = "";
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &iCons) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqlite3_vtab_rhs_value(pIdxInfo, iCons, &pVal);
|
||||
if( rc!=SQLITE_OK && rc!=SQLITE_NOTFOUND ){
|
||||
Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( pVal ){
|
||||
zVal = (const char*)sqlite3_value_text(pVal);
|
||||
}else if( objc==4 ){
|
||||
zVal = Tcl_GetString(objv[3]);
|
||||
}
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj(zVal, -1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
static int tclBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
tcl_vtab *pTab = (tcl_vtab*)tab;
|
||||
Tcl_Interp *interp = pTab->interp;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
static int iNext = 43;
|
||||
char zHdl[24];
|
||||
Tcl_Obj *pScript;
|
||||
|
||||
pScript = Tcl_DuplicateObj(pTab->pCmd);
|
||||
Tcl_IncrRefCount(pScript);
|
||||
Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj("xBestIndex", -1));
|
||||
|
||||
sqlite3_snprintf(sizeof(zHdl), zHdl, "bestindex%d", iNext++);
|
||||
Tcl_CreateObjCommand(interp, zHdl, testBestIndexObj, pIdxInfo, 0);
|
||||
Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj(zHdl, -1));
|
||||
rc = Tcl_EvalObjEx(interp, pScript, TCL_EVAL_GLOBAL);
|
||||
Tcl_DeleteCommand(interp, zHdl);
|
||||
Tcl_DecrRefCount(pScript);
|
||||
|
||||
if( rc!=TCL_OK ){
|
||||
const char *zErr = Tcl_GetStringResult(interp);
|
||||
rc = SQLITE_ERROR;
|
||||
@@ -489,6 +639,7 @@ static int tclBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
rc = SQLITE_ERROR;
|
||||
pTab->base.zErrMsg = sqlite3_mprintf("%s", zErr);
|
||||
}else{
|
||||
int ii;
|
||||
int iArgv = 1;
|
||||
for(ii=0; rc==SQLITE_OK && ii<nElem; ii+=2){
|
||||
const char *zCmd = Tcl_GetString(apElem[ii]);
|
||||
|
||||
+1
-1
@@ -239,7 +239,7 @@ static void set_options(Tcl_Interp *interp){
|
||||
Tcl_SetVar2(interp, "sqlite_options", "geopoly", "0", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_ENABLE_JSON1
|
||||
#ifndef SQLITE_OMIT_JSON
|
||||
Tcl_SetVar2(interp, "sqlite_options", "json1", "1", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
Tcl_SetVar2(interp, "sqlite_options", "json1", "0", TCL_GLOBAL_ONLY);
|
||||
|
||||
+4
-2
@@ -499,7 +499,8 @@ static void test_extract(
|
||||
mem.db = db;
|
||||
mem.enc = ENC(db);
|
||||
pHdr += sqlite3GetVarint(pHdr, &iSerialType);
|
||||
pBody += sqlite3VdbeSerialGet(pBody, (u32)iSerialType, &mem);
|
||||
sqlite3VdbeSerialGet(pBody, (u32)iSerialType, &mem);
|
||||
pBody += sqlite3VdbeSerialTypeLen((u32)iSerialType);
|
||||
|
||||
if( iCurrent==iIdx ){
|
||||
sqlite3_result_value(context, &mem);
|
||||
@@ -547,7 +548,8 @@ static void test_decode(
|
||||
mem.db = db;
|
||||
mem.enc = ENC(db);
|
||||
pHdr += sqlite3GetVarint(pHdr, &iSerialType);
|
||||
pBody += sqlite3VdbeSerialGet(pBody, (u32)iSerialType, &mem);
|
||||
sqlite3VdbeSerialGet(pBody, (u32)iSerialType, &mem);
|
||||
pBody += sqlite3VdbeSerialTypeLen((u32)iSerialType);
|
||||
|
||||
switch( sqlite3_value_type(&mem) ){
|
||||
case SQLITE_TEXT:
|
||||
|
||||
+20
-33
@@ -290,6 +290,9 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){
|
||||
for(i=2; (c=z[i])!=0 && c!='\n'; i++){}
|
||||
*tokenType = TK_SPACE; /* IMP: R-22934-25134 */
|
||||
return i;
|
||||
}else if( z[1]=='>' ){
|
||||
*tokenType = TK_PTR;
|
||||
return 2 + (z[2]=='>');
|
||||
}
|
||||
*tokenType = TK_MINUS;
|
||||
return 1;
|
||||
@@ -559,13 +562,9 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){
|
||||
}
|
||||
|
||||
/*
|
||||
** Run the parser on the given SQL string. The parser structure is
|
||||
** passed in. An SQLITE_ status code is returned. If an error occurs
|
||||
** then an and attempt is made to write an error message into
|
||||
** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that
|
||||
** error message.
|
||||
** Run the parser on the given SQL string.
|
||||
*/
|
||||
int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
int sqlite3RunParser(Parse *pParse, const char *zSql){
|
||||
int nErr = 0; /* Number of errors encountered */
|
||||
void *pEngine; /* The LEMON-generated LALR(1) parser */
|
||||
int n = 0; /* Length of the next token token */
|
||||
@@ -573,6 +572,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
int lastTokenParsed = -1; /* type of the previous token */
|
||||
sqlite3 *db = pParse->db; /* The database connection */
|
||||
int mxSqlLen; /* Max length of an SQL string */
|
||||
Parse *pParentParse = 0; /* Outer parse context, if any */
|
||||
#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
|
||||
yyParser sEngine; /* Space to hold the Lemon-generated Parser object */
|
||||
#endif
|
||||
@@ -585,7 +585,6 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
}
|
||||
pParse->rc = SQLITE_OK;
|
||||
pParse->zTail = zSql;
|
||||
assert( pzErrMsg!=0 );
|
||||
#ifdef SQLITE_DEBUG
|
||||
if( db->flags & SQLITE_ParserTrace ){
|
||||
printf("parser: [[[%s]]]\n", zSql);
|
||||
@@ -608,7 +607,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
assert( pParse->pNewTrigger==0 );
|
||||
assert( pParse->nVar==0 );
|
||||
assert( pParse->pVList==0 );
|
||||
pParse->pParentParse = db->pParse;
|
||||
pParentParse = db->pParse;
|
||||
db->pParse = pParse;
|
||||
while( 1 ){
|
||||
n = sqlite3GetToken((u8*)zSql, &tokenType);
|
||||
@@ -628,6 +627,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
#endif /* SQLITE_OMIT_WINDOWFUNC */
|
||||
if( AtomicLoad(&db->u1.isInterrupted) ){
|
||||
pParse->rc = SQLITE_INTERRUPT;
|
||||
pParse->nErr++;
|
||||
break;
|
||||
}
|
||||
if( tokenType==TK_SPACE ){
|
||||
@@ -657,7 +657,10 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
tokenType = analyzeFilterKeyword((const u8*)&zSql[6], lastTokenParsed);
|
||||
#endif /* SQLITE_OMIT_WINDOWFUNC */
|
||||
}else{
|
||||
sqlite3ErrorMsg(pParse, "unrecognized token: \"%.*s\"", n, zSql);
|
||||
Token x;
|
||||
x.z = zSql;
|
||||
x.n = n;
|
||||
sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", &x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -685,46 +688,30 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
if( db->mallocFailed ){
|
||||
pParse->rc = SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
|
||||
pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc));
|
||||
}
|
||||
assert( pzErrMsg!=0 );
|
||||
if( pParse->zErrMsg ){
|
||||
*pzErrMsg = pParse->zErrMsg;
|
||||
sqlite3_log(pParse->rc, "%s in \"%s\"",
|
||||
*pzErrMsg, pParse->zTail);
|
||||
pParse->zErrMsg = 0;
|
||||
if( pParse->zErrMsg || (pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE) ){
|
||||
if( pParse->zErrMsg==0 ){
|
||||
pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc));
|
||||
}
|
||||
sqlite3_log(pParse->rc, "%s in \"%s\"", pParse->zErrMsg, pParse->zTail);
|
||||
nErr++;
|
||||
}
|
||||
pParse->zTail = zSql;
|
||||
if( pParse->pVdbe && pParse->nErr>0 && pParse->nested==0 ){
|
||||
sqlite3VdbeDelete(pParse->pVdbe);
|
||||
pParse->pVdbe = 0;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
if( pParse->nested==0 ){
|
||||
sqlite3DbFree(db, pParse->aTableLock);
|
||||
pParse->aTableLock = 0;
|
||||
pParse->nTableLock = 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
sqlite3_free(pParse->apVtabLock);
|
||||
#endif
|
||||
|
||||
if( !IN_SPECIAL_PARSE ){
|
||||
if( pParse->pNewTable && !IN_SPECIAL_PARSE ){
|
||||
/* If the pParse->declareVtab flag is set, do not delete any table
|
||||
** structure built up in pParse->pNewTable. The calling code (see vtab.c)
|
||||
** will take responsibility for freeing the Table structure.
|
||||
*/
|
||||
sqlite3DeleteTable(db, pParse->pNewTable);
|
||||
}
|
||||
if( !IN_RENAME_OBJECT ){
|
||||
if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){
|
||||
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
|
||||
}
|
||||
sqlite3DbFree(db, pParse->pVList);
|
||||
db->pParse = pParse->pParentParse;
|
||||
pParse->pParentParse = 0;
|
||||
db->pParse = pParentParse;
|
||||
assert( nErr==0 || pParse->rc!=SQLITE_OK );
|
||||
return nErr;
|
||||
}
|
||||
|
||||
+4
-4
@@ -33,7 +33,7 @@ static TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
|
||||
p->iLevel++;
|
||||
}
|
||||
assert( moreToFollow==0 || moreToFollow==1 );
|
||||
if( p->iLevel<sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow;
|
||||
if( p->iLevel<(int)sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow;
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ static void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
|
||||
char zBuf[500];
|
||||
sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
|
||||
if( p ){
|
||||
for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
|
||||
for(i=0; i<p->iLevel && i<(int)sizeof(p->bLine)-1; i++){
|
||||
sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4);
|
||||
}
|
||||
sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
|
||||
@@ -387,7 +387,7 @@ void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
|
||||
void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
|
||||
pView = sqlite3TreeViewPush(pView, more);
|
||||
sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
|
||||
pWin->pFunc->zName, pWin->pFunc->nArg);
|
||||
pWin->pWFunc->zName, pWin->pWFunc->nArg);
|
||||
sqlite3TreeViewWindow(pView, pWin, 0);
|
||||
sqlite3TreeViewPop(pView);
|
||||
}
|
||||
@@ -412,7 +412,7 @@ void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
|
||||
sqlite3_str_appendf(&x, " fg.af=%x.%c",
|
||||
pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
|
||||
if( ExprHasProperty(pExpr, EP_FromJoin) ){
|
||||
sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable);
|
||||
sqlite3_str_appendf(&x, " iRJT=%d", pExpr->w.iRightJoinTable);
|
||||
}
|
||||
if( ExprHasProperty(pExpr, EP_FromDDL) ){
|
||||
sqlite3_str_appendf(&x, " DDL");
|
||||
|
||||
+41
-32
@@ -446,6 +446,7 @@ static TriggerStep *triggerStepAllocate(
|
||||
sqlite3 *db = pParse->db;
|
||||
TriggerStep *pTriggerStep;
|
||||
|
||||
if( pParse->nErr ) return 0;
|
||||
pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
|
||||
if( pTriggerStep ){
|
||||
char *z = (char*)&pTriggerStep[1];
|
||||
@@ -918,6 +919,7 @@ static void codeReturningTrigger(
|
||||
|
||||
assert( v!=0 );
|
||||
assert( pParse->bReturning );
|
||||
assert( db->pParse==pParse );
|
||||
pReturning = pParse->u1.pReturning;
|
||||
assert( pTrigger == &(pReturning->retTrig) );
|
||||
memset(&sSelect, 0, sizeof(sSelect));
|
||||
@@ -928,12 +930,13 @@ static void codeReturningTrigger(
|
||||
sFrom.a[0].pTab = pTab;
|
||||
sFrom.a[0].iCursor = -1;
|
||||
sqlite3SelectPrep(pParse, &sSelect, 0);
|
||||
if( db->mallocFailed==0 && pParse->nErr==0 ){
|
||||
if( pParse->nErr==0 ){
|
||||
assert( db->mallocFailed==0 );
|
||||
sqlite3GenerateColumnNames(pParse, &sSelect);
|
||||
}
|
||||
sqlite3ExprListDelete(db, sSelect.pEList);
|
||||
pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
|
||||
if( pNew ){
|
||||
if( !db->mallocFailed ){
|
||||
NameContext sNC;
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
if( pReturning->nRetCol==0 ){
|
||||
@@ -945,7 +948,9 @@ static void codeReturningTrigger(
|
||||
sNC.ncFlags = NC_UBaseReg;
|
||||
pParse->eTriggerOp = pTrigger->op;
|
||||
pParse->pTriggerTab = pTab;
|
||||
if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK ){
|
||||
if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK
|
||||
&& ALWAYS(!db->mallocFailed)
|
||||
){
|
||||
int i;
|
||||
int nCol = pNew->nExpr;
|
||||
int reg = pParse->nMem+1;
|
||||
@@ -953,16 +958,20 @@ static void codeReturningTrigger(
|
||||
pReturning->iRetReg = reg;
|
||||
for(i=0; i<nCol; i++){
|
||||
Expr *pCol = pNew->a[i].pExpr;
|
||||
assert( pCol!=0 ); /* Due to !db->mallocFailed ~9 lines above */
|
||||
sqlite3ExprCodeFactorable(pParse, pCol, reg+i);
|
||||
if( sqlite3ExprAffinity(pCol)==SQLITE_AFF_REAL ){
|
||||
sqlite3VdbeAddOp1(v, OP_RealAffinity, reg+i);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, i, reg+i);
|
||||
sqlite3VdbeAddOp2(v, OP_NewRowid, pReturning->iRetCur, reg+i+1);
|
||||
sqlite3VdbeAddOp3(v, OP_Insert, pReturning->iRetCur, reg+i, reg+i+1);
|
||||
}
|
||||
sqlite3ExprListDelete(db, pNew);
|
||||
pParse->eTriggerOp = 0;
|
||||
pParse->pTriggerTab = 0;
|
||||
}
|
||||
sqlite3ExprListDelete(db, pNew);
|
||||
pParse->eTriggerOp = 0;
|
||||
pParse->pTriggerTab = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1104,8 +1113,8 @@ static TriggerPrg *codeRowTrigger(
|
||||
Vdbe *v; /* Temporary VM */
|
||||
NameContext sNC; /* Name context for sub-vdbe */
|
||||
SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
|
||||
Parse *pSubParse; /* Parse context for sub-vdbe */
|
||||
int iEndTrigger = 0; /* Label to jump to if WHEN is false */
|
||||
Parse sSubParse; /* Parse context for sub-vdbe */
|
||||
|
||||
assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
|
||||
assert( pTop->pVdbe );
|
||||
@@ -1127,19 +1136,17 @@ static TriggerPrg *codeRowTrigger(
|
||||
|
||||
/* Allocate and populate a new Parse context to use for coding the
|
||||
** trigger sub-program. */
|
||||
pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
|
||||
if( !pSubParse ) return 0;
|
||||
sqlite3ParseObjectInit(&sSubParse, db);
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pSubParse;
|
||||
pSubParse->db = db;
|
||||
pSubParse->pTriggerTab = pTab;
|
||||
pSubParse->pToplevel = pTop;
|
||||
pSubParse->zAuthContext = pTrigger->zName;
|
||||
pSubParse->eTriggerOp = pTrigger->op;
|
||||
pSubParse->nQueryLoop = pParse->nQueryLoop;
|
||||
pSubParse->disableVtab = pParse->disableVtab;
|
||||
sNC.pParse = &sSubParse;
|
||||
sSubParse.pTriggerTab = pTab;
|
||||
sSubParse.pToplevel = pTop;
|
||||
sSubParse.zAuthContext = pTrigger->zName;
|
||||
sSubParse.eTriggerOp = pTrigger->op;
|
||||
sSubParse.nQueryLoop = pParse->nQueryLoop;
|
||||
sSubParse.disableVtab = pParse->disableVtab;
|
||||
|
||||
v = sqlite3GetVdbe(pSubParse);
|
||||
v = sqlite3GetVdbe(&sSubParse);
|
||||
if( v ){
|
||||
VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
|
||||
pTrigger->zName, onErrorText(orconf),
|
||||
@@ -1165,14 +1172,14 @@ static TriggerPrg *codeRowTrigger(
|
||||
if( db->mallocFailed==0
|
||||
&& SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
|
||||
){
|
||||
iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
|
||||
sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
|
||||
iEndTrigger = sqlite3VdbeMakeLabel(&sSubParse);
|
||||
sqlite3ExprIfFalse(&sSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
|
||||
}
|
||||
sqlite3ExprDelete(db, pWhen);
|
||||
}
|
||||
|
||||
/* Code the trigger program into the sub-vdbe. */
|
||||
codeTriggerProgram(pSubParse, pTrigger->step_list, orconf);
|
||||
codeTriggerProgram(&sSubParse, pTrigger->step_list, orconf);
|
||||
|
||||
/* Insert an OP_Halt at the end of the sub-program. */
|
||||
if( iEndTrigger ){
|
||||
@@ -1180,23 +1187,24 @@ static TriggerPrg *codeRowTrigger(
|
||||
}
|
||||
sqlite3VdbeAddOp0(v, OP_Halt);
|
||||
VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
|
||||
transferParseError(pParse, &sSubParse);
|
||||
|
||||
transferParseError(pParse, pSubParse);
|
||||
if( db->mallocFailed==0 && pParse->nErr==0 ){
|
||||
if( pParse->nErr==0 ){
|
||||
assert( db->mallocFailed==0 );
|
||||
pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
|
||||
}
|
||||
pProgram->nMem = pSubParse->nMem;
|
||||
pProgram->nCsr = pSubParse->nTab;
|
||||
pProgram->nMem = sSubParse.nMem;
|
||||
pProgram->nCsr = sSubParse.nTab;
|
||||
pProgram->token = (void *)pTrigger;
|
||||
pPrg->aColmask[0] = pSubParse->oldmask;
|
||||
pPrg->aColmask[1] = pSubParse->newmask;
|
||||
pPrg->aColmask[0] = sSubParse.oldmask;
|
||||
pPrg->aColmask[1] = sSubParse.newmask;
|
||||
sqlite3VdbeDelete(v);
|
||||
}else{
|
||||
transferParseError(pParse, &sSubParse);
|
||||
}
|
||||
|
||||
assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
|
||||
sqlite3ParserReset(pSubParse);
|
||||
sqlite3StackFree(db, pSubParse);
|
||||
|
||||
assert( !sSubParse.pTriggerPrg && !sSubParse.nMaxArg );
|
||||
sqlite3ParseObjectReset(&sSubParse);
|
||||
return pPrg;
|
||||
}
|
||||
|
||||
@@ -1229,6 +1237,7 @@ static TriggerPrg *getRowTrigger(
|
||||
/* If an existing TriggerPrg could not be located, create a new one. */
|
||||
if( !pPrg ){
|
||||
pPrg = codeRowTrigger(pParse, pTrigger, pTab, orconf);
|
||||
pParse->db->errByteOffset = -1;
|
||||
}
|
||||
|
||||
return pPrg;
|
||||
@@ -1251,7 +1260,7 @@ void sqlite3CodeRowTriggerDirect(
|
||||
Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */
|
||||
TriggerPrg *pPrg;
|
||||
pPrg = getRowTrigger(pParse, p, pTab, orconf);
|
||||
assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
|
||||
assert( pPrg || pParse->nErr );
|
||||
|
||||
/* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
|
||||
** is a pointer to the sub-vdbe containing the trigger program. */
|
||||
|
||||
+8
-6
@@ -347,9 +347,11 @@ void sqlite3Update(
|
||||
|
||||
memset(&sContext, 0, sizeof(sContext));
|
||||
db = pParse->db;
|
||||
if( pParse->nErr || db->mallocFailed ){
|
||||
assert( db->pParse==pParse );
|
||||
if( pParse->nErr ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
assert( db->mallocFailed==0 );
|
||||
|
||||
/* Locate the table which we want to update.
|
||||
*/
|
||||
@@ -721,7 +723,7 @@ void sqlite3Update(
|
||||
if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
|
||||
flags |= WHERE_ONEPASS_MULTIROW;
|
||||
}
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags,iIdxCur);
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur);
|
||||
if( pWInfo==0 ) goto update_cleanup;
|
||||
|
||||
/* A one-pass strategy that might update more than one row may not
|
||||
@@ -1121,9 +1123,7 @@ void sqlite3Update(
|
||||
** that information.
|
||||
*/
|
||||
if( regRowCount ){
|
||||
sqlite3VdbeAddOp2(v, OP_ChngCntRow, regRowCount, 1);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
|
||||
sqlite3CodeChangeCount(v, regRowCount, "rows updated");
|
||||
}
|
||||
|
||||
update_cleanup:
|
||||
@@ -1245,7 +1245,9 @@ static void updateVirtualTable(
|
||||
regRowid = ++pParse->nMem;
|
||||
|
||||
/* Start scanning the virtual table */
|
||||
pWInfo = sqlite3WhereBegin(pParse, pSrc,pWhere,0,0,WHERE_ONEPASS_DESIRED,0);
|
||||
pWInfo = sqlite3WhereBegin(
|
||||
pParse, pSrc, pWhere, 0, 0, 0, WHERE_ONEPASS_DESIRED, 0
|
||||
);
|
||||
if( pWInfo==0 ) return;
|
||||
|
||||
/* Populate the argument registers. */
|
||||
|
||||
+16
-35
@@ -117,7 +117,11 @@ static SQLITE_NOINLINE void sqlite3ErrorFinish(sqlite3 *db, int err_code){
|
||||
void sqlite3Error(sqlite3 *db, int err_code){
|
||||
assert( db!=0 );
|
||||
db->errCode = err_code;
|
||||
if( err_code || db->pErr ) sqlite3ErrorFinish(db, err_code);
|
||||
if( err_code || db->pErr ){
|
||||
sqlite3ErrorFinish(db, err_code);
|
||||
}else{
|
||||
db->errByteOffset = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -127,6 +131,7 @@ void sqlite3Error(sqlite3 *db, int err_code){
|
||||
void sqlite3ErrorClear(sqlite3 *db){
|
||||
assert( db!=0 );
|
||||
db->errCode = SQLITE_OK;
|
||||
db->errByteOffset = -1;
|
||||
if( db->pErr ) sqlite3ValueSetNull(db->pErr);
|
||||
}
|
||||
|
||||
@@ -147,17 +152,8 @@ void sqlite3SystemError(sqlite3 *db, int rc){
|
||||
** handle "db". The error code is set to "err_code".
|
||||
**
|
||||
** If it is not NULL, string zFormat specifies the format of the
|
||||
** error string in the style of the printf functions: The following
|
||||
** format characters are allowed:
|
||||
**
|
||||
** %s Insert a string
|
||||
** %z A string that should be freed after use
|
||||
** %d Insert an integer
|
||||
** %T Insert a token
|
||||
** %S Insert the first element of a SrcList
|
||||
**
|
||||
** zFormat and any string tokens that follow it are assumed to be
|
||||
** encoded in UTF-8.
|
||||
** error string. zFormat and any string tokens that follow it are
|
||||
** assumed to be encoded in UTF-8.
|
||||
**
|
||||
** To clear the most recent error for sqlite handle "db", sqlite3Error
|
||||
** should be called with err_code set to SQLITE_OK and zFormat set
|
||||
@@ -181,13 +177,6 @@ void sqlite3ErrorWithMsg(sqlite3 *db, int err_code, const char *zFormat, ...){
|
||||
|
||||
/*
|
||||
** Add an error message to pParse->zErrMsg and increment pParse->nErr.
|
||||
** The following formatting characters are allowed:
|
||||
**
|
||||
** %s Insert a string
|
||||
** %z A string that should be freed after use
|
||||
** %d Insert an integer
|
||||
** %T Insert a token
|
||||
** %S Insert the first element of a SrcList
|
||||
**
|
||||
** This function should be used to report any error that occurs while
|
||||
** compiling an SQL statement (i.e. within sqlite3_prepare()). The
|
||||
@@ -200,11 +189,19 @@ void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
|
||||
char *zMsg;
|
||||
va_list ap;
|
||||
sqlite3 *db = pParse->db;
|
||||
assert( db!=0 );
|
||||
assert( db->pParse==pParse );
|
||||
db->errByteOffset = -2;
|
||||
va_start(ap, zFormat);
|
||||
zMsg = sqlite3VMPrintf(db, zFormat, ap);
|
||||
va_end(ap);
|
||||
if( db->errByteOffset<-1 ) db->errByteOffset = -1;
|
||||
if( db->suppressErr ){
|
||||
sqlite3DbFree(db, zMsg);
|
||||
if( db->mallocFailed ){
|
||||
pParse->nErr++;
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
}
|
||||
}else{
|
||||
pParse->nErr++;
|
||||
sqlite3DbFree(db, pParse->zErrMsg);
|
||||
@@ -1586,7 +1583,6 @@ LogEst sqlite3LogEst(u64 x){
|
||||
return a[x&7] + y - 10;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
/*
|
||||
** Convert a double into a LogEst
|
||||
** In other words, compute an approximation for 10*log2(x).
|
||||
@@ -1601,16 +1597,9 @@ LogEst sqlite3LogEstFromDouble(double x){
|
||||
e = (a>>52) - 1022;
|
||||
return e*10;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \
|
||||
defined(SQLITE_ENABLE_STAT4) || \
|
||||
defined(SQLITE_EXPLAIN_ESTIMATED_ROWS)
|
||||
/*
|
||||
** Convert a LogEst into an integer.
|
||||
**
|
||||
** Note that this routine is only used when one or more of various
|
||||
** non-standard compile-time options is enabled.
|
||||
*/
|
||||
u64 sqlite3LogEstToInt(LogEst x){
|
||||
u64 n;
|
||||
@@ -1618,17 +1607,9 @@ u64 sqlite3LogEstToInt(LogEst x){
|
||||
x /= 10;
|
||||
if( n>=5 ) n -= 2;
|
||||
else if( n>=1 ) n -= 1;
|
||||
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \
|
||||
defined(SQLITE_EXPLAIN_ESTIMATED_ROWS)
|
||||
if( x>60 ) return (u64)LARGEST_INT64;
|
||||
#else
|
||||
/* If only SQLITE_ENABLE_STAT4 is on, then the largest input
|
||||
** possible to this routine is 310, resulting in a maximum x of 31 */
|
||||
assert( x<=60 );
|
||||
#endif
|
||||
return x>=3 ? (n+8)<<(x-3) : (n+8)>>(3-x);
|
||||
}
|
||||
#endif /* defined SCANSTAT or STAT4 or ESTIMATED_ROWS */
|
||||
|
||||
/*
|
||||
** Add a new name/number pair to a VList. This might require that the
|
||||
|
||||
+270
-83
@@ -241,7 +241,6 @@ static VdbeCursor *allocateCursor(
|
||||
Vdbe *p, /* The virtual machine */
|
||||
int iCur, /* Index of the new VdbeCursor */
|
||||
int nField, /* Number of fields in the table or index */
|
||||
int iDb, /* Database the cursor belongs to, or -1 */
|
||||
u8 eCurType /* Type of the new cursor */
|
||||
){
|
||||
/* Find the memory cell that will be used to store the blob of memory
|
||||
@@ -298,7 +297,6 @@ static VdbeCursor *allocateCursor(
|
||||
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc;
|
||||
memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
|
||||
pCx->eCurType = eCurType;
|
||||
pCx->iDb = iDb;
|
||||
pCx->nField = nField;
|
||||
pCx->aOffset = &pCx->aType[nField];
|
||||
if( eCurType==CURTYPE_BTREE ){
|
||||
@@ -671,6 +669,29 @@ static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Compute a bloom filter hash using pOp->p4.i registers from aMem[] beginning
|
||||
** with pOp->p3. Return the hash.
|
||||
*/
|
||||
static u64 filterHash(const Mem *aMem, const Op *pOp){
|
||||
int i, mx;
|
||||
u64 h = 0;
|
||||
|
||||
assert( pOp->p4type==P4_INT32 );
|
||||
for(i=pOp->p3, mx=i+pOp->p4.i; i<mx; i++){
|
||||
const Mem *p = &aMem[i];
|
||||
if( p->flags & (MEM_Int|MEM_IntReal) ){
|
||||
h += p->u.i;
|
||||
}else if( p->flags & MEM_Real ){
|
||||
h += sqlite3VdbeIntValue(p);
|
||||
}else if( p->flags & (MEM_Str|MEM_Blob) ){
|
||||
h += p->n;
|
||||
if( p->flags & MEM_Zero ) h += p->u.nZero;
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the symbolic name for the data type of a pMem
|
||||
*/
|
||||
@@ -970,10 +991,14 @@ jump_to_p2:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: Return P1 * * * *
|
||||
/* Opcode: Return P1 * P3 * *
|
||||
**
|
||||
** Jump to the next instruction after the address in register P1. After
|
||||
** the jump, register P1 becomes undefined.
|
||||
**
|
||||
** P3 is not used by the byte-code engine. However, the code generator
|
||||
** sets P3 to address of the associated OP_BeginSubrtn opcode, if there is
|
||||
** one.
|
||||
*/
|
||||
case OP_Return: { /* in1 */
|
||||
pIn1 = &aMem[pOp->p1];
|
||||
@@ -1161,11 +1186,22 @@ case OP_Halt: {
|
||||
goto vdbe_return;
|
||||
}
|
||||
|
||||
/* Opcode: BeginSubrtn P1 P2 * * *
|
||||
** Synopsis: r[P2]=P1
|
||||
**
|
||||
** Mark the beginning of a subroutine by loading the integer value P1
|
||||
** into register r[P2]. The P2 register is used to store the return
|
||||
** address of the subroutine call.
|
||||
**
|
||||
** This opcode is identical to OP_Integer. It has a different name
|
||||
** only to make the byte code easier to read and verify.
|
||||
*/
|
||||
/* Opcode: Integer P1 P2 * * *
|
||||
** Synopsis: r[P2]=P1
|
||||
**
|
||||
** The 32-bit integer value P1 is written into register P2.
|
||||
*/
|
||||
case OP_BeginSubrtn:
|
||||
case OP_Integer: { /* out2 */
|
||||
pOut = out2Prerelease(p, pOp);
|
||||
pOut->u.i = pOp->p1;
|
||||
@@ -1325,12 +1361,18 @@ case OP_SoftNull: {
|
||||
** Synopsis: r[P2]=P4 (len=P1)
|
||||
**
|
||||
** P4 points to a blob of data P1 bytes long. Store this
|
||||
** blob in register P2.
|
||||
** blob in register P2. If P4 is a NULL pointer, then construct
|
||||
** a zero-filled blob that is P1 bytes long in P2.
|
||||
*/
|
||||
case OP_Blob: { /* out2 */
|
||||
assert( pOp->p1 <= SQLITE_MAX_LENGTH );
|
||||
pOut = out2Prerelease(p, pOp);
|
||||
sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
|
||||
if( pOp->p4.z==0 ){
|
||||
sqlite3VdbeMemSetZeroBlob(pOut, pOp->p1);
|
||||
if( sqlite3VdbeMemExpandBlob(pOut) ) goto no_mem;
|
||||
}else{
|
||||
sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
|
||||
}
|
||||
pOut->enc = encoding;
|
||||
UPDATE_MAX_BLOBSIZE(pOut);
|
||||
break;
|
||||
@@ -1479,24 +1521,22 @@ case OP_IntCopy: { /* out2 */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: ChngCntRow P1 P2 * * *
|
||||
** Synopsis: output=r[P1]
|
||||
/* Opcode: FkCheck * * * * *
|
||||
**
|
||||
** Output value in register P1 as the chance count for a DML statement,
|
||||
** due to the "PRAGMA count_changes=ON" setting. Or, if there was a
|
||||
** foreign key error in the statement, trigger the error now.
|
||||
** Halt with an SQLITE_CONSTRAINT error if there are any unresolved
|
||||
** foreign key constraint violations. If there are no foreign key
|
||||
** constraint violations, this is a no-op.
|
||||
**
|
||||
** This opcode is a variant of OP_ResultRow that checks the foreign key
|
||||
** immediate constraint count and throws an error if the count is
|
||||
** non-zero. The P2 opcode must be 1.
|
||||
** FK constraint violations are also checked when the prepared statement
|
||||
** exits. This opcode is used to raise foreign key constraint errors prior
|
||||
** to returning results such as a row change count or the result of a
|
||||
** RETURNING clause.
|
||||
*/
|
||||
case OP_ChngCntRow: {
|
||||
assert( pOp->p2==1 );
|
||||
case OP_FkCheck: {
|
||||
if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){
|
||||
goto abort_due_to_error;
|
||||
}
|
||||
/* Fall through to the next case, OP_ResultRow */
|
||||
/* no break */ deliberate_fall_through
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: ResultRow P1 P2 * * *
|
||||
@@ -2134,7 +2174,7 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
|
||||
sqlite3VdbeMemStringify(pIn1, encoding, 1);
|
||||
testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
|
||||
flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
|
||||
if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
|
||||
if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str;
|
||||
}
|
||||
if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
|
||||
testcase( pIn3->flags & MEM_Int );
|
||||
@@ -2602,10 +2642,18 @@ case OP_Offset: { /* out3 */
|
||||
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
|
||||
pC = p->apCsr[pOp->p1];
|
||||
pOut = &p->aMem[pOp->p3];
|
||||
if( NEVER(pC==0) || pC->eCurType!=CURTYPE_BTREE ){
|
||||
if( pC==0 || pC->eCurType!=CURTYPE_BTREE ){
|
||||
sqlite3VdbeMemSetNull(pOut);
|
||||
}else{
|
||||
sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor));
|
||||
if( pC->deferredMoveto ){
|
||||
rc = sqlite3VdbeFinishMoveto(pC);
|
||||
if( rc ) goto abort_due_to_error;
|
||||
}
|
||||
if( sqlite3BtreeEof(pC->uc.pCursor) ){
|
||||
sqlite3VdbeMemSetNull(pOut);
|
||||
}else{
|
||||
sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2634,7 +2682,7 @@ case OP_Offset: { /* out3 */
|
||||
case OP_Column: {
|
||||
u32 p2; /* column number to retrieve */
|
||||
VdbeCursor *pC; /* The VDBE cursor */
|
||||
BtCursor *pCrsr; /* The BTree cursor */
|
||||
BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */
|
||||
u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
|
||||
int len; /* The length of the serialized data for the column */
|
||||
int i; /* Loop counter */
|
||||
@@ -2648,22 +2696,15 @@ case OP_Column: {
|
||||
Mem *pReg; /* PseudoTable input register */
|
||||
|
||||
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
|
||||
assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
|
||||
pC = p->apCsr[pOp->p1];
|
||||
assert( pC!=0 );
|
||||
p2 = (u32)pOp->p2;
|
||||
|
||||
/* If the cursor cache is stale (meaning it is not currently point at
|
||||
** the correct row) then bring it up-to-date by doing the necessary
|
||||
** B-Tree seek. */
|
||||
rc = sqlite3VdbeCursorMoveto(&pC, &p2);
|
||||
if( rc ) goto abort_due_to_error;
|
||||
|
||||
assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
|
||||
pDest = &aMem[pOp->p3];
|
||||
memAboutToChange(p, pDest);
|
||||
op_column_restart:
|
||||
assert( pC!=0 );
|
||||
assert( p2<(u32)pC->nField );
|
||||
aOffset = pC->aOffset;
|
||||
assert( aOffset==pC->aType+pC->nField );
|
||||
assert( pC->eCurType!=CURTYPE_VTAB );
|
||||
assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
|
||||
assert( pC->eCurType!=CURTYPE_SORTER );
|
||||
@@ -2680,11 +2721,28 @@ case OP_Column: {
|
||||
pC->payloadSize = pC->szRow = pReg->n;
|
||||
pC->aRow = (u8*)pReg->z;
|
||||
}else{
|
||||
pDest = &aMem[pOp->p3];
|
||||
memAboutToChange(p, pDest);
|
||||
sqlite3VdbeMemSetNull(pDest);
|
||||
goto op_column_out;
|
||||
}
|
||||
}else{
|
||||
pCrsr = pC->uc.pCursor;
|
||||
if( pC->deferredMoveto ){
|
||||
u32 iMap;
|
||||
assert( !pC->isEphemeral );
|
||||
if( pC->ub.aAltMap && (iMap = pC->ub.aAltMap[1+p2])>0 ){
|
||||
pC = pC->pAltCursor;
|
||||
p2 = iMap - 1;
|
||||
goto op_column_restart;
|
||||
}
|
||||
rc = sqlite3VdbeFinishMoveto(pC);
|
||||
if( rc ) goto abort_due_to_error;
|
||||
}else if( sqlite3BtreeCursorHasMoved(pCrsr) ){
|
||||
rc = sqlite3VdbeHandleMovedCursor(pC);
|
||||
if( rc ) goto abort_due_to_error;
|
||||
goto op_column_restart;
|
||||
}
|
||||
assert( pC->eCurType==CURTYPE_BTREE );
|
||||
assert( pCrsr );
|
||||
assert( sqlite3BtreeCursorIsValid(pCrsr) );
|
||||
@@ -2692,15 +2750,11 @@ case OP_Column: {
|
||||
pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow);
|
||||
assert( pC->szRow<=pC->payloadSize );
|
||||
assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */
|
||||
if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
|
||||
goto too_big;
|
||||
}
|
||||
}
|
||||
pC->cacheStatus = p->cacheCtr;
|
||||
pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]);
|
||||
pC->nHdrParsed = 0;
|
||||
|
||||
|
||||
if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/
|
||||
/* pC->aRow does not have to hold the entire row, but it does at least
|
||||
** need to cover the header of the record. If pC->aRow does not contain
|
||||
@@ -2740,6 +2794,10 @@ case OP_Column: {
|
||||
testcase( aOffset[0]==0 );
|
||||
goto op_column_read_header;
|
||||
}
|
||||
}else if( sqlite3BtreeCursorHasMoved(pC->uc.pCursor) ){
|
||||
rc = sqlite3VdbeHandleMovedCursor(pC);
|
||||
if( rc ) goto abort_due_to_error;
|
||||
goto op_column_restart;
|
||||
}
|
||||
|
||||
/* Make sure at least the first p2+1 entries of the header have been
|
||||
@@ -2808,6 +2866,8 @@ case OP_Column: {
|
||||
** columns. So the result will be either the default value or a NULL.
|
||||
*/
|
||||
if( pC->nHdrParsed<=p2 ){
|
||||
pDest = &aMem[pOp->p3];
|
||||
memAboutToChange(p, pDest);
|
||||
if( pOp->p4type==P4_MEM ){
|
||||
sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static);
|
||||
}else{
|
||||
@@ -2825,6 +2885,8 @@ case OP_Column: {
|
||||
*/
|
||||
assert( p2<pC->nHdrParsed );
|
||||
assert( rc==SQLITE_OK );
|
||||
pDest = &aMem[pOp->p3];
|
||||
memAboutToChange(p, pDest);
|
||||
assert( sqlite3VdbeCheckMemInvariants(pDest) );
|
||||
if( VdbeMemDynamic(pDest) ){
|
||||
sqlite3VdbeMemSetNull(pDest);
|
||||
@@ -2845,6 +2907,7 @@ case OP_Column: {
|
||||
pDest->n = len = (t-12)/2;
|
||||
pDest->enc = encoding;
|
||||
if( pDest->szMalloc < len+2 ){
|
||||
if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big;
|
||||
pDest->flags = MEM_Null;
|
||||
if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem;
|
||||
}else{
|
||||
@@ -2877,6 +2940,7 @@ case OP_Column: {
|
||||
*/
|
||||
sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest);
|
||||
}else{
|
||||
if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big;
|
||||
rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
|
||||
if( rc!=SQLITE_OK ) goto abort_due_to_error;
|
||||
sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
|
||||
@@ -2959,6 +3023,8 @@ case OP_TypeCheck: {
|
||||
break;
|
||||
}
|
||||
case COLTYPE_REAL: {
|
||||
testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real );
|
||||
testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal );
|
||||
if( pIn1->flags & MEM_Int ){
|
||||
/* When applying REAL affinity, if the result is still an MEM_Int
|
||||
** that will fit in 6 bytes, then change the type to MEM_IntReal
|
||||
@@ -2976,7 +3042,7 @@ case OP_TypeCheck: {
|
||||
pIn1->flags |= MEM_Real;
|
||||
pIn1->flags &= ~MEM_Int;
|
||||
}
|
||||
}else if( (pIn1->flags & MEM_Real)==0 ){
|
||||
}else if( (pIn1->flags & (MEM_Real|MEM_IntReal))==0 ){
|
||||
goto vdbe_type_error;
|
||||
}
|
||||
break;
|
||||
@@ -3087,7 +3153,6 @@ case OP_MakeRecord: {
|
||||
Mem *pLast; /* Last field of the record */
|
||||
int nField; /* Number of fields in the record */
|
||||
char *zAffinity; /* The affinity string for the record */
|
||||
int file_format; /* File format to use for encoding */
|
||||
u32 len; /* Length of a field */
|
||||
u8 *zHdr; /* Where to write next byte of the header */
|
||||
u8 *zPayload; /* Where to write next byte of the payload */
|
||||
@@ -3116,7 +3181,6 @@ case OP_MakeRecord: {
|
||||
pData0 = &aMem[nField];
|
||||
nField = pOp->p2;
|
||||
pLast = &pData0[nField-1];
|
||||
file_format = p->minWriteFileFormat;
|
||||
|
||||
/* Identify the output register */
|
||||
assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
|
||||
@@ -3215,10 +3279,10 @@ case OP_MakeRecord: {
|
||||
testcase( uu==127 ); testcase( uu==128 );
|
||||
testcase( uu==32767 ); testcase( uu==32768 );
|
||||
testcase( uu==8388607 ); testcase( uu==8388608 );
|
||||
testcase( uu==2147483647 ); testcase( uu==2147483648 );
|
||||
testcase( uu==2147483647 ); testcase( uu==2147483648LL );
|
||||
testcase( uu==140737488355327LL ); testcase( uu==140737488355328LL );
|
||||
if( uu<=127 ){
|
||||
if( (i&1)==i && file_format>=4 ){
|
||||
if( (i&1)==i && p->minWriteFileFormat>=4 ){
|
||||
pRec->uTemp = 8+(u32)uu;
|
||||
}else{
|
||||
nData++;
|
||||
@@ -3343,7 +3407,7 @@ case OP_MakeRecord: {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: Count P1 P2 p3 * *
|
||||
/* Opcode: Count P1 P2 P3 * *
|
||||
** Synopsis: r[P2]=count()
|
||||
**
|
||||
** Store the number of entries (an integer value) in the table or index
|
||||
@@ -3665,8 +3729,15 @@ case OP_Transaction: {
|
||||
assert( pOp->p1>=0 && pOp->p1<db->nDb );
|
||||
assert( DbMaskTest(p->btreeMask, pOp->p1) );
|
||||
assert( rc==SQLITE_OK );
|
||||
if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
|
||||
rc = SQLITE_READONLY;
|
||||
if( pOp->p2 && (db->flags & (SQLITE_QueryOnly|SQLITE_CorruptRdOnly))!=0 ){
|
||||
if( db->flags & SQLITE_QueryOnly ){
|
||||
/* Writes prohibited by the "PRAGMA query_only=TRUE" statement */
|
||||
rc = SQLITE_READONLY;
|
||||
}else{
|
||||
/* Writes prohibited due to a prior SQLITE_CORRUPT in the current
|
||||
** transaction */
|
||||
rc = SQLITE_CORRUPT;
|
||||
}
|
||||
goto abort_due_to_error;
|
||||
}
|
||||
pBt = db->aDb[pOp->p1].pBt;
|
||||
@@ -3806,6 +3877,7 @@ case OP_SetCookie: {
|
||||
/* When the schema cookie changes, record the new cookie internally */
|
||||
pDb->pSchema->schema_cookie = pOp->p3 - pOp->p5;
|
||||
db->mDbFlags |= DBFLAG_SchemaChange;
|
||||
sqlite3FkClearTriggerCache(db, pOp->p1);
|
||||
}else if( pOp->p2==BTREE_FILE_FORMAT ){
|
||||
/* Record changes in the file format */
|
||||
pDb->pSchema->file_format = pOp->p3;
|
||||
@@ -3983,8 +4055,9 @@ case OP_OpenWrite:
|
||||
assert( pOp->p1>=0 );
|
||||
assert( nField>=0 );
|
||||
testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
|
||||
pCur = allocateCursor(p, pOp->p1, nField, iDb, CURTYPE_BTREE);
|
||||
pCur = allocateCursor(p, pOp->p1, nField, CURTYPE_BTREE);
|
||||
if( pCur==0 ) goto no_mem;
|
||||
pCur->iDb = iDb;
|
||||
pCur->nullRow = 1;
|
||||
pCur->isOrdered = 1;
|
||||
pCur->pgnoRoot = p2;
|
||||
@@ -4026,7 +4099,7 @@ case OP_OpenDup: {
|
||||
assert( pOrig );
|
||||
assert( pOrig->isEphemeral ); /* Only ephemeral cursors can be duplicated */
|
||||
|
||||
pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
|
||||
pCx = allocateCursor(p, pOp->p1, pOrig->nField, CURTYPE_BTREE);
|
||||
if( pCx==0 ) goto no_mem;
|
||||
pCx->nullRow = 1;
|
||||
pCx->isEphemeral = 1;
|
||||
@@ -4034,10 +4107,10 @@ case OP_OpenDup: {
|
||||
pCx->isTable = pOrig->isTable;
|
||||
pCx->pgnoRoot = pOrig->pgnoRoot;
|
||||
pCx->isOrdered = pOrig->isOrdered;
|
||||
pCx->pBtx = pOrig->pBtx;
|
||||
pCx->ub.pBtx = pOrig->ub.pBtx;
|
||||
pCx->hasBeenDuped = 1;
|
||||
pOrig->hasBeenDuped = 1;
|
||||
rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
|
||||
rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR,
|
||||
pCx->pKeyInfo, pCx->uc.pCursor);
|
||||
/* The sqlite3BtreeCursor() routine can only fail for the first cursor
|
||||
** opened for a database. Since there is already an open cursor when this
|
||||
@@ -4110,16 +4183,16 @@ case OP_OpenEphemeral: {
|
||||
assert( pCx->isEphemeral );
|
||||
pCx->seqCount = 0;
|
||||
pCx->cacheStatus = CACHE_STALE;
|
||||
rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0);
|
||||
rc = sqlite3BtreeClearTable(pCx->ub.pBtx, pCx->pgnoRoot, 0);
|
||||
}else{
|
||||
pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
|
||||
pCx = allocateCursor(p, pOp->p1, pOp->p2, CURTYPE_BTREE);
|
||||
if( pCx==0 ) goto no_mem;
|
||||
pCx->isEphemeral = 1;
|
||||
rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx,
|
||||
rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->ub.pBtx,
|
||||
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5,
|
||||
vfsFlags);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0);
|
||||
rc = sqlite3BtreeBeginTrans(pCx->ub.pBtx, 1, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
/* If a transient index is required, create it by calling
|
||||
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
|
||||
@@ -4128,26 +4201,26 @@ case OP_OpenEphemeral: {
|
||||
*/
|
||||
if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
|
||||
assert( pOp->p4type==P4_KEYINFO );
|
||||
rc = sqlite3BtreeCreateTable(pCx->pBtx, &pCx->pgnoRoot,
|
||||
rc = sqlite3BtreeCreateTable(pCx->ub.pBtx, &pCx->pgnoRoot,
|
||||
BTREE_BLOBKEY | pOp->p5);
|
||||
if( rc==SQLITE_OK ){
|
||||
assert( pCx->pgnoRoot==SCHEMA_ROOT+1 );
|
||||
assert( pKeyInfo->db==db );
|
||||
assert( pKeyInfo->enc==ENC(db) );
|
||||
rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
|
||||
rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR,
|
||||
pKeyInfo, pCx->uc.pCursor);
|
||||
}
|
||||
pCx->isTable = 0;
|
||||
}else{
|
||||
pCx->pgnoRoot = SCHEMA_ROOT;
|
||||
rc = sqlite3BtreeCursor(pCx->pBtx, SCHEMA_ROOT, BTREE_WRCSR,
|
||||
rc = sqlite3BtreeCursor(pCx->ub.pBtx, SCHEMA_ROOT, BTREE_WRCSR,
|
||||
0, pCx->uc.pCursor);
|
||||
pCx->isTable = 1;
|
||||
}
|
||||
}
|
||||
pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
|
||||
if( rc ){
|
||||
sqlite3BtreeClose(pCx->pBtx);
|
||||
sqlite3BtreeClose(pCx->ub.pBtx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4171,7 +4244,7 @@ case OP_SorterOpen: {
|
||||
|
||||
assert( pOp->p1>=0 );
|
||||
assert( pOp->p2>=0 );
|
||||
pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_SORTER);
|
||||
pCx = allocateCursor(p, pOp->p1, pOp->p2, CURTYPE_SORTER);
|
||||
if( pCx==0 ) goto no_mem;
|
||||
pCx->pKeyInfo = pOp->p4.pKeyInfo;
|
||||
assert( pCx->pKeyInfo->db==db );
|
||||
@@ -4220,7 +4293,7 @@ case OP_OpenPseudo: {
|
||||
|
||||
assert( pOp->p1>=0 );
|
||||
assert( pOp->p3>=0 );
|
||||
pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO);
|
||||
pCx = allocateCursor(p, pOp->p1, pOp->p3, CURTYPE_PSEUDO);
|
||||
if( pCx==0 ) goto no_mem;
|
||||
pCx->nullRow = 1;
|
||||
pCx->seekResult = pOp->p2;
|
||||
@@ -5672,6 +5745,10 @@ case OP_Rowid: { /* out2 */
|
||||
** Move the cursor P1 to a null row. Any OP_Column operations
|
||||
** that occur while the cursor is on the null row will always
|
||||
** write a NULL.
|
||||
**
|
||||
** Or, if P1 is a Pseudo-Cursor (a cursor opened using OP_OpenPseudo)
|
||||
** just reset the cache for that cursor. This causes the row of
|
||||
** content held by the pseudo-cursor to be reparsed.
|
||||
*/
|
||||
case OP_NullRow: {
|
||||
VdbeCursor *pC;
|
||||
@@ -5851,7 +5928,7 @@ case OP_Rewind: { /* jump */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: Next P1 P2 P3 P4 P5
|
||||
/* Opcode: Next P1 P2 P3 * P5
|
||||
**
|
||||
** Advance cursor P1 so that it points to the next key/data pair in its
|
||||
** table or index. If there are no more key/value pairs then fall through
|
||||
@@ -5870,15 +5947,12 @@ case OP_Rewind: { /* jump */
|
||||
** omitted if that index had been unique. P3 is usually 0. P3 is
|
||||
** always either 0 or 1.
|
||||
**
|
||||
** P4 is always of type P4_ADVANCE. The function pointer points to
|
||||
** sqlite3BtreeNext().
|
||||
**
|
||||
** If P5 is positive and the jump is taken, then event counter
|
||||
** number P5-1 in the prepared statement is incremented.
|
||||
**
|
||||
** See also: Prev
|
||||
*/
|
||||
/* Opcode: Prev P1 P2 P3 P4 P5
|
||||
/* Opcode: Prev P1 P2 P3 * P5
|
||||
**
|
||||
** Back up cursor P1 so that it points to the previous key/data pair in its
|
||||
** table or index. If there is no previous key/value pairs then fall through
|
||||
@@ -5898,9 +5972,6 @@ case OP_Rewind: { /* jump */
|
||||
** omitted if that index had been unique. P3 is usually 0. P3 is
|
||||
** always either 0 or 1.
|
||||
**
|
||||
** P4 is always of type P4_ADVANCE. The function pointer points to
|
||||
** sqlite3BtreePrevious().
|
||||
**
|
||||
** If P5 is positive and the jump is taken, then event counter
|
||||
** number P5-1 in the prepared statement is incremented.
|
||||
*/
|
||||
@@ -5918,7 +5989,20 @@ case OP_SorterNext: { /* jump */
|
||||
assert( isSorter(pC) );
|
||||
rc = sqlite3VdbeSorterNext(db, pC);
|
||||
goto next_tail;
|
||||
|
||||
case OP_Prev: /* jump */
|
||||
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
|
||||
assert( pOp->p5<ArraySize(p->aCounter) );
|
||||
pC = p->apCsr[pOp->p1];
|
||||
assert( pC!=0 );
|
||||
assert( pC->deferredMoveto==0 );
|
||||
assert( pC->eCurType==CURTYPE_BTREE );
|
||||
assert( pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
|
||||
|| pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope
|
||||
|| pC->seekOp==OP_NullRow);
|
||||
rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3);
|
||||
goto next_tail;
|
||||
|
||||
case OP_Next: /* jump */
|
||||
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
|
||||
assert( pOp->p5<ArraySize(p->aCounter) );
|
||||
@@ -5926,22 +6010,12 @@ case OP_Next: /* jump */
|
||||
assert( pC!=0 );
|
||||
assert( pC->deferredMoveto==0 );
|
||||
assert( pC->eCurType==CURTYPE_BTREE );
|
||||
assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
|
||||
assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
|
||||
|
||||
/* The Next opcode is only used after SeekGT, SeekGE, Rewind, and Found.
|
||||
** The Prev opcode is only used after SeekLT, SeekLE, and Last. */
|
||||
assert( pOp->opcode!=OP_Next
|
||||
|| pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
|
||||
assert( pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
|
||||
|| pC->seekOp==OP_Rewind || pC->seekOp==OP_Found
|
||||
|| pC->seekOp==OP_NullRow|| pC->seekOp==OP_SeekRowid
|
||||
|| pC->seekOp==OP_IfNoHope);
|
||||
assert( pOp->opcode!=OP_Prev
|
||||
|| pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
|
||||
|| pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope
|
||||
|| pC->seekOp==OP_NullRow);
|
||||
rc = sqlite3BtreeNext(pC->uc.pCursor, pOp->p3);
|
||||
|
||||
rc = pOp->p4.xAdvance(pC->uc.pCursor, pOp->p3);
|
||||
next_tail:
|
||||
pC->cacheStatus = CACHE_STALE;
|
||||
VdbeBranchTaken(rc==SQLITE_OK,2);
|
||||
@@ -6159,10 +6233,11 @@ case OP_IdxRowid: { /* out2 */
|
||||
pTabCur->nullRow = 0;
|
||||
pTabCur->movetoTarget = rowid;
|
||||
pTabCur->deferredMoveto = 1;
|
||||
pTabCur->cacheStatus = CACHE_STALE;
|
||||
assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
|
||||
pTabCur->aAltMap = pOp->p4.ai;
|
||||
assert( !pC->isEphemeral );
|
||||
assert( !pTabCur->isEphemeral );
|
||||
pTabCur->ub.aAltMap = pOp->p4.ai;
|
||||
assert( !pC->isEphemeral );
|
||||
pTabCur->pAltCursor = pC;
|
||||
}else{
|
||||
pOut = out2Prerelease(p, pOp);
|
||||
@@ -6293,7 +6368,7 @@ case OP_IdxGE: { /* jump */
|
||||
rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m);
|
||||
if( rc ) goto abort_due_to_error;
|
||||
res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, &r, 0);
|
||||
sqlite3VdbeMemRelease(&m);
|
||||
sqlite3VdbeMemReleaseMalloc(&m);
|
||||
}
|
||||
/* End of inlined sqlite3VdbeIdxKeyCompare() */
|
||||
|
||||
@@ -7684,7 +7759,7 @@ case OP_VOpen: {
|
||||
pVCur->pVtab = pVtab;
|
||||
|
||||
/* Initialize vdbe cursor object */
|
||||
pCur = allocateCursor(p, pOp->p1, 0, -1, CURTYPE_VTAB);
|
||||
pCur = allocateCursor(p, pOp->p1, 0, CURTYPE_VTAB);
|
||||
if( pCur ){
|
||||
pCur->uc.pVCur = pVCur;
|
||||
pVtab->nRef++;
|
||||
@@ -7697,6 +7772,34 @@ case OP_VOpen: {
|
||||
}
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
/* Opcode: VInitIn P1 P2 P3 * *
|
||||
** Synopsis: r[P2]=ValueList(P1,P3)
|
||||
**
|
||||
** Set register P2 to be a pointer to a ValueList object for cursor P1
|
||||
** with cache register P3 and output register P3+1. This ValueList object
|
||||
** can be used as the first argument to sqlite3_vtab_in_first() and
|
||||
** sqlite3_vtab_in_next() to extract all of the values stored in the P1
|
||||
** cursor. Register P3 is used to hold the values returned by
|
||||
** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
|
||||
*/
|
||||
case OP_VInitIn: { /* out2 */
|
||||
VdbeCursor *pC; /* The cursor containing the RHS values */
|
||||
ValueList *pRhs; /* New ValueList object to put in reg[P2] */
|
||||
|
||||
pC = p->apCsr[pOp->p1];
|
||||
pRhs = sqlite3_malloc64( sizeof(*pRhs) );
|
||||
if( pRhs==0 ) goto no_mem;
|
||||
pRhs->pCsr = pC->uc.pCursor;
|
||||
pRhs->pOut = &aMem[pOp->p3];
|
||||
pOut = out2Prerelease(p, pOp);
|
||||
pOut->flags = MEM_Null;
|
||||
sqlite3VdbeMemSetPointer(pOut, pRhs, "ValueList", sqlite3_free);
|
||||
break;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
/* Opcode: VFilter P1 P2 P3 P4 *
|
||||
** Synopsis: iplan=r[P3] zplan='P4'
|
||||
@@ -7735,6 +7838,7 @@ case OP_VFilter: { /* jump */
|
||||
pCur = p->apCsr[pOp->p1];
|
||||
assert( memIsValid(pQuery) );
|
||||
REGISTER_TRACE(pOp->p3, pQuery);
|
||||
assert( pCur!=0 );
|
||||
assert( pCur->eCurType==CURTYPE_VTAB );
|
||||
pVCur = pCur->uc.pVCur;
|
||||
pVtab = pVCur->pVtab;
|
||||
@@ -7783,6 +7887,7 @@ case OP_VColumn: {
|
||||
sqlite3_context sContext;
|
||||
|
||||
VdbeCursor *pCur = p->apCsr[pOp->p1];
|
||||
assert( pCur!=0 );
|
||||
assert( pCur->eCurType==CURTYPE_VTAB );
|
||||
assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
|
||||
pDest = &aMem[pOp->p3];
|
||||
@@ -7836,6 +7941,7 @@ case OP_VNext: { /* jump */
|
||||
VdbeCursor *pCur;
|
||||
|
||||
pCur = p->apCsr[pOp->p1];
|
||||
assert( pCur!=0 );
|
||||
assert( pCur->eCurType==CURTYPE_VTAB );
|
||||
if( pCur->nullRow ){
|
||||
break;
|
||||
@@ -7931,7 +8037,7 @@ case OP_VUpdate: {
|
||||
const sqlite3_module *pModule;
|
||||
int nArg;
|
||||
int i;
|
||||
sqlite_int64 rowid;
|
||||
sqlite_int64 rowid = 0;
|
||||
Mem **apArg;
|
||||
Mem *pX;
|
||||
|
||||
@@ -8119,6 +8225,77 @@ case OP_Function: { /* group */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: FilterAdd P1 * P3 P4 *
|
||||
** Synopsis: filter(P1) += key(P3@P4)
|
||||
**
|
||||
** Compute a hash on the P4 registers starting with r[P3] and
|
||||
** add that hash to the bloom filter contained in r[P1].
|
||||
*/
|
||||
case OP_FilterAdd: {
|
||||
u64 h;
|
||||
|
||||
assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
|
||||
pIn1 = &aMem[pOp->p1];
|
||||
assert( pIn1->flags & MEM_Blob );
|
||||
assert( pIn1->n>0 );
|
||||
h = filterHash(aMem, pOp);
|
||||
#ifdef SQLITE_DEBUG
|
||||
if( db->flags&SQLITE_VdbeTrace ){
|
||||
int ii;
|
||||
for(ii=pOp->p3; ii<pOp->p3+pOp->p4.i; ii++){
|
||||
registerTrace(ii, &aMem[ii]);
|
||||
}
|
||||
printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n));
|
||||
}
|
||||
#endif
|
||||
h %= pIn1->n;
|
||||
pIn1->z[h/8] |= 1<<(h&7);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: Filter P1 P2 P3 P4 *
|
||||
** Synopsis: if key(P3@P4) not in filter(P1) goto P2
|
||||
**
|
||||
** Compute a hash on the key contained in the P4 registers starting
|
||||
** with r[P3]. Check to see if that hash is found in the
|
||||
** bloom filter hosted by register P1. If it is not present then
|
||||
** maybe jump to P2. Otherwise fall through.
|
||||
**
|
||||
** False negatives are harmless. It is always safe to fall through,
|
||||
** even if the value is in the bloom filter. A false negative causes
|
||||
** more CPU cycles to be used, but it should still yield the correct
|
||||
** answer. However, an incorrect answer may well arise from a
|
||||
** false positive - if the jump is taken when it should fall through.
|
||||
*/
|
||||
case OP_Filter: { /* jump */
|
||||
u64 h;
|
||||
|
||||
assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
|
||||
pIn1 = &aMem[pOp->p1];
|
||||
assert( (pIn1->flags & MEM_Blob)!=0 );
|
||||
assert( pIn1->n >= 1 );
|
||||
h = filterHash(aMem, pOp);
|
||||
#ifdef SQLITE_DEBUG
|
||||
if( db->flags&SQLITE_VdbeTrace ){
|
||||
int ii;
|
||||
for(ii=pOp->p3; ii<pOp->p3+pOp->p4.i; ii++){
|
||||
registerTrace(ii, &aMem[ii]);
|
||||
}
|
||||
printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n));
|
||||
}
|
||||
#endif
|
||||
h %= pIn1->n;
|
||||
if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){
|
||||
VdbeBranchTaken(1, 2);
|
||||
p->aCounter[SQLITE_STMTSTATUS_FILTER_HIT]++;
|
||||
goto jump_to_p2;
|
||||
}else{
|
||||
p->aCounter[SQLITE_STMTSTATUS_FILTER_MISS]++;
|
||||
VdbeBranchTaken(0, 2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: Trace P1 P2 * P4 *
|
||||
**
|
||||
** Write P4 on the statement trace output if statement tracing is
|
||||
@@ -8378,7 +8555,14 @@ abort_due_to_error:
|
||||
assert( rc );
|
||||
#ifdef SQLITE_DEBUG
|
||||
if( db->flags & SQLITE_VdbeTrace ){
|
||||
printf("ABORT-due-to-error. rc=%d\n", rc);
|
||||
const char *zTrace = p->zSql;
|
||||
if( zTrace==0 ){
|
||||
if( aOp[0].opcode==OP_Trace ){
|
||||
zTrace = aOp[0].p4.z;
|
||||
}
|
||||
if( zTrace==0 ) zTrace = "???";
|
||||
}
|
||||
printf("ABORT-due-to-error (rc=%d): %s\n", rc, zTrace);
|
||||
}
|
||||
#endif
|
||||
if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
|
||||
@@ -8391,6 +8575,9 @@ abort_due_to_error:
|
||||
(int)(pOp - aOp), p->zSql, p->zErrMsg);
|
||||
sqlite3VdbeHalt(p);
|
||||
if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db);
|
||||
if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){
|
||||
db->flags |= SQLITE_CorruptRdOnly;
|
||||
}
|
||||
rc = SQLITE_ERROR;
|
||||
if( resetSchemaOnFault>0 ){
|
||||
sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
|
||||
|
||||
+12
-15
@@ -63,7 +63,6 @@ struct VdbeOp {
|
||||
#ifdef SQLITE_ENABLE_CURSOR_HINTS
|
||||
Expr *pExpr; /* Used when p4type is P4_EXPR */
|
||||
#endif
|
||||
int (*xAdvance)(BtCursor *, int);
|
||||
} p4;
|
||||
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
char *zComment; /* Comment to improve readability */
|
||||
@@ -114,21 +113,19 @@ typedef struct VdbeOpList VdbeOpList;
|
||||
#define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */
|
||||
#define P4_INT32 (-3) /* P4 is a 32-bit signed integer */
|
||||
#define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */
|
||||
#define P4_ADVANCE (-5) /* P4 is a pointer to BtreeNext() or BtreePrev() */
|
||||
#define P4_TABLE (-6) /* P4 is a pointer to a Table structure */
|
||||
#define P4_TABLE (-5) /* P4 is a pointer to a Table structure */
|
||||
/* Above do not own any resources. Must free those below */
|
||||
#define P4_FREE_IF_LE (-7)
|
||||
#define P4_DYNAMIC (-7) /* Pointer to memory from sqliteMalloc() */
|
||||
#define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */
|
||||
#define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */
|
||||
#define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */
|
||||
#define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */
|
||||
#define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */
|
||||
#define P4_REAL (-13) /* P4 is a 64-bit floating point value */
|
||||
#define P4_INT64 (-14) /* P4 is a 64-bit signed integer */
|
||||
#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
|
||||
#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */
|
||||
#define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */
|
||||
#define P4_FREE_IF_LE (-6)
|
||||
#define P4_DYNAMIC (-6) /* Pointer to memory from sqliteMalloc() */
|
||||
#define P4_FUNCDEF (-7) /* P4 is a pointer to a FuncDef structure */
|
||||
#define P4_KEYINFO (-8) /* P4 is a pointer to a KeyInfo structure */
|
||||
#define P4_EXPR (-9) /* P4 is a pointer to an Expr tree */
|
||||
#define P4_MEM (-10) /* P4 is a pointer to a Mem* structure */
|
||||
#define P4_VTAB (-11) /* P4 is a pointer to an sqlite3_vtab structure */
|
||||
#define P4_REAL (-12) /* P4 is a 64-bit floating point value */
|
||||
#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
|
||||
#define P4_INTARRAY (-14) /* P4 is a vector of 32-bit integers */
|
||||
#define P4_FUNCCTX (-15) /* P4 is a pointer to an sqlite3_context object */
|
||||
|
||||
/* Error message codes for OP_Halt */
|
||||
#define P5_ConstraintNotNull 1
|
||||
|
||||
+88
-34
@@ -75,7 +75,7 @@ typedef struct AuxData AuxData;
|
||||
typedef struct VdbeCursor VdbeCursor;
|
||||
struct VdbeCursor {
|
||||
u8 eCurType; /* One of the CURTYPE_* values above */
|
||||
i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
|
||||
i8 iDb; /* Index of cursor database in db->aDb[] */
|
||||
u8 nullRow; /* True if pointing to a row with no data */
|
||||
u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
|
||||
u8 isTable; /* True for rowid tables. False for indexes */
|
||||
@@ -88,9 +88,11 @@ struct VdbeCursor {
|
||||
Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
|
||||
Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */
|
||||
u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
|
||||
Btree *pBtx; /* Separate file holding temporary table */
|
||||
union { /* pBtx for isEphermeral. pAltMap otherwise */
|
||||
Btree *pBtx; /* Separate file holding temporary table */
|
||||
u32 *aAltMap; /* Mapping from table to index column numbers */
|
||||
} ub;
|
||||
i64 seqCount; /* Sequence counter */
|
||||
u32 *aAltMap; /* Mapping from table to index column numbers */
|
||||
|
||||
/* Cached OP_Column parse information is only valid if cacheStatus matches
|
||||
** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
|
||||
@@ -206,16 +208,16 @@ struct sqlite3_value {
|
||||
const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */
|
||||
FuncDef *pDef; /* Used only when flags==MEM_Agg */
|
||||
} u;
|
||||
char *z; /* String or BLOB value */
|
||||
int n; /* Number of characters in string value, excluding '\0' */
|
||||
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
|
||||
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
|
||||
u8 eSubtype; /* Subtype for this value */
|
||||
int n; /* Number of characters in string value, excluding '\0' */
|
||||
char *z; /* String or BLOB value */
|
||||
/* ShallowCopy only needs to copy the information above */
|
||||
char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
|
||||
sqlite3 *db; /* The associated database connection */
|
||||
int szMalloc; /* Size of the zMalloc allocation */
|
||||
u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */
|
||||
sqlite3 *db; /* The associated database connection */
|
||||
char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
|
||||
void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
|
||||
#ifdef SQLITE_DEBUG
|
||||
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
|
||||
@@ -227,11 +229,43 @@ struct sqlite3_value {
|
||||
** Size of struct Mem not including the Mem.zMalloc member or anything that
|
||||
** follows.
|
||||
*/
|
||||
#define MEMCELLSIZE offsetof(Mem,zMalloc)
|
||||
#define MEMCELLSIZE offsetof(Mem,db)
|
||||
|
||||
/* One or more of the following flags are set to indicate the validOK
|
||||
/* One or more of the following flags are set to indicate the
|
||||
** representations of the value stored in the Mem struct.
|
||||
**
|
||||
** * MEM_Null An SQL NULL value
|
||||
**
|
||||
** * MEM_Null|MEM_Zero An SQL NULL with the virtual table
|
||||
** UPDATE no-change flag set
|
||||
**
|
||||
** * MEM_Null|MEM_Term| An SQL NULL, but also contains a
|
||||
** MEM_Subtype pointer accessible using
|
||||
** sqlite3_value_pointer().
|
||||
**
|
||||
** * MEM_Null|MEM_Cleared Special SQL NULL that compares non-equal
|
||||
** to other NULLs even using the IS operator.
|
||||
**
|
||||
** * MEM_Str A string, stored in Mem.z with
|
||||
** length Mem.n. Zero-terminated if
|
||||
** MEM_Term is set. This flag is
|
||||
** incompatible with MEM_Blob and
|
||||
** MEM_Null, but can appear with MEM_Int,
|
||||
** MEM_Real, and MEM_IntReal.
|
||||
**
|
||||
** * MEM_Blob A blob, stored in Mem.z length Mem.n.
|
||||
** Incompatible with MEM_Str, MEM_Null,
|
||||
** MEM_Int, MEM_Real, and MEM_IntReal.
|
||||
**
|
||||
** * MEM_Blob|MEM_Zero A blob in Mem.z of length Mem.n plus
|
||||
** MEM.u.i extra 0x00 bytes at the end.
|
||||
**
|
||||
** * MEM_Int Integer stored in Mem.u.i.
|
||||
**
|
||||
** * MEM_Real Real stored in Mem.u.r.
|
||||
**
|
||||
** * MEM_IntReal Real stored as an integer in Mem.u.i.
|
||||
**
|
||||
** If the MEM_Null flag is set, then the value is an SQL NULL value.
|
||||
** For a pointer type created using sqlite3_bind_pointer() or
|
||||
** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
|
||||
@@ -242,6 +276,7 @@ struct sqlite3_value {
|
||||
** set, then the string is nul terminated. The MEM_Int and MEM_Real
|
||||
** flags may coexist with the MEM_Str flag.
|
||||
*/
|
||||
#define MEM_Undefined 0x0000 /* Value is undefined */
|
||||
#define MEM_Null 0x0001 /* Value is NULL (or a pointer) */
|
||||
#define MEM_Str 0x0002 /* Value is a string */
|
||||
#define MEM_Int 0x0004 /* Value is an integer */
|
||||
@@ -249,28 +284,24 @@ struct sqlite3_value {
|
||||
#define MEM_Blob 0x0010 /* Value is a BLOB */
|
||||
#define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */
|
||||
#define MEM_AffMask 0x003f /* Mask of affinity bits */
|
||||
#define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */
|
||||
#define MEM_Undefined 0x0080 /* Value is undefined */
|
||||
#define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
|
||||
#define MEM_TypeMask 0xc1bf /* Mask of type bits */
|
||||
|
||||
|
||||
/* Whenever Mem contains a valid string or blob representation, one of
|
||||
** the following flags must be set to determine the memory management
|
||||
** policy for Mem.z. The MEM_Term flag tells us whether or not the
|
||||
** string is \000 or \u0000 terminated
|
||||
/* Extra bits that modify the meanings of the core datatypes above
|
||||
*/
|
||||
#define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */
|
||||
/* 0x0080 // Available */
|
||||
#define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
|
||||
#define MEM_Term 0x0200 /* String in Mem.z is zero terminated */
|
||||
#define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
|
||||
#define MEM_Static 0x0800 /* Mem.z points to a static string */
|
||||
#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
|
||||
#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
|
||||
#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
|
||||
#define MEM_Subtype 0x8000 /* Mem.eSubtype is valid */
|
||||
#ifdef SQLITE_OMIT_INCRBLOB
|
||||
#undef MEM_Zero
|
||||
#define MEM_Zero 0x0000
|
||||
#endif
|
||||
#define MEM_Zero 0x0400 /* Mem.i contains count of 0s appended to blob */
|
||||
#define MEM_Subtype 0x0800 /* Mem.eSubtype is valid */
|
||||
#define MEM_TypeMask 0x0dbf /* Mask of type bits */
|
||||
|
||||
/* Bits that determine the storage for Mem.z for a string or blob or
|
||||
** aggregate accumulator.
|
||||
*/
|
||||
#define MEM_Dyn 0x1000 /* Need to call Mem.xDel() on Mem.z */
|
||||
#define MEM_Static 0x2000 /* Mem.z points to a static string */
|
||||
#define MEM_Ephem 0x4000 /* Mem.z points to an ephemeral string */
|
||||
#define MEM_Agg 0x8000 /* Mem.z points to an agg function context */
|
||||
|
||||
/* Return TRUE if Mem X contains dynamically allocated content - anything
|
||||
** that needs to be deallocated to avoid a leak.
|
||||
@@ -292,11 +323,15 @@ struct sqlite3_value {
|
||||
&& (X)->n==0 && (X)->u.nZero==0)
|
||||
|
||||
/*
|
||||
** Return true if a memory cell is not marked as invalid. This macro
|
||||
** Return true if a memory cell has been initialized and is valid.
|
||||
** is for use inside assert() statements only.
|
||||
**
|
||||
** A Memory cell is initialized if at least one of the
|
||||
** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits
|
||||
** is set. It is "undefined" if all those bits are zero.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
#define memIsValid(M) ((M)->flags & MEM_Undefined)==0
|
||||
#define memIsValid(M) ((M)->flags & MEM_AffMask)!=0
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -430,7 +465,7 @@ struct Vdbe {
|
||||
bft bIsReader:1; /* True for statements that read */
|
||||
yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
|
||||
yDbMask lockMask; /* Subset of btreeMask that requires a lock */
|
||||
u32 aCounter[7]; /* Counters used by sqlite3_stmt_status() */
|
||||
u32 aCounter[9]; /* Counters used by sqlite3_stmt_status() */
|
||||
char *zSql; /* Text of the SQL statement that generated this */
|
||||
#ifdef SQLITE_ENABLE_NORMALIZE
|
||||
char *zNormSql; /* Normalization of the associated SQL statement */
|
||||
@@ -480,19 +515,37 @@ struct PreUpdate {
|
||||
Index *pPk; /* PK index if pTab is WITHOUT ROWID */
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of this object is used to pass an vector of values into
|
||||
** OP_VFilter, the xFilter method of a virtual table. The vector is the
|
||||
** set of values on the right-hand side of an IN constraint.
|
||||
**
|
||||
** The value as passed into xFilter is an sqlite3_value with a "pointer"
|
||||
** type, such as is generated by sqlite3_result_pointer() and read by
|
||||
** sqlite3_value_pointer. Such values have MEM_Term|MEM_Subtype|MEM_Null
|
||||
** and a subtype of 'p'. The sqlite3_vtab_in_first() and _next() interfaces
|
||||
** know how to use this object to step through all the values in the
|
||||
** right operand of the IN constraint.
|
||||
*/
|
||||
typedef struct ValueList ValueList;
|
||||
struct ValueList {
|
||||
BtCursor *pCsr; /* An ephemeral table holding all values */
|
||||
sqlite3_value *pOut; /* Register to hold each decoded output value */
|
||||
};
|
||||
|
||||
/*
|
||||
** Function prototypes
|
||||
*/
|
||||
void sqlite3VdbeError(Vdbe*, const char *, ...);
|
||||
void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
|
||||
void sqliteVdbePopStack(Vdbe*,int);
|
||||
int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p);
|
||||
int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
|
||||
int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*);
|
||||
int sqlite3VdbeCursorRestore(VdbeCursor*);
|
||||
u32 sqlite3VdbeSerialTypeLen(u32);
|
||||
u8 sqlite3VdbeOneByteSerialTypeLen(u8);
|
||||
u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
|
||||
u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
|
||||
void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
|
||||
void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int);
|
||||
|
||||
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
|
||||
@@ -538,7 +591,7 @@ int sqlite3VdbeMemSetRowSet(Mem*);
|
||||
int sqlite3VdbeMemMakeWriteable(Mem*);
|
||||
int sqlite3VdbeMemStringify(Mem*, u8, u8);
|
||||
int sqlite3IntFloatCompare(i64,double);
|
||||
i64 sqlite3VdbeIntValue(Mem*);
|
||||
i64 sqlite3VdbeIntValue(const Mem*);
|
||||
int sqlite3VdbeMemIntegerify(Mem*);
|
||||
double sqlite3VdbeRealValue(Mem*);
|
||||
int sqlite3VdbeBooleanValue(Mem*, int ifNull);
|
||||
@@ -549,6 +602,7 @@ int sqlite3VdbeMemCast(Mem*,u8,u8);
|
||||
int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
|
||||
int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*);
|
||||
void sqlite3VdbeMemRelease(Mem *p);
|
||||
void sqlite3VdbeMemReleaseMalloc(Mem*p);
|
||||
int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
|
||||
|
||||
+76
-5
@@ -345,6 +345,9 @@ sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){
|
||||
sqlite3ValueFree(pNew);
|
||||
pNew = 0;
|
||||
}
|
||||
}else if( pNew->flags & MEM_Null ){
|
||||
/* Do not duplicate pointer values */
|
||||
pNew->flags &= ~(MEM_Term|MEM_Subtype);
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
@@ -846,6 +849,70 @@ int sqlite3_vtab_nochange(sqlite3_context *p){
|
||||
return sqlite3_value_nochange(p->pOut);
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of sqlite3_vtab_in_first() (if bNext==0) and
|
||||
** sqlite3_vtab_in_next() (if bNext!=0).
|
||||
*/
|
||||
static int valueFromValueList(
|
||||
sqlite3_value *pVal, /* Pointer to the ValueList object */
|
||||
sqlite3_value **ppOut, /* Store the next value from the list here */
|
||||
int bNext /* 1 for _next(). 0 for _first() */
|
||||
){
|
||||
int rc;
|
||||
ValueList *pRhs;
|
||||
|
||||
*ppOut = 0;
|
||||
if( pVal==0 ) return SQLITE_MISUSE;
|
||||
pRhs = (ValueList*)sqlite3_value_pointer(pVal, "ValueList");
|
||||
if( pRhs==0 ) return SQLITE_MISUSE;
|
||||
if( bNext ){
|
||||
rc = sqlite3BtreeNext(pRhs->pCsr, 0);
|
||||
}else{
|
||||
int dummy = 0;
|
||||
rc = sqlite3BtreeFirst(pRhs->pCsr, &dummy);
|
||||
assert( rc==SQLITE_OK || sqlite3BtreeEof(pRhs->pCsr) );
|
||||
if( sqlite3BtreeEof(pRhs->pCsr) ) rc = SQLITE_DONE;
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
u32 sz; /* Size of current row in bytes */
|
||||
Mem sMem; /* Raw content of current row */
|
||||
memset(&sMem, 0, sizeof(sMem));
|
||||
sz = sqlite3BtreePayloadSize(pRhs->pCsr);
|
||||
rc = sqlite3VdbeMemFromBtreeZeroOffset(pRhs->pCsr,(int)sz,&sMem);
|
||||
if( rc==SQLITE_OK ){
|
||||
u8 *zBuf = (u8*)sMem.z;
|
||||
u32 iSerial;
|
||||
sqlite3_value *pOut = pRhs->pOut;
|
||||
int iOff = 1 + getVarint32(&zBuf[1], iSerial);
|
||||
sqlite3VdbeSerialGet(&zBuf[iOff], iSerial, pOut);
|
||||
pOut->enc = ENC(pOut->db);
|
||||
if( (pOut->flags & MEM_Ephem)!=0 && sqlite3VdbeMemMakeWriteable(pOut) ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
*ppOut = pOut;
|
||||
}
|
||||
}
|
||||
sqlite3VdbeMemRelease(&sMem);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the iterator value pVal to point to the first value in the set.
|
||||
** Set (*ppOut) to point to this value before returning.
|
||||
*/
|
||||
int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut){
|
||||
return valueFromValueList(pVal, ppOut, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the iterator value pVal to point to the next value in the set.
|
||||
** Set (*ppOut) to point to this value before returning.
|
||||
*/
|
||||
int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut){
|
||||
return valueFromValueList(pVal, ppOut, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the current time for a statement. If the current time
|
||||
** is requested more than once within the same run of a single prepared
|
||||
@@ -1040,15 +1107,15 @@ static const Mem *columnNullValue(void){
|
||||
#endif
|
||||
= {
|
||||
/* .u = */ {0},
|
||||
/* .z = */ (char*)0,
|
||||
/* .n = */ (int)0,
|
||||
/* .flags = */ (u16)MEM_Null,
|
||||
/* .enc = */ (u8)0,
|
||||
/* .eSubtype = */ (u8)0,
|
||||
/* .n = */ (int)0,
|
||||
/* .z = */ (char*)0,
|
||||
/* .zMalloc = */ (char*)0,
|
||||
/* .db = */ (sqlite3*)0,
|
||||
/* .szMalloc = */ (int)0,
|
||||
/* .uTemp = */ (u32)0,
|
||||
/* .db = */ (sqlite3*)0,
|
||||
/* .zMalloc = */ (char*)0,
|
||||
/* .xDel = */ (void(*)(void*))0,
|
||||
#ifdef SQLITE_DEBUG
|
||||
/* .pScopyFrom = */ (Mem*)0,
|
||||
@@ -1530,7 +1597,10 @@ int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
|
||||
break;
|
||||
}
|
||||
case SQLITE_FLOAT: {
|
||||
rc = sqlite3_bind_double(pStmt, i, pValue->u.r);
|
||||
assert( pValue->flags & (MEM_Real|MEM_IntReal) );
|
||||
rc = sqlite3_bind_double(pStmt, i,
|
||||
(pValue->flags & MEM_Real) ? pValue->u.r : (double)pValue->u.i
|
||||
);
|
||||
break;
|
||||
}
|
||||
case SQLITE_BLOB: {
|
||||
@@ -1850,6 +1920,7 @@ int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
|
||||
u32 nRec;
|
||||
u8 *aRec;
|
||||
|
||||
assert( p->pCsr->eCurType==CURTYPE_BTREE );
|
||||
nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor);
|
||||
aRec = sqlite3DbMallocRaw(db, nRec);
|
||||
if( !aRec ) goto preupdate_old_out;
|
||||
|
||||
+98
-109
@@ -180,7 +180,7 @@ static int growOpArray(Vdbe *v, int nOp){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
assert( nOp<=(1024/sizeof(Op)) );
|
||||
assert( nOp<=(int)(1024/sizeof(Op)) );
|
||||
assert( nNew>=(v->nOpAlloc+nOp) );
|
||||
pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
|
||||
if( pNew ){
|
||||
@@ -782,7 +782,7 @@ void sqlite3VdbeAssertAbortable(Vdbe *p){
|
||||
** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
|
||||
** indicate what the prepared statement actually does.
|
||||
**
|
||||
** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
|
||||
** (4) (discontinued)
|
||||
**
|
||||
** (5) Reclaim the memory allocated for storing labels.
|
||||
**
|
||||
@@ -828,25 +828,6 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
|
||||
p->bIsReader = 1;
|
||||
break;
|
||||
}
|
||||
case OP_Next:
|
||||
case OP_SorterNext: {
|
||||
pOp->p4.xAdvance = sqlite3BtreeNext;
|
||||
pOp->p4type = P4_ADVANCE;
|
||||
/* The code generator never codes any of these opcodes as a jump
|
||||
** to a label. They are always coded as a jump backwards to a
|
||||
** known address */
|
||||
assert( pOp->p2>=0 );
|
||||
break;
|
||||
}
|
||||
case OP_Prev: {
|
||||
pOp->p4.xAdvance = sqlite3BtreePrevious;
|
||||
pOp->p4type = P4_ADVANCE;
|
||||
/* The code generator never codes any of these opcodes as a jump
|
||||
** to a label. They are always coded as a jump backwards to a
|
||||
** known address */
|
||||
assert( pOp->p2>=0 );
|
||||
break;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
case OP_VUpdate: {
|
||||
if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
|
||||
@@ -1130,7 +1111,6 @@ static void freeP4(sqlite3 *db, int p4type, void *p4){
|
||||
case P4_REAL:
|
||||
case P4_INT64:
|
||||
case P4_DYNAMIC:
|
||||
case P4_DYNBLOB:
|
||||
case P4_INTARRAY: {
|
||||
sqlite3DbFree(db, p4);
|
||||
break;
|
||||
@@ -1378,8 +1358,7 @@ void sqlite3VdbeSetP4KeyInfo(Parse *pParse, Index *pIdx){
|
||||
*/
|
||||
static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
|
||||
assert( p->nOp>0 || p->aOp==0 );
|
||||
assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed
|
||||
|| p->pParse->nErr>0 );
|
||||
assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->pParse->nErr>0 );
|
||||
if( p->nOp ){
|
||||
assert( p->aOp );
|
||||
sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
|
||||
@@ -1728,10 +1707,6 @@ char *sqlite3VdbeDisplayP4(sqlite3 *db, Op *pOp){
|
||||
zP4 = "program";
|
||||
break;
|
||||
}
|
||||
case P4_DYNBLOB:
|
||||
case P4_ADVANCE: {
|
||||
break;
|
||||
}
|
||||
case P4_TABLE: {
|
||||
zP4 = pOp->p4.pTab->zName;
|
||||
break;
|
||||
@@ -1863,21 +1838,40 @@ void sqlite3VdbePrintOp(FILE *pOut, int pc, VdbeOp *pOp){
|
||||
|
||||
/*
|
||||
** Initialize an array of N Mem element.
|
||||
**
|
||||
** This is a high-runner, so only those fields that really do need to
|
||||
** be initialized are set. The Mem structure is organized so that
|
||||
** the fields that get initialized are nearby and hopefully on the same
|
||||
** cache line.
|
||||
**
|
||||
** Mem.flags = flags
|
||||
** Mem.db = db
|
||||
** Mem.szMalloc = 0
|
||||
**
|
||||
** All other fields of Mem can safely remain uninitialized for now. They
|
||||
** will be initialized before use.
|
||||
*/
|
||||
static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){
|
||||
while( (N--)>0 ){
|
||||
p->db = db;
|
||||
p->flags = flags;
|
||||
p->szMalloc = 0;
|
||||
if( N>0 ){
|
||||
do{
|
||||
p->flags = flags;
|
||||
p->db = db;
|
||||
p->szMalloc = 0;
|
||||
#ifdef SQLITE_DEBUG
|
||||
p->pScopyFrom = 0;
|
||||
p->pScopyFrom = 0;
|
||||
#endif
|
||||
p++;
|
||||
p++;
|
||||
}while( (--N)>0 );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Release an array of N Mem elements
|
||||
** Release auxiliary memory held in an array of N Mem elements.
|
||||
**
|
||||
** After this routine returns, all Mem elements in the array will still
|
||||
** be valid. Those Mem elements that were not holding auxiliary resources
|
||||
** will be unchanged. Mem elements which had something freed will be
|
||||
** set to MEM_Undefined.
|
||||
*/
|
||||
static void releaseMemArray(Mem *p, int N){
|
||||
if( p && N ){
|
||||
@@ -1910,12 +1904,17 @@ static void releaseMemArray(Mem *p, int N){
|
||||
if( p->flags&(MEM_Agg|MEM_Dyn) ){
|
||||
testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
|
||||
sqlite3VdbeMemRelease(p);
|
||||
p->flags = MEM_Undefined;
|
||||
}else if( p->szMalloc ){
|
||||
sqlite3DbFreeNN(db, p->zMalloc);
|
||||
p->szMalloc = 0;
|
||||
p->flags = MEM_Undefined;
|
||||
}
|
||||
|
||||
p->flags = MEM_Undefined;
|
||||
#ifdef SQLITE_DEBUG
|
||||
else{
|
||||
p->flags = MEM_Undefined;
|
||||
}
|
||||
#endif
|
||||
}while( (++p)<pEnd );
|
||||
}
|
||||
}
|
||||
@@ -2470,8 +2469,6 @@ void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
|
||||
if( pCx==0 ){
|
||||
return;
|
||||
}
|
||||
assert( pCx->pBtx==0 || pCx->eCurType==CURTYPE_BTREE );
|
||||
assert( pCx->pBtx==0 || pCx->isEphemeral );
|
||||
switch( pCx->eCurType ){
|
||||
case CURTYPE_SORTER: {
|
||||
sqlite3VdbeSorterClose(p->db, pCx);
|
||||
@@ -2997,7 +2994,7 @@ int sqlite3VdbeCheckFk(Vdbe *p, int deferred){
|
||||
p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
|
||||
p->errorAction = OE_Abort;
|
||||
sqlite3VdbeError(p, "FOREIGN KEY constraint failed");
|
||||
return SQLITE_ERROR;
|
||||
return SQLITE_CONSTRAINT_FOREIGNKEY;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -3056,9 +3053,15 @@ int sqlite3VdbeHalt(Vdbe *p){
|
||||
sqlite3VdbeEnter(p);
|
||||
|
||||
/* Check for one of the special errors */
|
||||
mrc = p->rc & 0xff;
|
||||
isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR
|
||||
|| mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL;
|
||||
if( p->rc ){
|
||||
mrc = p->rc & 0xff;
|
||||
isSpecialError = mrc==SQLITE_NOMEM
|
||||
|| mrc==SQLITE_IOERR
|
||||
|| mrc==SQLITE_INTERRUPT
|
||||
|| mrc==SQLITE_FULL;
|
||||
}else{
|
||||
mrc = isSpecialError = 0;
|
||||
}
|
||||
if( isSpecialError ){
|
||||
/* If the query was read-only and the error code is SQLITE_INTERRUPT,
|
||||
** no rollback is necessary. Otherwise, at least a savepoint
|
||||
@@ -3110,6 +3113,9 @@ int sqlite3VdbeHalt(Vdbe *p){
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
rc = SQLITE_CONSTRAINT_FOREIGNKEY;
|
||||
}else if( db->flags & SQLITE_CorruptRdOnly ){
|
||||
rc = SQLITE_CORRUPT;
|
||||
db->flags &= ~SQLITE_CorruptRdOnly;
|
||||
}else{
|
||||
/* The auto-commit flag is true, the vdbe program was successful
|
||||
** or hit an 'OR FAIL' constraint and there are no deferred foreign
|
||||
@@ -3243,6 +3249,7 @@ int sqlite3VdbeTransferError(Vdbe *p){
|
||||
sqlite3ValueSetNull(db->pErr);
|
||||
}
|
||||
db->errCode = rc;
|
||||
db->errByteOffset = -1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3522,7 +3529,7 @@ int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor *p){
|
||||
** is supposed to be pointing. If the row was deleted out from under the
|
||||
** cursor, set the cursor to point to a NULL row.
|
||||
*/
|
||||
static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){
|
||||
int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p){
|
||||
int isDifferentRow, rc;
|
||||
assert( p->eCurType==CURTYPE_BTREE );
|
||||
assert( p->uc.pCursor!=0 );
|
||||
@@ -3540,39 +3547,7 @@ static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){
|
||||
int sqlite3VdbeCursorRestore(VdbeCursor *p){
|
||||
assert( p->eCurType==CURTYPE_BTREE );
|
||||
if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
|
||||
return handleMovedCursor(p);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make sure the cursor p is ready to read or write the row to which it
|
||||
** was last positioned. Return an error code if an OOM fault or I/O error
|
||||
** prevents us from positioning the cursor to its correct position.
|
||||
**
|
||||
** If a MoveTo operation is pending on the given cursor, then do that
|
||||
** MoveTo now. If no move is pending, check to see if the row has been
|
||||
** deleted out from under the cursor and if it has, mark the row as
|
||||
** a NULL row.
|
||||
**
|
||||
** If the cursor is already pointing to the correct row and that row has
|
||||
** not been deleted out from under the cursor, then this routine is a no-op.
|
||||
*/
|
||||
int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){
|
||||
VdbeCursor *p = *pp;
|
||||
assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
|
||||
if( p->deferredMoveto ){
|
||||
u32 iMap;
|
||||
assert( !p->isEphemeral );
|
||||
if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){
|
||||
*pp = p->pAltCursor;
|
||||
*piCol = iMap - 1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
return sqlite3VdbeFinishMoveto(p);
|
||||
}
|
||||
if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
|
||||
return handleMovedCursor(p);
|
||||
return sqlite3VdbeHandleMovedCursor(p);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -3842,14 +3817,14 @@ u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){
|
||||
|
||||
/*
|
||||
** Deserialize the data blob pointed to by buf as serial type serial_type
|
||||
** and store the result in pMem. Return the number of bytes read.
|
||||
** and store the result in pMem.
|
||||
**
|
||||
** This function is implemented as two separate routines for performance.
|
||||
** The few cases that require local variables are broken out into a separate
|
||||
** routine so that in most cases the overhead of moving the stack pointer
|
||||
** is avoided.
|
||||
*/
|
||||
static u32 serialGet(
|
||||
static void serialGet(
|
||||
const unsigned char *buf, /* Buffer to deserialize from */
|
||||
u32 serial_type, /* Serial type to deserialize */
|
||||
Mem *pMem /* Memory cell to write value into */
|
||||
@@ -3883,9 +3858,8 @@ static u32 serialGet(
|
||||
memcpy(&pMem->u.r, &x, sizeof(x));
|
||||
pMem->flags = IsNaN(x) ? MEM_Null : MEM_Real;
|
||||
}
|
||||
return 8;
|
||||
}
|
||||
u32 sqlite3VdbeSerialGet(
|
||||
void sqlite3VdbeSerialGet(
|
||||
const unsigned char *buf, /* Buffer to deserialize from */
|
||||
u32 serial_type, /* Serial type to deserialize */
|
||||
Mem *pMem /* Memory cell to write value into */
|
||||
@@ -3896,13 +3870,13 @@ u32 sqlite3VdbeSerialGet(
|
||||
pMem->flags = MEM_Null|MEM_Zero;
|
||||
pMem->n = 0;
|
||||
pMem->u.nZero = 0;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case 11: /* Reserved for future use */
|
||||
case 0: { /* Null */
|
||||
/* EVIDENCE-OF: R-24078-09375 Value is a NULL. */
|
||||
pMem->flags = MEM_Null;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case 1: {
|
||||
/* EVIDENCE-OF: R-44885-25196 Value is an 8-bit twos-complement
|
||||
@@ -3910,7 +3884,7 @@ u32 sqlite3VdbeSerialGet(
|
||||
pMem->u.i = ONE_BYTE_INT(buf);
|
||||
pMem->flags = MEM_Int;
|
||||
testcase( pMem->u.i<0 );
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
case 2: { /* 2-byte signed integer */
|
||||
/* EVIDENCE-OF: R-49794-35026 Value is a big-endian 16-bit
|
||||
@@ -3918,7 +3892,7 @@ u32 sqlite3VdbeSerialGet(
|
||||
pMem->u.i = TWO_BYTE_INT(buf);
|
||||
pMem->flags = MEM_Int;
|
||||
testcase( pMem->u.i<0 );
|
||||
return 2;
|
||||
return;
|
||||
}
|
||||
case 3: { /* 3-byte signed integer */
|
||||
/* EVIDENCE-OF: R-37839-54301 Value is a big-endian 24-bit
|
||||
@@ -3926,7 +3900,7 @@ u32 sqlite3VdbeSerialGet(
|
||||
pMem->u.i = THREE_BYTE_INT(buf);
|
||||
pMem->flags = MEM_Int;
|
||||
testcase( pMem->u.i<0 );
|
||||
return 3;
|
||||
return;
|
||||
}
|
||||
case 4: { /* 4-byte signed integer */
|
||||
/* EVIDENCE-OF: R-01849-26079 Value is a big-endian 32-bit
|
||||
@@ -3938,7 +3912,7 @@ u32 sqlite3VdbeSerialGet(
|
||||
#endif
|
||||
pMem->flags = MEM_Int;
|
||||
testcase( pMem->u.i<0 );
|
||||
return 4;
|
||||
return;
|
||||
}
|
||||
case 5: { /* 6-byte signed integer */
|
||||
/* EVIDENCE-OF: R-50385-09674 Value is a big-endian 48-bit
|
||||
@@ -3946,13 +3920,14 @@ u32 sqlite3VdbeSerialGet(
|
||||
pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf);
|
||||
pMem->flags = MEM_Int;
|
||||
testcase( pMem->u.i<0 );
|
||||
return 6;
|
||||
return;
|
||||
}
|
||||
case 6: /* 8-byte signed integer */
|
||||
case 7: { /* IEEE floating point */
|
||||
/* These use local variables, so do them in a separate routine
|
||||
** to avoid having to move the frame pointer in the common case */
|
||||
return serialGet(buf,serial_type,pMem);
|
||||
serialGet(buf,serial_type,pMem);
|
||||
return;
|
||||
}
|
||||
case 8: /* Integer 0 */
|
||||
case 9: { /* Integer 1 */
|
||||
@@ -3960,7 +3935,7 @@ u32 sqlite3VdbeSerialGet(
|
||||
/* EVIDENCE-OF: R-18143-12121 Value is the integer 1. */
|
||||
pMem->u.i = serial_type-8;
|
||||
pMem->flags = MEM_Int;
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
/* EVIDENCE-OF: R-14606-31564 Value is a BLOB that is (N-12)/2 bytes in
|
||||
@@ -3971,10 +3946,10 @@ u32 sqlite3VdbeSerialGet(
|
||||
pMem->z = (char *)buf;
|
||||
pMem->n = (serial_type-12)/2;
|
||||
pMem->flags = aFlag[serial_type&1];
|
||||
return pMem->n;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
/*
|
||||
** This routine is used to allocate sufficient space for an UnpackedRecord
|
||||
@@ -4037,7 +4012,8 @@ void sqlite3VdbeRecordUnpack(
|
||||
/* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
|
||||
pMem->szMalloc = 0;
|
||||
pMem->z = 0;
|
||||
d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
|
||||
sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
|
||||
d += sqlite3VdbeSerialTypeLen(serial_type);
|
||||
pMem++;
|
||||
if( (++u)>=p->nField ) break;
|
||||
}
|
||||
@@ -4121,7 +4097,8 @@ static int vdbeRecordCompareDebug(
|
||||
|
||||
/* Extract the values to be compared.
|
||||
*/
|
||||
d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
|
||||
sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
|
||||
d1 += sqlite3VdbeSerialTypeLen(serial_type1);
|
||||
|
||||
/* Do the comparison
|
||||
*/
|
||||
@@ -4232,8 +4209,8 @@ static int vdbeCompareMemString(
|
||||
}else{
|
||||
rc = pColl->xCmp(pColl->pUser, c1.n, v1, c2.n, v2);
|
||||
}
|
||||
sqlite3VdbeMemRelease(&c1);
|
||||
sqlite3VdbeMemRelease(&c2);
|
||||
sqlite3VdbeMemReleaseMalloc(&c1);
|
||||
sqlite3VdbeMemReleaseMalloc(&c2);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -4757,7 +4734,8 @@ static int vdbeRecordCompareInt(
|
||||
return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2);
|
||||
}
|
||||
|
||||
v = pPKey2->aMem[0].u.i;
|
||||
assert( pPKey2->u.i == pPKey2->aMem[0].u.i );
|
||||
v = pPKey2->u.i;
|
||||
if( v>lhs ){
|
||||
res = pPKey2->r1;
|
||||
}else if( v<lhs ){
|
||||
@@ -4792,12 +4770,18 @@ static int vdbeRecordCompareString(
|
||||
int res;
|
||||
|
||||
assert( pPKey2->aMem[0].flags & MEM_Str );
|
||||
assert( pPKey2->aMem[0].n == pPKey2->n );
|
||||
assert( pPKey2->aMem[0].z == pPKey2->u.z );
|
||||
vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
|
||||
serial_type = (u8)(aKey1[1]);
|
||||
if( serial_type >= 0x80 ){
|
||||
sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type);
|
||||
}
|
||||
serial_type = (signed char)(aKey1[1]);
|
||||
|
||||
vrcs_restart:
|
||||
if( serial_type<12 ){
|
||||
if( serial_type<0 ){
|
||||
sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type);
|
||||
if( serial_type>=12 ) goto vrcs_restart;
|
||||
assert( CORRUPT_DB );
|
||||
}
|
||||
res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
|
||||
}else if( !(serial_type & 0x01) ){
|
||||
res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
|
||||
@@ -4811,15 +4795,15 @@ static int vdbeRecordCompareString(
|
||||
pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
|
||||
return 0; /* Corruption */
|
||||
}
|
||||
nCmp = MIN( pPKey2->aMem[0].n, nStr );
|
||||
res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp);
|
||||
nCmp = MIN( pPKey2->n, nStr );
|
||||
res = memcmp(&aKey1[szHdr], pPKey2->u.z, nCmp);
|
||||
|
||||
if( res>0 ){
|
||||
res = pPKey2->r2;
|
||||
}else if( res<0 ){
|
||||
res = pPKey2->r1;
|
||||
}else{
|
||||
res = nStr - pPKey2->aMem[0].n;
|
||||
res = nStr - pPKey2->n;
|
||||
if( res==0 ){
|
||||
if( pPKey2->nField>1 ){
|
||||
res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
|
||||
@@ -4874,6 +4858,7 @@ RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){
|
||||
p->r2 = 1;
|
||||
}
|
||||
if( (flags & MEM_Int) ){
|
||||
p->u.i = p->aMem[0].u.i;
|
||||
return vdbeRecordCompareInt;
|
||||
}
|
||||
testcase( flags & MEM_Real );
|
||||
@@ -4883,6 +4868,8 @@ RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){
|
||||
&& p->pKeyInfo->aColl[0]==0
|
||||
){
|
||||
assert( flags & MEM_Str );
|
||||
p->u.z = p->aMem[0].z;
|
||||
p->n = p->aMem[0].n;
|
||||
return vdbeRecordCompareString;
|
||||
}
|
||||
}
|
||||
@@ -4925,7 +4912,7 @@ int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
|
||||
/* The index entry must begin with a header size */
|
||||
getVarint32NR((u8*)m.z, szHdr);
|
||||
testcase( szHdr==3 );
|
||||
testcase( szHdr==m.n );
|
||||
testcase( szHdr==(u32)m.n );
|
||||
testcase( szHdr>0x7fffffff );
|
||||
assert( m.n>=0 );
|
||||
if( unlikely(szHdr<3 || szHdr>(unsigned)m.n) ){
|
||||
@@ -4955,14 +4942,14 @@ int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
|
||||
/* Fetch the integer off the end of the index record */
|
||||
sqlite3VdbeSerialGet((u8*)&m.z[m.n-lenRowid], typeRowid, &v);
|
||||
*rowid = v.u.i;
|
||||
sqlite3VdbeMemRelease(&m);
|
||||
sqlite3VdbeMemReleaseMalloc(&m);
|
||||
return SQLITE_OK;
|
||||
|
||||
/* Jump here if database corruption is detected after m has been
|
||||
** allocated. Free the m object and return SQLITE_CORRUPT. */
|
||||
idx_rowid_corruption:
|
||||
testcase( m.szMalloc!=0 );
|
||||
sqlite3VdbeMemRelease(&m);
|
||||
sqlite3VdbeMemReleaseMalloc(&m);
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
|
||||
@@ -5004,7 +4991,7 @@ int sqlite3VdbeIdxKeyCompare(
|
||||
return rc;
|
||||
}
|
||||
*res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0);
|
||||
sqlite3VdbeMemRelease(&m);
|
||||
sqlite3VdbeMemReleaseMalloc(&m);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -5171,7 +5158,7 @@ static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){
|
||||
int i;
|
||||
for(i=0; i<nField; i++){
|
||||
Mem *pMem = &p->aMem[i];
|
||||
if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
|
||||
if( pMem->zMalloc ) sqlite3VdbeMemReleaseMalloc(pMem);
|
||||
}
|
||||
sqlite3DbFreeNN(db, p);
|
||||
}
|
||||
@@ -5214,6 +5201,8 @@ void sqlite3VdbePreUpdateHook(
|
||||
}
|
||||
}
|
||||
|
||||
assert( pCsr!=0 );
|
||||
assert( pCsr->eCurType==CURTYPE_BTREE );
|
||||
assert( pCsr->nField==pTab->nCol
|
||||
|| (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1)
|
||||
);
|
||||
|
||||
+12
-6
@@ -75,7 +75,10 @@ static int blobSeekToRow(Incrblob *p, sqlite3_int64 iRow, char **pzErr){
|
||||
}
|
||||
if( rc==SQLITE_ROW ){
|
||||
VdbeCursor *pC = v->apCsr[0];
|
||||
u32 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0;
|
||||
u32 type;
|
||||
assert( pC!=0 );
|
||||
assert( pC->eCurType==CURTYPE_BTREE );
|
||||
type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0;
|
||||
testcase( pC->nHdrParsed==p->iCol );
|
||||
testcase( pC->nHdrParsed==p->iCol+1 );
|
||||
if( type<12 ){
|
||||
@@ -149,10 +152,9 @@ int sqlite3_blob_open(
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
|
||||
pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
|
||||
do {
|
||||
memset(&sParse, 0, sizeof(Parse));
|
||||
while(1){
|
||||
sqlite3ParseObjectInit(&sParse,db);
|
||||
if( !pBlob ) goto blob_open_out;
|
||||
sParse.db = db;
|
||||
sqlite3DbFree(db, zErr);
|
||||
zErr = 0;
|
||||
|
||||
@@ -329,7 +331,9 @@ int sqlite3_blob_open(
|
||||
goto blob_open_out;
|
||||
}
|
||||
rc = blobSeekToRow(pBlob, iRow, &zErr);
|
||||
} while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA );
|
||||
if( (++nAttempt)>=SQLITE_MAX_SCHEMA_RETRY || rc!=SQLITE_SCHEMA ) break;
|
||||
sqlite3ParseObjectReset(&sParse);
|
||||
}
|
||||
|
||||
blob_open_out:
|
||||
if( rc==SQLITE_OK && db->mallocFailed==0 ){
|
||||
@@ -340,7 +344,7 @@ blob_open_out:
|
||||
}
|
||||
sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
|
||||
sqlite3DbFree(db, zErr);
|
||||
sqlite3ParserReset(&sParse);
|
||||
sqlite3ParseObjectReset(&sParse);
|
||||
rc = sqlite3ApiExit(db, rc);
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return rc;
|
||||
@@ -420,6 +424,8 @@ static int blobReadWrite(
|
||||
*/
|
||||
sqlite3_int64 iKey;
|
||||
iKey = sqlite3BtreeIntegerKey(p->pCsr);
|
||||
assert( v->apCsr[0]!=0 );
|
||||
assert( v->apCsr[0]->eCurType==CURTYPE_BTREE );
|
||||
sqlite3VdbePreUpdateHook(
|
||||
v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol
|
||||
);
|
||||
|
||||
+12
-7
@@ -555,6 +555,14 @@ void sqlite3VdbeMemRelease(Mem *p){
|
||||
}
|
||||
}
|
||||
|
||||
/* Like sqlite3VdbeMemRelease() but faster for cases where we
|
||||
** know in advance that the Mem is not MEM_Dyn or MEM_Agg.
|
||||
*/
|
||||
void sqlite3VdbeMemReleaseMalloc(Mem *p){
|
||||
assert( !VdbeMemDynamic(p) );
|
||||
if( p->szMalloc ) vdbeMemClear(p);
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert a 64-bit IEEE double into a 64-bit signed integer.
|
||||
** If the double is out of range of a 64-bit signed integer then
|
||||
@@ -596,12 +604,12 @@ static SQLITE_NOINLINE i64 doubleToInt64(double r){
|
||||
**
|
||||
** If pMem represents a string value, its encoding might be changed.
|
||||
*/
|
||||
static SQLITE_NOINLINE i64 memIntValue(Mem *pMem){
|
||||
static SQLITE_NOINLINE i64 memIntValue(const Mem *pMem){
|
||||
i64 value = 0;
|
||||
sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
|
||||
return value;
|
||||
}
|
||||
i64 sqlite3VdbeIntValue(Mem *pMem){
|
||||
i64 sqlite3VdbeIntValue(const Mem *pMem){
|
||||
int flags;
|
||||
assert( pMem!=0 );
|
||||
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
|
||||
@@ -916,6 +924,7 @@ void sqlite3VdbeMemSetPointer(
|
||||
void (*xDestructor)(void*)
|
||||
){
|
||||
assert( pMem->flags==MEM_Null );
|
||||
vdbeMemClear(pMem);
|
||||
pMem->u.zPType = zPType ? zPType : "";
|
||||
pMem->z = pPtr;
|
||||
pMem->flags = MEM_Null|MEM_Dyn|MEM_Subtype|MEM_Term;
|
||||
@@ -1530,11 +1539,7 @@ static int valueFromExpr(
|
||||
|
||||
assert( pExpr!=0 );
|
||||
while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft;
|
||||
#if defined(SQLITE_ENABLE_STAT4)
|
||||
if( op==TK_REGISTER ) op = pExpr->op2;
|
||||
#else
|
||||
if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
|
||||
#endif
|
||||
|
||||
/* Compressed expressions only appear when parsing the DEFAULT clause
|
||||
** on a table column definition, and hence only when pCtx==0. This
|
||||
@@ -1649,7 +1654,7 @@ static int valueFromExpr(
|
||||
|
||||
no_mem:
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
if( pCtx==0 || pCtx->pParse->nErr==0 )
|
||||
if( pCtx==0 || NEVER(pCtx->pParse->nErr==0) )
|
||||
#endif
|
||||
sqlite3OomFault(db);
|
||||
sqlite3DbFree(db, zVal);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user