Compare commits
603 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d6ae89c21 | |||
| 02a9996e40 | |||
| 779e990629 | |||
| c6da6dba69 | |||
| 9045e7d696 | |||
| 1ae057d873 | |||
| e40875d211 | |||
| 68c7fdb7c1 | |||
| 3740712677 | |||
| 93dc177980 | |||
| c0495e8c9c | |||
| 55b8b73e74 | |||
| 348e002ec9 | |||
| c8d214711f | |||
| 74e5a5a703 | |||
| d59f983501 | |||
| 0f91a5352b | |||
| b4d9b2b537 | |||
| 53fa02507b | |||
| f5b70d06ea | |||
| de3246176b | |||
| bb2d2a50f9 | |||
| 73983658c9 | |||
| 05de5048b4 | |||
| 9513fc97a8 | |||
| ef8344c6a5 | |||
| ee612e2a5d | |||
| d51a2d8b8f | |||
| e46ec734c7 | |||
| 111c3cc9fb | |||
| 0fb78f0cca | |||
| e13dfe4b19 | |||
| 07444ecf8c | |||
| bb30123178 | |||
| 480f5e3e6e | |||
| 20235e56f7 | |||
| 6d373c89e0 | |||
| acae2b485e | |||
| 696555d7b5 | |||
| 06a0ea9a68 | |||
| 09b2196d97 | |||
| 4902235796 | |||
| f1cacb76b7 | |||
| 4b1c3eb5f9 | |||
| a73c306065 | |||
| 8eed584786 | |||
| 62f560f805 | |||
| f33e7795b3 | |||
| a13c0c73c5 | |||
| b523159f40 | |||
| f382e1dc59 | |||
| bd24e8faa3 | |||
| 77ea22300b | |||
| 9d41caf361 | |||
| 7098859031 | |||
| 4f16ff9d06 | |||
| 2931a66ece | |||
| 74777f994d | |||
| cc516af4cc | |||
| 9289f5103d | |||
| b9324fea07 | |||
| a612c1c9bc | |||
| 0f56f891dd | |||
| 5daf69e5f4 | |||
| e46292a920 | |||
| 10f08270e1 | |||
| 105c4b5ced | |||
| 4a4e02bc52 | |||
| 24384d88d6 | |||
| 5c46a7e555 | |||
| dd51365408 | |||
| 4d466698a2 | |||
| b9248ef5c7 | |||
| 3832ac9f51 | |||
| 90d3b24a16 | |||
| c629e21786 | |||
| 14a1b1c132 | |||
| cf1e25566b | |||
| 4422b3a646 | |||
| 81640a226e | |||
| 69935c0935 | |||
| 83cb9eb48e | |||
| dff34ab96f | |||
| c06836c3b1 | |||
| 10496f7657 | |||
| 9b9f235165 | |||
| a261c02d44 | |||
| 415ac68ae8 | |||
| 2c7188732d | |||
| 020c4f3830 | |||
| b9f8a187de | |||
| 4d2c20331a | |||
| b915418134 | |||
| 41d26396bb | |||
| 5d8ade1f67 | |||
| f51bad45f0 | |||
| 42a410dcad | |||
| 6d72858e79 | |||
| 9c32c914b8 | |||
| 755708538d | |||
| 7379b455a5 | |||
| a4df1bd5ff | |||
| d95a652025 | |||
| cbe83495ee | |||
| 236bcdf3e4 | |||
| 82f62e8324 | |||
| 9d82a2ccfe | |||
| f54e79405e | |||
| 17adf4e5a1 | |||
| a959bf5311 | |||
| 972da42749 | |||
| 11e489d6cb | |||
| 93fd5420d0 | |||
| ac67f56726 | |||
| 09612a5bb8 | |||
| 21571a94c1 | |||
| de5f21d0a8 | |||
| 0d08402f34 | |||
| 7a7cefa0b8 | |||
| bd0d62c35b | |||
| a2078e025b | |||
| 24ce9446a8 | |||
| 35e6cd09f2 | |||
| cf145047b0 | |||
| d03d3a9b74 | |||
| 6065686d9c | |||
| 26d61e5adf | |||
| 75016050f3 | |||
| d622855e34 | |||
| 8d2a9c3b3a | |||
| 18f9be897d | |||
| 26ec568d28 | |||
| 9025af1603 | |||
| 822810b95a | |||
| bc85a51595 | |||
| ec73546103 | |||
| 09c69fc1b3 | |||
| ccf0bb49bb | |||
| fe972341a5 | |||
| 9a4127a8c1 | |||
| 9ae57841d0 | |||
| 06258a4260 | |||
| e427fe5210 | |||
| 946b65793c | |||
| 50dce5e82f | |||
| abc15f1b9a | |||
| 9718bca77f | |||
| 2d26cfcc4a | |||
| f3c1256a4d | |||
| 2540a7482a | |||
| 19e4eefbca | |||
| a6df0e693f | |||
| 6468990e7b | |||
| de30a3d2e1 | |||
| 75f7317722 | |||
| 3074faabed | |||
| 9966439879 | |||
| e847164f55 | |||
| eda790d28b | |||
| b034a24140 | |||
| f9ac1ab1e7 | |||
| b56a09079e | |||
| d65b7e36ec | |||
| d36bcec9ad | |||
| e9de65201c | |||
| d2f55773f1 | |||
| 48a296c589 | |||
| 342cb33b23 | |||
| 48f4f27cfb | |||
| 7d11e647ad | |||
| a8ed515400 | |||
| c3b48848b3 | |||
| 40b82f9dc6 | |||
| 14c4d42874 | |||
| 151446e793 | |||
| 137b8ebb2b | |||
| 4df68e0ae5 | |||
| 78a9d7551c | |||
| c00727ab58 | |||
| 0fcf6f01e7 | |||
| b6b06bb339 | |||
| bf7f3a005e | |||
| 0542812726 | |||
| 7cc73b399e | |||
| 5e1a7ded4d | |||
| ff9186137d | |||
| d42dbd9dfe | |||
| 93c8139c1a | |||
| acef1abda2 | |||
| ec2f689b21 | |||
| a76b7f5296 | |||
| 90bc36fb30 | |||
| a8f249f1e7 | |||
| cd1499f47b | |||
| 5da5b71435 | |||
| 1168f81092 | |||
| 14e250ac16 | |||
| 4f878f33a9 | |||
| 1f4f7c7a41 | |||
| 04f4b6836b | |||
| 187e2e48a8 | |||
| 3d691fd9ff | |||
| 9088186bfb | |||
| 99bd552503 | |||
| 93ffb50fcd | |||
| e74ca517b4 | |||
| 8ed1da195a | |||
| 904e48eb89 | |||
| 8546497383 | |||
| be12083bc7 | |||
| ba39ca4058 | |||
| 9430506df0 | |||
| 2454e4a901 | |||
| 86c779fe42 | |||
| 49bb56e9b0 | |||
| 6a9595a76b | |||
| b775c97682 | |||
| 11c87895e0 | |||
| 31da7be9f2 | |||
| 756748ea86 | |||
| 7ffb16b495 | |||
| 0564cc2601 | |||
| 52d1407891 | |||
| 85ffcae177 | |||
| 277ae64103 | |||
| 2d344f944e | |||
| 483051c9b6 | |||
| f71d6fa9db | |||
| ccb897c70a | |||
| 2f4d0ec392 | |||
| 8d889afc0d | |||
| d10c3ca3f7 | |||
| 4752bbd872 | |||
| 01ec691979 | |||
| e31cba5675 | |||
| c3c23f346c | |||
| 59df3e92db | |||
| 4fd82a2a78 | |||
| 67656ac78a | |||
| 23634898c5 | |||
| 6068b6b451 | |||
| 433a3e935d | |||
| f83d501c6d | |||
| e103a8de2d | |||
| 736d11ed21 | |||
| 76baad95f4 | |||
| 0449f6561f | |||
| 5f5719bd07 | |||
| 5960724789 | |||
| 81f5ef05a9 | |||
| 7bfccfe73c | |||
| 5f086ddee0 | |||
| 5e26d07d62 | |||
| c645871123 | |||
| 79f313f13c | |||
| 3765c03243 | |||
| a476768340 | |||
| a4cd0bbcb3 | |||
| 3ec4861c00 | |||
| 2f40dc9884 | |||
| 19a7f72ce2 | |||
| d8bc250b91 | |||
| c7f5077e88 | |||
| feef447271 | |||
| ada2323d95 | |||
| f0ac29090b | |||
| 3c6edc8a11 | |||
| 8ed8ddf759 | |||
| bb0eec438d | |||
| 3ff6a5edd9 | |||
| 113a33c539 | |||
| ba9ebc2d12 | |||
| 971ae9f66a | |||
| 1521270010 | |||
| ba6619d7be | |||
| 292ed6decf | |||
| d84f10ed13 | |||
| f3d5a68461 | |||
| 7a04e296f3 | |||
| eca3c67b1c | |||
| 214b50314a | |||
| 743b5fd589 | |||
| 9ad39a33ff | |||
| 3d8c92d041 | |||
| a5b51b8715 | |||
| 6d29a4fe5b | |||
| 65b930553d | |||
| 68b63c0195 | |||
| 1da9c97bc0 | |||
| 824043150f | |||
| 31536304a5 | |||
| a23a873fbb | |||
| 7437c25b63 | |||
| f02b5ad69d | |||
| fe599b05f2 | |||
| 935ad98d60 | |||
| 8cae5a4a47 | |||
| 5b482a9832 | |||
| 9da977f1a5 | |||
| 8c6cb1bc6f | |||
| 5e8e7464d0 | |||
| 1bb89e9cc8 | |||
| 6a4f7f0225 | |||
| 60b95335e2 | |||
| 0a746cc528 | |||
| 3c6fbd6dd9 | |||
| 7d0a2f3fe3 | |||
| 68d261d073 | |||
| 55f36787ea | |||
| f5576936f1 | |||
| 48a6aede46 | |||
| 44918c74cd | |||
| 7b0d34fe32 | |||
| c7a409e78e | |||
| 1929cc0d8a | |||
| de0e1b150c | |||
| 453954b0de | |||
| 188ba3a979 | |||
| 6c68e55689 | |||
| 7f2eb8fff2 | |||
| 89eab376da | |||
| 197561cd42 | |||
| 19c16c8771 | |||
| 11a6e9d9f0 | |||
| 81e5a9a6df | |||
| 5ae13144ef | |||
| 34c11e2f4b | |||
| cf5ad4210e | |||
| 9988db8302 | |||
| 37d4ec86bf | |||
| d784cc893c | |||
| f8fb27f4a9 | |||
| 385b982865 | |||
| 8505d73dc0 | |||
| f817189e1b | |||
| 304cbc17c2 | |||
| 3bb9d75aa6 | |||
| 569143c851 | |||
| 6000e08d33 | |||
| b3d2ba7cb0 | |||
| 0e5cd34915 | |||
| 5cc9daf8a2 | |||
| 4aab6fae57 | |||
| f1f12661c3 | |||
| 9920bf975b | |||
| d487e37367 | |||
| ff37491874 | |||
| cd0b245934 | |||
| 1d6d737cb7 | |||
| 0003d87893 | |||
| 7f65b7af42 | |||
| 21c7ccb9ba | |||
| 1fd1cc4433 | |||
| 677e62aacd | |||
| 050611a79b | |||
| d78fe4e1a4 | |||
| 2be1f2afe8 | |||
| a3a91dd5f1 | |||
| bfd6f1bcd5 | |||
| 55938b5fa0 | |||
| f5ea93b432 | |||
| 1bae648b73 | |||
| d4f7ec7663 | |||
| a77d52f63c | |||
| 6af2a728e4 | |||
| 4ad9673d00 | |||
| a875b72d6b | |||
| 6e5020e8da | |||
| 252d582a35 | |||
| e7e7481a29 | |||
| d6a33de77c | |||
| 0781219fd2 | |||
| 755ed41f5a | |||
| 6536c4f18e | |||
| 204b634222 | |||
| a74364ae13 | |||
| cc26301ec3 | |||
| a6c54def42 | |||
| 5a9fd231ea | |||
| 112501fec2 | |||
| d73ade7d87 | |||
| 4ffaffe657 | |||
| 11fbee24b6 | |||
| d4b646997a | |||
| f22c590bab | |||
| 1408bf176e | |||
| d22ecfd38c | |||
| 2a1aeaa36e | |||
| 8119aab3c8 | |||
| 4c4a25727f | |||
| e0cc26734e | |||
| 9ce612a66f | |||
| 7ac08e8be6 | |||
| 6b6ec407ab | |||
| e3814ee026 | |||
| 240e36c0e3 | |||
| d5e7fff2ca | |||
| 2389048f29 | |||
| 319deefdb9 | |||
| b0e62b0a21 | |||
| dabada6020 | |||
| 57f90189a5 | |||
| ad3930be46 | |||
| f330d53ff3 | |||
| 9af69ff547 | |||
| aecc04d642 | |||
| ec435c40ed | |||
| 22af584e3e | |||
| d75aeee535 | |||
| b3ad4e6118 | |||
| b03786ad6e | |||
| 0d23f678b1 | |||
| 28a314e74d | |||
| acbae3ba10 | |||
| 269b7d09bd | |||
| 529df929de | |||
| 4bc20452b5 | |||
| 871e7ff43d | |||
| 1f97d2618b | |||
| 1af3fd562f | |||
| 9cffb0ffb9 | |||
| 5e23ae500b | |||
| 639ae98c63 | |||
| 126aab142e | |||
| 9be1339faf | |||
| 6db1c9da67 | |||
| 29821b46f5 | |||
| 1d14ffe63d | |||
| 5191ae06ab | |||
| 0227d9304d | |||
| ed42b98056 | |||
| 46bee2aa12 | |||
| 06c7cc7694 | |||
| 695c83ac0e | |||
| 50e43c5094 | |||
| a7fc252b0a | |||
| e3e8f5ce9c | |||
| f93ff6b9f4 | |||
| d01206ffc2 | |||
| 97060e5aa2 | |||
| 01a8ad231a | |||
| 2f2091b10e | |||
| 8210233c7b | |||
| 3c48ee9e0e | |||
| 6610e6a54f | |||
| d218decec5 | |||
| 49e6e5a04f | |||
| 340fd0bc23 | |||
| 4cf34a5e73 | |||
| 66f9655599 | |||
| 93eb906488 | |||
| d685dd6be6 | |||
| a979993b25 | |||
| 080fe6dec9 | |||
| f09a1794d8 | |||
| ca237a8b7b | |||
| 42d2aec1e9 | |||
| 8d81aac13f | |||
| 76f7b16f1e | |||
| 5a4a15fd2e | |||
| 8df014979e | |||
| eeee8a5f01 | |||
| 8e7c82ca3f | |||
| 918232aadb | |||
| e44ac3858c | |||
| 2b994ce5d3 | |||
| 176b04c476 | |||
| 8b04094c4f | |||
| 51ddfef74d | |||
| 42470513b7 | |||
| a7d8d4a07a | |||
| 1fffa73ea2 | |||
| 2ad080aa82 | |||
| 0d3485f019 | |||
| 0f503f6696 | |||
| 3fee67533e | |||
| 00bc66f2cc | |||
| 776a578c21 | |||
| 67d4bbf6c1 | |||
| b0f23784f6 | |||
| 5cad178b86 | |||
| 21f0f694ff | |||
| 1e24072d05 | |||
| a7eaa518f8 | |||
| 67c4ce131b | |||
| c9f1a7d1df | |||
| 6127d73abc | |||
| 7bdbe59829 | |||
| d8b4befdef | |||
| 0e8075ab78 | |||
| 44d441313a | |||
| b19a581241 | |||
| 9bfafa8917 | |||
| 9c0fee296a | |||
| 7607580791 | |||
| 051170c453 | |||
| 5383db714e | |||
| f1c43ea647 | |||
| 0ca23aa437 | |||
| 9d59e3b1bf | |||
| ab6098cfa6 | |||
| 3ddc3809bf | |||
| 407cfe994d | |||
| 632f0ed265 | |||
| 3fb7bd5ee0 | |||
| 55b2e8b062 | |||
| 662a1426cb | |||
| 4d17e30624 | |||
| ba34b79f15 | |||
| 099b385d17 | |||
| bc3c4e0830 | |||
| 3be2b860d0 | |||
| a1c467f51f | |||
| c5edbd1cf6 | |||
| a94c484584 | |||
| 4049ede97d | |||
| 0db20c490a | |||
| 45e4cb8e77 | |||
| 6d0053cfa7 | |||
| e7a377046d | |||
| 96ecb7b004 | |||
| 42c93b5e9f | |||
| 4fcb30b7d7 | |||
| 24ec37c3b3 | |||
| 657a7a66c3 | |||
| ddf4972063 | |||
| 52a0753152 | |||
| e58b2b4a80 | |||
| baca9807f9 | |||
| 7ae0549961 | |||
| b47e4c2819 | |||
| fb645d20bc | |||
| e021890954 | |||
| 1e6f334645 | |||
| 40942f22f1 | |||
| 5777380d19 | |||
| 7e398c04fe | |||
| b2e9640155 | |||
| 1b22ad8ae6 | |||
| 4bb4293b2a | |||
| 7f8653a257 | |||
| fa9011ec70 | |||
| 747cc9425d | |||
| 1f8f131a8b | |||
| feecc9f547 | |||
| 70149ba47e | |||
| 68d4f07577 | |||
| 0d08072b68 | |||
| a7e16a2f05 | |||
| bc7819d176 | |||
| b14d14696b | |||
| 05edf729f7 | |||
| 91be05a910 | |||
| 39b6bd5e17 | |||
| 5f0922b96c | |||
| e8dd6a4e77 | |||
| aae0f74e64 | |||
| 50f9f6c649 | |||
| 8718f0b613 | |||
| 0bff34aea3 | |||
| c6920cdb0c | |||
| fad1ad0526 | |||
| 3083d5f5ea | |||
| bb05976dac | |||
| 898ec7927a | |||
| 730629680a | |||
| eefef9ae80 | |||
| 1b1a1dda9e | |||
| 2d7a691fba | |||
| 531d01cae0 | |||
| 1f9f576695 | |||
| 1e06c70eb0 | |||
| a3944bc4fe | |||
| 676c869d52 | |||
| 15de3ce9ab | |||
| eca6d60bfa | |||
| 8ddf686267 | |||
| 4b17455ab2 | |||
| b3617e9d2d | |||
| a4656e390a | |||
| 3dc864b575 | |||
| ce5de60ff9 | |||
| e9cfe87843 | |||
| 601ec240a9 | |||
| 34a224a13b | |||
| 903fdd4834 | |||
| dee1cb3006 | |||
| c3b93d9e59 | |||
| f43fef29bb | |||
| 606411bf91 | |||
| 17267fe393 | |||
| 745912efac | |||
| a79e2a2d28 | |||
| 7601294ad3 | |||
| 5abe1d3d53 | |||
| 1862271f7c | |||
| 1e0cfd7184 | |||
| 1e25d20cca | |||
| f824b41e64 | |||
| 271d7c2677 | |||
| 578277c257 | |||
| d97471e1ad | |||
| be2ee38283 |
+12
-8
@@ -165,6 +165,7 @@ LTINSTALL = $(LIBTOOL) --mode=install $(INSTALL)
|
||||
###############################################################################
|
||||
|
||||
USE_AMALGAMATION = @USE_AMALGAMATION@
|
||||
AMALGAMATION_LINE_MACROS = @AMALGAMATION_LINE_MACROS@
|
||||
|
||||
# Object files for the SQLite library (non-amalgamation).
|
||||
#
|
||||
@@ -432,7 +433,7 @@ TESTSRC = \
|
||||
$(TOP)/ext/fts3/fts3_term.c \
|
||||
$(TOP)/ext/fts3/fts3_test.c \
|
||||
$(TOP)/ext/session/test_session.c \
|
||||
$(TOP)/ext/rbu/test_rbu.c
|
||||
$(TOP)/ext/rbu/test_rbu.c
|
||||
|
||||
# Statically linked extensions
|
||||
#
|
||||
@@ -440,6 +441,7 @@ TESTSRC += \
|
||||
$(TOP)/ext/expert/sqlite3expert.c \
|
||||
$(TOP)/ext/expert/test_expert.c \
|
||||
$(TOP)/ext/misc/amatch.c \
|
||||
$(TOP)/ext/misc/appendvfs.c \
|
||||
$(TOP)/ext/misc/carray.c \
|
||||
$(TOP)/ext/misc/cksumvfs.c \
|
||||
$(TOP)/ext/misc/closure.c \
|
||||
@@ -520,7 +522,8 @@ TESTSRC2 = \
|
||||
$(TOP)/ext/fts3/fts3_write.c \
|
||||
$(TOP)/ext/async/sqlite3async.c \
|
||||
$(TOP)/ext/session/sqlite3session.c \
|
||||
$(TOP)/ext/misc/stmt.c
|
||||
$(TOP)/ext/misc/stmt.c \
|
||||
fts5.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
@@ -614,12 +617,10 @@ SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
SHELL_OPT += -DSQLITE_ENABLE_DESERIALIZE
|
||||
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_FTS3_PARENTHESIS
|
||||
#FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS5
|
||||
@@ -693,7 +694,6 @@ dbfuzz$(TEXE): $(TOP)/test/dbfuzz.c sqlite3.c sqlite3.h
|
||||
DBFUZZ2_OPTS = \
|
||||
-DSQLITE_THREADSAFE=0 \
|
||||
-DSQLITE_OMIT_LOAD_EXTENSION \
|
||||
-DSQLITE_ENABLE_DESERIALIZE \
|
||||
-DSQLITE_DEBUG \
|
||||
-DSQLITE_ENABLE_DBSTAT_VTAB \
|
||||
-DSQLITE_ENABLE_BYTECODE_VTAB \
|
||||
@@ -757,7 +757,7 @@ mptest: mptester$(TEXE)
|
||||
touch .target_source
|
||||
|
||||
sqlite3.c: .target_source $(TOP)/tool/mksqlite3c.tcl
|
||||
$(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl
|
||||
$(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl $(AMALGAMATION_LINE_MACROS)
|
||||
cp tsrc/sqlite3ext.h .
|
||||
cp $(TOP)/ext/session/sqlite3session.h .
|
||||
|
||||
@@ -1087,6 +1087,7 @@ SHELL_SRC = \
|
||||
$(TOP)/ext/misc/decimal.c \
|
||||
$(TOP)/ext/misc/fileio.c \
|
||||
$(TOP)/ext/misc/ieee754.c \
|
||||
$(TOP)/ext/misc/regexp.c \
|
||||
$(TOP)/ext/misc/series.c \
|
||||
$(TOP)/ext/misc/shathree.c \
|
||||
$(TOP)/ext/misc/sqlar.c \
|
||||
@@ -1233,7 +1234,6 @@ TESTFIXTURE_FLAGS += -DSQLITE_DEFAULT_PAGE_SIZE=1024
|
||||
TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_STMTVTAB
|
||||
TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_DBPAGE_VTAB
|
||||
TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_DESERIALIZE
|
||||
TESTFIXTURE_FLAGS += -DSQLITE_CKSUMVFS_STATIC
|
||||
|
||||
TESTFIXTURE_SRC0 = $(TESTSRC2) libsqlite3.la
|
||||
@@ -1267,7 +1267,7 @@ fuzztest: fuzzcheck$(TEXE) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuz
|
||||
./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db
|
||||
|
||||
valgrindfuzz: fuzzcheck$(TEXT) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db
|
||||
valgrind ./fuzzcheck$(TEXE) --cell-size-check --limit-mem 10M --timeout 600 $(FUZZDATA)
|
||||
valgrind ./fuzzcheck$(TEXE) --cell-size-check --limit-mem 10M $(FUZZDATA)
|
||||
valgrind ./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db
|
||||
|
||||
# The veryquick.test TCL tests.
|
||||
@@ -1429,6 +1429,9 @@ threadtest3$(TEXE): sqlite3.lo $(THREADTEST3_SRC)
|
||||
threadtest: threadtest3$(TEXE)
|
||||
./threadtest3$(TEXE)
|
||||
|
||||
threadtest5: sqlite3.c $(TOP)/test/threadtest5.c
|
||||
$(LTLINK) $(TOP)/test/threadtest5.c sqlite3.c -o $@ $(TLIBS)
|
||||
|
||||
releasetest:
|
||||
$(TCLSH_CMD) $(TOP)/test/releasetest.tcl
|
||||
|
||||
@@ -1482,6 +1485,7 @@ clean:
|
||||
rm -f sqldiff sqldiff.exe
|
||||
rm -f dbhash dbhash.exe
|
||||
rm -f fts5.* fts5parse.*
|
||||
rm -f threadtest5
|
||||
|
||||
distclean: clean
|
||||
rm -f config.h config.log config.status libtool Makefile sqlite3.pc
|
||||
|
||||
+25
-14
@@ -235,8 +235,9 @@ DEBUG = 0
|
||||
!ENDIF
|
||||
|
||||
# <<mark>>
|
||||
# Disable use of the --linemacros argument to the mksqlite3c.tcl tool, which
|
||||
# is used to build the amalgamation.
|
||||
# By default, use --linemacros=1 argument to the mksqlite3c.tcl tool, which
|
||||
# is used to build the amalgamation. This can be turned off to ease debug
|
||||
# of the amalgamation away from the source tree.
|
||||
#
|
||||
!IFNDEF NO_LINEMACROS
|
||||
NO_LINEMACROS = 0
|
||||
@@ -367,7 +368,6 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1
|
||||
!ENDIF
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1
|
||||
!ENDIF
|
||||
@@ -789,9 +789,9 @@ MKSQLITE3C_TOOL = $(TOP)\tool\mksqlite3c.tcl
|
||||
|
||||
!IFNDEF MKSQLITE3C_ARGS
|
||||
!IF $(DEBUG)>1 && $(NO_LINEMACROS)==0
|
||||
MKSQLITE3C_ARGS = --linemacros
|
||||
MKSQLITE3C_ARGS = --linemacros=1
|
||||
!ELSE
|
||||
MKSQLITE3C_ARGS =
|
||||
MKSQLITE3C_ARGS = --linemacros=0
|
||||
!ENDIF
|
||||
!IF $(USE_STDCALL)!=0 || $(FOR_WIN10)!=0
|
||||
MKSQLITE3C_ARGS = $(MKSQLITE3C_ARGS) --useapicall
|
||||
@@ -1552,7 +1552,7 @@ TESTSRC = \
|
||||
$(TOP)\ext\fts3\fts3_term.c \
|
||||
$(TOP)\ext\fts3\fts3_test.c \
|
||||
$(TOP)\ext\rbu\test_rbu.c \
|
||||
$(TOP)\ext\session\test_session.c
|
||||
$(TOP)\ext\session\test_session.c
|
||||
|
||||
# Statically linked extensions.
|
||||
#
|
||||
@@ -1560,6 +1560,7 @@ TESTEXT = \
|
||||
$(TOP)\ext\expert\sqlite3expert.c \
|
||||
$(TOP)\ext\expert\test_expert.c \
|
||||
$(TOP)\ext\misc\amatch.c \
|
||||
$(TOP)\ext\misc\appendvfs.c \
|
||||
$(TOP)\ext\misc\carray.c \
|
||||
$(TOP)\ext\misc\cksumvfs.c \
|
||||
$(TOP)\ext\misc\closure.c \
|
||||
@@ -1584,7 +1585,8 @@ TESTEXT = \
|
||||
$(TOP)\ext\misc\spellfix.c \
|
||||
$(TOP)\ext\misc\totype.c \
|
||||
$(TOP)\ext\misc\unionvtab.c \
|
||||
$(TOP)\ext\misc\wholenumber.c
|
||||
$(TOP)\ext\misc\wholenumber.c \
|
||||
fts5.c
|
||||
|
||||
# If use of zlib is enabled, add the "zipfile.c" source file.
|
||||
#
|
||||
@@ -1687,7 +1689,6 @@ FUZZDATA = \
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS4=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_DESERIALIZE=1
|
||||
!ENDIF
|
||||
|
||||
# <<mark>>
|
||||
@@ -1696,7 +1697,6 @@ 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_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
|
||||
@@ -2209,10 +2209,11 @@ SHELL_SRC = \
|
||||
$(TOP)\src\shell.c.in \
|
||||
$(TOP)\ext\misc\appendvfs.c \
|
||||
$(TOP)\ext\misc\completion.c \
|
||||
$(TOP)\ext\misc\decimal.c \
|
||||
$(TOP)\ext\misc\decimal.c \
|
||||
$(TOP)\ext\misc\fileio.c \
|
||||
$(TOP)\ext\misc\ieee754.c \
|
||||
$(TOP)\ext\misc\series.c \
|
||||
$(TOP)\ext\misc\ieee754.c \
|
||||
$(TOP)\ext\misc\regexp.c \
|
||||
$(TOP)\ext\misc\series.c \
|
||||
$(TOP)\ext\misc\shathree.c \
|
||||
$(TOP)\ext\misc\uint.c \
|
||||
$(TOP)\ext\expert\sqlite3expert.c \
|
||||
@@ -2390,7 +2391,6 @@ TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_JSON1=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_CKSUMVFS_STATIC=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) $(TEST_CCONV_OPTS)
|
||||
|
||||
@@ -2586,6 +2586,17 @@ rbu.exe: $(TOP)\ext\rbu\rbu.c $(TOP)\ext\rbu\sqlite3rbu.c $(SQLITE3C) $(SQLITE3H
|
||||
$(LTLINK) $(NO_WARN) -DSQLITE_ENABLE_RBU \
|
||||
$(TOP)\ext\rbu\rbu.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
|
||||
THREADTEST3_SRC = \
|
||||
$(TOP)\test\threadtest3.c \
|
||||
$(TOP)\test\tt3_checkpoint.c \
|
||||
$(TOP)\test\tt3_index.c \
|
||||
$(TOP)\test\tt3_vacuum.c \
|
||||
$(TOP)\test\tt3_stress.c \
|
||||
$(TOP)\test\tt3_lookaside1.c
|
||||
|
||||
threadtest3.exe: $(THREADTEST3_SRC) $(TOP)\src\test_multiplex.c $(SQLITE3C) $(SQLITE3H)
|
||||
$(LTLINK) $(NO_WARN) $(TOP)\test\threadtest3.c $(TOP)\src\test_multiplex.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
|
||||
LSMDIR=$(TOP)\ext\lsm1
|
||||
!INCLUDE $(LSMDIR)\Makefile.msc
|
||||
|
||||
@@ -2623,7 +2634,7 @@ clean:
|
||||
del /Q sqlite-*-output.vsix 2>NUL
|
||||
del /Q fuzzershell.exe fuzzcheck.exe sqldiff.exe dbhash.exe 2>NUL
|
||||
del /Q sqltclsh.* 2>NUL
|
||||
del /Q dbfuzz.exe sessionfuzz.exe 2>NUL
|
||||
del /Q dbfuzz.exe sessionfuzz.exe threadtest3.exe 2>NUL
|
||||
del /Q kvtest.exe ossshell.exe scrub.exe 2>NUL
|
||||
del /Q showshm.exe sqlite3_checker.* sqlite3_expert.exe 2>NUL
|
||||
del /Q fts5.* fts5parse.* 2>NUL
|
||||
|
||||
@@ -55,11 +55,11 @@ a stand-alone program. To install, simply download or build the single
|
||||
executable file and put that file someplace on your $PATH.)
|
||||
Then run commands like this:
|
||||
|
||||
mkdir ~/sqlite
|
||||
mkdir -p ~/sqlite ~/Fossils
|
||||
cd ~/sqlite
|
||||
fossil clone https://www.sqlite.org/src sqlite.fossil
|
||||
fossil open sqlite.fossil
|
||||
|
||||
fossil clone https://www.sqlite.org/src ~/Fossils/sqlite.fossil
|
||||
fossil open ~/Fossils/sqlite.fossil
|
||||
|
||||
After setting up a repository using the steps above, you can always
|
||||
update to the lastest version using:
|
||||
|
||||
@@ -68,7 +68,7 @@ update to the lastest version using:
|
||||
|
||||
Or type "fossil ui" to get a web-based user interface.
|
||||
|
||||
## Compiling
|
||||
## Compiling for Unix-like systems
|
||||
|
||||
First create a directory in which to place
|
||||
the build products. It is recommended, but not required, that the
|
||||
@@ -94,22 +94,22 @@ script does not work out for you, there is a generic makefile named
|
||||
can copy and edit to suit your needs. Comments on the generic makefile
|
||||
show what changes are needed.
|
||||
|
||||
## Using MSVC
|
||||
## Using MSVC for Windows systems
|
||||
|
||||
On Windows, all applicable build products can be compiled with MSVC.
|
||||
First open the command prompt window associated with the desired compiler
|
||||
version (e.g. "Developer Command Prompt for VS2013"). Next, use NMAKE
|
||||
with the provided "Makefile.msc" to build one of the supported targets.
|
||||
|
||||
For example:
|
||||
For example, from the parent directory of the source subtree named "sqlite":
|
||||
|
||||
mkdir bld
|
||||
cd bld
|
||||
nmake /f Makefile.msc TOP=..\sqlite
|
||||
nmake /f Makefile.msc sqlite3.c TOP=..\sqlite
|
||||
nmake /f Makefile.msc sqlite3.dll TOP=..\sqlite
|
||||
nmake /f Makefile.msc sqlite3.exe TOP=..\sqlite
|
||||
nmake /f Makefile.msc test TOP=..\sqlite
|
||||
nmake /f ..\sqlite\Makefile.msc TOP=..\sqlite
|
||||
nmake /f ..\sqlite\Makefile.msc sqlite3.c TOP=..\sqlite
|
||||
nmake /f ..\sqlite\Makefile.msc sqlite3.dll TOP=..\sqlite
|
||||
nmake /f ..\sqlite\Makefile.msc sqlite3.exe TOP=..\sqlite
|
||||
nmake /f ..\sqlite\Makefile.msc test TOP=..\sqlite
|
||||
|
||||
There are several build options that can be set via the NMAKE command
|
||||
line. For example, to build for WinRT, simply add "FOR_WINRT=1" argument
|
||||
|
||||
@@ -290,7 +290,6 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1
|
||||
!ENDIF
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1
|
||||
!ENDIF
|
||||
@@ -303,6 +302,9 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_SESSION=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PREUPDATE_HOOK=1
|
||||
!ENDIF
|
||||
|
||||
# Always enable math functions on Windows
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_MATH_FUNCTIONS
|
||||
|
||||
# Should the rbu extension be enabled? If so, add compilation options
|
||||
# to enable it.
|
||||
#
|
||||
@@ -957,7 +959,6 @@ LIBRESOBJS =
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS4=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_DESERIALIZE=1
|
||||
!ENDIF
|
||||
|
||||
|
||||
|
||||
@@ -111,14 +111,34 @@ AC_MSG_CHECKING([for whether to support dynamic extensions])
|
||||
AC_MSG_RESULT($enable_dynamic_extensions)
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# --enable-math
|
||||
#
|
||||
AC_ARG_ENABLE(math, [AS_HELP_STRING(
|
||||
[--enable-math], [SQL math functions [default=yes]])],
|
||||
[], [enable_math=yes])
|
||||
AC_MSG_CHECKING([SQL math functions])
|
||||
if test x"$enable_math" = "xyes"; then
|
||||
BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_MATH_FUNCTIONS"
|
||||
AC_MSG_RESULT([enabled])
|
||||
AC_SEARCH_LIBS(ceil, m)
|
||||
else
|
||||
AC_MSG_RESULT([disabled])
|
||||
fi
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# --enable-fts4
|
||||
#
|
||||
AC_ARG_ENABLE(fts4, [AS_HELP_STRING(
|
||||
[--enable-fts4], [include fts4 support [default=yes]])],
|
||||
[], [enable_fts4=yes])
|
||||
AC_MSG_CHECKING([FTS4 extension])
|
||||
if test x"$enable_fts4" = "xyes"; then
|
||||
BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_FTS4"
|
||||
AC_MSG_RESULT([enabled])
|
||||
else
|
||||
AC_MSG_RESULT([disabled])
|
||||
fi
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
@@ -128,8 +148,12 @@ fi
|
||||
AC_ARG_ENABLE(fts3, [AS_HELP_STRING(
|
||||
[--enable-fts3], [include fts3 support [default=no]])],
|
||||
[], [])
|
||||
AC_MSG_CHECKING([FTS3 extension])
|
||||
if test x"$enable_fts3" = "xyes" -a x"$enable_fts4" = "xno"; then
|
||||
BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_FTS3"
|
||||
AC_MSG_RESULT([enabled])
|
||||
else
|
||||
AC_MSG_RESULT([disabled])
|
||||
fi
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
@@ -139,9 +163,13 @@ fi
|
||||
AC_ARG_ENABLE(fts5, [AS_HELP_STRING(
|
||||
[--enable-fts5], [include fts5 support [default=yes]])],
|
||||
[], [enable_fts5=yes])
|
||||
AC_MSG_CHECKING([FTS5 extension])
|
||||
if test x"$enable_fts5" = "xyes"; then
|
||||
AC_MSG_RESULT([enabled])
|
||||
AC_SEARCH_LIBS(log, m)
|
||||
BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_FTS5"
|
||||
else
|
||||
AC_MSG_RESULT([disabled])
|
||||
fi
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
@@ -151,8 +179,12 @@ fi
|
||||
AC_ARG_ENABLE(json1, [AS_HELP_STRING(
|
||||
[--enable-json1], [include json1 support [default=yes]])],
|
||||
[],[enable_json1=yes])
|
||||
AC_MSG_CHECKING([JSON functions])
|
||||
if test x"$enable_json1" = "xyes"; then
|
||||
BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_JSON1"
|
||||
AC_MSG_RESULT([enabled])
|
||||
else
|
||||
AC_MSG_RESULT([disabled])
|
||||
fi
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
@@ -162,8 +194,12 @@ fi
|
||||
AC_ARG_ENABLE(rtree, [AS_HELP_STRING(
|
||||
[--enable-rtree], [include rtree support [default=yes]])],
|
||||
[], [enable_rtree=yes])
|
||||
AC_MSG_CHECKING([RTREE extension])
|
||||
if test x"$enable_rtree" = "xyes"; then
|
||||
BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY"
|
||||
AC_MSG_RESULT([enabled])
|
||||
else
|
||||
AC_MSG_RESULT([disabled])
|
||||
fi
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
@@ -173,8 +209,12 @@ fi
|
||||
AC_ARG_ENABLE(session, [AS_HELP_STRING(
|
||||
[--enable-session], [enable the session extension [default=no]])],
|
||||
[], [])
|
||||
AC_MSG_CHECKING([Session extension])
|
||||
if test x"$enable_session" = "xyes"; then
|
||||
BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK"
|
||||
AC_MSG_RESULT([enabled])
|
||||
else
|
||||
AC_MSG_RESULT([disabled])
|
||||
fi
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
@@ -184,9 +224,13 @@ fi
|
||||
AC_ARG_ENABLE(debug, [AS_HELP_STRING(
|
||||
[--enable-debug], [build with debugging features enabled [default=no]])],
|
||||
[], [])
|
||||
AC_MSG_CHECKING([Build type])
|
||||
if test x"$enable_debug" = "xyes"; then
|
||||
BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_DEBUG -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE"
|
||||
CFLAGS="-g -O0"
|
||||
AC_MSG_RESULT([debug])
|
||||
else
|
||||
AC_MSG_RESULT([release])
|
||||
fi
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
|
||||
+168
-47
@@ -14,13 +14,10 @@
|
||||
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#include <windows.h>
|
||||
#define NO_SHLWAPI_GDI
|
||||
#define NO_SHLWAPI_STREAM
|
||||
#define NO_SHLWAPI_REG
|
||||
#include <shlwapi.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment (lib, "user32.lib")
|
||||
#pragma comment (lib, "kernel32.lib")
|
||||
#pragma comment (lib, "shlwapi.lib")
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
@@ -39,15 +36,15 @@
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* protos */
|
||||
|
||||
static int CheckForCompilerFeature(const char *option);
|
||||
static int CheckForLinkerFeature(const char *option);
|
||||
static int CheckForLinkerFeature(char **options, int count);
|
||||
static int IsIn(const char *string, const char *substring);
|
||||
static int SubstituteFile(const char *substs, const char *filename);
|
||||
static int QualifyPath(const char *path);
|
||||
static const char *GetVersionFromFile(const char *filename, const char *match);
|
||||
static int LocateDependency(const char *keyfile);
|
||||
static const char *GetVersionFromFile(const char *filename, const char *match, int numdots);
|
||||
static DWORD WINAPI ReadFromPipe(LPVOID args);
|
||||
|
||||
/* globals */
|
||||
@@ -59,8 +56,8 @@ typedef struct {
|
||||
char buffer[STATICBUFFERSIZE];
|
||||
} pipeinfo;
|
||||
|
||||
pipeinfo Out = {INVALID_HANDLE_VALUE, '\0'};
|
||||
pipeinfo Err = {INVALID_HANDLE_VALUE, '\0'};
|
||||
pipeinfo Out = {INVALID_HANDLE_VALUE, ""};
|
||||
pipeinfo Err = {INVALID_HANDLE_VALUE, ""};
|
||||
|
||||
/*
|
||||
* exitcodes: 0 == no, 1 == yes, 2 == error
|
||||
@@ -74,6 +71,7 @@ main(
|
||||
char msg[300];
|
||||
DWORD dwWritten;
|
||||
int chars;
|
||||
const char *s;
|
||||
|
||||
/*
|
||||
* Make sure children (cl.exe and link.exe) are kept quiet.
|
||||
@@ -102,16 +100,16 @@ main(
|
||||
}
|
||||
return CheckForCompilerFeature(argv[2]);
|
||||
case 'l':
|
||||
if (argc != 3) {
|
||||
if (argc < 3) {
|
||||
chars = snprintf(msg, sizeof(msg) - 1,
|
||||
"usage: %s -l <linker option>\n"
|
||||
"usage: %s -l <linker option> ?<mandatory option> ...?\n"
|
||||
"Tests for whether link.exe supports an option\n"
|
||||
"exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
|
||||
WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
|
||||
&dwWritten, NULL);
|
||||
return 2;
|
||||
}
|
||||
return CheckForLinkerFeature(argv[2]);
|
||||
return CheckForLinkerFeature(&argv[2], argc-2);
|
||||
case 'f':
|
||||
if (argc == 2) {
|
||||
chars = snprintf(msg, sizeof(msg) - 1,
|
||||
@@ -153,8 +151,13 @@ main(
|
||||
&dwWritten, NULL);
|
||||
return 0;
|
||||
}
|
||||
printf("%s\n", GetVersionFromFile(argv[2], argv[3]));
|
||||
return 0;
|
||||
s = GetVersionFromFile(argv[2], argv[3], *(argv[1]+2) - '0');
|
||||
if (s && *s) {
|
||||
printf("%s\n", s);
|
||||
return 0;
|
||||
} else
|
||||
return 1; /* Version not found. Return non-0 exit code */
|
||||
|
||||
case 'Q':
|
||||
if (argc != 3) {
|
||||
chars = snprintf(msg, sizeof(msg) - 1,
|
||||
@@ -166,6 +169,18 @@ main(
|
||||
return 2;
|
||||
}
|
||||
return QualifyPath(argv[2]);
|
||||
|
||||
case 'L':
|
||||
if (argc != 3) {
|
||||
chars = snprintf(msg, sizeof(msg) - 1,
|
||||
"usage: %s -L keypath\n"
|
||||
"Emit the fully qualified path of directory containing keypath\n"
|
||||
"exitcodes: 0 == success, 1 == not found, 2 == error\n", argv[0]);
|
||||
WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
|
||||
&dwWritten, NULL);
|
||||
return 2;
|
||||
}
|
||||
return LocateDependency(argv[2]);
|
||||
}
|
||||
}
|
||||
chars = snprintf(msg, sizeof(msg) - 1,
|
||||
@@ -260,7 +275,7 @@ CheckForCompilerFeature(
|
||||
"Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
|
||||
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
|
||||
FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
|
||||
FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars],
|
||||
(300-chars), 0);
|
||||
WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, lstrlen(msg), &err,NULL);
|
||||
return 2;
|
||||
@@ -313,7 +328,8 @@ CheckForCompilerFeature(
|
||||
|
||||
static int
|
||||
CheckForLinkerFeature(
|
||||
const char *option)
|
||||
char **options,
|
||||
int count)
|
||||
{
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
@@ -322,7 +338,8 @@ CheckForLinkerFeature(
|
||||
char msg[300];
|
||||
BOOL ok;
|
||||
HANDLE hProcess, h, pipeThreads[2];
|
||||
char cmdline[100];
|
||||
int i;
|
||||
char cmdline[255];
|
||||
|
||||
hProcess = GetCurrentProcess();
|
||||
|
||||
@@ -368,7 +385,11 @@ CheckForLinkerFeature(
|
||||
* Append our option for testing.
|
||||
*/
|
||||
|
||||
lstrcat(cmdline, option);
|
||||
for (i = 0; i < count; i++) {
|
||||
lstrcat(cmdline, " \"");
|
||||
lstrcat(cmdline, options[i]);
|
||||
lstrcat(cmdline, "\"");
|
||||
}
|
||||
|
||||
ok = CreateProcess(
|
||||
NULL, /* Module name. */
|
||||
@@ -388,7 +409,7 @@ CheckForLinkerFeature(
|
||||
"Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
|
||||
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
|
||||
FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
|
||||
FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars],
|
||||
(300-chars), 0);
|
||||
WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, lstrlen(msg), &err,NULL);
|
||||
return 2;
|
||||
@@ -433,7 +454,9 @@ CheckForLinkerFeature(
|
||||
return !(strstr(Out.buffer, "LNK1117") != NULL ||
|
||||
strstr(Err.buffer, "LNK1117") != NULL ||
|
||||
strstr(Out.buffer, "LNK4044") != NULL ||
|
||||
strstr(Err.buffer, "LNK4044") != NULL);
|
||||
strstr(Err.buffer, "LNK4044") != NULL ||
|
||||
strstr(Out.buffer, "LNK4224") != NULL ||
|
||||
strstr(Err.buffer, "LNK4224") != NULL);
|
||||
}
|
||||
|
||||
static DWORD WINAPI
|
||||
@@ -479,9 +502,9 @@ IsIn(
|
||||
static const char *
|
||||
GetVersionFromFile(
|
||||
const char *filename,
|
||||
const char *match)
|
||||
const char *match,
|
||||
int numdots)
|
||||
{
|
||||
size_t cbBuffer = 100;
|
||||
static char szBuffer[100];
|
||||
char *szResult = NULL;
|
||||
FILE *fp = fopen(filename, "rt");
|
||||
@@ -491,16 +514,17 @@ GetVersionFromFile(
|
||||
* Read data until we see our match string.
|
||||
*/
|
||||
|
||||
while (fgets(szBuffer, cbBuffer, fp) != NULL) {
|
||||
while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) {
|
||||
LPSTR p, q;
|
||||
|
||||
p = strstr(szBuffer, match);
|
||||
if (p != NULL) {
|
||||
/*
|
||||
* Skip to first digit.
|
||||
* Skip to first digit after the match.
|
||||
*/
|
||||
|
||||
while (*p && !isdigit(*p)) {
|
||||
p += strlen(match);
|
||||
while (*p && !isdigit((unsigned char)*p)) {
|
||||
++p;
|
||||
}
|
||||
|
||||
@@ -509,13 +533,13 @@ GetVersionFromFile(
|
||||
*/
|
||||
|
||||
q = p;
|
||||
while (*q && (isalnum(*q) || *q == '.')) {
|
||||
while (*q && (strchr("0123456789.ab", *q)) && (((!strchr(".ab", *q)
|
||||
&& !strchr("ab", q[-1])) || --numdots))) {
|
||||
++q;
|
||||
}
|
||||
|
||||
memcpy(szBuffer, p, q - p);
|
||||
szBuffer[q-p] = 0;
|
||||
szResult = szBuffer;
|
||||
*q = 0;
|
||||
szResult = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -538,7 +562,7 @@ typedef struct list_item_t {
|
||||
static list_item_t *
|
||||
list_insert(list_item_t **listPtrPtr, const char *key, const char *value)
|
||||
{
|
||||
list_item_t *itemPtr = malloc(sizeof(list_item_t));
|
||||
list_item_t *itemPtr = (list_item_t *)malloc(sizeof(list_item_t));
|
||||
if (itemPtr) {
|
||||
itemPtr->key = strdup(key);
|
||||
itemPtr->value = strdup(value);
|
||||
@@ -587,9 +611,7 @@ SubstituteFile(
|
||||
const char *substitutions,
|
||||
const char *filename)
|
||||
{
|
||||
size_t cbBuffer = 1024;
|
||||
static char szBuffer[1024], szCopy[1024];
|
||||
char *szResult = NULL;
|
||||
list_item_t *substPtr = NULL;
|
||||
FILE *fp, *sp;
|
||||
|
||||
@@ -602,7 +624,7 @@ SubstituteFile(
|
||||
|
||||
sp = fopen(substitutions, "rt");
|
||||
if (sp != NULL) {
|
||||
while (fgets(szBuffer, cbBuffer, sp) != NULL) {
|
||||
while (fgets(szBuffer, sizeof(szBuffer), sp) != NULL) {
|
||||
unsigned char *ks, *ke, *vs, *ve;
|
||||
ks = (unsigned char*)szBuffer;
|
||||
while (ks && *ks && isspace(*ks)) ++ks;
|
||||
@@ -619,7 +641,7 @@ SubstituteFile(
|
||||
}
|
||||
|
||||
/* debug: dump the list */
|
||||
#ifdef _DEBUG
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
int n = 0;
|
||||
list_item_t *p = NULL;
|
||||
@@ -628,12 +650,12 @@ SubstituteFile(
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Run the substitutions over each line of the input
|
||||
*/
|
||||
|
||||
while (fgets(szBuffer, cbBuffer, fp) != NULL) {
|
||||
|
||||
while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) {
|
||||
list_item_t *p = NULL;
|
||||
for (p = substPtr; p != NULL; p = p->nextPtr) {
|
||||
char *m = strstr(szBuffer, p->key);
|
||||
@@ -650,15 +672,26 @@ SubstituteFile(
|
||||
memcpy(szBuffer, szCopy, sizeof(szCopy));
|
||||
}
|
||||
}
|
||||
printf(szBuffer);
|
||||
printf("%s", szBuffer);
|
||||
}
|
||||
|
||||
|
||||
list_free(&substPtr);
|
||||
}
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL FileExists(LPCTSTR szPath)
|
||||
{
|
||||
#ifndef INVALID_FILE_ATTRIBUTES
|
||||
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
|
||||
#endif
|
||||
DWORD pathAttr = GetFileAttributes(szPath);
|
||||
return (pathAttr != INVALID_FILE_ATTRIBUTES &&
|
||||
!(pathAttr & FILE_ATTRIBUTE_DIRECTORY));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* QualifyPath --
|
||||
*
|
||||
@@ -672,17 +705,105 @@ QualifyPath(
|
||||
const char *szPath)
|
||||
{
|
||||
char szCwd[MAX_PATH + 1];
|
||||
char szTmp[MAX_PATH + 1];
|
||||
char *p;
|
||||
GetCurrentDirectory(MAX_PATH, szCwd);
|
||||
while ((p = strchr(szPath, '/')) && *p)
|
||||
*p = '\\';
|
||||
PathCombine(szTmp, szCwd, szPath);
|
||||
PathCanonicalize(szCwd, szTmp);
|
||||
|
||||
GetFullPathName(szPath, sizeof(szCwd)-1, szCwd, NULL);
|
||||
printf("%s\n", szCwd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Implements LocateDependency for a single directory. See that command
|
||||
* for an explanation.
|
||||
* Returns 0 if found after printing the directory.
|
||||
* Returns 1 if not found but no errors.
|
||||
* Returns 2 on any kind of error
|
||||
* Basically, these are used as exit codes for the process.
|
||||
*/
|
||||
static int LocateDependencyHelper(const char *dir, const char *keypath)
|
||||
{
|
||||
HANDLE hSearch;
|
||||
char path[MAX_PATH+1];
|
||||
size_t dirlen;
|
||||
int keylen, ret;
|
||||
WIN32_FIND_DATA finfo;
|
||||
|
||||
if (dir == NULL || keypath == NULL)
|
||||
return 2; /* Have no real error reporting mechanism into nmake */
|
||||
dirlen = strlen(dir);
|
||||
if ((dirlen + 3) > sizeof(path))
|
||||
return 2;
|
||||
strncpy(path, dir, dirlen);
|
||||
strncpy(path+dirlen, "\\*", 3); /* Including terminating \0 */
|
||||
keylen = strlen(keypath);
|
||||
|
||||
#if 0 /* This function is not available in Visual C++ 6 */
|
||||
/*
|
||||
* Use numerics 0 -> FindExInfoStandard,
|
||||
* 1 -> FindExSearchLimitToDirectories,
|
||||
* as these are not defined in Visual C++ 6
|
||||
*/
|
||||
hSearch = FindFirstFileEx(path, 0, &finfo, 1, NULL, 0);
|
||||
#else
|
||||
hSearch = FindFirstFile(path, &finfo);
|
||||
#endif
|
||||
if (hSearch == INVALID_HANDLE_VALUE)
|
||||
return 1; /* Not found */
|
||||
|
||||
/* Loop through all subdirs checking if the keypath is under there */
|
||||
ret = 1; /* Assume not found */
|
||||
do {
|
||||
int sublen;
|
||||
/*
|
||||
* We need to check it is a directory despite the
|
||||
* FindExSearchLimitToDirectories in the above call. See SDK docs
|
||||
*/
|
||||
if ((finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
|
||||
continue;
|
||||
sublen = strlen(finfo.cFileName);
|
||||
if ((dirlen+1+sublen+1+keylen+1) > sizeof(path))
|
||||
continue; /* Path does not fit, assume not matched */
|
||||
strncpy(path+dirlen+1, finfo.cFileName, sublen);
|
||||
path[dirlen+1+sublen] = '\\';
|
||||
strncpy(path+dirlen+1+sublen+1, keypath, keylen+1);
|
||||
if (FileExists(path)) {
|
||||
/* Found a match, print to stdout */
|
||||
path[dirlen+1+sublen] = '\0';
|
||||
QualifyPath(path);
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
} while (FindNextFile(hSearch, &finfo));
|
||||
FindClose(hSearch);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* LocateDependency --
|
||||
*
|
||||
* Locates a dependency for a package.
|
||||
* keypath - a relative path within the package directory
|
||||
* that is used to confirm it is the correct directory.
|
||||
* The search path for the package directory is currently only
|
||||
* the parent and grandparent of the current working directory.
|
||||
* If found, the command prints
|
||||
* name_DIRPATH=<full path of located directory>
|
||||
* and returns 0. If not found, does not print anything and returns 1.
|
||||
*/
|
||||
static int LocateDependency(const char *keypath)
|
||||
{
|
||||
size_t i;
|
||||
int ret;
|
||||
static const char *paths[] = {"..", "..\\..", "..\\..\\.."};
|
||||
|
||||
for (i = 0; i < (sizeof(paths)/sizeof(paths[0])); ++i) {
|
||||
ret = LocateDependencyHelper(paths[i], keypath);
|
||||
if (ret == 0)
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* mode: c
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.35.0.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.37.0.
|
||||
#
|
||||
#
|
||||
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
|
||||
@@ -726,8 +726,8 @@ MAKEFLAGS=
|
||||
# Identity of this package.
|
||||
PACKAGE_NAME='sqlite'
|
||||
PACKAGE_TARNAME='sqlite'
|
||||
PACKAGE_VERSION='3.35.0'
|
||||
PACKAGE_STRING='sqlite 3.35.0'
|
||||
PACKAGE_VERSION='3.37.0'
|
||||
PACKAGE_STRING='sqlite 3.37.0'
|
||||
PACKAGE_BUGREPORT=''
|
||||
PACKAGE_URL=''
|
||||
|
||||
@@ -774,6 +774,7 @@ USE_GCOV
|
||||
OPT_FEATURE_FLAGS
|
||||
HAVE_ZLIB
|
||||
USE_AMALGAMATION
|
||||
AMALGAMATION_LINE_MACROS
|
||||
TARGET_DEBUG
|
||||
TARGET_HAVE_EDITLINE
|
||||
TARGET_HAVE_READLINE
|
||||
@@ -902,11 +903,12 @@ with_readline_lib
|
||||
with_readline_inc
|
||||
enable_debug
|
||||
enable_amalgamation
|
||||
amalgamation_line_macros
|
||||
enable_load_extension
|
||||
enable_math
|
||||
enable_all
|
||||
enable_memsys5
|
||||
enable_memsys3
|
||||
enable_all
|
||||
enable_fts3
|
||||
enable_fts4
|
||||
enable_fts5
|
||||
@@ -1467,7 +1469,7 @@ if test "$ac_init_help" = "long"; then
|
||||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat <<_ACEOF
|
||||
\`configure' configures sqlite 3.35.0 to adapt to many kinds of systems.
|
||||
\`configure' configures sqlite 3.37.0 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -1532,7 +1534,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of sqlite 3.35.0:";;
|
||||
short | recursive ) echo "Configuration of sqlite 3.37.0:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@@ -1559,9 +1561,9 @@ Optional Features:
|
||||
--disable-load-extension
|
||||
Disable loading of external extensions
|
||||
--disable-math Disable math functions
|
||||
--enable-all Enable FTS4, FTS5, Geopoly, JSON, RTree, Sessions
|
||||
--enable-memsys5 Enable MEMSYS5
|
||||
--enable-memsys3 Enable MEMSYS3
|
||||
--enable-all Enable FTS4, FTS5, Geopoly, JSON, RTree, Sessions
|
||||
--enable-fts3 Enable the FTS3 extension
|
||||
--enable-fts4 Enable the FTS4 extension
|
||||
--enable-fts5 Enable the FTS5 extension
|
||||
@@ -1660,7 +1662,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
sqlite configure 3.35.0
|
||||
sqlite configure 3.37.0
|
||||
generated by GNU Autoconf 2.69
|
||||
|
||||
Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
@@ -2079,7 +2081,7 @@ cat >config.log <<_ACEOF
|
||||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by sqlite $as_me 3.35.0, which was
|
||||
It was created by sqlite $as_me 3.37.0, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
@@ -10305,6 +10307,13 @@ done
|
||||
#
|
||||
USE_AMALGAMATION=1
|
||||
|
||||
#########
|
||||
# By default, amalgamation sqlite3.c will have #line directives.
|
||||
# This is a build option not shown by ./configure --help
|
||||
# To control it, use configure option: amalgamation_line_macros=?
|
||||
# where ? is no to suppress #line directives or yes to create them.
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=0
|
||||
|
||||
#########
|
||||
# See whether we can run specific tclsh versions known to work well;
|
||||
# if not, then we fall back to plain tclsh.
|
||||
@@ -11251,10 +11260,16 @@ if test "${enable_debug+set}" = set; then :
|
||||
enableval=$enable_debug;
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build type" >&5
|
||||
$as_echo_n "checking build type... " >&6; }
|
||||
if test "${enable_debug}" = "yes" ; then
|
||||
TARGET_DEBUG="-DSQLITE_DEBUG=1 -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE -O0"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: debug" >&5
|
||||
$as_echo "debug" >&6; }
|
||||
else
|
||||
TARGET_DEBUG="-DNDEBUG"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: release" >&5
|
||||
$as_echo "release" >&6; }
|
||||
fi
|
||||
|
||||
|
||||
@@ -11269,6 +11284,19 @@ if test "${enable_amalgamation}" = "no" ; then
|
||||
USE_AMALGAMATION=0
|
||||
fi
|
||||
|
||||
########
|
||||
# See whether --disable
|
||||
if test "${amalgamation_line_macros+set}" = set; then :
|
||||
enableval=$amalgamation_line_macros;
|
||||
fi
|
||||
|
||||
if test "${amalgamation_line_macros}" = "yes" ; then
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=1
|
||||
fi
|
||||
if test "${amalgamation_line_macros}" = "no" ; then
|
||||
AMALGAMATION_LINE_MACROS=--linemacros=0
|
||||
fi
|
||||
|
||||
|
||||
#########
|
||||
# Look for zlib. Only needed by extensions and by the sqlite3.exe shell
|
||||
@@ -11490,6 +11518,16 @@ fi
|
||||
|
||||
fi
|
||||
|
||||
|
||||
########
|
||||
# The --enable-all argument is short-hand to enable
|
||||
# multiple extensions.
|
||||
# Check whether --enable-all was given.
|
||||
if test "${enable_all+set}" = set; then :
|
||||
enableval=$enable_all;
|
||||
fi
|
||||
|
||||
|
||||
##########
|
||||
# Do we want to support memsys3 and/or memsys5
|
||||
#
|
||||
@@ -11524,15 +11562,6 @@ else
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
########
|
||||
# The --enable-extensions argument is short-hand to enable
|
||||
# multiple extensions.
|
||||
# Check whether --enable-all was given.
|
||||
if test "${enable_all+set}" = set; then :
|
||||
enableval=$enable_all;
|
||||
fi
|
||||
|
||||
|
||||
#########
|
||||
# See whether we should enable Full Text Search extensions
|
||||
# Check whether --enable-fts3 was given.
|
||||
@@ -11540,15 +11569,26 @@ if test "${enable_fts3+set}" = set; then :
|
||||
enableval=$enable_fts3;
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support FTS3" >&5
|
||||
$as_echo_n "checking whether to support FTS3... " >&6; }
|
||||
if test "${enable_fts3}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS3"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
# Check whether --enable-fts4 was given.
|
||||
if test "${enable_fts4+set}" = set; then :
|
||||
enableval=$enable_fts4;
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support FTS4" >&5
|
||||
$as_echo_n "checking whether to support FTS4... " >&6; }
|
||||
if test "${enable_fts4}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS4"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing log" >&5
|
||||
$as_echo_n "checking for library containing log... " >&6; }
|
||||
@@ -11606,13 +11646,20 @@ if test "$ac_res" != no; then :
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
# Check whether --enable-fts5 was given.
|
||||
if test "${enable_fts5+set}" = set; then :
|
||||
enableval=$enable_fts5;
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support FTS5" >&5
|
||||
$as_echo_n "checking whether to support FTS5... " >&6; }
|
||||
if test "${enable_fts5}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS5"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing log" >&5
|
||||
$as_echo_n "checking for library containing log... " >&6; }
|
||||
@@ -11670,6 +11717,9 @@ if test "$ac_res" != no; then :
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
#########
|
||||
@@ -11679,8 +11729,15 @@ if test "${enable_json1+set}" = set; then :
|
||||
enableval=$enable_json1;
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support JSON" >&5
|
||||
$as_echo_n "checking whether to support JSON... " >&6; }
|
||||
if test "${enable_json1}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_JSON1"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
#########
|
||||
@@ -11691,8 +11748,15 @@ if test "${enable_update_limit+set}" = set; then :
|
||||
enableval=$enable_update_limit;
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support LIMIT on UPDATE and DELETE statements" >&5
|
||||
$as_echo_n "checking whether to support LIMIT on UPDATE and DELETE statements... " >&6; }
|
||||
if test "${enable_update_limit}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
#########
|
||||
@@ -11704,9 +11768,16 @@ else
|
||||
enable_geopoly=no
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support GEOPOLY" >&5
|
||||
$as_echo_n "checking whether to support GEOPOLY... " >&6; }
|
||||
if test "${enable_geopoly}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_GEOPOLY"
|
||||
enable_rtree=yes
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
#########
|
||||
@@ -11716,8 +11787,15 @@ if test "${enable_rtree+set}" = set; then :
|
||||
enableval=$enable_rtree;
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support RTREE" >&5
|
||||
$as_echo_n "checking whether to support RTREE... " >&6; }
|
||||
if test "${enable_rtree}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_RTREE"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
#########
|
||||
@@ -11727,9 +11805,16 @@ if test "${enable_session+set}" = set; then :
|
||||
enableval=$enable_session;
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support SESSION" >&5
|
||||
$as_echo_n "checking whether to support SESSION... " >&6; }
|
||||
if test "${enable_session}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_SESSION"
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_PREUPDATE_HOOK"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
#########
|
||||
@@ -12315,7 +12400,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
||||
# report actual input values of CONFIG_FILES etc. instead of their
|
||||
# values after options handling.
|
||||
ac_log="
|
||||
This file was extended by sqlite $as_me 3.35.0, which was
|
||||
This file was extended by sqlite $as_me 3.37.0, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@@ -12381,7 +12466,7 @@ _ACEOF
|
||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
|
||||
ac_cs_version="\\
|
||||
sqlite config.status 3.35.0
|
||||
sqlite config.status 3.37.0
|
||||
configured by $0, generated by GNU Autoconf 2.69,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
|
||||
+42
-6
@@ -555,10 +555,13 @@ AC_SEARCH_LIBS(fdatasync, [rt])
|
||||
#########
|
||||
# check for debug enabled
|
||||
AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug],[enable debugging & verbose explain]))
|
||||
AC_MSG_CHECKING([build type])
|
||||
if test "${enable_debug}" = "yes" ; then
|
||||
TARGET_DEBUG="-DSQLITE_DEBUG=1 -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE -O0"
|
||||
AC_MSG_RESULT([debug])
|
||||
else
|
||||
TARGET_DEBUG="-DNDEBUG"
|
||||
AC_MSG_RESULT([release])
|
||||
fi
|
||||
AC_SUBST(TARGET_DEBUG)
|
||||
|
||||
@@ -602,6 +605,13 @@ else
|
||||
AC_SEARCH_LIBS(ceil, m)
|
||||
fi
|
||||
|
||||
|
||||
########
|
||||
# The --enable-all argument is short-hand to enable
|
||||
# multiple extensions.
|
||||
AC_ARG_ENABLE(all, AC_HELP_STRING([--enable-all],
|
||||
[Enable FTS4, FTS5, Geopoly, JSON, RTree, Sessions]))
|
||||
|
||||
##########
|
||||
# Do we want to support memsys3 and/or memsys5
|
||||
#
|
||||
@@ -624,37 +634,47 @@ else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
########
|
||||
# The --enable-extensions argument is short-hand to enable
|
||||
# multiple extensions.
|
||||
AC_ARG_ENABLE(all, AC_HELP_STRING([--enable-all],
|
||||
[Enable FTS4, FTS5, Geopoly, JSON, RTree, Sessions]))
|
||||
|
||||
#########
|
||||
# See whether we should enable Full Text Search extensions
|
||||
AC_ARG_ENABLE(fts3, AC_HELP_STRING([--enable-fts3],
|
||||
[Enable the FTS3 extension]))
|
||||
AC_MSG_CHECKING([whether to support FTS3])
|
||||
if test "${enable_fts3}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS3"
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
AC_ARG_ENABLE(fts4, AC_HELP_STRING([--enable-fts4],
|
||||
[Enable the FTS4 extension]))
|
||||
AC_MSG_CHECKING([whether to support FTS4])
|
||||
if test "${enable_fts4}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
AC_MSG_RESULT([yes])
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS4"
|
||||
AC_SEARCH_LIBS([log],[m])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
AC_ARG_ENABLE(fts5, AC_HELP_STRING([--enable-fts5],
|
||||
[Enable the FTS5 extension]))
|
||||
AC_MSG_CHECKING([whether to support FTS5])
|
||||
if test "${enable_fts5}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
AC_MSG_RESULT([yes])
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS5"
|
||||
AC_SEARCH_LIBS([log],[m])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
#########
|
||||
# See whether we should enable JSON1
|
||||
AC_ARG_ENABLE(json1, AC_HELP_STRING([--enable-json1],[Enable the JSON1 extension]))
|
||||
AC_MSG_CHECKING([whether to support JSON])
|
||||
if test "${enable_json1}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_JSON1"
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
#########
|
||||
@@ -662,8 +682,12 @@ fi
|
||||
# statements.
|
||||
AC_ARG_ENABLE(update-limit, AC_HELP_STRING([--enable-update-limit],
|
||||
[Enable the UPDATE/DELETE LIMIT clause]))
|
||||
AC_MSG_CHECKING([whether to support LIMIT on UPDATE and DELETE statements])
|
||||
if test "${enable_update_limit}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT"
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
#########
|
||||
@@ -671,26 +695,38 @@ fi
|
||||
AC_ARG_ENABLE(geopoly, AC_HELP_STRING([--enable-geopoly],
|
||||
[Enable the GEOPOLY extension]),
|
||||
[enable_geopoly=yes],[enable_geopoly=no])
|
||||
AC_MSG_CHECKING([whether to support GEOPOLY])
|
||||
if test "${enable_geopoly}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_GEOPOLY"
|
||||
enable_rtree=yes
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
#########
|
||||
# See whether we should enable RTREE
|
||||
AC_ARG_ENABLE(rtree, AC_HELP_STRING([--enable-rtree],
|
||||
[Enable the RTREE extension]))
|
||||
AC_MSG_CHECKING([whether to support RTREE])
|
||||
if test "${enable_rtree}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_RTREE"
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
#########
|
||||
# See whether we should enable the SESSION extension
|
||||
AC_ARG_ENABLE(session, AC_HELP_STRING([--enable-session],
|
||||
[Enable the SESSION extension]))
|
||||
AC_MSG_CHECKING([whether to support SESSION])
|
||||
if test "${enable_session}" = "yes" -o "${enable_all}" = "yes" ; then
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_SESSION"
|
||||
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_PREUPDATE_HOOK"
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
#########
|
||||
|
||||
+29
-5
@@ -697,6 +697,7 @@ other than that, the order of directives in Lemon is arbitrary.</p>
|
||||
<li><tt><a href='#stack_size'>%stack_size</a></tt>
|
||||
<li><tt><a href='#start_symbol'>%start_symbol</a></tt>
|
||||
<li><tt><a href='#syntax_error'>%syntax_error</a></tt>
|
||||
<li><tt><a href='#token'>%token</a></tt>
|
||||
<li><tt><a href='#token_class'>%token_class</a></tt>
|
||||
<li><tt><a href='#token_destructor'>%token_destructor</a></tt>
|
||||
<li><tt><a href='#token_prefix'>%token_prefix</a></tt>
|
||||
@@ -1079,14 +1080,37 @@ can choose a different start symbol using the
|
||||
|
||||
<p>See <a href='#errors'>Error Processing</a>.</p>
|
||||
|
||||
<a id='token'></a>
|
||||
<h4>4.4.20 The <tt>%token</tt> directive</h4>
|
||||
|
||||
<p>Tokens are normally created automatically, the first time they are used.
|
||||
Any identifier that begins with an upper-case letter is a token.
|
||||
|
||||
<p>Sometimes it is useful to declare tokens in advance, however. The
|
||||
integer values assigned to each token determined by the order in which
|
||||
the tokens are seen. So by declaring tokens in advance, it is possible to
|
||||
cause some tokens to have low-numbered values, which might be desirable in
|
||||
some grammers, or to have sequential values assigned to a sequence of
|
||||
related tokens. For this reason, the %token directive is provided to
|
||||
declare tokens in advance. The syntax is as follows:
|
||||
|
||||
<blockquote>
|
||||
<tt>%token</tt> <i>TOKEN</i> <i>TOKEN...</i> <b>.</b>
|
||||
</blockquote></p>
|
||||
|
||||
<p>The %token directive is followed by zero or more token symbols and
|
||||
terminated by a single ".". Each token named is created if it does not
|
||||
already exist. Tokens are created in order.
|
||||
|
||||
|
||||
<a id='token_class'></a>
|
||||
<h4>4.4.20 The <tt>%token_class</tt> directive</h4>
|
||||
<h4>4.4.21 The <tt>%token_class</tt> directive</h4>
|
||||
|
||||
<p>Undocumented. Appears to be related to the MULTITERMINAL concept.
|
||||
<a href='http://sqlite.org/src/fdiff?v1=796930d5fc2036c7&v2=624b24c5dc048e09&sbs=0'>Implementation</a>.</p>
|
||||
|
||||
<a id='token_destructor'></a>
|
||||
<h4>4.4.21 The <tt>%token_destructor</tt> directive</h4>
|
||||
<h4>4.4.22 The <tt>%token_destructor</tt> directive</h4>
|
||||
|
||||
<p>The <tt>%destructor</tt> directive assigns a destructor to a non-terminal
|
||||
symbol. (See the description of the
|
||||
@@ -1102,7 +1126,7 @@ Other than that, the token destructor works just like the non-terminal
|
||||
destructors.</p>
|
||||
|
||||
<a id='token_prefix'></a>
|
||||
<h4>4.4.22 The <tt>%token_prefix</tt> directive</h4>
|
||||
<h4>4.4.23 The <tt>%token_prefix</tt> directive</h4>
|
||||
|
||||
<p>Lemon generates #defines that assign small integer constants
|
||||
to each terminal symbol in the grammar. If desired, Lemon will
|
||||
@@ -1129,7 +1153,7 @@ to each of the #defines it generates.</p>
|
||||
</pre>
|
||||
|
||||
<a id='token_type'></a><a id='ptype'></a>
|
||||
<h4>4.4.23 The <tt>%token_type</tt> and <tt>%type</tt> directives</h4>
|
||||
<h4>4.4.24 The <tt>%token_type</tt> and <tt>%type</tt> directives</h4>
|
||||
|
||||
<p>These directives are used to specify the data types for values
|
||||
on the parser's stack associated with terminal and non-terminal
|
||||
@@ -1166,7 +1190,7 @@ entry parser stack will require 100K of heap space. If you are willing
|
||||
and able to pay that price, fine. You just need to know.</p>
|
||||
|
||||
<a id='pwildcard'></a>
|
||||
<h4>4.4.24 The <tt>%wildcard</tt> directive</h4>
|
||||
<h4>4.4.25 The <tt>%wildcard</tt> directive</h4>
|
||||
|
||||
<p>The <tt>%wildcard</tt> directive is followed by a single token name and a
|
||||
period. This directive specifies that the identified token should
|
||||
|
||||
+32
-33
@@ -103,7 +103,7 @@ do_setup_rec_test $tn.1 { CREATE TABLE t1(a, b, c) } {
|
||||
SELECT * FROM t1
|
||||
} {
|
||||
(no new indexes)
|
||||
SCAN TABLE t1
|
||||
SCAN t1
|
||||
}
|
||||
|
||||
do_setup_rec_test $tn.2 {
|
||||
@@ -112,7 +112,7 @@ do_setup_rec_test $tn.2 {
|
||||
SELECT * FROM t1 WHERE b>?;
|
||||
} {
|
||||
CREATE INDEX t1_idx_00000062 ON t1(b);
|
||||
SEARCH TABLE t1 USING INDEX t1_idx_00000062 (b>?)
|
||||
SEARCH t1 USING INDEX t1_idx_00000062 (b>?)
|
||||
}
|
||||
|
||||
do_setup_rec_test $tn.3 {
|
||||
@@ -121,7 +121,7 @@ do_setup_rec_test $tn.3 {
|
||||
SELECT * FROM t1 WHERE b COLLATE nocase BETWEEN ? AND ?
|
||||
} {
|
||||
CREATE INDEX t1_idx_3e094c27 ON t1(b COLLATE NOCASE);
|
||||
SEARCH TABLE t1 USING INDEX t1_idx_3e094c27 (b>? AND b<?)
|
||||
SEARCH t1 USING INDEX t1_idx_3e094c27 (b>? AND b<?)
|
||||
}
|
||||
|
||||
do_setup_rec_test $tn.4 {
|
||||
@@ -130,7 +130,7 @@ do_setup_rec_test $tn.4 {
|
||||
SELECT a FROM t1 ORDER BY b;
|
||||
} {
|
||||
CREATE INDEX t1_idx_00000062 ON t1(b);
|
||||
SCAN TABLE t1 USING INDEX t1_idx_00000062
|
||||
SCAN t1 USING INDEX t1_idx_00000062
|
||||
}
|
||||
|
||||
do_setup_rec_test $tn.5 {
|
||||
@@ -139,7 +139,7 @@ do_setup_rec_test $tn.5 {
|
||||
SELECT a FROM t1 WHERE a=? ORDER BY b;
|
||||
} {
|
||||
CREATE INDEX t1_idx_000123a7 ON t1(a, b);
|
||||
SEARCH TABLE t1 USING COVERING INDEX t1_idx_000123a7 (a=?)
|
||||
SEARCH t1 USING COVERING INDEX t1_idx_000123a7 (a=?)
|
||||
}
|
||||
|
||||
if 0 {
|
||||
@@ -149,7 +149,7 @@ do_setup_rec_test $tn.6 {
|
||||
SELECT min(a) FROM t1
|
||||
} {
|
||||
CREATE INDEX t1_idx_00000061 ON t1(a);
|
||||
SEARCH TABLE t1 USING COVERING INDEX t1_idx_00000061
|
||||
SEARCH t1 USING COVERING INDEX t1_idx_00000061
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ do_setup_rec_test $tn.7 {
|
||||
SELECT * FROM t1 ORDER BY a, b, c;
|
||||
} {
|
||||
CREATE INDEX t1_idx_033e95fe ON t1(a, b, c);
|
||||
SCAN TABLE t1 USING COVERING INDEX t1_idx_033e95fe
|
||||
SCAN t1 USING COVERING INDEX t1_idx_033e95fe
|
||||
}
|
||||
|
||||
#do_setup_rec_test $tn.1.8 {
|
||||
@@ -168,7 +168,7 @@ do_setup_rec_test $tn.7 {
|
||||
# SELECT * FROM t1 ORDER BY a ASC, b COLLATE nocase DESC, c ASC;
|
||||
#} {
|
||||
# CREATE INDEX t1_idx_5be6e222 ON t1(a, b COLLATE NOCASE DESC, c);
|
||||
# 0|0|0|SCAN TABLE t1 USING COVERING INDEX t1_idx_5be6e222
|
||||
# 0|0|0|SCAN t1 USING COVERING INDEX t1_idx_5be6e222
|
||||
#}
|
||||
|
||||
do_setup_rec_test $tn.8.1 {
|
||||
@@ -177,7 +177,7 @@ do_setup_rec_test $tn.8.1 {
|
||||
SELECT * FROM t1 WHERE a=?
|
||||
} {
|
||||
CREATE INDEX t1_idx_00000061 ON t1(a);
|
||||
SEARCH TABLE t1 USING INDEX t1_idx_00000061 (a=?)
|
||||
SEARCH t1 USING INDEX t1_idx_00000061 (a=?)
|
||||
}
|
||||
do_setup_rec_test $tn.8.2 {
|
||||
CREATE TABLE t1(a, b COLLATE nocase, c);
|
||||
@@ -185,7 +185,7 @@ do_setup_rec_test $tn.8.2 {
|
||||
SELECT * FROM t1 ORDER BY a ASC, b DESC, c ASC;
|
||||
} {
|
||||
CREATE INDEX t1_idx_5cb97285 ON t1(a, b DESC, c);
|
||||
SCAN TABLE t1 USING COVERING INDEX t1_idx_5cb97285
|
||||
SCAN t1 USING COVERING INDEX t1_idx_5cb97285
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ do_setup_rec_test $tn.9.1 {
|
||||
SELECT * FROM "t t" WHERE a=?
|
||||
} {
|
||||
CREATE INDEX 't t_idx_00000061' ON 't t'(a);
|
||||
SEARCH TABLE t t USING INDEX t t_idx_00000061 (a=?)
|
||||
SEARCH t t USING INDEX t t_idx_00000061 (a=?)
|
||||
}
|
||||
|
||||
do_setup_rec_test $tn.9.2 {
|
||||
@@ -206,7 +206,7 @@ do_setup_rec_test $tn.9.2 {
|
||||
SELECT * FROM "t t" WHERE b BETWEEN ? AND ?
|
||||
} {
|
||||
CREATE INDEX 't t_idx_00000062' ON 't t'(b);
|
||||
SEARCH TABLE t t USING INDEX t t_idx_00000062 (b>? AND b<?)
|
||||
SEARCH t t USING INDEX t t_idx_00000062 (b>? AND b<?)
|
||||
}
|
||||
|
||||
# Columns with names that require quotes.
|
||||
@@ -217,7 +217,7 @@ do_setup_rec_test $tn.10.1 {
|
||||
SELECT * FROM t3 WHERE "b b" = ?
|
||||
} {
|
||||
CREATE INDEX t3_idx_00050c52 ON t3('b b');
|
||||
SEARCH TABLE t3 USING INDEX t3_idx_00050c52 (b b=?)
|
||||
SEARCH t3 USING INDEX t3_idx_00050c52 (b b=?)
|
||||
}
|
||||
|
||||
do_setup_rec_test $tn.10.2 {
|
||||
@@ -226,7 +226,7 @@ do_setup_rec_test $tn.10.2 {
|
||||
SELECT * FROM t3 ORDER BY "b b"
|
||||
} {
|
||||
CREATE INDEX t3_idx_00050c52 ON t3('b b');
|
||||
SCAN TABLE t3 USING INDEX t3_idx_00050c52
|
||||
SCAN t3 USING INDEX t3_idx_00050c52
|
||||
}
|
||||
|
||||
# Transitive constraints
|
||||
@@ -239,8 +239,8 @@ do_setup_rec_test $tn.11.1 {
|
||||
} {
|
||||
CREATE INDEX t5_idx_000123a7 ON t5(a, b);
|
||||
CREATE INDEX t6_idx_00000063 ON t6(c);
|
||||
SEARCH TABLE t6 USING INDEX t6_idx_00000063 (c=?)
|
||||
SEARCH TABLE t5 USING COVERING INDEX t5_idx_000123a7 (a=? AND b=?)
|
||||
SEARCH t6 USING INDEX t6_idx_00000063 (c=?)
|
||||
SEARCH t5 USING COVERING INDEX t5_idx_000123a7 (a=? AND b=?)
|
||||
}
|
||||
|
||||
# OR terms.
|
||||
@@ -254,9 +254,9 @@ do_setup_rec_test $tn.12.1 {
|
||||
CREATE INDEX t7_idx_00000061 ON t7(a);
|
||||
MULTI-INDEX OR
|
||||
INDEX 1
|
||||
SEARCH TABLE t7 USING INDEX t7_idx_00000061 (a=?)
|
||||
SEARCH t7 USING INDEX t7_idx_00000061 (a=?)
|
||||
INDEX 2
|
||||
SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
|
||||
SEARCH t7 USING INDEX t7_idx_00000062 (b=?)
|
||||
}
|
||||
|
||||
# rowid terms.
|
||||
@@ -267,7 +267,7 @@ do_setup_rec_test $tn.13.1 {
|
||||
SELECT * FROM t8 WHERE rowid=?
|
||||
} {
|
||||
(no new indexes)
|
||||
SEARCH TABLE t8 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
SEARCH t8 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
}
|
||||
do_setup_rec_test $tn.13.2 {
|
||||
CREATE TABLE t8(a, b);
|
||||
@@ -275,7 +275,7 @@ do_setup_rec_test $tn.13.2 {
|
||||
SELECT * FROM t8 ORDER BY rowid
|
||||
} {
|
||||
(no new indexes)
|
||||
SCAN TABLE t8
|
||||
SCAN t8
|
||||
}
|
||||
do_setup_rec_test $tn.13.3 {
|
||||
CREATE TABLE t8(a, b);
|
||||
@@ -283,7 +283,7 @@ do_setup_rec_test $tn.13.3 {
|
||||
SELECT * FROM t8 WHERE a=? ORDER BY rowid
|
||||
} {
|
||||
CREATE INDEX t8_idx_00000061 ON t8(a);
|
||||
SEARCH TABLE t8 USING INDEX t8_idx_00000061 (a=?)
|
||||
SEARCH t8 USING INDEX t8_idx_00000061 (a=?)
|
||||
}
|
||||
|
||||
# Triggers
|
||||
@@ -298,7 +298,7 @@ do_setup_rec_test $tn.14 {
|
||||
INSERT INTO t9 VALUES(?, ?, ?);
|
||||
} {
|
||||
CREATE INDEX t10_idx_00000062 ON t10(b);
|
||||
SEARCH TABLE t10 USING INDEX t10_idx_00000062 (b=?)
|
||||
SEARCH t10 USING INDEX t10_idx_00000062 (b=?)
|
||||
}
|
||||
|
||||
do_setup_rec_test $tn.15 {
|
||||
@@ -314,8 +314,8 @@ do_setup_rec_test $tn.15 {
|
||||
SELECT * FROM t2, t1 WHERE b=? AND d=? AND t2.rowid=t1.rowid
|
||||
} {
|
||||
CREATE INDEX t2_idx_00000064 ON t2(d);
|
||||
SEARCH TABLE t2 USING INDEX t2_idx_00000064 (d=?)
|
||||
SEARCH TABLE t1 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
SEARCH t2 USING INDEX t2_idx_00000064 (d=?)
|
||||
SEARCH t1 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
}
|
||||
|
||||
do_setup_rec_test $tn.16 {
|
||||
@@ -324,7 +324,7 @@ do_setup_rec_test $tn.16 {
|
||||
SELECT * FROM t1 WHERE b IS NOT NULL;
|
||||
} {
|
||||
(no new indexes)
|
||||
SCAN TABLE t1
|
||||
SCAN t1
|
||||
}
|
||||
|
||||
do_setup_rec_test $tn.17.1 {
|
||||
@@ -333,7 +333,7 @@ do_setup_rec_test $tn.17.1 {
|
||||
SELECT * FROM example WHERE a=?
|
||||
} {
|
||||
(no new indexes)
|
||||
SEARCH TABLE example USING INDEX sqlite_autoindex_example_1 (A=?)
|
||||
SEARCH example USING INDEX sqlite_autoindex_example_1 (A=?)
|
||||
}
|
||||
do_setup_rec_test $tn.17.2 {
|
||||
CREATE TABLE example (A INTEGER, B INTEGER, C INTEGER, PRIMARY KEY (A,B));
|
||||
@@ -341,7 +341,7 @@ do_setup_rec_test $tn.17.2 {
|
||||
SELECT * FROM example WHERE b=?
|
||||
} {
|
||||
CREATE INDEX example_idx_00000042 ON example(B);
|
||||
SEARCH TABLE example USING INDEX example_idx_00000042 (B=?)
|
||||
SEARCH example USING INDEX example_idx_00000042 (B=?)
|
||||
}
|
||||
do_setup_rec_test $tn.17.3 {
|
||||
CREATE TABLE example (A INTEGER, B INTEGER, C INTEGER, PRIMARY KEY (A,B));
|
||||
@@ -349,7 +349,7 @@ do_setup_rec_test $tn.17.3 {
|
||||
SELECT * FROM example WHERE a=? AND b=?
|
||||
} {
|
||||
(no new indexes)
|
||||
SEARCH TABLE example USING INDEX sqlite_autoindex_example_1 (A=? AND B=?)
|
||||
SEARCH example USING INDEX sqlite_autoindex_example_1 (A=? AND B=?)
|
||||
}
|
||||
do_setup_rec_test $tn.17.4 {
|
||||
CREATE TABLE example (A INTEGER, B INTEGER, C INTEGER, PRIMARY KEY (A,B));
|
||||
@@ -357,7 +357,7 @@ do_setup_rec_test $tn.17.4 {
|
||||
SELECT * FROM example WHERE a=? AND b>?
|
||||
} {
|
||||
(no new indexes)
|
||||
SEARCH TABLE example USING INDEX sqlite_autoindex_example_1 (A=? AND B>?)
|
||||
SEARCH example USING INDEX sqlite_autoindex_example_1 (A=? AND B>?)
|
||||
}
|
||||
do_setup_rec_test $tn.17.5 {
|
||||
CREATE TABLE example (A INTEGER, B INTEGER, C INTEGER, PRIMARY KEY (A,B));
|
||||
@@ -365,7 +365,7 @@ do_setup_rec_test $tn.17.5 {
|
||||
SELECT * FROM example WHERE a>? AND b=?
|
||||
} {
|
||||
CREATE INDEX example_idx_0000cb3f ON example(B, A);
|
||||
SEARCH TABLE example USING INDEX example_idx_0000cb3f (B=? AND A>?)
|
||||
SEARCH example USING INDEX example_idx_0000cb3f (B=? AND A>?)
|
||||
}
|
||||
|
||||
do_setup_rec_test $tn.18.0 {
|
||||
@@ -377,7 +377,7 @@ do_setup_rec_test $tn.18.0 {
|
||||
SELECT x FROM SomeObject;
|
||||
} {
|
||||
(no new indexes)
|
||||
SCAN TABLE SomeObject
|
||||
SCAN SomeObject
|
||||
}
|
||||
do_setup_rec_test $tn.18.1 {
|
||||
CREATE TABLE SomeObject (
|
||||
@@ -388,7 +388,7 @@ do_setup_rec_test $tn.18.1 {
|
||||
SELECT * FROM SomeObject WHERE x=?;
|
||||
} {
|
||||
CREATE INDEX SomeObject_idx_00000078 ON SomeObject(x);
|
||||
SEARCH TABLE SomeObject USING COVERING INDEX SomeObject_idx_00000078 (x=?)
|
||||
SEARCH SomeObject USING COVERING INDEX SomeObject_idx_00000078 (x=?)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -455,4 +455,3 @@ do_execsql_test 5.3 {
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -690,11 +690,13 @@ static int idxGetTableInfo(
|
||||
rc = idxPrintfPrepareStmt(db, &p1, pzErrmsg, "PRAGMA table_xinfo=%Q", zTab);
|
||||
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(p1) ){
|
||||
const char *zCol = (const char*)sqlite3_column_text(p1, 1);
|
||||
const char *zColSeq = 0;
|
||||
nByte += 1 + STRLEN(zCol);
|
||||
rc = sqlite3_table_column_metadata(
|
||||
db, "main", zTab, zCol, 0, &zCol, 0, 0, 0
|
||||
db, "main", zTab, zCol, 0, &zColSeq, 0, 0, 0
|
||||
);
|
||||
nByte += 1 + STRLEN(zCol);
|
||||
if( zColSeq==0 ) zColSeq = "binary";
|
||||
nByte += 1 + STRLEN(zColSeq);
|
||||
nCol++;
|
||||
nPk += (sqlite3_column_int(p1, 5)>0);
|
||||
}
|
||||
@@ -714,6 +716,7 @@ static int idxGetTableInfo(
|
||||
nCol = 0;
|
||||
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(p1) ){
|
||||
const char *zCol = (const char*)sqlite3_column_text(p1, 1);
|
||||
const char *zColSeq = 0;
|
||||
int nCopy = STRLEN(zCol) + 1;
|
||||
pNew->aCol[nCol].zName = pCsr;
|
||||
pNew->aCol[nCol].iPk = (sqlite3_column_int(p1, 5)==1 && nPk==1);
|
||||
@@ -721,12 +724,13 @@ static int idxGetTableInfo(
|
||||
pCsr += nCopy;
|
||||
|
||||
rc = sqlite3_table_column_metadata(
|
||||
db, "main", zTab, zCol, 0, &zCol, 0, 0, 0
|
||||
db, "main", zTab, zCol, 0, &zColSeq, 0, 0, 0
|
||||
);
|
||||
if( rc==SQLITE_OK ){
|
||||
nCopy = STRLEN(zCol) + 1;
|
||||
if( zColSeq==0 ) zColSeq = "binary";
|
||||
nCopy = STRLEN(zColSeq) + 1;
|
||||
pNew->aCol[nCol].zColl = pCsr;
|
||||
memcpy(pCsr, zCol, nCopy);
|
||||
memcpy(pCsr, zColSeq, nCopy);
|
||||
pCsr += nCopy;
|
||||
}
|
||||
|
||||
|
||||
+21
-14
@@ -326,7 +326,9 @@ int sqlite3Fts3Never(int b) { assert( !b ); return b; }
|
||||
** assert() conditions in the fts3 code are activated - conditions that are
|
||||
** only true if it is guaranteed that the fts3 database is not corrupt.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
int sqlite3_fts3_may_be_corrupt = 1;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Write a 64-bit variable-length integer to memory starting at p[0].
|
||||
@@ -1897,7 +1899,7 @@ static int fts3ScanInteriorNode(
|
||||
char *zBuffer = 0; /* Buffer to load terms into */
|
||||
i64 nAlloc = 0; /* Size of allocated buffer */
|
||||
int isFirstTerm = 1; /* True when processing first term on page */
|
||||
sqlite3_int64 iChild; /* Block id of child node to descend to */
|
||||
u64 iChild; /* Block id of child node to descend to */
|
||||
int nBuffer = 0; /* Total term size */
|
||||
|
||||
/* Skip over the 'height' varint that occurs at the start of every
|
||||
@@ -1913,8 +1915,8 @@ static int fts3ScanInteriorNode(
|
||||
** table, then there are always 20 bytes of zeroed padding following the
|
||||
** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
|
||||
*/
|
||||
zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
|
||||
zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
|
||||
zCsr += sqlite3Fts3GetVarintU(zCsr, &iChild);
|
||||
zCsr += sqlite3Fts3GetVarintU(zCsr, &iChild);
|
||||
if( zCsr>zEnd ){
|
||||
return FTS_CORRUPT_VTAB;
|
||||
}
|
||||
@@ -1967,20 +1969,20 @@ static int fts3ScanInteriorNode(
|
||||
*/
|
||||
cmp = memcmp(zTerm, zBuffer, (nBuffer>nTerm ? nTerm : nBuffer));
|
||||
if( piFirst && (cmp<0 || (cmp==0 && nBuffer>nTerm)) ){
|
||||
*piFirst = iChild;
|
||||
*piFirst = (i64)iChild;
|
||||
piFirst = 0;
|
||||
}
|
||||
|
||||
if( piLast && cmp<0 ){
|
||||
*piLast = iChild;
|
||||
*piLast = (i64)iChild;
|
||||
piLast = 0;
|
||||
}
|
||||
|
||||
iChild++;
|
||||
};
|
||||
|
||||
if( piFirst ) *piFirst = iChild;
|
||||
if( piLast ) *piLast = iChild;
|
||||
if( piFirst ) *piFirst = (i64)iChild;
|
||||
if( piLast ) *piLast = (i64)iChild;
|
||||
|
||||
finish_scan:
|
||||
sqlite3_free(zBuffer);
|
||||
@@ -3586,14 +3588,20 @@ static int fts3SetHasStat(Fts3Table *p){
|
||||
*/
|
||||
static int fts3BeginMethod(sqlite3_vtab *pVtab){
|
||||
Fts3Table *p = (Fts3Table*)pVtab;
|
||||
int rc;
|
||||
UNUSED_PARAMETER(pVtab);
|
||||
assert( p->pSegments==0 );
|
||||
assert( p->nPendingData==0 );
|
||||
assert( p->inTransaction!=1 );
|
||||
TESTONLY( p->inTransaction = 1 );
|
||||
TESTONLY( p->mxSavepoint = -1; );
|
||||
p->nLeafAdd = 0;
|
||||
return fts3SetHasStat(p);
|
||||
rc = fts3SetHasStat(p);
|
||||
#ifdef SQLITE_DEBUG
|
||||
if( rc==SQLITE_OK ){
|
||||
p->inTransaction = 1;
|
||||
p->mxSavepoint = -1;
|
||||
}
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -5122,16 +5130,15 @@ static int fts3EvalStart(Fts3Cursor *pCsr){
|
||||
#ifndef SQLITE_DISABLE_FTS4_DEFERRED
|
||||
if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
|
||||
Fts3TokenAndCost *aTC;
|
||||
Fts3Expr **apOr;
|
||||
aTC = (Fts3TokenAndCost *)sqlite3_malloc64(
|
||||
sizeof(Fts3TokenAndCost) * nToken
|
||||
+ sizeof(Fts3Expr *) * nOr * 2
|
||||
);
|
||||
apOr = (Fts3Expr **)&aTC[nToken];
|
||||
|
||||
if( !aTC ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
Fts3Expr **apOr = (Fts3Expr **)&aTC[nToken];
|
||||
int ii;
|
||||
Fts3TokenAndCost *pTC = aTC;
|
||||
Fts3Expr **ppOr = apOr;
|
||||
@@ -5212,9 +5219,9 @@ static int fts3EvalNearTrim(
|
||||
);
|
||||
if( res ){
|
||||
nNew = (int)(pOut - pPhrase->doclist.pList) - 1;
|
||||
if( nNew>=0 ){
|
||||
assert_fts3_nc( nNew<=pPhrase->doclist.nList && nNew>0 );
|
||||
if( nNew>=0 && nNew<=pPhrase->doclist.nList ){
|
||||
assert( pPhrase->doclist.pList[nNew]=='\0' );
|
||||
assert( nNew<=pPhrase->doclist.nList && nNew>0 );
|
||||
memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew);
|
||||
pPhrase->doclist.nList = nNew;
|
||||
}
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ SQLITE_EXTENSION_INIT3
|
||||
** 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)
|
||||
#ifdef SQLITE_DEBUG
|
||||
extern int sqlite3_fts3_may_be_corrupt;
|
||||
# define assert_fts3_nc(x) assert(sqlite3_fts3_may_be_corrupt || (x))
|
||||
#else
|
||||
|
||||
@@ -406,6 +406,7 @@ static int fts3auxFilterMethod(
|
||||
sqlite3Fts3SegReaderFinish(&pCsr->csr);
|
||||
sqlite3_free((void *)pCsr->filter.zTerm);
|
||||
sqlite3_free(pCsr->aStat);
|
||||
sqlite3_free(pCsr->zStop);
|
||||
memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr);
|
||||
|
||||
pCsr->filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY;
|
||||
|
||||
@@ -493,6 +493,11 @@ static int getNextNode(
|
||||
if( *zInput=='(' ){
|
||||
int nConsumed = 0;
|
||||
pParse->nNest++;
|
||||
#if !defined(SQLITE_MAX_EXPR_DEPTH)
|
||||
if( pParse->nNest>1000 ) return SQLITE_ERROR;
|
||||
#elif SQLITE_MAX_EXPR_DEPTH>0
|
||||
if( pParse->nNest>SQLITE_MAX_EXPR_DEPTH ) return SQLITE_ERROR;
|
||||
#endif
|
||||
rc = fts3ExprParse(pParse, zInput+1, nInput-1, ppExpr, &nConsumed);
|
||||
*pnConsumed = (int)(zInput - z) + 1 + nConsumed;
|
||||
return rc;
|
||||
|
||||
+14
-10
@@ -17,6 +17,10 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef SQLITE_AMALGAMATION
|
||||
typedef sqlite3_int64 i64;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Characters that may appear in the second argument to matchinfo().
|
||||
*/
|
||||
@@ -67,9 +71,9 @@ struct SnippetIter {
|
||||
struct SnippetPhrase {
|
||||
int nToken; /* Number of tokens in phrase */
|
||||
char *pList; /* Pointer to start of phrase position list */
|
||||
int iHead; /* Next value in position list */
|
||||
i64 iHead; /* Next value in position list */
|
||||
char *pHead; /* Position list data following iHead */
|
||||
int iTail; /* Next value in trailing position list */
|
||||
i64 iTail; /* Next value in trailing position list */
|
||||
char *pTail; /* Position list data following iTail */
|
||||
};
|
||||
|
||||
@@ -234,7 +238,7 @@ void sqlite3Fts3MIBufferFree(MatchinfoBuffer *p){
|
||||
** After it returns, *piPos contains the value of the next element of the
|
||||
** list and *pp is advanced to the following varint.
|
||||
*/
|
||||
static void fts3GetDeltaPosition(char **pp, int *piPos){
|
||||
static void fts3GetDeltaPosition(char **pp, i64 *piPos){
|
||||
int iVal;
|
||||
*pp += fts3GetVarint32(*pp, &iVal);
|
||||
*piPos += (iVal-2);
|
||||
@@ -343,10 +347,10 @@ static int fts3ExprPhraseCount(Fts3Expr *pExpr){
|
||||
** arguments so that it points to the first element with a value greater
|
||||
** than or equal to parameter iNext.
|
||||
*/
|
||||
static void fts3SnippetAdvance(char **ppIter, int *piIter, int iNext){
|
||||
static void fts3SnippetAdvance(char **ppIter, i64 *piIter, int iNext){
|
||||
char *pIter = *ppIter;
|
||||
if( pIter ){
|
||||
int iIter = *piIter;
|
||||
i64 iIter = *piIter;
|
||||
|
||||
while( iIter<iNext ){
|
||||
if( 0==(*pIter & 0xFE) ){
|
||||
@@ -429,7 +433,7 @@ static void fts3SnippetDetails(
|
||||
SnippetPhrase *pPhrase = &pIter->aPhrase[i];
|
||||
if( pPhrase->pTail ){
|
||||
char *pCsr = pPhrase->pTail;
|
||||
int iCsr = pPhrase->iTail;
|
||||
i64 iCsr = pPhrase->iTail;
|
||||
|
||||
while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
|
||||
int j;
|
||||
@@ -475,7 +479,7 @@ static int fts3SnippetFindPositions(Fts3Expr *pExpr, int iPhrase, void *ctx){
|
||||
rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pCsr);
|
||||
assert( rc==SQLITE_OK || pCsr==0 );
|
||||
if( pCsr ){
|
||||
int iFirst = 0;
|
||||
i64 iFirst = 0;
|
||||
pPhrase->pList = pCsr;
|
||||
fts3GetDeltaPosition(&pCsr, &iFirst);
|
||||
if( iFirst<0 ){
|
||||
@@ -1539,8 +1543,8 @@ typedef struct TermOffsetCtx TermOffsetCtx;
|
||||
|
||||
struct TermOffset {
|
||||
char *pList; /* Position-list */
|
||||
int iPos; /* Position just read from pList */
|
||||
int iOff; /* Offset of this term from read positions */
|
||||
i64 iPos; /* Position just read from pList */
|
||||
i64 iOff; /* Offset of this term from read positions */
|
||||
};
|
||||
|
||||
struct TermOffsetCtx {
|
||||
@@ -1559,7 +1563,7 @@ static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){
|
||||
int nTerm; /* Number of tokens in phrase */
|
||||
int iTerm; /* For looping through nTerm phrase terms */
|
||||
char *pList; /* Pointer to position list for phrase */
|
||||
int iPos = 0; /* First position in position-list */
|
||||
i64 iPos = 0; /* First position in position-list */
|
||||
int rc;
|
||||
|
||||
UNUSED_PARAMETER(iPhrase);
|
||||
|
||||
@@ -585,6 +585,7 @@ static int SQLITE_TCLAPI fts3_may_be_corrupt(
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
#ifdef SQLITE_DEBUG
|
||||
int bOld = sqlite3_fts3_may_be_corrupt;
|
||||
|
||||
if( objc!=2 && objc!=1 ){
|
||||
@@ -598,6 +599,7 @@ static int SQLITE_TCLAPI fts3_may_be_corrupt(
|
||||
}
|
||||
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(bOld));
|
||||
#endif
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -285,6 +285,7 @@ static int unicodeOpen(
|
||||
pCsr->aInput = (const unsigned char *)aInput;
|
||||
if( aInput==0 ){
|
||||
pCsr->nInput = 0;
|
||||
pCsr->aInput = (const unsigned char*)"";
|
||||
}else if( nInput<0 ){
|
||||
pCsr->nInput = (int)strlen(aInput);
|
||||
}else{
|
||||
|
||||
+10
-7
@@ -1807,7 +1807,7 @@ static int fts3SegReaderCmp(Fts3SegReader *pLhs, Fts3SegReader *pRhs){
|
||||
if( rc==0 ){
|
||||
rc = pRhs->iIdx - pLhs->iIdx;
|
||||
}
|
||||
assert( rc!=0 );
|
||||
assert_fts3_nc( rc!=0 );
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2003,8 +2003,8 @@ static int fts3PrefixCompress(
|
||||
int nNext /* Size of buffer zNext in bytes */
|
||||
){
|
||||
int n;
|
||||
UNUSED_PARAMETER(nNext);
|
||||
for(n=0; n<nPrev && zPrev[n]==zNext[n]; n++);
|
||||
for(n=0; n<nPrev && n<nNext && zPrev[n]==zNext[n]; n++);
|
||||
assert_fts3_nc( n<nNext );
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -3003,7 +3003,7 @@ int sqlite3Fts3SegReaderStep(
|
||||
|
||||
nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0);
|
||||
|
||||
rc = fts3GrowSegReaderBuffer(pCsr, nByte+nDoclist);
|
||||
rc = fts3GrowSegReaderBuffer(pCsr, nByte+nDoclist+FTS3_NODE_PADDING);
|
||||
if( rc ) return rc;
|
||||
|
||||
if( isFirst ){
|
||||
@@ -4335,17 +4335,20 @@ static int fts3IncrmergeLoad(
|
||||
while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader);
|
||||
blobGrowBuffer(&pNode->key, reader.term.n, &rc);
|
||||
if( rc==SQLITE_OK ){
|
||||
memcpy(pNode->key.a, reader.term.a, reader.term.n);
|
||||
assert_fts3_nc( reader.term.n>0 || reader.aNode==0 );
|
||||
if( reader.term.n>0 ){
|
||||
memcpy(pNode->key.a, reader.term.a, reader.term.n);
|
||||
}
|
||||
pNode->key.n = reader.term.n;
|
||||
if( i>0 ){
|
||||
char *aBlock = 0;
|
||||
int nBlock = 0;
|
||||
pNode = &pWriter->aNodeWriter[i-1];
|
||||
pNode->iBlock = reader.iChild;
|
||||
rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock, 0);
|
||||
rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock,0);
|
||||
blobGrowBuffer(&pNode->block,
|
||||
MAX(nBlock, p->nNodeSize)+FTS3_NODE_PADDING, &rc
|
||||
);
|
||||
);
|
||||
if( rc==SQLITE_OK ){
|
||||
memcpy(pNode->block.a, aBlock, nBlock);
|
||||
pNode->block.n = nBlock;
|
||||
|
||||
@@ -435,6 +435,9 @@ void sqlite3Fts5IndexCloseReader(Fts5Index*);
|
||||
*/
|
||||
const char *sqlite3Fts5IterTerm(Fts5IndexIter*, int*);
|
||||
int sqlite3Fts5IterNextScan(Fts5IndexIter*);
|
||||
void *sqlite3Fts5StructureRef(Fts5Index*);
|
||||
void sqlite3Fts5StructureRelease(void*);
|
||||
int sqlite3Fts5StructureTest(Fts5Index*, void*);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
+16
-9
@@ -176,8 +176,9 @@ int sqlite3Fts5PoslistNext64(
|
||||
return 1;
|
||||
}else{
|
||||
i64 iOff = *piOff;
|
||||
int iVal;
|
||||
u32 iVal;
|
||||
fts5FastGetVarint32(a, i, iVal);
|
||||
assert( iVal>=0 );
|
||||
if( iVal<=1 ){
|
||||
if( iVal==0 ){
|
||||
*pi = i;
|
||||
@@ -185,15 +186,19 @@ int sqlite3Fts5PoslistNext64(
|
||||
}
|
||||
fts5FastGetVarint32(a, i, iVal);
|
||||
iOff = ((i64)iVal) << 32;
|
||||
assert( iOff>=0 );
|
||||
fts5FastGetVarint32(a, i, iVal);
|
||||
if( iVal<2 ){
|
||||
/* This is a corrupt record. So stop parsing it here. */
|
||||
*piOff = -1;
|
||||
return 1;
|
||||
}
|
||||
*piOff = iOff + ((iVal-2) & 0x7FFFFFFF);
|
||||
}else{
|
||||
*piOff = (iOff & (i64)0x7FFFFFFF<<32)+((iOff + (iVal-2)) & 0x7FFFFFFF);
|
||||
}
|
||||
*piOff = iOff + ((iVal-2) & 0x7FFFFFFF);
|
||||
*pi = i;
|
||||
assert_nc( *piOff>=iOff );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -232,14 +237,16 @@ void sqlite3Fts5PoslistSafeAppend(
|
||||
i64 *piPrev,
|
||||
i64 iPos
|
||||
){
|
||||
static const i64 colmask = ((i64)(0x7FFFFFFF)) << 32;
|
||||
if( (iPos & colmask) != (*piPrev & colmask) ){
|
||||
pBuf->p[pBuf->n++] = 1;
|
||||
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], (iPos>>32));
|
||||
*piPrev = (iPos & colmask);
|
||||
if( iPos>=*piPrev ){
|
||||
static const i64 colmask = ((i64)(0x7FFFFFFF)) << 32;
|
||||
if( (iPos & colmask) != (*piPrev & colmask) ){
|
||||
pBuf->p[pBuf->n++] = 1;
|
||||
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], (iPos>>32));
|
||||
*piPrev = (iPos & colmask);
|
||||
}
|
||||
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], (iPos-*piPrev)+2);
|
||||
*piPrev = iPos;
|
||||
}
|
||||
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], (iPos-*piPrev)+2);
|
||||
*piPrev = iPos;
|
||||
}
|
||||
|
||||
int sqlite3Fts5PoslistWriterAppend(
|
||||
|
||||
@@ -537,7 +537,7 @@ int sqlite3Fts5ConfigParse(
|
||||
|
||||
nByte = nArg * (sizeof(char*) + sizeof(u8));
|
||||
pRet->azCol = (char**)sqlite3Fts5MallocZero(&rc, nByte);
|
||||
pRet->abUnindexed = (u8*)&pRet->azCol[nArg];
|
||||
pRet->abUnindexed = pRet->azCol ? (u8*)&pRet->azCol[nArg] : 0;
|
||||
pRet->zDb = sqlite3Fts5Strndup(&rc, azArg[1], -1);
|
||||
pRet->zName = sqlite3Fts5Strndup(&rc, azArg[2], -1);
|
||||
pRet->bColumnsize = 1;
|
||||
|
||||
+12
-8
@@ -135,6 +135,7 @@ void sqlite3Fts5ParseError(Fts5Parse *pParse, const char *zFmt, ...){
|
||||
va_list ap;
|
||||
va_start(ap, zFmt);
|
||||
if( pParse->rc==SQLITE_OK ){
|
||||
assert( pParse->zErr==0 );
|
||||
pParse->zErr = sqlite3_vmprintf(zFmt, ap);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
@@ -2144,9 +2145,8 @@ void sqlite3Fts5ParseSetColset(
|
||||
){
|
||||
Fts5Colset *pFree = pColset;
|
||||
if( pParse->pConfig->eDetail==FTS5_DETAIL_NONE ){
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
pParse->zErr = sqlite3_mprintf(
|
||||
"fts5: column queries are not supported (detail=none)"
|
||||
sqlite3Fts5ParseError(pParse,
|
||||
"fts5: column queries are not supported (detail=none)"
|
||||
);
|
||||
}else{
|
||||
fts5ParseSetColset(pParse, pExpr, pColset, &pFree);
|
||||
@@ -2320,13 +2320,10 @@ Fts5ExprNode *sqlite3Fts5ParseNode(
|
||||
|| pPhrase->nTerm>1
|
||||
|| (pPhrase->nTerm>0 && pPhrase->aTerm[0].bFirst)
|
||||
){
|
||||
assert( pParse->rc==SQLITE_OK );
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
assert( pParse->zErr==0 );
|
||||
pParse->zErr = sqlite3_mprintf(
|
||||
sqlite3Fts5ParseError(pParse,
|
||||
"fts5: %s queries are not supported (detail!=full)",
|
||||
pNear->nPhrase==1 ? "phrase": "NEAR"
|
||||
);
|
||||
);
|
||||
sqlite3_free(pRet);
|
||||
pRet = 0;
|
||||
}
|
||||
@@ -2412,6 +2409,7 @@ Fts5ExprNode *sqlite3Fts5ParseImplicitAnd(
|
||||
return pRet;
|
||||
}
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){
|
||||
sqlite3_int64 nByte = 0;
|
||||
Fts5ExprTerm *p;
|
||||
@@ -2778,12 +2776,14 @@ static void fts5ExprFold(
|
||||
sqlite3_result_int(pCtx, sqlite3Fts5UnicodeFold(iCode, bRemoveDiacritics));
|
||||
}
|
||||
}
|
||||
#endif /* ifdef SQLITE_TEST */
|
||||
|
||||
/*
|
||||
** This is called during initialization to register the fts5_expr() scalar
|
||||
** UDF with the SQLite handle passed as the only argument.
|
||||
*/
|
||||
int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){
|
||||
#ifdef SQLITE_TEST
|
||||
struct Fts5ExprFunc {
|
||||
const char *z;
|
||||
void (*x)(sqlite3_context*,int,sqlite3_value**);
|
||||
@@ -2801,6 +2801,10 @@ int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){
|
||||
struct Fts5ExprFunc *p = &aFunc[i];
|
||||
rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
|
||||
}
|
||||
#else
|
||||
int rc = SQLITE_OK;
|
||||
UNUSED_PARAM2(pGlobal,db);
|
||||
#endif
|
||||
|
||||
/* Avoid warnings indicating that sqlite3Fts5ParserTrace() and
|
||||
** sqlite3Fts5ParserFallback() are unused */
|
||||
|
||||
+60
-13
@@ -431,7 +431,7 @@ struct Fts5SegIter {
|
||||
int iLeafPgno; /* Current leaf page number */
|
||||
Fts5Data *pLeaf; /* Current leaf data */
|
||||
Fts5Data *pNextLeaf; /* Leaf page (iLeafPgno+1) */
|
||||
int iLeafOffset; /* Byte offset within current leaf */
|
||||
i64 iLeafOffset; /* Byte offset within current leaf */
|
||||
|
||||
/* Next method */
|
||||
void (*xNext)(Fts5Index*, Fts5SegIter*, int*);
|
||||
@@ -821,6 +821,22 @@ static void fts5StructureRef(Fts5Structure *pStruct){
|
||||
pStruct->nRef++;
|
||||
}
|
||||
|
||||
void *sqlite3Fts5StructureRef(Fts5Index *p){
|
||||
fts5StructureRef(p->pStruct);
|
||||
return (void*)p->pStruct;
|
||||
}
|
||||
void sqlite3Fts5StructureRelease(void *p){
|
||||
if( p ){
|
||||
fts5StructureRelease((Fts5Structure*)p);
|
||||
}
|
||||
}
|
||||
int sqlite3Fts5StructureTest(Fts5Index *p, void *pStruct){
|
||||
if( p->pStruct!=(Fts5Structure*)pStruct ){
|
||||
return SQLITE_ABORT;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Deserialize and return the structure record currently stored in serialized
|
||||
** form within buffer pData/nData.
|
||||
@@ -1611,7 +1627,7 @@ static void fts5SegIterLoadNPos(Fts5Index *p, Fts5SegIter *pIter){
|
||||
|
||||
static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
|
||||
u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
|
||||
int iOff = pIter->iLeafOffset;
|
||||
i64 iOff = pIter->iLeafOffset;
|
||||
|
||||
ASSERT_SZLEAF_OK(pIter->pLeaf);
|
||||
if( iOff>=pIter->pLeaf->szLeaf ){
|
||||
@@ -1644,7 +1660,7 @@ static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
|
||||
*/
|
||||
static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
|
||||
u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
|
||||
int iOff = pIter->iLeafOffset; /* Offset to read at */
|
||||
i64 iOff = pIter->iLeafOffset; /* Offset to read at */
|
||||
int nNew; /* Bytes of new data */
|
||||
|
||||
iOff += fts5GetVarint32(&a[iOff], nNew);
|
||||
@@ -2072,7 +2088,6 @@ static void fts5SegIterNext(
|
||||
** this block is particularly performance critical, so equivalent
|
||||
** code is inlined. */
|
||||
int nSz;
|
||||
assert( p->rc==SQLITE_OK );
|
||||
assert_nc( pIter->iLeafOffset<=pIter->pLeaf->nn );
|
||||
fts5FastGetVarint32(pIter->pLeaf->p, pIter->iLeafOffset, nSz);
|
||||
pIter->bDel = (nSz & 0x0001);
|
||||
@@ -3184,7 +3199,7 @@ static void fts5IndexExtractColset(
|
||||
}
|
||||
fts5BufferSafeAppendBlob(&pIter->poslist, aCopy, p-aCopy);
|
||||
}
|
||||
if( p==pEnd ){
|
||||
if( p>=pEnd ){
|
||||
pIter->base.pData = pIter->poslist.p;
|
||||
pIter->base.nData = pIter->poslist.n;
|
||||
return;
|
||||
@@ -4541,14 +4556,14 @@ static void fts5FlushOneHash(Fts5Index *p){
|
||||
fts5BufferSafeAppendBlob(pBuf, pDoclist, nDoclist);
|
||||
}else{
|
||||
i64 iRowid = 0;
|
||||
i64 iDelta = 0;
|
||||
u64 iDelta = 0;
|
||||
int iOff = 0;
|
||||
|
||||
/* The entire doclist will not fit on this leaf. The following
|
||||
** loop iterates through the poslists that make up the current
|
||||
** doclist. */
|
||||
while( p->rc==SQLITE_OK && iOff<nDoclist ){
|
||||
iOff += fts5GetVarint(&pDoclist[iOff], (u64*)&iDelta);
|
||||
iOff += fts5GetVarint(&pDoclist[iOff], &iDelta);
|
||||
iRowid += iDelta;
|
||||
|
||||
if( writer.bFirstRowidInPage ){
|
||||
@@ -4822,6 +4837,9 @@ static void fts5DoclistIterNext(Fts5DoclistIter *pIter){
|
||||
}
|
||||
|
||||
pIter->aPoslist = p;
|
||||
if( &pIter->aPoslist[pIter->nPoslist]>pIter->aEof ){
|
||||
pIter->aPoslist = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4830,9 +4848,11 @@ static void fts5DoclistIterInit(
|
||||
Fts5DoclistIter *pIter
|
||||
){
|
||||
memset(pIter, 0, sizeof(*pIter));
|
||||
pIter->aPoslist = pBuf->p;
|
||||
pIter->aEof = &pBuf->p[pBuf->n];
|
||||
fts5DoclistIterNext(pIter);
|
||||
if( pBuf->n>0 ){
|
||||
pIter->aPoslist = pBuf->p;
|
||||
pIter->aEof = &pBuf->p[pBuf->n];
|
||||
fts5DoclistIterNext(pIter);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -4975,7 +4995,7 @@ static void fts5MergePrefixLists(
|
||||
Fts5Buffer *aBuf /* Other lists to merge in */
|
||||
){
|
||||
#define fts5PrefixMergerNextPosition(p) \
|
||||
sqlite3Fts5PoslistNext64((p)->aPos,(p)->iter.nPoslist,&(p)->iOff,&(p)->iPos);
|
||||
sqlite3Fts5PoslistNext64((p)->aPos,(p)->iter.nPoslist,&(p)->iOff,&(p)->iPos)
|
||||
#define FTS5_MERGE_NLIST 16
|
||||
PrefixMerger aMerger[FTS5_MERGE_NLIST];
|
||||
PrefixMerger *pHead = 0;
|
||||
@@ -5074,7 +5094,8 @@ static void fts5MergePrefixLists(
|
||||
nTail = pHead->iter.nPoslist - pHead->iOff;
|
||||
|
||||
/* WRITEPOSLISTSIZE */
|
||||
assert( tmp.n+nTail<=nTmp );
|
||||
assert_nc( tmp.n+nTail<=nTmp );
|
||||
assert( tmp.n+nTail<=nTmp+nMerge*10 );
|
||||
if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){
|
||||
if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
|
||||
break;
|
||||
@@ -5594,8 +5615,9 @@ int sqlite3Fts5IterNextFrom(Fts5IndexIter *pIndexIter, i64 iMatch){
|
||||
const char *sqlite3Fts5IterTerm(Fts5IndexIter *pIndexIter, int *pn){
|
||||
int n;
|
||||
const char *z = (const char*)fts5MultiIterTerm((Fts5Iter*)pIndexIter, &n);
|
||||
assert_nc( z || n<=1 );
|
||||
*pn = n-1;
|
||||
return &z[1];
|
||||
return (z ? &z[1] : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -6220,6 +6242,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
|
||||
** function only.
|
||||
*/
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** Decode a segment-data rowid from the %_data table. This function is
|
||||
** the opposite of macro FTS5_SEGMENT_ROWID().
|
||||
@@ -6242,7 +6265,9 @@ static void fts5DecodeRowid(
|
||||
|
||||
*piSegid = (int)(iRowid & (((i64)1 << FTS5_DATA_ID_B) - 1));
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
static void fts5DebugRowid(int *pRc, Fts5Buffer *pBuf, i64 iKey){
|
||||
int iSegid, iHeight, iPgno, bDlidx; /* Rowid compenents */
|
||||
fts5DecodeRowid(iKey, &iSegid, &bDlidx, &iHeight, &iPgno);
|
||||
@@ -6260,7 +6285,9 @@ static void fts5DebugRowid(int *pRc, Fts5Buffer *pBuf, i64 iKey){
|
||||
);
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
static void fts5DebugStructure(
|
||||
int *pRc, /* IN/OUT: error code */
|
||||
Fts5Buffer *pBuf,
|
||||
@@ -6282,7 +6309,9 @@ static void fts5DebugStructure(
|
||||
sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "}");
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** This is part of the fts5_decode() debugging aid.
|
||||
**
|
||||
@@ -6307,7 +6336,9 @@ static void fts5DecodeStructure(
|
||||
fts5DebugStructure(pRc, pBuf, p);
|
||||
fts5StructureRelease(p);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** This is part of the fts5_decode() debugging aid.
|
||||
**
|
||||
@@ -6330,7 +6361,9 @@ static void fts5DecodeAverages(
|
||||
zSpace = " ";
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** Buffer (a/n) is assumed to contain a list of serialized varints. Read
|
||||
** each varint and append its string representation to buffer pBuf. Return
|
||||
@@ -6347,7 +6380,9 @@ static int fts5DecodePoslist(int *pRc, Fts5Buffer *pBuf, const u8 *a, int n){
|
||||
}
|
||||
return iOff;
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** The start of buffer (a/n) contains the start of a doclist. The doclist
|
||||
** may or may not finish within the buffer. This function appends a text
|
||||
@@ -6380,7 +6415,9 @@ static int fts5DecodeDoclist(int *pRc, Fts5Buffer *pBuf, const u8 *a, int n){
|
||||
|
||||
return iOff;
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** This function is part of the fts5_decode() debugging function. It is
|
||||
** only ever used with detail=none tables.
|
||||
@@ -6421,7 +6458,9 @@ static void fts5DecodeRowidList(
|
||||
sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %lld%s", iRowid, zApp);
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** The implementation of user-defined scalar function fts5_decode().
|
||||
*/
|
||||
@@ -6630,7 +6669,9 @@ static void fts5DecodeFunction(
|
||||
}
|
||||
fts5BufferFree(&s);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** The implementation of user-defined scalar function fts5_rowid().
|
||||
*/
|
||||
@@ -6664,6 +6705,7 @@ static void fts5RowidFunction(
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
/*
|
||||
** This is called as part of registering the FTS5 module with database
|
||||
@@ -6674,6 +6716,7 @@ static void fts5RowidFunction(
|
||||
** SQLite error code is returned instead.
|
||||
*/
|
||||
int sqlite3Fts5IndexInit(sqlite3 *db){
|
||||
#ifdef SQLITE_TEST
|
||||
int rc = sqlite3_create_function(
|
||||
db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0
|
||||
);
|
||||
@@ -6691,6 +6734,10 @@ int sqlite3Fts5IndexInit(sqlite3 *db){
|
||||
);
|
||||
}
|
||||
return rc;
|
||||
#else
|
||||
return SQLITE_OK;
|
||||
UNUSED_PARAM(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
+13
-6
@@ -22,7 +22,9 @@
|
||||
** assert() conditions in the fts5 code are activated - conditions that are
|
||||
** only true if it is guaranteed that the fts5 database is not corrupt.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
int sqlite3_fts5_may_be_corrupt = 1;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct Fts5Auxdata Fts5Auxdata;
|
||||
@@ -1947,13 +1949,15 @@ static int fts5CacheInstArray(Fts5Cursor *pCsr){
|
||||
|
||||
nInst++;
|
||||
if( nInst>=pCsr->nInstAlloc ){
|
||||
pCsr->nInstAlloc = pCsr->nInstAlloc ? pCsr->nInstAlloc*2 : 32;
|
||||
int nNewSize = pCsr->nInstAlloc ? pCsr->nInstAlloc*2 : 32;
|
||||
aInst = (int*)sqlite3_realloc64(
|
||||
pCsr->aInst, pCsr->nInstAlloc*sizeof(int)*3
|
||||
pCsr->aInst, nNewSize*sizeof(int)*3
|
||||
);
|
||||
if( aInst ){
|
||||
pCsr->aInst = aInst;
|
||||
pCsr->nInstAlloc = nNewSize;
|
||||
}else{
|
||||
nInst--;
|
||||
rc = SQLITE_NOMEM;
|
||||
break;
|
||||
}
|
||||
@@ -2177,7 +2181,8 @@ static int fts5ApiPhraseFirst(
|
||||
int n;
|
||||
int rc = fts5CsrPoslist(pCsr, iPhrase, &pIter->a, &n);
|
||||
if( rc==SQLITE_OK ){
|
||||
pIter->b = &pIter->a[n];
|
||||
assert( pIter->a || n==0 );
|
||||
pIter->b = (pIter->a ? &pIter->a[n] : 0);
|
||||
*piCol = 0;
|
||||
*piOff = 0;
|
||||
fts5ApiPhraseNext(pCtx, pIter, piCol, piOff);
|
||||
@@ -2236,7 +2241,8 @@ static int fts5ApiPhraseFirstColumn(
|
||||
rc = sqlite3Fts5ExprPhraseCollist(pCsr->pExpr, iPhrase, &pIter->a, &n);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
pIter->b = &pIter->a[n];
|
||||
assert( pIter->a || n==0 );
|
||||
pIter->b = (pIter->a ? &pIter->a[n] : 0);
|
||||
*piCol = 0;
|
||||
fts5ApiPhraseNextColumn(pCtx, pIter, piCol);
|
||||
}
|
||||
@@ -2244,7 +2250,8 @@ static int fts5ApiPhraseFirstColumn(
|
||||
int n;
|
||||
rc = fts5CsrPoslist(pCsr, iPhrase, &pIter->a, &n);
|
||||
if( rc==SQLITE_OK ){
|
||||
pIter->b = &pIter->a[n];
|
||||
assert( pIter->a || n==0 );
|
||||
pIter->b = (pIter->a ? &pIter->a[n] : 0);
|
||||
if( n<=0 ){
|
||||
*piCol = -1;
|
||||
}else if( pIter->a[0]==0x01 ){
|
||||
@@ -2722,7 +2729,7 @@ int sqlite3Fts5GetTokenizer(
|
||||
*pzErr = sqlite3_mprintf("no such tokenizer: %s", azArg[0]);
|
||||
}else{
|
||||
rc = pMod->x.xCreate(
|
||||
pMod->pUserData, &azArg[1], (nArg?nArg-1:0), &pConfig->pTok
|
||||
pMod->pUserData, (azArg?&azArg[1]:0), (nArg?nArg-1:0), &pConfig->pTok
|
||||
);
|
||||
pConfig->pTokApi = &pMod->x;
|
||||
if( rc!=SQLITE_OK ){
|
||||
|
||||
@@ -29,7 +29,9 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
extern int sqlite3_fts5_may_be_corrupt;
|
||||
#endif
|
||||
extern int sqlite3Fts5TestRegisterMatchinfo(sqlite3*);
|
||||
extern int sqlite3Fts5TestRegisterTok(sqlite3*, fts5_api*);
|
||||
|
||||
@@ -1011,6 +1013,7 @@ static int SQLITE_TCLAPI f5tMayBeCorrupt(
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
#ifdef SQLITE_DEBUG
|
||||
int bOld = sqlite3_fts5_may_be_corrupt;
|
||||
|
||||
if( objc!=2 && objc!=1 ){
|
||||
@@ -1024,6 +1027,7 @@ static int SQLITE_TCLAPI f5tMayBeCorrupt(
|
||||
}
|
||||
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(bOld));
|
||||
#endif
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ static int fts5tokConnectMethod(
|
||||
|
||||
rc = pApi->xFindTokenizer(pApi, zModule, &pTokCtx, &pTab->tok);
|
||||
if( rc==SQLITE_OK ){
|
||||
const char **azArg = (const char **)&azDequote[1];
|
||||
const char **azArg = (nDequote>1 ? (const char **)&azDequote[1] : 0);
|
||||
int nArg = nDequote>0 ? nDequote-1 : 0;
|
||||
rc = pTab->tok.xCreate(pTokCtx, azArg, nArg, &pTab->pTok);
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ struct Fts5VocabCursor {
|
||||
|
||||
int bEof; /* True if this cursor is at EOF */
|
||||
Fts5IndexIter *pIter; /* Term/rowid iterator object */
|
||||
void *pStruct; /* From sqlite3Fts5StructureRef() */
|
||||
|
||||
int nLeTerm; /* Size of zLeTerm in bytes */
|
||||
char *zLeTerm; /* (term <= $zLeTerm) paramater, or NULL */
|
||||
@@ -393,6 +394,8 @@ static int fts5VocabOpenMethod(
|
||||
static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){
|
||||
pCsr->rowid = 0;
|
||||
sqlite3Fts5IterClose(pCsr->pIter);
|
||||
sqlite3Fts5StructureRelease(pCsr->pStruct);
|
||||
pCsr->pStruct = 0;
|
||||
pCsr->pIter = 0;
|
||||
sqlite3_free(pCsr->zLeTerm);
|
||||
pCsr->nLeTerm = -1;
|
||||
@@ -470,9 +473,11 @@ static int fts5VocabInstanceNext(Fts5VocabCursor *pCsr){
|
||||
static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
|
||||
Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab;
|
||||
int rc = SQLITE_OK;
|
||||
int nCol = pCsr->pFts5->pConfig->nCol;
|
||||
int rc;
|
||||
|
||||
rc = sqlite3Fts5StructureTest(pCsr->pFts5->pIndex, pCsr->pStruct);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
pCsr->rowid++;
|
||||
|
||||
if( pTab->eType==FTS5_VOCAB_INSTANCE ){
|
||||
@@ -646,6 +651,9 @@ static int fts5VocabFilterMethod(
|
||||
if( rc==SQLITE_OK ){
|
||||
Fts5Index *pIndex = pCsr->pFts5->pIndex;
|
||||
rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
|
||||
if( rc==SQLITE_OK ){
|
||||
pCsr->pStruct = sqlite3Fts5StructureRef(pIndex);
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE_OK && eType==FTS5_VOCAB_INSTANCE ){
|
||||
rc = fts5VocabInstanceNewTerm(pCsr);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -212,6 +212,10 @@ do_catchsql_test 4.1 {
|
||||
SELECT * FROM t4('a:a')
|
||||
} {1 {fts5: column queries are not supported (detail=none)}}
|
||||
|
||||
do_catchsql_test 4.2 {
|
||||
SELECT * FROM t4('a:a &')
|
||||
} {1 {fts5: syntax error near "&"}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that for the same content detail=none uses less space than
|
||||
# detail=col, and that detail=col uses less space than detail=full
|
||||
|
||||
@@ -42,5 +42,26 @@ do_execsql_test 1.2 {
|
||||
INSERT INTO ccc(ccc) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 2.1 {
|
||||
CREATE VIRTUAL TABLE tx USING fts5(x);
|
||||
}
|
||||
|
||||
set doc [string repeat "abc " 5000]
|
||||
do_execsql_test 2.2 {
|
||||
BEGIN;
|
||||
INSERT INTO tx(rowid, x) VALUES(-9000000000000000000, $doc);
|
||||
INSERT INTO tx(rowid, x) VALUES(9000000000000000000, $doc);
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
do_execsql_test 2.3 {
|
||||
SELECT rowid FROM tx('abc');
|
||||
} {
|
||||
-9000000000000000000
|
||||
9000000000000000000
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -323,5 +323,34 @@ do_execsql_test 12.3 {
|
||||
SELECT * FROM t2 JOIN ft USING (ft)
|
||||
} {3 4 b b}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Forum post https://sqlite.org/forum/forumpost/21127c1160
|
||||
#
|
||||
reset_db
|
||||
sqlite3_db_config db DEFENSIVE 1
|
||||
|
||||
do_execsql_test 13.0 {
|
||||
CREATE TABLE a (id INTEGER PRIMARY KEY, name TEXT);
|
||||
CREATE VIRTUAL TABLE b USING fts5(name);
|
||||
CREATE TRIGGER a_trigger AFTER INSERT ON a BEGIN
|
||||
INSERT INTO b (name) VALUES ('foo');
|
||||
END;
|
||||
}
|
||||
|
||||
do_test 13.1 {
|
||||
set ::STMT [
|
||||
sqlite3_prepare db "INSERT INTO a VALUES (1, 'foo') RETURNING id;" -1 dummy
|
||||
]
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
|
||||
do_test 13.2 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test 13.3 {
|
||||
sqlite3_errmsg db
|
||||
} {not an error}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -30,23 +30,23 @@ do_eqp_test 1.1 {
|
||||
SELECT * FROM t1, f1 WHERE f1 MATCH t1.x
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1
|
||||
`--SCAN TABLE f1 VIRTUAL TABLE INDEX 0:M1
|
||||
|--SCAN t1
|
||||
`--SCAN f1 VIRTUAL TABLE INDEX 0:M1
|
||||
}
|
||||
|
||||
do_eqp_test 1.2 {
|
||||
SELECT * FROM t1, f1 WHERE f1 > t1.x
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE f1 VIRTUAL TABLE INDEX 0:
|
||||
`--SCAN TABLE t1
|
||||
|--SCAN f1 VIRTUAL TABLE INDEX 0:
|
||||
`--SCAN t1
|
||||
}
|
||||
|
||||
do_eqp_test 1.3 {
|
||||
SELECT * FROM f1 WHERE f1 MATCH ? ORDER BY ff
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE f1 VIRTUAL TABLE INDEX 0:M1
|
||||
|--SCAN f1 VIRTUAL TABLE INDEX 0:M1
|
||||
`--USE TEMP B-TREE FOR ORDER BY
|
||||
}
|
||||
|
||||
@@ -54,12 +54,12 @@ do_eqp_test 1.4 {
|
||||
SELECT * FROM f1 ORDER BY rank
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE f1 VIRTUAL TABLE INDEX 0:
|
||||
|--SCAN f1 VIRTUAL TABLE INDEX 0:
|
||||
`--USE TEMP B-TREE FOR ORDER BY
|
||||
}
|
||||
|
||||
do_eqp_test 1.5 {
|
||||
SELECT * FROM f1 WHERE rank MATCH ?
|
||||
} {SCAN TABLE f1 VIRTUAL TABLE INDEX 0:r}
|
||||
} {SCAN f1 VIRTUAL TABLE INDEX 0:r}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -192,10 +192,9 @@ do_eqp_test 6.2 {
|
||||
} {VIRTUAL TABLE INDEX 0:G0}
|
||||
do_eqp_test 6.3 {
|
||||
SELECT * FROM ci1 WHERE x LIKE ?
|
||||
} {{SCAN TABLE ci1 VIRTUAL TABLE INDEX 0:}}
|
||||
} {{SCAN ci1 VIRTUAL TABLE INDEX 0:}}
|
||||
do_eqp_test 6.4 {
|
||||
SELECT * FROM ci1 WHERE x GLOB ?
|
||||
} {VIRTUAL TABLE INDEX 0:G0}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -234,4 +234,27 @@ ifcapable fts3 {
|
||||
} {1 {no such fts5 table: main.nosuchtable}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Check that the fts5 table cannot be written while there are vocab
|
||||
# cursors open.
|
||||
reset_db
|
||||
do_execsql_test 5.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(a);
|
||||
CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
|
||||
INSERT INTO t1 VALUES('one'), ('two'), ('three'), ('four');
|
||||
}
|
||||
|
||||
do_test 5.1 {
|
||||
list [catch {
|
||||
db eval { SELECT * FROM v1 } {
|
||||
db eval {INSERT INTO t1 VALUES('five')}
|
||||
}
|
||||
} msg] $msg
|
||||
} {1 {query aborted}}
|
||||
|
||||
do_execsql_test 5.2 {
|
||||
SELECT * FROM t1
|
||||
} {one two three four five}
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
+223
-116
@@ -14,24 +14,23 @@
|
||||
** appended onto the end of some other file, such as an executable.
|
||||
**
|
||||
** A special record must appear at the end of the file that identifies the
|
||||
** file as an appended database and provides an offset to page 1. For
|
||||
** best performance page 1 should be located at a disk page boundary, though
|
||||
** that is not required.
|
||||
** file as an appended database and provides the offset to the first page
|
||||
** of the exposed content. (Or, it is the length of the content prefix.)
|
||||
** For best performance page 1 should be located at a disk page boundary,
|
||||
** though that is not required.
|
||||
**
|
||||
** When opening a database using this VFS, the connection might treat
|
||||
** the file as an ordinary SQLite database, or it might treat is as a
|
||||
** database appended onto some other file. Here are the rules:
|
||||
** the file as an ordinary SQLite database, or it might treat it as a
|
||||
** database appended onto some other file. The decision is made by
|
||||
** applying the following rules in order:
|
||||
**
|
||||
** (1) When opening a new empty file, that file is treated as an ordinary
|
||||
** database.
|
||||
** (1) An empty file is an ordinary database.
|
||||
**
|
||||
** (2) When opening a file that begins with the standard SQLite prefix
|
||||
** string "SQLite format 3", that file is treated as an ordinary
|
||||
** database.
|
||||
** (2) If the file ends with the appendvfs trailer string
|
||||
** "Start-Of-SQLite3-NNNNNNNN" that file is an appended database.
|
||||
**
|
||||
** (3) When opening a file that ends with the appendvfs trailer string
|
||||
** "Start-Of-SQLite3-NNNNNNNN" that file is treated as an appended
|
||||
** database.
|
||||
** (3) If the file begins with the standard SQLite prefix string
|
||||
** "SQLite format 3", that file is an ordinary database.
|
||||
**
|
||||
** (4) If none of the above apply and the SQLITE_OPEN_CREATE flag is
|
||||
** set, then a new database is appended to the already existing file.
|
||||
@@ -39,13 +38,13 @@
|
||||
** (5) Otherwise, SQLITE_CANTOPEN is returned.
|
||||
**
|
||||
** To avoid unnecessary complications with the PENDING_BYTE, the size of
|
||||
** the file containing the database is limited to 1GB. This VFS will refuse
|
||||
** to read or write past the 1GB mark. This restriction might be lifted in
|
||||
** future versions. For now, if you need a large database, then keep the
|
||||
** database in a separate file.
|
||||
** the file containing the database is limited to 1GiB. (1073741824 bytes)
|
||||
** This VFS will not read or write past the 1GiB mark. This restriction
|
||||
** might be lifted in future versions. For now, if you need a larger
|
||||
** database, then keep it in a separate file.
|
||||
**
|
||||
** If the file being opened is not an appended database, then this shim is
|
||||
** a pass-through into the default underlying VFS.
|
||||
** If the file being opened is a plain database (not an appended one), then
|
||||
** this shim is a pass-through into the default underlying VFS. (rule 3)
|
||||
**/
|
||||
#include "sqlite3ext.h"
|
||||
SQLITE_EXTENSION_INIT1
|
||||
@@ -58,17 +57,27 @@ SQLITE_EXTENSION_INIT1
|
||||
** 123456789 123456789 12345
|
||||
**
|
||||
** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
|
||||
** the offset to page 1.
|
||||
** the offset to page 1, and also the length of the prefix content.
|
||||
*/
|
||||
#define APND_MARK_PREFIX "Start-Of-SQLite3-"
|
||||
#define APND_MARK_PREFIX_SZ 17
|
||||
#define APND_MARK_SIZE 25
|
||||
#define APND_MARK_FOS_SZ 8
|
||||
#define APND_MARK_SIZE (APND_MARK_PREFIX_SZ+APND_MARK_FOS_SZ)
|
||||
|
||||
/*
|
||||
** Maximum size of the combined prefix + database + append-mark. This
|
||||
** must be less than 0x40000000 to avoid locking issues on Windows.
|
||||
*/
|
||||
#define APND_MAX_SIZE (65536*15259)
|
||||
#define APND_MAX_SIZE (0x40000000)
|
||||
|
||||
/*
|
||||
** Try to align the database to an even multiple of APND_ROUNDUP bytes.
|
||||
*/
|
||||
#ifndef APND_ROUNDUP
|
||||
#define APND_ROUNDUP 4096
|
||||
#endif
|
||||
#define APND_ALIGN_MASK ((sqlite3_int64)(APND_ROUNDUP-1))
|
||||
#define APND_START_ROUNDUP(fsz) (((fsz)+APND_ALIGN_MASK) & ~APND_ALIGN_MASK)
|
||||
|
||||
/*
|
||||
** Forward declaration of objects used by this utility
|
||||
@@ -82,11 +91,45 @@ typedef struct ApndFile ApndFile;
|
||||
#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
|
||||
#define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
|
||||
|
||||
/* An open file */
|
||||
/* An open appendvfs file
|
||||
**
|
||||
** An instance of this structure describes the appended database file.
|
||||
** A separate sqlite3_file object is always appended. The appended
|
||||
** sqlite3_file object (which can be accessed using ORIGFILE()) describes
|
||||
** the entire file, including the prefix, the database, and the
|
||||
** append-mark.
|
||||
**
|
||||
** The structure of an AppendVFS database is like this:
|
||||
**
|
||||
** +-------------+---------+----------+-------------+
|
||||
** | prefix-file | padding | database | append-mark |
|
||||
** +-------------+---------+----------+-------------+
|
||||
** ^ ^
|
||||
** | |
|
||||
** iPgOne iMark
|
||||
**
|
||||
**
|
||||
** "prefix file" - file onto which the database has been appended.
|
||||
** "padding" - zero or more bytes inserted so that "database"
|
||||
** starts on an APND_ROUNDUP boundary
|
||||
** "database" - The SQLite database file
|
||||
** "append-mark" - The 25-byte "Start-Of-SQLite3-NNNNNNNN" that indicates
|
||||
** the offset from the start of prefix-file to the start
|
||||
** of "database".
|
||||
**
|
||||
** The size of the database is iMark - iPgOne.
|
||||
**
|
||||
** The NNNNNNNN in the "Start-Of-SQLite3-NNNNNNNN" suffix is the value
|
||||
** of iPgOne stored as a big-ending 64-bit integer.
|
||||
**
|
||||
** iMark will be the size of the underlying file minus 25 (APND_MARKSIZE).
|
||||
** Or, iMark is -1 to indicate that it has not yet been written.
|
||||
*/
|
||||
struct ApndFile {
|
||||
sqlite3_file base; /* IO methods */
|
||||
sqlite3_int64 iPgOne; /* File offset to page 1 */
|
||||
sqlite3_int64 iMark; /* Start of the append-mark */
|
||||
sqlite3_file base; /* Subclass. MUST BE FIRST! */
|
||||
sqlite3_int64 iPgOne; /* Offset to the start of the database */
|
||||
sqlite3_int64 iMark; /* Offset of the append mark. -1 if unwritten */
|
||||
/* Always followed by another sqlite3_file that describes the whole file */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -178,8 +221,6 @@ static const sqlite3_io_methods apnd_io_methods = {
|
||||
apndUnfetch /* xUnfetch */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Close an apnd-file.
|
||||
*/
|
||||
@@ -197,22 +238,37 @@ static int apndRead(
|
||||
int iAmt,
|
||||
sqlite_int64 iOfst
|
||||
){
|
||||
ApndFile *p = (ApndFile *)pFile;
|
||||
ApndFile *paf = (ApndFile *)pFile;
|
||||
pFile = ORIGFILE(pFile);
|
||||
return pFile->pMethods->xRead(pFile, zBuf, iAmt, iOfst+p->iPgOne);
|
||||
return pFile->pMethods->xRead(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
|
||||
}
|
||||
|
||||
/*
|
||||
** Add the append-mark onto the end of the file.
|
||||
** Add the append-mark onto what should become the end of the file.
|
||||
* If and only if this succeeds, internal ApndFile.iMark is updated.
|
||||
* Parameter iWriteEnd is the appendvfs-relative offset of the new mark.
|
||||
*/
|
||||
static int apndWriteMark(ApndFile *p, sqlite3_file *pFile){
|
||||
int i;
|
||||
static int apndWriteMark(
|
||||
ApndFile *paf,
|
||||
sqlite3_file *pFile,
|
||||
sqlite_int64 iWriteEnd
|
||||
){
|
||||
sqlite_int64 iPgOne = paf->iPgOne;
|
||||
unsigned char a[APND_MARK_SIZE];
|
||||
int i = APND_MARK_FOS_SZ;
|
||||
int rc;
|
||||
assert(pFile == ORIGFILE(paf));
|
||||
memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
|
||||
for(i=0; i<8; i++){
|
||||
a[APND_MARK_PREFIX_SZ+i] = (p->iPgOne >> (56 - i*8)) & 0xff;
|
||||
while( --i >= 0 ){
|
||||
a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
|
||||
iPgOne >>= 8;
|
||||
}
|
||||
return pFile->pMethods->xWrite(pFile, a, APND_MARK_SIZE, p->iMark);
|
||||
iWriteEnd += paf->iPgOne;
|
||||
if( SQLITE_OK==(rc = pFile->pMethods->xWrite
|
||||
(pFile, a, APND_MARK_SIZE, iWriteEnd)) ){
|
||||
paf->iMark = iWriteEnd;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -224,38 +280,28 @@ static int apndWrite(
|
||||
int iAmt,
|
||||
sqlite_int64 iOfst
|
||||
){
|
||||
int rc;
|
||||
ApndFile *p = (ApndFile *)pFile;
|
||||
ApndFile *paf = (ApndFile *)pFile;
|
||||
sqlite_int64 iWriteEnd = iOfst + iAmt;
|
||||
if( iWriteEnd>=APND_MAX_SIZE ) return SQLITE_FULL;
|
||||
pFile = ORIGFILE(pFile);
|
||||
if( iOfst+iAmt>=APND_MAX_SIZE ) return SQLITE_FULL;
|
||||
rc = pFile->pMethods->xWrite(pFile, zBuf, iAmt, iOfst+p->iPgOne);
|
||||
if( rc==SQLITE_OK && iOfst + iAmt + p->iPgOne > p->iMark ){
|
||||
sqlite3_int64 sz = 0;
|
||||
rc = pFile->pMethods->xFileSize(pFile, &sz);
|
||||
if( rc==SQLITE_OK ){
|
||||
p->iMark = sz - APND_MARK_SIZE;
|
||||
if( iOfst + iAmt + p->iPgOne > p->iMark ){
|
||||
p->iMark = p->iPgOne + iOfst + iAmt;
|
||||
rc = apndWriteMark(p, pFile);
|
||||
}
|
||||
}
|
||||
/* If append-mark is absent or will be overwritten, write it. */
|
||||
if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){
|
||||
int rc = apndWriteMark(paf, pFile, iWriteEnd);
|
||||
if( SQLITE_OK!=rc ) return rc;
|
||||
}
|
||||
return rc;
|
||||
return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate an apnd-file.
|
||||
*/
|
||||
static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
|
||||
int rc;
|
||||
ApndFile *p = (ApndFile *)pFile;
|
||||
ApndFile *paf = (ApndFile *)pFile;
|
||||
pFile = ORIGFILE(pFile);
|
||||
rc = pFile->pMethods->xTruncate(pFile, size+p->iPgOne+APND_MARK_SIZE);
|
||||
if( rc==SQLITE_OK ){
|
||||
p->iMark = p->iPgOne+size;
|
||||
rc = apndWriteMark(p, pFile);
|
||||
}
|
||||
return rc;
|
||||
/* The append mark goes out first so truncate failure does not lose it. */
|
||||
if( SQLITE_OK!=apndWriteMark(paf, pFile, size) ) return SQLITE_IOERR;
|
||||
/* Truncate underlying file just past append mark */
|
||||
return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -268,16 +314,12 @@ static int apndSync(sqlite3_file *pFile, int flags){
|
||||
|
||||
/*
|
||||
** Return the current file-size of an apnd-file.
|
||||
** If the append mark is not yet there, the file-size is 0.
|
||||
*/
|
||||
static int apndFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
|
||||
ApndFile *p = (ApndFile *)pFile;
|
||||
int rc;
|
||||
pFile = ORIGFILE(p);
|
||||
rc = pFile->pMethods->xFileSize(pFile, pSize);
|
||||
if( rc==SQLITE_OK && p->iPgOne ){
|
||||
*pSize -= p->iPgOne + APND_MARK_SIZE;
|
||||
}
|
||||
return rc;
|
||||
ApndFile *paf = (ApndFile *)pFile;
|
||||
*pSize = ( paf->iMark >= 0 )? (paf->iMark - paf->iPgOne) : 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -308,12 +350,13 @@ static int apndCheckReservedLock(sqlite3_file *pFile, int *pResOut){
|
||||
** File control method. For custom operations on an apnd-file.
|
||||
*/
|
||||
static int apndFileControl(sqlite3_file *pFile, int op, void *pArg){
|
||||
ApndFile *p = (ApndFile *)pFile;
|
||||
ApndFile *paf = (ApndFile *)pFile;
|
||||
int rc;
|
||||
pFile = ORIGFILE(pFile);
|
||||
if( op==SQLITE_FCNTL_SIZE_HINT ) *(sqlite3_int64*)pArg += paf->iPgOne;
|
||||
rc = pFile->pMethods->xFileControl(pFile, op, pArg);
|
||||
if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
|
||||
*(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", p->iPgOne, *(char**)pArg);
|
||||
*(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", paf->iPgOne,*(char**)pArg);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -372,6 +415,9 @@ static int apndFetch(
|
||||
void **pp
|
||||
){
|
||||
ApndFile *p = (ApndFile *)pFile;
|
||||
if( p->iMark < 0 || iOfst+iAmt > p->iMark ){
|
||||
return SQLITE_IOERR; /* Cannot read what is not yet there. */
|
||||
}
|
||||
pFile = ORIGFILE(pFile);
|
||||
return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
|
||||
}
|
||||
@@ -383,95 +429,155 @@ static int apndUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
|
||||
return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
|
||||
}
|
||||
|
||||
/*
|
||||
** Check to see if the file is an ordinary SQLite database file.
|
||||
*/
|
||||
static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
|
||||
int rc;
|
||||
char zHdr[16];
|
||||
static const char aSqliteHdr[] = "SQLite format 3";
|
||||
if( sz<512 ) return 0;
|
||||
rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0);
|
||||
if( rc ) return 0;
|
||||
return memcmp(zHdr, aSqliteHdr, sizeof(zHdr))==0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Try to read the append-mark off the end of a file. Return the
|
||||
** start of the appended database if the append-mark is present. If
|
||||
** there is no append-mark, return -1;
|
||||
** start of the appended database if the append-mark is present.
|
||||
** If there is no valid append-mark, return -1;
|
||||
**
|
||||
** An append-mark is only valid if the NNNNNNNN start-of-database offset
|
||||
** indicates that the appended database contains at least one page. The
|
||||
** start-of-database value must be a multiple of 512.
|
||||
*/
|
||||
static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile){
|
||||
int rc, i;
|
||||
sqlite3_int64 iMark;
|
||||
int msbs = 8 * (APND_MARK_FOS_SZ-1);
|
||||
unsigned char a[APND_MARK_SIZE];
|
||||
|
||||
if( sz<=APND_MARK_SIZE ) return -1;
|
||||
if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1;
|
||||
rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
|
||||
if( rc ) return -1;
|
||||
if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
|
||||
iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ]&0x7f))<<56;
|
||||
for(i=1; i<8; i++){
|
||||
iMark += (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<(56-8*i);
|
||||
iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ] & 0x7f)) << msbs;
|
||||
for(i=1; i<8; i++){
|
||||
msbs -= 8;
|
||||
iMark |= (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<msbs;
|
||||
}
|
||||
if( iMark > (sz - APND_MARK_SIZE - 512) ) return -1;
|
||||
if( iMark & 0x1ff ) return -1;
|
||||
return iMark;
|
||||
}
|
||||
|
||||
static const char apvfsSqliteHdr[] = "SQLite format 3";
|
||||
/*
|
||||
** Check to see if the file is an appendvfs SQLite database file.
|
||||
** Return true iff it is such. Parameter sz is the file's size.
|
||||
*/
|
||||
static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile){
|
||||
int rc;
|
||||
char zHdr[16];
|
||||
sqlite3_int64 iMark = apndReadMark(sz, pFile);
|
||||
if( iMark>=0 ){
|
||||
/* If file has the correct end-marker, the expected odd size, and the
|
||||
** SQLite DB type marker where the end-marker puts it, then it
|
||||
** is an appendvfs database.
|
||||
*/
|
||||
rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
|
||||
if( SQLITE_OK==rc
|
||||
&& memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
|
||||
&& (sz & 0x1ff) == APND_MARK_SIZE
|
||||
&& sz>=512+APND_MARK_SIZE
|
||||
){
|
||||
return 1; /* It's an appendvfs database */
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Check to see if the file is an ordinary SQLite database file.
|
||||
** Return true iff so. Parameter sz is the file's size.
|
||||
*/
|
||||
static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
|
||||
char zHdr[16];
|
||||
if( apndIsAppendvfsDatabase(sz, pFile) /* rule 2 */
|
||||
|| (sz & 0x1ff) != 0
|
||||
|| SQLITE_OK!=pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0)
|
||||
|| memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))!=0
|
||||
){
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Open an apnd file handle.
|
||||
*/
|
||||
static int apndOpen(
|
||||
sqlite3_vfs *pVfs,
|
||||
sqlite3_vfs *pApndVfs,
|
||||
const char *zName,
|
||||
sqlite3_file *pFile,
|
||||
int flags,
|
||||
int *pOutFlags
|
||||
){
|
||||
ApndFile *p;
|
||||
sqlite3_file *pSubFile;
|
||||
sqlite3_vfs *pSubVfs;
|
||||
ApndFile *pApndFile = (ApndFile*)pFile;
|
||||
sqlite3_file *pBaseFile = ORIGFILE(pFile);
|
||||
sqlite3_vfs *pBaseVfs = ORIGVFS(pApndVfs);
|
||||
int rc;
|
||||
sqlite3_int64 sz;
|
||||
pSubVfs = ORIGVFS(pVfs);
|
||||
sqlite3_int64 sz = 0;
|
||||
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
|
||||
return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
|
||||
/* The appendvfs is not to be used for transient or temporary databases.
|
||||
** Just use the base VFS open to initialize the given file object and
|
||||
** open the underlying file. (Appendvfs is then unused for this file.)
|
||||
*/
|
||||
return pBaseVfs->xOpen(pBaseVfs, zName, pFile, flags, pOutFlags);
|
||||
}
|
||||
p = (ApndFile*)pFile;
|
||||
memset(p, 0, sizeof(*p));
|
||||
pSubFile = ORIGFILE(pFile);
|
||||
memset(pApndFile, 0, sizeof(ApndFile));
|
||||
pFile->pMethods = &apnd_io_methods;
|
||||
rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
|
||||
if( rc ) goto apnd_open_done;
|
||||
rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
|
||||
if( rc ){
|
||||
pSubFile->pMethods->xClose(pSubFile);
|
||||
goto apnd_open_done;
|
||||
pApndFile->iMark = -1; /* Append mark not yet written */
|
||||
|
||||
rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
|
||||
if( rc ){
|
||||
pBaseFile->pMethods->xClose(pBaseFile);
|
||||
}
|
||||
}
|
||||
if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
|
||||
memmove(pFile, pSubFile, pSubVfs->szOsFile);
|
||||
if( rc ){
|
||||
pFile->pMethods = 0;
|
||||
return rc;
|
||||
}
|
||||
if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
|
||||
/* The file being opened appears to be just an ordinary DB. Copy
|
||||
** the base dispatch-table so this instance mimics the base VFS.
|
||||
*/
|
||||
memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
p->iMark = 0;
|
||||
p->iPgOne = apndReadMark(sz, pFile);
|
||||
if( p->iPgOne>0 ){
|
||||
pApndFile->iPgOne = apndReadMark(sz, pFile);
|
||||
if( pApndFile->iPgOne>=0 ){
|
||||
pApndFile->iMark = sz - APND_MARK_SIZE; /* Append mark found */
|
||||
return SQLITE_OK;
|
||||
}
|
||||
if( (flags & SQLITE_OPEN_CREATE)==0 ){
|
||||
pSubFile->pMethods->xClose(pSubFile);
|
||||
pBaseFile->pMethods->xClose(pBaseFile);
|
||||
rc = SQLITE_CANTOPEN;
|
||||
pFile->pMethods = 0;
|
||||
}else{
|
||||
/* Round newly added appendvfs location to #define'd page boundary.
|
||||
** Note that nothing has yet been written to the underlying file.
|
||||
** The append mark will be written along with first content write.
|
||||
** Until then, paf->iMark value indicates it is not yet written.
|
||||
*/
|
||||
pApndFile->iPgOne = APND_START_ROUNDUP(sz);
|
||||
}
|
||||
p->iPgOne = (sz+0xfff) & ~(sqlite3_int64)0xfff;
|
||||
apnd_open_done:
|
||||
if( rc ) pFile->pMethods = 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete an apnd file.
|
||||
** For an appendvfs, this could mean delete the appendvfs portion,
|
||||
** leaving the appendee as it was before it gained an appendvfs.
|
||||
** For now, this code deletes the underlying file too.
|
||||
*/
|
||||
static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
|
||||
return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
|
||||
}
|
||||
|
||||
/*
|
||||
** All other VFS methods are pass-thrus.
|
||||
*/
|
||||
static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
|
||||
return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
|
||||
}
|
||||
static int apndAccess(
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zPath,
|
||||
@@ -551,6 +657,7 @@ int sqlite3_appendvfs_init(
|
||||
(void)pzErrMsg;
|
||||
(void)db;
|
||||
pOrig = sqlite3_vfs_find(0);
|
||||
if( pOrig==0 ) return SQLITE_ERROR;
|
||||
apnd_vfs.iVersion = pOrig->iVersion;
|
||||
apnd_vfs.pAppData = pOrig;
|
||||
apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
|
||||
|
||||
+17
-13
@@ -56,14 +56,24 @@
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* Allowed values for the mFlags parameter to sqlite3_carray_bind().
|
||||
** Must exactly match the definitions in carray.h.
|
||||
*/
|
||||
#define CARRAY_INT32 0 /* Data is 32-bit signed integers */
|
||||
#define CARRAY_INT64 1 /* Data is 64-bit signed integers */
|
||||
#define CARRAY_DOUBLE 2 /* Data is doubles */
|
||||
#define CARRAY_TEXT 3 /* Data is char* */
|
||||
#ifndef CARRAY_INT32
|
||||
# define CARRAY_INT32 0 /* Data is 32-bit signed integers */
|
||||
# define CARRAY_INT64 1 /* Data is 64-bit signed integers */
|
||||
# define CARRAY_DOUBLE 2 /* Data is doubles */
|
||||
# define CARRAY_TEXT 3 /* Data is char* */
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_API
|
||||
# ifdef _WIN32
|
||||
# define SQLITE_API __declspec(dllexport)
|
||||
# else
|
||||
# define SQLITE_API
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
|
||||
@@ -400,10 +410,7 @@ static void carrayBindDel(void *pPtr){
|
||||
** Invoke this interface in order to bind to the single-argument
|
||||
** version of CARRAY().
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_carray_bind(
|
||||
SQLITE_API int sqlite3_carray_bind(
|
||||
sqlite3_stmt *pStmt,
|
||||
int idx,
|
||||
void *aData,
|
||||
@@ -498,10 +505,7 @@ static void inttoptrFunc(
|
||||
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_carray_init(
|
||||
SQLITE_API int sqlite3_carray_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
|
||||
+28
-1
@@ -1,12 +1,32 @@
|
||||
/*
|
||||
** 2020-11-17
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** Interface definitions for the CARRAY table-valued function
|
||||
** extension.
|
||||
*/
|
||||
|
||||
#ifndef _CARRAY_H
|
||||
#define _CARRAY_H
|
||||
|
||||
#include "sqlite3.h" /* Required for error code definitions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Use this interface to bind an array to the single-argument version
|
||||
** of CARRAY().
|
||||
*/
|
||||
int sqlite3_carray_bind(
|
||||
SQLITE_API int sqlite3_carray_bind(
|
||||
sqlite3_stmt *pStmt, /* Statement to be bound */
|
||||
int i, /* Parameter index */
|
||||
void *aData, /* Pointer to array data */
|
||||
@@ -21,3 +41,10 @@ int sqlite3_carray_bind(
|
||||
#define CARRAY_INT64 1 /* Data is 64-bit signed integers */
|
||||
#define CARRAY_DOUBLE 2 /* Data is doubles */
|
||||
#define CARRAY_TEXT 3 /* Data is char* */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* end of the 'extern "C"' block */
|
||||
#endif
|
||||
|
||||
#endif /* ifndef _CARRAY_H */
|
||||
|
||||
|
||||
+15
-3
@@ -579,6 +579,18 @@ static int cksmFileControl(sqlite3_file *pFile, int op, void *pArg){
|
||||
}else if( op==SQLITE_FCNTL_CKPT_START || op==SQLITE_FCNTL_CKPT_DONE ){
|
||||
p->inCkpt = op==SQLITE_FCNTL_CKPT_START;
|
||||
if( p->pPartner ) p->pPartner->inCkpt = p->inCkpt;
|
||||
}else if( op==SQLITE_FCNTL_CKSM_FILE ){
|
||||
/* This VFS needs to obtain a pointer to the corresponding database
|
||||
** file handle from within xOpen() calls to open wal files. To do this,
|
||||
** it uses the sqlite3_database_file_object() API to obtain a pointer
|
||||
** to the file-handle used by SQLite to access the db file. This is
|
||||
** fine if cksmvfs happens to be the top-level VFS, but not if there
|
||||
** are one or more wrapper VFS. To handle this case, this file-control
|
||||
** is used to extract the cksmvfs file-handle from any wrapper file
|
||||
** handle. */
|
||||
sqlite3_file **ppFile = (sqlite3_file**)pArg;
|
||||
*ppFile = (sqlite3_file*)p;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
rc = pFile->pMethods->xFileControl(pFile, op, pArg);
|
||||
if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
|
||||
@@ -688,6 +700,8 @@ static int cksmOpen(
|
||||
if( rc ) goto cksm_open_done;
|
||||
if( flags & SQLITE_OPEN_WAL ){
|
||||
sqlite3_file *pDb = sqlite3_database_file_object(zName);
|
||||
rc = pDb->pMethods->xFileControl(pDb, SQLITE_FCNTL_CKSM_FILE, (void*)&pDb);
|
||||
assert( rc==SQLITE_OK );
|
||||
p->pPartner = (CksmFile*)pDb;
|
||||
assert( p->pPartner->pPartner==0 );
|
||||
p->pPartner->pPartner = p;
|
||||
@@ -809,6 +823,7 @@ static int cksmRegisterVfs(void){
|
||||
sqlite3_vfs *pOrig;
|
||||
if( sqlite3_vfs_find("cksmvfs")!=0 ) return SQLITE_OK;
|
||||
pOrig = sqlite3_vfs_find(0);
|
||||
if( pOrig==0 ) return SQLITE_ERROR;
|
||||
cksm_vfs.iVersion = pOrig->iVersion;
|
||||
cksm_vfs.pAppData = pOrig;
|
||||
cksm_vfs.szOsFile = pOrig->szOsFile + sizeof(CksmFile);
|
||||
@@ -856,9 +871,6 @@ int sqlite3_cksumvfs_init(
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg; /* not used */
|
||||
rc = cksmRegisterFunc(db, 0, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = cksmRegisterVfs();
|
||||
}
|
||||
|
||||
+5
-4
@@ -459,10 +459,11 @@ static void decimalSubFunc(
|
||||
Decimal *pA = decimal_new(context, argv[0], 0, 0);
|
||||
Decimal *pB = decimal_new(context, argv[1], 0, 0);
|
||||
UNUSED_PARAMETER(argc);
|
||||
if( pB==0 ) return;
|
||||
pB->sign = !pB->sign;
|
||||
decimal_add(pA, pB);
|
||||
decimal_result(context, pA);
|
||||
if( pB ){
|
||||
pB->sign = !pB->sign;
|
||||
decimal_add(pA, pB);
|
||||
decimal_result(context, pA);
|
||||
}
|
||||
decimal_free(pA);
|
||||
decimal_free(pB);
|
||||
}
|
||||
|
||||
@@ -167,6 +167,14 @@ static void ieee754func(
|
||||
int isNeg = 0;
|
||||
m = sqlite3_value_int64(argv[0]);
|
||||
e = sqlite3_value_int64(argv[1]);
|
||||
|
||||
/* Limit the range of e. Ticket 22dea1cfdb9151e4 2021-03-02 */
|
||||
if( e>10000 ){
|
||||
e = 10000;
|
||||
}else if( e<-10000 ){
|
||||
e = -10000;
|
||||
}
|
||||
|
||||
if( m<0 ){
|
||||
isNeg = 1;
|
||||
m = -m;
|
||||
|
||||
+11
-10
@@ -299,7 +299,7 @@ static void jsonAppendSeparator(JsonString *p){
|
||||
*/
|
||||
static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
|
||||
u32 i;
|
||||
if( (N+p->nUsed+2 >= p->nAlloc) && jsonGrow(p,N+2)!=0 ) return;
|
||||
if( zIn==0 || ((N+p->nUsed+2 >= p->nAlloc) && jsonGrow(p,N+2)!=0) ) return;
|
||||
p->zBuf[p->nUsed++] = '"';
|
||||
for(i=0; i<N; i++){
|
||||
unsigned char c = ((unsigned const char*)zIn)[i];
|
||||
@@ -1898,8 +1898,8 @@ static void jsonArrayStep(
|
||||
jsonAppendChar(pStr, '[');
|
||||
}else if( pStr->nUsed>1 ){
|
||||
jsonAppendChar(pStr, ',');
|
||||
pStr->pCtx = ctx;
|
||||
}
|
||||
pStr->pCtx = ctx;
|
||||
jsonAppendValue(pStr, argv[0]);
|
||||
}
|
||||
}
|
||||
@@ -1959,11 +1959,7 @@ static void jsonGroupInverse(
|
||||
if( NEVER(!pStr) ) return;
|
||||
#endif
|
||||
z = pStr->zBuf;
|
||||
for(i=1; (c = z[i])!=',' || inStr || nNest; i++){
|
||||
if( i>=pStr->nUsed ){
|
||||
pStr->nUsed = 1;
|
||||
return;
|
||||
}
|
||||
for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){
|
||||
if( c=='"' ){
|
||||
inStr = !inStr;
|
||||
}else if( c=='\\' ){
|
||||
@@ -1973,8 +1969,13 @@ static void jsonGroupInverse(
|
||||
if( c=='}' || c==']' ) nNest--;
|
||||
}
|
||||
}
|
||||
pStr->nUsed -= i;
|
||||
memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1);
|
||||
if( i<pStr->nUsed ){
|
||||
pStr->nUsed -= i;
|
||||
memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1);
|
||||
z[pStr->nUsed] = 0;
|
||||
}else{
|
||||
pStr->nUsed = 1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define jsonGroupInverse 0
|
||||
@@ -2002,8 +2003,8 @@ static void jsonObjectStep(
|
||||
jsonAppendChar(pStr, '{');
|
||||
}else if( pStr->nUsed>1 ){
|
||||
jsonAppendChar(pStr, ',');
|
||||
pStr->pCtx = ctx;
|
||||
}
|
||||
pStr->pCtx = ctx;
|
||||
z = (const char*)sqlite3_value_text(argv[0]);
|
||||
n = (u32)sqlite3_value_bytes(argv[0]);
|
||||
jsonAppendString(pStr, z, n);
|
||||
|
||||
@@ -559,6 +559,7 @@ int sqlite3_memvfs_init(
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
mem_vfs.pAppData = sqlite3_vfs_find(0);
|
||||
if( mem_vfs.pAppData==0 ) return SQLITE_ERROR;
|
||||
mem_vfs.szOsFile = sizeof(MemFile);
|
||||
rc = sqlite3_vfs_register(&mem_vfs, 1);
|
||||
#ifdef MEMVFS_TEST
|
||||
|
||||
+24
-13
@@ -248,7 +248,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
break;
|
||||
}
|
||||
case RE_OP_ANY: {
|
||||
re_add_state(pNext, x+1);
|
||||
if( c!=0 ) re_add_state(pNext, x+1);
|
||||
break;
|
||||
}
|
||||
case RE_OP_WORD: {
|
||||
@@ -256,7 +256,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
break;
|
||||
}
|
||||
case RE_OP_NOTWORD: {
|
||||
if( !re_word_char(c) ) re_add_state(pNext, x+1);
|
||||
if( !re_word_char(c) && c!=0 ) re_add_state(pNext, x+1);
|
||||
break;
|
||||
}
|
||||
case RE_OP_DIGIT: {
|
||||
@@ -264,7 +264,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
break;
|
||||
}
|
||||
case RE_OP_NOTDIGIT: {
|
||||
if( !re_digit_char(c) ) re_add_state(pNext, x+1);
|
||||
if( !re_digit_char(c) && c!=0 ) re_add_state(pNext, x+1);
|
||||
break;
|
||||
}
|
||||
case RE_OP_SPACE: {
|
||||
@@ -272,7 +272,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
break;
|
||||
}
|
||||
case RE_OP_NOTSPACE: {
|
||||
if( !re_space_char(c) ) re_add_state(pNext, x+1);
|
||||
if( !re_space_char(c) && c!=0 ) re_add_state(pNext, x+1);
|
||||
break;
|
||||
}
|
||||
case RE_OP_BOUNDARY: {
|
||||
@@ -297,8 +297,11 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
rc = 1;
|
||||
goto re_match_end;
|
||||
}
|
||||
case RE_OP_CC_INC:
|
||||
case RE_OP_CC_EXC: {
|
||||
if( c==0 ) break;
|
||||
/* fall-through */
|
||||
}
|
||||
case RE_OP_CC_INC: {
|
||||
int j = 1;
|
||||
int n = pRe->aArg[x];
|
||||
int hit = 0;
|
||||
@@ -319,7 +322,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
}
|
||||
if( pRe->aOp[x]==RE_OP_CC_EXC ) hit = !hit;
|
||||
if( hit ) re_add_state(pNext, x+n);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -480,7 +483,7 @@ static const char *re_subcompile_string(ReCompiled *p){
|
||||
iStart = p->nState;
|
||||
switch( c ){
|
||||
case '|':
|
||||
case '$':
|
||||
case '$':
|
||||
case ')': {
|
||||
p->sIn.i--;
|
||||
return 0;
|
||||
@@ -496,7 +499,7 @@ static const char *re_subcompile_string(ReCompiled *p){
|
||||
if( rePeek(p)=='*' ){
|
||||
re_append(p, RE_OP_ANYSTAR, 0);
|
||||
p->sIn.i++;
|
||||
}else{
|
||||
}else{
|
||||
re_append(p, RE_OP_ANY, 0);
|
||||
}
|
||||
break;
|
||||
@@ -673,8 +676,8 @@ static const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){
|
||||
** regex engine over the string. Do not worry able trying to match
|
||||
** unicode characters beyond plane 0 - those are very rare and this is
|
||||
** just an optimization. */
|
||||
if( pRe->aOp[0]==RE_OP_ANYSTAR ){
|
||||
for(j=0, i=1; j<sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){
|
||||
if( pRe->aOp[0]==RE_OP_ANYSTAR && !noCase ){
|
||||
for(j=0, i=1; j<(int)sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){
|
||||
unsigned x = pRe->aArg[i];
|
||||
if( x<=127 ){
|
||||
pRe->zInit[j++] = (unsigned char)x;
|
||||
@@ -705,8 +708,8 @@ static const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){
|
||||
** is implemented as regexp(B,A).
|
||||
*/
|
||||
static void re_sql_func(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
ReCompiled *pRe; /* Compiled regular expression */
|
||||
@@ -715,11 +718,12 @@ static void re_sql_func(
|
||||
const char *zErr; /* Compile error message */
|
||||
int setAux = 0; /* True to invoke sqlite3_set_auxdata() */
|
||||
|
||||
(void)argc; /* Unused */
|
||||
pRe = sqlite3_get_auxdata(context, 0);
|
||||
if( pRe==0 ){
|
||||
zPattern = (const char*)sqlite3_value_text(argv[0]);
|
||||
if( zPattern==0 ) return;
|
||||
zErr = re_compile(&pRe, zPattern, 0);
|
||||
zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
|
||||
if( zErr ){
|
||||
re_free(pRe);
|
||||
sqlite3_result_error(context, zErr, -1);
|
||||
@@ -754,7 +758,14 @@ int sqlite3_regexp_init(
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg; /* Unused */
|
||||
rc = sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8|SQLITE_INNOCUOUS,
|
||||
0, re_sql_func, 0, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
/* The regexpi(PATTERN,STRING) function is a case-insensitive version
|
||||
** of regexp(PATTERN,STRING). */
|
||||
rc = sqlite3_create_function(db, "regexpi", 2, SQLITE_UTF8|SQLITE_INNOCUOUS,
|
||||
(void*)db, re_sql_func, 0, 0);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
+16
-2
@@ -323,11 +323,12 @@ static int seriesFilter(
|
||||
** (8) output in descending order
|
||||
*/
|
||||
static int seriesBestIndex(
|
||||
sqlite3_vtab *tabUnused,
|
||||
sqlite3_vtab *pVTab,
|
||||
sqlite3_index_info *pIdxInfo
|
||||
){
|
||||
int i, j; /* Loop over constraints */
|
||||
int idxNum = 0; /* The query plan bitmask */
|
||||
int bStartSeen = 0; /* EQ constraint seen on the START column */
|
||||
int unusableMask = 0; /* Mask of unusable constraints */
|
||||
int nArg = 0; /* Number of arguments that seriesFilter() expects */
|
||||
int aIdx[3]; /* Constraints on start, stop, and step */
|
||||
@@ -337,7 +338,7 @@ static int seriesBestIndex(
|
||||
** are the last three columns in the virtual table. */
|
||||
assert( SERIES_COLUMN_STOP == SERIES_COLUMN_START+1 );
|
||||
assert( SERIES_COLUMN_STEP == SERIES_COLUMN_START+2 );
|
||||
(void)tabUnused;
|
||||
|
||||
aIdx[0] = aIdx[1] = aIdx[2] = -1;
|
||||
pConstraint = pIdxInfo->aConstraint;
|
||||
for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
|
||||
@@ -347,6 +348,7 @@ static int seriesBestIndex(
|
||||
iCol = pConstraint->iColumn - SERIES_COLUMN_START;
|
||||
assert( iCol>=0 && iCol<=2 );
|
||||
iMask = 1 << iCol;
|
||||
if( iCol==0 ) bStartSeen = 1;
|
||||
if( pConstraint->usable==0 ){
|
||||
unusableMask |= iMask;
|
||||
continue;
|
||||
@@ -361,6 +363,18 @@ static int seriesBestIndex(
|
||||
pIdxInfo->aConstraintUsage[j].omit = !SQLITE_SERIES_CONSTRAINT_VERIFY;
|
||||
}
|
||||
}
|
||||
/* The current generate_column() implementation requires at least one
|
||||
** argument (the START value). Legacy versions assumed START=0 if the
|
||||
** first argument was omitted. Compile with -DZERO_ARGUMENT_GENERATE_SERIES
|
||||
** to obtain the legacy behavior */
|
||||
#ifndef ZERO_ARGUMENT_GENERATE_SERIES
|
||||
if( !bStartSeen ){
|
||||
sqlite3_free(pVTab->zErrMsg);
|
||||
pVTab->zErrMsg = sqlite3_mprintf(
|
||||
"first argument to \"generate_series()\" missing or unusable");
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
#endif
|
||||
if( (unusableMask & ~idxNum)!=0 ){
|
||||
/* The start, stop, and step columns are inputs. Therefore if there
|
||||
** are unusable constraints on any of start, stop, or step then
|
||||
|
||||
@@ -754,6 +754,7 @@ static int vlogCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){
|
||||
*/
|
||||
int sqlite3_register_vfslog(const char *zArg){
|
||||
vlog_vfs.pVfs = sqlite3_vfs_find(0);
|
||||
if( vlog_vfs.pVfs==0 ) return SQLITE_ERROR;
|
||||
vlog_vfs.base.szOsFile = sizeof(VLogFile) + vlog_vfs.pVfs->szOsFile;
|
||||
return sqlite3_vfs_register(&vlog_vfs.base, 1);
|
||||
}
|
||||
|
||||
@@ -806,6 +806,7 @@ int sqlite3_vfsstat_init(
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
vstat_vfs.pVfs = sqlite3_vfs_find(0);
|
||||
if( vstat_vfs.pVfs==0 ) return SQLITE_ERROR;
|
||||
vstat_vfs.base.szOsFile = sizeof(VStatFile) + vstat_vfs.pVfs->szOsFile;
|
||||
rc = sqlite3_vfs_register(&vstat_vfs.base, 1);
|
||||
if( rc==SQLITE_OK ){
|
||||
|
||||
@@ -220,7 +220,7 @@ static int wholenumberBestIndex(
|
||||
pIdxInfo->orderByConsumed = 1;
|
||||
}
|
||||
if( (idxNum & 12)==0 ){
|
||||
pIdxInfo->estimatedCost = (double)100000000;
|
||||
pIdxInfo->estimatedCost = 1e99;
|
||||
}else if( (idxNum & 3)==0 ){
|
||||
pIdxInfo->estimatedCost = (double)5;
|
||||
}else{
|
||||
|
||||
+38
-29
@@ -36,10 +36,24 @@ SQLITE_EXTENSION_INIT1
|
||||
|
||||
#ifndef SQLITE_AMALGAMATION
|
||||
|
||||
#ifndef UINT32_TYPE
|
||||
# ifdef HAVE_UINT32_T
|
||||
# define UINT32_TYPE uint32_t
|
||||
# else
|
||||
# define UINT32_TYPE unsigned int
|
||||
# endif
|
||||
#endif
|
||||
#ifndef UINT16_TYPE
|
||||
# ifdef HAVE_UINT16_T
|
||||
# define UINT16_TYPE uint16_t
|
||||
# else
|
||||
# define UINT16_TYPE unsigned short int
|
||||
# endif
|
||||
#endif
|
||||
typedef sqlite3_int64 i64;
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned long u32;
|
||||
typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
|
||||
typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
|
||||
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
||||
|
||||
#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
|
||||
@@ -706,34 +720,24 @@ static int zipfileScanExtra(u8 *aExtra, int nExtra, u32 *pmTime){
|
||||
** https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx
|
||||
*/
|
||||
static u32 zipfileMtime(ZipfileCDS *pCDS){
|
||||
int Y = (1980 + ((pCDS->mDate >> 9) & 0x7F));
|
||||
int M = ((pCDS->mDate >> 5) & 0x0F);
|
||||
int D = (pCDS->mDate & 0x1F);
|
||||
int B = -13;
|
||||
|
||||
int sec = (pCDS->mTime & 0x1F)*2;
|
||||
int min = (pCDS->mTime >> 5) & 0x3F;
|
||||
int hr = (pCDS->mTime >> 11) & 0x1F;
|
||||
i64 JD;
|
||||
|
||||
/* JD = INT(365.25 * (Y+4716)) + INT(30.6001 * (M+1)) + D + B - 1524.5 */
|
||||
|
||||
/* Calculate the JD in seconds for noon on the day in question */
|
||||
if( M<3 ){
|
||||
Y = Y-1;
|
||||
M = M+12;
|
||||
int Y,M,D,X1,X2,A,B,sec,min,hr;
|
||||
i64 JDsec;
|
||||
Y = (1980 + ((pCDS->mDate >> 9) & 0x7F));
|
||||
M = ((pCDS->mDate >> 5) & 0x0F);
|
||||
D = (pCDS->mDate & 0x1F);
|
||||
sec = (pCDS->mTime & 0x1F)*2;
|
||||
min = (pCDS->mTime >> 5) & 0x3F;
|
||||
hr = (pCDS->mTime >> 11) & 0x1F;
|
||||
if( M<=2 ){
|
||||
Y--;
|
||||
M += 12;
|
||||
}
|
||||
JD = (i64)(24*60*60) * (
|
||||
(int)(365.25 * (Y + 4716))
|
||||
+ (int)(30.6001 * (M + 1))
|
||||
+ D + B - 1524
|
||||
);
|
||||
|
||||
/* Correct the JD for the time within the day */
|
||||
JD += (hr-12) * 3600 + min * 60 + sec;
|
||||
|
||||
/* Convert JD to unix timestamp (the JD epoch is 2440587.5) */
|
||||
return (u32)(JD - (i64)(24405875) * 24*60*6);
|
||||
X1 = 36525*(Y+4716)/100;
|
||||
X2 = 306001*(M+1)/10000;
|
||||
A = Y/100;
|
||||
B = 2 - A + (A/4);
|
||||
JDsec = (i64)((X1 + X2 + D + B - 1524.5)*86400) + hr*3600 + min*60 + sec;
|
||||
return (u32)(JDsec - (i64)24405875*(i64)8640);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1482,6 +1486,7 @@ static int zipfileBegin(sqlite3_vtab *pVtab){
|
||||
static u32 zipfileTime(void){
|
||||
sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
|
||||
u32 ret;
|
||||
if( pVfs==0 ) return 0;
|
||||
if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
|
||||
i64 ms;
|
||||
pVfs->xCurrentTimeInt64(pVfs, &ms);
|
||||
@@ -2170,6 +2175,10 @@ static int zipfileRegister(sqlite3 *db){
|
||||
zipfileStep, zipfileFinal
|
||||
);
|
||||
}
|
||||
assert( sizeof(i64)==8 );
|
||||
assert( sizeof(u32)==4 );
|
||||
assert( sizeof(u16)==2 );
|
||||
assert( sizeof(u8)==1 );
|
||||
return rc;
|
||||
}
|
||||
#else /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ void usage(const char *zArgv0){
|
||||
|
||||
void report_default_vfs(){
|
||||
sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
|
||||
fprintf(stdout, "default vfs is \"%s\"\n", pVfs->zName);
|
||||
fprintf(stdout, "default vfs is \"%s\"\n", pVfs ? pVfs->zName : "NULL");
|
||||
}
|
||||
|
||||
void report_rbu_vfs(sqlite3rbu *pRbu){
|
||||
|
||||
@@ -132,6 +132,11 @@ foreach {tn3 create_vfs destroy_vfs} {
|
||||
} {
|
||||
sqlite3rbu_destroy_vfs myrbu
|
||||
}
|
||||
3 {
|
||||
sqlite3_register_cksumvfs
|
||||
} {
|
||||
sqlite3_unregister_cksumvfs
|
||||
}
|
||||
} {
|
||||
|
||||
eval $create_vfs
|
||||
|
||||
@@ -268,6 +268,14 @@ tablE t1 USING FTs5(c);
|
||||
DELETE FROM t1 WHERE rowid = 1;
|
||||
INSERT INTO t1 VALUES('a b c');
|
||||
}
|
||||
4 {
|
||||
creAte virTUal tablE t1 USING FTs5(c);
|
||||
INSERT INTO t1 VALUES('a b c');
|
||||
INSERT INTO t1 VALUES('a b c');
|
||||
} {
|
||||
DELETE FROM t1 WHERE rowid = 1;
|
||||
INSERT INTO t1 VALUES('a b c');
|
||||
}
|
||||
|
||||
} {
|
||||
forcedelete test.db test.db2
|
||||
|
||||
+9
-21
@@ -1620,7 +1620,9 @@ char *rbuVacuumIndexStart(
|
||||
zSep = "";
|
||||
for(iCol=0; iCol<pIter->nCol; iCol++){
|
||||
const char *zQuoted = (const char*)sqlite3_column_text(pSel, iCol);
|
||||
if( zQuoted[0]=='N' ){
|
||||
if( zQuoted==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
}else if( zQuoted[0]=='N' ){
|
||||
bFailed = 1;
|
||||
break;
|
||||
}
|
||||
@@ -4992,28 +4994,14 @@ static int rbuVfsOpen(
|
||||
rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0);
|
||||
if( pDb ){
|
||||
if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
|
||||
/* This call is to open a *-wal file. Intead, open the *-oal. This
|
||||
** code ensures that the string passed to xOpen() is terminated by a
|
||||
** pair of '\0' bytes in case the VFS attempts to extract a URI
|
||||
** parameter from it. */
|
||||
const char *zBase = zName;
|
||||
size_t nCopy;
|
||||
char *zCopy;
|
||||
/* This call is to open a *-wal file. Intead, open the *-oal. */
|
||||
size_t nOpen;
|
||||
if( rbuIsVacuum(pDb->pRbu) ){
|
||||
zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
|
||||
zBase = sqlite3_filename_wal(zBase);
|
||||
}
|
||||
nCopy = strlen(zBase);
|
||||
zCopy = sqlite3_malloc64(nCopy+2);
|
||||
if( zCopy ){
|
||||
memcpy(zCopy, zBase, nCopy);
|
||||
zCopy[nCopy-3] = 'o';
|
||||
zCopy[nCopy] = '\0';
|
||||
zCopy[nCopy+1] = '\0';
|
||||
zOpen = (const char*)(pFd->zDel = zCopy);
|
||||
}else{
|
||||
rc = SQLITE_NOMEM;
|
||||
zOpen = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
|
||||
zOpen = sqlite3_filename_wal(zOpen);
|
||||
}
|
||||
nOpen = strlen(zOpen);
|
||||
((char*)zOpen)[nOpen-3] = 'o';
|
||||
pFd->pRbu = pDb->pRbu;
|
||||
}
|
||||
pDb->pWalFd = pFd;
|
||||
|
||||
+5
-1
@@ -310,6 +310,10 @@ static GeoPoly *geopolyFuncParam(
|
||||
){
|
||||
const unsigned char *a = sqlite3_value_blob(pVal);
|
||||
int nVertex;
|
||||
if( a==0 ){
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
return 0;
|
||||
}
|
||||
nVertex = (a[1]<<16) + (a[2]<<8) + a[3];
|
||||
if( (a[0]==0 || a[0]==1)
|
||||
&& (nVertex*2*sizeof(GeoCoord) + 4)==(unsigned int)nByte
|
||||
@@ -683,7 +687,7 @@ static GeoPoly *geopolyBBox(
|
||||
aCoord[2].f = mnY;
|
||||
aCoord[3].f = mxY;
|
||||
}
|
||||
}else{
|
||||
}else if( aCoord ){
|
||||
memset(aCoord, 0, sizeof(RtreeCoord)*4);
|
||||
}
|
||||
return pOut;
|
||||
|
||||
+6
-1
@@ -3890,11 +3890,16 @@ static void rtreedepth(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
|
||||
UNUSED_PARAMETER(nArg);
|
||||
if( sqlite3_value_type(apArg[0])!=SQLITE_BLOB
|
||||
|| sqlite3_value_bytes(apArg[0])<2
|
||||
|
||||
){
|
||||
sqlite3_result_error(ctx, "Invalid argument to rtreedepth()", -1);
|
||||
}else{
|
||||
u8 *zBlob = (u8 *)sqlite3_value_blob(apArg[0]);
|
||||
sqlite3_result_int(ctx, readInt16(zBlob));
|
||||
if( zBlob ){
|
||||
sqlite3_result_int(ctx, readInt16(zBlob));
|
||||
}else{
|
||||
sqlite3_result_error_nomem(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -79,47 +79,47 @@ do_eqp_test rtree6.2.1 {
|
||||
SELECT * FROM t1,t2 WHERE k=+ii AND x1<10
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0
|
||||
`--SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
|--SCAN t1 VIRTUAL TABLE INDEX 2:C0
|
||||
`--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
}
|
||||
|
||||
do_eqp_test rtree6.2.2 {
|
||||
SELECT * FROM t1,t2 WHERE k=ii AND x1<10
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0
|
||||
`--SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
|--SCAN t1 VIRTUAL TABLE INDEX 2:C0
|
||||
`--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
}
|
||||
|
||||
do_eqp_test rtree6.2.3 {
|
||||
SELECT * FROM t1,t2 WHERE k=ii
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1 VIRTUAL TABLE INDEX 2:
|
||||
`--SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
|--SCAN t1 VIRTUAL TABLE INDEX 2:
|
||||
`--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
}
|
||||
|
||||
do_eqp_test rtree6.2.4.1 {
|
||||
SELECT * FROM t1,t2 WHERE v=+ii and x1<10 and x2>10
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0E1
|
||||
`--SEARCH TABLE t2 USING AUTOMATIC COVERING INDEX (v=?)
|
||||
|--SCAN t1 VIRTUAL TABLE INDEX 2:C0E1
|
||||
`--SEARCH t2 USING AUTOMATIC COVERING INDEX (v=?)
|
||||
}
|
||||
do_eqp_test rtree6.2.4.2 {
|
||||
SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0E1
|
||||
`--SEARCH TABLE t2 USING AUTOMATIC PARTIAL COVERING INDEX (v=?)
|
||||
|--SCAN t1 VIRTUAL TABLE INDEX 2:C0E1
|
||||
`--SEARCH t2 USING AUTOMATIC PARTIAL COVERING INDEX (v=?)
|
||||
}
|
||||
|
||||
do_eqp_test rtree6.2.5 {
|
||||
SELECT * FROM t1,t2 WHERE k=ii AND x1<v
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1 VIRTUAL TABLE INDEX 2:
|
||||
`--SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
|--SCAN t1 VIRTUAL TABLE INDEX 2:
|
||||
`--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
|
||||
}
|
||||
|
||||
do_execsql_test rtree6-3.1 {
|
||||
|
||||
+44
-44
@@ -30,8 +30,8 @@ do_eqp_test 1.1 {
|
||||
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t
|
||||
`--SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
|--SCAN t
|
||||
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
}
|
||||
|
||||
do_eqp_test 1.2 {
|
||||
@@ -39,8 +39,8 @@ do_eqp_test 1.2 {
|
||||
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t
|
||||
`--SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
|--SCAN t
|
||||
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
}
|
||||
|
||||
do_eqp_test 1.3 {
|
||||
@@ -48,16 +48,16 @@ do_eqp_test 1.3 {
|
||||
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND ?<=max_y
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t
|
||||
`--SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
|--SCAN t
|
||||
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
}
|
||||
|
||||
do_eqp_test 1.5 {
|
||||
SELECT * FROM t, r_tree
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:
|
||||
`--SCAN TABLE t
|
||||
|--SCAN r_tree VIRTUAL TABLE INDEX 2:
|
||||
`--SCAN t
|
||||
}
|
||||
|
||||
do_execsql_test 2.0 {
|
||||
@@ -87,8 +87,8 @@ do_eqp_test 2.1 {
|
||||
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t
|
||||
`--SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
|--SCAN t
|
||||
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
}
|
||||
|
||||
do_eqp_test 2.2 {
|
||||
@@ -96,8 +96,8 @@ do_eqp_test 2.2 {
|
||||
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t
|
||||
`--SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
|--SCAN t
|
||||
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
}
|
||||
|
||||
do_eqp_test 2.3 {
|
||||
@@ -105,16 +105,16 @@ do_eqp_test 2.3 {
|
||||
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND ?<=max_y
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t
|
||||
`--SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
|--SCAN t
|
||||
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
||||
}
|
||||
|
||||
do_eqp_test 2.5 {
|
||||
SELECT * FROM t, r_tree
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:
|
||||
`--SCAN TABLE t
|
||||
|--SCAN r_tree VIRTUAL TABLE INDEX 2:
|
||||
`--SCAN t
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@@ -128,24 +128,24 @@ do_execsql_test 3.1 {
|
||||
|
||||
do_eqp_test 3.2.1 { SELECT * FROM t1 CROSS JOIN t2 } {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1
|
||||
`--SCAN TABLE t2
|
||||
|--SCAN t1
|
||||
`--SCAN t2
|
||||
}
|
||||
do_eqp_test 3.2.2 { SELECT * FROM t2 CROSS JOIN t1 } {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t2
|
||||
`--SCAN TABLE t1
|
||||
|--SCAN t2
|
||||
`--SCAN t1
|
||||
}
|
||||
|
||||
do_eqp_test 3.3.1 { SELECT * FROM t1 CROSS JOIN t3 } {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1
|
||||
`--SCAN TABLE t3 VIRTUAL TABLE INDEX 2:
|
||||
|--SCAN t1
|
||||
`--SCAN t3 VIRTUAL TABLE INDEX 2:
|
||||
}
|
||||
do_eqp_test 3.3.2 { SELECT * FROM t3 CROSS JOIN t1 } {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t3 VIRTUAL TABLE INDEX 2:
|
||||
`--SCAN TABLE t1
|
||||
|--SCAN t3 VIRTUAL TABLE INDEX 2:
|
||||
`--SCAN t1
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
@@ -203,8 +203,8 @@ do_eqp_test 5.2 {
|
||||
SELECT * FROM t1, rt WHERE x==id;
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1
|
||||
`--SCAN TABLE rt VIRTUAL TABLE INDEX 1:
|
||||
|--SCAN t1
|
||||
`--SCAN rt VIRTUAL TABLE INDEX 1:
|
||||
}
|
||||
|
||||
# Now create enough ANALYZE data to tell SQLite that virtual table "rt"
|
||||
@@ -220,8 +220,8 @@ do_eqp_test 5.4 {
|
||||
SELECT * FROM t1, rt WHERE x==id;
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE rt VIRTUAL TABLE INDEX 2:
|
||||
`--SEARCH TABLE t1 USING INDEX sqlite_autoindex_t1_1 (x=?)
|
||||
|--SCAN rt VIRTUAL TABLE INDEX 2:
|
||||
`--SEARCH t1 USING INDEX sqlite_autoindex_t1_1 (x=?)
|
||||
}
|
||||
|
||||
# Delete the ANALYZE data. "t1" should be the outer loop again.
|
||||
@@ -233,8 +233,8 @@ do_eqp_test 5.6 {
|
||||
SELECT * FROM t1, rt WHERE x==id;
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1
|
||||
`--SCAN TABLE rt VIRTUAL TABLE INDEX 1:
|
||||
|--SCAN t1
|
||||
`--SCAN rt VIRTUAL TABLE INDEX 1:
|
||||
}
|
||||
|
||||
# This time create and attach a database that contains ANALYZE data for
|
||||
@@ -258,8 +258,8 @@ do_eqp_test 5.8 {
|
||||
SELECT * FROM t1, rt WHERE x==id;
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE t1
|
||||
`--SCAN TABLE rt VIRTUAL TABLE INDEX 1:
|
||||
|--SCAN t1
|
||||
`--SCAN rt VIRTUAL TABLE INDEX 1:
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
@@ -327,9 +327,9 @@ do_eqp_execsql_test 7.1 {
|
||||
WHERE (x1 BETWEEN xmin AND xmax);
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE xdir
|
||||
|--SCAN TABLE ydir
|
||||
`--SCAN TABLE rt VIRTUAL TABLE INDEX 2:B2D3B0D1
|
||||
|--SCAN xdir
|
||||
|--SCAN ydir
|
||||
`--SCAN rt VIRTUAL TABLE INDEX 2:B2D3B0D1
|
||||
} {
|
||||
2 4
|
||||
}
|
||||
@@ -340,9 +340,9 @@ do_eqp_execsql_test 7.2 {
|
||||
WHERE (x1 BETWEEN xmin AND xmax);
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE xdir
|
||||
|--SCAN TABLE rt VIRTUAL TABLE INDEX 2:B0D1
|
||||
`--SCAN TABLE ydir
|
||||
|--SCAN xdir
|
||||
|--SCAN rt VIRTUAL TABLE INDEX 2:B0D1
|
||||
`--SCAN ydir
|
||||
} {
|
||||
5 1 2 7 12 14 {}
|
||||
5 2 2 7 8 12 10
|
||||
@@ -355,9 +355,9 @@ do_eqp_execsql_test 7.3 {
|
||||
WHERE (x1 BETWEEN xmin AND xmax);
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE xdir
|
||||
|--SCAN TABLE rt VIRTUAL TABLE INDEX 2:B0D1
|
||||
`--SCAN TABLE ydir
|
||||
|--SCAN xdir
|
||||
|--SCAN rt VIRTUAL TABLE INDEX 2:B0D1
|
||||
`--SCAN ydir
|
||||
} {
|
||||
2 4
|
||||
}
|
||||
@@ -368,9 +368,9 @@ do_eqp_execsql_test 7.4 {
|
||||
WHERE (x1 BETWEEN xmin AND xmax);
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN TABLE xdir
|
||||
|--SCAN TABLE rt VIRTUAL TABLE INDEX 2:B0D1
|
||||
`--SCAN TABLE ydir
|
||||
|--SCAN xdir
|
||||
|--SCAN rt VIRTUAL TABLE INDEX 2:B0D1
|
||||
`--SCAN ydir
|
||||
} {
|
||||
2 4
|
||||
}
|
||||
|
||||
@@ -1045,5 +1045,167 @@ do_test rtreefuzz001-500 {
|
||||
catchsql {UPDATE t1 SET ex= ex ISNULL}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
do_test rtreefuzz001-600 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
| size 20480 pagesize 4096 filename crash-7b37d80f000235.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 05 .....@ ........
|
||||
| 32: 00 00 00 00 00 00 00 00 00 00 10 06 00 00 00 04 ................
|
||||
| 96: 00 00 00 00 0d 00 00 00 05 0e 49 00 0f 99 0f 40 ..........I....@
|
||||
| 112: 0e da 0e 8f 0e 49 00 00 00 00 00 00 00 00 00 00 .....I..........
|
||||
| 3648: 00 00 00 00 00 00 00 00 00 44 05 06 17 15 15 08 .........D......
|
||||
| 3664: 6f 74 61 62 6c 65 67 65 6f 31 67 65 6f 31 43 52 otablegeo1geo1CR
|
||||
| 3680: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB
|
||||
| 3696: 4c 45 20 67 65 6f 31 20 55 53 49 4e 47 20 67 65 LE geo1 USING ge
|
||||
| 3712: 6f 70 6f 6c 79 28 74 79 70 65 2c 63 6c 72 29 49 opoly(type,clr)I
|
||||
| 3728: 04 06 17 1f 1f 01 63 74 61 62 6c 65 71 75 65 72 ......ctablequer
|
||||
| 3744: 79 70 6f 6c 79 71 75 65 72 79 70 6f 6c 79 05 43 ypolyquerypoly.C
|
||||
| 3760: 52 45 41 54 45 20 54 41 42 4c 45 20 71 75 65 72 REATE TABLE quer
|
||||
| 3776: 79 70 6f 6c 79 28 70 6f 6c 79 20 4a 53 4f 4e 2c ypoly(poly JSON,
|
||||
| 3792: 20 63 6c 72 20 54 45 58 54 29 64 03 07 17 23 23 clr TEXT)d...##
|
||||
| 3808: 01 81 0f 74 61 62 6c 65 67 65 6f 31 5f 70 61 72 ...tablegeo1_par
|
||||
| 3824: 65 6e 74 67 65 6f 31 5f 70 61 72 65 6e 74 04 43 entgeo1_parent.C
|
||||
| 3840: 52 45 41 54 45 20 54 41 42 4c 45 20 22 67 65 6f REATE TABLE .geo
|
||||
| 3856: 31 5f 70 61 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 1_parent.(nodeno
|
||||
| 3872: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY
|
||||
| 3888: 20 4b 45 59 2c 70 61 72 65 6e 74 6e 6f 64 85 29 KEY,parentnod.)
|
||||
| 3904: 57 02 06 17 1f 1f 01 7f 74 61 62 6c 65 67 65 6f W.......tablegeo
|
||||
| 3920: 31 5f 6e 6f 64 65 67 65 6f 31 5f 6e 6f 64 65 03 1_nodegeo1_node.
|
||||
| 3936: 43 52 45 41 54 45 20 54 41 42 4c 45 20 22 67 65 CREATE TABLE .ge
|
||||
| 3952: 6f 31 5f 6e 6f 64 65 22 28 6e 6f 64 65 6e 6f 20 o1_node.(nodeno
|
||||
| 3968: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 INTEGER PRIMARY
|
||||
| 3984: 4b 45 59 2c 64 61 74 61 29 65 01 07 17 21 21 01 KEY,data)e...!!.
|
||||
| 4000: 81 15 74 61 62 6c 65 67 65 6f 31 5f 72 6f 77 69 ..tablegeo1_rowi
|
||||
| 4016: 64 67 65 6f 31 5f 72 6f 77 69 64 02 43 52 45 41 dgeo1_rowid.CREA
|
||||
| 4032: 54 45 20 54 41 42 4c 45 20 22 67 65 6f 31 5f 72 TE TABLE .geo1_r
|
||||
| 4048: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45 owid.(rowid INTE
|
||||
| 4064: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY,
|
||||
| 4080: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 2c 61 32 29 nodeno,a0,a1,a2)
|
||||
| page 2 offset 4096
|
||||
| 0: 0d 00 00 00 0a 0d ab 00 0f c9 0f 88 0f 48 0f 00 .............H..
|
||||
| 3488: 00 00 00 00 00 00 00 00 00 00 00 45 82 0a 06 00 ...........E....
|
||||
| 3504: 09 74 1d 13 01 00 00 06 00 80 b5 43 00 80 ac 43 .t.........C...C
|
||||
| 3520: 00 00 bd 43 8f 82 9f 43 71 fd c9 43 8f 02 a7 43 ...C...Cq..C...C
|
||||
| 3536: 71 fd c8 43 e4 bd a8 43 64 bb bd 43 f4 3d a2 43 q..C...Cd..C.=.C
|
||||
| 3552: 64 3b b7 43 00 80 ad 43 61 6e 67 6c 65 2d 33 30 d;.C...Cangle-30
|
||||
| 3568: 72 65 64 32 81 4e 06 00 09 44 23 17 01 00 00 03 red2.N...D#.....
|
||||
| 3584: 00 40 3f 44 00 c0 20 44 00 c0 46 44 00 c0 20 44 .@?D.. D..FD.. D
|
||||
| 3600: 00 00 43 44 00 40 28 44 74 72 69 61 6e 67 6c 65 ..CD.@(Dtriangle
|
||||
| 3616: 2d 33 30 62 6c 61 63 6b 35 82 3e 06 00 09 54 1d -30black5.>...T.
|
||||
| 3632: 13 01 00 00 04 00 40 54 44 00 80 1d 44 9a c9 5c ......@TD...D...
|
||||
| 3648: 44 66 36 1b 44 33 13 5f 44 00 c0 23 44 9a 89 5b Df6.D3._D..#D..[
|
||||
| 3664: 44 a4 60 1d 44 61 72 72 6f 77 2d 35 30 72 65 64 D.`.Darrow-50red
|
||||
| 3680: 36 74 06 00 09 54 1b 17 01 00 00 04 00 80 0d 44 6t...T.........D
|
||||
| 3696: 00 00 f2 42 0a d7 04 44 00 00 ca 42 0a 77 05 44 ...B...D...B.w.D
|
||||
| 3712: 0a 57 c1 42 00 20 0e 44 0a 57 e9 42 6c 69 6e 65 .W.B. .D.W.Bline
|
||||
| 3728: 2d 34 30 67 72 65 65 6e 36 72 06 00 09 54 1b 17 -40green6r...T..
|
||||
| 3744: 01 00 00 04 00 00 7b 43 00 00 ea 42 29 5c 58 43 .......C...B).XC
|
||||
| 3760: 00 00 c2 42 29 dc 5a 43 0a 57 b9 42 00 80 7d 43 ...B).ZC.W.B...C
|
||||
| 3776: 0a 57 e1 42 6c 69 6e 65 2d 34 30 67 72 65 65 6e .W.Bline-40green
|
||||
| 3792: 36 54 06 00 09 54 1b 17 01 00 00 04 00 00 a2 43 6T...T.........C
|
||||
| 3808: 00 00 24 44 00 00 b6 43 00 00 24 44 00 00 b6 43 ..$D...C..$D...C
|
||||
| 3824: 00 40 25 44 00 00 a2 43 00 40 25 44 6c 69 6e 65 .@%D...C.@%Dline
|
||||
| 3840: 2d 34 30 62 6c 61 63 6b 3e 37 06 00 09 64 1d 15 -40black>7...d..
|
||||
| 3856: 01 00 00 05 00 80 f0 43 00 00 54 43 66 16 01 44 .......C..TCf..D
|
||||
| 3872: 66 a6 30 43 cd ec 09 44 00 00 54 43 8f 0a 09 44 f.0C...D..TC...D
|
||||
| 3888: a4 d0 73 43 66 16 01 44 9a 59 77 43 68 6f 75 73 ..sCf..D.YwChous
|
||||
| 3904: 65 2d 37 30 62 6c 75 65 3e 35 06 00 09 64 1d 15 e-70blue>5...d..
|
||||
| 3920: 01 00 00 05 00 00 a2 43 00 00 5a 43 cd ac b3 43 .......C..ZC...C
|
||||
| 3936: 66 a6 36 43 9a 59 c5 43 00 00 5a 43 1f 95 c3 43 f.6C.Y.C..ZC...C
|
||||
| 3952: a4 d0 79 43 cd ac b3 43 9a 59 7d 43 68 6f 75 73 ..yC...C.Y.Chous
|
||||
| 3968: 65 2d 37 30 62 6c 75 65 3f 2c 06 00 09 64 1d 17 e-70blue?,...d..
|
||||
| 3984: 01 00 00 05 00 00 f5 43 00 00 2f 43 00 00 07 44 .......C../C...D
|
||||
| 4000: 00 00 2f 43 00 00 07 44 00 00 61 43 00 c0 00 44 ../C...D..aC...D
|
||||
| 4016: 00 00 75 43 00 00 f5 43 00 00 61 43 68 6f 75 73 ..uC...C..aChous
|
||||
| 4032: 65 2d 37 30 62 6c 61 63 6b 35 1f 06 10 09 54 19 e-70black5....T.
|
||||
| 4048: 17 01 00 00 04 00 00 9b 43 00 00 67 43 0a 57 92 ........C..gC.W.
|
||||
| 4064: 43 00 00 5d 43 0a 57 97 43 14 ae 4b 42 ff ff a0 C..]C.W.C..KB...
|
||||
| 4080: 43 14 ae 55 43 62 6f 78 2d 32 30 67 72 65 65 6e C..UCbox-20green
|
||||
| page 3 offset 8192
|
||||
| 0: 0d 00 00 00 01 0b 2d 00 0b 2e 00 00 00 00 00 00 ......-.........
|
||||
| 2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 ...............P
|
||||
| 2864: 01 04 00 93 24 00 00 00 0a 00 00 00 00 00 00 01 ....$...........
|
||||
| 2880: 0a 43 b5 80 00 43 c9 fd 71 43 9f 82 8f 43 ad 80 .C...C..qC...C..
|
||||
| 2896: 00 00 00 00 00 00 00 00 72 43 58 5c 29 43 7d 80 ........rCX.)C..
|
||||
| 2912: 00 42 b9 57 0a 42 ea 00 00 00 00 00 00 00 00 00 .B.W.B..........
|
||||
| 2928: 35 43 a2 00 00 43 c5 59 9a 43 36 a6 66 43 7d 59 5C...C.Y.C6.fC.Y
|
||||
| 2944: 9a 00 00 00 00 00 00 00 1f 43 92 57 0a 43 a0 00 .........C.W.C..
|
||||
| 2960: 00 43 4b ae 14 43 67 00 00 00 00 00 00 00 00 00 .CK..Cg.........
|
||||
| 2976: 37 43 f0 80 00 44 09 ec cd 43 30 a6 66 43 77 59 7C...D...C0.fCwY
|
||||
| 2992: 9a 00 00 00 00 00 00 00 2c 43 f5 00 00 44 07 00 ........,C...D..
|
||||
| 3008: 00 43 2f 00 00 43 75 00 00 00 00 00 00 00 00 00 .C/..Cu.........
|
||||
| 3024: 74 44 04 d7 0a 44 0e 20 00 42 c1 57 0a 42 f2 00 tD...D. .B.W.B..
|
||||
| 3040: 00 00 00 00 00 00 00 00 ce 44 3f 40 00 44 46 c0 .........D?@.DF.
|
||||
| 3056: 00 44 20 c0 00 44 28 40 00 00 00 00 00 00 00 00 .D ..D(@........
|
||||
| 3072: be 44 54 40 00 44 5f 13 33 44 1b 36 66 44 23 c0 .DT@.D_.3D.6fD#.
|
||||
| 3088: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
||||
| 3104: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 00 .D$..D%@........
|
||||
| 3120: 54 43 a2 00 00 43 b6 00 00 44 24 00 00 44 25 40 TC...C...D$..D%@
|
||||
| 3136: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
||||
| 3152: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 00 .D$..D%@........
|
||||
| 3168: 54 43 a2 00 00 43 b6 00 00 44 24 00 00 44 25 40 TC...C...D$..D%@
|
||||
| 3184: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
||||
| 3200: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 00 .D$..D%@........
|
||||
| 3216: 54 43 a2 00 00 43 b6 00 00 44 24 00 00 44 25 40 TC...C...D$..D%@
|
||||
| 3232: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
||||
| 3248: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 00 .D$..D%@........
|
||||
| 3264: 54 43 a2 00 00 43 b6 00 00 44 24 00 00 44 25 40 TC...C...D$..D%@
|
||||
| 3280: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
||||
| 3296: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 00 .D$..D%@........
|
||||
| 3312: 54 43 a2 00 00 43 b6 00 00 44 24 00 00 44 25 40 TC...C...D$..D%@
|
||||
| 3328: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
||||
| 3344: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 01 .D$..D%@........
|
||||
| 3360: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
||||
| 3376: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
||||
| 3392: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
||||
| 3408: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
||||
| 3424: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
||||
| 3440: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
||||
| 3456: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
||||
| 3472: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
||||
| 3488: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
||||
| 3504: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
||||
| 3520: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
||||
| 3536: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
||||
| 3552: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
||||
| 3568: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
||||
| 3584: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
||||
| 3600: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
||||
| 3616: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
||||
| 3632: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
||||
| 3648: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
||||
| 3664: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
||||
| 3680: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
||||
| 3696: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
||||
| page 4 offset 12288
|
||||
| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| page 5 offset 16384
|
||||
| 0: 0d 00 00 00 01 0f 8f 00 00 00 00 00 00 00 00 00 ................
|
||||
| 3968: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 6f ...............o
|
||||
| 3984: 01 04 81 57 19 5b 5b 33 30 30 2c 33 30 30 5d 2c ...W.[[300,300],
|
||||
| 4000: 5b 34 30 30 2c 33 35 30 5d 2c 5b 35 30 30 2c 32 [400,350],[500,2
|
||||
| 4016: 35 30 5d 2c 5b 34 38 30 2c 35 30 30 5d 2c 5b 34 50],[480,500],[4
|
||||
| 4032: 30 30 2c 34 38 30 5d 2c 5c 33 30 30 2c 35 35 30 00,480],.300,550
|
||||
| 4048: 5d 2c 5b 32 38 30 2c 34 35 30 5d 2c 5b 33 32 30 ],[280,450],[320
|
||||
| 4064: 2c 34 30 30 5d 2c 5b 32 38 30 2c 33 35 30 5d 2c ,400],[280,350],
|
||||
| 4080: 5b 33 30 30 2c 33 30 00 00 00 00 00 00 00 00 00 [300,30.........
|
||||
| end crash-7b37d80f000235.db
|
||||
}]} {}
|
||||
|
||||
ifcapable geopoly {
|
||||
|
||||
do_catchsql_test rtreefuzz001-601 {
|
||||
SAVEPOINT one;
|
||||
UPDATE geo1 SET clr=CASE WHEN rowid IN ( SELECT geo1.rowid FROM geo1, querypoly ) THEN 'e' ELSE 'blue' END;
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
do_catchsql_test rtreefuzz001-602 {
|
||||
SELECT geopoly_svg(_shape, printf('j',geo1.clr))
|
||||
FROM geo1, querypoly WHERE geopoly_overlap(_shape, poly);
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
} ;# ifcapable geopoly
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -152,6 +152,26 @@ do_changeset_test $tn.2.4.2 S {}
|
||||
do_changeset_invert_test $tn.2.4.3 S {}
|
||||
do_test $tn.2.4.4 { S delete } {}
|
||||
|
||||
do_execsql_test $tn.2.5.0 {
|
||||
SELECT * FROM t1 ORDER BY x
|
||||
} {
|
||||
2 Surin
|
||||
10 Sukhothai
|
||||
20 Thapae
|
||||
}
|
||||
|
||||
do_test $tn.2.5.1 {
|
||||
sqlite3session S db main
|
||||
S attach t1
|
||||
execsql { DELETE FROM t1 }
|
||||
} {}
|
||||
do_changeset_test $tn.2.5.2 S {
|
||||
{DELETE t1 0 X. {i 10 t Sukhothai} {}}
|
||||
{DELETE t1 0 X. {i 2 t Surin} {}}
|
||||
{DELETE t1 0 X. {i 20 t Thapae} {}}
|
||||
}
|
||||
do_test $tn.2.5.3 { S delete } {}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test the application of simple changesets. These tests also test that
|
||||
# the conflict callback is invoked correctly. For these tests, the
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
# 2014 August 16
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file implements regression tests for sessions SQLite extension.
|
||||
# Specifically, this file contains tests for "patchset" changes.
|
||||
#
|
||||
|
||||
if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname [info script]] .. .. test]
|
||||
}
|
||||
source [file join [file dirname [info script]] session_common.tcl]
|
||||
source $testdir/tester.tcl
|
||||
ifcapable !session {finish_test; return}
|
||||
|
||||
if {[permutation]=="session_strm" || [permutation]=="session_eec"} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
if {$::tcl_platform(pointerSize)<8} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
set testprefix sessionbig
|
||||
|
||||
forcedelete test.db2
|
||||
sqlite3 db2 test.db2
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
|
||||
}
|
||||
do_execsql_test -db db2 1.1 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
|
||||
}
|
||||
|
||||
do_test 1.2 {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test 1.3 {
|
||||
execsql { DELETE FROM t1 }
|
||||
execsql2 { DELETE FROM t1 }
|
||||
} {}
|
||||
|
||||
do_test 1.4 {
|
||||
set rc [catch {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
}
|
||||
} msg]
|
||||
list $rc $msg
|
||||
} {1 SQLITE_NOMEM}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
# 2021 Februar 20
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
|
||||
if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname [info script]] .. .. test]
|
||||
}
|
||||
source [file join [file dirname [info script]] session_common.tcl]
|
||||
source $testdir/tester.tcl
|
||||
ifcapable !session {finish_test; return}
|
||||
|
||||
set testprefix sessionnoop
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test plan:
|
||||
#
|
||||
# 1.*: Test that concatenating changesets cannot produce a noop UPDATE.
|
||||
# 2.*: Test that rebasing changesets cannot produce a noop UPDATE.
|
||||
# 3.*: Test that sqlite3changeset_apply() ignores noop UPDATE changes.
|
||||
#
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b, c, d);
|
||||
INSERT INTO t1 VALUES(1, 1, 1, 1);
|
||||
INSERT INTO t1 VALUES(2, 2, 2, 2);
|
||||
INSERT INTO t1 VALUES(3, 3, 3, 3);
|
||||
}
|
||||
|
||||
proc do_concat_test {tn sql1 sql2 res} {
|
||||
uplevel [list do_test $tn [subst -nocommands {
|
||||
set C1 [changeset_from_sql {$sql1}]
|
||||
set C2 [changeset_from_sql {$sql2}]
|
||||
set C3 [sqlite3changeset_concat [set C1] [set C2]]
|
||||
set got [list]
|
||||
sqlite3session_foreach elem [set C3] { lappend got [set elem] }
|
||||
set got
|
||||
}] [list {*}$res]]
|
||||
}
|
||||
|
||||
do_concat_test 1.1 {
|
||||
UPDATE t1 SET c=c+1;
|
||||
} {
|
||||
UPDATE t1 SET c=c-1;
|
||||
} {
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 2.0 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b, c);
|
||||
INSERT INTO t1 VALUES(1, 1, 1);
|
||||
INSERT INTO t1 VALUES(2, 2, 2);
|
||||
INSERT INTO t1 VALUES(3, 3, 3);
|
||||
}
|
||||
|
||||
proc do_rebase_test {tn sql_local sql_remote conflict_res expected} {
|
||||
proc xConflict {args} [list return $conflict_res]
|
||||
|
||||
uplevel [list \
|
||||
do_test $tn [subst -nocommands {
|
||||
execsql BEGIN
|
||||
set c_remote [changeset_from_sql {$sql_remote}]
|
||||
execsql ROLLBACK
|
||||
|
||||
execsql BEGIN
|
||||
set c_local [changeset_from_sql {$sql_local}]
|
||||
set base [sqlite3changeset_apply_v2 db [set c_remote] xConflict]
|
||||
execsql ROLLBACK
|
||||
|
||||
sqlite3rebaser_create R
|
||||
R config [set base]
|
||||
set res [list]
|
||||
sqlite3session_foreach elem [R rebase [set c_local]] {
|
||||
lappend res [set elem]
|
||||
}
|
||||
R delete
|
||||
set res
|
||||
}] [list {*}$expected]
|
||||
]
|
||||
}
|
||||
|
||||
do_rebase_test 2.1 {
|
||||
UPDATE t1 SET c=2 WHERE a=1; -- local
|
||||
} {
|
||||
UPDATE t1 SET c=3 WHERE a=1; -- remote
|
||||
} OMIT {
|
||||
{UPDATE t1 0 X.. {i 1 {} {} i 3} {{} {} {} {} i 2}}
|
||||
}
|
||||
|
||||
do_rebase_test 2.2 {
|
||||
UPDATE t1 SET c=2 WHERE a=1; -- local
|
||||
} {
|
||||
UPDATE t1 SET c=3 WHERE a=1; -- remote
|
||||
} REPLACE {
|
||||
}
|
||||
|
||||
do_rebase_test 2.3.1 {
|
||||
UPDATE t1 SET c=4 WHERE a=1; -- local
|
||||
} {
|
||||
UPDATE t1 SET c=4 WHERE a=1 -- remote
|
||||
} OMIT {
|
||||
{UPDATE t1 0 X.. {i 1 {} {} i 4} {{} {} {} {} i 4}}
|
||||
}
|
||||
|
||||
do_rebase_test 2.3.2 {
|
||||
UPDATE t1 SET c=5 WHERE a=1; -- local
|
||||
} {
|
||||
UPDATE t1 SET c=5 WHERE a=1 -- remote
|
||||
} REPLACE {
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 3.0 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
|
||||
INSERT INTO t1 VALUES(1, 1, 1);
|
||||
INSERT INTO t1 VALUES(2, 2, 2);
|
||||
INSERT INTO t1 VALUES(3, 3, 3);
|
||||
INSERT INTO t1 VALUES(4, 4, 4);
|
||||
}
|
||||
|
||||
# Arg $pkstr contains one character for each column in the table. An
|
||||
# "X" for PK column, or a "." for a non-PK.
|
||||
#
|
||||
proc mk_tbl_header {name pkstr} {
|
||||
set ret [binary format H2c 54 [string length $pkstr]]
|
||||
foreach i [split $pkstr {}] {
|
||||
if {$i=="X"} {
|
||||
append ret [binary format H2 01]
|
||||
} else {
|
||||
if {$i!="."} {error "bad pkstr: $pkstr ($i)"}
|
||||
append ret [binary format H2 00]
|
||||
}
|
||||
}
|
||||
append ret $name
|
||||
append ret [binary format H2 00]
|
||||
set ret
|
||||
}
|
||||
|
||||
proc mk_update_change {args} {
|
||||
set ret [binary format H2H2 17 00]
|
||||
foreach a $args {
|
||||
if {$a==""} {
|
||||
append ret [binary format H2 00]
|
||||
} else {
|
||||
append ret [binary format H2W 01 $a]
|
||||
}
|
||||
}
|
||||
set ret
|
||||
}
|
||||
|
||||
proc xConflict {args} { return "ABORT" }
|
||||
do_test 3.1 {
|
||||
set C [mk_tbl_header t1 X..]
|
||||
append C [mk_update_change 1 {} 1 {} {} 500]
|
||||
append C [mk_update_change 2 {} {} {} {} {}]
|
||||
append C [mk_update_change 3 3 {} {} 600 {}]
|
||||
append C [mk_update_change 4 {} {} {} {} {}]
|
||||
|
||||
sqlite3changeset_apply_v2 db $C xConflict
|
||||
} {}
|
||||
do_execsql_test 3.2 {
|
||||
SELECT * FROM t1
|
||||
} {
|
||||
1 1 500
|
||||
2 2 2
|
||||
3 600 3
|
||||
4 4 4
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
# 2021 April 22
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
|
||||
if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname [info script]] .. .. test]
|
||||
}
|
||||
source [file join [file dirname [info script]] session_common.tcl]
|
||||
source $testdir/tester.tcl
|
||||
ifcapable !session {finish_test; return}
|
||||
|
||||
set testprefix sessionsize
|
||||
|
||||
proc do_changeset_size_test {tn sql} {
|
||||
sqlite3session S db main
|
||||
S attach *
|
||||
db eval $sql
|
||||
|
||||
set sz [S changeset_size]
|
||||
set C [S changeset]
|
||||
set szC [string length $C]
|
||||
S delete
|
||||
|
||||
do_test $tn "expr $sz" $szC
|
||||
}
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
|
||||
INSERT INTO t1 VALUES(1, 'abc', 'def');
|
||||
INSERT INTO t1 VALUES(2, 'ghi', 'jkl');
|
||||
}
|
||||
|
||||
do_changeset_size_test 1.1 {
|
||||
INSERT INTO t1 VALUES(3, 'hello', 'world');
|
||||
}
|
||||
|
||||
do_changeset_size_test 1.2 {
|
||||
DELETE FROM t1 WHERE a=2;
|
||||
}
|
||||
|
||||
do_changeset_size_test 1.3 {
|
||||
DELETE FROM t1 WHERE a=3;
|
||||
INSERT INTO t1 VALUES(3, 1, 2);
|
||||
}
|
||||
|
||||
do_changeset_size_test 1.4 {
|
||||
UPDATE t1 SET c='hello world' WHERE a=3;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
do_execsql_test 2.0 {
|
||||
CREATE TABlE t2(a, b, c, d, PRIMARY KEY(a, b)) WITHOUT ROWID;
|
||||
CREATE TABlE t3(a, b, c, d PRIMARY KEY);
|
||||
}
|
||||
|
||||
do_changeset_size_test 2.1 {
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50
|
||||
)
|
||||
INSERT INTO t2 SELECT i, i+1, i+2, i+3 FROM s;
|
||||
|
||||
UPDATE t2 SET c=randomblob(a) WHERE a>10
|
||||
}
|
||||
|
||||
do_changeset_size_test 2.2 {
|
||||
DELETE FROM t2 WHERE a=1;
|
||||
INSERT INTO t2 VALUES(1, 4, 3, 4);
|
||||
}
|
||||
|
||||
do_changeset_size_test 2.2 {
|
||||
UPDATE t2 SET b=4 WHERE a=2
|
||||
}
|
||||
|
||||
do_changeset_size_test 2.3 {
|
||||
INSERT INTO t2 VALUES('a', 'b', 'c', 'd');
|
||||
UPDATE t2 SET c='qwertyuiop' WHERE a='a';
|
||||
}
|
||||
|
||||
do_changeset_size_test 2.4 {
|
||||
DELETE FROM t2 WHERE a='a';
|
||||
INSERT INTO t2 VALUES('a', 'b', 'c', 'd');
|
||||
}
|
||||
|
||||
do_changeset_size_test 2.5 {
|
||||
UPDATE t2 SET a='aa', b='bb' WHERE (a, b) = ('a', 'b');
|
||||
}
|
||||
|
||||
do_changeset_size_test 2.6 {
|
||||
UPDATE t2 SET a='a', b='b' WHERE (a, b) = ('aa', 'bb');
|
||||
}
|
||||
|
||||
do_changeset_size_test 2.7 {
|
||||
INSERT INTO t3 DEFAULT VALUES;
|
||||
INSERT INTO t3 VALUES(1,2,3,4);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
|
||||
do_execsql_test 3.0 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
|
||||
}
|
||||
|
||||
do_test 3.1 {
|
||||
sqlite3session S db main
|
||||
S object_config_size -1
|
||||
} 1
|
||||
|
||||
do_test 3.2.1 { S object_config_size 0 } 0
|
||||
do_test 3.2.2 { S object_config_size -1 } 0
|
||||
do_test 3.2.3 { S object_config_size 1 } 1
|
||||
do_test 3.2.4 { S object_config_size -1 } 1
|
||||
|
||||
do_test 3.3 { S attach t1 } {}
|
||||
do_test 3.4 { S object_config_size 1 } {SQLITE_MISUSE}
|
||||
do_test 3.4 { S object_config_size -1 } {1}
|
||||
|
||||
S delete
|
||||
|
||||
finish_test
|
||||
|
||||
+244
-46
@@ -42,6 +42,7 @@ struct SessionHook {
|
||||
struct sqlite3_session {
|
||||
sqlite3 *db; /* Database handle session is attached to */
|
||||
char *zDb; /* Name of database session is attached to */
|
||||
int bEnableSize; /* True if changeset_size() enabled */
|
||||
int bEnable; /* True if currently recording */
|
||||
int bIndirect; /* True if all changes are indirect */
|
||||
int bAutoAttach; /* True to auto-attach tables */
|
||||
@@ -49,6 +50,7 @@ struct sqlite3_session {
|
||||
void *pFilterCtx; /* First argument to pass to xTableFilter */
|
||||
int (*xTableFilter)(void *pCtx, const char *zTab);
|
||||
i64 nMalloc; /* Number of bytes of data allocated */
|
||||
i64 nMaxChangesetSize;
|
||||
sqlite3_value *pZeroBlob; /* Value containing X'' */
|
||||
sqlite3_session *pNext; /* Next session object on same db. */
|
||||
SessionTable *pTable; /* List of attached tables */
|
||||
@@ -91,6 +93,7 @@ struct sqlite3_changeset_iter {
|
||||
SessionBuffer tblhdr; /* Buffer to hold apValue/zTab/abPK/ */
|
||||
int bPatchset; /* True if this is a patchset */
|
||||
int bInvert; /* True to invert changeset */
|
||||
int bSkipEmpty; /* Skip noop UPDATE changes */
|
||||
int rc; /* Iterator error code */
|
||||
sqlite3_stmt *pConflict; /* Points to conflicting row, if any */
|
||||
char *zTab; /* Current table */
|
||||
@@ -290,8 +293,9 @@ struct SessionTable {
|
||||
** this structure stored in a SessionTable.aChange[] hash table.
|
||||
*/
|
||||
struct SessionChange {
|
||||
int op; /* One of UPDATE, DELETE, INSERT */
|
||||
int bIndirect; /* True if this change is "indirect" */
|
||||
u8 op; /* One of UPDATE, DELETE, INSERT */
|
||||
u8 bIndirect; /* True if this change is "indirect" */
|
||||
int nMaxSize; /* Max size of eventual changeset record */
|
||||
int nRecord; /* Number of bytes in buffer aRecord[] */
|
||||
u8 *aRecord; /* Buffer containing old.* record */
|
||||
SessionChange *pNext; /* For hash-table collisions */
|
||||
@@ -1120,6 +1124,12 @@ static int sessionInitTable(sqlite3_session *pSession, SessionTable *pTab){
|
||||
if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){
|
||||
pTab->bStat1 = 1;
|
||||
}
|
||||
|
||||
if( pSession->bEnableSize ){
|
||||
pSession->nMaxChangesetSize += (
|
||||
1 + sessionVarintLen(pTab->nCol) + pTab->nCol + strlen(pTab->zName)+1
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (pSession->rc || pTab->abPK==0);
|
||||
@@ -1165,6 +1175,103 @@ static int sessionStat1Depth(void *pCtx){
|
||||
return p->hook.xDepth(p->hook.pCtx);
|
||||
}
|
||||
|
||||
static int sessionUpdateMaxSize(
|
||||
int op,
|
||||
sqlite3_session *pSession, /* Session object pTab is attached to */
|
||||
SessionTable *pTab, /* Table that change applies to */
|
||||
SessionChange *pC /* Update pC->nMaxSize */
|
||||
){
|
||||
i64 nNew = 2;
|
||||
if( pC->op==SQLITE_INSERT ){
|
||||
if( op!=SQLITE_DELETE ){
|
||||
int ii;
|
||||
for(ii=0; ii<pTab->nCol; ii++){
|
||||
sqlite3_value *p = 0;
|
||||
pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
|
||||
sessionSerializeValue(0, p, &nNew);
|
||||
}
|
||||
}
|
||||
}else if( op==SQLITE_DELETE ){
|
||||
nNew += pC->nRecord;
|
||||
if( sqlite3_preupdate_blobwrite(pSession->db)>=0 ){
|
||||
nNew += pC->nRecord;
|
||||
}
|
||||
}else{
|
||||
int ii;
|
||||
u8 *pCsr = pC->aRecord;
|
||||
for(ii=0; ii<pTab->nCol; ii++){
|
||||
int bChanged = 1;
|
||||
int nOld = 0;
|
||||
int eType;
|
||||
sqlite3_value *p = 0;
|
||||
pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
|
||||
if( p==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
eType = *pCsr++;
|
||||
switch( eType ){
|
||||
case SQLITE_NULL:
|
||||
bChanged = sqlite3_value_type(p)!=SQLITE_NULL;
|
||||
break;
|
||||
|
||||
case SQLITE_FLOAT:
|
||||
case SQLITE_INTEGER: {
|
||||
if( eType==sqlite3_value_type(p) ){
|
||||
sqlite3_int64 iVal = sessionGetI64(pCsr);
|
||||
if( eType==SQLITE_INTEGER ){
|
||||
bChanged = (iVal!=sqlite3_value_int64(p));
|
||||
}else{
|
||||
double dVal;
|
||||
memcpy(&dVal, &iVal, 8);
|
||||
bChanged = (dVal!=sqlite3_value_double(p));
|
||||
}
|
||||
}
|
||||
nOld = 8;
|
||||
pCsr += 8;
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
int nByte;
|
||||
nOld = sessionVarintGet(pCsr, &nByte);
|
||||
pCsr += nOld;
|
||||
nOld += nByte;
|
||||
assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB );
|
||||
if( eType==sqlite3_value_type(p)
|
||||
&& nByte==sqlite3_value_bytes(p)
|
||||
&& (nByte==0 || 0==memcmp(pCsr, sqlite3_value_blob(p), nByte))
|
||||
){
|
||||
bChanged = 0;
|
||||
}
|
||||
pCsr += nByte;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( bChanged && pTab->abPK[ii] ){
|
||||
nNew = pC->nRecord + 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if( bChanged ){
|
||||
nNew += 1 + nOld;
|
||||
sessionSerializeValue(0, p, &nNew);
|
||||
}else if( pTab->abPK[ii] ){
|
||||
nNew += 2 + nOld;
|
||||
}else{
|
||||
nNew += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( nNew>pC->nMaxSize ){
|
||||
int nIncr = nNew - pC->nMaxSize;
|
||||
pC->nMaxSize = nNew;
|
||||
pSession->nMaxChangesetSize += nIncr;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is only called from with a pre-update-hook reporting a
|
||||
@@ -1238,7 +1345,6 @@ static void sessionPreupdateOneChange(
|
||||
/* Create a new change object containing all the old values (if
|
||||
** this is an SQLITE_UPDATE or SQLITE_DELETE), or just the PK
|
||||
** values (if this is an INSERT). */
|
||||
SessionChange *pChange; /* New change object */
|
||||
sqlite3_int64 nByte; /* Number of bytes to allocate */
|
||||
int i; /* Used to iterate through columns */
|
||||
|
||||
@@ -1264,13 +1370,13 @@ static void sessionPreupdateOneChange(
|
||||
}
|
||||
|
||||
/* Allocate the change object */
|
||||
pChange = (SessionChange *)sessionMalloc64(pSession, nByte);
|
||||
if( !pChange ){
|
||||
pC = (SessionChange *)sessionMalloc64(pSession, nByte);
|
||||
if( !pC ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto error_out;
|
||||
}else{
|
||||
memset(pChange, 0, sizeof(SessionChange));
|
||||
pChange->aRecord = (u8 *)&pChange[1];
|
||||
memset(pC, 0, sizeof(SessionChange));
|
||||
pC->aRecord = (u8 *)&pC[1];
|
||||
}
|
||||
|
||||
/* Populate the change object. None of the preupdate_old(),
|
||||
@@ -1285,17 +1391,17 @@ static void sessionPreupdateOneChange(
|
||||
}else if( pTab->abPK[i] ){
|
||||
pSession->hook.xNew(pSession->hook.pCtx, i, &p);
|
||||
}
|
||||
sessionSerializeValue(&pChange->aRecord[nByte], p, &nByte);
|
||||
sessionSerializeValue(&pC->aRecord[nByte], p, &nByte);
|
||||
}
|
||||
|
||||
/* Add the change to the hash-table */
|
||||
if( pSession->bIndirect || pSession->hook.xDepth(pSession->hook.pCtx) ){
|
||||
pChange->bIndirect = 1;
|
||||
pC->bIndirect = 1;
|
||||
}
|
||||
pChange->nRecord = nByte;
|
||||
pChange->op = op;
|
||||
pChange->pNext = pTab->apChange[iHash];
|
||||
pTab->apChange[iHash] = pChange;
|
||||
pC->nRecord = nByte;
|
||||
pC->op = op;
|
||||
pC->pNext = pTab->apChange[iHash];
|
||||
pTab->apChange[iHash] = pC;
|
||||
|
||||
}else if( pC->bIndirect ){
|
||||
/* If the existing change is considered "indirect", but this current
|
||||
@@ -1306,8 +1412,14 @@ static void sessionPreupdateOneChange(
|
||||
pC->bIndirect = 0;
|
||||
}
|
||||
}
|
||||
|
||||
assert( rc==SQLITE_OK );
|
||||
if( pSession->bEnableSize ){
|
||||
rc = sessionUpdateMaxSize(op, pSession, pTab, pC);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* If an error has occurred, mark the session object as failed. */
|
||||
error_out:
|
||||
if( pTab->bStat1 ){
|
||||
@@ -1862,13 +1974,29 @@ int sqlite3session_attach(
|
||||
** If successful, return zero. Otherwise, if an OOM condition is encountered,
|
||||
** set *pRc to SQLITE_NOMEM and return non-zero.
|
||||
*/
|
||||
static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){
|
||||
if( *pRc==SQLITE_OK && (size_t)(p->nAlloc-p->nBuf)<nByte ){
|
||||
static int sessionBufferGrow(SessionBuffer *p, i64 nByte, int *pRc){
|
||||
#define SESSION_MAX_BUFFER_SZ (0x7FFFFF00 - 1)
|
||||
i64 nReq = p->nBuf + nByte;
|
||||
if( *pRc==SQLITE_OK && nReq>p->nAlloc ){
|
||||
u8 *aNew;
|
||||
i64 nNew = p->nAlloc ? p->nAlloc : 128;
|
||||
|
||||
do {
|
||||
nNew = nNew*2;
|
||||
}while( (size_t)(nNew-p->nBuf)<nByte );
|
||||
}while( nNew<nReq );
|
||||
|
||||
/* The value of SESSION_MAX_BUFFER_SZ is copied from the implementation
|
||||
** of sqlite3_realloc64(). Allocations greater than this size in bytes
|
||||
** always fail. It is used here to ensure that this routine can always
|
||||
** allocate up to this limit - instead of up to the largest power of
|
||||
** two smaller than the limit. */
|
||||
if( nNew>SESSION_MAX_BUFFER_SZ ){
|
||||
nNew = SESSION_MAX_BUFFER_SZ;
|
||||
if( nNew<nReq ){
|
||||
*pRc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
aNew = (u8 *)sqlite3_realloc64(p->aBuf, nNew);
|
||||
if( 0==aNew ){
|
||||
@@ -2519,7 +2647,11 @@ int sqlite3session_changeset(
|
||||
int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
|
||||
void **ppChangeset /* OUT: Buffer containing changeset */
|
||||
){
|
||||
return sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset);
|
||||
int rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset);
|
||||
assert( rc || pnChangeset==0
|
||||
|| pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
|
||||
);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2611,6 +2743,39 @@ sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession){
|
||||
return pSession->nMalloc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Configure the session object passed as the first argument.
|
||||
*/
|
||||
int sqlite3session_object_config(sqlite3_session *pSession, int op, void *pArg){
|
||||
int rc = SQLITE_OK;
|
||||
switch( op ){
|
||||
case SQLITE_SESSION_OBJCONFIG_SIZE: {
|
||||
int iArg = *(int*)pArg;
|
||||
if( iArg>=0 ){
|
||||
if( pSession->pTable ){
|
||||
rc = SQLITE_MISUSE;
|
||||
}else{
|
||||
pSession->bEnableSize = (iArg!=0);
|
||||
}
|
||||
}
|
||||
*(int*)pArg = pSession->bEnableSize;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the maximum size of sqlite3session_changeset() output.
|
||||
*/
|
||||
sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession){
|
||||
return pSession->nMaxChangesetSize;
|
||||
}
|
||||
|
||||
/*
|
||||
** Do the work for either sqlite3changeset_start() or start_strm().
|
||||
*/
|
||||
@@ -2620,7 +2785,8 @@ static int sessionChangesetStart(
|
||||
void *pIn,
|
||||
int nChangeset, /* Size of buffer pChangeset in bytes */
|
||||
void *pChangeset, /* Pointer to buffer containing changeset */
|
||||
int bInvert /* True to invert changeset */
|
||||
int bInvert, /* True to invert changeset */
|
||||
int bSkipEmpty /* True to skip empty UPDATE changes */
|
||||
){
|
||||
sqlite3_changeset_iter *pRet; /* Iterator to return */
|
||||
int nByte; /* Number of bytes to allocate for iterator */
|
||||
@@ -2641,6 +2807,7 @@ static int sessionChangesetStart(
|
||||
pRet->in.pIn = pIn;
|
||||
pRet->in.bEof = (xInput ? 0 : 1);
|
||||
pRet->bInvert = bInvert;
|
||||
pRet->bSkipEmpty = bSkipEmpty;
|
||||
|
||||
/* Populate the output variable and return success. */
|
||||
*pp = pRet;
|
||||
@@ -2655,7 +2822,7 @@ int sqlite3changeset_start(
|
||||
int nChangeset, /* Size of buffer pChangeset in bytes */
|
||||
void *pChangeset /* Pointer to buffer containing changeset */
|
||||
){
|
||||
return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, 0);
|
||||
return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, 0, 0);
|
||||
}
|
||||
int sqlite3changeset_start_v2(
|
||||
sqlite3_changeset_iter **pp, /* OUT: Changeset iterator handle */
|
||||
@@ -2664,7 +2831,7 @@ int sqlite3changeset_start_v2(
|
||||
int flags
|
||||
){
|
||||
int bInvert = !!(flags & SQLITE_CHANGESETSTART_INVERT);
|
||||
return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, bInvert);
|
||||
return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, bInvert, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2675,7 +2842,7 @@ int sqlite3changeset_start_strm(
|
||||
int (*xInput)(void *pIn, void *pData, int *pnData),
|
||||
void *pIn
|
||||
){
|
||||
return sessionChangesetStart(pp, xInput, pIn, 0, 0, 0);
|
||||
return sessionChangesetStart(pp, xInput, pIn, 0, 0, 0, 0);
|
||||
}
|
||||
int sqlite3changeset_start_v2_strm(
|
||||
sqlite3_changeset_iter **pp, /* OUT: Changeset iterator handle */
|
||||
@@ -2684,7 +2851,7 @@ int sqlite3changeset_start_v2_strm(
|
||||
int flags
|
||||
){
|
||||
int bInvert = !!(flags & SQLITE_CHANGESETSTART_INVERT);
|
||||
return sessionChangesetStart(pp, xInput, pIn, 0, 0, bInvert);
|
||||
return sessionChangesetStart(pp, xInput, pIn, 0, 0, bInvert, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2810,11 +2977,14 @@ static int sessionReadRecord(
|
||||
SessionInput *pIn, /* Input data */
|
||||
int nCol, /* Number of values in record */
|
||||
u8 *abPK, /* Array of primary key flags, or NULL */
|
||||
sqlite3_value **apOut /* Write values to this array */
|
||||
sqlite3_value **apOut, /* Write values to this array */
|
||||
int *pbEmpty
|
||||
){
|
||||
int i; /* Used to iterate through columns */
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
assert( pbEmpty==0 || *pbEmpty==0 );
|
||||
if( pbEmpty ) *pbEmpty = 1;
|
||||
for(i=0; i<nCol && rc==SQLITE_OK; i++){
|
||||
int eType = 0; /* Type of value (SQLITE_NULL, TEXT etc.) */
|
||||
if( abPK && abPK[i]==0 ) continue;
|
||||
@@ -2826,6 +2996,7 @@ static int sessionReadRecord(
|
||||
eType = pIn->aData[pIn->iNext++];
|
||||
assert( apOut[i]==0 );
|
||||
if( eType ){
|
||||
if( pbEmpty ) *pbEmpty = 0;
|
||||
apOut[i] = sqlite3ValueNew(0);
|
||||
if( !apOut[i] ) rc = SQLITE_NOMEM;
|
||||
}
|
||||
@@ -3005,31 +3176,27 @@ static int sessionChangesetReadTblhdr(sqlite3_changeset_iter *p){
|
||||
}
|
||||
|
||||
/*
|
||||
** Advance the changeset iterator to the next change.
|
||||
** Advance the changeset iterator to the next change. The differences between
|
||||
** this function and sessionChangesetNext() are that
|
||||
**
|
||||
** If both paRec and pnRec are NULL, then this function works like the public
|
||||
** API sqlite3changeset_next(). If SQLITE_ROW is returned, then the
|
||||
** sqlite3changeset_new() and old() APIs may be used to query for values.
|
||||
** * If pbEmpty is not NULL and the change is a no-op UPDATE (an UPDATE
|
||||
** that modifies no columns), this function sets (*pbEmpty) to 1.
|
||||
**
|
||||
** Otherwise, if paRec and pnRec are not NULL, then a pointer to the change
|
||||
** record is written to *paRec before returning and the number of bytes in
|
||||
** the record to *pnRec.
|
||||
**
|
||||
** Either way, this function returns SQLITE_ROW if the iterator is
|
||||
** successfully advanced to the next change in the changeset, an SQLite
|
||||
** error code if an error occurs, or SQLITE_DONE if there are no further
|
||||
** changes in the changeset.
|
||||
** * If the iterator is configured to skip no-op UPDATEs,
|
||||
** sessionChangesetNext() does that. This function does not.
|
||||
*/
|
||||
static int sessionChangesetNext(
|
||||
static int sessionChangesetNextOne(
|
||||
sqlite3_changeset_iter *p, /* Changeset iterator */
|
||||
u8 **paRec, /* If non-NULL, store record pointer here */
|
||||
int *pnRec, /* If non-NULL, store size of record here */
|
||||
int *pbNew /* If non-NULL, true if new table */
|
||||
int *pbNew, /* If non-NULL, true if new table */
|
||||
int *pbEmpty
|
||||
){
|
||||
int i;
|
||||
u8 op;
|
||||
|
||||
assert( (paRec==0 && pnRec==0) || (paRec && pnRec) );
|
||||
assert( pbEmpty==0 || *pbEmpty==0 );
|
||||
|
||||
/* If the iterator is in the error-state, return immediately. */
|
||||
if( p->rc!=SQLITE_OK ) return p->rc;
|
||||
@@ -3102,13 +3269,13 @@ static int sessionChangesetNext(
|
||||
/* If this is an UPDATE or DELETE, read the old.* record. */
|
||||
if( p->op!=SQLITE_INSERT && (p->bPatchset==0 || p->op==SQLITE_DELETE) ){
|
||||
u8 *abPK = p->bPatchset ? p->abPK : 0;
|
||||
p->rc = sessionReadRecord(&p->in, p->nCol, abPK, apOld);
|
||||
p->rc = sessionReadRecord(&p->in, p->nCol, abPK, apOld, 0);
|
||||
if( p->rc!=SQLITE_OK ) return p->rc;
|
||||
}
|
||||
|
||||
/* If this is an INSERT or UPDATE, read the new.* record. */
|
||||
if( p->op!=SQLITE_DELETE ){
|
||||
p->rc = sessionReadRecord(&p->in, p->nCol, 0, apNew);
|
||||
p->rc = sessionReadRecord(&p->in, p->nCol, 0, apNew, pbEmpty);
|
||||
if( p->rc!=SQLITE_OK ) return p->rc;
|
||||
}
|
||||
|
||||
@@ -3135,6 +3302,37 @@ static int sessionChangesetNext(
|
||||
return SQLITE_ROW;
|
||||
}
|
||||
|
||||
/*
|
||||
** Advance the changeset iterator to the next change.
|
||||
**
|
||||
** If both paRec and pnRec are NULL, then this function works like the public
|
||||
** API sqlite3changeset_next(). If SQLITE_ROW is returned, then the
|
||||
** sqlite3changeset_new() and old() APIs may be used to query for values.
|
||||
**
|
||||
** Otherwise, if paRec and pnRec are not NULL, then a pointer to the change
|
||||
** record is written to *paRec before returning and the number of bytes in
|
||||
** the record to *pnRec.
|
||||
**
|
||||
** Either way, this function returns SQLITE_ROW if the iterator is
|
||||
** successfully advanced to the next change in the changeset, an SQLite
|
||||
** error code if an error occurs, or SQLITE_DONE if there are no further
|
||||
** changes in the changeset.
|
||||
*/
|
||||
static int sessionChangesetNext(
|
||||
sqlite3_changeset_iter *p, /* Changeset iterator */
|
||||
u8 **paRec, /* If non-NULL, store record pointer here */
|
||||
int *pnRec, /* If non-NULL, store size of record here */
|
||||
int *pbNew /* If non-NULL, true if new table */
|
||||
){
|
||||
int bEmpty;
|
||||
int rc;
|
||||
do {
|
||||
bEmpty = 0;
|
||||
rc = sessionChangesetNextOne(p, paRec, pnRec, pbNew, &bEmpty);
|
||||
}while( rc==SQLITE_ROW && p->bSkipEmpty && bEmpty);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Advance an iterator created by sqlite3changeset_start() to the next
|
||||
** change in the changeset. This function may return SQLITE_ROW, SQLITE_DONE
|
||||
@@ -3407,9 +3605,9 @@ static int sessionChangesetInvert(
|
||||
|
||||
/* Read the old.* and new.* records for the update change. */
|
||||
pInput->iNext += 2;
|
||||
rc = sessionReadRecord(pInput, nCol, 0, &apVal[0]);
|
||||
rc = sessionReadRecord(pInput, nCol, 0, &apVal[0], 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sessionReadRecord(pInput, nCol, 0, &apVal[nCol]);
|
||||
rc = sessionReadRecord(pInput, nCol, 0, &apVal[nCol], 0);
|
||||
}
|
||||
|
||||
/* Write the new old.* record. Consists of the PK columns from the
|
||||
@@ -4357,7 +4555,7 @@ static int sessionRetryConstraints(
|
||||
memset(&pApply->constraints, 0, sizeof(SessionBuffer));
|
||||
|
||||
rc = sessionChangesetStart(
|
||||
&pIter2, 0, 0, cons.nBuf, cons.aBuf, pApply->bInvertConstraints
|
||||
&pIter2, 0, 0, cons.nBuf, cons.aBuf, pApply->bInvertConstraints, 1
|
||||
);
|
||||
if( rc==SQLITE_OK ){
|
||||
size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
|
||||
@@ -4613,8 +4811,8 @@ int sqlite3changeset_apply_v2(
|
||||
int flags
|
||||
){
|
||||
sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
|
||||
int bInverse = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
|
||||
int rc = sessionChangesetStart(&pIter, 0, 0, nChangeset, pChangeset,bInverse);
|
||||
int bInv = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
|
||||
int rc = sessionChangesetStart(&pIter, 0, 0, nChangeset, pChangeset, bInv, 1);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sessionChangesetApply(
|
||||
db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
|
||||
@@ -4672,7 +4870,7 @@ int sqlite3changeset_apply_v2_strm(
|
||||
){
|
||||
sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
|
||||
int bInverse = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
|
||||
int rc = sessionChangesetStart(&pIter, xInput, pIn, 0, 0, bInverse);
|
||||
int rc = sessionChangesetStart(&pIter, xInput, pIn, 0, 0, bInverse, 1);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sessionChangesetApply(
|
||||
db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
|
||||
@@ -5292,7 +5490,7 @@ static void sessionAppendPartialUpdate(
|
||||
int n1 = sessionSerialLen(a1);
|
||||
int n2 = sessionSerialLen(a2);
|
||||
if( pIter->abPK[i] || a2[0]==0 ){
|
||||
if( !pIter->abPK[i] ) bData = 1;
|
||||
if( !pIter->abPK[i] && a1[0] ) bData = 1;
|
||||
memcpy(pOut, a1, n1);
|
||||
pOut += n1;
|
||||
}else if( a2[0]!=0xFF ){
|
||||
|
||||
@@ -79,6 +79,38 @@ int sqlite3session_create(
|
||||
*/
|
||||
void sqlite3session_delete(sqlite3_session *pSession);
|
||||
|
||||
/*
|
||||
** CAPIREF: Conigure a Session Object
|
||||
** METHOD: sqlite3_session
|
||||
**
|
||||
** This method is used to configure a session object after it has been
|
||||
** created. At present the only valid value for the second parameter is
|
||||
** [SQLITE_SESSION_OBJCONFIG_SIZE].
|
||||
**
|
||||
** Arguments for sqlite3session_object_config()
|
||||
**
|
||||
** The following values may passed as the the 4th parameter to
|
||||
** sqlite3session_object_config().
|
||||
**
|
||||
** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
|
||||
** This option is used to set, clear or query the flag that enables
|
||||
** the [sqlite3session_changeset_size()] API. Because it imposes some
|
||||
** computational overhead, this API is disabled by default. Argument
|
||||
** pArg must point to a value of type (int). If the value is initially
|
||||
** 0, then the sqlite3session_changeset_size() API is disabled. If it
|
||||
** is greater than 0, then the same API is enabled. Or, if the initial
|
||||
** value is less than zero, no change is made. In all cases the (int)
|
||||
** variable is set to 1 if the sqlite3session_changeset_size() API is
|
||||
** enabled following the current call, or 0 otherwise.
|
||||
**
|
||||
** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
|
||||
** the first table has been attached to the session object.
|
||||
*/
|
||||
int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
|
||||
|
||||
/*
|
||||
*/
|
||||
#define SQLITE_SESSION_OBJCONFIG_SIZE 1
|
||||
|
||||
/*
|
||||
** CAPI3REF: Enable Or Disable A Session Object
|
||||
@@ -323,6 +355,22 @@ int sqlite3session_changeset(
|
||||
void **ppChangeset /* OUT: Buffer containing changeset */
|
||||
);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
|
||||
** METHOD: sqlite3_session
|
||||
**
|
||||
** By default, this function always returns 0. For it to return
|
||||
** a useful result, the sqlite3_session object must have been configured
|
||||
** to enable this API using sqlite3session_object_config() with the
|
||||
** SQLITE_SESSION_OBJCONFIG_SIZE verb.
|
||||
**
|
||||
** When enabled, this function returns an upper limit, in bytes, for the size
|
||||
** of the changeset that might be produced if sqlite3session_changeset() were
|
||||
** called. The final changeset size might be equal to or smaller than the
|
||||
** size in bytes returned by this function.
|
||||
*/
|
||||
sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Load The Difference Between Tables Into A Session
|
||||
** METHOD: sqlite3_session
|
||||
@@ -550,18 +598,23 @@ int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
|
||||
** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
|
||||
** is not the case, this function returns [SQLITE_MISUSE].
|
||||
**
|
||||
** If argument pzTab is not NULL, then *pzTab is set to point to a
|
||||
** nul-terminated utf-8 encoded string containing the name of the table
|
||||
** affected by the current change. The buffer remains valid until either
|
||||
** sqlite3changeset_next() is called on the iterator or until the
|
||||
** conflict-handler function returns. If pnCol is not NULL, then *pnCol is
|
||||
** set to the number of columns in the table affected by the change. If
|
||||
** pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
|
||||
** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three
|
||||
** outputs are set through these pointers:
|
||||
**
|
||||
** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],
|
||||
** depending on the type of change that the iterator currently points to;
|
||||
**
|
||||
** *pnCol is set to the number of columns in the table affected by the change; and
|
||||
**
|
||||
** *pzTab is set to point to a nul-terminated utf-8 encoded string containing
|
||||
** the name of the table affected by the current change. The buffer remains
|
||||
** valid until either sqlite3changeset_next() is called on the iterator
|
||||
** or until the conflict-handler function returns.
|
||||
**
|
||||
** If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
|
||||
** is an indirect change, or false (0) otherwise. See the documentation for
|
||||
** [sqlite3session_indirect()] for a description of direct and indirect
|
||||
** changes. Finally, if pOp is not NULL, then *pOp is set to one of
|
||||
** [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], depending on the
|
||||
** type of change that the iterator currently points to.
|
||||
** changes.
|
||||
**
|
||||
** If no error occurs, SQLITE_OK is returned. If an error does occur, an
|
||||
** SQLite error code is returned. The values of the output variables may not
|
||||
|
||||
@@ -146,7 +146,10 @@ static int SQLITE_TCLAPI test_sql_exec_changeset(
|
||||
static int test_tcl_integer(Tcl_Interp *interp, const char *zVar){
|
||||
Tcl_Obj *pObj;
|
||||
int iVal = 0;
|
||||
pObj = Tcl_ObjGetVar2(interp, Tcl_NewStringObj(zVar, -1), 0, TCL_GLOBAL_ONLY);
|
||||
Tcl_Obj *pName = Tcl_NewStringObj(zVar, -1);
|
||||
Tcl_IncrRefCount(pName);
|
||||
pObj = Tcl_ObjGetVar2(interp, pName, 0, TCL_GLOBAL_ONLY);
|
||||
Tcl_DecrRefCount(pName);
|
||||
if( pObj ) Tcl_GetIntFromObj(0, pObj, &iVal);
|
||||
return iVal;
|
||||
}
|
||||
@@ -243,6 +246,8 @@ static int SQLITE_TCLAPI test_session_cmd(
|
||||
{ "patchset", 0, "", }, /* 7 */
|
||||
{ "diff", 2, "FROMDB TBL", }, /* 8 */
|
||||
{ "memory_used", 0, "", }, /* 9 */
|
||||
{ "changeset_size", 0, "", }, /* 10 */
|
||||
{ "object_config_size", 1, "INTEGER", }, /* 11 */
|
||||
{ 0 }
|
||||
};
|
||||
int iSub;
|
||||
@@ -354,6 +359,29 @@ static int SQLITE_TCLAPI test_session_cmd(
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(nMalloc));
|
||||
break;
|
||||
}
|
||||
|
||||
case 10: {
|
||||
sqlite3_int64 nSize = sqlite3session_changeset_size(pSession);
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(nSize));
|
||||
break;
|
||||
}
|
||||
case 11: {
|
||||
int rc;
|
||||
int iArg;
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &iArg) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqlite3session_object_config(
|
||||
pSession, SQLITE_SESSION_OBJCONFIG_SIZE, &iArg
|
||||
);
|
||||
if( rc!=SQLITE_OK ){
|
||||
extern const char *sqlite3ErrName(int);
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
|
||||
}else{
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(iArg));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TCL_OK;
|
||||
@@ -379,6 +407,7 @@ static int SQLITE_TCLAPI test_sqlite3session(
|
||||
Tcl_CmdInfo info;
|
||||
int rc; /* sqlite3session_create() return code */
|
||||
TestSession *p; /* New wrapper object */
|
||||
int iArg = -1;
|
||||
|
||||
if( objc!=4 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "CMD DB-HANDLE DB-NAME");
|
||||
@@ -399,6 +428,13 @@ static int SQLITE_TCLAPI test_sqlite3session(
|
||||
return test_session_error(interp, rc, 0);
|
||||
}
|
||||
|
||||
/* Query the SQLITE_SESSION_OBJCONFIG_SIZE option to ensure that it
|
||||
** is clear by default. Then set it. */
|
||||
sqlite3session_object_config(p->pSession,SQLITE_SESSION_OBJCONFIG_SIZE,&iArg);
|
||||
assert( iArg==0 );
|
||||
iArg = 1;
|
||||
sqlite3session_object_config(p->pSession,SQLITE_SESSION_OBJCONFIG_SIZE,&iArg);
|
||||
|
||||
Tcl_CreateObjCommand(
|
||||
interp, Tcl_GetString(objv[1]), test_session_cmd, (ClientData)p,
|
||||
test_session_del
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
###############################################################################
|
||||
# The following macros should be defined before this script is
|
||||
# invoked:
|
||||
@@ -360,6 +361,7 @@ TESTSRC = \
|
||||
#
|
||||
TESTSRC += \
|
||||
$(TOP)/ext/misc/amatch.c \
|
||||
$(TOP)/ext/misc/appendvfs.c \
|
||||
$(TOP)/ext/misc/carray.c \
|
||||
$(TOP)/ext/misc/cksumvfs.c \
|
||||
$(TOP)/ext/misc/closure.c \
|
||||
@@ -438,7 +440,8 @@ TESTSRC2 = \
|
||||
$(TOP)/ext/async/sqlite3async.c \
|
||||
$(TOP)/ext/misc/stmt.c \
|
||||
$(TOP)/ext/session/sqlite3session.c \
|
||||
$(TOP)/ext/session/test_session.c
|
||||
$(TOP)/ext/session/test_session.c \
|
||||
fts5.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
@@ -537,7 +540,6 @@ 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
|
||||
@@ -590,7 +592,6 @@ dbfuzz$(EXE): $(TOP)/test/dbfuzz.c sqlite3.c sqlite3.h
|
||||
DBFUZZ2_OPTS = \
|
||||
-DSQLITE_THREADSAFE=0 \
|
||||
-DSQLITE_OMIT_LOAD_EXTENSION \
|
||||
-DSQLITE_ENABLE_DESERIALIZE \
|
||||
-DSQLITE_DEBUG \
|
||||
-DSQLITE_ENABLE_DBSTAT_VTAB \
|
||||
-DSQLITE_ENABLE_BYTECODE_VTAB \
|
||||
@@ -663,7 +664,7 @@ sqlite3ext.h: target_source
|
||||
cp tsrc/sqlite3ext.h .
|
||||
|
||||
sqlite3.c-debug: target_source $(TOP)/tool/mksqlite3c.tcl
|
||||
tclsh $(TOP)/tool/mksqlite3c.tcl --linemacros
|
||||
tclsh $(TOP)/tool/mksqlite3c.tcl --linemacros=1
|
||||
echo '#ifndef USE_SYSTEM_SQLITE' >tclsqlite3.c
|
||||
cat sqlite3.c >>tclsqlite3.c
|
||||
echo '#endif /* USE_SYSTEM_SQLITE */' >>tclsqlite3.c
|
||||
@@ -747,6 +748,8 @@ SHELL_SRC = \
|
||||
$(TOP)/ext/misc/decimal.c \
|
||||
$(TOP)/ext/misc/fileio.c \
|
||||
$(TOP)/ext/misc/ieee754.c \
|
||||
$(TOP)/ext/misc/regexp.c \
|
||||
$(TOP)/ext/misc/series.c \
|
||||
$(TOP)/ext/misc/shathree.c \
|
||||
$(TOP)/ext/misc/sqlar.c \
|
||||
$(TOP)/ext/misc/uint.c \
|
||||
@@ -954,7 +957,7 @@ fuzztest: fuzzcheck$(EXE) $(FUZZDATA) sessionfuzz$(EXE) $(TOP)/test/sessionfuzz-
|
||||
./sessionfuzz run $(TOP)/test/sessionfuzz-data1.db
|
||||
|
||||
valgrindfuzz: fuzzcheck$(EXE) $(FUZZDATA) sessionfuzz$(EXE) $(TOP)/test/sessionfuzz-data1.db
|
||||
valgrind ./fuzzcheck$(EXE) --cell-size-check --limit-mem 10M --timeout 600 $(FUZZDATA)
|
||||
valgrind ./fuzzcheck$(EXE) --cell-size-check --limit-mem 10M $(FUZZDATA)
|
||||
valgrind ./sessionfuzz run $(TOP)/test/sessionfuzz-data1.db
|
||||
|
||||
# The veryquick.test TCL tests.
|
||||
@@ -1079,6 +1082,9 @@ rbu$(EXE): $(TOP)/ext/rbu/rbu.c $(TOP)/ext/rbu/sqlite3rbu.c sqlite3.o
|
||||
loadfts: $(TOP)/tool/loadfts.c libsqlite3.a
|
||||
$(TCC) $(TOP)/tool/loadfts.c libsqlite3.a -o loadfts $(THREADLIB)
|
||||
|
||||
threadtest5: $(TOP)/test/threadtest5.c libsqlite3.a
|
||||
$(TCC) $(TOP)/test/threadtest5.c libsqlite3.a -o threadtest5 $(THREADLIB)
|
||||
|
||||
# This target will fail if the SQLite amalgamation contains any exported
|
||||
# symbols that do not begin with "sqlite3_". It is run as part of the
|
||||
# releasetest.tcl script.
|
||||
@@ -1141,3 +1147,4 @@ clean:
|
||||
rm -f sqldiff sqldiff.exe
|
||||
rm -f fts5.* fts5parse.*
|
||||
rm -f lsm.h lsm1.c
|
||||
rm -f threadtest5
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
126ee1ec4f3565c0cccca98885fa3665a641ea3df251511de16eed2a1c396124
|
||||
8498d7727c25859f1a48b85bec44a0b9ad6e8c48112498d6c71882458970c637
|
||||
+313
-76
@@ -29,8 +29,9 @@
|
||||
** Or, if zName is not a system table, zero is returned.
|
||||
*/
|
||||
static int isAlterableTable(Parse *pParse, Table *pTab){
|
||||
if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
|
||||
if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
|| (pTab->tabFlags & TF_Eponymous)!=0
|
||||
|| ( (pTab->tabFlags & TF_Shadow)!=0
|
||||
&& sqlite3ReadOnlyShadowTables(pParse->db)
|
||||
)
|
||||
@@ -53,7 +54,8 @@ static void renameTestSchema(
|
||||
Parse *pParse, /* Parse context */
|
||||
const char *zDb, /* Name of db to verify schema of */
|
||||
int bTemp, /* True if this is the temp db */
|
||||
const char *zWhen /* "when" part of error message */
|
||||
const char *zWhen, /* "when" part of error message */
|
||||
int bNoDQS /* Do not allow DQS in the schema */
|
||||
){
|
||||
pParse->colNamesSet = 1;
|
||||
sqlite3NestedParse(pParse,
|
||||
@@ -61,9 +63,9 @@ static void renameTestSchema(
|
||||
"FROM \"%w\"." DFLT_SCHEMA_TABLE " "
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
" AND sql NOT LIKE 'create virtual%%'"
|
||||
" AND sqlite_rename_test(%Q, sql, type, name, %d, %Q)=NULL ",
|
||||
" AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %d)=NULL ",
|
||||
zDb,
|
||||
zDb, bTemp, zWhen
|
||||
zDb, bTemp, zWhen, bNoDQS
|
||||
);
|
||||
|
||||
if( bTemp==0 ){
|
||||
@@ -72,8 +74,32 @@ static void renameTestSchema(
|
||||
"FROM temp." DFLT_SCHEMA_TABLE " "
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
" AND sql NOT LIKE 'create virtual%%'"
|
||||
" AND sqlite_rename_test(%Q, sql, type, name, 1, %Q)=NULL ",
|
||||
zDb, zWhen
|
||||
" AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %d)=NULL ",
|
||||
zDb, zWhen, bNoDQS
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate VM code to replace any double-quoted strings (but not double-quoted
|
||||
** identifiers) within the "sql" column of the sqlite_schema table in
|
||||
** database zDb with their single-quoted equivalents. If argument bTemp is
|
||||
** not true, similarly update all SQL statements in the sqlite_schema table
|
||||
** of the temp db.
|
||||
*/
|
||||
static void renameFixQuotes(Parse *pParse, const char *zDb, int bTemp){
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE
|
||||
" SET sql = sqlite_rename_quotefix(%Q, sql)"
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
" AND sql NOT LIKE 'create virtual%%'" , zDb, zDb
|
||||
);
|
||||
if( bTemp==0 ){
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE temp." DFLT_SCHEMA_TABLE
|
||||
" SET sql = sqlite_rename_quotefix('temp', sql)"
|
||||
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
|
||||
" AND sql NOT LIKE 'create virtual%%'"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -236,7 +262,7 @@ void sqlite3AlterRenameTable(
|
||||
"sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
|
||||
"tbl_name = "
|
||||
"CASE WHEN tbl_name=%Q COLLATE nocase AND "
|
||||
" sqlite_rename_test(%Q, sql, type, name, 1, 'after rename') "
|
||||
" sqlite_rename_test(%Q, sql, type, name, 1, 'after rename', 0) "
|
||||
"THEN %Q ELSE tbl_name END "
|
||||
"WHERE type IN ('view', 'trigger')"
|
||||
, zDb, zTabName, zName, zTabName, zDb, zName);
|
||||
@@ -256,7 +282,7 @@ void sqlite3AlterRenameTable(
|
||||
#endif
|
||||
|
||||
renameReloadSchema(pParse, iDb, INITFLAG_AlterRename);
|
||||
renameTestSchema(pParse, zDb, iDb==1, "after rename");
|
||||
renameTestSchema(pParse, zDb, iDb==1, "after rename", 0);
|
||||
|
||||
exit_rename_table:
|
||||
sqlite3SrcListDelete(db, pSrc);
|
||||
@@ -401,12 +427,12 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
db->mDbFlags = savedDbFlags;
|
||||
}
|
||||
|
||||
/* Make sure the schema version is at least 3. But do not upgrade
|
||||
** from less than 3 to 4, as that will corrupt any preexisting DESC
|
||||
** index.
|
||||
*/
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v ){
|
||||
/* Make sure the schema version is at least 3. But do not upgrade
|
||||
** from less than 3 to 4, as that will corrupt any preexisting DESC
|
||||
** index.
|
||||
*/
|
||||
r1 = sqlite3GetTempReg(pParse);
|
||||
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
|
||||
sqlite3VdbeUsesBtree(v, iDb);
|
||||
@@ -415,10 +441,25 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
VdbeCoverage(v);
|
||||
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3);
|
||||
sqlite3ReleaseTempReg(pParse, r1);
|
||||
}
|
||||
|
||||
/* Reload the table definition */
|
||||
renameReloadSchema(pParse, iDb, INITFLAG_AlterRename);
|
||||
/* Reload the table definition */
|
||||
renameReloadSchema(pParse, iDb, INITFLAG_AlterRename);
|
||||
|
||||
/* Verify that constraints are still satisfied */
|
||||
if( pNew->pCheck!=0
|
||||
|| (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
|
||||
){
|
||||
sqlite3NestedParse(pParse,
|
||||
"SELECT CASE WHEN quick_check GLOB 'CHECK*'"
|
||||
" THEN raise(ABORT,'CHECK constraint failed')"
|
||||
" ELSE raise(ABORT,'NOT NULL constraint failed')"
|
||||
" END"
|
||||
" FROM pragma_quick_check(\"%w\",\"%w\")"
|
||||
" WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'",
|
||||
zTab, zDb
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -595,6 +636,10 @@ void sqlite3AlterRenameColumn(
|
||||
goto exit_rename_column;
|
||||
}
|
||||
|
||||
/* Ensure the schema contains no double-quoted strings */
|
||||
renameTestSchema(pParse, zDb, iSchema==1, "", 0);
|
||||
renameFixQuotes(pParse, zDb, iSchema==1);
|
||||
|
||||
/* Do the rename operation using a recursive UPDATE statement that
|
||||
** uses the sqlite_rename_column() SQL function to compute the new
|
||||
** CREATE statement text for the sqlite_schema table.
|
||||
@@ -624,7 +669,7 @@ void sqlite3AlterRenameColumn(
|
||||
|
||||
/* Drop and reload the database schema. */
|
||||
renameReloadSchema(pParse, iSchema, INITFLAG_AlterRename);
|
||||
renameTestSchema(pParse, zDb, iSchema==1, "after rename");
|
||||
renameTestSchema(pParse, zDb, iSchema==1, "after rename", 1);
|
||||
|
||||
exit_rename_column:
|
||||
sqlite3SrcListDelete(db, pSrc);
|
||||
@@ -770,15 +815,30 @@ static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
|
||||
static void renameWalkWith(Walker *pWalker, Select *pSelect){
|
||||
With *pWith = pSelect->pWith;
|
||||
if( pWith ){
|
||||
Parse *pParse = pWalker->pParse;
|
||||
int i;
|
||||
With *pCopy = 0;
|
||||
assert( pWith->nCte>0 );
|
||||
if( (pWith->a[0].pSelect->selFlags & SF_Expanded)==0 ){
|
||||
/* Push a copy of the With object onto the with-stack. We use a copy
|
||||
** here as the original will be expanded and resolved (flags SF_Expanded
|
||||
** and SF_Resolved) below. And the parser code that uses the with-stack
|
||||
** fails if the Select objects on it have already been expanded and
|
||||
** resolved. */
|
||||
pCopy = sqlite3WithDup(pParse->db, pWith);
|
||||
pCopy = sqlite3WithPush(pParse, pCopy, 1);
|
||||
}
|
||||
for(i=0; i<pWith->nCte; i++){
|
||||
Select *p = pWith->a[i].pSelect;
|
||||
NameContext sNC;
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pWalker->pParse;
|
||||
sqlite3SelectPrep(sNC.pParse, p, &sNC);
|
||||
sNC.pParse = pParse;
|
||||
if( pCopy ) sqlite3SelectPrep(sNC.pParse, p, &sNC);
|
||||
sqlite3WalkSelect(pWalker, p);
|
||||
sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols);
|
||||
sqlite3RenameExprlistUnmap(pParse, pWith->a[i].pCols);
|
||||
}
|
||||
if( pCopy && pParse->pWith==pCopy ){
|
||||
pParse->pWith = pCopy->pOuter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -805,7 +865,11 @@ static int renameUnmapSelectCb(Walker *pWalker, Select *p){
|
||||
Parse *pParse = pWalker->pParse;
|
||||
int i;
|
||||
if( pParse->nErr ) return WRC_Abort;
|
||||
if( NEVER(p->selFlags & SF_View) ) return WRC_Prune;
|
||||
if( p->selFlags & (SF_View|SF_CopyCte) ){
|
||||
testcase( p->selFlags & SF_View );
|
||||
testcase( p->selFlags & SF_CopyCte );
|
||||
return WRC_Prune;
|
||||
}
|
||||
if( ALWAYS(p->pEList) ){
|
||||
ExprList *pList = p->pEList;
|
||||
for(i=0; i<pList->nExpr; i++){
|
||||
@@ -889,7 +953,9 @@ static RenameToken *renameTokenFind(
|
||||
void *pPtr
|
||||
){
|
||||
RenameToken **pp;
|
||||
assert( pPtr!=0 );
|
||||
if( NEVER(pPtr==0) ){
|
||||
return 0;
|
||||
}
|
||||
for(pp=&pParse->pRename; (*pp); pp=&(*pp)->pNext){
|
||||
if( (*pp)->p==pPtr ){
|
||||
RenameToken *pToken = *pp;
|
||||
@@ -911,7 +977,11 @@ static RenameToken *renameTokenFind(
|
||||
** descend into sub-select statements.
|
||||
*/
|
||||
static int renameColumnSelectCb(Walker *pWalker, Select *p){
|
||||
if( p->selFlags & SF_View ) return WRC_Prune;
|
||||
if( p->selFlags & (SF_View|SF_CopyCte) ){
|
||||
testcase( p->selFlags & SF_View );
|
||||
testcase( p->selFlags & SF_CopyCte );
|
||||
return WRC_Prune;
|
||||
}
|
||||
renameWalkWith(pWalker, p);
|
||||
return WRC_Continue;
|
||||
}
|
||||
@@ -1105,51 +1175,76 @@ static int renameEditSql(
|
||||
const char *zNew, /* New token text */
|
||||
int bQuote /* True to always quote token */
|
||||
){
|
||||
int nNew = sqlite3Strlen30(zNew);
|
||||
int nSql = sqlite3Strlen30(zSql);
|
||||
i64 nNew = sqlite3Strlen30(zNew);
|
||||
i64 nSql = sqlite3Strlen30(zSql);
|
||||
sqlite3 *db = sqlite3_context_db_handle(pCtx);
|
||||
int rc = SQLITE_OK;
|
||||
char *zQuot;
|
||||
char *zQuot = 0;
|
||||
char *zOut;
|
||||
int nQuot;
|
||||
i64 nQuot = 0;
|
||||
char *zBuf1 = 0;
|
||||
char *zBuf2 = 0;
|
||||
|
||||
/* Set zQuot to point to a buffer containing a quoted copy of the
|
||||
** identifier zNew. If the corresponding identifier in the original
|
||||
** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
|
||||
** point to zQuot so that all substitutions are made using the
|
||||
** quoted version of the new column name. */
|
||||
zQuot = sqlite3MPrintf(db, "\"%w\"", zNew);
|
||||
if( zQuot==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
if( zNew ){
|
||||
/* Set zQuot to point to a buffer containing a quoted copy of the
|
||||
** identifier zNew. If the corresponding identifier in the original
|
||||
** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
|
||||
** point to zQuot so that all substitutions are made using the
|
||||
** quoted version of the new column name. */
|
||||
zQuot = sqlite3MPrintf(db, "\"%w\" ", zNew);
|
||||
if( zQuot==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}else{
|
||||
nQuot = sqlite3Strlen30(zQuot)-1;
|
||||
}
|
||||
|
||||
assert( nQuot>=nNew );
|
||||
zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1);
|
||||
}else{
|
||||
nQuot = sqlite3Strlen30(zQuot);
|
||||
}
|
||||
if( bQuote ){
|
||||
zNew = zQuot;
|
||||
nNew = nQuot;
|
||||
zOut = (char*)sqlite3DbMallocZero(db, (nSql*2+1) * 3);
|
||||
if( zOut ){
|
||||
zBuf1 = &zOut[nSql*2+1];
|
||||
zBuf2 = &zOut[nSql*4+2];
|
||||
}
|
||||
}
|
||||
|
||||
/* At this point pRename->pList contains a list of RenameToken objects
|
||||
** corresponding to all tokens in the input SQL that must be replaced
|
||||
** with the new column name. All that remains is to construct and
|
||||
** return the edited SQL string. */
|
||||
assert( nQuot>=nNew );
|
||||
zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1);
|
||||
** with the new column name, or with single-quoted versions of themselves.
|
||||
** All that remains is to construct and return the edited SQL string. */
|
||||
if( zOut ){
|
||||
int nOut = nSql;
|
||||
memcpy(zOut, zSql, nSql);
|
||||
while( pRename->pList ){
|
||||
int iOff; /* Offset of token to replace in zOut */
|
||||
RenameToken *pBest = renameColumnTokenNext(pRename);
|
||||
|
||||
u32 nReplace;
|
||||
const char *zReplace;
|
||||
if( sqlite3IsIdChar(*pBest->t.z) ){
|
||||
nReplace = nNew;
|
||||
zReplace = zNew;
|
||||
RenameToken *pBest = renameColumnTokenNext(pRename);
|
||||
|
||||
if( zNew ){
|
||||
if( bQuote==0 && sqlite3IsIdChar(*pBest->t.z) ){
|
||||
nReplace = nNew;
|
||||
zReplace = zNew;
|
||||
}else{
|
||||
nReplace = nQuot;
|
||||
zReplace = zQuot;
|
||||
if( pBest->t.z[pBest->t.n]=='"' ) nReplace++;
|
||||
}
|
||||
}else{
|
||||
nReplace = nQuot;
|
||||
zReplace = zQuot;
|
||||
/* Dequote the double-quoted token. Then requote it again, this time
|
||||
** using single quotes. If the character immediately following the
|
||||
** original token within the input SQL was a single quote ('), then
|
||||
** add another space after the new, single-quoted version of the
|
||||
** token. This is so that (SELECT "string"'alias') maps to
|
||||
** (SELECT 'string' 'alias'), and not (SELECT 'string''alias'). */
|
||||
memcpy(zBuf1, pBest->t.z, pBest->t.n);
|
||||
zBuf1[pBest->t.n] = 0;
|
||||
sqlite3Dequote(zBuf1);
|
||||
sqlite3_snprintf(nSql*2, zBuf2, "%Q%s", zBuf1,
|
||||
pBest->t.z[pBest->t.n]=='\'' ? " " : ""
|
||||
);
|
||||
zReplace = zBuf2;
|
||||
nReplace = sqlite3Strlen30(zReplace);
|
||||
}
|
||||
|
||||
iOff = pBest->t.z - zSql;
|
||||
@@ -1215,7 +1310,7 @@ static int renameResolveTrigger(Parse *pParse){
|
||||
if( pSrc ){
|
||||
int i;
|
||||
for(i=0; i<pSrc->nSrc && rc==SQLITE_OK; i++){
|
||||
struct SrcList_item *p = &pSrc->a[i];
|
||||
SrcItem *p = &pSrc->a[i];
|
||||
p->iCursor = pParse->nTab++;
|
||||
if( p->pSelect ){
|
||||
sqlite3SelectPrep(pParse, p->pSelect, 0);
|
||||
@@ -1241,9 +1336,8 @@ static int renameResolveTrigger(Parse *pParse){
|
||||
rc = sqlite3ResolveExprListNames(&sNC, pStep->pExprList);
|
||||
}
|
||||
assert( !pStep->pUpsert || (!pStep->pWhere && !pStep->pExprList) );
|
||||
if( pStep->pUpsert ){
|
||||
if( pStep->pUpsert && rc==SQLITE_OK ){
|
||||
Upsert *pUpsert = pStep->pUpsert;
|
||||
assert( rc==SQLITE_OK );
|
||||
pUpsert->pUpsertSrc = pSrc;
|
||||
sNC.uNC.pUpsert = pUpsert;
|
||||
sNC.ncFlags = NC_UUpsert;
|
||||
@@ -1417,9 +1511,11 @@ static void renameColumnFunc(
|
||||
assert( sParse.pNewTable->pSelect==0 );
|
||||
sCtx.pTab = sParse.pNewTable;
|
||||
if( bFKOnly==0 ){
|
||||
renameTokenFind(
|
||||
&sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zName
|
||||
);
|
||||
if( iCol<sParse.pNewTable->nCol ){
|
||||
renameTokenFind(
|
||||
&sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zName
|
||||
);
|
||||
}
|
||||
if( sCtx.iCol<0 ){
|
||||
renameTokenFind(&sParse, &sCtx, (void*)&sParse.pNewTable->iPKey);
|
||||
}
|
||||
@@ -1430,12 +1526,12 @@ static void renameColumnFunc(
|
||||
for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){
|
||||
sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
|
||||
for(i=0; i<sParse.pNewTable->nCol; i++){
|
||||
sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
|
||||
}
|
||||
for(i=0; i<sParse.pNewTable->nCol; i++){
|
||||
sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){
|
||||
for(i=0; i<pFKey->nCol; i++){
|
||||
@@ -1521,13 +1617,17 @@ static int renameTableSelectCb(Walker *pWalker, Select *pSelect){
|
||||
int i;
|
||||
RenameCtx *p = pWalker->u.pRename;
|
||||
SrcList *pSrc = pSelect->pSrc;
|
||||
if( pSelect->selFlags & SF_View ) return WRC_Prune;
|
||||
if( pSrc==0 ){
|
||||
if( pSelect->selFlags & (SF_View|SF_CopyCte) ){
|
||||
testcase( pSelect->selFlags & SF_View );
|
||||
testcase( pSelect->selFlags & SF_CopyCte );
|
||||
return WRC_Prune;
|
||||
}
|
||||
if( NEVER(pSrc==0) ){
|
||||
assert( pWalker->pParse->db->mallocFailed );
|
||||
return WRC_Abort;
|
||||
}
|
||||
for(i=0; i<pSrc->nSrc; i++){
|
||||
struct SrcList_item *pItem = &pSrc->a[i];
|
||||
SrcItem *pItem = &pSrc->a[i];
|
||||
if( pItem->pTab==p->pTab ){
|
||||
renameTokenFind(pWalker->pParse, p, pItem->zName);
|
||||
}
|
||||
@@ -1695,6 +1795,119 @@ static void renameTableFunc(
|
||||
return;
|
||||
}
|
||||
|
||||
static int renameQuotefixExprCb(Walker *pWalker, Expr *pExpr){
|
||||
if( pExpr->op==TK_STRING && (pExpr->flags & EP_DblQuoted) ){
|
||||
renameTokenFind(pWalker->pParse, pWalker->u.pRename, (void*)pExpr);
|
||||
}
|
||||
return WRC_Continue;
|
||||
}
|
||||
|
||||
/*
|
||||
** The implementation of an SQL scalar function that rewrites DDL statements
|
||||
** so that any string literals that use double-quotes are modified so that
|
||||
** they use single quotes.
|
||||
**
|
||||
** Two arguments must be passed:
|
||||
**
|
||||
** 0: Database name ("main", "temp" etc.).
|
||||
** 1: SQL statement to edit.
|
||||
**
|
||||
** The returned value is the modified SQL statement. For example, given
|
||||
** the database schema:
|
||||
**
|
||||
** CREATE TABLE t1(a, b, c);
|
||||
**
|
||||
** SELECT sqlite_rename_quotefix('main',
|
||||
** 'CREATE VIEW v1 AS SELECT "a", "string" FROM t1'
|
||||
** );
|
||||
**
|
||||
** returns the string:
|
||||
**
|
||||
** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1
|
||||
*/
|
||||
static void renameQuotefixFunc(
|
||||
sqlite3_context *context,
|
||||
int NotUsed,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
char const *zDb = (const char*)sqlite3_value_text(argv[0]);
|
||||
char const *zInput = (const char*)sqlite3_value_text(argv[1]);
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
sqlite3_xauth xAuth = db->xAuth;
|
||||
db->xAuth = 0;
|
||||
#endif
|
||||
|
||||
sqlite3BtreeEnterAll(db);
|
||||
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
if( zDb && zInput ){
|
||||
int rc;
|
||||
Parse sParse;
|
||||
rc = renameParseSql(&sParse, zDb, db, zInput, 0);
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
RenameCtx sCtx;
|
||||
Walker sWalker;
|
||||
|
||||
/* Walker to find tokens that need to be replaced. */
|
||||
memset(&sCtx, 0, sizeof(RenameCtx));
|
||||
memset(&sWalker, 0, sizeof(Walker));
|
||||
sWalker.pParse = &sParse;
|
||||
sWalker.xExprCallback = renameQuotefixExprCb;
|
||||
sWalker.xSelectCallback = renameColumnSelectCb;
|
||||
sWalker.u.pRename = &sCtx;
|
||||
|
||||
if( sParse.pNewTable ){
|
||||
Select *pSelect = sParse.pNewTable->pSelect;
|
||||
if( pSelect ){
|
||||
pSelect->selFlags &= ~SF_View;
|
||||
sParse.rc = SQLITE_OK;
|
||||
sqlite3SelectPrep(&sParse, pSelect, 0);
|
||||
rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3WalkSelect(&sWalker, pSelect);
|
||||
}
|
||||
}else{
|
||||
int i;
|
||||
sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck);
|
||||
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
|
||||
for(i=0; i<sParse.pNewTable->nCol; i++){
|
||||
sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
|
||||
}
|
||||
}else if( sParse.pNewIndex ){
|
||||
sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr);
|
||||
sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere);
|
||||
}else{
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
rc = renameResolveTrigger(&sParse);
|
||||
if( rc==SQLITE_OK ){
|
||||
renameWalkTrigger(&sWalker, sParse.pNewTrigger);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_TRIGGER */
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = renameEditSql(context, &sCtx, zInput, 0, 0);
|
||||
}
|
||||
renameTokenFree(db, sCtx.pList);
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3_result_error_code(context, rc);
|
||||
}
|
||||
renameParseCleanup(&sParse);
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
db->xAuth = xAuth;
|
||||
#endif
|
||||
|
||||
sqlite3BtreeLeaveAll(db);
|
||||
}
|
||||
|
||||
/*
|
||||
** An SQL user function that checks that there are no parse or symbol
|
||||
** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement.
|
||||
@@ -1708,6 +1921,7 @@ static void renameTableFunc(
|
||||
** 3: Object name.
|
||||
** 4: True if object is from temp schema.
|
||||
** 5: "when" part of error message.
|
||||
** 6: True to disable the DQS quirk when parsing SQL.
|
||||
**
|
||||
** Unless it finds an error, this function normally returns NULL. However, it
|
||||
** returns integer value 1 if:
|
||||
@@ -1726,6 +1940,7 @@ static void renameTableTest(
|
||||
int bTemp = sqlite3_value_int(argv[4]);
|
||||
int isLegacy = (db->flags & SQLITE_LegacyAlter);
|
||||
char const *zWhen = (const char*)sqlite3_value_text(argv[5]);
|
||||
int bNoDQS = sqlite3_value_int(argv[6]);
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
sqlite3_xauth xAuth = db->xAuth;
|
||||
@@ -1733,10 +1948,14 @@ static void renameTableTest(
|
||||
#endif
|
||||
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
|
||||
if( zDb && zInput ){
|
||||
int rc;
|
||||
Parse sParse;
|
||||
int flags = db->flags;
|
||||
if( bNoDQS ) db->flags &= ~(SQLITE_DqsDML|SQLITE_DqsDDL);
|
||||
rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
|
||||
db->flags |= (flags & (SQLITE_DqsDML|SQLITE_DqsDDL));
|
||||
if( rc==SQLITE_OK ){
|
||||
if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
|
||||
NameContext sNC;
|
||||
@@ -1777,7 +1996,6 @@ static void renameTableTest(
|
||||
** argv[0]: An integer - the index of the schema containing the table
|
||||
** argv[1]: CREATE TABLE statement to modify.
|
||||
** argv[2]: An integer - the index of the column to remove.
|
||||
** argv[3]: Byte offset of first byte after last column definition in argv[1]
|
||||
**
|
||||
** The value returned is a string containing the CREATE TABLE statement
|
||||
** with column argv[2] removed.
|
||||
@@ -1791,7 +2009,6 @@ static void dropColumnFunc(
|
||||
int iSchema = sqlite3_value_int(argv[0]);
|
||||
const char *zSql = (const char*)sqlite3_value_text(argv[1]);
|
||||
int iCol = sqlite3_value_int(argv[2]);
|
||||
int iAddColOffset = sqlite3_value_int(argv[3]);
|
||||
const char *zDb = db->aDb[iSchema].zDbSName;
|
||||
int rc;
|
||||
Parse sParse;
|
||||
@@ -1805,10 +2022,11 @@ static void dropColumnFunc(
|
||||
db->xAuth = 0;
|
||||
#endif
|
||||
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1);
|
||||
if( rc!=SQLITE_OK ) goto drop_column_done;
|
||||
pTab = sParse.pNewTable;
|
||||
if( iCol>=pTab->nCol ){
|
||||
if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
|
||||
/* This can happen if the sqlite_schema table is corrupt */
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto drop_column_done;
|
||||
@@ -1820,7 +2038,7 @@ static void dropColumnFunc(
|
||||
pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zName);
|
||||
zEnd = (const char*)pEnd->t.z;
|
||||
}else{
|
||||
zEnd = (const char*)&zSql[iAddColOffset];
|
||||
zEnd = (const char*)&zSql[pTab->addColOffset];
|
||||
while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
|
||||
}
|
||||
|
||||
@@ -1898,17 +2116,18 @@ void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, Token *pName){
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
assert( iDb>=0 );
|
||||
zDb = db->aDb[iDb].zDbSName;
|
||||
renameTestSchema(pParse, zDb, iDb==1, "");
|
||||
renameTestSchema(pParse, zDb, iDb==1, "", 0);
|
||||
renameFixQuotes(pParse, zDb, iDb==1);
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
|
||||
"sql = sqlite_drop_column(%d, sql, %d, %d) "
|
||||
"sql = sqlite_drop_column(%d, sql, %d) "
|
||||
"WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)"
|
||||
, zDb, iDb, iCol, pTab->addColOffset, pTab->zName
|
||||
, zDb, iDb, iCol, pTab->zName
|
||||
);
|
||||
|
||||
/* Drop and reload the database schema. */
|
||||
renameReloadSchema(pParse, iDb, INITFLAG_AlterDrop);
|
||||
renameTestSchema(pParse, zDb, iDb==1, "after drop column");
|
||||
renameTestSchema(pParse, zDb, iDb==1, "after drop column", 1);
|
||||
|
||||
/* Edit rows of table on disk */
|
||||
if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){
|
||||
@@ -1924,33 +2143,50 @@ void sqlite3AlterDropColumn(Parse *pParse, SrcList *pSrc, Token *pName){
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);
|
||||
addr = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
|
||||
reg = ++pParse->nMem;
|
||||
pParse->nMem += pTab->nCol;
|
||||
if( HasRowid(pTab) ){
|
||||
sqlite3VdbeAddOp2(v, OP_Rowid, iCur, reg);
|
||||
pParse->nMem += pTab->nCol;
|
||||
}else{
|
||||
pPk = sqlite3PrimaryKeyIndex(pTab);
|
||||
pParse->nMem += pPk->nColumn;
|
||||
for(i=0; i<pPk->nKeyCol; i++){
|
||||
sqlite3VdbeAddOp3(v, OP_Column, iCur, i, reg+i+1);
|
||||
}
|
||||
nField = pPk->nKeyCol;
|
||||
}
|
||||
regRec = ++pParse->nMem;
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i!=iCol && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
|
||||
int regOut;
|
||||
if( pPk ){
|
||||
int iPos = sqlite3TableColumnToIndex(pPk, i);
|
||||
int iColPos = sqlite3TableColumnToIndex(pPk, iCol);
|
||||
if( iPos<pPk->nKeyCol ) continue;
|
||||
regOut = reg+1+iPos-(iPos>iColPos);
|
||||
}else{
|
||||
regOut = reg+1+nField;
|
||||
}
|
||||
sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
|
||||
if( i==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp2(v, OP_Null, 0, regOut);
|
||||
}else{
|
||||
sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
|
||||
}
|
||||
nField++;
|
||||
}
|
||||
}
|
||||
regRec = reg + pTab->nCol;
|
||||
if( nField==0 ){
|
||||
/* dbsqlfuzz 5f09e7bcc78b4954d06bf9f2400d7715f48d1fef */
|
||||
pParse->nMem++;
|
||||
sqlite3VdbeAddOp2(v, OP_Null, 0, reg+1);
|
||||
nField = 1;
|
||||
}
|
||||
sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec);
|
||||
if( pPk ){
|
||||
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol);
|
||||
}else{
|
||||
sqlite3VdbeAddOp3(v, OP_Insert, iCur, regRec, reg);
|
||||
}
|
||||
sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
|
||||
|
||||
sqlite3VdbeAddOp2(v, OP_Next, iCur, addr+1); VdbeCoverage(v);
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
@@ -1968,8 +2204,9 @@ void sqlite3AlterFunctions(void){
|
||||
static FuncDef aAlterTableFuncs[] = {
|
||||
INTERNAL_FUNCTION(sqlite_rename_column, 9, renameColumnFunc),
|
||||
INTERNAL_FUNCTION(sqlite_rename_table, 7, renameTableFunc),
|
||||
INTERNAL_FUNCTION(sqlite_rename_test, 6, renameTableTest),
|
||||
INTERNAL_FUNCTION(sqlite_drop_column, 4, dropColumnFunc),
|
||||
INTERNAL_FUNCTION(sqlite_rename_test, 7, renameTableTest),
|
||||
INTERNAL_FUNCTION(sqlite_drop_column, 3, dropColumnFunc),
|
||||
INTERNAL_FUNCTION(sqlite_rename_quotefix,2, renameQuotefixFunc),
|
||||
};
|
||||
sqlite3InsertBuiltinFuncs(aAlterTableFuncs, ArraySize(aAlterTableFuncs));
|
||||
}
|
||||
|
||||
+23
-18
@@ -95,7 +95,7 @@ static void attachFunc(
|
||||
if( zFile==0 ) zFile = "";
|
||||
if( zName==0 ) zName = "";
|
||||
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
#ifndef SQLITE_OMIT_DESERIALIZE
|
||||
# define REOPEN_AS_MEMDB(db) (db->init.reopenMemdb)
|
||||
#else
|
||||
# define REOPEN_AS_MEMDB(db) (0)
|
||||
@@ -456,7 +456,7 @@ static int fixExprCb(Walker *p, Expr *pExpr){
|
||||
static int fixSelectCb(Walker *p, Select *pSelect){
|
||||
DbFixer *pFix = p->u.pFix;
|
||||
int i;
|
||||
struct SrcList_item *pItem;
|
||||
SrcItem *pItem;
|
||||
sqlite3 *db = pFix->pParse->db;
|
||||
int iDb = sqlite3FindDbName(db, pFix->zDb);
|
||||
SrcList *pList = pSelect->pSrc;
|
||||
@@ -464,14 +464,17 @@ static int fixSelectCb(Walker *p, Select *pSelect){
|
||||
if( NEVER(pList==0) ) return WRC_Continue;
|
||||
for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
|
||||
if( pFix->bTemp==0 ){
|
||||
if( pItem->zDatabase && iDb!=sqlite3FindDbName(db, pItem->zDatabase) ){
|
||||
sqlite3ErrorMsg(pFix->pParse,
|
||||
"%s %T cannot reference objects in database %s",
|
||||
pFix->zType, pFix->pName, pItem->zDatabase);
|
||||
return WRC_Abort;
|
||||
if( pItem->zDatabase ){
|
||||
if( iDb!=sqlite3FindDbName(db, pItem->zDatabase) ){
|
||||
sqlite3ErrorMsg(pFix->pParse,
|
||||
"%s %T cannot reference objects in database %s",
|
||||
pFix->zType, pFix->pName, pItem->zDatabase);
|
||||
return WRC_Abort;
|
||||
}
|
||||
sqlite3DbFree(db, pItem->zDatabase);
|
||||
pItem->zDatabase = 0;
|
||||
pItem->fg.notCte = 1;
|
||||
}
|
||||
sqlite3DbFree(db, pItem->zDatabase);
|
||||
pItem->zDatabase = 0;
|
||||
pItem->pSchema = pFix->pSchema;
|
||||
pItem->fg.fromDDL = 1;
|
||||
}
|
||||
@@ -511,7 +514,7 @@ void sqlite3FixInit(
|
||||
pFix->w.pParse = pParse;
|
||||
pFix->w.xExprCallback = fixExprCb;
|
||||
pFix->w.xSelectCallback = fixSelectCb;
|
||||
pFix->w.xSelectCallback2 = 0;
|
||||
pFix->w.xSelectCallback2 = sqlite3WalkWinDefnDummyCallback;
|
||||
pFix->w.walkerDepth = 0;
|
||||
pFix->w.eCode = 0;
|
||||
pFix->w.u.pFix = pFix;
|
||||
@@ -573,14 +576,16 @@ int sqlite3FixTriggerStep(
|
||||
return 1;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UPSERT
|
||||
if( pStep->pUpsert ){
|
||||
Upsert *pUp = pStep->pUpsert;
|
||||
if( sqlite3WalkExprList(&pFix->w, pUp->pUpsertTarget)
|
||||
|| sqlite3WalkExpr(&pFix->w, pUp->pUpsertTargetWhere)
|
||||
|| sqlite3WalkExprList(&pFix->w, pUp->pUpsertSet)
|
||||
|| sqlite3WalkExpr(&pFix->w, pUp->pUpsertWhere)
|
||||
){
|
||||
return 1;
|
||||
{
|
||||
Upsert *pUp;
|
||||
for(pUp=pStep->pUpsert; pUp; pUp=pUp->pNextUpsert){
|
||||
if( sqlite3WalkExprList(&pFix->w, pUp->pUpsertTarget)
|
||||
|| sqlite3WalkExpr(&pFix->w, pUp->pUpsertTargetWhere)
|
||||
|| sqlite3WalkExprList(&pFix->w, pUp->pUpsertSet)
|
||||
|| sqlite3WalkExpr(&pFix->w, pUp->pUpsertWhere)
|
||||
){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
+348
-222
@@ -547,7 +547,7 @@ static void invalidateIncrblobCursors(
|
||||
int isClearTable /* True if all rows are being deleted */
|
||||
){
|
||||
BtCursor *p;
|
||||
if( pBtree->hasIncrblobCur==0 ) return;
|
||||
assert( pBtree->hasIncrblobCur );
|
||||
assert( sqlite3BtreeHoldsMutex(pBtree) );
|
||||
pBtree->hasIncrblobCur = 0;
|
||||
for(p=pBtree->pBt->pCursor; p; p=p->pNext){
|
||||
@@ -827,15 +827,13 @@ static int btreeMoveto(
|
||||
sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
|
||||
if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto moveto_done;
|
||||
}else{
|
||||
rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes);
|
||||
}
|
||||
sqlite3DbFree(pCur->pKeyInfo->db, pIdxKey);
|
||||
}else{
|
||||
pIdxKey = 0;
|
||||
}
|
||||
rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
|
||||
moveto_done:
|
||||
if( pIdxKey ){
|
||||
sqlite3DbFree(pCur->pKeyInfo->db, pIdxKey);
|
||||
rc = sqlite3BtreeTableMoveto(pCur, nKey, bias, pRes);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -1448,6 +1446,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
|
||||
unsigned char *src; /* Source of content */
|
||||
int iCellFirst; /* First allowable cell index */
|
||||
int iCellLast; /* Last possible cell index */
|
||||
int iCellStart; /* First cell offset in input */
|
||||
|
||||
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
|
||||
assert( pPage->pBt!=0 );
|
||||
@@ -1489,7 +1488,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
|
||||
if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
|
||||
memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
|
||||
sz += sz2;
|
||||
}else if( NEVER(iFree+sz>usableSize) ){
|
||||
}else if( iFree+sz>usableSize ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
|
||||
@@ -1508,6 +1507,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
|
||||
|
||||
cbrk = usableSize;
|
||||
iCellLast = usableSize - 4;
|
||||
iCellStart = get2byte(&data[hdr+5]);
|
||||
for(i=0; i<nCell; i++){
|
||||
u8 *pAddr; /* The i-th cell pointer */
|
||||
pAddr = &data[cellOffset + i*2];
|
||||
@@ -1517,25 +1517,23 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
|
||||
/* These conditions have already been verified in btreeInitPage()
|
||||
** if PRAGMA cell_size_check=ON.
|
||||
*/
|
||||
if( pc<iCellFirst || pc>iCellLast ){
|
||||
if( pc<iCellStart || pc>iCellLast ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
assert( pc>=iCellFirst && pc<=iCellLast );
|
||||
assert( pc>=iCellStart && pc<=iCellLast );
|
||||
size = pPage->xCellSize(pPage, &src[pc]);
|
||||
cbrk -= size;
|
||||
if( cbrk<iCellFirst || pc+size>usableSize ){
|
||||
if( cbrk<iCellStart || pc+size>usableSize ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
|
||||
assert( cbrk+size<=usableSize && cbrk>=iCellStart );
|
||||
testcase( cbrk+size==usableSize );
|
||||
testcase( pc+size==usableSize );
|
||||
put2byte(pAddr, cbrk);
|
||||
if( temp==0 ){
|
||||
int x;
|
||||
if( cbrk==pc ) continue;
|
||||
temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
|
||||
x = get2byte(&data[hdr+5]);
|
||||
memcpy(&temp[x], &data[x], (cbrk+size) - x);
|
||||
memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
|
||||
src = temp;
|
||||
}
|
||||
memcpy(&data[cbrk], &src[pc], size);
|
||||
@@ -1684,7 +1682,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
|
||||
int g2;
|
||||
assert( pSpace+nByte<=data+pPage->pBt->usableSize );
|
||||
*pIdx = g2 = (int)(pSpace-data);
|
||||
if( NEVER(g2<=gap) ){
|
||||
if( g2<=gap ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
@@ -2737,19 +2735,23 @@ static void freeTempSpace(BtShared *pBt){
|
||||
*/
|
||||
int sqlite3BtreeClose(Btree *p){
|
||||
BtShared *pBt = p->pBt;
|
||||
BtCursor *pCur;
|
||||
|
||||
/* Close all cursors opened via this handle. */
|
||||
assert( sqlite3_mutex_held(p->db->mutex) );
|
||||
sqlite3BtreeEnter(p);
|
||||
pCur = pBt->pCursor;
|
||||
while( pCur ){
|
||||
BtCursor *pTmp = pCur;
|
||||
pCur = pCur->pNext;
|
||||
if( pTmp->pBtree==p ){
|
||||
sqlite3BtreeCloseCursor(pTmp);
|
||||
|
||||
/* Verify that no other cursors have this Btree open */
|
||||
#ifdef SQLITE_DEBUG
|
||||
{
|
||||
BtCursor *pCur = pBt->pCursor;
|
||||
while( pCur ){
|
||||
BtCursor *pTmp = pCur;
|
||||
pCur = pCur->pNext;
|
||||
assert( pTmp->pBtree!=p );
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Rollback any active transaction and free the handle structure.
|
||||
** The call to sqlite3BtreeRollback() drops any table-locks held by
|
||||
@@ -4131,7 +4133,7 @@ int sqlite3BtreeCommitPhaseTwo(Btree *p, int bCleanup){
|
||||
sqlite3BtreeLeave(p);
|
||||
return rc;
|
||||
}
|
||||
p->iDataVersion--; /* Compensate for pPager->iDataVersion++; */
|
||||
p->iBDataVersion--; /* Compensate for pPager->iDataVersion++; */
|
||||
pBt->inTransaction = TRANS_READ;
|
||||
btreeClearHasContent(pBt);
|
||||
}
|
||||
@@ -4541,7 +4543,14 @@ int sqlite3BtreeCloseCursor(BtCursor *pCur){
|
||||
unlockBtreeIfUnused(pBt);
|
||||
sqlite3_free(pCur->aOverflow);
|
||||
sqlite3_free(pCur->pKey);
|
||||
sqlite3BtreeLeave(pBtree);
|
||||
if( (pBt->openFlags & BTREE_SINGLE) && pBt->pCursor==0 ){
|
||||
/* Since the BtShared is not sharable, there is no need to
|
||||
** worry about the missing sqlite3BtreeLeave() call here. */
|
||||
assert( pBtree->sharable==0 );
|
||||
sqlite3BtreeClose(pBtree);
|
||||
}else{
|
||||
sqlite3BtreeLeave(pBtree);
|
||||
}
|
||||
pCur->pBtree = 0;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
@@ -5383,7 +5392,9 @@ int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
|
||||
for(ii=0; ii<pCur->iPage; ii++){
|
||||
assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
|
||||
}
|
||||
assert( pCur->ix==pCur->pPage->nCell-1 );
|
||||
assert( pCur->ix==pCur->pPage->nCell-1 || CORRUPT_DB );
|
||||
testcase( pCur->ix!=pCur->pPage->nCell-1 );
|
||||
/* ^-- dbsqlfuzz b92b72e4de80b5140c30ab71372ca719b8feb618 */
|
||||
assert( pCur->pPage->leaf );
|
||||
#endif
|
||||
*pRes = 0;
|
||||
@@ -5408,12 +5419,8 @@ int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Move the cursor so that it points to an entry near the key
|
||||
** specified by pIdxKey or intKey. Return a success code.
|
||||
**
|
||||
** For INTKEY tables, the intKey parameter is used. pIdxKey
|
||||
** must be NULL. For index tables, pIdxKey is used and intKey
|
||||
** is ignored.
|
||||
/* Move the cursor so that it points to an entry in a table (a.k.a INTKEY)
|
||||
** table near the key intKey. Return a success code.
|
||||
**
|
||||
** If an exact match is not found, then the cursor is always
|
||||
** left pointing at a leaf page which would hold the entry if it
|
||||
@@ -5426,39 +5433,32 @@ int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
|
||||
** *pRes is as follows:
|
||||
**
|
||||
** *pRes<0 The cursor is left pointing at an entry that
|
||||
** is smaller than intKey/pIdxKey or if the table is empty
|
||||
** is smaller than intKey or if the table is empty
|
||||
** and the cursor is therefore left point to nothing.
|
||||
**
|
||||
** *pRes==0 The cursor is left pointing at an entry that
|
||||
** exactly matches intKey/pIdxKey.
|
||||
** exactly matches intKey.
|
||||
**
|
||||
** *pRes>0 The cursor is left pointing at an entry that
|
||||
** is larger than intKey/pIdxKey.
|
||||
**
|
||||
** For index tables, the pIdxKey->eqSeen field is set to 1 if there
|
||||
** exists an entry in the table that exactly matches pIdxKey.
|
||||
** is larger than intKey.
|
||||
*/
|
||||
int sqlite3BtreeMovetoUnpacked(
|
||||
int sqlite3BtreeTableMoveto(
|
||||
BtCursor *pCur, /* The cursor to be moved */
|
||||
UnpackedRecord *pIdxKey, /* Unpacked index key */
|
||||
i64 intKey, /* The table key */
|
||||
int biasRight, /* If true, bias the search to the high end */
|
||||
int *pRes /* Write search results here */
|
||||
){
|
||||
int rc;
|
||||
RecordCompare xRecordCompare;
|
||||
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
|
||||
assert( pRes );
|
||||
assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
|
||||
assert( pCur->eState!=CURSOR_VALID || (pIdxKey==0)==(pCur->curIntKey!=0) );
|
||||
assert( pCur->pKeyInfo==0 );
|
||||
assert( pCur->eState!=CURSOR_VALID || pCur->curIntKey!=0 );
|
||||
|
||||
/* If the cursor is already positioned at the point we are trying
|
||||
** to move to, then just return without doing any work */
|
||||
if( pIdxKey==0
|
||||
&& pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0
|
||||
){
|
||||
if( pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0 ){
|
||||
if( pCur->info.nKey==intKey ){
|
||||
*pRes = 0;
|
||||
return SQLITE_OK;
|
||||
@@ -5493,16 +5493,149 @@ int sqlite3BtreeMovetoUnpacked(
|
||||
pCur->pBtree->nSeek++; /* Performance measurement during testing */
|
||||
#endif
|
||||
|
||||
if( pIdxKey ){
|
||||
xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
|
||||
pIdxKey->errCode = 0;
|
||||
assert( pIdxKey->default_rc==1
|
||||
|| pIdxKey->default_rc==0
|
||||
|| pIdxKey->default_rc==-1
|
||||
);
|
||||
}else{
|
||||
xRecordCompare = 0; /* All keys are integers */
|
||||
rc = moveToRoot(pCur);
|
||||
if( rc ){
|
||||
if( rc==SQLITE_EMPTY ){
|
||||
assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
|
||||
*pRes = -1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
assert( pCur->pPage );
|
||||
assert( pCur->pPage->isInit );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( pCur->pPage->nCell > 0 );
|
||||
assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey );
|
||||
assert( pCur->curIntKey );
|
||||
|
||||
for(;;){
|
||||
int lwr, upr, idx, c;
|
||||
Pgno chldPg;
|
||||
MemPage *pPage = pCur->pPage;
|
||||
u8 *pCell; /* Pointer to current cell in pPage */
|
||||
|
||||
/* pPage->nCell must be greater than zero. If this is the root-page
|
||||
** the cursor would have been INVALID above and this for(;;) loop
|
||||
** not run. If this is not the root-page, then the moveToChild() routine
|
||||
** would have already detected db corruption. Similarly, pPage must
|
||||
** be the right kind (index or table) of b-tree page. Otherwise
|
||||
** a moveToChild() or moveToRoot() call would have detected corruption. */
|
||||
assert( pPage->nCell>0 );
|
||||
assert( pPage->intKey );
|
||||
lwr = 0;
|
||||
upr = pPage->nCell-1;
|
||||
assert( biasRight==0 || biasRight==1 );
|
||||
idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
|
||||
pCur->ix = (u16)idx;
|
||||
for(;;){
|
||||
i64 nCellKey;
|
||||
pCell = findCellPastPtr(pPage, idx);
|
||||
if( pPage->intKeyLeaf ){
|
||||
while( 0x80 <= *(pCell++) ){
|
||||
if( pCell>=pPage->aDataEnd ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
getVarint(pCell, (u64*)&nCellKey);
|
||||
if( nCellKey<intKey ){
|
||||
lwr = idx+1;
|
||||
if( lwr>upr ){ c = -1; break; }
|
||||
}else if( nCellKey>intKey ){
|
||||
upr = idx-1;
|
||||
if( lwr>upr ){ c = +1; break; }
|
||||
}else{
|
||||
assert( nCellKey==intKey );
|
||||
pCur->ix = (u16)idx;
|
||||
if( !pPage->leaf ){
|
||||
lwr = idx;
|
||||
goto moveto_table_next_layer;
|
||||
}else{
|
||||
pCur->curFlags |= BTCF_ValidNKey;
|
||||
pCur->info.nKey = nCellKey;
|
||||
pCur->info.nSize = 0;
|
||||
*pRes = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
assert( lwr+upr>=0 );
|
||||
idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2; */
|
||||
}
|
||||
assert( lwr==upr+1 || !pPage->leaf );
|
||||
assert( pPage->isInit );
|
||||
if( pPage->leaf ){
|
||||
assert( pCur->ix<pCur->pPage->nCell );
|
||||
pCur->ix = (u16)idx;
|
||||
*pRes = c;
|
||||
rc = SQLITE_OK;
|
||||
goto moveto_table_finish;
|
||||
}
|
||||
moveto_table_next_layer:
|
||||
if( lwr>=pPage->nCell ){
|
||||
chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
|
||||
}else{
|
||||
chldPg = get4byte(findCell(pPage, lwr));
|
||||
}
|
||||
pCur->ix = (u16)lwr;
|
||||
rc = moveToChild(pCur, chldPg);
|
||||
if( rc ) break;
|
||||
}
|
||||
moveto_table_finish:
|
||||
pCur->info.nSize = 0;
|
||||
assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Move the cursor so that it points to an entry in an index table
|
||||
** near the key pIdxKey. Return a success code.
|
||||
**
|
||||
** If an exact match is not found, then the cursor is always
|
||||
** left pointing at a leaf page which would hold the entry if it
|
||||
** were present. The cursor might point to an entry that comes
|
||||
** before or after the key.
|
||||
**
|
||||
** An integer is written into *pRes which is the result of
|
||||
** comparing the key with the entry to which the cursor is
|
||||
** pointing. The meaning of the integer written into
|
||||
** *pRes is as follows:
|
||||
**
|
||||
** *pRes<0 The cursor is left pointing at an entry that
|
||||
** is smaller than pIdxKey or if the table is empty
|
||||
** and the cursor is therefore left point to nothing.
|
||||
**
|
||||
** *pRes==0 The cursor is left pointing at an entry that
|
||||
** exactly matches pIdxKey.
|
||||
**
|
||||
** *pRes>0 The cursor is left pointing at an entry that
|
||||
** is larger than pIdxKey.
|
||||
**
|
||||
** The pIdxKey->eqSeen field is set to 1 if there
|
||||
** exists an entry in the table that exactly matches pIdxKey.
|
||||
*/
|
||||
int sqlite3BtreeIndexMoveto(
|
||||
BtCursor *pCur, /* The cursor to be moved */
|
||||
UnpackedRecord *pIdxKey, /* Unpacked index key */
|
||||
int *pRes /* Write search results here */
|
||||
){
|
||||
int rc;
|
||||
RecordCompare xRecordCompare;
|
||||
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
|
||||
assert( pRes );
|
||||
assert( pCur->pKeyInfo!=0 );
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
pCur->pBtree->nSeek++; /* Performance measurement during testing */
|
||||
#endif
|
||||
|
||||
xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
|
||||
pIdxKey->errCode = 0;
|
||||
assert( pIdxKey->default_rc==1
|
||||
|| pIdxKey->default_rc==0
|
||||
|| pIdxKey->default_rc==-1
|
||||
);
|
||||
|
||||
rc = moveToRoot(pCur);
|
||||
if( rc ){
|
||||
@@ -5535,130 +5668,92 @@ int sqlite3BtreeMovetoUnpacked(
|
||||
assert( pPage->intKey==(pIdxKey==0) );
|
||||
lwr = 0;
|
||||
upr = pPage->nCell-1;
|
||||
assert( biasRight==0 || biasRight==1 );
|
||||
idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
|
||||
idx = upr>>1; /* idx = (lwr+upr)/2; */
|
||||
pCur->ix = (u16)idx;
|
||||
if( xRecordCompare==0 ){
|
||||
for(;;){
|
||||
i64 nCellKey;
|
||||
pCell = findCellPastPtr(pPage, idx);
|
||||
if( pPage->intKeyLeaf ){
|
||||
while( 0x80 <= *(pCell++) ){
|
||||
if( pCell>=pPage->aDataEnd ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
getVarint(pCell, (u64*)&nCellKey);
|
||||
if( nCellKey<intKey ){
|
||||
lwr = idx+1;
|
||||
if( lwr>upr ){ c = -1; break; }
|
||||
}else if( nCellKey>intKey ){
|
||||
upr = idx-1;
|
||||
if( lwr>upr ){ c = +1; break; }
|
||||
}else{
|
||||
assert( nCellKey==intKey );
|
||||
pCur->ix = (u16)idx;
|
||||
if( !pPage->leaf ){
|
||||
lwr = idx;
|
||||
goto moveto_next_layer;
|
||||
}else{
|
||||
pCur->curFlags |= BTCF_ValidNKey;
|
||||
pCur->info.nKey = nCellKey;
|
||||
pCur->info.nSize = 0;
|
||||
*pRes = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
assert( lwr+upr>=0 );
|
||||
idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2; */
|
||||
}
|
||||
}else{
|
||||
for(;;){
|
||||
int nCell; /* Size of the pCell cell in bytes */
|
||||
pCell = findCellPastPtr(pPage, idx);
|
||||
for(;;){
|
||||
int nCell; /* Size of the pCell cell in bytes */
|
||||
pCell = findCellPastPtr(pPage, idx);
|
||||
|
||||
/* The maximum supported page-size is 65536 bytes. This means that
|
||||
** the maximum number of record bytes stored on an index B-Tree
|
||||
** page is less than 16384 bytes and may be stored as a 2-byte
|
||||
** varint. This information is used to attempt to avoid parsing
|
||||
** the entire cell by checking for the cases where the record is
|
||||
** stored entirely within the b-tree page by inspecting the first
|
||||
** 2 bytes of the cell.
|
||||
*/
|
||||
nCell = pCell[0];
|
||||
if( nCell<=pPage->max1bytePayload ){
|
||||
/* This branch runs if the record-size field of the cell is a
|
||||
** single byte varint and the record fits entirely on the main
|
||||
** b-tree page. */
|
||||
testcase( pCell+nCell+1==pPage->aDataEnd );
|
||||
c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
|
||||
}else if( !(pCell[1] & 0x80)
|
||||
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
|
||||
){
|
||||
/* The record-size field is a 2 byte varint and the record
|
||||
** fits entirely on the main b-tree page. */
|
||||
testcase( pCell+nCell+2==pPage->aDataEnd );
|
||||
c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
|
||||
}else{
|
||||
/* The record flows over onto one or more overflow pages. In
|
||||
** this case the whole cell needs to be parsed, a buffer allocated
|
||||
** and accessPayload() used to retrieve the record into the
|
||||
** buffer before VdbeRecordCompare() can be called.
|
||||
**
|
||||
** If the record is corrupt, the xRecordCompare routine may read
|
||||
** up to two varints past the end of the buffer. An extra 18
|
||||
** bytes of padding is allocated at the end of the buffer in
|
||||
** case this happens. */
|
||||
void *pCellKey;
|
||||
u8 * const pCellBody = pCell - pPage->childPtrSize;
|
||||
const int nOverrun = 18; /* Size of the overrun padding */
|
||||
pPage->xParseCell(pPage, pCellBody, &pCur->info);
|
||||
nCell = (int)pCur->info.nKey;
|
||||
testcase( nCell<0 ); /* True if key size is 2^32 or more */
|
||||
testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
|
||||
testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
|
||||
testcase( nCell==2 ); /* Minimum legal index key size */
|
||||
if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
|
||||
rc = SQLITE_CORRUPT_PAGE(pPage);
|
||||
goto moveto_finish;
|
||||
}
|
||||
pCellKey = sqlite3Malloc( nCell+nOverrun );
|
||||
if( pCellKey==0 ){
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
goto moveto_finish;
|
||||
}
|
||||
pCur->ix = (u16)idx;
|
||||
rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
|
||||
memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */
|
||||
pCur->curFlags &= ~BTCF_ValidOvfl;
|
||||
if( rc ){
|
||||
sqlite3_free(pCellKey);
|
||||
goto moveto_finish;
|
||||
}
|
||||
c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
|
||||
/* The maximum supported page-size is 65536 bytes. This means that
|
||||
** the maximum number of record bytes stored on an index B-Tree
|
||||
** page is less than 16384 bytes and may be stored as a 2-byte
|
||||
** varint. This information is used to attempt to avoid parsing
|
||||
** the entire cell by checking for the cases where the record is
|
||||
** stored entirely within the b-tree page by inspecting the first
|
||||
** 2 bytes of the cell.
|
||||
*/
|
||||
nCell = pCell[0];
|
||||
if( nCell<=pPage->max1bytePayload ){
|
||||
/* This branch runs if the record-size field of the cell is a
|
||||
** single byte varint and the record fits entirely on the main
|
||||
** b-tree page. */
|
||||
testcase( pCell+nCell+1==pPage->aDataEnd );
|
||||
c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
|
||||
}else if( !(pCell[1] & 0x80)
|
||||
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
|
||||
){
|
||||
/* The record-size field is a 2 byte varint and the record
|
||||
** fits entirely on the main b-tree page. */
|
||||
testcase( pCell+nCell+2==pPage->aDataEnd );
|
||||
c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
|
||||
}else{
|
||||
/* The record flows over onto one or more overflow pages. In
|
||||
** this case the whole cell needs to be parsed, a buffer allocated
|
||||
** and accessPayload() used to retrieve the record into the
|
||||
** buffer before VdbeRecordCompare() can be called.
|
||||
**
|
||||
** If the record is corrupt, the xRecordCompare routine may read
|
||||
** up to two varints past the end of the buffer. An extra 18
|
||||
** bytes of padding is allocated at the end of the buffer in
|
||||
** case this happens. */
|
||||
void *pCellKey;
|
||||
u8 * const pCellBody = pCell - pPage->childPtrSize;
|
||||
const int nOverrun = 18; /* Size of the overrun padding */
|
||||
pPage->xParseCell(pPage, pCellBody, &pCur->info);
|
||||
nCell = (int)pCur->info.nKey;
|
||||
testcase( nCell<0 ); /* True if key size is 2^32 or more */
|
||||
testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
|
||||
testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
|
||||
testcase( nCell==2 ); /* Minimum legal index key size */
|
||||
if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
|
||||
rc = SQLITE_CORRUPT_PAGE(pPage);
|
||||
goto moveto_index_finish;
|
||||
}
|
||||
pCellKey = sqlite3Malloc( nCell+nOverrun );
|
||||
if( pCellKey==0 ){
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
goto moveto_index_finish;
|
||||
}
|
||||
pCur->ix = (u16)idx;
|
||||
rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
|
||||
memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */
|
||||
pCur->curFlags &= ~BTCF_ValidOvfl;
|
||||
if( rc ){
|
||||
sqlite3_free(pCellKey);
|
||||
goto moveto_index_finish;
|
||||
}
|
||||
assert(
|
||||
(pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
|
||||
&& (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
|
||||
);
|
||||
if( c<0 ){
|
||||
lwr = idx+1;
|
||||
}else if( c>0 ){
|
||||
upr = idx-1;
|
||||
}else{
|
||||
assert( c==0 );
|
||||
*pRes = 0;
|
||||
rc = SQLITE_OK;
|
||||
pCur->ix = (u16)idx;
|
||||
if( pIdxKey->errCode ) rc = SQLITE_CORRUPT_BKPT;
|
||||
goto moveto_finish;
|
||||
}
|
||||
if( lwr>upr ) break;
|
||||
assert( lwr+upr>=0 );
|
||||
idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */
|
||||
c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
|
||||
sqlite3_free(pCellKey);
|
||||
}
|
||||
assert(
|
||||
(pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
|
||||
&& (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
|
||||
);
|
||||
if( c<0 ){
|
||||
lwr = idx+1;
|
||||
}else if( c>0 ){
|
||||
upr = idx-1;
|
||||
}else{
|
||||
assert( c==0 );
|
||||
*pRes = 0;
|
||||
rc = SQLITE_OK;
|
||||
pCur->ix = (u16)idx;
|
||||
if( pIdxKey->errCode ) rc = SQLITE_CORRUPT_BKPT;
|
||||
goto moveto_index_finish;
|
||||
}
|
||||
if( lwr>upr ) break;
|
||||
assert( lwr+upr>=0 );
|
||||
idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */
|
||||
}
|
||||
assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
|
||||
assert( pPage->isInit );
|
||||
@@ -5667,9 +5762,8 @@ int sqlite3BtreeMovetoUnpacked(
|
||||
pCur->ix = (u16)idx;
|
||||
*pRes = c;
|
||||
rc = SQLITE_OK;
|
||||
goto moveto_finish;
|
||||
goto moveto_index_finish;
|
||||
}
|
||||
moveto_next_layer:
|
||||
if( lwr>=pPage->nCell ){
|
||||
chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
|
||||
}else{
|
||||
@@ -5679,7 +5773,7 @@ moveto_next_layer:
|
||||
rc = moveToChild(pCur, chldPg);
|
||||
if( rc ) break;
|
||||
}
|
||||
moveto_finish:
|
||||
moveto_index_finish:
|
||||
pCur->info.nSize = 0;
|
||||
assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
|
||||
return rc;
|
||||
@@ -6150,7 +6244,7 @@ static int allocateBtreePage(
|
||||
|
||||
iPage = get4byte(&aData[8+closest*4]);
|
||||
testcase( iPage==mxPage );
|
||||
if( iPage>mxPage ){
|
||||
if( iPage>mxPage || iPage<2 ){
|
||||
rc = SQLITE_CORRUPT_PGNO(iTrunk);
|
||||
goto end_allocate_page;
|
||||
}
|
||||
@@ -6406,10 +6500,9 @@ static void freePage(MemPage *pPage, int *pRC){
|
||||
}
|
||||
|
||||
/*
|
||||
** Free any overflow pages associated with the given Cell. Store
|
||||
** size information about the cell in pInfo.
|
||||
** Free the overflow pages associated with the given Cell.
|
||||
*/
|
||||
static int clearCell(
|
||||
static SQLITE_NOINLINE int clearCellOverflow(
|
||||
MemPage *pPage, /* The page that contains the Cell */
|
||||
unsigned char *pCell, /* First byte of the Cell */
|
||||
CellInfo *pInfo /* Size information about the cell */
|
||||
@@ -6421,10 +6514,7 @@ static int clearCell(
|
||||
u32 ovflPageSize;
|
||||
|
||||
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
|
||||
pPage->xParseCell(pPage, pCell, pInfo);
|
||||
if( pInfo->nLocal==pInfo->nPayload ){
|
||||
return SQLITE_OK; /* No overflow pages. Return without doing anything */
|
||||
}
|
||||
assert( pInfo->nLocal!=pInfo->nPayload );
|
||||
testcase( pCell + pInfo->nSize == pPage->aDataEnd );
|
||||
testcase( pCell + (pInfo->nSize-1) == pPage->aDataEnd );
|
||||
if( pCell + pInfo->nSize > pPage->aDataEnd ){
|
||||
@@ -6480,6 +6570,21 @@ static int clearCell(
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* Call xParseCell to compute the size of a cell. If the cell contains
|
||||
** overflow, then invoke cellClearOverflow to clear out that overflow.
|
||||
** STore the result code (SQLITE_OK or some error code) in rc.
|
||||
**
|
||||
** Implemented as macro to force inlining for performance.
|
||||
*/
|
||||
#define BTREE_CLEAR_CELL(rc, pPage, pCell, sInfo) \
|
||||
pPage->xParseCell(pPage, pCell, &sInfo); \
|
||||
if( sInfo.nLocal!=sInfo.nPayload ){ \
|
||||
rc = clearCellOverflow(pPage, pCell, &sInfo); \
|
||||
}else{ \
|
||||
rc = SQLITE_OK; \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Create the byte sequence used to represent a cell on page pPage
|
||||
** and write that byte sequence into pCell[]. Overflow pages are
|
||||
@@ -7002,7 +7107,7 @@ static int rebuildPage(
|
||||
u8 *pCell = pCArray->apCell[i];
|
||||
u16 sz = pCArray->szCell[i];
|
||||
assert( sz>0 );
|
||||
if( SQLITE_WITHIN(pCell,aData,pEnd) ){
|
||||
if( SQLITE_WITHIN(pCell,aData+j,pEnd) ){
|
||||
if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
|
||||
pCell = &pTmp[pCell - aData];
|
||||
}else if( (uptr)(pCell+sz)>(uptr)pSrcEnd
|
||||
@@ -7015,9 +7120,8 @@ static int rebuildPage(
|
||||
put2byte(pCellptr, (pData - aData));
|
||||
pCellptr += 2;
|
||||
if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
|
||||
memcpy(pData, pCell, sz);
|
||||
memmove(pData, pCell, sz);
|
||||
assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
|
||||
testcase( sz!=pPg->xCellSize(pPg,pCell) )
|
||||
i++;
|
||||
if( i>=iEnd ) break;
|
||||
if( pCArray->ixNx[k]<=i ){
|
||||
@@ -7156,7 +7260,9 @@ static int pageFreeArray(
|
||||
}
|
||||
pFree = pCell;
|
||||
szFree = sz;
|
||||
if( pFree+sz>pEnd ) return 0;
|
||||
if( pFree+sz>pEnd ){
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
pFree = pCell;
|
||||
szFree += sz;
|
||||
@@ -7637,7 +7743,9 @@ static int balance_nonroot(
|
||||
}
|
||||
pgno = get4byte(pRight);
|
||||
while( 1 ){
|
||||
rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
|
||||
}
|
||||
if( rc ){
|
||||
memset(apOld, 0, (i+1)*sizeof(MemPage*));
|
||||
goto balance_cleanup;
|
||||
@@ -7649,6 +7757,7 @@ static int balance_nonroot(
|
||||
goto balance_cleanup;
|
||||
}
|
||||
}
|
||||
nMaxCells += apOld[i]->nCell + ArraySize(pParent->apOvfl);
|
||||
if( (i--)==0 ) break;
|
||||
|
||||
if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
|
||||
@@ -7676,12 +7785,10 @@ static int balance_nonroot(
|
||||
if( pBt->btsFlags & BTS_FAST_SECURE ){
|
||||
int iOff;
|
||||
|
||||
/* If the following if() condition is not true, the db is corrupted.
|
||||
** The call to dropCell() below will detect this. */
|
||||
iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
|
||||
if( (iOff+szNew[i])>(int)pBt->usableSize ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
memset(apOld, 0, (i+1)*sizeof(MemPage*));
|
||||
goto balance_cleanup;
|
||||
}else{
|
||||
if( (iOff+szNew[i])<=(int)pBt->usableSize ){
|
||||
memcpy(&aOvflSpace[iOff], apDiv[i], szNew[i]);
|
||||
apDiv[i] = &aOvflSpace[apDiv[i]-pParent->aData];
|
||||
}
|
||||
@@ -7692,7 +7799,6 @@ static int balance_nonroot(
|
||||
|
||||
/* Make nMaxCells a multiple of 4 in order to preserve 8-byte
|
||||
** alignment */
|
||||
nMaxCells = nOld*(MX_CELL(pBt) + ArraySize(pParent->apOvfl));
|
||||
nMaxCells = (nMaxCells + 3)&~3;
|
||||
|
||||
/*
|
||||
@@ -7809,7 +7915,7 @@ static int balance_nonroot(
|
||||
b.szCell[b.nCell] = b.szCell[b.nCell] - leafCorrection;
|
||||
if( !pOld->leaf ){
|
||||
assert( leafCorrection==0 );
|
||||
assert( pOld->hdrOffset==0 );
|
||||
assert( pOld->hdrOffset==0 || CORRUPT_DB );
|
||||
/* The right pointer of the child page pOld becomes the left
|
||||
** pointer of the divider cell */
|
||||
memcpy(b.apCell[b.nCell], &pOld->aData[8], 4);
|
||||
@@ -7975,7 +8081,9 @@ static int balance_nonroot(
|
||||
apOld[i] = 0;
|
||||
rc = sqlite3PagerWrite(pNew->pDbPage);
|
||||
nNew++;
|
||||
if( sqlite3PagerPageRefcount(pNew->pDbPage)!=1+(i==(iParentIdx-nxDiv)) ){
|
||||
if( sqlite3PagerPageRefcount(pNew->pDbPage)!=1+(i==(iParentIdx-nxDiv))
|
||||
&& rc==SQLITE_OK
|
||||
){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
if( rc ) goto balance_cleanup;
|
||||
@@ -8132,6 +8240,7 @@ static int balance_nonroot(
|
||||
u8 *pCell;
|
||||
u8 *pTemp;
|
||||
int sz;
|
||||
u8 *pSrcEnd;
|
||||
MemPage *pNew = apNew[i];
|
||||
j = cntNew[i];
|
||||
|
||||
@@ -8175,6 +8284,12 @@ static int balance_nonroot(
|
||||
iOvflSpace += sz;
|
||||
assert( sz<=pBt->maxLocal+23 );
|
||||
assert( iOvflSpace <= (int)pBt->pageSize );
|
||||
for(k=0; b.ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
|
||||
pSrcEnd = b.apEnd[k];
|
||||
if( SQLITE_WITHIN(pSrcEnd, pCell, pCell+sz) ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto balance_cleanup;
|
||||
}
|
||||
insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
|
||||
if( rc!=SQLITE_OK ) goto balance_cleanup;
|
||||
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
|
||||
@@ -8717,13 +8832,23 @@ int sqlite3BtreeInsert(
|
||||
if( pCur->curFlags & BTCF_Multiple ){
|
||||
rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
|
||||
if( rc ) return rc;
|
||||
if( loc && pCur->iPage<0 ){
|
||||
/* This can only happen if the schema is corrupt such that there is more
|
||||
** than one table or index with the same root page as used by the cursor.
|
||||
** Which can only happen if the SQLITE_NoSchemaError flag was set when
|
||||
** the schema was loaded. This cannot be asserted though, as a user might
|
||||
** set the flag, load the schema, and then unset the flag. */
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
}
|
||||
|
||||
if( pCur->pKeyInfo==0 ){
|
||||
assert( pX->pKey==0 );
|
||||
/* If this is an insert into a table b-tree, invalidate any incrblob
|
||||
** cursors open on the row being replaced */
|
||||
invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
|
||||
if( p->hasIncrblobCur ){
|
||||
invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
|
||||
}
|
||||
|
||||
/* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
|
||||
** to a row with the same key as the new entry being inserted.
|
||||
@@ -8756,7 +8881,8 @@ int sqlite3BtreeInsert(
|
||||
** to an adjacent cell. Move the cursor so that it is pointing either
|
||||
** to the cell to be overwritten or an adjacent cell.
|
||||
*/
|
||||
rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
|
||||
rc = sqlite3BtreeTableMoveto(pCur, pX->nKey,
|
||||
(flags & BTREE_APPEND)!=0, &loc);
|
||||
if( rc ) return rc;
|
||||
}
|
||||
}else{
|
||||
@@ -8779,13 +8905,11 @@ int sqlite3BtreeInsert(
|
||||
r.aMem = pX->aMem;
|
||||
r.nField = pX->nMem;
|
||||
r.default_rc = 0;
|
||||
r.errCode = 0;
|
||||
r.r1 = 0;
|
||||
r.r2 = 0;
|
||||
r.eqSeen = 0;
|
||||
rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc);
|
||||
rc = sqlite3BtreeIndexMoveto(pCur, &r, &loc);
|
||||
}else{
|
||||
rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc);
|
||||
rc = btreeMoveto(pCur, pX->pKey, pX->nKey,
|
||||
(flags & BTREE_APPEND)!=0, &loc);
|
||||
}
|
||||
if( rc ) return rc;
|
||||
}
|
||||
@@ -8804,7 +8928,6 @@ int sqlite3BtreeInsert(
|
||||
return btreeOverwriteCell(pCur, &x2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
assert( pCur->eState==CURSOR_VALID
|
||||
|| (pCur->eState==CURSOR_INVALID && loc)
|
||||
@@ -8814,7 +8937,7 @@ int sqlite3BtreeInsert(
|
||||
assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
|
||||
assert( pPage->leaf || !pPage->intKey );
|
||||
if( pPage->nFree<0 ){
|
||||
if( pCur->eState>CURSOR_INVALID ){
|
||||
if( NEVER(pCur->eState>CURSOR_INVALID) ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}else{
|
||||
rc = btreeComputeFreeSpace(pPage);
|
||||
@@ -8858,7 +8981,7 @@ int sqlite3BtreeInsert(
|
||||
if( !pPage->leaf ){
|
||||
memcpy(newCell, oldCell, 4);
|
||||
}
|
||||
rc = clearCell(pPage, oldCell, &info);
|
||||
BTREE_CLEAR_CELL(rc, pPage, oldCell, info);
|
||||
testcase( pCur->curFlags & BTCF_ValidOvfl );
|
||||
invalidateOverflowCache(pCur);
|
||||
if( info.nSize==szNew && info.nLocal==info.nPayload
|
||||
@@ -9095,9 +9218,10 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
|
||||
if( pCur->eState==CURSOR_REQUIRESEEK ){
|
||||
rc = btreeRestoreCursorPosition(pCur);
|
||||
if( rc ) return rc;
|
||||
assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
|
||||
if( rc || pCur->eState!=CURSOR_VALID ) return rc;
|
||||
}
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
|
||||
|
||||
iCellDepth = pCur->iPage;
|
||||
iCellIdx = pCur->ix;
|
||||
@@ -9150,7 +9274,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
|
||||
/* If this is a delete operation to remove a row from a table b-tree,
|
||||
** invalidate any incrblob cursors open on the row being deleted. */
|
||||
if( pCur->pKeyInfo==0 ){
|
||||
if( pCur->pKeyInfo==0 && p->hasIncrblobCur ){
|
||||
invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
|
||||
}
|
||||
|
||||
@@ -9159,7 +9283,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
** itself from within the page. */
|
||||
rc = sqlite3PagerWrite(pPage->pDbPage);
|
||||
if( rc ) return rc;
|
||||
rc = clearCell(pPage, pCell, &info);
|
||||
BTREE_CLEAR_CELL(rc, pPage, pCell, info);
|
||||
dropCell(pPage, iCellIdx, info.nSize, &rc);
|
||||
if( rc ) return rc;
|
||||
|
||||
@@ -9419,7 +9543,7 @@ static int clearDatabasePage(
|
||||
BtShared *pBt, /* The BTree that contains the table */
|
||||
Pgno pgno, /* Page number to clear */
|
||||
int freePageFlag, /* Deallocate page if true */
|
||||
int *pnChange /* Add number of Cells freed to this counter */
|
||||
i64 *pnChange /* Add number of Cells freed to this counter */
|
||||
){
|
||||
MemPage *pPage;
|
||||
int rc;
|
||||
@@ -9446,14 +9570,15 @@ static int clearDatabasePage(
|
||||
rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
|
||||
if( rc ) goto cleardatabasepage_out;
|
||||
}
|
||||
rc = clearCell(pPage, pCell, &info);
|
||||
BTREE_CLEAR_CELL(rc, pPage, pCell, info);
|
||||
if( rc ) goto cleardatabasepage_out;
|
||||
}
|
||||
if( !pPage->leaf ){
|
||||
rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
|
||||
if( rc ) goto cleardatabasepage_out;
|
||||
}else if( pnChange ){
|
||||
assert( pPage->intKey || CORRUPT_DB );
|
||||
if( pPage->intKey ) pnChange = 0;
|
||||
}
|
||||
if( pnChange ){
|
||||
testcase( !pPage->intKey );
|
||||
*pnChange += pPage->nCell;
|
||||
}
|
||||
@@ -9478,11 +9603,10 @@ cleardatabasepage_out:
|
||||
** read cursors on the table. Open write cursors are moved to the
|
||||
** root of the table.
|
||||
**
|
||||
** If pnChange is not NULL, then table iTable must be an intkey table. The
|
||||
** integer value pointed to by pnChange is incremented by the number of
|
||||
** entries in the table.
|
||||
** If pnChange is not NULL, then the integer value pointed to by pnChange
|
||||
** is incremented by the number of entries in the table.
|
||||
*/
|
||||
int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
|
||||
int sqlite3BtreeClearTable(Btree *p, int iTable, i64 *pnChange){
|
||||
int rc;
|
||||
BtShared *pBt = p->pBt;
|
||||
sqlite3BtreeEnter(p);
|
||||
@@ -9494,7 +9618,9 @@ int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
|
||||
/* Invalidate all incrblob cursors open on table iTable (assuming iTable
|
||||
** is the root of a table b-tree - if it is not, the following call is
|
||||
** a no-op). */
|
||||
invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
|
||||
if( p->hasIncrblobCur ){
|
||||
invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
|
||||
}
|
||||
rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
|
||||
}
|
||||
sqlite3BtreeLeave(p);
|
||||
@@ -9654,7 +9780,7 @@ void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
|
||||
assert( idx>=0 && idx<=15 );
|
||||
|
||||
if( idx==BTREE_DATA_VERSION ){
|
||||
*pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
|
||||
*pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iBDataVersion;
|
||||
}else{
|
||||
*pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
|
||||
}
|
||||
|
||||
+8
-4
@@ -123,7 +123,7 @@ int sqlite3BtreeIncrVacuum(Btree *);
|
||||
#define BTREE_BLOBKEY 2 /* Table has keys only - no data */
|
||||
|
||||
int sqlite3BtreeDropTable(Btree*, int, int*);
|
||||
int sqlite3BtreeClearTable(Btree*, int, int*);
|
||||
int sqlite3BtreeClearTable(Btree*, int, i64*);
|
||||
int sqlite3BtreeClearTableOfCursor(BtCursor*);
|
||||
int sqlite3BtreeTripAllCursors(Btree*, int, int);
|
||||
|
||||
@@ -247,13 +247,17 @@ void sqlite3BtreeCursorHint(BtCursor*, int, ...);
|
||||
#endif
|
||||
|
||||
int sqlite3BtreeCloseCursor(BtCursor*);
|
||||
int sqlite3BtreeMovetoUnpacked(
|
||||
int sqlite3BtreeTableMoveto(
|
||||
BtCursor*,
|
||||
UnpackedRecord *pUnKey,
|
||||
i64 intKey,
|
||||
int bias,
|
||||
int *pRes
|
||||
);
|
||||
int sqlite3BtreeIndexMoveto(
|
||||
BtCursor*,
|
||||
UnpackedRecord *pUnKey,
|
||||
int *pRes
|
||||
);
|
||||
int sqlite3BtreeCursorHasMoved(BtCursor*);
|
||||
int sqlite3BtreeCursorRestore(BtCursor*, int*);
|
||||
int sqlite3BtreeDelete(BtCursor*, u8 flags);
|
||||
@@ -262,7 +266,7 @@ int sqlite3BtreeDelete(BtCursor*, u8 flags);
|
||||
#define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
|
||||
#define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
|
||||
#define BTREE_APPEND 0x08 /* Insert is likely an append */
|
||||
#define BTREE_PREFORMAT 0x80 /* Insert is likely an append */
|
||||
#define BTREE_PREFORMAT 0x80 /* Inserted data is a preformated cell */
|
||||
|
||||
/* An instance of the BtreePayload object describes the content of a single
|
||||
** entry in either an index or table btree.
|
||||
|
||||
+1
-1
@@ -350,7 +350,7 @@ struct Btree {
|
||||
u8 hasIncrblobCur; /* True if there are one or more Incrblob cursors */
|
||||
int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */
|
||||
int nBackup; /* Number of backup operations reading this btree */
|
||||
u32 iDataVersion; /* Combines with pBt->pPager->iDataVersion */
|
||||
u32 iBDataVersion; /* Combines with pBt->pPager->iDataVersion */
|
||||
Btree *pNext; /* List of other sharable Btrees from the same db */
|
||||
Btree *pPrev; /* Back pointer of the same list */
|
||||
#ifdef SQLITE_DEBUG
|
||||
|
||||
+174
-63
@@ -46,7 +46,7 @@ struct TableLock {
|
||||
** code to make the lock occur is generated by a later call to
|
||||
** codeTableLocks() which occurs during sqlite3FinishCoding().
|
||||
*/
|
||||
void sqlite3TableLock(
|
||||
static SQLITE_NOINLINE void lockTable(
|
||||
Parse *pParse, /* Parsing context */
|
||||
int iDb, /* Index of the database containing the table to lock */
|
||||
Pgno iTab, /* Root page number of the table to be locked */
|
||||
@@ -59,8 +59,6 @@ void sqlite3TableLock(
|
||||
TableLock *p;
|
||||
assert( iDb>=0 );
|
||||
|
||||
if( iDb==1 ) return;
|
||||
if( !sqlite3BtreeSharable(pParse->db->aDb[iDb].pBt) ) return;
|
||||
pToplevel = sqlite3ParseToplevel(pParse);
|
||||
for(i=0; i<pToplevel->nTableLock; i++){
|
||||
p = &pToplevel->aTableLock[i];
|
||||
@@ -84,6 +82,17 @@ void sqlite3TableLock(
|
||||
sqlite3OomFault(pToplevel->db);
|
||||
}
|
||||
}
|
||||
void sqlite3TableLock(
|
||||
Parse *pParse, /* Parsing context */
|
||||
int iDb, /* Index of the database containing the table to lock */
|
||||
Pgno iTab, /* Root page number of the table to be locked */
|
||||
u8 isWriteLock, /* True for a write lock */
|
||||
const char *zName /* Name of the table to be locked */
|
||||
){
|
||||
if( iDb==1 ) return;
|
||||
if( !sqlite3BtreeSharable(pParse->db->aDb[iDb].pBt) ) return;
|
||||
lockTable(pParse, iDb, iTab, isWriteLock, zName);
|
||||
}
|
||||
|
||||
/*
|
||||
** Code an OP_TableLock instruction for each table locked by the
|
||||
@@ -438,12 +447,13 @@ Table *sqlite3LocateTable(
|
||||
/* If zName is the not the name of a table in the schema created using
|
||||
** CREATE, then check to see if it is the name of an virtual table that
|
||||
** can be an eponymous virtual table. */
|
||||
if( pParse->disableVtab==0 ){
|
||||
if( pParse->disableVtab==0 && db->init.busy==0 ){
|
||||
Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName);
|
||||
if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
|
||||
pMod = sqlite3PragmaVtabRegister(db, zName);
|
||||
}
|
||||
if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
|
||||
testcase( pMod->pEpoTab==0 );
|
||||
return pMod->pEpoTab;
|
||||
}
|
||||
}
|
||||
@@ -461,6 +471,8 @@ Table *sqlite3LocateTable(
|
||||
}else{
|
||||
sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
|
||||
}
|
||||
}else{
|
||||
assert( HasRowid(p) || p->iPKey<0 );
|
||||
}
|
||||
|
||||
return p;
|
||||
@@ -478,7 +490,7 @@ Table *sqlite3LocateTable(
|
||||
Table *sqlite3LocateTableItem(
|
||||
Parse *pParse,
|
||||
u32 flags,
|
||||
struct SrcList_item *p
|
||||
SrcItem *p
|
||||
){
|
||||
const char *zDb;
|
||||
assert( p->pSchema==0 || p->zDatabase==0 );
|
||||
@@ -877,7 +889,7 @@ int sqlite3TwoPartName(
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
assert( db->init.iDb==0 || db->init.busy || IN_RENAME_OBJECT
|
||||
assert( db->init.iDb==0 || db->init.busy || IN_SPECIAL_PARSE
|
||||
|| (db->mDbFlags & DBFLAG_Vacuum)!=0);
|
||||
iDb = db->init.iDb;
|
||||
*pUnqual = pName1;
|
||||
@@ -1046,6 +1058,23 @@ i16 sqlite3TableColumnToStorage(Table *pTab, i16 iCol){
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Insert a single OP_JournalMode query opcode in order to force the
|
||||
** prepared statement to return false for sqlite3_stmt_readonly(). This
|
||||
** is used by CREATE TABLE IF NOT EXISTS and similar if the table already
|
||||
** exists, so that the prepared statement for CREATE TABLE IF NOT EXISTS
|
||||
** will return false for sqlite3_stmt_readonly() even if that statement
|
||||
** is a read-only no-op.
|
||||
*/
|
||||
static void sqlite3ForceNotReadOnly(Parse *pParse){
|
||||
int iReg = ++pParse->nMem;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
if( v ){
|
||||
sqlite3VdbeAddOp3(v, OP_JournalMode, 0, iReg, PAGER_JOURNALMODE_QUERY);
|
||||
sqlite3VdbeUsesBtree(v, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Begin constructing a new table representation in memory. This is
|
||||
** the first of several action routines that get called in response
|
||||
@@ -1145,6 +1174,7 @@ void sqlite3StartTable(
|
||||
}else{
|
||||
assert( !db->init.busy || CORRUPT_DB );
|
||||
sqlite3CodeVerifySchema(pParse, iDb);
|
||||
sqlite3ForceNotReadOnly(pParse);
|
||||
}
|
||||
goto begin_table_error;
|
||||
}
|
||||
@@ -1173,17 +1203,6 @@ void sqlite3StartTable(
|
||||
assert( pParse->pNewTable==0 );
|
||||
pParse->pNewTable = pTable;
|
||||
|
||||
/* If this is the magic sqlite_sequence table used by autoincrement,
|
||||
** then record a pointer to this table in the main database structure
|
||||
** so that INSERT can find the table easily.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){
|
||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||
pTable->pSchema->pSeqTab = pTable;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Begin generating the code that will insert the table record into
|
||||
** the schema table. Note in particular that we must go ahead
|
||||
** and allocate the record number for the table entry now. Before any
|
||||
@@ -1253,6 +1272,7 @@ void sqlite3StartTable(
|
||||
|
||||
/* If an error occurs, we jump here */
|
||||
begin_table_error:
|
||||
pParse->checkSchema = 1;
|
||||
sqlite3DbFree(db, zName);
|
||||
return;
|
||||
}
|
||||
@@ -1325,12 +1345,14 @@ void sqlite3AddReturning(Parse *pParse, ExprList *pList){
|
||||
pRet->pReturnEL = pList;
|
||||
sqlite3ParserAddCleanup(pParse,
|
||||
(void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet);
|
||||
testcase( pParse->earlyCleanup );
|
||||
if( db->mallocFailed ) return;
|
||||
pRet->retTrig.zName = RETURNING_TRIGGER_NAME;
|
||||
pRet->retTrig.op = TK_RETURNING;
|
||||
pRet->retTrig.tr_tm = TRIGGER_AFTER;
|
||||
pRet->retTrig.bReturning = 1;
|
||||
pRet->retTrig.pSchema = db->aDb[1].pSchema;
|
||||
pRet->retTrig.pTabSchema = db->aDb[1].pSchema;
|
||||
pRet->retTrig.step_list = &pRet->retTStep;
|
||||
pRet->retTStep.op = TK_RETURNING;
|
||||
pRet->retTStep.pTrig = &pRet->retTrig;
|
||||
@@ -2189,7 +2211,10 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
|
||||
pList = sqlite3ExprListAppend(pParse, 0,
|
||||
sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
|
||||
if( pList==0 ) return;
|
||||
if( pList==0 ){
|
||||
pTab->tabFlags &= ~TF_WithoutRowid;
|
||||
return;
|
||||
}
|
||||
if( IN_RENAME_OBJECT ){
|
||||
sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
|
||||
}
|
||||
@@ -2198,7 +2223,10 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
pTab->iPKey = -1;
|
||||
sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
|
||||
SQLITE_IDXTYPE_PRIMARYKEY);
|
||||
if( db->mallocFailed || pParse->nErr ) return;
|
||||
if( db->mallocFailed || pParse->nErr ){
|
||||
pTab->tabFlags &= ~TF_WithoutRowid;
|
||||
return;
|
||||
}
|
||||
pPk = sqlite3PrimaryKeyIndex(pTab);
|
||||
assert( pPk->nKeyCol==1 );
|
||||
}else{
|
||||
@@ -2402,7 +2430,6 @@ void sqlite3EndTable(
|
||||
if( pEnd==0 && pSelect==0 ){
|
||||
return;
|
||||
}
|
||||
assert( !db->mallocFailed );
|
||||
p = pParse->pNewTable;
|
||||
if( p==0 ) return;
|
||||
|
||||
@@ -2627,7 +2654,7 @@ void sqlite3EndTable(
|
||||
/* Check to see if we need to create an sqlite_sequence table for
|
||||
** keeping track of autoincrement keys.
|
||||
*/
|
||||
if( (p->tabFlags & TF_Autoincrement)!=0 ){
|
||||
if( (p->tabFlags & TF_Autoincrement)!=0 && !IN_SPECIAL_PARSE ){
|
||||
Db *pDb = &db->aDb[iDb];
|
||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||
if( pDb->pSchema->pSeqTab==0 ){
|
||||
@@ -2650,6 +2677,7 @@ void sqlite3EndTable(
|
||||
Table *pOld;
|
||||
Schema *pSchema = p->pSchema;
|
||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||
assert( HasRowid(p) || p->iPKey<0 );
|
||||
pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, p);
|
||||
if( pOld ){
|
||||
assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
|
||||
@@ -2659,19 +2687,27 @@ void sqlite3EndTable(
|
||||
pParse->pNewTable = 0;
|
||||
db->mDbFlags |= DBFLAG_SchemaChange;
|
||||
|
||||
#ifndef SQLITE_OMIT_ALTERTABLE
|
||||
if( !p->pSelect ){
|
||||
const char *zName = (const char *)pParse->sNameToken.z;
|
||||
int nName;
|
||||
assert( !pSelect && pCons && pEnd );
|
||||
if( pCons->z==0 ){
|
||||
pCons = pEnd;
|
||||
}
|
||||
nName = (int)((const char *)pCons->z - zName);
|
||||
p->addColOffset = 13 + nName;
|
||||
/* If this is the magic sqlite_sequence table used by autoincrement,
|
||||
** then record a pointer to this table in the main database structure
|
||||
** so that INSERT can find the table easily. */
|
||||
assert( !pParse->nested );
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
if( strcmp(p->zName, "sqlite_sequence")==0 ){
|
||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||
p->pSchema->pSeqTab = p;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_ALTERTABLE
|
||||
if( !pSelect && !p->pSelect ){
|
||||
assert( pCons && pEnd );
|
||||
if( pCons->z==0 ){
|
||||
pCons = pEnd;
|
||||
}
|
||||
p->addColOffset = 13 + (int)(pCons->z - pParse->sNameToken.z);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_VIEW
|
||||
@@ -2704,6 +2740,16 @@ void sqlite3CreateView(
|
||||
sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
|
||||
p = pParse->pNewTable;
|
||||
if( p==0 || pParse->nErr ) goto create_view_fail;
|
||||
|
||||
/* Legacy versions of SQLite allowed the use of the magic "rowid" column
|
||||
** on a view, even though views do not have rowids. The following flag
|
||||
** setting fixes this problem. But the fix can be disabled by compiling
|
||||
** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that
|
||||
** depend upon the old buggy behavior. */
|
||||
#ifndef SQLITE_ALLOW_ROWID_IN_VIEW
|
||||
p->tabFlags |= TF_NoVisibleRowid;
|
||||
#endif
|
||||
|
||||
sqlite3TwoPartName(pParse, pName1, pName2, &pName);
|
||||
iDb = sqlite3SchemaToIndex(db, p->pSchema);
|
||||
sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
|
||||
@@ -2862,6 +2908,7 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
||||
assert( pTable->aCol==0 );
|
||||
pTable->nCol = pSelTab->nCol;
|
||||
pTable->aCol = pSelTab->aCol;
|
||||
pTable->tabFlags |= (pSelTab->tabFlags & COLFLAG_NOINSERT);
|
||||
pSelTab->nCol = 0;
|
||||
pSelTab->aCol = 0;
|
||||
assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
|
||||
@@ -3135,6 +3182,7 @@ int sqlite3ReadOnlyShadowTables(sqlite3 *db){
|
||||
if( (db->flags & SQLITE_Defensive)!=0
|
||||
&& db->pVtabCtx==0
|
||||
&& db->nVdbeExec==0
|
||||
&& !sqlite3VtabInSync(db)
|
||||
){
|
||||
return 1;
|
||||
}
|
||||
@@ -3179,7 +3227,10 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, int noErr){
|
||||
if( noErr ) db->suppressErr--;
|
||||
|
||||
if( pTab==0 ){
|
||||
if( noErr ) sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
|
||||
if( noErr ){
|
||||
sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
|
||||
sqlite3ForceNotReadOnly(pParse);
|
||||
}
|
||||
goto exit_drop_table;
|
||||
}
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
@@ -3749,6 +3800,7 @@ void sqlite3CreateIndex(
|
||||
}else{
|
||||
assert( !db->init.busy );
|
||||
sqlite3CodeVerifySchema(pParse, iDb);
|
||||
sqlite3ForceNotReadOnly(pParse);
|
||||
}
|
||||
goto exit_create_index;
|
||||
}
|
||||
@@ -4150,7 +4202,11 @@ void sqlite3CreateIndex(
|
||||
/* Clean up before exiting */
|
||||
exit_create_index:
|
||||
if( pIndex ) sqlite3FreeIndex(db, pIndex);
|
||||
if( pTab ){ /* Ensure all REPLACE indexes are at the end of the list */
|
||||
if( pTab ){
|
||||
/* Ensure all REPLACE indexes on pTab are at the end of the pIndex list.
|
||||
** The list was already ordered when this routine was entered, so at this
|
||||
** point at most a single index (the newly added index) will be out of
|
||||
** order. So we have to reorder at most one index. */
|
||||
Index **ppFrom = &pTab->pIndex;
|
||||
Index *pThis;
|
||||
for(ppFrom=&pTab->pIndex; (pThis = *ppFrom)!=0; ppFrom=&pThis->pNext){
|
||||
@@ -4164,6 +4220,16 @@ exit_create_index:
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifdef SQLITE_DEBUG
|
||||
/* Verify that all REPLACE indexes really are now at the end
|
||||
** of the index list. In other words, no other index type ever
|
||||
** comes after a REPLACE index on the list. */
|
||||
for(pThis = pTab->pIndex; pThis; pThis=pThis->pNext){
|
||||
assert( pThis->onError!=OE_Replace
|
||||
|| pThis->pNext==0
|
||||
|| pThis->pNext->onError==OE_Replace );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
sqlite3ExprDelete(db, pPIWhere);
|
||||
sqlite3ExprListDelete(db, pList);
|
||||
@@ -4215,7 +4281,7 @@ void sqlite3DefaultRowEst(Index *pIdx){
|
||||
if( x<99 ){
|
||||
pIdx->pTable->nRowLogEst = x = 99;
|
||||
}
|
||||
if( pIdx->pPartIdxWhere!=0 ) x -= 10; assert( 10==sqlite3LogEst(2) );
|
||||
if( pIdx->pPartIdxWhere!=0 ){ x -= 10; assert( 10==sqlite3LogEst(2) ); }
|
||||
a[0] = x;
|
||||
|
||||
/* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is
|
||||
@@ -4250,9 +4316,10 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName, int ifExists){
|
||||
pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
|
||||
if( pIndex==0 ){
|
||||
if( !ifExists ){
|
||||
sqlite3ErrorMsg(pParse, "no such index: %S", pName, 0);
|
||||
sqlite3ErrorMsg(pParse, "no such index: %S", pName->a);
|
||||
}else{
|
||||
sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
|
||||
sqlite3ForceNotReadOnly(pParse);
|
||||
}
|
||||
pParse->checkSchema = 1;
|
||||
goto exit_drop_index;
|
||||
@@ -4272,7 +4339,7 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName, int ifExists){
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
|
||||
goto exit_drop_index;
|
||||
}
|
||||
if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX;
|
||||
if( !OMIT_TEMPDB && iDb==1 ) code = SQLITE_DROP_TEMP_INDEX;
|
||||
if( sqlite3AuthCheck(pParse, code, pIndex->zName, pTab->zName, zDb) ){
|
||||
goto exit_drop_index;
|
||||
}
|
||||
@@ -4522,7 +4589,7 @@ SrcList *sqlite3SrcListAppend(
|
||||
Token *pTable, /* Table to append */
|
||||
Token *pDatabase /* Database of the table */
|
||||
){
|
||||
struct SrcList_item *pItem;
|
||||
SrcItem *pItem;
|
||||
sqlite3 *db;
|
||||
assert( pDatabase==0 || pTable!=0 ); /* Cannot have C without B */
|
||||
assert( pParse!=0 );
|
||||
@@ -4563,9 +4630,9 @@ SrcList *sqlite3SrcListAppend(
|
||||
*/
|
||||
void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){
|
||||
int i;
|
||||
struct SrcList_item *pItem;
|
||||
assert(pList || pParse->db->mallocFailed );
|
||||
if( pList ){
|
||||
SrcItem *pItem;
|
||||
assert( pList || pParse->db->mallocFailed );
|
||||
if( ALWAYS(pList) ){
|
||||
for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
|
||||
if( pItem->iCursor>=0 ) continue;
|
||||
pItem->iCursor = pParse->nTab++;
|
||||
@@ -4581,7 +4648,7 @@ void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){
|
||||
*/
|
||||
void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
|
||||
int i;
|
||||
struct SrcList_item *pItem;
|
||||
SrcItem *pItem;
|
||||
if( pList==0 ) return;
|
||||
for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
|
||||
if( pItem->zDatabase ) sqlite3DbFreeNN(db, pItem->zDatabase);
|
||||
@@ -4623,7 +4690,7 @@ SrcList *sqlite3SrcListAppendFromTerm(
|
||||
Expr *pOn, /* The ON clause of a join */
|
||||
IdList *pUsing /* The USING clause of a join */
|
||||
){
|
||||
struct SrcList_item *pItem;
|
||||
SrcItem *pItem;
|
||||
sqlite3 *db = pParse->db;
|
||||
if( !p && (pOn || pUsing) ){
|
||||
sqlite3ErrorMsg(pParse, "a JOIN clause is required before %s",
|
||||
@@ -4667,7 +4734,7 @@ SrcList *sqlite3SrcListAppendFromTerm(
|
||||
void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
|
||||
assert( pIndexedBy!=0 );
|
||||
if( p && pIndexedBy->n>0 ){
|
||||
struct SrcList_item *pItem;
|
||||
SrcItem *pItem;
|
||||
assert( p->nSrc>0 );
|
||||
pItem = &p->a[p->nSrc-1];
|
||||
assert( pItem->fg.notIndexed==0 );
|
||||
@@ -4697,7 +4764,7 @@ SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2){
|
||||
sqlite3SrcListDelete(pParse->db, p2);
|
||||
}else{
|
||||
p1 = pNew;
|
||||
memcpy(&p1->a[1], p2->a, p2->nSrc*sizeof(struct SrcList_item));
|
||||
memcpy(&p1->a[1], p2->a, p2->nSrc*sizeof(SrcItem));
|
||||
sqlite3DbFree(pParse->db, p2);
|
||||
}
|
||||
}
|
||||
@@ -4710,7 +4777,7 @@ SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2){
|
||||
*/
|
||||
void sqlite3SrcListFuncArgs(Parse *pParse, SrcList *p, ExprList *pList){
|
||||
if( p ){
|
||||
struct SrcList_item *pItem = &p->a[p->nSrc-1];
|
||||
SrcItem *pItem = &p->a[p->nSrc-1];
|
||||
assert( pItem->fg.notIndexed==0 );
|
||||
assert( pItem->fg.isIndexedBy==0 );
|
||||
assert( pItem->fg.isTabFunc==0 );
|
||||
@@ -4865,7 +4932,7 @@ int sqlite3OpenTempDatabase(Parse *pParse){
|
||||
static void sqlite3CodeVerifySchemaAtToplevel(Parse *pToplevel, int iDb){
|
||||
assert( iDb>=0 && iDb<pToplevel->db->nDb );
|
||||
assert( pToplevel->db->aDb[iDb].pBt!=0 || iDb==1 );
|
||||
assert( iDb<SQLITE_MAX_ATTACHED+2 );
|
||||
assert( iDb<SQLITE_MAX_DB );
|
||||
assert( sqlite3SchemaMutexHeld(pToplevel->db, iDb, 0) );
|
||||
if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){
|
||||
DbMaskSet(pToplevel->cookieMask, iDb);
|
||||
@@ -5207,24 +5274,76 @@ KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_CTE
|
||||
/*
|
||||
** Create a new CTE object
|
||||
*/
|
||||
Cte *sqlite3CteNew(
|
||||
Parse *pParse, /* Parsing context */
|
||||
Token *pName, /* Name of the common-table */
|
||||
ExprList *pArglist, /* Optional column name list for the table */
|
||||
Select *pQuery, /* Query used to initialize the table */
|
||||
u8 eM10d /* The MATERIALIZED flag */
|
||||
){
|
||||
Cte *pNew;
|
||||
sqlite3 *db = pParse->db;
|
||||
|
||||
pNew = sqlite3DbMallocZero(db, sizeof(*pNew));
|
||||
assert( pNew!=0 || db->mallocFailed );
|
||||
|
||||
if( db->mallocFailed ){
|
||||
sqlite3ExprListDelete(db, pArglist);
|
||||
sqlite3SelectDelete(db, pQuery);
|
||||
}else{
|
||||
pNew->pSelect = pQuery;
|
||||
pNew->pCols = pArglist;
|
||||
pNew->zName = sqlite3NameFromToken(pParse->db, pName);
|
||||
pNew->eM10d = eM10d;
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
|
||||
/*
|
||||
** Clear information from a Cte object, but do not deallocate storage
|
||||
** for the object itself.
|
||||
*/
|
||||
static void cteClear(sqlite3 *db, Cte *pCte){
|
||||
assert( pCte!=0 );
|
||||
sqlite3ExprListDelete(db, pCte->pCols);
|
||||
sqlite3SelectDelete(db, pCte->pSelect);
|
||||
sqlite3DbFree(db, pCte->zName);
|
||||
}
|
||||
|
||||
/*
|
||||
** Free the contents of the CTE object passed as the second argument.
|
||||
*/
|
||||
void sqlite3CteDelete(sqlite3 *db, Cte *pCte){
|
||||
assert( pCte!=0 );
|
||||
cteClear(db, pCte);
|
||||
sqlite3DbFree(db, pCte);
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is invoked once per CTE by the parser while parsing a
|
||||
** WITH clause.
|
||||
** WITH clause. The CTE described by teh third argument is added to
|
||||
** the WITH clause of the second argument. If the second argument is
|
||||
** NULL, then a new WITH argument is created.
|
||||
*/
|
||||
With *sqlite3WithAdd(
|
||||
Parse *pParse, /* Parsing context */
|
||||
With *pWith, /* Existing WITH clause, or NULL */
|
||||
Token *pName, /* Name of the common-table */
|
||||
ExprList *pArglist, /* Optional column name list for the table */
|
||||
Select *pQuery /* Query used to initialize the table */
|
||||
Cte *pCte /* CTE to add to the WITH clause */
|
||||
){
|
||||
sqlite3 *db = pParse->db;
|
||||
With *pNew;
|
||||
char *zName;
|
||||
|
||||
if( pCte==0 ){
|
||||
return pWith;
|
||||
}
|
||||
|
||||
/* Check that the CTE name is unique within this WITH clause. If
|
||||
** not, store an error in the Parse structure. */
|
||||
zName = sqlite3NameFromToken(pParse->db, pName);
|
||||
zName = pCte->zName;
|
||||
if( zName && pWith ){
|
||||
int i;
|
||||
for(i=0; i<pWith->nCte; i++){
|
||||
@@ -5243,16 +5362,11 @@ With *sqlite3WithAdd(
|
||||
assert( (pNew!=0 && zName!=0) || db->mallocFailed );
|
||||
|
||||
if( db->mallocFailed ){
|
||||
sqlite3ExprListDelete(db, pArglist);
|
||||
sqlite3SelectDelete(db, pQuery);
|
||||
sqlite3DbFree(db, zName);
|
||||
sqlite3CteDelete(db, pCte);
|
||||
pNew = pWith;
|
||||
}else{
|
||||
pNew->a[pNew->nCte].pSelect = pQuery;
|
||||
pNew->a[pNew->nCte].pCols = pArglist;
|
||||
pNew->a[pNew->nCte].zName = zName;
|
||||
pNew->a[pNew->nCte].zCteErr = 0;
|
||||
pNew->nCte++;
|
||||
pNew->a[pNew->nCte++] = *pCte;
|
||||
sqlite3DbFree(db, pCte);
|
||||
}
|
||||
|
||||
return pNew;
|
||||
@@ -5265,10 +5379,7 @@ void sqlite3WithDelete(sqlite3 *db, With *pWith){
|
||||
if( pWith ){
|
||||
int i;
|
||||
for(i=0; i<pWith->nCte; i++){
|
||||
struct Cte *pCte = &pWith->a[i];
|
||||
sqlite3ExprListDelete(db, pCte->pCols);
|
||||
sqlite3SelectDelete(db, pCte->pSelect);
|
||||
sqlite3DbFree(db, pCte->zName);
|
||||
cteClear(db, &pWith->a[i]);
|
||||
}
|
||||
sqlite3DbFree(db, pWith);
|
||||
}
|
||||
|
||||
+213
-194
@@ -13,7 +13,6 @@
|
||||
** This file implements routines used to report what compile-time options
|
||||
** SQLite was built with.
|
||||
*/
|
||||
|
||||
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS /* IMP: R-16824-07538 */
|
||||
|
||||
/*
|
||||
@@ -35,6 +34,7 @@
|
||||
** comma. e.g. (-DSQLITE_DEFAULT_LOOKASIDE="100,100") */
|
||||
#define CTIMEOPT_VAL2_(opt1,opt2) #opt1 "," #opt2
|
||||
#define CTIMEOPT_VAL2(opt) CTIMEOPT_VAL2_(opt)
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** An array of names of all compile-time options. This array should
|
||||
@@ -49,31 +49,36 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
/*
|
||||
** BEGIN CODE GENERATED BY tool/mkctime.tcl
|
||||
*/
|
||||
#if SQLITE_32BIT_ROWID
|
||||
#ifdef SQLITE_32BIT_ROWID
|
||||
"32BIT_ROWID",
|
||||
#endif
|
||||
#if SQLITE_4_BYTE_ALIGNED_MALLOC
|
||||
#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
|
||||
"4_BYTE_ALIGNED_MALLOC",
|
||||
#endif
|
||||
#if SQLITE_64BIT_STATS
|
||||
#ifdef SQLITE_64BIT_STATS
|
||||
"64BIT_STATS",
|
||||
#endif
|
||||
#if SQLITE_ALLOW_COVERING_INDEX_SCAN
|
||||
"ALLOW_COVERING_INDEX_SCAN",
|
||||
#ifdef SQLITE_ALLOW_COVERING_INDEX_SCAN
|
||||
# if SQLITE_ALLOW_COVERING_INDEX_SCAN != 1
|
||||
"ALLOW_COVERING_INDEX_SCAN=" CTIMEOPT_VAL(SQLITE_ALLOW_COVERING_INDEX_SCAN),
|
||||
# endif
|
||||
#endif
|
||||
#if SQLITE_ALLOW_URI_AUTHORITY
|
||||
#ifdef SQLITE_ALLOW_URI_AUTHORITY
|
||||
"ALLOW_URI_AUTHORITY",
|
||||
#endif
|
||||
#ifdef SQLITE_ATOMIC_INTRINSICS
|
||||
"ATOMIC_INTRINSICS=" CTIMEOPT_VAL(SQLITE_ATOMIC_INTRINSICS),
|
||||
#endif
|
||||
#ifdef SQLITE_BITMASK_TYPE
|
||||
"BITMASK_TYPE=" CTIMEOPT_VAL(SQLITE_BITMASK_TYPE),
|
||||
#endif
|
||||
#if SQLITE_BUG_COMPATIBLE_20160819
|
||||
#ifdef SQLITE_BUG_COMPATIBLE_20160819
|
||||
"BUG_COMPATIBLE_20160819",
|
||||
#endif
|
||||
#if SQLITE_CASE_SENSITIVE_LIKE
|
||||
#ifdef SQLITE_CASE_SENSITIVE_LIKE
|
||||
"CASE_SENSITIVE_LIKE",
|
||||
#endif
|
||||
#if SQLITE_CHECK_PAGES
|
||||
#ifdef SQLITE_CHECK_PAGES
|
||||
"CHECK_PAGES",
|
||||
#endif
|
||||
#if defined(__clang__) && defined(__clang_major__)
|
||||
@@ -85,22 +90,22 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#elif defined(__GNUC__) && defined(__VERSION__)
|
||||
"COMPILER=gcc-" __VERSION__,
|
||||
#endif
|
||||
#if SQLITE_COVERAGE_TEST
|
||||
#ifdef SQLITE_COVERAGE_TEST
|
||||
"COVERAGE_TEST",
|
||||
#endif
|
||||
#if SQLITE_DEBUG
|
||||
#ifdef SQLITE_DEBUG
|
||||
"DEBUG",
|
||||
#endif
|
||||
#if SQLITE_DEFAULT_AUTOMATIC_INDEX
|
||||
#ifdef SQLITE_DEFAULT_AUTOMATIC_INDEX
|
||||
"DEFAULT_AUTOMATIC_INDEX",
|
||||
#endif
|
||||
#if SQLITE_DEFAULT_AUTOVACUUM
|
||||
#ifdef SQLITE_DEFAULT_AUTOVACUUM
|
||||
"DEFAULT_AUTOVACUUM",
|
||||
#endif
|
||||
#ifdef SQLITE_DEFAULT_CACHE_SIZE
|
||||
"DEFAULT_CACHE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_CACHE_SIZE),
|
||||
#endif
|
||||
#if SQLITE_DEFAULT_CKPTFULLFSYNC
|
||||
#ifdef SQLITE_DEFAULT_CKPTFULLFSYNC
|
||||
"DEFAULT_CKPTFULLFSYNC",
|
||||
#endif
|
||||
#ifdef SQLITE_DEFAULT_FILE_FORMAT
|
||||
@@ -109,7 +114,7 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_DEFAULT_FILE_PERMISSIONS
|
||||
"DEFAULT_FILE_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_PERMISSIONS),
|
||||
#endif
|
||||
#if SQLITE_DEFAULT_FOREIGN_KEYS
|
||||
#ifdef SQLITE_DEFAULT_FOREIGN_KEYS
|
||||
"DEFAULT_FOREIGN_KEYS",
|
||||
#endif
|
||||
#ifdef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
|
||||
@@ -121,8 +126,10 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_DEFAULT_LOOKASIDE
|
||||
"DEFAULT_LOOKASIDE=" CTIMEOPT_VAL2(SQLITE_DEFAULT_LOOKASIDE),
|
||||
#endif
|
||||
#if SQLITE_DEFAULT_MEMSTATUS
|
||||
"DEFAULT_MEMSTATUS",
|
||||
#ifdef SQLITE_DEFAULT_MEMSTATUS
|
||||
# if SQLITE_DEFAULT_MEMSTATUS != 1
|
||||
"DEFAULT_MEMSTATUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_MEMSTATUS),
|
||||
# endif
|
||||
#endif
|
||||
#ifdef SQLITE_DEFAULT_MMAP_SIZE
|
||||
"DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
|
||||
@@ -136,7 +143,7 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS
|
||||
"DEFAULT_PROXYDIR_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_PROXYDIR_PERMISSIONS),
|
||||
#endif
|
||||
#if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
|
||||
#ifdef SQLITE_DEFAULT_RECURSIVE_TRIGGERS
|
||||
"DEFAULT_RECURSIVE_TRIGGERS",
|
||||
#endif
|
||||
#ifdef SQLITE_DEFAULT_ROWEST
|
||||
@@ -157,193 +164,196 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_DEFAULT_WORKER_THREADS
|
||||
"DEFAULT_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WORKER_THREADS),
|
||||
#endif
|
||||
#if SQLITE_DIRECT_OVERFLOW_READ
|
||||
#ifdef SQLITE_DIRECT_OVERFLOW_READ
|
||||
"DIRECT_OVERFLOW_READ",
|
||||
#endif
|
||||
#if SQLITE_DISABLE_DIRSYNC
|
||||
#ifdef SQLITE_DISABLE_DIRSYNC
|
||||
"DISABLE_DIRSYNC",
|
||||
#endif
|
||||
#if SQLITE_DISABLE_FTS3_UNICODE
|
||||
#ifdef SQLITE_DISABLE_FTS3_UNICODE
|
||||
"DISABLE_FTS3_UNICODE",
|
||||
#endif
|
||||
#if SQLITE_DISABLE_FTS4_DEFERRED
|
||||
#ifdef SQLITE_DISABLE_FTS4_DEFERRED
|
||||
"DISABLE_FTS4_DEFERRED",
|
||||
#endif
|
||||
#if SQLITE_DISABLE_INTRINSIC
|
||||
#ifdef SQLITE_DISABLE_INTRINSIC
|
||||
"DISABLE_INTRINSIC",
|
||||
#endif
|
||||
#if SQLITE_DISABLE_LFS
|
||||
#ifdef SQLITE_DISABLE_LFS
|
||||
"DISABLE_LFS",
|
||||
#endif
|
||||
#if SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
|
||||
#ifdef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
|
||||
"DISABLE_PAGECACHE_OVERFLOW_STATS",
|
||||
#endif
|
||||
#if SQLITE_DISABLE_SKIPAHEAD_DISTINCT
|
||||
#ifdef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
|
||||
"DISABLE_SKIPAHEAD_DISTINCT",
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_8_3_NAMES
|
||||
"ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES),
|
||||
#endif
|
||||
#if SQLITE_ENABLE_API_ARMOR
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
"ENABLE_API_ARMOR",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_ATOMIC_WRITE
|
||||
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
|
||||
"ENABLE_ATOMIC_WRITE",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_BATCH_ATOMIC_WRITE
|
||||
#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
|
||||
"ENABLE_BATCH_ATOMIC_WRITE",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_BYTECODE_VTAB
|
||||
#ifdef SQLITE_ENABLE_BYTECODE_VTAB
|
||||
"ENABLE_BYTECODE_VTAB",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_CEROD
|
||||
#ifdef SQLITE_ENABLE_CEROD
|
||||
"ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD),
|
||||
#endif
|
||||
#if SQLITE_ENABLE_COLUMN_METADATA
|
||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||
"ENABLE_COLUMN_METADATA",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_COLUMN_USED_MASK
|
||||
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
|
||||
"ENABLE_COLUMN_USED_MASK",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_COSTMULT
|
||||
#ifdef SQLITE_ENABLE_COSTMULT
|
||||
"ENABLE_COSTMULT",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_CURSOR_HINTS
|
||||
#ifdef SQLITE_ENABLE_CURSOR_HINTS
|
||||
"ENABLE_CURSOR_HINTS",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_DBSTAT_VTAB
|
||||
#ifdef SQLITE_ENABLE_DBPAGE_VTAB
|
||||
"ENABLE_DBPAGE_VTAB",
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_DBSTAT_VTAB
|
||||
"ENABLE_DBSTAT_VTAB",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_EXPENSIVE_ASSERT
|
||||
#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
|
||||
"ENABLE_EXPENSIVE_ASSERT",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_FTS1
|
||||
"ENABLE_FTS1",
|
||||
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
"ENABLE_EXPLAIN_COMMENTS",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_FTS2
|
||||
"ENABLE_FTS2",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_FTS3
|
||||
#ifdef SQLITE_ENABLE_FTS3
|
||||
"ENABLE_FTS3",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_FTS3_PARENTHESIS
|
||||
#ifdef SQLITE_ENABLE_FTS3_PARENTHESIS
|
||||
"ENABLE_FTS3_PARENTHESIS",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_FTS3_TOKENIZER
|
||||
#ifdef SQLITE_ENABLE_FTS3_TOKENIZER
|
||||
"ENABLE_FTS3_TOKENIZER",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_FTS4
|
||||
#ifdef SQLITE_ENABLE_FTS4
|
||||
"ENABLE_FTS4",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
#ifdef SQLITE_ENABLE_FTS5
|
||||
"ENABLE_FTS5",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_GEOPOLY
|
||||
#ifdef SQLITE_ENABLE_GEOPOLY
|
||||
"ENABLE_GEOPOLY",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_HIDDEN_COLUMNS
|
||||
#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS
|
||||
"ENABLE_HIDDEN_COLUMNS",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_ICU
|
||||
#ifdef SQLITE_ENABLE_ICU
|
||||
"ENABLE_ICU",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_IOTRACE
|
||||
#ifdef SQLITE_ENABLE_IOTRACE
|
||||
"ENABLE_IOTRACE",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_JSON1
|
||||
#ifdef SQLITE_ENABLE_JSON1
|
||||
"ENABLE_JSON1",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_LOAD_EXTENSION
|
||||
#ifdef SQLITE_ENABLE_LOAD_EXTENSION
|
||||
"ENABLE_LOAD_EXTENSION",
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_LOCKING_STYLE
|
||||
"ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
|
||||
#endif
|
||||
#if SQLITE_ENABLE_MATH_FUNCTIONS
|
||||
#ifdef SQLITE_ENABLE_MATH_FUNCTIONS
|
||||
"ENABLE_MATH_FUNCTIONS",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
"ENABLE_MEMORY_MANAGEMENT",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_MEMSYS3
|
||||
#ifdef SQLITE_ENABLE_MEMSYS3
|
||||
"ENABLE_MEMSYS3",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_MEMSYS5
|
||||
#ifdef SQLITE_ENABLE_MEMSYS5
|
||||
"ENABLE_MEMSYS5",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_MULTIPLEX
|
||||
#ifdef SQLITE_ENABLE_MULTIPLEX
|
||||
"ENABLE_MULTIPLEX",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_NORMALIZE
|
||||
#ifdef SQLITE_ENABLE_NORMALIZE
|
||||
"ENABLE_NORMALIZE",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_NULL_TRIM
|
||||
#ifdef SQLITE_ENABLE_NULL_TRIM
|
||||
"ENABLE_NULL_TRIM",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_OVERSIZE_CELL_CHECK
|
||||
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
"ENABLE_OFFSET_SQL_FUNC",
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_OVERSIZE_CELL_CHECK
|
||||
"ENABLE_OVERSIZE_CELL_CHECK",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
"ENABLE_PREUPDATE_HOOK",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_QPSG
|
||||
#ifdef SQLITE_ENABLE_QPSG
|
||||
"ENABLE_QPSG",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_RBU
|
||||
#ifdef SQLITE_ENABLE_RBU
|
||||
"ENABLE_RBU",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_RTREE
|
||||
#ifdef SQLITE_ENABLE_RTREE
|
||||
"ENABLE_RTREE",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_SELECTTRACE
|
||||
#ifdef SQLITE_ENABLE_SELECTTRACE
|
||||
"ENABLE_SELECTTRACE",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_SESSION
|
||||
#ifdef SQLITE_ENABLE_SESSION
|
||||
"ENABLE_SESSION",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_SNAPSHOT
|
||||
#ifdef SQLITE_ENABLE_SNAPSHOT
|
||||
"ENABLE_SNAPSHOT",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_SORTER_REFERENCES
|
||||
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
|
||||
"ENABLE_SORTER_REFERENCES",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_SQLLOG
|
||||
#ifdef SQLITE_ENABLE_SQLLOG
|
||||
"ENABLE_SQLLOG",
|
||||
#endif
|
||||
#if defined(SQLITE_ENABLE_STAT4)
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
"ENABLE_STAT4",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_STMTVTAB
|
||||
#ifdef SQLITE_ENABLE_STMTVTAB
|
||||
"ENABLE_STMTVTAB",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_STMT_SCANSTATUS
|
||||
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
||||
"ENABLE_STMT_SCANSTATUS",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
|
||||
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
|
||||
"ENABLE_UNKNOWN_SQL_FUNCTION",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_UNLOCK_NOTIFY
|
||||
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
|
||||
"ENABLE_UNLOCK_NOTIFY",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
|
||||
#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
|
||||
"ENABLE_UPDATE_DELETE_LIMIT",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_URI_00_ERROR
|
||||
#ifdef SQLITE_ENABLE_URI_00_ERROR
|
||||
"ENABLE_URI_00_ERROR",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_VFSTRACE
|
||||
#ifdef SQLITE_ENABLE_VFSTRACE
|
||||
"ENABLE_VFSTRACE",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_WHERETRACE
|
||||
#ifdef SQLITE_ENABLE_WHERETRACE
|
||||
"ENABLE_WHERETRACE",
|
||||
#endif
|
||||
#if SQLITE_ENABLE_ZIPVFS
|
||||
#ifdef SQLITE_ENABLE_ZIPVFS
|
||||
"ENABLE_ZIPVFS",
|
||||
#endif
|
||||
#if SQLITE_EXPLAIN_ESTIMATED_ROWS
|
||||
#ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS
|
||||
"EXPLAIN_ESTIMATED_ROWS",
|
||||
#endif
|
||||
#if SQLITE_EXTRA_IFNULLROW
|
||||
#ifdef SQLITE_EXTRA_IFNULLROW
|
||||
"EXTRA_IFNULLROW",
|
||||
#endif
|
||||
#ifdef SQLITE_EXTRA_INIT
|
||||
@@ -355,40 +365,42 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_FTS3_MAX_EXPR_DEPTH
|
||||
"FTS3_MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_FTS3_MAX_EXPR_DEPTH),
|
||||
#endif
|
||||
#if SQLITE_FTS5_ENABLE_TEST_MI
|
||||
#ifdef SQLITE_FTS5_ENABLE_TEST_MI
|
||||
"FTS5_ENABLE_TEST_MI",
|
||||
#endif
|
||||
#if SQLITE_FTS5_NO_WITHOUT_ROWID
|
||||
#ifdef SQLITE_FTS5_NO_WITHOUT_ROWID
|
||||
"FTS5_NO_WITHOUT_ROWID",
|
||||
#endif
|
||||
#if HAVE_ISNAN || SQLITE_HAVE_ISNAN
|
||||
"HAVE_ISNAN",
|
||||
#endif
|
||||
#if SQLITE_HOMEGROWN_RECURSIVE_MUTEX
|
||||
"HOMEGROWN_RECURSIVE_MUTEX",
|
||||
#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
|
||||
# if SQLITE_HOMEGROWN_RECURSIVE_MUTEX != 1
|
||||
"HOMEGROWN_RECURSIVE_MUTEX=" CTIMEOPT_VAL(SQLITE_HOMEGROWN_RECURSIVE_MUTEX),
|
||||
# endif
|
||||
#endif
|
||||
#if SQLITE_IGNORE_AFP_LOCK_ERRORS
|
||||
#ifdef SQLITE_IGNORE_AFP_LOCK_ERRORS
|
||||
"IGNORE_AFP_LOCK_ERRORS",
|
||||
#endif
|
||||
#if SQLITE_IGNORE_FLOCK_LOCK_ERRORS
|
||||
#ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
|
||||
"IGNORE_FLOCK_LOCK_ERRORS",
|
||||
#endif
|
||||
#if SQLITE_INLINE_MEMCPY
|
||||
#ifdef SQLITE_INLINE_MEMCPY
|
||||
"INLINE_MEMCPY",
|
||||
#endif
|
||||
#if SQLITE_INT64_TYPE
|
||||
#ifdef SQLITE_INT64_TYPE
|
||||
"INT64_TYPE",
|
||||
#endif
|
||||
#ifdef SQLITE_INTEGRITY_CHECK_ERROR_MAX
|
||||
"INTEGRITY_CHECK_ERROR_MAX=" CTIMEOPT_VAL(SQLITE_INTEGRITY_CHECK_ERROR_MAX),
|
||||
#endif
|
||||
#if SQLITE_LIKE_DOESNT_MATCH_BLOBS
|
||||
#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
|
||||
"LIKE_DOESNT_MATCH_BLOBS",
|
||||
#endif
|
||||
#if SQLITE_LOCK_TRACE
|
||||
#ifdef SQLITE_LOCK_TRACE
|
||||
"LOCK_TRACE",
|
||||
#endif
|
||||
#if SQLITE_LOG_CACHE_SPILL
|
||||
#ifdef SQLITE_LOG_CACHE_SPILL
|
||||
"LOG_CACHE_SPILL",
|
||||
#endif
|
||||
#ifdef SQLITE_MALLOC_SOFT_LIMIT
|
||||
@@ -451,250 +463,254 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_MAX_WORKER_THREADS
|
||||
"MAX_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_MAX_WORKER_THREADS),
|
||||
#endif
|
||||
#if SQLITE_MEMDEBUG
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
"MEMDEBUG",
|
||||
#endif
|
||||
#if SQLITE_MIXED_ENDIAN_64BIT_FLOAT
|
||||
#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
|
||||
"MIXED_ENDIAN_64BIT_FLOAT",
|
||||
#endif
|
||||
#if SQLITE_MMAP_READWRITE
|
||||
#ifdef SQLITE_MMAP_READWRITE
|
||||
"MMAP_READWRITE",
|
||||
#endif
|
||||
#if SQLITE_MUTEX_NOOP
|
||||
#ifdef SQLITE_MUTEX_NOOP
|
||||
"MUTEX_NOOP",
|
||||
#endif
|
||||
#if SQLITE_MUTEX_NREF
|
||||
"MUTEX_NREF",
|
||||
#endif
|
||||
#if SQLITE_MUTEX_OMIT
|
||||
#ifdef SQLITE_MUTEX_OMIT
|
||||
"MUTEX_OMIT",
|
||||
#endif
|
||||
#if SQLITE_MUTEX_PTHREADS
|
||||
#ifdef SQLITE_MUTEX_PTHREADS
|
||||
"MUTEX_PTHREADS",
|
||||
#endif
|
||||
#if SQLITE_MUTEX_W32
|
||||
#ifdef SQLITE_MUTEX_W32
|
||||
"MUTEX_W32",
|
||||
#endif
|
||||
#if SQLITE_NEED_ERR_NAME
|
||||
#ifdef SQLITE_NEED_ERR_NAME
|
||||
"NEED_ERR_NAME",
|
||||
#endif
|
||||
#if SQLITE_NOINLINE
|
||||
"NOINLINE",
|
||||
#endif
|
||||
#if SQLITE_NO_SYNC
|
||||
#ifdef SQLITE_NO_SYNC
|
||||
"NO_SYNC",
|
||||
#endif
|
||||
#if SQLITE_OMIT_ALTERTABLE
|
||||
#ifdef SQLITE_OMIT_ALTERTABLE
|
||||
"OMIT_ALTERTABLE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_ANALYZE
|
||||
#ifdef SQLITE_OMIT_ANALYZE
|
||||
"OMIT_ANALYZE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_ATTACH
|
||||
#ifdef SQLITE_OMIT_ATTACH
|
||||
"OMIT_ATTACH",
|
||||
#endif
|
||||
#if SQLITE_OMIT_AUTHORIZATION
|
||||
#ifdef SQLITE_OMIT_AUTHORIZATION
|
||||
"OMIT_AUTHORIZATION",
|
||||
#endif
|
||||
#if SQLITE_OMIT_AUTOINCREMENT
|
||||
#ifdef SQLITE_OMIT_AUTOINCREMENT
|
||||
"OMIT_AUTOINCREMENT",
|
||||
#endif
|
||||
#if SQLITE_OMIT_AUTOINIT
|
||||
#ifdef SQLITE_OMIT_AUTOINIT
|
||||
"OMIT_AUTOINIT",
|
||||
#endif
|
||||
#if SQLITE_OMIT_AUTOMATIC_INDEX
|
||||
#ifdef SQLITE_OMIT_AUTOMATIC_INDEX
|
||||
"OMIT_AUTOMATIC_INDEX",
|
||||
#endif
|
||||
#if SQLITE_OMIT_AUTORESET
|
||||
#ifdef SQLITE_OMIT_AUTORESET
|
||||
"OMIT_AUTORESET",
|
||||
#endif
|
||||
#if SQLITE_OMIT_AUTOVACUUM
|
||||
#ifdef SQLITE_OMIT_AUTOVACUUM
|
||||
"OMIT_AUTOVACUUM",
|
||||
#endif
|
||||
#if SQLITE_OMIT_BETWEEN_OPTIMIZATION
|
||||
#ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
|
||||
"OMIT_BETWEEN_OPTIMIZATION",
|
||||
#endif
|
||||
#if SQLITE_OMIT_BLOB_LITERAL
|
||||
#ifdef SQLITE_OMIT_BLOB_LITERAL
|
||||
"OMIT_BLOB_LITERAL",
|
||||
#endif
|
||||
#if SQLITE_OMIT_CAST
|
||||
#ifdef SQLITE_OMIT_CAST
|
||||
"OMIT_CAST",
|
||||
#endif
|
||||
#if SQLITE_OMIT_CHECK
|
||||
#ifdef SQLITE_OMIT_CHECK
|
||||
"OMIT_CHECK",
|
||||
#endif
|
||||
#if SQLITE_OMIT_COMPLETE
|
||||
#ifdef SQLITE_OMIT_COMPLETE
|
||||
"OMIT_COMPLETE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_COMPOUND_SELECT
|
||||
#ifdef SQLITE_OMIT_COMPOUND_SELECT
|
||||
"OMIT_COMPOUND_SELECT",
|
||||
#endif
|
||||
#if SQLITE_OMIT_CONFLICT_CLAUSE
|
||||
#ifdef SQLITE_OMIT_CONFLICT_CLAUSE
|
||||
"OMIT_CONFLICT_CLAUSE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_CTE
|
||||
#ifdef SQLITE_OMIT_CTE
|
||||
"OMIT_CTE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_DATETIME_FUNCS
|
||||
#if defined(SQLITE_OMIT_DATETIME_FUNCS) || defined(SQLITE_OMIT_FLOATING_POINT)
|
||||
"OMIT_DATETIME_FUNCS",
|
||||
#endif
|
||||
#if SQLITE_OMIT_DECLTYPE
|
||||
#ifdef SQLITE_OMIT_DECLTYPE
|
||||
"OMIT_DECLTYPE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_DEPRECATED
|
||||
#ifdef SQLITE_OMIT_DEPRECATED
|
||||
"OMIT_DEPRECATED",
|
||||
#endif
|
||||
#if SQLITE_OMIT_DISKIO
|
||||
#ifdef SQLITE_OMIT_DESERIALIZE
|
||||
"OMIT_DESERIALIZE",
|
||||
#endif
|
||||
#ifdef SQLITE_OMIT_DISKIO
|
||||
"OMIT_DISKIO",
|
||||
#endif
|
||||
#if SQLITE_OMIT_EXPLAIN
|
||||
#ifdef SQLITE_OMIT_EXPLAIN
|
||||
"OMIT_EXPLAIN",
|
||||
#endif
|
||||
#if SQLITE_OMIT_FLAG_PRAGMAS
|
||||
#ifdef SQLITE_OMIT_FLAG_PRAGMAS
|
||||
"OMIT_FLAG_PRAGMAS",
|
||||
#endif
|
||||
#if SQLITE_OMIT_FLOATING_POINT
|
||||
#ifdef SQLITE_OMIT_FLOATING_POINT
|
||||
"OMIT_FLOATING_POINT",
|
||||
#endif
|
||||
#if SQLITE_OMIT_FOREIGN_KEY
|
||||
#ifdef SQLITE_OMIT_FOREIGN_KEY
|
||||
"OMIT_FOREIGN_KEY",
|
||||
#endif
|
||||
#if SQLITE_OMIT_GET_TABLE
|
||||
#ifdef SQLITE_OMIT_GET_TABLE
|
||||
"OMIT_GET_TABLE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_HEX_INTEGER
|
||||
#ifdef SQLITE_OMIT_HEX_INTEGER
|
||||
"OMIT_HEX_INTEGER",
|
||||
#endif
|
||||
#if SQLITE_OMIT_INCRBLOB
|
||||
#ifdef SQLITE_OMIT_INCRBLOB
|
||||
"OMIT_INCRBLOB",
|
||||
#endif
|
||||
#if SQLITE_OMIT_INTEGRITY_CHECK
|
||||
#ifdef SQLITE_OMIT_INTEGRITY_CHECK
|
||||
"OMIT_INTEGRITY_CHECK",
|
||||
#endif
|
||||
#if SQLITE_OMIT_LIKE_OPTIMIZATION
|
||||
#ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS
|
||||
"OMIT_INTROSPECTION_PRAGMAS",
|
||||
#endif
|
||||
#ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
|
||||
"OMIT_LIKE_OPTIMIZATION",
|
||||
#endif
|
||||
#if SQLITE_OMIT_LOAD_EXTENSION
|
||||
#ifdef SQLITE_OMIT_LOAD_EXTENSION
|
||||
"OMIT_LOAD_EXTENSION",
|
||||
#endif
|
||||
#if SQLITE_OMIT_LOCALTIME
|
||||
#ifdef SQLITE_OMIT_LOCALTIME
|
||||
"OMIT_LOCALTIME",
|
||||
#endif
|
||||
#if SQLITE_OMIT_LOOKASIDE
|
||||
#ifdef SQLITE_OMIT_LOOKASIDE
|
||||
"OMIT_LOOKASIDE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_MEMORYDB
|
||||
#ifdef SQLITE_OMIT_MEMORYDB
|
||||
"OMIT_MEMORYDB",
|
||||
#endif
|
||||
#if SQLITE_OMIT_OR_OPTIMIZATION
|
||||
#ifdef SQLITE_OMIT_OR_OPTIMIZATION
|
||||
"OMIT_OR_OPTIMIZATION",
|
||||
#endif
|
||||
#if SQLITE_OMIT_PAGER_PRAGMAS
|
||||
#ifdef SQLITE_OMIT_PAGER_PRAGMAS
|
||||
"OMIT_PAGER_PRAGMAS",
|
||||
#endif
|
||||
#if SQLITE_OMIT_PARSER_TRACE
|
||||
#ifdef SQLITE_OMIT_PARSER_TRACE
|
||||
"OMIT_PARSER_TRACE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_POPEN
|
||||
#ifdef SQLITE_OMIT_POPEN
|
||||
"OMIT_POPEN",
|
||||
#endif
|
||||
#if SQLITE_OMIT_PRAGMA
|
||||
#ifdef SQLITE_OMIT_PRAGMA
|
||||
"OMIT_PRAGMA",
|
||||
#endif
|
||||
#if SQLITE_OMIT_PROGRESS_CALLBACK
|
||||
#ifdef SQLITE_OMIT_PROGRESS_CALLBACK
|
||||
"OMIT_PROGRESS_CALLBACK",
|
||||
#endif
|
||||
#if SQLITE_OMIT_QUICKBALANCE
|
||||
#ifdef SQLITE_OMIT_QUICKBALANCE
|
||||
"OMIT_QUICKBALANCE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_REINDEX
|
||||
#ifdef SQLITE_OMIT_REINDEX
|
||||
"OMIT_REINDEX",
|
||||
#endif
|
||||
#if SQLITE_OMIT_SCHEMA_PRAGMAS
|
||||
#ifdef SQLITE_OMIT_SCHEMA_PRAGMAS
|
||||
"OMIT_SCHEMA_PRAGMAS",
|
||||
#endif
|
||||
#if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
|
||||
#ifdef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
|
||||
"OMIT_SCHEMA_VERSION_PRAGMAS",
|
||||
#endif
|
||||
#if SQLITE_OMIT_SHARED_CACHE
|
||||
#ifdef SQLITE_OMIT_SHARED_CACHE
|
||||
"OMIT_SHARED_CACHE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_SHUTDOWN_DIRECTORIES
|
||||
#ifdef SQLITE_OMIT_SHUTDOWN_DIRECTORIES
|
||||
"OMIT_SHUTDOWN_DIRECTORIES",
|
||||
#endif
|
||||
#if SQLITE_OMIT_SUBQUERY
|
||||
#ifdef SQLITE_OMIT_SUBQUERY
|
||||
"OMIT_SUBQUERY",
|
||||
#endif
|
||||
#if SQLITE_OMIT_TCL_VARIABLE
|
||||
#ifdef SQLITE_OMIT_TCL_VARIABLE
|
||||
"OMIT_TCL_VARIABLE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_TEMPDB
|
||||
#ifdef SQLITE_OMIT_TEMPDB
|
||||
"OMIT_TEMPDB",
|
||||
#endif
|
||||
#if SQLITE_OMIT_TEST_CONTROL
|
||||
#ifdef SQLITE_OMIT_TEST_CONTROL
|
||||
"OMIT_TEST_CONTROL",
|
||||
#endif
|
||||
#if SQLITE_OMIT_TRACE
|
||||
"OMIT_TRACE",
|
||||
#ifdef SQLITE_OMIT_TRACE
|
||||
# if SQLITE_OMIT_TRACE != 1
|
||||
"OMIT_TRACE=" CTIMEOPT_VAL(SQLITE_OMIT_TRACE),
|
||||
# endif
|
||||
#endif
|
||||
#if SQLITE_OMIT_TRIGGER
|
||||
#ifdef SQLITE_OMIT_TRIGGER
|
||||
"OMIT_TRIGGER",
|
||||
#endif
|
||||
#if SQLITE_OMIT_TRUNCATE_OPTIMIZATION
|
||||
#ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
|
||||
"OMIT_TRUNCATE_OPTIMIZATION",
|
||||
#endif
|
||||
#if SQLITE_OMIT_UTF16
|
||||
#ifdef SQLITE_OMIT_UTF16
|
||||
"OMIT_UTF16",
|
||||
#endif
|
||||
#if SQLITE_OMIT_VACUUM
|
||||
#ifdef SQLITE_OMIT_VACUUM
|
||||
"OMIT_VACUUM",
|
||||
#endif
|
||||
#if SQLITE_OMIT_VIEW
|
||||
#ifdef SQLITE_OMIT_VIEW
|
||||
"OMIT_VIEW",
|
||||
#endif
|
||||
#if SQLITE_OMIT_VIRTUALTABLE
|
||||
#ifdef SQLITE_OMIT_VIRTUALTABLE
|
||||
"OMIT_VIRTUALTABLE",
|
||||
#endif
|
||||
#if SQLITE_OMIT_WAL
|
||||
#ifdef SQLITE_OMIT_WAL
|
||||
"OMIT_WAL",
|
||||
#endif
|
||||
#if SQLITE_OMIT_WSD
|
||||
#ifdef SQLITE_OMIT_WSD
|
||||
"OMIT_WSD",
|
||||
#endif
|
||||
#if SQLITE_OMIT_XFER_OPT
|
||||
#ifdef SQLITE_OMIT_XFER_OPT
|
||||
"OMIT_XFER_OPT",
|
||||
#endif
|
||||
#if SQLITE_PCACHE_SEPARATE_HEADER
|
||||
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
|
||||
"PCACHE_SEPARATE_HEADER",
|
||||
#endif
|
||||
#if SQLITE_PERFORMANCE_TRACE
|
||||
#ifdef SQLITE_PERFORMANCE_TRACE
|
||||
"PERFORMANCE_TRACE",
|
||||
#endif
|
||||
#if SQLITE_POWERSAFE_OVERWRITE
|
||||
"POWERSAFE_OVERWRITE",
|
||||
#ifdef SQLITE_POWERSAFE_OVERWRITE
|
||||
# if SQLITE_POWERSAFE_OVERWRITE != 1
|
||||
"POWERSAFE_OVERWRITE=" CTIMEOPT_VAL(SQLITE_POWERSAFE_OVERWRITE),
|
||||
# endif
|
||||
#endif
|
||||
#if SQLITE_PREFER_PROXY_LOCKING
|
||||
#ifdef SQLITE_PREFER_PROXY_LOCKING
|
||||
"PREFER_PROXY_LOCKING",
|
||||
#endif
|
||||
#if SQLITE_PROXY_DEBUG
|
||||
#ifdef SQLITE_PROXY_DEBUG
|
||||
"PROXY_DEBUG",
|
||||
#endif
|
||||
#if SQLITE_REVERSE_UNORDERED_SELECTS
|
||||
#ifdef SQLITE_REVERSE_UNORDERED_SELECTS
|
||||
"REVERSE_UNORDERED_SELECTS",
|
||||
#endif
|
||||
#if SQLITE_RTREE_INT_ONLY
|
||||
#ifdef SQLITE_RTREE_INT_ONLY
|
||||
"RTREE_INT_ONLY",
|
||||
#endif
|
||||
#if SQLITE_SECURE_DELETE
|
||||
#ifdef SQLITE_SECURE_DELETE
|
||||
"SECURE_DELETE",
|
||||
#endif
|
||||
#if SQLITE_SMALL_STACK
|
||||
#ifdef SQLITE_SMALL_STACK
|
||||
"SMALL_STACK",
|
||||
#endif
|
||||
#ifdef SQLITE_SORTER_PMASZ
|
||||
"SORTER_PMASZ=" CTIMEOPT_VAL(SQLITE_SORTER_PMASZ),
|
||||
#endif
|
||||
#if SQLITE_SOUNDEX
|
||||
#ifdef SQLITE_SOUNDEX
|
||||
"SOUNDEX",
|
||||
#endif
|
||||
#ifdef SQLITE_STAT4_SAMPLES
|
||||
@@ -703,19 +719,22 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_STMTJRNL_SPILL
|
||||
"STMTJRNL_SPILL=" CTIMEOPT_VAL(SQLITE_STMTJRNL_SPILL),
|
||||
#endif
|
||||
#if SQLITE_SUBSTR_COMPATIBILITY
|
||||
#ifdef SQLITE_SUBSTR_COMPATIBILITY
|
||||
"SUBSTR_COMPATIBILITY",
|
||||
#endif
|
||||
#if SQLITE_SYSTEM_MALLOC
|
||||
#if (!defined(SQLITE_WIN32_MALLOC) \
|
||||
&& !defined(SQLITE_ZERO_MALLOC) \
|
||||
&& !defined(SQLITE_MEMDEBUG) \
|
||||
) || defined(SQLITE_SYSTEM_MALLOC)
|
||||
"SYSTEM_MALLOC",
|
||||
#endif
|
||||
#if SQLITE_TCL
|
||||
#ifdef SQLITE_TCL
|
||||
"TCL",
|
||||
#endif
|
||||
#ifdef SQLITE_TEMP_STORE
|
||||
"TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
|
||||
#endif
|
||||
#if SQLITE_TEST
|
||||
#ifdef SQLITE_TEST
|
||||
"TEST",
|
||||
#endif
|
||||
#if defined(SQLITE_THREADSAFE)
|
||||
@@ -725,31 +744,31 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#else
|
||||
"THREADSAFE=1",
|
||||
#endif
|
||||
#if SQLITE_UNLINK_AFTER_CLOSE
|
||||
#ifdef SQLITE_UNLINK_AFTER_CLOSE
|
||||
"UNLINK_AFTER_CLOSE",
|
||||
#endif
|
||||
#if SQLITE_UNTESTABLE
|
||||
#ifdef SQLITE_UNTESTABLE
|
||||
"UNTESTABLE",
|
||||
#endif
|
||||
#if SQLITE_USER_AUTHENTICATION
|
||||
#ifdef SQLITE_USER_AUTHENTICATION
|
||||
"USER_AUTHENTICATION",
|
||||
#endif
|
||||
#if SQLITE_USE_ALLOCA
|
||||
#ifdef SQLITE_USE_ALLOCA
|
||||
"USE_ALLOCA",
|
||||
#endif
|
||||
#if SQLITE_USE_FCNTL_TRACE
|
||||
#ifdef SQLITE_USE_FCNTL_TRACE
|
||||
"USE_FCNTL_TRACE",
|
||||
#endif
|
||||
#if SQLITE_USE_URI
|
||||
#ifdef SQLITE_USE_URI
|
||||
"USE_URI",
|
||||
#endif
|
||||
#if SQLITE_VDBE_COVERAGE
|
||||
#ifdef SQLITE_VDBE_COVERAGE
|
||||
"VDBE_COVERAGE",
|
||||
#endif
|
||||
#if SQLITE_WIN32_MALLOC
|
||||
#ifdef SQLITE_WIN32_MALLOC
|
||||
"WIN32_MALLOC",
|
||||
#endif
|
||||
#if SQLITE_ZERO_MALLOC
|
||||
#ifdef SQLITE_ZERO_MALLOC
|
||||
"ZERO_MALLOC",
|
||||
#endif
|
||||
/*
|
||||
|
||||
@@ -881,6 +881,7 @@ static int isDate(
|
||||
int eType;
|
||||
memset(p, 0, sizeof(*p));
|
||||
if( argc==0 ){
|
||||
if( !sqlite3NotPureFunc(context) ) return 1;
|
||||
return setDateTimeToCurrent(context, p);
|
||||
}
|
||||
if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
|
||||
|
||||
+24
-13
@@ -29,7 +29,7 @@
|
||||
**
|
||||
*/
|
||||
Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
struct SrcList_item *pItem = pSrc->a;
|
||||
SrcItem *pItem = pSrc->a;
|
||||
Table *pTab;
|
||||
assert( pItem && pSrc->nSrc>=1 );
|
||||
pTab = sqlite3LocateTableItem(pParse, 0, pItem);
|
||||
@@ -37,9 +37,9 @@ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
pItem->pTab = pTab;
|
||||
if( pTab ){
|
||||
pTab->nTabRef++;
|
||||
}
|
||||
if( sqlite3IndexedByLookup(pParse, pItem) ){
|
||||
pTab = 0;
|
||||
if( pItem->fg.isIndexedBy && sqlite3IndexedByLookup(pParse, pItem) ){
|
||||
pTab = 0;
|
||||
}
|
||||
}
|
||||
return pTab;
|
||||
}
|
||||
@@ -207,9 +207,15 @@ Expr *sqlite3LimitWhere(
|
||||
/* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
|
||||
** and the SELECT subtree. */
|
||||
pSrc->a[0].pTab = 0;
|
||||
pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
|
||||
pSelectSrc = sqlite3SrcListDup(db, pSrc, 0);
|
||||
pSrc->a[0].pTab = pTab;
|
||||
pSrc->a[0].pIBIndex = 0;
|
||||
if( pSrc->a[0].fg.isIndexedBy ){
|
||||
pSrc->a[0].u2.pIBIndex = 0;
|
||||
pSrc->a[0].fg.isIndexedBy = 0;
|
||||
sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy);
|
||||
}else if( pSrc->a[0].fg.isCte ){
|
||||
pSrc->a[0].u2.pCteUse->nUse++;
|
||||
}
|
||||
|
||||
/* generate the SELECT expression tree. */
|
||||
pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
|
||||
@@ -422,6 +428,9 @@ void sqlite3DeleteFrom(
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
assert( pIdx->pSchema==pTab->pSchema );
|
||||
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
|
||||
if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
|
||||
sqlite3VdbeChangeP3(v, -1, memCnt ? memCnt : -1);
|
||||
}
|
||||
}
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
|
||||
@@ -933,13 +942,15 @@ int sqlite3GenerateIndexKey(
|
||||
continue;
|
||||
}
|
||||
sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);
|
||||
/* If the column affinity is REAL but the number is an integer, then it
|
||||
** might be stored in the table as an integer (using a compact
|
||||
** representation) then converted to REAL by an OP_RealAffinity opcode.
|
||||
** But we are getting ready to store this value back into an index, where
|
||||
** it should be converted by to INTEGER again. So omit the OP_RealAffinity
|
||||
** opcode if it is present */
|
||||
sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity);
|
||||
if( pIdx->aiColumn[j]>=0 ){
|
||||
/* If the column affinity is REAL but the number is an integer, then it
|
||||
** might be stored in the table as an integer (using a compact
|
||||
** representation) then converted to REAL by an OP_RealAffinity opcode.
|
||||
** But we are getting ready to store this value back into an index, where
|
||||
** it should be converted by to INTEGER again. So omit the
|
||||
** OP_RealAffinity opcode if it is present */
|
||||
sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity);
|
||||
}
|
||||
}
|
||||
if( regOut ){
|
||||
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
|
||||
|
||||
+252
-126
@@ -52,6 +52,10 @@ char sqlite3ExprAffinity(const Expr *pExpr){
|
||||
assert( pExpr!=0 );
|
||||
}
|
||||
op = pExpr->op;
|
||||
if( op==TK_REGISTER ) op = pExpr->op2;
|
||||
if( (op==TK_COLUMN || op==TK_AGG_COLUMN) && pExpr->y.pTab ){
|
||||
return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
|
||||
}
|
||||
if( op==TK_SELECT ){
|
||||
assert( pExpr->flags&EP_xIsSelect );
|
||||
assert( pExpr->x.pSelect!=0 );
|
||||
@@ -59,18 +63,16 @@ char sqlite3ExprAffinity(const Expr *pExpr){
|
||||
assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
|
||||
return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
|
||||
}
|
||||
if( op==TK_REGISTER ) op = pExpr->op2;
|
||||
#ifndef SQLITE_OMIT_CAST
|
||||
if( op==TK_CAST ){
|
||||
assert( !ExprHasProperty(pExpr, EP_IntValue) );
|
||||
return sqlite3AffinityType(pExpr->u.zToken, 0);
|
||||
}
|
||||
#endif
|
||||
if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->y.pTab ){
|
||||
return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
|
||||
}
|
||||
if( op==TK_SELECT_COLUMN ){
|
||||
assert( pExpr->pLeft->flags&EP_xIsSelect );
|
||||
assert( pExpr->iColumn < pExpr->iTable );
|
||||
assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
|
||||
return sqlite3ExprAffinity(
|
||||
pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
|
||||
);
|
||||
@@ -95,18 +97,7 @@ Expr *sqlite3ExprAddCollateToken(
|
||||
const Token *pCollName, /* Name of collating sequence */
|
||||
int dequote /* True to dequote pCollName */
|
||||
){
|
||||
assert( pExpr!=0 || pParse->db->mallocFailed );
|
||||
if( pExpr==0 ) return 0;
|
||||
if( pExpr->op==TK_VECTOR ){
|
||||
ExprList *pList = pExpr->x.pList;
|
||||
if( ALWAYS(pList!=0) ){
|
||||
int i;
|
||||
for(i=0; i<pList->nExpr; i++){
|
||||
pList->a[i].pExpr = sqlite3ExprAddCollateToken(pParse,pList->a[i].pExpr,
|
||||
pCollName, dequote);
|
||||
}
|
||||
}
|
||||
}else if( pCollName->n>0 ){
|
||||
if( pCollName->n>0 ){
|
||||
Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
|
||||
if( pNew ){
|
||||
pNew->pLeft = pExpr;
|
||||
@@ -456,7 +447,7 @@ int sqlite3ExprVectorSize(Expr *pExpr){
|
||||
** been positioned.
|
||||
*/
|
||||
Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){
|
||||
assert( i<sqlite3ExprVectorSize(pVector) );
|
||||
assert( i<sqlite3ExprVectorSize(pVector) || pVector->op==TK_ERROR );
|
||||
if( sqlite3ExprIsVector(pVector) ){
|
||||
assert( pVector->op2==0 || pVector->op==TK_REGISTER );
|
||||
if( pVector->op==TK_SELECT || pVector->op2==TK_SELECT ){
|
||||
@@ -492,7 +483,8 @@ Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){
|
||||
Expr *sqlite3ExprForVectorField(
|
||||
Parse *pParse, /* Parsing context */
|
||||
Expr *pVector, /* The vector. List of expressions or a sub-SELECT */
|
||||
int iField /* Which column of the vector to return */
|
||||
int iField, /* Which column of the vector to return */
|
||||
int nField /* Total number of columns in the vector */
|
||||
){
|
||||
Expr *pRet;
|
||||
if( pVector->op==TK_SELECT ){
|
||||
@@ -515,10 +507,10 @@ Expr *sqlite3ExprForVectorField(
|
||||
*/
|
||||
pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0);
|
||||
if( pRet ){
|
||||
pRet->iTable = nField;
|
||||
pRet->iColumn = iField;
|
||||
pRet->pLeft = pVector;
|
||||
}
|
||||
assert( pRet==0 || pRet->iTable==0 );
|
||||
}else{
|
||||
if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr;
|
||||
pRet = sqlite3ExprDup(pParse->db, pVector, 0);
|
||||
@@ -572,7 +564,7 @@ static int exprVectorRegister(
|
||||
int *pRegFree /* OUT: Temp register to free */
|
||||
){
|
||||
u8 op = pVector->op;
|
||||
assert( op==TK_VECTOR || op==TK_REGISTER || op==TK_SELECT );
|
||||
assert( op==TK_VECTOR || op==TK_REGISTER || op==TK_SELECT || op==TK_ERROR );
|
||||
if( op==TK_REGISTER ){
|
||||
*ppExpr = sqlite3VectorFieldSubexpr(pVector, iField);
|
||||
return pVector->iTable+iField;
|
||||
@@ -581,8 +573,11 @@ static int exprVectorRegister(
|
||||
*ppExpr = pVector->x.pSelect->pEList->a[iField].pExpr;
|
||||
return regSelect+iField;
|
||||
}
|
||||
*ppExpr = pVector->x.pList->a[iField].pExpr;
|
||||
return sqlite3ExprCodeTemp(pParse, *ppExpr, pRegFree);
|
||||
if( op==TK_VECTOR ){
|
||||
*ppExpr = pVector->x.pList->a[iField].pExpr;
|
||||
return sqlite3ExprCodeTemp(pParse, *ppExpr, pRegFree);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -611,6 +606,7 @@ static void codeVectorCompare(
|
||||
int regLeft = 0;
|
||||
int regRight = 0;
|
||||
u8 opx = op;
|
||||
int addrCmp = 0;
|
||||
int addrDone = sqlite3VdbeMakeLabel(pParse);
|
||||
int isCommuted = ExprHasProperty(pExpr,EP_Commuted);
|
||||
|
||||
@@ -630,21 +626,24 @@ static void codeVectorCompare(
|
||||
assert( p5==0 || pExpr->op!=op );
|
||||
assert( p5==SQLITE_NULLEQ || pExpr->op==op );
|
||||
|
||||
p5 |= SQLITE_STOREP2;
|
||||
if( opx==TK_LE ) opx = TK_LT;
|
||||
if( opx==TK_GE ) opx = TK_GT;
|
||||
if( op==TK_LE ) opx = TK_LT;
|
||||
if( op==TK_GE ) opx = TK_GT;
|
||||
if( op==TK_NE ) opx = TK_EQ;
|
||||
|
||||
regLeft = exprCodeSubselect(pParse, pLeft);
|
||||
regRight = exprCodeSubselect(pParse, pRight);
|
||||
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 1, dest);
|
||||
for(i=0; 1 /*Loop exits by "break"*/; i++){
|
||||
int regFree1 = 0, regFree2 = 0;
|
||||
Expr *pL, *pR;
|
||||
Expr *pL = 0, *pR = 0;
|
||||
int r1, r2;
|
||||
assert( i>=0 && i<nLeft );
|
||||
if( addrCmp ) sqlite3VdbeJumpHere(v, addrCmp);
|
||||
r1 = exprVectorRegister(pParse, pLeft, i, regLeft, &pL, ®Free1);
|
||||
r2 = exprVectorRegister(pParse, pRight, i, regRight, &pR, ®Free2);
|
||||
codeCompare(pParse, pL, pR, opx, r1, r2, dest, p5, isCommuted);
|
||||
addrCmp = sqlite3VdbeCurrentAddr(v);
|
||||
codeCompare(pParse, pL, pR, opx, r1, r2, addrDone, p5, isCommuted);
|
||||
testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
|
||||
testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
|
||||
testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
|
||||
@@ -653,26 +652,32 @@ static void codeVectorCompare(
|
||||
testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
|
||||
sqlite3ReleaseTempReg(pParse, regFree1);
|
||||
sqlite3ReleaseTempReg(pParse, regFree2);
|
||||
if( (opx==TK_LT || opx==TK_GT) && i<nLeft-1 ){
|
||||
addrCmp = sqlite3VdbeAddOp0(v, OP_ElseEq);
|
||||
testcase(opx==TK_LT); VdbeCoverageIf(v,opx==TK_LT);
|
||||
testcase(opx==TK_GT); VdbeCoverageIf(v,opx==TK_GT);
|
||||
}
|
||||
if( p5==SQLITE_NULLEQ ){
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, dest);
|
||||
}else{
|
||||
sqlite3VdbeAddOp3(v, OP_ZeroOrNull, r1, dest, r2);
|
||||
}
|
||||
if( i==nLeft-1 ){
|
||||
break;
|
||||
}
|
||||
if( opx==TK_EQ ){
|
||||
sqlite3VdbeAddOp2(v, OP_IfNot, dest, addrDone); VdbeCoverage(v);
|
||||
p5 |= SQLITE_KEEPNULL;
|
||||
}else if( opx==TK_NE ){
|
||||
sqlite3VdbeAddOp2(v, OP_If, dest, addrDone); VdbeCoverage(v);
|
||||
p5 |= SQLITE_KEEPNULL;
|
||||
sqlite3VdbeAddOp2(v, OP_NotNull, dest, addrDone); VdbeCoverage(v);
|
||||
}else{
|
||||
assert( op==TK_LT || op==TK_GT || op==TK_LE || op==TK_GE );
|
||||
sqlite3VdbeAddOp2(v, OP_ElseNotEq, 0, addrDone);
|
||||
VdbeCoverageIf(v, op==TK_LT);
|
||||
VdbeCoverageIf(v, op==TK_GT);
|
||||
VdbeCoverageIf(v, op==TK_LE);
|
||||
VdbeCoverageIf(v, op==TK_GE);
|
||||
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
|
||||
if( i==nLeft-2 ) opx = op;
|
||||
}
|
||||
}
|
||||
sqlite3VdbeJumpHere(v, addrCmp);
|
||||
sqlite3VdbeResolveLabel(v, addrDone);
|
||||
if( op==TK_NE ){
|
||||
sqlite3VdbeAddOp2(v, OP_Not, dest, dest);
|
||||
}
|
||||
}
|
||||
|
||||
#if SQLITE_MAX_EXPR_DEPTH>0
|
||||
@@ -940,6 +945,56 @@ void sqlite3PExprAddSelect(Parse *pParse, Expr *pExpr, Select *pSelect){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Expression list pEList is a list of vector values. This function
|
||||
** converts the contents of pEList to a VALUES(...) Select statement
|
||||
** returning 1 row for each element of the list. For example, the
|
||||
** expression list:
|
||||
**
|
||||
** ( (1,2), (3,4) (5,6) )
|
||||
**
|
||||
** is translated to the equivalent of:
|
||||
**
|
||||
** VALUES(1,2), (3,4), (5,6)
|
||||
**
|
||||
** Each of the vector values in pEList must contain exactly nElem terms.
|
||||
** If a list element that is not a vector or does not contain nElem terms,
|
||||
** an error message is left in pParse.
|
||||
**
|
||||
** This is used as part of processing IN(...) expressions with a list
|
||||
** of vectors on the RHS. e.g. "... IN ((1,2), (3,4), (5,6))".
|
||||
*/
|
||||
Select *sqlite3ExprListToValues(Parse *pParse, int nElem, ExprList *pEList){
|
||||
int ii;
|
||||
Select *pRet = 0;
|
||||
assert( nElem>1 );
|
||||
for(ii=0; ii<pEList->nExpr; ii++){
|
||||
Select *pSel;
|
||||
Expr *pExpr = pEList->a[ii].pExpr;
|
||||
int nExprElem = (pExpr->op==TK_VECTOR ? pExpr->x.pList->nExpr : 1);
|
||||
if( nExprElem!=nElem ){
|
||||
sqlite3ErrorMsg(pParse, "IN(...) element has %d term%s - expected %d",
|
||||
nExprElem, nExprElem>1?"s":"", nElem
|
||||
);
|
||||
break;
|
||||
}
|
||||
pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0);
|
||||
pExpr->x.pList = 0;
|
||||
if( pSel ){
|
||||
if( pRet ){
|
||||
pSel->op = TK_ALL;
|
||||
pSel->pPrior = pRet;
|
||||
}
|
||||
pRet = pSel;
|
||||
}
|
||||
}
|
||||
|
||||
if( pRet && pRet->pPrior ){
|
||||
pRet->selFlags |= SF_MultiValue;
|
||||
}
|
||||
sqlite3ExprListDelete(pParse->db, pEList);
|
||||
return pRet;
|
||||
}
|
||||
|
||||
/*
|
||||
** Join two expressions using an AND operator. If either expression is
|
||||
@@ -958,8 +1013,8 @@ Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
|
||||
}else if( (ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight))
|
||||
&& !IN_RENAME_OBJECT
|
||||
){
|
||||
sqlite3ExprDelete(db, pLeft);
|
||||
sqlite3ExprDelete(db, pRight);
|
||||
sqlite3ExprDeferredDelete(pParse, pLeft);
|
||||
sqlite3ExprDeferredDelete(pParse, pRight);
|
||||
return sqlite3Expr(db, TK_INTEGER, "0");
|
||||
}else{
|
||||
return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
|
||||
@@ -984,7 +1039,10 @@ Expr *sqlite3ExprFunction(
|
||||
sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
|
||||
return 0;
|
||||
}
|
||||
if( pList && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
|
||||
if( pList
|
||||
&& pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG]
|
||||
&& !pParse->nested
|
||||
){
|
||||
sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
|
||||
}
|
||||
pNew->x.pList = pList;
|
||||
@@ -1156,6 +1214,22 @@ void sqlite3ExprDelete(sqlite3 *db, Expr *p){
|
||||
if( p ) sqlite3ExprDeleteNN(db, p);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Arrange to cause pExpr to be deleted when the pParse is deleted.
|
||||
** This is similar to sqlite3ExprDelete() except that the delete is
|
||||
** deferred untilthe pParse is deleted.
|
||||
**
|
||||
** The pExpr might be deleted immediately on an OOM error.
|
||||
**
|
||||
** The deferred delete is (currently) implemented by adding the
|
||||
** pExpr to the pParse->pConstExpr list with a register number of 0.
|
||||
*/
|
||||
void sqlite3ExprDeferredDelete(Parse *pParse, Expr *pExpr){
|
||||
pParse->pConstExpr =
|
||||
sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
|
||||
}
|
||||
|
||||
/* Invoke sqlite3RenameExprUnmap() and sqlite3ExprDelete() on the
|
||||
** expression.
|
||||
*/
|
||||
@@ -1298,6 +1372,7 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){
|
||||
if( pzBuffer ){
|
||||
zAlloc = *pzBuffer;
|
||||
staticFlag = EP_Static;
|
||||
assert( zAlloc!=0 );
|
||||
}else{
|
||||
zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags));
|
||||
staticFlag = 0;
|
||||
@@ -1375,8 +1450,8 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){
|
||||
if( !ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){
|
||||
if( pNew->op==TK_SELECT_COLUMN ){
|
||||
pNew->pLeft = p->pLeft;
|
||||
assert( p->iColumn==0 || p->pRight==0 );
|
||||
assert( p->pRight==0 || p->pRight==p->pLeft );
|
||||
assert( p->pRight==0 || p->pRight==p->pLeft
|
||||
|| ExprHasProperty(p->pLeft, EP_Subquery) );
|
||||
}else{
|
||||
pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
|
||||
}
|
||||
@@ -1393,7 +1468,7 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){
|
||||
** and the db->mallocFailed flag set.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_CTE
|
||||
static With *withDup(sqlite3 *db, With *p){
|
||||
With *sqlite3WithDup(sqlite3 *db, With *p){
|
||||
With *pRet = 0;
|
||||
if( p ){
|
||||
sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
|
||||
@@ -1411,7 +1486,7 @@ static With *withDup(sqlite3 *db, With *p){
|
||||
return pRet;
|
||||
}
|
||||
#else
|
||||
# define withDup(x,y) 0
|
||||
# define sqlite3WithDup(x,y) 0
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
@@ -1472,12 +1547,14 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
|
||||
ExprList *pNew;
|
||||
struct ExprList_item *pItem, *pOldItem;
|
||||
int i;
|
||||
Expr *pPriorSelectCol = 0;
|
||||
Expr *pPriorSelectColOld = 0;
|
||||
Expr *pPriorSelectColNew = 0;
|
||||
assert( db!=0 );
|
||||
if( p==0 ) return 0;
|
||||
pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p));
|
||||
if( pNew==0 ) return 0;
|
||||
pNew->nExpr = p->nExpr;
|
||||
pNew->nAlloc = p->nAlloc;
|
||||
pItem = pNew->a;
|
||||
pOldItem = p->a;
|
||||
for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
|
||||
@@ -1488,16 +1565,17 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
|
||||
&& pOldExpr->op==TK_SELECT_COLUMN
|
||||
&& (pNewExpr = pItem->pExpr)!=0
|
||||
){
|
||||
assert( pNewExpr->iColumn==0 || i>0 );
|
||||
if( pNewExpr->iColumn==0 ){
|
||||
assert( pOldExpr->pLeft==pOldExpr->pRight );
|
||||
pPriorSelectCol = pNewExpr->pLeft = pNewExpr->pRight;
|
||||
if( pNewExpr->pRight ){
|
||||
pPriorSelectColOld = pOldExpr->pRight;
|
||||
pPriorSelectColNew = pNewExpr->pRight;
|
||||
pNewExpr->pLeft = pNewExpr->pRight;
|
||||
}else{
|
||||
assert( i>0 );
|
||||
assert( pItem[-1].pExpr!=0 );
|
||||
assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 );
|
||||
assert( pPriorSelectCol==pItem[-1].pExpr->pLeft );
|
||||
pNewExpr->pLeft = pPriorSelectCol;
|
||||
if( pOldExpr->pLeft!=pPriorSelectColOld ){
|
||||
pPriorSelectColOld = pOldExpr->pLeft;
|
||||
pPriorSelectColNew = sqlite3ExprDup(db, pPriorSelectColOld, flags);
|
||||
pNewExpr->pRight = pPriorSelectColNew;
|
||||
}
|
||||
pNewExpr->pLeft = pPriorSelectColNew;
|
||||
}
|
||||
}
|
||||
pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
|
||||
@@ -1530,8 +1608,8 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
|
||||
if( pNew==0 ) return 0;
|
||||
pNew->nSrc = pNew->nAlloc = p->nSrc;
|
||||
for(i=0; i<p->nSrc; i++){
|
||||
struct SrcList_item *pNewItem = &pNew->a[i];
|
||||
struct SrcList_item *pOldItem = &p->a[i];
|
||||
SrcItem *pNewItem = &pNew->a[i];
|
||||
SrcItem *pOldItem = &p->a[i];
|
||||
Table *pTab;
|
||||
pNewItem->pSchema = pOldItem->pSchema;
|
||||
pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
|
||||
@@ -1544,7 +1622,10 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
|
||||
if( pNewItem->fg.isIndexedBy ){
|
||||
pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
|
||||
}
|
||||
pNewItem->pIBIndex = pOldItem->pIBIndex;
|
||||
pNewItem->u2 = pOldItem->u2;
|
||||
if( pNewItem->fg.isCte ){
|
||||
pNewItem->u2.pCteUse->nUse++;
|
||||
}
|
||||
if( pNewItem->fg.isTabFunc ){
|
||||
pNewItem->u1.pFuncArg =
|
||||
sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
|
||||
@@ -1610,13 +1691,21 @@ Select *sqlite3SelectDup(sqlite3 *db, Select *pDup, int flags){
|
||||
pNew->addrOpenEphm[0] = -1;
|
||||
pNew->addrOpenEphm[1] = -1;
|
||||
pNew->nSelectRow = p->nSelectRow;
|
||||
pNew->pWith = withDup(db, p->pWith);
|
||||
pNew->pWith = sqlite3WithDup(db, p->pWith);
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
pNew->pWin = 0;
|
||||
pNew->pWinDefn = sqlite3WindowListDup(db, p->pWinDefn);
|
||||
if( p->pWin && db->mallocFailed==0 ) gatherSelectWindows(pNew);
|
||||
#endif
|
||||
pNew->selId = p->selId;
|
||||
if( db->mallocFailed ){
|
||||
/* Any prior OOM might have left the Select object incomplete.
|
||||
** Delete the whole thing rather than allow an incomplete Select
|
||||
** to be used by the code generator. */
|
||||
pNew->pNext = 0;
|
||||
sqlite3SelectDelete(db, pNew);
|
||||
break;
|
||||
}
|
||||
*pp = pNew;
|
||||
pp = &pNew->pPrior;
|
||||
pNext = pNew;
|
||||
@@ -1647,41 +1736,64 @@ Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
|
||||
** NULL is returned. If non-NULL is returned, then it is guaranteed
|
||||
** that the new entry was successfully appended.
|
||||
*/
|
||||
static const struct ExprList_item zeroItem = {0};
|
||||
SQLITE_NOINLINE ExprList *sqlite3ExprListAppendNew(
|
||||
sqlite3 *db, /* Database handle. Used for memory allocation */
|
||||
Expr *pExpr /* Expression to be appended. Might be NULL */
|
||||
){
|
||||
struct ExprList_item *pItem;
|
||||
ExprList *pList;
|
||||
|
||||
pList = sqlite3DbMallocRawNN(db, sizeof(ExprList)+sizeof(pList->a[0])*4 );
|
||||
if( pList==0 ){
|
||||
sqlite3ExprDelete(db, pExpr);
|
||||
return 0;
|
||||
}
|
||||
pList->nAlloc = 4;
|
||||
pList->nExpr = 1;
|
||||
pItem = &pList->a[0];
|
||||
*pItem = zeroItem;
|
||||
pItem->pExpr = pExpr;
|
||||
return pList;
|
||||
}
|
||||
SQLITE_NOINLINE ExprList *sqlite3ExprListAppendGrow(
|
||||
sqlite3 *db, /* Database handle. Used for memory allocation */
|
||||
ExprList *pList, /* List to which to append. Might be NULL */
|
||||
Expr *pExpr /* Expression to be appended. Might be NULL */
|
||||
){
|
||||
struct ExprList_item *pItem;
|
||||
ExprList *pNew;
|
||||
pList->nAlloc *= 2;
|
||||
pNew = sqlite3DbRealloc(db, pList,
|
||||
sizeof(*pList)+(pList->nAlloc-1)*sizeof(pList->a[0]));
|
||||
if( pNew==0 ){
|
||||
sqlite3ExprListDelete(db, pList);
|
||||
sqlite3ExprDelete(db, pExpr);
|
||||
return 0;
|
||||
}else{
|
||||
pList = pNew;
|
||||
}
|
||||
pItem = &pList->a[pList->nExpr++];
|
||||
*pItem = zeroItem;
|
||||
pItem->pExpr = pExpr;
|
||||
return pList;
|
||||
}
|
||||
ExprList *sqlite3ExprListAppend(
|
||||
Parse *pParse, /* Parsing context */
|
||||
ExprList *pList, /* List to which to append. Might be NULL */
|
||||
Expr *pExpr /* Expression to be appended. Might be NULL */
|
||||
){
|
||||
struct ExprList_item *pItem;
|
||||
sqlite3 *db = pParse->db;
|
||||
assert( db!=0 );
|
||||
if( pList==0 ){
|
||||
pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
|
||||
if( pList==0 ){
|
||||
goto no_mem;
|
||||
}
|
||||
pList->nExpr = 0;
|
||||
}else if( (pList->nExpr & (pList->nExpr-1))==0 ){
|
||||
ExprList *pNew;
|
||||
pNew = sqlite3DbRealloc(db, pList,
|
||||
sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0]));
|
||||
if( pNew==0 ){
|
||||
goto no_mem;
|
||||
}
|
||||
pList = pNew;
|
||||
return sqlite3ExprListAppendNew(pParse->db,pExpr);
|
||||
}
|
||||
if( pList->nAlloc<pList->nExpr+1 ){
|
||||
return sqlite3ExprListAppendGrow(pParse->db,pList,pExpr);
|
||||
}
|
||||
pItem = &pList->a[pList->nExpr++];
|
||||
assert( offsetof(struct ExprList_item,zEName)==sizeof(pItem->pExpr) );
|
||||
assert( offsetof(struct ExprList_item,pExpr)==0 );
|
||||
memset(&pItem->zEName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zEName));
|
||||
*pItem = zeroItem;
|
||||
pItem->pExpr = pExpr;
|
||||
return pList;
|
||||
|
||||
no_mem:
|
||||
/* Avoid leaking memory if malloc has failed. */
|
||||
sqlite3ExprDelete(db, pExpr);
|
||||
sqlite3ExprListDelete(db, pList);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1722,11 +1834,9 @@ ExprList *sqlite3ExprListAppendVector(
|
||||
}
|
||||
|
||||
for(i=0; i<pColumns->nId; i++){
|
||||
Expr *pSubExpr = sqlite3ExprForVectorField(pParse, pExpr, i);
|
||||
Expr *pSubExpr = sqlite3ExprForVectorField(pParse, pExpr, i, pColumns->nId);
|
||||
assert( pSubExpr!=0 || db->mallocFailed );
|
||||
assert( pSubExpr==0 || pSubExpr->iTable==0 );
|
||||
if( pSubExpr==0 ) continue;
|
||||
pSubExpr->iTable = pColumns->nId;
|
||||
pList = sqlite3ExprListAppend(pParse, pList, pSubExpr);
|
||||
if( pList ){
|
||||
assert( pList->nExpr==iFirst+i+1 );
|
||||
@@ -2294,8 +2404,10 @@ int sqlite3ExprIsInteger(Expr *p, int *pValue){
|
||||
*/
|
||||
int sqlite3ExprCanBeNull(const Expr *p){
|
||||
u8 op;
|
||||
assert( p!=0 );
|
||||
while( p->op==TK_UPLUS || p->op==TK_UMINUS ){
|
||||
p = p->pLeft;
|
||||
assert( p!=0 );
|
||||
}
|
||||
op = p->op;
|
||||
if( op==TK_REGISTER ) op = p->op2;
|
||||
@@ -2582,7 +2694,7 @@ int sqlite3FindInIndex(
|
||||
|
||||
/* Code an OP_Transaction and OP_TableLock for <table>. */
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
assert( iDb>=0 && iDb<SQLITE_MAX_ATTACHED );
|
||||
assert( iDb>=0 && iDb<SQLITE_MAX_DB );
|
||||
sqlite3CodeVerifySchema(pParse, iDb);
|
||||
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
|
||||
|
||||
@@ -2927,19 +3039,23 @@ void sqlite3CodeRhsOfIN(
|
||||
/* 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) ){
|
||||
Select *pCopy;
|
||||
SelectDest dest;
|
||||
int i;
|
||||
int rc;
|
||||
sqlite3SelectDestInit(&dest, SRT_Set, iTab);
|
||||
dest.zAffSdst = exprINAffinity(pParse, pExpr);
|
||||
pSelect->iLimit = 0;
|
||||
testcase( pSelect->selFlags & SF_Distinct );
|
||||
testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
|
||||
if( sqlite3Select(pParse, pSelect, &dest) ){
|
||||
sqlite3DbFree(pParse->db, dest.zAffSdst);
|
||||
pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
|
||||
rc = pParse->db->mallocFailed ? 1 :sqlite3Select(pParse, pCopy, &dest);
|
||||
sqlite3SelectDelete(pParse->db, pCopy);
|
||||
sqlite3DbFree(pParse->db, dest.zAffSdst);
|
||||
if( rc ){
|
||||
sqlite3KeyInfoUnref(pKeyInfo);
|
||||
return;
|
||||
}
|
||||
sqlite3DbFree(pParse->db, dest.zAffSdst);
|
||||
}
|
||||
assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
|
||||
assert( pEList!=0 );
|
||||
assert( pEList->nExpr>0 );
|
||||
@@ -3038,12 +3154,30 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
|
||||
Vdbe *v = pParse->pVdbe;
|
||||
assert( v!=0 );
|
||||
if( pParse->nErr ) return 0;
|
||||
testcase( pExpr->op==TK_EXISTS );
|
||||
testcase( pExpr->op==TK_SELECT );
|
||||
assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
|
||||
assert( ExprHasProperty(pExpr, EP_xIsSelect) );
|
||||
pSel = pExpr->x.pSelect;
|
||||
|
||||
/* If this routine has already been coded, then invoke it as a
|
||||
** subroutine. */
|
||||
if( ExprHasProperty(pExpr, EP_Subrtn) ){
|
||||
ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
|
||||
sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
|
||||
pExpr->y.sub.iAddr);
|
||||
return pExpr->iTable;
|
||||
}
|
||||
|
||||
/* Begin coding the subroutine */
|
||||
ExprSetProperty(pExpr, EP_Subrtn);
|
||||
pExpr->y.sub.regReturn = ++pParse->nMem;
|
||||
pExpr->y.sub.iAddr =
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
|
||||
VdbeComment((v, "return address"));
|
||||
|
||||
|
||||
/* The evaluation of the EXISTS/SELECT must be repeated every time it
|
||||
** is encountered if any of the following is true:
|
||||
**
|
||||
@@ -3055,22 +3189,6 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
** save the results, and reuse the same result on subsequent invocations.
|
||||
*/
|
||||
if( !ExprHasProperty(pExpr, EP_VarSelect) ){
|
||||
/* If this routine has already been coded, then invoke it as a
|
||||
** subroutine. */
|
||||
if( ExprHasProperty(pExpr, EP_Subrtn) ){
|
||||
ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
|
||||
sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
|
||||
pExpr->y.sub.iAddr);
|
||||
return pExpr->iTable;
|
||||
}
|
||||
|
||||
/* Begin coding the subroutine */
|
||||
ExprSetProperty(pExpr, EP_Subrtn);
|
||||
pExpr->y.sub.regReturn = ++pParse->nMem;
|
||||
pExpr->y.sub.iAddr =
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
|
||||
VdbeComment((v, "return address"));
|
||||
|
||||
addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
|
||||
}
|
||||
|
||||
@@ -3119,19 +3237,22 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
}
|
||||
pSel->iLimit = 0;
|
||||
if( sqlite3Select(pParse, pSel, &dest) ){
|
||||
if( pParse->nErr ){
|
||||
pExpr->op2 = pExpr->op;
|
||||
pExpr->op = TK_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
pExpr->iTable = rReg = dest.iSDParm;
|
||||
ExprSetVVAProperty(pExpr, EP_NoReduce);
|
||||
if( addrOnce ){
|
||||
sqlite3VdbeJumpHere(v, addrOnce);
|
||||
|
||||
/* Subroutine return */
|
||||
sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
|
||||
sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
|
||||
sqlite3ClearTempRegCache(pParse);
|
||||
}
|
||||
|
||||
/* Subroutine return */
|
||||
sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
|
||||
sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
|
||||
sqlite3ClearTempRegCache(pParse);
|
||||
return rReg;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_SUBQUERY */
|
||||
@@ -3145,7 +3266,7 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
*/
|
||||
int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
|
||||
int nVector = sqlite3ExprVectorSize(pIn->pLeft);
|
||||
if( (pIn->flags & EP_xIsSelect) ){
|
||||
if( (pIn->flags & EP_xIsSelect)!=0 && !pParse->db->mallocFailed ){
|
||||
if( nVector!=pIn->x.pSelect->pEList->nExpr ){
|
||||
sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
|
||||
return 1;
|
||||
@@ -3336,6 +3457,7 @@ static void sqlite3ExprCodeIN(
|
||||
if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
|
||||
for(i=0; i<nVector; i++){
|
||||
Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
|
||||
if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
|
||||
if( sqlite3ExprCanBeNull(p) ){
|
||||
sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
|
||||
VdbeCoverage(v);
|
||||
@@ -3961,7 +4083,7 @@ expr_code_doover:
|
||||
** Expr node to be passed into this function, it will be handled
|
||||
** sanely and not crash. But keep the assert() to bring the problem
|
||||
** to the attention of the developers. */
|
||||
assert( op==TK_NULL );
|
||||
assert( op==TK_NULL || op==TK_ERROR || pParse->db->mallocFailed );
|
||||
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
|
||||
return target;
|
||||
}
|
||||
@@ -4027,8 +4149,9 @@ expr_code_doover:
|
||||
}else{
|
||||
r1 = sqlite3ExprCodeTemp(pParse, pLeft, ®Free1);
|
||||
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, ®Free2);
|
||||
codeCompare(pParse, pLeft, pExpr->pRight, op,
|
||||
r1, r2, inReg, SQLITE_STOREP2 | p5,
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 1, inReg);
|
||||
codeCompare(pParse, pLeft, pExpr->pRight, op, r1, r2,
|
||||
sqlite3VdbeCurrentAddr(v)+2, p5,
|
||||
ExprHasProperty(pExpr,EP_Commuted));
|
||||
assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
|
||||
assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
|
||||
@@ -4036,6 +4159,11 @@ expr_code_doover:
|
||||
assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
|
||||
assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
|
||||
assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
|
||||
if( p5==SQLITE_NULLEQ ){
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, inReg);
|
||||
}else{
|
||||
sqlite3VdbeAddOp3(v, OP_ZeroOrNull, r1, inReg, r2);
|
||||
}
|
||||
testcase( regFree1==0 );
|
||||
testcase( regFree2==0 );
|
||||
}
|
||||
@@ -4298,10 +4426,9 @@ expr_code_doover:
|
||||
if( pExpr->pLeft->iTable==0 ){
|
||||
pExpr->pLeft->iTable = sqlite3CodeSubselect(pParse, pExpr->pLeft);
|
||||
}
|
||||
assert( pExpr->iTable==0 || pExpr->pLeft->op==TK_SELECT );
|
||||
if( pExpr->iTable!=0
|
||||
&& pExpr->iTable!=(n = sqlite3ExprVectorSize(pExpr->pLeft))
|
||||
){
|
||||
assert( pExpr->pLeft->op==TK_SELECT || pExpr->pLeft->op==TK_ERROR );
|
||||
n = sqlite3ExprVectorSize(pExpr->pLeft);
|
||||
if( pExpr->iTable!=n ){
|
||||
sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
|
||||
pExpr->iTable, n);
|
||||
}
|
||||
@@ -5554,9 +5681,9 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
|
||||
testcase( pExpr->op==TK_GE );
|
||||
/* The y.pTab=0 assignment in wherecode.c always happens after the
|
||||
** impliesNotNullRow() test */
|
||||
if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0)
|
||||
if( (pLeft->op==TK_COLUMN && pLeft->y.pTab!=0
|
||||
&& IsVirtual(pLeft->y.pTab))
|
||||
|| (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0)
|
||||
|| (pRight->op==TK_COLUMN && pRight->y.pTab!=0
|
||||
&& IsVirtual(pRight->y.pTab))
|
||||
){
|
||||
return WRC_Prune;
|
||||
@@ -5778,8 +5905,7 @@ static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
|
||||
pExpr = sqlite3ExprDup(db, pExpr, 0);
|
||||
if( pExpr ){
|
||||
pAggInfo->aCol[iAgg].pCExpr = pExpr;
|
||||
pParse->pConstExpr =
|
||||
sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
|
||||
sqlite3ExprDeferredDelete(pParse, pExpr);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
@@ -5788,8 +5914,7 @@ static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
|
||||
pExpr = sqlite3ExprDup(db, pExpr, 0);
|
||||
if( pExpr ){
|
||||
pAggInfo->aFunc[iAgg].pFExpr = pExpr;
|
||||
pParse->pConstExpr =
|
||||
sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
|
||||
sqlite3ExprDeferredDelete(pParse, pExpr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5861,7 +5986,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
/* Check to see if the column is in one of the tables in the FROM
|
||||
** clause of the aggregate query */
|
||||
if( ALWAYS(pSrcList!=0) ){
|
||||
struct SrcList_item *pItem = pSrcList->a;
|
||||
SrcItem *pItem = pSrcList->a;
|
||||
for(i=0; i<pSrcList->nSrc; i++, pItem++){
|
||||
struct AggInfo_col *pCol;
|
||||
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
|
||||
@@ -5932,6 +6057,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
*/
|
||||
struct AggInfo_func *pItem = pAggInfo->aFunc;
|
||||
for(i=0; i<pAggInfo->nFunc; i++, pItem++){
|
||||
if( pItem->pFExpr==pExpr ) break;
|
||||
if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
|
||||
break;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1024,7 +1024,7 @@ void sqlite3FkCheck(
|
||||
** child table as a SrcList for sqlite3WhereBegin() */
|
||||
pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
|
||||
if( pSrc ){
|
||||
struct SrcList_item *pItem = pSrc->a;
|
||||
SrcItem *pItem = pSrc->a;
|
||||
pItem->pTab = pFKey->pFrom;
|
||||
pItem->zName = pFKey->pFrom->zName;
|
||||
pItem->pTab->nTabRef++;
|
||||
|
||||
+22
-22
@@ -572,7 +572,7 @@ static void last_insert_rowid(
|
||||
** Implementation of the changes() SQL function.
|
||||
**
|
||||
** IMP: R-62073-11209 The changes() SQL function is a wrapper
|
||||
** around the sqlite3_changes() C/C++ function and hence follows the same
|
||||
** around the sqlite3_changes64() C/C++ function and hence follows the same
|
||||
** rules for counting changes.
|
||||
*/
|
||||
static void changes(
|
||||
@@ -582,12 +582,12 @@ static void changes(
|
||||
){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
sqlite3_result_int(context, sqlite3_changes(db));
|
||||
sqlite3_result_int64(context, sqlite3_changes64(db));
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the total_changes() SQL function. The return value is
|
||||
** the same as the sqlite3_total_changes() API function.
|
||||
** the same as the sqlite3_total_changes64() API function.
|
||||
*/
|
||||
static void total_changes(
|
||||
sqlite3_context *context,
|
||||
@@ -596,9 +596,9 @@ static void total_changes(
|
||||
){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
/* IMP: R-52756-41993 This function is a wrapper around the
|
||||
/* IMP: R-52756-41993 This function was a wrapper around the
|
||||
** sqlite3_total_changes() C/C++ interface. */
|
||||
sqlite3_result_int(context, sqlite3_total_changes(db));
|
||||
sqlite3_result_int64(context, sqlite3_total_changes64(db));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1316,10 +1316,10 @@ static void trimFunc(
|
||||
){
|
||||
const unsigned char *zIn; /* Input string */
|
||||
const unsigned char *zCharSet; /* Set of characters to trim */
|
||||
int nIn; /* Number of bytes in input */
|
||||
unsigned int nIn; /* Number of bytes in input */
|
||||
int flags; /* 1: trimleft 2: trimright 3: trim */
|
||||
int i; /* Loop counter */
|
||||
unsigned char *aLen = 0; /* Length of each character in zCharSet */
|
||||
unsigned int *aLen = 0; /* Length of each character in zCharSet */
|
||||
unsigned char **azChar = 0; /* Individual characters in zCharSet */
|
||||
int nChar; /* Number of characters in zCharSet */
|
||||
|
||||
@@ -1328,13 +1328,13 @@ static void trimFunc(
|
||||
}
|
||||
zIn = sqlite3_value_text(argv[0]);
|
||||
if( zIn==0 ) return;
|
||||
nIn = sqlite3_value_bytes(argv[0]);
|
||||
nIn = (unsigned)sqlite3_value_bytes(argv[0]);
|
||||
assert( zIn==sqlite3_value_text(argv[0]) );
|
||||
if( argc==1 ){
|
||||
static const unsigned char lenOne[] = { 1 };
|
||||
static const unsigned lenOne[] = { 1 };
|
||||
static unsigned char * const azOne[] = { (u8*)" " };
|
||||
nChar = 1;
|
||||
aLen = (u8*)lenOne;
|
||||
aLen = (unsigned*)lenOne;
|
||||
azChar = (unsigned char **)azOne;
|
||||
zCharSet = 0;
|
||||
}else if( (zCharSet = sqlite3_value_text(argv[1]))==0 ){
|
||||
@@ -1345,15 +1345,16 @@ static void trimFunc(
|
||||
SQLITE_SKIP_UTF8(z);
|
||||
}
|
||||
if( nChar>0 ){
|
||||
azChar = contextMalloc(context, ((i64)nChar)*(sizeof(char*)+1));
|
||||
azChar = contextMalloc(context,
|
||||
((i64)nChar)*(sizeof(char*)+sizeof(unsigned)));
|
||||
if( azChar==0 ){
|
||||
return;
|
||||
}
|
||||
aLen = (unsigned char*)&azChar[nChar];
|
||||
aLen = (unsigned*)&azChar[nChar];
|
||||
for(z=zCharSet, nChar=0; *z; nChar++){
|
||||
azChar[nChar] = (unsigned char *)z;
|
||||
SQLITE_SKIP_UTF8(z);
|
||||
aLen[nChar] = (u8)(z - azChar[nChar]);
|
||||
aLen[nChar] = (unsigned)(z - azChar[nChar]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1361,7 +1362,7 @@ static void trimFunc(
|
||||
flags = SQLITE_PTR_TO_INT(sqlite3_user_data(context));
|
||||
if( flags & 1 ){
|
||||
while( nIn>0 ){
|
||||
int len = 0;
|
||||
unsigned int len = 0;
|
||||
for(i=0; i<nChar; i++){
|
||||
len = aLen[i];
|
||||
if( len<=nIn && memcmp(zIn, azChar[i], len)==0 ) break;
|
||||
@@ -1373,7 +1374,7 @@ static void trimFunc(
|
||||
}
|
||||
if( flags & 2 ){
|
||||
while( nIn>0 ){
|
||||
int len = 0;
|
||||
unsigned int len = 0;
|
||||
for(i=0; i<nChar; i++){
|
||||
len = aLen[i];
|
||||
if( len<=nIn && memcmp(&zIn[nIn-len],azChar[i],len)==0 ) break;
|
||||
@@ -2071,9 +2072,7 @@ static void math2Func(
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of 2-argument SQL math functions:
|
||||
**
|
||||
** power(X,Y) - Compute X to the Y-th power
|
||||
** Implementation of 0-argument pi() function.
|
||||
*/
|
||||
static void piFunc(
|
||||
sqlite3_context *context,
|
||||
@@ -2161,11 +2160,11 @@ void sqlite3RegisterBuiltinFunctions(void){
|
||||
FUNCTION(min, -1, 0, 1, minmaxFunc ),
|
||||
FUNCTION(min, 0, 0, 1, 0 ),
|
||||
WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
|
||||
SQLITE_FUNC_MINMAX ),
|
||||
SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
|
||||
FUNCTION(max, -1, 1, 1, minmaxFunc ),
|
||||
FUNCTION(max, 0, 1, 1, 0 ),
|
||||
WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
|
||||
SQLITE_FUNC_MINMAX ),
|
||||
SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
|
||||
FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
|
||||
FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
|
||||
FUNCTION(instr, 2, 0, 0, instrFunc ),
|
||||
@@ -2201,9 +2200,10 @@ void sqlite3RegisterBuiltinFunctions(void){
|
||||
WAGGREGATE(total, 1,0,0, sumStep,totalFinalize,totalFinalize,sumInverse, 0),
|
||||
WAGGREGATE(avg, 1,0,0, sumStep, avgFinalize, avgFinalize, sumInverse, 0),
|
||||
WAGGREGATE(count, 0,0,0, countStep,
|
||||
countFinalize, countFinalize, countInverse, SQLITE_FUNC_COUNT ),
|
||||
countFinalize, countFinalize, countInverse,
|
||||
SQLITE_FUNC_COUNT|SQLITE_FUNC_ANYORDER ),
|
||||
WAGGREGATE(count, 1,0,0, countStep,
|
||||
countFinalize, countFinalize, countInverse, 0 ),
|
||||
countFinalize, countFinalize, countInverse, SQLITE_FUNC_ANYORDER ),
|
||||
WAGGREGATE(group_concat, 1, 0, 0, groupConcatStep,
|
||||
groupConcatFinalize, groupConcatValue, groupConcatInverse, 0),
|
||||
WAGGREGATE(group_concat, 2, 0, 0, groupConcatStep,
|
||||
|
||||
+30
-2
@@ -37,7 +37,7 @@ const unsigned char sqlite3UpperToLower[] = {
|
||||
198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
|
||||
216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
|
||||
234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
|
||||
252,253,254,255
|
||||
252,253,254,255,
|
||||
#endif
|
||||
#ifdef SQLITE_EBCDIC
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */
|
||||
@@ -57,7 +57,35 @@ const unsigned char sqlite3UpperToLower[] = {
|
||||
224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */
|
||||
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */
|
||||
#endif
|
||||
/* All of the upper-to-lower conversion data is above. The following
|
||||
** 18 integers are completely unrelated. They are appended to the
|
||||
** sqlite3UpperToLower[] array to avoid UBSAN warnings. Here's what is
|
||||
** going on:
|
||||
**
|
||||
** The SQL comparison operators (<>, =, >, <=, <, and >=) are implemented
|
||||
** by invoking sqlite3MemCompare(A,B) which compares values A and B and
|
||||
** returns negative, zero, or positive if A is less then, equal to, or
|
||||
** greater than B, respectively. Then the true false results is found by
|
||||
** consulting sqlite3aLTb[opcode], sqlite3aEQb[opcode], or
|
||||
** sqlite3aGTb[opcode] depending on whether the result of compare(A,B)
|
||||
** is negative, zero, or positive, where opcode is the specific opcode.
|
||||
** The only works because the comparison opcodes are consecutive and in
|
||||
** this order: NE EQ GT LE LT GE. Various assert()s throughout the code
|
||||
** ensure that is the case.
|
||||
**
|
||||
** These elements must be appended to another array. Otherwise the
|
||||
** index (here shown as [256-OP_Ne]) would be out-of-bounds and thus
|
||||
** be undefined behavior. That's goofy, but the C-standards people thought
|
||||
** it was a good idea, so here we are.
|
||||
*/
|
||||
/* NE EQ GT LE LT GE */
|
||||
1, 0, 0, 1, 1, 0, /* aLTb[]: Use when compare(A,B) less than zero */
|
||||
0, 1, 0, 1, 0, 1, /* aEQb[]: Use when compare(A,B) equals zero */
|
||||
1, 0, 1, 0, 0, 1 /* aGTb[]: Use when compare(A,B) greater than zero*/
|
||||
};
|
||||
const unsigned char *sqlite3aLTb = &sqlite3UpperToLower[256-OP_Ne];
|
||||
const unsigned char *sqlite3aEQb = &sqlite3UpperToLower[256+6-OP_Ne];
|
||||
const unsigned char *sqlite3aGTb = &sqlite3UpperToLower[256+12-OP_Ne];
|
||||
|
||||
/*
|
||||
** The following 256 byte lookup table is used to support SQLites built-in
|
||||
@@ -251,7 +279,7 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = {
|
||||
0, /* xVdbeBranch */
|
||||
0, /* pVbeBranchArg */
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
#ifndef SQLITE_OMIT_DESERIALIZE
|
||||
SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
|
||||
#endif
|
||||
#ifndef SQLITE_UNTESTABLE
|
||||
|
||||
+17
-8
@@ -113,7 +113,7 @@ const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
|
||||
** Compute the affinity string for table pTab, if it has not already been
|
||||
** computed. As an optimization, omit trailing SQLITE_AFF_BLOB affinities.
|
||||
**
|
||||
** If the affinity exists (if it is no entirely SQLITE_AFF_BLOB values) and
|
||||
** If the affinity exists (if it is not entirely SQLITE_AFF_BLOB values) and
|
||||
** if iReg>0 then code an OP_Affinity opcode that will set the affinities
|
||||
** for register iReg and following. Or if affinities exists and iReg==0,
|
||||
** then just set the P4 operand of the previous opcode (which should be
|
||||
@@ -358,7 +358,7 @@ static int autoIncBegin(
|
||||
** Ticket d8dc2b3a58cd5dc2918a1d4acb 2018-05-23 */
|
||||
if( pSeqTab==0
|
||||
|| !HasRowid(pSeqTab)
|
||||
|| IsVirtual(pSeqTab)
|
||||
|| NEVER(IsVirtual(pSeqTab))
|
||||
|| pSeqTab->nCol!=2
|
||||
){
|
||||
pParse->nErr++;
|
||||
@@ -817,7 +817,7 @@ void sqlite3Insert(
|
||||
bIdListInOrder = 0;
|
||||
}else{
|
||||
sqlite3ErrorMsg(pParse, "table %S has no column named %s",
|
||||
pTabList, 0, pColumn->a[i].zName);
|
||||
pTabList->a, pColumn->a[i].zName);
|
||||
pParse->checkSchema = 1;
|
||||
goto insert_cleanup;
|
||||
}
|
||||
@@ -945,7 +945,7 @@ void sqlite3Insert(
|
||||
if( nColumn!=(pTab->nCol-nHidden) ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"table %S has %d columns but %d values were supplied",
|
||||
pTabList, 0, pTab->nCol-nHidden, nColumn);
|
||||
pTabList->a, pTab->nCol-nHidden, nColumn);
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -1004,7 +1004,9 @@ void sqlite3Insert(
|
||||
pNx->iDataCur = iDataCur;
|
||||
pNx->iIdxCur = iIdxCur;
|
||||
if( pNx->pUpsertTarget ){
|
||||
sqlite3UpsertAnalyzeTarget(pParse, pTabList, pNx);
|
||||
if( sqlite3UpsertAnalyzeTarget(pParse, pTabList, pNx) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
pNx = pNx->pNextUpsert;
|
||||
}while( pNx!=0 );
|
||||
@@ -1246,7 +1248,7 @@ void sqlite3Insert(
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
int isReplace; /* Set to true if constraints may cause a replace */
|
||||
int isReplace = 0;/* Set to true if constraints may cause a replace */
|
||||
int bUseSeek; /* True to use OPFLAG_SEEKRESULT */
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
|
||||
regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
|
||||
@@ -1266,6 +1268,13 @@ void sqlite3Insert(
|
||||
regIns, aRegIdx, 0, appendFlag, bUseSeek
|
||||
);
|
||||
}
|
||||
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
|
||||
}else if( pParse->bReturning ){
|
||||
/* If there is a RETURNING clause, populate the rowid register with
|
||||
** constant value -1, in case one or more of the returned expressions
|
||||
** refer to the "rowid" of the view. */
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, -1, regRowid);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Update the count of rows that are inserted
|
||||
@@ -2426,7 +2435,7 @@ static void codeWithoutRowidPreupdate(
|
||||
Vdbe *v = pParse->pVdbe;
|
||||
int r = sqlite3GetTempReg(pParse);
|
||||
assert( !HasRowid(pTab) );
|
||||
assert( 0==(pParse->db->mDbFlags & DBFLAG_Vacuum) );
|
||||
assert( 0==(pParse->db->mDbFlags & DBFLAG_Vacuum) || CORRUPT_DB );
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, r);
|
||||
sqlite3VdbeAddOp4(v, OP_Insert, iCur, regData, r, (char*)pTab, P4_TABLE);
|
||||
sqlite3VdbeChangeP5(v, OPFLAG_ISNOOP);
|
||||
@@ -2684,7 +2693,7 @@ static int xferOptimization(
|
||||
ExprList *pEList; /* The result set of the SELECT */
|
||||
Table *pSrc; /* The table in the FROM clause of SELECT */
|
||||
Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
|
||||
struct SrcList_item *pItem; /* An element of pSelect->pSrc */
|
||||
SrcItem *pItem; /* An element of pSelect->pSrc */
|
||||
int i; /* Loop counter */
|
||||
int iDbSrc; /* The database of pSrc */
|
||||
int iSrc, iDest; /* Cursors from source and destination */
|
||||
|
||||
+27
-14
@@ -480,6 +480,9 @@ static const sqlite3_api_routines sqlite3Apis = {
|
||||
sqlite3_database_file_object,
|
||||
/* Version 3.34.0 and later */
|
||||
sqlite3_txn_state,
|
||||
/* Version 3.36.1 and later */
|
||||
sqlite3_changes64,
|
||||
sqlite3_total_changes64,
|
||||
};
|
||||
|
||||
/* True if x is the directory separator character
|
||||
@@ -515,7 +518,7 @@ static int sqlite3LoadExtension(
|
||||
const char *zEntry;
|
||||
char *zAltEntry = 0;
|
||||
void **aHandle;
|
||||
u64 nMsg = 300 + sqlite3Strlen30(zFile);
|
||||
u64 nMsg = strlen(zFile);
|
||||
int ii;
|
||||
int rc;
|
||||
|
||||
@@ -549,6 +552,12 @@ static int sqlite3LoadExtension(
|
||||
|
||||
zEntry = zProc ? zProc : "sqlite3_extension_init";
|
||||
|
||||
/* tag-20210611-1. Some dlopen() implementations will segfault if given
|
||||
** an oversize filename. Most filesystems have a pathname limit of 4K,
|
||||
** so limit the extension filename length to about twice that.
|
||||
** https://sqlite.org/forum/forumpost/08a0d6d9bf */
|
||||
if( nMsg>SQLITE_MAX_PATHLEN ) goto extension_not_found;
|
||||
|
||||
handle = sqlite3OsDlOpen(pVfs, zFile);
|
||||
#if SQLITE_OS_UNIX || SQLITE_OS_WIN
|
||||
for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
|
||||
@@ -558,17 +567,7 @@ static int sqlite3LoadExtension(
|
||||
sqlite3_free(zAltFile);
|
||||
}
|
||||
#endif
|
||||
if( handle==0 ){
|
||||
if( pzErrMsg ){
|
||||
*pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
|
||||
if( zErrmsg ){
|
||||
sqlite3_snprintf(nMsg, zErrmsg,
|
||||
"unable to open shared library [%s]", zFile);
|
||||
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
|
||||
}
|
||||
}
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
if( handle==0 ) goto extension_not_found;
|
||||
xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry);
|
||||
|
||||
/* If no entry point was specified and the default legacy
|
||||
@@ -605,10 +604,11 @@ static int sqlite3LoadExtension(
|
||||
}
|
||||
if( xInit==0 ){
|
||||
if( pzErrMsg ){
|
||||
nMsg += sqlite3Strlen30(zEntry);
|
||||
nMsg += strlen(zEntry) + 300;
|
||||
*pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
|
||||
if( zErrmsg ){
|
||||
sqlite3_snprintf(nMsg, zErrmsg,
|
||||
assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */
|
||||
sqlite3_snprintf((int)nMsg, zErrmsg,
|
||||
"no entry point [%s] in shared library [%s]", zEntry, zFile);
|
||||
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
|
||||
}
|
||||
@@ -642,6 +642,19 @@ static int sqlite3LoadExtension(
|
||||
|
||||
db->aExtension[db->nExtension++] = handle;
|
||||
return SQLITE_OK;
|
||||
|
||||
extension_not_found:
|
||||
if( pzErrMsg ){
|
||||
nMsg += 300;
|
||||
*pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
|
||||
if( zErrmsg ){
|
||||
assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */
|
||||
sqlite3_snprintf((int)nMsg, zErrmsg,
|
||||
"unable to open shared library [%.*s]", SQLITE_MAX_PATHLEN, zFile);
|
||||
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
|
||||
}
|
||||
}
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
int sqlite3_load_extension(
|
||||
sqlite3 *db, /* Load the extension into this database connection */
|
||||
|
||||
+78
-24
@@ -305,7 +305,7 @@ int sqlite3_initialize(void){
|
||||
sqlite3GlobalConfig.isPCacheInit = 1;
|
||||
rc = sqlite3OsInit();
|
||||
}
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
#ifndef SQLITE_OMIT_DESERIALIZE
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3MemdbInit();
|
||||
}
|
||||
@@ -720,12 +720,12 @@ int sqlite3_config(int op, ...){
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_SORTER_REFERENCES */
|
||||
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
#ifndef SQLITE_OMIT_DESERIALIZE
|
||||
case SQLITE_CONFIG_MEMDB_MAXSIZE: {
|
||||
sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
|
||||
break;
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_DESERIALIZE */
|
||||
#endif /* SQLITE_OMIT_DESERIALIZE */
|
||||
|
||||
default: {
|
||||
rc = SQLITE_ERROR;
|
||||
@@ -1086,7 +1086,7 @@ void sqlite3_set_last_insert_rowid(sqlite3 *db, sqlite3_int64 iRowid){
|
||||
/*
|
||||
** Return the number of changes in the most recent call to sqlite3_exec().
|
||||
*/
|
||||
int sqlite3_changes(sqlite3 *db){
|
||||
sqlite3_int64 sqlite3_changes64(sqlite3 *db){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
@@ -1095,11 +1095,14 @@ int sqlite3_changes(sqlite3 *db){
|
||||
#endif
|
||||
return db->nChange;
|
||||
}
|
||||
int sqlite3_changes(sqlite3 *db){
|
||||
return (int)sqlite3_changes64(db);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of changes since the database handle was opened.
|
||||
*/
|
||||
int sqlite3_total_changes(sqlite3 *db){
|
||||
sqlite3_int64 sqlite3_total_changes64(sqlite3 *db){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
@@ -1108,6 +1111,9 @@ int sqlite3_total_changes(sqlite3 *db){
|
||||
#endif
|
||||
return db->nTotalChange;
|
||||
}
|
||||
int sqlite3_total_changes(sqlite3 *db){
|
||||
return (int)sqlite3_total_changes64(db);
|
||||
}
|
||||
|
||||
/*
|
||||
** Close all open savepoints. This function only manipulates fields of the
|
||||
@@ -1274,7 +1280,7 @@ int sqlite3_txn_state(sqlite3 *db, const char *zSchema){
|
||||
/*
|
||||
** Two variations on the public interface for closing a database
|
||||
** connection. The sqlite3_close() version returns SQLITE_BUSY and
|
||||
** leaves the connection option if there are unfinalized prepared
|
||||
** leaves the connection open if there are unfinalized prepared
|
||||
** statements or unfinished sqlite3_backups. The sqlite3_close_v2()
|
||||
** version forces the connection to become a zombie if there are
|
||||
** unclosed resources, and arranges for deallocation when the last
|
||||
@@ -1848,22 +1854,33 @@ int sqlite3CreateFunc(
|
||||
** If SQLITE_ANY is specified, add three versions of the function
|
||||
** to the hash table.
|
||||
*/
|
||||
if( enc==SQLITE_UTF16 ){
|
||||
enc = SQLITE_UTF16NATIVE;
|
||||
}else if( enc==SQLITE_ANY ){
|
||||
int rc;
|
||||
rc = sqlite3CreateFunc(db, zFunctionName, nArg,
|
||||
(SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE,
|
||||
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
|
||||
if( rc==SQLITE_OK ){
|
||||
switch( enc ){
|
||||
case SQLITE_UTF16:
|
||||
enc = SQLITE_UTF16NATIVE;
|
||||
break;
|
||||
case SQLITE_ANY: {
|
||||
int rc;
|
||||
rc = sqlite3CreateFunc(db, zFunctionName, nArg,
|
||||
(SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE,
|
||||
(SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE,
|
||||
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3CreateFunc(db, zFunctionName, nArg,
|
||||
(SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE,
|
||||
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
return rc;
|
||||
}
|
||||
enc = SQLITE_UTF16BE;
|
||||
break;
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
return rc;
|
||||
}
|
||||
enc = SQLITE_UTF16BE;
|
||||
case SQLITE_UTF8:
|
||||
case SQLITE_UTF16LE:
|
||||
case SQLITE_UTF16BE:
|
||||
break;
|
||||
default:
|
||||
enc = SQLITE_UTF8;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
enc = SQLITE_UTF8;
|
||||
@@ -1884,6 +1901,10 @@ int sqlite3CreateFunc(
|
||||
}else{
|
||||
sqlite3ExpirePreparedStatements(db, 0);
|
||||
}
|
||||
}else if( xSFunc==0 && xFinal==0 ){
|
||||
/* Trying to delete a function that does not exist. This is a no-op.
|
||||
** https://sqlite.org/forum/forumpost/726219164b */
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 1);
|
||||
@@ -1956,7 +1977,7 @@ static int createFunctionApi(
|
||||
xSFunc, xStep, xFinal, xValue, xInverse, pArg
|
||||
);
|
||||
if( pArg && pArg->nRef==0 ){
|
||||
assert( rc!=SQLITE_OK );
|
||||
assert( rc!=SQLITE_OK || (xStep==0 && xFinal==0) );
|
||||
xDestroy(p);
|
||||
sqlite3_free(pArg);
|
||||
}
|
||||
@@ -2374,7 +2395,7 @@ int sqlite3_wal_checkpoint_v2(
|
||||
return SQLITE_OK;
|
||||
#else
|
||||
int rc; /* Return code */
|
||||
int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
|
||||
int iDb; /* Schema to checkpoint */
|
||||
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
||||
@@ -2397,6 +2418,8 @@ int sqlite3_wal_checkpoint_v2(
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
if( zDb && zDb[0] ){
|
||||
iDb = sqlite3FindDbName(db, zDb);
|
||||
}else{
|
||||
iDb = SQLITE_MAX_DB; /* This means process all schemas */
|
||||
}
|
||||
if( iDb<0 ){
|
||||
rc = SQLITE_ERROR;
|
||||
@@ -2445,7 +2468,7 @@ int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
|
||||
** associated with the specific b-tree being checkpointed is taken by
|
||||
** this function while the checkpoint is running.
|
||||
**
|
||||
** If iDb is passed SQLITE_MAX_ATTACHED, then all attached databases are
|
||||
** If iDb is passed SQLITE_MAX_DB then all attached databases are
|
||||
** checkpointed. If an error is encountered it is returned immediately -
|
||||
** no attempt is made to checkpoint any remaining databases.
|
||||
**
|
||||
@@ -2460,9 +2483,11 @@ int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
|
||||
assert( sqlite3_mutex_held(db->mutex) );
|
||||
assert( !pnLog || *pnLog==-1 );
|
||||
assert( !pnCkpt || *pnCkpt==-1 );
|
||||
testcase( iDb==SQLITE_MAX_ATTACHED ); /* See forum post a006d86f72 */
|
||||
testcase( iDb==SQLITE_MAX_DB );
|
||||
|
||||
for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
|
||||
if( i==iDb || iDb==SQLITE_MAX_ATTACHED ){
|
||||
if( i==iDb || iDb==SQLITE_MAX_DB ){
|
||||
rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
|
||||
pnLog = 0;
|
||||
pnCkpt = 0;
|
||||
@@ -3135,7 +3160,6 @@ static int openDatabase(
|
||||
** off all other flags.
|
||||
*/
|
||||
flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
|
||||
SQLITE_OPEN_EXCLUSIVE |
|
||||
SQLITE_OPEN_MAIN_DB |
|
||||
SQLITE_OPEN_TEMP_DB |
|
||||
SQLITE_OPEN_TRANSIENT_DB |
|
||||
@@ -4275,6 +4299,36 @@ int sqlite3_test_control(int op, ...){
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_WSD)
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_TUNE, id, *piValue)
|
||||
**
|
||||
** If "id" is an integer between 1 and SQLITE_NTUNE then set the value
|
||||
** of the id-th tuning parameter to *piValue. If "id" is between -1
|
||||
** and -SQLITE_NTUNE, then write the current value of the (-id)-th
|
||||
** tuning parameter into *piValue.
|
||||
**
|
||||
** Tuning parameters are for use during transient development builds,
|
||||
** to help find the best values for constants in the query planner.
|
||||
** Access tuning parameters using the Tuning(ID) macro. Set the
|
||||
** parameters in the CLI using ".testctrl tune ID VALUE".
|
||||
**
|
||||
** Transient use only. Tuning parameters should not be used in
|
||||
** checked-in code.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_TUNE: {
|
||||
int id = va_arg(ap, int);
|
||||
int *piValue = va_arg(ap, int*);
|
||||
if( id>0 && id<=SQLITE_NTUNE ){
|
||||
Tuning(id) = *piValue;
|
||||
}else if( id<0 && id>=-SQLITE_NTUNE ){
|
||||
*piValue = Tuning(-id);
|
||||
}else{
|
||||
rc = SQLITE_NOTFOUND;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
va_end(ap);
|
||||
#endif /* SQLITE_UNTESTABLE */
|
||||
|
||||
@@ -161,7 +161,6 @@ int sqlite3MallocInit(void){
|
||||
if( sqlite3GlobalConfig.m.xMalloc==0 ){
|
||||
sqlite3MemSetDefault();
|
||||
}
|
||||
memset(&mem0, 0, sizeof(mem0));
|
||||
mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
|
||||
if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
|
||||
|| sqlite3GlobalConfig.nPage<=0 ){
|
||||
|
||||
+298
-56
@@ -17,31 +17,88 @@
|
||||
** sqlite3_deserialize().
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
#ifndef SQLITE_OMIT_DESERIALIZE
|
||||
|
||||
/*
|
||||
** Forward declaration of objects used by this utility
|
||||
*/
|
||||
typedef struct sqlite3_vfs MemVfs;
|
||||
typedef struct MemFile MemFile;
|
||||
typedef struct MemStore MemStore;
|
||||
|
||||
/* Access to a lower-level VFS that (might) implement dynamic loading,
|
||||
** access to randomness, etc.
|
||||
*/
|
||||
#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
|
||||
|
||||
/* An open file */
|
||||
struct MemFile {
|
||||
sqlite3_file base; /* IO methods */
|
||||
/* Storage for a memdb file.
|
||||
**
|
||||
** An memdb object can be shared or separate. Shared memdb objects can be
|
||||
** used by more than one database connection. Mutexes are used by shared
|
||||
** memdb objects to coordinate access. Separate memdb objects are only
|
||||
** connected to a single database connection and do not require additional
|
||||
** mutexes.
|
||||
**
|
||||
** Shared memdb objects have .zFName!=0 and .pMutex!=0. They are created
|
||||
** using "file:/name?vfs=memdb". The first character of the name must be
|
||||
** "/" or else the object will be a separate memdb object. All shared
|
||||
** memdb objects are stored in memdb_g.apMemStore[] in an arbitrary order.
|
||||
**
|
||||
** Separate memdb objects are created using a name that does not begin
|
||||
** with "/" or using sqlite3_deserialize().
|
||||
**
|
||||
** Access rules for shared MemStore objects:
|
||||
**
|
||||
** * .zFName is initialized when the object is created and afterwards
|
||||
** is unchanged until the object is destroyed. So it can be accessed
|
||||
** at any time as long as we know the object is not being destroyed,
|
||||
** which means while either the SQLITE_MUTEX_STATIC_VFS1 or
|
||||
** .pMutex is held or the object is not part of memdb_g.apMemStore[].
|
||||
**
|
||||
** * Can .pMutex can only be changed while holding the
|
||||
** SQLITE_MUTEX_STATIC_VFS1 mutex or while the object is not part
|
||||
** of memdb_g.apMemStore[].
|
||||
**
|
||||
** * Other fields can only be changed while holding the .pMutex mutex
|
||||
** or when the .nRef is less than zero and the object is not part of
|
||||
** memdb_g.apMemStore[].
|
||||
**
|
||||
** * The .aData pointer has the added requirement that it can can only
|
||||
** be changed (for resizing) when nMmap is zero.
|
||||
**
|
||||
*/
|
||||
struct MemStore {
|
||||
sqlite3_int64 sz; /* Size of the file */
|
||||
sqlite3_int64 szAlloc; /* Space allocated to aData */
|
||||
sqlite3_int64 szMax; /* Maximum allowed size of the file */
|
||||
unsigned char *aData; /* content of the file */
|
||||
sqlite3_mutex *pMutex; /* Used by shared stores only */
|
||||
int nMmap; /* Number of memory mapped pages */
|
||||
unsigned mFlags; /* Flags */
|
||||
int nRdLock; /* Number of readers */
|
||||
int nWrLock; /* Number of writers. (Always 0 or 1) */
|
||||
int nRef; /* Number of users of this MemStore */
|
||||
char *zFName; /* The filename for shared stores */
|
||||
};
|
||||
|
||||
/* An open file */
|
||||
struct MemFile {
|
||||
sqlite3_file base; /* IO methods */
|
||||
MemStore *pStore; /* The storage */
|
||||
int eLock; /* Most recent lock against this file */
|
||||
};
|
||||
|
||||
/*
|
||||
** File-scope variables for holding the memdb files that are accessible
|
||||
** to multiple database connections in separate threads.
|
||||
**
|
||||
** Must hold SQLITE_MUTEX_STATIC_VFS1 to access any part of this object.
|
||||
*/
|
||||
static struct MemFS {
|
||||
int nMemStore; /* Number of shared MemStore objects */
|
||||
MemStore **apMemStore; /* Array of all shared MemStore objects */
|
||||
} memdb_g;
|
||||
|
||||
/*
|
||||
** Methods for MemFile
|
||||
*/
|
||||
@@ -95,7 +152,10 @@ static sqlite3_vfs memdb_vfs = {
|
||||
memdbSleep, /* xSleep */
|
||||
0, /* memdbCurrentTime, */ /* xCurrentTime */
|
||||
memdbGetLastError, /* xGetLastError */
|
||||
memdbCurrentTimeInt64 /* xCurrentTimeInt64 */
|
||||
memdbCurrentTimeInt64, /* xCurrentTimeInt64 */
|
||||
0, /* xSetSystemCall */
|
||||
0, /* xGetSystemCall */
|
||||
0, /* xNextSystemCall */
|
||||
};
|
||||
|
||||
static const sqlite3_io_methods memdb_io_methods = {
|
||||
@@ -120,19 +180,67 @@ static const sqlite3_io_methods memdb_io_methods = {
|
||||
memdbUnfetch /* xUnfetch */
|
||||
};
|
||||
|
||||
/*
|
||||
** Enter/leave the mutex on a MemStore
|
||||
*/
|
||||
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE==0
|
||||
static void memdbEnter(MemStore *p){
|
||||
UNUSED_PARAMETER(p);
|
||||
}
|
||||
static void memdbLeave(MemStore *p){
|
||||
UNUSED_PARAMETER(p);
|
||||
}
|
||||
#else
|
||||
static void memdbEnter(MemStore *p){
|
||||
sqlite3_mutex_enter(p->pMutex);
|
||||
}
|
||||
static void memdbLeave(MemStore *p){
|
||||
sqlite3_mutex_leave(p->pMutex);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Close an memdb-file.
|
||||
**
|
||||
** The pData pointer is owned by the application, so there is nothing
|
||||
** to free. Unless the SQLITE_DESERIALIZE_FREEONCLOSE flag is set,
|
||||
** in which case we own the pData pointer and need to free it.
|
||||
** Free the underlying MemStore object when its refcount drops to zero
|
||||
** or less.
|
||||
*/
|
||||
static int memdbClose(sqlite3_file *pFile){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ){
|
||||
sqlite3_free(p->aData);
|
||||
MemStore *p = ((MemFile*)pFile)->pStore;
|
||||
if( p->zFName ){
|
||||
int i;
|
||||
#ifndef SQLITE_MUTEX_OMIT
|
||||
sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
|
||||
#endif
|
||||
sqlite3_mutex_enter(pVfsMutex);
|
||||
for(i=0; ALWAYS(i<memdb_g.nMemStore); i++){
|
||||
if( memdb_g.apMemStore[i]==p ){
|
||||
memdbEnter(p);
|
||||
if( p->nRef==1 ){
|
||||
memdb_g.apMemStore[i] = memdb_g.apMemStore[--memdb_g.nMemStore];
|
||||
if( memdb_g.nMemStore==0 ){
|
||||
sqlite3_free(memdb_g.apMemStore);
|
||||
memdb_g.apMemStore = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
sqlite3_mutex_leave(pVfsMutex);
|
||||
}else{
|
||||
memdbEnter(p);
|
||||
}
|
||||
p->nRef--;
|
||||
if( p->nRef<=0 ){
|
||||
if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ){
|
||||
sqlite3_free(p->aData);
|
||||
}
|
||||
memdbLeave(p);
|
||||
sqlite3_mutex_free(p->pMutex);
|
||||
sqlite3_free(p);
|
||||
}else{
|
||||
memdbLeave(p);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -146,20 +254,23 @@ static int memdbRead(
|
||||
int iAmt,
|
||||
sqlite_int64 iOfst
|
||||
){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
MemStore *p = ((MemFile*)pFile)->pStore;
|
||||
memdbEnter(p);
|
||||
if( iOfst+iAmt>p->sz ){
|
||||
memset(zBuf, 0, iAmt);
|
||||
if( iOfst<p->sz ) memcpy(zBuf, p->aData+iOfst, p->sz - iOfst);
|
||||
memdbLeave(p);
|
||||
return SQLITE_IOERR_SHORT_READ;
|
||||
}
|
||||
memcpy(zBuf, p->aData+iOfst, iAmt);
|
||||
memdbLeave(p);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Try to enlarge the memory allocation to hold at least sz bytes
|
||||
*/
|
||||
static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
|
||||
static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){
|
||||
unsigned char *pNew;
|
||||
if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
|
||||
return SQLITE_FULL;
|
||||
@@ -170,7 +281,7 @@ static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
|
||||
newSz *= 2;
|
||||
if( newSz>p->szMax ) newSz = p->szMax;
|
||||
pNew = sqlite3Realloc(p->aData, newSz);
|
||||
if( pNew==0 ) return SQLITE_NOMEM;
|
||||
if( pNew==0 ) return SQLITE_IOERR_NOMEM;
|
||||
p->aData = pNew;
|
||||
p->szAlloc = newSz;
|
||||
return SQLITE_OK;
|
||||
@@ -185,19 +296,27 @@ static int memdbWrite(
|
||||
int iAmt,
|
||||
sqlite_int64 iOfst
|
||||
){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ) return SQLITE_READONLY;
|
||||
MemStore *p = ((MemFile*)pFile)->pStore;
|
||||
memdbEnter(p);
|
||||
if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ){
|
||||
/* Can't happen: memdbLock() will return SQLITE_READONLY before
|
||||
** reaching this point */
|
||||
memdbLeave(p);
|
||||
return SQLITE_IOERR_WRITE;
|
||||
}
|
||||
if( iOfst+iAmt>p->sz ){
|
||||
int rc;
|
||||
if( iOfst+iAmt>p->szAlloc
|
||||
&& (rc = memdbEnlarge(p, iOfst+iAmt))!=SQLITE_OK
|
||||
){
|
||||
memdbLeave(p);
|
||||
return rc;
|
||||
}
|
||||
if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
|
||||
p->sz = iOfst+iAmt;
|
||||
}
|
||||
memcpy(p->aData+iOfst, z, iAmt);
|
||||
memdbLeave(p);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -209,16 +328,24 @@ static int memdbWrite(
|
||||
** the size of a file, never to increase the size.
|
||||
*/
|
||||
static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
if( NEVER(size>p->sz) ) return SQLITE_FULL;
|
||||
p->sz = size;
|
||||
return SQLITE_OK;
|
||||
MemStore *p = ((MemFile*)pFile)->pStore;
|
||||
int rc = SQLITE_OK;
|
||||
memdbEnter(p);
|
||||
if( NEVER(size>p->sz) ){
|
||||
rc = SQLITE_FULL;
|
||||
}else{
|
||||
p->sz = size;
|
||||
}
|
||||
memdbLeave(p);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sync an memdb-file.
|
||||
*/
|
||||
static int memdbSync(sqlite3_file *pFile, int flags){
|
||||
UNUSED_PARAMETER(pFile);
|
||||
UNUSED_PARAMETER(flags);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -226,8 +353,10 @@ static int memdbSync(sqlite3_file *pFile, int flags){
|
||||
** Return the current file-size of an memdb-file.
|
||||
*/
|
||||
static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
MemStore *p = ((MemFile*)pFile)->pStore;
|
||||
memdbEnter(p);
|
||||
*pSize = p->sz;
|
||||
memdbLeave(p);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -235,19 +364,48 @@ static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
|
||||
** Lock an memdb-file.
|
||||
*/
|
||||
static int memdbLock(sqlite3_file *pFile, int eLock){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
if( eLock>SQLITE_LOCK_SHARED
|
||||
&& (p->mFlags & SQLITE_DESERIALIZE_READONLY)!=0
|
||||
){
|
||||
return SQLITE_READONLY;
|
||||
MemFile *pThis = (MemFile*)pFile;
|
||||
MemStore *p = pThis->pStore;
|
||||
int rc = SQLITE_OK;
|
||||
if( eLock==pThis->eLock ) return SQLITE_OK;
|
||||
memdbEnter(p);
|
||||
if( eLock>SQLITE_LOCK_SHARED ){
|
||||
if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
|
||||
rc = SQLITE_READONLY;
|
||||
}else if( pThis->eLock<=SQLITE_LOCK_SHARED ){
|
||||
if( p->nWrLock ){
|
||||
rc = SQLITE_BUSY;
|
||||
}else{
|
||||
p->nWrLock = 1;
|
||||
}
|
||||
}
|
||||
}else if( eLock==SQLITE_LOCK_SHARED ){
|
||||
if( pThis->eLock > SQLITE_LOCK_SHARED ){
|
||||
assert( p->nWrLock==1 );
|
||||
p->nWrLock = 0;
|
||||
}else if( p->nWrLock ){
|
||||
rc = SQLITE_BUSY;
|
||||
}else{
|
||||
p->nRdLock++;
|
||||
}
|
||||
}else{
|
||||
assert( eLock==SQLITE_LOCK_NONE );
|
||||
if( pThis->eLock>SQLITE_LOCK_SHARED ){
|
||||
assert( p->nWrLock==1 );
|
||||
p->nWrLock = 0;
|
||||
}
|
||||
assert( p->nRdLock>0 );
|
||||
p->nRdLock--;
|
||||
}
|
||||
p->eLock = eLock;
|
||||
return SQLITE_OK;
|
||||
if( rc==SQLITE_OK ) pThis->eLock = eLock;
|
||||
memdbLeave(p);
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if 0 /* Never used because memdbAccess() always returns false */
|
||||
#if 0
|
||||
/*
|
||||
** Check if another file-handle holds a RESERVED lock on an memdb-file.
|
||||
** This interface is only used for crash recovery, which does not
|
||||
** occur on an in-memory database.
|
||||
*/
|
||||
static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){
|
||||
*pResOut = 0;
|
||||
@@ -255,12 +413,14 @@ static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** File control method. For custom operations on an memdb-file.
|
||||
*/
|
||||
static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
MemStore *p = ((MemFile*)pFile)->pStore;
|
||||
int rc = SQLITE_NOTFOUND;
|
||||
memdbEnter(p);
|
||||
if( op==SQLITE_FCNTL_VFSNAME ){
|
||||
*(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz);
|
||||
rc = SQLITE_OK;
|
||||
@@ -278,6 +438,7 @@ static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
|
||||
*(sqlite3_int64*)pArg = iLimit;
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
memdbLeave(p);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -294,6 +455,7 @@ static int memdbSectorSize(sqlite3_file *pFile){
|
||||
** Return the device characteristic flags supported by an memdb-file.
|
||||
*/
|
||||
static int memdbDeviceCharacteristics(sqlite3_file *pFile){
|
||||
UNUSED_PARAMETER(pFile);
|
||||
return SQLITE_IOCAP_ATOMIC |
|
||||
SQLITE_IOCAP_POWERSAFE_OVERWRITE |
|
||||
SQLITE_IOCAP_SAFE_APPEND |
|
||||
@@ -307,20 +469,26 @@ static int memdbFetch(
|
||||
int iAmt,
|
||||
void **pp
|
||||
){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
MemStore *p = ((MemFile*)pFile)->pStore;
|
||||
memdbEnter(p);
|
||||
if( iOfst+iAmt>p->sz ){
|
||||
*pp = 0;
|
||||
}else{
|
||||
p->nMmap++;
|
||||
*pp = (void*)(p->aData + iOfst);
|
||||
}
|
||||
memdbLeave(p);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* Release a memory-mapped page */
|
||||
static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
|
||||
MemFile *p = (MemFile *)pFile;
|
||||
MemStore *p = ((MemFile*)pFile)->pStore;
|
||||
UNUSED_PARAMETER(iOfst);
|
||||
UNUSED_PARAMETER(pPage);
|
||||
memdbEnter(p);
|
||||
p->nMmap--;
|
||||
memdbLeave(p);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -330,20 +498,79 @@ static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
|
||||
static int memdbOpen(
|
||||
sqlite3_vfs *pVfs,
|
||||
const char *zName,
|
||||
sqlite3_file *pFile,
|
||||
sqlite3_file *pFd,
|
||||
int flags,
|
||||
int *pOutFlags
|
||||
){
|
||||
MemFile *p = (MemFile*)pFile;
|
||||
MemFile *pFile = (MemFile*)pFd;
|
||||
MemStore *p = 0;
|
||||
int szName;
|
||||
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
|
||||
return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags, pOutFlags);
|
||||
return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags);
|
||||
}
|
||||
memset(p, 0, sizeof(*p));
|
||||
p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
|
||||
memset(pFile, 0, sizeof(*p));
|
||||
szName = sqlite3Strlen30(zName);
|
||||
if( szName>1 && zName[0]=='/' ){
|
||||
int i;
|
||||
#ifndef SQLITE_MUTEX_OMIT
|
||||
sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
|
||||
#endif
|
||||
sqlite3_mutex_enter(pVfsMutex);
|
||||
for(i=0; i<memdb_g.nMemStore; i++){
|
||||
if( strcmp(memdb_g.apMemStore[i]->zFName,zName)==0 ){
|
||||
p = memdb_g.apMemStore[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( p==0 ){
|
||||
MemStore **apNew;
|
||||
p = sqlite3Malloc( sizeof(*p) + szName + 3 );
|
||||
if( p==0 ){
|
||||
sqlite3_mutex_leave(pVfsMutex);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
apNew = sqlite3Realloc(memdb_g.apMemStore,
|
||||
sizeof(apNew[0])*(memdb_g.nMemStore+1) );
|
||||
if( apNew==0 ){
|
||||
sqlite3_free(p);
|
||||
sqlite3_mutex_leave(pVfsMutex);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
apNew[memdb_g.nMemStore++] = p;
|
||||
memdb_g.apMemStore = apNew;
|
||||
memset(p, 0, sizeof(*p));
|
||||
p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE|SQLITE_DESERIALIZE_FREEONCLOSE;
|
||||
p->szMax = sqlite3GlobalConfig.mxMemdbSize;
|
||||
p->zFName = (char*)&p[1];
|
||||
memcpy(p->zFName, zName, szName+1);
|
||||
p->pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
|
||||
if( p->pMutex==0 ){
|
||||
memdb_g.nMemStore--;
|
||||
sqlite3_free(p);
|
||||
sqlite3_mutex_leave(pVfsMutex);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
p->nRef = 1;
|
||||
memdbEnter(p);
|
||||
}else{
|
||||
memdbEnter(p);
|
||||
p->nRef++;
|
||||
}
|
||||
sqlite3_mutex_leave(pVfsMutex);
|
||||
}else{
|
||||
p = sqlite3Malloc( sizeof(*p) );
|
||||
if( p==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
memset(p, 0, sizeof(*p));
|
||||
p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
|
||||
p->szMax = sqlite3GlobalConfig.mxMemdbSize;
|
||||
}
|
||||
pFile->pStore = p;
|
||||
assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
|
||||
*pOutFlags = flags | SQLITE_OPEN_MEMORY;
|
||||
pFile->pMethods = &memdb_io_methods;
|
||||
p->szMax = sqlite3GlobalConfig.mxMemdbSize;
|
||||
pFd->pMethods = &memdb_io_methods;
|
||||
memdbLeave(p);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -371,6 +598,9 @@ static int memdbAccess(
|
||||
int flags,
|
||||
int *pResOut
|
||||
){
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
UNUSED_PARAMETER(zPath);
|
||||
UNUSED_PARAMETER(flags);
|
||||
*pResOut = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -386,6 +616,7 @@ static int memdbFullPathname(
|
||||
int nOut,
|
||||
char *zOut
|
||||
){
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
sqlite3_snprintf(nOut, zOut, "%s", zPath);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -458,9 +689,14 @@ static int memdbCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){
|
||||
*/
|
||||
static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){
|
||||
MemFile *p = 0;
|
||||
MemStore *pStore;
|
||||
int rc = sqlite3_file_control(db, zSchema, SQLITE_FCNTL_FILE_POINTER, &p);
|
||||
if( rc ) return 0;
|
||||
if( p->base.pMethods!=&memdb_io_methods ) return 0;
|
||||
pStore = p->pStore;
|
||||
memdbEnter(pStore);
|
||||
if( pStore->zFName!=0 ) p = 0;
|
||||
memdbLeave(pStore);
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -496,12 +732,14 @@ unsigned char *sqlite3_serialize(
|
||||
if( piSize ) *piSize = -1;
|
||||
if( iDb<0 ) return 0;
|
||||
if( p ){
|
||||
if( piSize ) *piSize = p->sz;
|
||||
MemStore *pStore = p->pStore;
|
||||
assert( pStore->pMutex==0 );
|
||||
if( piSize ) *piSize = pStore->sz;
|
||||
if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
|
||||
pOut = p->aData;
|
||||
pOut = pStore->aData;
|
||||
}else{
|
||||
pOut = sqlite3_malloc64( p->sz );
|
||||
if( pOut ) memcpy(pOut, p->aData, p->sz);
|
||||
pOut = sqlite3_malloc64( pStore->sz );
|
||||
if( pOut ) memcpy(pOut, pStore->aData, pStore->sz);
|
||||
}
|
||||
return pOut;
|
||||
}
|
||||
@@ -571,10 +809,11 @@ int sqlite3_deserialize(
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
|
||||
iDb = sqlite3FindDbName(db, zSchema);
|
||||
if( iDb<0 ){
|
||||
testcase( iDb==1 );
|
||||
if( iDb<2 && iDb!=0 ){
|
||||
rc = SQLITE_ERROR;
|
||||
goto end_deserialize;
|
||||
}
|
||||
}
|
||||
zSql = sqlite3_mprintf("ATTACH x AS %Q", zSchema);
|
||||
if( zSql==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
@@ -595,15 +834,16 @@ int sqlite3_deserialize(
|
||||
if( p==0 ){
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
p->aData = pData;
|
||||
MemStore *pStore = p->pStore;
|
||||
pStore->aData = pData;
|
||||
pData = 0;
|
||||
p->sz = szDb;
|
||||
p->szAlloc = szBuf;
|
||||
p->szMax = szBuf;
|
||||
if( p->szMax<sqlite3GlobalConfig.mxMemdbSize ){
|
||||
p->szMax = sqlite3GlobalConfig.mxMemdbSize;
|
||||
pStore->sz = szDb;
|
||||
pStore->szAlloc = szBuf;
|
||||
pStore->szMax = szBuf;
|
||||
if( pStore->szMax<sqlite3GlobalConfig.mxMemdbSize ){
|
||||
pStore->szMax = sqlite3GlobalConfig.mxMemdbSize;
|
||||
}
|
||||
p->mFlags = mFlags;
|
||||
pStore->mFlags = mFlags;
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -622,7 +862,9 @@ end_deserialize:
|
||||
*/
|
||||
int sqlite3MemdbInit(void){
|
||||
sqlite3_vfs *pLower = sqlite3_vfs_find(0);
|
||||
int sz = pLower->szOsFile;
|
||||
unsigned int sz;
|
||||
if( NEVER(pLower==0) ) return SQLITE_ERROR;
|
||||
sz = pLower->szOsFile;
|
||||
memdb_vfs.pAppData = pLower;
|
||||
/* The following conditional can only be true when compiled for
|
||||
** Windows x86 and SQLITE_MAX_MMAP_SIZE=0. We always leave
|
||||
@@ -632,4 +874,4 @@ int sqlite3MemdbInit(void){
|
||||
memdb_vfs.szOsFile = sz;
|
||||
return sqlite3_vfs_register(&memdb_vfs, 0);
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_DESERIALIZE */
|
||||
#endif /* SQLITE_OMIT_DESERIALIZE */
|
||||
|
||||
+24
-17
@@ -70,7 +70,6 @@ struct MemJournal {
|
||||
int nChunkSize; /* In-memory chunk-size */
|
||||
|
||||
int nSpill; /* Bytes of data before flushing */
|
||||
int nSize; /* Bytes of data currently in memory */
|
||||
FileChunk *pFirst; /* Head of in-memory chunk-list */
|
||||
FilePoint endpoint; /* Pointer to the end of the file */
|
||||
FilePoint readpoint; /* Pointer to the end of the last xRead() */
|
||||
@@ -131,14 +130,13 @@ static int memjrnlRead(
|
||||
/*
|
||||
** Free the list of FileChunk structures headed at MemJournal.pFirst.
|
||||
*/
|
||||
static void memjrnlFreeChunks(MemJournal *p){
|
||||
static void memjrnlFreeChunks(FileChunk *pFirst){
|
||||
FileChunk *pIter;
|
||||
FileChunk *pNext;
|
||||
for(pIter=p->pFirst; pIter; pIter=pNext){
|
||||
for(pIter=pFirst; pIter; pIter=pNext){
|
||||
pNext = pIter->pNext;
|
||||
sqlite3_free(pIter);
|
||||
}
|
||||
p->pFirst = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -165,7 +163,7 @@ static int memjrnlCreateFile(MemJournal *p){
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
/* No error has occurred. Free the in-memory buffers. */
|
||||
memjrnlFreeChunks(©);
|
||||
memjrnlFreeChunks(copy.pFirst);
|
||||
}
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
@@ -248,7 +246,6 @@ static int memjrnlWrite(
|
||||
nWrite -= iSpace;
|
||||
p->endpoint.iOffset += iSpace;
|
||||
}
|
||||
p->nSize = iAmt + iOfst;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,19 +253,29 @@ static int memjrnlWrite(
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate the file.
|
||||
**
|
||||
** If the journal file is already on disk, truncate it there. Or, if it
|
||||
** is still in main memory but is being truncated to zero bytes in size,
|
||||
** ignore
|
||||
** Truncate the in-memory file.
|
||||
*/
|
||||
static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){
|
||||
MemJournal *p = (MemJournal *)pJfd;
|
||||
if( ALWAYS(size==0) ){
|
||||
memjrnlFreeChunks(p);
|
||||
p->nSize = 0;
|
||||
p->endpoint.pChunk = 0;
|
||||
p->endpoint.iOffset = 0;
|
||||
assert( p->endpoint.pChunk==0 || p->endpoint.pChunk->pNext==0 );
|
||||
if( size<p->endpoint.iOffset ){
|
||||
FileChunk *pIter = 0;
|
||||
if( size==0 ){
|
||||
memjrnlFreeChunks(p->pFirst);
|
||||
p->pFirst = 0;
|
||||
}else{
|
||||
i64 iOff = p->nChunkSize;
|
||||
for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){
|
||||
iOff += p->nChunkSize;
|
||||
}
|
||||
if( ALWAYS(pIter) ){
|
||||
memjrnlFreeChunks(pIter->pNext);
|
||||
pIter->pNext = 0;
|
||||
}
|
||||
}
|
||||
|
||||
p->endpoint.pChunk = pIter;
|
||||
p->endpoint.iOffset = size;
|
||||
p->readpoint.pChunk = 0;
|
||||
p->readpoint.iOffset = 0;
|
||||
}
|
||||
@@ -280,7 +287,7 @@ static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){
|
||||
*/
|
||||
static int memjrnlClose(sqlite3_file *pJfd){
|
||||
MemJournal *p = (MemJournal *)pJfd;
|
||||
memjrnlFreeChunks(p);
|
||||
memjrnlFreeChunks(p->pFirst);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ int sqlite3OsOpen(
|
||||
int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
|
||||
DO_OS_MALLOC_TEST(0);
|
||||
assert( dirSync==0 || dirSync==1 );
|
||||
return pVfs->xDelete(pVfs, zPath, dirSync);
|
||||
return pVfs->xDelete!=0 ? pVfs->xDelete(pVfs, zPath, dirSync) : SQLITE_OK;
|
||||
}
|
||||
int sqlite3OsAccess(
|
||||
sqlite3_vfs *pVfs,
|
||||
@@ -252,6 +252,8 @@ int sqlite3OsFullPathname(
|
||||
}
|
||||
#ifndef SQLITE_OMIT_LOAD_EXTENSION
|
||||
void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
|
||||
assert( zPath!=0 );
|
||||
assert( strlen(zPath)<=SQLITE_MAX_PATHLEN ); /* tag-20210611-1 */
|
||||
return pVfs->xDlOpen(pVfs, zPath);
|
||||
}
|
||||
void sqlite3OsDlError(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
|
||||
|
||||
@@ -33,6 +33,12 @@
|
||||
# define SET_FULLSYNC(x,y)
|
||||
#endif
|
||||
|
||||
/* Maximum pathname length. Note: FILENAME_MAX defined by stdio.h
|
||||
*/
|
||||
#ifndef SQLITE_MAX_PATHLEN
|
||||
# define SQLITE_MAX_PATHLEN FILENAME_MAX
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The default size of a disk sector
|
||||
*/
|
||||
|
||||
+62
-1
@@ -3951,6 +3951,7 @@ static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){
|
||||
|
||||
/* Forward declaration */
|
||||
static int unixGetTempname(int nBuf, char *zBuf);
|
||||
static int unixFcntlExternalReader(unixFile*, int*);
|
||||
|
||||
/*
|
||||
** Information and control of an open file handle.
|
||||
@@ -4067,6 +4068,10 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
|
||||
return proxyFileControl(id,op,pArg);
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
|
||||
|
||||
case SQLITE_FCNTL_EXTERNAL_READER: {
|
||||
return unixFcntlExternalReader((unixFile*)id, (int*)pArg);
|
||||
}
|
||||
}
|
||||
return SQLITE_NOTFOUND;
|
||||
}
|
||||
@@ -4312,6 +4317,40 @@ struct unixShm {
|
||||
#define UNIX_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */
|
||||
#define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */
|
||||
|
||||
/*
|
||||
** Use F_GETLK to check whether or not there are any readers with open
|
||||
** wal-mode transactions in other processes on database file pFile. If
|
||||
** no error occurs, return SQLITE_OK and set (*piOut) to 1 if there are
|
||||
** such transactions, or 0 otherwise. If an error occurs, return an
|
||||
** SQLite error code. The final value of *piOut is undefined in this
|
||||
** case.
|
||||
*/
|
||||
static int unixFcntlExternalReader(unixFile *pFile, int *piOut){
|
||||
int rc = SQLITE_OK;
|
||||
*piOut = 0;
|
||||
if( pFile->pShm){
|
||||
unixShmNode *pShmNode = pFile->pShm->pShmNode;
|
||||
struct flock f;
|
||||
|
||||
memset(&f, 0, sizeof(f));
|
||||
f.l_type = F_WRLCK;
|
||||
f.l_whence = SEEK_SET;
|
||||
f.l_start = UNIX_SHM_BASE + 3;
|
||||
f.l_len = SQLITE_SHM_NLOCK - 3;
|
||||
|
||||
sqlite3_mutex_enter(pShmNode->pShmMutex);
|
||||
if( osFcntl(pShmNode->hShm, F_GETLK, &f)<0 ){
|
||||
rc = SQLITE_IOERR_LOCK;
|
||||
}else{
|
||||
*piOut = (f.l_type!=F_UNLCK);
|
||||
}
|
||||
sqlite3_mutex_leave(pShmNode->pShmMutex);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Apply posix advisory locks for all bytes from ofst through ofst+n-1.
|
||||
**
|
||||
@@ -6146,6 +6185,8 @@ static int unixOpen(
|
||||
/* If unable to create a journal because the directory is not
|
||||
** writable, change the error code to indicate that. */
|
||||
rc = SQLITE_READONLY_DIRECTORY;
|
||||
}else if( errno==EEXIST ){
|
||||
rc = SQLITE_CANTOPEN_EXISTS;
|
||||
}else if( errno!=EISDIR && isReadWrite ){
|
||||
/* Failed to open the file for read/write access. Try read-only. */
|
||||
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
|
||||
@@ -6361,7 +6402,8 @@ static int unixBackupDir(const char *z, int *pJ){
|
||||
int j = *pJ;
|
||||
int i;
|
||||
if( j<=0 ) return 0;
|
||||
for(i=j-1; ALWAYS(i>0) && z[i-1]!='/'; i--){}
|
||||
for(i=j-1; i>0 && z[i-1]!='/'; i--){}
|
||||
if( i==0 ) return 0;
|
||||
if( z[i]=='.' && i==j-2 && z[i+1]=='.' ) return 0;
|
||||
*pJ = i-1;
|
||||
return 1;
|
||||
@@ -8027,6 +8069,25 @@ int sqlite3_os_init(void){
|
||||
sqlite3_vfs_register(&aVfs[i], i==0);
|
||||
}
|
||||
unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
|
||||
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
/* Validate lock assumptions */
|
||||
assert( SQLITE_SHM_NLOCK==8 ); /* Number of available locks */
|
||||
assert( UNIX_SHM_BASE==120 ); /* Start of locking area */
|
||||
/* Locks:
|
||||
** WRITE UNIX_SHM_BASE 120
|
||||
** CKPT UNIX_SHM_BASE+1 121
|
||||
** RECOVER UNIX_SHM_BASE+2 122
|
||||
** READ-0 UNIX_SHM_BASE+3 123
|
||||
** READ-1 UNIX_SHM_BASE+4 124
|
||||
** READ-2 UNIX_SHM_BASE+5 125
|
||||
** READ-3 UNIX_SHM_BASE+6 126
|
||||
** READ-4 UNIX_SHM_BASE+7 127
|
||||
** DMS UNIX_SHM_BASE+8 128
|
||||
*/
|
||||
assert( UNIX_SHM_DMS==128 ); /* Byte offset of the deadman-switch */
|
||||
#endif
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
+210
-28
@@ -272,6 +272,7 @@ struct winFile {
|
||||
winShm *pShm; /* Instance of shared memory on this file */
|
||||
#endif
|
||||
const char *zPath; /* Full pathname of this file */
|
||||
unsigned iBusyTimeout; /* Wait this many millisec on locks */
|
||||
int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */
|
||||
#if SQLITE_OS_WINCE
|
||||
LPWSTR zDeleteOnClose; /* Name of file to delete when closing */
|
||||
@@ -1126,7 +1127,7 @@ static struct win_syscall {
|
||||
{ "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
|
||||
|
||||
#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \
|
||||
SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[76].pCurrent)
|
||||
SQLITE_WIN32_VOLATILE*,LONG,LONG))aSyscall[76].pCurrent)
|
||||
#endif /* defined(InterlockedCompareExchange) */
|
||||
|
||||
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
|
||||
@@ -1155,6 +1156,23 @@ static struct win_syscall {
|
||||
#define osFlushViewOfFile \
|
||||
((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
{ "GetFileInformationByHandle", (SYSCALL)GetFileInformationByHandle, 0 },
|
||||
#else
|
||||
{ "GetFileInformationByHandle", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osGetFileInformationByHandle ((BOOL(WINAPI*)(HANDLE, \
|
||||
LPBY_HANDLE_FILE_INFORMATION))aSyscall[80].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
{ "SleepEx", (SYSCALL)SleepEx, 0 },
|
||||
#else
|
||||
{ "SleepEx", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osSleepEx ((VOID(WINAPI*)(DWORD,BOOL))aSyscall[81].pCurrent)
|
||||
|
||||
}; /* End of the overrideable system calls */
|
||||
|
||||
/*
|
||||
@@ -1379,18 +1397,25 @@ void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
|
||||
static HANDLE sleepObj = NULL;
|
||||
#endif
|
||||
|
||||
void sqlite3_win32_sleep(DWORD milliseconds){
|
||||
void sqlite3Win32Sleep(DWORD milliseconds, BOOL alertable){
|
||||
#if SQLITE_OS_WINRT
|
||||
if ( sleepObj==NULL ){
|
||||
sleepObj = osCreateEventExW(NULL, NULL, CREATE_EVENT_MANUAL_RESET,
|
||||
SYNCHRONIZE);
|
||||
}
|
||||
assert( sleepObj!=NULL );
|
||||
osWaitForSingleObjectEx(sleepObj, milliseconds, FALSE);
|
||||
osWaitForSingleObjectEx(sleepObj, milliseconds, alertable);
|
||||
#else
|
||||
osSleep(milliseconds);
|
||||
if( alertable ){
|
||||
osSleepEx(milliseconds, alertable);
|
||||
}else{
|
||||
osSleep(milliseconds);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void sqlite3_win32_sleep(DWORD milliseconds){
|
||||
sqlite3Win32Sleep(milliseconds, FALSE);
|
||||
}
|
||||
|
||||
#if SQLITE_MAX_WORKER_THREADS>0 && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
|
||||
SQLITE_THREADSAFE>0
|
||||
@@ -2154,13 +2179,13 @@ static int winRetryIoerr(int *pnRetry, DWORD *pError){
|
||||
return 0;
|
||||
}
|
||||
if( winIoerrCanRetry1(e) ){
|
||||
sqlite3_win32_sleep(winIoerrRetryDelay*(1+*pnRetry));
|
||||
sqlite3Win32Sleep(winIoerrRetryDelay*(1+*pnRetry), TRUE);
|
||||
++*pnRetry;
|
||||
return 1;
|
||||
}
|
||||
#if defined(winIoerrCanRetry2)
|
||||
else if( winIoerrCanRetry2(e) ){
|
||||
sqlite3_win32_sleep(winIoerrRetryDelay*(1+*pnRetry));
|
||||
sqlite3Win32Sleep(winIoerrRetryDelay*(1+*pnRetry), TRUE);
|
||||
++*pnRetry;
|
||||
return 1;
|
||||
}
|
||||
@@ -2503,9 +2528,13 @@ static BOOL winceUnlockFile(
|
||||
|
||||
/*
|
||||
** Lock a file region.
|
||||
**
|
||||
** If the pFile->iBusyTimeout value is non-zero and the lock cannot be
|
||||
** acquired immediately, then try to block for up to iBusyTimeout milliseconds
|
||||
** waiting on the conflicting lock to appear.
|
||||
*/
|
||||
static BOOL winLockFile(
|
||||
LPHANDLE phFile,
|
||||
winFile *pFile,
|
||||
DWORD flags,
|
||||
DWORD offsetLow,
|
||||
DWORD offsetHigh,
|
||||
@@ -2517,17 +2546,31 @@ static BOOL winLockFile(
|
||||
** NOTE: Windows CE is handled differently here due its lack of the Win32
|
||||
** API LockFile.
|
||||
*/
|
||||
return winceLockFile(phFile, offsetLow, offsetHigh,
|
||||
return winceLockFile(&pFile->h, offsetLow, offsetHigh,
|
||||
numBytesLow, numBytesHigh);
|
||||
#else
|
||||
if( osIsNT() ){
|
||||
BOOL bResult;
|
||||
OVERLAPPED ovlp;
|
||||
memset(&ovlp, 0, sizeof(OVERLAPPED));
|
||||
ovlp.Offset = offsetLow;
|
||||
ovlp.OffsetHigh = offsetHigh;
|
||||
return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
|
||||
bResult = osLockFileEx(pFile->h, flags, 0, numBytesLow,
|
||||
numBytesHigh, &ovlp);
|
||||
if( !bResult && pFile->iBusyTimeout>0 ){
|
||||
unsigned iDelay = (unsigned)winIoerrRetryDelay;
|
||||
if( iDelay>0 ){
|
||||
u64 iTotalDelay = 0;
|
||||
do{
|
||||
sqlite3Win32Sleep(iDelay, TRUE); iTotalDelay += iDelay;
|
||||
bResult = osLockFileEx(pFile->h, flags, 0, numBytesLow,
|
||||
numBytesHigh, &ovlp);
|
||||
}while( !bResult && iTotalDelay<pFile->iBusyTimeout );
|
||||
}
|
||||
}
|
||||
return bResult;
|
||||
}else{
|
||||
return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
|
||||
return osLockFile(pFile->h, offsetLow, offsetHigh, numBytesLow,
|
||||
numBytesHigh);
|
||||
}
|
||||
#endif
|
||||
@@ -2673,7 +2716,7 @@ static int winClose(sqlite3_file *id){
|
||||
do{
|
||||
rc = osCloseHandle(pFile->h);
|
||||
/* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
|
||||
}while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
|
||||
}while( rc==0 && ++cnt<MX_CLOSE_ATTEMPT && (sqlite3Win32Sleep(100,TRUE), 1) );
|
||||
#if SQLITE_OS_WINCE
|
||||
#define WINCE_DELETION_ATTEMPTS 3
|
||||
{
|
||||
@@ -2689,7 +2732,7 @@ static int winClose(sqlite3_file *id){
|
||||
&& osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
|
||||
&& cnt++ < WINCE_DELETION_ATTEMPTS
|
||||
){
|
||||
sqlite3_win32_sleep(100); /* Wait a little before trying again */
|
||||
sqlite3Win32Sleep(100, TRUE); /* Wait a little before trying again */
|
||||
}
|
||||
sqlite3_free(pFile->zDeleteOnClose);
|
||||
}
|
||||
@@ -3162,7 +3205,7 @@ static int winGetReadLock(winFile *pFile){
|
||||
*/
|
||||
res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
|
||||
#else
|
||||
res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
|
||||
res = winLockFile(pFile, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
|
||||
SHARED_SIZE, 0);
|
||||
#endif
|
||||
}
|
||||
@@ -3171,7 +3214,7 @@ static int winGetReadLock(winFile *pFile){
|
||||
int lk;
|
||||
sqlite3_randomness(sizeof(lk), &lk);
|
||||
pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
|
||||
res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
|
||||
res = winLockFile(pFile, SQLITE_LOCKFILE_FLAGS,
|
||||
SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
|
||||
}
|
||||
#endif
|
||||
@@ -3275,7 +3318,7 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
|| (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK)
|
||||
){
|
||||
int cnt = 3;
|
||||
while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
|
||||
while( cnt-->0 && (res = winLockFile(pFile, SQLITE_LOCKFILE_FLAGS,
|
||||
PENDING_BYTE, 0, 1, 0))==0 ){
|
||||
/* Try 3 times to get the pending lock. This is needed to work
|
||||
** around problems caused by indexing and/or anti-virus software on
|
||||
@@ -3293,7 +3336,7 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
pFile->h, cnt, sqlite3ErrName(rc)));
|
||||
return rc;
|
||||
}
|
||||
if( cnt ) sqlite3_win32_sleep(1);
|
||||
if( cnt ) sqlite3Win32Sleep(1, TRUE);
|
||||
}
|
||||
gotPendingLock = res;
|
||||
if( !res ){
|
||||
@@ -3317,7 +3360,7 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
*/
|
||||
if( locktype==RESERVED_LOCK && res ){
|
||||
assert( pFile->locktype==SHARED_LOCK );
|
||||
res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
|
||||
res = winLockFile(pFile, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
|
||||
if( res ){
|
||||
newLocktype = RESERVED_LOCK;
|
||||
}else{
|
||||
@@ -3337,7 +3380,7 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
if( locktype==EXCLUSIVE_LOCK && res ){
|
||||
assert( pFile->locktype>=SHARED_LOCK );
|
||||
res = winUnlockReadLock(pFile);
|
||||
res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
|
||||
res = winLockFile(pFile, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
|
||||
SHARED_SIZE, 0);
|
||||
if( res ){
|
||||
newLocktype = EXCLUSIVE_LOCK;
|
||||
@@ -3388,7 +3431,7 @@ static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
|
||||
res = 1;
|
||||
OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res));
|
||||
}else{
|
||||
res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
|
||||
res = winLockFile(pFile, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
|
||||
if( res ){
|
||||
winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
|
||||
}
|
||||
@@ -3527,6 +3570,12 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
|
||||
OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
case SQLITE_FCNTL_LOCK_TIMEOUT: {
|
||||
int iOld = pFile->iBusyTimeout;
|
||||
pFile->iBusyTimeout = *(int*)pArg;
|
||||
*(int*)pArg = iOld;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
case SQLITE_FCNTL_SIZE_HINT: {
|
||||
if( pFile->szChunk>0 ){
|
||||
sqlite3_int64 oldSz;
|
||||
@@ -3804,7 +3853,7 @@ static int winShmSystemLock(
|
||||
/* Initialize the locking parameters */
|
||||
DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
|
||||
if( lockType == WINSHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
|
||||
rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
|
||||
rc = winLockFile(&pFile->hFile, dwFlags, ofst, 0, nByte, 0);
|
||||
}
|
||||
|
||||
if( rc!= 0 ){
|
||||
@@ -3824,6 +3873,135 @@ static int winShmSystemLock(
|
||||
/* Forward references to VFS methods */
|
||||
static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*);
|
||||
static int winDelete(sqlite3_vfs *,const char*,int);
|
||||
static int winFullPathname(sqlite3_vfs *,const char *,int,char *);
|
||||
static void *winConvertFromUtf8Filename(const char *);
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
/*
|
||||
** This function attempts to query the metadata information for the
|
||||
** specified file. Upon success, SQLITE_OK is returned; otherwise,
|
||||
** an appropriate error code is returned.
|
||||
*/
|
||||
|
||||
static int winGetFileInfo(
|
||||
const char *zFilename,
|
||||
winFile *pFile,
|
||||
LPBY_HANDLE_FILE_INFORMATION pFileInfo
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
HANDLE hFile = NULL;
|
||||
int lastError = 0;
|
||||
void *zConverted = winConvertFromUtf8Filename(zFilename);
|
||||
if( zConverted==0 ){
|
||||
lastError = osGetLastError();
|
||||
if( pFile ) pFile->lastErrno = lastError;
|
||||
return winLogError(SQLITE_IOERR_NOMEM, lastError,
|
||||
"winGetFileInfo1", zFilename);
|
||||
}
|
||||
if( osIsNT() ){
|
||||
hFile = osCreateFileW(
|
||||
(LPCWSTR)zConverted, GENERIC_READ,
|
||||
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
|
||||
);
|
||||
#ifdef SQLITE_WIN32_HAS_ANSI
|
||||
}else{
|
||||
hFile = osCreateFileA(
|
||||
(LPCSTR)zConverted, GENERIC_READ,
|
||||
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
|
||||
);
|
||||
#endif
|
||||
}
|
||||
sqlite3_free(zConverted);
|
||||
if( hFile==INVALID_HANDLE_VALUE ){
|
||||
lastError = osGetLastError();
|
||||
if( pFile ) pFile->lastErrno = lastError;
|
||||
return winLogError(SQLITE_CANTOPEN, lastError,
|
||||
"winGetFileInfo2", zFilename);
|
||||
}
|
||||
if( !osGetFileInformationByHandle(hFile, pFileInfo) ){
|
||||
lastError = osGetLastError();
|
||||
if( pFile ) pFile->lastErrno = lastError;
|
||||
rc = winLogError(SQLITE_IOERR_FSTAT, lastError,
|
||||
"winGetFileInfo3", zFilename);
|
||||
}
|
||||
osCloseHandle(hFile);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Returns non-zero if both of the specified file names refer to the same
|
||||
** underlying file. On some sub-platforms, this function may return zero
|
||||
** even when both file names refer to the same underlying file; however,
|
||||
** it will never return non-zero unless both file names refer to the same
|
||||
** underlying file.
|
||||
*/
|
||||
|
||||
static int winIsSameFile(
|
||||
sqlite3_vfs *pVfs,
|
||||
winFile *pFile,
|
||||
const char *zFilename1,
|
||||
const char *zFilename2,
|
||||
BOOL *pbSame
|
||||
){
|
||||
*pbSame = 0; /* initially, assume not the same file */
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
{
|
||||
BY_HANDLE_FILE_INFORMATION info1;
|
||||
BY_HANDLE_FILE_INFORMATION info2;
|
||||
|
||||
if( !winGetFileInfo(zFilename1, pFile, &info1)
|
||||
|| !winGetFileInfo(zFilename2, pFile, &info2) ){
|
||||
/* wrong file system type? ok, use fallback. */
|
||||
goto fallback;
|
||||
}
|
||||
if( info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber
|
||||
&& info1.nFileIndexHigh == info2.nFileIndexHigh
|
||||
&& info1.nFileIndexLow == info2.nFileIndexLow ){
|
||||
OSTRACE(("SAME pid=%lu, pFile=%p, name1=%s, name2=%s, "
|
||||
"YES (ID), rc=SQLITE_OK\n", osGetCurrentProcessId(),
|
||||
pFile, zFilename1, zFilename2));
|
||||
*pbSame = 1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
fallback:
|
||||
{
|
||||
int rc = SQLITE_OK;
|
||||
int nFull = pVfs->mxPathname+1;
|
||||
char *zFull1 = NULL;
|
||||
char *zFull2 = NULL;
|
||||
|
||||
zFull1 = sqlite3MallocZero( nFull );
|
||||
if( zFull1==0 ){
|
||||
rc = SQLITE_IOERR_NOMEM_BKPT;
|
||||
goto done;
|
||||
}
|
||||
zFull2 = sqlite3MallocZero( nFull );
|
||||
if( zFull2==0 ){
|
||||
rc = SQLITE_IOERR_NOMEM_BKPT;
|
||||
goto done;
|
||||
}
|
||||
rc = winFullPathname(pVfs, zFilename1, nFull, zFull1);
|
||||
if( rc!=SQLITE_OK ) goto done;
|
||||
rc = winFullPathname(pVfs, zFilename2, nFull, zFull2);
|
||||
if( rc!=SQLITE_OK ) goto done;
|
||||
*pbSame = sqlite3StrICmp(zFull1, zFull2)==0;
|
||||
done:
|
||||
if( zFull2 ) sqlite3_free(zFull2);
|
||||
if( zFull1 ) sqlite3_free(zFull1);
|
||||
OSTRACE(("SAME pid=%lu, pFile=%p, name1=%s, name2=%s, "
|
||||
"%s (NAME), rc=%s\n", osGetCurrentProcessId(),
|
||||
pFile, zFilename1, zFilename2, *pbSame?"YES":"NO",
|
||||
sqlite3ErrName(rc)));
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Purge the winShmNodeList list of all entries with winShmNode.nRef==0.
|
||||
@@ -3940,10 +4118,13 @@ static int winOpenSharedMemory(winFile *pDbFd){
|
||||
*/
|
||||
winShmEnterMutex();
|
||||
for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){
|
||||
/* TBD need to come up with better match here. Perhaps
|
||||
** use FILE_ID_BOTH_DIR_INFO Structure.
|
||||
*/
|
||||
if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break;
|
||||
BOOL bSame;
|
||||
rc = winIsSameFile(
|
||||
pDbFd->pVfs, pDbFd, pShmNode->zFilename, pNew->zFilename,
|
||||
&bSame
|
||||
);
|
||||
if( rc!=SQLITE_OK ) goto shm_open_err;
|
||||
if( bSame ) break;
|
||||
}
|
||||
if( pShmNode ){
|
||||
sqlite3_free(pNew);
|
||||
@@ -4085,6 +4266,7 @@ static int winShmLock(
|
||||
mask = (u16)((1U<<(ofst+n)) - (1U<<ofst));
|
||||
assert( n>1 || mask==(1<<ofst) );
|
||||
sqlite3_mutex_enter(pShmNode->mutex);
|
||||
pShmNode->hFile.iBusyTimeout = pDbFd->iBusyTimeout;
|
||||
if( flags & SQLITE_SHM_UNLOCK ){
|
||||
u16 allMask = 0; /* Mask of locks held by siblings */
|
||||
|
||||
@@ -4990,7 +5172,7 @@ static int winOpen(
|
||||
int flags, /* Open mode flags */
|
||||
int *pOutFlags /* Status return flags */
|
||||
){
|
||||
HANDLE h;
|
||||
HANDLE h = INVALID_HANDLE_VALUE;
|
||||
DWORD lastErrno = 0;
|
||||
DWORD dwDesiredAccess;
|
||||
DWORD dwShareMode;
|
||||
@@ -5277,7 +5459,7 @@ static int winOpen(
|
||||
pFile->ctrlFlags |= WINFILE_RDONLY;
|
||||
}
|
||||
if( (flags & SQLITE_OPEN_MAIN_DB)
|
||||
&& sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE)
|
||||
&& sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE)
|
||||
){
|
||||
pFile->ctrlFlags |= WINFILE_PSOW;
|
||||
}
|
||||
@@ -5884,7 +6066,7 @@ static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
|
||||
** Sleep for a little while. Return the amount of time slept.
|
||||
*/
|
||||
static int winSleep(sqlite3_vfs *pVfs, int microsec){
|
||||
sqlite3_win32_sleep((microsec+999)/1000);
|
||||
sqlite3Win32Sleep((microsec+999)/1000, FALSE);
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
return ((microsec+999)/1000)*1000;
|
||||
}
|
||||
@@ -6105,7 +6287,7 @@ int sqlite3_os_init(void){
|
||||
|
||||
/* Double-check that the aSyscall[] array has been constructed
|
||||
** correctly. See ticket [bb3a86e890c8e96ab] */
|
||||
assert( ArraySize(aSyscall)==80 );
|
||||
assert( ArraySize(aSyscall)==82 );
|
||||
|
||||
/* get memory map allocation granularity */
|
||||
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
|
||||
|
||||
+15
-7
@@ -435,6 +435,7 @@ struct PagerSavepoint {
|
||||
Bitvec *pInSavepoint; /* Set of pages in this savepoint */
|
||||
Pgno nOrig; /* Original number of pages in file */
|
||||
Pgno iSubRec; /* Index of first record in sub-journal */
|
||||
int bTruncateOnRelease; /* If stmt journal may be truncated on RELEASE */
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
u32 aWalData[WAL_SAVEPOINT_NDATA]; /* WAL savepoint context */
|
||||
#endif
|
||||
@@ -1070,6 +1071,9 @@ static int subjRequiresPage(PgHdr *pPg){
|
||||
for(i=0; i<pPager->nSavepoint; i++){
|
||||
p = &pPager->aSavepoint[i];
|
||||
if( p->nOrig>=pgno && 0==sqlite3BitvecTestNotNull(p->pInSavepoint, pgno) ){
|
||||
for(i=i+1; i<pPager->nSavepoint; i++){
|
||||
pPager->aSavepoint[i].bTruncateOnRelease = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -3932,7 +3936,8 @@ static void assertTruncateConstraint(Pager *pPager){
|
||||
** then continue writing to the database.
|
||||
*/
|
||||
void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
|
||||
assert( pPager->dbSize>=nPage );
|
||||
assert( pPager->dbSize>=nPage || CORRUPT_DB );
|
||||
testcase( pPager->dbSize<nPage );
|
||||
assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
|
||||
pPager->dbSize = nPage;
|
||||
|
||||
@@ -4660,7 +4665,7 @@ int sqlite3PagerOpen(
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
int tempFile = 0; /* True for temp files (incl. in-memory files) */
|
||||
int memDb = 0; /* True if this is an in-memory file */
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
#ifndef SQLITE_OMIT_DESERIALIZE
|
||||
int memJM = 0; /* Memory journal mode */
|
||||
#else
|
||||
# define memJM 0
|
||||
@@ -4864,7 +4869,7 @@ int sqlite3PagerOpen(
|
||||
int fout = 0; /* VFS flags returned by xOpen() */
|
||||
rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
|
||||
assert( !memDb );
|
||||
#ifdef SQLITE_ENABLE_DESERIALIZE
|
||||
#ifndef SQLITE_OMIT_DESERIALIZE
|
||||
memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
|
||||
#endif
|
||||
readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
|
||||
@@ -5832,7 +5837,7 @@ int sqlite3PagerBegin(Pager *pPager, int exFlag, int subjInMemory){
|
||||
assert( pPager->eState>=PAGER_READER && pPager->eState<PAGER_ERROR );
|
||||
pPager->subjInMemory = (u8)subjInMemory;
|
||||
|
||||
if( ALWAYS(pPager->eState==PAGER_READER) ){
|
||||
if( pPager->eState==PAGER_READER ){
|
||||
assert( pPager->pInJournal==0 );
|
||||
|
||||
if( pagerUseWal(pPager) ){
|
||||
@@ -6848,6 +6853,7 @@ static SQLITE_NOINLINE int pagerOpenSavepoint(Pager *pPager, int nSavepoint){
|
||||
}
|
||||
aNew[ii].iSubRec = pPager->nSubRec;
|
||||
aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
|
||||
aNew[ii].bTruncateOnRelease = 1;
|
||||
if( !aNew[ii].pInSavepoint ){
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
@@ -6929,13 +6935,15 @@ int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint){
|
||||
/* If this is a release of the outermost savepoint, truncate
|
||||
** the sub-journal to zero bytes in size. */
|
||||
if( op==SAVEPOINT_RELEASE ){
|
||||
if( nNew==0 && isOpen(pPager->sjfd) ){
|
||||
PagerSavepoint *pRel = &pPager->aSavepoint[nNew];
|
||||
if( pRel->bTruncateOnRelease && isOpen(pPager->sjfd) ){
|
||||
/* Only truncate if it is an in-memory sub-journal. */
|
||||
if( sqlite3JournalIsInMemory(pPager->sjfd) ){
|
||||
rc = sqlite3OsTruncate(pPager->sjfd, 0);
|
||||
i64 sz = (pPager->pageSize+4)*pRel->iSubRec;
|
||||
rc = sqlite3OsTruncate(pPager->sjfd, sz);
|
||||
assert( rc==SQLITE_OK );
|
||||
}
|
||||
pPager->nSubRec = 0;
|
||||
pPager->nSubRec = pRel->iSubRec;
|
||||
}
|
||||
}
|
||||
/* Else this is a rollback operation, playback the specified savepoint.
|
||||
|
||||
+72
-43
@@ -193,7 +193,7 @@ ifnotexists(A) ::= . {A = 0;}
|
||||
ifnotexists(A) ::= IF NOT EXISTS. {A = 1;}
|
||||
%type temp {int}
|
||||
%ifndef SQLITE_OMIT_TEMPDB
|
||||
temp(A) ::= TEMP. {A = 1;}
|
||||
temp(A) ::= TEMP. {A = pParse->db->init.busy==0;}
|
||||
%endif SQLITE_OMIT_TEMPDB
|
||||
temp(A) ::= . {A = 0;}
|
||||
create_table_args ::= LP columnlist conslist_opt(X) RP(E) table_options(F). {
|
||||
@@ -250,6 +250,7 @@ columnname(A) ::= nm(A) typetoken(Y). {sqlite3AddColumn(pParse,&A,&Y);}
|
||||
%ifndef SQLITE_OMIT_GENERATED_COLUMNS
|
||||
GENERATED ALWAYS
|
||||
%endif
|
||||
MATERIALIZED
|
||||
REINDEX RENAME CTIME_KW IF
|
||||
.
|
||||
%wildcard ANY.
|
||||
@@ -496,11 +497,21 @@ cmd ::= select(X). {
|
||||
static void parserDoubleLinkSelect(Parse *pParse, Select *p){
|
||||
assert( p!=0 );
|
||||
if( p->pPrior ){
|
||||
Select *pNext = 0, *pLoop;
|
||||
int mxSelect, cnt = 0;
|
||||
for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
|
||||
Select *pNext = 0, *pLoop = p;
|
||||
int mxSelect, cnt = 1;
|
||||
while(1){
|
||||
pLoop->pNext = pNext;
|
||||
pLoop->selFlags |= SF_Compound;
|
||||
pNext = pLoop;
|
||||
pLoop = pLoop->pPrior;
|
||||
if( pLoop==0 ) break;
|
||||
cnt++;
|
||||
if( pLoop->pOrderBy || pLoop->pLimit ){
|
||||
sqlite3ErrorMsg(pParse,"%s clause should come after %s not before",
|
||||
pLoop->pOrderBy!=0 ? "ORDER BY" : "LIMIT",
|
||||
sqlite3SelectOpName(pNext->op));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( (p->selFlags & SF_MultiValue)==0 &&
|
||||
(mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
|
||||
@@ -510,29 +521,25 @@ cmd ::= select(X). {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Attach a With object describing the WITH clause to a Select
|
||||
** object describing the query for which the WITH clause is a prefix.
|
||||
*/
|
||||
static Select *attachWithToSelect(Parse *pParse, Select *pSelect, With *pWith){
|
||||
if( pSelect ){
|
||||
pSelect->pWith = pWith;
|
||||
parserDoubleLinkSelect(pParse, pSelect);
|
||||
}else{
|
||||
sqlite3WithDelete(pParse->db, pWith);
|
||||
}
|
||||
return pSelect;
|
||||
}
|
||||
}
|
||||
|
||||
%ifndef SQLITE_OMIT_CTE
|
||||
select(A) ::= WITH wqlist(W) selectnowith(X). {
|
||||
Select *p = X;
|
||||
if( p ){
|
||||
p->pWith = W;
|
||||
parserDoubleLinkSelect(pParse, p);
|
||||
}else{
|
||||
sqlite3WithDelete(pParse->db, W);
|
||||
}
|
||||
A = p;
|
||||
}
|
||||
select(A) ::= WITH RECURSIVE wqlist(W) selectnowith(X). {
|
||||
Select *p = X;
|
||||
if( p ){
|
||||
p->pWith = W;
|
||||
parserDoubleLinkSelect(pParse, p);
|
||||
}else{
|
||||
sqlite3WithDelete(pParse->db, W);
|
||||
}
|
||||
A = p;
|
||||
}
|
||||
select(A) ::= WITH wqlist(W) selectnowith(X). {A = attachWithToSelect(pParse,X,W);}
|
||||
select(A) ::= WITH RECURSIVE wqlist(W) selectnowith(X).
|
||||
{A = attachWithToSelect(pParse,X,W);}
|
||||
%endif /* SQLITE_OMIT_CTE */
|
||||
select(A) ::= selectnowith(X). {
|
||||
Select *p = X;
|
||||
@@ -699,8 +706,8 @@ seltablist(A) ::= stl_prefix(A) nm(Y) dbnm(D) LP exprlist(E) RP as(Z)
|
||||
}else if( F->nSrc==1 ){
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,0,0,&Z,0,N,U);
|
||||
if( A ){
|
||||
struct SrcList_item *pNew = &A->a[A->nSrc-1];
|
||||
struct SrcList_item *pOld = F->a;
|
||||
SrcItem *pNew = &A->a[A->nSrc-1];
|
||||
SrcItem *pOld = F->a;
|
||||
pNew->zName = pOld->zName;
|
||||
pNew->zDatabase = pOld->zDatabase;
|
||||
pNew->pSelect = pOld->pSelect;
|
||||
@@ -1247,20 +1254,28 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
|
||||
*/
|
||||
sqlite3ExprUnmapAndDelete(pParse, A);
|
||||
A = sqlite3Expr(pParse->db, TK_INTEGER, N ? "1" : "0");
|
||||
}else if( Y->nExpr==1 && sqlite3ExprIsConstant(Y->a[0].pExpr) ){
|
||||
Expr *pRHS = Y->a[0].pExpr;
|
||||
Y->a[0].pExpr = 0;
|
||||
sqlite3ExprListDelete(pParse->db, Y);
|
||||
pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
|
||||
A = sqlite3PExpr(pParse, TK_EQ, A, pRHS);
|
||||
if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
|
||||
}else{
|
||||
A = sqlite3PExpr(pParse, TK_IN, A, 0);
|
||||
if( A ){
|
||||
A->x.pList = Y;
|
||||
sqlite3ExprSetHeightAndFlags(pParse, A);
|
||||
}else{
|
||||
Expr *pRHS = Y->a[0].pExpr;
|
||||
if( Y->nExpr==1 && sqlite3ExprIsConstant(pRHS) && A->op!=TK_VECTOR ){
|
||||
Y->a[0].pExpr = 0;
|
||||
sqlite3ExprListDelete(pParse->db, Y);
|
||||
pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
|
||||
A = sqlite3PExpr(pParse, TK_EQ, A, pRHS);
|
||||
}else{
|
||||
A = sqlite3PExpr(pParse, TK_IN, A, 0);
|
||||
if( A==0 ){
|
||||
sqlite3ExprListDelete(pParse->db, Y);
|
||||
}else if( A->pLeft->op==TK_VECTOR ){
|
||||
int nExpr = A->pLeft->x.pList->nExpr;
|
||||
Select *pSelectRHS = sqlite3ExprListToValues(pParse, nExpr, Y);
|
||||
if( pSelectRHS ){
|
||||
parserDoubleLinkSelect(pParse, pSelectRHS);
|
||||
sqlite3PExprAddSelect(pParse, A, pSelectRHS);
|
||||
}
|
||||
}else{
|
||||
A->x.pList = Y;
|
||||
sqlite3ExprSetHeightAndFlags(pParse, A);
|
||||
}
|
||||
}
|
||||
if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
|
||||
}
|
||||
@@ -1662,17 +1677,26 @@ anylist ::= anylist ANY.
|
||||
//////////////////////// COMMON TABLE EXPRESSIONS ////////////////////////////
|
||||
%type wqlist {With*}
|
||||
%destructor wqlist {sqlite3WithDelete(pParse->db, $$);}
|
||||
%type wqitem {Cte*}
|
||||
// %destructor wqitem {sqlite3CteDelete(pParse->db, $$);} // not reachable
|
||||
|
||||
with ::= .
|
||||
%ifndef SQLITE_OMIT_CTE
|
||||
with ::= WITH wqlist(W). { sqlite3WithPush(pParse, W, 1); }
|
||||
with ::= WITH RECURSIVE wqlist(W). { sqlite3WithPush(pParse, W, 1); }
|
||||
|
||||
wqlist(A) ::= nm(X) eidlist_opt(Y) AS LP select(Z) RP. {
|
||||
A = sqlite3WithAdd(pParse, 0, &X, Y, Z); /*A-overwrites-X*/
|
||||
%type wqas {u8}
|
||||
wqas(A) ::= AS. {A = M10d_Any;}
|
||||
wqas(A) ::= AS MATERIALIZED. {A = M10d_Yes;}
|
||||
wqas(A) ::= AS NOT MATERIALIZED. {A = M10d_No;}
|
||||
wqitem(A) ::= nm(X) eidlist_opt(Y) wqas(M) LP select(Z) RP. {
|
||||
A = sqlite3CteNew(pParse, &X, Y, Z, M); /*A-overwrites-X*/
|
||||
}
|
||||
wqlist(A) ::= wqlist(A) COMMA nm(X) eidlist_opt(Y) AS LP select(Z) RP. {
|
||||
A = sqlite3WithAdd(pParse, A, &X, Y, Z);
|
||||
wqlist(A) ::= wqitem(X). {
|
||||
A = sqlite3WithAdd(pParse, 0, X); /*A-overwrites-X*/
|
||||
}
|
||||
wqlist(A) ::= wqlist(A) COMMA wqitem(X). {
|
||||
A = sqlite3WithAdd(pParse, A, X);
|
||||
}
|
||||
%endif SQLITE_OMIT_CTE
|
||||
|
||||
@@ -1785,7 +1809,11 @@ frame_exclude(A) ::= GROUP|TIES(X). {A = @X; /*A-overwrites-X*/}
|
||||
window_clause(A) ::= WINDOW windowdefn_list(B). { A = B; }
|
||||
|
||||
filter_over(A) ::= filter_clause(F) over_clause(O). {
|
||||
O->pFilter = F;
|
||||
if( O ){
|
||||
O->pFilter = F;
|
||||
}else{
|
||||
sqlite3ExprDelete(pParse->db, F);
|
||||
}
|
||||
A = O;
|
||||
}
|
||||
filter_over(A) ::= over_clause(O). {
|
||||
@@ -1835,6 +1863,7 @@ filter_clause(A) ::= FILTER LP WHERE expr(X) RP. { A = X; }
|
||||
IF_NULL_ROW /* the if-null-row operator */
|
||||
ASTERISK /* The "*" in count(*) and similar */
|
||||
SPAN /* The span operator */
|
||||
ERROR /* An expression containing an error */
|
||||
.
|
||||
/* There must be no more than 255 tokens defined above. If this grammar
|
||||
** is extended with new rules and tokens, they must either be so few in
|
||||
|
||||
@@ -461,6 +461,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
|
||||
p->page.pExtra = &p[1];
|
||||
p->isBulkLocal = 0;
|
||||
p->isAnchor = 0;
|
||||
p->pLruPrev = 0; /* Initializing this saves a valgrind error */
|
||||
}
|
||||
(*pCache->pnPurgeable)++;
|
||||
return p;
|
||||
|
||||
+2
-1
@@ -1461,6 +1461,7 @@ void sqlite3Pragma(
|
||||
** regRow..regRow+n. If any of the child key values are NULL, this
|
||||
** row cannot cause an FK violation. Jump directly to addrOk in
|
||||
** this case. */
|
||||
if( regRow+pFK->nCol>pParse->nMem ) pParse->nMem = regRow+pFK->nCol;
|
||||
for(j=0; j<pFK->nCol; j++){
|
||||
int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
|
||||
sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
|
||||
@@ -1969,7 +1970,7 @@ void sqlite3Pragma(
|
||||
** Checkpoint the database.
|
||||
*/
|
||||
case PragTyp_WAL_CHECKPOINT: {
|
||||
int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
|
||||
int iBt = (pId2->z?iDb:SQLITE_MAX_DB);
|
||||
int eMode = SQLITE_CHECKPOINT_PASSIVE;
|
||||
if( zRight ){
|
||||
if( sqlite3StrICmp(zRight, "full")==0 ){
|
||||
|
||||
+2
-2
@@ -370,7 +370,7 @@ static const PragmaName aPragmaName[] = {
|
||||
#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
|
||||
{/* zName: */ "integrity_check",
|
||||
/* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
|
||||
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1,
|
||||
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1|PragFlg_SchemaOpt,
|
||||
/* ColNames: */ 0, 0,
|
||||
/* iArg: */ 0 },
|
||||
#endif
|
||||
@@ -478,7 +478,7 @@ static const PragmaName aPragmaName[] = {
|
||||
#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
|
||||
{/* zName: */ "quick_check",
|
||||
/* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
|
||||
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1,
|
||||
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1|PragFlg_SchemaOpt,
|
||||
/* ColNames: */ 0, 0,
|
||||
/* iArg: */ 0 },
|
||||
#endif
|
||||
|
||||
+27
-11
@@ -96,6 +96,7 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){
|
||||
UNUSED_PARAMETER2(NotUsed, argc);
|
||||
assert( sqlite3_mutex_held(db->mutex) );
|
||||
db->mDbFlags |= DBFLAG_EncodingFixed;
|
||||
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
|
||||
pData->nInitRow++;
|
||||
if( db->mallocFailed ){
|
||||
corruptSchema(pData, argv, 0);
|
||||
@@ -103,7 +104,6 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){
|
||||
}
|
||||
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
|
||||
if( argv[3]==0 ){
|
||||
corruptSchema(pData, argv, 0);
|
||||
}else if( argv[4]
|
||||
@@ -377,18 +377,22 @@ int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFlags){
|
||||
}
|
||||
#endif
|
||||
}
|
||||
assert( pDb == &(db->aDb[iDb]) );
|
||||
if( db->mallocFailed ){
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
sqlite3ResetAllSchemasOfConnection(db);
|
||||
}
|
||||
pDb = &db->aDb[iDb];
|
||||
}else
|
||||
if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
|
||||
/* Black magic: If the SQLITE_NoSchemaError flag is set, then consider
|
||||
** the schema loaded, even if errors occurred. In this situation the
|
||||
** current sqlite3_prepare() operation will fail, but the following one
|
||||
** will attempt to compile the supplied statement against whatever subset
|
||||
** of the schema was loaded before the error occurred. The primary
|
||||
** purpose of this is to allow access to the sqlite_schema table
|
||||
** even when its contents have been corrupted.
|
||||
/* Hack: If the SQLITE_NoSchemaError flag is set, then consider
|
||||
** the schema loaded, even if errors (other than OOM) occurred. In
|
||||
** this situation the current sqlite3_prepare() operation will fail,
|
||||
** but the following one will attempt to compile the supplied statement
|
||||
** against whatever subset of the schema was loaded before the error
|
||||
** occurred.
|
||||
**
|
||||
** The primary purpose of this is to allow access to the sqlite_schema
|
||||
** table even when its contents have been corrupted.
|
||||
*/
|
||||
DbSetProperty(db, iDb, DB_SchemaLoaded);
|
||||
rc = SQLITE_OK;
|
||||
@@ -498,6 +502,7 @@ static void schemaIsValid(Parse *pParse){
|
||||
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
|
||||
if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
|
||||
sqlite3OomFault(db);
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
}
|
||||
if( rc!=SQLITE_OK ) return;
|
||||
openedTransaction = 1;
|
||||
@@ -589,15 +594,23 @@ void sqlite3ParserReset(Parse *pParse){
|
||||
** sqlite3ParserReset(), which reduces the total CPU cycle count.
|
||||
**
|
||||
** If a memory allocation error occurs, then the cleanup happens immediately.
|
||||
** When eithr SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
|
||||
** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
|
||||
** pParse->earlyCleanup flag is set in that case. Calling code show verify
|
||||
** that test cases exist for which this happens, to guard against possible
|
||||
** use-after-free errors following an OOM. The preferred way to do this is
|
||||
** to immediately follow the call to this routine with:
|
||||
**
|
||||
** testcase( pParse->earlyCleanup );
|
||||
**
|
||||
** This routine returns a copy of its pPtr input (the third parameter)
|
||||
** except if an early cleanup occurs, in which case it returns NULL. So
|
||||
** another way to check for early cleanup is to check the return value.
|
||||
** Or, stop using the pPtr parameter with this call and use only its
|
||||
** return value thereafter. Something like this:
|
||||
**
|
||||
** pObj = sqlite3ParserAddCleanup(pParse, destructor, pObj);
|
||||
*/
|
||||
void sqlite3ParserAddCleanup(
|
||||
void *sqlite3ParserAddCleanup(
|
||||
Parse *pParse, /* Destroy when this Parser finishes */
|
||||
void (*xCleanup)(sqlite3*,void*), /* The cleanup routine */
|
||||
void *pPtr /* Pointer to object to be cleaned up */
|
||||
@@ -610,10 +623,12 @@ void sqlite3ParserAddCleanup(
|
||||
pCleanup->xCleanup = xCleanup;
|
||||
}else{
|
||||
xCleanup(pParse->db, pPtr);
|
||||
pPtr = 0;
|
||||
#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
|
||||
pParse->earlyCleanup = 1;
|
||||
#endif
|
||||
}
|
||||
return pPtr;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -723,6 +738,7 @@ static int sqlite3Prepare(
|
||||
}
|
||||
if( db->mallocFailed ){
|
||||
sParse.rc = SQLITE_NOMEM_BKPT;
|
||||
sParse.checkSchema = 0;
|
||||
}
|
||||
if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){
|
||||
if( sParse.checkSchema ){
|
||||
|
||||
+24
-15
@@ -29,7 +29,7 @@
|
||||
#define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '',
|
||||
NULL pointers replaced by SQL NULL. %Q */
|
||||
#define etTOKEN 11 /* a pointer to a Token structure */
|
||||
#define etSRCLIST 12 /* a pointer to a SrcList */
|
||||
#define etSRCITEM 12 /* a pointer to a SrcItem */
|
||||
#define etPOINTER 13 /* The %p conversion */
|
||||
#define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
|
||||
#define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
|
||||
@@ -95,10 +95,16 @@ static const et_info fmtinfo[] = {
|
||||
|
||||
/* All the rest are undocumented and are for internal use only */
|
||||
{ 'T', 0, 0, etTOKEN, 0, 0 },
|
||||
{ 'S', 0, 0, etSRCLIST, 0, 0 },
|
||||
{ 'S', 0, 0, etSRCITEM, 0, 0 },
|
||||
{ 'r', 10, 1, etORDINAL, 0, 0 },
|
||||
};
|
||||
|
||||
/* Notes:
|
||||
**
|
||||
** %S Takes a pointer to SrcItem. Shows name or database.name
|
||||
** %!S Like %S but prefer the zName over the zAlias
|
||||
*/
|
||||
|
||||
/* Floating point constants used for rounding */
|
||||
static const double arRound[] = {
|
||||
5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05,
|
||||
@@ -853,21 +859,24 @@ void sqlite3_str_vappendf(
|
||||
length = width = 0;
|
||||
break;
|
||||
}
|
||||
case etSRCLIST: {
|
||||
SrcList *pSrc;
|
||||
int k;
|
||||
struct SrcList_item *pItem;
|
||||
case etSRCITEM: {
|
||||
SrcItem *pItem;
|
||||
if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
|
||||
pSrc = va_arg(ap, SrcList*);
|
||||
k = va_arg(ap, int);
|
||||
pItem = &pSrc->a[k];
|
||||
pItem = va_arg(ap, SrcItem*);
|
||||
assert( bArgList==0 );
|
||||
assert( k>=0 && k<pSrc->nSrc );
|
||||
if( pItem->zDatabase ){
|
||||
sqlite3_str_appendall(pAccum, pItem->zDatabase);
|
||||
sqlite3_str_append(pAccum, ".", 1);
|
||||
if( pItem->zAlias && !flag_altform2 ){
|
||||
sqlite3_str_appendall(pAccum, pItem->zAlias);
|
||||
}else if( pItem->zName ){
|
||||
if( pItem->zDatabase ){
|
||||
sqlite3_str_appendall(pAccum, pItem->zDatabase);
|
||||
sqlite3_str_append(pAccum, ".", 1);
|
||||
}
|
||||
sqlite3_str_appendall(pAccum, pItem->zName);
|
||||
}else if( pItem->zAlias ){
|
||||
sqlite3_str_appendall(pAccum, pItem->zAlias);
|
||||
}else if( ALWAYS(pItem->pSelect) ){
|
||||
sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId);
|
||||
}
|
||||
sqlite3_str_appendall(pAccum, pItem->zName);
|
||||
length = width = 0;
|
||||
break;
|
||||
}
|
||||
@@ -921,7 +930,7 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){
|
||||
}else{
|
||||
char *zOld = isMalloced(p) ? p->zText : 0;
|
||||
i64 szNew = p->nChar;
|
||||
szNew += N + 1;
|
||||
szNew += (sqlite3_int64)N + 1;
|
||||
if( szNew+p->nChar<=p->mxAlloc ){
|
||||
/* Force exponential buffer size growth as long as it does not overflow,
|
||||
** to avoid having to call this routine too often */
|
||||
|
||||
+6
-1
@@ -76,11 +76,16 @@ void sqlite3_randomness(int N, void *pBuf){
|
||||
** number generator) not as an encryption device.
|
||||
*/
|
||||
if( !wsdPrng.isInit ){
|
||||
sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
|
||||
int i;
|
||||
char k[256];
|
||||
wsdPrng.j = 0;
|
||||
wsdPrng.i = 0;
|
||||
sqlite3OsRandomness(sqlite3_vfs_find(0), 256, k);
|
||||
if( NEVER(pVfs==0) ){
|
||||
memset(k, 0, sizeof(k));
|
||||
}else{
|
||||
sqlite3OsRandomness(pVfs, 256, k);
|
||||
}
|
||||
for(i=0; i<256; i++){
|
||||
wsdPrng.s[i] = (u8)i;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user