Compare commits
461 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f67fbdd1af | |||
| 158931ab64 | |||
| 37eca05112 | |||
| 150dfbd2c8 | |||
| 9b475e65a1 | |||
| 8ea00d744e | |||
| e639128cb0 | |||
| 323096175e | |||
| 971194aca3 | |||
| 579d41dc8d | |||
| 93673620ec | |||
| 523fb53f72 | |||
| 6adba9031c | |||
| 0364f229cc | |||
| 0e1a574875 | |||
| 86ec1eddde | |||
| 9e26ac852a | |||
| c3dcdba387 | |||
| c7f3373ec7 | |||
| a3020dcb21 | |||
| 25050f2620 | |||
| 427db2d245 | |||
| 7d683394f1 | |||
| ce3c3eeda0 | |||
| 7bbdc3c597 | |||
| f1722baaf8 | |||
| 6cf3009f6c | |||
| ce059e5219 | |||
| 94c7ab5038 | |||
| e3bd232e2d | |||
| 86223e8d65 | |||
| d1f9932e4b | |||
| 4c81cada05 | |||
| eacc8816dc | |||
| b84b38fd89 | |||
| 80ac9cb3c0 | |||
| 677525756b | |||
| eb80863cbf | |||
| 4e61e88348 | |||
| b92d7d264e | |||
| 3f49c321e8 | |||
| 0f134f0267 | |||
| 94809086e5 | |||
| 3de52e8fa0 | |||
| 3fda0aaf00 | |||
| 860d2b08c6 | |||
| e8975ac9e1 | |||
| 29ddbbbf36 | |||
| e0f20b46fb | |||
| d6db6598ca | |||
| afb3f3c72c | |||
| 1d07f1d8c7 | |||
| 495ed62e85 | |||
| 83c5bb997a | |||
| 21826f44bf | |||
| c906533650 | |||
| 6cbbcd8ad6 | |||
| 4e2d3d40dc | |||
| 8fe25c64f1 | |||
| ce5752cd1f | |||
| 3fc6042992 | |||
| 6f88359df6 | |||
| bf00f6d7ec | |||
| b336d1ab83 | |||
| 119e1ffc5e | |||
| 2c794b15a0 | |||
| 0708054570 | |||
| 7678fdc33d | |||
| 038ebf6875 | |||
| 3580843595 | |||
| a920b209ff | |||
| 5155b75be2 | |||
| 57b1a3e303 | |||
| d137f4e6e5 | |||
| f72a97925d | |||
| 4ded26a53c | |||
| 6f1644c0f9 | |||
| 0dc0e9c2af | |||
| fc15f4c528 | |||
| a2b6806b3e | |||
| 40f827a65e | |||
| 61ad5513e0 | |||
| ba9ee09598 | |||
| 725b1cfc53 | |||
| d4a591dd6b | |||
| b60c3b01cc | |||
| 1cb0263bcd | |||
| 65c29fd3eb | |||
| ccf6e7d0f0 | |||
| 346f4e264a | |||
| 58b42ad131 | |||
| 1c960269dd | |||
| af5a2e166d | |||
| e7476115ad | |||
| b17ea91230 | |||
| 21a3b3191e | |||
| b1b808b92d | |||
| 57494adcc5 | |||
| 781b7ac3f6 | |||
| ed26483346 | |||
| fb5567123f | |||
| 7ac2ee0a74 | |||
| e2bcbb4048 | |||
| dcc427cf19 | |||
| c7694a6d1d | |||
| 87c889cfa5 | |||
| 2381f6d7e5 | |||
| ff119f04b4 | |||
| e41fd72acc | |||
| 065f3bf4f2 | |||
| d0f820a7e6 | |||
| f3e90dd276 | |||
| 78694ea307 | |||
| 6603342f12 | |||
| 8eff0cc326 | |||
| 1d4b25fa50 | |||
| f012dc4eb9 | |||
| e5166e070a | |||
| b1dd3db537 | |||
| d430c2eb46 | |||
| 713836f913 | |||
| ced89124d8 | |||
| 0525b6f47f | |||
| 108e6b2c87 | |||
| bdabe742da | |||
| d406d07262 | |||
| b15f19c75e | |||
| 610f11de25 | |||
| faeeddf0f0 | |||
| 3756d59bc3 | |||
| 1e7cb19be3 | |||
| bf84515a2b | |||
| c782a81aa5 | |||
| aadf8327be | |||
| 25f5383cb8 | |||
| 1f3b284b11 | |||
| d35300f9b6 | |||
| a0f6b83300 | |||
| a49774f478 | |||
| 2e41b99ea9 | |||
| db7d895e9d | |||
| b6f2deac3c | |||
| b560a7194d | |||
| b65e801e5f | |||
| fcb02429ec | |||
| 2a934d75d9 | |||
| d446165f7d | |||
| bb40727857 | |||
| 935d9d8260 | |||
| 9e24439c2f | |||
| cc7a850f2e | |||
| a786e453a4 | |||
| 71fddaf195 | |||
| 72b9fdcf20 | |||
| f7b846e4ed | |||
| 0d86a9bd54 | |||
| 37f6ffb887 | |||
| 6c75b39614 | |||
| bcf1f41a62 | |||
| 4b986b2a47 | |||
| 66b8457c7c | |||
| 9a518843f5 | |||
| 54975cdff9 | |||
| c813750b7b | |||
| 00267b8a7b | |||
| b33487b0b6 | |||
| 39c5c4ae06 | |||
| aff0fd483c | |||
| aaad696141 | |||
| b25a214dec | |||
| 91ed9ce0dd | |||
| 7bf3133fef | |||
| 0a31dc201e | |||
| 4e72e62f3b | |||
| 680f6e8e2e | |||
| 4474e869fe | |||
| 75db74fdae | |||
| e22976c535 | |||
| 8f46f34e2d | |||
| f10c535fa5 | |||
| 10cc16c954 | |||
| b531aa8fd9 | |||
| 9cb0264041 | |||
| c06ede105d | |||
| 4ddf7f4211 | |||
| 95fdb63b7f | |||
| 45616c7f75 | |||
| 8e0f794d17 | |||
| 0319934322 | |||
| 89d249364e | |||
| f26b145385 | |||
| 69e224f88a | |||
| ddc28c23d5 | |||
| bfa70de117 | |||
| 5cb1ffc1bd | |||
| eaac9996ed | |||
| 2b454e0335 | |||
| 9ebe59d6ff | |||
| 8b738d0865 | |||
| c3017e7b4a | |||
| 7edcb11ca7 | |||
| f2e5c98613 | |||
| 7f414c0c0c | |||
| 4bdd26dfab | |||
| 50ef6716d2 | |||
| bc0a55cf0b | |||
| f030b37682 | |||
| 480c572f2d | |||
| 255a81f10a | |||
| dbdddc99d8 | |||
| 6a1bfc9a6d | |||
| 7e85e9033f | |||
| 8cf92890f2 | |||
| b1af9c603c | |||
| 042666e4fa | |||
| 2a98b586c8 | |||
| 2d441ce3f3 | |||
| 4bec44bdfa | |||
| 6d7f18d60c | |||
| 12fe9a0d25 | |||
| 3cbd2b7245 | |||
| 9df385ec3d | |||
| b43ac0021f | |||
| 56785a0a80 | |||
| e7c9ca41b2 | |||
| 9c7e44cddd | |||
| 82642f815b | |||
| c332e04310 | |||
| 5860a61d59 | |||
| 83acc14ad4 | |||
| f9101623a3 | |||
| 62e009f3d8 | |||
| 3e7800a9db | |||
| a941ff712d | |||
| 8357c662b3 | |||
| d4a6744b50 | |||
| 6813350966 | |||
| 43a6e4d3df | |||
| 47a30159e5 | |||
| c01f41cfa6 | |||
| 8cd2e4ae03 | |||
| 3fd7eaf3f2 | |||
| f0c48b1cd8 | |||
| 85a379b74b | |||
| b0ea9432a1 | |||
| 2fa619a3a8 | |||
| 298f45c641 | |||
| 16d7e87caa | |||
| 6ff7427733 | |||
| 1cf197583d | |||
| 8851e10017 | |||
| 1e30c7f369 | |||
| c9912d1706 | |||
| 24bfecab3c | |||
| af63892337 | |||
| e385d33a29 | |||
| 922b35801d | |||
| 9c5f734339 | |||
| 6e08c4a5e6 | |||
| 531230d006 | |||
| fbf6136c78 | |||
| 871b13492d | |||
| d0ee3a1e6d | |||
| 4acd754c79 | |||
| 01996dae49 | |||
| 569b1d9119 | |||
| d46b6f57c9 | |||
| fc4eeef9e7 | |||
| dee9be9b3b | |||
| d57936721b | |||
| 24545d2300 | |||
| 41e0717bcb | |||
| 53d30dd371 | |||
| af48257bc9 | |||
| a790882d63 | |||
| 88862d49a6 | |||
| f2305414cd | |||
| 4fc4ba771c | |||
| e2d2ad6ece | |||
| 83a635a267 | |||
| 3f83f59154 | |||
| 0062ddd4c9 | |||
| 81f44cdbfb | |||
| 41fc545147 | |||
| 150edadf58 | |||
| e5989723ba | |||
| 9b2bd91d9a | |||
| 8f5b14a5c2 | |||
| 844b900491 | |||
| 7ba03ea15a | |||
| 2964225247 | |||
| 9a6d01bff5 | |||
| 9c46c66c46 | |||
| 38a28a7434 | |||
| 26b7ec8b24 | |||
| 1c7d389a23 | |||
| abd7449478 | |||
| 3bf0d7a881 | |||
| 23a885956e | |||
| b92b019fe3 | |||
| 6a0db87a2f | |||
| 9b747068ba | |||
| 8bf4126c84 | |||
| da7a4c0f7a | |||
| 56b99ebc32 | |||
| 8d40673c84 | |||
| ba7bd02002 | |||
| a8614259c1 | |||
| 5a9c6bcc15 | |||
| dd579233e8 | |||
| 3f4f6823ac | |||
| 4551005332 | |||
| a046643820 | |||
| e25646d64c | |||
| eb2ed10ec0 | |||
| 3993397e6c | |||
| 4a7e9a25b6 | |||
| 3967d946c7 | |||
| e86974c619 | |||
| 95d5a88058 | |||
| c7def600bd | |||
| 6c43dbad98 | |||
| 9e35a61e59 | |||
| 0c873bf28a | |||
| c07eee7a50 | |||
| 05d49d1442 | |||
| 211a0857b9 | |||
| e5da9356e0 | |||
| e6a9efb976 | |||
| 32bb700a95 | |||
| b4e5039316 | |||
| 0814acd981 | |||
| b2e61bc66b | |||
| f69af053dc | |||
| 0578084507 | |||
| ed457037c4 | |||
| c2ea77e5b2 | |||
| e88609f23e | |||
| c1f6618217 | |||
| 31ab7d8e5c | |||
| 94f0a83421 | |||
| ba14c69b4f | |||
| 725a9c7f6c | |||
| df21659a40 | |||
| a47e709e89 | |||
| 813ed78054 | |||
| f467744d5f | |||
| 3cc9af2140 | |||
| 491b6d897d | |||
| b0c4c94996 | |||
| 936ade4dba | |||
| 55469bbafb | |||
| 6a02f237e3 | |||
| b4738ddb20 | |||
| a5f9f42a0e | |||
| e3dadac591 | |||
| f8f47dd8c5 | |||
| d99950310f | |||
| 4c7bdd1597 | |||
| ccfa550922 | |||
| 8e4fe01dda | |||
| c5ea2d474d | |||
| f186f0b058 | |||
| 178edcd774 | |||
| 6ca644818b | |||
| 247c1b4a0b | |||
| 2c7a73eaea | |||
| 9b13365bba | |||
| 87c3ad4537 | |||
| 129371553c | |||
| ac30553f76 | |||
| e6c628e98c | |||
| 50b910a8b5 | |||
| 7c04c69204 | |||
| 5976552a72 | |||
| 8ed07d1274 | |||
| 27a037354c | |||
| b8852ae083 | |||
| 93b6c1666d | |||
| 225b05795f | |||
| 6e0a75a2b8 | |||
| a86b20820d | |||
| 4c1c79035f | |||
| d00ad9a656 | |||
| 451297752c | |||
| ed968fa4cb | |||
| e3b89d2c5f | |||
| 0e14e98706 | |||
| 3cb79202f8 | |||
| 21908b2166 | |||
| 934d4f7bac | |||
| aa0f2d0efa | |||
| f66da6ce8e | |||
| 25fb50674f | |||
| 29c992cb04 | |||
| 0ad7aa8182 | |||
| 04fcef00ee | |||
| 30fdb45da0 | |||
| f20bbc5f69 | |||
| 8b20e4a3eb | |||
| e011ee2830 | |||
| 375afb8bda | |||
| 5e970a8f40 | |||
| fb8ac325d7 | |||
| 4ccb41fc99 | |||
| dfb5c963a0 | |||
| 1a39d2bb5c | |||
| a783931794 | |||
| 2d4e720579 | |||
| e2dcc42e1f | |||
| 58ed374370 | |||
| 9c039d9f2e | |||
| 9274ad898f | |||
| 4ead96348e | |||
| f8a488bb6b | |||
| 94ec92a1f7 | |||
| 4067ce7d54 | |||
| 68c1f9ce9a | |||
| d12db3dabb | |||
| b10a50e7f8 | |||
| f202c6cdcf | |||
| 0f1bf4c1ac | |||
| a1bd5c6aae | |||
| a79bcf358b | |||
| 951d165125 | |||
| 6214d93993 | |||
| b4439eef10 | |||
| 5d4589014a | |||
| 3e534eac19 | |||
| a2dc7494ef | |||
| 73bce66701 | |||
| 90294961da | |||
| 0ad63e5e0c | |||
| e6370e9c29 | |||
| 1735f91df4 | |||
| 2bd207ff6d | |||
| 2a58dbde30 | |||
| f10ce63651 | |||
| 1972c8cf07 | |||
| 26391eeefe | |||
| 51d35b0fa9 | |||
| e65b9c6a5e | |||
| 6ca98ad6b1 | |||
| f7d687c9d3 | |||
| 25e3073741 | |||
| c80864d77a | |||
| 69ab18d213 | |||
| 5f913ecb62 | |||
| c49d43a787 | |||
| a47e45f734 | |||
| 1757fed87f | |||
| 8eaf565feb | |||
| 3e08ba4521 | |||
| 885eeb676b | |||
| 2d77d80a65 | |||
| c930b405f0 | |||
| c0f162020e | |||
| 174c21ff06 | |||
| d9d7d253fc | |||
| 418454c63f | |||
| dcc2700d7e |
@@ -0,0 +1,6 @@
|
||||
The author disclaims copyright to this source code. In place of
|
||||
a legal notice, here is a blessing:
|
||||
|
||||
* May you do good and not evil.
|
||||
* May you find forgiveness for yourself and forgive others.
|
||||
* May you share freely, never taking more than you give.
|
||||
+37
-15
@@ -422,6 +422,7 @@ TESTSRC = \
|
||||
$(TOP)/src/test_tclsh.c \
|
||||
$(TOP)/src/test_tclvar.c \
|
||||
$(TOP)/src/test_thread.c \
|
||||
$(TOP)/src/test_vdbecov.c \
|
||||
$(TOP)/src/test_vfs.c \
|
||||
$(TOP)/src/test_windirent.c \
|
||||
$(TOP)/src/test_window.c \
|
||||
@@ -452,6 +453,7 @@ TESTSRC += \
|
||||
$(TOP)/ext/misc/nextchar.c \
|
||||
$(TOP)/ext/misc/normalize.c \
|
||||
$(TOP)/ext/misc/percentile.c \
|
||||
$(TOP)/ext/misc/prefixes.c \
|
||||
$(TOP)/ext/misc/regexp.c \
|
||||
$(TOP)/ext/misc/remember.c \
|
||||
$(TOP)/ext/misc/series.c \
|
||||
@@ -588,7 +590,8 @@ FUZZDATA = \
|
||||
$(TOP)/test/fuzzdata4.db \
|
||||
$(TOP)/test/fuzzdata5.db \
|
||||
$(TOP)/test/fuzzdata6.db \
|
||||
$(TOP)/test/fuzzdata7.db
|
||||
$(TOP)/test/fuzzdata7.db \
|
||||
$(TOP)/test/fuzzdata8.db
|
||||
|
||||
# Standard options to testfixture
|
||||
#
|
||||
@@ -611,6 +614,12 @@ FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
|
||||
FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
|
||||
FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
|
||||
FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_DESERIALIZE
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
|
||||
#FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS5
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
FUZZCHECK_SRC = $(TOP)/test/fuzzcheck.c $(TOP)/test/ossfuzz.c
|
||||
DBFUZZ_OPT =
|
||||
|
||||
@@ -682,12 +691,26 @@ DBFUZZ2_OPTS = \
|
||||
-DSQLITE_ENABLE_DBSTAT_VTAB \
|
||||
-DSQLITE_ENABLE_RTREE \
|
||||
-DSQLITE_ENABLE_FTS4 \
|
||||
-DSQLITE_EANBLE_FTS5
|
||||
-DSQLITE_ENABLE_FTS5
|
||||
|
||||
dbfuzz2: $(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
|
||||
dbfuzz2$(TEXE): $(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
|
||||
$(CC) $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
|
||||
-DSTANDALONE -o dbfuzz2 \
|
||||
$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
|
||||
mkdir -p dbfuzz2-dir
|
||||
cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
|
||||
|
||||
dbfuzz2-asan: $(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
|
||||
clang-6.0 $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
|
||||
-fsanitize=fuzzer,undefined,address -o dbfuzz2 \
|
||||
$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c
|
||||
-fsanitize=fuzzer,undefined,address -o dbfuzz2-asan \
|
||||
$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
|
||||
mkdir -p dbfuzz2-dir
|
||||
cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
|
||||
|
||||
dbfuzz2-msan: $(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
|
||||
clang-6.0 $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
|
||||
-fsanitize=fuzzer,undefined,memory -o dbfuzz2-msan \
|
||||
$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
|
||||
mkdir -p dbfuzz2-dir
|
||||
cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
|
||||
|
||||
@@ -1028,12 +1051,9 @@ opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/tool/mkopcodeh.tcl
|
||||
#
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon$(BEXE) $(TOP)/tool/addopcodes.tcl
|
||||
parse.c: $(TOP)/src/parse.y lemon$(BEXE)
|
||||
cp $(TOP)/src/parse.y .
|
||||
rm -f parse.h
|
||||
./lemon$(BEXE) $(OPT_FEATURE_FLAGS) $(OPTS) parse.y
|
||||
mv parse.h parse.h.temp
|
||||
$(TCLSH_CMD) $(TOP)/tool/addopcodes.tcl parse.h.temp >parse.h
|
||||
|
||||
sqlite3.h: $(TOP)/src/sqlite.h.in $(TOP)/manifest mksourceid$(BEXE) $(TOP)/VERSION
|
||||
$(TCLSH_CMD) $(TOP)/tool/mksqlite3h.tcl $(TOP) >sqlite3.h
|
||||
@@ -1053,6 +1073,7 @@ SHELL_SRC = \
|
||||
$(TOP)/ext/expert/sqlite3expert.c \
|
||||
$(TOP)/ext/expert/sqlite3expert.h \
|
||||
$(TOP)/ext/misc/zipfile.c \
|
||||
$(TOP)/ext/misc/memtrace.c \
|
||||
$(TOP)/src/test_windirent.c
|
||||
|
||||
shell.c: $(SHELL_SRC) $(TOP)/tool/mkshellc.tcl
|
||||
@@ -1126,10 +1147,10 @@ fts3_write.lo: $(TOP)/ext/fts3/fts3_write.c $(HDR) $(EXTHDR)
|
||||
rtree.lo: $(TOP)/ext/rtree/rtree.c $(HDR) $(EXTHDR)
|
||||
$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/rtree/rtree.c
|
||||
|
||||
sqlite3session.lo: $(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR)
|
||||
userauth.lo: $(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR)
|
||||
$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/userauth/userauth.c
|
||||
|
||||
userauth.lo: $(TOP)/ext/session/sqlite3session.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
|
||||
@@ -1312,7 +1333,7 @@ showshm$(TEXE): $(TOP)/tool/showshm.c
|
||||
$(LTLINK) -o $@ $(TOP)/tool/showshm.c
|
||||
|
||||
index_usage$(TEXE): $(TOP)/tool/index_usage.c sqlite3.lo
|
||||
$(LTLINK) -o $@ $(TOP)/tool/index_usage.c sqlite3.lo $(TLIBS)
|
||||
$(LTLINK) $(SHELL_OPT) -o $@ $(TOP)/tool/index_usage.c sqlite3.lo $(TLIBS)
|
||||
|
||||
changeset$(TEXE): $(TOP)/ext/session/changeset.c sqlite3.lo
|
||||
$(LTLINK) -o $@ $(TOP)/ext/session/changeset.c sqlite3.lo $(TLIBS)
|
||||
@@ -1351,8 +1372,9 @@ loadfts$(EXE): $(TOP)/tool/loadfts.c libsqlite3.la
|
||||
# releasetest.tcl script.
|
||||
#
|
||||
VALIDIDS=' sqlite3(changeset|changegroup|session)?_'
|
||||
checksymbols: sqlite3.lo
|
||||
nm -g --defined-only sqlite3.lo | egrep -v $(VALIDIDS); test $$? -ne 0
|
||||
checksymbols: sqlite3.o
|
||||
nm -g --defined-only sqlite3.o
|
||||
nm -g --defined-only sqlite3.o | egrep -v $(VALIDIDS); test $$? -ne 0
|
||||
echo '0 errors out of 1 tests'
|
||||
|
||||
# Build the amalgamation-autoconf package. The amalamgation-tarball target builds
|
||||
@@ -1401,7 +1423,7 @@ install: sqlite3$(TEXE) lib_install sqlite3.h sqlite3.pc ${HAVE_TCL:1=tcl_instal
|
||||
$(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(pkgconfigdir)
|
||||
|
||||
pkgIndex.tcl:
|
||||
echo 'package ifneeded sqlite3 $(RELEASE) [list load $(TCLLIBDIR)/libtclsqlite3$(SHLIB_SUFFIX) sqlite3]' > $@
|
||||
echo 'package ifneeded sqlite3 $(RELEASE) [list load [file join $$dir libtclsqlite3[info sharedlibextension]] sqlite3]' > $@
|
||||
tcl_install: lib_install libtclsqlite3.la pkgIndex.tcl
|
||||
$(INSTALL) -d $(DESTDIR)$(TCLLIBDIR)
|
||||
$(LTINSTALL) libtclsqlite3.la $(DESTDIR)$(TCLLIBDIR)
|
||||
|
||||
+60
-15
@@ -320,6 +320,13 @@ SQLITETCLH = sqlite_tcl.h
|
||||
SQLITETCLDECLSH = sqlite_tclDecls.h
|
||||
!ENDIF
|
||||
|
||||
# This is the name to use for the dynamic link library (DLL) containing the
|
||||
# Tcl bindings for SQLite.
|
||||
#
|
||||
!IFNDEF SQLITE3TCLDLL
|
||||
SQLITE3TCLDLL = tclsqlite3.dll
|
||||
!ENDIF
|
||||
|
||||
# These are the additional targets that the targets that integrate with the
|
||||
# Tcl library should depend on when compiling, etc.
|
||||
#
|
||||
@@ -495,9 +502,9 @@ UCRTLIBPATH = $(UCRTLIBPATH:\\=\)
|
||||
# will run on the platform that is doing the build.
|
||||
#
|
||||
!IF $(USE_FULLWARN)!=0
|
||||
BCC = $(NCC) -nologo -W4 $(CCOPTS) $(BCCOPTS)
|
||||
BCC = $(NCC) -nologo -W4 -Fd$*.pdb $(CCOPTS) $(BCCOPTS)
|
||||
!ELSE
|
||||
BCC = $(NCC) -nologo -W3 $(CCOPTS) $(BCCOPTS)
|
||||
BCC = $(NCC) -nologo -W3 -Fd$*.pdb $(CCOPTS) $(BCCOPTS)
|
||||
!ENDIF
|
||||
|
||||
# Check if assembly code listings should be generated for the source
|
||||
@@ -853,6 +860,14 @@ RCC = $(RCC) -DSQLITE_WIN32_MALLOC_VALIDATE=1
|
||||
# prior to running nmake in order to match the actual installed location and
|
||||
# version on this machine.
|
||||
#
|
||||
!IFNDEF TCLVERSION
|
||||
TCLVERSION = 86
|
||||
!ENDIF
|
||||
|
||||
!IFNDEF TCLSUFFIX
|
||||
TCLSUFFIX =
|
||||
!ENDIF
|
||||
|
||||
!IFNDEF TCLDIR
|
||||
TCLDIR = $(TOP)\compat\tcl
|
||||
!ENDIF
|
||||
@@ -866,11 +881,11 @@ TCLLIBDIR = $(TCLDIR)\lib
|
||||
!ENDIF
|
||||
|
||||
!IFNDEF LIBTCL
|
||||
LIBTCL = tcl86.lib
|
||||
LIBTCL = tcl$(TCLVERSION)$(TCLSUFFIX).lib
|
||||
!ENDIF
|
||||
|
||||
!IFNDEF LIBTCLSTUB
|
||||
LIBTCLSTUB = tclstub86.lib
|
||||
LIBTCLSTUB = tclstub$(TCLVERSION)$(TCLSUFFIX).lib
|
||||
!ENDIF
|
||||
|
||||
!IFNDEF LIBTCLPATH
|
||||
@@ -1063,7 +1078,7 @@ RCC = $(RCC) -I$(ICUINCDIR)
|
||||
# Command line prefixes for compiling code, compiling resources,
|
||||
# linking, etc.
|
||||
#
|
||||
LTCOMPILE = $(TCC) -Fo$@
|
||||
LTCOMPILE = $(TCC) -Fo$@ -Fd$*.pdb
|
||||
LTRCOMPILE = $(RCC) -r
|
||||
LTLIB = lib.exe
|
||||
LTLINK = $(TCC) -Fe$@
|
||||
@@ -1081,6 +1096,11 @@ LTLIBS = $(LTLIBS) rpcrt4.lib
|
||||
!IFDEF PLATFORM
|
||||
LTLINKOPTS = /NOLOGO /MACHINE:$(PLATFORM)
|
||||
LTLIBOPTS = /NOLOGO /MACHINE:$(PLATFORM)
|
||||
!ELSEIF "$(VISUALSTUDIOVERSION)"=="12.0" || \
|
||||
"$(VISUALSTUDIOVERSION)"=="14.0" || \
|
||||
"$(VISUALSTUDIOVERSION)"=="15.0"
|
||||
LTLINKOPTS = /NOLOGO /MACHINE:x86
|
||||
LTLIBOPTS = /NOLOGO /MACHINE:x86
|
||||
!ELSE
|
||||
LTLINKOPTS = /NOLOGO
|
||||
LTLIBOPTS = /NOLOGO
|
||||
@@ -1497,6 +1517,7 @@ TESTSRC = \
|
||||
$(TOP)\src\test_tclsh.c \
|
||||
$(TOP)\src\test_tclvar.c \
|
||||
$(TOP)\src\test_thread.c \
|
||||
$(TOP)\src\test_vdbecov.c \
|
||||
$(TOP)\src\test_vfs.c \
|
||||
$(TOP)\src\test_windirent.c \
|
||||
$(TOP)\src\test_window.c \
|
||||
@@ -1527,6 +1548,7 @@ TESTEXT = \
|
||||
$(TOP)\ext\misc\nextchar.c \
|
||||
$(TOP)\ext\misc\normalize.c \
|
||||
$(TOP)\ext\misc\percentile.c \
|
||||
$(TOP)\ext\misc\prefixes.c \
|
||||
$(TOP)\ext\misc\regexp.c \
|
||||
$(TOP)\ext\misc\remember.c \
|
||||
$(TOP)\ext\misc\series.c \
|
||||
@@ -1625,7 +1647,8 @@ FUZZDATA = \
|
||||
$(TOP)\test\fuzzdata4.db \
|
||||
$(TOP)\test\fuzzdata5.db \
|
||||
$(TOP)\test\fuzzdata6.db \
|
||||
$(TOP)\test\fuzzdata7.db
|
||||
$(TOP)\test\fuzzdata7.db \
|
||||
$(TOP)\test\fuzzdata8.db
|
||||
# <</mark>>
|
||||
|
||||
# Additional compiler options for the shell. These are only effective
|
||||
@@ -1643,7 +1666,13 @@ SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_DESERIALIZE=1
|
||||
#
|
||||
MPTESTER_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5
|
||||
FUZZERSHELL_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1
|
||||
FUZZCHECK_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ -DSQLITE_MAX_MEMORY=50000000 -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ -DSQLITE_MAX_MEMORY=50000000 -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DESERIALIZE
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS4
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_RTREE
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_GEOPOLY
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
|
||||
FUZZCHECK_SRC = $(TOP)\test\fuzzcheck.c $(TOP)\test\ossfuzz.c
|
||||
OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c
|
||||
DBFUZZ_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION
|
||||
@@ -1657,7 +1686,7 @@ TESTOPTS = --verbose=file --output=test-out.txt
|
||||
# Extra targets for the "all" target that require Tcl.
|
||||
#
|
||||
!IF $(NO_TCL)==0
|
||||
ALL_TCL_TARGETS = libtclsqlite3.lib
|
||||
ALL_TCL_TARGETS = $(SQLITE3TCLDLL)
|
||||
!ELSE
|
||||
ALL_TCL_TARGETS =
|
||||
!ENDIF
|
||||
@@ -1689,7 +1718,22 @@ libsqlite3.lib: $(LIBOBJ)
|
||||
$(LTLIB) $(LTLIBOPTS) /OUT:$@ $(LIBOBJ) $(TLIBS)
|
||||
|
||||
libtclsqlite3.lib: tclsqlite.lo libsqlite3.lib
|
||||
$(LTLIB) $(LTLIBOPTS) $(LTLIBPATHS) /OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCLSTUB) $(TLIBS)
|
||||
$(LTLIB) $(LTLIBOPTS) $(TCLLIBPATHS) $(LTLIBPATHS) /OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCLSTUB) $(TLIBS)
|
||||
|
||||
tclsqlite3.def: tclsqlite.lo
|
||||
echo EXPORTS > tclsqlite3.def
|
||||
dumpbin /all tclsqlite.lo \
|
||||
| $(TCLSH_CMD) $(TOP)\tool\replace.tcl include "^\s+/EXPORT:_?((?:Sqlite3|Tclsqlite3)_[^@]*)(?:@\d+)?$$" \1 \
|
||||
| sort >> tclsqlite3.def
|
||||
|
||||
pkgIndex.tcl: $(TOP)\VERSION
|
||||
for /F %%V in ('type "$(TOP)\VERSION"') do ( \
|
||||
echo package ifneeded sqlite3 @version@ [list load [file join $$dir $(SQLITE3TCLDLL)] sqlite3] \
|
||||
| $(TCLSH_CMD) $(TOP)\tool\replace.tcl exact @version@ %%V > pkgIndex.tcl \
|
||||
)
|
||||
|
||||
$(SQLITE3TCLDLL): libtclsqlite3.lib $(LIBRESOBJS) tclsqlite3.def pkgIndex.tcl
|
||||
$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /DEF:tclsqlite3.def /OUT:$@ libtclsqlite3.lib $(LIBRESOBJS) $(LTLIBS) $(TLIBS)
|
||||
# <</mark>>
|
||||
|
||||
$(SQLITE3DLL): $(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP)
|
||||
@@ -1730,10 +1774,10 @@ dbfuzz.exe: $(TOP)\test\dbfuzz.c $(SQLITE3C) $(SQLITE3H)
|
||||
$(LTLINK) $(NO_WARN) $(DBFUZZ_COMPILE_OPTS) $(TOP)\test\dbfuzz.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
|
||||
fuzzcheck.exe: $(FUZZCHECK_SRC) $(SQLITE3C) $(SQLITE3H)
|
||||
$(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
|
||||
ossshell.exe: $(OSSSHELL_SRC) $(SQLITE3C) $(SQLITE3H)
|
||||
$(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
|
||||
sessionfuzz.exe: zlib $(TOP)\test\sessionfuzz.c $(SQLITE3C) $(SQLITE3H)
|
||||
$(LTLINK) $(NO_WARN) -I$(ZLIBINCDIR) $(TOP)\test\sessionfuzz.c /link $(LDFLAGS) $(LTLINKOPTS) /LIBPATH:$(ZLIBLIBDIR) $(ZLIBLIB)
|
||||
@@ -1829,7 +1873,7 @@ opcodes.lo: opcodes.c
|
||||
#
|
||||
!IF $(USE_RC)!=0
|
||||
# <<block1>>
|
||||
$(LIBRESOBJS): $(TOP)\src\sqlite3.rc $(SQLITE3H)
|
||||
$(LIBRESOBJS): $(TOP)\src\sqlite3.rc $(SQLITE3H) $(TOP)\VERSION
|
||||
echo #ifndef SQLITE_RESOURCE_VERSION > sqlite3rc.h
|
||||
for /F %%V in ('type "$(TOP)\VERSION"') do ( \
|
||||
echo #define SQLITE_RESOURCE_VERSION %%V \
|
||||
@@ -2095,12 +2139,10 @@ opcodes.h: parse.h $(TOP)\src\vdbe.c $(TOP)\tool\mkopcodeh.tcl
|
||||
#
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)\src\parse.y lemon.exe $(TOP)\tool\addopcodes.tcl
|
||||
parse.c: $(TOP)\src\parse.y lemon.exe
|
||||
del /Q parse.y parse.h parse.h.temp 2>NUL
|
||||
copy $(TOP)\src\parse.y .
|
||||
.\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) $(OPTS) parse.y
|
||||
move parse.h parse.h.temp
|
||||
$(TCLSH_CMD) $(TOP)\tool\addopcodes.tcl parse.h.temp > parse.h
|
||||
|
||||
$(SQLITE3H): $(TOP)\src\sqlite.h.in $(TOP)\manifest mksourceid.exe $(TOP)\VERSION
|
||||
$(TCLSH_CMD) $(TOP)\tool\mksqlite3h.tcl $(TOP:\=/) > $(SQLITE3H) $(MKSQLITE3H_ARGS)
|
||||
@@ -2130,6 +2172,7 @@ SHELL_SRC = \
|
||||
$(TOP)\ext\misc\completion.c \
|
||||
$(TOP)\ext\expert\sqlite3expert.c \
|
||||
$(TOP)\ext\expert\sqlite3expert.h \
|
||||
$(TOP)\ext\misc\memtrace.c \
|
||||
$(TOP)\src\test_windirent.c
|
||||
|
||||
# If use of zlib is enabled, add the "zipfile.c" source file.
|
||||
@@ -2505,6 +2548,7 @@ clean:
|
||||
del /Q *.bsc *.def *.cod *.da *.bb *.bbg *.vc gmon.out 2>NUL
|
||||
del /Q $(SQLITE3EXE) $(SQLITE3DLL) Replace.exe 2>NUL
|
||||
# <<mark>>
|
||||
del /Q $(SQLITE3TCLDLL) pkgIndex.tcl 2>NUL
|
||||
del /Q opcodes.c opcodes.h 2>NUL
|
||||
del /Q lemon.* lempar.c parse.* 2>NUL
|
||||
del /Q mksourceid.* mkkeywordhash.* keywordhash.h 2>NUL
|
||||
@@ -2515,6 +2559,7 @@ clean:
|
||||
del /Q .target_source 2>NUL
|
||||
del /Q tclsqlite3.exe $(SQLITETCLH) $(SQLITETCLDECLSH) 2>NUL
|
||||
del /Q lsm.dll lsmtest.exe 2>NUL
|
||||
del /Q atrc.exe changesetfuzz.exe dbtotxt.exe index_usage.exe 2>NUL
|
||||
del /Q testloadext.dll 2>NUL
|
||||
del /Q testfixture.exe test.db 2>NUL
|
||||
del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe dbdump.exe 2>NUL
|
||||
|
||||
@@ -5,16 +5,28 @@ This repository contains the complete source code for the
|
||||
are also included. However, many other test scripts
|
||||
and most of the documentation are managed separately.
|
||||
|
||||
SQLite [does not use Git](https://sqlite.org/whynotgit.html).
|
||||
If you are reading this on GitHub, then you are looking at an
|
||||
unofficial mirror. See <https://sqlite.org/src> for the official
|
||||
repository.
|
||||
|
||||
## Obtaining The Code
|
||||
## Version Control
|
||||
|
||||
SQLite sources are managed using the
|
||||
[Fossil](https://www.fossil-scm.org/), a distributed version control system
|
||||
that was specifically designed to support SQLite development.
|
||||
that was specifically designed and written to support SQLite development.
|
||||
The [Fossil repository](https://sqlite.org/src/timeline) contains the urtext.
|
||||
|
||||
If you are reading this on GitHub or some other Git repository or service,
|
||||
then you are looking at a mirror. The names of check-ins and
|
||||
other artifacts in a Git mirror are different from the official
|
||||
names for those objects. The offical names for check-ins are
|
||||
found in a footer on the check-in comment for authorized mirrors.
|
||||
The official check-in name can also be seen in the `manifest.uuid` file
|
||||
in the root of the tree. Always use the official name, not the
|
||||
Git-name, when communicating about an SQLite check-in.
|
||||
|
||||
If you pulled your SQLite source code from a secondary source and want to
|
||||
verify its integrity, there are hints on how to do that in the
|
||||
[Verifying Code Authenticity](#vauth) section below.
|
||||
|
||||
## Obtaining The Code
|
||||
|
||||
If you do not want to use Fossil, you can download tarballs or ZIP
|
||||
archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
|
||||
|
||||
@@ -29,7 +41,7 @@ archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
|
||||
[SQLite-archive](https://www.sqlite.org/src/sqlar/sqlite.sqlar?r=release).
|
||||
|
||||
* For other check-ins, substitute an appropriate branch name or
|
||||
tag or hash prefix for "release" in the URLs of the previous
|
||||
tag or hash prefix in place of "release" in the URLs of the previous
|
||||
bullet. Or browse the [timeline](https://www.sqlite.org/src/timeline)
|
||||
to locate the check-in desired, click on its information page link,
|
||||
then click on the "Tarball" or "ZIP Archive" links on the information
|
||||
@@ -163,11 +175,8 @@ the src/parse.y file. The conversion of "parse.y" into "parse.c" is done
|
||||
by the [lemon](./doc/lemon.html) LALR(1) parser generator. The source code
|
||||
for lemon is at tool/lemon.c. Lemon uses the tool/lempar.c file as a
|
||||
template for generating its parser.
|
||||
|
||||
Lemon also generates the **parse.h** header file, at the same time it
|
||||
generates parse.c. But the parse.h header file is
|
||||
modified further (to add additional symbols) using the ./addopcodes.tcl
|
||||
Tcl script.
|
||||
generates parse.c.
|
||||
|
||||
The **opcodes.h** header file contains macros that define the numbers
|
||||
corresponding to opcodes in the "VDBE" virtual machine. The opcodes.h
|
||||
@@ -294,10 +303,42 @@ Key files:
|
||||
There are many other source files. Each has a succinct header comment that
|
||||
describes its purpose and role within the larger system.
|
||||
|
||||
<a name="vauth"></a>
|
||||
## Verifying Code Authenticity
|
||||
|
||||
If you obtained an SQLite source tree from a secondary source, such as a
|
||||
GitHub mirror, and you want to verify that it has not been altered, there
|
||||
are a couple of ways to do that.
|
||||
|
||||
If you have a release version of SQLite, and you are using the
|
||||
`sqlite3.c` amalgamation, then SHA3-256 hashes for the amalgamation are
|
||||
available in the [change log](https://www.sqlite.org/changes.html) on
|
||||
the official website. After building the `sqlite3.c` file, you can check
|
||||
that it is authentic by comparing the hash. This does not ensure that the
|
||||
test scripts are unaltered, but it does validate the deliverable part of
|
||||
the code and the verification process only involves computing and
|
||||
comparing a single hash.
|
||||
|
||||
For versions other than an official release, or if you are building the
|
||||
`sqlite3.c` amalgamation using non-standard build options, the verification
|
||||
process is a little more involved. 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. You can write a script
|
||||
to extracts hashes from `manifest` and verifies the hashes against the
|
||||
corresponding files in the source tree. The SHA3-256 hash of the `manifest`
|
||||
file itself is the official name of the version of the source tree that you
|
||||
have. The `manifest.uuid` file should contain the SHA3-256 hash of the
|
||||
`manifest` file. If all of the above hash comparisons are correct, then
|
||||
you can be confident that your source tree is authentic and unadulterated.
|
||||
|
||||
The format of the `manifest` file should be mostly self-explanatory, but
|
||||
if you want details, they are available
|
||||
[here](https://fossil-scm.org/fossil/doc/trunk/www/fileformat.wiki#manifest).
|
||||
|
||||
## Contacts
|
||||
|
||||
The main SQLite webpage is [http://www.sqlite.org/](http://www.sqlite.org/)
|
||||
The main SQLite website is [http://www.sqlite.org/](http://www.sqlite.org/)
|
||||
with geographically distributed backups at
|
||||
[http://www2.sqlite.org/](http://www2.sqlite.org) and
|
||||
[http://www3.sqlite.org/](http://www3.sqlite.org).
|
||||
|
||||
@@ -433,9 +433,9 @@ UCRTLIBPATH = $(UCRTLIBPATH:\\=\)
|
||||
# will run on the platform that is doing the build.
|
||||
#
|
||||
!IF $(USE_FULLWARN)!=0
|
||||
BCC = $(NCC) -nologo -W4 $(CCOPTS) $(BCCOPTS)
|
||||
BCC = $(NCC) -nologo -W4 -Fd$*.pdb $(CCOPTS) $(BCCOPTS)
|
||||
!ELSE
|
||||
BCC = $(NCC) -nologo -W3 $(CCOPTS) $(BCCOPTS)
|
||||
BCC = $(NCC) -nologo -W3 -Fd$*.pdb $(CCOPTS) $(BCCOPTS)
|
||||
!ENDIF
|
||||
|
||||
# Check if assembly code listings should be generated for the source
|
||||
@@ -808,7 +808,7 @@ BCC = $(BCC) -Zi
|
||||
# Command line prefixes for compiling code, compiling resources,
|
||||
# linking, etc.
|
||||
#
|
||||
LTCOMPILE = $(TCC) -Fo$@
|
||||
LTCOMPILE = $(TCC) -Fo$@ -Fd$*.pdb
|
||||
LTRCOMPILE = $(RCC) -r
|
||||
LTLIB = lib.exe
|
||||
LTLINK = $(TCC) -Fe$@
|
||||
@@ -826,6 +826,11 @@ LTLIBS = $(LTLIBS) rpcrt4.lib
|
||||
!IFDEF PLATFORM
|
||||
LTLINKOPTS = /NOLOGO /MACHINE:$(PLATFORM)
|
||||
LTLIBOPTS = /NOLOGO /MACHINE:$(PLATFORM)
|
||||
!ELSEIF "$(VISUALSTUDIOVERSION)"=="12.0" || \
|
||||
"$(VISUALSTUDIOVERSION)"=="14.0" || \
|
||||
"$(VISUALSTUDIOVERSION)"=="15.0"
|
||||
LTLINKOPTS = /NOLOGO /MACHINE:x86
|
||||
LTLIBOPTS = /NOLOGO /MACHINE:x86
|
||||
!ELSE
|
||||
LTLINKOPTS = /NOLOGO
|
||||
LTLIBOPTS = /NOLOGO
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.27.0.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.28.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.27.0'
|
||||
PACKAGE_STRING='sqlite 3.27.0'
|
||||
PACKAGE_VERSION='3.28.0'
|
||||
PACKAGE_STRING='sqlite 3.28.0'
|
||||
PACKAGE_BUGREPORT=''
|
||||
PACKAGE_URL=''
|
||||
|
||||
@@ -863,6 +863,7 @@ infodir
|
||||
docdir
|
||||
oldincludedir
|
||||
includedir
|
||||
runstatedir
|
||||
localstatedir
|
||||
sharedstatedir
|
||||
sysconfdir
|
||||
@@ -964,6 +965,7 @@ datadir='${datarootdir}'
|
||||
sysconfdir='${prefix}/etc'
|
||||
sharedstatedir='${prefix}/com'
|
||||
localstatedir='${prefix}/var'
|
||||
runstatedir='${localstatedir}/run'
|
||||
includedir='${prefix}/include'
|
||||
oldincludedir='/usr/include'
|
||||
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
|
||||
@@ -1216,6 +1218,15 @@ do
|
||||
| -silent | --silent | --silen | --sile | --sil)
|
||||
silent=yes ;;
|
||||
|
||||
-runstatedir | --runstatedir | --runstatedi | --runstated \
|
||||
| --runstate | --runstat | --runsta | --runst | --runs \
|
||||
| --run | --ru | --r)
|
||||
ac_prev=runstatedir ;;
|
||||
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
|
||||
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
|
||||
| --run=* | --ru=* | --r=*)
|
||||
runstatedir=$ac_optarg ;;
|
||||
|
||||
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
|
||||
ac_prev=sbindir ;;
|
||||
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
|
||||
@@ -1353,7 +1364,7 @@ fi
|
||||
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
|
||||
datadir sysconfdir sharedstatedir localstatedir includedir \
|
||||
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
|
||||
libdir localedir mandir
|
||||
libdir localedir mandir runstatedir
|
||||
do
|
||||
eval ac_val=\$$ac_var
|
||||
# Remove trailing slashes.
|
||||
@@ -1466,7 +1477,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.27.0 to adapt to many kinds of systems.
|
||||
\`configure' configures sqlite 3.28.0 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -1506,6 +1517,7 @@ Fine tuning of the installation directories:
|
||||
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
|
||||
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
|
||||
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
|
||||
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
|
||||
--libdir=DIR object code libraries [EPREFIX/lib]
|
||||
--includedir=DIR C header files [PREFIX/include]
|
||||
--oldincludedir=DIR C header files for non-gcc [/usr/include]
|
||||
@@ -1531,7 +1543,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of sqlite 3.27.0:";;
|
||||
short | recursive ) echo "Configuration of sqlite 3.28.0:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@@ -1657,7 +1669,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
sqlite configure 3.27.0
|
||||
sqlite configure 3.28.0
|
||||
generated by GNU Autoconf 2.69
|
||||
|
||||
Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
@@ -2076,7 +2088,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.27.0, which was
|
||||
It was created by sqlite $as_me 3.28.0, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
@@ -3934,13 +3946,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:3937: $ac_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:3949: $ac_compile\"" >&5)
|
||||
(eval "$ac_compile" 2>conftest.err)
|
||||
cat conftest.err >&5
|
||||
(eval echo "\"\$as_me:3940: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
|
||||
(eval echo "\"\$as_me:3952: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
|
||||
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
|
||||
cat conftest.err >&5
|
||||
(eval echo "\"\$as_me:3943: output\"" >&5)
|
||||
(eval echo "\"\$as_me:3955: output\"" >&5)
|
||||
cat conftest.out >&5
|
||||
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
|
||||
lt_cv_nm_interface="MS dumpbin"
|
||||
@@ -5146,7 +5158,7 @@ ia64-*-hpux*)
|
||||
;;
|
||||
*-*-irix6*)
|
||||
# Find out which ABI we are using.
|
||||
echo '#line 5149 "configure"' > conftest.$ac_ext
|
||||
echo '#line 5161 "configure"' > conftest.$ac_ext
|
||||
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
|
||||
(eval $ac_compile) 2>&5
|
||||
ac_status=$?
|
||||
@@ -6671,11 +6683,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:6674: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:6686: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:6678: \$? = $ac_status" >&5
|
||||
echo "$as_me:6690: \$? = $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.
|
||||
@@ -7010,11 +7022,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:7013: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7025: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:7017: \$? = $ac_status" >&5
|
||||
echo "$as_me:7029: \$? = $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.
|
||||
@@ -7115,11 +7127,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:7118: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7130: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7122: \$? = $ac_status" >&5
|
||||
echo "$as_me:7134: \$? = $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
|
||||
@@ -7170,11 +7182,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:7173: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7185: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7177: \$? = $ac_status" >&5
|
||||
echo "$as_me:7189: \$? = $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
|
||||
@@ -9550,7 +9562,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 9553 "configure"
|
||||
#line 9565 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -9646,7 +9658,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 9649 "configure"
|
||||
#line 9661 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@@ -9995,7 +10007,7 @@ else
|
||||
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
||||
since some C++ compilers masquerading as C compilers
|
||||
incorrectly reject 9223372036854775807. */
|
||||
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
|
||||
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
||||
&& LARGE_OFF_T % 2147483647 == 1)
|
||||
? 1 : -1];
|
||||
@@ -10041,7 +10053,7 @@ else
|
||||
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
||||
since some C++ compilers masquerading as C compilers
|
||||
incorrectly reject 9223372036854775807. */
|
||||
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
|
||||
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
||||
&& LARGE_OFF_T % 2147483647 == 1)
|
||||
? 1 : -1];
|
||||
@@ -10065,7 +10077,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
||||
since some C++ compilers masquerading as C compilers
|
||||
incorrectly reject 9223372036854775807. */
|
||||
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
|
||||
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
||||
&& LARGE_OFF_T % 2147483647 == 1)
|
||||
? 1 : -1];
|
||||
@@ -10110,7 +10122,7 @@ else
|
||||
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
||||
since some C++ compilers masquerading as C compilers
|
||||
incorrectly reject 9223372036854775807. */
|
||||
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
|
||||
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
||||
&& LARGE_OFF_T % 2147483647 == 1)
|
||||
? 1 : -1];
|
||||
@@ -10134,7 +10146,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
||||
since some C++ compilers masquerading as C compilers
|
||||
incorrectly reject 9223372036854775807. */
|
||||
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
|
||||
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
||||
&& LARGE_OFF_T % 2147483647 == 1)
|
||||
? 1 : -1];
|
||||
@@ -12232,7 +12244,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.27.0, which was
|
||||
This file was extended by sqlite $as_me 3.28.0, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@@ -12298,7 +12310,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.27.0
|
||||
sqlite config.status 3.28.0
|
||||
configured by $0, generated by GNU Autoconf 2.69,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
|
||||
@@ -52,8 +52,10 @@
|
||||
|
||||
SECURITY: If the fts3 extension is used in an environment where potentially
|
||||
malicious users may execute arbitrary SQL (i.e. gears), they should be
|
||||
prevented from invoking the fts3_tokenizer() function, possibly using the
|
||||
authorisation callback.
|
||||
prevented from invoking the fts3_tokenizer() function. The
|
||||
fts3_tokenizer() function is disabled by default. It is only enabled
|
||||
by SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER. Do not enable it in
|
||||
security sensitive environments.
|
||||
|
||||
See "Sample code" below for an example of calling the fts3_tokenizer()
|
||||
function from C code.
|
||||
|
||||
+72
-45
@@ -320,6 +320,14 @@ int sqlite3Fts3Never(int b) { assert( !b ); return b; }
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This variable is set to false when running tests for which the on disk
|
||||
** structures should not be corrupt. Otherwise, true. If it is false, extra
|
||||
** assert() conditions in the fts3 code are activated - conditions that are
|
||||
** only true if it is guaranteed that the fts3 database is not corrupt.
|
||||
*/
|
||||
int sqlite3_fts3_may_be_corrupt = 1;
|
||||
|
||||
/*
|
||||
** Write a 64-bit variable-length integer to memory starting at p[0].
|
||||
** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
|
||||
@@ -338,7 +346,7 @@ int sqlite3Fts3PutVarint(char *p, sqlite_int64 v){
|
||||
}
|
||||
|
||||
#define GETVARINT_STEP(v, ptr, shift, mask1, mask2, var, ret) \
|
||||
v = (v & mask1) | ( (*(ptr++)) << shift ); \
|
||||
v = (v & mask1) | ( (*(const unsigned char*)(ptr++)) << shift ); \
|
||||
if( (v & mask2)==0 ){ var = v; return ret; }
|
||||
#define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
|
||||
v = (*ptr++); \
|
||||
@@ -561,13 +569,18 @@ static int fts3DestroyMethod(sqlite3_vtab *pVtab){
|
||||
sqlite3 *db = p->db; /* Database handle */
|
||||
|
||||
/* Drop the shadow tables */
|
||||
if( p->zContentTbl==0 ){
|
||||
fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
|
||||
}
|
||||
fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
|
||||
fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
|
||||
fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
|
||||
fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
|
||||
fts3DbExec(&rc, db,
|
||||
"DROP TABLE IF EXISTS %Q.'%q_segments';"
|
||||
"DROP TABLE IF EXISTS %Q.'%q_segdir';"
|
||||
"DROP TABLE IF EXISTS %Q.'%q_docsize';"
|
||||
"DROP TABLE IF EXISTS %Q.'%q_stat';"
|
||||
"%s DROP TABLE IF EXISTS %Q.'%q_content';",
|
||||
zDb, p->zName,
|
||||
zDb, p->zName,
|
||||
zDb, p->zName,
|
||||
zDb, p->zName,
|
||||
(p->zContentTbl ? "--" : ""), zDb,p->zName
|
||||
);
|
||||
|
||||
/* If everything has worked, invoke fts3DisconnectMethod() to free the
|
||||
** memory associated with the Fts3Table structure and return SQLITE_OK.
|
||||
@@ -799,10 +812,10 @@ static void fts3Appendf(
|
||||
** memory.
|
||||
*/
|
||||
static char *fts3QuoteId(char const *zInput){
|
||||
int nRet;
|
||||
sqlite3_int64 nRet;
|
||||
char *zRet;
|
||||
nRet = 2 + (int)strlen(zInput)*2 + 1;
|
||||
zRet = sqlite3_malloc(nRet);
|
||||
zRet = sqlite3_malloc64(nRet);
|
||||
if( zRet ){
|
||||
int i;
|
||||
char *z = zRet;
|
||||
@@ -983,7 +996,7 @@ static int fts3PrefixParameter(
|
||||
}
|
||||
}
|
||||
|
||||
aIndex = sqlite3_malloc(sizeof(struct Fts3Index) * nIndex);
|
||||
aIndex = sqlite3_malloc64(sizeof(struct Fts3Index) * nIndex);
|
||||
*apIndex = aIndex;
|
||||
if( !aIndex ){
|
||||
return SQLITE_NOMEM;
|
||||
@@ -1062,7 +1075,7 @@ static int fts3ContentColumns(
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
const char **azCol; /* Output array */
|
||||
int nStr = 0; /* Size of all column names (incl. 0x00) */
|
||||
sqlite3_int64 nStr = 0; /* Size of all column names (incl. 0x00) */
|
||||
int nCol; /* Number of table columns */
|
||||
int i; /* Used to iterate through columns */
|
||||
|
||||
@@ -1072,11 +1085,11 @@ static int fts3ContentColumns(
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
for(i=0; i<nCol; i++){
|
||||
const char *zCol = sqlite3_column_name(pStmt, i);
|
||||
nStr += (int)strlen(zCol) + 1;
|
||||
nStr += strlen(zCol) + 1;
|
||||
}
|
||||
|
||||
/* Allocate and populate the array to return. */
|
||||
azCol = (const char **)sqlite3_malloc(sizeof(char *) * nCol + nStr);
|
||||
azCol = (const char **)sqlite3_malloc64(sizeof(char *) * nCol + nStr);
|
||||
if( azCol==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -1124,7 +1137,7 @@ static int fts3InitVtab(
|
||||
Fts3Table *p = 0; /* Pointer to allocated vtab */
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
int i; /* Iterator variable */
|
||||
int nByte; /* Size of allocation used for *p */
|
||||
sqlite3_int64 nByte; /* Size of allocation used for *p */
|
||||
int iCol; /* Column index */
|
||||
int nString = 0; /* Bytes required to hold all column names */
|
||||
int nCol = 0; /* Number of columns in the FTS table */
|
||||
@@ -1158,10 +1171,10 @@ static int fts3InitVtab(
|
||||
nName = (int)strlen(argv[2]) + 1;
|
||||
|
||||
nByte = sizeof(const char *) * (argc-2);
|
||||
aCol = (const char **)sqlite3_malloc(nByte);
|
||||
aCol = (const char **)sqlite3_malloc64(nByte);
|
||||
if( aCol ){
|
||||
memset((void*)aCol, 0, nByte);
|
||||
azNotindexed = (char **)sqlite3_malloc(nByte);
|
||||
azNotindexed = (char **)sqlite3_malloc64(nByte);
|
||||
}
|
||||
if( azNotindexed ){
|
||||
memset(azNotindexed, 0, nByte);
|
||||
@@ -1356,7 +1369,7 @@ static int fts3InitVtab(
|
||||
nName + /* zName */
|
||||
nDb + /* zDb */
|
||||
nString; /* Space for azColumn strings */
|
||||
p = (Fts3Table*)sqlite3_malloc(nByte);
|
||||
p = (Fts3Table*)sqlite3_malloc64(nByte);
|
||||
if( p==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto fts3_init_out;
|
||||
@@ -1860,7 +1873,7 @@ static int fts3ScanInteriorNode(
|
||||
zCsr += fts3GetVarint32(zCsr, &nSuffix);
|
||||
|
||||
assert( nPrefix>=0 && nSuffix>=0 );
|
||||
if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){
|
||||
if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
|
||||
rc = FTS_CORRUPT_VTAB;
|
||||
goto finish_scan;
|
||||
}
|
||||
@@ -2135,7 +2148,7 @@ static int fts3PutColNumber(char **pp, int iCol){
|
||||
** updated appropriately. The caller is responsible for insuring
|
||||
** that there is enough space in *pp to hold the complete output.
|
||||
*/
|
||||
static void fts3PoslistMerge(
|
||||
static int fts3PoslistMerge(
|
||||
char **pp, /* Output buffer */
|
||||
char **pp1, /* Left input list */
|
||||
char **pp2 /* Right input list */
|
||||
@@ -2148,11 +2161,17 @@ static void fts3PoslistMerge(
|
||||
int iCol1; /* The current column index in pp1 */
|
||||
int iCol2; /* The current column index in pp2 */
|
||||
|
||||
if( *p1==POS_COLUMN ) fts3GetVarint32(&p1[1], &iCol1);
|
||||
if( *p1==POS_COLUMN ){
|
||||
fts3GetVarint32(&p1[1], &iCol1);
|
||||
if( iCol1==0 ) return FTS_CORRUPT_VTAB;
|
||||
}
|
||||
else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
|
||||
else iCol1 = 0;
|
||||
|
||||
if( *p2==POS_COLUMN ) fts3GetVarint32(&p2[1], &iCol2);
|
||||
if( *p2==POS_COLUMN ){
|
||||
fts3GetVarint32(&p2[1], &iCol2);
|
||||
if( iCol2==0 ) return FTS_CORRUPT_VTAB;
|
||||
}
|
||||
else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
|
||||
else iCol2 = 0;
|
||||
|
||||
@@ -2200,6 +2219,7 @@ static void fts3PoslistMerge(
|
||||
*pp = p;
|
||||
*pp1 = p1 + 1;
|
||||
*pp2 = p2 + 1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2264,10 +2284,9 @@ static int fts3PoslistPhraseMerge(
|
||||
p += sqlite3Fts3PutVarint(p, iCol1);
|
||||
}
|
||||
|
||||
assert( *p1!=POS_END && *p1!=POS_COLUMN );
|
||||
assert( *p2!=POS_END && *p2!=POS_COLUMN );
|
||||
fts3GetDeltaVarint(&p1, &iPos1); iPos1 -= 2;
|
||||
fts3GetDeltaVarint(&p2, &iPos2); iPos2 -= 2;
|
||||
if( iPos1<0 || iPos2<0 ) break;
|
||||
|
||||
while( 1 ){
|
||||
if( iPos2==iPos1+nToken
|
||||
@@ -2493,6 +2512,7 @@ static int fts3DoclistOrMerge(
|
||||
char *a2, int n2, /* Second doclist */
|
||||
char **paOut, int *pnOut /* OUT: Malloc'd doclist */
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
sqlite3_int64 i1 = 0;
|
||||
sqlite3_int64 i2 = 0;
|
||||
sqlite3_int64 iPrev = 0;
|
||||
@@ -2536,7 +2556,7 @@ static int fts3DoclistOrMerge(
|
||||
** A symetric argument may be made if the doclists are in descending
|
||||
** order.
|
||||
*/
|
||||
aOut = sqlite3_malloc(n1+n2+FTS3_VARINT_MAX-1);
|
||||
aOut = sqlite3_malloc64((i64)n1+n2+FTS3_VARINT_MAX-1+FTS3_BUFFER_PADDING);
|
||||
if( !aOut ) return SQLITE_NOMEM;
|
||||
|
||||
p = aOut;
|
||||
@@ -2547,7 +2567,8 @@ static int fts3DoclistOrMerge(
|
||||
|
||||
if( p2 && p1 && iDiff==0 ){
|
||||
fts3PutDeltaVarint3(&p, bDescDoclist, &iPrev, &bFirstOut, i1);
|
||||
fts3PoslistMerge(&p, &p1, &p2);
|
||||
rc = fts3PoslistMerge(&p, &p1, &p2);
|
||||
if( rc ) break;
|
||||
fts3GetDeltaVarint3(&p1, pEnd1, bDescDoclist, &i1);
|
||||
fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2);
|
||||
}else if( !p2 || (p1 && iDiff<0) ){
|
||||
@@ -2561,10 +2582,16 @@ static int fts3DoclistOrMerge(
|
||||
}
|
||||
}
|
||||
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3_free(aOut);
|
||||
p = aOut = 0;
|
||||
}else{
|
||||
assert( (p-aOut)<=n1+n2+FTS3_VARINT_MAX-1 );
|
||||
memset(&aOut[(p-aOut)], 0, FTS3_BUFFER_PADDING);
|
||||
}
|
||||
*paOut = aOut;
|
||||
*pnOut = (int)(p-aOut);
|
||||
assert( *pnOut<=n1+n2+FTS3_VARINT_MAX-1 );
|
||||
return SQLITE_OK;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2599,7 +2626,7 @@ static int fts3DoclistPhraseMerge(
|
||||
|
||||
assert( nDist>0 );
|
||||
if( bDescDoclist ){
|
||||
aOut = sqlite3_malloc(*pnRight + FTS3_VARINT_MAX);
|
||||
aOut = sqlite3_malloc64((sqlite3_int64)*pnRight + FTS3_VARINT_MAX);
|
||||
if( aOut==0 ) return SQLITE_NOMEM;
|
||||
}else{
|
||||
aOut = aRight;
|
||||
@@ -2783,6 +2810,7 @@ static int fts3TermSelectMerge(
|
||||
pTS->anOutput[0] = nDoclist;
|
||||
if( pTS->aaOutput[0] ){
|
||||
memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
|
||||
memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX);
|
||||
}else{
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -2834,8 +2862,8 @@ static int fts3SegReaderCursorAppend(
|
||||
){
|
||||
if( (pCsr->nSegment%16)==0 ){
|
||||
Fts3SegReader **apNew;
|
||||
int nByte = (pCsr->nSegment + 16)*sizeof(Fts3SegReader*);
|
||||
apNew = (Fts3SegReader **)sqlite3_realloc(pCsr->apSegment, nByte);
|
||||
sqlite3_int64 nByte = (pCsr->nSegment + 16)*sizeof(Fts3SegReader*);
|
||||
apNew = (Fts3SegReader **)sqlite3_realloc64(pCsr->apSegment, nByte);
|
||||
if( !apNew ){
|
||||
sqlite3Fts3SegReaderFree(pNew);
|
||||
return SQLITE_NOMEM;
|
||||
@@ -2899,7 +2927,7 @@ static int fts3SegReaderCursor(
|
||||
|
||||
/* If zTerm is not NULL, and this segment is not stored entirely on its
|
||||
** root node, the range of leaves scanned can be reduced. Do this. */
|
||||
if( iStartBlock && zTerm ){
|
||||
if( iStartBlock && zTerm && zRoot ){
|
||||
sqlite3_int64 *pi = (isPrefix ? &iLeavesEndBlock : 0);
|
||||
rc = fts3SelectLeaf(p, zTerm, nTerm, zRoot, nRoot, &iStartBlock, pi);
|
||||
if( rc!=SQLITE_OK ) goto finished;
|
||||
@@ -3841,7 +3869,6 @@ static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
|
||||
Fts3Table *p = (Fts3Table*)pVtab;
|
||||
UNUSED_PARAMETER(iSavepoint);
|
||||
assert( p->inTransaction );
|
||||
assert( p->mxSavepoint >= iSavepoint );
|
||||
TESTONLY( p->mxSavepoint = iSavepoint );
|
||||
sqlite3Fts3PendingTermsClear(p);
|
||||
return SQLITE_OK;
|
||||
@@ -4616,9 +4643,10 @@ static int fts3EvalIncrPhraseNext(
|
||||
if( bEof==0 ){
|
||||
int nList = 0;
|
||||
int nByte = a[p->nToken-1].nList;
|
||||
char *aDoclist = sqlite3_malloc(nByte+1);
|
||||
char *aDoclist = sqlite3_malloc(nByte+FTS3_BUFFER_PADDING);
|
||||
if( !aDoclist ) return SQLITE_NOMEM;
|
||||
memcpy(aDoclist, a[p->nToken-1].pList, nByte+1);
|
||||
memset(&aDoclist[nByte], 0, FTS3_BUFFER_PADDING);
|
||||
|
||||
for(i=0; i<(p->nToken-1); i++){
|
||||
if( a[i].bIgnore==0 ){
|
||||
@@ -5009,7 +5037,7 @@ static int fts3EvalStart(Fts3Cursor *pCsr){
|
||||
if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
|
||||
Fts3TokenAndCost *aTC;
|
||||
Fts3Expr **apOr;
|
||||
aTC = (Fts3TokenAndCost *)sqlite3_malloc(
|
||||
aTC = (Fts3TokenAndCost *)sqlite3_malloc64(
|
||||
sizeof(Fts3TokenAndCost) * nToken
|
||||
+ sizeof(Fts3Expr *) * nOr * 2
|
||||
);
|
||||
@@ -5320,7 +5348,7 @@ static int fts3EvalNearTest(Fts3Expr *pExpr, int *pRc){
|
||||
&& (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
|
||||
){
|
||||
Fts3Expr *p;
|
||||
int nTmp = 0; /* Bytes of temp space */
|
||||
sqlite3_int64 nTmp = 0; /* Bytes of temp space */
|
||||
char *aTmp; /* Temp space for PoslistNearMerge() */
|
||||
|
||||
/* Allocate temporary working space. */
|
||||
@@ -5329,7 +5357,7 @@ static int fts3EvalNearTest(Fts3Expr *pExpr, int *pRc){
|
||||
nTmp += p->pRight->pPhrase->doclist.nList;
|
||||
}
|
||||
nTmp += p->pPhrase->doclist.nList;
|
||||
aTmp = sqlite3_malloc(nTmp*2);
|
||||
aTmp = sqlite3_malloc64(nTmp*2);
|
||||
if( !aTmp ){
|
||||
*pRc = SQLITE_NOMEM;
|
||||
res = 0;
|
||||
@@ -5599,15 +5627,14 @@ static void fts3EvalRestart(
|
||||
** found in Fts3Expr.pPhrase->doclist.pList for each of the phrase
|
||||
** expression nodes.
|
||||
*/
|
||||
static void fts3EvalUpdateCounts(Fts3Expr *pExpr){
|
||||
static void fts3EvalUpdateCounts(Fts3Expr *pExpr, int nCol){
|
||||
if( pExpr ){
|
||||
Fts3Phrase *pPhrase = pExpr->pPhrase;
|
||||
if( pPhrase && pPhrase->doclist.pList ){
|
||||
int iCol = 0;
|
||||
char *p = pPhrase->doclist.pList;
|
||||
|
||||
assert( *p );
|
||||
while( 1 ){
|
||||
do{
|
||||
u8 c = 0;
|
||||
int iCnt = 0;
|
||||
while( 0xFE & (*p | c) ){
|
||||
@@ -5623,11 +5650,11 @@ static void fts3EvalUpdateCounts(Fts3Expr *pExpr){
|
||||
if( *p==0x00 ) break;
|
||||
p++;
|
||||
p += fts3GetVarint32(p, &iCol);
|
||||
}
|
||||
}while( iCol<nCol );
|
||||
}
|
||||
|
||||
fts3EvalUpdateCounts(pExpr->pLeft);
|
||||
fts3EvalUpdateCounts(pExpr->pRight);
|
||||
fts3EvalUpdateCounts(pExpr->pLeft, nCol);
|
||||
fts3EvalUpdateCounts(pExpr->pRight, nCol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5671,7 +5698,7 @@ static int fts3EvalGatherStats(
|
||||
for(p=pRoot; p; p=p->pLeft){
|
||||
Fts3Expr *pE = (p->eType==FTSQUERY_PHRASE?p:p->pRight);
|
||||
assert( pE->aMI==0 );
|
||||
pE->aMI = (u32 *)sqlite3_malloc(pTab->nColumn * 3 * sizeof(u32));
|
||||
pE->aMI = (u32 *)sqlite3_malloc64(pTab->nColumn * 3 * sizeof(u32));
|
||||
if( !pE->aMI ) return SQLITE_NOMEM;
|
||||
memset(pE->aMI, 0, pTab->nColumn * 3 * sizeof(u32));
|
||||
}
|
||||
@@ -5697,7 +5724,7 @@ static int fts3EvalGatherStats(
|
||||
);
|
||||
|
||||
if( rc==SQLITE_OK && pCsr->isEof==0 ){
|
||||
fts3EvalUpdateCounts(pRoot);
|
||||
fts3EvalUpdateCounts(pRoot, pTab->nColumn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,8 @@ SQLITE_EXTENSION_INIT3
|
||||
*/
|
||||
#define FTS3_VARINT_MAX 10
|
||||
|
||||
#define FTS3_BUFFER_PADDING 8
|
||||
|
||||
/*
|
||||
** FTS4 virtual tables may maintain multiple indexes - one index of all terms
|
||||
** in the document set and zero or more prefix indexes. All indexes are stored
|
||||
@@ -127,6 +129,18 @@ SQLITE_EXTENSION_INIT3
|
||||
#define POS_COLUMN (1) /* Column-list terminator */
|
||||
#define POS_END (0) /* Position-list terminator */
|
||||
|
||||
/*
|
||||
** The assert_fts3_nc() macro is similar to the assert() macro, except that it
|
||||
** is used for assert() conditions that are true only if it can be
|
||||
** guranteed that the database is not corrupt.
|
||||
*/
|
||||
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
|
||||
extern int sqlite3_fts3_may_be_corrupt;
|
||||
# define assert_fts3_nc(x) assert(sqlite3_fts3_may_be_corrupt || (x))
|
||||
#else
|
||||
# define assert_fts3_nc(x) assert(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This section provides definitions to allow the
|
||||
** FTS3 extension to be compiled outside of the
|
||||
|
||||
+5
-5
@@ -66,7 +66,7 @@ static int fts3auxConnectMethod(
|
||||
char const *zFts3; /* Name of fts3 table */
|
||||
int nDb; /* Result of strlen(zDb) */
|
||||
int nFts3; /* Result of strlen(zFts3) */
|
||||
int nByte; /* Bytes of space to allocate here */
|
||||
sqlite3_int64 nByte; /* Bytes of space to allocate here */
|
||||
int rc; /* value returned by declare_vtab() */
|
||||
Fts3auxTable *p; /* Virtual table object to return */
|
||||
|
||||
@@ -98,7 +98,7 @@ static int fts3auxConnectMethod(
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
nByte = sizeof(Fts3auxTable) + sizeof(Fts3Table) + nDb + nFts3 + 2;
|
||||
p = (Fts3auxTable *)sqlite3_malloc(nByte);
|
||||
p = (Fts3auxTable *)sqlite3_malloc64(nByte);
|
||||
if( !p ) return SQLITE_NOMEM;
|
||||
memset(p, 0, nByte);
|
||||
|
||||
@@ -248,7 +248,7 @@ static int fts3auxCloseMethod(sqlite3_vtab_cursor *pCursor){
|
||||
static int fts3auxGrowStatArray(Fts3auxCursor *pCsr, int nSize){
|
||||
if( nSize>pCsr->nStat ){
|
||||
struct Fts3auxColstats *aNew;
|
||||
aNew = (struct Fts3auxColstats *)sqlite3_realloc(pCsr->aStat,
|
||||
aNew = (struct Fts3auxColstats *)sqlite3_realloc64(pCsr->aStat,
|
||||
sizeof(struct Fts3auxColstats) * nSize
|
||||
);
|
||||
if( aNew==0 ) return SQLITE_NOMEM;
|
||||
@@ -416,15 +416,15 @@ static int fts3auxFilterMethod(
|
||||
assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
|
||||
if( zStr ){
|
||||
pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr);
|
||||
pCsr->filter.nTerm = sqlite3_value_bytes(apVal[0]);
|
||||
if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
|
||||
pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm);
|
||||
}
|
||||
}
|
||||
|
||||
if( iLe>=0 ){
|
||||
pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe]));
|
||||
pCsr->nStop = sqlite3_value_bytes(apVal[iLe]);
|
||||
if( pCsr->zStop==0 ) return SQLITE_NOMEM;
|
||||
pCsr->nStop = (int)strlen(pCsr->zStop);
|
||||
}
|
||||
|
||||
if( iLangid>=0 ){
|
||||
|
||||
@@ -122,8 +122,8 @@ static int fts3isspace(char c){
|
||||
** zero the memory before returning a pointer to it. If unsuccessful,
|
||||
** return NULL.
|
||||
*/
|
||||
static void *fts3MallocZero(int nByte){
|
||||
void *pRet = sqlite3_malloc(nByte);
|
||||
static void *fts3MallocZero(sqlite3_int64 nByte){
|
||||
void *pRet = sqlite3_malloc64(nByte);
|
||||
if( pRet ) memset(pRet, 0, nByte);
|
||||
return pRet;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ static int getNextToken(
|
||||
if( rc==SQLITE_OK ){
|
||||
const char *zToken;
|
||||
int nToken = 0, iStart = 0, iEnd = 0, iPosition = 0;
|
||||
int nByte; /* total space to allocate */
|
||||
sqlite3_int64 nByte; /* total space to allocate */
|
||||
|
||||
rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -252,8 +252,8 @@ static int getNextToken(
|
||||
** Enlarge a memory allocation. If an out-of-memory allocation occurs,
|
||||
** then free the old allocation.
|
||||
*/
|
||||
static void *fts3ReallocOrFree(void *pOrig, int nNew){
|
||||
void *pRet = sqlite3_realloc(pOrig, nNew);
|
||||
static void *fts3ReallocOrFree(void *pOrig, sqlite3_int64 nNew){
|
||||
void *pRet = sqlite3_realloc64(pOrig, nNew);
|
||||
if( !pRet ){
|
||||
sqlite3_free(pOrig);
|
||||
}
|
||||
@@ -497,7 +497,6 @@ static int getNextNode(
|
||||
int nConsumed = 0;
|
||||
pParse->nNest++;
|
||||
rc = fts3ExprParse(pParse, zInput+1, nInput-1, ppExpr, &nConsumed);
|
||||
if( rc==SQLITE_OK && !*ppExpr ){ rc = SQLITE_DONE; }
|
||||
*pnConsumed = (int)(zInput - z) + 1 + nConsumed;
|
||||
return rc;
|
||||
}else if( *zInput==')' ){
|
||||
@@ -796,7 +795,7 @@ static int fts3ExprBalance(Fts3Expr **pp, int nMaxDepth){
|
||||
if( rc==SQLITE_OK ){
|
||||
if( (eType==FTSQUERY_AND || eType==FTSQUERY_OR) ){
|
||||
Fts3Expr **apLeaf;
|
||||
apLeaf = (Fts3Expr **)sqlite3_malloc(sizeof(Fts3Expr *) * nMaxDepth);
|
||||
apLeaf = (Fts3Expr **)sqlite3_malloc64(sizeof(Fts3Expr *) * nMaxDepth);
|
||||
if( 0==apLeaf ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -1216,7 +1215,7 @@ static void fts3ExprTestCommon(
|
||||
zExpr = (const char *)sqlite3_value_text(argv[1]);
|
||||
nExpr = sqlite3_value_bytes(argv[1]);
|
||||
nCol = argc-2;
|
||||
azCol = (char **)sqlite3_malloc(nCol*sizeof(char *));
|
||||
azCol = (char **)sqlite3_malloc64(nCol*sizeof(char *));
|
||||
if( !azCol ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
goto exprtest_out;
|
||||
|
||||
@@ -35,8 +35,8 @@
|
||||
/*
|
||||
** Malloc and Free functions
|
||||
*/
|
||||
static void *fts3HashMalloc(int n){
|
||||
void *p = sqlite3_malloc(n);
|
||||
static void *fts3HashMalloc(sqlite3_int64 n){
|
||||
void *p = sqlite3_malloc64(n);
|
||||
if( p ){
|
||||
memset(p, 0, n);
|
||||
}
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ static int icuCreate(
|
||||
if( argc>0 ){
|
||||
n = strlen(argv[0])+1;
|
||||
}
|
||||
p = (IcuTokenizer *)sqlite3_malloc(sizeof(IcuTokenizer)+n);
|
||||
p = (IcuTokenizer *)sqlite3_malloc64(sizeof(IcuTokenizer)+n);
|
||||
if( !p ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ static int icuOpen(
|
||||
nInput = strlen(zInput);
|
||||
}
|
||||
nChar = nInput+1;
|
||||
pCsr = (IcuCursor *)sqlite3_malloc(
|
||||
pCsr = (IcuCursor *)sqlite3_malloc64(
|
||||
sizeof(IcuCursor) + /* IcuCursor */
|
||||
((nChar+3)&~3) * sizeof(UChar) + /* IcuCursor.aChar[] */
|
||||
(nChar+1) * sizeof(int) /* IcuCursor.aOffset[] */
|
||||
|
||||
+44
-26
@@ -178,7 +178,7 @@ static void (*fts3MIBufferAlloc(MatchinfoBuffer *p, u32 **paOut))(void*){
|
||||
aOut = &p->aMatchinfo[p->nElem+2];
|
||||
xRet = fts3MIBufferFree;
|
||||
}else{
|
||||
aOut = (u32*)sqlite3_malloc(p->nElem * sizeof(u32));
|
||||
aOut = (u32*)sqlite3_malloc64(p->nElem * sizeof(u32));
|
||||
if( aOut ){
|
||||
xRet = sqlite3_free;
|
||||
if( p->bGlobal ) memcpy(aOut, &p->aMatchinfo[1], p->nElem*sizeof(u32));
|
||||
@@ -429,11 +429,12 @@ static void fts3SnippetDetails(
|
||||
char *pCsr = pPhrase->pTail;
|
||||
int iCsr = pPhrase->iTail;
|
||||
|
||||
while( iCsr<(iStart+pIter->nSnippet) ){
|
||||
while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
|
||||
int j;
|
||||
u64 mPhrase = (u64)1 << i;
|
||||
u64 mPos = (u64)1 << (iCsr - iStart);
|
||||
assert( iCsr>=iStart );
|
||||
assert( iCsr>=iStart && (iCsr - iStart)<=64 );
|
||||
assert( i>=0 && i<=64 );
|
||||
if( (mCover|mCovered)&mPhrase ){
|
||||
iScore++;
|
||||
}else{
|
||||
@@ -475,11 +476,14 @@ static int fts3SnippetFindPositions(Fts3Expr *pExpr, int iPhrase, void *ctx){
|
||||
int iFirst = 0;
|
||||
pPhrase->pList = pCsr;
|
||||
fts3GetDeltaPosition(&pCsr, &iFirst);
|
||||
assert( iFirst>=0 );
|
||||
pPhrase->pHead = pCsr;
|
||||
pPhrase->pTail = pCsr;
|
||||
pPhrase->iHead = iFirst;
|
||||
pPhrase->iTail = iFirst;
|
||||
if( iFirst<0 ){
|
||||
rc = FTS_CORRUPT_VTAB;
|
||||
}else{
|
||||
pPhrase->pHead = pCsr;
|
||||
pPhrase->pTail = pCsr;
|
||||
pPhrase->iHead = iFirst;
|
||||
pPhrase->iTail = iFirst;
|
||||
}
|
||||
}else{
|
||||
assert( rc!=SQLITE_OK || (
|
||||
pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0
|
||||
@@ -516,7 +520,7 @@ static int fts3BestSnippet(
|
||||
int rc; /* Return Code */
|
||||
int nList; /* Number of phrases in expression */
|
||||
SnippetIter sIter; /* Iterates through snippet candidates */
|
||||
int nByte; /* Number of bytes of space to allocate */
|
||||
sqlite3_int64 nByte; /* Number of bytes of space to allocate */
|
||||
int iBestScore = -1; /* Best snippet score found so far */
|
||||
int i; /* Loop counter */
|
||||
|
||||
@@ -534,7 +538,7 @@ static int fts3BestSnippet(
|
||||
** the required space using malloc().
|
||||
*/
|
||||
nByte = sizeof(SnippetPhrase) * nList;
|
||||
sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc(nByte);
|
||||
sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc64(nByte);
|
||||
if( !sIter.aPhrase ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -604,8 +608,8 @@ static int fts3StringAppend(
|
||||
** appended data.
|
||||
*/
|
||||
if( pStr->n+nAppend+1>=pStr->nAlloc ){
|
||||
int nAlloc = pStr->nAlloc+nAppend+100;
|
||||
char *zNew = sqlite3_realloc(pStr->z, nAlloc);
|
||||
sqlite3_int64 nAlloc = pStr->nAlloc+(sqlite3_int64)nAppend+100;
|
||||
char *zNew = sqlite3_realloc64(pStr->z, nAlloc);
|
||||
if( !zNew ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -660,6 +664,7 @@ static int fts3SnippetShift(
|
||||
|
||||
for(nLeft=0; !(hlmask & ((u64)1 << nLeft)); nLeft++);
|
||||
for(nRight=0; !(hlmask & ((u64)1 << (nSnippet-1-nRight))); nRight++);
|
||||
assert( (nSnippet-1-nRight)<=63 && (nSnippet-1-nRight)>=0 );
|
||||
nDesired = (nLeft-nRight)/2;
|
||||
|
||||
/* Ideally, the start of the snippet should be pushed forward in the
|
||||
@@ -852,7 +857,7 @@ static int fts3ColumnlistCount(char **ppCollist){
|
||||
/*
|
||||
** This function gathers 'y' or 'b' data for a single phrase.
|
||||
*/
|
||||
static void fts3ExprLHits(
|
||||
static int fts3ExprLHits(
|
||||
Fts3Expr *pExpr, /* Phrase expression node */
|
||||
MatchInfo *p /* Matchinfo context */
|
||||
){
|
||||
@@ -882,25 +887,29 @@ static void fts3ExprLHits(
|
||||
if( *pIter!=0x01 ) break;
|
||||
pIter++;
|
||||
pIter += fts3GetVarint32(pIter, &iCol);
|
||||
if( iCol>=p->nCol ) return FTS_CORRUPT_VTAB;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Gather the results for matchinfo directives 'y' and 'b'.
|
||||
*/
|
||||
static void fts3ExprLHitGather(
|
||||
static int fts3ExprLHitGather(
|
||||
Fts3Expr *pExpr,
|
||||
MatchInfo *p
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
assert( (pExpr->pLeft==0)==(pExpr->pRight==0) );
|
||||
if( pExpr->bEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
|
||||
if( pExpr->pLeft ){
|
||||
fts3ExprLHitGather(pExpr->pLeft, p);
|
||||
fts3ExprLHitGather(pExpr->pRight, p);
|
||||
rc = fts3ExprLHitGather(pExpr->pLeft, p);
|
||||
if( rc==SQLITE_OK ) rc = fts3ExprLHitGather(pExpr->pRight, p);
|
||||
}else{
|
||||
fts3ExprLHits(pExpr, p);
|
||||
rc = fts3ExprLHits(pExpr, p);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1117,11 +1126,12 @@ static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
|
||||
int i;
|
||||
int iCol;
|
||||
int nToken = 0;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
/* Allocate and populate the array of LcsIterator objects. The array
|
||||
** contains one element for each matchable phrase in the query.
|
||||
**/
|
||||
aIter = sqlite3_malloc(sizeof(LcsIterator) * pCsr->nPhrase);
|
||||
aIter = sqlite3_malloc64(sizeof(LcsIterator) * pCsr->nPhrase);
|
||||
if( !aIter ) return SQLITE_NOMEM;
|
||||
memset(aIter, 0, sizeof(LcsIterator) * pCsr->nPhrase);
|
||||
(void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
|
||||
@@ -1137,13 +1147,16 @@ static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
|
||||
int nLive = 0; /* Number of iterators in aIter not at EOF */
|
||||
|
||||
for(i=0; i<pInfo->nPhrase; i++){
|
||||
int rc;
|
||||
LcsIterator *pIt = &aIter[i];
|
||||
rc = sqlite3Fts3EvalPhrasePoslist(pCsr, pIt->pExpr, iCol, &pIt->pRead);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
if( rc!=SQLITE_OK ) goto matchinfo_lcs_out;
|
||||
if( pIt->pRead ){
|
||||
pIt->iPos = pIt->iPosOffset;
|
||||
fts3LcsIteratorAdvance(&aIter[i]);
|
||||
fts3LcsIteratorAdvance(pIt);
|
||||
if( pIt->pRead==0 ){
|
||||
rc = FTS_CORRUPT_VTAB;
|
||||
goto matchinfo_lcs_out;
|
||||
}
|
||||
nLive++;
|
||||
}
|
||||
}
|
||||
@@ -1175,8 +1188,9 @@ static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
|
||||
pInfo->aMatchinfo[iCol] = nLcs;
|
||||
}
|
||||
|
||||
matchinfo_lcs_out:
|
||||
sqlite3_free(aIter);
|
||||
return SQLITE_OK;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1272,7 +1286,7 @@ static int fts3MatchinfoValues(
|
||||
case FTS3_MATCHINFO_LHITS: {
|
||||
int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
|
||||
memset(pInfo->aMatchinfo, 0, nZero);
|
||||
fts3ExprLHitGather(pCsr->pExpr, pInfo);
|
||||
rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1424,6 +1438,10 @@ void sqlite3Fts3Snippet(
|
||||
return;
|
||||
}
|
||||
|
||||
/* Limit the snippet length to 64 tokens. */
|
||||
if( nToken<-64 ) nToken = -64;
|
||||
if( nToken>+64 ) nToken = +64;
|
||||
|
||||
for(nSnippet=1; 1; nSnippet++){
|
||||
|
||||
int iSnip; /* Loop counter 0..nSnippet-1 */
|
||||
@@ -1525,7 +1543,7 @@ static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){
|
||||
nTerm = pExpr->pPhrase->nToken;
|
||||
if( pList ){
|
||||
fts3GetDeltaPosition(&pList, &iPos);
|
||||
assert( iPos>=0 );
|
||||
assert_fts3_nc( iPos>=0 );
|
||||
}
|
||||
|
||||
for(iTerm=0; iTerm<nTerm; iTerm++){
|
||||
@@ -1566,7 +1584,7 @@ void sqlite3Fts3Offsets(
|
||||
if( rc!=SQLITE_OK ) goto offsets_out;
|
||||
|
||||
/* Allocate the array of TermOffset iterators. */
|
||||
sCtx.aTerm = (TermOffset *)sqlite3_malloc(sizeof(TermOffset)*nToken);
|
||||
sCtx.aTerm = (TermOffset *)sqlite3_malloc64(sizeof(TermOffset)*nToken);
|
||||
if( 0==sCtx.aTerm ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto offsets_out;
|
||||
@@ -1635,7 +1653,7 @@ void sqlite3Fts3Offsets(
|
||||
/* All offsets for this column have been gathered. */
|
||||
rc = SQLITE_DONE;
|
||||
}else{
|
||||
assert( iCurrent<=iMinPos );
|
||||
assert_fts3_nc( iCurrent<=iMinPos );
|
||||
if( 0==(0xFE&*pTerm->pList) ){
|
||||
pTerm->pList = 0;
|
||||
}else{
|
||||
|
||||
@@ -68,9 +68,9 @@ static int fts3termConnectMethod(
|
||||
char const *zFts3; /* Name of fts3 table */
|
||||
int nDb; /* Result of strlen(zDb) */
|
||||
int nFts3; /* Result of strlen(zFts3) */
|
||||
int nByte; /* Bytes of space to allocate here */
|
||||
sqlite3_int64 nByte; /* Bytes of space to allocate here */
|
||||
int rc; /* value returned by declare_vtab() */
|
||||
Fts3termTable *p; /* Virtual table object to return */
|
||||
Fts3termTable *p; /* Virtual table object to return */
|
||||
int iIndex = 0;
|
||||
|
||||
UNUSED_PARAMETER(pCtx);
|
||||
@@ -96,9 +96,9 @@ static int fts3termConnectMethod(
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
nByte = sizeof(Fts3termTable) + sizeof(Fts3Table) + nDb + nFts3 + 2;
|
||||
p = (Fts3termTable *)sqlite3_malloc(nByte);
|
||||
p = (Fts3termTable *)sqlite3_malloc64(nByte);
|
||||
if( !p ) return SQLITE_NOMEM;
|
||||
memset(p, 0, nByte);
|
||||
memset(p, 0, (size_t)nByte);
|
||||
|
||||
p->pFts3Tab = (Fts3Table *)&p[1];
|
||||
p->pFts3Tab->zDb = (char *)&p->pFts3Tab[1];
|
||||
|
||||
+30
-1
@@ -574,6 +574,33 @@ static int SQLITE_TCLAPI fts3_test_varint_cmd(
|
||||
** End of tokenizer code.
|
||||
**************************************************************************/
|
||||
|
||||
/*
|
||||
** sqlite3_fts3_may_be_corrupt BOOLEAN
|
||||
**
|
||||
** Set or clear the global "may-be-corrupt" flag. Return the old value.
|
||||
*/
|
||||
static int SQLITE_TCLAPI fts3_may_be_corrupt(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int bOld = sqlite3_fts3_may_be_corrupt;
|
||||
|
||||
if( objc!=2 && objc!=1 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "?BOOLEAN?");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( objc==2 ){
|
||||
int bNew;
|
||||
if( Tcl_GetBooleanFromObj(interp, objv[1], &bNew) ) return TCL_ERROR;
|
||||
sqlite3_fts3_may_be_corrupt = bNew;
|
||||
}
|
||||
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(bOld));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
int Sqlitetestfts3_Init(Tcl_Interp *interp){
|
||||
Tcl_CreateObjCommand(interp, "fts3_near_match", fts3_near_match_cmd, 0, 0);
|
||||
Tcl_CreateObjCommand(interp,
|
||||
@@ -582,10 +609,12 @@ int Sqlitetestfts3_Init(Tcl_Interp *interp){
|
||||
Tcl_CreateObjCommand(
|
||||
interp, "fts3_test_tokenizer", fts3_test_tokenizer_cmd, 0, 0
|
||||
);
|
||||
|
||||
Tcl_CreateObjCommand(
|
||||
interp, "fts3_test_varint", fts3_test_varint_cmd, 0, 0
|
||||
);
|
||||
Tcl_CreateObjCommand(
|
||||
interp, "sqlite3_fts3_may_be_corrupt", fts3_may_be_corrupt, 0, 0
|
||||
);
|
||||
return TCL_OK;
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_FTS3 || SQLITE_ENABLE_FTS4 */
|
||||
|
||||
@@ -122,7 +122,7 @@ static int fts3tokDequoteArray(
|
||||
nByte += (int)(strlen(argv[i]) + 1);
|
||||
}
|
||||
|
||||
*pazDequote = azDequote = sqlite3_malloc(sizeof(char *)*argc + nByte);
|
||||
*pazDequote = azDequote = sqlite3_malloc64(sizeof(char *)*argc + nByte);
|
||||
if( azDequote==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
|
||||
@@ -79,7 +79,7 @@ static void fts3TokenizerFunc(
|
||||
nName = sqlite3_value_bytes(argv[0])+1;
|
||||
|
||||
if( argc==2 ){
|
||||
if( fts3TokenizerEnabled(context) ){
|
||||
if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[1]) ){
|
||||
void *pOld;
|
||||
int n = sqlite3_value_bytes(argv[1]);
|
||||
if( zName==0 || n!=sizeof(pPtr) ){
|
||||
@@ -106,7 +106,9 @@ static void fts3TokenizerFunc(
|
||||
return;
|
||||
}
|
||||
}
|
||||
sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
|
||||
if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[0]) ){
|
||||
sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
|
||||
int sqlite3Fts3IsIdChar(char c){
|
||||
|
||||
@@ -155,7 +155,7 @@ static int unicodeAddExceptions(
|
||||
int *aNew; /* New aiException[] array */
|
||||
int nNew; /* Number of valid entries in array aNew[] */
|
||||
|
||||
aNew = sqlite3_realloc(p->aiException, (p->nException+nEntry)*sizeof(int));
|
||||
aNew = sqlite3_realloc64(p->aiException,(p->nException+nEntry)*sizeof(int));
|
||||
if( aNew==0 ) return SQLITE_NOMEM;
|
||||
nNew = p->nException;
|
||||
|
||||
@@ -344,7 +344,7 @@ static int unicodeNext(
|
||||
|
||||
/* Grow the output buffer if required. */
|
||||
if( (zOut-pCsr->zToken)>=(pCsr->nAlloc-4) ){
|
||||
char *zNew = sqlite3_realloc(pCsr->zToken, pCsr->nAlloc+64);
|
||||
char *zNew = sqlite3_realloc64(pCsr->zToken, pCsr->nAlloc+64);
|
||||
if( !zNew ) return SQLITE_NOMEM;
|
||||
zOut = &zNew[zOut - pCsr->zToken];
|
||||
pCsr->zToken = zNew;
|
||||
|
||||
+28
-14
@@ -567,7 +567,7 @@ static sqlite3_int64 getAbsoluteLevel(
|
||||
int iLevel /* Level of segments */
|
||||
){
|
||||
sqlite3_int64 iBase; /* First absolute level for iLangid/iIndex */
|
||||
assert( iLangid>=0 );
|
||||
assert_fts3_nc( iLangid>=0 );
|
||||
assert( p->nIndex>0 );
|
||||
assert( iIndex>=0 && iIndex<p->nIndex );
|
||||
|
||||
@@ -1348,7 +1348,9 @@ static int fts3SegReaderNext(
|
||||
|
||||
/* If iCurrentBlock>=iLeafEndBlock, this is an EOF condition. All leaf
|
||||
** blocks have already been traversed. */
|
||||
assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock );
|
||||
#ifdef CORRUPT_DB
|
||||
assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock || CORRUPT_DB );
|
||||
#endif
|
||||
if( pReader->iCurrentBlock>=pReader->iLeafEndBlock ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -1615,6 +1617,7 @@ int sqlite3Fts3SegReaderNew(
|
||||
#endif
|
||||
|
||||
if( iStartLeaf==0 ){
|
||||
if( iEndLeaf!=0 ) return FTS_CORRUPT_VTAB;
|
||||
nExtra = nRoot + FTS3_NODE_PADDING;
|
||||
}
|
||||
|
||||
@@ -2254,6 +2257,11 @@ static int fts3SegWriterAdd(
|
||||
nPrefix = fts3PrefixCompress(pWriter->zTerm, pWriter->nTerm, zTerm, nTerm);
|
||||
nSuffix = nTerm-nPrefix;
|
||||
|
||||
/* If nSuffix is zero or less, then zTerm/nTerm must be a prefix of
|
||||
** pWriter->zTerm/pWriter->nTerm. i.e. must be equal to or less than when
|
||||
** compared with BINARY collation. This indicates corruption. */
|
||||
if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
|
||||
|
||||
/* Figure out how many bytes are required by this new entry */
|
||||
nReq = sqlite3Fts3VarintLen(nPrefix) + /* varint containing prefix size */
|
||||
sqlite3Fts3VarintLen(nSuffix) + /* varint containing suffix size */
|
||||
@@ -2961,7 +2969,9 @@ int sqlite3Fts3SegReaderStep(
|
||||
}else{
|
||||
iDelta = iDocid - iPrev;
|
||||
}
|
||||
assert( iDelta>0 || (nDoclist==0 && iDelta==iDocid) );
|
||||
if( iDelta<=0 && (nDoclist>0 || iDelta!=iDocid) ){
|
||||
return FTS_CORRUPT_VTAB;
|
||||
}
|
||||
assert( nDoclist>0 || iDelta==iDocid );
|
||||
|
||||
nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0);
|
||||
@@ -3227,8 +3237,10 @@ static int fts3SegmentMerge(
|
||||
if( rc!=SQLITE_OK ) goto finished;
|
||||
|
||||
assert( csr.nSegment>0 );
|
||||
assert( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
|
||||
assert( iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL) );
|
||||
assert_fts3_nc( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
|
||||
assert_fts3_nc(
|
||||
iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL)
|
||||
);
|
||||
|
||||
memset(&filter, 0, sizeof(Fts3SegFilter));
|
||||
filter.flags = FTS3_SEGMENT_REQUIRE_POS;
|
||||
@@ -3327,14 +3339,16 @@ static void fts3DecodeIntArray(
|
||||
const char *zBuf, /* The BLOB containing the varints */
|
||||
int nBuf /* size of the BLOB */
|
||||
){
|
||||
int i, j;
|
||||
UNUSED_PARAMETER(nBuf);
|
||||
for(i=j=0; i<N; i++){
|
||||
sqlite3_int64 x;
|
||||
j += sqlite3Fts3GetVarint(&zBuf[j], &x);
|
||||
assert(j<=nBuf);
|
||||
a[i] = (u32)(x & 0xffffffff);
|
||||
int i = 0;
|
||||
if( nBuf && (zBuf[nBuf-1]&0x80)==0 ){
|
||||
int j;
|
||||
for(i=j=0; i<N && j<nBuf; i++){
|
||||
sqlite3_int64 x;
|
||||
j += sqlite3Fts3GetVarint(&zBuf[j], &x);
|
||||
a[i] = (u32)(x & 0xffffffff);
|
||||
}
|
||||
}
|
||||
while( i<N ) a[i++] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3740,7 +3754,7 @@ static int nodeReaderNext(NodeReader *p){
|
||||
p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nSuffix);
|
||||
|
||||
if( nPrefix>p->iOff || nSuffix>p->nNode-p->iOff ){
|
||||
return SQLITE_CORRUPT_VTAB;
|
||||
return FTS_CORRUPT_VTAB;
|
||||
}
|
||||
blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc);
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -3750,7 +3764,7 @@ static int nodeReaderNext(NodeReader *p){
|
||||
if( p->iChild==0 ){
|
||||
p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist);
|
||||
if( (p->nNode-p->iOff)<p->nDoclist ){
|
||||
return SQLITE_CORRUPT_VTAB;
|
||||
return FTS_CORRUPT_VTAB;
|
||||
}
|
||||
p->aDoclist = &p->aNode[p->iOff];
|
||||
p->iOff += p->nDoclist;
|
||||
|
||||
@@ -738,7 +738,7 @@ proc print_categories {lMap} {
|
||||
int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
|
||||
int n = (aFts5UnicodeData[iTbl] >> 5) + i;
|
||||
for(; i<128 && i<n; i++){
|
||||
aAscii[i] = bToken;
|
||||
aAscii[i] = (u8)bToken;
|
||||
}
|
||||
iTbl++;
|
||||
}
|
||||
|
||||
+4
-8
@@ -120,12 +120,8 @@ struct Fts5PhraseIter {
|
||||
**
|
||||
** Usually, output parameter *piPhrase is set to the phrase number, *piCol
|
||||
** to the column in which it occurs and *piOff the token offset of the
|
||||
** first token of the phrase. The exception is if the table was created
|
||||
** with the offsets=0 option specified. In this case *piOff is always
|
||||
** set to -1.
|
||||
**
|
||||
** Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM)
|
||||
** if an error occurs.
|
||||
** first token of the phrase. Returns SQLITE_OK if successful, or an error
|
||||
** code (i.e. SQLITE_NOMEM) if an error occurs.
|
||||
**
|
||||
** This API can be quite slow if used with an FTS5 table created with the
|
||||
** "detail=none" or "detail=column" option.
|
||||
@@ -166,7 +162,7 @@ struct Fts5PhraseIter {
|
||||
** Save the pointer passed as the second argument as the extension functions
|
||||
** "auxiliary data". The pointer may then be retrieved by the current or any
|
||||
** future invocation of the same fts5 extension function made as part of
|
||||
** of the same MATCH query using the xGetAuxdata() API.
|
||||
** the same MATCH query using the xGetAuxdata() API.
|
||||
**
|
||||
** Each extension function is allocated a single auxiliary data slot for
|
||||
** each FTS query (MATCH expression). If the extension function is invoked
|
||||
@@ -181,7 +177,7 @@ struct Fts5PhraseIter {
|
||||
** The xDelete callback, if one is specified, is also invoked on the
|
||||
** auxiliary data pointer after the FTS5 query has finished.
|
||||
**
|
||||
** If an error (e.g. an OOM condition) occurs within this function, an
|
||||
** If an error (e.g. an OOM condition) occurs within this function,
|
||||
** the auxiliary data is set to NULL and an error code returned. If the
|
||||
** xDelete parameter was not NULL, it is invoked on the auxiliary data
|
||||
** pointer before returning.
|
||||
|
||||
+24
-5
@@ -87,6 +87,12 @@ extern int sqlite3_fts5_may_be_corrupt;
|
||||
# define assert_nc(x) assert(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** A version of memcmp() that does not cause asan errors if one of the pointer
|
||||
** parameters is NULL and the number of bytes to compare is zero.
|
||||
*/
|
||||
#define fts5Memcmp(s1, s2, n) ((n)==0 ? 0 : memcmp((s1), (s2), (n)))
|
||||
|
||||
/* Mark a function parameter as unused, to suppress nuisance compiler
|
||||
** warnings. */
|
||||
#ifndef UNUSED_PARAM
|
||||
@@ -274,7 +280,7 @@ void sqlite3Fts5Put32(u8*, int);
|
||||
int sqlite3Fts5Get32(const u8*);
|
||||
|
||||
#define FTS5_POS2COLUMN(iPos) (int)(iPos >> 32)
|
||||
#define FTS5_POS2OFFSET(iPos) (int)(iPos & 0xFFFFFFFF)
|
||||
#define FTS5_POS2OFFSET(iPos) (int)(iPos & 0x7FFFFFFF)
|
||||
|
||||
typedef struct Fts5PoslistReader Fts5PoslistReader;
|
||||
struct Fts5PoslistReader {
|
||||
@@ -309,7 +315,7 @@ int sqlite3Fts5PoslistNext64(
|
||||
);
|
||||
|
||||
/* Malloc utility */
|
||||
void *sqlite3Fts5MallocZero(int *pRc, int nByte);
|
||||
void *sqlite3Fts5MallocZero(int *pRc, sqlite3_int64 nByte);
|
||||
char *sqlite3Fts5Strndup(int *pRc, const char *pIn, int nIn);
|
||||
|
||||
/* Character set tests (like isspace(), isalpha() etc.) */
|
||||
@@ -520,9 +526,19 @@ int sqlite3Fts5PutVarint(unsigned char *p, u64 v);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
** Interface to code in fts5.c.
|
||||
** Interface to code in fts5_main.c.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Virtual-table object.
|
||||
*/
|
||||
typedef struct Fts5Table Fts5Table;
|
||||
struct Fts5Table {
|
||||
sqlite3_vtab base; /* Base class used by SQLite core */
|
||||
Fts5Config *pConfig; /* Virtual table configuration */
|
||||
Fts5Index *pIndex; /* Full-text index */
|
||||
};
|
||||
|
||||
int sqlite3Fts5GetTokenizer(
|
||||
Fts5Global*,
|
||||
const char **azArg,
|
||||
@@ -532,7 +548,9 @@ int sqlite3Fts5GetTokenizer(
|
||||
char **pzErr
|
||||
);
|
||||
|
||||
Fts5Index *sqlite3Fts5IndexFromCsrid(Fts5Global*, i64, Fts5Config **);
|
||||
Fts5Table *sqlite3Fts5TableFromCsrid(Fts5Global*, i64);
|
||||
|
||||
int sqlite3Fts5FlushToDisk(Fts5Table*);
|
||||
|
||||
/*
|
||||
** End of interface to code in fts5.c.
|
||||
@@ -565,8 +583,9 @@ void sqlite3Fts5HashClear(Fts5Hash*);
|
||||
|
||||
int sqlite3Fts5HashQuery(
|
||||
Fts5Hash*, /* Hash table to query */
|
||||
int nPre,
|
||||
const char *pTerm, int nTerm, /* Query term */
|
||||
const u8 **ppDoclist, /* OUT: Pointer to doclist for pTerm */
|
||||
void **ppObj, /* OUT: Pointer to doclist for pTerm */
|
||||
int *pnDoclist /* OUT: Size of doclist in bytes */
|
||||
);
|
||||
|
||||
|
||||
+13
-11
@@ -136,7 +136,7 @@ static void fts5HighlightAppend(
|
||||
HighlightContext *p,
|
||||
const char *z, int n
|
||||
){
|
||||
if( *pRc==SQLITE_OK ){
|
||||
if( *pRc==SQLITE_OK && z ){
|
||||
if( n<0 ) n = (int)strlen(z);
|
||||
p->zOut = sqlite3_mprintf("%z%.*s", p->zOut, n, z);
|
||||
if( p->zOut==0 ) *pRc = SQLITE_NOMEM;
|
||||
@@ -268,7 +268,7 @@ static int fts5SentenceFinderAdd(Fts5SFinder *p, int iAdd){
|
||||
int nNew = p->nFirstAlloc ? p->nFirstAlloc*2 : 64;
|
||||
int *aNew;
|
||||
|
||||
aNew = (int*)sqlite3_realloc(p->aFirst, nNew*sizeof(int));
|
||||
aNew = (int*)sqlite3_realloc64(p->aFirst, nNew*sizeof(int));
|
||||
if( aNew==0 ) return SQLITE_NOMEM;
|
||||
p->aFirst = aNew;
|
||||
p->nFirstAlloc = nNew;
|
||||
@@ -335,11 +335,12 @@ static int fts5SnippetScore(
|
||||
int nInst;
|
||||
int nScore = 0;
|
||||
int iLast = 0;
|
||||
sqlite3_int64 iEnd = (sqlite3_int64)iPos + nToken;
|
||||
|
||||
rc = pApi->xInstCount(pFts, &nInst);
|
||||
for(i=0; i<nInst && rc==SQLITE_OK; i++){
|
||||
rc = pApi->xInst(pFts, i, &ip, &ic, &iOff);
|
||||
if( rc==SQLITE_OK && ic==iCol && iOff>=iPos && iOff<(iPos+nToken) ){
|
||||
if( rc==SQLITE_OK && ic==iCol && iOff>=iPos && iOff<iEnd ){
|
||||
nScore += (aSeen[ip] ? 1 : 1000);
|
||||
aSeen[ip] = 1;
|
||||
if( iFirst<0 ) iFirst = iOff;
|
||||
@@ -349,10 +350,10 @@ static int fts5SnippetScore(
|
||||
|
||||
*pnScore = nScore;
|
||||
if( piPos ){
|
||||
int iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
|
||||
sqlite3_int64 iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
|
||||
if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
|
||||
if( iAdj<0 ) iAdj = 0;
|
||||
*piPos = iAdj;
|
||||
*piPos = (int)iAdj;
|
||||
}
|
||||
|
||||
return rc;
|
||||
@@ -442,7 +443,9 @@ static void fts5SnippetFunction(
|
||||
int jj;
|
||||
|
||||
rc = pApi->xInst(pFts, ii, &ip, &ic, &io);
|
||||
if( ic!=i || rc!=SQLITE_OK ) continue;
|
||||
if( ic!=i ) continue;
|
||||
if( io>nDocsize ) rc = FTS5_CORRUPT;
|
||||
if( rc!=SQLITE_OK ) continue;
|
||||
memset(aSeen, 0, nPhrase);
|
||||
rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i,
|
||||
io, nToken, &nScore, &iAdj
|
||||
@@ -568,17 +571,17 @@ static int fts5Bm25GetData(
|
||||
int nPhrase; /* Number of phrases in query */
|
||||
sqlite3_int64 nRow = 0; /* Number of rows in table */
|
||||
sqlite3_int64 nToken = 0; /* Number of tokens in table */
|
||||
int nByte; /* Bytes of space to allocate */
|
||||
sqlite3_int64 nByte; /* Bytes of space to allocate */
|
||||
int i;
|
||||
|
||||
/* Allocate the Fts5Bm25Data object */
|
||||
nPhrase = pApi->xPhraseCount(pFts);
|
||||
nByte = sizeof(Fts5Bm25Data) + nPhrase*2*sizeof(double);
|
||||
p = (Fts5Bm25Data*)sqlite3_malloc(nByte);
|
||||
p = (Fts5Bm25Data*)sqlite3_malloc64(nByte);
|
||||
if( p==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
memset(p, 0, nByte);
|
||||
memset(p, 0, (size_t)nByte);
|
||||
p->nPhrase = nPhrase;
|
||||
p->aIDF = (double*)&p[1];
|
||||
p->aFreq = &p->aIDF[nPhrase];
|
||||
@@ -586,6 +589,7 @@ static int fts5Bm25GetData(
|
||||
|
||||
/* Calculate the average document length for this FTS5 table */
|
||||
if( rc==SQLITE_OK ) rc = pApi->xRowCount(pFts, &nRow);
|
||||
assert( rc!=SQLITE_OK || nRow>0 );
|
||||
if( rc==SQLITE_OK ) rc = pApi->xColumnTotalSize(pFts, -1, &nToken);
|
||||
if( rc==SQLITE_OK ) p->avgdl = (double)nToken / (double)nRow;
|
||||
|
||||
@@ -710,5 +714,3 @@ int sqlite3Fts5AuxInit(fts5_api *pApi){
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,17 +17,17 @@
|
||||
|
||||
int sqlite3Fts5BufferSize(int *pRc, Fts5Buffer *pBuf, u32 nByte){
|
||||
if( (u32)pBuf->nSpace<nByte ){
|
||||
u32 nNew = pBuf->nSpace ? pBuf->nSpace : 64;
|
||||
u64 nNew = pBuf->nSpace ? pBuf->nSpace : 64;
|
||||
u8 *pNew;
|
||||
while( nNew<nByte ){
|
||||
nNew = nNew * 2;
|
||||
}
|
||||
pNew = sqlite3_realloc(pBuf->p, nNew);
|
||||
pNew = sqlite3_realloc64(pBuf->p, nNew);
|
||||
if( pNew==0 ){
|
||||
*pRc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}else{
|
||||
pBuf->nSpace = nNew;
|
||||
pBuf->nSpace = (int)nNew;
|
||||
pBuf->p = pNew;
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ void sqlite3Fts5Put32(u8 *aBuf, int iVal){
|
||||
}
|
||||
|
||||
int sqlite3Fts5Get32(const u8 *aBuf){
|
||||
return (aBuf[0] << 24) + (aBuf[1] << 16) + (aBuf[2] << 8) + aBuf[3];
|
||||
return (int)((((u32)aBuf[0])<<24) + (aBuf[1]<<16) + (aBuf[2]<<8) + aBuf[3]);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -183,7 +183,7 @@ int sqlite3Fts5PoslistNext64(
|
||||
iOff = ((i64)iVal) << 32;
|
||||
fts5FastGetVarint32(a, i, iVal);
|
||||
}
|
||||
*piOff = iOff + (iVal-2);
|
||||
*piOff = iOff + ((iVal-2) & 0x7FFFFFFF);
|
||||
*pi = i;
|
||||
return 0;
|
||||
}
|
||||
@@ -244,14 +244,14 @@ int sqlite3Fts5PoslistWriterAppend(
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
void *sqlite3Fts5MallocZero(int *pRc, int nByte){
|
||||
void *sqlite3Fts5MallocZero(int *pRc, sqlite3_int64 nByte){
|
||||
void *pRet = 0;
|
||||
if( *pRc==SQLITE_OK ){
|
||||
pRet = sqlite3_malloc(nByte);
|
||||
pRet = sqlite3_malloc64(nByte);
|
||||
if( pRet==0 ){
|
||||
if( nByte>0 ) *pRc = SQLITE_NOMEM;
|
||||
}else{
|
||||
memset(pRet, 0, nByte);
|
||||
memset(pRet, 0, (size_t)nByte);
|
||||
}
|
||||
}
|
||||
return pRet;
|
||||
|
||||
@@ -295,7 +295,7 @@ static int fts5ConfigParseSpecial(
|
||||
|
||||
if( sqlite3_strnicmp("tokenize", zCmd, nCmd)==0 ){
|
||||
const char *p = (const char*)zArg;
|
||||
int nArg = (int)strlen(zArg) + 1;
|
||||
sqlite3_int64 nArg = strlen(zArg) + 1;
|
||||
char **azArg = sqlite3Fts5MallocZero(&rc, sizeof(char*) * nArg);
|
||||
char *pDel = sqlite3Fts5MallocZero(&rc, nArg * 2);
|
||||
char *pSpace = pDel;
|
||||
@@ -325,7 +325,7 @@ static int fts5ConfigParseSpecial(
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
rc = sqlite3Fts5GetTokenizer(pGlobal,
|
||||
(const char**)azArg, nArg, &pConfig->pTok, &pConfig->pTokApi,
|
||||
(const char**)azArg, (int)nArg, &pConfig->pTok, &pConfig->pTokApi,
|
||||
pzErr
|
||||
);
|
||||
}
|
||||
@@ -425,8 +425,8 @@ static const char *fts5ConfigGobbleWord(
|
||||
){
|
||||
const char *zRet = 0;
|
||||
|
||||
int nIn = (int)strlen(zIn);
|
||||
char *zOut = sqlite3_malloc(nIn+1);
|
||||
sqlite3_int64 nIn = strlen(zIn);
|
||||
char *zOut = sqlite3_malloc64(nIn+1);
|
||||
|
||||
assert( *pRc==SQLITE_OK );
|
||||
*pbQuoted = 0;
|
||||
@@ -435,7 +435,7 @@ static const char *fts5ConfigGobbleWord(
|
||||
if( zOut==0 ){
|
||||
*pRc = SQLITE_NOMEM;
|
||||
}else{
|
||||
memcpy(zOut, zIn, nIn+1);
|
||||
memcpy(zOut, zIn, (size_t)(nIn+1));
|
||||
if( fts5_isopenquote(zOut[0]) ){
|
||||
int ii = fts5Dequote(zOut);
|
||||
zRet = &zIn[ii];
|
||||
@@ -529,7 +529,7 @@ int sqlite3Fts5ConfigParse(
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
Fts5Config *pRet; /* New object to return */
|
||||
int i;
|
||||
int nByte;
|
||||
sqlite3_int64 nByte;
|
||||
|
||||
*ppOut = pRet = (Fts5Config*)sqlite3_malloc(sizeof(Fts5Config));
|
||||
if( pRet==0 ) return SQLITE_NOMEM;
|
||||
|
||||
+32
-29
@@ -211,7 +211,7 @@ static int fts5ExprGetToken(
|
||||
return tok;
|
||||
}
|
||||
|
||||
static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc((int)t); }
|
||||
static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc64((sqlite3_int64)t);}
|
||||
static void fts5ParseFree(void *p){ sqlite3_free(p); }
|
||||
|
||||
int sqlite3Fts5ExprNew(
|
||||
@@ -356,8 +356,8 @@ static int fts5ExprSynonymList(
|
||||
if( sqlite3Fts5IterEof(pIter)==0 && pIter->iRowid==iRowid ){
|
||||
if( pIter->nData==0 ) continue;
|
||||
if( nIter==nAlloc ){
|
||||
int nByte = sizeof(Fts5PoslistReader) * nAlloc * 2;
|
||||
Fts5PoslistReader *aNew = (Fts5PoslistReader*)sqlite3_malloc(nByte);
|
||||
sqlite3_int64 nByte = sizeof(Fts5PoslistReader) * nAlloc * 2;
|
||||
Fts5PoslistReader *aNew = (Fts5PoslistReader*)sqlite3_malloc64(nByte);
|
||||
if( aNew==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto synonym_poslist_out;
|
||||
@@ -437,8 +437,8 @@ static int fts5ExprPhraseIsMatch(
|
||||
/* If the aStatic[] array is not large enough, allocate a large array
|
||||
** using sqlite3_malloc(). This approach could be improved upon. */
|
||||
if( pPhrase->nTerm>ArraySize(aStatic) ){
|
||||
int nByte = sizeof(Fts5PoslistReader) * pPhrase->nTerm;
|
||||
aIter = (Fts5PoslistReader*)sqlite3_malloc(nByte);
|
||||
sqlite3_int64 nByte = sizeof(Fts5PoslistReader) * pPhrase->nTerm;
|
||||
aIter = (Fts5PoslistReader*)sqlite3_malloc64(nByte);
|
||||
if( !aIter ) return SQLITE_NOMEM;
|
||||
}
|
||||
memset(aIter, 0, sizeof(Fts5PoslistReader) * pPhrase->nTerm);
|
||||
@@ -572,7 +572,7 @@ static int fts5ExprNearIsMatch(int *pRc, Fts5ExprNearset *pNear){
|
||||
/* If the aStatic[] array is not large enough, allocate a large array
|
||||
** using sqlite3_malloc(). This approach could be improved upon. */
|
||||
if( pNear->nPhrase>ArraySize(aStatic) ){
|
||||
int nByte = sizeof(Fts5NearTrimmer) * pNear->nPhrase;
|
||||
sqlite3_int64 nByte = sizeof(Fts5NearTrimmer) * pNear->nPhrase;
|
||||
a = (Fts5NearTrimmer*)sqlite3Fts5MallocZero(&rc, nByte);
|
||||
}else{
|
||||
memset(aStatic, 0, sizeof(aStatic));
|
||||
@@ -1481,18 +1481,20 @@ Fts5ExprNearset *sqlite3Fts5ParseNearset(
|
||||
return pNear;
|
||||
}
|
||||
if( pNear==0 ){
|
||||
int nByte = sizeof(Fts5ExprNearset) + SZALLOC * sizeof(Fts5ExprPhrase*);
|
||||
pRet = sqlite3_malloc(nByte);
|
||||
sqlite3_int64 nByte;
|
||||
nByte = sizeof(Fts5ExprNearset) + SZALLOC * sizeof(Fts5ExprPhrase*);
|
||||
pRet = sqlite3_malloc64(nByte);
|
||||
if( pRet==0 ){
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
memset(pRet, 0, nByte);
|
||||
memset(pRet, 0, (size_t)nByte);
|
||||
}
|
||||
}else if( (pNear->nPhrase % SZALLOC)==0 ){
|
||||
int nNew = pNear->nPhrase + SZALLOC;
|
||||
int nByte = sizeof(Fts5ExprNearset) + nNew * sizeof(Fts5ExprPhrase*);
|
||||
sqlite3_int64 nByte;
|
||||
|
||||
pRet = (Fts5ExprNearset*)sqlite3_realloc(pNear, nByte);
|
||||
nByte = sizeof(Fts5ExprNearset) + nNew * sizeof(Fts5ExprPhrase*);
|
||||
pRet = (Fts5ExprNearset*)sqlite3_realloc64(pNear, nByte);
|
||||
if( pRet==0 ){
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
}
|
||||
@@ -1556,12 +1558,12 @@ static int fts5ParseTokenize(
|
||||
|
||||
if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
|
||||
Fts5ExprTerm *pSyn;
|
||||
int nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
|
||||
pSyn = (Fts5ExprTerm*)sqlite3_malloc(nByte);
|
||||
sqlite3_int64 nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
|
||||
pSyn = (Fts5ExprTerm*)sqlite3_malloc64(nByte);
|
||||
if( pSyn==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
memset(pSyn, 0, nByte);
|
||||
memset(pSyn, 0, (size_t)nByte);
|
||||
pSyn->zTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
|
||||
memcpy(pSyn->zTerm, pToken, nToken);
|
||||
pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
|
||||
@@ -1573,7 +1575,7 @@ static int fts5ParseTokenize(
|
||||
Fts5ExprPhrase *pNew;
|
||||
int nNew = SZALLOC + (pPhrase ? pPhrase->nTerm : 0);
|
||||
|
||||
pNew = (Fts5ExprPhrase*)sqlite3_realloc(pPhrase,
|
||||
pNew = (Fts5ExprPhrase*)sqlite3_realloc64(pPhrase,
|
||||
sizeof(Fts5ExprPhrase) + sizeof(Fts5ExprTerm) * nNew
|
||||
);
|
||||
if( pNew==0 ){
|
||||
@@ -1659,9 +1661,9 @@ Fts5ExprPhrase *sqlite3Fts5ParseTerm(
|
||||
|
||||
if( pAppend==0 ){
|
||||
if( (pParse->nPhrase % 8)==0 ){
|
||||
int nByte = sizeof(Fts5ExprPhrase*) * (pParse->nPhrase + 8);
|
||||
sqlite3_int64 nByte = sizeof(Fts5ExprPhrase*) * (pParse->nPhrase + 8);
|
||||
Fts5ExprPhrase **apNew;
|
||||
apNew = (Fts5ExprPhrase**)sqlite3_realloc(pParse->apPhrase, nByte);
|
||||
apNew = (Fts5ExprPhrase**)sqlite3_realloc64(pParse->apPhrase, nByte);
|
||||
if( apNew==0 ){
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
fts5ExprPhraseFree(sCtx.pPhrase);
|
||||
@@ -1716,10 +1718,12 @@ int sqlite3Fts5ExprClonePhrase(
|
||||
if( rc==SQLITE_OK ){
|
||||
Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
|
||||
if( pColsetOrig ){
|
||||
int nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
|
||||
Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
|
||||
sqlite3_int64 nByte;
|
||||
Fts5Colset *pColset;
|
||||
nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
|
||||
pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
|
||||
if( pColset ){
|
||||
memcpy(pColset, pColsetOrig, nByte);
|
||||
memcpy(pColset, pColsetOrig, (size_t)nByte);
|
||||
}
|
||||
pNew->pRoot->pNear->pColset = pColset;
|
||||
}
|
||||
@@ -1837,7 +1841,7 @@ static Fts5Colset *fts5ParseColset(
|
||||
assert( pParse->rc==SQLITE_OK );
|
||||
assert( iCol>=0 && iCol<pParse->pConfig->nCol );
|
||||
|
||||
pNew = sqlite3_realloc(p, sizeof(Fts5Colset) + sizeof(int)*nCol);
|
||||
pNew = sqlite3_realloc64(p, sizeof(Fts5Colset) + sizeof(int)*nCol);
|
||||
if( pNew==0 ){
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -1933,10 +1937,10 @@ Fts5Colset *sqlite3Fts5ParseColset(
|
||||
static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
|
||||
Fts5Colset *pRet;
|
||||
if( pOrig ){
|
||||
int nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
|
||||
sqlite3_int64 nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
|
||||
pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
|
||||
if( pRet ){
|
||||
memcpy(pRet, pOrig, nByte);
|
||||
memcpy(pRet, pOrig, (size_t)nByte);
|
||||
}
|
||||
}else{
|
||||
pRet = 0;
|
||||
@@ -2087,7 +2091,7 @@ Fts5ExprNode *sqlite3Fts5ParseNode(
|
||||
|
||||
if( pParse->rc==SQLITE_OK ){
|
||||
int nChild = 0; /* Number of children of returned node */
|
||||
int nByte; /* Bytes of space to allocate for this node */
|
||||
sqlite3_int64 nByte; /* Bytes of space to allocate for this node */
|
||||
|
||||
assert( (eType!=FTS5_STRING && !pNear)
|
||||
|| (eType==FTS5_STRING && !pLeft && !pRight)
|
||||
@@ -2219,7 +2223,7 @@ Fts5ExprNode *sqlite3Fts5ParseImplicitAnd(
|
||||
}
|
||||
|
||||
static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){
|
||||
int nByte = 0;
|
||||
sqlite3_int64 nByte = 0;
|
||||
Fts5ExprTerm *p;
|
||||
char *zQuoted;
|
||||
|
||||
@@ -2227,7 +2231,7 @@ static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){
|
||||
for(p=pTerm; p; p=p->pSynonym){
|
||||
nByte += (int)strlen(pTerm->zTerm) * 2 + 3 + 2;
|
||||
}
|
||||
zQuoted = sqlite3_malloc(nByte);
|
||||
zQuoted = sqlite3_malloc64(nByte);
|
||||
|
||||
if( zQuoted ){
|
||||
int i = 0;
|
||||
@@ -2467,7 +2471,7 @@ static void fts5ExprFunction(
|
||||
}
|
||||
|
||||
nConfig = 3 + (nArg-iArg);
|
||||
azConfig = (const char**)sqlite3_malloc(sizeof(char*) * nConfig);
|
||||
azConfig = (const char**)sqlite3_malloc64(sizeof(char*) * nConfig);
|
||||
if( azConfig==0 ){
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
return;
|
||||
@@ -2648,7 +2652,7 @@ struct Fts5PoslistPopulator {
|
||||
|
||||
Fts5PoslistPopulator *sqlite3Fts5ExprClearPoslists(Fts5Expr *pExpr, int bLive){
|
||||
Fts5PoslistPopulator *pRet;
|
||||
pRet = sqlite3_malloc(sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
|
||||
pRet = sqlite3_malloc64(sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
|
||||
if( pRet ){
|
||||
int i;
|
||||
memset(pRet, 0, sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
|
||||
@@ -2847,4 +2851,3 @@ int sqlite3Fts5ExprPhraseCollist(
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
+54
-31
@@ -90,20 +90,20 @@ int sqlite3Fts5HashNew(Fts5Config *pConfig, Fts5Hash **ppNew, int *pnByte){
|
||||
if( pNew==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
int nByte;
|
||||
sqlite3_int64 nByte;
|
||||
memset(pNew, 0, sizeof(Fts5Hash));
|
||||
pNew->pnByte = pnByte;
|
||||
pNew->eDetail = pConfig->eDetail;
|
||||
|
||||
pNew->nSlot = 1024;
|
||||
nByte = sizeof(Fts5HashEntry*) * pNew->nSlot;
|
||||
pNew->aSlot = (Fts5HashEntry**)sqlite3_malloc(nByte);
|
||||
pNew->aSlot = (Fts5HashEntry**)sqlite3_malloc64(nByte);
|
||||
if( pNew->aSlot==0 ){
|
||||
sqlite3_free(pNew);
|
||||
*ppNew = 0;
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
memset(pNew->aSlot, 0, nByte);
|
||||
memset(pNew->aSlot, 0, (size_t)nByte);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
@@ -165,7 +165,7 @@ static int fts5HashResize(Fts5Hash *pHash){
|
||||
Fts5HashEntry **apNew;
|
||||
Fts5HashEntry **apOld = pHash->aSlot;
|
||||
|
||||
apNew = (Fts5HashEntry**)sqlite3_malloc(nNew*sizeof(Fts5HashEntry*));
|
||||
apNew = (Fts5HashEntry**)sqlite3_malloc64(nNew*sizeof(Fts5HashEntry*));
|
||||
if( !apNew ) return SQLITE_NOMEM;
|
||||
memset(apNew, 0, nNew*sizeof(Fts5HashEntry*));
|
||||
|
||||
@@ -187,19 +187,25 @@ static int fts5HashResize(Fts5Hash *pHash){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static void fts5HashAddPoslistSize(Fts5Hash *pHash, Fts5HashEntry *p){
|
||||
static int fts5HashAddPoslistSize(
|
||||
Fts5Hash *pHash,
|
||||
Fts5HashEntry *p,
|
||||
Fts5HashEntry *p2
|
||||
){
|
||||
int nRet = 0;
|
||||
if( p->iSzPoslist ){
|
||||
u8 *pPtr = (u8*)p;
|
||||
u8 *pPtr = p2 ? (u8*)p2 : (u8*)p;
|
||||
int nData = p->nData;
|
||||
if( pHash->eDetail==FTS5_DETAIL_NONE ){
|
||||
assert( p->nData==p->iSzPoslist );
|
||||
assert( nData==p->iSzPoslist );
|
||||
if( p->bDel ){
|
||||
pPtr[p->nData++] = 0x00;
|
||||
pPtr[nData++] = 0x00;
|
||||
if( p->bContent ){
|
||||
pPtr[p->nData++] = 0x00;
|
||||
pPtr[nData++] = 0x00;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
int nSz = (p->nData - p->iSzPoslist - 1); /* Size in bytes */
|
||||
int nSz = (nData - p->iSzPoslist - 1); /* Size in bytes */
|
||||
int nPos = nSz*2 + p->bDel; /* Value of nPos field */
|
||||
|
||||
assert( p->bDel==0 || p->bDel==1 );
|
||||
@@ -209,14 +215,19 @@ static void fts5HashAddPoslistSize(Fts5Hash *pHash, Fts5HashEntry *p){
|
||||
int nByte = sqlite3Fts5GetVarintLen((u32)nPos);
|
||||
memmove(&pPtr[p->iSzPoslist + nByte], &pPtr[p->iSzPoslist + 1], nSz);
|
||||
sqlite3Fts5PutVarint(&pPtr[p->iSzPoslist], nPos);
|
||||
p->nData += (nByte-1);
|
||||
nData += (nByte-1);
|
||||
}
|
||||
}
|
||||
|
||||
p->iSzPoslist = 0;
|
||||
p->bDel = 0;
|
||||
p->bContent = 0;
|
||||
nRet = nData - p->nData;
|
||||
if( p2==0 ){
|
||||
p->iSzPoslist = 0;
|
||||
p->bDel = 0;
|
||||
p->bContent = 0;
|
||||
p->nData = nData;
|
||||
}
|
||||
}
|
||||
return nRet;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -259,7 +270,7 @@ int sqlite3Fts5HashWrite(
|
||||
if( p==0 ){
|
||||
/* Figure out how much space to allocate */
|
||||
char *zKey;
|
||||
int nByte = sizeof(Fts5HashEntry) + (nToken+1) + 1 + 64;
|
||||
sqlite3_int64 nByte = sizeof(Fts5HashEntry) + (nToken+1) + 1 + 64;
|
||||
if( nByte<128 ) nByte = 128;
|
||||
|
||||
/* Grow the Fts5Hash.aSlot[] array if necessary. */
|
||||
@@ -270,10 +281,10 @@ int sqlite3Fts5HashWrite(
|
||||
}
|
||||
|
||||
/* Allocate new Fts5HashEntry and add it to the hash table. */
|
||||
p = (Fts5HashEntry*)sqlite3_malloc(nByte);
|
||||
p = (Fts5HashEntry*)sqlite3_malloc64(nByte);
|
||||
if( !p ) return SQLITE_NOMEM;
|
||||
memset(p, 0, sizeof(Fts5HashEntry));
|
||||
p->nAlloc = nByte;
|
||||
p->nAlloc = (int)nByte;
|
||||
zKey = fts5EntryKey(p);
|
||||
zKey[0] = bByte;
|
||||
memcpy(&zKey[1], pToken, nToken);
|
||||
@@ -309,12 +320,12 @@ int sqlite3Fts5HashWrite(
|
||||
** + 5 bytes for the new position offset (32-bit max).
|
||||
*/
|
||||
if( (p->nAlloc - p->nData) < (9 + 4 + 1 + 3 + 5) ){
|
||||
int nNew = p->nAlloc * 2;
|
||||
sqlite3_int64 nNew = p->nAlloc * 2;
|
||||
Fts5HashEntry *pNew;
|
||||
Fts5HashEntry **pp;
|
||||
pNew = (Fts5HashEntry*)sqlite3_realloc(p, nNew);
|
||||
pNew = (Fts5HashEntry*)sqlite3_realloc64(p, nNew);
|
||||
if( pNew==0 ) return SQLITE_NOMEM;
|
||||
pNew->nAlloc = nNew;
|
||||
pNew->nAlloc = (int)nNew;
|
||||
for(pp=&pHash->aSlot[iHash]; *pp!=p; pp=&(*pp)->pHashNext);
|
||||
*pp = pNew;
|
||||
p = pNew;
|
||||
@@ -328,7 +339,7 @@ int sqlite3Fts5HashWrite(
|
||||
/* If this is a new rowid, append the 4-byte size field for the previous
|
||||
** entry, and the new rowid for this entry. */
|
||||
if( iRowid!=p->iRowid ){
|
||||
fts5HashAddPoslistSize(pHash, p);
|
||||
fts5HashAddPoslistSize(pHash, p, 0);
|
||||
p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iRowid - p->iRowid);
|
||||
p->iRowid = iRowid;
|
||||
bNew = 1;
|
||||
@@ -438,14 +449,16 @@ static int fts5HashEntrySort(
|
||||
int i;
|
||||
|
||||
*ppSorted = 0;
|
||||
ap = sqlite3_malloc(sizeof(Fts5HashEntry*) * nMergeSlot);
|
||||
ap = sqlite3_malloc64(sizeof(Fts5HashEntry*) * nMergeSlot);
|
||||
if( !ap ) return SQLITE_NOMEM;
|
||||
memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
|
||||
|
||||
for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
|
||||
Fts5HashEntry *pIter;
|
||||
for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
|
||||
if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
|
||||
if( pTerm==0
|
||||
|| (pIter->nKey+1>=nTerm && 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm))
|
||||
){
|
||||
Fts5HashEntry *pEntry = pIter;
|
||||
pEntry->pScanNext = 0;
|
||||
for(i=0; ap[i]; i++){
|
||||
@@ -473,8 +486,9 @@ static int fts5HashEntrySort(
|
||||
*/
|
||||
int sqlite3Fts5HashQuery(
|
||||
Fts5Hash *pHash, /* Hash table to query */
|
||||
int nPre,
|
||||
const char *pTerm, int nTerm, /* Query term */
|
||||
const u8 **ppDoclist, /* OUT: Pointer to doclist for pTerm */
|
||||
void **ppOut, /* OUT: Pointer to new object */
|
||||
int *pnDoclist /* OUT: Size of doclist in bytes */
|
||||
){
|
||||
unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
|
||||
@@ -483,15 +497,25 @@ int sqlite3Fts5HashQuery(
|
||||
|
||||
for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
|
||||
zKey = fts5EntryKey(p);
|
||||
if( memcmp(zKey, pTerm, nTerm)==0 && zKey[nTerm]==0 ) break;
|
||||
assert( p->nKey+1==(int)strlen(zKey) );
|
||||
if( nTerm==p->nKey+1 && memcmp(zKey, pTerm, nTerm)==0 ) break;
|
||||
}
|
||||
|
||||
if( p ){
|
||||
fts5HashAddPoslistSize(pHash, p);
|
||||
*ppDoclist = (const u8*)&zKey[nTerm+1];
|
||||
*pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
|
||||
int nHashPre = sizeof(Fts5HashEntry) + nTerm + 1;
|
||||
int nList = p->nData - nHashPre;
|
||||
u8 *pRet = (u8*)(*ppOut = sqlite3_malloc64(nPre + nList + 10));
|
||||
if( pRet ){
|
||||
Fts5HashEntry *pFaux = (Fts5HashEntry*)&pRet[nPre-nHashPre];
|
||||
memcpy(&pRet[nPre], &((u8*)p)[nHashPre], nList);
|
||||
nList += fts5HashAddPoslistSize(pHash, p, pFaux);
|
||||
*pnDoclist = nList;
|
||||
}else{
|
||||
*pnDoclist = 0;
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
}else{
|
||||
*ppDoclist = 0;
|
||||
*ppOut = 0;
|
||||
*pnDoclist = 0;
|
||||
}
|
||||
|
||||
@@ -524,7 +548,7 @@ void sqlite3Fts5HashScanEntry(
|
||||
if( (p = pHash->pScan) ){
|
||||
char *zKey = fts5EntryKey(p);
|
||||
int nTerm = (int)strlen(zKey);
|
||||
fts5HashAddPoslistSize(pHash, p);
|
||||
fts5HashAddPoslistSize(pHash, p, 0);
|
||||
*pzTerm = zKey;
|
||||
*ppDoclist = (const u8*)&zKey[nTerm+1];
|
||||
*pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
|
||||
@@ -534,4 +558,3 @@ void sqlite3Fts5HashScanEntry(
|
||||
*pnDoclist = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+125
-76
@@ -512,7 +512,6 @@ struct Fts5Iter {
|
||||
Fts5IndexIter base; /* Base class containing output vars */
|
||||
|
||||
Fts5Index *pIndex; /* Index that owns this iterator */
|
||||
Fts5Structure *pStruct; /* Database structure for this iterator */
|
||||
Fts5Buffer poslist; /* Buffer containing current poslist */
|
||||
Fts5Colset *pColset; /* Restrict matches to these columns */
|
||||
|
||||
@@ -573,7 +572,7 @@ static u16 fts5GetU16(const u8 *aIn){
|
||||
** If an OOM error is encountered, return NULL and set the error code in
|
||||
** the Fts5Index handle passed as the first argument.
|
||||
*/
|
||||
static void *fts5IdxMalloc(Fts5Index *p, int nByte){
|
||||
static void *fts5IdxMalloc(Fts5Index *p, sqlite3_int64 nByte){
|
||||
return sqlite3Fts5MallocZero(&p->rc, nByte);
|
||||
}
|
||||
|
||||
@@ -607,7 +606,7 @@ static int fts5BufferCompareBlob(
|
||||
*/
|
||||
static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
|
||||
int nCmp = MIN(pLeft->n, pRight->n);
|
||||
int res = memcmp(pLeft->p, pRight->p, nCmp);
|
||||
int res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
|
||||
return (res==0 ? (pLeft->n - pRight->n) : res);
|
||||
}
|
||||
|
||||
@@ -673,8 +672,8 @@ static Fts5Data *fts5DataRead(Fts5Index *p, i64 iRowid){
|
||||
if( rc==SQLITE_OK ){
|
||||
u8 *aOut = 0; /* Read blob data into this buffer */
|
||||
int nByte = sqlite3_blob_bytes(p->pReader);
|
||||
int nAlloc = sizeof(Fts5Data) + nByte + FTS5_DATA_PADDING;
|
||||
pRet = (Fts5Data*)sqlite3_malloc(nAlloc);
|
||||
sqlite3_int64 nAlloc = sizeof(Fts5Data) + nByte + FTS5_DATA_PADDING;
|
||||
pRet = (Fts5Data*)sqlite3_malloc64(nAlloc);
|
||||
if( pRet ){
|
||||
pRet->nn = nByte;
|
||||
aOut = pRet->p = (u8*)&pRet[1];
|
||||
@@ -849,7 +848,7 @@ static int fts5StructureDecode(
|
||||
int iLvl;
|
||||
int nLevel = 0;
|
||||
int nSegment = 0;
|
||||
int nByte; /* Bytes of space to allocate at pRet */
|
||||
sqlite3_int64 nByte; /* Bytes of space to allocate at pRet */
|
||||
Fts5Structure *pRet = 0; /* Structure object to return */
|
||||
|
||||
/* Grab the cookie value */
|
||||
@@ -933,12 +932,12 @@ static void fts5StructureAddLevel(int *pRc, Fts5Structure **ppStruct){
|
||||
if( *pRc==SQLITE_OK ){
|
||||
Fts5Structure *pStruct = *ppStruct;
|
||||
int nLevel = pStruct->nLevel;
|
||||
int nByte = (
|
||||
sqlite3_int64 nByte = (
|
||||
sizeof(Fts5Structure) + /* Main structure */
|
||||
sizeof(Fts5StructureLevel) * (nLevel+1) /* aLevel[] array */
|
||||
);
|
||||
|
||||
pStruct = sqlite3_realloc(pStruct, nByte);
|
||||
pStruct = sqlite3_realloc64(pStruct, nByte);
|
||||
if( pStruct ){
|
||||
memset(&pStruct->aLevel[nLevel], 0, sizeof(Fts5StructureLevel));
|
||||
pStruct->nLevel++;
|
||||
@@ -963,10 +962,10 @@ static void fts5StructureExtendLevel(
|
||||
if( *pRc==SQLITE_OK ){
|
||||
Fts5StructureLevel *pLvl = &pStruct->aLevel[iLvl];
|
||||
Fts5StructureSegment *aNew;
|
||||
int nByte;
|
||||
sqlite3_int64 nByte;
|
||||
|
||||
nByte = (pLvl->nSeg + nExtra) * sizeof(Fts5StructureSegment);
|
||||
aNew = sqlite3_realloc(pLvl->aSeg, nByte);
|
||||
aNew = sqlite3_realloc64(pLvl->aSeg, nByte);
|
||||
if( aNew ){
|
||||
if( bInsert==0 ){
|
||||
memset(&aNew[pLvl->nSeg], 0, sizeof(Fts5StructureSegment) * nExtra);
|
||||
@@ -1480,10 +1479,10 @@ static Fts5DlidxIter *fts5DlidxIterInit(
|
||||
int bDone = 0;
|
||||
|
||||
for(i=0; p->rc==SQLITE_OK && bDone==0; i++){
|
||||
int nByte = sizeof(Fts5DlidxIter) + i * sizeof(Fts5DlidxLvl);
|
||||
sqlite3_int64 nByte = sizeof(Fts5DlidxIter) + i * sizeof(Fts5DlidxLvl);
|
||||
Fts5DlidxIter *pNew;
|
||||
|
||||
pNew = (Fts5DlidxIter*)sqlite3_realloc(pIter, nByte);
|
||||
pNew = (Fts5DlidxIter*)sqlite3_realloc64(pIter, nByte);
|
||||
if( pNew==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -1653,7 +1652,7 @@ static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
|
||||
int nNew; /* Bytes of new data */
|
||||
|
||||
iOff += fts5GetVarint32(&a[iOff], nNew);
|
||||
if( iOff+nNew>pIter->pLeaf->nn || nKeep>pIter->term.n ){
|
||||
if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
|
||||
p->rc = FTS5_CORRUPT;
|
||||
return;
|
||||
}
|
||||
@@ -1780,7 +1779,7 @@ static void fts5SegIterReverseInitPage(Fts5Index *p, Fts5SegIter *pIter){
|
||||
/* If necessary, grow the pIter->aRowidOffset[] array. */
|
||||
if( iRowidOffset>=pIter->nRowidOffset ){
|
||||
int nNew = pIter->nRowidOffset + 8;
|
||||
int *aNew = (int*)sqlite3_realloc(pIter->aRowidOffset, nNew*sizeof(int));
|
||||
int *aNew = (int*)sqlite3_realloc64(pIter->aRowidOffset,nNew*sizeof(int));
|
||||
if( aNew==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
break;
|
||||
@@ -2234,10 +2233,10 @@ static void fts5LeafSeek(
|
||||
int szLeaf = pIter->pLeaf->szLeaf;
|
||||
int n = pIter->pLeaf->nn;
|
||||
|
||||
int nMatch = 0;
|
||||
int nKeep = 0;
|
||||
int nNew = 0;
|
||||
int iTermOff;
|
||||
u32 nMatch = 0;
|
||||
u32 nKeep = 0;
|
||||
u32 nNew = 0;
|
||||
u32 iTermOff;
|
||||
int iPgidx; /* Current offset in pgidx */
|
||||
int bEndOfPage = 0;
|
||||
|
||||
@@ -2261,15 +2260,15 @@ static void fts5LeafSeek(
|
||||
|
||||
assert( nKeep>=nMatch );
|
||||
if( nKeep==nMatch ){
|
||||
int nCmp;
|
||||
int i;
|
||||
nCmp = MIN(nNew, nTerm-nMatch);
|
||||
u32 nCmp;
|
||||
u32 i;
|
||||
nCmp = (u32)MIN(nNew, nTerm-nMatch);
|
||||
for(i=0; i<nCmp; i++){
|
||||
if( a[iOff+i]!=pTerm[nMatch+i] ) break;
|
||||
}
|
||||
nMatch += i;
|
||||
|
||||
if( nTerm==nMatch ){
|
||||
if( (u32)nTerm==nMatch ){
|
||||
if( i==nNew ){
|
||||
goto search_success;
|
||||
}else{
|
||||
@@ -2327,7 +2326,7 @@ static void fts5LeafSeek(
|
||||
|
||||
search_success:
|
||||
pIter->iLeafOffset = iOff + nNew;
|
||||
if( pIter->iLeafOffset>n ){
|
||||
if( pIter->iLeafOffset>n || nNew<1 ){
|
||||
p->rc = FTS5_CORRUPT;
|
||||
return;
|
||||
}
|
||||
@@ -2458,31 +2457,40 @@ static void fts5SegIterHashInit(
|
||||
int flags, /* Mask of FTS5INDEX_XXX flags */
|
||||
Fts5SegIter *pIter /* Object to populate */
|
||||
){
|
||||
const u8 *pList = 0;
|
||||
int nList = 0;
|
||||
const u8 *z = 0;
|
||||
int n = 0;
|
||||
Fts5Data *pLeaf = 0;
|
||||
|
||||
assert( p->pHash );
|
||||
assert( p->rc==SQLITE_OK );
|
||||
|
||||
if( pTerm==0 || (flags & FTS5INDEX_QUERY_SCAN) ){
|
||||
const u8 *pList = 0;
|
||||
|
||||
p->rc = sqlite3Fts5HashScanInit(p->pHash, (const char*)pTerm, nTerm);
|
||||
sqlite3Fts5HashScanEntry(p->pHash, (const char**)&z, &pList, &nList);
|
||||
n = (z ? (int)strlen((const char*)z) : 0);
|
||||
if( pList ){
|
||||
pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
|
||||
if( pLeaf ){
|
||||
pLeaf->p = (u8*)pList;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
pIter->flags |= FTS5_SEGITER_ONETERM;
|
||||
sqlite3Fts5HashQuery(p->pHash, (const char*)pTerm, nTerm, &pList, &nList);
|
||||
p->rc = sqlite3Fts5HashQuery(p->pHash, sizeof(Fts5Data),
|
||||
(const char*)pTerm, nTerm, (void**)&pLeaf, &nList
|
||||
);
|
||||
if( pLeaf ){
|
||||
pLeaf->p = (u8*)&pLeaf[1];
|
||||
}
|
||||
z = pTerm;
|
||||
n = nTerm;
|
||||
pIter->flags |= FTS5_SEGITER_ONETERM;
|
||||
}
|
||||
|
||||
if( pList ){
|
||||
Fts5Data *pLeaf;
|
||||
if( pLeaf ){
|
||||
sqlite3Fts5BufferSet(&p->rc, &pIter->term, n, z);
|
||||
pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
|
||||
if( pLeaf==0 ) return;
|
||||
pLeaf->p = (u8*)pList;
|
||||
pLeaf->nn = pLeaf->szLeaf = nList;
|
||||
pIter->pLeaf = pLeaf;
|
||||
pIter->iLeafOffset = fts5GetVarint(pLeaf->p, (u64*)&pIter->iRowid);
|
||||
@@ -2535,7 +2543,7 @@ static void fts5AssertComparisonResult(
|
||||
assert( pRes->iFirst==i1 );
|
||||
}else{
|
||||
int nMin = MIN(p1->term.n, p2->term.n);
|
||||
int res = memcmp(p1->term.p, p2->term.p, nMin);
|
||||
int res = fts5Memcmp(p1->term.p, p2->term.p, nMin);
|
||||
if( res==0 ) res = p1->term.n - p2->term.n;
|
||||
|
||||
if( res==0 ){
|
||||
@@ -2635,8 +2643,8 @@ static int fts5MultiIterDoCompare(Fts5Iter *pIter, int iOut){
|
||||
}else{
|
||||
int res = fts5BufferCompare(&p1->term, &p2->term);
|
||||
if( res==0 ){
|
||||
assert( i2>i1 );
|
||||
assert( i2!=0 );
|
||||
assert_nc( i2>i1 );
|
||||
assert_nc( i2!=0 );
|
||||
pRes->bTermEq = 1;
|
||||
if( p1->iRowid==p2->iRowid ){
|
||||
p1->bDel = p2->bDel;
|
||||
@@ -2758,7 +2766,6 @@ static void fts5MultiIterFree(Fts5Iter *pIter){
|
||||
for(i=0; i<pIter->nSeg; i++){
|
||||
fts5SegIterClear(&pIter->aSeg[i]);
|
||||
}
|
||||
fts5StructureRelease(pIter->pStruct);
|
||||
fts5BufferFree(&pIter->poslist);
|
||||
sqlite3_free(pIter);
|
||||
}
|
||||
@@ -3106,7 +3113,8 @@ static void fts5SegiterPoslist(
|
||||
Fts5Colset *pColset,
|
||||
Fts5Buffer *pBuf
|
||||
){
|
||||
if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos) ){
|
||||
if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){
|
||||
memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING);
|
||||
if( pColset==0 ){
|
||||
fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback);
|
||||
}else{
|
||||
@@ -3404,9 +3412,7 @@ static void fts5MultiIterNew(
|
||||
if( pNew==0 ) return;
|
||||
pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC));
|
||||
pNew->bSkipEmpty = (0!=(flags & FTS5INDEX_QUERY_SKIPEMPTY));
|
||||
pNew->pStruct = pStruct;
|
||||
pNew->pColset = pColset;
|
||||
fts5StructureRef(pStruct);
|
||||
if( (flags & FTS5INDEX_QUERY_NOOUTPUT)==0 ){
|
||||
fts5IterSetOutputCb(&p->rc, pNew);
|
||||
}
|
||||
@@ -3584,7 +3590,7 @@ static int fts5AllocateSegid(Fts5Index *p, Fts5Structure *pStruct){
|
||||
for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
|
||||
for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
|
||||
int iId = pStruct->aLevel[iLvl].aSeg[iSeg].iSegid;
|
||||
if( iId<=FTS5_MAX_SEGMENT ){
|
||||
if( iId<=FTS5_MAX_SEGMENT && iId>0 ){
|
||||
aUsed[(iId-1) / 32] |= (u32)1 << ((iId-1) % 32);
|
||||
}
|
||||
}
|
||||
@@ -3679,7 +3685,7 @@ static int fts5WriteDlidxGrow(
|
||||
int nLvl
|
||||
){
|
||||
if( p->rc==SQLITE_OK && nLvl>=pWriter->nDlidx ){
|
||||
Fts5DlidxWriter *aDlidx = (Fts5DlidxWriter*)sqlite3_realloc(
|
||||
Fts5DlidxWriter *aDlidx = (Fts5DlidxWriter*)sqlite3_realloc64(
|
||||
pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl
|
||||
);
|
||||
if( aDlidx==0 ){
|
||||
@@ -4131,7 +4137,7 @@ static void fts5TrimSegments(Fts5Index *p, Fts5Iter *pIter){
|
||||
int i;
|
||||
Fts5Buffer buf;
|
||||
memset(&buf, 0, sizeof(Fts5Buffer));
|
||||
for(i=0; i<pIter->nSeg; i++){
|
||||
for(i=0; i<pIter->nSeg && p->rc==SQLITE_OK; i++){
|
||||
Fts5SegIter *pSeg = &pIter->aSeg[i];
|
||||
if( pSeg->pSeg==0 ){
|
||||
/* no-op */
|
||||
@@ -4149,35 +4155,44 @@ static void fts5TrimSegments(Fts5Index *p, Fts5Iter *pIter){
|
||||
u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno);
|
||||
pData = fts5DataRead(p, iLeafRowid);
|
||||
pData = fts5LeafRead(p, iLeafRowid);
|
||||
if( pData ){
|
||||
fts5BufferZero(&buf);
|
||||
fts5BufferGrow(&p->rc, &buf, pData->nn);
|
||||
fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
|
||||
fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
|
||||
fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
|
||||
fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff, &pData->p[iOff]);
|
||||
if( p->rc==SQLITE_OK ){
|
||||
/* Set the szLeaf field */
|
||||
fts5PutU16(&buf.p[2], (u16)buf.n);
|
||||
}
|
||||
if( iOff>pData->szLeaf ){
|
||||
/* This can occur if the pages that the segments occupy overlap - if
|
||||
** a single page has been assigned to more than one segment. In
|
||||
** this case a prior iteration of this loop may have corrupted the
|
||||
** segment currently being trimmed. */
|
||||
p->rc = FTS5_CORRUPT;
|
||||
}else{
|
||||
fts5BufferZero(&buf);
|
||||
fts5BufferGrow(&p->rc, &buf, pData->nn);
|
||||
fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
|
||||
fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
|
||||
fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
|
||||
fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff,&pData->p[iOff]);
|
||||
if( p->rc==SQLITE_OK ){
|
||||
/* Set the szLeaf field */
|
||||
fts5PutU16(&buf.p[2], (u16)buf.n);
|
||||
}
|
||||
|
||||
/* Set up the new page-index array */
|
||||
fts5BufferAppendVarint(&p->rc, &buf, 4);
|
||||
if( pSeg->iLeafPgno==pSeg->iTermLeafPgno
|
||||
&& pSeg->iEndofDoclist<pData->szLeaf
|
||||
){
|
||||
int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
|
||||
fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
|
||||
fts5BufferAppendBlob(&p->rc, &buf,
|
||||
pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
|
||||
);
|
||||
}
|
||||
/* Set up the new page-index array */
|
||||
fts5BufferAppendVarint(&p->rc, &buf, 4);
|
||||
if( pSeg->iLeafPgno==pSeg->iTermLeafPgno
|
||||
&& pSeg->iEndofDoclist<pData->szLeaf
|
||||
&& pSeg->iPgidxOff<=pData->nn
|
||||
){
|
||||
int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
|
||||
fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
|
||||
fts5BufferAppendBlob(&p->rc, &buf,
|
||||
pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
|
||||
);
|
||||
}
|
||||
|
||||
pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
|
||||
fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
|
||||
fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
|
||||
}
|
||||
fts5DataRelease(pData);
|
||||
pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
|
||||
fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
|
||||
fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4269,7 +4284,7 @@ static void fts5IndexMergeLevel(
|
||||
const u8 *pTerm;
|
||||
|
||||
pTerm = fts5MultiIterTerm(pIter, &nTerm);
|
||||
if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){
|
||||
if( nTerm!=term.n || fts5Memcmp(pTerm, term.p, nTerm) ){
|
||||
if( pnRem && writer.nLeafWritten>nRem ){
|
||||
break;
|
||||
}
|
||||
@@ -4547,6 +4562,7 @@ static void fts5FlushOneHash(Fts5Index *p){
|
||||
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
|
||||
writer.bFirstRowidInPage = 0;
|
||||
fts5WriteDlidxAppend(p, &writer, iRowid);
|
||||
if( p->rc!=SQLITE_OK ) break;
|
||||
}else{
|
||||
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iDelta);
|
||||
}
|
||||
@@ -4648,7 +4664,7 @@ static Fts5Structure *fts5IndexOptimizeStruct(
|
||||
Fts5Structure *pStruct
|
||||
){
|
||||
Fts5Structure *pNew = 0;
|
||||
int nByte = sizeof(Fts5Structure);
|
||||
sqlite3_int64 nByte = sizeof(Fts5Structure);
|
||||
int nSeg = pStruct->nSegment;
|
||||
int i;
|
||||
|
||||
@@ -4778,11 +4794,13 @@ static void fts5AppendPoslist(
|
||||
Fts5Buffer *pBuf
|
||||
){
|
||||
int nData = pMulti->base.nData;
|
||||
int nByte = nData + 9 + 9 + FTS5_DATA_ZERO_PADDING;
|
||||
assert( nData>0 );
|
||||
if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nData+9+9) ){
|
||||
if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nByte) ){
|
||||
fts5BufferSafeAppendVarint(pBuf, iDelta);
|
||||
fts5BufferSafeAppendVarint(pBuf, nData*2);
|
||||
fts5BufferSafeAppendBlob(pBuf, pMulti->base.pData, nData);
|
||||
memset(&pBuf->p[pBuf->n], 0, FTS5_DATA_ZERO_PADDING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4963,6 +4981,8 @@ static void fts5MergePrefixLists(
|
||||
int iOff2 = 0;
|
||||
u8 *a1 = &i1.aPoslist[i1.nSize];
|
||||
u8 *a2 = &i2.aPoslist[i2.nSize];
|
||||
int nCopy;
|
||||
u8 *aCopy;
|
||||
|
||||
i64 iPrev = 0;
|
||||
Fts5PoslistWriter writer;
|
||||
@@ -4994,7 +5014,7 @@ static void fts5MergePrefixLists(
|
||||
sqlite3Fts5PoslistNext64(a1, i1.nPoslist, &iOff1, &iPos1);
|
||||
if( iPos1<0 ) break;
|
||||
}else{
|
||||
assert( iPos2!=iPrev );
|
||||
assert_nc( iPos2!=iPrev );
|
||||
sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2);
|
||||
sqlite3Fts5PoslistNext64(a2, i2.nPoslist, &iOff2, &iPos2);
|
||||
if( iPos2<0 ) break;
|
||||
@@ -5006,11 +5026,16 @@ static void fts5MergePrefixLists(
|
||||
if( iPos1!=iPrev ){
|
||||
sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1);
|
||||
}
|
||||
fts5BufferSafeAppendBlob(&tmp, &a1[iOff1], i1.nPoslist-iOff1);
|
||||
aCopy = &a1[iOff1];
|
||||
nCopy = i1.nPoslist - iOff1;
|
||||
}else{
|
||||
assert( iPos2>=0 && iPos2!=iPrev );
|
||||
sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2);
|
||||
fts5BufferSafeAppendBlob(&tmp, &a2[iOff2], i2.nPoslist-iOff2);
|
||||
aCopy = &a2[iOff2];
|
||||
nCopy = i2.nPoslist - iOff2;
|
||||
}
|
||||
if( nCopy>0 ){
|
||||
fts5BufferSafeAppendBlob(&tmp, aCopy, nCopy);
|
||||
}
|
||||
|
||||
/* WRITEPOSLISTSIZE */
|
||||
@@ -5018,6 +5043,7 @@ static void fts5MergePrefixLists(
|
||||
fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
|
||||
fts5DoclistIterNext(&i1);
|
||||
fts5DoclistIterNext(&i2);
|
||||
assert( out.n<=(p1->n+p2->n+9) );
|
||||
if( i1.aPoslist==0 || i2.aPoslist==0 ) break;
|
||||
}
|
||||
}
|
||||
@@ -5119,7 +5145,7 @@ static void fts5SetupPrefixIter(
|
||||
}
|
||||
fts5MultiIterFree(p1);
|
||||
|
||||
pData = fts5IdxMalloc(p, sizeof(Fts5Data) + doclist.n);
|
||||
pData = fts5IdxMalloc(p, sizeof(Fts5Data)+doclist.n+FTS5_DATA_ZERO_PADDING);
|
||||
if( pData ){
|
||||
pData->p = (u8*)&pData[1];
|
||||
pData->nn = pData->szLeaf = doclist.n;
|
||||
@@ -5885,7 +5911,7 @@ static void fts5IndexIntegrityCheckSegment(
|
||||
p->rc = FTS5_CORRUPT;
|
||||
}else{
|
||||
iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
|
||||
res = memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
|
||||
res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
|
||||
if( res==0 ) res = nTerm - nIdxTerm;
|
||||
if( res<0 ) p->rc = FTS5_CORRUPT;
|
||||
}
|
||||
@@ -6280,7 +6306,7 @@ static void fts5DecodeFunction(
|
||||
u8 *a = 0;
|
||||
Fts5Buffer s; /* Build up text to return here */
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
int nSpace = 0;
|
||||
sqlite3_int64 nSpace = 0;
|
||||
int eDetailNone = (sqlite3_user_data(pCtx)!=0);
|
||||
|
||||
assert( nArg==2 );
|
||||
@@ -6391,6 +6417,9 @@ static void fts5DecodeFunction(
|
||||
iPgidxOff = szLeaf = fts5GetU16(&a[2]);
|
||||
if( iPgidxOff<n ){
|
||||
fts5GetVarint32(&a[iPgidxOff], iTermOff);
|
||||
}else if( iPgidxOff>n ){
|
||||
rc = FTS5_CORRUPT;
|
||||
goto decode_out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6402,14 +6431,22 @@ static void fts5DecodeFunction(
|
||||
}else{
|
||||
iOff = szLeaf;
|
||||
}
|
||||
if( iOff>n ){
|
||||
rc = FTS5_CORRUPT;
|
||||
goto decode_out;
|
||||
}
|
||||
fts5DecodePoslist(&rc, &s, &a[4], iOff-4);
|
||||
|
||||
/* Decode any more doclist data that appears on the page before the
|
||||
** first term. */
|
||||
nDoclist = (iTermOff ? iTermOff : szLeaf) - iOff;
|
||||
if( nDoclist+iOff>n ){
|
||||
rc = FTS5_CORRUPT;
|
||||
goto decode_out;
|
||||
}
|
||||
fts5DecodeDoclist(&rc, &s, &a[iOff], nDoclist);
|
||||
|
||||
while( iPgidxOff<n ){
|
||||
while( iPgidxOff<n && rc==SQLITE_OK ){
|
||||
int bFirst = (iPgidxOff==szLeaf); /* True for first term on page */
|
||||
int nByte; /* Bytes of data */
|
||||
int iEnd;
|
||||
@@ -6424,12 +6461,24 @@ static void fts5DecodeFunction(
|
||||
}else{
|
||||
iEnd = szLeaf;
|
||||
}
|
||||
if( iEnd>szLeaf ){
|
||||
rc = FTS5_CORRUPT;
|
||||
break;
|
||||
}
|
||||
|
||||
if( bFirst==0 ){
|
||||
iOff += fts5GetVarint32(&a[iOff], nByte);
|
||||
if( nByte>term.n ){
|
||||
rc = FTS5_CORRUPT;
|
||||
break;
|
||||
}
|
||||
term.n = nByte;
|
||||
}
|
||||
iOff += fts5GetVarint32(&a[iOff], nByte);
|
||||
if( iOff+nByte>n ){
|
||||
rc = FTS5_CORRUPT;
|
||||
break;
|
||||
}
|
||||
fts5BufferAppendBlob(&rc, &term, nByte, &a[iOff]);
|
||||
iOff += nByte;
|
||||
|
||||
|
||||
+158
-152
@@ -28,8 +28,8 @@ int sqlite3_fts5_may_be_corrupt = 1;
|
||||
typedef struct Fts5Auxdata Fts5Auxdata;
|
||||
typedef struct Fts5Auxiliary Fts5Auxiliary;
|
||||
typedef struct Fts5Cursor Fts5Cursor;
|
||||
typedef struct Fts5FullTable Fts5FullTable;
|
||||
typedef struct Fts5Sorter Fts5Sorter;
|
||||
typedef struct Fts5Table Fts5Table;
|
||||
typedef struct Fts5TokenizerModule Fts5TokenizerModule;
|
||||
|
||||
/*
|
||||
@@ -110,13 +110,8 @@ struct Fts5TokenizerModule {
|
||||
Fts5TokenizerModule *pNext; /* Next registered tokenizer module */
|
||||
};
|
||||
|
||||
/*
|
||||
** Virtual-table object.
|
||||
*/
|
||||
struct Fts5Table {
|
||||
sqlite3_vtab base; /* Base class used by SQLite core */
|
||||
Fts5Config *pConfig; /* Virtual table configuration */
|
||||
Fts5Index *pIndex; /* Full-text index */
|
||||
struct Fts5FullTable {
|
||||
Fts5Table p; /* Public class members from fts5Int.h */
|
||||
Fts5Storage *pStorage; /* Document store */
|
||||
Fts5Global *pGlobal; /* Global (connection wide) data */
|
||||
Fts5Cursor *pSortCsr; /* Sort data from this cursor */
|
||||
@@ -254,7 +249,7 @@ struct Fts5Auxdata {
|
||||
#define FTS5_SAVEPOINT 5
|
||||
#define FTS5_RELEASE 6
|
||||
#define FTS5_ROLLBACKTO 7
|
||||
static void fts5CheckTransactionState(Fts5Table *p, int op, int iSavepoint){
|
||||
static void fts5CheckTransactionState(Fts5FullTable *p, int op, int iSavepoint){
|
||||
switch( op ){
|
||||
case FTS5_BEGIN:
|
||||
assert( p->ts.eState==0 );
|
||||
@@ -293,7 +288,7 @@ static void fts5CheckTransactionState(Fts5Table *p, int op, int iSavepoint){
|
||||
|
||||
case FTS5_ROLLBACKTO:
|
||||
assert( p->ts.eState==1 );
|
||||
assert( iSavepoint>=0 );
|
||||
assert( iSavepoint>=-1 );
|
||||
assert( iSavepoint<=p->ts.iSavepoint );
|
||||
p->ts.iSavepoint = iSavepoint;
|
||||
break;
|
||||
@@ -306,18 +301,18 @@ static void fts5CheckTransactionState(Fts5Table *p, int op, int iSavepoint){
|
||||
/*
|
||||
** Return true if pTab is a contentless table.
|
||||
*/
|
||||
static int fts5IsContentless(Fts5Table *pTab){
|
||||
return pTab->pConfig->eContent==FTS5_CONTENT_NONE;
|
||||
static int fts5IsContentless(Fts5FullTable *pTab){
|
||||
return pTab->p.pConfig->eContent==FTS5_CONTENT_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete a virtual table handle allocated by fts5InitVtab().
|
||||
*/
|
||||
static void fts5FreeVtab(Fts5Table *pTab){
|
||||
static void fts5FreeVtab(Fts5FullTable *pTab){
|
||||
if( pTab ){
|
||||
sqlite3Fts5IndexClose(pTab->pIndex);
|
||||
sqlite3Fts5IndexClose(pTab->p.pIndex);
|
||||
sqlite3Fts5StorageClose(pTab->pStorage);
|
||||
sqlite3Fts5ConfigFree(pTab->pConfig);
|
||||
sqlite3Fts5ConfigFree(pTab->p.pConfig);
|
||||
sqlite3_free(pTab);
|
||||
}
|
||||
}
|
||||
@@ -326,7 +321,7 @@ static void fts5FreeVtab(Fts5Table *pTab){
|
||||
** The xDisconnect() virtual table method.
|
||||
*/
|
||||
static int fts5DisconnectMethod(sqlite3_vtab *pVtab){
|
||||
fts5FreeVtab((Fts5Table*)pVtab);
|
||||
fts5FreeVtab((Fts5FullTable*)pVtab);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -337,7 +332,7 @@ static int fts5DestroyMethod(sqlite3_vtab *pVtab){
|
||||
Fts5Table *pTab = (Fts5Table*)pVtab;
|
||||
int rc = sqlite3Fts5DropAll(pTab->pConfig);
|
||||
if( rc==SQLITE_OK ){
|
||||
fts5FreeVtab((Fts5Table*)pVtab);
|
||||
fts5FreeVtab((Fts5FullTable*)pVtab);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -366,28 +361,28 @@ static int fts5InitVtab(
|
||||
const char **azConfig = (const char**)argv;
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
Fts5Config *pConfig = 0; /* Results of parsing argc/argv */
|
||||
Fts5Table *pTab = 0; /* New virtual table object */
|
||||
Fts5FullTable *pTab = 0; /* New virtual table object */
|
||||
|
||||
/* Allocate the new vtab object and parse the configuration */
|
||||
pTab = (Fts5Table*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5Table));
|
||||
pTab = (Fts5FullTable*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5FullTable));
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5ConfigParse(pGlobal, db, argc, azConfig, &pConfig, pzErr);
|
||||
assert( (rc==SQLITE_OK && *pzErr==0) || pConfig==0 );
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
pTab->pConfig = pConfig;
|
||||
pTab->p.pConfig = pConfig;
|
||||
pTab->pGlobal = pGlobal;
|
||||
}
|
||||
|
||||
/* Open the index sub-system */
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5IndexOpen(pConfig, bCreate, &pTab->pIndex, pzErr);
|
||||
rc = sqlite3Fts5IndexOpen(pConfig, bCreate, &pTab->p.pIndex, pzErr);
|
||||
}
|
||||
|
||||
/* Open the storage sub-system */
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5StorageOpen(
|
||||
pConfig, pTab->pIndex, bCreate, &pTab->pStorage, pzErr
|
||||
pConfig, pTab->p.pIndex, bCreate, &pTab->pStorage, pzErr
|
||||
);
|
||||
}
|
||||
|
||||
@@ -400,8 +395,8 @@ static int fts5InitVtab(
|
||||
if( rc==SQLITE_OK ){
|
||||
assert( pConfig->pzErrmsg==0 );
|
||||
pConfig->pzErrmsg = pzErr;
|
||||
rc = sqlite3Fts5IndexLoadConfig(pTab->pIndex);
|
||||
sqlite3Fts5IndexRollback(pTab->pIndex);
|
||||
rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
|
||||
sqlite3Fts5IndexRollback(pTab->p.pIndex);
|
||||
pConfig->pzErrmsg = 0;
|
||||
}
|
||||
|
||||
@@ -614,7 +609,7 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int fts5NewTransaction(Fts5Table *pTab){
|
||||
static int fts5NewTransaction(Fts5FullTable *pTab){
|
||||
Fts5Cursor *pCsr;
|
||||
for(pCsr=pTab->pGlobal->pCsr; pCsr; pCsr=pCsr->pNext){
|
||||
if( pCsr->base.pVtab==(sqlite3_vtab*)pTab ) return SQLITE_OK;
|
||||
@@ -626,19 +621,19 @@ static int fts5NewTransaction(Fts5Table *pTab){
|
||||
** Implementation of xOpen method.
|
||||
*/
|
||||
static int fts5OpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){
|
||||
Fts5Table *pTab = (Fts5Table*)pVTab;
|
||||
Fts5Config *pConfig = pTab->pConfig;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)pVTab;
|
||||
Fts5Config *pConfig = pTab->p.pConfig;
|
||||
Fts5Cursor *pCsr = 0; /* New cursor object */
|
||||
int nByte; /* Bytes of space to allocate */
|
||||
sqlite3_int64 nByte; /* Bytes of space to allocate */
|
||||
int rc; /* Return code */
|
||||
|
||||
rc = fts5NewTransaction(pTab);
|
||||
if( rc==SQLITE_OK ){
|
||||
nByte = sizeof(Fts5Cursor) + pConfig->nCol * sizeof(int);
|
||||
pCsr = (Fts5Cursor*)sqlite3_malloc(nByte);
|
||||
pCsr = (Fts5Cursor*)sqlite3_malloc64(nByte);
|
||||
if( pCsr ){
|
||||
Fts5Global *pGlobal = pTab->pGlobal;
|
||||
memset(pCsr, 0, nByte);
|
||||
memset(pCsr, 0, (size_t)nByte);
|
||||
pCsr->aColumnSize = (int*)&pCsr[1];
|
||||
pCsr->pNext = pGlobal->pCsr;
|
||||
pGlobal->pCsr = pCsr;
|
||||
@@ -673,7 +668,7 @@ static void fts5CsrNewrow(Fts5Cursor *pCsr){
|
||||
}
|
||||
|
||||
static void fts5FreeCursorComponents(Fts5Cursor *pCsr){
|
||||
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
|
||||
Fts5Auxdata *pData;
|
||||
Fts5Auxdata *pNext;
|
||||
|
||||
@@ -717,7 +712,7 @@ static void fts5FreeCursorComponents(Fts5Cursor *pCsr){
|
||||
*/
|
||||
static int fts5CloseMethod(sqlite3_vtab_cursor *pCursor){
|
||||
if( pCursor ){
|
||||
Fts5Table *pTab = (Fts5Table*)(pCursor->pVtab);
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCursor->pVtab);
|
||||
Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
|
||||
Fts5Cursor **pp;
|
||||
|
||||
@@ -774,7 +769,7 @@ static int fts5SorterNext(Fts5Cursor *pCsr){
|
||||
** Set the FTS5CSR_REQUIRE_RESEEK flag on all FTS5_PLAN_MATCH cursors
|
||||
** open on table pTab.
|
||||
*/
|
||||
static void fts5TripCursors(Fts5Table *pTab){
|
||||
static void fts5TripCursors(Fts5FullTable *pTab){
|
||||
Fts5Cursor *pCsr;
|
||||
for(pCsr=pTab->pGlobal->pCsr; pCsr; pCsr=pCsr->pNext){
|
||||
if( pCsr->ePlan==FTS5_PLAN_MATCH
|
||||
@@ -801,11 +796,11 @@ static int fts5CursorReseek(Fts5Cursor *pCsr, int *pbSkip){
|
||||
int rc = SQLITE_OK;
|
||||
assert( *pbSkip==0 );
|
||||
if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_RESEEK) ){
|
||||
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
|
||||
int bDesc = pCsr->bDesc;
|
||||
i64 iRowid = sqlite3Fts5ExprRowid(pCsr->pExpr);
|
||||
|
||||
rc = sqlite3Fts5ExprFirst(pCsr->pExpr, pTab->pIndex, iRowid, bDesc);
|
||||
rc = sqlite3Fts5ExprFirst(pCsr->pExpr, pTab->p.pIndex, iRowid, bDesc);
|
||||
if( rc==SQLITE_OK && iRowid!=sqlite3Fts5ExprRowid(pCsr->pExpr) ){
|
||||
*pbSkip = 1;
|
||||
}
|
||||
@@ -902,20 +897,24 @@ static int fts5PrepareStatement(
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){
|
||||
Fts5Config *pConfig = pTab->pConfig;
|
||||
static int fts5CursorFirstSorted(
|
||||
Fts5FullTable *pTab,
|
||||
Fts5Cursor *pCsr,
|
||||
int bDesc
|
||||
){
|
||||
Fts5Config *pConfig = pTab->p.pConfig;
|
||||
Fts5Sorter *pSorter;
|
||||
int nPhrase;
|
||||
int nByte;
|
||||
sqlite3_int64 nByte;
|
||||
int rc;
|
||||
const char *zRank = pCsr->zRank;
|
||||
const char *zRankArgs = pCsr->zRankArgs;
|
||||
|
||||
nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
|
||||
nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1);
|
||||
pSorter = (Fts5Sorter*)sqlite3_malloc(nByte);
|
||||
pSorter = (Fts5Sorter*)sqlite3_malloc64(nByte);
|
||||
if( pSorter==0 ) return SQLITE_NOMEM;
|
||||
memset(pSorter, 0, nByte);
|
||||
memset(pSorter, 0, (size_t)nByte);
|
||||
pSorter->nIdx = nPhrase;
|
||||
|
||||
/* TODO: It would be better to have some system for reusing statement
|
||||
@@ -950,10 +949,10 @@ static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int fts5CursorFirst(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){
|
||||
static int fts5CursorFirst(Fts5FullTable *pTab, Fts5Cursor *pCsr, int bDesc){
|
||||
int rc;
|
||||
Fts5Expr *pExpr = pCsr->pExpr;
|
||||
rc = sqlite3Fts5ExprFirst(pExpr, pTab->pIndex, pCsr->iFirstRowid, bDesc);
|
||||
rc = sqlite3Fts5ExprFirst(pExpr, pTab->p.pIndex, pCsr->iFirstRowid, bDesc);
|
||||
if( sqlite3Fts5ExprEof(pExpr) ){
|
||||
CsrFlagSet(pCsr, FTS5CSR_EOF);
|
||||
}
|
||||
@@ -968,7 +967,7 @@ static int fts5CursorFirst(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){
|
||||
** parameters.
|
||||
*/
|
||||
static int fts5SpecialMatch(
|
||||
Fts5Table *pTab,
|
||||
Fts5FullTable *pTab,
|
||||
Fts5Cursor *pCsr,
|
||||
const char *zQuery
|
||||
){
|
||||
@@ -979,18 +978,18 @@ static int fts5SpecialMatch(
|
||||
while( z[0]==' ' ) z++;
|
||||
for(n=0; z[n] && z[n]!=' '; n++);
|
||||
|
||||
assert( pTab->base.zErrMsg==0 );
|
||||
assert( pTab->p.base.zErrMsg==0 );
|
||||
pCsr->ePlan = FTS5_PLAN_SPECIAL;
|
||||
|
||||
if( 0==sqlite3_strnicmp("reads", z, n) ){
|
||||
pCsr->iSpecial = sqlite3Fts5IndexReads(pTab->pIndex);
|
||||
pCsr->iSpecial = sqlite3Fts5IndexReads(pTab->p.pIndex);
|
||||
}
|
||||
else if( 0==sqlite3_strnicmp("id", z, n) ){
|
||||
pCsr->iSpecial = pCsr->iCsrId;
|
||||
}
|
||||
else{
|
||||
/* An unrecognized directive. Return an error message. */
|
||||
pTab->base.zErrMsg = sqlite3_mprintf("unknown special query: %.*s", n, z);
|
||||
pTab->p.base.zErrMsg = sqlite3_mprintf("unknown special query: %.*s", n, z);
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
|
||||
@@ -1002,7 +1001,7 @@ static int fts5SpecialMatch(
|
||||
** pTab. If one is found, return a pointer to the corresponding Fts5Auxiliary
|
||||
** structure. Otherwise, if no such function exists, return NULL.
|
||||
*/
|
||||
static Fts5Auxiliary *fts5FindAuxiliary(Fts5Table *pTab, const char *zName){
|
||||
static Fts5Auxiliary *fts5FindAuxiliary(Fts5FullTable *pTab, const char *zName){
|
||||
Fts5Auxiliary *pAux;
|
||||
|
||||
for(pAux=pTab->pGlobal->pAux; pAux; pAux=pAux->pNext){
|
||||
@@ -1015,8 +1014,8 @@ static Fts5Auxiliary *fts5FindAuxiliary(Fts5Table *pTab, const char *zName){
|
||||
|
||||
|
||||
static int fts5FindRankFunction(Fts5Cursor *pCsr){
|
||||
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
||||
Fts5Config *pConfig = pTab->pConfig;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
|
||||
Fts5Config *pConfig = pTab->p.pConfig;
|
||||
int rc = SQLITE_OK;
|
||||
Fts5Auxiliary *pAux = 0;
|
||||
const char *zRank = pCsr->zRank;
|
||||
@@ -1032,7 +1031,7 @@ static int fts5FindRankFunction(Fts5Cursor *pCsr){
|
||||
assert( rc==SQLITE_OK || pCsr->pRankArgStmt==0 );
|
||||
if( rc==SQLITE_OK ){
|
||||
if( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
int nByte;
|
||||
sqlite3_int64 nByte;
|
||||
pCsr->nRankArg = sqlite3_column_count(pStmt);
|
||||
nByte = sizeof(sqlite3_value*)*pCsr->nRankArg;
|
||||
pCsr->apRankArg = (sqlite3_value**)sqlite3Fts5MallocZero(&rc, nByte);
|
||||
@@ -1054,8 +1053,8 @@ static int fts5FindRankFunction(Fts5Cursor *pCsr){
|
||||
if( rc==SQLITE_OK ){
|
||||
pAux = fts5FindAuxiliary(pTab, zRank);
|
||||
if( pAux==0 ){
|
||||
assert( pTab->base.zErrMsg==0 );
|
||||
pTab->base.zErrMsg = sqlite3_mprintf("no such function: %s", zRank);
|
||||
assert( pTab->p.base.zErrMsg==0 );
|
||||
pTab->p.base.zErrMsg = sqlite3_mprintf("no such function: %s", zRank);
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -1130,8 +1129,8 @@ static int fts5FilterMethod(
|
||||
int nVal, /* Number of elements in apVal */
|
||||
sqlite3_value **apVal /* Arguments for the indexing scheme */
|
||||
){
|
||||
Fts5Table *pTab = (Fts5Table*)(pCursor->pVtab);
|
||||
Fts5Config *pConfig = pTab->pConfig;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCursor->pVtab);
|
||||
Fts5Config *pConfig = pTab->p.pConfig;
|
||||
Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
|
||||
int rc = SQLITE_OK; /* Error code */
|
||||
int iVal = 0; /* Counter for apVal[] */
|
||||
@@ -1160,8 +1159,8 @@ static int fts5FilterMethod(
|
||||
assert( pCsr->zRank==0 );
|
||||
assert( pCsr->zRankArgs==0 );
|
||||
|
||||
assert( pzErrmsg==0 || pzErrmsg==&pTab->base.zErrMsg );
|
||||
pConfig->pzErrmsg = &pTab->base.zErrMsg;
|
||||
assert( pzErrmsg==0 || pzErrmsg==&pTab->p.base.zErrMsg );
|
||||
pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
|
||||
|
||||
/* Decode the arguments passed through to this function.
|
||||
**
|
||||
@@ -1227,7 +1226,7 @@ static int fts5FilterMethod(
|
||||
** but a request for an internal parameter. */
|
||||
rc = fts5SpecialMatch(pTab, pCsr, &zExpr[1]);
|
||||
}else{
|
||||
char **pzErr = &pTab->base.zErrMsg;
|
||||
char **pzErr = &pTab->p.base.zErrMsg;
|
||||
rc = sqlite3Fts5ExprNew(pConfig, iCol, zExpr, &pCsr->pExpr, pzErr);
|
||||
if( rc==SQLITE_OK ){
|
||||
if( bOrderByRank ){
|
||||
@@ -1250,7 +1249,7 @@ static int fts5FilterMethod(
|
||||
** by rowid (ePlan==FTS5_PLAN_ROWID). */
|
||||
pCsr->ePlan = (pRowidEq ? FTS5_PLAN_ROWID : FTS5_PLAN_SCAN);
|
||||
rc = sqlite3Fts5StorageStmt(
|
||||
pTab->pStorage, fts5StmtType(pCsr), &pCsr->pStmt, &pTab->base.zErrMsg
|
||||
pTab->pStorage, fts5StmtType(pCsr), &pCsr->pStmt, &pTab->p.base.zErrMsg
|
||||
);
|
||||
if( rc==SQLITE_OK ){
|
||||
if( pCsr->ePlan==FTS5_PLAN_ROWID ){
|
||||
@@ -1333,12 +1332,12 @@ static int fts5SeekCursor(Fts5Cursor *pCsr, int bErrormsg){
|
||||
|
||||
/* If the cursor does not yet have a statement handle, obtain one now. */
|
||||
if( pCsr->pStmt==0 ){
|
||||
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
|
||||
int eStmt = fts5StmtType(pCsr);
|
||||
rc = sqlite3Fts5StorageStmt(
|
||||
pTab->pStorage, eStmt, &pCsr->pStmt, (bErrormsg?&pTab->base.zErrMsg:0)
|
||||
pTab->pStorage, eStmt, &pCsr->pStmt, (bErrormsg?&pTab->p.base.zErrMsg:0)
|
||||
);
|
||||
assert( rc!=SQLITE_OK || pTab->base.zErrMsg==0 );
|
||||
assert( rc!=SQLITE_OK || pTab->p.base.zErrMsg==0 );
|
||||
assert( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) );
|
||||
}
|
||||
|
||||
@@ -1360,11 +1359,11 @@ static int fts5SeekCursor(Fts5Cursor *pCsr, int bErrormsg){
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void fts5SetVtabError(Fts5Table *p, const char *zFormat, ...){
|
||||
static void fts5SetVtabError(Fts5FullTable *p, const char *zFormat, ...){
|
||||
va_list ap; /* ... printf arguments */
|
||||
va_start(ap, zFormat);
|
||||
assert( p->base.zErrMsg==0 );
|
||||
p->base.zErrMsg = sqlite3_vmprintf(zFormat, ap);
|
||||
assert( p->p.base.zErrMsg==0 );
|
||||
p->p.base.zErrMsg = sqlite3_vmprintf(zFormat, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@@ -1384,11 +1383,11 @@ static void fts5SetVtabError(Fts5Table *p, const char *zFormat, ...){
|
||||
** more commands are added to this function.
|
||||
*/
|
||||
static int fts5SpecialInsert(
|
||||
Fts5Table *pTab, /* Fts5 table object */
|
||||
Fts5FullTable *pTab, /* Fts5 table object */
|
||||
const char *zCmd, /* Text inserted into table-name column */
|
||||
sqlite3_value *pVal /* Value inserted into rank column */
|
||||
){
|
||||
Fts5Config *pConfig = pTab->pConfig;
|
||||
Fts5Config *pConfig = pTab->p.pConfig;
|
||||
int rc = SQLITE_OK;
|
||||
int bError = 0;
|
||||
|
||||
@@ -1423,9 +1422,9 @@ static int fts5SpecialInsert(
|
||||
pConfig->bPrefixIndex = sqlite3_value_int(pVal);
|
||||
#endif
|
||||
}else{
|
||||
rc = sqlite3Fts5IndexLoadConfig(pTab->pIndex);
|
||||
rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5ConfigSetValue(pTab->pConfig, zCmd, pVal, &bError);
|
||||
rc = sqlite3Fts5ConfigSetValue(pTab->p.pConfig, zCmd, pVal, &bError);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
if( bError ){
|
||||
@@ -1439,7 +1438,7 @@ static int fts5SpecialInsert(
|
||||
}
|
||||
|
||||
static int fts5SpecialDelete(
|
||||
Fts5Table *pTab,
|
||||
Fts5FullTable *pTab,
|
||||
sqlite3_value **apVal
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
@@ -1453,7 +1452,7 @@ static int fts5SpecialDelete(
|
||||
|
||||
static void fts5StorageInsert(
|
||||
int *pRc,
|
||||
Fts5Table *pTab,
|
||||
Fts5FullTable *pTab,
|
||||
sqlite3_value **apVal,
|
||||
i64 *piRowid
|
||||
){
|
||||
@@ -1487,8 +1486,8 @@ static int fts5UpdateMethod(
|
||||
sqlite3_value **apVal, /* Array of arguments */
|
||||
sqlite_int64 *pRowid /* OUT: The affected (or effected) rowid */
|
||||
){
|
||||
Fts5Table *pTab = (Fts5Table*)pVtab;
|
||||
Fts5Config *pConfig = pTab->pConfig;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
|
||||
Fts5Config *pConfig = pTab->p.pConfig;
|
||||
int eType0; /* value_type() of apVal[0] */
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
|
||||
@@ -1497,12 +1496,11 @@ static int fts5UpdateMethod(
|
||||
|
||||
assert( pVtab->zErrMsg==0 );
|
||||
assert( nArg==1 || nArg==(2+pConfig->nCol+2) );
|
||||
assert( nArg==1
|
||||
|| sqlite3_value_type(apVal[1])==SQLITE_INTEGER
|
||||
|| sqlite3_value_type(apVal[1])==SQLITE_NULL
|
||||
assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER
|
||||
|| sqlite3_value_type(apVal[0])==SQLITE_NULL
|
||||
);
|
||||
assert( pTab->pConfig->pzErrmsg==0 );
|
||||
pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
|
||||
assert( pTab->p.pConfig->pzErrmsg==0 );
|
||||
pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
|
||||
|
||||
/* Put any active cursors into REQUIRE_SEEK state. */
|
||||
fts5TripCursors(pTab);
|
||||
@@ -1543,7 +1541,7 @@ static int fts5UpdateMethod(
|
||||
/* Filter out attempts to run UPDATE or DELETE on contentless tables.
|
||||
** This is not suported. */
|
||||
if( eType0==SQLITE_INTEGER && fts5IsContentless(pTab) ){
|
||||
pTab->base.zErrMsg = sqlite3_mprintf(
|
||||
pTab->p.base.zErrMsg = sqlite3_mprintf(
|
||||
"cannot %s contentless fts5 table: %s",
|
||||
(nArg>1 ? "UPDATE" : "DELETE from"), pConfig->zName
|
||||
);
|
||||
@@ -1556,46 +1554,52 @@ static int fts5UpdateMethod(
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0);
|
||||
}
|
||||
|
||||
/* INSERT */
|
||||
else if( eType0!=SQLITE_INTEGER ){
|
||||
/* If this is a REPLACE, first remove the current entry (if any) */
|
||||
if( eConflict==SQLITE_REPLACE
|
||||
&& sqlite3_value_type(apVal[1])==SQLITE_INTEGER
|
||||
){
|
||||
i64 iNew = sqlite3_value_int64(apVal[1]); /* Rowid to delete */
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
|
||||
}
|
||||
fts5StorageInsert(&rc, pTab, apVal, pRowid);
|
||||
}
|
||||
|
||||
/* UPDATE */
|
||||
/* INSERT or UPDATE */
|
||||
else{
|
||||
i64 iOld = sqlite3_value_int64(apVal[0]); /* Old rowid */
|
||||
i64 iNew = sqlite3_value_int64(apVal[1]); /* New rowid */
|
||||
if( iOld!=iNew ){
|
||||
if( eConflict==SQLITE_REPLACE ){
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
|
||||
}
|
||||
fts5StorageInsert(&rc, pTab, apVal, pRowid);
|
||||
}else{
|
||||
rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, apVal, pRowid);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5StorageIndexInsert(pTab->pStorage, apVal, *pRowid);
|
||||
}
|
||||
int eType1 = sqlite3_value_numeric_type(apVal[1]);
|
||||
|
||||
if( eType1!=SQLITE_INTEGER && eType1!=SQLITE_NULL ){
|
||||
rc = SQLITE_MISMATCH;
|
||||
}
|
||||
|
||||
else if( eType0!=SQLITE_INTEGER ){
|
||||
/* If this is a REPLACE, first remove the current entry (if any) */
|
||||
if( eConflict==SQLITE_REPLACE && eType1==SQLITE_INTEGER ){
|
||||
i64 iNew = sqlite3_value_int64(apVal[1]); /* Rowid to delete */
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
|
||||
}
|
||||
}else{
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
|
||||
fts5StorageInsert(&rc, pTab, apVal, pRowid);
|
||||
}
|
||||
|
||||
/* UPDATE */
|
||||
else{
|
||||
i64 iOld = sqlite3_value_int64(apVal[0]); /* Old rowid */
|
||||
i64 iNew = sqlite3_value_int64(apVal[1]); /* New rowid */
|
||||
if( eType1==SQLITE_INTEGER && iOld!=iNew ){
|
||||
if( eConflict==SQLITE_REPLACE ){
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
|
||||
}
|
||||
fts5StorageInsert(&rc, pTab, apVal, pRowid);
|
||||
}else{
|
||||
rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, apVal, pRowid);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5StorageIndexInsert(pTab->pStorage, apVal,*pRowid);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
|
||||
fts5StorageInsert(&rc, pTab, apVal, pRowid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pTab->pConfig->pzErrmsg = 0;
|
||||
pTab->p.pConfig->pzErrmsg = 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1604,12 +1608,12 @@ static int fts5UpdateMethod(
|
||||
*/
|
||||
static int fts5SyncMethod(sqlite3_vtab *pVtab){
|
||||
int rc;
|
||||
Fts5Table *pTab = (Fts5Table*)pVtab;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
|
||||
fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
|
||||
pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
|
||||
pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
|
||||
fts5TripCursors(pTab);
|
||||
rc = sqlite3Fts5StorageSync(pTab->pStorage);
|
||||
pTab->pConfig->pzErrmsg = 0;
|
||||
pTab->p.pConfig->pzErrmsg = 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1617,8 +1621,8 @@ static int fts5SyncMethod(sqlite3_vtab *pVtab){
|
||||
** Implementation of xBegin() method.
|
||||
*/
|
||||
static int fts5BeginMethod(sqlite3_vtab *pVtab){
|
||||
fts5CheckTransactionState((Fts5Table*)pVtab, FTS5_BEGIN, 0);
|
||||
fts5NewTransaction((Fts5Table*)pVtab);
|
||||
fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_BEGIN, 0);
|
||||
fts5NewTransaction((Fts5FullTable*)pVtab);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -1629,7 +1633,7 @@ static int fts5BeginMethod(sqlite3_vtab *pVtab){
|
||||
*/
|
||||
static int fts5CommitMethod(sqlite3_vtab *pVtab){
|
||||
UNUSED_PARAM(pVtab); /* Call below is a no-op for NDEBUG builds */
|
||||
fts5CheckTransactionState((Fts5Table*)pVtab, FTS5_COMMIT, 0);
|
||||
fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_COMMIT, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -1639,7 +1643,7 @@ static int fts5CommitMethod(sqlite3_vtab *pVtab){
|
||||
*/
|
||||
static int fts5RollbackMethod(sqlite3_vtab *pVtab){
|
||||
int rc;
|
||||
Fts5Table *pTab = (Fts5Table*)pVtab;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
|
||||
fts5CheckTransactionState(pTab, FTS5_ROLLBACK, 0);
|
||||
rc = sqlite3Fts5StorageRollback(pTab->pStorage);
|
||||
return rc;
|
||||
@@ -1663,13 +1667,13 @@ static int fts5ApiColumnTotalSize(
|
||||
sqlite3_int64 *pnToken
|
||||
){
|
||||
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
||||
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
|
||||
return sqlite3Fts5StorageSize(pTab->pStorage, iCol, pnToken);
|
||||
}
|
||||
|
||||
static int fts5ApiRowCount(Fts5Context *pCtx, i64 *pnRow){
|
||||
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
||||
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
|
||||
return sqlite3Fts5StorageRowCount(pTab->pStorage, pnRow);
|
||||
}
|
||||
|
||||
@@ -1704,7 +1708,9 @@ static int fts5ApiColumnText(
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
||||
if( fts5IsContentless((Fts5Table*)(pCsr->base.pVtab)) ){
|
||||
if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab))
|
||||
|| pCsr->ePlan==FTS5_PLAN_SPECIAL
|
||||
){
|
||||
*pz = 0;
|
||||
*pn = 0;
|
||||
}else{
|
||||
@@ -1773,10 +1779,11 @@ static int fts5CacheInstArray(Fts5Cursor *pCsr){
|
||||
int rc = SQLITE_OK;
|
||||
Fts5PoslistReader *aIter; /* One iterator for each phrase */
|
||||
int nIter; /* Number of iterators/phrases */
|
||||
int nCol = ((Fts5Table*)pCsr->base.pVtab)->pConfig->nCol;
|
||||
|
||||
nIter = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
|
||||
if( pCsr->aInstIter==0 ){
|
||||
int nByte = sizeof(Fts5PoslistReader) * nIter;
|
||||
sqlite3_int64 nByte = sizeof(Fts5PoslistReader) * nIter;
|
||||
pCsr->aInstIter = (Fts5PoslistReader*)sqlite3Fts5MallocZero(&rc, nByte);
|
||||
}
|
||||
aIter = pCsr->aInstIter;
|
||||
@@ -1811,7 +1818,7 @@ static int fts5CacheInstArray(Fts5Cursor *pCsr){
|
||||
nInst++;
|
||||
if( nInst>=pCsr->nInstAlloc ){
|
||||
pCsr->nInstAlloc = pCsr->nInstAlloc ? pCsr->nInstAlloc*2 : 32;
|
||||
aInst = (int*)sqlite3_realloc(
|
||||
aInst = (int*)sqlite3_realloc64(
|
||||
pCsr->aInst, pCsr->nInstAlloc*sizeof(int)*3
|
||||
);
|
||||
if( aInst ){
|
||||
@@ -1826,6 +1833,10 @@ static int fts5CacheInstArray(Fts5Cursor *pCsr){
|
||||
aInst[0] = iBest;
|
||||
aInst[1] = FTS5_POS2COLUMN(aIter[iBest].iPos);
|
||||
aInst[2] = FTS5_POS2OFFSET(aIter[iBest].iPos);
|
||||
if( aInst[1]<0 || aInst[1]>=nCol ){
|
||||
rc = FTS5_CORRUPT;
|
||||
break;
|
||||
}
|
||||
sqlite3Fts5PoslistReaderNext(&aIter[iBest]);
|
||||
}
|
||||
}
|
||||
@@ -1898,8 +1909,8 @@ static int fts5ColumnSizeCb(
|
||||
|
||||
static int fts5ApiColumnSize(Fts5Context *pCtx, int iCol, int *pnToken){
|
||||
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
||||
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
||||
Fts5Config *pConfig = pTab->pConfig;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
|
||||
Fts5Config *pConfig = pTab->p.pConfig;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_DOCSIZE) ){
|
||||
@@ -2155,7 +2166,7 @@ static int fts5ApiQueryPhrase(
|
||||
int(*xCallback)(const Fts5ExtensionApi*, Fts5Context*, void*)
|
||||
){
|
||||
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
||||
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
|
||||
int rc;
|
||||
Fts5Cursor *pNew = 0;
|
||||
|
||||
@@ -2232,25 +2243,19 @@ static void fts5ApiCallback(
|
||||
|
||||
|
||||
/*
|
||||
** Given cursor id iId, return a pointer to the corresponding Fts5Index
|
||||
** Given cursor id iId, return a pointer to the corresponding Fts5Table
|
||||
** object. Or NULL If the cursor id does not exist.
|
||||
**
|
||||
** If successful, set *ppConfig to point to the associated config object
|
||||
** before returning.
|
||||
*/
|
||||
Fts5Index *sqlite3Fts5IndexFromCsrid(
|
||||
Fts5Table *sqlite3Fts5TableFromCsrid(
|
||||
Fts5Global *pGlobal, /* FTS5 global context for db handle */
|
||||
i64 iCsrId, /* Id of cursor to find */
|
||||
Fts5Config **ppConfig /* OUT: Configuration object */
|
||||
i64 iCsrId /* Id of cursor to find */
|
||||
){
|
||||
Fts5Cursor *pCsr;
|
||||
Fts5Table *pTab;
|
||||
|
||||
pCsr = fts5CursorFromCsrid(pGlobal, iCsrId);
|
||||
pTab = (Fts5Table*)pCsr->base.pVtab;
|
||||
*ppConfig = pTab->pConfig;
|
||||
|
||||
return pTab->pIndex;
|
||||
if( pCsr ){
|
||||
return (Fts5Table*)pCsr->base.pVtab;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2330,8 +2335,8 @@ static int fts5ColumnMethod(
|
||||
sqlite3_context *pCtx, /* Context for sqlite3_result_xxx() calls */
|
||||
int iCol /* Index of column to read value from */
|
||||
){
|
||||
Fts5Table *pTab = (Fts5Table*)(pCursor->pVtab);
|
||||
Fts5Config *pConfig = pTab->pConfig;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)(pCursor->pVtab);
|
||||
Fts5Config *pConfig = pTab->p.pConfig;
|
||||
Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
@@ -2383,7 +2388,7 @@ static int fts5FindFunctionMethod(
|
||||
void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), /* OUT: Result */
|
||||
void **ppArg /* OUT: User data for *pxFunc */
|
||||
){
|
||||
Fts5Table *pTab = (Fts5Table*)pVtab;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
|
||||
Fts5Auxiliary *pAux;
|
||||
|
||||
UNUSED_PARAM(nUnused);
|
||||
@@ -2405,21 +2410,24 @@ static int fts5RenameMethod(
|
||||
sqlite3_vtab *pVtab, /* Virtual table handle */
|
||||
const char *zName /* New name of table */
|
||||
){
|
||||
Fts5Table *pTab = (Fts5Table*)pVtab;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
|
||||
return sqlite3Fts5StorageRename(pTab->pStorage, zName);
|
||||
}
|
||||
|
||||
int sqlite3Fts5FlushToDisk(Fts5Table *pTab){
|
||||
fts5TripCursors((Fts5FullTable*)pTab);
|
||||
return sqlite3Fts5StorageSync(((Fts5FullTable*)pTab)->pStorage);
|
||||
}
|
||||
|
||||
/*
|
||||
** The xSavepoint() method.
|
||||
**
|
||||
** Flush the contents of the pending-terms table to disk.
|
||||
*/
|
||||
static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
|
||||
Fts5Table *pTab = (Fts5Table*)pVtab;
|
||||
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
|
||||
fts5CheckTransactionState(pTab, FTS5_SAVEPOINT, iSavepoint);
|
||||
fts5TripCursors(pTab);
|
||||
return sqlite3Fts5StorageSync(pTab->pStorage);
|
||||
fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_SAVEPOINT, iSavepoint);
|
||||
return sqlite3Fts5FlushToDisk((Fts5Table*)pVtab);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2428,11 +2436,9 @@ static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
|
||||
** This is a no-op.
|
||||
*/
|
||||
static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
|
||||
Fts5Table *pTab = (Fts5Table*)pVtab;
|
||||
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
|
||||
fts5CheckTransactionState(pTab, FTS5_RELEASE, iSavepoint);
|
||||
fts5TripCursors(pTab);
|
||||
return sqlite3Fts5StorageSync(pTab->pStorage);
|
||||
fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_RELEASE, iSavepoint);
|
||||
return sqlite3Fts5FlushToDisk((Fts5Table*)pVtab);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2441,7 +2447,7 @@ static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
|
||||
** Discard the contents of the pending terms table.
|
||||
*/
|
||||
static int fts5RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
|
||||
Fts5Table *pTab = (Fts5Table*)pVtab;
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
|
||||
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
|
||||
fts5CheckTransactionState(pTab, FTS5_ROLLBACKTO, iSavepoint);
|
||||
fts5TripCursors(pTab);
|
||||
|
||||
+12
-6
@@ -115,7 +115,7 @@ static int fts5StorageGetStmt(
|
||||
char *zBind;
|
||||
int i;
|
||||
|
||||
zBind = sqlite3_malloc(1 + nCol*2);
|
||||
zBind = sqlite3_malloc64(1 + nCol*2);
|
||||
if( zBind ){
|
||||
for(i=0; i<nCol; i++){
|
||||
zBind[i*2] = '?';
|
||||
@@ -282,14 +282,14 @@ int sqlite3Fts5StorageOpen(
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
Fts5Storage *p; /* New object */
|
||||
int nByte; /* Bytes of space to allocate */
|
||||
sqlite3_int64 nByte; /* Bytes of space to allocate */
|
||||
|
||||
nByte = sizeof(Fts5Storage) /* Fts5Storage object */
|
||||
+ pConfig->nCol * sizeof(i64); /* Fts5Storage.aTotalSize[] */
|
||||
*pp = p = (Fts5Storage*)sqlite3_malloc(nByte);
|
||||
*pp = p = (Fts5Storage*)sqlite3_malloc64(nByte);
|
||||
if( !p ) return SQLITE_NOMEM;
|
||||
|
||||
memset(p, 0, nByte);
|
||||
memset(p, 0, (size_t)nByte);
|
||||
p->aTotalSize = (i64*)&p[1];
|
||||
p->pConfig = pConfig;
|
||||
p->pIndex = pIndex;
|
||||
@@ -297,7 +297,7 @@ int sqlite3Fts5StorageOpen(
|
||||
if( bCreate ){
|
||||
if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
|
||||
int nDefn = 32 + pConfig->nCol*10;
|
||||
char *zDefn = sqlite3_malloc(32 + pConfig->nCol * 10);
|
||||
char *zDefn = sqlite3_malloc64(32 + (sqlite3_int64)pConfig->nCol * 10);
|
||||
if( zDefn==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -878,7 +878,7 @@ int sqlite3Fts5StorageIntegrity(Fts5Storage *p){
|
||||
|
||||
memset(&ctx, 0, sizeof(Fts5IntegrityCtx));
|
||||
ctx.pConfig = p->pConfig;
|
||||
aTotalSize = (i64*)sqlite3_malloc(pConfig->nCol * (sizeof(int)+sizeof(i64)));
|
||||
aTotalSize = (i64*)sqlite3_malloc64(pConfig->nCol*(sizeof(int)+sizeof(i64)));
|
||||
if( !aTotalSize ) return SQLITE_NOMEM;
|
||||
aColSize = (int*)&aTotalSize[pConfig->nCol];
|
||||
memset(aTotalSize, 0, sizeof(i64) * pConfig->nCol);
|
||||
@@ -1078,7 +1078,13 @@ int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnToken){
|
||||
int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow){
|
||||
int rc = fts5StorageLoadTotals(p, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
/* nTotalRow being zero does not necessarily indicate a corrupt
|
||||
** database - it might be that the FTS5 table really does contain zero
|
||||
** rows. However this function is only called from the xRowCount() API,
|
||||
** and there is no way for that API to be invoked if the table contains
|
||||
** no rows. Hence the FTS5_CORRUPT return. */
|
||||
*pnRow = p->nTotalRow;
|
||||
if( p->nTotalRow<=0 ) rc = FTS5_CORRUPT;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ static Fts5MatchinfoCtx *fts5MatchinfoNew(
|
||||
int nPhrase;
|
||||
int i;
|
||||
int nInt;
|
||||
int nByte;
|
||||
sqlite3_int64 nByte;
|
||||
int rc;
|
||||
|
||||
nCol = pApi->xColumnCount(pFts);
|
||||
@@ -330,7 +330,7 @@ static Fts5MatchinfoCtx *fts5MatchinfoNew(
|
||||
nByte = sizeof(Fts5MatchinfoCtx) /* The struct itself */
|
||||
+ sizeof(u32) * nInt /* The p->aRet[] array */
|
||||
+ (i+1); /* The p->zArg string */
|
||||
p = (Fts5MatchinfoCtx*)sqlite3_malloc(nByte);
|
||||
p = (Fts5MatchinfoCtx*)sqlite3_malloc64(nByte);
|
||||
if( p==0 ){
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
return 0;
|
||||
|
||||
@@ -137,7 +137,7 @@ static int fts5tokDequoteArray(
|
||||
nByte += (int)(strlen(argv[i]) + 1);
|
||||
}
|
||||
|
||||
*pazDequote = azDequote = sqlite3_malloc(sizeof(char *)*argc + nByte);
|
||||
*pazDequote = azDequote = sqlite3_malloc64(sizeof(char *)*argc + nByte);
|
||||
if( azDequote==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -335,7 +335,7 @@ static int fts5tokCb(
|
||||
if( (pCsr->nRow & (pCsr->nRow-1))==0 ){
|
||||
int nNew = pCsr->nRow ? pCsr->nRow*2 : 32;
|
||||
Fts5tokRow *aNew;
|
||||
aNew = (Fts5tokRow*)sqlite3_realloc(pCsr->aRow, nNew*sizeof(Fts5tokRow));
|
||||
aNew = (Fts5tokRow*)sqlite3_realloc64(pCsr->aRow, nNew*sizeof(Fts5tokRow));
|
||||
if( aNew==0 ) return SQLITE_NOMEM;
|
||||
memset(&aNew[pCsr->nRow], 0, sizeof(Fts5tokRow)*(nNew-pCsr->nRow));
|
||||
pCsr->aRow = aNew;
|
||||
|
||||
@@ -152,7 +152,7 @@ static int fts5AsciiTokenize(
|
||||
nByte = ie-is;
|
||||
if( nByte>nFold ){
|
||||
if( pFold!=aFold ) sqlite3_free(pFold);
|
||||
pFold = sqlite3_malloc(nByte*2);
|
||||
pFold = sqlite3_malloc64((sqlite3_int64)nByte*2);
|
||||
if( pFold==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
break;
|
||||
@@ -256,7 +256,8 @@ static int fts5UnicodeAddExceptions(
|
||||
int *aNew;
|
||||
|
||||
if( n>0 ){
|
||||
aNew = (int*)sqlite3_realloc(p->aiException, (n+p->nException)*sizeof(int));
|
||||
aNew = (int*)sqlite3_realloc64(p->aiException,
|
||||
(n+p->nException)*sizeof(int));
|
||||
if( aNew ){
|
||||
int nNew = p->nException;
|
||||
const unsigned char *zCsr = (const unsigned char*)z;
|
||||
@@ -490,7 +491,7 @@ static int fts5UnicodeTokenize(
|
||||
/* Grow the output buffer so that there is sufficient space to fit the
|
||||
** largest possible utf-8 character. */
|
||||
if( zOut>pEnd ){
|
||||
aFold = sqlite3_malloc(nFold*2);
|
||||
aFold = sqlite3_malloc64((sqlite3_int64)nFold*2);
|
||||
if( aFold==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto tokenize_done;
|
||||
|
||||
@@ -769,9 +769,8 @@ void sqlite3Fts5UnicodeAscii(u8 *aArray, u8 *aAscii){
|
||||
int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
|
||||
int n = (aFts5UnicodeData[iTbl] >> 5) + i;
|
||||
for(; i<128 && i<n; i++){
|
||||
aAscii[i] = bToken;
|
||||
aAscii[i] = (u8)bToken;
|
||||
}
|
||||
iTbl++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ int sqlite3Fts5GetVarint32(const unsigned char *p, u32 *v){
|
||||
u8 n;
|
||||
p -= 2;
|
||||
n = sqlite3Fts5GetVarint(p, &v64);
|
||||
*v = (u32)v64;
|
||||
*v = ((u32)v64) & 0x7FFFFFFF;
|
||||
assert( n>3 && n<=9 );
|
||||
return n;
|
||||
}
|
||||
@@ -342,4 +342,3 @@ int sqlite3Fts5GetVarintLen(u32 iVal){
|
||||
if( iVal<(1 << 28) ) return 4;
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
||||
+38
-31
@@ -55,7 +55,7 @@ struct Fts5VocabTable {
|
||||
struct Fts5VocabCursor {
|
||||
sqlite3_vtab_cursor base;
|
||||
sqlite3_stmt *pStmt; /* Statement holding lock on pIndex */
|
||||
Fts5Index *pIndex; /* Associated FTS5 index */
|
||||
Fts5Table *pFts5; /* Associated FTS5 table */
|
||||
|
||||
int bEof; /* True if this cursor is at EOF */
|
||||
Fts5IndexIter *pIter; /* Term/rowid iterator object */
|
||||
@@ -64,7 +64,6 @@ struct Fts5VocabCursor {
|
||||
char *zLeTerm; /* (term <= $zLeTerm) paramater, or NULL */
|
||||
|
||||
/* These are used by 'col' tables only */
|
||||
Fts5Config *pConfig; /* Fts5 table configuration */
|
||||
int iCol;
|
||||
i64 *aCnt;
|
||||
i64 *aDoc;
|
||||
@@ -327,8 +326,7 @@ static int fts5VocabOpenMethod(
|
||||
sqlite3_vtab_cursor **ppCsr
|
||||
){
|
||||
Fts5VocabTable *pTab = (Fts5VocabTable*)pVTab;
|
||||
Fts5Index *pIndex = 0;
|
||||
Fts5Config *pConfig = 0;
|
||||
Fts5Table *pFts5 = 0;
|
||||
Fts5VocabCursor *pCsr = 0;
|
||||
int rc = SQLITE_OK;
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
@@ -347,31 +345,34 @@ static int fts5VocabOpenMethod(
|
||||
|
||||
if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
|
||||
i64 iId = sqlite3_column_int64(pStmt, 0);
|
||||
pIndex = sqlite3Fts5IndexFromCsrid(pTab->pGlobal, iId, &pConfig);
|
||||
pFts5 = sqlite3Fts5TableFromCsrid(pTab->pGlobal, iId);
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK && pIndex==0 ){
|
||||
rc = sqlite3_finalize(pStmt);
|
||||
pStmt = 0;
|
||||
if( rc==SQLITE_OK ){
|
||||
pVTab->zErrMsg = sqlite3_mprintf(
|
||||
"no such fts5 table: %s.%s", pTab->zFts5Db, pTab->zFts5Tbl
|
||||
);
|
||||
rc = SQLITE_ERROR;
|
||||
if( rc==SQLITE_OK ){
|
||||
if( pFts5==0 ){
|
||||
rc = sqlite3_finalize(pStmt);
|
||||
pStmt = 0;
|
||||
if( rc==SQLITE_OK ){
|
||||
pVTab->zErrMsg = sqlite3_mprintf(
|
||||
"no such fts5 table: %s.%s", pTab->zFts5Db, pTab->zFts5Tbl
|
||||
);
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
}else{
|
||||
rc = sqlite3Fts5FlushToDisk(pFts5);
|
||||
}
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
int nByte = pConfig->nCol * sizeof(i64) * 2 + sizeof(Fts5VocabCursor);
|
||||
int nByte = pFts5->pConfig->nCol * sizeof(i64)*2 + sizeof(Fts5VocabCursor);
|
||||
pCsr = (Fts5VocabCursor*)sqlite3Fts5MallocZero(&rc, nByte);
|
||||
}
|
||||
|
||||
if( pCsr ){
|
||||
pCsr->pIndex = pIndex;
|
||||
pCsr->pFts5 = pFts5;
|
||||
pCsr->pStmt = pStmt;
|
||||
pCsr->pConfig = pConfig;
|
||||
pCsr->aCnt = (i64*)&pCsr[1];
|
||||
pCsr->aDoc = &pCsr->aCnt[pConfig->nCol];
|
||||
pCsr->aDoc = &pCsr->aCnt[pFts5->pConfig->nCol];
|
||||
}else{
|
||||
sqlite3_finalize(pStmt);
|
||||
}
|
||||
@@ -387,6 +388,7 @@ static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){
|
||||
sqlite3_free(pCsr->zLeTerm);
|
||||
pCsr->nLeTerm = -1;
|
||||
pCsr->zLeTerm = 0;
|
||||
pCsr->bEof = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -425,7 +427,7 @@ static int fts5VocabInstanceNewTerm(Fts5VocabCursor *pCsr){
|
||||
}
|
||||
|
||||
static int fts5VocabInstanceNext(Fts5VocabCursor *pCsr){
|
||||
int eDetail = pCsr->pConfig->eDetail;
|
||||
int eDetail = pCsr->pFts5->pConfig->eDetail;
|
||||
int rc = SQLITE_OK;
|
||||
Fts5IndexIter *pIter = pCsr->pIter;
|
||||
i64 *pp = &pCsr->iInstPos;
|
||||
@@ -460,7 +462,7 @@ static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
|
||||
Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab;
|
||||
int rc = SQLITE_OK;
|
||||
int nCol = pCsr->pConfig->nCol;
|
||||
int nCol = pCsr->pFts5->pConfig->nCol;
|
||||
|
||||
pCsr->rowid++;
|
||||
|
||||
@@ -482,6 +484,7 @@ static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
int nTerm;
|
||||
|
||||
zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
|
||||
assert( nTerm>=0 );
|
||||
if( pCsr->nLeTerm>=0 ){
|
||||
int nCmp = MIN(nTerm, pCsr->nLeTerm);
|
||||
int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp);
|
||||
@@ -498,7 +501,7 @@ static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
|
||||
assert( pTab->eType==FTS5_VOCAB_COL || pTab->eType==FTS5_VOCAB_ROW );
|
||||
while( rc==SQLITE_OK ){
|
||||
int eDetail = pCsr->pConfig->eDetail;
|
||||
int eDetail = pCsr->pFts5->pConfig->eDetail;
|
||||
const u8 *pPos; int nPos; /* Position list */
|
||||
i64 iPos = 0; /* 64-bit position read from poslist */
|
||||
int iOff = 0; /* Current offset within position list */
|
||||
@@ -521,7 +524,6 @@ static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
int iCol = -1;
|
||||
while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
|
||||
int ii = FTS5_POS2COLUMN(iPos);
|
||||
pCsr->aCnt[ii]++;
|
||||
if( iCol!=ii ){
|
||||
if( ii>=nCol ){
|
||||
rc = FTS5_CORRUPT;
|
||||
@@ -530,6 +532,7 @@ static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
pCsr->aDoc[ii]++;
|
||||
iCol = ii;
|
||||
}
|
||||
pCsr->aCnt[ii]++;
|
||||
}
|
||||
}else if( eDetail==FTS5_DETAIL_COLUMNS ){
|
||||
while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff,&iPos) ){
|
||||
@@ -558,7 +561,9 @@ static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
|
||||
if( nTerm!=pCsr->term.n || memcmp(zTerm, pCsr->term.p, nTerm) ){
|
||||
if( nTerm!=pCsr->term.n
|
||||
|| (nTerm>0 && memcmp(zTerm, pCsr->term.p, nTerm))
|
||||
){
|
||||
break;
|
||||
}
|
||||
if( sqlite3Fts5IterEof(pCsr->pIter) ) break;
|
||||
@@ -569,7 +574,7 @@ static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
|
||||
if( rc==SQLITE_OK && pCsr->bEof==0 && pTab->eType==FTS5_VOCAB_COL ){
|
||||
while( pCsr->aDoc[pCsr->iCol]==0 ) pCsr->iCol++;
|
||||
assert( pCsr->iCol<pCsr->pConfig->nCol );
|
||||
assert( pCsr->iCol<pCsr->pFts5->pConfig->nCol );
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -616,6 +621,7 @@ static int fts5VocabFilterMethod(
|
||||
}
|
||||
if( pLe ){
|
||||
const char *zCopy = (const char *)sqlite3_value_text(pLe);
|
||||
if( zCopy==0 ) zCopy = "";
|
||||
pCsr->nLeTerm = sqlite3_value_bytes(pLe);
|
||||
pCsr->zLeTerm = sqlite3_malloc(pCsr->nLeTerm+1);
|
||||
if( pCsr->zLeTerm==0 ){
|
||||
@@ -627,14 +633,15 @@ static int fts5VocabFilterMethod(
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5IndexQuery(pCsr->pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
|
||||
Fts5Index *pIndex = pCsr->pFts5->pIndex;
|
||||
rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
|
||||
}
|
||||
if( rc==SQLITE_OK && eType==FTS5_VOCAB_INSTANCE ){
|
||||
rc = fts5VocabInstanceNewTerm(pCsr);
|
||||
}
|
||||
if( rc==SQLITE_OK
|
||||
&& !pCsr->bEof
|
||||
&& (eType!=FTS5_VOCAB_INSTANCE || pCsr->pConfig->eDetail!=FTS5_DETAIL_NONE)
|
||||
if( rc==SQLITE_OK && !pCsr->bEof
|
||||
&& (eType!=FTS5_VOCAB_INSTANCE
|
||||
|| pCsr->pFts5->pConfig->eDetail!=FTS5_DETAIL_NONE)
|
||||
){
|
||||
rc = fts5VocabNextMethod(pCursor);
|
||||
}
|
||||
@@ -657,7 +664,7 @@ static int fts5VocabColumnMethod(
|
||||
int iCol /* Index of column to read value from */
|
||||
){
|
||||
Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
|
||||
int eDetail = pCsr->pConfig->eDetail;
|
||||
int eDetail = pCsr->pFts5->pConfig->eDetail;
|
||||
int eType = ((Fts5VocabTable*)(pCursor->pVtab))->eType;
|
||||
i64 iVal = 0;
|
||||
|
||||
@@ -669,7 +676,7 @@ static int fts5VocabColumnMethod(
|
||||
assert( iCol==1 || iCol==2 || iCol==3 );
|
||||
if( iCol==1 ){
|
||||
if( eDetail!=FTS5_DETAIL_NONE ){
|
||||
const char *z = pCsr->pConfig->azCol[pCsr->iCol];
|
||||
const char *z = pCsr->pFts5->pConfig->azCol[pCsr->iCol];
|
||||
sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
|
||||
}
|
||||
}else if( iCol==2 ){
|
||||
@@ -697,8 +704,8 @@ static int fts5VocabColumnMethod(
|
||||
}else if( eDetail==FTS5_DETAIL_COLUMNS ){
|
||||
ii = (int)pCsr->iInstPos;
|
||||
}
|
||||
if( ii>=0 && ii<pCsr->pConfig->nCol ){
|
||||
const char *z = pCsr->pConfig->azCol[ii];
|
||||
if( ii>=0 && ii<pCsr->pFts5->pConfig->nCol ){
|
||||
const char *z = pCsr->pFts5->pConfig->azCol[ii];
|
||||
sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -427,7 +427,7 @@ proc funk {} {
|
||||
db eval { UPDATE n1_config SET v=50 WHERE k='version' }
|
||||
set fd [db incrblob main n1_data block 10]
|
||||
fconfigure $fd -encoding binary -translation binary
|
||||
puts -nonewline $fd "\x44\x45"
|
||||
# puts -nonewline $fd "\x44\x45"
|
||||
close $fd
|
||||
}
|
||||
db func funk funk
|
||||
@@ -603,6 +603,38 @@ do_execsql_test 23.2 {
|
||||
SELECT * FROM t11, t10 WHERE t10.rowid IS NULL;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
do_execsql_test 24.0 {
|
||||
CREATE VIRTUAL TABLE t12 USING fts5(x, detail=%DETAIL%);
|
||||
INSERT INTO t12 VALUES('aaaa');
|
||||
}
|
||||
do_execsql_test 24.1 {
|
||||
BEGIN;
|
||||
DELETE FROM t12 WHERE rowid=1;
|
||||
SELECT * FROM t12('aaaa');
|
||||
INSERT INTO t12 VALUES('aaaa');
|
||||
END;
|
||||
}
|
||||
do_execsql_test 24.2 {
|
||||
INSERT INTO t12(t12) VALUES('integrity-check');
|
||||
}
|
||||
do_execsql_test 24.3 {
|
||||
SELECT * FROM t12('aaaa');
|
||||
} {aaaa}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
do_execsql_test 25.0 {
|
||||
CREATE VIRTUAL TABLE t13 USING fts5(x, detail=%DETAIL%);
|
||||
}
|
||||
do_execsql_test 25.1 {
|
||||
BEGIN;
|
||||
INSERT INTO t13 VALUES('AAAA');
|
||||
SELECT * FROM t13('BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB*');
|
||||
|
||||
END;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
expand_all_sql db
|
||||
|
||||
@@ -51,6 +51,12 @@ do_execsql_test 1.1 {
|
||||
do_execsql_test 1.2 {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
SAVEPOINT one;
|
||||
INSERT INTO t1 VALUES('v w x');
|
||||
ROLLBACK TO one;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -144,6 +144,14 @@ do_execsql_test 3.1 {
|
||||
{[a b c d e]}
|
||||
}
|
||||
|
||||
do_execsql_test 3.2 {
|
||||
SELECT highlight(ft, 0, NULL, NULL) FROM ft WHERE ft MATCH 'a+b+c AND c+d+e';
|
||||
} {
|
||||
{a b c x c d e}
|
||||
{a b c c d e}
|
||||
{a b c d e}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -275,6 +275,37 @@ do_execsql_test 9.3 {
|
||||
9 10
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that aux. functions may not be used in aggregate queries.
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 10.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(x, y, z);
|
||||
INSERT INTO t1 VALUES('a', 'one two', 1);
|
||||
INSERT INTO t1 VALUES('b', 'two three', 2);
|
||||
INSERT INTO t1 VALUES('c', 'three four', 1);
|
||||
INSERT INTO t1 VALUES('d', 'four five', 2);
|
||||
INSERT INTO t1 VALUES('e', 'five six', 1);
|
||||
INSERT INTO t1 VALUES('f', 'six seven', 2);
|
||||
}
|
||||
|
||||
proc firstcol {cmd} { $cmd xColumnText 0 }
|
||||
sqlite3_fts5_create_function db firstcol firstcol
|
||||
|
||||
do_execsql_test 10.1.1 {
|
||||
SELECT firstcol(t1) FROM t1
|
||||
} {a b c d e f}
|
||||
do_execsql_test 10.1.2 {
|
||||
SELECT group_concat(x, '.') FROM t1
|
||||
} {a.b.c.d.e.f}
|
||||
|
||||
do_catchsql_test 10.1.3 {
|
||||
SELECT group_concat(firstcol(t1), '.') FROM t1
|
||||
} {1 {unable to use function firstcol in the requested context}}
|
||||
|
||||
do_catchsql_test 10.1.4 {
|
||||
SELECT group_concat(firstcol(t1), '.') FROM t1 GROUP BY rowid
|
||||
} {1 {unable to use function firstcol in the requested context}}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
+5595
-1
File diff suppressed because one or more lines are too long
@@ -115,5 +115,43 @@ do_execsql_test 2.2.integrity {
|
||||
INSERT INTO x2(x2) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE x3 USING fts5(x, detail=%DETAIL%);
|
||||
INSERT INTO x3 VALUES('one');
|
||||
INSERT INTO x3 VALUES('two');
|
||||
INSERT INTO x3 VALUES('one');
|
||||
INSERT INTO x3 VALUES('two');
|
||||
INSERT INTO x3 VALUES('one');
|
||||
}
|
||||
|
||||
do_test 3.1 {
|
||||
db eval { SELECT * FROM x3('one') } {
|
||||
db eval {
|
||||
INSERT INTO x3(x3) VALUES('optimize');
|
||||
}
|
||||
}
|
||||
} {}
|
||||
|
||||
do_execsql_test 4.0 {
|
||||
CREATE VIRTUAL TABLE x4 USING fts5(a, detail=%DETAIL%);
|
||||
INSERT INTO x4 VALUES('one two three');
|
||||
INSERT INTO x4(rowid, a) VALUES('2', 'one two three');
|
||||
INSERT INTO x4(rowid, a) VALUES('3.0', 'one two three');
|
||||
}
|
||||
do_catchsql_test 4.1 {
|
||||
INSERT INTO x4(rowid, a) VALUES('four', 'one two three');
|
||||
} {1 {datatype mismatch}}
|
||||
|
||||
do_catchsql_test 4.2 {
|
||||
UPDATE x4 SET rowid = 'four' WHERE rowid=1;
|
||||
} {1 {datatype mismatch}}
|
||||
|
||||
|
||||
}
|
||||
|
||||
reset_db
|
||||
do_catchsql_test 4.0 { CREATE VIRTUAL TABLE t1 USING fts5(a,b,c); } {0 {}}
|
||||
do_catchsql_test 4.1 { DELETE FROM t1 WHERE t1 MATCH 'f*'; } {0 {}}
|
||||
finish_test
|
||||
|
||||
@@ -479,6 +479,68 @@ do_test 9.6 {
|
||||
expr [lsearch $e2 SorterSort]<0
|
||||
} 0
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
do_execsql_test 10.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(a, b, c);
|
||||
CREATE VIRTUAL TABLE t2 USING fts5vocab('ft','row');
|
||||
CREATE VIRTUAL TABLE t3 USING fts5vocab('ft','row');
|
||||
}
|
||||
|
||||
do_execsql_test 10.1 {
|
||||
BEGIN;
|
||||
INSERT INTO ft(b) VALUES('x y');
|
||||
}
|
||||
|
||||
do_execsql_test 10.2 {
|
||||
SELECT t2.term FROM t2;
|
||||
} {x y}
|
||||
|
||||
do_execsql_test 10.3 {
|
||||
SELECT t2.term, t3.term FROM t2, t3;
|
||||
} {x x x y y x y y}
|
||||
|
||||
do_execsql_test 10.4 {
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
do_execsql_test 10.5 {
|
||||
BEGIN;
|
||||
INSERT INTO ft(a) VALUES('1 2 3');
|
||||
INSERT INTO ft(a) VALUES('4 5 6');
|
||||
INSERT INTO ft(a) VALUES('1 2 3');
|
||||
INSERT INTO ft(a) VALUES('4 5 6');
|
||||
INSERT INTO ft(a) VALUES('1 2 3');
|
||||
INSERT INTO ft(a) VALUES('4 5 6');
|
||||
}
|
||||
|
||||
do_test 10.6 {
|
||||
set res [list]
|
||||
db eval { SELECT rowid FROM ft('4') } x {
|
||||
db eval { SELECT * FROM t2 }
|
||||
lappend res $x(rowid)
|
||||
}
|
||||
db eval COMMIT
|
||||
set res
|
||||
} {3 5 7}
|
||||
|
||||
do_execsql_test 10.6.1 {
|
||||
SELECT * FROM t2 WHERE term<NULL;
|
||||
}
|
||||
do_execsql_test 10.6.2 {
|
||||
SELECT * FROM t2 WHERE term>NULL;
|
||||
}
|
||||
do_execsql_test 10.6.3 {
|
||||
SELECT * FROM t2 WHERE term=NULL;
|
||||
}
|
||||
do_execsql_test 10.7.1 {
|
||||
SELECT * FROM t2 WHERE term<?;
|
||||
}
|
||||
do_execsql_test 10.7.2 {
|
||||
SELECT * FROM t2 WHERE term>?;
|
||||
}
|
||||
do_execsql_test 10.7.3 {
|
||||
SELECT * FROM t2 WHERE term=?;
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -202,4 +202,36 @@ do_execsql_test 3.5 {
|
||||
SELECT * FROM v1;
|
||||
} {}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 4.0 {
|
||||
CREATE VIRTUAL TABLE v1 USING fts5vocab(nosuchtable, col);
|
||||
}
|
||||
|
||||
do_catchsql_test 4.1 {
|
||||
SELECT * FROM v1 WHERE term=='nosuchterm';
|
||||
} {1 {no such fts5 table: main.nosuchtable}}
|
||||
|
||||
do_execsql_test 4.2.1 {
|
||||
CREATE TABLE nosuchtable(nosuchtable, y, z);
|
||||
}
|
||||
do_catchsql_test 4.2.2 {
|
||||
SELECT * FROM v1 WHERE term=='nosuchterm';
|
||||
} {1 {no such fts5 table: main.nosuchtable}}
|
||||
|
||||
ifcapable fts3 {
|
||||
do_execsql_test 4.3.1 {
|
||||
DROP TABLE nosuchtable;
|
||||
CREATE VIRTUAL TABLE nosuchtable USING fts3(a, b);
|
||||
} {}
|
||||
do_catchsql_test 4.3.2 {
|
||||
SELECT * FROM v1 WHERE term=='nosuchterm';
|
||||
} {1 {no such fts5 table: main.nosuchtable}}
|
||||
do_catchsql_test 4.3.3 {
|
||||
INSERT INTO nosuchtable VALUES('id', '*id');
|
||||
SELECT * FROM v1 WHERE term=='nosuchterm';
|
||||
} {1 {no such fts5 table: main.nosuchtable}}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
+6
-6
@@ -619,7 +619,7 @@ static int amatchLoadOneRule(
|
||||
if( p->rDel==0 || p->rDel>rCost ) p->rDel = rCost;
|
||||
}else
|
||||
{
|
||||
pRule = sqlite3_malloc( sizeof(*pRule) + nFrom + nTo );
|
||||
pRule = sqlite3_malloc64( sizeof(*pRule) + nFrom + nTo );
|
||||
if( pRule==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -738,16 +738,16 @@ static int amatchLoadRules(
|
||||
** `mno` becomes mno
|
||||
*/
|
||||
static char *amatchDequote(const char *zIn){
|
||||
int nIn; /* Size of input string, in bytes */
|
||||
sqlite3_int64 nIn; /* Size of input string, in bytes */
|
||||
char *zOut; /* Output (dequoted) string */
|
||||
|
||||
nIn = (int)strlen(zIn);
|
||||
zOut = sqlite3_malloc(nIn+1);
|
||||
nIn = strlen(zIn);
|
||||
zOut = sqlite3_malloc64(nIn+1);
|
||||
if( zOut ){
|
||||
char q = zIn[0]; /* Quote character (if any ) */
|
||||
|
||||
if( q!='[' && q!= '\'' && q!='"' && q!='`' ){
|
||||
memcpy(zOut, zIn, nIn+1);
|
||||
memcpy(zOut, zIn, (size_t)(nIn+1));
|
||||
}else{
|
||||
int iOut = 0; /* Index of next byte to write to output */
|
||||
int iIn; /* Index of next byte to read from input */
|
||||
@@ -1069,7 +1069,7 @@ static void amatchAddWord(
|
||||
}
|
||||
return;
|
||||
}
|
||||
pWord = sqlite3_malloc( sizeof(*pWord) + nBase + nTail - 1 );
|
||||
pWord = sqlite3_malloc64( sizeof(*pWord) + nBase + nTail - 1 );
|
||||
if( pWord==0 ) return;
|
||||
memset(pWord, 0, sizeof(*pWord));
|
||||
pWord->rCost = rCost;
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
** 2019-03-30
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** An SQL function that uses the incremental BLOB I/O mechanism of SQLite
|
||||
** to read or write part of a blob. This is intended for debugging use
|
||||
** in the CLI.
|
||||
**
|
||||
** readblob(SCHEMA,TABLE,COLUMN,ROWID,OFFSET,N)
|
||||
**
|
||||
** Returns N bytes of the blob starting at OFFSET.
|
||||
**
|
||||
** writeblob(SCHEMA,TABLE,COLUMN,ROWID,OFFSET,NEWDATA)
|
||||
**
|
||||
** NEWDATA must be a blob. The content of NEWDATA overwrites the
|
||||
** existing BLOB data at SCHEMA.TABLE.COLUMN for row ROWID beginning
|
||||
** at OFFSET bytes into the blob.
|
||||
*/
|
||||
#include "sqlite3ext.h"
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
static void readblobFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_blob *pBlob = 0;
|
||||
const char *zSchema;
|
||||
const char *zTable;
|
||||
const char *zColumn;
|
||||
sqlite3_int64 iRowid;
|
||||
int iOfst;
|
||||
unsigned char *aData;
|
||||
int nData;
|
||||
sqlite3 *db;
|
||||
int rc;
|
||||
|
||||
zSchema = (const char*)sqlite3_value_text(argv[0]);
|
||||
zTable = (const char*)sqlite3_value_text(argv[1]);
|
||||
if( zTable==0 ){
|
||||
sqlite3_result_error(context, "bad table name", -1);
|
||||
return;
|
||||
}
|
||||
zColumn = (const char*)sqlite3_value_text(argv[2]);
|
||||
if( zTable==0 ){
|
||||
sqlite3_result_error(context, "bad column name", -1);
|
||||
return;
|
||||
}
|
||||
iRowid = sqlite3_value_int64(argv[3]);
|
||||
iOfst = sqlite3_value_int(argv[4]);
|
||||
nData = sqlite3_value_int(argv[5]);
|
||||
if( nData<=0 ) return;
|
||||
aData = sqlite3_malloc64( nData+1 );
|
||||
if( aData==0 ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
return;
|
||||
}
|
||||
db = sqlite3_context_db_handle(context);
|
||||
rc = sqlite3_blob_open(db, zSchema, zTable, zColumn, iRowid, 0, &pBlob);
|
||||
if( rc ){
|
||||
sqlite3_free(aData);
|
||||
sqlite3_result_error(context, "cannot open BLOB pointer", -1);
|
||||
return;
|
||||
}
|
||||
rc = sqlite3_blob_read(pBlob, aData, nData, iOfst);
|
||||
sqlite3_blob_close(pBlob);
|
||||
if( rc ){
|
||||
sqlite3_free(aData);
|
||||
sqlite3_result_error(context, "BLOB write failed", -1);
|
||||
}else{
|
||||
sqlite3_result_blob(context, aData, nData, sqlite3_free);
|
||||
}
|
||||
}
|
||||
|
||||
static void writeblobFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_blob *pBlob = 0;
|
||||
const char *zSchema;
|
||||
const char *zTable;
|
||||
const char *zColumn;
|
||||
sqlite3_int64 iRowid;
|
||||
int iOfst;
|
||||
unsigned char *aData;
|
||||
int nData;
|
||||
sqlite3 *db;
|
||||
int rc;
|
||||
|
||||
zSchema = (const char*)sqlite3_value_text(argv[0]);
|
||||
zTable = (const char*)sqlite3_value_text(argv[1]);
|
||||
if( zTable==0 ){
|
||||
sqlite3_result_error(context, "bad table name", -1);
|
||||
return;
|
||||
}
|
||||
zColumn = (const char*)sqlite3_value_text(argv[2]);
|
||||
if( zTable==0 ){
|
||||
sqlite3_result_error(context, "bad column name", -1);
|
||||
return;
|
||||
}
|
||||
iRowid = sqlite3_value_int64(argv[3]);
|
||||
iOfst = sqlite3_value_int(argv[4]);
|
||||
if( sqlite3_value_type(argv[5])!=SQLITE_BLOB ){
|
||||
sqlite3_result_error(context, "6th argument must be a BLOB", -1);
|
||||
return;
|
||||
}
|
||||
nData = sqlite3_value_bytes(argv[5]);
|
||||
aData = (unsigned char *)sqlite3_value_blob(argv[5]);
|
||||
db = sqlite3_context_db_handle(context);
|
||||
rc = sqlite3_blob_open(db, zSchema, zTable, zColumn, iRowid, 1, &pBlob);
|
||||
if( rc ){
|
||||
sqlite3_result_error(context, "cannot open BLOB pointer", -1);
|
||||
return;
|
||||
}
|
||||
rc = sqlite3_blob_write(pBlob, aData, nData, iOfst);
|
||||
sqlite3_blob_close(pBlob);
|
||||
if( rc ){
|
||||
sqlite3_result_error(context, "BLOB write failed", -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_blobio_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg; /* Unused parameter */
|
||||
rc = sqlite3_create_function(db, "readblob", 6, SQLITE_UTF8, 0,
|
||||
readblobFunc, 0, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_create_function(db, "writeblob", 6, SQLITE_UTF8, 0,
|
||||
writeblobFunc, 0, 0);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
+4
-4
@@ -422,16 +422,16 @@ static closure_avl *queuePull(closure_queue *pQueue){
|
||||
** `mno` becomes mno
|
||||
*/
|
||||
static char *closureDequote(const char *zIn){
|
||||
int nIn; /* Size of input string, in bytes */
|
||||
sqlite3_int64 nIn; /* Size of input string, in bytes */
|
||||
char *zOut; /* Output (dequoted) string */
|
||||
|
||||
nIn = (int)strlen(zIn);
|
||||
zOut = sqlite3_malloc(nIn+1);
|
||||
nIn = strlen(zIn);
|
||||
zOut = sqlite3_malloc64(nIn+1);
|
||||
if( zOut ){
|
||||
char q = zIn[0]; /* Quote character (if any ) */
|
||||
|
||||
if( q!='[' && q!= '\'' && q!='"' && q!='`' ){
|
||||
memcpy(zOut, zIn, nIn+1);
|
||||
memcpy(zOut, zIn, (size_t)(nIn+1));
|
||||
}else{
|
||||
int iOut = 0; /* Index of next byte to write to output */
|
||||
int iIn; /* Index of next byte to read from input */
|
||||
|
||||
+1
-1
@@ -195,7 +195,7 @@ static char **tableColumnList(DState *p, const char *zTab){
|
||||
if( nCol>=nAlloc-2 ){
|
||||
char **azNew;
|
||||
nAlloc = nAlloc*2 + nCol + 10;
|
||||
azNew = sqlite3_realloc(azCol, nAlloc*sizeof(azCol[0]));
|
||||
azNew = sqlite3_realloc64(azCol, nAlloc*sizeof(azCol[0]));
|
||||
if( azNew==0 ) goto col_oom;
|
||||
azCol = azNew;
|
||||
azCol[0] = 0;
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ static int callback(void *pCtx, int argc, char **argv, char **colnames){
|
||||
/* Using sqlite3_realloc64() would be better, but it is a recent
|
||||
** addition and will cause a segfault if loaded by an older version
|
||||
** of SQLite. */
|
||||
zNew = p->nAlloc<=0x7fffffff ? sqlite3_realloc(p->z, (int)p->nAlloc) : 0;
|
||||
zNew = p->nAlloc<=0x7fffffff ? sqlite3_realloc64(p->z, p->nAlloc) : 0;
|
||||
if( zNew==0 ){
|
||||
sqlite3_free(p->z);
|
||||
memset(p, 0, sizeof(*p));
|
||||
|
||||
+40
-15
@@ -121,22 +121,47 @@ SQLITE_EXTENSION_INIT1
|
||||
|
||||
/*
|
||||
** Set the result stored by context ctx to a blob containing the
|
||||
** contents of file zName.
|
||||
** contents of file zName. Or, leave the result unchanged (NULL)
|
||||
** if the file does not exist or is unreadable.
|
||||
**
|
||||
** If the file exceeds the SQLite blob size limit, through an
|
||||
** SQLITE_TOOBIG error.
|
||||
**
|
||||
** Throw an SQLITE_IOERR if there are difficulties pulling the file
|
||||
** off of disk.
|
||||
*/
|
||||
static void readFileContents(sqlite3_context *ctx, const char *zName){
|
||||
FILE *in;
|
||||
long nIn;
|
||||
sqlite3_int64 nIn;
|
||||
void *pBuf;
|
||||
sqlite3 *db;
|
||||
int mxBlob;
|
||||
|
||||
in = fopen(zName, "rb");
|
||||
if( in==0 ) return;
|
||||
if( in==0 ){
|
||||
/* File does not exist or is unreadable. Leave the result set to NULL. */
|
||||
return;
|
||||
}
|
||||
fseek(in, 0, SEEK_END);
|
||||
nIn = ftell(in);
|
||||
rewind(in);
|
||||
pBuf = sqlite3_malloc( nIn );
|
||||
if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
|
||||
sqlite3_result_blob(ctx, pBuf, nIn, sqlite3_free);
|
||||
db = sqlite3_context_db_handle(ctx);
|
||||
mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
|
||||
if( nIn>mxBlob ){
|
||||
sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
|
||||
fclose(in);
|
||||
return;
|
||||
}
|
||||
pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
|
||||
if( pBuf==0 ){
|
||||
sqlite3_result_error_nomem(ctx);
|
||||
fclose(in);
|
||||
return;
|
||||
}
|
||||
if( nIn==(sqlite3_int64)fread(pBuf, 1, (size_t)nIn, in) ){
|
||||
sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
|
||||
}else{
|
||||
sqlite3_result_error_code(ctx, SQLITE_IOERR);
|
||||
sqlite3_free(pBuf);
|
||||
}
|
||||
fclose(in);
|
||||
@@ -268,15 +293,15 @@ static int fileLinkStat(
|
||||
** Argument zFile is the name of a file that will be created and/or written
|
||||
** by SQL function writefile(). This function ensures that the directory
|
||||
** zFile will be written to exists, creating it if required. The permissions
|
||||
** for any path components created by this function are set to (mode&0777).
|
||||
** for any path components created by this function are set in accordance
|
||||
** with the current umask.
|
||||
**
|
||||
** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
|
||||
** SQLITE_OK is returned if the directory is successfully created, or
|
||||
** SQLITE_ERROR otherwise.
|
||||
*/
|
||||
static int makeDirectory(
|
||||
const char *zFile,
|
||||
mode_t mode
|
||||
const char *zFile
|
||||
){
|
||||
char *zCopy = sqlite3_mprintf("%s", zFile);
|
||||
int rc = SQLITE_OK;
|
||||
@@ -297,7 +322,7 @@ static int makeDirectory(
|
||||
|
||||
rc2 = fileStat(zCopy, &sStat);
|
||||
if( rc2!=0 ){
|
||||
if( mkdir(zCopy, mode & 0777) ) rc = SQLITE_ERROR;
|
||||
if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
|
||||
}else{
|
||||
if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
|
||||
}
|
||||
@@ -455,7 +480,7 @@ static void writefileFunc(
|
||||
|
||||
res = writeFile(context, zFile, argv[1], mode, mtime);
|
||||
if( res==1 && errno==ENOENT ){
|
||||
if( makeDirectory(zFile, mode)==SQLITE_OK ){
|
||||
if( makeDirectory(zFile)==SQLITE_OK ){
|
||||
res = writeFile(context, zFile, argv[1], mode, mtime);
|
||||
}
|
||||
}
|
||||
@@ -646,8 +671,8 @@ static int fsdirNext(sqlite3_vtab_cursor *cur){
|
||||
FsdirLevel *pLvl;
|
||||
if( iNew>=pCur->nLvl ){
|
||||
int nNew = iNew+1;
|
||||
int nByte = nNew*sizeof(FsdirLevel);
|
||||
FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc(pCur->aLvl, nByte);
|
||||
sqlite3_int64 nByte = nNew*sizeof(FsdirLevel);
|
||||
FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc64(pCur->aLvl, nByte);
|
||||
if( aNew==0 ) return SQLITE_NOMEM;
|
||||
memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl));
|
||||
pCur->aLvl = aNew;
|
||||
@@ -727,7 +752,7 @@ static int fsdirColumn(
|
||||
}else if( S_ISLNK(m) ){
|
||||
char aStatic[64];
|
||||
char *aBuf = aStatic;
|
||||
int nBuf = 64;
|
||||
sqlite3_int64 nBuf = 64;
|
||||
int n;
|
||||
|
||||
while( 1 ){
|
||||
@@ -735,7 +760,7 @@ static int fsdirColumn(
|
||||
if( n<nBuf ) break;
|
||||
if( aBuf!=aStatic ) sqlite3_free(aBuf);
|
||||
nBuf = nBuf*2;
|
||||
aBuf = sqlite3_malloc(nBuf);
|
||||
aBuf = sqlite3_malloc64(nBuf);
|
||||
if( aBuf==0 ){
|
||||
sqlite3_result_error_nomem(ctx);
|
||||
return SQLITE_NOMEM;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+10
-10
@@ -337,7 +337,7 @@ static int fuzzerLoadOneRule(
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
|
||||
pRule = sqlite3_malloc( sizeof(*pRule) + nFrom + nTo );
|
||||
pRule = sqlite3_malloc64( sizeof(*pRule) + nFrom + nTo );
|
||||
if( pRule==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -447,16 +447,16 @@ static int fuzzerLoadRules(
|
||||
** `mno` becomes mno
|
||||
*/
|
||||
static char *fuzzerDequote(const char *zIn){
|
||||
int nIn; /* Size of input string, in bytes */
|
||||
sqlite3_int64 nIn; /* Size of input string, in bytes */
|
||||
char *zOut; /* Output (dequoted) string */
|
||||
|
||||
nIn = (int)strlen(zIn);
|
||||
zOut = sqlite3_malloc(nIn+1);
|
||||
nIn = strlen(zIn);
|
||||
zOut = sqlite3_malloc64(nIn+1);
|
||||
if( zOut ){
|
||||
char q = zIn[0]; /* Quote character (if any ) */
|
||||
|
||||
if( q!='[' && q!= '\'' && q!='"' && q!='`' ){
|
||||
memcpy(zOut, zIn, nIn+1);
|
||||
memcpy(zOut, zIn, (size_t)(nIn+1));
|
||||
}else{
|
||||
int iOut = 0; /* Index of next byte to write to output */
|
||||
int iIn; /* Index of next byte to read from input */
|
||||
@@ -513,10 +513,10 @@ static int fuzzerConnect(
|
||||
);
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
int nModule; /* Length of zModule, in bytes */
|
||||
sqlite3_int64 nModule; /* Length of zModule, in bytes */
|
||||
|
||||
nModule = (int)strlen(zModule);
|
||||
pNew = sqlite3_malloc( sizeof(*pNew) + nModule + 1);
|
||||
nModule = strlen(zModule);
|
||||
pNew = sqlite3_malloc64( sizeof(*pNew) + nModule + 1);
|
||||
if( pNew==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -524,7 +524,7 @@ static int fuzzerConnect(
|
||||
|
||||
memset(pNew, 0, sizeof(*pNew));
|
||||
pNew->zClassName = (char*)&pNew[1];
|
||||
memcpy(pNew->zClassName, zModule, nModule+1);
|
||||
memcpy(pNew->zClassName, zModule, (size_t)(nModule+1));
|
||||
|
||||
zTab = fuzzerDequote(argv[3]);
|
||||
if( zTab==0 ){
|
||||
@@ -872,7 +872,7 @@ static fuzzer_stem *fuzzerNewStem(
|
||||
fuzzer_rule *pRule;
|
||||
unsigned int h;
|
||||
|
||||
pNew = sqlite3_malloc( sizeof(*pNew) + (int)strlen(zWord) + 1 );
|
||||
pNew = sqlite3_malloc64( sizeof(*pNew) + strlen(zWord) + 1 );
|
||||
if( pNew==0 ) return 0;
|
||||
memset(pNew, 0, sizeof(*pNew));
|
||||
pNew->zBasis = (char*)&pNew[1];
|
||||
|
||||
+3
-3
@@ -691,7 +691,7 @@ static JSON_NOINLINE int jsonParseAddNodeExpand(
|
||||
assert( pParse->nNode>=pParse->nAlloc );
|
||||
if( pParse->oom ) return -1;
|
||||
nNew = pParse->nAlloc*2 + 10;
|
||||
pNew = sqlite3_realloc(pParse->aNode, sizeof(JsonNode)*nNew);
|
||||
pNew = sqlite3_realloc64(pParse->aNode, sizeof(JsonNode)*nNew);
|
||||
if( pNew==0 ){
|
||||
pParse->oom = 1;
|
||||
return -1;
|
||||
@@ -965,7 +965,7 @@ static void jsonParseFillInParentage(JsonParse *pParse, u32 i, u32 iParent){
|
||||
static int jsonParseFindParents(JsonParse *pParse){
|
||||
u32 *aUp;
|
||||
assert( pParse->aUp==0 );
|
||||
aUp = pParse->aUp = sqlite3_malloc( sizeof(u32)*pParse->nNode );
|
||||
aUp = pParse->aUp = sqlite3_malloc64( sizeof(u32)*pParse->nNode );
|
||||
if( aUp==0 ){
|
||||
pParse->oom = 1;
|
||||
return SQLITE_NOMEM;
|
||||
@@ -1027,7 +1027,7 @@ static JsonParse *jsonParseCached(
|
||||
pMatch->iHold = iMaxHold+1;
|
||||
return pMatch;
|
||||
}
|
||||
p = sqlite3_malloc( sizeof(*p) + nJson + 1 );
|
||||
p = sqlite3_malloc64( sizeof(*p) + nJson + 1 );
|
||||
if( p==0 ){
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
return 0;
|
||||
|
||||
+1
-1
@@ -143,7 +143,7 @@ static int memstatFindSchemas(memstat_cursor *pCur){
|
||||
}
|
||||
while( sqlite3_step(pStmt)==SQLITE_ROW ){
|
||||
char **az, *z;
|
||||
az = sqlite3_realloc(pCur->azDb, sizeof(char*)*(pCur->nDb+1));
|
||||
az = sqlite3_realloc64(pCur->azDb, sizeof(char*)*(pCur->nDb+1));
|
||||
if( az==0 ){
|
||||
memstatClearSchema(pCur);
|
||||
return SQLITE_NOMEM;
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
** 2019-01-21
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** This file implements an extension that uses the SQLITE_CONFIG_MALLOC
|
||||
** mechanism to add a tracing layer on top of SQLite. If this extension
|
||||
** is registered prior to sqlite3_initialize(), it will cause all memory
|
||||
** allocation activities to be logged on standard output, or to some other
|
||||
** FILE specified by the initializer.
|
||||
**
|
||||
** This file needs to be compiled into the application that uses it.
|
||||
**
|
||||
** This extension is used to implement the --memtrace option of the
|
||||
** command-line shell.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* The original memory allocation routines */
|
||||
static sqlite3_mem_methods memtraceBase;
|
||||
static FILE *memtraceOut;
|
||||
|
||||
/* Methods that trace memory allocations */
|
||||
static void *memtraceMalloc(int n){
|
||||
if( memtraceOut ){
|
||||
fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n",
|
||||
memtraceBase.xRoundup(n));
|
||||
}
|
||||
return memtraceBase.xMalloc(n);
|
||||
}
|
||||
static void memtraceFree(void *p){
|
||||
if( p==0 ) return;
|
||||
if( memtraceOut ){
|
||||
fprintf(memtraceOut, "MEMTRACE: free %d bytes\n", memtraceBase.xSize(p));
|
||||
}
|
||||
memtraceBase.xFree(p);
|
||||
}
|
||||
static void *memtraceRealloc(void *p, int n){
|
||||
if( p==0 ) return memtraceMalloc(n);
|
||||
if( n==0 ){
|
||||
memtraceFree(p);
|
||||
return 0;
|
||||
}
|
||||
if( memtraceOut ){
|
||||
fprintf(memtraceOut, "MEMTRACE: resize %d -> %d bytes\n",
|
||||
memtraceBase.xSize(p), memtraceBase.xRoundup(n));
|
||||
}
|
||||
return memtraceBase.xRealloc(p, n);
|
||||
}
|
||||
static int memtraceSize(void *p){
|
||||
return memtraceBase.xSize(p);
|
||||
}
|
||||
static int memtraceRoundup(int n){
|
||||
return memtraceBase.xRoundup(n);
|
||||
}
|
||||
static int memtraceInit(void *p){
|
||||
return memtraceBase.xInit(p);
|
||||
}
|
||||
static void memtraceShutdown(void *p){
|
||||
memtraceBase.xShutdown(p);
|
||||
}
|
||||
|
||||
/* The substitute memory allocator */
|
||||
static sqlite3_mem_methods ersaztMethods = {
|
||||
memtraceMalloc,
|
||||
memtraceFree,
|
||||
memtraceRealloc,
|
||||
memtraceSize,
|
||||
memtraceRoundup,
|
||||
memtraceInit,
|
||||
memtraceShutdown,
|
||||
0
|
||||
};
|
||||
|
||||
/* Begin tracing memory allocations to out. */
|
||||
int sqlite3MemTraceActivate(FILE *out){
|
||||
int rc = SQLITE_OK;
|
||||
if( memtraceBase.xMalloc==0 ){
|
||||
rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memtraceBase);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &ersaztMethods);
|
||||
}
|
||||
}
|
||||
memtraceOut = out;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Deactivate memory tracing */
|
||||
int sqlite3MemTraceDeactivate(void){
|
||||
int rc = SQLITE_OK;
|
||||
if( memtraceBase.xMalloc!=0 ){
|
||||
rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memtraceBase);
|
||||
if( rc==SQLITE_OK ){
|
||||
memset(&memtraceBase, 0, sizeof(memtraceBase));
|
||||
}
|
||||
}
|
||||
memtraceOut = 0;
|
||||
return rc;
|
||||
}
|
||||
@@ -105,4 +105,3 @@ int sqlite3_mmap_warm(sqlite3 *db, const char *zDb){
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -85,7 +85,7 @@ static void nextCharAppend(nextCharContext *p, unsigned c){
|
||||
if( p->nUsed+1 > p->nAlloc ){
|
||||
unsigned int *aNew;
|
||||
int n = p->nAlloc*2 + 30;
|
||||
aNew = sqlite3_realloc(p->aResult, n*sizeof(unsigned int));
|
||||
aNew = sqlite3_realloc64(p->aResult, n*sizeof(unsigned int));
|
||||
if( aNew==0 ){
|
||||
p->mallocFailed = 1;
|
||||
return;
|
||||
@@ -269,7 +269,7 @@ static void nextCharFunc(
|
||||
sqlite3_result_error_nomem(context);
|
||||
}else{
|
||||
unsigned char *pRes;
|
||||
pRes = sqlite3_malloc( c.nUsed*4 + 1 );
|
||||
pRes = sqlite3_malloc64( c.nUsed*4 + 1 );
|
||||
if( pRes==0 ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
}else{
|
||||
|
||||
@@ -108,8 +108,8 @@ static void percentStep(sqlite3_context *pCtx, int argc, sqlite3_value **argv){
|
||||
/* Requirement 3: P must be a number between 0 and 100 */
|
||||
eType = sqlite3_value_numeric_type(argv[1]);
|
||||
rPct = sqlite3_value_double(argv[1]);
|
||||
if( (eType!=SQLITE_INTEGER && eType!=SQLITE_FLOAT) ||
|
||||
((rPct = sqlite3_value_double(argv[1]))<0.0 || rPct>100.0) ){
|
||||
if( (eType!=SQLITE_INTEGER && eType!=SQLITE_FLOAT)
|
||||
|| rPct<0.0 || rPct>100.0 ){
|
||||
sqlite3_result_error(pCtx, "2nd argument to percentile() is not "
|
||||
"a number between 0.0 and 100.0", -1);
|
||||
return;
|
||||
@@ -151,7 +151,7 @@ static void percentStep(sqlite3_context *pCtx, int argc, sqlite3_value **argv){
|
||||
/* Allocate and store the Y */
|
||||
if( p->nUsed>=p->nAlloc ){
|
||||
unsigned n = p->nAlloc*2 + 250;
|
||||
double *a = sqlite3_realloc(p->a, sizeof(double)*n);
|
||||
double *a = sqlite3_realloc64(p->a, sizeof(double)*n);
|
||||
if( a==0 ){
|
||||
sqlite3_free(p->a);
|
||||
memset(p, 0, sizeof(*p));
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
** 2018-04-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 table-valued function:
|
||||
**
|
||||
** prefixes('abcdefg')
|
||||
**
|
||||
** The function has a single (non-HIDDEN) column named prefix that takes
|
||||
** on all prefixes of the string in its argument, including an empty string
|
||||
** and the input string itself. The order of prefixes is from longest
|
||||
** to shortest.
|
||||
*/
|
||||
#if !defined(SQLITE_CORE) || !defined(SQLITE_OMIT_VIRTUALTABLE)
|
||||
#if !defined(SQLITEINT_H)
|
||||
#include "sqlite3ext.h"
|
||||
#endif
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
/* prefixes_vtab is a subclass of sqlite3_vtab which is
|
||||
** underlying representation of the virtual table
|
||||
*/
|
||||
typedef struct prefixes_vtab prefixes_vtab;
|
||||
struct prefixes_vtab {
|
||||
sqlite3_vtab base; /* Base class - must be first */
|
||||
/* No additional fields are necessary */
|
||||
};
|
||||
|
||||
/* prefixes_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 prefixes_cursor prefixes_cursor;
|
||||
struct prefixes_cursor {
|
||||
sqlite3_vtab_cursor base; /* Base class - must be first */
|
||||
sqlite3_int64 iRowid; /* The rowid */
|
||||
char *zStr; /* Original string to be prefixed */
|
||||
int nStr; /* Length of the string in bytes */
|
||||
};
|
||||
|
||||
/*
|
||||
** The prefixesConnect() method is invoked to create a new
|
||||
** template virtual table.
|
||||
**
|
||||
** Think of this routine as the constructor for prefixes_vtab objects.
|
||||
**
|
||||
** All this routine needs to do is:
|
||||
**
|
||||
** (1) Allocate the prefixes_vtab object and initialize all fields.
|
||||
**
|
||||
** (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the
|
||||
** result set of queries against the virtual table will look like.
|
||||
*/
|
||||
static int prefixesConnect(
|
||||
sqlite3 *db,
|
||||
void *pAux,
|
||||
int argc, const char *const*argv,
|
||||
sqlite3_vtab **ppVtab,
|
||||
char **pzErr
|
||||
){
|
||||
prefixes_vtab *pNew;
|
||||
int rc;
|
||||
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
"CREATE TABLE prefixes(prefix TEXT, original_string TEXT HIDDEN)"
|
||||
);
|
||||
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 prefixes_vtab objects.
|
||||
*/
|
||||
static int prefixesDisconnect(sqlite3_vtab *pVtab){
|
||||
prefixes_vtab *p = (prefixes_vtab*)pVtab;
|
||||
sqlite3_free(p);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Constructor for a new prefixes_cursor object.
|
||||
*/
|
||||
static int prefixesOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
|
||||
prefixes_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 prefixes_cursor.
|
||||
*/
|
||||
static int prefixesClose(sqlite3_vtab_cursor *cur){
|
||||
prefixes_cursor *pCur = (prefixes_cursor*)cur;
|
||||
sqlite3_free(pCur->zStr);
|
||||
sqlite3_free(pCur);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Advance a prefixes_cursor to its next row of output.
|
||||
*/
|
||||
static int prefixesNext(sqlite3_vtab_cursor *cur){
|
||||
prefixes_cursor *pCur = (prefixes_cursor*)cur;
|
||||
pCur->iRowid++;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return values of columns for the row at which the prefixes_cursor
|
||||
** is currently pointing.
|
||||
*/
|
||||
static int prefixesColumn(
|
||||
sqlite3_vtab_cursor *cur, /* The cursor */
|
||||
sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
|
||||
int i /* Which column to return */
|
||||
){
|
||||
prefixes_cursor *pCur = (prefixes_cursor*)cur;
|
||||
switch( i ){
|
||||
case 0:
|
||||
sqlite3_result_text(ctx, pCur->zStr, pCur->nStr - (int)pCur->iRowid,
|
||||
0);
|
||||
break;
|
||||
default:
|
||||
sqlite3_result_text(ctx, pCur->zStr, pCur->nStr, 0);
|
||||
break;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the rowid for the current row. In this implementation, the
|
||||
** rowid is the same as the output value.
|
||||
*/
|
||||
static int prefixesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
|
||||
prefixes_cursor *pCur = (prefixes_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 prefixesEof(sqlite3_vtab_cursor *cur){
|
||||
prefixes_cursor *pCur = (prefixes_cursor*)cur;
|
||||
return pCur->iRowid>pCur->nStr;
|
||||
}
|
||||
|
||||
/*
|
||||
** This method is called to "rewind" the prefixes_cursor object back
|
||||
** to the first row of output. This method is always called at least
|
||||
** once prior to any call to prefixesColumn() or prefixesRowid() or
|
||||
** prefixesEof().
|
||||
*/
|
||||
static int prefixesFilter(
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
prefixes_cursor *pCur = (prefixes_cursor *)pVtabCursor;
|
||||
sqlite3_free(pCur->zStr);
|
||||
if( argc>0 ){
|
||||
pCur->zStr = sqlite3_mprintf("%s", sqlite3_value_text(argv[0]));
|
||||
pCur->nStr = pCur->zStr ? (int)strlen(pCur->zStr) : 0;
|
||||
}else{
|
||||
pCur->zStr = 0;
|
||||
pCur->nStr = 0;
|
||||
}
|
||||
pCur->iRowid = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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 prefixesBestIndex(
|
||||
sqlite3_vtab *tab,
|
||||
sqlite3_index_info *pIdxInfo
|
||||
){
|
||||
/* Search for a usable equality constraint against column 1
|
||||
** (original_string) and use it if at all possible */
|
||||
int i;
|
||||
const struct sqlite3_index_constraint *p;
|
||||
|
||||
for(i=0, p=pIdxInfo->aConstraint; i<pIdxInfo->nConstraint; i++, p++){
|
||||
if( p->iColumn!=1 ) continue;
|
||||
if( p->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
|
||||
if( !p->usable ) continue;
|
||||
pIdxInfo->aConstraintUsage[i].argvIndex = 1;
|
||||
pIdxInfo->aConstraintUsage[i].omit = 1;
|
||||
pIdxInfo->estimatedCost = (double)10;
|
||||
pIdxInfo->estimatedRows = 10;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
pIdxInfo->estimatedCost = (double)1000000000;
|
||||
pIdxInfo->estimatedRows = 1000000000;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This following structure defines all the methods for the
|
||||
** virtual table.
|
||||
*/
|
||||
static sqlite3_module prefixesModule = {
|
||||
/* iVersion */ 0,
|
||||
/* xCreate */ 0,
|
||||
/* xConnect */ prefixesConnect,
|
||||
/* xBestIndex */ prefixesBestIndex,
|
||||
/* xDisconnect */ prefixesDisconnect,
|
||||
/* xDestroy */ 0,
|
||||
/* xOpen */ prefixesOpen,
|
||||
/* xClose */ prefixesClose,
|
||||
/* xFilter */ prefixesFilter,
|
||||
/* xNext */ prefixesNext,
|
||||
/* xEof */ prefixesEof,
|
||||
/* xColumn */ prefixesColumn,
|
||||
/* xRowid */ prefixesRowid,
|
||||
/* xUpdate */ 0,
|
||||
/* xBegin */ 0,
|
||||
/* xSync */ 0,
|
||||
/* xCommit */ 0,
|
||||
/* xRollback */ 0,
|
||||
/* xFindMethod */ 0,
|
||||
/* xRename */ 0,
|
||||
/* xSavepoint */ 0,
|
||||
/* xRelease */ 0,
|
||||
/* xRollbackTo */ 0,
|
||||
/* xShadowName */ 0
|
||||
};
|
||||
|
||||
/*
|
||||
** This is a copy of the SQLITE_SKIP_UTF8(zIn) macro in sqliteInt.h.
|
||||
**
|
||||
** Assuming zIn points to the first byte of a UTF-8 character,
|
||||
** advance zIn to point to the first byte of the next UTF-8 character.
|
||||
*/
|
||||
#define PREFIX_SKIP_UTF8(zIn) { \
|
||||
if( (*(zIn++))>=0xc0 ){ \
|
||||
while( (*zIn & 0xc0)==0x80 ){ zIn++; } \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of function prefix_length(). This function accepts two
|
||||
** strings as arguments and returns the length in characters (not bytes),
|
||||
** of the longest prefix shared by the two strings. For example:
|
||||
**
|
||||
** prefix_length('abcdxxx', 'abcyy') == 3
|
||||
** prefix_length('abcdxxx', 'bcyyy') == 0
|
||||
** prefix_length('abcdxxx', 'ab') == 2
|
||||
** prefix_length('ab', 'abcd') == 2
|
||||
**
|
||||
** This function assumes the input is well-formed utf-8. If it is not,
|
||||
** it is possible for this function to return -1.
|
||||
*/
|
||||
static void prefixLengthFunc(
|
||||
sqlite3_context *ctx,
|
||||
int nVal,
|
||||
sqlite3_value **apVal
|
||||
){
|
||||
int nByte; /* Number of bytes to compare */
|
||||
int nRet = 0; /* Return value */
|
||||
const unsigned char *zL = sqlite3_value_text(apVal[0]);
|
||||
const unsigned char *zR = sqlite3_value_text(apVal[1]);
|
||||
int nL = sqlite3_value_bytes(apVal[0]);
|
||||
int nR = sqlite3_value_bytes(apVal[1]);
|
||||
int i;
|
||||
|
||||
nByte = (nL > nR ? nL : nR);
|
||||
for(i=0; i<nByte; i++){
|
||||
if( zL[i]!=zR[i] ) break;
|
||||
if( (zL[i] & 0xC0)!=0x80 ) nRet++;
|
||||
}
|
||||
|
||||
if( (zL[i] & 0xC0)==0x80 ) nRet--;
|
||||
sqlite3_result_int(ctx, nRet);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_prefixes_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
rc = sqlite3_create_module(db, "prefixes", &prefixesModule, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_create_function(
|
||||
db, "prefix_length", 2, SQLITE_UTF8, 0, prefixLengthFunc, 0, 0
|
||||
);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif /* !defined(SQLITE_CORE) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
|
||||
+3
-3
@@ -225,7 +225,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
pToFree = 0;
|
||||
aStateSet[0].aState = aSpace;
|
||||
}else{
|
||||
pToFree = sqlite3_malloc( sizeof(ReStateNumber)*2*pRe->nState );
|
||||
pToFree = sqlite3_malloc64( sizeof(ReStateNumber)*2*pRe->nState );
|
||||
if( pToFree==0 ) return -1;
|
||||
aStateSet[0].aState = pToFree;
|
||||
}
|
||||
@@ -337,10 +337,10 @@ re_match_end:
|
||||
static int re_resize(ReCompiled *p, int N){
|
||||
char *aOp;
|
||||
int *aArg;
|
||||
aOp = sqlite3_realloc(p->aOp, N*sizeof(p->aOp[0]));
|
||||
aOp = sqlite3_realloc64(p->aOp, N*sizeof(p->aOp[0]));
|
||||
if( aOp==0 ) return 1;
|
||||
p->aOp = aOp;
|
||||
aArg = sqlite3_realloc(p->aArg, N*sizeof(p->aArg[0]));
|
||||
aArg = sqlite3_realloc64(p->aArg, N*sizeof(p->aArg[0]));
|
||||
if( aArg==0 ) return 1;
|
||||
p->aArg = aArg;
|
||||
p->nAlloc = N;
|
||||
|
||||
@@ -0,0 +1,504 @@
|
||||
/*
|
||||
** 2019 April 12
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** A read-only VFS that reads data from a server instead of a file
|
||||
** using a custom protocol over a tcp/ip socket. The VFS is named
|
||||
** "socket". The filename passed to sqlite3_open() is of the
|
||||
** form "host:portnumber". For example, to connect to the server
|
||||
** on port 23456 on the localhost:
|
||||
**
|
||||
** sqlite3_open_v2("localhost:23456", &db, SQLITE_OPEN_READONLY, "socket");
|
||||
**
|
||||
** Or, if using URIs:
|
||||
**
|
||||
** sqlite3_open("file:localhost:23456?vfs=socket", &db);
|
||||
**
|
||||
** The protocol is:
|
||||
**
|
||||
** * Client connects to tcp/ip server. Server immediately sends the
|
||||
** database file-size in bytes as a 64-bit big-endian integer.
|
||||
**
|
||||
** * To read from the file, client sends the byte offset and amount
|
||||
** of data required in bytes, both as 64-bit big-endian integers
|
||||
** (i.e. a 16-byte message). Server sends back the requested data.
|
||||
**
|
||||
** As well as the usual SQLite loadable extension entry point, this file
|
||||
** exports one more function:
|
||||
**
|
||||
** sqlite3_vfs *sqlite3_socketvfs(void);
|
||||
**
|
||||
** To install the "socket" VFS without loading the extension, link this file
|
||||
** into the application and invoke:
|
||||
**
|
||||
** int bDefault = 0; // Do not make "socket" the default VFS
|
||||
** sqlite3_vfs_register(sqlite3_socketvfs(), bDefault);
|
||||
**
|
||||
*/
|
||||
|
||||
#include "sqlite3ext.h"
|
||||
SQLITE_EXTENSION_INIT1
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
# if defined(_WIN32_WINNT)
|
||||
# undef _WIN32_WINNT
|
||||
# endif
|
||||
# define _WIN32_WINNT 0x501
|
||||
#endif
|
||||
#ifndef __EXTENSIONS__
|
||||
# define __EXTENSIONS__ 1 /* IPv6 won't compile on Solaris without this */
|
||||
#endif
|
||||
#if defined(_WIN32)
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
# include <Windows.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# include <netinet/in.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netdb.h>
|
||||
# include <time.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
** When using this VFS, the sqlite3_file* handles that SQLite uses are
|
||||
** actually pointers to instances of type SocketFile.
|
||||
*/
|
||||
typedef struct SocketFile SocketFile;
|
||||
struct SocketFile {
|
||||
sqlite3_file base; /* Base class. Must be first. */
|
||||
int iSocket; /* Socket used to talk to server. */
|
||||
sqlite3_int64 szFile; /* Size of file in bytes */
|
||||
};
|
||||
|
||||
static sqlite3_uint64 socketGetU64(const unsigned char *a){
|
||||
return (((sqlite3_uint64)(a[0])) << 56)
|
||||
+ (((sqlite3_uint64)(a[1])) << 48)
|
||||
+ (((sqlite3_uint64)(a[2])) << 40)
|
||||
+ (((sqlite3_uint64)(a[3])) << 32)
|
||||
+ (((sqlite3_uint64)(a[4])) << 24)
|
||||
+ (((sqlite3_uint64)(a[5])) << 16)
|
||||
+ (((sqlite3_uint64)(a[6])) << 8)
|
||||
+ (((sqlite3_uint64)(a[7])) << 0);
|
||||
}
|
||||
|
||||
static void socketPutU64(unsigned char *a, sqlite3_int64 i){
|
||||
a[0] = ((i >> 56) & 0xFF);
|
||||
a[1] = ((i >> 48) & 0xFF);
|
||||
a[2] = ((i >> 40) & 0xFF);
|
||||
a[3] = ((i >> 32) & 0xFF);
|
||||
a[4] = ((i >> 24) & 0xFF);
|
||||
a[5] = ((i >> 16) & 0xFF);
|
||||
a[6] = ((i >> 8) & 0xFF);
|
||||
a[7] = ((i >> 0) & 0xFF);
|
||||
}
|
||||
|
||||
static void socket_close(int iSocket){
|
||||
if( iSocket>=0 ){
|
||||
#if defined(_WIN32)
|
||||
if( shutdown(iSocket,1)==0 ) shutdown(iSocket,0);
|
||||
closesocket(iSocket);
|
||||
#else
|
||||
close(iSocket);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Write nData bytes of data from buffer aData to socket iSocket. If
|
||||
** successful, return SQLITE_OK. Otherwise, SQLITE_IOERR_WRITE.
|
||||
*/
|
||||
static int socket_send(int iSocket, const unsigned char *aData, int nData){
|
||||
int nWrite = 0;
|
||||
do{
|
||||
int res = send(iSocket, (const char*)&aData[nWrite], nData-nWrite, 0);
|
||||
if( res<=0 ) return SQLITE_IOERR_WRITE;
|
||||
nWrite += res;
|
||||
}while( nWrite<nData );
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Read nData bytes of data from socket iSocket into buffer aData. If
|
||||
** successful, return SQLITE_OK. Otherwise, SQLITE_IOERR_READ.
|
||||
*/
|
||||
static int socket_recv(int iSocket, unsigned char *aData, int nData){
|
||||
int nRead = 0;
|
||||
do{
|
||||
int res = recv(iSocket, (char*)&aData[nRead], nData-nRead, 0);
|
||||
if( res<=0 ) return SQLITE_IOERR_READ;
|
||||
nRead += res;
|
||||
}while( nRead<nData );
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close a SocketFile file.
|
||||
*/
|
||||
static int socketClose(sqlite3_file *pFile){
|
||||
SocketFile *pSock = (SocketFile*)pFile;
|
||||
socket_close(pSock->iSocket);
|
||||
pSock->iSocket = -1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Read data from a SocketFile file.
|
||||
*/
|
||||
static int socketRead(
|
||||
sqlite3_file *pFile,
|
||||
void *zBuf,
|
||||
int iAmt,
|
||||
sqlite3_int64 iOfst
|
||||
){
|
||||
SocketFile *pSock = (SocketFile*)pFile;
|
||||
unsigned char aRequest[16];
|
||||
int rc = SQLITE_OK;
|
||||
int nRead = iAmt;
|
||||
|
||||
if( iOfst+nRead>pSock->szFile ){
|
||||
nRead = (int)(pSock->szFile - iOfst);
|
||||
memset(zBuf, 0, iAmt);
|
||||
rc = SQLITE_IOERR_SHORT_READ;
|
||||
}
|
||||
|
||||
if( nRead>0 ){
|
||||
socketPutU64(&aRequest[0], (sqlite3_uint64)iOfst);
|
||||
socketPutU64(&aRequest[8], (sqlite3_uint64)nRead);
|
||||
rc = socket_send(pSock->iSocket, aRequest, sizeof(aRequest));
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = socket_recv(pSock->iSocket, zBuf, nRead);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write to a file. This is a no-op, as this VFS is always opens files
|
||||
** read-only.
|
||||
*/
|
||||
static int socketWrite(
|
||||
sqlite3_file *pFile,
|
||||
const void *zBuf,
|
||||
int iAmt,
|
||||
sqlite3_int64 iOfst
|
||||
){
|
||||
return SQLITE_IOERR_WRITE;
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate a file. This is a no-op, as this VFS is always opens files
|
||||
** read-only.
|
||||
*/
|
||||
static int socketTruncate(sqlite3_file *pFile, sqlite3_int64 size){
|
||||
return SQLITE_IOERR_TRUNCATE;
|
||||
}
|
||||
|
||||
/*
|
||||
** Synk a file. This is a no-op, as this VFS is always opens files
|
||||
** read-only.
|
||||
*/
|
||||
static int socketSync(sqlite3_file *pFile, int flags){
|
||||
return SQLITE_IOERR_FSYNC;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write the size of the file in bytes to *pSize.
|
||||
*/
|
||||
static int socketFileSize(sqlite3_file *pFile, sqlite3_int64 *pSize){
|
||||
SocketFile *pSock = (SocketFile*)pFile;
|
||||
*pSize = pSock->szFile;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Locking functions. All no-ops.
|
||||
*/
|
||||
static int socketLock(sqlite3_file *pFile, int eLock){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
static int socketUnlock(sqlite3_file *pFile, int eLock){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
static int socketCheckReservedLock(sqlite3_file *pFile, int *pResOut){
|
||||
*pResOut = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** No xFileControl() verbs are implemented by this VFS.
|
||||
*/
|
||||
static int socketFileControl(sqlite3_file *pFile, int op, void *pArg){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** The xSectorSize() and xDeviceCharacteristics() methods. These two
|
||||
** may return special values allowing SQLite to optimize file-system
|
||||
** access to some extent. But it is also safe to simply return 0.
|
||||
*/
|
||||
static int socketSectorSize(sqlite3_file *pFile){
|
||||
return 0;
|
||||
}
|
||||
static int socketDeviceCharacteristics(sqlite3_file *pFile){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Open a SocketFile file.
|
||||
*/
|
||||
static int socketOpen(
|
||||
sqlite3_vfs *pVfs, /* VFS */
|
||||
const char *zName, /* File to open, or 0 for a temp file */
|
||||
sqlite3_file *pFile, /* Pointer to SocketFile struct to populate */
|
||||
int flags, /* Input SQLITE_OPEN_XXX flags */
|
||||
int *pOutFlags /* Output SQLITE_OPEN_XXX flags (or NULL) */
|
||||
){
|
||||
static const sqlite3_io_methods socketio = {
|
||||
1, /* iVersion */
|
||||
socketClose, /* xClose */
|
||||
socketRead, /* xRead */
|
||||
socketWrite, /* xWrite */
|
||||
socketTruncate, /* xTruncate */
|
||||
socketSync, /* xSync */
|
||||
socketFileSize, /* xFileSize */
|
||||
socketLock, /* xLock */
|
||||
socketUnlock, /* xUnlock */
|
||||
socketCheckReservedLock, /* xCheckReservedLock */
|
||||
socketFileControl, /* xFileControl */
|
||||
socketSectorSize, /* xSectorSize */
|
||||
socketDeviceCharacteristics /* xDeviceCharacteristics */
|
||||
};
|
||||
|
||||
SocketFile *pSock = (SocketFile*)pFile;
|
||||
|
||||
char zHost[1024];
|
||||
const char *zPort;
|
||||
int i;
|
||||
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *ai = 0;
|
||||
struct addrinfo *pInfo;
|
||||
unsigned char aFileSize[8];
|
||||
|
||||
pSock->iSocket = -1;
|
||||
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ) return SQLITE_CANTOPEN;
|
||||
|
||||
/* Parse the argument and copy the results to zHost and zPort. It should be
|
||||
** "hostname:port". Anything else is an error. */
|
||||
assert( sizeof(zHost)>=pVfs->mxPathname );
|
||||
if( zName==0 ) return SQLITE_CANTOPEN;
|
||||
for(i=0; zName[i] && zName[i]!=':'; i++);
|
||||
if( zName[i]==0 ) return SQLITE_CANTOPEN;
|
||||
memcpy(zHost, zName, i);
|
||||
zHost[i] = '\0';
|
||||
zPort = &zName[i+1];
|
||||
|
||||
/* Resolve the address */
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
if( getaddrinfo(zHost, zPort, &hints, &ai) ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
|
||||
/* Connect to the resolved address. Set SocketFile.iSocket to the tcp/ip
|
||||
** socket and return SQLITE_OK. */
|
||||
for(pInfo=ai; pInfo; pInfo=pInfo->ai_next){
|
||||
int sd = socket(pInfo->ai_family, pInfo->ai_socktype, pInfo->ai_protocol);
|
||||
if( sd<0 ) continue;
|
||||
if( connect(sd, pInfo->ai_addr, pInfo->ai_addrlen)<0 ){
|
||||
socket_close(sd);
|
||||
continue;
|
||||
}
|
||||
pSock->iSocket = sd;
|
||||
break;
|
||||
}
|
||||
|
||||
if( ai ) freeaddrinfo(ai);
|
||||
if( pSock->iSocket<0 ) return SQLITE_CANTOPEN;
|
||||
|
||||
/* The server sends back the file size as a 64-bit big-endian */
|
||||
if( socket_recv(pSock->iSocket, aFileSize, 8) ){
|
||||
socket_close(pSock->iSocket);
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
pSock->szFile = (sqlite3_int64)socketGetU64(aFileSize);
|
||||
|
||||
*pOutFlags = flags & ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
|
||||
*pOutFlags |= SQLITE_OPEN_READONLY;
|
||||
pSock->base.pMethods = &socketio;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Another no-op. This is a read-only VFS.
|
||||
*/
|
||||
static int socketDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
|
||||
return SQLITE_IOERR_DELETE;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is used by SQLite to detect journal and wal files. Which cannot
|
||||
** exist for this VFS. So always set the output to false and return
|
||||
** SQLITE_OK.
|
||||
*/
|
||||
static int socketAccess(
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zPath,
|
||||
int flags,
|
||||
int *pResOut
|
||||
){
|
||||
*pResOut = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** A no-op. Copy the input to the output.
|
||||
*/
|
||||
static int socketFullPathname(
|
||||
sqlite3_vfs *pVfs, /* VFS */
|
||||
const char *zPath, /* Input path (possibly a relative path) */
|
||||
int nPathOut, /* Size of output buffer in bytes */
|
||||
char *zPathOut /* Pointer to output buffer */
|
||||
){
|
||||
int nByte = strlen(zPath);
|
||||
if( nByte>=pVfs->mxPathname ) return SQLITE_IOERR;
|
||||
memcpy(zPathOut, zPath, nByte+1);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following four VFS methods:
|
||||
**
|
||||
** xDlOpen
|
||||
** xDlError
|
||||
** xDlSym
|
||||
** xDlClose
|
||||
**
|
||||
** are supposed to implement the functionality needed by SQLite to load
|
||||
** extensions compiled as shared objects. This simple VFS does not support
|
||||
** this functionality, so the following functions are no-ops.
|
||||
*/
|
||||
static void *socketDlOpen(sqlite3_vfs *pVfs, const char *zPath){
|
||||
return 0;
|
||||
}
|
||||
static void socketDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
|
||||
sqlite3_snprintf(nByte, zErrMsg, "Loadable extensions are not supported");
|
||||
zErrMsg[nByte-1] = '\0';
|
||||
}
|
||||
static void (*socketDlSym(sqlite3_vfs *pVfs, void *pH, const char *z))(void){
|
||||
return 0;
|
||||
}
|
||||
static void socketDlClose(sqlite3_vfs *pVfs, void *pHandle){
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** Parameter zByte points to a buffer nByte bytes in size. Populate this
|
||||
** buffer with pseudo-random data.
|
||||
*/
|
||||
static int socketRandomness(sqlite3_vfs *pVfs, int nByte, char *zByte){
|
||||
memset(zByte, 0, nByte);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sleep for at least nMicro microseconds. Return the (approximate) number
|
||||
** of microseconds slept for.
|
||||
*/
|
||||
static int socketSleep(sqlite3_vfs *pVfs, int nMicro){
|
||||
#ifdef _WIN32
|
||||
Sleep(nMicro/1000);
|
||||
#else
|
||||
sleep(nMicro / 1000000);
|
||||
usleep(nMicro % 1000000);
|
||||
#endif
|
||||
return nMicro;
|
||||
}
|
||||
|
||||
/*
|
||||
** Set *pTime to the current UTC time expressed as a Julian day. Return
|
||||
** SQLITE_OK if successful, or an error code otherwise.
|
||||
**
|
||||
** http://en.wikipedia.org/wiki/Julian_day
|
||||
**
|
||||
** This implementation is not very good. The current time is rounded to
|
||||
** an integer number of seconds. Also, assuming time_t is a signed 32-bit
|
||||
** value, it will stop working some time in the year 2038 AD (the so-called
|
||||
** "year 2038" problem that afflicts systems that store time this way).
|
||||
*/
|
||||
static int socketCurrentTime(sqlite3_vfs *pVfs, double *pTime){
|
||||
time_t t = time(0);
|
||||
*pTime = t/86400.0 + 2440587.5;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function returns a pointer to the VFS implemented in this file.
|
||||
** To make the VFS available to SQLite:
|
||||
**
|
||||
** sqlite3_vfs_register(sqlite3_socketvfs(), 0);
|
||||
*/
|
||||
sqlite3_vfs *sqlite3_socketvfs(void){
|
||||
static sqlite3_vfs socketvfs = {
|
||||
1, /* iVersion */
|
||||
sizeof(SocketFile), /* szOsFile */
|
||||
512, /* mxPathname */
|
||||
0, /* pNext */
|
||||
"socket", /* zName */
|
||||
0, /* pAppData */
|
||||
socketOpen, /* xOpen */
|
||||
socketDelete, /* xDelete */
|
||||
socketAccess, /* xAccess */
|
||||
socketFullPathname, /* xFullPathname */
|
||||
socketDlOpen, /* xDlOpen */
|
||||
socketDlError, /* xDlError */
|
||||
socketDlSym, /* xDlSym */
|
||||
socketDlClose, /* xDlClose */
|
||||
socketRandomness, /* xRandomness */
|
||||
socketSleep, /* xSleep */
|
||||
socketCurrentTime, /* xCurrentTime */
|
||||
};
|
||||
return &socketvfs;
|
||||
}
|
||||
|
||||
/*
|
||||
** Register the amatch virtual table
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_socketvfs_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg; /* Not used */
|
||||
sqlite3_vfs_register(sqlite3_socketvfs(), 0);
|
||||
return SQLITE_OK_LOAD_PERMANENTLY;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
# \
|
||||
exec tclsh "$0" ${1+"$@"}
|
||||
|
||||
if {[llength $argv]!=2} {
|
||||
puts stderr "Usage: $argv0 <filename> <port>"
|
||||
exit -1
|
||||
}
|
||||
set G(filename) [lindex $argv 0]
|
||||
set G(port) [lindex $argv 1]
|
||||
|
||||
proc new_message {chan} {
|
||||
global G
|
||||
if {[eof $chan]} {
|
||||
close $chan
|
||||
puts "Close channel $chan"
|
||||
} else {
|
||||
set msg [read $chan 16]
|
||||
if {[string length $msg]>0} {
|
||||
binary scan $msg WW offset amt
|
||||
# puts "Request from $chan for $amt bytes at offset $offset"
|
||||
seek $G(fd) $offset
|
||||
set data [read $G(fd) $amt]
|
||||
puts -nonewline $chan $data
|
||||
flush $chan
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proc new_connection {chan addr port} {
|
||||
global G
|
||||
|
||||
set sz [file size $G(filename)]
|
||||
|
||||
puts -nonewline "$addr:$port connects! "
|
||||
puts "Sending file size ($sz) as a 64-bit big-endian integer."
|
||||
set bin [binary format W $sz]
|
||||
puts -nonewline $chan $bin
|
||||
flush $chan
|
||||
|
||||
fconfigure $chan -encoding binary
|
||||
fconfigure $chan -translation binary
|
||||
fileevent $chan readable [list new_message $chan]
|
||||
}
|
||||
|
||||
set G(fd) [open $G(filename) r]
|
||||
fconfigure $G(fd) -encoding binary
|
||||
fconfigure $G(fd) -translation binary
|
||||
|
||||
socket -server new_connection $G(port)
|
||||
vwait forever
|
||||
|
||||
@@ -250,13 +250,13 @@ struct UnionCsr {
|
||||
** is attempted but fails, NULL is returned and *pRc is set to
|
||||
** SQLITE_NOMEM.
|
||||
*/
|
||||
static void *unionMalloc(int *pRc, int nByte){
|
||||
static void *unionMalloc(int *pRc, sqlite3_int64 nByte){
|
||||
void *pRet;
|
||||
assert( nByte>0 );
|
||||
if( *pRc==SQLITE_OK ){
|
||||
pRet = sqlite3_malloc(nByte);
|
||||
pRet = sqlite3_malloc64(nByte);
|
||||
if( pRet ){
|
||||
memset(pRet, 0, nByte);
|
||||
memset(pRet, 0, (size_t)nByte);
|
||||
}else{
|
||||
*pRc = SQLITE_NOMEM;
|
||||
}
|
||||
@@ -276,10 +276,10 @@ static void *unionMalloc(int *pRc, int nByte){
|
||||
static char *unionStrdup(int *pRc, const char *zIn){
|
||||
char *zRet = 0;
|
||||
if( zIn ){
|
||||
int nByte = (int)strlen(zIn) + 1;
|
||||
sqlite3_int64 nByte = strlen(zIn) + 1;
|
||||
zRet = unionMalloc(pRc, nByte);
|
||||
if( zRet ){
|
||||
memcpy(zRet, zIn, nByte);
|
||||
memcpy(zRet, zIn, (size_t)nByte);
|
||||
}
|
||||
}
|
||||
return zRet;
|
||||
@@ -939,7 +939,7 @@ static int unionConnect(
|
||||
/* Grow the pTab->aSrc[] array if required. */
|
||||
if( nAlloc<=pTab->nSrc ){
|
||||
int nNew = nAlloc ? nAlloc*2 : 8;
|
||||
UnionSrc *aNew = (UnionSrc*)sqlite3_realloc(
|
||||
UnionSrc *aNew = (UnionSrc*)sqlite3_realloc64(
|
||||
pTab->aSrc, nNew*sizeof(UnionSrc)
|
||||
);
|
||||
if( aNew==0 ){
|
||||
|
||||
+1
-1
@@ -276,7 +276,7 @@ static VLogLog *vlogLogOpen(const char *zFilename){
|
||||
&& sqlite3_strglob("-mj??????9??", zFilename+nName-12)==0 ){
|
||||
return 0; /* Do not log master journal files */
|
||||
}
|
||||
pTemp = sqlite3_malloc( sizeof(*pLog)*2 + nName + 60 );
|
||||
pTemp = sqlite3_malloc64( sizeof(*pLog)*2 + nName + 60 );
|
||||
if( pTemp==0 ) return 0;
|
||||
pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
|
||||
sqlite3_mutex_enter(pMutex);
|
||||
|
||||
+6
-3
@@ -783,8 +783,8 @@ static sqlite3_module VfsStatModule = {
|
||||
*/
|
||||
static int vstatRegister(
|
||||
sqlite3 *db,
|
||||
const char **pzErrMsg,
|
||||
const struct sqlite3_api_routines *pThunk
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pThunk
|
||||
){
|
||||
return sqlite3_create_module(db, "vfsstat", &VfsStatModule, 0);
|
||||
}
|
||||
@@ -809,7 +809,10 @@ int sqlite3_vfsstat_init(
|
||||
vstat_vfs.base.szOsFile = sizeof(VStatFile) + vstat_vfs.pVfs->szOsFile;
|
||||
rc = sqlite3_vfs_register(&vstat_vfs.base, 1);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_auto_extension(vstatRegister);
|
||||
rc = vstatRegister(db, pzErrMsg, pApi);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_auto_extension(vstatRegister);
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE_OK ) rc = SQLITE_OK_LOAD_PERMANENTLY;
|
||||
return rc;
|
||||
|
||||
+12
-12
@@ -358,7 +358,7 @@ static int zipfileConnect(
|
||||
|
||||
rc = sqlite3_declare_vtab(db, ZIPFILE_SCHEMA);
|
||||
if( rc==SQLITE_OK ){
|
||||
pNew = (ZipfileTab*)sqlite3_malloc(nByte+nFile);
|
||||
pNew = (ZipfileTab*)sqlite3_malloc64((sqlite3_int64)nByte+nFile);
|
||||
if( pNew==0 ) return SQLITE_NOMEM;
|
||||
memset(pNew, 0, nByte+nFile);
|
||||
pNew->db = db;
|
||||
@@ -806,7 +806,7 @@ static int zipfileGetEntry(
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
int nAlloc;
|
||||
sqlite3_int64 nAlloc;
|
||||
ZipfileEntry *pNew;
|
||||
|
||||
int nFile = zipfileGetU16(&aRead[ZIPFILE_CDS_NFILE_OFF]);
|
||||
@@ -818,7 +818,7 @@ static int zipfileGetEntry(
|
||||
nAlloc += zipfileGetU32(&aRead[ZIPFILE_CDS_SZCOMPRESSED_OFF]);
|
||||
}
|
||||
|
||||
pNew = (ZipfileEntry*)sqlite3_malloc(nAlloc);
|
||||
pNew = (ZipfileEntry*)sqlite3_malloc64(nAlloc);
|
||||
if( pNew==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -981,11 +981,11 @@ static int zipfileDeflate(
|
||||
u8 **ppOut, int *pnOut, /* Output */
|
||||
char **pzErr /* OUT: Error message */
|
||||
){
|
||||
int nAlloc = (int)compressBound(nIn);
|
||||
sqlite3_int64 nAlloc = compressBound(nIn);
|
||||
u8 *aOut;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
aOut = (u8*)sqlite3_malloc(nAlloc);
|
||||
aOut = (u8*)sqlite3_malloc64(nAlloc);
|
||||
if( aOut==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -1058,7 +1058,7 @@ static int zipfileColumn(
|
||||
if( pCsr->pCurrent->aData ){
|
||||
aBuf = pCsr->pCurrent->aData;
|
||||
}else{
|
||||
aBuf = aFree = sqlite3_malloc(sz);
|
||||
aBuf = aFree = sqlite3_malloc64(sz);
|
||||
if( aBuf==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -1897,14 +1897,14 @@ struct ZipfileCtx {
|
||||
static int zipfileBufferGrow(ZipfileBuffer *pBuf, int nByte){
|
||||
if( pBuf->n+nByte>pBuf->nAlloc ){
|
||||
u8 *aNew;
|
||||
int nNew = pBuf->n ? pBuf->n*2 : 512;
|
||||
sqlite3_int64 nNew = pBuf->n ? pBuf->n*2 : 512;
|
||||
int nReq = pBuf->n + nByte;
|
||||
|
||||
while( nNew<nReq ) nNew = nNew*2;
|
||||
aNew = sqlite3_realloc(pBuf->a, nNew);
|
||||
aNew = sqlite3_realloc64(pBuf->a, nNew);
|
||||
if( aNew==0 ) return SQLITE_NOMEM;
|
||||
pBuf->a = aNew;
|
||||
pBuf->nAlloc = nNew;
|
||||
pBuf->nAlloc = (int)nNew;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -2095,7 +2095,7 @@ void zipfileStep(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal){
|
||||
void zipfileFinal(sqlite3_context *pCtx){
|
||||
ZipfileCtx *p;
|
||||
ZipfileEOCD eocd;
|
||||
int nZip;
|
||||
sqlite3_int64 nZip;
|
||||
u8 *aZip;
|
||||
|
||||
p = (ZipfileCtx*)sqlite3_aggregate_context(pCtx, sizeof(ZipfileCtx));
|
||||
@@ -2108,14 +2108,14 @@ void zipfileFinal(sqlite3_context *pCtx){
|
||||
eocd.iOffset = p->body.n;
|
||||
|
||||
nZip = p->body.n + p->cds.n + ZIPFILE_EOCD_FIXED_SZ;
|
||||
aZip = (u8*)sqlite3_malloc(nZip);
|
||||
aZip = (u8*)sqlite3_malloc64(nZip);
|
||||
if( aZip==0 ){
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
}else{
|
||||
memcpy(aZip, p->body.a, p->body.n);
|
||||
memcpy(&aZip[p->body.n], p->cds.a, p->cds.n);
|
||||
zipfileSerializeEOCD(&eocd, &aZip[p->body.n + p->cds.n]);
|
||||
sqlite3_result_blob(pCtx, aZip, nZip, zipfileFree);
|
||||
sqlite3_result_blob(pCtx, aZip, (int)nZip, zipfileFree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
# 2019 April 11
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] rbu_common.tcl]
|
||||
set ::testprefix rbupartial
|
||||
|
||||
db close
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_uri 1
|
||||
|
||||
foreach {tn without_rowid a b c d} {
|
||||
1 "" a b c d
|
||||
2 "WITHOUT ROWID" aaa bbb ccc ddd
|
||||
3 "WITHOUT ROWID" "\"hello\"" {"one'two"} {[c]} ddd
|
||||
4 "WITHOUT ROWID" {`a b`} {"one'two"} {[c c c]} ddd
|
||||
5 "" a b c {"d""d"}
|
||||
6 "" {'one''two'} b {"c""c"} {"d""d"}
|
||||
} {
|
||||
eval [string map [list \
|
||||
%WITHOUT_ROWID% $without_rowid %A% $a %B% $b %C% $c %D% $d
|
||||
] {
|
||||
reset_db
|
||||
do_execsql_test $tn.1.0 {
|
||||
CREATE TABLE t1(%A% PRIMARY KEY, %B%, %C%, %D%) %WITHOUT_ROWID% ;
|
||||
CREATE INDEX i1b ON t1(%B%);
|
||||
CREATE INDEX i1b2 ON t1(%B%) WHERE %C%<5;
|
||||
CREATE INDEX i1b3 ON t1(%B%) WHERE %C%>=5;
|
||||
|
||||
CREATE INDEX i1c ON t1(%C%);
|
||||
CREATE INDEX i1c2 ON t1(%C%) WHERE %C% IS NULL;
|
||||
CREATE INDEX i1c3 ON t1(%C%) WHERE %C% IS NOT NULL;
|
||||
|
||||
CREATE INDEX i1c4 ON t1(%C%) WHERE %D% < 'd';
|
||||
}
|
||||
|
||||
do_execsql_test $tn.1.1 {
|
||||
INSERT INTO t1 VALUES(0, NULL, NULL, 'a');
|
||||
INSERT INTO t1 VALUES(1, 2, 3, 'b');
|
||||
INSERT INTO t1 VALUES(4, 5, 6, 'c');
|
||||
INSERT INTO t1 VALUES(7, 8, 9, 'd');
|
||||
}
|
||||
|
||||
forcedelete rbu.db
|
||||
do_test $tn.1.2 {
|
||||
sqlite3 rbu rbu.db
|
||||
rbu eval {
|
||||
CREATE TABLE data_t1(%A%, %B%, %C%, %D%, rbu_control);
|
||||
|
||||
INSERT INTO data_t1 VALUES(10, 11, 12, 'e', 0);
|
||||
INSERT INTO data_t1 VALUES(13, 14, NULL, 'f', 0);
|
||||
|
||||
INSERT INTO data_t1 VALUES(0, NULL, NULL, NULL, 1);
|
||||
INSERT INTO data_t1 VALUES(4, NULL, NULL, NULL, 1);
|
||||
|
||||
INSERT INTO data_t1 VALUES(7, NULL, 4, NULL, '..x.');
|
||||
INSERT INTO data_t1 VALUES(1, 10, NULL, NULL, '.xx.');
|
||||
}
|
||||
rbu close
|
||||
} {}
|
||||
|
||||
do_test $tn.1.3 {
|
||||
run_rbu test.db rbu.db
|
||||
execsql { PRAGMA integrity_check }
|
||||
} {ok}
|
||||
|
||||
do_execsql_test $tn.1.4 {
|
||||
SELECT * FROM t1 ORDER BY %A%;
|
||||
} {
|
||||
1 10 {} b 7 8 4 d 10 11 12 e 13 14 {} f
|
||||
}
|
||||
|
||||
set step 0
|
||||
do_rbu_vacuum_test $tn.1.5 0
|
||||
}]
|
||||
}
|
||||
|
||||
finish_test
|
||||
+78
-7
@@ -240,6 +240,11 @@ struct RbuUpdateStmt {
|
||||
** it points to an array of flags nTblCol elements in size. The flag is
|
||||
** set for each column that is either a part of the PK or a part of an
|
||||
** index. Or clear otherwise.
|
||||
**
|
||||
** If there are one or more partial indexes on the table, all fields of
|
||||
** this array set set to 1. This is because in that case, the module has
|
||||
** no way to tell which fields will be required to add and remove entries
|
||||
** from the partial indexes.
|
||||
**
|
||||
*/
|
||||
struct RbuObjIter {
|
||||
@@ -684,6 +689,7 @@ static void rbuFossilDeltaFunc(
|
||||
}else{
|
||||
nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
|
||||
if( nOut2!=nOut ){
|
||||
sqlite3_free(aOut);
|
||||
sqlite3_result_error(context, "corrupt fossil delta", -1);
|
||||
}else{
|
||||
sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
|
||||
@@ -1249,8 +1255,12 @@ static void rbuObjIterCacheIndexedCols(sqlite3rbu *p, RbuObjIter *pIter){
|
||||
pIter->nIndex = 0;
|
||||
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){
|
||||
const char *zIdx = (const char*)sqlite3_column_text(pList, 1);
|
||||
int bPartial = sqlite3_column_int(pList, 4);
|
||||
sqlite3_stmt *pXInfo = 0;
|
||||
if( zIdx==0 ) break;
|
||||
if( bPartial ){
|
||||
memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
|
||||
}
|
||||
p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
|
||||
sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
|
||||
);
|
||||
@@ -1957,6 +1967,62 @@ static void rbuTmpInsertFunc(
|
||||
}
|
||||
}
|
||||
|
||||
static char *rbuObjIterGetIndexWhere(sqlite3rbu *p, RbuObjIter *pIter){
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
int rc = p->rc;
|
||||
char *zRet = 0;
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
|
||||
"SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?"
|
||||
);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
int rc2;
|
||||
rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC);
|
||||
if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
|
||||
if( zSql ){
|
||||
int nParen = 0; /* Number of open parenthesis */
|
||||
int i;
|
||||
for(i=0; zSql[i]; i++){
|
||||
char c = zSql[i];
|
||||
if( c=='(' ){
|
||||
nParen++;
|
||||
}
|
||||
else if( c==')' ){
|
||||
nParen--;
|
||||
if( nParen==0 ){
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
}else if( c=='"' || c=='\'' || c=='`' ){
|
||||
for(i++; 1; i++){
|
||||
if( zSql[i]==c ){
|
||||
if( zSql[i+1]!=c ) break;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}else if( c=='[' ){
|
||||
for(i++; 1; i++){
|
||||
if( zSql[i]==']' ) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( zSql[i] ){
|
||||
zRet = rbuStrndup(&zSql[i], &rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rc2 = sqlite3_finalize(pStmt);
|
||||
if( rc==SQLITE_OK ) rc = rc2;
|
||||
}
|
||||
|
||||
p->rc = rc;
|
||||
return zRet;
|
||||
}
|
||||
|
||||
/*
|
||||
** Ensure that the SQLite statement handles required to update the
|
||||
** target database object currently indicated by the iterator passed
|
||||
@@ -1986,6 +2052,7 @@ static int rbuObjIterPrepareAll(
|
||||
char *zImposterPK = 0; /* Primary key declaration for imposter */
|
||||
char *zWhere = 0; /* WHERE clause on PK columns */
|
||||
char *zBind = 0;
|
||||
char *zPart = 0;
|
||||
int nBind = 0;
|
||||
|
||||
assert( pIter->eType!=RBU_PK_VTAB );
|
||||
@@ -1993,6 +2060,7 @@ static int rbuObjIterPrepareAll(
|
||||
p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
|
||||
);
|
||||
zBind = rbuObjIterGetBindlist(p, nBind);
|
||||
zPart = rbuObjIterGetIndexWhere(p, pIter);
|
||||
|
||||
/* Create the imposter table used to write to this index. */
|
||||
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
|
||||
@@ -2025,28 +2093,30 @@ static int rbuObjIterPrepareAll(
|
||||
char *zSql;
|
||||
if( rbuIsVacuum(p) ){
|
||||
zSql = sqlite3_mprintf(
|
||||
"SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s",
|
||||
"SELECT %s, 0 AS rbu_control FROM '%q' %s ORDER BY %s%s",
|
||||
zCollist,
|
||||
pIter->zDataTbl,
|
||||
zCollist, zLimit
|
||||
zPart, zCollist, zLimit
|
||||
);
|
||||
}else
|
||||
|
||||
if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
|
||||
zSql = sqlite3_mprintf(
|
||||
"SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
|
||||
"SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s",
|
||||
zCollist, p->zStateDb, pIter->zDataTbl,
|
||||
zCollist, zLimit
|
||||
zPart, zCollist, zLimit
|
||||
);
|
||||
}else{
|
||||
zSql = sqlite3_mprintf(
|
||||
"SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
|
||||
"SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s "
|
||||
"UNION ALL "
|
||||
"SELECT %s, rbu_control FROM '%q' "
|
||||
"WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
|
||||
"%s %s typeof(rbu_control)='integer' AND rbu_control!=1 "
|
||||
"ORDER BY %s%s",
|
||||
zCollist, p->zStateDb, pIter->zDataTbl,
|
||||
zCollist, p->zStateDb, pIter->zDataTbl, zPart,
|
||||
zCollist, pIter->zDataTbl,
|
||||
zPart,
|
||||
(zPart ? "AND" : "WHERE"),
|
||||
zCollist, zLimit
|
||||
);
|
||||
}
|
||||
@@ -2057,6 +2127,7 @@ static int rbuObjIterPrepareAll(
|
||||
sqlite3_free(zImposterPK);
|
||||
sqlite3_free(zWhere);
|
||||
sqlite3_free(zBind);
|
||||
sqlite3_free(zPart);
|
||||
}else{
|
||||
int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
|
||||
||(pIter->eType==RBU_PK_NONE)
|
||||
|
||||
+50
-41
@@ -124,6 +124,14 @@ struct GeoPoly {
|
||||
*/
|
||||
#define GEOPOLY_SZ(N) (sizeof(GeoPoly) + sizeof(GeoCoord)*2*((N)-4))
|
||||
|
||||
/* Macros to access coordinates of a GeoPoly.
|
||||
** We have to use these macros, rather than just say p->a[i] in order
|
||||
** to silence (incorrect) UBSAN warnings if the array index is too large.
|
||||
*/
|
||||
#define GeoX(P,I) (((GeoCoord*)(P)->a)[(I)*2])
|
||||
#define GeoY(P,I) (((GeoCoord*)(P)->a)[(I)*2+1])
|
||||
|
||||
|
||||
/*
|
||||
** State of a parse of a GeoJSON input.
|
||||
*/
|
||||
@@ -316,8 +324,9 @@ static GeoPoly *geopolyFuncParam(
|
||||
memcpy(p->hdr, a, nByte);
|
||||
if( a[0] != *(unsigned char*)&x ){
|
||||
int ii;
|
||||
for(ii=0; ii<nVertex*2; ii++){
|
||||
geopolySwab32((unsigned char*)&p->a[ii]);
|
||||
for(ii=0; ii<nVertex; ii++){
|
||||
geopolySwab32((unsigned char*)&GeoX(p,ii));
|
||||
geopolySwab32((unsigned char*)&GeoY(p,ii));
|
||||
}
|
||||
p->hdr[0] ^= 1;
|
||||
}
|
||||
@@ -376,9 +385,9 @@ static void geopolyJsonFunc(
|
||||
int i;
|
||||
sqlite3_str_append(x, "[", 1);
|
||||
for(i=0; i<p->nVertex; i++){
|
||||
sqlite3_str_appendf(x, "[%!g,%!g],", p->a[i*2], p->a[i*2+1]);
|
||||
sqlite3_str_appendf(x, "[%!g,%!g],", GeoX(p,i), GeoY(p,i));
|
||||
}
|
||||
sqlite3_str_appendf(x, "[%!g,%!g]]", p->a[0], p->a[1]);
|
||||
sqlite3_str_appendf(x, "[%!g,%!g]]", GeoX(p,0), GeoY(p,0));
|
||||
sqlite3_result_text(context, sqlite3_str_finish(x), -1, sqlite3_free);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
@@ -405,10 +414,10 @@ static void geopolySvgFunc(
|
||||
char cSep = '\'';
|
||||
sqlite3_str_appendf(x, "<polyline points=");
|
||||
for(i=0; i<p->nVertex; i++){
|
||||
sqlite3_str_appendf(x, "%c%g,%g", cSep, p->a[i*2], p->a[i*2+1]);
|
||||
sqlite3_str_appendf(x, "%c%g,%g", cSep, GeoX(p,i), GeoY(p,i));
|
||||
cSep = ' ';
|
||||
}
|
||||
sqlite3_str_appendf(x, " %g,%g'", p->a[0], p->a[1]);
|
||||
sqlite3_str_appendf(x, " %g,%g'", GeoX(p,0), GeoY(p,0));
|
||||
for(i=1; i<argc; i++){
|
||||
const char *z = (const char*)sqlite3_value_text(argv[i]);
|
||||
if( z && z[0] ){
|
||||
@@ -453,12 +462,12 @@ static void geopolyXformFunc(
|
||||
int ii;
|
||||
if( p ){
|
||||
for(ii=0; ii<p->nVertex; ii++){
|
||||
x0 = p->a[ii*2];
|
||||
y0 = p->a[ii*2+1];
|
||||
x0 = GeoX(p,ii);
|
||||
y0 = GeoY(p,ii);
|
||||
x1 = (GeoCoord)(A*x0 + B*y0 + E);
|
||||
y1 = (GeoCoord)(C*x0 + D*y0 + F);
|
||||
p->a[ii*2] = x1;
|
||||
p->a[ii*2+1] = y1;
|
||||
GeoX(p,ii) = x1;
|
||||
GeoY(p,ii) = y1;
|
||||
}
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
4+8*p->nVertex, SQLITE_TRANSIENT);
|
||||
@@ -477,12 +486,12 @@ static double geopolyArea(GeoPoly *p){
|
||||
double rArea = 0.0;
|
||||
int ii;
|
||||
for(ii=0; ii<p->nVertex-1; ii++){
|
||||
rArea += (p->a[ii*2] - p->a[ii*2+2]) /* (x0 - x1) */
|
||||
* (p->a[ii*2+1] + p->a[ii*2+3]) /* (y0 + y1) */
|
||||
rArea += (GeoX(p,ii) - GeoX(p,ii+1)) /* (x0 - x1) */
|
||||
* (GeoY(p,ii) + GeoY(p,ii+1)) /* (y0 + y1) */
|
||||
* 0.5;
|
||||
}
|
||||
rArea += (p->a[ii*2] - p->a[0]) /* (xN - x0) */
|
||||
* (p->a[ii*2+1] + p->a[1]) /* (yN + y0) */
|
||||
rArea += (GeoX(p,ii) - GeoX(p,0)) /* (xN - x0) */
|
||||
* (GeoY(p,ii) + GeoY(p,0)) /* (yN + y0) */
|
||||
* 0.5;
|
||||
return rArea;
|
||||
}
|
||||
@@ -529,13 +538,13 @@ static void geopolyCcwFunc(
|
||||
if( p ){
|
||||
if( geopolyArea(p)<0.0 ){
|
||||
int ii, jj;
|
||||
for(ii=2, jj=p->nVertex*2 - 2; ii<jj; ii+=2, jj-=2){
|
||||
GeoCoord t = p->a[ii];
|
||||
p->a[ii] = p->a[jj];
|
||||
p->a[jj] = t;
|
||||
t = p->a[ii+1];
|
||||
p->a[ii+1] = p->a[jj+1];
|
||||
p->a[jj+1] = t;
|
||||
for(ii=1, jj=p->nVertex-1; ii<jj; ii++, jj--){
|
||||
GeoCoord t = GeoX(p,ii);
|
||||
GeoX(p,ii) = GeoX(p,jj);
|
||||
GeoX(p,jj) = t;
|
||||
t = GeoY(p,ii);
|
||||
GeoY(p,ii) = GeoY(p,jj);
|
||||
GeoY(p,jj) = t;
|
||||
}
|
||||
}
|
||||
sqlite3_result_blob(context, p->hdr,
|
||||
@@ -595,8 +604,8 @@ static void geopolyRegularFunc(
|
||||
p->hdr[3] = n&0xff;
|
||||
for(i=0; i<n; i++){
|
||||
double rAngle = 2.0*GEOPOLY_PI*i/n;
|
||||
p->a[i*2] = x - r*geopolySine(rAngle-0.5*GEOPOLY_PI);
|
||||
p->a[i*2+1] = y + r*geopolySine(rAngle);
|
||||
GeoX(p,i) = x - r*geopolySine(rAngle-0.5*GEOPOLY_PI);
|
||||
GeoY(p,i) = y + r*geopolySine(rAngle);
|
||||
}
|
||||
sqlite3_result_blob(context, p->hdr, 4+8*n, SQLITE_TRANSIENT);
|
||||
sqlite3_free(p);
|
||||
@@ -633,13 +642,13 @@ static GeoPoly *geopolyBBox(
|
||||
}
|
||||
if( p ){
|
||||
int ii;
|
||||
mnX = mxX = p->a[0];
|
||||
mnY = mxY = p->a[1];
|
||||
mnX = mxX = GeoX(p,0);
|
||||
mnY = mxY = GeoY(p,0);
|
||||
for(ii=1; ii<p->nVertex; ii++){
|
||||
double r = p->a[ii*2];
|
||||
double r = GeoX(p,ii);
|
||||
if( r<mnX ) mnX = (float)r;
|
||||
else if( r>mxX ) mxX = (float)r;
|
||||
r = p->a[ii*2+1];
|
||||
r = GeoY(p,ii);
|
||||
if( r<mnY ) mnY = (float)r;
|
||||
else if( r>mxY ) mxY = (float)r;
|
||||
}
|
||||
@@ -659,14 +668,14 @@ static GeoPoly *geopolyBBox(
|
||||
pOut->hdr[1] = 0;
|
||||
pOut->hdr[2] = 0;
|
||||
pOut->hdr[3] = 4;
|
||||
pOut->a[0] = mnX;
|
||||
pOut->a[1] = mnY;
|
||||
pOut->a[2] = mxX;
|
||||
pOut->a[3] = mnY;
|
||||
pOut->a[4] = mxX;
|
||||
pOut->a[5] = mxY;
|
||||
pOut->a[6] = mnX;
|
||||
pOut->a[7] = mxY;
|
||||
GeoX(pOut,0) = mnX;
|
||||
GeoY(pOut,0) = mnY;
|
||||
GeoX(pOut,1) = mxX;
|
||||
GeoY(pOut,1) = mnY;
|
||||
GeoX(pOut,2) = mxX;
|
||||
GeoY(pOut,2) = mxY;
|
||||
GeoX(pOut,3) = mnX;
|
||||
GeoY(pOut,3) = mxY;
|
||||
}else{
|
||||
sqlite3_free(p);
|
||||
aCoord[0].f = mnX;
|
||||
@@ -804,14 +813,14 @@ static void geopolyContainsPointFunc(
|
||||
int ii;
|
||||
if( p1==0 ) return;
|
||||
for(ii=0; ii<p1->nVertex-1; ii++){
|
||||
v = pointBeneathLine(x0,y0,p1->a[ii*2],p1->a[ii*2+1],
|
||||
p1->a[ii*2+2],p1->a[ii*2+3]);
|
||||
v = pointBeneathLine(x0,y0,GeoX(p1,ii), GeoY(p1,ii),
|
||||
GeoX(p1,ii+1),GeoY(p1,ii+1));
|
||||
if( v==2 ) break;
|
||||
cnt += v;
|
||||
}
|
||||
if( v!=2 ){
|
||||
v = pointBeneathLine(x0,y0,p1->a[ii*2],p1->a[ii*2+1],
|
||||
p1->a[0],p1->a[1]);
|
||||
v = pointBeneathLine(x0,y0,GeoX(p1,ii), GeoY(p1,ii),
|
||||
GeoX(p1,0), GeoY(p1,0));
|
||||
}
|
||||
if( v==2 ){
|
||||
sqlite3_result_int(context, 1);
|
||||
@@ -933,10 +942,10 @@ static void geopolyAddSegments(
|
||||
unsigned int i;
|
||||
GeoCoord *x;
|
||||
for(i=0; i<(unsigned)pPoly->nVertex-1; i++){
|
||||
x = pPoly->a + (i*2);
|
||||
x = &GeoX(pPoly,i);
|
||||
geopolyAddOneSegment(p, x[0], x[1], x[2], x[3], side, i);
|
||||
}
|
||||
x = pPoly->a + (i*2);
|
||||
x = &GeoX(pPoly,i);
|
||||
geopolyAddOneSegment(p, x[0], x[1], pPoly->a[0], pPoly->a[1], side, i);
|
||||
}
|
||||
|
||||
|
||||
+35
-39
@@ -611,7 +611,7 @@ static void nodeHashDelete(Rtree *pRtree, RtreeNode *pNode){
|
||||
*/
|
||||
static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){
|
||||
RtreeNode *pNode;
|
||||
pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode) + pRtree->iNodeSize);
|
||||
pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode) + pRtree->iNodeSize);
|
||||
if( pNode ){
|
||||
memset(pNode, 0, sizeof(RtreeNode) + pRtree->iNodeSize);
|
||||
pNode->zData = (u8 *)&pNode[1];
|
||||
@@ -704,7 +704,7 @@ static int nodeAcquire(
|
||||
RTREE_IS_CORRUPT(pRtree);
|
||||
}
|
||||
}else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
|
||||
pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize);
|
||||
pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize);
|
||||
if( !pNode ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -717,7 +717,6 @@ static int nodeAcquire(
|
||||
pNode->pNext = 0;
|
||||
rc = sqlite3_blob_read(pRtree->pNodeBlob, pNode->zData,
|
||||
pRtree->iNodeSize, 0);
|
||||
nodeReference(pParent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -748,6 +747,7 @@ static int nodeAcquire(
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
if( pNode!=0 ){
|
||||
nodeReference(pParent);
|
||||
nodeHashInsert(pRtree, pNode);
|
||||
}else{
|
||||
rc = SQLITE_CORRUPT_VTAB;
|
||||
@@ -1036,7 +1036,7 @@ static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
|
||||
Rtree *pRtree = (Rtree *)pVTab;
|
||||
RtreeCursor *pCsr;
|
||||
|
||||
pCsr = (RtreeCursor *)sqlite3_malloc(sizeof(RtreeCursor));
|
||||
pCsr = (RtreeCursor *)sqlite3_malloc64(sizeof(RtreeCursor));
|
||||
if( pCsr ){
|
||||
memset(pCsr, 0, sizeof(RtreeCursor));
|
||||
pCsr->base.pVtab = pVTab;
|
||||
@@ -1403,7 +1403,7 @@ static RtreeSearchPoint *rtreeEnqueue(
|
||||
RtreeSearchPoint *pNew;
|
||||
if( pCur->nPoint>=pCur->nPointAlloc ){
|
||||
int nNew = pCur->nPointAlloc*2 + 8;
|
||||
pNew = sqlite3_realloc(pCur->aPoint, nNew*sizeof(pCur->aPoint[0]));
|
||||
pNew = sqlite3_realloc64(pCur->aPoint, nNew*sizeof(pCur->aPoint[0]));
|
||||
if( pNew==0 ) return 0;
|
||||
pCur->aPoint = pNew;
|
||||
pCur->nPointAlloc = nNew;
|
||||
@@ -1805,7 +1805,7 @@ static int rtreeFilter(
|
||||
*/
|
||||
rc = nodeAcquire(pRtree, 1, 0, &pRoot);
|
||||
if( rc==SQLITE_OK && argc>0 ){
|
||||
pCsr->aConstraint = sqlite3_malloc(sizeof(RtreeConstraint)*argc);
|
||||
pCsr->aConstraint = sqlite3_malloc64(sizeof(RtreeConstraint)*argc);
|
||||
pCsr->nConstraint = argc;
|
||||
if( !pCsr->aConstraint ){
|
||||
rc = SQLITE_NOMEM;
|
||||
@@ -1999,11 +1999,11 @@ static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){
|
||||
#endif
|
||||
{
|
||||
switch( pRtree->nDim ){
|
||||
case 5: area = p->aCoord[9].i - p->aCoord[8].i;
|
||||
case 4: area *= p->aCoord[7].i - p->aCoord[6].i;
|
||||
case 3: area *= p->aCoord[5].i - p->aCoord[4].i;
|
||||
case 2: area *= p->aCoord[3].i - p->aCoord[2].i;
|
||||
default: area *= p->aCoord[1].i - p->aCoord[0].i;
|
||||
case 5: area = (i64)p->aCoord[9].i - (i64)p->aCoord[8].i;
|
||||
case 4: area *= (i64)p->aCoord[7].i - (i64)p->aCoord[6].i;
|
||||
case 3: area *= (i64)p->aCoord[5].i - (i64)p->aCoord[4].i;
|
||||
case 2: area *= (i64)p->aCoord[3].i - (i64)p->aCoord[2].i;
|
||||
default: area *= (i64)p->aCoord[1].i - (i64)p->aCoord[0].i;
|
||||
}
|
||||
}
|
||||
return area;
|
||||
@@ -2376,9 +2376,9 @@ static int splitNodeStartree(
|
||||
int iBestSplit = 0;
|
||||
RtreeDValue fBestMargin = RTREE_ZERO;
|
||||
|
||||
int nByte = (pRtree->nDim+1)*(sizeof(int*)+nCell*sizeof(int));
|
||||
sqlite3_int64 nByte = (pRtree->nDim+1)*(sizeof(int*)+nCell*sizeof(int));
|
||||
|
||||
aaSorted = (int **)sqlite3_malloc(nByte);
|
||||
aaSorted = (int **)sqlite3_malloc64(nByte);
|
||||
if( !aaSorted ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -2499,7 +2499,7 @@ static int SplitNode(
|
||||
/* Allocate an array and populate it with a copy of pCell and
|
||||
** all cells from node pLeft. Then zero the original node.
|
||||
*/
|
||||
aCell = sqlite3_malloc((sizeof(RtreeCell)+sizeof(int))*(nCell+1));
|
||||
aCell = sqlite3_malloc64((sizeof(RtreeCell)+sizeof(int))*(nCell+1));
|
||||
if( !aCell ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto splitnode_out;
|
||||
@@ -2790,7 +2790,7 @@ static int Reinsert(
|
||||
/* Allocate the buffers used by this operation. The allocation is
|
||||
** relinquished before this function returns.
|
||||
*/
|
||||
aCell = (RtreeCell *)sqlite3_malloc(n * (
|
||||
aCell = (RtreeCell *)sqlite3_malloc64(n * (
|
||||
sizeof(RtreeCell) + /* aCell array */
|
||||
sizeof(int) + /* aOrder array */
|
||||
sizeof(int) + /* aSpare array */
|
||||
@@ -3658,7 +3658,7 @@ static int rtreeInit(
|
||||
/* Allocate the sqlite3_vtab structure */
|
||||
nDb = (int)strlen(argv[1]);
|
||||
nName = (int)strlen(argv[2]);
|
||||
pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
|
||||
pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
|
||||
if( !pRtree ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -3755,49 +3755,45 @@ rtreeInit_fail:
|
||||
** <num-dimension>*2 coordinates.
|
||||
*/
|
||||
static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
|
||||
char *zText = 0;
|
||||
RtreeNode node;
|
||||
Rtree tree;
|
||||
int ii;
|
||||
int nData;
|
||||
int errCode;
|
||||
sqlite3_str *pOut;
|
||||
|
||||
UNUSED_PARAMETER(nArg);
|
||||
memset(&node, 0, sizeof(RtreeNode));
|
||||
memset(&tree, 0, sizeof(Rtree));
|
||||
tree.nDim = (u8)sqlite3_value_int(apArg[0]);
|
||||
if( tree.nDim<1 || tree.nDim>5 ) return;
|
||||
tree.nDim2 = tree.nDim*2;
|
||||
tree.nBytesPerCell = 8 + 8 * tree.nDim;
|
||||
node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
|
||||
nData = sqlite3_value_bytes(apArg[1]);
|
||||
if( nData<4 ) return;
|
||||
if( nData<NCELL(&node)*tree.nBytesPerCell ) return;
|
||||
|
||||
pOut = sqlite3_str_new(0);
|
||||
for(ii=0; ii<NCELL(&node); ii++){
|
||||
char zCell[512];
|
||||
int nCell = 0;
|
||||
RtreeCell cell;
|
||||
int jj;
|
||||
|
||||
nodeGetCell(&tree, &node, ii, &cell);
|
||||
sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
|
||||
nCell = (int)strlen(zCell);
|
||||
if( ii>0 ) sqlite3_str_append(pOut, " ", 1);
|
||||
sqlite3_str_appendf(pOut, "{%lld", cell.iRowid);
|
||||
for(jj=0; jj<tree.nDim2; jj++){
|
||||
#ifndef SQLITE_RTREE_INT_ONLY
|
||||
sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
|
||||
(double)cell.aCoord[jj].f);
|
||||
sqlite3_str_appendf(pOut, " %g", (double)cell.aCoord[jj].f);
|
||||
#else
|
||||
sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
|
||||
cell.aCoord[jj].i);
|
||||
sqlite3_str_appendf(pOut, " %d", cell.aCoord[jj].i);
|
||||
#endif
|
||||
nCell = (int)strlen(zCell);
|
||||
}
|
||||
|
||||
if( zText ){
|
||||
char *zTextNew = sqlite3_mprintf("%s {%s}", zText, zCell);
|
||||
sqlite3_free(zText);
|
||||
zText = zTextNew;
|
||||
}else{
|
||||
zText = sqlite3_mprintf("{%s}", zCell);
|
||||
}
|
||||
sqlite3_str_append(pOut, "}", 1);
|
||||
}
|
||||
|
||||
sqlite3_result_text(ctx, zText, -1, sqlite3_free);
|
||||
errCode = sqlite3_str_errcode(pOut);
|
||||
sqlite3_result_text(ctx, sqlite3_str_finish(pOut), -1, sqlite3_free);
|
||||
sqlite3_result_error_code(ctx, errCode);
|
||||
}
|
||||
|
||||
/* This routine implements an SQL function that returns the "depth" parameter
|
||||
@@ -3938,7 +3934,7 @@ static u8 *rtreeCheckGetNode(RtreeCheck *pCheck, i64 iNode, int *pnNode){
|
||||
if( sqlite3_step(pCheck->pGetNode)==SQLITE_ROW ){
|
||||
int nNode = sqlite3_column_bytes(pCheck->pGetNode, 0);
|
||||
const u8 *pNode = (const u8*)sqlite3_column_blob(pCheck->pGetNode, 0);
|
||||
pRet = sqlite3_malloc(nNode);
|
||||
pRet = sqlite3_malloc64(nNode);
|
||||
if( pRet==0 ){
|
||||
pCheck->rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -4371,12 +4367,12 @@ static void rtreeMatchArgFree(void *pArg){
|
||||
static void geomCallback(sqlite3_context *ctx, int nArg, sqlite3_value **aArg){
|
||||
RtreeGeomCallback *pGeomCtx = (RtreeGeomCallback *)sqlite3_user_data(ctx);
|
||||
RtreeMatchArg *pBlob;
|
||||
int nBlob;
|
||||
sqlite3_int64 nBlob;
|
||||
int memErr = 0;
|
||||
|
||||
nBlob = sizeof(RtreeMatchArg) + (nArg-1)*sizeof(RtreeDValue)
|
||||
+ nArg*sizeof(sqlite3_value*);
|
||||
pBlob = (RtreeMatchArg *)sqlite3_malloc(nBlob);
|
||||
pBlob = (RtreeMatchArg *)sqlite3_malloc64(nBlob);
|
||||
if( !pBlob ){
|
||||
sqlite3_result_error_nomem(ctx);
|
||||
}else{
|
||||
|
||||
@@ -647,5 +647,19 @@ do_execsql_test 16.130 {
|
||||
SELECT * FROM rt1 WHERE id IN (1, 2, 3, 4);
|
||||
} {1 1.0 2.0 aux1 2 2.0 3.0 aux2 3 3.0 4.0 aux3 4 4.0 5.0 aux4}
|
||||
|
||||
reset_db
|
||||
do_execsql_test 17.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING rtree(id, x1 PRIMARY KEY, x2, y1, y2);
|
||||
CREATE VIRTUAL TABLE t2 USING rtree(id, x1, x2, y1, y2 UNIQUE);
|
||||
}
|
||||
do_execsql_test 17.1 {
|
||||
REINDEX t1;
|
||||
REINDEX t2;
|
||||
} {}
|
||||
|
||||
do_execsql_test 17.2 {
|
||||
REINDEX;
|
||||
} {}
|
||||
|
||||
expand_all_sql db
|
||||
finish_test
|
||||
|
||||
@@ -15,6 +15,7 @@ if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname [info script]] .. .. test]
|
||||
}
|
||||
source $testdir/tester.tcl
|
||||
set testprefix rtree6
|
||||
|
||||
ifcapable {!rtree || rtree_int_only} {
|
||||
finish_test
|
||||
@@ -167,5 +168,14 @@ do_execsql_test rtree6-3.5 {
|
||||
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>1.1
|
||||
} {}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 4.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING rtree(id,x0,x1,y0,y1);
|
||||
}
|
||||
do_execsql_test 4.1 {
|
||||
DELETE FROM t1 WHERE x0>1 AND x1<2 OR y0<92;
|
||||
}
|
||||
|
||||
expand_all_sql db
|
||||
finish_test
|
||||
|
||||
@@ -42,7 +42,7 @@ static void usage(const char *argv0){
|
||||
*/
|
||||
static void readFile(const char *zFilename, int *pSz, void **ppBuf){
|
||||
FILE *f;
|
||||
int sz;
|
||||
sqlite3_int64 sz;
|
||||
void *pBuf;
|
||||
f = fopen(zFilename, "rb");
|
||||
if( f==0 ){
|
||||
@@ -50,22 +50,23 @@ static void readFile(const char *zFilename, int *pSz, void **ppBuf){
|
||||
exit(1);
|
||||
}
|
||||
fseek(f, 0, SEEK_END);
|
||||
sz = (int)ftell(f);
|
||||
sz = ftell(f);
|
||||
rewind(f);
|
||||
pBuf = sqlite3_malloc( sz ? sz : 1 );
|
||||
pBuf = sqlite3_malloc64( sz ? sz : 1 );
|
||||
if( pBuf==0 ){
|
||||
fprintf(stderr, "cannot allocate %d to hold content of \"%s\"\n",
|
||||
sz, zFilename);
|
||||
(int)sz, zFilename);
|
||||
exit(1);
|
||||
}
|
||||
if( sz>0 ){
|
||||
if( fread(pBuf, sz, 1, f)!=1 ){
|
||||
fprintf(stderr, "cannot read all %d bytes of \"%s\"\n", sz, zFilename);
|
||||
if( fread(pBuf, (size_t)sz, 1, f)!=1 ){
|
||||
fprintf(stderr, "cannot read all %d bytes of \"%s\"\n",
|
||||
(int)sz, zFilename);
|
||||
exit(1);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
*pSz = sz;
|
||||
*pSz = (int)sz;
|
||||
*ppBuf = pBuf;
|
||||
}
|
||||
|
||||
|
||||
+18
-20
@@ -141,7 +141,7 @@ static void usage(const char *argv0){
|
||||
*/
|
||||
static void fuzzReadFile(const char *zFilename, int *pSz, void **ppBuf){
|
||||
FILE *f;
|
||||
int sz;
|
||||
sqlite3_int64 sz;
|
||||
void *pBuf;
|
||||
f = fopen(zFilename, "rb");
|
||||
if( f==0 ){
|
||||
@@ -149,22 +149,23 @@ static void fuzzReadFile(const char *zFilename, int *pSz, void **ppBuf){
|
||||
exit(1);
|
||||
}
|
||||
fseek(f, 0, SEEK_END);
|
||||
sz = (int)ftell(f);
|
||||
sz = ftell(f);
|
||||
rewind(f);
|
||||
pBuf = sqlite3_malloc( sz ? sz : 1 );
|
||||
pBuf = sqlite3_malloc64( sz ? sz : 1 );
|
||||
if( pBuf==0 ){
|
||||
fprintf(stderr, "cannot allocate %d to hold content of \"%s\"\n",
|
||||
sz, zFilename);
|
||||
(int)sz, zFilename);
|
||||
exit(1);
|
||||
}
|
||||
if( sz>0 ){
|
||||
if( fread(pBuf, sz, 1, f)!=1 ){
|
||||
fprintf(stderr, "cannot read all %d bytes of \"%s\"\n", sz, zFilename);
|
||||
if( fread(pBuf, (size_t)sz, 1, f)!=1 ){
|
||||
fprintf(stderr, "cannot read all %d bytes of \"%s\"\n",
|
||||
(int)sz, zFilename);
|
||||
exit(1);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
*pSz = sz;
|
||||
*pSz = (int)sz;
|
||||
*ppBuf = pBuf;
|
||||
}
|
||||
|
||||
@@ -340,10 +341,10 @@ struct FuzzChange {
|
||||
/*
|
||||
** Allocate and return nByte bytes of zeroed memory.
|
||||
*/
|
||||
static void *fuzzMalloc(int nByte){
|
||||
void *pRet = sqlite3_malloc(nByte);
|
||||
static void *fuzzMalloc(sqlite3_int64 nByte){
|
||||
void *pRet = sqlite3_malloc64(nByte);
|
||||
if( pRet ){
|
||||
memset(pRet, 0, nByte);
|
||||
memset(pRet, 0, (size_t)nByte);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
@@ -384,7 +385,7 @@ static int fuzzGetVarint(u8 *p, int *pnVal){
|
||||
static int fuzzPutVarint(u8 *p, int nVal){
|
||||
assert( nVal>0 && nVal<2097152 );
|
||||
if( nVal<128 ){
|
||||
p[0] = nVal;
|
||||
p[0] = (u8)nVal;
|
||||
return 1;
|
||||
}
|
||||
if( nVal<16384 ){
|
||||
@@ -459,7 +460,7 @@ static int fuzzParseHeader(
|
||||
pGrp->aPK = p;
|
||||
p += pGrp->nCol;
|
||||
pGrp->zTab = (const char*)p;
|
||||
p = &p[strlen(p)+1];
|
||||
p = &p[strlen((const char*)p)+1];
|
||||
|
||||
if( p>=pEnd ){
|
||||
rc = fuzzCorrupt();
|
||||
@@ -631,7 +632,7 @@ static int fuzzParseChangeset(
|
||||
/* If the table-header was successfully parsed, add the new change-group
|
||||
** to the array and parse the associated changes. */
|
||||
if( rc==SQLITE_OK ){
|
||||
FuzzChangesetGroup **apNew = (FuzzChangesetGroup**)sqlite3_realloc(
|
||||
FuzzChangesetGroup **apNew = (FuzzChangesetGroup**)sqlite3_realloc64(
|
||||
pParse->apGroup, sizeof(FuzzChangesetGroup*)*(pParse->nGroup+1)
|
||||
);
|
||||
if( apNew==0 ){
|
||||
@@ -695,8 +696,6 @@ static int fuzzPrintRecord(FuzzChangesetGroup *pGrp, u8 **ppRec, int bPKOnly){
|
||||
case 0x03: /* text */
|
||||
case 0x04: { /* blob */
|
||||
int nTxt;
|
||||
int sz;
|
||||
int i;
|
||||
p += fuzzGetVarint(p, &nTxt);
|
||||
printf("%s%s", zPre, eType==0x03 ? "'" : "X'");
|
||||
for(i=0; i<nTxt; i++){
|
||||
@@ -859,7 +858,7 @@ static int fuzzSelectChange(FuzzChangeset *pParse, FuzzChange *pChange){
|
||||
case 0x03: /* text */
|
||||
case 0x04: { /* blob */
|
||||
int nByte = fuzzRandomInt(48);
|
||||
pChange->aSub[1] = nByte;
|
||||
pChange->aSub[1] = (u8)nByte;
|
||||
fuzzRandomBlob(nByte, &pChange->aSub[2]);
|
||||
if( pChange->aSub[0]==0x03 ){
|
||||
int i;
|
||||
@@ -1004,7 +1003,7 @@ static int fuzzCopyChange(
|
||||
}else if( p==pFuzz->pSub2 ){
|
||||
pCopy = pFuzz->pSub1;
|
||||
}else if( i==iUndef ){
|
||||
pCopy = "\0";
|
||||
pCopy = (u8*)"\0";
|
||||
}
|
||||
|
||||
if( pCopy[0]==0x00 && eNew!=eType && eType==SQLITE_UPDATE && iRec==0 ){
|
||||
@@ -1067,7 +1066,7 @@ static int fuzzCopyChange(
|
||||
for(i=0; i<pGrp->nCol; i++){
|
||||
int sz;
|
||||
u8 *pCopy = pCsr;
|
||||
if( pGrp->aPK[i] ) pCopy = "\0";
|
||||
if( pGrp->aPK[i] ) pCopy = (u8*)"\0";
|
||||
fuzzChangeSize(pCopy, &sz);
|
||||
memcpy(pOut, pCopy, sz);
|
||||
pOut += sz;
|
||||
@@ -1214,7 +1213,7 @@ int main(int argc, char **argv){
|
||||
fuzzPrintGroup(&changeset, changeset.apGroup[i]);
|
||||
}
|
||||
}else{
|
||||
pBuf = (u8*)fuzzMalloc(nChangeset*2 + 1024);
|
||||
pBuf = (u8*)fuzzMalloc((sqlite3_int64)nChangeset*2 + 1024);
|
||||
if( pBuf==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -1237,4 +1236,3 @@ int main(int argc, char **argv){
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -258,8 +258,7 @@ do_patchconcat_test 4.3.3 {
|
||||
INSERT INTO t2 VALUES('a', 'a', 'a', 'a');
|
||||
} {
|
||||
DELETE FROM t2 WHERE c = 'a';
|
||||
} {
|
||||
}
|
||||
} {}
|
||||
|
||||
# INSERT + UPDATE
|
||||
do_patchconcat_test 4.3.4 {
|
||||
|
||||
@@ -356,5 +356,3 @@ int main(int argc, char **argv){
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+60
-16
@@ -30,27 +30,71 @@ proc test_reset {} {
|
||||
sqlite3 db2 test.db2
|
||||
}
|
||||
|
||||
foreach {tn wo} {
|
||||
1 ""
|
||||
2 "WITHOUT ROWID"
|
||||
} {
|
||||
reset_db
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b) WITHOUT ROWID;
|
||||
do_execsql_test 1.$tn.0 "CREATE TABLE t1(a PRIMARY KEY, b) $wo ;"
|
||||
|
||||
do_iterator_test 1.$tn.1 t1 {
|
||||
INSERT INTO t1 VALUES('one', 'two');
|
||||
} {
|
||||
{INSERT t1 0 X. {} {t one t two}}
|
||||
}
|
||||
|
||||
do_iterator_test 1.$tn.2 t1 {
|
||||
UPDATE t1 SET b='three'
|
||||
} {
|
||||
{UPDATE t1 0 X. {t one t two} {{} {} t three}}
|
||||
}
|
||||
|
||||
do_iterator_test 1.$tn.3 t1 {
|
||||
REPLACE INTO t1 VALUES('one', 'four');
|
||||
} {
|
||||
{UPDATE t1 0 X. {t one t three} {{} {} t four}}
|
||||
}
|
||||
|
||||
do_iterator_test 1.$tn.4 t1 {
|
||||
DELETE FROM t1;
|
||||
} {
|
||||
{DELETE t1 0 X. {t one t four} {}}
|
||||
}
|
||||
}
|
||||
|
||||
do_iterator_test 1.1 t1 {
|
||||
INSERT INTO t1 VALUES('one', 'two');
|
||||
foreach {tn wo} {
|
||||
1 ""
|
||||
2 "WITHOUT ROWID"
|
||||
} {
|
||||
{INSERT t1 0 X. {} {t one t two}}
|
||||
}
|
||||
reset_db
|
||||
|
||||
do_iterator_test 1.2 t1 {
|
||||
UPDATE t1 SET b='three'
|
||||
} {
|
||||
{UPDATE t1 0 X. {t one t two} {{} {} t three}}
|
||||
}
|
||||
|
||||
do_iterator_test 1.3 t1 {
|
||||
DELETE FROM t1;
|
||||
} {
|
||||
{DELETE t1 0 X. {t one t three} {}}
|
||||
do_execsql_test 2.$tn.0 "CREATE TABLE t1(a INTEGER PRIMARY KEY, b) $wo ;"
|
||||
|
||||
do_iterator_test 1.1 t1 {
|
||||
INSERT INTO t1 VALUES(1, 'two');
|
||||
} {
|
||||
{INSERT t1 0 X. {} {i 1 t two}}
|
||||
}
|
||||
|
||||
do_iterator_test 2.$tn.2 t1 {
|
||||
UPDATE t1 SET b='three'
|
||||
} {
|
||||
{UPDATE t1 0 X. {i 1 t two} {{} {} t three}}
|
||||
}
|
||||
|
||||
do_iterator_test 2.$tn.3 t1 {
|
||||
REPLACE INTO t1 VALUES(1, 'four');
|
||||
} {
|
||||
{UPDATE t1 0 X. {i 1 t three} {{} {} t four}}
|
||||
}
|
||||
|
||||
do_iterator_test 2.$tn.4 t1 {
|
||||
DELETE FROM t1;
|
||||
} {
|
||||
{DELETE t1 0 X. {i 1 t four} {}}
|
||||
}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -363,7 +363,7 @@ static void sessionPutI64(u8 *aBuf, sqlite3_int64 i){
|
||||
static int sessionSerializeValue(
|
||||
u8 *aBuf, /* If non-NULL, write serialized value here */
|
||||
sqlite3_value *pValue, /* Value to serialize */
|
||||
int *pnWrite /* IN/OUT: Increment by bytes written */
|
||||
sqlite3_int64 *pnWrite /* IN/OUT: Increment by bytes written */
|
||||
){
|
||||
int nByte; /* Size of serialized value in bytes */
|
||||
|
||||
@@ -904,7 +904,7 @@ static int sessionGrowHash(int bPatchset, SessionTable *pTab){
|
||||
SessionChange **apNew;
|
||||
int nNew = (pTab->nChange ? pTab->nChange : 128) * 2;
|
||||
|
||||
apNew = (SessionChange **)sqlite3_malloc(sizeof(SessionChange *) * nNew);
|
||||
apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew);
|
||||
if( apNew==0 ){
|
||||
if( pTab->nChange==0 ){
|
||||
return SQLITE_ERROR;
|
||||
@@ -970,7 +970,7 @@ static int sessionTableInfo(
|
||||
char *zPragma;
|
||||
sqlite3_stmt *pStmt;
|
||||
int rc;
|
||||
int nByte;
|
||||
sqlite3_int64 nByte;
|
||||
int nDbCol = 0;
|
||||
int nThis;
|
||||
int i;
|
||||
@@ -1013,7 +1013,7 @@ static int sessionTableInfo(
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
nByte += nDbCol * (sizeof(const char *) + sizeof(u8) + 1);
|
||||
pAlloc = sqlite3_malloc(nByte);
|
||||
pAlloc = sqlite3_malloc64(nByte);
|
||||
if( pAlloc==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
@@ -1211,7 +1211,7 @@ static void sessionPreupdateOneChange(
|
||||
** this is an SQLITE_UPDATE or SQLITE_DELETE), or just the PK
|
||||
** values (if this is an INSERT). */
|
||||
SessionChange *pChange; /* New change object */
|
||||
int nByte; /* Number of bytes to allocate */
|
||||
sqlite3_int64 nByte; /* Number of bytes to allocate */
|
||||
int i; /* Used to iterate through columns */
|
||||
|
||||
assert( rc==SQLITE_OK );
|
||||
@@ -1236,7 +1236,7 @@ static void sessionPreupdateOneChange(
|
||||
}
|
||||
|
||||
/* Allocate the change object */
|
||||
pChange = (SessionChange *)sqlite3_malloc(nByte);
|
||||
pChange = (SessionChange *)sqlite3_malloc64(nByte);
|
||||
if( !pChange ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto error_out;
|
||||
@@ -1680,7 +1680,7 @@ int sqlite3session_create(
|
||||
*ppSession = 0;
|
||||
|
||||
/* Allocate and populate the new session object. */
|
||||
pNew = (sqlite3_session *)sqlite3_malloc(sizeof(sqlite3_session) + nDb + 1);
|
||||
pNew = (sqlite3_session *)sqlite3_malloc64(sizeof(sqlite3_session) + nDb + 1);
|
||||
if( !pNew ) return SQLITE_NOMEM;
|
||||
memset(pNew, 0, sizeof(sqlite3_session));
|
||||
pNew->db = db;
|
||||
@@ -1799,7 +1799,7 @@ int sqlite3session_attach(
|
||||
|
||||
if( !pTab ){
|
||||
/* Allocate new SessionTable object. */
|
||||
pTab = (SessionTable *)sqlite3_malloc(sizeof(SessionTable) + nName + 1);
|
||||
pTab = (SessionTable *)sqlite3_malloc64(sizeof(SessionTable) + nName + 1);
|
||||
if( !pTab ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -1859,7 +1859,7 @@ static int sessionBufferGrow(SessionBuffer *p, int nByte, int *pRc){
|
||||
static void sessionAppendValue(SessionBuffer *p, sqlite3_value *pVal, int *pRc){
|
||||
int rc = *pRc;
|
||||
if( rc==SQLITE_OK ){
|
||||
int nByte = 0;
|
||||
sqlite3_int64 nByte = 0;
|
||||
rc = sessionSerializeValue(0, pVal, &nByte);
|
||||
sessionBufferGrow(p, nByte, &rc);
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -2735,7 +2735,7 @@ static int sessionValueSetStr(
|
||||
** argument to sqlite3ValueSetStr() and have the copy created
|
||||
** automatically. But doing so makes it difficult to detect any OOM
|
||||
** error. Hence the code to create the copy externally. */
|
||||
u8 *aCopy = sqlite3_malloc(nData+1);
|
||||
u8 *aCopy = sqlite3_malloc64((sqlite3_int64)nData+1);
|
||||
if( aCopy==0 ) return SQLITE_NOMEM;
|
||||
memcpy(aCopy, aData, nData);
|
||||
sqlite3ValueSetStr(pVal, nData, (char*)aCopy, enc, sqlite3_free);
|
||||
@@ -3348,7 +3348,7 @@ static int sessionChangesetInvert(
|
||||
int iCol;
|
||||
|
||||
if( 0==apVal ){
|
||||
apVal = (sqlite3_value **)sqlite3_malloc(sizeof(apVal[0])*nCol*2);
|
||||
apVal = (sqlite3_value **)sqlite3_malloc64(sizeof(apVal[0])*nCol*2);
|
||||
if( 0==apVal ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto finished_invert;
|
||||
@@ -3862,7 +3862,7 @@ static int sessionSeekToRow(
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is called from within sqlite3changset_apply_v2() when
|
||||
** This function is called from within sqlite3changeset_apply_v2() when
|
||||
** a conflict is encountered and resolved using conflict resolution
|
||||
** mode eType (either SQLITE_CHANGESET_OMIT or SQLITE_CHANGESET_REPLACE)..
|
||||
** It adds a conflict resolution record to the buffer in
|
||||
@@ -4621,7 +4621,7 @@ static int sessionChangeMerge(
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
if( !pExist ){
|
||||
pNew = (SessionChange *)sqlite3_malloc(sizeof(SessionChange) + nRec);
|
||||
pNew = (SessionChange *)sqlite3_malloc64(sizeof(SessionChange) + nRec);
|
||||
if( !pNew ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -4654,8 +4654,8 @@ static int sessionChangeMerge(
|
||||
if( pExist->op==SQLITE_DELETE && pExist->bIndirect ){
|
||||
*ppNew = pExist;
|
||||
}else{
|
||||
int nByte = nRec + pExist->nRecord + sizeof(SessionChange);
|
||||
pNew = (SessionChange*)sqlite3_malloc(nByte);
|
||||
sqlite3_int64 nByte = nRec + pExist->nRecord + sizeof(SessionChange);
|
||||
pNew = (SessionChange*)sqlite3_malloc64(nByte);
|
||||
if( pNew==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -4715,14 +4715,14 @@ static int sessionChangeMerge(
|
||||
assert( pNew==0 );
|
||||
}else{
|
||||
u8 *aExist = pExist->aRecord;
|
||||
int nByte;
|
||||
sqlite3_int64 nByte;
|
||||
u8 *aCsr;
|
||||
|
||||
/* Allocate a new SessionChange object. Ensure that the aRecord[]
|
||||
** buffer of the new object is large enough to hold any record that
|
||||
** may be generated by combining the input records. */
|
||||
nByte = sizeof(SessionChange) + pExist->nRecord + nRec;
|
||||
pNew = (SessionChange *)sqlite3_malloc(nByte);
|
||||
pNew = (SessionChange *)sqlite3_malloc64(nByte);
|
||||
if( !pNew ){
|
||||
sqlite3_free(pExist);
|
||||
return SQLITE_NOMEM;
|
||||
@@ -4828,7 +4828,7 @@ static int sessionChangesetToHash(
|
||||
if( !pTab ){
|
||||
SessionTable **ppTab;
|
||||
|
||||
pTab = sqlite3_malloc(sizeof(SessionTable) + nCol + nNew+1);
|
||||
pTab = sqlite3_malloc64(sizeof(SessionTable) + nCol + nNew+1);
|
||||
if( !pTab ){
|
||||
rc = SQLITE_NOMEM;
|
||||
break;
|
||||
|
||||
@@ -1415,7 +1415,7 @@ int sqlite3rebaser_configure(
|
||||
** in size. This function allocates and populates a buffer with a copy
|
||||
** of the changeset rebased rebased according to the configuration of the
|
||||
** rebaser object passed as the first argument. If successful, (*ppOut)
|
||||
** is set to point to the new buffer containing the rebased changset and
|
||||
** is set to point to the new buffer containing the rebased changeset and
|
||||
** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
|
||||
** responsibility of the caller to eventually free the new buffer using
|
||||
** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
|
||||
|
||||
@@ -348,6 +348,7 @@ TESTSRC = \
|
||||
$(TOP)/src/test_tclsh.c \
|
||||
$(TOP)/src/test_tclvar.c \
|
||||
$(TOP)/src/test_thread.c \
|
||||
$(TOP)/src/test_vdbecov.c \
|
||||
$(TOP)/src/test_vfs.c \
|
||||
$(TOP)/src/test_windirent.c \
|
||||
$(TOP)/src/test_window.c \
|
||||
@@ -369,6 +370,7 @@ TESTSRC += \
|
||||
$(TOP)/ext/misc/nextchar.c \
|
||||
$(TOP)/ext/misc/normalize.c \
|
||||
$(TOP)/ext/misc/percentile.c \
|
||||
$(TOP)/ext/misc/prefixes.c \
|
||||
$(TOP)/ext/misc/regexp.c \
|
||||
$(TOP)/ext/misc/remember.c \
|
||||
$(TOP)/ext/misc/series.c \
|
||||
@@ -376,7 +378,6 @@ TESTSRC += \
|
||||
$(TOP)/ext/misc/totype.c \
|
||||
$(TOP)/ext/misc/unionvtab.c \
|
||||
$(TOP)/ext/misc/wholenumber.c \
|
||||
$(TOP)/ext/misc/vfslog.c \
|
||||
$(TOP)/ext/misc/zipfile.c \
|
||||
$(TOP)/ext/fts5/fts5_tcl.c \
|
||||
$(TOP)/ext/fts5/fts5_test_mi.c \
|
||||
@@ -509,7 +510,8 @@ FUZZDATA = \
|
||||
$(TOP)/test/fuzzdata4.db \
|
||||
$(TOP)/test/fuzzdata5.db \
|
||||
$(TOP)/test/fuzzdata6.db \
|
||||
$(TOP)/test/fuzzdata7.db
|
||||
$(TOP)/test/fuzzdata7.db \
|
||||
$(TOP)/test/fuzzdata8.db
|
||||
|
||||
# Standard options to testfixture
|
||||
#
|
||||
@@ -530,6 +532,11 @@ FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
|
||||
FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5
|
||||
FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
|
||||
FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_DESERIALIZE
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
DBFUZZ_OPT =
|
||||
KV_OPT = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ
|
||||
ST_OPT = -DSQLITE_THREADSAFE=0
|
||||
@@ -574,6 +581,20 @@ dbfuzz$(EXE): $(TOP)/test/dbfuzz.c sqlite3.c sqlite3.h
|
||||
$(DBFUZZ_OPT) $(TOP)/test/dbfuzz.c sqlite3.c \
|
||||
$(TLIBS) $(THREADLIB)
|
||||
|
||||
DBFUZZ2_OPTS = \
|
||||
-DSQLITE_THREADSAFE=0 \
|
||||
-DSQLITE_OMIT_LOAD_EXTENSION \
|
||||
-DSQLITE_ENABLE_DESERIALIZE \
|
||||
-DSQLITE_DEBUG \
|
||||
-DSQLITE_ENABLE_DBSTAT_VTAB \
|
||||
-DSQLITE_ENABLE_RTREE \
|
||||
-DSQLITE_ENABLE_FTS4 \
|
||||
-DSQLITE_ENABLE_FTS5
|
||||
|
||||
dbfuzz2$(EXE): $(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
|
||||
$(TCCX) -I. -g -O0 -DSTANDALONE -o dbfuzz2$(EXE) \
|
||||
$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS) $(THREADLIB)
|
||||
|
||||
fuzzcheck$(EXE): $(TOP)/test/fuzzcheck.c sqlite3.c sqlite3.h $(TOP)/test/ossfuzz.c
|
||||
$(TCCX) -o fuzzcheck$(EXE) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
|
||||
-DSQLITE_ENABLE_MEMSYS5 $(FUZZCHECK_OPT) -DSQLITE_OSS_FUZZ \
|
||||
@@ -694,12 +715,9 @@ opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/tool/mkopcodeh.tcl
|
||||
#
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon $(TOP)/tool/addopcodes.tcl
|
||||
parse.c: $(TOP)/src/parse.y lemon
|
||||
cp $(TOP)/src/parse.y .
|
||||
rm -f parse.h
|
||||
./lemon -s $(OPTS) parse.y
|
||||
mv parse.h parse.h.temp
|
||||
tclsh $(TOP)/tool/addopcodes.tcl parse.h.temp >parse.h
|
||||
|
||||
sqlite3.h: $(TOP)/src/sqlite.h.in $(TOP)/manifest mksourceid $(TOP)/VERSION $(TOP)/ext/rtree/sqlite3rtree.h
|
||||
tclsh $(TOP)/tool/mksqlite3h.tcl $(TOP) >sqlite3.h
|
||||
@@ -719,6 +737,7 @@ SHELL_SRC = \
|
||||
$(TOP)/ext/expert/sqlite3expert.c \
|
||||
$(TOP)/ext/expert/sqlite3expert.h \
|
||||
$(TOP)/ext/misc/zipfile.c \
|
||||
$(TOP)/ext/misc/memtrace.c \
|
||||
$(TOP)/src/test_windirent.c
|
||||
|
||||
shell.c: $(SHELL_SRC) $(TOP)/tool/mkshellc.tcl
|
||||
@@ -999,7 +1018,7 @@ showshm$(EXE): $(TOP)/tool/showshm.c
|
||||
$(TCC) -o showshm$(EXE) $(TOP)/tool/showshm.c
|
||||
|
||||
index_usage$(EXE): $(TOP)/tool/index_usage.c sqlite3.o
|
||||
$(TCC) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_DEPRECATED -o index_usage$(EXE) \
|
||||
$(TCC) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_DEPRECATED $(SHELL_OPTS) -o index_usage$(EXE) \
|
||||
$(TOP)/tool/index_usage.c sqlite3.o $(THREADLIB)
|
||||
|
||||
changeset$(EXE): $(TOP)/ext/session/changeset.c sqlite3.o
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
a874c649960ba2e2b2fd380d08c02a45884a1060d3922be8847729008ca6766e
|
||||
f5b3ce9404ffc8afdab6d8e57f806afba0b3ee75520d5e03335335d0f93d4a4b
|
||||
+15
-8
@@ -166,15 +166,15 @@ void sqlite3AlterRenameTable(
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Begin a transaction for database iDb.
|
||||
** Then modify the schema cookie (since the ALTER TABLE modifies the
|
||||
** schema). Open a statement transaction if the table is a virtual
|
||||
** table.
|
||||
*/
|
||||
/* Begin a transaction for database iDb. Then modify the schema cookie
|
||||
** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
|
||||
** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
|
||||
** nested SQL may raise an exception. */
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ){
|
||||
goto exit_rename_table;
|
||||
}
|
||||
sqlite3MayAbort(pParse);
|
||||
|
||||
/* figure out how many UTF-8 characters are in zName */
|
||||
zTabName = pTab->zName;
|
||||
@@ -243,7 +243,6 @@ void sqlite3AlterRenameTable(
|
||||
int i = ++pParse->nMem;
|
||||
sqlite3VdbeLoadString(v, i, zName);
|
||||
sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
|
||||
sqlite3MayAbort(pParse);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -564,6 +563,7 @@ void sqlite3AlterRenameColumn(
|
||||
** uses the sqlite_rename_column() SQL function to compute the new
|
||||
** CREATE statement text for the sqlite_master table.
|
||||
*/
|
||||
sqlite3MayAbort(pParse);
|
||||
zNew = sqlite3NameFromToken(db, pNew);
|
||||
if( !zNew ) goto exit_rename_column;
|
||||
assert( pNew->n>0 );
|
||||
@@ -961,7 +961,6 @@ static int renameParseSql(
|
||||
rc = sqlite3RunParser(p, zSql, &zErr);
|
||||
assert( p->zErrMsg==0 );
|
||||
assert( rc!=SQLITE_OK || zErr==0 );
|
||||
assert( (0!=p->pNewTable) + (0!=p->pNewIndex) + (0!=p->pNewTrigger)<2 );
|
||||
p->zErrMsg = zErr;
|
||||
if( db->mallocFailed ) rc = SQLITE_NOMEM;
|
||||
if( rc==SQLITE_OK
|
||||
@@ -1144,6 +1143,7 @@ static int renameResolveTrigger(Parse *pParse, const char *zDb){
|
||||
}
|
||||
sNC.ncFlags = 0;
|
||||
}
|
||||
sNC.pSrcList = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1181,11 +1181,15 @@ static void renameWalkTrigger(Walker *pWalker, Trigger *pTrigger){
|
||||
*/
|
||||
static void renameParseCleanup(Parse *pParse){
|
||||
sqlite3 *db = pParse->db;
|
||||
Index *pIdx;
|
||||
if( pParse->pVdbe ){
|
||||
sqlite3VdbeFinalize(pParse->pVdbe);
|
||||
}
|
||||
sqlite3DeleteTable(db, pParse->pNewTable);
|
||||
if( pParse->pNewIndex ) sqlite3FreeIndex(db, pParse->pNewIndex);
|
||||
while( (pIdx = pParse->pNewIndex)!=0 ){
|
||||
pParse->pNewIndex = pIdx->pNext;
|
||||
sqlite3FreeIndex(db, pIdx);
|
||||
}
|
||||
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
|
||||
sqlite3DbFree(db, pParse->zErrMsg);
|
||||
renameTokenFree(db, pParse->pRename);
|
||||
@@ -1296,6 +1300,9 @@ static void renameColumnFunc(
|
||||
for(pIdx=sParse.pNewTable->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
|
||||
}
|
||||
for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){
|
||||
sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
|
||||
}
|
||||
}
|
||||
|
||||
for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){
|
||||
|
||||
+12
-7
@@ -155,8 +155,8 @@ static void attachFunc(
|
||||
assert( pVfs );
|
||||
flags |= SQLITE_OPEN_MAIN_DB;
|
||||
rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags);
|
||||
sqlite3_free( zPath );
|
||||
db->nDb++;
|
||||
pNew->zDbSName = sqlite3DbStrDup(db, zName);
|
||||
}
|
||||
db->noSharedCache = 0;
|
||||
if( rc==SQLITE_CONSTRAINT ){
|
||||
@@ -184,7 +184,6 @@ static void attachFunc(
|
||||
sqlite3BtreeLeave(pNew->pBt);
|
||||
}
|
||||
pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
|
||||
if( !REOPEN_AS_MEMDB(db) ) pNew->zDbSName = sqlite3DbStrDup(db, zName);
|
||||
if( rc==SQLITE_OK && pNew->zDbSName==0 ){
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
@@ -212,15 +211,19 @@ static void attachFunc(
|
||||
break;
|
||||
|
||||
case SQLITE_NULL:
|
||||
/* No key specified. Use the key from the main database */
|
||||
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
|
||||
if( nKey || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
|
||||
rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
/* No key specified. Use the key from URI filename, or if none,
|
||||
** use the key from the main database. */
|
||||
if( sqlite3CodecQueryParameters(db, zName, zPath)==0 ){
|
||||
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
|
||||
if( nKey || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
|
||||
rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
sqlite3_free( zPath );
|
||||
|
||||
/* If the file was opened successfully, read the schema for the new database.
|
||||
** If this fails, or if opening the file failed, then close the file and
|
||||
@@ -231,7 +234,9 @@ static void attachFunc(
|
||||
sqlite3BtreeEnterAll(db);
|
||||
db->init.iDb = 0;
|
||||
db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
|
||||
rc = sqlite3Init(db, &zErrDyn);
|
||||
if( !REOPEN_AS_MEMDB(db) ){
|
||||
rc = sqlite3Init(db, &zErrDyn);
|
||||
}
|
||||
sqlite3BtreeLeaveAll(db);
|
||||
assert( zErrDyn==0 || rc!=SQLITE_OK );
|
||||
}
|
||||
|
||||
+465
-247
File diff suppressed because it is too large
Load Diff
+1
-3
@@ -301,9 +301,6 @@ struct BtreePayload {
|
||||
int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
|
||||
int flags, int seekResult);
|
||||
int sqlite3BtreeFirst(BtCursor*, int *pRes);
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
void sqlite3BtreeSkipNext(BtCursor*);
|
||||
#endif
|
||||
int sqlite3BtreeLast(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeNext(BtCursor*, int flags);
|
||||
int sqlite3BtreeEof(BtCursor*);
|
||||
@@ -315,6 +312,7 @@ i64 sqlite3BtreeOffset(BtCursor*);
|
||||
int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
|
||||
const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
|
||||
u32 sqlite3BtreePayloadSize(BtCursor*);
|
||||
sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
|
||||
|
||||
char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
|
||||
struct Pager *sqlite3BtreePager(Btree*);
|
||||
|
||||
+11
-4
@@ -286,7 +286,7 @@ struct MemPage {
|
||||
u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
|
||||
u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
|
||||
u16 cellOffset; /* Index in aData of first cell pointer */
|
||||
u16 nFree; /* Number of free bytes on the page */
|
||||
int nFree; /* Number of free bytes on the page. -1 for unknown */
|
||||
u16 nCell; /* Number of cells on this page, local and ovfl */
|
||||
u16 maskPage; /* Mask for page offset */
|
||||
u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th
|
||||
@@ -494,9 +494,16 @@ struct CellInfo {
|
||||
** found at self->pBt->mutex.
|
||||
**
|
||||
** skipNext meaning:
|
||||
** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
|
||||
** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
|
||||
** eState==FAULT: Cursor fault with skipNext as error code.
|
||||
** The meaning of skipNext depends on the value of eState:
|
||||
**
|
||||
** eState Meaning of skipNext
|
||||
** VALID skipNext is meaningless and is ignored
|
||||
** INVALID skipNext is meaningless and is ignored
|
||||
** SKIPNEXT sqlite3BtreeNext() is a no-op if skipNext>0 and
|
||||
** sqlite3BtreePrevious() is no-op if skipNext<0.
|
||||
** REQUIRESEEK restoreCursorPosition() restores the cursor to
|
||||
** eState=SKIPNEXT if skipNext!=0
|
||||
** FAULT skipNext holds the cursor fault error code.
|
||||
*/
|
||||
struct BtCursor {
|
||||
u8 eState; /* One of the CURSOR_XXX constants (see below) */
|
||||
|
||||
+82
-30
@@ -260,7 +260,12 @@ void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
|
||||
zSql = sqlite3VMPrintf(db, zFormat, ap);
|
||||
va_end(ap);
|
||||
if( zSql==0 ){
|
||||
return; /* A malloc must have failed */
|
||||
/* This can result either from an OOM or because the formatted string
|
||||
** exceeds SQLITE_LIMIT_LENGTH. In the latter case, we need to set
|
||||
** an error */
|
||||
if( !db->mallocFailed ) pParse->rc = SQLITE_TOOBIG;
|
||||
pParse->nErr++;
|
||||
return;
|
||||
}
|
||||
pParse->nested++;
|
||||
memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
|
||||
@@ -1400,7 +1405,8 @@ void sqlite3AddPrimaryKey(
|
||||
&& sortOrder!=SQLITE_SO_DESC
|
||||
){
|
||||
if( IN_RENAME_OBJECT && pList ){
|
||||
sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pList->a[0].pExpr);
|
||||
Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
|
||||
sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
|
||||
}
|
||||
pTab->iPKey = iCol;
|
||||
pTab->keyConf = (u8)onError;
|
||||
@@ -1821,6 +1827,7 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
pTab->iPKey = -1;
|
||||
}else{
|
||||
pPk = sqlite3PrimaryKeyIndex(pTab);
|
||||
assert( pPk!=0 );
|
||||
|
||||
/*
|
||||
** Remove all redundant columns from the PRIMARY KEY. For example, change
|
||||
@@ -1990,6 +1997,11 @@ void sqlite3EndTable(
|
||||
if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
|
||||
}
|
||||
|
||||
assert( (p->tabFlags & TF_HasPrimaryKey)==0
|
||||
|| p->iPKey>=0 || sqlite3PrimaryKeyIndex(p)!=0 );
|
||||
assert( (p->tabFlags & TF_HasPrimaryKey)!=0
|
||||
|| (p->iPKey<0 && sqlite3PrimaryKeyIndex(p)==0) );
|
||||
|
||||
/* Special processing for WITHOUT ROWID Tables */
|
||||
if( tabOpts & TF_WithoutRowid ){
|
||||
if( (p->tabFlags & TF_Autoincrement) ){
|
||||
@@ -3143,13 +3155,13 @@ void sqlite3CreateIndex(
|
||||
assert( pParse->nErr==0 );
|
||||
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
|
||||
&& db->init.busy==0
|
||||
&& pTblName!=0
|
||||
#if SQLITE_USER_AUTHENTICATION
|
||||
&& sqlite3UserAuthTable(pTab->zName)==0
|
||||
#endif
|
||||
#ifdef SQLITE_ALLOW_SQLITE_MASTER_INDEX
|
||||
&& sqlite3StrICmp(&pTab->zName[7],"master")!=0
|
||||
#endif
|
||||
&& sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0
|
||||
){
|
||||
sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
|
||||
goto exit_create_index;
|
||||
@@ -3253,6 +3265,7 @@ void sqlite3CreateIndex(
|
||||
sqlite3ExprListSetSortOrder(pList, sortOrder);
|
||||
}else{
|
||||
sqlite3ExprListCheckLength(pParse, pList, "index");
|
||||
if( pParse->nErr ) goto exit_create_index;
|
||||
}
|
||||
|
||||
/* Figure out how many bytes of space are required to store explicitly
|
||||
@@ -3271,6 +3284,7 @@ void sqlite3CreateIndex(
|
||||
*/
|
||||
nName = sqlite3Strlen30(zName);
|
||||
nExtraCol = pPk ? pPk->nKeyCol : 1;
|
||||
assert( pList->nExpr + nExtraCol <= 32767 /* Fits in i16 */ );
|
||||
pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
|
||||
nName + nExtra + 1, &zExtra);
|
||||
if( db->mallocFailed ){
|
||||
@@ -3467,6 +3481,11 @@ void sqlite3CreateIndex(
|
||||
}
|
||||
}
|
||||
if( idxType==SQLITE_IDXTYPE_PRIMARYKEY ) pIdx->idxType = idxType;
|
||||
if( IN_RENAME_OBJECT ){
|
||||
pIndex->pNext = pParse->pNewIndex;
|
||||
pParse->pNewIndex = pIndex;
|
||||
pIndex = 0;
|
||||
}
|
||||
goto exit_create_index;
|
||||
}
|
||||
}
|
||||
@@ -3482,6 +3501,14 @@ void sqlite3CreateIndex(
|
||||
Index *p;
|
||||
assert( !IN_SPECIAL_PARSE );
|
||||
assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
|
||||
if( pTblName!=0 ){
|
||||
pIndex->tnum = db->init.newTnum;
|
||||
if( sqlite3IndexHasDuplicateRootPage(pIndex) ){
|
||||
sqlite3ErrorMsg(pParse, "invalid rootpage");
|
||||
pParse->rc = SQLITE_CORRUPT_BKPT;
|
||||
goto exit_create_index;
|
||||
}
|
||||
}
|
||||
p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
|
||||
pIndex->zName, pIndex);
|
||||
if( p ){
|
||||
@@ -3490,9 +3517,6 @@ void sqlite3CreateIndex(
|
||||
goto exit_create_index;
|
||||
}
|
||||
db->mDbFlags |= DBFLAG_SchemaChange;
|
||||
if( pTblName!=0 ){
|
||||
pIndex->tnum = db->init.newTnum;
|
||||
}
|
||||
}
|
||||
|
||||
/* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
|
||||
@@ -3818,6 +3842,18 @@ int sqlite3IdListIndex(IdList *pList, const char *zName){
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Maximum size of a SrcList object.
|
||||
** The SrcList object is used to represent the FROM clause of a
|
||||
** SELECT statement, and the query planner cannot deal with more
|
||||
** than 64 tables in a join. So any value larger than 64 here
|
||||
** is sufficient for most uses. Smaller values, like say 10, are
|
||||
** appropriate for small and memory-limited applications.
|
||||
*/
|
||||
#ifndef SQLITE_MAX_SRCLIST
|
||||
# define SQLITE_MAX_SRCLIST 200
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Expand the space allocated for the given SrcList object by
|
||||
** creating nExtra new slots beginning at iStart. iStart is zero based.
|
||||
@@ -3834,11 +3870,12 @@ int sqlite3IdListIndex(IdList *pList, const char *zName){
|
||||
** the iStart value would be 0. The result then would
|
||||
** be: nil, nil, nil, A, B.
|
||||
**
|
||||
** If a memory allocation fails the SrcList is unchanged. The
|
||||
** db->mallocFailed flag will be set to true.
|
||||
** If a memory allocation fails or the SrcList becomes too large, leave
|
||||
** the original SrcList unchanged, return NULL, and leave an error message
|
||||
** in pParse.
|
||||
*/
|
||||
SrcList *sqlite3SrcListEnlarge(
|
||||
sqlite3 *db, /* Database connection to notify of OOM errors */
|
||||
Parse *pParse, /* Parsing context into which errors are reported */
|
||||
SrcList *pSrc, /* The SrcList to be enlarged */
|
||||
int nExtra, /* Number of new slots to add to pSrc->a[] */
|
||||
int iStart /* Index in pSrc->a[] of first new slot */
|
||||
@@ -3855,16 +3892,22 @@ SrcList *sqlite3SrcListEnlarge(
|
||||
if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
|
||||
SrcList *pNew;
|
||||
int nAlloc = pSrc->nSrc*2+nExtra;
|
||||
int nGot;
|
||||
sqlite3 *db = pParse->db;
|
||||
|
||||
if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
|
||||
sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
|
||||
SQLITE_MAX_SRCLIST);
|
||||
return 0;
|
||||
}
|
||||
if( nAlloc>SQLITE_MAX_SRCLIST ) nAlloc = SQLITE_MAX_SRCLIST;
|
||||
pNew = sqlite3DbRealloc(db, pSrc,
|
||||
sizeof(*pSrc) + (nAlloc-1)*sizeof(pSrc->a[0]) );
|
||||
if( pNew==0 ){
|
||||
assert( db->mallocFailed );
|
||||
return pSrc;
|
||||
return 0;
|
||||
}
|
||||
pSrc = pNew;
|
||||
nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
|
||||
pSrc->nAlloc = nGot;
|
||||
pSrc->nAlloc = nAlloc;
|
||||
}
|
||||
|
||||
/* Move existing slots that come after the newly inserted slots
|
||||
@@ -3889,7 +3932,8 @@ SrcList *sqlite3SrcListEnlarge(
|
||||
** Append a new table name to the given SrcList. Create a new SrcList if
|
||||
** need be. A new entry is created in the SrcList even if pTable is NULL.
|
||||
**
|
||||
** A SrcList is returned, or NULL if there is an OOM error. The returned
|
||||
** A SrcList is returned, or NULL if there is an OOM error or if the
|
||||
** SrcList grows to large. The returned
|
||||
** SrcList might be the same as the SrcList that was input or it might be
|
||||
** a new one. If an OOM error does occurs, then the prior value of pList
|
||||
** that is input to this routine is automatically freed.
|
||||
@@ -3920,27 +3964,32 @@ SrcList *sqlite3SrcListEnlarge(
|
||||
** before being added to the SrcList.
|
||||
*/
|
||||
SrcList *sqlite3SrcListAppend(
|
||||
sqlite3 *db, /* Connection to notify of malloc failures */
|
||||
Parse *pParse, /* Parsing context, in which errors are reported */
|
||||
SrcList *pList, /* Append to this SrcList. NULL creates a new SrcList */
|
||||
Token *pTable, /* Table to append */
|
||||
Token *pDatabase /* Database of the table */
|
||||
){
|
||||
struct SrcList_item *pItem;
|
||||
sqlite3 *db;
|
||||
assert( pDatabase==0 || pTable!=0 ); /* Cannot have C without B */
|
||||
assert( db!=0 );
|
||||
assert( pParse!=0 );
|
||||
assert( pParse->db!=0 );
|
||||
db = pParse->db;
|
||||
if( pList==0 ){
|
||||
pList = sqlite3DbMallocRawNN(db, sizeof(SrcList) );
|
||||
pList = sqlite3DbMallocRawNN(pParse->db, sizeof(SrcList) );
|
||||
if( pList==0 ) return 0;
|
||||
pList->nAlloc = 1;
|
||||
pList->nSrc = 1;
|
||||
memset(&pList->a[0], 0, sizeof(pList->a[0]));
|
||||
pList->a[0].iCursor = -1;
|
||||
}else{
|
||||
pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
|
||||
}
|
||||
if( db->mallocFailed ){
|
||||
sqlite3SrcListDelete(db, pList);
|
||||
return 0;
|
||||
SrcList *pNew = sqlite3SrcListEnlarge(pParse, pList, 1, pList->nSrc);
|
||||
if( pNew==0 ){
|
||||
sqlite3SrcListDelete(db, pList);
|
||||
return 0;
|
||||
}else{
|
||||
pList = pNew;
|
||||
}
|
||||
}
|
||||
pItem = &pList->a[pList->nSrc-1];
|
||||
if( pDatabase && pDatabase->z==0 ){
|
||||
@@ -4029,7 +4078,7 @@ SrcList *sqlite3SrcListAppendFromTerm(
|
||||
);
|
||||
goto append_from_error;
|
||||
}
|
||||
p = sqlite3SrcListAppend(db, p, pTable, pDatabase);
|
||||
p = sqlite3SrcListAppend(pParse, p, pTable, pDatabase);
|
||||
if( p==0 ){
|
||||
goto append_from_error;
|
||||
}
|
||||
@@ -4349,7 +4398,8 @@ void sqlite3UniqueConstraint(
|
||||
StrAccum errMsg;
|
||||
Table *pTab = pIdx->pTable;
|
||||
|
||||
sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
|
||||
sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0,
|
||||
pParse->db->aLimit[SQLITE_LIMIT_LENGTH]);
|
||||
if( pIdx->aColExpr ){
|
||||
sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
|
||||
}else{
|
||||
@@ -4418,13 +4468,15 @@ static int collationMatch(const char *zColl, Index *pIndex){
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_REINDEX
|
||||
static void reindexTable(Parse *pParse, Table *pTab, char const *zColl){
|
||||
Index *pIndex; /* An index associated with pTab */
|
||||
if( !IsVirtual(pTab) ){
|
||||
Index *pIndex; /* An index associated with pTab */
|
||||
|
||||
for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
|
||||
if( zColl==0 || collationMatch(zColl, pIndex) ){
|
||||
int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
sqlite3RefillIndex(pParse, pIndex, -1);
|
||||
for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){
|
||||
if( zColl==0 || collationMatch(zColl, pIndex) ){
|
||||
int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
sqlite3RefillIndex(pParse, pIndex, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -531,6 +531,10 @@ statNextRestart:
|
||||
goto statNextRestart; /* Tail recursion */
|
||||
}
|
||||
pCsr->iPage++;
|
||||
if( pCsr->iPage>=ArraySize(pCsr->aPage) ){
|
||||
statResetCsr(pCsr);
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
assert( p==&pCsr->aPage[pCsr->iPage-1] );
|
||||
|
||||
if( p->iCell==p->nCell ){
|
||||
@@ -602,7 +606,6 @@ static int statFilter(
|
||||
StatTable *pTab = (StatTable*)(pCursor->pVtab);
|
||||
char *zSql;
|
||||
int rc = SQLITE_OK;
|
||||
char *zMaster;
|
||||
|
||||
if( idxNum==1 ){
|
||||
const char *zDbase = (const char*)sqlite3_value_text(argv[0]);
|
||||
@@ -618,13 +621,12 @@ static int statFilter(
|
||||
statResetCsr(pCsr);
|
||||
sqlite3_finalize(pCsr->pStmt);
|
||||
pCsr->pStmt = 0;
|
||||
zMaster = pCsr->iDb==1 ? "sqlite_temp_master" : "sqlite_master";
|
||||
zSql = sqlite3_mprintf(
|
||||
"SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
|
||||
" UNION ALL "
|
||||
"SELECT name, rootpage, type"
|
||||
" FROM \"%w\".%s WHERE rootpage!=0"
|
||||
" ORDER BY name", pTab->db->aDb[pCsr->iDb].zDbSName, zMaster);
|
||||
" FROM \"%w\".sqlite_master WHERE rootpage!=0"
|
||||
" ORDER BY name", pTab->db->aDb[pCsr->iDb].zDbSName);
|
||||
if( zSql==0 ){
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
}else{
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ void sqlite3MaterializeView(
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
|
||||
pWhere = sqlite3ExprDup(db, pWhere, 0);
|
||||
pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
|
||||
pFrom = sqlite3SrcListAppend(pParse, 0, 0, 0);
|
||||
if( pFrom ){
|
||||
assert( pFrom->nSrc==1 );
|
||||
pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
|
||||
|
||||
+35
-40
@@ -465,6 +465,7 @@ Expr *sqlite3ExprForVectorField(
|
||||
}else{
|
||||
if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr;
|
||||
pRet = sqlite3ExprDup(pParse->db, pVector, 0);
|
||||
sqlite3RenameTokenRemap(pParse, pRet, pVector);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
@@ -780,8 +781,7 @@ Expr *sqlite3ExprAlloc(
|
||||
if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
|
||||
pNew->u.zToken[pToken->n] = 0;
|
||||
if( dequote && sqlite3Isquote(pNew->u.zToken[0]) ){
|
||||
if( pNew->u.zToken[0]=='"' ) pNew->flags |= EP_DblQuoted;
|
||||
sqlite3Dequote(pNew->u.zToken);
|
||||
sqlite3DequoteExpr(pNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -850,14 +850,14 @@ Expr *sqlite3PExpr(
|
||||
Expr *pRight /* Right operand */
|
||||
){
|
||||
Expr *p;
|
||||
if( op==TK_AND && pParse->nErr==0 ){
|
||||
if( op==TK_AND && pParse->nErr==0 && !IN_RENAME_OBJECT ){
|
||||
/* Take advantage of short-circuit false optimization for AND */
|
||||
p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
|
||||
}else{
|
||||
p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
|
||||
if( p ){
|
||||
memset(p, 0, sizeof(Expr));
|
||||
p->op = op & TKFLG_MASK;
|
||||
p->op = op & 0xff;
|
||||
p->iAgg = -1;
|
||||
}
|
||||
sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
|
||||
@@ -1363,6 +1363,7 @@ static void gatherSelectWindows(Select *p){
|
||||
w.xExprCallback = gatherSelectWindowsCallback;
|
||||
w.xSelectCallback = gatherSelectWindowsSelectCallback;
|
||||
w.xSelectCallback2 = 0;
|
||||
w.pParse = 0;
|
||||
w.u.pSelect = p;
|
||||
sqlite3WalkSelect(&w, p);
|
||||
}
|
||||
@@ -1669,6 +1670,9 @@ ExprList *sqlite3ExprListAppendVector(
|
||||
}
|
||||
|
||||
vector_append_error:
|
||||
if( IN_RENAME_OBJECT ){
|
||||
sqlite3RenameExprUnmap(pParse, pExpr);
|
||||
}
|
||||
sqlite3ExprDelete(db, pExpr);
|
||||
sqlite3IdListDelete(db, pColumns);
|
||||
return pList;
|
||||
@@ -1812,8 +1816,9 @@ int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){
|
||||
*/
|
||||
int sqlite3ExprIdToTrueFalse(Expr *pExpr){
|
||||
assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
|
||||
if( sqlite3StrICmp(pExpr->u.zToken, "true")==0
|
||||
|| sqlite3StrICmp(pExpr->u.zToken, "false")==0
|
||||
if( !ExprHasProperty(pExpr, EP_Quoted)
|
||||
&& (sqlite3StrICmp(pExpr->u.zToken, "true")==0
|
||||
|| sqlite3StrICmp(pExpr->u.zToken, "false")==0)
|
||||
){
|
||||
pExpr->op = TK_TRUEFALSE;
|
||||
return 1;
|
||||
@@ -2547,14 +2552,11 @@ int sqlite3FindInIndex(
|
||||
eType = IN_INDEX_EPH;
|
||||
if( inFlags & IN_INDEX_LOOP ){
|
||||
pParse->nQueryLoop = 0;
|
||||
if( pX->pLeft->iColumn<0 && !ExprHasProperty(pX, EP_xIsSelect) ){
|
||||
eType = IN_INDEX_ROWID;
|
||||
}
|
||||
}else if( prRhsHasNull ){
|
||||
*prRhsHasNull = rMayHaveNull = ++pParse->nMem;
|
||||
}
|
||||
assert( pX->op==TK_IN );
|
||||
sqlite3CodeRhsOfIN(pParse, pX, iTab, eType==IN_INDEX_ROWID);
|
||||
sqlite3CodeRhsOfIN(pParse, pX, iTab);
|
||||
if( rMayHaveNull ){
|
||||
sqlite3SetHasNullFlag(v, iTab, rMayHaveNull);
|
||||
}
|
||||
@@ -2655,12 +2657,6 @@ void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
|
||||
** however the cursor number returned might not be the same, as it might
|
||||
** have been duplicated using OP_OpenDup.
|
||||
**
|
||||
** If parameter isRowid is non-zero, then LHS of the IN operator is guaranteed
|
||||
** to be a non-null integer. In this case, the ephemeral table can be an
|
||||
** table B-Tree that keyed by only integers. The more general cases uses
|
||||
** an index B-Tree which can have arbitrary keys, but is slower to both
|
||||
** read and write.
|
||||
**
|
||||
** If the LHS expression ("x" in the examples) is a column value, or
|
||||
** the SELECT statement returns a column value, then the affinity of that
|
||||
** column is used to build the index keys. If both 'x' and the
|
||||
@@ -2672,8 +2668,7 @@ void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
|
||||
void sqlite3CodeRhsOfIN(
|
||||
Parse *pParse, /* Parsing context */
|
||||
Expr *pExpr, /* The IN operator */
|
||||
int iTab, /* Use this cursor number */
|
||||
int isRowid /* If true, LHS is a rowid */
|
||||
int iTab /* Use this cursor number */
|
||||
){
|
||||
int addrOnce = 0; /* Address of the OP_Once instruction at top */
|
||||
int addr; /* Address of OP_OpenEphemeral instruction */
|
||||
@@ -2726,14 +2721,12 @@ void sqlite3CodeRhsOfIN(
|
||||
/* Check to see if this is a vector IN operator */
|
||||
pLeft = pExpr->pLeft;
|
||||
nVal = sqlite3ExprVectorSize(pLeft);
|
||||
assert( !isRowid || nVal==1 );
|
||||
|
||||
/* Construct the ephemeral table that will contain the content of
|
||||
** RHS of the IN operator.
|
||||
*/
|
||||
pExpr->iTable = iTab;
|
||||
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral,
|
||||
pExpr->iTable, (isRowid?0:nVal));
|
||||
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal);
|
||||
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
|
||||
VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
|
||||
@@ -2741,7 +2734,7 @@ void sqlite3CodeRhsOfIN(
|
||||
VdbeComment((v, "RHS of IN operator"));
|
||||
}
|
||||
#endif
|
||||
pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
|
||||
pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
|
||||
|
||||
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
|
||||
/* Case 1: expr IN (SELECT ...)
|
||||
@@ -2755,7 +2748,6 @@ void sqlite3CodeRhsOfIN(
|
||||
ExplainQueryPlan((pParse, 1, "%sLIST SUBQUERY %d",
|
||||
addrOnce?"":"CORRELATED ", pSelect->selId
|
||||
));
|
||||
assert( !isRowid );
|
||||
/* If the LHS and RHS of the IN operator do not match, that
|
||||
** error will have been caught long before we reach this point. */
|
||||
if( ALWAYS(pEList->nExpr==nVal) ){
|
||||
@@ -2808,10 +2800,8 @@ void sqlite3CodeRhsOfIN(
|
||||
/* Loop through each expression in <exprlist>. */
|
||||
r1 = sqlite3GetTempReg(pParse);
|
||||
r2 = sqlite3GetTempReg(pParse);
|
||||
if( isRowid ) sqlite3VdbeAddOp4(v, OP_Blob, 0, r2, 0, "", P4_STATIC);
|
||||
for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
|
||||
Expr *pE2 = pItem->pExpr;
|
||||
int iValToIns;
|
||||
|
||||
/* If the expression is not constant then we will need to
|
||||
** disable the test that was generated above that makes sure
|
||||
@@ -2824,20 +2814,9 @@ void sqlite3CodeRhsOfIN(
|
||||
}
|
||||
|
||||
/* Evaluate the expression and insert it into the temp table */
|
||||
if( isRowid && sqlite3ExprIsInteger(pE2, &iValToIns) ){
|
||||
sqlite3VdbeAddOp3(v, OP_InsertInt, iTab, r2, iValToIns);
|
||||
}else{
|
||||
r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
|
||||
if( isRowid ){
|
||||
sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
|
||||
sqlite3VdbeCurrentAddr(v)+2);
|
||||
VdbeCoverage(v);
|
||||
sqlite3VdbeAddOp3(v, OP_Insert, iTab, r2, r3);
|
||||
}else{
|
||||
sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
|
||||
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
|
||||
}
|
||||
}
|
||||
r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
|
||||
sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
|
||||
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
|
||||
}
|
||||
sqlite3ReleaseTempReg(pParse, r1);
|
||||
sqlite3ReleaseTempReg(pParse, r2);
|
||||
@@ -4854,9 +4833,11 @@ int sqlite3ExprCompare(Parse *pParse, Expr *pA, Expr *pB, int iTab){
|
||||
if( sqlite3WindowCompare(pParse,pA->y.pWin,pB->y.pWin)!=0 ) return 2;
|
||||
}
|
||||
#endif
|
||||
}else if( pA->op==TK_NULL ){
|
||||
return 0;
|
||||
}else if( pA->op==TK_COLLATE ){
|
||||
if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
|
||||
}else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
|
||||
}else if( ALWAYS(pB->u.zToken!=0) && strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -4979,6 +4960,7 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
|
||||
case TK_ISNOT:
|
||||
case TK_NOT:
|
||||
case TK_ISNULL:
|
||||
case TK_NOTNULL:
|
||||
case TK_IS:
|
||||
case TK_OR:
|
||||
case TK_CASE:
|
||||
@@ -4987,6 +4969,7 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
|
||||
testcase( pExpr->op==TK_ISNOT );
|
||||
testcase( pExpr->op==TK_NOT );
|
||||
testcase( pExpr->op==TK_ISNULL );
|
||||
testcase( pExpr->op==TK_NOTNULL );
|
||||
testcase( pExpr->op==TK_IS );
|
||||
testcase( pExpr->op==TK_OR );
|
||||
testcase( pExpr->op==TK_CASE );
|
||||
@@ -5049,6 +5032,17 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
|
||||
*/
|
||||
int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){
|
||||
Walker w;
|
||||
p = sqlite3ExprSkipCollate(p);
|
||||
while( p ){
|
||||
if( p->op==TK_NOTNULL ){
|
||||
p = p->pLeft;
|
||||
}else if( p->op==TK_AND ){
|
||||
if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab) ) return 1;
|
||||
p = p->pRight;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
w.xExprCallback = impliesNotNullRow;
|
||||
w.xSelectCallback = 0;
|
||||
w.xSelectCallback2 = 0;
|
||||
@@ -5360,6 +5354,7 @@ void sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){
|
||||
w.xSelectCallback2 = analyzeAggregatesInSelectEnd;
|
||||
w.walkerDepth = 0;
|
||||
w.u.pNC = pNC;
|
||||
w.pParse = 0;
|
||||
assert( pNC->pSrcList!=0 );
|
||||
sqlite3WalkExpr(&w, pExpr);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1014,7 +1014,7 @@ void sqlite3FkCheck(
|
||||
|
||||
/* Create a SrcList structure containing the child table. We need the
|
||||
** child table as a SrcList for sqlite3WhereBegin() */
|
||||
pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
|
||||
pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
|
||||
if( pSrc ){
|
||||
struct SrcList_item *pItem = pSrc->a;
|
||||
pItem->pTab = pFKey->pFrom;
|
||||
@@ -1291,7 +1291,7 @@ static Trigger *fkActionTrigger(
|
||||
}
|
||||
pSelect = sqlite3SelectNew(pParse,
|
||||
sqlite3ExprListAppend(pParse, 0, pRaise),
|
||||
sqlite3SrcListAppend(db, 0, &tFrom, 0),
|
||||
sqlite3SrcListAppend(pParse, 0, &tFrom, 0),
|
||||
pWhere,
|
||||
0, 0, 0, 0, 0
|
||||
);
|
||||
|
||||
+11
-3
@@ -201,6 +201,7 @@ static void instrFunc(
|
||||
int typeHaystack, typeNeedle;
|
||||
int N = 1;
|
||||
int isText;
|
||||
unsigned char firstChar;
|
||||
|
||||
UNUSED_PARAMETER(argc);
|
||||
typeHaystack = sqlite3_value_type(argv[0]);
|
||||
@@ -219,7 +220,10 @@ static void instrFunc(
|
||||
isText = 1;
|
||||
}
|
||||
if( zNeedle==0 || (nHaystack && zHaystack==0) ) return;
|
||||
while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){
|
||||
firstChar = zNeedle[0];
|
||||
while( nNeedle<=nHaystack
|
||||
&& (zHaystack[0]!=firstChar || memcmp(zHaystack, zNeedle, nNeedle)!=0)
|
||||
){
|
||||
N++;
|
||||
do{
|
||||
nHaystack--;
|
||||
@@ -510,11 +514,11 @@ static void randomBlob(
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
int n;
|
||||
sqlite3_int64 n;
|
||||
unsigned char *p;
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
n = sqlite3_value_int(argv[0]);
|
||||
n = sqlite3_value_int64(argv[0]);
|
||||
if( n<1 ){
|
||||
n = 1;
|
||||
}
|
||||
@@ -1802,6 +1806,10 @@ static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
|
||||
if( ALWAYS(pDef) ){
|
||||
pDef->funcFlags |= flagVal;
|
||||
}
|
||||
pDef = sqlite3FindFunction(db, zName, 3, SQLITE_UTF8, 0);
|
||||
if( pDef ){
|
||||
pDef->funcFlags |= flagVal;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+11
-1
@@ -189,6 +189,13 @@ const unsigned char sqlite3CtypeMap[256] = {
|
||||
#endif
|
||||
|
||||
|
||||
/* The default maximum size of an in-memory database created using
|
||||
** sqlite3_deserialize()
|
||||
*/
|
||||
#ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE
|
||||
# define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The following singleton contains the global configuration for
|
||||
** the SQLite library.
|
||||
@@ -236,13 +243,16 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = {
|
||||
0, /* xVdbeBranch */
|
||||
0, /* pVbeBranchArg */
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
|
||||
#endif
|
||||
#ifndef SQLITE_UNTESTABLE
|
||||
0, /* xTestCallback */
|
||||
#endif
|
||||
0, /* bLocaltimeFault */
|
||||
0, /* bInternalFunctions */
|
||||
0x7ffffffe, /* iOnceResetThreshold */
|
||||
SQLITE_DEFAULT_SORTERREF_SIZE /* szSorterRef */
|
||||
SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
+31
-17
@@ -953,16 +953,12 @@ void sqlite3Insert(
|
||||
}else if( pSelect ){
|
||||
sqlite3VdbeAddOp2(v, OP_Copy, regFromSelect+ipkColumn, regRowid);
|
||||
}else{
|
||||
VdbeOp *pOp;
|
||||
sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
|
||||
pOp = sqlite3VdbeGetOp(v, -1);
|
||||
assert( pOp!=0 );
|
||||
if( pOp->opcode==OP_Null && !IsVirtual(pTab) ){
|
||||
Expr *pIpk = pList->a[ipkColumn].pExpr;
|
||||
if( pIpk->op==TK_NULL && !IsVirtual(pTab) ){
|
||||
sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
|
||||
appendFlag = 1;
|
||||
pOp->opcode = OP_NewRowid;
|
||||
pOp->p1 = iDataCur;
|
||||
pOp->p2 = regRowid;
|
||||
pOp->p3 = regAutoinc;
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
|
||||
}
|
||||
}
|
||||
/* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
|
||||
@@ -1673,7 +1669,9 @@ void sqlite3GenerateConstraintChecks(
|
||||
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
|
||||
VdbeComment((v, "for %s", pIdx->zName));
|
||||
#ifdef SQLITE_ENABLE_NULL_TRIM
|
||||
if( pIdx->idxType==2 ) sqlite3SetMakeRecordP5(v, pIdx->pTable);
|
||||
if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
|
||||
sqlite3SetMakeRecordP5(v, pIdx->pTable);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* In an UPDATE operation, if this index is the PRIMARY KEY index
|
||||
@@ -1712,7 +1710,11 @@ void sqlite3GenerateConstraintChecks(
|
||||
** (3) There are no secondary indexes on the table
|
||||
** (4) No delete triggers need to be fired if there is a conflict
|
||||
** (5) No FK constraint counters need to be updated if a conflict occurs.
|
||||
*/
|
||||
**
|
||||
** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
|
||||
** must be explicitly deleted in order to ensure any pre-update hook
|
||||
** is invoked. */
|
||||
#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
|
||||
&& pPk==pIdx /* Condition 2 */
|
||||
&& onError==OE_Replace /* Condition 1 */
|
||||
@@ -1724,6 +1726,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
sqlite3VdbeResolveLabel(v, addrUniqueOk);
|
||||
continue;
|
||||
}
|
||||
#endif /* ifndef SQLITE_ENABLE_PREUPDATE_HOOK */
|
||||
|
||||
/* Check to see if the new index entry will be unique */
|
||||
sqlite3VdbeVerifyAbortable(v, onError);
|
||||
@@ -1837,7 +1840,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
|
||||
/* If the IPK constraint is a REPLACE, run it last */
|
||||
if( ipkTop ){
|
||||
sqlite3VdbeGoto(v, ipkTop+1);
|
||||
sqlite3VdbeGoto(v, ipkTop);
|
||||
VdbeComment((v, "Do IPK REPLACE"));
|
||||
sqlite3VdbeJumpHere(v, ipkBottom);
|
||||
}
|
||||
@@ -1918,10 +1921,13 @@ void sqlite3CompleteInsertion(
|
||||
pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
|
||||
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
if( update_flags==0 ){
|
||||
sqlite3VdbeAddOp4(v, OP_InsertInt,
|
||||
iIdxCur+i, aRegIdx[i], 0, (char*)pTab, P4_TABLE
|
||||
int r = sqlite3GetTempReg(pParse);
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, r);
|
||||
sqlite3VdbeAddOp4(v, OP_Insert,
|
||||
iIdxCur+i, aRegIdx[i], r, (char*)pTab, P4_TABLE
|
||||
);
|
||||
sqlite3VdbeChangeP5(v, OPFLAG_ISNOOP);
|
||||
sqlite3ReleaseTempReg(pParse, r);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -2207,7 +2213,8 @@ static int xferOptimization(
|
||||
if( pSrc==0 ){
|
||||
return 0; /* FROM clause does not contain a real table */
|
||||
}
|
||||
if( pSrc==pDest ){
|
||||
if( pSrc->tnum==pDest->tnum && pSrc->pSchema==pDest->pSchema ){
|
||||
testcase( pSrc!=pDest ); /* Possible due to bad sqlite_master.rootpage */
|
||||
return 0; /* tab1 and tab2 may not be the same table */
|
||||
}
|
||||
if( HasRowid(pDest)!=HasRowid(pSrc) ){
|
||||
@@ -2268,6 +2275,13 @@ static int xferOptimization(
|
||||
if( pSrcIdx==0 ){
|
||||
return 0; /* pDestIdx has no corresponding index in pSrc */
|
||||
}
|
||||
if( pSrcIdx->tnum==pDestIdx->tnum && pSrc->pSchema==pDest->pSchema
|
||||
&& sqlite3FaultSim(411)==SQLITE_OK ){
|
||||
/* The sqlite3FaultSim() call allows this corruption test to be
|
||||
** bypassed during testing, in order to exercise other corruption tests
|
||||
** further downstream. */
|
||||
return 0; /* Corrupt schema - two indexes on the same btree */
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_CHECK
|
||||
if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
|
||||
@@ -2345,7 +2359,7 @@ static int xferOptimization(
|
||||
sqlite3RowidConstraint(pParse, onError, pDest);
|
||||
sqlite3VdbeJumpHere(v, addr2);
|
||||
autoIncStep(pParse, regAutoinc, regRowid);
|
||||
}else if( pDest->pIndex==0 ){
|
||||
}else if( pDest->pIndex==0 && !(db->mDbFlags & DBFLAG_VacuumInto) ){
|
||||
addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
|
||||
}else{
|
||||
addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
|
||||
@@ -2408,7 +2422,7 @@ static int xferOptimization(
|
||||
sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
|
||||
}
|
||||
}
|
||||
if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
|
||||
if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
|
||||
idxInsFlags |= OPFLAG_NCHANGE;
|
||||
}
|
||||
sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData);
|
||||
|
||||
+2
-3
@@ -46,7 +46,7 @@ int sqlite3_exec(
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
sqlite3Error(db, SQLITE_OK);
|
||||
while( rc==SQLITE_OK && zSql[0] ){
|
||||
int nCol;
|
||||
int nCol = 0;
|
||||
char **azVals = 0;
|
||||
|
||||
pStmt = 0;
|
||||
@@ -60,9 +60,7 @@ int sqlite3_exec(
|
||||
zSql = zLeftover;
|
||||
continue;
|
||||
}
|
||||
|
||||
callbackIsInit = 0;
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
|
||||
while( 1 ){
|
||||
int i;
|
||||
@@ -73,6 +71,7 @@ int sqlite3_exec(
|
||||
(SQLITE_DONE==rc && !callbackIsInit
|
||||
&& db->flags&SQLITE_NullCallback)) ){
|
||||
if( !callbackIsInit ){
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*));
|
||||
if( azCols==0 ){
|
||||
goto exec_out;
|
||||
|
||||
+5
-2
@@ -455,10 +455,13 @@ static const sqlite3_api_routines sqlite3Apis = {
|
||||
sqlite3_create_window_function,
|
||||
/* Version 3.26.0 and later */
|
||||
#ifdef SQLITE_ENABLE_NORMALIZE
|
||||
sqlite3_normalized_sql
|
||||
sqlite3_normalized_sql,
|
||||
#else
|
||||
0
|
||||
0,
|
||||
#endif
|
||||
/* Version 3.28.0 and later */
|
||||
sqlite3_stmt_isexplain,
|
||||
sqlite3_value_frombind
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
+45
-15
@@ -653,6 +653,13 @@ int sqlite3_config(int op, ...){
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_SORTER_REFERENCES */
|
||||
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
case SQLITE_CONFIG_MEMDB_MAXSIZE: {
|
||||
sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
|
||||
break;
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_DESERIALIZE */
|
||||
|
||||
default: {
|
||||
rc = SQLITE_ERROR;
|
||||
break;
|
||||
@@ -836,6 +843,8 @@ int sqlite3_db_config(sqlite3 *db, int op, ...){
|
||||
{ SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_TriggerEQP },
|
||||
{ SQLITE_DBCONFIG_RESET_DATABASE, SQLITE_ResetDatabase },
|
||||
{ SQLITE_DBCONFIG_DEFENSIVE, SQLITE_Defensive },
|
||||
{ SQLITE_DBCONFIG_WRITABLE_SCHEMA, SQLITE_WriteSchema|
|
||||
SQLITE_NoSchemaError },
|
||||
};
|
||||
unsigned int i;
|
||||
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
|
||||
@@ -2935,6 +2944,40 @@ int sqlite3ParseUri(
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if defined(SQLITE_HAS_CODEC)
|
||||
/*
|
||||
** Process URI filename query parameters relevant to the SQLite Encryption
|
||||
** Extension. Return true if any of the relevant query parameters are
|
||||
** seen and return false if not.
|
||||
*/
|
||||
int sqlite3CodecQueryParameters(
|
||||
sqlite3 *db, /* Database connection */
|
||||
const char *zDb, /* Which schema is being created/attached */
|
||||
const char *zUri /* URI filename */
|
||||
){
|
||||
const char *zKey;
|
||||
if( (zKey = sqlite3_uri_parameter(zUri, "hexkey"))!=0 && zKey[0] ){
|
||||
u8 iByte;
|
||||
int i;
|
||||
char zDecoded[40];
|
||||
for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
|
||||
iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
|
||||
if( (i&1)!=0 ) zDecoded[i/2] = iByte;
|
||||
}
|
||||
sqlite3_key_v2(db, zDb, zDecoded, i/2);
|
||||
return 1;
|
||||
}else if( (zKey = sqlite3_uri_parameter(zUri, "key"))!=0 ){
|
||||
sqlite3_key_v2(db, zDb, zKey, sqlite3Strlen30(zKey));
|
||||
return 1;
|
||||
}else if( (zKey = sqlite3_uri_parameter(zUri, "textkey"))!=0 ){
|
||||
sqlite3_key_v2(db, zDb, zKey, -1);
|
||||
return 1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** This routine does the work of opening a database on behalf of
|
||||
@@ -3280,26 +3323,13 @@ opendb_out:
|
||||
}
|
||||
#endif
|
||||
#if defined(SQLITE_HAS_CODEC)
|
||||
if( rc==SQLITE_OK ){
|
||||
const char *zKey;
|
||||
if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){
|
||||
u8 iByte;
|
||||
int i;
|
||||
char zDecoded[40];
|
||||
for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
|
||||
iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
|
||||
if( (i&1)!=0 ) zDecoded[i/2] = iByte;
|
||||
}
|
||||
sqlite3_key_v2(db, 0, zDecoded, i/2);
|
||||
}else if( (zKey = sqlite3_uri_parameter(zOpen, "key"))!=0 ){
|
||||
sqlite3_key_v2(db, 0, zKey, sqlite3Strlen30(zKey));
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE_OK ) sqlite3CodecQueryParameters(db, 0, zOpen);
|
||||
#endif
|
||||
sqlite3_free(zOpen);
|
||||
return rc & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Open a new database handle.
|
||||
*/
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user