Compare commits
791 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 739aab893a | |||
| 6a42c8f368 | |||
| 523de6a830 | |||
| b842b1a61f | |||
| 8dc5a288c6 | |||
| 74217cc079 | |||
| 8e647b8191 | |||
| c035e6e4ab | |||
| de29e3e9be | |||
| d654be803f | |||
| 4f68623875 | |||
| e313382e3e | |||
| b6fb62d9b4 | |||
| e1547a2f1c | |||
| 22d6a53a77 | |||
| eb8cbaeb18 | |||
| 4b14b4d720 | |||
| a7aa59e097 | |||
| 549c8b68c7 | |||
| bbdc2b94fc | |||
| 48083cee4c | |||
| a15cdcc4f4 | |||
| ee2b437f0a | |||
| 8cb1895c74 | |||
| 5c959118f1 | |||
| e3000ae84c | |||
| ac1733d409 | |||
| 0aadf33312 | |||
| 432a93ba73 | |||
| a67367e7d1 | |||
| 4928570812 | |||
| bfcb8909c6 | |||
| 36da52425b | |||
| f5b1138bae | |||
| 4190d4b53e | |||
| 267cb326e9 | |||
| 50f2f43cba | |||
| 15f411dbdd | |||
| 2349c3d151 | |||
| fd5f5b65b4 | |||
| a2833a0cf6 | |||
| 688c9f0622 | |||
| 53f733c7ae | |||
| b38ad9991c | |||
| 6e4fc2ca2b | |||
| 289ab0760b | |||
| 111cf34f7a | |||
| b27795c183 | |||
| 4b529d97ff | |||
| 9d4673a9ea | |||
| c99130fd82 | |||
| 00b950d71e | |||
| 0c35667b02 | |||
| ecc9242f6f | |||
| d891967052 | |||
| 3dec223ca0 | |||
| f307a4aaf8 | |||
| e08b814d72 | |||
| fd35797469 | |||
| b4746b9e33 | |||
| c2bd913a40 | |||
| 3f219f46fc | |||
| 825c662e66 | |||
| 4f26bb62a8 | |||
| 97571957a1 | |||
| eb796a7c8f | |||
| f80bcd73af | |||
| 2af6742d86 | |||
| 3224b32b00 | |||
| 3d1d95e625 | |||
| d49c16ee9b | |||
| 9d2985c7b4 | |||
| 5360ad34b1 | |||
| d1c301e804 | |||
| 5774b80629 | |||
| a10a34b88f | |||
| 13449892ef | |||
| 79158e1865 | |||
| abfcea25ea | |||
| 1ec43c9a5a | |||
| b726ee6d1c | |||
| d81bd4e209 | |||
| c092998715 | |||
| a21c8495f9 | |||
| 4db38a7092 | |||
| 0342b1f542 | |||
| dece1a8464 | |||
| 6242b9511d | |||
| 37108e112a | |||
| a91965b38a | |||
| b64d5ee42c | |||
| f6ac657f27 | |||
| 8897f6fa3f | |||
| 3e60cdc3c0 | |||
| 0a8640d4f2 | |||
| 63782855ee | |||
| 5d9a4af9af | |||
| 220b10285b | |||
| 01b4171e57 | |||
| 19e2d37f1d | |||
| b46b57745d | |||
| d64fe2f374 | |||
| bfd6b03554 | |||
| de941c605e | |||
| 9b4b45d5cf | |||
| 0b9693556d | |||
| c5ee956611 | |||
| f9dc42d870 | |||
| 2c8997b9a5 | |||
| 9cc5abd769 | |||
| ff8a0983d2 | |||
| 77207ab7c6 | |||
| 6e4b7cd4ef | |||
| e69cc5b742 | |||
| 87abf5c033 | |||
| 65d415cb72 | |||
| 0f77f5dc0b | |||
| 978468d488 | |||
| 3ca84ba0a0 | |||
| 3268f2b10c | |||
| 96c52a9b48 | |||
| 9eb2028fbc | |||
| 7681618c18 | |||
| 6c8c6cec1f | |||
| 75757853a0 | |||
| 8c154875b1 | |||
| ff1bc76916 | |||
| ad81e87054 | |||
| 03e7954732 | |||
| 7a22af6a60 | |||
| 788581d78a | |||
| 130b9f4040 | |||
| 992f2d781d | |||
| f0bce09cdd | |||
| 85c23c61e2 | |||
| 0bbaa1ba9a | |||
| f14fd03899 | |||
| 5eba8c09df | |||
| fc23314a0b | |||
| 8b3d990b71 | |||
| 91124b3545 | |||
| 731c96b412 | |||
| ce604012ac | |||
| c182d16302 | |||
| a2b902d66d | |||
| 9abc9c6aff | |||
| 55ef4d9758 | |||
| 3d94662a06 | |||
| d645967aaa | |||
| 8718f52624 | |||
| 531fe87834 | |||
| 3e9aeec03f | |||
| 557cc60f4d | |||
| 592ac8cb6c | |||
| 42b9d7c561 | |||
| 2501eb1df6 | |||
| bb7ac00bf0 | |||
| d2687b7731 | |||
| 2db0bbc24b | |||
| 4dcbdbff40 | |||
| 1cd7f83ef5 | |||
| 7018030d06 | |||
| 45b1ee44a4 | |||
| 586e4b2f30 | |||
| b5555e7e34 | |||
| 09d0debf3b | |||
| 3d21423c65 | |||
| 943af3cda1 | |||
| 2ce99ecf8b | |||
| 6c30be8e51 | |||
| ed37800693 | |||
| a611040eea | |||
| 3adc9cedb0 | |||
| 28c4cf42da | |||
| 51147baa6d | |||
| 17a18f2f36 | |||
| 497e446d76 | |||
| e6e049694d | |||
| ff2d5ea408 | |||
| d00ada9a00 | |||
| ed90e26313 | |||
| e23399fc9c | |||
| 29dda4ae65 | |||
| 7ec764a29e | |||
| fe05af87f8 | |||
| 013972052e | |||
| e8b9727835 | |||
| 0fcef5e110 | |||
| 0aa74edd72 | |||
| 9042f395cc | |||
| 84bfda41db | |||
| 4cfb644e5f | |||
| c0f2a01926 | |||
| e866fcb923 | |||
| df3816974c | |||
| a4afb65cb7 | |||
| 57dbd7b324 | |||
| 9170dd7e1c | |||
| 392e597c8a | |||
| 70031fa396 | |||
| a01f79df49 | |||
| 9f18e8a0c4 | |||
| 26d0e2a6da | |||
| 7bac700686 | |||
| eb55bd2fe9 | |||
| 67ce73b466 | |||
| ba336867c4 | |||
| 54f080e82c | |||
| d1e4733d07 | |||
| 8a15132904 | |||
| df0bddaef3 | |||
| 487e262f44 | |||
| 7f057c9166 | |||
| 2f47149691 | |||
| 5708d2deac | |||
| 288d37f1b4 | |||
| edef8fcd73 | |||
| 13aebc66f2 | |||
| cf5f58fa3e | |||
| bf8f1b3460 | |||
| 6eb8577cae | |||
| 2b4b5962c4 | |||
| 8d904f058b | |||
| 556b2a2322 | |||
| 3f73708ce4 | |||
| 78776ecdb1 | |||
| 7c3d49c275 | |||
| 4fd81a51fa | |||
| 3d334bcb1f | |||
| e44d483818 | |||
| 65efb65e46 | |||
| 51942bc3c3 | |||
| f0863fe568 | |||
| 4a9f241c37 | |||
| 0ccebe7e2d | |||
| 80f93bf41f | |||
| db0441b155 | |||
| cbe21be330 | |||
| af6df11f8a | |||
| 3844990cfc | |||
| ed8a3bb108 | |||
| 473d179d8a | |||
| ba0232a0df | |||
| 873fac0cae | |||
| 355ef36114 | |||
| d70dc52d79 | |||
| 7c3d64f151 | |||
| 41f5852eea | |||
| defc997230 | |||
| a38b4134e7 | |||
| 44ee5bf795 | |||
| 3e1d8e6356 | |||
| 105afed6a0 | |||
| 5c2d9155de | |||
| 1f723bd904 | |||
| 4dade03788 | |||
| fa256a3306 | |||
| 97903fef77 | |||
| fd9a0a45a7 | |||
| b71090fdfb | |||
| 15ccce1c0d | |||
| 0bb8f36d05 | |||
| 7e900abf0a | |||
| eb43e5c7b7 | |||
| 132d8d6ab9 | |||
| edc1cc5b3e | |||
| fd9e1f3179 | |||
| 3a3f38e090 | |||
| 3c68582188 | |||
| fcd35c7b8c | |||
| 6d156e464d | |||
| 1c7880e501 | |||
| e590fbde7c | |||
| 562e8d3c3b | |||
| 1f55c05660 | |||
| dd9f8b45ef | |||
| 8e855770de | |||
| c43e8be80c | |||
| 5205b40393 | |||
| 29f214bdaa | |||
| 6601e9e898 | |||
| 68cb6192c1 | |||
| 8d97f1f141 | |||
| 0405a34d11 | |||
| c7f269d551 | |||
| c96d8530ca | |||
| 07d183da90 | |||
| 7e62779a58 | |||
| 89dec819d2 | |||
| 2e66f0b972 | |||
| ee570fa498 | |||
| f8db1bc03b | |||
| b47d45ccbf | |||
| c7e22ee254 | |||
| d536273abf | |||
| ae87f0ed25 | |||
| 55c45f2e1e | |||
| 2b70fb90e1 | |||
| 495c09a49a | |||
| 9a7e60865d | |||
| 4fb90f2bff | |||
| f4f8fd51e4 | |||
| 3ced14a616 | |||
| 3eb8db90ba | |||
| 60625c4c84 | |||
| d2d62b31ce | |||
| faf60c7a0d | |||
| 19642e5d65 | |||
| 7a5147c5c9 | |||
| bc04f8529d | |||
| 53c0f7480b | |||
| 50f059b871 | |||
| 88b01a13c6 | |||
| 6cdc5d0269 | |||
| 92fd9d285f | |||
| 634f298c89 | |||
| dd5b2fa5f2 | |||
| f0b5792bdc | |||
| b3a2cced6b | |||
| d960d0641e | |||
| 1d5de64d20 | |||
| 3ee003d8f7 | |||
| 3d07343c84 | |||
| 6b456a2b46 | |||
| e94ddc9e43 | |||
| 7a8245b525 | |||
| 6062d8f5f2 | |||
| 38fba69135 | |||
| 6841f162c6 | |||
| 4cb29b4cfc | |||
| 09bf0e8d5e | |||
| 47fb54da2e | |||
| ab34b8f65a | |||
| 8aa60cb746 | |||
| 9636284e32 | |||
| 41712ef171 | |||
| c2cb4c10c8 | |||
| 47b4b29b12 | |||
| 255d448726 | |||
| ddba9e54e7 | |||
| e29b915e9b | |||
| 072192dffa | |||
| 37b69a0130 | |||
| c4a41b12f4 | |||
| 19a8e7e882 | |||
| 44dcbda393 | |||
| 4ff55083e5 | |||
| fb189328de | |||
| cb9882a753 | |||
| d5d565235b | |||
| 165ffe9708 | |||
| ae8b3615ee | |||
| b8ef32c3e8 | |||
| 556927f944 | |||
| 9179fd93ff | |||
| f580380463 | |||
| 9c2ba47eac | |||
| 70e15d6cbb | |||
| f30cc9496a | |||
| 05501af78b | |||
| 748f763f7a | |||
| 4835fc5c9b | |||
| a8f9361f1d | |||
| 6575a222d5 | |||
| 75ea0289cc | |||
| b851b2c938 | |||
| cca76c2f7e | |||
| fec8066734 | |||
| 33fa535dca | |||
| 5fd057af68 | |||
| aee18ef8e2 | |||
| 97ba4c94fc | |||
| d61c443e6a | |||
| 737b6e83a1 | |||
| de4fb7b050 | |||
| bf21627b6f | |||
| ccae6026e6 | |||
| 7530873132 | |||
| 51e75cafb0 | |||
| 29088eb6c9 | |||
| 3fdf826699 | |||
| dcc2b9882b | |||
| 30375de10e | |||
| 30963453c5 | |||
| 0ab5fcccc7 | |||
| e1b4f0374c | |||
| 36963fdca8 | |||
| 25d39a83ac | |||
| 75f86a4b0b | |||
| 46dd62bc69 | |||
| b797783d68 | |||
| dc30dd3158 | |||
| 0f68fd1bd9 | |||
| 1f01ec1b7a | |||
| d0e4a6c11d | |||
| 057cd3a0aa | |||
| 39171f390d | |||
| a10da477c2 | |||
| 208bbcbcba | |||
| 8f4971fcd9 | |||
| 08971de9bc | |||
| 1179ee3418 | |||
| 1722181328 | |||
| 3c407374fc | |||
| aee128dc20 | |||
| 2b6d46b975 | |||
| 802d69a79c | |||
| a1cb183d04 | |||
| 8cbd373ca7 | |||
| c30f9e7356 | |||
| 48af65aeae | |||
| 24c8ab8030 | |||
| 4d88778b26 | |||
| a58fdfb162 | |||
| 7bec505e26 | |||
| a2dc3b1a5e | |||
| 99ba19ea08 | |||
| ac17178853 | |||
| 4e6083cb56 | |||
| 6a67fe8edf | |||
| 62d54916c4 | |||
| f8eb96ab9c | |||
| 4c7f941cfc | |||
| 99b214d28e | |||
| d0a6932f70 | |||
| e90b1bd1f1 | |||
| 7715643f49 | |||
| 24c9253c43 | |||
| a38432df12 | |||
| 161aba32be | |||
| 441daf68d2 | |||
| 490a73bcde | |||
| 48d0d866fc | |||
| 201f7168df | |||
| 74bf02858b | |||
| b3dff964bd | |||
| 59f19c15c5 | |||
| 52a83fbbe9 | |||
| c60e9b82db | |||
| d5b6b38d6f | |||
| 142bdf4051 | |||
| 6c18b6e0f4 | |||
| 0fa388f685 | |||
| 494fa66d19 | |||
| f7c9bfead4 | |||
| b3bce66232 | |||
| c9ec413a08 | |||
| b659e9bf7a | |||
| e63739a868 | |||
| 52f159e040 | |||
| 81e9674ba6 | |||
| 33a5edc3a4 | |||
| 536065afef | |||
| 5742b63e4a | |||
| f87d01abe9 | |||
| e257300f2e | |||
| 9636c4e102 | |||
| 86c4948198 | |||
| bfb9e35b30 | |||
| 190765c470 | |||
| a21c6b6fe0 | |||
| d5a71b5de3 | |||
| fb7e7651ca | |||
| 4af00c6cee | |||
| 940fac9dc5 | |||
| f4d173ae14 | |||
| 178286b5df | |||
| 32554c10d0 | |||
| d89bd007ba | |||
| 52370e2c95 | |||
| 1ba1e6e0b9 | |||
| 80fc58bf99 | |||
| e425464be5 | |||
| 842b864118 | |||
| 0602c2e4a5 | |||
| 54a83b4d5a | |||
| 7bf5661068 | |||
| 576ec6b32a | |||
| 93758c8dcc | |||
| e61b9f4f3c | |||
| 3e8c37e7f8 | |||
| 801845fb2d | |||
| 83715c3edd | |||
| 4eec4c1b0c | |||
| 279d477939 | |||
| fe2093d73e | |||
| 51522cd34a | |||
| 5338a5f74d | |||
| b84f96f854 | |||
| 1ad7f64aac | |||
| 4489f9bdec | |||
| 1bd3644f27 | |||
| 3119bc421a | |||
| 6d32959693 | |||
| 600dd0ba33 | |||
| 1398ad3639 | |||
| 76b047d957 | |||
| ca6707145d | |||
| 030530de9b | |||
| 79d5f63fa2 | |||
| 47a6db2bfd | |||
| 9b3187e113 | |||
| 73b211abed | |||
| 626a879a25 | |||
| 3719d7f9c4 | |||
| 5558a8a697 | |||
| f10519b45a | |||
| 3c9cc8d095 | |||
| fdb7cdb4b1 | |||
| 2683665406 | |||
| 615ae553fc | |||
| 0d477437ac | |||
| aac0a38d1f | |||
| 4e17d14c63 | |||
| 79a40da6d7 | |||
| ac11ee6766 | |||
| 018d1a4929 | |||
| 8b07c7178a | |||
| 39df51b269 | |||
| f222e712a4 | |||
| ac245ec5af | |||
| d6fe961ef4 | |||
| 3b93bc8cb1 | |||
| 8d65973d93 | |||
| c08d405d2e | |||
| 6b77a36abf | |||
| aca790ace3 | |||
| 2c3365493b | |||
| 656152c2e3 | |||
| 4397de57ce | |||
| 8b60e0f142 | |||
| b5402fbf05 | |||
| c8f9079c61 | |||
| ac931eb93b | |||
| a0d1f663e1 | |||
| 48e5aa2769 | |||
| c5cdca613a | |||
| cacb208e4e | |||
| 01427a6214 | |||
| 1400b52838 | |||
| 62e05d8feb | |||
| 2812956b18 | |||
| 7701e817ba | |||
| 307a777932 | |||
| cc6bd38380 | |||
| 49766d6cd0 | |||
| 268283bc7f | |||
| 4b238dfb80 | |||
| 42741be968 | |||
| 59adfaa6ce | |||
| d9c847dcd1 | |||
| a3ad5e7d9f | |||
| dcd7c471ce | |||
| 9d9f76c0b6 | |||
| 7a9b161587 | |||
| 49d642dba8 | |||
| c89b91beee | |||
| 7465a80899 | |||
| acf3b988f6 | |||
| e6f85e71e9 | |||
| 9a09a3caed | |||
| 9012bcbc0a | |||
| 51669863a8 | |||
| 9ee3cdcba7 | |||
| 1067fe1104 | |||
| be5fd4906d | |||
| 23bf66d6af | |||
| 6a8903c3fc | |||
| daa28ff326 | |||
| 93468367fe | |||
| b571b457fa | |||
| 8671e6d784 | |||
| 10fb11da9e | |||
| 2530378003 | |||
| dca7684141 | |||
| 81db88e630 | |||
| 32c0d4f17b | |||
| 61212b69c1 | |||
| 4b2266ae4c | |||
| 7b5717e1a1 | |||
| 3b7b78b312 | |||
| 251b067ccd | |||
| 8b840013da | |||
| 1d54df88e3 | |||
| 78583d2440 | |||
| 11cf9fbcf2 | |||
| c7b4a44cda | |||
| 27188fb5f0 | |||
| ae82558bd0 | |||
| e4e7207248 | |||
| b6c29897eb | |||
| 8237d45ed8 | |||
| d8702b4d40 | |||
| 27c774388a | |||
| 81650dc6c8 | |||
| 125254784d | |||
| aecc8ba904 | |||
| 12b13002ce | |||
| 299b187d76 | |||
| 0fa8ddbdec | |||
| 03aded4924 | |||
| 215e64da5e | |||
| f856582562 | |||
| 60404f46c1 | |||
| b9ecf6fa8e | |||
| 42cac6dacb | |||
| b08153d0fb | |||
| bf128941d0 | |||
| 6c90fecc96 | |||
| 4693423b09 | |||
| 73c42a1386 | |||
| f9c852bfd5 | |||
| 2097e949f6 | |||
| cd45ab2d6f | |||
| 023f41762c | |||
| aacd732b11 | |||
| 4d36b81ea0 | |||
| 343e92610e | |||
| d641d646ff | |||
| 20fc0887f5 | |||
| e854c5607b | |||
| 4f1f8705f6 | |||
| 7c6303c042 | |||
| c7dc75334f | |||
| 602479eae8 | |||
| ed326d7047 | |||
| 6a43f9b3ff | |||
| 670fb032ab | |||
| 7b4e7268f1 | |||
| 6c62608fc6 | |||
| 5436dc2d97 | |||
| 13d7042a73 | |||
| ce9a7b1e57 | |||
| 8040bc8b57 | |||
| f338814455 | |||
| b92b70bb0a | |||
| 1c8c23cc36 | |||
| 9fd2a9a028 | |||
| 2958a4e6a5 | |||
| 817c60bd66 | |||
| dae2495b1f | |||
| 2df9fabf3c | |||
| 45901d622c | |||
| ae381aa1b6 | |||
| e6efa74b9f | |||
| 2a03c3a326 | |||
| 752e679a1e | |||
| 7977a17f06 | |||
| 0ba87cb85d | |||
| 16254450f4 | |||
| 8f5a31b50f | |||
| e0830e8e03 | |||
| 94daf7fdff | |||
| 599fcbae56 | |||
| e497f0051f | |||
| ef73ee9a46 | |||
| eee46cf35c | |||
| 4343fea20f | |||
| b17131a084 | |||
| 063336a55e | |||
| 4794f73524 | |||
| d761c0c9fd | |||
| 951af8050b | |||
| 87a6e7318f | |||
| cb1a7eb0df | |||
| 63e3e9f81a | |||
| e7de6f25a8 | |||
| 7a638581b2 | |||
| 958390005b | |||
| 4e0cff6080 | |||
| f197484617 | |||
| a64a035f7e | |||
| 467d4707ff | |||
| 205f48e635 | |||
| 40e016e492 | |||
| a0bf265269 | |||
| 798da52ce7 | |||
| bf8aa33bba | |||
| 003ba061da | |||
| 6bf895708c | |||
| a71aa00102 | |||
| a19df67c58 | |||
| 1be29eb6be | |||
| f5fdda8208 | |||
| 52fb6d71f5 | |||
| 4fa03bde07 | |||
| e80463bc7d | |||
| 7041e17e9c | |||
| cfe4a990ce | |||
| f78fc0818c | |||
| 06f502170e | |||
| 687566d786 | |||
| a82ffef115 | |||
| afcdd02f6a | |||
| b7f9164e98 | |||
| 27d258a3ec | |||
| 2536ee480b | |||
| 9c35cda6b1 | |||
| 0b2110c9f5 | |||
| 722e95ac65 | |||
| 40f20f7d2a | |||
| f404083e56 | |||
| 887dc4c275 | |||
| 6138df56e7 | |||
| 63afe89499 | |||
| b45bb9f17d | |||
| 44c6d46480 | |||
| 13f52c77dc | |||
| 093031f6b0 | |||
| 81d01352c3 | |||
| 270c856eba | |||
| 1043afaeaf | |||
| a1d65d0221 | |||
| 0fe0b01ed9 | |||
| 3500b7c2d4 | |||
| 757028e6ea | |||
| 57790b8fca | |||
| 2090a0ed48 | |||
| 74ad7fe980 | |||
| 8e64d1caad | |||
| 1e284f4558 | |||
| 5719628afb | |||
| b327f77358 | |||
| 2e3a1f16b6 | |||
| 36d4e97e94 | |||
| 86f43308d6 | |||
| 2783e4bc0e | |||
| 684917c269 | |||
| 9a43267ba2 | |||
| f2bc013c70 | |||
| 9c105bb990 | |||
| 0924bba36c | |||
| 047d4836ff | |||
| ededaa59bd | |||
| eb206256f1 | |||
| a3f70cbc31 | |||
| 596bd23554 | |||
| c60d04464f | |||
| 44f87bdc56 | |||
| 3127653b1c | |||
| 10e8266b91 | |||
| aa756b0978 | |||
| ae29ffbe23 | |||
| 94a11211f5 | |||
| 5e2517e1f3 | |||
| b8dd3155e0 | |||
| 76ff3a0e09 | |||
| 59c98a6f2b | |||
| 3b584fa6c5 | |||
| 971a7c87bc | |||
| 670404626d | |||
| 145716b323 | |||
| 65623c78e8 | |||
| ad6d94607f | |||
| 344737f60a | |||
| c2316c3931 | |||
| 1a9d17fe77 | |||
| 2d7c0609ed | |||
| cc01bc037f | |||
| 8d45ec079d | |||
| d2f397f9f3 | |||
| 31f33e1369 | |||
| d900a46be0 | |||
| 31f11f6923 | |||
| f7a8362920 | |||
| a42707b234 | |||
| c16a03b54b | |||
| fd241b0ea4 | |||
| 90b6bb1995 | |||
| 94a98365a6 | |||
| 2aa6ca45c1 | |||
| 9db55dfb98 | |||
| 5689123ca6 | |||
| 6aff507e73 | |||
| ed6b3eb076 | |||
| 217a416cec | |||
| fe63d1c98b | |||
| 03c8988076 | |||
| 95380fae3c | |||
| 916d68efea | |||
| fa6bc0000f | |||
| 1807ce37b8 | |||
| af805ca035 | |||
| 12057d54ef | |||
| 9bb575fd72 | |||
| 873cdcb2ce | |||
| f2a611c988 | |||
| ad3e010547 | |||
| 2e38c32b67 | |||
| 2c7e56798b | |||
| 6ad3326fd5 |
+174
-105
@@ -26,28 +26,21 @@ BCC = @BUILD_CC@ @BUILD_CFLAGS@
|
||||
# will run on the target platform. (BCC and TCC are usually the
|
||||
# same unless your are cross-compiling.)
|
||||
#
|
||||
TCC = @TARGET_CC@ @TARGET_CFLAGS@ -I. -I${TOP}/src -DNDEBUG
|
||||
TCC = @TARGET_CC@ @TARGET_CFLAGS@ -I. -I${TOP}/src
|
||||
|
||||
# Some standard variables and programs
|
||||
# Define -DNDEBUG to compile without debugging (i.e., for production usage)
|
||||
# Omitting the define will cause extra debugging code to be inserted and
|
||||
# includes extra comments when "EXPLAIN stmt" is used.
|
||||
#
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
INSTALL = @INSTALL@
|
||||
LIBTOOL = ./libtool
|
||||
RELEASE = @ALLOWRELEASE@
|
||||
|
||||
# libtool compile/link/install
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(TCC)
|
||||
LTLINK = $(LIBTOOL) --mode=link $(TCC)
|
||||
LTINSTALL = $(LIBTOOL) --mode=install $(INSTALL)
|
||||
TCC += @TARGET_DEBUG@
|
||||
|
||||
# Compiler options needed for programs that use the TCL library.
|
||||
#
|
||||
TCL_FLAGS = @TARGET_TCL_INC@
|
||||
TCC += @TCL_INCLUDE_SPEC@
|
||||
|
||||
# The library that programs using TCL must link against.
|
||||
#
|
||||
LIBTCL = @TARGET_TCL_LIBS@
|
||||
LIBTCL = @TCL_LIB_SPEC@ @TCL_LIBS@
|
||||
|
||||
# Compiler options needed for programs that use the readline() library.
|
||||
#
|
||||
@@ -59,7 +52,11 @@ LIBREADLINE = @TARGET_READLINE_LIBS@
|
||||
|
||||
# Should the database engine be compiled threadsafe
|
||||
#
|
||||
THREADSAFE = -DTHREADSAFE=@THREADSAFE@
|
||||
TCC += -DTHREADSAFE=@THREADSAFE@
|
||||
|
||||
# The pthreads library if needed
|
||||
#
|
||||
LIBPTHREAD=@TARGET_THREAD_LIB@
|
||||
|
||||
# Flags controlling use of the in memory btree implementation
|
||||
#
|
||||
@@ -69,30 +66,76 @@ THREADSAFE = -DTHREADSAFE=@THREADSAFE@
|
||||
#
|
||||
TEMP_STORE = -DTEMP_STORE=@TEMP_STORE@
|
||||
|
||||
# Version numbers and release number for the SQLite being compiled.
|
||||
#
|
||||
VERSION = @VERSION@
|
||||
VERSION_NUMBER = @VERSION_NUMBER@
|
||||
RELEASE = @RELEASE@
|
||||
|
||||
# Filename extensions
|
||||
#
|
||||
BEXE = @BUILD_EXEEXT@
|
||||
TEXE = @TARGET_EXEEXT@
|
||||
|
||||
# The following variable is "1" if the configure script was able to locate
|
||||
# the tclConfig.sh file. It is an empty string otherwise. When this
|
||||
# variable is "1", the TCL extension library (libtclsqlite3.so) is built
|
||||
# and installed.
|
||||
#
|
||||
HAVE_TCL = @HAVE_TCL@
|
||||
|
||||
# The suffix used on shared libraries. Ex: ".dll", ".so", ".dylib"
|
||||
#
|
||||
SHLIB_SUFFIX = @TCL_SHLIB_SUFFIX@
|
||||
|
||||
# The directory into which to store package information for
|
||||
|
||||
# Some standard variables and programs
|
||||
#
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
libdir = @libdir@
|
||||
INSTALL = @INSTALL@
|
||||
LIBTOOL = ./libtool
|
||||
ALLOWRELEASE = @ALLOWRELEASE@
|
||||
|
||||
# libtool compile/link/install
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(TCC)
|
||||
LTLINK = $(LIBTOOL) --mode=link $(TCC)
|
||||
LTINSTALL = $(LIBTOOL) --mode=install $(INSTALL)
|
||||
|
||||
# You should not have to change anything below this line
|
||||
###############################################################################
|
||||
|
||||
OPTS += -DSQLITE_OMIT_CURSOR # Cursors do not work at this time
|
||||
TCC += -DSQLITE_OMIT_CURSOR
|
||||
|
||||
# Object files for the SQLite library.
|
||||
#
|
||||
LIBOBJ = attach.lo auth.lo btree.lo build.lo date.lo delete.lo \
|
||||
expr.lo func.lo hash.lo insert.lo \
|
||||
main.lo opcodes.lo os_mac.lo os_unix.lo os_win.lo \
|
||||
pager.lo parse.lo pragma.lo printf.lo random.lo \
|
||||
select.lo table.lo tokenize.lo trigger.lo update.lo util.lo vacuum.lo \
|
||||
vdbe.lo vdbeapi.lo vdbeaux.lo vdbemem.lo \
|
||||
LIBOBJ = alter.lo analyze.lo attach.lo auth.lo btree.lo build.lo \
|
||||
callback.lo complete.lo date.lo \
|
||||
delete.lo expr.lo func.lo hash.lo insert.lo \
|
||||
main.lo opcodes.lo os_unix.lo os_win.lo \
|
||||
pager.lo parse.lo pragma.lo prepare.lo printf.lo random.lo \
|
||||
select.lo table.lo tokenize.lo trigger.lo update.lo \
|
||||
util.lo vacuum.lo \
|
||||
vdbe.lo vdbeapi.lo vdbeaux.lo vdbefifo.lo vdbemem.lo \
|
||||
where.lo utf.lo legacy.lo
|
||||
|
||||
# All of the source code files.
|
||||
#
|
||||
SRC = \
|
||||
$(TOP)/src/alter.c \
|
||||
$(TOP)/src/analyze.c \
|
||||
$(TOP)/src/attach.c \
|
||||
$(TOP)/src/auth.c \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/btree.h \
|
||||
$(TOP)/src/build.c \
|
||||
$(TOP)/src/callback.c \
|
||||
$(TOP)/src/complete.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/delete.c \
|
||||
$(TOP)/src/encode.c \
|
||||
$(TOP)/src/expr.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/hash.c \
|
||||
@@ -100,13 +143,13 @@ SRC = \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os_mac.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pager.h \
|
||||
$(TOP)/src/parse.y \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/prepare.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/random.c \
|
||||
$(TOP)/src/select.c \
|
||||
@@ -125,6 +168,7 @@ SRC = \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/vdbeapi.c \
|
||||
$(TOP)/src/vdbeaux.c \
|
||||
$(TOP)/src/vdbefifo.c \
|
||||
$(TOP)/src/vdbemem.c \
|
||||
$(TOP)/src/vdbeInt.h \
|
||||
$(TOP)/src/where.c
|
||||
@@ -133,8 +177,8 @@ SRC = \
|
||||
#
|
||||
TESTSRC = \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/os_mac.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c \
|
||||
@@ -146,20 +190,20 @@ TESTSRC = \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/test5.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/md5.c
|
||||
$(TOP)/src/md5.c \
|
||||
$(TOP)/src/where.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
sqlite3.h \
|
||||
$(TOP)/src/btree.h \
|
||||
config.h \
|
||||
$(TOP)/src/hash.h \
|
||||
opcodes.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/os_common.h \
|
||||
$(TOP)/src/os_mac.h \
|
||||
$(TOP)/src/os_unix.h \
|
||||
$(TOP)/src/os_win.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
@@ -175,7 +219,7 @@ VDBEHDR = \
|
||||
# This is the default Makefile target. The objects listed here
|
||||
# are what get build when you type just "make" with no arguments.
|
||||
#
|
||||
all: sqlite3.h libsqlite3.la sqlite3@TARGET_EXEEXT@
|
||||
all: sqlite3.h libsqlite3.la sqlite3$(TEXE) $(HAVE_TCL:1=libtclsqlite3.la)
|
||||
|
||||
Makefile: $(TOP)/Makefile.in
|
||||
./config.status
|
||||
@@ -188,17 +232,18 @@ last_change: $(SRC)
|
||||
| awk '{print $$5,$$6}' >last_change
|
||||
|
||||
libsqlite3.la: $(LIBOBJ)
|
||||
$(LTLINK) -o libsqlite3.la $(LIBOBJ) ${RELEASE} -rpath @exec_prefix@/lib \
|
||||
-version-info "8:6:8"
|
||||
$(LTLINK) -o libsqlite3.la $(LIBOBJ) $(LIBPTHREAD) \
|
||||
${ALLOWRELEASE} -rpath $(libdir) -version-info "8:6:8"
|
||||
|
||||
libtclsqlite3.la: tclsqlite.lo libsqlite3.la
|
||||
$(LTLINK) -o libtclsqlite3.la tclsqlite.lo \
|
||||
libsqlite3.la $(LIBTCL) -rpath @exec_prefix@/lib/sqlite \
|
||||
$(LIBOBJ) @TCL_STUB_LIB_SPEC@ $(LIBPTHREAD) \
|
||||
-rpath $(libdir)/sqlite \
|
||||
-version-info "8:6:8"
|
||||
|
||||
sqlite3@TARGET_EXEEXT@: $(TOP)/src/shell.c libsqlite3.la sqlite3.h
|
||||
$(LTLINK) $(READLINE_FLAGS) -o sqlite3 $(TOP)/src/shell.c \
|
||||
libsqlite3.la $(LIBREADLINE)
|
||||
sqlite3$(TEXE): $(TOP)/src/shell.c libsqlite3.la sqlite3.h
|
||||
$(LTLINK) $(READLINE_FLAGS) $(LIBPTHREAD) \
|
||||
-o sqlite3 $(TOP)/src/shell.c libsqlite3.la $(LIBREADLINE)
|
||||
|
||||
# This target creates a directory named "tsrc" and fills it with
|
||||
# copies of all of the C source code and header files needed to
|
||||
@@ -206,23 +251,29 @@ sqlite3@TARGET_EXEEXT@: $(TOP)/src/shell.c libsqlite3.la sqlite3.h
|
||||
# files are automatically generated. This target takes care of
|
||||
# all that automatic generation.
|
||||
#
|
||||
target_source: $(SRC) $(VDBEHDR)
|
||||
target_source: $(SRC) parse.c opcodes.c keywordhash.h $(VDBEHDR)
|
||||
rm -rf tsrc
|
||||
mkdir tsrc
|
||||
mkdir -p tsrc
|
||||
cp $(SRC) $(VDBEHDR) tsrc
|
||||
rm tsrc/sqlite.h.in tsrc/parse.y
|
||||
cp parse.c opcodes.c tsrc
|
||||
cp parse.c opcodes.c keywordhash.h tsrc
|
||||
cp $(TOP)/sqlite3.def tsrc
|
||||
|
||||
# Rules to build the LEMON compiler generator
|
||||
#
|
||||
lemon@BUILD_EXEEXT@: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
lemon$(BEXE): $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
$(BCC) -o lemon $(TOP)/tool/lemon.c
|
||||
cp $(TOP)/tool/lempar.c .
|
||||
|
||||
|
||||
# Rules to build individual files
|
||||
#
|
||||
alter.lo: $(TOP)/src/alter.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/alter.c
|
||||
|
||||
analyze.lo: $(TOP)/src/analyze.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/analyze.c
|
||||
|
||||
attach.lo: $(TOP)/src/attach.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/attach.c
|
||||
|
||||
@@ -235,21 +286,11 @@ btree.lo: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
|
||||
build.lo: $(TOP)/src/build.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/build.c
|
||||
|
||||
# The config.h file will contain a single #define that tells us how
|
||||
# many bytes are in a pointer. This only works if a pointer is the
|
||||
# same size on the host as it is on the target. If you are cross-compiling
|
||||
# to a target with a different pointer size, you'll need to manually
|
||||
# configure the config.h file.
|
||||
#
|
||||
config.h:
|
||||
echo '#include <stdio.h>' >temp.c
|
||||
echo 'int main(){printf(' >>temp.c
|
||||
echo '"#define SQLITE_PTR_SZ %d",sizeof(char*));' >>temp.c
|
||||
echo 'exit(0);}' >>temp.c
|
||||
$(BCC) -o temp temp.c
|
||||
./temp >config.h
|
||||
echo >>config.h
|
||||
rm -f temp.c temp
|
||||
callback.lo: $(TOP)/src/callback.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/callback.c
|
||||
|
||||
complete.lo: $(TOP)/src/complete.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/complete.c
|
||||
|
||||
date.lo: $(TOP)/src/date.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/date.c
|
||||
@@ -257,9 +298,6 @@ date.lo: $(TOP)/src/date.c $(HDR)
|
||||
delete.lo: $(TOP)/src/delete.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/delete.c
|
||||
|
||||
encode.lo: $(TOP)/src/encode.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/encode.c
|
||||
|
||||
expr.lo: $(TOP)/src/expr.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/expr.c
|
||||
|
||||
@@ -284,42 +322,35 @@ pager.lo: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
opcodes.lo: opcodes.c
|
||||
$(LTCOMPILE) -c opcodes.c
|
||||
|
||||
opcodes.c: $(TOP)/src/vdbe.c
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.c
|
||||
echo 'char *sqlite3OpcodeNames[] = { "???", ' >>opcodes.c
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/^.*OP_/ "/' -e 's/:.*$$/", /' >>opcodes.c
|
||||
echo '};' >>opcodes.c
|
||||
opcodes.c: opcodes.h $(TOP)/mkopcodec.awk
|
||||
sort -n -b +2 opcodes.h | awk -f $(TOP)/mkopcodec.awk >opcodes.c
|
||||
|
||||
opcodes.h: $(TOP)/src/vdbe.h
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.h
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/://' | \
|
||||
awk '{printf "#define %-30s %3d\n", $$2, ++cnt}' >>opcodes.h
|
||||
|
||||
os_mac.lo: $(TOP)/src/os_mac.c $(HDR)
|
||||
$(LTCOMPILE) $(THREADSAFE) -c $(TOP)/src/os_mac.c
|
||||
opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk
|
||||
cat parse.h $(TOP)/src/vdbe.c | awk -f $(TOP)/mkopcodeh.awk >opcodes.h
|
||||
|
||||
os_unix.lo: $(TOP)/src/os_unix.c $(HDR)
|
||||
$(LTCOMPILE) $(THREADSAFE) -c $(TOP)/src/os_unix.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/os_unix.c
|
||||
|
||||
os_win.lo: $(TOP)/src/os_win.c $(HDR)
|
||||
$(LTCOMPILE) $(THREADSAFE) -c $(TOP)/src/os_win.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/os_win.c
|
||||
|
||||
parse.lo: parse.c $(HDR)
|
||||
$(LTCOMPILE) -c parse.c
|
||||
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon@BUILD_EXEEXT@
|
||||
parse.c: $(TOP)/src/parse.y lemon$(BEXE)
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon parse.y
|
||||
./lemon $(OPTS) parse.y
|
||||
|
||||
pragma.lo: $(TOP)/src/pragma.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/pragma.c
|
||||
|
||||
prepare.lo: $(TOP)/src/prepare.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/prepare.c
|
||||
|
||||
printf.lo: $(TOP)/src/printf.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/printf.c
|
||||
|
||||
random.lo: $(TOP)/src/random.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/random.c
|
||||
@@ -328,18 +359,22 @@ select.lo: $(TOP)/src/select.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/select.c
|
||||
|
||||
sqlite3.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||
$(TOP)/src/sqlite.h.in >sqlite3.h
|
||||
sed -e s/--VERS--/$(RELEASE)/ $(TOP)/src/sqlite.h.in | \
|
||||
sed -e s/--VERSION-NUMBER--/$(VERSION_NUMBER)/ >sqlite3.h
|
||||
|
||||
table.lo: $(TOP)/src/table.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/table.c
|
||||
|
||||
tclsqlite.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
tokenize.lo: $(TOP)/src/tokenize.c $(HDR)
|
||||
tokenize.lo: $(TOP)/src/tokenize.c keywordhash.h $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/tokenize.c
|
||||
|
||||
keywordhash.h: $(TOP)/tool/mkkeywordhash.c
|
||||
$(BCC) -o mkkeywordhash$(BEXE) $(OPTS) $(TOP)/tool/mkkeywordhash.c
|
||||
./mkkeywordhash$(BEXE) >keywordhash.h
|
||||
|
||||
trigger.lo: $(TOP)/src/trigger.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/trigger.c
|
||||
|
||||
@@ -364,39 +399,56 @@ vdbeapi.lo: $(TOP)/src/vdbeapi.c $(VDBEHDR)
|
||||
vdbeaux.lo: $(TOP)/src/vdbeaux.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbeaux.c
|
||||
|
||||
vdbefifo.lo: $(TOP)/src/vdbefifo.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbefifo.c
|
||||
|
||||
vdbemem.lo: $(TOP)/src/vdbemem.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbemem.c
|
||||
|
||||
where.lo: $(TOP)/src/where.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/where.c
|
||||
|
||||
tclsqlite-sh.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -DTCLSH=1 -o $@ -c $(TOP)/src/tclsqlite.c
|
||||
tclsqlite-shell.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LTCOMPILE) -DTCLSH=1 -o $@ -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
tclsqlite3: tclsqlite-sh.lo libsqlite3.la
|
||||
$(LTLINK) $(TCL_FLAGS) -o tclsqlite3 tclsqlite-sh.lo \
|
||||
tclsqlite-stubs.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LTCOMPILE) -DTCL_USE_STUBS=1 -o $@ -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
tclsqlite3: tclsqlite-shell.lo libsqlite3.la
|
||||
$(LTLINK) -o tclsqlite3 tclsqlite-shell.lo \
|
||||
libsqlite3.la $(LIBTCL)
|
||||
|
||||
testfixture@TARGET_EXEEXT@: $(TOP)/src/tclsqlite.c libtclsqlite3.la libsqlite3.la $(TESTSRC)
|
||||
$(LTLINK) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1\
|
||||
$(THREADSAFE) $(TEMP_STORE)\
|
||||
-o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libtclsqlite3.la libsqlite3.la $(LIBTCL)
|
||||
testfixture$(TEXE): $(TOP)/src/tclsqlite.c libsqlite3.la $(TESTSRC)
|
||||
$(LTLINK) -DTCLSH=1 -DSQLITE_TEST=1 $(TEMP_STORE) \
|
||||
-o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.la $(LIBTCL)
|
||||
|
||||
crashtest@TARGET_EXEEXT@: $(TOP)/src/tclsqlite.c libsqlite3.la $(TESTSRC) $(TOP)/src/os_test.c
|
||||
$(LTLINK) $(TCL_FLAGS) -DOS_TEST=1 -DTCLSH=1 -DSQLITE_TEST=1 \
|
||||
crashtest$(TEXE): $(TOP)/src/tclsqlite.c libsqlite3.la $(TESTSRC) $(TOP)/src/os_test.c
|
||||
$(LTLINK) -DOS_TEST=1 -DTCLSH=1 -DSQLITE_TEST=1 \
|
||||
-o crashtest \
|
||||
$(TESTSRC) $(TOP)/src/os_test.c $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.la $(LIBTCL) $(THREADLIB)
|
||||
libsqlite3.la $(LIBTCL)
|
||||
|
||||
|
||||
|
||||
fulltest: testfixture@TARGET_EXEEXT@ sqlite3@TARGET_EXEEXT@ crashtest@TARGET_EXEEXT@
|
||||
fulltest: testfixture$(TEXE) sqlite3$(TEXE) crashtest$(TEXE)
|
||||
./testfixture $(TOP)/test/all.test
|
||||
|
||||
test: testfixture@TARGET_EXEEXT@ sqlite3@TARGET_EXEEXT@
|
||||
test: testfixture$(TEXE) sqlite3$(TEXE)
|
||||
./testfixture $(TOP)/test/quick.test
|
||||
|
||||
sqlite3_analyzer$(TEXE): $(TOP)/src/tclsqlite.c libtclsqlite3.la \
|
||||
$(TESTSRC) $(TOP)/tool/spaceanal.tcl
|
||||
sed \
|
||||
-e '/^#/d' \
|
||||
-e 's,\\,\\\\,g' \
|
||||
-e 's,",\\",g' \
|
||||
-e 's,^,",' \
|
||||
-e 's,$$,\\n",' \
|
||||
$(TOP)/tool/spaceanal.tcl >spaceanal_tcl.h
|
||||
$(LTLINK) -DTCLSH=2 -DSQLITE_TEST=1 $(TEMP_STORE)\
|
||||
-o sqlite3_analyzer$(EXE) $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libtclsqlite3.la $(LIBTCL)
|
||||
|
||||
# Rules used to build documentation
|
||||
#
|
||||
@@ -406,6 +458,9 @@ arch.html: $(TOP)/www/arch.tcl
|
||||
arch2.gif: $(TOP)/www/arch2.gif
|
||||
cp $(TOP)/www/arch2.gif .
|
||||
|
||||
autoinc.html: $(TOP)/www/autoinc.tcl
|
||||
tclsh $(TOP)/www/autoinc.tcl >autoinc.html
|
||||
|
||||
c_interface.html: $(TOP)/www/c_interface.tcl
|
||||
tclsh $(TOP)/www/c_interface.tcl >c_interface.html
|
||||
|
||||
@@ -418,6 +473,9 @@ capi3ref.html: $(TOP)/www/capi3ref.tcl
|
||||
changes.html: $(TOP)/www/changes.tcl
|
||||
tclsh $(TOP)/www/changes.tcl >changes.html
|
||||
|
||||
compile.html: $(TOP)/www/compile.tcl
|
||||
tclsh $(TOP)/www/compile.tcl >compile.html
|
||||
|
||||
copyright.html: $(TOP)/www/copyright.tcl
|
||||
tclsh $(TOP)/www/copyright.tcl >copyright.html
|
||||
|
||||
@@ -443,7 +501,7 @@ docs.html: $(TOP)/www/docs.tcl
|
||||
tclsh $(TOP)/www/docs.tcl >docs.html
|
||||
|
||||
download.html: $(TOP)/www/download.tcl
|
||||
mkdir doc
|
||||
mkdir -p doc
|
||||
tclsh $(TOP)/www/download.tcl >download.html
|
||||
|
||||
faq.html: $(TOP)/www/faq.tcl
|
||||
@@ -461,6 +519,9 @@ index.html: $(TOP)/www/index.tcl last_change
|
||||
lang.html: $(TOP)/www/lang.tcl
|
||||
tclsh $(TOP)/www/lang.tcl >lang.html
|
||||
|
||||
pragma.html: $(TOP)/www/pragma.tcl
|
||||
tclsh $(TOP)/www/pragma.tcl >pragma.html
|
||||
|
||||
lockingv3.html: $(TOP)/www/lockingv3.tcl
|
||||
tclsh $(TOP)/www/lockingv3.tcl >lockingv3.html
|
||||
|
||||
@@ -509,10 +570,12 @@ version3.html: $(TOP)/www/version3.tcl
|
||||
DOC = \
|
||||
arch.html \
|
||||
arch2.gif \
|
||||
autoinc.html \
|
||||
c_interface.html \
|
||||
capi3.html \
|
||||
capi3ref.html \
|
||||
changes.html \
|
||||
compile.html \
|
||||
copyright.html \
|
||||
copyright-release.html \
|
||||
copyright-release.pdf \
|
||||
@@ -532,6 +595,7 @@ DOC = \
|
||||
oldnews.html \
|
||||
omitted.html \
|
||||
opcode.html \
|
||||
pragma.html \
|
||||
quickstart.html \
|
||||
speed.html \
|
||||
sqlite.gif \
|
||||
@@ -539,30 +603,34 @@ DOC = \
|
||||
support.html \
|
||||
tclsqlite.html \
|
||||
vdbe.html \
|
||||
version3.html
|
||||
version3.html
|
||||
|
||||
doc: common.tcl $(DOC)
|
||||
mkdir -p doc
|
||||
mv $(DOC) doc
|
||||
|
||||
install: sqlite3 libsqlite3.la sqlite3.h
|
||||
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/lib
|
||||
$(LTINSTALL) libsqlite3.la $(DESTDIR)$(exec_prefix)/lib
|
||||
install: sqlite3 libsqlite3.la sqlite3.h ${HAVE_TCL:1=tcl_install}
|
||||
$(INSTALL) -d $(DESTDIR)$(libdir)
|
||||
$(LTINSTALL) libsqlite3.la $(DESTDIR)$(libdir)
|
||||
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/bin
|
||||
$(LTINSTALL) sqlite3 $(DESTDIR)$(exec_prefix)/bin
|
||||
$(INSTALL) -d $(DESTDIR)$(prefix)/include
|
||||
$(INSTALL) -m 0644 sqlite3.h $(DESTDIR)$(prefix)/include
|
||||
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/lib/pkgconfig;
|
||||
$(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(exec_prefix)/lib/pkgconfig;
|
||||
$(INSTALL) -d $(DESTDIR)$(libdir)/pkgconfig;
|
||||
$(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(libdir)/pkgconfig;
|
||||
|
||||
tcl_install: libtclsqlite3.la
|
||||
tclsh $(TOP)/tclinstaller.tcl $(VERSION)
|
||||
|
||||
clean:
|
||||
rm -f *.lo *.la *.o sqlite3@TARGET_EXEEXT@ libsqlite3.la
|
||||
rm -f *.lo *.la *.o sqlite3$(TEXE) libsqlite3.la
|
||||
rm -f sqlite3.h opcodes.*
|
||||
rm -rf .libs .deps
|
||||
rm -f lemon@BUILD_EXEEXT@ lempar.c parse.* sqlite*.tar.gz
|
||||
rm -f lemon$(BEXE) lempar.c parse.* sqlite*.tar.gz
|
||||
rm -f mkkeywordhash$(BEXE) keywordhash.h
|
||||
rm -f $(PUBLISH)
|
||||
rm -f *.da *.bb *.bbg gmon.out
|
||||
rm -f testfixture@TARGET_EXEEXT@ test.db
|
||||
rm -f testfixture$(TEXE) test.db
|
||||
rm -rf doc
|
||||
rm -f common.tcl
|
||||
rm -f sqlite3.dll sqlite3.lib
|
||||
@@ -584,7 +652,8 @@ implib: sqlite3.lib
|
||||
#make Borland C++ and/or Microsoft VC import library for the dll
|
||||
# ignore any errors (usually due to missing programs)
|
||||
sqlite3.lib: sqlite3.dll
|
||||
-implib -a sqlite3.lib sqlite3.dll
|
||||
-impdef -a sqlite3.def sqlite3.dll
|
||||
-implib sqlite3.lib sqlite3.def
|
||||
-lib /machine:i386 /def:$(TOP)/sqlite3.def
|
||||
|
||||
distclean: clean
|
||||
|
||||
+4
-4
@@ -94,13 +94,13 @@ LIBTCL = /home/drh/tcltk/8.4linux/libtcl8.4g.a -lm -ldl
|
||||
|
||||
#### Compiler options needed for programs that use the readline() library.
|
||||
#
|
||||
#READLINE_FLAGS =
|
||||
READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline
|
||||
READLINE_FLAGS =
|
||||
#READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline
|
||||
|
||||
#### Linker options needed by programs using readline() must link against.
|
||||
#
|
||||
#LIBREADLINE =
|
||||
LIBREADLINE = -static -lreadline -ltermcap
|
||||
LIBREADLINE =
|
||||
#LIBREADLINE = -static -lreadline -ltermcap
|
||||
|
||||
#### Should the database engine assume text is coded as UTF-8 or iso8859?
|
||||
#
|
||||
|
||||
@@ -15,6 +15,7 @@ For example:
|
||||
cd bld ;# Change to the build directory
|
||||
../sqlite/configure ;# Run the configure script
|
||||
make ;# Run the makefile.
|
||||
make install ;# (Optional) Install the build products
|
||||
|
||||
The configure script uses autoconf 2.50 and libtool. If the configure
|
||||
script does not work out for you, there is a generic makefile named
|
||||
@@ -32,6 +33,3 @@ script at the top-level of the source tree.
|
||||
Contacts:
|
||||
|
||||
http://www.sqlite.org/
|
||||
http://www.hwaci.com/sw/sqlite/
|
||||
http://groups.yahoo.com/group/sqlite/
|
||||
drh@hwaci.com
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
+171
-85
@@ -1,9 +1,4 @@
|
||||
#
|
||||
# This file describes a "configure" script that is used to build
|
||||
# makefiles for a particular platform. Process this file using
|
||||
# Autoconf version 1.13 in order to generate that script. All
|
||||
# lines of this file up to the AC_INIT macro are ignored.
|
||||
#
|
||||
# The build process allows for using a cross-compiler. But the default
|
||||
# action is to target the same platform that we are running on. The
|
||||
# configure script needs to discover the following properties of the
|
||||
@@ -62,18 +57,11 @@
|
||||
# into *.o files. Do not include TARGET_TCL_INC in this list.
|
||||
# Makefiles might add additional switches such as "-I.".
|
||||
#
|
||||
# TARGET_TCL_LIBS
|
||||
# TCL_*
|
||||
#
|
||||
# This is the library directives passed to the target linker
|
||||
# that cause the executable to link against Tcl. This might
|
||||
# be a switch like "-ltcl8.0" or pathnames of library file
|
||||
# like "../../src/libtcl8.0.a".
|
||||
#
|
||||
# TARGET_TCL_INC
|
||||
#
|
||||
# This variables define the directory that contain header
|
||||
# files for Tcl. If the compiler is able to find <tcl.h>
|
||||
# on its own, then this can be blank.
|
||||
# Lots of values are read in from the tclConfig.sh script,
|
||||
# if that script is available. This values are used for
|
||||
# constructing and installing the TCL extension.
|
||||
#
|
||||
# TARGET_READLINE_LIBS
|
||||
#
|
||||
@@ -118,16 +106,6 @@
|
||||
# where FILE is the name of the file that sets the environment
|
||||
# variables. FILE should be an absolute pathname.
|
||||
#
|
||||
# If you have a Tcl/Tk/BLT source distribution available, then the
|
||||
# files in that distribution will be used instead of any other
|
||||
# Tcl/Tk/BLT files the script might discover if you tell the configure
|
||||
# script about the source tree. Use commandline options:
|
||||
#
|
||||
# --with-tcl=PATH --with-tk=PATH --with-blt=PATH
|
||||
#
|
||||
# Or set environment variables config_WITH_TCL, config_WITH_TK, or
|
||||
# config_WITH_BLT.
|
||||
#
|
||||
# This configure.in file is easy to reuse on other projects. Just
|
||||
# change the argument to AC_INIT(). And disable any features that
|
||||
# you don't need (for example BLT) by erasing or commenting out
|
||||
@@ -138,7 +116,7 @@ AC_INIT(src/sqlite.h.in)
|
||||
dnl Put the RCS revision string after AC_INIT so that it will also
|
||||
dnl show in in configure.
|
||||
# The following RCS revision string applies to configure.in
|
||||
# $Revision: 1.10 $
|
||||
# $Revision: 1.17 $
|
||||
|
||||
#########
|
||||
# Programs needed
|
||||
@@ -154,11 +132,17 @@ if test "$program_prefix" = "NONE"; then
|
||||
fi
|
||||
AC_SUBST(program_prefix)
|
||||
|
||||
if test -f VERSION; then
|
||||
VERSION=`cat VERSION`
|
||||
echo "Version set to $VERSION"
|
||||
fi
|
||||
VERSION=[`cat $srcdir/VERSION | sed 's/^\([0-9]*\.*[0-9]*\).*/\1/'`]
|
||||
echo "Version set to $VERSION"
|
||||
AC_SUBST(VERSION)
|
||||
RELEASE=`cat $srcdir/VERSION`
|
||||
echo "Release set to $RELEASE"
|
||||
AC_SUBST(RELEASE)
|
||||
VERSION_NUMBER=[`cat $srcdir/VERSION \
|
||||
| sed 's/[^0-9]/ /g' \
|
||||
| awk '{printf "%d%03d%03d",$1,$2,$3}'`]
|
||||
echo "Version number set to $VERSION_NUMBER"
|
||||
AC_SUBST(VERSION_NUMBER)
|
||||
|
||||
#########
|
||||
# Check to see if the --with-hints=FILE option is used. If there is none,
|
||||
@@ -305,6 +289,16 @@ else
|
||||
fi
|
||||
AC_SUBST(THREADSAFE)
|
||||
|
||||
if test "$THREADSAFE" = "1"; then
|
||||
LIBS=""
|
||||
AC_CHECK_LIB(pthread, pthread_create)
|
||||
TARGET_THREAD_LIB="$LIBS"
|
||||
LIBS=""
|
||||
else
|
||||
TARGET_THREAD_LIB=""
|
||||
fi
|
||||
AC_SUBST(TARGET_THREAD_LIB)
|
||||
|
||||
##########
|
||||
# Do we want to support release
|
||||
#
|
||||
@@ -400,65 +394,146 @@ fi
|
||||
AC_SUBST(TARGET_LIBS)
|
||||
|
||||
##########
|
||||
# Figure out what C libraries are required to compile Tcl programs.
|
||||
# Figure out all the parameters needed to compile against Tcl.
|
||||
#
|
||||
if test "$config_TARGET_TCL_LIBS" != ""; then
|
||||
TARGET_TCL_LIBS="$config_TARGET_TCL_LIBS"
|
||||
else
|
||||
if test "$with_tcl" != ""; then
|
||||
extra=`echo $with_tcl/$tclsubdir/libtcl8*.a`
|
||||
fi
|
||||
CC=$TARGET_CC
|
||||
AC_CHECK_FUNC(sin, LIBS="", LIBS="-lm")
|
||||
AC_CHECK_LIB(dl, dlopen)
|
||||
otherlibs=$LIBS
|
||||
if test "$extra" != ""; then
|
||||
LIBS=$extra
|
||||
else
|
||||
LIBS=""
|
||||
AC_SEARCH_LIBS(Tcl_Init, dnl
|
||||
tcl8.4 tcl8.3 tcl84 tcl83 tcl,,,$otherlibs)
|
||||
fi
|
||||
TARGET_TCL_LIBS="$LIBS $otherlibs"
|
||||
fi
|
||||
AC_SUBST(TARGET_TCL_LIBS)
|
||||
|
||||
##########
|
||||
# Figure out where to get the TCL header files.
|
||||
# This code is derived from the SC_PATH_TCLCONFIG and SC_LOAD_TCLCONFIG
|
||||
# macros in the in the tcl.m4 file of the standard TCL distribution.
|
||||
# Those macros could not be used directly since we have to make some
|
||||
# minor changes to accomodate systems that do not have TCL installed.
|
||||
#
|
||||
AC_MSG_CHECKING([TCL header files])
|
||||
found=no
|
||||
if test "$config_TARGET_TCL_INC" != ""; then
|
||||
TARGET_TCL_INC=$config_TARGET_TCL_INC
|
||||
found=yes
|
||||
else
|
||||
if test "$with_tcl" != ""; then
|
||||
TARGET_TCL_INC="-I$with_tcl/generic -I$with_tcl/$tclsubdir"
|
||||
found=yes
|
||||
else
|
||||
TARGET_TCL_INC=""
|
||||
found=no
|
||||
fi
|
||||
fi
|
||||
if test "$found" = "yes"; then
|
||||
AC_MSG_RESULT($TARGET_TCL_INC)
|
||||
else
|
||||
AC_MSG_RESULT(not specified: still searching...)
|
||||
AC_CHECK_HEADER(tcl.h, [found=yes])
|
||||
fi
|
||||
if test "$found" = "no"; then
|
||||
for dir in /usr/local /usr/X11 /usr/X11R6 /usr/pkg /usr/contrib /usr; do
|
||||
AC_CHECK_FILE($dir/include/tcl.h, found=yes)
|
||||
if test "$found" = "yes"; then
|
||||
TARGET_TCL_INC="-I$dir/include"
|
||||
break
|
||||
AC_ARG_ENABLE(tcl, [ --disable-tcl do not build TCL extension],
|
||||
[use_tcl=$enableval],[use_tcl=yes])
|
||||
if test "${use_tcl}" = "yes" ; then
|
||||
AC_ARG_WITH(tcl, [ --with-tcl=DIR directory containing tcl configuration (tclConfig.sh)], with_tclconfig=${withval})
|
||||
AC_MSG_CHECKING([for Tcl configuration])
|
||||
AC_CACHE_VAL(ac_cv_c_tclconfig,[
|
||||
# First check to see if --with-tcl was specified.
|
||||
if test x"${with_tclconfig}" != x ; then
|
||||
if test -f "${with_tclconfig}/tclConfig.sh" ; then
|
||||
ac_cv_c_tclconfig=`(cd ${with_tclconfig}; pwd)`
|
||||
else
|
||||
AC_MSG_ERROR([${with_tclconfig} directory doesn't contain tclConfig.sh])
|
||||
fi
|
||||
fi
|
||||
done
|
||||
# then check for a private Tcl installation
|
||||
if test x"${ac_cv_c_tclconfig}" = x ; then
|
||||
for i in \
|
||||
../tcl \
|
||||
`ls -dr ../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
|
||||
`ls -dr ../tcl[[8-9]].[[0-9]] 2>/dev/null` \
|
||||
`ls -dr ../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
|
||||
../../tcl \
|
||||
`ls -dr ../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
|
||||
`ls -dr ../../tcl[[8-9]].[[0-9]] 2>/dev/null` \
|
||||
`ls -dr ../../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
|
||||
../../../tcl \
|
||||
`ls -dr ../../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
|
||||
`ls -dr ../../../tcl[[8-9]].[[0-9]] 2>/dev/null` \
|
||||
`ls -dr ../../../tcl[[8-9]].[[0-9]]* 2>/dev/null`
|
||||
do
|
||||
if test -f "$i/unix/tclConfig.sh" ; then
|
||||
ac_cv_c_tclconfig=`(cd $i/unix; pwd)`
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# check in a few common install locations
|
||||
if test x"${ac_cv_c_tclconfig}" = x ; then
|
||||
for i in \
|
||||
`ls -d ${libdir} 2>/dev/null` \
|
||||
`ls -d /usr/local/lib 2>/dev/null` \
|
||||
`ls -d /usr/contrib/lib 2>/dev/null` \
|
||||
`ls -d /usr/lib 2>/dev/null`
|
||||
do
|
||||
if test -f "$i/tclConfig.sh" ; then
|
||||
ac_cv_c_tclconfig=`(cd $i; pwd)`
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# check in a few other private locations
|
||||
if test x"${ac_cv_c_tclconfig}" = x ; then
|
||||
for i in \
|
||||
${srcdir}/../tcl \
|
||||
`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
|
||||
`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]] 2>/dev/null` \
|
||||
`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]]* 2>/dev/null`
|
||||
do
|
||||
if test -f "$i/unix/tclConfig.sh" ; then
|
||||
ac_cv_c_tclconfig=`(cd $i/unix; pwd)`
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
])
|
||||
|
||||
if test x"${ac_cv_c_tclconfig}" = x ; then
|
||||
use_tcl=no
|
||||
AC_MSG_WARN(Can't find Tcl configuration definitions)
|
||||
AC_MSG_WARN(*** Without Tcl the regression tests cannot be executed ***)
|
||||
AC_MSG_WARN(*** Consider using --with-tcl=... to define location of Tcl ***)
|
||||
else
|
||||
TCL_BIN_DIR=${ac_cv_c_tclconfig}
|
||||
AC_MSG_RESULT(found $TCL_BIN_DIR/tclConfig.sh)
|
||||
|
||||
AC_MSG_CHECKING([for existence of $TCL_BIN_DIR/tclConfig.sh])
|
||||
if test -f "$TCL_BIN_DIR/tclConfig.sh" ; then
|
||||
AC_MSG_RESULT([loading])
|
||||
. $TCL_BIN_DIR/tclConfig.sh
|
||||
else
|
||||
AC_MSG_RESULT([file not found])
|
||||
fi
|
||||
|
||||
#
|
||||
# If the TCL_BIN_DIR is the build directory (not the install directory),
|
||||
# then set the common variable name to the value of the build variables.
|
||||
# For example, the variable TCL_LIB_SPEC will be set to the value
|
||||
# of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC
|
||||
# instead of TCL_BUILD_LIB_SPEC since it will work with both an
|
||||
# installed and uninstalled version of Tcl.
|
||||
#
|
||||
|
||||
if test -f $TCL_BIN_DIR/Makefile ; then
|
||||
TCL_LIB_SPEC=${TCL_BUILD_LIB_SPEC}
|
||||
TCL_STUB_LIB_SPEC=${TCL_BUILD_STUB_LIB_SPEC}
|
||||
TCL_STUB_LIB_PATH=${TCL_BUILD_STUB_LIB_PATH}
|
||||
fi
|
||||
|
||||
#
|
||||
# eval is required to do the TCL_DBGX substitution
|
||||
#
|
||||
|
||||
eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
|
||||
eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
|
||||
eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""
|
||||
|
||||
eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""
|
||||
eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
|
||||
eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""
|
||||
|
||||
AC_SUBST(TCL_VERSION)
|
||||
AC_SUBST(TCL_BIN_DIR)
|
||||
AC_SUBST(TCL_SRC_DIR)
|
||||
AC_SUBST(TCL_LIBS)
|
||||
AC_SUBST(TCL_INCLUDE_SPEC)
|
||||
|
||||
AC_SUBST(TCL_LIB_FILE)
|
||||
AC_SUBST(TCL_LIB_FLAG)
|
||||
AC_SUBST(TCL_LIB_SPEC)
|
||||
|
||||
AC_SUBST(TCL_STUB_LIB_FILE)
|
||||
AC_SUBST(TCL_STUB_LIB_FLAG)
|
||||
AC_SUBST(TCL_STUB_LIB_SPEC)
|
||||
fi
|
||||
fi
|
||||
if test "$found" = "no"; then
|
||||
TARGET_TCL_INC="-DNO_TCL=1"
|
||||
if test "${use_tcl}" = "no" ; then
|
||||
HAVE_TCL=""
|
||||
else
|
||||
HAVE_TCL=1
|
||||
fi
|
||||
AC_SUBST(TARGET_TCL_INC)
|
||||
AC_SUBST(HAVE_TCL)
|
||||
|
||||
##########
|
||||
# Figure out what C libraries are required to compile programs
|
||||
@@ -516,6 +591,17 @@ fi
|
||||
AC_SUBST(TARGET_READLINE_INC)
|
||||
AC_SUBST(TARGET_HAVE_READLINE)
|
||||
|
||||
#########
|
||||
# check for debug enabled
|
||||
AC_ARG_ENABLE(debug, [ --enable-debug enable debugging & verbose explain],
|
||||
[use_debug=$enableval],[use_debug=no])
|
||||
if test "${use_debug}" = "yes" ; then
|
||||
TARGET_DEBUG=""
|
||||
else
|
||||
TARGET_DEBUG="-DNDEBUG"
|
||||
fi
|
||||
AC_SUBST(TARGET_DEBUG)
|
||||
|
||||
#########
|
||||
# Figure out whether or not we have a "usleep()" function.
|
||||
#
|
||||
|
||||
@@ -0,0 +1,679 @@
|
||||
# A Tk console widget for SQLite. Invoke sqlitecon::create with a window name,
|
||||
# a prompt string, a title to set a new top-level window, and the SQLite
|
||||
# database handle. For example:
|
||||
#
|
||||
# sqlitecon::create .sqlcon {sql:- } {SQL Console} db
|
||||
#
|
||||
# A toplevel window is created that allows you to type in SQL commands to
|
||||
# be processed on the spot.
|
||||
#
|
||||
# A limited set of dot-commands are supported:
|
||||
#
|
||||
# .table
|
||||
# .schema ?TABLE?
|
||||
# .mode list|column|multicolumn|line
|
||||
# .exit
|
||||
#
|
||||
# In addition, a new SQL function named "edit()" is created. This function
|
||||
# takes a single text argument and returns a text result. Whenever the
|
||||
# the function is called, it pops up a new toplevel window containing a
|
||||
# text editor screen initialized to the argument. When the "OK" button
|
||||
# is pressed, whatever revised text is in the text editor is returned as
|
||||
# the result of the edit() function. This allows text fields of SQL tables
|
||||
# to be edited quickly and easily as follows:
|
||||
#
|
||||
# UPDATE table1 SET dscr = edit(dscr) WHERE rowid=15;
|
||||
#
|
||||
|
||||
|
||||
# Create a namespace to work in
|
||||
#
|
||||
namespace eval ::sqlitecon {
|
||||
# do nothing
|
||||
}
|
||||
|
||||
# Create a console widget named $w. The prompt string is $prompt.
|
||||
# The title at the top of the window is $title. The database connection
|
||||
# object is $db
|
||||
#
|
||||
proc sqlitecon::create {w prompt title db} {
|
||||
upvar #0 $w.t v
|
||||
if {[winfo exists $w]} {destroy $w}
|
||||
if {[info exists v]} {unset v}
|
||||
toplevel $w
|
||||
wm title $w $title
|
||||
wm iconname $w $title
|
||||
frame $w.mb -bd 2 -relief raised
|
||||
pack $w.mb -side top -fill x
|
||||
menubutton $w.mb.file -text File -menu $w.mb.file.m
|
||||
menubutton $w.mb.edit -text Edit -menu $w.mb.edit.m
|
||||
pack $w.mb.file $w.mb.edit -side left -padx 8 -pady 1
|
||||
set m [menu $w.mb.file.m -tearoff 0]
|
||||
$m add command -label {Close} -command "destroy $w"
|
||||
sqlitecon::create_child $w $prompt $w.mb.edit.m
|
||||
set v(db) $db
|
||||
$db function edit ::sqlitecon::_edit
|
||||
}
|
||||
|
||||
# This routine creates a console as a child window within a larger
|
||||
# window. It also creates an edit menu named "$editmenu" if $editmenu!="".
|
||||
# The calling function is responsible for posting the edit menu.
|
||||
#
|
||||
proc sqlitecon::create_child {w prompt editmenu} {
|
||||
upvar #0 $w.t v
|
||||
if {$editmenu!=""} {
|
||||
set m [menu $editmenu -tearoff 0]
|
||||
$m add command -label Cut -command "sqlitecon::Cut $w.t"
|
||||
$m add command -label Copy -command "sqlitecon::Copy $w.t"
|
||||
$m add command -label Paste -command "sqlitecon::Paste $w.t"
|
||||
$m add command -label {Clear Screen} -command "sqlitecon::Clear $w.t"
|
||||
$m add separator
|
||||
$m add command -label {Save As...} -command "sqlitecon::SaveFile $w.t"
|
||||
catch {$editmenu config -postcommand "sqlitecon::EnableEditMenu $w"}
|
||||
}
|
||||
scrollbar $w.sb -orient vertical -command "$w.t yview"
|
||||
pack $w.sb -side right -fill y
|
||||
text $w.t -font fixed -yscrollcommand "$w.sb set"
|
||||
pack $w.t -side right -fill both -expand 1
|
||||
bindtags $w.t Sqlitecon
|
||||
set v(editmenu) $editmenu
|
||||
set v(history) 0
|
||||
set v(historycnt) 0
|
||||
set v(current) -1
|
||||
set v(prompt) $prompt
|
||||
set v(prior) {}
|
||||
set v(plength) [string length $v(prompt)]
|
||||
set v(x) 0
|
||||
set v(y) 0
|
||||
set v(mode) column
|
||||
set v(header) on
|
||||
$w.t mark set insert end
|
||||
$w.t tag config ok -foreground blue
|
||||
$w.t tag config err -foreground red
|
||||
$w.t insert end $v(prompt)
|
||||
$w.t mark set out 1.0
|
||||
after idle "focus $w.t"
|
||||
}
|
||||
|
||||
bind Sqlitecon <1> {sqlitecon::Button1 %W %x %y}
|
||||
bind Sqlitecon <B1-Motion> {sqlitecon::B1Motion %W %x %y}
|
||||
bind Sqlitecon <B1-Leave> {sqlitecon::B1Leave %W %x %y}
|
||||
bind Sqlitecon <B1-Enter> {sqlitecon::cancelMotor %W}
|
||||
bind Sqlitecon <ButtonRelease-1> {sqlitecon::cancelMotor %W}
|
||||
bind Sqlitecon <KeyPress> {sqlitecon::Insert %W %A}
|
||||
bind Sqlitecon <Left> {sqlitecon::Left %W}
|
||||
bind Sqlitecon <Control-b> {sqlitecon::Left %W}
|
||||
bind Sqlitecon <Right> {sqlitecon::Right %W}
|
||||
bind Sqlitecon <Control-f> {sqlitecon::Right %W}
|
||||
bind Sqlitecon <BackSpace> {sqlitecon::Backspace %W}
|
||||
bind Sqlitecon <Control-h> {sqlitecon::Backspace %W}
|
||||
bind Sqlitecon <Delete> {sqlitecon::Delete %W}
|
||||
bind Sqlitecon <Control-d> {sqlitecon::Delete %W}
|
||||
bind Sqlitecon <Home> {sqlitecon::Home %W}
|
||||
bind Sqlitecon <Control-a> {sqlitecon::Home %W}
|
||||
bind Sqlitecon <End> {sqlitecon::End %W}
|
||||
bind Sqlitecon <Control-e> {sqlitecon::End %W}
|
||||
bind Sqlitecon <Return> {sqlitecon::Enter %W}
|
||||
bind Sqlitecon <KP_Enter> {sqlitecon::Enter %W}
|
||||
bind Sqlitecon <Up> {sqlitecon::Prior %W}
|
||||
bind Sqlitecon <Control-p> {sqlitecon::Prior %W}
|
||||
bind Sqlitecon <Down> {sqlitecon::Next %W}
|
||||
bind Sqlitecon <Control-n> {sqlitecon::Next %W}
|
||||
bind Sqlitecon <Control-k> {sqlitecon::EraseEOL %W}
|
||||
bind Sqlitecon <<Cut>> {sqlitecon::Cut %W}
|
||||
bind Sqlitecon <<Copy>> {sqlitecon::Copy %W}
|
||||
bind Sqlitecon <<Paste>> {sqlitecon::Paste %W}
|
||||
bind Sqlitecon <<Clear>> {sqlitecon::Clear %W}
|
||||
|
||||
# Insert a single character at the insertion cursor
|
||||
#
|
||||
proc sqlitecon::Insert {w a} {
|
||||
$w insert insert $a
|
||||
$w yview insert
|
||||
}
|
||||
|
||||
# Move the cursor one character to the left
|
||||
#
|
||||
proc sqlitecon::Left {w} {
|
||||
upvar #0 $w v
|
||||
scan [$w index insert] %d.%d row col
|
||||
if {$col>$v(plength)} {
|
||||
$w mark set insert "insert -1c"
|
||||
}
|
||||
}
|
||||
|
||||
# Erase the character to the left of the cursor
|
||||
#
|
||||
proc sqlitecon::Backspace {w} {
|
||||
upvar #0 $w v
|
||||
scan [$w index insert] %d.%d row col
|
||||
if {$col>$v(plength)} {
|
||||
$w delete {insert -1c}
|
||||
}
|
||||
}
|
||||
|
||||
# Erase to the end of the line
|
||||
#
|
||||
proc sqlitecon::EraseEOL {w} {
|
||||
upvar #0 $w v
|
||||
scan [$w index insert] %d.%d row col
|
||||
if {$col>=$v(plength)} {
|
||||
$w delete insert {insert lineend}
|
||||
}
|
||||
}
|
||||
|
||||
# Move the cursor one character to the right
|
||||
#
|
||||
proc sqlitecon::Right {w} {
|
||||
$w mark set insert "insert +1c"
|
||||
}
|
||||
|
||||
# Erase the character to the right of the cursor
|
||||
#
|
||||
proc sqlitecon::Delete w {
|
||||
$w delete insert
|
||||
}
|
||||
|
||||
# Move the cursor to the beginning of the current line
|
||||
#
|
||||
proc sqlitecon::Home w {
|
||||
upvar #0 $w v
|
||||
scan [$w index insert] %d.%d row col
|
||||
$w mark set insert $row.$v(plength)
|
||||
}
|
||||
|
||||
# Move the cursor to the end of the current line
|
||||
#
|
||||
proc sqlitecon::End w {
|
||||
$w mark set insert {insert lineend}
|
||||
}
|
||||
|
||||
# Add a line to the history
|
||||
#
|
||||
proc sqlitecon::addHistory {w line} {
|
||||
upvar #0 $w v
|
||||
if {$v(historycnt)>0} {
|
||||
set last [lindex $v(history) [expr $v(historycnt)-1]]
|
||||
if {[string compare $last $line]} {
|
||||
lappend v(history) $line
|
||||
incr v(historycnt)
|
||||
}
|
||||
} else {
|
||||
set v(history) [list $line]
|
||||
set v(historycnt) 1
|
||||
}
|
||||
set v(current) $v(historycnt)
|
||||
}
|
||||
|
||||
# Called when "Enter" is pressed. Do something with the line
|
||||
# of text that was entered.
|
||||
#
|
||||
proc sqlitecon::Enter w {
|
||||
upvar #0 $w v
|
||||
scan [$w index insert] %d.%d row col
|
||||
set start $row.$v(plength)
|
||||
set line [$w get $start "$start lineend"]
|
||||
$w insert end \n
|
||||
$w mark set out end
|
||||
if {$v(prior)==""} {
|
||||
set cmd $line
|
||||
} else {
|
||||
set cmd $v(prior)\n$line
|
||||
}
|
||||
if {[string index $cmd 0]=="." || [$v(db) complete $cmd]} {
|
||||
regsub -all {\n} [string trim $cmd] { } cmd2
|
||||
addHistory $w $cmd2
|
||||
set rc [catch {DoCommand $w $cmd} res]
|
||||
if {![winfo exists $w]} return
|
||||
if {$rc} {
|
||||
$w insert end $res\n err
|
||||
} elseif {[string length $res]>0} {
|
||||
$w insert end $res\n ok
|
||||
}
|
||||
set v(prior) {}
|
||||
$w insert end $v(prompt)
|
||||
} else {
|
||||
set v(prior) $cmd
|
||||
regsub -all {[^ ]} $v(prompt) . x
|
||||
$w insert end $x
|
||||
}
|
||||
$w mark set insert end
|
||||
$w mark set out {insert linestart}
|
||||
$w yview insert
|
||||
}
|
||||
|
||||
# Execute a single SQL command. Pay special attention to control
|
||||
# directives that begin with "."
|
||||
#
|
||||
# The return value is the text output from the command, properly
|
||||
# formatted.
|
||||
#
|
||||
proc sqlitecon::DoCommand {w cmd} {
|
||||
upvar #0 $w v
|
||||
set mode $v(mode)
|
||||
set header $v(header)
|
||||
if {[regexp {^(\.[a-z]+)} $cmd all word]} {
|
||||
if {$word==".mode"} {
|
||||
regexp {^.[a-z]+ +([a-z]+)} $cmd all v(mode)
|
||||
return {}
|
||||
} elseif {$word==".exit"} {
|
||||
destroy [winfo toplevel $w]
|
||||
return {}
|
||||
} elseif {$word==".header"} {
|
||||
regexp {^.[a-z]+ +([a-z]+)} $cmd all v(header)
|
||||
return {}
|
||||
} elseif {$word==".tables"} {
|
||||
set mode multicolumn
|
||||
set cmd {SELECT name FROM sqlite_master WHERE type='table'
|
||||
UNION ALL
|
||||
SELECT name FROM sqlite_temp_master WHERE type='table'}
|
||||
$v(db) eval {PRAGMA database_list} {
|
||||
if {$name!="temp" && $name!="main"} {
|
||||
append cmd "UNION ALL SELECT name FROM $name.sqlite_master\
|
||||
WHERE type='table'"
|
||||
}
|
||||
}
|
||||
append cmd { ORDER BY 1}
|
||||
} elseif {$word==".fullschema"} {
|
||||
set pattern %
|
||||
regexp {^.[a-z]+ +([^ ]+)} $cmd all pattern
|
||||
set mode list
|
||||
set header 0
|
||||
set cmd "SELECT sql FROM sqlite_master WHERE tbl_name LIKE '$pattern'
|
||||
AND sql NOT NULL UNION ALL SELECT sql FROM sqlite_temp_master
|
||||
WHERE tbl_name LIKE '$pattern' AND sql NOT NULL"
|
||||
$v(db) eval {PRAGMA database_list} {
|
||||
if {$name!="temp" && $name!="main"} {
|
||||
append cmd " UNION ALL SELECT sql FROM $name.sqlite_master\
|
||||
WHERE tbl_name LIKE '$pattern' AND sql NOT NULL"
|
||||
}
|
||||
}
|
||||
} elseif {$word==".schema"} {
|
||||
set pattern %
|
||||
regexp {^.[a-z]+ +([^ ]+)} $cmd all pattern
|
||||
set mode list
|
||||
set header 0
|
||||
set cmd "SELECT sql FROM sqlite_master WHERE name LIKE '$pattern'
|
||||
AND sql NOT NULL UNION ALL SELECT sql FROM sqlite_temp_master
|
||||
WHERE name LIKE '$pattern' AND sql NOT NULL"
|
||||
$v(db) eval {PRAGMA database_list} {
|
||||
if {$name!="temp" && $name!="main"} {
|
||||
append cmd " UNION ALL SELECT sql FROM $name.sqlite_master\
|
||||
WHERE name LIKE '$pattern' AND sql NOT NULL"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return \
|
||||
".exit\n.mode line|list|column\n.schema ?TABLENAME?\n.tables"
|
||||
}
|
||||
}
|
||||
set res {}
|
||||
if {$mode=="list"} {
|
||||
$v(db) eval $cmd x {
|
||||
set sep {}
|
||||
foreach col $x(*) {
|
||||
append res $sep$x($col)
|
||||
set sep |
|
||||
}
|
||||
append res \n
|
||||
}
|
||||
if {[info exists x(*)] && $header} {
|
||||
set sep {}
|
||||
set hdr {}
|
||||
foreach col $x(*) {
|
||||
append hdr $sep$col
|
||||
set sep |
|
||||
}
|
||||
set res $hdr\n$res
|
||||
}
|
||||
} elseif {[string range $mode 0 2]=="col"} {
|
||||
set y {}
|
||||
$v(db) eval $cmd x {
|
||||
foreach col $x(*) {
|
||||
if {![info exists cw($col)] || $cw($col)<[string length $x($col)]} {
|
||||
set cw($col) [string length $x($col)]
|
||||
}
|
||||
lappend y $x($col)
|
||||
}
|
||||
}
|
||||
if {[info exists x(*)] && $header} {
|
||||
set hdr {}
|
||||
set ln {}
|
||||
set dash ---------------------------------------------------------------
|
||||
append dash ------------------------------------------------------------
|
||||
foreach col $x(*) {
|
||||
if {![info exists cw($col)] || $cw($col)<[string length $col]} {
|
||||
set cw($col) [string length $col]
|
||||
}
|
||||
lappend hdr $col
|
||||
lappend ln [string range $dash 1 $cw($col)]
|
||||
}
|
||||
set y [concat $hdr $ln $y]
|
||||
}
|
||||
if {[info exists x(*)]} {
|
||||
set format {}
|
||||
set arglist {}
|
||||
set arglist2 {}
|
||||
set i 0
|
||||
foreach col $x(*) {
|
||||
lappend arglist x$i
|
||||
append arglist2 " \$x$i"
|
||||
incr i
|
||||
append format " %-$cw($col)s"
|
||||
}
|
||||
set format [string trimleft $format]\n
|
||||
if {[llength $arglist]>0} {
|
||||
foreach $arglist $y "append res \[format [list $format] $arglist2\]"
|
||||
}
|
||||
}
|
||||
} elseif {$mode=="multicolumn"} {
|
||||
set y [$v(db) eval $cmd]
|
||||
set max 0
|
||||
foreach e $y {
|
||||
if {$max<[string length $e]} {set max [string length $e]}
|
||||
}
|
||||
set ncol [expr {int(80/($max+2))}]
|
||||
if {$ncol<1} {set ncol 1}
|
||||
set nelem [llength $y]
|
||||
set nrow [expr {($nelem+$ncol-1)/$ncol}]
|
||||
set format "%-${max}s"
|
||||
for {set i 0} {$i<$nrow} {incr i} {
|
||||
set j $i
|
||||
while 1 {
|
||||
append res [format $format [lindex $y $j]]
|
||||
incr j $nrow
|
||||
if {$j>=$nelem} break
|
||||
append res { }
|
||||
}
|
||||
append res \n
|
||||
}
|
||||
} else {
|
||||
$v(db) eval $cmd x {
|
||||
foreach col $x(*) {append res "$col = $x($col)\n"}
|
||||
append res \n
|
||||
}
|
||||
}
|
||||
return [string trimright $res]
|
||||
}
|
||||
|
||||
# Change the line to the previous line
|
||||
#
|
||||
proc sqlitecon::Prior w {
|
||||
upvar #0 $w v
|
||||
if {$v(current)<=0} return
|
||||
incr v(current) -1
|
||||
set line [lindex $v(history) $v(current)]
|
||||
sqlitecon::SetLine $w $line
|
||||
}
|
||||
|
||||
# Change the line to the next line
|
||||
#
|
||||
proc sqlitecon::Next w {
|
||||
upvar #0 $w v
|
||||
if {$v(current)>=$v(historycnt)} return
|
||||
incr v(current) 1
|
||||
set line [lindex $v(history) $v(current)]
|
||||
sqlitecon::SetLine $w $line
|
||||
}
|
||||
|
||||
# Change the contents of the entry line
|
||||
#
|
||||
proc sqlitecon::SetLine {w line} {
|
||||
upvar #0 $w v
|
||||
scan [$w index insert] %d.%d row col
|
||||
set start $row.$v(plength)
|
||||
$w delete $start end
|
||||
$w insert end $line
|
||||
$w mark set insert end
|
||||
$w yview insert
|
||||
}
|
||||
|
||||
# Called when the mouse button is pressed at position $x,$y on
|
||||
# the console widget.
|
||||
#
|
||||
proc sqlitecon::Button1 {w x y} {
|
||||
global tkPriv
|
||||
upvar #0 $w v
|
||||
set v(mouseMoved) 0
|
||||
set v(pressX) $x
|
||||
set p [sqlitecon::nearestBoundry $w $x $y]
|
||||
scan [$w index insert] %d.%d ix iy
|
||||
scan $p %d.%d px py
|
||||
if {$px==$ix} {
|
||||
$w mark set insert $p
|
||||
}
|
||||
$w mark set anchor $p
|
||||
focus $w
|
||||
}
|
||||
|
||||
# Find the boundry between characters that is nearest
|
||||
# to $x,$y
|
||||
#
|
||||
proc sqlitecon::nearestBoundry {w x y} {
|
||||
set p [$w index @$x,$y]
|
||||
set bb [$w bbox $p]
|
||||
if {![string compare $bb ""]} {return $p}
|
||||
if {($x-[lindex $bb 0])<([lindex $bb 2]/2)} {return $p}
|
||||
$w index "$p + 1 char"
|
||||
}
|
||||
|
||||
# This routine extends the selection to the point specified by $x,$y
|
||||
#
|
||||
proc sqlitecon::SelectTo {w x y} {
|
||||
upvar #0 $w v
|
||||
set cur [sqlitecon::nearestBoundry $w $x $y]
|
||||
if {[catch {$w index anchor}]} {
|
||||
$w mark set anchor $cur
|
||||
}
|
||||
set anchor [$w index anchor]
|
||||
if {[$w compare $cur != $anchor] || (abs($v(pressX) - $x) >= 3)} {
|
||||
if {$v(mouseMoved)==0} {
|
||||
$w tag remove sel 0.0 end
|
||||
}
|
||||
set v(mouseMoved) 1
|
||||
}
|
||||
if {[$w compare $cur < anchor]} {
|
||||
set first $cur
|
||||
set last anchor
|
||||
} else {
|
||||
set first anchor
|
||||
set last $cur
|
||||
}
|
||||
if {$v(mouseMoved)} {
|
||||
$w tag remove sel 0.0 $first
|
||||
$w tag add sel $first $last
|
||||
$w tag remove sel $last end
|
||||
update idletasks
|
||||
}
|
||||
}
|
||||
|
||||
# Called whenever the mouse moves while button-1 is held down.
|
||||
#
|
||||
proc sqlitecon::B1Motion {w x y} {
|
||||
upvar #0 $w v
|
||||
set v(y) $y
|
||||
set v(x) $x
|
||||
sqlitecon::SelectTo $w $x $y
|
||||
}
|
||||
|
||||
# Called whenever the mouse leaves the boundries of the widget
|
||||
# while button 1 is held down.
|
||||
#
|
||||
proc sqlitecon::B1Leave {w x y} {
|
||||
upvar #0 $w v
|
||||
set v(y) $y
|
||||
set v(x) $x
|
||||
sqlitecon::motor $w
|
||||
}
|
||||
|
||||
# This routine is called to automatically scroll the window when
|
||||
# the mouse drags offscreen.
|
||||
#
|
||||
proc sqlitecon::motor w {
|
||||
upvar #0 $w v
|
||||
if {![winfo exists $w]} return
|
||||
if {$v(y)>=[winfo height $w]} {
|
||||
$w yview scroll 1 units
|
||||
} elseif {$v(y)<0} {
|
||||
$w yview scroll -1 units
|
||||
} else {
|
||||
return
|
||||
}
|
||||
sqlitecon::SelectTo $w $v(x) $v(y)
|
||||
set v(timer) [after 50 sqlitecon::motor $w]
|
||||
}
|
||||
|
||||
# This routine cancels the scrolling motor if it is active
|
||||
#
|
||||
proc sqlitecon::cancelMotor w {
|
||||
upvar #0 $w v
|
||||
catch {after cancel $v(timer)}
|
||||
catch {unset v(timer)}
|
||||
}
|
||||
|
||||
# Do a Copy operation on the stuff currently selected.
|
||||
#
|
||||
proc sqlitecon::Copy w {
|
||||
if {![catch {set text [$w get sel.first sel.last]}]} {
|
||||
clipboard clear -displayof $w
|
||||
clipboard append -displayof $w $text
|
||||
}
|
||||
}
|
||||
|
||||
# Return 1 if the selection exists and is contained
|
||||
# entirely on the input line. Return 2 if the selection
|
||||
# exists but is not entirely on the input line. Return 0
|
||||
# if the selection does not exist.
|
||||
#
|
||||
proc sqlitecon::canCut w {
|
||||
set r [catch {
|
||||
scan [$w index sel.first] %d.%d s1x s1y
|
||||
scan [$w index sel.last] %d.%d s2x s2y
|
||||
scan [$w index insert] %d.%d ix iy
|
||||
}]
|
||||
if {$r==1} {return 0}
|
||||
if {$s1x==$ix && $s2x==$ix} {return 1}
|
||||
return 2
|
||||
}
|
||||
|
||||
# Do a Cut operation if possible. Cuts are only allowed
|
||||
# if the current selection is entirely contained on the
|
||||
# current input line.
|
||||
#
|
||||
proc sqlitecon::Cut w {
|
||||
if {[sqlitecon::canCut $w]==1} {
|
||||
sqlitecon::Copy $w
|
||||
$w delete sel.first sel.last
|
||||
}
|
||||
}
|
||||
|
||||
# Do a paste opeation.
|
||||
#
|
||||
proc sqlitecon::Paste w {
|
||||
if {[sqlitecon::canCut $w]==1} {
|
||||
$w delete sel.first sel.last
|
||||
}
|
||||
if {[catch {selection get -displayof $w -selection CLIPBOARD} topaste]
|
||||
&& [catch {selection get -displayof $w -selection PRIMARY} topaste]} {
|
||||
return
|
||||
}
|
||||
if {[info exists ::$w]} {
|
||||
set prior 0
|
||||
foreach line [split $topaste \n] {
|
||||
if {$prior} {
|
||||
sqlitecon::Enter $w
|
||||
update
|
||||
}
|
||||
set prior 1
|
||||
$w insert insert $line
|
||||
}
|
||||
} else {
|
||||
$w insert insert $topaste
|
||||
}
|
||||
}
|
||||
|
||||
# Enable or disable entries in the Edit menu
|
||||
#
|
||||
proc sqlitecon::EnableEditMenu w {
|
||||
upvar #0 $w.t v
|
||||
set m $v(editmenu)
|
||||
if {$m=="" || ![winfo exists $m]} return
|
||||
switch [sqlitecon::canCut $w.t] {
|
||||
0 {
|
||||
$m entryconf Copy -state disabled
|
||||
$m entryconf Cut -state disabled
|
||||
}
|
||||
1 {
|
||||
$m entryconf Copy -state normal
|
||||
$m entryconf Cut -state normal
|
||||
}
|
||||
2 {
|
||||
$m entryconf Copy -state normal
|
||||
$m entryconf Cut -state disabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Prompt the user for the name of a writable file. Then write the
|
||||
# entire contents of the console screen to that file.
|
||||
#
|
||||
proc sqlitecon::SaveFile w {
|
||||
set types {
|
||||
{{Text Files} {.txt}}
|
||||
{{All Files} *}
|
||||
}
|
||||
set f [tk_getSaveFile -filetypes $types -title "Write Screen To..."]
|
||||
if {$f!=""} {
|
||||
if {[catch {open $f w} fd]} {
|
||||
tk_messageBox -type ok -icon error -message $fd
|
||||
} else {
|
||||
puts $fd [string trimright [$w get 1.0 end] \n]
|
||||
close $fd
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Erase everything from the console above the insertion line.
|
||||
#
|
||||
proc sqlitecon::Clear w {
|
||||
$w delete 1.0 {insert linestart}
|
||||
}
|
||||
|
||||
# An in-line editor for SQL
|
||||
#
|
||||
proc sqlitecon::_edit {origtxt {title {}}} {
|
||||
for {set i 0} {[winfo exists .ed$i]} {incr i} continue
|
||||
set w .ed$i
|
||||
toplevel $w
|
||||
wm protocol $w WM_DELETE_WINDOW "$w.b.can invoke"
|
||||
wm title $w {Inline SQL Editor}
|
||||
frame $w.b
|
||||
pack $w.b -side bottom -fill x
|
||||
button $w.b.can -text Cancel -width 6 -command [list set ::$w 0]
|
||||
button $w.b.ok -text OK -width 6 -command [list set ::$w 1]
|
||||
button $w.b.cut -text Cut -width 6 -command [list ::sqlitecon::Cut $w.t]
|
||||
button $w.b.copy -text Copy -width 6 -command [list ::sqlitecon::Copy $w.t]
|
||||
button $w.b.paste -text Paste -width 6 -command [list ::sqlitecon::Paste $w.t]
|
||||
set ::$w {}
|
||||
pack $w.b.cut $w.b.copy $w.b.paste $w.b.can $w.b.ok\
|
||||
-side left -padx 5 -pady 5 -expand 1
|
||||
if {$title!=""} {
|
||||
label $w.title -text $title
|
||||
pack $w.title -side top -padx 5 -pady 5
|
||||
}
|
||||
text $w.t -bg white -fg black -yscrollcommand [list $w.sb set]
|
||||
pack $w.t -side left -fill both -expand 1
|
||||
scrollbar $w.sb -orient vertical -command [list $w.t yview]
|
||||
pack $w.sb -side left -fill y
|
||||
$w.t insert end $origtxt
|
||||
|
||||
vwait ::$w
|
||||
|
||||
if {[set ::$w]} {
|
||||
set txt [string trimright [$w.t get 1.0 end]]
|
||||
} else {
|
||||
set txt $origtxt
|
||||
}
|
||||
destroy $w
|
||||
return $txt
|
||||
}
|
||||
@@ -1,264 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
|
||||
<TITLE></TITLE>
|
||||
<META NAME="GENERATOR" CONTENT="OpenOffice.org 1.0.2 (Linux)">
|
||||
<META NAME="CREATED" CONTENT="20040515;10253700">
|
||||
<META NAME="CHANGED" CONTENT="20040517;11521700">
|
||||
<STYLE>
|
||||
<!--
|
||||
@page { size: 21.59cm 27.94cm; margin-left: 3.18cm; margin-right: 3.18cm; margin-top: 2.54cm; margin-bottom: 2.54cm }
|
||||
H1 { margin-bottom: 0.21cm }
|
||||
H1.western { font-family: "Luxi Sans", sans-serif; font-size: 16pt }
|
||||
H1.cjk { font-size: 16pt }
|
||||
H1.ctl { font-size: 16pt }
|
||||
P { margin-bottom: 0.21cm }
|
||||
H2 { margin-bottom: 0.21cm }
|
||||
H2.western { font-family: "Luxi Sans", sans-serif; font-size: 14pt; font-style: normal }
|
||||
H2.cjk { font-size: 14pt; font-style: italic }
|
||||
H2.ctl { font-size: 14pt; font-style: italic }
|
||||
-->
|
||||
</STYLE>
|
||||
</HEAD>
|
||||
<BODY LANG="en-US">
|
||||
<H1 CLASS="western" ALIGN=CENTER>SQLite v3 Value Storage and
|
||||
Collation</H1>
|
||||
<P>This document is a collection of notes describing the proposed
|
||||
SQLite v3 type affinity and collation sequence features.</P>
|
||||
<H2 CLASS="western">1. Storage Classes</H2>
|
||||
<P>Version 2 of SQLite stores all column values as ASCII text.
|
||||
Version 3 enhances this by providing the ability to store integer and
|
||||
real numbers in a more compact format and the capability to store
|
||||
BLOB data.</P>
|
||||
<P>Each value stored in an SQLite database (or manipulated by the
|
||||
database engine) has one of the following storage classes:</P>
|
||||
<UL>
|
||||
<LI><P><B>NULL</B>. The value is a NULL value.</P>
|
||||
<LI><P><B>INTEGER</B>. The value is a signed integer, stored in 1,
|
||||
2, 4 or 8 bytes depending on the magnitude of the value.</P>
|
||||
<LI><P><B>REAL</B>. The value is a floating point value, stored as
|
||||
an 8-byte IEEE floating point number.</P>
|
||||
<LI><P><B>TEXT</B>. The value is a text string, stored using the
|
||||
database encoding (UTF-8, UTF-16BE or UTF-16-LE).</P>
|
||||
<LI><P><B>BLOB</B>. The value is a blob of data, stored exactly as
|
||||
it was input.</P>
|
||||
</UL>
|
||||
<P>As in SQLite v2, normally any SQLite v3 column except an INTEGER
|
||||
PRIMARY KEY may be used to store any type of value. The exception to
|
||||
this rule is described below under 'Strict Affinity Mode'.</P>
|
||||
<P>All values supplied to SQLite, whether as literals embedded in SQL
|
||||
statements, values bound to pre-compiled SQL statements or data read
|
||||
using the COPY command are assigned a storage class before the SQL
|
||||
statement is executed. Under circumstances described below, the
|
||||
database engine may convert values between numeric storage classes
|
||||
(INTEGER and REAL) and TEXT during query execution.
|
||||
</P>
|
||||
<P>Storage classes are initially assigned as follows:</P>
|
||||
<UL>
|
||||
<LI><P>Values read using the COPY command are assigned the storage
|
||||
class TEXT or NULL.</P>
|
||||
<LI><P>Values specified as literals as part of SQL statements are
|
||||
assigned storage class TEXT if they are enclosed by single or double
|
||||
quotes, INTEGER if the literal is specified as an unquoted number
|
||||
with no decimal point or exponent, REAL if the literal is an
|
||||
unquoted number with a decimal point or exponent and NULL if the
|
||||
value is a NULL.</P>
|
||||
<LI><P>Values supplied using the sqlite3_bind_* APIs are assigned
|
||||
the storage class that most closely matches the native type bound
|
||||
(i.e. sqlite3_bind_blob() binds a value with storage class BLOB).</P>
|
||||
</UL>
|
||||
<P>The storage class of a value that is the result of an SQL scalar
|
||||
operator depends on the outermost operator of the expression.
|
||||
User-defined functions may return values with any storage class. It
|
||||
is not generally possible to determine the storage class of the
|
||||
result of an expression at compile time.</P>
|
||||
<H2 CLASS="western">2. Column Affinity</H2>
|
||||
<P>Each column in an SQLite 3 database is assigned one of the
|
||||
following type affinities:</P>
|
||||
<UL>
|
||||
<LI><P>TEXT.</P>
|
||||
<LI><P>NUMERIC.</P>
|
||||
<LI><P>INTEGER.</P>
|
||||
<LI><P>NONE.</P>
|
||||
</UL>
|
||||
<P>The affinity of a column determines the storage class used by
|
||||
values inserted into the column.</P>
|
||||
<P>A column with TEXT affinity stores all data using storage classes
|
||||
NULL, TEXT or BLOB. If numerical data is inserted into a column with
|
||||
TEXT affinity it is converted to text form before being stored.</P>
|
||||
<P>A column with NUMERIC affinity may contain values using all five
|
||||
storage classes. When text data is inserted into a NUMERIC column, an
|
||||
attempt is made to convert it to an integer or real number before it
|
||||
is stored. If the conversion is successful, then the value is stored
|
||||
using the INTEGER or REAL storage class. If the conversion cannot be
|
||||
performed the value is stored using the TEXT storage class. No
|
||||
attempt is made to convert NULL or blob values.</P>
|
||||
<P>A column that uses INTEGER affinity behaves in the same way as a
|
||||
column with NUMERIC affinity, except that if a real value with no
|
||||
floating point component (or text value that converts to such) is
|
||||
inserted it is converted to an integer and stored using the INTEGER
|
||||
storage class.</P>
|
||||
<P>A column with affinity NONE makes no attempt to coerce data before
|
||||
it is inserted.</P>
|
||||
<H3>2.1 Determination Of Column Affinity</H3>
|
||||
<P>The type affinity of a column is determined by the declared type
|
||||
of the column, according to the following rules:</P>
|
||||
<OL>
|
||||
<LI><P>If the datatype of the column contains any of the strings
|
||||
"CHAR", "CLOB", or "TEXT" then that
|
||||
column has TEXT affinity. Notice that the type VARCHAR contains the
|
||||
string "CHAR" and is thus assigned TEXT affinity.</P>
|
||||
<LI><P>If the datatype contains the string "INT" then it
|
||||
is assigned INTEGER affinity.</P>
|
||||
<LI><P>If the datatype contains the string "BLOB" is is
|
||||
given an affinity of NONE.</P>
|
||||
<LI><P>Any column that does not matches the rules above, including
|
||||
columns that have no datatype specified, are given NUMERIC affinity.</P>
|
||||
</OL>
|
||||
<P>If a table is created using a “CREATE TABLE <table> AS
|
||||
SELECT...” statement, then all columns have no datatype specified
|
||||
and they are given no affinity.</P>
|
||||
<H3>2.2 Column Affinity Example</H3>
|
||||
<PRE>CREATE TABLE t1(
|
||||
t AFFINITY TEXT,
|
||||
nu AFFINITY NUMERIC,
|
||||
i AFFINITY INTEGER,
|
||||
no AFFINITY NONE
|
||||
);
|
||||
|
||||
-- Storage classes for the following row:
|
||||
-- TEXT, REAL, INTEGER, TEXT
|
||||
INSERT INTO t1 VALUES('500.0', '500.0', '500.0', '500.0');
|
||||
|
||||
-- Storage classes for the following row:
|
||||
-- TEXT, REAL, INTEGER, REAL
|
||||
INSERT INTO t1 VALUES(500.0, 500.0, 500.0, 500.0);</PRE><H2 CLASS="western">
|
||||
3. Comparison Expressions</H2>
|
||||
<P>Like SQLite v2, v3 features the binary comparison operators '=',
|
||||
'<', '<=', '>=' and '!=', an operation to test for set
|
||||
membership, 'IN', and the ternary comparison operator 'BETWEEN'.</P>
|
||||
<P>The results of a comparison depend on the storage classes of the
|
||||
two values being compared, according to the following rules:</P>
|
||||
<UL>
|
||||
<LI><P>A value with storage class NULL is considered less than any
|
||||
other value (including another value with storage class NULL).</P>
|
||||
<LI><P>An INTEGER or REAL value is less than any TEXT or BLOB value.
|
||||
When an INTEGER or REAL is compared to another INTEGER or REAL, a
|
||||
numerical comparison is performed.</P>
|
||||
<LI><P>A TEXT value is less than a BLOB value. When two TEXT values
|
||||
are compared, the C library function memcmp() is usually used to
|
||||
determine the result. However this can be overriden, as described
|
||||
under 'User-defined collation Sequences' below.</P>
|
||||
<LI><P>When two BLOB values are compared, the result is always
|
||||
determined using memcmp().</P>
|
||||
</UL>
|
||||
<P>SQLite may attempt to convert values between the numeric storage
|
||||
classes (INTEGER and REAL) and TEXT before performing a comparison.
|
||||
For binary comparisons, this is done in the cases enumerated below.
|
||||
The term “expression” used in the bullet points below means any
|
||||
SQL scalar expression or literal other than a column value.</P>
|
||||
<UL>
|
||||
<LI><P>When a column value is compared to the result of an
|
||||
expression, the affinity of the column is applied to the result of
|
||||
the expression before the comparison takes place.</P>
|
||||
<LI><P>When two column values are compared, if one column has
|
||||
INTEGER or NUMERIC affinity and the other does not, the NUMERIC
|
||||
affinity is applied to any values with storage class TEXT extracted
|
||||
from the non-NUMERIC column.</P>
|
||||
<LI><P>When the results of two expressions are compared, the NUMERIC
|
||||
affinity is applied to both values before the comparison takes
|
||||
place.</P>
|
||||
</UL>
|
||||
<H3>3.1 Comparison Example</H3>
|
||||
<PRE>CREATE TABLE t1(
|
||||
a AFFINITY TEXT,
|
||||
b AFFINITY NUMERIC,
|
||||
c AFFINITY NONE
|
||||
);
|
||||
|
||||
-- Storage classes for the following row:
|
||||
-- TEXT, REAL, TEXT
|
||||
INSERT INTO t1 VALUES('500', '500', '500');
|
||||
|
||||
-- 60 and 40 are converted to “60” and “40” and values are compared as TEXT.
|
||||
SELECT a < 60, a < 40 FROM t1;
|
||||
1|0
|
||||
|
||||
-- Comparisons are numeric. No conversions are required.
|
||||
SELECT b < 60, b < 600 FROM t1;
|
||||
0|1
|
||||
|
||||
-- Both 60 and 600 (storage class NUMERIC) are less than '500' (storage class TEXT).
|
||||
SELECT c < 60, c < 600 FROM t1;
|
||||
0|0</PRE><P>
|
||||
In SQLite, the expression “a BETWEEN b AND c” is currently
|
||||
equivalent to “a >= b AND a <= c”. SQLite will continue to
|
||||
treat the two as exactly equivalent, even if this means that
|
||||
different affinities are applied to 'a' in each of the comparisons
|
||||
required to evaluate the expression.</P>
|
||||
<P>Expressions of the type “a IN (SELECT b ....)” are handled by
|
||||
the three rules enumerated above for binary comparisons (e.g. in a
|
||||
similar manner to “a = b”). For example if 'b' is a column value
|
||||
and 'a' is an expression, then the affinity of 'b' is applied to 'a'
|
||||
before any comparisons take place.</P>
|
||||
<P>SQLite currently treats the expression “a IN (x, y, z)” as
|
||||
equivalent to “a = z OR a = y OR a = z”. SQLite will continue to
|
||||
treat the two as exactly equivalent, even if this means that
|
||||
different affinities are applied to 'a' in each of the comparisons
|
||||
required to evaluate the expression.</P>
|
||||
<H2 CLASS="western">4. Operators</H2>
|
||||
<P>All mathematical operators (which is to say, all operators other
|
||||
than the concatenation operator "||") apply NUMERIC
|
||||
affinity to all operands prior to being carried out. If one or both
|
||||
operands cannot be converted to NUMERIC then the result of the
|
||||
operation is NULL.</P>
|
||||
<P>For the concatenation operator, TEXT affinity is applied to both
|
||||
operands. If either operand cannot be converted to TEXT (because it
|
||||
is NULL or a BLOB) then the result of the concatenation is NULL.</P>
|
||||
<H2 CLASS="western">5. Sorting, Grouping and Compound SELECTs</H2>
|
||||
<P>When values are sorted by an ORDER by clause, values with storage
|
||||
class NULL come first, followed by INTEGER and REAL values
|
||||
interspersed in numeric order, followed by TEXT values usually in
|
||||
memcmp() order, and finally BLOB values in memcmp() order. No storage
|
||||
class conversions occur before the sort.</P>
|
||||
<P>When grouping values with the GROUP BY clause values with
|
||||
different storage classes are considered distinct, except for INTEGER
|
||||
and REAL values which are considered equal if they are numerically
|
||||
equal. No affinities are applied to any values as the result of a
|
||||
GROUP by clause.</P>
|
||||
<P STYLE="font-style: normal">The compound SELECT operators UNION,
|
||||
INTERSECT and EXCEPT perform implicit comparisons between values.
|
||||
Before these comparisons are performed an affinity may be applied to
|
||||
each value. The same affinity, if any, is applied to all values that
|
||||
may be returned in a single column of the compound SELECT result set.
|
||||
The affinity applied is the affinity of the column returned by the
|
||||
left most component SELECTs that has a column value (and not some
|
||||
other kind of expression) in that position. If for a given compound
|
||||
SELECT column none of the component SELECTs return a column value, no
|
||||
affinity is applied to the values from that column before they are
|
||||
compared.</P>
|
||||
<H2 CLASS="western">6. Other Affinity Modes</H2>
|
||||
<P>The above sections describe the operation of the database engine
|
||||
in 'normal' affinity mode. SQLite v3 will feature two other affinity
|
||||
modes, as follows:</P>
|
||||
<UL>
|
||||
<LI><P><B>Strict affinity</B> mode. In this mode if a conversion
|
||||
between storage classes is ever required, the database engine
|
||||
returns an error and the current statement is rolled back.</P>
|
||||
<LI><P><B>No affinity</B> mode. In this mode no conversions between
|
||||
storage classes are ever performed. Comparisons between values of
|
||||
different storage classes (except for INTEGER and REAL) are always
|
||||
false.</P>
|
||||
</UL>
|
||||
<H2 CLASS="western">7. User-defined Collation Sequences</H2>
|
||||
<P STYLE="font-style: normal">By default, when SQLite compares two
|
||||
text values, the result of the comparison is determined using
|
||||
memcmp(), regardless of the encoding of the string. SQLite v3
|
||||
provides the ability for users to supply arbitrary comparison
|
||||
functions, known as user-defined collation sequences, to be used
|
||||
instead of memcmp().</P>
|
||||
<P STYLE="font-style: normal"><BR><BR>
|
||||
</P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -54,26 +54,30 @@ TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
|
||||
|
||||
# Object files for the SQLite library.
|
||||
#
|
||||
LIBOBJ+= attach.o auth.o btree.o build.o date.o delete.o \
|
||||
LIBOBJ+= alter.o analyze.o attach.o auth.o btree.o build.o \
|
||||
callback.o complete.o date.o delete.o \
|
||||
expr.o func.o hash.o insert.o \
|
||||
main.o opcodes.o os_mac.o os_unix.o os_win.o \
|
||||
pager.o parse.o pragma.o printf.o random.o \
|
||||
main.o opcodes.o os_unix.o os_win.o \
|
||||
pager.o parse.o pragma.o prepare.o printf.o random.o \
|
||||
select.o table.o tclsqlite.o tokenize.o trigger.o \
|
||||
update.o util.o vacuum.o \
|
||||
vdbe.o vdbeapi.o vdbeaux.o vdbemem.o \
|
||||
vdbe.o vdbeapi.o vdbeaux.o vdbefifo.o vdbemem.o \
|
||||
where.o utf.o legacy.o
|
||||
|
||||
# All of the source code files.
|
||||
#
|
||||
SRC = \
|
||||
$(TOP)/src/alter.c \
|
||||
$(TOP)/src/analyze.c \
|
||||
$(TOP)/src/attach.c \
|
||||
$(TOP)/src/auth.c \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/btree.h \
|
||||
$(TOP)/src/build.c \
|
||||
$(TOP)/src/callback.c \
|
||||
$(TOP)/src/complete.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/delete.c \
|
||||
$(TOP)/src/encode.c \
|
||||
$(TOP)/src/expr.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/hash.c \
|
||||
@@ -81,13 +85,13 @@ SRC = \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os_mac.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pager.h \
|
||||
$(TOP)/src/parse.y \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/prepare.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/random.c \
|
||||
$(TOP)/src/select.c \
|
||||
@@ -106,6 +110,7 @@ SRC = \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/vdbeapi.c \
|
||||
$(TOP)/src/vdbeaux.c \
|
||||
$(TOP)/src/vdbefifo.c \
|
||||
$(TOP)/src/vdbemem.c \
|
||||
$(TOP)/src/vdbeInt.h \
|
||||
$(TOP)/src/where.c
|
||||
@@ -114,8 +119,8 @@ SRC = \
|
||||
#
|
||||
TESTSRC = \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/os_mac.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c \
|
||||
@@ -127,20 +132,20 @@ TESTSRC = \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/test5.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/md5.c
|
||||
$(TOP)/src/md5.c \
|
||||
$(TOP)/src/where.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
sqlite3.h \
|
||||
$(TOP)/src/btree.h \
|
||||
config.h \
|
||||
$(TOP)/src/hash.h \
|
||||
opcodes.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/os_common.h \
|
||||
$(TOP)/src/os_mac.h \
|
||||
$(TOP)/src/os_unix.h \
|
||||
$(TOP)/src/os_win.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
@@ -156,7 +161,7 @@ VDBEHDR = \
|
||||
# This is the default Makefile target. The objects listed here
|
||||
# are what get build when you type just "make" with no arguments.
|
||||
#
|
||||
all: sqlite3.h config.h libsqlite3.a sqlite3$(EXE)
|
||||
all: sqlite3.h libsqlite3.a sqlite3$(EXE)
|
||||
|
||||
# Generate the file "last_change" which contains the date of change
|
||||
# of the most recently modified source code file
|
||||
@@ -181,12 +186,12 @@ objects: $(LIBOBJ_ORIG)
|
||||
# files are automatically generated. This target takes care of
|
||||
# all that automatic generation.
|
||||
#
|
||||
target_source: $(SRC) $(VDBEHDR) opcodes.c
|
||||
target_source: $(SRC) $(VDBEHDR) opcodes.c keywordhash.h
|
||||
rm -rf tsrc
|
||||
mkdir tsrc
|
||||
cp $(SRC) $(VDBEHDR) tsrc
|
||||
rm tsrc/sqlite.h.in tsrc/parse.y
|
||||
cp parse.c opcodes.c tsrc
|
||||
cp parse.c opcodes.c keywordhash.h tsrc
|
||||
cp $(TOP)/sqlite3.def tsrc
|
||||
|
||||
# Rules to build the LEMON compiler generator
|
||||
@@ -197,6 +202,12 @@ lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
|
||||
# Rules to build individual files
|
||||
#
|
||||
alter.o: $(TOP)/src/alter.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/alter.c
|
||||
|
||||
analyze.o: $(TOP)/src/analyze.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/analyze.c
|
||||
|
||||
attach.o: $(TOP)/src/attach.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/attach.c
|
||||
|
||||
@@ -209,21 +220,11 @@ btree.o: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
|
||||
build.o: $(TOP)/src/build.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/build.c
|
||||
|
||||
# The config.h file will contain a single #define that tells us how
|
||||
# many bytes are in a pointer. This only works if a pointer is the
|
||||
# same size on the host as it is on the target. If you are cross-compiling
|
||||
# to a target with a different pointer size, you'll need to manually
|
||||
# configure the config.h file.
|
||||
#
|
||||
config.h:
|
||||
echo '#include <stdio.h>' >temp.c
|
||||
echo 'int main(){printf(' >>temp.c
|
||||
echo '"#define SQLITE_PTR_SZ %d",sizeof(char*));' >>temp.c
|
||||
echo 'exit(0);}' >>temp.c
|
||||
$(BCC) -o temp temp.c
|
||||
./temp >config.h
|
||||
echo >>config.h
|
||||
rm -f temp.c temp
|
||||
callback.o: $(TOP)/src/callback.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/callback.c
|
||||
|
||||
complete.o: $(TOP)/src/complete.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/complete.c
|
||||
|
||||
date.o: $(TOP)/src/date.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/date.c
|
||||
@@ -231,9 +232,6 @@ date.o: $(TOP)/src/date.c $(HDR)
|
||||
delete.o: $(TOP)/src/delete.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/delete.c
|
||||
|
||||
encode.o: $(TOP)/src/encode.c
|
||||
$(TCCX) -c $(TOP)/src/encode.c
|
||||
|
||||
expr.o: $(TOP)/src/expr.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/expr.c
|
||||
|
||||
@@ -258,21 +256,11 @@ pager.o: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
opcodes.o: opcodes.c
|
||||
$(TCCX) -c opcodes.c
|
||||
|
||||
opcodes.c: $(TOP)/src/vdbe.c
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.c
|
||||
echo 'char *sqlite3OpcodeNames[] = { "???", ' >>opcodes.c
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/^.*OP_/ "/' -e 's/:.*$$/", /' >>opcodes.c
|
||||
echo '};' >>opcodes.c
|
||||
opcodes.c: opcodes.h $(TOP)/mkopcodec.awk
|
||||
sort -n -b +2 opcodes.h | awk -f $(TOP)/mkopcodec.awk >opcodes.c
|
||||
|
||||
opcodes.h: $(TOP)/src/vdbe.h
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.h
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/://' | \
|
||||
awk '{printf "#define %-30s %3d\n", $$2, ++cnt}' >>opcodes.h
|
||||
|
||||
os_mac.o: $(TOP)/src/os_mac.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/os_mac.c
|
||||
opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk
|
||||
cat parse.h $(TOP)/src/vdbe.c | awk -f $(TOP)/mkopcodeh.awk >opcodes.h
|
||||
|
||||
os_unix.o: $(TOP)/src/os_unix.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/os_unix.c
|
||||
@@ -287,11 +275,14 @@ parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon parse.y
|
||||
./lemon $(OPTS) parse.y
|
||||
|
||||
pragma.o: $(TOP)/src/pragma.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
|
||||
|
||||
prepare.o: $(TOP)/src/prepare.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/prepare.c
|
||||
|
||||
printf.o: $(TOP)/src/printf.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
|
||||
@@ -303,7 +294,7 @@ select.o: $(TOP)/src/select.c $(HDR)
|
||||
|
||||
sqlite3.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||
-e s/--ENCODING--/$(ENCODING)/ \
|
||||
-e s/--VERSION-NUMBER--/`cat ${TOP}/VERSION | sed 's/[^0-9]/ /g' | awk '{printf "%d%03d%03d",$$1,$$2,$$3}'`/ \
|
||||
$(TOP)/src/sqlite.h.in >sqlite3.h
|
||||
|
||||
table.o: $(TOP)/src/table.c $(HDR)
|
||||
@@ -312,9 +303,13 @@ table.o: $(TOP)/src/table.c $(HDR)
|
||||
tclsqlite.o: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
tokenize.o: $(TOP)/src/tokenize.c $(HDR)
|
||||
tokenize.o: $(TOP)/src/tokenize.c keywordhash.h $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/tokenize.c
|
||||
|
||||
keywordhash.h: $(TOP)/tool/mkkeywordhash.c
|
||||
$(BCC) -o mkkeywordhash $(OPTS) $(TOP)/tool/mkkeywordhash.c
|
||||
./mkkeywordhash >keywordhash.h
|
||||
|
||||
trigger.o: $(TOP)/src/trigger.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/trigger.c
|
||||
|
||||
@@ -339,6 +334,9 @@ vdbeapi.o: $(TOP)/src/vdbeapi.c $(VDBEHDR)
|
||||
vdbeaux.o: $(TOP)/src/vdbeaux.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbeaux.c
|
||||
|
||||
vdbefifo.o: $(TOP)/src/vdbefifo.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbefifo.c
|
||||
|
||||
vdbemem.o: $(TOP)/src/vdbemem.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbemem.c
|
||||
|
||||
@@ -377,7 +375,7 @@ sqlite3_analyzer$(EXE): $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC) \
|
||||
-e 's,^,",' \
|
||||
-e 's,$$,\\n",' \
|
||||
$(TOP)/tool/spaceanal.tcl >spaceanal_tcl.h
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=2 -DSQLITE_TEST=1 -static -o \
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=2 -DSQLITE_TEST=1 -o \
|
||||
sqlite3_analyzer$(EXE) $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
@@ -386,8 +384,8 @@ sqlite3_analyzer$(EXE): $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC) \
|
||||
arch.html: $(TOP)/www/arch.tcl
|
||||
tclsh $(TOP)/www/arch.tcl >arch.html
|
||||
|
||||
arch.png: $(TOP)/www/arch.png
|
||||
cp $(TOP)/www/arch.png .
|
||||
autoinc.html: $(TOP)/www/autoinc.tcl
|
||||
tclsh $(TOP)/www/autoinc.tcl >autoinc.html
|
||||
|
||||
c_interface.html: $(TOP)/www/c_interface.tcl
|
||||
tclsh $(TOP)/www/c_interface.tcl >c_interface.html
|
||||
@@ -401,6 +399,9 @@ capi3ref.html: $(TOP)/www/capi3ref.tcl
|
||||
changes.html: $(TOP)/www/changes.tcl
|
||||
tclsh $(TOP)/www/changes.tcl >changes.html
|
||||
|
||||
compile.html: $(TOP)/www/compile.tcl
|
||||
tclsh $(TOP)/www/compile.tcl >compile.html
|
||||
|
||||
copyright.html: $(TOP)/www/copyright.tcl
|
||||
tclsh $(TOP)/www/copyright.tcl >copyright.html
|
||||
|
||||
@@ -422,6 +423,9 @@ datatypes.html: $(TOP)/www/datatypes.tcl
|
||||
datatype3.html: $(TOP)/www/datatype3.tcl
|
||||
tclsh $(TOP)/www/datatype3.tcl >datatype3.html
|
||||
|
||||
different.html: $(TOP)/www/different.tcl
|
||||
tclsh $(TOP)/www/different.tcl >different.html
|
||||
|
||||
docs.html: $(TOP)/www/docs.tcl
|
||||
tclsh $(TOP)/www/docs.tcl >docs.html
|
||||
|
||||
@@ -442,11 +446,20 @@ index.html: $(TOP)/www/index.tcl last_change
|
||||
tclsh $(TOP)/www/index.tcl >index.html
|
||||
|
||||
lang.html: $(TOP)/www/lang.tcl
|
||||
tclsh $(TOP)/www/lang.tcl >lang.html
|
||||
tclsh $(TOP)/www/lang.tcl doc >lang.html
|
||||
|
||||
pragma.html: $(TOP)/www/pragma.tcl
|
||||
tclsh $(TOP)/www/pragma.tcl >pragma.html
|
||||
|
||||
lockingv3.html: $(TOP)/www/lockingv3.tcl
|
||||
tclsh $(TOP)/www/lockingv3.tcl >lockingv3.html
|
||||
|
||||
mingw.html: $(TOP)/www/mingw.tcl
|
||||
tclsh $(TOP)/www/mingw.tcl >mingw.html
|
||||
|
||||
nulls.html: $(TOP)/www/nulls.tcl
|
||||
tclsh $(TOP)/www/nulls.tcl >nulls.html
|
||||
|
||||
oldnews.html: $(TOP)/www/oldnews.tcl
|
||||
tclsh $(TOP)/www/oldnews.tcl >oldnews.html
|
||||
|
||||
@@ -456,11 +469,11 @@ omitted.html: $(TOP)/www/omitted.tcl
|
||||
opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
|
||||
tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
|
||||
|
||||
mingw.html: $(TOP)/www/mingw.tcl
|
||||
tclsh $(TOP)/www/mingw.tcl >mingw.html
|
||||
optimizer.html: $(TOP)/www/optimizer.tcl
|
||||
tclsh $(TOP)/www/optimizer.tcl >optimizer.html
|
||||
|
||||
nulls.html: $(TOP)/www/nulls.tcl
|
||||
tclsh $(TOP)/www/nulls.tcl >nulls.html
|
||||
optoverview.html: $(TOP)/www/optoverview.tcl
|
||||
tclsh $(TOP)/www/optoverview.tcl >optoverview.html
|
||||
|
||||
quickstart.html: $(TOP)/www/quickstart.tcl
|
||||
tclsh $(TOP)/www/quickstart.tcl >quickstart.html
|
||||
@@ -468,9 +481,6 @@ quickstart.html: $(TOP)/www/quickstart.tcl
|
||||
speed.html: $(TOP)/www/speed.tcl
|
||||
tclsh $(TOP)/www/speed.tcl >speed.html
|
||||
|
||||
sqlite.gif: $(TOP)/art/SQLite.gif
|
||||
cp $(TOP)/art/SQLite.gif sqlite.gif
|
||||
|
||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
|
||||
|
||||
@@ -486,22 +496,27 @@ vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
version3.html: $(TOP)/www/version3.tcl
|
||||
tclsh $(TOP)/www/version3.tcl >version3.html
|
||||
|
||||
whentouse.html: $(TOP)/www/whentouse.tcl
|
||||
tclsh $(TOP)/www/whentouse.tcl >whentouse.html
|
||||
|
||||
|
||||
# Files to be published on the website.
|
||||
#
|
||||
DOC = \
|
||||
arch.html \
|
||||
arch.png \
|
||||
autoinc.html \
|
||||
c_interface.html \
|
||||
capi3.html \
|
||||
capi3ref.html \
|
||||
changes.html \
|
||||
compile.html \
|
||||
copyright.html \
|
||||
copyright-release.html \
|
||||
copyright-release.pdf \
|
||||
conflict.html \
|
||||
datatypes.html \
|
||||
datatype3.html \
|
||||
different.html \
|
||||
docs.html \
|
||||
download.html \
|
||||
faq.html \
|
||||
@@ -515,18 +530,22 @@ DOC = \
|
||||
oldnews.html \
|
||||
omitted.html \
|
||||
opcode.html \
|
||||
optimizer.html \
|
||||
optoverview.html \
|
||||
pragma.html \
|
||||
quickstart.html \
|
||||
speed.html \
|
||||
sqlite.gif \
|
||||
sqlite.html \
|
||||
support.html \
|
||||
tclsqlite.html \
|
||||
vdbe.html \
|
||||
version3.html
|
||||
version3.html \
|
||||
whentouse.html
|
||||
|
||||
doc: common.tcl $(DOC)
|
||||
mkdir -p doc
|
||||
mv $(DOC) doc
|
||||
cp $(TOP)/www/*.gif $(TOP)/art/*.gif doc
|
||||
|
||||
# Standard install and cleanup targets
|
||||
#
|
||||
@@ -536,8 +555,8 @@ install: sqlite3 libsqlite3.a sqlite3.h
|
||||
mv sqlite3.h /usr/include
|
||||
|
||||
clean:
|
||||
rm -f *.o sqlite3 libsqlite3.a sqlite3.h opcodes.*
|
||||
rm -f lemon lempar.c parse.* sqlite*.tar.gz
|
||||
rm -f *.o sqlite3 libsqlite3.a sqlite3.h opcodes.* crashtest
|
||||
rm -f lemon lempar.c parse.* sqlite*.tar.gz mkkeywordhash keywordhash.h
|
||||
rm -f $(PUBLISH)
|
||||
rm -f *.da *.bb *.bbg gmon.out
|
||||
rm -rf tsrc
|
||||
|
||||
@@ -1,254 +1,315 @@
|
||||
C Version\s3.0.6\s(beta)\s(CVS\s1934)
|
||||
D 2004-09-02T16:45:59
|
||||
F Makefile.in 65a7c43fcaf9a710d62f120b11b6e435eeb4a450
|
||||
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||
F VERSION d28cfc2e7714a747851e50cc1a5ee8ab0ded7a78
|
||||
C Version\s3.2.8\s(CVS\s2835)
|
||||
D 2005-12-19T17:27:00
|
||||
F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
|
||||
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
|
||||
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
|
||||
F VERSION 4cef1bf020a669a809eb9ae30b049af780c5b52b
|
||||
F aclocal.m4 7daea4c35e88de30d5a3f6f7a2ab99720e803bbd
|
||||
F art/2005osaward.gif 0d1851b2a7c1c9d0ccce545f3e14bca42d7fd248
|
||||
F art/SQLite.eps 9b43cc99cfd2be687d386faea6862ea68d6a72b2
|
||||
F art/SQLite.gif 1bbb94484963f1382e27e1c5e86dd0c1061eba2b
|
||||
F art/SQLiteLogo3.tiff b9e6bf022ae939bc986cddb8ab99583ca1b02cb3
|
||||
F config.guess 2103e94b15dc57112d7b9ee152c6fac5288895b4
|
||||
F config.sub 9bf686ec001ae7bc53f5b3563c90c62d4c6d48be
|
||||
F configure d3720624693e6b18264e7776f7250dd472659a10 x
|
||||
F configure.ac 82b4d26ae0234e87019b5783b67bd5b807eb5820
|
||||
F doc/affinity.html bdc7560fa3d2284af59d8fb52041cddbb14578f5
|
||||
F configure b36e5d4156002b857e4c741626a7ac8412c2885c x
|
||||
F configure.ac fe941d9e98fff7edecdaca36a730da76f397f378
|
||||
F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad
|
||||
F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
|
||||
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
|
||||
F main.mk 2eb2826d6bd82d54e768902e5e1929e550409273
|
||||
F mkdll.sh 468d4f41d3ea98221371df4825cfbffbaac4d7e4
|
||||
F mkso.sh 7b67da1d63070875ba948e749aee9ef50ce36e3d
|
||||
F publish.sh 72bde067dda3fc2d33e92f20253b924e3b97da30
|
||||
F main.mk 72176d7299c2fd6ca2850623195a6984f75380a6
|
||||
F mkdll.sh 5ec23622515d5bf8969404e80cfb5e220ddf0512
|
||||
F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d
|
||||
F mkopcodeh.awk c5ed62f101d408e64bcad0a8c036d85e99905480
|
||||
F mkso.sh 125868def279650a07d3f0f5e8476fecf99613fd
|
||||
F publish.sh ed0aba4ffdfadb36597d03ce8efdae96efc038cb
|
||||
F spec.template b2f6c4e488cbc3b993a57deba22cbc36203c4da3
|
||||
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
|
||||
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
|
||||
F sqlite3.def 84215604aa7b547d75e0f7b437966e7ad18fa8b2
|
||||
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||
F sqlite3.def c413e514217736884254739a105c8c942fdf0c2f
|
||||
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
|
||||
F src/attach.c 0bd4f11da6999665da30625665a4096ba7898de6
|
||||
F src/auth.c 60db23b98bb94c8b0178180faaf49dc116674217
|
||||
F src/btree.c 598e7eccfa93194851f570c0ea146f6efe098ac3
|
||||
F src/btree.h 94dfec0a1722d33359b23e7e310f2b64ffedf029
|
||||
F src/build.c 35275654d9c5ce6c1c0c78e391f85e6915a8a66b
|
||||
F src/date.c edff4aa851eeca8abbc737dc3933a2f0671156ce
|
||||
F src/delete.c cebfdde83e7bf68d8118e1c13e40c99787302fbf
|
||||
F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37
|
||||
F src/expr.c d618305952f75567514824cf9bdd5de74db5e00a
|
||||
F src/func.c 54a095713dd117e5482b25fa829e241d6938f1b6
|
||||
F src/hash.c a97721a55440b7bea31ffe471bb2f6b4123cddd5
|
||||
F src/alter.c 26d755f2143719dd3f5b8aaf6cbe3c7f95332528
|
||||
F src/analyze.c 21a4cd125bedd3cb15857595c45c2a49c0556d26
|
||||
F src/attach.c 4b21689700a72ae281fa85dbaff06b2a62bd49ee
|
||||
F src/auth.c 31e2304bef67f44d635655f44234387ea7d21454
|
||||
F src/btree.c 236126155d5607da945d33514218cbec762d887e
|
||||
F src/btree.h 1ed561263ca0e335bc3e81d761c9d5ff8c22f61e
|
||||
F src/build.c aa9591839c00731370c1ba53a9c0045f70d764c4
|
||||
F src/callback.c 9a1162c8f9dae9fad6d548339669aacb5f6cf76b
|
||||
F src/complete.c 4de937dfdd4c79a501772ab2035b26082f337a79
|
||||
F src/date.c 7444b0900a28da77e57e3337a636873cff0ae940
|
||||
F src/delete.c 29dac493f4d83b05f91233b116827c133bcdab72
|
||||
F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
|
||||
F src/expr.c bb2cf5d5b065eaa23d5ae2620f6de0568768147d
|
||||
F src/func.c f63d417248808ff2632a3b576536abffcc21d858
|
||||
F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f
|
||||
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
|
||||
F src/insert.c fc1ce65a0fe68f226143de9b43c3582164a92aff
|
||||
F src/legacy.c 2f3617c61bcdcd1d776154a9cfebf99facda8ad8
|
||||
F src/main.c 981bbcf4521762ab9f8ecbda1a4260ef94d7234f
|
||||
F src/insert.c 1f51566d7cf4b243a2792f5fda37343d6e9377fa
|
||||
F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
|
||||
F src/main.c 422014201f22aa17b96c76650163178a91a825af
|
||||
F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
|
||||
F src/os.h d1780e0db95cad01f213d48da22ab490eb4fd345
|
||||
F src/os_common.h cd7eb025fdab7dc91e0e97bf6310f1648205857f
|
||||
F src/os_mac.c 3d31e26be1411acfb7961033098631b4f3486fdf
|
||||
F src/os_mac.h 51d2445f47e182ed32d3bd6937f81070c6fd9bd4
|
||||
F src/os_test.c d3cb336448d28cb6238f8c0d7a44b0ff010601ea
|
||||
F src/os_test.h 6a26a4978492e4bbdbf385554958418ff02db162
|
||||
F src/os_unix.c a5625eed7ab071d1715df783f4684945ae538a22
|
||||
F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13
|
||||
F src/os_win.c 9e2887825b1a32f0ceb1b73b93ffe29a112cd86f
|
||||
F src/os_win.h babd4e912967c6b09088cfe38a45e8005a07ba44
|
||||
F src/pager.c ae06c85de0db43f61a7a3e5eacad3fd5615daf59
|
||||
F src/pager.h 67739fe649f33be55dba522ca8a9cc4e42d14f71
|
||||
F src/parse.y 581a2ce014b843506805b2470c02b7865ad034d5
|
||||
F src/pragma.c 7156618038546ed4d09d733ceea231aebee3f2f8
|
||||
F src/printf.c 17b28a1eedfe8129b05de981719306c18c3f1327
|
||||
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
|
||||
F src/select.c 14534579535579a082fda8bbc7d621d7d170f406
|
||||
F src/shell.c 4f1a2760ced81c829defb47b0a3b61ffec61b604
|
||||
F src/sqlite.h.in b89ced1acc705bc9c79a2a4e725ac0eb64bd0614
|
||||
F src/sqliteInt.h 71de4b0400b50579d5dfab70b59adbb7776e77d8
|
||||
F src/table.c 4521c278892f60e4d630788c0ea5cf4db1e75c49
|
||||
F src/tclsqlite.c b7dd8b3531b70188d03354db530de0f2ffcac697
|
||||
F src/test1.c 3670f318c473b5a81cae548d9cc42da3f6a6efee
|
||||
F src/test2.c f4c2f3928f1998fd8cb75a81e33a60e025ea85d4
|
||||
F src/test3.c 94d0a2a90bccd85802488cb42c69ec8afd2e4646
|
||||
F src/test4.c c38766914e924091516030b6a8b677d849c08bf0
|
||||
F src/test5.c b001fa7f1b9e2dc5c2331de62fc641b5ab2bd7a1
|
||||
F src/tokenize.c 32171c3d576c7ec6acd6cf15e55c00ac0b314769
|
||||
F src/trigger.c 40e10f4b219b55e56478bc17480ce77654300e8d
|
||||
F src/update.c bbe126c67529bd699016af2d72bc4ceb8fd41527
|
||||
F src/utf.c 328890099db492dda5620ee5f924e244c6e57ff7
|
||||
F src/util.c d5aaf211543fb6e285654fada50252c857ac78aa
|
||||
F src/vacuum.c 47bf6837d39f5849b8eda7d037d3e21a26f736bc
|
||||
F src/vdbe.c 45f659497b479f001c2f4e8251474aba3975b9f8
|
||||
F src/vdbe.h e081c72cd0f7c19d49b1927460aeefcf0fbc85ac
|
||||
F src/vdbeInt.h f8df57a9dc272967991f806e612628e0aa57e705
|
||||
F src/vdbeapi.c 854732720c2cfc6ff76b28eef6253ac84a5408bc
|
||||
F src/vdbeaux.c 77eaaf62b8b3acad4a2ef351e3c44ecffc67faf6
|
||||
F src/vdbemem.c ef9ac7d32acfe4bce5c5b408b1294c8d9e0cdb56
|
||||
F src/where.c a84eee276cd072158224da6b5f30733df2d56027
|
||||
F test/all.test 929bfa932b55e75c96fe2203f7650ba451c1862c
|
||||
F test/attach.test feb2ce54e78688df4c84553416d5aec3b2a0112e
|
||||
F test/attach2.test 32ca2c1a5a347a7404219a11f9f84739a63d2582
|
||||
F test/attach3.test 6d060986ff004ebb89e1876a331d96c6bb62269e
|
||||
F test/auth.test e74b015545f608c06d5b84d17acdf7146eb818af
|
||||
F test/bigfile.test 62722ac4b420dfbcdceb137b8634e2cf2865fe27
|
||||
F src/os.h c51f2747f7bd1840447e2c7d26db749604626814
|
||||
F src/os_common.h 1ff88c7e7e6bd3e5f85443106c91cc26a4f8600b
|
||||
F src/os_unix.c 407dd07818d13807c396acf3f7570af81cbb666c
|
||||
F src/os_win.c fbccc85e7011174068c27d54256746321a1f0059
|
||||
F src/pager.c b74ebe5aca00ad5f831e19ae17193fe7b83a7ddf
|
||||
F src/pager.h e7b41ce8e7b5f629d456708b7ad9a8c8ede37140
|
||||
F src/parse.y 5602d5cb894dda2932bf50b7e88782a4440ae3ae
|
||||
F src/pragma.c 126149668aa7086e86cfa3e32c8523513c19dd63
|
||||
F src/prepare.c fc098db25d2a121affb08686cf04833fd50452d4
|
||||
F src/printf.c bd421c1ad5e01013c89af63c60eab02852ccd15e
|
||||
F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
|
||||
F src/select.c 034c7f7447b8711f85bef578a437ea12ca7cac53
|
||||
F src/shell.c 3596c1e559b82663057940d19ba533ad421c7dd3
|
||||
F src/sqlite.h.in 461b2535550cf77aedfd44385da11ef7d63e57a2
|
||||
F src/sqliteInt.h 53daa72541b4336c5e89773cf39717ed695bd523
|
||||
F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
|
||||
F src/tclsqlite.c ac94682f9e601dd373912c46414a5a842db2089a
|
||||
F src/test1.c 0f1a66f65a54fba029f7e93b7500d49443dc959b
|
||||
F src/test2.c 4196848c845626e7df894470f27329e80bfe92aa
|
||||
F src/test3.c f4e6a16a602091696619a1171bda25c0e3df49f7
|
||||
F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
|
||||
F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5
|
||||
F src/tokenize.c e1faf5637f3f4f90933785a0ecf64595f3ac3530
|
||||
F src/trigger.c f51dec15921629591cb98bf2e350018e268b109a
|
||||
F src/update.c ac506fb7400158f826ec6c3a0dbe65e7ed3928d5
|
||||
F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c
|
||||
F src/util.c 55caaffbb2716f9928ab452d20f3e9cbbeab872d
|
||||
F src/vacuum.c 829d9e1a6d7c094b80e0899686670932eafd768c
|
||||
F src/vdbe.c 3f1adcf4535dd35e4244d19d332fb6b515491c0d
|
||||
F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
|
||||
F src/vdbeInt.h 7bedbb9553a10e86b53f75d99e197f3f00a732bf
|
||||
F src/vdbeapi.c 85bbe1d0243a89655433d60711b4bd71979b59cd
|
||||
F src/vdbeaux.c 2b728d82cf2095386a90051b66e7faf1a143f27d
|
||||
F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
|
||||
F src/vdbemem.c ff426ff6e72aa3f0300a56ec8c7f18099be96b43
|
||||
F src/where.c 3ed72ca029b3010a76e3a41b7b02ec1bdf849f00
|
||||
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
|
||||
F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
|
||||
F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
|
||||
F test/alter2.test 60ba0a7057dc71ad630a1cc7c487104346849d50
|
||||
F test/alter3.test d4eecd8dbd008d0e66f1c201fa6dc2edca853c38
|
||||
F test/altermalloc.test 6e1f404ec021eb2ba6582e3c77b0a35cf206b7af
|
||||
F test/analyze.test 2f55535aa335785db1a2f97d3f3831c16c09f8b0
|
||||
F test/attach.test f320e98bcca68d100cab7666a0c9a93ac5f236bd
|
||||
F test/attach2.test 3396c012a39ddf7ba6b528d80bd79554168aa115
|
||||
F test/attach3.test 63013383adc4380af69779f34f4af19bd49f7cbe
|
||||
F test/attachmalloc.test cdb26c42850f04698377ccec05f5fa89d987837c
|
||||
F test/auth.test 973ae7274eae32c4453fbbcbd0ec2b80c5b1eeb3
|
||||
F test/autoinc.test 395fbac8bc158d3599995c73bfb15c418a5429f0
|
||||
F test/autovacuum.test 9471d58a08b14dc0d2c15b87583c46d1744343d6
|
||||
F test/autovacuum_crash.test 05a63b8805b20cfba7ace82856ce4ccdda075a31
|
||||
F test/autovacuum_ioerr.test 9cf27275ca47b72e188a47c53b61b6d583a01d24
|
||||
F test/autovacuum_ioerr2.test 2f8a3fb31f833fd0ca86ad4ad98913c73e807572
|
||||
F test/between.test ca092fa28b665ca92172b182c6c360a92f7ca348
|
||||
F test/bigfile.test f768fb6078604cefb73dba0690f0115cc60e6305
|
||||
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
|
||||
F test/bind.test 7968edd61eb83b6e09165e4ba38e327dace6fb35
|
||||
F test/blob.test 8727a7b46b2073a369cfc9bcb6f54dd366b9d884
|
||||
F test/btree.test 97b563e1ab999bf8764b129e8c4b4be0a116a52a
|
||||
F test/btree2.test aa4a6d05b1ea90b1acaf83ba89039dd302a88635
|
||||
F test/bind.test 3169339a9fb7aaa8244d0ed8651fe6b6796d809c
|
||||
F test/bindxfer.test 856830e9e5552b9882c9d5c6647f90e25bdae4ac
|
||||
F test/blob.test 0b4ee6fef7a50685b88d921e2992606999510881
|
||||
F test/btree.test 8aa7424aeec844df990273fe36447e5d7e407261
|
||||
F test/btree2.test dbce930b549d5ac883a7d8905c976209ea241db3
|
||||
F test/btree4.test 3797b4305694c7af6828675b0f4b1424b8ca30e4
|
||||
F test/btree5.test 8e5ff32c02e685d36516c6499add9375fe1377f2
|
||||
F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027
|
||||
F test/btree7.test 429b96cfef5b51a7d512cfb4b5b3e453384af293
|
||||
F test/capi2.test 53e3f399074d5654f26d55b32ccaca7b5b619933
|
||||
F test/capi3.test 9258ca75fc98d89477015dcd70aa3d2757b142b8
|
||||
F test/capi3b.test 458044d8c250c129ddfd77c6265a6923bc008b5e
|
||||
F test/btree7.test a6d3b842db22af97dd14b989e90a2fd96066b72f
|
||||
F test/btree8.test fadc112bcbd6a0c622d34c813fc8a648eacf8804
|
||||
F test/busy.test 0271c854738e23ad76e10d4096a698e5af29d211
|
||||
F test/capi2.test f897209386fb21cfdc9267595e0c667ebaca9164
|
||||
F test/capi3.test fc8e573467049add3bfaf81f53827e8ff153cf8f
|
||||
F test/capi3b.test 5b6a66f9f295f79f443b5d3f33187fa5ef6cf336
|
||||
F test/cast.test 937af85faabdb189b6cd05879977f2469223be59
|
||||
F test/collate1.test f79736d2ebf5492167ee4d1f4ab4c09dda776b03
|
||||
F test/collate2.test c1a3b41f761b28853c5696037f92de928f93233b
|
||||
F test/collate3.test e60b428e07ec945492ba90ff1c895902ee3a8a50
|
||||
F test/collate4.test 4a7902b7560686af11d6cace717d876c6937b7ef
|
||||
F test/collate5.test 1dd5f0f508c46667f9d4606c7950c414b0bdc0d5
|
||||
F test/collate6.test 2a45768914f04c1447a69d1358bbede376552675
|
||||
F test/conflict.test c5b849b01cfbe0a4f63a90cba6f68e2fe3a75f87
|
||||
F test/corrupt.test 0080ddcece23e8ba47c44608c4fb73fd4d1d8ce2
|
||||
F test/crash.test a3f6d27f7cb7f7bd752461db1e14f7c781ecedc3
|
||||
F test/collate2.test 224a632ba04907c049804b08162efd234aa7871f
|
||||
F test/collate3.test 947a77f5b8227e037a7094d0e338a5504f155cc4
|
||||
F test/collate4.test daf498e294dcd596b961d425c3f2dda117e4717e
|
||||
F test/collate5.test 8fb4e7e0241839356bd8710f437c32efb47bfff8
|
||||
F test/collate6.test 6c9470d1606ee3e564675b229653e320c49ec638
|
||||
F test/conflict.test 774e10709f5e9a9a7352dc929b856929ec805e58
|
||||
F test/corrupt.test 18c7a995b1af76a8c8600b996257f2c7b7bff083
|
||||
F test/corrupt2.test 88342570828f2b8cbbd8369eff3891f5c0bdd5ba
|
||||
F test/crash.test 131259005bb5dbe776eba8de99408a493c69c06c
|
||||
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
|
||||
F test/date.test fd3db29bba089578b1b008e3511ea9e74840377a
|
||||
F test/delete.test ec0b455f2dcc0e189d96ee438438ba026c4e51d8
|
||||
F test/delete2.test 050a3a6e8ea0f83aed817d164b16af2a499fb452
|
||||
F test/enc.test 2f5463af488d50aef60c6110bec6b21b5efba961
|
||||
F test/enc2.test 7a60971a62748be6b607b4b4380eb4c5e151a6ec
|
||||
F test/enc3.test 2ae80b11adf5b2c171d2e17214dabd356b9672c1
|
||||
F test/expr.test 91358521f8ec41cd0fd1c5370c93104265f1fefc
|
||||
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
|
||||
F test/func.test 830d352574c7f5cd15149a9be58a6dcc2b995c05
|
||||
F test/date.test 30ca15e608a45d868fd419c901795382efe27020
|
||||
F test/default.test 252298e42a680146b1dd64f563b95bdf088d94fb
|
||||
F test/delete.test 33e1670049364fc3604217a6c2eda042a47115ab
|
||||
F test/delete2.test e382b6a97787197eb8b93dd4ccd37797c3725ea3
|
||||
F test/delete3.test 555e84a00a99230b7d049d477a324a631126a6ab
|
||||
F test/diskfull.test d828d72adfc9e2d1a194d25996718c1989152cf9
|
||||
F test/distinctagg.test 2b89d1c5220d966a30ba4b40430338669301188b
|
||||
F test/enc.test 7a03417a1051fe8bc6c7641cf4c8c3f7e0066d52
|
||||
F test/enc2.test 76c13b8c00beaf95b15c152e95dab51292eb1f0d
|
||||
F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837
|
||||
F test/expr.test 71b8cba7fe5c228147c93e530e098144565aaa46
|
||||
F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
|
||||
F test/func.test 431f8e07a30aadf2a2a0c8c32f918a497bc4331d
|
||||
F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda
|
||||
F test/in.test b92a2df9162e1cbd33c6449a29a05e6955b1741a
|
||||
F test/index.test 31ed90af028d1ec9a3a8a4f0d7021717ba05dd16
|
||||
F test/insert.test ebbab63db4ad69395a058514bccb3cdb0a029d48
|
||||
F test/insert2.test ea5d4f8dcbc68d8ad85eaa5f03d9812757610f90
|
||||
F test/interrupt.test 9142ce4448605127640eda5e283952f75f67ed91
|
||||
F test/intpkey.test c8efd06db62b8b27216558ef439cc867d113cfec
|
||||
F test/ioerr.test 7d087bfd1a1a53442940e000df936e0df0c5b886
|
||||
F test/join.test 9ef6aabaac9de51d5fc41e68d1f4355da05a84cd
|
||||
F test/join2.test c97e4c5aa65dea462145529e58212a709b4722b8
|
||||
F test/join3.test 67dc0d7c8dab3fff25796d0f3c3fd9c999aeded3
|
||||
F test/join4.test 8dec387d06b3a4685e1104048065cf5236b99b93
|
||||
F test/lastinsert.test 31382f88b9b0270333ac9e4a17f2c2f4732da718
|
||||
F test/laststmtchanges.test 417aa27eb2b5cdfafb46e390e2c9ddd0a20eba43
|
||||
F test/limit.test f7c06fccd76755e8d083b61c06bc31cf461b9c35
|
||||
F test/lock.test 7cb9395919a0986ee4dd08bd49d34df93c8fc4fe
|
||||
F test/lock2.test 2213590d442147d09fd2334c905a755586c1c398
|
||||
F test/main.test 1430a4b5bd3a6d5e0294966b742d80a551f87211
|
||||
F test/malloc.test 769b240d89a7ef3320d88919fdb6765f9395a51f
|
||||
F test/memdb.test b8a13fa79f006bd087bbcf135ce8eb62056a6027
|
||||
F test/memleak.test a7efa33c7adc2762add028a4cc70a6bb04fe573e
|
||||
F test/minmax.test c0f92d3f7b11656221735385f2c8b1878bbbdaf6
|
||||
F test/misc1.test 1a20ea722dff15155e93948dc4ac3e8d80fec386
|
||||
F test/misc2.test 703734f5817215ca54e364833b3bf5ff36fcc21e
|
||||
F test/misc3.test 57c373aed45acdf45f8f78ea914ef8855841e6b7
|
||||
F test/misc4.test 9f8ab4896dd627f5f9ba893a7b57c9f0a95dfd64
|
||||
F test/misuse.test 2a64ce711419f2fd12806ed95af930fd4e7bb8f3
|
||||
F test/in.test cead6165aebbe0d451bb2263a307173acfeb6240
|
||||
F test/index.test 51e01a0928b4b61228917ddd8c6c0e2466547f6f
|
||||
F test/index2.test 9ad98243fd7fe833795a9cc662f371f0eed4ff4f
|
||||
F test/index3.test f66718cd92ce1216819d47e6a156755e4b2c4ca1
|
||||
F test/insert.test b0a89e1568fe9890758f8f2b43b68e840e8f1a1a
|
||||
F test/insert2.test 792ad079f59c7e14cf9397712725224e2112c838
|
||||
F test/insert3.test c67f0240b1c17e71fa2ed8bb6de064928f549f95
|
||||
F test/interrupt.test 170f87c2819f0e56c76e0a754949ea103d05009c
|
||||
F test/intpkey.test af4fd826c4784ec5c93b444de07adea0254d0d30
|
||||
F test/ioerr.test c3f71a60be73404bc5ae344e171b505d9af49320
|
||||
F test/join.test db3802739fb695bdfa2e88805e3d64ec5ffbebd1
|
||||
F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324
|
||||
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
|
||||
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
|
||||
F test/join5.test 2646825693a6e066ea89b498176d4a68df45ab68
|
||||
F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19
|
||||
F test/lastinsert.test eaa89c6ee1f13062d87139fd32c1e56753d2fd89
|
||||
F test/laststmtchanges.test 19a6d0c11f7a31dc45465b495f7b845a62cbec17
|
||||
F test/like.test 145382e6a1f3d2edf266ca7d0236ab1b7c0ba66f
|
||||
F test/limit.test 39f084f4e5f11e0b984cb517b56867cbf88df156
|
||||
F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107
|
||||
F test/lock2.test d83ba79d3c4fffdb5b926c7d8ca7a36c34288a55
|
||||
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
|
||||
F test/main.test 249f139ef2f75710db1b49bb79e8b27767eacae1
|
||||
F test/malloc.test 666c77a878ce50f5c22b9211ed43e889cabb63a6
|
||||
F test/malloc2.test 655b972372d2754a3f6c6ed54d7cfd18fde9bd32
|
||||
F test/memdb.test 1860e060be810bf0775bc57408a5b7c4954bcaea
|
||||
F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
|
||||
F test/minmax.test cad887abca5504396718e2cd5729ca40758743e8
|
||||
F test/misc1.test c991617666991e11513e46cb646fd2e45ae68599
|
||||
F test/misc2.test 5c699af2fede2694736a9f45aea7e2f052686e15
|
||||
F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
|
||||
F test/misc4.test fbb81c1d520f34deea819a5d94d787d3d38dc35b
|
||||
F test/misc5.test 24bd03404039ec727028ac9cf7fd9066fd209ec9
|
||||
F test/misuse.test 1c7fee3c4c0cb4008717ecccf5c72281fac0008e
|
||||
F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
|
||||
F test/null.test 642428b6a5408cc5b954b49e1b6e5025e4458b2b
|
||||
F test/pager.test 059cc5c58d3b5a851343dff8c56cf7286425d03a
|
||||
F test/pager2.test 55469c7c1c1a54d6b32d7b3cc99001e90101a1ce
|
||||
F test/pager3.test 16f546293bb751b8151dc17df613fca938bbec8b
|
||||
F test/pagesize.test ada866e3d8bad7ec252d5131e2fd4d892b8fef8d
|
||||
F test/pragma.test 66a66b7f3b273b93325c9a5794acb418f52fdcbf
|
||||
F test/printf.test 5a30fb0d736148fca64cb1b7ed0390be7414e024
|
||||
F test/progress.test 76c722f090b1ccb575e7e4e203a71608c5763beb x
|
||||
F test/quick.test 212a9cd4c40c72c7c4780fef1c2fbe5d1cb34ce6
|
||||
F test/quote.test 6d75cf635d93ba2484dc9cb378d88cbae9dc2c62
|
||||
F test/rollback.test 4097328d44510277244ef4fa51b22b2f11d7ef4c
|
||||
F test/rowid.test b3d059f5c8d8874fa1c31030e0636f67405d20ea
|
||||
F test/select1.test 0e459a8066259445d707cc4f64ea00459441e29f
|
||||
F test/select2.test 91a2225926039b0d1687840735c284dbbf89f0bc
|
||||
F test/select3.test 9de435aa84fc406708cd8dc1b1d60e7f27cea685
|
||||
F test/select4.test 86e72fc3b07de4fe11439aa419e37db3c49467e2
|
||||
F test/select5.test 94db800bbeff2e426c0175e07f7a71d4617853b5
|
||||
F test/select6.test 7a4c572ada0c2f969cecacd76f1f5c1533a22bbb
|
||||
F test/select7.test c71c822a82c80bbd55558b4b69d35442dfe22ffd
|
||||
F test/sort.test 35e9d6bd6930969050606c8feb9c6745469720e3
|
||||
F test/subselect.test 50f98723f00e97b1839d36410ee63597ca82d775
|
||||
F test/table.test fd9a0f4992230e4ca89cd37ae3191a12750df1d0
|
||||
F test/tableapi.test b21ab097e87a5484bb61029e69e1a4e5c5e65ede
|
||||
F test/tclsqlite.test d84b91f5e8219bbaf7f960ce649806eb39cc703f
|
||||
F test/temptable.test 63a16e3ad19adf073cfbcdf7624c92ac5236522c
|
||||
F test/tester.tcl 1ff1170dd4203d87f572871080cdb64330dade99
|
||||
F test/null.test 012fe5455f4fc3102490b4bad373a674e5741fdd
|
||||
F test/pager.test 1579e8f07291ae8e24db62ffade5c101c3e76597
|
||||
F test/pager2.test 49c0f57c7da0b060f0486b85fdd074025caa694e
|
||||
F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
|
||||
F test/pagesize.test cbc6a312b6f6c0f02619b189985df2a14164b690
|
||||
F test/pragma.test 95ea907adf68459e1be6f310c9ae94d1d59c465b
|
||||
F test/printf.test 9e10c74e16bf889f8495ddb3d6f5f891e75ff1b7
|
||||
F test/progress.test 16496001da445e6534afb94562c286708316d82f x
|
||||
F test/quick.test a94d12658a2b590c1a5be580bef09bbb04c1266b
|
||||
F test/quote.test c1ca5e18800455f1c882baf5b0274755a3836549
|
||||
F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b
|
||||
F test/rollback.test 94cd981ee3a627d9f6466f69dcf1f7dbfe695d7a
|
||||
F test/rowid.test 040a3bef06f970c45f5fcd14b2355f7f4d62f0cf
|
||||
F test/safety.test 907b64fee719554a3622853812af3886fddbbb4f
|
||||
F test/schema.test 21cbe7dac652f6d7eb058f3dec369bdbf46bbde6
|
||||
F test/select1.test 480233d4f5a81d7d59a55e40d05084d97e57ecdf
|
||||
F test/select2.test f3c2678c3a9f3cf08ec4988a3845bda64be6d9e3
|
||||
F test/select3.test 576df1a5cc5e01dadae9176384e2d506315afdcf
|
||||
F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca
|
||||
F test/select5.test 07a90ab3c7e3f0a241a9cdea1d997b2c8a89ff0b
|
||||
F test/select6.test 21b72c56e7cbcefd063fdf9bc6c89342aedabccf
|
||||
F test/select7.test 1bf795b948c133a15a2a5e99d3270e652ec58ce6
|
||||
F test/sort.test 0c33a8ae1c238377ad197387c3872175f40d3843
|
||||
F test/subquery.test e6de53332c0301b3cfa34edc3f3cd5fa1e859efd
|
||||
F test/subselect.test 2d13fb7f450db3595adcdd24079a0dd1d2d6abc2
|
||||
F test/sync.test d769caaec48456119316775e35e0fdee2fa852d7
|
||||
F test/table.test ec0e6c2186bb8f6824f470caa118524dfd8fe057
|
||||
F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1
|
||||
F test/tclsqlite.test 2da3e4b3a79b13c1511c9d0cd995e08f8362e782
|
||||
F test/temptable.test 7927261befdbc7b0a7ffebb85ecc70a74fa7b15b
|
||||
F test/tester.tcl 1e75553d320f5d2720613d8483c934488fc2c56f
|
||||
F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
|
||||
F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
|
||||
F test/threadtest2.c 97a830d53c24c42290501fdfba4a6e5bdd34748b
|
||||
F test/trace.test 0ed72787440d97c6de6b6ecb4c022e6f78d5d94a
|
||||
F test/trans.test 29645b344d2b9b6792793562b12340177ddd8f96
|
||||
F test/trigger1.test dc015c410161f1a6109fd52638dfac852e2a34de
|
||||
F test/trigger2.test a5d06e6e8e1e773cfcb5aaa75ab381b2ff35de63
|
||||
F test/trigger3.test 70931be83fa3f563f7a5ca9e88b86f476af73948
|
||||
F test/trigger4.test 97c11d3cf43d752b172809bb82536372ee5e399c
|
||||
F test/trigger5.test 25ba4d352282cd05753496a50f0bd23162cc97b9
|
||||
F test/types.test 1f5f0670cf07e44c0a5b03a31e31ec5ed39a482e
|
||||
F test/types2.test f23c147a2ab3e51d5dbcfa9987200db5acba7aa7
|
||||
F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b
|
||||
F test/update.test b29bd9061a1150426dab6959806fcc73a41b1217
|
||||
F test/utf16.test 459c2f5ab80c60092c603630a348c32d6e59c558
|
||||
F test/vacuum.test 6bce0f84fff255b943abed3b345c9e0ce287e2b6
|
||||
F test/tkt1435.test f768e5415d102fa1d8de3f548469d8fd1b79abd8
|
||||
F test/tkt1443.test 1e83b6a1e7f6e261682e67106ab3bc05f6c70e90
|
||||
F test/tkt1444.test 0f0fc1f277691f904dea2abece6db919dcae2351
|
||||
F test/tkt1449.test f8de8a84ec12ee805ed80055e1209560f8bee4d8
|
||||
F test/trace.test 9fd28695c463b90c2d32c387a432e01eb26e8ccf
|
||||
F test/trans.test 10506dc30305cfb8c4098359f7f6f64786f69c5e
|
||||
F test/trigger1.test 152aed5a1fa90709fe171f2ca501a6b7f7901479
|
||||
F test/trigger2.test dea71f4b05e22896e72527278bc8ef71b7475bf2
|
||||
F test/trigger3.test 9102fd3933db294dc654b5aee9edfe9e94f2b9e2
|
||||
F test/trigger4.test 9615207f3746b1f3965113007869e45a895d2497
|
||||
F test/trigger5.test 619391a3e9fc194081d22cefd830d811e7badf83
|
||||
F test/trigger6.test 0e411654f122552da6590f0b4e6f781048a4a9b9
|
||||
F test/trigger7.test 0afa870be2ce1b132cdb85b17a4a4ef45aa8cece
|
||||
F test/types.test f0a98d10c5ecc9865d19dc94486f9873afc6bb6b
|
||||
F test/types2.test 81dd1897be8ef4b5b73d0006e6076abe40610de3
|
||||
F test/types3.test 5c63c9cdbafe8fcb73a70a0beb0ecb65b7fa061d
|
||||
F test/unique.test 0253c4227a5dc533e312202ce21ecfad18058d18
|
||||
F test/update.test 7669ca789d62c258b678e8aa7a22a57eac10f2cf
|
||||
F test/utf16.test 5fb019e09601774743858ef7380b6c02103ff120
|
||||
F test/vacuum.test 5d4857ae2afc9c20d0edb8acc58bdc8d630126a9
|
||||
F test/vacuum2.test 5d77e98c458bcdbeecc6327de5107179ba1aa095
|
||||
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
|
||||
F test/view.test ca5c296989d3045f121be9a67588ff88c64874a8
|
||||
F test/where.test 40dcffcb77ad0a00960cef2b5b1212c77fd02199
|
||||
F test/view.test ce0f0ad39fa4a3572acffcf1e634850ee151aae0
|
||||
F test/where.test ce21f4910ef6a0c08f8172857baecefca20a3b0c
|
||||
F test/where2.test 503e2e2b6abe14c5c10222e72d08ef84c1bf1ffb
|
||||
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
|
||||
F tool/lemon.c ece41a3cd100e68fef5f136267cf02c44366c263
|
||||
F tool/lempar.c 0b5e7a58634e0d448929b8e85f7981c2aa708d57
|
||||
F tool/memleak.awk b744b6109566206c746d826f6ecdba34662216bc
|
||||
F tool/lemon.c c88936c67f6411608db8fa4254d254f509fa40f6
|
||||
F tool/lempar.c f0c30abcae762a7d1eb37cd88b2232ab8dd625fb
|
||||
F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133
|
||||
F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
|
||||
F tool/memleak3.tcl 336eb50b0849dbf99b1d5462d9c37291b01b2b43
|
||||
F tool/memleak3.tcl 009da0ea82dc5893edca76cf1a21fb7260e9412e
|
||||
F tool/mkkeywordhash.c 5263a654e5c9fd8d6e3238fb39c2d5c3126be32f
|
||||
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
|
||||
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
|
||||
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
|
||||
F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
|
||||
F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
|
||||
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
|
||||
F tool/spaceanal.tcl c8c39c466fbbc01dab10fc6c4a816db3c8168ab3
|
||||
F tool/spaceanal.tcl 5b47b70b9a0d216ec63a5b5547b3642dd308e53a
|
||||
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
|
||||
F www/arch.gif f845a64772062e82d17980a349f95f1f0b4c8054
|
||||
F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4
|
||||
F www/arch.tcl b833057e89aeb43335c0bf84a3d5b7f9d11df6fa
|
||||
F www/arch.tcl 03a6c66b1b34209d2897352e058377b421f0b80e
|
||||
F www/arch2.fig ae2432145c26cfa148fa0116589517ad3cd5fc65
|
||||
F www/arch2.gif 49c6bb36160f03ca2b89eaa5bfb1f560c7d68ee7
|
||||
F www/arch2.gif 6f2d47c4e0c5842c0d6b5513fd8249393d7c7003
|
||||
F www/arch2b.fig d22a2c9642d584b89d4088b1e51e2bb0f7c04bed
|
||||
F www/audit.tcl 90e09d580f79c7efec0c7d6f447b7ec5c2dce5c0
|
||||
F www/c_interface.tcl 83b39203e1ded4c2dab97f42edf31279a308efcb
|
||||
F www/capi3.tcl 5c1cb163f4d2a54e2d0e22dcc399dd71245c8b89
|
||||
F www/capi3ref.tcl bead38516efb0227ffa6ac76beb3f7ea405bb389
|
||||
F www/changes.tcl 3641bc28b86b40c82d546727da45ea0f0aa9a9f4
|
||||
F www/common.tcl f786e6be86fb2627ceb30e770e9efa83b9c67a3a
|
||||
F www/conflict.tcl fb8a2ba83746c7fdfd9e52fa7f6aaf5c422b8246
|
||||
F www/autoinc.tcl b357f5ba954b046ee35392ce0f884a2fcfcdea06
|
||||
F www/c_interface.tcl b51b08591554c16a0c3ef718364a508ac25abc7e
|
||||
F www/capi3.tcl 7a7cc225fe02eb7ab861a6019b08baa0014409e1
|
||||
F www/capi3ref.tcl 885f2aa112e2e9b8822753bf2972d5afd0cfeba9
|
||||
F www/changes.tcl 5f09e69c5498cf388b3158978664db090708ed83
|
||||
F www/common.tcl de758130d54d95d151ea0d17a2ae5b92e1bb01de
|
||||
F www/compile.tcl 276546d7eb445add5a867193bbd80f6919a6b084
|
||||
F www/conflict.tcl cdd0f4b59b0ba6d61f67e6a38f3ae45853bacb30
|
||||
F www/copyright-release.html 294e011760c439c44951a6bfecd4c81a1ae359e8
|
||||
F www/copyright-release.pdf cfca3558fc97095e57c6117d08f1f5b80d95125a
|
||||
F www/copyright.tcl 82c9670c7ddb0311912ab7fe24703f33c531066c
|
||||
F www/datatype3.tcl 2bb7dbfa4dd518a6e5fb3cb1cd8296797976d205
|
||||
F www/datatypes.tcl 566004b81c36877397ddbe6e1907aae6065f6b41
|
||||
F www/docs.tcl 095b5718ec044156af477061566ea25632624b56
|
||||
F www/download.tcl 958931d67680a2ff7044d5ed77ced1825a2a8c63
|
||||
F www/datatype3.tcl 0197a60590da421fc6516dabfa725c3d53ef90d1
|
||||
F www/datatypes.tcl 7c786d2e8ff434346764534ec015966d17efce60
|
||||
F www/different.tcl 81377eb0c8e27d3bdf812bde357281c4c44bec0c
|
||||
F www/direct1b.gif 32b48b764244817b6b591898dc52a04299a7b8a7
|
||||
F www/docs.tcl 4e2d716f004cc4c4dae773206ed58f50d4468a87
|
||||
F www/download.tcl d56a1c30b1c3c18f62926a806179976eb133ce94
|
||||
F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
|
||||
F www/faq.tcl 3a1776818d9bd973ab0c3048ec7ad6b1ad091ae5
|
||||
F www/fileformat.tcl f71a06a0d533c7df408539c64113b4adeaf29764
|
||||
F www/formatchng.tcl d1dfecedfb25e122ab513a1e0948b15cb4f0be46
|
||||
F www/index.tcl 7d0caef2a084b3f6e4881bee2485b1cc1458d9f6
|
||||
F www/lang.tcl b2ba401104a76e7842469b33a968f5eda9bd462b
|
||||
F www/lockingv3.tcl afcd22f0f063989cff2f4d57bbc38d719b4c6e75
|
||||
F www/faq.tcl eb7fb7b7242ccfec65820f01b94d0d83956236c1
|
||||
F www/fileformat.tcl 900c95b9633abc3dcfc384d9ddd8eb4876793059
|
||||
F www/formatchng.tcl 053ddb73646701353a5b1c9ca6274d5900739b45
|
||||
F www/fullscanb.gif f7c94cb227f060511f8909e10f570157263e9a25
|
||||
F www/index-ex1-x-b.gif f9b1d85c3fa2435cf38b15970c7e3aa1edae23a3
|
||||
F www/index.tcl 2fff45565fd52fba6746b27eb60ea1d7834042ec
|
||||
F www/indirect1b1.gif adfca361d2df59e34f9c5cac52a670c2bfc303a1
|
||||
F www/lang.tcl b04a87ce05cdbd8d356d6b760a9a0b6f6fce927e
|
||||
F www/lockingv3.tcl f59b19d6c8920a931f096699d6faaf61c05db55f
|
||||
F www/mingw.tcl d96b451568c5d28545fefe0c80bee3431c73f69c
|
||||
F www/nulls.tcl ede975a29def48838c606d4a0c0185d44f90a789
|
||||
F www/oldnews.tcl fbbdbb64ed602b0c92b03498578f7ac70f47753d
|
||||
F www/omitted.tcl 7bd62b6f0f53b60c5360895b16b3af8407bbca03
|
||||
F www/opcode.tcl e8c421fd2c70c503b25cedb3f9617a1f387ac7ea
|
||||
F www/quickstart.tcl 4e97bef825e6a4153c43afb9f97235fc4da278ab
|
||||
F www/speed.tcl 19cf0c1bf73c4b534dfafc95b3eacff4825740b4
|
||||
F www/nulls.tcl ec35193f92485b87b90a994a01d0171b58823fcf
|
||||
F www/oldnews.tcl 1a808d86882621557774bf7741ed81c7f4ef9f19
|
||||
F www/omitted.tcl 658ebdc83781ac419dc8a08b3f6cf93929023470
|
||||
F www/opcode.tcl 5bd68059416b223515a680d410a9f7cb6736485f
|
||||
F www/optimizer.tcl d6812a10269bd0d7c488987aac0ad5036cace9dc
|
||||
F www/optimizing.tcl f0b2538988d1bbad16cbfe63ec6e8f48c9eb04e5
|
||||
F www/optoverview.tcl 28b6f114a33bfd91bbe3440611ceed6090587211
|
||||
F www/pragma.tcl 44f7b665ca598ad24724f35991653638a36a6e3f
|
||||
F www/quickstart.tcl 6f6f694b6139be2d967b1492eb9a6bdf7058aa60
|
||||
F www/speed.tcl 656ed5be8cc9d536353e1a96927b925634a62933
|
||||
F www/sqlite.tcl b51fd15f0531a54874de785a9efba323eecd5975
|
||||
F www/support.tcl 96c8324cea27b5ded53ff5c60c127ba2053f688e
|
||||
F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25
|
||||
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
|
||||
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
||||
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
|
||||
P 67370926e374180b2de6e9ab60e5c9ddab4b1317
|
||||
R 11a68bf4bf2e4d26d945a2cfc6fe7c62
|
||||
F www/support.tcl 3955da0fd82be68cc5c83d347c05095e80967051
|
||||
F www/table-ex1b2.gif a588d21a2d88bb2a2ef0431fcc5ed5aa48c0bbc5
|
||||
F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
|
||||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
|
||||
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
|
||||
P d8e74af5b081a074173c470e9f2115be9b095777
|
||||
R 3ef1bc3892118ec529a39c9be34b97bf
|
||||
U drh
|
||||
Z d1756bd08569789e6c48078c47ef61ea
|
||||
Z ad60d4c3881558341fdd282b95f7c97a
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
c190b95c30981d2a6026e501e21af675ff8a2d13
|
||||
e61382aed45a83ad688a0461948f9cd052a527fa
|
||||
@@ -21,7 +21,9 @@ for i in *.c; do
|
||||
done
|
||||
echo 'EXPORTS' >tclsqlite3.def
|
||||
echo 'Tclsqlite3_Init' >>tclsqlite3.def
|
||||
echo 'Tclsqlite_Init' >>tclsqlite3.def
|
||||
echo 'Sqlite3_Init' >>tclsqlite3.def
|
||||
echo 'Sqlite_Init' >>tclsqlite3.def
|
||||
i386-mingw32msvc-dllwrap \
|
||||
--def tclsqlite3.def -v --export-all \
|
||||
--driver-name i386-mingw32msvc-gcc \
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/awk -f
|
||||
#
|
||||
# This AWK script scans the opcodes.h file (which is itself generated by
|
||||
# another awk script) and uses the information gleaned to create the
|
||||
# opcodes.c source file.
|
||||
#
|
||||
# Opcodes.c contains strings which are the symbolic names for the various
|
||||
# opcodes used by the VDBE. These strings are used when disassembling a
|
||||
# VDBE program during tracing or as a result of the EXPLAIN keyword.
|
||||
#
|
||||
BEGIN {
|
||||
print "/* Automatically generated. Do not edit */"
|
||||
print "/* See the mkopcodec.awk script for details. */"
|
||||
printf "#if !defined(SQLITE_OMIT_EXPLAIN)"
|
||||
printf " || !defined(NDEBUG)"
|
||||
printf " || defined(VDBE_PROFILE)"
|
||||
print " || defined(SQLITE_DEBUG)"
|
||||
print "const char *const sqlite3OpcodeNames[] = { \"?\","
|
||||
}
|
||||
/define OP_/ {
|
||||
sub("OP_","",$2)
|
||||
i++
|
||||
printf " /* %3d */ \"%s\",\n", $3, $2
|
||||
}
|
||||
END {
|
||||
print "};"
|
||||
print "#endif"
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/awk -f
|
||||
#
|
||||
# Generate the file opcodes.h.
|
||||
#
|
||||
# This AWK script scans a concatenation of the parse.h output file from the
|
||||
# parser and the vdbe.c source file in order to generate the opcodes numbers
|
||||
# for all opcodes.
|
||||
#
|
||||
# The lines of the vdbe.c that we are interested in are of the form:
|
||||
#
|
||||
# case OP_aaaa: /* same as TK_bbbbb */
|
||||
#
|
||||
# The TK_ comment is optional. If it is present, then the value assigned to
|
||||
# the OP_ is the same as the TK_ value. If missing, the OP_ value is assigned
|
||||
# a small integer that is different from every other OP_ value.
|
||||
#
|
||||
# We go to the trouble of making some OP_ value the same as TK_ values
|
||||
# as an optimization. During parsing, things like expression operators
|
||||
# are coded with TK_ values such as TK_ADD, TK_DIVIDE, and so forth. Later
|
||||
# during code generation, we need to generate corresponding opcodes like
|
||||
# OP_Add and OP_Divide. By making TK_ADD==OP_Add and TK_DIVIDE==OP_Divide,
|
||||
# code to translation from one to the other is avoided. This makes the
|
||||
# code generator run (infinitesimally) faster and more importantly it makes
|
||||
# the total library smaller.
|
||||
#
|
||||
|
||||
|
||||
# Remember the TK_ values from the parse.h file
|
||||
/^#define TK_/ {
|
||||
tk[$2] = $3
|
||||
}
|
||||
|
||||
# Scan for "case OP_aaaa:" lines in the vdbe.c file
|
||||
/^case OP_/ {
|
||||
name = $2
|
||||
sub(/:/,"",name)
|
||||
sub("\r","",name)
|
||||
op[name] = -1
|
||||
for(i=3; i<NF; i++){
|
||||
if($i=="same" && $(i+1)=="as"){
|
||||
sym = $(i+2)
|
||||
sub(/,/,"",sym)
|
||||
op[name] = tk[sym]
|
||||
used[op[name]] = 1
|
||||
sameas[op[name]] = sym
|
||||
}
|
||||
if($i=="no-push"){
|
||||
nopush[name] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Assign numbers to all opcodes and output the result.
|
||||
END {
|
||||
cnt = 0
|
||||
max = 0
|
||||
print "/* Automatically generated. Do not edit */"
|
||||
print "/* See the mkopcodeh.awk script for details */"
|
||||
for(name in op){
|
||||
if( op[name]<0 ){
|
||||
cnt++
|
||||
while( used[cnt] ) cnt++
|
||||
op[name] = cnt
|
||||
}
|
||||
used[op[name]] = 1;
|
||||
if( op[name]>max ) max = op[name]
|
||||
printf "#define %-25s %15d", name, op[name]
|
||||
if( sameas[op[name]] ) {
|
||||
printf " /* same as %-12s*/", sameas[op[name]]
|
||||
}
|
||||
printf "\n"
|
||||
|
||||
}
|
||||
seenUnused = 0;
|
||||
for(i=1; i<max; i++){
|
||||
if( !used[i] ){
|
||||
if( !seenUnused ){
|
||||
printf "\n/* The following opcode values are never used */\n"
|
||||
seenUnused = 1
|
||||
}
|
||||
printf "#define %-25s %15d\n", sprintf( "OP_NotUsed_%-3d", i ), i
|
||||
}
|
||||
}
|
||||
|
||||
# Generate the 10 16-bit bitmasks used by function opcodeUsesStack()
|
||||
# in vdbeaux.c. See comments in that function for details.
|
||||
#
|
||||
nopush[0] = 0 # 0..15
|
||||
nopush[1] = 0 # 16..31
|
||||
nopush[2] = 0 # 32..47
|
||||
nopush[3] = 0 # 48..63
|
||||
nopush[4] = 0 # 64..79
|
||||
nopush[5] = 0 # 80..95
|
||||
nopush[6] = 0 # 96..111
|
||||
nopush[7] = 0 # 112..127
|
||||
nopush[8] = 0 # 128..143
|
||||
nopush[9] = 0 # 144..159
|
||||
for(name in op){
|
||||
if( nopush[name] ){
|
||||
n = op[name]
|
||||
j = n%16
|
||||
i = ((n - j)/16)
|
||||
nopush[i] = nopush[i] + (2^j)
|
||||
}
|
||||
}
|
||||
printf "\n"
|
||||
for(i=0; i<10; i++){
|
||||
printf "#define NOPUSH_MASK_%d %d\n", i, nopush[i]
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,11 @@ TCLDIR=/home/drh/tcltk/846/linux/846linux
|
||||
TCLSTUBLIB=$TCLDIR/libtclstub8.4g.a
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1'
|
||||
for i in *.c; do
|
||||
CMD="cc -fPIC $OPTS -O2 -I. -I$TCLDIR -c $i"
|
||||
echo $CMD
|
||||
$CMD
|
||||
if test $i != 'keywordhash.c'; then
|
||||
CMD="cc -fPIC $OPTS -O2 -I. -I$TCLDIR -c $i"
|
||||
echo $CMD
|
||||
$CMD
|
||||
fi
|
||||
done
|
||||
echo gcc -shared *.o $TCLSTUBLIB -o tclsqlite3.so
|
||||
gcc -shared *.o $TCLSTUBLIB -o tclsqlite3.so
|
||||
|
||||
+4
-2
@@ -75,8 +75,10 @@ cd ..
|
||||
ORIGIN=`pwd`
|
||||
cd $srcdir
|
||||
cd ..
|
||||
EXCLUDE=`find sqlite -print | grep CVS | sed 's,^, --exclude ,'`
|
||||
tar czf $ORIGIN/doc/sqlite-$VERS.tar.gz $EXCLUDE sqlite
|
||||
mv sqlite sqlite-$VERS
|
||||
EXCLUDE=`find sqlite-$VERS -print | grep CVS | sed 's,^, --exclude ,'`
|
||||
tar czf $ORIGIN/doc/sqlite-$VERS.tar.gz $EXCLUDE sqlite-$VERS
|
||||
mv sqlite-$VERS sqlite
|
||||
cd $ORIGIN
|
||||
|
||||
#
|
||||
|
||||
@@ -1,203 +0,0 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.\" First parameter, NAME, should be all caps
|
||||
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
|
||||
.\" other parameters are allowed: see man(7), man(1)
|
||||
.TH SQLITE 1 "Mon Apr 15 23:49:17 2002"
|
||||
.\" Please adjust this date whenever revising the manpage.
|
||||
.\"
|
||||
.\" Some roff macros, for reference:
|
||||
.\" .nh disable hyphenation
|
||||
.\" .hy enable hyphenation
|
||||
.\" .ad l left justify
|
||||
.\" .ad b justify to both left and right margins
|
||||
.\" .nf disable filling
|
||||
.\" .fi enable filling
|
||||
.\" .br insert line break
|
||||
.\" .sp <n> insert n+1 empty lines
|
||||
.\" for manpage-specific macros, see man(7)
|
||||
.SH NAME
|
||||
sqlite \- A command line interface for SQLite
|
||||
.SH SYNOPSIS
|
||||
.B sqlite
|
||||
.RI [ options ] " filename " [ SQL ]
|
||||
.SS SUMMARY
|
||||
.PP
|
||||
sqlite is a terminal-based front-end to the SQLite library. It enables
|
||||
you to type in queries interactively, issue them to SQLite and see the
|
||||
results. Alternatively, you can specify SQL code on the command-line. In
|
||||
addition it provides a number of meta-commands.
|
||||
|
||||
.SH DESCRIPTION
|
||||
This manual page documents briefly the
|
||||
.B sqlite
|
||||
command.
|
||||
This manual page was written for the Debian GNU/Linux distribution
|
||||
because the original program does not have a manual page.
|
||||
.SS GETTING STARTED
|
||||
.PP
|
||||
To start the sqlite program, just type "sqlite" followed by the name
|
||||
the file that holds the SQLite database. If the file does not exist, a
|
||||
new one is created automatically. The sqlite program will then prompt
|
||||
you to enter SQL. Type in SQL statements (terminated by a semicolon),
|
||||
press "Enter" and the SQL will be executed.
|
||||
|
||||
For example, to create a new SQLite database named "ex1" with a single
|
||||
table named "tbl1", you might do this:
|
||||
.sp
|
||||
.nf
|
||||
$ sqlite ex1
|
||||
SQLite version 2.0.0
|
||||
Enter ".help" for instructions
|
||||
sqlite> create table tbl1(one varchar(10), two smallint);
|
||||
sqlite> insert into tbl1 values('hello!',10);
|
||||
sqlite> insert into tbl1 values('goodbye', 20);
|
||||
sqlite> select * from tbl1;
|
||||
hello!|10
|
||||
goodbye|20
|
||||
sqlite>
|
||||
.sp
|
||||
.fi
|
||||
|
||||
.SS SQLITE META-COMMANDS
|
||||
.PP
|
||||
Most of the time, sqlite just reads lines of input and passes them on
|
||||
to the SQLite library for execution. But if an input line begins with
|
||||
a dot ("."), then that line is intercepted and interpreted by the
|
||||
sqlite program itself. These "dot commands" are typically used to
|
||||
change the output format of queries, or to execute certain prepackaged
|
||||
query statements.
|
||||
|
||||
For a listing of the available dot commands, you can enter ".help" at
|
||||
any time. For example:
|
||||
.sp
|
||||
.nf
|
||||
.cc |
|
||||
sqlite> .help
|
||||
.dump ?TABLE? ... Dump the database in an text format
|
||||
.echo ON|OFF Turn command echo on or off
|
||||
.exit Exit this program
|
||||
.explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
|
||||
"off" will revert to the output mode that was
|
||||
previously in effect
|
||||
.header(s) ON|OFF Turn display of headers on or off
|
||||
.help Show this message
|
||||
.indices TABLE Show names of all indices on TABLE
|
||||
.mode MODE Set mode to one of "line(s)", "column(s)",
|
||||
"insert", "list", or "html"
|
||||
.mode insert TABLE Generate SQL insert statements for TABLE
|
||||
.nullvalue STRING Print STRING instead of nothing for NULL data
|
||||
.output FILENAME Send output to FILENAME
|
||||
.output stdout Send output to the screen
|
||||
.prompt MAIN CONTINUE Replace the standard prompts
|
||||
"sqlite > " and " ...> "
|
||||
with the strings MAIN and CONTINUE
|
||||
CONTINUE is optional.
|
||||
.quit Exit this program
|
||||
.read FILENAME Execute SQL in FILENAME
|
||||
.reindex ?TABLE? Rebuild indices
|
||||
.schema ?TABLE? Show the CREATE statements
|
||||
.separator STRING Change separator string for "list" mode
|
||||
.show Show the current values for the following:
|
||||
.echo
|
||||
.explain
|
||||
.mode
|
||||
.nullvalue
|
||||
.output
|
||||
.separator
|
||||
.width
|
||||
.tables ?PATTERN? List names of tables matching a pattern
|
||||
.timeout MS Try opening locked tables for MS milliseconds
|
||||
.width NUM NUM ... Set column widths for "column" mode
|
||||
sqlite>
|
||||
|cc .
|
||||
.sp
|
||||
.fi
|
||||
|
||||
.SH OPTIONS
|
||||
The program has the following options:
|
||||
.TP
|
||||
.BI \-init\ file
|
||||
Read in and process 'file', which contains "dot commands".
|
||||
You can use this file to initialize display settings.
|
||||
.TP
|
||||
.B \-html
|
||||
Set output mode to HTML.
|
||||
.TP
|
||||
.B \-list
|
||||
Set output mode to 'list'.
|
||||
.TP
|
||||
.B \-line
|
||||
Set output mode to 'line'.
|
||||
.TP
|
||||
.B \-column
|
||||
Set output mode to 'column'.
|
||||
.TP
|
||||
.BI \-separator\ separator
|
||||
Specify which output field separator for 'list' mode to use.
|
||||
Default is '|'.
|
||||
.TP
|
||||
.BI \-nullvalue\ string
|
||||
When a null is encountered, print 'string'. Default is no string.
|
||||
.TP
|
||||
.B \-[no]header
|
||||
Turn headers on or off. Default is off.
|
||||
.TP
|
||||
.B \-echo
|
||||
Print commands before execution.
|
||||
|
||||
|
||||
.SH OUTPUT MODE
|
||||
The SQLite program has different output modes, which define the way
|
||||
the output (from queries) is formatted.
|
||||
|
||||
In 'list' mode, which is the default, one record per line is output,
|
||||
each field separated by the separator specified with the
|
||||
\fB-separator\fP option or \fB.separator\fP command.
|
||||
|
||||
In 'line' mode, each column is output on its own line, records are
|
||||
separated by blank lines.
|
||||
|
||||
In HTML mode, an XHTML table is generated.
|
||||
|
||||
In 'column' mode, one record per line is output, aligned neatly in colums.
|
||||
|
||||
.SH INIT FILE
|
||||
sqlite can be initialized using resource files. These can be combined with
|
||||
command line arguments to set up sqlite exactly the way you want it.
|
||||
Initialization proceeds as follows:
|
||||
|
||||
o The defaults of
|
||||
|
||||
.sp
|
||||
.nf
|
||||
.cc |
|
||||
mode = LIST
|
||||
separator = "|"
|
||||
main prompt = "sqlite> "
|
||||
continue prompt = " ...> "
|
||||
|cc .
|
||||
.sp
|
||||
.fi
|
||||
|
||||
are established.
|
||||
|
||||
o If a file .sqliterc can be found in the user's home directory, it is
|
||||
read and processed. It should only contain "dot commands". If the
|
||||
file is not found or cannot be read, processing continues without
|
||||
notification.
|
||||
|
||||
o If a file is specified on the command line with the -init option, it
|
||||
is processed in the same manner as .sqliterc
|
||||
|
||||
o All other command line options are processed
|
||||
|
||||
o The database is opened and you are now ready to begin.
|
||||
|
||||
.SH SEE ALSO
|
||||
http://www.hwaci.com/sw/sqlite/
|
||||
.br
|
||||
The sqlite-doc package
|
||||
.SH AUTHOR
|
||||
This manual page was originally written by Andreas Rottmann
|
||||
<rotty@debian.org>, for the Debian GNU/Linux system (but may be used
|
||||
by others).
|
||||
@@ -0,0 +1,229 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.\" First parameter, NAME, should be all caps
|
||||
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
|
||||
.\" other parameters are allowed: see man(7), man(1)
|
||||
.TH SQLITE3 1 "Mon Apr 15 23:49:17 2002"
|
||||
.\" Please adjust this date whenever revising the manpage.
|
||||
.\"
|
||||
.\" Some roff macros, for reference:
|
||||
.\" .nh disable hyphenation
|
||||
.\" .hy enable hyphenation
|
||||
.\" .ad l left justify
|
||||
.\" .ad b justify to both left and right margins
|
||||
.\" .nf disable filling
|
||||
.\" .fi enable filling
|
||||
.\" .br insert line break
|
||||
.\" .sp <n> insert n+1 empty lines
|
||||
.\" for manpage-specific macros, see man(7)
|
||||
.SH NAME
|
||||
.B sqlite3
|
||||
\- A command line interface for SQLite version 3
|
||||
|
||||
.SH SYNOPSIS
|
||||
.B sqlite3
|
||||
.RI [ options ]
|
||||
.RI [ databasefile ]
|
||||
.RI [ SQL ]
|
||||
|
||||
.SH SUMMARY
|
||||
.PP
|
||||
.B sqlite3
|
||||
is a terminal-based front-end to the SQLite library that can evaluate
|
||||
queries interactively and display the results in multiple formats.
|
||||
.B sqlite3
|
||||
can also be used within shell scripts and other applications to provide
|
||||
batch processing features.
|
||||
|
||||
.SH DESCRIPTION
|
||||
To start a
|
||||
.B sqlite3
|
||||
interactive session, invoke the
|
||||
.B sqlite3
|
||||
command and optionally provide the name of a database file. If the
|
||||
database file does not exist, it will be created. If the database file
|
||||
does exist, it will be opened.
|
||||
|
||||
For example, to create a new database file named "mydata.db", create
|
||||
a table named "memos" and insert a couple of records into that table:
|
||||
.sp
|
||||
$
|
||||
.B sqlite3 mydata.db
|
||||
.br
|
||||
SQLite version 3.1.3
|
||||
.br
|
||||
Enter ".help" for instructions
|
||||
.br
|
||||
sqlite>
|
||||
.B create table memos(text, priority INTEGER);
|
||||
.br
|
||||
sqlite>
|
||||
.B insert into memos values('deliver project description', 10);
|
||||
.br
|
||||
sqlite>
|
||||
.B insert into memos values('lunch with Christine', 100);
|
||||
.br
|
||||
sqlite>
|
||||
.B select * from memos;
|
||||
.br
|
||||
deliver project description|10
|
||||
.br
|
||||
lunch with Christine|100
|
||||
.br
|
||||
sqlite>
|
||||
.sp
|
||||
|
||||
If no database name is supplied, the ATTACH sql command can be used
|
||||
to attach to existing or create new database files. ATTACH can also
|
||||
be used to attach to multiple databases within the same interactive
|
||||
session. This is useful for migrating data between databases,
|
||||
possibly changing the schema along the way.
|
||||
|
||||
Optionally, a SQL statement or set of SQL statements can be supplied as
|
||||
a single argument. Multiple statements should be separated by
|
||||
semi-colons.
|
||||
|
||||
For example:
|
||||
.sp
|
||||
$
|
||||
.B sqlite3 -line mydata.db 'select * from memos where priority > 20;'
|
||||
.br
|
||||
text = lunch with Christine
|
||||
.br
|
||||
priority = 100
|
||||
.br
|
||||
.sp
|
||||
|
||||
.SS SQLITE META-COMMANDS
|
||||
.PP
|
||||
The interactive interpreter offers a set of meta-commands that can be
|
||||
used to control the output format, examine the currently attached
|
||||
database files, or perform administrative operations upon the
|
||||
attached databases (such as rebuilding indices). Meta-commands are
|
||||
always prefixed with a dot (.).
|
||||
|
||||
A list of available meta-commands can be viewed at any time by issuing
|
||||
the '.help' command. For example:
|
||||
.sp
|
||||
sqlite>
|
||||
.B .help
|
||||
.nf
|
||||
.cc |
|
||||
.databases List names and files of attached databases
|
||||
.dump ?TABLE? ... Dump the database in an SQL text format
|
||||
.echo ON|OFF Turn command echo on or off
|
||||
.exit Exit this program
|
||||
.explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
|
||||
.header(s) ON|OFF Turn display of headers on or off
|
||||
.help Show this message
|
||||
.import FILE TABLE Import data from FILE into TABLE
|
||||
.indices TABLE Show names of all indices on TABLE
|
||||
.mode MODE ?TABLE? Set output mode where MODE is one of:
|
||||
csv Comma-separated values
|
||||
column Left-aligned columns. (See .width)
|
||||
html HTML <table> code
|
||||
insert SQL insert statements for TABLE
|
||||
line One value per line
|
||||
list Values delimited by .separator string
|
||||
tabs Tab-separated values
|
||||
tcl TCL list elements
|
||||
.nullvalue STRING Print STRING in place of NULL values
|
||||
.output FILENAME Send output to FILENAME
|
||||
.output stdout Send output to the screen
|
||||
.prompt MAIN CONTINUE Replace the standard prompts
|
||||
.quit Exit this program
|
||||
.read FILENAME Execute SQL in FILENAME
|
||||
.schema ?TABLE? Show the CREATE statements
|
||||
.separator STRING Change separator used by output mode and .import
|
||||
.show Show the current values for various settings
|
||||
.tables ?PATTERN? List names of tables matching a LIKE pattern
|
||||
.timeout MS Try opening locked tables for MS milliseconds
|
||||
.width NUM NUM ... Set column widths for "column" mode
|
||||
sqlite>
|
||||
|cc .
|
||||
.sp
|
||||
.fi
|
||||
|
||||
.SH OPTIONS
|
||||
.B sqlite3
|
||||
has the following options:
|
||||
.TP
|
||||
.BI \-init\ file
|
||||
Read and execute commands from
|
||||
.I file
|
||||
, which can contain a mix of SQL statements and meta-commands.
|
||||
.TP
|
||||
.B \-echo
|
||||
Print commands before execution.
|
||||
.TP
|
||||
.B \-[no]header
|
||||
Turn headers on or off.
|
||||
.TP
|
||||
.B \-column
|
||||
Query results will be displayed in a table like form, using
|
||||
whitespace characters to separate the columns and align the
|
||||
output.
|
||||
.TP
|
||||
.B \-html
|
||||
Query results will be output as simple HTML tables.
|
||||
.TP
|
||||
.B \-line
|
||||
Query results will be displayed with one value per line, rows
|
||||
separated by a blank line. Designed to be easily parsed by
|
||||
scripts or other programs
|
||||
.TP
|
||||
.B \-list
|
||||
Query results will be displayed with the separator (|, by default)
|
||||
character between each field value. The default.
|
||||
.TP
|
||||
.BI \-separator\ separator
|
||||
Set output field separator. Default is '|'.
|
||||
.TP
|
||||
.BI \-nullvalue\ string
|
||||
Set string used to represent NULL values. Default is ''
|
||||
(empty string).
|
||||
.TP
|
||||
.B \-version
|
||||
Show SQLite version.
|
||||
.TP
|
||||
.B \-help
|
||||
Show help on options and exit.
|
||||
|
||||
|
||||
.SH INIT FILE
|
||||
.B sqlite3
|
||||
reads an initialization file to set the configuration of the
|
||||
interactive environment. Throughout initialization, any previously
|
||||
specified setting can be overridden. The sequence of initialization is
|
||||
as follows:
|
||||
|
||||
o The default configuration is established as follows:
|
||||
|
||||
.sp
|
||||
.nf
|
||||
.cc |
|
||||
mode = LIST
|
||||
separator = "|"
|
||||
main prompt = "sqlite> "
|
||||
continue prompt = " ...> "
|
||||
|cc .
|
||||
.sp
|
||||
.fi
|
||||
|
||||
o If the file
|
||||
.B ~/.sqliterc
|
||||
exists, it is processed first.
|
||||
can be found in the user's home directory, it is
|
||||
read and processed. It should generally only contain meta-commands.
|
||||
|
||||
o If the -init option is present, the specified file is processed.
|
||||
|
||||
o All other command line options are processed.
|
||||
|
||||
.SH SEE ALSO
|
||||
http://www.sqlite.org/
|
||||
.br
|
||||
The sqlite-doc package
|
||||
.SH AUTHOR
|
||||
This manual page was originally written by Andreas Rottmann
|
||||
<rotty@debian.org>, for the Debian GNU/Linux system (but may be used
|
||||
by others). It was subsequently revised by Bill Bumgarner <bbum@mac.com>.
|
||||
@@ -7,6 +7,8 @@ sqlite3_bind_int
|
||||
sqlite3_bind_int64
|
||||
sqlite3_bind_null
|
||||
sqlite3_bind_parameter_count
|
||||
sqlite3_bind_parameter_index
|
||||
sqlite3_bind_parameter_name
|
||||
sqlite3_bind_text
|
||||
sqlite3_bind_text16
|
||||
sqlite3_busy_handler
|
||||
@@ -37,18 +39,23 @@ sqlite3_create_collation16
|
||||
sqlite3_create_function
|
||||
sqlite3_create_function16
|
||||
sqlite3_data_count
|
||||
sqlite3_db_handle
|
||||
sqlite3_errcode
|
||||
sqlite3_errmsg
|
||||
sqlite3_errmsg16
|
||||
sqlite3_exec
|
||||
sqlite3_expired
|
||||
sqlite3_finalize
|
||||
sqlite3_free
|
||||
sqlite3_free_table
|
||||
sqlite3_get_autocommit
|
||||
sqlite3_get_auxdata
|
||||
sqlite3_get_table
|
||||
sqlite3_global_recover
|
||||
sqlite3_interrupt
|
||||
sqlite3_last_insert_rowid
|
||||
sqlite3_libversion
|
||||
sqlite3_libversion_number
|
||||
sqlite3_mprintf
|
||||
sqlite3_open
|
||||
sqlite3_open16
|
||||
@@ -74,6 +81,7 @@ sqlite3_snprintf
|
||||
sqlite3_step
|
||||
sqlite3_total_changes
|
||||
sqlite3_trace
|
||||
sqlite3_transfer_bindings
|
||||
sqlite3_user_data
|
||||
sqlite3_value_blob
|
||||
sqlite3_value_bytes
|
||||
|
||||
+557
@@ -0,0 +1,557 @@
|
||||
/*
|
||||
** 2005 February 15
|
||||
**
|
||||
** 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 C code routines that used to generate VDBE code
|
||||
** that implements the ALTER TABLE command.
|
||||
**
|
||||
** $Id: alter.c,v 1.8 2005/08/19 19:14:13 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
** The code in this file only exists if we are not omitting the
|
||||
** ALTER TABLE logic from the build.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_ALTERTABLE
|
||||
|
||||
|
||||
/*
|
||||
** This function is used by SQL generated to implement the
|
||||
** ALTER TABLE command. The first argument is the text of a CREATE TABLE or
|
||||
** CREATE INDEX command. The second is a table name. The table name in
|
||||
** the CREATE TABLE or CREATE INDEX statement is replaced with the second
|
||||
** argument and the result returned. Examples:
|
||||
**
|
||||
** sqlite_rename_table('CREATE TABLE abc(a, b, c)', 'def')
|
||||
** -> 'CREATE TABLE def(a, b, c)'
|
||||
**
|
||||
** sqlite_rename_table('CREATE INDEX i ON abc(a)', 'def')
|
||||
** -> 'CREATE INDEX i ON def(a, b, c)'
|
||||
*/
|
||||
static void renameTableFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
unsigned char const *zSql = sqlite3_value_text(argv[0]);
|
||||
unsigned char const *zTableName = sqlite3_value_text(argv[1]);
|
||||
|
||||
int token;
|
||||
Token tname;
|
||||
char const *zCsr = zSql;
|
||||
int len = 0;
|
||||
char *zRet;
|
||||
|
||||
/* The principle used to locate the table name in the CREATE TABLE
|
||||
** statement is that the table name is the first token that is immediatedly
|
||||
** followed by a left parenthesis - TK_LP.
|
||||
*/
|
||||
if( zSql ){
|
||||
do {
|
||||
/* Store the token that zCsr points to in tname. */
|
||||
tname.z = zCsr;
|
||||
tname.n = len;
|
||||
|
||||
/* Advance zCsr to the next token. Store that token type in 'token',
|
||||
** and it's length in 'len' (to be used next iteration of this loop).
|
||||
*/
|
||||
do {
|
||||
zCsr += len;
|
||||
len = sqlite3GetToken(zCsr, &token);
|
||||
} while( token==TK_SPACE );
|
||||
assert( len>0 );
|
||||
} while( token!=TK_LP );
|
||||
|
||||
zRet = sqlite3MPrintf("%.*s%Q%s", tname.z - zSql, zSql,
|
||||
zTableName, tname.z+tname.n);
|
||||
sqlite3_result_text(context, zRet, -1, sqlite3FreeX);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/* This function is used by SQL generated to implement the ALTER TABLE
|
||||
** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER
|
||||
** statement. The second is a table name. The table name in the CREATE
|
||||
** TRIGGER statement is replaced with the second argument and the result
|
||||
** returned. This is analagous to renameTableFunc() above, except for CREATE
|
||||
** TRIGGER, not CREATE INDEX and CREATE TABLE.
|
||||
*/
|
||||
static void renameTriggerFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
unsigned char const *zSql = sqlite3_value_text(argv[0]);
|
||||
unsigned char const *zTableName = sqlite3_value_text(argv[1]);
|
||||
|
||||
int token;
|
||||
Token tname;
|
||||
int dist = 3;
|
||||
char const *zCsr = zSql;
|
||||
int len = 0;
|
||||
char *zRet;
|
||||
|
||||
/* The principle used to locate the table name in the CREATE TRIGGER
|
||||
** statement is that the table name is the first token that is immediatedly
|
||||
** preceded by either TK_ON or TK_DOT and immediatedly followed by one
|
||||
** of TK_WHEN, TK_BEGIN or TK_FOR.
|
||||
*/
|
||||
if( zSql ){
|
||||
do {
|
||||
/* Store the token that zCsr points to in tname. */
|
||||
tname.z = zCsr;
|
||||
tname.n = len;
|
||||
|
||||
/* Advance zCsr to the next token. Store that token type in 'token',
|
||||
** and it's length in 'len' (to be used next iteration of this loop).
|
||||
*/
|
||||
do {
|
||||
zCsr += len;
|
||||
len = sqlite3GetToken(zCsr, &token);
|
||||
}while( token==TK_SPACE );
|
||||
assert( len>0 );
|
||||
|
||||
/* Variable 'dist' stores the number of tokens read since the most
|
||||
** recent TK_DOT or TK_ON. This means that when a WHEN, FOR or BEGIN
|
||||
** token is read and 'dist' equals 2, the condition stated above
|
||||
** to be met.
|
||||
**
|
||||
** Note that ON cannot be a database, table or column name, so
|
||||
** there is no need to worry about syntax like
|
||||
** "CREATE TRIGGER ... ON ON.ON BEGIN ..." etc.
|
||||
*/
|
||||
dist++;
|
||||
if( token==TK_DOT || token==TK_ON ){
|
||||
dist = 0;
|
||||
}
|
||||
} while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );
|
||||
|
||||
/* Variable tname now contains the token that is the old table-name
|
||||
** in the CREATE TRIGGER statement.
|
||||
*/
|
||||
zRet = sqlite3MPrintf("%.*s%Q%s", tname.z - zSql, zSql,
|
||||
zTableName, tname.z+tname.n);
|
||||
sqlite3_result_text(context, zRet, -1, sqlite3FreeX);
|
||||
}
|
||||
}
|
||||
#endif /* !SQLITE_OMIT_TRIGGER */
|
||||
|
||||
/*
|
||||
** Register built-in functions used to help implement ALTER TABLE
|
||||
*/
|
||||
void sqlite3AlterFunctions(sqlite3 *db){
|
||||
static const struct {
|
||||
char *zName;
|
||||
signed char nArg;
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value **);
|
||||
} aFuncs[] = {
|
||||
{ "sqlite_rename_table", 2, renameTableFunc},
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
{ "sqlite_rename_trigger", 2, renameTriggerFunc},
|
||||
#endif
|
||||
};
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
|
||||
sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
|
||||
SQLITE_UTF8, 0, aFuncs[i].xFunc, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate the text of a WHERE expression which can be used to select all
|
||||
** temporary triggers on table pTab from the sqlite_temp_master table. If
|
||||
** table pTab has no temporary triggers, or is itself stored in the
|
||||
** temporary database, NULL is returned.
|
||||
*/
|
||||
static char *whereTempTriggers(Parse *pParse, Table *pTab){
|
||||
Trigger *pTrig;
|
||||
char *zWhere = 0;
|
||||
char *tmp = 0;
|
||||
if( pTab->iDb!=1 ){
|
||||
for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
|
||||
if( pTrig->iDb==1 ){
|
||||
if( !zWhere ){
|
||||
zWhere = sqlite3MPrintf("name=%Q", pTrig->name);
|
||||
}else{
|
||||
tmp = zWhere;
|
||||
zWhere = sqlite3MPrintf("%s OR name=%Q", zWhere, pTrig->name);
|
||||
sqliteFree(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return zWhere;
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code to drop and reload the internal representation of table
|
||||
** pTab from the database, including triggers and temporary triggers.
|
||||
** Argument zName is the name of the table in the database schema at
|
||||
** the time the generated code is executed. This can be different from
|
||||
** pTab->zName if this function is being called to code part of an
|
||||
** "ALTER TABLE RENAME TO" statement.
|
||||
*/
|
||||
static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
|
||||
Vdbe *v;
|
||||
char *zWhere;
|
||||
int iDb;
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
Trigger *pTrig;
|
||||
#endif
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
iDb = pTab->iDb;
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/* Drop any table triggers from the internal schema. */
|
||||
for(pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext){
|
||||
assert( pTrig->iDb==iDb || pTrig->iDb==1 );
|
||||
sqlite3VdbeOp3(v, OP_DropTrigger, pTrig->iDb, 0, pTrig->name, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Drop the table and index from the internal schema */
|
||||
sqlite3VdbeOp3(v, OP_DropTable, iDb, 0, pTab->zName, 0);
|
||||
|
||||
/* Reload the table, index and permanent trigger schemas. */
|
||||
zWhere = sqlite3MPrintf("tbl_name=%Q", zName);
|
||||
if( !zWhere ) return;
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, zWhere, P3_DYNAMIC);
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/* Now, if the table is not stored in the temp database, reload any temp
|
||||
** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined.
|
||||
*/
|
||||
if( (zWhere=whereTempTriggers(pParse, pTab)) ){
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, 1, 0, zWhere, P3_DYNAMIC);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
|
||||
** command.
|
||||
*/
|
||||
void sqlite3AlterRenameTable(
|
||||
Parse *pParse, /* Parser context. */
|
||||
SrcList *pSrc, /* The table to rename. */
|
||||
Token *pName /* The new table name. */
|
||||
){
|
||||
int iDb; /* Database that contains the table */
|
||||
char *zDb; /* Name of database iDb */
|
||||
Table *pTab; /* Table being renamed */
|
||||
char *zName = 0; /* NULL-terminated version of pName */
|
||||
sqlite3 *db = pParse->db; /* Database connection */
|
||||
Vdbe *v;
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
char *zWhere = 0; /* Where clause to locate temp triggers */
|
||||
#endif
|
||||
|
||||
if( sqlite3_malloc_failed ) goto exit_rename_table;
|
||||
assert( pSrc->nSrc==1 );
|
||||
|
||||
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
|
||||
if( !pTab ) goto exit_rename_table;
|
||||
iDb = pTab->iDb;
|
||||
zDb = db->aDb[iDb].zName;
|
||||
|
||||
/* Get a NULL terminated version of the new table name. */
|
||||
zName = sqlite3NameFromToken(pName);
|
||||
if( !zName ) goto exit_rename_table;
|
||||
|
||||
/* Check that a table or index named 'zName' does not already exist
|
||||
** in database iDb. If so, this is an error.
|
||||
*/
|
||||
if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"there is already another table or index with this name: %s", zName);
|
||||
goto exit_rename_table;
|
||||
}
|
||||
|
||||
/* Make sure it is not a system table being altered, or a reserved name
|
||||
** that the table is being renamed to.
|
||||
*/
|
||||
if( strlen(pTab->zName)>6 && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ){
|
||||
sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);
|
||||
goto exit_rename_table;
|
||||
}
|
||||
if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
|
||||
goto exit_rename_table;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
/* Invoke the authorization callback. */
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
|
||||
goto exit_rename_table;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Begin a transaction and code the VerifyCookie for database iDb.
|
||||
** Then modify the schema cookie (since the ALTER TABLE modifies the
|
||||
** schema).
|
||||
*/
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ){
|
||||
goto exit_rename_table;
|
||||
}
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
sqlite3ChangeCookie(db, v, iDb);
|
||||
|
||||
/* Modify the sqlite_master table to use the new table name. */
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE %Q.%s SET "
|
||||
#ifdef SQLITE_OMIT_TRIGGER
|
||||
"sql = sqlite_rename_table(sql, %Q), "
|
||||
#else
|
||||
"sql = CASE "
|
||||
"WHEN type = 'trigger' THEN sqlite_rename_trigger(sql, %Q)"
|
||||
"ELSE sqlite_rename_table(sql, %Q) END, "
|
||||
#endif
|
||||
"tbl_name = %Q, "
|
||||
"name = CASE "
|
||||
"WHEN type='table' THEN %Q "
|
||||
"WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
|
||||
"'sqlite_autoindex_' || %Q || substr(name, %d+18,10) "
|
||||
"ELSE name END "
|
||||
"WHERE tbl_name=%Q AND "
|
||||
"(type='table' OR type='index' OR type='trigger');",
|
||||
zDb, SCHEMA_TABLE(iDb), zName, zName, zName,
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
zName,
|
||||
#endif
|
||||
zName, strlen(pTab->zName), pTab->zName
|
||||
);
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
/* If the sqlite_sequence table exists in this database, then update
|
||||
** it with the new table name.
|
||||
*/
|
||||
if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE %Q.sqlite_sequence set name = %Q WHERE name = %Q",
|
||||
zDb, zName, pTab->zName);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/* If there are TEMP triggers on this table, modify the sqlite_temp_master
|
||||
** table. Don't do this if the table being ALTERed is itself located in
|
||||
** the temp database.
|
||||
*/
|
||||
if( (zWhere=whereTempTriggers(pParse, pTab)) ){
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE sqlite_temp_master SET "
|
||||
"sql = sqlite_rename_trigger(sql, %Q), "
|
||||
"tbl_name = %Q "
|
||||
"WHERE %s;", zName, zName, zWhere);
|
||||
sqliteFree(zWhere);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Drop and reload the internal table schema. */
|
||||
reloadTableSchema(pParse, pTab, zName);
|
||||
|
||||
exit_rename_table:
|
||||
sqlite3SrcListDelete(pSrc);
|
||||
sqliteFree(zName);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This function is called after an "ALTER TABLE ... ADD" statement
|
||||
** has been parsed. Argument pColDef contains the text of the new
|
||||
** column definition.
|
||||
**
|
||||
** The Table structure pParse->pNewTable was extended to include
|
||||
** the new column during parsing.
|
||||
*/
|
||||
void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
Table *pNew; /* Copy of pParse->pNewTable */
|
||||
Table *pTab; /* Table being altered */
|
||||
int iDb; /* Database number */
|
||||
const char *zDb; /* Database name */
|
||||
const char *zTab; /* Table name */
|
||||
char *zCol; /* Null-terminated column definition */
|
||||
Column *pCol; /* The new column */
|
||||
Expr *pDflt; /* Default value for the new column */
|
||||
Vdbe *v;
|
||||
|
||||
if( pParse->nErr ) return;
|
||||
pNew = pParse->pNewTable;
|
||||
assert( pNew );
|
||||
|
||||
iDb = pNew->iDb;
|
||||
zDb = pParse->db->aDb[iDb].zName;
|
||||
zTab = pNew->zName;
|
||||
pCol = &pNew->aCol[pNew->nCol-1];
|
||||
pDflt = pCol->pDflt;
|
||||
pTab = sqlite3FindTable(pParse->db, zTab, zDb);
|
||||
assert( pTab );
|
||||
|
||||
/* If the default value for the new column was specified with a
|
||||
** literal NULL, then set pDflt to 0. This simplifies checking
|
||||
** for an SQL NULL default below.
|
||||
*/
|
||||
if( pDflt && pDflt->op==TK_NULL ){
|
||||
pDflt = 0;
|
||||
}
|
||||
|
||||
/* Check that the new column is not specified as PRIMARY KEY or UNIQUE.
|
||||
** If there is a NOT NULL constraint, then the default value for the
|
||||
** column must not be NULL.
|
||||
*/
|
||||
if( pCol->isPrimKey ){
|
||||
sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column");
|
||||
return;
|
||||
}
|
||||
if( pNew->pIndex ){
|
||||
sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column");
|
||||
return;
|
||||
}
|
||||
if( pCol->notNull && !pDflt ){
|
||||
sqlite3ErrorMsg(pParse,
|
||||
"Cannot add a NOT NULL column with default value NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Ensure the default expression is something that sqlite3ValueFromExpr()
|
||||
** can handle (i.e. not CURRENT_TIME etc.)
|
||||
*/
|
||||
if( pDflt ){
|
||||
sqlite3_value *pVal;
|
||||
if( sqlite3ValueFromExpr(pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
|
||||
/* malloc() has failed */
|
||||
return;
|
||||
}
|
||||
if( !pVal ){
|
||||
sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default");
|
||||
return;
|
||||
}
|
||||
sqlite3ValueFree(pVal);
|
||||
}
|
||||
|
||||
/* Modify the CREATE TABLE statement. */
|
||||
zCol = sqliteStrNDup(pColDef->z, pColDef->n);
|
||||
if( zCol ){
|
||||
char *zEnd = &zCol[pColDef->n-1];
|
||||
while( (zEnd>zCol && *zEnd==';') || isspace(*(unsigned char *)zEnd) ){
|
||||
*zEnd-- = '\0';
|
||||
}
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE %Q.%s SET "
|
||||
"sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d,length(sql)) "
|
||||
"WHERE type = 'table' AND name = %Q",
|
||||
zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1,
|
||||
zTab
|
||||
);
|
||||
sqliteFree(zCol);
|
||||
}
|
||||
|
||||
/* If the default value of the new column is NULL, then set the file
|
||||
** format to 2. If the default value of the new column is not NULL,
|
||||
** the file format becomes 3.
|
||||
*/
|
||||
if( (v=sqlite3GetVdbe(pParse)) ){
|
||||
int f = (pDflt?3:2);
|
||||
|
||||
/* Only set the file format to $f if it is currently less than $f. */
|
||||
sqlite3VdbeAddOp(v, OP_ReadCookie, iDb, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, f, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ge, 0, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, f, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 1);
|
||||
}
|
||||
|
||||
/* Reload the schema of the modified table. */
|
||||
reloadTableSchema(pParse, pTab, pTab->zName);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This function is called by the parser after the table-name in
|
||||
** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
|
||||
** pSrc is the full-name of the table being altered.
|
||||
**
|
||||
** This routine makes a (partial) copy of the Table structure
|
||||
** for the table being altered and sets Parse.pNewTable to point
|
||||
** to it. Routines called by the parser as the column definition
|
||||
** is parsed (i.e. sqlite3AddColumn()) add the new Column data to
|
||||
** the copy. The copy of the Table structure is deleted by tokenize.c
|
||||
** after parsing is finished.
|
||||
**
|
||||
** Routine sqlite3AlterFinishAddColumn() will be called to complete
|
||||
** coding the "ALTER TABLE ... ADD" statement.
|
||||
*/
|
||||
void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
||||
Table *pNew;
|
||||
Table *pTab;
|
||||
Vdbe *v;
|
||||
int iDb;
|
||||
int i;
|
||||
int nAlloc;
|
||||
|
||||
|
||||
/* Look up the table being altered. */
|
||||
assert( pParse->pNewTable==0 );
|
||||
if( sqlite3_malloc_failed ) goto exit_begin_add_column;
|
||||
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
|
||||
if( !pTab ) goto exit_begin_add_column;
|
||||
|
||||
/* Make sure this is not an attempt to ALTER a view. */
|
||||
if( pTab->pSelect ){
|
||||
sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
|
||||
goto exit_begin_add_column;
|
||||
}
|
||||
|
||||
assert( pTab->addColOffset>0 );
|
||||
iDb = pTab->iDb;
|
||||
|
||||
/* Put a copy of the Table struct in Parse.pNewTable for the
|
||||
** sqlite3AddColumn() function and friends to modify.
|
||||
*/
|
||||
pNew = (Table *)sqliteMalloc(sizeof(Table));
|
||||
if( !pNew ) goto exit_begin_add_column;
|
||||
pParse->pNewTable = pNew;
|
||||
pNew->nRef = 1;
|
||||
pNew->nCol = pTab->nCol;
|
||||
assert( pNew->nCol>0 );
|
||||
nAlloc = (((pNew->nCol-1)/8)*8)+8;
|
||||
assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
|
||||
pNew->aCol = (Column *)sqliteMalloc(sizeof(Column)*nAlloc);
|
||||
pNew->zName = sqliteStrDup(pTab->zName);
|
||||
if( !pNew->aCol || !pNew->zName ){
|
||||
goto exit_begin_add_column;
|
||||
}
|
||||
memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
|
||||
for(i=0; i<pNew->nCol; i++){
|
||||
Column *pCol = &pNew->aCol[i];
|
||||
pCol->zName = sqliteStrDup(pCol->zName);
|
||||
pCol->zType = 0;
|
||||
pCol->pDflt = 0;
|
||||
}
|
||||
pNew->iDb = iDb;
|
||||
pNew->addColOffset = pTab->addColOffset;
|
||||
pNew->nRef = 1;
|
||||
|
||||
/* Begin a transaction and increment the schema cookie. */
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) goto exit_begin_add_column;
|
||||
sqlite3ChangeCookie(pParse->db, v, iDb);
|
||||
|
||||
exit_begin_add_column:
|
||||
sqlite3SrcListDelete(pSrc);
|
||||
return;
|
||||
}
|
||||
#endif /* SQLITE_ALTER_TABLE */
|
||||
+386
@@ -0,0 +1,386 @@
|
||||
/*
|
||||
** 2005 July 8
|
||||
**
|
||||
** 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 code associated with the ANALYZE command.
|
||||
**
|
||||
** @(#) $Id: analyze.c,v 1.9 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_ANALYZE
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This routine generates code that opens the sqlite_stat1 table on cursor
|
||||
** iStatCur.
|
||||
**
|
||||
** If the sqlite_stat1 tables does not previously exist, it is created.
|
||||
** If it does previously exist, all entires associated with table zWhere
|
||||
** are removed. If zWhere==0 then all entries are removed.
|
||||
*/
|
||||
static void openStatTable(
|
||||
Parse *pParse, /* Parsing context */
|
||||
int iDb, /* The database we are looking in */
|
||||
int iStatCur, /* Open the sqlite_stat1 table on this cursor */
|
||||
const char *zWhere /* Delete entries associated with this table */
|
||||
){
|
||||
sqlite3 *db = pParse->db;
|
||||
Db *pDb;
|
||||
int iRootPage;
|
||||
Table *pStat;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
|
||||
pDb = &db->aDb[iDb];
|
||||
if( (pStat = sqlite3FindTable(db, "sqlite_stat1", pDb->zName))==0 ){
|
||||
/* The sqlite_stat1 tables does not exist. Create it.
|
||||
** Note that a side-effect of the CREATE TABLE statement is to leave
|
||||
** the rootpage of the new table on the top of the stack. This is
|
||||
** important because the OpenWrite opcode below will be needing it. */
|
||||
sqlite3NestedParse(pParse,
|
||||
"CREATE TABLE %Q.sqlite_stat1(tbl,idx,stat)",
|
||||
pDb->zName
|
||||
);
|
||||
iRootPage = 0; /* Cause rootpage to be taken from top of stack */
|
||||
}else if( zWhere ){
|
||||
/* The sqlite_stat1 table exists. Delete all entries associated with
|
||||
** the table zWhere. */
|
||||
sqlite3NestedParse(pParse,
|
||||
"DELETE FROM %Q.sqlite_stat1 WHERE tbl=%Q",
|
||||
pDb->zName, zWhere
|
||||
);
|
||||
iRootPage = pStat->tnum;
|
||||
}else{
|
||||
/* The sqlite_stat1 table already exists. Delete all rows. */
|
||||
iRootPage = pStat->tnum;
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pStat->tnum, iDb);
|
||||
}
|
||||
|
||||
/* Open the sqlite_stat1 table for writing.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenWrite, iStatCur, iRootPage);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iStatCur, 3);
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code to do an analysis of all indices associated with
|
||||
** a single table.
|
||||
*/
|
||||
static void analyzeOneTable(
|
||||
Parse *pParse, /* Parser context */
|
||||
Table *pTab, /* Table whose indices are to be analyzed */
|
||||
int iStatCur, /* Cursor that writes to the sqlite_stat1 table */
|
||||
int iMem /* Available memory locations begin here */
|
||||
){
|
||||
Index *pIdx; /* An index to being analyzed */
|
||||
int iIdxCur; /* Cursor number for index being analyzed */
|
||||
int nCol; /* Number of columns in the index */
|
||||
Vdbe *v; /* The virtual machine being built up */
|
||||
int i; /* Loop counter */
|
||||
int topOfLoop; /* The top of the loop */
|
||||
int endOfLoop; /* The end of the loop */
|
||||
int addr; /* The address of an instruction */
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( pTab==0 || pTab->pIndex==0 ){
|
||||
/* Do no analysis for tables that have no indices */
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
|
||||
pParse->db->aDb[pTab->iDb].zName ) ){
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
iIdxCur = pParse->nTab;
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
/* Open a cursor to the index to be analyzed
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
VdbeComment((v, "# %s", pIdx->zName));
|
||||
sqlite3VdbeOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
nCol = pIdx->nColumn;
|
||||
if( iMem+nCol*2>=pParse->nMem ){
|
||||
pParse->nMem = iMem+nCol*2+1;
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iIdxCur, nCol+1);
|
||||
|
||||
/* Memory cells are used as follows:
|
||||
**
|
||||
** mem[iMem]: The total number of rows in the table.
|
||||
** mem[iMem+1]: Number of distinct values in column 1
|
||||
** ...
|
||||
** mem[iMem+nCol]: Number of distinct values in column N
|
||||
** mem[iMem+nCol+1] Last observed value of column 1
|
||||
** ...
|
||||
** mem[iMem+nCol+nCol]: Last observed value of column N
|
||||
**
|
||||
** Cells iMem through iMem+nCol are initialized to 0. The others
|
||||
** are initialized to NULL.
|
||||
*/
|
||||
for(i=0; i<=nCol; i++){
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, iMem+i);
|
||||
}
|
||||
for(i=0; i<nCol; i++){
|
||||
sqlite3VdbeAddOp(v, OP_MemNull, iMem+nCol+i+1, 0);
|
||||
}
|
||||
|
||||
/* Do the analysis.
|
||||
*/
|
||||
endOfLoop = sqlite3VdbeMakeLabel(v);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, endOfLoop);
|
||||
topOfLoop = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, iMem, 0);
|
||||
for(i=0; i<nCol; i++){
|
||||
sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+nCol+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ne, 0x100, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, endOfLoop);
|
||||
for(i=0; i<nCol; i++){
|
||||
addr = sqlite3VdbeAddOp(v, OP_MemIncr, iMem+i+1, 0);
|
||||
sqlite3VdbeChangeP2(v, topOfLoop + 3*i + 3, addr);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iMem+nCol+i+1, 1);
|
||||
}
|
||||
sqlite3VdbeResolveLabel(v, endOfLoop);
|
||||
sqlite3VdbeAddOp(v, OP_Next, iIdxCur, topOfLoop);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iIdxCur, 0);
|
||||
|
||||
/* Store the results.
|
||||
**
|
||||
** The result is a single row of the sqlite_stmt1 table. The first
|
||||
** two columns are the names of the table and index. The third column
|
||||
** is a string composed of a list of integer statistics about the
|
||||
** index. The first integer in the list is the total number of entires
|
||||
** in the index. There is one additional integer in the list for each
|
||||
** column of the table. This additional integer is a guess of how many
|
||||
** rows of the table the index will select. If D is the count of distinct
|
||||
** values and K is the total number of rows, then the integer is computed
|
||||
** as:
|
||||
**
|
||||
** I = (K+D-1)/D
|
||||
**
|
||||
** If K==0 then no entry is made into the sqlite_stat1 table.
|
||||
** If K>0 then it is always the case the D>0 so division by zero
|
||||
** is never possible.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_IfNot, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, iStatCur, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, " ", 0);
|
||||
for(i=0; i<nCol; i++){
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Add, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, -1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Divide, 0, 0);
|
||||
if( i==nCol-1 ){
|
||||
sqlite3VdbeAddOp(v, OP_Concat, nCol*2-1, 0);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "ttt", 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, iStatCur, 0);
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code that will cause the most recent index analysis to
|
||||
** be laoded into internal hash tables where is can be used.
|
||||
*/
|
||||
static void loadAnalysis(Parse *pParse, int iDb){
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
sqlite3VdbeAddOp(v, OP_LoadAnalysis, iDb, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code that will do an analysis of an entire database
|
||||
*/
|
||||
static void analyzeDatabase(Parse *pParse, int iDb){
|
||||
sqlite3 *db = pParse->db;
|
||||
HashElem *k;
|
||||
int iStatCur;
|
||||
int iMem;
|
||||
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
iStatCur = pParse->nTab++;
|
||||
openStatTable(pParse, iDb, iStatCur, 0);
|
||||
iMem = pParse->nMem;
|
||||
for(k=sqliteHashFirst(&db->aDb[iDb].tblHash); k; k=sqliteHashNext(k)){
|
||||
Table *pTab = (Table*)sqliteHashData(k);
|
||||
analyzeOneTable(pParse, pTab, iStatCur, iMem);
|
||||
}
|
||||
loadAnalysis(pParse, iDb);
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code that will do an analysis of a single table in
|
||||
** a database.
|
||||
*/
|
||||
static void analyzeTable(Parse *pParse, Table *pTab){
|
||||
int iDb;
|
||||
int iStatCur;
|
||||
|
||||
assert( pTab!=0 );
|
||||
iDb = pTab->iDb;
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
iStatCur = pParse->nTab++;
|
||||
openStatTable(pParse, iDb, iStatCur, pTab->zName);
|
||||
analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem);
|
||||
loadAnalysis(pParse, iDb);
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code for the ANALYZE command. The parser calls this routine
|
||||
** when it recognizes an ANALYZE command.
|
||||
**
|
||||
** ANALYZE -- 1
|
||||
** ANALYZE <database> -- 2
|
||||
** ANALYZE ?<database>.?<tablename> -- 3
|
||||
**
|
||||
** Form 1 causes all indices in all attached databases to be analyzed.
|
||||
** Form 2 analyzes all indices the single database named.
|
||||
** Form 3 analyzes all indices associated with the named table.
|
||||
*/
|
||||
void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb;
|
||||
int i;
|
||||
char *z, *zDb;
|
||||
Table *pTab;
|
||||
Token *pTableName;
|
||||
|
||||
/* Read the database schema. If an error occurs, leave an error message
|
||||
** and code in pParse and return NULL. */
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
|
||||
return;
|
||||
}
|
||||
|
||||
if( pName1==0 ){
|
||||
/* Form 1: Analyze everything */
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( i==1 ) continue; /* Do not analyze the TEMP database */
|
||||
analyzeDatabase(pParse, i);
|
||||
}
|
||||
}else if( pName2==0 || pName2->n==0 ){
|
||||
/* Form 2: Analyze the database or table named */
|
||||
iDb = sqlite3FindDb(db, pName1);
|
||||
if( iDb>=0 ){
|
||||
analyzeDatabase(pParse, iDb);
|
||||
}else{
|
||||
z = sqlite3NameFromToken(pName1);
|
||||
pTab = sqlite3LocateTable(pParse, z, 0);
|
||||
sqliteFree(z);
|
||||
if( pTab ){
|
||||
analyzeTable(pParse, pTab);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
/* Form 3: Analyze the fully qualified table name */
|
||||
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
|
||||
if( iDb>=0 ){
|
||||
zDb = db->aDb[iDb].zName;
|
||||
z = sqlite3NameFromToken(pTableName);
|
||||
pTab = sqlite3LocateTable(pParse, z, zDb);
|
||||
sqliteFree(z);
|
||||
if( pTab ){
|
||||
analyzeTable(pParse, pTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Used to pass information from the analyzer reader through to the
|
||||
** callback routine.
|
||||
*/
|
||||
typedef struct analysisInfo analysisInfo;
|
||||
struct analysisInfo {
|
||||
sqlite3 *db;
|
||||
const char *zDatabase;
|
||||
};
|
||||
|
||||
/*
|
||||
** This callback is invoked once for each index when reading the
|
||||
** sqlite_stat1 table.
|
||||
**
|
||||
** argv[0] = name of the index
|
||||
** argv[1] = results of analysis - on integer for each column
|
||||
*/
|
||||
static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){
|
||||
analysisInfo *pInfo = (analysisInfo*)pData;
|
||||
Index *pIndex;
|
||||
int i, c;
|
||||
unsigned int v;
|
||||
const char *z;
|
||||
|
||||
assert( argc==2 );
|
||||
if( argv==0 || argv[0]==0 || argv[1]==0 ){
|
||||
return 0;
|
||||
}
|
||||
pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase);
|
||||
if( pIndex==0 ){
|
||||
return 0;
|
||||
}
|
||||
z = argv[1];
|
||||
for(i=0; *z && i<=pIndex->nColumn; i++){
|
||||
v = 0;
|
||||
while( (c=z[0])>='0' && c<='9' ){
|
||||
v = v*10 + c - '0';
|
||||
z++;
|
||||
}
|
||||
pIndex->aiRowEst[i] = v;
|
||||
if( *z==' ' ) z++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Load the content of the sqlite_stat1 table into the index hash tables.
|
||||
*/
|
||||
void sqlite3AnalysisLoad(sqlite3 *db, int iDb){
|
||||
analysisInfo sInfo;
|
||||
HashElem *i;
|
||||
char *zSql;
|
||||
|
||||
/* Clear any prior statistics */
|
||||
for(i=sqliteHashFirst(&db->aDb[iDb].idxHash); i; i=sqliteHashNext(i)){
|
||||
Index *pIdx = sqliteHashData(i);
|
||||
sqlite3DefaultRowEst(pIdx);
|
||||
}
|
||||
|
||||
/* Check to make sure the sqlite_stat1 table existss */
|
||||
sInfo.db = db;
|
||||
sInfo.zDatabase = db->aDb[iDb].zName;
|
||||
if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Load new statistics out of the sqlite_stat1 table */
|
||||
zSql = sqlite3MPrintf("SELECT idx, stat FROM %Q.sqlite_stat1",
|
||||
sInfo.zDatabase);
|
||||
sqlite3SafetyOff(db);
|
||||
sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
|
||||
sqlite3SafetyOn(db);
|
||||
sqliteFree(zSql);
|
||||
}
|
||||
|
||||
|
||||
#endif /* SQLITE_OMIT_ANALYZE */
|
||||
+60
-36
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.26 2004/08/01 03:52:18 drh Exp $
|
||||
** $Id: attach.c,v 1.34 2005/08/20 03:03:04 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -28,16 +28,18 @@ void sqlite3Attach(
|
||||
Token *pFilename, /* Name of database file */
|
||||
Token *pDbname, /* Name of the database to use internally */
|
||||
int keyType, /* 0: no key. 1: TEXT, 2: BLOB */
|
||||
Token *pKey /* Text of the key for keytype 2 and 3 */
|
||||
Token *pKey /* Text of the key for keytype 1 and 2 */
|
||||
){
|
||||
Db *aNew;
|
||||
int rc, i;
|
||||
char *zFile, *zName;
|
||||
sqlite *db;
|
||||
char *zFile = 0;
|
||||
char *zName = 0;
|
||||
sqlite3 *db;
|
||||
Vdbe *v;
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
|
||||
if( pParse->explain ) return;
|
||||
db = pParse->db;
|
||||
@@ -54,34 +56,40 @@ void sqlite3Attach(
|
||||
return;
|
||||
}
|
||||
|
||||
zFile = sqlite3NameFromToken(pFilename);;
|
||||
if( zFile==0 ) return;
|
||||
zFile = sqlite3NameFromToken(pFilename);
|
||||
if( zFile==0 ){
|
||||
goto attach_end;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
|
||||
sqliteFree(zFile);
|
||||
return;
|
||||
goto attach_end;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
zName = sqlite3NameFromToken(pDbname);
|
||||
if( zName==0 ) return;
|
||||
if( zName==0 ){
|
||||
goto attach_end;
|
||||
}
|
||||
for(i=0; i<db->nDb; i++){
|
||||
char *z = db->aDb[i].zName;
|
||||
if( z && sqlite3StrICmp(z, zName)==0 ){
|
||||
sqlite3ErrorMsg(pParse, "database %z is already in use", zName);
|
||||
sqlite3ErrorMsg(pParse, "database %s is already in use", zName);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
sqliteFree(zFile);
|
||||
return;
|
||||
goto attach_end;
|
||||
}
|
||||
}
|
||||
|
||||
if( db->aDb==db->aDbStatic ){
|
||||
aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );
|
||||
if( aNew==0 ) return;
|
||||
if( aNew==0 ){
|
||||
goto attach_end;
|
||||
}
|
||||
memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
|
||||
}else{
|
||||
aNew = sqliteRealloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
|
||||
if( aNew==0 ) return;
|
||||
if( aNew==0 ){
|
||||
goto attach_end;
|
||||
}
|
||||
}
|
||||
db->aDb = aNew;
|
||||
aNew = &db->aDb[db->nDb++];
|
||||
@@ -91,6 +99,7 @@ void sqlite3Attach(
|
||||
sqlite3HashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);
|
||||
aNew->zName = zName;
|
||||
zName = 0;
|
||||
aNew->safety_level = 3;
|
||||
rc = sqlite3BtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
|
||||
if( rc ){
|
||||
@@ -125,7 +134,6 @@ void sqlite3Attach(
|
||||
}
|
||||
}
|
||||
#endif
|
||||
sqliteFree(zFile);
|
||||
db->flags &= ~SQLITE_Initialized;
|
||||
if( pParse->nErr==0 && rc==SQLITE_OK ){
|
||||
rc = sqlite3ReadSchema(pParse);
|
||||
@@ -138,11 +146,15 @@ void sqlite3Attach(
|
||||
db->aDb[i].pBt = 0;
|
||||
}
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
if( 0==pParse->nErr ){
|
||||
pParse->nErr++;
|
||||
assert( pParse->nErr>0 ); /* Always set by sqlite3ReadSchema() */
|
||||
if( pParse->rc==SQLITE_OK ){
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
attach_end:
|
||||
sqliteFree(zFile);
|
||||
sqliteFree(zName);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -154,29 +166,33 @@ void sqlite3Attach(
|
||||
*/
|
||||
void sqlite3Detach(Parse *pParse, Token *pDbname){
|
||||
int i;
|
||||
sqlite *db;
|
||||
sqlite3 *db;
|
||||
Vdbe *v;
|
||||
Db *pDb = 0;
|
||||
char *zName;
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( !v ) return;
|
||||
sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
|
||||
if( pParse->explain ) return;
|
||||
db = pParse->db;
|
||||
zName = sqlite3NameFromToken(pDbname);
|
||||
if( zName==0 ) return;
|
||||
for(i=0; i<db->nDb; i++){
|
||||
pDb = &db->aDb[i];
|
||||
if( pDb->pBt==0 || pDb->zName==0 ) continue;
|
||||
if( strlen(pDb->zName)!=pDbname->n ) continue;
|
||||
if( sqlite3StrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break;
|
||||
if( pDb->pBt==0 ) continue;
|
||||
if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
|
||||
}
|
||||
if( i>=db->nDb ){
|
||||
sqlite3ErrorMsg(pParse, "no such database: %T", pDbname);
|
||||
sqlite3ErrorMsg(pParse, "no such database: %z", zName);
|
||||
return;
|
||||
}
|
||||
if( i<2 ){
|
||||
sqlite3ErrorMsg(pParse, "cannot detach database %T", pDbname);
|
||||
sqlite3ErrorMsg(pParse, "cannot detach database %z", zName);
|
||||
return;
|
||||
}
|
||||
sqliteFree(zName);
|
||||
if( !db->autoCommit ){
|
||||
sqlite3ErrorMsg(pParse, "cannot DETACH database within transaction");
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
@@ -202,11 +218,11 @@ void sqlite3Detach(Parse *pParse, Token *pDbname){
|
||||
int sqlite3FixInit(
|
||||
DbFixer *pFix, /* The fixer to be initialized */
|
||||
Parse *pParse, /* Error messages will be written here */
|
||||
int iDb, /* This is the database that must must be used */
|
||||
int iDb, /* This is the database that must be used */
|
||||
const char *zType, /* "view", "trigger", or "index" */
|
||||
const Token *pName /* Name of the view, trigger, or index */
|
||||
){
|
||||
sqlite *db;
|
||||
sqlite3 *db;
|
||||
|
||||
if( iDb<0 || iDb==1 ) return 0;
|
||||
db = pParse->db;
|
||||
@@ -238,24 +254,27 @@ int sqlite3FixSrcList(
|
||||
){
|
||||
int i;
|
||||
const char *zDb;
|
||||
struct SrcList_item *pItem;
|
||||
|
||||
if( pList==0 ) return 0;
|
||||
zDb = pFix->zDb;
|
||||
for(i=0; i<pList->nSrc; i++){
|
||||
if( pList->a[i].zDatabase==0 ){
|
||||
pList->a[i].zDatabase = sqliteStrDup(zDb);
|
||||
}else if( sqlite3StrICmp(pList->a[i].zDatabase,zDb)!=0 ){
|
||||
for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
|
||||
if( pItem->zDatabase==0 ){
|
||||
pItem->zDatabase = sqliteStrDup(zDb);
|
||||
}else if( sqlite3StrICmp(pItem->zDatabase,zDb)!=0 ){
|
||||
sqlite3ErrorMsg(pFix->pParse,
|
||||
"%s %z cannot reference objects in database %s",
|
||||
pFix->zType, sqliteStrNDup(pFix->pName->z, pFix->pName->n),
|
||||
pList->a[i].zDatabase);
|
||||
"%s %T cannot reference objects in database %s",
|
||||
pFix->zType, pFix->pName, pItem->zDatabase);
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixSelect(pFix, pList->a[i].pSelect) ) return 1;
|
||||
if( sqlite3FixExpr(pFix, pList->a[i].pOn) ) return 1;
|
||||
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
|
||||
if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1;
|
||||
if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
|
||||
int sqlite3FixSelect(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
Select *pSelect /* The SELECT statement to be fixed to one database */
|
||||
@@ -300,14 +319,18 @@ int sqlite3FixExprList(
|
||||
ExprList *pList /* The expression to be fixed to one database */
|
||||
){
|
||||
int i;
|
||||
struct ExprList_item *pItem;
|
||||
if( pList==0 ) return 0;
|
||||
for(i=0; i<pList->nExpr; i++){
|
||||
if( sqlite3FixExpr(pFix, pList->a[i].pExpr) ){
|
||||
for(i=0, pItem=pList->a; i<pList->nExpr; i++, pItem++){
|
||||
if( sqlite3FixExpr(pFix, pItem->pExpr) ){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int sqlite3FixTriggerStep(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
TriggerStep *pStep /* The trigger step be fixed to one database */
|
||||
@@ -326,3 +349,4 @@ int sqlite3FixTriggerStep(
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
+13
-11
@@ -14,7 +14,7 @@
|
||||
** systems that do not need this facility may omit it by recompiling
|
||||
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
|
||||
**
|
||||
** $Id: auth.c,v 1.16 2004/06/19 16:06:11 drh Exp $
|
||||
** $Id: auth.c,v 1.22 2005/07/29 15:36:15 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -70,12 +70,13 @@
|
||||
** setting of the auth function is NULL.
|
||||
*/
|
||||
int sqlite3_set_authorizer(
|
||||
sqlite *db,
|
||||
sqlite3 *db,
|
||||
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
|
||||
void *pArg
|
||||
){
|
||||
db->xAuth = xAuth;
|
||||
db->pAuthArg = pArg;
|
||||
sqlite3ExpirePreparedStatements(db);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -87,7 +88,7 @@ static void sqliteAuthBadReturnCode(Parse *pParse, int rc){
|
||||
sqlite3ErrorMsg(pParse, "illegal return value (%d) from the "
|
||||
"authorization function - should be SQLITE_OK, SQLITE_IGNORE, "
|
||||
"or SQLITE_DENY", rc);
|
||||
pParse->rc = SQLITE_MISUSE;
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -104,29 +105,30 @@ void sqlite3AuthRead(
|
||||
Expr *pExpr, /* The expression to check authorization on */
|
||||
SrcList *pTabList /* All table that pExpr might refer to */
|
||||
){
|
||||
sqlite *db = pParse->db;
|
||||
sqlite3 *db = pParse->db;
|
||||
int rc;
|
||||
Table *pTab; /* The table being read */
|
||||
const char *zCol; /* Name of the column of the table */
|
||||
int iSrc; /* Index in pTabList->a[] of table being read */
|
||||
const char *zDBase; /* Name of database being accessed */
|
||||
TriggerStack *pStack; /* The stack of current triggers */
|
||||
|
||||
if( db->xAuth==0 ) return;
|
||||
if( pExpr->op==TK_AS ) return;
|
||||
assert( pExpr->op==TK_COLUMN );
|
||||
for(iSrc=0; iSrc<pTabList->nSrc; iSrc++){
|
||||
for(iSrc=0; pTabList && iSrc<pTabList->nSrc; iSrc++){
|
||||
if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break;
|
||||
}
|
||||
if( iSrc>=0 && iSrc<pTabList->nSrc ){
|
||||
if( iSrc>=0 && pTabList && iSrc<pTabList->nSrc ){
|
||||
pTab = pTabList->a[iSrc].pTab;
|
||||
}else{
|
||||
}else if( (pStack = pParse->trigStack)!=0 ){
|
||||
/* This must be an attempt to read the NEW or OLD pseudo-tables
|
||||
** of a trigger.
|
||||
*/
|
||||
TriggerStack *pStack; /* The stack of current triggers */
|
||||
pStack = pParse->trigStack;
|
||||
assert( pStack!=0 );
|
||||
assert( pExpr->iTable==pStack->newIdx || pExpr->iTable==pStack->oldIdx );
|
||||
pTab = pStack->pTab;
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
if( pTab==0 ) return;
|
||||
if( pExpr->iColumn>=0 ){
|
||||
@@ -170,7 +172,7 @@ int sqlite3AuthCheck(
|
||||
const char *zArg2,
|
||||
const char *zArg3
|
||||
){
|
||||
sqlite *db = pParse->db;
|
||||
sqlite3 *db = pParse->db;
|
||||
int rc;
|
||||
|
||||
/* Don't do any authorization checks if the database is initialising. */
|
||||
|
||||
+1807
-384
File diff suppressed because it is too large
Load Diff
+24
-4
@@ -13,7 +13,7 @@
|
||||
** subsystem. See comments in the source code for a detailed description
|
||||
** of what each interface routine does.
|
||||
**
|
||||
** @(#) $Id: btree.h,v 1.58 2004/07/23 00:01:39 drh Exp $
|
||||
** @(#) $Id: btree.h,v 1.64 2005/08/27 16:36:49 drh Exp $
|
||||
*/
|
||||
#ifndef _BTREE_H_
|
||||
#define _BTREE_H_
|
||||
@@ -23,6 +23,14 @@
|
||||
*/
|
||||
#define SQLITE_N_BTREE_META 10
|
||||
|
||||
/*
|
||||
** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
|
||||
** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
|
||||
*/
|
||||
#ifndef SQLITE_DEFAULT_AUTOVACUUM
|
||||
#define SQLITE_DEFAULT_AUTOVACUUM 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Forward declarations of structure
|
||||
*/
|
||||
@@ -38,17 +46,24 @@ int sqlite3BtreeOpen(
|
||||
|
||||
/* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
|
||||
** following values.
|
||||
**
|
||||
** NOTE: These values must match the corresponding PAGER_ values in
|
||||
** pager.h.
|
||||
*/
|
||||
#define BTREE_OMIT_JOURNAL 1 /* Do not use journal. No argument */
|
||||
#define BTREE_MEMORY 2 /* In-memory DB. No argument */
|
||||
#define BTREE_NO_READLOCK 2 /* Omit readlocks on readonly files */
|
||||
#define BTREE_MEMORY 4 /* In-memory DB. No argument */
|
||||
|
||||
int sqlite3BtreeClose(Btree*);
|
||||
int sqlite3BtreeSetBusyHandler(Btree*,BusyHandler*);
|
||||
int sqlite3BtreeSetCacheSize(Btree*,int);
|
||||
int sqlite3BtreeSetSafetyLevel(Btree*,int);
|
||||
int sqlite3BtreeSyncDisabled(Btree*);
|
||||
int sqlite3BtreeSetPageSize(Btree*,int,int);
|
||||
int sqlite3BtreeGetPageSize(Btree*);
|
||||
int sqlite3BtreeGetReserve(Btree*);
|
||||
int sqlite3BtreeSetAutoVacuum(Btree *, int);
|
||||
int sqlite3BtreeGetAutoVacuum(Btree *);
|
||||
int sqlite3BtreeBeginTrans(Btree*,int);
|
||||
int sqlite3BtreeCommit(Btree*);
|
||||
int sqlite3BtreeRollback(Btree*);
|
||||
@@ -59,6 +74,7 @@ int sqlite3BtreeCreateTable(Btree*, int*, int flags);
|
||||
int sqlite3BtreeIsInTrans(Btree*);
|
||||
int sqlite3BtreeIsInStmt(Btree*);
|
||||
int sqlite3BtreeSync(Btree*, const char *zMaster);
|
||||
int sqlite3BtreeReset(Btree *);
|
||||
|
||||
const char *sqlite3BtreeGetFilename(Btree *);
|
||||
const char *sqlite3BtreeGetDirname(Btree *);
|
||||
@@ -72,7 +88,7 @@ int sqlite3BtreeCopyFile(Btree *, Btree *);
|
||||
#define BTREE_ZERODATA 2 /* Table has keys only - no data */
|
||||
#define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */
|
||||
|
||||
int sqlite3BtreeDropTable(Btree*, int);
|
||||
int sqlite3BtreeDropTable(Btree*, int, int*);
|
||||
int sqlite3BtreeClearTable(Btree*, int);
|
||||
int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
|
||||
int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
|
||||
@@ -117,8 +133,12 @@ struct Pager *sqlite3BtreePager(Btree*);
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
|
||||
void sqlite3BtreeCursorList(Btree*);
|
||||
int sqlite3BtreePageDump(Btree*, int, int recursive);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
int sqlite3BtreePageDump(Btree*, int, int recursive);
|
||||
#else
|
||||
#define sqlite3BtreePageDump(X,Y,Z) SQLITE_OK
|
||||
#endif
|
||||
|
||||
#endif /* _BTREE_H_ */
|
||||
|
||||
+936
-582
File diff suppressed because it is too large
Load Diff
+305
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
** 2005 May 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 file contains functions used to access the internal hash tables
|
||||
** of user defined functions and collation sequences.
|
||||
**
|
||||
** $Id: callback.c,v 1.3 2005/08/14 01:20:38 drh Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Invoke the 'collation needed' callback to request a collation sequence
|
||||
** in the database text encoding of name zName, length nName.
|
||||
** If the collation sequence
|
||||
*/
|
||||
static void callCollNeeded(sqlite3 *db, const char *zName, int nName){
|
||||
assert( !db->xCollNeeded || !db->xCollNeeded16 );
|
||||
if( nName<0 ) nName = strlen(zName);
|
||||
if( db->xCollNeeded ){
|
||||
char *zExternal = sqliteStrNDup(zName, nName);
|
||||
if( !zExternal ) return;
|
||||
db->xCollNeeded(db->pCollNeededArg, db, (int)db->enc, zExternal);
|
||||
sqliteFree(zExternal);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
if( db->xCollNeeded16 ){
|
||||
char const *zExternal;
|
||||
sqlite3_value *pTmp = sqlite3GetTransientValue(db);
|
||||
sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF8, SQLITE_STATIC);
|
||||
zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
|
||||
if( !zExternal ) return;
|
||||
db->xCollNeeded16(db->pCollNeededArg, db, (int)db->enc, zExternal);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called if the collation factory fails to deliver a
|
||||
** collation function in the best encoding but there may be other versions
|
||||
** of this collation function (for other text encodings) available. Use one
|
||||
** of these instead if they exist. Avoid a UTF-8 <-> UTF-16 conversion if
|
||||
** possible.
|
||||
*/
|
||||
static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
|
||||
CollSeq *pColl2;
|
||||
char *z = pColl->zName;
|
||||
int n = strlen(z);
|
||||
int i;
|
||||
static const u8 aEnc[] = { SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8 };
|
||||
for(i=0; i<3; i++){
|
||||
pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, n, 0);
|
||||
if( pColl2->xCmp!=0 ){
|
||||
memcpy(pColl, pColl2, sizeof(CollSeq));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is responsible for invoking the collation factory callback
|
||||
** or substituting a collation sequence of a different encoding when the
|
||||
** requested collation sequence is not available in the database native
|
||||
** encoding.
|
||||
**
|
||||
** If it is not NULL, then pColl must point to the database native encoding
|
||||
** collation sequence with name zName, length nName.
|
||||
**
|
||||
** The return value is either the collation sequence to be used in database
|
||||
** db for collation type name zName, length nName, or NULL, if no collation
|
||||
** sequence can be found.
|
||||
*/
|
||||
CollSeq *sqlite3GetCollSeq(
|
||||
sqlite3* db,
|
||||
CollSeq *pColl,
|
||||
const char *zName,
|
||||
int nName
|
||||
){
|
||||
CollSeq *p;
|
||||
|
||||
p = pColl;
|
||||
if( !p ){
|
||||
p = sqlite3FindCollSeq(db, db->enc, zName, nName, 0);
|
||||
}
|
||||
if( !p || !p->xCmp ){
|
||||
/* No collation sequence of this type for this encoding is registered.
|
||||
** Call the collation factory to see if it can supply us with one.
|
||||
*/
|
||||
callCollNeeded(db, zName, nName);
|
||||
p = sqlite3FindCollSeq(db, db->enc, zName, nName, 0);
|
||||
}
|
||||
if( p && !p->xCmp && synthCollSeq(db, p) ){
|
||||
p = 0;
|
||||
}
|
||||
assert( !p || p->xCmp );
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called on a collation sequence before it is used to
|
||||
** check that it is defined. An undefined collation sequence exists when
|
||||
** a database is loaded that contains references to collation sequences
|
||||
** that have not been defined by sqlite3_create_collation() etc.
|
||||
**
|
||||
** If required, this routine calls the 'collation needed' callback to
|
||||
** request a definition of the collating sequence. If this doesn't work,
|
||||
** an equivalent collating sequence that uses a text encoding different
|
||||
** from the main database is substituted, if one is available.
|
||||
*/
|
||||
int sqlite3CheckCollSeq(Parse *pParse, CollSeq *pColl){
|
||||
if( pColl ){
|
||||
const char *zName = pColl->zName;
|
||||
CollSeq *p = sqlite3GetCollSeq(pParse->db, pColl, zName, -1);
|
||||
if( !p ){
|
||||
if( pParse->nErr==0 ){
|
||||
sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName);
|
||||
}
|
||||
pParse->nErr++;
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Locate and return an entry from the db.aCollSeq hash table. If the entry
|
||||
** specified by zName and nName is not found and parameter 'create' is
|
||||
** true, then create a new entry. Otherwise return NULL.
|
||||
**
|
||||
** Each pointer stored in the sqlite3.aCollSeq hash table contains an
|
||||
** array of three CollSeq structures. The first is the collation sequence
|
||||
** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be.
|
||||
**
|
||||
** Stored immediately after the three collation sequences is a copy of
|
||||
** the collation sequence name. A pointer to this string is stored in
|
||||
** each collation sequence structure.
|
||||
*/
|
||||
static CollSeq *findCollSeqEntry(
|
||||
sqlite3 *db,
|
||||
const char *zName,
|
||||
int nName,
|
||||
int create
|
||||
){
|
||||
CollSeq *pColl;
|
||||
if( nName<0 ) nName = strlen(zName);
|
||||
pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
|
||||
|
||||
if( 0==pColl && create ){
|
||||
pColl = sqliteMalloc( 3*sizeof(*pColl) + nName + 1 );
|
||||
if( pColl ){
|
||||
CollSeq *pDel = 0;
|
||||
pColl[0].zName = (char*)&pColl[3];
|
||||
pColl[0].enc = SQLITE_UTF8;
|
||||
pColl[1].zName = (char*)&pColl[3];
|
||||
pColl[1].enc = SQLITE_UTF16LE;
|
||||
pColl[2].zName = (char*)&pColl[3];
|
||||
pColl[2].enc = SQLITE_UTF16BE;
|
||||
memcpy(pColl[0].zName, zName, nName);
|
||||
pColl[0].zName[nName] = 0;
|
||||
pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
|
||||
|
||||
/* If a malloc() failure occured in sqlite3HashInsert(), it will
|
||||
** return the pColl pointer to be deleted (because it wasn't added
|
||||
** to the hash table).
|
||||
*/
|
||||
assert( !pDel || (sqlite3_malloc_failed && pDel==pColl) );
|
||||
sqliteFree(pDel);
|
||||
}
|
||||
}
|
||||
return pColl;
|
||||
}
|
||||
|
||||
/*
|
||||
** Parameter zName points to a UTF-8 encoded string nName bytes long.
|
||||
** Return the CollSeq* pointer for the collation sequence named zName
|
||||
** for the encoding 'enc' from the database 'db'.
|
||||
**
|
||||
** If the entry specified is not found and 'create' is true, then create a
|
||||
** new entry. Otherwise return NULL.
|
||||
*/
|
||||
CollSeq *sqlite3FindCollSeq(
|
||||
sqlite3 *db,
|
||||
u8 enc,
|
||||
const char *zName,
|
||||
int nName,
|
||||
int create
|
||||
){
|
||||
CollSeq *pColl = findCollSeqEntry(db, zName, nName, create);
|
||||
assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
|
||||
assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
|
||||
if( pColl ) pColl += enc-1;
|
||||
return pColl;
|
||||
}
|
||||
|
||||
/*
|
||||
** Locate a user function given a name, a number of arguments and a flag
|
||||
** indicating whether the function prefers UTF-16 over UTF-8. Return a
|
||||
** pointer to the FuncDef structure that defines that function, or return
|
||||
** NULL if the function does not exist.
|
||||
**
|
||||
** If the createFlag argument is true, then a new (blank) FuncDef
|
||||
** structure is created and liked into the "db" structure if a
|
||||
** no matching function previously existed. When createFlag is true
|
||||
** and the nArg parameter is -1, then only a function that accepts
|
||||
** any number of arguments will be returned.
|
||||
**
|
||||
** If createFlag is false and nArg is -1, then the first valid
|
||||
** function found is returned. A function is valid if either xFunc
|
||||
** or xStep is non-zero.
|
||||
**
|
||||
** If createFlag is false, then a function with the required name and
|
||||
** number of arguments may be returned even if the eTextRep flag does not
|
||||
** match that requested.
|
||||
*/
|
||||
FuncDef *sqlite3FindFunction(
|
||||
sqlite3 *db, /* An open database */
|
||||
const char *zName, /* Name of the function. Not null-terminated */
|
||||
int nName, /* Number of characters in the name */
|
||||
int nArg, /* Number of arguments. -1 means any number */
|
||||
u8 enc, /* Preferred text encoding */
|
||||
int createFlag /* Create new entry if true and does not otherwise exist */
|
||||
){
|
||||
FuncDef *p; /* Iterator variable */
|
||||
FuncDef *pFirst; /* First function with this name */
|
||||
FuncDef *pBest = 0; /* Best match found so far */
|
||||
int bestmatch = 0;
|
||||
|
||||
|
||||
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
|
||||
if( nArg<-1 ) nArg = -1;
|
||||
|
||||
pFirst = (FuncDef*)sqlite3HashFind(&db->aFunc, zName, nName);
|
||||
for(p=pFirst; p; p=p->pNext){
|
||||
/* During the search for the best function definition, bestmatch is set
|
||||
** as follows to indicate the quality of the match with the definition
|
||||
** pointed to by pBest:
|
||||
**
|
||||
** 0: pBest is NULL. No match has been found.
|
||||
** 1: A variable arguments function that prefers UTF-8 when a UTF-16
|
||||
** encoding is requested, or vice versa.
|
||||
** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is
|
||||
** requested, or vice versa.
|
||||
** 3: A variable arguments function using the same text encoding.
|
||||
** 4: A function with the exact number of arguments requested that
|
||||
** prefers UTF-8 when a UTF-16 encoding is requested, or vice versa.
|
||||
** 5: A function with the exact number of arguments requested that
|
||||
** prefers UTF-16LE when UTF-16BE is requested, or vice versa.
|
||||
** 6: An exact match.
|
||||
**
|
||||
** A larger value of 'matchqual' indicates a more desirable match.
|
||||
*/
|
||||
if( p->nArg==-1 || p->nArg==nArg || nArg==-1 ){
|
||||
int match = 1; /* Quality of this match */
|
||||
if( p->nArg==nArg || nArg==-1 ){
|
||||
match = 4;
|
||||
}
|
||||
if( enc==p->iPrefEnc ){
|
||||
match += 2;
|
||||
}
|
||||
else if( (enc==SQLITE_UTF16LE && p->iPrefEnc==SQLITE_UTF16BE) ||
|
||||
(enc==SQLITE_UTF16BE && p->iPrefEnc==SQLITE_UTF16LE) ){
|
||||
match += 1;
|
||||
}
|
||||
|
||||
if( match>bestmatch ){
|
||||
pBest = p;
|
||||
bestmatch = match;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If the createFlag parameter is true, and the seach did not reveal an
|
||||
** exact match for the name, number of arguments and encoding, then add a
|
||||
** new entry to the hash table and return it.
|
||||
*/
|
||||
if( createFlag && bestmatch<6 &&
|
||||
(pBest = sqliteMalloc(sizeof(*pBest)+nName)) ){
|
||||
pBest->nArg = nArg;
|
||||
pBest->pNext = pFirst;
|
||||
pBest->iPrefEnc = enc;
|
||||
memcpy(pBest->zName, zName, nName);
|
||||
pBest->zName[nName] = 0;
|
||||
if( pBest==sqlite3HashInsert(&db->aFunc,pBest->zName,nName,(void*)pBest) ){
|
||||
sqliteFree(pBest);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){
|
||||
return pBest;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
** 2001 September 15
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** An tokenizer for SQL
|
||||
**
|
||||
** This file contains C code that implements the sqlite3_complete() API.
|
||||
** This code used to be part of the tokenizer.c source file. But by
|
||||
** separating it out, the code will be automatically omitted from
|
||||
** static links that do not use it.
|
||||
**
|
||||
** $Id: complete.c,v 1.1 2005/08/14 17:53:21 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#ifndef SQLITE_OMIT_COMPLETE
|
||||
|
||||
/*
|
||||
** This is defined in tokenize.c. We just have to import the definition.
|
||||
*/
|
||||
extern const char sqlite3IsIdChar[];
|
||||
#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20]))
|
||||
|
||||
|
||||
/*
|
||||
** Token types used by the sqlite3_complete() routine. See the header
|
||||
** comments on that procedure for additional information.
|
||||
*/
|
||||
#define tkSEMI 0
|
||||
#define tkWS 1
|
||||
#define tkOTHER 2
|
||||
#define tkEXPLAIN 3
|
||||
#define tkCREATE 4
|
||||
#define tkTEMP 5
|
||||
#define tkTRIGGER 6
|
||||
#define tkEND 7
|
||||
|
||||
/*
|
||||
** Return TRUE if the given SQL string ends in a semicolon.
|
||||
**
|
||||
** Special handling is require for CREATE TRIGGER statements.
|
||||
** Whenever the CREATE TRIGGER keywords are seen, the statement
|
||||
** must end with ";END;".
|
||||
**
|
||||
** This implementation uses a state machine with 7 states:
|
||||
**
|
||||
** (0) START At the beginning or end of an SQL statement. This routine
|
||||
** returns 1 if it ends in the START state and 0 if it ends
|
||||
** in any other state.
|
||||
**
|
||||
** (1) NORMAL We are in the middle of statement which ends with a single
|
||||
** semicolon.
|
||||
**
|
||||
** (2) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
|
||||
** a statement.
|
||||
**
|
||||
** (3) CREATE The keyword CREATE has been seen at the beginning of a
|
||||
** statement, possibly preceeded by EXPLAIN and/or followed by
|
||||
** TEMP or TEMPORARY
|
||||
**
|
||||
** (4) TRIGGER We are in the middle of a trigger definition that must be
|
||||
** ended by a semicolon, the keyword END, and another semicolon.
|
||||
**
|
||||
** (5) SEMI We've seen the first semicolon in the ";END;" that occurs at
|
||||
** the end of a trigger definition.
|
||||
**
|
||||
** (6) END We've seen the ";END" of the ";END;" that occurs at the end
|
||||
** of a trigger difinition.
|
||||
**
|
||||
** Transitions between states above are determined by tokens extracted
|
||||
** from the input. The following tokens are significant:
|
||||
**
|
||||
** (0) tkSEMI A semicolon.
|
||||
** (1) tkWS Whitespace
|
||||
** (2) tkOTHER Any other SQL token.
|
||||
** (3) tkEXPLAIN The "explain" keyword.
|
||||
** (4) tkCREATE The "create" keyword.
|
||||
** (5) tkTEMP The "temp" or "temporary" keyword.
|
||||
** (6) tkTRIGGER The "trigger" keyword.
|
||||
** (7) tkEND The "end" keyword.
|
||||
**
|
||||
** Whitespace never causes a state transition and is always ignored.
|
||||
**
|
||||
** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed
|
||||
** to recognize the end of a trigger can be omitted. All we have to do
|
||||
** is look for a semicolon that is not part of an string or comment.
|
||||
*/
|
||||
int sqlite3_complete(const char *zSql){
|
||||
u8 state = 0; /* Current state, using numbers defined in header comment */
|
||||
u8 token; /* Value of the next token */
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/* A complex statement machine used to detect the end of a CREATE TRIGGER
|
||||
** statement. This is the normal case.
|
||||
*/
|
||||
static const u8 trans[7][8] = {
|
||||
/* Token: */
|
||||
/* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
|
||||
/* 0 START: */ { 0, 0, 1, 2, 3, 1, 1, 1, },
|
||||
/* 1 NORMAL: */ { 0, 1, 1, 1, 1, 1, 1, 1, },
|
||||
/* 2 EXPLAIN: */ { 0, 2, 1, 1, 3, 1, 1, 1, },
|
||||
/* 3 CREATE: */ { 0, 3, 1, 1, 1, 3, 4, 1, },
|
||||
/* 4 TRIGGER: */ { 5, 4, 4, 4, 4, 4, 4, 4, },
|
||||
/* 5 SEMI: */ { 5, 5, 4, 4, 4, 4, 4, 6, },
|
||||
/* 6 END: */ { 0, 6, 4, 4, 4, 4, 4, 4, },
|
||||
};
|
||||
#else
|
||||
/* If triggers are not suppored by this compile then the statement machine
|
||||
** used to detect the end of a statement is much simplier
|
||||
*/
|
||||
static const u8 trans[2][3] = {
|
||||
/* Token: */
|
||||
/* State: ** SEMI WS OTHER */
|
||||
/* 0 START: */ { 0, 0, 1, },
|
||||
/* 1 NORMAL: */ { 0, 1, 1, },
|
||||
};
|
||||
#endif /* SQLITE_OMIT_TRIGGER */
|
||||
|
||||
while( *zSql ){
|
||||
switch( *zSql ){
|
||||
case ';': { /* A semicolon */
|
||||
token = tkSEMI;
|
||||
break;
|
||||
}
|
||||
case ' ':
|
||||
case '\r':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\f': { /* White space is ignored */
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '/': { /* C-style comments */
|
||||
if( zSql[1]!='*' ){
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
zSql += 2;
|
||||
while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
|
||||
if( zSql[0]==0 ) return 0;
|
||||
zSql++;
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '-': { /* SQL-style comments from "--" to end of line */
|
||||
if( zSql[1]!='-' ){
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
while( *zSql && *zSql!='\n' ){ zSql++; }
|
||||
if( *zSql==0 ) return state==0;
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '[': { /* Microsoft-style identifiers in [...] */
|
||||
zSql++;
|
||||
while( *zSql && *zSql!=']' ){ zSql++; }
|
||||
if( *zSql==0 ) return 0;
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
case '`': /* Grave-accent quoted symbols used by MySQL */
|
||||
case '"': /* single- and double-quoted strings */
|
||||
case '\'': {
|
||||
int c = *zSql;
|
||||
zSql++;
|
||||
while( *zSql && *zSql!=c ){ zSql++; }
|
||||
if( *zSql==0 ) return 0;
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
int c;
|
||||
if( IdChar((u8)*zSql) ){
|
||||
/* Keywords and unquoted identifiers */
|
||||
int nId;
|
||||
for(nId=1; IdChar(zSql[nId]); nId++){}
|
||||
#ifdef SQLITE_OMIT_TRIGGER
|
||||
token = tkOTHER;
|
||||
#else
|
||||
switch( *zSql ){
|
||||
case 'c': case 'C': {
|
||||
if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
|
||||
token = tkCREATE;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 't': case 'T': {
|
||||
if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
|
||||
token = tkTRIGGER;
|
||||
}else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
|
||||
token = tkTEMP;
|
||||
}else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
|
||||
token = tkTEMP;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'e': case 'E': {
|
||||
if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
|
||||
token = tkEND;
|
||||
}else
|
||||
#ifndef SQLITE_OMIT_EXPLAIN
|
||||
if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
|
||||
token = tkEXPLAIN;
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_OMIT_TRIGGER */
|
||||
zSql += nId-1;
|
||||
}else{
|
||||
/* Operators and special symbols */
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
state = trans[state][token];
|
||||
zSql++;
|
||||
}
|
||||
return state==0;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** This routine is the same as the sqlite3_complete() routine described
|
||||
** above, except that the parameter is required to be UTF-16 encoded, not
|
||||
** UTF-8.
|
||||
*/
|
||||
int sqlite3_complete16(const void *zSql){
|
||||
sqlite3_value *pVal;
|
||||
char const *zSql8;
|
||||
int rc = 0;
|
||||
|
||||
pVal = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
if( zSql8 ){
|
||||
rc = sqlite3_complete(zSql8);
|
||||
}
|
||||
sqlite3ValueFree(pVal);
|
||||
return rc;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
#endif /* SQLITE_OMIT_COMPLETE */
|
||||
+120
-17
@@ -16,7 +16,7 @@
|
||||
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: date.c,v 1.34 2004/08/17 10:42:55 drh Exp $
|
||||
** $Id: date.c,v 1.45 2005/06/25 18:42:14 drh Exp $
|
||||
**
|
||||
** NOTES:
|
||||
**
|
||||
@@ -47,8 +47,8 @@
|
||||
** Willmann-Bell, Inc
|
||||
** Richmond, Virginia (USA)
|
||||
*/
|
||||
#include "os.h"
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
@@ -124,11 +124,7 @@ static int getDigits(const char *zDate, ...){
|
||||
** Read text from z[] and convert into a floating point number. Return
|
||||
** the number of digits converted.
|
||||
*/
|
||||
static int getValue(const char *z, double *pR){
|
||||
const char *zEnd;
|
||||
*pR = sqlite3AtoF(z, &zEnd);
|
||||
return zEnd - z;
|
||||
}
|
||||
#define getValue sqlite3AtoF
|
||||
|
||||
/*
|
||||
** Parse a timezone extension on the end of a date-time.
|
||||
@@ -272,7 +268,7 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
||||
return 1;
|
||||
}
|
||||
zDate += 10;
|
||||
while( isspace(*(u8*)zDate) ){ zDate++; }
|
||||
while( isspace(*(u8*)zDate) || 'T'==*(u8*)zDate ){ zDate++; }
|
||||
if( parseHhMmSs(zDate, p)==0 ){
|
||||
/* We got the time */
|
||||
}else if( *zDate==0 ){
|
||||
@@ -315,14 +311,12 @@ static int parseDateOrTime(const char *zDate, DateTime *p){
|
||||
return 0;
|
||||
}else if( sqlite3StrICmp(zDate,"now")==0){
|
||||
double r;
|
||||
if( sqlite3OsCurrentTime(&r)==0 ){
|
||||
p->rJD = r;
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
sqlite3OsCurrentTime(&r);
|
||||
p->rJD = r;
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}else if( sqlite3IsNumber(zDate, 0, SQLITE_UTF8) ){
|
||||
p->rJD = sqlite3AtoF(zDate, 0);
|
||||
getValue(zDate, &p->rJD);
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -862,17 +856,108 @@ static void strftimeFunc(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** current_time()
|
||||
**
|
||||
** This function returns the same value as time('now').
|
||||
*/
|
||||
static void ctimeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_value *pVal = sqlite3ValueNew();
|
||||
if( pVal ){
|
||||
sqlite3ValueSetStr(pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC);
|
||||
timeFunc(context, 1, &pVal);
|
||||
sqlite3ValueFree(pVal);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** current_date()
|
||||
**
|
||||
** This function returns the same value as date('now').
|
||||
*/
|
||||
static void cdateFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_value *pVal = sqlite3ValueNew();
|
||||
if( pVal ){
|
||||
sqlite3ValueSetStr(pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC);
|
||||
dateFunc(context, 1, &pVal);
|
||||
sqlite3ValueFree(pVal);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** current_timestamp()
|
||||
**
|
||||
** This function returns the same value as datetime('now').
|
||||
*/
|
||||
static void ctimestampFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_value *pVal = sqlite3ValueNew();
|
||||
if( pVal ){
|
||||
sqlite3ValueSetStr(pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC);
|
||||
datetimeFunc(context, 1, &pVal);
|
||||
sqlite3ValueFree(pVal);
|
||||
}
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */
|
||||
|
||||
#ifdef SQLITE_OMIT_DATETIME_FUNCS
|
||||
/*
|
||||
** If the library is compiled to omit the full-scale date and time
|
||||
** handling (to get a smaller binary), the following minimal version
|
||||
** of the functions current_time(), current_date() and current_timestamp()
|
||||
** are included instead. This is to support column declarations that
|
||||
** include "DEFAULT CURRENT_TIME" etc.
|
||||
**
|
||||
** This function uses the C-library functions time(), gmtime()
|
||||
** and strftime(). The format string to pass to strftime() is supplied
|
||||
** as the user-data for the function.
|
||||
*/
|
||||
static void currentTimeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
time_t t;
|
||||
char *zFormat = (char *)sqlite3_user_data(context);
|
||||
char zBuf[20];
|
||||
|
||||
time(&t);
|
||||
#ifdef SQLITE_TEST
|
||||
{
|
||||
extern int sqlite3_current_time; /* See os_XXX.c */
|
||||
if( sqlite3_current_time ){
|
||||
t = sqlite3_current_time;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
sqlite3OsEnterMutex();
|
||||
strftime(zBuf, 20, zFormat, gmtime(&t));
|
||||
sqlite3OsLeaveMutex();
|
||||
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This function registered all of the above C functions as SQL
|
||||
** functions. This should be the only routine in this file with
|
||||
** external linkage.
|
||||
*/
|
||||
void sqlite3RegisterDateTimeFunctions(sqlite *db){
|
||||
void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
static struct {
|
||||
static const struct {
|
||||
char *zName;
|
||||
int nArg;
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
|
||||
@@ -882,6 +967,9 @@ void sqlite3RegisterDateTimeFunctions(sqlite *db){
|
||||
{ "time", -1, timeFunc },
|
||||
{ "datetime", -1, datetimeFunc },
|
||||
{ "strftime", -1, strftimeFunc },
|
||||
{ "current_time", 0, ctimeFunc },
|
||||
{ "current_timestamp", 0, ctimestampFunc },
|
||||
{ "current_date", 0, cdateFunc },
|
||||
};
|
||||
int i;
|
||||
|
||||
@@ -889,5 +977,20 @@ void sqlite3RegisterDateTimeFunctions(sqlite *db){
|
||||
sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
|
||||
SQLITE_UTF8, 0, aFuncs[i].xFunc, 0, 0);
|
||||
}
|
||||
#else
|
||||
static const struct {
|
||||
char *zName;
|
||||
char *zFormat;
|
||||
} aFuncs[] = {
|
||||
{ "current_time", "%H:%M:%S" },
|
||||
{ "current_date", "%Y-%m-%d" },
|
||||
{ "current_timestamp", "%Y-%m-%d %H:%M:%S" }
|
||||
};
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
|
||||
sqlite3_create_function(db, aFuncs[i].zName, 0, SQLITE_UTF8,
|
||||
aFuncs[i].zFormat, currentTimeFunc, 0, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
+98
-62
@@ -10,9 +10,9 @@
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle DELETE FROM statements.
|
||||
** in order to generate code for DELETE FROM statements.
|
||||
**
|
||||
** $Id: delete.c,v 1.79 2004/08/31 13:45:12 drh Exp $
|
||||
** $Id: delete.c,v 1.111 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -27,7 +27,11 @@ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
struct SrcList_item *pItem;
|
||||
for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
|
||||
pTab = sqlite3LocateTable(pParse, pItem->zName, pItem->zDatabase);
|
||||
sqlite3DeleteTable(pParse->db, pItem->pTab);
|
||||
pItem->pTab = pTab;
|
||||
if( pTab ){
|
||||
pTab->nRef++;
|
||||
}
|
||||
}
|
||||
return pTab;
|
||||
}
|
||||
@@ -38,19 +42,41 @@ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
** writable return 0;
|
||||
*/
|
||||
int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
if( pTab->readOnly ){
|
||||
if( pTab->readOnly && (pParse->db->flags & SQLITE_WriteSchema)==0
|
||||
&& pParse->nested==0 ){
|
||||
sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
|
||||
return 1;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_VIEW
|
||||
if( !viewOk && pTab->pSelect ){
|
||||
sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Process a DELETE FROM statement.
|
||||
** Generate code that will open a table for reading.
|
||||
*/
|
||||
void sqlite3OpenTableForReading(
|
||||
Vdbe *v, /* Generate code into this VDBE */
|
||||
int iCur, /* The cursor number of the table */
|
||||
Table *pTab /* The table to be opened */
|
||||
){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
VdbeComment((v, "# %s", pTab->zName));
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Generate code for a DELETE FROM statement.
|
||||
**
|
||||
** DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;
|
||||
** \________/ \________________/
|
||||
** pTabList pWhere
|
||||
*/
|
||||
void sqlite3DeleteFrom(
|
||||
Parse *pParse, /* The parser context */
|
||||
@@ -65,18 +91,18 @@ void sqlite3DeleteFrom(
|
||||
WhereInfo *pWInfo; /* Information about the WHERE clause */
|
||||
Index *pIdx; /* For looping over indices of the table */
|
||||
int iCur; /* VDBE Cursor number for pTab */
|
||||
sqlite *db; /* Main database structure */
|
||||
int isView; /* True if attempting to delete from a view */
|
||||
sqlite3 *db; /* Main database structure */
|
||||
AuthContext sContext; /* Authorization context */
|
||||
int oldIdx = -1; /* Cursor for the OLD table of AFTER triggers */
|
||||
NameContext sNC; /* Name context to resolve expressions in */
|
||||
|
||||
int row_triggers_exist = 0; /* True if any triggers exist */
|
||||
int before_triggers; /* True if there are BEFORE triggers */
|
||||
int after_triggers; /* True if there are AFTER triggers */
|
||||
int oldIdx = -1; /* Cursor for the OLD table of AFTER triggers */
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* True if attempting to delete from a view */
|
||||
int triggers_exist = 0; /* True if any triggers exist */
|
||||
#endif
|
||||
|
||||
sContext.pParse = 0;
|
||||
if( pParse->nErr || sqlite3_malloc_failed ){
|
||||
pTabList = 0;
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
db = pParse->db;
|
||||
@@ -89,13 +115,23 @@ void sqlite3DeleteFrom(
|
||||
*/
|
||||
pTab = sqlite3SrcListLookup(pParse, pTabList);
|
||||
if( pTab==0 ) goto delete_from_cleanup;
|
||||
before_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger,
|
||||
TK_DELETE, TK_BEFORE, TK_ROW, 0);
|
||||
after_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger,
|
||||
TK_DELETE, TK_AFTER, TK_ROW, 0);
|
||||
row_triggers_exist = before_triggers || after_triggers;
|
||||
|
||||
/* Figure out if we have any triggers and if the table being
|
||||
** deleted from is a view
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0);
|
||||
isView = pTab->pSelect!=0;
|
||||
if( sqlite3IsReadOnly(pParse, pTab, before_triggers) ){
|
||||
#else
|
||||
# define triggers_exist 0
|
||||
# define isView 0
|
||||
#endif
|
||||
#ifdef SQLITE_OMIT_VIEW
|
||||
# undef isView
|
||||
# define isView 0
|
||||
#endif
|
||||
|
||||
if( sqlite3IsReadOnly(pParse, pTab, triggers_exist) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
assert( pTab->iDb<db->nDb );
|
||||
@@ -112,15 +148,18 @@ void sqlite3DeleteFrom(
|
||||
|
||||
/* Allocate a cursor used to store the old.* data for a trigger.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist ){
|
||||
oldIdx = pParse->nTab++;
|
||||
}
|
||||
|
||||
/* Resolve the column names in all the expressions.
|
||||
/* Resolve the column names in the WHERE clause.
|
||||
*/
|
||||
assert( pTabList->nSrc==1 );
|
||||
iCur = pTabList->a[0].iCursor = pParse->nTab++;
|
||||
if( sqlite3ExprResolveAndCheck(pParse, pTabList, 0, pWhere, 0, 0) ){
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pParse;
|
||||
sNC.pSrcList = pTabList;
|
||||
if( sqlite3ExprResolveNames(&sNC, pWhere) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
|
||||
@@ -136,15 +175,15 @@ void sqlite3DeleteFrom(
|
||||
if( v==0 ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, row_triggers_exist, pTab->iDb);
|
||||
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, triggers_exist, pTab->iDb);
|
||||
|
||||
/* If we are trying to delete from a view, construct that view into
|
||||
** a temporary table.
|
||||
/* If we are trying to delete from a view, realize that view into
|
||||
** a ephemeral table.
|
||||
*/
|
||||
if( isView ){
|
||||
Select *pView = sqlite3SelectDup(pTab->pSelect);
|
||||
sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0);
|
||||
sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(pView);
|
||||
}
|
||||
|
||||
@@ -159,16 +198,14 @@ void sqlite3DeleteFrom(
|
||||
** It is easier just to erase the whole table. Note, however, that
|
||||
** this means that the row change count will be incorrect.
|
||||
*/
|
||||
if( pWhere==0 && !row_triggers_exist ){
|
||||
if( pWhere==0 && !triggers_exist ){
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
/* If counting rows deleted, just count the total number of
|
||||
** entries in the table. */
|
||||
int endOfLoop = sqlite3VdbeMakeLabel(v);
|
||||
int addr;
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, sqlite3VdbeCurrentAddr(v)+2);
|
||||
addr = sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
@@ -197,12 +234,13 @@ void sqlite3DeleteFrom(
|
||||
|
||||
/* Begin the database scan
|
||||
*/
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 1, 0);
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0);
|
||||
if( pWInfo==0 ) goto delete_from_cleanup;
|
||||
|
||||
/* Remember the key of every item to be deleted.
|
||||
/* Remember the rowid of every item to be deleted.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0);
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
}
|
||||
@@ -213,7 +251,7 @@ void sqlite3DeleteFrom(
|
||||
|
||||
/* Open the pseudo-table used to store OLD if there are triggers.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist ){
|
||||
sqlite3VdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, oldIdx, pTab->nCol);
|
||||
}
|
||||
@@ -222,37 +260,34 @@ void sqlite3DeleteFrom(
|
||||
** database scan. We have to delete items after the scan is complete
|
||||
** because deleting an item can change the scan order.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
end = sqlite3VdbeMakeLabel(v);
|
||||
|
||||
/* This is the beginning of the delete loop when there are
|
||||
** row triggers.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
if( triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
|
||||
sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TK_BEFORE, pTab, -1,
|
||||
oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
|
||||
addr);
|
||||
(void)sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TRIGGER_BEFORE, pTab,
|
||||
-1, oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
|
||||
addr);
|
||||
}
|
||||
|
||||
if( !isView ){
|
||||
/* Open cursors for the table we are deleting from and all its
|
||||
** indices. If there are row triggers, this happens inside the
|
||||
** OP_ListRead loop because the cursor have to all be closed
|
||||
** OP_FifoRead loop because the cursor have to all be closed
|
||||
** before the trigger fires. If there are no row triggers, the
|
||||
** cursors are opened only once on the outside the loop.
|
||||
*/
|
||||
@@ -260,48 +295,48 @@ void sqlite3DeleteFrom(
|
||||
|
||||
/* This is the beginning of the delete loop when there are no
|
||||
** row triggers */
|
||||
if( !row_triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end);
|
||||
if( !triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end);
|
||||
}
|
||||
|
||||
/* Delete the row */
|
||||
sqlite3GenerateRowDelete(db, v, pTab, iCur, 1);
|
||||
sqlite3GenerateRowDelete(db, v, pTab, iCur, pParse->nested==0);
|
||||
}
|
||||
|
||||
/* If there are row triggers, close all cursors then invoke
|
||||
** the AFTER triggers
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist ){
|
||||
if( !isView ){
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1,
|
||||
(void)sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TRIGGER_AFTER, pTab, -1,
|
||||
oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
|
||||
addr);
|
||||
addr);
|
||||
}
|
||||
|
||||
/* End of the delete loop */
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqlite3VdbeResolveLabel(v, end);
|
||||
sqlite3VdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
|
||||
/* Close the cursors after the loop if there are no row triggers */
|
||||
if( !row_triggers_exist ){
|
||||
if( !triggers_exist ){
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
}
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
|
||||
/*
|
||||
** Return the number of rows that were deleted.
|
||||
** Return the number of rows that were deleted. If this routine is
|
||||
** generating code because of a call to sqlite3NestedParse(), do not
|
||||
** invoke the callback function.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "rows deleted", P3_STATIC);
|
||||
@@ -335,7 +370,7 @@ delete_from_cleanup:
|
||||
** entries that point to that record.
|
||||
*/
|
||||
void sqlite3GenerateRowDelete(
|
||||
sqlite *db, /* The database containing the index */
|
||||
sqlite3 *db, /* The database containing the index */
|
||||
Vdbe *v, /* Generate code into this VDBE */
|
||||
Table *pTab, /* Table containing the row to be deleted */
|
||||
int iCur, /* Cursor number for the table */
|
||||
@@ -345,7 +380,7 @@ void sqlite3GenerateRowDelete(
|
||||
addr = sqlite3VdbeAddOp(v, OP_NotExists, iCur, 0);
|
||||
sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
|
||||
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -365,7 +400,7 @@ void sqlite3GenerateRowDelete(
|
||||
** deleted.
|
||||
*/
|
||||
void sqlite3GenerateRowIndexDelete(
|
||||
sqlite *db, /* The database containing the index */
|
||||
sqlite3 *db, /* The database containing the index */
|
||||
Vdbe *v, /* Generate code into this VDBE */
|
||||
Table *pTab, /* Table containing the row to be deleted */
|
||||
int iCur, /* Cursor number for the table */
|
||||
@@ -395,15 +430,16 @@ void sqlite3GenerateIndexKey(
|
||||
int j;
|
||||
Table *pTab = pIdx->pTable;
|
||||
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
for(j=0; j<pIdx->nColumn; j++){
|
||||
int idx = pIdx->aiColumn[j];
|
||||
if( idx==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, j, 0);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, idx);
|
||||
sqlite3ColumnDefault(v, pTab, idx);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24));
|
||||
sqlite3VdbeAddOp(v, OP_MakeIdxRec, pIdx->nColumn, 0);
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
}
|
||||
|
||||
-257
@@ -1,257 +0,0 @@
|
||||
/*
|
||||
** 2002 April 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.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains helper routines used to translate binary data into
|
||||
** a null-terminated string (suitable for use in SQLite) and back again.
|
||||
** These are convenience routines for use by people who want to store binary
|
||||
** data in an SQLite database. The code in this file is not used by any other
|
||||
** part of the SQLite library.
|
||||
**
|
||||
** $Id: encode.c,v 1.13 2004/05/08 08:23:24 danielk1977 Exp $
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
** How This Encoder Works
|
||||
**
|
||||
** The output is allowed to contain any character except 0x27 (') and
|
||||
** 0x00. This is accomplished by using an escape character to encode
|
||||
** 0x27 and 0x00 as a two-byte sequence. The escape character is always
|
||||
** 0x01. An 0x00 is encoded as the two byte sequence 0x01 0x01. The
|
||||
** 0x27 character is encoded as the two byte sequence 0x01 0x28. Finally,
|
||||
** the escape character itself is encoded as the two-character sequence
|
||||
** 0x01 0x02.
|
||||
**
|
||||
** To summarize, the encoder works by using an escape sequences as follows:
|
||||
**
|
||||
** 0x00 -> 0x01 0x01
|
||||
** 0x01 -> 0x01 0x02
|
||||
** 0x27 -> 0x01 0x28
|
||||
**
|
||||
** If that were all the encoder did, it would work, but in certain cases
|
||||
** it could double the size of the encoded string. For example, to
|
||||
** encode a string of 100 0x27 characters would require 100 instances of
|
||||
** the 0x01 0x03 escape sequence resulting in a 200-character output.
|
||||
** We would prefer to keep the size of the encoded string smaller than
|
||||
** this.
|
||||
**
|
||||
** To minimize the encoding size, we first add a fixed offset value to each
|
||||
** byte in the sequence. The addition is modulo 256. (That is to say, if
|
||||
** the sum of the original character value and the offset exceeds 256, then
|
||||
** the higher order bits are truncated.) The offset is chosen to minimize
|
||||
** the number of characters in the string that need to be escaped. For
|
||||
** example, in the case above where the string was composed of 100 0x27
|
||||
** characters, the offset might be 0x01. Each of the 0x27 characters would
|
||||
** then be converted into an 0x28 character which would not need to be
|
||||
** escaped at all and so the 100 character input string would be converted
|
||||
** into just 100 characters of output. Actually 101 characters of output -
|
||||
** we have to record the offset used as the first byte in the sequence so
|
||||
** that the string can be decoded. Since the offset value is stored as
|
||||
** part of the output string and the output string is not allowed to contain
|
||||
** characters 0x00 or 0x27, the offset cannot be 0x00 or 0x27.
|
||||
**
|
||||
** Here, then, are the encoding steps:
|
||||
**
|
||||
** (1) Choose an offset value and make it the first character of
|
||||
** output.
|
||||
**
|
||||
** (2) Copy each input character into the output buffer, one by
|
||||
** one, adding the offset value as you copy.
|
||||
**
|
||||
** (3) If the value of an input character plus offset is 0x00, replace
|
||||
** that one character by the two-character sequence 0x01 0x01.
|
||||
** If the sum is 0x01, replace it with 0x01 0x02. If the sum
|
||||
** is 0x27, replace it with 0x01 0x03.
|
||||
**
|
||||
** (4) Put a 0x00 terminator at the end of the output.
|
||||
**
|
||||
** Decoding is obvious:
|
||||
**
|
||||
** (5) Copy encoded characters except the first into the decode
|
||||
** buffer. Set the first encoded character aside for use as
|
||||
** the offset in step 7 below.
|
||||
**
|
||||
** (6) Convert each 0x01 0x01 sequence into a single character 0x00.
|
||||
** Convert 0x01 0x02 into 0x01. Convert 0x01 0x28 into 0x27.
|
||||
**
|
||||
** (7) Subtract the offset value that was the first character of
|
||||
** the encoded buffer from all characters in the output buffer.
|
||||
**
|
||||
** The only tricky part is step (1) - how to compute an offset value to
|
||||
** minimize the size of the output buffer. This is accomplished by testing
|
||||
** all offset values and picking the one that results in the fewest number
|
||||
** of escapes. To do that, we first scan the entire input and count the
|
||||
** number of occurances of each character value in the input. Suppose
|
||||
** the number of 0x00 characters is N(0), the number of occurances of 0x01
|
||||
** is N(1), and so forth up to the number of occurances of 0xff is N(255).
|
||||
** An offset of 0 is not allowed so we don't have to test it. The number
|
||||
** of escapes required for an offset of 1 is N(1)+N(2)+N(40). The number
|
||||
** of escapes required for an offset of 2 is N(2)+N(3)+N(41). And so forth.
|
||||
** In this way we find the offset that gives the minimum number of escapes,
|
||||
** and thus minimizes the length of the output string.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Encode a binary buffer "in" of size n bytes so that it contains
|
||||
** no instances of characters '\'' or '\000'. The output is
|
||||
** null-terminated and can be used as a string value in an INSERT
|
||||
** or UPDATE statement. Use sqlite_decode_binary() to convert the
|
||||
** string back into its original binary.
|
||||
**
|
||||
** The result is written into a preallocated output buffer "out".
|
||||
** "out" must be able to hold at least 2 +(257*n)/254 bytes.
|
||||
** In other words, the output will be expanded by as much as 3
|
||||
** bytes for every 254 bytes of input plus 2 bytes of fixed overhead.
|
||||
** (This is approximately 2 + 1.0118*n or about a 1.2% size increase.)
|
||||
**
|
||||
** The return value is the number of characters in the encoded
|
||||
** string, excluding the "\000" terminator.
|
||||
**
|
||||
** If out==NULL then no output is generated but the routine still returns
|
||||
** the number of characters that would have been generated if out had
|
||||
** not been NULL.
|
||||
*/
|
||||
int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
|
||||
int i, j, e, m;
|
||||
unsigned char x;
|
||||
int cnt[256];
|
||||
if( n<=0 ){
|
||||
if( out ){
|
||||
out[0] = 'x';
|
||||
out[1] = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
memset(cnt, 0, sizeof(cnt));
|
||||
for(i=n-1; i>=0; i--){ cnt[in[i]]++; }
|
||||
m = n;
|
||||
for(i=1; i<256; i++){
|
||||
int sum;
|
||||
if( i=='\'' ) continue;
|
||||
sum = cnt[i] + cnt[(i+1)&0xff] + cnt[(i+'\'')&0xff];
|
||||
if( sum<m ){
|
||||
m = sum;
|
||||
e = i;
|
||||
if( m==0 ) break;
|
||||
}
|
||||
}
|
||||
if( out==0 ){
|
||||
return n+m+1;
|
||||
}
|
||||
out[0] = e;
|
||||
j = 1;
|
||||
for(i=0; i<n; i++){
|
||||
x = in[i] - e;
|
||||
if( x==0 || x==1 || x=='\''){
|
||||
out[j++] = 1;
|
||||
x++;
|
||||
}
|
||||
out[j++] = x;
|
||||
}
|
||||
out[j] = 0;
|
||||
assert( j==n+m+1 );
|
||||
return j;
|
||||
}
|
||||
|
||||
/*
|
||||
** Decode the string "in" into binary data and write it into "out".
|
||||
** This routine reverses the encoding created by sqlite_encode_binary().
|
||||
** The output will always be a few bytes less than the input. The number
|
||||
** of bytes of output is returned. If the input is not a well-formed
|
||||
** encoding, -1 is returned.
|
||||
**
|
||||
** The "in" and "out" parameters may point to the same buffer in order
|
||||
** to decode a string in place.
|
||||
*/
|
||||
int sqlite_decode_binary(const unsigned char *in, unsigned char *out){
|
||||
int i, e;
|
||||
unsigned char c;
|
||||
e = *(in++);
|
||||
i = 0;
|
||||
while( (c = *(in++))!=0 ){
|
||||
if( c==1 ){
|
||||
c = *(in++) - 1;
|
||||
}
|
||||
out[i++] = c + e;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
#ifdef ENCODER_TEST
|
||||
#include <stdio.h>
|
||||
/*
|
||||
** The subroutines above are not tested by the usual test suite. To test
|
||||
** these routines, compile just this one file with a -DENCODER_TEST=1 option
|
||||
** and run the result.
|
||||
*/
|
||||
int main(int argc, char **argv){
|
||||
int i, j, n, m, nOut, nByteIn, nByteOut;
|
||||
unsigned char in[30000];
|
||||
unsigned char out[33000];
|
||||
|
||||
nByteIn = nByteOut = 0;
|
||||
for(i=0; i<sizeof(in); i++){
|
||||
printf("Test %d: ", i+1);
|
||||
n = rand() % (i+1);
|
||||
if( i%100==0 ){
|
||||
int k;
|
||||
for(j=k=0; j<n; j++){
|
||||
/* if( k==0 || k=='\'' ) k++; */
|
||||
in[j] = k;
|
||||
k = (k+1)&0xff;
|
||||
}
|
||||
}else{
|
||||
for(j=0; j<n; j++) in[j] = rand() & 0xff;
|
||||
}
|
||||
nByteIn += n;
|
||||
nOut = sqlite_encode_binary(in, n, out);
|
||||
nByteOut += nOut;
|
||||
if( nOut!=strlen(out) ){
|
||||
printf(" ERROR return value is %d instead of %d\n", nOut, strlen(out));
|
||||
exit(1);
|
||||
}
|
||||
if( nOut!=sqlite_encode_binary(in, n, 0) ){
|
||||
printf(" ERROR actual output size disagrees with predicted size\n");
|
||||
exit(1);
|
||||
}
|
||||
m = (256*n + 1262)/253;
|
||||
printf("size %d->%d (max %d)", n, strlen(out)+1, m);
|
||||
if( strlen(out)+1>m ){
|
||||
printf(" ERROR output too big\n");
|
||||
exit(1);
|
||||
}
|
||||
for(j=0; out[j]; j++){
|
||||
if( out[j]=='\'' ){
|
||||
printf(" ERROR contains (')\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
j = sqlite_decode_binary(out, out);
|
||||
if( j!=n ){
|
||||
printf(" ERROR decode size %d\n", j);
|
||||
exit(1);
|
||||
}
|
||||
if( memcmp(in, out, n)!=0 ){
|
||||
printf(" ERROR decode mismatch\n");
|
||||
exit(1);
|
||||
}
|
||||
printf(" OK\n");
|
||||
}
|
||||
fprintf(stderr,"Finished. Total encoding: %d->%d bytes\n",
|
||||
nByteIn, nByteOut);
|
||||
fprintf(stderr,"Avg size increase: %.3f%%\n",
|
||||
(nByteOut-nByteIn)*100.0/(double)nByteIn);
|
||||
}
|
||||
#endif /* ENCODER_TEST */
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
** 2005 January 20
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains C code routines that are not a part of the official
|
||||
** SQLite API. These routines are unsupported.
|
||||
**
|
||||
** $Id: experimental.c,v 1.3 2005/03/02 05:18:30 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Set all the parameters in the compiled SQL statement to NULL.
|
||||
*/
|
||||
int sqlite3_clear_bindings(sqlite3_stmt *pStmt){
|
||||
int i;
|
||||
int rc = SQLITE_OK;
|
||||
for(i=1; rc==SQLITE_OK && i<=sqlite3_bind_parameter_count(pStmt); i++){
|
||||
rc = sqlite3_bind_null(pStmt, i);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sleep for a little while. Return the amount of time slept.
|
||||
*/
|
||||
int sqlite3_sleep(int ms){
|
||||
return sqlite3OsSleep(ms);
|
||||
}
|
||||
+1119
-711
File diff suppressed because it is too large
Load Diff
+190
-90
@@ -16,16 +16,19 @@
|
||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.82 2004/09/02 15:53:57 drh Exp $
|
||||
** $Id: func.c,v 1.110 2005/09/08 20:37:43 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** Return the collating function associated with a function.
|
||||
*/
|
||||
static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
|
||||
return context->pColl;
|
||||
}
|
||||
@@ -78,6 +81,7 @@ static void typeofFunc(
|
||||
sqlite3_result_text(context, z, -1, SQLITE_STATIC);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Implementation of the length() function
|
||||
*/
|
||||
@@ -183,7 +187,7 @@ static void substrFunc(
|
||||
static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
int n = 0;
|
||||
double r;
|
||||
char zBuf[100];
|
||||
char zBuf[500]; /* larger than the %f representation of the largest double */
|
||||
assert( argc==1 || argc==2 );
|
||||
if( argc==2 ){
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return;
|
||||
@@ -193,7 +197,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
}
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[0]) ) return;
|
||||
r = sqlite3_value_double(argv[0]);
|
||||
sprintf(zBuf,"%.*f",n,r);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%.*f",n,r);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
@@ -268,7 +272,7 @@ static void last_insert_rowid(
|
||||
int arg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite *db = sqlite3_user_data(context);
|
||||
sqlite3 *db = sqlite3_user_data(context);
|
||||
sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
|
||||
}
|
||||
|
||||
@@ -281,7 +285,7 @@ static void changes(
|
||||
int arg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite *db = sqlite3_user_data(context);
|
||||
sqlite3 *db = sqlite3_user_data(context);
|
||||
sqlite3_result_int(context, sqlite3_changes(db));
|
||||
}
|
||||
|
||||
@@ -294,7 +298,7 @@ static void total_changes(
|
||||
int arg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite *db = sqlite3_user_data(context);
|
||||
sqlite3 *db = sqlite3_user_data(context);
|
||||
sqlite3_result_int(context, sqlite3_total_changes(db));
|
||||
}
|
||||
|
||||
@@ -307,8 +311,14 @@ struct compareInfo {
|
||||
u8 matchSet;
|
||||
u8 noCase;
|
||||
};
|
||||
|
||||
static const struct compareInfo globInfo = { '*', '?', '[', 0 };
|
||||
static const struct compareInfo likeInfo = { '%', '_', 0, 1 };
|
||||
/* The correct SQL-92 behavior is for the LIKE operator to ignore
|
||||
** case. Thus 'a' LIKE 'A' would be true. */
|
||||
static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 };
|
||||
/* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator
|
||||
** is case sensitive causing 'a' LIKE 'A' to be false */
|
||||
static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
|
||||
|
||||
/*
|
||||
** X is a pointer to the first byte of a UTF-8 character. Increment
|
||||
@@ -347,10 +357,11 @@ static const struct compareInfo likeInfo = { '%', '_', 0, 1 };
|
||||
**
|
||||
** abc[*]xyz Matches "abc*xyz" only
|
||||
*/
|
||||
int patternCompare(
|
||||
static int patternCompare(
|
||||
const u8 *zPattern, /* The glob pattern */
|
||||
const u8 *zString, /* The string to compare against the glob */
|
||||
const struct compareInfo *pInfo /* Information about how to do the compare */
|
||||
const struct compareInfo *pInfo, /* Information about how to do the compare */
|
||||
const int esc /* The escape character */
|
||||
){
|
||||
register int c;
|
||||
int invert;
|
||||
@@ -360,9 +371,10 @@ int patternCompare(
|
||||
u8 matchAll = pInfo->matchAll;
|
||||
u8 matchSet = pInfo->matchSet;
|
||||
u8 noCase = pInfo->noCase;
|
||||
int prevEscape = 0; /* True if the previous character was 'escape' */
|
||||
|
||||
while( (c = *zPattern)!=0 ){
|
||||
if( c==matchAll ){
|
||||
if( !prevEscape && c==matchAll ){
|
||||
while( (c=zPattern[1]) == matchAll || c == matchOne ){
|
||||
if( c==matchOne ){
|
||||
if( *zString==0 ) return 0;
|
||||
@@ -370,9 +382,15 @@ int patternCompare(
|
||||
}
|
||||
zPattern++;
|
||||
}
|
||||
if( c && esc && sqlite3ReadUtf8(&zPattern[1])==esc ){
|
||||
u8 const *zTemp = &zPattern[1];
|
||||
sqliteNextChar(zTemp);
|
||||
c = *zTemp;
|
||||
}
|
||||
if( c==0 ) return 1;
|
||||
if( c==matchSet ){
|
||||
while( *zString && patternCompare(&zPattern[1],zString,pInfo)==0 ){
|
||||
assert( esc==0 ); /* This is GLOB, not LIKE */
|
||||
while( *zString && patternCompare(&zPattern[1],zString,pInfo,esc)==0 ){
|
||||
sqliteNextChar(zString);
|
||||
}
|
||||
return *zString!=0;
|
||||
@@ -386,17 +404,18 @@ int patternCompare(
|
||||
while( c2 != 0 && c2 != c ){ c2 = *++zString; }
|
||||
}
|
||||
if( c2==0 ) return 0;
|
||||
if( patternCompare(&zPattern[1],zString,pInfo) ) return 1;
|
||||
if( patternCompare(&zPattern[1],zString,pInfo,esc) ) return 1;
|
||||
sqliteNextChar(zString);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}else if( c==matchOne ){
|
||||
}else if( !prevEscape && c==matchOne ){
|
||||
if( *zString==0 ) return 0;
|
||||
sqliteNextChar(zString);
|
||||
zPattern++;
|
||||
}else if( c==matchSet ){
|
||||
int prior_c = 0;
|
||||
assert( esc==0 ); /* This only occurs for GLOB, not LIKE */
|
||||
seen = 0;
|
||||
invert = 0;
|
||||
c = sqliteCharVal(zString);
|
||||
@@ -424,6 +443,9 @@ int patternCompare(
|
||||
if( c2==0 || (seen ^ invert)==0 ) return 0;
|
||||
sqliteNextChar(zString);
|
||||
zPattern++;
|
||||
}else if( esc && !prevEscape && sqlite3ReadUtf8(zPattern)==esc){
|
||||
prevEscape = 1;
|
||||
sqliteNextChar(zPattern);
|
||||
}else{
|
||||
if( noCase ){
|
||||
if( sqlite3UpperToLower[c] != sqlite3UpperToLower[*zString] ) return 0;
|
||||
@@ -432,11 +454,21 @@ int patternCompare(
|
||||
}
|
||||
zPattern++;
|
||||
zString++;
|
||||
prevEscape = 0;
|
||||
}
|
||||
}
|
||||
return *zString==0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Count the number of times that the LIKE operator (or GLOB which is
|
||||
** just a variation of LIKE) gets called. This is used for testing
|
||||
** only.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_like_count = 0;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Implementation of the like() SQL function. This function implements
|
||||
@@ -447,8 +479,8 @@ int patternCompare(
|
||||
**
|
||||
** is implemented as like(B,A).
|
||||
**
|
||||
** If the pointer retrieved by via a call to sqlite3_user_data() is
|
||||
** not NULL, then this function uses UTF-16. Otherwise UTF-8.
|
||||
** This same function (with a different compareInfo structure) computes
|
||||
** the GLOB operator.
|
||||
*/
|
||||
static void likeFunc(
|
||||
sqlite3_context *context,
|
||||
@@ -457,25 +489,25 @@ static void likeFunc(
|
||||
){
|
||||
const unsigned char *zA = sqlite3_value_text(argv[0]);
|
||||
const unsigned char *zB = sqlite3_value_text(argv[1]);
|
||||
if( zA && zB ){
|
||||
sqlite3_result_int(context, patternCompare(zA, zB, &likeInfo));
|
||||
int escape = 0;
|
||||
if( argc==3 ){
|
||||
/* The escape character string must consist of a single UTF-8 character.
|
||||
** Otherwise, return an error.
|
||||
*/
|
||||
const unsigned char *zEsc = sqlite3_value_text(argv[2]);
|
||||
if( sqlite3utf8CharLen(zEsc, -1)!=1 ){
|
||||
sqlite3_result_error(context,
|
||||
"ESCAPE expression must be a single character", -1);
|
||||
return;
|
||||
}
|
||||
escape = sqlite3ReadUtf8(zEsc);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the glob() SQL function. This function implements
|
||||
** the build-in GLOB operator. The first argument to the function is the
|
||||
** string and the second argument is the pattern. So, the SQL statements:
|
||||
**
|
||||
** A GLOB B
|
||||
**
|
||||
** is implemented as glob(A,B).
|
||||
*/
|
||||
static void globFunc(sqlite3_context *context, int arg, sqlite3_value **argv){
|
||||
const unsigned char *zA = sqlite3_value_text(argv[0]);
|
||||
const unsigned char *zB = sqlite3_value_text(argv[1]);
|
||||
if( zA && zB ){
|
||||
sqlite3_result_int(context, patternCompare(zA, zB, &globInfo));
|
||||
struct compareInfo *pInfo = sqlite3_user_data(context);
|
||||
#ifdef SQLITE_TEST
|
||||
sqlite3_like_count++;
|
||||
#endif
|
||||
sqlite3_result_int(context, patternCompare(zA, zB, pInfo, escape));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,6 +539,7 @@ static void versionFunc(
|
||||
sqlite3_result_text(context, sqlite3_version, -1, SQLITE_STATIC);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** EXPERIMENTAL - This is not an official function. The interface may
|
||||
** change. This function may disappear. Do not write code that depends
|
||||
@@ -690,7 +723,7 @@ static void test_destructor(
|
||||
){
|
||||
char *zVal;
|
||||
int len;
|
||||
sqlite *db = sqlite3_user_data(pCtx);
|
||||
sqlite3 *db = sqlite3_user_data(pCtx);
|
||||
|
||||
test_destructor_count_var++;
|
||||
assert( nArg==1 );
|
||||
@@ -704,10 +737,12 @@ static void test_destructor(
|
||||
memcpy(zVal, sqlite3ValueText(argv[0], db->enc), len);
|
||||
if( db->enc==SQLITE_UTF8 ){
|
||||
sqlite3_result_text(pCtx, zVal, -1, destructor);
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
}else if( db->enc==SQLITE_UTF16LE ){
|
||||
sqlite3_result_text16le(pCtx, zVal, -1, destructor);
|
||||
}else{
|
||||
sqlite3_result_text16be(pCtx, zVal, -1, destructor);
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
}
|
||||
}
|
||||
static void test_destructor_count(
|
||||
@@ -762,6 +797,20 @@ static void test_auxdata(
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** A function to test error reporting from user functions. This function
|
||||
** returns a copy of it's first argument as an error.
|
||||
*/
|
||||
static void test_error(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_result_error(pCtx, sqlite3_value_text(argv[0]), 0);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
/*
|
||||
** An instance of the following structure holds the context of a
|
||||
** sum() or avg() aggregate computation.
|
||||
@@ -770,6 +819,7 @@ typedef struct SumCtx SumCtx;
|
||||
struct SumCtx {
|
||||
double sum; /* Sum of terms */
|
||||
int cnt; /* Number of elements summed */
|
||||
u8 seenFloat; /* True if there has been any floating point value */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -777,21 +827,32 @@ struct SumCtx {
|
||||
*/
|
||||
static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
SumCtx *p;
|
||||
if( argc<1 ) return;
|
||||
int type;
|
||||
assert( argc==1 );
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
if( p && SQLITE_NULL!=sqlite3_value_type(argv[0]) ){
|
||||
type = sqlite3_value_type(argv[0]);
|
||||
if( p && type!=SQLITE_NULL ){
|
||||
p->sum += sqlite3_value_double(argv[0]);
|
||||
p->cnt++;
|
||||
if( type==SQLITE_FLOAT ){
|
||||
p->seenFloat = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void sumFinalize(sqlite3_context *context){
|
||||
SumCtx *p;
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
sqlite3_result_double(context, p ? p->sum : 0.0);
|
||||
p = sqlite3_aggregate_context(context, 0);
|
||||
if( p && p->cnt>0 ){
|
||||
if( p->seenFloat ){
|
||||
sqlite3_result_double(context, p->sum);
|
||||
}else{
|
||||
sqlite3_result_int64(context, (i64)p->sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void avgFinalize(sqlite3_context *context){
|
||||
SumCtx *p;
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
p = sqlite3_aggregate_context(context, 0);
|
||||
if( p && p->cnt>0 ){
|
||||
sqlite3_result_double(context, p->sum/(double)p->cnt);
|
||||
}
|
||||
@@ -808,33 +869,6 @@ struct StdDevCtx {
|
||||
int cnt; /* Number of terms counted */
|
||||
};
|
||||
|
||||
#if 0 /* Omit because math library is required */
|
||||
/*
|
||||
** Routines used to compute the standard deviation as an aggregate.
|
||||
*/
|
||||
static void stdDevStep(sqlite3_context *context, int argc, const char **argv){
|
||||
StdDevCtx *p;
|
||||
double x;
|
||||
if( argc<1 ) return;
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
if( p && argv[0] ){
|
||||
x = sqlite3AtoF(argv[0], 0);
|
||||
p->sum += x;
|
||||
p->sum2 += x*x;
|
||||
p->cnt++;
|
||||
}
|
||||
}
|
||||
static void stdDevFinalize(sqlite3_context *context){
|
||||
double rN = sqlite3_aggregate_count(context);
|
||||
StdDevCtx *p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
if( p && p->cnt>1 ){
|
||||
double rCnt = cnt;
|
||||
sqlite3_set_result_double(context,
|
||||
sqrt((p->sum2 - p->sum*p->sum/rCnt)/(rCnt-1.0)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The following structure keeps track of state information for the
|
||||
** count() aggregate function.
|
||||
@@ -856,20 +890,10 @@ static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
}
|
||||
static void countFinalize(sqlite3_context *context){
|
||||
CountCtx *p;
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
p = sqlite3_aggregate_context(context, 0);
|
||||
sqlite3_result_int(context, p ? p->n : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** This function tracks state information for the min() and max()
|
||||
** aggregate functions.
|
||||
*/
|
||||
typedef struct MinMaxCtx MinMaxCtx;
|
||||
struct MinMaxCtx {
|
||||
char *z; /* The best so far */
|
||||
char zBuf[28]; /* Space that can be used for storage */
|
||||
};
|
||||
|
||||
/*
|
||||
** Routines to implement min() and max() aggregate functions.
|
||||
*/
|
||||
@@ -904,11 +928,13 @@ static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv)
|
||||
}
|
||||
static void minMaxFinalize(sqlite3_context *context){
|
||||
sqlite3_value *pRes;
|
||||
pRes = (sqlite3_value *)sqlite3_aggregate_context(context, sizeof(Mem));
|
||||
if( pRes->flags ){
|
||||
sqlite3_result_value(context, pRes);
|
||||
pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0);
|
||||
if( pRes ){
|
||||
if( pRes->flags ){
|
||||
sqlite3_result_value(context, pRes);
|
||||
}
|
||||
sqlite3VdbeMemRelease(pRes);
|
||||
}
|
||||
sqlite3VdbeMemRelease(pRes);
|
||||
}
|
||||
|
||||
|
||||
@@ -917,8 +943,8 @@ static void minMaxFinalize(sqlite3_context *context){
|
||||
** functions. This should be the only routine in this file with
|
||||
** external linkage.
|
||||
*/
|
||||
void sqlite3RegisterBuiltinFunctions(sqlite *db){
|
||||
static struct {
|
||||
void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
static const struct {
|
||||
char *zName;
|
||||
signed char nArg;
|
||||
u8 argType; /* 0: none. 1: db 2: (-1) */
|
||||
@@ -933,7 +959,9 @@ void sqlite3RegisterBuiltinFunctions(sqlite *db){
|
||||
{ "typeof", 1, 0, SQLITE_UTF8, 0, typeofFunc },
|
||||
{ "length", 1, 0, SQLITE_UTF8, 0, lengthFunc },
|
||||
{ "substr", 3, 0, SQLITE_UTF8, 0, substrFunc },
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
{ "substr", 3, 0, SQLITE_UTF16LE, 0, sqlite3utf16Substr },
|
||||
#endif
|
||||
{ "abs", 1, 0, SQLITE_UTF8, 0, absFunc },
|
||||
{ "round", 1, 0, SQLITE_UTF8, 0, roundFunc },
|
||||
{ "round", 2, 0, SQLITE_UTF8, 0, roundFunc },
|
||||
@@ -944,9 +972,7 @@ void sqlite3RegisterBuiltinFunctions(sqlite *db){
|
||||
{ "coalesce", 1, 0, SQLITE_UTF8, 0, 0 },
|
||||
{ "ifnull", 2, 0, SQLITE_UTF8, 1, ifnullFunc },
|
||||
{ "random", -1, 0, SQLITE_UTF8, 0, randomFunc },
|
||||
{ "like", 2, 0, SQLITE_UTF8, 0, likeFunc },
|
||||
{ "glob", 2, 0, SQLITE_UTF8, 0, globFunc },
|
||||
{ "nullif", 2, 0, SQLITE_UTF8, 0, nullifFunc },
|
||||
{ "nullif", 2, 0, SQLITE_UTF8, 1, nullifFunc },
|
||||
{ "sqlite_version", 0, 0, SQLITE_UTF8, 0, versionFunc},
|
||||
{ "quote", 1, 0, SQLITE_UTF8, 0, quoteFunc },
|
||||
{ "last_insert_rowid", 0, 1, SQLITE_UTF8, 0, last_insert_rowid },
|
||||
@@ -960,9 +986,10 @@ void sqlite3RegisterBuiltinFunctions(sqlite *db){
|
||||
{ "test_destructor", 1, 1, SQLITE_UTF8, 0, test_destructor},
|
||||
{ "test_destructor_count", 0, 0, SQLITE_UTF8, 0, test_destructor_count},
|
||||
{ "test_auxdata", -1, 0, SQLITE_UTF8, 0, test_auxdata},
|
||||
{ "test_error", 1, 0, SQLITE_UTF8, 0, test_error},
|
||||
#endif
|
||||
};
|
||||
static struct {
|
||||
static const struct {
|
||||
char *zName;
|
||||
signed char nArg;
|
||||
u8 argType;
|
||||
@@ -976,9 +1003,6 @@ void sqlite3RegisterBuiltinFunctions(sqlite *db){
|
||||
{ "avg", 1, 0, 0, sumStep, avgFinalize },
|
||||
{ "count", 0, 0, 0, countStep, countFinalize },
|
||||
{ "count", 1, 0, 0, countStep, countFinalize },
|
||||
#if 0
|
||||
{ "stddev", 1, 0, stdDevStep, stdDevFinalize },
|
||||
#endif
|
||||
};
|
||||
int i;
|
||||
|
||||
@@ -998,6 +1022,9 @@ void sqlite3RegisterBuiltinFunctions(sqlite *db){
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_ALTERTABLE
|
||||
sqlite3AlterFunctions(db);
|
||||
#endif
|
||||
for(i=0; i<sizeof(aAggs)/sizeof(aAggs[0]); i++){
|
||||
void *pArg = 0;
|
||||
switch( aAggs[i].argType ){
|
||||
@@ -1015,4 +1042,77 @@ void sqlite3RegisterBuiltinFunctions(sqlite *db){
|
||||
}
|
||||
}
|
||||
sqlite3RegisterDateTimeFunctions(db);
|
||||
#ifdef SQLITE_SSE
|
||||
sqlite3SseFunctions(db);
|
||||
#endif
|
||||
#ifdef SQLITE_CASE_SENSITIVE_LIKE
|
||||
sqlite3RegisterLikeFunctions(db, 1);
|
||||
#else
|
||||
sqlite3RegisterLikeFunctions(db, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the LIKEOPT flag on the 2-argument function with the given name.
|
||||
*/
|
||||
static void setLikeOptFlag(sqlite3 *db, const char *zName, int flagVal){
|
||||
FuncDef *pDef;
|
||||
pDef = sqlite3FindFunction(db, zName, strlen(zName), 2, SQLITE_UTF8, 0);
|
||||
if( pDef ){
|
||||
pDef->flags = flagVal;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Register the built-in LIKE and GLOB functions. The caseSensitive
|
||||
** parameter determines whether or not the LIKE operator is case
|
||||
** sensitive. GLOB is always case sensitive.
|
||||
*/
|
||||
void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
|
||||
struct compareInfo *pInfo;
|
||||
if( caseSensitive ){
|
||||
pInfo = (struct compareInfo*)&likeInfoAlt;
|
||||
}else{
|
||||
pInfo = (struct compareInfo*)&likeInfoNorm;
|
||||
}
|
||||
sqlite3_create_function(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0);
|
||||
sqlite3_create_function(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0);
|
||||
sqlite3_create_function(db, "glob", 2, SQLITE_UTF8,
|
||||
(struct compareInfo*)&globInfo, likeFunc, 0,0);
|
||||
setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
|
||||
setLikeOptFlag(db, "like",
|
||||
caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
|
||||
}
|
||||
|
||||
/*
|
||||
** pExpr points to an expression which implements a function. If
|
||||
** it is appropriate to apply the LIKE optimization to that function
|
||||
** then set aWc[0] through aWc[2] to the wildcard characters and
|
||||
** return TRUE. If the function is not a LIKE-style function then
|
||||
** return FALSE.
|
||||
*/
|
||||
int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
|
||||
FuncDef *pDef;
|
||||
if( pExpr->op!=TK_FUNCTION ){
|
||||
return 0;
|
||||
}
|
||||
if( pExpr->pList->nExpr!=2 ){
|
||||
return 0;
|
||||
}
|
||||
pDef = sqlite3FindFunction(db, pExpr->token.z, pExpr->token.n, 2,
|
||||
SQLITE_UTF8, 0);
|
||||
if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The memcpy() statement assumes that the wildcard characters are
|
||||
** the first three statements in the compareInfo structure. The
|
||||
** asserts() that follow verify that assumption
|
||||
*/
|
||||
memcpy(aWc, pDef->pUserData, 3);
|
||||
assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
|
||||
assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
|
||||
assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
|
||||
*pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
+9
-2
@@ -12,7 +12,7 @@
|
||||
** This is the implementation of generic hash-tables
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.c,v 1.15 2004/08/20 14:08:51 drh Exp $
|
||||
** $Id: hash.c,v 1.16 2005/01/31 12:56:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <assert.h>
|
||||
@@ -98,7 +98,14 @@ static int ptrCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
** Hash and comparison functions when the mode is SQLITE_HASH_STRING
|
||||
*/
|
||||
static int strHash(const void *pKey, int nKey){
|
||||
return sqlite3HashNoCase((const char*)pKey, nKey);
|
||||
const char *z = (const char *)pKey;
|
||||
int h = 0;
|
||||
if( nKey<=0 ) nKey = strlen(z);
|
||||
while( nKey > 0 ){
|
||||
h = (h<<3) ^ h ^ sqlite3UpperToLower[(unsigned char)*z++];
|
||||
nKey--;
|
||||
}
|
||||
return h & 0x7fffffff;
|
||||
}
|
||||
static int strCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
if( n1!=n2 ) return 1;
|
||||
|
||||
+194
-103
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle INSERT statements in SQLite.
|
||||
**
|
||||
** $Id: insert.c,v 1.115 2004/08/21 17:54:45 drh Exp $
|
||||
** $Id: insert.c,v 1.143 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -94,6 +94,27 @@ void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
|
||||
sqlite3VdbeChangeP3(v, -1, pTab->zColAff, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return non-zero if SELECT statement p opens the table with rootpage
|
||||
** iTab in database iDb. This is used to see if a statement of the form
|
||||
** "INSERT INTO <iDb, iTab> SELECT ..." can run without using temporary
|
||||
** table for the results of the SELECT.
|
||||
**
|
||||
** No checking is done for sub-selects that are part of expressions.
|
||||
*/
|
||||
static int selectReadsTable(Select *p, int iDb, int iTab){
|
||||
int i;
|
||||
struct SrcList_item *pItem;
|
||||
if( p->pSrc==0 ) return 0;
|
||||
for(i=0, pItem=p->pSrc->a; i<p->pSrc->nSrc; i++, pItem++){
|
||||
if( pItem->pSelect ){
|
||||
if( selectReadsTable(pItem->pSelect, iDb, iTab) ) return 1;
|
||||
}else{
|
||||
if( pItem->pTab->iDb==iDb && pItem->pTab->tnum==iTab ) return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is call to handle SQL of the following forms:
|
||||
@@ -179,21 +200,27 @@ void sqlite3Insert(
|
||||
int nColumn; /* Number of columns in the data */
|
||||
int base = 0; /* VDBE Cursor number for pTab */
|
||||
int iCont=0,iBreak=0; /* Beginning and end of the loop over srcTab */
|
||||
sqlite *db; /* The main database structure */
|
||||
sqlite3 *db; /* The main database structure */
|
||||
int keyColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
|
||||
int endOfLoop; /* Label for the end of the insertion loop */
|
||||
int useTempTable; /* Store SELECT results in intermediate table */
|
||||
int useTempTable = 0; /* Store SELECT results in intermediate table */
|
||||
int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
|
||||
int iSelectLoop = 0; /* Address of code that implements the SELECT */
|
||||
int iCleanup = 0; /* Address of the cleanup code */
|
||||
int iInsertBlock = 0; /* Address of the subroutine used to insert data */
|
||||
int iCntMem = 0; /* Memory cell used for the row counter */
|
||||
int isView; /* True if attempting to insert into a view */
|
||||
int newIdx = -1; /* Cursor for the NEW table */
|
||||
Db *pDb; /* The database containing table being inserted into */
|
||||
int counterMem = 0; /* Memory cell holding AUTOINCREMENT counter */
|
||||
|
||||
int row_triggers_exist = 0; /* True if there are FOR EACH ROW triggers */
|
||||
int before_triggers; /* True if there are BEFORE triggers */
|
||||
int after_triggers; /* True if there are AFTER triggers */
|
||||
int newIdx = -1; /* Cursor for the NEW table */
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* True if attempting to insert into a view */
|
||||
int triggers_exist = 0; /* True if there are FOR EACH ROW triggers */
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
int counterRowid; /* Memory cell holding rowid of autoinc counter */
|
||||
#endif
|
||||
|
||||
if( pParse->nErr || sqlite3_malloc_failed ) goto insert_cleanup;
|
||||
db = pParse->db;
|
||||
@@ -208,22 +235,32 @@ void sqlite3Insert(
|
||||
goto insert_cleanup;
|
||||
}
|
||||
assert( pTab->iDb<db->nDb );
|
||||
zDb = db->aDb[pTab->iDb].zName;
|
||||
pDb = &db->aDb[pTab->iDb];
|
||||
zDb = pDb->zName;
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
|
||||
/* Figure out if we have any triggers and if the table being
|
||||
** inserted into is a view
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0);
|
||||
isView = pTab->pSelect!=0;
|
||||
#else
|
||||
# define triggers_exist 0
|
||||
# define isView 0
|
||||
#endif
|
||||
#ifdef SQLITE_OMIT_VIEW
|
||||
# undef isView
|
||||
# define isView 0
|
||||
#endif
|
||||
|
||||
/* Ensure that:
|
||||
* (a) the table is not read-only,
|
||||
* (b) that if it is a view then ON INSERT triggers exist
|
||||
*/
|
||||
before_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger, TK_INSERT,
|
||||
TK_BEFORE, TK_ROW, 0);
|
||||
after_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger, TK_INSERT,
|
||||
TK_AFTER, TK_ROW, 0);
|
||||
row_triggers_exist = before_triggers || after_triggers;
|
||||
isView = pTab->pSelect!=0;
|
||||
if( sqlite3IsReadOnly(pParse, pTab, before_triggers) ){
|
||||
if( sqlite3IsReadOnly(pParse, pTab, triggers_exist) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( pTab==0 ) goto insert_cleanup;
|
||||
@@ -245,14 +282,42 @@ void sqlite3Insert(
|
||||
*/
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) goto insert_cleanup;
|
||||
sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, pSelect || row_triggers_exist, pTab->iDb);
|
||||
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, pSelect || triggers_exist, pTab->iDb);
|
||||
|
||||
/* if there are row triggers, allocate a temp table for new.* references. */
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist ){
|
||||
newIdx = pParse->nTab++;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
/* If this is an AUTOINCREMENT table, look up the sequence number in the
|
||||
** sqlite_sequence table and store it in memory cell counterMem. Also
|
||||
** remember the rowid of the sqlite_sequence table entry in memory cell
|
||||
** counterRowid.
|
||||
*/
|
||||
if( pTab->autoInc ){
|
||||
int iCur = pParse->nTab;
|
||||
int base = sqlite3VdbeCurrentAddr(v);
|
||||
counterRowid = pParse->nMem++;
|
||||
counterMem = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pDb->pSeqTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, 2);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, base+13);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Ne, 28417, base+12);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, counterRowid, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, counterMem, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, base+13);
|
||||
sqlite3VdbeAddOp(v, OP_Next, iCur, base+4);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTOINCREMENT */
|
||||
|
||||
/* Figure out how many columns of data are supplied. If the data
|
||||
** is coming from a SELECT statement, then this step also generates
|
||||
** all the code to implement the SELECT statement and invoke a subroutine
|
||||
@@ -268,8 +333,11 @@ void sqlite3Insert(
|
||||
iInitCode = sqlite3VdbeAddOp(v, OP_Goto, 0, 0);
|
||||
iSelectLoop = sqlite3VdbeCurrentAddr(v);
|
||||
iInsertBlock = sqlite3VdbeMakeLabel(v);
|
||||
rc = sqlite3Select(pParse, pSelect, SRT_Subroutine, iInsertBlock, 0,0,0,0);
|
||||
|
||||
/* Resolve the expressions in the SELECT statement and execute it. */
|
||||
rc = sqlite3Select(pParse, pSelect, SRT_Subroutine, iInsertBlock,0,0,0,0);
|
||||
if( rc || pParse->nErr || sqlite3_malloc_failed ) goto insert_cleanup;
|
||||
|
||||
iCleanup = sqlite3VdbeMakeLabel(v);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, iCleanup);
|
||||
assert( pSelect->pEList );
|
||||
@@ -283,17 +351,8 @@ void sqlite3Insert(
|
||||
** of the tables being read by the SELECT statement. Also use a
|
||||
** temp table in the case of row triggers.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist || selectReadsTable(pSelect, pTab->iDb, pTab->tnum) ){
|
||||
useTempTable = 1;
|
||||
}else{
|
||||
int addr = sqlite3VdbeFindOp(v, 0, OP_OpenRead, pTab->tnum);
|
||||
useTempTable = 0;
|
||||
if( addr>0 ){
|
||||
VdbeOp *pOp = sqlite3VdbeGetOp(v, addr-2);
|
||||
if( pOp->opcode==OP_Integer && pOp->p1==pTab->iDb ){
|
||||
useTempTable = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( useTempTable ){
|
||||
@@ -304,36 +363,37 @@ void sqlite3Insert(
|
||||
sqlite3VdbeResolveLabel(v, iInsertBlock);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
sqlite3VdbeAddOp(v, OP_NewRecno, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Return, 0, 0);
|
||||
|
||||
/* The following code runs first because the GOTO at the very top
|
||||
** of the program jumps to it. Create the temporary table, then jump
|
||||
** back up and execute the SELECT code above.
|
||||
*/
|
||||
sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeAddOp(v, OP_OpenTemp, srcTab, 0);
|
||||
sqlite3VdbeJumpHere(v, iInitCode);
|
||||
sqlite3VdbeAddOp(v, OP_OpenVirtual, srcTab, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, nColumn);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop);
|
||||
sqlite3VdbeResolveLabel(v, iCleanup);
|
||||
}else{
|
||||
sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeJumpHere(v, iInitCode);
|
||||
}
|
||||
}else{
|
||||
/* This is the case if the data for the INSERT is coming from a VALUES
|
||||
** clause
|
||||
*/
|
||||
SrcList dummy;
|
||||
NameContext sNC;
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pParse;
|
||||
assert( pList!=0 );
|
||||
srcTab = -1;
|
||||
useTempTable = 0;
|
||||
assert( pList );
|
||||
nColumn = pList->nExpr;
|
||||
dummy.nSrc = 0;
|
||||
for(i=0; i<nColumn; i++){
|
||||
if( sqlite3ExprResolveAndCheck(pParse,&dummy,0,pList->a[i].pExpr,0,0) ){
|
||||
if( sqlite3ExprResolveNames(&sNC, pList->a[i].pExpr) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -401,7 +461,7 @@ void sqlite3Insert(
|
||||
|
||||
/* Open the temp table for FOR EACH ROW triggers
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist ){
|
||||
sqlite3VdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol);
|
||||
}
|
||||
@@ -410,12 +470,11 @@ void sqlite3Insert(
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
iCntMem = pParse->nMem++;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, iCntMem, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, iCntMem);
|
||||
}
|
||||
|
||||
/* Open tables and indices if there are no row triggers */
|
||||
if( !row_triggers_exist ){
|
||||
if( !triggers_exist ){
|
||||
base = pParse->nTab;
|
||||
sqlite3OpenTableAndIndices(pParse, pTab, base, OP_OpenWrite);
|
||||
}
|
||||
@@ -437,7 +496,7 @@ void sqlite3Insert(
|
||||
/* Run the BEFORE and INSTEAD OF triggers, if there are any
|
||||
*/
|
||||
endOfLoop = sqlite3VdbeMakeLabel(v);
|
||||
if( before_triggers ){
|
||||
if( triggers_exist & TRIGGER_BEFORE ){
|
||||
|
||||
/* build the NEW.* reference row. Note that if there is an INTEGER
|
||||
** PRIMARY KEY into which a NULL is being inserted, that NULL will be
|
||||
@@ -449,9 +508,8 @@ void sqlite3Insert(
|
||||
sqlite3VdbeAddOp(v, OP_Integer, -1, 0);
|
||||
}else if( useTempTable ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, srcTab, keyColumn);
|
||||
}else if( pSelect ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nColumn - keyColumn - 1, 1);
|
||||
}else{
|
||||
assert( pSelect==0 ); /* Otherwise useTempTable is true */
|
||||
sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr);
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
@@ -470,13 +528,12 @@ void sqlite3Insert(
|
||||
}
|
||||
}
|
||||
if( pColumn && j>=pColumn->nId ){
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
|
||||
}else if( useTempTable ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, srcTab, j);
|
||||
}else if( pSelect ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nColumn-j-1, 1);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pList->a[j].pExpr);
|
||||
assert( pSelect==0 ); /* Otherwise useTempTable is true */
|
||||
sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
@@ -489,10 +546,10 @@ void sqlite3Insert(
|
||||
if( !isView ){
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
|
||||
|
||||
/* Fire BEFORE or INSTEAD OF triggers */
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab,
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TRIGGER_BEFORE, pTab,
|
||||
newIdx, -1, onError, endOfLoop) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
@@ -501,13 +558,13 @@ void sqlite3Insert(
|
||||
/* If any triggers exists, the opening of tables and indices is deferred
|
||||
** until now.
|
||||
*/
|
||||
if( row_triggers_exist && !isView ){
|
||||
if( triggers_exist && !isView ){
|
||||
base = pParse->nTab;
|
||||
sqlite3OpenTableAndIndices(pParse, pTab, base, OP_OpenWrite);
|
||||
}
|
||||
|
||||
/* Push the record number for the new entry onto the stack. The
|
||||
** record number is a randomly generate integer created by NewRecno
|
||||
** record number is a randomly generate integer created by NewRowid
|
||||
** except when the table has an INTEGER PRIMARY KEY column, in which
|
||||
** case the record number is the same as that column.
|
||||
*/
|
||||
@@ -520,16 +577,21 @@ void sqlite3Insert(
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr);
|
||||
}
|
||||
/* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
|
||||
/* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
|
||||
** to generate a unique primary key value.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRecno, base, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, base, counterMem);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_NewRecno, base, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, base, counterMem);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
if( pTab->autoInc ){
|
||||
sqlite3VdbeAddOp(v, OP_MemMax, counterMem, 0);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTOINCREMENT */
|
||||
|
||||
/* Push onto the stack, data for all columns of the new entry, beginning
|
||||
** with the first column.
|
||||
@@ -540,7 +602,7 @@ void sqlite3Insert(
|
||||
** Whenever this column is read, the record number will be substituted
|
||||
** in its place. So will fill this column with a NULL to avoid
|
||||
** taking up data space with information that will never be used. */
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
|
||||
continue;
|
||||
}
|
||||
if( pColumn==0 ){
|
||||
@@ -551,7 +613,7 @@ void sqlite3Insert(
|
||||
}
|
||||
}
|
||||
if( pColumn && j>=pColumn->nId ){
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
|
||||
}else if( useTempTable ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, srcTab, j);
|
||||
}else if( pSelect ){
|
||||
@@ -567,7 +629,7 @@ void sqlite3Insert(
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, base, 0, keyColumn>=0,
|
||||
0, onError, endOfLoop);
|
||||
sqlite3CompleteInsertion(pParse, pTab, base, 0,0,0,
|
||||
after_triggers ? newIdx : -1);
|
||||
(triggers_exist & TRIGGER_AFTER)!=0 ? newIdx : -1);
|
||||
}
|
||||
|
||||
/* Update the count of rows that are inserted
|
||||
@@ -576,7 +638,7 @@ void sqlite3Insert(
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, iCntMem, 0);
|
||||
}
|
||||
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist ){
|
||||
/* Close all tables opened */
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, base, 0);
|
||||
@@ -586,8 +648,8 @@ void sqlite3Insert(
|
||||
}
|
||||
|
||||
/* Code AFTER triggers */
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TK_AFTER, pTab, newIdx, -1,
|
||||
onError, endOfLoop) ){
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TRIGGER_AFTER, pTab,
|
||||
newIdx, -1, onError, endOfLoop) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -605,7 +667,7 @@ void sqlite3Insert(
|
||||
sqlite3VdbeResolveLabel(v, iCleanup);
|
||||
}
|
||||
|
||||
if( !row_triggers_exist ){
|
||||
if( !triggers_exist ){
|
||||
/* Close all tables opened */
|
||||
sqlite3VdbeAddOp(v, OP_Close, base, 0);
|
||||
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
|
||||
@@ -613,12 +675,35 @@ void sqlite3Insert(
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
/* Update the sqlite_sequence table by storing the content of the
|
||||
** counter value in memory counterMem back into the sqlite_sequence
|
||||
** table.
|
||||
*/
|
||||
if( pTab->autoInc ){
|
||||
int iCur = pParse->nTab;
|
||||
int base = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenWrite, iCur, pDb->pSeqTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, 2);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, counterRowid, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NotNull, -1, base+7);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_NewRowid, iCur, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, counterMem, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, 2, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Return the number of rows inserted.
|
||||
** Return the number of rows inserted. If this routine is
|
||||
** generating code because of a call to sqlite3NestedParse(), do not
|
||||
** invoke the callback function.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
|
||||
sqlite3VdbeAddOp(v, OP_MemLoad, iCntMem, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
@@ -627,8 +712,8 @@ void sqlite3Insert(
|
||||
|
||||
insert_cleanup:
|
||||
sqlite3SrcListDelete(pTabList);
|
||||
if( pList ) sqlite3ExprListDelete(pList);
|
||||
if( pSelect ) sqlite3SelectDelete(pSelect);
|
||||
sqlite3ExprListDelete(pList);
|
||||
sqlite3SelectDelete(pSelect);
|
||||
sqlite3IdListDelete(pColumn);
|
||||
}
|
||||
|
||||
@@ -638,11 +723,11 @@ insert_cleanup:
|
||||
** When this routine is called, the stack contains (from bottom to top)
|
||||
** the following values:
|
||||
**
|
||||
** 1. The recno of the row to be updated before the update. This
|
||||
** 1. The rowid of the row to be updated before the update. This
|
||||
** value is omitted unless we are doing an UPDATE that involves a
|
||||
** change to the record number.
|
||||
**
|
||||
** 2. The recno of the row after the update.
|
||||
** 2. The rowid of the row after the update.
|
||||
**
|
||||
** 3. The data in the first column of the entry after the update.
|
||||
**
|
||||
@@ -650,9 +735,9 @@ insert_cleanup:
|
||||
**
|
||||
** N. The data in the last column of the entry after the update.
|
||||
**
|
||||
** The old recno shown as entry (1) above is omitted unless both isUpdate
|
||||
** and recnoChng are 1. isUpdate is true for UPDATEs and false for
|
||||
** INSERTs and recnoChng is true if the record number is being changed.
|
||||
** The old rowid shown as entry (1) above is omitted unless both isUpdate
|
||||
** and rowidChng are 1. isUpdate is true for UPDATEs and false for
|
||||
** INSERTs and rowidChng is true if the record number is being changed.
|
||||
**
|
||||
** The code generated by this routine pushes additional entries onto
|
||||
** the stack which are the keys for new index entries for the new record.
|
||||
@@ -716,7 +801,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
Table *pTab, /* the table into which we are inserting */
|
||||
int base, /* Index of a read/write cursor pointing at pTab */
|
||||
char *aIdxUsed, /* Which indices are used. NULL means all are used */
|
||||
int recnoChng, /* True if the record number will change */
|
||||
int rowidChng, /* True if the record number will change */
|
||||
int isUpdate, /* True for UPDATE, False for INSERT */
|
||||
int overrideError, /* Override onError to this if not OE_Default */
|
||||
int ignoreDest /* Jump to this label on an OE_Ignore resolution */
|
||||
@@ -731,8 +816,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
Index *pIdx;
|
||||
int seenReplace = 0;
|
||||
int jumpInst1=0, jumpInst2;
|
||||
int contAddr;
|
||||
int hasTwoRecnos = (isUpdate && recnoChng);
|
||||
int hasTwoRowids = (isUpdate && rowidChng);
|
||||
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
@@ -752,11 +836,13 @@ void sqlite3GenerateConstraintChecks(
|
||||
}else if( onError==OE_Default ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
if( onError==OE_Replace && pTab->aCol[i].zDflt==0 ){
|
||||
if( onError==OE_Replace && pTab->aCol[i].pDflt==0 ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol-1-i, 1);
|
||||
addr = sqlite3VdbeAddOp(v, OP_NotNull, 1, 0);
|
||||
assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
|
||||
|| onError==OE_Ignore || onError==OE_Replace );
|
||||
switch( onError ){
|
||||
case OE_Rollback:
|
||||
case OE_Abort:
|
||||
@@ -769,18 +855,17 @@ void sqlite3GenerateConstraintChecks(
|
||||
break;
|
||||
}
|
||||
case OE_Ignore: {
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
case OE_Replace: {
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
|
||||
sqlite3VdbeAddOp(v, OP_Push, nCol-i, 0);
|
||||
break;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
|
||||
/* Test all CHECK constraints
|
||||
@@ -791,7 +876,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
** of the new record does not previously exist. Except, if this
|
||||
** is an UPDATE and the primary key is not changing, that is OK.
|
||||
*/
|
||||
if( recnoChng ){
|
||||
if( rowidChng ){
|
||||
onError = pTab->keyConf;
|
||||
if( overrideError!=OE_Default ){
|
||||
onError = overrideError;
|
||||
@@ -821,7 +906,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
case OE_Replace: {
|
||||
sqlite3GenerateRowIndexDelete(pParse->db, v, pTab, base, 0);
|
||||
if( isUpdate ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+hasTwoRecnos, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+hasTwoRowids, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
|
||||
}
|
||||
seenReplace = 1;
|
||||
@@ -829,15 +914,14 @@ void sqlite3GenerateConstraintChecks(
|
||||
}
|
||||
case OE_Ignore: {
|
||||
assert( seenReplace==0 );
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
}
|
||||
contAddr = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3VdbeChangeP2(v, jumpInst2, contAddr);
|
||||
sqlite3VdbeJumpHere(v, jumpInst2);
|
||||
if( isUpdate ){
|
||||
sqlite3VdbeChangeP2(v, jumpInst1, contAddr);
|
||||
sqlite3VdbeJumpHere(v, jumpInst1);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
|
||||
}
|
||||
@@ -862,7 +946,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
sqlite3VdbeAddOp(v, OP_Dup, i+extra+nCol-idx, 1);
|
||||
}
|
||||
}
|
||||
jumpInst1 = sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24));
|
||||
jumpInst1 = sqlite3VdbeAddOp(v, OP_MakeIdxRec, pIdx->nColumn, 0);
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
|
||||
/* Find out what action to take in case there is an indexing conflict */
|
||||
@@ -880,10 +964,12 @@ void sqlite3GenerateConstraintChecks(
|
||||
|
||||
|
||||
/* Check to see if the new index entry will be unique */
|
||||
sqlite3VdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRecnos, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRowids, 1);
|
||||
jumpInst2 = sqlite3VdbeAddOp(v, OP_IsUnique, base+iCur+1, 0);
|
||||
|
||||
/* Generate code that executes if the new index entry is not unique */
|
||||
assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
|
||||
|| onError==OE_Ignore || onError==OE_Replace );
|
||||
switch( onError ){
|
||||
case OE_Rollback:
|
||||
case OE_Abort:
|
||||
@@ -915,27 +1001,24 @@ void sqlite3GenerateConstraintChecks(
|
||||
}
|
||||
case OE_Ignore: {
|
||||
assert( seenReplace==0 );
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRecnos, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRowids, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
case OE_Replace: {
|
||||
sqlite3GenerateRowDelete(pParse->db, v, pTab, base, 0);
|
||||
if( isUpdate ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRecnos, 1);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRowids, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
|
||||
}
|
||||
seenReplace = 1;
|
||||
break;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
contAddr = sqlite3VdbeCurrentAddr(v);
|
||||
assert( contAddr<(1<<24) );
|
||||
#if NULL_DISTINCT_FOR_UNIQUE
|
||||
sqlite3VdbeChangeP2(v, jumpInst1, contAddr | (1<<24));
|
||||
sqlite3VdbeJumpHere(v, jumpInst1);
|
||||
#endif
|
||||
sqlite3VdbeChangeP2(v, jumpInst2, contAddr);
|
||||
sqlite3VdbeJumpHere(v, jumpInst2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -943,7 +1026,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
** This routine generates code to finish the INSERT or UPDATE operation
|
||||
** that was started by a prior call to sqlite3GenerateConstraintChecks.
|
||||
** The stack must contain keys for all active indices followed by data
|
||||
** and the recno for the new entry. This routine creates the new
|
||||
** and the rowid for the new entry. This routine creates the new
|
||||
** entries in all indices and in the main table.
|
||||
**
|
||||
** The arguments to this routine should be the same as the first six
|
||||
@@ -954,7 +1037,7 @@ void sqlite3CompleteInsertion(
|
||||
Table *pTab, /* the table into which we are inserting */
|
||||
int base, /* Index of a read/write cursor pointing at pTab */
|
||||
char *aIdxUsed, /* Which indices are used. NULL means all are used */
|
||||
int recnoChng, /* True if the record number will change */
|
||||
int rowidChng, /* True if the record number will change */
|
||||
int isUpdate, /* True for UPDATE, False for INSERT */
|
||||
int newIdx /* Index of NEW table for triggers. -1 if none */
|
||||
){
|
||||
@@ -970,19 +1053,25 @@ void sqlite3CompleteInsertion(
|
||||
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
|
||||
for(i=nIdx-1; i>=0; i--){
|
||||
if( aIdxUsed && aIdxUsed[i]==0 ) continue;
|
||||
sqlite3VdbeAddOp(v, OP_IdxPut, base+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_IdxInsert, base+i+1, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
if( newIdx>=0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
|
||||
}
|
||||
pik_flags = (OPFLAG_NCHANGE|(isUpdate?0:OPFLAG_LASTROWID));
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, base, pik_flags);
|
||||
#endif
|
||||
if( pParse->nested ){
|
||||
pik_flags = 0;
|
||||
}else{
|
||||
pik_flags = (OPFLAG_NCHANGE|(isUpdate?0:OPFLAG_LASTROWID));
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Insert, base, pik_flags);
|
||||
|
||||
if( isUpdate && recnoChng ){
|
||||
if( isUpdate && rowidChng ){
|
||||
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
|
||||
}
|
||||
}
|
||||
@@ -1003,10 +1092,12 @@ void sqlite3OpenTableAndIndices(
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
VdbeComment((v, "# %s", pTab->zName));
|
||||
sqlite3VdbeAddOp(v, op, base, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, base, pTab->nCol);
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
VdbeComment((v, "# %s", pIdx->zName));
|
||||
sqlite3VdbeOp3(v, op, i+base, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
}
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@
|
||||
** other files are for internal use by SQLite and should not be
|
||||
** accessed by users of the library.
|
||||
**
|
||||
** $Id: legacy.c,v 1.5 2004/08/08 23:39:19 drh Exp $
|
||||
** $Id: legacy.c,v 1.7 2004/09/06 17:34:13 drh Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
@@ -32,9 +32,9 @@
|
||||
** is invoked, even for queries.
|
||||
*/
|
||||
int sqlite3_exec(
|
||||
sqlite *db, /* The database on which the SQL executes */
|
||||
sqlite3 *db, /* The database on which the SQL executes */
|
||||
const char *zSql, /* The SQL to be executed */
|
||||
sqlite_callback xCallback, /* Invoke this callback routine */
|
||||
sqlite3_callback xCallback, /* Invoke this callback routine */
|
||||
void *pArg, /* First argument to xCallback() */
|
||||
char **pzErrMsg /* Write error messages here */
|
||||
){
|
||||
|
||||
+324
-620
File diff suppressed because it is too large
Load Diff
@@ -23,32 +23,20 @@
|
||||
** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
|
||||
** The MacOS build is designed to use CodeWarrior (tested with v8)
|
||||
*/
|
||||
#if !defined(OS_UNIX) && !defined(OS_TEST)
|
||||
#if !defined(OS_UNIX) && !defined(OS_TEST) && !defined(OS_OTHER)
|
||||
# define OS_OTHER 0
|
||||
# ifndef OS_WIN
|
||||
# ifndef OS_MAC
|
||||
# if defined(__MACOS__)
|
||||
# define OS_MAC 1
|
||||
# define OS_WIN 0
|
||||
# define OS_UNIX 0
|
||||
# elif defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
|
||||
# define OS_MAC 0
|
||||
# define OS_WIN 1
|
||||
# define OS_UNIX 0
|
||||
# else
|
||||
# define OS_MAC 0
|
||||
# define OS_WIN 0
|
||||
# define OS_UNIX 1
|
||||
# endif
|
||||
# else
|
||||
# define OS_WIN 0
|
||||
# define OS_UNIX 0
|
||||
# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
|
||||
# define OS_WIN 1
|
||||
# define OS_UNIX 0
|
||||
# else
|
||||
# define OS_WIN 0
|
||||
# define OS_UNIX 1
|
||||
# endif
|
||||
# else
|
||||
# define OS_MAC 0
|
||||
# define OS_UNIX 0
|
||||
# endif
|
||||
#else
|
||||
# define OS_MAC 0
|
||||
# ifndef OS_WIN
|
||||
# define OS_WIN 0
|
||||
# endif
|
||||
@@ -66,8 +54,20 @@
|
||||
#if OS_WIN
|
||||
# include "os_win.h"
|
||||
#endif
|
||||
#if OS_MAC
|
||||
# include "os_mac.h"
|
||||
|
||||
/* os_other.c and os_other.h are not delivered with SQLite. These files
|
||||
** are place-holders that can be filled in by third-party developers to
|
||||
** implement backends to their on proprietary operating systems.
|
||||
*/
|
||||
#if OS_OTHER
|
||||
# include "os_other.h"
|
||||
#endif
|
||||
|
||||
/* If the SET_FULLSYNC macro is not defined above, then make it
|
||||
** a no-op
|
||||
*/
|
||||
#ifndef SET_FULLSYNC
|
||||
# define SET_FULLSYNC(x,y)
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -161,8 +161,13 @@
|
||||
** 1GB boundary.
|
||||
**
|
||||
*/
|
||||
#ifndef SQLITE_TEST
|
||||
#define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
|
||||
/* #define PENDING_BYTE 0x5400 // Page 20 - for testing */
|
||||
#else
|
||||
extern unsigned int sqlite3_pending_byte;
|
||||
#define PENDING_BYTE sqlite3_pending_byte
|
||||
#endif
|
||||
|
||||
#define RESERVED_BYTE (PENDING_BYTE+1)
|
||||
#define SHARED_FIRST (PENDING_BYTE+2)
|
||||
#define SHARED_SIZE 510
|
||||
@@ -176,22 +181,27 @@ int sqlite3OsOpenReadOnly(const char*, OsFile*);
|
||||
int sqlite3OsOpenDirectory(const char*, OsFile*);
|
||||
int sqlite3OsSyncDirectory(const char*);
|
||||
int sqlite3OsTempFileName(char*);
|
||||
int sqlite3OsIsDirWritable(char*);
|
||||
int sqlite3OsClose(OsFile*);
|
||||
int sqlite3OsRead(OsFile*, void*, int amt);
|
||||
int sqlite3OsWrite(OsFile*, const void*, int amt);
|
||||
int sqlite3OsSeek(OsFile*, off_t offset);
|
||||
int sqlite3OsSync(OsFile*);
|
||||
int sqlite3OsTruncate(OsFile*, off_t size);
|
||||
int sqlite3OsFileSize(OsFile*, off_t *pSize);
|
||||
int sqlite3OsRandomSeed(char*);
|
||||
int sqlite3OsSleep(int ms);
|
||||
int sqlite3OsCurrentTime(double*);
|
||||
int sqlite3OsFileModTime(OsFile*, double*);
|
||||
void sqlite3OsEnterMutex(void);
|
||||
void sqlite3OsLeaveMutex(void);
|
||||
int sqlite3OsSeek(OsFile*, i64 offset);
|
||||
int sqlite3OsSync(OsFile*, int);
|
||||
int sqlite3OsTruncate(OsFile*, i64 size);
|
||||
int sqlite3OsFileSize(OsFile*, i64 *pSize);
|
||||
char *sqlite3OsFullPathname(const char*);
|
||||
int sqlite3OsLock(OsFile*, int);
|
||||
int sqlite3OsUnlock(OsFile*, int);
|
||||
int sqlite3OsCheckReservedLock(OsFile *id);
|
||||
|
||||
|
||||
/* The interface for file I/O is above. Other miscellaneous functions
|
||||
** are below */
|
||||
|
||||
int sqlite3OsRandomSeed(char*);
|
||||
int sqlite3OsSleep(int ms);
|
||||
int sqlite3OsCurrentTime(double*);
|
||||
void sqlite3OsEnterMutex(void);
|
||||
void sqlite3OsLeaveMutex(void);
|
||||
|
||||
#endif /* _SQLITE_OS_H_ */
|
||||
|
||||
@@ -28,6 +28,14 @@
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* When testing, this global variable stores the location of the
|
||||
* pending-byte in the database file.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
unsigned int sqlite3_pending_byte = 0x40000000;
|
||||
#endif
|
||||
|
||||
int sqlite3_os_trace = 0;
|
||||
#ifdef SQLITE_DEBUG
|
||||
static int last_page = 0;
|
||||
@@ -81,14 +89,27 @@ static unsigned int elapse;
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_io_error_pending = 0;
|
||||
int sqlite3_diskfull_pending = 0;
|
||||
int sqlite3_diskfull = 0;
|
||||
#define SimulateIOError(A) \
|
||||
if( sqlite3_io_error_pending ) \
|
||||
if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
|
||||
static void local_ioerr(){
|
||||
sqlite3_io_error_pending = 0; /* Really just a place to set a breakpoint */
|
||||
}
|
||||
#define SimulateDiskfullError \
|
||||
if( sqlite3_diskfull_pending ){ \
|
||||
if( sqlite3_diskfull_pending == 1 ){ \
|
||||
local_ioerr(); \
|
||||
sqlite3_diskfull = 1; \
|
||||
return SQLITE_FULL; \
|
||||
}else{ \
|
||||
sqlite3_diskfull_pending--; \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define SimulateIOError(A)
|
||||
#define SimulateDiskfullError
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
-738
@@ -1,738 +0,0 @@
|
||||
/*
|
||||
** 2004 May 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 code that is specific classic mac. Mac OS X
|
||||
** uses the os_unix.c file, not this one.
|
||||
*/
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
#if OS_MAC /* This file used on classic mac only */
|
||||
#include "sqliteInt.h"
|
||||
|
||||
#include <extras.h>
|
||||
#include <path2fss.h>
|
||||
#include <TextUtils.h>
|
||||
#include <FinderRegistry.h>
|
||||
#include <Folders.h>
|
||||
#include <Timer.h>
|
||||
#include <OSUtils.h>
|
||||
|
||||
/*
|
||||
** Macros used to determine whether or not to use threads.
|
||||
*/
|
||||
#if defined(THREADSAFE) && THREADSAFE
|
||||
# include <Multiprocessing.h>
|
||||
# define SQLITE_MACOS_MULTITASKING 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Include code that is common to all os_*.c files
|
||||
*/
|
||||
#include "os_common.h"
|
||||
|
||||
/*
|
||||
** Delete the named file
|
||||
*/
|
||||
int sqlite3OsDelete(const char *zFilename){
|
||||
unlink(zFilename);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return TRUE if the named file exists.
|
||||
*/
|
||||
int sqlite3OsFileExists(const char *zFilename){
|
||||
return access(zFilename, 0)==0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to open a file for both reading and writing. If that
|
||||
** fails, try opening it read-only. If the file does not exist,
|
||||
** try to create it.
|
||||
**
|
||||
** On success, a handle for the open file is written to *id
|
||||
** and *pReadonly is set to 0 if the file was opened for reading and
|
||||
** writing or 1 if the file was opened read-only. The function returns
|
||||
** SQLITE_OK.
|
||||
**
|
||||
** On failure, the function returns SQLITE_CANTOPEN and leaves
|
||||
** *id and *pReadonly unchanged.
|
||||
*/
|
||||
int sqlite3OsOpenReadWrite(
|
||||
const char *zFilename,
|
||||
OsFile *id,
|
||||
int *pReadonly
|
||||
){
|
||||
FSSpec fsSpec;
|
||||
# ifdef _LARGE_FILE
|
||||
HFSUniStr255 dfName;
|
||||
FSRef fsRef;
|
||||
if( __path2fss(zFilename, &fsSpec) != noErr ){
|
||||
if( HCreate(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, 'SQLI', cDocumentFile) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
if( FSpMakeFSRef(&fsSpec, &fsRef) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
FSGetDataForkName(&dfName);
|
||||
if( FSOpenFork(&fsRef, dfName.length, dfName.unicode,
|
||||
fsRdWrShPerm, &(id->refNum)) != noErr ){
|
||||
if( FSOpenFork(&fsRef, dfName.length, dfName.unicode,
|
||||
fsRdWrPerm, &(id->refNum)) != noErr ){
|
||||
if (FSOpenFork(&fsRef, dfName.length, dfName.unicode,
|
||||
fsRdPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
else
|
||||
*pReadonly = 1;
|
||||
} else
|
||||
*pReadonly = 0;
|
||||
} else
|
||||
*pReadonly = 0;
|
||||
# else
|
||||
__path2fss(zFilename, &fsSpec);
|
||||
if( !sqlite3OsFileExists(zFilename) ){
|
||||
if( HCreate(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, 'SQLI', cDocumentFile) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
if( HOpenDF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdWrShPerm, &(id->refNum)) != noErr ){
|
||||
if( HOpenDF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdWrPerm, &(id->refNum)) != noErr ){
|
||||
if( HOpenDF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
else
|
||||
*pReadonly = 1;
|
||||
} else
|
||||
*pReadonly = 0;
|
||||
} else
|
||||
*pReadonly = 0;
|
||||
# endif
|
||||
if( HOpenRF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdWrShPerm, &(id->refNumRF)) != noErr){
|
||||
id->refNumRF = -1;
|
||||
}
|
||||
id->locked = 0;
|
||||
id->delOnClose = 0;
|
||||
OpenCounter(+1);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Attempt to open a new file for exclusive access by this process.
|
||||
** The file will be opened for both reading and writing. To avoid
|
||||
** a potential security problem, we do not allow the file to have
|
||||
** previously existed. Nor do we allow the file to be a symbolic
|
||||
** link.
|
||||
**
|
||||
** If delFlag is true, then make arrangements to automatically delete
|
||||
** the file when it is closed.
|
||||
**
|
||||
** On success, write the file handle into *id and return SQLITE_OK.
|
||||
**
|
||||
** On failure, return SQLITE_CANTOPEN.
|
||||
*/
|
||||
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
FSSpec fsSpec;
|
||||
# ifdef _LARGE_FILE
|
||||
HFSUniStr255 dfName;
|
||||
FSRef fsRef;
|
||||
__path2fss(zFilename, &fsSpec);
|
||||
if( HCreate(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, 'SQLI', cDocumentFile) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
if( FSpMakeFSRef(&fsSpec, &fsRef) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
FSGetDataForkName(&dfName);
|
||||
if( FSOpenFork(&fsRef, dfName.length, dfName.unicode,
|
||||
fsRdWrPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
# else
|
||||
__path2fss(zFilename, &fsSpec);
|
||||
if( HCreate(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, 'SQLI', cDocumentFile) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
if( HOpenDF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdWrPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
# endif
|
||||
id->refNumRF = -1;
|
||||
id->locked = 0;
|
||||
id->delOnClose = delFlag;
|
||||
if (delFlag)
|
||||
id->pathToDel = sqlite3OsFullPathname(zFilename);
|
||||
OpenCounter(+1);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to open a new file for read-only access.
|
||||
**
|
||||
** On success, write the file handle into *id and return SQLITE_OK.
|
||||
**
|
||||
** On failure, return SQLITE_CANTOPEN.
|
||||
*/
|
||||
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
|
||||
FSSpec fsSpec;
|
||||
# ifdef _LARGE_FILE
|
||||
HFSUniStr255 dfName;
|
||||
FSRef fsRef;
|
||||
if( __path2fss(zFilename, &fsSpec) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
if( FSpMakeFSRef(&fsSpec, &fsRef) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
FSGetDataForkName(&dfName);
|
||||
if( FSOpenFork(&fsRef, dfName.length, dfName.unicode,
|
||||
fsRdPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
# else
|
||||
__path2fss(zFilename, &fsSpec);
|
||||
if( HOpenDF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdPerm, &(id->refNum)) != noErr )
|
||||
return SQLITE_CANTOPEN;
|
||||
# endif
|
||||
if( HOpenRF(fsSpec.vRefNum, fsSpec.parID, fsSpec.name, fsRdWrShPerm, &(id->refNumRF)) != noErr){
|
||||
id->refNumRF = -1;
|
||||
}
|
||||
id->locked = 0;
|
||||
id->delOnClose = 0;
|
||||
OpenCounter(+1);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to open a file descriptor for the directory that contains a
|
||||
** file. This file descriptor can be used to fsync() the directory
|
||||
** in order to make sure the creation of a new file is actually written
|
||||
** to disk.
|
||||
**
|
||||
** This routine is only meaningful for Unix. It is a no-op under
|
||||
** windows since windows does not support hard links.
|
||||
**
|
||||
** On success, a handle for a previously open file is at *id is
|
||||
** updated with the new directory file descriptor and SQLITE_OK is
|
||||
** returned.
|
||||
**
|
||||
** On failure, the function returns SQLITE_CANTOPEN and leaves
|
||||
** *id unchanged.
|
||||
*/
|
||||
int sqlite3OsOpenDirectory(
|
||||
const char *zDirname,
|
||||
OsFile *id
|
||||
){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a temporary file name in zBuf. zBuf must be big enough to
|
||||
** hold at least SQLITE_TEMPNAME_SIZE characters.
|
||||
*/
|
||||
int sqlite3OsTempFileName(char *zBuf){
|
||||
static char zChars[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"0123456789";
|
||||
int i, j;
|
||||
char zTempPath[SQLITE_TEMPNAME_SIZE];
|
||||
char zdirName[32];
|
||||
CInfoPBRec infoRec;
|
||||
Str31 dirName;
|
||||
memset(&infoRec, 0, sizeof(infoRec));
|
||||
memset(zTempPath, 0, SQLITE_TEMPNAME_SIZE);
|
||||
if( FindFolder(kOnSystemDisk, kTemporaryFolderType, kCreateFolder,
|
||||
&(infoRec.dirInfo.ioVRefNum), &(infoRec.dirInfo.ioDrParID)) == noErr ){
|
||||
infoRec.dirInfo.ioNamePtr = dirName;
|
||||
do{
|
||||
infoRec.dirInfo.ioFDirIndex = -1;
|
||||
infoRec.dirInfo.ioDrDirID = infoRec.dirInfo.ioDrParID;
|
||||
if( PBGetCatInfoSync(&infoRec) == noErr ){
|
||||
CopyPascalStringToC(dirName, zdirName);
|
||||
i = strlen(zdirName);
|
||||
memmove(&(zTempPath[i+1]), zTempPath, strlen(zTempPath));
|
||||
strcpy(zTempPath, zdirName);
|
||||
zTempPath[i] = ':';
|
||||
}else{
|
||||
*zTempPath = 0;
|
||||
break;
|
||||
}
|
||||
} while( infoRec.dirInfo.ioDrDirID != fsRtDirID );
|
||||
}
|
||||
if( *zTempPath == 0 )
|
||||
getcwd(zTempPath, SQLITE_TEMPNAME_SIZE-24);
|
||||
for(;;){
|
||||
sprintf(zBuf, "%s"TEMP_FILE_PREFIX, zTempPath);
|
||||
j = strlen(zBuf);
|
||||
sqlite3Randomness(15, &zBuf[j]);
|
||||
for(i=0; i<15; i++, j++){
|
||||
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
|
||||
}
|
||||
zBuf[j] = 0;
|
||||
if( !sqlite3OsFileExists(zBuf) ) break;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close a file.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile *id){
|
||||
if( id->refNumRF!=-1 )
|
||||
FSClose(id->refNumRF);
|
||||
# ifdef _LARGE_FILE
|
||||
FSCloseFork(id->refNum);
|
||||
# else
|
||||
FSClose(id->refNum);
|
||||
# endif
|
||||
if( id->delOnClose ){
|
||||
unlink(id->pathToDel);
|
||||
sqliteFree(id->pathToDel);
|
||||
}
|
||||
OpenCounter(-1);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Read data from a file into a buffer. Return SQLITE_OK if all
|
||||
** bytes were read successfully and SQLITE_IOERR if anything goes
|
||||
** wrong.
|
||||
*/
|
||||
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
int got;
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
TRACE2("READ %d\n", last_page);
|
||||
# ifdef _LARGE_FILE
|
||||
FSReadFork(id->refNum, fsAtMark, 0, (ByteCount)amt, pBuf, (ByteCount*)&got);
|
||||
# else
|
||||
got = amt;
|
||||
FSRead(id->refNum, &got, pBuf);
|
||||
# endif
|
||||
if( got==amt ){
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Write data from a buffer into a file. Return SQLITE_OK on success
|
||||
** or some other error code on failure.
|
||||
*/
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
OSErr oserr;
|
||||
int wrote = 0;
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
TRACE2("WRITE %d\n", last_page);
|
||||
while( amt>0 ){
|
||||
# ifdef _LARGE_FILE
|
||||
oserr = FSWriteFork(id->refNum, fsAtMark, 0,
|
||||
(ByteCount)amt, pBuf, (ByteCount*)&wrote);
|
||||
# else
|
||||
wrote = amt;
|
||||
oserr = FSWrite(id->refNum, &wrote, pBuf);
|
||||
# endif
|
||||
if( wrote == 0 || oserr != noErr)
|
||||
break;
|
||||
amt -= wrote;
|
||||
pBuf = &((char*)pBuf)[wrote];
|
||||
}
|
||||
if( oserr != noErr || amt>wrote ){
|
||||
return SQLITE_FULL;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Move the read/write pointer in a file.
|
||||
*/
|
||||
int sqlite3OsSeek(OsFile *id, off_t offset){
|
||||
off_t curSize;
|
||||
SEEK(offset/1024 + 1);
|
||||
if( sqlite3OsFileSize(id, &curSize) != SQLITE_OK ){
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
if( offset >= curSize ){
|
||||
if( sqlite3OsTruncate(id, offset+1) != SQLITE_OK ){
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
}
|
||||
# ifdef _LARGE_FILE
|
||||
if( FSSetForkPosition(id->refNum, fsFromStart, offset) != noErr ){
|
||||
# else
|
||||
if( SetFPos(id->refNum, fsFromStart, offset) != noErr ){
|
||||
# endif
|
||||
return SQLITE_IOERR;
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Make sure all writes to a particular file are committed to disk.
|
||||
**
|
||||
** Under Unix, also make sure that the directory entry for the file
|
||||
** has been created by fsync-ing the directory that contains the file.
|
||||
** If we do not do this and we encounter a power failure, the directory
|
||||
** entry for the journal might not exist after we reboot. The next
|
||||
** SQLite to access the file will not know that the journal exists (because
|
||||
** the directory entry for the journal was never created) and the transaction
|
||||
** will not roll back - possibly leading to database corruption.
|
||||
*/
|
||||
int sqlite3OsSync(OsFile *id){
|
||||
# ifdef _LARGE_FILE
|
||||
if( FSFlushFork(id->refNum) != noErr ){
|
||||
# else
|
||||
ParamBlockRec params;
|
||||
memset(¶ms, 0, sizeof(ParamBlockRec));
|
||||
params.ioParam.ioRefNum = id->refNum;
|
||||
if( PBFlushFileSync(¶ms) != noErr ){
|
||||
# endif
|
||||
return SQLITE_IOERR;
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Sync the directory zDirname. This is a no-op on operating systems other
|
||||
** than UNIX.
|
||||
*/
|
||||
int sqlite3OsSyncDirectory(const char *zDirname){
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate an open file to a specified size
|
||||
*/
|
||||
int sqlite3OsTruncate(OsFile *id, off_t nByte){
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
# ifdef _LARGE_FILE
|
||||
if( FSSetForkSize(id->refNum, fsFromStart, nByte) != noErr){
|
||||
# else
|
||||
if( SetEOF(id->refNum, nByte) != noErr ){
|
||||
# endif
|
||||
return SQLITE_IOERR;
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Determine the current size of a file in bytes
|
||||
*/
|
||||
int sqlite3OsFileSize(OsFile *id, off_t *pSize){
|
||||
# ifdef _LARGE_FILE
|
||||
if( FSGetForkSize(id->refNum, pSize) != noErr){
|
||||
# else
|
||||
if( GetEOF(id->refNum, pSize) != noErr ){
|
||||
# endif
|
||||
return SQLITE_IOERR;
|
||||
}else{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Windows file locking notes: [similar issues apply to MacOS]
|
||||
**
|
||||
** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
|
||||
** those functions are not available. So we use only LockFile() and
|
||||
** UnlockFile().
|
||||
**
|
||||
** LockFile() prevents not just writing but also reading by other processes.
|
||||
** (This is a design error on the part of Windows, but there is nothing
|
||||
** we can do about that.) So the region used for locking is at the
|
||||
** end of the file where it is unlikely to ever interfere with an
|
||||
** actual read attempt.
|
||||
**
|
||||
** A database read lock is obtained by locking a single randomly-chosen
|
||||
** byte out of a specific range of bytes. The lock byte is obtained at
|
||||
** random so two separate readers can probably access the file at the
|
||||
** same time, unless they are unlucky and choose the same lock byte.
|
||||
** A database write lock is obtained by locking all bytes in the range.
|
||||
** There can only be one writer.
|
||||
**
|
||||
** A lock is obtained on the first byte of the lock range before acquiring
|
||||
** either a read lock or a write lock. This prevents two processes from
|
||||
** attempting to get a lock at a same time. The semantics of
|
||||
** sqlite3OsReadLock() require that if there is already a write lock, that
|
||||
** lock is converted into a read lock atomically. The lock on the first
|
||||
** byte allows us to drop the old write lock and get the read lock without
|
||||
** another process jumping into the middle and messing us up. The same
|
||||
** argument applies to sqlite3OsWriteLock().
|
||||
**
|
||||
** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
|
||||
** which means we can use reader/writer locks. When reader writer locks
|
||||
** are used, the lock is placed on the same range of bytes that is used
|
||||
** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
|
||||
** will support two or more Win95 readers or two or more WinNT readers.
|
||||
** But a single Win95 reader will lock out all WinNT readers and a single
|
||||
** WinNT reader will lock out all other Win95 readers.
|
||||
**
|
||||
** Note: On MacOS we use the resource fork for locking.
|
||||
**
|
||||
** The following #defines specify the range of bytes used for locking.
|
||||
** N_LOCKBYTE is the number of bytes available for doing the locking.
|
||||
** The first byte used to hold the lock while the lock is changing does
|
||||
** not count toward this number. FIRST_LOCKBYTE is the address of
|
||||
** the first byte in the range of bytes used for locking.
|
||||
*/
|
||||
#define N_LOCKBYTE 10239
|
||||
#define FIRST_LOCKBYTE (0x000fffff - N_LOCKBYTE)
|
||||
|
||||
/*
|
||||
** Change the status of the lock on the file "id" to be a readlock.
|
||||
** If the file was write locked, then this reduces the lock to a read.
|
||||
** If the file was read locked, then this acquires a new read lock.
|
||||
**
|
||||
** Return SQLITE_OK on success and SQLITE_BUSY on failure. If this
|
||||
** library was compiled with large file support (LFS) but LFS is not
|
||||
** available on the host, then an SQLITE_NOLFS is returned.
|
||||
*/
|
||||
int sqlite3OsReadLock(OsFile *id){
|
||||
int rc;
|
||||
if( id->locked>0 || id->refNumRF == -1 ){
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
int lk;
|
||||
OSErr res;
|
||||
int cnt = 5;
|
||||
ParamBlockRec params;
|
||||
sqlite3Randomness(sizeof(lk), &lk);
|
||||
lk = (lk & 0x7fffffff)%N_LOCKBYTE + 1;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.ioParam.ioRefNum = id->refNumRF;
|
||||
params.ioParam.ioPosMode = fsFromStart;
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
while( cnt-->0 && (res = PBLockRangeSync(¶ms))!=noErr ){
|
||||
UInt32 finalTicks;
|
||||
Delay(1, &finalTicks); /* 1/60 sec */
|
||||
}
|
||||
if( res == noErr ){
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE+1;
|
||||
params.ioParam.ioReqCount = N_LOCKBYTE;
|
||||
PBUnlockRangeSync(¶ms);
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE+lk;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
res = PBLockRangeSync(¶ms);
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
PBUnlockRangeSync(¶ms);
|
||||
}
|
||||
if( res == noErr ){
|
||||
id->locked = lk;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
rc = SQLITE_BUSY;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the lock status to be an exclusive or write lock. Return
|
||||
** SQLITE_OK on success and SQLITE_BUSY on a failure. If this
|
||||
** library was compiled with large file support (LFS) but LFS is not
|
||||
** available on the host, then an SQLITE_NOLFS is returned.
|
||||
*/
|
||||
int sqlite3OsWriteLock(OsFile *id){
|
||||
int rc;
|
||||
if( id->locked<0 || id->refNumRF == -1 ){
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
OSErr res;
|
||||
int cnt = 5;
|
||||
ParamBlockRec params;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.ioParam.ioRefNum = id->refNumRF;
|
||||
params.ioParam.ioPosMode = fsFromStart;
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
while( cnt-->0 && (res = PBLockRangeSync(¶ms))!=noErr ){
|
||||
UInt32 finalTicks;
|
||||
Delay(1, &finalTicks); /* 1/60 sec */
|
||||
}
|
||||
if( res == noErr ){
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE + id->locked;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
if( id->locked==0
|
||||
|| PBUnlockRangeSync(¶ms)==noErr ){
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE+1;
|
||||
params.ioParam.ioReqCount = N_LOCKBYTE;
|
||||
res = PBLockRangeSync(¶ms);
|
||||
}else{
|
||||
res = afpRangeNotLocked;
|
||||
}
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
PBUnlockRangeSync(¶ms);
|
||||
}
|
||||
if( res == noErr ){
|
||||
id->locked = -1;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
rc = SQLITE_BUSY;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Unlock the given file descriptor. If the file descriptor was
|
||||
** not previously locked, then this routine is a no-op. If this
|
||||
** library was compiled with large file support (LFS) but LFS is not
|
||||
** available on the host, then an SQLITE_NOLFS is returned.
|
||||
*/
|
||||
int sqlite3OsUnlock(OsFile *id){
|
||||
int rc;
|
||||
ParamBlockRec params;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.ioParam.ioRefNum = id->refNumRF;
|
||||
params.ioParam.ioPosMode = fsFromStart;
|
||||
if( id->locked==0 || id->refNumRF == -1 ){
|
||||
rc = SQLITE_OK;
|
||||
}else if( id->locked<0 ){
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE+1;
|
||||
params.ioParam.ioReqCount = N_LOCKBYTE;
|
||||
PBUnlockRangeSync(¶ms);
|
||||
rc = SQLITE_OK;
|
||||
id->locked = 0;
|
||||
}else{
|
||||
params.ioParam.ioPosOffset = FIRST_LOCKBYTE+id->locked;
|
||||
params.ioParam.ioReqCount = 1;
|
||||
PBUnlockRangeSync(¶ms);
|
||||
rc = SQLITE_OK;
|
||||
id->locked = 0;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Get information to seed the random number generator. The seed
|
||||
** is written into the buffer zBuf[256]. The calling function must
|
||||
** supply a sufficiently large buffer.
|
||||
*/
|
||||
int sqlite3OsRandomSeed(char *zBuf){
|
||||
/* We have to initialize zBuf to prevent valgrind from reporting
|
||||
** errors. The reports issued by valgrind are incorrect - we would
|
||||
** prefer that the randomness be increased by making use of the
|
||||
** uninitialized space in zBuf - but valgrind errors tend to worry
|
||||
** some users. Rather than argue, it seems easier just to initialize
|
||||
** the whole array and silence valgrind, even if that means less randomness
|
||||
** in the random seed.
|
||||
**
|
||||
** When testing, initializing zBuf[] to zero is all we do. That means
|
||||
** that we always use the same random number sequence.* This makes the
|
||||
** tests repeatable.
|
||||
*/
|
||||
memset(zBuf, 0, 256);
|
||||
#if !defined(SQLITE_TEST)
|
||||
{
|
||||
int pid;
|
||||
Microseconds((UnsignedWide*)zBuf);
|
||||
pid = getpid();
|
||||
memcpy(&zBuf[sizeof(UnsignedWide)], &pid, sizeof(pid));
|
||||
}
|
||||
#endif
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sleep for a little while. Return the amount of time slept.
|
||||
*/
|
||||
int sqlite3OsSleep(int ms){
|
||||
UInt32 finalTicks;
|
||||
UInt32 ticks = (((UInt32)ms+16)*3)/50; /* 1/60 sec per tick */
|
||||
Delay(ticks, &finalTicks);
|
||||
return (int)((ticks*50)/3);
|
||||
}
|
||||
|
||||
/*
|
||||
** Static variables used for thread synchronization
|
||||
*/
|
||||
static int inMutex = 0;
|
||||
#ifdef SQLITE_MACOS_MULTITASKING
|
||||
static MPCriticalRegionID criticalRegion;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The following pair of routine implement mutual exclusion for
|
||||
** multi-threaded processes. Only a single thread is allowed to
|
||||
** executed code that is surrounded by EnterMutex() and LeaveMutex().
|
||||
**
|
||||
** SQLite uses only a single Mutex. There is not much critical
|
||||
** code and what little there is executes quickly and without blocking.
|
||||
*/
|
||||
void sqlite3OsEnterMutex(){
|
||||
#ifdef SQLITE_MACOS_MULTITASKING
|
||||
static volatile int notInit = 1;
|
||||
if( notInit ){
|
||||
if( notInit == 2 ) /* as close as you can get to thread safe init */
|
||||
MPYield();
|
||||
else{
|
||||
notInit = 2;
|
||||
MPCreateCriticalRegion(&criticalRegion);
|
||||
notInit = 0;
|
||||
}
|
||||
}
|
||||
MPEnterCriticalRegion(criticalRegion, kDurationForever);
|
||||
#endif
|
||||
assert( !inMutex );
|
||||
inMutex = 1;
|
||||
}
|
||||
void sqlite3OsLeaveMutex(){
|
||||
assert( inMutex );
|
||||
inMutex = 0;
|
||||
#ifdef SQLITE_MACOS_MULTITASKING
|
||||
MPExitCriticalRegion(criticalRegion);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Turn a relative pathname into a full pathname. Return a pointer
|
||||
** to the full pathname stored in space obtained from sqliteMalloc().
|
||||
** The calling function is responsible for freeing this space once it
|
||||
** is no longer needed.
|
||||
*/
|
||||
char *sqlite3OsFullPathname(const char *zRelative){
|
||||
char *zFull = 0;
|
||||
if( zRelative[0]==':' ){
|
||||
char zBuf[_MAX_PATH+1];
|
||||
sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), &(zRelative[1]),
|
||||
(char*)0);
|
||||
}else{
|
||||
if( strchr(zRelative, ':') ){
|
||||
sqlite3SetString(&zFull, zRelative, (char*)0);
|
||||
}else{
|
||||
char zBuf[_MAX_PATH+1];
|
||||
sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), zRelative, (char*)0);
|
||||
}
|
||||
}
|
||||
return zFull;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following variable, if set to a non-zero value, becomes the result
|
||||
** returned from sqlite3OsCurrentTime(). This is used for testing.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_current_time = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Find the current time (in Universal Coordinated Time). Write the
|
||||
** current time and date as a Julian Day number into *prNow and
|
||||
** return 0. Return 1 if the time and date cannot be found.
|
||||
*/
|
||||
int sqlite3OsCurrentTime(double *prNow){
|
||||
*prNow = 0.0; /**** FIX ME *****/
|
||||
#ifdef SQLITE_TEST
|
||||
if( sqlite3_current_time ){
|
||||
*prNow = sqlite3_current_time/86400.0 + 2440587.5;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* OS_MAC */
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
** 2004 May 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 header file defines OS-specific features of classic Mac.
|
||||
** OS X uses the os_unix.h file, not this one.
|
||||
*/
|
||||
#ifndef _SQLITE_OS_MAC_H_
|
||||
#define _SQLITE_OS_MAC_H_
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <Files.h>
|
||||
#ifdef _LARGE_FILE
|
||||
typedef SInt64 off_t;
|
||||
#else
|
||||
typedef SInt32 off_t;
|
||||
#endif
|
||||
#define SQLITE_TEMPNAME_SIZE _MAX_PATH
|
||||
#define SQLITE_MIN_SLEEP_MS 17
|
||||
|
||||
/*
|
||||
** The OsFile structure is a operating-system independing representation
|
||||
** of an open file handle. It is defined differently for each architecture.
|
||||
**
|
||||
** This is the definition for class Mac.
|
||||
*/
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
SInt16 refNum; /* Data fork/file reference number */
|
||||
SInt16 refNumRF; /* Resource fork reference number (for locking) */
|
||||
int locked; /* 0: unlocked, <0: write lock, >0: read lock */
|
||||
int delOnClose; /* True if file is to be deleted on close */
|
||||
char *pathToDel; /* Name of file to delete on close */
|
||||
};
|
||||
|
||||
|
||||
#endif /* _SQLITE_OS_MAC_H_ */
|
||||
-461
@@ -1,461 +0,0 @@
|
||||
/*
|
||||
** 2004 May 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 code that is specific to Unix systems. It is used
|
||||
** for testing SQLite only.
|
||||
*/
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
#if OS_TEST /* This file is used for the test backend only */
|
||||
#include "sqliteInt.h"
|
||||
|
||||
#define sqlite3OsOpenReadWrite sqlite3RealOpenReadWrite
|
||||
#define sqlite3OsOpenExclusive sqlite3RealOpenExclusive
|
||||
#define sqlite3OsOpenReadOnly sqlite3RealOpenReadOnly
|
||||
#define sqlite3OsOpenDirectory sqlite3RealOpenDirectory
|
||||
#define sqlite3OsClose sqlite3RealClose
|
||||
#define sqlite3OsRead sqlite3RealRead
|
||||
#define sqlite3OsWrite sqlite3RealWrite
|
||||
#define sqlite3OsSeek sqlite3RealSeek
|
||||
#define sqlite3OsSync sqlite3RealSync
|
||||
#define sqlite3OsTruncate sqlite3RealTruncate
|
||||
#define sqlite3OsFileSize sqlite3RealFileSize
|
||||
#define sqlite3OsLock sqlite3RealLock
|
||||
#define sqlite3OsUnlock sqlite3RealUnlock
|
||||
#define sqlite3OsCheckReservedLock sqlite3RealCheckReservedLock
|
||||
|
||||
#define OsFile OsRealFile
|
||||
#define OS_UNIX 1
|
||||
#include "os_unix.c"
|
||||
#undef OS_UNIX
|
||||
#undef OsFile
|
||||
|
||||
#undef sqlite3OsOpenReadWrite
|
||||
#undef sqlite3OsOpenExclusive
|
||||
#undef sqlite3OsOpenReadOnly
|
||||
#undef sqlite3OsOpenDirectory
|
||||
#undef sqlite3OsClose
|
||||
#undef sqlite3OsRead
|
||||
#undef sqlite3OsWrite
|
||||
#undef sqlite3OsSeek
|
||||
#undef sqlite3OsSync
|
||||
#undef sqlite3OsTruncate
|
||||
#undef sqlite3OsFileSize
|
||||
#undef sqlite3OsLock
|
||||
#undef sqlite3OsUnlock
|
||||
#undef sqlite3OsCheckReservedLock
|
||||
|
||||
#define BLOCKSIZE 512
|
||||
#define BLOCK_OFFSET(x) ((x) * BLOCKSIZE)
|
||||
|
||||
|
||||
/*
|
||||
** The following variables control when a simulated crash occurs.
|
||||
**
|
||||
** If iCrashDelay is non-zero, then zCrashFile contains (full path) name of
|
||||
** a file that SQLite will call sqlite3OsSync() on. Each time this happens
|
||||
** iCrashDelay is decremented. If iCrashDelay is zero after being
|
||||
** decremented, a "crash" occurs during the sync() operation.
|
||||
**
|
||||
** In other words, a crash occurs the iCrashDelay'th time zCrashFile is
|
||||
** synced.
|
||||
*/
|
||||
static int iCrashDelay = 0;
|
||||
char zCrashFile[256];
|
||||
|
||||
/*
|
||||
** Set the value of the two crash parameters.
|
||||
*/
|
||||
void sqlite3SetCrashParams(int iDelay, char const *zFile){
|
||||
sqlite3OsEnterMutex();
|
||||
assert( strlen(zFile)<256 );
|
||||
strcpy(zCrashFile, zFile);
|
||||
iCrashDelay = iDelay;
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
|
||||
/*
|
||||
** File zPath is being sync()ed. Return non-zero if this should
|
||||
** cause a crash.
|
||||
*/
|
||||
static int crashRequired(char const *zPath){
|
||||
int r;
|
||||
int n;
|
||||
sqlite3OsEnterMutex();
|
||||
n = strlen(zCrashFile);
|
||||
if( zCrashFile[n-1]=='*' ){
|
||||
n--;
|
||||
}else if( strlen(zPath)>n ){
|
||||
n = strlen(zPath);
|
||||
}
|
||||
r = 0;
|
||||
if( iCrashDelay>0 && strncmp(zPath, zCrashFile, n)==0 ){
|
||||
iCrashDelay--;
|
||||
if( iCrashDelay<=0 ){
|
||||
r = 1;
|
||||
}
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
static OsTestFile *pAllFiles = 0;
|
||||
|
||||
/*
|
||||
** Initialise the os_test.c specific fields of pFile.
|
||||
*/
|
||||
static void initFile(OsFile *id, char const *zName){
|
||||
OsTestFile *pFile = (OsTestFile *)
|
||||
sqliteMalloc(sizeof(OsTestFile) + strlen(zName)+1);
|
||||
pFile->nMaxWrite = 0;
|
||||
pFile->nBlk = 0;
|
||||
pFile->apBlk = 0;
|
||||
pFile->zName = (char *)(&pFile[1]);
|
||||
strcpy(pFile->zName, zName);
|
||||
*id = pFile;
|
||||
pFile->pNext = pAllFiles;
|
||||
pAllFiles = pFile;
|
||||
}
|
||||
|
||||
/*
|
||||
** Undo the work done by initFile. Delete the OsTestFile structure
|
||||
** and unlink the structure from the pAllFiles list.
|
||||
*/
|
||||
static void closeFile(OsFile *id){
|
||||
OsTestFile *pFile = *id;
|
||||
if( pFile==pAllFiles ){
|
||||
pAllFiles = pFile->pNext;
|
||||
}else{
|
||||
OsTestFile *p;
|
||||
for(p=pAllFiles; p->pNext!=pFile; p=p->pNext ){
|
||||
assert( p );
|
||||
}
|
||||
p->pNext = pFile->pNext;
|
||||
}
|
||||
sqliteFree(pFile);
|
||||
*id = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the current seek offset from the start of the file. This
|
||||
** is unix-only code.
|
||||
*/
|
||||
static off_t osTell(OsTestFile *pFile){
|
||||
return lseek(pFile->fd.h, 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
/*
|
||||
** Load block 'blk' into the cache of pFile.
|
||||
*/
|
||||
static int cacheBlock(OsTestFile *pFile, int blk){
|
||||
if( blk>=pFile->nBlk ){
|
||||
int n = ((pFile->nBlk * 2) + 100 + blk);
|
||||
/* if( pFile->nBlk==0 ){ printf("DIRTY %s\n", pFile->zName); } */
|
||||
pFile->apBlk = (u8 **)sqliteRealloc(pFile->apBlk, n * sizeof(u8*));
|
||||
if( !pFile->apBlk ) return SQLITE_NOMEM;
|
||||
memset(&pFile->apBlk[pFile->nBlk], 0, (n - pFile->nBlk)*sizeof(u8*));
|
||||
pFile->nBlk = n;
|
||||
}
|
||||
|
||||
if( !pFile->apBlk[blk] ){
|
||||
off_t filesize;
|
||||
int rc;
|
||||
|
||||
u8 *p = sqliteMalloc(BLOCKSIZE);
|
||||
if( !p ) return SQLITE_NOMEM;
|
||||
pFile->apBlk[blk] = p;
|
||||
|
||||
rc = sqlite3RealFileSize(&pFile->fd, &filesize);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
if( BLOCK_OFFSET(blk)<filesize ){
|
||||
int len = BLOCKSIZE;
|
||||
rc = sqlite3RealSeek(&pFile->fd, blk*BLOCKSIZE);
|
||||
if( BLOCK_OFFSET(blk+1)>filesize ){
|
||||
len = filesize - BLOCK_OFFSET(blk);
|
||||
}
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3RealRead(&pFile->fd, p, len);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* #define TRACE_WRITECACHE */
|
||||
|
||||
/*
|
||||
** Write the cache of pFile to disk. If crash is non-zero, randomly
|
||||
** skip blocks when writing. The cache is deleted before returning.
|
||||
*/
|
||||
static int writeCache2(OsTestFile *pFile, int crash){
|
||||
int i;
|
||||
int nMax = pFile->nMaxWrite;
|
||||
off_t offset;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
offset = osTell(pFile);
|
||||
for(i=0; i<pFile->nBlk; i++){
|
||||
u8 *p = pFile->apBlk[i];
|
||||
if( p ){
|
||||
int skip = 0;
|
||||
int trash = 0;
|
||||
if( crash ){
|
||||
char random;
|
||||
sqlite3Randomness(1, &random);
|
||||
if( random & 0x01 ){
|
||||
if( random & 0x02 ){
|
||||
trash = 1;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Trashing block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}else{
|
||||
skip = 1;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Skiping block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}
|
||||
}else{
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("Writing block %d of %s\n", i, pFile->zName);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3RealSeek(&pFile->fd, BLOCK_OFFSET(i));
|
||||
}
|
||||
if( rc==SQLITE_OK && !skip ){
|
||||
int len = BLOCKSIZE;
|
||||
if( BLOCK_OFFSET(i+1)>nMax ){
|
||||
len = nMax-BLOCK_OFFSET(i);
|
||||
}
|
||||
if( trash ){
|
||||
sqlite3Randomness(len, p);
|
||||
}
|
||||
rc = sqlite3RealWrite(&pFile->fd, p, len);
|
||||
}
|
||||
sqliteFree(p);
|
||||
}
|
||||
}
|
||||
sqliteFree(pFile->apBlk);
|
||||
pFile->nBlk = 0;
|
||||
pFile->apBlk = 0;
|
||||
pFile->nMaxWrite = 0;
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3RealSeek(&pFile->fd, offset);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write the cache to disk.
|
||||
*/
|
||||
static int writeCache(OsTestFile *pFile){
|
||||
if( pFile->apBlk ){
|
||||
int c = crashRequired(pFile->zName);
|
||||
if( c ){
|
||||
OsTestFile *p;
|
||||
#ifdef TRACE_WRITECACHE
|
||||
printf("\nCrash during sync of %s\n", pFile->zName);
|
||||
#endif
|
||||
for(p=pAllFiles; p; p=p->pNext){
|
||||
writeCache2(p, 1);
|
||||
}
|
||||
exit(-1);
|
||||
}else{
|
||||
return writeCache2(pFile, 0);
|
||||
}
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close the file.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile *id){
|
||||
if( !(*id) ) return SQLITE_OK;
|
||||
if( (*id)->fd.isOpen ){
|
||||
/* printf("CLOSE %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */
|
||||
writeCache(*id);
|
||||
sqlite3RealClose(&(*id)->fd);
|
||||
}
|
||||
closeFile(id);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
off_t offset; /* The current offset from the start of the file */
|
||||
off_t end; /* The byte just past the last byte read */
|
||||
int blk; /* Block number the read starts on */
|
||||
int i;
|
||||
u8 *zCsr;
|
||||
int rc = SQLITE_OK;
|
||||
OsTestFile *pFile = *id;
|
||||
|
||||
offset = osTell(pFile);
|
||||
end = offset+amt;
|
||||
blk = (offset/BLOCKSIZE);
|
||||
|
||||
zCsr = (u8 *)pBuf;
|
||||
for(i=blk; i*BLOCKSIZE<end; i++){
|
||||
int off = 0;
|
||||
int len = 0;
|
||||
|
||||
|
||||
if( BLOCK_OFFSET(i) < offset ){
|
||||
off = offset-BLOCK_OFFSET(i);
|
||||
}
|
||||
len = BLOCKSIZE - off;
|
||||
if( BLOCK_OFFSET(i+1) > end ){
|
||||
len = len - (BLOCK_OFFSET(i+1)-end);
|
||||
}
|
||||
|
||||
if( i<pFile->nBlk && pFile->apBlk[i]){
|
||||
u8 *pBlk = pFile->apBlk[i];
|
||||
memcpy(zCsr, &pBlk[off], len);
|
||||
}else{
|
||||
rc = sqlite3RealSeek(&pFile->fd, BLOCK_OFFSET(i) + off);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3RealRead(&pFile->fd, zCsr, len);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
|
||||
zCsr += len;
|
||||
}
|
||||
assert( zCsr==&((u8 *)pBuf)[amt] );
|
||||
|
||||
rc = sqlite3RealSeek(&pFile->fd, end);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
off_t offset; /* The current offset from the start of the file */
|
||||
off_t end; /* The byte just past the last byte written */
|
||||
int blk; /* Block number the write starts on */
|
||||
int i;
|
||||
const u8 *zCsr;
|
||||
int rc = SQLITE_OK;
|
||||
OsTestFile *pFile = *id;
|
||||
|
||||
offset = osTell(pFile);
|
||||
end = offset+amt;
|
||||
blk = (offset/BLOCKSIZE);
|
||||
|
||||
zCsr = (u8 *)pBuf;
|
||||
for(i=blk; i*BLOCKSIZE<end; i++){
|
||||
u8 *pBlk;
|
||||
int off = 0;
|
||||
int len = 0;
|
||||
|
||||
/* Make sure the block is in the cache */
|
||||
rc = cacheBlock(pFile, i);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
/* Write into the cache */
|
||||
pBlk = pFile->apBlk[i];
|
||||
assert( pBlk );
|
||||
|
||||
if( BLOCK_OFFSET(i) < offset ){
|
||||
off = offset-BLOCK_OFFSET(i);
|
||||
}
|
||||
len = BLOCKSIZE - off;
|
||||
if( BLOCK_OFFSET(i+1) > end ){
|
||||
len = len - (BLOCK_OFFSET(i+1)-end);
|
||||
}
|
||||
memcpy(&pBlk[off], zCsr, len);
|
||||
zCsr += len;
|
||||
}
|
||||
if( pFile->nMaxWrite<end ){
|
||||
pFile->nMaxWrite = end;
|
||||
}
|
||||
assert( zCsr==&((u8 *)pBuf)[amt] );
|
||||
|
||||
rc = sqlite3RealSeek(&pFile->fd, end);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sync the file. First flush the write-cache to disk, then call the
|
||||
** real sync() function.
|
||||
*/
|
||||
int sqlite3OsSync(OsFile *id){
|
||||
int rc;
|
||||
/* printf("SYNC %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */
|
||||
rc = writeCache(*id);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3RealSync(&(*id)->fd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate the file. Set the internal OsFile.nMaxWrite variable to the new
|
||||
** file size to ensure that nothing in the write-cache past this point
|
||||
** is written to disk.
|
||||
*/
|
||||
int sqlite3OsTruncate(OsFile *id, off_t nByte){
|
||||
(*id)->nMaxWrite = nByte;
|
||||
return sqlite3RealTruncate(&(*id)->fd, nByte);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the size of the file. If the cache contains a write that extended
|
||||
** the file, then return this size instead of the on-disk size.
|
||||
*/
|
||||
int sqlite3OsFileSize(OsFile *id, off_t *pSize){
|
||||
int rc = sqlite3RealFileSize(&(*id)->fd, pSize);
|
||||
if( rc==SQLITE_OK && pSize && *pSize<(*id)->nMaxWrite ){
|
||||
*pSize = (*id)->nMaxWrite;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** The three functions used to open files. All that is required is to
|
||||
** initialise the os_test.c specific fields and then call the corresponding
|
||||
** os_unix.c function to really open the file.
|
||||
*/
|
||||
int sqlite3OsOpenReadWrite(const char *zFilename, OsFile *id, int *pReadonly){
|
||||
initFile(id, zFilename);
|
||||
return sqlite3RealOpenReadWrite(zFilename, &(*id)->fd, pReadonly);
|
||||
}
|
||||
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
initFile(id, zFilename);
|
||||
return sqlite3RealOpenExclusive(zFilename, &(*id)->fd, delFlag);
|
||||
}
|
||||
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
|
||||
initFile(id, zFilename);
|
||||
return sqlite3RealOpenReadOnly(zFilename, &(*id)->fd);
|
||||
}
|
||||
|
||||
/*
|
||||
** These six function calls are passed straight through to the os_unix.c
|
||||
** backend.
|
||||
*/
|
||||
int sqlite3OsSeek(OsFile *id, off_t offset){
|
||||
return sqlite3RealSeek(&(*id)->fd, offset);
|
||||
}
|
||||
int sqlite3OsCheckReservedLock(OsFile *id){
|
||||
return sqlite3RealCheckReservedLock(&(*id)->fd);
|
||||
}
|
||||
int sqlite3OsLock(OsFile *id, int locktype){
|
||||
return sqlite3RealLock(&(*id)->fd, locktype);
|
||||
}
|
||||
int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
return sqlite3RealUnlock(&(*id)->fd, locktype);
|
||||
}
|
||||
int sqlite3OsOpenDirectory(const char *zDirname, OsFile *id){
|
||||
return sqlite3RealOpenDirectory(zDirname, &(*id)->fd);
|
||||
}
|
||||
|
||||
#endif /* OS_TEST */
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
** 2004 May 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.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
*/
|
||||
#ifndef _SQLITE_OS_TEST_H_
|
||||
#define _SQLITE_OS_TEST_H_
|
||||
|
||||
#define OsFile OsRealFile
|
||||
#define OS_UNIX 1
|
||||
#include "os_unix.h"
|
||||
#undef OS_UNIX
|
||||
#undef OsFile
|
||||
|
||||
/* Include sqliteInt.h now to get the type u8. */
|
||||
#include "sqliteInt.h"
|
||||
|
||||
typedef struct OsTestFile* OsFile;
|
||||
typedef struct OsTestFile OsTestFile;
|
||||
struct OsTestFile {
|
||||
u8 **apBlk; /* Array of blocks that have been written to. */
|
||||
int nBlk; /* Size of apBlock. */
|
||||
int nMaxWrite; /* Largest offset written to. */
|
||||
char *zName; /* File name */
|
||||
OsRealFile fd;
|
||||
OsTestFile *pNext;
|
||||
};
|
||||
|
||||
void sqlite3SetCrashParams(int iDelay, char const *zFile);
|
||||
|
||||
#endif /* _SQLITE_OS_UNIX_H_ */
|
||||
+291
-92
@@ -12,14 +12,27 @@
|
||||
**
|
||||
** This file contains code that is specific to Unix systems.
|
||||
*/
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
#if OS_UNIX /* This file is used on unix only */
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#if OS_UNIX /* This file is used on unix only */
|
||||
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
** Do not include any of the File I/O interface procedures if the
|
||||
** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
|
||||
** will be in-memory only)
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
|
||||
|
||||
/*
|
||||
** Define various macros that are missing from some systems.
|
||||
*/
|
||||
#ifndef O_LARGEFILE
|
||||
# define O_LARGEFILE 0
|
||||
#endif
|
||||
@@ -44,25 +57,36 @@
|
||||
# define fcntl(A,B,C) 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Macros used to determine whether or not to use threads. The
|
||||
** SQLITE_UNIX_THREADS macro is defined if we are synchronizing for
|
||||
** Posix threads and SQLITE_W32_THREADS is defined if we are
|
||||
** synchronizing using Win32 threads.
|
||||
*/
|
||||
#if defined(THREADSAFE) && THREADSAFE
|
||||
# include <pthread.h>
|
||||
# define SQLITE_UNIX_THREADS 1
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Include code that is common to all os_*.c files
|
||||
*/
|
||||
#include "os_common.h"
|
||||
|
||||
#if defined(THREADSAFE) && THREADSAFE && defined(__linux__)
|
||||
#define getpid pthread_self
|
||||
/*
|
||||
** The threadid macro resolves to the thread-id or to 0. Used for
|
||||
** testing and debugging only.
|
||||
*/
|
||||
#ifdef SQLITE_UNIX_THREADS
|
||||
#define threadid pthread_self()
|
||||
#else
|
||||
#define threadid 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Set or check the OsFile.tid field. This field is set when an OsFile
|
||||
** is first opened. All subsequent uses of the OsFile verify that the
|
||||
** same thread is operating on the OsFile. Some operating systems do
|
||||
** not allow locks to be overridden by other threads and that restriction
|
||||
** means that sqlite3* database handles cannot be moved from one thread
|
||||
** to another. This logic makes sure a user does not try to do that
|
||||
** by mistake.
|
||||
*/
|
||||
#ifdef SQLITE_UNIX_THREADS
|
||||
# define SET_THREADID(X) X->tid = pthread_self()
|
||||
# define CHECK_THREADID(X) (!pthread_equal(X->tid, pthread_self()))
|
||||
#else
|
||||
# define SET_THREADID(X)
|
||||
# define CHECK_THREADID(X) 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -252,6 +276,65 @@ struct threadTestData {
|
||||
int result; /* Result of the locking operation */
|
||||
};
|
||||
|
||||
#ifdef SQLITE_LOCK_TRACE
|
||||
/*
|
||||
** Print out information about all locking operations.
|
||||
**
|
||||
** This routine is used for troubleshooting locks on multithreaded
|
||||
** platforms. Enable by compiling with the -DSQLITE_LOCK_TRACE
|
||||
** command-line option on the compiler. This code is normally
|
||||
** turnned off.
|
||||
*/
|
||||
static int lockTrace(int fd, int op, struct flock *p){
|
||||
char *zOpName, *zType;
|
||||
int s;
|
||||
int savedErrno;
|
||||
if( op==F_GETLK ){
|
||||
zOpName = "GETLK";
|
||||
}else if( op==F_SETLK ){
|
||||
zOpName = "SETLK";
|
||||
}else{
|
||||
s = fcntl(fd, op, p);
|
||||
sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s);
|
||||
return s;
|
||||
}
|
||||
if( p->l_type==F_RDLCK ){
|
||||
zType = "RDLCK";
|
||||
}else if( p->l_type==F_WRLCK ){
|
||||
zType = "WRLCK";
|
||||
}else if( p->l_type==F_UNLCK ){
|
||||
zType = "UNLCK";
|
||||
}else{
|
||||
assert( 0 );
|
||||
}
|
||||
assert( p->l_whence==SEEK_SET );
|
||||
s = fcntl(fd, op, p);
|
||||
savedErrno = errno;
|
||||
sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n",
|
||||
threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len,
|
||||
(int)p->l_pid, s);
|
||||
if( s && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){
|
||||
struct flock l2;
|
||||
l2 = *p;
|
||||
fcntl(fd, F_GETLK, &l2);
|
||||
if( l2.l_type==F_RDLCK ){
|
||||
zType = "RDLCK";
|
||||
}else if( l2.l_type==F_WRLCK ){
|
||||
zType = "WRLCK";
|
||||
}else if( l2.l_type==F_UNLCK ){
|
||||
zType = "UNLCK";
|
||||
}else{
|
||||
assert( 0 );
|
||||
}
|
||||
sqlite3DebugPrintf("fcntl-failure-reason: %s %d %d %d\n",
|
||||
zType, (int)l2.l_start, (int)l2.l_len, (int)l2.l_pid);
|
||||
}
|
||||
errno = savedErrno;
|
||||
return s;
|
||||
}
|
||||
#define fcntl lockTrace
|
||||
#endif /* SQLITE_LOCK_TRACE */
|
||||
|
||||
/*
|
||||
** The testThreadLockingBehavior() routine launches two separate
|
||||
** threads on this routine. This routine attempts to lock a file
|
||||
@@ -431,7 +514,9 @@ int sqlite3OsOpenReadWrite(
|
||||
int rc;
|
||||
assert( !id->isOpen );
|
||||
id->dirfd = -1;
|
||||
id->h = open(zFilename, O_RDWR|O_CREAT|O_LARGEFILE|O_BINARY, 0644);
|
||||
SET_THREADID(id);
|
||||
id->h = open(zFilename, O_RDWR|O_CREAT|O_LARGEFILE|O_BINARY,
|
||||
SQLITE_DEFAULT_FILE_PERMISSIONS);
|
||||
if( id->h<0 ){
|
||||
#ifdef EISDIR
|
||||
if( errno==EISDIR ){
|
||||
@@ -481,9 +566,11 @@ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
if( access(zFilename, 0)==0 ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
SET_THREADID(id);
|
||||
id->dirfd = -1;
|
||||
id->h = open(zFilename,
|
||||
O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_LARGEFILE|O_BINARY, 0600);
|
||||
O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_LARGEFILE|O_BINARY,
|
||||
SQLITE_DEFAULT_FILE_PERMISSIONS);
|
||||
if( id->h<0 ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
@@ -515,6 +602,7 @@ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
|
||||
int rc;
|
||||
assert( !id->isOpen );
|
||||
SET_THREADID(id);
|
||||
id->dirfd = -1;
|
||||
id->h = open(zFilename, O_RDONLY|O_LARGEFILE|O_BINARY);
|
||||
if( id->h<0 ){
|
||||
@@ -559,8 +647,9 @@ int sqlite3OsOpenDirectory(
|
||||
** open. */
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
SET_THREADID(id);
|
||||
assert( id->dirfd<0 );
|
||||
id->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0644);
|
||||
id->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0);
|
||||
if( id->dirfd<0 ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
@@ -573,7 +662,7 @@ int sqlite3OsOpenDirectory(
|
||||
** name of a directory, then that directory will be used to store
|
||||
** temporary files.
|
||||
*/
|
||||
const char *sqlite3_temp_directory = 0;
|
||||
char *sqlite3_temp_directory = 0;
|
||||
|
||||
/*
|
||||
** Create a temporary file name in zBuf. zBuf must be big enough to
|
||||
@@ -587,7 +676,7 @@ int sqlite3OsTempFileName(char *zBuf){
|
||||
"/tmp",
|
||||
".",
|
||||
};
|
||||
static unsigned char zChars[] =
|
||||
static const unsigned char zChars[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"0123456789";
|
||||
@@ -615,6 +704,22 @@ int sqlite3OsTempFileName(char *zBuf){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
|
||||
/*
|
||||
** Check that a given pathname is a directory and is writable
|
||||
**
|
||||
*/
|
||||
int sqlite3OsIsDirWritable(char *zBuf){
|
||||
struct stat buf;
|
||||
if( zBuf==0 ) return 0;
|
||||
if( zBuf[0]==0 ) return 0;
|
||||
if( stat(zBuf, &buf) ) return 0;
|
||||
if( !S_ISDIR(buf.st_mode) ) return 0;
|
||||
if( access(zBuf, 07) ) return 0;
|
||||
return 1;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
|
||||
|
||||
/*
|
||||
** Read data from a file into a buffer. Return SQLITE_OK if all
|
||||
** bytes were read successfully and SQLITE_IOERR if anything goes
|
||||
@@ -627,7 +732,7 @@ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
TIMER_START;
|
||||
got = read(id->h, pBuf, amt);
|
||||
TIMER_END;
|
||||
TRACE4("READ %-3d %7d %d\n", id->h, last_page, TIMER_ELAPSED);
|
||||
TRACE5("READ %-3d %5d %7d %d\n", id->h, got, last_page, TIMER_ELAPSED);
|
||||
SEEK(0);
|
||||
/* if( got<0 ) got = 0; */
|
||||
if( got==amt ){
|
||||
@@ -644,14 +749,16 @@ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
int wrote = 0;
|
||||
assert( id->isOpen );
|
||||
assert( amt>0 );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
SimulateDiskfullError;
|
||||
TIMER_START;
|
||||
while( amt>0 && (wrote = write(id->h, pBuf, amt))>0 ){
|
||||
amt -= wrote;
|
||||
pBuf = &((char*)pBuf)[wrote];
|
||||
}
|
||||
TIMER_END;
|
||||
TRACE4("WRITE %-3d %7d %d\n", id->h, last_page, TIMER_ELAPSED);
|
||||
TRACE5("WRITE %-3d %5d %7d %d\n", id->h, wrote, last_page, TIMER_ELAPSED);
|
||||
SEEK(0);
|
||||
if( amt>0 ){
|
||||
return SQLITE_FULL;
|
||||
@@ -662,32 +769,87 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
/*
|
||||
** Move the read/write pointer in a file.
|
||||
*/
|
||||
int sqlite3OsSeek(OsFile *id, off_t offset){
|
||||
int sqlite3OsSeek(OsFile *id, i64 offset){
|
||||
assert( id->isOpen );
|
||||
SEEK(offset/1024 + 1);
|
||||
#ifdef SQLITE_TEST
|
||||
if( offset ) SimulateDiskfullError
|
||||
#endif
|
||||
lseek(id->h, offset, SEEK_SET);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** Count the number of fullsyncs and normal syncs. This is used to test
|
||||
** that syncs and fullsyncs are occuring at the right times.
|
||||
*/
|
||||
int sqlite3_sync_count = 0;
|
||||
int sqlite3_fullsync_count = 0;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** The fsync() system call does not work as advertised on many
|
||||
** unix systems. The following procedure is an attempt to make
|
||||
** it work better.
|
||||
**
|
||||
** The SQLITE_NO_SYNC macro disables all fsync()s. This is useful
|
||||
** for testing when we want to run through the test suite quickly.
|
||||
** You are strongly advised *not* to deploy with SQLITE_NO_SYNC
|
||||
** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash
|
||||
** or power failure will likely corrupt the database file.
|
||||
*/
|
||||
static int full_fsync(int fd){
|
||||
static int full_fsync(int fd, int fullSync, int dataOnly){
|
||||
int rc;
|
||||
#ifdef F_FULLFSYNC
|
||||
rc = fcntl(fd, F_FULLFSYNC, 0);
|
||||
if( rc ) rc = fsync(fd);
|
||||
#else
|
||||
rc = fsync(fd);
|
||||
|
||||
/* Record the number of times that we do a normal fsync() and
|
||||
** FULLSYNC. This is used during testing to verify that this procedure
|
||||
** gets called with the correct arguments.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
if( fullSync ) sqlite3_fullsync_count++;
|
||||
sqlite3_sync_count++;
|
||||
#endif
|
||||
|
||||
/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
|
||||
** no-op
|
||||
*/
|
||||
#ifdef SQLITE_NO_SYNC
|
||||
rc = SQLITE_OK;
|
||||
#else
|
||||
|
||||
#ifdef F_FULLFSYNC
|
||||
if( fullSync ){
|
||||
rc = fcntl(fd, F_FULLFSYNC, 0);
|
||||
}else{
|
||||
rc = 1;
|
||||
}
|
||||
/* If the FULLSYNC failed, try to do a normal fsync() */
|
||||
if( rc ) rc = fsync(fd);
|
||||
|
||||
#else /* if !defined(F_FULLSYNC) */
|
||||
#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO>0
|
||||
if( dataOnly ){
|
||||
rc = fdatasync(fd);
|
||||
}else
|
||||
#endif /* _POSIX_SYNCHRONIZED_IO > 0 */
|
||||
{
|
||||
rc = fsync(fd);
|
||||
}
|
||||
#endif /* defined(F_FULLFSYNC) */
|
||||
#endif /* defined(SQLITE_NO_SYNC) */
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make sure all writes to a particular file are committed to disk.
|
||||
**
|
||||
** If dataOnly==0 then both the file itself and its metadata (file
|
||||
** size, access time, etc) are synced. If dataOnly!=0 then only the
|
||||
** file data is synced.
|
||||
**
|
||||
** Under Unix, also make sure that the directory entry for the file
|
||||
** has been created by fsync-ing the directory that contains the file.
|
||||
** If we do not do this and we encounter a power failure, the directory
|
||||
@@ -696,16 +858,16 @@ static int full_fsync(int fd){
|
||||
** the directory entry for the journal was never created) and the transaction
|
||||
** will not roll back - possibly leading to database corruption.
|
||||
*/
|
||||
int sqlite3OsSync(OsFile *id){
|
||||
int sqlite3OsSync(OsFile *id, int dataOnly){
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
TRACE2("SYNC %-3d\n", id->h);
|
||||
if( full_fsync(id->h) ){
|
||||
if( full_fsync(id->h, id->fullSync, dataOnly) ){
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
if( id->dirfd>=0 ){
|
||||
TRACE2("DIRSYNC %-3d\n", id->dirfd);
|
||||
full_fsync(id->dirfd);
|
||||
full_fsync(id->dirfd, id->fullSync, 0);
|
||||
close(id->dirfd); /* Only need to sync once, so close the directory */
|
||||
id->dirfd = -1; /* when we are done. */
|
||||
}
|
||||
@@ -715,12 +877,16 @@ int sqlite3OsSync(OsFile *id){
|
||||
/*
|
||||
** Sync the directory zDirname. This is a no-op on operating systems other
|
||||
** than UNIX.
|
||||
**
|
||||
** This is used to make sure the master journal file has truely been deleted
|
||||
** before making changes to individual journals on a multi-database commit.
|
||||
** The F_FULLFSYNC option is not needed here.
|
||||
*/
|
||||
int sqlite3OsSyncDirectory(const char *zDirname){
|
||||
int fd;
|
||||
int r;
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
fd = open(zDirname, O_RDONLY|O_BINARY, 0644);
|
||||
fd = open(zDirname, O_RDONLY|O_BINARY, 0);
|
||||
TRACE3("DIRSYNC %-3d (%s)\n", fd, zDirname);
|
||||
if( fd<0 ){
|
||||
return SQLITE_CANTOPEN;
|
||||
@@ -733,7 +899,7 @@ int sqlite3OsSyncDirectory(const char *zDirname){
|
||||
/*
|
||||
** Truncate an open file to a specified size
|
||||
*/
|
||||
int sqlite3OsTruncate(OsFile *id, off_t nByte){
|
||||
int sqlite3OsTruncate(OsFile *id, i64 nByte){
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
return ftruncate(id->h, nByte)==0 ? SQLITE_OK : SQLITE_IOERR;
|
||||
@@ -742,7 +908,7 @@ int sqlite3OsTruncate(OsFile *id, off_t nByte){
|
||||
/*
|
||||
** Determine the current size of a file in bytes
|
||||
*/
|
||||
int sqlite3OsFileSize(OsFile *id, off_t *pSize){
|
||||
int sqlite3OsFileSize(OsFile *id, i64 *pSize){
|
||||
struct stat buf;
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
@@ -763,6 +929,7 @@ int sqlite3OsCheckReservedLock(OsFile *id){
|
||||
int r = 0;
|
||||
|
||||
assert( id->isOpen );
|
||||
if( CHECK_THREADID(id) ) return SQLITE_MISUSE;
|
||||
sqlite3OsEnterMutex(); /* Needed because id->pLock is shared across threads */
|
||||
|
||||
/* Check if a thread in this process holds such a lock */
|
||||
@@ -877,16 +1044,17 @@ int sqlite3OsLock(OsFile *id, int locktype){
|
||||
int s;
|
||||
|
||||
assert( id->isOpen );
|
||||
TRACE7("LOCK %d %s was %s(%s,%d) pid=%d\n", id->h, locktypeName(locktype),
|
||||
TRACE7("LOCK %d %s was %s(%s,%d) pid=%d\n", id->h, locktypeName(locktype),
|
||||
locktypeName(id->locktype), locktypeName(pLock->locktype), pLock->cnt
|
||||
,getpid() );
|
||||
if( CHECK_THREADID(id) ) return SQLITE_MISUSE;
|
||||
|
||||
/* If there is already a lock of this type or more restrictive on the
|
||||
** OsFile, do nothing. Don't use the end_lock: exit path, as
|
||||
** sqlite3OsEnterMutex() hasn't been called yet.
|
||||
*/
|
||||
if( id->locktype>=locktype ){
|
||||
TRACE3("LOCK %d %s ok (already held)\n", id->h, locktypeName(locktype));
|
||||
TRACE3("LOCK %d %s ok (already held)\n", id->h, locktypeName(locktype));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -926,6 +1094,7 @@ int sqlite3OsLock(OsFile *id, int locktype){
|
||||
}
|
||||
|
||||
lock.l_len = 1L;
|
||||
|
||||
lock.l_whence = SEEK_SET;
|
||||
|
||||
/* A PENDING lock is needed before acquiring a SHARED lock and before
|
||||
@@ -961,7 +1130,10 @@ int sqlite3OsLock(OsFile *id, int locktype){
|
||||
lock.l_start = PENDING_BYTE;
|
||||
lock.l_len = 1L;
|
||||
lock.l_type = F_UNLCK;
|
||||
fcntl(id->h, F_SETLK, &lock);
|
||||
if( fcntl(id->h, F_SETLK, &lock)!=0 ){
|
||||
rc = SQLITE_IOERR; /* This should never happen */
|
||||
goto end_lock;
|
||||
}
|
||||
if( s ){
|
||||
rc = (errno==EINVAL) ? SQLITE_NOLFS : SQLITE_BUSY;
|
||||
}else{
|
||||
@@ -1007,7 +1179,7 @@ int sqlite3OsLock(OsFile *id, int locktype){
|
||||
|
||||
end_lock:
|
||||
sqlite3OsLeaveMutex();
|
||||
TRACE4("LOCK %d %s %s\n", id->h, locktypeName(locktype),
|
||||
TRACE4("LOCK %d %s %s\n", id->h, locktypeName(locktype),
|
||||
rc==SQLITE_OK ? "ok" : "failed");
|
||||
return rc;
|
||||
}
|
||||
@@ -1019,15 +1191,19 @@ end_lock:
|
||||
** If the locking level of the file descriptor is already at or below
|
||||
** the requested locking level, this routine is a no-op.
|
||||
**
|
||||
** It is not possible for this routine to fail.
|
||||
** It is not possible for this routine to fail if the second argument
|
||||
** is NO_LOCK. If the second argument is SHARED_LOCK, this routine
|
||||
** might return SQLITE_IOERR instead of SQLITE_OK.
|
||||
*/
|
||||
int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
struct lockInfo *pLock;
|
||||
struct flock lock;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
assert( id->isOpen );
|
||||
TRACE7("UNLOCK %d %d was %d(%d,%d) pid=%d\n", id->h, locktype, id->locktype,
|
||||
TRACE7("UNLOCK %d %d was %d(%d,%d) pid=%d\n", id->h, locktype, id->locktype,
|
||||
id->pLock->locktype, id->pLock->cnt, getpid());
|
||||
if( CHECK_THREADID(id) ) return SQLITE_MISUSE;
|
||||
|
||||
assert( locktype<=SHARED_LOCK );
|
||||
if( id->locktype<=locktype ){
|
||||
@@ -1038,12 +1214,25 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
assert( pLock->cnt!=0 );
|
||||
if( id->locktype>SHARED_LOCK ){
|
||||
assert( pLock->locktype==id->locktype );
|
||||
if( locktype==SHARED_LOCK ){
|
||||
lock.l_type = F_RDLCK;
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = SHARED_FIRST;
|
||||
lock.l_len = SHARED_SIZE;
|
||||
if( fcntl(id->h, F_SETLK, &lock)!=0 ){
|
||||
/* This should never happen */
|
||||
rc = SQLITE_IOERR;
|
||||
}
|
||||
}
|
||||
lock.l_type = F_UNLCK;
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = PENDING_BYTE;
|
||||
lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE );
|
||||
fcntl(id->h, F_SETLK, &lock);
|
||||
pLock->locktype = SHARED_LOCK;
|
||||
if( fcntl(id->h, F_SETLK, &lock)==0 ){
|
||||
pLock->locktype = SHARED_LOCK;
|
||||
}else{
|
||||
rc = SQLITE_IOERR; /* This should never happen */
|
||||
}
|
||||
}
|
||||
if( locktype==NO_LOCK ){
|
||||
struct openCnt *pOpen;
|
||||
@@ -1057,8 +1246,11 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
lock.l_type = F_UNLCK;
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = lock.l_len = 0L;
|
||||
fcntl(id->h, F_SETLK, &lock);
|
||||
pLock->locktype = NO_LOCK;
|
||||
if( fcntl(id->h, F_SETLK, &lock)==0 ){
|
||||
pLock->locktype = NO_LOCK;
|
||||
}else{
|
||||
rc = SQLITE_IOERR; /* This should never happen */
|
||||
}
|
||||
}
|
||||
|
||||
/* Decrement the count of locks against this same file. When the
|
||||
@@ -1080,7 +1272,7 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
id->locktype = locktype;
|
||||
return SQLITE_OK;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1088,6 +1280,7 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
*/
|
||||
int sqlite3OsClose(OsFile *id){
|
||||
if( !id->isOpen ) return SQLITE_OK;
|
||||
if( CHECK_THREADID(id) ) return SQLITE_MISUSE;
|
||||
sqlite3OsUnlock(id, NO_LOCK);
|
||||
if( id->dirfd>=0 ) close(id->dirfd);
|
||||
id->dirfd = -1;
|
||||
@@ -1100,13 +1293,13 @@ int sqlite3OsClose(OsFile *id){
|
||||
*/
|
||||
int *aNew;
|
||||
struct openCnt *pOpen = id->pOpen;
|
||||
pOpen->nPending++;
|
||||
aNew = sqliteRealloc( pOpen->aPending, pOpen->nPending*sizeof(int) );
|
||||
aNew = sqliteRealloc( pOpen->aPending, (pOpen->nPending+1)*sizeof(int) );
|
||||
if( aNew==0 ){
|
||||
/* If a malloc fails, just leak the file descriptor */
|
||||
}else{
|
||||
pOpen->aPending = aNew;
|
||||
pOpen->aPending[pOpen->nPending-1] = id->h;
|
||||
pOpen->aPending[pOpen->nPending] = id->h;
|
||||
pOpen->nPending++;
|
||||
}
|
||||
}else{
|
||||
/* There are no outstanding locks so we can close the file immediately */
|
||||
@@ -1121,6 +1314,37 @@ int sqlite3OsClose(OsFile *id){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Turn a relative pathname into a full pathname. Return a pointer
|
||||
** to the full pathname stored in space obtained from sqliteMalloc().
|
||||
** The calling function is responsible for freeing this space once it
|
||||
** is no longer needed.
|
||||
*/
|
||||
char *sqlite3OsFullPathname(const char *zRelative){
|
||||
char *zFull = 0;
|
||||
if( zRelative[0]=='/' ){
|
||||
sqlite3SetString(&zFull, zRelative, (char*)0);
|
||||
}else{
|
||||
char *zBuf = sqliteMalloc(5000);
|
||||
if( zBuf==0 ){
|
||||
return 0;
|
||||
}
|
||||
zBuf[0] = 0;
|
||||
sqlite3SetString(&zFull, getcwd(zBuf, 5000), "/", zRelative,
|
||||
(char*)0);
|
||||
sqliteFree(zBuf);
|
||||
}
|
||||
return zFull;
|
||||
}
|
||||
|
||||
|
||||
#endif /* SQLITE_OMIT_DISKIO */
|
||||
/***************************************************************************
|
||||
** Everything above deals with file I/O. Everything that follows deals
|
||||
** with other miscellanous aspects of the operating system interface
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
** Get information to seed the random number generator. The seed
|
||||
** is written into the buffer zBuf[256]. The calling function must
|
||||
@@ -1142,10 +1366,16 @@ int sqlite3OsRandomSeed(char *zBuf){
|
||||
memset(zBuf, 0, 256);
|
||||
#if !defined(SQLITE_TEST)
|
||||
{
|
||||
int pid;
|
||||
time((time_t*)zBuf);
|
||||
pid = getpid();
|
||||
memcpy(&zBuf[sizeof(time_t)], &pid, sizeof(pid));
|
||||
int pid, fd;
|
||||
fd = open("/dev/urandom", O_RDONLY);
|
||||
if( fd<0 ){
|
||||
time((time_t*)zBuf);
|
||||
pid = getpid();
|
||||
memcpy(&zBuf[sizeof(time_t)], &pid, sizeof(pid));
|
||||
}else{
|
||||
read(fd, zBuf, 256);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return SQLITE_OK;
|
||||
@@ -1195,24 +1425,6 @@ void sqlite3OsLeaveMutex(){
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Turn a relative pathname into a full pathname. Return a pointer
|
||||
** to the full pathname stored in space obtained from sqliteMalloc().
|
||||
** The calling function is responsible for freeing this space once it
|
||||
** is no longer needed.
|
||||
*/
|
||||
char *sqlite3OsFullPathname(const char *zRelative){
|
||||
char *zFull = 0;
|
||||
if( zRelative[0]=='/' ){
|
||||
sqlite3SetString(&zFull, zRelative, (char*)0);
|
||||
}else{
|
||||
char zBuf[5000];
|
||||
sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), "/", zRelative,
|
||||
(char*)0);
|
||||
}
|
||||
return zFull;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following variable, if set to a non-zero value, becomes the result
|
||||
** returned from sqlite3OsCurrentTime(). This is used for testing.
|
||||
@@ -1227,9 +1439,16 @@ int sqlite3_current_time = 0;
|
||||
** return 0. Return 1 if the time and date cannot be found.
|
||||
*/
|
||||
int sqlite3OsCurrentTime(double *prNow){
|
||||
#ifdef NO_GETTOD
|
||||
time_t t;
|
||||
time(&t);
|
||||
*prNow = t/86400.0 + 2440587.5;
|
||||
#else
|
||||
struct timeval sNow;
|
||||
struct timezone sTz; /* Not used */
|
||||
gettimeofday(&sNow, &sTz);
|
||||
*prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0;
|
||||
#endif
|
||||
#ifdef SQLITE_TEST
|
||||
if( sqlite3_current_time ){
|
||||
*prNow = sqlite3_current_time/86400.0 + 2440587.5;
|
||||
@@ -1238,24 +1457,4 @@ int sqlite3OsCurrentTime(double *prNow){
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0 /* NOT USED */
|
||||
/*
|
||||
** Find the time that the file was last modified. Write the
|
||||
** modification time and date as a Julian Day number into *prNow and
|
||||
** return SQLITE_OK. Return SQLITE_ERROR if the modification
|
||||
** time cannot be found.
|
||||
*/
|
||||
int sqlite3OsFileModTime(OsFile *id, double *prNow){
|
||||
int rc;
|
||||
struct stat statbuf;
|
||||
if( fstat(id->h, &statbuf)==0 ){
|
||||
*prNow = statbuf.st_mtime/86400.0 + 2440587.5;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif /* NOT USED */
|
||||
|
||||
#endif /* OS_UNIX */
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
** 2004 May 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 header file defined OS-specific features for Unix.
|
||||
*/
|
||||
#ifndef _SQLITE_OS_UNIX_H_
|
||||
#define _SQLITE_OS_UNIX_H_
|
||||
|
||||
/*
|
||||
** Helpful hint: To get this to compile on HP/UX, add -D_INCLUDE_POSIX_SOURCE
|
||||
** to the compiler command line.
|
||||
*/
|
||||
|
||||
/*
|
||||
** These #defines should enable >2GB file support on Posix if the
|
||||
** underlying operating system supports it. If the OS lacks
|
||||
** large file support, or if the OS is windows, these should be no-ops.
|
||||
**
|
||||
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
|
||||
** on the compiler command line. This is necessary if you are compiling
|
||||
** on a recent machine (ex: RedHat 7.2) but you want your code to work
|
||||
** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2
|
||||
** without this option, LFS is enable. But LFS does not exist in the kernel
|
||||
** in RedHat 6.0, so the code won't work. Hence, for maximum binary
|
||||
** portability you should omit LFS.
|
||||
**
|
||||
** Similar is true for MacOS. LFS is only supported on MacOS 9 and later.
|
||||
*/
|
||||
#ifndef SQLITE_DISABLE_LFS
|
||||
# define _LARGE_FILE 1
|
||||
# ifndef _FILE_OFFSET_BITS
|
||||
# define _FILE_OFFSET_BITS 64
|
||||
# endif
|
||||
# define _LARGEFILE_SOURCE 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** standard include files.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
** The OsFile structure is a operating-system independing representation
|
||||
** of an open file handle. It is defined differently for each architecture.
|
||||
**
|
||||
** This is the definition for Unix.
|
||||
**
|
||||
** OsFile.locktype takes one of the values SHARED_LOCK, RESERVED_LOCK,
|
||||
** PENDING_LOCK or EXCLUSIVE_LOCK.
|
||||
*/
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
struct Pager *pPager; /* The pager that owns this OsFile. Might be 0 */
|
||||
struct openCnt *pOpen; /* Info about all open fd's on this inode */
|
||||
struct lockInfo *pLock; /* Info about locks on this inode */
|
||||
int h; /* The file descriptor */
|
||||
unsigned char locktype; /* The type of lock held on this fd */
|
||||
unsigned char isOpen; /* True if needs to be closed */
|
||||
int dirfd; /* File descriptor for the directory */
|
||||
};
|
||||
|
||||
/*
|
||||
** Maximum number of characters in a temporary file name
|
||||
*/
|
||||
#define SQLITE_TEMPNAME_SIZE 200
|
||||
|
||||
/*
|
||||
** Minimum interval supported by sqlite3OsSleep().
|
||||
*/
|
||||
#if defined(HAVE_USLEEP) && HAVE_USLEEP
|
||||
# define SQLITE_MIN_SLEEP_MS 1
|
||||
#else
|
||||
# define SQLITE_MIN_SLEEP_MS 1000
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _SQLITE_OS_UNIX_H_ */
|
||||
+319
-121
@@ -12,12 +12,16 @@
|
||||
**
|
||||
** This file contains code that is specific to windows.
|
||||
*/
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
#if OS_WIN /* This file is used for windows only */
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#if OS_WIN /* This file is used for windows only */
|
||||
|
||||
#include <winbase.h>
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
# include <sys/cygwin.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Macros used to determine whether or not to use threads.
|
||||
*/
|
||||
@@ -30,11 +34,106 @@
|
||||
*/
|
||||
#include "os_common.h"
|
||||
|
||||
/*
|
||||
** Do not include any of the File I/O interface procedures if the
|
||||
** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
|
||||
** will be in-memory only)
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
|
||||
/*
|
||||
** The following variable is (normally) set once and never changes
|
||||
** thereafter. It records whether the operating system is Win95
|
||||
** or WinNT.
|
||||
**
|
||||
** 0: Operating system unknown.
|
||||
** 1: Operating system is Win95.
|
||||
** 2: Operating system is WinNT.
|
||||
**
|
||||
** In order to facilitate testing on a WinNT system, the test fixture
|
||||
** can manually set this value to 1 to emulate Win98 behavior.
|
||||
*/
|
||||
int sqlite3_os_type = 0;
|
||||
|
||||
/*
|
||||
** Return true (non-zero) if we are running under WinNT, Win2K or WinXP.
|
||||
** Return false (zero) for Win95, Win98, or WinME.
|
||||
**
|
||||
** Here is an interesting observation: Win95, Win98, and WinME lack
|
||||
** the LockFileEx() API. But we can still statically link against that
|
||||
** API as long as we don't call it win running Win95/98/ME. A call to
|
||||
** this routine is used to determine if the host is Win95/98/ME or
|
||||
** WinNT/2K/XP so that we will know whether or not we can safely call
|
||||
** the LockFileEx() API.
|
||||
*/
|
||||
static int isNT(void){
|
||||
if( sqlite3_os_type==0 ){
|
||||
OSVERSIONINFO sInfo;
|
||||
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
|
||||
GetVersionEx(&sInfo);
|
||||
sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
|
||||
}
|
||||
return sqlite3_os_type==2;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert a UTF-8 string to UTF-32. Space to hold the returned string
|
||||
** is obtained from sqliteMalloc.
|
||||
*/
|
||||
static WCHAR *utf8ToUnicode(const char *zFilename){
|
||||
int nByte;
|
||||
WCHAR *zWideFilename;
|
||||
|
||||
if( !isNT() ){
|
||||
return 0;
|
||||
}
|
||||
nByte = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0)*sizeof(WCHAR);
|
||||
zWideFilename = sqliteMalloc( nByte*sizeof(zWideFilename[0]) );
|
||||
if( zWideFilename==0 ){
|
||||
return 0;
|
||||
}
|
||||
nByte = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, nByte);
|
||||
if( nByte==0 ){
|
||||
sqliteFree(zWideFilename);
|
||||
zWideFilename = 0;
|
||||
}
|
||||
return zWideFilename;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert UTF-32 to UTF-8. Space to hold the returned string is
|
||||
** obtained from sqliteMalloc().
|
||||
*/
|
||||
static char *unicodeToUtf8(const WCHAR *zWideFilename){
|
||||
int nByte;
|
||||
char *zFilename;
|
||||
|
||||
nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
|
||||
zFilename = sqliteMalloc( nByte );
|
||||
if( zFilename==0 ){
|
||||
return 0;
|
||||
}
|
||||
nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
|
||||
0, 0);
|
||||
if( nByte == 0 ){
|
||||
sqliteFree(zFilename);
|
||||
zFilename = 0;
|
||||
}
|
||||
return zFilename;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Delete the named file
|
||||
*/
|
||||
int sqlite3OsDelete(const char *zFilename){
|
||||
DeleteFileA(zFilename);
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
if( zWide ){
|
||||
DeleteFileW(zWide);
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
DeleteFileA(zFilename);
|
||||
}
|
||||
TRACE2("DELETE \"%s\"\n", zFilename);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -43,7 +142,15 @@ int sqlite3OsDelete(const char *zFilename){
|
||||
** Return TRUE if the named file exists.
|
||||
*/
|
||||
int sqlite3OsFileExists(const char *zFilename){
|
||||
return GetFileAttributesA(zFilename) != 0xffffffff;
|
||||
int exists = 0;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
if( zWide ){
|
||||
exists = GetFileAttributesW(zWide) != 0xffffffff;
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
exists = GetFileAttributesA(zFilename) != 0xffffffff;
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -65,30 +172,60 @@ int sqlite3OsOpenReadWrite(
|
||||
int *pReadonly
|
||||
){
|
||||
HANDLE h;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
assert( !id->isOpen );
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,
|
||||
if( zWide ){
|
||||
h = CreateFileW(zWide,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
return SQLITE_CANTOPEN;
|
||||
h = CreateFileW(zWide,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,
|
||||
NULL,
|
||||
OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
sqliteFree(zWide);
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
*pReadonly = 1;
|
||||
}else{
|
||||
*pReadonly = 0;
|
||||
}
|
||||
*pReadonly = 1;
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
*pReadonly = 0;
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,
|
||||
NULL,
|
||||
OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
*pReadonly = 1;
|
||||
}else{
|
||||
*pReadonly = 0;
|
||||
}
|
||||
}
|
||||
id->h = h;
|
||||
id->locktype = NO_LOCK;
|
||||
@@ -117,6 +254,7 @@ int sqlite3OsOpenReadWrite(
|
||||
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
HANDLE h;
|
||||
int fileflags;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
assert( !id->isOpen );
|
||||
if( delFlag ){
|
||||
fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS
|
||||
@@ -124,14 +262,26 @@ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
}else{
|
||||
fileflags = FILE_FLAG_RANDOM_ACCESS;
|
||||
}
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
CREATE_ALWAYS,
|
||||
fileflags,
|
||||
NULL
|
||||
);
|
||||
if( zWide ){
|
||||
h = CreateFileW(zWide,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
CREATE_ALWAYS,
|
||||
fileflags,
|
||||
NULL
|
||||
);
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
CREATE_ALWAYS,
|
||||
fileflags,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
@@ -153,15 +303,28 @@ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
|
||||
*/
|
||||
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
|
||||
HANDLE h;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
assert( !id->isOpen );
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
if( zWide ){
|
||||
h = CreateFileW(zWide,
|
||||
GENERIC_READ,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
h = CreateFileA(zFilename,
|
||||
GENERIC_READ,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
@@ -202,7 +365,7 @@ int sqlite3OsOpenDirectory(
|
||||
** name of a directory, then that directory will be used to store
|
||||
** temporary files.
|
||||
*/
|
||||
const char *sqlite3_temp_directory = 0;
|
||||
char *sqlite3_temp_directory = 0;
|
||||
|
||||
/*
|
||||
** Create a temporary file name in zBuf. zBuf must be big enough to
|
||||
@@ -218,6 +381,16 @@ int sqlite3OsTempFileName(char *zBuf){
|
||||
if( sqlite3_temp_directory ){
|
||||
strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30);
|
||||
zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
|
||||
}else if( isNT() ){
|
||||
char *zMulti;
|
||||
WCHAR zWidePath[SQLITE_TEMPNAME_SIZE];
|
||||
GetTempPathW(SQLITE_TEMPNAME_SIZE-30, zWidePath);
|
||||
zMulti = unicodeToUtf8(zWidePath);
|
||||
if( zMulti ){
|
||||
strncpy(zTempPath, zMulti, SQLITE_TEMPNAME_SIZE-30);
|
||||
zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
|
||||
sqliteFree(zMulti);
|
||||
}
|
||||
}else{
|
||||
GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath);
|
||||
}
|
||||
@@ -275,11 +448,13 @@ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
|
||||
** or some other error code on failure.
|
||||
*/
|
||||
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
int rc;
|
||||
int rc = 0;
|
||||
DWORD wrote;
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
SimulateDiskfullError;
|
||||
TRACE3("WRITE %d lock=%d\n", id->h, id->locktype);
|
||||
assert( amt>0 );
|
||||
while( amt>0 && (rc = WriteFile(id->h, pBuf, amt, &wrote, 0))!=0 && wrote>0 ){
|
||||
amt -= wrote;
|
||||
pBuf = &((char*)pBuf)[wrote];
|
||||
@@ -290,24 +465,37 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Some microsoft compilers lack this definition.
|
||||
*/
|
||||
#ifndef INVALID_SET_FILE_POINTER
|
||||
# define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Move the read/write pointer in a file.
|
||||
*/
|
||||
int sqlite3OsSeek(OsFile *id, off_t offset){
|
||||
int sqlite3OsSeek(OsFile *id, i64 offset){
|
||||
LONG upperBits = offset>>32;
|
||||
LONG lowerBits = offset & 0xffffffff;
|
||||
DWORD rc;
|
||||
assert( id->isOpen );
|
||||
#ifdef SQLITE_TEST
|
||||
if( offset ) SimulateDiskfullError
|
||||
#endif
|
||||
SEEK(offset/1024 + 1);
|
||||
rc = SetFilePointer(id->h, lowerBits, &upperBits, FILE_BEGIN);
|
||||
TRACE3("SEEK %d %lld\n", id->h, offset);
|
||||
if( rc==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR ){
|
||||
return SQLITE_FULL;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make sure all writes to a particular file are committed to disk.
|
||||
*/
|
||||
int sqlite3OsSync(OsFile *id){
|
||||
int sqlite3OsSync(OsFile *id, int dataOnly){
|
||||
assert( id->isOpen );
|
||||
TRACE3("SYNC %d lock=%d\n", id->h, id->locktype);
|
||||
if( FlushFileBuffers(id->h) ){
|
||||
@@ -329,7 +517,7 @@ int sqlite3OsSyncDirectory(const char *zDirname){
|
||||
/*
|
||||
** Truncate an open file to a specified size
|
||||
*/
|
||||
int sqlite3OsTruncate(OsFile *id, off_t nByte){
|
||||
int sqlite3OsTruncate(OsFile *id, i64 nByte){
|
||||
LONG upperBits = nByte>>32;
|
||||
assert( id->isOpen );
|
||||
TRACE3("TRUNCATE %d %lld\n", id->h, nByte);
|
||||
@@ -342,52 +530,33 @@ int sqlite3OsTruncate(OsFile *id, off_t nByte){
|
||||
/*
|
||||
** Determine the current size of a file in bytes
|
||||
*/
|
||||
int sqlite3OsFileSize(OsFile *id, off_t *pSize){
|
||||
int sqlite3OsFileSize(OsFile *id, i64 *pSize){
|
||||
DWORD upperBits, lowerBits;
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
lowerBits = GetFileSize(id->h, &upperBits);
|
||||
*pSize = (((off_t)upperBits)<<32) + lowerBits;
|
||||
*pSize = (((i64)upperBits)<<32) + lowerBits;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return true (non-zero) if we are running under WinNT, Win2K or WinXP.
|
||||
** Return false (zero) for Win95, Win98, or WinME.
|
||||
**
|
||||
** Here is an interesting observation: Win95, Win98, and WinME lack
|
||||
** the LockFileEx() API. But we can still statically link against that
|
||||
** API as long as we don't call it win running Win95/98/ME. A call to
|
||||
** this routine is used to determine if the host is Win95/98/ME or
|
||||
** WinNT/2K/XP so that we will know whether or not we can safely call
|
||||
** the LockFileEx() API.
|
||||
*/
|
||||
static int isNT(void){
|
||||
static int osType = 0; /* 0=unknown 1=win95 2=winNT */
|
||||
if( osType==0 ){
|
||||
OSVERSIONINFO sInfo;
|
||||
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
|
||||
GetVersionEx(&sInfo);
|
||||
osType = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
|
||||
}
|
||||
return osType==2;
|
||||
}
|
||||
|
||||
/*
|
||||
** Acquire a reader lock on the range of bytes from iByte...iByte+nByte-1.
|
||||
** Acquire a reader lock.
|
||||
** Different API routines are called depending on whether or not this
|
||||
** is Win95 or WinNT.
|
||||
*/
|
||||
static int getReadLock(HANDLE h, unsigned int iByte, unsigned int nByte){
|
||||
static int getReadLock(OsFile *id){
|
||||
int res;
|
||||
if( isNT() ){
|
||||
OVERLAPPED ovlp;
|
||||
ovlp.Offset = iByte;
|
||||
ovlp.Offset = SHARED_FIRST;
|
||||
ovlp.OffsetHigh = 0;
|
||||
ovlp.hEvent = 0;
|
||||
res = LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY, 0, nByte, 0, &ovlp);
|
||||
res = LockFileEx(id->h, LOCKFILE_FAIL_IMMEDIATELY, 0, SHARED_SIZE,0,&ovlp);
|
||||
}else{
|
||||
res = LockFile(h, iByte, 0, nByte, 0);
|
||||
int lk;
|
||||
sqlite3Randomness(sizeof(lk), &lk);
|
||||
id->sharedLockByte = (lk & 0x7fffffff)%(SHARED_SIZE - 1);
|
||||
res = LockFile(id->h, SHARED_FIRST+id->sharedLockByte, 0, 1, 0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -405,6 +574,31 @@ static int unlockReadLock(OsFile *id){
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
|
||||
/*
|
||||
** Check that a given pathname is a directory and is writable
|
||||
**
|
||||
*/
|
||||
int sqlite3OsIsDirWritable(char *zDirname){
|
||||
int fileAttr;
|
||||
WCHAR *zWide;
|
||||
if( zDirname==0 ) return 0;
|
||||
if( !isNT() && strlen(zDirname)>MAX_PATH ) return 0;
|
||||
zWide = utf8ToUnicode(zDirname);
|
||||
if( zWide ){
|
||||
fileAttr = GetFileAttributesW(zWide);
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
fileAttr = GetFileAttributesA(zDirname);
|
||||
}
|
||||
if( fileAttr == 0xffffffff ) return 0;
|
||||
if( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ){
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
|
||||
|
||||
/*
|
||||
** Lock the file with the lock specified by parameter locktype - one
|
||||
** of the following:
|
||||
@@ -478,14 +672,7 @@ int sqlite3OsLock(OsFile *id, int locktype){
|
||||
*/
|
||||
if( locktype==SHARED_LOCK && res ){
|
||||
assert( id->locktype==NO_LOCK );
|
||||
if( isNT() ){
|
||||
res = getReadLock(id->h, SHARED_FIRST, SHARED_SIZE);
|
||||
}else{
|
||||
int lk;
|
||||
sqlite3Randomness(sizeof(lk), &lk);
|
||||
id->sharedLockByte = (lk & 0x7fffffff)%(SHARED_SIZE - 1);
|
||||
res = LockFile(id->h, SHARED_FIRST+id->sharedLockByte, 0, 1, 0);
|
||||
}
|
||||
res = getReadLock(id);
|
||||
if( res ){
|
||||
newLocktype = SHARED_LOCK;
|
||||
}
|
||||
@@ -572,10 +759,13 @@ int sqlite3OsCheckReservedLock(OsFile *id){
|
||||
** If the locking level of the file descriptor is already at or below
|
||||
** the requested locking level, this routine is a no-op.
|
||||
**
|
||||
** It is not possible for this routine to fail.
|
||||
** It is not possible for this routine to fail if the second argument
|
||||
** is NO_LOCK. If the second argument is SHARED_LOCK then this routine
|
||||
** might return SQLITE_IOERR;
|
||||
*/
|
||||
int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
int rc, type;
|
||||
int type;
|
||||
int rc = SQLITE_OK;
|
||||
assert( id->isOpen );
|
||||
assert( locktype<=SHARED_LOCK );
|
||||
TRACE5("UNLOCK %d to %d was %d(%d)\n", id->h, locktype,
|
||||
@@ -583,20 +773,68 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
|
||||
type = id->locktype;
|
||||
if( type>=EXCLUSIVE_LOCK ){
|
||||
UnlockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
if( locktype==SHARED_LOCK && !getReadLock(id) ){
|
||||
/* This should never happen. We should always be able to
|
||||
** reacquire the read lock */
|
||||
rc = SQLITE_IOERR;
|
||||
}
|
||||
}
|
||||
if( type>=RESERVED_LOCK ){
|
||||
UnlockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
}
|
||||
if( locktype==NO_LOCK && type>=SHARED_LOCK && type<EXCLUSIVE_LOCK ){
|
||||
if( locktype==NO_LOCK && type>=SHARED_LOCK ){
|
||||
unlockReadLock(id);
|
||||
}
|
||||
if( type>=PENDING_LOCK ){
|
||||
UnlockFile(id->h, PENDING_BYTE, 0, 1, 0);
|
||||
}
|
||||
id->locktype = locktype;
|
||||
return SQLITE_OK;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Turn a relative pathname into a full pathname. Return a pointer
|
||||
** to the full pathname stored in space obtained from sqliteMalloc().
|
||||
** The calling function is responsible for freeing this space once it
|
||||
** is no longer needed.
|
||||
*/
|
||||
char *sqlite3OsFullPathname(const char *zRelative){
|
||||
char *zNotUsed;
|
||||
char *zFull;
|
||||
WCHAR *zWide;
|
||||
int nByte;
|
||||
#ifdef __CYGWIN__
|
||||
nByte = strlen(zRelative) + MAX_PATH + 1001;
|
||||
zFull = sqliteMalloc( nByte );
|
||||
if( zFull==0 ) return 0;
|
||||
if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0;
|
||||
#else
|
||||
zWide = utf8ToUnicode(zRelative);
|
||||
if( zWide ){
|
||||
WCHAR *zTemp, *zNotUsedW;
|
||||
nByte = GetFullPathNameW(zWide, 0, 0, &zNotUsedW) + 1;
|
||||
zTemp = sqliteMalloc( nByte*sizeof(zTemp[0]) );
|
||||
if( zTemp==0 ) return 0;
|
||||
GetFullPathNameW(zWide, nByte, zTemp, &zNotUsedW);
|
||||
sqliteFree(zWide);
|
||||
zFull = unicodeToUtf8(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
}else{
|
||||
nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
|
||||
zFull = sqliteMalloc( nByte*sizeof(zFull[0]) );
|
||||
if( zFull==0 ) return 0;
|
||||
GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
|
||||
}
|
||||
#endif
|
||||
return zFull;
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_DISKIO */
|
||||
/***************************************************************************
|
||||
** Everything above deals with file I/O. Everything that follows deals
|
||||
** with other miscellanous aspects of the operating system interface
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
** Get information to seed the random number generator. The seed
|
||||
** is written into the buffer zBuf[256]. The calling function must
|
||||
@@ -669,23 +907,6 @@ void sqlite3OsLeaveMutex(){
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Turn a relative pathname into a full pathname. Return a pointer
|
||||
** to the full pathname stored in space obtained from sqliteMalloc().
|
||||
** The calling function is responsible for freeing this space once it
|
||||
** is no longer needed.
|
||||
*/
|
||||
char *sqlite3OsFullPathname(const char *zRelative){
|
||||
char *zNotUsed;
|
||||
char *zFull;
|
||||
int nByte;
|
||||
nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
|
||||
zFull = sqliteMalloc( nByte );
|
||||
if( zFull==0 ) return 0;
|
||||
GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
|
||||
return zFull;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following variable, if set to a non-zero value, becomes the result
|
||||
** returned from sqlite3OsCurrentTime(). This is used for testing.
|
||||
@@ -716,27 +937,4 @@ int sqlite3OsCurrentTime(double *prNow){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Find the time that the file was last modified. Write the
|
||||
** modification time and date as a Julian Day number into *prNow and
|
||||
** return SQLITE_OK. Return SQLITE_ERROR if the modification
|
||||
** time cannot be found.
|
||||
*/
|
||||
int sqlite3OsFileModTime(OsFile *id, double *prMTime){
|
||||
int rc;
|
||||
FILETIME ft;
|
||||
/* FILETIME structure is a 64-bit value representing the number of
|
||||
** 100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
|
||||
*/
|
||||
if( GetFileTime(id->h, 0, 0, &ft) ){
|
||||
double t;
|
||||
t = ((double)ft.dwHighDateTime) * 4294967296.0;
|
||||
*prMTime = (t + ft.dwLowDateTime)/864000000000.0 + 2305813.5;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* OS_WIN */
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
** 2004 May 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 header file defines OS-specific features for Win32
|
||||
*/
|
||||
#ifndef _SQLITE_OS_WIN_H_
|
||||
#define _SQLITE_OS_WIN_H_
|
||||
|
||||
#include <windows.h>
|
||||
#include <winbase.h>
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 off_t;
|
||||
#else
|
||||
# if !defined(_CYGWIN_TYPES_H)
|
||||
typedef long long off_t;
|
||||
# if defined(__MINGW32__)
|
||||
# define _OFF_T_
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The OsFile structure is a operating-system independing representation
|
||||
** of an open file handle. It is defined differently for each architecture.
|
||||
**
|
||||
** This is the definition for Win32.
|
||||
*/
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
HANDLE h; /* Handle for accessing the file */
|
||||
unsigned char locktype; /* Type of lock currently held on this file */
|
||||
unsigned char isOpen; /* True if needs to be closed */
|
||||
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
|
||||
};
|
||||
|
||||
|
||||
#define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
|
||||
#define SQLITE_MIN_SLEEP_MS 1
|
||||
|
||||
|
||||
#endif /* _SQLITE_OS_WIN_H_ */
|
||||
+822
-364
File diff suppressed because it is too large
Load Diff
+26
-12
@@ -13,7 +13,7 @@
|
||||
** subsystem. The page cache subsystem reads and writes a file a page
|
||||
** at a time and provides a journal for rollback.
|
||||
**
|
||||
** @(#) $Id: pager.h,v 1.37 2004/07/22 01:19:35 drh Exp $
|
||||
** @(#) $Id: pager.h,v 1.46 2005/09/19 19:05:21 drh Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -23,15 +23,18 @@
|
||||
# define SQLITE_DEFAULT_PAGE_SIZE 1024
|
||||
#endif
|
||||
|
||||
/* Maximum page size. The upper bound on this value is 65536 (a limit
|
||||
** imposed by the 2-byte size of cell array pointers.) The
|
||||
** maximum page size determines the amount of stack space allocated
|
||||
** by many of the routines in pager.c and btree.c On embedded architectures
|
||||
** or any machine where memory and especially stack memory is limited,
|
||||
** one may wish to chose a smaller value for the maximum page size.
|
||||
/* Maximum page size. The upper bound on this value is 32768. This a limit
|
||||
** imposed by necessity of storing the value in a 2-byte unsigned integer
|
||||
** and the fact that the page size must be a power of 2.
|
||||
**
|
||||
** This value is used to initialize certain arrays on the stack at
|
||||
** various places in the code. On embedded machines where stack space
|
||||
** is limited and the flexibility of having large pages is not needed,
|
||||
** it makes good sense to reduce the maximum page size to something more
|
||||
** reasonable, like 1024.
|
||||
*/
|
||||
#ifndef SQLITE_MAX_PAGE_SIZE
|
||||
# define SQLITE_MAX_PAGE_SIZE 8192
|
||||
# define SQLITE_MAX_PAGE_SIZE 32768
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -50,17 +53,25 @@ typedef unsigned int Pgno;
|
||||
*/
|
||||
typedef struct Pager Pager;
|
||||
|
||||
/*
|
||||
** Allowed values for the flags parameter to sqlite3pager_open().
|
||||
**
|
||||
** NOTE: This values must match the corresponding BTREE_ values in btree.h.
|
||||
*/
|
||||
#define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
|
||||
#define PAGER_NO_READLOCK 0x0002 /* Omit readlocks on readonly files */
|
||||
|
||||
|
||||
/*
|
||||
** See source code comments for a detailed description of the following
|
||||
** routines:
|
||||
*/
|
||||
int sqlite3pager_open(Pager **ppPager, const char *zFilename,
|
||||
int nExtra, int useJournal);
|
||||
int nExtra, int flags);
|
||||
void sqlite3pager_set_busyhandler(Pager*, BusyHandler *pBusyHandler);
|
||||
void sqlite3pager_set_destructor(Pager*, void(*)(void*,int));
|
||||
void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int));
|
||||
void sqlite3pager_set_pagesize(Pager*, int);
|
||||
int sqlite3pager_set_pagesize(Pager*, int);
|
||||
void sqlite3pager_read_fileheader(Pager*, int, unsigned char*);
|
||||
void sqlite3pager_set_cachesize(Pager*, int);
|
||||
int sqlite3pager_close(Pager *pPager);
|
||||
@@ -74,9 +85,9 @@ int sqlite3pager_iswriteable(void*);
|
||||
int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void*);
|
||||
int sqlite3pager_pagecount(Pager*);
|
||||
int sqlite3pager_truncate(Pager*,Pgno);
|
||||
int sqlite3pager_begin(void*);
|
||||
int sqlite3pager_begin(void*, int exFlag);
|
||||
int sqlite3pager_commit(Pager*);
|
||||
int sqlite3pager_sync(Pager*,const char *zMaster);
|
||||
int sqlite3pager_sync(Pager*,const char *zMaster, Pgno);
|
||||
int sqlite3pager_rollback(Pager*);
|
||||
int sqlite3pager_isreadonly(Pager*);
|
||||
int sqlite3pager_stmt_begin(Pager*);
|
||||
@@ -89,8 +100,11 @@ void sqlite3pager_set_safety_level(Pager*,int);
|
||||
const char *sqlite3pager_filename(Pager*);
|
||||
const char *sqlite3pager_dirname(Pager*);
|
||||
const char *sqlite3pager_journalname(Pager*);
|
||||
int sqlite3pager_nosync(Pager*);
|
||||
int sqlite3pager_rename(Pager*, const char *zNewName);
|
||||
void sqlite3pager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);
|
||||
int sqlite3pager_movepage(Pager*,void*,Pgno);
|
||||
int sqlite3pager_reset(Pager*);
|
||||
|
||||
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
|
||||
int sqlite3pager_lockstate(Pager*);
|
||||
|
||||
+373
-225
@@ -14,12 +14,23 @@
|
||||
** the parser. Lemon will also generate a header file containing
|
||||
** numeric codes for all of the tokens.
|
||||
**
|
||||
** @(#) $Id: parse.y,v 1.135 2004/08/25 04:07:02 drh Exp $
|
||||
** @(#) $Id: parse.y,v 1.180 2005/09/16 02:38:10 drh Exp $
|
||||
*/
|
||||
|
||||
// All token codes are small integers with #defines that begin with "TK_"
|
||||
%token_prefix TK_
|
||||
|
||||
// The type of the data attached to each token is Token. This is also the
|
||||
// default type for non-terminals.
|
||||
//
|
||||
%token_type {Token}
|
||||
%default_type {Token}
|
||||
|
||||
// The generated parser function takes a 4th argument as follows:
|
||||
%extra_argument {Parse *pParse}
|
||||
|
||||
// This code runs whenever there is a syntax error
|
||||
//
|
||||
%syntax_error {
|
||||
if( pParse->zErrMsg==0 ){
|
||||
if( TOKEN.z[0] ){
|
||||
@@ -29,7 +40,14 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The name of the generated procedure that implements the parser
|
||||
// is as follows:
|
||||
%name sqlite3Parser
|
||||
|
||||
// The following text is included near the beginning of the C source
|
||||
// code file that implements the parser.
|
||||
//
|
||||
%include {
|
||||
#include "sqliteInt.h"
|
||||
#include "parse.h"
|
||||
@@ -39,8 +57,17 @@
|
||||
** LIMIT clause of a SELECT statement.
|
||||
*/
|
||||
struct LimitVal {
|
||||
int limit; /* The LIMIT value. -1 if there is no limit */
|
||||
int offset; /* The OFFSET. 0 if there is none */
|
||||
Expr *pLimit; /* The LIMIT expression. NULL if there is no limit */
|
||||
Expr *pOffset; /* The OFFSET expression. NULL if there is none */
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of this structure is used to store the LIKE,
|
||||
** GLOB, NOT LIKE, and NOT GLOB operators.
|
||||
*/
|
||||
struct LikeOp {
|
||||
Token operator; /* "like" or "glob" or "regexp" */
|
||||
int not; /* True if the NOT keyword is present */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -66,25 +93,33 @@ struct AttachKey { int type; Token key; };
|
||||
// add them to the parse.h output file.
|
||||
//
|
||||
%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
|
||||
COLUMN AGG_FUNCTION.
|
||||
COLUMN AGG_FUNCTION AGG_COLUMN CONST_FUNC.
|
||||
|
||||
// Input is a single SQL command
|
||||
input ::= cmdlist.
|
||||
cmdlist ::= cmdlist ecmd.
|
||||
cmdlist ::= ecmd.
|
||||
ecmd ::= explain cmdx SEMI.
|
||||
ecmd ::= SEMI.
|
||||
cmdx ::= cmd. { sqlite3FinishCoding(pParse); }
|
||||
explain ::= EXPLAIN. { sqlite3BeginParse(pParse, 1); }
|
||||
ecmd ::= SEMI.
|
||||
ecmd ::= explain cmdx SEMI.
|
||||
explain ::= . { sqlite3BeginParse(pParse, 0); }
|
||||
%ifndef SQLITE_OMIT_EXPLAIN
|
||||
explain ::= EXPLAIN. { sqlite3BeginParse(pParse, 1); }
|
||||
explain ::= EXPLAIN QUERY PLAN. { sqlite3BeginParse(pParse, 2); }
|
||||
%endif
|
||||
|
||||
///////////////////// Begin and end transactions. ////////////////////////////
|
||||
//
|
||||
|
||||
cmd ::= BEGIN trans_opt. {sqlite3BeginTransaction(pParse);}
|
||||
cmd ::= BEGIN transtype(Y) trans_opt. {sqlite3BeginTransaction(pParse, Y);}
|
||||
trans_opt ::= .
|
||||
trans_opt ::= TRANSACTION.
|
||||
trans_opt ::= TRANSACTION nm.
|
||||
%type transtype {int}
|
||||
transtype(A) ::= . {A = TK_DEFERRED;}
|
||||
transtype(A) ::= DEFERRED(X). {A = @X;}
|
||||
transtype(A) ::= IMMEDIATE(X). {A = @X;}
|
||||
transtype(A) ::= EXCLUSIVE(X). {A = @X;}
|
||||
cmd ::= COMMIT trans_opt. {sqlite3CommitTransaction(pParse);}
|
||||
cmd ::= END trans_opt. {sqlite3CommitTransaction(pParse);}
|
||||
cmd ::= ROLLBACK trans_opt. {sqlite3RollbackTransaction(pParse);}
|
||||
@@ -96,24 +131,34 @@ create_table ::= CREATE(X) temp(T) TABLE nm(Y) dbnm(Z). {
|
||||
sqlite3StartTable(pParse,&X,&Y,&Z,T,0);
|
||||
}
|
||||
%type temp {int}
|
||||
%ifndef SQLITE_OMIT_TEMPDB
|
||||
temp(A) ::= TEMP. {A = 1;}
|
||||
%endif
|
||||
temp(A) ::= . {A = 0;}
|
||||
create_table_args ::= LP columnlist conslist_opt RP(X). {
|
||||
sqlite3EndTable(pParse,&X,0);
|
||||
create_table_args ::= LP columnlist conslist_opt(X) RP(Y). {
|
||||
sqlite3EndTable(pParse,&X,&Y,0);
|
||||
}
|
||||
create_table_args ::= AS select(S). {
|
||||
sqlite3EndTable(pParse,0,S);
|
||||
sqlite3EndTable(pParse,0,0,S);
|
||||
sqlite3SelectDelete(S);
|
||||
}
|
||||
columnlist ::= columnlist COMMA column.
|
||||
columnlist ::= column.
|
||||
|
||||
// About the only information used for a column is the name of the
|
||||
// column. The type is always just "text". But the code will accept
|
||||
// an elaborate typename. Perhaps someday we'll do something with it.
|
||||
// A "column" is a complete description of a single column in a
|
||||
// CREATE TABLE statement. This includes the column name, its
|
||||
// datatype, and other keywords such as PRIMARY KEY, UNIQUE, REFERENCES,
|
||||
// NOT NULL and so forth.
|
||||
//
|
||||
column ::= columnid type carglist.
|
||||
columnid ::= nm(X). {sqlite3AddColumn(pParse,&X);}
|
||||
column(A) ::= columnid(X) type carglist. {
|
||||
A.z = X.z;
|
||||
A.n = (pParse->sLastToken.z-X.z) + pParse->sLastToken.n;
|
||||
}
|
||||
columnid(A) ::= nm(X). {
|
||||
sqlite3AddColumn(pParse,&X);
|
||||
A = X;
|
||||
}
|
||||
|
||||
|
||||
// An IDENTIFIER can be a generic identifier, or one of several
|
||||
// keywords. Any non-standard keyword can also be an identifier.
|
||||
@@ -126,22 +171,34 @@ id(A) ::= ID(X). {A = X;}
|
||||
// This obviates the need for the "id" nonterminal.
|
||||
//
|
||||
%fallback ID
|
||||
ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT
|
||||
DATABASE DEFERRED DESC DETACH EACH END EXPLAIN FAIL FOR
|
||||
GLOB IGNORE IMMEDIATE INITIALLY INSTEAD LIKE MATCH KEY
|
||||
ABORT AFTER ANALYZE ASC ATTACH BEFORE BEGIN CASCADE CAST CONFLICT
|
||||
DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR
|
||||
IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH PLAN QUERY KEY
|
||||
OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT
|
||||
TEMP TRIGGER VACUUM VIEW.
|
||||
TEMP TRIGGER VACUUM VIEW
|
||||
%ifdef SQLITE_OMIT_COMPOUND_SELECT
|
||||
EXCEPT INTERSECT UNION
|
||||
%endif
|
||||
REINDEX RENAME CTIME_KW ALTER
|
||||
.
|
||||
|
||||
// Define operator precedence early so that this is the first occurance
|
||||
// of the operator tokens in the grammer. Keeping the operators together
|
||||
// causes them to be assigned integer values that are close together,
|
||||
// which keeps parser tables smaller.
|
||||
//
|
||||
// The token values assigned to these symbols is determined by the order
|
||||
// in which lemon first sees them. It must be the case that ISNULL/NOTNULL,
|
||||
// NE/EQ, GT/LE, and GE/LT are separated by only a single value. See
|
||||
// the sqlite3ExprIfFalse() routine for additional information on this
|
||||
// constraint.
|
||||
//
|
||||
%left OR.
|
||||
%left AND.
|
||||
%right NOT.
|
||||
%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
|
||||
%left GT GE LT LE.
|
||||
%left IS LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ.
|
||||
%left GT LE LT GE.
|
||||
%right ESCAPE.
|
||||
%left BITAND BITOR LSHIFT RSHIFT.
|
||||
%left PLUS MINUS.
|
||||
%left STAR SLASH REM.
|
||||
@@ -161,45 +218,67 @@ nm(A) ::= ID(X). {A = X;}
|
||||
nm(A) ::= STRING(X). {A = X;}
|
||||
nm(A) ::= JOIN_KW(X). {A = X;}
|
||||
|
||||
// A typetoken is really one or more tokens that form a type name such
|
||||
// as can be found after the column name in a CREATE TABLE statement.
|
||||
// Multiple tokens are concatenated to form the value of the typetoken.
|
||||
//
|
||||
%type typetoken {Token}
|
||||
type ::= .
|
||||
type ::= typename(X). {sqlite3AddColumnType(pParse,&X,&X);}
|
||||
type ::= typename(X) LP signed RP(Y). {sqlite3AddColumnType(pParse,&X,&Y);}
|
||||
type ::= typename(X) LP signed COMMA signed RP(Y).
|
||||
{sqlite3AddColumnType(pParse,&X,&Y);}
|
||||
type ::= typetoken(X). {sqlite3AddColumnType(pParse,&X);}
|
||||
typetoken(A) ::= typename(X). {A = X;}
|
||||
typetoken(A) ::= typename(X) LP signed RP(Y). {
|
||||
A.z = X.z;
|
||||
A.n = &Y.z[Y.n] - X.z;
|
||||
}
|
||||
typetoken(A) ::= typename(X) LP signed COMMA signed RP(Y). {
|
||||
A.z = X.z;
|
||||
A.n = &Y.z[Y.n] - X.z;
|
||||
}
|
||||
%type typename {Token}
|
||||
typename(A) ::= ids(X). {A = X;}
|
||||
typename(A) ::= typename(X) ids(Y). {A.z=X.z; A.n=X.n+Addr(Y.z)-Addr(X.z);}
|
||||
typename(A) ::= typename(X) ids(Y). {A.z=X.z; A.n=Y.n+(Y.z-X.z);}
|
||||
%type signed {int}
|
||||
signed(A) ::= INTEGER(X). { A = atoi(X.z); }
|
||||
signed(A) ::= PLUS INTEGER(X). { A = atoi(X.z); }
|
||||
signed(A) ::= MINUS INTEGER(X). { A = -atoi(X.z); }
|
||||
signed(A) ::= plus_num(X). { A = atoi(X.z); }
|
||||
signed(A) ::= minus_num(X). { A = -atoi(X.z); }
|
||||
|
||||
// "carglist" is a list of additional constraints that come after the
|
||||
// column name and column type in a CREATE TABLE statement.
|
||||
//
|
||||
carglist ::= carglist carg.
|
||||
carglist ::= .
|
||||
carg ::= CONSTRAINT nm ccons.
|
||||
carg ::= ccons.
|
||||
carg ::= DEFAULT STRING(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT ID(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT INTEGER(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT PLUS INTEGER(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT MINUS INTEGER(X). {sqlite3AddDefaultValue(pParse,&X,1);}
|
||||
carg ::= DEFAULT FLOAT(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT PLUS FLOAT(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT MINUS FLOAT(X). {sqlite3AddDefaultValue(pParse,&X,1);}
|
||||
carg ::= DEFAULT NULL.
|
||||
carg ::= DEFAULT term(X). {sqlite3AddDefaultValue(pParse,X);}
|
||||
carg ::= DEFAULT LP expr(X) RP. {sqlite3AddDefaultValue(pParse,X);}
|
||||
carg ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,X);}
|
||||
carg ::= DEFAULT MINUS term(X). {
|
||||
Expr *p = sqlite3Expr(TK_UMINUS, X, 0, 0);
|
||||
sqlite3AddDefaultValue(pParse,p);
|
||||
}
|
||||
carg ::= DEFAULT id(X). {
|
||||
Expr *p = sqlite3Expr(TK_STRING, 0, 0, &X);
|
||||
sqlite3AddDefaultValue(pParse,p);
|
||||
}
|
||||
|
||||
// In addition to the type name, we also care about the primary key and
|
||||
// UNIQUE constraints.
|
||||
//
|
||||
ccons ::= NULL onconf.
|
||||
ccons ::= NOT NULL onconf(R). {sqlite3AddNotNull(pParse, R);}
|
||||
ccons ::= PRIMARY KEY sortorder onconf(R). {sqlite3AddPrimaryKey(pParse,0,R);}
|
||||
ccons ::= UNIQUE onconf(R). {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0);}
|
||||
ccons ::= CHECK LP expr RP onconf.
|
||||
ccons ::= PRIMARY KEY sortorder onconf(R) autoinc(I).
|
||||
{sqlite3AddPrimaryKey(pParse,0,R,I);}
|
||||
ccons ::= UNIQUE onconf(R). {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0);}
|
||||
ccons ::= CHECK LP expr(X) RP onconf. {sqlite3ExprDelete(X);}
|
||||
ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R).
|
||||
{sqlite3CreateForeignKey(pParse,0,&T,TA,R);}
|
||||
ccons ::= defer_subclause(D). {sqlite3DeferForeignKey(pParse,D);}
|
||||
ccons ::= COLLATE id(C). {sqlite3AddCollateType(pParse, C.z, C.n);}
|
||||
|
||||
// The optional AUTOINCREMENT keyword
|
||||
%type autoinc {int}
|
||||
autoinc(X) ::= . {X = 0;}
|
||||
autoinc(X) ::= AUTOINCR. {X = 1;}
|
||||
|
||||
// The next group of rules parses the arguments to a REFERENCES clause
|
||||
// that determine if the referential integrity checking is deferred or
|
||||
// or immediate and which determine what action to take if a ref-integ
|
||||
@@ -229,14 +308,14 @@ init_deferred_pred_opt(A) ::= INITIALLY IMMEDIATE. {A = 0;}
|
||||
// For the time being, the only constraint we care about is the primary
|
||||
// key and UNIQUE. Both create indices.
|
||||
//
|
||||
conslist_opt ::= .
|
||||
conslist_opt ::= COMMA conslist.
|
||||
conslist_opt(A) ::= . {A.n = 0; A.z = 0;}
|
||||
conslist_opt(A) ::= COMMA(X) conslist. {A = X;}
|
||||
conslist ::= conslist COMMA tcons.
|
||||
conslist ::= conslist tcons.
|
||||
conslist ::= tcons.
|
||||
tcons ::= CONSTRAINT nm.
|
||||
tcons ::= PRIMARY KEY LP idxlist(X) RP onconf(R).
|
||||
{sqlite3AddPrimaryKey(pParse,X,R);}
|
||||
tcons ::= PRIMARY KEY LP idxlist(X) autoinc(I) RP onconf(R).
|
||||
{sqlite3AddPrimaryKey(pParse,X,R,I);}
|
||||
tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
|
||||
{sqlite3CreateIndex(pParse,0,0,0,X,R,0,0);}
|
||||
tcons ::= CHECK expr onconf.
|
||||
@@ -255,30 +334,30 @@ defer_subclause_opt(A) ::= defer_subclause(X). {A = X;}
|
||||
%type onconf {int}
|
||||
%type orconf {int}
|
||||
%type resolvetype {int}
|
||||
onconf(A) ::= . { A = OE_Default; }
|
||||
onconf(A) ::= ON CONFLICT resolvetype(X). { A = X; }
|
||||
orconf(A) ::= . { A = OE_Default; }
|
||||
orconf(A) ::= OR resolvetype(X). { A = X; }
|
||||
resolvetype(A) ::= ROLLBACK. { A = OE_Rollback; }
|
||||
resolvetype(A) ::= ABORT. { A = OE_Abort; }
|
||||
resolvetype(A) ::= FAIL. { A = OE_Fail; }
|
||||
resolvetype(A) ::= IGNORE. { A = OE_Ignore; }
|
||||
resolvetype(A) ::= REPLACE. { A = OE_Replace; }
|
||||
onconf(A) ::= . {A = OE_Default;}
|
||||
onconf(A) ::= ON CONFLICT resolvetype(X). {A = X;}
|
||||
orconf(A) ::= . {A = OE_Default;}
|
||||
orconf(A) ::= OR resolvetype(X). {A = X;}
|
||||
resolvetype(A) ::= raisetype(X). {A = X;}
|
||||
resolvetype(A) ::= IGNORE. {A = OE_Ignore;}
|
||||
resolvetype(A) ::= REPLACE. {A = OE_Replace;}
|
||||
|
||||
////////////////////////// The DROP TABLE /////////////////////////////////////
|
||||
//
|
||||
cmd ::= DROP TABLE nm(X) dbnm(Y). {
|
||||
sqlite3DropTable(pParse, sqlite3SrcListAppend(0,&X,&Y), 0);
|
||||
cmd ::= DROP TABLE fullname(X). {
|
||||
sqlite3DropTable(pParse, X, 0);
|
||||
}
|
||||
|
||||
///////////////////// The CREATE VIEW statement /////////////////////////////
|
||||
//
|
||||
%ifndef SQLITE_OMIT_VIEW
|
||||
cmd ::= CREATE(X) temp(T) VIEW nm(Y) dbnm(Z) AS select(S). {
|
||||
sqlite3CreateView(pParse, &X, &Y, &Z, S, T);
|
||||
}
|
||||
cmd ::= DROP VIEW nm(X) dbnm(Y). {
|
||||
sqlite3DropTable(pParse, sqlite3SrcListAppend(0,&X,&Y), 1);
|
||||
cmd ::= DROP VIEW fullname(X). {
|
||||
sqlite3DropTable(pParse, X, 1);
|
||||
}
|
||||
%endif // SQLITE_OMIT_VIEW
|
||||
|
||||
//////////////////////// The SELECT statement /////////////////////////////////
|
||||
//
|
||||
@@ -293,6 +372,7 @@ cmd ::= select(X). {
|
||||
%destructor oneselect {sqlite3SelectDelete($$);}
|
||||
|
||||
select(A) ::= oneselect(X). {A = X;}
|
||||
%ifndef SQLITE_OMIT_COMPOUND_SELECT
|
||||
select(A) ::= select(X) multiselect_op(Y) oneselect(Z). {
|
||||
if( Z ){
|
||||
Z->op = Y;
|
||||
@@ -301,13 +381,14 @@ select(A) ::= select(X) multiselect_op(Y) oneselect(Z). {
|
||||
A = Z;
|
||||
}
|
||||
%type multiselect_op {int}
|
||||
multiselect_op(A) ::= UNION. {A = TK_UNION;}
|
||||
multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
|
||||
multiselect_op(A) ::= INTERSECT. {A = TK_INTERSECT;}
|
||||
multiselect_op(A) ::= EXCEPT. {A = TK_EXCEPT;}
|
||||
multiselect_op(A) ::= UNION(OP). {A = @OP;}
|
||||
multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
|
||||
multiselect_op(A) ::= INTERSECT(OP). {A = @OP;}
|
||||
multiselect_op(A) ::= EXCEPT(OP). {A = @OP;}
|
||||
%endif // SQLITE_OMIT_COMPOUND_SELECT
|
||||
oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
|
||||
groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
|
||||
A = sqlite3SelectNew(W,X,Y,P,Q,Z,D,L.limit,L.offset);
|
||||
A = sqlite3SelectNew(W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset);
|
||||
}
|
||||
|
||||
// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
|
||||
@@ -345,9 +426,9 @@ selcollist(A) ::= sclp(P) nm(X) DOT STAR. {
|
||||
// define the result set, or one of the tables in the FROM clause.
|
||||
//
|
||||
%type as {Token}
|
||||
as(X) ::= AS nm(Y). { X = Y; }
|
||||
as(X) ::= ids(Y). { X = Y; }
|
||||
as(X) ::= . { X.n = 0; }
|
||||
as(X) ::= AS nm(Y). {X = Y;}
|
||||
as(X) ::= ids(Y). {X = Y;}
|
||||
as(X) ::= . {X.n = 0;}
|
||||
|
||||
|
||||
%type seltablist {SrcList*}
|
||||
@@ -382,36 +463,42 @@ seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) on_opt(N) using_opt(U). {
|
||||
else { sqlite3IdListDelete(U); }
|
||||
}
|
||||
}
|
||||
seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP
|
||||
as(Z) on_opt(N) using_opt(U). {
|
||||
A = sqlite3SrcListAppend(X,0,0);
|
||||
A->a[A->nSrc-1].pSelect = S;
|
||||
if( Z.n ) sqlite3SrcListAddAlias(A,&Z);
|
||||
if( N ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
|
||||
else { sqlite3ExprDelete(N); }
|
||||
%ifndef SQLITE_OMIT_SUBQUERY
|
||||
seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP
|
||||
as(Z) on_opt(N) using_opt(U). {
|
||||
A = sqlite3SrcListAppend(X,0,0);
|
||||
A->a[A->nSrc-1].pSelect = S;
|
||||
if( Z.n ) sqlite3SrcListAddAlias(A,&Z);
|
||||
if( N ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
|
||||
else { sqlite3ExprDelete(N); }
|
||||
}
|
||||
if( U ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
|
||||
else { sqlite3IdListDelete(U); }
|
||||
}
|
||||
}
|
||||
if( U ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
|
||||
else { sqlite3IdListDelete(U); }
|
||||
|
||||
// A seltablist_paren nonterminal represents anything in a FROM that
|
||||
// is contained inside parentheses. This can be either a subquery or
|
||||
// a grouping of table and subqueries.
|
||||
//
|
||||
%type seltablist_paren {Select*}
|
||||
%destructor seltablist_paren {sqlite3SelectDelete($$);}
|
||||
seltablist_paren(A) ::= select(S). {A = S;}
|
||||
seltablist_paren(A) ::= seltablist(F). {
|
||||
A = sqlite3SelectNew(0,F,0,0,0,0,0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
// A seltablist_paren nonterminal represents anything in a FROM that
|
||||
// is contained inside parentheses. This can be either a subquery or
|
||||
// a grouping of table and subqueries.
|
||||
//
|
||||
%type seltablist_paren {Select*}
|
||||
%destructor seltablist_paren {sqlite3SelectDelete($$);}
|
||||
seltablist_paren(A) ::= select(S). {A = S;}
|
||||
seltablist_paren(A) ::= seltablist(F). {
|
||||
A = sqlite3SelectNew(0,F,0,0,0,0,0,-1,0);
|
||||
}
|
||||
%endif // SQLITE_OMIT_SUBQUERY
|
||||
|
||||
%type dbnm {Token}
|
||||
dbnm(A) ::= . {A.z=0; A.n=0;}
|
||||
dbnm(A) ::= DOT nm(X). {A = X;}
|
||||
|
||||
%type fullname {SrcList*}
|
||||
%destructor fullname {sqlite3SrcListDelete($$);}
|
||||
fullname(A) ::= nm(X) dbnm(Y). {A = sqlite3SrcListAppend(0,&X,&Y);}
|
||||
|
||||
%type joinop {int}
|
||||
%type joinop2 {int}
|
||||
joinop(X) ::= COMMA. { X = JT_INNER; }
|
||||
@@ -471,18 +558,20 @@ having_opt(A) ::= . {A = 0;}
|
||||
having_opt(A) ::= HAVING expr(X). {A = X;}
|
||||
|
||||
%type limit_opt {struct LimitVal}
|
||||
limit_opt(A) ::= . {A.limit = -1; A.offset = 0;}
|
||||
limit_opt(A) ::= LIMIT signed(X). {A.limit = X; A.offset = 0;}
|
||||
limit_opt(A) ::= LIMIT signed(X) OFFSET signed(Y).
|
||||
{A.limit = X; A.offset = Y;}
|
||||
limit_opt(A) ::= LIMIT signed(X) COMMA signed(Y).
|
||||
{A.limit = Y; A.offset = X;}
|
||||
%destructor limit_opt {
|
||||
sqlite3ExprDelete($$.pLimit);
|
||||
sqlite3ExprDelete($$.pOffset);
|
||||
}
|
||||
limit_opt(A) ::= . {A.pLimit = 0; A.pOffset = 0;}
|
||||
limit_opt(A) ::= LIMIT expr(X). {A.pLimit = X; A.pOffset = 0;}
|
||||
limit_opt(A) ::= LIMIT expr(X) OFFSET expr(Y).
|
||||
{A.pLimit = X; A.pOffset = Y;}
|
||||
limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y).
|
||||
{A.pOffset = X; A.pLimit = Y;}
|
||||
|
||||
/////////////////////////// The DELETE statement /////////////////////////////
|
||||
//
|
||||
cmd ::= DELETE FROM nm(X) dbnm(D) where_opt(Y). {
|
||||
sqlite3DeleteFrom(pParse, sqlite3SrcListAppend(0,&X,&D), Y);
|
||||
}
|
||||
cmd ::= DELETE FROM fullname(X) where_opt(Y). {sqlite3DeleteFrom(pParse,X,Y);}
|
||||
|
||||
%type where_opt {Expr*}
|
||||
%destructor where_opt {sqlite3ExprDelete($$);}
|
||||
@@ -490,13 +579,13 @@ cmd ::= DELETE FROM nm(X) dbnm(D) where_opt(Y). {
|
||||
where_opt(A) ::= . {A = 0;}
|
||||
where_opt(A) ::= WHERE expr(X). {A = X;}
|
||||
|
||||
%type setlist {ExprList*}
|
||||
%destructor setlist {sqlite3ExprListDelete($$);}
|
||||
|
||||
////////////////////////// The UPDATE command ////////////////////////////////
|
||||
//
|
||||
cmd ::= UPDATE orconf(R) nm(X) dbnm(D) SET setlist(Y) where_opt(Z).
|
||||
{sqlite3Update(pParse,sqlite3SrcListAppend(0,&X,&D),Y,Z,R);}
|
||||
cmd ::= UPDATE orconf(R) fullname(X) SET setlist(Y) where_opt(Z).
|
||||
{sqlite3Update(pParse,X,Y,Z,R);}
|
||||
|
||||
%type setlist {ExprList*}
|
||||
%destructor setlist {sqlite3ExprListDelete($$);}
|
||||
|
||||
setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y).
|
||||
{A = sqlite3ExprListAppend(Z,Y,&X);}
|
||||
@@ -504,11 +593,11 @@ setlist(A) ::= nm(X) EQ expr(Y). {A = sqlite3ExprListAppend(0,Y,&X);}
|
||||
|
||||
////////////////////////// The INSERT command /////////////////////////////////
|
||||
//
|
||||
cmd ::= insert_cmd(R) INTO nm(X) dbnm(D) inscollist_opt(F)
|
||||
cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F)
|
||||
VALUES LP itemlist(Y) RP.
|
||||
{sqlite3Insert(pParse, sqlite3SrcListAppend(0,&X,&D), Y, 0, F, R);}
|
||||
cmd ::= insert_cmd(R) INTO nm(X) dbnm(D) inscollist_opt(F) select(S).
|
||||
{sqlite3Insert(pParse, sqlite3SrcListAppend(0,&X,&D), 0, S, F, R);}
|
||||
{sqlite3Insert(pParse, X, Y, 0, F, R);}
|
||||
cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) select(S).
|
||||
{sqlite3Insert(pParse, X, 0, S, F, R);}
|
||||
|
||||
%type insert_cmd {int}
|
||||
insert_cmd(A) ::= INSERT orconf(R). {A = R;}
|
||||
@@ -536,9 +625,12 @@ inscollist(A) ::= nm(Y). {A = sqlite3IdListAppend(0,&Y);}
|
||||
|
||||
%type expr {Expr*}
|
||||
%destructor expr {sqlite3ExprDelete($$);}
|
||||
%type term {Expr*}
|
||||
%destructor term {sqlite3ExprDelete($$);}
|
||||
|
||||
expr(A) ::= term(X). {A = X;}
|
||||
expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqlite3ExprSpan(A,&B,&E); }
|
||||
expr(A) ::= NULL(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= NULL(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= ID(X). {A = sqlite3Expr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= JOIN_KW(X). {A = sqlite3Expr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= nm(X) DOT nm(Y). {
|
||||
@@ -553,25 +645,39 @@ expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
|
||||
Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0);
|
||||
A = sqlite3Expr(TK_DOT, temp1, temp4, 0);
|
||||
}
|
||||
expr(A) ::= INTEGER(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= FLOAT(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= STRING(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= INTEGER(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= FLOAT(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= STRING(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= REGISTER(X). {A = sqlite3RegisterExpr(pParse, &X);}
|
||||
expr(A) ::= VARIABLE(X). {
|
||||
Token *pToken = &X;
|
||||
Expr *pExpr = A = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
|
||||
if( pExpr ){
|
||||
pExpr->iTable = ++pParse->nVar;
|
||||
}
|
||||
sqlite3ExprAssignVarNumber(pParse, pExpr);
|
||||
}
|
||||
expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
|
||||
%ifndef SQLITE_OMIT_CAST
|
||||
expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). {
|
||||
A = sqlite3Expr(TK_CAST, E, 0, &T);
|
||||
sqlite3ExprSpan(A,&X,&Y);
|
||||
}
|
||||
%endif // SQLITE_OMIT_CAST
|
||||
expr(A) ::= ID(X) LP distinct(D) exprlist(Y) RP(E). {
|
||||
A = sqlite3ExprFunction(Y, &X);
|
||||
sqlite3ExprSpan(A,&X,&E);
|
||||
if( D ){
|
||||
A->flags |= EP_Distinct;
|
||||
}
|
||||
}
|
||||
expr(A) ::= ID(X) LP STAR RP(E). {
|
||||
A = sqlite3ExprFunction(0, &X);
|
||||
sqlite3ExprSpan(A,&X,&E);
|
||||
}
|
||||
term(A) ::= CTIME_KW(OP). {
|
||||
/* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
|
||||
** treated as functions that return constants */
|
||||
A = sqlite3ExprFunction(0,&OP);
|
||||
if( A ) A->op = TK_CONST_FUNC;
|
||||
}
|
||||
expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
@@ -584,30 +690,29 @@ expr(A) ::= expr(X) BITAND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITOR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LSHIFT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) RSHIFT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) likeop(OP) expr(Y). [LIKE] {
|
||||
ExprList *pList = sqlite3ExprListAppend(0, Y, 0);
|
||||
pList = sqlite3ExprListAppend(pList, X, 0);
|
||||
A = sqlite3ExprFunction(pList, 0);
|
||||
if( A ) A->op = OP;
|
||||
sqlite3ExprSpan(A, &X->span, &Y->span);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT likeop(OP) expr(Y). [LIKE] {
|
||||
ExprList *pList = sqlite3ExprListAppend(0, Y, 0);
|
||||
pList = sqlite3ExprListAppend(pList, X, 0);
|
||||
A = sqlite3ExprFunction(pList, 0);
|
||||
if( A ) A->op = OP;
|
||||
A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&Y->span);
|
||||
}
|
||||
%type likeop {int}
|
||||
likeop(A) ::= LIKE. {A = TK_LIKE;}
|
||||
likeop(A) ::= GLOB. {A = TK_GLOB;}
|
||||
expr(A) ::= expr(X) PLUS(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) MINUS(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) STAR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) SLASH(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) REM(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
%type likeop {struct LikeOp}
|
||||
likeop(A) ::= LIKE_KW(X). {A.operator = X; A.not = 0;}
|
||||
likeop(A) ::= NOT LIKE_KW(X). {A.operator = X; A.not = 1;}
|
||||
%type escape {Expr*}
|
||||
escape(X) ::= ESCAPE expr(A). [ESCAPE] {X = A;}
|
||||
escape(X) ::= . [ESCAPE] {X = 0;}
|
||||
expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E). [LIKE_KW] {
|
||||
ExprList *pList = sqlite3ExprListAppend(0, Y, 0);
|
||||
pList = sqlite3ExprListAppend(pList, X, 0);
|
||||
if( E ){
|
||||
pList = sqlite3ExprListAppend(pList, E, 0);
|
||||
}
|
||||
A = sqlite3ExprFunction(pList, &OP.operator);
|
||||
if( OP.not ) A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A, &X->span, &Y->span);
|
||||
}
|
||||
|
||||
expr(A) ::= expr(X) ISNULL(E). {
|
||||
A = sqlite3Expr(TK_ISNULL, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
@@ -644,67 +749,84 @@ expr(A) ::= PLUS(B) expr(X). [UPLUS] {
|
||||
A = sqlite3Expr(TK_UPLUS, X, 0, 0);
|
||||
sqlite3ExprSpan(A,&B,&X->span);
|
||||
}
|
||||
expr(A) ::= LP(B) select(X) RP(E). {
|
||||
A = sqlite3Expr(TK_SELECT, 0, 0, 0);
|
||||
if( A ) A->pSelect = X;
|
||||
sqlite3ExprSpan(A,&B,&E);
|
||||
}
|
||||
expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
|
||||
%type between_op {int}
|
||||
between_op(A) ::= BETWEEN. {A = 0;}
|
||||
between_op(A) ::= NOT BETWEEN. {A = 1;}
|
||||
expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
|
||||
ExprList *pList = sqlite3ExprListAppend(0, X, 0);
|
||||
pList = sqlite3ExprListAppend(pList, Y, 0);
|
||||
A = sqlite3Expr(TK_BETWEEN, W, 0, 0);
|
||||
if( A ) A->pList = pList;
|
||||
if( A ){
|
||||
A->pList = pList;
|
||||
}else{
|
||||
sqlite3ExprListDelete(pList);
|
||||
}
|
||||
if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&W->span,&Y->span);
|
||||
}
|
||||
expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
|
||||
ExprList *pList = sqlite3ExprListAppend(0, X, 0);
|
||||
pList = sqlite3ExprListAppend(pList, Y, 0);
|
||||
A = sqlite3Expr(TK_BETWEEN, W, 0, 0);
|
||||
if( A ) A->pList = pList;
|
||||
A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&W->span,&Y->span);
|
||||
}
|
||||
expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pList = Y;
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) IN LP select(Y) RP(E). {
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = Y;
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pList = Y;
|
||||
A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = Y;
|
||||
A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) IN nm(Y) dbnm(D). {
|
||||
SrcList *pSrc = sqlite3SrcListAppend(0, &Y, &D);
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,-1,0);
|
||||
sqlite3ExprSpan(A,&X->span,D.z?&D:&Y);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT IN nm(Y) dbnm(D). {
|
||||
SrcList *pSrc = sqlite3SrcListAppend(0, &Y, &D);
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,-1,0);
|
||||
A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,D.z?&D:&Y);
|
||||
}
|
||||
|
||||
%ifndef SQLITE_OMIT_SUBQUERY
|
||||
%type in_op {int}
|
||||
in_op(A) ::= IN. {A = 0;}
|
||||
in_op(A) ::= NOT IN. {A = 1;}
|
||||
expr(A) ::= expr(X) in_op(N) LP exprlist(Y) RP(E). [IN] {
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ){
|
||||
A->pList = Y;
|
||||
}else{
|
||||
sqlite3ExprListDelete(Y);
|
||||
}
|
||||
if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= LP(B) select(X) RP(E). {
|
||||
A = sqlite3Expr(TK_SELECT, 0, 0, 0);
|
||||
if( A ){
|
||||
A->pSelect = X;
|
||||
}else{
|
||||
sqlite3SelectDelete(X);
|
||||
}
|
||||
sqlite3ExprSpan(A,&B,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) in_op(N) LP select(Y) RP(E). [IN] {
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ){
|
||||
A->pSelect = Y;
|
||||
}else{
|
||||
sqlite3SelectDelete(Y);
|
||||
}
|
||||
if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) in_op(N) nm(Y) dbnm(Z). [IN] {
|
||||
SrcList *pSrc = sqlite3SrcListAppend(0,&Y,&Z);
|
||||
A = sqlite3Expr(TK_IN, X, 0, 0);
|
||||
if( A ){
|
||||
A->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0);
|
||||
}else{
|
||||
sqlite3SrcListDelete(pSrc);
|
||||
}
|
||||
if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
|
||||
sqlite3ExprSpan(A,&X->span,Z.z?&Z:&Y);
|
||||
}
|
||||
expr(A) ::= EXISTS(B) LP select(Y) RP(E). {
|
||||
Expr *p = A = sqlite3Expr(TK_EXISTS, 0, 0, 0);
|
||||
if( p ){
|
||||
p->pSelect = Y;
|
||||
sqlite3ExprSpan(p,&B,&E);
|
||||
}else{
|
||||
sqlite3SelectDelete(Y);
|
||||
}
|
||||
}
|
||||
%endif // SQLITE_OMIT_SUBQUERY
|
||||
|
||||
/* CASE expressions */
|
||||
expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
|
||||
A = sqlite3Expr(TK_CASE, X, Z, 0);
|
||||
if( A ) A->pList = Y;
|
||||
if( A ){
|
||||
A->pList = Y;
|
||||
}else{
|
||||
sqlite3ExprListDelete(Y);
|
||||
}
|
||||
sqlite3ExprSpan(A, &C, &E);
|
||||
}
|
||||
%type case_exprlist {ExprList*}
|
||||
@@ -730,7 +852,7 @@ case_operand(A) ::= . {A = 0;}
|
||||
%destructor expritem {sqlite3ExprDelete($$);}
|
||||
|
||||
exprlist(A) ::= exprlist(X) COMMA expritem(Y).
|
||||
{A = sqlite3ExprListAppend(X,Y,0);}
|
||||
{A = sqlite3ExprListAppend(X,Y,0);}
|
||||
exprlist(A) ::= expritem(X). {A = sqlite3ExprListAppend(0,X,0);}
|
||||
expritem(A) ::= expr(X). {A = X;}
|
||||
expritem(A) ::= . {A = 0;}
|
||||
@@ -738,16 +860,15 @@ expritem(A) ::= . {A = 0;}
|
||||
///////////////////////////// The CREATE INDEX command ///////////////////////
|
||||
//
|
||||
cmd ::= CREATE(S) uniqueflag(U) INDEX nm(X) dbnm(D)
|
||||
ON nm(Y) dbnm(C) LP idxlist(Z) RP(E) onconf(R). {
|
||||
ON nm(Y) LP idxlist(Z) RP(E) onconf(R). {
|
||||
if( U!=OE_None ) U = R;
|
||||
if( U==OE_Default) U = OE_Abort;
|
||||
sqlite3CreateIndex(pParse, &X, &D, sqlite3SrcListAppend(0,&Y,&C),
|
||||
Z, U, &S, &E);
|
||||
sqlite3CreateIndex(pParse, &X, &D, sqlite3SrcListAppend(0,&Y,0),Z,U, &S, &E);
|
||||
}
|
||||
|
||||
%type uniqueflag {int}
|
||||
uniqueflag(A) ::= UNIQUE. { A = OE_Abort; }
|
||||
uniqueflag(A) ::= . { A = OE_None; }
|
||||
uniqueflag(A) ::= UNIQUE. {A = OE_Abort;}
|
||||
uniqueflag(A) ::= . {A = OE_None;}
|
||||
|
||||
%type idxlist {ExprList*}
|
||||
%destructor idxlist {sqlite3ExprListDelete($$);}
|
||||
@@ -778,18 +899,16 @@ idxitem(A) ::= nm(X). {A = X;}
|
||||
|
||||
///////////////////////////// The DROP INDEX command /////////////////////////
|
||||
//
|
||||
|
||||
cmd ::= DROP INDEX nm(X) dbnm(Y). {
|
||||
sqlite3DropIndex(pParse, sqlite3SrcListAppend(0,&X,&Y));
|
||||
}
|
||||
cmd ::= DROP INDEX fullname(X). {sqlite3DropIndex(pParse, X);}
|
||||
|
||||
///////////////////////////// The VACUUM command /////////////////////////////
|
||||
//
|
||||
cmd ::= VACUUM. {sqlite3Vacuum(pParse,0);}
|
||||
cmd ::= VACUUM nm(X). {sqlite3Vacuum(pParse,&X);}
|
||||
cmd ::= VACUUM nm. {sqlite3Vacuum(pParse,0);}
|
||||
|
||||
///////////////////////////// The PRAGMA command /////////////////////////////
|
||||
//
|
||||
%ifndef SQLITE_OMIT_PRAGMA
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z) EQ nm(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z) EQ ON(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z) EQ plus_num(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
|
||||
@@ -797,16 +916,19 @@ cmd ::= PRAGMA nm(X) dbnm(Z) EQ minus_num(Y). {
|
||||
sqlite3Pragma(pParse,&X,&Z,&Y,1);
|
||||
}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z) LP nm(Y) RP. {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z). {sqlite3Pragma(pParse,&X,&Z,0,0);}
|
||||
cmd ::= PRAGMA nm(X) dbnm(Z). {sqlite3Pragma(pParse,&X,&Z,0,0);}
|
||||
%endif // SQLITE_OMIT_PRAGMA
|
||||
plus_num(A) ::= plus_opt number(X). {A = X;}
|
||||
minus_num(A) ::= MINUS number(X). {A = X;}
|
||||
number(A) ::= INTEGER(X). {A = X;}
|
||||
number(A) ::= FLOAT(X). {A = X;}
|
||||
number(A) ::= INTEGER(X). {A = X;}
|
||||
number(A) ::= FLOAT(X). {A = X;}
|
||||
plus_opt ::= PLUS.
|
||||
plus_opt ::= .
|
||||
|
||||
//////////////////////////// The CREATE TRIGGER command /////////////////////
|
||||
|
||||
%ifndef SQLITE_OMIT_TRIGGER
|
||||
|
||||
cmd ::= CREATE trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). {
|
||||
Token all;
|
||||
all.z = A.z;
|
||||
@@ -814,10 +936,10 @@ cmd ::= CREATE trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). {
|
||||
sqlite3FinishTrigger(pParse, S, &all);
|
||||
}
|
||||
|
||||
trigger_decl(A) ::= temp(T) TRIGGER nm(B) dbnm(Z) trigger_time(C) trigger_event(D)
|
||||
ON nm(E) dbnm(DB) foreach_clause(F) when_clause(G). {
|
||||
SrcList *pTab = sqlite3SrcListAppend(0, &E, &DB);
|
||||
sqlite3BeginTrigger(pParse, &B, &Z, C, D.a, D.b, pTab, F, G, T);
|
||||
trigger_decl(A) ::= temp(T) TRIGGER nm(B) dbnm(Z) trigger_time(C)
|
||||
trigger_event(D)
|
||||
ON fullname(E) foreach_clause(F) when_clause(G). {
|
||||
sqlite3BeginTrigger(pParse, &B, &Z, C, D.a, D.b, E, F, G, T);
|
||||
A = (Z.n==0?B:Z);
|
||||
}
|
||||
|
||||
@@ -829,10 +951,10 @@ trigger_time(A) ::= . { A = TK_BEFORE; }
|
||||
|
||||
%type trigger_event {struct TrigEvent}
|
||||
%destructor trigger_event {sqlite3IdListDelete($$.b);}
|
||||
trigger_event(A) ::= DELETE. { A.a = TK_DELETE; A.b = 0; }
|
||||
trigger_event(A) ::= INSERT. { A.a = TK_INSERT; A.b = 0; }
|
||||
trigger_event(A) ::= UPDATE. { A.a = TK_UPDATE; A.b = 0;}
|
||||
trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X; }
|
||||
trigger_event(A) ::= DELETE(OP). {A.a = @OP; A.b = 0;}
|
||||
trigger_event(A) ::= INSERT(OP). {A.a = @OP; A.b = 0;}
|
||||
trigger_event(A) ::= UPDATE(OP). {A.a = @OP; A.b = 0;}
|
||||
trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X;}
|
||||
|
||||
%type foreach_clause {int}
|
||||
foreach_clause(A) ::= . { A = TK_ROW; }
|
||||
@@ -859,8 +981,8 @@ trigger_cmd(A) ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z).
|
||||
|
||||
// INSERT
|
||||
trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F)
|
||||
VALUES LP itemlist(Y) RP.
|
||||
{A = sqlite3TriggerInsertStep(&X, F, Y, 0, R);}
|
||||
VALUES LP itemlist(Y) RP.
|
||||
{A = sqlite3TriggerInsertStep(&X, F, Y, 0, R);}
|
||||
|
||||
trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S).
|
||||
{A = sqlite3TriggerInsertStep(&X, F, 0, S, R);}
|
||||
@@ -878,26 +1000,25 @@ expr(A) ::= RAISE(X) LP IGNORE RP(Y). {
|
||||
A->iColumn = OE_Ignore;
|
||||
sqlite3ExprSpan(A, &X, &Y);
|
||||
}
|
||||
expr(A) ::= RAISE(X) LP ROLLBACK COMMA nm(Z) RP(Y). {
|
||||
expr(A) ::= RAISE(X) LP raisetype(T) COMMA nm(Z) RP(Y). {
|
||||
A = sqlite3Expr(TK_RAISE, 0, 0, &Z);
|
||||
A->iColumn = OE_Rollback;
|
||||
sqlite3ExprSpan(A, &X, &Y);
|
||||
}
|
||||
expr(A) ::= RAISE(X) LP ABORT COMMA nm(Z) RP(Y). {
|
||||
A = sqlite3Expr(TK_RAISE, 0, 0, &Z);
|
||||
A->iColumn = OE_Abort;
|
||||
sqlite3ExprSpan(A, &X, &Y);
|
||||
}
|
||||
expr(A) ::= RAISE(X) LP FAIL COMMA nm(Z) RP(Y). {
|
||||
A = sqlite3Expr(TK_RAISE, 0, 0, &Z);
|
||||
A->iColumn = OE_Fail;
|
||||
A->iColumn = T;
|
||||
sqlite3ExprSpan(A, &X, &Y);
|
||||
}
|
||||
%endif // !SQLITE_OMIT_TRIGGER
|
||||
|
||||
%type raisetype {int}
|
||||
raisetype(A) ::= ROLLBACK. {A = OE_Rollback;}
|
||||
raisetype(A) ::= ABORT. {A = OE_Abort;}
|
||||
raisetype(A) ::= FAIL. {A = OE_Fail;}
|
||||
|
||||
|
||||
//////////////////////// DROP TRIGGER statement //////////////////////////////
|
||||
cmd ::= DROP TRIGGER nm(X) dbnm(D). {
|
||||
sqlite3DropTrigger(pParse,sqlite3SrcListAppend(0,&X,&D));
|
||||
%ifndef SQLITE_OMIT_TRIGGER
|
||||
cmd ::= DROP TRIGGER fullname(X). {
|
||||
sqlite3DropTrigger(pParse,X);
|
||||
}
|
||||
%endif // !SQLITE_OMIT_TRIGGER
|
||||
|
||||
//////////////////////// ATTACH DATABASE file AS name /////////////////////////
|
||||
cmd ::= ATTACH database_kw_opt ids(F) AS nm(D) key_opt(K). {
|
||||
@@ -915,3 +1036,30 @@ database_kw_opt ::= .
|
||||
cmd ::= DETACH database_kw_opt nm(D). {
|
||||
sqlite3Detach(pParse, &D);
|
||||
}
|
||||
|
||||
////////////////////////// REINDEX collation //////////////////////////////////
|
||||
%ifndef SQLITE_OMIT_REINDEX
|
||||
cmd ::= REINDEX. {sqlite3Reindex(pParse, 0, 0);}
|
||||
cmd ::= REINDEX nm(X) dbnm(Y). {sqlite3Reindex(pParse, &X, &Y);}
|
||||
%endif
|
||||
|
||||
/////////////////////////////////// ANALYZE ///////////////////////////////////
|
||||
%ifndef SQLITE_OMIT_ANALYZE
|
||||
cmd ::= ANALYZE. {sqlite3Analyze(pParse, 0, 0);}
|
||||
cmd ::= ANALYZE nm(X) dbnm(Y). {sqlite3Analyze(pParse, &X, &Y);}
|
||||
%endif
|
||||
|
||||
//////////////////////// ALTER TABLE table ... ////////////////////////////////
|
||||
%ifndef SQLITE_OMIT_ALTERTABLE
|
||||
cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). {
|
||||
sqlite3AlterRenameTable(pParse,X,&Z);
|
||||
}
|
||||
cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column(Y). {
|
||||
sqlite3AlterFinishAddColumn(pParse, &Y);
|
||||
}
|
||||
add_column_fullname ::= fullname(X). {
|
||||
sqlite3AlterBeginAddColumn(pParse, X);
|
||||
}
|
||||
kwcolumn_opt ::= .
|
||||
kwcolumn_opt ::= COLUMNKW.
|
||||
%endif
|
||||
|
||||
+330
-151
@@ -11,32 +11,21 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the PRAGMA command.
|
||||
**
|
||||
** $Id: pragma.c,v 1.62 2004/09/02 15:14:01 drh Exp $
|
||||
** $Id: pragma.c,v 1.100 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include <ctype.h>
|
||||
|
||||
/* Ignore this whole file if pragmas are disabled
|
||||
*/
|
||||
#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
|
||||
|
||||
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
|
||||
# include "pager.h"
|
||||
# include "btree.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Interpret the given string as a boolean value.
|
||||
*/
|
||||
static int getBoolean(const u8 *z){
|
||||
static const u8 *azTrue[] = { "yes", "on", "true" };
|
||||
int i;
|
||||
if( z[0]==0 ) return 0;
|
||||
if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){
|
||||
return atoi(z);
|
||||
}
|
||||
for(i=0; i<sizeof(azTrue)/sizeof(azTrue[0]); i++){
|
||||
if( sqlite3StrICmp(z,azTrue[i])==0 ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Interpret the given string as a safety level. Return 0 for OFF,
|
||||
** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
|
||||
@@ -47,30 +36,33 @@ static int getBoolean(const u8 *z){
|
||||
** to support legacy SQL code. The safety level used to be boolean
|
||||
** and older scripts may have used numbers 0 for OFF and 1 for ON.
|
||||
*/
|
||||
static int getSafetyLevel(u8 *z){
|
||||
static const struct {
|
||||
const u8 *zWord;
|
||||
int val;
|
||||
} aKey[] = {
|
||||
{ "no", 0 },
|
||||
{ "off", 0 },
|
||||
{ "false", 0 },
|
||||
{ "yes", 1 },
|
||||
{ "on", 1 },
|
||||
{ "true", 1 },
|
||||
{ "full", 2 },
|
||||
};
|
||||
int i;
|
||||
if( z[0]==0 ) return 1;
|
||||
if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){
|
||||
static int getSafetyLevel(const u8 *z){
|
||||
/* 123456789 123456789 */
|
||||
static const char zText[] = "onoffalseyestruefull";
|
||||
static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
|
||||
static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
|
||||
static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2};
|
||||
int i, n;
|
||||
if( isdigit(*z) ){
|
||||
return atoi(z);
|
||||
}
|
||||
for(i=0; i<sizeof(aKey)/sizeof(aKey[0]); i++){
|
||||
if( sqlite3StrICmp(z,aKey[i].zWord)==0 ) return aKey[i].val;
|
||||
n = strlen(z);
|
||||
for(i=0; i<sizeof(iLength); i++){
|
||||
if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
|
||||
return iValue[i];
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Interpret the given string as a boolean value.
|
||||
*/
|
||||
static int getBoolean(const u8 *z){
|
||||
return getSafetyLevel(z)&1;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
|
||||
/*
|
||||
** Interpret the given string as a temp db location. Return 1 for file
|
||||
** backed temporary databases, 2 for the Red-Black tree in memory database
|
||||
@@ -87,16 +79,15 @@ static int getTempStore(const char *z){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_PAGER_PRAGMAS */
|
||||
|
||||
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
|
||||
/*
|
||||
** If the TEMP database is open, close it and mark the database schema
|
||||
** as needing reloading. This must be done when using the TEMP_STORE
|
||||
** or DEFAULT_TEMP_STORE pragmas.
|
||||
** Invalidate temp storage, either when the temp storage is changed
|
||||
** from default, or when 'file' and the temp_store_directory has changed
|
||||
*/
|
||||
static int changeTempStorage(Parse *pParse, const char *zStorageType){
|
||||
int ts = getTempStore(zStorageType);
|
||||
sqlite *db = pParse->db;
|
||||
if( db->temp_store==ts ) return SQLITE_OK;
|
||||
static int invalidateTempStorage(Parse *pParse){
|
||||
sqlite3 *db = pParse->db;
|
||||
if( db->aDb[1].pBt!=0 ){
|
||||
if( db->flags & SQLITE_InTrans ){
|
||||
sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
|
||||
@@ -107,9 +98,27 @@ static int changeTempStorage(Parse *pParse, const char *zStorageType){
|
||||
db->aDb[1].pBt = 0;
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
#endif /* SQLITE_PAGER_PRAGMAS */
|
||||
|
||||
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
|
||||
/*
|
||||
** If the TEMP database is open, close it and mark the database schema
|
||||
** as needing reloading. This must be done when using the TEMP_STORE
|
||||
** or DEFAULT_TEMP_STORE pragmas.
|
||||
*/
|
||||
static int changeTempStorage(Parse *pParse, const char *zStorageType){
|
||||
int ts = getTempStore(zStorageType);
|
||||
sqlite3 *db = pParse->db;
|
||||
if( db->temp_store==ts ) return SQLITE_OK;
|
||||
if( invalidateTempStorage( pParse ) != SQLITE_OK ){
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
db->temp_store = ts;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
#endif /* SQLITE_PAGER_PRAGMAS */
|
||||
|
||||
/*
|
||||
** Generate code to return a single integer value.
|
||||
@@ -124,47 +133,56 @@ static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
|
||||
/*
|
||||
** Check to see if zRight and zLeft refer to a pragma that queries
|
||||
** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
|
||||
** Also, implement the pragma.
|
||||
*/
|
||||
static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
|
||||
static const struct {
|
||||
static const struct sPragmaType {
|
||||
const char *zName; /* Name of the pragma */
|
||||
int mask; /* Mask for the db->flags value */
|
||||
} aPragma[] = {
|
||||
{ "vdbe_trace", SQLITE_VdbeTrace },
|
||||
{ "sql_trace", SQLITE_SqlTrace },
|
||||
{ "vdbe_listing", SQLITE_VdbeListing },
|
||||
#if 1 /* FIX ME: Remove the following pragmas */
|
||||
{ "full_column_names", SQLITE_FullColNames },
|
||||
{ "short_column_names", SQLITE_ShortColNames },
|
||||
{ "count_changes", SQLITE_CountRows },
|
||||
{ "empty_result_callbacks", SQLITE_NullCallback },
|
||||
#endif
|
||||
/* The following is VERY experimental */
|
||||
{ "writable_schema", SQLITE_WriteSchema },
|
||||
{ "omit_readlock", SQLITE_NoReadlock },
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aPragma)/sizeof(aPragma[0]); i++){
|
||||
if( sqlite3StrICmp(zLeft, aPragma[i].zName)==0 ){
|
||||
sqlite *db = pParse->db;
|
||||
const struct sPragmaType *p;
|
||||
for(i=0, p=aPragma; i<sizeof(aPragma)/sizeof(aPragma[0]); i++, p++){
|
||||
if( sqlite3StrICmp(zLeft, p->zName)==0 ){
|
||||
sqlite3 *db = pParse->db;
|
||||
Vdbe *v;
|
||||
if( zRight==0 ){
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v ){
|
||||
returnSingleInt(pParse,
|
||||
aPragma[i].zName, (db->flags&aPragma[i].mask)!=0);
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v ){
|
||||
if( zRight==0 ){
|
||||
returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
|
||||
}else{
|
||||
if( getBoolean(zRight) ){
|
||||
db->flags |= p->mask;
|
||||
}else{
|
||||
db->flags &= ~p->mask;
|
||||
}
|
||||
}
|
||||
}else if( getBoolean(zRight) ){
|
||||
db->flags |= aPragma[i].mask;
|
||||
}else{
|
||||
db->flags &= ~aPragma[i].mask;
|
||||
/* If one of these pragmas is executed, any prepared statements
|
||||
** need to be recompiled.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
|
||||
|
||||
/*
|
||||
** Process a pragma statement.
|
||||
@@ -193,7 +211,7 @@ void sqlite3Pragma(
|
||||
const char *zDb = 0; /* The database name */
|
||||
Token *pId; /* Pointer to <id> token */
|
||||
int iDb; /* Database index for <database> */
|
||||
sqlite *db = pParse->db;
|
||||
sqlite3 *db = pParse->db;
|
||||
Db *pDb;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) return;
|
||||
@@ -207,8 +225,7 @@ void sqlite3Pragma(
|
||||
zLeft = sqlite3NameFromToken(pId);
|
||||
if( !zLeft ) return;
|
||||
if( minusFlag ){
|
||||
zRight = 0;
|
||||
sqlite3SetNString(&zRight, "-", 1, pValue->z, pValue->n, 0);
|
||||
zRight = sqlite3MPrintf("-%T", pValue);
|
||||
}else{
|
||||
zRight = sqlite3NameFromToken(pValue);
|
||||
}
|
||||
@@ -218,6 +235,7 @@ void sqlite3Pragma(
|
||||
goto pragma_out;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
|
||||
/*
|
||||
** PRAGMA [database.]default_cache_size
|
||||
** PRAGMA [database.]default_cache_size=N
|
||||
@@ -235,7 +253,7 @@ void sqlite3Pragma(
|
||||
** and a positive value means synchronous is on.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
|
||||
static VdbeOpList getCacheSize[] = {
|
||||
static const VdbeOpList getCacheSize[] = {
|
||||
{ OP_ReadCookie, 0, 2, 0}, /* 0 */
|
||||
{ OP_AbsValue, 0, 0, 0},
|
||||
{ OP_Dup, 0, 0, 0},
|
||||
@@ -262,7 +280,6 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeAddOp(v, OP_Ge, 0, addr+3);
|
||||
sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 2);
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
pDb->cache_size = size;
|
||||
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->cache_size);
|
||||
}
|
||||
@@ -283,10 +300,31 @@ void sqlite3Pragma(
|
||||
int size = pBt ? sqlite3BtreeGetPageSize(pBt) : 0;
|
||||
returnSingleInt(pParse, "page_size", size);
|
||||
}else{
|
||||
sqlite3BtreeSetPageSize(pBt, atoi(zRight), 0);
|
||||
sqlite3BtreeSetPageSize(pBt, atoi(zRight), -1);
|
||||
}
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
|
||||
|
||||
/*
|
||||
** PRAGMA [database.]auto_vacuum
|
||||
** PRAGMA [database.]auto_vacuum=N
|
||||
**
|
||||
** Get or set the (boolean) value of the database 'auto-vacuum' parameter.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
|
||||
Btree *pBt = pDb->pBt;
|
||||
if( !zRight ){
|
||||
int auto_vacuum =
|
||||
pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM;
|
||||
returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
|
||||
}else{
|
||||
sqlite3BtreeSetAutoVacuum(pBt, getBoolean(zRight));
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
|
||||
/*
|
||||
** PRAGMA [database.]cache_size
|
||||
** PRAGMA [database.]cache_size=N
|
||||
@@ -332,6 +370,45 @@ void sqlite3Pragma(
|
||||
}
|
||||
}else
|
||||
|
||||
/*
|
||||
** PRAGMA temp_store_directory
|
||||
** PRAGMA temp_store_directory = ""|"directory_name"
|
||||
**
|
||||
** Return or set the local value of the temp_store_directory flag. Changing
|
||||
** the value sets a specific directory to be used for temporary files.
|
||||
** Setting to a null string reverts to the default temporary directory search.
|
||||
** If temporary directory is changed, then invalidateTempStorage.
|
||||
**
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
|
||||
if( !zRight ){
|
||||
if( sqlite3_temp_directory ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "temp_store_directory", P3_STATIC);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
}else{
|
||||
if( zRight[0] && !sqlite3OsIsDirWritable(zRight) ){
|
||||
sqlite3ErrorMsg(pParse, "not a writable directory");
|
||||
goto pragma_out;
|
||||
}
|
||||
if( TEMP_STORE==0
|
||||
|| (TEMP_STORE==1 && db->temp_store<=1)
|
||||
|| (TEMP_STORE==2 && db->temp_store==1)
|
||||
){
|
||||
invalidateTempStorage(pParse);
|
||||
}
|
||||
sqliteFree(sqlite3_temp_directory);
|
||||
if( zRight[0] ){
|
||||
sqlite3_temp_directory = zRight;
|
||||
zRight = 0;
|
||||
}else{
|
||||
sqlite3_temp_directory = 0;
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
/*
|
||||
** PRAGMA [database.]synchronous
|
||||
** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
|
||||
@@ -355,22 +432,16 @@ void sqlite3Pragma(
|
||||
}
|
||||
}
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
|
||||
|
||||
#if 0 /* Used once during development. No longer needed */
|
||||
if( sqlite3StrICmp(zLeft, "trigger_overhead_test")==0 ){
|
||||
if( getBoolean(zRight) ){
|
||||
sqlite3_always_code_trigger_setup = 1;
|
||||
}else{
|
||||
sqlite3_always_code_trigger_setup = 0;
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
|
||||
if( flagPragma(pParse, zLeft, zRight) ){
|
||||
/* The flagPragma() subroutine also generates any necessary code
|
||||
** there is nothing more to do here */
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
|
||||
|
||||
#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
|
||||
/*
|
||||
** PRAGMA table_info(<table>)
|
||||
**
|
||||
@@ -386,7 +457,7 @@ void sqlite3Pragma(
|
||||
if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
|
||||
Table *pTab;
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
pTab = sqlite3FindTable(db, zRight, 0);
|
||||
pTab = sqlite3FindTable(db, zRight, zDb);
|
||||
if( pTab ){
|
||||
int i;
|
||||
sqlite3VdbeSetNumCols(v, 6);
|
||||
@@ -403,8 +474,7 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
|
||||
}
|
||||
@@ -415,7 +485,7 @@ void sqlite3Pragma(
|
||||
Index *pIdx;
|
||||
Table *pTab;
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
pIdx = sqlite3FindIndex(db, zRight, 0);
|
||||
pIdx = sqlite3FindIndex(db, zRight, zDb);
|
||||
if( pIdx ){
|
||||
int i;
|
||||
pTab = pIdx->pTable;
|
||||
@@ -438,7 +508,7 @@ void sqlite3Pragma(
|
||||
Index *pIdx;
|
||||
Table *pTab;
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
pTab = sqlite3FindTable(db, zRight, 0);
|
||||
pTab = sqlite3FindTable(db, zRight, zDb);
|
||||
if( pTab ){
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
pIdx = pTab->pIndex;
|
||||
@@ -460,40 +530,6 @@ void sqlite3Pragma(
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
|
||||
FKey *pFK;
|
||||
Table *pTab;
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
pTab = sqlite3FindTable(db, zRight, 0);
|
||||
if( pTab ){
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
pFK = pTab->pFKey;
|
||||
if( pFK ){
|
||||
int i = 0;
|
||||
sqlite3VdbeSetNumCols(v, 5);
|
||||
sqlite3VdbeSetColName(v, 0, "id", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "table", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, "from", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, "to", P3_STATIC);
|
||||
while(pFK){
|
||||
int j;
|
||||
for(j=0; j<pFK->nCol; j++){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, j, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->aCol[j].zCol, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 5, 0);
|
||||
}
|
||||
++i;
|
||||
pFK = pFK->pNextFrom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqlite3StrICmp(zLeft, "database_list")==0 ){
|
||||
int i;
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
@@ -512,33 +548,89 @@ void sqlite3Pragma(
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
|
||||
int i = 0;
|
||||
HashElem *p;
|
||||
sqlite3VdbeSetNumCols(v, 2);
|
||||
sqlite3VdbeSetColName(v, 0, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
|
||||
for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
|
||||
CollSeq *pColl = (CollSeq *)sqliteHashData(p);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i++, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pColl->zName, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
|
||||
}
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
|
||||
|
||||
#ifndef SQLITE_OMIT_FOREIGN_KEY
|
||||
if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
|
||||
FKey *pFK;
|
||||
Table *pTab;
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
pTab = sqlite3FindTable(db, zRight, zDb);
|
||||
if( pTab ){
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
pFK = pTab->pFKey;
|
||||
if( pFK ){
|
||||
int i = 0;
|
||||
sqlite3VdbeSetNumCols(v, 5);
|
||||
sqlite3VdbeSetColName(v, 0, "id", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, "seq", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, "table", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, "from", P3_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, "to", P3_STATIC);
|
||||
while(pFK){
|
||||
int j;
|
||||
for(j=0; j<pFK->nCol; j++){
|
||||
char *zCol = pFK->aCol[j].zCol;
|
||||
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, j, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
|
||||
sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 5, 0);
|
||||
}
|
||||
++i;
|
||||
pFK = pFK->pNextFrom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else
|
||||
#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
|
||||
|
||||
#ifndef NDEBUG
|
||||
if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
|
||||
extern void sqlite3ParserTrace(FILE*, char *);
|
||||
if( getBoolean(zRight) ){
|
||||
sqlite3ParserTrace(stdout, "parser: ");
|
||||
}else{
|
||||
sqlite3ParserTrace(0, 0);
|
||||
if( zRight ){
|
||||
if( getBoolean(zRight) ){
|
||||
sqlite3ParserTrace(stderr, "parser: ");
|
||||
}else{
|
||||
sqlite3ParserTrace(0, 0);
|
||||
}
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
|
||||
/* Reinstall the LIKE and GLOB functions. The variant of LIKE
|
||||
** used will be case sensitive or not depending on the RHS.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
|
||||
if( zRight ){
|
||||
sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
|
||||
}
|
||||
}else
|
||||
|
||||
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
|
||||
if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){
|
||||
int i, j, addr;
|
||||
|
||||
/* Code that initializes the integrity check program. Set the
|
||||
** error count 0
|
||||
*/
|
||||
static VdbeOpList initCode[] = {
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_MemStore, 0, 1, 0},
|
||||
};
|
||||
|
||||
/* Code that appears at the end of the integrity check. If no error
|
||||
** messages have been generated, output OK. Otherwise output the
|
||||
** error message
|
||||
*/
|
||||
static VdbeOpList endCode[] = {
|
||||
static const VdbeOpList endCode[] = {
|
||||
{ OP_MemLoad, 0, 0, 0},
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_Ne, 0, 0, 0}, /* 2 */
|
||||
@@ -550,13 +642,15 @@ void sqlite3Pragma(
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "integrity_check", P3_STATIC);
|
||||
sqlite3VdbeAddOpList(v, ArraySize(initCode), initCode);
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, 0); /* Initialize error count to 0 */
|
||||
|
||||
/* Do an integrity check on each database file */
|
||||
for(i=0; i<db->nDb; i++){
|
||||
HashElem *x;
|
||||
int cnt = 0;
|
||||
|
||||
if( OMIT_TEMPDB && i==1 ) continue;
|
||||
|
||||
sqlite3CodeVerifySchema(pParse, i);
|
||||
|
||||
/* Do an integrity check of the B-Tree
|
||||
@@ -594,16 +688,15 @@ void sqlite3Pragma(
|
||||
|
||||
if( pTab->pIndex==0 ) continue;
|
||||
sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemStore, 1, 1);
|
||||
sqlite3VdbeAddOp(v, OP_MemInt, 0, 1);
|
||||
loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0);
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
int jmp2;
|
||||
static VdbeOpList idxErr[] = {
|
||||
static const VdbeOpList idxErr[] = {
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_String8, 0, 0, "rowid "},
|
||||
{ OP_Recno, 1, 0, 0},
|
||||
{ OP_Rowid, 1, 0, 0},
|
||||
{ OP_String8, 0, 0, " missing from index "},
|
||||
{ OP_String8, 0, 0, 0}, /* 4 */
|
||||
{ OP_Concat, 2, 0, 0},
|
||||
@@ -613,40 +706,42 @@ void sqlite3Pragma(
|
||||
jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
|
||||
sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
|
||||
sqlite3VdbeChangeP2(v, jmp2, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeJumpHere(v, jmp2);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1);
|
||||
sqlite3VdbeChangeP2(v, loopTop, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeJumpHere(v, loopTop);
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
static VdbeOpList cntIdx[] = {
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_MemStore, 2, 1, 0},
|
||||
{ OP_Rewind, 0, 0, 0}, /* 2 */
|
||||
static const VdbeOpList cntIdx[] = {
|
||||
{ OP_MemInt, 0, 2, 0},
|
||||
{ OP_Rewind, 0, 0, 0}, /* 1 */
|
||||
{ OP_MemIncr, 2, 0, 0},
|
||||
{ OP_Next, 0, 0, 0}, /* 4 */
|
||||
{ OP_Next, 0, 0, 0}, /* 3 */
|
||||
{ OP_MemLoad, 1, 0, 0},
|
||||
{ OP_MemLoad, 2, 0, 0},
|
||||
{ OP_Eq, 0, 0, 0}, /* 7 */
|
||||
{ OP_Eq, 0, 0, 0}, /* 6 */
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_String8, 0, 0, "wrong # of entries in index "},
|
||||
{ OP_String8, 0, 0, 0}, /* 10 */
|
||||
{ OP_String8, 0, 0, 0}, /* 9 */
|
||||
{ OP_Concat, 0, 0, 0},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
if( pIdx->tnum==0 ) continue;
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
|
||||
sqlite3VdbeChangeP1(v, addr+2, j+2);
|
||||
sqlite3VdbeChangeP2(v, addr+2, addr+5);
|
||||
sqlite3VdbeChangeP1(v, addr+4, j+2);
|
||||
sqlite3VdbeChangeP2(v, addr+4, addr+3);
|
||||
sqlite3VdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
|
||||
sqlite3VdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
|
||||
sqlite3VdbeChangeP1(v, addr+1, j+2);
|
||||
sqlite3VdbeChangeP2(v, addr+1, addr+4);
|
||||
sqlite3VdbeChangeP1(v, addr+3, j+2);
|
||||
sqlite3VdbeChangeP2(v, addr+3, addr+2);
|
||||
sqlite3VdbeJumpHere(v, addr+6);
|
||||
sqlite3VdbeChangeP3(v, addr+9, pIdx->zName, P3_STATIC);
|
||||
}
|
||||
}
|
||||
}
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
|
||||
sqlite3VdbeChangeP2(v, addr+2, addr+ArraySize(endCode));
|
||||
sqlite3VdbeJumpHere(v, addr+2);
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** PRAGMA encoding
|
||||
** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
|
||||
@@ -670,7 +765,7 @@ void sqlite3Pragma(
|
||||
** useful if invoked immediately after the main database i
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "encoding")==0 ){
|
||||
struct EncName {
|
||||
static struct EncName {
|
||||
char *zName;
|
||||
u8 enc;
|
||||
} encnames[] = {
|
||||
@@ -717,13 +812,76 @@ void sqlite3Pragma(
|
||||
}
|
||||
}
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
#ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
|
||||
/*
|
||||
** PRAGMA [database.]schema_version
|
||||
** PRAGMA [database.]schema_version = <integer>
|
||||
**
|
||||
** PRAGMA [database.]user_version
|
||||
** PRAGMA [database.]user_version = <integer>
|
||||
**
|
||||
** The pragma's schema_version and user_version are used to set or get
|
||||
** the value of the schema-version and user-version, respectively. Both
|
||||
** the schema-version and the user-version are 32-bit signed integers
|
||||
** stored in the database header.
|
||||
**
|
||||
** The schema-cookie is usually only manipulated internally by SQLite. It
|
||||
** is incremented by SQLite whenever the database schema is modified (by
|
||||
** creating or dropping a table or index). The schema version is used by
|
||||
** SQLite each time a query is executed to ensure that the internal cache
|
||||
** of the schema used when compiling the SQL query matches the schema of
|
||||
** the database against which the compiled query is actually executed.
|
||||
** Subverting this mechanism by using "PRAGMA schema_version" to modify
|
||||
** the schema-version is potentially dangerous and may lead to program
|
||||
** crashes or database corruption. Use with caution!
|
||||
**
|
||||
** The user-version is not used internally by SQLite. It may be used by
|
||||
** applications for any purpose.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "schema_version")==0 ||
|
||||
sqlite3StrICmp(zLeft, "user_version")==0 ){
|
||||
|
||||
int iCookie; /* Cookie index. 0 for schema-cookie, 6 for user-cookie. */
|
||||
if( zLeft[0]=='s' || zLeft[0]=='S' ){
|
||||
iCookie = 0;
|
||||
}else{
|
||||
iCookie = 5;
|
||||
}
|
||||
|
||||
if( zRight ){
|
||||
/* Write the specified cookie value */
|
||||
static const VdbeOpList setCookie[] = {
|
||||
{ OP_Transaction, 0, 1, 0}, /* 0 */
|
||||
{ OP_Integer, 0, 0, 0}, /* 1 */
|
||||
{ OP_SetCookie, 0, 0, 0}, /* 2 */
|
||||
};
|
||||
int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
|
||||
sqlite3VdbeChangeP1(v, addr, iDb);
|
||||
sqlite3VdbeChangeP1(v, addr+1, atoi(zRight));
|
||||
sqlite3VdbeChangeP1(v, addr+2, iDb);
|
||||
sqlite3VdbeChangeP2(v, addr+2, iCookie);
|
||||
}else{
|
||||
/* Read the specified cookie value */
|
||||
static const VdbeOpList readCookie[] = {
|
||||
{ OP_ReadCookie, 0, 0, 0}, /* 0 */
|
||||
{ OP_Callback, 1, 0, 0}
|
||||
};
|
||||
int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
|
||||
sqlite3VdbeChangeP1(v, addr, iDb);
|
||||
sqlite3VdbeChangeP2(v, addr, iCookie);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
|
||||
|
||||
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
|
||||
/*
|
||||
** Report the current state of file logs for all databases
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
|
||||
static char *azLockName[] = {
|
||||
static const char *const azLockName[] = {
|
||||
"unlocked", "shared", "reserved", "pending", "exclusive"
|
||||
};
|
||||
int i;
|
||||
@@ -735,13 +893,13 @@ void sqlite3Pragma(
|
||||
Btree *pBt;
|
||||
Pager *pPager;
|
||||
if( db->aDb[i].zName==0 ) continue;
|
||||
sqlite3VdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, P3_STATIC);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC);
|
||||
pBt = db->aDb[i].pBt;
|
||||
if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
|
||||
sqlite3VdbeOp3(v, OP_String, 0, 0, "closed", P3_STATIC);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC);
|
||||
}else{
|
||||
int j = sqlite3pager_lockstate(pPager);
|
||||
sqlite3VdbeOp3(v, OP_String, 0, 0,
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
(j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
|
||||
@@ -749,8 +907,29 @@ void sqlite3Pragma(
|
||||
}else
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_SSE
|
||||
/*
|
||||
** Check to see if the sqlite_statements table exists. Create it
|
||||
** if it does not.
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){
|
||||
extern int sqlite3CreateStatementsTable(Parse*);
|
||||
sqlite3CreateStatementsTable(pParse);
|
||||
}else
|
||||
#endif
|
||||
|
||||
{}
|
||||
|
||||
if( v ){
|
||||
/* Code an OP_Expire at the end of each PRAGMA program to cause
|
||||
** the VDBE implementing the pragma to expire. Most (all?) pragmas
|
||||
** are only valid for a single execution.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
|
||||
}
|
||||
pragma_out:
|
||||
sqliteFree(zLeft);
|
||||
sqliteFree(zRight);
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */
|
||||
|
||||
+540
@@ -0,0 +1,540 @@
|
||||
/*
|
||||
** 2005 May 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.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains the implementation of the sqlite3_prepare()
|
||||
** interface, and routines that contribute to loading the database schema
|
||||
** from disk.
|
||||
**
|
||||
** $Id: prepare.c,v 1.4 2005/09/10 16:46:13 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
** Fill the InitData structure with an error message that indicates
|
||||
** that the database is corrupt.
|
||||
*/
|
||||
static void corruptSchema(InitData *pData, const char *zExtra){
|
||||
if( !sqlite3_malloc_failed ){
|
||||
sqlite3SetString(pData->pzErrMsg, "malformed database schema",
|
||||
zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This is the callback routine for the code that initializes the
|
||||
** database. See sqlite3Init() below for additional information.
|
||||
** This routine is also called from the OP_ParseSchema opcode of the VDBE.
|
||||
**
|
||||
** Each callback contains the following information:
|
||||
**
|
||||
** argv[0] = name of thing being created
|
||||
** argv[1] = root page number for table or index. NULL for trigger or view.
|
||||
** argv[2] = SQL text for the CREATE statement.
|
||||
** argv[3] = "1" for temporary files, "0" for main database, "2" or more
|
||||
** for auxiliary database files.
|
||||
**
|
||||
*/
|
||||
int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
|
||||
InitData *pData = (InitData*)pInit;
|
||||
sqlite3 *db = pData->db;
|
||||
int iDb;
|
||||
|
||||
assert( argc==4 );
|
||||
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
|
||||
if( argv[1]==0 || argv[3]==0 ){
|
||||
corruptSchema(pData, 0);
|
||||
return 1;
|
||||
}
|
||||
iDb = atoi(argv[3]);
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
if( argv[2] && argv[2][0] ){
|
||||
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
|
||||
** But because db->init.busy is set to 1, no VDBE code is generated
|
||||
** or executed. All the parser does is build the internal data
|
||||
** structures that describe the table, index, or view.
|
||||
*/
|
||||
char *zErr;
|
||||
int rc;
|
||||
assert( db->init.busy );
|
||||
db->init.iDb = iDb;
|
||||
db->init.newTnum = atoi(argv[1]);
|
||||
rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
|
||||
db->init.iDb = 0;
|
||||
if( SQLITE_OK!=rc ){
|
||||
corruptSchema(pData, zErr);
|
||||
sqlite3_free(zErr);
|
||||
return rc;
|
||||
}
|
||||
}else{
|
||||
/* If the SQL column is blank it means this is an index that
|
||||
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
|
||||
** constraint for a CREATE TABLE. The index should have already
|
||||
** been created when we processed the CREATE TABLE. All we have
|
||||
** to do here is record the root page number for that index.
|
||||
*/
|
||||
Index *pIndex;
|
||||
pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
|
||||
if( pIndex==0 || pIndex->tnum!=0 ){
|
||||
/* This can occur if there exists an index on a TEMP table which
|
||||
** has the same name as another index on a permanent index. Since
|
||||
** the permanent table is hidden by the TEMP table, we can also
|
||||
** safely ignore the index on the permanent table.
|
||||
*/
|
||||
/* Do Nothing */;
|
||||
}else{
|
||||
pIndex->tnum = atoi(argv[1]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to read the database schema and initialize internal
|
||||
** data structures for a single database file. The index of the
|
||||
** database file is given by iDb. iDb==0 is used for the main
|
||||
** database. iDb==1 should never be used. iDb>=2 is used for
|
||||
** auxiliary databases. Return one of the SQLITE_ error codes to
|
||||
** indicate success or failure.
|
||||
*/
|
||||
static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
int rc;
|
||||
BtCursor *curMain;
|
||||
int size;
|
||||
Table *pTab;
|
||||
char const *azArg[5];
|
||||
char zDbNum[30];
|
||||
int meta[10];
|
||||
InitData initData;
|
||||
char const *zMasterSchema;
|
||||
char const *zMasterName = SCHEMA_TABLE(iDb);
|
||||
|
||||
/*
|
||||
** The master database table has a structure like this
|
||||
*/
|
||||
static const char master_schema[] =
|
||||
"CREATE TABLE sqlite_master(\n"
|
||||
" type text,\n"
|
||||
" name text,\n"
|
||||
" tbl_name text,\n"
|
||||
" rootpage integer,\n"
|
||||
" sql text\n"
|
||||
")"
|
||||
;
|
||||
#ifndef SQLITE_OMIT_TEMPDB
|
||||
static const char temp_master_schema[] =
|
||||
"CREATE TEMP TABLE sqlite_temp_master(\n"
|
||||
" type text,\n"
|
||||
" name text,\n"
|
||||
" tbl_name text,\n"
|
||||
" rootpage integer,\n"
|
||||
" sql text\n"
|
||||
")"
|
||||
;
|
||||
#else
|
||||
#define temp_master_schema 0
|
||||
#endif
|
||||
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
|
||||
/* zMasterSchema and zInitScript are set to point at the master schema
|
||||
** and initialisation script appropriate for the database being
|
||||
** initialised. zMasterName is the name of the master table.
|
||||
*/
|
||||
if( !OMIT_TEMPDB && iDb==1 ){
|
||||
zMasterSchema = temp_master_schema;
|
||||
}else{
|
||||
zMasterSchema = master_schema;
|
||||
}
|
||||
zMasterName = SCHEMA_TABLE(iDb);
|
||||
|
||||
/* Construct the schema tables. */
|
||||
sqlite3SafetyOff(db);
|
||||
azArg[0] = zMasterName;
|
||||
azArg[1] = "1";
|
||||
azArg[2] = zMasterSchema;
|
||||
sprintf(zDbNum, "%d", iDb);
|
||||
azArg[3] = zDbNum;
|
||||
azArg[4] = 0;
|
||||
initData.db = db;
|
||||
initData.pzErrMsg = pzErrMsg;
|
||||
rc = sqlite3InitCallback(&initData, 4, (char **)azArg, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3SafetyOn(db);
|
||||
return rc;
|
||||
}
|
||||
pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
|
||||
if( pTab ){
|
||||
pTab->readOnly = 1;
|
||||
}
|
||||
sqlite3SafetyOn(db);
|
||||
|
||||
/* Create a cursor to hold the database open
|
||||
*/
|
||||
if( db->aDb[iDb].pBt==0 ){
|
||||
if( !OMIT_TEMPDB && iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain);
|
||||
if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){
|
||||
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Get the database meta information.
|
||||
**
|
||||
** Meta values are as follows:
|
||||
** meta[0] Schema cookie. Changes with each schema change.
|
||||
** meta[1] File format of schema layer.
|
||||
** meta[2] Size of the page cache.
|
||||
** meta[3] Use freelist if 0. Autovacuum if greater than zero.
|
||||
** meta[4] Db text encoding. 1:UTF-8 3:UTF-16 LE 4:UTF-16 BE
|
||||
** meta[5] The user cookie. Used by the application.
|
||||
** meta[6]
|
||||
** meta[7]
|
||||
** meta[8]
|
||||
** meta[9]
|
||||
**
|
||||
** Note: The hash defined SQLITE_UTF* symbols in sqliteInt.h correspond to
|
||||
** the possible values of meta[4].
|
||||
*/
|
||||
if( rc==SQLITE_OK ){
|
||||
int i;
|
||||
for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){
|
||||
rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, i+1, (u32 *)&meta[i]);
|
||||
}
|
||||
if( rc ){
|
||||
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
return rc;
|
||||
}
|
||||
}else{
|
||||
memset(meta, 0, sizeof(meta));
|
||||
}
|
||||
db->aDb[iDb].schema_cookie = meta[0];
|
||||
|
||||
/* If opening a non-empty database, check the text encoding. For the
|
||||
** main database, set sqlite3.enc to the encoding of the main database.
|
||||
** For an attached db, it is an error if the encoding is not the same
|
||||
** as sqlite3.enc.
|
||||
*/
|
||||
if( meta[4] ){ /* text encoding */
|
||||
if( iDb==0 ){
|
||||
/* If opening the main database, set db->enc. */
|
||||
db->enc = (u8)meta[4];
|
||||
db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0);
|
||||
}else{
|
||||
/* If opening an attached database, the encoding much match db->enc */
|
||||
if( meta[4]!=db->enc ){
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
sqlite3SetString(pzErrMsg, "attached databases must use the same"
|
||||
" text encoding as main database", (char*)0);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size = meta[2];
|
||||
if( size==0 ){ size = MAX_PAGES; }
|
||||
db->aDb[iDb].cache_size = size;
|
||||
|
||||
if( iDb==0 ){
|
||||
db->file_format = meta[1];
|
||||
if( db->file_format==0 ){
|
||||
/* This happens if the database was initially empty */
|
||||
db->file_format = 1;
|
||||
}
|
||||
|
||||
if( db->file_format==2 || db->file_format==3 ){
|
||||
/* File format 2 is treated exactly as file format 1. New
|
||||
** databases are created with file format 1.
|
||||
*/
|
||||
db->file_format = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** file_format==1 Version 3.0.0.
|
||||
** file_format==2 Version 3.1.3.
|
||||
** file_format==3 Version 3.1.4.
|
||||
**
|
||||
** Version 3.0 can only use files with file_format==1. Version 3.1.3
|
||||
** can read and write files with file_format==1 or file_format==2.
|
||||
** Version 3.1.4 can read and write file formats 1, 2 and 3.
|
||||
*/
|
||||
if( meta[1]>3 ){
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
sqlite3BtreeSetCacheSize(db->aDb[iDb].pBt, db->aDb[iDb].cache_size);
|
||||
|
||||
/* Read the schema information out of the schema tables
|
||||
*/
|
||||
assert( db->init.busy );
|
||||
if( rc==SQLITE_EMPTY ){
|
||||
/* For an empty database, there is nothing to read */
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
char *zSql;
|
||||
zSql = sqlite3MPrintf(
|
||||
"SELECT name, rootpage, sql, '%s' FROM '%q'.%s",
|
||||
zDbNum, db->aDb[iDb].zName, zMasterName);
|
||||
sqlite3SafetyOff(db);
|
||||
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
|
||||
sqlite3SafetyOn(db);
|
||||
sqliteFree(zSql);
|
||||
#ifndef SQLITE_OMIT_ANALYZE
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3AnalysisLoad(db, iDb);
|
||||
}
|
||||
#endif
|
||||
sqlite3BtreeCloseCursor(curMain);
|
||||
}
|
||||
if( sqlite3_malloc_failed ){
|
||||
sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
|
||||
rc = SQLITE_NOMEM;
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
DbSetProperty(db, iDb, DB_SchemaLoaded);
|
||||
}else{
|
||||
sqlite3ResetInternalSchema(db, iDb);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Initialize all database files - the main database file, the file
|
||||
** used to store temporary tables, and any additional database files
|
||||
** created using ATTACH statements. Return a success code. If an
|
||||
** error occurs, write an error message into *pzErrMsg.
|
||||
**
|
||||
** After the database is initialized, the SQLITE_Initialized
|
||||
** bit is set in the flags field of the sqlite structure.
|
||||
*/
|
||||
int sqlite3Init(sqlite3 *db, char **pzErrMsg){
|
||||
int i, rc;
|
||||
|
||||
if( db->init.busy ) return SQLITE_OK;
|
||||
assert( (db->flags & SQLITE_Initialized)==0 );
|
||||
rc = SQLITE_OK;
|
||||
db->init.busy = 1;
|
||||
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
|
||||
if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
|
||||
rc = sqlite3InitOne(db, i, pzErrMsg);
|
||||
if( rc ){
|
||||
sqlite3ResetInternalSchema(db, i);
|
||||
}
|
||||
}
|
||||
|
||||
/* Once all the other databases have been initialised, load the schema
|
||||
** for the TEMP database. This is loaded last, as the TEMP database
|
||||
** schema may contain references to objects in other databases.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_TEMPDB
|
||||
if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
|
||||
rc = sqlite3InitOne(db, 1, pzErrMsg);
|
||||
if( rc ){
|
||||
sqlite3ResetInternalSchema(db, 1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
db->init.busy = 0;
|
||||
if( rc==SQLITE_OK ){
|
||||
db->flags |= SQLITE_Initialized;
|
||||
sqlite3CommitInternalChanges(db);
|
||||
}
|
||||
|
||||
if( rc!=SQLITE_OK ){
|
||||
db->flags &= ~SQLITE_Initialized;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is a no-op if the database schema is already initialised.
|
||||
** Otherwise, the schema is loaded. An error code is returned.
|
||||
*/
|
||||
int sqlite3ReadSchema(Parse *pParse){
|
||||
int rc = SQLITE_OK;
|
||||
sqlite3 *db = pParse->db;
|
||||
if( !db->init.busy ){
|
||||
if( (db->flags & SQLITE_Initialized)==0 ){
|
||||
rc = sqlite3Init(db, &pParse->zErrMsg);
|
||||
}
|
||||
}
|
||||
assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized) || db->init.busy );
|
||||
if( rc!=SQLITE_OK ){
|
||||
pParse->rc = rc;
|
||||
pParse->nErr++;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Check schema cookies in all databases. If any cookie is out
|
||||
** of date, return 0. If all schema cookies are current, return 1.
|
||||
*/
|
||||
static int schemaIsValid(sqlite3 *db){
|
||||
int iDb;
|
||||
int rc;
|
||||
BtCursor *curTemp;
|
||||
int cookie;
|
||||
int allOk = 1;
|
||||
|
||||
for(iDb=0; allOk && iDb<db->nDb; iDb++){
|
||||
Btree *pBt;
|
||||
pBt = db->aDb[iDb].pBt;
|
||||
if( pBt==0 ) continue;
|
||||
rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, 0, &curTemp);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&cookie);
|
||||
if( rc==SQLITE_OK && cookie!=db->aDb[iDb].schema_cookie ){
|
||||
allOk = 0;
|
||||
}
|
||||
sqlite3BtreeCloseCursor(curTemp);
|
||||
}
|
||||
}
|
||||
return allOk;
|
||||
}
|
||||
|
||||
/*
|
||||
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
|
||||
*/
|
||||
int sqlite3_prepare(
|
||||
sqlite3 *db, /* Database handle. */
|
||||
const char *zSql, /* UTF-8 encoded SQL statement. */
|
||||
int nBytes, /* Length of zSql in bytes. */
|
||||
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
|
||||
const char** pzTail /* OUT: End of parsed string */
|
||||
){
|
||||
Parse sParse;
|
||||
char *zErrMsg = 0;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
if( sqlite3_malloc_failed ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
assert( ppStmt );
|
||||
*ppStmt = 0;
|
||||
if( sqlite3SafetyOn(db) ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
|
||||
memset(&sParse, 0, sizeof(sParse));
|
||||
sParse.db = db;
|
||||
sqlite3RunParser(&sParse, zSql, &zErrMsg);
|
||||
|
||||
if( sqlite3_malloc_failed ){
|
||||
rc = SQLITE_NOMEM;
|
||||
sqlite3RollbackAll(db);
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
db->flags &= ~SQLITE_InTrans;
|
||||
goto prepare_out;
|
||||
}
|
||||
if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
|
||||
if( sParse.rc!=SQLITE_OK && sParse.checkSchema && !schemaIsValid(db) ){
|
||||
sParse.rc = SQLITE_SCHEMA;
|
||||
}
|
||||
if( sParse.rc==SQLITE_SCHEMA ){
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
}
|
||||
if( pzTail ) *pzTail = sParse.zTail;
|
||||
rc = sParse.rc;
|
||||
|
||||
#ifndef SQLITE_OMIT_EXPLAIN
|
||||
if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
|
||||
if( sParse.explain==2 ){
|
||||
sqlite3VdbeSetNumCols(sParse.pVdbe, 3);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 0, "order", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 1, "from", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 2, "detail", P3_STATIC);
|
||||
}else{
|
||||
sqlite3VdbeSetNumCols(sParse.pVdbe, 5);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
prepare_out:
|
||||
if( sqlite3SafetyOff(db) ){
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
*ppStmt = (sqlite3_stmt*)sParse.pVdbe;
|
||||
}else if( sParse.pVdbe ){
|
||||
sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
|
||||
}
|
||||
|
||||
if( zErrMsg ){
|
||||
sqlite3Error(db, rc, "%s", zErrMsg);
|
||||
sqliteFree(zErrMsg);
|
||||
}else{
|
||||
sqlite3Error(db, rc, 0);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
|
||||
*/
|
||||
int sqlite3_prepare16(
|
||||
sqlite3 *db, /* Database handle. */
|
||||
const void *zSql, /* UTF-8 encoded SQL statement. */
|
||||
int nBytes, /* Length of zSql in bytes. */
|
||||
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
|
||||
const void **pzTail /* OUT: End of parsed string */
|
||||
){
|
||||
/* This function currently works by first transforming the UTF-16
|
||||
** encoded string to UTF-8, then invoking sqlite3_prepare(). The
|
||||
** tricky bit is figuring out the pointer to return in *pzTail.
|
||||
*/
|
||||
char const *zSql8 = 0;
|
||||
char const *zTail8 = 0;
|
||||
int rc;
|
||||
sqlite3_value *pTmp;
|
||||
|
||||
if( sqlite3SafetyCheck(db) ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
pTmp = sqlite3GetTransientValue(db);
|
||||
sqlite3ValueSetStr(pTmp, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zSql8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
|
||||
if( !zSql8 ){
|
||||
sqlite3Error(db, SQLITE_NOMEM, 0);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
rc = sqlite3_prepare(db, zSql8, -1, ppStmt, &zTail8);
|
||||
|
||||
if( zTail8 && pzTail ){
|
||||
/* If sqlite3_prepare returns a tail pointer, we calculate the
|
||||
** equivalent pointer into the UTF-16 string by counting the unicode
|
||||
** characters between zSql8 and zTail8, and then returning a pointer
|
||||
** the same number of characters into the UTF-16 string.
|
||||
*/
|
||||
int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
|
||||
*pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
+174
-121
@@ -73,6 +73,7 @@
|
||||
NULL pointers replaced by SQL NULL. %Q */
|
||||
#define etTOKEN 14 /* a pointer to a Token structure */
|
||||
#define etSRCLIST 15 /* a pointer to a SrcList */
|
||||
#define etPOINTER 16 /* The %p conversion */
|
||||
|
||||
|
||||
/*
|
||||
@@ -89,8 +90,8 @@ typedef struct et_info { /* Information about each format field */
|
||||
etByte base; /* The base for radix conversion */
|
||||
etByte flags; /* One or more of FLAG_ constants below */
|
||||
etByte type; /* Conversion paradigm */
|
||||
char *charset; /* The character set for conversion */
|
||||
char *prefix; /* Prefix on non-zero values in alt format */
|
||||
etByte charset; /* Offset into aDigits[] of the digits string */
|
||||
etByte prefix; /* Offset into aPrefix[] of the prefix string */
|
||||
} et_info;
|
||||
|
||||
/*
|
||||
@@ -98,34 +99,37 @@ typedef struct et_info { /* Information about each format field */
|
||||
*/
|
||||
#define FLAG_SIGNED 1 /* True if the value to convert is signed */
|
||||
#define FLAG_INTERN 2 /* True if for internal use only */
|
||||
#define FLAG_STRING 4 /* Allow infinity precision */
|
||||
|
||||
|
||||
/*
|
||||
** The following table is searched linearly, so it is good to put the
|
||||
** most frequently used conversion types first.
|
||||
*/
|
||||
static et_info fmtinfo[] = {
|
||||
{ 'd', 10, 1, etRADIX, "0123456789", 0 },
|
||||
{ 's', 0, 0, etSTRING, 0, 0 },
|
||||
{ 'z', 0, 2, etDYNSTRING, 0, 0 },
|
||||
{ 'q', 0, 0, etSQLESCAPE, 0, 0 },
|
||||
{ 'Q', 0, 0, etSQLESCAPE2, 0, 0 },
|
||||
{ 'c', 0, 0, etCHARX, 0, 0 },
|
||||
{ 'o', 8, 0, etRADIX, "01234567", "0" },
|
||||
{ 'u', 10, 0, etRADIX, "0123456789", 0 },
|
||||
{ 'x', 16, 0, etRADIX, "0123456789abcdef", "x0" },
|
||||
{ 'X', 16, 0, etRADIX, "0123456789ABCDEF", "X0" },
|
||||
{ 'f', 0, 1, etFLOAT, 0, 0 },
|
||||
{ 'e', 0, 1, etEXP, "e", 0 },
|
||||
{ 'E', 0, 1, etEXP, "E", 0 },
|
||||
{ 'g', 0, 1, etGENERIC, "e", 0 },
|
||||
{ 'G', 0, 1, etGENERIC, "E", 0 },
|
||||
{ 'i', 10, 1, etRADIX, "0123456789", 0 },
|
||||
{ 'n', 0, 0, etSIZE, 0, 0 },
|
||||
{ '%', 0, 0, etPERCENT, 0, 0 },
|
||||
{ 'p', 10, 0, etRADIX, "0123456789", 0 },
|
||||
{ 'T', 0, 2, etTOKEN, 0, 0 },
|
||||
{ 'S', 0, 2, etSRCLIST, 0, 0 },
|
||||
static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
|
||||
static const char aPrefix[] = "-x0\000X0";
|
||||
static const et_info fmtinfo[] = {
|
||||
{ 'd', 10, 1, etRADIX, 0, 0 },
|
||||
{ 's', 0, 4, etSTRING, 0, 0 },
|
||||
{ 'g', 0, 1, etGENERIC, 30, 0 },
|
||||
{ 'z', 0, 6, etDYNSTRING, 0, 0 },
|
||||
{ 'q', 0, 4, etSQLESCAPE, 0, 0 },
|
||||
{ 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
|
||||
{ 'c', 0, 0, etCHARX, 0, 0 },
|
||||
{ 'o', 8, 0, etRADIX, 0, 2 },
|
||||
{ 'u', 10, 0, etRADIX, 0, 0 },
|
||||
{ 'x', 16, 0, etRADIX, 16, 1 },
|
||||
{ 'X', 16, 0, etRADIX, 0, 4 },
|
||||
{ 'f', 0, 1, etFLOAT, 0, 0 },
|
||||
{ 'e', 0, 1, etEXP, 30, 0 },
|
||||
{ 'E', 0, 1, etEXP, 14, 0 },
|
||||
{ 'G', 0, 1, etGENERIC, 14, 0 },
|
||||
{ 'i', 10, 1, etRADIX, 0, 0 },
|
||||
{ 'n', 0, 0, etSIZE, 0, 0 },
|
||||
{ '%', 0, 0, etPERCENT, 0, 0 },
|
||||
{ 'p', 16, 0, etPOINTER, 0, 1 },
|
||||
{ 'T', 0, 2, etTOKEN, 0, 0 },
|
||||
{ 'S', 0, 2, etSRCLIST, 0, 0 },
|
||||
};
|
||||
#define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
|
||||
|
||||
@@ -159,7 +163,15 @@ static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
|
||||
}
|
||||
#endif
|
||||
|
||||
#define etBUFSIZE 1000 /* Size of the output buffer */
|
||||
/*
|
||||
** On machines with a small stack size, you can redefine the
|
||||
** SQLITE_PRINT_BUF_SIZE to be less than 350. But beware - for
|
||||
** smaller values some %f conversions may go into an infinite loop.
|
||||
*/
|
||||
#ifndef SQLITE_PRINT_BUF_SIZE
|
||||
# define SQLITE_PRINT_BUF_SIZE 350
|
||||
#endif
|
||||
#define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
|
||||
|
||||
/*
|
||||
** The root program. All variations call this core.
|
||||
@@ -206,21 +218,24 @@ static int vxprintf(
|
||||
etByte flag_plussign; /* True if "+" flag is present */
|
||||
etByte flag_blanksign; /* True if " " flag is present */
|
||||
etByte flag_alternateform; /* True if "#" flag is present */
|
||||
etByte flag_altform2; /* True if "!" flag is present */
|
||||
etByte flag_zeropad; /* True if field width constant starts with zero */
|
||||
etByte flag_long; /* True if "l" flag is present */
|
||||
etByte flag_longlong; /* True if the "ll" flag is present */
|
||||
etByte done; /* Loop termination flag */
|
||||
UINT64_TYPE longvalue; /* Value for integer types */
|
||||
LONGDOUBLE_TYPE realvalue; /* Value for real types */
|
||||
et_info *infop; /* Pointer to the appropriate info structure */
|
||||
const et_info *infop; /* Pointer to the appropriate info structure */
|
||||
char buf[etBUFSIZE]; /* Conversion buffer */
|
||||
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
|
||||
etByte errorflag = 0; /* True if an error is encountered */
|
||||
etByte xtype; /* Conversion paradigm */
|
||||
char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
|
||||
static char spaces[] = " ";
|
||||
static const char spaces[] =
|
||||
" ";
|
||||
#define etSPACESIZE (sizeof(spaces)-1)
|
||||
#ifndef etNOFLOATINGPOINT
|
||||
int exp; /* exponent of real numbers */
|
||||
int exp, e2; /* exponent of real numbers */
|
||||
double rounder; /* Used for rounding floating point values */
|
||||
etByte flag_dp; /* True if decimal point should be shown */
|
||||
etByte flag_rtz; /* True if trailing zeros should be removed */
|
||||
@@ -249,17 +264,19 @@ static int vxprintf(
|
||||
}
|
||||
/* Find out what flags are present */
|
||||
flag_leftjustify = flag_plussign = flag_blanksign =
|
||||
flag_alternateform = flag_zeropad = 0;
|
||||
flag_alternateform = flag_altform2 = flag_zeropad = 0;
|
||||
done = 0;
|
||||
do{
|
||||
switch( c ){
|
||||
case '-': flag_leftjustify = 1; c = 0; break;
|
||||
case '+': flag_plussign = 1; c = 0; break;
|
||||
case ' ': flag_blanksign = 1; c = 0; break;
|
||||
case '#': flag_alternateform = 1; c = 0; break;
|
||||
case '0': flag_zeropad = 1; c = 0; break;
|
||||
default: break;
|
||||
case '-': flag_leftjustify = 1; break;
|
||||
case '+': flag_plussign = 1; break;
|
||||
case ' ': flag_blanksign = 1; break;
|
||||
case '#': flag_alternateform = 1; break;
|
||||
case '!': flag_altform2 = 1; break;
|
||||
case '0': flag_zeropad = 1; break;
|
||||
default: done = 1; break;
|
||||
}
|
||||
}while( c==0 && (c=(*++fmt))!=0 );
|
||||
}while( !done && (c=(*++fmt))!=0 );
|
||||
/* Get the field width */
|
||||
width = 0;
|
||||
if( c=='*' ){
|
||||
@@ -292,8 +309,6 @@ static int vxprintf(
|
||||
c = *++fmt;
|
||||
}
|
||||
}
|
||||
/* Limit the precision to prevent overflowing buf[] during conversion */
|
||||
if( precision>etBUFSIZE-40 ) precision = etBUFSIZE-40;
|
||||
}else{
|
||||
precision = -1;
|
||||
}
|
||||
@@ -324,10 +339,16 @@ static int vxprintf(
|
||||
}
|
||||
zExtra = 0;
|
||||
|
||||
/* Limit the precision to prevent overflowing buf[] during conversion */
|
||||
if( precision>etBUFSIZE-40 && (infop->flags & FLAG_STRING)==0 ){
|
||||
precision = etBUFSIZE-40;
|
||||
}
|
||||
|
||||
/*
|
||||
** At this point, variables are initialized as follows:
|
||||
**
|
||||
** flag_alternateform TRUE if a '#' is present.
|
||||
** flag_altform2 TRUE if a '!' is present.
|
||||
** flag_plussign TRUE if a '+' is present.
|
||||
** flag_leftjustify TRUE if a '-' is present or if the
|
||||
** field width was negative.
|
||||
@@ -345,6 +366,10 @@ static int vxprintf(
|
||||
** infop Pointer to the appropriate info struct.
|
||||
*/
|
||||
switch( xtype ){
|
||||
case etPOINTER:
|
||||
flag_longlong = sizeof(char*)==sizeof(i64);
|
||||
flag_long = sizeof(char*)==sizeof(long int);
|
||||
/* Fall through into the next case */
|
||||
case etRADIX:
|
||||
if( infop->flags & FLAG_SIGNED ){
|
||||
i64 v;
|
||||
@@ -372,9 +397,9 @@ static int vxprintf(
|
||||
}
|
||||
bufpt = &buf[etBUFSIZE-1];
|
||||
{
|
||||
register char *cset; /* Use registers for speed */
|
||||
register const char *cset; /* Use registers for speed */
|
||||
register int base;
|
||||
cset = infop->charset;
|
||||
cset = &aDigits[infop->charset];
|
||||
base = infop->base;
|
||||
do{ /* Convert to ascii */
|
||||
*(--bufpt) = cset[longvalue%base];
|
||||
@@ -387,10 +412,11 @@ static int vxprintf(
|
||||
}
|
||||
if( prefix ) *(--bufpt) = prefix; /* Add sign */
|
||||
if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */
|
||||
char *pre, x;
|
||||
pre = infop->prefix;
|
||||
const char *pre;
|
||||
char x;
|
||||
pre = &aPrefix[infop->prefix];
|
||||
if( *bufpt!=pre[0] ){
|
||||
for(pre=infop->prefix; (x=(*pre))!=0; pre++) *(--bufpt) = x;
|
||||
for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
|
||||
}
|
||||
}
|
||||
length = &buf[etBUFSIZE-1]-bufpt;
|
||||
@@ -401,7 +427,7 @@ static int vxprintf(
|
||||
realvalue = va_arg(ap,double);
|
||||
#ifndef etNOFLOATINGPOINT
|
||||
if( precision<0 ) precision = 6; /* Set default precision */
|
||||
if( precision>etBUFSIZE-10 ) precision = etBUFSIZE-10;
|
||||
if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10;
|
||||
if( realvalue<0.0 ){
|
||||
realvalue = -realvalue;
|
||||
prefix = '-';
|
||||
@@ -410,8 +436,7 @@ static int vxprintf(
|
||||
else if( flag_blanksign ) prefix = ' ';
|
||||
else prefix = 0;
|
||||
}
|
||||
if( infop->type==etGENERIC && precision>0 ) precision--;
|
||||
rounder = 0.0;
|
||||
if( xtype==etGENERIC && precision>0 ) precision--;
|
||||
#if 0
|
||||
/* Rounding works like BSD when the constant 0.4999 is used. Wierd! */
|
||||
for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);
|
||||
@@ -419,10 +444,11 @@ static int vxprintf(
|
||||
/* It makes more sense to use 0.5 */
|
||||
for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1);
|
||||
#endif
|
||||
if( infop->type==etFLOAT ) realvalue += rounder;
|
||||
if( xtype==etFLOAT ) realvalue += rounder;
|
||||
/* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
|
||||
exp = 0;
|
||||
if( realvalue>0.0 ){
|
||||
while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
|
||||
while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
|
||||
while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
|
||||
while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
|
||||
@@ -454,51 +480,67 @@ static int vxprintf(
|
||||
}else{
|
||||
flag_rtz = 0;
|
||||
}
|
||||
/*
|
||||
** The "exp+precision" test causes output to be of type etEXP if
|
||||
** the precision is too large to fit in buf[].
|
||||
*/
|
||||
if( xtype==etEXP ){
|
||||
e2 = 0;
|
||||
}else{
|
||||
e2 = exp;
|
||||
}
|
||||
nsd = 0;
|
||||
if( xtype==etFLOAT && exp+precision<etBUFSIZE-30 ){
|
||||
flag_dp = (precision>0 || flag_alternateform);
|
||||
if( prefix ) *(bufpt++) = prefix; /* Sign */
|
||||
if( exp<0 ) *(bufpt++) = '0'; /* Digits before "." */
|
||||
else for(; exp>=0; exp--) *(bufpt++) = et_getdigit(&realvalue,&nsd);
|
||||
if( flag_dp ) *(bufpt++) = '.'; /* The decimal point */
|
||||
for(exp++; exp<0 && precision>0; precision--, exp++){
|
||||
*(bufpt++) = '0';
|
||||
}
|
||||
while( (precision--)>0 ) *(bufpt++) = et_getdigit(&realvalue,&nsd);
|
||||
*(bufpt--) = 0; /* Null terminate */
|
||||
if( flag_rtz && flag_dp ){ /* Remove trailing zeros and "." */
|
||||
while( bufpt>=buf && *bufpt=='0' ) *(bufpt--) = 0;
|
||||
if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0;
|
||||
}
|
||||
bufpt++; /* point to next free slot */
|
||||
}else{ /* etEXP or etGENERIC */
|
||||
flag_dp = (precision>0 || flag_alternateform);
|
||||
if( prefix ) *(bufpt++) = prefix; /* Sign */
|
||||
*(bufpt++) = et_getdigit(&realvalue,&nsd); /* First digit */
|
||||
if( flag_dp ) *(bufpt++) = '.'; /* Decimal point */
|
||||
while( (precision--)>0 ) *(bufpt++) = et_getdigit(&realvalue,&nsd);
|
||||
bufpt--; /* point to last digit */
|
||||
if( flag_rtz && flag_dp ){ /* Remove tail zeros */
|
||||
while( bufpt>=buf && *bufpt=='0' ) *(bufpt--) = 0;
|
||||
if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0;
|
||||
}
|
||||
bufpt++; /* point to next free slot */
|
||||
if( exp || flag_exp ){
|
||||
*(bufpt++) = infop->charset[0];
|
||||
if( exp<0 ){ *(bufpt++) = '-'; exp = -exp; } /* sign of exp */
|
||||
else { *(bufpt++) = '+'; }
|
||||
if( exp>=100 ){
|
||||
*(bufpt++) = (exp/100)+'0'; /* 100's digit */
|
||||
exp %= 100;
|
||||
}
|
||||
*(bufpt++) = exp/10+'0'; /* 10's digit */
|
||||
*(bufpt++) = exp%10+'0'; /* 1's digit */
|
||||
flag_dp = (precision>0) | flag_alternateform | flag_altform2;
|
||||
/* The sign in front of the number */
|
||||
if( prefix ){
|
||||
*(bufpt++) = prefix;
|
||||
}
|
||||
/* Digits prior to the decimal point */
|
||||
if( e2<0 ){
|
||||
*(bufpt++) = '0';
|
||||
}else{
|
||||
for(; e2>=0; e2--){
|
||||
*(bufpt++) = et_getdigit(&realvalue,&nsd);
|
||||
}
|
||||
}
|
||||
/* The decimal point */
|
||||
if( flag_dp ){
|
||||
*(bufpt++) = '.';
|
||||
}
|
||||
/* "0" digits after the decimal point but before the first
|
||||
** significant digit of the number */
|
||||
for(e2++; e2<0 && precision>0; precision--, e2++){
|
||||
*(bufpt++) = '0';
|
||||
}
|
||||
/* Significant digits after the decimal point */
|
||||
while( (precision--)>0 ){
|
||||
*(bufpt++) = et_getdigit(&realvalue,&nsd);
|
||||
}
|
||||
/* Remove trailing zeros and the "." if no digits follow the "." */
|
||||
if( flag_rtz && flag_dp ){
|
||||
while( bufpt[-1]=='0' ) *(--bufpt) = 0;
|
||||
assert( bufpt>buf );
|
||||
if( bufpt[-1]=='.' ){
|
||||
if( flag_altform2 ){
|
||||
*(bufpt++) = '0';
|
||||
}else{
|
||||
*(--bufpt) = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Add the "eNNN" suffix */
|
||||
if( flag_exp || (xtype==etEXP && exp) ){
|
||||
*(bufpt++) = aDigits[infop->charset];
|
||||
if( exp<0 ){
|
||||
*(bufpt++) = '-'; exp = -exp;
|
||||
}else{
|
||||
*(bufpt++) = '+';
|
||||
}
|
||||
if( exp>=100 ){
|
||||
*(bufpt++) = (exp/100)+'0'; /* 100's digit */
|
||||
exp %= 100;
|
||||
}
|
||||
*(bufpt++) = exp/10+'0'; /* 10's digit */
|
||||
*(bufpt++) = exp%10+'0'; /* 1's digit */
|
||||
}
|
||||
*bufpt = 0;
|
||||
|
||||
/* The converted number is in buf[] and zero terminated. Output it.
|
||||
** Note that the number is in the usual order, not reversed as with
|
||||
** integer conversions. */
|
||||
@@ -551,37 +593,40 @@ static int vxprintf(
|
||||
if( precision>=0 && precision<length ) length = precision;
|
||||
break;
|
||||
case etSQLESCAPE:
|
||||
case etSQLESCAPE2:
|
||||
{
|
||||
int i, j, n, c, isnull;
|
||||
char *arg = va_arg(ap,char*);
|
||||
isnull = arg==0;
|
||||
if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
|
||||
for(i=n=0; (c=arg[i])!=0; i++){
|
||||
if( c=='\'' ) n++;
|
||||
}
|
||||
n += i + 1 + ((!isnull && xtype==etSQLESCAPE2) ? 2 : 0);
|
||||
if( n>etBUFSIZE ){
|
||||
bufpt = zExtra = sqliteMalloc( n );
|
||||
if( bufpt==0 ) return -1;
|
||||
}else{
|
||||
bufpt = buf;
|
||||
}
|
||||
j = 0;
|
||||
if( !isnull && xtype==etSQLESCAPE2 ) bufpt[j++] = '\'';
|
||||
for(i=0; (c=arg[i])!=0; i++){
|
||||
bufpt[j++] = c;
|
||||
if( c=='\'' ) bufpt[j++] = c;
|
||||
}
|
||||
if( !isnull && xtype==etSQLESCAPE2 ) bufpt[j++] = '\'';
|
||||
bufpt[j] = 0;
|
||||
length = j;
|
||||
if( precision>=0 && precision<length ) length = precision;
|
||||
case etSQLESCAPE2: {
|
||||
int i, j, n, c, isnull;
|
||||
int needQuote;
|
||||
char *arg = va_arg(ap,char*);
|
||||
isnull = arg==0;
|
||||
if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
|
||||
for(i=n=0; (c=arg[i])!=0; i++){
|
||||
if( c=='\'' ) n++;
|
||||
}
|
||||
needQuote = !isnull && xtype==etSQLESCAPE2;
|
||||
n += i + 1 + needQuote*2;
|
||||
if( n>etBUFSIZE ){
|
||||
bufpt = zExtra = sqliteMalloc( n );
|
||||
if( bufpt==0 ) return -1;
|
||||
}else{
|
||||
bufpt = buf;
|
||||
}
|
||||
j = 0;
|
||||
if( needQuote ) bufpt[j++] = '\'';
|
||||
for(i=0; (c=arg[i])!=0; i++){
|
||||
bufpt[j++] = c;
|
||||
if( c=='\'' ) bufpt[j++] = c;
|
||||
}
|
||||
if( needQuote ) bufpt[j++] = '\'';
|
||||
bufpt[j] = 0;
|
||||
length = j;
|
||||
if( precision>=0 && precision<length ) length = precision;
|
||||
break;
|
||||
}
|
||||
case etTOKEN: {
|
||||
Token *pToken = va_arg(ap, Token*);
|
||||
(*func)(arg, pToken->z, pToken->n);
|
||||
if( pToken && pToken->z ){
|
||||
(*func)(arg, pToken->z, pToken->n);
|
||||
}
|
||||
length = width = 0;
|
||||
break;
|
||||
}
|
||||
@@ -681,7 +726,11 @@ static void mout(void *arg, const char *zNewText, int nNewChar){
|
||||
memcpy(pM->zText, pM->zBase, pM->nChar);
|
||||
}
|
||||
}else{
|
||||
pM->zText = pM->xRealloc(pM->zText, pM->nAlloc);
|
||||
char *zNew;
|
||||
zNew = pM->xRealloc(pM->zText, pM->nAlloc);
|
||||
if( zNew ){
|
||||
pM->zText = zNew;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -719,7 +768,10 @@ static char *base_vprintf(
|
||||
memcpy(sM.zText, sM.zBase, sM.nChar+1);
|
||||
}
|
||||
}else if( sM.nAlloc>sM.nChar+10 ){
|
||||
sM.zText = xRealloc(sM.zText, sM.nChar+1);
|
||||
char *zNew = xRealloc(sM.zText, sM.nChar+1);
|
||||
if( zNew ){
|
||||
sM.zText = zNew;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sM.zText;
|
||||
@@ -737,7 +789,7 @@ static void *printf_realloc(void *old, int size){
|
||||
** %-conversion extensions.
|
||||
*/
|
||||
char *sqlite3VMPrintf(const char *zFormat, va_list ap){
|
||||
char zBase[1000];
|
||||
char zBase[SQLITE_PRINT_BUF_SIZE];
|
||||
return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
|
||||
}
|
||||
|
||||
@@ -748,7 +800,7 @@ char *sqlite3VMPrintf(const char *zFormat, va_list ap){
|
||||
char *sqlite3MPrintf(const char *zFormat, ...){
|
||||
va_list ap;
|
||||
char *z;
|
||||
char zBase[1000];
|
||||
char zBase[SQLITE_PRINT_BUF_SIZE];
|
||||
va_start(ap, zFormat);
|
||||
z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
|
||||
va_end(ap);
|
||||
@@ -802,12 +854,13 @@ char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
|
||||
** and segfaults if you give it a long long int.
|
||||
*/
|
||||
void sqlite3DebugPrintf(const char *zFormat, ...){
|
||||
extern int getpid(void);
|
||||
va_list ap;
|
||||
char zBuf[500];
|
||||
va_start(ap, zFormat);
|
||||
base_vprintf(0, 0, zBuf, sizeof(zBuf), zFormat, ap);
|
||||
va_end(ap);
|
||||
fprintf(stdout,"%s", zBuf);
|
||||
fprintf(stdout,"%d: %s", getpid(), zBuf);
|
||||
fflush(stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
+5
-5
@@ -15,7 +15,7 @@
|
||||
** Random numbers are used by some of the database backends in order
|
||||
** to generate random integer keys for tables or random filenames.
|
||||
**
|
||||
** $Id: random.c,v 1.12 2004/05/08 08:23:32 danielk1977 Exp $
|
||||
** $Id: random.c,v 1.13 2005/06/12 21:35:52 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -26,13 +26,16 @@
|
||||
** must be held while executing this routine.
|
||||
**
|
||||
** Why not just use a library random generator like lrand48() for this?
|
||||
** Because the OP_NewRecno opcode in the VDBE depends on having a very
|
||||
** Because the OP_NewRowid opcode in the VDBE depends on having a very
|
||||
** good source of random numbers. The lrand48() library function may
|
||||
** well be good enough. But maybe not. Or maybe lrand48() has some
|
||||
** subtle problems on some systems that could cause problems. It is hard
|
||||
** to know. To minimize the risk of problems due to bad lrand48()
|
||||
** implementations, SQLite uses this random number generator based
|
||||
** on RC4, which we know works very well.
|
||||
**
|
||||
** (Later): Actually, OP_NewRowid does not depend on a good source of
|
||||
** randomness any more. But we will leave this code in all the same.
|
||||
*/
|
||||
static int randomByte(){
|
||||
unsigned char t;
|
||||
@@ -95,6 +98,3 @@ void sqlite3Randomness(int N, void *pBuf){
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+1145
-646
File diff suppressed because it is too large
Load Diff
+74
-12
@@ -12,7 +12,7 @@
|
||||
** This file contains code to implement the "sqlite" command line
|
||||
** utility for accessing SQLite databases.
|
||||
**
|
||||
** $Id: shell.c,v 1.113 2004/08/31 23:41:26 drh Exp $
|
||||
** $Id: shell.c,v 1.128 2005/09/11 02:03:04 drh Exp $
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -196,7 +196,9 @@ static char *one_input_line(const char *zPrior, FILE *in){
|
||||
zPrompt = mainPrompt;
|
||||
}
|
||||
zResult = readline(zPrompt);
|
||||
#if defined(HAVE_READLINE) && HAVE_READLINE==1
|
||||
if( zResult ) add_history(zResult);
|
||||
#endif
|
||||
return zResult;
|
||||
}
|
||||
|
||||
@@ -242,7 +244,8 @@ struct callback_data {
|
||||
#define MODE_Html 4 /* Generate an XHTML table */
|
||||
#define MODE_Insert 5 /* Generate SQL "insert" statements */
|
||||
#define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
|
||||
#define MODE_NUM_OF 7 /* The number of modes (not a mode itself) */
|
||||
#define MODE_Csv 7 /* Quote strings, numbers are plain */
|
||||
#define MODE_NUM_OF 8 /* The number of modes (not a mode itself) */
|
||||
|
||||
char *modeDescr[MODE_NUM_OF] = {
|
||||
"line",
|
||||
@@ -252,6 +255,7 @@ char *modeDescr[MODE_NUM_OF] = {
|
||||
"html",
|
||||
"insert",
|
||||
"tcl",
|
||||
"csv",
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -309,7 +313,7 @@ static void output_c_string(FILE *out, const char *z){
|
||||
fputc('\\', out);
|
||||
fputc('r', out);
|
||||
}else if( !isprint(c) ){
|
||||
fprintf(out, "\\%03o", c);
|
||||
fprintf(out, "\\%03o", c&0xff);
|
||||
}else{
|
||||
fputc(c, out);
|
||||
}
|
||||
@@ -339,6 +343,26 @@ static void output_html_string(FILE *out, const char *z){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Output a single term of CSV. Actually, p->separator is used for
|
||||
** the separator, which may or may not be a comma. p->nullvalue is
|
||||
** the null value. Strings are quoted using ANSI-C rules. Numbers
|
||||
** appear outside of quotes.
|
||||
*/
|
||||
static void output_csv(struct callback_data *p, const char *z, int bSep){
|
||||
if( z==0 ){
|
||||
fprintf(p->out,"%s",p->nullvalue);
|
||||
}else if( isNumber(z, 0) ){
|
||||
fprintf(p->out,"%s",z);
|
||||
}else{
|
||||
output_c_string(p->out, z);
|
||||
}
|
||||
if( bSep ){
|
||||
fprintf(p->out, p->separator);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SIGINT
|
||||
/*
|
||||
** This routine runs when the user presses Ctrl-C
|
||||
*/
|
||||
@@ -346,6 +370,7 @@ static void interrupt_handler(int NotUsed){
|
||||
seenInterrupt = 1;
|
||||
if( db ) sqlite3_interrupt(db);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This is the callback routine that the SQLite library
|
||||
@@ -474,6 +499,20 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
fprintf(p->out,"\n");
|
||||
break;
|
||||
}
|
||||
case MODE_Csv: {
|
||||
if( p->cnt++==0 && p->showHeader ){
|
||||
for(i=0; i<nArg; i++){
|
||||
output_csv(p, azCol[i], i<nArg-1);
|
||||
}
|
||||
fprintf(p->out,"\n");
|
||||
}
|
||||
if( azArg==0 ) break;
|
||||
for(i=0; i<nArg; i++){
|
||||
output_csv(p, azArg[i], i<nArg-1);
|
||||
}
|
||||
fprintf(p->out,"\n");
|
||||
break;
|
||||
}
|
||||
case MODE_Insert: {
|
||||
if( azArg==0 ) break;
|
||||
fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
|
||||
@@ -617,7 +656,15 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
|
||||
zType = azArg[1];
|
||||
zSql = azArg[2];
|
||||
|
||||
fprintf(p->out, "%s;\n", zSql);
|
||||
if( strcmp(zTable, "sqlite_sequence")==0 ){
|
||||
fprintf(p->out, "DELETE FROM sqlite_sequence;\n");
|
||||
}else if( strcmp(zTable, "sqlite_stat1")==0 ){
|
||||
fprintf(p->out, "ANALYZE sqlite_master;\n");
|
||||
}else if( strncmp(zTable, "sqlite_", 7)==0 ){
|
||||
return 0;
|
||||
}else{
|
||||
fprintf(p->out, "%s;\n", zSql);
|
||||
}
|
||||
|
||||
if( strcmp(zType, "table")==0 ){
|
||||
sqlite3_stmt *pTableInfo = 0;
|
||||
@@ -711,8 +758,8 @@ static char zHelp[] =
|
||||
".help Show this message\n"
|
||||
".import FILE TABLE Import data from FILE into TABLE\n"
|
||||
".indices TABLE Show names of all indices on TABLE\n"
|
||||
".mode MODE ?TABLE? Set output mode where MODE is on of:\n"
|
||||
" cvs Comma-separated values\n"
|
||||
".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
|
||||
" csv Comma-separated values\n"
|
||||
" column Left-aligned columns. (See .width)\n"
|
||||
" html HTML <table> code\n"
|
||||
" insert SQL insert statements for TABLE\n"
|
||||
@@ -847,6 +894,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
data.colWidth[0] = 3;
|
||||
data.colWidth[1] = 15;
|
||||
data.colWidth[2] = 58;
|
||||
data.cnt = 0;
|
||||
sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
|
||||
if( zErrMsg ){
|
||||
fprintf(stderr,"Error: %s\n", zErrMsg);
|
||||
@@ -940,10 +988,10 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
p->showHeader = 1;
|
||||
memset(p->colWidth,0,ArraySize(p->colWidth));
|
||||
p->colWidth[0] = 4;
|
||||
p->colWidth[1] = 12;
|
||||
p->colWidth[1] = 14;
|
||||
p->colWidth[2] = 10;
|
||||
p->colWidth[3] = 10;
|
||||
p->colWidth[4] = 35;
|
||||
p->colWidth[4] = 33;
|
||||
}else if (p->explainPrev.valid) {
|
||||
p->explainPrev.valid = 0;
|
||||
p->mode = p->explainPrev.mode;
|
||||
@@ -1039,7 +1087,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
i = 0;
|
||||
lineno++;
|
||||
azCol[0] = zLine;
|
||||
for(i=0, z=zLine; *z; z++){
|
||||
for(i=0, z=zLine; *z && *z!='\n' && *z!='\r'; z++){
|
||||
if( *z==p->separator[0] && strncmp(z, p->separator, nSep)==0 ){
|
||||
*z = 0;
|
||||
i++;
|
||||
@@ -1049,6 +1097,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
}
|
||||
}
|
||||
}
|
||||
*z = 0;
|
||||
if( i+1!=nCol ){
|
||||
fprintf(stderr,"%s line %d: expected %d columns of data but found %d\n",
|
||||
zFile, lineno, nCol, i+1);
|
||||
@@ -1114,7 +1163,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
}else if( strncmp(azArg[1],"tcl",n2)==0 ){
|
||||
p->mode = MODE_Tcl;
|
||||
}else if( strncmp(azArg[1],"csv",n2)==0 ){
|
||||
p->mode = MODE_List;
|
||||
p->mode = MODE_Csv;
|
||||
strcpy(p->separator, ",");
|
||||
}else if( strncmp(azArg[1],"tabs",n2)==0 ){
|
||||
p->mode = MODE_List;
|
||||
@@ -1245,7 +1294,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
"SELECT sql FROM "
|
||||
" (SELECT * FROM sqlite_master UNION ALL"
|
||||
" SELECT * FROM sqlite_temp_master) "
|
||||
"WHERE type!='meta' AND sql NOTNULL "
|
||||
"WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
|
||||
"ORDER BY substr(type,2,1), name",
|
||||
callback, &data, &zErrMsg
|
||||
);
|
||||
@@ -1289,7 +1338,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
|
||||
if( nArg==1 ){
|
||||
rc = sqlite3_get_table(p->db,
|
||||
"SELECT name FROM sqlite_master "
|
||||
"WHERE type IN ('table','view') "
|
||||
"WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'"
|
||||
"UNION ALL "
|
||||
"SELECT name FROM sqlite_temp_master "
|
||||
"WHERE type IN ('table','view') "
|
||||
@@ -1642,13 +1691,24 @@ int main(int argc, char **argv){
|
||||
if( i<argc ){
|
||||
data.zDbFilename = argv[i++];
|
||||
}else{
|
||||
#ifndef SQLITE_OMIT_MEMORYDB
|
||||
data.zDbFilename = ":memory:";
|
||||
#else
|
||||
data.zDbFilename = 0;
|
||||
#endif
|
||||
}
|
||||
if( i<argc ){
|
||||
zFirstCmd = argv[i++];
|
||||
}
|
||||
data.out = stdout;
|
||||
|
||||
#ifdef SQLITE_OMIT_MEMORYDB
|
||||
if( data.zDbFilename==0 ){
|
||||
fprintf(stderr,"%s: no database filename specified\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Go ahead and open the database file if it already exists. If the
|
||||
** file does not exist, delay opening it. This prevents empty database
|
||||
** files from being created if a user mistypes the database name argument
|
||||
@@ -1735,7 +1795,9 @@ int main(int argc, char **argv){
|
||||
if( zHome && (zHistory = malloc(strlen(zHome)+20))!=0 ){
|
||||
sprintf(zHistory,"%s/.sqlite_history", zHome);
|
||||
}
|
||||
#if defined(HAVE_READLINE) && HAVE_READLINE==1
|
||||
if( zHistory ) read_history(zHistory);
|
||||
#endif
|
||||
process_input(&data, 0);
|
||||
if( zHistory ){
|
||||
stifle_history(100);
|
||||
|
||||
+173
-41
@@ -12,10 +12,10 @@
|
||||
** This header file defines the interface that the SQLite library
|
||||
** presents to client programs.
|
||||
**
|
||||
** @(#) $Id: sqlite.h.in,v 1.116 2004/08/29 23:42:14 drh Exp $
|
||||
** @(#) $Id: sqlite.h.in,v 1.141 2005/09/08 10:58:52 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_H_
|
||||
#define _SQLITE_H_
|
||||
#ifndef _SQLITE3_H_
|
||||
#define _SQLITE3_H_
|
||||
#include <stdarg.h> /* Needed for the definition of va_list */
|
||||
|
||||
/*
|
||||
@@ -28,8 +28,28 @@ extern "C" {
|
||||
/*
|
||||
** The version of the SQLite library.
|
||||
*/
|
||||
#ifdef SQLITE_VERSION
|
||||
# undef SQLITE_VERSION
|
||||
#endif
|
||||
#define SQLITE_VERSION "--VERS--"
|
||||
|
||||
/*
|
||||
** The format of the version string is "X.Y.Z<trailing string>", where
|
||||
** X is the major version number, Y is the minor version number and Z
|
||||
** is the release number. The trailing string is often "alpha" or "beta".
|
||||
** For example "3.1.1beta".
|
||||
**
|
||||
** The SQLITE_VERSION_NUMBER is an integer with the value
|
||||
** (X*100000 + Y*1000 + Z). For example, for version "3.1.1beta",
|
||||
** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using
|
||||
** version 3.1.1 or greater at compile time, programs may use the test
|
||||
** (SQLITE_VERSION_NUMBER>=3001001).
|
||||
*/
|
||||
#ifdef SQLITE_VERSION_NUMBER
|
||||
# undef SQLITE_VERSION_NUMBER
|
||||
#endif
|
||||
#define SQLITE_VERSION_NUMBER --VERSION-NUMBER--
|
||||
|
||||
/*
|
||||
** The version string is also compiled into the library so that a program
|
||||
** can check to make sure that the lib*.a file and the *.h file are from
|
||||
@@ -38,13 +58,19 @@ extern "C" {
|
||||
** global variables.
|
||||
*/
|
||||
extern const char sqlite3_version[];
|
||||
const char *sqlite3_libversion();
|
||||
const char *sqlite3_libversion(void);
|
||||
|
||||
/*
|
||||
** Return the value of the SQLITE_VERSION_NUMBER macro when the
|
||||
** library was compiled.
|
||||
*/
|
||||
int sqlite3_libversion_number(void);
|
||||
|
||||
/*
|
||||
** Each open sqlite database is represented by an instance of the
|
||||
** following opaque structure.
|
||||
*/
|
||||
typedef struct sqlite sqlite3;
|
||||
typedef struct sqlite3 sqlite3;
|
||||
|
||||
|
||||
/*
|
||||
@@ -77,7 +103,7 @@ int sqlite3_close(sqlite3 *);
|
||||
/*
|
||||
** The type for a callback function.
|
||||
*/
|
||||
typedef int (*sqlite_callback)(void*,int,char**, char**);
|
||||
typedef int (*sqlite3_callback)(void*,int,char**, char**);
|
||||
|
||||
/*
|
||||
** A function to executes one or more statements of SQL.
|
||||
@@ -120,9 +146,9 @@ typedef int (*sqlite_callback)(void*,int,char**, char**);
|
||||
** and sqlite3_busy_timeout() functions below.)
|
||||
*/
|
||||
int sqlite3_exec(
|
||||
sqlite3*, /* An open database */
|
||||
sqlite3*, /* An open database */
|
||||
const char *sql, /* SQL to be executed */
|
||||
sqlite_callback, /* Callback function */
|
||||
sqlite3_callback, /* Callback function */
|
||||
void *, /* 1st argument to callback function */
|
||||
char **errmsg /* Error msg written here */
|
||||
);
|
||||
@@ -132,7 +158,7 @@ int sqlite3_exec(
|
||||
*/
|
||||
#define SQLITE_OK 0 /* Successful result */
|
||||
#define SQLITE_ERROR 1 /* SQL error or missing database */
|
||||
#define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */
|
||||
#define SQLITE_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */
|
||||
#define SQLITE_PERM 3 /* Access permission denied */
|
||||
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
|
||||
#define SQLITE_BUSY 5 /* The database file is locked */
|
||||
@@ -142,13 +168,13 @@ int sqlite3_exec(
|
||||
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
|
||||
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
|
||||
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
|
||||
#define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */
|
||||
#define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
|
||||
#define SQLITE_FULL 13 /* Insertion failed because database is full */
|
||||
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
|
||||
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
|
||||
#define SQLITE_EMPTY 16 /* Database is empty */
|
||||
#define SQLITE_SCHEMA 17 /* The database schema changed */
|
||||
#define SQLITE_TOOBIG 18 /* Too much data for one row of a table */
|
||||
#define SQLITE_TOOBIG 18 /* NOT USED. Too much data for one row */
|
||||
#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */
|
||||
#define SQLITE_MISMATCH 20 /* Data type mismatch */
|
||||
#define SQLITE_MISUSE 21 /* Library used incorrectly */
|
||||
@@ -305,7 +331,7 @@ int sqlite3_busy_timeout(sqlite3*, int ms);
|
||||
** pass the result data pointer to sqlite3_free_table() in order to
|
||||
** release the memory that was malloc-ed. Because of the way the
|
||||
** malloc() happens, the calling function must not try to call
|
||||
** malloc() directly. Only sqlite3_free_table() is able to release
|
||||
** free() directly. Only sqlite3_free_table() is able to release
|
||||
** the memory properly and safely.
|
||||
**
|
||||
** The return value of this routine is the same as from sqlite3_exec().
|
||||
@@ -347,8 +373,9 @@ void sqlite3_free_table(char **result);
|
||||
**
|
||||
** We can use this text in an SQL statement as follows:
|
||||
**
|
||||
** sqlite3_exec_printf(db, "INSERT INTO table VALUES('%q')",
|
||||
** callback1, 0, 0, zText);
|
||||
** char *z = sqlite3_mprintf("INSERT INTO TABLES('%q')", zText);
|
||||
** sqlite3_exec(db, z, callback1, 0, 0);
|
||||
** sqlite3_free(z);
|
||||
**
|
||||
** Because the %q format string is used, the '\'' character in zText
|
||||
** is escaped and the SQL generated is as follows:
|
||||
@@ -424,6 +451,9 @@ int sqlite3_set_authorizer(
|
||||
#define SQLITE_UPDATE 23 /* Table Name Column Name */
|
||||
#define SQLITE_ATTACH 24 /* Filename NULL */
|
||||
#define SQLITE_DETACH 25 /* Database Name NULL */
|
||||
#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
|
||||
#define SQLITE_REINDEX 27 /* Index Name NULL */
|
||||
#define SQLITE_ANALYZE 28 /* Table Name NULL */
|
||||
|
||||
|
||||
/*
|
||||
@@ -435,17 +465,24 @@ int sqlite3_set_authorizer(
|
||||
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
|
||||
|
||||
/*
|
||||
** Register a function that is called at every invocation of sqlite3_exec()
|
||||
** or sqlite3_prepare(). This function can be used (for example) to generate
|
||||
** a log file of all SQL executed against a database.
|
||||
** Register a function for tracing SQL command evaluation. The function
|
||||
** registered by sqlite3_trace() is invoked at the first sqlite3_step()
|
||||
** for the evaluation of an SQL statement. The function registered by
|
||||
** sqlite3_profile() runs at the end of each SQL statement and includes
|
||||
** information on how long that statement ran.
|
||||
**
|
||||
** The sqlite3_profile() API is currently considered experimental and
|
||||
** is subject to change.
|
||||
*/
|
||||
void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
|
||||
void *sqlite3_profile(sqlite3*,
|
||||
void(*xProfile)(void*,const char*,sqlite_uint64), void*);
|
||||
|
||||
/*
|
||||
** This routine configures a callback function - the progress callback - that
|
||||
** is invoked periodically during long running calls to sqlite3_exec(),
|
||||
** sqlite3_step() and sqlite3_get_table(). An example use for this API is to keep
|
||||
** a GUI updated during a large query.
|
||||
** sqlite3_step() and sqlite3_get_table(). An example use for this API is to
|
||||
** keep a GUI updated during a large query.
|
||||
**
|
||||
** The progress callback is invoked once for every N virtual machine opcodes,
|
||||
** where N is the second argument to this function. The progress callback
|
||||
@@ -602,14 +639,19 @@ typedef struct Mem sqlite3_value;
|
||||
|
||||
/*
|
||||
** In the SQL strings input to sqlite3_prepare() and sqlite3_prepare16(),
|
||||
** one or more literals can be replace by a wildcard "?" or ":N:" where
|
||||
** N is an integer. These value of these wildcard literals can be set
|
||||
** using the routines listed below.
|
||||
** one or more literals can be replace by parameters "?" or ":AAA" or
|
||||
** "$VVV" where AAA is an identifer and VVV is a variable name according
|
||||
** to the syntax rules of the TCL programming language.
|
||||
** The value of these parameters (also called "host parameter names") can
|
||||
** be set using the routines listed below.
|
||||
**
|
||||
** In every case, the first parameter is a pointer to the sqlite3_stmt
|
||||
** structure returned from sqlite3_prepare(). The second parameter is the
|
||||
** index of the wildcard. The first "?" has an index of 1. ":N:" wildcards
|
||||
** use the index N.
|
||||
** index of the parameter. The first parameter as an index of 1. For
|
||||
** named parameters (":AAA" or "$VVV") you can use
|
||||
** sqlite3_bind_parameter_index() to get the correct index value given
|
||||
** the parameters name. If the same named parameter occurs more than
|
||||
** once, it is assigned the same index each time.
|
||||
**
|
||||
** The fifth parameter to sqlite3_bind_blob(), sqlite3_bind_text(), and
|
||||
** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
|
||||
@@ -620,8 +662,8 @@ typedef struct Mem sqlite3_value;
|
||||
** own private copy of the data.
|
||||
**
|
||||
** The sqlite3_bind_* routine must be called before sqlite3_step() after
|
||||
** an sqlite3_prepare() or sqlite3_reset(). Unbound wildcards are interpreted
|
||||
** as NULL.
|
||||
** an sqlite3_prepare() or sqlite3_reset(). Unbound parameterss are
|
||||
** interpreted as NULL.
|
||||
*/
|
||||
int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
|
||||
int sqlite3_bind_double(sqlite3_stmt*, int, double);
|
||||
@@ -633,19 +675,31 @@ int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
|
||||
int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
|
||||
|
||||
/*
|
||||
** Return the number of wildcards in a compiled SQL statement. This
|
||||
** Return the number of parameters in a compiled SQL statement. This
|
||||
** routine was added to support DBD::SQLite.
|
||||
*/
|
||||
int sqlite3_bind_parameter_count(sqlite3_stmt*);
|
||||
|
||||
/*
|
||||
** Return the name of the i-th parameter. Ordinary wildcards "?" are
|
||||
** nameless and a NULL is returned. For wildcards of the form :N: or
|
||||
** $vvvv the complete text of the wildcard is returned.
|
||||
** NULL is returned if the index is out of range.
|
||||
** Return the name of the i-th parameter. Ordinary parameters "?" are
|
||||
** nameless and a NULL is returned. For parameters of the form :AAA or
|
||||
** $VVV the complete text of the parameter name is returned, including
|
||||
** the initial ":" or "$". NULL is returned if the index is out of range.
|
||||
*/
|
||||
const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
|
||||
|
||||
/*
|
||||
** Return the index of a parameter with the given name. The name
|
||||
** must match exactly. If no parameter with the given name is found,
|
||||
** return 0.
|
||||
*/
|
||||
int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
|
||||
|
||||
/*
|
||||
** Set all the parameters in the compiled SQL statement to NULL.
|
||||
*/
|
||||
int sqlite3_clear_bindings(sqlite3_stmt*);
|
||||
|
||||
/*
|
||||
** Return the number of columns in the result set returned by the compiled
|
||||
** SQL statement. This routine returns 0 if pStmt is an SQL statement
|
||||
@@ -753,10 +807,22 @@ int sqlite3_data_count(sqlite3_stmt *pStmt);
|
||||
*/
|
||||
#define SQLITE_INTEGER 1
|
||||
#define SQLITE_FLOAT 2
|
||||
#define SQLITE_TEXT 3
|
||||
/* #define SQLITE_TEXT 3 // See below */
|
||||
#define SQLITE_BLOB 4
|
||||
#define SQLITE_NULL 5
|
||||
|
||||
/*
|
||||
** SQLite version 2 defines SQLITE_TEXT differently. To allow both
|
||||
** version 2 and version 3 to be included, undefine them both if a
|
||||
** conflict is seen. Define SQLITE3_TEXT to be the version 3 value.
|
||||
*/
|
||||
#ifdef SQLITE_TEXT
|
||||
# undef SQLITE_TEXT
|
||||
#else
|
||||
# define SQLITE_TEXT 3
|
||||
#endif
|
||||
#define SQLITE3_TEXT 3
|
||||
|
||||
/*
|
||||
** The next group of routines returns information about the information
|
||||
** in a single column of the current result row of a query. In every
|
||||
@@ -945,10 +1011,9 @@ int sqlite3_value_type(sqlite3_value*);
|
||||
void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
|
||||
|
||||
/*
|
||||
** The pUserData parameter to the sqlite3_create_function() and
|
||||
** sqlite3_create_aggregate() routines used to register user functions
|
||||
** is available to the implementation of the function using this
|
||||
** call.
|
||||
** The pUserData parameter to the sqlite3_create_function()
|
||||
** routine used to register user functions is available to
|
||||
** the implementation of the function using this call.
|
||||
*/
|
||||
void *sqlite3_user_data(sqlite3_context*);
|
||||
|
||||
@@ -1125,17 +1190,84 @@ int sqlite3_rekey(
|
||||
);
|
||||
|
||||
/*
|
||||
** If the following global variable is made to point to a constant
|
||||
** Sleep for a little while. The second parameter is the number of
|
||||
** miliseconds to sleep for.
|
||||
**
|
||||
** If the operating system does not support sleep requests with
|
||||
** milisecond time resolution, then the time will be rounded up to
|
||||
** the nearest second. The number of miliseconds of sleep actually
|
||||
** requested from the operating system is returned.
|
||||
*/
|
||||
int sqlite3_sleep(int);
|
||||
|
||||
/*
|
||||
** Return TRUE (non-zero) if the statement supplied as an argument needs
|
||||
** to be recompiled. A statement needs to be recompiled whenever the
|
||||
** execution environment changes in a way that would alter the program
|
||||
** that sqlite3_prepare() generates. For example, if new functions or
|
||||
** collating sequences are registered or if an authorizer function is
|
||||
** added or changed.
|
||||
**
|
||||
*/
|
||||
int sqlite3_expired(sqlite3_stmt*);
|
||||
|
||||
/*
|
||||
** Move all bindings from the first prepared statement over to the second.
|
||||
** This routine is useful, for example, if the first prepared statement
|
||||
** fails with an SQLITE_SCHEMA error. The same SQL can be prepared into
|
||||
** the second prepared statement then all of the bindings transfered over
|
||||
** to the second statement before the first statement is finalized.
|
||||
*/
|
||||
int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
|
||||
|
||||
/*
|
||||
** If the following global variable is made to point to a
|
||||
** string which is the name of a directory, then all temporary files
|
||||
** created by SQLite will be placed in that directory. If this variable
|
||||
** is NULL pointer, then SQLite does a search for an appropriate temporary
|
||||
** file directory.
|
||||
**
|
||||
** This variable should only be changed when there are no open databases.
|
||||
** Once sqlite3_open() has been called, this variable should not be changed
|
||||
** until all database connections are closed.
|
||||
** Once sqlite3_open() has been called, changing this variable will invalidate
|
||||
** the current temporary database, if any.
|
||||
*/
|
||||
extern const char *sqlite3_temp_directory;
|
||||
extern char *sqlite3_temp_directory;
|
||||
|
||||
/*
|
||||
** This function is called to recover from a malloc() failure that occured
|
||||
** within the SQLite library. Normally, after a single malloc() fails the
|
||||
** library refuses to function (all major calls return SQLITE_NOMEM).
|
||||
** This function restores the library state so that it can be used again.
|
||||
**
|
||||
** All existing statements (sqlite3_stmt pointers) must be finalized or
|
||||
** reset before this call is made. Otherwise, SQLITE_BUSY is returned.
|
||||
** If any in-memory databases are in use, either as a main or TEMP
|
||||
** database, SQLITE_ERROR is returned. In either of these cases, the
|
||||
** library is not reset and remains unusable.
|
||||
**
|
||||
** This function is *not* threadsafe. Calling this from within a threaded
|
||||
** application when threads other than the caller have used SQLite is
|
||||
** dangerous and will almost certainly result in malfunctions.
|
||||
**
|
||||
** This functionality can be omitted from a build by defining the
|
||||
** SQLITE_OMIT_GLOBALRECOVER at compile time.
|
||||
*/
|
||||
int sqlite3_global_recover();
|
||||
|
||||
/*
|
||||
** Test to see whether or not the database connection is in autocommit
|
||||
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
|
||||
** by default. Autocommit is disabled by a BEGIN statement and reenabled
|
||||
** by the next COMMIT or ROLLBACK.
|
||||
*/
|
||||
int sqlite3_get_autocommit(sqlite3*);
|
||||
|
||||
/*
|
||||
** Return the sqlite3* database handle to which the prepared statement given
|
||||
** in the argument belongs. This is the same database handle that was
|
||||
** the first argument to the sqlite3_prepare() that was used to create
|
||||
** the statement in the first place.
|
||||
*/
|
||||
sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* End of the 'extern "C"' block */
|
||||
|
||||
+505
-234
File diff suppressed because it is too large
Load Diff
+4
-5
@@ -118,7 +118,7 @@ malloc_failed:
|
||||
** the calling procedure is finished using it.
|
||||
*/
|
||||
int sqlite3_get_table(
|
||||
sqlite *db, /* The database on which the SQL executes */
|
||||
sqlite3 *db, /* The database on which the SQL executes */
|
||||
const char *zSql, /* The SQL to be executed */
|
||||
char ***pazResult, /* Write the result table here */
|
||||
int *pnRow, /* Write the number of rows in the result here */
|
||||
@@ -150,12 +150,11 @@ int sqlite3_get_table(
|
||||
if( res.zErrMsg ){
|
||||
if( pzErrMsg ){
|
||||
free(*pzErrMsg);
|
||||
*pzErrMsg = res.zErrMsg;
|
||||
sqlite3StrRealloc(pzErrMsg);
|
||||
}else{
|
||||
sqliteFree(res.zErrMsg);
|
||||
*pzErrMsg = sqlite3_mprintf("%s",res.zErrMsg);
|
||||
}
|
||||
sqliteFree(res.zErrMsg);
|
||||
}
|
||||
db->errCode = res.rc;
|
||||
return res.rc;
|
||||
}
|
||||
sqliteFree(res.zErrMsg);
|
||||
|
||||
+1257
-512
File diff suppressed because it is too large
Load Diff
+813
-97
File diff suppressed because it is too large
Load Diff
+65
-27
@@ -13,10 +13,10 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test2.c,v 1.24 2004/07/22 01:19:35 drh Exp $
|
||||
** $Id: test2.c,v 1.34 2005/09/16 10:13:42 danielk1977 Exp $
|
||||
*/
|
||||
#include "os.h"
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include "pager.h"
|
||||
#include "tcl.h"
|
||||
#include <stdlib.h>
|
||||
@@ -30,7 +30,6 @@ static char *errorName(int rc){
|
||||
switch( rc ){
|
||||
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
||||
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
||||
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
|
||||
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
||||
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
||||
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
||||
@@ -39,13 +38,11 @@ static char *errorName(int rc){
|
||||
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
||||
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
||||
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
|
||||
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
|
||||
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
|
||||
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
|
||||
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
|
||||
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
|
||||
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
|
||||
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
|
||||
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
|
||||
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
|
||||
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
|
||||
@@ -81,14 +78,14 @@ static int pager_open(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_open(&pPager, argv[1], 0, 1);
|
||||
rc = sqlite3pager_open(&pPager, argv[1], 0, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sqlite3pager_set_cachesize(pPager, nPage);
|
||||
sqlite3pager_set_pagesize(pPager, test_pagesize);
|
||||
sprintf(zBuf,"0x%x",(int)pPager);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -111,7 +108,7 @@ static int pager_close(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_close(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -138,7 +135,7 @@ static int pager_rollback(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_rollback(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -165,7 +162,7 @@ static int pager_commit(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_commit(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -192,7 +189,7 @@ static int pager_stmt_begin(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_stmt_begin(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -219,7 +216,7 @@ static int pager_stmt_rollback(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_stmt_rollback(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -246,7 +243,7 @@ static int pager_stmt_commit(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_stmt_commit(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -273,7 +270,7 @@ static int pager_stats(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
a = sqlite3pager_stats(pPager);
|
||||
for(i=0; i<9; i++){
|
||||
static char *zName[] = {
|
||||
@@ -282,7 +279,7 @@ static int pager_stats(
|
||||
};
|
||||
char zBuf[100];
|
||||
Tcl_AppendElement(interp, zName[i]);
|
||||
sprintf(zBuf,"%d",a[i]);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",a[i]);
|
||||
Tcl_AppendElement(interp, zBuf);
|
||||
}
|
||||
return TCL_OK;
|
||||
@@ -306,8 +303,8 @@ static int pager_pagecount(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
sprintf(zBuf,"%d",sqlite3pager_pagecount(pPager));
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3pager_pagecount(pPager));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -333,14 +330,14 @@ static int page_get(
|
||||
" ID PGNO\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_get(pPager, pgno, &pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"0x%x",(int)pPage);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -366,16 +363,44 @@ static int page_lookup(
|
||||
" ID PGNO\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
|
||||
pPage = sqlite3pager_lookup(pPager, pgno);
|
||||
if( pPage ){
|
||||
sprintf(zBuf,"0x%x",(int)pPage);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_truncate ID PGNO
|
||||
*/
|
||||
static int pager_truncate(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int rc;
|
||||
int pgno;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID PGNO\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
|
||||
rc = sqlite3pager_truncate(pPager, pgno);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Usage: page_unref PAGE
|
||||
**
|
||||
@@ -394,7 +419,7 @@ static int page_unref(
|
||||
" PAGE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
pPage = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_unref(pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -421,7 +446,7 @@ static int page_read(
|
||||
" PAGE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
pPage = sqlite3TextToPtr(argv[1]);
|
||||
memcpy(zBuf, pPage, sizeof(zBuf));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
@@ -445,8 +470,8 @@ static int page_number(
|
||||
" PAGE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
sprintf(zBuf, "%d", sqlite3pager_pagenumber(pPage));
|
||||
pPage = sqlite3TextToPtr(argv[1]);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", sqlite3pager_pagenumber(pPage));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -469,7 +494,7 @@ static int page_write(
|
||||
" PAGE DATA\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
pPage = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_write(pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -480,6 +505,7 @@ static int page_write(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
/*
|
||||
** Usage: fake_big_file N FILENAME
|
||||
**
|
||||
@@ -497,7 +523,7 @@ static int fake_big_file(
|
||||
){
|
||||
int rc;
|
||||
int n;
|
||||
off_t offset;
|
||||
i64 offset;
|
||||
OsFile fd;
|
||||
int readOnly = 0;
|
||||
if( argc!=3 ){
|
||||
@@ -527,12 +553,15 @@ static int fake_big_file(
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
extern int sqlite3_io_error_pending;
|
||||
extern int sqlite3_diskfull_pending;
|
||||
extern int sqlite3_diskfull;
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_CmdProc *xProc;
|
||||
@@ -552,7 +581,10 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
{ "page_read", (Tcl_CmdProc*)page_read },
|
||||
{ "page_write", (Tcl_CmdProc*)page_write },
|
||||
{ "page_number", (Tcl_CmdProc*)page_number },
|
||||
{ "pager_truncate", (Tcl_CmdProc*)pager_truncate },
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
{ "fake_big_file", (Tcl_CmdProc*)fake_big_file },
|
||||
#endif
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
||||
@@ -560,6 +592,12 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
}
|
||||
Tcl_LinkVar(interp, "sqlite_io_error_pending",
|
||||
(char*)&sqlite3_io_error_pending, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_diskfull_pending",
|
||||
(char*)&sqlite3_diskfull_pending, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_diskfull",
|
||||
(char*)&sqlite3_diskfull, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_pending_byte",
|
||||
(char*)&sqlite3_pending_byte, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "pager_pagesize",
|
||||
(char*)&test_pagesize, TCL_LINK_INT);
|
||||
return TCL_OK;
|
||||
|
||||
+139
-65
@@ -13,7 +13,7 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test3.c,v 1.50 2004/07/23 00:01:39 drh Exp $
|
||||
** $Id: test3.c,v 1.62 2005/08/11 02:10:19 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "pager.h"
|
||||
@@ -30,7 +30,6 @@ static char *errorName(int rc){
|
||||
switch( rc ){
|
||||
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
||||
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
||||
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
|
||||
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
||||
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
||||
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
||||
@@ -39,11 +38,11 @@ static char *errorName(int rc){
|
||||
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
||||
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
||||
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
|
||||
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
|
||||
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
|
||||
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
|
||||
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
|
||||
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
|
||||
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
|
||||
default: zName = "SQLITE_Unknown"; break;
|
||||
}
|
||||
return zName;
|
||||
@@ -76,10 +75,7 @@ static int btree_open(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sqlite3BtreeSetCacheSize(pBt, nCache);
|
||||
sprintf(zBuf,"%p", pBt);
|
||||
if( strncmp(zBuf,"0x",2) ){
|
||||
sprintf(zBuf, "0x%p", pBt);
|
||||
}
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pBt);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -102,7 +98,7 @@ static int btree_close(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeClose(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -129,7 +125,7 @@ static int btree_begin_transaction(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeBeginTrans(pBt, 1);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -156,7 +152,7 @@ static int btree_rollback(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeRollback(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -183,7 +179,7 @@ static int btree_commit(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeCommit(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -210,7 +206,7 @@ static int btree_begin_statement(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeBeginStmt(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -237,7 +233,7 @@ static int btree_rollback_statement(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeRollbackStmt(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -264,7 +260,7 @@ static int btree_commit_statement(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeCommitStmt(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -292,14 +288,14 @@ static int btree_create_table(
|
||||
" ID FLAGS\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &flags) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeCreateTable(pBt, &iTable, flags);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf, "%d", iTable);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", iTable);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -318,14 +314,15 @@ static int btree_drop_table(
|
||||
Btree *pBt;
|
||||
int iTable;
|
||||
int rc;
|
||||
int notUsed1;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID TABLENUM\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeDropTable(pBt, iTable);
|
||||
rc = sqlite3BtreeDropTable(pBt, iTable, ¬Used1);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -352,7 +349,7 @@ static int btree_clear_table(
|
||||
" ID TABLENUM\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeClearTable(pBt, iTable);
|
||||
if( rc!=SQLITE_OK ){
|
||||
@@ -381,7 +378,7 @@ static int btree_get_meta(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
for(i=0; i<SQLITE_N_BTREE_META; i++){
|
||||
char zBuf[30];
|
||||
unsigned int v;
|
||||
@@ -390,7 +387,7 @@ static int btree_get_meta(
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",v);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf,"%d",v);
|
||||
Tcl_AppendElement(interp, zBuf);
|
||||
}
|
||||
return TCL_OK;
|
||||
@@ -414,12 +411,12 @@ static int btree_update_meta(
|
||||
|
||||
if( argc!=2+SQLITE_N_BTREE_META ){
|
||||
char zBuf[30];
|
||||
sprintf(zBuf,"%d",SQLITE_N_BTREE_META);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf,"%d",SQLITE_N_BTREE_META);
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID METADATA...\" (METADATA is ", zBuf, " integers)", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
for(i=1; i<SQLITE_N_BTREE_META; i++){
|
||||
if( Tcl_GetInt(interp, argv[i+2], &aMeta[i]) ) return TCL_ERROR;
|
||||
}
|
||||
@@ -453,7 +450,7 @@ static int btree_page_dump(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &iPage) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreePageDump(pBt, iPage, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
@@ -483,7 +480,7 @@ static int btree_tree_dump(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &iPage) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreePageDump(pBt, iPage, 1);
|
||||
if( rc!=SQLITE_OK ){
|
||||
@@ -513,16 +510,16 @@ static int btree_pager_stats(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
a = sqlite3pager_stats(sqlite3BtreePager(pBt));
|
||||
for(i=0; i<9; i++){
|
||||
for(i=0; i<11; i++){
|
||||
static char *zName[] = {
|
||||
"ref", "page", "max", "size", "state", "err",
|
||||
"hit", "miss", "ovfl",
|
||||
"hit", "miss", "ovfl", "read", "write"
|
||||
};
|
||||
char zBuf[100];
|
||||
Tcl_AppendElement(interp, zName[i]);
|
||||
sprintf(zBuf,"%d",a[i]);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf,"%d",a[i]);
|
||||
Tcl_AppendElement(interp, zBuf);
|
||||
}
|
||||
return TCL_OK;
|
||||
@@ -546,8 +543,10 @@ static int btree_pager_ref_dump(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
#ifdef SQLITE_DEBUG
|
||||
sqlite3pager_refdump(sqlite3BtreePager(pBt));
|
||||
#endif
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -565,23 +564,27 @@ static int btree_integrity_check(
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
char *zResult;
|
||||
int nRoot;
|
||||
int *aRoot;
|
||||
int i;
|
||||
char *zResult;
|
||||
|
||||
if( argc<3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID ROOT ...\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
nRoot = argc-2;
|
||||
aRoot = malloc( sizeof(int)*(argc-2) );
|
||||
for(i=0; i<argc-2; i++){
|
||||
if( Tcl_GetInt(interp, argv[i+2], &aRoot[i]) ) return TCL_ERROR;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
|
||||
zResult = sqlite3BtreeIntegrityCheck(pBt, aRoot, nRoot);
|
||||
#else
|
||||
zResult = 0;
|
||||
#endif
|
||||
if( zResult ){
|
||||
Tcl_AppendResult(interp, zResult, 0);
|
||||
sqliteFree(zResult);
|
||||
@@ -607,7 +610,7 @@ static int btree_cursor_list(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
sqlite3BtreeCursorList(pBt);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -635,7 +638,7 @@ static int btree_cursor(
|
||||
" ID TABLENUM WRITEABLE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
|
||||
if( Tcl_GetBoolean(interp, argv[3], &wrFlag) ) return TCL_ERROR;
|
||||
rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, 0, 0, &pCur);
|
||||
@@ -643,7 +646,7 @@ static int btree_cursor(
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"0x%x", (int)pCur);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pCur);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -667,7 +670,7 @@ static int btree_close_cursor(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeCloseCursor(pCur);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -697,7 +700,7 @@ static int btree_move_to(
|
||||
" ID KEY\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
|
||||
int iKey;
|
||||
if( Tcl_GetInt(interp, argv[2], &iKey) ) return TCL_ERROR;
|
||||
@@ -711,7 +714,7 @@ static int btree_move_to(
|
||||
}
|
||||
if( res<0 ) res = -1;
|
||||
if( res>0 ) res = 1;
|
||||
sprintf(zBuf,"%d",res);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf,"%d",res);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -735,7 +738,7 @@ static int btree_delete(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeDelete(pCur);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
@@ -763,8 +766,7 @@ static int btree_insert(
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "ID KEY DATA");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(Tcl_GetString(objv[1]));
|
||||
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
|
||||
i64 iKey;
|
||||
int len;
|
||||
@@ -811,13 +813,13 @@ static int btree_next(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeNext(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",res);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -845,13 +847,13 @@ static int btree_prev(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreePrevious(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",res);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -878,13 +880,13 @@ static int btree_first(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeFirst(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",res);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -911,13 +913,13 @@ static int btree_last(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3BtreeLast(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",res);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -942,8 +944,8 @@ static int btree_eof(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
sprintf(zBuf, "%d", sqlite3BtreeEof(pCur));
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", sqlite3BtreeEof(pCur));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -969,9 +971,9 @@ static int btree_keysize(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
sqlite3BtreeKeySize(pCur, &n);
|
||||
sprintf(zBuf, "%llu", n);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf, "%llu", n);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -997,11 +999,11 @@ static int btree_key(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
sqlite3BtreeKeySize(pCur, &n);
|
||||
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
|
||||
char zBuf2[60];
|
||||
sprintf(zBuf2, "%llu", n);
|
||||
sqlite3_snprintf(sizeof(zBuf2),zBuf2, "%llu", n);
|
||||
Tcl_AppendResult(interp, zBuf2, 0);
|
||||
}else{
|
||||
zBuf = malloc( n+1 );
|
||||
@@ -1018,7 +1020,7 @@ static int btree_key(
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_data ID
|
||||
** Usage: btree_data ID ?N?
|
||||
**
|
||||
** Return the data for the entry at which the cursor is pointing.
|
||||
*/
|
||||
@@ -1033,13 +1035,17 @@ static int btree_data(
|
||||
u32 n;
|
||||
char *zBuf;
|
||||
|
||||
if( argc!=2 ){
|
||||
if( argc!=2 && argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
sqlite3BtreeDataSize(pCur, &n);
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
if( argc==2 ){
|
||||
sqlite3BtreeDataSize(pCur, &n);
|
||||
}else{
|
||||
n = atoi(argv[2]);
|
||||
}
|
||||
zBuf = malloc( n+1 );
|
||||
rc = sqlite3BtreeData(pCur, 0, n, zBuf);
|
||||
if( rc ){
|
||||
@@ -1076,7 +1082,7 @@ static int btree_fetch_key(
|
||||
" ID AMT\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
|
||||
sqlite3BtreeKeySize(pCur, &nKey);
|
||||
zBuf = sqlite3BtreeKeyFetch(pCur, &amt);
|
||||
@@ -1114,7 +1120,7 @@ static int btree_fetch_data(
|
||||
" ID AMT\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
|
||||
sqlite3BtreeDataSize(pCur, &nData);
|
||||
zBuf = sqlite3BtreeDataFetch(pCur, &amt);
|
||||
@@ -1149,14 +1155,14 @@ static int btree_payload_size(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
|
||||
n1 = 0;
|
||||
}else{
|
||||
sqlite3BtreeKeySize(pCur, &n1);
|
||||
}
|
||||
sqlite3BtreeDataSize(pCur, &n2);
|
||||
sprintf(zBuf, "%d", (int)(n1+n2));
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", (int)(n1+n2));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -1196,7 +1202,7 @@ static int btree_cursor_info(
|
||||
" ID ?UP-CNT?\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
pCur = sqlite3TextToPtr(argv[1]);
|
||||
if( argc==3 ){
|
||||
if( Tcl_GetInt(interp, argv[2], &up) ) return TCL_ERROR;
|
||||
}else{
|
||||
@@ -1209,7 +1215,7 @@ static int btree_cursor_info(
|
||||
}
|
||||
j = 0;
|
||||
for(i=0; i<sizeof(aResult)/sizeof(aResult[0]); i++){
|
||||
sprintf(&zBuf[j]," %d", aResult[i]);
|
||||
sqlite3_snprintf(40,&zBuf[j]," %d", aResult[i]);
|
||||
j += strlen(&zBuf[j]);
|
||||
}
|
||||
Tcl_AppendResult(interp, &zBuf[1], 0);
|
||||
@@ -1318,6 +1324,72 @@ static int btree_varint_test(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** usage: btree_from_db DB-HANDLE
|
||||
**
|
||||
** This command returns the btree handle for the main database associated
|
||||
** with the database-handle passed as the argument. Example usage:
|
||||
**
|
||||
** sqlite3 db test.db
|
||||
** set bt [btree_from_db db]
|
||||
*/
|
||||
static int btree_from_db(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
char zBuf[100];
|
||||
Tcl_CmdInfo info;
|
||||
sqlite3 *db;
|
||||
Btree *pBt;
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" DB-HANDLE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if( 1!=Tcl_GetCommandInfo(interp, argv[1], &info) ){
|
||||
Tcl_AppendResult(interp, "No such db-handle: \"", argv[1], "\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
db = *((sqlite3 **)info.objClientData);
|
||||
assert( db );
|
||||
|
||||
pBt = db->aDb[0].pBt;
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", pBt);
|
||||
Tcl_SetResult(interp, zBuf, TCL_VOLATILE);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** usage: btree_set_cache_size ID NCACHE
|
||||
**
|
||||
** Set the size of the cache used by btree $ID.
|
||||
*/
|
||||
static int btree_set_cache_size(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int nCache;
|
||||
Btree *pBt;
|
||||
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" BT NCACHE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
pBt = sqlite3TextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR;
|
||||
sqlite3BtreeSetCacheSize(pBt, nCache);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
@@ -1364,6 +1436,8 @@ int Sqlitetest3_Init(Tcl_Interp *interp){
|
||||
{ "btree_begin_statement", (Tcl_CmdProc*)btree_begin_statement },
|
||||
{ "btree_commit_statement", (Tcl_CmdProc*)btree_commit_statement },
|
||||
{ "btree_rollback_statement", (Tcl_CmdProc*)btree_rollback_statement },
|
||||
{ "btree_from_db", (Tcl_CmdProc*)btree_from_db },
|
||||
{ "btree_set_cache_size", (Tcl_CmdProc*)btree_set_cache_size },
|
||||
};
|
||||
int i;
|
||||
|
||||
|
||||
+3
-6
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** Code for testing the the SQLite library in a multithreaded environment.
|
||||
**
|
||||
** $Id: test4.c,v 1.11 2004/08/08 20:22:18 drh Exp $
|
||||
** $Id: test4.c,v 1.13 2005/08/11 02:10:19 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
@@ -40,7 +40,7 @@ struct Thread {
|
||||
/* The next group of fields are writable by the thread but read-only to the
|
||||
** master. */
|
||||
int completed; /* Number of operations completed */
|
||||
sqlite *db; /* Open database */
|
||||
sqlite3 *db; /* Open database */
|
||||
sqlite3_stmt *pStmt; /* Pending operation */
|
||||
char *zErr; /* operation error */
|
||||
char *zStaticErr; /* Static error message */
|
||||
@@ -375,7 +375,6 @@ static int tcl_thread_result(
|
||||
switch( threadset[i].rc ){
|
||||
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
||||
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
||||
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
|
||||
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
||||
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
||||
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
||||
@@ -385,13 +384,11 @@ static int tcl_thread_result(
|
||||
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
||||
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
||||
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
|
||||
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
|
||||
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
|
||||
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
|
||||
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
|
||||
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
|
||||
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
|
||||
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
|
||||
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
|
||||
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
|
||||
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
|
||||
@@ -591,7 +588,7 @@ static int tcl_thread_swap(
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
int i, j;
|
||||
sqlite *temp;
|
||||
sqlite3 *temp;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID1 ID2", 0);
|
||||
|
||||
+3
-2
@@ -15,7 +15,7 @@
|
||||
** is used for testing the SQLite routines for converting between
|
||||
** the various supported unicode encodings.
|
||||
**
|
||||
** $Id: test5.c,v 1.13 2004/06/25 02:38:55 danielk1977 Exp $
|
||||
** $Id: test5.c,v 1.14 2004/11/14 21:56:30 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
@@ -190,7 +190,9 @@ static int test_translate_selftest(
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
sqlite3utfSelfTest();
|
||||
#endif
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -214,4 +216,3 @@ int Sqlitetest5_Init(Tcl_Interp *interp){
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
+121
-450
@@ -15,7 +15,7 @@
|
||||
** individual tokens and sends those tokens one-by-one over to the
|
||||
** parser for analysis.
|
||||
**
|
||||
** $Id: tokenize.c,v 1.84 2004/08/25 04:07:02 drh Exp $
|
||||
** $Id: tokenize.c,v 1.107 2005/08/23 11:31:26 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -23,170 +23,24 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
** All the keywords of the SQL language are stored as in a hash
|
||||
** table composed of instances of the following structure.
|
||||
*/
|
||||
typedef struct Keyword Keyword;
|
||||
struct Keyword {
|
||||
char *zName; /* The keyword name */
|
||||
u8 tokenType; /* Token value for this keyword */
|
||||
u8 len; /* Length of this keyword */
|
||||
u8 iNext; /* Index in aKeywordTable[] of next with same hash */
|
||||
};
|
||||
|
||||
/*
|
||||
** These are the keywords
|
||||
*/
|
||||
static Keyword aKeywordTable[] = {
|
||||
{ "ABORT", TK_ABORT, },
|
||||
{ "AFTER", TK_AFTER, },
|
||||
{ "ALL", TK_ALL, },
|
||||
{ "AND", TK_AND, },
|
||||
{ "AS", TK_AS, },
|
||||
{ "ASC", TK_ASC, },
|
||||
{ "ATTACH", TK_ATTACH, },
|
||||
{ "BEFORE", TK_BEFORE, },
|
||||
{ "BEGIN", TK_BEGIN, },
|
||||
{ "BETWEEN", TK_BETWEEN, },
|
||||
{ "BY", TK_BY, },
|
||||
{ "CASCADE", TK_CASCADE, },
|
||||
{ "CASE", TK_CASE, },
|
||||
{ "CHECK", TK_CHECK, },
|
||||
{ "CLUSTER", TK_CLUSTER, },
|
||||
{ "COLLATE", TK_COLLATE, },
|
||||
{ "COMMIT", TK_COMMIT, },
|
||||
{ "CONFLICT", TK_CONFLICT, },
|
||||
{ "CONSTRAINT", TK_CONSTRAINT, },
|
||||
{ "CREATE", TK_CREATE, },
|
||||
{ "CROSS", TK_JOIN_KW, },
|
||||
{ "DATABASE", TK_DATABASE, },
|
||||
{ "DEFAULT", TK_DEFAULT, },
|
||||
{ "DEFERRED", TK_DEFERRED, },
|
||||
{ "DEFERRABLE", TK_DEFERRABLE, },
|
||||
{ "DELETE", TK_DELETE, },
|
||||
{ "DESC", TK_DESC, },
|
||||
{ "DETACH", TK_DETACH, },
|
||||
{ "DISTINCT", TK_DISTINCT, },
|
||||
{ "DROP", TK_DROP, },
|
||||
{ "END", TK_END, },
|
||||
{ "EACH", TK_EACH, },
|
||||
{ "ELSE", TK_ELSE, },
|
||||
{ "EXCEPT", TK_EXCEPT, },
|
||||
{ "EXPLAIN", TK_EXPLAIN, },
|
||||
{ "FAIL", TK_FAIL, },
|
||||
{ "FOR", TK_FOR, },
|
||||
{ "FOREIGN", TK_FOREIGN, },
|
||||
{ "FROM", TK_FROM, },
|
||||
{ "FULL", TK_JOIN_KW, },
|
||||
{ "GLOB", TK_GLOB, },
|
||||
{ "GROUP", TK_GROUP, },
|
||||
{ "HAVING", TK_HAVING, },
|
||||
{ "IGNORE", TK_IGNORE, },
|
||||
{ "IMMEDIATE", TK_IMMEDIATE, },
|
||||
{ "IN", TK_IN, },
|
||||
{ "INDEX", TK_INDEX, },
|
||||
{ "INITIALLY", TK_INITIALLY, },
|
||||
{ "INNER", TK_JOIN_KW, },
|
||||
{ "INSERT", TK_INSERT, },
|
||||
{ "INSTEAD", TK_INSTEAD, },
|
||||
{ "INTERSECT", TK_INTERSECT, },
|
||||
{ "INTO", TK_INTO, },
|
||||
{ "IS", TK_IS, },
|
||||
{ "ISNULL", TK_ISNULL, },
|
||||
{ "JOIN", TK_JOIN, },
|
||||
{ "KEY", TK_KEY, },
|
||||
{ "LEFT", TK_JOIN_KW, },
|
||||
{ "LIKE", TK_LIKE, },
|
||||
{ "LIMIT", TK_LIMIT, },
|
||||
{ "MATCH", TK_MATCH, },
|
||||
{ "NATURAL", TK_JOIN_KW, },
|
||||
{ "NOT", TK_NOT, },
|
||||
{ "NOTNULL", TK_NOTNULL, },
|
||||
{ "NULL", TK_NULL, },
|
||||
{ "OF", TK_OF, },
|
||||
{ "OFFSET", TK_OFFSET, },
|
||||
{ "ON", TK_ON, },
|
||||
{ "OR", TK_OR, },
|
||||
{ "ORDER", TK_ORDER, },
|
||||
{ "OUTER", TK_JOIN_KW, },
|
||||
{ "PRAGMA", TK_PRAGMA, },
|
||||
{ "PRIMARY", TK_PRIMARY, },
|
||||
{ "RAISE", TK_RAISE, },
|
||||
{ "REFERENCES", TK_REFERENCES, },
|
||||
{ "REPLACE", TK_REPLACE, },
|
||||
{ "RESTRICT", TK_RESTRICT, },
|
||||
{ "RIGHT", TK_JOIN_KW, },
|
||||
{ "ROLLBACK", TK_ROLLBACK, },
|
||||
{ "ROW", TK_ROW, },
|
||||
{ "SELECT", TK_SELECT, },
|
||||
{ "SET", TK_SET, },
|
||||
{ "STATEMENT", TK_STATEMENT, },
|
||||
{ "TABLE", TK_TABLE, },
|
||||
{ "TEMP", TK_TEMP, },
|
||||
{ "TEMPORARY", TK_TEMP, },
|
||||
{ "THEN", TK_THEN, },
|
||||
{ "TRANSACTION", TK_TRANSACTION, },
|
||||
{ "TRIGGER", TK_TRIGGER, },
|
||||
{ "UNION", TK_UNION, },
|
||||
{ "UNIQUE", TK_UNIQUE, },
|
||||
{ "UPDATE", TK_UPDATE, },
|
||||
{ "USING", TK_USING, },
|
||||
{ "VACUUM", TK_VACUUM, },
|
||||
{ "VALUES", TK_VALUES, },
|
||||
{ "VIEW", TK_VIEW, },
|
||||
{ "WHEN", TK_WHEN, },
|
||||
{ "WHERE", TK_WHERE, },
|
||||
};
|
||||
|
||||
/*
|
||||
** This is the hash table
|
||||
*/
|
||||
#define KEY_HASH_SIZE 101
|
||||
static u8 aiHashTable[KEY_HASH_SIZE];
|
||||
|
||||
|
||||
/*
|
||||
** This function looks up an identifier to determine if it is a
|
||||
** keyword. If it is a keyword, the token code of that keyword is
|
||||
** The sqlite3KeywordCode function looks up an identifier to determine if
|
||||
** it is a keyword. If it is a keyword, the token code of that keyword is
|
||||
** returned. If the input is not a keyword, TK_ID is returned.
|
||||
**
|
||||
** The implementation of this routine was generated by a program,
|
||||
** mkkeywordhash.h, located in the tool subdirectory of the distribution.
|
||||
** The output of the mkkeywordhash.c program is written into a file
|
||||
** named keywordhash.h and then included into this source file by
|
||||
** the #include below.
|
||||
*/
|
||||
int sqlite3KeywordCode(const char *z, int n){
|
||||
int h, i;
|
||||
Keyword *p;
|
||||
static char needInit = 1;
|
||||
if( needInit ){
|
||||
/* Initialize the keyword hash table */
|
||||
sqlite3OsEnterMutex();
|
||||
if( needInit ){
|
||||
int nk;
|
||||
nk = sizeof(aKeywordTable)/sizeof(aKeywordTable[0]);
|
||||
for(i=0; i<nk; i++){
|
||||
aKeywordTable[i].len = strlen(aKeywordTable[i].zName);
|
||||
h = sqlite3HashNoCase(aKeywordTable[i].zName, aKeywordTable[i].len);
|
||||
h %= KEY_HASH_SIZE;
|
||||
aKeywordTable[i].iNext = aiHashTable[h];
|
||||
aiHashTable[h] = i+1;
|
||||
}
|
||||
needInit = 0;
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
h = sqlite3HashNoCase(z, n) % KEY_HASH_SIZE;
|
||||
for(i=aiHashTable[h]; i; i=p->iNext){
|
||||
p = &aKeywordTable[i-1];
|
||||
if( p->len==n && sqlite3StrNICmp(p->zName, z, n)==0 ){
|
||||
return p->tokenType;
|
||||
}
|
||||
}
|
||||
return TK_ID;
|
||||
}
|
||||
#include "keywordhash.h"
|
||||
|
||||
|
||||
/*
|
||||
** If X is a character that can be used in an identifier and
|
||||
** X&0x80==0 then isIdChar[X] will be 1. If X&0x80==0x80 then
|
||||
** X&0x80==0 then sqlite3IsIdChar[X] will be 1. If X&0x80==0x80 then
|
||||
** X is always an identifier character. (Hence all UTF-8
|
||||
** characters can be part of an identifier). isIdChar[X] will
|
||||
** characters can be part of an identifier). sqlite3IsIdChar[X] will
|
||||
** be 0 for every character in the lower 128 ASCII characters
|
||||
** that cannot be used as part of an identifier.
|
||||
**
|
||||
@@ -195,12 +49,15 @@ int sqlite3KeywordCode(const char *z, int n){
|
||||
** with the high-order bit set. The latter rule means that
|
||||
** any sequence of UTF-8 characters or characters taken from
|
||||
** an extended ISO8859 character set can form an identifier.
|
||||
**
|
||||
** Ticket #1066. the SQL standard does not allow '$' in the
|
||||
** middle of identfiers. But many SQL implementations do.
|
||||
** SQLite will allow '$' in identifiers for compatibility.
|
||||
** But the feature is undocumented.
|
||||
*/
|
||||
static const char isIdChar[] = {
|
||||
const char sqlite3IsIdChar[] = {
|
||||
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
|
||||
@@ -208,13 +65,14 @@ static const char isIdChar[] = {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
|
||||
};
|
||||
|
||||
#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20]))
|
||||
|
||||
/*
|
||||
** Return the length of the token that begins at z[0].
|
||||
** Store the token type in *tokenType before returning.
|
||||
*/
|
||||
static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
int i;
|
||||
static int getToken(const unsigned char *z, int *tokenType){
|
||||
int i, c;
|
||||
switch( *z ){
|
||||
case ' ': case '\t': case '\n': case '\f': case '\r': {
|
||||
for(i=1; isspace(z[i]); i++){}
|
||||
@@ -223,7 +81,7 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
}
|
||||
case '-': {
|
||||
if( z[1]=='-' ){
|
||||
for(i=2; z[i] && z[i]!='\n'; i++){}
|
||||
for(i=2; (c=z[i])!=0 && c!='\n'; i++){}
|
||||
*tokenType = TK_COMMENT;
|
||||
return i;
|
||||
}
|
||||
@@ -255,8 +113,8 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
*tokenType = TK_SLASH;
|
||||
return 1;
|
||||
}
|
||||
for(i=3; z[i] && (z[i]!='/' || z[i-1]!='*'); i++){}
|
||||
if( z[i] ) i++;
|
||||
for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){}
|
||||
if( c ) i++;
|
||||
*tokenType = TK_COMMENT;
|
||||
return i;
|
||||
}
|
||||
@@ -269,13 +127,13 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
return 1 + (z[1]=='=');
|
||||
}
|
||||
case '<': {
|
||||
if( z[1]=='=' ){
|
||||
if( (c=z[1])=='=' ){
|
||||
*tokenType = TK_LE;
|
||||
return 2;
|
||||
}else if( z[1]=='>' ){
|
||||
}else if( c=='>' ){
|
||||
*tokenType = TK_NE;
|
||||
return 2;
|
||||
}else if( z[1]=='<' ){
|
||||
}else if( c=='<' ){
|
||||
*tokenType = TK_LSHIFT;
|
||||
return 2;
|
||||
}else{
|
||||
@@ -284,10 +142,10 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
}
|
||||
}
|
||||
case '>': {
|
||||
if( z[1]=='=' ){
|
||||
if( (c=z[1])=='=' ){
|
||||
*tokenType = TK_GE;
|
||||
return 2;
|
||||
}else if( z[1]=='>' ){
|
||||
}else if( c=='>' ){
|
||||
*tokenType = TK_RSHIFT;
|
||||
return 2;
|
||||
}else{
|
||||
@@ -325,10 +183,12 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
*tokenType = TK_BITNOT;
|
||||
return 1;
|
||||
}
|
||||
case '\'': case '"': {
|
||||
case '`':
|
||||
case '\'':
|
||||
case '"': {
|
||||
int delim = z[0];
|
||||
for(i=1; z[i]; i++){
|
||||
if( z[i]==delim ){
|
||||
for(i=1; (c=z[i])!=0; i++){
|
||||
if( c==delim ){
|
||||
if( z[i+1]==delim ){
|
||||
i++;
|
||||
}else{
|
||||
@@ -336,20 +196,28 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
}
|
||||
}
|
||||
}
|
||||
if( z[i] ) i++;
|
||||
if( c ) i++;
|
||||
*tokenType = TK_STRING;
|
||||
return i;
|
||||
}
|
||||
case '.': {
|
||||
*tokenType = TK_DOT;
|
||||
return 1;
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
if( !isdigit(z[1]) )
|
||||
#endif
|
||||
{
|
||||
*tokenType = TK_DOT;
|
||||
return 1;
|
||||
}
|
||||
/* If the next character is a digit, this is a floating point
|
||||
** number that begins with ".". Fall thru into the next case */
|
||||
}
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9': {
|
||||
*tokenType = TK_INTEGER;
|
||||
for(i=1; isdigit(z[i]); i++){}
|
||||
if( z[i]=='.' && isdigit(z[i+1]) ){
|
||||
i += 2;
|
||||
for(i=0; isdigit(z[i]); i++){}
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
if( z[i]=='.' ){
|
||||
i++;
|
||||
while( isdigit(z[i]) ){ i++; }
|
||||
*tokenType = TK_FLOAT;
|
||||
}
|
||||
@@ -362,91 +230,96 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
while( isdigit(z[i]) ){ i++; }
|
||||
*tokenType = TK_FLOAT;
|
||||
}
|
||||
#endif
|
||||
return i;
|
||||
}
|
||||
case '[': {
|
||||
for(i=1; z[i] && z[i-1]!=']'; i++){}
|
||||
for(i=1, c=z[0]; c!=']' && (c=z[i])!=0; i++){}
|
||||
*tokenType = TK_ID;
|
||||
return i;
|
||||
}
|
||||
case '?': {
|
||||
*tokenType = TK_VARIABLE;
|
||||
return 1;
|
||||
}
|
||||
case ':': {
|
||||
for(i=1; (z[i]&0x80)!=0 || isIdChar[z[i]]; i++){}
|
||||
*tokenType = i>1 ? TK_VARIABLE : TK_ILLEGAL;
|
||||
for(i=1; isdigit(z[i]); i++){}
|
||||
return i;
|
||||
}
|
||||
case '$': {
|
||||
int c;
|
||||
case '#': {
|
||||
for(i=1; isdigit(z[i]); i++){}
|
||||
if( i>1 ){
|
||||
/* Parameters of the form #NNN (where NNN is a number) are used
|
||||
** internally by sqlite3NestedParse. */
|
||||
*tokenType = TK_REGISTER;
|
||||
return i;
|
||||
}
|
||||
/* Fall through into the next case if the '#' is not followed by
|
||||
** a digit. Try to match #AAAA where AAAA is a parameter name. */
|
||||
}
|
||||
#ifndef SQLITE_OMIT_TCL_VARIABLE
|
||||
case '$':
|
||||
#endif
|
||||
case ':': {
|
||||
int n = 0;
|
||||
*tokenType = TK_VARIABLE;
|
||||
if( z[1]=='{' ){
|
||||
int nBrace = 1;
|
||||
for(i=2; (c=z[i])!=0 && nBrace; i++){
|
||||
if( c=='{' ){
|
||||
nBrace++;
|
||||
}else if( c=='}' ){
|
||||
nBrace--;
|
||||
}
|
||||
}
|
||||
if( c==0 ) *tokenType = TK_ILLEGAL;
|
||||
}else{
|
||||
int n = 0;
|
||||
for(i=1; (c=z[i])!=0; i++){
|
||||
if( isalnum(c) || c=='_' ){
|
||||
n++;
|
||||
}else if( c=='(' && n>0 ){
|
||||
do{
|
||||
i++;
|
||||
}while( (c=z[i])!=0 && !isspace(c) && c!=')' );
|
||||
if( c==')' ){
|
||||
i++;
|
||||
}else{
|
||||
*tokenType = TK_ILLEGAL;
|
||||
}
|
||||
break;
|
||||
}else if( c==':' && z[i+1]==':' ){
|
||||
for(i=1; (c=z[i])!=0; i++){
|
||||
if( IdChar(c) ){
|
||||
n++;
|
||||
#ifndef SQLITE_OMIT_TCL_VARIABLE
|
||||
}else if( c=='(' && n>0 ){
|
||||
do{
|
||||
i++;
|
||||
}while( (c=z[i])!=0 && !isspace(c) && c!=')' );
|
||||
if( c==')' ){
|
||||
i++;
|
||||
}else{
|
||||
break;
|
||||
*tokenType = TK_ILLEGAL;
|
||||
}
|
||||
break;
|
||||
}else if( c==':' && z[i+1]==':' ){
|
||||
i++;
|
||||
#endif
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
if( n==0 ) *tokenType = TK_ILLEGAL;
|
||||
}
|
||||
if( n==0 ) *tokenType = TK_ILLEGAL;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_BLOB_LITERAL
|
||||
case 'x': case 'X': {
|
||||
if( z[1]=='\'' || z[1]=='"' ){
|
||||
int delim = z[1];
|
||||
if( (c=z[1])=='\'' || c=='"' ){
|
||||
int delim = c;
|
||||
*tokenType = TK_BLOB;
|
||||
for(i=2; z[i]; i++){
|
||||
if( z[i]==delim ){
|
||||
for(i=2; (c=z[i])!=0; i++){
|
||||
if( c==delim ){
|
||||
if( i%2 ) *tokenType = TK_ILLEGAL;
|
||||
break;
|
||||
}
|
||||
if( !isxdigit(z[i]) ){
|
||||
if( !isxdigit(c) ){
|
||||
*tokenType = TK_ILLEGAL;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
if( z[i] ) i++;
|
||||
if( c ) i++;
|
||||
return i;
|
||||
}
|
||||
/* Otherwise fall through to the next case */
|
||||
}
|
||||
#endif
|
||||
default: {
|
||||
if( (*z&0x80)==0 && !isIdChar[*z] ){
|
||||
if( !IdChar(*z) ){
|
||||
break;
|
||||
}
|
||||
for(i=1; (z[i]&0x80)!=0 || isIdChar[z[i]]; i++){}
|
||||
*tokenType = sqlite3KeywordCode((char*)z, i);
|
||||
for(i=1; IdChar(z[i]); i++){}
|
||||
*tokenType = keywordCode((char*)z, i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
*tokenType = TK_ILLEGAL;
|
||||
return 1;
|
||||
}
|
||||
int sqlite3GetToken(const unsigned char *z, int *tokenType){
|
||||
return getToken(z, tokenType);
|
||||
}
|
||||
|
||||
/*
|
||||
** Run the parser on the given SQL string. The parser structure is
|
||||
@@ -461,7 +334,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
void *pEngine;
|
||||
int tokenType;
|
||||
int lastTokenParsed = -1;
|
||||
sqlite *db = pParse->db;
|
||||
sqlite3 *db = pParse->db;
|
||||
extern void *sqlite3ParserAlloc(void*(*)(int));
|
||||
extern void sqlite3ParserFree(void*, void(*)(void*));
|
||||
extern int sqlite3Parser(void*, int, Token, Parse*);
|
||||
@@ -469,18 +342,24 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
db->flags &= ~SQLITE_Interrupt;
|
||||
pParse->rc = SQLITE_OK;
|
||||
i = 0;
|
||||
pEngine = sqlite3ParserAlloc((void*(*)(int))malloc);
|
||||
pEngine = sqlite3ParserAlloc((void*(*)(int))sqlite3MallocX);
|
||||
if( pEngine==0 ){
|
||||
sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
|
||||
return 1;
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pParse->sLastToken.dyn = 0;
|
||||
assert( pParse->sLastToken.dyn==0 );
|
||||
assert( pParse->pNewTable==0 );
|
||||
assert( pParse->pNewTrigger==0 );
|
||||
assert( pParse->nVar==0 );
|
||||
assert( pParse->nVarExpr==0 );
|
||||
assert( pParse->nVarExprAlloc==0 );
|
||||
assert( pParse->apVarExpr==0 );
|
||||
pParse->zTail = pParse->zSql = zSql;
|
||||
while( sqlite3_malloc_failed==0 && zSql[i]!=0 ){
|
||||
assert( i>=0 );
|
||||
pParse->sLastToken.z = &zSql[i];
|
||||
assert( pParse->sLastToken.dyn==0 );
|
||||
pParse->sLastToken.n = sqliteGetToken((unsigned char*)&zSql[i], &tokenType);
|
||||
pParse->sLastToken.n = getToken((unsigned char*)&zSql[i],&tokenType);
|
||||
i += pParse->sLastToken.n;
|
||||
switch( tokenType ){
|
||||
case TK_SPACE:
|
||||
@@ -493,8 +372,11 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
break;
|
||||
}
|
||||
case TK_ILLEGAL: {
|
||||
sqlite3SetNString(pzErrMsg, "unrecognized token: \"", -1,
|
||||
pParse->sLastToken.z, pParse->sLastToken.n, "\"", 1, 0);
|
||||
if( pzErrMsg ){
|
||||
sqliteFree(*pzErrMsg);
|
||||
*pzErrMsg = sqlite3MPrintf("unrecognized token: \"%T\"",
|
||||
&pParse->sLastToken);
|
||||
}
|
||||
nErr++;
|
||||
goto abort_parse;
|
||||
}
|
||||
@@ -520,7 +402,7 @@ abort_parse:
|
||||
}
|
||||
sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
|
||||
}
|
||||
sqlite3ParserFree(pEngine, free);
|
||||
sqlite3ParserFree(pEngine, sqlite3FreeX);
|
||||
if( sqlite3_malloc_failed ){
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
}
|
||||
@@ -537,226 +419,15 @@ abort_parse:
|
||||
pParse->zErrMsg = 0;
|
||||
if( !nErr ) nErr++;
|
||||
}
|
||||
if( pParse->pVdbe && pParse->nErr>0 ){
|
||||
if( pParse->pVdbe && pParse->nErr>0 && pParse->nested==0 ){
|
||||
sqlite3VdbeDelete(pParse->pVdbe);
|
||||
pParse->pVdbe = 0;
|
||||
}
|
||||
if( pParse->pNewTable ){
|
||||
sqlite3DeleteTable(pParse->db, pParse->pNewTable);
|
||||
pParse->pNewTable = 0;
|
||||
}
|
||||
if( pParse->pNewTrigger ){
|
||||
sqlite3DeleteTrigger(pParse->pNewTrigger);
|
||||
pParse->pNewTrigger = 0;
|
||||
}
|
||||
sqlite3DeleteTable(pParse->db, pParse->pNewTable);
|
||||
sqlite3DeleteTrigger(pParse->pNewTrigger);
|
||||
sqliteFree(pParse->apVarExpr);
|
||||
if( nErr>0 && (pParse->rc==SQLITE_OK || pParse->rc==SQLITE_DONE) ){
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
return nErr;
|
||||
}
|
||||
|
||||
/*
|
||||
** Token types used by the sqlite3_complete() routine. See the header
|
||||
** comments on that procedure for additional information.
|
||||
*/
|
||||
#define tkEXPLAIN 0
|
||||
#define tkCREATE 1
|
||||
#define tkTEMP 2
|
||||
#define tkTRIGGER 3
|
||||
#define tkEND 4
|
||||
#define tkSEMI 5
|
||||
#define tkWS 6
|
||||
#define tkOTHER 7
|
||||
|
||||
/*
|
||||
** Return TRUE if the given SQL string ends in a semicolon.
|
||||
**
|
||||
** Special handling is require for CREATE TRIGGER statements.
|
||||
** Whenever the CREATE TRIGGER keywords are seen, the statement
|
||||
** must end with ";END;".
|
||||
**
|
||||
** This implementation uses a state machine with 7 states:
|
||||
**
|
||||
** (0) START At the beginning or end of an SQL statement. This routine
|
||||
** returns 1 if it ends in the START state and 0 if it ends
|
||||
** in any other state.
|
||||
**
|
||||
** (1) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
|
||||
** a statement.
|
||||
**
|
||||
** (2) CREATE The keyword CREATE has been seen at the beginning of a
|
||||
** statement, possibly preceeded by EXPLAIN and/or followed by
|
||||
** TEMP or TEMPORARY
|
||||
**
|
||||
** (3) NORMAL We are in the middle of statement which ends with a single
|
||||
** semicolon.
|
||||
**
|
||||
** (4) TRIGGER We are in the middle of a trigger definition that must be
|
||||
** ended by a semicolon, the keyword END, and another semicolon.
|
||||
**
|
||||
** (5) SEMI We've seen the first semicolon in the ";END;" that occurs at
|
||||
** the end of a trigger definition.
|
||||
**
|
||||
** (6) END We've seen the ";END" of the ";END;" that occurs at the end
|
||||
** of a trigger difinition.
|
||||
**
|
||||
** Transitions between states above are determined by tokens extracted
|
||||
** from the input. The following tokens are significant:
|
||||
**
|
||||
** (0) tkEXPLAIN The "explain" keyword.
|
||||
** (1) tkCREATE The "create" keyword.
|
||||
** (2) tkTEMP The "temp" or "temporary" keyword.
|
||||
** (3) tkTRIGGER The "trigger" keyword.
|
||||
** (4) tkEND The "end" keyword.
|
||||
** (5) tkSEMI A semicolon.
|
||||
** (6) tkWS Whitespace
|
||||
** (7) tkOTHER Any other SQL token.
|
||||
**
|
||||
** Whitespace never causes a state transition and is always ignored.
|
||||
*/
|
||||
int sqlite3_complete(const char *zSql){
|
||||
u8 state = 0; /* Current state, using numbers defined in header comment */
|
||||
u8 token; /* Value of the next token */
|
||||
|
||||
/* The following matrix defines the transition from one state to another
|
||||
** according to what token is seen. trans[state][token] returns the
|
||||
** next state.
|
||||
*/
|
||||
static const u8 trans[7][8] = {
|
||||
/* Token: */
|
||||
/* State: ** EXPLAIN CREATE TEMP TRIGGER END SEMI WS OTHER */
|
||||
/* 0 START: */ { 1, 2, 3, 3, 3, 0, 0, 3, },
|
||||
/* 1 EXPLAIN: */ { 3, 2, 3, 3, 3, 0, 1, 3, },
|
||||
/* 2 CREATE: */ { 3, 3, 2, 4, 3, 0, 2, 3, },
|
||||
/* 3 NORMAL: */ { 3, 3, 3, 3, 3, 0, 3, 3, },
|
||||
/* 4 TRIGGER: */ { 4, 4, 4, 4, 4, 5, 4, 4, },
|
||||
/* 5 SEMI: */ { 4, 4, 4, 4, 6, 5, 5, 4, },
|
||||
/* 6 END: */ { 4, 4, 4, 4, 4, 0, 6, 4, },
|
||||
};
|
||||
|
||||
while( *zSql ){
|
||||
switch( *zSql ){
|
||||
case ';': { /* A semicolon */
|
||||
token = tkSEMI;
|
||||
break;
|
||||
}
|
||||
case ' ':
|
||||
case '\r':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\f': { /* White space is ignored */
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '/': { /* C-style comments */
|
||||
if( zSql[1]!='*' ){
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
zSql += 2;
|
||||
while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
|
||||
if( zSql[0]==0 ) return 0;
|
||||
zSql++;
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '-': { /* SQL-style comments from "--" to end of line */
|
||||
if( zSql[1]!='-' ){
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
while( *zSql && *zSql!='\n' ){ zSql++; }
|
||||
if( *zSql==0 ) return state==0;
|
||||
token = tkWS;
|
||||
break;
|
||||
}
|
||||
case '[': { /* Microsoft-style identifiers in [...] */
|
||||
zSql++;
|
||||
while( *zSql && *zSql!=']' ){ zSql++; }
|
||||
if( *zSql==0 ) return 0;
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
case '"': /* single- and double-quoted strings */
|
||||
case '\'': {
|
||||
int c = *zSql;
|
||||
zSql++;
|
||||
while( *zSql && *zSql!=c ){ zSql++; }
|
||||
if( *zSql==0 ) return 0;
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if( isIdChar[(u8)*zSql] ){
|
||||
/* Keywords and unquoted identifiers */
|
||||
int nId;
|
||||
for(nId=1; isIdChar[(u8)zSql[nId]]; nId++){}
|
||||
switch( *zSql ){
|
||||
case 'c': case 'C': {
|
||||
if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
|
||||
token = tkCREATE;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 't': case 'T': {
|
||||
if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
|
||||
token = tkTRIGGER;
|
||||
}else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
|
||||
token = tkTEMP;
|
||||
}else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
|
||||
token = tkTEMP;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'e': case 'E': {
|
||||
if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
|
||||
token = tkEND;
|
||||
}else if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
|
||||
token = tkEXPLAIN;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
token = tkOTHER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
zSql += nId-1;
|
||||
}else{
|
||||
/* Operators and special symbols */
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
state = trans[state][token];
|
||||
zSql++;
|
||||
}
|
||||
return state==0;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is the same as the sqlite3_complete() routine described
|
||||
** above, except that the parameter is required to be UTF-16 encoded, not
|
||||
** UTF-8.
|
||||
*/
|
||||
int sqlite3_complete16(const void *zSql){
|
||||
sqlite3_value *pVal;
|
||||
char const *zSql8;
|
||||
int rc = 0;
|
||||
|
||||
pVal = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
if( zSql8 ){
|
||||
rc = sqlite3_complete(zSql8);
|
||||
}
|
||||
sqlite3ValueFree(pVal);
|
||||
return rc;
|
||||
}
|
||||
|
||||
+118
-123
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/*
|
||||
** Delete a linked list of TriggerStep structures.
|
||||
*/
|
||||
@@ -50,10 +51,10 @@ void sqlite3BeginTrigger(
|
||||
Expr *pWhen, /* WHEN clause */
|
||||
int isTemp /* True if the TEMPORARY keyword is present */
|
||||
){
|
||||
Trigger *pTrigger;
|
||||
Trigger *pTrigger = 0;
|
||||
Table *pTab;
|
||||
char *zName = 0; /* Name of the trigger */
|
||||
sqlite *db = pParse->db;
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb; /* The database to store the trigger in */
|
||||
Token *pName; /* The unqualified db name */
|
||||
DbFixer sFix;
|
||||
@@ -110,9 +111,7 @@ void sqlite3BeginTrigger(
|
||||
}
|
||||
|
||||
/* Do not create a trigger on a system table */
|
||||
if( (iDb!=1 && sqlite3StrICmp(pTab->zName, MASTER_NAME)==0) ||
|
||||
(iDb==1 && sqlite3StrICmp(pTab->zName, TEMP_MASTER_NAME)==0)
|
||||
){
|
||||
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
|
||||
sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
|
||||
pParse->nErr++;
|
||||
goto trigger_cleanup;
|
||||
@@ -162,11 +161,10 @@ void sqlite3BeginTrigger(
|
||||
pTrigger->name = zName;
|
||||
zName = 0;
|
||||
pTrigger->table = sqliteStrDup(pTableName->a[0].zName);
|
||||
if( sqlite3_malloc_failed ) goto trigger_cleanup;
|
||||
pTrigger->iDb = iDb;
|
||||
pTrigger->iTabDb = pTab->iDb;
|
||||
pTrigger->op = op;
|
||||
pTrigger->tr_tm = tr_tm;
|
||||
pTrigger->tr_tm = tr_tm==TK_BEFORE ? TRIGGER_BEFORE : TRIGGER_AFTER;
|
||||
pTrigger->pWhen = sqlite3ExprDup(pWhen);
|
||||
pTrigger->pColumns = sqlite3IdListDup(pColumns);
|
||||
pTrigger->foreach = foreach;
|
||||
@@ -179,6 +177,11 @@ trigger_cleanup:
|
||||
sqlite3SrcListDelete(pTableName);
|
||||
sqlite3IdListDelete(pColumns);
|
||||
sqlite3ExprDelete(pWhen);
|
||||
if( !pParse->pNewTrigger ){
|
||||
sqlite3DeleteTrigger(pTrigger);
|
||||
}else{
|
||||
assert( pParse->pNewTrigger==pTrigger );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -190,20 +193,20 @@ void sqlite3FinishTrigger(
|
||||
TriggerStep *pStepList, /* The triggered program */
|
||||
Token *pAll /* Token that describes the complete CREATE TRIGGER */
|
||||
){
|
||||
Trigger *nt = 0; /* The trigger whose construction is finishing up */
|
||||
sqlite *db = pParse->db; /* The database */
|
||||
Trigger *pTrig = 0; /* The trigger whose construction is finishing up */
|
||||
sqlite3 *db = pParse->db; /* The database */
|
||||
DbFixer sFix;
|
||||
|
||||
if( pParse->nErr || pParse->pNewTrigger==0 ) goto triggerfinish_cleanup;
|
||||
nt = pParse->pNewTrigger;
|
||||
pTrig = pParse->pNewTrigger;
|
||||
pParse->pNewTrigger = 0;
|
||||
nt->step_list = pStepList;
|
||||
if( pParse->nErr || pTrig==0 ) goto triggerfinish_cleanup;
|
||||
pTrig->step_list = pStepList;
|
||||
while( pStepList ){
|
||||
pStepList->pTrig = nt;
|
||||
pStepList->pTrig = pTrig;
|
||||
pStepList = pStepList->pNext;
|
||||
}
|
||||
if( sqlite3FixInit(&sFix, pParse, nt->iDb, "trigger", &nt->nameToken)
|
||||
&& sqlite3FixTriggerStep(&sFix, nt->step_list) ){
|
||||
if( sqlite3FixInit(&sFix, pParse, pTrig->iDb, "trigger", &pTrig->nameToken)
|
||||
&& sqlite3FixTriggerStep(&sFix, pTrig->step_list) ){
|
||||
goto triggerfinish_cleanup;
|
||||
}
|
||||
|
||||
@@ -211,8 +214,8 @@ void sqlite3FinishTrigger(
|
||||
** build the sqlite_master entry
|
||||
*/
|
||||
if( !db->init.busy ){
|
||||
static VdbeOpList insertTrig[] = {
|
||||
{ OP_NewRecno, 0, 0, 0 },
|
||||
static const VdbeOpList insertTrig[] = {
|
||||
{ OP_NewRowid, 0, 0, 0 },
|
||||
{ OP_String8, 0, 0, "trigger" },
|
||||
{ OP_String8, 0, 0, 0 }, /* 2: trigger name */
|
||||
{ OP_String8, 0, 0, 0 }, /* 3: table name */
|
||||
@@ -221,7 +224,7 @@ void sqlite3FinishTrigger(
|
||||
{ OP_String8, 0, 0, 0 }, /* 6: SQL */
|
||||
{ OP_Concat, 0, 0, 0 },
|
||||
{ OP_MakeRecord, 5, 0, "tttit" },
|
||||
{ OP_PutIntKey, 0, 0, 0 },
|
||||
{ OP_Insert, 0, 0, 0 },
|
||||
};
|
||||
int addr;
|
||||
Vdbe *v;
|
||||
@@ -229,36 +232,37 @@ void sqlite3FinishTrigger(
|
||||
/* Make an entry in the sqlite_master table */
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) goto triggerfinish_cleanup;
|
||||
sqlite3BeginWriteOperation(pParse, 0, nt->iDb);
|
||||
sqlite3OpenMasterTable(v, nt->iDb);
|
||||
sqlite3BeginWriteOperation(pParse, 0, pTrig->iDb);
|
||||
sqlite3OpenMasterTable(v, pTrig->iDb);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(insertTrig), insertTrig);
|
||||
sqlite3VdbeChangeP3(v, addr+2, nt->name, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+3, nt->table, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+2, pTrig->name, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+3, pTrig->table, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+6, pAll->z, pAll->n);
|
||||
if( nt->iDb!=0 ){
|
||||
sqlite3ChangeCookie(db, v, nt->iDb);
|
||||
}
|
||||
sqlite3ChangeCookie(db, v, pTrig->iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, nt->iDb, 0,
|
||||
sqlite3MPrintf("type='trigger' AND name='%q'", nt->name), P3_DYNAMIC);
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, pTrig->iDb, 0,
|
||||
sqlite3MPrintf("type='trigger' AND name='%q'", pTrig->name), P3_DYNAMIC);
|
||||
}
|
||||
|
||||
if( db->init.busy ){
|
||||
Table *pTab;
|
||||
sqlite3HashInsert(&db->aDb[nt->iDb].trigHash,
|
||||
nt->name, strlen(nt->name)+1, nt);
|
||||
pTab = sqlite3LocateTable(pParse, nt->table, db->aDb[nt->iTabDb].zName);
|
||||
Trigger *pDel;
|
||||
pDel = sqlite3HashInsert(&db->aDb[pTrig->iDb].trigHash,
|
||||
pTrig->name, strlen(pTrig->name)+1, pTrig);
|
||||
if( pDel ){
|
||||
assert( sqlite3_malloc_failed && pDel==pTrig );
|
||||
goto triggerfinish_cleanup;
|
||||
}
|
||||
pTab = sqlite3LocateTable(pParse,pTrig->table,db->aDb[pTrig->iTabDb].zName);
|
||||
assert( pTab!=0 );
|
||||
nt->pNext = pTab->pTrigger;
|
||||
pTab->pTrigger = nt;
|
||||
nt = 0;
|
||||
pTrig->pNext = pTab->pTrigger;
|
||||
pTab->pTrigger = pTrig;
|
||||
pTrig = 0;
|
||||
}
|
||||
|
||||
triggerfinish_cleanup:
|
||||
sqlite3DeleteTrigger(nt);
|
||||
sqlite3DeleteTrigger(pParse->pNewTrigger);
|
||||
pParse->pNewTrigger = 0;
|
||||
sqlite3DeleteTrigger(pTrig);
|
||||
assert( !pParse->pNewTrigger );
|
||||
sqlite3DeleteTriggerStep(pStepList);
|
||||
}
|
||||
|
||||
@@ -333,18 +337,23 @@ TriggerStep *sqlite3TriggerInsertStep(
|
||||
int orconf /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */
|
||||
){
|
||||
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
|
||||
if( pTriggerStep==0 ) return 0;
|
||||
|
||||
assert(pEList == 0 || pSelect == 0);
|
||||
assert(pEList != 0 || pSelect != 0);
|
||||
|
||||
pTriggerStep->op = TK_INSERT;
|
||||
pTriggerStep->pSelect = pSelect;
|
||||
pTriggerStep->target = *pTableName;
|
||||
pTriggerStep->pIdList = pColumn;
|
||||
pTriggerStep->pExprList = pEList;
|
||||
pTriggerStep->orconf = orconf;
|
||||
sqlitePersistTriggerStep(pTriggerStep);
|
||||
if( pTriggerStep ){
|
||||
pTriggerStep->op = TK_INSERT;
|
||||
pTriggerStep->pSelect = pSelect;
|
||||
pTriggerStep->target = *pTableName;
|
||||
pTriggerStep->pIdList = pColumn;
|
||||
pTriggerStep->pExprList = pEList;
|
||||
pTriggerStep->orconf = orconf;
|
||||
sqlitePersistTriggerStep(pTriggerStep);
|
||||
}else{
|
||||
sqlite3IdListDelete(pColumn);
|
||||
sqlite3ExprListDelete(pEList);
|
||||
sqlite3SelectDup(pSelect);
|
||||
}
|
||||
|
||||
return pTriggerStep;
|
||||
}
|
||||
@@ -419,7 +428,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
|
||||
const char *zDb;
|
||||
const char *zName;
|
||||
int nName;
|
||||
sqlite *db = pParse->db;
|
||||
sqlite3 *db = pParse->db;
|
||||
|
||||
if( sqlite3_malloc_failed ) goto drop_trigger_cleanup;
|
||||
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
|
||||
@@ -430,7 +439,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
|
||||
zDb = pName->a[0].zDatabase;
|
||||
zName = pName->a[0].zName;
|
||||
nName = strlen(zName);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
for(i=OMIT_TEMPDB; i<db->nDb; i++){
|
||||
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
|
||||
if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
|
||||
pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1);
|
||||
@@ -463,7 +472,7 @@ static Table *tableOfTrigger(sqlite3 *db, Trigger *pTrigger){
|
||||
void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
Table *pTable;
|
||||
Vdbe *v;
|
||||
sqlite *db = pParse->db;
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb;
|
||||
|
||||
iDb = pTrigger->iDb;
|
||||
@@ -488,12 +497,12 @@ void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
*/
|
||||
if( pTable!=0 && (v = sqlite3GetVdbe(pParse))!=0 ){
|
||||
int base;
|
||||
static VdbeOpList dropTrigger[] = {
|
||||
static const VdbeOpList dropTrigger[] = {
|
||||
{ OP_Rewind, 0, ADDR(9), 0},
|
||||
{ OP_String8, 0, 0, 0}, /* 1 */
|
||||
{ OP_String8, 0, 0, 0}, /* 1 */
|
||||
{ OP_Column, 0, 1, 0},
|
||||
{ OP_Ne, 0, ADDR(8), 0},
|
||||
{ OP_String8, 0, 0, "trigger"},
|
||||
{ OP_String8, 0, 0, "trigger"},
|
||||
{ OP_Column, 0, 0, 0},
|
||||
{ OP_Ne, 0, ADDR(8), 0},
|
||||
{ OP_Delete, 0, 0, 0},
|
||||
@@ -556,52 +565,38 @@ static int checkColumnOverLap(IdList *pIdList, ExprList *pEList){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A global variable that is TRUE if we should always set up temp tables for
|
||||
* for triggers, even if there are no triggers to code. This is used to test
|
||||
* how much overhead the triggers algorithm is causing.
|
||||
*
|
||||
* This flag can be set or cleared using the "trigger_overhead_test" pragma.
|
||||
* The pragma is not documented since it is not really part of the interface
|
||||
* to SQLite, just the test procedure.
|
||||
*/
|
||||
int sqlite3_always_code_trigger_setup = 0;
|
||||
|
||||
/*
|
||||
* Returns true if a trigger matching op, tr_tm and foreach that is NOT already
|
||||
* on the Parse objects trigger-stack (to prevent recursive trigger firing) is
|
||||
* found in the list specified as pTrigger.
|
||||
*/
|
||||
** Return a bit vector to indicate what kind of triggers exist for operation
|
||||
** "op" on table pTab. If pChanges is not NULL then it is a list of columns
|
||||
** that are being updated. Triggers only match if the ON clause of the
|
||||
** trigger definition overlaps the set of columns being updated.
|
||||
**
|
||||
** The returned bit vector is some combination of TRIGGER_BEFORE and
|
||||
** TRIGGER_AFTER.
|
||||
*/
|
||||
int sqlite3TriggersExist(
|
||||
Parse *pParse, /* Used to check for recursive triggers */
|
||||
Trigger *pTrigger, /* A list of triggers associated with a table */
|
||||
Table *pTab, /* The table the contains the triggers */
|
||||
int op, /* one of TK_DELETE, TK_INSERT, TK_UPDATE */
|
||||
int tr_tm, /* one of TK_BEFORE, TK_AFTER */
|
||||
int foreach, /* one of TK_ROW or TK_STATEMENT */
|
||||
ExprList *pChanges /* Columns that change in an UPDATE statement */
|
||||
){
|
||||
Trigger * pTriggerCursor;
|
||||
Trigger *pTrigger = pTab->pTrigger;
|
||||
int mask = 0;
|
||||
|
||||
if( sqlite3_always_code_trigger_setup ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
pTriggerCursor = pTrigger;
|
||||
while( pTriggerCursor ){
|
||||
if( pTriggerCursor->op == op &&
|
||||
pTriggerCursor->tr_tm == tr_tm &&
|
||||
pTriggerCursor->foreach == foreach &&
|
||||
checkColumnOverLap(pTriggerCursor->pColumns, pChanges) ){
|
||||
TriggerStack * ss;
|
||||
while( pTrigger ){
|
||||
if( pTrigger->op==op && checkColumnOverLap(pTrigger->pColumns, pChanges) ){
|
||||
TriggerStack *ss;
|
||||
ss = pParse->trigStack;
|
||||
while( ss && ss->pTrigger != pTrigger ){
|
||||
while( ss && ss->pTrigger!=pTab->pTrigger ){
|
||||
ss = ss->pNext;
|
||||
}
|
||||
if( !ss )return 1;
|
||||
if( ss==0 ){
|
||||
mask |= pTrigger->tr_tm;
|
||||
}
|
||||
}
|
||||
pTriggerCursor = pTriggerCursor->pNext;
|
||||
pTrigger = pTrigger->pNext;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return mask;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -645,7 +640,12 @@ static int codeTriggerProgram(
|
||||
){
|
||||
TriggerStep * pTriggerStep = pStepList;
|
||||
int orconf;
|
||||
Vdbe *v = pParse->pVdbe;
|
||||
|
||||
assert( pTriggerStep!=0 );
|
||||
assert( v!=0 );
|
||||
sqlite3VdbeAddOp(v, OP_ContextPush, 0, 0);
|
||||
VdbeComment((v, "# begin trigger %s", pStepList->pTrig->name));
|
||||
while( pTriggerStep ){
|
||||
orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
|
||||
pParse->trigStack->orconf = orconf;
|
||||
@@ -654,6 +654,7 @@ static int codeTriggerProgram(
|
||||
Select * ss = sqlite3SelectDup(pTriggerStep->pSelect);
|
||||
assert(ss);
|
||||
assert(ss->pSrc);
|
||||
sqlite3SelectResolve(pParse, ss, 0);
|
||||
sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(ss);
|
||||
break;
|
||||
@@ -661,34 +662,30 @@ static int codeTriggerProgram(
|
||||
case TK_UPDATE: {
|
||||
SrcList *pSrc;
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 0, 0);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
|
||||
sqlite3Update(pParse, pSrc,
|
||||
sqlite3ExprListDup(pTriggerStep->pExprList),
|
||||
sqlite3ExprDup(pTriggerStep->pWhere), orconf);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0);
|
||||
break;
|
||||
}
|
||||
case TK_INSERT: {
|
||||
SrcList *pSrc;
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
|
||||
sqlite3Insert(pParse, pSrc,
|
||||
sqlite3ExprListDup(pTriggerStep->pExprList),
|
||||
sqlite3SelectDup(pTriggerStep->pSelect),
|
||||
sqlite3IdListDup(pTriggerStep->pIdList), orconf);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0);
|
||||
break;
|
||||
}
|
||||
case TK_DELETE: {
|
||||
SrcList *pSrc;
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 0, 0);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqlite3DeleteFrom(pParse, pSrc, sqlite3ExprDup(pTriggerStep->pWhere));
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ResetCount, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -696,6 +693,8 @@ static int codeTriggerProgram(
|
||||
}
|
||||
pTriggerStep = pTriggerStep->pNext;
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_ContextPop, 0, 0);
|
||||
VdbeComment((v, "# end trigger %s", pStepList->pTrig->name));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -724,18 +723,19 @@ int sqlite3CodeRowTrigger(
|
||||
Parse *pParse, /* Parse context */
|
||||
int op, /* One of TK_UPDATE, TK_INSERT, TK_DELETE */
|
||||
ExprList *pChanges, /* Changes list for any UPDATE OF triggers */
|
||||
int tr_tm, /* One of TK_BEFORE, TK_AFTER */
|
||||
int tr_tm, /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
|
||||
Table *pTab, /* The table to code triggers from */
|
||||
int newIdx, /* The indice of the "new" row to access */
|
||||
int oldIdx, /* The indice of the "old" row to access */
|
||||
int orconf, /* ON CONFLICT policy */
|
||||
int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
|
||||
){
|
||||
Trigger * pTrigger;
|
||||
TriggerStack * pTriggerStack;
|
||||
Trigger *pTrigger;
|
||||
TriggerStack *pStack;
|
||||
TriggerStack trigStackEntry;
|
||||
|
||||
assert(op == TK_UPDATE || op == TK_INSERT || op == TK_DELETE);
|
||||
assert(tr_tm == TK_BEFORE || tr_tm == TK_AFTER );
|
||||
assert(tr_tm == TRIGGER_BEFORE || tr_tm == TRIGGER_AFTER );
|
||||
|
||||
assert(newIdx != -1 || oldIdx != -1);
|
||||
|
||||
@@ -744,60 +744,54 @@ int sqlite3CodeRowTrigger(
|
||||
int fire_this = 0;
|
||||
|
||||
/* determine whether we should code this trigger */
|
||||
if( pTrigger->op == op && pTrigger->tr_tm == tr_tm &&
|
||||
pTrigger->foreach == TK_ROW ){
|
||||
if( pTrigger->op == op && pTrigger->tr_tm == tr_tm ){
|
||||
fire_this = 1;
|
||||
pTriggerStack = pParse->trigStack;
|
||||
while( pTriggerStack ){
|
||||
if( pTriggerStack->pTrigger == pTrigger ){
|
||||
for(pStack=pParse->trigStack; pStack; pStack=pStack->pNext){
|
||||
if( pStack->pTrigger==pTrigger ){
|
||||
fire_this = 0;
|
||||
}
|
||||
pTriggerStack = pTriggerStack->pNext;
|
||||
}
|
||||
if( op == TK_UPDATE && pTrigger->pColumns &&
|
||||
!checkColumnOverLap(pTrigger->pColumns, pChanges) ){
|
||||
fire_this = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if( fire_this && (pTriggerStack = sqliteMalloc(sizeof(TriggerStack)))!=0 ){
|
||||
|
||||
if( fire_this ){
|
||||
int endTrigger;
|
||||
SrcList dummyTablist;
|
||||
Expr * whenExpr;
|
||||
AuthContext sContext;
|
||||
NameContext sNC;
|
||||
|
||||
dummyTablist.nSrc = 0;
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pParse;
|
||||
|
||||
/* Push an entry on to the trigger stack */
|
||||
pTriggerStack->pTrigger = pTrigger;
|
||||
pTriggerStack->newIdx = newIdx;
|
||||
pTriggerStack->oldIdx = oldIdx;
|
||||
pTriggerStack->pTab = pTab;
|
||||
pTriggerStack->pNext = pParse->trigStack;
|
||||
pTriggerStack->ignoreJump = ignoreJump;
|
||||
pParse->trigStack = pTriggerStack;
|
||||
trigStackEntry.pTrigger = pTrigger;
|
||||
trigStackEntry.newIdx = newIdx;
|
||||
trigStackEntry.oldIdx = oldIdx;
|
||||
trigStackEntry.pTab = pTab;
|
||||
trigStackEntry.pNext = pParse->trigStack;
|
||||
trigStackEntry.ignoreJump = ignoreJump;
|
||||
pParse->trigStack = &trigStackEntry;
|
||||
sqlite3AuthContextPush(pParse, &sContext, pTrigger->name);
|
||||
|
||||
/* code the WHEN clause */
|
||||
endTrigger = sqlite3VdbeMakeLabel(pParse->pVdbe);
|
||||
whenExpr = sqlite3ExprDup(pTrigger->pWhen);
|
||||
if( sqlite3ExprResolveIds(pParse, &dummyTablist, 0, whenExpr) ){
|
||||
pParse->trigStack = pParse->trigStack->pNext;
|
||||
sqliteFree(pTriggerStack);
|
||||
if( sqlite3ExprResolveNames(&sNC, whenExpr) ){
|
||||
pParse->trigStack = trigStackEntry.pNext;
|
||||
sqlite3ExprDelete(whenExpr);
|
||||
return 1;
|
||||
}
|
||||
sqlite3ExprIfFalse(pParse, whenExpr, endTrigger, 1);
|
||||
sqlite3ExprDelete(whenExpr);
|
||||
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ContextPush, 0, 0);
|
||||
codeTriggerProgram(pParse, pTrigger->step_list, orconf);
|
||||
sqlite3VdbeAddOp(pParse->pVdbe, OP_ContextPop, 0, 0);
|
||||
|
||||
/* Pop the entry off the trigger stack */
|
||||
pParse->trigStack = pParse->trigStack->pNext;
|
||||
pParse->trigStack = trigStackEntry.pNext;
|
||||
sqlite3AuthContextPop(&sContext);
|
||||
sqliteFree(pTriggerStack);
|
||||
|
||||
sqlite3VdbeResolveLabel(pParse->pVdbe, endTrigger);
|
||||
}
|
||||
@@ -805,3 +799,4 @@ int sqlite3CodeRowTrigger(
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
|
||||
|
||||
+122
-70
@@ -12,10 +12,49 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle UPDATE statements.
|
||||
**
|
||||
** $Id: update.c,v 1.87 2004/08/31 13:45:12 drh Exp $
|
||||
** $Id: update.c,v 1.112 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** The most recently coded instruction was an OP_Column to retrieve column
|
||||
** 'i' of table pTab. This routine sets the P3 parameter of the
|
||||
** OP_Column to the default value, if any.
|
||||
**
|
||||
** The default value of a column is specified by a DEFAULT clause in the
|
||||
** column definition. This was either supplied by the user when the table
|
||||
** was created, or added later to the table definition by an ALTER TABLE
|
||||
** command. If the latter, then the row-records in the table btree on disk
|
||||
** may not contain a value for the column and the default value, taken
|
||||
** from the P3 parameter of the OP_Column instruction, is returned instead.
|
||||
** If the former, then all row-records are guaranteed to include a value
|
||||
** for the column and the P3 value is not required.
|
||||
**
|
||||
** Column definitions created by an ALTER TABLE command may only have
|
||||
** literal default values specified: a number, null or a string. (If a more
|
||||
** complicated default expression value was provided, it is evaluated
|
||||
** when the ALTER TABLE is executed and one of the literal values written
|
||||
** into the sqlite_master table.)
|
||||
**
|
||||
** Therefore, the P3 parameter is only required if the default value for
|
||||
** the column is a literal number, string or null. The sqlite3ValueFromExpr()
|
||||
** function is capable of transforming these types of expressions into
|
||||
** sqlite3_value objects.
|
||||
*/
|
||||
void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i){
|
||||
if( pTab && !pTab->pSelect ){
|
||||
sqlite3_value *pValue;
|
||||
u8 enc = sqlite3VdbeDb(v)->enc;
|
||||
Column *pCol = &pTab->aCol[i];
|
||||
sqlite3ValueFromExpr(pCol->pDflt, enc, pCol->affinity, &pValue);
|
||||
if( pValue ){
|
||||
sqlite3VdbeChangeP3(v, -1, (const char *)pValue, P3_MEM);
|
||||
}else{
|
||||
VdbeComment((v, "# %s.%s", pTab->zName, pCol->zName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Process an UPDATE statement.
|
||||
**
|
||||
@@ -39,21 +78,22 @@ void sqlite3Update(
|
||||
int nIdx; /* Number of indices that need updating */
|
||||
int nIdxTotal; /* Total number of indices */
|
||||
int iCur; /* VDBE Cursor number of pTab */
|
||||
sqlite *db; /* The database structure */
|
||||
sqlite3 *db; /* The database structure */
|
||||
Index **apIdx = 0; /* An array of indices that need updating too */
|
||||
char *aIdxUsed = 0; /* aIdxUsed[i]==1 if the i-th index is used */
|
||||
int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
|
||||
** an expression for the i-th column of the table.
|
||||
** aXRef[i]==-1 if the i-th column is not changed. */
|
||||
int chngRecno; /* True if the record number is being changed */
|
||||
Expr *pRecnoExpr = 0; /* Expression defining the new record number */
|
||||
int chngRowid; /* True if the record number is being changed */
|
||||
Expr *pRowidExpr = 0; /* Expression defining the new record number */
|
||||
int openAll = 0; /* True if all indices need to be opened */
|
||||
int isView; /* Trying to update a view */
|
||||
AuthContext sContext; /* The authorization context */
|
||||
NameContext sNC; /* The name-context to resolve expressions in */
|
||||
|
||||
int before_triggers; /* True if there are any BEFORE triggers */
|
||||
int after_triggers; /* True if there are any AFTER triggers */
|
||||
int row_triggers_exist = 0; /* True if any row triggers exist */
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* Trying to update a view */
|
||||
int triggers_exist = 0; /* True if any row triggers exist */
|
||||
#endif
|
||||
|
||||
int newIdx = -1; /* index of trigger "new" temp table */
|
||||
int oldIdx = -1; /* index of trigger "old" temp table */
|
||||
@@ -67,13 +107,23 @@ void sqlite3Update(
|
||||
*/
|
||||
pTab = sqlite3SrcListLookup(pParse, pTabList);
|
||||
if( pTab==0 ) goto update_cleanup;
|
||||
before_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger,
|
||||
TK_UPDATE, TK_BEFORE, TK_ROW, pChanges);
|
||||
after_triggers = sqlite3TriggersExist(pParse, pTab->pTrigger,
|
||||
TK_UPDATE, TK_AFTER, TK_ROW, pChanges);
|
||||
row_triggers_exist = before_triggers || after_triggers;
|
||||
|
||||
/* Figure out if we have any triggers and if the table being
|
||||
** updated is a view
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges);
|
||||
isView = pTab->pSelect!=0;
|
||||
if( sqlite3IsReadOnly(pParse, pTab, before_triggers) ){
|
||||
#else
|
||||
# define triggers_exist 0
|
||||
# define isView 0
|
||||
#endif
|
||||
#ifdef SQLITE_OMIT_VIEW
|
||||
# undef isView
|
||||
# define isView 0
|
||||
#endif
|
||||
|
||||
if( sqlite3IsReadOnly(pParse, pTab, triggers_exist) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( isView ){
|
||||
@@ -88,7 +138,7 @@ void sqlite3Update(
|
||||
/* If there are FOR EACH ROW triggers, allocate cursors for the
|
||||
** special OLD and NEW tables
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist ){
|
||||
newIdx = pParse->nTab++;
|
||||
oldIdx = pParse->nTab++;
|
||||
}
|
||||
@@ -103,23 +153,27 @@ void sqlite3Update(
|
||||
pParse->nTab++;
|
||||
}
|
||||
|
||||
/* Initialize the name-context */
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pParse;
|
||||
sNC.pSrcList = pTabList;
|
||||
|
||||
/* Resolve the column names in all the expressions of the
|
||||
** of the UPDATE statement. Also find the column index
|
||||
** for each column to be updated in the pChanges array. For each
|
||||
** column to be updated, make sure we have authorization to change
|
||||
** that column.
|
||||
*/
|
||||
chngRecno = 0;
|
||||
chngRowid = 0;
|
||||
for(i=0; i<pChanges->nExpr; i++){
|
||||
if( sqlite3ExprResolveAndCheck(pParse, pTabList, 0,
|
||||
pChanges->a[i].pExpr, 0, 0) ){
|
||||
if( sqlite3ExprResolveNames(&sNC, pChanges->a[i].pExpr) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
for(j=0; j<pTab->nCol; j++){
|
||||
if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
|
||||
if( j==pTab->iPKey ){
|
||||
chngRecno = 1;
|
||||
pRecnoExpr = pChanges->a[i].pExpr;
|
||||
chngRowid = 1;
|
||||
pRowidExpr = pChanges->a[i].pExpr;
|
||||
}
|
||||
aXRef[j] = i;
|
||||
break;
|
||||
@@ -127,8 +181,8 @@ void sqlite3Update(
|
||||
}
|
||||
if( j>=pTab->nCol ){
|
||||
if( sqlite3IsRowid(pChanges->a[i].zName) ){
|
||||
chngRecno = 1;
|
||||
pRecnoExpr = pChanges->a[i].pExpr;
|
||||
chngRowid = 1;
|
||||
pRowidExpr = pChanges->a[i].pExpr;
|
||||
}else{
|
||||
sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
|
||||
goto update_cleanup;
|
||||
@@ -154,7 +208,7 @@ void sqlite3Update(
|
||||
** number of the original table entry is changing.
|
||||
*/
|
||||
for(nIdx=nIdxTotal=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdxTotal++){
|
||||
if( chngRecno ){
|
||||
if( chngRowid ){
|
||||
i = 0;
|
||||
}else {
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
@@ -169,7 +223,7 @@ void sqlite3Update(
|
||||
aIdxUsed = (char*)&apIdx[nIdx];
|
||||
}
|
||||
for(nIdx=j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
if( chngRecno ){
|
||||
if( chngRowid ){
|
||||
i = 0;
|
||||
}else{
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
@@ -188,7 +242,7 @@ void sqlite3Update(
|
||||
/* Resolve the column names in all the expressions in the
|
||||
** WHERE clause.
|
||||
*/
|
||||
if( sqlite3ExprResolveAndCheck(pParse, pTabList, 0, pWhere, 0, 0) ){
|
||||
if( sqlite3ExprResolveNames(&sNC, pWhere) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
|
||||
@@ -202,27 +256,28 @@ void sqlite3Update(
|
||||
*/
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) goto update_cleanup;
|
||||
sqlite3VdbeCountChanges(v);
|
||||
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
|
||||
sqlite3BeginWriteOperation(pParse, 1, pTab->iDb);
|
||||
|
||||
/* If we are trying to update a view, construct that view into
|
||||
** a temporary table.
|
||||
/* If we are trying to update a view, realize that view into
|
||||
** a ephemeral table.
|
||||
*/
|
||||
if( isView ){
|
||||
Select *pView;
|
||||
pView = sqlite3SelectDup(pTab->pSelect);
|
||||
sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0);
|
||||
sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(pView);
|
||||
}
|
||||
|
||||
/* Begin the database scan
|
||||
*/
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 1, 0);
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0);
|
||||
if( pWInfo==0 ) goto update_cleanup;
|
||||
|
||||
/* Remember the index of every item to be updated.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0);
|
||||
|
||||
/* End the database scan loop.
|
||||
*/
|
||||
@@ -234,7 +289,7 @@ void sqlite3Update(
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
}
|
||||
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist ){
|
||||
/* Create pseudo-tables for NEW and OLD
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
@@ -244,44 +299,42 @@ void sqlite3Update(
|
||||
|
||||
/* The top of the update loop for when there are triggers.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0);
|
||||
|
||||
/* Open a cursor and make it point to the record that is
|
||||
** being updated.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
/* Open a cursor and make it point to the record that is
|
||||
** being updated.
|
||||
*/
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
|
||||
/* Generate the OLD table
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0);
|
||||
|
||||
/* Generate the NEW table
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqlite3ExprCode(pParse, pRecnoExpr);
|
||||
if( chngRowid ){
|
||||
sqlite3ExprCodeAndCache(pParse, pRowidExpr);
|
||||
}else{
|
||||
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
}
|
||||
for(i=0; i<pTab->nCol; i++){ /* TODO: Factor out this loop as common code */
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
|
||||
continue;
|
||||
}
|
||||
j = aXRef[i];
|
||||
if( j<0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, i);
|
||||
sqlite3ColumnDefault(v, pTab, i);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pChanges->a[j].pExpr);
|
||||
sqlite3ExprCodeAndCache(pParse, pChanges->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
@@ -289,14 +342,14 @@ void sqlite3Update(
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
}
|
||||
if( pParse->nErr ) goto update_cleanup;
|
||||
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
|
||||
/* Fire the BEFORE and INSTEAD OF triggers
|
||||
*/
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, pTab,
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TRIGGER_BEFORE, pTab,
|
||||
newIdx, oldIdx, onError, addr) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
@@ -338,9 +391,8 @@ void sqlite3Update(
|
||||
** Also, the old data is needed to delete the old index entires.
|
||||
** So make the cursor point at the old record.
|
||||
*/
|
||||
if( !row_triggers_exist ){
|
||||
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
if( !triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_NotExists, iCur, addr);
|
||||
@@ -349,8 +401,8 @@ void sqlite3Update(
|
||||
** will be after the update. (The old record number is currently
|
||||
** on top of the stack.)
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqlite3ExprCode(pParse, pRecnoExpr);
|
||||
if( chngRowid ){
|
||||
sqlite3ExprCode(pParse, pRowidExpr);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}
|
||||
|
||||
@@ -358,12 +410,13 @@ void sqlite3Update(
|
||||
*/
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
|
||||
continue;
|
||||
}
|
||||
j = aXRef[i];
|
||||
if( j<0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, i);
|
||||
sqlite3ColumnDefault(v, pTab, i);
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pChanges->a[j].pExpr);
|
||||
}
|
||||
@@ -371,7 +424,7 @@ void sqlite3Update(
|
||||
|
||||
/* Do constraint checks
|
||||
*/
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1,
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRowid, 1,
|
||||
onError, addr);
|
||||
|
||||
/* Delete the old indices for the current record.
|
||||
@@ -380,13 +433,13 @@ void sqlite3Update(
|
||||
|
||||
/* If changing the record number, delete the old record.
|
||||
*/
|
||||
if( chngRecno ){
|
||||
if( chngRowid ){
|
||||
sqlite3VdbeAddOp(v, OP_Delete, iCur, 0);
|
||||
}
|
||||
|
||||
/* Create the new index entries and the new record.
|
||||
*/
|
||||
sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, -1);
|
||||
sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRowid, 1, -1);
|
||||
}
|
||||
|
||||
/* Increment the row counter
|
||||
@@ -398,7 +451,7 @@ void sqlite3Update(
|
||||
/* If there are triggers, close all the cursors after each iteration
|
||||
** through the loop. The fire the after triggers.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist ){
|
||||
if( !isView ){
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
if( openAll || aIdxUsed[i] )
|
||||
@@ -406,7 +459,7 @@ void sqlite3Update(
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, pTab,
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TRIGGER_AFTER, pTab,
|
||||
newIdx, oldIdx, onError, addr) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
@@ -416,11 +469,10 @@ void sqlite3Update(
|
||||
** all record selected by the WHERE clause have been updated.
|
||||
*/
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
|
||||
sqlite3VdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
|
||||
/* Close all tables if there were no FOR EACH ROW triggers */
|
||||
if( !row_triggers_exist ){
|
||||
if( !triggers_exist ){
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
if( openAll || aIdxUsed[i] ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur+i+1, 0);
|
||||
@@ -432,12 +484,12 @@ void sqlite3Update(
|
||||
sqlite3VdbeAddOp(v, OP_Close, oldIdx, 0);
|
||||
}
|
||||
|
||||
sqlite3EndWriteOperation(pParse);
|
||||
|
||||
/*
|
||||
** Return the number of rows that were changed.
|
||||
** Return the number of rows that were changed. If this routine is
|
||||
** generating code because of a call to sqlite3NestedParse(), do not
|
||||
** invoke the callback function.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack && pParse->nested==0 ){
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, "rows updated", P3_STATIC);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
** This file contains routines used to translate between UTF-8,
|
||||
** UTF-16, UTF-16BE, and UTF-16LE.
|
||||
**
|
||||
** $Id: utf.c,v 1.28 2004/08/31 00:52:37 drh Exp $
|
||||
** $Id: utf.c,v 1.32 2005/01/28 01:29:08 drh Exp $
|
||||
**
|
||||
** Notes on UTF-8:
|
||||
**
|
||||
@@ -58,8 +58,8 @@
|
||||
** sqlite3utf8LikeCompare() - Do a LIKE match given two UTF8 char* strings.
|
||||
**
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "sqliteInt.h"
|
||||
#include <assert.h>
|
||||
#include "vdbeInt.h"
|
||||
|
||||
/*
|
||||
@@ -232,6 +232,7 @@ int sqlite3ReadUtf8(const unsigned char *z){
|
||||
*/
|
||||
/* #define TRANSLATE_TRACE 1 */
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** This routine transforms the internal text encoding used by pMem to
|
||||
** desiredEnc. It is an error if the string is already of the desired
|
||||
@@ -251,7 +252,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
assert( pMem->enc!=0 );
|
||||
assert( pMem->n>=0 );
|
||||
|
||||
#ifdef TRANSLATE_TRACE
|
||||
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
|
||||
{
|
||||
char zBuf[100];
|
||||
sqlite3VdbeMemPrettyPrint(pMem, zBuf, 100);
|
||||
@@ -324,17 +325,16 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
READ_UTF8(zIn, c);
|
||||
WRITE_UTF16LE(z, c);
|
||||
}
|
||||
WRITE_UTF16LE(z, 0);
|
||||
pMem->n = (z-zOut)-2;
|
||||
}else if( desiredEnc==SQLITE_UTF16BE ){
|
||||
}else{
|
||||
assert( desiredEnc==SQLITE_UTF16BE );
|
||||
/* UTF-8 -> UTF-16 Big-endian */
|
||||
while( zIn<zTerm ){
|
||||
READ_UTF8(zIn, c);
|
||||
WRITE_UTF16BE(z, c);
|
||||
}
|
||||
WRITE_UTF16BE(z, 0);
|
||||
pMem->n = (z-zOut)-2;
|
||||
}
|
||||
pMem->n = z - zOut;
|
||||
*z++ = 0;
|
||||
}else{
|
||||
assert( desiredEnc==SQLITE_UTF8 );
|
||||
if( pMem->enc==SQLITE_UTF16LE ){
|
||||
@@ -343,18 +343,16 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
READ_UTF16LE(zIn, c);
|
||||
WRITE_UTF8(z, c);
|
||||
}
|
||||
WRITE_UTF8(z, 0);
|
||||
pMem->n = (z-zOut)-1;
|
||||
}else{
|
||||
/* UTF-16 Little-endian -> UTF-8 */
|
||||
while( zIn<zTerm ){
|
||||
READ_UTF16BE(zIn, c);
|
||||
WRITE_UTF8(z, c);
|
||||
}
|
||||
WRITE_UTF8(z, 0);
|
||||
pMem->n = (z-zOut)-1;
|
||||
}
|
||||
pMem->n = z - zOut;
|
||||
}
|
||||
*z = 0;
|
||||
assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
|
||||
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
@@ -370,7 +368,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
pMem->z = zOut;
|
||||
|
||||
translate_out:
|
||||
#ifdef TRANSLATE_TRACE
|
||||
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
|
||||
{
|
||||
char zBuf[100];
|
||||
sqlite3VdbeMemPrettyPrint(pMem, zBuf, 100);
|
||||
@@ -426,6 +424,7 @@ int sqlite3VdbeMemHandleBom(Mem *pMem){
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
/*
|
||||
** pZ is a UTF-8 encoded unicode string. If nByte is less than zero,
|
||||
@@ -450,6 +449,7 @@ int sqlite3utf8CharLen(const char *z, int nByte){
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
/*
|
||||
** pZ is a UTF-16 encoded unicode string. If nChar is less than zero,
|
||||
** return the number of bytes up to (but not including), the first pair
|
||||
@@ -566,4 +566,5 @@ void sqlite3utfSelfTest(){
|
||||
assert( (z-zBuf)==n );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* SQLITE_TEST */
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
+158
-149
@@ -14,13 +14,13 @@
|
||||
** This file contains functions for allocating memory, comparing
|
||||
** strings, and stuff like that.
|
||||
**
|
||||
** $Id: util.c,v 1.114 2004/08/31 00:52:37 drh Exp $
|
||||
** $Id: util.c,v 1.146 2005/09/17 18:34:11 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if SQLITE_DEBUG>2 && defined(__GLIBC__)
|
||||
#if SQLITE_MEMDEBUG>2 && defined(__GLIBC__)
|
||||
#include <execinfo.h>
|
||||
void print_stack_trace(){
|
||||
void *bt[30];
|
||||
@@ -44,26 +44,54 @@ void print_stack_trace(){
|
||||
int sqlite3_malloc_failed = 0;
|
||||
|
||||
/*
|
||||
** If SQLITE_DEBUG is defined, then use versions of malloc() and
|
||||
** If SQLITE_MEMDEBUG is defined, then use versions of malloc() and
|
||||
** free() that track memory usage and check for buffer overruns.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
|
||||
/*
|
||||
** For keeping track of the number of mallocs and frees. This
|
||||
** is used to check for memory leaks.
|
||||
** is used to check for memory leaks. The iMallocFail and iMallocReset
|
||||
** values are used to simulate malloc() failures during testing in
|
||||
** order to verify that the library correctly handles an out-of-memory
|
||||
** condition.
|
||||
*/
|
||||
int sqlite3_nMalloc; /* Number of sqliteMalloc() calls */
|
||||
int sqlite3_nFree; /* Number of sqliteFree() calls */
|
||||
int sqlite3_memUsed; /* Total memory obtained from malloc */
|
||||
int sqlite3_memMax; /* Mem usage high-water mark */
|
||||
int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls */
|
||||
#if SQLITE_DEBUG>1
|
||||
int sqlite3_iMallocReset = -1; /* When iMallocFail reaches 0, set to this */
|
||||
#if SQLITE_MEMDEBUG>1
|
||||
static int memcnt = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Number of 32-bit guard words
|
||||
** Number of 32-bit guard words. This should probably be a multiple of
|
||||
** 2 since on 64-bit machines we want the value returned by sqliteMalloc()
|
||||
** to be 8-byte aligned.
|
||||
*/
|
||||
#define N_GUARD 1
|
||||
#define N_GUARD 2
|
||||
|
||||
/*
|
||||
** Check for a simulated memory allocation failure. Return true if
|
||||
** the failure should be simulated. Return false to proceed as normal.
|
||||
*/
|
||||
static int simulatedMallocFailure(int n, char *zFile, int line){
|
||||
if( sqlite3_iMallocFail>=0 ){
|
||||
sqlite3_iMallocFail--;
|
||||
if( sqlite3_iMallocFail==0 ){
|
||||
sqlite3_malloc_failed++;
|
||||
#if SQLITE_MEMDEBUG>1
|
||||
fprintf(stderr,"**** failed to allocate %d bytes at %s:%d\n",
|
||||
n, zFile,line);
|
||||
#endif
|
||||
sqlite3_iMallocFail = sqlite3_iMallocReset;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate new memory and set it to zero. Return NULL if
|
||||
@@ -73,23 +101,18 @@ void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
|
||||
void *p;
|
||||
int *pi;
|
||||
int i, k;
|
||||
if( sqlite3_iMallocFail>=0 ){
|
||||
sqlite3_iMallocFail--;
|
||||
if( sqlite3_iMallocFail==0 ){
|
||||
sqlite3_malloc_failed++;
|
||||
#if SQLITE_DEBUG>1
|
||||
fprintf(stderr,"**** failed to allocate %d bytes at %s:%d\n",
|
||||
n, zFile,line);
|
||||
#endif
|
||||
sqlite3_iMallocFail--;
|
||||
return 0;
|
||||
}
|
||||
if( n==0 ){
|
||||
return 0;
|
||||
}
|
||||
if( n==0 ) return 0;
|
||||
if( simulatedMallocFailure(n, zFile, line) ){
|
||||
return 0;
|
||||
}
|
||||
sqlite3_memUsed += n;
|
||||
if( sqlite3_memMax<sqlite3_memUsed ) sqlite3_memMax = sqlite3_memUsed;
|
||||
k = (n+sizeof(int)-1)/sizeof(int);
|
||||
pi = malloc( (N_GUARD*2+1+k)*sizeof(int));
|
||||
if( pi==0 ){
|
||||
sqlite3_malloc_failed++;
|
||||
if( n>0 ) sqlite3_malloc_failed++;
|
||||
return 0;
|
||||
}
|
||||
sqlite3_nMalloc++;
|
||||
@@ -98,7 +121,7 @@ void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
|
||||
for(i=0; i<N_GUARD; i++) pi[k+1+N_GUARD+i] = 0xdead3344;
|
||||
p = &pi[N_GUARD+1];
|
||||
memset(p, bZero==0, n);
|
||||
#if SQLITE_DEBUG>1
|
||||
#if SQLITE_MEMDEBUG>1
|
||||
print_stack_trace();
|
||||
fprintf(stderr,"%06d malloc %d bytes at 0x%x from %s:%d\n",
|
||||
++memcnt, n, (int)p, zFile,line);
|
||||
@@ -106,6 +129,13 @@ void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** This version of malloc is always a real function, never a macro
|
||||
*/
|
||||
void *sqlite3MallocX(int n){
|
||||
return sqlite3Malloc_(n, 0, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
/*
|
||||
** Check to see if the given pointer was obtained from sqliteMalloc()
|
||||
** and is able to hold at least N bytes. Raise an exception if this
|
||||
@@ -144,6 +174,7 @@ void sqlite3Free_(void *p, char *zFile, int line){
|
||||
}
|
||||
}
|
||||
n = pi[N_GUARD];
|
||||
sqlite3_memUsed -= n;
|
||||
k = (n+sizeof(int)-1)/sizeof(int);
|
||||
for(i=0; i<N_GUARD; i++){
|
||||
if( pi[k+N_GUARD+1+i]!=0xdead3344 ){
|
||||
@@ -152,7 +183,7 @@ void sqlite3Free_(void *p, char *zFile, int line){
|
||||
}
|
||||
}
|
||||
memset(pi, 0xff, (k+N_GUARD*2+1)*sizeof(int));
|
||||
#if SQLITE_DEBUG>1
|
||||
#if SQLITE_MEMDEBUG>1
|
||||
fprintf(stderr,"%06d free %d bytes at 0x%x from %s:%d\n",
|
||||
++memcnt, n, (int)p, zFile,line);
|
||||
#endif
|
||||
@@ -175,6 +206,9 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
|
||||
sqlite3Free_(oldP,zFile,line);
|
||||
return 0;
|
||||
}
|
||||
if( simulatedMallocFailure(n, zFile, line) ){
|
||||
return 0;
|
||||
}
|
||||
oldPi = oldP;
|
||||
oldPi -= N_GUARD+1;
|
||||
if( oldPi[0]!=0xdead1122 ){
|
||||
@@ -182,6 +216,7 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
|
||||
return 0;
|
||||
}
|
||||
oldN = oldPi[N_GUARD];
|
||||
sqlite3_memUsed -= oldN;
|
||||
oldK = (oldN+sizeof(int)-1)/sizeof(int);
|
||||
for(i=0; i<N_GUARD; i++){
|
||||
if( oldPi[oldK+N_GUARD+1+i]!=0xdead3344 ){
|
||||
@@ -193,11 +228,13 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
|
||||
k = (n + sizeof(int) - 1)/sizeof(int);
|
||||
pi = malloc( (k+N_GUARD*2+1)*sizeof(int) );
|
||||
if( pi==0 ){
|
||||
sqlite3_malloc_failed++;
|
||||
if( n>0 ) sqlite3_malloc_failed++;
|
||||
return 0;
|
||||
}
|
||||
for(i=0; i<N_GUARD; i++) pi[i] = 0xdead1122;
|
||||
pi[N_GUARD] = n;
|
||||
sqlite3_memUsed += n;
|
||||
if( sqlite3_memMax<sqlite3_memUsed ) sqlite3_memMax = sqlite3_memUsed;
|
||||
for(i=0; i<N_GUARD; i++) pi[k+N_GUARD+1+i] = 0xdead3344;
|
||||
p = &pi[N_GUARD+1];
|
||||
memcpy(p, oldP, n>oldN ? oldN : n);
|
||||
@@ -206,7 +243,7 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
|
||||
}
|
||||
memset(oldPi, 0xab, (oldK+N_GUARD+2)*sizeof(int));
|
||||
free(oldPi);
|
||||
#if SQLITE_DEBUG>1
|
||||
#if SQLITE_MEMDEBUG>1
|
||||
print_stack_trace();
|
||||
fprintf(stderr,"%06d realloc %d to %d bytes at 0x%x to 0x%x at %s:%d\n",
|
||||
++memcnt, oldN, n, (int)oldP, (int)p, zFile, line);
|
||||
@@ -214,28 +251,6 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make a duplicate of a string into memory obtained from malloc()
|
||||
** Free the original string using sqliteFree().
|
||||
**
|
||||
** This routine is called on all strings that are passed outside of
|
||||
** the SQLite library. That way clients can free the string using free()
|
||||
** rather than having to call sqliteFree().
|
||||
*/
|
||||
void sqlite3StrRealloc(char **pz){
|
||||
char *zNew;
|
||||
if( pz==0 || *pz==0 ) return;
|
||||
zNew = malloc( strlen(*pz) + 1 );
|
||||
if( zNew==0 ){
|
||||
sqlite3_malloc_failed++;
|
||||
sqliteFree(*pz);
|
||||
*pz = 0;
|
||||
}
|
||||
strcpy(zNew, *pz);
|
||||
sqliteFree(*pz);
|
||||
*pz = zNew;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make a copy of a string in memory obtained from sqliteMalloc()
|
||||
*/
|
||||
@@ -263,13 +278,13 @@ char *sqlite3StrNDup_(const char *z, int n, char *zFile, int line){
|
||||
void sqlite3FreeX(void *p){
|
||||
sqliteFree(p);
|
||||
}
|
||||
#endif /* SQLITE_DEBUG */
|
||||
#endif /* SQLITE_MEMDEBUG */
|
||||
|
||||
/*
|
||||
** The following versions of malloc() and free() are for use in a
|
||||
** normal build.
|
||||
*/
|
||||
#if !defined(SQLITE_DEBUG)
|
||||
#if !defined(SQLITE_MEMDEBUG)
|
||||
|
||||
/*
|
||||
** Allocate new memory and set it to zero. Return NULL if
|
||||
@@ -277,6 +292,7 @@ void sqlite3FreeX(void *p){
|
||||
*/
|
||||
void *sqlite3Malloc(int n){
|
||||
void *p;
|
||||
if( n==0 ) return 0;
|
||||
if( (p = malloc(n))==0 ){
|
||||
if( n>0 ) sqlite3_malloc_failed++;
|
||||
}else{
|
||||
@@ -291,6 +307,7 @@ void *sqlite3Malloc(int n){
|
||||
*/
|
||||
void *sqlite3MallocRaw(int n){
|
||||
void *p;
|
||||
if( n==0 ) return 0;
|
||||
if( (p = malloc(n))==0 ){
|
||||
if( n>0 ) sqlite3_malloc_failed++;
|
||||
}
|
||||
@@ -322,7 +339,7 @@ void *sqlite3Realloc(void *p, int n){
|
||||
}
|
||||
p2 = realloc(p, n);
|
||||
if( p2==0 ){
|
||||
sqlite3_malloc_failed++;
|
||||
if( n>0 ) sqlite3_malloc_failed++;
|
||||
}
|
||||
return p2;
|
||||
}
|
||||
@@ -347,7 +364,20 @@ char *sqlite3StrNDup(const char *z, int n){
|
||||
}
|
||||
return zNew;
|
||||
}
|
||||
#endif /* !defined(SQLITE_DEBUG) */
|
||||
#endif /* !defined(SQLITE_MEMDEBUG) */
|
||||
|
||||
/*
|
||||
** Reallocate a buffer to a different size. This is similar to
|
||||
** sqliteRealloc() except that if the allocation fails the buffer
|
||||
** is freed.
|
||||
*/
|
||||
void sqlite3ReallocOrFree(void **ppBuf, int newSize){
|
||||
void *pNew = sqliteRealloc(*ppBuf, newSize);
|
||||
if( pNew==0 ){
|
||||
sqliteFree(*ppBuf);
|
||||
}
|
||||
*ppBuf = pNew;
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a string from the 2nd and subsequent arguments (up to the
|
||||
@@ -356,15 +386,15 @@ char *sqlite3StrNDup(const char *z, int n){
|
||||
** point to that string. The 1st argument must either be NULL or
|
||||
** point to memory obtained from sqliteMalloc().
|
||||
*/
|
||||
void sqlite3SetString(char **pz, const char *zFirst, ...){
|
||||
void sqlite3SetString(char **pz, ...){
|
||||
va_list ap;
|
||||
int nByte;
|
||||
const char *z;
|
||||
char *zResult;
|
||||
|
||||
if( pz==0 ) return;
|
||||
nByte = strlen(zFirst) + 1;
|
||||
va_start(ap, zFirst);
|
||||
nByte = 1;
|
||||
va_start(ap, pz);
|
||||
while( (z = va_arg(ap, const char*))!=0 ){
|
||||
nByte += strlen(z);
|
||||
}
|
||||
@@ -374,63 +404,20 @@ void sqlite3SetString(char **pz, const char *zFirst, ...){
|
||||
if( zResult==0 ){
|
||||
return;
|
||||
}
|
||||
strcpy(zResult, zFirst);
|
||||
zResult += strlen(zResult);
|
||||
va_start(ap, zFirst);
|
||||
*zResult = 0;
|
||||
va_start(ap, pz);
|
||||
while( (z = va_arg(ap, const char*))!=0 ){
|
||||
strcpy(zResult, z);
|
||||
zResult += strlen(zResult);
|
||||
}
|
||||
va_end(ap);
|
||||
#ifdef SQLITE_DEBUG
|
||||
#if SQLITE_DEBUG>1
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
#if SQLITE_MEMDEBUG>1
|
||||
fprintf(stderr,"string at 0x%x is %s\n", (int)*pz, *pz);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Works like sqlite3SetString, but each string is now followed by
|
||||
** a length integer which specifies how much of the source string
|
||||
** to copy (in bytes). -1 means use the whole string. The 1st
|
||||
** argument must either be NULL or point to memory obtained from
|
||||
** sqliteMalloc().
|
||||
*/
|
||||
void sqlite3SetNString(char **pz, ...){
|
||||
va_list ap;
|
||||
int nByte;
|
||||
const char *z;
|
||||
char *zResult;
|
||||
int n;
|
||||
|
||||
if( pz==0 ) return;
|
||||
nByte = 0;
|
||||
va_start(ap, pz);
|
||||
while( (z = va_arg(ap, const char*))!=0 ){
|
||||
n = va_arg(ap, int);
|
||||
if( n<=0 ) n = strlen(z);
|
||||
nByte += n;
|
||||
}
|
||||
va_end(ap);
|
||||
sqliteFree(*pz);
|
||||
*pz = zResult = sqliteMallocRaw( nByte + 1 );
|
||||
if( zResult==0 ) return;
|
||||
va_start(ap, pz);
|
||||
while( (z = va_arg(ap, const char*))!=0 ){
|
||||
n = va_arg(ap, int);
|
||||
if( n<=0 ) n = strlen(z);
|
||||
memcpy(zResult, z, n);
|
||||
zResult += n;
|
||||
}
|
||||
*zResult = 0;
|
||||
#ifdef SQLITE_DEBUG
|
||||
#if SQLITE_DEBUG>1
|
||||
fprintf(stderr,"string at 0x%x is %s\n", (int)*pz, *pz);
|
||||
#endif
|
||||
#endif
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the most recent error code and error string for the sqlite
|
||||
** handle "db". The error code is set to "err_code".
|
||||
@@ -448,11 +435,11 @@ void sqlite3SetNString(char **pz, ...){
|
||||
** zFormat and any string tokens that follow it are assumed to be
|
||||
** encoded in UTF-8.
|
||||
**
|
||||
** To clear the most recent error for slqite handle "db", sqlite3Error
|
||||
** To clear the most recent error for sqlite handle "db", sqlite3Error
|
||||
** should be called with err_code set to SQLITE_OK and zFormat set
|
||||
** to NULL.
|
||||
*/
|
||||
void sqlite3Error(sqlite *db, int err_code, const char *zFormat, ...){
|
||||
void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
|
||||
if( db && (db->pErr || (db->pErr = sqlite3ValueNew())) ){
|
||||
db->errCode = err_code;
|
||||
if( zFormat ){
|
||||
@@ -512,7 +499,8 @@ void sqlite3Dequote(char *z){
|
||||
switch( quote ){
|
||||
case '\'': break;
|
||||
case '"': break;
|
||||
case '[': quote = ']'; break;
|
||||
case '`': break; /* For MySQL compatibility */
|
||||
case '[': quote = ']'; break; /* For MS SqlServer compatibility */
|
||||
default: return;
|
||||
}
|
||||
for(i=1, j=0; z[i]; i++){
|
||||
@@ -552,20 +540,6 @@ const unsigned char sqlite3UpperToLower[] = {
|
||||
};
|
||||
#define UpperToLower sqlite3UpperToLower
|
||||
|
||||
/*
|
||||
** This function computes a hash on the name of a keyword.
|
||||
** Case is not significant.
|
||||
*/
|
||||
int sqlite3HashNoCase(const char *z, int n){
|
||||
int h = 0;
|
||||
if( n<=0 ) n = strlen(z);
|
||||
while( n > 0 ){
|
||||
h = (h<<3) ^ h ^ UpperToLower[(unsigned char)*z++];
|
||||
n--;
|
||||
}
|
||||
return h & 0x7fffffff;
|
||||
}
|
||||
|
||||
/*
|
||||
** Some systems have stricmp(). Others have strcasecmp(). Because
|
||||
** there is no consistency, we will define our own.
|
||||
@@ -591,7 +565,7 @@ int sqlite3StrNICmp(const char *zLeft, const char *zRight, int N){
|
||||
** the string is numeric and contains the '.' character, set *realnum
|
||||
** to TRUE (otherwise FALSE).
|
||||
**
|
||||
** Am empty string is considered non-numeric.
|
||||
** An empty string is considered non-numeric.
|
||||
*/
|
||||
int sqlite3IsNumber(const char *z, int *realnum, u8 enc){
|
||||
int incr = (enc==SQLITE_UTF8?1:2);
|
||||
@@ -631,8 +605,9 @@ int sqlite3IsNumber(const char *z, int *realnum, u8 enc){
|
||||
** of "." depending on how locale is set. But that would cause problems
|
||||
** for SQL. So this routine always uses "." regardless of locale.
|
||||
*/
|
||||
double sqlite3AtoF(const char *z, const char **pzEnd){
|
||||
int sqlite3AtoF(const char *z, double *pResult){
|
||||
int sign = 1;
|
||||
const char *zBegin = z;
|
||||
LONGDOUBLE_TYPE v1 = 0.0;
|
||||
if( *z=='-' ){
|
||||
sign = -1;
|
||||
@@ -679,8 +654,8 @@ double sqlite3AtoF(const char *z, const char **pzEnd){
|
||||
v1 *= scale;
|
||||
}
|
||||
}
|
||||
if( pzEnd ) *pzEnd = z;
|
||||
return sign<0 ? -v1 : v1;
|
||||
*pResult = sign<0 ? -v1 : v1;
|
||||
return z - zBegin;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -722,7 +697,7 @@ int sqlite3atoi64(const char *zNum, i64 *pNum){
|
||||
** 32-bit signed integer, return TRUE. Otherwise return FALSE.
|
||||
**
|
||||
** This routine returns FALSE for the string -2147483648 even that
|
||||
** that number will, in theory fit in a 32-bit integer. But positive
|
||||
** that number will in fact fit in a 32-bit integer. But positive
|
||||
** 2147483648 will not fit in 32 bits. So it seems safer to return
|
||||
** false.
|
||||
*/
|
||||
@@ -782,11 +757,11 @@ int sqlite3FitsIn64Bits(const char *zNum){
|
||||
** call to sqlite3_close(db) and db has been deallocated. And we do
|
||||
** not want to write into deallocated memory.
|
||||
*/
|
||||
int sqlite3SafetyOn(sqlite *db){
|
||||
int sqlite3SafetyOn(sqlite3 *db){
|
||||
if( db->magic==SQLITE_MAGIC_OPEN ){
|
||||
db->magic = SQLITE_MAGIC_BUSY;
|
||||
return 0;
|
||||
}else if( db->magic==SQLITE_MAGIC_BUSY || db->magic==SQLITE_MAGIC_ERROR ){
|
||||
}else if( db->magic==SQLITE_MAGIC_BUSY ){
|
||||
db->magic = SQLITE_MAGIC_ERROR;
|
||||
db->flags |= SQLITE_Interrupt;
|
||||
}
|
||||
@@ -798,11 +773,11 @@ int sqlite3SafetyOn(sqlite *db){
|
||||
** Return an error (non-zero) if the magic was not SQLITE_MAGIC_BUSY
|
||||
** when this routine is called.
|
||||
*/
|
||||
int sqlite3SafetyOff(sqlite *db){
|
||||
int sqlite3SafetyOff(sqlite3 *db){
|
||||
if( db->magic==SQLITE_MAGIC_BUSY ){
|
||||
db->magic = SQLITE_MAGIC_OPEN;
|
||||
return 0;
|
||||
}else if( db->magic==SQLITE_MAGIC_OPEN || db->magic==SQLITE_MAGIC_ERROR ){
|
||||
}else if( db->magic==SQLITE_MAGIC_OPEN ){
|
||||
db->magic = SQLITE_MAGIC_ERROR;
|
||||
db->flags |= SQLITE_Interrupt;
|
||||
}
|
||||
@@ -810,19 +785,21 @@ int sqlite3SafetyOff(sqlite *db){
|
||||
}
|
||||
|
||||
/*
|
||||
** Check to make sure we are not currently executing an sqlite3_exec().
|
||||
** If we are currently in an sqlite3_exec(), return true and set
|
||||
** sqlite.magic to SQLITE_MAGIC_ERROR. This will cause a complete
|
||||
** shutdown of the database.
|
||||
**
|
||||
** This routine is used to try to detect when API routines are called
|
||||
** at the wrong time or in the wrong sequence.
|
||||
** Check to make sure we have a valid db pointer. This test is not
|
||||
** foolproof but it does provide some measure of protection against
|
||||
** misuse of the interface such as passing in db pointers that are
|
||||
** NULL or which have been previously closed. If this routine returns
|
||||
** TRUE it means that the db pointer is invalid and should not be
|
||||
** dereferenced for any reason. The calling function should invoke
|
||||
** SQLITE_MISUSE immediately.
|
||||
*/
|
||||
int sqlite3SafetyCheck(sqlite *db){
|
||||
if( db->pVdbe!=0 ){
|
||||
db->magic = SQLITE_MAGIC_ERROR;
|
||||
return 1;
|
||||
}
|
||||
int sqlite3SafetyCheck(sqlite3 *db){
|
||||
int magic;
|
||||
if( db==0 ) return 1;
|
||||
magic = db->magic;
|
||||
if( magic!=SQLITE_MAGIC_CLOSED &&
|
||||
magic!=SQLITE_MAGIC_OPEN &&
|
||||
magic!=SQLITE_MAGIC_BUSY ) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -858,7 +835,7 @@ int sqlite3SafetyCheck(sqlite *db){
|
||||
int sqlite3PutVarint(unsigned char *p, u64 v){
|
||||
int i, j, n;
|
||||
u8 buf[10];
|
||||
if( v & 0xff00000000000000 ){
|
||||
if( v & (((u64)0xff000000)<<32) ){
|
||||
p[8] = v;
|
||||
v >>= 8;
|
||||
for(i=7; i>=0; i--){
|
||||
@@ -930,16 +907,16 @@ int sqlite3GetVarint32(const unsigned char *p, u32 *v){
|
||||
u32 x;
|
||||
int n;
|
||||
unsigned char c;
|
||||
if( ((c = p[0]) & 0x80)==0 ){
|
||||
*v = c;
|
||||
if( ((signed char*)p)[0]>=0 ){
|
||||
*v = p[0];
|
||||
return 1;
|
||||
}
|
||||
x = c & 0x7f;
|
||||
if( ((c = p[1]) & 0x80)==0 ){
|
||||
*v = (x<<7) | c;
|
||||
x = p[0] & 0x7f;
|
||||
if( ((signed char*)p)[1]>=0 ){
|
||||
*v = (x<<7) | p[1];
|
||||
return 2;
|
||||
}
|
||||
x = (x<<7) | (c & 0x7f);
|
||||
x = (x<<7) | (p[1] & 0x7f);
|
||||
n = 2;
|
||||
do{
|
||||
x = (x<<7) | ((c = p[n++])&0x7f);
|
||||
@@ -961,6 +938,8 @@ int sqlite3VarintLen(u64 v){
|
||||
return i;
|
||||
}
|
||||
|
||||
#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) \
|
||||
|| defined(SQLITE_TEST)
|
||||
/*
|
||||
** Translate a single byte of Hex into an integer.
|
||||
*/
|
||||
@@ -969,13 +948,14 @@ static int hexToInt(int h){
|
||||
return h - '0';
|
||||
}else if( h>='a' && h<='f' ){
|
||||
return h - 'a' + 10;
|
||||
}else if( h>='A' && h<='F' ){
|
||||
return h - 'A' + 10;
|
||||
}else{
|
||||
return 0;
|
||||
assert( h>='A' && h<='F' );
|
||||
return h - 'A' + 10;
|
||||
}
|
||||
}
|
||||
#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC || SQLITE_TEST */
|
||||
|
||||
#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
|
||||
/*
|
||||
** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
|
||||
** value. Return a pointer to its binary value. Space to hold the
|
||||
@@ -994,3 +974,32 @@ void *sqlite3HexToBlob(const char *z){
|
||||
}
|
||||
return zBlob;
|
||||
}
|
||||
#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */
|
||||
|
||||
#if defined(SQLITE_TEST)
|
||||
/*
|
||||
** Convert text generated by the "%p" conversion format back into
|
||||
** a pointer.
|
||||
*/
|
||||
void *sqlite3TextToPtr(const char *z){
|
||||
void *p;
|
||||
u64 v;
|
||||
u32 v2;
|
||||
if( z[0]=='0' && z[1]=='x' ){
|
||||
z += 2;
|
||||
}
|
||||
v = 0;
|
||||
while( *z ){
|
||||
v = (v<<4) + hexToInt(*z);
|
||||
z++;
|
||||
}
|
||||
if( sizeof(p)==sizeof(v) ){
|
||||
p = *(void**)&v;
|
||||
}else{
|
||||
assert( sizeof(p)==sizeof(v2) );
|
||||
v2 = (u32)v;
|
||||
p = *(void**)&v2;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
|
||||
+83
-30
@@ -14,12 +14,12 @@
|
||||
** Most of the code in this file may be omitted by defining the
|
||||
** SQLITE_OMIT_VACUUM macro.
|
||||
**
|
||||
** $Id: vacuum.c,v 1.29 2004/09/02 15:27:42 drh Exp $
|
||||
** $Id: vacuum.c,v 1.45 2005/06/07 09:21:07 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
|
||||
#if !defined(SQLITE_OMIT_VACUUM) || SQLITE_OMIT_VACUUM
|
||||
#ifndef SQLITE_OMIT_VACUUM
|
||||
/*
|
||||
** Generate a random name of 20 character in length.
|
||||
*/
|
||||
@@ -91,15 +91,20 @@ void sqlite3Vacuum(Parse *pParse, Token *pTableName){
|
||||
/*
|
||||
** This routine implements the OP_Vacuum opcode of the VDBE.
|
||||
*/
|
||||
int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
|
||||
int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
int rc = SQLITE_OK; /* Return code from service routines */
|
||||
#if !defined(SQLITE_OMIT_VACUUM) || SQLITE_OMIT_VACUUM
|
||||
#ifndef SQLITE_OMIT_VACUUM
|
||||
const char *zFilename; /* full pathname of the database file */
|
||||
int nFilename; /* number of characters in zFilename[] */
|
||||
char *zTemp = 0; /* a temporary file in same directory as zFilename */
|
||||
int i; /* Loop counter */
|
||||
Btree *pMain; /* The database being vacuumed */
|
||||
Btree *pTemp;
|
||||
char *zSql = 0;
|
||||
int writeschema_flag; /* Saved value of the write-schema flag */
|
||||
|
||||
/* Save the current value of the write-schema flag before setting it. */
|
||||
writeschema_flag = db->flags&SQLITE_WriteSchema;
|
||||
db->flags |= SQLITE_WriteSchema;
|
||||
|
||||
if( !db->autoCommit ){
|
||||
sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction",
|
||||
@@ -111,7 +116,8 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
|
||||
/* Get the full pathname of the database file and create a
|
||||
** temporary filename in the same directory as the original file.
|
||||
*/
|
||||
zFilename = sqlite3BtreeGetFilename(db->aDb[0].pBt);
|
||||
pMain = db->aDb[0].pBt;
|
||||
zFilename = sqlite3BtreeGetFilename(pMain);
|
||||
assert( zFilename );
|
||||
if( zFilename[0]=='\0' ){
|
||||
/* The in-memory database. Do nothing. Return directly to avoid causing
|
||||
@@ -127,11 +133,19 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
strcpy(zTemp, zFilename);
|
||||
i = 0;
|
||||
|
||||
/* The randomName() procedure in the following loop uses an excellent
|
||||
** source of randomness to generate a name from a space of 1.3e+31
|
||||
** possibilities. So unless the directory already contains on the order
|
||||
** of 1.3e+31 files, the probability that the following loop will
|
||||
** run more than once or twice is vanishingly small. We are certain
|
||||
** enough that this loop will always terminate (and terminate quickly)
|
||||
** that we don't even bother to set a maximum loop count.
|
||||
*/
|
||||
do {
|
||||
zTemp[nFilename] = '-';
|
||||
randomName((unsigned char*)&zTemp[nFilename+1]);
|
||||
} while( i<10 && sqlite3OsFileExists(zTemp) );
|
||||
} while( sqlite3OsFileExists(zTemp) );
|
||||
|
||||
/* Attach the temporary database as 'vacuum_db'. The synchronous pragma
|
||||
** can be set to 'off' for this file, as it is not recovered if a crash
|
||||
@@ -150,7 +164,16 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
|
||||
sqliteFree(zSql);
|
||||
zSql = 0;
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
execSql(db, "PRAGMA vacuum_db.synchronous = off;");
|
||||
assert( strcmp(db->aDb[db->nDb-1].zName,"vacuum_db")==0 );
|
||||
pTemp = db->aDb[db->nDb-1].pBt;
|
||||
sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain),
|
||||
sqlite3BtreeGetReserve(pMain));
|
||||
assert( sqlite3BtreeGetPageSize(pTemp)==sqlite3BtreeGetPageSize(pMain) );
|
||||
execSql(db, "PRAGMA vacuum_db.synchronous=OFF");
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
sqlite3BtreeSetAutoVacuum(pTemp, sqlite3BtreeGetAutoVacuum(pMain));
|
||||
#endif
|
||||
|
||||
/* Begin a transaction */
|
||||
rc = execSql(db, "BEGIN;");
|
||||
@@ -161,14 +184,17 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
|
||||
*/
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14,100000000) "
|
||||
" FROM sqlite_master WHERE type='table' "
|
||||
"UNION ALL "
|
||||
"SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14,100000000) "
|
||||
" FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' "
|
||||
"UNION ALL "
|
||||
" FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'");
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14,100000000)"
|
||||
" FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' ");
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21,100000000) "
|
||||
" FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'"
|
||||
"UNION ALL "
|
||||
" FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'");
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'CREATE VIEW vacuum_db.' || substr(sql,13,100000000) "
|
||||
" FROM sqlite_master WHERE type='view'"
|
||||
);
|
||||
@@ -182,10 +208,25 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
|
||||
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
|
||||
"|| ' SELECT * FROM ' || quote(name) || ';'"
|
||||
"FROM sqlite_master "
|
||||
"WHERE type = 'table';"
|
||||
"WHERE type = 'table' AND name!='sqlite_sequence';"
|
||||
);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Copy over the sequence table
|
||||
*/
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'DELETE FROM vacuum_db.' || quote(name) || ';' "
|
||||
"FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence' "
|
||||
);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
|
||||
"|| ' SELECT * FROM ' || quote(name) || ';' "
|
||||
"FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';"
|
||||
);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
|
||||
/* Copy the triggers from the main database to the temporary database.
|
||||
** This was deferred before in case the triggers interfered with copying
|
||||
** the data. It's possible the indices should be deferred until this
|
||||
@@ -206,26 +247,33 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
|
||||
** opened for writing. This way, the SQL transaction used to create the
|
||||
** temporary database never needs to be committed.
|
||||
*/
|
||||
pTemp = db->aDb[db->nDb-1].pBt;
|
||||
if( sqlite3BtreeIsInTrans(pTemp) ){
|
||||
Btree *pMain = db->aDb[0].pBt;
|
||||
u32 meta;
|
||||
int i;
|
||||
|
||||
/* This array determines which meta meta values are preserved in the
|
||||
** vacuum. Even entries are the meta value number and odd entries
|
||||
** are an increment to apply to the meta value after the vacuum.
|
||||
** The increment is used to increase the schema cookie so that other
|
||||
** connections to the same database will know to reread the schema.
|
||||
*/
|
||||
static const unsigned char aCopy[] = {
|
||||
1, 1, /* Add one to the old schema cookie */
|
||||
3, 0, /* Preserve the default page cache size */
|
||||
5, 0, /* Preserve the default text encoding */
|
||||
6, 0, /* Preserve the user version */
|
||||
};
|
||||
|
||||
assert( 0==sqlite3BtreeIsInTrans(pMain) );
|
||||
rc = sqlite3BtreeBeginTrans(pMain, 1);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Copy Btree meta values 3 and 4. These correspond to SQL layer meta
|
||||
** values 2 and 3, the default values of a couple of pragmas.
|
||||
*/
|
||||
rc = sqlite3BtreeGetMeta(pMain, 3, &meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeUpdateMeta(pTemp, 3, meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeGetMeta(pMain, 4, &meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeUpdateMeta(pTemp, 4, meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
/* Copy Btree meta values */
|
||||
for(i=0; i<sizeof(aCopy)/sizeof(aCopy[0]); i+=2){
|
||||
rc = sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);
|
||||
}
|
||||
|
||||
rc = sqlite3BtreeCopyFile(pMain, pTemp);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
@@ -233,6 +281,10 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
|
||||
}
|
||||
|
||||
end_of_vacuum:
|
||||
/* Restore the original value of the write-schema flag. */
|
||||
db->flags &= ~SQLITE_WriteSchema;
|
||||
db->flags |= writeschema_flag;
|
||||
|
||||
/* Currently there is an SQL level transaction open on the vacuum
|
||||
** database. No locks are held on any other files (since the main file
|
||||
** was committed at the btree level). So it safe to end the transaction
|
||||
@@ -253,5 +305,6 @@ end_of_vacuum:
|
||||
if( zSql ) sqliteFree( zSql );
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
+874
-951
File diff suppressed because it is too large
Load Diff
+7
-7
@@ -15,7 +15,7 @@
|
||||
** or VDBE. The VDBE implements an abstract machine that runs a
|
||||
** simple program to access and modify the underlying database.
|
||||
**
|
||||
** $Id: vdbe.h,v 1.90 2004/08/21 17:54:45 drh Exp $
|
||||
** $Id: vdbe.h,v 1.99 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_VDBE_H_
|
||||
#define _SQLITE_VDBE_H_
|
||||
@@ -38,7 +38,7 @@ struct VdbeOp {
|
||||
int p1; /* First operand */
|
||||
int p2; /* Second parameter (often the jump destination) */
|
||||
char *p3; /* Third parameter */
|
||||
int p3type; /* P3_STATIC, P3_DYNAMIC or P3_POINTER */
|
||||
int p3type; /* One of the P3_xxx constants defined below */
|
||||
#ifdef VDBE_PROFILE
|
||||
int cnt; /* Number of times this instruction was executed */
|
||||
long long cycles; /* Total time spend executing this instruction */
|
||||
@@ -64,11 +64,11 @@ typedef struct VdbeOpList VdbeOpList;
|
||||
#define P3_NOTUSED 0 /* The P3 parameter is not used */
|
||||
#define P3_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
|
||||
#define P3_STATIC (-2) /* Pointer to a static string */
|
||||
#define P3_POINTER (-3) /* P3 is a pointer to some structure or object */
|
||||
#define P3_COLLSEQ (-4) /* P3 is a pointer to a CollSeq structure */
|
||||
#define P3_FUNCDEF (-5) /* P3 is a pointer to a FuncDef structure */
|
||||
#define P3_KEYINFO (-6) /* P3 is a pointer to a KeyInfo structure */
|
||||
#define P3_VDBEFUNC (-7) /* P3 is a pointer to a VdbeFunc structure */
|
||||
#define P3_MEM (-8) /* P3 is a pointer to a Mem* structure */
|
||||
|
||||
/* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
|
||||
** is made. That copy is freed when the Vdbe is finalized. But if the
|
||||
@@ -77,7 +77,7 @@ typedef struct VdbeOpList VdbeOpList;
|
||||
** from a single sqliteMalloc(). But no copy is made and the calling
|
||||
** function should *not* try to free the KeyInfo.
|
||||
*/
|
||||
#define P3_KEYINFO_HANDOFF (-7)
|
||||
#define P3_KEYINFO_HANDOFF (-9)
|
||||
|
||||
/*
|
||||
** The following macro converts a relative address in the p2 field
|
||||
@@ -97,16 +97,15 @@ typedef struct VdbeOpList VdbeOpList;
|
||||
** Prototypes for the VDBE interface. See comments on the implementation
|
||||
** for a description of what each of these routines does.
|
||||
*/
|
||||
Vdbe *sqlite3VdbeCreate(sqlite*);
|
||||
Vdbe *sqlite3VdbeCreate(sqlite3*);
|
||||
void sqlite3VdbeCreateCallback(Vdbe*, int*);
|
||||
int sqlite3VdbeAddOp(Vdbe*,int,int,int);
|
||||
int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
|
||||
int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
|
||||
void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
|
||||
void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
|
||||
void sqlite3VdbeJumpHere(Vdbe*, int addr);
|
||||
void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
|
||||
void sqlite3VdbeDequoteP3(Vdbe*, int addr);
|
||||
int sqlite3VdbeFindOp(Vdbe*, int, int, int);
|
||||
VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
|
||||
int sqlite3VdbeMakeLabel(Vdbe*);
|
||||
void sqlite3VdbeDelete(Vdbe*);
|
||||
@@ -120,6 +119,7 @@ int sqliteVdbeSetVariables(Vdbe*,int,const char**);
|
||||
void sqlite3VdbeSetNumCols(Vdbe*,int);
|
||||
int sqlite3VdbeSetColName(Vdbe*, int, const char *, int);
|
||||
void sqlite3VdbeCountChanges(Vdbe*);
|
||||
sqlite3 *sqlite3VdbeDb(Vdbe*);
|
||||
|
||||
#ifndef NDEBUG
|
||||
void sqlite3VdbeComment(Vdbe*, const char*, ...);
|
||||
|
||||
+56
-84
@@ -60,19 +60,18 @@ typedef unsigned char Bool;
|
||||
*/
|
||||
struct Cursor {
|
||||
BtCursor *pCursor; /* The cursor structure of the backend */
|
||||
i64 lastRecno; /* Last recno from a Next or NextIdx operation */
|
||||
i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
|
||||
i64 nextRowid; /* Next rowid returned by OP_NewRowid */
|
||||
Bool zeroed; /* True if zeroed out and ready for reuse */
|
||||
Bool recnoIsValid; /* True if lastRecno is valid */
|
||||
Bool keyAsData; /* The OP_Column command works on key instead of data */
|
||||
Bool rowidIsValid; /* True if lastRowid is valid */
|
||||
Bool atFirst; /* True if pointing to first entry */
|
||||
Bool useRandomRowid; /* Generate new record numbers semi-randomly */
|
||||
Bool nullRow; /* True if pointing to a row with no data */
|
||||
Bool nextRowidValid; /* True if the nextRowid field is valid */
|
||||
Bool pseudoTable; /* This is a NEW or OLD pseudo-tables of a trigger */
|
||||
Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
|
||||
Bool intKey; /* True if the table requires integer keys */
|
||||
Bool zeroData; /* True if table contains keys only - no data */
|
||||
Bool isTable; /* True if a table requiring integer keys */
|
||||
Bool isIndex; /* True if an index containing keys only - no data */
|
||||
u8 bogusIncrKey; /* Something for pIncrKey to point to if pKeyInfo==0 */
|
||||
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
|
||||
Btree *pBt; /* Separate file holding temporary table */
|
||||
@@ -82,6 +81,7 @@ struct Cursor {
|
||||
u8 *pIncrKey; /* Pointer to pKeyInfo->incrKey */
|
||||
KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
|
||||
int nField; /* Number of fields in the header */
|
||||
i64 seqCount; /* Sequence counter */
|
||||
|
||||
/* Cached information about the header for the data record that the
|
||||
** cursor is currently pointing to. Only valid if cacheValid is true.
|
||||
@@ -114,35 +114,18 @@ typedef struct Cursor Cursor;
|
||||
** SQLITE_BLOB.
|
||||
*/
|
||||
struct Mem {
|
||||
i64 i; /* Integer value */
|
||||
i64 i; /* Integer value. Or FuncDef* when flags==MEM_Agg */
|
||||
double r; /* Real value */
|
||||
char *z; /* String or BLOB value */
|
||||
int n; /* Number of characters in string value, including '\0' */
|
||||
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
|
||||
u8 type; /* One of MEM_Null, MEM_Str, etc. */
|
||||
u8 enc; /* TEXT_Utf8, TEXT_Utf16le, or TEXT_Utf16be */
|
||||
double r; /* Real value */
|
||||
char *z; /* String or BLOB value */
|
||||
void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
|
||||
char zShort[NBFS]; /* Space for short strings */
|
||||
};
|
||||
typedef struct Mem Mem;
|
||||
|
||||
/*
|
||||
** A sorter builds a list of elements to be sorted. Each element of
|
||||
** the list is an instance of the following structure.
|
||||
*/
|
||||
typedef struct Sorter Sorter;
|
||||
struct Sorter {
|
||||
int nKey; /* Number of bytes in the key */
|
||||
char *zKey; /* The key by which we will sort */
|
||||
Mem data;
|
||||
Sorter *pNext; /* Next in the list */
|
||||
};
|
||||
|
||||
/*
|
||||
** Number of buckets used for merge-sort.
|
||||
*/
|
||||
#define NSORT 30
|
||||
|
||||
/* One or more of the following flags are set to indicate the validOK
|
||||
** representations of the value stored in the Mem struct.
|
||||
**
|
||||
@@ -174,12 +157,7 @@ struct Sorter {
|
||||
#define MEM_Static 0x0080 /* Mem.z points to a static string */
|
||||
#define MEM_Ephem 0x0100 /* Mem.z points to an ephemeral string */
|
||||
#define MEM_Short 0x0200 /* Mem.z points to Mem.zShort */
|
||||
|
||||
/* The following MEM_ value appears only in AggElem.aMem.s.flag fields.
|
||||
** It indicates that the corresponding AggElem.aMem.z points to a
|
||||
** aggregate function context that needs to be finalized.
|
||||
*/
|
||||
#define MEM_AggCtx 0x0400 /* Mem.z points to an agg function context */
|
||||
#define MEM_Agg 0x0400 /* Mem.z points to an agg function context */
|
||||
|
||||
|
||||
/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
|
||||
@@ -211,42 +189,16 @@ typedef struct VdbeFunc VdbeFunc;
|
||||
** But this file is the only place where the internal details of this
|
||||
** structure are known.
|
||||
**
|
||||
** This structure is defined inside of vdbe.c because it uses substructures
|
||||
** This structure is defined inside of vdbeInt.h because it uses substructures
|
||||
** (Mem) which are only defined there.
|
||||
*/
|
||||
struct sqlite3_context {
|
||||
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
|
||||
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
|
||||
VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
|
||||
Mem s; /* The return value is stored here */
|
||||
void *pAgg; /* Aggregate context */
|
||||
u8 isError; /* Set to true for an error */
|
||||
u8 isStep; /* Current in the step function */
|
||||
int cnt; /* Number of times that the step function has been called */
|
||||
CollSeq *pColl;
|
||||
};
|
||||
|
||||
/*
|
||||
** An Agg structure describes an Aggregator. Each Agg consists of
|
||||
** zero or more Aggregator elements (AggElem). Each AggElem contains
|
||||
** a key and one or more values. The values are used in processing
|
||||
** aggregate functions in a SELECT. The key is used to implement
|
||||
** the GROUP BY clause of a select.
|
||||
*/
|
||||
typedef struct Agg Agg;
|
||||
typedef struct AggElem AggElem;
|
||||
struct Agg {
|
||||
int nMem; /* Number of values stored in each AggElem */
|
||||
AggElem *pCurrent; /* The AggElem currently in focus */
|
||||
FuncDef **apFunc; /* Information about aggregate functions */
|
||||
Btree *pBtree; /* The tmp. btree used to group elements, if required. */
|
||||
BtCursor *pCsr; /* Read/write cursor to the table in pBtree */
|
||||
int nTab; /* Root page of the table in pBtree */
|
||||
u8 searching; /* True between the first AggNext and AggReset */
|
||||
};
|
||||
struct AggElem {
|
||||
char *zKey; /* The key to this AggElem */
|
||||
int nKey; /* Number of bytes in the key, including '\0' at end */
|
||||
Mem aMem[1]; /* The values for this AggElem */
|
||||
Mem s; /* The return value is stored here */
|
||||
Mem *pMem; /* Memory cell used to store aggregate context */
|
||||
u8 isError; /* Set to true for an error */
|
||||
CollSeq *pColl; /* Collating sequence */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -262,29 +214,45 @@ struct Set {
|
||||
};
|
||||
|
||||
/*
|
||||
** A Keylist is a bunch of keys into a table. The keylist can
|
||||
** grow without bound. The keylist stores the ROWIDs of database
|
||||
** records that need to be deleted or updated.
|
||||
** A FifoPage structure holds a single page of valves. Pages are arranged
|
||||
** in a list.
|
||||
*/
|
||||
typedef struct Keylist Keylist;
|
||||
struct Keylist {
|
||||
int nKey; /* Number of slots in aKey[] */
|
||||
int nUsed; /* Next unwritten slot in aKey[] */
|
||||
int nRead; /* Next unread slot in aKey[] */
|
||||
Keylist *pNext; /* Next block of keys */
|
||||
i64 aKey[1]; /* One or more keys. Extra space allocated as needed */
|
||||
typedef struct FifoPage FifoPage;
|
||||
struct FifoPage {
|
||||
int nSlot; /* Number of entries aSlot[] */
|
||||
int iWrite; /* Push the next value into this entry in aSlot[] */
|
||||
int iRead; /* Read the next value from this entry in aSlot[] */
|
||||
FifoPage *pNext; /* Next page in the fifo */
|
||||
i64 aSlot[1]; /* One or more slots for rowid values */
|
||||
};
|
||||
|
||||
/*
|
||||
** The Fifo structure is typedef-ed in vdbeInt.h. But the implementation
|
||||
** of that structure is private to this file.
|
||||
**
|
||||
** The Fifo structure describes the entire fifo.
|
||||
*/
|
||||
typedef struct Fifo Fifo;
|
||||
struct Fifo {
|
||||
int nEntry; /* Total number of entries */
|
||||
FifoPage *pFirst; /* First page on the list */
|
||||
FifoPage *pLast; /* Last page on the list */
|
||||
};
|
||||
|
||||
/*
|
||||
** A Context stores the last insert rowid, the last statement change count,
|
||||
** and the current statement change count (i.e. changes since last statement).
|
||||
** The current keylist is also stored in the context.
|
||||
** Elements of Context structure type make up the ContextStack, which is
|
||||
** updated by the ContextPush and ContextPop opcodes (used by triggers)
|
||||
** updated by the ContextPush and ContextPop opcodes (used by triggers).
|
||||
** The context is pushed before executing a trigger a popped when the
|
||||
** trigger finishes.
|
||||
*/
|
||||
typedef struct Context Context;
|
||||
struct Context {
|
||||
int lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
|
||||
int nChange; /* Statement changes (Vdbe.nChanges) */
|
||||
Fifo sFifo; /* Records that will participate in a DELETE or UPDATE */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -295,7 +263,7 @@ struct Context {
|
||||
** is really a pointer to an instance of this structure.
|
||||
*/
|
||||
struct Vdbe {
|
||||
sqlite *db; /* The whole database */
|
||||
sqlite3 *db; /* The whole database */
|
||||
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
|
||||
FILE *trace; /* Write an execution trace here, if not NULL */
|
||||
int nOp; /* Number of instructions in the program */
|
||||
@@ -310,7 +278,6 @@ struct Vdbe {
|
||||
Mem *aColName; /* Column names to return */
|
||||
int nCursor; /* Number of slots in apCsr[] */
|
||||
Cursor **apCsr; /* One element of this array for each open cursor */
|
||||
Sorter *pSort; /* A linked list of objects to be sorted */
|
||||
int nVar; /* Number of entries in aVar[] */
|
||||
Mem *aVar; /* Values for the OP_Variable opcode. */
|
||||
char **azVar; /* Name of variables */
|
||||
@@ -318,11 +285,9 @@ struct Vdbe {
|
||||
int magic; /* Magic number for sanity checking */
|
||||
int nMem; /* Number of memory locations currently allocated */
|
||||
Mem *aMem; /* The memory locations */
|
||||
Agg agg; /* Aggregate information */
|
||||
int nCallback; /* Number of callbacks invoked so far */
|
||||
Keylist *pList; /* A list of ROWIDs */
|
||||
int keylistStackDepth; /* The size of the "keylist" stack */
|
||||
Keylist **keylistStack; /* The stack used by opcodes ListPush & ListPop */
|
||||
Fifo sFifo; /* A list of ROWIDs */
|
||||
int contextStackTop; /* Index of top element in the context stack */
|
||||
int contextStackDepth; /* The size of the "context" stack */
|
||||
Context *contextStack; /* Stack used by opcodes ContextPush & ContextPop*/
|
||||
int pc; /* The program counter */
|
||||
@@ -340,7 +305,9 @@ struct Vdbe {
|
||||
u8 explain; /* True if EXPLAIN present on SQL command */
|
||||
u8 changeCntOn; /* True to update the change-counter */
|
||||
u8 aborted; /* True if ROLLBACK in another VM causes an abort */
|
||||
u8 expired; /* True if the VM needs to be recompiled */
|
||||
int nChange; /* Number of db changes made since last reset */
|
||||
i64 startTime; /* Time when query started - used for profiling */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -355,15 +322,14 @@ struct Vdbe {
|
||||
** Function prototypes
|
||||
*/
|
||||
void sqlite3VdbeFreeCursor(Cursor*);
|
||||
void sqlite3VdbeSorterReset(Vdbe*);
|
||||
int sqlite3VdbeAggReset(sqlite *, Agg *, KeyInfo *);
|
||||
void sqlite3VdbeKeylistFree(Keylist*);
|
||||
void sqliteVdbePopStack(Vdbe*,int);
|
||||
int sqlite3VdbeCursorMoveto(Cursor*);
|
||||
#if !defined(NDEBUG) || defined(VDBE_PROFILE)
|
||||
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
|
||||
void sqlite3VdbePrintOp(FILE*, int, Op*);
|
||||
#endif
|
||||
#ifdef SQLITE_DEBUG
|
||||
void sqlite3VdbePrintSql(Vdbe*);
|
||||
#endif
|
||||
int sqlite3VdbeSerialTypeLen(u32);
|
||||
u32 sqlite3VdbeSerialType(Mem*);
|
||||
int sqlite3VdbeSerialPut(unsigned char*, Mem*);
|
||||
@@ -397,9 +363,15 @@ double sqlite3VdbeRealValue(Mem*);
|
||||
int sqlite3VdbeMemRealify(Mem*);
|
||||
int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
|
||||
void sqlite3VdbeMemRelease(Mem *p);
|
||||
void sqlite3VdbeMemFinalize(Mem*, FuncDef*);
|
||||
#ifndef NDEBUG
|
||||
void sqlite3VdbeMemSanity(Mem*, u8);
|
||||
int sqlite3VdbeOpcodeNoPush(u8);
|
||||
#endif
|
||||
int sqlite3VdbeMemTranslate(Mem*, u8);
|
||||
void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf);
|
||||
int sqlite3VdbeMemHandleBom(Mem *pMem);
|
||||
void sqlite3VdbeFifoInit(Fifo*);
|
||||
int sqlite3VdbeFifoPush(Fifo*, i64);
|
||||
int sqlite3VdbeFifoPop(Fifo*, i64*);
|
||||
void sqlite3VdbeFifoClear(Fifo*);
|
||||
|
||||
+295
-108
@@ -15,6 +15,20 @@
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** Return TRUE (non-zero) of the statement supplied as an argument needs
|
||||
** to be recompiled. A statement needs to be recompiled whenever the
|
||||
** execution environment changes in a way that would alter the program
|
||||
** that sqlite3_prepare() generates. For example, if new functions or
|
||||
** collating sequences are registered or if an authorizer function is
|
||||
** added or changed.
|
||||
*/
|
||||
int sqlite3_expired(sqlite3_stmt *pStmt){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
return p==0 || p->expired;
|
||||
}
|
||||
|
||||
/**************************** sqlite3_value_ *******************************
|
||||
** The following routines extract information from a Mem or sqlite3_value
|
||||
@@ -46,6 +60,7 @@ sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
|
||||
const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
|
||||
return (const char *)sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_value_text16(sqlite3_value* pVal){
|
||||
return sqlite3ValueText(pVal, SQLITE_UTF16NATIVE);
|
||||
}
|
||||
@@ -55,6 +70,7 @@ const void *sqlite3_value_text16be(sqlite3_value *pVal){
|
||||
const void *sqlite3_value_text16le(sqlite3_value *pVal){
|
||||
return sqlite3ValueText(pVal, SQLITE_UTF16LE);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
int sqlite3_value_type(sqlite3_value* pVal){
|
||||
return pVal->type;
|
||||
}
|
||||
@@ -69,7 +85,7 @@ void sqlite3_result_blob(
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
assert( n>0 );
|
||||
assert( n>=0 );
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, 0, xDel);
|
||||
}
|
||||
void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
|
||||
@@ -100,6 +116,7 @@ void sqlite3_result_text(
|
||||
){
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, xDel);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
void sqlite3_result_text16(
|
||||
sqlite3_context *pCtx,
|
||||
const void *z,
|
||||
@@ -124,6 +141,7 @@ void sqlite3_result_text16le(
|
||||
){
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16LE, xDel);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
|
||||
sqlite3VdbeMemCopy(&pCtx->s, pValue);
|
||||
}
|
||||
@@ -135,7 +153,7 @@ void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
|
||||
*/
|
||||
int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
sqlite *db;
|
||||
sqlite3 *db;
|
||||
int rc;
|
||||
|
||||
if( p==0 || p->magic!=VDBE_MAGIC_RUN ){
|
||||
@@ -144,18 +162,58 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
if( p->aborted ){
|
||||
return SQLITE_ABORT;
|
||||
}
|
||||
if( p->pc<=0 && p->expired ){
|
||||
if( p->rc==SQLITE_OK ){
|
||||
p->rc = SQLITE_SCHEMA;
|
||||
}
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
db = p->db;
|
||||
if( sqlite3SafetyOn(db) ){
|
||||
p->rc = SQLITE_MISUSE;
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( p->pc<0 ){
|
||||
#ifndef SQLITE_OMIT_TRACE
|
||||
/* Invoke the trace callback if there is one
|
||||
*/
|
||||
if( db->xTrace && !db->init.busy ){
|
||||
assert( p->nOp>0 );
|
||||
assert( p->aOp[p->nOp-1].opcode==OP_Noop );
|
||||
assert( p->aOp[p->nOp-1].p3!=0 );
|
||||
assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );
|
||||
sqlite3SafetyOff(db);
|
||||
db->xTrace(db->pTraceArg, p->aOp[p->nOp-1].p3);
|
||||
if( sqlite3SafetyOn(db) ){
|
||||
p->rc = SQLITE_MISUSE;
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
}
|
||||
if( db->xProfile && !db->init.busy ){
|
||||
double rNow;
|
||||
sqlite3OsCurrentTime(&rNow);
|
||||
p->startTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print a copy of SQL as it is executed if the SQL_TRACE pragma is turned
|
||||
** on in debugging mode.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
if( (db->flags & SQLITE_SqlTrace)!=0 ){
|
||||
sqlite3DebugPrintf("SQL-trace: %s\n", p->aOp[p->nOp-1].p3);
|
||||
}
|
||||
#endif /* SQLITE_DEBUG */
|
||||
|
||||
db->activeVdbeCnt++;
|
||||
p->pc = 0;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_EXPLAIN
|
||||
if( p->explain ){
|
||||
rc = sqlite3VdbeList(p);
|
||||
}else{
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_EXPLAIN */
|
||||
{
|
||||
rc = sqlite3VdbeExec(p);
|
||||
}
|
||||
|
||||
@@ -163,7 +221,24 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
|
||||
sqlite3Error(p->db, rc, p->zErrMsg);
|
||||
#ifndef SQLITE_OMIT_TRACE
|
||||
/* Invoke the profile callback if there is one
|
||||
*/
|
||||
if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy ){
|
||||
double rNow;
|
||||
u64 elapseTime;
|
||||
|
||||
sqlite3OsCurrentTime(&rNow);
|
||||
elapseTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0 - p->startTime;
|
||||
assert( p->nOp>0 );
|
||||
assert( p->aOp[p->nOp-1].opcode==OP_Noop );
|
||||
assert( p->aOp[p->nOp-1].p3!=0 );
|
||||
assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );
|
||||
db->xProfile(db->pProfileArg, p->aOp[p->nOp-1].p3, elapseTime);
|
||||
}
|
||||
#endif
|
||||
|
||||
sqlite3Error(p->db, rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -180,22 +255,27 @@ void *sqlite3_user_data(sqlite3_context *p){
|
||||
** Allocate or return the aggregate context for a user function. A new
|
||||
** context is allocated on the first call. Subsequent calls return the
|
||||
** same context that was returned on prior calls.
|
||||
**
|
||||
** This routine is defined here in vdbe.c because it depends on knowing
|
||||
** the internals of the sqlite3_context structure which is only defined in
|
||||
** this source file.
|
||||
*/
|
||||
void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){
|
||||
Mem *pMem = p->pMem;
|
||||
assert( p && p->pFunc && p->pFunc->xStep );
|
||||
if( p->pAgg==0 ){
|
||||
if( nByte<=NBFS ){
|
||||
p->pAgg = (void*)p->s.z;
|
||||
memset(p->pAgg, 0, nByte);
|
||||
if( (pMem->flags & MEM_Agg)==0 ){
|
||||
if( nByte==0 ){
|
||||
assert( pMem->flags==MEM_Null );
|
||||
pMem->z = 0;
|
||||
}else{
|
||||
p->pAgg = sqliteMalloc( nByte );
|
||||
pMem->flags = MEM_Agg;
|
||||
pMem->xDel = sqlite3FreeX;
|
||||
*(FuncDef**)&pMem->i = p->pFunc;
|
||||
if( nByte<=NBFS ){
|
||||
pMem->z = pMem->zShort;
|
||||
memset(pMem->z, 0, nByte);
|
||||
}else{
|
||||
pMem->z = sqliteMalloc( nByte );
|
||||
}
|
||||
}
|
||||
}
|
||||
return p->pAgg;
|
||||
return (void*)pMem->z;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -228,8 +308,9 @@ void sqlite3_set_auxdata(
|
||||
pVdbeFunc = pCtx->pVdbeFunc;
|
||||
if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
|
||||
int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
|
||||
pCtx->pVdbeFunc = pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc);
|
||||
pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc);
|
||||
if( !pVdbeFunc ) return;
|
||||
pCtx->pVdbeFunc = pVdbeFunc;
|
||||
memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0,
|
||||
sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux));
|
||||
pVdbeFunc->nAux = iArg+1;
|
||||
@@ -254,7 +335,7 @@ void sqlite3_set_auxdata(
|
||||
*/
|
||||
int sqlite3_aggregate_count(sqlite3_context *p){
|
||||
assert( p && p->pFunc && p->pFunc->xStep );
|
||||
return p->cnt;
|
||||
return p->pMem->n;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -319,77 +400,125 @@ sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
|
||||
const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_text( columnMem(pStmt,i) );
|
||||
}
|
||||
#if 0
|
||||
sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
|
||||
return columnMem(pStmt, i);
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_text16( columnMem(pStmt,i) );
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_type( columnMem(pStmt,i) );
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert the N-th element of pStmt->pColName[] into a string using
|
||||
** xFunc() then return that string. If N is out of range, return 0.
|
||||
**
|
||||
** There are up to 5 names for each column. useType determines which
|
||||
** name is returned. Here are the names:
|
||||
**
|
||||
** 0 The column name as it should be displayed for output
|
||||
** 1 The datatype name for the column
|
||||
** 2 The name of the database that the column derives from
|
||||
** 3 The name of the table that the column derives from
|
||||
** 4 The name of the table column that the result column derives from
|
||||
**
|
||||
** If the result is not a simple column reference (if it is an expression
|
||||
** or a constant) then useTypes 2, 3, and 4 return NULL.
|
||||
*/
|
||||
static const void *columnName(
|
||||
sqlite3_stmt *pStmt,
|
||||
int N,
|
||||
const void *(*xFunc)(Mem*),
|
||||
int useType
|
||||
){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
int n = sqlite3_column_count(pStmt);
|
||||
|
||||
if( p==0 || N>=n || N<0 ){
|
||||
return 0;
|
||||
}
|
||||
N += useType*n;
|
||||
return xFunc(&p->aColName[N]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Return the name of the Nth column of the result set returned by SQL
|
||||
** statement pStmt.
|
||||
*/
|
||||
const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pColName;
|
||||
|
||||
if( N>=sqlite3_column_count(pStmt) || N<0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
pColName = &(p->aColName[N]);
|
||||
return sqlite3_value_text(pColName);
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the name of the 'i'th column of the result set of SQL statement
|
||||
** pStmt, encoded as UTF-16.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pColName;
|
||||
|
||||
if( N>=sqlite3_column_count(pStmt) || N<0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
pColName = &(p->aColName[N]);
|
||||
return sqlite3_value_text16(pColName);
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Return the column declaration type (if applicable) of the 'i'th column
|
||||
** of the result set of SQL statement pStmt, encoded as UTF-8.
|
||||
** of the result set of SQL statement pStmt.
|
||||
*/
|
||||
const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pColName;
|
||||
|
||||
if( N>=sqlite3_column_count(pStmt) || N<0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
pColName = &(p->aColName[N+sqlite3_column_count(pStmt)]);
|
||||
return sqlite3_value_text(pColName);
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 1);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 1);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
#if !defined(SQLITE_OMIT_ORIGIN_NAMES) && 0
|
||||
/*
|
||||
** Return the name of the database from which a result column derives.
|
||||
** NULL is returned if the result column is an expression or constant or
|
||||
** anything else which is not an unabiguous reference to a database column.
|
||||
*/
|
||||
const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 2);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 2);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
/*
|
||||
** Return the column declaration type (if applicable) of the 'i'th column
|
||||
** of the result set of SQL statement pStmt, encoded as UTF-16.
|
||||
** Return the name of the table from which a result column derives.
|
||||
** NULL is returned if the result column is an expression or constant or
|
||||
** anything else which is not an unabiguous reference to a database column.
|
||||
*/
|
||||
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pColName;
|
||||
|
||||
if( N>=sqlite3_column_count(pStmt) || N<0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
pColName = &(p->aColName[N+sqlite3_column_count(pStmt)]);
|
||||
return sqlite3_value_text16(pColName);
|
||||
const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 3);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 3);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
/*
|
||||
** Return the name of the table column from which a result column derives.
|
||||
** NULL is returned if the result column is an expression or constant or
|
||||
** anything else which is not an unabiguous reference to a database column.
|
||||
*/
|
||||
const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 4);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 4);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
#endif /* SQLITE_OMIT_ORIGIN_NAMES */
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************* sqlite3_bind_ ***************************
|
||||
**
|
||||
@@ -406,7 +535,7 @@ const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
|
||||
static int vdbeUnbind(Vdbe *p, int i){
|
||||
Mem *pVar;
|
||||
if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
|
||||
sqlite3Error(p->db, SQLITE_MISUSE, 0);
|
||||
if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( i<1 || i>p->nVar ){
|
||||
@@ -422,14 +551,15 @@ static int vdbeUnbind(Vdbe *p, int i){
|
||||
}
|
||||
|
||||
/*
|
||||
** Bind a blob value to an SQL statement variable.
|
||||
** Bind a text or BLOB value.
|
||||
*/
|
||||
int sqlite3_bind_blob(
|
||||
static int bindText(
|
||||
sqlite3_stmt *pStmt,
|
||||
int i,
|
||||
const void *zData,
|
||||
int nData,
|
||||
void (*xDel)(void*)
|
||||
void (*xDel)(void*),
|
||||
int encoding
|
||||
){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pVar;
|
||||
@@ -440,9 +570,29 @@ int sqlite3_bind_blob(
|
||||
return rc;
|
||||
}
|
||||
pVar = &p->aVar[i-1];
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, 0, xDel);
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
if( rc==SQLITE_OK && encoding!=0 ){
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Bind a blob value to an SQL statement variable.
|
||||
*/
|
||||
int sqlite3_bind_blob(
|
||||
sqlite3_stmt *pStmt,
|
||||
int i,
|
||||
const void *zData,
|
||||
int nData,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
return bindText(pStmt, i, zData, nData, xDel, 0);
|
||||
}
|
||||
int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
|
||||
int rc;
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
@@ -474,22 +624,9 @@ int sqlite3_bind_text(
|
||||
int nData,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pVar;
|
||||
int rc;
|
||||
|
||||
rc = vdbeUnbind(p, i);
|
||||
if( rc || zData==0 ){
|
||||
return rc;
|
||||
}
|
||||
pVar = &p->aVar[i-1];
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, SQLITE_UTF8, xDel);
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc);
|
||||
return rc;
|
||||
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
int sqlite3_bind_text16(
|
||||
sqlite3_stmt *pStmt,
|
||||
int i,
|
||||
@@ -497,23 +634,9 @@ int sqlite3_bind_text16(
|
||||
int nData,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
Mem *pVar;
|
||||
int rc;
|
||||
|
||||
rc = vdbeUnbind(p, i);
|
||||
if( rc || zData==0 ){
|
||||
return rc;
|
||||
}
|
||||
pVar = &p->aVar[i-1];
|
||||
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, SQLITE_UTF16NATIVE, xDel);
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc);
|
||||
return rc;
|
||||
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
/*
|
||||
** Return the number of wildcards that can be potentially bound to.
|
||||
@@ -524,6 +647,25 @@ int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
|
||||
return p ? p->nVar : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a mapping from variable numbers to variable names
|
||||
** in the Vdbe.azVar[] array, if such a mapping does not already
|
||||
** exist.
|
||||
*/
|
||||
static void createVarMap(Vdbe *p){
|
||||
if( !p->okVar ){
|
||||
int j;
|
||||
Op *pOp;
|
||||
for(j=0, pOp=p->aOp; j<p->nOp; j++, pOp++){
|
||||
if( pOp->opcode==OP_Variable ){
|
||||
assert( pOp->p1>0 && pOp->p1<=p->nVar );
|
||||
p->azVar[pOp->p1-1] = pOp->p3;
|
||||
}
|
||||
}
|
||||
p->okVar = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the name of a wildcard parameter. Return NULL if the index
|
||||
** is out of range or if the wildcard is unnamed.
|
||||
@@ -535,16 +677,61 @@ const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
|
||||
if( p==0 || i<1 || i>p->nVar ){
|
||||
return 0;
|
||||
}
|
||||
if( !p->okVar ){
|
||||
int j;
|
||||
Op *pOp;
|
||||
for(j=0, pOp=p->aOp; j<p->nOp; j++, pOp++){
|
||||
if( pOp->opcode==OP_Variable ){
|
||||
assert( pOp->p1>0 && pOp->p1<=p->nVar );
|
||||
p->azVar[pOp->p1-1] = pOp->p3;
|
||||
}
|
||||
}
|
||||
p->okVar = 1;
|
||||
}
|
||||
createVarMap(p);
|
||||
return p->azVar[i-1];
|
||||
}
|
||||
|
||||
/*
|
||||
** Given a wildcard parameter name, return the index of the variable
|
||||
** with that name. If there is no variable with the given name,
|
||||
** return 0.
|
||||
*/
|
||||
int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
int i;
|
||||
if( p==0 ){
|
||||
return 0;
|
||||
}
|
||||
createVarMap(p);
|
||||
if( zName ){
|
||||
for(i=0; i<p->nVar; i++){
|
||||
const char *z = p->azVar[i];
|
||||
if( z && strcmp(z,zName)==0 ){
|
||||
return i+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Transfer all bindings from the first statement over to the second.
|
||||
** If the two statements contain a different number of bindings, then
|
||||
** an SQLITE_ERROR is returned.
|
||||
*/
|
||||
int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
|
||||
Vdbe *pFrom = (Vdbe*)pFromStmt;
|
||||
Vdbe *pTo = (Vdbe*)pToStmt;
|
||||
int i, rc = SQLITE_OK;
|
||||
if( (pFrom->magic!=VDBE_MAGIC_RUN && pFrom->magic!=VDBE_MAGIC_HALT)
|
||||
|| (pTo->magic!=VDBE_MAGIC_RUN && pTo->magic!=VDBE_MAGIC_HALT) ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( pFrom->nVar!=pTo->nVar ){
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
for(i=0; rc==SQLITE_OK && i<pFrom->nVar; i++){
|
||||
rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the sqlite3* database handle to which the prepared statement given
|
||||
** in the argument belongs. This is the same database handle that was
|
||||
** the first argument to the sqlite3_prepare() that was used to create
|
||||
** the statement in the first place.
|
||||
*/
|
||||
sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){
|
||||
return pStmt ? ((Vdbe*)pStmt)->db : 0;
|
||||
}
|
||||
|
||||
+475
-455
File diff suppressed because it is too large
Load Diff
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
** 2005 June 16
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file implements a FIFO queue of rowids used for processing
|
||||
** UPDATE and DELETE statements.
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
|
||||
/*
|
||||
** Allocate a new FifoPage and return a pointer to it. Return NULL if
|
||||
** we run out of memory. Leave space on the page for nEntry entries.
|
||||
*/
|
||||
static FifoPage *allocatePage(int nEntry){
|
||||
FifoPage *pPage;
|
||||
if( nEntry>32767 ){
|
||||
nEntry = 32767;
|
||||
}
|
||||
pPage = sqliteMallocRaw( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) );
|
||||
if( pPage ){
|
||||
pPage->nSlot = nEntry;
|
||||
pPage->iWrite = 0;
|
||||
pPage->iRead = 0;
|
||||
pPage->pNext = 0;
|
||||
}
|
||||
return pPage;
|
||||
}
|
||||
|
||||
/*
|
||||
** Initialize a Fifo structure.
|
||||
*/
|
||||
void sqlite3VdbeFifoInit(Fifo *pFifo){
|
||||
memset(pFifo, 0, sizeof(*pFifo));
|
||||
}
|
||||
|
||||
/*
|
||||
** Push a single 64-bit integer value into the Fifo. Return SQLITE_OK
|
||||
** normally. SQLITE_NOMEM is returned if we are unable to allocate
|
||||
** memory.
|
||||
*/
|
||||
int sqlite3VdbeFifoPush(Fifo *pFifo, i64 val){
|
||||
FifoPage *pPage;
|
||||
pPage = pFifo->pLast;
|
||||
if( pPage==0 ){
|
||||
pPage = pFifo->pLast = pFifo->pFirst = allocatePage(20);
|
||||
if( pPage==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
}else if( pPage->iWrite>=pPage->nSlot ){
|
||||
pPage->pNext = allocatePage(pFifo->nEntry);
|
||||
if( pPage->pNext==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pPage = pFifo->pLast = pPage->pNext;
|
||||
}
|
||||
pPage->aSlot[pPage->iWrite++] = val;
|
||||
pFifo->nEntry++;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Extract a single 64-bit integer value from the Fifo. The integer
|
||||
** extracted is the one least recently inserted. If the Fifo is empty
|
||||
** return SQLITE_DONE.
|
||||
*/
|
||||
int sqlite3VdbeFifoPop(Fifo *pFifo, i64 *pVal){
|
||||
FifoPage *pPage;
|
||||
if( pFifo->nEntry==0 ){
|
||||
return SQLITE_DONE;
|
||||
}
|
||||
assert( pFifo->nEntry>0 );
|
||||
pPage = pFifo->pFirst;
|
||||
assert( pPage!=0 );
|
||||
assert( pPage->iWrite>pPage->iRead );
|
||||
assert( pPage->iWrite<=pPage->nSlot );
|
||||
assert( pPage->iRead<pPage->nSlot );
|
||||
assert( pPage->iRead>=0 );
|
||||
*pVal = pPage->aSlot[pPage->iRead++];
|
||||
pFifo->nEntry--;
|
||||
if( pPage->iRead>=pPage->iWrite ){
|
||||
pFifo->pFirst = pPage->pNext;
|
||||
sqliteFree(pPage);
|
||||
if( pFifo->nEntry==0 ){
|
||||
assert( pFifo->pLast==pPage );
|
||||
pFifo->pLast = 0;
|
||||
}else{
|
||||
assert( pFifo->pFirst!=0 );
|
||||
}
|
||||
}else{
|
||||
assert( pFifo->nEntry>0 );
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete all information from a Fifo object. Free all memory held
|
||||
** by the Fifo.
|
||||
*/
|
||||
void sqlite3VdbeFifoClear(Fifo *pFifo){
|
||||
FifoPage *pPage, *pNextPage;
|
||||
for(pPage=pFifo->pFirst; pPage; pPage=pNextPage){
|
||||
pNextPage = pPage->pNext;
|
||||
sqliteFree(pPage);
|
||||
}
|
||||
sqlite3VdbeFifoInit(pFifo);
|
||||
}
|
||||
+130
-14
@@ -34,10 +34,21 @@
|
||||
** between formats.
|
||||
*/
|
||||
int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
|
||||
int rc;
|
||||
if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
return sqlite3VdbeMemTranslate(pMem, desiredEnc);
|
||||
#ifdef SQLITE_OMIT_UTF16
|
||||
return SQLITE_ERROR;
|
||||
#else
|
||||
rc = sqlite3VdbeMemTranslate(pMem, desiredEnc);
|
||||
if( rc==SQLITE_NOMEM ){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Null;
|
||||
pMem->z = 0;
|
||||
}
|
||||
return rc;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -163,7 +174,7 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
|
||||
*/
|
||||
if( fg & MEM_Real ){
|
||||
sqlite3_snprintf(NBFS, z, "%.15g", pMem->r);
|
||||
sqlite3_snprintf(NBFS, z, "%!.15g", pMem->r);
|
||||
}else{
|
||||
assert( fg & MEM_Int );
|
||||
sqlite3_snprintf(NBFS, z, "%lld", pMem->i);
|
||||
@@ -176,15 +187,45 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Memory cell pMem contains the context of an aggregate function.
|
||||
** This routine calls the finalize method for that function. The
|
||||
** result of the aggregate is stored back into pMem.
|
||||
*/
|
||||
void sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
|
||||
if( pFunc && pFunc->xFinalize ){
|
||||
sqlite3_context ctx;
|
||||
assert( (pMem->flags & MEM_Null)!=0 || pFunc==*(FuncDef**)&pMem->i );
|
||||
ctx.s.flags = MEM_Null;
|
||||
ctx.s.z = pMem->zShort;
|
||||
ctx.pMem = pMem;
|
||||
ctx.pFunc = pFunc;
|
||||
pFunc->xFinalize(&ctx);
|
||||
if( pMem->z && pMem->z!=pMem->zShort ){
|
||||
sqliteFree( pMem->z );
|
||||
}
|
||||
*pMem = ctx.s;
|
||||
if( pMem->flags & MEM_Short ){
|
||||
pMem->z = pMem->zShort;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Release any memory held by the Mem. This may leave the Mem in an
|
||||
** inconsistent state, for example with (Mem.z==0) and
|
||||
** (Mem.type==SQLITE_TEXT).
|
||||
*/
|
||||
void sqlite3VdbeMemRelease(Mem *p){
|
||||
if( p->flags & MEM_Dyn ){
|
||||
if( p->flags & (MEM_Dyn|MEM_Agg) ){
|
||||
if( p->xDel ){
|
||||
p->xDel((void *)p->z);
|
||||
if( p->flags & MEM_Agg ){
|
||||
sqlite3VdbeMemFinalize(p, *(FuncDef**)&p->i);
|
||||
assert( (p->flags & MEM_Agg)==0 );
|
||||
sqlite3VdbeMemRelease(p);
|
||||
}else{
|
||||
p->xDel((void *)p->z);
|
||||
}
|
||||
}else{
|
||||
sqliteFree(p->z);
|
||||
}
|
||||
@@ -245,12 +286,14 @@ double sqlite3VdbeRealValue(Mem *pMem){
|
||||
}else if( pMem->flags & MEM_Int ){
|
||||
return (double)pMem->i;
|
||||
}else if( pMem->flags & (MEM_Str|MEM_Blob) ){
|
||||
double val = 0.0;
|
||||
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|
||||
|| sqlite3VdbeMemNulTerminate(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( pMem->z );
|
||||
return sqlite3AtoF(pMem->z, 0);
|
||||
sqlite3AtoF(pMem->z, &val);
|
||||
return val;
|
||||
}else{
|
||||
return 0.0;
|
||||
}
|
||||
@@ -274,6 +317,7 @@ void sqlite3VdbeMemSetNull(Mem *pMem){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Null;
|
||||
pMem->type = SQLITE_NULL;
|
||||
pMem->n = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -390,9 +434,12 @@ int sqlite3VdbeMemSetStr(
|
||||
pMem->type = enc==0 ? SQLITE_BLOB : SQLITE_TEXT;
|
||||
pMem->n = n;
|
||||
|
||||
assert( enc==0 || enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE
|
||||
|| enc==SQLITE_UTF16BE );
|
||||
switch( enc ){
|
||||
case 0:
|
||||
pMem->flags |= MEM_Blob;
|
||||
pMem->enc = SQLITE_UTF8;
|
||||
break;
|
||||
|
||||
case SQLITE_UTF8:
|
||||
@@ -403,6 +450,7 @@ int sqlite3VdbeMemSetStr(
|
||||
}
|
||||
break;
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
case SQLITE_UTF16LE:
|
||||
case SQLITE_UTF16BE:
|
||||
pMem->flags |= MEM_Str;
|
||||
@@ -413,10 +461,7 @@ int sqlite3VdbeMemSetStr(
|
||||
if( sqlite3VdbeMemHandleBom(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
}
|
||||
if( pMem->flags&MEM_Ephem ){
|
||||
return sqlite3VdbeMemMakeWriteable(pMem);
|
||||
@@ -597,8 +642,13 @@ int sqlite3VdbeMemFromBtree(
|
||||
zData[amt] = 0;
|
||||
zData[amt+1] = 0;
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( amt>NBFS ){
|
||||
if( amt>NBFS-2 ){
|
||||
assert( zData!=pMem->zShort );
|
||||
assert( pMem->flags & MEM_Dyn );
|
||||
sqliteFree(zData);
|
||||
} else {
|
||||
assert( zData==pMem->zShort );
|
||||
assert( pMem->flags & MEM_Short );
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -650,9 +700,9 @@ void sqlite3VdbeMemSanity(Mem *pMem, u8 db_enc){
|
||||
/* MEM_Null excludes all other types */
|
||||
assert( (pMem->flags&(MEM_Str|MEM_Int|MEM_Real|MEM_Blob))==0
|
||||
|| (pMem->flags&MEM_Null)==0 );
|
||||
if( (pMem->flags & (MEM_Int|MEM_Real))==(MEM_Int|MEM_Real) ){
|
||||
assert( pMem->r==pMem->i );
|
||||
}
|
||||
/* If the MEM is both real and integer, the values are equal */
|
||||
assert( (pMem->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real)
|
||||
|| pMem->r==pMem->i );
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -680,7 +730,7 @@ const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
|
||||
/*
|
||||
** Create a new sqlite3_value object.
|
||||
*/
|
||||
sqlite3_value* sqlite3ValueNew(){
|
||||
sqlite3_value* sqlite3ValueNew(void){
|
||||
Mem *p = sqliteMalloc(sizeof(*p));
|
||||
if( p ){
|
||||
p->flags = MEM_Null;
|
||||
@@ -689,6 +739,72 @@ sqlite3_value* sqlite3ValueNew(){
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a new sqlite3_value object, containing the value of pExpr.
|
||||
**
|
||||
** This only works for very simple expressions that consist of one constant
|
||||
** token (i.e. "5", "5.1", "NULL", "'a string'"). If the expression can
|
||||
** be converted directly into a value, then the value is allocated and
|
||||
** a pointer written to *ppVal. The caller is responsible for deallocating
|
||||
** the value by passing it to sqlite3ValueFree() later on. If the expression
|
||||
** cannot be converted to a value, then *ppVal is set to NULL.
|
||||
*/
|
||||
int sqlite3ValueFromExpr(
|
||||
Expr *pExpr,
|
||||
u8 enc,
|
||||
u8 affinity,
|
||||
sqlite3_value **ppVal
|
||||
){
|
||||
int op;
|
||||
char *zVal = 0;
|
||||
sqlite3_value *pVal = 0;
|
||||
|
||||
if( !pExpr ){
|
||||
*ppVal = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
op = pExpr->op;
|
||||
|
||||
if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
|
||||
zVal = sqliteStrNDup(pExpr->token.z, pExpr->token.n);
|
||||
pVal = sqlite3ValueNew();
|
||||
if( !zVal || !pVal ) goto no_mem;
|
||||
sqlite3Dequote(zVal);
|
||||
sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, sqlite3FreeX);
|
||||
if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
|
||||
sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, enc);
|
||||
}else{
|
||||
sqlite3ValueApplyAffinity(pVal, affinity, enc);
|
||||
}
|
||||
}else if( op==TK_UMINUS ) {
|
||||
if( SQLITE_OK==sqlite3ValueFromExpr(pExpr->pLeft, enc, affinity, &pVal) ){
|
||||
pVal->i = -1 * pVal->i;
|
||||
pVal->r = -1.0 * pVal->r;
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_BLOB_LITERAL
|
||||
else if( op==TK_BLOB ){
|
||||
int nVal;
|
||||
pVal = sqlite3ValueNew();
|
||||
zVal = sqliteStrNDup(pExpr->token.z+1, pExpr->token.n-1);
|
||||
if( !zVal || !pVal ) goto no_mem;
|
||||
sqlite3Dequote(zVal);
|
||||
nVal = strlen(zVal)/2;
|
||||
sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(zVal), nVal, 0, sqlite3FreeX);
|
||||
sqliteFree(zVal);
|
||||
}
|
||||
#endif
|
||||
|
||||
*ppVal = pVal;
|
||||
return SQLITE_OK;
|
||||
|
||||
no_mem:
|
||||
sqliteFree(zVal);
|
||||
sqlite3ValueFree(pVal);
|
||||
*ppVal = 0;
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the string value of an sqlite3_value object
|
||||
*/
|
||||
|
||||
+1623
-783
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
# This script attempts to install SQLite3 so that it can be used
|
||||
# by TCL. Invoke this script with single argument which is the
|
||||
# version number of SQLite. Example:
|
||||
#
|
||||
# tclsh tclinstaller.tcl 3.0
|
||||
#
|
||||
set VERSION [lindex $argv 0]
|
||||
set LIBFILE .libs/libtclsqlite3[info sharedlibextension]
|
||||
if { ![info exists env(DESTDIR)] } { set env(DESTDIR) "" }
|
||||
set LIBDIR $env(DESTDIR)[lindex $auto_path 0]
|
||||
set LIBNAME [file tail $LIBFILE]
|
||||
set LIB $LIBDIR/sqlite3/$LIBNAME
|
||||
|
||||
file delete -force $LIBDIR/sqlite3
|
||||
file mkdir $LIBDIR/sqlite3
|
||||
set fd [open $LIBDIR/sqlite3/pkgIndex.tcl w]
|
||||
puts $fd "package ifneeded sqlite3 $VERSION \[list load $LIB sqlite3\]"
|
||||
close $fd
|
||||
|
||||
# We cannot use [file copy] because that will just make a copy of
|
||||
# a symbolic link. We have to open and copy the file for ourselves.
|
||||
#
|
||||
set in [open $LIBFILE]
|
||||
fconfigure $in -translation binary
|
||||
set out [open $LIB w]
|
||||
fconfigure $out -translation binary
|
||||
puts -nonewline $out [read $in]
|
||||
close $in
|
||||
close $out
|
||||
+18
-6
@@ -10,7 +10,7 @@
|
||||
#***********************************************************************
|
||||
# This file runs all tests.
|
||||
#
|
||||
# $Id: all.test,v 1.22 2004/08/31 13:45:12 drh Exp $
|
||||
# $Id: all.test,v 1.30 2005/01/17 07:53:44 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -50,13 +50,21 @@ set LeakList {}
|
||||
set EXCLUDE {
|
||||
all.test
|
||||
crash.test
|
||||
autovacuum_crash.test
|
||||
quick.test
|
||||
malloc.test
|
||||
misuse.test
|
||||
memleak.test
|
||||
corrupt.test
|
||||
}
|
||||
# btree2.test
|
||||
|
||||
# Test files btree2.test and btree4.test don't work if the
|
||||
# SQLITE_DEFAULT_AUTOVACUUM macro is defined to true (because they depend
|
||||
# on tables being allocated starting at page 2).
|
||||
#
|
||||
ifcapable default_autovacuum {
|
||||
lappend EXCLUDE btree2.test
|
||||
lappend EXCLUDE btree4.test
|
||||
}
|
||||
|
||||
for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} {
|
||||
if {$Counter%2} {
|
||||
@@ -81,7 +89,7 @@ for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} {
|
||||
}
|
||||
|
||||
# Do one last test to look for a memory leak in the library. This will
|
||||
# only work if SQLite is compiled with the -DMEMORY_DEBUG=1 flag.
|
||||
# only work if SQLite is compiled with the -DSQLITE_DEBUG=1 flag.
|
||||
#
|
||||
if {$LeakList!=""} {
|
||||
puts -nonewline memory-leak-test...
|
||||
@@ -99,10 +107,14 @@ if {$LeakList!=""} {
|
||||
puts " Ok"
|
||||
}
|
||||
|
||||
# Run the crashtest only on unix and only once.
|
||||
# Run the crashtest only on unix and only once. If the library does not
|
||||
# always create auto-vacuum databases, also run autovacuum_crash.test.
|
||||
#
|
||||
if {$tcl_platform(platform)=="unix"} {
|
||||
if {$::tcl_platform(platform)=="unix"} {
|
||||
source $testdir/crash.test
|
||||
ifcapable !default_autovacuum {
|
||||
source $testdir/autovacuum_crash.test
|
||||
}
|
||||
}
|
||||
|
||||
# Run the malloc tests and the misuse test after memory leak detection.
|
||||
|
||||
+554
@@ -0,0 +1,554 @@
|
||||
# 2004 November 10
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing the ALTER TABLE statement.
|
||||
#
|
||||
# $Id: alter.test,v 1.11 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
|
||||
ifcapable !altertable {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Test organization:
|
||||
#
|
||||
# alter-1.1.* - alter-1.7.*: Basic tests of ALTER TABLE, including tables
|
||||
# with implicit and explicit indices. These tests came from an earlier
|
||||
# fork of SQLite that also supported ALTER TABLE.
|
||||
# alter-1.8.*: Tests for ALTER TABLE when the table resides in an
|
||||
# attached database.
|
||||
# alter-1.9.*: Tests for ALTER TABLE when their is whitespace between the
|
||||
# table name and left parenthesis token. i.e:
|
||||
# "CREATE TABLE abc (a, b, c);"
|
||||
# alter-2.*: Test error conditions and messages.
|
||||
# alter-3.*: Test ALTER TABLE on tables that have TRIGGERs attached to them.
|
||||
# alter-4.*: Test ALTER TABLE on tables that have AUTOINCREMENT fields.
|
||||
#
|
||||
|
||||
# Create some tables to rename. Be sure to include some TEMP tables
|
||||
# and some tables with odd names.
|
||||
#
|
||||
do_test alter-1.1 {
|
||||
ifcapable tempdb {
|
||||
set ::temp TEMP
|
||||
} else {
|
||||
set ::temp {}
|
||||
}
|
||||
execsql [subst -nocommands {
|
||||
CREATE TABLE t1(a,b);
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
CREATE TABLE [t1'x1](c UNIQUE, b PRIMARY KEY);
|
||||
INSERT INTO [t1'x1] VALUES(3,4);
|
||||
CREATE INDEX t1i1 ON T1(B);
|
||||
CREATE INDEX t1i2 ON t1(a,b);
|
||||
CREATE INDEX i3 ON [t1'x1](b,c);
|
||||
CREATE $::temp TABLE "temp table"(e,f,g UNIQUE);
|
||||
CREATE INDEX i2 ON [temp table](f);
|
||||
INSERT INTO [temp table] VALUES(5,6,7);
|
||||
}]
|
||||
execsql {
|
||||
SELECT 't1', * FROM t1;
|
||||
SELECT 't1''x1', * FROM "t1'x1";
|
||||
SELECT * FROM [temp table];
|
||||
}
|
||||
} {t1 1 2 t1'x1 3 4 5 6 7}
|
||||
do_test alter-1.2 {
|
||||
execsql [subst {
|
||||
CREATE $::temp TABLE objlist(type, name, tbl_name);
|
||||
INSERT INTO objlist SELECT type, name, tbl_name
|
||||
FROM sqlite_master WHERE NAME!='objlist';
|
||||
}]
|
||||
ifcapable tempdb {
|
||||
execsql {
|
||||
INSERT INTO objlist SELECT type, name, tbl_name
|
||||
FROM sqlite_temp_master WHERE NAME!='objlist';
|
||||
}
|
||||
}
|
||||
|
||||
execsql {
|
||||
SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name;
|
||||
}
|
||||
} [list \
|
||||
table t1 t1 \
|
||||
index t1i1 t1 \
|
||||
index t1i2 t1 \
|
||||
table t1'x1 t1'x1 \
|
||||
index i3 t1'x1 \
|
||||
index {sqlite_autoindex_t1'x1_1} t1'x1 \
|
||||
index {sqlite_autoindex_t1'x1_2} t1'x1 \
|
||||
table {temp table} {temp table} \
|
||||
index i2 {temp table} \
|
||||
index {sqlite_autoindex_temp table_1} {temp table} \
|
||||
]
|
||||
|
||||
# Make some changes
|
||||
#
|
||||
do_test alter-1.3 {
|
||||
execsql {
|
||||
ALTER TABLE [T1] RENAME to [-t1-];
|
||||
ALTER TABLE "t1'x1" RENAME TO T2;
|
||||
ALTER TABLE [temp table] RENAME to TempTab;
|
||||
}
|
||||
} {}
|
||||
integrity_check alter-1.3.1
|
||||
do_test alter-1.4 {
|
||||
execsql {
|
||||
SELECT 't1', * FROM [-t1-];
|
||||
SELECT 't2', * FROM t2;
|
||||
SELECT * FROM temptab;
|
||||
}
|
||||
} {t1 1 2 t2 3 4 5 6 7}
|
||||
do_test alter-1.5 {
|
||||
execsql {
|
||||
DELETE FROM objlist;
|
||||
INSERT INTO objlist SELECT type, name, tbl_name
|
||||
FROM sqlite_master WHERE NAME!='objlist';
|
||||
}
|
||||
catchsql {
|
||||
INSERT INTO objlist SELECT type, name, tbl_name
|
||||
FROM sqlite_temp_master WHERE NAME!='objlist';
|
||||
}
|
||||
execsql {
|
||||
SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name;
|
||||
}
|
||||
} [list \
|
||||
table -t1- -t1- \
|
||||
index t1i1 -t1- \
|
||||
index t1i2 -t1- \
|
||||
table T2 T2 \
|
||||
index i3 T2 \
|
||||
index {sqlite_autoindex_T2_1} T2 \
|
||||
index {sqlite_autoindex_T2_2} T2 \
|
||||
table {TempTab} {TempTab} \
|
||||
index i2 {TempTab} \
|
||||
index {sqlite_autoindex_TempTab_1} {TempTab} \
|
||||
]
|
||||
|
||||
# Make sure the changes persist after restarting the database.
|
||||
# (The TEMP table will not persist, of course.)
|
||||
#
|
||||
ifcapable tempdb {
|
||||
do_test alter-1.6 {
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
execsql {
|
||||
CREATE TEMP TABLE objlist(type, name, tbl_name);
|
||||
INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
|
||||
INSERT INTO objlist
|
||||
SELECT type, name, tbl_name FROM sqlite_temp_master
|
||||
WHERE NAME!='objlist';
|
||||
SELECT type, name, tbl_name FROM objlist
|
||||
ORDER BY tbl_name, type desc, name;
|
||||
}
|
||||
} [list \
|
||||
table -t1- -t1- \
|
||||
index t1i1 -t1- \
|
||||
index t1i2 -t1- \
|
||||
table T2 T2 \
|
||||
index i3 T2 \
|
||||
index {sqlite_autoindex_T2_1} T2 \
|
||||
index {sqlite_autoindex_T2_2} T2 \
|
||||
]
|
||||
} else {
|
||||
execsql {
|
||||
DROP TABLE TempTab;
|
||||
}
|
||||
}
|
||||
|
||||
# Make sure the ALTER TABLE statements work with the
|
||||
# non-callback API
|
||||
#
|
||||
do_test alter-1.7 {
|
||||
stepsql $DB {
|
||||
ALTER TABLE [-t1-] RENAME to [*t1*];
|
||||
ALTER TABLE T2 RENAME TO [<t2>];
|
||||
}
|
||||
execsql {
|
||||
DELETE FROM objlist;
|
||||
INSERT INTO objlist SELECT type, name, tbl_name
|
||||
FROM sqlite_master WHERE NAME!='objlist';
|
||||
}
|
||||
catchsql {
|
||||
INSERT INTO objlist SELECT type, name, tbl_name
|
||||
FROM sqlite_temp_master WHERE NAME!='objlist';
|
||||
}
|
||||
execsql {
|
||||
SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name;
|
||||
}
|
||||
} [list \
|
||||
table *t1* *t1* \
|
||||
index t1i1 *t1* \
|
||||
index t1i2 *t1* \
|
||||
table <t2> <t2> \
|
||||
index i3 <t2> \
|
||||
index {sqlite_autoindex_<t2>_1} <t2> \
|
||||
index {sqlite_autoindex_<t2>_2} <t2> \
|
||||
]
|
||||
|
||||
# Check that ALTER TABLE works on attached databases.
|
||||
#
|
||||
do_test alter-1.8.1 {
|
||||
file delete -force test2.db
|
||||
file delete -force test2.db-journal
|
||||
execsql {
|
||||
ATTACH 'test2.db' AS aux;
|
||||
}
|
||||
} {}
|
||||
do_test alter-1.8.2 {
|
||||
execsql {
|
||||
CREATE TABLE t4(a PRIMARY KEY, b, c);
|
||||
CREATE TABLE aux.t4(a PRIMARY KEY, b, c);
|
||||
CREATE INDEX i4 ON t4(b);
|
||||
CREATE INDEX aux.i4 ON t4(b);
|
||||
}
|
||||
} {}
|
||||
do_test alter-1.8.3 {
|
||||
execsql {
|
||||
INSERT INTO t4 VALUES('main', 'main', 'main');
|
||||
INSERT INTO aux.t4 VALUES('aux', 'aux', 'aux');
|
||||
SELECT * FROM t4 WHERE a = 'main';
|
||||
}
|
||||
} {main main main}
|
||||
do_test alter-1.8.4 {
|
||||
execsql {
|
||||
ALTER TABLE t4 RENAME TO t5;
|
||||
SELECT * FROM t4 WHERE a = 'aux';
|
||||
}
|
||||
} {aux aux aux}
|
||||
do_test alter-1.8.5 {
|
||||
execsql {
|
||||
SELECT * FROM t5;
|
||||
}
|
||||
} {main main main}
|
||||
do_test alter-1.8.6 {
|
||||
execsql {
|
||||
SELECT * FROM t5 WHERE b = 'main';
|
||||
}
|
||||
} {main main main}
|
||||
do_test alter-1.8.7 {
|
||||
execsql {
|
||||
ALTER TABLE aux.t4 RENAME TO t5;
|
||||
SELECT * FROM aux.t5 WHERE b = 'aux';
|
||||
}
|
||||
} {aux aux aux}
|
||||
|
||||
do_test alter-1.9.1 {
|
||||
execsql {
|
||||
CREATE TABLE tbl1 (a, b, c);
|
||||
INSERT INTO tbl1 VALUES(1, 2, 3);
|
||||
}
|
||||
} {}
|
||||
do_test alter-1.9.2 {
|
||||
execsql {
|
||||
SELECT * FROM tbl1;
|
||||
}
|
||||
} {1 2 3}
|
||||
do_test alter-1.9.3 {
|
||||
execsql {
|
||||
ALTER TABLE tbl1 RENAME TO tbl2;
|
||||
SELECT * FROM tbl2;
|
||||
}
|
||||
} {1 2 3}
|
||||
do_test alter-1.9.4 {
|
||||
execsql {
|
||||
DROP TABLE tbl2;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Test error messages
|
||||
#
|
||||
do_test alter-2.1 {
|
||||
catchsql {
|
||||
ALTER TABLE none RENAME TO hi;
|
||||
}
|
||||
} {1 {no such table: none}}
|
||||
do_test alter-2.2 {
|
||||
execsql {
|
||||
CREATE TABLE t3(p,q,r);
|
||||
}
|
||||
catchsql {
|
||||
ALTER TABLE [<t2>] RENAME TO t3;
|
||||
}
|
||||
} {1 {there is already another table or index with this name: t3}}
|
||||
do_test alter-2.3 {
|
||||
catchsql {
|
||||
ALTER TABLE [<t2>] RENAME TO i3;
|
||||
}
|
||||
} {1 {there is already another table or index with this name: i3}}
|
||||
do_test alter-2.4 {
|
||||
catchsql {
|
||||
ALTER TABLE SqLiTe_master RENAME TO master;
|
||||
}
|
||||
} {1 {table sqlite_master may not be altered}}
|
||||
do_test alter-2.5 {
|
||||
catchsql {
|
||||
ALTER TABLE t3 RENAME TO sqlite_t3;
|
||||
}
|
||||
} {1 {object name reserved for internal use: sqlite_t3}}
|
||||
|
||||
# If this compilation does not include triggers, omit the alter-3.* tests.
|
||||
ifcapable trigger {
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Tests alter-3.* test ALTER TABLE on tables that have triggers.
|
||||
#
|
||||
# alter-3.1.*: ALTER TABLE with triggers.
|
||||
# alter-3.2.*: Test that the ON keyword cannot be used as a database,
|
||||
# table or column name unquoted. This is done because part of the
|
||||
# ALTER TABLE code (specifically the implementation of SQL function
|
||||
# "sqlite_alter_trigger") will break in this case.
|
||||
# alter-3.3.*: ALTER TABLE with TEMP triggers (todo).
|
||||
#
|
||||
|
||||
# An SQL user-function for triggers to fire, so that we know they
|
||||
# are working.
|
||||
proc trigfunc {args} {
|
||||
set ::TRIGGER $args
|
||||
}
|
||||
db func trigfunc trigfunc
|
||||
|
||||
do_test alter-3.1.0 {
|
||||
execsql {
|
||||
CREATE TABLE t6(a, b, c);
|
||||
CREATE TRIGGER trig1 AFTER INSERT ON t6 BEGIN
|
||||
SELECT trigfunc('trig1', new.a, new.b, new.c);
|
||||
END;
|
||||
}
|
||||
} {}
|
||||
do_test alter-3.1.1 {
|
||||
execsql {
|
||||
INSERT INTO t6 VALUES(1, 2, 3);
|
||||
}
|
||||
set ::TRIGGER
|
||||
} {trig1 1 2 3}
|
||||
do_test alter-3.1.2 {
|
||||
execsql {
|
||||
ALTER TABLE t6 RENAME TO t7;
|
||||
INSERT INTO t7 VALUES(4, 5, 6);
|
||||
}
|
||||
set ::TRIGGER
|
||||
} {trig1 4 5 6}
|
||||
do_test alter-3.1.3 {
|
||||
execsql {
|
||||
DROP TRIGGER trig1;
|
||||
}
|
||||
} {}
|
||||
do_test alter-3.1.4 {
|
||||
execsql {
|
||||
CREATE TRIGGER trig2 AFTER INSERT ON main.t7 BEGIN
|
||||
SELECT trigfunc('trig2', new.a, new.b, new.c);
|
||||
END;
|
||||
INSERT INTO t7 VALUES(1, 2, 3);
|
||||
}
|
||||
set ::TRIGGER
|
||||
} {trig2 1 2 3}
|
||||
do_test alter-3.1.5 {
|
||||
execsql {
|
||||
ALTER TABLE t7 RENAME TO t8;
|
||||
INSERT INTO t8 VALUES(4, 5, 6);
|
||||
}
|
||||
set ::TRIGGER
|
||||
} {trig2 4 5 6}
|
||||
do_test alter-3.1.6 {
|
||||
execsql {
|
||||
DROP TRIGGER trig2;
|
||||
}
|
||||
} {}
|
||||
do_test alter-3.1.7 {
|
||||
execsql {
|
||||
CREATE TRIGGER trig3 AFTER INSERT ON main.'t8'BEGIN
|
||||
SELECT trigfunc('trig3', new.a, new.b, new.c);
|
||||
END;
|
||||
INSERT INTO t8 VALUES(1, 2, 3);
|
||||
}
|
||||
set ::TRIGGER
|
||||
} {trig3 1 2 3}
|
||||
do_test alter-3.1.8 {
|
||||
execsql {
|
||||
ALTER TABLE t8 RENAME TO t9;
|
||||
INSERT INTO t9 VALUES(4, 5, 6);
|
||||
}
|
||||
set ::TRIGGER
|
||||
} {trig3 4 5 6}
|
||||
|
||||
# Make sure "ON" cannot be used as a database, table or column name without
|
||||
# quoting. Otherwise the sqlite_alter_trigger() function might not work.
|
||||
file delete -force test3.db
|
||||
file delete -force test3.db-journal
|
||||
do_test alter-3.2.1 {
|
||||
catchsql {
|
||||
ATTACH 'test3.db' AS ON;
|
||||
}
|
||||
} {1 {near "ON": syntax error}}
|
||||
do_test alter-3.2.2 {
|
||||
catchsql {
|
||||
ATTACH 'test3.db' AS 'ON';
|
||||
}
|
||||
} {0 {}}
|
||||
do_test alter-3.2.3 {
|
||||
catchsql {
|
||||
CREATE TABLE ON.t1(a, b, c);
|
||||
}
|
||||
} {1 {near "ON": syntax error}}
|
||||
do_test alter-3.2.4 {
|
||||
catchsql {
|
||||
CREATE TABLE 'ON'.t1(a, b, c);
|
||||
}
|
||||
} {0 {}}
|
||||
do_test alter-3.2.4 {
|
||||
catchsql {
|
||||
CREATE TABLE 'ON'.ON(a, b, c);
|
||||
}
|
||||
} {1 {near "ON": syntax error}}
|
||||
do_test alter-3.2.5 {
|
||||
catchsql {
|
||||
CREATE TABLE 'ON'.'ON'(a, b, c);
|
||||
}
|
||||
} {0 {}}
|
||||
do_test alter-3.2.6 {
|
||||
catchsql {
|
||||
CREATE TABLE t10(a, ON, c);
|
||||
}
|
||||
} {1 {near "ON": syntax error}}
|
||||
do_test alter-3.2.7 {
|
||||
catchsql {
|
||||
CREATE TABLE t10(a, 'ON', c);
|
||||
}
|
||||
} {0 {}}
|
||||
do_test alter-3.2.8 {
|
||||
catchsql {
|
||||
CREATE TRIGGER trig4 AFTER INSERT ON ON BEGIN SELECT 1; END;
|
||||
}
|
||||
} {1 {near "ON": syntax error}}
|
||||
do_test alter-3.2.9 {
|
||||
catchsql {
|
||||
CREATE TRIGGER 'on'.trig4 AFTER INSERT ON 'ON' BEGIN SELECT 1; END;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test alter-3.2.10 {
|
||||
execsql {
|
||||
DROP TABLE t10;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test alter-3.3.1 {
|
||||
execsql [subst {
|
||||
CREATE TABLE tbl1(a, b, c);
|
||||
CREATE $::temp TRIGGER trig1 AFTER INSERT ON tbl1 BEGIN
|
||||
SELECT trigfunc('trig1', new.a, new.b, new.c);
|
||||
END;
|
||||
}]
|
||||
} {}
|
||||
do_test alter-3.3.2 {
|
||||
execsql {
|
||||
INSERT INTO tbl1 VALUES('a', 'b', 'c');
|
||||
}
|
||||
set ::TRIGGER
|
||||
} {trig1 a b c}
|
||||
do_test alter-3.3.3 {
|
||||
execsql {
|
||||
ALTER TABLE tbl1 RENAME TO tbl2;
|
||||
INSERT INTO tbl2 VALUES('d', 'e', 'f');
|
||||
}
|
||||
set ::TRIGGER
|
||||
} {trig1 d e f}
|
||||
do_test alter-3.3.4 {
|
||||
execsql [subst {
|
||||
CREATE $::temp TRIGGER trig2 AFTER UPDATE ON tbl2 BEGIN
|
||||
SELECT trigfunc('trig2', new.a, new.b, new.c);
|
||||
END;
|
||||
}]
|
||||
} {}
|
||||
do_test alter-3.3.5 {
|
||||
execsql {
|
||||
ALTER TABLE tbl2 RENAME TO tbl3;
|
||||
INSERT INTO tbl3 VALUES('g', 'h', 'i');
|
||||
}
|
||||
set ::TRIGGER
|
||||
} {trig1 g h i}
|
||||
do_test alter-3.3.6 {
|
||||
execsql {
|
||||
UPDATE tbl3 SET a = 'G' where a = 'g';
|
||||
}
|
||||
set ::TRIGGER
|
||||
} {trig2 G h i}
|
||||
do_test alter-3.3.7 {
|
||||
execsql {
|
||||
DROP TABLE tbl3;
|
||||
}
|
||||
} {}
|
||||
ifcapable tempdb {
|
||||
do_test alter-3.3.8 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_temp_master WHERE type = 'trigger';
|
||||
}
|
||||
} {}
|
||||
}
|
||||
|
||||
} ;# ifcapable trigger
|
||||
|
||||
# If the build does not include AUTOINCREMENT fields, omit alter-4.*.
|
||||
ifcapable autoinc {
|
||||
|
||||
do_test alter-4.1 {
|
||||
execsql {
|
||||
CREATE TABLE tbl1(a INTEGER PRIMARY KEY AUTOINCREMENT);
|
||||
INSERT INTO tbl1 VALUES(10);
|
||||
}
|
||||
} {}
|
||||
do_test alter-4.2 {
|
||||
execsql {
|
||||
INSERT INTO tbl1 VALUES(NULL);
|
||||
SELECT a FROM tbl1;
|
||||
}
|
||||
} {10 11}
|
||||
do_test alter-4.3 {
|
||||
execsql {
|
||||
ALTER TABLE tbl1 RENAME TO tbl2;
|
||||
DELETE FROM tbl2;
|
||||
INSERT INTO tbl2 VALUES(NULL);
|
||||
SELECT a FROM tbl2;
|
||||
}
|
||||
} {12}
|
||||
do_test alter-4.4 {
|
||||
execsql {
|
||||
DROP TABLE tbl2;
|
||||
}
|
||||
} {}
|
||||
|
||||
} ;# ifcapable autoinc
|
||||
|
||||
# Test that it is Ok to execute an ALTER TABLE immediately after
|
||||
# opening a database.
|
||||
do_test alter-5.1 {
|
||||
execsql {
|
||||
CREATE TABLE tbl1(a, b, c);
|
||||
INSERT INTO tbl1 VALUES('x', 'y', 'z');
|
||||
}
|
||||
} {}
|
||||
do_test alter-5.2 {
|
||||
sqlite3 db2 test.db
|
||||
execsql {
|
||||
ALTER TABLE tbl1 RENAME TO tbl2;
|
||||
SELECT * FROM tbl2;
|
||||
} db2
|
||||
} {x y z}
|
||||
do_test alter-5.3 {
|
||||
db2 close
|
||||
} {}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,438 @@
|
||||
# 2005 February 18
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing that SQLite can handle a subtle
|
||||
# file format change that may be used in the future to implement
|
||||
# "ALTER TABLE ... ADD COLUMN".
|
||||
#
|
||||
# $Id: alter2.test,v 1.4 2005/03/10 12:52:47 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# We have to have pragmas in order to do this test
|
||||
ifcapable {!pragma} return
|
||||
|
||||
# These tests do not work if there is a codec. The
|
||||
# btree_open command does not know how to handle codecs.
|
||||
#
|
||||
if {[catch {sqlite3 -has_codec} r] || $r} return
|
||||
|
||||
# The file format change affects the way row-records stored in tables (but
|
||||
# not indices) are interpreted. Before version 3.1.3, a row-record for a
|
||||
# table with N columns was guaranteed to contain exactly N fields. As
|
||||
# of version 3.1.3, the record may contain up to N fields. In this case
|
||||
# the M fields that are present are the values for the left-most M
|
||||
# columns. The (N-M) rightmost columns contain NULL.
|
||||
#
|
||||
# If any records in the database contain less fields than their table
|
||||
# has columns, then the file-format meta value should be set to (at least) 2.
|
||||
#
|
||||
|
||||
# This procedure sets the value of the file-format in file 'test.db'
|
||||
# to $newval. Also, the schema cookie is incremented.
|
||||
#
|
||||
proc set_file_format {newval} {
|
||||
set bt [btree_open test.db 10 0]
|
||||
btree_begin_transaction $bt
|
||||
set meta [btree_get_meta $bt]
|
||||
lset meta 2 $newval ;# File format
|
||||
lset meta 1 [expr [lindex $meta 1]+1] ;# Schema cookie
|
||||
eval "btree_update_meta $bt $meta"
|
||||
btree_commit $bt
|
||||
btree_close $bt
|
||||
}
|
||||
|
||||
# This procedure returns the value of the file-format in file 'test.db'.
|
||||
#
|
||||
proc get_file_format {{fname test.db}} {
|
||||
set bt [btree_open $fname 10 0]
|
||||
set meta [btree_get_meta $bt]
|
||||
btree_close $bt
|
||||
lindex $meta 2
|
||||
}
|
||||
|
||||
# This procedure sets the SQL statement stored for table $tbl in the
|
||||
# sqlite_master table of file 'test.db' to $sql. Also set the file format
|
||||
# to the supplied value. This is 2 if the added column has a default that is
|
||||
# NULL, or 3 otherwise.
|
||||
#
|
||||
proc alter_table {tbl sql {file_format 2}} {
|
||||
sqlite3 dbat test.db
|
||||
puts one
|
||||
dbat eval {
|
||||
PRAGMA writable_schema = 1;
|
||||
UPDATE sqlite_master SET sql = $sql WHERE name = $tbl AND type = 'table';
|
||||
PRAGMA writable_schema = 0;
|
||||
}
|
||||
puts two
|
||||
dbat close
|
||||
puts three
|
||||
set_file_format 2
|
||||
puts four
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Some basic tests to make sure short rows are handled.
|
||||
#
|
||||
do_test alter2-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE abc(a, b);
|
||||
INSERT INTO abc VALUES(1, 2);
|
||||
INSERT INTO abc VALUES(3, 4);
|
||||
INSERT INTO abc VALUES(5, 6);
|
||||
}
|
||||
} {}
|
||||
do_test alter2-1.2 {
|
||||
# ALTER TABLE abc ADD COLUMN c;
|
||||
alter_table abc {CREATE TABLE abc(a, b, c);}
|
||||
} {}
|
||||
exit
|
||||
do_test alter2-1.3 {
|
||||
execsql {
|
||||
SELECT * FROM abc;
|
||||
}
|
||||
} {1 2 {} 3 4 {} 5 6 {}}
|
||||
do_test alter2-1.4 {
|
||||
execsql {
|
||||
UPDATE abc SET c = 10 WHERE a = 1;
|
||||
SELECT * FROM abc;
|
||||
}
|
||||
} {1 2 10 3 4 {} 5 6 {}}
|
||||
do_test alter2-1.5 {
|
||||
execsql {
|
||||
CREATE INDEX abc_i ON abc(c);
|
||||
}
|
||||
} {}
|
||||
do_test alter2-1.6 {
|
||||
execsql {
|
||||
SELECT c FROM abc ORDER BY c;
|
||||
}
|
||||
} {{} {} 10}
|
||||
do_test alter2-1.7 {
|
||||
execsql {
|
||||
SELECT * FROM abc WHERE c = 10;
|
||||
}
|
||||
} {1 2 10}
|
||||
do_test alter2-1.8 {
|
||||
execsql {
|
||||
SELECT sum(a), c FROM abc GROUP BY c;
|
||||
}
|
||||
} {8.0 {} 1.0 10}
|
||||
do_test alter2-1.9 {
|
||||
# ALTER TABLE abc ADD COLUMN d;
|
||||
alter_table abc {CREATE TABLE abc(a, b, c, d);}
|
||||
execsql { SELECT * FROM abc; }
|
||||
execsql {
|
||||
UPDATE abc SET d = 11 WHERE c IS NULL AND a<4;
|
||||
SELECT * FROM abc;
|
||||
}
|
||||
} {1 2 10 {} 3 4 {} 11 5 6 {} {}}
|
||||
do_test alter2-1.10 {
|
||||
execsql {
|
||||
SELECT typeof(d) FROM abc;
|
||||
}
|
||||
} {null integer null}
|
||||
do_test alter2-1.99 {
|
||||
execsql {
|
||||
DROP TABLE abc;
|
||||
}
|
||||
} {}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Test that views work when the underlying table structure is changed.
|
||||
#
|
||||
ifcapable view {
|
||||
do_test alter2-2.1 {
|
||||
execsql {
|
||||
CREATE TABLE abc2(a, b, c);
|
||||
INSERT INTO abc2 VALUES(1, 2, 10);
|
||||
INSERT INTO abc2 VALUES(3, 4, NULL);
|
||||
INSERT INTO abc2 VALUES(5, 6, NULL);
|
||||
CREATE VIEW abc2_v AS SELECT * FROM abc2;
|
||||
SELECT * FROM abc2_v;
|
||||
}
|
||||
} {1 2 10 3 4 {} 5 6 {}}
|
||||
do_test alter2-2.2 {
|
||||
# ALTER TABLE abc ADD COLUMN d;
|
||||
alter_table abc2 {CREATE TABLE abc2(a, b, c, d);}
|
||||
execsql {
|
||||
SELECT * FROM abc2_v;
|
||||
}
|
||||
} {1 2 10 {} 3 4 {} {} 5 6 {} {}}
|
||||
do_test alter2-2.3 {
|
||||
execsql {
|
||||
DROP TABLE abc2;
|
||||
DROP VIEW abc2_v;
|
||||
}
|
||||
} {}
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Test that triggers work when a short row is copied to the old.*
|
||||
# trigger pseudo-table.
|
||||
#
|
||||
ifcapable trigger {
|
||||
do_test alter2-3.1 {
|
||||
execsql {
|
||||
CREATE TABLE abc3(a, b);
|
||||
CREATE TABLE blog(o, n);
|
||||
CREATE TRIGGER abc3_t AFTER UPDATE OF b ON abc3 BEGIN
|
||||
INSERT INTO blog VALUES(old.b, new.b);
|
||||
END;
|
||||
}
|
||||
} {}
|
||||
do_test alter2-3.2 {
|
||||
execsql {
|
||||
INSERT INTO abc3 VALUES(1, 4);
|
||||
UPDATE abc3 SET b = 2 WHERE b = 4;
|
||||
SELECT * FROM blog;
|
||||
}
|
||||
} {4 2}
|
||||
do_test alter2-3.3 {
|
||||
execsql {
|
||||
INSERT INTO abc3 VALUES(3, 4);
|
||||
INSERT INTO abc3 VALUES(5, 6);
|
||||
}
|
||||
alter_table abc3 {CREATE TABLE abc3(a, b, c);}
|
||||
execsql {
|
||||
SELECT * FROM abc3;
|
||||
}
|
||||
} {1 2 {} 3 4 {} 5 6 {}}
|
||||
do_test alter2-3.4 {
|
||||
execsql {
|
||||
UPDATE abc3 SET b = b*2 WHERE a<4;
|
||||
SELECT * FROM abc3;
|
||||
}
|
||||
} {1 4 {} 3 8 {} 5 6 {}}
|
||||
do_test alter2-3.5 {
|
||||
execsql {
|
||||
SELECT * FROM blog;
|
||||
}
|
||||
} {4 2 2 4 4 8}
|
||||
|
||||
do_test alter2-3.6 {
|
||||
execsql {
|
||||
CREATE TABLE clog(o, n);
|
||||
CREATE TRIGGER abc3_t2 AFTER UPDATE OF c ON abc3 BEGIN
|
||||
INSERT INTO clog VALUES(old.c, new.c);
|
||||
END;
|
||||
UPDATE abc3 SET c = a*2;
|
||||
SELECT * FROM clog;
|
||||
}
|
||||
} {{} 2 {} 6 {} 10}
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Check that an error occurs if the database is upgraded to a file
|
||||
# format that SQLite does not support (in this case 4). Note: The
|
||||
# file format is checked each time the schema is read, so changing the
|
||||
# file format requires incrementing the schema cookie.
|
||||
#
|
||||
do_test alter2-4.1 {
|
||||
set_file_format 4
|
||||
} {}
|
||||
do_test alter2-4.2 {
|
||||
catchsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
} {1 {unsupported file format}}
|
||||
do_test alter2-4.3 {
|
||||
sqlite3_errcode $::DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test alter2-4.4 {
|
||||
db close
|
||||
set ::DB [sqlite3 db test.db]
|
||||
catchsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
} {1 {unsupported file format}}
|
||||
do_test alter2-4.5 {
|
||||
sqlite3_errcode $::DB
|
||||
} {SQLITE_ERROR}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Check that executing VACUUM on a file with file-format version 2
|
||||
# resets the file format to 1.
|
||||
#
|
||||
do_test alter2-5.1 {
|
||||
set_file_format 2
|
||||
get_file_format
|
||||
} {2}
|
||||
do_test alter2-5.2 {
|
||||
execsql {
|
||||
VACUUM;
|
||||
}
|
||||
} {}
|
||||
do_test alter2-5.3 {
|
||||
get_file_format
|
||||
} {1}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Test that when a database with file-format 2 is opened, new
|
||||
# databases are still created with file-format 1.
|
||||
#
|
||||
do_test alter2-6.1 {
|
||||
db close
|
||||
set_file_format 2
|
||||
set ::DB [sqlite3 db test.db]
|
||||
get_file_format
|
||||
} {2}
|
||||
do_test alter2-6.2 {
|
||||
file delete -force test2.db-journal
|
||||
file delete -force test2.db
|
||||
execsql {
|
||||
ATTACH 'test2.db' AS aux;
|
||||
CREATE TABLE aux.t1(a, b);
|
||||
}
|
||||
get_file_format test2.db
|
||||
} {1}
|
||||
do_test alter2-6.3 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
}
|
||||
get_file_format
|
||||
} {2}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Test that types and values for columns added with default values
|
||||
# other than NULL work with SELECT statements.
|
||||
#
|
||||
do_test alter2-7.1 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a);
|
||||
INSERT INTO t1 VALUES(1);
|
||||
INSERT INTO t1 VALUES(2);
|
||||
INSERT INTO t1 VALUES(3);
|
||||
INSERT INTO t1 VALUES(4);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 2 3 4}
|
||||
do_test alter2-7.2 {
|
||||
set sql {CREATE TABLE t1(a, b DEFAULT '123', c INTEGER DEFAULT '123')}
|
||||
alter_table t1 $sql 3
|
||||
execsql {
|
||||
SELECT * FROM t1 LIMIT 1;
|
||||
}
|
||||
} {1 123 123}
|
||||
do_test alter2-7.3 {
|
||||
execsql {
|
||||
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
|
||||
}
|
||||
} {1 integer 123 text 123 integer}
|
||||
do_test alter2-7.4 {
|
||||
execsql {
|
||||
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
|
||||
}
|
||||
} {1 integer 123 text 123 integer}
|
||||
do_test alter2-7.5 {
|
||||
set sql {CREATE TABLE t1(a, b DEFAULT -123.0, c VARCHAR(10) default 5)}
|
||||
alter_table t1 $sql 3
|
||||
execsql {
|
||||
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
|
||||
}
|
||||
} {1 integer -123.0 real 5 text}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Test that UPDATE trigger tables work with default values, and that when
|
||||
# a row is updated the default values are correctly transfered to the
|
||||
# new row.
|
||||
#
|
||||
ifcapable trigger {
|
||||
db function set_val {set ::val}
|
||||
do_test alter2-8.1 {
|
||||
execsql {
|
||||
CREATE TRIGGER trig1 BEFORE UPDATE ON t1 BEGIN
|
||||
SELECT set_val(
|
||||
old.b||' '||typeof(old.b)||' '||old.c||' '||typeof(old.c)||' '||
|
||||
new.b||' '||typeof(new.b)||' '||new.c||' '||typeof(new.c)
|
||||
);
|
||||
END;
|
||||
}
|
||||
list
|
||||
} {}
|
||||
}
|
||||
do_test alter2-8.2 {
|
||||
execsql {
|
||||
UPDATE t1 SET c = 10 WHERE a = 1;
|
||||
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
|
||||
}
|
||||
} {1 integer -123.0 real 10 text}
|
||||
ifcapable trigger {
|
||||
do_test alter2-8.3 {
|
||||
set ::val
|
||||
} {-123 real 5 text -123 real 10 text}
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Test that DELETE trigger tables work with default values, and that when
|
||||
# a row is updated the default values are correctly transfered to the
|
||||
# new row.
|
||||
#
|
||||
ifcapable trigger {
|
||||
do_test alter2-9.1 {
|
||||
execsql {
|
||||
CREATE TRIGGER trig2 BEFORE DELETE ON t1 BEGIN
|
||||
SELECT set_val(
|
||||
old.b||' '||typeof(old.b)||' '||old.c||' '||typeof(old.c)
|
||||
);
|
||||
END;
|
||||
}
|
||||
list
|
||||
} {}
|
||||
do_test alter2-9.2 {
|
||||
execsql {
|
||||
DELETE FROM t1 WHERE a = 2;
|
||||
}
|
||||
set ::val
|
||||
} {-123 real 5 text}
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Test creating an index on a column added with a default value.
|
||||
#
|
||||
do_test alter2-10.1 {
|
||||
execsql {
|
||||
CREATE TABLE t2(a);
|
||||
INSERT INTO t2 VALUES('a');
|
||||
INSERT INTO t2 VALUES('b');
|
||||
INSERT INTO t2 VALUES('c');
|
||||
INSERT INTO t2 VALUES('d');
|
||||
}
|
||||
alter_table t2 {CREATE TABLE t2(a, b DEFAULT X'ABCD', c DEFAULT NULL);} 3
|
||||
catchsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
execsql {
|
||||
SELECT quote(a), quote(b), quote(c) FROM t2 LIMIT 1;
|
||||
}
|
||||
} {'a' X'ABCD' NULL}
|
||||
do_test alter2-10.2 {
|
||||
execsql {
|
||||
CREATE INDEX i1 ON t2(b);
|
||||
SELECT a FROM t2 WHERE b = X'ABCD';
|
||||
}
|
||||
} {a b c d}
|
||||
do_test alter2-10.3 {
|
||||
execsql {
|
||||
DELETE FROM t2 WHERE a = 'c';
|
||||
SELECT a FROM t2 WHERE b = X'ABCD';
|
||||
}
|
||||
} {a b d}
|
||||
do_test alter2-10.4 {
|
||||
execsql {
|
||||
SELECT count(b) FROM t2 WHERE b = X'ABCD';
|
||||
}
|
||||
} {3}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,380 @@
|
||||
# 2005 February 19
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing that SQLite can handle a subtle
|
||||
# file format change that may be used in the future to implement
|
||||
# "ALTER TABLE ... ADD COLUMN".
|
||||
#
|
||||
# $Id: alter3.test,v 1.6 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
|
||||
ifcapable !altertable {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Determine if there is a codec available on this test.
|
||||
#
|
||||
if {[catch {sqlite3 -has_codec} r] || $r} {
|
||||
set has_codec 1
|
||||
} else {
|
||||
set has_codec 0
|
||||
}
|
||||
|
||||
|
||||
# Test Organisation:
|
||||
# ------------------
|
||||
#
|
||||
# alter3-1.*: Test that ALTER TABLE correctly modifies the CREATE TABLE sql.
|
||||
# alter3-2.*: Test error messages.
|
||||
# alter3-3.*: Test adding columns with default value NULL.
|
||||
# alter3-4.*: Test adding columns with default values other than NULL.
|
||||
# alter3-5.*: Test adding columns to tables in ATTACHed databases.
|
||||
# alter3-6.*: Test that temp triggers are not accidentally dropped.
|
||||
# alter3-7.*: Test that VACUUM resets the file-format.
|
||||
#
|
||||
|
||||
# This procedure returns the value of the file-format in file 'test.db'.
|
||||
#
|
||||
proc get_file_format {{fname test.db}} {
|
||||
set bt [btree_open $fname 10 0]
|
||||
set meta [btree_get_meta $bt]
|
||||
btree_close $bt
|
||||
lindex $meta 2
|
||||
}
|
||||
|
||||
do_test alter3-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE abc(a, b, c);
|
||||
SELECT sql FROM sqlite_master;
|
||||
}
|
||||
} {{CREATE TABLE abc(a, b, c)}}
|
||||
do_test alter3-1.2 {
|
||||
execsql {ALTER TABLE abc ADD d INTEGER;}
|
||||
execsql {
|
||||
SELECT sql FROM sqlite_master;
|
||||
}
|
||||
} {{CREATE TABLE abc(a, b, c, d INTEGER)}}
|
||||
do_test alter3-1.3 {
|
||||
execsql {ALTER TABLE abc ADD e}
|
||||
execsql {
|
||||
SELECT sql FROM sqlite_master;
|
||||
}
|
||||
} {{CREATE TABLE abc(a, b, c, d INTEGER, e)}}
|
||||
do_test alter3-1.4 {
|
||||
execsql {
|
||||
CREATE TABLE main.t1(a, b);
|
||||
ALTER TABLE t1 ADD c;
|
||||
SELECT sql FROM sqlite_master WHERE tbl_name = 't1';
|
||||
}
|
||||
} {{CREATE TABLE t1(a, b, c)}}
|
||||
do_test alter3-1.5 {
|
||||
execsql {
|
||||
ALTER TABLE t1 ADD d CHECK (a>d);
|
||||
SELECT sql FROM sqlite_master WHERE tbl_name = 't1';
|
||||
}
|
||||
} {{CREATE TABLE t1(a, b, c, d CHECK (a>d))}}
|
||||
do_test alter3-1.6 {
|
||||
execsql {
|
||||
CREATE TABLE t2(a, b, UNIQUE(a, b));
|
||||
ALTER TABLE t2 ADD c REFERENCES t1(c) ;
|
||||
SELECT sql FROM sqlite_master WHERE tbl_name = 't2' AND type = 'table';
|
||||
}
|
||||
} {{CREATE TABLE t2(a, b, c REFERENCES t1(c), UNIQUE(a, b))}}
|
||||
do_test alter3-1.7 {
|
||||
execsql {
|
||||
CREATE TABLE t3(a, b, UNIQUE(a, b));
|
||||
ALTER TABLE t3 ADD COLUMN c VARCHAR(10, 20);
|
||||
SELECT sql FROM sqlite_master WHERE tbl_name = 't3' AND type = 'table';
|
||||
}
|
||||
} {{CREATE TABLE t3(a, b, c VARCHAR(10, 20), UNIQUE(a, b))}}
|
||||
do_test alter3-1.99 {
|
||||
execsql {
|
||||
DROP TABLE abc;
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
DROP TABLE t3;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test alter3-2.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
}
|
||||
catchsql {
|
||||
ALTER TABLE t1 ADD c PRIMARY KEY;
|
||||
}
|
||||
} {1 {Cannot add a PRIMARY KEY column}}
|
||||
do_test alter3-2.2 {
|
||||
catchsql {
|
||||
ALTER TABLE t1 ADD c UNIQUE
|
||||
}
|
||||
} {1 {Cannot add a UNIQUE column}}
|
||||
do_test alter3-2.3 {
|
||||
catchsql {
|
||||
ALTER TABLE t1 ADD b VARCHAR(10)
|
||||
}
|
||||
} {1 {duplicate column name: b}}
|
||||
do_test alter3-2.3 {
|
||||
catchsql {
|
||||
ALTER TABLE t1 ADD c NOT NULL;
|
||||
}
|
||||
} {1 {Cannot add a NOT NULL column with default value NULL}}
|
||||
do_test alter3-2.4 {
|
||||
catchsql {
|
||||
ALTER TABLE t1 ADD c NOT NULL DEFAULT 10;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test alter3-2.5 {
|
||||
execsql {
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
}
|
||||
catchsql {
|
||||
alter table v1 add column d;
|
||||
}
|
||||
} {1 {Cannot add a column to a view}}
|
||||
do_test alter3-2.6 {
|
||||
catchsql {
|
||||
alter table t1 add column d DEFAULT CURRENT_TIME;
|
||||
}
|
||||
} {1 {Cannot add a column with non-constant default}}
|
||||
do_test alter3-2.99 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test alter3-3.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
INSERT INTO t1 VALUES(1, 100);
|
||||
INSERT INTO t1 VALUES(2, 300);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 100 2 300}
|
||||
do_test alter3-3.1 {
|
||||
execsql {
|
||||
PRAGMA schema_version = 10;
|
||||
}
|
||||
} {}
|
||||
do_test alter3-3.2 {
|
||||
execsql {
|
||||
ALTER TABLE t1 ADD c;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 100 {} 2 300 {}}
|
||||
if {!$has_codec} {
|
||||
do_test alter3-3.3 {
|
||||
get_file_format
|
||||
} {3}
|
||||
}
|
||||
do_test alter3-3.4 {
|
||||
execsql {
|
||||
PRAGMA schema_version;
|
||||
}
|
||||
} {11}
|
||||
|
||||
do_test alter3-4.1 {
|
||||
db close
|
||||
file delete -force test.db
|
||||
set ::DB [sqlite3 db test.db]
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
INSERT INTO t1 VALUES(1, 100);
|
||||
INSERT INTO t1 VALUES(2, 300);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 100 2 300}
|
||||
do_test alter3-4.1 {
|
||||
execsql {
|
||||
PRAGMA schema_version = 20;
|
||||
}
|
||||
} {}
|
||||
do_test alter3-4.2 {
|
||||
execsql {
|
||||
ALTER TABLE t1 ADD c DEFAULT 'hello world';
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 100 {hello world} 2 300 {hello world}}
|
||||
if {!$has_codec} {
|
||||
do_test alter3-4.3 {
|
||||
get_file_format
|
||||
} {3}
|
||||
}
|
||||
do_test alter3-4.4 {
|
||||
execsql {
|
||||
PRAGMA schema_version;
|
||||
}
|
||||
} {21}
|
||||
do_test alter3-4.99 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test alter3-5.1 {
|
||||
file delete -force test2.db
|
||||
file delete -force test2.db-journal
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
INSERT INTO t1 VALUES(1, 'one');
|
||||
INSERT INTO t1 VALUES(2, 'two');
|
||||
ATTACH 'test2.db' AS aux;
|
||||
CREATE TABLE aux.t1 AS SELECT * FROM t1;
|
||||
PRAGMA aux.schema_version = 30;
|
||||
SELECT sql FROM aux.sqlite_master;
|
||||
}
|
||||
} {{CREATE TABLE t1(a,b)}}
|
||||
do_test alter3-5.2 {
|
||||
execsql {
|
||||
ALTER TABLE aux.t1 ADD COLUMN c VARCHAR(128);
|
||||
SELECT sql FROM aux.sqlite_master;
|
||||
}
|
||||
} {{CREATE TABLE t1(a,b, c VARCHAR(128))}}
|
||||
do_test alter3-5.3 {
|
||||
execsql {
|
||||
SELECT * FROM aux.t1;
|
||||
}
|
||||
} {1 one {} 2 two {}}
|
||||
do_test alter3-5.4 {
|
||||
execsql {
|
||||
PRAGMA aux.schema_version;
|
||||
}
|
||||
} {31}
|
||||
if {!$has_codec} {
|
||||
do_test alter3-5.5 {
|
||||
list [get_file_format test2.db] [get_file_format]
|
||||
} {2 3}
|
||||
}
|
||||
do_test alter3-5.6 {
|
||||
execsql {
|
||||
ALTER TABLE aux.t1 ADD COLUMN d DEFAULT 1000;
|
||||
SELECT sql FROM aux.sqlite_master;
|
||||
}
|
||||
} {{CREATE TABLE t1(a,b, c VARCHAR(128), d DEFAULT 1000)}}
|
||||
do_test alter3-5.7 {
|
||||
execsql {
|
||||
SELECT * FROM aux.t1;
|
||||
}
|
||||
} {1 one {} 1000 2 two {} 1000}
|
||||
do_test alter3-5.8 {
|
||||
execsql {
|
||||
PRAGMA aux.schema_version;
|
||||
}
|
||||
} {32}
|
||||
do_test alter3-5.9 {
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 one 2 two}
|
||||
do_test alter3-5.99 {
|
||||
execsql {
|
||||
DROP TABLE aux.t1;
|
||||
DROP TABLE t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Test that the table schema is correctly reloaded when a column
|
||||
# is added to a table.
|
||||
#
|
||||
ifcapable trigger&&tempdb {
|
||||
do_test alter3-6.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE TABLE log(trig, a, b);
|
||||
|
||||
CREATE TRIGGER t1_a AFTER INSERT ON t1 BEGIN
|
||||
INSERT INTO log VALUES('a', new.a, new.b);
|
||||
END;
|
||||
CREATE TEMP TRIGGER t1_b AFTER INSERT ON t1 BEGIN
|
||||
INSERT INTO log VALUES('b', new.a, new.b);
|
||||
END;
|
||||
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
SELECT * FROM log;
|
||||
}
|
||||
} {b 1 2 a 1 2}
|
||||
do_test alter3-6.2 {
|
||||
execsql {
|
||||
ALTER TABLE t1 ADD COLUMN c DEFAULT 'c';
|
||||
INSERT INTO t1(a, b) VALUES(3, 4);
|
||||
SELECT * FROM log;
|
||||
}
|
||||
} {b 1 2 a 1 2 b 3 4 a 3 4}
|
||||
}
|
||||
|
||||
if {!$has_codec} {
|
||||
ifcapable vacuum {
|
||||
do_test alter3-7.1 {
|
||||
execsql {
|
||||
VACUUM;
|
||||
}
|
||||
get_file_format
|
||||
} {1}
|
||||
do_test alter3-7.2 {
|
||||
execsql {
|
||||
CREATE TABLE abc(a, b, c);
|
||||
ALTER TABLE abc ADD d DEFAULT NULL;
|
||||
}
|
||||
get_file_format
|
||||
} {2}
|
||||
do_test alter3-7.3 {
|
||||
execsql {
|
||||
ALTER TABLE abc ADD e DEFAULT 10;
|
||||
}
|
||||
get_file_format
|
||||
} {3}
|
||||
do_test alter3-7.4 {
|
||||
execsql {
|
||||
ALTER TABLE abc ADD f DEFAULT NULL;
|
||||
}
|
||||
get_file_format
|
||||
} {3}
|
||||
do_test alter3-7.5 {
|
||||
execsql {
|
||||
VACUUM;
|
||||
}
|
||||
get_file_format
|
||||
} {1}
|
||||
}
|
||||
}
|
||||
|
||||
# Ticket #1183 - Make sure adding columns to large tables does not cause
|
||||
# memory corruption (as was the case before this bug was fixed).
|
||||
do_test alter3-8.1 {
|
||||
execsql {
|
||||
CREATE TABLE t4(c1);
|
||||
}
|
||||
} {}
|
||||
do_test alter3-8.2 {
|
||||
set cols c1
|
||||
for {set i 2} {$i < 100} {incr i} {
|
||||
execsql "
|
||||
ALTER TABLE t4 ADD c$i
|
||||
"
|
||||
lappend cols c$i
|
||||
}
|
||||
set ::sql "CREATE TABLE t4([join $cols {, }])"
|
||||
list
|
||||
} {}
|
||||
do_test alter3-8.2 {
|
||||
execsql {
|
||||
SELECT sql FROM sqlite_master WHERE name = 't4';
|
||||
}
|
||||
} [list $::sql]
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,126 @@
|
||||
# 2005 September 19
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing the ALTER TABLE statement and
|
||||
# specifically out-of-memory conditions within that command.
|
||||
#
|
||||
# $Id: altermalloc.test,v 1.2 2005/08/21 18:21:50 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Only run these tests if memory debugging is turned on.
|
||||
#
|
||||
if {[info command sqlite_malloc_stat]==""} {
|
||||
puts "Skipping malloc tests: not compiled with -DSQLITE_DEBUG..."
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
|
||||
ifcapable !altertable {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Usage: do_malloc_test <test name> <options...>
|
||||
#
|
||||
# The first argument, <test number>, is an integer used to name the
|
||||
# tests executed by this proc. Options are as follows:
|
||||
#
|
||||
# -tclprep TCL script to run to prepare test.
|
||||
# -sqlprep SQL script to run to prepare test.
|
||||
# -tclbody TCL script to run with malloc failure simulation.
|
||||
# -sqlbody TCL script to run with malloc failure simulation.
|
||||
# -cleanup TCL script to run after the test.
|
||||
#
|
||||
# This command runs a series of tests to verify SQLite's ability
|
||||
# to handle an out-of-memory condition gracefully. It is assumed
|
||||
# that if this condition occurs a malloc() call will return a
|
||||
# NULL pointer. Linux, for example, doesn't do that by default. See
|
||||
# the "BUGS" section of malloc(3).
|
||||
#
|
||||
# Each iteration of a loop, the TCL commands in any argument passed
|
||||
# to the -tclbody switch, followed by the SQL commands in any argument
|
||||
# passed to the -sqlbody switch are executed. Each iteration the
|
||||
# Nth call to sqliteMalloc() is made to fail, where N is increased
|
||||
# each time the loop runs starting from 1. When all commands execute
|
||||
# successfully, the loop ends.
|
||||
#
|
||||
proc do_malloc_test {tn args} {
|
||||
array set ::mallocopts $args
|
||||
|
||||
set ::go 1
|
||||
for {set ::n 1} {$::go} {incr ::n} {
|
||||
|
||||
do_test $tn.$::n {
|
||||
|
||||
sqlite_malloc_fail 0
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
catch {file delete -force test2.db}
|
||||
catch {file delete -force test2.db-journal}
|
||||
set ::DB [sqlite3 db test.db]
|
||||
|
||||
if {[info exists ::mallocopts(-tclprep)]} {
|
||||
eval $::mallocopts(-tclprep)
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlprep)]} {
|
||||
execsql $::mallocopts(-sqlprep)
|
||||
}
|
||||
|
||||
sqlite_malloc_fail $::n
|
||||
set ::mallocbody {}
|
||||
if {[info exists ::mallocopts(-tclbody)]} {
|
||||
append ::mallocbody "$::mallocopts(-tclbody)\n"
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlbody)]} {
|
||||
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
|
||||
}
|
||||
|
||||
set v [catch $::mallocbody msg]
|
||||
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
set v {1 1}
|
||||
} else {
|
||||
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
}
|
||||
} {1 1}
|
||||
sqlite_malloc_fail 0
|
||||
|
||||
if {[info exists ::mallocopts(-cleanup)]} {
|
||||
catch $::mallocopts(-cleanup)
|
||||
}
|
||||
}
|
||||
unset ::mallocopts
|
||||
}
|
||||
|
||||
do_malloc_test altermalloc-1 -tclprep {
|
||||
db close
|
||||
} -tclbody {
|
||||
if {[catch {sqlite3 db test.db}]} {
|
||||
error "out of memory"
|
||||
}
|
||||
} -sqlbody {
|
||||
CREATE TABLE t1(a int);
|
||||
ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL;
|
||||
ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text';
|
||||
ALTER TABLE t1 RENAME TO t2;
|
||||
}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,257 @@
|
||||
# 2005 July 22
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
# This file implements tests for the ANALYZE command.
|
||||
#
|
||||
# $Id: analyze.test,v 1.5 2005/09/10 22:40:54 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# There is nothing to test if ANALYZE is disable for this build.
|
||||
#
|
||||
ifcapable {!analyze} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Basic sanity checks.
|
||||
#
|
||||
do_test analyze-1.1 {
|
||||
catchsql {
|
||||
ANALYZE no_such_table
|
||||
}
|
||||
} {1 {no such table: no_such_table}}
|
||||
do_test analyze-1.2 {
|
||||
execsql {
|
||||
SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1'
|
||||
}
|
||||
} {0}
|
||||
do_test analyze-1.3 {
|
||||
catchsql {
|
||||
ANALYZE no_such_db.no_such_table
|
||||
}
|
||||
} {1 {unknown database no_such_db}}
|
||||
do_test analyze-1.4 {
|
||||
execsql {
|
||||
SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1'
|
||||
}
|
||||
} {0}
|
||||
do_test analyze-1.5.1 {
|
||||
catchsql {
|
||||
ANALYZE
|
||||
}
|
||||
} {0 {}}
|
||||
do_test analyze-1.5.2 {
|
||||
catchsql {
|
||||
PRAGMA empty_result_callbacks=1;
|
||||
ANALYZE
|
||||
}
|
||||
} {0 {}}
|
||||
do_test analyze-1.6 {
|
||||
execsql {
|
||||
SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1'
|
||||
}
|
||||
} {1}
|
||||
do_test analyze-1.7 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_stat1
|
||||
}
|
||||
} {}
|
||||
do_test analyze-1.8 {
|
||||
catchsql {
|
||||
ANALYZE main
|
||||
}
|
||||
} {0 {}}
|
||||
do_test analyze-1.9 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_stat1
|
||||
}
|
||||
} {}
|
||||
do_test analyze-1.10 {
|
||||
catchsql {
|
||||
CREATE TABLE t1(a,b);
|
||||
ANALYZE main.t1;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test analyze-1.11 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_stat1
|
||||
}
|
||||
} {}
|
||||
do_test analyze-1.12 {
|
||||
catchsql {
|
||||
ANALYZE t1;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test analyze-1.13 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_stat1
|
||||
}
|
||||
} {}
|
||||
|
||||
# Create some indices that can be analyzed. But do not yet add
|
||||
# data. Without data in the tables, no analysis is done.
|
||||
#
|
||||
do_test analyze-2.1 {
|
||||
execsql {
|
||||
CREATE INDEX t1i1 ON t1(a);
|
||||
ANALYZE main.t1;
|
||||
SELECT * FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {}
|
||||
do_test analyze-2.2 {
|
||||
execsql {
|
||||
CREATE INDEX t1i2 ON t1(b);
|
||||
ANALYZE t1;
|
||||
SELECT * FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {}
|
||||
do_test analyze-2.3 {
|
||||
execsql {
|
||||
CREATE INDEX t1i3 ON t1(a,b);
|
||||
ANALYZE main;
|
||||
SELECT * FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Start adding data to the table. Verify that the analysis
|
||||
# is done correctly.
|
||||
#
|
||||
do_test analyze-3.1 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
INSERT INTO t1 VALUES(1,3);
|
||||
ANALYZE main.t1;
|
||||
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {t1i1 {2 2} t1i2 {2 1} t1i3 {2 2 1}}
|
||||
do_test analyze-3.2 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(1,4);
|
||||
INSERT INTO t1 VALUES(1,5);
|
||||
ANALYZE t1;
|
||||
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {t1i1 {4 4} t1i2 {4 1} t1i3 {4 4 1}}
|
||||
do_test analyze-3.3 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(2,5);
|
||||
ANALYZE main;
|
||||
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1}}
|
||||
do_test analyze-3.4 {
|
||||
execsql {
|
||||
CREATE TABLE t2 AS SELECT * FROM t1;
|
||||
CREATE INDEX t2i1 ON t2(a);
|
||||
CREATE INDEX t2i2 ON t2(b);
|
||||
CREATE INDEX t2i3 ON t2(a,b);
|
||||
ANALYZE;
|
||||
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2} t2i3 {5 3 1}}
|
||||
do_test analyze-3.5 {
|
||||
execsql {
|
||||
DROP INDEX t2i3;
|
||||
ANALYZE t1;
|
||||
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2} t2i3 {5 3 1}}
|
||||
do_test analyze-3.6 {
|
||||
execsql {
|
||||
ANALYZE t2;
|
||||
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2}}
|
||||
do_test analyze-3.7 {
|
||||
execsql {
|
||||
DROP INDEX t2i2;
|
||||
ANALYZE t2;
|
||||
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3}}
|
||||
do_test analyze-3.8 {
|
||||
execsql {
|
||||
CREATE TABLE t3 AS SELECT a, b, rowid AS c, 'hi' AS d FROM t1;
|
||||
CREATE INDEX t3i1 ON t3(a);
|
||||
CREATE INDEX t3i2 ON t3(a,b,c,d);
|
||||
CREATE INDEX t3i3 ON t3(d,b,c,a);
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
ANALYZE;
|
||||
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}}
|
||||
|
||||
# Try corrupting the sqlite_stat1 table and make sure the
|
||||
# database is still able to function.
|
||||
#
|
||||
do_test analyze-4.0 {
|
||||
sqlite3 db2 test.db
|
||||
db2 eval {
|
||||
CREATE TABLE t4(x,y,z);
|
||||
CREATE INDEX t4i1 ON t4(x);
|
||||
CREATE INDEX t4i2 ON t4(y);
|
||||
INSERT INTO t4 SELECT a,b,c FROM t3;
|
||||
}
|
||||
db2 close
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
ANALYZE;
|
||||
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
|
||||
}
|
||||
} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1} t4i1 {5 3} t4i2 {5 2}}
|
||||
do_test analyze-4.1 {
|
||||
execsql {
|
||||
PRAGMA writable_schema=on;
|
||||
INSERT INTO sqlite_stat1 VALUES(null,null,null);
|
||||
PRAGMA writable_schema=off;
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
SELECT * FROM t4 WHERE x=1234;
|
||||
}
|
||||
} {}
|
||||
do_test analyze-4.2 {
|
||||
execsql {
|
||||
PRAGMA writable_schema=on;
|
||||
DELETE FROM sqlite_stat1;
|
||||
INSERT INTO sqlite_stat1 VALUES('t4','t4i1','nonsense');
|
||||
INSERT INTO sqlite_stat1 VALUES('t4','t4i2','120897349817238741092873198273409187234918720394817209384710928374109827172901827349871928741910');
|
||||
PRAGMA writable_schema=off;
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
SELECT * FROM t4 WHERE x=1234;
|
||||
}
|
||||
} {}
|
||||
|
||||
# This test corrupts the database file so it must be the last test
|
||||
# in the series.
|
||||
#
|
||||
do_test analyze-99.1 {
|
||||
execsql {
|
||||
PRAGMA writable_schema=on;
|
||||
UPDATE sqlite_master SET sql='nonsense';
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
catchsql {
|
||||
ANALYZE
|
||||
}
|
||||
} {1 {malformed database schema - near "nonsense": syntax error}}
|
||||
|
||||
|
||||
finish_test
|
||||
+214
-88
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach.test,v 1.26 2004/08/18 15:58:24 drh Exp $
|
||||
# $Id: attach.test,v 1.40 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -80,7 +80,7 @@ do_test attach-1.9 {
|
||||
} {0 {}}
|
||||
do_test attach-1.10 {
|
||||
catchsql {
|
||||
DETACH DATABASE three;
|
||||
DETACH DATABASE [three];
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach-1.11 {
|
||||
@@ -102,9 +102,11 @@ proc db_list {db} {
|
||||
}
|
||||
return $list
|
||||
}
|
||||
ifcapable schema_pragmas {
|
||||
do_test attach-1.11b {
|
||||
db_list db
|
||||
} {0 main 2 db2 3 db3 4 db4 5 db5 6 db6 7 db7 8 db8 9 db9}
|
||||
} ;# ifcapable schema_pragmas
|
||||
do_test attach-1.12 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as db2;
|
||||
@@ -125,11 +127,13 @@ do_test attach-1.15 {
|
||||
ATTACH 'test.db' as main;
|
||||
}
|
||||
} {1 {database main is already in use}}
|
||||
do_test attach-1.16 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as temp;
|
||||
}
|
||||
} {1 {database temp is already in use}}
|
||||
ifcapable tempdb {
|
||||
do_test attach-1.16 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as temp;
|
||||
}
|
||||
} {1 {database temp is already in use}}
|
||||
}
|
||||
do_test attach-1.17 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as MAIN;
|
||||
@@ -150,9 +154,16 @@ do_test attach-1.20.1 {
|
||||
execsql {
|
||||
DETACH db5;
|
||||
}
|
||||
} {}
|
||||
ifcapable schema_pragmas {
|
||||
do_test attach-1.20.2 {
|
||||
db_list db
|
||||
} {0 main 2 db2 3 db3 4 db4 5 db6 6 db7 7 db8 8 db9 9 db10 10 db11}
|
||||
integrity_check attach-1.20.2
|
||||
} ;# ifcapable schema_pragmas
|
||||
integrity_check attach-1.20.3
|
||||
ifcapable tempdb {
|
||||
execsql {select * from sqlite_temp_master}
|
||||
}
|
||||
do_test attach-1.21 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as db12;
|
||||
@@ -165,7 +176,7 @@ do_test attach-1.22 {
|
||||
} {1 {too many attached databases - max 10}}
|
||||
do_test attach-1.23 {
|
||||
catchsql {
|
||||
DETACH db14;
|
||||
DETACH "db14";
|
||||
}
|
||||
} {1 {no such database: db14}}
|
||||
do_test attach-1.24 {
|
||||
@@ -183,11 +194,21 @@ do_test attach-1.26 {
|
||||
DETACH main;
|
||||
}
|
||||
} {1 {cannot detach database main}}
|
||||
do_test attach-1.27 {
|
||||
catchsql {
|
||||
DETACH Temp;
|
||||
}
|
||||
} {1 {cannot detach database Temp}}
|
||||
|
||||
ifcapable tempdb {
|
||||
do_test attach-1.27 {
|
||||
catchsql {
|
||||
DETACH Temp;
|
||||
}
|
||||
} {1 {cannot detach database Temp}}
|
||||
} else {
|
||||
do_test attach-1.27 {
|
||||
catchsql {
|
||||
DETACH Temp;
|
||||
}
|
||||
} {1 {no such database: Temp}}
|
||||
}
|
||||
|
||||
do_test attach-1.28 {
|
||||
catchsql {
|
||||
DETACH db11;
|
||||
@@ -201,10 +222,19 @@ do_test attach-1.28 {
|
||||
DETACH db2;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach-1.29 {
|
||||
db_list db
|
||||
} {0 main 1 temp}
|
||||
ifcapable schema_pragmas {
|
||||
ifcapable tempdb {
|
||||
do_test attach-1.29 {
|
||||
db_list db
|
||||
} {0 main 1 temp}
|
||||
} else {
|
||||
do_test attach-1.29 {
|
||||
db_list db
|
||||
} {0 main}
|
||||
}
|
||||
} ;# ifcapable schema_pragmas
|
||||
|
||||
ifcapable {trigger} { # Only do the following tests if triggers are enabled
|
||||
do_test attach-2.1 {
|
||||
execsql {
|
||||
CREATE TABLE tx(x1,x2,y1,y2);
|
||||
@@ -247,9 +277,18 @@ do_test attach-2.7 {
|
||||
SELECT type, name, tbl_name FROM db2.sqlite_master;
|
||||
}
|
||||
} {table t2 t2 table tx tx trigger r1 t2}
|
||||
do_test attach-2.8 {
|
||||
db_list db
|
||||
} {0 main 1 temp 2 db2}
|
||||
|
||||
ifcapable schema_pragmas&&tempdb {
|
||||
do_test attach-2.8 {
|
||||
db_list db
|
||||
} {0 main 1 temp 2 db2}
|
||||
} ;# ifcapable schema_pragmas&&tempdb
|
||||
ifcapable schema_pragmas&&!tempdb {
|
||||
do_test attach-2.8 {
|
||||
db_list db
|
||||
} {0 main 2 db2}
|
||||
} ;# ifcapable schema_pragmas&&!tempdb
|
||||
|
||||
do_test attach-2.9 {
|
||||
execsql {
|
||||
CREATE INDEX i2 ON t2(x);
|
||||
@@ -266,9 +305,17 @@ do_test attach-2.10 {
|
||||
# SELECT * FROM t2 WHERE x>5;
|
||||
# }
|
||||
#} {1 {database schema has changed}}
|
||||
do_test attach-2.12 {
|
||||
db_list db
|
||||
} {0 main 1 temp 2 db2}
|
||||
ifcapable schema_pragmas {
|
||||
ifcapable tempdb {
|
||||
do_test attach-2.12 {
|
||||
db_list db
|
||||
} {0 main 1 temp 2 db2}
|
||||
} else {
|
||||
do_test attach-2.12 {
|
||||
db_list db
|
||||
} {0 main 2 db2}
|
||||
}
|
||||
} ;# ifcapable schema_pragmas
|
||||
do_test attach-2.13 {
|
||||
catchsql {
|
||||
SELECT * FROM t2 WHERE x>5;
|
||||
@@ -292,6 +339,7 @@ do_test attach-2.16 {
|
||||
SELECT type, name, tbl_name FROM db2.sqlite_master;
|
||||
}
|
||||
} {table t2 t2 table tx tx trigger r1 t2 index i2 t2}
|
||||
} ;# End of ifcapable {trigger}
|
||||
|
||||
do_test attach-3.1 {
|
||||
db close
|
||||
@@ -302,6 +350,24 @@ do_test attach-3.1 {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 2 3 4}
|
||||
|
||||
# If we are testing a version of the code that lacks trigger support,
|
||||
# adjust the database contents so that they are the same if triggers
|
||||
# had been enabled.
|
||||
ifcapable {!trigger} {
|
||||
db2 eval {
|
||||
DELETE FROM t2;
|
||||
INSERT INTO t2 VALUES(21, 'x');
|
||||
INSERT INTO t2 VALUES(22, 'y');
|
||||
CREATE TABLE tx(x1,x2,y1,y2);
|
||||
INSERT INTO tx VALUES(1, 11, 'x', 'x');
|
||||
INSERT INTO tx VALUES(2, 12, 'y', 'y');
|
||||
INSERT INTO tx VALUES(11, 21, 'x', 'x');
|
||||
INSERT INTO tx VALUES(12, 22, 'y', 'y');
|
||||
CREATE INDEX i2 ON t2(x);
|
||||
}
|
||||
}
|
||||
|
||||
do_test attach-3.2 {
|
||||
catchsql {
|
||||
SELECT * FROM t2
|
||||
@@ -327,6 +393,7 @@ do_test attach-3.4 {
|
||||
# prevent test2.db from being read by db2.
|
||||
do_test attach-3.5 {
|
||||
execsql {SELECT * FROM t2}
|
||||
btree_breakpoint
|
||||
catchsql {
|
||||
SELECT * FROM t2;
|
||||
} db2;
|
||||
@@ -434,29 +501,48 @@ do_test attach-4.5 {
|
||||
SELECT * FROM db2.t3;
|
||||
}
|
||||
} {1 2 9 10}
|
||||
do_test attach-4.6 {
|
||||
execsql {
|
||||
DETACH db2;
|
||||
}
|
||||
execsql {
|
||||
DETACH db2;
|
||||
}
|
||||
ifcapable {trigger} {
|
||||
do_test attach-4.6 {
|
||||
execsql {
|
||||
CREATE TABLE t4(x);
|
||||
CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN
|
||||
INSERT INTO t4 VALUES('db2.' || NEW.x);
|
||||
END;
|
||||
INSERT INTO t3 VALUES(6,7);
|
||||
SELECT * FROM t4;
|
||||
} db2
|
||||
} {db2.6}
|
||||
do_test attach-4.7 {
|
||||
execsql {
|
||||
CREATE TABLE t4(y);
|
||||
CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN
|
||||
INSERT INTO t4 VALUES('main.' || NEW.a);
|
||||
END;
|
||||
INSERT INTO main.t3 VALUES(11,12);
|
||||
SELECT * FROM main.t4;
|
||||
}
|
||||
} {main.11}
|
||||
}
|
||||
ifcapable {!trigger} {
|
||||
# When we do not have trigger support, set up the table like they
|
||||
# would have been had triggers been there. The tests that follow need
|
||||
# this setup.
|
||||
execsql {
|
||||
CREATE TABLE t4(x);
|
||||
CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN
|
||||
INSERT INTO t4 VALUES('db2.' || NEW.x);
|
||||
END;
|
||||
INSERT INTO t3 VALUES(6,7);
|
||||
SELECT * FROM t4;
|
||||
INSERT INTO t4 VALUES('db2.6');
|
||||
INSERT INTO t4 VALUES('db2.13');
|
||||
} db2
|
||||
} {db2.6}
|
||||
do_test attach-4.7 {
|
||||
execsql {
|
||||
CREATE TABLE t4(y);
|
||||
CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN
|
||||
INSERT INTO t4 VALUES('main.' || NEW.a);
|
||||
END;
|
||||
INSERT INTO main.t3 VALUES(11,12);
|
||||
SELECT * FROM main.t4;
|
||||
INSERT INTO t4 VALUES('main.11');
|
||||
}
|
||||
} {main.11}
|
||||
}
|
||||
|
||||
|
||||
# This one is tricky. On the UNION ALL select, we have to make sure
|
||||
# the schema for both main and db2 is valid before starting to execute
|
||||
@@ -465,6 +551,7 @@ do_test attach-4.7 {
|
||||
# fail and the query will abort but we will have already output some
|
||||
# results. When the query is retried, the results will be repeated.
|
||||
#
|
||||
ifcapable compound {
|
||||
do_test attach-4.8 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS db2;
|
||||
@@ -474,11 +561,24 @@ do_test attach-4.8 {
|
||||
} {db2.6 db2.13 main.11}
|
||||
|
||||
do_test attach-4.9 {
|
||||
ifcapable {!trigger} {execsql {INSERT INTO main.t4 VALUES('main.15')}}
|
||||
execsql {
|
||||
INSERT INTO main.t3 VALUES(15,16);
|
||||
SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4;
|
||||
}
|
||||
} {db2.6 db2.13 main.11 main.15}
|
||||
} ;# ifcapable compound
|
||||
|
||||
ifcapable !compound {
|
||||
ifcapable {!trigger} {execsql {INSERT INTO main.t4 VALUES('main.15')}}
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS db2;
|
||||
INSERT INTO db2.t3 VALUES(13,14);
|
||||
INSERT INTO main.t3 VALUES(15,16);
|
||||
}
|
||||
} ;# ifcapable !compound
|
||||
|
||||
ifcapable view {
|
||||
do_test attach-4.10 {
|
||||
execsql {
|
||||
DETACH DATABASE db2;
|
||||
@@ -505,9 +605,11 @@ do_test attach-4.13 {
|
||||
SELECT * FROM main.v3;
|
||||
}
|
||||
} {910 1112 1516}
|
||||
} ;# ifcapable view
|
||||
|
||||
# Tests for the sqliteFix...() routines in attach.c
|
||||
#
|
||||
ifcapable {trigger} {
|
||||
do_test attach-5.1 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
@@ -537,56 +639,61 @@ do_test attach-5.3 {
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database orig}}
|
||||
do_test attach-5.4 {
|
||||
catchsql {
|
||||
CREATE TEMP TABLE t6(p,q,r);
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT 'no-op' FROM temp.t6;
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.5 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT 'no-op' || (SELECT * FROM temp.t6);
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.6 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT 'no-op' FROM t1 WHERE x<(SELECT min(x) FROM temp.t6);
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.7 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT 'no-op' FROM t1 GROUP BY 1 HAVING x<(SELECT min(x) FROM temp.t6);
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.7 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT max(1,x,(SELECT min(x) FROM temp.t6)) FROM t1;
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.8 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
INSERT INTO t1 VALUES((SELECT min(x) FROM temp.t6),5);
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.9 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
DELETE FROM t1 WHERE x<(SELECT min(x) FROM temp.t6);
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
ifcapable tempdb {
|
||||
do_test attach-5.4 {
|
||||
catchsql {
|
||||
CREATE TEMP TABLE t6(p,q,r);
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT 'no-op' FROM temp.t6;
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
}
|
||||
ifcapable subquery {
|
||||
do_test attach-5.5 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT 'no-op' || (SELECT * FROM temp.t6);
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.6 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT 'no-op' FROM t1 WHERE x<(SELECT min(x) FROM temp.t6);
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.7 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT 'no-op' FROM t1 GROUP BY 1 HAVING x<(SELECT min(x) FROM temp.t6);
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.7 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT max(1,x,(SELECT min(x) FROM temp.t6)) FROM t1;
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.8 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
INSERT INTO t1 VALUES((SELECT min(x) FROM temp.t6),5);
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
do_test attach-5.9 {
|
||||
catchsql {
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
DELETE FROM t1 WHERE x<(SELECT min(x) FROM temp.t6);
|
||||
END;
|
||||
} db2
|
||||
} {1 {trigger r5 cannot reference objects in database temp}}
|
||||
} ;# endif subquery
|
||||
} ;# endif trigger
|
||||
|
||||
# Check to make sure we get a sensible error if unable to open
|
||||
# the file that we are trying to attach.
|
||||
@@ -602,6 +709,11 @@ if {$tcl_platform(platform)=="unix"} {
|
||||
dbx eval {CREATE TABLE t1(a,b,c)}
|
||||
dbx close
|
||||
file attributes cannot-read -permission 0000
|
||||
if {[file writable cannot-read]} {
|
||||
puts "\n**** Tests do not work when run as root ****"
|
||||
file delete -force cannot-read
|
||||
exit 1
|
||||
}
|
||||
catchsql {
|
||||
ATTACH DATABASE 'cannot-read' AS noread;
|
||||
}
|
||||
@@ -609,6 +721,20 @@ if {$tcl_platform(platform)=="unix"} {
|
||||
file delete -force cannot-read
|
||||
}
|
||||
|
||||
# Check the error message if we try to access a database that has
|
||||
# not been attached.
|
||||
do_test attach-6.3 {
|
||||
catchsql {
|
||||
CREATE TABLE no_such_db.t1(a, b, c);
|
||||
}
|
||||
} {1 {unknown database no_such_db}}
|
||||
ifcapable !compound {
|
||||
do_test attach-6.4 {
|
||||
catchsql {
|
||||
CREATE TEMP TABLE db2.temp1(a, b, c);
|
||||
}
|
||||
} {1 {temporary table name must be unqualified}}
|
||||
}
|
||||
for {set i 2} {$i<=15} {incr i} {
|
||||
catch {db$i close}
|
||||
}
|
||||
|
||||
+16
-3
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach2.test,v 1.26 2004/09/02 14:57:09 drh Exp $
|
||||
# $Id: attach2.test,v 1.32 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -61,10 +61,12 @@ do_test attach2-2.1 {
|
||||
ATTACH 'test2.db' AS t2;
|
||||
}
|
||||
} {0 {}}
|
||||
ifcapable schema_pragmas {
|
||||
do_test attach2-2.2 {
|
||||
# make sure test2.db did get attached.
|
||||
db_list db
|
||||
} {0 main 2 t2}
|
||||
} ;# ifcapable schema_pragmas
|
||||
db2 eval {COMMIT}
|
||||
|
||||
do_test attach2-2.5 {
|
||||
@@ -150,7 +152,18 @@ for {set i 2} {$i<=15} {incr i} {
|
||||
# A procedure to verify the status of locks on a database.
|
||||
#
|
||||
proc lock_status {testnum db expected_result} {
|
||||
# If the database was compiled with OMIT_TEMPDB set, then
|
||||
# the lock_status list will not contain an entry for the temp
|
||||
# db. But the test code doesn't know this, so it's easiest
|
||||
# to filter it out here.
|
||||
ifcapable !tempdb {
|
||||
set expected_result [concat \
|
||||
[lrange $expected_result 0 1] \
|
||||
[lrange $expected_result 4 end] \
|
||||
]
|
||||
}
|
||||
do_test attach2-$testnum [subst {
|
||||
$db cache flush ;# The lock_status pragma should not be cached
|
||||
execsql {PRAGMA lock_status} $db
|
||||
}] $expected_result
|
||||
}
|
||||
@@ -323,7 +336,7 @@ do_test attach2-5.2 {
|
||||
}
|
||||
} {}
|
||||
do_test attach2-5.3 {
|
||||
glob test.db*
|
||||
lsort [glob test.db*]
|
||||
} {test.db test.db2}
|
||||
do_test attach2-5.4 {
|
||||
execsql {
|
||||
@@ -334,7 +347,7 @@ do_test attach2-5.4 {
|
||||
}
|
||||
} {}
|
||||
do_test attach2-5.5 {
|
||||
glob test.db*
|
||||
lsort [glob test.db*]
|
||||
} {test.db test.db2}
|
||||
|
||||
# Check that a database cannot be ATTACHed or DETACHed during a transaction.
|
||||
|
||||
+34
-30
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and schema changes to attached databases.
|
||||
#
|
||||
# $Id: attach3.test,v 1.9 2004/07/19 00:56:24 drh Exp $
|
||||
# $Id: attach3.test,v 1.15 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ execsql {
|
||||
|
||||
# Create tables t1 and t2 in database file test2.db
|
||||
file delete -force test2.db
|
||||
file delete -force test2.db-journal
|
||||
sqlite3 db2 test2.db
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
@@ -54,7 +55,7 @@ do_test attach3-1.4 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 't3';
|
||||
}
|
||||
} {table t3 t3 4 {CREATE TABLE t3(e, f)}}
|
||||
} "table t3 t3 [expr $AUTOVACUUM?5:4] {CREATE TABLE t3(e, f)}"
|
||||
do_test attach3-1.5 {
|
||||
execsql {
|
||||
INSERT INTO t3 VALUES(1, 2);
|
||||
@@ -68,9 +69,6 @@ do_test attach3-2.1 {
|
||||
CREATE INDEX aux.i1 on t3(e);
|
||||
}
|
||||
} {}
|
||||
execsql {
|
||||
pragma vdbe_trace = off;
|
||||
}
|
||||
do_test attach3-2.2 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_master WHERE name = 'i1';
|
||||
@@ -80,7 +78,7 @@ do_test attach3-2.3 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} {index i1 t3 5 {CREATE INDEX i1 on t3(e)}}
|
||||
} "index i1 t3 [expr $AUTOVACUUM?6:5] {CREATE INDEX i1 on t3(e)}"
|
||||
|
||||
# Drop the index on the aux database table.
|
||||
do_test attach3-3.1 {
|
||||
@@ -94,7 +92,7 @@ do_test attach3-3.2 {
|
||||
CREATE INDEX aux.i1 on t3(e);
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} {index i1 t3 5 {CREATE INDEX i1 on t3(e)}}
|
||||
} "index i1 t3 [expr $AUTOVACUUM?6:5] {CREATE INDEX i1 on t3(e)}"
|
||||
do_test attach3-3.3 {
|
||||
execsql {
|
||||
DROP INDEX i1;
|
||||
@@ -124,6 +122,7 @@ do_test attach3-4.3 {
|
||||
} {t3}
|
||||
|
||||
# Create a view in the auxilary database.
|
||||
ifcapable view {
|
||||
do_test attach3-5.1 {
|
||||
execsql {
|
||||
CREATE VIEW aux.v1 AS SELECT * FROM t3;
|
||||
@@ -152,7 +151,9 @@ do_test attach3-6.2 {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'v1';
|
||||
}
|
||||
} {}
|
||||
} ;# ifcapable view
|
||||
|
||||
ifcapable {trigger} {
|
||||
# Create a trigger in the auxilary database.
|
||||
do_test attach3-7.1 {
|
||||
execsql {
|
||||
@@ -188,29 +189,32 @@ do_test attach3-8.2 {
|
||||
}
|
||||
} {}
|
||||
|
||||
# Try to trick SQLite into dropping the wrong temp trigger.
|
||||
do_test attach3-9.0 {
|
||||
execsql {
|
||||
CREATE TABLE main.t4(a, b, c);
|
||||
CREATE TABLE aux.t4(a, b, c);
|
||||
CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN
|
||||
SELECT 'hello world';
|
||||
END;
|
||||
SELECT count(*) FROM sqlite_temp_master;
|
||||
}
|
||||
} {1}
|
||||
do_test attach3-9.1 {
|
||||
execsql {
|
||||
DROP TABLE main.t4;
|
||||
SELECT count(*) FROM sqlite_temp_master;
|
||||
}
|
||||
} {1}
|
||||
do_test attach3-9.2 {
|
||||
execsql {
|
||||
DROP TABLE aux.t4;
|
||||
SELECT count(*) FROM sqlite_temp_master;
|
||||
}
|
||||
} {0}
|
||||
ifcapable tempdb {
|
||||
# Try to trick SQLite into dropping the wrong temp trigger.
|
||||
do_test attach3-9.0 {
|
||||
execsql {
|
||||
CREATE TABLE main.t4(a, b, c);
|
||||
CREATE TABLE aux.t4(a, b, c);
|
||||
CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN
|
||||
SELECT 'hello world';
|
||||
END;
|
||||
SELECT count(*) FROM sqlite_temp_master;
|
||||
}
|
||||
} {1}
|
||||
do_test attach3-9.1 {
|
||||
execsql {
|
||||
DROP TABLE main.t4;
|
||||
SELECT count(*) FROM sqlite_temp_master;
|
||||
}
|
||||
} {1}
|
||||
do_test attach3-9.2 {
|
||||
execsql {
|
||||
DROP TABLE aux.t4;
|
||||
SELECT count(*) FROM sqlite_temp_master;
|
||||
}
|
||||
} {0}
|
||||
}
|
||||
} ;# endif trigger
|
||||
|
||||
# Make sure the aux.sqlite_master table is read-only
|
||||
do_test attach3-10.0 {
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
# 2005 September 19
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing the ATTACH statement and
|
||||
# specifically out-of-memory conditions within that command.
|
||||
#
|
||||
# $Id: attachmalloc.test,v 1.2 2005/08/21 18:21:50 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Only run these tests if memory debugging is turned on.
|
||||
#
|
||||
if {[info command sqlite_malloc_stat]==""} {
|
||||
puts "Skipping malloc tests: not compiled with -DSQLITE_DEBUG..."
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
# Usage: do_malloc_test <test name> <options...>
|
||||
#
|
||||
# The first argument, <test number>, is an integer used to name the
|
||||
# tests executed by this proc. Options are as follows:
|
||||
#
|
||||
# -tclprep TCL script to run to prepare test.
|
||||
# -sqlprep SQL script to run to prepare test.
|
||||
# -tclbody TCL script to run with malloc failure simulation.
|
||||
# -sqlbody TCL script to run with malloc failure simulation.
|
||||
# -cleanup TCL script to run after the test.
|
||||
#
|
||||
# This command runs a series of tests to verify SQLite's ability
|
||||
# to handle an out-of-memory condition gracefully. It is assumed
|
||||
# that if this condition occurs a malloc() call will return a
|
||||
# NULL pointer. Linux, for example, doesn't do that by default. See
|
||||
# the "BUGS" section of malloc(3).
|
||||
#
|
||||
# Each iteration of a loop, the TCL commands in any argument passed
|
||||
# to the -tclbody switch, followed by the SQL commands in any argument
|
||||
# passed to the -sqlbody switch are executed. Each iteration the
|
||||
# Nth call to sqliteMalloc() is made to fail, where N is increased
|
||||
# each time the loop runs starting from 1. When all commands execute
|
||||
# successfully, the loop ends.
|
||||
#
|
||||
proc do_malloc_test {tn args} {
|
||||
array set ::mallocopts $args
|
||||
|
||||
set ::go 1
|
||||
for {set ::n 1} {$::go} {incr ::n} {
|
||||
|
||||
do_test $tn.$::n {
|
||||
|
||||
sqlite_malloc_fail 0
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
catch {file delete -force test2.db}
|
||||
catch {file delete -force test2.db-journal}
|
||||
set ::DB [sqlite3 db test.db]
|
||||
|
||||
if {[info exists ::mallocopts(-tclprep)]} {
|
||||
eval $::mallocopts(-tclprep)
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlprep)]} {
|
||||
execsql $::mallocopts(-sqlprep)
|
||||
}
|
||||
|
||||
sqlite_malloc_fail $::n
|
||||
set ::mallocbody {}
|
||||
if {[info exists ::mallocopts(-tclbody)]} {
|
||||
append ::mallocbody "$::mallocopts(-tclbody)\n"
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlbody)]} {
|
||||
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
|
||||
}
|
||||
|
||||
set v [catch $::mallocbody msg]
|
||||
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
set v {1 1}
|
||||
} else {
|
||||
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
}
|
||||
} {1 1}
|
||||
sqlite_malloc_fail 0
|
||||
|
||||
if {[info exists ::mallocopts(-cleanup)]} {
|
||||
catch $::mallocopts(-cleanup)
|
||||
}
|
||||
}
|
||||
unset ::mallocopts
|
||||
}
|
||||
|
||||
do_malloc_test attachmalloc-1 -tclprep {
|
||||
db close
|
||||
for {set i 2} {$i<=4} {incr i} {
|
||||
file delete -force test$i.db
|
||||
file delete -force test$i.db-journal
|
||||
}
|
||||
} -tclbody {
|
||||
if {[catch {sqlite3 db test.db}]} {
|
||||
error "out of memory"
|
||||
}
|
||||
} -sqlbody {
|
||||
ATTACH 'test2.db' AS two;
|
||||
CREATE TABLE two.t1(x);
|
||||
ATTACH 'test3.db' AS three;
|
||||
CREATE TABLE three.t1(x);
|
||||
ATTACH 'test4.db' AS four;
|
||||
CREATE TABLE four.t1(x);
|
||||
}
|
||||
|
||||
finish_test
|
||||
+768
-410
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,535 @@
|
||||
# 2004 November 12
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing the AUTOINCREMENT features.
|
||||
#
|
||||
# $Id: autoinc.test,v 1.7 2005/08/11 02:10:19 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If the library is not compiled with autoincrement support then
|
||||
# skip all tests in this file.
|
||||
#
|
||||
ifcapable {!autoinc} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# The database is initially empty.
|
||||
#
|
||||
do_test autoinc-1.1 {
|
||||
execsql {
|
||||
SELECT name FROM sqlite_master WHERE type='table';
|
||||
}
|
||||
} {}
|
||||
|
||||
# Add a table with the AUTOINCREMENT feature. Verify that the
|
||||
# SQLITE_SEQUENCE table gets created.
|
||||
#
|
||||
do_test autoinc-1.2 {
|
||||
execsql {
|
||||
CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
|
||||
SELECT name FROM sqlite_master WHERE type='table';
|
||||
}
|
||||
} {t1 sqlite_sequence}
|
||||
|
||||
# The SQLITE_SEQUENCE table is initially empty
|
||||
#
|
||||
do_test autoinc-1.3 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Close and reopen the database. Verify that everything is still there.
|
||||
#
|
||||
do_test autoinc-1.4 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {}
|
||||
|
||||
# We are not allowed to drop the sqlite_sequence table.
|
||||
#
|
||||
do_test autoinc-1.5 {
|
||||
catchsql {DROP TABLE sqlite_sequence}
|
||||
} {1 {table sqlite_sequence may not be dropped}}
|
||||
do_test autoinc-1.6 {
|
||||
execsql {SELECT name FROM sqlite_master WHERE type='table'}
|
||||
} {t1 sqlite_sequence}
|
||||
|
||||
# Insert an entries into the t1 table and make sure the largest key
|
||||
# is always recorded in the sqlite_sequence table.
|
||||
#
|
||||
do_test autoinc-2.1 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence
|
||||
}
|
||||
} {}
|
||||
do_test autoinc-2.2 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(12,34);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 12}
|
||||
do_test autoinc-2.3 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(1,23);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 12}
|
||||
do_test autoinc-2.4 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(123,456);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 123}
|
||||
do_test autoinc-2.5 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(NULL,567);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 124}
|
||||
do_test autoinc-2.6 {
|
||||
execsql {
|
||||
DELETE FROM t1 WHERE y=567;
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 124}
|
||||
do_test autoinc-2.7 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(NULL,567);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 125}
|
||||
do_test autoinc-2.8 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 125}
|
||||
do_test autoinc-2.9 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(12,34);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 125}
|
||||
do_test autoinc-2.10 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(125,456);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 125}
|
||||
do_test autoinc-2.11 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(-1234567,-1);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 125}
|
||||
do_test autoinc-2.12 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(234,5678);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 234}
|
||||
do_test autoinc-2.13 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
INSERT INTO t1 VALUES(NULL,1);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 235}
|
||||
do_test autoinc-2.14 {
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {235 1}
|
||||
|
||||
# Manually change the autoincrement values in sqlite_sequence.
|
||||
#
|
||||
do_test autoinc-2.20 {
|
||||
execsql {
|
||||
UPDATE sqlite_sequence SET seq=1234 WHERE name='t1';
|
||||
INSERT INTO t1 VALUES(NULL,2);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {235 1 1235 2}
|
||||
do_test autoinc-2.21 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 1235}
|
||||
do_test autoinc-2.22 {
|
||||
execsql {
|
||||
UPDATE sqlite_sequence SET seq=NULL WHERE name='t1';
|
||||
INSERT INTO t1 VALUES(NULL,3);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {235 1 1235 2 1236 3}
|
||||
do_test autoinc-2.23 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 1236}
|
||||
do_test autoinc-2.24 {
|
||||
execsql {
|
||||
UPDATE sqlite_sequence SET seq='a-string' WHERE name='t1';
|
||||
INSERT INTO t1 VALUES(NULL,4);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {235 1 1235 2 1236 3 1237 4}
|
||||
do_test autoinc-2.25 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 1237}
|
||||
do_test autoinc-2.26 {
|
||||
execsql {
|
||||
DELETE FROM sqlite_sequence WHERE name='t1';
|
||||
INSERT INTO t1 VALUES(NULL,5);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {235 1 1235 2 1236 3 1237 4 1238 5}
|
||||
do_test autoinc-2.27 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 1238}
|
||||
do_test autoinc-2.28 {
|
||||
execsql {
|
||||
UPDATE sqlite_sequence SET seq='12345678901234567890'
|
||||
WHERE name='t1';
|
||||
INSERT INTO t1 VALUES(NULL,6);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {235 1 1235 2 1236 3 1237 4 1238 5 1239 6}
|
||||
do_test autoinc-2.29 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 1239}
|
||||
|
||||
# Test multi-row inserts
|
||||
#
|
||||
do_test autoinc-2.50 {
|
||||
execsql {
|
||||
DELETE FROM t1 WHERE y>=3;
|
||||
INSERT INTO t1 SELECT NULL, y+2 FROM t1;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {235 1 1235 2 1240 3 1241 4}
|
||||
do_test autoinc-2.51 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence
|
||||
}
|
||||
} {t1 1241}
|
||||
|
||||
ifcapable tempdb {
|
||||
do_test autoinc-2.52 {
|
||||
execsql {
|
||||
CREATE TEMP TABLE t2 AS SELECT y FROM t1;
|
||||
INSERT INTO t1 SELECT NULL, y+4 FROM t2;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {235 1 1235 2 1240 3 1241 4 1242 5 1243 6 1244 7 1245 8}
|
||||
do_test autoinc-2.53 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence
|
||||
}
|
||||
} {t1 1245}
|
||||
do_test autoinc-2.54 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
INSERT INTO t1 SELECT NULL, y FROM t2;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1246 1 1247 2 1248 3 1249 4}
|
||||
do_test autoinc-2.55 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_sequence
|
||||
}
|
||||
} {t1 1249}
|
||||
}
|
||||
|
||||
# Create multiple AUTOINCREMENT tables. Make sure all sequences are
|
||||
# tracked separately and do not interfere with one another.
|
||||
#
|
||||
do_test autoinc-2.70 {
|
||||
catchsql {
|
||||
DROP TABLE t2;
|
||||
}
|
||||
execsql {
|
||||
CREATE TABLE t2(d, e INTEGER PRIMARY KEY AUTOINCREMENT, f);
|
||||
INSERT INTO t2(d) VALUES(1);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} [ifcapable tempdb {list t1 1249 t2 1} else {list t1 1241 t2 1}]
|
||||
do_test autoinc-2.71 {
|
||||
execsql {
|
||||
INSERT INTO t2(d) VALUES(2);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} [ifcapable tempdb {list t1 1249 t2 2} else {list t1 1241 t2 2}]
|
||||
do_test autoinc-2.72 {
|
||||
execsql {
|
||||
INSERT INTO t1(x) VALUES(10000);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 10000 t2 2}
|
||||
do_test autoinc-2.73 {
|
||||
execsql {
|
||||
CREATE TABLE t3(g INTEGER PRIMARY KEY AUTOINCREMENT, h);
|
||||
INSERT INTO t3(h) VALUES(1);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 10000 t2 2 t3 1}
|
||||
do_test autoinc-2.74 {
|
||||
execsql {
|
||||
INSERT INTO t2(d,e) VALUES(3,100);
|
||||
SELECT * FROM sqlite_sequence;
|
||||
}
|
||||
} {t1 10000 t2 100 t3 1}
|
||||
|
||||
|
||||
# When a table with an AUTOINCREMENT is deleted, the corresponding entry
|
||||
# in the SQLITE_SEQUENCE table should also be deleted. But the SQLITE_SEQUENCE
|
||||
# table itself should remain behind.
|
||||
#
|
||||
do_test autoinc-3.1 {
|
||||
execsql {SELECT name FROM sqlite_sequence}
|
||||
} {t1 t2 t3}
|
||||
do_test autoinc-3.2 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
SELECT name FROM sqlite_sequence;
|
||||
}
|
||||
} {t2 t3}
|
||||
do_test autoinc-3.3 {
|
||||
execsql {
|
||||
DROP TABLE t3;
|
||||
SELECT name FROM sqlite_sequence;
|
||||
}
|
||||
} {t2}
|
||||
do_test autoinc-3.4 {
|
||||
execsql {
|
||||
DROP TABLE t2;
|
||||
SELECT name FROM sqlite_sequence;
|
||||
}
|
||||
} {}
|
||||
|
||||
# AUTOINCREMENT on TEMP tables.
|
||||
#
|
||||
ifcapable tempdb {
|
||||
do_test autoinc-4.1 {
|
||||
execsql {
|
||||
SELECT 1, name FROM sqlite_master WHERE type='table';
|
||||
SELECT 2, name FROM sqlite_temp_master WHERE type='table';
|
||||
}
|
||||
} {1 sqlite_sequence}
|
||||
do_test autoinc-4.2 {
|
||||
execsql {
|
||||
CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
|
||||
CREATE TEMP TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
|
||||
SELECT 1, name FROM sqlite_master WHERE type='table';
|
||||
SELECT 2, name FROM sqlite_temp_master WHERE type='table';
|
||||
}
|
||||
} {1 sqlite_sequence 1 t1 2 t3 2 sqlite_sequence}
|
||||
do_test autoinc-4.3 {
|
||||
execsql {
|
||||
SELECT 1, * FROM main.sqlite_sequence;
|
||||
SELECT 2, * FROM temp.sqlite_sequence;
|
||||
}
|
||||
} {}
|
||||
do_test autoinc-4.4 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(10,1);
|
||||
INSERT INTO t3 VALUES(20,2);
|
||||
INSERT INTO t1 VALUES(NULL,3);
|
||||
INSERT INTO t3 VALUES(NULL,4);
|
||||
}
|
||||
} {}
|
||||
|
||||
ifcapable compound {
|
||||
do_test autoinc-4.4.1 {
|
||||
execsql {
|
||||
SELECT * FROM t1 UNION ALL SELECT * FROM t3;
|
||||
}
|
||||
} {10 1 11 3 20 2 21 4}
|
||||
} ;# ifcapable compound
|
||||
|
||||
do_test autoinc-4.5 {
|
||||
execsql {
|
||||
SELECT 1, * FROM main.sqlite_sequence;
|
||||
SELECT 2, * FROM temp.sqlite_sequence;
|
||||
}
|
||||
} {1 t1 11 2 t3 21}
|
||||
do_test autoinc-4.6 {
|
||||
execsql {
|
||||
INSERT INTO t1 SELECT * FROM t3;
|
||||
SELECT 1, * FROM main.sqlite_sequence;
|
||||
SELECT 2, * FROM temp.sqlite_sequence;
|
||||
}
|
||||
} {1 t1 21 2 t3 21}
|
||||
do_test autoinc-4.7 {
|
||||
execsql {
|
||||
INSERT INTO t3 SELECT x+100, y FROM t1;
|
||||
SELECT 1, * FROM main.sqlite_sequence;
|
||||
SELECT 2, * FROM temp.sqlite_sequence;
|
||||
}
|
||||
} {1 t1 21 2 t3 121}
|
||||
do_test autoinc-4.8 {
|
||||
execsql {
|
||||
DROP TABLE t3;
|
||||
SELECT 1, * FROM main.sqlite_sequence;
|
||||
SELECT 2, * FROM temp.sqlite_sequence;
|
||||
}
|
||||
} {1 t1 21}
|
||||
do_test autoinc-4.9 {
|
||||
execsql {
|
||||
CREATE TEMP TABLE t2(p INTEGER PRIMARY KEY AUTOINCREMENT, q);
|
||||
INSERT INTO t2 SELECT * FROM t1;
|
||||
DROP TABLE t1;
|
||||
SELECT 1, * FROM main.sqlite_sequence;
|
||||
SELECT 2, * FROM temp.sqlite_sequence;
|
||||
}
|
||||
} {2 t2 21}
|
||||
do_test autoinc-4.10 {
|
||||
execsql {
|
||||
DROP TABLE t2;
|
||||
SELECT 1, * FROM main.sqlite_sequence;
|
||||
SELECT 2, * FROM temp.sqlite_sequence;
|
||||
}
|
||||
} {}
|
||||
}
|
||||
|
||||
# Make sure AUTOINCREMENT works on ATTACH-ed tables.
|
||||
#
|
||||
ifcapable tempdb {
|
||||
do_test autoinc-5.1 {
|
||||
file delete -force test2.db
|
||||
file delete -force test2.db-journal
|
||||
sqlite3 db2 test2.db
|
||||
execsql {
|
||||
CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n);
|
||||
CREATE TABLE t5(o, p INTEGER PRIMARY KEY AUTOINCREMENT);
|
||||
} db2;
|
||||
execsql {
|
||||
ATTACH 'test2.db' as aux;
|
||||
SELECT 1, * FROM main.sqlite_sequence;
|
||||
SELECT 2, * FROM temp.sqlite_sequence;
|
||||
SELECT 3, * FROM aux.sqlite_sequence;
|
||||
}
|
||||
} {}
|
||||
do_test autoinc-5.2 {
|
||||
execsql {
|
||||
INSERT INTO t4 VALUES(NULL,1);
|
||||
SELECT 1, * FROM main.sqlite_sequence;
|
||||
SELECT 2, * FROM temp.sqlite_sequence;
|
||||
SELECT 3, * FROM aux.sqlite_sequence;
|
||||
}
|
||||
} {3 t4 1}
|
||||
do_test autoinc-5.3 {
|
||||
execsql {
|
||||
INSERT INTO t5 VALUES(100,200);
|
||||
SELECT * FROM sqlite_sequence
|
||||
} db2
|
||||
} {t4 1 t5 200}
|
||||
do_test autoinc-5.4 {
|
||||
execsql {
|
||||
SELECT 1, * FROM main.sqlite_sequence;
|
||||
SELECT 2, * FROM temp.sqlite_sequence;
|
||||
SELECT 3, * FROM aux.sqlite_sequence;
|
||||
}
|
||||
} {3 t4 1 3 t5 200}
|
||||
}
|
||||
|
||||
# Requirement REQ00310: Make sure an insert fails if the sequence is
|
||||
# already at its maximum value.
|
||||
#
|
||||
ifcapable {rowid32} {
|
||||
do_test autoinc-6.1 {
|
||||
execsql {
|
||||
CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w);
|
||||
INSERT INTO t6 VALUES(2147483647,1);
|
||||
SELECT seq FROM main.sqlite_sequence WHERE name='t6';
|
||||
}
|
||||
} 2147483647
|
||||
}
|
||||
ifcapable {!rowid32} {
|
||||
do_test autoinc-6.1 {
|
||||
execsql {
|
||||
CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w);
|
||||
INSERT INTO t6 VALUES(9223372036854775807,1);
|
||||
SELECT seq FROM main.sqlite_sequence WHERE name='t6';
|
||||
}
|
||||
} 9223372036854775807
|
||||
}
|
||||
do_test autoinc-6.2 {
|
||||
catchsql {
|
||||
INSERT INTO t6 VALUES(NULL,1);
|
||||
}
|
||||
} {1 {database or disk is full}}
|
||||
|
||||
# Allow the AUTOINCREMENT keyword inside the parentheses
|
||||
# on a separate PRIMARY KEY designation.
|
||||
#
|
||||
do_test autoinc-7.1 {
|
||||
execsql {
|
||||
CREATE TABLE t7(x INTEGER, y REAL, PRIMARY KEY(x AUTOINCREMENT));
|
||||
INSERT INTO t7(y) VALUES(123);
|
||||
INSERT INTO t7(y) VALUES(234);
|
||||
DELETE FROM t7;
|
||||
INSERT INTO t7(y) VALUES(345);
|
||||
SELECT * FROM t7;
|
||||
}
|
||||
} {3 345}
|
||||
|
||||
# Test that if the AUTOINCREMENT is applied to a non integer primary key
|
||||
# the error message is sensible.
|
||||
do_test autoinc-7.2 {
|
||||
catchsql {
|
||||
CREATE TABLE t8(x TEXT PRIMARY KEY AUTOINCREMENT);
|
||||
}
|
||||
} {1 {AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY}}
|
||||
|
||||
|
||||
# Ticket #1283. Make sure that preparing but never running a statement
|
||||
# that creates the sqlite_sequence table does not mess up the database.
|
||||
#
|
||||
do_test autoinc-8.1 {
|
||||
catch {db2 close}
|
||||
catch {db close}
|
||||
file delete -force test.db
|
||||
set DB [sqlite3 db test.db]
|
||||
set STMT [sqlite3_prepare $DB {
|
||||
CREATE TABLE t1(
|
||||
x INTEGER PRIMARY KEY AUTOINCREMENT
|
||||
)
|
||||
} -1 TAIL]
|
||||
sqlite3_finalize $STMT
|
||||
set STMT [sqlite3_prepare $DB {
|
||||
CREATE TABLE t1(
|
||||
x INTEGER PRIMARY KEY AUTOINCREMENT
|
||||
)
|
||||
} -1 TAIL]
|
||||
sqlite3_step $STMT
|
||||
sqlite3_finalize $STMT
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(NULL);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,528 @@
|
||||
# 2001 September 15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the SELECT statement.
|
||||
#
|
||||
# $Id: autovacuum.test,v 1.19 2005/09/16 09:52:30 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If this build of the library does not support auto-vacuum, omit this
|
||||
# whole file.
|
||||
ifcapable {!autovacuum} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Return a string $len characters long. The returned string is $char repeated
|
||||
# over and over. For example, [make_str abc 8] returns "abcabcab".
|
||||
proc make_str {char len} {
|
||||
set str [string repeat $char. $len]
|
||||
return [string range $str 0 [expr $len-1]]
|
||||
}
|
||||
|
||||
# Return the number of pages in the file test.db by looking at the file system.
|
||||
proc file_pages {} {
|
||||
return [expr [file size test.db] / 1024]
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test cases autovacuum-1.* work as follows:
|
||||
#
|
||||
# 1. A table with a single indexed field is created.
|
||||
# 2. Approximately 20 rows are inserted into the table. Each row is long
|
||||
# enough such that it uses at least 2 overflow pages for both the table
|
||||
# and index entry.
|
||||
# 3. The rows are deleted in a psuedo-random order. Sometimes only one row
|
||||
# is deleted per transaction, sometimes more than one.
|
||||
# 4. After each transaction the table data is checked to ensure it is correct
|
||||
# and a "PRAGMA integrity_check" is executed.
|
||||
# 5. Once all the rows are deleted the file is checked to make sure it
|
||||
# consists of exactly 4 pages.
|
||||
#
|
||||
# Steps 2-5 are repeated for a few different psuedo-random delete patterns
|
||||
# (defined by the $delete_orders list).
|
||||
set delete_orders [list]
|
||||
lappend delete_orders {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
|
||||
lappend delete_orders {20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1}
|
||||
lappend delete_orders {8 18 2 4 14 11 13 3 10 7 9 5 12 17 19 15 20 6 16 1}
|
||||
lappend delete_orders {10 3 11 17 19 20 7 4 13 6 1 14 16 12 9 18 8 15 5 2}
|
||||
lappend delete_orders {{1 2 3 4 5 6 7 8 9 10} {11 12 13 14 15 16 17 18 19 20}}
|
||||
lappend delete_orders {{19 8 17 15} {16 11 9 14} {18 5 3 1} {13 20 7 2} {6 12}}
|
||||
|
||||
# The length of each table entry.
|
||||
# set ENTRY_LEN 3500
|
||||
set ENTRY_LEN 3500
|
||||
|
||||
do_test autovacuum-1.1 {
|
||||
execsql {
|
||||
PRAGMA auto_vacuum = 1;
|
||||
CREATE TABLE av1(a);
|
||||
CREATE INDEX av1_idx ON av1(a);
|
||||
}
|
||||
} {}
|
||||
|
||||
set tn 0
|
||||
foreach delete_order $delete_orders {
|
||||
incr tn
|
||||
|
||||
# Set up the table.
|
||||
set ::tbl_data [list]
|
||||
foreach i [lsort -integer [eval concat $delete_order]] {
|
||||
execsql "INSERT INTO av1 (oid, a) VALUES($i, '[make_str $i $ENTRY_LEN]')"
|
||||
lappend ::tbl_data [make_str $i $ENTRY_LEN]
|
||||
}
|
||||
|
||||
# Make sure the integrity check passes with the initial data.
|
||||
ifcapable {integrityck} {
|
||||
do_test autovacuum-1.$tn.1 {
|
||||
execsql {
|
||||
pragma integrity_check
|
||||
}
|
||||
} {ok}
|
||||
}
|
||||
|
||||
foreach delete $delete_order {
|
||||
# Delete one set of rows from the table.
|
||||
do_test autovacuum-1.$tn.($delete).1 {
|
||||
execsql "
|
||||
DELETE FROM av1 WHERE oid = [join $delete "OR oid = "]
|
||||
"
|
||||
} {}
|
||||
|
||||
# Do the integrity check.
|
||||
ifcapable {integrityck} {
|
||||
do_test autovacuum-1.$tn.($delete).2 {
|
||||
execsql {
|
||||
pragma integrity_check
|
||||
}
|
||||
} {ok}
|
||||
}
|
||||
# Ensure the data remaining in the table is what was expected.
|
||||
foreach d $delete {
|
||||
set idx [lsearch $::tbl_data [make_str $d $ENTRY_LEN]]
|
||||
set ::tbl_data [lreplace $::tbl_data $idx $idx]
|
||||
}
|
||||
do_test autovacuum-1.$tn.($delete).3 {
|
||||
execsql {
|
||||
select a from av1
|
||||
}
|
||||
} $::tbl_data
|
||||
}
|
||||
|
||||
# All rows have been deleted. Ensure the file has shrunk to 4 pages.
|
||||
do_test autovacuum-1.$tn.3 {
|
||||
file_pages
|
||||
} {4}
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Tests cases autovacuum-2.* test that root pages are allocated
|
||||
# and deallocated correctly at the start of the file. Operation is roughly as
|
||||
# follows:
|
||||
#
|
||||
# autovacuum-2.1.*: Drop the tables that currently exist in the database.
|
||||
# autovacuum-2.2.*: Create some tables. Ensure that data pages can be
|
||||
# moved correctly to make space for new root-pages.
|
||||
# autovacuum-2.3.*: Drop one of the tables just created (not the last one),
|
||||
# and check that one of the other tables is moved to
|
||||
# the free root-page location.
|
||||
# autovacuum-2.4.*: Check that a table can be created correctly when the
|
||||
# root-page it requires is on the free-list.
|
||||
# autovacuum-2.5.*: Check that a table with indices can be dropped. This
|
||||
# is slightly tricky because dropping one of the
|
||||
# indices/table btrees could move the root-page of another.
|
||||
# The code-generation layer of SQLite overcomes this problem
|
||||
# by dropping the btrees in descending order of root-pages.
|
||||
# This test ensures that this actually happens.
|
||||
#
|
||||
do_test autovacuum-2.1.1 {
|
||||
execsql {
|
||||
DROP TABLE av1;
|
||||
}
|
||||
} {}
|
||||
do_test autovacuum-2.1.2 {
|
||||
file_pages
|
||||
} {1}
|
||||
|
||||
# Create a table and put some data in it.
|
||||
do_test autovacuum-2.2.1 {
|
||||
execsql {
|
||||
CREATE TABLE av1(x);
|
||||
SELECT rootpage FROM sqlite_master ORDER BY rootpage;
|
||||
}
|
||||
} {3}
|
||||
do_test autovacuum-2.2.2 {
|
||||
execsql "
|
||||
INSERT INTO av1 VALUES('[make_str abc 3000]');
|
||||
INSERT INTO av1 VALUES('[make_str def 3000]');
|
||||
INSERT INTO av1 VALUES('[make_str ghi 3000]');
|
||||
INSERT INTO av1 VALUES('[make_str jkl 3000]');
|
||||
"
|
||||
set ::av1_data [db eval {select * from av1}]
|
||||
file_pages
|
||||
} {15}
|
||||
|
||||
# Create another table. Check it is located immediately after the first.
|
||||
# This test case moves the second page in an over-flow chain.
|
||||
do_test autovacuum-2.2.3 {
|
||||
execsql {
|
||||
CREATE TABLE av2(x);
|
||||
SELECT rootpage FROM sqlite_master ORDER BY rootpage;
|
||||
}
|
||||
} {3 4}
|
||||
do_test autovacuum-2.2.4 {
|
||||
file_pages
|
||||
} {16}
|
||||
|
||||
# Create another table. Check it is located immediately after the second.
|
||||
# This test case moves the first page in an over-flow chain.
|
||||
do_test autovacuum-2.2.5 {
|
||||
execsql {
|
||||
CREATE TABLE av3(x);
|
||||
SELECT rootpage FROM sqlite_master ORDER BY rootpage;
|
||||
}
|
||||
} {3 4 5}
|
||||
do_test autovacuum-2.2.6 {
|
||||
file_pages
|
||||
} {17}
|
||||
|
||||
# Create another table. Check it is located immediately after the second.
|
||||
# This test case moves a btree leaf page.
|
||||
do_test autovacuum-2.2.7 {
|
||||
execsql {
|
||||
CREATE TABLE av4(x);
|
||||
SELECT rootpage FROM sqlite_master ORDER BY rootpage;
|
||||
}
|
||||
} {3 4 5 6}
|
||||
do_test autovacuum-2.2.8 {
|
||||
file_pages
|
||||
} {18}
|
||||
do_test autovacuum-2.2.9 {
|
||||
execsql {
|
||||
select * from av1
|
||||
}
|
||||
} $av1_data
|
||||
|
||||
do_test autovacuum-2.3.1 {
|
||||
execsql {
|
||||
INSERT INTO av2 SELECT 'av1' || x FROM av1;
|
||||
INSERT INTO av3 SELECT 'av2' || x FROM av1;
|
||||
INSERT INTO av4 SELECT 'av3' || x FROM av1;
|
||||
}
|
||||
set ::av2_data [execsql {select x from av2}]
|
||||
set ::av3_data [execsql {select x from av3}]
|
||||
set ::av4_data [execsql {select x from av4}]
|
||||
file_pages
|
||||
} {54}
|
||||
do_test autovacuum-2.3.2 {
|
||||
execsql {
|
||||
DROP TABLE av2;
|
||||
SELECT rootpage FROM sqlite_master ORDER BY rootpage;
|
||||
}
|
||||
} {3 4 5}
|
||||
do_test autovacuum-2.3.3 {
|
||||
file_pages
|
||||
} {41}
|
||||
do_test autovacuum-2.3.4 {
|
||||
execsql {
|
||||
SELECT x FROM av3;
|
||||
}
|
||||
} $::av3_data
|
||||
do_test autovacuum-2.3.5 {
|
||||
execsql {
|
||||
SELECT x FROM av4;
|
||||
}
|
||||
} $::av4_data
|
||||
|
||||
# Drop all the tables in the file. This puts all pages except the first 2
|
||||
# (the sqlite_master root-page and the first pointer map page) on the
|
||||
# free-list.
|
||||
do_test autovacuum-2.4.1 {
|
||||
execsql {
|
||||
DROP TABLE av1;
|
||||
DROP TABLE av3;
|
||||
BEGIN;
|
||||
DROP TABLE av4;
|
||||
}
|
||||
file_pages
|
||||
} {15}
|
||||
do_test autovacuum-2.4.2 {
|
||||
for {set i 3} {$i<=10} {incr i} {
|
||||
execsql "CREATE TABLE av$i (x)"
|
||||
}
|
||||
file_pages
|
||||
} {15}
|
||||
do_test autovacuum-2.4.3 {
|
||||
execsql {
|
||||
SELECT rootpage FROM sqlite_master ORDER by rootpage
|
||||
}
|
||||
} {3 4 5 6 7 8 9 10}
|
||||
|
||||
# Right now there are 5 free pages in the database. Consume and then free
|
||||
# a 520 pages. Then create 520 tables. This ensures that at least some of the
|
||||
# desired root-pages reside on the second free-list trunk page, and that the
|
||||
# trunk itself is required at some point.
|
||||
do_test autovacuum-2.4.4 {
|
||||
execsql "
|
||||
INSERT INTO av3 VALUES ('[make_str abcde [expr 1020*520 + 500]]');
|
||||
DELETE FROM av3;
|
||||
"
|
||||
} {}
|
||||
set root_page_list [list]
|
||||
set pending_byte_page [expr ($::sqlite_pending_byte / 1024) + 1]
|
||||
for {set i 3} {$i<=532} {incr i} {
|
||||
# 207 and 412 are pointer-map pages.
|
||||
if { $i!=207 && $i!=412 && $i != $pending_byte_page} {
|
||||
lappend root_page_list $i
|
||||
}
|
||||
}
|
||||
if {$i >= $pending_byte_page} {
|
||||
lappend root_page_list $i
|
||||
}
|
||||
do_test autovacuum-2.4.5 {
|
||||
for {set i 11} {$i<=530} {incr i} {
|
||||
execsql "CREATE TABLE av$i (x)"
|
||||
}
|
||||
execsql {
|
||||
SELECT rootpage FROM sqlite_master ORDER by rootpage
|
||||
}
|
||||
} $root_page_list
|
||||
|
||||
# Just for fun, delete all those tables and see if the database is 1 page.
|
||||
do_test autovacuum-2.4.6 {
|
||||
execsql COMMIT;
|
||||
file_pages
|
||||
} [expr 561 + (($i >= $pending_byte_page)?1:0)]
|
||||
integrity_check autovacuum-2.4.6
|
||||
do_test autovacuum-2.4.7 {
|
||||
execsql BEGIN
|
||||
for {set i 3} {$i<=530} {incr i} {
|
||||
execsql "DROP TABLE av$i"
|
||||
}
|
||||
execsql COMMIT
|
||||
file_pages
|
||||
} 1
|
||||
|
||||
# Create some tables with indices to drop.
|
||||
do_test autovacuum-2.5.1 {
|
||||
execsql {
|
||||
CREATE TABLE av1(a PRIMARY KEY, b, c);
|
||||
INSERT INTO av1 VALUES('av1 a', 'av1 b', 'av1 c');
|
||||
|
||||
CREATE TABLE av2(a PRIMARY KEY, b, c);
|
||||
CREATE INDEX av2_i1 ON av2(b);
|
||||
CREATE INDEX av2_i2 ON av2(c);
|
||||
INSERT INTO av2 VALUES('av2 a', 'av2 b', 'av2 c');
|
||||
|
||||
CREATE TABLE av3(a PRIMARY KEY, b, c);
|
||||
CREATE INDEX av3_i1 ON av3(b);
|
||||
INSERT INTO av3 VALUES('av3 a', 'av3 b', 'av3 c');
|
||||
|
||||
CREATE TABLE av4(a, b, c);
|
||||
CREATE INDEX av4_i1 ON av4(a);
|
||||
CREATE INDEX av4_i2 ON av4(b);
|
||||
CREATE INDEX av4_i3 ON av4(c);
|
||||
CREATE INDEX av4_i4 ON av4(a, b, c);
|
||||
INSERT INTO av4 VALUES('av4 a', 'av4 b', 'av4 c');
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test autovacuum-2.5.2 {
|
||||
execsql {
|
||||
SELECT name, rootpage FROM sqlite_master;
|
||||
}
|
||||
} [list av1 3 sqlite_autoindex_av1_1 4 \
|
||||
av2 5 sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \
|
||||
av3 9 sqlite_autoindex_av3_1 10 av3_i1 11 \
|
||||
av4 12 av4_i1 13 av4_i2 14 av4_i3 15 av4_i4 16 \
|
||||
]
|
||||
|
||||
# The following 4 tests are SELECT queries that use the indices created.
|
||||
# If the root-pages in the internal schema are not updated correctly when
|
||||
# a table or indice is moved, these queries will fail. They are repeated
|
||||
# after each table is dropped (i.e. as test cases 2.5.*.[1..4]).
|
||||
do_test autovacuum-2.5.2.1 {
|
||||
execsql {
|
||||
SELECT * FROM av1 WHERE a = 'av1 a';
|
||||
}
|
||||
} {{av1 a} {av1 b} {av1 c}}
|
||||
do_test autovacuum-2.5.2.2 {
|
||||
execsql {
|
||||
SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'
|
||||
}
|
||||
} {{av2 a} {av2 b} {av2 c}}
|
||||
do_test autovacuum-2.5.2.3 {
|
||||
execsql {
|
||||
SELECT * FROM av3 WHERE a = 'av3 a' AND b = 'av3 b';
|
||||
}
|
||||
} {{av3 a} {av3 b} {av3 c}}
|
||||
do_test autovacuum-2.5.2.4 {
|
||||
execsql {
|
||||
SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c';
|
||||
}
|
||||
} {{av4 a} {av4 b} {av4 c}}
|
||||
|
||||
# Drop table av3. Indices av4_i2, av4_i3 and av4_i4 are moved to fill the two
|
||||
# root pages vacated. The operation proceeds as:
|
||||
# Step 1: Delete av3_i1 (root-page 11). Move root-page of av4_i4 to page 11.
|
||||
# Step 2: Delete av3 (root-page 10). Move root-page of av4_i3 to page 10.
|
||||
# Step 3: Delete sqlite_autoindex_av1_3 (root-page 9). Move av4_i2 to page 9.
|
||||
do_test autovacuum-2.5.3 {
|
||||
execsql {
|
||||
DROP TABLE av3;
|
||||
SELECT name, rootpage FROM sqlite_master;
|
||||
}
|
||||
} [list av1 3 sqlite_autoindex_av1_1 4 \
|
||||
av2 5 sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \
|
||||
av4 12 av4_i1 13 av4_i2 9 av4_i3 10 av4_i4 11 \
|
||||
]
|
||||
do_test autovacuum-2.5.3.1 {
|
||||
execsql {
|
||||
SELECT * FROM av1 WHERE a = 'av1 a';
|
||||
}
|
||||
} {{av1 a} {av1 b} {av1 c}}
|
||||
do_test autovacuum-2.5.3.2 {
|
||||
execsql {
|
||||
SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'
|
||||
}
|
||||
} {{av2 a} {av2 b} {av2 c}}
|
||||
do_test autovacuum-2.5.3.3 {
|
||||
execsql {
|
||||
SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c';
|
||||
}
|
||||
} {{av4 a} {av4 b} {av4 c}}
|
||||
|
||||
# Drop table av1:
|
||||
# Step 1: Delete av1 (root page 4). Root-page of av4_i1 fills the gap.
|
||||
# Step 2: Delete sqlite_autoindex_av1_1 (root page 3). Move av4 to the gap.
|
||||
do_test autovacuum-2.5.4 {
|
||||
execsql {
|
||||
DROP TABLE av1;
|
||||
SELECT name, rootpage FROM sqlite_master;
|
||||
}
|
||||
} [list av2 5 sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \
|
||||
av4 3 av4_i1 4 av4_i2 9 av4_i3 10 av4_i4 11 \
|
||||
]
|
||||
do_test autovacuum-2.5.4.2 {
|
||||
execsql {
|
||||
SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'
|
||||
}
|
||||
} {{av2 a} {av2 b} {av2 c}}
|
||||
do_test autovacuum-2.5.4.4 {
|
||||
execsql {
|
||||
SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c';
|
||||
}
|
||||
} {{av4 a} {av4 b} {av4 c}}
|
||||
|
||||
# Drop table av4:
|
||||
# Step 1: Delete av4_i4.
|
||||
# Step 2: Delete av4_i3.
|
||||
# Step 3: Delete av4_i2.
|
||||
# Step 4: Delete av4_i1. av2_i2 replaces it.
|
||||
# Step 5: Delete av4. av2_i1 replaces it.
|
||||
do_test autovacuum-2.5.5 {
|
||||
execsql {
|
||||
DROP TABLE av4;
|
||||
SELECT name, rootpage FROM sqlite_master;
|
||||
}
|
||||
} [list av2 5 sqlite_autoindex_av2_1 6 av2_i1 3 av2_i2 4]
|
||||
do_test autovacuum-2.5.5.2 {
|
||||
execsql {
|
||||
SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'
|
||||
}
|
||||
} {{av2 a} {av2 b} {av2 c}}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Test cases autovacuum-3.* test the operation of the "PRAGMA auto_vacuum"
|
||||
# command.
|
||||
#
|
||||
do_test autovacuum-3.1 {
|
||||
execsql {
|
||||
PRAGMA auto_vacuum;
|
||||
}
|
||||
} {1}
|
||||
do_test autovacuum-3.2 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
PRAGMA auto_vacuum;
|
||||
}
|
||||
} {1}
|
||||
do_test autovacuum-3.3 {
|
||||
execsql {
|
||||
PRAGMA auto_vacuum = 0;
|
||||
PRAGMA auto_vacuum;
|
||||
}
|
||||
} {1}
|
||||
|
||||
do_test autovacuum-3.4 {
|
||||
db close
|
||||
file delete -force test.db
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
PRAGMA auto_vacuum;
|
||||
}
|
||||
} $AUTOVACUUM
|
||||
do_test autovacuum-3.5 {
|
||||
execsql {
|
||||
CREATE TABLE av1(x);
|
||||
PRAGMA auto_vacuum;
|
||||
}
|
||||
} $AUTOVACUUM
|
||||
do_test autovacuum-3.6 {
|
||||
execsql {
|
||||
PRAGMA auto_vacuum = 1;
|
||||
PRAGMA auto_vacuum;
|
||||
}
|
||||
} $AUTOVACUUM
|
||||
do_test autovacuum-3.7 {
|
||||
execsql {
|
||||
DROP TABLE av1;
|
||||
}
|
||||
file_pages
|
||||
} [expr $AUTOVACUUM?1:2]
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Test that if a statement transaction around a CREATE INDEX statement is
|
||||
# rolled back no corruption occurs.
|
||||
#
|
||||
do_test autovacuum-4.1 {
|
||||
execsql {
|
||||
CREATE TABLE av1(a, b);
|
||||
BEGIN;
|
||||
}
|
||||
for {set i 0} {$i<100} {incr i} {
|
||||
execsql "INSERT INTO av1 VALUES($i, '[string repeat X 200]');"
|
||||
}
|
||||
execsql "INSERT INTO av1 VALUES(99, '[string repeat X 200]');"
|
||||
execsql {
|
||||
SELECT sum(a) FROM av1;
|
||||
}
|
||||
} {5049}
|
||||
do_test autovacuum-4.2 {
|
||||
catchsql {
|
||||
CREATE UNIQUE INDEX av1_i ON av1(a);
|
||||
}
|
||||
} {1 {indexed columns are not unique}}
|
||||
do_test autovacuum-4.3 {
|
||||
execsql {
|
||||
SELECT sum(a) FROM av1;
|
||||
}
|
||||
} {5049}
|
||||
do_test autovacuum-4.4 {
|
||||
execsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,58 @@
|
||||
# 2001 September 15
|
||||
#
|
||||
# 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 runs the tests in the file crash.test with auto-vacuum enabled
|
||||
# databases.
|
||||
#
|
||||
# $Id: autovacuum_crash.test,v 1.2 2005/01/16 09:06:34 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If this build of the library does not support auto-vacuum, omit this
|
||||
# whole file.
|
||||
ifcapable {!autovacuum} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
rename finish_test really_finish_test2
|
||||
proc finish_test {} {}
|
||||
set ISQUICK 1
|
||||
|
||||
rename sqlite3 real_sqlite3
|
||||
proc sqlite3 {args} {
|
||||
set r [eval "real_sqlite3 $args"]
|
||||
if { [llength $args] == 2 } {
|
||||
[lindex $args 0] eval {pragma auto_vacuum = 1}
|
||||
}
|
||||
set r
|
||||
}
|
||||
|
||||
rename do_test really_do_test
|
||||
proc do_test {args} {
|
||||
set sc [concat really_do_test "autovacuum-[lindex $args 0]" \
|
||||
[lrange $args 1 end]]
|
||||
eval $sc
|
||||
}
|
||||
|
||||
source $testdir/crash.test
|
||||
|
||||
rename sqlite3 ""
|
||||
rename real_sqlite3 sqlite3
|
||||
rename finish_test ""
|
||||
rename really_finish_test2 finish_test
|
||||
rename do_test ""
|
||||
rename really_do_test do_test
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# 2001 September 15
|
||||
#
|
||||
# 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 runs the tests in the file crash.test with auto-vacuum enabled
|
||||
# databases.
|
||||
#
|
||||
# $Id: autovacuum_ioerr.test,v 1.2 2005/01/16 09:06:34 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If this build of the library does not support auto-vacuum, omit this
|
||||
# whole file.
|
||||
ifcapable {!autovacuum} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
rename finish_test really_finish_test2
|
||||
proc finish_test {} {}
|
||||
set ISQUICK 1
|
||||
|
||||
rename sqlite3 real_sqlite3
|
||||
proc sqlite3 {args} {
|
||||
set r [eval "real_sqlite3 $args"]
|
||||
if { [llength $args] == 2 } {
|
||||
[lindex $args 0] eval {pragma auto_vacuum = 1}
|
||||
}
|
||||
set r
|
||||
}
|
||||
|
||||
rename do_test really_do_test
|
||||
proc do_test {args} {
|
||||
set sc [concat really_do_test "autovacuum-[lindex $args 0]" \
|
||||
[lrange $args 1 end]]
|
||||
eval $sc
|
||||
}
|
||||
|
||||
source $testdir/ioerr.test
|
||||
|
||||
rename sqlite3 ""
|
||||
rename real_sqlite3 sqlite3
|
||||
rename finish_test ""
|
||||
rename really_finish_test2 finish_test
|
||||
rename do_test ""
|
||||
rename really_do_test do_test
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
# 2001 October 12
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing for correct handling of I/O errors
|
||||
# such as writes failing because the disk is full.
|
||||
#
|
||||
# The tests in this file use special facilities that are only
|
||||
# available in the SQLite test fixture.
|
||||
#
|
||||
# $Id: autovacuum_ioerr2.test,v 1.5 2005/01/29 09:14:05 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If this build of the library does not support auto-vacuum, omit this
|
||||
# whole file.
|
||||
ifcapable {!autovacuum} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_ioerr_test autovacuum-ioerr2-1 -sqlprep {
|
||||
PRAGMA auto_vacuum = 1;
|
||||
CREATE TABLE abc(a);
|
||||
INSERT INTO abc VALUES(randstr(1500,1500));
|
||||
} -sqlbody {
|
||||
CREATE TABLE abc2(a);
|
||||
BEGIN;
|
||||
DELETE FROM abc;
|
||||
INSERT INTO abc VALUES(randstr(1500,1500));
|
||||
CREATE TABLE abc3(a);
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
do_ioerr_test autovacuum-ioerr2-2 -tclprep {
|
||||
execsql {
|
||||
PRAGMA auto_vacuum = 1;
|
||||
PRAGMA cache_size = 10;
|
||||
BEGIN;
|
||||
CREATE TABLE abc(a);
|
||||
INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 4 is overflow
|
||||
INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 5 is overflow
|
||||
}
|
||||
for {set i 0} {$i<150} {incr i} {
|
||||
execsql {
|
||||
INSERT INTO abc VALUES(randstr(100,100));
|
||||
}
|
||||
}
|
||||
execsql COMMIT
|
||||
} -sqlbody {
|
||||
BEGIN;
|
||||
DELETE FROM abc WHERE length(a)>100;
|
||||
UPDATE abc SET a = randstr(90,90);
|
||||
CREATE TABLE abc3(a);
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
do_ioerr_test autovacuum-ioerr2-3 -sqlprep {
|
||||
PRAGMA auto_vacuum = 1;
|
||||
CREATE TABLE abc(a);
|
||||
CREATE TABLE abc2(b);
|
||||
} -sqlbody {
|
||||
BEGIN;
|
||||
INSERT INTO abc2 VALUES(10);
|
||||
DROP TABLE abc;
|
||||
COMMIT;
|
||||
DROP TABLE abc2;
|
||||
}
|
||||
|
||||
file delete -force backup.db
|
||||
ifcapable subquery {
|
||||
do_ioerr_test autovacuum-ioerr2-4 -tclprep {
|
||||
if {![file exists backup.db]} {
|
||||
sqlite3 dbb backup.db
|
||||
execsql {
|
||||
PRAGMA auto_vacuum = 1;
|
||||
BEGIN;
|
||||
CREATE TABLE abc(a);
|
||||
INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 4 is overflow
|
||||
INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 5 is overflow
|
||||
} dbb
|
||||
for {set i 0} {$i<2500} {incr i} {
|
||||
execsql {
|
||||
INSERT INTO abc VALUES(randstr(100,100));
|
||||
} dbb
|
||||
}
|
||||
execsql {
|
||||
COMMIT;
|
||||
PRAGMA cache_size = 10;
|
||||
} dbb
|
||||
dbb close
|
||||
}
|
||||
db close
|
||||
file delete -force test.db
|
||||
file delete -force test.db-journal
|
||||
copy_file backup.db test.db
|
||||
set ::DB [sqlite3 db test.db]
|
||||
execsql {
|
||||
PRAGMA cache_size = 10;
|
||||
}
|
||||
} -sqlbody {
|
||||
BEGIN;
|
||||
DELETE FROM abc WHERE oid < 3;
|
||||
UPDATE abc SET a = randstr(100,100) WHERE oid > 2300;
|
||||
UPDATE abc SET a = randstr(1100,1100) WHERE oid =
|
||||
(select max(oid) from abc);
|
||||
COMMIT;
|
||||
}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
# 2005 July 28
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the use of indices in WHERE clauses
|
||||
# when the WHERE clause contains the BETWEEN operator.
|
||||
#
|
||||
# $Id: between.test,v 1.1 2005/07/28 23:12:08 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Build some test data
|
||||
#
|
||||
do_test between-1.0 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE t1(w int, x int, y int, z int);
|
||||
}
|
||||
for {set i 1} {$i<=100} {incr i} {
|
||||
set w $i
|
||||
set x [expr {int(log($i)/log(2))}]
|
||||
set y [expr {$i*$i + 2*$i + 1}]
|
||||
set z [expr {$x+$y}]
|
||||
execsql {INSERT INTO t1 VALUES($::w,$::x,$::y,$::z)}
|
||||
}
|
||||
execsql {
|
||||
CREATE UNIQUE INDEX i1w ON t1(w);
|
||||
CREATE INDEX i1xy ON t1(x,y);
|
||||
CREATE INDEX i1zyx ON t1(z,y,x);
|
||||
COMMIT;
|
||||
}
|
||||
} {}
|
||||
|
||||
# This procedure executes the SQL. Then it appends to the result the
|
||||
# "sort" or "nosort" keyword depending on whether or not any sorting
|
||||
# is done. Then it appends the ::sqlite_query_plan variable.
|
||||
#
|
||||
proc queryplan {sql} {
|
||||
set ::sqlite_sort_count 0
|
||||
set data [execsql $sql]
|
||||
if {$::sqlite_sort_count} {set x sort} {set x nosort}
|
||||
lappend data $x
|
||||
return [concat $data $::sqlite_query_plan]
|
||||
}
|
||||
|
||||
do_test between-1.1.1 {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE w BETWEEN 5 AND 6 ORDER BY +w
|
||||
}
|
||||
} {5 2 36 38 6 2 49 51 sort t1 i1w}
|
||||
do_test between-1.1.2 {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE +w BETWEEN 5 AND 6 ORDER BY +w
|
||||
}
|
||||
} {5 2 36 38 6 2 49 51 sort t1 {}}
|
||||
do_test between-1.2.1 {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE w BETWEEN 5 AND 65-y ORDER BY +w
|
||||
}
|
||||
} {5 2 36 38 6 2 49 51 sort t1 i1w}
|
||||
do_test between-1.2.2 {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE +w BETWEEN 5 AND 65-y ORDER BY +w
|
||||
}
|
||||
} {5 2 36 38 6 2 49 51 sort t1 {}}
|
||||
do_test between-1.3.1 {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE w BETWEEN 41-y AND 6 ORDER BY +w
|
||||
}
|
||||
} {5 2 36 38 6 2 49 51 sort t1 i1w}
|
||||
do_test between-1.3.2 {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE +w BETWEEN 41-y AND 6 ORDER BY +w
|
||||
}
|
||||
} {5 2 36 38 6 2 49 51 sort t1 {}}
|
||||
do_test between-1.4 {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE w BETWEEN 41-y AND 65-y ORDER BY +w
|
||||
}
|
||||
} {5 2 36 38 6 2 49 51 sort t1 {}}
|
||||
do_test between-1.5.1 {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE 26 BETWEEN y AND z ORDER BY +w
|
||||
}
|
||||
} {4 2 25 27 sort t1 i1zyx}
|
||||
do_test between-1.5.2 {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE 26 BETWEEN +y AND z ORDER BY +w
|
||||
}
|
||||
} {4 2 25 27 sort t1 i1zyx}
|
||||
do_test between-1.5.3 {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE 26 BETWEEN y AND +z ORDER BY +w
|
||||
}
|
||||
} {4 2 25 27 sort t1 {}}
|
||||
|
||||
|
||||
finish_test
|
||||
+6
-2
@@ -12,7 +12,7 @@
|
||||
# focus of this script testing the ability of SQLite to handle database
|
||||
# files larger than 4GB.
|
||||
#
|
||||
# $Id: bigfile.test,v 1.6 2004/06/30 11:28:13 drh Exp $
|
||||
# $Id: bigfile.test,v 1.8 2005/09/07 23:05:22 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -71,7 +71,6 @@ do_test bigfile-1.2 {
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
|
||||
|
||||
# The previous test may fail on some systems because they are unable
|
||||
# to handle large files. If that is so, then skip all of the following
|
||||
# tests. We will know the above test failed because the "db" command
|
||||
@@ -176,6 +175,11 @@ do_test bigfile-1.16 {
|
||||
SELECT md5sum(x) FROM t3;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.17 {
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t4;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
|
||||
} ;# End of the "if( db command exists )"
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user