Compare commits
728 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 399665beb5 | |||
| 7424aeff41 | |||
| 5035c33df8 | |||
| 7bc6a818f0 | |||
| 1337a2291d | |||
| 2d3261fe86 | |||
| 0a803bd984 | |||
| ad658b2d82 | |||
| cb57716c65 | |||
| 31474ce57e | |||
| 5d48e0cdc5 | |||
| 6319a8003c | |||
| 80cf891792 | |||
| f333370e1f | |||
| 2897b88f9e | |||
| faaacd3fbb | |||
| 0f51aa3972 | |||
| 0cc6f78bcf | |||
| 4c5c941b6e | |||
| 8b9a3d1fc8 | |||
| 5a0771a1f4 | |||
| a5f8c42c98 | |||
| 703c208d30 | |||
| 40c9becc81 | |||
| b22b493338 | |||
| 316cd40122 | |||
| bcdb4cc71b | |||
| 3e4e697d1c | |||
| bdb6368d72 | |||
| b53e0992b2 | |||
| 8c983ddb67 | |||
| 2e440a0801 | |||
| 0c4517a61a | |||
| 4c8404e555 | |||
| 6e440ab3de | |||
| ad617b4d6d | |||
| 173b418e60 | |||
| 5fc3a8a32f | |||
| 4e9bf5ace3 | |||
| e04c9f4b33 | |||
| fee6431392 | |||
| 18a3a48db1 | |||
| 44132244fa | |||
| a3fc683c80 | |||
| 9c3a114ca0 | |||
| 78d15f097a | |||
| 4d28830861 | |||
| f0f025b340 | |||
| f6e3e31625 | |||
| 23593f8e99 | |||
| 09cb5eb5ac | |||
| 11969c1269 | |||
| 546d46a40d | |||
| aae210884c | |||
| 7b7a373706 | |||
| aa07b36dd5 | |||
| 2578cf2eb7 | |||
| 1544960b3d | |||
| 7383f5a7d9 | |||
| 4f2bf6bf88 | |||
| 2ce2b779bb | |||
| e5928b17ca | |||
| 35908b167f | |||
| f7415736d1 | |||
| 376860ba88 | |||
| 41ce47c4f4 | |||
| 05cb948bf7 | |||
| 00378fde23 | |||
| f56291ed02 | |||
| 78ed74ef8e | |||
| 16b03c0196 | |||
| 0348fc722f | |||
| a8771a1736 | |||
| cd05aafa56 | |||
| 534945ad07 | |||
| 0f201fccc0 | |||
| 2756f806f2 | |||
| 9113c87ef3 | |||
| 207cb6f670 | |||
| 5187c955f6 | |||
| 9c5e1e40e3 | |||
| 087f143f87 | |||
| 5b0e63eb4c | |||
| e1c3462484 | |||
| e6d1650c5b | |||
| fbfe5af903 | |||
| 9289c47df7 | |||
| f0d12d87fa | |||
| 778d334085 | |||
| 217635f709 | |||
| 2315e83463 | |||
| 3961b26363 | |||
| 8c3b7501af | |||
| 3822e8ac47 | |||
| 626bcc88dd | |||
| c8e9f6818b | |||
| 6aafd74853 | |||
| 26e817f69b | |||
| 5e10d892d6 | |||
| a3a4da0922 | |||
| 8c3cc71a5a | |||
| 8e658f0a13 | |||
| e2848932a5 | |||
| bffd5c1ece | |||
| e24a6f58ae | |||
| 3cf46ee508 | |||
| 403f00219b | |||
| 3a17e2e5cf | |||
| b5a6f33e50 | |||
| f98109e7cb | |||
| 3b01dd0f5d | |||
| b4d7f1eb88 | |||
| 1dd1303600 | |||
| 4784a78d1c | |||
| 4b1b65ca2e | |||
| f4c291275b | |||
| e6710e83fc | |||
| 3c8fb6fb84 | |||
| fe888bcf11 | |||
| 509a6303d1 | |||
| ef69d2b277 | |||
| f89812fe52 | |||
| 2d2e528e1f | |||
| 47e2fe3ce7 | |||
| 058e99502a | |||
| 6aabb72618 | |||
| ee37302095 | |||
| 6b6d6c6bd2 | |||
| 8bd0b250b7 | |||
| 7bace9e9bb | |||
| 3dedb87bd7 | |||
| ee6b80c3b5 | |||
| 825fa17b1f | |||
| 034d111807 | |||
| d00505dc97 | |||
| e50998859d | |||
| 9553016377 | |||
| 3245f3be67 | |||
| 4b5919e2ce | |||
| a5cc692422 | |||
| cf2ad7ae36 | |||
| 2a7b27f1c6 | |||
| 077e17b59a | |||
| 449b473ee6 | |||
| 18934137dd | |||
| 67a0bf383f | |||
| b496eef690 | |||
| 02cb3ff004 | |||
| 40e3fa3035 | |||
| b3623e0af7 | |||
| b1c034b2f1 | |||
| de353fb5c2 | |||
| ca0720a9d8 | |||
| e834484d89 | |||
| 615aeceaff | |||
| 4f28ee9d76 | |||
| 2bb2d53bca | |||
| cda165ff9a | |||
| 95cc6a5e11 | |||
| e9a7ebe19f | |||
| b88bf865c3 | |||
| 0505851451 | |||
| 4413ec7255 | |||
| 03437f7886 | |||
| 8d48e30b39 | |||
| f0af3db770 | |||
| ea1e3b4251 | |||
| b2d7137154 | |||
| ebdf4c0240 | |||
| f703b42dc4 | |||
| 90120b9f4a | |||
| d5c2e08449 | |||
| f1ab642cde | |||
| fc7f8f81da | |||
| cd9e863079 | |||
| 3dfab26028 | |||
| 25bb72a7a8 | |||
| 74879e137d | |||
| 5f289e8400 | |||
| 4efa360f89 | |||
| 72f38795b4 | |||
| 43bb445f77 | |||
| 2337e97949 | |||
| 0e400f4e7d | |||
| 554cb87d96 | |||
| 5ca48c0b35 | |||
| e6aec72312 | |||
| f15b77b7cf | |||
| c59b7b1fb0 | |||
| ebaa9477d7 | |||
| dce232a298 | |||
| 07fae32db0 | |||
| e7ebe0aa81 | |||
| e36281fc31 | |||
| f53487a42d | |||
| c578e4f0eb | |||
| 48cae1320b | |||
| 3325a5c497 | |||
| 16316f1b68 | |||
| 0e4ab0db7e | |||
| f28727f61e | |||
| a57ac0a827 | |||
| 20e9cbe0ff | |||
| 2c1b1ddc55 | |||
| 064390b2b1 | |||
| 2b294b543f | |||
| d85e4ac347 | |||
| e26f592ea5 | |||
| b0b734d145 | |||
| bc7180cdb3 | |||
| 54f1fc4f94 | |||
| fe9833482f | |||
| 62f1b48638 | |||
| f79d277999 | |||
| 3691e56210 | |||
| 0702c63bc0 | |||
| 47d8c40ca5 | |||
| fa17e10592 | |||
| 1c67ec5692 | |||
| f170b0868d | |||
| 766ba7917e | |||
| af260308b3 | |||
| a36fedbda0 | |||
| d45ac3947d | |||
| 86bc5e41bb | |||
| a5ec23a705 | |||
| 2a40a882f2 | |||
| 521e0b6cb6 | |||
| 3a6e0c3f04 | |||
| d198183465 | |||
| 9efc618607 | |||
| 2b0ea0204f | |||
| f221e4b5d6 | |||
| cf5cab01cf | |||
| 0751fc3b85 | |||
| 2591cfb673 | |||
| b885744709 | |||
| 861ac67a9d | |||
| 8c44962aaf | |||
| b9294de1e6 | |||
| 4af6462fb8 | |||
| 436c28a265 | |||
| d7480403bc | |||
| ae8776e092 | |||
| 1d49768151 | |||
| 13736999d9 | |||
| d0d21f5565 | |||
| 8fa6206bc4 | |||
| 01156ec1c9 | |||
| c2beb0d8f6 | |||
| f26e45139e | |||
| b103c574fd | |||
| ea64cb31a5 | |||
| 63880362ed | |||
| c68fb84759 | |||
| 36f904f065 | |||
| 6efabd6cd3 | |||
| 2a7aff93ed | |||
| 3e245bcef3 | |||
| 8f9261a8e9 | |||
| e3bf2c8e9b | |||
| dba3a5ab87 | |||
| 516c85026b | |||
| 10c5341c72 | |||
| 0c278c3d76 | |||
| a913f9b992 | |||
| 27a242c634 | |||
| bbf71138cf | |||
| a1f79dae98 | |||
| 92d1afba9b | |||
| 1cc5c4ac84 | |||
| e45b87a9b7 | |||
| 958fcd417c | |||
| a27e350b6f | |||
| 0c2b00b0d6 | |||
| 65458dc146 | |||
| e5dea28482 | |||
| 8878f8a8d3 | |||
| 0483668007 | |||
| 0a841a2b85 | |||
| 8a5469b6f5 | |||
| 40357f0d5d | |||
| 5c118e3946 | |||
| a341bae948 | |||
| 093dd41e97 | |||
| f6bee94e22 | |||
| 644817721e | |||
| 33b2cb9aec | |||
| bb1369037b | |||
| d580bea7d4 | |||
| 6fdac75127 | |||
| 16828c8c12 | |||
| 93c4087ffe | |||
| c18fc6134e | |||
| 8a4d2bc34f | |||
| 0dbb3db431 | |||
| 8fca1c7044 | |||
| fd80fa9b6d | |||
| 626aa48c26 | |||
| f3d6e8fd6e | |||
| b61c2424d7 | |||
| 93a4b411ef | |||
| 181d75ef9e | |||
| 410fac35d7 | |||
| bf154369e7 | |||
| 486191603f | |||
| f89f4efb28 | |||
| 4e5aeb54f2 | |||
| a5d06a3d54 | |||
| 23aa8ff4de | |||
| f74f4ed5b5 | |||
| 0f4b534b60 | |||
| 6d013d890e | |||
| 1324b2830e | |||
| 0286cdbca6 | |||
| 47b4969e2d | |||
| 36c19f7799 | |||
| ea7a4e4fb3 | |||
| 645682a7c7 | |||
| 6ffa895884 | |||
| bff17db433 | |||
| c7fc08f69a | |||
| aa03c69591 | |||
| f51672a945 | |||
| d69820c42b | |||
| 9f67cc26c1 | |||
| c9dfe2b808 | |||
| b1f08bc690 | |||
| 5fd9f03291 | |||
| 404bf6bac6 | |||
| 1943005f62 | |||
| 1a66ff359f | |||
| e9ab04a446 | |||
| 5af8a86d62 | |||
| abe1ff38dd | |||
| 23b34bbc25 | |||
| ca29bbce2f | |||
| 4209d553e7 | |||
| 8d2f661ab8 | |||
| cd69784646 | |||
| b8bbe3e2db | |||
| 26c4df0fb0 | |||
| e91bde4655 | |||
| 78907bba3e | |||
| c121e087f3 | |||
| 724e298e9c | |||
| 7bfbd2508c | |||
| 361e0ede47 | |||
| ddcdf0b0dd | |||
| 26542e722b | |||
| e599cc427f | |||
| 085c5c6b43 | |||
| d0b22b81c8 | |||
| 79669c25c4 | |||
| fb98dac04f | |||
| 80bf86967f | |||
| de1e02ee52 | |||
| 6af03b469e | |||
| 73c6ad1920 | |||
| 400ee2ecef | |||
| 2f6a729d55 | |||
| 64f0e9376b | |||
| a240a24ad0 | |||
| e145136a4e | |||
| 325b56b504 | |||
| dc5888e04a | |||
| 192201d2ed | |||
| ea488b1258 | |||
| 51e5d447ba | |||
| 43baa1de76 | |||
| 71eacead76 | |||
| c21c0e2af9 | |||
| 744a65cf7d | |||
| f6868562ce | |||
| 40b5b19a0f | |||
| d60b7275c3 | |||
| 166542cc98 | |||
| 4ec29fc115 | |||
| 40822eb262 | |||
| 660dfbdcfb | |||
| b800bd63aa | |||
| 4257373f6d | |||
| 0592b20faf | |||
| 2eb454147a | |||
| 056b72a988 | |||
| e26d162402 | |||
| 1c0dcec4c5 | |||
| 2f72d711ac | |||
| 091fb16e09 | |||
| 9d023c227f | |||
| d59ac28d4f | |||
| 7db1289b0f | |||
| 2d0a85c5de | |||
| e9e0208561 | |||
| 38240592ad | |||
| 6da6f31cca | |||
| 403445be23 | |||
| 618a375e9f | |||
| 0fb074ab61 | |||
| b8a2b20509 | |||
| 9af6beb977 | |||
| 29f2458aae | |||
| 348f7420b3 | |||
| 02520cc8f6 | |||
| b0dae2b3c3 | |||
| 0076e49700 | |||
| 8ae45e4c6b | |||
| 9f69b9411e | |||
| f8cd3d2b5c | |||
| b8b2d9c5e1 | |||
| 5348fbe332 | |||
| ff16267d7d | |||
| c7d7ebd755 | |||
| 07576c3fe8 | |||
| 96d5549778 | |||
| d83997ba7f | |||
| c93bf1d462 | |||
| 086b800fcd | |||
| 556527a154 | |||
| f69dad8c53 | |||
| 767bc8de8e | |||
| a6e8ee12e2 | |||
| f8d2745f99 | |||
| d383557960 | |||
| 67a99dbee8 | |||
| 8b0e5c3c7e | |||
| d631c6af80 | |||
| 902e2602c2 | |||
| d59a388b61 | |||
| 175fdcb912 | |||
| f4874818a4 | |||
| 6868bca6c5 | |||
| b302c065d8 | |||
| e8346d0a88 | |||
| d647819034 | |||
| 51b011d8d5 | |||
| cc212e4450 | |||
| 73b7af0437 | |||
| 825ecf9c05 | |||
| 0338f53b05 | |||
| d2b960cf41 | |||
| de695eab88 | |||
| 1607ac3357 | |||
| 527c39de80 | |||
| be7777f4a5 | |||
| f015a3d19f | |||
| adef15986a | |||
| 1a53219981 | |||
| f71b8123df | |||
| 4077b006ad | |||
| 77874e782b | |||
| 2f5f674066 | |||
| fa5dfa8910 | |||
| 1e48d79f71 | |||
| 41724ebc5a | |||
| 87b7ac0420 | |||
| 744c17c482 | |||
| c915b9c46f | |||
| 049d239a8c | |||
| 95cb5ccf92 | |||
| b2cc3cf36e | |||
| 11d63ebf2c | |||
| 3b52f80237 | |||
| b55776230d | |||
| 367c146b09 | |||
| bc33519de6 | |||
| eeada07457 | |||
| 00e5d3d59e | |||
| 8aa7f4d813 | |||
| 207f626356 | |||
| d88fd53989 | |||
| 689f1b9246 | |||
| 63879a2c99 | |||
| 72d620bdb1 | |||
| 56f38db700 | |||
| c35f02d676 | |||
| 7a8809907f | |||
| 85f93850f7 | |||
| 3a45d30ea5 | |||
| b94182bdc6 | |||
| bae50d6719 | |||
| 7497364749 | |||
| 2aa1086cab | |||
| a25bbaf74a | |||
| c64f0e71c1 | |||
| 3d5665366f | |||
| 8e8e9de87e | |||
| 0c0d0526dc | |||
| 08e1a6a29b | |||
| de7a820fd0 | |||
| 07fd1bf323 | |||
| a087eb8f6d | |||
| 4bea8c6b56 | |||
| 09121b0523 | |||
| 22b541b55a | |||
| 609959285b | |||
| 9684d71081 | |||
| 5487cdcc0a | |||
| 3e4314b4f8 | |||
| 0e464b5f51 | |||
| 5eb6e09795 | |||
| a9cdb90421 | |||
| 95fe38f2fc | |||
| 7f417569f7 | |||
| 1a6bac0d2f | |||
| 7980fadcef | |||
| ecb386b71f | |||
| 30d2aab5fd | |||
| 6c7e89b48a | |||
| b77c312956 | |||
| d63c07e6c5 | |||
| 0748e8bf9a | |||
| ab843a51d3 | |||
| 45e41b7371 | |||
| f054c34372 | |||
| d6bb6000ef | |||
| da653b897d | |||
| 67f70bea06 | |||
| 9b843f0ce0 | |||
| 1ca14b74ed | |||
| 9c2d7aa7d0 | |||
| 8318b55d87 | |||
| 1c69bc912d | |||
| abb4e7598c | |||
| 11140addbb | |||
| 6dab33bf40 | |||
| a74b4c4d45 | |||
| 7e9a56f70f | |||
| 503ad9c72d | |||
| 825a6bffc4 | |||
| 18f8600fe6 | |||
| 6403e77d3b | |||
| 22b410d894 | |||
| e60ffa3350 | |||
| 910e57b9df | |||
| 41150bf35b | |||
| bc656e220f | |||
| 815b782e99 | |||
| b465a83353 | |||
| d4e9caf987 | |||
| 2627cbd4b5 | |||
| befbb40f44 | |||
| cbde37d8e4 | |||
| 4d0d071a53 | |||
| 3117b7b081 | |||
| e32d6a0bbf | |||
| de75638b33 | |||
| 2e61588931 | |||
| d737b16f92 | |||
| 3b8c7545df | |||
| 1c2bf41a12 | |||
| ec39c96473 | |||
| f80bb195b3 | |||
| 7466d5665a | |||
| 23f240b325 | |||
| a20922cb20 | |||
| 25f2ce6e71 | |||
| 7348ca4e0b | |||
| 2e1bcc9dd0 | |||
| 1942d1f236 | |||
| 41db500274 | |||
| e98b71e65d | |||
| 088b615acd | |||
| 01a6c16e0c | |||
| a1848a5d22 | |||
| d875c7eefe | |||
| d973268ccf | |||
| abf86bd313 | |||
| 79a25ee021 | |||
| d0453f7ec5 | |||
| a3e2518bb3 | |||
| f68621fe83 | |||
| 2bd9f44a18 | |||
| fe14699765 | |||
| 6fda176ba6 | |||
| 052953a4e6 | |||
| fdc621aece | |||
| cebc8009ed | |||
| 2d27d36cba | |||
| b192970809 | |||
| 977eef6cdc | |||
| bdbda1eb1f | |||
| be60896485 | |||
| e62d9149a6 | |||
| bb3c62a758 | |||
| 4ce7bf9156 | |||
| 22c4bc8991 | |||
| a99e325468 | |||
| 358424aeff | |||
| a51379ad78 | |||
| b3ebf3043f | |||
| 79f60034ee | |||
| d549a702b3 | |||
| 2c31c00bfa | |||
| 37f5584a2f | |||
| d345dcf39a | |||
| 375f182b1d | |||
| c504f677b6 | |||
| eab6c125bd | |||
| 95b1036e9a | |||
| b60d1fbe8e | |||
| 7c96039492 | |||
| 3ac624344d | |||
| f7ecd956ce | |||
| 94e615a6ac | |||
| 12c35ec322 | |||
| 3b79f7580a | |||
| 146e64d2e4 | |||
| f7309bce10 | |||
| 0879d5f9e0 | |||
| 949e2ab49a | |||
| 57d4b5bde1 | |||
| 6625d6d873 | |||
| 61dac44eb9 | |||
| a70782407d | |||
| f7413d9acf | |||
| b087de063b | |||
| c133bab72a | |||
| ec27077c4f | |||
| 6134b2dff2 | |||
| ff02ac7f07 | |||
| c583719b65 | |||
| 37259f4e6b | |||
| 3a6e4c59c4 | |||
| b77c07a715 | |||
| 189c065942 | |||
| d198526289 | |||
| 79d2658671 | |||
| 8a28ce7bc2 | |||
| 41798d5bbc | |||
| 529394e5c1 | |||
| 9debb58e48 | |||
| 62ed36bb5d | |||
| fcde633f7c | |||
| e21e36dd2c | |||
| a20c71e9e8 | |||
| ac8c438a79 | |||
| 039132be20 | |||
| de24dd706e | |||
| 86c1beb402 | |||
| 7c1734b09e | |||
| c2308ad2a0 | |||
| c187163090 | |||
| f8bdcfa3f1 | |||
| a76ac88af8 | |||
| 7d0ae00361 | |||
| 81a23623d8 | |||
| ce5dd9e8d6 | |||
| e603ab00ee | |||
| da4c7ccc07 | |||
| db08a6d13c | |||
| a744167956 | |||
| 4cd8296f39 | |||
| 9c949b1c46 | |||
| c381056e6d | |||
| d44f8b2385 | |||
| 200adc9e75 | |||
| c2d0df95ba | |||
| 2a7dcbfbb0 | |||
| c16a5686fe | |||
| 8f1eb6f5e4 | |||
| 5e431bead8 | |||
| f8ef2dbd7b | |||
| 7d2c1d24b0 | |||
| ec534e6a23 | |||
| 50f22d17a8 | |||
| b834e0de59 | |||
| 36d2d09023 | |||
| 0de10ac11c | |||
| b07fb4f1c2 | |||
| a81a9f78fd | |||
| 1c8486301f | |||
| 8703edd3e9 | |||
| 8bb93daca0 | |||
| 18bcfb999a | |||
| 8ee75f7c3a | |||
| c2808f39d1 | |||
| 1f416db292 | |||
| d13527daed | |||
| 2c144b0f63 | |||
| d859dc2b25 | |||
| b47b1f67dc | |||
| 759e507ce5 | |||
| 3b8b5be3b7 | |||
| 35e9e350ca | |||
| a24832b7b2 | |||
| cf6e3fd787 | |||
| 473571b083 | |||
| 2fb448f2c8 | |||
| 17c4865b83 | |||
| 00946d7953 | |||
| 659fdb4da8 | |||
| 99a218282c | |||
| 66181ce2b8 | |||
| c4c0ff8664 | |||
| 89cf958c00 | |||
| 7e62146b13 | |||
| 66f58bf38d | |||
| c55b62d4cb | |||
| 4cb32b70ed | |||
| 555db979f6 | |||
| de9484858e | |||
| fb92e07186 | |||
| bcedbb2781 | |||
| f4dd18ea36 | |||
| 60a512d923 | |||
| cea170ec96 | |||
| da3ec15f3c | |||
| f5a8386c32 | |||
| be341502db | |||
| 5705b41fb8 | |||
| 8ad3c43257 | |||
| 500d7e542c | |||
| 56d88aad29 | |||
| 6fad5776c0 | |||
| b5bb769c27 | |||
| cb0854a380 | |||
| a753a3a2be | |||
| c63e40956b | |||
| bd5fb3a888 | |||
| 67aa2318c1 | |||
| 75c493f767 | |||
| ef07f96faf | |||
| 9198f5afac | |||
| d5c35f6d69 | |||
| 389e056bfe | |||
| b45e1d674a | |||
| 494317ad57 |
+153
-3
@@ -503,6 +503,7 @@ TESTSRC2 = \
|
||||
$(TOP)/src/pcache1.c \
|
||||
$(TOP)/src/select.c \
|
||||
$(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/treeview.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vdbeapi.c \
|
||||
@@ -630,7 +631,7 @@ FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
FUZZCHECK_SRC = $(TOP)/test/fuzzcheck.c $(TOP)/test/ossfuzz.c
|
||||
FUZZCHECK_SRC = $(TOP)/test/fuzzcheck.c $(TOP)/test/ossfuzz.c $(TOP)/test/fuzzinvariants.c
|
||||
DBFUZZ_OPT =
|
||||
|
||||
# This is the default Makefile target. The objects listed here
|
||||
@@ -874,7 +875,7 @@ hash.lo: $(TOP)/src/hash.c $(HDR)
|
||||
insert.lo: $(TOP)/src/insert.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/insert.c
|
||||
|
||||
json.lo: $(TOP)/src/json.c
|
||||
json.lo: $(TOP)/src/json.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/json.c
|
||||
|
||||
legacy.lo: $(TOP)/src/legacy.c $(HDR)
|
||||
@@ -1280,6 +1281,12 @@ valgrindfuzz: fuzzcheck$(TEXT) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessio
|
||||
tcltest: ./testfixture$(TEXE)
|
||||
./testfixture$(TEXE) $(TOP)/test/veryquick.test $(TESTOPTS)
|
||||
|
||||
# Runs all the same tests cases as the "tcltest" target but uses
|
||||
# the testrunner.tcl script to run them in multiple cores
|
||||
# concurrently.
|
||||
testrunner: testfixture$(TEXE)
|
||||
./testfixture$(TEXE) $(TOP)/test/testrunner.tcl
|
||||
|
||||
# Minimal testing that runs in less than 3 minutes
|
||||
#
|
||||
quicktest: ./testfixture$(TEXE)
|
||||
@@ -1469,6 +1476,7 @@ clean:
|
||||
rm -rf .libs .deps
|
||||
rm -f lemon$(BEXE) lempar.c parse.* sqlite*.tar.gz
|
||||
rm -f mkkeywordhash$(BEXE) keywordhash.h
|
||||
rm -f mksourceid$(BEXE)
|
||||
rm -f *.da *.bb *.bbg gmon.out
|
||||
rm -rf tsrc .target_source
|
||||
rm -f tclsqlite3$(TEXE)
|
||||
@@ -1493,7 +1501,8 @@ clean:
|
||||
rm -f threadtest5
|
||||
|
||||
distclean: clean
|
||||
rm -f config.h config.log config.status libtool Makefile sqlite3.pc
|
||||
rm -f config.h config.log config.status libtool Makefile sqlite3.pc \
|
||||
$(TESTPROGS)
|
||||
|
||||
#
|
||||
# Windows section
|
||||
@@ -1512,3 +1521,144 @@ sqlite3.def: $(REAL_LIBOBJ)
|
||||
sqlite3.dll: $(REAL_LIBOBJ) sqlite3.def
|
||||
$(TCC) -shared -o $@ sqlite3.def \
|
||||
-Wl,"--strip-all" $(REAL_LIBOBJ)
|
||||
|
||||
|
||||
#
|
||||
# fiddle/wasm section
|
||||
#
|
||||
# Maintenance reminder: we can/should move this into the wasm-specific
|
||||
# GNU Make makefile, but we currently need it here for access to
|
||||
# $(SHELL_OPT). The rest of the wasm-related bits are handled via GNU
|
||||
# Make in ext/wasm/...
|
||||
#
|
||||
wasm_dir = ext/wasm
|
||||
wasm_dir_abs = $(TOP)/ext/wasm
|
||||
# ^^^ some emcc opts require absolute paths
|
||||
fiddle_dir = $(wasm_dir)/fiddle
|
||||
fiddle_dir_abs = $(TOP)/$(fiddle_dir)
|
||||
fiddle_module_js = $(fiddle_dir)/fiddle-module.js
|
||||
#emcc_opt = -O0
|
||||
#emcc_opt = -O1
|
||||
#emcc_opt = -O2
|
||||
#emcc_opt = -O3
|
||||
emcc_opt = -Oz
|
||||
emcc_flags = $(emcc_opt) \
|
||||
-sALLOW_TABLE_GROWTH \
|
||||
-sABORTING_MALLOC \
|
||||
-sSTRICT_JS \
|
||||
-sENVIRONMENT=web \
|
||||
-sMODULARIZE \
|
||||
-sEXPORTED_RUNTIME_METHODS=@$(wasm_dir_abs)/EXPORTED_RUNTIME_METHODS.fiddle \
|
||||
-sDYNAMIC_EXECUTION=0 \
|
||||
--minify 0 \
|
||||
-I. $(SHELL_OPT) \
|
||||
-DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_UTF16 -DSQLITE_OMIT_DEPRECATED
|
||||
$(fiddle_module_js): Makefile sqlite3.c shell.c \
|
||||
$(wasm_dir)/EXPORTED_RUNTIME_METHODS.fiddle \
|
||||
$(wasm_dir)/EXPORTED_FUNCTIONS.fiddle
|
||||
emcc -o $@ $(emcc_flags) \
|
||||
-sEXPORT_NAME=initFiddleModule \
|
||||
-sEXPORTED_FUNCTIONS=@$(wasm_dir_abs)/EXPORTED_FUNCTIONS.fiddle \
|
||||
-DSQLITE_SHELL_FIDDLE \
|
||||
sqlite3.c shell.c
|
||||
gzip < $@ > $@.gz
|
||||
gzip < $(fiddle_dir)/fiddle-module.wasm > $(fiddle_dir)/fiddle-module.wasm.gz
|
||||
$(fiddle_dir)/fiddle.js.gz: $(fiddle_dir)/fiddle.js
|
||||
gzip < $< > $@
|
||||
|
||||
fiddle_generated = $(fiddle_module_js) $(fiddle_module_js).gz \
|
||||
$(fiddle_dir)/fiddle-module.wasm \
|
||||
$(fiddle_dir)/fiddle-module.wasm.gz \
|
||||
$(fiddle_dir)/fiddle.js.gz
|
||||
|
||||
clean-fiddle:
|
||||
rm -f $(fiddle_generated)
|
||||
clean: clean-fiddle
|
||||
fiddle: $(fiddle_module_js) $(fiddle_dir)/fiddle.js.gz
|
||||
wasm: fiddle
|
||||
########################################################################
|
||||
# Explanation of the emcc build flags follows. Full docs for these can
|
||||
# be found at:
|
||||
#
|
||||
# https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
|
||||
#
|
||||
# -sENVIRONMENT=web: elides bootstrap code related to non-web JS
|
||||
# environments like node.js. Removing this makes the output a tiny
|
||||
# tick larger but hypothetically makes it more portable to
|
||||
# non-browser JS environments.
|
||||
#
|
||||
# -sMODULARIZE: changes how the generated code is structured to avoid
|
||||
# declaring a global Module object and instead installing a function
|
||||
# which loads and initializes the module. The function is named...
|
||||
#
|
||||
# -sEXPORT_NAME=jsFunctionName (see -sMODULARIZE)
|
||||
#
|
||||
# -sEXPORTED_RUNTIME_METHODS=@/absolute/path/to/file: a file
|
||||
# containing a list of emscripten-supplied APIs, one per line, which
|
||||
# must be exported into the generated JS. Must be an absolute path!
|
||||
#
|
||||
# -sEXPORTED_FUNCTIONS=@/absolute/path/to/file: a file containing a
|
||||
# list of C functions, one per line, which must be exported via wasm
|
||||
# so they're visible to JS. C symbols names in that file must all
|
||||
# start with an underscore for reasons known only to the emcc
|
||||
# developers. e.g., _sqlite3_open_v2 and _sqlite3_finalize. Must be
|
||||
# an absolute path!
|
||||
#
|
||||
# -sSTRICT_JS ensures that the emitted JS code includes the 'use
|
||||
# strict' option. Note that -sSTRICT is more broadly-scoped and
|
||||
# results in build errors.
|
||||
#
|
||||
# -sALLOW_TABLE_GROWTH is required for (at a minimum) the UDF-binding
|
||||
# feature. Without it, JS functions cannot be made to proxy C-side
|
||||
# callbacks.
|
||||
#
|
||||
# -sABORTING_MALLOC causes the JS-bound _malloc() to abort rather than
|
||||
# return 0 on OOM. If set to 0 then all code which uses _malloc()
|
||||
# must, just like in C, check the result before using it, else
|
||||
# they're likely to corrupt the JS/WASM heap by writing to its
|
||||
# address of 0. It is, as of this writing, enabled in Emscripten by
|
||||
# default but we enable it explicitly in case that default changes.
|
||||
#
|
||||
# -sDYNAMIC_EXECUTION=0 disables eval() and the Function constructor.
|
||||
# If the build runs without these, it's preferable to use this flag
|
||||
# because certain execution environments disallow those constructs.
|
||||
# This flag is not strictly necessary, however.
|
||||
#
|
||||
# -sWASM_BIGINT is UNTESTED but "should" allow the int64-using C APIs
|
||||
# to work with JS/wasm, insofar as the JS environment supports the
|
||||
# BigInt type. That support requires an extremely recent browser:
|
||||
# Safari didn't get that support until late 2020.
|
||||
#
|
||||
# --no-entry: for compiling library code with no main(). If this is
|
||||
# not supplied and the code has a main(), it is called as part of the
|
||||
# module init process. Note that main() is #if'd out of shell.c
|
||||
# (renamed) when building in wasm mode.
|
||||
#
|
||||
# --pre-js/--post-js=FILE relative or absolute paths to JS files to
|
||||
# prepend/append to the emcc-generated bootstrapping JS. It's
|
||||
# easier/faster to develop with separate JS files (reduces rebuilding
|
||||
# requirements) but certain configurations, namely -sMODULARIZE, may
|
||||
# require using at least a --pre-js file. They can be used
|
||||
# individually and need not be paired.
|
||||
#
|
||||
# -O0..-O3 and -Oz: optimization levels affect not only C-style
|
||||
# optimization but whether or not the resulting generated JS code
|
||||
# gets minified. -O0 compiles _much_ more quickly than -O3 or -Oz,
|
||||
# and doesn't minimize any JS code, so is recommended for
|
||||
# development. -O3 or -Oz are recommended for deployment, but
|
||||
# primarily because -Oz will shrink the wasm file notably. JS-side
|
||||
# minification makes little difference in terms of overall
|
||||
# distributable size.
|
||||
#
|
||||
# --minify 0: disables minification of the generated JS code,
|
||||
# regardless of optimization level. Minification of the JS has
|
||||
# minimal overall effect in the larger scheme of things and results
|
||||
# in JS files which can neither be edited nor viewed as text files in
|
||||
# Fossil (which flags them as binary because of their extreme line
|
||||
# lengths). Interestingly, whether or not the comments in the
|
||||
# generated JS file get stripped is unaffected by this setting and
|
||||
# depends entirely on the optimization level. Higher optimization
|
||||
# levels reduce the size of the JS considerably even without
|
||||
# minification.
|
||||
#
|
||||
########################################################################
|
||||
|
||||
+7
-1
@@ -1705,7 +1705,7 @@ FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_GEOPOLY
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
|
||||
FUZZCHECK_SRC = $(TOP)\test\fuzzcheck.c $(TOP)\test\ossfuzz.c
|
||||
FUZZCHECK_SRC = $(TOP)\test\fuzzcheck.c $(TOP)\test\ossfuzz.c $(TOP)\test\fuzzinvariants.c
|
||||
OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c
|
||||
DBFUZZ_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION
|
||||
KV_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ
|
||||
@@ -2475,6 +2475,12 @@ tcltest: testfixture.exe
|
||||
@set PATH=$(LIBTCLPATH);$(PATH)
|
||||
.\testfixture.exe $(TOP)\test\veryquick.test $(TESTOPTS)
|
||||
|
||||
# Runs all the same tests cases as the "tcltest" target but uses
|
||||
# the testrunner.tcl script to run them in multiple cores
|
||||
# concurrently.
|
||||
testrunner: testfixture.exe
|
||||
.\testfixture.exe $(TOP)\test\testrunner.tcl
|
||||
|
||||
smoketest: $(TESTPROGS)
|
||||
@set PATH=$(LIBTCLPATH);$(PATH)
|
||||
.\testfixture.exe $(TOP)\test\main.test $(TESTOPTS)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<h1 align="center">SQLite Source Repository</h1>
|
||||
|
||||
This repository contains the complete source code for the
|
||||
[SQLite database engine](https://sqlite.org/). Some test scripts
|
||||
This repository contains the complete source code for the
|
||||
[SQLite database engine](https://sqlite.org/). Some test scripts
|
||||
are also included. However, many other test scripts
|
||||
and most of the documentation are managed separately.
|
||||
|
||||
@@ -15,7 +15,7 @@ The [Fossil repository](https://sqlite.org/src/timeline) contains the urtext.
|
||||
If you are reading this on GitHub or some other Git repository or service,
|
||||
then you are looking at a mirror. The names of check-ins and
|
||||
other artifacts in a Git mirror are different from the official
|
||||
names for those objects. The offical names for check-ins are
|
||||
names for those objects. The official names for check-ins are
|
||||
found in a footer on the check-in comment for authorized mirrors.
|
||||
The official check-in name can also be seen in the `manifest.uuid` file
|
||||
in the root of the tree. Always use the official name, not the
|
||||
@@ -30,7 +30,7 @@ verify its integrity, there are hints on how to do that in the
|
||||
If you do not want to use Fossil, you can download tarballs or ZIP
|
||||
archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
|
||||
|
||||
* Lastest trunk check-in as
|
||||
* Latest trunk check-in as
|
||||
[Tarball](https://www.sqlite.org/src/tarball/sqlite.tar.gz),
|
||||
[ZIP-archive](https://www.sqlite.org/src/zip/sqlite.zip), or
|
||||
[SQLite-archive](https://www.sqlite.org/src/sqlar/sqlite.sqlar).
|
||||
@@ -47,11 +47,11 @@ archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
|
||||
then click on the "Tarball" or "ZIP Archive" links on the information
|
||||
page.
|
||||
|
||||
If you do want to use Fossil to check out the source tree,
|
||||
If you do want to use Fossil to check out the source tree,
|
||||
first install Fossil version 2.0 or later.
|
||||
(Source tarballs and precompiled binaries available
|
||||
[here](https://www.fossil-scm.org/fossil/uv/download.html). Fossil is
|
||||
a stand-alone program. To install, simply download or build the single
|
||||
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:
|
||||
|
||||
@@ -61,7 +61,7 @@ Then run commands like this:
|
||||
fossil open ~/Fossils/sqlite.fossil
|
||||
|
||||
After setting up a repository using the steps above, you can always
|
||||
update to the lastest version using:
|
||||
update to the latest version using:
|
||||
|
||||
fossil update trunk ;# latest trunk check-in
|
||||
fossil update release ;# latest official release
|
||||
@@ -136,7 +136,7 @@ the "tclsqlite.c" file which implements the
|
||||
extension and only later escaped to the wild as an independent library.)
|
||||
|
||||
Test scripts and programs are found in the **test/** subdirectory.
|
||||
Addtional test code is found in other source repositories.
|
||||
Additional test code is found in other source repositories.
|
||||
See [How SQLite Is Tested](http://www.sqlite.org/testing.html) for
|
||||
additional information.
|
||||
|
||||
@@ -170,7 +170,7 @@ at just the right spots. Note that comment text in the sqlite3.h file is
|
||||
used to generate much of the SQLite API documentation. The Tcl scripts
|
||||
used to generate that documentation are in a separate source repository.
|
||||
|
||||
The SQL language parser is **parse.c** which is generate from a grammar in
|
||||
The SQL language parser is **parse.c** which is generated from a grammar in
|
||||
the src/parse.y file. The conversion of "parse.y" into "parse.c" is done
|
||||
by the [lemon](./doc/lemon.html) LALR(1) parser generator. The source code
|
||||
for lemon is at tool/lemon.c. Lemon uses the tool/lempar.c file as a
|
||||
@@ -180,7 +180,7 @@ generates parse.c.
|
||||
|
||||
The **opcodes.h** header file contains macros that define the numbers
|
||||
corresponding to opcodes in the "VDBE" virtual machine. The opcodes.h
|
||||
file is generated by the scanning the src/vdbe.c source file. The
|
||||
file is generated by scanning the src/vdbe.c source file. The
|
||||
Tcl script at ./mkopcodeh.tcl does this scan and generates opcodes.h.
|
||||
A second Tcl script, ./mkopcodec.tcl, then scans opcodes.h to generate
|
||||
the **opcodes.c** source file, which contains a reverse mapping from
|
||||
@@ -237,7 +237,7 @@ prepared statements, the description of
|
||||
[how transactions work](http://www.sqlite.org/atomiccommit.html), and
|
||||
the [overview of the query planner](http://www.sqlite.org/optoverview.html).
|
||||
|
||||
Years of effort have gone into optimizating SQLite, both
|
||||
Years of effort have gone into optimizing SQLite, both
|
||||
for small size and high performance. And optimizations tend to result in
|
||||
complex code. So there is a lot of complexity in the current SQLite
|
||||
implementation. It will not be the easiest library in the world to hack.
|
||||
@@ -294,11 +294,11 @@ Key files:
|
||||
building the "testfixture.exe" program. The testfixture.exe program is
|
||||
an enhanced Tcl shell. The testfixture.exe program runs scripts in the
|
||||
test/ folder to validate the core SQLite code. The testfixture program
|
||||
(and some other test programs too) is build and run when you type
|
||||
(and some other test programs too) is built and run when you type
|
||||
"make test".
|
||||
|
||||
* **ext/misc/json1.c** - This file implements the various JSON functions
|
||||
that are build into SQLite.
|
||||
that are built into SQLite.
|
||||
|
||||
There are many other source files. Each has a succinct header comment that
|
||||
describes its purpose and role within the larger system.
|
||||
@@ -307,7 +307,7 @@ describes its purpose and role within the larger system.
|
||||
## Verifying Code Authenticity
|
||||
|
||||
The `manifest` file at the root directory of the source tree
|
||||
contains either a SHA3-256 hash (for newer files) or a SHA1 hash (for
|
||||
contains either a SHA3-256 hash (for newer files) or a SHA1 hash (for
|
||||
older files) for every source file in the repository.
|
||||
The name of the version of the entire source tree is just the
|
||||
SHA3-256 hash of the `manifest` file itself, possibly with the
|
||||
|
||||
+109
-74
@@ -11,8 +11,6 @@
|
||||
#
|
||||
# See the file "license.terms" for information on usage and redistribution
|
||||
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
#
|
||||
# RCS: @(#) $Id: Makefile.in,v 1.59 2005/07/26 19:17:02 mdejong Exp $
|
||||
|
||||
#========================================================================
|
||||
# Add additional lines to handle any additional AC_SUBST cases that
|
||||
@@ -60,6 +58,8 @@ PKG_HEADERS = @PKG_HEADERS@
|
||||
#========================================================================
|
||||
|
||||
PKG_LIB_FILE = @PKG_LIB_FILE@
|
||||
PKG_LIB_FILE8 = @PKG_LIB_FILE8@
|
||||
PKG_LIB_FILE9 = @PKG_LIB_FILE9@
|
||||
PKG_STUB_LIB_FILE = @PKG_STUB_LIB_FILE@
|
||||
|
||||
lib_BINARIES = $(PKG_LIB_FILE)
|
||||
@@ -73,10 +73,11 @@ exec_prefix = @exec_prefix@
|
||||
|
||||
bindir = @bindir@
|
||||
libdir = @libdir@
|
||||
includedir = @includedir@
|
||||
datarootdir = @datarootdir@
|
||||
runstatedir = @runstatedir@
|
||||
datadir = @datadir@
|
||||
mandir = @mandir@
|
||||
includedir = @includedir@
|
||||
|
||||
DESTDIR =
|
||||
|
||||
@@ -85,24 +86,25 @@ pkgdatadir = $(datadir)/$(PKG_DIR)
|
||||
pkglibdir = $(libdir)/$(PKG_DIR)
|
||||
pkgincludedir = $(includedir)/$(PKG_DIR)
|
||||
|
||||
top_builddir = .
|
||||
top_builddir = @abs_top_builddir@
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_OPTIONS =
|
||||
INSTALL = @INSTALL@ $(INSTALL_OPTIONS)
|
||||
INSTALL_DATA_DIR = @INSTALL_DATA_DIR@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_LIBRARY = @INSTALL_LIBRARY@
|
||||
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
CC = @CC@
|
||||
CCLD = @CCLD@
|
||||
CFLAGS_DEFAULT = @CFLAGS_DEFAULT@
|
||||
CFLAGS_WARNING = @CFLAGS_WARNING@
|
||||
CLEANFILES = @CLEANFILES@
|
||||
EXEEXT = @EXEEXT@
|
||||
LDFLAGS_DEFAULT = @LDFLAGS_DEFAULT@
|
||||
MAKE_LIB = @MAKE_LIB@
|
||||
MAKE_SHARED_LIB = @MAKE_SHARED_LIB@
|
||||
MAKE_STATIC_LIB = @MAKE_STATIC_LIB@
|
||||
MAKE_STUB_LIB = @MAKE_STUB_LIB@
|
||||
OBJEXT = @OBJEXT@
|
||||
RANLIB = @RANLIB@
|
||||
@@ -117,8 +119,6 @@ TCL_SRC_DIR = @TCL_SRC_DIR@
|
||||
#TK_BIN_DIR = @TK_BIN_DIR@
|
||||
#TK_SRC_DIR = @TK_SRC_DIR@
|
||||
|
||||
# This is no longer necessary even for packages that use private Tcl headers
|
||||
#TCL_TOP_DIR_NATIVE = @TCL_TOP_DIR_NATIVE@
|
||||
# Not used, but retained for reference of what libs Tcl required
|
||||
#TCL_LIBS = @TCL_LIBS@
|
||||
|
||||
@@ -132,41 +132,52 @@ TCL_SRC_DIR = @TCL_SRC_DIR@
|
||||
EXTRA_PATH = $(top_builddir):$(TCL_BIN_DIR)
|
||||
#EXTRA_PATH = $(top_builddir):$(TCL_BIN_DIR):$(TK_BIN_DIR)
|
||||
TCLLIBPATH = $(top_builddir)
|
||||
TCLSH_ENV = TCL_LIBRARY=`@CYGPATH@ $(TCL_SRC_DIR)/library` \
|
||||
@LD_LIBRARY_PATH_VAR@="$(EXTRA_PATH):$(@LD_LIBRARY_PATH_VAR@)" \
|
||||
TCLSH_ENV = TCL_LIBRARY=`@CYGPATH@ $(TCL_SRC_DIR)/library`
|
||||
PKG_ENV = @LD_LIBRARY_PATH_VAR@="$(EXTRA_PATH):$(@LD_LIBRARY_PATH_VAR@)" \
|
||||
PATH="$(EXTRA_PATH):$(PATH)" \
|
||||
TCLLIBPATH="$(TCLLIBPATH)"
|
||||
# TK_LIBRARY=`@CYGPATH@ $(TK_SRC_DIR)/library`
|
||||
|
||||
TCLSH_PROG = @TCLSH_PROG@
|
||||
TCLSH = $(TCLSH_ENV) $(TCLSH_PROG)
|
||||
TCLSH = $(TCLSH_ENV) $(PKG_ENV) $(TCLSH_PROG)
|
||||
|
||||
#WISH_ENV = TK_LIBRARY=`@CYGPATH@ $(TK_SRC_DIR)/library`
|
||||
#WISH_PROG = @WISH_PROG@
|
||||
#WISH = $(TCLSH_ENV) $(WISH_PROG)
|
||||
|
||||
#WISH = $(TCLSH_ENV) $(WISH_ENV) $(PKG_ENV) $(WISH_PROG)
|
||||
|
||||
SHARED_BUILD = @SHARED_BUILD@
|
||||
|
||||
INCLUDES = @PKG_INCLUDES@ @TCL_INCLUDES@ -I$(srcdir)/..
|
||||
INCLUDES = @PKG_INCLUDES@ @TCL_INCLUDES@ -I. -I$(srcdir)/..
|
||||
#INCLUDES = @PKG_INCLUDES@ @TCL_INCLUDES@ @TK_INCLUDES@ @TK_XINCLUDES@
|
||||
|
||||
PKG_CFLAGS = @PKG_CFLAGS@
|
||||
|
||||
# TCL_DEFS is not strictly need here, but if you remove it, then you
|
||||
# must make sure that configure.in checks for the necessary components
|
||||
# must make sure that configure.ac checks for the necessary components
|
||||
# that your library may use. TCL_DEFS can actually be a problem if
|
||||
# you do not compile with a similar machine setup as the Tcl core was
|
||||
# compiled with.
|
||||
#DEFS = $(TCL_DEFS) @DEFS@ $(PKG_CFLAGS)
|
||||
DEFS = @DEFS@ $(PKG_CFLAGS)
|
||||
|
||||
# Move pkgIndex.tcl to 'BINARIES' var if it is generated in the Makefile
|
||||
CONFIG_CLEAN_FILES = Makefile pkgIndex.tcl
|
||||
CLEANFILES = @CLEANFILES@
|
||||
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LIBS = @PKG_LIBS@ @LIBS@
|
||||
AR = @AR@
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LDFLAGS_DEFAULT = @LDFLAGS_DEFAULT@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) \
|
||||
$(CFLAGS_DEFAULT) $(CFLAGS_WARNING) $(SHLIB_CFLAGS) $(CFLAGS)
|
||||
|
||||
GDB = gdb
|
||||
VALGRIND = valgrind
|
||||
VALGRINDARGS = --tool=memcheck --num-callers=8 --leak-resolution=high \
|
||||
--leak-check=yes --show-reachable=yes -v
|
||||
|
||||
.SUFFIXES: .c .$(OBJEXT)
|
||||
|
||||
#========================================================================
|
||||
# Start of user-definable TARGETS section
|
||||
@@ -174,7 +185,7 @@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(C
|
||||
|
||||
#========================================================================
|
||||
# TEA TARGETS. Please note that the "libraries:" target refers to platform
|
||||
# independent files, and the "binaries:" target inclues executable programs and
|
||||
# independent files, and the "binaries:" target includes executable programs and
|
||||
# platform-dependent libraries. Modify these targets so that they install
|
||||
# the various pieces of your package. The make and install rules
|
||||
# for the BINARIES that you specified above have already been done.
|
||||
@@ -193,7 +204,6 @@ binaries: $(BINARIES)
|
||||
|
||||
libraries:
|
||||
|
||||
|
||||
#========================================================================
|
||||
# Your doc target should differentiate from doc builds (by the developer)
|
||||
# and doc installs (see install-doc), which just install the docs on the
|
||||
@@ -216,11 +226,11 @@ install-binaries: binaries install-lib-binaries install-bin-binaries
|
||||
#========================================================================
|
||||
|
||||
install-libraries: libraries
|
||||
@mkdir -p $(DESTDIR)$(includedir)
|
||||
@$(INSTALL_DATA_DIR) "$(DESTDIR)$(includedir)"
|
||||
@echo "Installing header files in $(DESTDIR)$(includedir)"
|
||||
@list='$(PKG_HEADERS)'; for i in $$list; do \
|
||||
echo "Installing $(srcdir)/$$i" ; \
|
||||
$(INSTALL_DATA) $(srcdir)/$$i $(DESTDIR)$(includedir) ; \
|
||||
$(INSTALL_DATA) $(srcdir)/$$i "$(DESTDIR)$(includedir)" ; \
|
||||
done;
|
||||
|
||||
#========================================================================
|
||||
@@ -229,12 +239,11 @@ install-libraries: libraries
|
||||
#========================================================================
|
||||
|
||||
install-doc: doc
|
||||
@mkdir -p $(DESTDIR)$(mandir)/mann
|
||||
@$(INSTALL_DATA_DIR) "$(DESTDIR)$(mandir)/mann"
|
||||
@echo "Installing documentation in $(DESTDIR)$(mandir)"
|
||||
@list='$(srcdir)/doc/*.n'; for i in $$list; do \
|
||||
echo "Installing $$i"; \
|
||||
rm -f $(DESTDIR)$(mandir)/mann/`basename $$i`; \
|
||||
$(INSTALL_DATA) $$i $(DESTDIR)$(mandir)/mann ; \
|
||||
$(INSTALL_DATA) $$i "$(DESTDIR)$(mandir)/mann" ; \
|
||||
done
|
||||
|
||||
test: binaries libraries
|
||||
@@ -244,7 +253,21 @@ shell: binaries libraries
|
||||
@$(TCLSH) $(SCRIPT)
|
||||
|
||||
gdb:
|
||||
$(TCLSH_ENV) gdb $(TCLSH_PROG) $(SCRIPT)
|
||||
$(TCLSH_ENV) $(PKG_ENV) $(GDB) $(TCLSH_PROG) $(SCRIPT)
|
||||
|
||||
gdb-test: binaries libraries
|
||||
$(TCLSH_ENV) $(PKG_ENV) $(GDB) \
|
||||
--args $(TCLSH_PROG) `@CYGPATH@ $(srcdir)/tests/all.tcl` \
|
||||
$(TESTFLAGS) -singleproc 1 \
|
||||
-load "package ifneeded $(PACKAGE_NAME) $(PACKAGE_VERSION) \
|
||||
[list load `@CYGPATH@ $(PKG_LIB_FILE)` [string totitle $(PACKAGE_NAME)]]"
|
||||
|
||||
valgrind: binaries libraries
|
||||
$(TCLSH_ENV) $(PKG_ENV) $(VALGRIND) $(VALGRINDARGS) $(TCLSH_PROG) \
|
||||
`@CYGPATH@ $(srcdir)/tests/all.tcl` $(TESTFLAGS)
|
||||
|
||||
valgrindshell: binaries libraries
|
||||
$(TCLSH_ENV) $(PKG_ENV) $(VALGRIND) $(VALGRINDARGS) $(TCLSH_PROG) $(SCRIPT)
|
||||
|
||||
depend:
|
||||
|
||||
@@ -283,49 +306,70 @@ $(PKG_STUB_LIB_FILE): $(PKG_STUB_OBJECTS)
|
||||
# As necessary, add $(srcdir):$(srcdir)/compat:....
|
||||
#========================================================================
|
||||
|
||||
VPATH = $(srcdir):$(srcdir)/generic:$(srcdir)/unix:$(srcdir)/win
|
||||
VPATH = $(srcdir):$(srcdir)/generic:$(srcdir)/unix:$(srcdir)/win:$(srcdir)/macosx
|
||||
|
||||
.c.@OBJEXT@:
|
||||
$(COMPILE) -c `@CYGPATH@ $<` -o $@
|
||||
|
||||
tclsample.@OBJEXT@: sampleUuid.h
|
||||
|
||||
$(srcdir)/manifest.uuid:
|
||||
printf "git-" >$(srcdir)/manifest.uuid
|
||||
(cd $(srcdir); git rev-parse HEAD >>$(srcdir)/manifest.uuid || \
|
||||
(printf "svn-r" >$(srcdir)/manifest.uuid ; \
|
||||
svn info --show-item last-changed-revision >>$(srcdir)/manifest.uuid) || \
|
||||
printf "unknown" >$(srcdir)/manifest.uuid)
|
||||
|
||||
sampleUuid.h: $(srcdir)/manifest.uuid
|
||||
echo "#define SAMPLE_VERSION_UUID \\" >$@
|
||||
cat $(srcdir)/manifest.uuid >>$@
|
||||
echo "" >>$@
|
||||
|
||||
#========================================================================
|
||||
# Distribution creation
|
||||
# You may need to tweak this target to make it work correctly.
|
||||
#========================================================================
|
||||
|
||||
#COMPRESS = tar cvf $(PKG_DIR).tar $(PKG_DIR); compress $(PKG_DIR).tar
|
||||
COMPRESS = gtar zcvf $(PKG_DIR).tar.gz $(PKG_DIR)
|
||||
COMPRESS = tar zcvf $(PKG_DIR).tar.gz $(PKG_DIR)
|
||||
DIST_ROOT = /tmp/dist
|
||||
DIST_DIR = $(DIST_ROOT)/$(PKG_DIR)
|
||||
|
||||
DIST_INSTALL_DATA = CPPROG='cp -p' $(INSTALL) -m 644
|
||||
DIST_INSTALL_SCRIPT = CPPROG='cp -p' $(INSTALL) -m 755
|
||||
|
||||
dist-clean:
|
||||
rm -rf $(DIST_DIR) $(DIST_ROOT)/$(PKG_DIR).tar.*
|
||||
|
||||
dist: dist-clean
|
||||
mkdir -p $(DIST_DIR)
|
||||
cp -p $(srcdir)/README* $(srcdir)/license* \
|
||||
$(srcdir)/aclocal.m4 $(srcdir)/configure $(srcdir)/*.in \
|
||||
$(DIST_DIR)/
|
||||
chmod 664 $(DIST_DIR)/Makefile.in $(DIST_DIR)/aclocal.m4
|
||||
chmod 775 $(DIST_DIR)/configure $(DIST_DIR)/configure.in
|
||||
dist: dist-clean $(srcdir)/manifest.uuid
|
||||
$(INSTALL_DATA_DIR) $(DIST_DIR)
|
||||
|
||||
for i in $(srcdir)/*.[ch]; do \
|
||||
if [ -f $$i ]; then \
|
||||
cp -p $$i $(DIST_DIR)/ ; \
|
||||
fi; \
|
||||
done;
|
||||
# TEA files
|
||||
$(DIST_INSTALL_DATA) $(srcdir)/Makefile.in \
|
||||
$(srcdir)/aclocal.m4 $(srcdir)/configure.ac \
|
||||
$(DIST_DIR)/
|
||||
$(DIST_INSTALL_SCRIPT) $(srcdir)/configure $(DIST_DIR)/
|
||||
|
||||
mkdir $(DIST_DIR)/tclconfig
|
||||
cp $(srcdir)/tclconfig/install-sh $(srcdir)/tclconfig/tcl.m4 \
|
||||
$(DIST_DIR)/tclconfig/
|
||||
chmod 664 $(DIST_DIR)/tclconfig/tcl.m4
|
||||
chmod +x $(DIST_DIR)/tclconfig/install-sh
|
||||
$(INSTALL_DATA_DIR) $(DIST_DIR)/tclconfig
|
||||
$(DIST_INSTALL_DATA) $(srcdir)/tclconfig/README.txt \
|
||||
$(srcdir)/manifest.uuid \
|
||||
$(srcdir)/tclconfig/tcl.m4 $(srcdir)/tclconfig/install-sh \
|
||||
$(DIST_DIR)/tclconfig/
|
||||
|
||||
list='demos doc generic library mac tests unix win'; \
|
||||
# Extension files
|
||||
$(DIST_INSTALL_DATA) \
|
||||
$(srcdir)/ChangeLog \
|
||||
$(srcdir)/README.sha \
|
||||
$(srcdir)/license.terms \
|
||||
$(srcdir)/README \
|
||||
$(srcdir)/pkgIndex.tcl.in \
|
||||
$(DIST_DIR)/
|
||||
|
||||
list='demos doc generic library macosx tests unix win'; \
|
||||
for p in $$list; do \
|
||||
if test -d $(srcdir)/$$p ; then \
|
||||
mkdir $(DIST_DIR)/$$p; \
|
||||
cp -p $(srcdir)/$$p/*.* $(DIST_DIR)/$$p/; \
|
||||
$(INSTALL_DATA_DIR) $(DIST_DIR)/$$p; \
|
||||
$(DIST_INSTALL_DATA) $(srcdir)/$$p/* $(DIST_DIR)/$$p/; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
@@ -337,10 +381,10 @@ dist: dist-clean
|
||||
|
||||
#========================================================================
|
||||
# Don't modify the file to clean here. Instead, set the "CLEANFILES"
|
||||
# variable in configure.in
|
||||
# variable in configure.ac
|
||||
#========================================================================
|
||||
|
||||
clean:
|
||||
clean:
|
||||
-test -z "$(BINARIES)" || rm -f $(BINARIES)
|
||||
-rm -f *.$(OBJEXT) core *.core
|
||||
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
|
||||
@@ -348,7 +392,7 @@ clean:
|
||||
distclean: clean
|
||||
-rm -f *.tab.c
|
||||
-rm -f $(CONFIG_CLEAN_FILES)
|
||||
-rm -f config.h config.cache config.log config.status
|
||||
-rm -f config.cache config.log config.status
|
||||
|
||||
#========================================================================
|
||||
# Install binary object libraries. On Windows this includes both .dll and
|
||||
@@ -362,25 +406,17 @@ distclean: clean
|
||||
#========================================================================
|
||||
|
||||
install-lib-binaries: binaries
|
||||
@mkdir -p $(DESTDIR)$(pkglibdir)
|
||||
@$(INSTALL_DATA_DIR) "$(DESTDIR)$(pkglibdir)"
|
||||
@list='$(lib_BINARIES)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(pkglibdir)/$$p"; \
|
||||
$(INSTALL_PROGRAM) $$p $(DESTDIR)$(pkglibdir)/$$p; \
|
||||
stub=`echo $$p|sed -e "s/.*\(stub\).*/\1/"`; \
|
||||
if test "x$$stub" = "xstub"; then \
|
||||
echo " $(RANLIB_STUB) $(DESTDIR)$(pkglibdir)/$$p"; \
|
||||
$(RANLIB_STUB) $(DESTDIR)$(pkglibdir)/$$p; \
|
||||
else \
|
||||
echo " $(RANLIB) $(DESTDIR)$(pkglibdir)/$$p"; \
|
||||
$(RANLIB) $(DESTDIR)$(pkglibdir)/$$p; \
|
||||
fi; \
|
||||
echo " $(INSTALL_LIBRARY) $$p $(DESTDIR)$(pkglibdir)/$$p"; \
|
||||
$(INSTALL_LIBRARY) $$p "$(DESTDIR)$(pkglibdir)/$$p"; \
|
||||
ext=`echo $$p|sed -e "s/.*\.//"`; \
|
||||
if test "x$$ext" = "xdll"; then \
|
||||
lib=`basename $$p|sed -e 's/.[^.]*$$//'`.lib; \
|
||||
if test -f $$lib; then \
|
||||
echo " $(INSTALL_DATA) $$lib $(DESTDIR)$(pkglibdir)/$$lib"; \
|
||||
$(INSTALL_DATA) $$lib $(DESTDIR)$(pkglibdir)/$$lib; \
|
||||
$(INSTALL_DATA) $$lib "$(DESTDIR)$(pkglibdir)/$$lib"; \
|
||||
fi; \
|
||||
fi; \
|
||||
fi; \
|
||||
@@ -389,12 +425,12 @@ install-lib-binaries: binaries
|
||||
if test -f $(srcdir)/$$p; then \
|
||||
destp=`basename $$p`; \
|
||||
echo " Install $$destp $(DESTDIR)$(pkglibdir)/$$destp"; \
|
||||
$(INSTALL_DATA) $(srcdir)/$$p $(DESTDIR)$(pkglibdir)/$$destp; \
|
||||
$(INSTALL_DATA) $(srcdir)/$$p "$(DESTDIR)$(pkglibdir)/$$destp"; \
|
||||
fi; \
|
||||
done
|
||||
@if test "x$(SHARED_BUILD)" = "x1"; then \
|
||||
echo " Install pkgIndex.tcl $(DESTDIR)$(pkglibdir)"; \
|
||||
$(INSTALL_DATA) pkgIndex.tcl $(DESTDIR)$(pkglibdir); \
|
||||
$(INSTALL_DATA) pkgIndex.tcl "$(DESTDIR)$(pkglibdir)"; \
|
||||
fi
|
||||
|
||||
#========================================================================
|
||||
@@ -407,33 +443,32 @@ install-lib-binaries: binaries
|
||||
#========================================================================
|
||||
|
||||
install-bin-binaries: binaries
|
||||
@mkdir -p $(DESTDIR)$(bindir)
|
||||
@$(INSTALL_DATA_DIR) "$(DESTDIR)$(bindir)"
|
||||
@list='$(bin_BINARIES)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$p"; \
|
||||
$(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$p; \
|
||||
$(INSTALL_PROGRAM) $$p "$(DESTDIR)$(bindir)/$$p"; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
.SUFFIXES: .c .$(OBJEXT)
|
||||
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
cd $(top_builddir) \
|
||||
&& CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status
|
||||
|
||||
uninstall-binaries:
|
||||
list='$(lib_BINARIES)'; for p in $$list; do \
|
||||
rm -f $(DESTDIR)$(pkglibdir)/$$p; \
|
||||
rm -f "$(DESTDIR)$(pkglibdir)/$$p"; \
|
||||
done
|
||||
list='$(PKG_TCL_SOURCES)'; for p in $$list; do \
|
||||
p=`basename $$p`; \
|
||||
rm -f $(DESTDIR)$(pkglibdir)/$$p; \
|
||||
rm -f "$(DESTDIR)$(pkglibdir)/$$p"; \
|
||||
done
|
||||
list='$(bin_BINARIES)'; for p in $$list; do \
|
||||
rm -f $(DESTDIR)$(bindir)/$$p; \
|
||||
rm -f "$(DESTDIR)$(bindir)/$$p"; \
|
||||
done
|
||||
|
||||
.PHONY: all binaries clean depend distclean doc install libraries test
|
||||
.PHONY: gdb gdb-test valgrind valgrindshell
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
|
||||
+60
-34
@@ -2,11 +2,9 @@
|
||||
dnl This file is an input file used by the GNU "autoconf" program to
|
||||
dnl generate the file "configure", which is run during Tcl installation
|
||||
dnl to configure the system for the local environment.
|
||||
#
|
||||
# RCS: @(#) $Id: configure.in,v 1.43 2005/07/26 19:17:05 mdejong Exp $
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Sample configure.in for Tcl Extensions. The only places you should
|
||||
# Sample configure.ac for Tcl Extensions. The only places you should
|
||||
# need to modify this file are marked by the string __CHANGE__
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
@@ -17,9 +15,11 @@ dnl to configure the system for the local environment.
|
||||
# This initializes the environment with PACKAGE_NAME and PACKAGE_VERSION
|
||||
# set as provided. These will also be added as -D defs in your Makefile
|
||||
# so you can encode the package version directly into the source files.
|
||||
# This will also define a special symbol for Windows (BUILD_<PACKAGE_NAME>
|
||||
# so that we create the export library with the dll.
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
AC_INIT([sqlite], [3.32.0])
|
||||
AC_INIT([sqlite],[3.40.0])
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Call TEA_INIT as the first TEA_ macro to set up initial vars.
|
||||
@@ -27,7 +27,7 @@ AC_INIT([sqlite], [3.32.0])
|
||||
# as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE.
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
TEA_INIT([3.9])
|
||||
TEA_INIT()
|
||||
|
||||
AC_CONFIG_AUX_DIR(tclconfig)
|
||||
|
||||
@@ -55,8 +55,8 @@ TEA_PREFIX
|
||||
#-----------------------------------------------------------------------
|
||||
# Standard compiler checks.
|
||||
# This sets up CC by using the CC env var, or looks for gcc otherwise.
|
||||
# This also calls AC_PROG_CC, AC_PROG_INSTALL and a few others to create
|
||||
# the basic setup necessary to compile executables.
|
||||
# This also calls AC_PROG_CC and a few others to create the basic setup
|
||||
# necessary to compile executables.
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
TEA_SETUP_COMPILER
|
||||
@@ -73,11 +73,19 @@ TEA_SETUP_COMPILER
|
||||
|
||||
TEA_ADD_SOURCES([tclsqlite3.c])
|
||||
TEA_ADD_HEADERS([])
|
||||
TEA_ADD_INCLUDES([-I\"`\${CYGPATH} \${srcdir}/generic`\"])
|
||||
TEA_ADD_INCLUDES([])
|
||||
TEA_ADD_LIBS([])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_ENABLE_FTS3=1])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_ENABLE_FTS4=1])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_ENABLE_FTS5=1])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_3_SUFFIX_ONLY=1])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_ENABLE_RTREE=1])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_ENABLE_GEOPOLY=1])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_ENABLE_MATH_FUNCTIONS=1])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_ENABLE_DESERIALIZE=1])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_ENABLE_DBPAGE_VTAB=1])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_ENABLE_BYTECODE_VTAB=1])
|
||||
TEA_ADD_CFLAGS([-DSQLITE_ENABLE_DBSTAT_VTAB=1])
|
||||
TEA_ADD_STUB_SOURCES([])
|
||||
TEA_ADD_TCL_SOURCES([])
|
||||
|
||||
@@ -99,6 +107,31 @@ if test x$with_system_sqlite != xno; then
|
||||
LIBS="$LIBS -lsqlite3"])])
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# __CHANGE__
|
||||
#
|
||||
# You can add more files to clean if your extension creates any extra
|
||||
# files by extending CLEANFILES.
|
||||
# Add pkgIndex.tcl if it is generated in the Makefile instead of ./configure
|
||||
# and change Makefile.in to move it from CONFIG_CLEAN_FILES to BINARIES var.
|
||||
#
|
||||
# A few miscellaneous platform-specific items:
|
||||
# TEA_ADD_* any platform specific compiler/build info here.
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
#CLEANFILES="$CLEANFILES pkgIndex.tcl"
|
||||
if test "${TEA_PLATFORM}" = "windows" ; then
|
||||
# Ensure no empty if clauses
|
||||
:
|
||||
#TEA_ADD_SOURCES([win/winFile.c])
|
||||
#TEA_ADD_INCLUDES([-I\"$(${CYGPATH} ${srcdir}/win)\"])
|
||||
else
|
||||
# Ensure no empty else clauses
|
||||
:
|
||||
#TEA_ADD_SOURCES([unix/unixFile.c])
|
||||
#TEA_ADD_LIBS([-lsuperfly])
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# __CHANGE__
|
||||
# Choose which headers you need. Extension authors should try very
|
||||
@@ -151,28 +184,6 @@ TEA_CONFIG_CFLAGS
|
||||
|
||||
TEA_ENABLE_SYMBOLS
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Everyone should be linking against the Tcl stub library. If you
|
||||
# can't for some reason, remove this definition. If you aren't using
|
||||
# stubs, you also need to modify the SHLIB_LD_LIBS setting below to
|
||||
# link against the non-stubbed Tcl library. Add Tk too if necessary.
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
AC_DEFINE(USE_TCL_STUBS, 1, [Use Tcl stubs])
|
||||
#AC_DEFINE(USE_TK_STUBS, 1, [Use Tk stubs])
|
||||
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Redefine fdatasync as fsync on systems that lack fdatasync
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
#AC_CHECK_FUNC(fdatasync, , AC_DEFINE(fdatasync, fsync))
|
||||
# Check for library functions that SQLite can optionally use.
|
||||
AC_CHECK_FUNCS([fdatasync usleep fullfsync localtime_r gmtime_r])
|
||||
|
||||
AC_FUNC_STRERROR_R
|
||||
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# This macro generates a line to use when building a library. It
|
||||
# depends on values set by the TEA_ENABLE_SHARED, TEA_ENABLE_SYMBOLS,
|
||||
@@ -193,9 +204,24 @@ TEA_PROG_TCLSH
|
||||
#TEA_PROG_WISH
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Finally, substitute all of the various values into the Makefile.
|
||||
# You may alternatively have a special pkgIndex.tcl.in or other files
|
||||
# which require substituting th AC variables in. Include these here.
|
||||
# Setup a *Config.sh.in configuration file.
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
AC_OUTPUT([Makefile pkgIndex.tcl])
|
||||
#TEA_EXPORT_CONFIG([sample])
|
||||
#AC_SUBST(SAMPLE_VAR)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Specify files to substitute AC variables in. You may alternatively
|
||||
# have a special pkgIndex.tcl.in or other files which require
|
||||
# substituting the AC variables in. Include these here.
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
AC_CONFIG_FILES([Makefile pkgIndex.tcl])
|
||||
#AC_CONFIG_FILES([sampleConfig.sh])
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Finally, substitute all of the various values into the files
|
||||
# specified with AC_CONFIG_FILES.
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
# -*- tcl -*-
|
||||
# Tcl package index file, version 1.1
|
||||
#
|
||||
# Tcl package index file
|
||||
#
|
||||
# Note sqlite*3* init specifically
|
||||
#
|
||||
package ifneeded sqlite3 @PACKAGE_VERSION@ \
|
||||
[list load [file join $dir @PKG_LIB_FILE@] Sqlite3]
|
||||
if {[package vsatisfies [package provide Tcl] 9.0-]} {
|
||||
package ifneeded sqlite3 @PACKAGE_VERSION@ \
|
||||
[list load [file join $dir @PKG_LIB_FILE9@] sqlite3]
|
||||
} else {
|
||||
package ifneeded sqlite3 @PACKAGE_VERSION@ \
|
||||
[list load [file join $dir @PKG_LIB_FILE8@] sqlite3]
|
||||
}
|
||||
|
||||
+525
-626
File diff suppressed because it is too large
Load Diff
@@ -251,7 +251,18 @@ INCLUDES = $(SQL_INCLUDES) $(TCL_INCLUDES) -I"$(WINDIR)" \
|
||||
-I"$(GENERICDIR)" -I"$(ROOT)\.."
|
||||
BASE_CLFAGS = $(cflags) $(cdebug) $(crt) $(INCLUDES) \
|
||||
-DSQLITE_3_SUFFIX_ONLY=1 -DSQLITE_ENABLE_RTREE=1 \
|
||||
-DSQLITE_ENABLE_FTS3=1 -DSQLITE_OMIT_DEPRECATED=1
|
||||
-DSQLITE_ENABLE_FTS3=1 -DSQLITE_OMIT_DEPRECATED=1 \
|
||||
-DSQLITE_ENABLE_FTS4=1 \
|
||||
-DSQLITE_ENABLE_FTS5=1 \
|
||||
-DSQLITE_3_SUFFIX_ONLY=1 \
|
||||
-DSQLITE_ENABLE_RTREE=1 \
|
||||
-DSQLITE_ENABLE_GEOPOLY=1 \
|
||||
-DSQLITE_ENABLE_MATH_FUNCTIONS=1 \
|
||||
-DSQLITE_ENABLE_DESERIALIZE=1 \
|
||||
-DSQLITE_ENABLE_DBPAGE_VTAB=1 \
|
||||
-DSQLITE_ENABLE_BYTECODE_VTAB=1 \
|
||||
-DSQLITE_ENABLE_DBSTAT_VTAB=1
|
||||
|
||||
CON_CFLAGS = $(cflags) $(cdebug) $(crt) -DCONSOLE -DSQLITE_ENABLE_FTS3=1
|
||||
TCL_CFLAGS = -DBUILD_sqlite -DUSE_TCL_STUBS \
|
||||
-DPACKAGE_VERSION="\"$(DOTVERSION)\"" $(BASE_CLFAGS) \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.39.0.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.40.0.
|
||||
#
|
||||
#
|
||||
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
|
||||
@@ -726,8 +726,8 @@ MAKEFLAGS=
|
||||
# Identity of this package.
|
||||
PACKAGE_NAME='sqlite'
|
||||
PACKAGE_TARNAME='sqlite'
|
||||
PACKAGE_VERSION='3.39.0'
|
||||
PACKAGE_STRING='sqlite 3.39.0'
|
||||
PACKAGE_VERSION='3.40.0'
|
||||
PACKAGE_STRING='sqlite 3.40.0'
|
||||
PACKAGE_BUGREPORT=''
|
||||
PACKAGE_URL=''
|
||||
|
||||
@@ -1468,7 +1468,7 @@ if test "$ac_init_help" = "long"; then
|
||||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat <<_ACEOF
|
||||
\`configure' configures sqlite 3.39.0 to adapt to many kinds of systems.
|
||||
\`configure' configures sqlite 3.40.0 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -1533,7 +1533,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of sqlite 3.39.0:";;
|
||||
short | recursive ) echo "Configuration of sqlite 3.40.0:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@@ -1661,7 +1661,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
sqlite configure 3.39.0
|
||||
sqlite configure 3.40.0
|
||||
generated by GNU Autoconf 2.69
|
||||
|
||||
Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
@@ -2080,7 +2080,7 @@ cat >config.log <<_ACEOF
|
||||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by sqlite $as_me 3.39.0, which was
|
||||
It was created by sqlite $as_me 3.40.0, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
@@ -12390,7 +12390,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
||||
# report actual input values of CONFIG_FILES etc. instead of their
|
||||
# values after options handling.
|
||||
ac_log="
|
||||
This file was extended by sqlite $as_me 3.39.0, which was
|
||||
This file was extended by sqlite $as_me 3.40.0, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@@ -12456,7 +12456,7 @@ _ACEOF
|
||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
|
||||
ac_cs_version="\\
|
||||
sqlite config.status 3.39.0
|
||||
sqlite config.status 3.40.0
|
||||
configured by $0, generated by GNU Autoconf 2.69,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
|
||||
@@ -391,6 +391,16 @@ do_setup_rec_test $tn.18.1 {
|
||||
SEARCH SomeObject USING COVERING INDEX SomeObject_idx_00000078 (x=?)
|
||||
}
|
||||
|
||||
|
||||
do_setup_rec_test $tn.19.0 {
|
||||
CREATE TABLE t1("index");
|
||||
} {
|
||||
SELECT * FROM t1 ORDER BY "index";
|
||||
} {
|
||||
CREATE INDEX t1_idx_01a7214e ON t1('index');
|
||||
SCAN t1 USING COVERING INDEX t1_idx_01a7214e
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
proc do_candidates_test {tn sql res} {
|
||||
|
||||
@@ -820,6 +820,10 @@ static char *idxAppendText(int *pRc, char *zIn, const char *zFmt, ...){
|
||||
*/
|
||||
static int idxIdentifierRequiresQuotes(const char *zId){
|
||||
int i;
|
||||
int nId = STRLEN(zId);
|
||||
|
||||
if( sqlite3_keyword_check(zId, nId) ) return 1;
|
||||
|
||||
for(i=0; zId[i]; i++){
|
||||
if( !(zId[i]=='_')
|
||||
&& !(zId[i]>='0' && zId[i]<='9')
|
||||
|
||||
+11
-9
@@ -2888,7 +2888,7 @@ static int fts3TermSelectMerge(
|
||||
**
|
||||
** Similar padding is added in the fts3DoclistOrMerge() function.
|
||||
*/
|
||||
pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1);
|
||||
pTS->aaOutput[0] = sqlite3_malloc64((i64)nDoclist + FTS3_VARINT_MAX + 1);
|
||||
pTS->anOutput[0] = nDoclist;
|
||||
if( pTS->aaOutput[0] ){
|
||||
memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
|
||||
@@ -4308,8 +4308,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
|
||||
char *aPoslist = 0; /* Position list for deferred tokens */
|
||||
int nPoslist = 0; /* Number of bytes in aPoslist */
|
||||
int iPrev = -1; /* Token number of previous deferred token */
|
||||
|
||||
assert( pPhrase->doclist.bFreeList==0 );
|
||||
char *aFree = (pPhrase->doclist.bFreeList ? pPhrase->doclist.pList : 0);
|
||||
|
||||
for(iToken=0; iToken<pPhrase->nToken; iToken++){
|
||||
Fts3PhraseToken *pToken = &pPhrase->aToken[iToken];
|
||||
@@ -4323,6 +4322,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
|
||||
|
||||
if( pList==0 ){
|
||||
sqlite3_free(aPoslist);
|
||||
sqlite3_free(aFree);
|
||||
pPhrase->doclist.pList = 0;
|
||||
pPhrase->doclist.nList = 0;
|
||||
return SQLITE_OK;
|
||||
@@ -4343,6 +4343,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
|
||||
nPoslist = (int)(aOut - aPoslist);
|
||||
if( nPoslist==0 ){
|
||||
sqlite3_free(aPoslist);
|
||||
sqlite3_free(aFree);
|
||||
pPhrase->doclist.pList = 0;
|
||||
pPhrase->doclist.nList = 0;
|
||||
return SQLITE_OK;
|
||||
@@ -4375,13 +4376,14 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
|
||||
nDistance = iPrev - nMaxUndeferred;
|
||||
}
|
||||
|
||||
aOut = (char *)sqlite3_malloc(nPoslist+8);
|
||||
aOut = (char *)sqlite3Fts3MallocZero(nPoslist+FTS3_BUFFER_PADDING);
|
||||
if( !aOut ){
|
||||
sqlite3_free(aPoslist);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
pPhrase->doclist.pList = aOut;
|
||||
assert( p1 && p2 );
|
||||
if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){
|
||||
pPhrase->doclist.bFreeList = 1;
|
||||
pPhrase->doclist.nList = (int)(aOut - pPhrase->doclist.pList);
|
||||
@@ -4394,6 +4396,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
|
||||
}
|
||||
}
|
||||
|
||||
if( pPhrase->doclist.pList!=aFree ) sqlite3_free(aFree);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
#endif /* SQLITE_DISABLE_FTS4_DEFERRED */
|
||||
@@ -4742,7 +4745,7 @@ static int fts3EvalIncrPhraseNext(
|
||||
if( bEof==0 ){
|
||||
int nList = 0;
|
||||
int nByte = a[p->nToken-1].nList;
|
||||
char *aDoclist = sqlite3_malloc(nByte+FTS3_BUFFER_PADDING);
|
||||
char *aDoclist = sqlite3_malloc64((i64)nByte+FTS3_BUFFER_PADDING);
|
||||
if( !aDoclist ) return SQLITE_NOMEM;
|
||||
memcpy(aDoclist, a[p->nToken-1].pList, nByte+1);
|
||||
memset(&aDoclist[nByte], 0, FTS3_BUFFER_PADDING);
|
||||
@@ -5568,11 +5571,10 @@ static int fts3EvalTestExpr(
|
||||
|
||||
default: {
|
||||
#ifndef SQLITE_DISABLE_FTS4_DEFERRED
|
||||
if( pCsr->pDeferred
|
||||
&& (pExpr->iDocid==pCsr->iPrevId || pExpr->bDeferred)
|
||||
){
|
||||
if( pCsr->pDeferred && (pExpr->bDeferred || (
|
||||
pExpr->iDocid==pCsr->iPrevId && pExpr->pPhrase->doclist.pList
|
||||
))){
|
||||
Fts3Phrase *pPhrase = pExpr->pPhrase;
|
||||
assert( pExpr->bDeferred || pPhrase->doclist.bFreeList==0 );
|
||||
if( pExpr->bDeferred ){
|
||||
fts3EvalInvalidatePoslist(pPhrase);
|
||||
}
|
||||
|
||||
+1
-1
@@ -558,7 +558,7 @@ struct Fts3MultiSegReader {
|
||||
int nAdvance; /* How many seg-readers to advance */
|
||||
Fts3SegFilter *pFilter; /* Pointer to filter object */
|
||||
char *aBuffer; /* Buffer to merge doclists in */
|
||||
int nBuffer; /* Allocated size of aBuffer[] in bytes */
|
||||
i64 nBuffer; /* Allocated size of aBuffer[] in bytes */
|
||||
|
||||
int iColFilter; /* If >=0, filter for this column */
|
||||
int bRestart;
|
||||
|
||||
@@ -621,7 +621,7 @@ static int porterNext(
|
||||
if( n>c->nAllocated ){
|
||||
char *pNew;
|
||||
c->nAllocated = n+20;
|
||||
pNew = sqlite3_realloc(c->zToken, c->nAllocated);
|
||||
pNew = sqlite3_realloc64(c->zToken, c->nAllocated);
|
||||
if( !pNew ) return SQLITE_NOMEM;
|
||||
c->zToken = pNew;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ static int simpleNext(
|
||||
if( n>c->nTokenAllocated ){
|
||||
char *pNew;
|
||||
c->nTokenAllocated = n+20;
|
||||
pNew = sqlite3_realloc(c->pToken, c->nTokenAllocated);
|
||||
pNew = sqlite3_realloc64(c->pToken, c->nTokenAllocated);
|
||||
if( !pNew ) return SQLITE_NOMEM;
|
||||
c->pToken = pNew;
|
||||
}
|
||||
|
||||
+35
-30
@@ -649,7 +649,7 @@ static int fts3PendingListAppendVarint(
|
||||
|
||||
/* Allocate or grow the PendingList as required. */
|
||||
if( !p ){
|
||||
p = sqlite3_malloc(sizeof(*p) + 100);
|
||||
p = sqlite3_malloc64(sizeof(*p) + 100);
|
||||
if( !p ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -658,14 +658,14 @@ static int fts3PendingListAppendVarint(
|
||||
p->nData = 0;
|
||||
}
|
||||
else if( p->nData+FTS3_VARINT_MAX+1>p->nSpace ){
|
||||
int nNew = p->nSpace * 2;
|
||||
p = sqlite3_realloc(p, sizeof(*p) + nNew);
|
||||
i64 nNew = p->nSpace * 2;
|
||||
p = sqlite3_realloc64(p, sizeof(*p) + nNew);
|
||||
if( !p ){
|
||||
sqlite3_free(*pp);
|
||||
*pp = 0;
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
p->nSpace = nNew;
|
||||
p->nSpace = (int)nNew;
|
||||
p->aData = (char *)&p[1];
|
||||
}
|
||||
|
||||
@@ -1222,7 +1222,7 @@ int sqlite3Fts3ReadBlock(
|
||||
int nByte = sqlite3_blob_bytes(p->pSegments);
|
||||
*pnBlob = nByte;
|
||||
if( paBlob ){
|
||||
char *aByte = sqlite3_malloc(nByte + FTS3_NODE_PADDING);
|
||||
char *aByte = sqlite3_malloc64((i64)nByte + FTS3_NODE_PADDING);
|
||||
if( !aByte ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -1339,7 +1339,7 @@ static int fts3SegReaderNext(
|
||||
int nTerm = fts3HashKeysize(pElem);
|
||||
if( (nTerm+1)>pReader->nTermAlloc ){
|
||||
sqlite3_free(pReader->zTerm);
|
||||
pReader->zTerm = (char*)sqlite3_malloc((nTerm+1)*2);
|
||||
pReader->zTerm = (char*)sqlite3_malloc64(((i64)nTerm+1)*2);
|
||||
if( !pReader->zTerm ) return SQLITE_NOMEM;
|
||||
pReader->nTermAlloc = (nTerm+1)*2;
|
||||
}
|
||||
@@ -1347,7 +1347,7 @@ static int fts3SegReaderNext(
|
||||
pReader->zTerm[nTerm] = '\0';
|
||||
pReader->nTerm = nTerm;
|
||||
|
||||
aCopy = (char*)sqlite3_malloc(nCopy);
|
||||
aCopy = (char*)sqlite3_malloc64(nCopy);
|
||||
if( !aCopy ) return SQLITE_NOMEM;
|
||||
memcpy(aCopy, pList->aData, nCopy);
|
||||
pReader->nNode = pReader->nDoclist = nCopy;
|
||||
@@ -1634,7 +1634,7 @@ int sqlite3Fts3SegReaderNew(
|
||||
nExtra = nRoot + FTS3_NODE_PADDING;
|
||||
}
|
||||
|
||||
pReader = (Fts3SegReader *)sqlite3_malloc(sizeof(Fts3SegReader) + nExtra);
|
||||
pReader = (Fts3SegReader *)sqlite3_malloc64(sizeof(Fts3SegReader) + nExtra);
|
||||
if( !pReader ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -1726,7 +1726,7 @@ int sqlite3Fts3SegReaderPending(
|
||||
if( nElem==nAlloc ){
|
||||
Fts3HashElem **aElem2;
|
||||
nAlloc += 16;
|
||||
aElem2 = (Fts3HashElem **)sqlite3_realloc(
|
||||
aElem2 = (Fts3HashElem **)sqlite3_realloc64(
|
||||
aElem, nAlloc*sizeof(Fts3HashElem *)
|
||||
);
|
||||
if( !aElem2 ){
|
||||
@@ -2060,7 +2060,7 @@ static int fts3NodeAddTerm(
|
||||
** this is not expected to be a serious problem.
|
||||
*/
|
||||
assert( pTree->aData==(char *)&pTree[1] );
|
||||
pTree->aData = (char *)sqlite3_malloc(nReq);
|
||||
pTree->aData = (char *)sqlite3_malloc64(nReq);
|
||||
if( !pTree->aData ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -2078,7 +2078,7 @@ static int fts3NodeAddTerm(
|
||||
|
||||
if( isCopyTerm ){
|
||||
if( pTree->nMalloc<nTerm ){
|
||||
char *zNew = sqlite3_realloc(pTree->zMalloc, nTerm*2);
|
||||
char *zNew = sqlite3_realloc64(pTree->zMalloc, (i64)nTerm*2);
|
||||
if( !zNew ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -2104,7 +2104,7 @@ static int fts3NodeAddTerm(
|
||||
** now. Instead, the term is inserted into the parent of pTree. If pTree
|
||||
** has no parent, one is created here.
|
||||
*/
|
||||
pNew = (SegmentNode *)sqlite3_malloc(sizeof(SegmentNode) + p->nNodeSize);
|
||||
pNew = (SegmentNode *)sqlite3_malloc64(sizeof(SegmentNode) + p->nNodeSize);
|
||||
if( !pNew ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -2242,7 +2242,7 @@ static int fts3SegWriterAdd(
|
||||
){
|
||||
int nPrefix; /* Size of term prefix in bytes */
|
||||
int nSuffix; /* Size of term suffix in bytes */
|
||||
int nReq; /* Number of bytes required on leaf page */
|
||||
i64 nReq; /* Number of bytes required on leaf page */
|
||||
int nData;
|
||||
SegmentWriter *pWriter = *ppWriter;
|
||||
|
||||
@@ -2251,13 +2251,13 @@ static int fts3SegWriterAdd(
|
||||
sqlite3_stmt *pStmt;
|
||||
|
||||
/* Allocate the SegmentWriter structure */
|
||||
pWriter = (SegmentWriter *)sqlite3_malloc(sizeof(SegmentWriter));
|
||||
pWriter = (SegmentWriter *)sqlite3_malloc64(sizeof(SegmentWriter));
|
||||
if( !pWriter ) return SQLITE_NOMEM;
|
||||
memset(pWriter, 0, sizeof(SegmentWriter));
|
||||
*ppWriter = pWriter;
|
||||
|
||||
/* Allocate a buffer in which to accumulate data */
|
||||
pWriter->aData = (char *)sqlite3_malloc(p->nNodeSize);
|
||||
pWriter->aData = (char *)sqlite3_malloc64(p->nNodeSize);
|
||||
if( !pWriter->aData ) return SQLITE_NOMEM;
|
||||
pWriter->nSize = p->nNodeSize;
|
||||
|
||||
@@ -2332,7 +2332,7 @@ static int fts3SegWriterAdd(
|
||||
** the buffer to make it large enough.
|
||||
*/
|
||||
if( nReq>pWriter->nSize ){
|
||||
char *aNew = sqlite3_realloc(pWriter->aData, nReq);
|
||||
char *aNew = sqlite3_realloc64(pWriter->aData, nReq);
|
||||
if( !aNew ) return SQLITE_NOMEM;
|
||||
pWriter->aData = aNew;
|
||||
pWriter->nSize = nReq;
|
||||
@@ -2357,7 +2357,7 @@ static int fts3SegWriterAdd(
|
||||
*/
|
||||
if( isCopyTerm ){
|
||||
if( nTerm>pWriter->nMalloc ){
|
||||
char *zNew = sqlite3_realloc(pWriter->zMalloc, nTerm*2);
|
||||
char *zNew = sqlite3_realloc64(pWriter->zMalloc, (i64)nTerm*2);
|
||||
if( !zNew ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -2665,12 +2665,12 @@ static void fts3ColumnFilter(
|
||||
static int fts3MsrBufferData(
|
||||
Fts3MultiSegReader *pMsr, /* Multi-segment-reader handle */
|
||||
char *pList,
|
||||
int nList
|
||||
i64 nList
|
||||
){
|
||||
if( nList>pMsr->nBuffer ){
|
||||
char *pNew;
|
||||
pMsr->nBuffer = nList*2;
|
||||
pNew = (char *)sqlite3_realloc(pMsr->aBuffer, pMsr->nBuffer);
|
||||
pNew = (char *)sqlite3_realloc64(pMsr->aBuffer, pMsr->nBuffer);
|
||||
if( !pNew ) return SQLITE_NOMEM;
|
||||
pMsr->aBuffer = pNew;
|
||||
}
|
||||
@@ -2726,7 +2726,7 @@ int sqlite3Fts3MsrIncrNext(
|
||||
fts3SegReaderSort(pMsr->apSegment, nMerge, j, xCmp);
|
||||
|
||||
if( nList>0 && fts3SegReaderIsPending(apSegment[0]) ){
|
||||
rc = fts3MsrBufferData(pMsr, pList, nList+1);
|
||||
rc = fts3MsrBufferData(pMsr, pList, (i64)nList+1);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
|
||||
pList = pMsr->aBuffer;
|
||||
@@ -2863,11 +2863,11 @@ int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int fts3GrowSegReaderBuffer(Fts3MultiSegReader *pCsr, int nReq){
|
||||
static int fts3GrowSegReaderBuffer(Fts3MultiSegReader *pCsr, i64 nReq){
|
||||
if( nReq>pCsr->nBuffer ){
|
||||
char *aNew;
|
||||
pCsr->nBuffer = nReq*2;
|
||||
aNew = sqlite3_realloc(pCsr->aBuffer, pCsr->nBuffer);
|
||||
aNew = sqlite3_realloc64(pCsr->aBuffer, pCsr->nBuffer);
|
||||
if( !aNew ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -2958,7 +2958,8 @@ int sqlite3Fts3SegReaderStep(
|
||||
){
|
||||
pCsr->nDoclist = apSegment[0]->nDoclist;
|
||||
if( fts3SegReaderIsPending(apSegment[0]) ){
|
||||
rc = fts3MsrBufferData(pCsr, apSegment[0]->aDoclist, pCsr->nDoclist);
|
||||
rc = fts3MsrBufferData(pCsr, apSegment[0]->aDoclist,
|
||||
(i64)pCsr->nDoclist);
|
||||
pCsr->aDoclist = pCsr->aBuffer;
|
||||
}else{
|
||||
pCsr->aDoclist = apSegment[0]->aDoclist;
|
||||
@@ -3011,7 +3012,8 @@ int sqlite3Fts3SegReaderStep(
|
||||
|
||||
nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0);
|
||||
|
||||
rc = fts3GrowSegReaderBuffer(pCsr, nByte+nDoclist+FTS3_NODE_PADDING);
|
||||
rc = fts3GrowSegReaderBuffer(pCsr,
|
||||
(i64)nByte+nDoclist+FTS3_NODE_PADDING);
|
||||
if( rc ) return rc;
|
||||
|
||||
if( isFirst ){
|
||||
@@ -3037,7 +3039,7 @@ int sqlite3Fts3SegReaderStep(
|
||||
fts3SegReaderSort(apSegment, nMerge, j, xCmp);
|
||||
}
|
||||
if( nDoclist>0 ){
|
||||
rc = fts3GrowSegReaderBuffer(pCsr, nDoclist+FTS3_NODE_PADDING);
|
||||
rc = fts3GrowSegReaderBuffer(pCsr, (i64)nDoclist+FTS3_NODE_PADDING);
|
||||
if( rc ) return rc;
|
||||
memset(&pCsr->aBuffer[nDoclist], 0, FTS3_NODE_PADDING);
|
||||
pCsr->aDoclist = pCsr->aBuffer;
|
||||
@@ -3750,7 +3752,7 @@ struct NodeReader {
|
||||
static void blobGrowBuffer(Blob *pBlob, int nMin, int *pRc){
|
||||
if( *pRc==SQLITE_OK && nMin>pBlob->nAlloc ){
|
||||
int nAlloc = nMin;
|
||||
char *a = (char *)sqlite3_realloc(pBlob->a, nAlloc);
|
||||
char *a = (char *)sqlite3_realloc64(pBlob->a, nAlloc);
|
||||
if( a ){
|
||||
pBlob->nAlloc = nAlloc;
|
||||
pBlob->a = a;
|
||||
@@ -3899,6 +3901,8 @@ static int fts3IncrmergePush(
|
||||
pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nPrefix);
|
||||
}
|
||||
pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nSuffix);
|
||||
assert( nPrefix+nSuffix<=nTerm );
|
||||
assert( nPrefix>=0 );
|
||||
memcpy(&pBlk->a[pBlk->n], &zTerm[nPrefix], nSuffix);
|
||||
pBlk->n += nSuffix;
|
||||
|
||||
@@ -4021,6 +4025,7 @@ static int fts3IncrmergeAppend(
|
||||
pLeaf = &pWriter->aNodeWriter[0];
|
||||
nPrefix = fts3PrefixCompress(pLeaf->key.a, pLeaf->key.n, zTerm, nTerm);
|
||||
nSuffix = nTerm - nPrefix;
|
||||
if(nSuffix<=0 ) return FTS_CORRUPT_VTAB;
|
||||
|
||||
nSpace = sqlite3Fts3VarintLen(nPrefix);
|
||||
nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix;
|
||||
@@ -4544,7 +4549,7 @@ static int fts3RepackSegdirLevel(
|
||||
if( nIdx>=nAlloc ){
|
||||
int *aNew;
|
||||
nAlloc += 16;
|
||||
aNew = sqlite3_realloc(aIdx, nAlloc*sizeof(int));
|
||||
aNew = sqlite3_realloc64(aIdx, nAlloc*sizeof(int));
|
||||
if( !aNew ){
|
||||
rc = SQLITE_NOMEM;
|
||||
break;
|
||||
@@ -4918,7 +4923,7 @@ int sqlite3Fts3Incrmerge(Fts3Table *p, int nMerge, int nMin){
|
||||
|
||||
/* Allocate space for the cursor, filter and writer objects */
|
||||
const int nAlloc = sizeof(*pCsr) + sizeof(*pFilter) + sizeof(*pWriter);
|
||||
pWriter = (IncrmergeWriter *)sqlite3_malloc(nAlloc);
|
||||
pWriter = (IncrmergeWriter *)sqlite3_malloc64(nAlloc);
|
||||
if( !pWriter ) return SQLITE_NOMEM;
|
||||
pFilter = (Fts3SegFilter *)&pWriter[1];
|
||||
pCsr = (Fts3MultiSegReader *)&pFilter[1];
|
||||
@@ -5554,7 +5559,7 @@ int sqlite3Fts3DeferredTokenList(
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
pRet = (char *)sqlite3_malloc(p->pList->nData);
|
||||
pRet = (char *)sqlite3_malloc64(p->pList->nData);
|
||||
if( !pRet ) return SQLITE_NOMEM;
|
||||
|
||||
nSkip = sqlite3Fts3GetVarint(p->pList->aData, &dummy);
|
||||
@@ -5574,7 +5579,7 @@ int sqlite3Fts3DeferToken(
|
||||
int iCol /* Column that token must appear in (or -1) */
|
||||
){
|
||||
Fts3DeferredToken *pDeferred;
|
||||
pDeferred = sqlite3_malloc(sizeof(*pDeferred));
|
||||
pDeferred = sqlite3_malloc64(sizeof(*pDeferred));
|
||||
if( !pDeferred ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
+1
-1
@@ -286,7 +286,7 @@ void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...);
|
||||
char *sqlite3Fts5Mprintf(int *pRc, const char *zFmt, ...);
|
||||
|
||||
#define fts5BufferZero(x) sqlite3Fts5BufferZero(x)
|
||||
#define fts5BufferAppendVarint(a,b,c) sqlite3Fts5BufferAppendVarint(a,b,c)
|
||||
#define fts5BufferAppendVarint(a,b,c) sqlite3Fts5BufferAppendVarint(a,b,(i64)c)
|
||||
#define fts5BufferFree(a) sqlite3Fts5BufferFree(a)
|
||||
#define fts5BufferAppendBlob(a,b,c,d) sqlite3Fts5BufferAppendBlob(a,b,c,d)
|
||||
#define fts5BufferSet(a,b,c,d) sqlite3Fts5BufferSet(a,b,c,d)
|
||||
|
||||
@@ -1627,6 +1627,9 @@ Fts5ExprNearset *sqlite3Fts5ParseNearset(
|
||||
}else{
|
||||
if( pRet->nPhrase>0 ){
|
||||
Fts5ExprPhrase *pLast = pRet->apPhrase[pRet->nPhrase-1];
|
||||
assert( pParse!=0 );
|
||||
assert( pParse->apPhrase!=0 );
|
||||
assert( pParse->nPhrase>=2 );
|
||||
assert( pLast==pParse->apPhrase[pParse->nPhrase-2] );
|
||||
if( pPhrase->nTerm==0 ){
|
||||
fts5ExprPhraseFree(pPhrase);
|
||||
|
||||
+13
-11
@@ -296,7 +296,7 @@ struct Fts5Index {
|
||||
sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
|
||||
sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
|
||||
sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
|
||||
sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=? */
|
||||
sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
|
||||
sqlite3_stmt *pIdxSelect;
|
||||
int nRead; /* Total number of blocks read */
|
||||
|
||||
@@ -4087,7 +4087,9 @@ static void fts5WriteAppendRowid(
|
||||
fts5BufferAppendVarint(&p->rc, &pPage->buf, iRowid);
|
||||
}else{
|
||||
assert_nc( p->rc || iRowid>pWriter->iPrevRowid );
|
||||
fts5BufferAppendVarint(&p->rc, &pPage->buf, iRowid - pWriter->iPrevRowid);
|
||||
fts5BufferAppendVarint(&p->rc, &pPage->buf,
|
||||
(u64)iRowid - (u64)pWriter->iPrevRowid
|
||||
);
|
||||
}
|
||||
pWriter->iPrevRowid = iRowid;
|
||||
pWriter->bFirstRowidInDoclist = 0;
|
||||
@@ -4851,7 +4853,7 @@ int sqlite3Fts5IndexMerge(Fts5Index *p, int nMerge){
|
||||
|
||||
static void fts5AppendRowid(
|
||||
Fts5Index *p,
|
||||
i64 iDelta,
|
||||
u64 iDelta,
|
||||
Fts5Iter *pUnused,
|
||||
Fts5Buffer *pBuf
|
||||
){
|
||||
@@ -4861,7 +4863,7 @@ static void fts5AppendRowid(
|
||||
|
||||
static void fts5AppendPoslist(
|
||||
Fts5Index *p,
|
||||
i64 iDelta,
|
||||
u64 iDelta,
|
||||
Fts5Iter *pMulti,
|
||||
Fts5Buffer *pBuf
|
||||
){
|
||||
@@ -4936,10 +4938,10 @@ static void fts5MergeAppendDocid(
|
||||
}
|
||||
#endif
|
||||
|
||||
#define fts5MergeAppendDocid(pBuf, iLastRowid, iRowid) { \
|
||||
assert( (pBuf)->n!=0 || (iLastRowid)==0 ); \
|
||||
fts5BufferSafeAppendVarint((pBuf), (iRowid) - (iLastRowid)); \
|
||||
(iLastRowid) = (iRowid); \
|
||||
#define fts5MergeAppendDocid(pBuf, iLastRowid, iRowid) { \
|
||||
assert( (pBuf)->n!=0 || (iLastRowid)==0 ); \
|
||||
fts5BufferSafeAppendVarint((pBuf), (u64)(iRowid) - (u64)(iLastRowid)); \
|
||||
(iLastRowid) = (iRowid); \
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -5210,7 +5212,7 @@ static void fts5SetupPrefixIter(
|
||||
int nMerge = 1;
|
||||
|
||||
void (*xMerge)(Fts5Index*, Fts5Buffer*, int, Fts5Buffer*);
|
||||
void (*xAppend)(Fts5Index*, i64, Fts5Iter*, Fts5Buffer*);
|
||||
void (*xAppend)(Fts5Index*, u64, Fts5Iter*, Fts5Buffer*);
|
||||
if( p->pConfig->eDetail==FTS5_DETAIL_NONE ){
|
||||
xMerge = fts5MergeRowidLists;
|
||||
xAppend = fts5AppendRowid;
|
||||
@@ -5249,7 +5251,7 @@ static void fts5SetupPrefixIter(
|
||||
Fts5SegIter *pSeg = &p1->aSeg[ p1->aFirst[1].iFirst ];
|
||||
p1->xSetOutputs(p1, pSeg);
|
||||
if( p1->base.nData ){
|
||||
xAppend(p, p1->base.iRowid-iLastRowid, p1, &doclist);
|
||||
xAppend(p, (u64)p1->base.iRowid-(u64)iLastRowid, p1, &doclist);
|
||||
iLastRowid = p1->base.iRowid;
|
||||
}
|
||||
}
|
||||
@@ -5297,7 +5299,7 @@ static void fts5SetupPrefixIter(
|
||||
iLastRowid = 0;
|
||||
}
|
||||
|
||||
xAppend(p, p1->base.iRowid-iLastRowid, p1, &doclist);
|
||||
xAppend(p, (u64)p1->base.iRowid-(u64)iLastRowid, p1, &doclist);
|
||||
iLastRowid = p1->base.iRowid;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing the FTS5 module.
|
||||
#
|
||||
# TESTRUNNER: slow
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5ah
|
||||
|
||||
@@ -16,12 +16,16 @@ source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
source $testdir/malloc_common.tcl
|
||||
set testprefix fts5fault4
|
||||
|
||||
# If SQLITE_ENABLE_FTS3 is defined, omit this file.
|
||||
# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
set ::TMPDBERROR [list 1 \
|
||||
{unable to open a temporary database file for storing temporary tables}
|
||||
]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# An OOM while dropping an fts5 table.
|
||||
#
|
||||
@@ -391,7 +395,7 @@ do_faultsim_test 14.1 -faults oom-t* -prep {
|
||||
} -body {
|
||||
db eval { ALTER TABLE "tbl one" RENAME TO "tbl two" }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
faultsim_test_result {0 {}} $::TMPDBERROR
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
# 2022 August 9
|
||||
#
|
||||
# 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 test is focused on edge cases that cause ubsan errors.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5ubsan
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE x1 USING fts5(x);
|
||||
}
|
||||
|
||||
set BIG 9000000000000000000
|
||||
set SMALL -9000000000000000000
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
BEGIN;
|
||||
INSERT INTO x1 (rowid, x) VALUES($BIG, 'aaa aba acc');
|
||||
INSERT INTO x1 (rowid, x) VALUES($SMALL, 'aaa abc acb');
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
SELECT rowid, x FROM x1('ab*');
|
||||
} [list $SMALL {aaa abc acb} $BIG {aaa aba acc}]
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
SELECT rowid, x FROM x1('ac*');
|
||||
} [list $SMALL {aaa abc acb} $BIG {aaa aba acc}]
|
||||
|
||||
reset_db
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE x1 USING fts5(x);
|
||||
}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
INSERT INTO x1 (rowid, x) VALUES($BIG, 'aaa aba acc');
|
||||
INSERT INTO x1 (rowid, x) VALUES($SMALL, 'aaa abc acb');
|
||||
}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
INSERT INTO x1 (x1) VALUES('optimize');
|
||||
}
|
||||
|
||||
finish_test
|
||||
+3
-2
@@ -299,8 +299,9 @@ static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){
|
||||
|
||||
if( U_SUCCESS(status) ){
|
||||
sqlite3_set_auxdata(p, 0, pExpr, icuRegexpDelete);
|
||||
}else{
|
||||
assert(!pExpr);
|
||||
pExpr = sqlite3_get_auxdata(p, 0);
|
||||
}
|
||||
if( !pExpr ){
|
||||
icuFunctionError(p, "uregex_open", status);
|
||||
return;
|
||||
}
|
||||
|
||||
+8
-1
@@ -280,6 +280,7 @@ static char *csv_read_one_field(CsvReader *p){
|
||||
}
|
||||
p->cTerm = (char)c;
|
||||
}
|
||||
assert( p->z==0 || p->n<p->nAlloc );
|
||||
if( p->z ) p->z[p->n] = 0;
|
||||
p->bNotFirst = 1;
|
||||
return p->z;
|
||||
@@ -750,7 +751,7 @@ static int csvtabNext(sqlite3_vtab_cursor *cur){
|
||||
i++;
|
||||
}
|
||||
}while( pCur->rdr.cTerm==',' );
|
||||
if( z==0 || (pCur->rdr.cTerm==EOF && i<pTab->nCol) ){
|
||||
if( z==0 && i==0 ){
|
||||
pCur->iRowid = -1;
|
||||
}else{
|
||||
pCur->iRowid++;
|
||||
@@ -811,6 +812,12 @@ static int csvtabFilter(
|
||||
CsvCursor *pCur = (CsvCursor*)pVtabCursor;
|
||||
CsvTable *pTab = (CsvTable*)pVtabCursor->pVtab;
|
||||
pCur->iRowid = 0;
|
||||
|
||||
/* Ensure the field buffer is always allocated. Otherwise, if the
|
||||
** first field is zero bytes in size, this may be mistaken for an OOM
|
||||
** error in csvtabNext(). */
|
||||
if( csv_append(&pCur->rdr, 0) ) return SQLITE_NOMEM;
|
||||
|
||||
if( pCur->rdr.in==0 ){
|
||||
assert( pCur->rdr.zIn==pTab->zData );
|
||||
assert( pTab->iStart>=0 );
|
||||
|
||||
+117
-10
@@ -72,6 +72,7 @@ SQLITE_EXTENSION_INIT1
|
||||
|
||||
/* The end-of-input character */
|
||||
#define RE_EOF 0 /* End of input */
|
||||
#define RE_START 0xfffffff /* Start of input - larger than an UTF-8 */
|
||||
|
||||
/* The NFA is implemented as sequence of opcodes taken from the following
|
||||
** set. Each opcode has a single integer argument.
|
||||
@@ -93,6 +94,33 @@ SQLITE_EXTENSION_INIT1
|
||||
#define RE_OP_SPACE 15 /* space: [ \t\n\r\v\f] */
|
||||
#define RE_OP_NOTSPACE 16 /* Not a digit */
|
||||
#define RE_OP_BOUNDARY 17 /* Boundary between word and non-word */
|
||||
#define RE_OP_ATSTART 18 /* Currently at the start of the string */
|
||||
|
||||
#if defined(SQLITE_DEBUG)
|
||||
/* Opcode names used for symbolic debugging */
|
||||
static const char *ReOpName[] = {
|
||||
"EOF",
|
||||
"MATCH",
|
||||
"ANY",
|
||||
"ANYSTAR",
|
||||
"FORK",
|
||||
"GOTO",
|
||||
"ACCEPT",
|
||||
"CC_INC",
|
||||
"CC_EXC",
|
||||
"CC_VALUE",
|
||||
"CC_RANGE",
|
||||
"WORD",
|
||||
"NOTWORD",
|
||||
"DIGIT",
|
||||
"NOTDIGIT",
|
||||
"SPACE",
|
||||
"NOTSPACE",
|
||||
"BOUNDARY",
|
||||
"ATSTART",
|
||||
};
|
||||
#endif /* SQLITE_DEBUG */
|
||||
|
||||
|
||||
/* Each opcode is a "state" in the NFA */
|
||||
typedef unsigned short ReStateNumber;
|
||||
@@ -127,7 +155,7 @@ struct ReCompiled {
|
||||
int *aArg; /* Arguments to each operator */
|
||||
unsigned (*xNextChar)(ReInput*); /* Next character function */
|
||||
unsigned char zInit[12]; /* Initial text to match */
|
||||
int nInit; /* Number of characters in zInit */
|
||||
int nInit; /* Number of bytes in zInit */
|
||||
unsigned nState; /* Number of entries in aOp[] and aArg[] */
|
||||
unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */
|
||||
};
|
||||
@@ -200,7 +228,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
ReStateNumber *pToFree;
|
||||
unsigned int i = 0;
|
||||
unsigned int iSwap = 0;
|
||||
int c = RE_EOF+1;
|
||||
int c = RE_START;
|
||||
int cPrev = 0;
|
||||
int rc = 0;
|
||||
ReInput in;
|
||||
@@ -219,6 +247,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
in.i++;
|
||||
}
|
||||
if( in.i+pRe->nInit>in.mx ) return 0;
|
||||
c = RE_START-1;
|
||||
}
|
||||
|
||||
if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
|
||||
@@ -247,6 +276,10 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
|
||||
break;
|
||||
}
|
||||
case RE_OP_ATSTART: {
|
||||
if( cPrev==RE_START ) re_add_state(pThis, x+1);
|
||||
break;
|
||||
}
|
||||
case RE_OP_ANY: {
|
||||
if( c!=0 ) re_add_state(pNext, x+1);
|
||||
break;
|
||||
@@ -328,7 +361,9 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
}
|
||||
}
|
||||
for(i=0; i<pNext->nState; i++){
|
||||
if( pRe->aOp[pNext->aState[i]]==RE_OP_ACCEPT ){ rc = 1; break; }
|
||||
int x = pNext->aState[i];
|
||||
while( pRe->aOp[x]==RE_OP_GOTO ) x += pRe->aArg[x];
|
||||
if( pRe->aOp[x]==RE_OP_ACCEPT ){ rc = 1; break; }
|
||||
}
|
||||
re_match_end:
|
||||
sqlite3_free(pToFree);
|
||||
@@ -483,7 +518,6 @@ static const char *re_subcompile_string(ReCompiled *p){
|
||||
iStart = p->nState;
|
||||
switch( c ){
|
||||
case '|':
|
||||
case '$':
|
||||
case ')': {
|
||||
p->sIn.i--;
|
||||
return 0;
|
||||
@@ -520,6 +554,14 @@ static const char *re_subcompile_string(ReCompiled *p){
|
||||
re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
|
||||
break;
|
||||
}
|
||||
case '$': {
|
||||
re_append(p, RE_OP_MATCH, RE_EOF);
|
||||
break;
|
||||
}
|
||||
case '^': {
|
||||
re_append(p, RE_OP_ATSTART, 0);
|
||||
break;
|
||||
}
|
||||
case '{': {
|
||||
int m = 0, n = 0;
|
||||
int sz, j;
|
||||
@@ -538,6 +580,7 @@ static const char *re_subcompile_string(ReCompiled *p){
|
||||
if( m==0 ){
|
||||
if( n==0 ) return "both m and n are zero in '{m,n}'";
|
||||
re_insert(p, iPrev, RE_OP_FORK, sz+1);
|
||||
iPrev++;
|
||||
n--;
|
||||
}else{
|
||||
for(j=1; j<m; j++) re_copy(p, iPrev, sz);
|
||||
@@ -656,11 +699,7 @@ static const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){
|
||||
re_free(pRe);
|
||||
return zErr;
|
||||
}
|
||||
if( rePeek(pRe)=='$' && pRe->sIn.i+1>=pRe->sIn.mx ){
|
||||
re_append(pRe, RE_OP_MATCH, RE_EOF);
|
||||
re_append(pRe, RE_OP_ACCEPT, 0);
|
||||
*ppRe = pRe;
|
||||
}else if( pRe->sIn.i>=pRe->sIn.mx ){
|
||||
if( pRe->sIn.i>=pRe->sIn.mx ){
|
||||
re_append(pRe, RE_OP_ACCEPT, 0);
|
||||
*ppRe = pRe;
|
||||
}else{
|
||||
@@ -685,7 +724,7 @@ static const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){
|
||||
pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6));
|
||||
pRe->zInit[j++] = 0x80 | (x&0x3f);
|
||||
}else if( x<=0xffff ){
|
||||
pRe->zInit[j++] = (unsigned char)(0xd0 | (x>>12));
|
||||
pRe->zInit[j++] = (unsigned char)(0xe0 | (x>>12));
|
||||
pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f);
|
||||
pRe->zInit[j++] = 0x80 | (x&0x3f);
|
||||
}else{
|
||||
@@ -744,6 +783,67 @@ static void re_sql_func(
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(SQLITE_DEBUG)
|
||||
/*
|
||||
** This function is used for testing and debugging only. It is only available
|
||||
** if the SQLITE_DEBUG compile-time option is used.
|
||||
**
|
||||
** Compile a regular expression and then convert the compiled expression into
|
||||
** text and return that text.
|
||||
*/
|
||||
static void re_bytecode_func(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *zPattern;
|
||||
const char *zErr;
|
||||
ReCompiled *pRe;
|
||||
sqlite3_str *pStr;
|
||||
int i;
|
||||
int n;
|
||||
char *z;
|
||||
|
||||
zPattern = (const char*)sqlite3_value_text(argv[0]);
|
||||
if( zPattern==0 ) return;
|
||||
zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
|
||||
if( zErr ){
|
||||
re_free(pRe);
|
||||
sqlite3_result_error(context, zErr, -1);
|
||||
return;
|
||||
}
|
||||
if( pRe==0 ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
return;
|
||||
}
|
||||
pStr = sqlite3_str_new(0);
|
||||
if( pStr==0 ) goto re_bytecode_func_err;
|
||||
if( pRe->nInit>0 ){
|
||||
sqlite3_str_appendf(pStr, "INIT ");
|
||||
for(i=0; i<pRe->nInit; i++){
|
||||
sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]);
|
||||
}
|
||||
sqlite3_str_appendf(pStr, "\n");
|
||||
}
|
||||
for(i=0; (unsigned)i<pRe->nState; i++){
|
||||
sqlite3_str_appendf(pStr, "%-8s %4d\n",
|
||||
ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]);
|
||||
}
|
||||
n = sqlite3_str_length(pStr);
|
||||
z = sqlite3_str_finish(pStr);
|
||||
if( n==0 ){
|
||||
sqlite3_free(z);
|
||||
}else{
|
||||
sqlite3_result_text(context, z, n-1, sqlite3_free);
|
||||
}
|
||||
|
||||
re_bytecode_func_err:
|
||||
re_free(pRe);
|
||||
}
|
||||
|
||||
#endif /* SQLITE_DEBUG */
|
||||
|
||||
|
||||
/*
|
||||
** Invoke this routine to register the regexp() function with the
|
||||
** SQLite database connection.
|
||||
@@ -768,6 +868,13 @@ int sqlite3_regexp_init(
|
||||
rc = sqlite3_create_function(db, "regexpi", 2,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
||||
(void*)db, re_sql_func, 0, 0);
|
||||
#if defined(SQLITE_DEBUG)
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_create_function(db, "regexp_bytecode", 1,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
||||
0, re_bytecode_func, 0, 0);
|
||||
}
|
||||
#endif /* SQLITE_DEBUG */
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
+90
-45
@@ -30,6 +30,16 @@ SQLITE_EXTENSION_INIT1
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
|
||||
|
||||
#define STMT_NUM_INTEGER_COLUMN 11
|
||||
typedef struct StmtRow StmtRow;
|
||||
struct StmtRow {
|
||||
sqlite3_int64 iRowid; /* Rowid value */
|
||||
char *zSql; /* column "sql" */
|
||||
int aCol[STMT_NUM_INTEGER_COLUMN+1]; /* all other column values */
|
||||
StmtRow *pNext; /* Next row to return */
|
||||
};
|
||||
|
||||
/* stmt_vtab is a subclass of sqlite3_vtab which will
|
||||
** serve as the underlying representation of a stmt virtual table
|
||||
*/
|
||||
@@ -47,8 +57,7 @@ typedef struct stmt_cursor stmt_cursor;
|
||||
struct stmt_cursor {
|
||||
sqlite3_vtab_cursor base; /* Base class - must be first */
|
||||
sqlite3 *db; /* Database connection for this cursor */
|
||||
sqlite3_stmt *pStmt; /* Statement cursor is currently pointing at */
|
||||
sqlite3_int64 iRowid; /* The rowid */
|
||||
StmtRow *pRow; /* Current row */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -86,13 +95,14 @@ static int stmtConnect(
|
||||
#define STMT_COLUMN_REPREP 8 /* SQLITE_STMTSTATUS_REPREPARE */
|
||||
#define STMT_COLUMN_RUN 9 /* SQLITE_STMTSTATUS_RUN */
|
||||
#define STMT_COLUMN_MEM 10 /* SQLITE_STMTSTATUS_MEMUSED */
|
||||
#define STMT_COLUMN_STATE 11 /* SQLITE_STMTSTATUS_STATE */
|
||||
|
||||
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
"CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep,"
|
||||
"reprep,run,mem)");
|
||||
"reprep,run,mem,state)");
|
||||
if( rc==SQLITE_OK ){
|
||||
pNew = sqlite3_malloc( sizeof(*pNew) );
|
||||
pNew = sqlite3_malloc64( sizeof(*pNew) );
|
||||
*ppVtab = (sqlite3_vtab*)pNew;
|
||||
if( pNew==0 ) return SQLITE_NOMEM;
|
||||
memset(pNew, 0, sizeof(*pNew));
|
||||
@@ -114,7 +124,7 @@ static int stmtDisconnect(sqlite3_vtab *pVtab){
|
||||
*/
|
||||
static int stmtOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
|
||||
stmt_cursor *pCur;
|
||||
pCur = sqlite3_malloc( sizeof(*pCur) );
|
||||
pCur = sqlite3_malloc64( sizeof(*pCur) );
|
||||
if( pCur==0 ) return SQLITE_NOMEM;
|
||||
memset(pCur, 0, sizeof(*pCur));
|
||||
pCur->db = ((stmt_vtab*)p)->db;
|
||||
@@ -122,10 +132,21 @@ static int stmtOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static void stmtCsrReset(stmt_cursor *pCur){
|
||||
StmtRow *pRow = 0;
|
||||
StmtRow *pNext = 0;
|
||||
for(pRow=pCur->pRow; pRow; pRow=pNext){
|
||||
pNext = pRow->pNext;
|
||||
sqlite3_free(pRow);
|
||||
}
|
||||
pCur->pRow = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Destructor for a stmt_cursor.
|
||||
*/
|
||||
static int stmtClose(sqlite3_vtab_cursor *cur){
|
||||
stmtCsrReset((stmt_cursor*)cur);
|
||||
sqlite3_free(cur);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -136,8 +157,9 @@ static int stmtClose(sqlite3_vtab_cursor *cur){
|
||||
*/
|
||||
static int stmtNext(sqlite3_vtab_cursor *cur){
|
||||
stmt_cursor *pCur = (stmt_cursor*)cur;
|
||||
pCur->iRowid++;
|
||||
pCur->pStmt = sqlite3_next_stmt(pCur->db, pCur->pStmt);
|
||||
StmtRow *pNext = pCur->pRow->pNext;
|
||||
sqlite3_free(pCur->pRow);
|
||||
pCur->pRow = pNext;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -151,39 +173,15 @@ static int stmtColumn(
|
||||
int i /* Which column to return */
|
||||
){
|
||||
stmt_cursor *pCur = (stmt_cursor*)cur;
|
||||
switch( i ){
|
||||
case STMT_COLUMN_SQL: {
|
||||
sqlite3_result_text(ctx, sqlite3_sql(pCur->pStmt), -1, SQLITE_TRANSIENT);
|
||||
break;
|
||||
}
|
||||
case STMT_COLUMN_NCOL: {
|
||||
sqlite3_result_int(ctx, sqlite3_column_count(pCur->pStmt));
|
||||
break;
|
||||
}
|
||||
case STMT_COLUMN_RO: {
|
||||
sqlite3_result_int(ctx, sqlite3_stmt_readonly(pCur->pStmt));
|
||||
break;
|
||||
}
|
||||
case STMT_COLUMN_BUSY: {
|
||||
sqlite3_result_int(ctx, sqlite3_stmt_busy(pCur->pStmt));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
assert( i==STMT_COLUMN_MEM );
|
||||
i = SQLITE_STMTSTATUS_MEMUSED +
|
||||
STMT_COLUMN_NSCAN - SQLITE_STMTSTATUS_FULLSCAN_STEP;
|
||||
/* Fall thru */
|
||||
}
|
||||
case STMT_COLUMN_NSCAN:
|
||||
case STMT_COLUMN_NSORT:
|
||||
case STMT_COLUMN_NAIDX:
|
||||
case STMT_COLUMN_NSTEP:
|
||||
case STMT_COLUMN_REPREP:
|
||||
case STMT_COLUMN_RUN: {
|
||||
sqlite3_result_int(ctx, sqlite3_stmt_status(pCur->pStmt,
|
||||
i-STMT_COLUMN_NSCAN+SQLITE_STMTSTATUS_FULLSCAN_STEP, 0));
|
||||
break;
|
||||
}
|
||||
StmtRow *pRow = pCur->pRow;
|
||||
if( i==STMT_COLUMN_SQL ){
|
||||
sqlite3_result_text(ctx, pRow->zSql, -1, SQLITE_TRANSIENT);
|
||||
}else if( i==STMT_COLUMN_STATE ){
|
||||
const char *azStateName[] = { "INIT", "READY", "RUN", "HALT", "CACHE" };
|
||||
int j = pRow->aCol[i];
|
||||
sqlite3_result_text(ctx, azStateName[j%5], -1, SQLITE_STATIC);
|
||||
}else{
|
||||
sqlite3_result_int(ctx, pRow->aCol[i]);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -194,7 +192,7 @@ static int stmtColumn(
|
||||
*/
|
||||
static int stmtRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
|
||||
stmt_cursor *pCur = (stmt_cursor*)cur;
|
||||
*pRowid = pCur->iRowid;
|
||||
*pRowid = pCur->pRow->iRowid;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -204,7 +202,7 @@ static int stmtRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
|
||||
*/
|
||||
static int stmtEof(sqlite3_vtab_cursor *cur){
|
||||
stmt_cursor *pCur = (stmt_cursor*)cur;
|
||||
return pCur->pStmt==0;
|
||||
return pCur->pRow==0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -219,9 +217,56 @@ static int stmtFilter(
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
stmt_cursor *pCur = (stmt_cursor *)pVtabCursor;
|
||||
pCur->pStmt = 0;
|
||||
pCur->iRowid = 0;
|
||||
return stmtNext(pVtabCursor);
|
||||
sqlite3_stmt *p = 0;
|
||||
sqlite3_int64 iRowid = 1;
|
||||
StmtRow **ppRow = 0;
|
||||
|
||||
stmtCsrReset(pCur);
|
||||
ppRow = &pCur->pRow;
|
||||
for(p=sqlite3_next_stmt(pCur->db, 0); p; p=sqlite3_next_stmt(pCur->db, p)){
|
||||
const char *zSql = sqlite3_sql(p);
|
||||
sqlite3_int64 nSql = zSql ? strlen(zSql)+1 : 0;
|
||||
StmtRow *pNew = (StmtRow*)sqlite3_malloc64(sizeof(StmtRow) + nSql);
|
||||
|
||||
if( pNew==0 ) return SQLITE_NOMEM;
|
||||
memset(pNew, 0, sizeof(StmtRow));
|
||||
if( zSql ){
|
||||
pNew->zSql = (char*)&pNew[1];
|
||||
memcpy(pNew->zSql, zSql, nSql);
|
||||
}
|
||||
pNew->aCol[STMT_COLUMN_NCOL] = sqlite3_column_count(p);
|
||||
pNew->aCol[STMT_COLUMN_RO] = sqlite3_stmt_readonly(p);
|
||||
pNew->aCol[STMT_COLUMN_BUSY] = sqlite3_stmt_busy(p);
|
||||
pNew->aCol[STMT_COLUMN_NSCAN] = sqlite3_stmt_status(
|
||||
p, SQLITE_STMTSTATUS_FULLSCAN_STEP, 0
|
||||
);
|
||||
pNew->aCol[STMT_COLUMN_NSORT] = sqlite3_stmt_status(
|
||||
p, SQLITE_STMTSTATUS_SORT, 0
|
||||
);
|
||||
pNew->aCol[STMT_COLUMN_NAIDX] = sqlite3_stmt_status(
|
||||
p, SQLITE_STMTSTATUS_AUTOINDEX, 0
|
||||
);
|
||||
pNew->aCol[STMT_COLUMN_NSTEP] = sqlite3_stmt_status(
|
||||
p, SQLITE_STMTSTATUS_VM_STEP, 0
|
||||
);
|
||||
pNew->aCol[STMT_COLUMN_REPREP] = sqlite3_stmt_status(
|
||||
p, SQLITE_STMTSTATUS_REPREPARE, 0
|
||||
);
|
||||
pNew->aCol[STMT_COLUMN_RUN] = sqlite3_stmt_status(
|
||||
p, SQLITE_STMTSTATUS_RUN, 0
|
||||
);
|
||||
pNew->aCol[STMT_COLUMN_MEM] = sqlite3_stmt_status(
|
||||
p, SQLITE_STMTSTATUS_MEMUSED, 0
|
||||
);
|
||||
pNew->aCol[STMT_COLUMN_STATE] = sqlite3_stmt_status(
|
||||
p, SQLITE_STMTSTATUS_STATE, 0
|
||||
);
|
||||
pNew->iRowid = iRowid++;
|
||||
*ppRow = pNew;
|
||||
ppRow = &pNew->pNext;
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1262,9 +1262,14 @@ static int zipfileFilter(
|
||||
zipfileCursorErr(pCsr, "zipfile() function requires an argument");
|
||||
return SQLITE_ERROR;
|
||||
}else if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
|
||||
static const u8 aEmptyBlob = 0;
|
||||
const u8 *aBlob = (const u8*)sqlite3_value_blob(argv[0]);
|
||||
int nBlob = sqlite3_value_bytes(argv[0]);
|
||||
assert( pTab->pFirstEntry==0 );
|
||||
if( aBlob==0 ){
|
||||
aBlob = &aEmptyBlob;
|
||||
nBlob = 0;
|
||||
}
|
||||
rc = zipfileLoadDirectory(pTab, aBlob, nBlob);
|
||||
pCsr->pFreeEntry = pTab->pFirstEntry;
|
||||
pTab->pFirstEntry = pTab->pLastEntry = 0;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
# 2014 August 30
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] rbu_common.tcl]
|
||||
set ::testprefix rbubusy
|
||||
|
||||
db close
|
||||
sqlite3_shutdown
|
||||
test_sqlite3_log xLog
|
||||
reset_db
|
||||
|
||||
set db_sql {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b, c);
|
||||
INSERT INTO t1 VALUES(1000, 2000, 3000);
|
||||
}
|
||||
|
||||
set rbu_sql {
|
||||
CREATE TABLE data_t1(a, b, c, rbu_control);
|
||||
INSERT INTO data_t1 VALUES(1, 2, 3, 0);
|
||||
INSERT INTO data_t1 VALUES(4, 5, 6, 0);
|
||||
INSERT INTO data_t1 VALUES(7, 8, 9, 0);
|
||||
}
|
||||
|
||||
do_test 1.1 {
|
||||
forcedelete rbu.db
|
||||
sqlite3 rbu rbu.db
|
||||
rbu eval $rbu_sql
|
||||
rbu close
|
||||
|
||||
db eval $db_sql
|
||||
} {}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
BEGIN;
|
||||
SELECT * FROM t1
|
||||
} {1000 2000 3000}
|
||||
|
||||
do_test 1.3 {
|
||||
sqlite3rbu rbu test.db rbu.db
|
||||
rbu step
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test 1.4 {
|
||||
while 1 {
|
||||
set rc [rbu step]
|
||||
if {$rc!="SQLITE_OK"} break
|
||||
}
|
||||
set rc
|
||||
} {SQLITE_BUSY}
|
||||
|
||||
do_test 1.5 {
|
||||
rbu step
|
||||
} {SQLITE_BUSY}
|
||||
|
||||
do_test 1.6 {
|
||||
db eval COMMIT
|
||||
rbu step
|
||||
} {SQLITE_BUSY}
|
||||
catch { rbu close }
|
||||
|
||||
do_test 1.7 {
|
||||
sqlite3rbu rbu test.db rbu.db
|
||||
while 1 {
|
||||
set rc [rbu step]
|
||||
if {$rc!="SQLITE_OK"} break
|
||||
}
|
||||
set rc
|
||||
} {SQLITE_DONE}
|
||||
|
||||
rbu close
|
||||
|
||||
db close
|
||||
sqlite3_shutdown
|
||||
test_sqlite3_log
|
||||
sqlite3_initialize
|
||||
finish_test
|
||||
|
||||
+1
-1
@@ -1695,7 +1695,7 @@ static int geopolyUpdate(
|
||||
sqlite3_free(p);
|
||||
nChange = 1;
|
||||
}
|
||||
for(jj=1; jj<pRtree->nAux; jj++){
|
||||
for(jj=1; jj<nData-2; jj++){
|
||||
nChange++;
|
||||
sqlite3_bind_value(pUp, jj+2, aData[jj+2]);
|
||||
}
|
||||
|
||||
@@ -733,4 +733,27 @@ do_execsql_test 19.1 {
|
||||
SELECT v0.x FROM v0, rt0 WHERE v0.x = rt0.b;
|
||||
} {0.0}
|
||||
|
||||
# 2022-06-20 https://sqlite.org/forum/forumpost/57bdf2217d
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 20.0 {
|
||||
CREATE VIRTUAL TABLE rt0 USING rtree(id, x0, x1);
|
||||
CREATE TABLE t0(a INT);
|
||||
CREATE TABLE t1(b INT);
|
||||
INSERT INTO rt0 VALUES(0, 0, 0);
|
||||
}
|
||||
do_catchsql_test 20.1 {
|
||||
SELECT * FROM t1 JOIN t0 ON x0>a RIGHT JOIN rt0 ON true WHERE +x0 = 0;
|
||||
} {1 {ON clause references tables to its right}}
|
||||
do_catchsql_test 20.2 {
|
||||
SELECT * FROM t1 JOIN t0 ON x0>a RIGHT JOIN rt0 ON true WHERE x0 = 0;
|
||||
} {1 {ON clause references tables to its right}}
|
||||
db null -
|
||||
do_execsql_test 20.3 {
|
||||
SELECT * FROM t1 JOIN t0 ON true RIGHT JOIN rt0 ON x0>a WHERE +x0 = 0;
|
||||
} {- - 0 0.0 0.0}
|
||||
do_execsql_test 20.4 {
|
||||
SELECT * FROM t1 JOIN t0 ON true RIGHT JOIN rt0 ON x0>a WHERE x0 = 0;
|
||||
} {- - 0 0.0 0.0}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -23,6 +23,10 @@ ifcapable !rtree {
|
||||
return
|
||||
}
|
||||
|
||||
set ::TMPDBERROR [list 1 \
|
||||
{unable to open a temporary database file for storing temporary tables}
|
||||
]
|
||||
|
||||
# Test summary:
|
||||
#
|
||||
# rtree3-1: Test OOM in simple CREATE TABLE, INSERT, DELETE and SELECT
|
||||
@@ -196,9 +200,9 @@ do_test rtree3-7.prep {
|
||||
do_faultsim_test rtree3-7 -faults oom-* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
execsql { ALTER TABLE rt RENAME TO rt2 }
|
||||
execsql { ALTER TABLE rt RENAME TO rt2 }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
faultsim_test_result {0 {}} $::TMPDBERROR
|
||||
}
|
||||
|
||||
do_faultsim_test rtree3-8 -faults oom-* -prep {
|
||||
|
||||
@@ -342,7 +342,7 @@ do_eqp_execsql_test 7.2 {
|
||||
QUERY PLAN
|
||||
|--SCAN xdir
|
||||
|--SCAN rt VIRTUAL TABLE INDEX 2:B0D1
|
||||
`--SCAN ydir
|
||||
`--SCAN ydir LEFT-JOIN
|
||||
} {
|
||||
5 1 2 7 12 14 {}
|
||||
5 2 2 7 8 12 10
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
_fiddle_exec
|
||||
_fiddle_interrupt
|
||||
_fiddle_experiment
|
||||
_fiddle_the_db
|
||||
_fiddle_db_arg
|
||||
_fiddle_db_filename
|
||||
_fiddle_reset_db
|
||||
@@ -0,0 +1,14 @@
|
||||
FS
|
||||
addFunction
|
||||
allocateUTF8OnStack
|
||||
ccall
|
||||
cwrap
|
||||
getValue
|
||||
intArrayFromString
|
||||
lengthBytesUTF8
|
||||
removeFunction
|
||||
setValue
|
||||
stackAlloc
|
||||
stackRestore
|
||||
stackSave
|
||||
stringToUTF8Array
|
||||
@@ -0,0 +1,287 @@
|
||||
# This GNU makefile exists primarily to simplify/speed up development
|
||||
# of the sqlite3 WASM components. It is not part of the canonical
|
||||
# build process.
|
||||
#
|
||||
# Maintenance notes: the fiddle build is currently performed in the
|
||||
# top-level ../../Makefile.in. It may be moved into this file at some
|
||||
# point, as GNU Make has been deemed acceptable for the WASM-related
|
||||
# components (whereas POSIX Make is required for the more conventional
|
||||
# components).
|
||||
SHELL := $(shell which bash 2>/dev/null)
|
||||
all:
|
||||
|
||||
.PHONY: fiddle
|
||||
ifneq (,$(wildcard /home/stephan))
|
||||
fiddle_opt ?= -O0
|
||||
else
|
||||
fiddle_opt = -Os
|
||||
endif
|
||||
fiddle:
|
||||
$(MAKE) -C ../.. fiddle -e emcc_opt=$(fiddle_opt)
|
||||
|
||||
clean:
|
||||
$(MAKE) -C ../../ clean-fiddle
|
||||
-rm -f $(CLEAN_FILES)
|
||||
|
||||
MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
||||
dir.top := ../..
|
||||
# Reminder: some Emscripten flags require absolute paths
|
||||
dir.wasm := $(patsubst %/,%,$(dir $(abspath $(MAKEFILE))))
|
||||
dir.api := api
|
||||
dir.jacc := jaccwabyt
|
||||
dir.common := common
|
||||
CLEAN_FILES := *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~
|
||||
|
||||
SQLITE_OPT = \
|
||||
-DSQLITE_ENABLE_FTS4 \
|
||||
-DSQLITE_ENABLE_RTREE \
|
||||
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
|
||||
-DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION \
|
||||
-DSQLITE_ENABLE_STMTVTAB \
|
||||
-DSQLITE_ENABLE_DBPAGE_VTAB \
|
||||
-DSQLITE_ENABLE_DBSTAT_VTAB \
|
||||
-DSQLITE_ENABLE_BYTECODE_VTAB \
|
||||
-DSQLITE_ENABLE_OFFSET_SQL_FUNC \
|
||||
-DSQLITE_OMIT_LOAD_EXTENSION \
|
||||
-DSQLITE_OMIT_DEPRECATED \
|
||||
-DSQLITE_OMIT_UTF16 \
|
||||
-DSQLITE_THREADSAFE=0
|
||||
#SQLITE_OPT += -DSQLITE_ENABLE_MEMSYS5
|
||||
$(dir.top)/sqlite3.c:
|
||||
$(MAKE) -C $(dir.top) sqlite3.c
|
||||
|
||||
# SQLITE_OMIT_LOAD_EXTENSION: if this is true, sqlite3_vfs::xDlOpen
|
||||
# and friends may be NULL.
|
||||
|
||||
emcc_opt ?= -O0
|
||||
.PHONY: release
|
||||
release:
|
||||
$(MAKE) 'emcc_opt=-Os -g3'
|
||||
# ^^^^^ target-specific vars, e.g.:
|
||||
# release: emcc_opt=...
|
||||
# apparently only work for file targets, not PHONY targets?
|
||||
#
|
||||
# ^^^^ -O3, -Oz, -Os minify symbol names and there appears to be no
|
||||
# way around that except to use -g3, but -g3 causes the binary file
|
||||
# size to absolutely explode (approx. 5x larger). This minification
|
||||
# utterly breaks the resulting module, making it unsable except as
|
||||
# self-contained/self-referential-only code, as ALL of the exported
|
||||
# symbols get minified names.
|
||||
#
|
||||
# However, we have an option for using -Oz or -Os:
|
||||
#
|
||||
# Build with (-Os -g3) or (-Oz -g3) then use wasm-strip, from the wabt
|
||||
# tools package (https://github.com/WebAssembly/wabt), to strip the
|
||||
# debugging symbols. That results in a small build with unmangled
|
||||
# symbol names. -Oz gives ever-so-slightly better compression than
|
||||
# -Os: not quite 1% in some completely unscientific tests. Runtime
|
||||
# speed for the unit tests is all over the place either way so it's
|
||||
# difficult to say whether -Os gives any speed benefit over -Oz.
|
||||
########################################################################
|
||||
|
||||
# Emscripten SDK home dir and related binaries...
|
||||
EMSDK_HOME ?= $(word 1,$(wildcard $(HOME)/src/emsdk $(HOME)/emsdk))
|
||||
emcc.bin ?= $(word 1,$(wildcard $(shell which emcc) $(EMSDK_HOME)/upstream/emscripten/emcc))
|
||||
ifeq (,$(emcc.bin))
|
||||
$(error Cannot find emcc.)
|
||||
endif
|
||||
|
||||
wasm-strip ?= $(shell which wasm-strip 2>/dev/null)
|
||||
ifeq (,$(filter clean,$(MAKECMDGOALS)))
|
||||
ifeq (,$(wasm-strip))
|
||||
$(info WARNING: *******************************************************************)
|
||||
$(info WARNING: builds using -O3/-Os/-Oz will minify WASM-exported names,)
|
||||
$(info WARNING: breaking _All The Things_. The workaround for that is to build)
|
||||
$(info WARNING: with -g3 (which explodes the file size) and then strip the debug)
|
||||
$(info WARNING: info after compilation, using wasm-strip, to shrink the wasm file.)
|
||||
$(info WARNING: wasm-strip was not found in the PATH so we cannot strip those.)
|
||||
$(info WARNING: If this build uses any optimization level higher than -O2 then)
|
||||
$(info WARNING: the ***resulting WASM binary WILL NOT BE USABLE***.)
|
||||
$(info WARNING: wasm-strip is part of the wabt package:)
|
||||
$(info WARNING: https://github.com/WebAssembly/wabt)
|
||||
$(info WARNING: on Ubuntu-like systems it can be installed with:)
|
||||
$(info WARNING: sudo apt install wabt)
|
||||
$(info WARNING: *******************************************************************)
|
||||
endif
|
||||
endif # 'make clean' check
|
||||
|
||||
ifeq (release,$(filter release,$(MAKECMDGOALS)))
|
||||
ifeq (,$(wasm-strip))
|
||||
$(error Cannot make release-quality binary because wasm-strip is not available. \
|
||||
See notes in the warning above)
|
||||
endif
|
||||
else
|
||||
$(info Development build. Use '$(MAKE) release' for a smaller release build.)
|
||||
endif
|
||||
|
||||
EXPORTED_FUNCTIONS.api.in := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api \
|
||||
$(dir.jacc)/jaccwabyt_test.exports
|
||||
|
||||
EXPORTED_FUNCTIONS.api: $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE)
|
||||
cat $(EXPORTED_FUNCTIONS.api.in) > $@
|
||||
CLEAN_FILES += EXPORTED_FUNCTIONS.api
|
||||
|
||||
sqlite3-api.jses := \
|
||||
$(dir.api)/sqlite3-api-prologue.js \
|
||||
$(dir.common)/whwasmutil.js \
|
||||
$(dir.jacc)/jaccwabyt.js \
|
||||
$(dir.api)/sqlite3-api-glue.js \
|
||||
$(dir.api)/sqlite3-api-oo1.js \
|
||||
$(dir.api)/sqlite3-api-worker.js \
|
||||
$(dir.api)/sqlite3-api-opfs.js \
|
||||
$(dir.api)/sqlite3-api-cleanup.js
|
||||
|
||||
sqlite3-api.js := $(dir.api)/sqlite3-api.js
|
||||
CLEAN_FILES += $(sqlite3-api.js)
|
||||
$(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE)
|
||||
@echo "Making $@..."
|
||||
@for i in $(sqlite3-api.jses); do \
|
||||
echo "/* BEGIN FILE: $$i */"; \
|
||||
cat $$i; \
|
||||
echo "/* END FILE: $$i */"; \
|
||||
done > $@
|
||||
|
||||
post-js.js := $(dir.api)/post-js.js
|
||||
CLEAN_FILES += $(post-js.js)
|
||||
post-jses := \
|
||||
$(dir.api)/post-js-header.js \
|
||||
$(sqlite3-api.js) \
|
||||
$(dir.api)/post-js-footer.js
|
||||
|
||||
$(post-js.js): $(post-jses) $(MAKEFILE)
|
||||
@echo "Making $@..."
|
||||
@for i in $(post-jses); do \
|
||||
echo "/* BEGIN FILE: $$i */"; \
|
||||
cat $$i; \
|
||||
echo "/* END FILE: $$i */"; \
|
||||
done > $@
|
||||
|
||||
|
||||
########################################################################
|
||||
# emcc flags for .c/.o/.wasm.
|
||||
emcc.flags =
|
||||
#emcc.flags += -v # _very_ loud but also informative about what it's doing
|
||||
|
||||
########################################################################
|
||||
# emcc flags for .c/.o.
|
||||
emcc.cflags :=
|
||||
emcc.cflags += -std=c99 -fPIC
|
||||
# -------------^^^^^^^^ we currently need c99 for WASM-specific sqlite3 APIs.
|
||||
emcc.cflags += -I. -I$(dir.top) # $(SQLITE_OPT)
|
||||
|
||||
########################################################################
|
||||
# emcc flags specific to building the final .js/.wasm file...
|
||||
emcc.jsflags := -fPIC
|
||||
emcc.jsflags += --no-entry
|
||||
emcc.jsflags += -sENVIRONMENT=web
|
||||
emcc.jsflags += -sMODULARIZE
|
||||
emcc.jsflags += -sSTRICT_JS
|
||||
emcc.jsflags += -sDYNAMIC_EXECUTION=0
|
||||
emcc.jsflags += -sNO_POLYFILL
|
||||
emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.api
|
||||
emcc.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory # wasmMemory==>for -sIMPORTED_MEMORY
|
||||
emcc.jsflags += -sUSE_CLOSURE_COMPILER=0
|
||||
emcc.jsflags += -sIMPORTED_MEMORY
|
||||
#emcc.jsflags += -sINITIAL_MEMORY=13107200
|
||||
#emcc.jsflags += -sTOTAL_STACK=4194304
|
||||
emcc.jsflags += -sEXPORT_NAME=sqlite3InitModule
|
||||
emcc.jsflags += -sGLOBAL_BASE=4096 # HYPOTHETICALLY keep func table indexes from overlapping w/ heap addr.
|
||||
emcc.jsflags +=--post-js=$(post-js.js)
|
||||
#emcc.jsflags += -sSTRICT # fails due to missing __syscall_...()
|
||||
#emcc.jsflags += -sALLOW_UNIMPLEMENTED_SYSCALLS
|
||||
#emcc.jsflags += -sFILESYSTEM=0 # only for experimentation. sqlite3 needs the FS API
|
||||
#emcc.jsflags += -sABORTING_MALLOC
|
||||
emcc.jsflags += -sALLOW_MEMORY_GROWTH
|
||||
emcc.jsflags += -sALLOW_TABLE_GROWTH
|
||||
emcc.jsflags += -Wno-limited-postlink-optimizations
|
||||
# ^^^^^ it likes to warn when we have "limited optimizations" via the -g3 flag.
|
||||
#emcc.jsflags += -sMALLOC=emmalloc
|
||||
#emcc.jsflags += -sMALLOC=dlmalloc # a good 8k larger than emmalloc
|
||||
#emcc.jsflags += -sSTANDALONE_WASM # causes OOM errors, not sure why
|
||||
#emcc.jsflags += --import=foo_bar
|
||||
#emcc.jsflags += --no-gc-sections
|
||||
# https://lld.llvm.org/WebAssembly.html
|
||||
emcc.jsflags += -sERROR_ON_UNDEFINED_SYMBOLS=0
|
||||
emcc.jsflags += -sLLD_REPORT_UNDEFINED
|
||||
#emcc.jsflags += --allow-undefined
|
||||
emcc.jsflags += --import-undefined
|
||||
#emcc.jsflags += --unresolved-symbols=import-dynamic --experimental-pic
|
||||
#emcc.jsflags += --experimental-pic --unresolved-symbols=ingore-all --import-undefined
|
||||
#emcc.jsflags += --unresolved-symbols=ignore-all
|
||||
enable_bigint ?= 1
|
||||
ifneq (0,$(enable_bigint))
|
||||
emcc.jsflags += -sWASM_BIGINT
|
||||
endif
|
||||
emcc.jsflags += -sMEMORY64=0
|
||||
# ^^^^ MEMORY64=1 fails to load, erroring with:
|
||||
# invalid memory limits flags 0x5
|
||||
# (enable via --experimental-wasm-memory64)
|
||||
#
|
||||
# ^^^^ MEMORY64=2 builds and loads but dies when we do things like:
|
||||
#
|
||||
# new Uint8Array(heapWrappers().HEAP8U.buffer, ptr, n)
|
||||
#
|
||||
# because ptr is now a BigInt, so is invalid for passing to arguments
|
||||
# which have strict must-be-a-number requirements.
|
||||
########################################################################
|
||||
|
||||
|
||||
sqlite3.js := $(dir.api)/sqlite3.js
|
||||
sqlite3.wasm := $(dir.api)/sqlite3.wasm
|
||||
$(dir.api)/sqlite3-wasm.o: emcc.cflags += $(SQLITE_OPT)
|
||||
$(dir.api)/sqlite3-wasm.o: $(dir.top)/sqlite3.c
|
||||
$(dir.api)/wasm_util.o: emcc.cflags += $(SQLITE_OPT)
|
||||
sqlite3.wasm.c := $(dir.api)/sqlite3-wasm.c \
|
||||
$(dir.jacc)/jaccwabyt_test.c
|
||||
# ^^^ FIXME (how?): jaccwabyt_test.c is only needed for the test
|
||||
# apps. However, we want to test the release builds with those apps,
|
||||
# so we cannot simply elide that file in release builds. That
|
||||
# component is critical to the VFS bindings so needs to be tested
|
||||
# along with the core APIs.
|
||||
define WASM_C_COMPILE
|
||||
$(1).o := $$(subst .c,.o,$(1))
|
||||
sqlite3.wasm.obj += $$($(1).o)
|
||||
$$($(1).o): $$(MAKEFILE) $(1)
|
||||
$$(emcc.bin) $$(emcc_opt) $$(emcc.flags) $$(emcc.cflags) -c $(1) -o $$@
|
||||
CLEAN_FILES += $$($(1).o)
|
||||
endef
|
||||
$(foreach c,$(sqlite3.wasm.c),$(eval $(call WASM_C_COMPILE,$(c))))
|
||||
$(sqlite3.js):
|
||||
$(sqlite3.js): $(MAKEFILE) $(sqlite3.wasm.obj) \
|
||||
EXPORTED_FUNCTIONS.api \
|
||||
$(post-js.js)
|
||||
$(emcc.bin) -o $@ $(emcc_opt) $(emcc.flags) $(emcc.jsflags) $(sqlite3.wasm.obj)
|
||||
chmod -x $(sqlite3.wasm)
|
||||
ifneq (,$(wasm-strip))
|
||||
$(wasm-strip) $(sqlite3.wasm)
|
||||
endif
|
||||
@ls -la $@ $(sqlite3.wasm)
|
||||
|
||||
CLEAN_FILES += $(sqlite3.js) $(sqlite3.wasm)
|
||||
all: $(sqlite3.js)
|
||||
# End main Emscripten-based module build
|
||||
########################################################################
|
||||
|
||||
|
||||
########################################################################
|
||||
# fiddle_remote is the remote destination for the fiddle app. It
|
||||
# must be a [user@]HOST:/path for rsync.
|
||||
# Note that the target "should probably" contain a symlink of
|
||||
# index.html -> fiddle.html.
|
||||
fiddle_remote ?=
|
||||
ifeq (,$(fiddle_remote))
|
||||
ifneq (,$(wildcard /home/stephan))
|
||||
fiddle_remote = wh:www/wh/sqlite3/.
|
||||
else ifneq (,$(wildcard /home/drh))
|
||||
#fiddle_remote = if appropriate, add that user@host:/path here
|
||||
endif
|
||||
endif
|
||||
$(fiddle_files): default
|
||||
push-fiddle: $(fiddle_files)
|
||||
@if [ x = "x$(fiddle_remote)" ]; then \
|
||||
echo "fiddle_remote must be a [user@]HOST:/path for rsync"; \
|
||||
exit 1; \
|
||||
fi
|
||||
rsync -va fiddle/ $(fiddle_remote)
|
||||
# end fiddle remote push
|
||||
########################################################################
|
||||
@@ -0,0 +1,103 @@
|
||||
This directory houses the [Web Assembly (WASM)](https://en.wikipedia.org/wiki/WebAssembly)
|
||||
parts of the sqlite3 build.
|
||||
|
||||
It requires [emscripten][] and that the build environment be set up for
|
||||
emscripten. A mini-HOWTO for setting that up follows...
|
||||
|
||||
First, install the Emscripten SDK, as documented
|
||||
[here](https://emscripten.org/docs/getting_started/downloads.html) and summarized
|
||||
below for Linux environments:
|
||||
|
||||
```
|
||||
# Clone the emscripten repository:
|
||||
$ git clone https://github.com/emscripten-core/emsdk.git
|
||||
$ cd emsdk
|
||||
|
||||
# Download and install the latest SDK tools:
|
||||
$ ./emsdk install latest
|
||||
|
||||
# Make the "latest" SDK "active" for the current user:
|
||||
$ ./emsdk activate latest
|
||||
```
|
||||
|
||||
Those parts only need to be run once, but the SDK can be updated using:
|
||||
|
||||
```
|
||||
$ git pull
|
||||
$ ./emsdk activate latest
|
||||
```
|
||||
|
||||
The following needs to be run for each shell instance which needs the
|
||||
`emcc` compiler:
|
||||
|
||||
```
|
||||
# Activate PATH and other environment variables in the current terminal:
|
||||
$ source ./emsdk_env.sh
|
||||
|
||||
$ which emcc
|
||||
/path/to/emsdk/upstream/emscripten/emcc
|
||||
```
|
||||
|
||||
Optionally, add that to your login shell's resource file (`~/.bashrc`
|
||||
or equivalent).
|
||||
|
||||
That `env` script needs to be sourced for building this application
|
||||
from the top of the sqlite3 build tree:
|
||||
|
||||
```
|
||||
$ make fiddle
|
||||
```
|
||||
|
||||
Or:
|
||||
|
||||
```
|
||||
$ cd ext/wasm
|
||||
$ make
|
||||
```
|
||||
|
||||
That will generate the fiddle application under
|
||||
[ext/fiddle](/dir/ext/wasm/fiddle), as `fiddle.html`. That application
|
||||
cannot, due to XMLHttpRequest security limitations, run if the HTML
|
||||
file is opened directly in the browser (i.e. if it is opened using a
|
||||
`file://` URL), so it needs to be served via an HTTP server. For
|
||||
example, using [althttpd][]:
|
||||
|
||||
```
|
||||
$ cd ext/wasm/fiddle
|
||||
$ althttpd -page fiddle.html
|
||||
```
|
||||
|
||||
That will open the system's browser and run the fiddle app's page.
|
||||
|
||||
Note that when serving this app via [althttpd][], it must be a version
|
||||
from 2022-05-17 or newer so that it recognizes the `.wasm` file
|
||||
extension and responds with the mimetype `application/wasm`, as the
|
||||
WASM loader is pedantic about that detail.
|
||||
|
||||
|
||||
# Known Quirks and Limitations
|
||||
|
||||
Some "impedence mismatch" between C and WASM/JavaScript is to be
|
||||
expected.
|
||||
|
||||
## No I/O
|
||||
|
||||
sqlite3 shell commands which require file I/O or pipes are disabled in
|
||||
the WASM build.
|
||||
|
||||
## `exit()` Triggered from C
|
||||
|
||||
When C code calls `exit()`, as happens (for example) when running an
|
||||
"unsafe" command when safe mode is active, WASM's connection to the
|
||||
sqlite3 shell environment has no sensible choice but to shut down
|
||||
because `exit()` leaves it in a state we can no longer recover
|
||||
from. The JavaScript-side application attempts to recognize this and
|
||||
warn the user that restarting the application is necessary. Currently
|
||||
the only way to restart it is to reload the page. Restructuring the
|
||||
shell code such that it could be "rebooted" without restarting the
|
||||
JS app would require some invasive changes which are not currently
|
||||
on any TODO list but have not been entirely ruled out long-term.
|
||||
|
||||
|
||||
[emscripten]: https://emscripten.org
|
||||
[althttpd]: https://sqlite.org/althttpd
|
||||
@@ -0,0 +1,72 @@
|
||||
_sqlite3_bind_blob
|
||||
_sqlite3_bind_double
|
||||
_sqlite3_bind_int
|
||||
_sqlite3_bind_int64
|
||||
_sqlite3_bind_null
|
||||
_sqlite3_bind_parameter_count
|
||||
_sqlite3_bind_parameter_index
|
||||
_sqlite3_bind_text
|
||||
_sqlite3_changes
|
||||
_sqlite3_changes64
|
||||
_sqlite3_clear_bindings
|
||||
_sqlite3_close_v2
|
||||
_sqlite3_column_blob
|
||||
_sqlite3_column_bytes
|
||||
_sqlite3_column_count
|
||||
_sqlite3_column_count
|
||||
_sqlite3_column_double
|
||||
_sqlite3_column_int
|
||||
_sqlite3_column_int64
|
||||
_sqlite3_column_name
|
||||
_sqlite3_column_text
|
||||
_sqlite3_column_type
|
||||
_sqlite3_compileoption_get
|
||||
_sqlite3_compileoption_used
|
||||
_sqlite3_create_function_v2
|
||||
_sqlite3_data_count
|
||||
_sqlite3_db_filename
|
||||
_sqlite3_db_name
|
||||
_sqlite3_errmsg
|
||||
_sqlite3_error_offset
|
||||
_sqlite3_errstr
|
||||
_sqlite3_exec
|
||||
_sqlite3_expanded_sql
|
||||
_sqlite3_extended_errcode
|
||||
_sqlite3_extended_result_codes
|
||||
_sqlite3_finalize
|
||||
_sqlite3_initialize
|
||||
_sqlite3_interrupt
|
||||
_sqlite3_libversion
|
||||
_sqlite3_libversion_number
|
||||
_sqlite3_open
|
||||
_sqlite3_open_v2
|
||||
_sqlite3_prepare_v2
|
||||
_sqlite3_prepare_v3
|
||||
_sqlite3_reset
|
||||
_sqlite3_result_blob
|
||||
_sqlite3_result_double
|
||||
_sqlite3_result_error
|
||||
_sqlite3_result_error_code
|
||||
_sqlite3_result_error_nomem
|
||||
_sqlite3_result_error_toobig
|
||||
_sqlite3_result_int
|
||||
_sqlite3_result_null
|
||||
_sqlite3_result_text
|
||||
_sqlite3_sourceid
|
||||
_sqlite3_sql
|
||||
_sqlite3_step
|
||||
_sqlite3_strglob
|
||||
_sqlite3_strlike
|
||||
_sqlite3_total_changes
|
||||
_sqlite3_total_changes64
|
||||
_sqlite3_value_blob
|
||||
_sqlite3_value_bytes
|
||||
_sqlite3_value_double
|
||||
_sqlite3_value_text
|
||||
_sqlite3_value_type
|
||||
_sqlite3_vfs_find
|
||||
_sqlite3_vfs_register
|
||||
_sqlite3_wasm_db_error
|
||||
_sqlite3_wasm_enum_json
|
||||
_malloc
|
||||
_free
|
||||
@@ -0,0 +1,3 @@
|
||||
FS
|
||||
wasmMemory
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
# sqlite3-api.js And Friends
|
||||
|
||||
This is the README for the files `sqlite3-*.js` and
|
||||
`sqlite3-wasm.c`. This collection of files is used to build a
|
||||
single-file distribution of the sqlite3 WASM API. It is broken into
|
||||
multiple JS files because:
|
||||
|
||||
1. To facilitate including or excluding certain components for
|
||||
specific use cases. e.g. by removing `sqlite3-api-oo1.js` if the
|
||||
OO#1 API is not needed.
|
||||
|
||||
2. To facilitate modularizing the pieces for use in different WASM
|
||||
build environments. e.g. the files `post-js-*.js` are for use with
|
||||
Emscripten's `--post-js` feature, and nowhere else.
|
||||
|
||||
3. Certain components must be in their own standalone files in order
|
||||
to be loaded as JS Workers.
|
||||
|
||||
Note that the structure described here is the current state of things,
|
||||
not necessarily the "final" state.
|
||||
|
||||
The overall idea is that the following files get concatenated
|
||||
together, in the listed order, the resulting file is loaded by a
|
||||
browser client:
|
||||
|
||||
- `post-js-header.js`\
|
||||
Emscripten-specific header for the `--post-js` input.
|
||||
- `sqlite3-api-prologue.js`\
|
||||
Contains the initial bootstrap setup of the sqlite3 API
|
||||
objects. This is exposed as a function, rather than objects, so that
|
||||
the next step can pass in a config object which abstracts away parts
|
||||
of the WASM environment, to facilitate plugging it in to arbitrary
|
||||
WASM toolchains.
|
||||
- `../common/whwasmutil.js`\
|
||||
A semi-third-party collection of JS/WASM utility code intended to
|
||||
replace much of the Emscripten glue. The sqlite3 APIs internally use
|
||||
these APIs instead of their Emscripten counterparts, in order to be
|
||||
more portable to arbitrary WASM toolchains. This API is
|
||||
configurable, in principle, for use with arbitrary WASM
|
||||
toolchains. It is "semi-third-party" in that it was created in order
|
||||
to support this tree but is standalone and maintained together
|
||||
with...
|
||||
- `../jaccwabyt/jaccwabyt.js`\
|
||||
Another semi-third-party API which creates bindings between JS
|
||||
and C structs, such that changes to the struct state from either JS
|
||||
or C are visible to the other end of the connection. This is also an
|
||||
independent spinoff project, conceived for the sqlite3 project but
|
||||
maintained separately.
|
||||
- `sqlite3-api-glue.js`\
|
||||
Invokes the function exposed by `sqlite3-api-prologue.js`, passing
|
||||
it a configuration object to configure it for the current WASM
|
||||
toolchain (noting that it currently requires Emscripten), then
|
||||
removes that function from the global scope. The result of this file
|
||||
is a global-scope `sqlite3` object which acts as a namespace for the
|
||||
API's functionality. This object gets removed from the global scope
|
||||
after the following files have attached their own features to it.
|
||||
- `sqlite3-api-oo1.js`\
|
||||
Provides a high-level object-oriented wrapper to the lower-level C
|
||||
API, colloquially known as OO API #1. Its API is similar to other
|
||||
high-level sqlite3 JS wrappers and should feel relatively familiar
|
||||
to anyone familiar with such APIs. That said, it is not a "required
|
||||
component" and can be elided from builds which do not want it.
|
||||
- `sqlite3-api-worker.js`\
|
||||
A Worker-thread-based API which uses OO API #1 to provide an
|
||||
interface to a database which can be driven from the main Window
|
||||
thread via the Worker message-passing interface. Like OO API #1,
|
||||
this is an optional component, offering one of any number of
|
||||
potential implementations for such an API.
|
||||
- `sqlite3-worker.js`\
|
||||
Is not part of the amalgamated sources and is intended to be
|
||||
loaded by a client Worker thread. It loads the sqlite3 module
|
||||
and runs the Worker API which is implemented in
|
||||
`sqlite3-api-worker.js`.
|
||||
- `sqlite3-api-opfs.js`\
|
||||
is an in-development/experimental sqlite3 VFS wrapper, the goal of
|
||||
which being to use Google Chrome's Origin-Private FileSystem (OPFS)
|
||||
storage layer to provide persistent storage for database files in a
|
||||
browser. It is far from complete.
|
||||
- `sqlite3-api-cleanup.js`\
|
||||
the previous files temporarily create global objects in order to
|
||||
communicate their state to the files which follow them, and _this_
|
||||
file connects any final components together and cleans up those
|
||||
globals. As of this writing, this code ensures that the previous
|
||||
files leave no global symbols installed, and it moves the sqlite3
|
||||
namespace object into the in-scope Emscripten module. Abstracting
|
||||
this for other WASM toolchains is TODO.
|
||||
- `post-js-footer.js`\
|
||||
Emscripten-specific footer for the `--post-js` input. This closes
|
||||
off the lexical scope opened by `post-js-header.js`.
|
||||
|
||||
The build process glues those files together, resulting in
|
||||
`sqlite3-api.js`, which is everything except for the `post-js-*.js`
|
||||
files, and `sqlite3.js`, which is the Emscripten-generated amalgamated
|
||||
output and includes the `post-js-*.js` parts, as well as the
|
||||
Emscripten-provided module loading pieces.
|
||||
|
||||
The non-JS outlier file is `sqlite3-wasm.c`: it is a proxy for
|
||||
`sqlite3.c` which `#include`'s that file and adds a couple more
|
||||
WASM-specific helper functions, at least one of which requires access
|
||||
to private/static `sqlite3.c` internals. `sqlite3.wasm` is compiled
|
||||
from this file rather than `sqlite3.c`.
|
||||
@@ -0,0 +1,3 @@
|
||||
/* The current function scope was opened via post-js-header.js, which
|
||||
gets prepended to this at build-time. */
|
||||
})/*postRun.push(...)*/;
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
post-js-header.js is to be prepended to other code to create
|
||||
post-js.js for use with Emscripten's --post-js flag. This code
|
||||
requires that it be running in that context. The Emscripten
|
||||
environment must have been set up already but it will not have
|
||||
loaded its WASM when the code in this file is run. The function it
|
||||
installs will be run after the WASM module is loaded, at which
|
||||
point the sqlite3 WASM API bits will be set up.
|
||||
*/
|
||||
if(!Module.postRun) Module.postRun = [];
|
||||
Module.postRun.push(function(Module/*the Emscripten-style module object*/){
|
||||
'use strict';
|
||||
/* This function will contain:
|
||||
|
||||
- post-js-header.js (this file)
|
||||
- sqlite3-api-prologue.js => Bootstrapping bits to attach the rest to
|
||||
- sqlite3-api-whwasmutil.js => Replacements for much of Emscripten's glue
|
||||
- sqlite3-api-jaccwabyt.js => Jaccwabyt (C/JS struct binding)
|
||||
- sqlite3-api-glue.js => glues previous parts together
|
||||
- sqlite3-api-oo.js => SQLite3 OO API #1.
|
||||
- sqlite3-api-worker.js => Worker-based API
|
||||
- sqlite3-api-cleanup.js => final API cleanup
|
||||
- post-js-footer.js => closes this postRun() function
|
||||
|
||||
Whew!
|
||||
*/
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
2022-07-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 is the tail end of the sqlite3-api.js constellation,
|
||||
intended to be appended after all other files so that it can clean
|
||||
up any global systems temporarily used for setting up the API's
|
||||
various subsystems.
|
||||
*/
|
||||
'use strict';
|
||||
self.sqlite3.postInit.forEach(
|
||||
self.importScripts/*global is a Worker*/
|
||||
? function(f){
|
||||
/** We try/catch/report for the sake of failures which happen in
|
||||
a Worker, as those exceptions can otherwise get completely
|
||||
swallowed, leading to confusing downstream errors which have
|
||||
nothing to do with this failure. */
|
||||
try{ f(self, self.sqlite3) }
|
||||
catch(e){
|
||||
console.error("Error in postInit() function:",e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
: (f)=>f(self, self.sqlite3)
|
||||
);
|
||||
delete self.sqlite3.postInit;
|
||||
if(self.location && +self.location.port > 1024){
|
||||
console.warn("Installing sqlite3 bits as global S for dev-testing purposes.");
|
||||
self.S = self.sqlite3;
|
||||
}
|
||||
/* Clean up temporary global-scope references to our APIs... */
|
||||
self.sqlite3.config.Module.sqlite3 = self.sqlite3
|
||||
/* ^^^^ Currently needed by test code and Worker API setup */;
|
||||
delete self.sqlite3.capi.util /* arguable, but these are (currently) internal-use APIs */;
|
||||
delete self.sqlite3 /* clean up our global-scope reference */;
|
||||
//console.warn("Module.sqlite3 =",Module.sqlite3);
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
2022-07-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 glues together disparate pieces of JS which are loaded in
|
||||
previous steps of the sqlite3-api.js bootstrapping process:
|
||||
sqlite3-api-prologue.js, whwasmutil.js, and jaccwabyt.js. It
|
||||
initializes the main API pieces so that the downstream components
|
||||
(e.g. sqlite3-api-oo1.js) have all that they need.
|
||||
*/
|
||||
(function(self){
|
||||
'use strict';
|
||||
const toss = (...args)=>{throw new Error(args.join(' '))};
|
||||
|
||||
self.sqlite3 = self.sqlite3ApiBootstrap({
|
||||
Module: Module /* ==> Emscripten-style Module object. Currently
|
||||
needs to be exposed here for test code. NOT part
|
||||
of the public API. */,
|
||||
exports: Module['asm'],
|
||||
memory: Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */,
|
||||
bigIntEnabled: !!self.BigInt64Array,
|
||||
allocExportName: 'malloc',
|
||||
deallocExportName: 'free'
|
||||
});
|
||||
delete self.sqlite3ApiBootstrap;
|
||||
|
||||
const sqlite3 = self.sqlite3;
|
||||
const capi = sqlite3.capi, wasm = capi.wasm, util = capi.util;
|
||||
self.WhWasmUtilInstaller(capi.wasm);
|
||||
delete self.WhWasmUtilInstaller;
|
||||
|
||||
if(0){
|
||||
/* "The problem" is that the following isn't type-safe.
|
||||
OTOH, nothing about WASM pointers is. */
|
||||
/**
|
||||
Add the `.pointer` xWrap() signature entry to extend
|
||||
the `pointer` arg handler to check for a `pointer`
|
||||
property. This can be used to permit, e.g., passing
|
||||
an SQLite3.DB instance to a C-style sqlite3_xxx function
|
||||
which takes an `sqlite3*` argument.
|
||||
*/
|
||||
const oldP = wasm.xWrap.argAdapter('pointer');
|
||||
const adapter = function(v){
|
||||
if(v && 'object'===typeof v && v.constructor){
|
||||
const x = v.pointer;
|
||||
if(Number.isInteger(x)) return x;
|
||||
else toss("Invalid (object) type for pointer-type argument.");
|
||||
}
|
||||
return oldP(v);
|
||||
};
|
||||
wasm.xWrap.argAdapter('.pointer', adapter);
|
||||
}
|
||||
|
||||
// WhWasmUtil.xWrap() bindings...
|
||||
{
|
||||
/**
|
||||
Add some descriptive xWrap() aliases for '*' intended to
|
||||
(A) initially improve readability/correctness of capi.signatures
|
||||
and (B) eventually perhaps provide some sort of type-safety
|
||||
in their conversions.
|
||||
*/
|
||||
const aPtr = wasm.xWrap.argAdapter('*');
|
||||
wasm.xWrap.argAdapter('sqlite3*', aPtr)('sqlite3_stmt*', aPtr);
|
||||
|
||||
/**
|
||||
Populate api object with sqlite3_...() by binding the "raw" wasm
|
||||
exports into type-converting proxies using wasm.xWrap().
|
||||
*/
|
||||
for(const e of wasm.bindingSignatures){
|
||||
capi[e[0]] = wasm.xWrap.apply(null, e);
|
||||
}
|
||||
|
||||
/* For functions which cannot work properly unless
|
||||
wasm.bigIntEnabled is true, install a bogus impl which
|
||||
throws if called when bigIntEnabled is false. */
|
||||
const fI64Disabled = function(fname){
|
||||
return ()=>toss(fname+"() disabled due to lack",
|
||||
"of BigInt support in this build.");
|
||||
};
|
||||
for(const e of wasm.bindingSignatures.int64){
|
||||
capi[e[0]] = wasm.bigIntEnabled
|
||||
? wasm.xWrap.apply(null, e)
|
||||
: fI64Disabled(e[0]);
|
||||
}
|
||||
|
||||
if(wasm.exports.sqlite3_wasm_db_error){
|
||||
util.sqlite3_wasm_db_error = capi.wasm.xWrap(
|
||||
'sqlite3_wasm_db_error', 'int', 'sqlite3*', 'int', 'string'
|
||||
);
|
||||
}else{
|
||||
util.sqlite3_wasm_db_error = function(pDb,errCode,msg){
|
||||
console.warn("sqlite3_wasm_db_error() is not exported.",arguments);
|
||||
return errCode;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
When registering a VFS and its related components it may be
|
||||
necessary to ensure that JS keeps a reference to them to keep
|
||||
them from getting garbage collected. Simply pass each such value
|
||||
to this function and a reference will be held to it for the life
|
||||
of the app.
|
||||
*/
|
||||
capi.sqlite3_vfs_register.addReference = function f(...args){
|
||||
if(!f._) f._ = [];
|
||||
f._.push(...args);
|
||||
};
|
||||
|
||||
}/*xWrap() bindings*/;
|
||||
|
||||
/**
|
||||
Scope-local holder of the two impls of sqlite3_prepare_v2/v3().
|
||||
*/
|
||||
const __prepare = Object.create(null);
|
||||
/**
|
||||
This binding expects a JS string as its 2nd argument and
|
||||
null as its final argument. In order to compile multiple
|
||||
statements from a single string, the "full" impl (see
|
||||
below) must be used.
|
||||
*/
|
||||
__prepare.basic = wasm.xWrap('sqlite3_prepare_v3',
|
||||
"int", ["sqlite3*", "string",
|
||||
"int"/*MUST always be negative*/,
|
||||
"int", "**",
|
||||
"**"/*MUST be 0 or null or undefined!*/]);
|
||||
/**
|
||||
Impl which requires that the 2nd argument be a pointer
|
||||
to the SQL string, instead of being converted to a
|
||||
string. This variant is necessary for cases where we
|
||||
require a non-NULL value for the final argument
|
||||
(exec()'ing multiple statements from one input
|
||||
string). For simpler cases, where only the first
|
||||
statement in the SQL string is required, the wrapper
|
||||
named sqlite3_prepare_v2() is sufficient and easier to
|
||||
use because it doesn't require dealing with pointers.
|
||||
*/
|
||||
__prepare.full = wasm.xWrap('sqlite3_prepare_v3',
|
||||
"int", ["sqlite3*", "*", "int", "int",
|
||||
"**", "**"]);
|
||||
|
||||
/* Documented in the api object's initializer. */
|
||||
capi.sqlite3_prepare_v3 = function f(pDb, sql, sqlLen, prepFlags, ppStmt, pzTail){
|
||||
/* 2022-07-08: xWrap() 'string' arg handling may be able do this
|
||||
special-case handling for us. It needs to be tested. Or maybe
|
||||
not: we always want to treat pzTail as null when passed a
|
||||
non-pointer SQL string and the argument adapters don't have
|
||||
enough state to know that. Maybe they could/should, by passing
|
||||
the currently-collected args as an array as the 2nd arg to the
|
||||
argument adapters? Or maybe we collect all args in an array,
|
||||
pass that to an optional post-args-collected callback, and give
|
||||
it a chance to manipulate the args before we pass them on? */
|
||||
if(util.isSQLableTypedArray(sql)) sql = util.typedArrayToString(sql);
|
||||
switch(typeof sql){
|
||||
case 'string': return __prepare.basic(pDb, sql, -1, prepFlags, ppStmt, null);
|
||||
case 'number': return __prepare.full(pDb, sql, sqlLen||-1, prepFlags, ppStmt, pzTail);
|
||||
default:
|
||||
return util.sqlite3_wasm_db_error(
|
||||
pDb, capi.SQLITE_MISUSE,
|
||||
"Invalid SQL argument type for sqlite3_prepare_v2/v3()."
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
capi.sqlite3_prepare_v2 =
|
||||
(pDb, sql, sqlLen, ppStmt, pzTail)=>capi.sqlite3_prepare_v3(pDb, sql, sqlLen, 0, ppStmt, pzTail);
|
||||
|
||||
/**
|
||||
Install JS<->C struct bindings for the non-opaque struct types we
|
||||
need... */
|
||||
sqlite3.StructBinder = self.Jaccwabyt({
|
||||
heap: 0 ? wasm.memory : wasm.heap8u,
|
||||
alloc: wasm.alloc,
|
||||
dealloc: wasm.dealloc,
|
||||
functionTable: wasm.functionTable,
|
||||
bigIntEnabled: wasm.bigIntEnabled,
|
||||
memberPrefix: '$'
|
||||
});
|
||||
delete self.Jaccwabyt;
|
||||
|
||||
{/* Import C-level constants and structs... */
|
||||
const cJson = wasm.xCall('sqlite3_wasm_enum_json');
|
||||
if(!cJson){
|
||||
toss("Maintenance required: increase sqlite3_wasm_enum_json()'s",
|
||||
"static buffer size!");
|
||||
}
|
||||
wasm.ctype = JSON.parse(wasm.cstringToJs(cJson));
|
||||
//console.debug('wasm.ctype length =',wasm.cstrlen(cJson));
|
||||
for(const t of ['access', 'blobFinalizers', 'dataTypes',
|
||||
'encodings', 'flock', 'ioCap',
|
||||
'openFlags', 'prepareFlags', 'resultCodes',
|
||||
'syncFlags', 'udfFlags', 'version'
|
||||
]){
|
||||
for(const [k,v] of Object.entries(wasm.ctype[t])){
|
||||
capi[k] = v;
|
||||
}
|
||||
}
|
||||
/* Bind all registered C-side structs... */
|
||||
for(const s of wasm.ctype.structs){
|
||||
capi[s.name] = sqlite3.StructBinder(s);
|
||||
}
|
||||
}
|
||||
|
||||
})(self);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,393 @@
|
||||
/*
|
||||
2022-07-22
|
||||
|
||||
The author disclaims copyright to this source code. In place of a
|
||||
legal notice, here is a blessing:
|
||||
|
||||
* May you do good and not evil.
|
||||
* May you find forgiveness for yourself and forgive others.
|
||||
* May you share freely, never taking more than you give.
|
||||
|
||||
***********************************************************************
|
||||
|
||||
This file contains extensions to the sqlite3 WASM API related to the
|
||||
Origin-Private FileSystem (OPFS). It is intended to be appended to
|
||||
the main JS deliverable somewhere after sqlite3-api-glue.js and
|
||||
before sqlite3-api-cleanup.js.
|
||||
|
||||
Significant notes and limitations:
|
||||
|
||||
- As of this writing, OPFS is still very much in flux and only
|
||||
available in bleeding-edge versions of Chrome (v102+, noting that
|
||||
that number will increase as the OPFS API matures).
|
||||
|
||||
- The _synchronous_ family of OPFS features (which is what this API
|
||||
requires) are only available in non-shared Worker threads. This
|
||||
file tries to detect that case and becomes a no-op if those
|
||||
features do not seem to be available.
|
||||
*/
|
||||
|
||||
// FileSystemHandle
|
||||
// FileSystemDirectoryHandle
|
||||
// FileSystemFileHandle
|
||||
// FileSystemFileHandle.prototype.createSyncAccessHandle
|
||||
self.sqlite3.postInit.push(function(self, sqlite3){
|
||||
const warn = console.warn.bind(console),
|
||||
error = console.error.bind(console);
|
||||
if(!self.importScripts || !self.FileSystemFileHandle
|
||||
|| !self.FileSystemFileHandle.prototype.createSyncAccessHandle){
|
||||
warn("OPFS not found or its sync API is not available in this environment.");
|
||||
return;
|
||||
}else if(!sqlite3.capi.wasm.bigIntEnabled){
|
||||
error("OPFS requires BigInt support but sqlite3.capi.wasm.bigIntEnabled is false.");
|
||||
return;
|
||||
}
|
||||
//warn('self.FileSystemFileHandle =',self.FileSystemFileHandle);
|
||||
//warn('self.FileSystemFileHandle.prototype =',self.FileSystemFileHandle.prototype);
|
||||
const toss = (...args)=>{throw new Error(args.join(' '))};
|
||||
const capi = sqlite3.capi,
|
||||
wasm = capi.wasm;
|
||||
const sqlite3_vfs = capi.sqlite3_vfs
|
||||
|| toss("Missing sqlite3.capi.sqlite3_vfs object.");
|
||||
const sqlite3_file = capi.sqlite3_file
|
||||
|| toss("Missing sqlite3.capi.sqlite3_file object.");
|
||||
const sqlite3_io_methods = capi.sqlite3_io_methods
|
||||
|| toss("Missing sqlite3.capi.sqlite3_io_methods object.");
|
||||
const StructBinder = sqlite3.StructBinder || toss("Missing sqlite3.StructBinder.");
|
||||
const debug = console.debug.bind(console),
|
||||
log = console.log.bind(console);
|
||||
warn("UNDER CONSTRUCTION: setting up OPFS VFS...");
|
||||
|
||||
const pDVfs = capi.sqlite3_vfs_find(null)/*pointer to default VFS*/;
|
||||
const dVfs = pDVfs
|
||||
? new sqlite3_vfs(pDVfs)
|
||||
: null /* dVfs will be null when sqlite3 is built with
|
||||
SQLITE_OS_OTHER. Though we cannot currently handle
|
||||
that case, the hope is to eventually be able to. */;
|
||||
const oVfs = new sqlite3_vfs();
|
||||
const oIom = new sqlite3_io_methods();
|
||||
oVfs.$iVersion = 2/*yes, two*/;
|
||||
oVfs.$szOsFile = capi.sqlite3_file.structInfo.sizeof;
|
||||
oVfs.$mxPathname = 1024/*sure, why not?*/;
|
||||
oVfs.$zName = wasm.allocCString("opfs");
|
||||
oVfs.ondispose = [
|
||||
'$zName', oVfs.$zName,
|
||||
'cleanup dVfs', ()=>(dVfs ? dVfs.dispose() : null)
|
||||
];
|
||||
if(dVfs){
|
||||
oVfs.$xSleep = dVfs.$xSleep;
|
||||
oVfs.$xRandomness = dVfs.$xRandomness;
|
||||
}
|
||||
// All C-side memory of oVfs is zeroed out, but just to be explicit:
|
||||
oVfs.$xDlOpen = oVfs.$xDlError = oVfs.$xDlSym = oVfs.$xDlClose = null;
|
||||
|
||||
/**
|
||||
Pedantic sidebar about oVfs.ondispose: the entries in that array
|
||||
are items to clean up when oVfs.dispose() is called, but in this
|
||||
environment it will never be called. The VFS instance simply
|
||||
hangs around until the WASM module instance is cleaned up. We
|
||||
"could" _hypothetically_ clean it up by "importing" an
|
||||
sqlite3_os_end() impl into the wasm build, but the shutdown order
|
||||
of the wasm engine and the JS one are undefined so there is no
|
||||
guaranty that the oVfs instance would be available in one
|
||||
environment or the other when sqlite3_os_end() is called (_if_ it
|
||||
gets called at all in a wasm build, which is undefined).
|
||||
*/
|
||||
|
||||
/**
|
||||
Installs a StructBinder-bound function pointer member of the
|
||||
given name and function in the given StructType target object.
|
||||
It creates a WASM proxy for the given function and arranges for
|
||||
that proxy to be cleaned up when tgt.dispose() is called. Throws
|
||||
on the slightest hint of error (e.g. tgt is-not-a StructType,
|
||||
name does not map to a struct-bound member, etc.).
|
||||
|
||||
Returns a proxy for this function which is bound to tgt and takes
|
||||
2 args (name,func). That function returns the same thing,
|
||||
permitting calls to be chained.
|
||||
|
||||
If called with only 1 arg, it has no side effects but returns a
|
||||
func with the same signature as described above.
|
||||
*/
|
||||
const installMethod = function callee(tgt, name, func){
|
||||
if(!(tgt instanceof StructBinder.StructType)){
|
||||
toss("Usage error: target object is-not-a StructType.");
|
||||
}
|
||||
if(1===arguments.length){
|
||||
return (n,f)=>callee(tgt,n,f);
|
||||
}
|
||||
if(!callee.argcProxy){
|
||||
callee.argcProxy = function(func,sig){
|
||||
return function(...args){
|
||||
if(func.length!==arguments.length){
|
||||
toss("Argument mismatch. Native signature is:",sig);
|
||||
}
|
||||
return func.apply(this, args);
|
||||
}
|
||||
};
|
||||
callee.removeFuncList = function(){
|
||||
if(this.ondispose.__removeFuncList){
|
||||
this.ondispose.__removeFuncList.forEach(
|
||||
(v,ndx)=>{
|
||||
if('number'===typeof v){
|
||||
try{wasm.uninstallFunction(v)}
|
||||
catch(e){/*ignore*/}
|
||||
}
|
||||
/* else it's a descriptive label for the next number in
|
||||
the list. */
|
||||
}
|
||||
);
|
||||
delete this.ondispose.__removeFuncList;
|
||||
}
|
||||
};
|
||||
}/*static init*/
|
||||
const sigN = tgt.memberSignature(name);
|
||||
if(sigN.length<2){
|
||||
toss("Member",name," is not a function pointer. Signature =",sigN);
|
||||
}
|
||||
const memKey = tgt.memberKey(name);
|
||||
//log("installMethod",tgt, name, sigN);
|
||||
const fProxy = 1
|
||||
// We can remove this proxy middle-man once the VFS is working
|
||||
? callee.argcProxy(func, sigN)
|
||||
: func;
|
||||
const pFunc = wasm.installFunction(fProxy, tgt.memberSignature(name, true));
|
||||
tgt[memKey] = pFunc;
|
||||
if(!tgt.ondispose) tgt.ondispose = [];
|
||||
if(!tgt.ondispose.__removeFuncList){
|
||||
tgt.ondispose.push('ondispose.__removeFuncList handler',
|
||||
callee.removeFuncList);
|
||||
tgt.ondispose.__removeFuncList = [];
|
||||
}
|
||||
tgt.ondispose.__removeFuncList.push(memKey, pFunc);
|
||||
return (n,f)=>callee(tgt, n, f);
|
||||
}/*installMethod*/;
|
||||
|
||||
/**
|
||||
Map of sqlite3_file pointers to OPFS handles.
|
||||
*/
|
||||
const __opfsHandles = Object.create(null);
|
||||
|
||||
const randomFilename = function f(len=16){
|
||||
if(!f._chars){
|
||||
f._chars = "abcdefghijklmnopqrstuvwxyz"+
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
|
||||
"012346789";
|
||||
f._n = f._chars.length;
|
||||
}
|
||||
const a = [];
|
||||
let i = 0;
|
||||
for( ; i < len; ++i){
|
||||
const ndx = Math.random() * (f._n * 64) % f._n | 0;
|
||||
a[i] = f._chars[ndx];
|
||||
}
|
||||
return a.join('');
|
||||
};
|
||||
|
||||
//const rootDir = await navigator.storage.getDirectory();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Set up OPFS VFS methods...
|
||||
let inst = installMethod(oVfs);
|
||||
inst('xOpen', function(pVfs, zName, pFile, flags, pOutFlags){
|
||||
const f = new sqlite3_file(pFile);
|
||||
f.$pMethods = oIom.pointer;
|
||||
__opfsHandles[pFile] = f;
|
||||
f.opfsHandle = null /* TODO */;
|
||||
if(flags & capi.SQLITE_OPEN_DELETEONCLOSE){
|
||||
f.deleteOnClose = true;
|
||||
}
|
||||
f.filename = zName ? wasm.cstringToJs(zName) : randomFilename();
|
||||
error("OPFS sqlite3_vfs::xOpen is not yet full implemented.");
|
||||
return capi.SQLITE_IOERR;
|
||||
})
|
||||
('xFullPathname', function(pVfs,zName,nOut,pOut){
|
||||
/* Until/unless we have some notion of "current dir"
|
||||
in OPFS, simply copy zName to pOut... */
|
||||
const i = wasm.cstrncpy(pOut, zName, nOut);
|
||||
return i<nOut ? 0 : capi.SQLITE_CANTOPEN
|
||||
/*CANTOPEN is required by the docs but SQLITE_RANGE would be a closer match*/;
|
||||
})
|
||||
('xAccess', function(pVfs,zName,flags,pOut){
|
||||
error("OPFS sqlite3_vfs::xAccess is not yet implemented.");
|
||||
let fileExists = 0;
|
||||
switch(flags){
|
||||
case capi.SQLITE_ACCESS_EXISTS: break;
|
||||
case capi.SQLITE_ACCESS_READWRITE: break;
|
||||
case capi.SQLITE_ACCESS_READ/*docs say this is never used*/:
|
||||
default:
|
||||
error("Unexpected flags value for sqlite3_vfs::xAccess():",flags);
|
||||
return capi.SQLITE_MISUSE;
|
||||
}
|
||||
wasm.setMemValue(pOut, fileExists, 'i32');
|
||||
return 0;
|
||||
})
|
||||
('xDelete', function(pVfs, zName, doSyncDir){
|
||||
error("OPFS sqlite3_vfs::xDelete is not yet implemented.");
|
||||
return capi.SQLITE_IOERR;
|
||||
})
|
||||
('xGetLastError', function(pVfs,nOut,pOut){
|
||||
debug("OPFS sqlite3_vfs::xGetLastError() has nothing sensible to return.");
|
||||
return 0;
|
||||
})
|
||||
('xCurrentTime', function(pVfs,pOut){
|
||||
/* If it turns out that we need to adjust for timezone, see:
|
||||
https://stackoverflow.com/a/11760121/1458521 */
|
||||
wasm.setMemValue(pOut, 2440587.5 + (new Date().getTime()/86400000),
|
||||
'double');
|
||||
return 0;
|
||||
})
|
||||
('xCurrentTimeInt64',function(pVfs,pOut){
|
||||
// TODO: confirm that this calculation is correct
|
||||
wasm.setMemValue(pOut, (2440587.5 * 86400000) + new Date().getTime(),
|
||||
'i64');
|
||||
return 0;
|
||||
});
|
||||
if(!oVfs.$xSleep){
|
||||
inst('xSleep', function(pVfs,ms){
|
||||
error("sqlite3_vfs::xSleep(",ms,") cannot be implemented from "+
|
||||
"JS and we have no default VFS to copy the impl from.");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
if(!oVfs.$xRandomness){
|
||||
inst('xRandomness', function(pVfs, nOut, pOut){
|
||||
const heap = wasm.heap8u();
|
||||
let i = 0;
|
||||
for(; i < nOut; ++i) heap[pOut + i] = (Math.random()*255000) & 0xFF;
|
||||
return i;
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Set up OPFS sqlite3_io_methods...
|
||||
inst = installMethod(oIom);
|
||||
inst('xClose', async function(pFile){
|
||||
warn("xClose(",arguments,") uses await");
|
||||
const f = __opfsHandles[pFile];
|
||||
delete __opfsHandles[pFile];
|
||||
if(f.opfsHandle){
|
||||
await f.opfsHandle.close();
|
||||
if(f.deleteOnClose){
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
f.dispose();
|
||||
return 0;
|
||||
})
|
||||
('xRead', /*i(ppij)*/function(pFile,pDest,n,offset){
|
||||
/* int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst) */
|
||||
try {
|
||||
const f = __opfsHandles[pFile];
|
||||
const heap = wasm.heap8u();
|
||||
const b = new Uint8Array(heap.buffer, pDest, n);
|
||||
const nRead = f.opfsHandle.read(b, {at: offset});
|
||||
if(nRead<n){
|
||||
// MUST zero-fill short reads (per the docs)
|
||||
heap.fill(0, dest + nRead, n - nRead);
|
||||
}
|
||||
return 0;
|
||||
}catch(e){
|
||||
error("xRead(",arguments,") failed:",e);
|
||||
return capi.SQLITE_IOERR_READ;
|
||||
}
|
||||
})
|
||||
('xWrite', /*i(ppij)*/function(pFile,pSrc,n,offset){
|
||||
/* int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst) */
|
||||
try {
|
||||
const f = __opfsHandles[pFile];
|
||||
const b = new Uint8Array(wasm.heap8u().buffer, pSrc, n);
|
||||
const nOut = f.opfsHandle.write(b, {at: offset});
|
||||
if(nOut<n){
|
||||
error("xWrite(",arguments,") short write!");
|
||||
return capi.SQLITE_IOERR_WRITE;
|
||||
}
|
||||
return 0;
|
||||
}catch(e){
|
||||
error("xWrite(",arguments,") failed:",e);
|
||||
return capi.SQLITE_IOERR_WRITE;
|
||||
}
|
||||
})
|
||||
('xTruncate', /*i(pj)*/async function(pFile,sz){
|
||||
/* int (*xTruncate)(sqlite3_file*, sqlite3_int64 size) */
|
||||
try{
|
||||
warn("xTruncate(",arguments,") uses await");
|
||||
const f = __opfsHandles[pFile];
|
||||
await f.opfsHandle.truncate(sz);
|
||||
return 0;
|
||||
}
|
||||
catch(e){
|
||||
error("xTruncate(",arguments,") failed:",e);
|
||||
return capi.SQLITE_IOERR_TRUNCATE;
|
||||
}
|
||||
})
|
||||
('xSync', /*i(pi)*/async function(pFile,flags){
|
||||
/* int (*xSync)(sqlite3_file*, int flags) */
|
||||
try {
|
||||
warn("xSync(",arguments,") uses await");
|
||||
const f = __opfsHandles[pFile];
|
||||
await f.opfsHandle.flush();
|
||||
return 0;
|
||||
}catch(e){
|
||||
error("xSync(",arguments,") failed:",e);
|
||||
return capi.SQLITE_IOERR_SYNC;
|
||||
}
|
||||
})
|
||||
('xFileSize', /*i(pp)*/async function(pFile,pSz){
|
||||
/* int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize) */
|
||||
try {
|
||||
warn("xFileSize(",arguments,") uses await");
|
||||
const f = __opfsHandles[pFile];
|
||||
const fsz = await f.opfsHandle.getSize();
|
||||
capi.wasm.setMemValue(pSz, fsz,'i64');
|
||||
return 0;
|
||||
}catch(e){
|
||||
error("xFileSize(",arguments,") failed:",e);
|
||||
return capi.SQLITE_IOERR_SEEK;
|
||||
}
|
||||
})
|
||||
('xLock', /*i(pi)*/function(pFile,lockType){
|
||||
/* int (*xLock)(sqlite3_file*, int) */
|
||||
// Opening a handle locks it automatically.
|
||||
warn("xLock(",arguments,") is a no-op");
|
||||
return 0;
|
||||
})
|
||||
('xUnlock', /*i(pi)*/function(pFile,lockType){
|
||||
/* int (*xUnlock)(sqlite3_file*, int) */
|
||||
// Opening a handle locks it automatically.
|
||||
warn("xUnlock(",arguments,") is a no-op");
|
||||
return 0;
|
||||
})
|
||||
('xCheckReservedLock', /*i(pp)*/function(pFile,pOut){
|
||||
/* int (*xCheckReservedLock)(sqlite3_file*, int *pResOut) */
|
||||
// Exclusive lock is automatically acquired when opened
|
||||
warn("xCheckReservedLock(",arguments,") is a no-op");
|
||||
wasm.setMemValue(pOut,1,'i32');
|
||||
return 0;
|
||||
})
|
||||
('xFileControl', /*i(pip)*/function(pFile,op,pArg){
|
||||
/* int (*xFileControl)(sqlite3_file*, int op, void *pArg) */
|
||||
debug("xFileControl(",arguments,") is a no-op");
|
||||
return capi.SQLITE_NOTFOUND;
|
||||
})
|
||||
('xDeviceCharacteristics',/*i(p)*/function(pFile){
|
||||
/* int (*xDeviceCharacteristics)(sqlite3_file*) */
|
||||
debug("xDeviceCharacteristics(",pFile,")");
|
||||
return capi.SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN;
|
||||
});
|
||||
// xSectorSize may be NULL
|
||||
//('xSectorSize', function(pFile){
|
||||
// /* int (*xSectorSize)(sqlite3_file*) */
|
||||
// log("xSectorSize(",pFile,")");
|
||||
// return 4096 /* ==> SQLITE_DEFAULT_SECTOR_SIZE */;
|
||||
//})
|
||||
|
||||
const rc = capi.sqlite3_vfs_register(oVfs.pointer, 0);
|
||||
if(rc){
|
||||
oVfs.dispose();
|
||||
toss("sqlite3_vfs_register(OPFS) failed with rc",rc);
|
||||
}
|
||||
capi.sqlite3_vfs_register.addReference(oVfs, oIom);
|
||||
warn("End of (very incomplete) OPFS setup.", oVfs);
|
||||
//oVfs.dispose()/*only because we can't yet do anything with it*/;
|
||||
});
|
||||
@@ -0,0 +1,593 @@
|
||||
/*
|
||||
2022-05-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 is intended to be combined at build-time with other
|
||||
related code, most notably a header and footer which wraps this whole
|
||||
file into an Emscripten Module.postRun() handler which has a parameter
|
||||
named "Module" (the Emscripten Module object). The exact requirements,
|
||||
conventions, and build process are very much under construction and
|
||||
will be (re)documented once they've stopped fluctuating so much.
|
||||
|
||||
Specific goals of this project:
|
||||
|
||||
- Except where noted in the non-goals, provide a more-or-less
|
||||
feature-complete wrapper to the sqlite3 C API, insofar as WASM
|
||||
feature parity with C allows for. In fact, provide at least 3
|
||||
APIs...
|
||||
|
||||
1) Bind a low-level sqlite3 API which is as close to the native
|
||||
one as feasible in terms of usage.
|
||||
|
||||
2) A higher-level API, more akin to sql.js and node.js-style
|
||||
implementations. This one speaks directly to the low-level
|
||||
API. This API must be used from the same thread as the
|
||||
low-level API.
|
||||
|
||||
3) A second higher-level API which speaks to the previous APIs via
|
||||
worker messages. This one is intended for use in the main
|
||||
thread, with the lower-level APIs installed in a Worker thread,
|
||||
and talking to them via Worker messages. Because Workers are
|
||||
asynchronouns and have only a single message channel, some
|
||||
acrobatics are needed here to feed async work results back to
|
||||
the client (as we cannot simply pass around callbacks between
|
||||
the main and Worker threads).
|
||||
|
||||
- Insofar as possible, support client-side storage using JS
|
||||
filesystem APIs. As of this writing, such things are still very
|
||||
much TODO. Initial testing with using IndexedDB as backing storage
|
||||
showed it to work reasonably well, but it's also too easy to
|
||||
corrupt by using a web page in two browser tabs because IndexedDB
|
||||
lacks the locking features needed to support that.
|
||||
|
||||
Specific non-goals of this project:
|
||||
|
||||
- As WASM is a web-centric technology and UTF-8 is the King of
|
||||
Encodings in that realm, there are no currently plans to support
|
||||
the UTF16-related sqlite3 APIs. They would add a complication to
|
||||
the bindings for no appreciable benefit. Though web-related
|
||||
implementation details take priority, the lower-level WASM module
|
||||
"should" work in non-web WASM environments.
|
||||
|
||||
- Supporting old or niche-market platforms. WASM is built for a
|
||||
modern web and requires modern platforms.
|
||||
|
||||
- Though scalar User-Defined Functions (UDFs) may be created in
|
||||
JavaScript, there are currently no plans to add support for
|
||||
aggregate and window functions.
|
||||
|
||||
Attribution:
|
||||
|
||||
This project is endebted to the work of sql.js:
|
||||
|
||||
https://github.com/sql-js/sql.js
|
||||
|
||||
sql.js was an essential stepping stone in this code's development as
|
||||
it demonstrated how to handle some of the WASM-related voodoo (like
|
||||
handling pointers-to-pointers and adding JS implementations of
|
||||
C-bound callback functions). These APIs have a considerably
|
||||
different shape than sql.js's, however.
|
||||
*/
|
||||
|
||||
/**
|
||||
This global symbol is is only a temporary measure: the JS-side
|
||||
post-processing will remove that object from the global scope when
|
||||
setup is complete. We require it there temporarily in order to glue
|
||||
disparate parts together during the loading of the API (which spans
|
||||
several components).
|
||||
|
||||
This function requires a configuration object intended to abstract
|
||||
away details specific to any given WASM environment, primarily so
|
||||
that it can be used without any _direct_ dependency on Emscripten.
|
||||
(That said, OO API #1 requires, as of this writing, Emscripten's
|
||||
virtual filesystem API. Baby steps.)
|
||||
*/
|
||||
self.sqlite3ApiBootstrap = function(config){
|
||||
'use strict';
|
||||
|
||||
/** Throws a new Error, the message of which is the concatenation
|
||||
all args with a space between each. */
|
||||
const toss = (...args)=>{throw new Error(args.join(' '))};
|
||||
|
||||
/**
|
||||
Returns true if n is a 32-bit (signed) integer, else
|
||||
false. This is used for determining when we need to switch to
|
||||
double-type DB operations for integer values in order to keep
|
||||
more precision.
|
||||
*/
|
||||
const isInt32 = function(n){
|
||||
return ('bigint'!==typeof n /*TypeError: can't convert BigInt to number*/)
|
||||
&& !!(n===(n|0) && n<=2147483647 && n>=-2147483648);
|
||||
};
|
||||
|
||||
/** Returns v if v appears to be a TypedArray, else false. */
|
||||
const isTypedArray = (v)=>{
|
||||
return (v && v.constructor && isInt32(v.constructor.BYTES_PER_ELEMENT)) ? v : false;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns true if v appears to be one of our bind()-able
|
||||
TypedArray types: Uint8Array or Int8Array. Support for
|
||||
TypedArrays with element sizes >1 is TODO.
|
||||
*/
|
||||
const isBindableTypedArray = (v)=>{
|
||||
return v && v.constructor && (1===v.constructor.BYTES_PER_ELEMENT);
|
||||
};
|
||||
|
||||
/**
|
||||
Returns true if v appears to be one of the TypedArray types
|
||||
which is legal for holding SQL code (as opposed to binary blobs).
|
||||
|
||||
Currently this is the same as isBindableTypedArray() but it
|
||||
seems likely that we'll eventually want to add Uint32Array
|
||||
and friends to the isBindableTypedArray() list but not to the
|
||||
isSQLableTypedArray() list.
|
||||
*/
|
||||
const isSQLableTypedArray = (v)=>{
|
||||
return v && v.constructor && (1===v.constructor.BYTES_PER_ELEMENT);
|
||||
};
|
||||
|
||||
/** Returns true if isBindableTypedArray(v) does, else throws with a message
|
||||
that v is not a supported TypedArray value. */
|
||||
const affirmBindableTypedArray = (v)=>{
|
||||
return isBindableTypedArray(v)
|
||||
|| toss("Value is not of a supported TypedArray type.");
|
||||
};
|
||||
|
||||
const utf8Decoder = new TextDecoder('utf-8');
|
||||
const typedArrayToString = (str)=>utf8Decoder.decode(str);
|
||||
|
||||
/**
|
||||
An Error subclass specifically for reporting Wasm-level malloc()
|
||||
failure and enabling clients to unambiguously identify such
|
||||
exceptions.
|
||||
*/
|
||||
class WasmAllocError extends Error {
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
this.name = 'WasmAllocError';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
The main sqlite3 binding API gets installed into this object,
|
||||
mimicking the C API as closely as we can. The numerous members
|
||||
names with prefixes 'sqlite3_' and 'SQLITE_' behave, insofar as
|
||||
possible, identically to the C-native counterparts, as documented at:
|
||||
|
||||
https://www.sqlite.org/c3ref/intro.html
|
||||
|
||||
A very few exceptions require an additional level of proxy
|
||||
function or may otherwise require special attention in the WASM
|
||||
environment, and all such cases are document here. Those not
|
||||
documented here are installed as 1-to-1 proxies for their C-side
|
||||
counterparts.
|
||||
*/
|
||||
const capi = {
|
||||
/**
|
||||
An Error subclass which is thrown by this object's alloc() method
|
||||
on OOM.
|
||||
*/
|
||||
WasmAllocError: WasmAllocError,
|
||||
/**
|
||||
The API's one single point of access to the WASM-side memory
|
||||
allocator. Works like malloc(3) (and is likely bound to
|
||||
malloc()) but throws an WasmAllocError if allocation fails. It is
|
||||
important that any code which might pass through the sqlite3 C
|
||||
API NOT throw and must instead return SQLITE_NOMEM (or
|
||||
equivalent, depending on the context).
|
||||
|
||||
That said, very few cases in the API can result in
|
||||
client-defined functions propagating exceptions via the C-style
|
||||
API. Most notably, this applies ot User-defined SQL Functions
|
||||
(UDFs) registered via sqlite3_create_function_v2(). For that
|
||||
specific case it is recommended that all UDF creation be
|
||||
funneled through a utility function and that a wrapper function
|
||||
be added around the UDF which catches any exception and sets
|
||||
the error state to OOM. (The overall complexity of registering
|
||||
UDFs essentially requires a helper for doing so!)
|
||||
*/
|
||||
alloc: undefined/*installed later*/,
|
||||
/**
|
||||
The API's one single point of access to the WASM-side memory
|
||||
deallocator. Works like free(3) (and is likely bound to
|
||||
free()).
|
||||
*/
|
||||
dealloc: undefined/*installed later*/,
|
||||
/**
|
||||
When using sqlite3_open_v2() it is important to keep the following
|
||||
in mind:
|
||||
|
||||
https://www.sqlite.org/c3ref/open.html
|
||||
|
||||
- The flags for use with its 3rd argument are installed in this
|
||||
object using the C-cide names, e.g. SQLITE_OPEN_CREATE.
|
||||
|
||||
- If the combination of flags passed to it are invalid,
|
||||
behavior is undefined. Thus is is never okay to call this
|
||||
with fewer than 3 arguments, as JS will default the
|
||||
missing arguments to `undefined`, which will result in a
|
||||
flag value of 0. Most of the available SQLITE_OPEN_xxx
|
||||
flags are meaningless in the WASM build, e.g. the mutext-
|
||||
and cache-related flags, but they are retained in this
|
||||
API for consistency's sake.
|
||||
|
||||
- The final argument to this function specifies the VFS to
|
||||
use, which is largely (but not entirely!) meaningless in
|
||||
the WASM environment. It should always be null or
|
||||
undefined, and it is safe to elide that argument when
|
||||
calling this function.
|
||||
*/
|
||||
sqlite3_open_v2: function(filename,dbPtrPtr,flags,vfsStr){}/*installed later*/,
|
||||
/**
|
||||
The sqlite3_prepare_v3() binding handles two different uses
|
||||
with differing JS/WASM semantics:
|
||||
|
||||
1) sqlite3_prepare_v3(pDb, sqlString, -1, prepFlags, ppStmt [, null])
|
||||
|
||||
2) sqlite3_prepare_v3(pDb, sqlPointer, sqlByteLen, prepFlags, ppStmt, sqlPointerToPointer)
|
||||
|
||||
Note that the SQL length argument (the 3rd argument) must, for
|
||||
usage (1), always be negative because it must be a byte length
|
||||
and that value is expensive to calculate from JS (where only
|
||||
the character length of strings is readily available). It is
|
||||
retained in this API's interface for code/documentation
|
||||
compatibility reasons but is currently _always_ ignored. With
|
||||
usage (2), the 3rd argument is used as-is but is is still
|
||||
critical that the C-style input string (2nd argument) be
|
||||
terminated with a 0 byte.
|
||||
|
||||
In usage (1), the 2nd argument must be of type string,
|
||||
Uint8Array, or Int8Array (either of which is assumed to
|
||||
hold SQL). If it is, this function assumes case (1) and
|
||||
calls the underyling C function with the equivalent of:
|
||||
|
||||
(pDb, sqlAsString, -1, prepFlags, ppStmt, null)
|
||||
|
||||
The pzTail argument is ignored in this case because its result
|
||||
is meaningless when a string-type value is passed through
|
||||
(because the string goes through another level of internal
|
||||
conversion for WASM's sake and the result pointer would refer
|
||||
to that transient conversion's memory, not the passed-in
|
||||
string).
|
||||
|
||||
If the sql argument is not a string, it must be a _pointer_ to
|
||||
a NUL-terminated string which was allocated in the WASM memory
|
||||
(e.g. using cwapi.wasm.alloc() or equivalent). In that case,
|
||||
the final argument may be 0/null/undefined or must be a pointer
|
||||
to which the "tail" of the compiled SQL is written, as
|
||||
documented for the C-side sqlite3_prepare_v3(). In case (2),
|
||||
the underlying C function is called with the equivalent of:
|
||||
|
||||
(pDb, sqlAsPointer, (sqlByteLen||-1), prepFlags, ppStmt, pzTail)
|
||||
|
||||
It returns its result and compiled statement as documented in
|
||||
the C API. Fetching the output pointers (5th and 6th
|
||||
parameters) requires using capi.wasm.getMemValue() (or
|
||||
equivalent) and the pzTail will point to an address relative to
|
||||
the sqlAsPointer value.
|
||||
|
||||
If passed an invalid 2nd argument type, this function will
|
||||
return SQLITE_MISUSE but will unfortunately be able to return
|
||||
any additional error information because we have no way to set
|
||||
the db's error state such that this function could return a
|
||||
non-0 integer and the client could call sqlite3_errcode() or
|
||||
sqlite3_errmsg() to fetch it. See the RFE at:
|
||||
|
||||
https://sqlite.org/forum/forumpost/f9eb79b11aefd4fc81d
|
||||
|
||||
The alternative would be to throw an exception for that case,
|
||||
but that would be in strong constrast to the rest of the
|
||||
C-level API and seems likely to cause more confusion.
|
||||
|
||||
Side-note: in the C API the function does not fail if provided
|
||||
an empty string but its result output pointer will be NULL.
|
||||
*/
|
||||
sqlite3_prepare_v3: function(dbPtr, sql, sqlByteLen, prepFlags,
|
||||
stmtPtrPtr, strPtrPtr){}/*installed later*/,
|
||||
|
||||
/**
|
||||
Equivalent to calling sqlite3_prapare_v3() with 0 as its 4th argument.
|
||||
*/
|
||||
sqlite3_prepare_v2: function(dbPtr, sql, sqlByteLen, stmtPtrPtr,
|
||||
strPtrPtr){}/*installed later*/,
|
||||
|
||||
/**
|
||||
Various internal-use utilities are added here as needed. They
|
||||
are bound to an object only so that we have access to them in
|
||||
the differently-scoped steps of the API bootstrapping
|
||||
process. At the end of the API setup process, this object gets
|
||||
removed.
|
||||
*/
|
||||
util:{
|
||||
isInt32, isTypedArray, isBindableTypedArray, isSQLableTypedArray,
|
||||
affirmBindableTypedArray, typedArrayToString
|
||||
},
|
||||
|
||||
/**
|
||||
Holds state which are specific to the WASM-related
|
||||
infrastructure and glue code. It is not expected that client
|
||||
code will normally need these, but they're exposed here in case
|
||||
it does. These APIs are _not_ to be considered an
|
||||
official/stable part of the sqlite3 WASM API. They may change
|
||||
as the developers' experience suggests appropriate changes.
|
||||
|
||||
Note that a number of members of this object are injected
|
||||
dynamically after the api object is fully constructed, so
|
||||
not all are documented inline here.
|
||||
*/
|
||||
wasm: {
|
||||
//^^^ TODO?: move wasm from sqlite3.capi.wasm to sqlite3.wasm
|
||||
/**
|
||||
Emscripten APIs have a deep-seated assumption that all pointers
|
||||
are 32 bits. We'll remain optimistic that that won't always be
|
||||
the case and will use this constant in places where we might
|
||||
otherwise use a hard-coded 4.
|
||||
*/
|
||||
ptrSizeof: config.wasmPtrSizeof || 4,
|
||||
/**
|
||||
The WASM IR (Intermediate Representation) value for
|
||||
pointer-type values. It MUST refer to a value type of the
|
||||
size described by this.ptrSizeof _or_ it may be any value
|
||||
which ends in '*', which Emscripten's glue code internally
|
||||
translates to i32.
|
||||
*/
|
||||
ptrIR: config.wasmPtrIR || "i32",
|
||||
/**
|
||||
True if BigInt support was enabled via (e.g.) the
|
||||
Emscripten -sWASM_BIGINT flag, else false. When
|
||||
enabled, certain 64-bit sqlite3 APIs are enabled which
|
||||
are not otherwise enabled due to JS/WASM int64
|
||||
impedence mismatches.
|
||||
*/
|
||||
bigIntEnabled: !!config.bigIntEnabled,
|
||||
/**
|
||||
The symbols exported by the WASM environment.
|
||||
*/
|
||||
exports: config.exports
|
||||
|| toss("Missing API config.exports (WASM module exports)."),
|
||||
|
||||
/**
|
||||
When Emscripten compiles with `-sIMPORT_MEMORY`, it
|
||||
initalizes the heap and imports it into wasm, as opposed to
|
||||
the other way around. In this case, the memory is not
|
||||
available via this.exports.memory.
|
||||
*/
|
||||
memory: config.memory || config.exports['memory']
|
||||
|| toss("API config object requires a WebAssembly.Memory object",
|
||||
"in either config.exports.memory (exported)",
|
||||
"or config.memory (imported)."),
|
||||
/* Many more wasm-related APIs get installed later on. */
|
||||
}/*wasm*/
|
||||
}/*capi*/;
|
||||
|
||||
/**
|
||||
capi.wasm.alloc()'s srcTypedArray.byteLength bytes,
|
||||
populates them with the values from the source
|
||||
TypedArray, and returns the pointer to that memory. The
|
||||
returned pointer must eventually be passed to
|
||||
capi.wasm.dealloc() to clean it up.
|
||||
|
||||
As a special case, to avoid further special cases where
|
||||
this is used, if srcTypedArray.byteLength is 0, it
|
||||
allocates a single byte and sets it to the value
|
||||
0. Even in such cases, calls must behave as if the
|
||||
allocated memory has exactly srcTypedArray.byteLength
|
||||
bytes.
|
||||
|
||||
ACHTUNG: this currently only works for Uint8Array and
|
||||
Int8Array types and will throw if srcTypedArray is of
|
||||
any other type.
|
||||
*/
|
||||
capi.wasm.mallocFromTypedArray = function(srcTypedArray){
|
||||
affirmBindableTypedArray(srcTypedArray);
|
||||
const pRet = this.alloc(srcTypedArray.byteLength || 1);
|
||||
this.heapForSize(srcTypedArray.constructor).set(srcTypedArray.byteLength ? srcTypedArray : [0], pRet);
|
||||
return pRet;
|
||||
}.bind(capi.wasm);
|
||||
|
||||
const keyAlloc = config.allocExportName || 'malloc',
|
||||
keyDealloc = config.deallocExportName || 'free';
|
||||
for(const key of [keyAlloc, keyDealloc]){
|
||||
const f = capi.wasm.exports[key];
|
||||
if(!(f instanceof Function)) toss("Missing required exports[",key,"] function.");
|
||||
}
|
||||
capi.wasm.alloc = function(n){
|
||||
const m = this.exports[keyAlloc](n);
|
||||
if(!m) throw new WasmAllocError("Failed to allocate "+n+" bytes.");
|
||||
return m;
|
||||
}.bind(capi.wasm)
|
||||
capi.wasm.dealloc = (m)=>capi.wasm.exports[keyDealloc](m);
|
||||
|
||||
/**
|
||||
Reports info about compile-time options using
|
||||
sqlite_compileoption_get() and sqlite3_compileoption_used(). It
|
||||
has several distinct uses:
|
||||
|
||||
If optName is an array then it is expected to be a list of
|
||||
compilation options and this function returns an object
|
||||
which maps each such option to true or false, indicating
|
||||
whether or not the given option was included in this
|
||||
build. That object is returned.
|
||||
|
||||
If optName is an object, its keys are expected to be compilation
|
||||
options and this function sets each entry to true or false,
|
||||
indicating whether the compilation option was used or not. That
|
||||
object is returned.
|
||||
|
||||
If passed no arguments then it returns an object mapping
|
||||
all known compilation options to their compile-time values,
|
||||
or boolean true if they are defined with no value. This
|
||||
result, which is relatively expensive to compute, is cached
|
||||
and returned for future no-argument calls.
|
||||
|
||||
In all other cases it returns true if the given option was
|
||||
active when when compiling the sqlite3 module, else false.
|
||||
|
||||
Compile-time option names may optionally include their
|
||||
"SQLITE_" prefix. When it returns an object of all options,
|
||||
the prefix is elided.
|
||||
*/
|
||||
capi.wasm.compileOptionUsed = function f(optName){
|
||||
if(!arguments.length){
|
||||
if(f._result) return f._result;
|
||||
else if(!f._opt){
|
||||
f._rx = /^([^=]+)=(.+)/;
|
||||
f._rxInt = /^-?\d+$/;
|
||||
f._opt = function(opt, rv){
|
||||
const m = f._rx.exec(opt);
|
||||
rv[0] = (m ? m[1] : opt);
|
||||
rv[1] = m ? (f._rxInt.test(m[2]) ? +m[2] : m[2]) : true;
|
||||
};
|
||||
}
|
||||
const rc = {}, ov = [0,0];
|
||||
let i = 0, k;
|
||||
while((k = capi.sqlite3_compileoption_get(i++))){
|
||||
f._opt(k,ov);
|
||||
rc[ov[0]] = ov[1];
|
||||
}
|
||||
return f._result = rc;
|
||||
}else if(Array.isArray(optName)){
|
||||
const rc = {};
|
||||
optName.forEach((v)=>{
|
||||
rc[v] = capi.sqlite3_compileoption_used(v);
|
||||
});
|
||||
return rc;
|
||||
}else if('object' === typeof optName){
|
||||
Object.keys(optName).forEach((k)=> {
|
||||
optName[k] = capi.sqlite3_compileoption_used(k);
|
||||
});
|
||||
return optName;
|
||||
}
|
||||
return (
|
||||
'string'===typeof optName
|
||||
) ? !!capi.sqlite3_compileoption_used(optName) : false;
|
||||
}/*compileOptionUsed()*/;
|
||||
|
||||
capi.wasm.bindingSignatures = [
|
||||
/**
|
||||
Signatures for the WASM-exported C-side functions. Each entry
|
||||
is an array with 2+ elements:
|
||||
|
||||
["c-side name",
|
||||
"result type" (capi.wasm.xWrap() syntax),
|
||||
[arg types in xWrap() syntax]
|
||||
// ^^^ this needn't strictly be an array: it can be subsequent
|
||||
// elements instead: [x,y,z] is equivalent to x,y,z
|
||||
]
|
||||
*/
|
||||
// Please keep these sorted by function name!
|
||||
["sqlite3_bind_blob","int", "sqlite3_stmt*", "int", "*", "int", "*"],
|
||||
["sqlite3_bind_double","int", "sqlite3_stmt*", "int", "f64"],
|
||||
["sqlite3_bind_int","int", "sqlite3_stmt*", "int", "int"],
|
||||
["sqlite3_bind_null",undefined, "sqlite3_stmt*", "int"],
|
||||
["sqlite3_bind_parameter_count", "int", "sqlite3_stmt*"],
|
||||
["sqlite3_bind_parameter_index","int", "sqlite3_stmt*", "string"],
|
||||
["sqlite3_bind_text","int", "sqlite3_stmt*", "int", "string", "int", "int"],
|
||||
["sqlite3_close_v2", "int", "sqlite3*"],
|
||||
["sqlite3_changes", "int", "sqlite3*"],
|
||||
["sqlite3_clear_bindings","int", "sqlite3_stmt*"],
|
||||
["sqlite3_column_blob","*", "sqlite3_stmt*", "int"],
|
||||
["sqlite3_column_bytes","int", "sqlite3_stmt*", "int"],
|
||||
["sqlite3_column_count", "int", "sqlite3_stmt*"],
|
||||
["sqlite3_column_double","f64", "sqlite3_stmt*", "int"],
|
||||
["sqlite3_column_int","int", "sqlite3_stmt*", "int"],
|
||||
["sqlite3_column_name","string", "sqlite3_stmt*", "int"],
|
||||
["sqlite3_column_text","string", "sqlite3_stmt*", "int"],
|
||||
["sqlite3_column_type","int", "sqlite3_stmt*", "int"],
|
||||
["sqlite3_compileoption_get", "string", "int"],
|
||||
["sqlite3_compileoption_used", "int", "string"],
|
||||
["sqlite3_create_function_v2", "int",
|
||||
"sqlite3*", "string", "int", "int", "*", "*", "*", "*", "*"],
|
||||
["sqlite3_data_count", "int", "sqlite3_stmt*"],
|
||||
["sqlite3_db_filename", "string", "sqlite3*", "string"],
|
||||
["sqlite3_db_name", "string", "sqlite3*", "int"],
|
||||
["sqlite3_errmsg", "string", "sqlite3*"],
|
||||
["sqlite3_error_offset", "int", "sqlite3*"],
|
||||
["sqlite3_errstr", "string", "int"],
|
||||
//["sqlite3_exec", "int", "sqlite3*", "string", "*", "*", "**"],
|
||||
// ^^^ TODO: we need a wrapper to support passing a function pointer or a function
|
||||
// for the callback.
|
||||
["sqlite3_expanded_sql", "string", "sqlite3_stmt*"],
|
||||
["sqlite3_extended_errcode", "int", "sqlite3*"],
|
||||
["sqlite3_extended_result_codes", "int", "sqlite3*", "int"],
|
||||
["sqlite3_finalize", "int", "sqlite3_stmt*"],
|
||||
["sqlite3_initialize", undefined],
|
||||
["sqlite3_interrupt", undefined, "sqlite3*"
|
||||
/* ^^^ we cannot actually currently support this because JS is
|
||||
single-threaded and we don't have a portable way to access a DB
|
||||
from 2 SharedWorkers concurrently. */],
|
||||
["sqlite3_libversion", "string"],
|
||||
["sqlite3_libversion_number", "int"],
|
||||
["sqlite3_open", "int", "string", "*"],
|
||||
["sqlite3_open_v2", "int", "string", "*", "int", "string"],
|
||||
/* sqlite3_prepare_v2() and sqlite3_prepare_v3() are handled
|
||||
separately due to us requiring two different sets of semantics
|
||||
for those, depending on how their SQL argument is provided. */
|
||||
["sqlite3_reset", "int", "sqlite3_stmt*"],
|
||||
["sqlite3_result_blob",undefined, "*", "*", "int", "*"],
|
||||
["sqlite3_result_double",undefined, "*", "f64"],
|
||||
["sqlite3_result_error",undefined, "*", "string", "int"],
|
||||
["sqlite3_result_error_code", undefined, "*", "int"],
|
||||
["sqlite3_result_error_nomem", undefined, "*"],
|
||||
["sqlite3_result_error_toobig", undefined, "*"],
|
||||
["sqlite3_result_int",undefined, "*", "int"],
|
||||
["sqlite3_result_null",undefined, "*"],
|
||||
["sqlite3_result_text",undefined, "*", "string", "int", "*"],
|
||||
["sqlite3_sourceid", "string"],
|
||||
["sqlite3_sql", "string", "sqlite3_stmt*"],
|
||||
["sqlite3_step", "int", "sqlite3_stmt*"],
|
||||
["sqlite3_strglob", "int", "string","string"],
|
||||
["sqlite3_strlike", "int", "string","string","int"],
|
||||
["sqlite3_total_changes", "int", "sqlite3*"],
|
||||
["sqlite3_value_blob", "*", "*"],
|
||||
["sqlite3_value_bytes","int", "*"],
|
||||
["sqlite3_value_double","f64", "*"],
|
||||
["sqlite3_value_text", "string", "*"],
|
||||
["sqlite3_value_type", "int", "*"],
|
||||
["sqlite3_vfs_find", "*", "string"],
|
||||
["sqlite3_vfs_register", "int", "*", "int"]
|
||||
]/*capi.wasm.bindingSignatures*/;
|
||||
|
||||
if(false && capi.wasm.compileOptionUsed('SQLITE_ENABLE_NORMALIZE')){
|
||||
/* ^^^ "the problem" is that this is an option feature and the
|
||||
build-time function-export list does not currently take
|
||||
optional features into account. */
|
||||
capi.wasm.bindingSignatures.push(["sqlite3_normalized_sql", "string", "sqlite3_stmt*"]);
|
||||
}
|
||||
|
||||
/**
|
||||
Functions which require BigInt (int64) support are separated from
|
||||
the others because we need to conditionally bind them or apply
|
||||
dummy impls, depending on the capabilities of the environment.
|
||||
*/
|
||||
capi.wasm.bindingSignatures.int64 = [
|
||||
["sqlite3_bind_int64","int", ["sqlite3_stmt*", "int", "i64"]],
|
||||
["sqlite3_changes64","i64", ["sqlite3*"]],
|
||||
["sqlite3_column_int64","i64", ["sqlite3_stmt*", "int"]],
|
||||
["sqlite3_total_changes64", "i64", ["sqlite3*"]]
|
||||
];
|
||||
|
||||
/* The remainder of the API will be set up in later steps. */
|
||||
return {
|
||||
capi,
|
||||
postInit: [
|
||||
/* some pieces of the API may install functions into this array,
|
||||
and each such function will be called, passed (self,sqlite3),
|
||||
at the very end of the API load/init process, where self is
|
||||
the current global object and sqlite3 is the object returned
|
||||
from sqlite3ApiBootstrap(). This array will be removed at the
|
||||
end of the API setup process. */],
|
||||
/** Config is needed downstream for gluing pieces together. It
|
||||
will be removed at the end of the API setup process. */
|
||||
config
|
||||
};
|
||||
}/*sqlite3ApiBootstrap()*/;
|
||||
@@ -0,0 +1,420 @@
|
||||
/*
|
||||
2022-07-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 a Worker-based wrapper around SQLite3 OO API
|
||||
#1.
|
||||
|
||||
In order to permit this API to be loaded in worker threads without
|
||||
automatically registering onmessage handlers, initializing the
|
||||
worker API requires calling initWorkerAPI(). If this function
|
||||
is called from a non-worker thread then it throws an exception.
|
||||
|
||||
When initialized, it installs message listeners to receive messages
|
||||
from the main thread and then it posts a message in the form:
|
||||
|
||||
```
|
||||
{type:'sqlite3-api',data:'worker-ready'}
|
||||
```
|
||||
|
||||
This file requires that the core C-style sqlite3 API and OO API #1
|
||||
have been loaded and that self.sqlite3 contains both,
|
||||
as documented for those APIs.
|
||||
*/
|
||||
self.sqlite3.initWorkerAPI = function(){
|
||||
'use strict';
|
||||
/**
|
||||
UNDER CONSTRUCTION
|
||||
|
||||
We need an API which can proxy the DB API via a Worker message
|
||||
interface. The primary quirky factor in such an API is that we
|
||||
cannot pass callback functions between the window thread and a
|
||||
worker thread, so we have to receive all db results via
|
||||
asynchronous message-passing. That requires an asychronous API
|
||||
with a distinctly different shape that the main OO API.
|
||||
|
||||
Certain important considerations here include:
|
||||
|
||||
- Support only one db connection or multiple? The former is far
|
||||
easier, but there's always going to be a user out there who wants
|
||||
to juggle six database handles at once. Do we add that complexity
|
||||
or tell such users to write their own code using the provided
|
||||
lower-level APIs?
|
||||
|
||||
- Fetching multiple results: do we pass them on as a series of
|
||||
messages, with start/end messages on either end, or do we collect
|
||||
all results and bundle them back in a single message? The former
|
||||
is, generically speaking, more memory-efficient but the latter
|
||||
far easier to implement in this environment. The latter is
|
||||
untennable for large data sets. Despite a web page hypothetically
|
||||
being a relatively limited environment, there will always be
|
||||
those users who feel that they should/need to be able to work
|
||||
with multi-hundred-meg (or larger) blobs, and passing around
|
||||
arrays of those may quickly exhaust the JS engine's memory.
|
||||
|
||||
TODOs include, but are not limited to:
|
||||
|
||||
- The ability to manage multiple DB handles. This can
|
||||
potentially be done via a simple mapping of DB.filename or
|
||||
DB.pointer (`sqlite3*` handle) to DB objects. The open()
|
||||
interface would need to provide an ID (probably DB.pointer) back
|
||||
to the user which can optionally be passed as an argument to
|
||||
the other APIs (they'd default to the first-opened DB, for
|
||||
ease of use). Client-side usability of this feature would
|
||||
benefit from making another wrapper class (or a singleton)
|
||||
available to the main thread, with that object proxying all(?)
|
||||
communication with the worker.
|
||||
|
||||
- Revisit how virtual files are managed. We currently delete DBs
|
||||
from the virtual filesystem when we close them, for the sake of
|
||||
saving memory (the VFS lives in RAM). Supporting multiple DBs may
|
||||
require that we give up that habit. Similarly, fully supporting
|
||||
ATTACH, where a user can upload multiple DBs and ATTACH them,
|
||||
also requires the that we manage the VFS entries better.
|
||||
*/
|
||||
const toss = (...args)=>{throw new Error(args.join(' '))};
|
||||
if('function' !== typeof importScripts){
|
||||
toss("Cannot initalize the sqlite3 worker API in the main thread.");
|
||||
}
|
||||
const self = this.self;
|
||||
const sqlite3 = this.sqlite3 || toss("Missing this.sqlite3 object.");
|
||||
const SQLite3 = sqlite3.oo1 || toss("Missing this.sqlite3.oo1 OO API.");
|
||||
const DB = SQLite3.DB;
|
||||
|
||||
/**
|
||||
Returns the app-wide unique ID for the given db, creating one if
|
||||
needed.
|
||||
*/
|
||||
const getDbId = function(db){
|
||||
let id = wState.idMap.get(db);
|
||||
if(id) return id;
|
||||
id = 'db#'+(++wState.idSeq)+'@'+db.pointer;
|
||||
/** ^^^ can't simply use db.pointer b/c closing/opening may re-use
|
||||
the same address, which could map pending messages to a wrong
|
||||
instance. */
|
||||
wState.idMap.set(db, id);
|
||||
return id;
|
||||
};
|
||||
|
||||
/**
|
||||
Helper for managing Worker-level state.
|
||||
*/
|
||||
const wState = {
|
||||
defaultDb: undefined,
|
||||
idSeq: 0,
|
||||
idMap: new WeakMap,
|
||||
open: function(arg){
|
||||
// TODO: if arg is a filename, look for a db in this.dbs with the
|
||||
// same filename and close/reopen it (or just pass it back as is?).
|
||||
if(!arg && this.defaultDb) return this.defaultDb;
|
||||
//???if(this.defaultDb) this.defaultDb.close();
|
||||
let db;
|
||||
db = (Array.isArray(arg) ? new DB(...arg) : new DB(arg));
|
||||
this.dbs[getDbId(db)] = db;
|
||||
if(!this.defaultDb) this.defaultDb = db;
|
||||
return db;
|
||||
},
|
||||
close: function(db,alsoUnlink){
|
||||
if(db){
|
||||
delete this.dbs[getDbId(db)];
|
||||
db.close(alsoUnlink);
|
||||
if(db===this.defaultDb) this.defaultDb = undefined;
|
||||
}
|
||||
},
|
||||
post: function(type,data,xferList){
|
||||
if(xferList){
|
||||
self.postMessage({type, data},xferList);
|
||||
xferList.length = 0;
|
||||
}else{
|
||||
self.postMessage({type, data});
|
||||
}
|
||||
},
|
||||
/** Map of DB IDs to DBs. */
|
||||
dbs: Object.create(null),
|
||||
getDb: function(id,require=true){
|
||||
return this.dbs[id]
|
||||
|| (require ? toss("Unknown (or closed) DB ID:",id) : undefined);
|
||||
}
|
||||
};
|
||||
|
||||
/** Throws if the given db is falsy or not opened. */
|
||||
const affirmDbOpen = function(db = wState.defaultDb){
|
||||
return (db && db.pointer) ? db : toss("DB is not opened.");
|
||||
};
|
||||
|
||||
/** Extract dbId from the given message payload. */
|
||||
const getMsgDb = function(msgData,affirmExists=true){
|
||||
const db = wState.getDb(msgData.dbId,false) || wState.defaultDb;
|
||||
return affirmExists ? affirmDbOpen(db) : db;
|
||||
};
|
||||
|
||||
const getDefaultDbId = function(){
|
||||
return wState.defaultDb && getDbId(wState.defaultDb);
|
||||
};
|
||||
|
||||
/**
|
||||
A level of "organizational abstraction" for the Worker
|
||||
API. Each method in this object must map directly to a Worker
|
||||
message type key. The onmessage() dispatcher attempts to
|
||||
dispatch all inbound messages to a method of this object,
|
||||
passing it the event.data part of the inbound event object. All
|
||||
methods must return a plain Object containing any response
|
||||
state, which the dispatcher may amend. All methods must throw
|
||||
on error.
|
||||
*/
|
||||
const wMsgHandler = {
|
||||
xfer: [/*Temp holder for "transferable" postMessage() state.*/],
|
||||
/**
|
||||
Proxy for DB.exec() which expects a single argument of type
|
||||
string (SQL to execute) or an options object in the form
|
||||
expected by exec(). The notable differences from exec()
|
||||
include:
|
||||
|
||||
- The default value for options.rowMode is 'array' because
|
||||
the normal default cannot cross the window/Worker boundary.
|
||||
|
||||
- A function-type options.callback property cannot cross
|
||||
the window/Worker boundary, so is not useful here. If
|
||||
options.callback is a string then it is assumed to be a
|
||||
message type key, in which case a callback function will be
|
||||
applied which posts each row result via:
|
||||
|
||||
postMessage({type: thatKeyType, data: theRow})
|
||||
|
||||
And, at the end of the result set (whether or not any
|
||||
result rows were produced), it will post an identical
|
||||
message with data:null to alert the caller than the result
|
||||
set is completed.
|
||||
|
||||
The callback proxy must not recurse into this interface, or
|
||||
results are undefined. (It hypothetically cannot recurse
|
||||
because an exec() call will be tying up the Worker thread,
|
||||
causing any recursion attempt to wait until the first
|
||||
exec() is completed.)
|
||||
|
||||
The response is the input options object (or a synthesized
|
||||
one if passed only a string), noting that
|
||||
options.resultRows and options.columnNames may be populated
|
||||
by the call to exec().
|
||||
|
||||
This opens/creates the Worker's db if needed.
|
||||
*/
|
||||
exec: function(ev){
|
||||
const opt = (
|
||||
'string'===typeof ev.data
|
||||
) ? {sql: ev.data} : (ev.data || Object.create(null));
|
||||
if(undefined===opt.rowMode){
|
||||
/* Since the default rowMode of 'stmt' is not useful
|
||||
for the Worker interface, we'll default to
|
||||
something else. */
|
||||
opt.rowMode = 'array';
|
||||
}else if('stmt'===opt.rowMode){
|
||||
toss("Invalid rowMode for exec(): stmt mode",
|
||||
"does not work in the Worker API.");
|
||||
}
|
||||
const db = getMsgDb(ev);
|
||||
if(opt.callback || Array.isArray(opt.resultRows)){
|
||||
// Part of a copy-avoidance optimization for blobs
|
||||
db._blobXfer = this.xfer;
|
||||
}
|
||||
const callbackMsgType = opt.callback;
|
||||
if('string' === typeof callbackMsgType){
|
||||
/* Treat this as a worker message type and post each
|
||||
row as a message of that type. */
|
||||
const that = this;
|
||||
opt.callback =
|
||||
(row)=>wState.post(callbackMsgType,row,this.xfer);
|
||||
}
|
||||
try {
|
||||
db.exec(opt);
|
||||
if(opt.callback instanceof Function){
|
||||
opt.callback = callbackMsgType;
|
||||
wState.post(callbackMsgType, null);
|
||||
}
|
||||
}/*catch(e){
|
||||
console.warn("Worker is propagating:",e);throw e;
|
||||
}*/finally{
|
||||
delete db._blobXfer;
|
||||
if(opt.callback){
|
||||
opt.callback = callbackMsgType;
|
||||
}
|
||||
}
|
||||
return opt;
|
||||
}/*exec()*/,
|
||||
/**
|
||||
TO(re)DO, once we can abstract away access to the
|
||||
JS environment's virtual filesystem. Currently this
|
||||
always throws.
|
||||
|
||||
Response is (should be) an object:
|
||||
|
||||
{
|
||||
buffer: Uint8Array (db file contents),
|
||||
filename: the current db filename,
|
||||
mimetype: 'application/x-sqlite3'
|
||||
}
|
||||
|
||||
TODO is to determine how/whether this feature can support
|
||||
exports of ":memory:" and "" (temp file) DBs. The latter is
|
||||
ostensibly easy because the file is (potentially) on disk, but
|
||||
the former does not have a structure which maps directly to a
|
||||
db file image.
|
||||
*/
|
||||
export: function(ev){
|
||||
toss("export() requires reimplementing for portability reasons.");
|
||||
/**const db = getMsgDb(ev);
|
||||
const response = {
|
||||
buffer: db.exportBinaryImage(),
|
||||
filename: db.filename,
|
||||
mimetype: 'application/x-sqlite3'
|
||||
};
|
||||
this.xfer.push(response.buffer.buffer);
|
||||
return response;**/
|
||||
}/*export()*/,
|
||||
/**
|
||||
Proxy for the DB constructor. Expects to be passed a single
|
||||
object or a falsy value to use defaults. The object may
|
||||
have a filename property to name the db file (see the DB
|
||||
constructor for peculiarities and transformations) and/or a
|
||||
buffer property (a Uint8Array holding a complete database
|
||||
file's contents). The response is an object:
|
||||
|
||||
{
|
||||
filename: db filename (possibly differing from the input),
|
||||
|
||||
id: an opaque ID value intended for future distinction
|
||||
between multiple db handles. Messages including a specific
|
||||
ID will use the DB for that ID.
|
||||
|
||||
}
|
||||
|
||||
If the Worker's db is currently opened, this call closes it
|
||||
before proceeding.
|
||||
*/
|
||||
open: function(ev){
|
||||
wState.close(/*true???*/);
|
||||
const args = [], data = (ev.data || {});
|
||||
if(data.simulateError){
|
||||
toss("Throwing because of open.simulateError flag.");
|
||||
}
|
||||
if(data.filename) args.push(data.filename);
|
||||
if(data.buffer){
|
||||
args.push(data.buffer);
|
||||
this.xfer.push(data.buffer.buffer);
|
||||
}
|
||||
const db = wState.open(args);
|
||||
return {
|
||||
filename: db.filename,
|
||||
dbId: getDbId(db)
|
||||
};
|
||||
},
|
||||
/**
|
||||
Proxy for DB.close(). If ev.data may either be a boolean or
|
||||
an object with an `unlink` property. If that value is
|
||||
truthy then the db file (if the db is currently open) will
|
||||
be unlinked from the virtual filesystem, else it will be
|
||||
kept intact. The response object is:
|
||||
|
||||
{
|
||||
filename: db filename _if_ the db is opened when this
|
||||
is called, else the undefined value
|
||||
}
|
||||
*/
|
||||
close: function(ev){
|
||||
const db = getMsgDb(ev,false);
|
||||
const response = {
|
||||
filename: db && db.filename
|
||||
};
|
||||
if(db){
|
||||
wState.close(db, !!((ev.data && 'object'===typeof ev.data)
|
||||
? ev.data.unlink : ev.data));
|
||||
}
|
||||
return response;
|
||||
},
|
||||
toss: function(ev){
|
||||
toss("Testing worker exception");
|
||||
}
|
||||
}/*wMsgHandler*/;
|
||||
|
||||
/**
|
||||
UNDER CONSTRUCTION!
|
||||
|
||||
A subset of the DB API is accessible via Worker messages in the
|
||||
form:
|
||||
|
||||
{ type: apiCommand,
|
||||
dbId: optional DB ID value (else uses a default db handle)
|
||||
data: apiArguments
|
||||
}
|
||||
|
||||
As a rule, these commands respond with a postMessage() of their
|
||||
own in the same form, but will, if needed, transform the `data`
|
||||
member to an object and may add state to it. The responses
|
||||
always have an object-format `data` part. If the inbound `data`
|
||||
is an object which has a `messageId` property, that property is
|
||||
always mirrored in the result object, for use in client-side
|
||||
dispatching of these asynchronous results. Exceptions thrown
|
||||
during processing result in an `error`-type event with a
|
||||
payload in the form:
|
||||
|
||||
{
|
||||
message: error string,
|
||||
errorClass: class name of the error type,
|
||||
dbId: DB handle ID,
|
||||
input: ev.data,
|
||||
[messageId: if set in the inbound message]
|
||||
}
|
||||
|
||||
The individual APIs are documented in the wMsgHandler object.
|
||||
*/
|
||||
self.onmessage = function(ev){
|
||||
ev = ev.data;
|
||||
let response, dbId = ev.dbId, evType = ev.type;
|
||||
const arrivalTime = performance.now();
|
||||
try {
|
||||
if(wMsgHandler.hasOwnProperty(evType) &&
|
||||
wMsgHandler[evType] instanceof Function){
|
||||
response = wMsgHandler[evType](ev);
|
||||
}else{
|
||||
toss("Unknown db worker message type:",ev.type);
|
||||
}
|
||||
}catch(err){
|
||||
evType = 'error';
|
||||
response = {
|
||||
message: err.message,
|
||||
errorClass: err.name,
|
||||
input: ev
|
||||
};
|
||||
if(err.stack){
|
||||
response.stack = ('string'===typeof err.stack)
|
||||
? err.stack.split('\n') : err.stack;
|
||||
}
|
||||
if(0) console.warn("Worker is propagating an exception to main thread.",
|
||||
"Reporting it _here_ for the stack trace:",err,response);
|
||||
}
|
||||
if(!response.messageId && ev.data
|
||||
&& 'object'===typeof ev.data && ev.data.messageId){
|
||||
response.messageId = ev.data.messageId;
|
||||
}
|
||||
if(!dbId){
|
||||
dbId = response.dbId/*from 'open' cmd*/
|
||||
|| getDefaultDbId();
|
||||
}
|
||||
if(!response.dbId) response.dbId = dbId;
|
||||
// Timing info is primarily for use in testing this API. It's not part of
|
||||
// the public API. arrivalTime = when the worker got the message.
|
||||
response.workerReceivedTime = arrivalTime;
|
||||
response.workerRespondTime = performance.now();
|
||||
response.departureTime = ev.departureTime;
|
||||
wState.post(evType, response, wMsgHandler.xfer);
|
||||
};
|
||||
setTimeout(()=>self.postMessage({type:'sqlite3-api',data:'worker-ready'}), 0);
|
||||
}.bind({self, sqlite3: self.sqlite3});
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
Dummy function stubs to get sqlite3.c compiling with
|
||||
wasi-sdk. This requires, in addition:
|
||||
|
||||
-D_WASI_EMULATED_MMAN -D_WASI_EMULATED_GETPID
|
||||
|
||||
-lwasi-emulated-getpid
|
||||
*/
|
||||
typedef unsigned mode_t;
|
||||
int fchmod(int fd, mode_t mode);
|
||||
int fchmod(int fd, mode_t mode){
|
||||
return (fd && mode) ? 0 : 0;
|
||||
}
|
||||
typedef unsigned uid_t;
|
||||
typedef uid_t gid_t;
|
||||
int fchown(int fd, uid_t owner, gid_t group);
|
||||
int fchown(int fd, uid_t owner, gid_t group){
|
||||
return (fd && owner && group) ? 0 : 0;
|
||||
}
|
||||
uid_t geteuid(void);
|
||||
uid_t geteuid(void){return 0;}
|
||||
#if !defined(F_WRLCK)
|
||||
enum {
|
||||
F_WRLCK,
|
||||
F_RDLCK,
|
||||
F_GETLK,
|
||||
F_SETLK,
|
||||
F_UNLCK
|
||||
};
|
||||
#endif
|
||||
|
||||
#undef HAVE_PREAD
|
||||
|
||||
#include <wasi/api.h>
|
||||
#define WASM__KEEP __attribute__((used))
|
||||
|
||||
#if 0
|
||||
/**
|
||||
wasi-sdk cannot build sqlite3's default VFS without at least the following
|
||||
functions. They are apparently syscalls which clients have to implement or
|
||||
otherwise obtain.
|
||||
|
||||
https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
||||
*/
|
||||
environ_get
|
||||
environ_sizes_get
|
||||
clock_time_get
|
||||
fd_close
|
||||
fd_fdstat_get
|
||||
fd_fdstat_set_flags
|
||||
fd_filestat_get
|
||||
fd_filestat_set_size
|
||||
fd_pread
|
||||
fd_prestat_get
|
||||
fd_prestat_dir_name
|
||||
fd_read
|
||||
fd_seek
|
||||
fd_sync
|
||||
fd_write
|
||||
path_create_directory
|
||||
path_filestat_get
|
||||
path_filestat_set_times
|
||||
path_open
|
||||
path_readlink
|
||||
path_remove_directory
|
||||
path_unlink_file
|
||||
poll_oneoff
|
||||
proc_exit
|
||||
#endif
|
||||
@@ -0,0 +1,413 @@
|
||||
#include "sqlite3.c"
|
||||
|
||||
/*
|
||||
** This function is NOT part of the sqlite3 public API. It is strictly
|
||||
** for use by the sqlite project's own JS/WASM bindings.
|
||||
**
|
||||
** For purposes of certain hand-crafted C/Wasm function bindings, we
|
||||
** need a way of reporting errors which is consistent with the rest of
|
||||
** the C API, as opposed to throwing JS exceptions. To that end, this
|
||||
** internal-use-only function is a thin proxy around
|
||||
** sqlite3ErrorWithMessage(). The intent is that it only be used from
|
||||
** Wasm bindings such as sqlite3_prepare_v2/v3(), and definitely not
|
||||
** from client code.
|
||||
**
|
||||
** Returns err_code.
|
||||
*/
|
||||
int sqlite3_wasm_db_error(sqlite3*db, int err_code,
|
||||
const char *zMsg){
|
||||
if(0!=zMsg){
|
||||
const int nMsg = sqlite3Strlen30(zMsg);
|
||||
sqlite3ErrorWithMsg(db, err_code, "%.*s", nMsg, zMsg);
|
||||
}else{
|
||||
sqlite3ErrorWithMsg(db, err_code, NULL);
|
||||
}
|
||||
return err_code;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is NOT part of the sqlite3 public API. It is strictly
|
||||
** for use by the sqlite project's own JS/WASM bindings. Unlike the
|
||||
** rest of the sqlite3 API, this part requires C99 for snprintf() and
|
||||
** variadic macros.
|
||||
**
|
||||
** Returns a string containing a JSON-format "enum" of C-level
|
||||
** constants intended to be imported into the JS environment. The JSON
|
||||
** is initialized the first time this function is called and that
|
||||
** result is reused for all future calls.
|
||||
**
|
||||
** If this function returns NULL then it means that the internal
|
||||
** buffer is not large enough for the generated JSON. In debug builds
|
||||
** that will trigger an assert().
|
||||
*/
|
||||
const char * sqlite3_wasm_enum_json(void){
|
||||
static char strBuf[1024 * 8] = {0} /* where the JSON goes */;
|
||||
int n = 0, childCount = 0, structCount = 0
|
||||
/* output counters for figuring out where commas go */;
|
||||
char * pos = &strBuf[1] /* skip first byte for now to help protect
|
||||
** against a small race condition */;
|
||||
char const * const zEnd = pos + sizeof(strBuf) /* one-past-the-end */;
|
||||
if(strBuf[0]) return strBuf;
|
||||
/* Leave strBuf[0] at 0 until the end to help guard against a tiny
|
||||
** race condition. If this is called twice concurrently, they might
|
||||
** end up both writing to strBuf, but they'll both write the same
|
||||
** thing, so that's okay. If we set byte 0 up front then the 2nd
|
||||
** instance might return and use the string before the 1st instance
|
||||
** is done filling it. */
|
||||
|
||||
/* Core output macros... */
|
||||
#define lenCheck assert(pos < zEnd - 128 \
|
||||
&& "sqlite3_wasm_enum_json() buffer is too small."); \
|
||||
if(pos >= zEnd - 128) return 0
|
||||
#define outf(format,...) \
|
||||
pos += snprintf(pos, ((size_t)(zEnd - pos)), format, __VA_ARGS__); \
|
||||
lenCheck
|
||||
#define out(TXT) outf("%s",TXT)
|
||||
#define CloseBrace(LEVEL) \
|
||||
assert(LEVEL<5); memset(pos, '}', LEVEL); pos+=LEVEL; lenCheck
|
||||
|
||||
/* Macros for emitting maps of integer- and string-type macros to
|
||||
** their values. */
|
||||
#define DefGroup(KEY) n = 0; \
|
||||
outf("%s\"" #KEY "\": {",(childCount++ ? "," : ""));
|
||||
#define DefInt(KEY) \
|
||||
outf("%s\"%s\": %d", (n++ ? ", " : ""), #KEY, (int)KEY)
|
||||
#define DefStr(KEY) \
|
||||
outf("%s\"%s\": \"%s\"", (n++ ? ", " : ""), #KEY, KEY)
|
||||
#define _DefGroup CloseBrace(1)
|
||||
|
||||
DefGroup(version) {
|
||||
DefInt(SQLITE_VERSION_NUMBER);
|
||||
DefStr(SQLITE_VERSION);
|
||||
DefStr(SQLITE_SOURCE_ID);
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(resultCodes) {
|
||||
DefInt(SQLITE_OK);
|
||||
DefInt(SQLITE_ERROR);
|
||||
DefInt(SQLITE_INTERNAL);
|
||||
DefInt(SQLITE_PERM);
|
||||
DefInt(SQLITE_ABORT);
|
||||
DefInt(SQLITE_BUSY);
|
||||
DefInt(SQLITE_LOCKED);
|
||||
DefInt(SQLITE_NOMEM);
|
||||
DefInt(SQLITE_READONLY);
|
||||
DefInt(SQLITE_INTERRUPT);
|
||||
DefInt(SQLITE_IOERR);
|
||||
DefInt(SQLITE_CORRUPT);
|
||||
DefInt(SQLITE_NOTFOUND);
|
||||
DefInt(SQLITE_FULL);
|
||||
DefInt(SQLITE_CANTOPEN);
|
||||
DefInt(SQLITE_PROTOCOL);
|
||||
DefInt(SQLITE_EMPTY);
|
||||
DefInt(SQLITE_SCHEMA);
|
||||
DefInt(SQLITE_TOOBIG);
|
||||
DefInt(SQLITE_CONSTRAINT);
|
||||
DefInt(SQLITE_MISMATCH);
|
||||
DefInt(SQLITE_MISUSE);
|
||||
DefInt(SQLITE_NOLFS);
|
||||
DefInt(SQLITE_AUTH);
|
||||
DefInt(SQLITE_FORMAT);
|
||||
DefInt(SQLITE_RANGE);
|
||||
DefInt(SQLITE_NOTADB);
|
||||
DefInt(SQLITE_NOTICE);
|
||||
DefInt(SQLITE_WARNING);
|
||||
DefInt(SQLITE_ROW);
|
||||
DefInt(SQLITE_DONE);
|
||||
|
||||
// Extended Result Codes
|
||||
DefInt(SQLITE_ERROR_MISSING_COLLSEQ);
|
||||
DefInt(SQLITE_ERROR_RETRY);
|
||||
DefInt(SQLITE_ERROR_SNAPSHOT);
|
||||
DefInt(SQLITE_IOERR_READ);
|
||||
DefInt(SQLITE_IOERR_SHORT_READ);
|
||||
DefInt(SQLITE_IOERR_WRITE);
|
||||
DefInt(SQLITE_IOERR_FSYNC);
|
||||
DefInt(SQLITE_IOERR_DIR_FSYNC);
|
||||
DefInt(SQLITE_IOERR_TRUNCATE);
|
||||
DefInt(SQLITE_IOERR_FSTAT);
|
||||
DefInt(SQLITE_IOERR_UNLOCK);
|
||||
DefInt(SQLITE_IOERR_RDLOCK);
|
||||
DefInt(SQLITE_IOERR_DELETE);
|
||||
DefInt(SQLITE_IOERR_BLOCKED);
|
||||
DefInt(SQLITE_IOERR_NOMEM);
|
||||
DefInt(SQLITE_IOERR_ACCESS);
|
||||
DefInt(SQLITE_IOERR_CHECKRESERVEDLOCK);
|
||||
DefInt(SQLITE_IOERR_LOCK);
|
||||
DefInt(SQLITE_IOERR_CLOSE);
|
||||
DefInt(SQLITE_IOERR_DIR_CLOSE);
|
||||
DefInt(SQLITE_IOERR_SHMOPEN);
|
||||
DefInt(SQLITE_IOERR_SHMSIZE);
|
||||
DefInt(SQLITE_IOERR_SHMLOCK);
|
||||
DefInt(SQLITE_IOERR_SHMMAP);
|
||||
DefInt(SQLITE_IOERR_SEEK);
|
||||
DefInt(SQLITE_IOERR_DELETE_NOENT);
|
||||
DefInt(SQLITE_IOERR_MMAP);
|
||||
DefInt(SQLITE_IOERR_GETTEMPPATH);
|
||||
DefInt(SQLITE_IOERR_CONVPATH);
|
||||
DefInt(SQLITE_IOERR_VNODE);
|
||||
DefInt(SQLITE_IOERR_AUTH);
|
||||
DefInt(SQLITE_IOERR_BEGIN_ATOMIC);
|
||||
DefInt(SQLITE_IOERR_COMMIT_ATOMIC);
|
||||
DefInt(SQLITE_IOERR_ROLLBACK_ATOMIC);
|
||||
DefInt(SQLITE_IOERR_DATA);
|
||||
DefInt(SQLITE_IOERR_CORRUPTFS);
|
||||
DefInt(SQLITE_LOCKED_SHAREDCACHE);
|
||||
DefInt(SQLITE_LOCKED_VTAB);
|
||||
DefInt(SQLITE_BUSY_RECOVERY);
|
||||
DefInt(SQLITE_BUSY_SNAPSHOT);
|
||||
DefInt(SQLITE_BUSY_TIMEOUT);
|
||||
DefInt(SQLITE_CANTOPEN_NOTEMPDIR);
|
||||
DefInt(SQLITE_CANTOPEN_ISDIR);
|
||||
DefInt(SQLITE_CANTOPEN_FULLPATH);
|
||||
DefInt(SQLITE_CANTOPEN_CONVPATH);
|
||||
//DefInt(SQLITE_CANTOPEN_DIRTYWAL)/*docs say not used*/;
|
||||
DefInt(SQLITE_CANTOPEN_SYMLINK);
|
||||
DefInt(SQLITE_CORRUPT_VTAB);
|
||||
DefInt(SQLITE_CORRUPT_SEQUENCE);
|
||||
DefInt(SQLITE_CORRUPT_INDEX);
|
||||
DefInt(SQLITE_READONLY_RECOVERY);
|
||||
DefInt(SQLITE_READONLY_CANTLOCK);
|
||||
DefInt(SQLITE_READONLY_ROLLBACK);
|
||||
DefInt(SQLITE_READONLY_DBMOVED);
|
||||
DefInt(SQLITE_READONLY_CANTINIT);
|
||||
DefInt(SQLITE_READONLY_DIRECTORY);
|
||||
DefInt(SQLITE_ABORT_ROLLBACK);
|
||||
DefInt(SQLITE_CONSTRAINT_CHECK);
|
||||
DefInt(SQLITE_CONSTRAINT_COMMITHOOK);
|
||||
DefInt(SQLITE_CONSTRAINT_FOREIGNKEY);
|
||||
DefInt(SQLITE_CONSTRAINT_FUNCTION);
|
||||
DefInt(SQLITE_CONSTRAINT_NOTNULL);
|
||||
DefInt(SQLITE_CONSTRAINT_PRIMARYKEY);
|
||||
DefInt(SQLITE_CONSTRAINT_TRIGGER);
|
||||
DefInt(SQLITE_CONSTRAINT_UNIQUE);
|
||||
DefInt(SQLITE_CONSTRAINT_VTAB);
|
||||
DefInt(SQLITE_CONSTRAINT_ROWID);
|
||||
DefInt(SQLITE_CONSTRAINT_PINNED);
|
||||
DefInt(SQLITE_CONSTRAINT_DATATYPE);
|
||||
DefInt(SQLITE_NOTICE_RECOVER_WAL);
|
||||
DefInt(SQLITE_NOTICE_RECOVER_ROLLBACK);
|
||||
DefInt(SQLITE_WARNING_AUTOINDEX);
|
||||
DefInt(SQLITE_AUTH_USER);
|
||||
DefInt(SQLITE_OK_LOAD_PERMANENTLY);
|
||||
//DefInt(SQLITE_OK_SYMLINK) /* internal use only */;
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(dataTypes) {
|
||||
DefInt(SQLITE_INTEGER);
|
||||
DefInt(SQLITE_FLOAT);
|
||||
DefInt(SQLITE_TEXT);
|
||||
DefInt(SQLITE_BLOB);
|
||||
DefInt(SQLITE_NULL);
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(encodings) {
|
||||
/* Noting that the wasm binding only aims to support UTF-8. */
|
||||
DefInt(SQLITE_UTF8);
|
||||
DefInt(SQLITE_UTF16LE);
|
||||
DefInt(SQLITE_UTF16BE);
|
||||
DefInt(SQLITE_UTF16);
|
||||
/*deprecated DefInt(SQLITE_ANY); */
|
||||
DefInt(SQLITE_UTF16_ALIGNED);
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(blobFinalizers) {
|
||||
/* SQLITE_STATIC/TRANSIENT need to be handled explicitly as
|
||||
** integers to avoid casting-related warnings. */
|
||||
out("\"SQLITE_STATIC\":0, \"SQLITE_TRANSIENT\":-1");
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(udfFlags) {
|
||||
DefInt(SQLITE_DETERMINISTIC);
|
||||
DefInt(SQLITE_DIRECTONLY);
|
||||
DefInt(SQLITE_INNOCUOUS);
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(openFlags) {
|
||||
/* Noting that not all of these will have any effect in WASM-space. */
|
||||
DefInt(SQLITE_OPEN_READONLY);
|
||||
DefInt(SQLITE_OPEN_READWRITE);
|
||||
DefInt(SQLITE_OPEN_CREATE);
|
||||
DefInt(SQLITE_OPEN_URI);
|
||||
DefInt(SQLITE_OPEN_MEMORY);
|
||||
DefInt(SQLITE_OPEN_NOMUTEX);
|
||||
DefInt(SQLITE_OPEN_FULLMUTEX);
|
||||
DefInt(SQLITE_OPEN_SHAREDCACHE);
|
||||
DefInt(SQLITE_OPEN_PRIVATECACHE);
|
||||
DefInt(SQLITE_OPEN_EXRESCODE);
|
||||
DefInt(SQLITE_OPEN_NOFOLLOW);
|
||||
/* OPEN flags for use with VFSes... */
|
||||
DefInt(SQLITE_OPEN_MAIN_DB);
|
||||
DefInt(SQLITE_OPEN_MAIN_JOURNAL);
|
||||
DefInt(SQLITE_OPEN_TEMP_DB);
|
||||
DefInt(SQLITE_OPEN_TEMP_JOURNAL);
|
||||
DefInt(SQLITE_OPEN_TRANSIENT_DB);
|
||||
DefInt(SQLITE_OPEN_SUBJOURNAL);
|
||||
DefInt(SQLITE_OPEN_SUPER_JOURNAL);
|
||||
DefInt(SQLITE_OPEN_WAL);
|
||||
DefInt(SQLITE_OPEN_DELETEONCLOSE);
|
||||
DefInt(SQLITE_OPEN_EXCLUSIVE);
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(syncFlags) {
|
||||
DefInt(SQLITE_SYNC_NORMAL);
|
||||
DefInt(SQLITE_SYNC_FULL);
|
||||
DefInt(SQLITE_SYNC_DATAONLY);
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(prepareFlags) {
|
||||
DefInt(SQLITE_PREPARE_PERSISTENT);
|
||||
DefInt(SQLITE_PREPARE_NORMALIZE);
|
||||
DefInt(SQLITE_PREPARE_NO_VTAB);
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(flock) {
|
||||
DefInt(SQLITE_LOCK_NONE);
|
||||
DefInt(SQLITE_LOCK_SHARED);
|
||||
DefInt(SQLITE_LOCK_RESERVED);
|
||||
DefInt(SQLITE_LOCK_PENDING);
|
||||
DefInt(SQLITE_LOCK_EXCLUSIVE);
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(ioCap) {
|
||||
DefInt(SQLITE_IOCAP_ATOMIC);
|
||||
DefInt(SQLITE_IOCAP_ATOMIC512);
|
||||
DefInt(SQLITE_IOCAP_ATOMIC1K);
|
||||
DefInt(SQLITE_IOCAP_ATOMIC2K);
|
||||
DefInt(SQLITE_IOCAP_ATOMIC4K);
|
||||
DefInt(SQLITE_IOCAP_ATOMIC8K);
|
||||
DefInt(SQLITE_IOCAP_ATOMIC16K);
|
||||
DefInt(SQLITE_IOCAP_ATOMIC32K);
|
||||
DefInt(SQLITE_IOCAP_ATOMIC64K);
|
||||
DefInt(SQLITE_IOCAP_SAFE_APPEND);
|
||||
DefInt(SQLITE_IOCAP_SEQUENTIAL);
|
||||
DefInt(SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN);
|
||||
DefInt(SQLITE_IOCAP_POWERSAFE_OVERWRITE);
|
||||
DefInt(SQLITE_IOCAP_IMMUTABLE);
|
||||
DefInt(SQLITE_IOCAP_BATCH_ATOMIC);
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(access){
|
||||
DefInt(SQLITE_ACCESS_EXISTS);
|
||||
DefInt(SQLITE_ACCESS_READWRITE);
|
||||
DefInt(SQLITE_ACCESS_READ)/*docs say this is unused*/;
|
||||
} _DefGroup;
|
||||
|
||||
#undef DefGroup
|
||||
#undef DefStr
|
||||
#undef DefInt
|
||||
#undef _DefGroup
|
||||
|
||||
/*
|
||||
** Emit an array of "StructBinder" struct descripions, which look
|
||||
** like:
|
||||
**
|
||||
** {
|
||||
** "name": "MyStruct",
|
||||
** "sizeof": 16,
|
||||
** "members": {
|
||||
** "member1": {"offset": 0,"sizeof": 4,"signature": "i"},
|
||||
** "member2": {"offset": 4,"sizeof": 4,"signature": "p"},
|
||||
** "member3": {"offset": 8,"sizeof": 8,"signature": "j"}
|
||||
** }
|
||||
** }
|
||||
**
|
||||
** Detailed documentation for those bits are in the docs for the
|
||||
** Jaccwabyt JS-side component.
|
||||
*/
|
||||
|
||||
/** Macros for emitting StructBinder description. */
|
||||
#define StructBinder__(TYPE) \
|
||||
n = 0; \
|
||||
outf("%s{", (structCount++ ? ", " : "")); \
|
||||
out("\"name\": \"" # TYPE "\","); \
|
||||
outf("\"sizeof\": %d", (int)sizeof(TYPE)); \
|
||||
out(",\"members\": {");
|
||||
#define StructBinder_(T) StructBinder__(T)
|
||||
/** ^^^ indirection needed to expand CurrentStruct */
|
||||
#define StructBinder StructBinder_(CurrentStruct)
|
||||
#define _StructBinder CloseBrace(2)
|
||||
#define M(MEMBER,SIG) \
|
||||
outf("%s\"%s\": " \
|
||||
"{\"offset\":%d,\"sizeof\": %d,\"signature\":\"%s\"}", \
|
||||
(n++ ? ", " : ""), #MEMBER, \
|
||||
(int)offsetof(CurrentStruct,MEMBER), \
|
||||
(int)sizeof(((CurrentStruct*)0)->MEMBER), \
|
||||
SIG)
|
||||
|
||||
structCount = 0;
|
||||
out(", \"structs\": ["); {
|
||||
|
||||
#define CurrentStruct sqlite3_vfs
|
||||
StructBinder {
|
||||
M(iVersion,"i");
|
||||
M(szOsFile,"i");
|
||||
M(mxPathname,"i");
|
||||
M(pNext,"p");
|
||||
M(zName,"s");
|
||||
M(pAppData,"p");
|
||||
M(xOpen,"i(pppip)");
|
||||
M(xDelete,"i(ppi)");
|
||||
M(xAccess,"i(ppip)");
|
||||
M(xFullPathname,"i(ppip)");
|
||||
M(xDlOpen,"p(pp)");
|
||||
M(xDlError,"p(pip)");
|
||||
M(xDlSym,"p()");
|
||||
M(xDlClose,"v(pp)");
|
||||
M(xRandomness,"i(pip)");
|
||||
M(xSleep,"i(pi)");
|
||||
M(xCurrentTime,"i(pp)");
|
||||
M(xGetLastError,"i(pip)");
|
||||
M(xCurrentTimeInt64,"i(pp)");
|
||||
M(xSetSystemCall,"i(ppp)");
|
||||
M(xGetSystemCall,"p(pp)");
|
||||
M(xNextSystemCall,"p(pp)");
|
||||
} _StructBinder;
|
||||
#undef CurrentStruct
|
||||
|
||||
#define CurrentStruct sqlite3_io_methods
|
||||
StructBinder {
|
||||
M(iVersion,"i");
|
||||
M(xClose,"i(p)");
|
||||
M(xRead,"i(ppij)");
|
||||
M(xWrite,"i(ppij)");
|
||||
M(xTruncate,"i(pj)");
|
||||
M(xSync,"i(pi)");
|
||||
M(xFileSize,"i(pp)");
|
||||
M(xLock,"i(pi)");
|
||||
M(xUnlock,"i(pi)");
|
||||
M(xCheckReservedLock,"i(pp)");
|
||||
M(xFileControl,"i(pip)");
|
||||
M(xSectorSize,"i(p)");
|
||||
M(xDeviceCharacteristics,"i(p)");
|
||||
M(xShmMap,"i(piiip)");
|
||||
M(xShmLock,"i(piii)");
|
||||
M(xShmBarrier,"v(p)");
|
||||
M(xShmUnmap,"i(pi)");
|
||||
M(xFetch,"i(pjip)");
|
||||
M(xUnfetch,"i(pjp)");
|
||||
} _StructBinder;
|
||||
#undef CurrentStruct
|
||||
|
||||
#define CurrentStruct sqlite3_file
|
||||
StructBinder {
|
||||
M(pMethods,"P");
|
||||
} _StructBinder;
|
||||
#undef CurrentStruct
|
||||
|
||||
} out( "]"/*structs*/);
|
||||
|
||||
out("}"/*top-level object*/);
|
||||
*pos = 0;
|
||||
strBuf[0] = '{'/*end of the race-condition workaround*/;
|
||||
return strBuf;
|
||||
#undef StructBinder
|
||||
#undef StructBinder_
|
||||
#undef StructBinder__
|
||||
#undef M
|
||||
#undef _StructBinder
|
||||
#undef CloseBrace
|
||||
#undef out
|
||||
#undef outf
|
||||
#undef lenCheck
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
2022-05-23
|
||||
|
||||
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 is a JS Worker file for the main sqlite3 api. It loads
|
||||
sqlite3.js, initializes the module, and postMessage()'s a message
|
||||
after the module is initialized:
|
||||
|
||||
{type: 'sqlite3-api', data: 'worker-ready'}
|
||||
|
||||
This seemingly superfluous level of indirection is necessary when
|
||||
loading sqlite3.js via a Worker. Instantiating a worker with new
|
||||
Worker("sqlite.js") will not (cannot) call sqlite3InitModule() to
|
||||
initialize the module due to a timing/order-of-operations conflict
|
||||
(and that symbol is not exported in a way that a Worker loading it
|
||||
that way can see it). Thus JS code wanting to load the sqlite3
|
||||
Worker-specific API needs to pass _this_ file (or equivalent) to the
|
||||
Worker constructor and then listen for an event in the form shown
|
||||
above in order to know when the module has completed initialization.
|
||||
*/
|
||||
"use strict";
|
||||
importScripts('sqlite3.js');
|
||||
sqlite3InitModule().then((EmscriptenModule)=>EmscriptenModule.sqlite3.initWorkerAPI());
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
2022-05-22
|
||||
|
||||
The author disclaims copyright to this source code. In place of a
|
||||
legal notice, here is a blessing:
|
||||
|
||||
* May you do good and not evil.
|
||||
* May you find forgiveness for yourself and forgive others.
|
||||
* May you share freely, never taking more than you give.
|
||||
|
||||
***********************************************************************
|
||||
|
||||
This file contains bootstrapping code used by various test scripts
|
||||
which live in this file's directory.
|
||||
*/
|
||||
'use strict';
|
||||
(function(self){
|
||||
/* querySelectorAll() proxy */
|
||||
const EAll = function(/*[element=document,] cssSelector*/){
|
||||
return (arguments.length>1 ? arguments[0] : document)
|
||||
.querySelectorAll(arguments[arguments.length-1]);
|
||||
};
|
||||
/* querySelector() proxy */
|
||||
const E = function(/*[element=document,] cssSelector*/){
|
||||
return (arguments.length>1 ? arguments[0] : document)
|
||||
.querySelector(arguments[arguments.length-1]);
|
||||
};
|
||||
|
||||
/**
|
||||
Helpers for writing sqlite3-specific tests.
|
||||
*/
|
||||
self.SqliteTestUtil = {
|
||||
/** Running total of the number of tests run via
|
||||
this API. */
|
||||
counter: 0,
|
||||
/**
|
||||
If expr is a function, it is called and its result
|
||||
is returned, coerced to a bool, else expr, coerced to
|
||||
a bool, is returned.
|
||||
*/
|
||||
toBool: function(expr){
|
||||
return (expr instanceof Function) ? !!expr() : !!expr;
|
||||
},
|
||||
/** abort() if expr is false. If expr is a function, it
|
||||
is called and its result is evaluated.
|
||||
*/
|
||||
assert: function f(expr, msg){
|
||||
if(!f._){
|
||||
f._ = ('undefined'===typeof abort
|
||||
? (msg)=>{throw new Error(msg)}
|
||||
: abort);
|
||||
}
|
||||
++this.counter;
|
||||
if(!this.toBool(expr)){
|
||||
f._(msg || "Assertion failed.");
|
||||
}
|
||||
return this;
|
||||
},
|
||||
/** Identical to assert() but throws instead of calling
|
||||
abort(). */
|
||||
affirm: function(expr, msg){
|
||||
++this.counter;
|
||||
if(!this.toBool(expr)) throw new Error(msg || "Affirmation failed.");
|
||||
return this;
|
||||
},
|
||||
/** Calls f() and squelches any exception it throws. If it
|
||||
does not throw, this function throws. */
|
||||
mustThrow: function(f, msg){
|
||||
++this.counter;
|
||||
let err;
|
||||
try{ f(); } catch(e){err=e;}
|
||||
if(!err) throw new Error(msg || "Expected exception.");
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
Works like mustThrow() but expects filter to be a regex,
|
||||
function, or string to match/filter the resulting exception
|
||||
against. If f() does not throw, this test fails and an Error is
|
||||
thrown. If filter is a regex, the test passes if
|
||||
filter.test(error.message) passes. If it's a function, the test
|
||||
passes if filter(error) returns truthy. If it's a string, the
|
||||
test passes if the filter matches the exception message
|
||||
precisely. In all other cases the test fails, throwing an
|
||||
Error.
|
||||
|
||||
If it throws, msg is used as the error report unless it's falsy,
|
||||
in which case a default is used.
|
||||
*/
|
||||
mustThrowMatching: function(f, filter, msg){
|
||||
++this.counter;
|
||||
let err;
|
||||
try{ f(); } catch(e){err=e;}
|
||||
if(!err) throw new Error(msg || "Expected exception.");
|
||||
let pass = false;
|
||||
if(filter instanceof RegExp) pass = filter.test(err.message);
|
||||
else if(filter instanceof Function) pass = filter(err);
|
||||
else if('string' === typeof filter) pass = (err.message === filter);
|
||||
if(!pass){
|
||||
throw new Error(msg || ("Filter rejected this exception: "+err.message));
|
||||
}
|
||||
return this;
|
||||
},
|
||||
/** Throws if expr is truthy or expr is a function and expr()
|
||||
returns truthy. */
|
||||
throwIf: function(expr, msg){
|
||||
++this.counter;
|
||||
if(this.toBool(expr)) throw new Error(msg || "throwIf() failed");
|
||||
return this;
|
||||
},
|
||||
/** Throws if expr is falsy or expr is a function and expr()
|
||||
returns falsy. */
|
||||
throwUnless: function(expr, msg){
|
||||
++this.counter;
|
||||
if(!this.toBool(expr)) throw new Error(msg || "throwUnless() failed");
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
This is a module object for use with the emscripten-installed
|
||||
sqlite3InitModule() factory function.
|
||||
*/
|
||||
self.sqlite3TestModule = {
|
||||
postRun: [
|
||||
/* function(theModule){...} */
|
||||
],
|
||||
//onRuntimeInitialized: function(){},
|
||||
/* Proxy for C-side stdout output. */
|
||||
print: function(){
|
||||
console.log.apply(console, Array.prototype.slice.call(arguments));
|
||||
},
|
||||
/* Proxy for C-side stderr output. */
|
||||
printErr: function(){
|
||||
console.error.apply(console, Array.prototype.slice.call(arguments));
|
||||
},
|
||||
/**
|
||||
Called by the module init bits to report loading
|
||||
progress. It gets passed an empty argument when loading is
|
||||
done (after onRuntimeInitialized() and any this.postRun
|
||||
callbacks have been run).
|
||||
*/
|
||||
setStatus: function f(text){
|
||||
if(!f.last){
|
||||
f.last = { text: '', step: 0 };
|
||||
f.ui = {
|
||||
status: E('#module-status'),
|
||||
progress: E('#module-progress'),
|
||||
spinner: E('#module-spinner')
|
||||
};
|
||||
}
|
||||
if(text === f.last.text) return;
|
||||
f.last.text = text;
|
||||
if(f.ui.progress){
|
||||
f.ui.progress.value = f.last.step;
|
||||
f.ui.progress.max = f.last.step + 1;
|
||||
}
|
||||
++f.last.step;
|
||||
if(text) {
|
||||
f.ui.status.classList.remove('hidden');
|
||||
f.ui.status.innerText = text;
|
||||
}else{
|
||||
if(f.ui.progress){
|
||||
f.ui.progress.remove();
|
||||
f.ui.spinner.remove();
|
||||
delete f.ui.progress;
|
||||
delete f.ui.spinner;
|
||||
}
|
||||
f.ui.status.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
};
|
||||
})(self/*window or worker*/);
|
||||
@@ -0,0 +1,24 @@
|
||||
/* emcscript-related styling, used during the module load/intialization processes... */
|
||||
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
|
||||
div.emscripten { text-align: center; }
|
||||
div.emscripten_border { border: 1px solid black; }
|
||||
#module-spinner { overflow: visible; }
|
||||
#module-spinner > * {
|
||||
margin-top: 1em;
|
||||
}
|
||||
.spinner {
|
||||
height: 50px;
|
||||
width: 50px;
|
||||
margin: 0px auto;
|
||||
animation: rotation 0.8s linear infinite;
|
||||
border-left: 10px solid rgb(0,150,240);
|
||||
border-right: 10px solid rgb(0,150,240);
|
||||
border-bottom: 10px solid rgb(0,150,240);
|
||||
border-top: 10px solid rgb(100,0,200);
|
||||
border-radius: 100%;
|
||||
background-color: rgb(200,100,250);
|
||||
}
|
||||
@keyframes rotation {
|
||||
from {transform: rotate(0deg);}
|
||||
to {transform: rotate(360deg);}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
textarea {
|
||||
font-family: monospace;
|
||||
}
|
||||
header {
|
||||
font-size: 130%;
|
||||
font-weight: bold;
|
||||
}
|
||||
.hidden, .initially-hidden {
|
||||
position: absolute !important;
|
||||
opacity: 0 !important;
|
||||
pointer-events: none !important;
|
||||
display: none !important;
|
||||
}
|
||||
fieldset.options {
|
||||
font-size: 75%;
|
||||
}
|
||||
fieldset > legend {
|
||||
padding: 0 0.5em;
|
||||
}
|
||||
span.labeled-input {
|
||||
padding: 0.25em;
|
||||
margin: 0.25em 0.5em;
|
||||
border-radius: 0.25em;
|
||||
white-space: nowrap;
|
||||
background: #0002;
|
||||
}
|
||||
.center { text-align: center; }
|
||||
.error {
|
||||
color: red;
|
||||
background-color: yellow;
|
||||
}
|
||||
#test-output { font-family: monospace }
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
/* emcscript-related styling, used during the module load/intialization processes... */
|
||||
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
|
||||
div.emscripten { text-align: center; }
|
||||
div.emscripten_border { border: 1px solid black; }
|
||||
#module-spinner { overflow: visible; }
|
||||
#module-spinner > * {
|
||||
margin-top: 1em;
|
||||
}
|
||||
.spinner {
|
||||
height: 50px;
|
||||
width: 50px;
|
||||
margin: 0px auto;
|
||||
animation: rotation 0.8s linear infinite;
|
||||
border-left: 10px solid rgb(0,150,240);
|
||||
border-right: 10px solid rgb(0,150,240);
|
||||
border-bottom: 10px solid rgb(0,150,240);
|
||||
border-top: 10px solid rgb(100,0,200);
|
||||
border-radius: 100%;
|
||||
background-color: rgb(200,100,250);
|
||||
}
|
||||
@keyframes rotation {
|
||||
from {transform: rotate(0deg);}
|
||||
to {transform: rotate(360deg);}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
2022-05-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 is the JS Worker file for the sqlite3 fiddle app. It loads the
|
||||
sqlite3 wasm module and offers access to the db via the Worker
|
||||
message-passing interface.
|
||||
|
||||
Forewarning: this API is still very much Under Construction and
|
||||
subject to any number of changes as experience reveals what those
|
||||
need to be.
|
||||
|
||||
Because we can have only a single message handler, as opposed to an
|
||||
arbitrary number of discrete event listeners like with DOM elements,
|
||||
we have to define a lower-level message API. Messages abstractly
|
||||
look like:
|
||||
|
||||
{ type: string, data: type-specific value }
|
||||
|
||||
Where 'type' is used for dispatching and 'data' is a
|
||||
'type'-dependent value.
|
||||
|
||||
The 'type' values expected by each side of the main/worker
|
||||
connection vary. The types are described below but subject to
|
||||
change at any time as this experiment evolves.
|
||||
|
||||
Workers-to-Main types
|
||||
|
||||
- stdout, stderr: indicate stdout/stderr output from the wasm
|
||||
layer. The data property is the string of the output, noting
|
||||
that the emscripten binding emits these one line at a time. Thus,
|
||||
if a C-side puts() emits multiple lines in a single call, the JS
|
||||
side will see that as multiple calls. Example:
|
||||
|
||||
{type:'stdout', data: 'Hi, world.'}
|
||||
|
||||
- module: Status text. This is intended to alert the main thread
|
||||
about module loading status so that, e.g., the main thread can
|
||||
update a progress widget and DTRT when the module is finished
|
||||
loading and available for work. Status messages come in the form
|
||||
|
||||
{type:'module', data:{
|
||||
type:'status',
|
||||
data: {text:string|null, step:1-based-integer}
|
||||
}
|
||||
|
||||
with an incrementing step value for each subsequent message. When
|
||||
the module loading is complete, a message with a text value of
|
||||
null is posted.
|
||||
|
||||
- working: data='start'|'end'. Indicates that work is about to be
|
||||
sent to the module or has just completed. This can be used, e.g.,
|
||||
to disable UI elements which should not be activated while work
|
||||
is pending. Example:
|
||||
|
||||
{type:'working', data:'start'}
|
||||
|
||||
Main-to-Worker types:
|
||||
|
||||
- shellExec: data=text to execute as if it had been entered in the
|
||||
sqlite3 CLI shell app (as opposed to sqlite3_exec()). This event
|
||||
causes the worker to emit a 'working' event (data='start') before
|
||||
it starts and a 'working' event (data='end') when it finished. If
|
||||
called while work is currently being executed it emits stderr
|
||||
message instead of doing actual work, as the underlying db cannot
|
||||
handle concurrent tasks. Example:
|
||||
|
||||
{type:'shellExec', data: 'select * from sqlite_master'}
|
||||
|
||||
- More TBD as the higher-level db layer develops.
|
||||
*/
|
||||
|
||||
/*
|
||||
Apparent browser(s) bug: console messages emitted may be duplicated
|
||||
in the console, even though they're provably only run once. See:
|
||||
|
||||
https://stackoverflow.com/questions/49659464
|
||||
|
||||
Noting that it happens in Firefox as well as Chrome. Harmless but
|
||||
annoying.
|
||||
*/
|
||||
"use strict";
|
||||
(function(){
|
||||
/**
|
||||
Posts a message in the form {type,data} unless passed more than 2
|
||||
args, in which case it posts {type, data:[arg1...argN]}.
|
||||
*/
|
||||
const wMsg = function(type,data){
|
||||
postMessage({
|
||||
type,
|
||||
data: arguments.length<3
|
||||
? data
|
||||
: Array.prototype.slice.call(arguments,1)
|
||||
});
|
||||
};
|
||||
|
||||
const stdout = function(){wMsg('stdout', Array.prototype.slice.call(arguments));};
|
||||
const stderr = function(){wMsg('stderr', Array.prototype.slice.call(arguments));};
|
||||
|
||||
self.onerror = function(/*message, source, lineno, colno, error*/) {
|
||||
const err = arguments[4];
|
||||
if(err && 'ExitStatus'==err.name){
|
||||
/* This is relevant for the sqlite3 shell binding but not the
|
||||
lower-level binding. */
|
||||
fiddleModule.isDead = true;
|
||||
stderr("FATAL ERROR:", err.message);
|
||||
stderr("Restarting the app requires reloading the page.");
|
||||
wMsg('error', err);
|
||||
}
|
||||
console.error(err);
|
||||
fiddleModule.setStatus('Exception thrown, see JavaScript console: '+err);
|
||||
};
|
||||
|
||||
const Sqlite3Shell = {
|
||||
/** Returns the name of the currently-opened db. */
|
||||
dbFilename: function f(){
|
||||
if(!f._) f._ = fiddleModule.cwrap('fiddle_db_filename', "string", ['string']);
|
||||
return f._();
|
||||
},
|
||||
/**
|
||||
Runs the given text through the shell as if it had been typed
|
||||
in by a user. Fires a working/start event before it starts and
|
||||
working/end event when it finishes.
|
||||
*/
|
||||
exec: function f(sql){
|
||||
if(!f._) f._ = fiddleModule.cwrap('fiddle_exec', null, ['string']);
|
||||
if(fiddleModule.isDead){
|
||||
stderr("shell module has exit()ed. Cannot run SQL.");
|
||||
return;
|
||||
}
|
||||
wMsg('working','start');
|
||||
try {
|
||||
if(f._running){
|
||||
stderr('Cannot run multiple commands concurrently.');
|
||||
}else{
|
||||
f._running = true;
|
||||
f._(sql);
|
||||
}
|
||||
} finally {
|
||||
delete f._running;
|
||||
wMsg('working','end');
|
||||
}
|
||||
},
|
||||
resetDb: function f(){
|
||||
if(!f._) f._ = fiddleModule.cwrap('fiddle_reset_db', null);
|
||||
stdout("Resetting database.");
|
||||
f._();
|
||||
stdout("Reset",this.dbFilename());
|
||||
},
|
||||
/* Interrupt can't work: this Worker is tied up working, so won't get the
|
||||
interrupt event which would be needed to perform the interrupt. */
|
||||
interrupt: function f(){
|
||||
if(!f._) f._ = fiddleModule.cwrap('fiddle_interrupt', null);
|
||||
stdout("Requesting interrupt.");
|
||||
f._();
|
||||
}
|
||||
};
|
||||
|
||||
self.onmessage = function f(ev){
|
||||
ev = ev.data;
|
||||
if(!f.cache){
|
||||
f.cache = {
|
||||
prevFilename: null
|
||||
};
|
||||
}
|
||||
//console.debug("worker: onmessage.data",ev);
|
||||
switch(ev.type){
|
||||
case 'shellExec': Sqlite3Shell.exec(ev.data); return;
|
||||
case 'db-reset': Sqlite3Shell.resetDb(); return;
|
||||
case 'interrupt': Sqlite3Shell.interrupt(); return;
|
||||
/** Triggers the export of the current db. Fires an
|
||||
event in the form:
|
||||
|
||||
{type:'db-export',
|
||||
data:{
|
||||
filename: name of db,
|
||||
buffer: contents of the db file (Uint8Array),
|
||||
error: on error, a message string and no buffer property.
|
||||
}
|
||||
}
|
||||
*/
|
||||
case 'db-export': {
|
||||
const fn = Sqlite3Shell.dbFilename();
|
||||
stdout("Exporting",fn+".");
|
||||
const fn2 = fn ? fn.split(/[/\\]/).pop() : null;
|
||||
try{
|
||||
if(!fn2) throw new Error("DB appears to be closed.");
|
||||
wMsg('db-export',{
|
||||
filename: fn2,
|
||||
buffer: fiddleModule.FS.readFile(fn, {encoding:"binary"})
|
||||
});
|
||||
}catch(e){
|
||||
/* Post a failure message so that UI elements disabled
|
||||
during the export can be re-enabled. */
|
||||
wMsg('db-export',{
|
||||
filename: fn,
|
||||
error: e.message
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'open': {
|
||||
/* Expects: {
|
||||
buffer: ArrayBuffer | Uint8Array,
|
||||
filename: for logging/informational purposes only
|
||||
} */
|
||||
const opt = ev.data;
|
||||
let buffer = opt.buffer;
|
||||
if(buffer instanceof Uint8Array){
|
||||
}else if(buffer instanceof ArrayBuffer){
|
||||
buffer = new Uint8Array(buffer);
|
||||
}else{
|
||||
stderr("'open' expects {buffer:Uint8Array} containing an uploaded db.");
|
||||
return;
|
||||
}
|
||||
const fn = (
|
||||
opt.filename
|
||||
? opt.filename.split(/[/\\]/).pop().replace('"','_')
|
||||
: ("db-"+((Math.random() * 10000000) | 0)+
|
||||
"-"+((Math.random() * 10000000) | 0)+".sqlite3")
|
||||
);
|
||||
/* We cannot delete the existing db file until the new one
|
||||
is installed, which means that we risk overflowing our
|
||||
quota (if any) by having both the previous and current
|
||||
db briefly installed in the virtual filesystem. */
|
||||
fiddleModule.FS.createDataFile("/", fn, buffer, true, true);
|
||||
const oldName = Sqlite3Shell.dbFilename();
|
||||
Sqlite3Shell.exec('.open "/'+fn+'"');
|
||||
if(oldName && oldName !== fn){
|
||||
try{fiddleModule.FS.unlink(oldName);}
|
||||
catch(e){/*ignored*/}
|
||||
}
|
||||
stdout("Replaced DB with",fn+".");
|
||||
return;
|
||||
}
|
||||
};
|
||||
console.warn("Unknown fiddle-worker message type:",ev);
|
||||
};
|
||||
|
||||
/**
|
||||
emscripten module for use with build mode -sMODULARIZE.
|
||||
*/
|
||||
const fiddleModule = {
|
||||
print: stdout,
|
||||
printErr: stderr,
|
||||
/**
|
||||
Intercepts status updates from the emscripting module init
|
||||
and fires worker events with a type of 'status' and a
|
||||
payload of:
|
||||
|
||||
{
|
||||
text: string | null, // null at end of load process
|
||||
step: integer // starts at 1, increments 1 per call
|
||||
}
|
||||
|
||||
We have no way of knowing in advance how many steps will
|
||||
be processed/posted, so creating a "percentage done" view is
|
||||
not really practical. One can be approximated by giving it a
|
||||
current value of message.step and max value of message.step+1,
|
||||
though.
|
||||
|
||||
When work is finished, a message with a text value of null is
|
||||
submitted.
|
||||
|
||||
After a message with text==null is posted, the module may later
|
||||
post messages about fatal problems, e.g. an exit() being
|
||||
triggered, so it is recommended that UI elements for posting
|
||||
status messages not be outright removed from the DOM when
|
||||
text==null, and that they instead be hidden until/unless
|
||||
text!=null.
|
||||
*/
|
||||
setStatus: function f(text){
|
||||
if(!f.last) f.last = { step: 0, text: '' };
|
||||
else if(text === f.last.text) return;
|
||||
f.last.text = text;
|
||||
wMsg('module',{
|
||||
type:'status',
|
||||
data:{step: ++f.last.step, text: text||null}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
importScripts('fiddle-module.js');
|
||||
/**
|
||||
initFiddleModule() is installed via fiddle-module.js due to
|
||||
building with:
|
||||
|
||||
emcc ... -sMODULARIZE=1 -sEXPORT_NAME=initFiddleModule
|
||||
*/
|
||||
initFiddleModule(fiddleModule).then(function(thisModule){
|
||||
wMsg('fiddle-ready');
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,283 @@
|
||||
<!doctype html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>SQLite3 Fiddle</title>
|
||||
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
||||
<!-- to add a togglable terminal-style view, uncomment the following
|
||||
two lines and ensure that these files are on the web server. -->
|
||||
<!--script src="jqterm/jqterm-bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="jqterm/jquery.terminal.min.css"/-->
|
||||
<link rel="stylesheet" href="emscripten.css"/>
|
||||
<style>
|
||||
/* The following styles are for app-level use. */
|
||||
:root {
|
||||
--sqlite-blue: #044a64;
|
||||
--textarea-color1: #044a64;
|
||||
--textarea-color2: white;
|
||||
}
|
||||
textarea {
|
||||
font-family: monospace;
|
||||
flex: 1 1 auto;
|
||||
background-color: var(--textarea-color1);
|
||||
color: var(--textarea-color2);
|
||||
}
|
||||
textarea#input {
|
||||
color: var(--textarea-color1);
|
||||
background-color: var(--textarea-color2);
|
||||
}
|
||||
header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background-color: var(--sqlite-blue);
|
||||
color: white;
|
||||
font-size: 120%;
|
||||
font-weight: bold;
|
||||
border-radius: 0.25em;
|
||||
padding: 0.2em 0.5em;
|
||||
}
|
||||
header > .powered-by {
|
||||
font-size: 80%;
|
||||
}
|
||||
header a, header a:visited, header a:hover {
|
||||
color: inherit;
|
||||
}
|
||||
#main-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column-reverse;
|
||||
flex: 1 1 auto;
|
||||
margin: 0.5em 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
#main-wrapper.side-by-side {
|
||||
flex-direction: row;
|
||||
}
|
||||
#main-wrapper.side-by-side > fieldset {
|
||||
margin-left: 0.25em;
|
||||
margin-right: 0.25em;
|
||||
}
|
||||
#main-wrapper:not(.side-by-side) > fieldset {
|
||||
margin-bottom: 0.25em;
|
||||
}
|
||||
#main-wrapper.swapio {
|
||||
flex-direction: column;
|
||||
}
|
||||
#main-wrapper.side-by-side.swapio {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
.zone-wrapper{
|
||||
display: flex;
|
||||
margin: 0;
|
||||
flex: 1 1 0%;
|
||||
border-radius: 0.5em;
|
||||
min-width: inherit/*important: resolves inability to scroll fieldset child element!*/;
|
||||
padding: 0.35em 0 0 0;
|
||||
}
|
||||
.zone-wrapper textarea {
|
||||
border-radius: 0.5em;
|
||||
flex: 1 1 auto;
|
||||
/*min/max width resolve an inexplicable margin on the RHS. The -1em
|
||||
is for the padding, else we overlap the parent boundaries.*/
|
||||
/*min-width: calc(100% - 1em);
|
||||
max-width: calc(100% - 1em);
|
||||
padding: 0 0.5em;*/
|
||||
}
|
||||
|
||||
.zone-wrapper.input { flex: 10 1 auto; }
|
||||
.zone-wrapper.output { flex: 20 1 auto; }
|
||||
.zone-wrapper > div {
|
||||
display:flex;
|
||||
flex: 1 1 0%;
|
||||
}
|
||||
.zone-wrapper.output {}
|
||||
.button-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
align-content: space-between;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.button-bar > * {
|
||||
margin: 0.05em 0.5em 0.05em 0;
|
||||
flex: 0 1 auto;
|
||||
align-self: auto;
|
||||
}
|
||||
label[for] {
|
||||
cursor: pointer;
|
||||
}
|
||||
.error {
|
||||
color: red;
|
||||
background-color: yellow;
|
||||
}
|
||||
.hidden, .initially-hidden {
|
||||
position: absolute !important;
|
||||
opacity: 0 !important;
|
||||
pointer-events: none !important;
|
||||
display: none !important;
|
||||
}
|
||||
fieldset {
|
||||
border-radius: 0.5em;
|
||||
border: 1px inset;
|
||||
padding: 0.25em;
|
||||
}
|
||||
fieldset.options {
|
||||
font-size: 80%;
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
fieldset:not(.options) > legend {
|
||||
font-size: 80%;
|
||||
}
|
||||
fieldset.options > div {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
fieldset button {
|
||||
font-size: inherit;
|
||||
}
|
||||
fieldset.collapsible > legend > .fieldset-toggle::after {
|
||||
content: " [hide]";
|
||||
position: relative;
|
||||
}
|
||||
fieldset.collapsible.collapsed > legend > .fieldset-toggle::after {
|
||||
content: " [show]";
|
||||
position: relative;
|
||||
}
|
||||
span.labeled-input {
|
||||
padding: 0.25em;
|
||||
margin: 0.05em 0.25em;
|
||||
border-radius: 0.25em;
|
||||
white-space: nowrap;
|
||||
background: #0002;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
span.labeled-input > *:nth-child(2) {
|
||||
margin-left: 0.3em;
|
||||
}
|
||||
.center { text-align: center; }
|
||||
body.terminal-mode {
|
||||
max-height: calc(100% - 2em);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
#view-terminal {}
|
||||
.app-view {
|
||||
flex: 20 1 auto;
|
||||
}
|
||||
#view-split {
|
||||
display: flex;
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header id='titlebar'>
|
||||
<span>SQLite3 Fiddle</span>
|
||||
<span class='powered-by'>Powered by
|
||||
<a href='https://sqlite.org'>SQLite3</a></span>
|
||||
</header>
|
||||
<!-- emscripten bits -->
|
||||
<figure id="module-spinner">
|
||||
<div class="spinner"></div>
|
||||
<div class='center'><strong>Initializing app...</strong></div>
|
||||
<div class='center'>
|
||||
On a slow internet connection this may take a moment. If this
|
||||
message displays for "a long time", intialization may have
|
||||
failed and the JavaScript console may contain clues as to why.
|
||||
</div>
|
||||
</figure>
|
||||
<div class="emscripten" id="module-status">Downloading...</div>
|
||||
<div class="emscripten">
|
||||
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
|
||||
</div><!-- /emscripten bits -->
|
||||
|
||||
<div id='view-terminal' class='app-view hidden initially-hidden'>
|
||||
This is a placeholder for a terminal-like view which is not in
|
||||
the default build.
|
||||
</div>
|
||||
|
||||
<div id='view-split' class='app-view initially-hidden'>
|
||||
<fieldset class='options collapsible'>
|
||||
<legend><button class='fieldset-toggle'>Options</button></legend>
|
||||
<div class=''>
|
||||
<span class='labeled-input'>
|
||||
<input type='checkbox' id='opt-cb-sbs'
|
||||
data-csstgt='#main-wrapper'
|
||||
data-cssclass='side-by-side'
|
||||
data-config='sideBySide'>
|
||||
<label for='opt-cb-sbs'>Side-by-side</label>
|
||||
</span>
|
||||
<span class='labeled-input'>
|
||||
<input type='checkbox' id='opt-cb-swapio'
|
||||
data-csstgt='#main-wrapper'
|
||||
data-cssclass='swapio'
|
||||
data-config='swapInOut'>
|
||||
<label for='opt-cb-swapio'>Swap in/out</label>
|
||||
</span>
|
||||
<span class='labeled-input'>
|
||||
<input type='checkbox' id='opt-cb-autoscroll'
|
||||
data-config='autoScrollOutput'>
|
||||
<label for='opt-cb-autoscroll'>Auto-scroll output</label>
|
||||
</span>
|
||||
<span class='labeled-input'>
|
||||
<input type='checkbox' id='opt-cb-autoclear'
|
||||
data-config='autoClearOutput'>
|
||||
<label for='opt-cb-autoclear'>Auto-clear output</label>
|
||||
</span>
|
||||
<span class='labeled-input'>
|
||||
<input type='file' id='load-db' class='hidden'/>
|
||||
<button id='btn-load-db'>Load DB...</button>
|
||||
</span>
|
||||
<span class='labeled-input'>
|
||||
<button id='btn-export'>Download DB</button>
|
||||
</span>
|
||||
<span class='labeled-input'>
|
||||
<button id='btn-reset'>Reset DB</button>
|
||||
</span>
|
||||
</div>
|
||||
</fieldset><!-- .options -->
|
||||
<div id='main-wrapper' class=''>
|
||||
<fieldset class='zone-wrapper input'>
|
||||
<legend><div class='button-bar'>
|
||||
<button id='btn-shell-exec'>Run</button>
|
||||
<button id='btn-clear'>Clear Input</button>
|
||||
<!--button data-cmd='.help'>Help</button-->
|
||||
<select id='select-examples'></select>
|
||||
</div></legend>
|
||||
<div><textarea id="input"
|
||||
placeholder="Shell input. Ctrl-enter/shift-enter runs it.">
|
||||
-- ==================================================
|
||||
-- Use ctrl-enter or shift-enter to execute sqlite3
|
||||
-- shell commands and SQL.
|
||||
-- If a subset of the text is currently selected,
|
||||
-- only that part is executed.
|
||||
-- ==================================================
|
||||
.nullvalue NULL
|
||||
.headers on
|
||||
</textarea></div>
|
||||
</fieldset>
|
||||
<fieldset class='zone-wrapper output'>
|
||||
<legend><div class='button-bar'>
|
||||
<button id='btn-clear-output'>Clear Output</button>
|
||||
<button id='btn-interrupt' class='hidden' disabled>Interrupt</button>
|
||||
<!-- interruption cannot work in the current configuration
|
||||
because we cannot send an interrupt message when work
|
||||
is currently underway. At that point the Worker is
|
||||
tied up and will not receive the message. -->
|
||||
</div></legend>
|
||||
<div><textarea id="output" readonly
|
||||
placeholder="Shell output."></textarea></div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div> <!-- #view-split -->
|
||||
<!-- Maintenance notes:
|
||||
|
||||
... TODO... currently being refactored...
|
||||
|
||||
-->
|
||||
<script src="fiddle.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,809 @@
|
||||
/*
|
||||
2022-05-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 is the main entry point for the sqlite3 fiddle app. It sets up the
|
||||
various UI bits, loads a Worker for the db connection, and manages the
|
||||
communication between the UI and worker.
|
||||
*/
|
||||
(function(){
|
||||
'use strict';
|
||||
/* Recall that the 'self' symbol, except where locally
|
||||
overwritten, refers to the global window or worker object. */
|
||||
|
||||
const storage = (function(NS/*namespace object in which to store this module*/){
|
||||
/* Pedantic licensing note: this code originated in the Fossil SCM
|
||||
source tree, where it has a different license, but the person who
|
||||
ported it into sqlite is the same one who wrote it for fossil. */
|
||||
'use strict';
|
||||
NS = NS||{};
|
||||
|
||||
/**
|
||||
This module provides a basic wrapper around localStorage
|
||||
or sessionStorage or a dummy proxy object if neither
|
||||
of those are available.
|
||||
*/
|
||||
const tryStorage = function f(obj){
|
||||
if(!f.key) f.key = 'storage.access.check';
|
||||
try{
|
||||
obj.setItem(f.key, 'f');
|
||||
const x = obj.getItem(f.key);
|
||||
obj.removeItem(f.key);
|
||||
if(x!=='f') throw new Error(f.key+" failed")
|
||||
return obj;
|
||||
}catch(e){
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
/** Internal storage impl for this module. */
|
||||
const $storage =
|
||||
tryStorage(window.localStorage)
|
||||
|| tryStorage(window.sessionStorage)
|
||||
|| tryStorage({
|
||||
// A basic dummy xyzStorage stand-in
|
||||
$$$:{},
|
||||
setItem: function(k,v){this.$$$[k]=v},
|
||||
getItem: function(k){
|
||||
return this.$$$.hasOwnProperty(k) ? this.$$$[k] : undefined;
|
||||
},
|
||||
removeItem: function(k){delete this.$$$[k]},
|
||||
clear: function(){this.$$$={}}
|
||||
});
|
||||
|
||||
/**
|
||||
For the dummy storage we need to differentiate between
|
||||
$storage and its real property storage for hasOwnProperty()
|
||||
to work properly...
|
||||
*/
|
||||
const $storageHolder = $storage.hasOwnProperty('$$$') ? $storage.$$$ : $storage;
|
||||
|
||||
/**
|
||||
A prefix which gets internally applied to all storage module
|
||||
property keys so that localStorage and sessionStorage across the
|
||||
same browser profile instance do not "leak" across multiple apps
|
||||
being hosted by the same origin server. Such cross-polination is
|
||||
still there but, with this key prefix applied, it won't be
|
||||
immediately visible via the storage API.
|
||||
|
||||
With this in place we can justify using localStorage instead of
|
||||
sessionStorage.
|
||||
|
||||
One implication of using localStorage and sessionStorage is that
|
||||
their scope (the same "origin" and client application/profile)
|
||||
allows multiple apps on the same origin to use the same
|
||||
storage. Thus /appA/foo could then see changes made via
|
||||
/appB/foo. The data do not cross user- or browser boundaries,
|
||||
though, so it "might" arguably be called a
|
||||
feature. storageKeyPrefix was added so that we can sandbox that
|
||||
state for each separate app which shares an origin.
|
||||
|
||||
See: https://fossil-scm.org/forum/forumpost/4afc4d34de
|
||||
|
||||
Sidebar: it might seem odd to provide a key prefix and stick all
|
||||
properties in the topmost level of the storage object. We do that
|
||||
because adding a layer of object to sandbox each app would mean
|
||||
(de)serializing that whole tree on every storage property change.
|
||||
e.g. instead of storageObject.projectName.foo we have
|
||||
storageObject[storageKeyPrefix+'foo']. That's soley for
|
||||
efficiency's sake (in terms of battery life and
|
||||
environment-internal storage-level effort).
|
||||
*/
|
||||
const storageKeyPrefix = (
|
||||
$storageHolder===$storage/*localStorage or sessionStorage*/
|
||||
? (
|
||||
(NS.config ?
|
||||
(NS.config.projectCode || NS.config.projectName
|
||||
|| NS.config.shortProjectName)
|
||||
: false)
|
||||
|| window.location.pathname
|
||||
)+'::' : (
|
||||
'' /* transient storage */
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
A proxy for localStorage or sessionStorage or a
|
||||
page-instance-local proxy, if neither one is availble.
|
||||
|
||||
Which exact storage implementation is uses is unspecified, and
|
||||
apps must not rely on it.
|
||||
*/
|
||||
NS.storage = {
|
||||
storageKeyPrefix: storageKeyPrefix,
|
||||
/** Sets the storage key k to value v, implicitly converting
|
||||
it to a string. */
|
||||
set: (k,v)=>$storage.setItem(storageKeyPrefix+k,v),
|
||||
/** Sets storage key k to JSON.stringify(v). */
|
||||
setJSON: (k,v)=>$storage.setItem(storageKeyPrefix+k,JSON.stringify(v)),
|
||||
/** Returns the value for the given storage key, or
|
||||
dflt if the key is not found in the storage. */
|
||||
get: (k,dflt)=>$storageHolder.hasOwnProperty(
|
||||
storageKeyPrefix+k
|
||||
) ? $storage.getItem(storageKeyPrefix+k) : dflt,
|
||||
/** Returns true if the given key has a value of "true". If the
|
||||
key is not found, it returns true if the boolean value of dflt
|
||||
is "true". (Remember that JS persistent storage values are all
|
||||
strings.) */
|
||||
getBool: function(k,dflt){
|
||||
return 'true'===this.get(k,''+(!!dflt));
|
||||
},
|
||||
/** Returns the JSON.parse()'d value of the given
|
||||
storage key's value, or dflt is the key is not
|
||||
found or JSON.parse() fails. */
|
||||
getJSON: function f(k,dflt){
|
||||
try {
|
||||
const x = this.get(k,f);
|
||||
return x===f ? dflt : JSON.parse(x);
|
||||
}
|
||||
catch(e){return dflt}
|
||||
},
|
||||
/** Returns true if the storage contains the given key,
|
||||
else false. */
|
||||
contains: (k)=>$storageHolder.hasOwnProperty(storageKeyPrefix+k),
|
||||
/** Removes the given key from the storage. Returns this. */
|
||||
remove: function(k){
|
||||
$storage.removeItem(storageKeyPrefix+k);
|
||||
return this;
|
||||
},
|
||||
/** Clears ALL keys from the storage. Returns this. */
|
||||
clear: function(){
|
||||
this.keys().forEach((k)=>$storage.removeItem(/*w/o prefix*/k));
|
||||
return this;
|
||||
},
|
||||
/** Returns an array of all keys currently in the storage. */
|
||||
keys: ()=>Object.keys($storageHolder).filter((v)=>(v||'').startsWith(storageKeyPrefix)),
|
||||
/** Returns true if this storage is transient (only available
|
||||
until the page is reloaded), indicating that fileStorage
|
||||
and sessionStorage are unavailable. */
|
||||
isTransient: ()=>$storageHolder!==$storage,
|
||||
/** Returns a symbolic name for the current storage mechanism. */
|
||||
storageImplName: function(){
|
||||
if($storage===window.localStorage) return 'localStorage';
|
||||
else if($storage===window.sessionStorage) return 'sessionStorage';
|
||||
else return 'transient';
|
||||
},
|
||||
|
||||
/**
|
||||
Returns a brief help text string for the currently-selected
|
||||
storage type.
|
||||
*/
|
||||
storageHelpDescription: function(){
|
||||
return {
|
||||
localStorage: "Browser-local persistent storage with an "+
|
||||
"unspecified long-term lifetime (survives closing the browser, "+
|
||||
"but maybe not a browser upgrade).",
|
||||
sessionStorage: "Storage local to this browser tab, "+
|
||||
"lost if this tab is closed.",
|
||||
"transient": "Transient storage local to this invocation of this page."
|
||||
}[this.storageImplName()];
|
||||
}
|
||||
};
|
||||
return NS.storage;
|
||||
})({})/*storage API setup*/;
|
||||
|
||||
|
||||
/** Name of the stored copy of SqliteFiddle.config. */
|
||||
const configStorageKey = 'sqlite3-fiddle-config';
|
||||
|
||||
/**
|
||||
The SqliteFiddle object is intended to be the primary
|
||||
app-level object for the main-thread side of the sqlite
|
||||
fiddle application. It uses a worker thread to load the
|
||||
sqlite WASM module and communicate with it.
|
||||
*/
|
||||
const SF/*local convenience alias*/
|
||||
= window.SqliteFiddle/*canonical name*/ = {
|
||||
/* Config options. */
|
||||
config: {
|
||||
/* If true, SqliteFiddle.echo() will auto-scroll the
|
||||
output widget to the bottom when it receives output,
|
||||
else it won't. */
|
||||
autoScrollOutput: true,
|
||||
/* If true, the output area will be cleared before each
|
||||
command is run, else it will not. */
|
||||
autoClearOutput: false,
|
||||
/* If true, SqliteFiddle.echo() will echo its output to
|
||||
the console, in addition to its normal output widget.
|
||||
That slows it down but is useful for testing. */
|
||||
echoToConsole: false,
|
||||
/* If true, display input/output areas side-by-side. */
|
||||
sideBySide: true,
|
||||
/* If true, swap positions of the input/output areas. */
|
||||
swapInOut: false
|
||||
},
|
||||
/**
|
||||
Emits the given text, followed by a line break, to the
|
||||
output widget. If given more than one argument, they are
|
||||
join()'d together with a space between each. As a special
|
||||
case, if passed a single array, that array is used in place
|
||||
of the arguments array (this is to facilitate receiving
|
||||
lists of arguments via worker events).
|
||||
*/
|
||||
echo: function f(text) {
|
||||
/* Maintenance reminder: we currently require/expect a textarea
|
||||
output element. It might be nice to extend this to behave
|
||||
differently if the output element is a non-textarea element,
|
||||
in which case it would need to append the given text as a TEXT
|
||||
node and add a line break. */
|
||||
if(!f._){
|
||||
f._ = document.getElementById('output');
|
||||
f._.value = ''; // clear browser cache
|
||||
}
|
||||
if(arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
|
||||
else if(1===arguments.length && Array.isArray(text)) text = text.join(' ');
|
||||
// These replacements are necessary if you render to raw HTML
|
||||
//text = text.replace(/&/g, "&");
|
||||
//text = text.replace(/</g, "<");
|
||||
//text = text.replace(/>/g, ">");
|
||||
//text = text.replace('\n', '<br>', 'g');
|
||||
if(null===text){/*special case: clear output*/
|
||||
f._.value = '';
|
||||
return;
|
||||
}else if(this.echo._clearPending){
|
||||
delete this.echo._clearPending;
|
||||
f._.value = '';
|
||||
}
|
||||
if(this.config.echoToConsole) console.log(text);
|
||||
if(this.jqTerm) this.jqTerm.echo(text);
|
||||
f._.value += text + "\n";
|
||||
if(this.config.autoScrollOutput){
|
||||
f._.scrollTop = f._.scrollHeight;
|
||||
}
|
||||
},
|
||||
_msgMap: {},
|
||||
/** Adds a worker message handler for messages of the given
|
||||
type. */
|
||||
addMsgHandler: function f(type,callback){
|
||||
if(Array.isArray(type)){
|
||||
type.forEach((t)=>this.addMsgHandler(t, callback));
|
||||
return this;
|
||||
}
|
||||
(this._msgMap.hasOwnProperty(type)
|
||||
? this._msgMap[type]
|
||||
: (this._msgMap[type] = [])).push(callback);
|
||||
return this;
|
||||
},
|
||||
/** Given a worker message, runs all handlers for msg.type. */
|
||||
runMsgHandlers: function(msg){
|
||||
const list = (this._msgMap.hasOwnProperty(msg.type)
|
||||
? this._msgMap[msg.type] : false);
|
||||
if(!list){
|
||||
console.warn("No handlers found for message type:",msg);
|
||||
return false;
|
||||
}
|
||||
//console.debug("runMsgHandlers",msg);
|
||||
list.forEach((f)=>f(msg));
|
||||
return true;
|
||||
},
|
||||
/** Removes all message handlers for the given message type. */
|
||||
clearMsgHandlers: function(type){
|
||||
delete this._msgMap[type];
|
||||
return this;
|
||||
},
|
||||
/* Posts a message in the form {type, data} to the db worker. Returns this. */
|
||||
wMsg: function(type,data){
|
||||
this.worker.postMessage({type, data});
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
Prompts for confirmation and, if accepted, deletes
|
||||
all content and tables in the (transient) database.
|
||||
*/
|
||||
resetDb: function(){
|
||||
if(window.confirm("Really destroy all content and tables "
|
||||
+"in the (transient) db?")){
|
||||
this.wMsg('db-reset');
|
||||
}
|
||||
return this;
|
||||
},
|
||||
/** Stores this object's config in the browser's storage. */
|
||||
storeConfig: function(){
|
||||
storage.setJSON(configStorageKey,this.config);
|
||||
}
|
||||
};
|
||||
|
||||
if(1){ /* Restore SF.config */
|
||||
const storedConfig = storage.getJSON(configStorageKey);
|
||||
if(storedConfig){
|
||||
/* Copy all properties to SF.config which are currently in
|
||||
storedConfig. We don't bother copying any other
|
||||
properties: those have been removed from the app in the
|
||||
meantime. */
|
||||
Object.keys(SF.config).forEach(function(k){
|
||||
if(storedConfig.hasOwnProperty(k)){
|
||||
SF.config[k] = storedConfig[k];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
SF.worker = new Worker('fiddle-worker.js');
|
||||
SF.worker.onmessage = (ev)=>SF.runMsgHandlers(ev.data);
|
||||
SF.addMsgHandler(['stdout', 'stderr'], (ev)=>SF.echo(ev.data));
|
||||
|
||||
/* querySelectorAll() proxy */
|
||||
const EAll = function(/*[element=document,] cssSelector*/){
|
||||
return (arguments.length>1 ? arguments[0] : document)
|
||||
.querySelectorAll(arguments[arguments.length-1]);
|
||||
};
|
||||
/* querySelector() proxy */
|
||||
const E = function(/*[element=document,] cssSelector*/){
|
||||
return (arguments.length>1 ? arguments[0] : document)
|
||||
.querySelector(arguments[arguments.length-1]);
|
||||
};
|
||||
|
||||
/** Handles status updates from the Module object. */
|
||||
SF.addMsgHandler('module', function f(ev){
|
||||
ev = ev.data;
|
||||
if('status'!==ev.type){
|
||||
console.warn("Unexpected module-type message:",ev);
|
||||
return;
|
||||
}
|
||||
if(!f.ui){
|
||||
f.ui = {
|
||||
status: E('#module-status'),
|
||||
progress: E('#module-progress'),
|
||||
spinner: E('#module-spinner')
|
||||
};
|
||||
}
|
||||
const msg = ev.data;
|
||||
if(f.ui.progres){
|
||||
progress.value = msg.step;
|
||||
progress.max = msg.step + 1/*we don't know how many steps to expect*/;
|
||||
}
|
||||
if(1==msg.step){
|
||||
f.ui.progress.classList.remove('hidden');
|
||||
f.ui.spinner.classList.remove('hidden');
|
||||
}
|
||||
if(msg.text){
|
||||
f.ui.status.classList.remove('hidden');
|
||||
f.ui.status.innerText = msg.text;
|
||||
}else{
|
||||
if(f.ui.progress){
|
||||
f.ui.progress.remove();
|
||||
f.ui.spinner.remove();
|
||||
delete f.ui.progress;
|
||||
delete f.ui.spinner;
|
||||
}
|
||||
f.ui.status.classList.add('hidden');
|
||||
/* The module can post messages about fatal problems,
|
||||
e.g. an exit() being triggered or assertion failure,
|
||||
after the last "load" message has arrived, so
|
||||
leave f.ui.status and message listener intact. */
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
The 'fiddle-ready' event is fired (with no payload) when the
|
||||
wasm module has finished loading. Interestingly, that happens
|
||||
_before_ the final module:status event */
|
||||
SF.addMsgHandler('fiddle-ready', function(){
|
||||
SF.clearMsgHandlers('fiddle-ready');
|
||||
self.onSFLoaded();
|
||||
});
|
||||
|
||||
/**
|
||||
Performs all app initialization which must wait until after the
|
||||
worker module is loaded. This function removes itself when it's
|
||||
called.
|
||||
*/
|
||||
self.onSFLoaded = function(){
|
||||
delete this.onSFLoaded;
|
||||
// Unhide all elements which start out hidden
|
||||
EAll('.initially-hidden').forEach((e)=>e.classList.remove('initially-hidden'));
|
||||
E('#btn-reset').addEventListener('click',()=>SF.resetDb());
|
||||
const taInput = E('#input');
|
||||
const btnClearIn = E('#btn-clear');
|
||||
btnClearIn.addEventListener('click',function(){
|
||||
taInput.value = '';
|
||||
},false);
|
||||
// Ctrl-enter and shift-enter both run the current SQL.
|
||||
taInput.addEventListener('keydown',function(ev){
|
||||
if((ev.ctrlKey || ev.shiftKey) && 13 === ev.keyCode){
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
btnShellExec.click();
|
||||
}
|
||||
}, false);
|
||||
const taOutput = E('#output');
|
||||
const btnClearOut = E('#btn-clear-output');
|
||||
btnClearOut.addEventListener('click',function(){
|
||||
taOutput.value = '';
|
||||
if(SF.jqTerm) SF.jqTerm.clear();
|
||||
},false);
|
||||
const btnShellExec = E('#btn-shell-exec');
|
||||
btnShellExec.addEventListener('click',function(ev){
|
||||
let sql;
|
||||
ev.preventDefault();
|
||||
if(taInput.selectionStart<taInput.selectionEnd){
|
||||
sql = taInput.value.substring(taInput.selectionStart,taInput.selectionEnd).trim();
|
||||
}else{
|
||||
sql = taInput.value.trim();
|
||||
}
|
||||
if(sql) SF.dbExec(sql);
|
||||
},false);
|
||||
|
||||
const btnInterrupt = E("#btn-interrupt");
|
||||
//btnInterrupt.classList.add('hidden');
|
||||
/** To be called immediately before work is sent to the
|
||||
worker. Updates some UI elements. The 'working'/'end'
|
||||
event will apply the inverse, undoing the bits this
|
||||
function does. This impl is not in the 'working'/'start'
|
||||
event handler because that event is given to us
|
||||
asynchronously _after_ we need to have performed this
|
||||
work.
|
||||
*/
|
||||
const preStartWork = function f(){
|
||||
if(!f._){
|
||||
const title = E('title');
|
||||
f._ = {
|
||||
btnLabel: btnShellExec.innerText,
|
||||
pageTitle: title,
|
||||
pageTitleOrig: title.innerText
|
||||
};
|
||||
}
|
||||
f._.pageTitle.innerText = "[working...] "+f._.pageTitleOrig;
|
||||
btnShellExec.setAttribute('disabled','disabled');
|
||||
btnInterrupt.removeAttribute('disabled','disabled');
|
||||
};
|
||||
|
||||
/* Sends the given text to the db module to evaluate as if it
|
||||
had been entered in the sqlite3 CLI shell. If it's null or
|
||||
empty, this is a no-op except that the very first call will
|
||||
initialize the db and output an informational header. */
|
||||
SF.dbExec = function f(sql){
|
||||
if(this.config.autoClearOutput){
|
||||
this.echo._clearPending = true;
|
||||
}
|
||||
preStartWork();
|
||||
this.wMsg('shellExec',sql);
|
||||
};
|
||||
|
||||
SF.addMsgHandler('working',function f(ev){
|
||||
switch(ev.data){
|
||||
case 'start': /* See notes in preStartWork(). */; return;
|
||||
case 'end':
|
||||
preStartWork._.pageTitle.innerText = preStartWork._.pageTitleOrig;
|
||||
btnShellExec.innerText = preStartWork._.btnLabel;
|
||||
btnShellExec.removeAttribute('disabled');
|
||||
btnInterrupt.setAttribute('disabled','disabled');
|
||||
return;
|
||||
}
|
||||
console.warn("Unhandled 'working' event:",ev.data);
|
||||
});
|
||||
|
||||
/* For each checkbox with data-csstgt, set up a handler which
|
||||
toggles the given CSS class on the element matching
|
||||
E(data-csstgt). */
|
||||
EAll('input[type=checkbox][data-csstgt]')
|
||||
.forEach(function(e){
|
||||
const tgt = E(e.dataset.csstgt);
|
||||
const cssClass = e.dataset.cssclass || 'error';
|
||||
e.checked = tgt.classList.contains(cssClass);
|
||||
e.addEventListener('change', function(){
|
||||
tgt.classList[
|
||||
this.checked ? 'add' : 'remove'
|
||||
](cssClass)
|
||||
}, false);
|
||||
});
|
||||
/* For each checkbox with data-config=X, set up a binding to
|
||||
SF.config[X]. These must be set up AFTER data-csstgt
|
||||
checkboxes so that those two states can be synced properly. */
|
||||
EAll('input[type=checkbox][data-config]')
|
||||
.forEach(function(e){
|
||||
const confVal = !!SF.config[e.dataset.config];
|
||||
if(e.checked !== confVal){
|
||||
/* Ensure that data-csstgt mappings (if any) get
|
||||
synced properly. */
|
||||
e.checked = confVal;
|
||||
e.dispatchEvent(new Event('change'));
|
||||
}
|
||||
e.addEventListener('change', function(){
|
||||
SF.config[this.dataset.config] = this.checked;
|
||||
SF.storeConfig();
|
||||
}, false);
|
||||
});
|
||||
/* For each button with data-cmd=X, map a click handler which
|
||||
calls SF.dbExec(X). */
|
||||
const cmdClick = function(){SF.dbExec(this.dataset.cmd);};
|
||||
EAll('button[data-cmd]').forEach(
|
||||
e => e.addEventListener('click', cmdClick, false)
|
||||
);
|
||||
|
||||
btnInterrupt.addEventListener('click',function(){
|
||||
SF.wMsg('interrupt');
|
||||
});
|
||||
|
||||
/** Initiate a download of the db. */
|
||||
const btnExport = E('#btn-export');
|
||||
const eLoadDb = E('#load-db');
|
||||
const btnLoadDb = E('#btn-load-db');
|
||||
btnLoadDb.addEventListener('click', ()=>eLoadDb.click());
|
||||
/**
|
||||
Enables (if passed true) or disables all UI elements which
|
||||
"might," if timed "just right," interfere with an
|
||||
in-progress db import/export/exec operation.
|
||||
*/
|
||||
const enableMutatingElements = function f(enable){
|
||||
if(!f._elems){
|
||||
f._elems = [
|
||||
/* UI elements to disable while import/export are
|
||||
running. Normally the export is fast enough
|
||||
that this won't matter, but we really don't
|
||||
want to be reading (from outside of sqlite) the
|
||||
db when the user taps btnShellExec. */
|
||||
btnShellExec, btnExport, eLoadDb
|
||||
];
|
||||
}
|
||||
f._elems.forEach( enable
|
||||
? (e)=>e.removeAttribute('disabled')
|
||||
: (e)=>e.setAttribute('disabled','disabled') );
|
||||
};
|
||||
btnExport.addEventListener('click',function(){
|
||||
enableMutatingElements(false);
|
||||
SF.wMsg('db-export');
|
||||
});
|
||||
SF.addMsgHandler('db-export', function(ev){
|
||||
enableMutatingElements(true);
|
||||
ev = ev.data;
|
||||
if(ev.error){
|
||||
SF.echo("Export failed:",ev.error);
|
||||
return;
|
||||
}
|
||||
const blob = new Blob([ev.buffer], {type:"application/x-sqlite3"});
|
||||
const a = document.createElement('a');
|
||||
document.body.appendChild(a);
|
||||
a.href = window.URL.createObjectURL(blob);
|
||||
a.download = ev.filename;
|
||||
a.addEventListener('click',function(){
|
||||
setTimeout(function(){
|
||||
SF.echo("Exported (possibly auto-downloaded):",ev.filename);
|
||||
window.URL.revokeObjectURL(a.href);
|
||||
a.remove();
|
||||
},500);
|
||||
});
|
||||
a.click();
|
||||
});
|
||||
/**
|
||||
Handle load/import of an external db file.
|
||||
*/
|
||||
eLoadDb.addEventListener('change',function(){
|
||||
const f = this.files[0];
|
||||
const r = new FileReader();
|
||||
const status = {loaded: 0, total: 0};
|
||||
enableMutatingElements(false);
|
||||
r.addEventListener('loadstart', function(){
|
||||
SF.echo("Loading",f.name,"...");
|
||||
});
|
||||
r.addEventListener('progress', function(ev){
|
||||
SF.echo("Loading progress:",ev.loaded,"of",ev.total,"bytes.");
|
||||
});
|
||||
const that = this;
|
||||
r.addEventListener('load', function(){
|
||||
enableMutatingElements(true);
|
||||
SF.echo("Loaded",f.name+". Opening db...");
|
||||
SF.wMsg('open',{
|
||||
filename: f.name,
|
||||
buffer: this.result
|
||||
});
|
||||
});
|
||||
r.addEventListener('error',function(){
|
||||
enableMutatingElements(true);
|
||||
SF.echo("Loading",f.name,"failed for unknown reasons.");
|
||||
});
|
||||
r.addEventListener('abort',function(){
|
||||
enableMutatingElements(true);
|
||||
SF.echo("Cancelled loading of",f.name+".");
|
||||
});
|
||||
r.readAsArrayBuffer(f);
|
||||
});
|
||||
|
||||
EAll('fieldset.collapsible').forEach(function(fs){
|
||||
const btnToggle = E(fs,'legend > .fieldset-toggle'),
|
||||
content = EAll(fs,':scope > div');
|
||||
btnToggle.addEventListener('click', function(){
|
||||
fs.classList.toggle('collapsed');
|
||||
content.forEach((d)=>d.classList.toggle('hidden'));
|
||||
}, false);
|
||||
});
|
||||
|
||||
/**
|
||||
Given a DOM element, this routine measures its "effective
|
||||
height", which is the bounding top/bottom range of this element
|
||||
and all of its children, recursively. For some DOM structure
|
||||
cases, a parent may have a reported height of 0 even though
|
||||
children have non-0 sizes.
|
||||
|
||||
Returns 0 if !e or if the element really has no height.
|
||||
*/
|
||||
const effectiveHeight = function f(e){
|
||||
if(!e) return 0;
|
||||
if(!f.measure){
|
||||
f.measure = function callee(e, depth){
|
||||
if(!e) return;
|
||||
const m = e.getBoundingClientRect();
|
||||
if(0===depth){
|
||||
callee.top = m.top;
|
||||
callee.bottom = m.bottom;
|
||||
}else{
|
||||
callee.top = m.top ? Math.min(callee.top, m.top) : callee.top;
|
||||
callee.bottom = Math.max(callee.bottom, m.bottom);
|
||||
}
|
||||
Array.prototype.forEach.call(e.children,(e)=>callee(e,depth+1));
|
||||
if(0===depth){
|
||||
//console.debug("measure() height:",e.className, callee.top, callee.bottom, (callee.bottom - callee.top));
|
||||
f.extra += callee.bottom - callee.top;
|
||||
}
|
||||
return f.extra;
|
||||
};
|
||||
}
|
||||
f.extra = 0;
|
||||
f.measure(e,0);
|
||||
return f.extra;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns a function, that, as long as it continues to be invoked,
|
||||
will not be triggered. The function will be called after it stops
|
||||
being called for N milliseconds. If `immediate` is passed, call
|
||||
the callback immediately and hinder future invocations until at
|
||||
least the given time has passed.
|
||||
|
||||
If passed only 1 argument, or passed a falsy 2nd argument,
|
||||
the default wait time set in this function's $defaultDelay
|
||||
property is used.
|
||||
|
||||
Source: underscore.js, by way of https://davidwalsh.name/javascript-debounce-function
|
||||
*/
|
||||
const debounce = function f(func, wait, immediate) {
|
||||
var timeout;
|
||||
if(!wait) wait = f.$defaultDelay;
|
||||
return function() {
|
||||
const context = this, args = Array.prototype.slice.call(arguments);
|
||||
const later = function() {
|
||||
timeout = undefined;
|
||||
if(!immediate) func.apply(context, args);
|
||||
};
|
||||
const callNow = immediate && !timeout;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
if(callNow) func.apply(context, args);
|
||||
};
|
||||
};
|
||||
debounce.$defaultDelay = 500 /*arbitrary*/;
|
||||
|
||||
const ForceResizeKludge = (function(){
|
||||
/* Workaround for Safari mayhem regarding use of vh CSS
|
||||
units.... We cannot use vh units to set the main view
|
||||
size because Safari chokes on that, so we calculate
|
||||
that height here. Larger than ~95% is too big for
|
||||
Firefox on Android, causing the input area to move
|
||||
off-screen. */
|
||||
const appViews = EAll('.app-view');
|
||||
const elemsToCount = [
|
||||
/* Elements which we need to always count in the
|
||||
visible body size. */
|
||||
E('body > header'),
|
||||
E('body > footer')
|
||||
];
|
||||
const resized = function f(){
|
||||
if(f.$disabled) return;
|
||||
const wh = window.innerHeight;
|
||||
var ht;
|
||||
var extra = 0;
|
||||
elemsToCount.forEach((e)=>e ? extra += effectiveHeight(e) : false);
|
||||
ht = wh - extra;
|
||||
appViews.forEach(function(e){
|
||||
e.style.height =
|
||||
e.style.maxHeight = [
|
||||
"calc(", (ht>=100 ? ht : 100), "px",
|
||||
" - 2em"/*fudge value*/,")"
|
||||
/* ^^^^ hypothetically not needed, but both
|
||||
Chrome/FF on Linux will force scrollbars on the
|
||||
body if this value is too small. */
|
||||
].join('');
|
||||
});
|
||||
};
|
||||
resized.$disabled = true/*gets deleted when setup is finished*/;
|
||||
window.addEventListener('resize', debounce(resized, 250), false);
|
||||
return resized;
|
||||
})();
|
||||
|
||||
/** Set up a selection list of examples */
|
||||
(function(){
|
||||
const xElem = E('#select-examples');
|
||||
const examples = [
|
||||
{name: "Help", sql:
|
||||
`-- ================================================
|
||||
-- Use ctrl-enter or shift-enter to execute sqlite3
|
||||
-- shell commands and SQL.
|
||||
-- If a subset of the text is currently selected,
|
||||
-- only that part is executed.
|
||||
-- ================================================
|
||||
.help`},
|
||||
{name: "Timer on", sql: ".timer on"},
|
||||
{name: "Setup table T", sql:`.nullvalue NULL
|
||||
CREATE TABLE t(a,b);
|
||||
INSERT INTO t(a,b) VALUES('abc',123),('def',456),(NULL,789),('ghi',012);
|
||||
SELECT * FROM t;`},
|
||||
{name: "Table list", sql: ".tables"},
|
||||
{name: "Box Mode", sql: ".mode box"},
|
||||
{name: "JSON Mode", sql: ".mode json"},
|
||||
{name: "Mandlebrot", sql: `WITH RECURSIVE
|
||||
xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+0.05 FROM xaxis WHERE x<1.2),
|
||||
yaxis(y) AS (VALUES(-1.0) UNION ALL SELECT y+0.1 FROM yaxis WHERE y<1.0),
|
||||
m(iter, cx, cy, x, y) AS (
|
||||
SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis
|
||||
UNION ALL
|
||||
SELECT iter+1, cx, cy, x*x-y*y + cx, 2.0*x*y + cy FROM m
|
||||
WHERE (x*x + y*y) < 4.0 AND iter<28
|
||||
),
|
||||
m2(iter, cx, cy) AS (
|
||||
SELECT max(iter), cx, cy FROM m GROUP BY cx, cy
|
||||
),
|
||||
a(t) AS (
|
||||
SELECT group_concat( substr(' .+*#', 1+min(iter/7,4), 1), '')
|
||||
FROM m2 GROUP BY cy
|
||||
)
|
||||
SELECT group_concat(rtrim(t),x'0a') as Mandelbrot FROM a;`}
|
||||
];
|
||||
const newOpt = function(lbl,val){
|
||||
const o = document.createElement('option');
|
||||
o.value = val;
|
||||
if(!val) o.setAttribute('disabled',true);
|
||||
o.appendChild(document.createTextNode(lbl));
|
||||
xElem.appendChild(o);
|
||||
};
|
||||
newOpt("Examples (replaces input!)");
|
||||
examples.forEach((o)=>newOpt(o.name, o.sql));
|
||||
//xElem.setAttribute('disabled',true);
|
||||
xElem.selectedIndex = 0;
|
||||
xElem.addEventListener('change', function(){
|
||||
taInput.value = '-- ' +
|
||||
this.selectedOptions[0].innerText +
|
||||
'\n' + this.value;
|
||||
SF.dbExec(this.value);
|
||||
});
|
||||
})()/* example queries */;
|
||||
|
||||
SF.echo(null/*clear any output generated by the init process*/);
|
||||
if(window.jQuery && window.jQuery.terminal){
|
||||
/* Set up the terminal-style view... */
|
||||
const eTerm = window.jQuery('#view-terminal').empty();
|
||||
SF.jqTerm = eTerm.terminal(SF.dbExec.bind(SF),{
|
||||
prompt: 'sqlite> ',
|
||||
greetings: false /* note that the docs incorrectly call this 'greeting' */
|
||||
});
|
||||
/* Set up a button to toggle the views... */
|
||||
const head = E('header#titlebar');
|
||||
const btnToggleView = document.createElement('button');
|
||||
btnToggleView.appendChild(document.createTextNode("Toggle View"));
|
||||
head.appendChild(btnToggleView);
|
||||
btnToggleView.addEventListener('click',function f(){
|
||||
EAll('.app-view').forEach(e=>e.classList.toggle('hidden'));
|
||||
if(document.body.classList.toggle('terminal-mode')){
|
||||
ForceResizeKludge();
|
||||
}
|
||||
}, false);
|
||||
btnToggleView.click()/*default to terminal view*/;
|
||||
}
|
||||
SF.dbExec(null/*init the db and output the header*/);
|
||||
SF.echo('This experimental app is provided in the hope that it',
|
||||
'may prove interesting or useful but is not an officially',
|
||||
'supported deliverable of the sqlite project. It is subject to',
|
||||
'any number of changes or outright removal at any time.\n');
|
||||
delete ForceResizeKludge.$disabled;
|
||||
ForceResizeKludge();
|
||||
|
||||
btnShellExec.click();
|
||||
}/*onSFLoaded()*/;
|
||||
})();
|
||||
@@ -0,0 +1,737 @@
|
||||
/**
|
||||
2022-06-30
|
||||
|
||||
The author disclaims copyright to this source code. In place of a
|
||||
legal notice, here is a blessing:
|
||||
|
||||
* May you do good and not evil.
|
||||
* May you find forgiveness for yourself and forgive others.
|
||||
* May you share freely, never taking more than you give.
|
||||
|
||||
***********************************************************************
|
||||
|
||||
The Jaccwabyt API is documented in detail in an external file.
|
||||
|
||||
Project home: https://fossil.wanderinghorse.net/r/jaccwabyt
|
||||
|
||||
*/
|
||||
'use strict';
|
||||
self.Jaccwabyt = function StructBinderFactory(config){
|
||||
/* ^^^^ it is recommended that clients move that object into wherever
|
||||
they'd like to have it and delete the self-held copy ("self" being
|
||||
the global window or worker object). This API does not require the
|
||||
global reference - it is simply installed as a convenience for
|
||||
connecting these bits to other co-developed code before it gets
|
||||
removed from the global namespace.
|
||||
*/
|
||||
|
||||
/** Throws a new Error, the message of which is the concatenation
|
||||
all args with a space between each. */
|
||||
const toss = (...args)=>{throw new Error(args.join(' '))};
|
||||
|
||||
/**
|
||||
Implementing function bindings revealed significant
|
||||
shortcomings in Emscripten's addFunction()/removeFunction()
|
||||
interfaces:
|
||||
|
||||
https://github.com/emscripten-core/emscripten/issues/17323
|
||||
|
||||
Until those are resolved, or a suitable replacement can be
|
||||
implemented, our function-binding API will be more limited
|
||||
and/or clumsier to use than initially hoped.
|
||||
*/
|
||||
if(!(config.heap instanceof WebAssembly.Memory)
|
||||
&& !(config.heap instanceof Function)){
|
||||
toss("config.heap must be WebAssembly.Memory instance or a function.");
|
||||
}
|
||||
['alloc','dealloc'].forEach(function(k){
|
||||
(config[k] instanceof Function) ||
|
||||
toss("Config option '"+k+"' must be a function.");
|
||||
});
|
||||
const SBF = StructBinderFactory;
|
||||
const heap = (config.heap instanceof Function)
|
||||
? config.heap : (()=>new Uint8Array(config.heap.buffer)),
|
||||
alloc = config.alloc,
|
||||
dealloc = config.dealloc,
|
||||
log = config.log || console.log.bind(console),
|
||||
memberPrefix = (config.memberPrefix || ""),
|
||||
memberSuffix = (config.memberSuffix || ""),
|
||||
bigIntEnabled = (undefined===config.bigIntEnabled
|
||||
? !!self['BigInt64Array'] : !!config.bigIntEnabled),
|
||||
BigInt = self['BigInt'],
|
||||
BigInt64Array = self['BigInt64Array'],
|
||||
/* Undocumented (on purpose) config options: */
|
||||
functionTable = config.functionTable/*EXPERIMENTAL, undocumented*/,
|
||||
ptrSizeof = config.ptrSizeof || 4,
|
||||
ptrIR = config.ptrIR || 'i32'
|
||||
;
|
||||
|
||||
if(!SBF.debugFlags){
|
||||
SBF.__makeDebugFlags = function(deriveFrom=null){
|
||||
/* This is disgustingly overengineered. :/ */
|
||||
if(deriveFrom && deriveFrom.__flags) deriveFrom = deriveFrom.__flags;
|
||||
const f = function f(flags){
|
||||
if(0===arguments.length){
|
||||
return f.__flags;
|
||||
}
|
||||
if(flags<0){
|
||||
delete f.__flags.getter; delete f.__flags.setter;
|
||||
delete f.__flags.alloc; delete f.__flags.dealloc;
|
||||
}else{
|
||||
f.__flags.getter = 0!==(0x01 & flags);
|
||||
f.__flags.setter = 0!==(0x02 & flags);
|
||||
f.__flags.alloc = 0!==(0x04 & flags);
|
||||
f.__flags.dealloc = 0!==(0x08 & flags);
|
||||
}
|
||||
return f._flags;
|
||||
};
|
||||
Object.defineProperty(f,'__flags', {
|
||||
iterable: false, writable: false,
|
||||
value: Object.create(deriveFrom)
|
||||
});
|
||||
if(!deriveFrom) f(0);
|
||||
return f;
|
||||
};
|
||||
SBF.debugFlags = SBF.__makeDebugFlags();
|
||||
}/*static init*/
|
||||
|
||||
const isLittleEndian = (function() {
|
||||
const buffer = new ArrayBuffer(2);
|
||||
new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
|
||||
// Int16Array uses the platform's endianness.
|
||||
return new Int16Array(buffer)[0] === 256;
|
||||
})();
|
||||
/**
|
||||
Some terms used in the internal docs:
|
||||
|
||||
StructType: a struct-wrapping class generated by this
|
||||
framework.
|
||||
DEF: struct description object.
|
||||
SIG: struct member signature string.
|
||||
*/
|
||||
|
||||
/** True if SIG s looks like a function signature, else
|
||||
false. */
|
||||
const isFuncSig = (s)=>'('===s[1];
|
||||
/** True if SIG s is-a pointer signature. */
|
||||
const isPtrSig = (s)=>'p'===s || 'P'===s;
|
||||
const isAutoPtrSig = (s)=>'P'===s /*EXPERIMENTAL*/;
|
||||
const sigLetter = (s)=>isFuncSig(s) ? 'p' : s[0];
|
||||
/** Returns the WASM IR form of the Emscripten-conventional letter
|
||||
at SIG s[0]. Throws for an unknown SIG. */
|
||||
const sigIR = function(s){
|
||||
switch(sigLetter(s)){
|
||||
case 'i': return 'i32';
|
||||
case 'p': case 'P': case 's': return ptrIR;
|
||||
case 'j': return 'i64';
|
||||
case 'f': return 'float';
|
||||
case 'd': return 'double';
|
||||
}
|
||||
toss("Unhandled signature IR:",s);
|
||||
};
|
||||
/** Returns the sizeof value for the given SIG. Throws for an
|
||||
unknown SIG. */
|
||||
const sigSizeof = function(s){
|
||||
switch(sigLetter(s)){
|
||||
case 'i': return 4;
|
||||
case 'p': case 'P': case 's': return ptrSizeof;
|
||||
case 'j': return 8;
|
||||
case 'f': return 4 /* C-side floats, not JS-side */;
|
||||
case 'd': return 8;
|
||||
}
|
||||
toss("Unhandled signature sizeof:",s);
|
||||
};
|
||||
const affirmBigIntArray = BigInt64Array
|
||||
? ()=>true : ()=>toss('BigInt64Array is not available.');
|
||||
/** Returns the (signed) TypedArray associated with the type
|
||||
described by the given SIG. Throws for an unknown SIG. */
|
||||
/**********
|
||||
const sigTypedArray = function(s){
|
||||
switch(sigIR(s)) {
|
||||
case 'i32': return Int32Array;
|
||||
case 'i64': return affirmBigIntArray() && BigInt64Array;
|
||||
case 'float': return Float32Array;
|
||||
case 'double': return Float64Array;
|
||||
}
|
||||
toss("Unhandled signature TypedArray:",s);
|
||||
};
|
||||
**************/
|
||||
/** Returns the name of a DataView getter method corresponding
|
||||
to the given SIG. */
|
||||
const sigDVGetter = function(s){
|
||||
switch(sigLetter(s)) {
|
||||
case 'p': case 'P': case 's': {
|
||||
switch(ptrSizeof){
|
||||
case 4: return 'getInt32';
|
||||
case 8: return affirmBigIntArray() && 'getBigInt64';
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'i': return 'getInt32';
|
||||
case 'j': return affirmBigIntArray() && 'getBigInt64';
|
||||
case 'f': return 'getFloat32';
|
||||
case 'd': return 'getFloat64';
|
||||
}
|
||||
toss("Unhandled DataView getter for signature:",s);
|
||||
};
|
||||
/** Returns the name of a DataView setter method corresponding
|
||||
to the given SIG. */
|
||||
const sigDVSetter = function(s){
|
||||
switch(sigLetter(s)){
|
||||
case 'p': case 'P': case 's': {
|
||||
switch(ptrSizeof){
|
||||
case 4: return 'setInt32';
|
||||
case 8: return affirmBigIntArray() && 'setBigInt64';
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'i': return 'setInt32';
|
||||
case 'j': return affirmBigIntArray() && 'setBigInt64';
|
||||
case 'f': return 'setFloat32';
|
||||
case 'd': return 'setFloat64';
|
||||
}
|
||||
toss("Unhandled DataView setter for signature:",s);
|
||||
};
|
||||
/**
|
||||
Returns either Number of BigInt, depending on the given
|
||||
SIG. This constructor is used in property setters to coerce
|
||||
the being-set value to the correct size.
|
||||
*/
|
||||
const sigDVSetWrapper = function(s){
|
||||
switch(sigLetter(s)) {
|
||||
case 'i': case 'f': case 'd': return Number;
|
||||
case 'j': return affirmBigIntArray() && BigInt;
|
||||
case 'p': case 'P': case 's':
|
||||
switch(ptrSizeof){
|
||||
case 4: return Number;
|
||||
case 8: return affirmBigIntArray() && BigInt;
|
||||
}
|
||||
break;
|
||||
}
|
||||
toss("Unhandled DataView set wrapper for signature:",s);
|
||||
};
|
||||
|
||||
const sPropName = (s,k)=>s+'::'+k;
|
||||
|
||||
const __propThrowOnSet = function(structName,propName){
|
||||
return ()=>toss(sPropName(structName,propName),"is read-only.");
|
||||
};
|
||||
|
||||
/**
|
||||
When C code passes a pointer of a bound struct to back into
|
||||
a JS function via a function pointer struct member, it
|
||||
arrives in JS as a number (pointer).
|
||||
StructType.instanceForPointer(ptr) can be used to get the
|
||||
instance associated with that pointer, and __ptrBacklinks
|
||||
holds that mapping. WeakMap keys must be objects, so we
|
||||
cannot use a weak map to map pointers to instances. We use
|
||||
the StructType constructor as the WeakMap key, mapped to a
|
||||
plain, prototype-less Object which maps the pointers to
|
||||
struct instances. That arrangement gives us a
|
||||
per-StructType type-safe way to resolve pointers.
|
||||
*/
|
||||
const __ptrBacklinks = new WeakMap();
|
||||
/**
|
||||
Similar to __ptrBacklinks but is scoped at the StructBinder
|
||||
level and holds pointer-to-object mappings for all struct
|
||||
instances created by any struct from any StructFactory
|
||||
which this specific StructBinder has created. The intention
|
||||
of this is to help implement more transparent handling of
|
||||
pointer-type property resolution.
|
||||
*/
|
||||
const __ptrBacklinksGlobal = Object.create(null);
|
||||
|
||||
/**
|
||||
In order to completely hide StructBinder-bound struct
|
||||
pointers from JS code, we store them in a scope-local
|
||||
WeakMap which maps the struct-bound objects to their WASM
|
||||
pointers. The pointers are accessible via
|
||||
boundObject.pointer, which is gated behind an accessor
|
||||
function, but are not exposed anywhere else in the
|
||||
object. The main intention of that is to make it impossible
|
||||
for stale copies to be made.
|
||||
*/
|
||||
const __instancePointerMap = new WeakMap();
|
||||
|
||||
/** Property name for the pointer-is-external marker. */
|
||||
const xPtrPropName = '(pointer-is-external)';
|
||||
|
||||
/** Frees the obj.pointer memory and clears the pointer
|
||||
property. */
|
||||
const __freeStruct = function(ctor, obj, m){
|
||||
if(!m) m = __instancePointerMap.get(obj);
|
||||
if(m) {
|
||||
if(obj.ondispose instanceof Function){
|
||||
try{obj.ondispose()}
|
||||
catch(e){
|
||||
/*do not rethrow: destructors must not throw*/
|
||||
console.warn("ondispose() for",ctor.structName,'@',
|
||||
m,'threw. NOT propagating it.',e);
|
||||
}
|
||||
}else if(Array.isArray(obj.ondispose)){
|
||||
obj.ondispose.forEach(function(x){
|
||||
try{
|
||||
if(x instanceof Function) x.call(obj);
|
||||
else if('number' === typeof x) dealloc(x);
|
||||
// else ignore. Strings are permitted to annotate entries
|
||||
// to assist in debugging.
|
||||
}catch(e){
|
||||
console.warn("ondispose() for",ctor.structName,'@',
|
||||
m,'threw. NOT propagating it.',e);
|
||||
}
|
||||
});
|
||||
}
|
||||
delete obj.ondispose;
|
||||
delete __ptrBacklinks.get(ctor)[m];
|
||||
delete __ptrBacklinksGlobal[m];
|
||||
__instancePointerMap.delete(obj);
|
||||
if(ctor.debugFlags.__flags.dealloc){
|
||||
log("debug.dealloc:",(obj[xPtrPropName]?"EXTERNAL":""),
|
||||
ctor.structName,"instance:",
|
||||
ctor.structInfo.sizeof,"bytes @"+m);
|
||||
}
|
||||
if(!obj[xPtrPropName]) dealloc(m);
|
||||
}
|
||||
};
|
||||
|
||||
/** Returns a skeleton for a read-only property accessor wrapping
|
||||
value v. */
|
||||
const rop = (v)=>{return {configurable: false, writable: false,
|
||||
iterable: false, value: v}};
|
||||
|
||||
/** Allocates obj's memory buffer based on the size defined in
|
||||
DEF.sizeof. */
|
||||
const __allocStruct = function(ctor, obj, m){
|
||||
let fill = !m;
|
||||
if(m) Object.defineProperty(obj, xPtrPropName, rop(m));
|
||||
else{
|
||||
m = alloc(ctor.structInfo.sizeof);
|
||||
if(!m) toss("Allocation of",ctor.structName,"structure failed.");
|
||||
}
|
||||
try {
|
||||
if(ctor.debugFlags.__flags.alloc){
|
||||
log("debug.alloc:",(fill?"":"EXTERNAL"),
|
||||
ctor.structName,"instance:",
|
||||
ctor.structInfo.sizeof,"bytes @"+m);
|
||||
}
|
||||
if(fill) heap().fill(0, m, m + ctor.structInfo.sizeof);
|
||||
__instancePointerMap.set(obj, m);
|
||||
__ptrBacklinks.get(ctor)[m] = obj;
|
||||
__ptrBacklinksGlobal[m] = obj;
|
||||
}catch(e){
|
||||
__freeStruct(ctor, obj, m);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
/** Gets installed as the memoryDump() method of all structs. */
|
||||
const __memoryDump = function(){
|
||||
const p = this.pointer;
|
||||
return p
|
||||
? new Uint8Array(heap().slice(p, p+this.structInfo.sizeof))
|
||||
: null;
|
||||
};
|
||||
|
||||
const __memberKey = (k)=>memberPrefix + k + memberSuffix;
|
||||
const __memberKeyProp = rop(__memberKey);
|
||||
|
||||
/**
|
||||
Looks up a struct member in structInfo.members. Throws if found
|
||||
if tossIfNotFound is true, else returns undefined if not
|
||||
found. The given name may be either the name of the
|
||||
structInfo.members key (faster) or the key as modified by the
|
||||
memberPrefix/memberSuffix settings.
|
||||
*/
|
||||
const __lookupMember = function(structInfo, memberName, tossIfNotFound=true){
|
||||
let m = structInfo.members[memberName];
|
||||
if(!m && (memberPrefix || memberSuffix)){
|
||||
// Check for a match on members[X].key
|
||||
for(const v of Object.values(structInfo.members)){
|
||||
if(v.key===memberName){ m = v; break; }
|
||||
}
|
||||
if(!m && tossIfNotFound){
|
||||
toss(sPropName(structInfo.name,memberName),'is not a mapped struct member.');
|
||||
}
|
||||
}
|
||||
return m;
|
||||
};
|
||||
|
||||
/**
|
||||
Uses __lookupMember(obj.structInfo,memberName) to find a member,
|
||||
throwing if not found. Returns its signature, either in this
|
||||
framework's native format or in Emscripten format.
|
||||
*/
|
||||
const __memberSignature = function f(obj,memberName,emscriptenFormat=false){
|
||||
if(!f._) f._ = (x)=>x.replace(/[^vipPsjrd]/g,'').replace(/[pPs]/g,'i');
|
||||
const m = __lookupMember(obj.structInfo, memberName, true);
|
||||
return emscriptenFormat ? f._(m.signature) : m.signature;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the instanceForPointer() impl for the given
|
||||
StructType constructor.
|
||||
*/
|
||||
const __instanceBacklinkFactory = function(ctor){
|
||||
const b = Object.create(null);
|
||||
__ptrBacklinks.set(ctor, b);
|
||||
return (ptr)=>b[ptr];
|
||||
};
|
||||
|
||||
const __ptrPropDescriptor = {
|
||||
configurable: false, enumerable: false,
|
||||
get: function(){return __instancePointerMap.get(this)},
|
||||
set: ()=>toss("Cannot assign the 'pointer' property of a struct.")
|
||||
// Reminder: leaving `set` undefined makes assignments
|
||||
// to the property _silently_ do nothing. Current unit tests
|
||||
// rely on it throwing, though.
|
||||
};
|
||||
|
||||
/** Impl of X.memberKeys() for StructType and struct ctors. */
|
||||
const __structMemberKeys = rop(function(){
|
||||
const a = [];
|
||||
Object.keys(this.structInfo.members).forEach((k)=>a.push(this.memberKey(k)));
|
||||
return a;
|
||||
});
|
||||
|
||||
const __utf8Decoder = new TextDecoder('utf-8');
|
||||
const __utf8Encoder = new TextEncoder();
|
||||
|
||||
/**
|
||||
Uses __lookupMember() to find the given obj.structInfo key.
|
||||
Returns that member if it is a string, else returns false. If the
|
||||
member is not found, throws if tossIfNotFound is true, else
|
||||
returns false.
|
||||
*/
|
||||
const __memberIsString = function(obj,memberName, tossIfNotFound=false){
|
||||
const m = __lookupMember(obj.structInfo, memberName, tossIfNotFound);
|
||||
return (m && 1===m.signature.length && 's'===m.signature[0]) ? m : false;
|
||||
};
|
||||
|
||||
/**
|
||||
Given a member description object, throws if member.signature is
|
||||
not valid for assigning to or interpretation as a C-style string.
|
||||
It optimistically assumes that any signature of (i,p,s) is
|
||||
C-string compatible.
|
||||
*/
|
||||
const __affirmCStringSignature = function(member){
|
||||
if('s'===member.signature) return;
|
||||
toss("Invalid member type signature for C-string value:",
|
||||
JSON.stringify(member));
|
||||
};
|
||||
|
||||
/**
|
||||
Looks up the given member in obj.structInfo. If it has a
|
||||
signature of 's' then it is assumed to be a C-style UTF-8 string
|
||||
and a decoded copy of the string at its address is returned. If
|
||||
the signature is of any other type, it throws. If an s-type
|
||||
member's address is 0, `null` is returned.
|
||||
*/
|
||||
const __memberToJsString = function f(obj,memberName){
|
||||
const m = __lookupMember(obj.structInfo, memberName, true);
|
||||
__affirmCStringSignature(m);
|
||||
const addr = obj[m.key];
|
||||
//log("addr =",addr,memberName,"m =",m);
|
||||
if(!addr) return null;
|
||||
let pos = addr;
|
||||
const mem = heap();
|
||||
for( ; mem[pos]!==0; ++pos ) {
|
||||
//log("mem[",pos,"]",mem[pos]);
|
||||
};
|
||||
//log("addr =",addr,"pos =",pos);
|
||||
if(addr===pos) return "";
|
||||
return __utf8Decoder.decode(new Uint8Array(mem.buffer, addr, pos-addr));
|
||||
};
|
||||
|
||||
/**
|
||||
Adds value v to obj.ondispose, creating ondispose,
|
||||
or converting it to an array, if needed.
|
||||
*/
|
||||
const __addOnDispose = function(obj, v){
|
||||
if(obj.ondispose){
|
||||
if(obj.ondispose instanceof Function){
|
||||
obj.ondispose = [obj.ondispose];
|
||||
}/*else assume it's an array*/
|
||||
}else{
|
||||
obj.ondispose = [];
|
||||
}
|
||||
obj.ondispose.push(v);
|
||||
};
|
||||
|
||||
/**
|
||||
Allocates a new UTF-8-encoded, NUL-terminated copy of the given
|
||||
JS string and returns its address relative to heap(). If
|
||||
allocation returns 0 this function throws. Ownership of the
|
||||
memory is transfered to the caller, who must eventually pass it
|
||||
to the configured dealloc() function.
|
||||
*/
|
||||
const __allocCString = function(str){
|
||||
const u = __utf8Encoder.encode(str);
|
||||
const mem = alloc(u.length+1);
|
||||
if(!mem) toss("Allocation error while duplicating string:",str);
|
||||
const h = heap();
|
||||
let i = 0;
|
||||
for( ; i < u.length; ++i ) h[mem + i] = u[i];
|
||||
h[mem + u.length] = 0;
|
||||
//log("allocCString @",mem," =",u);
|
||||
return mem;
|
||||
};
|
||||
|
||||
/**
|
||||
Sets the given struct member of obj to a dynamically-allocated,
|
||||
UTF-8-encoded, NUL-terminated copy of str. It is up to the caller
|
||||
to free any prior memory, if appropriate. The newly-allocated
|
||||
string is added to obj.ondispose so will be freed when the object
|
||||
is disposed.
|
||||
*/
|
||||
const __setMemberCString = function(obj, memberName, str){
|
||||
const m = __lookupMember(obj.structInfo, memberName, true);
|
||||
__affirmCStringSignature(m);
|
||||
/* Potential TODO: if obj.ondispose contains obj[m.key] then
|
||||
dealloc that value and clear that ondispose entry */
|
||||
const mem = __allocCString(str);
|
||||
obj[m.key] = mem;
|
||||
__addOnDispose(obj, mem);
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
Prototype for all StructFactory instances (the constructors
|
||||
returned from StructBinder).
|
||||
*/
|
||||
const StructType = function ctor(structName, structInfo){
|
||||
if(arguments[2]!==rop){
|
||||
toss("Do not call the StructType constructor",
|
||||
"from client-level code.");
|
||||
}
|
||||
Object.defineProperties(this,{
|
||||
//isA: rop((v)=>v instanceof ctor),
|
||||
structName: rop(structName),
|
||||
structInfo: rop(structInfo)
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
Properties inherited by struct-type-specific StructType instances
|
||||
and (indirectly) concrete struct-type instances.
|
||||
*/
|
||||
StructType.prototype = Object.create(null, {
|
||||
dispose: rop(function(){__freeStruct(this.constructor, this)}),
|
||||
lookupMember: rop(function(memberName, tossIfNotFound=true){
|
||||
return __lookupMember(this.structInfo, memberName, tossIfNotFound);
|
||||
}),
|
||||
memberToJsString: rop(function(memberName){
|
||||
return __memberToJsString(this, memberName);
|
||||
}),
|
||||
memberIsString: rop(function(memberName, tossIfNotFound=true){
|
||||
return __memberIsString(this, memberName, tossIfNotFound);
|
||||
}),
|
||||
memberKey: __memberKeyProp,
|
||||
memberKeys: __structMemberKeys,
|
||||
memberSignature: rop(function(memberName, emscriptenFormat=false){
|
||||
return __memberSignature(this, memberName, emscriptenFormat);
|
||||
}),
|
||||
memoryDump: rop(__memoryDump),
|
||||
pointer: __ptrPropDescriptor,
|
||||
setMemberCString: rop(function(memberName, str){
|
||||
return __setMemberCString(this, memberName, str);
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
"Static" properties for StructType.
|
||||
*/
|
||||
Object.defineProperties(StructType, {
|
||||
allocCString: rop(__allocCString),
|
||||
instanceForPointer: rop((ptr)=>__ptrBacklinksGlobal[ptr]),
|
||||
isA: rop((v)=>v instanceof StructType),
|
||||
hasExternalPointer: rop((v)=>(v instanceof StructType) && !!v[xPtrPropName]),
|
||||
memberKey: __memberKeyProp
|
||||
});
|
||||
|
||||
const isNumericValue = (v)=>Number.isFinite(v) || (v instanceof (BigInt || Number));
|
||||
|
||||
/**
|
||||
Pass this a StructBinder-generated prototype, and the struct
|
||||
member description object. It will define property accessors for
|
||||
proto[memberKey] which read from/write to memory in
|
||||
this.pointer. It modifies descr to make certain downstream
|
||||
operations much simpler.
|
||||
*/
|
||||
const makeMemberWrapper = function f(ctor,name, descr){
|
||||
if(!f._){
|
||||
/*cache all available getters/setters/set-wrappers for
|
||||
direct reuse in each accessor function. */
|
||||
f._ = {getters: {}, setters: {}, sw:{}};
|
||||
const a = ['i','p','P','s','f','d','v()'];
|
||||
if(bigIntEnabled) a.push('j');
|
||||
a.forEach(function(v){
|
||||
//const ir = sigIR(v);
|
||||
f._.getters[v] = sigDVGetter(v) /* DataView[MethodName] values for GETTERS */;
|
||||
f._.setters[v] = sigDVSetter(v) /* DataView[MethodName] values for SETTERS */;
|
||||
f._.sw[v] = sigDVSetWrapper(v) /* BigInt or Number ctor to wrap around values
|
||||
for conversion */;
|
||||
});
|
||||
const rxSig1 = /^[ipPsjfd]$/,
|
||||
rxSig2 = /^[vipPsjfd]\([ipPsjfd]*\)$/;
|
||||
f.sigCheck = function(obj, name, key,sig){
|
||||
if(Object.prototype.hasOwnProperty.call(obj, key)){
|
||||
toss(obj.structName,'already has a property named',key+'.');
|
||||
}
|
||||
rxSig1.test(sig) || rxSig2.test(sig)
|
||||
|| toss("Malformed signature for",
|
||||
sPropName(obj.structName,name)+":",sig);
|
||||
};
|
||||
}
|
||||
const key = ctor.memberKey(name);
|
||||
f.sigCheck(ctor.prototype, name, key, descr.signature);
|
||||
descr.key = key;
|
||||
descr.name = name;
|
||||
const sizeOf = sigSizeof(descr.signature);
|
||||
const sigGlyph = sigLetter(descr.signature);
|
||||
const xPropName = sPropName(ctor.prototype.structName,key);
|
||||
const dbg = ctor.prototype.debugFlags.__flags;
|
||||
/*
|
||||
TODO?: set prototype of descr to an object which can set/fetch
|
||||
its prefered representation, e.g. conversion to string or mapped
|
||||
function. Advantage: we can avoid doing that via if/else if/else
|
||||
in the get/set methods.
|
||||
*/
|
||||
const prop = Object.create(null);
|
||||
prop.configurable = false;
|
||||
prop.enumerable = false;
|
||||
prop.get = function(){
|
||||
if(dbg.getter){
|
||||
log("debug.getter:",f._.getters[sigGlyph],"for", sigIR(sigGlyph),
|
||||
xPropName,'@', this.pointer,'+',descr.offset,'sz',sizeOf);
|
||||
}
|
||||
let rc = (
|
||||
new DataView(heap().buffer, this.pointer + descr.offset, sizeOf)
|
||||
)[f._.getters[sigGlyph]](0, isLittleEndian);
|
||||
if(dbg.getter) log("debug.getter:",xPropName,"result =",rc);
|
||||
if(rc && isAutoPtrSig(descr.signature)){
|
||||
rc = StructType.instanceForPointer(rc) || rc;
|
||||
if(dbg.getter) log("debug.getter:",xPropName,"resolved =",rc);
|
||||
}
|
||||
return rc;
|
||||
};
|
||||
if(descr.readOnly){
|
||||
prop.set = __propThrowOnSet(ctor.prototype.structName,key);
|
||||
}else{
|
||||
prop.set = function(v){
|
||||
if(dbg.setter){
|
||||
log("debug.setter:",f._.setters[sigGlyph],"for", sigIR(sigGlyph),
|
||||
xPropName,'@', this.pointer,'+',descr.offset,'sz',sizeOf, v);
|
||||
}
|
||||
if(!this.pointer){
|
||||
toss("Cannot set struct property on disposed instance.");
|
||||
}
|
||||
if(null===v) v = 0;
|
||||
else while(!isNumericValue(v)){
|
||||
if(isAutoPtrSig(descr.signature) && (v instanceof StructType)){
|
||||
// It's a struct instance: let's store its pointer value!
|
||||
v = v.pointer || 0;
|
||||
if(dbg.setter) log("debug.setter:",xPropName,"resolved to",v);
|
||||
break;
|
||||
}
|
||||
toss("Invalid value for pointer-type",xPropName+'.');
|
||||
}
|
||||
(
|
||||
new DataView(heap().buffer, this.pointer + descr.offset, sizeOf)
|
||||
)[f._.setters[sigGlyph]](0, f._.sw[sigGlyph](v), isLittleEndian);
|
||||
};
|
||||
}
|
||||
Object.defineProperty(ctor.prototype, key, prop);
|
||||
}/*makeMemberWrapper*/;
|
||||
|
||||
/**
|
||||
The main factory function which will be returned to the
|
||||
caller.
|
||||
*/
|
||||
const StructBinder = function StructBinder(structName, structInfo){
|
||||
if(1===arguments.length){
|
||||
structInfo = structName;
|
||||
structName = structInfo.name;
|
||||
}else if(!structInfo.name){
|
||||
structInfo.name = structName;
|
||||
}
|
||||
if(!structName) toss("Struct name is required.");
|
||||
let lastMember = false;
|
||||
Object.keys(structInfo.members).forEach((k)=>{
|
||||
const m = structInfo.members[k];
|
||||
if(!m.sizeof) toss(structName,"member",k,"is missing sizeof.");
|
||||
else if(0!==(m.sizeof%4)){
|
||||
toss(structName,"member",k,"sizeof is not aligned.");
|
||||
}
|
||||
else if(0!==(m.offset%4)){
|
||||
toss(structName,"member",k,"offset is not aligned.");
|
||||
}
|
||||
if(!lastMember || lastMember.offset < m.offset) lastMember = m;
|
||||
});
|
||||
if(!lastMember) toss("No member property descriptions found.");
|
||||
else if(structInfo.sizeof < lastMember.offset+lastMember.sizeof){
|
||||
toss("Invalid struct config:",structName,
|
||||
"max member offset ("+lastMember.offset+") ",
|
||||
"extends past end of struct (sizeof="+structInfo.sizeof+").");
|
||||
}
|
||||
const debugFlags = rop(SBF.__makeDebugFlags(StructBinder.debugFlags));
|
||||
/** Constructor for the StructCtor. */
|
||||
const StructCtor = function StructCtor(externalMemory){
|
||||
if(!(this instanceof StructCtor)){
|
||||
toss("The",structName,"constructor may only be called via 'new'.");
|
||||
}else if(arguments.length){
|
||||
if(externalMemory!==(externalMemory|0) || externalMemory<=0){
|
||||
toss("Invalid pointer value for",structName,"constructor.");
|
||||
}
|
||||
__allocStruct(StructCtor, this, externalMemory);
|
||||
}else{
|
||||
__allocStruct(StructCtor, this);
|
||||
}
|
||||
};
|
||||
Object.defineProperties(StructCtor,{
|
||||
debugFlags: debugFlags,
|
||||
disposeAll: rop(function(){
|
||||
const map = __ptrBacklinks.get(StructCtor);
|
||||
Object.keys(map).forEach(function(ptr){
|
||||
const b = map[ptr];
|
||||
if(b) __freeStruct(StructCtor, b, ptr);
|
||||
});
|
||||
__ptrBacklinks.set(StructCtor, Object.create(null));
|
||||
return StructCtor;
|
||||
}),
|
||||
instanceForPointer: rop(__instanceBacklinkFactory(StructCtor)),
|
||||
isA: rop((v)=>v instanceof StructCtor),
|
||||
memberKey: __memberKeyProp,
|
||||
memberKeys: __structMemberKeys,
|
||||
resolveToInstance: rop(function(v, throwIfNot=false){
|
||||
if(!(v instanceof StructCtor)){
|
||||
v = Number.isSafeInteger(v)
|
||||
? StructCtor.instanceForPointer(v) : undefined;
|
||||
}
|
||||
if(!v && throwIfNot) toss("Value is-not-a",StructCtor.structName);
|
||||
return v;
|
||||
}),
|
||||
methodInfoForKey: rop(function(mKey){
|
||||
}),
|
||||
structInfo: rop(structInfo),
|
||||
structName: rop(structName)
|
||||
});
|
||||
StructCtor.prototype = new StructType(structName, structInfo, rop);
|
||||
Object.defineProperties(StructCtor.prototype,{
|
||||
debugFlags: debugFlags,
|
||||
constructor: rop(StructCtor)
|
||||
/*if we assign StructCtor.prototype and don't do
|
||||
this then StructCtor!==instance.constructor!*/
|
||||
});
|
||||
Object.keys(structInfo.members).forEach(
|
||||
(name)=>makeMemberWrapper(StructCtor, name, structInfo.members[name])
|
||||
);
|
||||
return StructCtor;
|
||||
};
|
||||
StructBinder.instanceForPointer = StructType.instanceForPointer;
|
||||
StructBinder.StructType = StructType;
|
||||
StructBinder.config = config;
|
||||
StructBinder.allocCString = __allocCString;
|
||||
if(!StructBinder.debugFlags){
|
||||
StructBinder.debugFlags = SBF.__makeDebugFlags(SBF.debugFlags);
|
||||
}
|
||||
return StructBinder;
|
||||
}/*StructBinderFactory*/;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,178 @@
|
||||
#include <assert.h>
|
||||
#include <string.h> /* memset() */
|
||||
#include <stddef.h> /* offsetof() */
|
||||
#include <stdio.h> /* snprintf() */
|
||||
#include <stdint.h> /* int64_t */
|
||||
/*#include <stdlib.h>*/ /* malloc/free(), needed for emscripten exports. */
|
||||
extern void * malloc(size_t);
|
||||
extern void free(void *);
|
||||
|
||||
/*
|
||||
** 2022-06-25
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
***********************************************************************
|
||||
**
|
||||
** Utility functions for use with the emscripten/WASM bits. These
|
||||
** functions ARE NOT part of the sqlite3 public API. They are strictly
|
||||
** for internal use by the JS/WASM bindings.
|
||||
**
|
||||
** This file is intended to be WASM-compiled together with sqlite3.c,
|
||||
** e.g.:
|
||||
**
|
||||
** emcc ... sqlite3.c wasm_util.c
|
||||
*/
|
||||
|
||||
/*
|
||||
** Experimenting with output parameters.
|
||||
*/
|
||||
int jaccwabyt_test_intptr(int * p){
|
||||
if(1==((int)p)%3){
|
||||
/* kludge to get emscripten to export malloc() and free() */;
|
||||
free(malloc(0));
|
||||
}
|
||||
return *p = *p * 2;
|
||||
}
|
||||
int64_t jaccwabyt_test_int64_max(void){
|
||||
return (int64_t)0x7fffffffffffffff;
|
||||
}
|
||||
int64_t jaccwabyt_test_int64_min(void){
|
||||
return ~jaccwabyt_test_int64_max();
|
||||
}
|
||||
int64_t jaccwabyt_test_int64_times2(int64_t x){
|
||||
return x * 2;
|
||||
}
|
||||
|
||||
void jaccwabyt_test_int64_minmax(int64_t * min, int64_t *max){
|
||||
*max = jaccwabyt_test_int64_max();
|
||||
*min = jaccwabyt_test_int64_min();
|
||||
/*printf("minmax: min=%lld, max=%lld\n", *min, *max);*/
|
||||
}
|
||||
int64_t jaccwabyt_test_int64ptr(int64_t * p){
|
||||
/*printf("jaccwabyt_test_int64ptr( @%lld = 0x%llx )\n", (int64_t)p, *p);*/
|
||||
return *p = *p * 2;
|
||||
}
|
||||
|
||||
void jaccwabyt_test_stack_overflow(int recurse){
|
||||
if(recurse) jaccwabyt_test_stack_overflow(recurse);
|
||||
}
|
||||
|
||||
struct WasmTestStruct {
|
||||
int v4;
|
||||
void * ppV;
|
||||
const char * cstr;
|
||||
int64_t v8;
|
||||
void (*xFunc)(void*);
|
||||
};
|
||||
typedef struct WasmTestStruct WasmTestStruct;
|
||||
void jaccwabyt_test_struct(WasmTestStruct * s){
|
||||
if(s){
|
||||
s->v4 *= 2;
|
||||
s->v8 = s->v4 * 2;
|
||||
s->ppV = s;
|
||||
s->cstr = __FILE__;
|
||||
if(s->xFunc) s->xFunc(s);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** For testing the 'string-free' whwasmutil.xWrap() conversion. */
|
||||
char * jaccwabyt_test_str_hello(int fail){
|
||||
char * s = fail ? 0 : (char *)malloc(6);
|
||||
if(s){
|
||||
memcpy(s, "hello", 5);
|
||||
s[5] = 0;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
** Returns a NUL-terminated string containing a JSON-format metadata
|
||||
** regarding C structs, for use with the StructBinder API. The
|
||||
** returned memory is static and is only written to the first time
|
||||
** this is called.
|
||||
*/
|
||||
const char * jaccwabyt_test_ctype_json(void){
|
||||
static char strBuf[1024 * 8] = {0};
|
||||
int n = 0, structCount = 0, groupCount = 0;
|
||||
char * pos = &strBuf[1] /* skip first byte for now to help protect
|
||||
against a small race condition */;
|
||||
char const * const zEnd = pos + sizeof(strBuf);
|
||||
if(strBuf[0]) return strBuf;
|
||||
/* Leave first strBuf[0] at 0 until the end to help guard against a
|
||||
tiny race condition. If this is called twice concurrently, they
|
||||
might end up both writing to strBuf, but they'll both write the
|
||||
same thing, so that's okay. If we set byte 0 up front then the
|
||||
2nd instance might return a partially-populated string. */
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// First we need to build up our macro framework...
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Core output macros...
|
||||
#define lenCheck assert(pos < zEnd - 100)
|
||||
#define outf(format,...) \
|
||||
pos += snprintf(pos, ((size_t)(zEnd - pos)), format, __VA_ARGS__); \
|
||||
lenCheck
|
||||
#define out(TXT) outf("%s",TXT)
|
||||
#define CloseBrace(LEVEL) \
|
||||
assert(LEVEL<5); memset(pos, '}', LEVEL); pos+=LEVEL; lenCheck
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Macros for emitting StructBinder descriptions...
|
||||
#define StructBinder__(TYPE) \
|
||||
n = 0; \
|
||||
outf("%s{", (structCount++ ? ", " : "")); \
|
||||
out("\"name\": \"" # TYPE "\","); \
|
||||
outf("\"sizeof\": %d", (int)sizeof(TYPE)); \
|
||||
out(",\"members\": {");
|
||||
#define StructBinder_(T) StructBinder__(T)
|
||||
// ^^^ indirection needed to expand CurrentStruct
|
||||
#define StructBinder StructBinder_(CurrentStruct)
|
||||
#define _StructBinder CloseBrace(2)
|
||||
#define M(MEMBER,SIG) \
|
||||
outf("%s\"%s\": " \
|
||||
"{\"offset\":%d,\"sizeof\": %d,\"signature\":\"%s\"}", \
|
||||
(n++ ? ", " : ""), #MEMBER, \
|
||||
(int)offsetof(CurrentStruct,MEMBER), \
|
||||
(int)sizeof(((CurrentStruct*)0)->MEMBER), \
|
||||
SIG)
|
||||
// End of macros
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
out("\"structs\": ["); {
|
||||
|
||||
#define CurrentStruct WasmTestStruct
|
||||
StructBinder {
|
||||
M(v4,"i");
|
||||
M(cstr,"s");
|
||||
M(ppV,"p");
|
||||
M(v8,"j");
|
||||
M(xFunc,"v(p)");
|
||||
} _StructBinder;
|
||||
#undef CurrentStruct
|
||||
|
||||
} out( "]"/*structs*/);
|
||||
out("}"/*top-level object*/);
|
||||
*pos = 0;
|
||||
strBuf[0] = '{'/*end of the race-condition workaround*/;
|
||||
return strBuf;
|
||||
#undef DefGroup
|
||||
#undef Def
|
||||
#undef _DefGroup
|
||||
#undef StructBinder
|
||||
#undef StructBinder_
|
||||
#undef StructBinder__
|
||||
#undef M
|
||||
#undef _StructBinder
|
||||
#undef CurrentStruct
|
||||
#undef CloseBrace
|
||||
#undef out
|
||||
#undef outf
|
||||
#undef lenCheck
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
_jaccwabyt_test_intptr
|
||||
_jaccwabyt_test_int64ptr
|
||||
_jaccwabyt_test_int64_max
|
||||
_jaccwabyt_test_int64_min
|
||||
_jaccwabyt_test_int64_minmax
|
||||
_jaccwabyt_test_int64_times2
|
||||
_jaccwabyt_test_struct
|
||||
_jaccwabyt_test_ctype_json
|
||||
_jaccwabyt_test_stack_overflow
|
||||
_jaccwabyt_test_str_hello
|
||||
@@ -0,0 +1,34 @@
|
||||
<!doctype html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
||||
<link rel="stylesheet" href="common/emscripten.css"/>
|
||||
<link rel="stylesheet" href="common/testing.css"/>
|
||||
<title>sqlite3-api.js tests</title>
|
||||
</head>
|
||||
<body>
|
||||
<header id='titlebar'><span>sqlite3-api.js tests</span></header>
|
||||
<!-- emscripten bits -->
|
||||
<figure id="module-spinner">
|
||||
<div class="spinner"></div>
|
||||
<div class='center'><strong>Initializing app...</strong></div>
|
||||
<div class='center'>
|
||||
On a slow internet connection this may take a moment. If this
|
||||
message displays for "a long time", intialization may have
|
||||
failed and the JavaScript console may contain clues as to why.
|
||||
</div>
|
||||
</figure>
|
||||
<div class="emscripten" id="module-status">Downloading...</div>
|
||||
<div class="emscripten">
|
||||
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
|
||||
</div><!-- /emscripten bits -->
|
||||
<div>Most stuff on this page happens in the dev console.</div>
|
||||
<hr>
|
||||
<div id='test-output'></div>
|
||||
<script src="api/sqlite3.js"></script>
|
||||
<script src="common/SqliteTestUtil.js"></script>
|
||||
<script src="testing1.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,33 @@
|
||||
<!doctype html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
||||
<link rel="stylesheet" href="common/emscripten.css"/>
|
||||
<link rel="stylesheet" href="common/testing.css"/>
|
||||
<title>sqlite3-worker.js tests</title>
|
||||
</head>
|
||||
<body>
|
||||
<header id='titlebar'><span>sqlite3-worker.js tests</span></header>
|
||||
<!-- emscripten bits -->
|
||||
<figure id="module-spinner">
|
||||
<div class="spinner"></div>
|
||||
<div class='center'><strong>Initializing app...</strong></div>
|
||||
<div class='center'>
|
||||
On a slow internet connection this may take a moment. If this
|
||||
message displays for "a long time", intialization may have
|
||||
failed and the JavaScript console may contain clues as to why.
|
||||
</div>
|
||||
</figure>
|
||||
<div class="emscripten" id="module-status">Downloading...</div>
|
||||
<div class="emscripten">
|
||||
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
|
||||
</div><!-- /emscripten bits -->
|
||||
<div>Most stuff on this page happens in the dev console.</div>
|
||||
<hr>
|
||||
<div id='test-output'></div>
|
||||
<script src="common/SqliteTestUtil.js"></script>
|
||||
<script src="testing2.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
2022-05-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.
|
||||
|
||||
***********************************************************************
|
||||
|
||||
A basic test script for sqlite3-worker.js.
|
||||
*/
|
||||
'use strict';
|
||||
(function(){
|
||||
const T = self.SqliteTestUtil;
|
||||
const SW = new Worker("api/sqlite3-worker.js");
|
||||
const DbState = {
|
||||
id: undefined
|
||||
};
|
||||
const eOutput = document.querySelector('#test-output');
|
||||
const log = console.log.bind(console)
|
||||
const logHtml = function(cssClass,...args){
|
||||
log.apply(this, args);
|
||||
const ln = document.createElement('div');
|
||||
if(cssClass) ln.classList.add(cssClass);
|
||||
ln.append(document.createTextNode(args.join(' ')));
|
||||
eOutput.append(ln);
|
||||
};
|
||||
const warn = console.warn.bind(console);
|
||||
const error = console.error.bind(console);
|
||||
const toss = (...args)=>{throw new Error(args.join(' '))};
|
||||
/** Posts a worker message as {type:type, data:data}. */
|
||||
const wMsg = function(type,data){
|
||||
log("Posting message to worker dbId="+(DbState.id||'default')+':',data);
|
||||
SW.postMessage({
|
||||
type,
|
||||
dbId: DbState.id,
|
||||
data,
|
||||
departureTime: performance.now()
|
||||
});
|
||||
return SW;
|
||||
};
|
||||
|
||||
SW.onerror = function(event){
|
||||
error("onerror",event);
|
||||
};
|
||||
|
||||
let startTime;
|
||||
|
||||
/**
|
||||
A queue for callbacks which are to be run in response to async
|
||||
DB commands. See the notes in runTests() for why we need
|
||||
this. The event-handling plumbing of this file requires that
|
||||
any DB command which includes a `messageId` property also have
|
||||
a queued callback entry, as the existence of that property in
|
||||
response payloads is how it knows whether or not to shift an
|
||||
entry off of the queue.
|
||||
*/
|
||||
const MsgHandlerQueue = {
|
||||
queue: [],
|
||||
id: 0,
|
||||
push: function(type,callback){
|
||||
this.queue.push(callback);
|
||||
return type + '-' + (++this.id);
|
||||
},
|
||||
shift: function(){
|
||||
return this.queue.shift();
|
||||
}
|
||||
};
|
||||
|
||||
const testCount = ()=>{
|
||||
logHtml("","Total test count:",T.counter+". Total time =",(performance.now() - startTime),"ms");
|
||||
};
|
||||
|
||||
const logEventResult = function(evd){
|
||||
logHtml(evd.errorClass ? 'error' : '',
|
||||
"runOneTest",evd.messageId,"Worker time =",
|
||||
(evd.workerRespondTime - evd.workerReceivedTime),"ms.",
|
||||
"Round-trip event time =",
|
||||
(performance.now() - evd.departureTime),"ms.",
|
||||
(evd.errorClass ? evd.message : "")
|
||||
);
|
||||
};
|
||||
|
||||
const runOneTest = function(eventType, eventData, callback){
|
||||
T.assert(eventData && 'object'===typeof eventData);
|
||||
/* ^^^ that is for the testing and messageId-related code, not
|
||||
a hard requirement of all of the Worker-exposed APIs. */
|
||||
eventData.messageId = MsgHandlerQueue.push(eventType,function(ev){
|
||||
logEventResult(ev.data);
|
||||
if(callback instanceof Function){
|
||||
callback(ev);
|
||||
testCount();
|
||||
}
|
||||
});
|
||||
wMsg(eventType, eventData);
|
||||
};
|
||||
|
||||
/** Methods which map directly to onmessage() event.type keys.
|
||||
They get passed the inbound event.data. */
|
||||
const dbMsgHandler = {
|
||||
open: function(ev){
|
||||
DbState.id = ev.dbId;
|
||||
log("open result",ev.data);
|
||||
},
|
||||
exec: function(ev){
|
||||
log("exec result",ev.data);
|
||||
},
|
||||
export: function(ev){
|
||||
log("export result",ev.data);
|
||||
},
|
||||
error: function(ev){
|
||||
error("ERROR from the worker:",ev.data);
|
||||
logEventResult(ev.data);
|
||||
},
|
||||
resultRowTest1: function f(ev){
|
||||
if(undefined === f.counter) f.counter = 0;
|
||||
if(ev.data) ++f.counter;
|
||||
//log("exec() result row:",ev.data);
|
||||
T.assert(null===ev.data || 'number' === typeof ev.data.b);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
"The problem" now is that the test results are async. We
|
||||
know, however, that the messages posted to the worker will
|
||||
be processed in the order they are passed to it, so we can
|
||||
create a queue of callbacks to handle them. The problem
|
||||
with that approach is that it's not error-handling
|
||||
friendly, in that an error can cause us to bypass a result
|
||||
handler queue entry. We have to perform some extra
|
||||
acrobatics to account for that.
|
||||
|
||||
Problem #2 is that we cannot simply start posting events: we
|
||||
first have to post an 'open' event, wait for it to respond, and
|
||||
collect its db ID before continuing. If we don't wait, we may
|
||||
well fire off 10+ messages before the open actually responds.
|
||||
*/
|
||||
const runTests2 = function(){
|
||||
const mustNotReach = ()=>{
|
||||
throw new Error("This is not supposed to be reached.");
|
||||
};
|
||||
runOneTest('exec',{
|
||||
sql: ["create table t(a,b)",
|
||||
"insert into t(a,b) values(1,2),(3,4),(5,6)"
|
||||
].join(';'),
|
||||
multi: true,
|
||||
resultRows: [], columnNames: []
|
||||
}, function(ev){
|
||||
ev = ev.data;
|
||||
T.assert(0===ev.resultRows.length)
|
||||
.assert(0===ev.columnNames.length);
|
||||
});
|
||||
runOneTest('exec',{
|
||||
sql: 'select a a, b b from t order by a',
|
||||
resultRows: [], columnNames: [],
|
||||
}, function(ev){
|
||||
ev = ev.data;
|
||||
T.assert(3===ev.resultRows.length)
|
||||
.assert(1===ev.resultRows[0][0])
|
||||
.assert(6===ev.resultRows[2][1])
|
||||
.assert(2===ev.columnNames.length)
|
||||
.assert('b'===ev.columnNames[1]);
|
||||
});
|
||||
runOneTest('exec',{
|
||||
sql: 'select a a, b b from t order by a',
|
||||
resultRows: [], columnNames: [],
|
||||
rowMode: 'object'
|
||||
}, function(ev){
|
||||
ev = ev.data;
|
||||
T.assert(3===ev.resultRows.length)
|
||||
.assert(1===ev.resultRows[0].a)
|
||||
.assert(6===ev.resultRows[2].b)
|
||||
});
|
||||
runOneTest('exec',{sql:'intentional_error'}, mustNotReach);
|
||||
// Ensure that the message-handler queue survives ^^^ that error...
|
||||
runOneTest('exec',{
|
||||
sql:'select 1',
|
||||
resultRows: [],
|
||||
//rowMode: 'array', // array is the default in the Worker interface
|
||||
}, function(ev){
|
||||
ev = ev.data;
|
||||
T.assert(1 === ev.resultRows.length)
|
||||
.assert(1 === ev.resultRows[0][0]);
|
||||
});
|
||||
runOneTest('exec',{
|
||||
sql: 'select a a, b b from t order by a',
|
||||
callback: 'resultRowTest1',
|
||||
rowMode: 'object'
|
||||
}, function(ev){
|
||||
T.assert(3===dbMsgHandler.resultRowTest1.counter);
|
||||
dbMsgHandler.resultRowTest1.counter = 0;
|
||||
});
|
||||
runOneTest('exec',{
|
||||
multi: true,
|
||||
sql:[
|
||||
'pragma foreign_keys=0;',
|
||||
// ^^^ arbitrary query with no result columns
|
||||
'select a, b from t order by a desc; select a from t;'
|
||||
// multi-exec only honors results from the first
|
||||
// statement with result columns (regardless of whether)
|
||||
// it has any rows).
|
||||
],
|
||||
rowMode: 1,
|
||||
resultRows: []
|
||||
},function(ev){
|
||||
const rows = ev.data.resultRows;
|
||||
T.assert(3===rows.length).
|
||||
assert(6===rows[0]);
|
||||
});
|
||||
runOneTest('exec',{sql: 'delete from t where a>3'});
|
||||
runOneTest('exec',{
|
||||
sql: 'select count(a) from t',
|
||||
resultRows: []
|
||||
},function(ev){
|
||||
ev = ev.data;
|
||||
T.assert(1===ev.resultRows.length)
|
||||
.assert(2===ev.resultRows[0][0]);
|
||||
});
|
||||
if(0){
|
||||
// export requires reimpl. for portability reasons.
|
||||
runOneTest('export',{}, function(ev){
|
||||
ev = ev.data;
|
||||
T.assert('string' === typeof ev.filename)
|
||||
.assert(ev.buffer instanceof Uint8Array)
|
||||
.assert(ev.buffer.length > 1024)
|
||||
.assert('application/x-sqlite3' === ev.mimetype);
|
||||
});
|
||||
}
|
||||
/***** close() tests must come last. *****/
|
||||
runOneTest('close',{unlink:true},function(ev){
|
||||
ev = ev.data;
|
||||
T.assert('string' === typeof ev.filename);
|
||||
});
|
||||
runOneTest('close',{unlink:true},function(ev){
|
||||
ev = ev.data;
|
||||
T.assert(undefined === ev.filename);
|
||||
});
|
||||
};
|
||||
|
||||
const runTests = function(){
|
||||
/**
|
||||
Design decision time: all remaining tests depend on the 'open'
|
||||
command having succeeded. In order to support multiple DBs, the
|
||||
upcoming commands ostensibly have to know the ID of the DB they
|
||||
want to talk to. We have two choices:
|
||||
|
||||
1) We run 'open' and wait for its response, which contains the
|
||||
db id.
|
||||
|
||||
2) We have the Worker automatically use the current "default
|
||||
db" (the one which was most recently opened) if no db id is
|
||||
provided in the message. When we do this, the main thread may
|
||||
well fire off _all_ of the test messages before the 'open'
|
||||
actually responds, but because the messages are handled on a
|
||||
FIFO basis, those after the initial 'open' will pick up the
|
||||
"default" db. However, if the open fails, then all pending
|
||||
messages (until next next 'open', at least) except for 'close'
|
||||
will fail and we have no way of cancelling them once they've
|
||||
been posted to the worker.
|
||||
|
||||
We currently do (2) because (A) it's certainly the most
|
||||
client-friendly thing to do and (B) it seems likely that most
|
||||
apps using this API will only have a single db to work with so
|
||||
won't need to juggle multiple DB ids. If we revert to (1) then
|
||||
the following call to runTests2() needs to be moved into the
|
||||
callback function of the runOneTest() check for the 'open'
|
||||
command. Note, also, that using approach (2) does not keep the
|
||||
user from instead using approach (1), noting that doing so
|
||||
requires explicit handling of the 'open' message to account for
|
||||
it.
|
||||
*/
|
||||
const waitForOpen = 1,
|
||||
simulateOpenError = 0 /* if true, the remaining tests will
|
||||
all barf if waitForOpen is
|
||||
false. */;
|
||||
logHtml('',
|
||||
"Sending 'open' message and",(waitForOpen ? "" : "NOT ")+
|
||||
"waiting for its response before continuing.");
|
||||
startTime = performance.now();
|
||||
runOneTest('open', {
|
||||
filename:'testing2.sqlite3',
|
||||
simulateError: simulateOpenError
|
||||
}, function(ev){
|
||||
//log("open result",ev);
|
||||
T.assert('testing2.sqlite3'===ev.data.filename)
|
||||
.assert(ev.data.dbId)
|
||||
.assert(ev.data.messageId);
|
||||
DbState.id = ev.data.dbId;
|
||||
if(waitForOpen) setTimeout(runTests2, 0);
|
||||
});
|
||||
if(!waitForOpen) runTests2();
|
||||
};
|
||||
|
||||
SW.onmessage = function(ev){
|
||||
if(!ev.data || 'object'!==typeof ev.data){
|
||||
warn("Unknown sqlite3-worker message type:",ev);
|
||||
return;
|
||||
}
|
||||
ev = ev.data/*expecting a nested object*/;
|
||||
//log("main window onmessage:",ev);
|
||||
if(ev.data && ev.data.messageId){
|
||||
/* We're expecting a queued-up callback handler. */
|
||||
const f = MsgHandlerQueue.shift();
|
||||
if('error'===ev.type){
|
||||
dbMsgHandler.error(ev);
|
||||
return;
|
||||
}
|
||||
T.assert(f instanceof Function);
|
||||
f(ev);
|
||||
return;
|
||||
}
|
||||
switch(ev.type){
|
||||
case 'sqlite3-api':
|
||||
switch(ev.data){
|
||||
case 'worker-ready':
|
||||
log("Message:",ev);
|
||||
self.sqlite3TestModule.setStatus(null);
|
||||
runTests();
|
||||
return;
|
||||
default:
|
||||
warn("Unknown sqlite3-api message type:",ev);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
if(dbMsgHandler.hasOwnProperty(ev.type)){
|
||||
try{dbMsgHandler[ev.type](ev);}
|
||||
catch(err){
|
||||
error("Exception while handling db result message",
|
||||
ev,":",err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
warn("Unknown sqlite3-api message type:",ev);
|
||||
}
|
||||
};
|
||||
log("Init complete, but async init bits may still be running.");
|
||||
})();
|
||||
@@ -423,6 +423,7 @@ TESTSRC2 = \
|
||||
$(TOP)/src/select.c \
|
||||
$(TOP)/src/threads.c \
|
||||
$(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/treeview.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vdbeapi.c \
|
||||
@@ -546,6 +547,9 @@ FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
FUZZSRC += $(TOP)/test/fuzzcheck.c
|
||||
FUZZSRC += $(TOP)/test/ossfuzz.c
|
||||
FUZZSRC += $(TOP)/test/fuzzinvariants.c
|
||||
DBFUZZ_OPT =
|
||||
KV_OPT = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ
|
||||
ST_OPT = -DSQLITE_THREADSAFE=0
|
||||
@@ -604,10 +608,10 @@ dbfuzz2$(EXE): $(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
|
||||
$(TCCX) -I. -g -O0 -DSTANDALONE -o dbfuzz2$(EXE) \
|
||||
$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS) $(THREADLIB)
|
||||
|
||||
fuzzcheck$(EXE): $(TOP)/test/fuzzcheck.c sqlite3.c sqlite3.h $(TOP)/test/ossfuzz.c
|
||||
fuzzcheck$(EXE): $(FUZZSRC) sqlite3.c sqlite3.h
|
||||
$(TCCX) -o fuzzcheck$(EXE) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
|
||||
-DSQLITE_ENABLE_MEMSYS5 $(FUZZCHECK_OPT) -DSQLITE_OSS_FUZZ \
|
||||
$(TOP)/test/fuzzcheck.c $(TOP)/test/ossfuzz.c sqlite3.c $(TLIBS) $(THREADLIB)
|
||||
$(FUZZSRC) sqlite3.c $(TLIBS) $(THREADLIB)
|
||||
|
||||
ossshell$(EXE): $(TOP)/test/ossfuzz.c $(TOP)/test/ossshell.c sqlite3.c sqlite3.h
|
||||
$(TCCX) -o ossshell$(EXE) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
|
||||
@@ -954,6 +958,12 @@ valgrindfuzz: fuzzcheck$(EXE) $(FUZZDATA) sessionfuzz$(EXE) $(TOP)/test/sessionf
|
||||
tcltest: ./testfixture$(EXE)
|
||||
./testfixture$(EXE) $(TOP)/test/veryquick.test $(TESTOPTS)
|
||||
|
||||
# Runs all the same tests cases as the "tcltest" target but uses
|
||||
# the testrunner.tcl script to run them in multiple cores
|
||||
# concurrently.
|
||||
testrunner: testfixture$(EXE)
|
||||
./testfixture$(EXE) $(TOP)/test/testrunner.tcl
|
||||
|
||||
# A very quick test using only testfixture and omitting all the slower
|
||||
# tests. Designed to run in under 3 minutes on a workstation.
|
||||
#
|
||||
@@ -964,6 +974,7 @@ quicktest: ./testfixture$(EXE)
|
||||
# and fuzz tests, and sqlite3_analyzer and sqldiff tests.
|
||||
test: fuzztest sourcetest $(TESTPROGS) tcltest
|
||||
|
||||
|
||||
# Run a test using valgrind. This can take a really long time
|
||||
# because valgrind is so much slower than a native machine.
|
||||
#
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
0c5be14aac07222b9cd2404ae485b6587f8cb2899e776bc45f1f1117bdd7e9b7
|
||||
c8d77f398099f357bed0aab10f066c6b26ba4ad8ffd68bb7b4465c0c4999599b
|
||||
+45
-28
@@ -858,11 +858,10 @@ static void unmapColumnIdlistNames(
|
||||
Parse *pParse,
|
||||
const IdList *pIdList
|
||||
){
|
||||
if( pIdList ){
|
||||
int ii;
|
||||
for(ii=0; ii<pIdList->nId; ii++){
|
||||
sqlite3RenameTokenRemap(pParse, 0, (const void*)pIdList->a[ii].zName);
|
||||
}
|
||||
int ii;
|
||||
assert( pIdList!=0 );
|
||||
for(ii=0; ii<pIdList->nId; ii++){
|
||||
sqlite3RenameTokenRemap(pParse, 0, (const void*)pIdList->a[ii].zName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -881,7 +880,7 @@ static int renameUnmapSelectCb(Walker *pWalker, Select *p){
|
||||
if( ALWAYS(p->pEList) ){
|
||||
ExprList *pList = p->pEList;
|
||||
for(i=0; i<pList->nExpr; i++){
|
||||
if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
|
||||
if( pList->a[i].zEName && pList->a[i].fg.eEName==ENAME_NAME ){
|
||||
sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
|
||||
}
|
||||
}
|
||||
@@ -890,8 +889,11 @@ static int renameUnmapSelectCb(Walker *pWalker, Select *p){
|
||||
SrcList *pSrc = p->pSrc;
|
||||
for(i=0; i<pSrc->nSrc; i++){
|
||||
sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
|
||||
sqlite3WalkExpr(pWalker, pSrc->a[i].pOn);
|
||||
unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing);
|
||||
if( pSrc->a[i].fg.isUsing==0 ){
|
||||
sqlite3WalkExpr(pWalker, pSrc->a[i].u3.pOn);
|
||||
}else{
|
||||
unmapColumnIdlistNames(pParse, pSrc->a[i].u3.pUsing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -927,7 +929,7 @@ void sqlite3RenameExprlistUnmap(Parse *pParse, ExprList *pEList){
|
||||
sWalker.xExprCallback = renameUnmapExprCb;
|
||||
sqlite3WalkExprList(&sWalker, pEList);
|
||||
for(i=0; i<pEList->nExpr; i++){
|
||||
if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
|
||||
if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) ){
|
||||
sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
|
||||
}
|
||||
}
|
||||
@@ -1085,7 +1087,7 @@ static void renameColumnElistNames(
|
||||
int i;
|
||||
for(i=0; i<pEList->nExpr; i++){
|
||||
const char *zName = pEList->a[i].zEName;
|
||||
if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
|
||||
if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME)
|
||||
&& ALWAYS(zName!=0)
|
||||
&& 0==sqlite3_stricmp(zName, zOld)
|
||||
){
|
||||
@@ -1315,27 +1317,33 @@ static int renameResolveTrigger(Parse *pParse){
|
||||
if( rc==SQLITE_OK && pStep->zTarget ){
|
||||
SrcList *pSrc = sqlite3TriggerStepSrc(pParse, pStep);
|
||||
if( pSrc ){
|
||||
int i;
|
||||
for(i=0; i<pSrc->nSrc && rc==SQLITE_OK; i++){
|
||||
SrcItem *p = &pSrc->a[i];
|
||||
p->iCursor = pParse->nTab++;
|
||||
if( p->pSelect ){
|
||||
sqlite3SelectPrep(pParse, p->pSelect, 0);
|
||||
sqlite3ExpandSubquery(pParse, p);
|
||||
assert( i>0 );
|
||||
assert( pStep->pFrom->a[i-1].pSelect );
|
||||
sqlite3SelectPrep(pParse, pStep->pFrom->a[i-1].pSelect, 0);
|
||||
}else{
|
||||
p->pTab = sqlite3LocateTableItem(pParse, 0, p);
|
||||
if( p->pTab==0 ){
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
p->pTab->nTabRef++;
|
||||
rc = sqlite3ViewGetColumnNames(pParse, p->pTab);
|
||||
Select *pSel = sqlite3SelectNew(
|
||||
pParse, pStep->pExprList, pSrc, 0, 0, 0, 0, 0, 0
|
||||
);
|
||||
if( pSel==0 ){
|
||||
pStep->pExprList = 0;
|
||||
pSrc = 0;
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
sqlite3SelectPrep(pParse, pSel, 0);
|
||||
rc = pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
|
||||
assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
|
||||
assert( pSrc==pSel->pSrc );
|
||||
if( pStep->pExprList ) pSel->pEList = 0;
|
||||
pSel->pSrc = 0;
|
||||
sqlite3SelectDelete(db, pSel);
|
||||
}
|
||||
if( pStep->pFrom ){
|
||||
int i;
|
||||
for(i=0; i<pStep->pFrom->nSrc && rc==SQLITE_OK; i++){
|
||||
SrcItem *p = &pStep->pFrom->a[i];
|
||||
if( p->pSelect ){
|
||||
sqlite3SelectPrep(pParse, p->pSelect, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE_OK && db->mallocFailed ){
|
||||
|
||||
if( db->mallocFailed ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
sNC.pSrcList = pSrc;
|
||||
@@ -1787,6 +1795,15 @@ static void renameTableFunc(
|
||||
if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
|
||||
renameTokenFind(&sParse, &sCtx, pStep->zTarget);
|
||||
}
|
||||
if( pStep->pFrom ){
|
||||
int i;
|
||||
for(i=0; i<pStep->pFrom->nSrc; i++){
|
||||
SrcItem *pItem = &pStep->pFrom->a[i];
|
||||
if( 0==sqlite3_stricmp(pItem->zName, zOld) ){
|
||||
renameTokenFind(&sParse, &sCtx, pItem->zName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -847,9 +847,14 @@ static void statGet(
|
||||
** * "WHERE a=? AND b=?" matches 2 rows.
|
||||
**
|
||||
** If D is the count of distinct values and K is the total number of
|
||||
** rows, then each estimate is computed as:
|
||||
** rows, then each estimate is usually computed as:
|
||||
**
|
||||
** I = (K+D-1)/D
|
||||
**
|
||||
** In other words, I is K/D rounded up to the next whole integer.
|
||||
** However, if I is between 1.0 and 1.1 (in other words if I is
|
||||
** close to 1.0 but just a little larger) then do not round up but
|
||||
** instead keep the I value at 1.0.
|
||||
*/
|
||||
sqlite3_str sStat; /* Text of the constructed "stat" line */
|
||||
int i; /* Loop counter */
|
||||
@@ -860,6 +865,7 @@ static void statGet(
|
||||
for(i=0; i<p->nKeyCol; i++){
|
||||
u64 nDistinct = p->current.anDLt[i] + 1;
|
||||
u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
|
||||
if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
|
||||
sqlite3_str_appendf(&sStat, " %llu", iVal);
|
||||
assert( p->current.anEq[i] );
|
||||
}
|
||||
|
||||
+5
-1
@@ -480,7 +480,11 @@ static int fixSelectCb(Walker *p, Select *pSelect){
|
||||
pItem->fg.fromDDL = 1;
|
||||
}
|
||||
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
|
||||
if( sqlite3WalkExpr(&pFix->w, pList->a[i].pOn) ) return WRC_Abort;
|
||||
if( pList->a[i].fg.isUsing==0
|
||||
&& sqlite3WalkExpr(&pFix->w, pList->a[i].u3.pOn)
|
||||
){
|
||||
return WRC_Abort;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if( pSelect->pWith ){
|
||||
|
||||
@@ -252,6 +252,7 @@ int sqlite3BtreeHoldsAllMutexes(sqlite3 *db){
|
||||
int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
|
||||
Btree *p;
|
||||
assert( db!=0 );
|
||||
if( db->pVfs==0 && db->nDb==0 ) return 1;
|
||||
if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
if( !sqlite3_mutex_held(db->mutex) ) return 0;
|
||||
|
||||
+138
-121
@@ -1513,8 +1513,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
|
||||
assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
|
||||
assert( pPage->nOverflow==0 );
|
||||
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
|
||||
temp = 0;
|
||||
src = data = pPage->aData;
|
||||
data = pPage->aData;
|
||||
hdr = pPage->hdrOffset;
|
||||
cellOffset = pPage->cellOffset;
|
||||
nCell = pPage->nCell;
|
||||
@@ -1548,7 +1547,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);
|
||||
}
|
||||
|
||||
@@ -1568,39 +1567,38 @@ 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];
|
||||
pc = get2byte(pAddr);
|
||||
testcase( pc==iCellFirst );
|
||||
testcase( pc==iCellLast );
|
||||
/* These conditions have already been verified in btreeInitPage()
|
||||
** if PRAGMA cell_size_check=ON.
|
||||
*/
|
||||
if( pc<iCellStart || pc>iCellLast ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
if( nCell>0 ){
|
||||
temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
|
||||
memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
|
||||
src = temp;
|
||||
for(i=0; i<nCell; i++){
|
||||
u8 *pAddr; /* The i-th cell pointer */
|
||||
pAddr = &data[cellOffset + i*2];
|
||||
pc = get2byte(pAddr);
|
||||
testcase( pc==iCellFirst );
|
||||
testcase( pc==iCellLast );
|
||||
/* These conditions have already been verified in btreeInitPage()
|
||||
** if PRAGMA cell_size_check=ON.
|
||||
*/
|
||||
if( pc<iCellStart || pc>iCellLast ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
assert( pc>=iCellStart && pc<=iCellLast );
|
||||
size = pPage->xCellSize(pPage, &src[pc]);
|
||||
cbrk -= size;
|
||||
if( cbrk<iCellStart || pc+size>usableSize ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
assert( cbrk+size<=usableSize && cbrk>=iCellStart );
|
||||
testcase( cbrk+size==usableSize );
|
||||
testcase( pc+size==usableSize );
|
||||
put2byte(pAddr, cbrk);
|
||||
memcpy(&data[cbrk], &src[pc], size);
|
||||
}
|
||||
assert( pc>=iCellStart && pc<=iCellLast );
|
||||
size = pPage->xCellSize(pPage, &src[pc]);
|
||||
cbrk -= size;
|
||||
if( cbrk<iCellStart || pc+size>usableSize ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
assert( cbrk+size<=usableSize && cbrk>=iCellStart );
|
||||
testcase( cbrk+size==usableSize );
|
||||
testcase( pc+size==usableSize );
|
||||
put2byte(pAddr, cbrk);
|
||||
if( temp==0 ){
|
||||
if( cbrk==pc ) continue;
|
||||
temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
|
||||
memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
|
||||
src = temp;
|
||||
}
|
||||
memcpy(&data[cbrk], &src[pc], size);
|
||||
}
|
||||
data[hdr+7] = 0;
|
||||
|
||||
defragment_out:
|
||||
defragment_out:
|
||||
assert( pPage->nFree>=0 );
|
||||
if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
@@ -1657,6 +1655,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
|
||||
** fragmented bytes within the page. */
|
||||
memcpy(&aData[iAddr], &aData[pc], 2);
|
||||
aData[hdr+7] += (u8)x;
|
||||
testcase( pc+x>maxPC );
|
||||
return &aData[pc];
|
||||
}else if( x+pc > maxPC ){
|
||||
/* This slot extends off the end of the usable part of the page */
|
||||
*pRc = SQLITE_CORRUPT_PAGE(pPg);
|
||||
@@ -1671,9 +1671,9 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
|
||||
iAddr = pc;
|
||||
pTmp = &aData[pc];
|
||||
pc = get2byte(pTmp);
|
||||
if( pc<=iAddr+size ){
|
||||
if( pc<=iAddr ){
|
||||
if( pc ){
|
||||
/* The next slot in the chain is not past the end of the current slot */
|
||||
/* The next slot in the chain comes before the current slot */
|
||||
*pRc = SQLITE_CORRUPT_PAGE(pPg);
|
||||
}
|
||||
return 0;
|
||||
@@ -1825,7 +1825,7 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
|
||||
iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
|
||||
}else{
|
||||
while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
|
||||
if( iFreeBlk<iPtr+4 ){
|
||||
if( iFreeBlk<=iPtr ){
|
||||
if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
|
||||
return SQLITE_CORRUPT_PAGE(pPage);
|
||||
}
|
||||
@@ -2307,9 +2307,7 @@ getAndInitPage_error1:
|
||||
pCur->pPage = pCur->apPage[pCur->iPage];
|
||||
}
|
||||
testcase( pgno==0 );
|
||||
assert( pgno!=0 || rc==SQLITE_CORRUPT
|
||||
|| rc==SQLITE_IOERR_NOMEM
|
||||
|| rc==SQLITE_NOMEM );
|
||||
assert( pgno!=0 || rc!=SQLITE_OK );
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3931,12 +3929,17 @@ static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){
|
||||
}
|
||||
do {
|
||||
MemPage *pFreePg;
|
||||
Pgno dbSize = btreePagecount(pBt);
|
||||
rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iNear, eMode);
|
||||
if( rc!=SQLITE_OK ){
|
||||
releasePage(pLastPg);
|
||||
return rc;
|
||||
}
|
||||
releasePage(pFreePg);
|
||||
if( iFreePg>dbSize ){
|
||||
releasePage(pLastPg);
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
}while( bCommit && iFreePg>nFin );
|
||||
assert( iFreePg<iLastPg );
|
||||
|
||||
@@ -5246,8 +5249,6 @@ const void *sqlite3BtreePayloadFetch(BtCursor *pCur, u32 *pAmt){
|
||||
** vice-versa).
|
||||
*/
|
||||
static int moveToChild(BtCursor *pCur, u32 newPgno){
|
||||
BtShared *pBt = pCur->pBt;
|
||||
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
|
||||
@@ -5261,7 +5262,8 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){
|
||||
pCur->apPage[pCur->iPage] = pCur->pPage;
|
||||
pCur->ix = 0;
|
||||
pCur->iPage++;
|
||||
return getAndInitPage(pBt, newPgno, &pCur->pPage, pCur, pCur->curPagerFlags);
|
||||
return getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur,
|
||||
pCur->curPagerFlags);
|
||||
}
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
@@ -5367,7 +5369,7 @@ static int moveToRoot(BtCursor *pCur){
|
||||
}
|
||||
sqlite3BtreeClearCursor(pCur);
|
||||
}
|
||||
rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
|
||||
rc = getAndInitPage(pCur->pBt, pCur->pgnoRoot, &pCur->pPage,
|
||||
0, pCur->curPagerFlags);
|
||||
if( rc!=SQLITE_OK ){
|
||||
pCur->eState = CURSOR_INVALID;
|
||||
@@ -5840,6 +5842,9 @@ int sqlite3BtreeIndexMoveto(
|
||||
&& pIdxKey->errCode==SQLITE_OK
|
||||
){
|
||||
pCur->curFlags &= ~BTCF_ValidOvfl;
|
||||
if( !pCur->pPage->isInit ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
goto bypass_moveto_root; /* Start search on the current page */
|
||||
}
|
||||
pIdxKey->errCode = SQLITE_OK;
|
||||
@@ -5967,7 +5972,7 @@ bypass_moveto_root:
|
||||
assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
|
||||
assert( pPage->isInit );
|
||||
if( pPage->leaf ){
|
||||
assert( pCur->ix<pCur->pPage->nCell );
|
||||
assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
|
||||
pCur->ix = (u16)idx;
|
||||
*pRes = c;
|
||||
rc = SQLITE_OK;
|
||||
@@ -6072,14 +6077,7 @@ static SQLITE_NOINLINE int btreeNext(BtCursor *pCur){
|
||||
|
||||
pPage = pCur->pPage;
|
||||
idx = ++pCur->ix;
|
||||
if( !pPage->isInit || sqlite3FaultSim(412) ){
|
||||
/* The only known way for this to happen is for there to be a
|
||||
** recursive SQL function that does a DELETE operation as part of a
|
||||
** SELECT which deletes content out from under an active cursor
|
||||
** in a corrupt database file where the table being DELETE-ed from
|
||||
** has pages in common with the table being queried. See TH3
|
||||
** module cov1/btree78.test testcase 220 (2018-06-08) for an
|
||||
** example. */
|
||||
if( NEVER(!pPage->isInit) || sqlite3FaultSim(412) ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
|
||||
@@ -7005,12 +7003,6 @@ static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
|
||||
assert( pPage->pBt->usableSize > (u32)(ptr-data) );
|
||||
pc = get2byte(ptr);
|
||||
hdr = pPage->hdrOffset;
|
||||
#if 0 /* Not required. Omit for efficiency */
|
||||
if( pc<hdr+pPage->nCell*2 ){
|
||||
*pRC = SQLITE_CORRUPT_BKPT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
testcase( pc==(u32)get2byte(&data[hdr+5]) );
|
||||
testcase( pc+sz==pPage->pBt->usableSize );
|
||||
if( pc+sz > pPage->pBt->usableSize ){
|
||||
@@ -7894,8 +7886,6 @@ static int balance_nonroot(
|
||||
Pgno pgno; /* Temp var to store a page number in */
|
||||
u8 abDone[NB+2]; /* True after i'th new page is populated */
|
||||
Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
|
||||
Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */
|
||||
u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */
|
||||
CellArray b; /* Parsed information on cells being balanced */
|
||||
|
||||
memset(abDone, 0, sizeof(abDone));
|
||||
@@ -8319,42 +8309,39 @@ static int balance_nonroot(
|
||||
** of the table is closer to a linear scan through the file. That in turn
|
||||
** helps the operating system to deliver pages from the disk more rapidly.
|
||||
**
|
||||
** An O(n^2) insertion sort algorithm is used, but since n is never more
|
||||
** than (NB+2) (a small constant), that should not be a problem.
|
||||
** An O(N*N) sort algorithm is used, but since N is never more than NB+2
|
||||
** (5), that is not a performance concern.
|
||||
**
|
||||
** When NB==3, this one optimization makes the database about 25% faster
|
||||
** for large insertions and deletions.
|
||||
*/
|
||||
for(i=0; i<nNew; i++){
|
||||
aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
|
||||
aPgFlags[i] = apNew[i]->pDbPage->flags;
|
||||
for(j=0; j<i; j++){
|
||||
if( NEVER(aPgno[j]==aPgno[i]) ){
|
||||
/* This branch is taken if the set of sibling pages somehow contains
|
||||
** duplicate entries. This can happen if the database is corrupt.
|
||||
** It would be simpler to detect this as part of the loop below, but
|
||||
** we do the detection here in order to avoid populating the pager
|
||||
** cache with two separate objects associated with the same
|
||||
** page number. */
|
||||
assert( CORRUPT_DB );
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto balance_cleanup;
|
||||
}
|
||||
}
|
||||
aPgno[i] = apNew[i]->pgno;
|
||||
assert( apNew[i]->pDbPage->flags & PGHDR_WRITEABLE );
|
||||
assert( apNew[i]->pDbPage->flags & PGHDR_DIRTY );
|
||||
}
|
||||
for(i=0; i<nNew; i++){
|
||||
int iBest = 0; /* aPgno[] index of page number to use */
|
||||
for(j=1; j<nNew; j++){
|
||||
if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j;
|
||||
for(i=0; i<nNew-1; i++){
|
||||
int iB = i;
|
||||
for(j=i+1; j<nNew; j++){
|
||||
if( apNew[j]->pgno < apNew[iB]->pgno ) iB = j;
|
||||
}
|
||||
pgno = aPgOrder[iBest];
|
||||
aPgOrder[iBest] = 0xffffffff;
|
||||
if( iBest!=i ){
|
||||
if( iBest>i ){
|
||||
sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0);
|
||||
}
|
||||
sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]);
|
||||
apNew[i]->pgno = pgno;
|
||||
|
||||
/* If apNew[i] has a page number that is bigger than any of the
|
||||
** subsequence apNew[i] entries, then swap apNew[i] with the subsequent
|
||||
** entry that has the smallest page number (which we know to be
|
||||
** entry apNew[iB]).
|
||||
*/
|
||||
if( iB!=i ){
|
||||
Pgno pgnoA = apNew[i]->pgno;
|
||||
Pgno pgnoB = apNew[iB]->pgno;
|
||||
Pgno pgnoTemp = (PENDING_BYTE/pBt->pageSize)+1;
|
||||
u16 fgA = apNew[i]->pDbPage->flags;
|
||||
u16 fgB = apNew[iB]->pDbPage->flags;
|
||||
sqlite3PagerRekey(apNew[i]->pDbPage, pgnoTemp, fgB);
|
||||
sqlite3PagerRekey(apNew[iB]->pDbPage, pgnoA, fgA);
|
||||
sqlite3PagerRekey(apNew[i]->pDbPage, pgnoB, fgB);
|
||||
apNew[i]->pgno = pgnoB;
|
||||
apNew[iB]->pgno = pgnoA;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8491,7 +8478,7 @@ 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++){}
|
||||
for(k=0; b.ixNx[k]<=j && ALWAYS(k<NB*2); k++){}
|
||||
pSrcEnd = b.apEnd[k];
|
||||
if( SQLITE_WITHIN(pSrcEnd, pCell, pCell+sz) ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
@@ -8742,7 +8729,6 @@ static int anotherValidCursor(BtCursor *pCur){
|
||||
*/
|
||||
static int balance(BtCursor *pCur){
|
||||
int rc = SQLITE_OK;
|
||||
const int nMin = pCur->pBt->usableSize * 2 / 3;
|
||||
u8 aBalanceQuickSpace[13];
|
||||
u8 *pFree = 0;
|
||||
|
||||
@@ -8754,7 +8740,11 @@ static int balance(BtCursor *pCur){
|
||||
MemPage *pPage = pCur->pPage;
|
||||
|
||||
if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
|
||||
if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
|
||||
if( pPage->nOverflow==0 && pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
|
||||
/* No rebalance required as long as:
|
||||
** (1) There are no overflow cells
|
||||
** (2) The amount of free space on the page is less than 2/3rds of
|
||||
** the total usable space on the page. */
|
||||
break;
|
||||
}else if( (iPage = pCur->iPage)==0 ){
|
||||
if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){
|
||||
@@ -8777,6 +8767,11 @@ static int balance(BtCursor *pCur){
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}else if( sqlite3PagerPageRefcount(pPage->pDbPage)>1 ){
|
||||
/* The page being written is not a root page, and there is currently
|
||||
** more than one reference to it. This only happens if the page is one
|
||||
** of its own ancestor pages. Corruption. */
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}else{
|
||||
MemPage * const pParent = pCur->apPage[iPage-1];
|
||||
int const iIdx = pCur->aiIdx[iPage-1];
|
||||
@@ -9007,24 +9002,6 @@ int sqlite3BtreeInsert(
|
||||
assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND|BTREE_PREFORMAT))==flags );
|
||||
assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
|
||||
|
||||
if( pCur->eState==CURSOR_FAULT ){
|
||||
assert( pCur->skipNext!=SQLITE_OK );
|
||||
return pCur->skipNext;
|
||||
}
|
||||
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( (pCur->curFlags & BTCF_WriteFlag)!=0
|
||||
&& pBt->inTransaction==TRANS_WRITE
|
||||
&& (pBt->btsFlags & BTS_READ_ONLY)==0 );
|
||||
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
|
||||
|
||||
/* Assert that the caller has been consistent. If this cursor was opened
|
||||
** expecting an index b-tree, then the caller should be inserting blob
|
||||
** keys with no associated data. If the cursor was opened expecting an
|
||||
** intkey table, the caller should be inserting integer keys with a
|
||||
** blob of associated data. */
|
||||
assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
|
||||
|
||||
/* Save the positions of any other cursors open on this table.
|
||||
**
|
||||
** In some cases, the call to btreeMoveto() below is a no-op. For
|
||||
@@ -9049,6 +9026,29 @@ int sqlite3BtreeInsert(
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure that the cursor is not in the CURSOR_FAULT state and that it
|
||||
** points to a valid cell.
|
||||
*/
|
||||
if( pCur->eState>=CURSOR_REQUIRESEEK ){
|
||||
testcase( pCur->eState==CURSOR_REQUIRESEEK );
|
||||
testcase( pCur->eState==CURSOR_FAULT );
|
||||
rc = moveToRoot(pCur);
|
||||
if( rc && rc!=SQLITE_EMPTY ) return rc;
|
||||
}
|
||||
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( (pCur->curFlags & BTCF_WriteFlag)!=0
|
||||
&& pBt->inTransaction==TRANS_WRITE
|
||||
&& (pBt->btsFlags & BTS_READ_ONLY)==0 );
|
||||
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
|
||||
|
||||
/* Assert that the caller has been consistent. If this cursor was opened
|
||||
** expecting an index b-tree, then the caller should be inserting blob
|
||||
** keys with no associated data. If the cursor was opened expecting an
|
||||
** intkey table, the caller should be inserting integer keys with a
|
||||
** blob of associated data. */
|
||||
assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
|
||||
|
||||
if( pCur->pKeyInfo==0 ){
|
||||
assert( pX->pKey==0 );
|
||||
/* If this is an insert into a table b-tree, invalidate any incrblob
|
||||
@@ -9137,14 +9137,14 @@ int sqlite3BtreeInsert(
|
||||
}
|
||||
}
|
||||
assert( pCur->eState==CURSOR_VALID
|
||||
|| (pCur->eState==CURSOR_INVALID && loc)
|
||||
|| CORRUPT_DB );
|
||||
|| (pCur->eState==CURSOR_INVALID && loc) );
|
||||
|
||||
pPage = pCur->pPage;
|
||||
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) ){
|
||||
/* ^^^^^--- due to the moveToRoot() call above */
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}else{
|
||||
rc = btreeComputeFreeSpace(pPage);
|
||||
@@ -9155,7 +9155,7 @@ int sqlite3BtreeInsert(
|
||||
TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
|
||||
pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
|
||||
loc==0 ? "overwrite" : "new entry"));
|
||||
assert( pPage->isInit );
|
||||
assert( pPage->isInit || CORRUPT_DB );
|
||||
newCell = pBt->pTmpSpace;
|
||||
assert( newCell!=0 );
|
||||
if( flags & BTREE_PREFORMAT ){
|
||||
@@ -9306,7 +9306,11 @@ int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 iKey){
|
||||
u32 nRem; /* Bytes of data still to copy */
|
||||
|
||||
getCellInfo(pSrc);
|
||||
aOut += putVarint32(aOut, pSrc->info.nPayload);
|
||||
if( pSrc->info.nPayload<0x80 ){
|
||||
*(aOut++) = pSrc->info.nPayload;
|
||||
}else{
|
||||
aOut += sqlite3PutVarint(aOut, pSrc->info.nPayload);
|
||||
}
|
||||
if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
|
||||
nIn = pSrc->info.nLocal;
|
||||
aIn = pSrc->info.pPayload;
|
||||
@@ -9425,12 +9429,16 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
|
||||
assert( !hasReadConflicts(p, pCur->pgnoRoot) );
|
||||
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
|
||||
if( pCur->eState==CURSOR_REQUIRESEEK ){
|
||||
rc = btreeRestoreCursorPosition(pCur);
|
||||
assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
|
||||
if( rc || pCur->eState!=CURSOR_VALID ) return rc;
|
||||
if( pCur->eState!=CURSOR_VALID ){
|
||||
if( pCur->eState>=CURSOR_REQUIRESEEK ){
|
||||
rc = btreeRestoreCursorPosition(pCur);
|
||||
assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
|
||||
if( rc || pCur->eState!=CURSOR_VALID ) return rc;
|
||||
}else{
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
}
|
||||
assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
|
||||
iCellDepth = pCur->iPage;
|
||||
iCellIdx = pCur->ix;
|
||||
@@ -9462,7 +9470,8 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
|
||||
if( bPreserve ){
|
||||
if( !pPage->leaf
|
||||
|| (pPage->nFree+pPage->xCellSize(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
|
||||
|| (pPage->nFree+pPage->xCellSize(pPage,pCell)+2) >
|
||||
(int)(pBt->usableSize*2/3)
|
||||
|| pPage->nCell==1 /* See dbfuzz001.test for a test case */
|
||||
){
|
||||
/* A b-tree rebalance will be required after deleting this entry.
|
||||
@@ -9558,7 +9567,15 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
** been corrected, so be it. Otherwise, after balancing the leaf node,
|
||||
** walk the cursor up the tree to the internal node and balance it as
|
||||
** well. */
|
||||
rc = balance(pCur);
|
||||
assert( pCur->pPage->nOverflow==0 );
|
||||
assert( pCur->pPage->nFree>=0 );
|
||||
if( pCur->pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
|
||||
/* Optimization: If the free space is less than 2/3rds of the page,
|
||||
** then balance() will always be a no-op. No need to invoke it. */
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
rc = balance(pCur);
|
||||
}
|
||||
if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
|
||||
releasePageNotNull(pCur->pPage);
|
||||
pCur->iPage--;
|
||||
|
||||
+159
-123
@@ -140,6 +140,7 @@ int sqlite3DbMaskAllZero(yDbMask m){
|
||||
void sqlite3FinishCoding(Parse *pParse){
|
||||
sqlite3 *db;
|
||||
Vdbe *v;
|
||||
int iDb, i;
|
||||
|
||||
assert( pParse->pToplevel==0 );
|
||||
db = pParse->db;
|
||||
@@ -169,12 +170,9 @@ void sqlite3FinishCoding(Parse *pParse){
|
||||
if( pParse->bReturning ){
|
||||
Returning *pReturning = pParse->u1.pReturning;
|
||||
int addrRewind;
|
||||
int i;
|
||||
int reg;
|
||||
|
||||
if( NEVER(pReturning->nRetCol==0) ){
|
||||
assert( CORRUPT_DB );
|
||||
}else{
|
||||
if( pReturning->nRetCol ){
|
||||
sqlite3VdbeAddOp0(v, OP_FkCheck);
|
||||
addrRewind =
|
||||
sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
|
||||
@@ -208,76 +206,69 @@ void sqlite3FinishCoding(Parse *pParse){
|
||||
** transaction on each used database and to verify the schema cookie
|
||||
** on each used database.
|
||||
*/
|
||||
if( db->mallocFailed==0
|
||||
&& (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr)
|
||||
){
|
||||
int iDb, i;
|
||||
assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
|
||||
sqlite3VdbeJumpHere(v, 0);
|
||||
for(iDb=0; iDb<db->nDb; iDb++){
|
||||
Schema *pSchema;
|
||||
if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
|
||||
sqlite3VdbeUsesBtree(v, iDb);
|
||||
pSchema = db->aDb[iDb].pSchema;
|
||||
sqlite3VdbeAddOp4Int(v,
|
||||
OP_Transaction, /* Opcode */
|
||||
iDb, /* P1 */
|
||||
DbMaskTest(pParse->writeMask,iDb), /* P2 */
|
||||
pSchema->schema_cookie, /* P3 */
|
||||
pSchema->iGeneration /* P4 */
|
||||
);
|
||||
if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
|
||||
VdbeComment((v,
|
||||
"usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
|
||||
}
|
||||
assert( pParse->nErr>0 || sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
|
||||
sqlite3VdbeJumpHere(v, 0);
|
||||
assert( db->nDb>0 );
|
||||
iDb = 0;
|
||||
do{
|
||||
Schema *pSchema;
|
||||
if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
|
||||
sqlite3VdbeUsesBtree(v, iDb);
|
||||
pSchema = db->aDb[iDb].pSchema;
|
||||
sqlite3VdbeAddOp4Int(v,
|
||||
OP_Transaction, /* Opcode */
|
||||
iDb, /* P1 */
|
||||
DbMaskTest(pParse->writeMask,iDb), /* P2 */
|
||||
pSchema->schema_cookie, /* P3 */
|
||||
pSchema->iGeneration /* P4 */
|
||||
);
|
||||
if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
|
||||
VdbeComment((v,
|
||||
"usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
|
||||
}while( ++iDb<db->nDb );
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
for(i=0; i<pParse->nVtabLock; i++){
|
||||
char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
|
||||
sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
|
||||
}
|
||||
pParse->nVtabLock = 0;
|
||||
for(i=0; i<pParse->nVtabLock; i++){
|
||||
char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
|
||||
sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
|
||||
}
|
||||
pParse->nVtabLock = 0;
|
||||
#endif
|
||||
|
||||
/* Once all the cookies have been verified and transactions opened,
|
||||
** obtain the required table-locks. This is a no-op unless the
|
||||
** shared-cache feature is enabled.
|
||||
*/
|
||||
codeTableLocks(pParse);
|
||||
/* Once all the cookies have been verified and transactions opened,
|
||||
** obtain the required table-locks. This is a no-op unless the
|
||||
** shared-cache feature is enabled.
|
||||
*/
|
||||
codeTableLocks(pParse);
|
||||
|
||||
/* Initialize any AUTOINCREMENT data structures required.
|
||||
*/
|
||||
sqlite3AutoincrementBegin(pParse);
|
||||
/* Initialize any AUTOINCREMENT data structures required.
|
||||
*/
|
||||
sqlite3AutoincrementBegin(pParse);
|
||||
|
||||
/* Code constant expressions that where factored out of inner loops.
|
||||
**
|
||||
** The pConstExpr list might also contain expressions that we simply
|
||||
** want to keep around until the Parse object is deleted. Such
|
||||
** expressions have iConstExprReg==0. Do not generate code for
|
||||
** those expressions, of course.
|
||||
*/
|
||||
if( pParse->pConstExpr ){
|
||||
ExprList *pEL = pParse->pConstExpr;
|
||||
pParse->okConstFactor = 0;
|
||||
for(i=0; i<pEL->nExpr; i++){
|
||||
int iReg = pEL->a[i].u.iConstExprReg;
|
||||
if( iReg>0 ){
|
||||
sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
|
||||
}
|
||||
}
|
||||
/* Code constant expressions that where factored out of inner loops.
|
||||
**
|
||||
** The pConstExpr list might also contain expressions that we simply
|
||||
** want to keep around until the Parse object is deleted. Such
|
||||
** expressions have iConstExprReg==0. Do not generate code for
|
||||
** those expressions, of course.
|
||||
*/
|
||||
if( pParse->pConstExpr ){
|
||||
ExprList *pEL = pParse->pConstExpr;
|
||||
pParse->okConstFactor = 0;
|
||||
for(i=0; i<pEL->nExpr; i++){
|
||||
int iReg = pEL->a[i].u.iConstExprReg;
|
||||
sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
|
||||
}
|
||||
|
||||
if( pParse->bReturning ){
|
||||
Returning *pRet = pParse->u1.pReturning;
|
||||
if( NEVER(pRet->nRetCol==0) ){
|
||||
assert( CORRUPT_DB );
|
||||
}else{
|
||||
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
|
||||
}
|
||||
}
|
||||
|
||||
/* Finally, jump back to the beginning of the executable code. */
|
||||
sqlite3VdbeGoto(v, 1);
|
||||
}
|
||||
|
||||
if( pParse->bReturning ){
|
||||
Returning *pRet = pParse->u1.pReturning;
|
||||
if( pRet->nRetCol ){
|
||||
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
|
||||
}
|
||||
}
|
||||
|
||||
/* Finally, jump back to the beginning of the executable code. */
|
||||
sqlite3VdbeGoto(v, 1);
|
||||
}
|
||||
|
||||
/* Get the VDBE program ready for execution
|
||||
@@ -333,8 +324,6 @@ void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
|
||||
memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
|
||||
db->mDbFlags |= DBFLAG_PreferBuiltin;
|
||||
sqlite3RunParser(pParse, zSql);
|
||||
sqlite3DbFree(db, pParse->zErrMsg);
|
||||
pParse->zErrMsg = 0;
|
||||
db->mDbFlags = savedDbFlags;
|
||||
sqlite3DbFree(db, zSql);
|
||||
memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ);
|
||||
@@ -464,7 +453,7 @@ 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 && db->init.busy==0 ){
|
||||
if( (pParse->prepFlags & SQLITE_PREPARE_NO_VTAB)==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);
|
||||
@@ -477,7 +466,7 @@ Table *sqlite3LocateTable(
|
||||
#endif
|
||||
if( flags & LOCATE_NOERR ) return 0;
|
||||
pParse->checkSchema = 1;
|
||||
}else if( IsVirtual(p) && pParse->disableVtab ){
|
||||
}else if( IsVirtual(p) && (pParse->prepFlags & SQLITE_PREPARE_NO_VTAB)!=0 ){
|
||||
p = 0;
|
||||
}
|
||||
|
||||
@@ -786,16 +775,17 @@ void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
|
||||
int i;
|
||||
Column *pCol;
|
||||
assert( pTable!=0 );
|
||||
assert( db!=0 );
|
||||
if( (pCol = pTable->aCol)!=0 ){
|
||||
for(i=0; i<pTable->nCol; i++, pCol++){
|
||||
assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
|
||||
sqlite3DbFree(db, pCol->zCnName);
|
||||
}
|
||||
sqlite3DbFree(db, pTable->aCol);
|
||||
sqlite3DbNNFreeNN(db, pTable->aCol);
|
||||
if( IsOrdinaryTable(pTable) ){
|
||||
sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
|
||||
}
|
||||
if( db==0 || db->pnBytesFreed==0 ){
|
||||
if( db->pnBytesFreed==0 ){
|
||||
pTable->aCol = 0;
|
||||
pTable->nCol = 0;
|
||||
if( IsOrdinaryTable(pTable) ){
|
||||
@@ -832,7 +822,8 @@ static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
|
||||
** a Table object that was going to be marked ephemeral. So do not check
|
||||
** that no lookaside memory is used in this case either. */
|
||||
int nLookaside = 0;
|
||||
if( db && !db->mallocFailed && (pTable->tabFlags & TF_Ephemeral)==0 ){
|
||||
assert( db!=0 );
|
||||
if( !db->mallocFailed && (pTable->tabFlags & TF_Ephemeral)==0 ){
|
||||
nLookaside = sqlite3LookasideUsed(db, 0);
|
||||
}
|
||||
#endif
|
||||
@@ -842,7 +833,7 @@ static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
|
||||
pNext = pIndex->pNext;
|
||||
assert( pIndex->pSchema==pTable->pSchema
|
||||
|| (IsVirtual(pTable) && pIndex->idxType!=SQLITE_IDXTYPE_APPDEF) );
|
||||
if( (db==0 || db->pnBytesFreed==0) && !IsVirtual(pTable) ){
|
||||
if( db->pnBytesFreed==0 && !IsVirtual(pTable) ){
|
||||
char *zName = pIndex->zName;
|
||||
TESTONLY ( Index *pOld = ) sqlite3HashInsert(
|
||||
&pIndex->pSchema->idxHash, zName, 0
|
||||
@@ -879,8 +870,9 @@ static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
|
||||
}
|
||||
void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
|
||||
/* Do not delete the table until the reference count reaches zero. */
|
||||
assert( db!=0 );
|
||||
if( !pTable ) return;
|
||||
if( ((!db || db->pnBytesFreed==0) && (--pTable->nTabRef)>0) ) return;
|
||||
if( db->pnBytesFreed==0 && (--pTable->nTabRef)>0 ) return;
|
||||
deleteTable(db, pTable);
|
||||
}
|
||||
|
||||
@@ -1892,7 +1884,7 @@ void sqlite3AddPrimaryKey(
|
||||
pTab->keyConf = (u8)onError;
|
||||
assert( autoInc==0 || autoInc==1 );
|
||||
pTab->tabFlags |= autoInc*TF_Autoincrement;
|
||||
if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
|
||||
if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
|
||||
(void)sqlite3HasExplicitNulls(pParse, pList);
|
||||
}else if( autoInc ){
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
@@ -2386,7 +2378,7 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
if( IN_RENAME_OBJECT ){
|
||||
sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
|
||||
}
|
||||
pList->a[0].sortFlags = pParse->iPkSortOrder;
|
||||
pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
|
||||
assert( pParse->pNewTable==pTab );
|
||||
pTab->iPKey = -1;
|
||||
sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
|
||||
@@ -2799,6 +2791,7 @@ void sqlite3EndTable(
|
||||
#ifndef SQLITE_OMIT_VIEW
|
||||
}else{
|
||||
/* A view */
|
||||
sqlite3VdbeRunOnlyOnce(v);
|
||||
zType = "view";
|
||||
zType2 = "VIEW";
|
||||
#endif
|
||||
@@ -3053,11 +3046,10 @@ create_view_fail:
|
||||
** the columns of the view in the pTable structure. Return the number
|
||||
** of errors. If an error is seen leave an error message in pParse->zErrMsg.
|
||||
*/
|
||||
int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
||||
static SQLITE_NOINLINE int viewGetColumnNames(Parse *pParse, Table *pTable){
|
||||
Table *pSelTab; /* A fake table from which we get the result set */
|
||||
Select *pSel; /* Copy of the SELECT that implements the view */
|
||||
int nErr = 0; /* Number of errors encountered */
|
||||
int n; /* Temporarily holds the number of cursors assigned */
|
||||
sqlite3 *db = pParse->db; /* Database connection for malloc errors */
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
int rc;
|
||||
@@ -3079,9 +3071,10 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
||||
|
||||
#ifndef SQLITE_OMIT_VIEW
|
||||
/* A positive nCol means the columns names for this view are
|
||||
** already known.
|
||||
** already known. This routine is not called unless either the
|
||||
** table is virtual or nCol is zero.
|
||||
*/
|
||||
if( pTable->nCol>0 ) return 0;
|
||||
assert( pTable->nCol<=0 );
|
||||
|
||||
/* A negative nCol is a special marker meaning that we are currently
|
||||
** trying to compute the column names. If we enter this routine with
|
||||
@@ -3115,8 +3108,9 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
||||
pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
|
||||
if( pSel ){
|
||||
u8 eParseMode = pParse->eParseMode;
|
||||
int nTab = pParse->nTab;
|
||||
int nSelect = pParse->nSelect;
|
||||
pParse->eParseMode = PARSE_MODE_NORMAL;
|
||||
n = pParse->nTab;
|
||||
sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
|
||||
pTable->nCol = -1;
|
||||
DisableLookaside;
|
||||
@@ -3128,7 +3122,8 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
||||
#else
|
||||
pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
|
||||
#endif
|
||||
pParse->nTab = n;
|
||||
pParse->nTab = nTab;
|
||||
pParse->nSelect = nSelect;
|
||||
if( pSelTab==0 ){
|
||||
pTable->nCol = 0;
|
||||
nErr++;
|
||||
@@ -3175,6 +3170,11 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
||||
#endif /* SQLITE_OMIT_VIEW */
|
||||
return nErr;
|
||||
}
|
||||
int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
|
||||
assert( pTable!=0 );
|
||||
if( !IsVirtual(pTable) && pTable->nCol>0 ) return 0;
|
||||
return viewGetColumnNames(pParse, pTable);
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
|
||||
|
||||
#ifndef SQLITE_OMIT_VIEW
|
||||
@@ -3873,8 +3873,8 @@ int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
|
||||
if( pList ){
|
||||
int i;
|
||||
for(i=0; i<pList->nExpr; i++){
|
||||
if( pList->a[i].bNulls ){
|
||||
u8 sf = pList->a[i].sortFlags;
|
||||
if( pList->a[i].fg.bNulls ){
|
||||
u8 sf = pList->a[i].fg.sortFlags;
|
||||
sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
|
||||
(sf==0 || sf==3) ? "FIRST" : "LAST"
|
||||
);
|
||||
@@ -4040,7 +4040,7 @@ void sqlite3CreateIndex(
|
||||
}
|
||||
if( !IN_RENAME_OBJECT ){
|
||||
if( !db->init.busy ){
|
||||
if( sqlite3FindTable(db, zName, 0)!=0 ){
|
||||
if( sqlite3FindTable(db, zName, pDb->zDbSName)!=0 ){
|
||||
sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
|
||||
goto exit_create_index;
|
||||
}
|
||||
@@ -4227,7 +4227,7 @@ void sqlite3CreateIndex(
|
||||
goto exit_create_index;
|
||||
}
|
||||
pIndex->azColl[i] = zColl;
|
||||
requestedSortOrder = pListItem->sortFlags & sortOrderMask;
|
||||
requestedSortOrder = pListItem->fg.sortFlags & sortOrderMask;
|
||||
pIndex->aSortOrder[i] = (u8)requestedSortOrder;
|
||||
}
|
||||
|
||||
@@ -4670,18 +4670,17 @@ IdList *sqlite3IdListAppend(Parse *pParse, IdList *pList, Token *pToken){
|
||||
if( pList==0 ){
|
||||
pList = sqlite3DbMallocZero(db, sizeof(IdList) );
|
||||
if( pList==0 ) return 0;
|
||||
}else{
|
||||
IdList *pNew;
|
||||
pNew = sqlite3DbRealloc(db, pList,
|
||||
sizeof(IdList) + pList->nId*sizeof(pList->a));
|
||||
if( pNew==0 ){
|
||||
sqlite3IdListDelete(db, pList);
|
||||
return 0;
|
||||
}
|
||||
pList = pNew;
|
||||
}
|
||||
pList->a = sqlite3ArrayAllocate(
|
||||
db,
|
||||
pList->a,
|
||||
sizeof(pList->a[0]),
|
||||
&pList->nId,
|
||||
&i
|
||||
);
|
||||
if( i<0 ){
|
||||
sqlite3IdListDelete(db, pList);
|
||||
return 0;
|
||||
}
|
||||
i = pList->nId++;
|
||||
pList->a[i].zName = sqlite3NameFromToken(db, pToken);
|
||||
if( IN_RENAME_OBJECT && pList->a[i].zName ){
|
||||
sqlite3RenameTokenMap(pParse, (void*)pList->a[i].zName, pToken);
|
||||
@@ -4694,12 +4693,13 @@ IdList *sqlite3IdListAppend(Parse *pParse, IdList *pList, Token *pToken){
|
||||
*/
|
||||
void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
|
||||
int i;
|
||||
assert( db!=0 );
|
||||
if( pList==0 ) return;
|
||||
assert( pList->eU4!=EU4_EXPR ); /* EU4_EXPR mode is not currently used */
|
||||
for(i=0; i<pList->nId; i++){
|
||||
sqlite3DbFree(db, pList->a[i].zName);
|
||||
}
|
||||
sqlite3DbFree(db, pList->a);
|
||||
sqlite3DbFreeNN(db, pList);
|
||||
sqlite3DbNNFreeNN(db, pList);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4708,7 +4708,7 @@ void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
|
||||
*/
|
||||
int sqlite3IdListIndex(IdList *pList, const char *zName){
|
||||
int i;
|
||||
if( pList==0 ) return -1;
|
||||
assert( pList!=0 );
|
||||
for(i=0; i<pList->nId; i++){
|
||||
if( sqlite3StrICmp(pList->a[i].zName, zName)==0 ) return i;
|
||||
}
|
||||
@@ -4902,19 +4902,23 @@ void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){
|
||||
void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
|
||||
int i;
|
||||
SrcItem *pItem;
|
||||
assert( db!=0 );
|
||||
if( pList==0 ) return;
|
||||
for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
|
||||
if( pItem->zDatabase ) sqlite3DbFreeNN(db, pItem->zDatabase);
|
||||
sqlite3DbFree(db, pItem->zName);
|
||||
if( pItem->zAlias ) sqlite3DbFreeNN(db, pItem->zAlias);
|
||||
if( pItem->zDatabase ) sqlite3DbNNFreeNN(db, pItem->zDatabase);
|
||||
if( pItem->zName ) sqlite3DbNNFreeNN(db, pItem->zName);
|
||||
if( pItem->zAlias ) sqlite3DbNNFreeNN(db, pItem->zAlias);
|
||||
if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
|
||||
if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
|
||||
sqlite3DeleteTable(db, pItem->pTab);
|
||||
if( pItem->pSelect ) sqlite3SelectDelete(db, pItem->pSelect);
|
||||
if( pItem->pOn ) sqlite3ExprDelete(db, pItem->pOn);
|
||||
if( pItem->pUsing ) sqlite3IdListDelete(db, pItem->pUsing);
|
||||
if( pItem->fg.isUsing ){
|
||||
sqlite3IdListDelete(db, pItem->u3.pUsing);
|
||||
}else if( pItem->u3.pOn ){
|
||||
sqlite3ExprDelete(db, pItem->u3.pOn);
|
||||
}
|
||||
}
|
||||
sqlite3DbFreeNN(db, pList);
|
||||
sqlite3DbNNFreeNN(db, pList);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4940,14 +4944,13 @@ SrcList *sqlite3SrcListAppendFromTerm(
|
||||
Token *pDatabase, /* Name of the database containing pTable */
|
||||
Token *pAlias, /* The right-hand side of the AS subexpression */
|
||||
Select *pSubquery, /* A subquery used in place of a table name */
|
||||
Expr *pOn, /* The ON clause of a join */
|
||||
IdList *pUsing /* The USING clause of a join */
|
||||
OnOrUsing *pOnUsing /* Either the ON clause or the USING clause */
|
||||
){
|
||||
SrcItem *pItem;
|
||||
sqlite3 *db = pParse->db;
|
||||
if( !p && (pOn || pUsing) ){
|
||||
if( !p && pOnUsing!=0 && (pOnUsing->pOn || pOnUsing->pUsing) ){
|
||||
sqlite3ErrorMsg(pParse, "a JOIN clause is required before %s",
|
||||
(pOn ? "ON" : "USING")
|
||||
(pOnUsing->pOn ? "ON" : "USING")
|
||||
);
|
||||
goto append_from_error;
|
||||
}
|
||||
@@ -4967,15 +4970,27 @@ SrcList *sqlite3SrcListAppendFromTerm(
|
||||
if( pAlias->n ){
|
||||
pItem->zAlias = sqlite3NameFromToken(db, pAlias);
|
||||
}
|
||||
pItem->pSelect = pSubquery;
|
||||
pItem->pOn = pOn;
|
||||
pItem->pUsing = pUsing;
|
||||
if( pSubquery ){
|
||||
pItem->pSelect = pSubquery;
|
||||
if( pSubquery->selFlags & SF_NestedFrom ){
|
||||
pItem->fg.isNestedFrom = 1;
|
||||
}
|
||||
}
|
||||
assert( pOnUsing==0 || pOnUsing->pOn==0 || pOnUsing->pUsing==0 );
|
||||
assert( pItem->fg.isUsing==0 );
|
||||
if( pOnUsing==0 ){
|
||||
pItem->u3.pOn = 0;
|
||||
}else if( pOnUsing->pUsing ){
|
||||
pItem->fg.isUsing = 1;
|
||||
pItem->u3.pUsing = pOnUsing->pUsing;
|
||||
}else{
|
||||
pItem->u3.pOn = pOnUsing->pOn;
|
||||
}
|
||||
return p;
|
||||
|
||||
append_from_error:
|
||||
assert( p==0 );
|
||||
sqlite3ExprDelete(db, pOn);
|
||||
sqlite3IdListDelete(db, pUsing);
|
||||
sqlite3ClearOnOrUsing(db, pOnUsing);
|
||||
sqlite3SelectDelete(db, pSubquery);
|
||||
return 0;
|
||||
}
|
||||
@@ -5020,6 +5035,7 @@ SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2){
|
||||
p1 = pNew;
|
||||
memcpy(&p1->a[1], p2->a, p2->nSrc*sizeof(SrcItem));
|
||||
sqlite3DbFree(pParse->db, p2);
|
||||
p1->a[0].fg.jointype |= (JT_LTORJ & p1->a[1].fg.jointype);
|
||||
}
|
||||
}
|
||||
return p1;
|
||||
@@ -5056,14 +5072,34 @@ void sqlite3SrcListFuncArgs(Parse *pParse, SrcList *p, ExprList *pList){
|
||||
** The operator is "natural cross join". The A and B operands are stored
|
||||
** in p->a[0] and p->a[1], respectively. The parser initially stores the
|
||||
** operator with A. This routine shifts that operator over to B.
|
||||
**
|
||||
** Additional changes:
|
||||
**
|
||||
** * All tables to the left of the right-most RIGHT JOIN are tagged with
|
||||
** JT_LTORJ (mnemonic: Left Table Of Right Join) so that the
|
||||
** code generator can easily tell that the table is part of
|
||||
** the left operand of at least one RIGHT JOIN.
|
||||
*/
|
||||
void sqlite3SrcListShiftJoinType(SrcList *p){
|
||||
if( p ){
|
||||
int i;
|
||||
for(i=p->nSrc-1; i>0; i--){
|
||||
p->a[i].fg.jointype = p->a[i-1].fg.jointype;
|
||||
}
|
||||
void sqlite3SrcListShiftJoinType(Parse *pParse, SrcList *p){
|
||||
(void)pParse;
|
||||
if( p && p->nSrc>1 ){
|
||||
int i = p->nSrc-1;
|
||||
u8 allFlags = 0;
|
||||
do{
|
||||
allFlags |= p->a[i].fg.jointype = p->a[i-1].fg.jointype;
|
||||
}while( (--i)>0 );
|
||||
p->a[0].fg.jointype = 0;
|
||||
|
||||
/* All terms to the left of a RIGHT JOIN should be tagged with the
|
||||
** JT_LTORJ flags */
|
||||
if( allFlags & JT_RIGHT ){
|
||||
for(i=p->nSrc-1; ALWAYS(i>0) && (p->a[i].fg.jointype&JT_RIGHT)==0; i--){}
|
||||
i--;
|
||||
assert( i>=0 );
|
||||
do{
|
||||
p->a[i].fg.jointype |= JT_LTORJ;
|
||||
}while( (--i)>=0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -490,19 +490,21 @@ void sqlite3SchemaClear(void *p){
|
||||
Hash temp2;
|
||||
HashElem *pElem;
|
||||
Schema *pSchema = (Schema *)p;
|
||||
sqlite3 xdb;
|
||||
|
||||
memset(&xdb, 0, sizeof(xdb));
|
||||
temp1 = pSchema->tblHash;
|
||||
temp2 = pSchema->trigHash;
|
||||
sqlite3HashInit(&pSchema->trigHash);
|
||||
sqlite3HashClear(&pSchema->idxHash);
|
||||
for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
|
||||
sqlite3DeleteTrigger(0, (Trigger*)sqliteHashData(pElem));
|
||||
sqlite3DeleteTrigger(&xdb, (Trigger*)sqliteHashData(pElem));
|
||||
}
|
||||
sqlite3HashClear(&temp2);
|
||||
sqlite3HashInit(&pSchema->tblHash);
|
||||
for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
|
||||
Table *pTab = sqliteHashData(pElem);
|
||||
sqlite3DeleteTable(0, pTab);
|
||||
sqlite3DeleteTable(&xdb, pTab);
|
||||
}
|
||||
sqlite3HashClear(&temp1);
|
||||
sqlite3HashClear(&pSchema->fkeyHash);
|
||||
|
||||
+3
-6
@@ -307,9 +307,6 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_ENABLE_RTREE
|
||||
"ENABLE_RTREE",
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_SELECTTRACE
|
||||
"ENABLE_SELECTTRACE",
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_SESSION
|
||||
"ENABLE_SESSION",
|
||||
#endif
|
||||
@@ -331,6 +328,9 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
||||
"ENABLE_STMT_SCANSTATUS",
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_TREETRACE
|
||||
"ENABLE_TREETRACE",
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
|
||||
"ENABLE_UNKNOWN_SQL_FUNCTION",
|
||||
#endif
|
||||
@@ -683,9 +683,6 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_OMIT_XFER_OPT
|
||||
"OMIT_XFER_OPT",
|
||||
#endif
|
||||
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
|
||||
"PCACHE_SEPARATE_HEADER",
|
||||
#endif
|
||||
#ifdef SQLITE_PERFORMANCE_TRACE
|
||||
"PERFORMANCE_TRACE",
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -276,7 +276,7 @@ static void computeJD(DateTime *p){
|
||||
p->iJD = (sqlite3_int64)((X1 + X2 + D + B - 1524.5 ) * 86400000);
|
||||
p->validJD = 1;
|
||||
if( p->validHMS ){
|
||||
p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000);
|
||||
p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000 + 0.5);
|
||||
if( p->validTZ ){
|
||||
p->iJD -= p->tz*60000;
|
||||
p->validYMD = 0;
|
||||
@@ -785,7 +785,7 @@ static int parseModifier(
|
||||
*/
|
||||
if( sqlite3_strnicmp(z, "weekday ", 8)==0
|
||||
&& sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0
|
||||
&& (n=(int)r)==r && n>=0 && r<7 ){
|
||||
&& r>=0.0 && r<7.0 && (n=(int)r)==r ){
|
||||
sqlite3_int64 Z;
|
||||
computeYMD_HMS(p);
|
||||
p->validTZ = 0;
|
||||
|
||||
+5
-4
@@ -156,7 +156,7 @@ static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
){
|
||||
pIdxInfo->orderByConsumed = 1;
|
||||
}
|
||||
sqlite3VtabWriteAll(pIdxInfo);
|
||||
sqlite3VtabUsesAllSchemas(pIdxInfo);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -372,11 +372,12 @@ static int dbpageBegin(sqlite3_vtab *pVtab){
|
||||
DbpageTable *pTab = (DbpageTable *)pVtab;
|
||||
sqlite3 *db = pTab->db;
|
||||
int i;
|
||||
for(i=0; i<db->nDb; i++){
|
||||
int rc = SQLITE_OK;
|
||||
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
|
||||
Btree *pBt = db->aDb[i].pBt;
|
||||
if( pBt ) sqlite3BtreeBeginTrans(pBt, 1, 0);
|
||||
if( pBt ) rc = sqlite3BtreeBeginTrans(pBt, 1, 0);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+46
-12
@@ -61,18 +61,42 @@ void sqlite3CodeChangeCount(Vdbe *v, int regCounter, const char *zColName){
|
||||
** 1) It is a virtual table and no implementation of the xUpdate method
|
||||
** has been provided
|
||||
**
|
||||
** 2) It is a system table (i.e. sqlite_schema), this call is not
|
||||
** 2) A trigger is currently being coded and the table is a virtual table
|
||||
** that is SQLITE_VTAB_DIRECTONLY or if PRAGMA trusted_schema=OFF and
|
||||
** the table is not SQLITE_VTAB_INNOCUOUS.
|
||||
**
|
||||
** 3) It is a system table (i.e. sqlite_schema), this call is not
|
||||
** part of a nested parse and writable_schema pragma has not
|
||||
** been specified
|
||||
**
|
||||
** 3) The table is a shadow table, the database connection is in
|
||||
** 4) The table is a shadow table, the database connection is in
|
||||
** defensive mode, and the current sqlite3_prepare()
|
||||
** is for a top-level SQL statement.
|
||||
*/
|
||||
static int vtabIsReadOnly(Parse *pParse, Table *pTab){
|
||||
if( sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Within triggers:
|
||||
** * Do not allow DELETE, INSERT, or UPDATE of SQLITE_VTAB_DIRECTONLY
|
||||
** virtual tables
|
||||
** * Only allow DELETE, INSERT, or UPDATE of non-SQLITE_VTAB_INNOCUOUS
|
||||
** virtual tables if PRAGMA trusted_schema=ON.
|
||||
*/
|
||||
if( pParse->pToplevel!=0
|
||||
&& pTab->u.vtab.p->eVtabRisk >
|
||||
((pParse->db->flags & SQLITE_TrustedSchema)!=0)
|
||||
){
|
||||
sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
|
||||
pTab->zName);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static int tabIsReadOnly(Parse *pParse, Table *pTab){
|
||||
sqlite3 *db;
|
||||
if( IsVirtual(pTab) ){
|
||||
return sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0;
|
||||
return vtabIsReadOnly(pParse, pTab);
|
||||
}
|
||||
if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0;
|
||||
db = pParse->db;
|
||||
@@ -84,9 +108,11 @@ static int tabIsReadOnly(Parse *pParse, Table *pTab){
|
||||
}
|
||||
|
||||
/*
|
||||
** Check to make sure the given table is writable. If it is not
|
||||
** writable, generate an error message and return 1. If it is
|
||||
** writable return 0;
|
||||
** Check to make sure the given table is writable.
|
||||
**
|
||||
** If pTab is not writable -> generate an error message and return 1.
|
||||
** If pTab is writable but other errors have occurred -> return 1.
|
||||
** If pTab is writable and no prior errors -> return 0;
|
||||
*/
|
||||
int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
if( tabIsReadOnly(pParse, pTab) ){
|
||||
@@ -128,8 +154,8 @@ void sqlite3MaterializeView(
|
||||
assert( pFrom->nSrc==1 );
|
||||
pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
|
||||
pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
|
||||
assert( pFrom->a[0].pOn==0 );
|
||||
assert( pFrom->a[0].pUsing==0 );
|
||||
assert( pFrom->a[0].fg.isUsing==0 );
|
||||
assert( pFrom->a[0].u3.pOn==0 );
|
||||
}
|
||||
pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
|
||||
SF_IncludeHidden, pLimit);
|
||||
@@ -300,7 +326,6 @@ void sqlite3DeleteFrom(
|
||||
assert( db->mallocFailed==0 );
|
||||
assert( pTabList->nSrc==1 );
|
||||
|
||||
|
||||
/* Locate the table which we want to delete. This table has to be
|
||||
** put in an SrcList structure because some of the subroutines we
|
||||
** will be calling are designed to work with multiple tables and expect
|
||||
@@ -325,6 +350,14 @@ void sqlite3DeleteFrom(
|
||||
# define isView 0
|
||||
#endif
|
||||
|
||||
#if TREETRACE_ENABLED
|
||||
if( sqlite3TreeTrace & 0x10000 ){
|
||||
sqlite3TreeViewLine(0, "In sqlite3Delete() at %s:%d", __FILE__, __LINE__);
|
||||
sqlite3TreeViewDelete(pParse->pWith, pTabList, pWhere,
|
||||
pOrderBy, pLimit, pTrigger);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
|
||||
if( !isView ){
|
||||
pWhere = sqlite3LimitWhere(
|
||||
@@ -440,9 +473,10 @@ 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);
|
||||
sqlite3VdbeAddOp3(v, OP_Clear, pIdx->tnum, iDb, memCnt ? memCnt : -1);
|
||||
}else{
|
||||
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
|
||||
}
|
||||
}
|
||||
}else
|
||||
@@ -642,7 +676,7 @@ delete_from_cleanup:
|
||||
sqlite3ExprListDelete(db, pOrderBy);
|
||||
sqlite3ExprDelete(db, pLimit);
|
||||
#endif
|
||||
sqlite3DbFree(db, aToOpen);
|
||||
if( aToOpen ) sqlite3DbNNFreeNN(db, aToOpen);
|
||||
return;
|
||||
}
|
||||
/* Make sure "isView" and other macros defined above are undefined. Otherwise
|
||||
|
||||
+201
-93
@@ -770,7 +770,9 @@ static void heightOfSelect(const Select *pSelect, int *pnHeight){
|
||||
*/
|
||||
static void exprSetHeight(Expr *p){
|
||||
int nHeight = p->pLeft ? p->pLeft->nHeight : 0;
|
||||
if( p->pRight && p->pRight->nHeight>nHeight ) nHeight = p->pRight->nHeight;
|
||||
if( NEVER(p->pRight) && p->pRight->nHeight>nHeight ){
|
||||
nHeight = p->pRight->nHeight;
|
||||
}
|
||||
if( ExprUseXSelect(p) ){
|
||||
heightOfSelect(p->x.pSelect, &nHeight);
|
||||
}else if( p->x.pList ){
|
||||
@@ -913,15 +915,26 @@ void sqlite3ExprAttachSubtrees(
|
||||
sqlite3ExprDelete(db, pLeft);
|
||||
sqlite3ExprDelete(db, pRight);
|
||||
}else{
|
||||
assert( ExprUseXList(pRoot) );
|
||||
assert( pRoot->x.pSelect==0 );
|
||||
if( pRight ){
|
||||
pRoot->pRight = pRight;
|
||||
pRoot->flags |= EP_Propagate & pRight->flags;
|
||||
#if SQLITE_MAX_EXPR_DEPTH>0
|
||||
pRoot->nHeight = pRight->nHeight+1;
|
||||
}else{
|
||||
pRoot->nHeight = 1;
|
||||
#endif
|
||||
}
|
||||
if( pLeft ){
|
||||
pRoot->pLeft = pLeft;
|
||||
pRoot->flags |= EP_Propagate & pLeft->flags;
|
||||
#if SQLITE_MAX_EXPR_DEPTH>0
|
||||
if( pLeft->nHeight>=pRoot->nHeight ){
|
||||
pRoot->nHeight = pLeft->nHeight+1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
exprSetHeight(pRoot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1069,6 +1082,7 @@ Expr *sqlite3ExprFunction(
|
||||
sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
|
||||
return 0;
|
||||
}
|
||||
assert( !ExprHasProperty(pNew, EP_InnerON|EP_OuterON) );
|
||||
pNew->w.iOfst = (int)(pToken->z - pParse->zTail);
|
||||
if( pList
|
||||
&& pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG]
|
||||
@@ -1206,6 +1220,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
|
||||
*/
|
||||
static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
|
||||
assert( p!=0 );
|
||||
assert( db!=0 );
|
||||
assert( !ExprUseUValue(p) || p->u.iValue>=0 );
|
||||
assert( !ExprUseYWin(p) || !ExprUseYSub(p) );
|
||||
assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
|
||||
@@ -1237,18 +1252,26 @@ static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if( ExprHasProperty(p, EP_MemToken) ){
|
||||
assert( !ExprHasProperty(p, EP_IntValue) );
|
||||
sqlite3DbFree(db, p->u.zToken);
|
||||
}
|
||||
if( !ExprHasProperty(p, EP_Static) ){
|
||||
sqlite3DbFreeNN(db, p);
|
||||
sqlite3DbNNFreeNN(db, p);
|
||||
}
|
||||
}
|
||||
void sqlite3ExprDelete(sqlite3 *db, Expr *p){
|
||||
if( p ) sqlite3ExprDeleteNN(db, p);
|
||||
}
|
||||
|
||||
/*
|
||||
** Clear both elements of an OnOrUsing object
|
||||
*/
|
||||
void sqlite3ClearOnOrUsing(sqlite3 *db, OnOrUsing *p){
|
||||
if( p==0 ){
|
||||
/* Nothing to clear */
|
||||
}else if( p->pOn ){
|
||||
sqlite3ExprDeleteNN(db, p->pOn);
|
||||
}else if( p->pUsing ){
|
||||
sqlite3IdListDelete(db, p->pUsing);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Arrange to cause pExpr to be deleted when the pParse is deleted.
|
||||
@@ -1261,8 +1284,9 @@ void sqlite3ExprDelete(sqlite3 *db, Expr *p){
|
||||
** 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);
|
||||
sqlite3ParserAddCleanup(pParse,
|
||||
(void(*)(sqlite3*,void*))sqlite3ExprDelete,
|
||||
pExpr);
|
||||
}
|
||||
|
||||
/* Invoke sqlite3RenameExprUnmap() and sqlite3ExprDelete() on the
|
||||
@@ -1335,8 +1359,7 @@ static int dupedExprStructSize(const Expr *p, int flags){
|
||||
nSize = EXPR_FULLSIZE;
|
||||
}else{
|
||||
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
|
||||
assert( !ExprHasProperty(p, EP_FromJoin) );
|
||||
assert( !ExprHasProperty(p, EP_MemToken) );
|
||||
assert( !ExprHasProperty(p, EP_OuterON) );
|
||||
assert( !ExprHasVVAProperty(p, EP_NoReduce) );
|
||||
if( p->pLeft || p->x.pList ){
|
||||
nSize = EXPR_REDUCEDSIZE | EP_Reduced;
|
||||
@@ -1440,7 +1463,7 @@ static Expr *exprDup(sqlite3 *db, const Expr *p, int dupFlags, u8 **pzBuffer){
|
||||
}
|
||||
|
||||
/* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
|
||||
pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
|
||||
pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static);
|
||||
pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
|
||||
pNew->flags |= staticFlag;
|
||||
ExprClearVVAProperties(pNew);
|
||||
@@ -1515,6 +1538,7 @@ With *sqlite3WithDup(sqlite3 *db, With *p){
|
||||
pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
|
||||
pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
|
||||
pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
|
||||
pRet->a[i].eM10d = p->a[i].eM10d;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1615,11 +1639,8 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, const ExprList *p, int flags){
|
||||
}
|
||||
}
|
||||
pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
|
||||
pItem->sortFlags = pOldItem->sortFlags;
|
||||
pItem->eEName = pOldItem->eEName;
|
||||
pItem->done = 0;
|
||||
pItem->bNulls = pOldItem->bNulls;
|
||||
pItem->bSorterRef = pOldItem->bSorterRef;
|
||||
pItem->fg = pOldItem->fg;
|
||||
pItem->fg.done = 0;
|
||||
pItem->u = pOldItem->u;
|
||||
}
|
||||
return pNew;
|
||||
@@ -1671,8 +1692,12 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, const SrcList *p, int flags){
|
||||
pTab->nTabRef++;
|
||||
}
|
||||
pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
|
||||
pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
|
||||
pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
|
||||
if( pOldItem->fg.isUsing ){
|
||||
assert( pNewItem->fg.isUsing );
|
||||
pNewItem->u3.pUsing = sqlite3IdListDup(db, pOldItem->u3.pUsing);
|
||||
}else{
|
||||
pNewItem->u3.pOn = sqlite3ExprDup(db, pOldItem->u3.pOn, flags);
|
||||
}
|
||||
pNewItem->colUsed = pOldItem->colUsed;
|
||||
}
|
||||
return pNew;
|
||||
@@ -1682,22 +1707,16 @@ IdList *sqlite3IdListDup(sqlite3 *db, const IdList *p){
|
||||
int i;
|
||||
assert( db!=0 );
|
||||
if( p==0 ) return 0;
|
||||
pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
|
||||
assert( p->eU4!=EU4_EXPR );
|
||||
pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew)+(p->nId-1)*sizeof(p->a[0]) );
|
||||
if( pNew==0 ) return 0;
|
||||
pNew->nId = p->nId;
|
||||
pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) );
|
||||
if( pNew->a==0 ){
|
||||
sqlite3DbFreeNN(db, pNew);
|
||||
return 0;
|
||||
}
|
||||
/* Note that because the size of the allocation for p->a[] is not
|
||||
** necessarily a power of two, sqlite3IdListAppend() may not be called
|
||||
** on the duplicate created by this function. */
|
||||
pNew->eU4 = p->eU4;
|
||||
for(i=0; i<p->nId; i++){
|
||||
struct IdList_item *pNewItem = &pNew->a[i];
|
||||
struct IdList_item *pOldItem = &p->a[i];
|
||||
const struct IdList_item *pOldItem = &p->a[i];
|
||||
pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
|
||||
pNewItem->idx = pOldItem->idx;
|
||||
pNewItem->u4 = pOldItem->u4;
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
@@ -1921,16 +1940,16 @@ void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder, int eNulls){
|
||||
);
|
||||
|
||||
pItem = &p->a[p->nExpr-1];
|
||||
assert( pItem->bNulls==0 );
|
||||
assert( pItem->fg.bNulls==0 );
|
||||
if( iSortOrder==SQLITE_SO_UNDEFINED ){
|
||||
iSortOrder = SQLITE_SO_ASC;
|
||||
}
|
||||
pItem->sortFlags = (u8)iSortOrder;
|
||||
pItem->fg.sortFlags = (u8)iSortOrder;
|
||||
|
||||
if( eNulls!=SQLITE_SO_UNDEFINED ){
|
||||
pItem->bNulls = 1;
|
||||
pItem->fg.bNulls = 1;
|
||||
if( iSortOrder!=eNulls ){
|
||||
pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
|
||||
pItem->fg.sortFlags |= KEYINFO_ORDER_BIGNULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1956,7 +1975,7 @@ void sqlite3ExprListSetName(
|
||||
assert( pList->nExpr>0 );
|
||||
pItem = &pList->a[pList->nExpr-1];
|
||||
assert( pItem->zEName==0 );
|
||||
assert( pItem->eEName==ENAME_NAME );
|
||||
assert( pItem->fg.eEName==ENAME_NAME );
|
||||
pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
|
||||
if( dequote ){
|
||||
/* If dequote==0, then pName->z does not point to part of a DDL
|
||||
@@ -1991,7 +2010,7 @@ void sqlite3ExprListSetSpan(
|
||||
assert( pList->nExpr>0 );
|
||||
if( pItem->zEName==0 ){
|
||||
pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
|
||||
pItem->eEName = ENAME_SPAN;
|
||||
pItem->fg.eEName = ENAME_SPAN;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2020,12 +2039,13 @@ static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
|
||||
int i = pList->nExpr;
|
||||
struct ExprList_item *pItem = pList->a;
|
||||
assert( pList->nExpr>0 );
|
||||
assert( db!=0 );
|
||||
do{
|
||||
sqlite3ExprDelete(db, pItem->pExpr);
|
||||
sqlite3DbFree(db, pItem->zEName);
|
||||
if( pItem->zEName ) sqlite3DbNNFreeNN(db, pItem->zEName);
|
||||
pItem++;
|
||||
}while( --i>0 );
|
||||
sqlite3DbFreeNN(db, pList);
|
||||
sqlite3DbNNFreeNN(db, pList);
|
||||
}
|
||||
void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
|
||||
if( pList ) exprListDeleteNN(db, pList);
|
||||
@@ -2163,9 +2183,9 @@ Expr *sqlite3ExprSimplifiedAndOr(Expr *pExpr){
|
||||
static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
|
||||
|
||||
/* If pWalker->eCode is 2 then any term of the expression that comes from
|
||||
** the ON or USING clauses of a left join disqualifies the expression
|
||||
** the ON or USING clauses of an outer join disqualifies the expression
|
||||
** from being considered constant. */
|
||||
if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
|
||||
if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_OuterON) ){
|
||||
pWalker->eCode = 0;
|
||||
return WRC_Abort;
|
||||
}
|
||||
@@ -2284,6 +2304,42 @@ int sqlite3ExprIsTableConstant(Expr *p, int iCur){
|
||||
return exprIsConst(p, 3, iCur);
|
||||
}
|
||||
|
||||
/*
|
||||
** Check pExpr to see if it is an invariant constraint on data source pSrc.
|
||||
** This is an optimization. False negatives will perhaps cause slower
|
||||
** queries, but false positives will yield incorrect answers. So when in
|
||||
** doubt, return 0.
|
||||
**
|
||||
** To be an invariant constraint, the following must be true:
|
||||
**
|
||||
** (1) pExpr cannot refer to any table other than pSrc->iCursor.
|
||||
**
|
||||
** (2) pExpr cannot use subqueries or non-deterministic functions.
|
||||
**
|
||||
** (3) pSrc cannot be part of the left operand for a RIGHT JOIN.
|
||||
** (Is there some way to relax this constraint?)
|
||||
**
|
||||
** (4) If pSrc is the right operand of a LEFT JOIN, then...
|
||||
** (4a) pExpr must come from an ON clause..
|
||||
(4b) and specifically the ON clause associated with the LEFT JOIN.
|
||||
**
|
||||
** (5) If pSrc is not the right operand of a LEFT JOIN or the left
|
||||
** operand of a RIGHT JOIN, then pExpr must be from the WHERE
|
||||
** clause, not an ON clause.
|
||||
*/
|
||||
int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
|
||||
if( pSrc->fg.jointype & JT_LTORJ ){
|
||||
return 0; /* rule (3) */
|
||||
}
|
||||
if( pSrc->fg.jointype & JT_LEFT ){
|
||||
if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */
|
||||
if( pExpr->w.iJoin!=pSrc->iCursor ) return 0; /* rule (4b) */
|
||||
}else{
|
||||
if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (5) */
|
||||
}
|
||||
return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
|
||||
@@ -2611,7 +2667,7 @@ static int sqlite3InRhsIsConstant(Expr *pIn){
|
||||
** all members of the RHS set, skipping duplicates.
|
||||
**
|
||||
** A cursor is opened on the b-tree object that is the RHS of the IN operator
|
||||
** and pX->iTable is set to the index of that cursor.
|
||||
** and the *piTab parameter is set to the index of that cursor.
|
||||
**
|
||||
** The returned value of this function indicates the b-tree type, as follows:
|
||||
**
|
||||
@@ -2631,7 +2687,10 @@ static int sqlite3InRhsIsConstant(Expr *pIn){
|
||||
** If the RHS of the IN operator is a list or a more complex subquery, then
|
||||
** an ephemeral table might need to be generated from the RHS and then
|
||||
** pX->iTable made to point to the ephemeral table instead of an
|
||||
** existing table.
|
||||
** existing table. In this case, the creation and initialization of the
|
||||
** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag
|
||||
** will be set on pX and the pX->y.sub fields will be set to show where
|
||||
** the subroutine is coded.
|
||||
**
|
||||
** The inFlags parameter must contain, at a minimum, one of the bits
|
||||
** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
|
||||
@@ -2692,12 +2751,13 @@ int sqlite3FindInIndex(
|
||||
){
|
||||
Select *p; /* SELECT to the right of IN operator */
|
||||
int eType = 0; /* Type of RHS table. IN_INDEX_* */
|
||||
int iTab = pParse->nTab++; /* Cursor of the RHS table */
|
||||
int iTab; /* Cursor of the RHS table */
|
||||
int mustBeUnique; /* True if RHS must be unique */
|
||||
Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
|
||||
|
||||
assert( pX->op==TK_IN );
|
||||
mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
|
||||
iTab = pParse->nTab++;
|
||||
|
||||
/* If the RHS of this IN(...) operator is a SELECT, and if it matters
|
||||
** whether or not the SELECT result contains NULL values, check whether
|
||||
@@ -2863,6 +2923,8 @@ int sqlite3FindInIndex(
|
||||
&& ExprUseXList(pX)
|
||||
&& (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
|
||||
){
|
||||
pParse->nTab--; /* Back out the allocation of the unused cursor */
|
||||
iTab = -1; /* Cursor is not allocated */
|
||||
eType = IN_INDEX_NOOP;
|
||||
}
|
||||
|
||||
@@ -3029,6 +3091,7 @@ void sqlite3CodeRhsOfIN(
|
||||
assert( ExprUseYSub(pExpr) );
|
||||
sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
|
||||
pExpr->y.sub.iAddr);
|
||||
assert( iTab!=pExpr->iTable );
|
||||
sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
|
||||
sqlite3VdbeJumpHere(v, addrOnce);
|
||||
return;
|
||||
@@ -3160,14 +3223,15 @@ void sqlite3CodeRhsOfIN(
|
||||
sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
|
||||
}
|
||||
if( addrOnce ){
|
||||
sqlite3VdbeAddOp1(v, OP_NullRow, iTab);
|
||||
sqlite3VdbeJumpHere(v, addrOnce);
|
||||
/* Subroutine return */
|
||||
assert( ExprUseYSub(pExpr) );
|
||||
assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
|
||||
|| pParse->nErr );
|
||||
sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn, 0,
|
||||
pExpr->y.sub.iAddr-1);
|
||||
sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
|
||||
sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn,
|
||||
pExpr->y.sub.iAddr, 1);
|
||||
VdbeCoverage(v);
|
||||
sqlite3ClearTempRegCache(pParse);
|
||||
}
|
||||
}
|
||||
@@ -3273,7 +3337,7 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
pLimit = sqlite3PExpr(pParse, TK_NE,
|
||||
sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
|
||||
}
|
||||
sqlite3ExprDelete(db, pSel->pLimit->pLeft);
|
||||
sqlite3ExprDeferredDelete(pParse, pSel->pLimit->pLeft);
|
||||
pSel->pLimit->pLeft = pLimit;
|
||||
}else{
|
||||
/* If there is no pre-existing limit add a limit of 1 */
|
||||
@@ -3296,9 +3360,9 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
assert( ExprUseYSub(pExpr) );
|
||||
assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
|
||||
|| pParse->nErr );
|
||||
sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn, 0,
|
||||
pExpr->y.sub.iAddr-1);
|
||||
sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
|
||||
sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn,
|
||||
pExpr->y.sub.iAddr, 1);
|
||||
VdbeCoverage(v);
|
||||
sqlite3ClearTempRegCache(pParse);
|
||||
return rReg;
|
||||
}
|
||||
@@ -3732,6 +3796,7 @@ void sqlite3ExprCodeGetColumnOfTable(
|
||||
}
|
||||
if( iCol<0 || iCol==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
|
||||
VdbeComment((v, "%s.rowid", pTab->zName));
|
||||
}else{
|
||||
int op;
|
||||
int x;
|
||||
@@ -3786,7 +3851,7 @@ int sqlite3ExprCodeGetColumn(
|
||||
assert( pParse->pVdbe!=0 );
|
||||
sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pTab, iTable, iColumn, iReg);
|
||||
if( p5 ){
|
||||
VdbeOp *pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
|
||||
VdbeOp *pOp = sqlite3VdbeGetLastOp(pParse->pVdbe);
|
||||
if( pOp->opcode==OP_Column ) pOp->p5 = p5;
|
||||
}
|
||||
return iReg;
|
||||
@@ -3855,7 +3920,7 @@ static int exprCodeVector(Parse *pParse, Expr *p, int *piFreeable){
|
||||
** so that a subsequent copy will not be merged into this one.
|
||||
*/
|
||||
static void setDoNotMergeFlagOnCopy(Vdbe *v){
|
||||
if( sqlite3VdbeGetOp(v, -1)->opcode==OP_Copy ){
|
||||
if( sqlite3VdbeGetLastOp(v)->opcode==OP_Copy ){
|
||||
sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */
|
||||
}
|
||||
}
|
||||
@@ -3902,7 +3967,17 @@ static int exprCodeInlineFunction(
|
||||
caseExpr.x.pList = pFarg;
|
||||
return sqlite3ExprCodeTarget(pParse, &caseExpr, target);
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
case INLINEFUNC_sqlite_offset: {
|
||||
Expr *pArg = pFarg->a[0].pExpr;
|
||||
if( pArg->op==TK_COLUMN && pArg->iTable>=0 ){
|
||||
sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
|
||||
}else{
|
||||
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default: {
|
||||
/* The UNLIKELY() function is a no-op. The result is the value
|
||||
** of the first argument.
|
||||
@@ -4016,7 +4091,7 @@ expr_code_doover:
|
||||
pCol->iSorterColumn, target);
|
||||
if( pCol->iColumn<0 ){
|
||||
VdbeComment((v,"%s.rowid",pTab->zName));
|
||||
}else{
|
||||
}else if( ALWAYS(pTab!=0) ){
|
||||
VdbeComment((v,"%s.%s",
|
||||
pTab->zName, pTab->aCol[pCol->iColumn].zCnName));
|
||||
if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){
|
||||
@@ -4441,20 +4516,8 @@ expr_code_doover:
|
||||
if( !pColl ) pColl = db->pDfltColl;
|
||||
sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
|
||||
}
|
||||
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
if( (pDef->funcFlags & SQLITE_FUNC_OFFSET)!=0 && ALWAYS(pFarg!=0) ){
|
||||
Expr *pArg = pFarg->a[0].pExpr;
|
||||
if( pArg->op==TK_COLUMN ){
|
||||
sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
|
||||
}else{
|
||||
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
|
||||
pDef, pExpr->op2);
|
||||
}
|
||||
sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
|
||||
pDef, pExpr->op2);
|
||||
if( nFarg ){
|
||||
if( constMask==0 ){
|
||||
sqlite3ReleaseTempRange(pParse, r1, nFarg);
|
||||
@@ -4484,16 +4547,18 @@ expr_code_doover:
|
||||
}
|
||||
case TK_SELECT_COLUMN: {
|
||||
int n;
|
||||
if( pExpr->pLeft->iTable==0 ){
|
||||
pExpr->pLeft->iTable = sqlite3CodeSubselect(pParse, pExpr->pLeft);
|
||||
Expr *pLeft = pExpr->pLeft;
|
||||
if( pLeft->iTable==0 || pParse->withinRJSubrtn > pLeft->op2 ){
|
||||
pLeft->iTable = sqlite3CodeSubselect(pParse, pLeft);
|
||||
pLeft->op2 = pParse->withinRJSubrtn;
|
||||
}
|
||||
assert( pExpr->pLeft->op==TK_SELECT || pExpr->pLeft->op==TK_ERROR );
|
||||
n = sqlite3ExprVectorSize(pExpr->pLeft);
|
||||
assert( pLeft->op==TK_SELECT || pLeft->op==TK_ERROR );
|
||||
n = sqlite3ExprVectorSize(pLeft);
|
||||
if( pExpr->iTable!=n ){
|
||||
sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
|
||||
pExpr->iTable, n);
|
||||
}
|
||||
return pExpr->pLeft->iTable + pExpr->iColumn;
|
||||
return pLeft->iTable + pExpr->iColumn;
|
||||
}
|
||||
case TK_IN: {
|
||||
int destIfFalse = sqlite3VdbeMakeLabel(pParse);
|
||||
@@ -4524,8 +4589,24 @@ expr_code_doover:
|
||||
exprCodeBetween(pParse, pExpr, target, 0, 0);
|
||||
return target;
|
||||
}
|
||||
case TK_COLLATE: {
|
||||
if( !ExprHasProperty(pExpr, EP_Collate)
|
||||
&& ALWAYS(pExpr->pLeft)
|
||||
&& pExpr->pLeft->op==TK_FUNCTION
|
||||
){
|
||||
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
|
||||
if( inReg!=target ){
|
||||
sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
|
||||
inReg = target;
|
||||
}
|
||||
sqlite3VdbeAddOp1(v, OP_ClrSubtype, inReg);
|
||||
return inReg;
|
||||
}else{
|
||||
pExpr = pExpr->pLeft;
|
||||
goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. */
|
||||
}
|
||||
}
|
||||
case TK_SPAN:
|
||||
case TK_COLLATE:
|
||||
case TK_UPLUS: {
|
||||
pExpr = pExpr->pLeft;
|
||||
goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. OSSFuzz. */
|
||||
@@ -4605,6 +4686,21 @@ expr_code_doover:
|
||||
case TK_IF_NULL_ROW: {
|
||||
int addrINR;
|
||||
u8 okConstFactor = pParse->okConstFactor;
|
||||
AggInfo *pAggInfo = pExpr->pAggInfo;
|
||||
if( pAggInfo ){
|
||||
assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
|
||||
if( !pAggInfo->directMode ){
|
||||
inReg = pAggInfo->aCol[pExpr->iAgg].iMem;
|
||||
break;
|
||||
}
|
||||
if( pExpr->pAggInfo->useSortingIdx ){
|
||||
sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
|
||||
pAggInfo->aCol[pExpr->iAgg].iSorterColumn,
|
||||
target);
|
||||
inReg = target;
|
||||
break;
|
||||
}
|
||||
}
|
||||
addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
|
||||
/* Temporarily disable factoring of constant expressions, since
|
||||
** even though expressions may appear to be constant, they are not
|
||||
@@ -4766,7 +4862,9 @@ int sqlite3ExprCodeRunJustOnce(
|
||||
struct ExprList_item *pItem;
|
||||
int i;
|
||||
for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
|
||||
if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){
|
||||
if( pItem->fg.reusable
|
||||
&& sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
|
||||
){
|
||||
return pItem->u.iConstExprReg;
|
||||
}
|
||||
}
|
||||
@@ -4789,7 +4887,7 @@ int sqlite3ExprCodeRunJustOnce(
|
||||
p = sqlite3ExprListAppend(pParse, p, pExpr);
|
||||
if( p ){
|
||||
struct ExprList_item *pItem = &p->a[p->nExpr-1];
|
||||
pItem->reusable = regDest<0;
|
||||
pItem->fg.reusable = regDest<0;
|
||||
if( regDest<0 ) regDest = ++pParse->nMem;
|
||||
pItem->u.iConstExprReg = regDest;
|
||||
}
|
||||
@@ -4923,7 +5021,7 @@ int sqlite3ExprCodeExprList(
|
||||
for(pItem=pList->a, i=0; i<n; i++, pItem++){
|
||||
Expr *pExpr = pItem->pExpr;
|
||||
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
|
||||
if( pItem->bSorterRef ){
|
||||
if( pItem->fg.bSorterRef ){
|
||||
i--;
|
||||
n--;
|
||||
}else
|
||||
@@ -4944,7 +5042,7 @@ int sqlite3ExprCodeExprList(
|
||||
if( inReg!=target+i ){
|
||||
VdbeOp *pOp;
|
||||
if( copyOp==OP_Copy
|
||||
&& (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
|
||||
&& (pOp=sqlite3VdbeGetLastOp(v))->opcode==OP_Copy
|
||||
&& pOp->p1+pOp->p3+1==inReg
|
||||
&& pOp->p2+pOp->p3+1==target+i
|
||||
&& pOp->p5==0 /* The do-not-merge flag must be clear */
|
||||
@@ -5017,8 +5115,8 @@ static void exprCodeBetween(
|
||||
** so that the sqlite3ExprCodeTarget() routine will not attempt to move
|
||||
** it into the Parse.pConstExpr list. We should use a new bit for this,
|
||||
** for clarity, but we are out of bits in the Expr.flags field so we
|
||||
** have to reuse the EP_FromJoin bit. Bummer. */
|
||||
pDel->flags |= EP_FromJoin;
|
||||
** have to reuse the EP_OuterON bit. Bummer. */
|
||||
pDel->flags |= EP_OuterON;
|
||||
sqlite3ExprCodeTarget(pParse, &exprAnd, dest);
|
||||
}
|
||||
sqlite3ReleaseTempReg(pParse, regFree1);
|
||||
@@ -5548,7 +5646,7 @@ int sqlite3ExprListCompare(const ExprList *pA, const ExprList *pB, int iTab){
|
||||
int res;
|
||||
Expr *pExprA = pA->a[i].pExpr;
|
||||
Expr *pExprB = pB->a[i].pExpr;
|
||||
if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
|
||||
if( pA->a[i].fg.sortFlags!=pB->a[i].fg.sortFlags ) return 1;
|
||||
if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
|
||||
}
|
||||
return 0;
|
||||
@@ -5703,7 +5801,7 @@ int sqlite3ExprImpliesExpr(
|
||||
static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
|
||||
testcase( pExpr->op==TK_AGG_COLUMN );
|
||||
testcase( pExpr->op==TK_AGG_FUNCTION );
|
||||
if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune;
|
||||
if( ExprHasProperty(pExpr, EP_OuterON) ) return WRC_Prune;
|
||||
switch( pExpr->op ){
|
||||
case TK_ISNOT:
|
||||
case TK_ISNULL:
|
||||
@@ -5800,8 +5898,8 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
|
||||
** False positives are not allowed, however. A false positive may result
|
||||
** in an incorrect answer.
|
||||
**
|
||||
** Terms of p that are marked with EP_FromJoin (and hence that come from
|
||||
** the ON or USING clauses of LEFT JOINS) are excluded from the analysis.
|
||||
** Terms of p that are marked with EP_OuterON (and hence that come from
|
||||
** the ON or USING clauses of OUTER JOINS) are excluded from the analysis.
|
||||
**
|
||||
** This routine is used to check if a LEFT JOIN can be converted into
|
||||
** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE
|
||||
@@ -5980,6 +6078,7 @@ static int exprRefToSrcList(Walker *pWalker, Expr *pExpr){
|
||||
int sqlite3ReferencesSrcList(Parse *pParse, Expr *pExpr, SrcList *pSrcList){
|
||||
Walker w;
|
||||
struct RefSrcList x;
|
||||
assert( pParse->db!=0 );
|
||||
memset(&w, 0, sizeof(w));
|
||||
memset(&x, 0, sizeof(x));
|
||||
w.xExprCallback = exprRefToSrcList;
|
||||
@@ -5996,7 +6095,7 @@ int sqlite3ReferencesSrcList(Parse *pParse, Expr *pExpr, SrcList *pSrcList){
|
||||
sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
|
||||
}
|
||||
#endif
|
||||
sqlite3DbFree(pParse->db, x.aiExclude);
|
||||
if( x.aiExclude ) sqlite3DbNNFreeNN(pParse->db, x.aiExclude);
|
||||
if( w.eCode & 0x01 ){
|
||||
return 1;
|
||||
}else if( w.eCode ){
|
||||
@@ -6027,8 +6126,8 @@ static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
|
||||
int iAgg = pExpr->iAgg;
|
||||
Parse *pParse = pWalker->pParse;
|
||||
sqlite3 *db = pParse->db;
|
||||
assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION );
|
||||
if( pExpr->op==TK_AGG_COLUMN ){
|
||||
if( pExpr->op!=TK_AGG_FUNCTION ){
|
||||
assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_IF_NULL_ROW );
|
||||
assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
|
||||
if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
|
||||
pExpr = sqlite3ExprDup(db, pExpr, 0);
|
||||
@@ -6038,6 +6137,7 @@ static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
|
||||
}
|
||||
}
|
||||
}else{
|
||||
assert( pExpr->op==TK_AGG_FUNCTION );
|
||||
assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
|
||||
if( pAggInfo->aFunc[iAgg].pFExpr==pExpr ){
|
||||
pExpr = sqlite3ExprDup(db, pExpr, 0);
|
||||
@@ -6108,10 +6208,12 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
|
||||
assert( pNC->ncFlags & NC_UAggInfo );
|
||||
switch( pExpr->op ){
|
||||
case TK_IF_NULL_ROW:
|
||||
case TK_AGG_COLUMN:
|
||||
case TK_COLUMN: {
|
||||
testcase( pExpr->op==TK_AGG_COLUMN );
|
||||
testcase( pExpr->op==TK_COLUMN );
|
||||
testcase( pExpr->op==TK_IF_NULL_ROW );
|
||||
/* Check to see if the column is in one of the tables in the FROM
|
||||
** clause of the aggregate query */
|
||||
if( ALWAYS(pSrcList!=0) ){
|
||||
@@ -6129,8 +6231,10 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
int k;
|
||||
pCol = pAggInfo->aCol;
|
||||
for(k=0; k<pAggInfo->nColumn; k++, pCol++){
|
||||
if( pCol->iTable==pExpr->iTable &&
|
||||
pCol->iColumn==pExpr->iColumn ){
|
||||
if( pCol->iTable==pExpr->iTable
|
||||
&& pCol->iColumn==pExpr->iColumn
|
||||
&& pExpr->op!=TK_IF_NULL_ROW
|
||||
){
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -6145,15 +6249,17 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
pCol->iMem = ++pParse->nMem;
|
||||
pCol->iSorterColumn = -1;
|
||||
pCol->pCExpr = pExpr;
|
||||
if( pAggInfo->pGroupBy ){
|
||||
if( pAggInfo->pGroupBy && pExpr->op!=TK_IF_NULL_ROW ){
|
||||
int j, n;
|
||||
ExprList *pGB = pAggInfo->pGroupBy;
|
||||
struct ExprList_item *pTerm = pGB->a;
|
||||
n = pGB->nExpr;
|
||||
for(j=0; j<n; j++, pTerm++){
|
||||
Expr *pE = pTerm->pExpr;
|
||||
if( pE->op==TK_COLUMN && pE->iTable==pExpr->iTable &&
|
||||
pE->iColumn==pExpr->iColumn ){
|
||||
if( pE->op==TK_COLUMN
|
||||
&& pE->iTable==pExpr->iTable
|
||||
&& pE->iColumn==pExpr->iColumn
|
||||
){
|
||||
pCol->iSorterColumn = j;
|
||||
break;
|
||||
}
|
||||
@@ -6170,7 +6276,9 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
*/
|
||||
ExprSetVVAProperty(pExpr, EP_NoReduce);
|
||||
pExpr->pAggInfo = pAggInfo;
|
||||
pExpr->op = TK_AGG_COLUMN;
|
||||
if( pExpr->op==TK_COLUMN ){
|
||||
pExpr->op = TK_AGG_COLUMN;
|
||||
}
|
||||
pExpr->iAgg = (i16)k;
|
||||
break;
|
||||
} /* endif pExpr->iTable==pItem->iCursor */
|
||||
|
||||
+15
-15
@@ -390,7 +390,6 @@ static void fkLookupParent(
|
||||
}else{
|
||||
int nCol = pFKey->nCol;
|
||||
int regTemp = sqlite3GetTempRange(pParse, nCol);
|
||||
int regRec = sqlite3GetTempReg(pParse);
|
||||
|
||||
sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
|
||||
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
|
||||
@@ -429,12 +428,11 @@ static void fkLookupParent(
|
||||
}
|
||||
sqlite3VdbeGoto(v, iOk);
|
||||
}
|
||||
|
||||
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
|
||||
|
||||
sqlite3VdbeAddOp4(v, OP_Affinity, regTemp, nCol, 0,
|
||||
sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
|
||||
sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
|
||||
|
||||
sqlite3ReleaseTempReg(pParse, regRec);
|
||||
sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regTemp, nCol);
|
||||
VdbeCoverage(v);
|
||||
sqlite3ReleaseTempRange(pParse, regTemp, nCol);
|
||||
}
|
||||
}
|
||||
@@ -536,14 +534,10 @@ static Expr *exprTableColumn(
|
||||
** Operation | FK type | Action taken
|
||||
** --------------------------------------------------------------------------
|
||||
** DELETE immediate Increment the "immediate constraint counter".
|
||||
** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
|
||||
** throw a "FOREIGN KEY constraint failed" exception.
|
||||
**
|
||||
** INSERT immediate Decrement the "immediate constraint counter".
|
||||
**
|
||||
** DELETE deferred Increment the "deferred constraint counter".
|
||||
** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
|
||||
** throw a "FOREIGN KEY constraint failed" exception.
|
||||
**
|
||||
** INSERT deferred Decrement the "deferred constraint counter".
|
||||
**
|
||||
@@ -1191,9 +1185,9 @@ int sqlite3FkRequired(
|
||||
**
|
||||
** It returns a pointer to a Trigger structure containing a trigger
|
||||
** equivalent to the ON UPDATE or ON DELETE action specified by pFKey.
|
||||
** If the action is "NO ACTION" or "RESTRICT", then a NULL pointer is
|
||||
** returned (these actions require no special handling by the triggers
|
||||
** sub-system, code for them is created by fkScanChildren()).
|
||||
** If the action is "NO ACTION" then a NULL pointer is returned (these actions
|
||||
** require no special handling by the triggers sub-system, code for them is
|
||||
** created by fkScanChildren()).
|
||||
**
|
||||
** For example, if pFKey is the foreign key and pTab is table "p" in
|
||||
** the following schema:
|
||||
@@ -1322,18 +1316,23 @@ static Trigger *fkActionTrigger(
|
||||
nFrom = sqlite3Strlen30(zFrom);
|
||||
|
||||
if( action==OE_Restrict ){
|
||||
int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
Token tFrom;
|
||||
Token tDb;
|
||||
Expr *pRaise;
|
||||
|
||||
tFrom.z = zFrom;
|
||||
tFrom.n = nFrom;
|
||||
tDb.z = db->aDb[iDb].zDbSName;
|
||||
tDb.n = sqlite3Strlen30(tDb.z);
|
||||
|
||||
pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
|
||||
if( pRaise ){
|
||||
pRaise->affExpr = OE_Abort;
|
||||
}
|
||||
pSelect = sqlite3SelectNew(pParse,
|
||||
sqlite3ExprListAppend(pParse, 0, pRaise),
|
||||
sqlite3SrcListAppend(pParse, 0, &tFrom, 0),
|
||||
sqlite3SrcListAppend(pParse, 0, &tDb, &tFrom),
|
||||
pWhere,
|
||||
0, 0, 0, 0, 0
|
||||
);
|
||||
@@ -1440,11 +1439,12 @@ void sqlite3FkDelete(sqlite3 *db, Table *pTab){
|
||||
FKey *pNext; /* Copy of pFKey->pNextFrom */
|
||||
|
||||
assert( IsOrdinaryTable(pTab) );
|
||||
assert( db!=0 );
|
||||
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
|
||||
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
|
||||
|
||||
/* Remove the FK from the fkeyHash hash table. */
|
||||
if( !db || db->pnBytesFreed==0 ){
|
||||
if( db->pnBytesFreed==0 ){
|
||||
if( pFKey->pPrevTo ){
|
||||
pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
|
||||
}else{
|
||||
|
||||
+3
-4
@@ -2098,11 +2098,11 @@ static void logFunc(
|
||||
switch( SQLITE_PTR_TO_INT(sqlite3_user_data(context)) ){
|
||||
case 1:
|
||||
/* Convert from natural logarithm to log base 10 */
|
||||
ans *= 1.0/M_LN10;
|
||||
ans /= M_LN10;
|
||||
break;
|
||||
case 2:
|
||||
/* Convert from natural logarithm to log base 2 */
|
||||
ans *= 1.0/M_LN2;
|
||||
ans /= M_LN2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -2241,8 +2241,7 @@ void sqlite3RegisterBuiltinFunctions(void){
|
||||
INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
|
||||
INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
|
||||
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
{1, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_OFFSET|SQLITE_FUNC_TYPEOF,
|
||||
0, 0, noopFunc, 0, 0, 0, "sqlite_offset", {0} },
|
||||
INLINE_FUNC(sqlite_offset, 1, INLINEFUNC_sqlite_offset, 0 ),
|
||||
#endif
|
||||
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
|
||||
FUNCTION(ltrim, 2, 1, 0, trimFunc ),
|
||||
|
||||
+1
-1
@@ -347,7 +347,7 @@ int sqlite3PendingByte = 0x40000000;
|
||||
/*
|
||||
** Tracing flags set by SQLITE_TESTCTRL_TRACEFLAGS.
|
||||
*/
|
||||
u32 sqlite3SelectTrace = 0;
|
||||
u32 sqlite3TreeTrace = 0;
|
||||
u32 sqlite3WhereTrace = 0;
|
||||
|
||||
#include "opcodes.h"
|
||||
|
||||
+28
-10
@@ -159,7 +159,7 @@ void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
|
||||
** OP_MakeRecord is found */
|
||||
VdbeOp *pPrev;
|
||||
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
|
||||
pPrev = sqlite3VdbeGetOp(v, -1);
|
||||
pPrev = sqlite3VdbeGetLastOp(v);
|
||||
assert( pPrev!=0 );
|
||||
assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
|
||||
pPrev->opcode = OP_TypeCheck;
|
||||
@@ -181,7 +181,7 @@ void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
|
||||
}
|
||||
|
||||
for(i=j=0; i<pTab->nCol; i++){
|
||||
assert( pTab->aCol[i].affinity!=0 );
|
||||
assert( pTab->aCol[i].affinity!=0 || sqlite3VdbeParser(v)->nErr>0 );
|
||||
if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
|
||||
zColAff[j++] = pTab->aCol[i].affinity;
|
||||
}
|
||||
@@ -197,7 +197,7 @@ void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
|
||||
if( iReg ){
|
||||
sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
|
||||
}else{
|
||||
assert( sqlite3VdbeGetOp(v, -1)->opcode==OP_MakeRecord
|
||||
assert( sqlite3VdbeGetLastOp(v)->opcode==OP_MakeRecord
|
||||
|| sqlite3VdbeDb(v)->mallocFailed );
|
||||
sqlite3VdbeChangeP4(v, -1, zColAff, i);
|
||||
}
|
||||
@@ -283,7 +283,7 @@ void sqlite3ComputeGeneratedColumns(
|
||||
*/
|
||||
sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
|
||||
if( (pTab->tabFlags & TF_HasStored)!=0 ){
|
||||
pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
|
||||
pOp = sqlite3VdbeGetLastOp(pParse->pVdbe);
|
||||
if( pOp->opcode==OP_Affinity ){
|
||||
/* Change the OP_Affinity argument to '@' (NONE) for all stored
|
||||
** columns. '@' is the no-op affinity and those columns have not
|
||||
@@ -765,6 +765,14 @@ void sqlite3Insert(
|
||||
#endif
|
||||
assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
|
||||
|
||||
#if TREETRACE_ENABLED
|
||||
if( sqlite3TreeTrace & 0x10000 ){
|
||||
sqlite3TreeViewLine(0, "In sqlite3Insert() at %s:%d", __FILE__, __LINE__);
|
||||
sqlite3TreeViewInsert(pParse->pWith, pTabList, pColumn, pSelect, pList,
|
||||
onError, pUpsert, pTrigger);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If pTab is really a view, make sure it has been initialized.
|
||||
** ViewGetColumnNames() is a no-op if pTab is not a view.
|
||||
*/
|
||||
@@ -843,13 +851,15 @@ void sqlite3Insert(
|
||||
*/
|
||||
bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
|
||||
if( pColumn ){
|
||||
assert( pColumn->eU4!=EU4_EXPR );
|
||||
pColumn->eU4 = EU4_IDX;
|
||||
for(i=0; i<pColumn->nId; i++){
|
||||
pColumn->a[i].idx = -1;
|
||||
pColumn->a[i].u4.idx = -1;
|
||||
}
|
||||
for(i=0; i<pColumn->nId; i++){
|
||||
for(j=0; j<pTab->nCol; j++){
|
||||
if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){
|
||||
pColumn->a[i].idx = j;
|
||||
pColumn->a[i].u4.idx = j;
|
||||
if( i!=j ) bIdListInOrder = 0;
|
||||
if( j==pTab->iPKey ){
|
||||
ipkColumn = i; assert( !withoutRowid );
|
||||
@@ -1151,7 +1161,8 @@ void sqlite3Insert(
|
||||
}
|
||||
}
|
||||
if( pColumn ){
|
||||
for(j=0; j<pColumn->nId && pColumn->a[j].idx!=i; j++){}
|
||||
assert( pColumn->eU4==EU4_IDX );
|
||||
for(j=0; j<pColumn->nId && pColumn->a[j].u4.idx!=i; j++){}
|
||||
if( j>=pColumn->nId ){
|
||||
/* A column not named in the insert column list gets its
|
||||
** default value */
|
||||
@@ -1178,7 +1189,12 @@ void sqlite3Insert(
|
||||
sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+k, iRegStore);
|
||||
}
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pList->a[k].pExpr, iRegStore);
|
||||
Expr *pX = pList->a[k].pExpr;
|
||||
int y = sqlite3ExprCodeTarget(pParse, pX, iRegStore);
|
||||
if( y!=iRegStore ){
|
||||
sqlite3VdbeAddOp2(v,
|
||||
ExprHasProperty(pX, EP_Subquery) ? OP_Copy : OP_SCopy, y, iRegStore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1315,7 +1331,9 @@ void sqlite3Insert(
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
|
||||
regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
|
||||
);
|
||||
sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
|
||||
if( db->flags & SQLITE_ForeignKeys ){
|
||||
sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
|
||||
}
|
||||
|
||||
/* Set the OPFLAG_USESEEKRESULT flag if either (a) there are no REPLACE
|
||||
** constraints or (b) there are no triggers and this table is not a
|
||||
@@ -1399,7 +1417,7 @@ insert_cleanup:
|
||||
sqlite3UpsertDelete(db, pUpsert);
|
||||
sqlite3SelectDelete(db, pSelect);
|
||||
sqlite3IdListDelete(db, pColumn);
|
||||
sqlite3DbFree(db, aRegIdx);
|
||||
if( aRegIdx ) sqlite3DbNNFreeNN(db, aRegIdx);
|
||||
}
|
||||
|
||||
/* Make sure "isView" and other macros defined above are undefined. Otherwise
|
||||
|
||||
+34
-10
@@ -1119,14 +1119,15 @@ static JsonNode *jsonLookupStep(
|
||||
*pzErr = zPath;
|
||||
return 0;
|
||||
}
|
||||
testcase( nKey==0 );
|
||||
}else{
|
||||
zKey = zPath;
|
||||
for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
|
||||
nKey = i;
|
||||
}
|
||||
if( nKey==0 ){
|
||||
*pzErr = zPath;
|
||||
return 0;
|
||||
if( nKey==0 ){
|
||||
*pzErr = zPath;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
j = 1;
|
||||
for(;;){
|
||||
@@ -2274,6 +2275,33 @@ static int jsonEachNext(sqlite3_vtab_cursor *cur){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* Append an object label to the JSON Path being constructed
|
||||
** in pStr.
|
||||
*/
|
||||
static void jsonAppendObjectPathElement(
|
||||
JsonString *pStr,
|
||||
JsonNode *pNode
|
||||
){
|
||||
int jj, nn;
|
||||
const char *z;
|
||||
assert( pNode->eType==JSON_STRING );
|
||||
assert( pNode->jnFlags & JNODE_LABEL );
|
||||
assert( pNode->eU==1 );
|
||||
z = pNode->u.zJContent;
|
||||
nn = pNode->n;
|
||||
assert( nn>=2 );
|
||||
assert( z[0]=='"' );
|
||||
assert( z[nn-1]=='"' );
|
||||
if( nn>2 && sqlite3Isalpha(z[1]) ){
|
||||
for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
|
||||
if( jj==nn-1 ){
|
||||
z++;
|
||||
nn -= 2;
|
||||
}
|
||||
}
|
||||
jsonPrintf(nn+2, pStr, ".%.*s", nn, z);
|
||||
}
|
||||
|
||||
/* Append the name of the path for element i to pStr
|
||||
*/
|
||||
static void jsonEachComputePath(
|
||||
@@ -2298,10 +2326,7 @@ static void jsonEachComputePath(
|
||||
}else{
|
||||
assert( pUp->eType==JSON_OBJECT );
|
||||
if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
|
||||
assert( pNode->eType==JSON_STRING );
|
||||
assert( pNode->jnFlags & JNODE_LABEL );
|
||||
assert( pNode->eU==1 );
|
||||
jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
|
||||
jsonAppendObjectPathElement(pStr, pNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2372,8 +2397,7 @@ static int jsonEachColumn(
|
||||
if( p->eType==JSON_ARRAY ){
|
||||
jsonPrintf(30, &x, "[%d]", p->iRowid);
|
||||
}else if( p->eType==JSON_OBJECT ){
|
||||
assert( pThis->eU==1 );
|
||||
jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
|
||||
jsonAppendObjectPathElement(&x, pThis);
|
||||
}
|
||||
}
|
||||
jsonResult(&x);
|
||||
|
||||
+18
-1
@@ -487,11 +487,28 @@ static const sqlite3_api_routines sqlite3Apis = {
|
||||
sqlite3_autovacuum_pages,
|
||||
/* Version 3.38.0 and later */
|
||||
sqlite3_error_offset,
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
sqlite3_vtab_rhs_value,
|
||||
sqlite3_vtab_distinct,
|
||||
sqlite3_vtab_in,
|
||||
sqlite3_vtab_in_first,
|
||||
sqlite3_vtab_in_next
|
||||
sqlite3_vtab_in_next,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
/* Version 3.39.0 and later */
|
||||
#ifndef SQLITE_OMIT_DESERIALIZE
|
||||
sqlite3_deserialize,
|
||||
sqlite3_serialize,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
sqlite3_db_name
|
||||
};
|
||||
|
||||
/* True if x is the directory separator character
|
||||
|
||||
+64
-9
@@ -824,18 +824,19 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
|
||||
db->lookaside.bMalloced = pBuf==0 ?1:0;
|
||||
db->lookaside.nSlot = nBig+nSm;
|
||||
}else{
|
||||
db->lookaside.pStart = db;
|
||||
db->lookaside.pStart = 0;
|
||||
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
|
||||
db->lookaside.pSmallInit = 0;
|
||||
db->lookaside.pSmallFree = 0;
|
||||
db->lookaside.pMiddle = db;
|
||||
db->lookaside.pMiddle = 0;
|
||||
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
|
||||
db->lookaside.pEnd = db;
|
||||
db->lookaside.pEnd = 0;
|
||||
db->lookaside.bDisable = 1;
|
||||
db->lookaside.sz = 0;
|
||||
db->lookaside.bMalloced = 0;
|
||||
db->lookaside.nSlot = 0;
|
||||
}
|
||||
db->lookaside.pTrueEnd = db->lookaside.pEnd;
|
||||
assert( sqlite3LookasideUsed(db,0)==0 );
|
||||
#endif /* SQLITE_OMIT_LOOKASIDE */
|
||||
return SQLITE_OK;
|
||||
@@ -914,8 +915,19 @@ int sqlite3_db_cacheflush(sqlite3 *db){
|
||||
int sqlite3_db_config(sqlite3 *db, int op, ...){
|
||||
va_list ap;
|
||||
int rc;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
va_start(ap, op);
|
||||
switch( op ){
|
||||
case SQLITE_DBCONFIG_STMTCACHE_SIZE: {
|
||||
int szDesired = va_arg(ap,int);
|
||||
int *pszNew = va_arg(ap,int*);
|
||||
if( szDesired>=0 ){
|
||||
sqlite3VdbeChangeStmtCacheSize(db, szDesired);
|
||||
}
|
||||
if( pszNew ) *pszNew = (int)db->mxCache;
|
||||
rc = SQLITE_OK;
|
||||
break;
|
||||
}
|
||||
case SQLITE_DBCONFIG_MAINDBNAME: {
|
||||
/* IMP: R-06824-28531 */
|
||||
/* IMP: R-36257-52125 */
|
||||
@@ -979,6 +991,7 @@ int sqlite3_db_config(sqlite3 *db, int op, ...){
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1211,6 +1224,7 @@ static int sqlite3Close(sqlite3 *db, int forceZombie){
|
||||
}
|
||||
|
||||
/* Force xDisconnect calls on all virtual tables */
|
||||
sqlite3VdbeChangeStmtCacheSize(db, 0);
|
||||
disconnectAllVtab(db);
|
||||
|
||||
/* If a transaction is open, the disconnectAllVtab() call above
|
||||
@@ -3249,6 +3263,7 @@ static int openDatabase(
|
||||
db->autoCommit = 1;
|
||||
db->nextAutovac = -1;
|
||||
db->szMmap = sqlite3GlobalConfig.szMmap;
|
||||
db->mxCache = SQLITE_DEFAULT_STMTCACHE_SIZE;
|
||||
db->nextPagesize = 0;
|
||||
db->init.azInit = sqlite3StdType; /* Any array of string ptrs will do */
|
||||
#ifdef SQLITE_ENABLE_SORTER_MMAP
|
||||
@@ -4097,6 +4112,28 @@ int sqlite3_test_control(int op, ...){
|
||||
volatile int x = 0;
|
||||
assert( /*side-effects-ok*/ (x = va_arg(ap,int))!=0 );
|
||||
rc = x;
|
||||
#if defined(SQLITE_DEBUG)
|
||||
/* Invoke these debugging routines so that the compiler does not
|
||||
** issue "defined but not used" warnings. */
|
||||
if( x==9999 ){
|
||||
sqlite3ShowExpr(0);
|
||||
sqlite3ShowExpr(0);
|
||||
sqlite3ShowExprList(0);
|
||||
sqlite3ShowIdList(0);
|
||||
sqlite3ShowSrcList(0);
|
||||
sqlite3ShowWith(0);
|
||||
sqlite3ShowUpsert(0);
|
||||
sqlite3ShowTriggerStep(0);
|
||||
sqlite3ShowTriggerStepList(0);
|
||||
sqlite3ShowTrigger(0);
|
||||
sqlite3ShowTriggerList(0);
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
sqlite3ShowWindow(0);
|
||||
sqlite3ShowWinFunc(0);
|
||||
#endif
|
||||
sqlite3ShowSelect(0);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4358,8 +4395,8 @@ int sqlite3_test_control(int op, ...){
|
||||
**
|
||||
** "ptr" is a pointer to a u32.
|
||||
**
|
||||
** op==0 Store the current sqlite3SelectTrace in *ptr
|
||||
** op==1 Set sqlite3SelectTrace to the value *ptr
|
||||
** op==0 Store the current sqlite3TreeTrace in *ptr
|
||||
** op==1 Set sqlite3TreeTrace to the value *ptr
|
||||
** op==3 Store the current sqlite3WhereTrace in *ptr
|
||||
** op==3 Set sqlite3WhereTrace to the value *ptr
|
||||
*/
|
||||
@@ -4367,10 +4404,10 @@ int sqlite3_test_control(int op, ...){
|
||||
int opTrace = va_arg(ap, int);
|
||||
u32 *ptr = va_arg(ap, u32*);
|
||||
switch( opTrace ){
|
||||
case 0: *ptr = sqlite3SelectTrace; break;
|
||||
case 1: sqlite3SelectTrace = *ptr; break;
|
||||
case 2: *ptr = sqlite3WhereTrace; break;
|
||||
case 3: sqlite3WhereTrace = *ptr; break;
|
||||
case 0: *ptr = sqlite3TreeTrace; break;
|
||||
case 1: sqlite3TreeTrace = *ptr; break;
|
||||
case 2: *ptr = sqlite3WhereTrace; break;
|
||||
case 3: sqlite3WhereTrace = *ptr; break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -4607,6 +4644,24 @@ Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
|
||||
return iDb<0 ? 0 : db->aDb[iDb].pBt;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the name of the N-th database schema. Return NULL if N is out
|
||||
** of range.
|
||||
*/
|
||||
const char *sqlite3_db_name(sqlite3 *db, int N){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if( N<0 || N>=db->nDb ){
|
||||
return 0;
|
||||
}else{
|
||||
return db->aDb[N].zDbSName;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the filename of the database associated with a database
|
||||
** connection.
|
||||
|
||||
+80
-21
@@ -270,18 +270,34 @@ static void mallocWithAlarm(int n, void **pp){
|
||||
*pp = p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Maximum size of any single memory allocation.
|
||||
**
|
||||
** This is not a limit on the total amount of memory used. This is
|
||||
** a limit on the size parameter to sqlite3_malloc() and sqlite3_realloc().
|
||||
**
|
||||
** The upper bound is slightly less than 2GiB: 0x7ffffeff == 2,147,483,391
|
||||
** This provides a 256-byte safety margin for defense against 32-bit
|
||||
** signed integer overflow bugs when computing memory allocation sizes.
|
||||
** Parnoid applications might want to reduce the maximum allocation size
|
||||
** further for an even larger safety margin. 0x3fffffff or 0x0fffffff
|
||||
** or even smaller would be reasonable upper bounds on the size of a memory
|
||||
** allocations for most applications.
|
||||
*/
|
||||
#ifndef SQLITE_MAX_ALLOCATION_SIZE
|
||||
# define SQLITE_MAX_ALLOCATION_SIZE 2147483391
|
||||
#endif
|
||||
#if SQLITE_MAX_ALLOCATION_SIZE>2147483391
|
||||
# error Maximum size for SQLITE_MAX_ALLOCATION_SIZE is 2147483391
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Allocate memory. This routine is like sqlite3_malloc() except that it
|
||||
** assumes the memory subsystem has already been initialized.
|
||||
*/
|
||||
void *sqlite3Malloc(u64 n){
|
||||
void *p;
|
||||
if( n==0 || n>=0x7fffff00 ){
|
||||
/* A memory allocation of a number of bytes which is near the maximum
|
||||
** signed integer value might cause an integer overflow inside of the
|
||||
** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
|
||||
** 255 bytes of overhead. SQLite itself will never use anything near
|
||||
** this amount. The only way to reach the limit is with sqlite3_malloc() */
|
||||
if( n==0 || n>SQLITE_MAX_ALLOCATION_SIZE ){
|
||||
p = 0;
|
||||
}else if( sqlite3GlobalConfig.bMemstat ){
|
||||
sqlite3_mutex_enter(mem0.mutex);
|
||||
@@ -317,7 +333,7 @@ void *sqlite3_malloc64(sqlite3_uint64 n){
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_LOOKASIDE
|
||||
static int isLookaside(sqlite3 *db, const void *p){
|
||||
return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd);
|
||||
return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pTrueEnd);
|
||||
}
|
||||
#else
|
||||
#define isLookaside(A,B) 0
|
||||
@@ -341,18 +357,16 @@ static int lookasideMallocSize(sqlite3 *db, const void *p){
|
||||
int sqlite3DbMallocSize(sqlite3 *db, const void *p){
|
||||
assert( p!=0 );
|
||||
#ifdef SQLITE_DEBUG
|
||||
if( db==0 || !isLookaside(db,p) ){
|
||||
if( db==0 ){
|
||||
assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
|
||||
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
|
||||
}else{
|
||||
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
|
||||
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
|
||||
}
|
||||
if( db==0 ){
|
||||
assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
|
||||
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
|
||||
}else if( !isLookaside(db,p) ){
|
||||
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
|
||||
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
|
||||
}
|
||||
#endif
|
||||
if( db ){
|
||||
if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
|
||||
if( ((uptr)p)<(uptr)(db->lookaside.pTrueEnd) ){
|
||||
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
|
||||
if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
|
||||
assert( sqlite3_mutex_held(db->mutex) );
|
||||
@@ -408,14 +422,11 @@ void sqlite3DbFreeNN(sqlite3 *db, void *p){
|
||||
assert( db==0 || sqlite3_mutex_held(db->mutex) );
|
||||
assert( p!=0 );
|
||||
if( db ){
|
||||
if( db->pnBytesFreed ){
|
||||
measureAllocationSize(db, p);
|
||||
return;
|
||||
}
|
||||
if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
|
||||
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
|
||||
if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
|
||||
LookasideSlot *pBuf = (LookasideSlot*)p;
|
||||
assert( db->pnBytesFreed==0 );
|
||||
#ifdef SQLITE_DEBUG
|
||||
memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
|
||||
#endif
|
||||
@@ -426,6 +437,7 @@ void sqlite3DbFreeNN(sqlite3 *db, void *p){
|
||||
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
|
||||
if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
|
||||
LookasideSlot *pBuf = (LookasideSlot*)p;
|
||||
assert( db->pnBytesFreed==0 );
|
||||
#ifdef SQLITE_DEBUG
|
||||
memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
|
||||
#endif
|
||||
@@ -434,6 +446,10 @@ void sqlite3DbFreeNN(sqlite3 *db, void *p){
|
||||
return;
|
||||
}
|
||||
}
|
||||
if( db->pnBytesFreed ){
|
||||
measureAllocationSize(db, p);
|
||||
return;
|
||||
}
|
||||
}
|
||||
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
|
||||
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
|
||||
@@ -441,6 +457,43 @@ void sqlite3DbFreeNN(sqlite3 *db, void *p){
|
||||
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
void sqlite3DbNNFreeNN(sqlite3 *db, void *p){
|
||||
assert( db!=0 );
|
||||
assert( sqlite3_mutex_held(db->mutex) );
|
||||
assert( p!=0 );
|
||||
if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
|
||||
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
|
||||
if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
|
||||
LookasideSlot *pBuf = (LookasideSlot*)p;
|
||||
assert( db->pnBytesFreed==0 );
|
||||
#ifdef SQLITE_DEBUG
|
||||
memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
|
||||
#endif
|
||||
pBuf->pNext = db->lookaside.pSmallFree;
|
||||
db->lookaside.pSmallFree = pBuf;
|
||||
return;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
|
||||
if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
|
||||
LookasideSlot *pBuf = (LookasideSlot*)p;
|
||||
assert( db->pnBytesFreed==0 );
|
||||
#ifdef SQLITE_DEBUG
|
||||
memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
|
||||
#endif
|
||||
pBuf->pNext = db->lookaside.pFree;
|
||||
db->lookaside.pFree = pBuf;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if( db->pnBytesFreed ){
|
||||
measureAllocationSize(db, p);
|
||||
return;
|
||||
}
|
||||
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
|
||||
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
|
||||
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
void sqlite3DbFree(sqlite3 *db, void *p){
|
||||
assert( db==0 || sqlite3_mutex_held(db->mutex) );
|
||||
if( p ) sqlite3DbFreeNN(db, p);
|
||||
@@ -750,8 +803,9 @@ char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){
|
||||
** Free any prior content in *pz and replace it with a copy of zNew.
|
||||
*/
|
||||
void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
|
||||
char *z = sqlite3DbStrDup(db, zNew);
|
||||
sqlite3DbFree(db, *pz);
|
||||
*pz = sqlite3DbStrDup(db, zNew);
|
||||
*pz = z;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -775,8 +829,13 @@ void *sqlite3OomFault(sqlite3 *db){
|
||||
}
|
||||
DisableLookaside;
|
||||
if( db->pParse ){
|
||||
Parse *pParse;
|
||||
sqlite3ErrorMsg(db->pParse, "out of memory");
|
||||
db->pParse->rc = SQLITE_NOMEM_BKPT;
|
||||
for(pParse=db->pParse->pOuterParse; pParse; pParse = pParse->pOuterParse){
|
||||
pParse->nErr++;
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
+7
-2
@@ -420,8 +420,13 @@ static void *memsys5Realloc(void *pPrior, int nBytes){
|
||||
*/
|
||||
static int memsys5Roundup(int n){
|
||||
int iFullSz;
|
||||
if( n > 0x40000000 ) return 0;
|
||||
for(iFullSz=mem5.szAtom; iFullSz<n; iFullSz *= 2);
|
||||
if( n<=mem5.szAtom*2 ){
|
||||
if( n<=mem5.szAtom ) return mem5.szAtom;
|
||||
return mem5.szAtom*2;
|
||||
}
|
||||
if( n>0x40000000 ) return 0;
|
||||
for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
|
||||
if( (iFullSz/2)>=n ) return iFullSz/2;
|
||||
return iFullSz;
|
||||
}
|
||||
|
||||
|
||||
@@ -359,6 +359,8 @@ int sqlite3JournalOpen(
|
||||
){
|
||||
MemJournal *p = (MemJournal*)pJfd;
|
||||
|
||||
assert( zName || nSpill<0 || (flags & SQLITE_OPEN_EXCLUSIVE) );
|
||||
|
||||
/* Zero the file-handle object. If nSpill was passed zero, initialize
|
||||
** it using the sqlite3OsOpen() function of the underlying VFS. In this
|
||||
** case none of the code in this module is executed as a result of calls
|
||||
|
||||
@@ -223,6 +223,7 @@ int sqlite3OsOpen(
|
||||
** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
|
||||
** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
|
||||
** reaching the VFS. */
|
||||
assert( zPath || (flags & SQLITE_OPEN_EXCLUSIVE) );
|
||||
rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut);
|
||||
assert( rc==SQLITE_OK || pFile->pMethods==0 );
|
||||
return rc;
|
||||
|
||||
@@ -39,6 +39,13 @@
|
||||
# define SQLITE_MAX_PATHLEN FILENAME_MAX
|
||||
#endif
|
||||
|
||||
/* Maximum number of symlinks that will be resolved while trying to
|
||||
** expand a filename in xFullPathname() in the VFS.
|
||||
*/
|
||||
#ifndef SQLITE_MAX_SYMLINK
|
||||
# define SQLITE_MAX_SYMLINK 200
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The default size of a disk sector
|
||||
*/
|
||||
|
||||
+137
-163
@@ -4910,11 +4910,17 @@ static int unixShmLock(
|
||||
int flags /* What to do with the lock */
|
||||
){
|
||||
unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */
|
||||
unixShm *p = pDbFd->pShm; /* The shared memory being locked */
|
||||
unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */
|
||||
unixShm *p; /* The shared memory being locked */
|
||||
unixShmNode *pShmNode; /* The underlying file iNode */
|
||||
int rc = SQLITE_OK; /* Result code */
|
||||
u16 mask; /* Mask of locks to take or release */
|
||||
int *aLock = pShmNode->aLock;
|
||||
int *aLock;
|
||||
|
||||
p = pDbFd->pShm;
|
||||
if( p==0 ) return SQLITE_IOERR_SHMLOCK;
|
||||
pShmNode = p->pShmNode;
|
||||
if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
|
||||
aLock = pShmNode->aLock;
|
||||
|
||||
assert( pShmNode==pDbFd->pInode->pShmNode );
|
||||
assert( pShmNode->pInode==pDbFd->pInode );
|
||||
@@ -5849,6 +5855,7 @@ static const char *unixTempFileDir(void){
|
||||
static int unixGetTempname(int nBuf, char *zBuf){
|
||||
const char *zDir;
|
||||
int iLimit = 0;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
/* It's odd to simulate an io-error here, but really this is just
|
||||
** using the io-error infrastructure to test that SQLite handles this
|
||||
@@ -5857,18 +5864,26 @@ static int unixGetTempname(int nBuf, char *zBuf){
|
||||
zBuf[0] = 0;
|
||||
SimulateIOError( return SQLITE_IOERR );
|
||||
|
||||
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
|
||||
zDir = unixTempFileDir();
|
||||
if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH;
|
||||
do{
|
||||
u64 r;
|
||||
sqlite3_randomness(sizeof(r), &r);
|
||||
assert( nBuf>2 );
|
||||
zBuf[nBuf-2] = 0;
|
||||
sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
|
||||
zDir, r, 0);
|
||||
if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ) return SQLITE_ERROR;
|
||||
}while( osAccess(zBuf,0)==0 );
|
||||
return SQLITE_OK;
|
||||
if( zDir==0 ){
|
||||
rc = SQLITE_IOERR_GETTEMPPATH;
|
||||
}else{
|
||||
do{
|
||||
u64 r;
|
||||
sqlite3_randomness(sizeof(r), &r);
|
||||
assert( nBuf>2 );
|
||||
zBuf[nBuf-2] = 0;
|
||||
sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
|
||||
zDir, r, 0);
|
||||
if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ){
|
||||
rc = SQLITE_ERROR;
|
||||
break;
|
||||
}
|
||||
}while( osAccess(zBuf,0)==0 );
|
||||
}
|
||||
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
|
||||
@@ -6417,86 +6432,99 @@ static int unixAccess(
|
||||
}
|
||||
|
||||
/*
|
||||
** If the last component of the pathname in z[0]..z[j-1] is something
|
||||
** other than ".." then back it out and return true. If the last
|
||||
** component is empty or if it is ".." then return false.
|
||||
** A pathname under construction
|
||||
*/
|
||||
static int unixBackupDir(const char *z, int *pJ){
|
||||
int j = *pJ;
|
||||
int i;
|
||||
if( j<=0 ) return 0;
|
||||
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;
|
||||
typedef struct DbPath DbPath;
|
||||
struct DbPath {
|
||||
int rc; /* Non-zero following any error */
|
||||
int nSymlink; /* Number of symlinks resolved */
|
||||
char *zOut; /* Write the pathname here */
|
||||
int nOut; /* Bytes of space available to zOut[] */
|
||||
int nUsed; /* Bytes of zOut[] currently being used */
|
||||
};
|
||||
|
||||
/* Forward reference */
|
||||
static void appendAllPathElements(DbPath*,const char*);
|
||||
|
||||
/*
|
||||
** Append a single path element to the DbPath under construction
|
||||
*/
|
||||
static void appendOnePathElement(
|
||||
DbPath *pPath, /* Path under construction, to which to append zName */
|
||||
const char *zName, /* Name to append to pPath. Not zero-terminated */
|
||||
int nName /* Number of significant bytes in zName */
|
||||
){
|
||||
assert( nName>0 );
|
||||
assert( zName!=0 );
|
||||
if( zName[0]=='.' ){
|
||||
if( nName==1 ) return;
|
||||
if( zName[1]=='.' && nName==2 ){
|
||||
if( pPath->nUsed<=1 ){
|
||||
pPath->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
assert( pPath->zOut[0]=='/' );
|
||||
while( pPath->zOut[--pPath->nUsed]!='/' ){}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if( pPath->nUsed + nName + 2 >= pPath->nOut ){
|
||||
pPath->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
pPath->zOut[pPath->nUsed++] = '/';
|
||||
memcpy(&pPath->zOut[pPath->nUsed], zName, nName);
|
||||
pPath->nUsed += nName;
|
||||
#if defined(HAVE_READLINK) && defined(HAVE_LSTAT)
|
||||
if( pPath->rc==SQLITE_OK ){
|
||||
const char *zIn;
|
||||
struct stat buf;
|
||||
pPath->zOut[pPath->nUsed] = 0;
|
||||
zIn = pPath->zOut;
|
||||
if( osLstat(zIn, &buf)!=0 ){
|
||||
if( errno!=ENOENT ){
|
||||
pPath->rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
|
||||
}
|
||||
}else if( S_ISLNK(buf.st_mode) ){
|
||||
ssize_t got;
|
||||
char zLnk[SQLITE_MAX_PATHLEN+2];
|
||||
if( pPath->nSymlink++ > SQLITE_MAX_SYMLINK ){
|
||||
pPath->rc = SQLITE_CANTOPEN_BKPT;
|
||||
return;
|
||||
}
|
||||
got = osReadlink(zIn, zLnk, sizeof(zLnk)-2);
|
||||
if( got<=0 || got>=(ssize_t)sizeof(zLnk)-2 ){
|
||||
pPath->rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
|
||||
return;
|
||||
}
|
||||
zLnk[got] = 0;
|
||||
if( zLnk[0]=='/' ){
|
||||
pPath->nUsed = 0;
|
||||
}else{
|
||||
pPath->nUsed -= nName + 1;
|
||||
}
|
||||
appendAllPathElements(pPath, zLnk);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert a relative pathname into a full pathname. Also
|
||||
** simplify the pathname as follows:
|
||||
**
|
||||
** Remove all instances of /./
|
||||
** Remove all isntances of /X/../ for any X
|
||||
** Append all path elements in zPath to the DbPath under construction.
|
||||
*/
|
||||
static int mkFullPathname(
|
||||
const char *zPath, /* Input path */
|
||||
char *zOut, /* Output buffer */
|
||||
int nOut /* Allocated size of buffer zOut */
|
||||
static void appendAllPathElements(
|
||||
DbPath *pPath, /* Path under construction, to which to append zName */
|
||||
const char *zPath /* Path to append to pPath. Is zero-terminated */
|
||||
){
|
||||
int nPath = sqlite3Strlen30(zPath);
|
||||
int iOff = 0;
|
||||
int i, j;
|
||||
if( zPath[0]!='/' ){
|
||||
if( osGetcwd(zOut, nOut-2)==0 ){
|
||||
return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
do{
|
||||
while( zPath[i] && zPath[i]!='/' ){ i++; }
|
||||
if( i>j ){
|
||||
appendOnePathElement(pPath, &zPath[j], i-j);
|
||||
}
|
||||
iOff = sqlite3Strlen30(zOut);
|
||||
zOut[iOff++] = '/';
|
||||
}
|
||||
if( (iOff+nPath+1)>nOut ){
|
||||
/* SQLite assumes that xFullPathname() nul-terminates the output buffer
|
||||
** even if it returns an error. */
|
||||
zOut[iOff] = '\0';
|
||||
return SQLITE_CANTOPEN_BKPT;
|
||||
}
|
||||
sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
|
||||
|
||||
/* Remove duplicate '/' characters. Except, two // at the beginning
|
||||
** of a pathname is allowed since this is important on windows. */
|
||||
for(i=j=1; zOut[i]; i++){
|
||||
zOut[j++] = zOut[i];
|
||||
while( zOut[i]=='/' && zOut[i+1]=='/' ) i++;
|
||||
}
|
||||
zOut[j] = 0;
|
||||
|
||||
assert( zOut[0]=='/' );
|
||||
for(i=j=0; zOut[i]; i++){
|
||||
if( zOut[i]=='/' ){
|
||||
/* Skip over internal "/." directory components */
|
||||
if( zOut[i+1]=='.' && zOut[i+2]=='/' ){
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If this is a "/.." directory component then back out the
|
||||
** previous term of the directory if it is something other than "..".
|
||||
*/
|
||||
if( zOut[i+1]=='.'
|
||||
&& zOut[i+2]=='.'
|
||||
&& zOut[i+3]=='/'
|
||||
&& unixBackupDir(zOut, &j)
|
||||
){
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if( ALWAYS(j>=0) ) zOut[j] = zOut[i];
|
||||
j++;
|
||||
}
|
||||
if( NEVER(j==0) ) zOut[j++] = '/';
|
||||
zOut[j] = 0;
|
||||
return SQLITE_OK;
|
||||
j = i+1;
|
||||
}while( zPath[i++] );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -6514,86 +6542,27 @@ static int unixFullPathname(
|
||||
int nOut, /* Size of output buffer in bytes */
|
||||
char *zOut /* Output buffer */
|
||||
){
|
||||
#if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT)
|
||||
return mkFullPathname(zPath, zOut, nOut);
|
||||
#else
|
||||
int rc = SQLITE_OK;
|
||||
int nByte;
|
||||
int nLink = 0; /* Number of symbolic links followed so far */
|
||||
const char *zIn = zPath; /* Input path for each iteration of loop */
|
||||
char *zDel = 0;
|
||||
|
||||
assert( pVfs->mxPathname==MAX_PATHNAME );
|
||||
DbPath path;
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
|
||||
/* It's odd to simulate an io-error here, but really this is just
|
||||
** using the io-error infrastructure to test that SQLite handles this
|
||||
** function failing. This function could fail if, for example, the
|
||||
** current working directory has been unlinked.
|
||||
*/
|
||||
SimulateIOError( return SQLITE_ERROR );
|
||||
|
||||
do {
|
||||
|
||||
/* Call stat() on path zIn. Set bLink to true if the path is a symbolic
|
||||
** link, or false otherwise. */
|
||||
int bLink = 0;
|
||||
struct stat buf;
|
||||
if( osLstat(zIn, &buf)!=0 ){
|
||||
if( errno!=ENOENT ){
|
||||
rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
|
||||
}
|
||||
}else{
|
||||
bLink = S_ISLNK(buf.st_mode);
|
||||
path.rc = 0;
|
||||
path.nUsed = 0;
|
||||
path.nSymlink = 0;
|
||||
path.nOut = nOut;
|
||||
path.zOut = zOut;
|
||||
if( zPath[0]!='/' ){
|
||||
char zPwd[SQLITE_MAX_PATHLEN+2];
|
||||
if( osGetcwd(zPwd, sizeof(zPwd)-2)==0 ){
|
||||
return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
|
||||
}
|
||||
|
||||
if( bLink ){
|
||||
nLink++;
|
||||
if( zDel==0 ){
|
||||
zDel = sqlite3_malloc(nOut);
|
||||
if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
|
||||
}else if( nLink>=SQLITE_MAX_SYMLINKS ){
|
||||
rc = SQLITE_CANTOPEN_BKPT;
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
nByte = osReadlink(zIn, zDel, nOut-1);
|
||||
if( nByte<0 ){
|
||||
rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
|
||||
}else{
|
||||
if( zDel[0]!='/' ){
|
||||
int n;
|
||||
for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
|
||||
if( nByte+n+1>nOut ){
|
||||
rc = SQLITE_CANTOPEN_BKPT;
|
||||
}else{
|
||||
memmove(&zDel[n], zDel, nByte+1);
|
||||
memcpy(zDel, zIn, n);
|
||||
nByte += n;
|
||||
}
|
||||
}
|
||||
zDel[nByte] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
zIn = zDel;
|
||||
}
|
||||
|
||||
assert( rc!=SQLITE_OK || zIn!=zOut || zIn[0]=='/' );
|
||||
if( rc==SQLITE_OK && zIn!=zOut ){
|
||||
rc = mkFullPathname(zIn, zOut, nOut);
|
||||
}
|
||||
if( bLink==0 ) break;
|
||||
zIn = zOut;
|
||||
}while( rc==SQLITE_OK );
|
||||
|
||||
sqlite3_free(zDel);
|
||||
if( rc==SQLITE_OK && nLink ) rc = SQLITE_OK_SYMLINK;
|
||||
return rc;
|
||||
#endif /* HAVE_READLINK && HAVE_LSTAT */
|
||||
appendAllPathElements(&path, zPwd);
|
||||
}
|
||||
appendAllPathElements(&path, zPath);
|
||||
zOut[path.nUsed] = 0;
|
||||
if( path.rc || path.nUsed<2 ) return SQLITE_CANTOPEN_BKPT;
|
||||
if( path.nSymlink ) return SQLITE_OK_SYMLINK;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_LOAD_EXTENSION
|
||||
/*
|
||||
** Interfaces for opening a shared library, finding entry points
|
||||
@@ -8089,7 +8058,12 @@ int sqlite3_os_init(void){
|
||||
|
||||
/* Register all VFSes defined in the aVfs[] array */
|
||||
for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
|
||||
#ifdef SQLITE_DEFAULT_UNIX_VFS
|
||||
sqlite3_vfs_register(&aVfs[i],
|
||||
0==strcmp(aVfs[i].zName,SQLITE_DEFAULT_UNIX_VFS));
|
||||
#else
|
||||
sqlite3_vfs_register(&aVfs[i], i==0);
|
||||
#endif
|
||||
}
|
||||
unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
|
||||
|
||||
|
||||
+47
-7
@@ -1918,10 +1918,12 @@ int sqlite3_win32_set_directory8(
|
||||
const char *zValue /* New value for directory being set or reset */
|
||||
){
|
||||
char **ppDirectory = 0;
|
||||
int rc;
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
int rc = sqlite3_initialize();
|
||||
rc = sqlite3_initialize();
|
||||
if( rc ) return rc;
|
||||
#endif
|
||||
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
|
||||
if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){
|
||||
ppDirectory = &sqlite3_data_directory;
|
||||
}else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){
|
||||
@@ -1936,14 +1938,19 @@ int sqlite3_win32_set_directory8(
|
||||
if( zValue && zValue[0] ){
|
||||
zCopy = sqlite3_mprintf("%s", zValue);
|
||||
if ( zCopy==0 ){
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
goto set_directory8_done;
|
||||
}
|
||||
}
|
||||
sqlite3_free(*ppDirectory);
|
||||
*ppDirectory = zCopy;
|
||||
return SQLITE_OK;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
return SQLITE_ERROR;
|
||||
set_directory8_done:
|
||||
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4070,10 +4077,14 @@ static int winShmLock(
|
||||
winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */
|
||||
winShm *p = pDbFd->pShm; /* The shared memory being locked */
|
||||
winShm *pX; /* For looping over all siblings */
|
||||
winShmNode *pShmNode = p->pShmNode;
|
||||
winShmNode *pShmNode;
|
||||
int rc = SQLITE_OK; /* Result code */
|
||||
u16 mask; /* Mask of locks to take or release */
|
||||
|
||||
if( p==0 ) return SQLITE_IOERR_SHMLOCK;
|
||||
pShmNode = p->pShmNode;
|
||||
if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
|
||||
|
||||
assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
|
||||
assert( n>=1 );
|
||||
assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
|
||||
@@ -4713,6 +4724,18 @@ static int winMakeEndInDirSep(int nBuf, char *zBuf){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** If sqlite3_temp_directory is not, take the mutex and return true.
|
||||
**
|
||||
** If sqlite3_temp_directory is NULL, omit the mutex and return false.
|
||||
*/
|
||||
static int winTempDirDefined(void){
|
||||
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
|
||||
if( sqlite3_temp_directory!=0 ) return 1;
|
||||
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a temporary file name and store the resulting pointer into pzBuf.
|
||||
** The pointer returned in pzBuf must be freed via sqlite3_free().
|
||||
@@ -4749,20 +4772,23 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
*/
|
||||
nDir = nMax - (nPre + 15);
|
||||
assert( nDir>0 );
|
||||
if( sqlite3_temp_directory ){
|
||||
if( winTempDirDefined() ){
|
||||
int nDirLen = sqlite3Strlen30(sqlite3_temp_directory);
|
||||
if( nDirLen>0 ){
|
||||
if( !winIsDirSep(sqlite3_temp_directory[nDirLen-1]) ){
|
||||
nDirLen++;
|
||||
}
|
||||
if( nDirLen>nDir ){
|
||||
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
|
||||
sqlite3_free(zBuf);
|
||||
OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
|
||||
return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
|
||||
}
|
||||
sqlite3_snprintf(nMax, zBuf, "%s", sqlite3_temp_directory);
|
||||
}
|
||||
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
|
||||
}
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
else{
|
||||
static const char *azDirs[] = {
|
||||
@@ -5551,7 +5577,7 @@ static BOOL winIsVerbatimPathname(
|
||||
** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
|
||||
** bytes in size.
|
||||
*/
|
||||
static int winFullPathname(
|
||||
static int winFullPathnameNoMutex(
|
||||
sqlite3_vfs *pVfs, /* Pointer to vfs object */
|
||||
const char *zRelative, /* Possibly relative input path */
|
||||
int nFull, /* Size of output buffer in bytes */
|
||||
@@ -5730,6 +5756,20 @@ static int winFullPathname(
|
||||
}
|
||||
#endif
|
||||
}
|
||||
static int winFullPathname(
|
||||
sqlite3_vfs *pVfs, /* Pointer to vfs object */
|
||||
const char *zRelative, /* Possibly relative input path */
|
||||
int nFull, /* Size of output buffer in bytes */
|
||||
char *zFull /* Output buffer */
|
||||
){
|
||||
int rc;
|
||||
MUTEX_LOGIC( sqlite3_mutex *pMutex; )
|
||||
MUTEX_LOGIC( pMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR); )
|
||||
sqlite3_mutex_enter(pMutex);
|
||||
rc = winFullPathnameNoMutex(pVfs, zRelative, nFull, zFull);
|
||||
sqlite3_mutex_leave(pMutex);
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_LOAD_EXTENSION
|
||||
/*
|
||||
|
||||
@@ -2623,6 +2623,7 @@ static int pager_truncate(Pager *pPager, Pgno nPage){
|
||||
memset(pTmp, 0, szPage);
|
||||
testcase( (newSize-szPage) == currentSize );
|
||||
testcase( (newSize-szPage) > currentSize );
|
||||
sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &newSize);
|
||||
rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -5785,6 +5786,7 @@ static int pager_open_journal(Pager *pPager){
|
||||
|
||||
if( pPager->tempFile ){
|
||||
flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL);
|
||||
flags |= SQLITE_OPEN_EXCLUSIVE;
|
||||
nSpill = sqlite3Config.nStmtSpill;
|
||||
}else{
|
||||
flags |= SQLITE_OPEN_MAIN_JOURNAL;
|
||||
@@ -5820,6 +5822,7 @@ static int pager_open_journal(Pager *pPager){
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3BitvecDestroy(pPager->pInJournal);
|
||||
pPager->pInJournal = 0;
|
||||
pPager->journalOff = 0;
|
||||
}else{
|
||||
assert( pPager->eState==PAGER_WRITER_LOCKED );
|
||||
pPager->eState = PAGER_WRITER_CACHEMOD;
|
||||
|
||||
+64
-34
@@ -570,7 +570,7 @@ selectnowith(A) ::= selectnowith(A) multiselect_op(Y) oneselect(Z). {
|
||||
Token x;
|
||||
x.n = 0;
|
||||
parserDoubleLinkSelect(pParse, pRhs);
|
||||
pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
|
||||
pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0);
|
||||
pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
|
||||
}
|
||||
if( pRhs ){
|
||||
@@ -685,7 +685,7 @@ as(X) ::= . {X.n = 0; X.z = 0;}
|
||||
from(A) ::= . {A = 0;}
|
||||
from(A) ::= FROM seltablist(X). {
|
||||
A = X;
|
||||
sqlite3SrcListShiftJoinType(A);
|
||||
sqlite3SrcListShiftJoinType(pParse,A);
|
||||
}
|
||||
|
||||
// "seltablist" is a "Select Table List" - the content of the FROM clause
|
||||
@@ -695,33 +695,35 @@ stl_prefix(A) ::= seltablist(A) joinop(Y). {
|
||||
if( ALWAYS(A && A->nSrc>0) ) A->a[A->nSrc-1].fg.jointype = (u8)Y;
|
||||
}
|
||||
stl_prefix(A) ::= . {A = 0;}
|
||||
seltablist(A) ::= stl_prefix(A) nm(Y) dbnm(D) as(Z) indexed_opt(I)
|
||||
on_opt(N) using_opt(U). {
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,&Y,&D,&Z,0,N,U);
|
||||
seltablist(A) ::= stl_prefix(A) nm(Y) dbnm(D) as(Z) on_using(N). {
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,&Y,&D,&Z,0,&N);
|
||||
}
|
||||
seltablist(A) ::= stl_prefix(A) nm(Y) dbnm(D) as(Z) indexed_by(I) on_using(N). {
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,&Y,&D,&Z,0,&N);
|
||||
sqlite3SrcListIndexedBy(pParse, A, &I);
|
||||
}
|
||||
seltablist(A) ::= stl_prefix(A) nm(Y) dbnm(D) LP exprlist(E) RP as(Z)
|
||||
on_opt(N) using_opt(U). {
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,&Y,&D,&Z,0,N,U);
|
||||
seltablist(A) ::= stl_prefix(A) nm(Y) dbnm(D) LP exprlist(E) RP as(Z) on_using(N). {
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,&Y,&D,&Z,0,&N);
|
||||
sqlite3SrcListFuncArgs(pParse, A, E);
|
||||
}
|
||||
%ifndef SQLITE_OMIT_SUBQUERY
|
||||
seltablist(A) ::= stl_prefix(A) LP select(S) RP
|
||||
as(Z) on_opt(N) using_opt(U). {
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,0,0,&Z,S,N,U);
|
||||
seltablist(A) ::= stl_prefix(A) LP select(S) RP as(Z) on_using(N). {
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,0,0,&Z,S,&N);
|
||||
}
|
||||
seltablist(A) ::= stl_prefix(A) LP seltablist(F) RP
|
||||
as(Z) on_opt(N) using_opt(U). {
|
||||
if( A==0 && Z.n==0 && N==0 && U==0 ){
|
||||
seltablist(A) ::= stl_prefix(A) LP seltablist(F) RP as(Z) on_using(N). {
|
||||
if( A==0 && Z.n==0 && N.pOn==0 && N.pUsing==0 ){
|
||||
A = F;
|
||||
}else if( F->nSrc==1 ){
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,0,0,&Z,0,N,U);
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,0,0,&Z,0,&N);
|
||||
if( A ){
|
||||
SrcItem *pNew = &A->a[A->nSrc-1];
|
||||
SrcItem *pOld = F->a;
|
||||
pNew->zName = pOld->zName;
|
||||
pNew->zDatabase = pOld->zDatabase;
|
||||
pNew->pSelect = pOld->pSelect;
|
||||
if( pNew->pSelect && (pNew->pSelect->selFlags & SF_NestedFrom)!=0 ){
|
||||
pNew->fg.isNestedFrom = 1;
|
||||
}
|
||||
if( pOld->fg.isTabFunc ){
|
||||
pNew->u1.pFuncArg = pOld->u1.pFuncArg;
|
||||
pOld->u1.pFuncArg = 0;
|
||||
@@ -734,9 +736,9 @@ seltablist(A) ::= stl_prefix(A) nm(Y) dbnm(D) LP exprlist(E) RP as(Z)
|
||||
sqlite3SrcListDelete(pParse->db, F);
|
||||
}else{
|
||||
Select *pSubquery;
|
||||
sqlite3SrcListShiftJoinType(F);
|
||||
sqlite3SrcListShiftJoinType(pParse,F);
|
||||
pSubquery = sqlite3SelectNew(pParse,0,F,0,0,0,0,SF_NestedFrom,0);
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,0,0,&Z,pSubquery,N,U);
|
||||
A = sqlite3SrcListAppendFromTerm(pParse,A,0,0,&Z,pSubquery,&N);
|
||||
}
|
||||
}
|
||||
%endif SQLITE_OMIT_SUBQUERY
|
||||
@@ -794,13 +796,14 @@ joinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN.
|
||||
//
|
||||
// INSERT INTO tab SELECT * FROM aaa JOIN bbb WHERE true ON CONFLICT ...
|
||||
//
|
||||
// The [AND] and [OR] precedence marks in the rules for on_opt cause the
|
||||
// The [AND] and [OR] precedence marks in the rules for on_using cause the
|
||||
// ON in this context to always be interpreted as belonging to the JOIN.
|
||||
//
|
||||
%type on_opt {Expr*}
|
||||
%destructor on_opt {sqlite3ExprDelete(pParse->db, $$);}
|
||||
on_opt(N) ::= ON expr(E). {N = E;}
|
||||
on_opt(N) ::= . [OR] {N = 0;}
|
||||
%type on_using {OnOrUsing}
|
||||
//%destructor on_using {sqlite3ClearOnOrUsing(pParse->db, &$$);}
|
||||
on_using(N) ::= ON expr(E). {N.pOn = E; N.pUsing = 0;}
|
||||
on_using(N) ::= USING LP idlist(L) RP. {N.pOn = 0; N.pUsing = L;}
|
||||
on_using(N) ::= . [OR] {N.pOn = 0; N.pUsing = 0;}
|
||||
|
||||
// Note that this block abuses the Token type just a little. If there is
|
||||
// no "INDEXED BY" clause, the returned token is empty (z==0 && n==0). If
|
||||
@@ -813,15 +816,11 @@ on_opt(N) ::= . [OR] {N = 0;}
|
||||
// recognizes and interprets this as a special case.
|
||||
//
|
||||
%type indexed_opt {Token}
|
||||
%type indexed_by {Token}
|
||||
indexed_opt(A) ::= . {A.z=0; A.n=0;}
|
||||
indexed_opt(A) ::= INDEXED BY nm(X). {A = X;}
|
||||
indexed_opt(A) ::= NOT INDEXED. {A.z=0; A.n=1;}
|
||||
|
||||
%type using_opt {IdList*}
|
||||
%destructor using_opt {sqlite3IdListDelete(pParse->db, $$);}
|
||||
using_opt(U) ::= USING LP idlist(L) RP. {U = L;}
|
||||
using_opt(U) ::= . {U = 0;}
|
||||
|
||||
indexed_opt(A) ::= indexed_by(A).
|
||||
indexed_by(A) ::= INDEXED BY nm(X). {A = X;}
|
||||
indexed_by(A) ::= NOT INDEXED. {A.z=0; A.n=1;}
|
||||
|
||||
%type orderby_opt {ExprList*}
|
||||
%destructor orderby_opt {sqlite3ExprListDelete(pParse->db, $$);}
|
||||
@@ -925,7 +924,18 @@ where_opt_ret(A) ::= WHERE expr(X) RETURNING selcollist(Y).
|
||||
cmd ::= with UPDATE orconf(R) xfullname(X) indexed_opt(I) SET setlist(Y) from(F)
|
||||
where_opt_ret(W) orderby_opt(O) limit_opt(L). {
|
||||
sqlite3SrcListIndexedBy(pParse, X, &I);
|
||||
X = sqlite3SrcListAppendList(pParse, X, F);
|
||||
if( F ){
|
||||
SrcList *pFromClause = F;
|
||||
if( pFromClause->nSrc>1 ){
|
||||
Select *pSubquery;
|
||||
Token as;
|
||||
pSubquery = sqlite3SelectNew(pParse,0,pFromClause,0,0,0,0,SF_NestedFrom,0);
|
||||
as.n = 0;
|
||||
as.z = 0;
|
||||
pFromClause = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
|
||||
}
|
||||
X = sqlite3SrcListAppendList(pParse, X, pFromClause);
|
||||
}
|
||||
sqlite3ExprListCheckLength(pParse,Y,"set list");
|
||||
#ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
|
||||
if( O || L ){
|
||||
@@ -941,7 +951,18 @@ cmd ::= with UPDATE orconf(R) xfullname(X) indexed_opt(I) SET setlist(Y) from(F)
|
||||
where_opt_ret(W). {
|
||||
sqlite3SrcListIndexedBy(pParse, X, &I);
|
||||
sqlite3ExprListCheckLength(pParse,Y,"set list");
|
||||
X = sqlite3SrcListAppendList(pParse, X, F);
|
||||
if( F ){
|
||||
SrcList *pFromClause = F;
|
||||
if( pFromClause->nSrc>1 ){
|
||||
Select *pSubquery;
|
||||
Token as;
|
||||
pSubquery = sqlite3SelectNew(pParse,0,pFromClause,0,0,0,0,SF_NestedFrom,0);
|
||||
as.n = 0;
|
||||
as.z = 0;
|
||||
pFromClause = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
|
||||
}
|
||||
X = sqlite3SrcListAppendList(pParse, X, pFromClause);
|
||||
}
|
||||
sqlite3Update(pParse,X,Y,W,R,0,0,0);
|
||||
}
|
||||
%endif
|
||||
@@ -1034,7 +1055,7 @@ idlist(A) ::= nm(Y).
|
||||
p->affExpr = 0;
|
||||
p->flags = EP_Leaf;
|
||||
ExprClearVVAProperties(p);
|
||||
p->iAgg = -1;
|
||||
/* p->iAgg = -1; // Not required */
|
||||
p->pLeft = p->pRight = 0;
|
||||
p->pAggInfo = 0;
|
||||
memset(&p->x, 0, sizeof(p->x));
|
||||
@@ -1219,6 +1240,14 @@ expr(A) ::= expr(A) IS NOT expr(Y). {
|
||||
A = sqlite3PExpr(pParse,TK_ISNOT,A,Y);
|
||||
binaryToUnaryIfNull(pParse, Y, A, TK_NOTNULL);
|
||||
}
|
||||
expr(A) ::= expr(A) IS NOT DISTINCT FROM expr(Y). {
|
||||
A = sqlite3PExpr(pParse,TK_IS,A,Y);
|
||||
binaryToUnaryIfNull(pParse, Y, A, TK_ISNULL);
|
||||
}
|
||||
expr(A) ::= expr(A) IS DISTINCT FROM expr(Y). {
|
||||
A = sqlite3PExpr(pParse,TK_ISNOT,A,Y);
|
||||
binaryToUnaryIfNull(pParse, Y, A, TK_NOTNULL);
|
||||
}
|
||||
|
||||
expr(A) ::= NOT(B) expr(X).
|
||||
{A = sqlite3PExpr(pParse, @B, X, 0);/*A-overwrites-B*/}
|
||||
@@ -1264,7 +1293,8 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
|
||||
** regardless of the value of expr1.
|
||||
*/
|
||||
sqlite3ExprUnmapAndDelete(pParse, A);
|
||||
A = sqlite3Expr(pParse->db, TK_INTEGER, N ? "1" : "0");
|
||||
A = sqlite3Expr(pParse->db, TK_STRING, N ? "true" : "false");
|
||||
if( A ) sqlite3ExprIdToTrueFalse(A);
|
||||
}else{
|
||||
Expr *pRHS = Y->a[0].pExpr;
|
||||
if( Y->nExpr==1 && sqlite3ExprIsConstant(pRHS) && A->op!=TK_VECTOR ){
|
||||
|
||||
+52
-16
@@ -66,12 +66,20 @@ struct PCache {
|
||||
int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
|
||||
int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */
|
||||
# define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
|
||||
void pcacheDump(PCache *pCache){
|
||||
int N;
|
||||
int i, j;
|
||||
sqlite3_pcache_page *pLower;
|
||||
static void pcachePageTrace(int i, sqlite3_pcache_page *pLower){
|
||||
PgHdr *pPg;
|
||||
unsigned char *a;
|
||||
int j;
|
||||
pPg = (PgHdr*)pLower->pExtra;
|
||||
printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
|
||||
a = (unsigned char *)pLower->pBuf;
|
||||
for(j=0; j<12; j++) printf("%02x", a[j]);
|
||||
printf(" ptr %p\n", pPg);
|
||||
}
|
||||
static void pcacheDump(PCache *pCache){
|
||||
int N;
|
||||
int i;
|
||||
sqlite3_pcache_page *pLower;
|
||||
|
||||
if( sqlite3PcacheTrace<2 ) return;
|
||||
if( pCache->pCache==0 ) return;
|
||||
@@ -80,21 +88,32 @@ struct PCache {
|
||||
for(i=1; i<=N; i++){
|
||||
pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
|
||||
if( pLower==0 ) continue;
|
||||
pPg = (PgHdr*)pLower->pExtra;
|
||||
printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
|
||||
a = (unsigned char *)pLower->pBuf;
|
||||
for(j=0; j<12; j++) printf("%02x", a[j]);
|
||||
printf("\n");
|
||||
if( pPg->pPage==0 ){
|
||||
pcachePageTrace(i, pLower);
|
||||
if( ((PgHdr*)pLower)->pPage==0 ){
|
||||
sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
#else
|
||||
# define pcacheTrace(X)
|
||||
# define pcachePageTrace(PGNO, X)
|
||||
# define pcacheDump(X)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Return 1 if pPg is on the dirty list for pCache. Return 0 if not.
|
||||
** This routine runs inside of assert() statements only.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
static int pageOnDirtyList(PCache *pCache, PgHdr *pPg){
|
||||
PgHdr *p;
|
||||
for(p=pCache->pDirty; p; p=p->pDirtyNext){
|
||||
if( p==pPg ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Check invariants on a PgHdr entry. Return true if everything is OK.
|
||||
** Return false if any invariant is violated.
|
||||
@@ -113,8 +132,13 @@ int sqlite3PcachePageSanity(PgHdr *pPg){
|
||||
assert( pCache!=0 ); /* Every page has an associated PCache */
|
||||
if( pPg->flags & PGHDR_CLEAN ){
|
||||
assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
|
||||
assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
|
||||
assert( pCache->pDirtyTail!=pPg );
|
||||
assert( !pageOnDirtyList(pCache, pPg) );/* CLEAN pages not on dirty list */
|
||||
}else{
|
||||
assert( (pPg->flags & PGHDR_DIRTY)!=0 );/* If not CLEAN must be DIRTY */
|
||||
assert( pPg->pDirtyNext==0 || pPg->pDirtyNext->pDirtyPrev==pPg );
|
||||
assert( pPg->pDirtyPrev==0 || pPg->pDirtyPrev->pDirtyNext==pPg );
|
||||
assert( pPg->pDirtyPrev!=0 || pCache->pDirty==pPg );
|
||||
assert( pageOnDirtyList(pCache, pPg) );
|
||||
}
|
||||
/* WRITEABLE pages must also be DIRTY */
|
||||
if( pPg->flags & PGHDR_WRITEABLE ){
|
||||
@@ -388,8 +412,9 @@ sqlite3_pcache_page *sqlite3PcacheFetch(
|
||||
assert( createFlag==0 || pCache->eCreate==eCreate );
|
||||
assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
|
||||
pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
|
||||
pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
|
||||
pcacheTrace(("%p.FETCH %d%s (result: %p) ",pCache,pgno,
|
||||
createFlag?" create":"",pRes));
|
||||
pcachePageTrace(pgno, pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
@@ -517,6 +542,7 @@ void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
|
||||
pcacheUnpin(p);
|
||||
}else{
|
||||
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
|
||||
assert( sqlite3PcachePageSanity(p) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -551,8 +577,7 @@ void sqlite3PcacheDrop(PgHdr *p){
|
||||
** make it so.
|
||||
*/
|
||||
void sqlite3PcacheMakeDirty(PgHdr *p){
|
||||
assert( p->nRef>0 || p->pCache->bPurgeable==0 );
|
||||
testcase( p->nRef==0 );
|
||||
assert( p->nRef>0 );
|
||||
assert( sqlite3PcachePageSanity(p) );
|
||||
if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
|
||||
p->flags &= ~PGHDR_DONT_WRITE;
|
||||
@@ -561,6 +586,7 @@ void sqlite3PcacheMakeDirty(PgHdr *p){
|
||||
pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
|
||||
assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY );
|
||||
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
|
||||
assert( sqlite3PcachePageSanity(p) );
|
||||
}
|
||||
assert( sqlite3PcachePageSanity(p) );
|
||||
}
|
||||
@@ -623,14 +649,24 @@ void sqlite3PcacheClearSyncFlags(PCache *pCache){
|
||||
*/
|
||||
void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
|
||||
PCache *pCache = p->pCache;
|
||||
sqlite3_pcache_page *pOther;
|
||||
assert( p->nRef>0 );
|
||||
assert( newPgno>0 );
|
||||
assert( sqlite3PcachePageSanity(p) );
|
||||
pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
|
||||
pOther = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, newPgno, 0);
|
||||
if( pOther ){
|
||||
PgHdr *pXPage = (PgHdr*)pOther->pExtra;
|
||||
assert( pXPage->nRef==0 );
|
||||
pXPage->nRef++;
|
||||
pCache->nRefSum++;
|
||||
sqlite3PcacheDrop(pXPage);
|
||||
}
|
||||
sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
|
||||
p->pgno = newPgno;
|
||||
if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
|
||||
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
|
||||
assert( sqlite3PcachePageSanity(p) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+41
-45
@@ -39,12 +39,13 @@
|
||||
** size can vary according to architecture, compile-time options, and
|
||||
** SQLite library version number.
|
||||
**
|
||||
** If SQLITE_PCACHE_SEPARATE_HEADER is defined, then the extension is obtained
|
||||
** using a separate memory allocation from the database page content. This
|
||||
** seeks to overcome the "clownshoe" problem (also called "internal
|
||||
** fragmentation" in academic literature) of allocating a few bytes more
|
||||
** than a power of two with the memory allocator rounding up to the next
|
||||
** power of two, and leaving the rounded-up space unused.
|
||||
** Historical note: It used to be that if the SQLITE_PCACHE_SEPARATE_HEADER
|
||||
** was defined, then the page content would be held in a separate memory
|
||||
** allocation from the PgHdr1. This was intended to avoid clownshoe memory
|
||||
** allocations. However, the btree layer needs a small (16-byte) overrun
|
||||
** area after the page content buffer. The header serves as that overrun
|
||||
** area. Therefore SQLITE_PCACHE_SEPARATE_HEADER was discontinued to avoid
|
||||
** any possibility of a memory error.
|
||||
**
|
||||
** This module tracks pointers to PgHdr1 objects. Only pcache.c communicates
|
||||
** with this module. Information is passed back and forth as PgHdr1 pointers.
|
||||
@@ -89,30 +90,40 @@ typedef struct PGroup PGroup;
|
||||
|
||||
/*
|
||||
** Each cache entry is represented by an instance of the following
|
||||
** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
|
||||
** PgHdr1.pCache->szPage bytes is allocated directly before this structure
|
||||
** in memory.
|
||||
** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
|
||||
** directly before this structure and is used to cache the page content.
|
||||
**
|
||||
** Note: Variables isBulkLocal and isAnchor were once type "u8". That works,
|
||||
** When reading a corrupt database file, it is possible that SQLite might
|
||||
** read a few bytes (no more than 16 bytes) past the end of the page buffer.
|
||||
** It will only read past the end of the page buffer, never write. This
|
||||
** object is positioned immediately after the page buffer to serve as an
|
||||
** overrun area, so that overreads are harmless.
|
||||
**
|
||||
** Variables isBulkLocal and isAnchor were once type "u8". That works,
|
||||
** but causes a 2-byte gap in the structure for most architectures (since
|
||||
** pointers must be either 4 or 8-byte aligned). As this structure is located
|
||||
** in memory directly after the associated page data, if the database is
|
||||
** corrupt, code at the b-tree layer may overread the page buffer and
|
||||
** read part of this structure before the corruption is detected. This
|
||||
** can cause a valgrind error if the unitialized gap is accessed. Using u16
|
||||
** ensures there is no such gap, and therefore no bytes of unitialized memory
|
||||
** in the structure.
|
||||
** ensures there is no such gap, and therefore no bytes of uninitialized
|
||||
** memory in the structure.
|
||||
**
|
||||
** The pLruNext and pLruPrev pointers form a double-linked circular list
|
||||
** of all pages that are unpinned. The PGroup.lru element (which should be
|
||||
** the only element on the list with PgHdr1.isAnchor set to 1) forms the
|
||||
** beginning and the end of the list.
|
||||
*/
|
||||
struct PgHdr1 {
|
||||
sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
|
||||
unsigned int iKey; /* Key value (page number) */
|
||||
u16 isBulkLocal; /* This page from bulk local storage */
|
||||
u16 isAnchor; /* This is the PGroup.lru element */
|
||||
PgHdr1 *pNext; /* Next in hash table chain */
|
||||
PCache1 *pCache; /* Cache that currently owns this page */
|
||||
PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
|
||||
PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
|
||||
/* NB: pLruPrev is only valid if pLruNext!=0 */
|
||||
sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
|
||||
unsigned int iKey; /* Key value (page number) */
|
||||
u16 isBulkLocal; /* This page from bulk local storage */
|
||||
u16 isAnchor; /* This is the PGroup.lru element */
|
||||
PgHdr1 *pNext; /* Next in hash table chain */
|
||||
PCache1 *pCache; /* Cache that currently owns this page */
|
||||
PgHdr1 *pLruNext; /* Next in circular LRU list of unpinned pages */
|
||||
PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
|
||||
/* NB: pLruPrev is only valid if pLruNext!=0 */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -438,25 +449,13 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
|
||||
pcache1LeaveMutex(pCache->pGroup);
|
||||
#endif
|
||||
if( benignMalloc ){ sqlite3BeginBenignMalloc(); }
|
||||
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
|
||||
pPg = pcache1Alloc(pCache->szPage);
|
||||
p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
|
||||
if( !pPg || !p ){
|
||||
pcache1Free(pPg);
|
||||
sqlite3_free(p);
|
||||
pPg = 0;
|
||||
}
|
||||
#else
|
||||
pPg = pcache1Alloc(pCache->szAlloc);
|
||||
#endif
|
||||
if( benignMalloc ){ sqlite3EndBenignMalloc(); }
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
pcache1EnterMutex(pCache->pGroup);
|
||||
#endif
|
||||
if( pPg==0 ) return 0;
|
||||
#ifndef SQLITE_PCACHE_SEPARATE_HEADER
|
||||
p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
|
||||
#endif
|
||||
p->page.pBuf = pPg;
|
||||
p->page.pExtra = &p[1];
|
||||
p->isBulkLocal = 0;
|
||||
@@ -480,9 +479,6 @@ static void pcache1FreePage(PgHdr1 *p){
|
||||
pCache->pFree = p;
|
||||
}else{
|
||||
pcache1Free(p->page.pBuf);
|
||||
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
|
||||
sqlite3_free(p);
|
||||
#endif
|
||||
}
|
||||
(*pCache->pnPurgeable)--;
|
||||
}
|
||||
@@ -1123,23 +1119,26 @@ static void pcache1Rekey(
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
PgHdr1 *pPage = (PgHdr1 *)pPg;
|
||||
PgHdr1 **pp;
|
||||
unsigned int h;
|
||||
unsigned int hOld, hNew;
|
||||
assert( pPage->iKey==iOld );
|
||||
assert( pPage->pCache==pCache );
|
||||
assert( iOld!=iNew ); /* The page number really is changing */
|
||||
|
||||
pcache1EnterMutex(pCache->pGroup);
|
||||
|
||||
h = iOld%pCache->nHash;
|
||||
pp = &pCache->apHash[h];
|
||||
assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
|
||||
hOld = iOld%pCache->nHash;
|
||||
pp = &pCache->apHash[hOld];
|
||||
while( (*pp)!=pPage ){
|
||||
pp = &(*pp)->pNext;
|
||||
}
|
||||
*pp = pPage->pNext;
|
||||
|
||||
h = iNew%pCache->nHash;
|
||||
assert( pcache1FetchNoMutex(p, iNew, 0)==0 ); /* iNew not in cache */
|
||||
hNew = iNew%pCache->nHash;
|
||||
pPage->iKey = iNew;
|
||||
pPage->pNext = pCache->apHash[h];
|
||||
pCache->apHash[h] = pPage;
|
||||
pPage->pNext = pCache->apHash[hNew];
|
||||
pCache->apHash[hNew] = pPage;
|
||||
if( iNew>pCache->iMaxKey ){
|
||||
pCache->iMaxKey = iNew;
|
||||
}
|
||||
@@ -1246,9 +1245,6 @@ int sqlite3PcacheReleaseMemory(int nReq){
|
||||
&& p->isAnchor==0
|
||||
){
|
||||
nFree += pcache1MemSize(p->page.pBuf);
|
||||
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
|
||||
nFree += sqlite3MemSize(p);
|
||||
#endif
|
||||
assert( PAGE_IS_UNPINNED(p) );
|
||||
pcache1PinPage(p);
|
||||
pcache1RemoveFromHash(p, 1);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user