Compare commits
1523 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 | |||
| bc58e70e90 | |||
| d1b03577ec | |||
| c44af71c08 | |||
| 32fc1a5c51 | |||
| 51a6ec4892 | |||
| 5bb7ffe1ea | |||
| 92f02c31d4 | |||
| 66cbd1543b | |||
| 91bb0eedd1 | |||
| c8d7441eb4 | |||
| 855eb1cf02 | |||
| 4e5ffc5f8d | |||
| ee696e2218 | |||
| 57ee3cc2ce | |||
| 7f4680c92e | |||
| dd3d4598bf | |||
| effd02bcbe | |||
| 208f80a7d4 | |||
| 7cdc3e6578 | |||
| d271df0569 | |||
| 37e012846c | |||
| f298718005 | |||
| 8cdbf83690 | |||
| fbc4ee7b70 | |||
| 6f3a3efe03 | |||
| febe1060f9 | |||
| 4aec8b65c7 | |||
| 1bcdb0c0b2 | |||
| 3d2efea4fa | |||
| db06183c22 | |||
| 1d895039e2 | |||
| 2c6674cf7e | |||
| 9d74b4c516 | |||
| fdb38064b0 | |||
| 290c19482e | |||
| 92febd92ad | |||
| 895d747226 | |||
| e8cf2cacb1 | |||
| 7ac25c7510 | |||
| 2889ae7248 | |||
| cb4c40ba0e | |||
| 2b74d70a38 | |||
| 34f4732b06 | |||
| dc3ff9c34c | |||
| 181fc99332 | |||
| ae15787643 | |||
| 22ac46d15d | |||
| 472cbf6b9e | |||
| ab3f9fea05 | |||
| 458b8fc8bc | |||
| b78825070e | |||
| 71c697ef4d | |||
| 4c755c0f53 | |||
| 8dcd7cab83 | |||
| 1d64fc1a5e | |||
| 00afe0b374 | |||
| b860bc97d5 | |||
| a9600bc692 | |||
| d2f0a72331 | |||
| db2d9a0bbb | |||
| feac5f8dbc | |||
| 9796ef5804 | |||
| adfa3daf49 | |||
| cced337e35 | |||
| d89fd07dc3 | |||
| 1211de3709 | |||
| be5c89acd0 | |||
| 956bc92cde | |||
| 3f7d4e49d8 | |||
| 234c39dff7 | |||
| 3e27c02625 | |||
| 8ea1a04ff8 | |||
| ad19857f5a | |||
| 20753fb2d0 | |||
| 8685a946b8 | |||
| 91551097ea | |||
| 1b06fbcd72 | |||
| 7dcc2c9e27 | |||
| f8c3a21022 | |||
| 1dba027428 | |||
| 25d6543de5 | |||
| 89aa31e509 | |||
| 2011d5f5e5 | |||
| 90f5ecb39d | |||
| 900dfba8ef | |||
| a4aac81cdf | |||
| 422b3024e2 | |||
| 17c402944a | |||
| 193bd777aa | |||
| 0bb132bedc | |||
| 6d08b4d647 | |||
| cf55b7aef7 | |||
| 6458e39c12 | |||
| 78d153eecd | |||
| fd1f394af2 | |||
| 2c61c070d2 | |||
| bab39e1358 | |||
| ea48eb2eef | |||
| 88215bdfde | |||
| d5b447d9ac | |||
| 8d7e24f1d3 | |||
| 2ffb11855a | |||
| c275b4ea91 | |||
| 27438cf186 | |||
| 12b3444483 | |||
| 6f137d44e7 | |||
| 8feb4b1d9e | |||
| 755b6ba9f0 | |||
| 5f6a87b3dd | |||
| 83ca160a33 | |||
| 8cd9db004a | |||
| 1020d49a31 | |||
| 1af3fdb4dc | |||
| 9eb516c0eb | |||
| e29b1a05a7 | |||
| dd809b087f | |||
| 4ebfef14e3 | |||
| 75f6a032c4 | |||
| 939a16d622 | |||
| 2b735010f5 | |||
| ee4a1872c5 | |||
| 5efb145d6e | |||
| b733c18436 | |||
| 070aaad8e8 | |||
| 49d55ac3f5 | |||
| 76d7f8b385 | |||
| 7acde5a33b | |||
| 93d648d4b4 | |||
| 7dca81b84c | |||
| 25b3363d2c | |||
| 5b59af85c7 | |||
| 13073931a3 | |||
| 376deb182a | |||
| 3ea64406fc | |||
| 91b48aa1af | |||
| 05056307fd | |||
| 96fb0dd55a | |||
| bc6ada4103 | |||
| 46c43edd39 | |||
| 9d213ef022 | |||
| cc19587998 | |||
| 5b809e3198 | |||
| 93cd039570 | |||
| 54bbdf4f7f | |||
| db96db107c | |||
| 2d1f92a13d | |||
| 7939aa87e3 | |||
| 4230e2c7f3 | |||
| c8c1158be2 | |||
| 312d6b36e3 | |||
| 779c6a0647 | |||
| 0f14e2ebed | |||
| b97759ed11 | |||
| fd69dd6b3d | |||
| ef0715c20a | |||
| 8a41449ecc | |||
| 2b444853e0 | |||
| 5fdae7711a | |||
| f46188911d | |||
| 2ec81649a5 | |||
| 489468cf26 | |||
| 8191bff0c2 | |||
| c3e8f5ef52 | |||
| e0d4b060db | |||
| 55e0af4653 | |||
| fe587031cf | |||
| 6a179ea796 | |||
| 6a6124e27a | |||
| 5260f7e925 | |||
| b089c0b722 | |||
| b5548a8b20 | |||
| 3dea76474c | |||
| b2c7f5b31e | |||
| e35ee196dc | |||
| 40b38dcdf8 | |||
| 1e8770ec89 | |||
| 91cf71b01f | |||
| 75edc16f07 | |||
| c8e9a2df77 | |||
| cafadbac02 | |||
| 4cb1607bc0 | |||
| fa916940fa | |||
| 90ba3bd065 | |||
| f42f25c2c5 | |||
| f187bd9d64 | |||
| 7657240a21 | |||
| e970767144 | |||
| 256a4ec4a3 | |||
| afded26eac | |||
| 575414ae8d | |||
| cf991b375a | |||
| 3aeab9e438 | |||
| 1ba1b5511c | |||
| e12c17bab3 | |||
| 9d951766ea | |||
| ef317ab577 | |||
| ece80f1e48 | |||
| d7e69648c1 | |||
| 22276bd773 | |||
| 1b743be858 | |||
| 7cf8c55add | |||
| c4d8d097dc | |||
| fa9249dd98 | |||
| f1f7d25536 | |||
| d8c8d5cec8 | |||
| 8eebadf133 | |||
| 03601b8d57 | |||
| d86596e0e2 | |||
| e5b7a0e8ee | |||
| 645f63ed02 | |||
| d1e3bee1a0 | |||
| 241db313b4 | |||
| 83f4707ab2 | |||
| 8a6c550d94 | |||
| efad99959b | |||
| e302663615 | |||
| 369340af3d | |||
| 001c0bdc28 | |||
| 0f290bf7b8 | |||
| da71ce1623 | |||
| da95f8a67f | |||
| e159fdf21c | |||
| 72c952a1c4 | |||
| 9e6db7d70f | |||
| 00e279d9f7 | |||
| b28af71a22 | |||
| d664d9a2bb | |||
| 0e3d74761d | |||
| 124b27e654 | |||
| f92c7ff74a | |||
| 998da3a287 | |||
| a99db3b6ac | |||
| 65d8439342 | |||
| 7ec0191c42 | |||
| ec8450f6cb | |||
| 92f9a1bbda | |||
| f9d64d2c30 | |||
| 96d81f99d4 | |||
| b7ce0c90a3 | |||
| d008cfe305 | |||
| d3fc6d0e3b | |||
| ef4ac8f9df | |||
| 81c95efaf5 | |||
| f12f80f071 | |||
| 6b29334cd2 | |||
| bdb4383a90 | |||
| 38f8271f81 | |||
| 43d0578e04 | |||
| 8107be2c7e | |||
| f5628d7825 | |||
| 829512baa0 | |||
| 8d81b86a2e | |||
| 5314c4d7ab | |||
| bfd6cce56b | |||
| a285422922 | |||
| ededfd5e83 | |||
| f736b77160 | |||
| 3f6b087471 | |||
| d09b592f63 | |||
| f7df9ccfe7 | |||
| 742f947b1d | |||
| cfe9a69f90 | |||
| 8def5ea203 | |||
| 5c4c77878d | |||
| eac7a362f6 | |||
| 7b93ed3d48 | |||
| e00484002f | |||
| b20e56b451 | |||
| 369f27eb51 | |||
| fbcd585fe6 | |||
| 0c6cc4ed19 | |||
| 1f5957167b | |||
| bf9a7e4d4e | |||
| 2dd59365ed | |||
| 026d270ca6 | |||
| 2ac79703b1 | |||
| f3ce83f5f6 | |||
| 66b978a415 | |||
| 3fe83ac7a1 | |||
| 962398d395 | |||
| f9d19a6b3f | |||
| 19bea40160 | |||
| 5865e3d54f | |||
| aa5ccdf5b8 | |||
| 59eb676017 | |||
| eafe05b0ce | |||
| e1632b271d | |||
| 4774b13029 | |||
| e61cffc203 | |||
| 406c3f9284 | |||
| d8123366c4 | |||
| 3cde3bb0da | |||
| 2a764eb0cd | |||
| dc8453fd7a | |||
| 31ef3b91f5 | |||
| 52619dfb7f | |||
| ce2663ccc8 | |||
| dc1bdc4f9d | |||
| 726de599bd | |||
| ef5ecb4126 | |||
| 4e6af1347c | |||
| caec4e7a59 | |||
| d2b65b9fad | |||
| 7cedc8d4d6 | |||
| 0de0bb3360 | |||
| a3f3a5f3d2 | |||
| 466be56bcf | |||
| 35d4c2f4b8 | |||
| a60accbdb2 | |||
| 427eab53e1 | |||
| a6ecd33851 | |||
| f8646695a2 | |||
| ff13c7d6a3 | |||
| c9e0686ead | |||
| ae2b40c47d | |||
| a6abd04193 | |||
| 89ac8c1a70 | |||
| faa57acc9f | |||
| c039139807 | |||
| 0202b29ef7 | |||
| 80242055e5 | |||
| b3e043463d | |||
| 3f41e976e8 | |||
| 4f057f904a | |||
| 2ac3ee9787 | |||
| 517eb64616 | |||
| 8e227875dd | |||
| e54ca3fe2e | |||
| ad7dd42558 | |||
| d02eb1fdf4 | |||
| 51c6d9633f | |||
| 682f68b020 | |||
| 2a02e33950 | |||
| a2fce64acc | |||
| 9eed505701 | |||
| 24162fe668 | |||
| 13adf8a071 | |||
| ecb2a9644b | |||
| 7a224deb5f | |||
| df0148931d | |||
| 193c72f84e | |||
| cc74b1429d | |||
| 9a1d0abed4 | |||
| fedc8347c0 | |||
| 26dbdbf857 | |||
| 014ac19de2 | |||
| 93db69ee0f | |||
| d1a2553ae6 | |||
| f20b21c8fd | |||
| 218dc69436 | |||
| 3f4fedb2c4 | |||
| 9c054830b4 | |||
| 1d482dd917 | |||
| 75d82cc4bf | |||
| 02f9f6b38f | |||
| d4acf19cb0 | |||
| e100f835d3 | |||
| 3a81de11b6 | |||
| 11146c9c2e | |||
| 77d83ba50f | |||
| ee5741ea78 | |||
| 33752f8acf | |||
| 1d850a72c2 | |||
| a19b775db9 | |||
| e51c44f481 | |||
| 271efa5a28 | |||
| 3a41a3fe66 | |||
| 696b32fa4e | |||
| 6fec076238 | |||
| 436051582f | |||
| 0f69c1e3ec | |||
| bd26f925e0 | |||
| 3df6b2570f | |||
| e7d00f5825 | |||
| ef2cb63e9e | |||
| 51846b56ed | |||
| 76d505baad | |||
| 48dec7e215 | |||
| a8858103c9 | |||
| cbb18d2256 | |||
| d578820154 | |||
| f3218fea00 | |||
| 25aa1b4580 | |||
| 61de0d1b99 | |||
| d3194f5a4a | |||
| 5f3b4ab53c | |||
| 6d88bad4f9 | |||
| 49e4643ee8 | |||
| 3fd0a736bf | |||
| 30ccda1006 | |||
| f93bbbea47 | |||
| c572ef7fcd | |||
| f44795013f | |||
| eb2e176a12 | |||
| ea61b2c4fc | |||
| 04f2e68d0c | |||
| 69174eb484 | |||
| 4f26d6c429 | |||
| f9b596ebc0 | |||
| b77f5dadbf | |||
| 3cf8606395 | |||
| 398eae781e | |||
| 6590493d53 | |||
| fc57d7bf72 | |||
| 17240fd90f | |||
| 8c6fa9b03b | |||
| 98d30677b0 | |||
| 22322fd42b | |||
| 0ae8b83155 | |||
| 7e18c259fe | |||
| 88208050b6 | |||
| 6ddcca553d | |||
| 35bb9d026e | |||
| 51ad0ecd28 | |||
| 7e435458a0 | |||
| 0ffba6b269 | |||
| bd7e46086e | |||
| 8a6b5411b3 | |||
| 93d4675d67 | |||
| 7906975a0f | |||
| be94025f3b | |||
| bbd42a6dda | |||
| 60ca804396 | |||
| fe7fdb7344 | |||
| e1cd98740f | |||
| 802908635d | |||
| 28d47b57ec | |||
| 172bc3938a | |||
| 18f4189055 | |||
| b1bc95315b | |||
| ab01f61ab8 | |||
| 1483e14cf7 | |||
| 7f0f12e3ab | |||
| 83ab5a8f62 | |||
| ca6b291fcf | |||
| 106bb236a8 | |||
| ce665cf60e | |||
| 736c22b803 | |||
| 2f2322fa9c | |||
| 4ad1713c5e | |||
| ffbc30884c | |||
| 1186b0a08b | |||
| d3d39e939d | |||
| 53db145800 | |||
| e2ea40d36d | |||
| 1ad3b9e61a | |||
| 6622cce372 | |||
| 137b35e480 | |||
| d686179207 | |||
| b6f5452fb2 | |||
| 465407d9b6 | |||
| e3209e4eb6 | |||
| 51e3d8e204 | |||
| a34a84fe1a | |||
| fec19aad44 | |||
| 7cf6e4de35 | |||
| 772ae62a82 | |||
| 09e490ce3c | |||
| 5a12e68986 | |||
| 54db47e3da | |||
| c7134988f4 | |||
| e4b7c01fd5 | |||
| 295ba55ac6 | |||
| a9fd84b034 | |||
| 428702d730 | |||
| d93b626c0a | |||
| 7efd61f240 | |||
| d8820e80fc | |||
| 10c0fa6a75 | |||
| bf3b721fab | |||
| 84ac9d02dd | |||
| eb015e03e1 | |||
| b4964b723c | |||
| e014a83880 | |||
| 93edea9380 | |||
| 96f5b7672d | |||
| f9dd2c2e04 | |||
| a37cdde042 | |||
| 3add367f2f | |||
| d7556d209e | |||
| 9188b38919 | |||
| fa1a98a24e | |||
| 6d2fb15475 | |||
| 10617cddf6 | |||
| e6c438166f | |||
| 940762585e | |||
| 13dadd2798 | |||
| 3d1bfeaa22 | |||
| b6f4148607 | |||
| e7c8d58a1f | |||
| 50ce750c2a | |||
| 9688f3796b | |||
| 96fc5fe6a5 | |||
| 183f9f7360 | |||
| 452c989fd8 | |||
| 6f11bef7d6 | |||
| fc70e6fcec | |||
| 8b18dd4fb5 | |||
| 4a1c380a4b | |||
| ac69b05efa | |||
| 8d059845fc | |||
| cfcdaefe11 | |||
| 779b6d357a | |||
| f4dada7512 | |||
| bf57cfebc2 | |||
| a3b321df91 | |||
| 33825340cb | |||
| 9400f26176 | |||
| 3d68f03a96 | |||
| 36a3c70b98 | |||
| 6490bebd62 | |||
| 0dbe72b952 | |||
| 643631771d | |||
| 49f737d124 | |||
| 1bbf5ee85c | |||
| 0e1c19e2b6 | |||
| 5f8d8a844c | |||
| f328bc80ce | |||
| 3644f0858d | |||
| 24cd67e732 | |||
| 3dc0b8ebe3 | |||
| 1d994699a0 | |||
| 132872b37e | |||
| 6f8a503d71 | |||
| 24b03fd055 | |||
| 90e4d95d14 | |||
| 9490bee025 | |||
| 192ac1dcab | |||
| 8e150818ec | |||
| 189621d81f | |||
| 3a4c141357 | |||
| da200cc1c7 | |||
| 457f501464 | |||
| c12fc0d85f | |||
| c8629a13e1 | |||
| ab9f7f12d5 | |||
| eec983e175 | |||
| 4adee20fcb | |||
| 9b17127705 | |||
| c39e000bbf | |||
| de64713041 | |||
| a34b676483 | |||
| 4fc0fb4358 | |||
| 697e6e27b8 | |||
| 998b56c351 | |||
| 23e11cab7d | |||
| a5d14fe7c5 | |||
| 9102529d8c | |||
| 4b70f11aea | |||
| 8856d6aad2 | |||
| 3aac2dd7bc | |||
| 9e572e608f | |||
| cc83b6e071 | |||
| 226e5f9de7 | |||
| 1bdd9b5787 | |||
| 932ee8f4bb | |||
| d888544275 | |||
| 8b8891bf0a | |||
| 276fd588d8 | |||
| a8804c82b8 | |||
| 6ff15d0c49 | |||
| 6da834a8b4 | |||
| 371cb93a2a | |||
| 6e17529e97 | |||
| 1a72d72a7f | |||
| 7972e32a9e | |||
| 66eb270d6b | |||
| a0c9a112de | |||
| 06333689a7 | |||
| a2cfd57491 | |||
| e3f25eb91e | |||
| 489c4677a0 | |||
| aa5707cd5e | |||
| 79f14b7240 | |||
| b1aa04fccc | |||
| 9bc8b93f41 | |||
| 0d131ab716 | |||
| b6829e94bd | |||
| 446536a089 | |||
| 33a9ad2f8c | |||
| 3039c0a896 | |||
| 1d78a38f51 | |||
| 964dbb1e6c | |||
| f146a77677 | |||
| 268380ca9e | |||
| d41d73d556 | |||
| f73287ceb0 | |||
| 946966f2a1 | |||
| cd44690ad0 | |||
| 02f75f19e5 | |||
| 701a0aebe2 | |||
| d383401c6a | |||
| f7a9e1ac87 | |||
| eb9a9e8888 | |||
| 2d3917da29 | |||
| 60d316542f | |||
| b621c23775 | |||
| 3e7bc9ca1c | |||
| 5f968436e6 | |||
| 8722318f3c | |||
| 905793e249 | |||
| 8eb2cce55c | |||
| 8307ac7521 | |||
| 9d524f6b9c | |||
| a503d7312a | |||
| b0c374ffbb | |||
| fcabd4641e | |||
| 784d86f716 | |||
| 9cbe7ca7db | |||
| fef9765507 | |||
| 230680276c | |||
| 960ac04f4f | |||
| d6502758b4 | |||
| 826fb5a3f8 | |||
| 1d85d93158 | |||
| 8a6ac0adbc | |||
| a1f9b5ee0b | |||
| b5f70c2ef1 | |||
| eceae45cb5 | |||
| e72daeb0ac | |||
| 50350a15c4 | |||
| 78a7583828 | |||
| e384a4ed4e | |||
| c602f9ae01 | |||
| 4d189ca48f | |||
| 3054efee07 | |||
| 70a931c2ac | |||
| 8ef83ffed8 | |||
| 93581642d2 | |||
| ab9426e242 | |||
| eb8ed70db5 | |||
| 7e26d75094 | |||
| bbd82df617 | |||
| 9eb9e26b82 | |||
| d86a39c866 | |||
| fb044c1d1c | |||
| 4bc058593b | |||
| 57ced9186a | |||
| 2d71ca94a9 | |||
| d0ba193dc7 | |||
| f620b4e2cb | |||
| e2201971ac | |||
| b20ea9d225 | |||
| 8e6283155e | |||
| f603871326 | |||
| f1b07b0ca2 | |||
| 585a3d7c22 | |||
| 34e79ceeb6 | |||
| 240c5795d5 | |||
| e84a306b91 | |||
| 22fbcb8ddd | |||
| 3914aed1de | |||
| 2c79c67fcb | |||
| 6810ce677d | |||
| 00706be366 | |||
| 0c37e6309b | |||
| e8a63423da | |||
| 11437fa6b1 | |||
| 8141f61ef2 | |||
| b733d03749 | |||
| a8d6243bc7 | |||
| 30c84bfd5f | |||
| 0bca353087 | |||
| a8fbdd36f8 | |||
| 4b11c6d3f4 | |||
| cfa5684d47 | |||
| 8bc03a7acd | |||
| b6c9e6e6c1 | |||
| b1639ffeb5 | |||
| 4d5b836545 | |||
| 606c369847 | |||
| a70f2d8d72 | |||
| 51e9a44592 | |||
| 4efc4754f3 | |||
| 1dba727946 | |||
| d1bec47a3d | |||
| 23b2db23b4 | |||
| aa940eacfe | |||
| 751f41217e | |||
| d43ce86fa7 | |||
| 0ee7ae0f0d | |||
| 52b36cabe0 | |||
| f6a7ade6b6 | |||
| c713bdc778 | |||
| 7bdeb312ed | |||
| 31e95bcc5d | |||
| 7b40e60800 | |||
| 572b6f5614 | |||
| ba21256f98 | |||
| 143f3c45a7 | |||
| d1d9fc3397 | |||
| a11846b77a | |||
| 912184b0cf | |||
| c5dd9fa8ab | |||
| 384eef32fd | |||
| 133cdf6eba | |||
| 3a4e19be6b | |||
| 9d4280d53f | |||
| e8e3920a2e | |||
| 202b2df74a | |||
| e807febbc2 | |||
| b46d162d8d | |||
| 7739630451 | |||
| 4ec2e9612f | |||
| cf64d8b820 | |||
| 89ef0eeb9b | |||
| 07fa2a60ea | |||
| dff7ec2cbd | |||
| ae53418df4 | |||
| f586aa8b96 | |||
| 7091cb0566 | |||
| 90f405e3ba | |||
| 93a5c6bdf4 | |||
| 3ddfdf7ac6 | |||
| 2fd2fa0851 | |||
| 6194a5fb75 | |||
| f93e41442e | |||
| 5202560ee5 | |||
| acf01e7ddd | |||
| a6064dcf3b | |||
| 9c4dcca89e | |||
| 0f5c27a168 | |||
| 0c9c3d06d4 | |||
| acf4ac96e3 | |||
| 4be295be07 | |||
| 1285a76973 | |||
| 256ada0fda | |||
| 0f18bfa789 | |||
| 6f8c91caa0 | |||
| 447623d9aa | |||
| 41743984bf | |||
| 3a6629d27e |
+426
-237
@@ -28,21 +28,19 @@ BCC = @BUILD_CC@ @BUILD_CFLAGS@
|
||||
#
|
||||
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@
|
||||
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.
|
||||
#
|
||||
@@ -52,55 +50,90 @@ READLINE_FLAGS = -DHAVE_READLINE=@TARGET_HAVE_READLINE@ @TARGET_READLINE_INC@
|
||||
#
|
||||
LIBREADLINE = @TARGET_READLINE_LIBS@
|
||||
|
||||
# Should the database engine assume text is coded as UTF-8 or iso8859?
|
||||
# Should the database engine be compiled threadsafe
|
||||
#
|
||||
# ENCODING = UTF8
|
||||
# ENCODING = ISO8859
|
||||
ENCODING = @ENCODING@
|
||||
TCC += -DTHREADSAFE=@THREADSAFE@
|
||||
|
||||
# The pthreads library if needed
|
||||
#
|
||||
LIBPTHREAD=@TARGET_THREAD_LIB@
|
||||
|
||||
# Flags controlling use of the in memory btree implementation
|
||||
#
|
||||
# SQLITE_OMIT_INMEMORYDB is defined in order to omit the in-memory
|
||||
# red/black tree driver in the file btree_rb.c
|
||||
#
|
||||
# TEMP_STORE is 0 to force temporary tables to be in a file, 1 to
|
||||
# default to file, 2 to default to memory, and 3 to force temporary
|
||||
# tables to always be in memory.
|
||||
#
|
||||
INMEMORYDB = @INMEMORYDB@
|
||||
INCOREFLAGS = -DTEMP_STORE=@TEMP_STORE@
|
||||
TEMP_STORE = -DTEMP_STORE=@TEMP_STORE@
|
||||
|
||||
ifeq (${INMEMORYDB},0)
|
||||
INCOREFLAGS += -DSQLITE_OMIT_INMEMORYDB=1
|
||||
endif
|
||||
# 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 copy.lo date.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.lo pager.lo parse.lo pragma.lo \
|
||||
printf.lo random.lo select.lo table.lo tokenize.lo \
|
||||
update.lo util.lo vacuum.lo vdbe.lo vdbeaux.lo \
|
||||
where.lo trigger.lo
|
||||
|
||||
# Only build the in-core DB if it is required.
|
||||
ifeq (${INMEMORYDB},1)
|
||||
LIBOBJ += btree_rb.lo
|
||||
endif
|
||||
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/btree_rb.c \
|
||||
$(TOP)/src/build.c \
|
||||
$(TOP)/src/copy.c \
|
||||
$(TOP)/src/callback.c \
|
||||
$(TOP)/src/complete.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/delete.c \
|
||||
$(TOP)/src/expr.c \
|
||||
@@ -108,12 +141,15 @@ SRC = \
|
||||
$(TOP)/src/hash.c \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os.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 \
|
||||
@@ -124,37 +160,54 @@ SRC = \
|
||||
$(TOP)/src/tclsqlite.c \
|
||||
$(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/trigger.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/update.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vacuum.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/vdbeaux.c \
|
||||
$(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
|
||||
|
||||
# Source code to the test files.
|
||||
#
|
||||
TESTSRC = \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/md5.c
|
||||
$(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/where.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
sqlite.h \
|
||||
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_unix.h \
|
||||
$(TOP)/src/os_win.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
parse.h
|
||||
|
||||
# Header files used by the VDBE submodule
|
||||
@@ -166,7 +219,10 @@ VDBEHDR = \
|
||||
# This is the default Makefile target. The objects listed here
|
||||
# are what get build when you type just "make" with no arguments.
|
||||
#
|
||||
all: sqlite.h libsqlite.la sqlite
|
||||
all: sqlite3.h libsqlite3.la sqlite3$(TEXE) $(HAVE_TCL:1=libtclsqlite3.la)
|
||||
|
||||
Makefile: $(TOP)/Makefile.in
|
||||
./config.status
|
||||
|
||||
# Generate the file "last_change" which contains the date of change
|
||||
# of the most recently modified source code file
|
||||
@@ -175,18 +231,19 @@ last_change: $(SRC)
|
||||
cat $(SRC) | grep '$$Id: ' | sort +4 | tail -1 \
|
||||
| awk '{print $$5,$$6}' >last_change
|
||||
|
||||
libsqlite.la: $(LIBOBJ)
|
||||
$(LIBTOOL) $(TCC) -o libsqlite.la $(LIBOBJ) ${RELEASE} -rpath $(exec_prefix)/lib \
|
||||
libsqlite3.la: $(LIBOBJ)
|
||||
$(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 \
|
||||
$(LIBOBJ) @TCL_STUB_LIB_SPEC@ $(LIBPTHREAD) \
|
||||
-rpath $(libdir)/sqlite \
|
||||
-version-info "8:6:8"
|
||||
|
||||
libtclsqlite.la: tclsqlite.lo libsqlite.la
|
||||
$(LIBTOOL) $(TCC) -o libtclsqlite.la tclsqlite.lo \
|
||||
libsqlite.la $(LIBTCL) -rpath $(exec_prefix)/lib \
|
||||
-version-info "8:6:8"
|
||||
|
||||
sqlite: $(TOP)/src/shell.c libsqlite.la sqlite.h
|
||||
$(LIBTOOL) $(TCC) $(READLINE_FLAGS) -o sqlite $(TOP)/src/shell.c \
|
||||
libsqlite.la $(LIBREADLINE) -rpath $(exec_prefix)/lib
|
||||
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
|
||||
@@ -194,190 +251,285 @@ sqlite: $(TOP)/src/shell.c libsqlite.la sqlite.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: $(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 .
|
||||
|
||||
btree.lo: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/btree.c
|
||||
|
||||
btree_rb.lo: $(TOP)/src/btree_rb.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/btree_rb.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
|
||||
|
||||
auth.lo: $(TOP)/src/auth.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/auth.c
|
||||
|
||||
btree.lo: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
|
||||
$(LTCOMPILE) -c $(TOP)/src/btree.c
|
||||
|
||||
build.lo: $(TOP)/src/build.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/build.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/build.c
|
||||
|
||||
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
|
||||
|
||||
delete.lo: $(TOP)/src/delete.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/delete.c
|
||||
|
||||
expr.lo: $(TOP)/src/expr.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/expr.c
|
||||
|
||||
func.lo: $(TOP)/src/func.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/func.c
|
||||
|
||||
hash.lo: $(TOP)/src/hash.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/hash.c
|
||||
|
||||
insert.lo: $(TOP)/src/insert.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/insert.c
|
||||
|
||||
legacy.lo: $(TOP)/src/legacy.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/legacy.c
|
||||
|
||||
main.lo: $(TOP)/src/main.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c ${INCOREFLAGS} $(TOP)/src/main.c
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/main.c
|
||||
|
||||
pager.lo: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/pager.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/pager.c
|
||||
|
||||
opcodes.lo: opcodes.c
|
||||
$(LIBTOOL) $(TCC) -c opcodes.c
|
||||
$(LTCOMPILE) -c opcodes.c
|
||||
|
||||
opcodes.c: $(TOP)/src/vdbe.c
|
||||
echo '/* Automatically generated file. Do not edit */' >opcodes.c
|
||||
echo 'char *sqliteOpcodeNames[] = { "???", ' >>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
|
||||
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.lo: $(TOP)/src/os.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/os.c
|
||||
os_unix.lo: $(TOP)/src/os_unix.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/os_unix.c
|
||||
|
||||
os_win.lo: $(TOP)/src/os_win.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/os_win.c
|
||||
|
||||
parse.lo: parse.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c parse.c
|
||||
$(LTCOMPILE) -c parse.c
|
||||
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon
|
||||
parse.c: $(TOP)/src/parse.y lemon$(BEXE)
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon parse.y
|
||||
|
||||
# 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
|
||||
|
||||
sqlite.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||
-e s/--ENCODING--/$(ENCODING)/ \
|
||||
$(TOP)/src/sqlite.h.in >sqlite.h
|
||||
|
||||
tokenize.lo: $(TOP)/src/tokenize.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/tokenize.c
|
||||
|
||||
util.lo: $(TOP)/src/util.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/util.c
|
||||
|
||||
vdbe.lo: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/vdbe.c
|
||||
|
||||
vdbeaux.lo: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/vdbeaux.c
|
||||
|
||||
where.lo: $(TOP)/src/where.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/where.c
|
||||
|
||||
copy.lo: $(TOP)/src/copy.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/copy.c
|
||||
|
||||
date.lo: $(TOP)/src/date.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/date.c
|
||||
|
||||
delete.lo: $(TOP)/src/delete.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/delete.c
|
||||
|
||||
expr.lo: $(TOP)/src/expr.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/expr.c
|
||||
|
||||
func.lo: $(TOP)/src/func.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/func.c
|
||||
|
||||
hash.lo: $(TOP)/src/hash.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/hash.c
|
||||
|
||||
insert.lo: $(TOP)/src/insert.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/insert.c
|
||||
|
||||
random.lo: $(TOP)/src/random.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/random.c
|
||||
|
||||
select.lo: $(TOP)/src/select.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/select.c
|
||||
|
||||
table.lo: $(TOP)/src/table.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/table.c
|
||||
|
||||
trigger.lo: $(TOP)/src/trigger.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/trigger.c
|
||||
|
||||
update.lo: $(TOP)/src/update.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/update.c
|
||||
|
||||
vacuum.lo: $(TOP)/src/vacuum.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/vacuum.c
|
||||
|
||||
tclsqlite.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
./lemon $(OPTS) parse.y
|
||||
|
||||
pragma.lo: $(TOP)/src/pragma.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) $(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)
|
||||
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/printf.c
|
||||
|
||||
attach.lo: $(TOP)/src/attach.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -c $(TOP)/src/attach.c
|
||||
random.lo: $(TOP)/src/random.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/random.c
|
||||
|
||||
auth.lo: $(TOP)/src/auth.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -c $(TOP)/src/auth.c
|
||||
select.lo: $(TOP)/src/select.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/select.c
|
||||
|
||||
tclsqlite: $(TOP)/src/tclsqlite.c libsqlite.la
|
||||
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite \
|
||||
$(TOP)/src/tclsqlite.c libsqlite.la $(LIBTCL)
|
||||
sqlite3.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/$(RELEASE)/ $(TOP)/src/sqlite.h.in | \
|
||||
sed -e s/--VERSION-NUMBER--/$(VERSION_NUMBER)/ >sqlite3.h
|
||||
|
||||
testfixture: $(TOP)/src/tclsqlite.c libtclsqlite.la libsqlite.la $(TESTSRC)
|
||||
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1\
|
||||
-o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libtclsqlite.la libsqlite.la $(LIBTCL)
|
||||
table.lo: $(TOP)/src/table.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/table.c
|
||||
|
||||
fulltest: testfixture sqlite
|
||||
tclsqlite.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
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
|
||||
|
||||
update.lo: $(TOP)/src/update.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/update.c
|
||||
|
||||
utf.lo: $(TOP)/src/utf.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/utf.c
|
||||
|
||||
util.lo: $(TOP)/src/util.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/util.c
|
||||
|
||||
vacuum.lo: $(TOP)/src/vacuum.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vacuum.c
|
||||
|
||||
vdbe.lo: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbe.c
|
||||
|
||||
vdbeapi.lo: $(TOP)/src/vdbeapi.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbeapi.c
|
||||
|
||||
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-shell.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LTCOMPILE) -DTCLSH=1 -o $@ -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
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$(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$(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)
|
||||
|
||||
|
||||
|
||||
fulltest: testfixture$(TEXE) sqlite3$(TEXE) crashtest$(TEXE)
|
||||
./testfixture $(TOP)/test/all.test
|
||||
|
||||
test: testfixture sqlite
|
||||
test: testfixture$(TEXE) sqlite3$(TEXE)
|
||||
./testfixture $(TOP)/test/quick.test
|
||||
|
||||
index.html: $(TOP)/www/index.tcl last_change
|
||||
tclsh $(TOP)/www/index.tcl `cat $(TOP)/VERSION` >index.html
|
||||
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)
|
||||
|
||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
|
||||
# Rules used to build documentation
|
||||
#
|
||||
arch.html: $(TOP)/www/arch.tcl
|
||||
tclsh $(TOP)/www/arch.tcl >arch.html
|
||||
|
||||
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
|
||||
|
||||
capi3.html: $(TOP)/www/capi3.tcl
|
||||
tclsh $(TOP)/www/capi3.tcl >capi3.html
|
||||
|
||||
capi3ref.html: $(TOP)/www/capi3ref.tcl
|
||||
tclsh $(TOP)/www/capi3ref.tcl >capi3ref.html
|
||||
|
||||
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
|
||||
|
||||
copyright-release.html: $(TOP)/www/copyright-release.html
|
||||
cp $(TOP)/www/copyright-release.html .
|
||||
|
||||
copyright-release.pdf: $(TOP)/www/copyright-release.pdf
|
||||
cp $(TOP)/www/copyright-release.pdf .
|
||||
|
||||
common.tcl: $(TOP)/www/common.tcl
|
||||
cp $(TOP)/www/common.tcl .
|
||||
|
||||
conflict.html: $(TOP)/www/conflict.tcl
|
||||
tclsh $(TOP)/www/conflict.tcl >conflict.html
|
||||
|
||||
datatypes.html: $(TOP)/www/datatypes.tcl
|
||||
tclsh $(TOP)/www/datatypes.tcl >datatypes.html
|
||||
|
||||
datatype3.html: $(TOP)/www/datatype3.tcl
|
||||
tclsh $(TOP)/www/datatype3.tcl >datatype3.html
|
||||
|
||||
docs.html: $(TOP)/www/docs.tcl
|
||||
tclsh $(TOP)/www/docs.tcl >docs.html
|
||||
|
||||
download.html: $(TOP)/www/download.tcl
|
||||
mkdir -p doc
|
||||
tclsh $(TOP)/www/download.tcl >download.html
|
||||
|
||||
faq.html: $(TOP)/www/faq.tcl
|
||||
tclsh $(TOP)/www/faq.tcl >faq.html
|
||||
|
||||
fileformat.html: $(TOP)/www/fileformat.tcl
|
||||
tclsh $(TOP)/www/fileformat.tcl >fileformat.html
|
||||
|
||||
formatchng.html: $(TOP)/www/formatchng.tcl
|
||||
tclsh $(TOP)/www/formatchng.tcl >formatchng.html
|
||||
|
||||
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
|
||||
|
||||
vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
tclsh $(TOP)/www/vdbe.tcl >vdbe.html
|
||||
pragma.html: $(TOP)/www/pragma.tcl
|
||||
tclsh $(TOP)/www/pragma.tcl >pragma.html
|
||||
|
||||
arch.html: $(TOP)/www/arch.tcl
|
||||
tclsh $(TOP)/www/arch.tcl >arch.html
|
||||
lockingv3.html: $(TOP)/www/lockingv3.tcl
|
||||
tclsh $(TOP)/www/lockingv3.tcl >lockingv3.html
|
||||
|
||||
arch.png: $(TOP)/www/arch.png
|
||||
cp $(TOP)/www/arch.png .
|
||||
oldnews.html: $(TOP)/www/oldnews.tcl
|
||||
tclsh $(TOP)/www/oldnews.tcl >oldnews.html
|
||||
|
||||
omitted.html: $(TOP)/www/omitted.tcl
|
||||
tclsh $(TOP)/www/omitted.tcl >omitted.html
|
||||
|
||||
opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
|
||||
tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
|
||||
@@ -385,87 +537,124 @@ opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
|
||||
mingw.html: $(TOP)/www/mingw.tcl
|
||||
tclsh $(TOP)/www/mingw.tcl >mingw.html
|
||||
|
||||
tclsqlite.html: $(TOP)/www/tclsqlite.tcl
|
||||
tclsh $(TOP)/www/tclsqlite.tcl >tclsqlite.html
|
||||
|
||||
speed.html: $(TOP)/www/speed.tcl
|
||||
tclsh $(TOP)/www/speed.tcl >speed.html
|
||||
|
||||
faq.html: $(TOP)/www/faq.tcl
|
||||
tclsh $(TOP)/www/faq.tcl >faq.html
|
||||
|
||||
formatchng.html: $(TOP)/www/formatchng.tcl
|
||||
tclsh $(TOP)/www/formatchng.tcl >formatchng.html
|
||||
|
||||
conflict.html: $(TOP)/www/conflict.tcl
|
||||
tclsh $(TOP)/www/conflict.tcl >conflict.html
|
||||
|
||||
download.html: $(TOP)/www/download.tcl
|
||||
tclsh $(TOP)/www/download.tcl >download.html
|
||||
|
||||
omitted.html: $(TOP)/www/omitted.tcl
|
||||
tclsh $(TOP)/www/omitted.tcl >omitted.html
|
||||
|
||||
datatypes.html: $(TOP)/www/datatypes.tcl
|
||||
tclsh $(TOP)/www/datatypes.tcl >datatypes.html
|
||||
nulls.html: $(TOP)/www/nulls.tcl
|
||||
tclsh $(TOP)/www/nulls.tcl >nulls.html
|
||||
|
||||
quickstart.html: $(TOP)/www/quickstart.tcl
|
||||
tclsh $(TOP)/www/quickstart.tcl >quickstart.html
|
||||
|
||||
fileformat.html: $(TOP)/www/fileformat.tcl
|
||||
tclsh $(TOP)/www/fileformat.tcl >fileformat.html
|
||||
speed.html: $(TOP)/www/speed.tcl
|
||||
tclsh $(TOP)/www/speed.tcl >speed.html
|
||||
|
||||
nulls.html: $(TOP)/www/nulls.tcl
|
||||
tclsh $(TOP)/www/nulls.tcl >nulls.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
|
||||
|
||||
support.html: $(TOP)/www/support.tcl
|
||||
tclsh $(TOP)/www/support.tcl >support.html
|
||||
|
||||
tclsqlite.html: $(TOP)/www/tclsqlite.tcl
|
||||
tclsh $(TOP)/www/tclsqlite.tcl >tclsqlite.html
|
||||
|
||||
vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
tclsh $(TOP)/www/vdbe.tcl >vdbe.html
|
||||
|
||||
version3.html: $(TOP)/www/version3.tcl
|
||||
tclsh $(TOP)/www/version3.tcl >version3.html
|
||||
|
||||
|
||||
# Files to be published on the website.
|
||||
#
|
||||
DOC = \
|
||||
index.html \
|
||||
sqlite.html \
|
||||
changes.html \
|
||||
lang.html \
|
||||
opcode.html \
|
||||
arch.html \
|
||||
arch.png \
|
||||
vdbe.html \
|
||||
arch2.gif \
|
||||
autoinc.html \
|
||||
c_interface.html \
|
||||
mingw.html \
|
||||
tclsqlite.html \
|
||||
download.html \
|
||||
speed.html \
|
||||
faq.html \
|
||||
formatchng.html \
|
||||
capi3.html \
|
||||
capi3ref.html \
|
||||
changes.html \
|
||||
compile.html \
|
||||
copyright.html \
|
||||
copyright-release.html \
|
||||
copyright-release.pdf \
|
||||
conflict.html \
|
||||
omitted.html \
|
||||
datatypes.html \
|
||||
quickstart.html \
|
||||
datatype3.html \
|
||||
docs.html \
|
||||
download.html \
|
||||
faq.html \
|
||||
fileformat.html \
|
||||
nulls.html
|
||||
formatchng.html \
|
||||
index.html \
|
||||
lang.html \
|
||||
lockingv3.html \
|
||||
mingw.html \
|
||||
nulls.html \
|
||||
oldnews.html \
|
||||
omitted.html \
|
||||
opcode.html \
|
||||
pragma.html \
|
||||
quickstart.html \
|
||||
speed.html \
|
||||
sqlite.gif \
|
||||
sqlite.html \
|
||||
support.html \
|
||||
tclsqlite.html \
|
||||
vdbe.html \
|
||||
version3.html
|
||||
|
||||
doc: $(DOC)
|
||||
doc: common.tcl $(DOC)
|
||||
mkdir -p doc
|
||||
mv $(DOC) doc
|
||||
|
||||
install: sqlite libsqlite.la sqlite.h
|
||||
$(INSTALL) -d $(exec_prefix)/lib
|
||||
$(LIBTOOL) $(INSTALL) libsqlite.la $(exec_prefix)/lib
|
||||
$(INSTALL) -d $(exec_prefix)/bin
|
||||
$(LIBTOOL) $(INSTALL) sqlite $(exec_prefix)/bin
|
||||
$(INSTALL) -d $(prefix)/include
|
||||
$(INSTALL) -m 0644 sqlite.h $(prefix)/include
|
||||
$(INSTALL) -d $(exec_prefix)/lib/pkgconfig;
|
||||
$(INSTALL) -m 0644 sqlite.pc $(exec_prefix)/lib/pkgconfig;
|
||||
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)$(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 sqlite libsqlite.la sqlite.h opcodes.*
|
||||
rm -f *.lo *.la *.o sqlite3$(TEXE) libsqlite3.la
|
||||
rm -f sqlite3.h opcodes.*
|
||||
rm -rf .libs .deps
|
||||
rm -f lemon 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 test.db
|
||||
rm -f testfixture$(TEXE) test.db
|
||||
rm -rf doc
|
||||
rm -f common.tcl
|
||||
rm -f sqlite3.dll sqlite3.lib
|
||||
|
||||
#
|
||||
# Windows section; all this funky .dll stuff ;-)
|
||||
#
|
||||
dll: sqlite3.dll
|
||||
|
||||
REAL_LIBOBJ = $(LIBOBJ:%.lo=.libs/%.o)
|
||||
|
||||
sqlite3.dll: $(LIBOBJ) $(TOP)/sqlite3.def
|
||||
dllwrap --dllname sqlite3.dll --def $(TOP)/sqlite3.def $(REAL_LIBOBJ)
|
||||
strip sqlite3.dll
|
||||
|
||||
#target for dll import libraries
|
||||
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
|
||||
-impdef -a sqlite3.def sqlite3.dll
|
||||
-implib sqlite3.lib sqlite3.def
|
||||
-lib /machine:i386 /def:$(TOP)/sqlite3.def
|
||||
|
||||
distclean: clean
|
||||
rm -f config.log config.status libtool Makefile config.h
|
||||
|
||||
+8
-8
@@ -41,16 +41,16 @@ THREADSAFE = -DTHREADSAFE=0
|
||||
#THREADLIB = -lpthread
|
||||
THREADLIB =
|
||||
|
||||
#### Leave MEMORY_DEBUG undefined for maximum speed. Use MEMORY_DEBUG=1
|
||||
# to check for memory leaks. Use MEMORY_DEBUG=2 to print a log of all
|
||||
#### Leave SQLITE_DEBUG undefined for maximum speed. Use SQLITE_DEBUG=1
|
||||
# to check for memory leaks. Use SQLITE_DEBUG=2 to print a log of all
|
||||
# malloc()s and free()s in order to track down memory leaks.
|
||||
#
|
||||
# SQLite uses some expensive assert() statements in the inner loop.
|
||||
# You can make the library go almost twice as fast if you compile
|
||||
# with -DNDEBUG=1
|
||||
#
|
||||
#OPTS = -DMEMORY_DEBUG=2
|
||||
#OPTS = -DMEMORY_DEBUG=1
|
||||
#OPTS = -DSQLITE_DEBUG=2
|
||||
#OPTS = -DSQLITE_DEBUG=1
|
||||
#OPTS =
|
||||
OPTS = -DNDEBUG=1
|
||||
|
||||
@@ -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
|
||||
|
||||
Vendored
+4766
-2500
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
Vendored
+88
-65
@@ -3,7 +3,7 @@
|
||||
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
|
||||
# 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
|
||||
timestamp='2003-01-10'
|
||||
timestamp='2004-01-05'
|
||||
|
||||
# This file is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
@@ -106,6 +106,7 @@ trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
|
||||
: ${TMPDIR=/tmp} ;
|
||||
{ tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
|
||||
{ test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
|
||||
{ tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
|
||||
{ echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
|
||||
dummy=$tmp/dummy ;
|
||||
tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
|
||||
@@ -220,6 +221,9 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
mvmeppc:OpenBSD:*:*)
|
||||
echo powerpc-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
pegasos:OpenBSD:*:*)
|
||||
echo powerpc-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
pmax:OpenBSD:*:*)
|
||||
echo mipsel-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
@@ -235,74 +239,56 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
*:OpenBSD:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:MicroBSD:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-microbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
alpha:OSF1:*:*)
|
||||
if test $UNAME_RELEASE = "V4.0"; then
|
||||
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
|
||||
fi
|
||||
# According to Compaq, /usr/sbin/psrinfo has been available on
|
||||
# OSF/1 and Tru64 systems produced since 1995. I hope that
|
||||
# covers most systems running today. This code pipes the CPU
|
||||
# types through head -n 1, so we only detect the type of CPU 0.
|
||||
ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
|
||||
case "$ALPHA_CPU_TYPE" in
|
||||
"EV4 (21064)")
|
||||
UNAME_MACHINE="alpha" ;;
|
||||
"EV4.5 (21064)")
|
||||
UNAME_MACHINE="alpha" ;;
|
||||
"LCA4 (21066/21068)")
|
||||
UNAME_MACHINE="alpha" ;;
|
||||
"EV5 (21164)")
|
||||
UNAME_MACHINE="alphaev5" ;;
|
||||
"EV5.6 (21164A)")
|
||||
UNAME_MACHINE="alphaev56" ;;
|
||||
"EV5.6 (21164PC)")
|
||||
UNAME_MACHINE="alphapca56" ;;
|
||||
"EV5.7 (21164PC)")
|
||||
UNAME_MACHINE="alphapca57" ;;
|
||||
"EV6 (21264)")
|
||||
UNAME_MACHINE="alphaev6" ;;
|
||||
"EV6.7 (21264A)")
|
||||
UNAME_MACHINE="alphaev67" ;;
|
||||
"EV6.8CB (21264C)")
|
||||
UNAME_MACHINE="alphaev68" ;;
|
||||
"EV6.8AL (21264B)")
|
||||
UNAME_MACHINE="alphaev68" ;;
|
||||
"EV6.8CX (21264D)")
|
||||
UNAME_MACHINE="alphaev68" ;;
|
||||
"EV6.9A (21264/EV69A)")
|
||||
UNAME_MACHINE="alphaev69" ;;
|
||||
"EV7 (21364)")
|
||||
UNAME_MACHINE="alphaev7" ;;
|
||||
"EV7.9 (21364A)")
|
||||
UNAME_MACHINE="alphaev79" ;;
|
||||
esac
|
||||
# A Vn.n version is a released version.
|
||||
# A Tn.n version is a released field test version.
|
||||
# A Xn.n version is an unreleased experimental baselevel.
|
||||
# 1.2 uses "1.2" for uname -r.
|
||||
eval $set_cc_for_build
|
||||
cat <<EOF >$dummy.s
|
||||
.data
|
||||
\$Lformat:
|
||||
.byte 37,100,45,37,120,10,0 # "%d-%x\n"
|
||||
|
||||
.text
|
||||
.globl main
|
||||
.align 4
|
||||
.ent main
|
||||
main:
|
||||
.frame \$30,16,\$26,0
|
||||
ldgp \$29,0(\$27)
|
||||
.prologue 1
|
||||
.long 0x47e03d80 # implver \$0
|
||||
lda \$2,-1
|
||||
.long 0x47e20c21 # amask \$2,\$1
|
||||
lda \$16,\$Lformat
|
||||
mov \$0,\$17
|
||||
not \$1,\$18
|
||||
jsr \$26,printf
|
||||
ldgp \$29,0(\$26)
|
||||
mov 0,\$16
|
||||
jsr \$26,exit
|
||||
.end main
|
||||
EOF
|
||||
$CC_FOR_BUILD -o $dummy $dummy.s 2>/dev/null
|
||||
if test "$?" = 0 ; then
|
||||
case `$dummy` in
|
||||
0-0)
|
||||
UNAME_MACHINE="alpha"
|
||||
;;
|
||||
1-0)
|
||||
UNAME_MACHINE="alphaev5"
|
||||
;;
|
||||
1-1)
|
||||
UNAME_MACHINE="alphaev56"
|
||||
;;
|
||||
1-101)
|
||||
UNAME_MACHINE="alphapca56"
|
||||
;;
|
||||
2-303)
|
||||
UNAME_MACHINE="alphaev6"
|
||||
;;
|
||||
2-307)
|
||||
UNAME_MACHINE="alphaev67"
|
||||
;;
|
||||
2-1307)
|
||||
UNAME_MACHINE="alphaev68"
|
||||
;;
|
||||
3-1307)
|
||||
UNAME_MACHINE="alphaev7"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
|
||||
exit 0 ;;
|
||||
Alpha*:OpenVMS:*:*)
|
||||
echo alpha-hp-vms
|
||||
exit 0 ;;
|
||||
Alpha\ *:Windows_NT*:*)
|
||||
# How do we know it's Interix rather than the generic POSIX subsystem?
|
||||
# Should we change UNAME_MACHINE based on the output of uname instead
|
||||
@@ -324,6 +310,9 @@ EOF
|
||||
*:OS/390:*:*)
|
||||
echo i370-ibm-openedition
|
||||
exit 0 ;;
|
||||
*:OS400:*:*)
|
||||
echo powerpc-ibm-os400
|
||||
exit 0 ;;
|
||||
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
|
||||
echo arm-acorn-riscix${UNAME_RELEASE}
|
||||
exit 0;;
|
||||
@@ -341,6 +330,9 @@ EOF
|
||||
NILE*:*:*:dcosx)
|
||||
echo pyramid-pyramid-svr4
|
||||
exit 0 ;;
|
||||
DRS?6000:unix:4.0:6*)
|
||||
echo sparc-icl-nx6
|
||||
exit 0 ;;
|
||||
DRS?6000:UNIX_SV:4.2*:7*)
|
||||
case `/usr/bin/uname -p` in
|
||||
sparc) echo sparc-icl-nx7 && exit 0 ;;
|
||||
@@ -748,7 +740,7 @@ EOF
|
||||
echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
|
||||
exit 0 ;;
|
||||
*:UNICOS/mp:*:*)
|
||||
echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
|
||||
echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
|
||||
exit 0 ;;
|
||||
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
|
||||
FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
|
||||
@@ -756,6 +748,11 @@ EOF
|
||||
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
|
||||
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
|
||||
exit 0 ;;
|
||||
5000:UNIX_System_V:4.*:*)
|
||||
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
|
||||
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
|
||||
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
|
||||
exit 0 ;;
|
||||
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
@@ -777,7 +774,10 @@ EOF
|
||||
#endif
|
||||
EOF
|
||||
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
|
||||
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC}
|
||||
# GNU/KFreeBSD systems have a "k" prefix to indicate we are using
|
||||
# FreeBSD's kernel, but not the complete OS.
|
||||
case ${LIBC} in gnu) kernel_only='k' ;; esac
|
||||
echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC}
|
||||
exit 0 ;;
|
||||
i*:CYGWIN*:*)
|
||||
echo ${UNAME_MACHINE}-pc-cygwin
|
||||
@@ -788,8 +788,8 @@ EOF
|
||||
i*:PW*:*)
|
||||
echo ${UNAME_MACHINE}-pc-pw32
|
||||
exit 0 ;;
|
||||
x86:Interix*:3*)
|
||||
echo i586-pc-interix3
|
||||
x86:Interix*:[34]*)
|
||||
echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//'
|
||||
exit 0 ;;
|
||||
[345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
|
||||
echo i${UNAME_MACHINE}-pc-mks
|
||||
@@ -810,14 +810,22 @@ EOF
|
||||
echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
exit 0 ;;
|
||||
*:GNU:*:*)
|
||||
# the GNU system
|
||||
echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
|
||||
exit 0 ;;
|
||||
*:GNU/*:*:*)
|
||||
# other systems with GNU libc and userland
|
||||
echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
|
||||
exit 0 ;;
|
||||
i*86:Minix:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-minix
|
||||
exit 0 ;;
|
||||
arm*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
exit 0 ;;
|
||||
cris:Linux:*:*)
|
||||
echo cris-axis-linux-gnu
|
||||
exit 0 ;;
|
||||
ia64:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
exit 0 ;;
|
||||
@@ -896,6 +904,9 @@ EOF
|
||||
s390:Linux:*:* | s390x:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-ibm-linux
|
||||
exit 0 ;;
|
||||
sh64*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
exit 0 ;;
|
||||
sh*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
exit 0 ;;
|
||||
@@ -953,6 +964,9 @@ EOF
|
||||
LIBC=gnuaout
|
||||
#endif
|
||||
#endif
|
||||
#ifdef __dietlibc__
|
||||
LIBC=dietlibc
|
||||
#endif
|
||||
EOF
|
||||
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
|
||||
test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
|
||||
@@ -983,6 +997,9 @@ EOF
|
||||
i*86:atheos:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-atheos
|
||||
exit 0 ;;
|
||||
i*86:syllable:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-syllable
|
||||
exit 0 ;;
|
||||
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
|
||||
echo i386-unknown-lynxos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
@@ -1054,7 +1071,7 @@ EOF
|
||||
exit 0 ;;
|
||||
M68*:*:R3V[567]*:*)
|
||||
test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
|
||||
3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0)
|
||||
3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0)
|
||||
OS_REL=''
|
||||
test -r /etc/.relid \
|
||||
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
|
||||
@@ -1169,7 +1186,7 @@ EOF
|
||||
*:QNX:*:4*)
|
||||
echo i386-pc-qnx
|
||||
exit 0 ;;
|
||||
NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*)
|
||||
NSR-?:NONSTOP_KERNEL:*:*)
|
||||
echo nsr-tandem-nsk${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:NonStop-UX:*:*)
|
||||
@@ -1210,6 +1227,12 @@ EOF
|
||||
*:ITS:*:*)
|
||||
echo pdp10-unknown-its
|
||||
exit 0 ;;
|
||||
SEI:*:*:SEIUX)
|
||||
echo mips-sei-seiux${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:DRAGONFLY:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-dragonfly${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
esac
|
||||
|
||||
#echo '(No uname command or uname output not recognized.)' 1>&2
|
||||
|
||||
Vendored
+84
-20
@@ -3,7 +3,7 @@
|
||||
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
|
||||
# 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
|
||||
timestamp='2003-01-03'
|
||||
timestamp='2004-01-05'
|
||||
|
||||
# This file is (in principle) common to ALL GNU software.
|
||||
# The presence of a machine in this file suggests that SOME GNU software
|
||||
@@ -118,7 +118,8 @@ esac
|
||||
# Here we must recognize all the valid KERNEL-OS combinations.
|
||||
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
|
||||
case $maybe_os in
|
||||
nto-qnx* | linux-gnu* | freebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
|
||||
nto-qnx* | linux-gnu* | linux-dietlibc | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | \
|
||||
kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
|
||||
os=-$maybe_os
|
||||
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
|
||||
;;
|
||||
@@ -228,13 +229,14 @@ case $basic_machine in
|
||||
| a29k \
|
||||
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
|
||||
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
|
||||
| am33_2.0 \
|
||||
| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
|
||||
| clipper \
|
||||
| c4x | clipper \
|
||||
| d10v | d30v | dlx | dsp16xx \
|
||||
| fr30 | frv \
|
||||
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
|
||||
| i370 | i860 | i960 | ia64 \
|
||||
| ip2k \
|
||||
| ip2k | iq2000 \
|
||||
| m32r | m68000 | m68k | m88k | mcore \
|
||||
| mips | mipsbe | mipseb | mipsel | mipsle \
|
||||
| mips16 \
|
||||
@@ -247,6 +249,7 @@ case $basic_machine in
|
||||
| mipsisa32 | mipsisa32el \
|
||||
| mipsisa32r2 | mipsisa32r2el \
|
||||
| mipsisa64 | mipsisa64el \
|
||||
| mipsisa64r2 | mipsisa64r2el \
|
||||
| mipsisa64sb1 | mipsisa64sb1el \
|
||||
| mipsisa64sr71k | mipsisa64sr71kel \
|
||||
| mipstx39 | mipstx39el \
|
||||
@@ -257,11 +260,11 @@ case $basic_machine in
|
||||
| pdp10 | pdp11 | pj | pjl \
|
||||
| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
|
||||
| pyramid \
|
||||
| sh | sh[1234] | sh3e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
|
||||
| sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
|
||||
| sh64 | sh64le \
|
||||
| sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \
|
||||
| strongarm \
|
||||
| tahoe | thumb | tic80 | tron \
|
||||
| tahoe | thumb | tic4x | tic80 | tron \
|
||||
| v850 | v850e \
|
||||
| we32k \
|
||||
| x86 | xscale | xstormy16 | xtensa \
|
||||
@@ -296,7 +299,7 @@ case $basic_machine in
|
||||
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \
|
||||
| avr-* \
|
||||
| bs2000-* \
|
||||
| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* \
|
||||
| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
|
||||
| clipper-* | cydra-* \
|
||||
| d10v-* | d30v-* | dlx-* \
|
||||
| elxsi-* \
|
||||
@@ -304,7 +307,7 @@ case $basic_machine in
|
||||
| h8300-* | h8500-* \
|
||||
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
|
||||
| i*86-* | i860-* | i960-* | ia64-* \
|
||||
| ip2k-* \
|
||||
| ip2k-* | iq2000-* \
|
||||
| m32r-* \
|
||||
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
|
||||
| m88110-* | m88k-* | mcore-* \
|
||||
@@ -319,6 +322,7 @@ case $basic_machine in
|
||||
| mipsisa32-* | mipsisa32el-* \
|
||||
| mipsisa32r2-* | mipsisa32r2el-* \
|
||||
| mipsisa64-* | mipsisa64el-* \
|
||||
| mipsisa64r2-* | mipsisa64r2el-* \
|
||||
| mipsisa64sb1-* | mipsisa64sb1el-* \
|
||||
| mipsisa64sr71k-* | mipsisa64sr71kel-* \
|
||||
| mipstx39-* | mipstx39el-* \
|
||||
@@ -329,11 +333,13 @@ case $basic_machine in
|
||||
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
|
||||
| pyramid-* \
|
||||
| romp-* | rs6000-* \
|
||||
| sh-* | sh[1234]-* | sh3e-* | sh[34]eb-* | shbe-* \
|
||||
| sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \
|
||||
| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
|
||||
| sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \
|
||||
| sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
|
||||
| tahoe-* | thumb-* | tic30-* | tic4x-* | tic54x-* | tic80-* | tron-* \
|
||||
| tahoe-* | thumb-* \
|
||||
| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
|
||||
| tron-* \
|
||||
| v850-* | v850e-* | vax-* \
|
||||
| we32k-* \
|
||||
| x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \
|
||||
@@ -371,6 +377,12 @@ case $basic_machine in
|
||||
basic_machine=a29k-none
|
||||
os=-bsd
|
||||
;;
|
||||
amd64)
|
||||
basic_machine=x86_64-pc
|
||||
;;
|
||||
amd64-*)
|
||||
basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
amdahl)
|
||||
basic_machine=580-amdahl
|
||||
os=-sysv
|
||||
@@ -735,6 +747,10 @@ case $basic_machine in
|
||||
basic_machine=or32-unknown
|
||||
os=-coff
|
||||
;;
|
||||
os400)
|
||||
basic_machine=powerpc-ibm
|
||||
os=-os400
|
||||
;;
|
||||
OSE68000 | ose68000)
|
||||
basic_machine=m68000-ericsson
|
||||
os=-ose
|
||||
@@ -766,18 +782,24 @@ case $basic_machine in
|
||||
pentiumpro | p6 | 6x86 | athlon | athlon_*)
|
||||
basic_machine=i686-pc
|
||||
;;
|
||||
pentiumii | pentium2)
|
||||
pentiumii | pentium2 | pentiumiii | pentium3)
|
||||
basic_machine=i686-pc
|
||||
;;
|
||||
pentium4)
|
||||
basic_machine=i786-pc
|
||||
;;
|
||||
pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
|
||||
basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
pentiumpro-* | p6-* | 6x86-* | athlon-*)
|
||||
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
pentiumii-* | pentium2-*)
|
||||
pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
|
||||
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
pentium4-*)
|
||||
basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
pn)
|
||||
basic_machine=pn-gould
|
||||
;;
|
||||
@@ -836,6 +858,10 @@ case $basic_machine in
|
||||
sb1el)
|
||||
basic_machine=mipsisa64sb1el-unknown
|
||||
;;
|
||||
sei)
|
||||
basic_machine=mips-sei
|
||||
os=-seiux
|
||||
;;
|
||||
sequent)
|
||||
basic_machine=i386-sequent
|
||||
;;
|
||||
@@ -843,6 +869,9 @@ case $basic_machine in
|
||||
basic_machine=sh-hitachi
|
||||
os=-hms
|
||||
;;
|
||||
sh64)
|
||||
basic_machine=sh64-unknown
|
||||
;;
|
||||
sparclite-wrs | simso-wrs)
|
||||
basic_machine=sparclite-wrs
|
||||
os=-vxworks
|
||||
@@ -917,14 +946,18 @@ case $basic_machine in
|
||||
basic_machine=t90-cray
|
||||
os=-unicos
|
||||
;;
|
||||
tic4x | c4x*)
|
||||
basic_machine=tic4x-unknown
|
||||
os=-coff
|
||||
;;
|
||||
tic54x | c54x*)
|
||||
basic_machine=tic54x-unknown
|
||||
os=-coff
|
||||
;;
|
||||
tic55x | c55x*)
|
||||
basic_machine=tic55x-unknown
|
||||
os=-coff
|
||||
;;
|
||||
tic6x | c6x*)
|
||||
basic_machine=tic6x-unknown
|
||||
os=-coff
|
||||
;;
|
||||
tx39)
|
||||
basic_machine=mipstx39-unknown
|
||||
;;
|
||||
@@ -938,6 +971,10 @@ case $basic_machine in
|
||||
tower | tower-32)
|
||||
basic_machine=m68k-ncr
|
||||
;;
|
||||
tpf)
|
||||
basic_machine=s390x-ibm
|
||||
os=-tpf
|
||||
;;
|
||||
udi29k)
|
||||
basic_machine=a29k-amd
|
||||
os=-udi
|
||||
@@ -1027,7 +1064,7 @@ case $basic_machine in
|
||||
we32k)
|
||||
basic_machine=we32k-att
|
||||
;;
|
||||
sh3 | sh4 | sh3eb | sh4eb | sh[1234]le | sh3ele)
|
||||
sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele)
|
||||
basic_machine=sh-unknown
|
||||
;;
|
||||
sh64)
|
||||
@@ -1106,19 +1143,19 @@ case $os in
|
||||
| -aos* \
|
||||
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
|
||||
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
|
||||
| -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \
|
||||
| -hiux* | -386bsd* | -knetbsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \
|
||||
| -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
|
||||
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
|
||||
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
|
||||
| -chorusos* | -chorusrdb* \
|
||||
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
|
||||
| -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \
|
||||
| -mingw32* | -linux-gnu* | -linux-uclibc* | -uxpv* | -beos* | -mpeix* | -udk* \
|
||||
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
|
||||
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
|
||||
| -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
|
||||
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
|
||||
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
|
||||
| -powermax* | -dnix* | -microbsd*)
|
||||
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly*)
|
||||
# Remember, each alternative MUST END IN *, to match a version number.
|
||||
;;
|
||||
-qnx*)
|
||||
@@ -1142,6 +1179,9 @@ case $os in
|
||||
-mac*)
|
||||
os=`echo $os | sed -e 's|mac|macos|'`
|
||||
;;
|
||||
-linux-dietlibc)
|
||||
os=-linux-dietlibc
|
||||
;;
|
||||
-linux*)
|
||||
os=`echo $os | sed -e 's|linux|linux-gnu|'`
|
||||
;;
|
||||
@@ -1154,6 +1194,9 @@ case $os in
|
||||
-opened*)
|
||||
os=-openedition
|
||||
;;
|
||||
-os400*)
|
||||
os=-os400
|
||||
;;
|
||||
-wince*)
|
||||
os=-wince
|
||||
;;
|
||||
@@ -1175,6 +1218,9 @@ case $os in
|
||||
-atheos*)
|
||||
os=-atheos
|
||||
;;
|
||||
-syllable*)
|
||||
os=-syllable
|
||||
;;
|
||||
-386bsd)
|
||||
os=-bsd
|
||||
;;
|
||||
@@ -1197,6 +1243,9 @@ case $os in
|
||||
-sinix*)
|
||||
os=-sysv4
|
||||
;;
|
||||
-tpf*)
|
||||
os=-tpf
|
||||
;;
|
||||
-triton*)
|
||||
os=-sysv3
|
||||
;;
|
||||
@@ -1227,6 +1276,12 @@ case $os in
|
||||
-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
|
||||
os=-mint
|
||||
;;
|
||||
-aros*)
|
||||
os=-aros
|
||||
;;
|
||||
-kaos*)
|
||||
os=-kaos
|
||||
;;
|
||||
-none)
|
||||
;;
|
||||
*)
|
||||
@@ -1258,6 +1313,9 @@ case $basic_machine in
|
||||
arm*-semi)
|
||||
os=-aout
|
||||
;;
|
||||
c4x-* | tic4x-*)
|
||||
os=-coff
|
||||
;;
|
||||
# This must come before the *-dec entry.
|
||||
pdp10-*)
|
||||
os=-tops20
|
||||
@@ -1436,9 +1494,15 @@ case $basic_machine in
|
||||
-mvs* | -opened*)
|
||||
vendor=ibm
|
||||
;;
|
||||
-os400*)
|
||||
vendor=ibm
|
||||
;;
|
||||
-ptx*)
|
||||
vendor=sequent
|
||||
;;
|
||||
-tpf*)
|
||||
vendor=ibm
|
||||
;;
|
||||
-vxsim* | -vxworks* | -windiss*)
|
||||
vendor=wrs
|
||||
;;
|
||||
|
||||
+188
-120
@@ -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.6 $
|
||||
# $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,
|
||||
@@ -291,34 +275,29 @@ else
|
||||
fi
|
||||
|
||||
##########
|
||||
# Are we using UTF-8 or iso8859 encodings?
|
||||
# Do we want to support multithreaded use of sqlite
|
||||
#
|
||||
AC_ARG_ENABLE(utf8,
|
||||
[ --enable-utf8 Use UTF-8 encodings],,enable_utf8=no)
|
||||
AC_MSG_CHECKING([character encoding])
|
||||
if test "$enable_utf8" = "no"; then
|
||||
ENCODING=ISO8859
|
||||
AC_MSG_RESULT([iso8859])
|
||||
else
|
||||
ENCODING=UTF8
|
||||
AC_MSG_RESULT([UTF-8])
|
||||
fi
|
||||
AC_SUBST(ENCODING)
|
||||
|
||||
##########
|
||||
# Do we want to support in-ram databases for ATTACH DATABASE and sqlite_open
|
||||
#
|
||||
AC_ARG_ENABLE(incore-db,
|
||||
[ --enable-incore-db Support incore database],,enable_incore_db=yes)
|
||||
AC_MSG_CHECKING([whether to support incore databases for attach and open])
|
||||
if test "$enable_incore_db" = "no"; then
|
||||
INMEMORYDB=0
|
||||
AC_ARG_ENABLE(threadsafe,
|
||||
[ --enable-threadsafe Support threadsafe operation],,enable_threadsafe=no)
|
||||
AC_MSG_CHECKING([whether to support threadsafe operation])
|
||||
if test "$enable_threadsafe" = "no"; then
|
||||
THREADSAFE=0
|
||||
AC_MSG_RESULT([no])
|
||||
else
|
||||
INMEMORYDB=1
|
||||
THREADSAFE=1
|
||||
AC_MSG_RESULT([yes])
|
||||
fi
|
||||
AC_SUBST(ALLOWATTACHMEM)
|
||||
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
|
||||
@@ -338,32 +317,28 @@ AC_SUBST(ALLOWRELEASE)
|
||||
##########
|
||||
# Do we want temporary databases in memory
|
||||
#
|
||||
AC_ARG_ENABLE(tempdb-in-ram,
|
||||
[ --enable-tempdb-in-ram Use an in-ram database for temporary tables],,enable_tempdb_in_ram=no)
|
||||
AC_ARG_ENABLE(tempstore,
|
||||
[ --enable-tempstore Use an in-ram database for temporary tables (never,no,yes,always)],,enable_tempstore=yes)
|
||||
AC_MSG_CHECKING([whether to use an in-ram database for temporary tables])
|
||||
case "$enable_tempdb_in_ram" in
|
||||
case "$enable_tempstore" in
|
||||
never )
|
||||
TEMP_STORE=0
|
||||
AC_MSG_RESULT([never])
|
||||
;;
|
||||
no )
|
||||
INMEMORYDB=1
|
||||
TEMP_STORE=1
|
||||
AC_MSG_RESULT([no])
|
||||
;;
|
||||
always )
|
||||
INMEMORYDB=1
|
||||
TEMP_STORE=3
|
||||
TEMP_STORE=3
|
||||
AC_MSG_RESULT([always])
|
||||
;;
|
||||
* )
|
||||
INMEMORYDB=1
|
||||
TEMP_STORE=2
|
||||
AC_MSG_RESULT([yes])
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_SUBST(INMEMORYDB)
|
||||
AC_SUBST(TEMP_STORE)
|
||||
|
||||
###########
|
||||
@@ -384,7 +359,7 @@ fi
|
||||
if test "$CYGWIN" = "yes"; then
|
||||
BUILD_EXEEXT=.exe
|
||||
else
|
||||
BUILD_EXEEXT=""
|
||||
BUILD_EXEEXT=$EXEEXT
|
||||
fi
|
||||
if test "$cross" = "0"; then
|
||||
TARGET_EXEEXT=$BUILD_EXEEXT
|
||||
@@ -395,12 +370,13 @@ if test "$TARGET_EXEEXT" = ".exe"; then
|
||||
OS_UNIX=0
|
||||
OS_WIN=1
|
||||
tclsubdir=win
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DOS_WIN=1"
|
||||
else
|
||||
OS_UNIX=1
|
||||
OS_WIN=0
|
||||
tclsubdir=unix
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DOS_UNIX=1"
|
||||
fi
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DOS_UNIX=$OS_UNIX -DOS_WIN=$OS_WIN"
|
||||
|
||||
AC_SUBST(BUILD_EXEEXT)
|
||||
AC_SUBST(OS_UNIX)
|
||||
@@ -418,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 tcl8.2 tcl8.1 tcl8.0 tcl80 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
|
||||
@@ -509,7 +566,7 @@ else
|
||||
AC_CHECK_HEADER(readline.h, [found=yes])
|
||||
fi
|
||||
if test "$found" = "no"; then
|
||||
for dir in /usr /usr/local /usr/local/readline /usr/contrib; do
|
||||
for dir in /usr /usr/local /usr/local/readline /usr/contrib /mingw; do
|
||||
AC_CHECK_FILE($dir/include/readline.h, found=yes)
|
||||
if test "$found" = "yes"; then
|
||||
TARGET_READLINE_INC="-I$dir/include"
|
||||
@@ -534,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.
|
||||
#
|
||||
@@ -544,5 +612,5 @@ AC_CHECK_FUNC(usleep, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_USLEEP=1"])
|
||||
#
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
sqlite.pc
|
||||
sqlite3.pc
|
||||
])
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -54,22 +54,28 @@ TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
|
||||
|
||||
# Object files for the SQLite library.
|
||||
#
|
||||
LIBOBJ = attach.o auth.o btree.o btree_rb.o build.o copy.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.o pager.o parse.o pragma.o printf.o random.o \
|
||||
select.o table.o tokenize.o trigger.o update.o util.o \
|
||||
vacuum.o vdbe.o vdbeaux.o where.o tclsqlite.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 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/btree_rb.c \
|
||||
$(TOP)/src/build.c \
|
||||
$(TOP)/src/copy.c \
|
||||
$(TOP)/src/callback.c \
|
||||
$(TOP)/src/complete.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/delete.c \
|
||||
$(TOP)/src/expr.c \
|
||||
@@ -77,12 +83,15 @@ SRC = \
|
||||
$(TOP)/src/hash.c \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os.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 \
|
||||
@@ -93,12 +102,16 @@ SRC = \
|
||||
$(TOP)/src/tclsqlite.c \
|
||||
$(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/trigger.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/update.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vacuum.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(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
|
||||
|
||||
@@ -106,23 +119,35 @@ SRC = \
|
||||
#
|
||||
TESTSRC = \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/md5.c
|
||||
$(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/where.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
sqlite.h \
|
||||
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_unix.h \
|
||||
$(TOP)/src/os_win.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
parse.h
|
||||
@@ -136,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: sqlite.h config.h libsqlite.a sqlite$(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
|
||||
@@ -145,13 +170,15 @@ last_change: $(SRC)
|
||||
cat $(SRC) | grep '$$Id: ' | sort +4 | tail -1 \
|
||||
| awk '{print $$5,$$6}' >last_change
|
||||
|
||||
libsqlite.a: $(LIBOBJ)
|
||||
$(AR) libsqlite.a $(LIBOBJ)
|
||||
$(RANLIB) libsqlite.a
|
||||
libsqlite3.a: $(LIBOBJ)
|
||||
$(AR) libsqlite3.a $(LIBOBJ)
|
||||
$(RANLIB) libsqlite3.a
|
||||
|
||||
sqlite$(EXE): $(TOP)/src/shell.c libsqlite.a sqlite.h
|
||||
$(TCCX) $(READLINE_FLAGS) -o sqlite$(EXE) $(TOP)/src/shell.c \
|
||||
libsqlite.a $(LIBREADLINE) $(THREADLIB)
|
||||
sqlite3$(EXE): $(TOP)/src/shell.c libsqlite3.a sqlite3.h
|
||||
$(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE) $(TOP)/src/shell.c \
|
||||
libsqlite3.a $(LIBREADLINE) $(THREADLIB)
|
||||
|
||||
objects: $(LIBOBJ_ORIG)
|
||||
|
||||
# This target creates a directory named "tsrc" and fills it with
|
||||
# copies of all of the C source code and header files needed to
|
||||
@@ -159,12 +186,13 @@ sqlite$(EXE): $(TOP)/src/shell.c libsqlite.a sqlite.h
|
||||
# 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
|
||||
#
|
||||
@@ -172,93 +200,31 @@ lemon: $(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.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
|
||||
|
||||
auth.o: $(TOP)/src/auth.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/auth.c
|
||||
|
||||
btree.o: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
|
||||
$(TCCX) -c $(TOP)/src/btree.c
|
||||
|
||||
btree_rb.o: $(TOP)/src/btree_rb.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/btree_rb.c
|
||||
|
||||
build.o: $(TOP)/src/build.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/build.c
|
||||
|
||||
main.o: $(TOP)/src/main.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/main.c
|
||||
callback.o: $(TOP)/src/callback.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/callback.c
|
||||
|
||||
pager.o: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
$(TCCX) -c $(TOP)/src/pager.c
|
||||
|
||||
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 *sqliteOpcodeNames[] = { "???", ' >>opcodes.c
|
||||
grep '^case OP_' $(TOP)/src/vdbe.c | \
|
||||
sed -e 's/^.*OP_/ "/' -e 's/:.*$$/", /' >>opcodes.c
|
||||
echo '};' >>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.o: $(TOP)/src/os.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/os.c
|
||||
|
||||
parse.o: parse.c $(HDR)
|
||||
$(TCCX) -c parse.c
|
||||
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon parse.y
|
||||
|
||||
# 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
|
||||
|
||||
sqlite.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||
-e s/--ENCODING--/$(ENCODING)/ \
|
||||
$(TOP)/src/sqlite.h.in >sqlite.h
|
||||
|
||||
tokenize.o: $(TOP)/src/tokenize.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/tokenize.c
|
||||
|
||||
trigger.o: $(TOP)/src/trigger.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/trigger.c
|
||||
|
||||
util.o: $(TOP)/src/util.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/util.c
|
||||
|
||||
vacuum.o: $(TOP)/src/vacuum.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/vacuum.c
|
||||
|
||||
vdbe.o: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbe.c
|
||||
|
||||
vdbeaux.o: $(TOP)/src/vdbeaux.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbeaux.c
|
||||
|
||||
where.o: $(TOP)/src/where.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/where.c
|
||||
|
||||
copy.o: $(TOP)/src/copy.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/copy.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
|
||||
@@ -278,149 +244,319 @@ hash.o: $(TOP)/src/hash.c $(HDR)
|
||||
insert.o: $(TOP)/src/insert.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/insert.c
|
||||
|
||||
legacy.o: $(TOP)/src/legacy.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/legacy.c
|
||||
|
||||
main.o: $(TOP)/src/main.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/main.c
|
||||
|
||||
pager.o: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
$(TCCX) -c $(TOP)/src/pager.c
|
||||
|
||||
opcodes.o: opcodes.c
|
||||
$(TCCX) -c opcodes.c
|
||||
|
||||
opcodes.c: opcodes.h $(TOP)/mkopcodec.awk
|
||||
sort -n -b +2 opcodes.h | awk -f $(TOP)/mkopcodec.awk >opcodes.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
|
||||
|
||||
os_win.o: $(TOP)/src/os_win.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/os_win.c
|
||||
|
||||
parse.o: parse.c $(HDR)
|
||||
$(TCCX) -c parse.c
|
||||
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon
|
||||
cp $(TOP)/src/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
|
||||
|
||||
random.o: $(TOP)/src/random.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/random.c
|
||||
|
||||
select.o: $(TOP)/src/select.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/select.c
|
||||
|
||||
sqlite3.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||
-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)
|
||||
$(TCCX) -c $(TOP)/src/table.c
|
||||
|
||||
update.o: $(TOP)/src/update.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/update.c
|
||||
|
||||
tclsqlite.o: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
pragma.o: $(TOP)/src/pragma.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
|
||||
tokenize.o: $(TOP)/src/tokenize.c keywordhash.h $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/tokenize.c
|
||||
|
||||
printf.o: $(TOP)/src/printf.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
keywordhash.h: $(TOP)/tool/mkkeywordhash.c
|
||||
$(BCC) -o mkkeywordhash $(OPTS) $(TOP)/tool/mkkeywordhash.c
|
||||
./mkkeywordhash >keywordhash.h
|
||||
|
||||
attach.o: $(TOP)/src/attach.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/attach.c
|
||||
trigger.o: $(TOP)/src/trigger.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/trigger.c
|
||||
|
||||
auth.o: $(TOP)/src/auth.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/auth.c
|
||||
update.o: $(TOP)/src/update.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/update.c
|
||||
|
||||
tclsqlite: $(TOP)/src/tclsqlite.c libsqlite.a
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite \
|
||||
$(TOP)/src/tclsqlite.c libsqlite.a $(LIBTCL)
|
||||
utf.o: $(TOP)/src/utf.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/utf.c
|
||||
|
||||
testfixture$(EXE): $(TOP)/src/tclsqlite.c libsqlite.a $(TESTSRC)
|
||||
util.o: $(TOP)/src/util.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/util.c
|
||||
|
||||
vacuum.o: $(TOP)/src/vacuum.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/vacuum.c
|
||||
|
||||
vdbe.o: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbe.c
|
||||
|
||||
vdbeapi.o: $(TOP)/src/vdbeapi.c $(VDBEHDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbeapi.c
|
||||
|
||||
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
|
||||
|
||||
where.o: $(TOP)/src/where.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/where.c
|
||||
|
||||
# Rules for building test programs and for running tests
|
||||
#
|
||||
tclsqlite3: $(TOP)/src/tclsqlite.c libsqlite3.a
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite3 \
|
||||
$(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
testfixture$(EXE): $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC)
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -o testfixture$(EXE) \
|
||||
$(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite.a $(LIBTCL)
|
||||
libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
fulltest: testfixture$(EXE) sqlite$(EXE)
|
||||
crashtest: $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC) $(TOP)/src/os_test.c
|
||||
$(TCCX) $(TCL_FLAGS) -DOS_TEST=1 -DTCLSH=1 -DSQLITE_TEST=1 \
|
||||
-o crashtest \
|
||||
$(TESTSRC) $(TOP)/src/os_test.c $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
fulltest: testfixture$(EXE) sqlite3$(EXE) crashtest
|
||||
./testfixture$(EXE) $(TOP)/test/all.test
|
||||
|
||||
test: testfixture$(EXE) sqlite$(EXE)
|
||||
test: testfixture$(EXE) sqlite3$(EXE)
|
||||
./testfixture$(EXE) $(TOP)/test/quick.test
|
||||
|
||||
index.html: $(TOP)/www/index.tcl last_change
|
||||
tclsh $(TOP)/www/index.tcl `cat $(TOP)/VERSION` >index.html
|
||||
sqlite3_analyzer$(EXE): $(TOP)/src/tclsqlite.c libsqlite3.a $(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
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=2 -DSQLITE_TEST=1 -o \
|
||||
sqlite3_analyzer$(EXE) $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
|
||||
# Rules used to build documentation
|
||||
#
|
||||
arch.html: $(TOP)/www/arch.tcl
|
||||
tclsh $(TOP)/www/arch.tcl >arch.html
|
||||
|
||||
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
|
||||
|
||||
capi3.html: $(TOP)/www/capi3.tcl
|
||||
tclsh $(TOP)/www/capi3.tcl >capi3.html
|
||||
|
||||
capi3ref.html: $(TOP)/www/capi3ref.tcl
|
||||
tclsh $(TOP)/www/capi3ref.tcl >capi3ref.html
|
||||
|
||||
changes.html: $(TOP)/www/changes.tcl
|
||||
tclsh $(TOP)/www/changes.tcl >changes.html
|
||||
|
||||
lang.html: $(TOP)/www/lang.tcl
|
||||
tclsh $(TOP)/www/lang.tcl >lang.html
|
||||
compile.html: $(TOP)/www/compile.tcl
|
||||
tclsh $(TOP)/www/compile.tcl >compile.html
|
||||
|
||||
vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
tclsh $(TOP)/www/vdbe.tcl >vdbe.html
|
||||
copyright.html: $(TOP)/www/copyright.tcl
|
||||
tclsh $(TOP)/www/copyright.tcl >copyright.html
|
||||
|
||||
arch.html: $(TOP)/www/arch.tcl
|
||||
tclsh $(TOP)/www/arch.tcl >arch.html
|
||||
copyright-release.html: $(TOP)/www/copyright-release.html
|
||||
cp $(TOP)/www/copyright-release.html .
|
||||
|
||||
arch.png: $(TOP)/www/arch.png
|
||||
cp $(TOP)/www/arch.png .
|
||||
copyright-release.pdf: $(TOP)/www/copyright-release.pdf
|
||||
cp $(TOP)/www/copyright-release.pdf .
|
||||
|
||||
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
|
||||
|
||||
tclsqlite.html: $(TOP)/www/tclsqlite.tcl
|
||||
tclsh $(TOP)/www/tclsqlite.tcl >tclsqlite.html
|
||||
|
||||
speed.html: $(TOP)/www/speed.tcl
|
||||
tclsh $(TOP)/www/speed.tcl >speed.html
|
||||
|
||||
faq.html: $(TOP)/www/faq.tcl
|
||||
tclsh $(TOP)/www/faq.tcl >faq.html
|
||||
|
||||
formatchng.html: $(TOP)/www/formatchng.tcl
|
||||
tclsh $(TOP)/www/formatchng.tcl >formatchng.html
|
||||
common.tcl: $(TOP)/www/common.tcl
|
||||
cp $(TOP)/www/common.tcl .
|
||||
|
||||
conflict.html: $(TOP)/www/conflict.tcl
|
||||
tclsh $(TOP)/www/conflict.tcl >conflict.html
|
||||
|
||||
download.html: $(TOP)/www/download.tcl
|
||||
tclsh $(TOP)/www/download.tcl >download.html
|
||||
|
||||
omitted.html: $(TOP)/www/omitted.tcl
|
||||
tclsh $(TOP)/www/omitted.tcl >omitted.html
|
||||
|
||||
datatypes.html: $(TOP)/www/datatypes.tcl
|
||||
tclsh $(TOP)/www/datatypes.tcl >datatypes.html
|
||||
|
||||
quickstart.html: $(TOP)/www/quickstart.tcl
|
||||
tclsh $(TOP)/www/quickstart.tcl >quickstart.html
|
||||
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
|
||||
|
||||
download.html: $(TOP)/www/download.tcl
|
||||
mkdir -p doc
|
||||
tclsh $(TOP)/www/download.tcl >download.html
|
||||
|
||||
faq.html: $(TOP)/www/faq.tcl
|
||||
tclsh $(TOP)/www/faq.tcl >faq.html
|
||||
|
||||
fileformat.html: $(TOP)/www/fileformat.tcl
|
||||
tclsh $(TOP)/www/fileformat.tcl >fileformat.html
|
||||
|
||||
formatchng.html: $(TOP)/www/formatchng.tcl
|
||||
tclsh $(TOP)/www/formatchng.tcl >formatchng.html
|
||||
|
||||
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 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
|
||||
|
||||
omitted.html: $(TOP)/www/omitted.tcl
|
||||
tclsh $(TOP)/www/omitted.tcl >omitted.html
|
||||
|
||||
opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
|
||||
tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
|
||||
|
||||
optimizer.html: $(TOP)/www/optimizer.tcl
|
||||
tclsh $(TOP)/www/optimizer.tcl >optimizer.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
|
||||
|
||||
speed.html: $(TOP)/www/speed.tcl
|
||||
tclsh $(TOP)/www/speed.tcl >speed.html
|
||||
|
||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
|
||||
|
||||
support.html: $(TOP)/www/support.tcl
|
||||
tclsh $(TOP)/www/support.tcl >support.html
|
||||
|
||||
tclsqlite.html: $(TOP)/www/tclsqlite.tcl
|
||||
tclsh $(TOP)/www/tclsqlite.tcl >tclsqlite.html
|
||||
|
||||
vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
tclsh $(TOP)/www/vdbe.tcl >vdbe.html
|
||||
|
||||
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 = \
|
||||
index.html \
|
||||
sqlite.html \
|
||||
changes.html \
|
||||
lang.html \
|
||||
opcode.html \
|
||||
arch.html \
|
||||
arch.png \
|
||||
vdbe.html \
|
||||
autoinc.html \
|
||||
c_interface.html \
|
||||
mingw.html \
|
||||
tclsqlite.html \
|
||||
download.html \
|
||||
speed.html \
|
||||
faq.html \
|
||||
formatchng.html \
|
||||
capi3.html \
|
||||
capi3ref.html \
|
||||
changes.html \
|
||||
compile.html \
|
||||
copyright.html \
|
||||
copyright-release.html \
|
||||
copyright-release.pdf \
|
||||
conflict.html \
|
||||
omitted.html \
|
||||
datatypes.html \
|
||||
quickstart.html \
|
||||
datatype3.html \
|
||||
different.html \
|
||||
docs.html \
|
||||
download.html \
|
||||
faq.html \
|
||||
fileformat.html \
|
||||
nulls.html
|
||||
formatchng.html \
|
||||
index.html \
|
||||
lang.html \
|
||||
lockingv3.html \
|
||||
mingw.html \
|
||||
nulls.html \
|
||||
oldnews.html \
|
||||
omitted.html \
|
||||
opcode.html \
|
||||
optimizer.html \
|
||||
optoverview.html \
|
||||
pragma.html \
|
||||
quickstart.html \
|
||||
speed.html \
|
||||
sqlite.html \
|
||||
support.html \
|
||||
tclsqlite.html \
|
||||
vdbe.html \
|
||||
version3.html \
|
||||
whentouse.html
|
||||
|
||||
doc: $(DOC)
|
||||
doc: common.tcl $(DOC)
|
||||
mkdir -p doc
|
||||
mv $(DOC) doc
|
||||
cp $(TOP)/www/*.gif $(TOP)/art/*.gif doc
|
||||
|
||||
install: sqlite libsqlite.a sqlite.h
|
||||
mv sqlite /usr/bin
|
||||
mv libsqlite.a /usr/lib
|
||||
mv sqlite.h /usr/include
|
||||
# Standard install and cleanup targets
|
||||
#
|
||||
install: sqlite3 libsqlite3.a sqlite3.h
|
||||
mv sqlite3 /usr/bin
|
||||
mv libsqlite3.a /usr/lib
|
||||
mv sqlite3.h /usr/include
|
||||
|
||||
clean:
|
||||
rm -f *.o sqlite libsqlite.a sqlite.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,182 +1,315 @@
|
||||
C Version\s2.8.7\s(CVS\s1124)
|
||||
D 2003-12-04T13:47:05
|
||||
F Makefile.in 5cb273b7d0e945d47ee8b9ad1c2a04ce79927d2d
|
||||
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||
F VERSION 3efaa76c9810cc1d4c6c777f48f433987cbb3662
|
||||
F aclocal.m4 ff32919e75f42b2d4213fe3c6f79dd0fe47f7769
|
||||
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 config.guess 831db445a8ae31d1f773fce85e14c16c8677417d
|
||||
F config.sub 975368989965310238930ecf8e7f06a23061dbb1
|
||||
F configure a79b01eab6acd5e45f08a84b187c435d7d76e256 x
|
||||
F configure.ac 85202fbe47e3d308406090d0016af2a4f6c5b9e6
|
||||
F art/SQLiteLogo3.tiff b9e6bf022ae939bc986cddb8ab99583ca1b02cb3
|
||||
F config.guess 2103e94b15dc57112d7b9ee152c6fac5288895b4
|
||||
F config.sub 9bf686ec001ae7bc53f5b3563c90c62d4c6d48be
|
||||
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 libtool bbbea7d79c23323e4100103836028e4fad0d9242
|
||||
F ltmain.sh abfb9387049fff6996afc6e325736597795baf11
|
||||
F main.mk 3e200c199e46c2b7c3106fd2c3bfa11cd0aa22c9
|
||||
F publish.sh 86b5e8535830a2588f62ce1d5d1ef00e1dede23a
|
||||
F spec.template a38492f1c1dd349fc24cb0565e08afc53045304b
|
||||
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
|
||||
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
|
||||
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.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
|
||||
F src/attach.c 9f78b4aaac02a2b09ff108e92cbaee3199e7962a
|
||||
F src/auth.c c8f50d4507e37779d96ff3c55417bc2b612dfed6
|
||||
F src/btree.c ba1cc0c71c3d2742b9a9047832335dc7d3656c45
|
||||
F src/btree.h 9b7c09f1e64274d7bb74a57bbfc63778f67b1048
|
||||
F src/btree_rb.c 67d154ffb0fac27a4a7eab9118ece6eaafeb49c9
|
||||
F src/build.c fede6bfb79d50483747fa55ae18c35d95db35fe3
|
||||
F src/copy.c 9e47975ea96751c658bcf1a0c4f0bb7c6ee61e73
|
||||
F src/date.c acb75ff7849ca923837a9d3ef6b2d3e111a32fb0
|
||||
F src/delete.c 0f81e6799c089487615d38e042a2de4d2d6192bc
|
||||
F src/encode.c 25ea901a9cefb3d93774afa4a06b57cb58acf544
|
||||
F src/expr.c d4d8eca6363a6e680361e5d2a934b78e5c7b7fa3
|
||||
F src/func.c 82a749b9a03ae9834a90854464f93e29f902799b
|
||||
F src/hash.c 058f077c1f36f266581aa16f907a3903abf64aa3
|
||||
F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8
|
||||
F src/insert.c dc200ae04a36bd36e575272a069e20c528b7fbdf
|
||||
F src/main.c 9422005bb4411cc08c2986fde3278ac5b87068a0
|
||||
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
|
||||
F src/os.c 97df440bc71f65e22df5d3d920ce39551c0a5f5a
|
||||
F src/os.h 729395fefcca4b81ae056aa9ff67b72bb40dd9e0
|
||||
F src/pager.c 62702dff51d50694d039bc210f31990d1fbba2dd
|
||||
F src/pager.h 5da62c83443f26b1792cfd72c96c422f91aadd31
|
||||
F src/parse.y 1c72ca2a1f57df2c6263ea6164ef4cae9dd4f7e7
|
||||
F src/pragma.c cee60f17679210e8acd30d5bdee855716d0c898c
|
||||
F src/printf.c 12e45d482ac8abcc6f786fc99e5bed7dd9a51af0
|
||||
F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
|
||||
F src/select.c d79ac60ba1595ff3c94b12892e87098329776482
|
||||
F src/shell.c c2ba26c850874964f5ec1ebf6c43406f28e44c4a
|
||||
F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
|
||||
F src/sqlite.h.in e6cfff01fafc8a82ce82cd8c932af421dc9adb54
|
||||
F src/sqliteInt.h 882aa33ee2aed7685449b899d917a316b9cc2c44
|
||||
F src/table.c 4301926464d88d2c2c7cd21c3360aa75bf068b95
|
||||
F src/tclsqlite.c 3efac6b5861ac149c41251d4d4c420c94be5ba6a
|
||||
F src/test1.c f9d5816610f7ec4168ab7b098d5207a5708712b6
|
||||
F src/test2.c 5014337d8576b731cce5b5a14bec4f0daf432700
|
||||
F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
|
||||
F src/threadtest.c d641a5219e718e18a1a80a50eb9bb549f451f42e
|
||||
F src/tokenize.c e14db6bfa972a7c449c80788fcdbc0fdc11b17d7
|
||||
F src/trigger.c ce83e017b407d046e909d05373d7f8ee70f9f7f9
|
||||
F src/update.c 24260b4fda00c9726d27699a0561d53c0dccc397
|
||||
F src/util.c cc95dd360fac09a059b2ab98e4c333d1a2308db5
|
||||
F src/vacuum.c e4724eade07e4cf8897060a8cf632dbd92408eeb
|
||||
F src/vdbe.c 0928a242ced0b5d26292f3949fdab26fa4dc327d
|
||||
F src/vdbe.h 3957844e46fea71fd030e78f6a3bd2f7e320fb43
|
||||
F src/vdbeInt.h 2824bf88895b901b3a8c9e44527c67530e1c0dcb
|
||||
F src/vdbeaux.c 31abb8e3e57866913360381947e267a51fed92c6
|
||||
F src/where.c 6bd1d2a9c70af63a6e47b0ab0c181d501b12514f
|
||||
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
|
||||
F test/attach.test c26848402e7ac829e043e1fa5e0eb87032e5d81d
|
||||
F test/attach2.test 6f98cc2b929d88dc5f82d95d04e9b89b3b5dead3
|
||||
F test/auth.test b7d6bdeffa804b96b7bcac2712e5f71ce014a1b8
|
||||
F test/bigfile.test 1cd8256d4619c39bea48147d344f348823e78678
|
||||
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
|
||||
F test/bind.test 56a57043b42c4664ca705f6050e56717a8a6699a
|
||||
F test/btree.test 1e3463c7838e7e71bbf37c9c6e45beee9c8975ba
|
||||
F test/btree2.test e3b81ec33dc2f89b3e6087436dfe605b870c9080
|
||||
F test/btree3.test e597fb59be2ac0ea69c62aaa2064e998e528b665
|
||||
F test/btree3rb.test 127efcf5cdfcc352054e7db12622b01cdd8b36ac
|
||||
F test/btree4.test fa955a3d7a8bc91d6084b7f494f9e5d1bdfb15b6
|
||||
F test/btree4rb.test ae6f0438512edcb45cf483471cd6070a765963a9
|
||||
F test/capi2.test ec96e0e235d87b53cbaef3d8e3e0f8ccf32c71ca
|
||||
F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e
|
||||
F test/copy.test 88dabd4e811b17644b726aa81d404e73b7635c84
|
||||
F test/date.test 17619ff81d5b813092915927c50923e265e85bd8
|
||||
F test/delete.test 92256384f1801760180ded129f7427884cf28886
|
||||
F test/expr.test c4cc292d601019c2f2ce95093caaa5d10284b105
|
||||
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
|
||||
F test/format3.test b05cb2968841553698290f2833f72894f156024e
|
||||
F test/func.test 000515779001ac6899eec4b54e65c6e2501279d4
|
||||
F test/in.test 22de8a3eb27265aab723adc513bea0e76bef70c6
|
||||
F test/index.test 9295deefbdb6dedbe01be8905f0c448fe5bd4079
|
||||
F test/insert.test a17b7f7017097afb2727aa5b67ceeb7ab0a120a1
|
||||
F test/insert2.test c288375a64dad3295044714f0dfed4a193cf067f
|
||||
F test/intpkey.test 9320af48415c594afd4e15f8ef0daa272e05502e
|
||||
F test/ioerr.test 5dbaf09f96b56ee01cf3edd762b96eb4ad2c9ca4
|
||||
F test/join.test 9ef6aabaac9de51d5fc41e68d1f4355da05a84cd
|
||||
F test/limit.test fa2a8b3fe377ebe60e0bc9a6a35af9ac4eb3d2b3
|
||||
F test/lock.test 388a3a10962d2d571c0c1821cc35bf069ee73473
|
||||
F test/main.test 6a851b5992c4881a725a3d9647e629199df8de9d
|
||||
F test/malloc.test 7ba32a9ebd3aeed52ae4aaa6d42ca37e444536fd
|
||||
F test/memdb.test 6ece25c7c0e6500199d3662607a3edca081abb2a
|
||||
F test/memleak.test a18e6810cae96d2f6f5136920267adbefc8e1e90
|
||||
F test/minmax.test 6d9b6d6ee34f42e2a58dffece1f76d35f446b3af
|
||||
F test/misc1.test 0b98d493b0cf55cb5f53e1f3df8107c166eecb5a
|
||||
F test/misc2.test 5818bfafd07535b0437f15c32bed983f3bd363b2
|
||||
F test/misuse.test a3aa2b18a97e4c409a1fcaff5151a4dd804a0162
|
||||
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||
F sqlite3.def c413e514217736884254739a105c8c942fdf0c2f
|
||||
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
|
||||
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 1f51566d7cf4b243a2792f5fda37343d6e9377fa
|
||||
F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
|
||||
F src/main.c 422014201f22aa17b96c76650163178a91a825af
|
||||
F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
|
||||
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 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 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 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 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 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 c14d0f4739f21e929b8115b72bf0c765b6bb1721
|
||||
F test/pager.test dd31da9bee94a82e2e87e58cf286cfe809f8fc5f
|
||||
F test/pragma.test e7cb7ffd765c9158868b0b7a3771d54a0d5f5072
|
||||
F test/printf.test 3ed02f1361402c0767492cd5cef4650e61df8308
|
||||
F test/progress.test 701b6115c2613128ececdfe1398a1bd0e1a4cfb3 x
|
||||
F test/quick.test c527bdb899b12a8cd8ceecce45f72922099f4095
|
||||
F test/quote.test 08f23385c685d3dc7914ec760d492cacea7f6e3d
|
||||
F test/rowid.test 1936d0d866a8105ab53cf6cb40a549b6664d06ce
|
||||
F test/select1.test 0d708cec567104653ec9aa49fecf3444a2e7d150
|
||||
F test/select2.test aceea74fd895b9d007512f72499db589735bd8e4
|
||||
F test/select3.test 445a1a3dde4e2fd32541b311f55da5e2f8079d76
|
||||
F test/select4.test e7e9a32fa745246cb99fadbeb63af4843a17925b
|
||||
F test/select5.test c2a6c4a003316ee42cbbd689eebef8fdce0db2ac
|
||||
F test/select6.test 670026a06c358cc867ace7b1de6020e43adc7245
|
||||
F test/sort.test ba07b107c16070208e6aab3cadea66ba079d85ba
|
||||
F test/subselect.test f0fea8cf9f386d416d64d152e3c65f9116d0f50f
|
||||
F test/table.test 371a1fc1c470982b2f68f9732f903a5d96f949c4
|
||||
F test/tableapi.test d881e787779a175238b72f55b5e50d3a85ab47a6
|
||||
F test/tclsqlite.test f141303e0f2e9a616b551813e2b21bd38c5dca50
|
||||
F test/temptable.test c82bd6f800f10e8cf96921af6315e5f1c21e2692
|
||||
F test/tester.tcl 2671536d3650c29e7c105219f277568b0884cb58
|
||||
F test/trans.test 75e7a171b5d2d94ee56766459113e2ad0e5f809d
|
||||
F test/trigger1.test 3fe06daecf8334df840025e154e95fd4727600d7
|
||||
F test/trigger2.test 0767ab30cb5a2c8402c8524f3d566b410b6f5263
|
||||
F test/trigger3.test a95ccace88291449f5eae7139ec438a42f90654d
|
||||
F test/trigger4.test 542afce45774e8f8e1130b96b8675f414d6e4bd8
|
||||
F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b
|
||||
F test/update.test 2ef5a6655f2966f0aef733a9f4495b3fe8e16809
|
||||
F test/vacuum.test a58776ef529e9bc21980ac120d6859d4ee34b578
|
||||
F test/version.test 605fd0d7e7d571370c32b12dbf395b58953de246
|
||||
F test/view.test 1ee12c6f8f4791a2c0655120d5562a49400cfe53
|
||||
F test/where.test cb3a2ed062ce4b5f08aff2d08027c6a46d68c47b
|
||||
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/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 ce0f0ad39fa4a3572acffcf1e634850ee151aae0
|
||||
F test/where.test ce21f4910ef6a0c08f8172857baecefca20a3b0c
|
||||
F test/where2.test 503e2e2b6abe14c5c10222e72d08ef84c1bf1ffb
|
||||
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
|
||||
F tool/lemon.c e37dcb5b8cdb16f4ac98338134bf8d8cd28e399f
|
||||
F tool/lempar.c 686d85ff4b11a790f52dd033612e6890a2a10f3c
|
||||
F tool/memleak.awk 16ef9493dcd36146f806e75148f4bb0201a123ec
|
||||
F tool/lemon.c c88936c67f6411608db8fa4254d254f509fa40f6
|
||||
F tool/lempar.c f0c30abcae762a7d1eb37cd88b2232ab8dd625fb
|
||||
F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133
|
||||
F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
|
||||
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 9a37d7b05de0591e3102aaf774d01fbc0d053a8b
|
||||
F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
|
||||
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
|
||||
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 44b589fc01d6829d43447ab40588b00aec5b9734
|
||||
F www/arch.tcl 03a6c66b1b34209d2897352e058377b421f0b80e
|
||||
F www/arch2.fig ae2432145c26cfa148fa0116589517ad3cd5fc65
|
||||
F www/arch2.gif 6f2d47c4e0c5842c0d6b5513fd8249393d7c7003
|
||||
F www/arch2b.fig d22a2c9642d584b89d4088b1e51e2bb0f7c04bed
|
||||
F www/audit.tcl 90e09d580f79c7efec0c7d6f447b7ec5c2dce5c0
|
||||
F www/c_interface.tcl 17d8bd9e7b4fbdca47c30c8b9bcb728c351d55c0
|
||||
F www/changes.tcl e2d31395f6ba922712b94642679b344b95d6d8f7
|
||||
F www/conflict.tcl 81dd21f9a679e60aae049e9dd8ab53d59570cda2
|
||||
F www/datatypes.tcl 0cb28565580554fa7e03e8fcb303e87ce57757ae
|
||||
F www/download.tcl 0932d7f4f0e8b2adbbd22fac73132f86e43ab4a9
|
||||
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 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 88d3b95d9cd8e374772daa3a646c4d107e7f3e9b
|
||||
F www/fileformat.tcl 56f77e435a6306b337b20b416e3b89500ba2d029
|
||||
F www/formatchng.tcl ca6cc1cb1bef9bc36f0619049d3c95e749bc6983
|
||||
F www/index.tcl 3530ab3c43e2f34f114d16495d19cc1751d12446
|
||||
F www/lang.tcl 5f39bbda1ba38a28f18f97bd98c81f40355393b2
|
||||
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 38117d24afb81efd079b59723b985a6d654cc2e8
|
||||
F www/omitted.tcl 11037a1b557bd01405092d93dfa08898a4c26cd7
|
||||
F www/opcode.tcl b8d561f33597c62955796b797646f00144d97332
|
||||
F www/quickstart.tcl 4e97bef825e6a4153c43afb9f97235fc4da278ab
|
||||
F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3
|
||||
F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
|
||||
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
|
||||
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
|
||||
P 9e79ab6ce06d68fcd7efa207d0ffcd1c51c13d58
|
||||
R cc120688e7dc0440e3d7bbe8a30278b7
|
||||
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 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 027fc0bba25796022eb035ace8db7316
|
||||
Z ad60d4c3881558341fdd282b95f7c97a
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
d48b0b018d47470689cc49f3be4cde50db165454
|
||||
e61382aed45a83ad688a0461948f9cd052a527fa
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to compile SQLite into a DLL.
|
||||
#
|
||||
# Two separate DLLs are generated. "sqlite3.dll" is the core
|
||||
# library. "tclsqlite3.dll" contains the TCL bindings and is the
|
||||
# library that is loaded into TCL in order to run SQLite.
|
||||
#
|
||||
make target_source
|
||||
cd tsrc
|
||||
PATH=$PATH:/opt/mingw/bin
|
||||
TCLDIR=/home/drh/tcltk/846/win/846win
|
||||
TCLSTUBLIB=$TCLDIR/libtcl84stub.a
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1 -DTHREADSAFE=1'
|
||||
CC="i386-mingw32msvc-gcc -O2 $OPTS -I. -I$TCLDIR"
|
||||
rm shell.c
|
||||
for i in *.c; do
|
||||
CMD="$CC -c $i"
|
||||
echo $CMD
|
||||
$CMD
|
||||
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 \
|
||||
--dlltool-name i386-mingw32msvc-dlltool \
|
||||
--as i386-mingw32msvc-as \
|
||||
--target i386-mingw32 \
|
||||
-dllname tclsqlite3.dll -lmsvcrt *.o $TCLSTUBLIB
|
||||
i386-mingw32msvc-strip tclsqlite3.dll
|
||||
rm tclsqlite.o
|
||||
i386-mingw32msvc-dllwrap \
|
||||
--def sqlite3.def -v --export-all \
|
||||
--driver-name i386-mingw32msvc-gcc \
|
||||
--dlltool-name i386-mingw32msvc-dlltool \
|
||||
--as i386-mingw32msvc-as \
|
||||
--target i386-mingw32 \
|
||||
-dllname sqlite3.dll -lmsvcrt *.o
|
||||
i386-mingw32msvc-strip sqlite3.dll
|
||||
cd ..
|
||||
@@ -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]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to compile SQLite into a shared library on Linux.
|
||||
#
|
||||
# Two separate shared libraries are generated. "sqlite3.so" is the core
|
||||
# library. "tclsqlite3.so" contains the TCL bindings and is the
|
||||
# library that is loaded into TCL in order to run SQLite.
|
||||
#
|
||||
make target_source
|
||||
cd tsrc
|
||||
rm shell.c
|
||||
TCLDIR=/home/drh/tcltk/846/linux/846linux
|
||||
TCLSTUBLIB=$TCLDIR/libtclstub8.4g.a
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1'
|
||||
for i in *.c; do
|
||||
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
|
||||
strip tclsqlite3.so
|
||||
rm tclsqlite.c tclsqlite.o
|
||||
echo gcc -shared *.o -o sqlite3.so
|
||||
gcc -shared *.o -o sqlite3.so
|
||||
strip sqlite3.so
|
||||
cd ..
|
||||
+44
-125
@@ -14,124 +14,51 @@ srcdir=`echo "$0" | sed 's%\(^.*\)/[^/][^/]*$%\1%'`
|
||||
# Get the makefile.
|
||||
#
|
||||
cp $srcdir/Makefile.linux-gcc ./Makefile
|
||||
chmod +x $srcdir/install-sh
|
||||
|
||||
# Start building stuff.
|
||||
# Get the current version number - needed to help build filenames
|
||||
#
|
||||
VERS=`cat $srcdir/VERSION`
|
||||
VERSW=`sed 's/\./_/g' $srcdir/VERSION`
|
||||
|
||||
# Start by building an sqlite shell for linux.
|
||||
#
|
||||
make clean
|
||||
make sqlite
|
||||
strip sqlite
|
||||
mv sqlite sqlite.bin
|
||||
rm -f sqlite.bin.gz
|
||||
gzip sqlite.bin
|
||||
make sqlite3
|
||||
strip sqlite3
|
||||
mv sqlite3 sqlite3-$VERS.bin
|
||||
gzip sqlite3-$VERS.bin
|
||||
mv sqlite3-$VERS.bin.gz doc
|
||||
|
||||
# Build the tclsqlite.so shared library for import into tclsh or wish
|
||||
# Build a source archive useful for windows.
|
||||
#
|
||||
make target_source
|
||||
cd tsrc
|
||||
zip ../doc/sqlite-source-$VERSW.zip *
|
||||
cd ..
|
||||
|
||||
# Build the sqlite.so and tclsqlite.so shared libraries
|
||||
# under Linux
|
||||
#
|
||||
make target_source
|
||||
rm sqlite_source.zip
|
||||
. $srcdir/mkso.sh
|
||||
cd tsrc
|
||||
zip ../sqlite_source.zip *
|
||||
rm shell.c
|
||||
TCLDIR=/home/drh/tcltk/8.2linux
|
||||
TCLSTUBLIB=$TCLDIR/libtclstub8.2g.a
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1'
|
||||
gcc -fPIC $OPTS -O2 -I. -I$TCLDIR -shared *.c $TCLSTUBLIB -o tclsqlite.so
|
||||
strip tclsqlite.so
|
||||
mv tclsqlite.so ..
|
||||
rm tclsqlite.c
|
||||
gcc -fPIC -DNDEBUG=1 -O2 -I. -shared *.c -o sqlite.so
|
||||
strip sqlite.so
|
||||
mv sqlite.so ..
|
||||
mv tclsqlite3.so tclsqlite-$VERS.so
|
||||
gzip tclsqlite-$VERS.so
|
||||
mv tclsqlite-$VERS.so.gz ../doc
|
||||
mv sqlite3.so sqlite-$VERS.so
|
||||
gzip sqlite-$VERS.so
|
||||
mv sqlite-$VERS.so.gz ../doc
|
||||
cd ..
|
||||
rm -f tclsqlite.so.gz sqlite.so.gz
|
||||
gzip tclsqlite.so
|
||||
gzip sqlite.so
|
||||
|
||||
# Build the tclsqlite.dll shared library that can be imported into tclsh
|
||||
# or wish on windows.
|
||||
# Build the tclsqlite3.dll and sqlite3.dll shared libraries.
|
||||
#
|
||||
make target_source
|
||||
. $srcdir/mkdll.sh
|
||||
cd tsrc
|
||||
rm shell.c
|
||||
TCLDIR=/home/drh/tcltk/8.2win
|
||||
TCLSTUBLIB=$TCLDIR/tclstub82.a
|
||||
PATH=$PATH:/opt/mingw/bin
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1 -DTHREADSAFE=1'
|
||||
CC="i386-mingw32msvc-gcc -O2 $OPTS -I. -I$TCLDIR"
|
||||
rm shell.c
|
||||
for i in *.c; do
|
||||
CMD="$CC -c $i"
|
||||
echo $CMD
|
||||
$CMD
|
||||
done
|
||||
echo 'EXPORTS' >tclsqlite.def
|
||||
echo 'Tclsqlite_Init' >>tclsqlite.def
|
||||
echo 'Sqlite_Init' >>tclsqlite.def
|
||||
i386-mingw32msvc-dllwrap \
|
||||
--def tclsqlite.def -v --export-all \
|
||||
--driver-name i386-mingw32msvc-gcc \
|
||||
--dlltool-name i386-mingw32msvc-dlltool \
|
||||
--as i386-mingw32msvc-as \
|
||||
--target i386-mingw32 \
|
||||
-dllname tclsqlite.dll -lmsvcrt *.o $TCLSTUBLIB
|
||||
i386-mingw32msvc-strip tclsqlite.dll
|
||||
mv tclsqlite.dll ..
|
||||
rm tclsqlite.o
|
||||
cat >sqlite.def <<\END_OF_FILE
|
||||
EXPORTS
|
||||
sqlite_open
|
||||
sqlite_close
|
||||
sqlite_exec
|
||||
sqlite_last_insert_rowid
|
||||
sqlite_error_string
|
||||
sqlite_interrupt
|
||||
sqlite_complete
|
||||
sqlite_busy_handler
|
||||
sqlite_busy_timeout
|
||||
sqlite_get_table
|
||||
sqlite_free_table
|
||||
sqlite_mprintf
|
||||
sqlite_vmprintf
|
||||
sqlite_exec_printf
|
||||
sqlite_exec_vprintf
|
||||
sqlite_get_table_printf
|
||||
sqlite_get_table_vprintf
|
||||
sqlite_freemem
|
||||
sqlite_libversion
|
||||
sqlite_libencoding
|
||||
sqlite_changes
|
||||
sqlite_create_function
|
||||
sqlite_create_aggregate
|
||||
sqlite_function_type
|
||||
sqlite_user_data
|
||||
sqlite_aggregate_context
|
||||
sqlite_aggregate_count
|
||||
sqlite_set_result_string
|
||||
sqlite_set_result_int
|
||||
sqlite_set_result_double
|
||||
sqlite_set_result_error
|
||||
sqliteMalloc
|
||||
sqliteFree
|
||||
sqliteRealloc
|
||||
sqlite_set_authorizer
|
||||
sqlite_trace
|
||||
sqlite_compile
|
||||
sqlite_step
|
||||
sqlite_finalize
|
||||
END_OF_FILE
|
||||
i386-mingw32msvc-dllwrap \
|
||||
--def sqlite.def -v --export-all \
|
||||
--driver-name i386-mingw32msvc-gcc \
|
||||
--dlltool-name i386-mingw32msvc-dlltool \
|
||||
--as i386-mingw32msvc-as \
|
||||
--target i386-mingw32 \
|
||||
-dllname sqlite.dll -lmsvcrt *.o
|
||||
i386-mingw32msvc-strip sqlite.dll
|
||||
mv sqlite.dll sqlite.def ..
|
||||
echo zip ../doc/tclsqlite-$VERSW.zip tclsqlite3.dll
|
||||
zip ../doc/tclsqlite-$VERSW.zip tclsqlite3.dll
|
||||
echo zip ../doc/sqlitedll-$VERSW.zip sqlite3.dll sqlite3.def
|
||||
zip ../doc/sqlitedll-$VERSW.zip sqlite3.dll sqlite3.def
|
||||
cd ..
|
||||
rm -f tclsqlite.zip sqlitedll.zip
|
||||
zip tclsqlite.zip tclsqlite.dll
|
||||
zip sqlitedll.zip sqlite.dll sqlite.def
|
||||
|
||||
# Build the sqlite.exe executable for windows.
|
||||
#
|
||||
@@ -139,23 +66,20 @@ make target_source
|
||||
cd tsrc
|
||||
rm tclsqlite.c
|
||||
OPTS='-DSTATIC_BUILD=1 -DNDEBUG=1'
|
||||
i386-mingw32msvc-gcc -O2 $OPTS -I. -I$TCLDIR *.c -o sqlite.exe
|
||||
mv sqlite.exe ..
|
||||
i386-mingw32msvc-gcc -O2 $OPTS -I. -I$TCLDIR *.c -o sqlite3.exe
|
||||
zip ../doc/sqlite-$VERSW.zip sqlite3.exe
|
||||
cd ..
|
||||
rm -f sqlite.zip
|
||||
zip sqlite.zip sqlite.exe
|
||||
|
||||
# Construct a tarball of the source tree
|
||||
#
|
||||
ORIGIN=`pwd`
|
||||
cd $srcdir
|
||||
cd ..
|
||||
EXCLUDE=`find sqlite -print | grep CVS | sed 's,sqlite/, --exclude sqlite/,'`
|
||||
tar czf $ORIGIN/sqlite.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
|
||||
vers=`cat $srcdir/VERSION`
|
||||
rm -f sqlite-$vers.tar.gz
|
||||
ln sqlite.tar.gz sqlite-$vers.tar.gz
|
||||
|
||||
#
|
||||
# Build RPMS (binary) and Source RPM
|
||||
@@ -173,24 +97,19 @@ mkdir $HOME/rpm/SRPMS
|
||||
mkdir $HOME/rpm/SPECS
|
||||
|
||||
# create the spec file from the template
|
||||
sed s/SQLITE_VERSION/$vers/g $srcdir/spec.template > $HOME/rpm/SPECS/sqlite.spec
|
||||
sed s/SQLITE_VERSION/$VERS/g $srcdir/spec.template > $HOME/rpm/SPECS/sqlite.spec
|
||||
|
||||
# copy the source tarball to the rpm directory
|
||||
cp sqlite-$vers.tar.gz $HOME/rpm/SOURCES/.
|
||||
cp doc/sqlite-$VERS.tar.gz $HOME/rpm/SOURCES/.
|
||||
|
||||
# build all the rpms
|
||||
rpm -ba $HOME/rpm/SPECS/sqlite.spec >& rpm-$vers.log
|
||||
|
||||
# copy the RPMs into the build directory.
|
||||
ln $HOME/rpm/RPMS/i386/sqlite*-$vers*.rpm .
|
||||
ln $HOME/rpm/SRPMS/sqlite-$vers*.rpm .
|
||||
|
||||
mv $HOME/rpm/RPMS/i386/sqlite*-$vers*.rpm doc
|
||||
mv $HOME/rpm/SRPMS/sqlite-$vers*.rpm doc
|
||||
|
||||
# Build the website
|
||||
#
|
||||
cp $srcdir/../historical/* .
|
||||
rm -rf doc
|
||||
#cp $srcdir/../historical/* doc
|
||||
make doc
|
||||
ln sqlite.bin.gz sqlite.zip sqlite*.tar.gz tclsqlite.so.gz tclsqlite.zip doc
|
||||
ln sqlitedll.zip sqlite.so.gz sqlite_source.zip doc
|
||||
ln *.rpm doc
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ rm -fr $RPM_BUILD_ROOT
|
||||
|
||||
%files -n %{name}-devel
|
||||
%defattr(-, root, root)
|
||||
%{_libdir}/pkgconfig/sqlite.pc
|
||||
%{_libdir}/pkgconfig/sqlite3.pc
|
||||
%{_libdir}/*.a
|
||||
%{_libdir}/*.la
|
||||
%{_includedir}/*
|
||||
|
||||
@@ -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>.
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
EXPORTS
|
||||
sqlite3_aggregate_context
|
||||
sqlite3_aggregate_count
|
||||
sqlite3_bind_blob
|
||||
sqlite3_bind_double
|
||||
sqlite3_bind_int
|
||||
sqlite3_bind_int64
|
||||
sqlite3_bind_null
|
||||
sqlite3_bind_parameter_count
|
||||
sqlite3_bind_parameter_index
|
||||
sqlite3_bind_parameter_name
|
||||
sqlite3_bind_text
|
||||
sqlite3_bind_text16
|
||||
sqlite3_busy_handler
|
||||
sqlite3_busy_timeout
|
||||
sqlite3_changes
|
||||
sqlite3_close
|
||||
sqlite3_collation_needed
|
||||
sqlite3_collation_needed16
|
||||
sqlite3_column_blob
|
||||
sqlite3_column_bytes
|
||||
sqlite3_column_bytes16
|
||||
sqlite3_column_count
|
||||
sqlite3_column_decltype
|
||||
sqlite3_column_decltype16
|
||||
sqlite3_column_double
|
||||
sqlite3_column_int
|
||||
sqlite3_column_int64
|
||||
sqlite3_column_name
|
||||
sqlite3_column_name16
|
||||
sqlite3_column_text
|
||||
sqlite3_column_text16
|
||||
sqlite3_column_type
|
||||
sqlite3_commit_hook
|
||||
sqlite3_complete
|
||||
sqlite3_complete16
|
||||
sqlite3_create_collation
|
||||
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
|
||||
sqlite3_prepare
|
||||
sqlite3_prepare16
|
||||
sqlite3_progress_handler
|
||||
sqlite3_reset
|
||||
sqlite3_result_blob
|
||||
sqlite3_result_double
|
||||
sqlite3_result_error
|
||||
sqlite3_result_error16
|
||||
sqlite3_result_int
|
||||
sqlite3_result_int64
|
||||
sqlite3_result_null
|
||||
sqlite3_result_text
|
||||
sqlite3_result_text16
|
||||
sqlite3_result_text16be
|
||||
sqlite3_result_text16le
|
||||
sqlite3_result_value
|
||||
sqlite3_set_authorizer
|
||||
sqlite3_set_auxdata
|
||||
sqlite3_snprintf
|
||||
sqlite3_step
|
||||
sqlite3_total_changes
|
||||
sqlite3_trace
|
||||
sqlite3_transfer_bindings
|
||||
sqlite3_user_data
|
||||
sqlite3_value_blob
|
||||
sqlite3_value_bytes
|
||||
sqlite3_value_bytes16
|
||||
sqlite3_value_double
|
||||
sqlite3_value_int
|
||||
sqlite3_value_int64
|
||||
sqlite3_value_text
|
||||
sqlite3_value_text16
|
||||
sqlite3_value_text16be
|
||||
sqlite3_value_text16le
|
||||
sqlite3_value_type
|
||||
sqlite3_vmprintf
|
||||
@@ -0,0 +1,12 @@
|
||||
# Package Information for pkg-config
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: SQLite
|
||||
Description: SQL database engine
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lsqlite3
|
||||
Cflags: -I${includedir}
|
||||
+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 */
|
||||
+164
-90
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.7 2003/06/14 12:04:08 drh Exp $
|
||||
** $Id: attach.c,v 1.34 2005/08/20 03:03:04 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -23,80 +23,138 @@
|
||||
** The pFilename and pDbname arguments are the tokens that define the
|
||||
** filename and dbname in the ATTACH statement.
|
||||
*/
|
||||
void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname){
|
||||
void sqlite3Attach(
|
||||
Parse *pParse, /* The parser context */
|
||||
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 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;
|
||||
if( db->file_format<4 ){
|
||||
sqliteErrorMsg(pParse, "cannot attach auxiliary databases to an "
|
||||
"older format master database", 0);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
if( db->nDb>=MAX_ATTACHED+2 ){
|
||||
sqliteErrorMsg(pParse, "too many attached databases - max %d",
|
||||
sqlite3ErrorMsg(pParse, "too many attached databases - max %d",
|
||||
MAX_ATTACHED);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
zFile = 0;
|
||||
sqliteSetNString(&zFile, pFilename->z, pFilename->n, 0);
|
||||
if( zFile==0 ) return;
|
||||
sqliteDequote(zFile);
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqliteAuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
|
||||
sqliteFree(zFile);
|
||||
if( !db->autoCommit ){
|
||||
sqlite3ErrorMsg(pParse, "cannot ATTACH database within transaction");
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
zFile = sqlite3NameFromToken(pFilename);
|
||||
if( zFile==0 ){
|
||||
goto attach_end;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
|
||||
goto attach_end;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
zName = 0;
|
||||
sqliteSetNString(&zName, pDbname->z, pDbname->n, 0);
|
||||
if( zName==0 ) return;
|
||||
sqliteDequote(zName);
|
||||
zName = sqlite3NameFromToken(pDbname);
|
||||
if( zName==0 ){
|
||||
goto attach_end;
|
||||
}
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( db->aDb[i].zName && sqliteStrICmp(db->aDb[i].zName, zName)==0 ){
|
||||
sqliteErrorMsg(pParse, "database %z is already in use", zName);
|
||||
char *z = db->aDb[i].zName;
|
||||
if( z && sqlite3StrICmp(z, zName)==0 ){
|
||||
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++];
|
||||
memset(aNew, 0, sizeof(*aNew));
|
||||
sqliteHashInit(&aNew->tblHash, SQLITE_HASH_STRING, 0);
|
||||
sqliteHashInit(&aNew->idxHash, SQLITE_HASH_STRING, 0);
|
||||
sqliteHashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqliteHashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);
|
||||
sqlite3HashInit(&aNew->tblHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&aNew->idxHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);
|
||||
sqlite3HashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);
|
||||
aNew->zName = zName;
|
||||
rc = sqliteBtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
|
||||
zName = 0;
|
||||
aNew->safety_level = 3;
|
||||
rc = sqlite3BtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
|
||||
if( rc ){
|
||||
sqliteErrorMsg(pParse, "unable to open database: %s", zFile);
|
||||
sqlite3ErrorMsg(pParse, "unable to open database: %s", zFile);
|
||||
}
|
||||
sqliteFree(zFile);
|
||||
#if SQLITE_HAS_CODEC
|
||||
{
|
||||
extern int sqlite3CodecAttach(sqlite3*, int, void*, int);
|
||||
char *zKey;
|
||||
int nKey;
|
||||
if( keyType==0 ){
|
||||
/* No key specified. Use the key from the main database */
|
||||
extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);
|
||||
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
|
||||
}else if( keyType==1 ){
|
||||
/* Key specified as text */
|
||||
zKey = sqlite3NameFromToken(pKey);
|
||||
nKey = strlen(zKey);
|
||||
}else{
|
||||
/* Key specified as a BLOB */
|
||||
char *zTemp;
|
||||
assert( keyType==2 );
|
||||
pKey->z++;
|
||||
pKey->n--;
|
||||
zTemp = sqlite3NameFromToken(pKey);
|
||||
zKey = sqlite3HexToBlob(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
}
|
||||
sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
if( keyType ){
|
||||
sqliteFree(zKey);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
db->flags &= ~SQLITE_Initialized;
|
||||
if( pParse->nErr ) return;
|
||||
rc = sqliteInit(pParse->db, &pParse->zErrMsg);
|
||||
if( rc ){
|
||||
sqliteResetInternalSchema(db, 0);
|
||||
pParse->nErr++;
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
if( pParse->nErr==0 && rc==SQLITE_OK ){
|
||||
rc = sqlite3ReadSchema(pParse);
|
||||
}
|
||||
if( rc ){
|
||||
int i = db->nDb - 1;
|
||||
assert( i>=2 );
|
||||
if( db->aDb[i].pBt ){
|
||||
sqlite3BtreeClose(db->aDb[i].pBt);
|
||||
db->aDb[i].pBt = 0;
|
||||
}
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
assert( pParse->nErr>0 ); /* Always set by sqlite3ReadSchema() */
|
||||
if( pParse->rc==SQLITE_OK ){
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
attach_end:
|
||||
sqliteFree(zFile);
|
||||
sqliteFree(zName);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -106,40 +164,48 @@ void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname){
|
||||
**
|
||||
** The pDbname argument is the name of the database in the DETACH statement.
|
||||
*/
|
||||
void sqliteDetach(Parse *pParse, Token *pDbname){
|
||||
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++){
|
||||
if( db->aDb[i].pBt==0 || db->aDb[i].zName==0 ) continue;
|
||||
if( strlen(db->aDb[i].zName)!=pDbname->n ) continue;
|
||||
if( sqliteStrNICmp(db->aDb[i].zName, pDbname->z, pDbname->n)==0 ) break;
|
||||
pDb = &db->aDb[i];
|
||||
if( pDb->pBt==0 ) continue;
|
||||
if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
|
||||
}
|
||||
if( i>=db->nDb ){
|
||||
sqliteErrorMsg(pParse, "no such database: %T", pDbname);
|
||||
sqlite3ErrorMsg(pParse, "no such database: %z", zName);
|
||||
return;
|
||||
}
|
||||
if( i<2 ){
|
||||
sqliteErrorMsg(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;
|
||||
return;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqliteAuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){
|
||||
if( sqlite3AuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){
|
||||
return;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
sqliteBtreeClose(db->aDb[i].pBt);
|
||||
db->aDb[i].pBt = 0;
|
||||
sqliteFree(db->aDb[i].zName);
|
||||
sqliteResetInternalSchema(db, i);
|
||||
db->nDb--;
|
||||
if( i<db->nDb ){
|
||||
db->aDb[i] = db->aDb[db->nDb];
|
||||
memset(&db->aDb[db->nDb], 0, sizeof(db->aDb[0]));
|
||||
sqliteResetInternalSchema(db, i);
|
||||
}
|
||||
sqlite3BtreeClose(pDb->pBt);
|
||||
pDb->pBt = 0;
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -149,14 +215,14 @@ void sqliteDetach(Parse *pParse, Token *pDbname){
|
||||
** The return value indicates whether or not fixation is required. TRUE
|
||||
** means we do need to fix the database references, FALSE means we do not.
|
||||
*/
|
||||
int sqliteFixInit(
|
||||
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;
|
||||
@@ -172,7 +238,7 @@ int sqliteFixInit(
|
||||
** The following set of routines walk through the parse tree and assign
|
||||
** a specific database to all table references where the database name
|
||||
** was left unspecified in the original SQL statement. The pFix structure
|
||||
** must have been initialized by a prior call to sqliteFixInit().
|
||||
** must have been initialized by a prior call to sqlite3FixInit().
|
||||
**
|
||||
** These routines are used to make sure that an index, trigger, or
|
||||
** view in one database does not refer to objects in a different database.
|
||||
@@ -182,97 +248,105 @@ int sqliteFixInit(
|
||||
** pParse->zErrMsg and these routines return non-zero. If everything
|
||||
** checks out, these routines return 0.
|
||||
*/
|
||||
int sqliteFixSrcList(
|
||||
int sqlite3FixSrcList(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
SrcList *pList /* The Source list to check and modify */
|
||||
){
|
||||
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( sqliteStrICmp(pList->a[i].zDatabase,zDb)!=0 ){
|
||||
sqliteErrorMsg(pFix->pParse,
|
||||
"%s %z cannot reference objects in database %s",
|
||||
pFix->zType, sqliteStrNDup(pFix->pName->z, pFix->pName->n),
|
||||
pList->a[i].zDatabase);
|
||||
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 %T cannot reference objects in database %s",
|
||||
pFix->zType, pFix->pName, pItem->zDatabase);
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixSelect(pFix, pList->a[i].pSelect) ) return 1;
|
||||
if( sqliteFixExpr(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;
|
||||
}
|
||||
int sqliteFixSelect(
|
||||
#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 */
|
||||
){
|
||||
while( pSelect ){
|
||||
if( sqliteFixExprList(pFix, pSelect->pEList) ){
|
||||
if( sqlite3FixExprList(pFix, pSelect->pEList) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixSrcList(pFix, pSelect->pSrc) ){
|
||||
if( sqlite3FixSrcList(pFix, pSelect->pSrc) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExpr(pFix, pSelect->pWhere) ){
|
||||
if( sqlite3FixExpr(pFix, pSelect->pWhere) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExpr(pFix, pSelect->pHaving) ){
|
||||
if( sqlite3FixExpr(pFix, pSelect->pHaving) ){
|
||||
return 1;
|
||||
}
|
||||
pSelect = pSelect->pPrior;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqliteFixExpr(
|
||||
int sqlite3FixExpr(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
Expr *pExpr /* The expression to be fixed to one database */
|
||||
){
|
||||
while( pExpr ){
|
||||
if( sqliteFixSelect(pFix, pExpr->pSelect) ){
|
||||
if( sqlite3FixSelect(pFix, pExpr->pSelect) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExprList(pFix, pExpr->pList) ){
|
||||
if( sqlite3FixExprList(pFix, pExpr->pList) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExpr(pFix, pExpr->pRight) ){
|
||||
if( sqlite3FixExpr(pFix, pExpr->pRight) ){
|
||||
return 1;
|
||||
}
|
||||
pExpr = pExpr->pLeft;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqliteFixExprList(
|
||||
int sqlite3FixExprList(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
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( sqliteFixExpr(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;
|
||||
}
|
||||
int sqliteFixTriggerStep(
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int sqlite3FixTriggerStep(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
TriggerStep *pStep /* The trigger step be fixed to one database */
|
||||
){
|
||||
while( pStep ){
|
||||
if( sqliteFixSelect(pFix, pStep->pSelect) ){
|
||||
if( sqlite3FixSelect(pFix, pStep->pSelect) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExpr(pFix, pStep->pWhere) ){
|
||||
if( sqlite3FixExpr(pFix, pStep->pWhere) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExprList(pFix, pStep->pExprList) ){
|
||||
if( sqlite3FixExprList(pFix, pStep->pExprList) ){
|
||||
return 1;
|
||||
}
|
||||
pStep = pStep->pNext;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
+33
-33
@@ -9,12 +9,12 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the sqlite_set_authorizer()
|
||||
** This file contains code used to implement the sqlite3_set_authorizer()
|
||||
** API. This facility is an optional feature of the library. Embedded
|
||||
** systems that do not need this facility may omit it by recompiling
|
||||
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
|
||||
**
|
||||
** $Id: auth.c,v 1.10 2003/05/10 03:36:54 drh Exp $
|
||||
** $Id: auth.c,v 1.22 2005/07/29 15:36:15 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
** is a copy of the 3rd argument to this routine. The second argument
|
||||
** to the auth function is one of these constants:
|
||||
**
|
||||
** SQLITE_COPY
|
||||
** SQLITE_CREATE_INDEX
|
||||
** SQLITE_CREATE_TABLE
|
||||
** SQLITE_CREATE_TEMP_INDEX
|
||||
@@ -62,7 +61,7 @@
|
||||
** the table and the column that are being accessed. The auth function
|
||||
** should return either SQLITE_OK, SQLITE_DENY, or SQLITE_IGNORE. If
|
||||
** SQLITE_OK is returned, it means that access is allowed. SQLITE_DENY
|
||||
** means that the SQL statement will never-run - the sqlite_exec() call
|
||||
** means that the SQL statement will never-run - the sqlite3_exec() call
|
||||
** will return with an error. SQLITE_IGNORE means that the SQL statement
|
||||
** should run but attempts to read the specified column will return NULL
|
||||
** and attempts to write the column will be ignored.
|
||||
@@ -70,13 +69,14 @@
|
||||
** Setting the auth function to NULL disables this hook. The default
|
||||
** setting of the auth function is NULL.
|
||||
*/
|
||||
int sqlite_set_authorizer(
|
||||
sqlite *db,
|
||||
int sqlite3_set_authorizer(
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -85,13 +85,10 @@ int sqlite_set_authorizer(
|
||||
** user-supplied authorization function returned an illegal value.
|
||||
*/
|
||||
static void sqliteAuthBadReturnCode(Parse *pParse, int rc){
|
||||
char zBuf[20];
|
||||
sprintf(zBuf, "(%d)", rc);
|
||||
sqliteSetString(&pParse->zErrMsg, "illegal return value ", zBuf,
|
||||
" from the authorization function - should be SQLITE_OK, "
|
||||
"SQLITE_IGNORE, or SQLITE_DENY", 0);
|
||||
pParse->nErr++;
|
||||
pParse->rc = SQLITE_MISUSE;
|
||||
sqlite3ErrorMsg(pParse, "illegal return value (%d) from the "
|
||||
"authorization function - should be SQLITE_OK, SQLITE_IGNORE, "
|
||||
"or SQLITE_DENY", rc);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -103,34 +100,35 @@ static void sqliteAuthBadReturnCode(Parse *pParse, int rc){
|
||||
** instruction into a TK_NULL. If the auth function returns SQLITE_DENY,
|
||||
** then generate an error.
|
||||
*/
|
||||
void sqliteAuthRead(
|
||||
void sqlite3AuthRead(
|
||||
Parse *pParse, /* The parser context */
|
||||
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 ){
|
||||
@@ -150,13 +148,11 @@ void sqliteAuthRead(
|
||||
pExpr->op = TK_NULL;
|
||||
}else if( rc==SQLITE_DENY ){
|
||||
if( db->nDb>2 || pExpr->iDb!=0 ){
|
||||
sqliteSetString(&pParse->zErrMsg,"access to ", zDBase, ".",
|
||||
pTab->zName, ".", zCol, " is prohibited", 0);
|
||||
sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",
|
||||
zDBase, pTab->zName, zCol);
|
||||
}else{
|
||||
sqliteSetString(&pParse->zErrMsg,"access to ", pTab->zName, ".",
|
||||
zCol, " is prohibited", 0);
|
||||
sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited",pTab->zName,zCol);
|
||||
}
|
||||
pParse->nErr++;
|
||||
pParse->rc = SQLITE_AUTH;
|
||||
}else if( rc!=SQLITE_OK ){
|
||||
sqliteAuthBadReturnCode(pParse, rc);
|
||||
@@ -169,24 +165,28 @@ void sqliteAuthRead(
|
||||
** is returned, then the error count and error message in pParse are
|
||||
** modified appropriately.
|
||||
*/
|
||||
int sqliteAuthCheck(
|
||||
int sqlite3AuthCheck(
|
||||
Parse *pParse,
|
||||
int code,
|
||||
const char *zArg1,
|
||||
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. */
|
||||
if( db->init.busy ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
if( db->xAuth==0 ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
|
||||
if( rc==SQLITE_DENY ){
|
||||
sqliteSetString(&pParse->zErrMsg, "not authorized", 0);
|
||||
sqlite3ErrorMsg(pParse, "not authorized");
|
||||
pParse->rc = SQLITE_AUTH;
|
||||
pParse->nErr++;
|
||||
}else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
|
||||
rc = SQLITE_DENY;
|
||||
sqliteAuthBadReturnCode(pParse, rc);
|
||||
@@ -199,7 +199,7 @@ int sqliteAuthCheck(
|
||||
** zArg3 argument to authorization callbacks will be zContext until
|
||||
** popped. Or if pParse==0, this routine is a no-op.
|
||||
*/
|
||||
void sqliteAuthContextPush(
|
||||
void sqlite3AuthContextPush(
|
||||
Parse *pParse,
|
||||
AuthContext *pContext,
|
||||
const char *zContext
|
||||
@@ -213,9 +213,9 @@ void sqliteAuthContextPush(
|
||||
|
||||
/*
|
||||
** Pop an authorization context that was previously pushed
|
||||
** by sqliteAuthContextPush
|
||||
** by sqlite3AuthContextPush
|
||||
*/
|
||||
void sqliteAuthContextPop(AuthContext *pContext){
|
||||
void sqlite3AuthContextPop(AuthContext *pContext){
|
||||
if( pContext->pParse ){
|
||||
pContext->pParse->zAuthContext = pContext->zAuthContext;
|
||||
pContext->pParse = 0;
|
||||
|
||||
+4303
-2055
File diff suppressed because it is too large
Load Diff
+110
-122
@@ -13,144 +13,132 @@
|
||||
** subsystem. See comments in the source code for a detailed description
|
||||
** of what each interface routine does.
|
||||
**
|
||||
** @(#) $Id: btree.h,v 1.35 2003/06/01 01:10:33 drh Exp $
|
||||
** @(#) $Id: btree.h,v 1.64 2005/08/27 16:36:49 drh Exp $
|
||||
*/
|
||||
#ifndef _BTREE_H_
|
||||
#define _BTREE_H_
|
||||
|
||||
/* TODO: This definition is just included so other modules compile. It
|
||||
** needs to be revisited.
|
||||
*/
|
||||
#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
|
||||
*/
|
||||
typedef struct Btree Btree;
|
||||
typedef struct BtCursor BtCursor;
|
||||
typedef struct BtOps BtOps;
|
||||
typedef struct BtCursorOps BtCursorOps;
|
||||
|
||||
|
||||
/*
|
||||
** An instance of the following structure contains pointers to all
|
||||
** methods against an open BTree. Alternative BTree implementations
|
||||
** (examples: file based versus in-memory) can be created by substituting
|
||||
** different methods. Users of the BTree cannot tell the difference.
|
||||
int sqlite3BtreeOpen(
|
||||
const char *zFilename, /* Name of database file to open */
|
||||
Btree **, /* Return open Btree* here */
|
||||
int flags /* Flags */
|
||||
);
|
||||
|
||||
/* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
|
||||
** following values.
|
||||
**
|
||||
** In C++ we could do this by defining a virtual base class and then
|
||||
** creating subclasses for each different implementation. But this is
|
||||
** C not C++ so we have to be a little more explicit.
|
||||
** NOTE: These values must match the corresponding PAGER_ values in
|
||||
** pager.h.
|
||||
*/
|
||||
struct BtOps {
|
||||
int (*Close)(Btree*);
|
||||
int (*SetCacheSize)(Btree*, int);
|
||||
int (*SetSafetyLevel)(Btree*, int);
|
||||
int (*BeginTrans)(Btree*);
|
||||
int (*Commit)(Btree*);
|
||||
int (*Rollback)(Btree*);
|
||||
int (*BeginCkpt)(Btree*);
|
||||
int (*CommitCkpt)(Btree*);
|
||||
int (*RollbackCkpt)(Btree*);
|
||||
int (*CreateTable)(Btree*, int*);
|
||||
int (*CreateIndex)(Btree*, int*);
|
||||
int (*DropTable)(Btree*, int);
|
||||
int (*ClearTable)(Btree*, int);
|
||||
int (*Cursor)(Btree*, int iTable, int wrFlag, BtCursor **ppCur);
|
||||
int (*GetMeta)(Btree*, int*);
|
||||
int (*UpdateMeta)(Btree*, int*);
|
||||
char *(*IntegrityCheck)(Btree*, int*, int);
|
||||
const char *(*GetFilename)(Btree*);
|
||||
int (*Copyfile)(Btree*,Btree*);
|
||||
#define BTREE_OMIT_JOURNAL 1 /* Do not use journal. 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*);
|
||||
int sqlite3BtreeBeginStmt(Btree*);
|
||||
int sqlite3BtreeCommitStmt(Btree*);
|
||||
int sqlite3BtreeRollbackStmt(Btree*);
|
||||
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 *);
|
||||
const char *sqlite3BtreeGetJournalname(Btree *);
|
||||
int sqlite3BtreeCopyFile(Btree *, Btree *);
|
||||
|
||||
/* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
|
||||
** of the following flags:
|
||||
*/
|
||||
#define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
|
||||
#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*);
|
||||
int sqlite3BtreeClearTable(Btree*, int);
|
||||
int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
|
||||
int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
|
||||
|
||||
int sqlite3BtreeCursor(
|
||||
Btree*, /* BTree containing table to open */
|
||||
int iTable, /* Index of root page */
|
||||
int wrFlag, /* 1 for writing. 0 for read-only */
|
||||
int(*)(void*,int,const void*,int,const void*), /* Key comparison function */
|
||||
void*, /* First argument to compare function */
|
||||
BtCursor **ppCursor /* Returned cursor */
|
||||
);
|
||||
|
||||
void sqlite3BtreeSetCompare(
|
||||
BtCursor *,
|
||||
int(*)(void*,int,const void*,int,const void*),
|
||||
void*
|
||||
);
|
||||
|
||||
int sqlite3BtreeCloseCursor(BtCursor*);
|
||||
int sqlite3BtreeMoveto(BtCursor*, const void *pKey, i64 nKey, int *pRes);
|
||||
int sqlite3BtreeDelete(BtCursor*);
|
||||
int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
|
||||
const void *pData, int nData);
|
||||
int sqlite3BtreeFirst(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeLast(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeNext(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeEof(BtCursor*);
|
||||
int sqlite3BtreeFlags(BtCursor*);
|
||||
int sqlite3BtreePrevious(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
|
||||
int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
|
||||
const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
|
||||
const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
|
||||
int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
|
||||
int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
|
||||
|
||||
char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot);
|
||||
struct Pager *sqlite3BtreePager(Btree*);
|
||||
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
int (*PageDump)(Btree*, int, int);
|
||||
struct Pager *(*Pager)(Btree*);
|
||||
int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
|
||||
void sqlite3BtreeCursorList(Btree*);
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of this structure defines all of the methods that can
|
||||
** be executed against a cursor.
|
||||
*/
|
||||
struct BtCursorOps {
|
||||
int (*Moveto)(BtCursor*, const void *pKey, int nKey, int *pRes);
|
||||
int (*Delete)(BtCursor*);
|
||||
int (*Insert)(BtCursor*, const void *pKey, int nKey,
|
||||
const void *pData, int nData);
|
||||
int (*First)(BtCursor*, int *pRes);
|
||||
int (*Last)(BtCursor*, int *pRes);
|
||||
int (*Next)(BtCursor*, int *pRes);
|
||||
int (*Previous)(BtCursor*, int *pRes);
|
||||
int (*KeySize)(BtCursor*, int *pSize);
|
||||
int (*Key)(BtCursor*, int offset, int amt, char *zBuf);
|
||||
int (*KeyCompare)(BtCursor*, const void *pKey, int nKey,
|
||||
int nIgnore, int *pRes);
|
||||
int (*DataSize)(BtCursor*, int *pSize);
|
||||
int (*Data)(BtCursor*, int offset, int amt, char *zBuf);
|
||||
int (*CloseCursor)(BtCursor*);
|
||||
#ifdef SQLITE_TEST
|
||||
int (*CursorDump)(BtCursor*, int*);
|
||||
#ifdef SQLITE_DEBUG
|
||||
int sqlite3BtreePageDump(Btree*, int, int recursive);
|
||||
#else
|
||||
#define sqlite3BtreePageDump(X,Y,Z) SQLITE_OK
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
** The number of 4-byte "meta" values contained on the first page of each
|
||||
** database file.
|
||||
*/
|
||||
#define SQLITE_N_BTREE_META 10
|
||||
|
||||
int sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
|
||||
int sqliteRbtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
|
||||
|
||||
#define btOps(pBt) (*((BtOps **)(pBt)))
|
||||
#define btCOps(pCur) (*((BtCursorOps **)(pCur)))
|
||||
|
||||
#define sqliteBtreeClose(pBt) (btOps(pBt)->Close(pBt))
|
||||
#define sqliteBtreeSetCacheSize(pBt, sz) (btOps(pBt)->SetCacheSize(pBt, sz))
|
||||
#define sqliteBtreeSetSafetyLevel(pBt, sl) (btOps(pBt)->SetSafetyLevel(pBt, sl))
|
||||
#define sqliteBtreeBeginTrans(pBt) (btOps(pBt)->BeginTrans(pBt))
|
||||
#define sqliteBtreeCommit(pBt) (btOps(pBt)->Commit(pBt))
|
||||
#define sqliteBtreeRollback(pBt) (btOps(pBt)->Rollback(pBt))
|
||||
#define sqliteBtreeBeginCkpt(pBt) (btOps(pBt)->BeginCkpt(pBt))
|
||||
#define sqliteBtreeCommitCkpt(pBt) (btOps(pBt)->CommitCkpt(pBt))
|
||||
#define sqliteBtreeRollbackCkpt(pBt) (btOps(pBt)->RollbackCkpt(pBt))
|
||||
#define sqliteBtreeCreateTable(pBt,piTable)\
|
||||
(btOps(pBt)->CreateTable(pBt,piTable))
|
||||
#define sqliteBtreeCreateIndex(pBt, piIndex)\
|
||||
(btOps(pBt)->CreateIndex(pBt, piIndex))
|
||||
#define sqliteBtreeDropTable(pBt, iTable) (btOps(pBt)->DropTable(pBt, iTable))
|
||||
#define sqliteBtreeClearTable(pBt, iTable)\
|
||||
(btOps(pBt)->ClearTable(pBt, iTable))
|
||||
#define sqliteBtreeCursor(pBt, iTable, wrFlag, ppCur)\
|
||||
(btOps(pBt)->Cursor(pBt, iTable, wrFlag, ppCur))
|
||||
#define sqliteBtreeMoveto(pCur, pKey, nKey, pRes)\
|
||||
(btCOps(pCur)->Moveto(pCur, pKey, nKey, pRes))
|
||||
#define sqliteBtreeDelete(pCur) (btCOps(pCur)->Delete(pCur))
|
||||
#define sqliteBtreeInsert(pCur, pKey, nKey, pData, nData) \
|
||||
(btCOps(pCur)->Insert(pCur, pKey, nKey, pData, nData))
|
||||
#define sqliteBtreeFirst(pCur, pRes) (btCOps(pCur)->First(pCur, pRes))
|
||||
#define sqliteBtreeLast(pCur, pRes) (btCOps(pCur)->Last(pCur, pRes))
|
||||
#define sqliteBtreeNext(pCur, pRes) (btCOps(pCur)->Next(pCur, pRes))
|
||||
#define sqliteBtreePrevious(pCur, pRes) (btCOps(pCur)->Previous(pCur, pRes))
|
||||
#define sqliteBtreeKeySize(pCur, pSize) (btCOps(pCur)->KeySize(pCur, pSize) )
|
||||
#define sqliteBtreeKey(pCur, offset, amt, zBuf)\
|
||||
(btCOps(pCur)->Key(pCur, offset, amt, zBuf))
|
||||
#define sqliteBtreeKeyCompare(pCur, pKey, nKey, nIgnore, pRes)\
|
||||
(btCOps(pCur)->KeyCompare(pCur, pKey, nKey, nIgnore, pRes))
|
||||
#define sqliteBtreeDataSize(pCur, pSize) (btCOps(pCur)->DataSize(pCur, pSize))
|
||||
#define sqliteBtreeData(pCur, offset, amt, zBuf)\
|
||||
(btCOps(pCur)->Data(pCur, offset, amt, zBuf))
|
||||
#define sqliteBtreeCloseCursor(pCur) (btCOps(pCur)->CloseCursor(pCur))
|
||||
#define sqliteBtreeGetMeta(pBt, aMeta) (btOps(pBt)->GetMeta(pBt, aMeta))
|
||||
#define sqliteBtreeUpdateMeta(pBt, aMeta) (btOps(pBt)->UpdateMeta(pBt, aMeta))
|
||||
#define sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot)\
|
||||
(btOps(pBt)->IntegrityCheck(pBt, aRoot, nRoot))
|
||||
#define sqliteBtreeGetFilename(pBt) (btOps(pBt)->GetFilename(pBt))
|
||||
#define sqliteBtreeCopyFile(pBt1, pBt2) (btOps(pBt1)->Copyfile(pBt1, pBt2))
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
#define sqliteBtreePageDump(pBt, pgno, recursive)\
|
||||
(btOps(pBt)->PageDump(pBt, pgno, recursive))
|
||||
#define sqliteBtreeCursorDump(pCur, aResult)\
|
||||
(btCOps(pCur)->CursorDump(pCur, aResult))
|
||||
#define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt))
|
||||
int btree_native_byte_order;
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
|
||||
#endif /* _BTREE_H_ */
|
||||
|
||||
-1474
File diff suppressed because it is too large
Load Diff
+1785
-1070
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
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
** 2003 April 6
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the COPY command.
|
||||
**
|
||||
** $Id: copy.c,v 1.6 2003/06/02 22:50:26 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** The COPY command is for compatibility with PostgreSQL and specificially
|
||||
** for the ability to read the output of pg_dump. The format is as
|
||||
** follows:
|
||||
**
|
||||
** COPY table FROM file [USING DELIMITERS string]
|
||||
**
|
||||
** "table" is an existing table name. We will read lines of code from
|
||||
** file to fill this table with data. File might be "stdin". The optional
|
||||
** delimiter string identifies the field separators. The default is a tab.
|
||||
*/
|
||||
void sqliteCopy(
|
||||
Parse *pParse, /* The parser context */
|
||||
SrcList *pTableName, /* The name of the table into which we will insert */
|
||||
Token *pFilename, /* The file from which to obtain information */
|
||||
Token *pDelimiter, /* Use this as the field delimiter */
|
||||
int onError /* What to do if a constraint fails */
|
||||
){
|
||||
Table *pTab;
|
||||
int i;
|
||||
Vdbe *v;
|
||||
int addr, end;
|
||||
Index *pIdx;
|
||||
char *zFile = 0;
|
||||
const char *zDb;
|
||||
sqlite *db = pParse->db;
|
||||
|
||||
|
||||
if( sqlite_malloc_failed ) goto copy_cleanup;
|
||||
assert( pTableName->nSrc==1 );
|
||||
pTab = sqliteSrcListLookup(pParse, pTableName);
|
||||
if( pTab==0 || sqliteIsReadOnly(pParse, pTab, 0) ) goto copy_cleanup;
|
||||
zFile = sqliteStrNDup(pFilename->z, pFilename->n);
|
||||
sqliteDequote(zFile);
|
||||
assert( pTab->iDb<db->nDb );
|
||||
zDb = db->aDb[pTab->iDb].zName;
|
||||
if( sqliteAuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb)
|
||||
|| sqliteAuthCheck(pParse, SQLITE_COPY, pTab->zName, zFile, zDb) ){
|
||||
goto copy_cleanup;
|
||||
}
|
||||
v = sqliteGetVdbe(pParse);
|
||||
if( v ){
|
||||
sqliteBeginWriteOperation(pParse, 1, pTab->iDb);
|
||||
addr = sqliteVdbeAddOp(v, OP_FileOpen, 0, 0);
|
||||
sqliteVdbeChangeP3(v, addr, pFilename->z, pFilename->n);
|
||||
sqliteVdbeDequoteP3(v, addr);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenWrite, 0, pTab->tnum);
|
||||
sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
assert( pIdx->iDb==1 || pIdx->iDb==pTab->iDb );
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenWrite, i, pIdx->tnum);
|
||||
sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC);
|
||||
}
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0); /* Initialize the row count */
|
||||
}
|
||||
end = sqliteVdbeMakeLabel(v);
|
||||
addr = sqliteVdbeAddOp(v, OP_FileRead, pTab->nCol, end);
|
||||
if( pDelimiter ){
|
||||
sqliteVdbeChangeP3(v, addr, pDelimiter->z, pDelimiter->n);
|
||||
sqliteVdbeDequoteP3(v, addr);
|
||||
}else{
|
||||
sqliteVdbeChangeP3(v, addr, "\t", 1);
|
||||
}
|
||||
if( pTab->iPKey>=0 ){
|
||||
sqliteVdbeAddOp(v, OP_FileColumn, pTab->iPKey, 0);
|
||||
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_NewRecno, 0, 0);
|
||||
}
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
/* The integer primary key column is filled with NULL since its
|
||||
** value is always pulled from the record number */
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_FileColumn, i, 0);
|
||||
}
|
||||
}
|
||||
sqliteGenerateConstraintChecks(pParse, pTab, 0, 0, pTab->iPKey>=0,
|
||||
0, onError, addr);
|
||||
sqliteCompleteInsertion(pParse, pTab, 0, 0, 0, 0, -1);
|
||||
if( (db->flags & SQLITE_CountRows)!=0 ){
|
||||
sqliteVdbeAddOp(v, OP_AddImm, 1, 0); /* Increment row count */
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqliteVdbeResolveLabel(v, end);
|
||||
sqliteVdbeAddOp(v, OP_Noop, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
|
||||
sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
copy_cleanup:
|
||||
sqliteSrcListDelete(pTableName);
|
||||
sqliteFree(zFile);
|
||||
return;
|
||||
}
|
||||
+402
-179
@@ -13,10 +13,10 @@
|
||||
** functions for SQLite.
|
||||
**
|
||||
** There is only one exported symbol in this file - the function
|
||||
** sqliteRegisterDateTimeFunctions() found at the bottom of the file.
|
||||
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: date.c,v 1.1 2003/11/01 01:53:54 drh Exp $
|
||||
** $Id: date.c,v 1.45 2005/06/25 18:42:14 drh Exp $
|
||||
**
|
||||
** NOTES:
|
||||
**
|
||||
@@ -47,12 +47,14 @@
|
||||
** Willmann-Bell, Inc
|
||||
** Richmond, Virginia (USA)
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include <time.h>
|
||||
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
|
||||
/*
|
||||
** A structure for holding a single date and time.
|
||||
@@ -72,57 +74,57 @@ struct DateTime {
|
||||
|
||||
|
||||
/*
|
||||
** Convert N digits from zDate into an integer. Return
|
||||
** -1 if zDate does not begin with N digits.
|
||||
** Convert zDate into one or more integers. Additional arguments
|
||||
** come in groups of 5 as follows:
|
||||
**
|
||||
** N number of digits in the integer
|
||||
** min minimum allowed value of the integer
|
||||
** max maximum allowed value of the integer
|
||||
** nextC first character after the integer
|
||||
** pVal where to write the integers value.
|
||||
**
|
||||
** Conversions continue until one with nextC==0 is encountered.
|
||||
** The function returns the number of successful conversions.
|
||||
*/
|
||||
static int getDigits(const char *zDate, int N){
|
||||
int val = 0;
|
||||
while( N-- ){
|
||||
if( !isdigit(*zDate) ) return -1;
|
||||
val = val*10 + *zDate - '0';
|
||||
static int getDigits(const char *zDate, ...){
|
||||
va_list ap;
|
||||
int val;
|
||||
int N;
|
||||
int min;
|
||||
int max;
|
||||
int nextC;
|
||||
int *pVal;
|
||||
int cnt = 0;
|
||||
va_start(ap, zDate);
|
||||
do{
|
||||
N = va_arg(ap, int);
|
||||
min = va_arg(ap, int);
|
||||
max = va_arg(ap, int);
|
||||
nextC = va_arg(ap, int);
|
||||
pVal = va_arg(ap, int*);
|
||||
val = 0;
|
||||
while( N-- ){
|
||||
if( !isdigit(*(u8*)zDate) ){
|
||||
return cnt;
|
||||
}
|
||||
val = val*10 + *zDate - '0';
|
||||
zDate++;
|
||||
}
|
||||
if( val<min || val>max || (nextC!=0 && nextC!=*zDate) ){
|
||||
return cnt;
|
||||
}
|
||||
*pVal = val;
|
||||
zDate++;
|
||||
}
|
||||
return val;
|
||||
cnt++;
|
||||
}while( nextC );
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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){
|
||||
double r = 0.0;
|
||||
double rDivide = 1.0;
|
||||
int isNeg = 0;
|
||||
int nChar = 0;
|
||||
if( *z=='+' ){
|
||||
z++;
|
||||
nChar++;
|
||||
}else if( *z=='-' ){
|
||||
z++;
|
||||
isNeg = 1;
|
||||
nChar++;
|
||||
}
|
||||
if( !isdigit(*z) ) return 0;
|
||||
while( isdigit(*z) ){
|
||||
r = r*10.0 + *z - '0';
|
||||
nChar++;
|
||||
z++;
|
||||
}
|
||||
if( *z=='.' && isdigit(z[1]) ){
|
||||
z++;
|
||||
nChar++;
|
||||
while( isdigit(*z) ){
|
||||
r = r*10.0 + *z - '0';
|
||||
rDivide *= 10.0;
|
||||
nChar++;
|
||||
z++;
|
||||
}
|
||||
r /= rDivide;
|
||||
}
|
||||
if( *z!=0 && !isspace(*z) ) return 0;
|
||||
*pR = isNeg ? -r : r;
|
||||
return nChar;
|
||||
}
|
||||
#define getValue sqlite3AtoF
|
||||
|
||||
/*
|
||||
** Parse a timezone extension on the end of a date-time.
|
||||
@@ -139,7 +141,7 @@ static int getValue(const char *z, double *pR){
|
||||
static int parseTimezone(const char *zDate, DateTime *p){
|
||||
int sgn = 0;
|
||||
int nHr, nMn;
|
||||
while( isspace(*zDate) ){ zDate++; }
|
||||
while( isspace(*(u8*)zDate) ){ zDate++; }
|
||||
p->tz = 0;
|
||||
if( *zDate=='-' ){
|
||||
sgn = -1;
|
||||
@@ -149,16 +151,12 @@ static int parseTimezone(const char *zDate, DateTime *p){
|
||||
return *zDate!=0;
|
||||
}
|
||||
zDate++;
|
||||
nHr = getDigits(zDate, 2);
|
||||
if( nHr<0 || nHr>14 ) return 1;
|
||||
zDate += 2;
|
||||
if( zDate[0]!=':' ) return 1;
|
||||
zDate++;
|
||||
nMn = getDigits(zDate, 2);
|
||||
if( nMn<0 || nMn>59 ) return 1;
|
||||
zDate += 2;
|
||||
if( getDigits(zDate, 2, 0, 14, ':', &nHr, 2, 0, 59, 0, &nMn)!=2 ){
|
||||
return 1;
|
||||
}
|
||||
zDate += 5;
|
||||
p->tz = sgn*(nMn + nHr*60);
|
||||
while( isspace(*zDate) ){ zDate++; }
|
||||
while( isspace(*(u8*)zDate) ){ zDate++; }
|
||||
return *zDate!=0;
|
||||
}
|
||||
|
||||
@@ -172,20 +170,20 @@ static int parseTimezone(const char *zDate, DateTime *p){
|
||||
static int parseHhMmSs(const char *zDate, DateTime *p){
|
||||
int h, m, s;
|
||||
double ms = 0.0;
|
||||
h = getDigits(zDate, 2);
|
||||
if( h<0 || zDate[2]!=':' ) return 1;
|
||||
zDate += 3;
|
||||
m = getDigits(zDate, 2);
|
||||
if( m<0 || m>59 ) return 1;
|
||||
zDate += 2;
|
||||
if( getDigits(zDate, 2, 0, 24, ':', &h, 2, 0, 59, 0, &m)!=2 ){
|
||||
return 1;
|
||||
}
|
||||
zDate += 5;
|
||||
if( *zDate==':' ){
|
||||
s = getDigits(&zDate[1], 2);
|
||||
if( s<0 || s>59 ) return 1;
|
||||
zDate += 3;
|
||||
if( *zDate=='.' && isdigit(zDate[1]) ){
|
||||
zDate++;
|
||||
if( getDigits(zDate, 2, 0, 59, 0, &s)!=1 ){
|
||||
return 1;
|
||||
}
|
||||
zDate += 2;
|
||||
if( *zDate=='.' && isdigit((u8)zDate[1]) ){
|
||||
double rScale = 1.0;
|
||||
zDate++;
|
||||
while( isdigit(*zDate) ){
|
||||
while( isdigit(*(u8*)zDate) ){
|
||||
ms = ms*10.0 + *zDate - '0';
|
||||
rScale *= 10.0;
|
||||
zDate++;
|
||||
@@ -220,7 +218,7 @@ static void computeJD(DateTime *p){
|
||||
M = p->M;
|
||||
D = p->D;
|
||||
}else{
|
||||
Y = 2000;
|
||||
Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
|
||||
M = 1;
|
||||
D = 1;
|
||||
}
|
||||
@@ -258,20 +256,21 @@ static void computeJD(DateTime *p){
|
||||
** date.
|
||||
*/
|
||||
static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
||||
int Y, M, D;
|
||||
int Y, M, D, neg;
|
||||
|
||||
Y = getDigits(zDate, 4);
|
||||
if( Y<0 || zDate[4]!='-' ) return 1;
|
||||
zDate += 5;
|
||||
M = getDigits(zDate, 2);
|
||||
if( M<=0 || M>12 || zDate[2]!='-' ) return 1;
|
||||
zDate += 3;
|
||||
D = getDigits(zDate, 2);
|
||||
if( D<=0 || D>31 ) return 1;
|
||||
zDate += 2;
|
||||
while( isspace(*zDate) ){ zDate++; }
|
||||
if( isdigit(*zDate) ){
|
||||
if( parseHhMmSs(zDate, p) ) return 1;
|
||||
if( zDate[0]=='-' ){
|
||||
zDate++;
|
||||
neg = 1;
|
||||
}else{
|
||||
neg = 0;
|
||||
}
|
||||
if( getDigits(zDate,4,0,9999,'-',&Y,2,1,12,'-',&M,2,1,31,0,&D)!=3 ){
|
||||
return 1;
|
||||
}
|
||||
zDate += 10;
|
||||
while( isspace(*(u8*)zDate) || 'T'==*(u8*)zDate ){ zDate++; }
|
||||
if( parseHhMmSs(zDate, p)==0 ){
|
||||
/* We got the time */
|
||||
}else if( *zDate==0 ){
|
||||
p->validHMS = 0;
|
||||
}else{
|
||||
@@ -279,7 +278,7 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
||||
}
|
||||
p->validJD = 0;
|
||||
p->validYMD = 1;
|
||||
p->Y = Y;
|
||||
p->Y = neg ? -Y : Y;
|
||||
p->M = M;
|
||||
p->D = D;
|
||||
if( p->validTZ ){
|
||||
@@ -305,24 +304,19 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
||||
** as there is a year and date.
|
||||
*/
|
||||
static int parseDateOrTime(const char *zDate, DateTime *p){
|
||||
int i;
|
||||
memset(p, 0, sizeof(*p));
|
||||
for(i=0; isdigit(zDate[i]); i++){}
|
||||
if( i==4 && zDate[i]=='-' ){
|
||||
return parseYyyyMmDd(zDate, p);
|
||||
}else if( i==2 && zDate[i]==':' ){
|
||||
return parseHhMmSs(zDate, p);
|
||||
if( parseYyyyMmDd(zDate,p)==0 ){
|
||||
return 0;
|
||||
}else if( i==0 && sqliteStrICmp(zDate,"now")==0 ){
|
||||
}else if( parseHhMmSs(zDate, p)==0 ){
|
||||
return 0;
|
||||
}else if( sqlite3StrICmp(zDate,"now")==0){
|
||||
double r;
|
||||
if( sqliteOsCurrentTime(&r)==0 ){
|
||||
p->rJD = r;
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}else if( sqliteIsNumber(zDate) ){
|
||||
p->rJD = atof(zDate);
|
||||
sqlite3OsCurrentTime(&r);
|
||||
p->rJD = r;
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}else if( sqlite3IsNumber(zDate, 0, SQLITE_UTF8) ){
|
||||
getValue(zDate, &p->rJD);
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -335,17 +329,23 @@ static int parseDateOrTime(const char *zDate, DateTime *p){
|
||||
static void computeYMD(DateTime *p){
|
||||
int Z, A, B, C, D, E, X1;
|
||||
if( p->validYMD ) return;
|
||||
Z = p->rJD + 0.5;
|
||||
A = (Z - 1867216.25)/36524.25;
|
||||
A = Z + 1 + A - (A/4);
|
||||
B = A + 1524;
|
||||
C = (B - 122.1)/365.25;
|
||||
D = 365.25*C;
|
||||
E = (B-D)/30.6001;
|
||||
X1 = 30.6001*E;
|
||||
p->D = B - D - X1;
|
||||
p->M = E<14 ? E-1 : E-13;
|
||||
p->Y = p->M>2 ? C - 4716 : C - 4715;
|
||||
if( !p->validJD ){
|
||||
p->Y = 2000;
|
||||
p->M = 1;
|
||||
p->D = 1;
|
||||
}else{
|
||||
Z = p->rJD + 0.5;
|
||||
A = (Z - 1867216.25)/36524.25;
|
||||
A = Z + 1 + A - (A/4);
|
||||
B = A + 1524;
|
||||
C = (B - 122.1)/365.25;
|
||||
D = 365.25*C;
|
||||
E = (B-D)/30.6001;
|
||||
X1 = 30.6001*E;
|
||||
p->D = B - D - X1;
|
||||
p->M = E<14 ? E-1 : E-13;
|
||||
p->Y = p->M>2 ? C - 4716 : C - 4715;
|
||||
}
|
||||
p->validYMD = 1;
|
||||
}
|
||||
|
||||
@@ -367,6 +367,65 @@ static void computeHMS(DateTime *p){
|
||||
p->validHMS = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Compute both YMD and HMS
|
||||
*/
|
||||
static void computeYMD_HMS(DateTime *p){
|
||||
computeYMD(p);
|
||||
computeHMS(p);
|
||||
}
|
||||
|
||||
/*
|
||||
** Clear the YMD and HMS and the TZ
|
||||
*/
|
||||
static void clearYMD_HMS_TZ(DateTime *p){
|
||||
p->validYMD = 0;
|
||||
p->validHMS = 0;
|
||||
p->validTZ = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Compute the difference (in days) between localtime and UTC (a.k.a. GMT)
|
||||
** for the time value p where p is in UTC.
|
||||
*/
|
||||
static double localtimeOffset(DateTime *p){
|
||||
DateTime x, y;
|
||||
time_t t;
|
||||
struct tm *pTm;
|
||||
x = *p;
|
||||
computeYMD_HMS(&x);
|
||||
if( x.Y<1971 || x.Y>=2038 ){
|
||||
x.Y = 2000;
|
||||
x.M = 1;
|
||||
x.D = 1;
|
||||
x.h = 0;
|
||||
x.m = 0;
|
||||
x.s = 0.0;
|
||||
} else {
|
||||
int s = x.s + 0.5;
|
||||
x.s = s;
|
||||
}
|
||||
x.tz = 0;
|
||||
x.validJD = 0;
|
||||
computeJD(&x);
|
||||
t = (x.rJD-2440587.5)*86400.0 + 0.5;
|
||||
sqlite3OsEnterMutex();
|
||||
pTm = localtime(&t);
|
||||
y.Y = pTm->tm_year + 1900;
|
||||
y.M = pTm->tm_mon + 1;
|
||||
y.D = pTm->tm_mday;
|
||||
y.h = pTm->tm_hour;
|
||||
y.m = pTm->tm_min;
|
||||
y.s = pTm->tm_sec;
|
||||
sqlite3OsLeaveMutex();
|
||||
y.validYMD = 1;
|
||||
y.validHMS = 1;
|
||||
y.validJD = 0;
|
||||
y.validTZ = 0;
|
||||
computeJD(&y);
|
||||
return y.rJD - x.rJD;
|
||||
}
|
||||
|
||||
/*
|
||||
** Process a modifier to a date-time stamp. The modifiers are
|
||||
** as follows:
|
||||
@@ -383,6 +442,8 @@ static void computeHMS(DateTime *p){
|
||||
** start of day
|
||||
** weekday N
|
||||
** unixepoch
|
||||
** localtime
|
||||
** utc
|
||||
**
|
||||
** Return 0 on success and 1 if there is any kind of error.
|
||||
*/
|
||||
@@ -390,12 +451,27 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
int rc = 1;
|
||||
int n;
|
||||
double r;
|
||||
char z[30];
|
||||
for(n=0; n<sizeof(z)-1; n++){
|
||||
char *z, zBuf[30];
|
||||
z = zBuf;
|
||||
for(n=0; n<sizeof(zBuf)-1 && zMod[n]; n++){
|
||||
z[n] = tolower(zMod[n]);
|
||||
}
|
||||
z[n] = 0;
|
||||
switch( z[0] ){
|
||||
case 'l': {
|
||||
/* localtime
|
||||
**
|
||||
** Assuming the current time value is UTC (a.k.a. GMT), shift it to
|
||||
** show local time.
|
||||
*/
|
||||
if( strcmp(z, "localtime")==0 ){
|
||||
computeJD(p);
|
||||
p->rJD += localtimeOffset(p);
|
||||
clearYMD_HMS_TZ(p);
|
||||
rc = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
/*
|
||||
** unixepoch
|
||||
@@ -405,9 +481,15 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
*/
|
||||
if( strcmp(z, "unixepoch")==0 && p->validJD ){
|
||||
p->rJD = p->rJD/86400.0 + 2440587.5;
|
||||
p->validYMD = 0;
|
||||
p->validHMS = 0;
|
||||
p->validTZ = 0;
|
||||
clearYMD_HMS_TZ(p);
|
||||
rc = 0;
|
||||
}else if( strcmp(z, "utc")==0 ){
|
||||
double c1;
|
||||
computeJD(p);
|
||||
c1 = localtimeOffset(p);
|
||||
p->rJD -= c1;
|
||||
clearYMD_HMS_TZ(p);
|
||||
p->rJD += c1 - localtimeOffset(p);
|
||||
rc = 0;
|
||||
}
|
||||
break;
|
||||
@@ -416,16 +498,14 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
/*
|
||||
** weekday N
|
||||
**
|
||||
** Move the date to the beginning of the next occurrance of
|
||||
** Move the date to the same time on the next occurrence of
|
||||
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
|
||||
** date is already on the appropriate weekday, this is equivalent
|
||||
** to "start of day".
|
||||
** date is already on the appropriate weekday, this is a no-op.
|
||||
*/
|
||||
if( strncmp(z, "weekday ", 8)==0 && getValue(&z[8],&r)>0
|
||||
&& (n=r)==r && n>=0 && r<7 ){
|
||||
int Z;
|
||||
computeYMD(p);
|
||||
p->validHMS = 0;
|
||||
computeYMD_HMS(p);
|
||||
p->validTZ = 0;
|
||||
p->validJD = 0;
|
||||
computeJD(p);
|
||||
@@ -433,8 +513,7 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
Z %= 7;
|
||||
if( Z>n ) Z -= 7;
|
||||
p->rJD += n - Z;
|
||||
p->validYMD = 0;
|
||||
p->validHMS = 0;
|
||||
clearYMD_HMS_TZ(p);
|
||||
rc = 0;
|
||||
}
|
||||
break;
|
||||
@@ -447,22 +526,22 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
** or month or year.
|
||||
*/
|
||||
if( strncmp(z, "start of ", 9)!=0 ) break;
|
||||
zMod = &z[9];
|
||||
z += 9;
|
||||
computeYMD(p);
|
||||
p->validHMS = 1;
|
||||
p->h = p->m = 0;
|
||||
p->s = 0.0;
|
||||
p->validTZ = 0;
|
||||
p->validJD = 0;
|
||||
if( strcmp(zMod,"month")==0 ){
|
||||
if( strcmp(z,"month")==0 ){
|
||||
p->D = 1;
|
||||
rc = 0;
|
||||
}else if( strcmp(zMod,"year")==0 ){
|
||||
}else if( strcmp(z,"year")==0 ){
|
||||
computeYMD(p);
|
||||
p->M = 1;
|
||||
p->D = 1;
|
||||
rc = 0;
|
||||
}else if( strcmp(zMod,"day")==0 ){
|
||||
}else if( strcmp(z,"day")==0 ){
|
||||
rc = 0;
|
||||
}
|
||||
break;
|
||||
@@ -481,28 +560,47 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
case '9': {
|
||||
n = getValue(z, &r);
|
||||
if( n<=0 ) break;
|
||||
zMod = &z[n];
|
||||
while( isspace(zMod[0]) ) zMod++;
|
||||
n = strlen(zMod);
|
||||
if( z[n]==':' ){
|
||||
/* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
|
||||
** specified number of hours, minutes, seconds, and fractional seconds
|
||||
** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
|
||||
** omitted.
|
||||
*/
|
||||
const char *z2 = z;
|
||||
DateTime tx;
|
||||
int day;
|
||||
if( !isdigit(*(u8*)z2) ) z2++;
|
||||
memset(&tx, 0, sizeof(tx));
|
||||
if( parseHhMmSs(z2, &tx) ) break;
|
||||
computeJD(&tx);
|
||||
tx.rJD -= 0.5;
|
||||
day = (int)tx.rJD;
|
||||
tx.rJD -= day;
|
||||
if( z[0]=='-' ) tx.rJD = -tx.rJD;
|
||||
computeJD(p);
|
||||
clearYMD_HMS_TZ(p);
|
||||
p->rJD += tx.rJD;
|
||||
rc = 0;
|
||||
break;
|
||||
}
|
||||
z += n;
|
||||
while( isspace(*(u8*)z) ) z++;
|
||||
n = strlen(z);
|
||||
if( n>10 || n<3 ) break;
|
||||
strcpy(z, zMod);
|
||||
if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
|
||||
computeJD(p);
|
||||
rc = 0;
|
||||
if( n==3 && strcmp(z,"day")==0 ){
|
||||
p->rJD += r;
|
||||
}else if( n==4 && strcmp(z,"hour")==0 ){
|
||||
computeJD(p);
|
||||
p->rJD += r/24.0;
|
||||
}else if( n==6 && strcmp(z,"minute")==0 ){
|
||||
computeJD(p);
|
||||
p->rJD += r/(24.0*60.0);
|
||||
}else if( n==6 && strcmp(z,"second")==0 ){
|
||||
computeJD(p);
|
||||
p->rJD += r/(24.0*60.0*60.0);
|
||||
}else if( n==5 && strcmp(z,"month")==0 ){
|
||||
int x, y;
|
||||
computeYMD(p);
|
||||
computeYMD_HMS(p);
|
||||
p->M += r;
|
||||
x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
|
||||
p->Y += x;
|
||||
@@ -514,16 +612,14 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
p->rJD += (r - y)*30.0;
|
||||
}
|
||||
}else if( n==4 && strcmp(z,"year")==0 ){
|
||||
computeYMD(p);
|
||||
computeYMD_HMS(p);
|
||||
p->Y += r;
|
||||
p->validJD = 0;
|
||||
computeJD(p);
|
||||
}else{
|
||||
rc = 1;
|
||||
}
|
||||
p->validYMD = 0;
|
||||
p->validHMS = 0;
|
||||
p->validTZ = 0;
|
||||
clearYMD_HMS_TZ(p);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -539,12 +635,14 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
** the resulting time into the DateTime structure p. Return 0
|
||||
** on success and 1 if there are any errors.
|
||||
*/
|
||||
static int isDate(int argc, const char **argv, DateTime *p){
|
||||
static int isDate(int argc, sqlite3_value **argv, DateTime *p){
|
||||
int i;
|
||||
if( argc==0 ) return 1;
|
||||
if( parseDateOrTime(argv[0], p) ) return 1;
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[0]) ||
|
||||
parseDateOrTime(sqlite3_value_text(argv[0]), p) ) return 1;
|
||||
for(i=1; i<argc; i++){
|
||||
if( parseModifier(argv[i], p) ) return 1;
|
||||
if( SQLITE_NULL==sqlite3_value_type(argv[i]) ||
|
||||
parseModifier(sqlite3_value_text(argv[i]), p) ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -560,11 +658,15 @@ static int isDate(int argc, const char **argv, DateTime *p){
|
||||
**
|
||||
** Return the julian day number of the date specified in the arguments
|
||||
*/
|
||||
static void juliandayFunc(sqlite_func *context, int argc, const char **argv){
|
||||
static void juliandayFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(argc, argv, &x)==0 ){
|
||||
computeJD(&x);
|
||||
sqlite_set_result_double(context, x.rJD);
|
||||
sqlite3_result_double(context, x.rJD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,15 +675,18 @@ static void juliandayFunc(sqlite_func *context, int argc, const char **argv){
|
||||
**
|
||||
** Return YYYY-MM-DD HH:MM:SS
|
||||
*/
|
||||
static void datetimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
static void datetimeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(argc, argv, &x)==0 ){
|
||||
char zBuf[100];
|
||||
computeYMD(&x);
|
||||
computeHMS(&x);
|
||||
computeYMD_HMS(&x);
|
||||
sprintf(zBuf, "%04d-%02d-%02d %02d:%02d:%02d",x.Y, x.M, x.D, x.h, x.m,
|
||||
(int)(x.s));
|
||||
sqlite_set_result_string(context, zBuf, -1);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,13 +695,17 @@ static void datetimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
**
|
||||
** Return HH:MM:SS
|
||||
*/
|
||||
static void timeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
static void timeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(argc, argv, &x)==0 ){
|
||||
char zBuf[100];
|
||||
computeHMS(&x);
|
||||
sprintf(zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s);
|
||||
sqlite_set_result_string(context, zBuf, -1);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,13 +714,17 @@ static void timeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
**
|
||||
** Return YYYY-MM-DD
|
||||
*/
|
||||
static void dateFunc(sqlite_func *context, int argc, const char **argv){
|
||||
static void dateFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
DateTime x;
|
||||
if( isDate(argc, argv, &x)==0 ){
|
||||
char zBuf[100];
|
||||
computeYMD(&x);
|
||||
sprintf(zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D);
|
||||
sqlite_set_result_string(context, zBuf, -1);
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,13 +747,17 @@ static void dateFunc(sqlite_func *context, int argc, const char **argv){
|
||||
** %Y year 0000-9999
|
||||
** %% %
|
||||
*/
|
||||
static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
static void strftimeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
DateTime x;
|
||||
int n, i, j;
|
||||
char *z;
|
||||
const char *zFmt = argv[0];
|
||||
const char *zFmt = sqlite3_value_text(argv[0]);
|
||||
char zBuf[100];
|
||||
if( isDate(argc-1, argv+1, &x) ) return;
|
||||
if( zFmt==0 || isDate(argc-1, argv+1, &x) ) return;
|
||||
for(i=0, n=1; zFmt[i]; i++, n++){
|
||||
if( zFmt[i]=='%' ){
|
||||
switch( zFmt[i+1] ){
|
||||
@@ -681,8 +798,7 @@ static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
if( z==0 ) return;
|
||||
}
|
||||
computeJD(&x);
|
||||
computeYMD(&x);
|
||||
computeHMS(&x);
|
||||
computeYMD_HMS(&x);
|
||||
for(i=j=0; zFmt[i]; i++){
|
||||
if( zFmt[i]!='%' ){
|
||||
z[j++] = zFmt[i];
|
||||
@@ -700,18 +816,20 @@ static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
case 'H': sprintf(&z[j],"%02d",x.h); j+=2; break;
|
||||
case 'W': /* Fall thru */
|
||||
case 'j': {
|
||||
int n;
|
||||
int n; /* Number of days since 1st day of year */
|
||||
DateTime y = x;
|
||||
y.validJD = 0;
|
||||
y.M = 1;
|
||||
y.D = 1;
|
||||
computeJD(&y);
|
||||
n = x.rJD - y.rJD + 1;
|
||||
n = x.rJD - y.rJD;
|
||||
if( zFmt[i]=='W' ){
|
||||
sprintf(&z[j],"%02d",(n+6)/7);
|
||||
int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */
|
||||
wd = ((int)(x.rJD+0.5)) % 7;
|
||||
sprintf(&z[j],"%02d",(n+7-wd)/7);
|
||||
j += 2;
|
||||
}else{
|
||||
sprintf(&z[j],"%03d",n);
|
||||
sprintf(&z[j],"%03d",n+1);
|
||||
j += 3;
|
||||
}
|
||||
break;
|
||||
@@ -720,11 +838,11 @@ static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
case 'm': sprintf(&z[j],"%02d",x.M); j+=2; break;
|
||||
case 'M': sprintf(&z[j],"%02d",x.m); j+=2; break;
|
||||
case 's': {
|
||||
sprintf(&z[j],"%d",(int)((x.rJD-2440587.5)*86400.0));
|
||||
sprintf(&z[j],"%d",(int)((x.rJD-2440587.5)*86400.0 + 0.5));
|
||||
j += strlen(&z[j]);
|
||||
break;
|
||||
}
|
||||
case 'S': sprintf(&z[j],"%02d",(int)x.s); j+=2; break;
|
||||
case 'S': sprintf(&z[j],"%02d",(int)(x.s+0.5)); j+=2; break;
|
||||
case 'w': z[j++] = (((int)(x.rJD+1.5)) % 7) + '0'; break;
|
||||
case 'Y': sprintf(&z[j],"%04d",x.Y); j+=strlen(&z[j]); break;
|
||||
case '%': z[j++] = '%'; break;
|
||||
@@ -732,42 +850,147 @@ static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
}
|
||||
}
|
||||
z[j] = 0;
|
||||
sqlite_set_result_string(context, z, -1);
|
||||
sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
|
||||
if( z!=zBuf ){
|
||||
sqliteFree(z);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** 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 sqliteRegisterDateTimeFunctions(sqlite *db){
|
||||
static struct {
|
||||
void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
static const struct {
|
||||
char *zName;
|
||||
int nArg;
|
||||
int dataType;
|
||||
void (*xFunc)(sqlite_func*,int,const char**);
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
|
||||
} aFuncs[] = {
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
{ "julianday", -1, SQLITE_NUMERIC, juliandayFunc },
|
||||
{ "date", -1, SQLITE_TEXT, dateFunc },
|
||||
{ "time", 1, SQLITE_TEXT, timeFunc },
|
||||
{ "datetime", -1, SQLITE_TEXT, datetimeFunc },
|
||||
{ "strftime", -1, SQLITE_TEXT, strftimeFunc },
|
||||
#endif
|
||||
{ "julianday", -1, juliandayFunc },
|
||||
{ "date", -1, dateFunc },
|
||||
{ "time", -1, timeFunc },
|
||||
{ "datetime", -1, datetimeFunc },
|
||||
{ "strftime", -1, strftimeFunc },
|
||||
{ "current_time", 0, ctimeFunc },
|
||||
{ "current_timestamp", 0, ctimestampFunc },
|
||||
{ "current_date", 0, cdateFunc },
|
||||
};
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
|
||||
sqlite_create_function(db, aFuncs[i].zName,
|
||||
aFuncs[i].nArg, aFuncs[i].xFunc, 0);
|
||||
if( aFuncs[i].xFunc ){
|
||||
sqlite_function_type(db, aFuncs[i].zName, aFuncs[i].dataType);
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
+187
-138
@@ -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.57 2003/05/17 17:35:11 drh Exp $
|
||||
** $Id: delete.c,v 1.111 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -21,14 +21,17 @@
|
||||
** add an error message to pParse->zErrMsg and return NULL. If all tables
|
||||
** are found, return a pointer to the last table.
|
||||
*/
|
||||
Table *sqliteSrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
Table *pTab = 0;
|
||||
int i;
|
||||
for(i=0; i<pSrc->nSrc; i++){
|
||||
const char *zTab = pSrc->a[i].zName;
|
||||
const char *zDb = pSrc->a[i].zDatabase;
|
||||
pTab = sqliteLocateTable(pParse, zTab, zDb);
|
||||
pSrc->a[i].pTab = pTab;
|
||||
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,22 +41,44 @@ Table *sqliteSrcListLookup(Parse *pParse, SrcList *pSrc){
|
||||
** writable, generate an error message and return 1. If it is
|
||||
** writable return 0;
|
||||
*/
|
||||
int sqliteIsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
if( pTab->readOnly ){
|
||||
sqliteErrorMsg(pParse, "table %s may not be modified", pTab->zName);
|
||||
int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
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 ){
|
||||
sqliteErrorMsg(pParse, "cannot modify %s because it is a view",pTab->zName);
|
||||
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 sqliteDeleteFrom(
|
||||
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 */
|
||||
SrcList *pTabList, /* The table from which we should delete things */
|
||||
Expr *pWhere /* The WHERE clause. May be null */
|
||||
@@ -61,23 +86,23 @@ void sqliteDeleteFrom(
|
||||
Vdbe *v; /* The virtual database engine */
|
||||
Table *pTab; /* The table from which records will be deleted */
|
||||
const char *zDb; /* Name of database holding pTab */
|
||||
int end, addr; /* A couple addresses of generated code */
|
||||
int end, addr = 0; /* A couple addresses of generated code */
|
||||
int i; /* Loop counter */
|
||||
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 || sqlite_malloc_failed ){
|
||||
pTabList = 0;
|
||||
if( pParse->nErr || sqlite3_malloc_failed ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
db = pParse->db;
|
||||
@@ -88,232 +113,239 @@ void sqliteDeleteFrom(
|
||||
** will be calling are designed to work with multiple tables and expect
|
||||
** an SrcList* parameter instead of just a Table* parameter.
|
||||
*/
|
||||
pTab = sqliteSrcListLookup(pParse, pTabList);
|
||||
pTab = sqlite3SrcListLookup(pParse, pTabList);
|
||||
if( pTab==0 ) goto delete_from_cleanup;
|
||||
before_triggers = sqliteTriggersExist(pParse, pTab->pTrigger,
|
||||
TK_DELETE, TK_BEFORE, TK_ROW, 0);
|
||||
after_triggers = sqliteTriggersExist(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( sqliteIsReadOnly(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 );
|
||||
zDb = db->aDb[pTab->iDb].zName;
|
||||
if( sqliteAuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
|
||||
/* If pTab is really a view, make sure it has been initialized.
|
||||
*/
|
||||
if( isView && sqliteViewGetColumnNames(pParse, pTab) ){
|
||||
if( isView && sqlite3ViewGetColumnNames(pParse, pTab) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
|
||||
/* 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( pWhere ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, 0, pWhere) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pParse;
|
||||
sNC.pSrcList = pTabList;
|
||||
if( sqlite3ExprResolveNames(&sNC, pWhere) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
|
||||
/* Start the view context
|
||||
*/
|
||||
if( isView ){
|
||||
sqliteAuthContextPush(pParse, &sContext, pTab->zName);
|
||||
sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
|
||||
}
|
||||
|
||||
/* Begin generating code.
|
||||
*/
|
||||
v = sqliteGetVdbe(pParse);
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
sqliteBeginWriteOperation(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 = sqliteSelectDup(pTab->pSelect);
|
||||
sqliteSelect(pParse, pView, SRT_TempTable, iCur, 0, 0, 0);
|
||||
sqliteSelectDelete(pView);
|
||||
Select *pView = sqlite3SelectDup(pTab->pSelect);
|
||||
sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(pView);
|
||||
}
|
||||
|
||||
/* Initialize the counter of the number of rows deleted, if
|
||||
** we are counting rows.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
}
|
||||
|
||||
/* Special case: A DELETE without a WHERE clause deletes everything.
|
||||
** 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 = sqliteVdbeMakeLabel(v);
|
||||
int endOfLoop = sqlite3VdbeMakeLabel(v);
|
||||
int addr;
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Rewind, iCur, sqliteVdbeCurrentAddr(v)+2);
|
||||
addr = sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Next, iCur, addr);
|
||||
sqliteVdbeResolveLabel(v, endOfLoop);
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rewind, iCur, sqlite3VdbeCurrentAddr(v)+2);
|
||||
addr = sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Next, iCur, addr);
|
||||
sqlite3VdbeResolveLabel(v, endOfLoop);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Clear, pTab->tnum, pTab->iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pTab->tnum, pTab->iDb);
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
sqliteVdbeAddOp(v, OP_Clear, pIdx->tnum, pIdx->iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Clear, pIdx->tnum, pIdx->iDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The usual case: There is a WHERE clause so we have to scan through
|
||||
** the table an pick which records to delete.
|
||||
** the table and pick which records to delete.
|
||||
*/
|
||||
else{
|
||||
/* Ensure all required collation sequences are available. */
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Begin the database scan
|
||||
*/
|
||||
pWInfo = sqliteWhereBegin(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.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0);
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
}
|
||||
|
||||
/* End the database scan loop.
|
||||
*/
|
||||
sqliteWhereEnd(pWInfo);
|
||||
sqlite3WhereEnd(pWInfo);
|
||||
|
||||
/* Open the pseudo-table used to store OLD if there are triggers.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
if( triggers_exist ){
|
||||
sqlite3VdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, oldIdx, pTab->nCol);
|
||||
}
|
||||
|
||||
/* Delete every item whose key was written to the list during the
|
||||
** database scan. We have to delete items after the scan is complete
|
||||
** because deleting an item can change the scan order.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
end = sqliteVdbeMakeLabel(v);
|
||||
end = sqlite3VdbeMakeLabel(v);
|
||||
|
||||
/* This is the beginning of the delete loop when there are
|
||||
** row triggers.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
if( triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end);
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
sqlite3OpenTableForReading(v, iCur, pTab);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
|
||||
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0);
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
|
||||
sqliteCodeRowTrigger(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.
|
||||
*/
|
||||
pParse->nTab = iCur + 1;
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum);
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenWrite, pParse->nTab++, pIdx->tnum);
|
||||
}
|
||||
sqlite3OpenTableAndIndices(pParse, pTab, iCur, OP_OpenWrite);
|
||||
|
||||
/* This is the beginning of the delete loop when there are no
|
||||
** row triggers */
|
||||
if( !row_triggers_exist ){
|
||||
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
|
||||
if( !triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end);
|
||||
}
|
||||
|
||||
/* Delete the row */
|
||||
sqliteGenerateRowDelete(db, v, pTab, iCur, pParse->trigStack==0);
|
||||
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){
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
sqliteCodeRowTrigger(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 */
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqliteVdbeResolveLabel(v, end);
|
||||
sqliteVdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqlite3VdbeResolveLabel(v, end);
|
||||
|
||||
/* 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){
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
pParse->nTab = iCur;
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
}
|
||||
sqliteEndWriteOperation(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 ){
|
||||
sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
|
||||
sqliteVdbeChangeP3(v, -1, "rows deleted", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
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);
|
||||
}
|
||||
|
||||
delete_from_cleanup:
|
||||
sqliteAuthContextPop(&sContext);
|
||||
sqliteSrcListDelete(pTabList);
|
||||
sqliteExprDelete(pWhere);
|
||||
sqlite3AuthContextPop(&sContext);
|
||||
sqlite3SrcListDelete(pTabList);
|
||||
sqlite3ExprDelete(pWhere);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -337,18 +369,18 @@ delete_from_cleanup:
|
||||
** and then generates code to remove both the table record and all index
|
||||
** entries that point to that record.
|
||||
*/
|
||||
void sqliteGenerateRowDelete(
|
||||
sqlite *db, /* The database containing the index */
|
||||
void sqlite3GenerateRowDelete(
|
||||
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 */
|
||||
int count /* Increment the row change counter */
|
||||
){
|
||||
int addr;
|
||||
addr = sqliteVdbeAddOp(v, OP_NotExists, iCur, 0);
|
||||
sqliteGenerateRowIndexDelete(db, v, pTab, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_Delete, iCur, count);
|
||||
sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
|
||||
addr = sqlite3VdbeAddOp(v, OP_NotExists, iCur, 0);
|
||||
sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
|
||||
sqlite3VdbeJumpHere(v, addr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -367,8 +399,8 @@ void sqliteGenerateRowDelete(
|
||||
** 3. The "iCur" cursor must be pointing to the row that is to be
|
||||
** deleted.
|
||||
*/
|
||||
void sqliteGenerateRowIndexDelete(
|
||||
sqlite *db, /* The database containing the index */
|
||||
void sqlite3GenerateRowIndexDelete(
|
||||
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 */
|
||||
@@ -378,19 +410,36 @@ void sqliteGenerateRowIndexDelete(
|
||||
Index *pIdx;
|
||||
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
int j;
|
||||
if( aIdxUsed!=0 && aIdxUsed[i-1]==0 ) continue;
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
for(j=0; j<pIdx->nColumn; j++){
|
||||
int idx = pIdx->aiColumn[j];
|
||||
if( idx==pTab->iPKey ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, j, 0);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_Column, iCur, idx);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
|
||||
if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
|
||||
sqliteVdbeAddOp(v, OP_IdxDelete, iCur+i, 0);
|
||||
sqlite3GenerateIndexKey(v, pIdx, iCur);
|
||||
sqlite3VdbeAddOp(v, OP_IdxDelete, iCur+i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code that will assemble an index key and put it on the top
|
||||
** of the tack. The key with be for index pIdx which is an index on pTab.
|
||||
** iCur is the index of a cursor open on the pTab table and pointing to
|
||||
** the entry that needs indexing.
|
||||
*/
|
||||
void sqlite3GenerateIndexKey(
|
||||
Vdbe *v, /* Generate code into this VDBE */
|
||||
Index *pIdx, /* The index for which to generate a key */
|
||||
int iCur /* Cursor number for the pIdx->pTable table */
|
||||
){
|
||||
int j;
|
||||
Table *pTab = pIdx->pTable;
|
||||
|
||||
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_MakeIdxRec, pIdx->nColumn, 0);
|
||||
sqlite3IndexAffinityStr(v, pIdx);
|
||||
}
|
||||
|
||||
-245
@@ -1,245 +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.9 2003/06/28 16:25:34 drh Exp $
|
||||
*/
|
||||
#include <string.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 0x03. 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 0x03
|
||||
**
|
||||
** 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 0x03 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.
|
||||
*/
|
||||
int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
|
||||
int i, j, e, m;
|
||||
int cnt[256];
|
||||
if( n<=0 ){
|
||||
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;
|
||||
}
|
||||
}
|
||||
out[0] = e;
|
||||
j = 1;
|
||||
for(i=0; i<n; i++){
|
||||
int c = (in[i] - e)&0xff;
|
||||
if( c==0 ){
|
||||
out[j++] = 1;
|
||||
out[j++] = 1;
|
||||
}else if( c==1 ){
|
||||
out[j++] = 1;
|
||||
out[j++] = 2;
|
||||
}else if( c=='\'' ){
|
||||
out[j++] = 1;
|
||||
out[j++] = 3;
|
||||
}else{
|
||||
out[j++] = c;
|
||||
}
|
||||
}
|
||||
out[j] = 0;
|
||||
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, c, e;
|
||||
e = *(in++);
|
||||
i = 0;
|
||||
while( (c = *(in++))!=0 ){
|
||||
if( c==1 ){
|
||||
c = *(in++);
|
||||
if( c==1 ){
|
||||
c = 0;
|
||||
}else if( c==2 ){
|
||||
c = 1;
|
||||
}else if( c==3 ){
|
||||
c = '\'';
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
out[i++] = (c + e)&0xff;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
#ifdef ENCODER_TEST
|
||||
/*
|
||||
** 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;
|
||||
unsigned char in[30000];
|
||||
unsigned char out[33000];
|
||||
|
||||
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;
|
||||
}
|
||||
nOut = sqlite_encode_binary(in, n, out);
|
||||
if( nOut!=strlen(out) ){
|
||||
printf(" ERROR return value is %d instead of %d\n", nOut, strlen(out));
|
||||
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");
|
||||
}
|
||||
}
|
||||
#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);
|
||||
}
|
||||
+1715
-1092
File diff suppressed because it is too large
Load Diff
+803
-302
File diff suppressed because it is too large
Load Diff
+94
-61
@@ -12,7 +12,7 @@
|
||||
** This is the implementation of generic hash-tables
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.c,v 1.10 2003/05/12 23:06:53 drh Exp $
|
||||
** $Id: hash.c,v 1.16 2005/01/31 12:56:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <assert.h>
|
||||
@@ -20,7 +20,7 @@
|
||||
/* Turn bulk memory into a hash table object by initializing the
|
||||
** fields of the Hash structure.
|
||||
**
|
||||
** "new" is a pointer to the hash table that is to be initialized.
|
||||
** "pNew" is a pointer to the hash table that is to be initialized.
|
||||
** keyClass is one of the constants SQLITE_HASH_INT, SQLITE_HASH_POINTER,
|
||||
** SQLITE_HASH_BINARY, or SQLITE_HASH_STRING. The value of keyClass
|
||||
** determines what kind of key the hash table will use. "copyKey" is
|
||||
@@ -29,23 +29,25 @@
|
||||
** sense for SQLITE_HASH_STRING and SQLITE_HASH_BINARY and is ignored
|
||||
** for other key classes.
|
||||
*/
|
||||
void sqliteHashInit(Hash *new, int keyClass, int copyKey){
|
||||
assert( new!=0 );
|
||||
assert( keyClass>=SQLITE_HASH_INT && keyClass<=SQLITE_HASH_BINARY );
|
||||
new->keyClass = keyClass;
|
||||
new->copyKey = copyKey &&
|
||||
(keyClass==SQLITE_HASH_STRING || keyClass==SQLITE_HASH_BINARY);
|
||||
new->first = 0;
|
||||
new->count = 0;
|
||||
new->htsize = 0;
|
||||
new->ht = 0;
|
||||
void sqlite3HashInit(Hash *pNew, int keyClass, int copyKey){
|
||||
assert( pNew!=0 );
|
||||
assert( keyClass>=SQLITE_HASH_STRING && keyClass<=SQLITE_HASH_BINARY );
|
||||
pNew->keyClass = keyClass;
|
||||
#if 0
|
||||
if( keyClass==SQLITE_HASH_POINTER || keyClass==SQLITE_HASH_INT ) copyKey = 0;
|
||||
#endif
|
||||
pNew->copyKey = copyKey;
|
||||
pNew->first = 0;
|
||||
pNew->count = 0;
|
||||
pNew->htsize = 0;
|
||||
pNew->ht = 0;
|
||||
}
|
||||
|
||||
/* Remove all entries from a hash table. Reclaim all memory.
|
||||
** Call this routine to delete a hash table or to reset a hash table
|
||||
** to the empty state.
|
||||
*/
|
||||
void sqliteHashClear(Hash *pH){
|
||||
void sqlite3HashClear(Hash *pH){
|
||||
HashElem *elem; /* For looping over all elements of the table */
|
||||
|
||||
assert( pH!=0 );
|
||||
@@ -65,6 +67,7 @@ void sqliteHashClear(Hash *pH){
|
||||
pH->count = 0;
|
||||
}
|
||||
|
||||
#if 0 /* NOT USED */
|
||||
/*
|
||||
** Hash and comparison functions when the mode is SQLITE_HASH_INT
|
||||
*/
|
||||
@@ -74,7 +77,9 @@ static int intHash(const void *pKey, int nKey){
|
||||
static int intCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
return n2 - n1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 /* NOT USED */
|
||||
/*
|
||||
** Hash and comparison functions when the mode is SQLITE_HASH_POINTER
|
||||
*/
|
||||
@@ -87,16 +92,24 @@ static int ptrCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
if( pKey1<pKey2 ) return -1;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Hash and comparison functions when the mode is SQLITE_HASH_STRING
|
||||
*/
|
||||
static int strHash(const void *pKey, int nKey){
|
||||
return sqliteHashNoCase((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 n2-n1;
|
||||
return sqliteStrNICmp((const char*)pKey1,(const char*)pKey2,n1);
|
||||
if( n1!=n2 ) return 1;
|
||||
return sqlite3StrNICmp((const char*)pKey1,(const char*)pKey2,n1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -111,7 +124,7 @@ static int binHash(const void *pKey, int nKey){
|
||||
return h & 0x7fffffff;
|
||||
}
|
||||
static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
if( n1!=n2 ) return n2-n1;
|
||||
if( n1!=n2 ) return 1;
|
||||
return memcmp(pKey1,pKey2,n1);
|
||||
}
|
||||
|
||||
@@ -128,6 +141,7 @@ static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
** with types "const void*" and "int" and returns an "int".
|
||||
*/
|
||||
static int (*hashFunction(int keyClass))(const void*,int){
|
||||
#if 0 /* HASH_INT and HASH_POINTER are never used */
|
||||
switch( keyClass ){
|
||||
case SQLITE_HASH_INT: return &intHash;
|
||||
case SQLITE_HASH_POINTER: return &ptrHash;
|
||||
@@ -136,6 +150,14 @@ static int (*hashFunction(int keyClass))(const void*,int){
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
if( keyClass==SQLITE_HASH_STRING ){
|
||||
return &strHash;
|
||||
}else{
|
||||
assert( keyClass==SQLITE_HASH_BINARY );
|
||||
return &binHash;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -145,6 +167,7 @@ static int (*hashFunction(int keyClass))(const void*,int){
|
||||
** see the header comment on the previous function.
|
||||
*/
|
||||
static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
|
||||
#if 0 /* HASH_INT and HASH_POINTER are never used */
|
||||
switch( keyClass ){
|
||||
case SQLITE_HASH_INT: return &intCompare;
|
||||
case SQLITE_HASH_POINTER: return &ptrCompare;
|
||||
@@ -153,6 +176,39 @@ static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
if( keyClass==SQLITE_HASH_STRING ){
|
||||
return &strCompare;
|
||||
}else{
|
||||
assert( keyClass==SQLITE_HASH_BINARY );
|
||||
return &binCompare;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Link an element into the hash table
|
||||
*/
|
||||
static void insertElement(
|
||||
Hash *pH, /* The complete hash table */
|
||||
struct _ht *pEntry, /* The entry into which pNew is inserted */
|
||||
HashElem *pNew /* The element to be inserted */
|
||||
){
|
||||
HashElem *pHead; /* First element already in pEntry */
|
||||
pHead = pEntry->chain;
|
||||
if( pHead ){
|
||||
pNew->next = pHead;
|
||||
pNew->prev = pHead->prev;
|
||||
if( pHead->prev ){ pHead->prev->next = pNew; }
|
||||
else { pH->first = pNew; }
|
||||
pHead->prev = pNew;
|
||||
}else{
|
||||
pNew->next = pH->first;
|
||||
if( pH->first ){ pH->first->prev = pNew; }
|
||||
pNew->prev = 0;
|
||||
pH->first = pNew;
|
||||
}
|
||||
pEntry->count++;
|
||||
pEntry->chain = pNew;
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +219,6 @@ static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
|
||||
static void rehash(Hash *pH, int new_size){
|
||||
struct _ht *new_ht; /* The new hash table */
|
||||
HashElem *elem, *next_elem; /* For looping over existing elements */
|
||||
HashElem *x; /* Element being copied to new hash table */
|
||||
int (*xHash)(const void*,int); /* The hash function */
|
||||
|
||||
assert( (new_size & (new_size-1))==0 );
|
||||
@@ -176,21 +231,7 @@ static void rehash(Hash *pH, int new_size){
|
||||
for(elem=pH->first, pH->first=0; elem; elem = next_elem){
|
||||
int h = (*xHash)(elem->pKey, elem->nKey) & (new_size-1);
|
||||
next_elem = elem->next;
|
||||
x = new_ht[h].chain;
|
||||
if( x ){
|
||||
elem->next = x;
|
||||
elem->prev = x->prev;
|
||||
if( x->prev ) x->prev->next = elem;
|
||||
else pH->first = elem;
|
||||
x->prev = elem;
|
||||
}else{
|
||||
elem->next = pH->first;
|
||||
if( pH->first ) pH->first->prev = elem;
|
||||
elem->prev = 0;
|
||||
pH->first = elem;
|
||||
}
|
||||
new_ht[h].chain = elem;
|
||||
new_ht[h].count++;
|
||||
insertElement(pH, &new_ht[h], elem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,8 +250,9 @@ static HashElem *findElementGivenHash(
|
||||
int (*xCompare)(const void*,int,const void*,int); /* comparison function */
|
||||
|
||||
if( pH->ht ){
|
||||
elem = pH->ht[h].chain;
|
||||
count = pH->ht[h].count;
|
||||
struct _ht *pEntry = &pH->ht[h];
|
||||
elem = pEntry->chain;
|
||||
count = pEntry->count;
|
||||
xCompare = compareFunction(pH->keyClass);
|
||||
while( count-- && elem ){
|
||||
if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){
|
||||
@@ -230,6 +272,7 @@ static void removeElementGivenHash(
|
||||
HashElem* elem, /* The element to be removed from the pH */
|
||||
int h /* Hash value for the element */
|
||||
){
|
||||
struct _ht *pEntry;
|
||||
if( elem->prev ){
|
||||
elem->prev->next = elem->next;
|
||||
}else{
|
||||
@@ -238,12 +281,13 @@ static void removeElementGivenHash(
|
||||
if( elem->next ){
|
||||
elem->next->prev = elem->prev;
|
||||
}
|
||||
if( pH->ht[h].chain==elem ){
|
||||
pH->ht[h].chain = elem->next;
|
||||
pEntry = &pH->ht[h];
|
||||
if( pEntry->chain==elem ){
|
||||
pEntry->chain = elem->next;
|
||||
}
|
||||
pH->ht[h].count--;
|
||||
if( pH->ht[h].count<=0 ){
|
||||
pH->ht[h].chain = 0;
|
||||
pEntry->count--;
|
||||
if( pEntry->count<=0 ){
|
||||
pEntry->chain = 0;
|
||||
}
|
||||
if( pH->copyKey && elem->pKey ){
|
||||
sqliteFree(elem->pKey);
|
||||
@@ -256,7 +300,7 @@ static void removeElementGivenHash(
|
||||
** that matches pKey,nKey. Return the data for this element if it is
|
||||
** found, or NULL if there is no match.
|
||||
*/
|
||||
void *sqliteHashFind(const Hash *pH, const void *pKey, int nKey){
|
||||
void *sqlite3HashFind(const Hash *pH, const void *pKey, int nKey){
|
||||
int h; /* A hash on key */
|
||||
HashElem *elem; /* The element that matches key */
|
||||
int (*xHash)(const void*,int); /* The hash function */
|
||||
@@ -285,7 +329,7 @@ void *sqliteHashFind(const Hash *pH, const void *pKey, int nKey){
|
||||
** If the "data" parameter to this function is NULL, then the
|
||||
** element corresponding to "key" is removed from the hash table.
|
||||
*/
|
||||
void *sqliteHashInsert(Hash *pH, const void *pKey, int nKey, void *data){
|
||||
void *sqlite3HashInsert(Hash *pH, const void *pKey, int nKey, void *data){
|
||||
int hraw; /* Raw hash value of the key */
|
||||
int h; /* the hash of the key modulo hash table size */
|
||||
HashElem *elem; /* Used to loop thru the element list */
|
||||
@@ -323,32 +367,21 @@ void *sqliteHashInsert(Hash *pH, const void *pKey, int nKey, void *data){
|
||||
}
|
||||
new_elem->nKey = nKey;
|
||||
pH->count++;
|
||||
if( pH->htsize==0 ) rehash(pH,8);
|
||||
if( pH->htsize==0 ){
|
||||
pH->count = 0;
|
||||
sqliteFree(new_elem);
|
||||
return data;
|
||||
rehash(pH,8);
|
||||
if( pH->htsize==0 ){
|
||||
pH->count = 0;
|
||||
sqliteFree(new_elem);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
if( pH->count > pH->htsize ){
|
||||
rehash(pH,pH->htsize*2);
|
||||
}
|
||||
assert( pH->htsize>0 );
|
||||
assert( (pH->htsize & (pH->htsize-1))==0 );
|
||||
h = hraw & (pH->htsize-1);
|
||||
elem = pH->ht[h].chain;
|
||||
if( elem ){
|
||||
new_elem->next = elem;
|
||||
new_elem->prev = elem->prev;
|
||||
if( elem->prev ){ elem->prev->next = new_elem; }
|
||||
else { pH->first = new_elem; }
|
||||
elem->prev = new_elem;
|
||||
}else{
|
||||
new_elem->next = pH->first;
|
||||
new_elem->prev = 0;
|
||||
if( pH->first ){ pH->first->prev = new_elem; }
|
||||
pH->first = new_elem;
|
||||
}
|
||||
pH->ht[h].count++;
|
||||
pH->ht[h].chain = new_elem;
|
||||
insertElement(pH, &pH->ht[h], new_elem);
|
||||
new_elem->data = data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-7
@@ -12,7 +12,7 @@
|
||||
** This is the header file for the generic hash-table implemenation
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.h,v 1.5 2002/06/08 23:25:09 drh Exp $
|
||||
** $Id: hash.h,v 1.8 2004/08/20 14:08:51 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_HASH_H_
|
||||
#define _SQLITE_HASH_H_
|
||||
@@ -70,18 +70,18 @@ struct HashElem {
|
||||
** A copy of the key is made for SQLITE_HASH_STRING and SQLITE_HASH_BINARY
|
||||
** if the copyKey parameter to HashInit is 1.
|
||||
*/
|
||||
#define SQLITE_HASH_INT 1
|
||||
#define SQLITE_HASH_POINTER 2
|
||||
/* #define SQLITE_HASH_INT 1 // NOT USED */
|
||||
/* #define SQLITE_HASH_POINTER 2 // NOT USED */
|
||||
#define SQLITE_HASH_STRING 3
|
||||
#define SQLITE_HASH_BINARY 4
|
||||
|
||||
/*
|
||||
** Access routines. To delete, insert a NULL pointer.
|
||||
*/
|
||||
void sqliteHashInit(Hash*, int keytype, int copyKey);
|
||||
void *sqliteHashInsert(Hash*, const void *pKey, int nKey, void *pData);
|
||||
void *sqliteHashFind(const Hash*, const void *pKey, int nKey);
|
||||
void sqliteHashClear(Hash*);
|
||||
void sqlite3HashInit(Hash*, int keytype, int copyKey);
|
||||
void *sqlite3HashInsert(Hash*, const void *pKey, int nKey, void *pData);
|
||||
void *sqlite3HashFind(const Hash*, const void *pKey, int nKey);
|
||||
void sqlite3HashClear(Hash*);
|
||||
|
||||
/*
|
||||
** Macros for looping over all elements of a hash table. The idiom is
|
||||
|
||||
+442
-248
File diff suppressed because it is too large
Load Diff
+138
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
** Main file for the SQLite library. The routines in this file
|
||||
** implement the programmer interface to the library. Routines in
|
||||
** other files are for internal use by SQLite and should not be
|
||||
** accessed by users of the library.
|
||||
**
|
||||
** $Id: legacy.c,v 1.7 2004/09/06 17:34:13 drh Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
** Execute SQL code. Return one of the SQLITE_ success/failure
|
||||
** codes. Also write an error message into memory obtained from
|
||||
** malloc() and make *pzErrMsg point to that message.
|
||||
**
|
||||
** If the SQL is a query, then for each row in the query result
|
||||
** the xCallback() function is called. pArg becomes the first
|
||||
** argument to xCallback(). If xCallback=NULL then no callback
|
||||
** is invoked, even for queries.
|
||||
*/
|
||||
int sqlite3_exec(
|
||||
sqlite3 *db, /* The database on which the SQL executes */
|
||||
const char *zSql, /* The SQL to be executed */
|
||||
sqlite3_callback xCallback, /* Invoke this callback routine */
|
||||
void *pArg, /* First argument to xCallback() */
|
||||
char **pzErrMsg /* Write error messages here */
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
const char *zLeftover;
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
char **azCols = 0;
|
||||
|
||||
int nRetry = 0;
|
||||
int nChange = 0;
|
||||
int nCallback;
|
||||
|
||||
if( zSql==0 ) return SQLITE_OK;
|
||||
while( (rc==SQLITE_OK || (rc==SQLITE_SCHEMA && (++nRetry)<2)) && zSql[0] ){
|
||||
int nCol;
|
||||
char **azVals = 0;
|
||||
|
||||
pStmt = 0;
|
||||
rc = sqlite3_prepare(db, zSql, -1, &pStmt, &zLeftover);
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( pStmt ) sqlite3_finalize(pStmt);
|
||||
continue;
|
||||
}
|
||||
if( !pStmt ){
|
||||
/* this happens for a comment or white-space */
|
||||
zSql = zLeftover;
|
||||
continue;
|
||||
}
|
||||
|
||||
db->nChange += nChange;
|
||||
nCallback = 0;
|
||||
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
azCols = sqliteMalloc(2*nCol*sizeof(const char *));
|
||||
if( nCol && !azCols ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto exec_out;
|
||||
}
|
||||
|
||||
while( 1 ){
|
||||
int i;
|
||||
rc = sqlite3_step(pStmt);
|
||||
|
||||
/* Invoke the callback function if required */
|
||||
if( xCallback && (SQLITE_ROW==rc ||
|
||||
(SQLITE_DONE==rc && !nCallback && db->flags&SQLITE_NullCallback)) ){
|
||||
if( 0==nCallback ){
|
||||
for(i=0; i<nCol; i++){
|
||||
azCols[i] = (char *)sqlite3_column_name(pStmt, i);
|
||||
}
|
||||
nCallback++;
|
||||
}
|
||||
if( rc==SQLITE_ROW ){
|
||||
azVals = &azCols[nCol];
|
||||
for(i=0; i<nCol; i++){
|
||||
azVals[i] = (char *)sqlite3_column_text(pStmt, i);
|
||||
}
|
||||
}
|
||||
if( xCallback(pArg, nCol, azVals, azCols) ){
|
||||
rc = SQLITE_ABORT;
|
||||
goto exec_out;
|
||||
}
|
||||
}
|
||||
|
||||
if( rc!=SQLITE_ROW ){
|
||||
rc = sqlite3_finalize(pStmt);
|
||||
pStmt = 0;
|
||||
if( db->pVdbe==0 ){
|
||||
nChange = db->nChange;
|
||||
}
|
||||
if( rc!=SQLITE_SCHEMA ){
|
||||
nRetry = 0;
|
||||
zSql = zLeftover;
|
||||
while( isspace((unsigned char)zSql[0]) ) zSql++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sqliteFree(azCols);
|
||||
azCols = 0;
|
||||
}
|
||||
|
||||
exec_out:
|
||||
if( pStmt ) sqlite3_finalize(pStmt);
|
||||
if( azCols ) sqliteFree(azCols);
|
||||
|
||||
if( sqlite3_malloc_failed ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
|
||||
*pzErrMsg = malloc(1+strlen(sqlite3_errmsg(db)));
|
||||
if( *pzErrMsg ){
|
||||
strcpy(*pzErrMsg, sqlite3_errmsg(db));
|
||||
}
|
||||
}else if( pzErrMsg ){
|
||||
*pzErrMsg = 0;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
+824
-801
File diff suppressed because it is too large
Load Diff
@@ -30,7 +30,7 @@
|
||||
*/
|
||||
#include <tcl.h>
|
||||
#include <string.h>
|
||||
#include "sqlite.h"
|
||||
#include "sqlite3.h"
|
||||
|
||||
/*
|
||||
* If compiled on a machine that doesn't have a 32-bit integer,
|
||||
@@ -356,30 +356,32 @@ int Md5_Init(Tcl_Interp *interp){
|
||||
** During testing, the special md5sum() aggregate function is available.
|
||||
** inside SQLite. The following routines implement that function.
|
||||
*/
|
||||
static void md5step(sqlite_func *context, int argc, const char **argv){
|
||||
static void md5step(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
MD5Context *p;
|
||||
int i;
|
||||
if( argc<1 ) return;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
if( p==0 ) return;
|
||||
if( sqlite_aggregate_count(context)==1 ){
|
||||
if( sqlite3_aggregate_count(context)==1 ){
|
||||
MD5Init(p);
|
||||
}
|
||||
for(i=0; i<argc; i++){
|
||||
if( argv[i] ){
|
||||
MD5Update(p, (unsigned char*)argv[i], strlen(argv[i]));
|
||||
const char *zData = sqlite3_value_text(argv[i]);
|
||||
if( zData ){
|
||||
MD5Update(p, zData, strlen(zData));
|
||||
}
|
||||
}
|
||||
}
|
||||
static void md5finalize(sqlite_func *context){
|
||||
static void md5finalize(sqlite3_context *context){
|
||||
MD5Context *p;
|
||||
unsigned char digest[16];
|
||||
char zBuf[33];
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
MD5Final(digest,p);
|
||||
DigestToBase16(digest, zBuf);
|
||||
sqlite_set_result_string(context, zBuf, strlen(zBuf));
|
||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
void Md5_Register(sqlite *db){
|
||||
sqlite_create_aggregate(db, "md5sum", -1, md5step, md5finalize, 0);
|
||||
void Md5_Register(sqlite3 *db){
|
||||
sqlite3_create_function(db, "md5sum", -1, SQLITE_UTF8, 0, 0,
|
||||
md5step, md5finalize);
|
||||
}
|
||||
|
||||
@@ -18,29 +18,56 @@
|
||||
#define _SQLITE_OS_H_
|
||||
|
||||
/*
|
||||
** Helpful hint: To get this to compile on HP/UX, add -D_INCLUDE_POSIX_SOURCE
|
||||
** to the compiler command line.
|
||||
** Figure out if we are dealing with Unix, Windows or MacOS.
|
||||
**
|
||||
** 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) && !defined(OS_OTHER)
|
||||
# define OS_OTHER 0
|
||||
# ifndef OS_WIN
|
||||
# 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_UNIX 0
|
||||
# endif
|
||||
#else
|
||||
# ifndef OS_WIN
|
||||
# define OS_WIN 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
** 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.
|
||||
** Invoke the appropriate operating-system specific header file.
|
||||
*/
|
||||
#ifndef SQLITE_DISABLE_LFS
|
||||
# define _LARGE_FILE 1
|
||||
# define _FILE_OFFSET_BITS 64
|
||||
# define _LARGEFILE_SOURCE 1
|
||||
#if OS_TEST
|
||||
# include "os_test.h"
|
||||
#endif
|
||||
#if OS_UNIX
|
||||
# include "os_unix.h"
|
||||
#endif
|
||||
#if OS_WIN
|
||||
# include "os_win.h"
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
|
||||
/*
|
||||
@@ -57,132 +84,124 @@
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Figure out if we are dealing with Unix, Windows or MacOS.
|
||||
** The following values may be passed as the second argument to
|
||||
** sqlite3OsLock(). The various locks exhibit the following semantics:
|
||||
**
|
||||
** 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)
|
||||
** SHARED: Any number of processes may hold a SHARED lock simultaneously.
|
||||
** RESERVED: A single process may hold a RESERVED lock on a file at
|
||||
** any time. Other processes may hold and obtain new SHARED locks.
|
||||
** PENDING: A single process may hold a PENDING lock on a file at
|
||||
** any one time. Existing SHARED locks may persist, but no new
|
||||
** SHARED locks may be obtained by other processes.
|
||||
** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
|
||||
**
|
||||
** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
|
||||
** process that requests an EXCLUSIVE lock may actually obtain a PENDING
|
||||
** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
|
||||
** sqlite3OsLock().
|
||||
*/
|
||||
#ifndef OS_UNIX
|
||||
# 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
|
||||
# endif
|
||||
# else
|
||||
# define OS_MAC 0
|
||||
# define OS_UNIX 0
|
||||
# endif
|
||||
#else
|
||||
# define OS_MAC 0
|
||||
# ifndef OS_WIN
|
||||
# define OS_WIN 0
|
||||
# endif
|
||||
#endif
|
||||
#define NO_LOCK 0
|
||||
#define SHARED_LOCK 1
|
||||
#define RESERVED_LOCK 2
|
||||
#define PENDING_LOCK 3
|
||||
#define EXCLUSIVE_LOCK 4
|
||||
|
||||
/*
|
||||
** A handle for an open file is stored in an OsFile object.
|
||||
** File Locking Notes: (Mostly about windows but also some info for Unix)
|
||||
**
|
||||
** 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.
|
||||
** A SHARED_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.
|
||||
** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
|
||||
** There can only be one writer. A RESERVED_LOCK is obtained by locking
|
||||
** a single byte of the file that is designated as the reserved lock byte.
|
||||
** A PENDING_LOCK is obtained by locking a designated byte different from
|
||||
** the RESERVED_LOCK byte.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** The following #defines specify the range of bytes used for locking.
|
||||
** SHARED_SIZE is the number of bytes available in the pool from which
|
||||
** a random byte is selected for a shared lock. The pool of bytes for
|
||||
** shared locks begins at SHARED_FIRST.
|
||||
**
|
||||
** These #defines are available in os.h so that Unix can use the same
|
||||
** byte ranges for locking. This leaves open the possiblity of having
|
||||
** clients on win95, winNT, and unix all talking to the same shared file
|
||||
** and all locking correctly. To do so would require that samba (or whatever
|
||||
** tool is being used for file sharing) implements locks correctly between
|
||||
** windows and unix. I'm guessing that isn't likely to happen, but by
|
||||
** using the same locking range we are at least open to the possibility.
|
||||
**
|
||||
** Locking in windows is manditory. For this reason, we cannot store
|
||||
** actual data in the bytes used for locking. The pager never allocates
|
||||
** the pages involved in locking therefore. SHARED_SIZE is selected so
|
||||
** that all locks will fit on a single page even at the minimum page size.
|
||||
** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
|
||||
** is set high so that we don't have to allocate an unused page except
|
||||
** for very large databases. But one should test the page skipping logic
|
||||
** by setting PENDING_BYTE low and running the entire regression suite.
|
||||
**
|
||||
** Changing the value of PENDING_BYTE results in a subtly incompatible
|
||||
** file format. Depending on how it is changed, you might not notice
|
||||
** the incompatibility right away, even running a full regression test.
|
||||
** The default location of PENDING_BYTE is the first byte past the
|
||||
** 1GB boundary.
|
||||
**
|
||||
*/
|
||||
#if OS_UNIX
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
struct lockInfo *pLock; /* Information about locks on this inode */
|
||||
int fd; /* The file descriptor */
|
||||
int locked; /* True if this user holds the lock */
|
||||
int dirfd; /* File descriptor for the directory */
|
||||
};
|
||||
# define SQLITE_TEMPNAME_SIZE 200
|
||||
# if defined(HAVE_USLEEP) && HAVE_USLEEP
|
||||
# define SQLITE_MIN_SLEEP_MS 1
|
||||
# else
|
||||
# define SQLITE_MIN_SLEEP_MS 1000
|
||||
# endif
|
||||
#ifndef SQLITE_TEST
|
||||
#define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
|
||||
#else
|
||||
extern unsigned int sqlite3_pending_byte;
|
||||
#define PENDING_BYTE sqlite3_pending_byte
|
||||
#endif
|
||||
|
||||
#if OS_WIN
|
||||
# if defined(__CYGWIN__)
|
||||
# define __CYGWIN_USE_BIG_TYPES__
|
||||
# endif
|
||||
#include <windows.h>
|
||||
#include <winbase.h>
|
||||
typedef struct OsFile OsFile;
|
||||
struct OsFile {
|
||||
HANDLE h; /* Handle for accessing the file */
|
||||
int locked; /* 0: unlocked, <0: write lock, >0: read lock */
|
||||
};
|
||||
# if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 off_t;
|
||||
# else
|
||||
# if !defined(_CYGWIN_TYPES_H)
|
||||
typedef long long off_t;
|
||||
# endif
|
||||
# endif
|
||||
# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
|
||||
# define SQLITE_MIN_SLEEP_MS 1
|
||||
#endif
|
||||
|
||||
#if OS_MAC
|
||||
# include <unistd.h>
|
||||
# include <Files.h>
|
||||
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 */
|
||||
};
|
||||
# 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
|
||||
#endif
|
||||
|
||||
int sqliteOsDelete(const char*);
|
||||
int sqliteOsFileExists(const char*);
|
||||
int sqliteOsFileRename(const char*, const char*);
|
||||
int sqliteOsOpenReadWrite(const char*, OsFile*, int*);
|
||||
int sqliteOsOpenExclusive(const char*, OsFile*, int);
|
||||
int sqliteOsOpenReadOnly(const char*, OsFile*);
|
||||
int sqliteOsOpenDirectory(const char*, OsFile*);
|
||||
int sqliteOsTempFileName(char*);
|
||||
int sqliteOsClose(OsFile*);
|
||||
int sqliteOsRead(OsFile*, void*, int amt);
|
||||
int sqliteOsWrite(OsFile*, const void*, int amt);
|
||||
int sqliteOsSeek(OsFile*, off_t offset);
|
||||
int sqliteOsSync(OsFile*);
|
||||
int sqliteOsTruncate(OsFile*, off_t size);
|
||||
int sqliteOsFileSize(OsFile*, off_t *pSize);
|
||||
int sqliteOsReadLock(OsFile*);
|
||||
int sqliteOsWriteLock(OsFile*);
|
||||
int sqliteOsUnlock(OsFile*);
|
||||
int sqliteOsRandomSeed(char*);
|
||||
int sqliteOsSleep(int ms);
|
||||
int sqliteOsCurrentTime(double*);
|
||||
void sqliteOsEnterMutex(void);
|
||||
void sqliteOsLeaveMutex(void);
|
||||
char *sqliteOsFullPathname(const char*);
|
||||
#define RESERVED_BYTE (PENDING_BYTE+1)
|
||||
#define SHARED_FIRST (PENDING_BYTE+2)
|
||||
#define SHARED_SIZE 510
|
||||
|
||||
|
||||
int sqlite3OsDelete(const char*);
|
||||
int sqlite3OsFileExists(const char*);
|
||||
int sqlite3OsOpenReadWrite(const char*, OsFile*, int*);
|
||||
int sqlite3OsOpenExclusive(const char*, OsFile*, int);
|
||||
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*, 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_ */
|
||||
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
** 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 macros and a little bit of code that is common to
|
||||
** all of the platform-specific files (os_*.c) and is #included into those
|
||||
** files.
|
||||
**
|
||||
** This file should be #included by the os_*.c files only. It is not a
|
||||
** general purpose header file.
|
||||
*/
|
||||
|
||||
/*
|
||||
** At least two bugs have slipped in because we changed the MEMORY_DEBUG
|
||||
** macro to SQLITE_DEBUG and some older makefiles have not yet made the
|
||||
** switch. The following code should catch this problem at compile-time.
|
||||
*/
|
||||
#ifdef MEMORY_DEBUG
|
||||
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
|
||||
#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;
|
||||
#define SEEK(X) last_page=(X)
|
||||
#define TRACE1(X) if( sqlite3_os_trace ) sqlite3DebugPrintf(X)
|
||||
#define TRACE2(X,Y) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y)
|
||||
#define TRACE3(X,Y,Z) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z)
|
||||
#define TRACE4(X,Y,Z,A) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A)
|
||||
#define TRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B)
|
||||
#define TRACE6(X,Y,Z,A,B,C) if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C)
|
||||
#define TRACE7(X,Y,Z,A,B,C,D) \
|
||||
if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C,D)
|
||||
#else
|
||||
#define SEEK(X)
|
||||
#define TRACE1(X)
|
||||
#define TRACE2(X,Y)
|
||||
#define TRACE3(X,Y,Z)
|
||||
#define TRACE4(X,Y,Z,A)
|
||||
#define TRACE5(X,Y,Z,A,B)
|
||||
#define TRACE6(X,Y,Z,A,B,C)
|
||||
#define TRACE7(X,Y,Z,A,B,C,D)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Macros for performance tracing. Normally turned off. Only works
|
||||
** on i486 hardware.
|
||||
*/
|
||||
#ifdef SQLITE_PERFORMANCE_TRACE
|
||||
__inline__ unsigned long long int hwtime(void){
|
||||
unsigned long long int x;
|
||||
__asm__("rdtsc\n\t"
|
||||
"mov %%edx, %%ecx\n\t"
|
||||
:"=A" (x));
|
||||
return x;
|
||||
}
|
||||
static unsigned long long int g_start;
|
||||
static unsigned int elapse;
|
||||
#define TIMER_START g_start=hwtime()
|
||||
#define TIMER_END elapse=hwtime()-g_start
|
||||
#define TIMER_ELAPSED elapse
|
||||
#else
|
||||
#define TIMER_START
|
||||
#define TIMER_END
|
||||
#define TIMER_ELAPSED 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
** If we compile with the SQLITE_TEST macro set, then the following block
|
||||
** of code will give us the ability to simulate a disk I/O error. This
|
||||
** is used for testing the I/O recovery logic.
|
||||
*/
|
||||
#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
|
||||
|
||||
/*
|
||||
** When testing, keep a count of the number of open files.
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_open_file_count = 0;
|
||||
#define OpenCounter(X) sqlite3_open_file_count+=(X)
|
||||
#else
|
||||
#define OpenCounter(X)
|
||||
#endif
|
||||
+1460
File diff suppressed because it is too large
Load Diff
+940
@@ -0,0 +1,940 @@
|
||||
/*
|
||||
** 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 windows.
|
||||
*/
|
||||
#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.
|
||||
*/
|
||||
#if defined(THREADSAFE) && THREADSAFE
|
||||
# define SQLITE_W32_THREADS 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Include code that is common to all os_*.c files
|
||||
*/
|
||||
#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){
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
if( zWide ){
|
||||
DeleteFileW(zWide);
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
DeleteFileA(zFilename);
|
||||
}
|
||||
TRACE2("DELETE \"%s\"\n", zFilename);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return TRUE if the named file exists.
|
||||
*/
|
||||
int sqlite3OsFileExists(const char *zFilename){
|
||||
int exists = 0;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
if( zWide ){
|
||||
exists = GetFileAttributesW(zWide) != 0xffffffff;
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
exists = GetFileAttributesA(zFilename) != 0xffffffff;
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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
|
||||
){
|
||||
HANDLE h;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
assert( !id->isOpen );
|
||||
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 ){
|
||||
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;
|
||||
}
|
||||
sqliteFree(zWide);
|
||||
}else{
|
||||
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;
|
||||
id->sharedLockByte = 0;
|
||||
id->isOpen = 1;
|
||||
OpenCounter(+1);
|
||||
TRACE3("OPEN R/W %d \"%s\"\n", h, zFilename);
|
||||
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){
|
||||
HANDLE h;
|
||||
int fileflags;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
assert( !id->isOpen );
|
||||
if( delFlag ){
|
||||
fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS
|
||||
| FILE_FLAG_DELETE_ON_CLOSE;
|
||||
}else{
|
||||
fileflags = FILE_FLAG_RANDOM_ACCESS;
|
||||
}
|
||||
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;
|
||||
}
|
||||
id->h = h;
|
||||
id->locktype = NO_LOCK;
|
||||
id->sharedLockByte = 0;
|
||||
id->isOpen = 1;
|
||||
OpenCounter(+1);
|
||||
TRACE3("OPEN EX %d \"%s\"\n", h, zFilename);
|
||||
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){
|
||||
HANDLE h;
|
||||
WCHAR *zWide = utf8ToUnicode(zFilename);
|
||||
assert( !id->isOpen );
|
||||
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;
|
||||
}
|
||||
id->h = h;
|
||||
id->locktype = NO_LOCK;
|
||||
id->sharedLockByte = 0;
|
||||
id->isOpen = 1;
|
||||
OpenCounter(+1);
|
||||
TRACE3("OPEN RO %d \"%s\"\n", h, zFilename);
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
** If the following global variable points to a string which is the
|
||||
** name of a directory, then that directory will be used to store
|
||||
** temporary files.
|
||||
*/
|
||||
char *sqlite3_temp_directory = 0;
|
||||
|
||||
/*
|
||||
** 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];
|
||||
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);
|
||||
}
|
||||
for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
|
||||
zTempPath[i] = 0;
|
||||
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;
|
||||
}
|
||||
TRACE2("TEMP FILENAME: %s\n", zBuf);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close a file.
|
||||
*/
|
||||
int sqlite3OsClose(OsFile *id){
|
||||
if( id->isOpen ){
|
||||
TRACE2("CLOSE %d\n", id->h);
|
||||
CloseHandle(id->h);
|
||||
OpenCounter(-1);
|
||||
id->isOpen = 0;
|
||||
}
|
||||
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){
|
||||
DWORD got;
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
TRACE3("READ %d lock=%d\n", id->h, id->locktype);
|
||||
if( !ReadFile(id->h, pBuf, amt, &got, 0) ){
|
||||
got = 0;
|
||||
}
|
||||
if( got==(DWORD)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){
|
||||
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];
|
||||
}
|
||||
if( !rc || amt>(int)wrote ){
|
||||
return SQLITE_FULL;
|
||||
}
|
||||
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, 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 dataOnly){
|
||||
assert( id->isOpen );
|
||||
TRACE3("SYNC %d lock=%d\n", id->h, id->locktype);
|
||||
if( FlushFileBuffers(id->h) ){
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** 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, i64 nByte){
|
||||
LONG upperBits = nByte>>32;
|
||||
assert( id->isOpen );
|
||||
TRACE3("TRUNCATE %d %lld\n", id->h, nByte);
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
SetFilePointer(id->h, nByte, &upperBits, FILE_BEGIN);
|
||||
SetEndOfFile(id->h);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Determine the current size of a file in bytes
|
||||
*/
|
||||
int sqlite3OsFileSize(OsFile *id, i64 *pSize){
|
||||
DWORD upperBits, lowerBits;
|
||||
assert( id->isOpen );
|
||||
SimulateIOError(SQLITE_IOERR);
|
||||
lowerBits = GetFileSize(id->h, &upperBits);
|
||||
*pSize = (((i64)upperBits)<<32) + lowerBits;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Acquire a reader lock.
|
||||
** Different API routines are called depending on whether or not this
|
||||
** is Win95 or WinNT.
|
||||
*/
|
||||
static int getReadLock(OsFile *id){
|
||||
int res;
|
||||
if( isNT() ){
|
||||
OVERLAPPED ovlp;
|
||||
ovlp.Offset = SHARED_FIRST;
|
||||
ovlp.OffsetHigh = 0;
|
||||
ovlp.hEvent = 0;
|
||||
res = LockFileEx(id->h, LOCKFILE_FAIL_IMMEDIATELY, 0, SHARED_SIZE,0,&ovlp);
|
||||
}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);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
** Undo a readlock
|
||||
*/
|
||||
static int unlockReadLock(OsFile *id){
|
||||
int res;
|
||||
if( isNT() ){
|
||||
res = UnlockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
}else{
|
||||
res = UnlockFile(id->h, SHARED_FIRST + id->sharedLockByte, 0, 1, 0);
|
||||
}
|
||||
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:
|
||||
**
|
||||
** (1) SHARED_LOCK
|
||||
** (2) RESERVED_LOCK
|
||||
** (3) PENDING_LOCK
|
||||
** (4) EXCLUSIVE_LOCK
|
||||
**
|
||||
** Sometimes when requesting one lock state, additional lock states
|
||||
** are inserted in between. The locking might fail on one of the later
|
||||
** transitions leaving the lock state different from what it started but
|
||||
** still short of its goal. The following chart shows the allowed
|
||||
** transitions and the inserted intermediate states:
|
||||
**
|
||||
** UNLOCKED -> SHARED
|
||||
** SHARED -> RESERVED
|
||||
** SHARED -> (PENDING) -> EXCLUSIVE
|
||||
** RESERVED -> (PENDING) -> EXCLUSIVE
|
||||
** PENDING -> EXCLUSIVE
|
||||
**
|
||||
** This routine will only increase a lock. The sqlite3OsUnlock() routine
|
||||
** erases all locks at once and returns us immediately to locking level 0.
|
||||
** It is not possible to lower the locking level one step at a time. You
|
||||
** must go straight to locking level 0.
|
||||
*/
|
||||
int sqlite3OsLock(OsFile *id, int locktype){
|
||||
int rc = SQLITE_OK; /* Return code from subroutines */
|
||||
int res = 1; /* Result of a windows lock call */
|
||||
int newLocktype; /* Set id->locktype to this value before exiting */
|
||||
int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
|
||||
|
||||
assert( id->isOpen );
|
||||
TRACE5("LOCK %d %d was %d(%d)\n",
|
||||
id->h, locktype, id->locktype, id->sharedLockByte);
|
||||
|
||||
/* 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 ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/* Make sure the locking sequence is correct
|
||||
*/
|
||||
assert( id->locktype!=NO_LOCK || locktype==SHARED_LOCK );
|
||||
assert( locktype!=PENDING_LOCK );
|
||||
assert( locktype!=RESERVED_LOCK || id->locktype==SHARED_LOCK );
|
||||
|
||||
/* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
|
||||
** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of
|
||||
** the PENDING_LOCK byte is temporary.
|
||||
*/
|
||||
newLocktype = id->locktype;
|
||||
if( id->locktype==NO_LOCK
|
||||
|| (locktype==EXCLUSIVE_LOCK && id->locktype==RESERVED_LOCK)
|
||||
){
|
||||
int cnt = 3;
|
||||
while( cnt-->0 && (res = LockFile(id->h, PENDING_BYTE, 0, 1, 0))==0 ){
|
||||
/* Try 3 times to get the pending lock. The pending lock might be
|
||||
** held by another reader process who will release it momentarily.
|
||||
*/
|
||||
TRACE2("could not get a PENDING lock. cnt=%d\n", cnt);
|
||||
Sleep(1);
|
||||
}
|
||||
gotPendingLock = res;
|
||||
}
|
||||
|
||||
/* Acquire a shared lock
|
||||
*/
|
||||
if( locktype==SHARED_LOCK && res ){
|
||||
assert( id->locktype==NO_LOCK );
|
||||
res = getReadLock(id);
|
||||
if( res ){
|
||||
newLocktype = SHARED_LOCK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Acquire a RESERVED lock
|
||||
*/
|
||||
if( locktype==RESERVED_LOCK && res ){
|
||||
assert( id->locktype==SHARED_LOCK );
|
||||
res = LockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
if( res ){
|
||||
newLocktype = RESERVED_LOCK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Acquire a PENDING lock
|
||||
*/
|
||||
if( locktype==EXCLUSIVE_LOCK && res ){
|
||||
newLocktype = PENDING_LOCK;
|
||||
gotPendingLock = 0;
|
||||
}
|
||||
|
||||
/* Acquire an EXCLUSIVE lock
|
||||
*/
|
||||
if( locktype==EXCLUSIVE_LOCK && res ){
|
||||
assert( id->locktype>=SHARED_LOCK );
|
||||
res = unlockReadLock(id);
|
||||
TRACE2("unreadlock = %d\n", res);
|
||||
res = LockFile(id->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
if( res ){
|
||||
newLocktype = EXCLUSIVE_LOCK;
|
||||
}else{
|
||||
TRACE2("error-code = %d\n", GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
/* If we are holding a PENDING lock that ought to be released, then
|
||||
** release it now.
|
||||
*/
|
||||
if( gotPendingLock && locktype==SHARED_LOCK ){
|
||||
UnlockFile(id->h, PENDING_BYTE, 0, 1, 0);
|
||||
}
|
||||
|
||||
/* Update the state of the lock has held in the file descriptor then
|
||||
** return the appropriate result code.
|
||||
*/
|
||||
if( res ){
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
TRACE4("LOCK FAILED %d trying for %d but got %d\n", id->h,
|
||||
locktype, newLocktype);
|
||||
rc = SQLITE_BUSY;
|
||||
}
|
||||
id->locktype = newLocktype;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine checks if there is a RESERVED lock held on the specified
|
||||
** file by this or any other process. If such a lock is held, return
|
||||
** non-zero, otherwise zero.
|
||||
*/
|
||||
int sqlite3OsCheckReservedLock(OsFile *id){
|
||||
int rc;
|
||||
assert( id->isOpen );
|
||||
if( id->locktype>=RESERVED_LOCK ){
|
||||
rc = 1;
|
||||
TRACE3("TEST WR-LOCK %d %d (local)\n", id->h, rc);
|
||||
}else{
|
||||
rc = LockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
if( rc ){
|
||||
UnlockFile(id->h, RESERVED_BYTE, 0, 1, 0);
|
||||
}
|
||||
rc = !rc;
|
||||
TRACE3("TEST WR-LOCK %d %d (remote)\n", id->h, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Lower the locking level on file descriptor id to locktype. locktype
|
||||
** must be either NO_LOCK or SHARED_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 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 type;
|
||||
int rc = SQLITE_OK;
|
||||
assert( id->isOpen );
|
||||
assert( locktype<=SHARED_LOCK );
|
||||
TRACE5("UNLOCK %d to %d was %d(%d)\n", id->h, locktype,
|
||||
id->locktype, id->sharedLockByte);
|
||||
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 ){
|
||||
unlockReadLock(id);
|
||||
}
|
||||
if( type>=PENDING_LOCK ){
|
||||
UnlockFile(id->h, PENDING_BYTE, 0, 1, 0);
|
||||
}
|
||||
id->locktype = locktype;
|
||||
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
|
||||
** 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);
|
||||
GetSystemTime((LPSYSTEMTIME)zBuf);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sleep for a little while. Return the amount of time slept.
|
||||
*/
|
||||
int sqlite3OsSleep(int ms){
|
||||
Sleep(ms);
|
||||
return ms;
|
||||
}
|
||||
|
||||
/*
|
||||
** Static variables used for thread synchronization
|
||||
*/
|
||||
static int inMutex = 0;
|
||||
#ifdef SQLITE_W32_THREADS
|
||||
static CRITICAL_SECTION cs;
|
||||
#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_W32_THREADS
|
||||
static int isInit = 0;
|
||||
while( !isInit ){
|
||||
static long lock = 0;
|
||||
if( InterlockedIncrement(&lock)==1 ){
|
||||
InitializeCriticalSection(&cs);
|
||||
isInit = 1;
|
||||
}else{
|
||||
Sleep(1);
|
||||
}
|
||||
}
|
||||
EnterCriticalSection(&cs);
|
||||
#endif
|
||||
assert( !inMutex );
|
||||
inMutex = 1;
|
||||
}
|
||||
void sqlite3OsLeaveMutex(){
|
||||
assert( inMutex );
|
||||
inMutex = 0;
|
||||
#ifdef SQLITE_W32_THREADS
|
||||
LeaveCriticalSection(&cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** 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){
|
||||
FILETIME ft;
|
||||
/* FILETIME structure is a 64-bit value representing the number of
|
||||
100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
|
||||
*/
|
||||
double now;
|
||||
GetSystemTimeAsFileTime( &ft );
|
||||
now = ((double)ft.dwHighDateTime) * 4294967296.0;
|
||||
*prNow = (now + ft.dwLowDateTime)/864000000000.0 + 2305813.5;
|
||||
#ifdef SQLITE_TEST
|
||||
if( sqlite3_current_time ){
|
||||
*prNow = sqlite3_current_time/86400.0 + 2440587.5;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* OS_WIN */
|
||||
+2360
-824
File diff suppressed because it is too large
Load Diff
+73
-40
@@ -13,22 +13,32 @@
|
||||
** 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.23 2003/04/25 13:22:53 drh Exp $
|
||||
** @(#) $Id: pager.h,v 1.46 2005/09/19 19:05:21 drh Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
** The size of one page
|
||||
** The default size of a database page.
|
||||
*/
|
||||
#ifndef SQLITE_DEFAULT_PAGE_SIZE
|
||||
# define SQLITE_DEFAULT_PAGE_SIZE 1024
|
||||
#endif
|
||||
|
||||
/* 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.
|
||||
**
|
||||
** You can change this value to another (reasonable) power of two
|
||||
** such as 512, 2048, 4096, or 8192 and things will still work. But
|
||||
** experiments show that a page size of 1024 gives the best speed.
|
||||
** (The speed differences are minimal.)
|
||||
** 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.
|
||||
*/
|
||||
#define SQLITE_PAGE_SIZE 1024
|
||||
#ifndef SQLITE_MAX_PAGE_SIZE
|
||||
# define SQLITE_MAX_PAGE_SIZE 32768
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Maximum number of pages in one database. (This is a limitation of
|
||||
** imposed by 4GB files size limits.)
|
||||
** Maximum number of pages in one database.
|
||||
*/
|
||||
#define SQLITE_MAX_PAGE 1073741823
|
||||
|
||||
@@ -43,41 +53,64 @@ 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 sqlitepager_open(Pager **ppPager, const char *zFilename,
|
||||
int nPage, int nExtra, int useJournal);
|
||||
void sqlitepager_set_destructor(Pager*, void(*)(void*));
|
||||
void sqlitepager_set_cachesize(Pager*, int);
|
||||
int sqlitepager_close(Pager *pPager);
|
||||
int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage);
|
||||
void *sqlitepager_lookup(Pager *pPager, Pgno pgno);
|
||||
int sqlitepager_ref(void*);
|
||||
int sqlitepager_unref(void*);
|
||||
Pgno sqlitepager_pagenumber(void*);
|
||||
int sqlitepager_write(void*);
|
||||
int sqlitepager_iswriteable(void*);
|
||||
int sqlitepager_overwrite(Pager *pPager, Pgno pgno, void*);
|
||||
int sqlitepager_pagecount(Pager*);
|
||||
int sqlitepager_truncate(Pager*,Pgno);
|
||||
int sqlitepager_begin(void*);
|
||||
int sqlitepager_commit(Pager*);
|
||||
int sqlitepager_rollback(Pager*);
|
||||
int sqlitepager_isreadonly(Pager*);
|
||||
int sqlitepager_ckpt_begin(Pager*);
|
||||
int sqlitepager_ckpt_commit(Pager*);
|
||||
int sqlitepager_ckpt_rollback(Pager*);
|
||||
void sqlitepager_dont_rollback(void*);
|
||||
void sqlitepager_dont_write(Pager*, Pgno);
|
||||
int *sqlitepager_stats(Pager*);
|
||||
void sqlitepager_set_safety_level(Pager*,int);
|
||||
const char *sqlitepager_filename(Pager*);
|
||||
int sqlitepager_rename(Pager*, const char *zNewName);
|
||||
int sqlite3pager_open(Pager **ppPager, const char *zFilename,
|
||||
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));
|
||||
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);
|
||||
int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage);
|
||||
void *sqlite3pager_lookup(Pager *pPager, Pgno pgno);
|
||||
int sqlite3pager_ref(void*);
|
||||
int sqlite3pager_unref(void*);
|
||||
Pgno sqlite3pager_pagenumber(void*);
|
||||
int sqlite3pager_write(void*);
|
||||
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 exFlag);
|
||||
int sqlite3pager_commit(Pager*);
|
||||
int sqlite3pager_sync(Pager*,const char *zMaster, Pgno);
|
||||
int sqlite3pager_rollback(Pager*);
|
||||
int sqlite3pager_isreadonly(Pager*);
|
||||
int sqlite3pager_stmt_begin(Pager*);
|
||||
int sqlite3pager_stmt_commit(Pager*);
|
||||
int sqlite3pager_stmt_rollback(Pager*);
|
||||
void sqlite3pager_dont_rollback(void*);
|
||||
void sqlite3pager_dont_write(Pager*, Pgno);
|
||||
int *sqlite3pager_stats(Pager*);
|
||||
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*);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
void sqlitepager_refdump(Pager*);
|
||||
int pager_refinfo_enable;
|
||||
int journal_format;
|
||||
void sqlite3pager_refdump(Pager*);
|
||||
int pager3_refinfo_enable;
|
||||
#endif
|
||||
|
||||
+584
-386
File diff suppressed because it is too large
Load Diff
+755
-530
File diff suppressed because it is too large
Load Diff
+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 */
|
||||
+417
-385
File diff suppressed because it is too large
Load Diff
+22
-35
@@ -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.10 2002/02/19 13:39:23 drh Exp $
|
||||
** $Id: random.c,v 1.13 2005/06/12 21:35:52 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -26,24 +26,27 @@
|
||||
** 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(){
|
||||
int t;
|
||||
unsigned char t;
|
||||
|
||||
/* All threads share a single random number generator.
|
||||
** This structure is the current state of the generator.
|
||||
*/
|
||||
static struct {
|
||||
int isInit; /* True if initialized */
|
||||
int i, j; /* State variables */
|
||||
int s[256]; /* State variables */
|
||||
unsigned char isInit; /* True if initialized */
|
||||
unsigned char i, j; /* State variables */
|
||||
unsigned char s[256]; /* State variables */
|
||||
} prng;
|
||||
|
||||
/* Initialize the state of the random number generator once,
|
||||
@@ -60,13 +63,12 @@ static int randomByte(){
|
||||
char k[256];
|
||||
prng.j = 0;
|
||||
prng.i = 0;
|
||||
sqliteOsRandomSeed(k);
|
||||
sqlite3OsRandomSeed(k);
|
||||
for(i=0; i<256; i++){
|
||||
prng.s[i] = i;
|
||||
}
|
||||
for(i=0; i<256; i++){
|
||||
int t;
|
||||
prng.j = (prng.j + prng.s[i] + k[i]) & 0xff;
|
||||
prng.j += prng.s[i] + k[i];
|
||||
t = prng.s[prng.j];
|
||||
prng.s[prng.j] = prng.s[i];
|
||||
prng.s[i] = t;
|
||||
@@ -76,38 +78,23 @@ static int randomByte(){
|
||||
|
||||
/* Generate and return single random byte
|
||||
*/
|
||||
prng.i = (prng.i + 1) & 0xff;
|
||||
prng.j = (prng.j + prng.s[prng.i]) & 0xff;
|
||||
prng.i++;
|
||||
t = prng.s[prng.i];
|
||||
prng.j += t;
|
||||
prng.s[prng.i] = prng.s[prng.j];
|
||||
prng.s[prng.j] = t;
|
||||
t = prng.s[prng.i] + prng.s[prng.j];
|
||||
return prng.s[t & 0xff];
|
||||
t += prng.s[prng.i];
|
||||
return prng.s[t];
|
||||
}
|
||||
|
||||
/*
|
||||
** Return an random 8-bit integer.
|
||||
** Return N random bytes.
|
||||
*/
|
||||
int sqliteRandomByte(){
|
||||
int r;
|
||||
sqliteOsEnterMutex();
|
||||
r = randomByte();
|
||||
sqliteOsLeaveMutex();
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return a random 32-bit integer. The integer is generated by making
|
||||
** 4 calls to sqliteRandomByte().
|
||||
*/
|
||||
int sqliteRandomInteger(){
|
||||
int r;
|
||||
int i;
|
||||
sqliteOsEnterMutex();
|
||||
r = randomByte();
|
||||
for(i=1; i<4; i++){
|
||||
r = (r<<8) + randomByte();
|
||||
void sqlite3Randomness(int N, void *pBuf){
|
||||
unsigned char *zBuf = pBuf;
|
||||
sqlite3OsEnterMutex();
|
||||
while( N-- ){
|
||||
*(zBuf++) = randomByte();
|
||||
}
|
||||
sqliteOsLeaveMutex();
|
||||
return r;
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
|
||||
+1754
-1020
File diff suppressed because it is too large
Load Diff
+667
-195
File diff suppressed because it is too large
Load Diff
-596
@@ -1,596 +0,0 @@
|
||||
#!/usr/bin/wish
|
||||
#
|
||||
# A GUI shell for SQLite
|
||||
#
|
||||
|
||||
# The following code is slighly modified from the original. See comments
|
||||
# for the modifications...
|
||||
############################################################################
|
||||
# A console widget for Tcl/Tk. Invoke console:create with a window name,
|
||||
# a prompt string, and a title to get a new top-level window that allows
|
||||
# the user to enter tcl commands. This is mainly useful for testing and
|
||||
# debugging.
|
||||
#
|
||||
# Copyright (C) 1998, 1999 D. Richard Hipp
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author contact information:
|
||||
# drh@acm.org
|
||||
# http://www.hwaci.com/drh/
|
||||
|
||||
# Create a console widget named $w. The prompt string is $prompt.
|
||||
# The title at the top of the window is $title
|
||||
#
|
||||
proc console:create {w prompt title} {
|
||||
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]
|
||||
# $m add command -label {Source...} -command "console:SourceFile $w.t"
|
||||
# $m add command -label {Save As...} -command "console:SaveFile $w.t"
|
||||
# $m add separator
|
||||
$m add command -label {Close} -command "destroy $w"
|
||||
$m add command -label {Exit} -command exit
|
||||
console:create_child $w $prompt $w.mb.edit.m
|
||||
}
|
||||
|
||||
# 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 console:create_child {w prompt editmenu} {
|
||||
upvar #0 $w.t v
|
||||
if {$editmenu!=""} {
|
||||
set m [menu $editmenu]
|
||||
$m add command -label Cut -command "console:Cut $w.t"
|
||||
$m add command -label Copy -command "console:Copy $w.t"
|
||||
$m add command -label Paste -command "console:Paste $w.t"
|
||||
$m add command -label {Clear Screen} -command "console:Clear $w.t"
|
||||
$m add separator
|
||||
$m add command -label {Source...} -command "console:SourceFile $w.t"
|
||||
$m add command -label {Save As...} -command "console:SaveFile $w.t"
|
||||
catch {$editmenu config -postcommand "console: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 Console
|
||||
set v(editmenu) $editmenu
|
||||
set v(text) $w.t
|
||||
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
|
||||
$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
|
||||
catch {rename puts console:oldputs$w}
|
||||
proc puts args [format {
|
||||
if {![winfo exists %s]} {
|
||||
rename puts {}
|
||||
rename console:oldputs%s puts
|
||||
return [uplevel #0 puts $args]
|
||||
}
|
||||
switch -glob -- "[llength $args] $args" {
|
||||
{1 *} {
|
||||
set msg [lindex $args 0]\n
|
||||
set tag ok
|
||||
}
|
||||
{2 stdout *} {
|
||||
set msg [lindex $args 1]\n
|
||||
set tag ok
|
||||
}
|
||||
{2 stderr *} {
|
||||
set msg [lindex $args 1]\n
|
||||
set tag err
|
||||
}
|
||||
{2 -nonewline *} {
|
||||
set msg [lindex $args 1]
|
||||
set tag ok
|
||||
}
|
||||
{3 -nonewline stdout *} {
|
||||
set msg [lindex $args 2]
|
||||
set tag ok
|
||||
}
|
||||
{3 -nonewline stderr *} {
|
||||
set msg [lindex $args 2]
|
||||
set tag err
|
||||
}
|
||||
default {
|
||||
uplevel #0 console:oldputs%s $args
|
||||
return
|
||||
}
|
||||
}
|
||||
console:Puts %s $msg $tag
|
||||
} $w $w $w $w.t]
|
||||
after idle "focus $w.t"
|
||||
}
|
||||
|
||||
bind Console <1> {console:Button1 %W %x %y}
|
||||
bind Console <B1-Motion> {console:B1Motion %W %x %y}
|
||||
bind Console <B1-Leave> {console:B1Leave %W %x %y}
|
||||
bind Console <B1-Enter> {console:cancelMotor %W}
|
||||
bind Console <ButtonRelease-1> {console:cancelMotor %W}
|
||||
bind Console <KeyPress> {console:Insert %W %A}
|
||||
bind Console <Left> {console:Left %W}
|
||||
bind Console <Control-b> {console:Left %W}
|
||||
bind Console <Right> {console:Right %W}
|
||||
bind Console <Control-f> {console:Right %W}
|
||||
bind Console <BackSpace> {console:Backspace %W}
|
||||
bind Console <Control-h> {console:Backspace %W}
|
||||
bind Console <Delete> {console:Delete %W}
|
||||
bind Console <Control-d> {console:Delete %W}
|
||||
bind Console <Home> {console:Home %W}
|
||||
bind Console <Control-a> {console:Home %W}
|
||||
bind Console <End> {console:End %W}
|
||||
bind Console <Control-e> {console:End %W}
|
||||
bind Console <Return> {console:Enter %W}
|
||||
bind Console <KP_Enter> {console:Enter %W}
|
||||
bind Console <Up> {console:Prior %W}
|
||||
bind Console <Control-p> {console:Prior %W}
|
||||
bind Console <Down> {console:Next %W}
|
||||
bind Console <Control-n> {console:Next %W}
|
||||
bind Console <Control-k> {console:EraseEOL %W}
|
||||
bind Console <<Cut>> {console:Cut %W}
|
||||
bind Console <<Copy>> {console:Copy %W}
|
||||
bind Console <<Paste>> {console:Paste %W}
|
||||
bind Console <<Clear>> {console:Clear %W}
|
||||
|
||||
# Insert test at the "out" mark. The "out" mark is always
|
||||
# before the input line. New text appears on the line prior
|
||||
# to the current input line.
|
||||
#
|
||||
proc console:Puts {w t tag} {
|
||||
set nc [string length $t]
|
||||
set endc [string index $t [expr $nc-1]]
|
||||
if {$endc=="\n"} {
|
||||
if {[$w index out]<[$w index {insert linestart}]} {
|
||||
$w insert out [string range $t 0 [expr $nc-2]] $tag
|
||||
$w mark set out {out linestart +1 lines}
|
||||
} else {
|
||||
$w insert out $t $tag
|
||||
}
|
||||
} else {
|
||||
if {[$w index out]<[$w index {insert linestart}]} {
|
||||
$w insert out $t $tag
|
||||
} else {
|
||||
$w insert out $t\n $tag
|
||||
$w mark set out {out -1 char}
|
||||
}
|
||||
}
|
||||
$w yview insert
|
||||
}
|
||||
|
||||
# Insert a single character at the insertion cursor
|
||||
#
|
||||
proc console:Insert {w a} {
|
||||
$w insert insert $a
|
||||
$w yview insert
|
||||
}
|
||||
|
||||
# Move the cursor one character to the left
|
||||
#
|
||||
proc console: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 console: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 console: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 console:Right {w} {
|
||||
$w mark set insert "insert +1c"
|
||||
}
|
||||
|
||||
# Erase the character to the right of the cursor
|
||||
#
|
||||
proc console:Delete w {
|
||||
$w delete insert
|
||||
}
|
||||
|
||||
# Move the cursor to the beginning of the current line
|
||||
#
|
||||
proc console: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 console:End w {
|
||||
$w mark set insert {insert lineend}
|
||||
}
|
||||
|
||||
# Called when "Enter" is pressed. Do something with the line
|
||||
# of text that was entered.
|
||||
#
|
||||
proc console: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"]
|
||||
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)
|
||||
$w insert end \n
|
||||
$w mark set out end
|
||||
if {$v(prior)==""} {
|
||||
set cmd $line
|
||||
} else {
|
||||
set cmd $v(prior)\n$line
|
||||
}
|
||||
##### Original
|
||||
# if {[info complete $cmd]} { }
|
||||
# set rc [catch {uplevel #0 $cmd} res]
|
||||
##### New
|
||||
global DB
|
||||
if {[$DB complete $cmd]} {
|
||||
set CODE {}
|
||||
set rc [catch {$DB eval $cmd RESULT $CODE}]
|
||||
##### End Of Changes
|
||||
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
|
||||
}
|
||||
|
||||
# Change the line to the previous line
|
||||
#
|
||||
proc console:Prior w {
|
||||
upvar #0 $w v
|
||||
if {$v(current)<=0} return
|
||||
incr v(current) -1
|
||||
set line [lindex $v(history) $v(current)]
|
||||
console:SetLine $w $line
|
||||
}
|
||||
|
||||
# Change the line to the next line
|
||||
#
|
||||
proc console:Next w {
|
||||
upvar #0 $w v
|
||||
if {$v(current)>=$v(historycnt)} return
|
||||
incr v(current) 1
|
||||
set line [lindex $v(history) $v(current)]
|
||||
console:SetLine $w $line
|
||||
}
|
||||
|
||||
# Change the contents of the entry line
|
||||
#
|
||||
proc console: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 console:Button1 {w x y} {
|
||||
global tkPriv
|
||||
upvar #0 $w v
|
||||
set v(mouseMoved) 0
|
||||
set v(pressX) $x
|
||||
set p [console: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 console: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 console:SelectTo {w x y} {
|
||||
upvar #0 $w v
|
||||
set cur [console: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 console:B1Motion {w x y} {
|
||||
upvar #0 $w v
|
||||
set v(y) $y
|
||||
set v(x) $x
|
||||
console:SelectTo $w $x $y
|
||||
}
|
||||
|
||||
# Called whenever the mouse leaves the boundries of the widget
|
||||
# while button 1 is held down.
|
||||
#
|
||||
proc console:B1Leave {w x y} {
|
||||
upvar #0 $w v
|
||||
set v(y) $y
|
||||
set v(x) $x
|
||||
console:motor $w
|
||||
}
|
||||
|
||||
# This routine is called to automatically scroll the window when
|
||||
# the mouse drags offscreen.
|
||||
#
|
||||
proc console: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
|
||||
}
|
||||
console:SelectTo $w $v(x) $v(y)
|
||||
set v(timer) [after 50 console:motor $w]
|
||||
}
|
||||
|
||||
# This routine cancels the scrolling motor if it is active
|
||||
#
|
||||
proc console: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 console: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 console: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 console:Cut w {
|
||||
if {[console:canCut $w]==1} {
|
||||
console:Copy $w
|
||||
$w delete sel.first sel.last
|
||||
}
|
||||
}
|
||||
|
||||
# Do a paste opeation.
|
||||
#
|
||||
proc console:Paste w {
|
||||
if {[console:canCut $w]==1} {
|
||||
$w delete sel.first sel.last
|
||||
}
|
||||
if {[catch {selection get -displayof $w -selection CLIPBOARD} topaste]} {
|
||||
return
|
||||
}
|
||||
set prior 0
|
||||
foreach line [split $topaste \n] {
|
||||
if {$prior} {
|
||||
console:Enter $w
|
||||
update
|
||||
}
|
||||
set prior 1
|
||||
$w insert insert $line
|
||||
}
|
||||
}
|
||||
|
||||
# Enable or disable entries in the Edit menu
|
||||
#
|
||||
proc console:EnableEditMenu w {
|
||||
upvar #0 $w.t v
|
||||
set m $v(editmenu)
|
||||
if {$m=="" || ![winfo exists $m]} return
|
||||
switch [console: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 for the user to select an input file, the "source" that file.
|
||||
#
|
||||
proc console:SourceFile w {
|
||||
set types {
|
||||
{{TCL Scripts} {.tcl}}
|
||||
{{All Files} *}
|
||||
}
|
||||
set f [tk_getOpenFile -filetypes $types -title "TCL Script To Source..."]
|
||||
if {$f!=""} {
|
||||
uplevel #0 source $f
|
||||
}
|
||||
}
|
||||
|
||||
# Prompt the user for the name of a writable file. Then write the
|
||||
# entire contents of the console screen to that file.
|
||||
#
|
||||
proc console: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 console:Clear w {
|
||||
$w delete 1.0 {insert linestart}
|
||||
}
|
||||
|
||||
# Start the console
|
||||
#
|
||||
# console:create {.@console} {% } {Tcl/Tk Console}
|
||||
###############################################################################
|
||||
|
||||
|
||||
if {[info command sqlite]==""} {
|
||||
load ./tclsqlite.so sqlite
|
||||
}
|
||||
|
||||
|
||||
|
||||
proc set_title {title} {
|
||||
if {$title==""} {
|
||||
set main SQLite
|
||||
} else {
|
||||
set main "SQLite - $title"
|
||||
}
|
||||
wm title . $main
|
||||
wm iconname . SQLite
|
||||
}
|
||||
set_title {}
|
||||
|
||||
frame .mb -bd 1 -relief raised
|
||||
pack .mb -side top -fill x
|
||||
menubutton .mb.file -text File -underline 0 -menu .mb.file.m
|
||||
pack .mb.file -side left -padx 5
|
||||
set m [menu .mb.file.m]
|
||||
$m add separator
|
||||
$m add command -label Exit -command exit
|
||||
menubutton .mb.edit -text Edit -underline 0 -menu .mb.edit.m
|
||||
pack .mb.edit -side left -padx 5
|
||||
#menu .mb.edit.m
|
||||
|
||||
frame .f
|
||||
pack .f -side top -fill both -expand 1
|
||||
console:create_child .f {sqlite> } .mb.edit.m
|
||||
+917
-405
File diff suppressed because it is too large
Load Diff
+861
-401
File diff suppressed because it is too large
Load Diff
+28
-35
@@ -9,9 +9,9 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains the sqlite_get_table() and sqlite_free_table()
|
||||
** This file contains the sqlite3_get_table() and sqlite3_free_table()
|
||||
** interface routines. These are just wrappers around the main
|
||||
** interface routine of sqlite_exec().
|
||||
** interface routine of sqlite3_exec().
|
||||
**
|
||||
** These routines are in a separate files so that they will not be linked
|
||||
** if they are not used.
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This structure is used to pass data from sqlite_get_table() through
|
||||
** This structure is used to pass data from sqlite3_get_table() through
|
||||
** to the callback function is uses to build the result.
|
||||
*/
|
||||
typedef struct TabResult {
|
||||
@@ -40,7 +40,7 @@ typedef struct TabResult {
|
||||
** is to fill in the TabResult structure appropriately, allocating new
|
||||
** memory as necessary.
|
||||
*/
|
||||
static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
TabResult *p = (TabResult*)pArg;
|
||||
int need;
|
||||
int i;
|
||||
@@ -58,10 +58,7 @@ static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
char **azNew;
|
||||
p->nAlloc = p->nAlloc*2 + need + 1;
|
||||
azNew = realloc( p->azResult, sizeof(char*)*p->nAlloc );
|
||||
if( azNew==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
if( azNew==0 ) goto malloc_failed;
|
||||
p->azResult = azNew;
|
||||
}
|
||||
|
||||
@@ -75,17 +72,15 @@ static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
z = 0;
|
||||
}else{
|
||||
z = malloc( strlen(colv[i])+1 );
|
||||
if( z==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
if( z==0 ) goto malloc_failed;
|
||||
strcpy(z, colv[i]);
|
||||
}
|
||||
p->azResult[p->nData++] = z;
|
||||
}
|
||||
}else if( p->nColumn!=nCol ){
|
||||
sqliteSetString(&p->zErrMsg,
|
||||
"sqlite_get_table() called with two or more incompatible queries", 0);
|
||||
sqlite3SetString(&p->zErrMsg,
|
||||
"sqlite3_get_table() called with two or more incompatible queries",
|
||||
(char*)0);
|
||||
p->rc = SQLITE_ERROR;
|
||||
return 1;
|
||||
}
|
||||
@@ -98,10 +93,7 @@ static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
z = 0;
|
||||
}else{
|
||||
z = malloc( strlen(argv[i])+1 );
|
||||
if( z==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
if( z==0 ) goto malloc_failed;
|
||||
strcpy(z, argv[i]);
|
||||
}
|
||||
p->azResult[p->nData++] = z;
|
||||
@@ -109,6 +101,10 @@ static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
p->nRow++;
|
||||
}
|
||||
return 0;
|
||||
|
||||
malloc_failed:
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -118,11 +114,11 @@ static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
**
|
||||
** The result that is written to ***pazResult is held in memory obtained
|
||||
** from malloc(). But the caller cannot free this memory directly.
|
||||
** Instead, the entire table should be passed to sqlite_free_table() when
|
||||
** Instead, the entire table should be passed to sqlite3_free_table() when
|
||||
** the calling procedure is finished using it.
|
||||
*/
|
||||
int sqlite_get_table(
|
||||
sqlite *db, /* The database on which the SQL executes */
|
||||
int sqlite3_get_table(
|
||||
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 */
|
||||
@@ -143,37 +139,34 @@ int sqlite_get_table(
|
||||
res.nAlloc = 20;
|
||||
res.rc = SQLITE_OK;
|
||||
res.azResult = malloc( sizeof(char*)*res.nAlloc );
|
||||
if( res.azResult==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
if( res.azResult==0 ) return SQLITE_NOMEM;
|
||||
res.azResult[0] = 0;
|
||||
rc = sqlite_exec(db, zSql, sqlite_get_table_cb, &res, pzErrMsg);
|
||||
rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
|
||||
if( res.azResult ){
|
||||
res.azResult[0] = (char*)res.nData;
|
||||
}
|
||||
if( rc==SQLITE_ABORT ){
|
||||
sqlite_free_table(&res.azResult[1]);
|
||||
sqlite3_free_table(&res.azResult[1]);
|
||||
if( res.zErrMsg ){
|
||||
if( pzErrMsg ){
|
||||
free(*pzErrMsg);
|
||||
*pzErrMsg = res.zErrMsg;
|
||||
sqliteStrRealloc(pzErrMsg);
|
||||
}else{
|
||||
sqliteFree(res.zErrMsg);
|
||||
*pzErrMsg = sqlite3_mprintf("%s",res.zErrMsg);
|
||||
}
|
||||
sqliteFree(res.zErrMsg);
|
||||
}
|
||||
db->errCode = res.rc;
|
||||
return res.rc;
|
||||
}
|
||||
sqliteFree(res.zErrMsg);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite_free_table(&res.azResult[1]);
|
||||
sqlite3_free_table(&res.azResult[1]);
|
||||
return rc;
|
||||
}
|
||||
if( res.nAlloc>res.nData ){
|
||||
char **azNew;
|
||||
azNew = realloc( res.azResult, sizeof(char*)*(res.nData+1) );
|
||||
if( azNew==0 ){
|
||||
sqlite_free_table(&res.azResult[1]);
|
||||
sqlite3_free_table(&res.azResult[1]);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
res.nAlloc = res.nData+1;
|
||||
@@ -186,10 +179,10 @@ int sqlite_get_table(
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine frees the space the sqlite_get_table() malloced.
|
||||
** This routine frees the space the sqlite3_get_table() malloced.
|
||||
*/
|
||||
void sqlite_free_table(
|
||||
char **azResult /* Result returned from from sqlite_get_table() */
|
||||
void sqlite3_free_table(
|
||||
char **azResult /* Result returned from from sqlite3_get_table() */
|
||||
){
|
||||
if( azResult ){
|
||||
int i, n;
|
||||
|
||||
+1502
-528
File diff suppressed because it is too large
Load Diff
+2696
-371
File diff suppressed because it is too large
Load Diff
+103
-59
@@ -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.15 2003/02/11 14:55:41 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;
|
||||
@@ -55,6 +52,11 @@ static char *errorName(int rc){
|
||||
return zName;
|
||||
}
|
||||
|
||||
/*
|
||||
** Page size and reserved size used for testing.
|
||||
*/
|
||||
static int test_pagesize = 1024;
|
||||
|
||||
/*
|
||||
** Usage: pager_open FILENAME N-PAGE
|
||||
**
|
||||
@@ -76,12 +78,14 @@ static int pager_open(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR;
|
||||
rc = sqlitepager_open(&pPager, argv[1], nPage, 0, 1);
|
||||
rc = sqlite3pager_open(&pPager, argv[1], 0, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"0x%x",(int)pPager);
|
||||
sqlite3pager_set_cachesize(pPager, nPage);
|
||||
sqlite3pager_set_pagesize(pPager, test_pagesize);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -104,8 +108,8 @@ static int pager_close(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_close(pPager);
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_close(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -131,8 +135,8 @@ static int pager_rollback(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_rollback(pPager);
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_rollback(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -158,8 +162,8 @@ static int pager_commit(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_commit(pPager);
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_commit(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -168,11 +172,11 @@ static int pager_commit(
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_ckpt_begin ID
|
||||
** Usage: pager_stmt_begin ID
|
||||
**
|
||||
** Start a new checkpoint.
|
||||
*/
|
||||
static int pager_ckpt_begin(
|
||||
static int pager_stmt_begin(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
@@ -185,8 +189,8 @@ static int pager_ckpt_begin(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_ckpt_begin(pPager);
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_stmt_begin(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -195,11 +199,11 @@ static int pager_ckpt_begin(
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_ckpt_rollback ID
|
||||
** Usage: pager_stmt_rollback ID
|
||||
**
|
||||
** Rollback changes to a checkpoint
|
||||
*/
|
||||
static int pager_ckpt_rollback(
|
||||
static int pager_stmt_rollback(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
@@ -212,8 +216,8 @@ static int pager_ckpt_rollback(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_ckpt_rollback(pPager);
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_stmt_rollback(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -222,11 +226,11 @@ static int pager_ckpt_rollback(
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_ckpt_commit ID
|
||||
** Usage: pager_stmt_commit ID
|
||||
**
|
||||
** Commit changes to a checkpoint
|
||||
*/
|
||||
static int pager_ckpt_commit(
|
||||
static int pager_stmt_commit(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
@@ -239,8 +243,8 @@ static int pager_ckpt_commit(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_ckpt_commit(pPager);
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_stmt_commit(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -266,8 +270,8 @@ static int pager_stats(
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
a = sqlitepager_stats(pPager);
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
a = sqlite3pager_stats(pPager);
|
||||
for(i=0; i<9; i++){
|
||||
static char *zName[] = {
|
||||
"ref", "page", "max", "size", "state", "err",
|
||||
@@ -275,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;
|
||||
@@ -299,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",sqlitepager_pagecount(pPager));
|
||||
pPager = sqlite3TextToPtr(argv[1]);
|
||||
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3pager_pagecount(pPager));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -326,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 = sqlitepager_get(pPager, pgno, &pPage);
|
||||
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;
|
||||
}
|
||||
@@ -359,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 = sqlitepager_lookup(pPager, pgno);
|
||||
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
|
||||
**
|
||||
@@ -387,8 +419,8 @@ static int page_unref(
|
||||
" PAGE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
rc = sqlitepager_unref(pPage);
|
||||
pPage = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_unref(pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -414,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;
|
||||
@@ -438,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", sqlitepager_pagenumber(pPage));
|
||||
pPage = sqlite3TextToPtr(argv[1]);
|
||||
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", sqlite3pager_pagenumber(pPage));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -462,17 +494,18 @@ static int page_write(
|
||||
" PAGE DATA\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
rc = sqlitepager_write(pPage);
|
||||
pPage = sqlite3TextToPtr(argv[1]);
|
||||
rc = sqlite3pager_write(pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
strncpy((char*)pPage, argv[2], SQLITE_PAGE_SIZE-1);
|
||||
((char*)pPage)[SQLITE_PAGE_SIZE-1] = 0;
|
||||
strncpy((char*)pPage, argv[2], test_pagesize-1);
|
||||
((char*)pPage)[test_pagesize-1] = 0;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
/*
|
||||
** Usage: fake_big_file N FILENAME
|
||||
**
|
||||
@@ -490,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 ){
|
||||
@@ -499,32 +532,36 @@ static int fake_big_file(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
|
||||
rc = sqliteOsOpenReadWrite(argv[2], &fd, &readOnly);
|
||||
memset(&fd, 0, sizeof(fd));
|
||||
rc = sqlite3OsOpenReadWrite(argv[2], &fd, &readOnly);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "open failed: ", errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
offset = n;
|
||||
offset *= 1024*1024;
|
||||
rc = sqliteOsSeek(&fd, offset);
|
||||
rc = sqlite3OsSeek(&fd, offset);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "seek failed: ", errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqliteOsWrite(&fd, "Hello, World!", 14);
|
||||
sqliteOsClose(&fd);
|
||||
rc = sqlite3OsWrite(&fd, "Hello, World!", 14);
|
||||
sqlite3OsClose(&fd);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "write failed: ", errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
extern int sqlite_io_error_pending;
|
||||
extern int sqlite3_io_error_pending;
|
||||
extern int sqlite3_diskfull_pending;
|
||||
extern int sqlite3_diskfull;
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_CmdProc *xProc;
|
||||
@@ -533,9 +570,9 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
{ "pager_close", (Tcl_CmdProc*)pager_close },
|
||||
{ "pager_commit", (Tcl_CmdProc*)pager_commit },
|
||||
{ "pager_rollback", (Tcl_CmdProc*)pager_rollback },
|
||||
{ "pager_ckpt_begin", (Tcl_CmdProc*)pager_ckpt_begin },
|
||||
{ "pager_ckpt_commit", (Tcl_CmdProc*)pager_ckpt_commit },
|
||||
{ "pager_ckpt_rollback", (Tcl_CmdProc*)pager_ckpt_rollback },
|
||||
{ "pager_stmt_begin", (Tcl_CmdProc*)pager_stmt_begin },
|
||||
{ "pager_stmt_commit", (Tcl_CmdProc*)pager_stmt_commit },
|
||||
{ "pager_stmt_rollback", (Tcl_CmdProc*)pager_stmt_rollback },
|
||||
{ "pager_stats", (Tcl_CmdProc*)pager_stats },
|
||||
{ "pager_pagecount", (Tcl_CmdProc*)pager_pagecount },
|
||||
{ "page_get", (Tcl_CmdProc*)page_get },
|
||||
@@ -544,17 +581,24 @@ 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++){
|
||||
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
||||
}
|
||||
Tcl_LinkVar(interp, "sqlite_io_error_pending",
|
||||
(char*)&sqlite_io_error_pending, TCL_LINK_INT);
|
||||
#ifdef SQLITE_TEST
|
||||
Tcl_LinkVar(interp, "journal_format",
|
||||
(char*)&journal_format, TCL_LINK_INT);
|
||||
#endif
|
||||
(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;
|
||||
}
|
||||
|
||||
+603
-137
File diff suppressed because it is too large
Load Diff
+647
@@ -0,0 +1,647 @@
|
||||
/*
|
||||
** 2003 December 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.
|
||||
**
|
||||
*************************************************************************
|
||||
** Code for testing the the SQLite library in a multithreaded environment.
|
||||
**
|
||||
** $Id: test4.c,v 1.13 2005/08/11 02:10:19 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
#include "os.h"
|
||||
#if defined(OS_UNIX) && OS_UNIX==1 && defined(THREADSAFE) && THREADSAFE==1
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
** Each thread is controlled by an instance of the following
|
||||
** structure.
|
||||
*/
|
||||
typedef struct Thread Thread;
|
||||
struct Thread {
|
||||
/* The first group of fields are writable by the master and read-only
|
||||
** to the thread. */
|
||||
char *zFilename; /* Name of database file */
|
||||
void (*xOp)(Thread*); /* next operation to do */
|
||||
char *zArg; /* argument usable by xOp */
|
||||
int opnum; /* Operation number */
|
||||
int busy; /* True if this thread is in use */
|
||||
|
||||
/* The next group of fields are writable by the thread but read-only to the
|
||||
** master. */
|
||||
int completed; /* Number of operations completed */
|
||||
sqlite3 *db; /* Open database */
|
||||
sqlite3_stmt *pStmt; /* Pending operation */
|
||||
char *zErr; /* operation error */
|
||||
char *zStaticErr; /* Static error message */
|
||||
int rc; /* operation return code */
|
||||
int argc; /* number of columns in result */
|
||||
const char *argv[100]; /* result columns */
|
||||
const char *colv[100]; /* result column names */
|
||||
};
|
||||
|
||||
/*
|
||||
** There can be as many as 26 threads running at once. Each is named
|
||||
** by a capital letter: A, B, C, ..., Y, Z.
|
||||
*/
|
||||
#define N_THREAD 26
|
||||
static Thread threadset[N_THREAD];
|
||||
|
||||
|
||||
/*
|
||||
** The main loop for a thread. Threads use busy waiting.
|
||||
*/
|
||||
static void *thread_main(void *pArg){
|
||||
Thread *p = (Thread*)pArg;
|
||||
if( p->db ){
|
||||
sqlite3_close(p->db);
|
||||
}
|
||||
sqlite3_open(p->zFilename, &p->db);
|
||||
if( SQLITE_OK!=sqlite3_errcode(p->db) ){
|
||||
p->zErr = strdup(sqlite3_errmsg(p->db));
|
||||
sqlite3_close(p->db);
|
||||
p->db = 0;
|
||||
}
|
||||
p->pStmt = 0;
|
||||
p->completed = 1;
|
||||
while( p->opnum<=p->completed ) sched_yield();
|
||||
while( p->xOp ){
|
||||
if( p->zErr && p->zErr!=p->zStaticErr ){
|
||||
sqlite3_free(p->zErr);
|
||||
p->zErr = 0;
|
||||
}
|
||||
(*p->xOp)(p);
|
||||
p->completed++;
|
||||
while( p->opnum<=p->completed ) sched_yield();
|
||||
}
|
||||
if( p->pStmt ){
|
||||
sqlite3_finalize(p->pStmt);
|
||||
p->pStmt = 0;
|
||||
}
|
||||
if( p->db ){
|
||||
sqlite3_close(p->db);
|
||||
p->db = 0;
|
||||
}
|
||||
if( p->zErr && p->zErr!=p->zStaticErr ){
|
||||
sqlite3_free(p->zErr);
|
||||
p->zErr = 0;
|
||||
}
|
||||
p->completed++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Get a thread ID which is an upper case letter. Return the index.
|
||||
** If the argument is not a valid thread ID put an error message in
|
||||
** the interpreter and return -1.
|
||||
*/
|
||||
static int parse_thread_id(Tcl_Interp *interp, const char *zArg){
|
||||
if( zArg==0 || zArg[0]==0 || zArg[1]!=0 || !isupper((unsigned char)zArg[0]) ){
|
||||
Tcl_AppendResult(interp, "thread ID must be an upper case letter", 0);
|
||||
return -1;
|
||||
}
|
||||
return zArg[0] - 'A';
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_create NAME FILENAME
|
||||
**
|
||||
** NAME should be an upper case letter. Start the thread running with
|
||||
** an open connection to the given database.
|
||||
*/
|
||||
static int tcl_thread_create(
|
||||
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 i;
|
||||
pthread_t x;
|
||||
int rc;
|
||||
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID FILENAME", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "thread ", argv[1], " is already running", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
threadset[i].busy = 1;
|
||||
sqliteFree(threadset[i].zFilename);
|
||||
threadset[i].zFilename = sqliteStrDup(argv[2]);
|
||||
threadset[i].opnum = 1;
|
||||
threadset[i].completed = 0;
|
||||
rc = pthread_create(&x, 0, thread_main, &threadset[i]);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "failed to create the thread", 0);
|
||||
sqliteFree(threadset[i].zFilename);
|
||||
threadset[i].busy = 0;
|
||||
return TCL_ERROR;
|
||||
}
|
||||
pthread_detach(x);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Wait for a thread to reach its idle state.
|
||||
*/
|
||||
static void thread_wait(Thread *p){
|
||||
while( p->opnum>p->completed ) sched_yield();
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_wait ID
|
||||
**
|
||||
** Wait on thread ID to reach its idle state.
|
||||
*/
|
||||
static int tcl_thread_wait(
|
||||
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 i;
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[i]);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Stop a thread.
|
||||
*/
|
||||
static void stop_thread(Thread *p){
|
||||
thread_wait(p);
|
||||
p->xOp = 0;
|
||||
p->opnum++;
|
||||
thread_wait(p);
|
||||
sqliteFree(p->zArg);
|
||||
p->zArg = 0;
|
||||
sqliteFree(p->zFilename);
|
||||
p->zFilename = 0;
|
||||
p->busy = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_halt ID
|
||||
**
|
||||
** Cause a thread to shut itself down. Wait for the shutdown to be
|
||||
** completed. If ID is "*" then stop all threads.
|
||||
*/
|
||||
static int tcl_thread_halt(
|
||||
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 i;
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( argv[1][0]=='*' && argv[1][1]==0 ){
|
||||
for(i=0; i<N_THREAD; i++){
|
||||
if( threadset[i].busy ) stop_thread(&threadset[i]);
|
||||
}
|
||||
}else{
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
stop_thread(&threadset[i]);
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_argc ID
|
||||
**
|
||||
** Wait on the most recent thread_step to complete, then return the
|
||||
** number of columns in the result set.
|
||||
*/
|
||||
static int tcl_thread_argc(
|
||||
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 i;
|
||||
char zBuf[100];
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[i]);
|
||||
sprintf(zBuf, "%d", threadset[i].argc);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_argv ID N
|
||||
**
|
||||
** Wait on the most recent thread_step to complete, then return the
|
||||
** value of the N-th columns in the result set.
|
||||
*/
|
||||
static int tcl_thread_argv(
|
||||
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 i;
|
||||
int n;
|
||||
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID N", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
|
||||
thread_wait(&threadset[i]);
|
||||
if( n<0 || n>=threadset[i].argc ){
|
||||
Tcl_AppendResult(interp, "column number out of range", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
Tcl_AppendResult(interp, threadset[i].argv[n], 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_colname ID N
|
||||
**
|
||||
** Wait on the most recent thread_step to complete, then return the
|
||||
** name of the N-th columns in the result set.
|
||||
*/
|
||||
static int tcl_thread_colname(
|
||||
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 i;
|
||||
int n;
|
||||
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID N", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
|
||||
thread_wait(&threadset[i]);
|
||||
if( n<0 || n>=threadset[i].argc ){
|
||||
Tcl_AppendResult(interp, "column number out of range", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
Tcl_AppendResult(interp, threadset[i].colv[n], 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_result ID
|
||||
**
|
||||
** Wait on the most recent operation to complete, then return the
|
||||
** result code from that operation.
|
||||
*/
|
||||
static int tcl_thread_result(
|
||||
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 i;
|
||||
const char *zName;
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[i]);
|
||||
switch( threadset[i].rc ){
|
||||
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
||||
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
||||
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
||||
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
||||
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
||||
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
|
||||
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
|
||||
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
|
||||
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
||||
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
||||
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; 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_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
|
||||
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
|
||||
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
|
||||
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
|
||||
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
|
||||
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
|
||||
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
|
||||
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
|
||||
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
|
||||
default: zName = "SQLITE_Unknown"; break;
|
||||
}
|
||||
Tcl_AppendResult(interp, zName, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_error ID
|
||||
**
|
||||
** Wait on the most recent operation to complete, then return the
|
||||
** error string.
|
||||
*/
|
||||
static int tcl_thread_error(
|
||||
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 i;
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[i]);
|
||||
Tcl_AppendResult(interp, threadset[i].zErr, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This procedure runs in the thread to compile an SQL statement.
|
||||
*/
|
||||
static void do_compile(Thread *p){
|
||||
if( p->db==0 ){
|
||||
p->zErr = p->zStaticErr = "no database is open";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
if( p->pStmt ){
|
||||
sqlite3_finalize(p->pStmt);
|
||||
p->pStmt = 0;
|
||||
}
|
||||
p->rc = sqlite3_prepare(p->db, p->zArg, -1, &p->pStmt, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_compile ID SQL
|
||||
**
|
||||
** Compile a new virtual machine.
|
||||
*/
|
||||
static int tcl_thread_compile(
|
||||
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 i;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID SQL", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[i]);
|
||||
threadset[i].xOp = do_compile;
|
||||
sqliteFree(threadset[i].zArg);
|
||||
threadset[i].zArg = sqliteStrDup(argv[2]);
|
||||
threadset[i].opnum++;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This procedure runs in the thread to step the virtual machine.
|
||||
*/
|
||||
static void do_step(Thread *p){
|
||||
int i;
|
||||
if( p->pStmt==0 ){
|
||||
p->zErr = p->zStaticErr = "no virtual machine available";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
p->rc = sqlite3_step(p->pStmt);
|
||||
if( p->rc==SQLITE_ROW ){
|
||||
p->argc = sqlite3_column_count(p->pStmt);
|
||||
for(i=0; i<sqlite3_data_count(p->pStmt); i++){
|
||||
p->argv[i] = sqlite3_column_text(p->pStmt, i);
|
||||
}
|
||||
for(i=0; i<p->argc; i++){
|
||||
p->colv[i] = sqlite3_column_name(p->pStmt, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_step ID
|
||||
**
|
||||
** Advance the virtual machine by one step
|
||||
*/
|
||||
static int tcl_thread_step(
|
||||
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 i;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" IDL", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[i]);
|
||||
threadset[i].xOp = do_step;
|
||||
threadset[i].opnum++;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This procedure runs in the thread to finalize a virtual machine.
|
||||
*/
|
||||
static void do_finalize(Thread *p){
|
||||
if( p->pStmt==0 ){
|
||||
p->zErr = p->zStaticErr = "no virtual machine available";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
p->rc = sqlite3_finalize(p->pStmt);
|
||||
p->pStmt = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_finalize ID
|
||||
**
|
||||
** Finalize the virtual machine.
|
||||
*/
|
||||
static int tcl_thread_finalize(
|
||||
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 i;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" IDL", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[i]);
|
||||
threadset[i].xOp = do_finalize;
|
||||
sqliteFree(threadset[i].zArg);
|
||||
threadset[i].zArg = 0;
|
||||
threadset[i].opnum++;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: thread_swap ID ID
|
||||
**
|
||||
** Interchange the sqlite* pointer between two threads.
|
||||
*/
|
||||
static int tcl_thread_swap(
|
||||
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 i, j;
|
||||
sqlite3 *temp;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID1 ID2", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
i = parse_thread_id(interp, argv[1]);
|
||||
if( i<0 ) return TCL_ERROR;
|
||||
if( !threadset[i].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[i]);
|
||||
j = parse_thread_id(interp, argv[2]);
|
||||
if( j<0 ) return TCL_ERROR;
|
||||
if( !threadset[j].busy ){
|
||||
Tcl_AppendResult(interp, "no such thread", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
thread_wait(&threadset[j]);
|
||||
temp = threadset[i].db;
|
||||
threadset[i].db = threadset[j].db;
|
||||
threadset[j].db = temp;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest4_Init(Tcl_Interp *interp){
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_CmdProc *xProc;
|
||||
} aCmd[] = {
|
||||
{ "thread_create", (Tcl_CmdProc*)tcl_thread_create },
|
||||
{ "thread_wait", (Tcl_CmdProc*)tcl_thread_wait },
|
||||
{ "thread_halt", (Tcl_CmdProc*)tcl_thread_halt },
|
||||
{ "thread_argc", (Tcl_CmdProc*)tcl_thread_argc },
|
||||
{ "thread_argv", (Tcl_CmdProc*)tcl_thread_argv },
|
||||
{ "thread_colname", (Tcl_CmdProc*)tcl_thread_colname },
|
||||
{ "thread_result", (Tcl_CmdProc*)tcl_thread_result },
|
||||
{ "thread_error", (Tcl_CmdProc*)tcl_thread_error },
|
||||
{ "thread_compile", (Tcl_CmdProc*)tcl_thread_compile },
|
||||
{ "thread_step", (Tcl_CmdProc*)tcl_thread_step },
|
||||
{ "thread_finalize", (Tcl_CmdProc*)tcl_thread_finalize },
|
||||
{ "thread_swap", (Tcl_CmdProc*)tcl_thread_swap },
|
||||
};
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
||||
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
#else
|
||||
int Sqlitetest4_Init(Tcl_Interp *interp){ return TCL_OK; }
|
||||
#endif /* OS_UNIX */
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
** Code for testing the utf.c module in SQLite. This code
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library. Specifically, the code in this file
|
||||
** is used for testing the SQLite routines for converting between
|
||||
** the various supported unicode encodings.
|
||||
**
|
||||
** $Id: test5.c,v 1.14 2004/11/14 21:56:30 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
#include "os.h" /* to get SQLITE_BIGENDIAN */
|
||||
#include "tcl.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
** The first argument is a TCL UTF-8 string. Return the byte array
|
||||
** object with the encoded representation of the string, including
|
||||
** the NULL terminator.
|
||||
*/
|
||||
static int binarize(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int len;
|
||||
char *bytes;
|
||||
Tcl_Obj *pRet;
|
||||
assert(objc==2);
|
||||
|
||||
bytes = Tcl_GetStringFromObj(objv[1], &len);
|
||||
pRet = Tcl_NewByteArrayObj(bytes, len+1);
|
||||
Tcl_SetObjResult(interp, pRet);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: test_value_overhead <repeat-count> <do-calls>.
|
||||
**
|
||||
** This routine is used to test the overhead of calls to
|
||||
** sqlite3_value_text(), on a value that contains a UTF-8 string. The idea
|
||||
** is to figure out whether or not it is a problem to use sqlite3_value
|
||||
** structures with collation sequence functions.
|
||||
**
|
||||
** If <do-calls> is 0, then the calls to sqlite3_value_text() are not
|
||||
** actually made.
|
||||
*/
|
||||
static int test_value_overhead(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int do_calls;
|
||||
int repeat_count;
|
||||
int i;
|
||||
Mem val;
|
||||
const char *zVal;
|
||||
|
||||
if( objc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0), " <repeat-count> <do-calls>", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], &repeat_count) ) return TCL_ERROR;
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &do_calls) ) return TCL_ERROR;
|
||||
|
||||
val.flags = MEM_Str|MEM_Term|MEM_Static;
|
||||
val.z = "hello world";
|
||||
val.type = SQLITE_TEXT;
|
||||
val.enc = SQLITE_UTF8;
|
||||
|
||||
for(i=0; i<repeat_count; i++){
|
||||
if( do_calls ){
|
||||
zVal = sqlite3_value_text(&val);
|
||||
}
|
||||
}
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
static u8 name_to_enc(Tcl_Interp *interp, Tcl_Obj *pObj){
|
||||
struct EncName {
|
||||
char *zName;
|
||||
u8 enc;
|
||||
} encnames[] = {
|
||||
{ "UTF8", SQLITE_UTF8 },
|
||||
{ "UTF16LE", SQLITE_UTF16LE },
|
||||
{ "UTF16BE", SQLITE_UTF16BE },
|
||||
{ "UTF16", SQLITE_UTF16NATIVE },
|
||||
{ 0, 0 }
|
||||
};
|
||||
struct EncName *pEnc;
|
||||
char *z = Tcl_GetString(pObj);
|
||||
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
|
||||
if( 0==sqlite3StrICmp(z, pEnc->zName) ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !pEnc->enc ){
|
||||
Tcl_AppendResult(interp, "No such encoding: ", z, 0);
|
||||
}
|
||||
return pEnc->enc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: test_translate <string/blob> <from enc> <to enc> ?<transient>?
|
||||
**
|
||||
*/
|
||||
static int test_translate(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
u8 enc_from;
|
||||
u8 enc_to;
|
||||
sqlite3_value *pVal;
|
||||
|
||||
char *z;
|
||||
int len;
|
||||
void (*xDel)(void *p) = SQLITE_STATIC;
|
||||
|
||||
if( objc!=4 && objc!=5 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0),
|
||||
" <string/blob> <from enc> <to enc>", 0
|
||||
);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( objc==5 ){
|
||||
xDel = sqlite3FreeX;
|
||||
}
|
||||
|
||||
enc_from = name_to_enc(interp, objv[2]);
|
||||
if( !enc_from ) return TCL_ERROR;
|
||||
enc_to = name_to_enc(interp, objv[3]);
|
||||
if( !enc_to ) return TCL_ERROR;
|
||||
|
||||
pVal = sqlite3ValueNew();
|
||||
|
||||
if( enc_from==SQLITE_UTF8 ){
|
||||
z = Tcl_GetString(objv[1]);
|
||||
if( objc==5 ){
|
||||
z = sqliteStrDup(z);
|
||||
}
|
||||
sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel);
|
||||
}else{
|
||||
z = Tcl_GetByteArrayFromObj(objv[1], &len);
|
||||
if( objc==5 ){
|
||||
char *zTmp = z;
|
||||
z = sqliteMalloc(len);
|
||||
memcpy(z, zTmp, len);
|
||||
}
|
||||
sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel);
|
||||
}
|
||||
|
||||
z = (char *)sqlite3ValueText(pVal, enc_to);
|
||||
len = sqlite3ValueBytes(pVal, enc_to) + (enc_to==SQLITE_UTF8?1:2);
|
||||
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(z, len));
|
||||
|
||||
sqlite3ValueFree(pVal);
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: translate_selftest
|
||||
**
|
||||
** Call sqlite3utfSelfTest() to run the internal tests for unicode
|
||||
** translation. If there is a problem an assert() will fail.
|
||||
**/
|
||||
void sqlite3utfSelfTest();
|
||||
static int test_translate_selftest(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
sqlite3utfSelfTest();
|
||||
#endif
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest5_Init(Tcl_Interp *interp){
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_ObjCmdProc *xProc;
|
||||
} aCmd[] = {
|
||||
{ "binarize", (Tcl_ObjCmdProc*)binarize },
|
||||
{ "test_value_overhead", (Tcl_ObjCmdProc*)test_value_overhead },
|
||||
{ "test_translate", (Tcl_ObjCmdProc*)test_translate },
|
||||
{ "translate_selftest", (Tcl_ObjCmdProc*)test_translate_selftest},
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
||||
Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
+163
-410
@@ -15,7 +15,7 @@
|
||||
** individual tokens and sends those tokens one-by-one over to the
|
||||
** parser for analysis.
|
||||
**
|
||||
** $Id: tokenize.c,v 1.64 2003/09/27 13:39:39 drh Exp $
|
||||
** $Id: tokenize.c,v 1.107 2005/08/23 11:31:26 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -23,202 +23,56 @@
|
||||
#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 */
|
||||
u16 len; /* Number of characters in the keyword */
|
||||
u16 tokenType; /* The token value for this keyword */
|
||||
Keyword *pNext; /* Next keyword with the same hash */
|
||||
};
|
||||
|
||||
/*
|
||||
** These are the keywords
|
||||
*/
|
||||
static Keyword aKeywordTable[] = {
|
||||
{ "ABORT", 0, TK_ABORT, 0 },
|
||||
{ "AFTER", 0, TK_AFTER, 0 },
|
||||
{ "ALL", 0, TK_ALL, 0 },
|
||||
{ "AND", 0, TK_AND, 0 },
|
||||
{ "AS", 0, TK_AS, 0 },
|
||||
{ "ASC", 0, TK_ASC, 0 },
|
||||
{ "ATTACH", 0, TK_ATTACH, 0 },
|
||||
{ "BEFORE", 0, TK_BEFORE, 0 },
|
||||
{ "BEGIN", 0, TK_BEGIN, 0 },
|
||||
{ "BETWEEN", 0, TK_BETWEEN, 0 },
|
||||
{ "BY", 0, TK_BY, 0 },
|
||||
{ "CASCADE", 0, TK_CASCADE, 0 },
|
||||
{ "CASE", 0, TK_CASE, 0 },
|
||||
{ "CHECK", 0, TK_CHECK, 0 },
|
||||
{ "CLUSTER", 0, TK_CLUSTER, 0 },
|
||||
{ "COLLATE", 0, TK_COLLATE, 0 },
|
||||
{ "COMMIT", 0, TK_COMMIT, 0 },
|
||||
{ "CONFLICT", 0, TK_CONFLICT, 0 },
|
||||
{ "CONSTRAINT", 0, TK_CONSTRAINT, 0 },
|
||||
{ "COPY", 0, TK_COPY, 0 },
|
||||
{ "CREATE", 0, TK_CREATE, 0 },
|
||||
{ "CROSS", 0, TK_JOIN_KW, 0 },
|
||||
{ "DATABASE", 0, TK_DATABASE, 0 },
|
||||
{ "DEFAULT", 0, TK_DEFAULT, 0 },
|
||||
{ "DEFERRED", 0, TK_DEFERRED, 0 },
|
||||
{ "DEFERRABLE", 0, TK_DEFERRABLE, 0 },
|
||||
{ "DELETE", 0, TK_DELETE, 0 },
|
||||
{ "DELIMITERS", 0, TK_DELIMITERS, 0 },
|
||||
{ "DESC", 0, TK_DESC, 0 },
|
||||
{ "DETACH", 0, TK_DETACH, 0 },
|
||||
{ "DISTINCT", 0, TK_DISTINCT, 0 },
|
||||
{ "DROP", 0, TK_DROP, 0 },
|
||||
{ "END", 0, TK_END, 0 },
|
||||
{ "EACH", 0, TK_EACH, 0 },
|
||||
{ "ELSE", 0, TK_ELSE, 0 },
|
||||
{ "EXCEPT", 0, TK_EXCEPT, 0 },
|
||||
{ "EXPLAIN", 0, TK_EXPLAIN, 0 },
|
||||
{ "FAIL", 0, TK_FAIL, 0 },
|
||||
{ "FOR", 0, TK_FOR, 0 },
|
||||
{ "FOREIGN", 0, TK_FOREIGN, 0 },
|
||||
{ "FROM", 0, TK_FROM, 0 },
|
||||
{ "FULL", 0, TK_JOIN_KW, 0 },
|
||||
{ "GLOB", 0, TK_GLOB, 0 },
|
||||
{ "GROUP", 0, TK_GROUP, 0 },
|
||||
{ "HAVING", 0, TK_HAVING, 0 },
|
||||
{ "IGNORE", 0, TK_IGNORE, 0 },
|
||||
{ "IMMEDIATE", 0, TK_IMMEDIATE, 0 },
|
||||
{ "IN", 0, TK_IN, 0 },
|
||||
{ "INDEX", 0, TK_INDEX, 0 },
|
||||
{ "INITIALLY", 0, TK_INITIALLY, 0 },
|
||||
{ "INNER", 0, TK_JOIN_KW, 0 },
|
||||
{ "INSERT", 0, TK_INSERT, 0 },
|
||||
{ "INSTEAD", 0, TK_INSTEAD, 0 },
|
||||
{ "INTERSECT", 0, TK_INTERSECT, 0 },
|
||||
{ "INTO", 0, TK_INTO, 0 },
|
||||
{ "IS", 0, TK_IS, 0 },
|
||||
{ "ISNULL", 0, TK_ISNULL, 0 },
|
||||
{ "JOIN", 0, TK_JOIN, 0 },
|
||||
{ "KEY", 0, TK_KEY, 0 },
|
||||
{ "LEFT", 0, TK_JOIN_KW, 0 },
|
||||
{ "LIKE", 0, TK_LIKE, 0 },
|
||||
{ "LIMIT", 0, TK_LIMIT, 0 },
|
||||
{ "MATCH", 0, TK_MATCH, 0 },
|
||||
{ "NATURAL", 0, TK_JOIN_KW, 0 },
|
||||
{ "NOT", 0, TK_NOT, 0 },
|
||||
{ "NOTNULL", 0, TK_NOTNULL, 0 },
|
||||
{ "NULL", 0, TK_NULL, 0 },
|
||||
{ "OF", 0, TK_OF, 0 },
|
||||
{ "OFFSET", 0, TK_OFFSET, 0 },
|
||||
{ "ON", 0, TK_ON, 0 },
|
||||
{ "OR", 0, TK_OR, 0 },
|
||||
{ "ORDER", 0, TK_ORDER, 0 },
|
||||
{ "OUTER", 0, TK_JOIN_KW, 0 },
|
||||
{ "PRAGMA", 0, TK_PRAGMA, 0 },
|
||||
{ "PRIMARY", 0, TK_PRIMARY, 0 },
|
||||
{ "RAISE", 0, TK_RAISE, 0 },
|
||||
{ "REFERENCES", 0, TK_REFERENCES, 0 },
|
||||
{ "REPLACE", 0, TK_REPLACE, 0 },
|
||||
{ "RESTRICT", 0, TK_RESTRICT, 0 },
|
||||
{ "RIGHT", 0, TK_JOIN_KW, 0 },
|
||||
{ "ROLLBACK", 0, TK_ROLLBACK, 0 },
|
||||
{ "ROW", 0, TK_ROW, 0 },
|
||||
{ "SELECT", 0, TK_SELECT, 0 },
|
||||
{ "SET", 0, TK_SET, 0 },
|
||||
{ "STATEMENT", 0, TK_STATEMENT, 0 },
|
||||
{ "TABLE", 0, TK_TABLE, 0 },
|
||||
{ "TEMP", 0, TK_TEMP, 0 },
|
||||
{ "TEMPORARY", 0, TK_TEMP, 0 },
|
||||
{ "THEN", 0, TK_THEN, 0 },
|
||||
{ "TRANSACTION", 0, TK_TRANSACTION, 0 },
|
||||
{ "TRIGGER", 0, TK_TRIGGER, 0 },
|
||||
{ "UNION", 0, TK_UNION, 0 },
|
||||
{ "UNIQUE", 0, TK_UNIQUE, 0 },
|
||||
{ "UPDATE", 0, TK_UPDATE, 0 },
|
||||
{ "USING", 0, TK_USING, 0 },
|
||||
{ "VACUUM", 0, TK_VACUUM, 0 },
|
||||
{ "VALUES", 0, TK_VALUES, 0 },
|
||||
{ "VIEW", 0, TK_VIEW, 0 },
|
||||
{ "WHEN", 0, TK_WHEN, 0 },
|
||||
{ "WHERE", 0, TK_WHERE, 0 },
|
||||
};
|
||||
|
||||
/*
|
||||
** This is the hash table
|
||||
*/
|
||||
#define KEY_HASH_SIZE 71
|
||||
static Keyword *apHashTable[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 sqliteKeywordCode(const char *z, int n){
|
||||
int h;
|
||||
Keyword *p;
|
||||
if( aKeywordTable[0].len==0 ){
|
||||
/* Initialize the keyword hash table */
|
||||
sqliteOsEnterMutex();
|
||||
if( aKeywordTable[0].len==0 ){
|
||||
int i;
|
||||
int n;
|
||||
n = sizeof(aKeywordTable)/sizeof(aKeywordTable[0]);
|
||||
for(i=0; i<n; i++){
|
||||
aKeywordTable[i].len = strlen(aKeywordTable[i].zName);
|
||||
h = sqliteHashNoCase(aKeywordTable[i].zName, aKeywordTable[i].len);
|
||||
h %= KEY_HASH_SIZE;
|
||||
aKeywordTable[i].pNext = apHashTable[h];
|
||||
apHashTable[h] = &aKeywordTable[i];
|
||||
}
|
||||
}
|
||||
sqliteOsLeaveMutex();
|
||||
}
|
||||
h = sqliteHashNoCase(z, n) % KEY_HASH_SIZE;
|
||||
for(p=apHashTable[h]; p; p=p->pNext){
|
||||
if( p->len==n && sqliteStrNICmp(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 then
|
||||
** isIdChar[X] will be 1. Otherwise isIdChar[X] will be 0.
|
||||
** If X is a character that can be used in an identifier and
|
||||
** 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). sqlite3IsIdChar[X] will
|
||||
** be 0 for every character in the lower 128 ASCII characters
|
||||
** that cannot be used as part of an identifier.
|
||||
**
|
||||
** In this implementation, an identifier can be a string of
|
||||
** alphabetic characters, digits, and "_" plus any character
|
||||
** 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 */
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 8x */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 9x */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Ax */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Bx */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Cx */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Dx */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Ex */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Fx */
|
||||
};
|
||||
|
||||
#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++){}
|
||||
@@ -227,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;
|
||||
}
|
||||
@@ -259,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;
|
||||
}
|
||||
@@ -273,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{
|
||||
@@ -288,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{
|
||||
@@ -329,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{
|
||||
@@ -340,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;
|
||||
}
|
||||
@@ -366,29 +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;
|
||||
for(i=1; isdigit(z[i]); i++){}
|
||||
return i;
|
||||
}
|
||||
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;
|
||||
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{
|
||||
*tokenType = TK_ILLEGAL;
|
||||
}
|
||||
break;
|
||||
}else if( c==':' && z[i+1]==':' ){
|
||||
i++;
|
||||
#endif
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( n==0 ) *tokenType = TK_ILLEGAL;
|
||||
return i;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_BLOB_LITERAL
|
||||
case 'x': case 'X': {
|
||||
if( (c=z[1])=='\'' || c=='"' ){
|
||||
int delim = c;
|
||||
*tokenType = TK_BLOB;
|
||||
for(i=2; (c=z[i])!=0; i++){
|
||||
if( c==delim ){
|
||||
if( i%2 ) *tokenType = TK_ILLEGAL;
|
||||
break;
|
||||
}
|
||||
if( !isxdigit(c) ){
|
||||
*tokenType = TK_ILLEGAL;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
if( c ) i++;
|
||||
return i;
|
||||
}
|
||||
/* Otherwise fall through to the next case */
|
||||
}
|
||||
#endif
|
||||
default: {
|
||||
if( !isIdChar[*z] ){
|
||||
if( !IdChar(*z) ){
|
||||
break;
|
||||
}
|
||||
for(i=1; isIdChar[z[i]]; i++){}
|
||||
*tokenType = sqliteKeywordCode((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
|
||||
@@ -397,46 +328,55 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
||||
** memory obtained from malloc() and *pzErrMsg made to point to that
|
||||
** error message. Or maybe not.
|
||||
*/
|
||||
int sqliteRunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
int nErr = 0;
|
||||
int i;
|
||||
void *pEngine;
|
||||
int tokenType;
|
||||
int lastTokenParsed = -1;
|
||||
sqlite *db = pParse->db;
|
||||
extern void *sqliteParserAlloc(void*(*)(int));
|
||||
extern void sqliteParserFree(void*, void(*)(void*));
|
||||
extern int sqliteParser(void*, int, Token, Parse*);
|
||||
sqlite3 *db = pParse->db;
|
||||
extern void *sqlite3ParserAlloc(void*(*)(int));
|
||||
extern void sqlite3ParserFree(void*, void(*)(void*));
|
||||
extern int sqlite3Parser(void*, int, Token, Parse*);
|
||||
|
||||
db->flags &= ~SQLITE_Interrupt;
|
||||
pParse->rc = SQLITE_OK;
|
||||
i = 0;
|
||||
pEngine = sqliteParserAlloc((void*(*)(int))malloc);
|
||||
pEngine = sqlite3ParserAlloc((void*(*)(int))sqlite3MallocX);
|
||||
if( pEngine==0 ){
|
||||
sqliteSetString(pzErrMsg, "out of memory", 0);
|
||||
return 1;
|
||||
sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pParse->sLastToken.dyn = 0;
|
||||
pParse->zTail = zSql;
|
||||
while( sqlite_malloc_failed==0 && zSql[i]!=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:
|
||||
case TK_COMMENT: {
|
||||
if( (db->flags & SQLITE_Interrupt)!=0 ){
|
||||
pParse->rc = SQLITE_INTERRUPT;
|
||||
sqliteSetString(pzErrMsg, "interrupt", 0);
|
||||
sqlite3SetString(pzErrMsg, "interrupt", (char*)0);
|
||||
goto abort_parse;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TK_ILLEGAL: {
|
||||
sqliteSetNString(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;
|
||||
}
|
||||
@@ -445,7 +385,7 @@ int sqliteRunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
/* Fall thru into the default case */
|
||||
}
|
||||
default: {
|
||||
sqliteParser(pEngine, tokenType, pParse->sLastToken, pParse);
|
||||
sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse);
|
||||
lastTokenParsed = tokenType;
|
||||
if( pParse->rc!=SQLITE_OK ){
|
||||
goto abort_parse;
|
||||
@@ -457,14 +397,18 @@ int sqliteRunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
abort_parse:
|
||||
if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
|
||||
if( lastTokenParsed!=TK_SEMI ){
|
||||
sqliteParser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
|
||||
sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
|
||||
pParse->zTail = &zSql[i];
|
||||
}
|
||||
sqliteParser(pEngine, 0, pParse->sLastToken, pParse);
|
||||
sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
|
||||
}
|
||||
sqlite3ParserFree(pEngine, sqlite3FreeX);
|
||||
if( sqlite3_malloc_failed ){
|
||||
pParse->rc = SQLITE_NOMEM;
|
||||
}
|
||||
sqliteParserFree(pEngine, free);
|
||||
if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
|
||||
sqliteSetString(&pParse->zErrMsg, sqlite_error_string(pParse->rc), 0);
|
||||
sqlite3SetString(&pParse->zErrMsg, sqlite3ErrStr(pParse->rc),
|
||||
(char*)0);
|
||||
}
|
||||
if( pParse->zErrMsg ){
|
||||
if( pzErrMsg && *pzErrMsg==0 ){
|
||||
@@ -475,206 +419,15 @@ abort_parse:
|
||||
pParse->zErrMsg = 0;
|
||||
if( !nErr ) nErr++;
|
||||
}
|
||||
if( pParse->pVdbe && (pParse->useCallback || pParse->nErr>0) ){
|
||||
sqliteVdbeDelete(pParse->pVdbe);
|
||||
if( pParse->pVdbe && pParse->nErr>0 && pParse->nested==0 ){
|
||||
sqlite3VdbeDelete(pParse->pVdbe);
|
||||
pParse->pVdbe = 0;
|
||||
}
|
||||
if( pParse->pNewTable ){
|
||||
sqliteDeleteTable(pParse->db, pParse->pNewTable);
|
||||
pParse->pNewTable = 0;
|
||||
}
|
||||
if( pParse->pNewTrigger ){
|
||||
sqliteDeleteTrigger(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 sqlite_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 sqlite_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 && sqliteStrNICmp(zSql, "create", 6)==0 ){
|
||||
token = tkCREATE;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 't': case 'T': {
|
||||
if( nId==7 && sqliteStrNICmp(zSql, "trigger", 7)==0 ){
|
||||
token = tkTRIGGER;
|
||||
}else if( nId==4 && sqliteStrNICmp(zSql, "temp", 4)==0 ){
|
||||
token = tkTEMP;
|
||||
}else if( nId==9 && sqliteStrNICmp(zSql, "temporary", 9)==0 ){
|
||||
token = tkTEMP;
|
||||
}else{
|
||||
token = tkOTHER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'e': case 'E': {
|
||||
if( nId==3 && sqliteStrNICmp(zSql, "end", 3)==0 ){
|
||||
token = tkEND;
|
||||
}else if( nId==7 && sqliteStrNICmp(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;
|
||||
}
|
||||
|
||||
+320
-280
@@ -12,19 +12,20 @@
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
/*
|
||||
** Delete a linked list of TriggerStep structures.
|
||||
*/
|
||||
void sqliteDeleteTriggerStep(TriggerStep *pTriggerStep){
|
||||
void sqlite3DeleteTriggerStep(TriggerStep *pTriggerStep){
|
||||
while( pTriggerStep ){
|
||||
TriggerStep * pTmp = pTriggerStep;
|
||||
pTriggerStep = pTriggerStep->pNext;
|
||||
|
||||
if( pTmp->target.dyn ) sqliteFree((char*)pTmp->target.z);
|
||||
sqliteExprDelete(pTmp->pWhere);
|
||||
sqliteExprListDelete(pTmp->pExprList);
|
||||
sqliteSelectDelete(pTmp->pSelect);
|
||||
sqliteIdListDelete(pTmp->pIdList);
|
||||
sqlite3ExprDelete(pTmp->pWhere);
|
||||
sqlite3ExprListDelete(pTmp->pExprList);
|
||||
sqlite3SelectDelete(pTmp->pSelect);
|
||||
sqlite3IdListDelete(pTmp->pIdList);
|
||||
|
||||
sqliteFree(pTmp);
|
||||
}
|
||||
@@ -35,12 +36,13 @@ void sqliteDeleteTriggerStep(TriggerStep *pTriggerStep){
|
||||
** up to the point of the BEGIN before the trigger actions. A Trigger
|
||||
** structure is generated based on the information available and stored
|
||||
** in pParse->pNewTrigger. After the trigger actions have been parsed, the
|
||||
** sqliteFinishTrigger() function is called to complete the trigger
|
||||
** sqlite3FinishTrigger() function is called to complete the trigger
|
||||
** construction process.
|
||||
*/
|
||||
void sqliteBeginTrigger(
|
||||
void sqlite3BeginTrigger(
|
||||
Parse *pParse, /* The parse context of the CREATE TRIGGER statement */
|
||||
Token *pName, /* The name of the trigger */
|
||||
Token *pName1, /* The name of the trigger */
|
||||
Token *pName2, /* The name of the trigger */
|
||||
int tr_tm, /* One of TK_BEFORE, TK_AFTER, TK_INSTEAD */
|
||||
int op, /* One of TK_INSERT, TK_UPDATE, TK_DELETE */
|
||||
IdList *pColumns, /* column list if this is an UPDATE OF trigger */
|
||||
@@ -49,76 +51,102 @@ void sqliteBeginTrigger(
|
||||
Expr *pWhen, /* WHEN clause */
|
||||
int isTemp /* True if the TEMPORARY keyword is present */
|
||||
){
|
||||
Trigger *nt;
|
||||
Table *tab;
|
||||
Trigger *pTrigger = 0;
|
||||
Table *pTab;
|
||||
char *zName = 0; /* Name of the trigger */
|
||||
sqlite *db = pParse->db;
|
||||
int iDb; /* When database to store the trigger in */
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb; /* The database to store the trigger in */
|
||||
Token *pName; /* The unqualified db name */
|
||||
DbFixer sFix;
|
||||
|
||||
/* Check that:
|
||||
** 1. the trigger name does not already exist.
|
||||
** 2. the table (or view) does exist in the same database as the trigger.
|
||||
** 3. that we are not trying to create a trigger on the sqlite_master table
|
||||
** 4. That we are not trying to create an INSTEAD OF trigger on a table.
|
||||
** 5. That we are not trying to create a BEFORE or AFTER trigger on a view.
|
||||
if( isTemp ){
|
||||
/* If TEMP was specified, then the trigger name may not be qualified. */
|
||||
if( pName2 && pName2->n>0 ){
|
||||
sqlite3ErrorMsg(pParse, "temporary trigger may not have qualified name");
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
iDb = 1;
|
||||
pName = pName1;
|
||||
}else{
|
||||
/* Figure out the db that the the trigger will be created in */
|
||||
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
|
||||
if( iDb<0 ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the trigger name was unqualified, and the table is a temp table,
|
||||
** then set iDb to 1 to create the trigger in the temporary database.
|
||||
** If sqlite3SrcListLookup() returns 0, indicating the table does not
|
||||
** exist, the error is caught by the block below.
|
||||
*/
|
||||
if( sqlite_malloc_failed ) goto trigger_cleanup;
|
||||
if( !pTableName || sqlite3_malloc_failed ) goto trigger_cleanup;
|
||||
pTab = sqlite3SrcListLookup(pParse, pTableName);
|
||||
if( pName2->n==0 && pTab && pTab->iDb==1 ){
|
||||
iDb = 1;
|
||||
}
|
||||
|
||||
/* Ensure the table name matches database name and that the table exists */
|
||||
if( sqlite3_malloc_failed ) goto trigger_cleanup;
|
||||
assert( pTableName->nSrc==1 );
|
||||
if( pParse->initFlag
|
||||
&& sqliteFixInit(&sFix, pParse, pParse->iDb, "trigger", pName)
|
||||
&& sqliteFixSrcList(&sFix, pTableName)
|
||||
){
|
||||
if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) &&
|
||||
sqlite3FixSrcList(&sFix, pTableName) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
tab = sqliteSrcListLookup(pParse, pTableName);
|
||||
if( !tab ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
iDb = isTemp ? 1 : tab->iDb;
|
||||
if( iDb>=2 && !pParse->initFlag ){
|
||||
sqliteErrorMsg(pParse, "triggers may not be added to auxiliary "
|
||||
"database %s", db->aDb[tab->iDb].zName);
|
||||
pTab = sqlite3SrcListLookup(pParse, pTableName);
|
||||
if( !pTab ){
|
||||
/* The table does not exist. */
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
|
||||
zName = sqliteStrNDup(pName->z, pName->n);
|
||||
sqliteDequote(zName);
|
||||
if( sqliteHashFind(&(db->aDb[iDb].trigHash), zName,pName->n+1) ){
|
||||
sqliteErrorMsg(pParse, "trigger %T already exists", pName);
|
||||
/* Check that the trigger name is not reserved and that no trigger of the
|
||||
** specified name exists */
|
||||
zName = sqlite3NameFromToken(pName);
|
||||
if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqliteStrNICmp(tab->zName, "sqlite_", 7)==0 ){
|
||||
sqliteErrorMsg(pParse, "cannot create trigger on system table");
|
||||
if( sqlite3HashFind(&(db->aDb[iDb].trigHash), zName,pName->n+1) ){
|
||||
sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
|
||||
/* Do not create a trigger on a system table */
|
||||
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
|
||||
sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
|
||||
pParse->nErr++;
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( tab->pSelect && tr_tm != TK_INSTEAD ){
|
||||
sqliteErrorMsg(pParse, "cannot create %s trigger on view: %S",
|
||||
|
||||
/* INSTEAD of triggers are only for views and views only support INSTEAD
|
||||
** of triggers.
|
||||
*/
|
||||
if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
|
||||
sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
|
||||
(tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( !tab->pSelect && tr_tm == TK_INSTEAD ){
|
||||
sqliteErrorMsg(pParse, "cannot create INSTEAD OF"
|
||||
if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
|
||||
sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
|
||||
" trigger on table: %S", pTableName, 0);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
int code = SQLITE_CREATE_TRIGGER;
|
||||
const char *zDb = db->aDb[tab->iDb].zName;
|
||||
const char *zDb = db->aDb[pTab->iDb].zName;
|
||||
const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
|
||||
if( tab->iDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
|
||||
if( sqliteAuthCheck(pParse, code, zName, tab->zName, zDbTrig) ){
|
||||
if( pTab->iDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
|
||||
if( sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqliteAuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(tab->iDb), 0, zDb)){
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(pTab->iDb),0,zDb)){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* INSTEAD OF triggers can only appear on views and BEGIN triggers
|
||||
/* INSTEAD OF triggers can only appear on views and BEFORE triggers
|
||||
** cannot appear on views. So we might as well translate every
|
||||
** INSTEAD OF trigger into a BEFORE trigger. It simplifies code
|
||||
** elsewhere.
|
||||
@@ -128,105 +156,114 @@ void sqliteBeginTrigger(
|
||||
}
|
||||
|
||||
/* Build the Trigger object */
|
||||
nt = (Trigger*)sqliteMalloc(sizeof(Trigger));
|
||||
if( nt==0 ) goto trigger_cleanup;
|
||||
nt->name = zName;
|
||||
pTrigger = (Trigger*)sqliteMalloc(sizeof(Trigger));
|
||||
if( pTrigger==0 ) goto trigger_cleanup;
|
||||
pTrigger->name = zName;
|
||||
zName = 0;
|
||||
nt->table = sqliteStrDup(pTableName->a[0].zName);
|
||||
if( sqlite_malloc_failed ) goto trigger_cleanup;
|
||||
nt->iDb = iDb;
|
||||
nt->iTabDb = tab->iDb;
|
||||
nt->op = op;
|
||||
nt->tr_tm = tr_tm;
|
||||
nt->pWhen = sqliteExprDup(pWhen);
|
||||
nt->pColumns = sqliteIdListDup(pColumns);
|
||||
nt->foreach = foreach;
|
||||
sqliteTokenCopy(&nt->nameToken,pName);
|
||||
pTrigger->table = sqliteStrDup(pTableName->a[0].zName);
|
||||
pTrigger->iDb = iDb;
|
||||
pTrigger->iTabDb = pTab->iDb;
|
||||
pTrigger->op = op;
|
||||
pTrigger->tr_tm = tr_tm==TK_BEFORE ? TRIGGER_BEFORE : TRIGGER_AFTER;
|
||||
pTrigger->pWhen = sqlite3ExprDup(pWhen);
|
||||
pTrigger->pColumns = sqlite3IdListDup(pColumns);
|
||||
pTrigger->foreach = foreach;
|
||||
sqlite3TokenCopy(&pTrigger->nameToken,pName);
|
||||
assert( pParse->pNewTrigger==0 );
|
||||
pParse->pNewTrigger = nt;
|
||||
pParse->pNewTrigger = pTrigger;
|
||||
|
||||
trigger_cleanup:
|
||||
sqliteFree(zName);
|
||||
sqliteSrcListDelete(pTableName);
|
||||
sqliteIdListDelete(pColumns);
|
||||
sqliteExprDelete(pWhen);
|
||||
sqlite3SrcListDelete(pTableName);
|
||||
sqlite3IdListDelete(pColumns);
|
||||
sqlite3ExprDelete(pWhen);
|
||||
if( !pParse->pNewTrigger ){
|
||||
sqlite3DeleteTrigger(pTrigger);
|
||||
}else{
|
||||
assert( pParse->pNewTrigger==pTrigger );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called after all of the trigger actions have been parsed
|
||||
** in order to complete the process of building the trigger.
|
||||
*/
|
||||
void sqliteFinishTrigger(
|
||||
void sqlite3FinishTrigger(
|
||||
Parse *pParse, /* Parser context */
|
||||
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( sqliteFixInit(&sFix, pParse, nt->iDb, "trigger", &nt->nameToken)
|
||||
&& sqliteFixTriggerStep(&sFix, nt->step_list) ){
|
||||
if( sqlite3FixInit(&sFix, pParse, pTrig->iDb, "trigger", &pTrig->nameToken)
|
||||
&& sqlite3FixTriggerStep(&sFix, pTrig->step_list) ){
|
||||
goto triggerfinish_cleanup;
|
||||
}
|
||||
|
||||
/* if we are not initializing, and this trigger is not on a TEMP table,
|
||||
** build the sqlite_master entry
|
||||
*/
|
||||
if( !pParse->initFlag ){
|
||||
static VdbeOp insertTrig[] = {
|
||||
{ OP_NewRecno, 0, 0, 0 },
|
||||
{ OP_String, 0, 0, "trigger" },
|
||||
{ OP_String, 0, 0, 0 }, /* 2: trigger name */
|
||||
{ OP_String, 0, 0, 0 }, /* 3: table name */
|
||||
if( !db->init.busy ){
|
||||
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 */
|
||||
{ OP_Integer, 0, 0, 0 },
|
||||
{ OP_String, 0, 0, 0 }, /* 5: SQL */
|
||||
{ OP_MakeRecord, 5, 0, 0 },
|
||||
{ OP_PutIntKey, 0, 0, 0 },
|
||||
{ OP_String8, 0, 0, "CREATE TRIGGER "},
|
||||
{ OP_String8, 0, 0, 0 }, /* 6: SQL */
|
||||
{ OP_Concat, 0, 0, 0 },
|
||||
{ OP_MakeRecord, 5, 0, "tttit" },
|
||||
{ OP_Insert, 0, 0, 0 },
|
||||
};
|
||||
int addr;
|
||||
Vdbe *v;
|
||||
|
||||
/* Make an entry in the sqlite_master table */
|
||||
v = sqliteGetVdbe(pParse);
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) goto triggerfinish_cleanup;
|
||||
sqliteBeginWriteOperation(pParse, 0, 0);
|
||||
sqliteOpenMasterTable(v, nt->iDb);
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(insertTrig), insertTrig);
|
||||
sqliteVdbeChangeP3(v, addr+2, nt->name, 0);
|
||||
sqliteVdbeChangeP3(v, addr+3, nt->table, 0);
|
||||
sqliteVdbeChangeP3(v, addr+5, pAll->z, pAll->n);
|
||||
if( nt->iDb==0 ){
|
||||
sqliteChangeCookie(db, v);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
sqlite3BeginWriteOperation(pParse, 0, pTrig->iDb);
|
||||
sqlite3OpenMasterTable(v, pTrig->iDb);
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(insertTrig), insertTrig);
|
||||
sqlite3VdbeChangeP3(v, addr+2, pTrig->name, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+3, pTrig->table, 0);
|
||||
sqlite3VdbeChangeP3(v, addr+6, pAll->z, pAll->n);
|
||||
sqlite3ChangeCookie(db, v, pTrig->iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqlite3VdbeOp3(v, OP_ParseSchema, pTrig->iDb, 0,
|
||||
sqlite3MPrintf("type='trigger' AND name='%q'", pTrig->name), P3_DYNAMIC);
|
||||
}
|
||||
|
||||
if( !pParse->explain ){
|
||||
if( db->init.busy ){
|
||||
Table *pTab;
|
||||
sqliteHashInsert(&db->aDb[nt->iDb].trigHash,
|
||||
nt->name, strlen(nt->name)+1, nt);
|
||||
pTab = sqliteLocateTable(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:
|
||||
sqliteDeleteTrigger(nt);
|
||||
sqliteDeleteTrigger(pParse->pNewTrigger);
|
||||
pParse->pNewTrigger = 0;
|
||||
sqliteDeleteTriggerStep(pStepList);
|
||||
sqlite3DeleteTrigger(pTrig);
|
||||
assert( !pParse->pNewTrigger );
|
||||
sqlite3DeleteTriggerStep(pStepList);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -234,10 +271,10 @@ triggerfinish_cleanup:
|
||||
** the effect of copying all Expr.token.z values into memory obtained
|
||||
** from sqliteMalloc(). As initially created, the Expr.token.z values
|
||||
** all point to the input string that was fed to the parser. But that
|
||||
** string is ephemeral - it will go away as soon as the sqlite_exec()
|
||||
** string is ephemeral - it will go away as soon as the sqlite3_exec()
|
||||
** call that started the parser exits. This routine makes a persistent
|
||||
** copy of all the Expr.token.z strings so that the TriggerStep structure
|
||||
** will be valid even after the sqlite_exec() call returns.
|
||||
** will be valid even after the sqlite3_exec() call returns.
|
||||
*/
|
||||
static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
if( p->target.z ){
|
||||
@@ -245,23 +282,23 @@ static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
p->target.dyn = 1;
|
||||
}
|
||||
if( p->pSelect ){
|
||||
Select *pNew = sqliteSelectDup(p->pSelect);
|
||||
sqliteSelectDelete(p->pSelect);
|
||||
Select *pNew = sqlite3SelectDup(p->pSelect);
|
||||
sqlite3SelectDelete(p->pSelect);
|
||||
p->pSelect = pNew;
|
||||
}
|
||||
if( p->pWhere ){
|
||||
Expr *pNew = sqliteExprDup(p->pWhere);
|
||||
sqliteExprDelete(p->pWhere);
|
||||
Expr *pNew = sqlite3ExprDup(p->pWhere);
|
||||
sqlite3ExprDelete(p->pWhere);
|
||||
p->pWhere = pNew;
|
||||
}
|
||||
if( p->pExprList ){
|
||||
ExprList *pNew = sqliteExprListDup(p->pExprList);
|
||||
sqliteExprListDelete(p->pExprList);
|
||||
ExprList *pNew = sqlite3ExprListDup(p->pExprList);
|
||||
sqlite3ExprListDelete(p->pExprList);
|
||||
p->pExprList = pNew;
|
||||
}
|
||||
if( p->pIdList ){
|
||||
IdList *pNew = sqliteIdListDup(p->pIdList);
|
||||
sqliteIdListDelete(p->pIdList);
|
||||
IdList *pNew = sqlite3IdListDup(p->pIdList);
|
||||
sqlite3IdListDelete(p->pIdList);
|
||||
p->pIdList = pNew;
|
||||
}
|
||||
}
|
||||
@@ -273,7 +310,7 @@ static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
** The parser calls this routine when it finds a SELECT statement in
|
||||
** body of a TRIGGER.
|
||||
*/
|
||||
TriggerStep *sqliteTriggerSelectStep(Select *pSelect){
|
||||
TriggerStep *sqlite3TriggerSelectStep(Select *pSelect){
|
||||
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
|
||||
if( pTriggerStep==0 ) return 0;
|
||||
|
||||
@@ -292,7 +329,7 @@ TriggerStep *sqliteTriggerSelectStep(Select *pSelect){
|
||||
** The parser calls this routine when it sees an INSERT inside the
|
||||
** body of a trigger.
|
||||
*/
|
||||
TriggerStep *sqliteTriggerInsertStep(
|
||||
TriggerStep *sqlite3TriggerInsertStep(
|
||||
Token *pTableName, /* Name of the table into which we insert */
|
||||
IdList *pColumn, /* List of columns in pTableName to insert into */
|
||||
ExprList *pEList, /* The VALUE clause: a list of values to be inserted */
|
||||
@@ -300,18 +337,23 @@ TriggerStep *sqliteTriggerInsertStep(
|
||||
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;
|
||||
}
|
||||
@@ -321,7 +363,7 @@ TriggerStep *sqliteTriggerInsertStep(
|
||||
** a pointer to that trigger step. The parser calls this routine when it
|
||||
** sees an UPDATE statement inside the body of a CREATE TRIGGER.
|
||||
*/
|
||||
TriggerStep *sqliteTriggerUpdateStep(
|
||||
TriggerStep *sqlite3TriggerUpdateStep(
|
||||
Token *pTableName, /* Name of the table to be updated */
|
||||
ExprList *pEList, /* The SET clause: list of column and new values */
|
||||
Expr *pWhere, /* The WHERE clause */
|
||||
@@ -345,7 +387,7 @@ TriggerStep *sqliteTriggerUpdateStep(
|
||||
** a pointer to that trigger step. The parser calls this routine when it
|
||||
** sees a DELETE statement inside the body of a CREATE TRIGGER.
|
||||
*/
|
||||
TriggerStep *sqliteTriggerDeleteStep(Token *pTableName, Expr *pWhere){
|
||||
TriggerStep *sqlite3TriggerDeleteStep(Token *pTableName, Expr *pWhere){
|
||||
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
|
||||
if( pTriggerStep==0 ) return 0;
|
||||
|
||||
@@ -361,86 +403,91 @@ TriggerStep *sqliteTriggerDeleteStep(Token *pTableName, Expr *pWhere){
|
||||
/*
|
||||
** Recursively delete a Trigger structure
|
||||
*/
|
||||
void sqliteDeleteTrigger(Trigger *pTrigger){
|
||||
void sqlite3DeleteTrigger(Trigger *pTrigger){
|
||||
if( pTrigger==0 ) return;
|
||||
sqliteDeleteTriggerStep(pTrigger->step_list);
|
||||
sqlite3DeleteTriggerStep(pTrigger->step_list);
|
||||
sqliteFree(pTrigger->name);
|
||||
sqliteFree(pTrigger->table);
|
||||
sqliteExprDelete(pTrigger->pWhen);
|
||||
sqliteIdListDelete(pTrigger->pColumns);
|
||||
sqlite3ExprDelete(pTrigger->pWhen);
|
||||
sqlite3IdListDelete(pTrigger->pColumns);
|
||||
if( pTrigger->nameToken.dyn ) sqliteFree((char*)pTrigger->nameToken.z);
|
||||
sqliteFree(pTrigger);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is called to drop a trigger from the database schema.
|
||||
*
|
||||
* This may be called directly from the parser and therefore identifies
|
||||
* the trigger by name. The sqliteDropTriggerPtr() routine does the
|
||||
* same job as this routine except it take a spointer to the trigger
|
||||
* instead of the trigger name.
|
||||
*
|
||||
* Note that this function does not delete the trigger entirely. Instead it
|
||||
* removes it from the internal schema and places it in the trigDrop hash
|
||||
* table. This is so that the trigger can be restored into the database schema
|
||||
* if the transaction is rolled back.
|
||||
*/
|
||||
void sqliteDropTrigger(Parse *pParse, SrcList *pName){
|
||||
Trigger *pTrigger;
|
||||
** This function is called to drop a trigger from the database schema.
|
||||
**
|
||||
** This may be called directly from the parser and therefore identifies
|
||||
** the trigger by name. The sqlite3DropTriggerPtr() routine does the
|
||||
** same job as this routine except it takes a pointer to the trigger
|
||||
** instead of the trigger name.
|
||||
**/
|
||||
void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
|
||||
Trigger *pTrigger = 0;
|
||||
int i;
|
||||
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) ){
|
||||
goto drop_trigger_cleanup;
|
||||
}
|
||||
|
||||
if( sqlite_malloc_failed ) goto drop_trigger_cleanup;
|
||||
assert( pName->nSrc==1 );
|
||||
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 && sqliteStrICmp(db->aDb[j].zName, zDb) ) continue;
|
||||
pTrigger = sqliteHashFind(&(db->aDb[j].trigHash), zName, nName+1);
|
||||
if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
|
||||
pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1);
|
||||
if( pTrigger ) break;
|
||||
}
|
||||
if( !pTrigger ){
|
||||
sqliteErrorMsg(pParse, "no such trigger: %S", pName, 0);
|
||||
sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
|
||||
goto drop_trigger_cleanup;
|
||||
}
|
||||
sqliteDropTriggerPtr(pParse, pTrigger, 0);
|
||||
sqlite3DropTriggerPtr(pParse, pTrigger, 0);
|
||||
|
||||
drop_trigger_cleanup:
|
||||
sqliteSrcListDelete(pName);
|
||||
sqlite3SrcListDelete(pName);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return a pointer to the Table structure for the table that a trigger
|
||||
** is set on.
|
||||
*/
|
||||
static Table *tableOfTrigger(sqlite3 *db, Trigger *pTrigger){
|
||||
return sqlite3FindTable(db,pTrigger->table,db->aDb[pTrigger->iTabDb].zName);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Drop a trigger given a pointer to that trigger. If nested is false,
|
||||
** then also generate code to remove the trigger from the SQLITE_MASTER
|
||||
** table.
|
||||
*/
|
||||
void sqliteDropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
Table *pTable;
|
||||
Vdbe *v;
|
||||
sqlite *db = pParse->db;
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb;
|
||||
|
||||
assert( pTrigger->iDb<db->nDb );
|
||||
if( pTrigger->iDb>=2 ){
|
||||
sqliteErrorMsg(pParse, "triggers may not be removed from "
|
||||
"auxiliary database %s", db->aDb[pTrigger->iDb].zName);
|
||||
return;
|
||||
}
|
||||
pTable = sqliteFindTable(db, pTrigger->table,db->aDb[pTrigger->iTabDb].zName);
|
||||
iDb = pTrigger->iDb;
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
pTable = tableOfTrigger(db, pTrigger);
|
||||
assert(pTable);
|
||||
assert( pTable->iDb==pTrigger->iDb || pTrigger->iDb==1 );
|
||||
assert( pTable->iDb==iDb || iDb==1 );
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
int code = SQLITE_DROP_TRIGGER;
|
||||
const char *zDb = db->aDb[pTrigger->iDb].zName;
|
||||
const char *zTab = SCHEMA_TABLE(pTrigger->iDb);
|
||||
if( pTrigger->iDb ) code = SQLITE_DROP_TEMP_TRIGGER;
|
||||
if( sqliteAuthCheck(pParse, code, pTrigger->name, pTable->zName, zDb) ||
|
||||
sqliteAuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
|
||||
const char *zDb = db->aDb[iDb].zName;
|
||||
const char *zTab = SCHEMA_TABLE(iDb);
|
||||
if( iDb==1 ) code = SQLITE_DROP_TEMP_TRIGGER;
|
||||
if( sqlite3AuthCheck(pParse, code, pTrigger->name, pTable->zName, zDb) ||
|
||||
sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -448,37 +495,40 @@ void sqliteDropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
|
||||
/* Generate code to destroy the database record of the trigger.
|
||||
*/
|
||||
if( pTable!=0 && !nested && (v = sqliteGetVdbe(pParse))!=0 ){
|
||||
if( pTable!=0 && (v = sqlite3GetVdbe(pParse))!=0 ){
|
||||
int base;
|
||||
static VdbeOp dropTrigger[] = {
|
||||
static const VdbeOpList dropTrigger[] = {
|
||||
{ OP_Rewind, 0, ADDR(9), 0},
|
||||
{ OP_String, 0, 0, 0}, /* 1 */
|
||||
{ OP_String8, 0, 0, 0}, /* 1 */
|
||||
{ OP_Column, 0, 1, 0},
|
||||
{ OP_Ne, 0, ADDR(8), 0},
|
||||
{ OP_String, 0, 0, "trigger"},
|
||||
{ OP_String8, 0, 0, "trigger"},
|
||||
{ OP_Column, 0, 0, 0},
|
||||
{ OP_Ne, 0, ADDR(8), 0},
|
||||
{ OP_Delete, 0, 0, 0},
|
||||
{ OP_Next, 0, ADDR(1), 0}, /* 8 */
|
||||
};
|
||||
|
||||
sqliteBeginWriteOperation(pParse, 0, 0);
|
||||
sqliteOpenMasterTable(v, pTrigger->iDb);
|
||||
base = sqliteVdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
|
||||
sqliteVdbeChangeP3(v, base+1, pTrigger->name, 0);
|
||||
if( pTrigger->iDb==0 ){
|
||||
sqliteChangeCookie(db, v);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||
sqlite3OpenMasterTable(v, iDb);
|
||||
base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
|
||||
sqlite3VdbeChangeP3(v, base+1, pTrigger->name, 0);
|
||||
sqlite3ChangeCookie(db, v, iDb);
|
||||
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
|
||||
sqlite3VdbeOp3(v, OP_DropTrigger, iDb, 0, pTrigger->name, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If this is not an "explain", then delete the trigger structure.
|
||||
*/
|
||||
if( !pParse->explain ){
|
||||
const char *zName = pTrigger->name;
|
||||
int nName = strlen(zName);
|
||||
/*
|
||||
** Remove a trigger from the hash tables of the sqlite* pointer.
|
||||
*/
|
||||
void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
|
||||
Trigger *pTrigger;
|
||||
int nName = strlen(zName);
|
||||
pTrigger = sqlite3HashInsert(&(db->aDb[iDb].trigHash), zName, nName+1, 0);
|
||||
if( pTrigger ){
|
||||
Table *pTable = tableOfTrigger(db, pTrigger);
|
||||
assert( pTable!=0 );
|
||||
if( pTable->pTrigger == pTrigger ){
|
||||
pTable->pTrigger = pTrigger->pNext;
|
||||
}else{
|
||||
@@ -492,8 +542,8 @@ void sqliteDropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
|
||||
}
|
||||
assert(cc);
|
||||
}
|
||||
sqliteHashInsert(&(db->aDb[pTrigger->iDb].trigHash), zName, nName+1, 0);
|
||||
sqliteDeleteTrigger(pTrigger);
|
||||
sqlite3DeleteTrigger(pTrigger);
|
||||
db->flags |= SQLITE_InternChanges;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,57 +560,43 @@ static int checkColumnOverLap(IdList *pIdList, ExprList *pEList){
|
||||
int e;
|
||||
if( !pIdList || !pEList ) return 1;
|
||||
for(e=0; e<pEList->nExpr; e++){
|
||||
if( sqliteIdListIndex(pIdList, pEList->a[e].zName)>=0 ) return 1;
|
||||
if( sqlite3IdListIndex(pIdList, pEList->a[e].zName)>=0 ) return 1;
|
||||
}
|
||||
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 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.
|
||||
*/
|
||||
int sqliteTriggersExist(
|
||||
** 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( 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;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -586,9 +622,9 @@ static SrcList *targetSrcList(
|
||||
assert( iDb<pParse->db->nDb );
|
||||
sDb.z = pParse->db->aDb[iDb].zName;
|
||||
sDb.n = strlen(sDb.z);
|
||||
pSrc = sqliteSrcListAppend(0, &sDb, &pStep->target);
|
||||
pSrc = sqlite3SrcListAppend(0, &sDb, &pStep->target);
|
||||
} else {
|
||||
pSrc = sqliteSrcListAppend(0, &pStep->target, 0);
|
||||
pSrc = sqlite3SrcListAppend(0, &pStep->target, 0);
|
||||
}
|
||||
return pSrc;
|
||||
}
|
||||
@@ -604,54 +640,61 @@ 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 ){
|
||||
int saveNTab = pParse->nTab;
|
||||
|
||||
orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
|
||||
pParse->trigStack->orconf = orconf;
|
||||
switch( pTriggerStep->op ){
|
||||
case TK_SELECT: {
|
||||
Select * ss = sqliteSelectDup(pTriggerStep->pSelect);
|
||||
Select * ss = sqlite3SelectDup(pTriggerStep->pSelect);
|
||||
assert(ss);
|
||||
assert(ss->pSrc);
|
||||
sqliteSelect(pParse, ss, SRT_Discard, 0, 0, 0, 0);
|
||||
sqliteSelectDelete(ss);
|
||||
sqlite3SelectResolve(pParse, ss, 0);
|
||||
sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(ss);
|
||||
break;
|
||||
}
|
||||
case TK_UPDATE: {
|
||||
SrcList *pSrc;
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
|
||||
sqliteUpdate(pParse, pSrc,
|
||||
sqliteExprListDup(pTriggerStep->pExprList),
|
||||
sqliteExprDup(pTriggerStep->pWhere), orconf);
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
|
||||
sqlite3Update(pParse, pSrc,
|
||||
sqlite3ExprListDup(pTriggerStep->pExprList),
|
||||
sqlite3ExprDup(pTriggerStep->pWhere), orconf);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0);
|
||||
break;
|
||||
}
|
||||
case TK_INSERT: {
|
||||
SrcList *pSrc;
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqliteInsert(pParse, pSrc,
|
||||
sqliteExprListDup(pTriggerStep->pExprList),
|
||||
sqliteSelectDup(pTriggerStep->pSelect),
|
||||
sqliteIdListDup(pTriggerStep->pIdList), orconf);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
|
||||
sqlite3Insert(pParse, pSrc,
|
||||
sqlite3ExprListDup(pTriggerStep->pExprList),
|
||||
sqlite3SelectDup(pTriggerStep->pSelect),
|
||||
sqlite3IdListDup(pTriggerStep->pIdList), orconf);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0);
|
||||
break;
|
||||
}
|
||||
case TK_DELETE: {
|
||||
SrcList *pSrc;
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqliteDeleteFrom(pParse, pSrc, sqliteExprDup(pTriggerStep->pWhere));
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
|
||||
sqlite3DeleteFrom(pParse, pSrc, sqlite3ExprDup(pTriggerStep->pWhere));
|
||||
sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
pParse->nTab = saveNTab;
|
||||
pTriggerStep = pTriggerStep->pNext;
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_ContextPop, 0, 0);
|
||||
VdbeComment((v, "# end trigger %s", pStepList->pTrig->name));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -676,22 +719,23 @@ static int codeTriggerProgram(
|
||||
** trigger program(s).
|
||||
**
|
||||
*/
|
||||
int sqliteCodeRowTrigger(
|
||||
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);
|
||||
|
||||
@@ -700,63 +744,59 @@ int sqliteCodeRowTrigger(
|
||||
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;
|
||||
sqliteAuthContextPush(pParse, &sContext, pTrigger->name);
|
||||
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 = sqliteVdbeMakeLabel(pParse->pVdbe);
|
||||
whenExpr = sqliteExprDup(pTrigger->pWhen);
|
||||
if( sqliteExprResolveIds(pParse, &dummyTablist, 0, whenExpr) ){
|
||||
pParse->trigStack = pParse->trigStack->pNext;
|
||||
sqliteFree(pTriggerStack);
|
||||
sqliteExprDelete(whenExpr);
|
||||
endTrigger = sqlite3VdbeMakeLabel(pParse->pVdbe);
|
||||
whenExpr = sqlite3ExprDup(pTrigger->pWhen);
|
||||
if( sqlite3ExprResolveNames(&sNC, whenExpr) ){
|
||||
pParse->trigStack = trigStackEntry.pNext;
|
||||
sqlite3ExprDelete(whenExpr);
|
||||
return 1;
|
||||
}
|
||||
sqliteExprIfFalse(pParse, whenExpr, endTrigger, 1);
|
||||
sqliteExprDelete(whenExpr);
|
||||
sqlite3ExprIfFalse(pParse, whenExpr, endTrigger, 1);
|
||||
sqlite3ExprDelete(whenExpr);
|
||||
|
||||
codeTriggerProgram(pParse, pTrigger->step_list, orconf);
|
||||
|
||||
/* Pop the entry off the trigger stack */
|
||||
pParse->trigStack = pParse->trigStack->pNext;
|
||||
sqliteAuthContextPop(&sContext);
|
||||
sqliteFree(pTriggerStack);
|
||||
pParse->trigStack = trigStackEntry.pNext;
|
||||
sqlite3AuthContextPop(&sContext);
|
||||
|
||||
sqliteVdbeResolveLabel(pParse->pVdbe, endTrigger);
|
||||
sqlite3VdbeResolveLabel(pParse->pVdbe, endTrigger);
|
||||
}
|
||||
pTrigger = pTrigger->pNext;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
|
||||
|
||||
+183
-129
@@ -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.67 2003/06/01 01:10:33 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.
|
||||
**
|
||||
@@ -23,7 +62,7 @@
|
||||
** \_______/ \________/ \______/ \________________/
|
||||
* onError pTabList pChanges pWhere
|
||||
*/
|
||||
void sqliteUpdate(
|
||||
void sqlite3Update(
|
||||
Parse *pParse, /* The parser context */
|
||||
SrcList *pTabList, /* The table in which we should change things */
|
||||
ExprList *pChanges, /* Things to be changed */
|
||||
@@ -32,63 +71,74 @@ void sqliteUpdate(
|
||||
){
|
||||
int i, j; /* Loop counters */
|
||||
Table *pTab; /* The table to be updated */
|
||||
int addr; /* VDBE instruction address of the start of the loop */
|
||||
int addr = 0; /* VDBE instruction address of the start of the loop */
|
||||
WhereInfo *pWInfo; /* Information about the WHERE clause */
|
||||
Vdbe *v; /* The virtual database engine */
|
||||
Index *pIdx; /* For looping over indices */
|
||||
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; /* Expression defining the new record number */
|
||||
int openAll; /* True if all indices need to be opened */
|
||||
int isView; /* Trying to update a view */
|
||||
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 */
|
||||
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 */
|
||||
|
||||
sContext.pParse = 0;
|
||||
if( pParse->nErr || sqlite_malloc_failed ) goto update_cleanup;
|
||||
if( pParse->nErr || sqlite3_malloc_failed ) goto update_cleanup;
|
||||
db = pParse->db;
|
||||
assert( pTabList->nSrc==1 );
|
||||
|
||||
/* Locate the table which we want to update.
|
||||
*/
|
||||
pTab = sqliteSrcListLookup(pParse, pTabList);
|
||||
pTab = sqlite3SrcListLookup(pParse, pTabList);
|
||||
if( pTab==0 ) goto update_cleanup;
|
||||
before_triggers = sqliteTriggersExist(pParse, pTab->pTrigger,
|
||||
TK_UPDATE, TK_BEFORE, TK_ROW, pChanges);
|
||||
after_triggers = sqliteTriggersExist(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( sqliteIsReadOnly(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 ){
|
||||
if( sqliteViewGetColumnNames(pParse, pTab) ){
|
||||
if( sqlite3ViewGetColumnNames(pParse, pTab) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
aXRef = sqliteMalloc( sizeof(int) * pTab->nCol );
|
||||
aXRef = sqliteMallocRaw( sizeof(int) * pTab->nCol );
|
||||
if( aXRef==0 ) goto update_cleanup;
|
||||
for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
|
||||
|
||||
/* 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,43 +153,45 @@ void sqliteUpdate(
|
||||
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( sqliteExprResolveIds(pParse, pTabList, 0, pChanges->a[i].pExpr) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pChanges->a[i].pExpr, 0, 0) ){
|
||||
if( sqlite3ExprResolveNames(&sNC, pChanges->a[i].pExpr) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
for(j=0; j<pTab->nCol; j++){
|
||||
if( sqliteStrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
|
||||
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;
|
||||
}
|
||||
}
|
||||
if( j>=pTab->nCol ){
|
||||
if( sqliteIsRowid(pChanges->a[i].zName) ){
|
||||
chngRecno = 1;
|
||||
pRecnoExpr = pChanges->a[i].pExpr;
|
||||
if( sqlite3IsRowid(pChanges->a[i].zName) ){
|
||||
chngRowid = 1;
|
||||
pRowidExpr = pChanges->a[i].pExpr;
|
||||
}else{
|
||||
sqliteErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
|
||||
sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
{
|
||||
int rc;
|
||||
rc = sqliteAuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
|
||||
rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
|
||||
pTab->aCol[j].zName, db->aDb[pTab->iDb].zName);
|
||||
if( rc==SQLITE_DENY ){
|
||||
goto update_cleanup;
|
||||
@@ -156,7 +208,7 @@ void sqliteUpdate(
|
||||
** 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++){
|
||||
@@ -166,12 +218,12 @@ void sqliteUpdate(
|
||||
if( i<pIdx->nColumn ) nIdx++;
|
||||
}
|
||||
if( nIdxTotal>0 ){
|
||||
apIdx = sqliteMalloc( sizeof(Index*) * nIdx + nIdxTotal );
|
||||
apIdx = sqliteMallocRaw( sizeof(Index*) * nIdx + nIdxTotal );
|
||||
if( apIdx==0 ) goto update_cleanup;
|
||||
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++){
|
||||
@@ -179,6 +231,7 @@ void sqliteUpdate(
|
||||
}
|
||||
}
|
||||
if( i<pIdx->nColumn ){
|
||||
if( sqlite3CheckIndexCollSeq(pParse, pIdx) ) goto update_cleanup;
|
||||
apIdx[nIdx++] = pIdx;
|
||||
aIdxUsed[j] = 1;
|
||||
}else{
|
||||
@@ -189,112 +242,114 @@ void sqliteUpdate(
|
||||
/* Resolve the column names in all the expressions in the
|
||||
** WHERE clause.
|
||||
*/
|
||||
if( pWhere ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, 0, pWhere) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( sqlite3ExprResolveNames(&sNC, pWhere) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
|
||||
/* Start the view context
|
||||
*/
|
||||
if( isView ){
|
||||
sqliteAuthContextPush(pParse, &sContext, pTab->zName);
|
||||
sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
|
||||
}
|
||||
|
||||
/* Begin generating code.
|
||||
*/
|
||||
v = sqliteGetVdbe(pParse);
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
if( v==0 ) goto update_cleanup;
|
||||
sqliteBeginWriteOperation(pParse, 1, pTab->iDb);
|
||||
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 = sqliteSelectDup(pTab->pSelect);
|
||||
sqliteSelect(pParse, pView, SRT_TempTable, iCur, 0, 0, 0);
|
||||
sqliteSelectDelete(pView);
|
||||
pView = sqlite3SelectDup(pTab->pSelect);
|
||||
sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0);
|
||||
sqlite3SelectDelete(pView);
|
||||
}
|
||||
|
||||
/* Begin the database scan
|
||||
*/
|
||||
pWInfo = sqliteWhereBegin(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.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0);
|
||||
|
||||
/* End the database scan loop.
|
||||
*/
|
||||
sqliteWhereEnd(pWInfo);
|
||||
sqlite3WhereEnd(pWInfo);
|
||||
|
||||
/* Initialize the count of updated rows
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
|
||||
}
|
||||
|
||||
if( row_triggers_exist ){
|
||||
if( triggers_exist ){
|
||||
/* Create pseudo-tables for NEW and OLD
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, oldIdx, pTab->nCol);
|
||||
sqlite3VdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol);
|
||||
|
||||
/* The top of the update loop for when there are triggers.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
sqliteVdbeAddOp(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.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
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);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
|
||||
|
||||
/* Generate the OLD table
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0);
|
||||
|
||||
/* Generate the NEW table
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqliteExprCode(pParse, pRecnoExpr);
|
||||
if( chngRowid ){
|
||||
sqlite3ExprCodeAndCache(pParse, pRowidExpr);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
|
||||
}
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
|
||||
continue;
|
||||
}
|
||||
j = aXRef[i];
|
||||
if( j<0 ){
|
||||
sqliteVdbeAddOp(v, OP_Column, iCur, i);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, i);
|
||||
sqlite3ColumnDefault(v, pTab, i);
|
||||
}else{
|
||||
sqliteExprCode(pParse, pChanges->a[j].pExpr);
|
||||
sqlite3ExprCodeAndCache(pParse, pChanges->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
}
|
||||
if( pParse->nErr ) goto update_cleanup;
|
||||
sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
|
||||
/* Fire the BEFORE and INSTEAD OF triggers
|
||||
*/
|
||||
if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, pTab,
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TRIGGER_BEFORE, pTab,
|
||||
newIdx, oldIdx, onError, addr) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
@@ -307,8 +362,9 @@ void sqliteUpdate(
|
||||
** action, then we need to open all indices because we might need
|
||||
** to be deleting some records.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqlite3VdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
|
||||
if( onError==OE_Replace ){
|
||||
openAll = 1;
|
||||
}else{
|
||||
@@ -322,8 +378,9 @@ void sqliteUpdate(
|
||||
}
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
if( openAll || aIdxUsed[i] ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenWrite, iCur+i+1, pIdx->tnum);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqlite3VdbeOp3(v, OP_OpenWrite, iCur+i+1, pIdx->tnum,
|
||||
(char*)&pIdx->keyInfo, P3_KEYINFO);
|
||||
assert( pParse->nTab>iCur+i+1 );
|
||||
}
|
||||
}
|
||||
@@ -334,76 +391,75 @@ void sqliteUpdate(
|
||||
** 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 ){
|
||||
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
if( !triggers_exist ){
|
||||
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_NotExists, iCur, addr);
|
||||
sqlite3VdbeAddOp(v, OP_NotExists, iCur, addr);
|
||||
|
||||
/* If the record number will change, push the record number as it
|
||||
** will be after the update. (The old record number is currently
|
||||
** on top of the stack.)
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqliteExprCode(pParse, pRecnoExpr);
|
||||
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
if( chngRowid ){
|
||||
sqlite3ExprCode(pParse, pRowidExpr);
|
||||
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}
|
||||
|
||||
/* Compute new data for this record.
|
||||
*/
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
|
||||
continue;
|
||||
}
|
||||
j = aXRef[i];
|
||||
if( j<0 ){
|
||||
sqliteVdbeAddOp(v, OP_Column, iCur, i);
|
||||
sqlite3VdbeAddOp(v, OP_Column, iCur, i);
|
||||
sqlite3ColumnDefault(v, pTab, i);
|
||||
}else{
|
||||
sqliteExprCode(pParse, pChanges->a[j].pExpr);
|
||||
sqlite3ExprCode(pParse, pChanges->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Do constraint checks
|
||||
*/
|
||||
sqliteGenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1,
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRowid, 1,
|
||||
onError, addr);
|
||||
|
||||
/* Delete the old indices for the current record.
|
||||
*/
|
||||
sqliteGenerateRowIndexDelete(db, v, pTab, iCur, aIdxUsed);
|
||||
sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, aIdxUsed);
|
||||
|
||||
/* If changing the record number, delete the old record.
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqliteVdbeAddOp(v, OP_Delete, iCur, 0);
|
||||
if( chngRowid ){
|
||||
sqlite3VdbeAddOp(v, OP_Delete, iCur, 0);
|
||||
}
|
||||
|
||||
/* Create the new index entries and the new record.
|
||||
*/
|
||||
sqliteCompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, -1);
|
||||
sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRowid, 1, -1);
|
||||
}
|
||||
|
||||
/* Increment the row counter
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack){
|
||||
sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
}
|
||||
|
||||
/* 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] )
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur+i+1, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
pParse->nTab = iCur;
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, pTab,
|
||||
if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TRIGGER_AFTER, pTab,
|
||||
newIdx, oldIdx, onError, addr) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
@@ -412,41 +468,39 @@ void sqliteUpdate(
|
||||
/* Repeat the above with the next record to be updated, until
|
||||
** all record selected by the WHERE clause have been updated.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
|
||||
sqliteVdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
|
||||
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] ){
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur+i+1, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur+i+1, 0);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
pParse->nTab = iCur;
|
||||
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_Close, newIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, oldIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Close, newIdx, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Close, oldIdx, 0);
|
||||
}
|
||||
|
||||
sqliteEndWriteOperation(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 ){
|
||||
sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
|
||||
sqliteVdbeChangeP3(v, -1, "rows updated", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
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);
|
||||
}
|
||||
|
||||
update_cleanup:
|
||||
sqliteAuthContextPop(&sContext);
|
||||
sqlite3AuthContextPop(&sContext);
|
||||
sqliteFree(apIdx);
|
||||
sqliteFree(aXRef);
|
||||
sqliteSrcListDelete(pTabList);
|
||||
sqliteExprListDelete(pChanges);
|
||||
sqliteExprDelete(pWhere);
|
||||
sqlite3SrcListDelete(pTabList);
|
||||
sqlite3ExprListDelete(pChanges);
|
||||
sqlite3ExprDelete(pWhere);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,570 @@
|
||||
/*
|
||||
** 2004 April 13
|
||||
**
|
||||
** 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 routines used to translate between UTF-8,
|
||||
** UTF-16, UTF-16BE, and UTF-16LE.
|
||||
**
|
||||
** $Id: utf.c,v 1.32 2005/01/28 01:29:08 drh Exp $
|
||||
**
|
||||
** Notes on UTF-8:
|
||||
**
|
||||
** Byte-0 Byte-1 Byte-2 Byte-3 Value
|
||||
** 0xxxxxxx 00000000 00000000 0xxxxxxx
|
||||
** 110yyyyy 10xxxxxx 00000000 00000yyy yyxxxxxx
|
||||
** 1110zzzz 10yyyyyy 10xxxxxx 00000000 zzzzyyyy yyxxxxxx
|
||||
** 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx 000uuuuu zzzzyyyy yyxxxxxx
|
||||
**
|
||||
**
|
||||
** Notes on UTF-16: (with wwww+1==uuuuu)
|
||||
**
|
||||
** Word-0 Word-1 Value
|
||||
** 110110ww wwzzzzyy 110111yy yyxxxxxx 000uuuuu zzzzyyyy yyxxxxxx
|
||||
** zzzzyyyy yyxxxxxx 00000000 zzzzyyyy yyxxxxxx
|
||||
**
|
||||
**
|
||||
** BOM or Byte Order Mark:
|
||||
** 0xff 0xfe little-endian utf-16 follows
|
||||
** 0xfe 0xff big-endian utf-16 follows
|
||||
**
|
||||
**
|
||||
** Handling of malformed strings:
|
||||
**
|
||||
** SQLite accepts and processes malformed strings without an error wherever
|
||||
** possible. However this is not possible when converting between UTF-8 and
|
||||
** UTF-16.
|
||||
**
|
||||
** When converting malformed UTF-8 strings to UTF-16, one instance of the
|
||||
** replacement character U+FFFD for each byte that cannot be interpeted as
|
||||
** part of a valid unicode character.
|
||||
**
|
||||
** When converting malformed UTF-16 strings to UTF-8, one instance of the
|
||||
** replacement character U+FFFD for each pair of bytes that cannot be
|
||||
** interpeted as part of a valid unicode character.
|
||||
**
|
||||
** This file contains the following public routines:
|
||||
**
|
||||
** sqlite3VdbeMemTranslate() - Translate the encoding used by a Mem* string.
|
||||
** sqlite3VdbeMemHandleBom() - Handle byte-order-marks in UTF16 Mem* strings.
|
||||
** sqlite3utf16ByteLen() - Calculate byte-length of a void* UTF16 string.
|
||||
** sqlite3utf8CharLen() - Calculate char-length of a char* UTF8 string.
|
||||
** sqlite3utf8LikeCompare() - Do a LIKE match given two UTF8 char* strings.
|
||||
**
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <assert.h>
|
||||
#include "vdbeInt.h"
|
||||
|
||||
/*
|
||||
** This table maps from the first byte of a UTF-8 character to the number
|
||||
** of trailing bytes expected. A value '255' indicates that the table key
|
||||
** is not a legal first byte for a UTF-8 character.
|
||||
*/
|
||||
static const u8 xtra_utf8_bytes[256] = {
|
||||
/* 0xxxxxxx */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
/* 10wwwwww */
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
|
||||
/* 110yyyyy */
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
|
||||
/* 1110zzzz */
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
|
||||
/* 11110yyy */
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
};
|
||||
|
||||
/*
|
||||
** This table maps from the number of trailing bytes in a UTF-8 character
|
||||
** to an integer constant that is effectively calculated for each character
|
||||
** read by a naive implementation of a UTF-8 character reader. The code
|
||||
** in the READ_UTF8 macro explains things best.
|
||||
*/
|
||||
static const int xtra_utf8_bits[4] = {
|
||||
0,
|
||||
12416, /* (0xC0 << 6) + (0x80) */
|
||||
925824, /* (0xE0 << 12) + (0x80 << 6) + (0x80) */
|
||||
63447168 /* (0xF0 << 18) + (0x80 << 12) + (0x80 << 6) + 0x80 */
|
||||
};
|
||||
|
||||
#define READ_UTF8(zIn, c) { \
|
||||
int xtra; \
|
||||
c = *(zIn)++; \
|
||||
xtra = xtra_utf8_bytes[c]; \
|
||||
switch( xtra ){ \
|
||||
case 255: c = (int)0xFFFD; break; \
|
||||
case 3: c = (c<<6) + *(zIn)++; \
|
||||
case 2: c = (c<<6) + *(zIn)++; \
|
||||
case 1: c = (c<<6) + *(zIn)++; \
|
||||
c -= xtra_utf8_bits[xtra]; \
|
||||
} \
|
||||
}
|
||||
int sqlite3ReadUtf8(const unsigned char *z){
|
||||
int c;
|
||||
READ_UTF8(z, c);
|
||||
return c;
|
||||
}
|
||||
|
||||
#define SKIP_UTF8(zIn) { \
|
||||
zIn += (xtra_utf8_bytes[*(u8 *)zIn] + 1); \
|
||||
}
|
||||
|
||||
#define WRITE_UTF8(zOut, c) { \
|
||||
if( c<0x00080 ){ \
|
||||
*zOut++ = (c&0xFF); \
|
||||
} \
|
||||
else if( c<0x00800 ){ \
|
||||
*zOut++ = 0xC0 + ((c>>6)&0x1F); \
|
||||
*zOut++ = 0x80 + (c & 0x3F); \
|
||||
} \
|
||||
else if( c<0x10000 ){ \
|
||||
*zOut++ = 0xE0 + ((c>>12)&0x0F); \
|
||||
*zOut++ = 0x80 + ((c>>6) & 0x3F); \
|
||||
*zOut++ = 0x80 + (c & 0x3F); \
|
||||
}else{ \
|
||||
*zOut++ = 0xF0 + ((c>>18) & 0x07); \
|
||||
*zOut++ = 0x80 + ((c>>12) & 0x3F); \
|
||||
*zOut++ = 0x80 + ((c>>6) & 0x3F); \
|
||||
*zOut++ = 0x80 + (c & 0x3F); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define WRITE_UTF16LE(zOut, c) { \
|
||||
if( c<=0xFFFF ){ \
|
||||
*zOut++ = (c&0x00FF); \
|
||||
*zOut++ = ((c>>8)&0x00FF); \
|
||||
}else{ \
|
||||
*zOut++ = (((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
|
||||
*zOut++ = (0x00D8 + (((c-0x10000)>>18)&0x03)); \
|
||||
*zOut++ = (c&0x00FF); \
|
||||
*zOut++ = (0x00DC + ((c>>8)&0x03)); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define WRITE_UTF16BE(zOut, c) { \
|
||||
if( c<=0xFFFF ){ \
|
||||
*zOut++ = ((c>>8)&0x00FF); \
|
||||
*zOut++ = (c&0x00FF); \
|
||||
}else{ \
|
||||
*zOut++ = (0x00D8 + (((c-0x10000)>>18)&0x03)); \
|
||||
*zOut++ = (((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
|
||||
*zOut++ = (0x00DC + ((c>>8)&0x03)); \
|
||||
*zOut++ = (c&0x00FF); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define READ_UTF16LE(zIn, c){ \
|
||||
c = (*zIn++); \
|
||||
c += ((*zIn++)<<8); \
|
||||
if( c>=0xD800 && c<=0xE000 ){ \
|
||||
int c2 = (*zIn++); \
|
||||
c2 += ((*zIn++)<<8); \
|
||||
c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define READ_UTF16BE(zIn, c){ \
|
||||
c = ((*zIn++)<<8); \
|
||||
c += (*zIn++); \
|
||||
if( c>=0xD800 && c<=0xE000 ){ \
|
||||
int c2 = ((*zIn++)<<8); \
|
||||
c2 += (*zIn++); \
|
||||
c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SKIP_UTF16BE(zIn){ \
|
||||
if( *zIn>=0xD8 && (*zIn<0xE0 || (*zIn==0xE0 && *(zIn+1)==0x00)) ){ \
|
||||
zIn += 4; \
|
||||
}else{ \
|
||||
zIn += 2; \
|
||||
} \
|
||||
}
|
||||
#define SKIP_UTF16LE(zIn){ \
|
||||
zIn++; \
|
||||
if( *zIn>=0xD8 && (*zIn<0xE0 || (*zIn==0xE0 && *(zIn-1)==0x00)) ){ \
|
||||
zIn += 3; \
|
||||
}else{ \
|
||||
zIn += 1; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define RSKIP_UTF16LE(zIn){ \
|
||||
if( *zIn>=0xD8 && (*zIn<0xE0 || (*zIn==0xE0 && *(zIn-1)==0x00)) ){ \
|
||||
zIn -= 4; \
|
||||
}else{ \
|
||||
zIn -= 2; \
|
||||
} \
|
||||
}
|
||||
#define RSKIP_UTF16BE(zIn){ \
|
||||
zIn--; \
|
||||
if( *zIn>=0xD8 && (*zIn<0xE0 || (*zIn==0xE0 && *(zIn+1)==0x00)) ){ \
|
||||
zIn -= 3; \
|
||||
}else{ \
|
||||
zIn -= 1; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
** If the TRANSLATE_TRACE macro is defined, the value of each Mem is
|
||||
** printed on stderr on the way into and out of sqlite3VdbeMemTranslate().
|
||||
*/
|
||||
/* #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
|
||||
** encoding, or if *pMem does not contain a string value.
|
||||
*/
|
||||
int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
unsigned char zShort[NBFS]; /* Temporary short output buffer */
|
||||
int len; /* Maximum length of output string in bytes */
|
||||
unsigned char *zOut; /* Output buffer */
|
||||
unsigned char *zIn; /* Input iterator */
|
||||
unsigned char *zTerm; /* End of input */
|
||||
unsigned char *z; /* Output iterator */
|
||||
int c;
|
||||
|
||||
assert( pMem->flags&MEM_Str );
|
||||
assert( pMem->enc!=desiredEnc );
|
||||
assert( pMem->enc!=0 );
|
||||
assert( pMem->n>=0 );
|
||||
|
||||
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
|
||||
{
|
||||
char zBuf[100];
|
||||
sqlite3VdbeMemPrettyPrint(pMem, zBuf, 100);
|
||||
fprintf(stderr, "INPUT: %s\n", zBuf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If the translation is between UTF-16 little and big endian, then
|
||||
** all that is required is to swap the byte order. This case is handled
|
||||
** differently from the others.
|
||||
*/
|
||||
if( pMem->enc!=SQLITE_UTF8 && desiredEnc!=SQLITE_UTF8 ){
|
||||
u8 temp;
|
||||
int rc;
|
||||
rc = sqlite3VdbeMemMakeWriteable(pMem);
|
||||
if( rc!=SQLITE_OK ){
|
||||
assert( rc==SQLITE_NOMEM );
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
zIn = pMem->z;
|
||||
zTerm = &zIn[pMem->n];
|
||||
while( zIn<zTerm ){
|
||||
temp = *zIn;
|
||||
*zIn = *(zIn+1);
|
||||
zIn++;
|
||||
*zIn++ = temp;
|
||||
}
|
||||
pMem->enc = desiredEnc;
|
||||
goto translate_out;
|
||||
}
|
||||
|
||||
/* Set len to the maximum number of bytes required in the output buffer. */
|
||||
if( desiredEnc==SQLITE_UTF8 ){
|
||||
/* When converting from UTF-16, the maximum growth results from
|
||||
** translating a 2-byte character to a 3-byte UTF-8 character (i.e.
|
||||
** code-point 0xFFFC). A single byte is required for the output string
|
||||
** nul-terminator.
|
||||
*/
|
||||
len = (pMem->n/2) * 3 + 1;
|
||||
}else{
|
||||
/* When converting from UTF-8 to UTF-16 the maximum growth is caused
|
||||
** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
|
||||
** character. Two bytes are required in the output buffer for the
|
||||
** nul-terminator.
|
||||
*/
|
||||
len = pMem->n * 2 + 2;
|
||||
}
|
||||
|
||||
/* Set zIn to point at the start of the input buffer and zTerm to point 1
|
||||
** byte past the end.
|
||||
**
|
||||
** Variable zOut is set to point at the output buffer. This may be space
|
||||
** obtained from malloc(), or Mem.zShort, if it large enough and not in
|
||||
** use, or the zShort array on the stack (see above).
|
||||
*/
|
||||
zIn = pMem->z;
|
||||
zTerm = &zIn[pMem->n];
|
||||
if( len>NBFS ){
|
||||
zOut = sqliteMallocRaw(len);
|
||||
if( !zOut ) return SQLITE_NOMEM;
|
||||
}else{
|
||||
zOut = zShort;
|
||||
}
|
||||
z = zOut;
|
||||
|
||||
if( pMem->enc==SQLITE_UTF8 ){
|
||||
if( desiredEnc==SQLITE_UTF16LE ){
|
||||
/* UTF-8 -> UTF-16 Little-endian */
|
||||
while( zIn<zTerm ){
|
||||
READ_UTF8(zIn, c);
|
||||
WRITE_UTF16LE(z, c);
|
||||
}
|
||||
}else{
|
||||
assert( desiredEnc==SQLITE_UTF16BE );
|
||||
/* UTF-8 -> UTF-16 Big-endian */
|
||||
while( zIn<zTerm ){
|
||||
READ_UTF8(zIn, c);
|
||||
WRITE_UTF16BE(z, c);
|
||||
}
|
||||
}
|
||||
pMem->n = z - zOut;
|
||||
*z++ = 0;
|
||||
}else{
|
||||
assert( desiredEnc==SQLITE_UTF8 );
|
||||
if( pMem->enc==SQLITE_UTF16LE ){
|
||||
/* UTF-16 Little-endian -> UTF-8 */
|
||||
while( zIn<zTerm ){
|
||||
READ_UTF16LE(zIn, c);
|
||||
WRITE_UTF8(z, c);
|
||||
}
|
||||
}else{
|
||||
/* UTF-16 Little-endian -> UTF-8 */
|
||||
while( zIn<zTerm ){
|
||||
READ_UTF16BE(zIn, c);
|
||||
WRITE_UTF8(z, c);
|
||||
}
|
||||
}
|
||||
pMem->n = z - zOut;
|
||||
}
|
||||
*z = 0;
|
||||
assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
|
||||
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short);
|
||||
pMem->enc = desiredEnc;
|
||||
if( zOut==zShort ){
|
||||
memcpy(pMem->zShort, zOut, len);
|
||||
zOut = pMem->zShort;
|
||||
pMem->flags |= (MEM_Term|MEM_Short);
|
||||
}else{
|
||||
pMem->flags |= (MEM_Term|MEM_Dyn);
|
||||
}
|
||||
pMem->z = zOut;
|
||||
|
||||
translate_out:
|
||||
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
|
||||
{
|
||||
char zBuf[100];
|
||||
sqlite3VdbeMemPrettyPrint(pMem, zBuf, 100);
|
||||
fprintf(stderr, "OUTPUT: %s\n", zBuf);
|
||||
}
|
||||
#endif
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine checks for a byte-order mark at the beginning of the
|
||||
** UTF-16 string stored in *pMem. If one is present, it is removed and
|
||||
** the encoding of the Mem adjusted. This routine does not do any
|
||||
** byte-swapping, it just sets Mem.enc appropriately.
|
||||
**
|
||||
** The allocation (static, dynamic etc.) and encoding of the Mem may be
|
||||
** changed by this function.
|
||||
*/
|
||||
int sqlite3VdbeMemHandleBom(Mem *pMem){
|
||||
int rc = SQLITE_OK;
|
||||
u8 bom = 0;
|
||||
|
||||
if( pMem->n<0 || pMem->n>1 ){
|
||||
u8 b1 = *(u8 *)pMem->z;
|
||||
u8 b2 = *(((u8 *)pMem->z) + 1);
|
||||
if( b1==0xFE && b2==0xFF ){
|
||||
bom = SQLITE_UTF16BE;
|
||||
}
|
||||
if( b1==0xFF && b2==0xFE ){
|
||||
bom = SQLITE_UTF16LE;
|
||||
}
|
||||
}
|
||||
|
||||
if( bom ){
|
||||
/* This function is called as soon as a string is stored in a Mem*,
|
||||
** from within sqlite3VdbeMemSetStr(). At that point it is not possible
|
||||
** for the string to be stored in Mem.zShort, or for it to be stored
|
||||
** in dynamic memory with no destructor.
|
||||
*/
|
||||
assert( !(pMem->flags&MEM_Short) );
|
||||
assert( !(pMem->flags&MEM_Dyn) || pMem->xDel );
|
||||
if( pMem->flags & MEM_Dyn ){
|
||||
void (*xDel)(void*) = pMem->xDel;
|
||||
char *z = pMem->z;
|
||||
pMem->z = 0;
|
||||
pMem->xDel = 0;
|
||||
rc = sqlite3VdbeMemSetStr(pMem, &z[2], pMem->n-2, bom, SQLITE_TRANSIENT);
|
||||
xDel(z);
|
||||
}else{
|
||||
rc = sqlite3VdbeMemSetStr(pMem, &pMem->z[2], pMem->n-2, bom,
|
||||
SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
/*
|
||||
** pZ is a UTF-8 encoded unicode string. If nByte is less than zero,
|
||||
** return the number of unicode characters in pZ up to (but not including)
|
||||
** the first 0x00 byte. If nByte is not less than zero, return the
|
||||
** number of unicode characters in the first nByte of pZ (or up to
|
||||
** the first 0x00, whichever comes first).
|
||||
*/
|
||||
int sqlite3utf8CharLen(const char *z, int nByte){
|
||||
int r = 0;
|
||||
const char *zTerm;
|
||||
if( nByte>=0 ){
|
||||
zTerm = &z[nByte];
|
||||
}else{
|
||||
zTerm = (const char *)(-1);
|
||||
}
|
||||
assert( z<=zTerm );
|
||||
while( *z!=0 && z<zTerm ){
|
||||
SKIP_UTF8(z);
|
||||
r++;
|
||||
}
|
||||
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
|
||||
** of consecutive 0x00 bytes in pZ. If nChar is not less than zero,
|
||||
** then return the number of bytes in the first nChar unicode characters
|
||||
** in pZ (or up until the first pair of 0x00 bytes, whichever comes first).
|
||||
*/
|
||||
int sqlite3utf16ByteLen(const void *zIn, int nChar){
|
||||
int c = 1;
|
||||
char const *z = zIn;
|
||||
int n = 0;
|
||||
if( SQLITE_UTF16NATIVE==SQLITE_UTF16BE ){
|
||||
while( c && ((nChar<0) || n<nChar) ){
|
||||
READ_UTF16BE(z, c);
|
||||
n++;
|
||||
}
|
||||
}else{
|
||||
while( c && ((nChar<0) || n<nChar) ){
|
||||
READ_UTF16LE(z, c);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
return (z-(char const *)zIn)-((c==0)?2:0);
|
||||
}
|
||||
|
||||
/*
|
||||
** UTF-16 implementation of the substr()
|
||||
*/
|
||||
void sqlite3utf16Substr(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
int y, z;
|
||||
unsigned char const *zStr;
|
||||
unsigned char const *zStrEnd;
|
||||
unsigned char const *zStart;
|
||||
unsigned char const *zEnd;
|
||||
int i;
|
||||
|
||||
zStr = (unsigned char const *)sqlite3_value_text16(argv[0]);
|
||||
zStrEnd = &zStr[sqlite3_value_bytes16(argv[0])];
|
||||
y = sqlite3_value_int(argv[1]);
|
||||
z = sqlite3_value_int(argv[2]);
|
||||
|
||||
if( y>0 ){
|
||||
y = y-1;
|
||||
zStart = zStr;
|
||||
if( SQLITE_UTF16BE==SQLITE_UTF16NATIVE ){
|
||||
for(i=0; i<y && zStart<zStrEnd; i++) SKIP_UTF16BE(zStart);
|
||||
}else{
|
||||
for(i=0; i<y && zStart<zStrEnd; i++) SKIP_UTF16LE(zStart);
|
||||
}
|
||||
}else{
|
||||
zStart = zStrEnd;
|
||||
if( SQLITE_UTF16BE==SQLITE_UTF16NATIVE ){
|
||||
for(i=y; i<0 && zStart>zStr; i++) RSKIP_UTF16BE(zStart);
|
||||
}else{
|
||||
for(i=y; i<0 && zStart>zStr; i++) RSKIP_UTF16LE(zStart);
|
||||
}
|
||||
for(; i<0; i++) z -= 1;
|
||||
}
|
||||
|
||||
zEnd = zStart;
|
||||
if( SQLITE_UTF16BE==SQLITE_UTF16NATIVE ){
|
||||
for(i=0; i<z && zEnd<zStrEnd; i++) SKIP_UTF16BE(zEnd);
|
||||
}else{
|
||||
for(i=0; i<z && zEnd<zStrEnd; i++) SKIP_UTF16LE(zEnd);
|
||||
}
|
||||
|
||||
sqlite3_result_text16(context, zStart, zEnd-zStart, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
#if defined(SQLITE_TEST)
|
||||
/*
|
||||
** This routine is called from the TCL test function "translate_selftest".
|
||||
** It checks that the primitives for serializing and deserializing
|
||||
** characters in each encoding are inverses of each other.
|
||||
*/
|
||||
void sqlite3utfSelfTest(){
|
||||
int i;
|
||||
unsigned char zBuf[20];
|
||||
unsigned char *z;
|
||||
int n;
|
||||
int c;
|
||||
|
||||
for(i=0; i<0x00110000; i++){
|
||||
z = zBuf;
|
||||
WRITE_UTF8(z, i);
|
||||
n = z-zBuf;
|
||||
z = zBuf;
|
||||
READ_UTF8(z, c);
|
||||
assert( c==i );
|
||||
assert( (z-zBuf)==n );
|
||||
}
|
||||
for(i=0; i<0x00110000; i++){
|
||||
if( i>=0xD800 && i<=0xE000 ) continue;
|
||||
z = zBuf;
|
||||
WRITE_UTF16LE(z, i);
|
||||
n = z-zBuf;
|
||||
z = zBuf;
|
||||
READ_UTF16LE(z, c);
|
||||
assert( c==i );
|
||||
assert( (z-zBuf)==n );
|
||||
}
|
||||
for(i=0; i<0x00110000; i++){
|
||||
if( i>=0xD800 && i<=0xE000 ) continue;
|
||||
z = zBuf;
|
||||
WRITE_UTF16BE(z, i);
|
||||
n = z-zBuf;
|
||||
z = zBuf;
|
||||
READ_UTF16BE(z, c);
|
||||
assert( c==i );
|
||||
assert( (z-zBuf)==n );
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
+563
-720
File diff suppressed because it is too large
Load Diff
+247
-256
@@ -14,185 +14,60 @@
|
||||
** Most of the code in this file may be omitted by defining the
|
||||
** SQLITE_OMIT_VACUUM macro.
|
||||
**
|
||||
** $Id: vacuum.c,v 1.8 2003/08/15 13:24:52 drh Exp $
|
||||
** $Id: vacuum.c,v 1.45 2005/06/07 09:21:07 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** A structure for holding a dynamic string - a string that can grow
|
||||
** without bound.
|
||||
*/
|
||||
typedef struct dynStr dynStr;
|
||||
struct dynStr {
|
||||
char *z; /* Text of the string in space obtained from sqliteMalloc() */
|
||||
int nAlloc; /* Amount of space allocated to z[] */
|
||||
int nUsed; /* Next unused slot in z[] */
|
||||
};
|
||||
|
||||
/*
|
||||
** A structure that holds the vacuum context
|
||||
*/
|
||||
typedef struct vacuumStruct vacuumStruct;
|
||||
struct vacuumStruct {
|
||||
sqlite *dbOld; /* Original database */
|
||||
sqlite *dbNew; /* New database */
|
||||
Parse *pParse; /* The parser context */
|
||||
const char *zTable; /* Name of a table being copied */
|
||||
const char *zPragma; /* Pragma to execute with results */
|
||||
dynStr s1, s2; /* Two dynamic strings */
|
||||
};
|
||||
|
||||
#if !defined(SQLITE_OMIT_VACUUM) || SQLITE_OMIT_VACUUM
|
||||
/*
|
||||
** Append text to a dynamic string
|
||||
*/
|
||||
static void appendText(dynStr *p, const char *zText, int nText){
|
||||
if( nText<0 ) nText = strlen(zText);
|
||||
if( p->z==0 || p->nUsed + nText + 1 >= p->nAlloc ){
|
||||
char *zNew;
|
||||
p->nAlloc = p->nUsed + nText + 1000;
|
||||
zNew = sqliteRealloc(p->z, p->nAlloc);
|
||||
if( zNew==0 ){
|
||||
sqliteFree(p->z);
|
||||
memset(p, 0, sizeof(*p));
|
||||
return;
|
||||
}
|
||||
p->z = zNew;
|
||||
}
|
||||
memcpy(&p->z[p->nUsed], zText, nText+1);
|
||||
p->nUsed += nText;
|
||||
}
|
||||
|
||||
/*
|
||||
** Append text to a dynamic string, having first put the text in quotes.
|
||||
*/
|
||||
static void appendQuoted(dynStr *p, const char *zText){
|
||||
int i, j;
|
||||
appendText(p, "'", 1);
|
||||
for(i=j=0; zText[i]; i++){
|
||||
if( zText[i]=='\'' ){
|
||||
appendText(p, &zText[j], i-j+1);
|
||||
j = i + 1;
|
||||
appendText(p, "'", 1);
|
||||
}
|
||||
}
|
||||
if( j<i ){
|
||||
appendText(p, &zText[j], i-j);
|
||||
}
|
||||
appendText(p, "'", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
** Execute statements of SQL. If an error occurs, write the error
|
||||
** message into pParse->zErrMsg and return non-zero.
|
||||
*/
|
||||
static int execsql(Parse *pParse, sqlite *db, const char *zSql){
|
||||
int rc;
|
||||
char *zErrMsg = 0;
|
||||
|
||||
/* printf("***** executing *****\n%s\n", zSql); */
|
||||
rc = sqlite_exec(db, zSql, 0, 0, &zErrMsg);
|
||||
if( rc ){
|
||||
sqliteErrorMsg(pParse, "%s", zErrMsg);
|
||||
sqlite_freemem(zErrMsg);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is the second stage callback. Each invocation contains all the
|
||||
** data for a single row of a single table in the original database. This
|
||||
** routine must write that information into the new database.
|
||||
*/
|
||||
static int vacuumCallback2(void *pArg, int argc, char **argv, char **NotUsed){
|
||||
vacuumStruct *p = (vacuumStruct*)pArg;
|
||||
int rc = 0;
|
||||
const char *zSep = "(";
|
||||
int i;
|
||||
|
||||
if( argv==0 ) return 0;
|
||||
p->s2.nUsed = 0;
|
||||
appendText(&p->s2, "INSERT INTO ", -1);
|
||||
appendQuoted(&p->s2, p->zTable);
|
||||
appendText(&p->s2, " VALUES", -1);
|
||||
for(i=0; i<argc; i++){
|
||||
appendText(&p->s2, zSep, 1);
|
||||
zSep = ",";
|
||||
if( argv[i]==0 ){
|
||||
appendText(&p->s2, "NULL", 4);
|
||||
}else{
|
||||
appendQuoted(&p->s2, argv[i]);
|
||||
}
|
||||
}
|
||||
appendText(&p->s2,")", 1);
|
||||
rc = execsql(p->pParse, p->dbNew, p->s2.z);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is the first stage callback. Each invocation contains three
|
||||
** arguments where are taken from the SQLITE_MASTER table of the original
|
||||
** database: (1) the entry type, (2) the entry name, and (3) the SQL for
|
||||
** the entry. In all cases, execute the SQL of the third argument.
|
||||
** For tables, run a query to select all entries in that table and
|
||||
** transfer them to the second-stage callback.
|
||||
*/
|
||||
static int vacuumCallback1(void *pArg, int argc, char **argv, char **NotUsed){
|
||||
vacuumStruct *p = (vacuumStruct*)pArg;
|
||||
int rc = 0;
|
||||
assert( argc==3 );
|
||||
if( argv==0 ) return 0;
|
||||
assert( argv[0]!=0 );
|
||||
assert( argv[1]!=0 );
|
||||
assert( argv[2]!=0 );
|
||||
rc = execsql(p->pParse, p->dbNew, argv[2]);
|
||||
if( rc==SQLITE_OK && strcmp(argv[0],"table")==0 ){
|
||||
char *zErrMsg = 0;
|
||||
p->s1.nUsed = 0;
|
||||
appendText(&p->s1, "SELECT * FROM ", -1);
|
||||
appendQuoted(&p->s1, argv[1]);
|
||||
p->zTable = argv[1];
|
||||
rc = sqlite_exec(p->dbOld, p->s1.z, vacuumCallback2, p, &zErrMsg);
|
||||
if( rc && p->pParse->zErrMsg==0 ){
|
||||
sqliteErrorMsg(p->pParse, "%s", zErrMsg);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This callback is used to transfer PRAGMA settings from one database
|
||||
** to the other. The value in argv[0] should be passed to a pragma
|
||||
** identified by ((vacuumStruct*)pArg)->zPragma.
|
||||
*/
|
||||
static int vacuumCallback3(void *pArg, int argc, char **argv, char **NotUsed){
|
||||
vacuumStruct *p = (vacuumStruct*)pArg;
|
||||
int rc = 0;
|
||||
char zBuf[200];
|
||||
assert( argc==1 );
|
||||
if( argv==0 ) return 0;
|
||||
assert( argv[0]!=0 );
|
||||
assert( strlen(p->zPragma)<100 );
|
||||
assert( strlen(argv[0])<30 );
|
||||
sprintf(zBuf,"PRAGMA %s=%s;", p->zPragma, argv[0]);
|
||||
rc = execsql(p->pParse, p->dbNew, zBuf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_VACUUM
|
||||
/*
|
||||
** Generate a random name of 20 character in length.
|
||||
*/
|
||||
static void randomName(char *zBuf){
|
||||
static const char zChars[] =
|
||||
static void randomName(unsigned char *zBuf){
|
||||
static const unsigned char zChars[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789";
|
||||
int i;
|
||||
sqlite3Randomness(20, zBuf);
|
||||
for(i=0; i<20; i++){
|
||||
int n = sqliteRandomByte() % (sizeof(zChars)-1);
|
||||
zBuf[i] = zChars[n];
|
||||
zBuf[i] = zChars[ zBuf[i]%(sizeof(zChars)-1) ];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Execute zSql on database db. Return an error code.
|
||||
*/
|
||||
static int execSql(sqlite3 *db, const char *zSql){
|
||||
sqlite3_stmt *pStmt;
|
||||
if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
|
||||
return sqlite3_errcode(db);
|
||||
}
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) );
|
||||
return sqlite3_finalize(pStmt);
|
||||
}
|
||||
|
||||
/*
|
||||
** Execute zSql on database db. The statement returns exactly
|
||||
** one column. Execute this as SQL on the same database.
|
||||
*/
|
||||
static int execExecSql(sqlite3 *db, const char *zSql){
|
||||
sqlite3_stmt *pStmt;
|
||||
int rc;
|
||||
|
||||
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
rc = execSql(db, sqlite3_column_text(pStmt, 0));
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3_finalize(pStmt);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return sqlite3_finalize(pStmt);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -205,115 +80,231 @@ static void randomName(char *zBuf){
|
||||
** with 2.0.0, SQLite no longer uses GDBM so this command has
|
||||
** become a no-op.
|
||||
*/
|
||||
void sqliteVacuum(Parse *pParse, Token *pTableName){
|
||||
#if !defined(SQLITE_OMIT_VACUUM) || SQLITE_OMIT_VACUUM
|
||||
void sqlite3Vacuum(Parse *pParse, Token *pTableName){
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
if( v ){
|
||||
sqlite3VdbeAddOp(v, OP_Vacuum, 0, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine implements the OP_Vacuum opcode of the VDBE.
|
||||
*/
|
||||
int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
int rc = SQLITE_OK; /* Return code from service routines */
|
||||
#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 */
|
||||
sqlite *dbNew = 0; /* The new vacuumed database */
|
||||
sqlite *db; /* The original database */
|
||||
int rc = SQLITE_OK; /* Return code from service routines */
|
||||
int i; /* Loop counter */
|
||||
char *zErrMsg = 0; /* Error messages stored here */
|
||||
int safety = 0; /* TRUE if safety is off */
|
||||
vacuumStruct sVac; /* Information passed to callbacks */
|
||||
Btree *pMain; /* The database being vacuumed */
|
||||
Btree *pTemp;
|
||||
char *zSql = 0;
|
||||
int writeschema_flag; /* Saved value of the write-schema flag */
|
||||
|
||||
/* These are all of the pragmas that need to be transferred over
|
||||
** to the new database */
|
||||
static const char *zPragma[] = {
|
||||
"default_synchronous",
|
||||
"default_cache_size",
|
||||
/* "default_temp_store", */
|
||||
};
|
||||
/* Save the current value of the write-schema flag before setting it. */
|
||||
writeschema_flag = db->flags&SQLITE_WriteSchema;
|
||||
db->flags |= SQLITE_WriteSchema;
|
||||
|
||||
/* Initial error checks
|
||||
*/
|
||||
if( pParse->explain ){
|
||||
return;
|
||||
if( !db->autoCommit ){
|
||||
sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction",
|
||||
(char*)0);
|
||||
rc = SQLITE_ERROR;
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
db = pParse->db;
|
||||
if( db->flags & SQLITE_InTrans ){
|
||||
sqliteErrorMsg(pParse, "cannot VACUUM from within a transaction");
|
||||
return;
|
||||
}
|
||||
memset(&sVac, 0, sizeof(sVac));
|
||||
|
||||
/* Get the full pathname of the database file and create two
|
||||
** temporary filenames in the same directory as the original file.
|
||||
/* Get the full pathname of the database file and create a
|
||||
** temporary filename in the same directory as the original file.
|
||||
*/
|
||||
zFilename = sqliteBtreeGetFilename(db->aDb[0].pBt);
|
||||
if( zFilename==0 ){
|
||||
/* This only happens with the in-memory database. VACUUM is a no-op
|
||||
** there, so just return */
|
||||
return;
|
||||
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
|
||||
** an error trying to DETACH the vacuum_db (which never got attached)
|
||||
** in the exit-handler.
|
||||
*/
|
||||
return SQLITE_OK;
|
||||
}
|
||||
nFilename = strlen(zFilename);
|
||||
zTemp = sqliteMalloc( nFilename+100 );
|
||||
if( zTemp==0 ) return;
|
||||
if( zTemp==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
strcpy(zTemp, zFilename);
|
||||
for(i=0; i<10; i++){
|
||||
zTemp[nFilename] = '-';
|
||||
randomName(&zTemp[nFilename+1]);
|
||||
if( !sqliteOsFileExists(zTemp) ) break;
|
||||
}
|
||||
if( i>=10 ){
|
||||
sqliteErrorMsg(pParse, "unable to create a temporary database file "
|
||||
"in the same directory as the original database");
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
|
||||
|
||||
dbNew = sqlite_open(zTemp, 0, &zErrMsg);
|
||||
if( dbNew==0 ){
|
||||
sqliteErrorMsg(pParse, "unable to open a temporary database at %s - %s",
|
||||
zTemp, zErrMsg);
|
||||
/* 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( 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
|
||||
** occurs anyway. The integrity of the database is maintained by a
|
||||
** (possibly synchronous) transaction opened on the main database before
|
||||
** sqlite3BtreeCopyFile() is called.
|
||||
**
|
||||
** An optimisation would be to use a non-journaled pager.
|
||||
*/
|
||||
zSql = sqlite3MPrintf("ATTACH '%q' AS vacuum_db;", zTemp);
|
||||
if( !zSql ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
if( sqliteSafetyOff(db) ){
|
||||
sqliteErrorMsg(pParse, "library routines called out of sequence");
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
safety = 1;
|
||||
if( execsql(pParse, db, "BEGIN") ) goto end_of_vacuum;
|
||||
if( execsql(pParse, dbNew, "PRAGMA synchronous=off; BEGIN") ){
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
sVac.dbOld = db;
|
||||
sVac.dbNew = dbNew;
|
||||
sVac.pParse = pParse;
|
||||
for(i=0; rc==SQLITE_OK && i<sizeof(zPragma)/sizeof(zPragma[0]); i++){
|
||||
char zBuf[200];
|
||||
assert( strlen(zPragma[i])<100 );
|
||||
sprintf(zBuf, "PRAGMA %s;", zPragma[i]);
|
||||
sVac.zPragma = zPragma[i];
|
||||
rc = sqlite_exec(db, zBuf, vacuumCallback3, &sVac, &zErrMsg);
|
||||
}
|
||||
if( !rc ){
|
||||
rc = sqlite_exec(db, "SELECT type, name, sql FROM sqlite_master "
|
||||
"WHERE sql NOT NULL", vacuumCallback1, &sVac, &zErrMsg);
|
||||
}
|
||||
if( !rc ){
|
||||
rc = sqliteBtreeCopyFile(db->aDb[0].pBt, dbNew->aDb[0].pBt);
|
||||
sqlite_exec(db, "COMMIT", 0, 0, 0);
|
||||
sqlite_exec(db, "ROLLBACK", 0, 0, 0); /* In case the COMMIT failed */
|
||||
sqliteResetInternalSchema(db, 0);
|
||||
rc = execSql(db, zSql);
|
||||
sqliteFree(zSql);
|
||||
zSql = 0;
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
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;");
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Query the schema of the main database. Create a mirror schema
|
||||
** in the temporary database.
|
||||
*/
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14,100000000) "
|
||||
" 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 %'");
|
||||
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'"
|
||||
);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
/* Loop through the tables in the main database. For each, do
|
||||
** an "INSERT INTO vacuum_db.xxx SELECT * FROM xxx;" to copy
|
||||
** the contents to the temporary database.
|
||||
*/
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
|
||||
"|| ' SELECT * FROM ' || quote(name) || ';'"
|
||||
"FROM sqlite_master "
|
||||
"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
|
||||
** point also.
|
||||
*/
|
||||
rc = execExecSql(db,
|
||||
"SELECT 'CREATE TRIGGER vacuum_db.' || substr(sql, 16, 1000000) "
|
||||
"FROM sqlite_master WHERE type='trigger'"
|
||||
);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
|
||||
|
||||
/* At this point, unless the main db was completely empty, there is now a
|
||||
** transaction open on the vacuum database, but not on the main database.
|
||||
** Open a btree level transaction on the main database. This allows a
|
||||
** call to sqlite3BtreeCopyFile(). The main database btree level
|
||||
** transaction is then committed, so the SQL level never knows it was
|
||||
** opened for writing. This way, the SQL transaction used to create the
|
||||
** temporary database never needs to be committed.
|
||||
*/
|
||||
if( sqlite3BtreeIsInTrans(pTemp) ){
|
||||
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 */
|
||||
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;
|
||||
rc = sqlite3BtreeCommit(pMain);
|
||||
}
|
||||
|
||||
end_of_vacuum:
|
||||
if( rc && pParse->zErrMsg==0 && zErrMsg!=0 ){
|
||||
sqliteErrorMsg(pParse, "unable to vacuum database - %s", zErrMsg);
|
||||
/* 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
|
||||
** by manually setting the autoCommit flag to true and detaching the
|
||||
** vacuum database. The vacuum_db journal file is deleted when the pager
|
||||
** is closed by the DETACH.
|
||||
*/
|
||||
db->autoCommit = 1;
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = execSql(db, "DETACH vacuum_db;");
|
||||
}else{
|
||||
execSql(db, "DETACH vacuum_db;");
|
||||
}
|
||||
if( safety ) {
|
||||
sqlite_exec(db, "COMMIT", 0, 0, 0);
|
||||
sqlite_exec(db, "ROLLBACK", 0, 0, 0); /* In case the COMMIT failed */
|
||||
sqliteSafetyOn(db);
|
||||
if( zTemp ){
|
||||
sqlite3OsDelete(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
}
|
||||
if( dbNew ) sqlite_close(dbNew);
|
||||
sqliteOsDelete(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
sqliteFree(sVac.s1.z);
|
||||
sqliteFree(sVac.s2.z);
|
||||
if( zErrMsg ) sqlite_freemem(zErrMsg);
|
||||
return;
|
||||
if( zSql ) sqliteFree( zSql );
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
+2710
-3090
File diff suppressed because it is too large
Load Diff
+59
-26
@@ -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.68 2003/09/06 22:18:08 drh Exp $
|
||||
** $Id: vdbe.h,v 1.99 2005/09/20 17:42:23 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_VDBE_H_
|
||||
#define _SQLITE_VDBE_H_
|
||||
@@ -34,11 +34,11 @@ typedef struct Vdbe Vdbe;
|
||||
** as an instance of the following structure:
|
||||
*/
|
||||
struct VdbeOp {
|
||||
int opcode; /* What operation to perform */
|
||||
u8 opcode; /* What operation to perform */
|
||||
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 */
|
||||
@@ -46,18 +46,43 @@ struct VdbeOp {
|
||||
};
|
||||
typedef struct VdbeOp VdbeOp;
|
||||
|
||||
/*
|
||||
** A smaller version of VdbeOp used for the VdbeAddOpList() function because
|
||||
** it takes up less space.
|
||||
*/
|
||||
struct VdbeOpList {
|
||||
u8 opcode; /* What operation to perform */
|
||||
signed char p1; /* First operand */
|
||||
short int p2; /* Second parameter (often the jump destination) */
|
||||
char *p3; /* Third parameter */
|
||||
};
|
||||
typedef struct VdbeOpList VdbeOpList;
|
||||
|
||||
/*
|
||||
** Allowed values of VdbeOp.p3type
|
||||
*/
|
||||
#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
|
||||
** argument is P3_KEYINFO_HANDOFF, the passed in pointer is used. It still
|
||||
** gets freed when the Vdbe is finalized so it still should be obtained
|
||||
** from a single sqliteMalloc(). But no copy is made and the calling
|
||||
** function should *not* try to free the KeyInfo.
|
||||
*/
|
||||
#define P3_KEYINFO_HANDOFF (-9)
|
||||
|
||||
/*
|
||||
** The following macro converts a relative address in the p2 field
|
||||
** of a VdbeOp structure into a negative number so that
|
||||
** sqliteVdbeAddOpList() knows that the address is relative. Calling
|
||||
** sqlite3VdbeAddOpList() knows that the address is relative. Calling
|
||||
** the macro again restores the address.
|
||||
*/
|
||||
#define ADDR(X) (-1-(X))
|
||||
@@ -72,27 +97,35 @@ typedef struct VdbeOp VdbeOp;
|
||||
** Prototypes for the VDBE interface. See comments on the implementation
|
||||
** for a description of what each of these routines does.
|
||||
*/
|
||||
Vdbe *sqliteVdbeCreate(sqlite*);
|
||||
void sqliteVdbeCreateCallback(Vdbe*, int*);
|
||||
int sqliteVdbeAddOp(Vdbe*,int,int,int);
|
||||
int sqliteVdbeAddOpList(Vdbe*, int nOp, VdbeOp const *aOp);
|
||||
void sqliteVdbeChangeP1(Vdbe*, int addr, int P1);
|
||||
void sqliteVdbeChangeP2(Vdbe*, int addr, int P2);
|
||||
void sqliteVdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
|
||||
void sqliteVdbeDequoteP3(Vdbe*, int addr);
|
||||
int sqliteVdbeFindOp(Vdbe*, int, int);
|
||||
VdbeOp *sqliteVdbeGetOp(Vdbe*, int);
|
||||
int sqliteVdbeMakeLabel(Vdbe*);
|
||||
void sqliteVdbeDelete(Vdbe*);
|
||||
void sqliteVdbeMakeReady(Vdbe*,int,sqlite_callback,void*,int);
|
||||
int sqliteVdbeExec(Vdbe*);
|
||||
int sqliteVdbeList(Vdbe*);
|
||||
int sqliteVdbeFinalize(Vdbe*,char**);
|
||||
void sqliteVdbeResolveLabel(Vdbe*, int);
|
||||
int sqliteVdbeCurrentAddr(Vdbe*);
|
||||
void sqliteVdbeTrace(Vdbe*,FILE*);
|
||||
void sqliteVdbeCompressSpace(Vdbe*,int);
|
||||
int sqliteVdbeReset(Vdbe*,char **);
|
||||
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);
|
||||
VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
|
||||
int sqlite3VdbeMakeLabel(Vdbe*);
|
||||
void sqlite3VdbeDelete(Vdbe*);
|
||||
void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
|
||||
int sqlite3VdbeFinalize(Vdbe*);
|
||||
void sqlite3VdbeResolveLabel(Vdbe*, int);
|
||||
int sqlite3VdbeCurrentAddr(Vdbe*);
|
||||
void sqlite3VdbeTrace(Vdbe*,FILE*);
|
||||
int sqlite3VdbeReset(Vdbe*);
|
||||
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*, ...);
|
||||
# define VdbeComment(X) sqlite3VdbeComment X
|
||||
#else
|
||||
# define VdbeComment(X)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+225
-147
@@ -17,12 +17,19 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
** The makefile scans this source file and creates the following
|
||||
** array of string constants which are the names of all VDBE opcodes.
|
||||
** This array is defined in a separate source code file named opcode.c
|
||||
** which is automatically generated by the makefile.
|
||||
** intToKey() and keyToInt() used to transform the rowid. But with
|
||||
** the latest versions of the design they are no-ops.
|
||||
*/
|
||||
extern char *sqliteOpcodeNames[];
|
||||
#define keyToInt(X) (X)
|
||||
#define intToKey(X) (X)
|
||||
|
||||
/*
|
||||
** The makefile scans the vdbe.c source file and creates the following
|
||||
** array of string constants which are the names of all VDBE opcodes. This
|
||||
** array is defined in a separate source code file named opcode.c which is
|
||||
** automatically generated by the makefile.
|
||||
*/
|
||||
extern char *sqlite3OpcodeNames[];
|
||||
|
||||
/*
|
||||
** SQL is translated into a sequence of instructions to be
|
||||
@@ -53,40 +60,41 @@ typedef unsigned char Bool;
|
||||
*/
|
||||
struct Cursor {
|
||||
BtCursor *pCursor; /* The cursor structure of the backend */
|
||||
int lastRecno; /* Last recno from a Next or NextIdx operation */
|
||||
int nextRowid; /* Next rowid returned by OP_NewRowid */
|
||||
Bool recnoIsValid; /* True if lastRecno is valid */
|
||||
Bool keyAsData; /* The OP_Column command works on key instead of data */
|
||||
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 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 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 */
|
||||
int nData; /* Number of bytes in pData */
|
||||
char *pData; /* Data for a NEW or OLD pseudo-table */
|
||||
int iKey; /* Key for the NEW or OLD pseudo-table row */
|
||||
i64 iKey; /* Key for the NEW or OLD pseudo-table row */
|
||||
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.
|
||||
** zRow might point to (ephemeral) data for the current row, or it might
|
||||
** be NULL. */
|
||||
Bool cacheValid; /* True if the cache is valid */
|
||||
int payloadSize; /* Total number of bytes in the record */
|
||||
u32 *aType; /* Type values for all entries in the record */
|
||||
u32 *aOffset; /* Cached offsets to the start of each columns data */
|
||||
u8 *aRow; /* Data for the current row, if all on one page */
|
||||
};
|
||||
typedef struct Cursor Cursor;
|
||||
|
||||
/*
|
||||
** 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 */
|
||||
int nData; /* Number of bytes in the data */
|
||||
char *pData; /* The data associated with this key */
|
||||
Sorter *pNext; /* Next in the list */
|
||||
};
|
||||
|
||||
/*
|
||||
** Number of buckets used for merge-sort.
|
||||
*/
|
||||
#define NSORT 30
|
||||
|
||||
/*
|
||||
** Number of bytes of string storage space available to each stack
|
||||
** layer without having to malloc. NBFS is short for Number of Bytes
|
||||
@@ -95,47 +103,81 @@ struct Sorter {
|
||||
#define NBFS 32
|
||||
|
||||
/*
|
||||
** A single level of the stack is an instance of the following
|
||||
** structure. Except, string values are stored on a separate
|
||||
** list of of pointers to character. The reason for storing
|
||||
** strings separately is so that they can be easily passed
|
||||
** to the callback function.
|
||||
*/
|
||||
struct Stack {
|
||||
int i; /* Integer value */
|
||||
int n; /* Number of characters in string value, including '\0' */
|
||||
int flags; /* Some combination of STK_Null, STK_Str, STK_Dyn, etc. */
|
||||
double r; /* Real value */
|
||||
char z[NBFS]; /* Space for short strings */
|
||||
};
|
||||
typedef struct Stack Stack;
|
||||
|
||||
/*
|
||||
** Memory cells use the same structure as the stack except that space
|
||||
** for an arbitrary string is added.
|
||||
** Internally, the vdbe manipulates nearly all SQL values as Mem
|
||||
** structures. Each Mem struct may cache multiple representations (string,
|
||||
** integer etc.) of the same value. A value (and therefore Mem structure)
|
||||
** has the following properties:
|
||||
**
|
||||
** Each value has a manifest type. The manifest type of the value stored
|
||||
** in a Mem struct is returned by the MemType(Mem*) macro. The type is
|
||||
** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
|
||||
** SQLITE_BLOB.
|
||||
*/
|
||||
struct Mem {
|
||||
Stack s; /* All values of the memory cell besides string */
|
||||
char *z; /* String value for this memory cell */
|
||||
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 */
|
||||
void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
|
||||
char zShort[NBFS]; /* Space for short strings */
|
||||
};
|
||||
typedef struct Mem Mem;
|
||||
|
||||
/*
|
||||
** Allowed values for Stack.flags
|
||||
/* One or more of the following flags are set to indicate the validOK
|
||||
** representations of the value stored in the Mem struct.
|
||||
**
|
||||
** If the MEM_Null flag is set, then the value is an SQL NULL value.
|
||||
** No other flags may be set in this case.
|
||||
**
|
||||
** If the MEM_Str flag is set then Mem.z points at a string representation.
|
||||
** Usually this is encoded in the same unicode encoding as the main
|
||||
** database (see below for exceptions). If the MEM_Term flag is also
|
||||
** set, then the string is nul terminated. The MEM_Int and MEM_Real
|
||||
** flags may coexist with the MEM_Str flag.
|
||||
**
|
||||
** Multiple of these values can appear in Mem.flags. But only one
|
||||
** at a time can appear in Mem.type.
|
||||
*/
|
||||
#define STK_Null 0x0001 /* Value is NULL */
|
||||
#define STK_Str 0x0002 /* Value is a string */
|
||||
#define STK_Int 0x0004 /* Value is an integer */
|
||||
#define STK_Real 0x0008 /* Value is a real number */
|
||||
#define STK_Dyn 0x0010 /* Need to call sqliteFree() on zStack[] */
|
||||
#define STK_Static 0x0020 /* zStack[] points to a static string */
|
||||
#define STK_Ephem 0x0040 /* zStack[] points to an ephemeral string */
|
||||
#define MEM_Null 0x0001 /* Value is NULL */
|
||||
#define MEM_Str 0x0002 /* Value is a string */
|
||||
#define MEM_Int 0x0004 /* Value is an integer */
|
||||
#define MEM_Real 0x0008 /* Value is a real number */
|
||||
#define MEM_Blob 0x0010 /* Value is a BLOB */
|
||||
|
||||
/* The following STK_ 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.
|
||||
/* Whenever Mem contains a valid string or blob representation, one of
|
||||
** the following flags must be set to determine the memory management
|
||||
** policy for Mem.z. The MEM_Term flag tells us whether or not the
|
||||
** string is \000 or \u0000 terminated
|
||||
*/
|
||||
#define STK_AggCtx 0x0040 /* zStack[] points to an agg function context */
|
||||
#define MEM_Term 0x0020 /* String rep is nul terminated */
|
||||
#define MEM_Dyn 0x0040 /* Need to call sqliteFree() on Mem.z */
|
||||
#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 */
|
||||
#define MEM_Agg 0x0400 /* Mem.z points to an agg function context */
|
||||
|
||||
|
||||
/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
|
||||
** additional information about auxiliary information bound to arguments
|
||||
** of the function. This is used to implement the sqlite3_get_auxdata()
|
||||
** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
|
||||
** that can be associated with a constant argument to a function. This
|
||||
** allows functions such as "regexp" to compile their constant regular
|
||||
** expression argument once and reused the compiled code for multiple
|
||||
** invocations.
|
||||
*/
|
||||
struct VdbeFunc {
|
||||
FuncDef *pFunc; /* The definition of the function */
|
||||
int nAux; /* Number of entries allocated for apAux[] */
|
||||
struct AuxData {
|
||||
void *pAux; /* Aux data for the i-th argument */
|
||||
void (*xDelete)(void *); /* Destructor for the aux data */
|
||||
} apAux[1]; /* One slot for each function argument */
|
||||
};
|
||||
typedef struct VdbeFunc VdbeFunc;
|
||||
|
||||
/*
|
||||
** The "context" argument for a installable function. A pointer to an
|
||||
@@ -147,39 +189,16 @@ typedef struct Mem Mem;
|
||||
** 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
|
||||
** (Stack) which are only defined there.
|
||||
** This structure is defined inside of vdbeInt.h because it uses substructures
|
||||
** (Mem) which are only defined there.
|
||||
*/
|
||||
struct sqlite_func {
|
||||
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
|
||||
Stack s; /* Small strings, ints, and double values go here */
|
||||
char *z; /* Space for holding dynamic string results */
|
||||
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 */
|
||||
};
|
||||
|
||||
/*
|
||||
** 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 */
|
||||
HashElem *pSearch; /* The hash element for pCurrent */
|
||||
Hash hash; /* Hash table of all aggregate elements */
|
||||
FuncDef **apFunc; /* Information about aggregate functions */
|
||||
};
|
||||
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 */
|
||||
struct sqlite3_context {
|
||||
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
|
||||
VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
|
||||
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 */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -195,28 +214,56 @@ 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 */
|
||||
int 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).
|
||||
** 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 */
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of the virtual machine. This structure contains the complete
|
||||
** state of the virtual machine.
|
||||
**
|
||||
** The "sqlite_vm" structure pointer that is returned by sqlite_compile()
|
||||
** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile()
|
||||
** 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 */
|
||||
@@ -225,47 +272,42 @@ struct Vdbe {
|
||||
int nLabel; /* Number of labels used */
|
||||
int nLabelAlloc; /* Number of slots allocated in aLabel[] */
|
||||
int *aLabel; /* Space to hold the labels */
|
||||
int tos; /* Index of top of stack */
|
||||
Stack *aStack; /* The operand stack, except string values */
|
||||
char **zStack; /* Text or binary values of the stack */
|
||||
char **azColName; /* Becomes the 4th parameter to callbacks */
|
||||
int nCursor; /* Number of slots in aCsr[] */
|
||||
Cursor *aCsr; /* One element of this array for each open cursor */
|
||||
Sorter *pSort; /* A linked list of objects to be sorted */
|
||||
FILE *pFile; /* At most one open file handler */
|
||||
int nField; /* Number of file fields */
|
||||
char **azField; /* Data for each file field */
|
||||
int nVar; /* Number of entries in azVariable[] */
|
||||
char **azVar; /* Values for the OP_Variable opcode */
|
||||
int *anVar; /* Length of each value in azVariable[] */
|
||||
u8 *abVar; /* TRUE if azVariable[i] needs to be sqliteFree()ed */
|
||||
char *zLine; /* A single line from the input file */
|
||||
int nLineAlloc; /* Number of spaces allocated for zLine */
|
||||
Mem *aStack; /* The operand stack, except string values */
|
||||
Mem *pTos; /* Top entry in the operand stack */
|
||||
Mem **apArg; /* Arguments to currently executing user function */
|
||||
Mem *aColName; /* Column names to return */
|
||||
int nCursor; /* Number of slots in apCsr[] */
|
||||
Cursor **apCsr; /* One element of this array for each open cursor */
|
||||
int nVar; /* Number of entries in aVar[] */
|
||||
Mem *aVar; /* Values for the OP_Variable opcode. */
|
||||
char **azVar; /* Name of variables */
|
||||
int okVar; /* True if azVar[] has been initialized */
|
||||
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 nSet; /* Number of sets allocated */
|
||||
Set *aSet; /* An array of sets */
|
||||
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 */
|
||||
int rc; /* Value to return */
|
||||
unsigned uniqueCnt; /* Used by OP_MakeRecord when P2!=0 */
|
||||
int errorAction; /* Recovery action to do in case of an error */
|
||||
int undoTransOnError; /* If error, either ROLLBACK or COMMIT */
|
||||
int inTempTrans; /* True if temp database is transactioned */
|
||||
int returnStack[100]; /* Return address stack for OP_Gosub & OP_Return */
|
||||
int returnDepth; /* Next unused element in returnStack[] */
|
||||
int nResColumn; /* Number of columns in one row of the result set */
|
||||
char **azResColumn; /* Values for one row of result */
|
||||
int (*xCallback)(void*,int,char**,char**); /* Callback for SELECT results */
|
||||
void *pCbArg; /* First argument to xCallback() */
|
||||
char **azResColumn; /* Values for one row of result */
|
||||
int popStack; /* Pop the stack this much on entry to VdbeExec() */
|
||||
char *zErrMsg; /* Error message written here */
|
||||
u8 resOnStack; /* True if there are result values on the stack */
|
||||
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 */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -276,24 +318,60 @@ struct Vdbe {
|
||||
#define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */
|
||||
#define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */
|
||||
|
||||
/*
|
||||
** Here is a macro to handle the common case of popping the stack
|
||||
** once. This macro only works from within the sqliteVdbeExec()
|
||||
** function.
|
||||
*/
|
||||
#define POPSTACK \
|
||||
assert(p->tos>=0); \
|
||||
if( aStack[p->tos].flags & STK_Dyn ) sqliteFree(zStack[p->tos]); \
|
||||
p->tos--;
|
||||
|
||||
/*
|
||||
** Function prototypes
|
||||
*/
|
||||
void sqliteVdbeCleanupCursor(Cursor*);
|
||||
void sqliteVdbeSorterReset(Vdbe*);
|
||||
void sqliteVdbeAggReset(Agg*);
|
||||
void sqliteVdbeKeylistFree(Keylist*);
|
||||
void sqlite3VdbeFreeCursor(Cursor*);
|
||||
void sqliteVdbePopStack(Vdbe*,int);
|
||||
#if !defined(NDEBUG) || defined(VDBE_PROFILE)
|
||||
void sqliteVdbePrintOp(FILE*, int, Op*);
|
||||
int sqlite3VdbeCursorMoveto(Cursor*);
|
||||
#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*);
|
||||
int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
|
||||
void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
|
||||
|
||||
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
|
||||
int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int*);
|
||||
int sqlite3VdbeIdxRowid(BtCursor *, i64 *);
|
||||
int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
|
||||
int sqlite3VdbeRecordCompare(void*,int,const void*,int, const void*);
|
||||
int sqlite3VdbeIdxRowidLen(int,const u8*);
|
||||
int sqlite3VdbeExec(Vdbe*);
|
||||
int sqlite3VdbeList(Vdbe*);
|
||||
int sqlite3VdbeHalt(Vdbe*);
|
||||
int sqlite3VdbeChangeEncoding(Mem *, int);
|
||||
int sqlite3VdbeMemCopy(Mem*, const Mem*);
|
||||
void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
|
||||
int sqlite3VdbeMemMove(Mem*, Mem*);
|
||||
int sqlite3VdbeMemNulTerminate(Mem*);
|
||||
int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
|
||||
void sqlite3VdbeMemSetInt64(Mem*, i64);
|
||||
void sqlite3VdbeMemSetDouble(Mem*, double);
|
||||
void sqlite3VdbeMemSetNull(Mem*);
|
||||
int sqlite3VdbeMemMakeWriteable(Mem*);
|
||||
int sqlite3VdbeMemDynamicify(Mem*);
|
||||
int sqlite3VdbeMemStringify(Mem*, int);
|
||||
i64 sqlite3VdbeIntValue(Mem*);
|
||||
int sqlite3VdbeMemIntegerify(Mem*);
|
||||
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*);
|
||||
|
||||
+737
@@ -0,0 +1,737 @@
|
||||
/*
|
||||
** 2004 May 26
|
||||
**
|
||||
** 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 use to implement APIs that are part of the
|
||||
** VDBE.
|
||||
*/
|
||||
#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
|
||||
** structure.
|
||||
*/
|
||||
const void *sqlite3_value_blob(sqlite3_value *pVal){
|
||||
Mem *p = (Mem*)pVal;
|
||||
if( p->flags & (MEM_Blob|MEM_Str) ){
|
||||
return p->z;
|
||||
}else{
|
||||
return sqlite3_value_text(pVal);
|
||||
}
|
||||
}
|
||||
int sqlite3_value_bytes(sqlite3_value *pVal){
|
||||
return sqlite3ValueBytes(pVal, SQLITE_UTF8);
|
||||
}
|
||||
int sqlite3_value_bytes16(sqlite3_value *pVal){
|
||||
return sqlite3ValueBytes(pVal, SQLITE_UTF16NATIVE);
|
||||
}
|
||||
double sqlite3_value_double(sqlite3_value *pVal){
|
||||
return sqlite3VdbeRealValue((Mem*)pVal);
|
||||
}
|
||||
int sqlite3_value_int(sqlite3_value *pVal){
|
||||
return sqlite3VdbeIntValue((Mem*)pVal);
|
||||
}
|
||||
sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
|
||||
return sqlite3VdbeIntValue((Mem*)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);
|
||||
}
|
||||
const void *sqlite3_value_text16be(sqlite3_value *pVal){
|
||||
return sqlite3ValueText(pVal, SQLITE_UTF16BE);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**************************** sqlite3_result_ *******************************
|
||||
** The following routines are used by user-defined functions to specify
|
||||
** the function result.
|
||||
*/
|
||||
void sqlite3_result_blob(
|
||||
sqlite3_context *pCtx,
|
||||
const void *z,
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
assert( n>=0 );
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, 0, xDel);
|
||||
}
|
||||
void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
|
||||
sqlite3VdbeMemSetDouble(&pCtx->s, rVal);
|
||||
}
|
||||
void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){
|
||||
pCtx->isError = 1;
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT);
|
||||
}
|
||||
void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){
|
||||
pCtx->isError = 1;
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT);
|
||||
}
|
||||
void sqlite3_result_int(sqlite3_context *pCtx, int iVal){
|
||||
sqlite3VdbeMemSetInt64(&pCtx->s, (i64)iVal);
|
||||
}
|
||||
void sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){
|
||||
sqlite3VdbeMemSetInt64(&pCtx->s, iVal);
|
||||
}
|
||||
void sqlite3_result_null(sqlite3_context *pCtx){
|
||||
sqlite3VdbeMemSetNull(&pCtx->s);
|
||||
}
|
||||
void sqlite3_result_text(
|
||||
sqlite3_context *pCtx,
|
||||
const char *z,
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, xDel);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
void sqlite3_result_text16(
|
||||
sqlite3_context *pCtx,
|
||||
const void *z,
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, xDel);
|
||||
}
|
||||
void sqlite3_result_text16be(
|
||||
sqlite3_context *pCtx,
|
||||
const void *z,
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16BE, xDel);
|
||||
}
|
||||
void sqlite3_result_text16le(
|
||||
sqlite3_context *pCtx,
|
||||
const void *z,
|
||||
int n,
|
||||
void (*xDel)(void *)
|
||||
){
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Execute the statement pStmt, either until a row of data is ready, the
|
||||
** statement is completely executed or an error occurs.
|
||||
*/
|
||||
int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
sqlite3 *db;
|
||||
int rc;
|
||||
|
||||
if( p==0 || p->magic!=VDBE_MAGIC_RUN ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
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
|
||||
#endif /* SQLITE_OMIT_EXPLAIN */
|
||||
{
|
||||
rc = sqlite3VdbeExec(p);
|
||||
}
|
||||
|
||||
if( sqlite3SafetyOff(db) ){
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
/*
|
||||
** Extract the user data from a sqlite3_context structure and return a
|
||||
** pointer to it.
|
||||
*/
|
||||
void *sqlite3_user_data(sqlite3_context *p){
|
||||
assert( p && p->pFunc );
|
||||
return p->pFunc->pUserData;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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.
|
||||
*/
|
||||
void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){
|
||||
Mem *pMem = p->pMem;
|
||||
assert( p && p->pFunc && p->pFunc->xStep );
|
||||
if( (pMem->flags & MEM_Agg)==0 ){
|
||||
if( nByte==0 ){
|
||||
assert( pMem->flags==MEM_Null );
|
||||
pMem->z = 0;
|
||||
}else{
|
||||
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 (void*)pMem->z;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the auxilary data pointer, if any, for the iArg'th argument to
|
||||
** the user-function defined by pCtx.
|
||||
*/
|
||||
void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
|
||||
VdbeFunc *pVdbeFunc = pCtx->pVdbeFunc;
|
||||
if( !pVdbeFunc || iArg>=pVdbeFunc->nAux || iArg<0 ){
|
||||
return 0;
|
||||
}
|
||||
return pVdbeFunc->apAux[iArg].pAux;
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the auxilary data pointer and delete function, for the iArg'th
|
||||
** argument to the user-function defined by pCtx. Any previous value is
|
||||
** deleted by calling the delete function specified when it was set.
|
||||
*/
|
||||
void sqlite3_set_auxdata(
|
||||
sqlite3_context *pCtx,
|
||||
int iArg,
|
||||
void *pAux,
|
||||
void (*xDelete)(void*)
|
||||
){
|
||||
struct AuxData *pAuxData;
|
||||
VdbeFunc *pVdbeFunc;
|
||||
if( iArg<0 ) return;
|
||||
|
||||
pVdbeFunc = pCtx->pVdbeFunc;
|
||||
if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
|
||||
int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
|
||||
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;
|
||||
pVdbeFunc->pFunc = pCtx->pFunc;
|
||||
}
|
||||
|
||||
pAuxData = &pVdbeFunc->apAux[iArg];
|
||||
if( pAuxData->pAux && pAuxData->xDelete ){
|
||||
pAuxData->xDelete(pAuxData->pAux);
|
||||
}
|
||||
pAuxData->pAux = pAux;
|
||||
pAuxData->xDelete = xDelete;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of times the Step function of a aggregate has been
|
||||
** called.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
int sqlite3_aggregate_count(sqlite3_context *p){
|
||||
assert( p && p->pFunc && p->pFunc->xStep );
|
||||
return p->pMem->n;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of columns in the result set for the statement pStmt.
|
||||
*/
|
||||
int sqlite3_column_count(sqlite3_stmt *pStmt){
|
||||
Vdbe *pVm = (Vdbe *)pStmt;
|
||||
return pVm ? pVm->nResColumn : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of values available from the current row of the
|
||||
** currently executing statement pStmt.
|
||||
*/
|
||||
int sqlite3_data_count(sqlite3_stmt *pStmt){
|
||||
Vdbe *pVm = (Vdbe *)pStmt;
|
||||
if( pVm==0 || !pVm->resOnStack ) return 0;
|
||||
return pVm->nResColumn;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Check to see if column iCol of the given statement is valid. If
|
||||
** it is, return a pointer to the Mem for the value of that column.
|
||||
** If iCol is not valid, return a pointer to a Mem which has a value
|
||||
** of NULL.
|
||||
*/
|
||||
static Mem *columnMem(sqlite3_stmt *pStmt, int i){
|
||||
Vdbe *pVm = (Vdbe *)pStmt;
|
||||
int vals = sqlite3_data_count(pStmt);
|
||||
if( i>=vals || i<0 ){
|
||||
static Mem nullMem;
|
||||
if( nullMem.flags==0 ){ nullMem.flags = MEM_Null; }
|
||||
sqlite3Error(pVm->db, SQLITE_RANGE, 0);
|
||||
return &nullMem;
|
||||
}
|
||||
return &pVm->pTos[(1-vals)+i];
|
||||
}
|
||||
|
||||
/**************************** sqlite3_column_ *******************************
|
||||
** The following routines are used to access elements of the current row
|
||||
** in the result set.
|
||||
*/
|
||||
const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_blob( columnMem(pStmt,i) );
|
||||
}
|
||||
int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_bytes( columnMem(pStmt,i) );
|
||||
}
|
||||
int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_bytes16( columnMem(pStmt,i) );
|
||||
}
|
||||
double sqlite3_column_double(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_double( columnMem(pStmt,i) );
|
||||
}
|
||||
int sqlite3_column_int(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_int( columnMem(pStmt,i) );
|
||||
}
|
||||
sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_int64( columnMem(pStmt,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){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 0);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
|
||||
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.
|
||||
*/
|
||||
const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
|
||||
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 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 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_ ***************************
|
||||
**
|
||||
** Routines used to attach values to wildcards in a compiled SQL statement.
|
||||
*/
|
||||
/*
|
||||
** Unbind the value bound to variable i in virtual machine p. This is the
|
||||
** the same as binding a NULL value to the column. If the "i" parameter is
|
||||
** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK.
|
||||
**
|
||||
** The error code stored in database p->db is overwritten with the return
|
||||
** value in any case.
|
||||
*/
|
||||
static int vdbeUnbind(Vdbe *p, int i){
|
||||
Mem *pVar;
|
||||
if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
|
||||
if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( i<1 || i>p->nVar ){
|
||||
sqlite3Error(p->db, SQLITE_RANGE, 0);
|
||||
return SQLITE_RANGE;
|
||||
}
|
||||
i--;
|
||||
pVar = &p->aVar[i];
|
||||
sqlite3VdbeMemRelease(pVar);
|
||||
pVar->flags = MEM_Null;
|
||||
sqlite3Error(p->db, SQLITE_OK, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Bind a text or BLOB value.
|
||||
*/
|
||||
static int bindText(
|
||||
sqlite3_stmt *pStmt,
|
||||
int i,
|
||||
const void *zData,
|
||||
int nData,
|
||||
void (*xDel)(void*),
|
||||
int encoding
|
||||
){
|
||||
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, 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;
|
||||
rc = vdbeUnbind(p, i);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
|
||||
return sqlite3_bind_int64(p, i, (i64)iValue);
|
||||
}
|
||||
int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
|
||||
int rc;
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
rc = vdbeUnbind(p, i);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
int sqlite3_bind_null(sqlite3_stmt* p, int i){
|
||||
return vdbeUnbind((Vdbe *)p, i);
|
||||
}
|
||||
int sqlite3_bind_text(
|
||||
sqlite3_stmt *pStmt,
|
||||
int i,
|
||||
const char *zData,
|
||||
int nData,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
int sqlite3_bind_text16(
|
||||
sqlite3_stmt *pStmt,
|
||||
int i,
|
||||
const void *zData,
|
||||
int nData,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
/*
|
||||
** Return the number of wildcards that can be potentially bound to.
|
||||
** This routine is added to support DBD::SQLite.
|
||||
*/
|
||||
int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
|
||||
Vdbe *p = (Vdbe*)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.
|
||||
**
|
||||
** The result is always UTF-8.
|
||||
*/
|
||||
const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
if( p==0 || i<1 || i>p->nVar ){
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
+1435
-607
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);
|
||||
}
|
||||
+840
@@ -0,0 +1,840 @@
|
||||
/*
|
||||
** 2004 May 26
|
||||
**
|
||||
** 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 use to manipulate "Mem" structure. A "Mem"
|
||||
** stores a single value in the VDBE. Mem is an opaque structure visible
|
||||
** only within the VDBE. Interface routines refer to a Mem using the
|
||||
** name sqlite_value
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
#include <ctype.h>
|
||||
#include "vdbeInt.h"
|
||||
|
||||
/*
|
||||
** If pMem is an object with a valid string representation, this routine
|
||||
** ensures the internal encoding for the string representation is
|
||||
** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
|
||||
**
|
||||
** If pMem is not a string object, or the encoding of the string
|
||||
** representation is already stored using the requested encoding, then this
|
||||
** routine is a no-op.
|
||||
**
|
||||
** SQLITE_OK is returned if the conversion is successful (or not required).
|
||||
** SQLITE_NOMEM may be returned if a malloc() fails during conversion
|
||||
** between formats.
|
||||
*/
|
||||
int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
|
||||
int rc;
|
||||
if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
#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
|
||||
}
|
||||
|
||||
/*
|
||||
** Make the given Mem object MEM_Dyn.
|
||||
**
|
||||
** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
|
||||
*/
|
||||
int sqlite3VdbeMemDynamicify(Mem *pMem){
|
||||
int n = pMem->n;
|
||||
u8 *z;
|
||||
if( (pMem->flags & (MEM_Ephem|MEM_Static|MEM_Short))==0 ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
assert( (pMem->flags & MEM_Dyn)==0 );
|
||||
assert( pMem->flags & (MEM_Str|MEM_Blob) );
|
||||
z = sqliteMallocRaw( n+2 );
|
||||
if( z==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pMem->flags |= MEM_Dyn|MEM_Term;
|
||||
pMem->xDel = 0;
|
||||
memcpy(z, pMem->z, n );
|
||||
z[n] = 0;
|
||||
z[n+1] = 0;
|
||||
pMem->z = z;
|
||||
pMem->flags &= ~(MEM_Ephem|MEM_Static|MEM_Short);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make the given Mem object either MEM_Short or MEM_Dyn so that bytes
|
||||
** of the Mem.z[] array can be modified.
|
||||
**
|
||||
** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
|
||||
*/
|
||||
int sqlite3VdbeMemMakeWriteable(Mem *pMem){
|
||||
int n;
|
||||
u8 *z;
|
||||
if( (pMem->flags & (MEM_Ephem|MEM_Static))==0 ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
assert( (pMem->flags & MEM_Dyn)==0 );
|
||||
assert( pMem->flags & (MEM_Str|MEM_Blob) );
|
||||
if( (n = pMem->n)+2<sizeof(pMem->zShort) ){
|
||||
z = pMem->zShort;
|
||||
pMem->flags |= MEM_Short|MEM_Term;
|
||||
}else{
|
||||
z = sqliteMallocRaw( n+2 );
|
||||
if( z==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pMem->flags |= MEM_Dyn|MEM_Term;
|
||||
pMem->xDel = 0;
|
||||
}
|
||||
memcpy(z, pMem->z, n );
|
||||
z[n] = 0;
|
||||
z[n+1] = 0;
|
||||
pMem->z = z;
|
||||
pMem->flags &= ~(MEM_Ephem|MEM_Static);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make sure the given Mem is \u0000 terminated.
|
||||
*/
|
||||
int sqlite3VdbeMemNulTerminate(Mem *pMem){
|
||||
/* In SQLite, a string without a nul terminator occurs when a string
|
||||
** is loaded from disk (in this case the memory management is ephemeral),
|
||||
** or when it is supplied by the user as a bound variable or function
|
||||
** return value. Therefore, the memory management of the string must be
|
||||
** either ephemeral, static or controlled by a user-supplied destructor.
|
||||
*/
|
||||
assert(
|
||||
!(pMem->flags&MEM_Str) || /* it's not a string, or */
|
||||
(pMem->flags&MEM_Term) || /* it's nul term. already, or */
|
||||
(pMem->flags&(MEM_Ephem|MEM_Static)) || /* it's static or ephem, or */
|
||||
(pMem->flags&MEM_Dyn && pMem->xDel) /* external management */
|
||||
);
|
||||
if( (pMem->flags & MEM_Term)!=0 || (pMem->flags & MEM_Str)==0 ){
|
||||
return SQLITE_OK; /* Nothing to do */
|
||||
}
|
||||
|
||||
if( pMem->flags & (MEM_Static|MEM_Ephem) ){
|
||||
return sqlite3VdbeMemMakeWriteable(pMem);
|
||||
}else{
|
||||
char *z = sqliteMalloc(pMem->n+2);
|
||||
if( !z ) return SQLITE_NOMEM;
|
||||
memcpy(z, pMem->z, pMem->n);
|
||||
z[pMem->n] = 0;
|
||||
z[pMem->n+1] = 0;
|
||||
pMem->xDel(pMem->z);
|
||||
pMem->xDel = 0;
|
||||
pMem->z = z;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Add MEM_Str to the set of representations for the given Mem. Numbers
|
||||
** are converted using sqlite3_snprintf(). Converting a BLOB to a string
|
||||
** is a no-op.
|
||||
**
|
||||
** Existing representations MEM_Int and MEM_Real are *not* invalidated.
|
||||
**
|
||||
** A MEM_Null value will never be passed to this function. This function is
|
||||
** used for converting values to text for returning to the user (i.e. via
|
||||
** sqlite3_value_text()), or for ensuring that values to be used as btree
|
||||
** keys are strings. In the former case a NULL pointer is returned the
|
||||
** user and the later is an internal programming error.
|
||||
*/
|
||||
int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
int rc = SQLITE_OK;
|
||||
int fg = pMem->flags;
|
||||
u8 *z = pMem->zShort;
|
||||
|
||||
assert( !(fg&(MEM_Str|MEM_Blob)) );
|
||||
assert( fg&(MEM_Int|MEM_Real) );
|
||||
|
||||
/* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
|
||||
** string representation of the value. Then, if the required encoding
|
||||
** is UTF-16le or UTF-16be do a translation.
|
||||
**
|
||||
** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
|
||||
*/
|
||||
if( fg & MEM_Real ){
|
||||
sqlite3_snprintf(NBFS, z, "%!.15g", pMem->r);
|
||||
}else{
|
||||
assert( fg & MEM_Int );
|
||||
sqlite3_snprintf(NBFS, z, "%lld", pMem->i);
|
||||
}
|
||||
pMem->n = strlen(z);
|
||||
pMem->z = z;
|
||||
pMem->enc = SQLITE_UTF8;
|
||||
pMem->flags |= MEM_Str | MEM_Short | MEM_Term;
|
||||
sqlite3VdbeChangeEncoding(pMem, 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|MEM_Agg) ){
|
||||
if( p->xDel ){
|
||||
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);
|
||||
}
|
||||
p->z = 0;
|
||||
p->xDel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Return some kind of integer value which is the best we can do
|
||||
** at representing the value that *pMem describes as an integer.
|
||||
** If pMem is an integer, then the value is exact. If pMem is
|
||||
** a floating-point then the value returned is the integer part.
|
||||
** If pMem is a string or blob, then we make an attempt to convert
|
||||
** it into a integer and return that. If pMem is NULL, return 0.
|
||||
**
|
||||
** If pMem is a string, its encoding might be changed.
|
||||
*/
|
||||
i64 sqlite3VdbeIntValue(Mem *pMem){
|
||||
int flags = pMem->flags;
|
||||
if( flags & MEM_Int ){
|
||||
return pMem->i;
|
||||
}else if( flags & MEM_Real ){
|
||||
return (i64)pMem->r;
|
||||
}else if( flags & (MEM_Str|MEM_Blob) ){
|
||||
i64 value;
|
||||
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|
||||
|| sqlite3VdbeMemNulTerminate(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( pMem->z );
|
||||
sqlite3atoi64(pMem->z, &value);
|
||||
return value;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem to type integer. Invalidate any prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
pMem->i = sqlite3VdbeIntValue(pMem);
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Int;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the best representation of pMem that we can get into a
|
||||
** double. If pMem is already a double or an integer, return its
|
||||
** value. If it is a string or blob, try to convert it to a double.
|
||||
** If it is a NULL, return 0.0.
|
||||
*/
|
||||
double sqlite3VdbeRealValue(Mem *pMem){
|
||||
if( pMem->flags & MEM_Real ){
|
||||
return pMem->r;
|
||||
}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 );
|
||||
sqlite3AtoF(pMem->z, &val);
|
||||
return val;
|
||||
}else{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert pMem so that it is of type MEM_Real. Invalidate any
|
||||
** prior representations.
|
||||
*/
|
||||
int sqlite3VdbeMemRealify(Mem *pMem){
|
||||
pMem->r = sqlite3VdbeRealValue(pMem);
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Real;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete any previous value and set the value stored in *pMem to NULL.
|
||||
*/
|
||||
void sqlite3VdbeMemSetNull(Mem *pMem){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Null;
|
||||
pMem->type = SQLITE_NULL;
|
||||
pMem->n = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete any previous value and set the value stored in *pMem to val,
|
||||
** manifest type INTEGER.
|
||||
*/
|
||||
void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->i = val;
|
||||
pMem->flags = MEM_Int;
|
||||
pMem->type = SQLITE_INTEGER;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete any previous value and set the value stored in *pMem to val,
|
||||
** manifest type REAL.
|
||||
*/
|
||||
void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->r = val;
|
||||
pMem->flags = MEM_Real;
|
||||
pMem->type = SQLITE_FLOAT;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make an shallow copy of pFrom into pTo. Prior contents of
|
||||
** pTo are overwritten. The pFrom->z field is not duplicated. If
|
||||
** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
|
||||
** and flags gets srcType (either MEM_Ephem or MEM_Static).
|
||||
*/
|
||||
void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
|
||||
memcpy(pTo, pFrom, sizeof(*pFrom)-sizeof(pFrom->zShort));
|
||||
pTo->xDel = 0;
|
||||
if( pTo->flags & (MEM_Str|MEM_Blob) ){
|
||||
pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Short|MEM_Ephem);
|
||||
assert( srcType==MEM_Ephem || srcType==MEM_Static );
|
||||
pTo->flags |= srcType;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Make a full copy of pFrom into pTo. Prior contents of pTo are
|
||||
** freed before the copy is made.
|
||||
*/
|
||||
int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
|
||||
int rc;
|
||||
if( pTo->flags & MEM_Dyn ){
|
||||
sqlite3VdbeMemRelease(pTo);
|
||||
}
|
||||
sqlite3VdbeMemShallowCopy(pTo, pFrom, MEM_Ephem);
|
||||
if( pTo->flags & MEM_Ephem ){
|
||||
rc = sqlite3VdbeMemMakeWriteable(pTo);
|
||||
}else{
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Transfer the contents of pFrom to pTo. Any existing value in pTo is
|
||||
** freed. If pFrom contains ephemeral data, a copy is made.
|
||||
**
|
||||
** pFrom contains an SQL NULL when this routine returns. SQLITE_NOMEM
|
||||
** might be returned if pFrom held ephemeral data and we were unable
|
||||
** to allocate enough space to make a copy.
|
||||
*/
|
||||
int sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){
|
||||
int rc;
|
||||
if( pTo->flags & MEM_Dyn ){
|
||||
sqlite3VdbeMemRelease(pTo);
|
||||
}
|
||||
memcpy(pTo, pFrom, sizeof(Mem));
|
||||
if( pFrom->flags & MEM_Short ){
|
||||
pTo->z = pTo->zShort;
|
||||
}
|
||||
pFrom->flags = MEM_Null;
|
||||
pFrom->xDel = 0;
|
||||
if( pTo->flags & MEM_Ephem ){
|
||||
rc = sqlite3VdbeMemMakeWriteable(pTo);
|
||||
}else{
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the value of a Mem to be a string or a BLOB.
|
||||
*/
|
||||
int sqlite3VdbeMemSetStr(
|
||||
Mem *pMem, /* Memory cell to set to string value */
|
||||
const char *z, /* String pointer */
|
||||
int n, /* Bytes in string, or negative */
|
||||
u8 enc, /* Encoding of z. 0 for BLOBs */
|
||||
void (*xDel)(void*) /* Destructor function */
|
||||
){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
if( !z ){
|
||||
pMem->flags = MEM_Null;
|
||||
pMem->type = SQLITE_NULL;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
pMem->z = (char *)z;
|
||||
if( xDel==SQLITE_STATIC ){
|
||||
pMem->flags = MEM_Static;
|
||||
}else if( xDel==SQLITE_TRANSIENT ){
|
||||
pMem->flags = MEM_Ephem;
|
||||
}else{
|
||||
pMem->flags = MEM_Dyn;
|
||||
pMem->xDel = xDel;
|
||||
}
|
||||
|
||||
pMem->enc = enc;
|
||||
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:
|
||||
pMem->flags |= MEM_Str;
|
||||
if( n<0 ){
|
||||
pMem->n = strlen(z);
|
||||
pMem->flags |= MEM_Term;
|
||||
}
|
||||
break;
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
case SQLITE_UTF16LE:
|
||||
case SQLITE_UTF16BE:
|
||||
pMem->flags |= MEM_Str;
|
||||
if( pMem->n<0 ){
|
||||
pMem->n = sqlite3utf16ByteLen(pMem->z,-1);
|
||||
pMem->flags |= MEM_Term;
|
||||
}
|
||||
if( sqlite3VdbeMemHandleBom(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
}
|
||||
if( pMem->flags&MEM_Ephem ){
|
||||
return sqlite3VdbeMemMakeWriteable(pMem);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Compare the values contained by the two memory cells, returning
|
||||
** negative, zero or positive if pMem1 is less than, equal to, or greater
|
||||
** than pMem2. Sorting order is NULL's first, followed by numbers (integers
|
||||
** and reals) sorted numerically, followed by text ordered by the collating
|
||||
** sequence pColl and finally blob's ordered by memcmp().
|
||||
**
|
||||
** Two NULL values are considered equal by this function.
|
||||
*/
|
||||
int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
|
||||
int rc;
|
||||
int f1, f2;
|
||||
int combined_flags;
|
||||
|
||||
/* Interchange pMem1 and pMem2 if the collating sequence specifies
|
||||
** DESC order.
|
||||
*/
|
||||
f1 = pMem1->flags;
|
||||
f2 = pMem2->flags;
|
||||
combined_flags = f1|f2;
|
||||
|
||||
/* If one value is NULL, it is less than the other. If both values
|
||||
** are NULL, return 0.
|
||||
*/
|
||||
if( combined_flags&MEM_Null ){
|
||||
return (f2&MEM_Null) - (f1&MEM_Null);
|
||||
}
|
||||
|
||||
/* If one value is a number and the other is not, the number is less.
|
||||
** If both are numbers, compare as reals if one is a real, or as integers
|
||||
** if both values are integers.
|
||||
*/
|
||||
if( combined_flags&(MEM_Int|MEM_Real) ){
|
||||
if( !(f1&(MEM_Int|MEM_Real)) ){
|
||||
return 1;
|
||||
}
|
||||
if( !(f2&(MEM_Int|MEM_Real)) ){
|
||||
return -1;
|
||||
}
|
||||
if( (f1 & f2 & MEM_Int)==0 ){
|
||||
double r1, r2;
|
||||
if( (f1&MEM_Real)==0 ){
|
||||
r1 = pMem1->i;
|
||||
}else{
|
||||
r1 = pMem1->r;
|
||||
}
|
||||
if( (f2&MEM_Real)==0 ){
|
||||
r2 = pMem2->i;
|
||||
}else{
|
||||
r2 = pMem2->r;
|
||||
}
|
||||
if( r1<r2 ) return -1;
|
||||
if( r1>r2 ) return 1;
|
||||
return 0;
|
||||
}else{
|
||||
assert( f1&MEM_Int );
|
||||
assert( f2&MEM_Int );
|
||||
if( pMem1->i < pMem2->i ) return -1;
|
||||
if( pMem1->i > pMem2->i ) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* If one value is a string and the other is a blob, the string is less.
|
||||
** If both are strings, compare using the collating functions.
|
||||
*/
|
||||
if( combined_flags&MEM_Str ){
|
||||
if( (f1 & MEM_Str)==0 ){
|
||||
return 1;
|
||||
}
|
||||
if( (f2 & MEM_Str)==0 ){
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert( pMem1->enc==pMem2->enc );
|
||||
assert( pMem1->enc==SQLITE_UTF8 ||
|
||||
pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
|
||||
|
||||
/* This assert may fail if the collation sequence is deleted after this
|
||||
** vdbe program is compiled. The documentation defines this as an
|
||||
** undefined condition. A crash is usual result.
|
||||
*/
|
||||
assert( !pColl || pColl->xCmp );
|
||||
|
||||
if( pColl ){
|
||||
if( pMem1->enc==pColl->enc ){
|
||||
return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
|
||||
}else{
|
||||
u8 origEnc = pMem1->enc;
|
||||
rc = pColl->xCmp(
|
||||
pColl->pUser,
|
||||
sqlite3ValueBytes((sqlite3_value*)pMem1, pColl->enc),
|
||||
sqlite3ValueText((sqlite3_value*)pMem1, pColl->enc),
|
||||
sqlite3ValueBytes((sqlite3_value*)pMem2, pColl->enc),
|
||||
sqlite3ValueText((sqlite3_value*)pMem2, pColl->enc)
|
||||
);
|
||||
sqlite3ValueBytes((sqlite3_value*)pMem1, origEnc);
|
||||
sqlite3ValueText((sqlite3_value*)pMem1, origEnc);
|
||||
sqlite3ValueBytes((sqlite3_value*)pMem2, origEnc);
|
||||
sqlite3ValueText((sqlite3_value*)pMem2, origEnc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
/* If a NULL pointer was passed as the collate function, fall through
|
||||
** to the blob case and use memcmp(). */
|
||||
}
|
||||
|
||||
/* Both values must be blobs. Compare using memcmp(). */
|
||||
rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
|
||||
if( rc==0 ){
|
||||
rc = pMem1->n - pMem2->n;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Move data out of a btree key or data field and into a Mem structure.
|
||||
** The data or key is taken from the entry that pCur is currently pointing
|
||||
** to. offset and amt determine what portion of the data or key to retrieve.
|
||||
** key is true to get the key or false to get data. The result is written
|
||||
** into the pMem element.
|
||||
**
|
||||
** The pMem structure is assumed to be uninitialized. Any prior content
|
||||
** is overwritten without being freed.
|
||||
**
|
||||
** If this routine fails for any reason (malloc returns NULL or unable
|
||||
** to read from the disk) then the pMem is left in an inconsistent state.
|
||||
*/
|
||||
int sqlite3VdbeMemFromBtree(
|
||||
BtCursor *pCur, /* Cursor pointing at record to retrieve. */
|
||||
int offset, /* Offset from the start of data to return bytes from. */
|
||||
int amt, /* Number of bytes to return. */
|
||||
int key, /* If true, retrieve from the btree key, not data. */
|
||||
Mem *pMem /* OUT: Return data in this Mem structure. */
|
||||
){
|
||||
char *zData; /* Data from the btree layer */
|
||||
int available; /* Number of bytes available on the local btree page */
|
||||
|
||||
if( key ){
|
||||
zData = (char *)sqlite3BtreeKeyFetch(pCur, &available);
|
||||
}else{
|
||||
zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
|
||||
}
|
||||
|
||||
pMem->n = amt;
|
||||
if( offset+amt<=available ){
|
||||
pMem->z = &zData[offset];
|
||||
pMem->flags = MEM_Blob|MEM_Ephem;
|
||||
}else{
|
||||
int rc;
|
||||
if( amt>NBFS-2 ){
|
||||
zData = (char *)sqliteMallocRaw(amt+2);
|
||||
if( !zData ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
|
||||
pMem->xDel = 0;
|
||||
}else{
|
||||
zData = &(pMem->zShort[0]);
|
||||
pMem->flags = MEM_Blob|MEM_Short|MEM_Term;
|
||||
}
|
||||
pMem->z = zData;
|
||||
pMem->enc = 0;
|
||||
pMem->type = SQLITE_BLOB;
|
||||
|
||||
if( key ){
|
||||
rc = sqlite3BtreeKey(pCur, offset, amt, zData);
|
||||
}else{
|
||||
rc = sqlite3BtreeData(pCur, offset, amt, zData);
|
||||
}
|
||||
zData[amt] = 0;
|
||||
zData[amt+1] = 0;
|
||||
if( rc!=SQLITE_OK ){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
/*
|
||||
** Perform various checks on the memory cell pMem. An assert() will
|
||||
** fail if pMem is internally inconsistent.
|
||||
*/
|
||||
void sqlite3VdbeMemSanity(Mem *pMem, u8 db_enc){
|
||||
int flags = pMem->flags;
|
||||
assert( flags!=0 ); /* Must define some type */
|
||||
if( pMem->flags & (MEM_Str|MEM_Blob) ){
|
||||
int x = pMem->flags & (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short);
|
||||
assert( x!=0 ); /* Strings must define a string subtype */
|
||||
assert( (x & (x-1))==0 ); /* Only one string subtype can be defined */
|
||||
assert( pMem->z!=0 ); /* Strings must have a value */
|
||||
/* Mem.z points to Mem.zShort iff the subtype is MEM_Short */
|
||||
assert( (pMem->flags & MEM_Short)==0 || pMem->z==pMem->zShort );
|
||||
assert( (pMem->flags & MEM_Short)!=0 || pMem->z!=pMem->zShort );
|
||||
/* No destructor unless there is MEM_Dyn */
|
||||
assert( pMem->xDel==0 || (pMem->flags & MEM_Dyn)!=0 );
|
||||
|
||||
if( (flags & MEM_Str) ){
|
||||
assert( pMem->enc==SQLITE_UTF8 ||
|
||||
pMem->enc==SQLITE_UTF16BE ||
|
||||
pMem->enc==SQLITE_UTF16LE
|
||||
);
|
||||
/* If the string is UTF-8 encoded and nul terminated, then pMem->n
|
||||
** must be the length of the string. (Later:) If the database file
|
||||
** has been corrupted, '\000' characters might have been inserted
|
||||
** into the middle of the string. In that case, the strlen() might
|
||||
** be less.
|
||||
*/
|
||||
if( pMem->enc==SQLITE_UTF8 && (flags & MEM_Term) ){
|
||||
assert( strlen(pMem->z)<=pMem->n );
|
||||
assert( pMem->z[pMem->n]==0 );
|
||||
}
|
||||
}
|
||||
}else{
|
||||
/* Cannot define a string subtype for non-string objects */
|
||||
assert( (pMem->flags & (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short))==0 );
|
||||
assert( pMem->xDel==0 );
|
||||
}
|
||||
/* MEM_Null excludes all other types */
|
||||
assert( (pMem->flags&(MEM_Str|MEM_Int|MEM_Real|MEM_Blob))==0
|
||||
|| (pMem->flags&MEM_Null)==0 );
|
||||
/* 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
|
||||
|
||||
/* This function is only available internally, it is not part of the
|
||||
** external API. It works in a similar way to sqlite3_value_text(),
|
||||
** except the data returned is in the encoding specified by the second
|
||||
** parameter, which must be one of SQLITE_UTF16BE, SQLITE_UTF16LE or
|
||||
** SQLITE_UTF8.
|
||||
*/
|
||||
const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
|
||||
if( !pVal ) return 0;
|
||||
assert( enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE || enc==SQLITE_UTF8);
|
||||
|
||||
if( pVal->flags&MEM_Null ){
|
||||
return 0;
|
||||
}
|
||||
if( pVal->flags&MEM_Str ){
|
||||
sqlite3VdbeChangeEncoding(pVal, enc);
|
||||
}else if( !(pVal->flags&MEM_Blob) ){
|
||||
sqlite3VdbeMemStringify(pVal, enc);
|
||||
}
|
||||
return (const void *)(pVal->z);
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a new sqlite3_value object.
|
||||
*/
|
||||
sqlite3_value* sqlite3ValueNew(void){
|
||||
Mem *p = sqliteMalloc(sizeof(*p));
|
||||
if( p ){
|
||||
p->flags = MEM_Null;
|
||||
p->type = SQLITE_NULL;
|
||||
}
|
||||
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
|
||||
*/
|
||||
void sqlite3ValueSetStr(
|
||||
sqlite3_value *v,
|
||||
int n,
|
||||
const void *z,
|
||||
u8 enc,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
if( v ) sqlite3VdbeMemSetStr((Mem *)v, z, n, enc, xDel);
|
||||
}
|
||||
|
||||
/*
|
||||
** Free an sqlite3_value object
|
||||
*/
|
||||
void sqlite3ValueFree(sqlite3_value *v){
|
||||
if( !v ) return;
|
||||
sqlite3ValueSetStr(v, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
|
||||
sqliteFree(v);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of bytes in the sqlite3_value object assuming
|
||||
** that it uses the encoding "enc"
|
||||
*/
|
||||
int sqlite3ValueBytes(sqlite3_value *pVal, u8 enc){
|
||||
Mem *p = (Mem*)pVal;
|
||||
if( (p->flags & MEM_Blob)!=0 || sqlite3ValueText(pVal, enc) ){
|
||||
return p->n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+1707
-851
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
|
||||
+29
-6
@@ -10,7 +10,7 @@
|
||||
#***********************************************************************
|
||||
# This file runs all tests.
|
||||
#
|
||||
# $Id: all.test,v 1.19 2003/02/16 22:21:33 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
|
||||
@@ -20,7 +20,7 @@ proc finish_test {} {memleak_check}
|
||||
if {[file exists ./sqlite_test_count]} {
|
||||
set COUNT [exec cat ./sqlite_test_count]
|
||||
} else {
|
||||
set COUNT 4
|
||||
set COUNT 3
|
||||
}
|
||||
|
||||
if {[llength $argv]>0} {
|
||||
@@ -49,15 +49,24 @@ set LeakList {}
|
||||
|
||||
set EXCLUDE {
|
||||
all.test
|
||||
crash.test
|
||||
autovacuum_crash.test
|
||||
quick.test
|
||||
malloc.test
|
||||
misuse.test
|
||||
memleak.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} {
|
||||
set btree_native_byte_order [expr {($Counter>>1)&0x1}]
|
||||
if {$Counter%2} {
|
||||
set ::SETUP_SQL {PRAGMA default_synchronous=off;}
|
||||
} else {
|
||||
@@ -80,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...
|
||||
@@ -98,10 +107,24 @@ if {$LeakList!=""} {
|
||||
puts " Ok"
|
||||
}
|
||||
|
||||
# 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"} {
|
||||
source $testdir/crash.test
|
||||
ifcapable !default_autovacuum {
|
||||
source $testdir/autovacuum_crash.test
|
||||
}
|
||||
}
|
||||
|
||||
# Run the malloc tests and the misuse test after memory leak detection.
|
||||
# Both tests leak memory.
|
||||
# Both tests leak memory. Currently, misuse.test also leaks a handful of
|
||||
# file descriptors. This is not considered a problem, but can cause tests
|
||||
# in malloc.test to fail. So set the open-file count to zero before running
|
||||
# malloc.test to get around this.
|
||||
#
|
||||
catch {source $testdir/misuse.test}
|
||||
set sqlite_open_file_count 0
|
||||
catch {source $testdir/malloc.test}
|
||||
|
||||
catch {db close}
|
||||
|
||||
+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
|
||||
+279
-115
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach.test,v 1.11 2003/07/18 01:25:35 drh Exp $
|
||||
# $Id: attach.test,v 1.40 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -23,6 +23,7 @@ for {set i 2} {$i<=15} {incr i} {
|
||||
file delete -force test$i.db-journal
|
||||
}
|
||||
|
||||
set btree_trace 0
|
||||
do_test attach-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b);
|
||||
@@ -32,7 +33,7 @@ do_test attach-1.1 {
|
||||
}
|
||||
} {1 2 3 4}
|
||||
do_test attach-1.2 {
|
||||
sqlite db2 test2.db
|
||||
sqlite3 db2 test2.db
|
||||
execsql {
|
||||
CREATE TABLE t2(x,y);
|
||||
INSERT INTO t2 VALUES(1,'x');
|
||||
@@ -71,17 +72,17 @@ do_test attach-1.8 {
|
||||
catchsql {
|
||||
ATTACH DATABASE 'test3.db' AS three;
|
||||
}
|
||||
} {1 {cannot attach empty database: three}}
|
||||
} {0 {}}
|
||||
do_test attach-1.9 {
|
||||
catchsql {
|
||||
SELECT * FROM three.sqlite_master;
|
||||
}
|
||||
} {1 {no such table: three.sqlite_master}}
|
||||
} {0 {}}
|
||||
do_test attach-1.10 {
|
||||
catchsql {
|
||||
DETACH DATABASE three;
|
||||
DETACH DATABASE [three];
|
||||
}
|
||||
} {1 {no such database: three}}
|
||||
} {0 {}}
|
||||
do_test attach-1.11 {
|
||||
execsql {
|
||||
ATTACH 'test.db' AS db2;
|
||||
@@ -101,9 +102,11 @@ proc db_list {db} {
|
||||
}
|
||||
return $list
|
||||
}
|
||||
ifcapable schema_pragmas {
|
||||
do_test attach-1.11b {
|
||||
db_list db
|
||||
} {0 main 1 temp 2 db2 3 db3 4 db4 5 db5 6 db6 7 db7 8 db8 9 db9}
|
||||
} {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;
|
||||
@@ -124,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;
|
||||
@@ -149,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 1 temp 2 db2 3 db3 4 db4 5 db11 6 db6 7 db7 8 db8 9 db9 10 db10}
|
||||
integrity_check attach-1.20.2
|
||||
} {0 main 2 db2 3 db3 4 db4 5 db6 6 db7 7 db8 8 db9 9 db10 10 db11}
|
||||
} ;# 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;
|
||||
@@ -164,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 {
|
||||
@@ -182,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;
|
||||
@@ -200,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);
|
||||
@@ -246,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);
|
||||
@@ -260,14 +300,22 @@ do_test attach-2.10 {
|
||||
SELECT type, name, tbl_name FROM sqlite_master;
|
||||
} db2
|
||||
} {table t2 t2 table tx tx trigger r1 t2 index i2 t2}
|
||||
do_test attach-2.11 {
|
||||
catchsql {
|
||||
SELECT * FROM t2 WHERE x>5;
|
||||
#do_test attach-2.11 {
|
||||
# catchsql {
|
||||
# SELECT * FROM t2 WHERE x>5;
|
||||
# }
|
||||
#} {1 {database schema has changed}}
|
||||
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}
|
||||
}
|
||||
} {1 {database schema has changed}}
|
||||
do_test attach-2.12 {
|
||||
db_list db
|
||||
} {0 main 1 temp 2 db2}
|
||||
} ;# ifcapable schema_pragmas
|
||||
do_test attach-2.13 {
|
||||
catchsql {
|
||||
SELECT * FROM t2 WHERE x>5;
|
||||
@@ -285,22 +333,41 @@ do_test attach-2.15 {
|
||||
} {table t2 t2 table tx tx trigger r1 t2 index i2 t2}
|
||||
do_test attach-2.16 {
|
||||
db close
|
||||
sqlite db test.db
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
ATTACH 'test2.db' AS db2;
|
||||
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
|
||||
db2 close
|
||||
sqlite db test.db
|
||||
sqlite db2 test2.db
|
||||
sqlite3 db test.db
|
||||
sqlite3 db2 test2.db
|
||||
execsql {
|
||||
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
|
||||
@@ -313,7 +380,8 @@ do_test attach-3.3 {
|
||||
}
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# Even though main has a transaction, test2.db should not be locked.
|
||||
# Even though 'db' has started a transaction, it should not yet have
|
||||
# a lock on test2.db so 'db2' should be readable.
|
||||
do_test attach-3.4 {
|
||||
execsql BEGIN
|
||||
catchsql {
|
||||
@@ -321,15 +389,18 @@ do_test attach-3.4 {
|
||||
} db2;
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# Reading from db2 should not lock test2.db
|
||||
# Reading from test2.db from db within a transaction should not
|
||||
# prevent test2.db from being read by db2.
|
||||
do_test attach-3.5 {
|
||||
execsql {SELECT * FROM t2}
|
||||
btree_breakpoint
|
||||
catchsql {
|
||||
SELECT * FROM t2;
|
||||
} db2;
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# Making a change to db2 causes test2.ddb to become locked.
|
||||
# Making a change to test2.db through db causes test2.db to get
|
||||
# a reserved lock. It should still be accessible through db2.
|
||||
do_test attach-3.6 {
|
||||
execsql {
|
||||
UPDATE t2 SET x=x+1 WHERE x=50;
|
||||
@@ -337,43 +408,67 @@ do_test attach-3.6 {
|
||||
catchsql {
|
||||
SELECT * FROM t2;
|
||||
} db2;
|
||||
} {1 {database is locked}}
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
do_test attach-3.7 {
|
||||
execsql ROLLBACK
|
||||
execsql {SELECT * FROM t2} db2
|
||||
} {21 x 22 y}
|
||||
|
||||
# Start transactions on both db and db2. Once again, just because
|
||||
# we make a change to test2.db using db2, only a RESERVED lock is
|
||||
# obtained, so test2.db should still be readable using db.
|
||||
#
|
||||
do_test attach-3.8 {
|
||||
execsql BEGIN
|
||||
execsql BEGIN db2
|
||||
execsql {UPDATE t2 SET x=0 WHERE 0} db2
|
||||
catchsql {SELECT * FROM t2}
|
||||
} {1 {database is locked}}
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# It is also still accessible from db2.
|
||||
do_test attach-3.9 {
|
||||
catchsql {SELECT * FROM t2} db2
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
do_test attach-3.10 {
|
||||
execsql {SELECT * FROM t1}
|
||||
} {1 2 3 4}
|
||||
|
||||
do_test attach-3.11 {
|
||||
catchsql {UPDATE t1 SET a=a+1}
|
||||
} {0 {}}
|
||||
do_test attach-3.12 {
|
||||
execsql {SELECT * FROM t1}
|
||||
} {2 2 4 4}
|
||||
|
||||
# db2 has a RESERVED lock on test2.db, so db cannot write to any tables
|
||||
# in test2.db.
|
||||
do_test attach-3.13 {
|
||||
catchsql {UPDATE t2 SET x=x+1 WHERE x=50}
|
||||
} {1 {database is locked}}
|
||||
|
||||
# Change for version 3. Transaction is no longer rolled back
|
||||
# for a locked database.
|
||||
execsql {ROLLBACK}
|
||||
|
||||
# db is able to reread its schema because db2 still only holds a
|
||||
# reserved lock.
|
||||
do_test attach-3.14 {
|
||||
# the "database is locked" error on the previous test should have
|
||||
# caused a rollback.
|
||||
catchsql {SELECT * FROM t1}
|
||||
} {0 {1 2 3 4}}
|
||||
do_test attach-3.15 {
|
||||
execsql COMMIT db2
|
||||
execsql {SELECT * FROM t1}
|
||||
} {1 2 3 4}
|
||||
|
||||
#set btree_trace 1
|
||||
|
||||
# Ticket #323
|
||||
do_test attach-4.1 {
|
||||
execsql {DETACH db2}
|
||||
db2 close
|
||||
sqlite db2 test2.db
|
||||
sqlite3 db2 test2.db
|
||||
execsql {
|
||||
CREATE TABLE t3(x,y);
|
||||
CREATE UNIQUE INDEX t3i1 ON t3(x);
|
||||
@@ -406,29 +501,57 @@ 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
|
||||
# the first query of the UNION ALL. If we wait to test the validity of
|
||||
# the schema for main until after the first query has run, that test will
|
||||
# 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;
|
||||
@@ -436,12 +559,26 @@ do_test attach-4.8 {
|
||||
SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4;
|
||||
}
|
||||
} {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;
|
||||
@@ -468,22 +605,24 @@ 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
|
||||
sqlite db test.db
|
||||
sqlite3 db test.db
|
||||
db2 close
|
||||
file delete -force test2.db
|
||||
sqlite db2 test2.db
|
||||
sqlite3 db2 test2.db
|
||||
catchsql {
|
||||
ATTACH DATABASE 'test.db' AS orig;
|
||||
CREATE TRIGGER r1 AFTER INSERT ON orig.t1 BEGIN;
|
||||
SELECT 'no-op';
|
||||
END;
|
||||
} db2
|
||||
} {1 {triggers may not be added to auxiliary database orig}}
|
||||
} {1 {trigger r1 cannot reference objects in database orig}}
|
||||
do_test attach-5.2 {
|
||||
catchsql {
|
||||
CREATE TABLE t5(x,y);
|
||||
@@ -500,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.
|
||||
@@ -558,14 +702,18 @@ do_test attach-6.1 {
|
||||
catchsql {
|
||||
ATTACH DATABASE 'no-such-file' AS nosuch;
|
||||
}
|
||||
} {1 {cannot attach empty database: nosuch}}
|
||||
file delete -force no-such-file
|
||||
} {0 {}}
|
||||
if {$tcl_platform(platform)=="unix"} {
|
||||
do_test attach-6.2 {
|
||||
sqlite dbx cannot-read
|
||||
sqlite3 dbx cannot-read
|
||||
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;
|
||||
}
|
||||
@@ -573,10 +721,26 @@ 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}
|
||||
}
|
||||
db close
|
||||
file delete -force test2.db
|
||||
file delete -force no-such-file
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
+335
-3
@@ -12,22 +12,26 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach2.test,v 1.2 2003/07/18 01:25:35 drh Exp $
|
||||
# $Id: attach2.test,v 1.32 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
# Ticket #354
|
||||
#
|
||||
# Databases test.db and test2.db contain identical schemas. Make
|
||||
# sure we can attach test2.db from test.db.
|
||||
#
|
||||
do_test attach2-1.1 {
|
||||
db eval {
|
||||
CREATE TABLE t1(a,b);
|
||||
CREATE INDEX x1 ON t1(a);
|
||||
}
|
||||
file delete -force test2.db
|
||||
sqlite db2 test2.db
|
||||
file delete -force test2.db-journal
|
||||
sqlite3 db2 test2.db
|
||||
db2 eval {
|
||||
CREATE TABLE t1(a,b);
|
||||
CREATE INDEX x1 ON t1(a);
|
||||
@@ -37,11 +41,339 @@ do_test attach2-1.1 {
|
||||
}
|
||||
} {0 {}}
|
||||
|
||||
# Ticket #514
|
||||
#
|
||||
proc db_list {db} {
|
||||
set list {}
|
||||
foreach {idx name file} [execsql {PRAGMA database_list} $db] {
|
||||
lappend list $idx $name
|
||||
}
|
||||
return $list
|
||||
}
|
||||
db eval {DETACH t2}
|
||||
do_test attach2-2.1 {
|
||||
# lock test2.db then try to attach it. This is no longer an error because
|
||||
# db2 just RESERVES the database. It does not obtain a write-lock until
|
||||
# we COMMIT.
|
||||
db2 eval {BEGIN}
|
||||
db2 eval {UPDATE t1 SET a = 0 WHERE 0}
|
||||
catchsql {
|
||||
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 {
|
||||
# Make sure we can read test2.db from db
|
||||
catchsql {
|
||||
SELECT name FROM t2.sqlite_master;
|
||||
}
|
||||
} {0 {t1 x1}}
|
||||
do_test attach2-2.6 {
|
||||
# lock test2.db and try to read from it. This should still work because
|
||||
# the lock is only a RESERVED lock which does not prevent reading.
|
||||
#
|
||||
db2 eval BEGIN
|
||||
db2 eval {UPDATE t1 SET a = 0 WHERE 0}
|
||||
catchsql {
|
||||
SELECT name FROM t2.sqlite_master;
|
||||
}
|
||||
} {0 {t1 x1}}
|
||||
do_test attach2-2.7 {
|
||||
# but we can still read from test1.db even though test2.db is locked.
|
||||
catchsql {
|
||||
SELECT name FROM main.sqlite_master;
|
||||
}
|
||||
} {0 {t1 x1}}
|
||||
do_test attach2-2.8 {
|
||||
# start a transaction on test.db even though test2.db is locked.
|
||||
catchsql {
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES(8,9);
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach2-2.9 {
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {8 9}
|
||||
do_test attach2-2.10 {
|
||||
# now try to write to test2.db. the write should fail
|
||||
catchsql {
|
||||
INSERT INTO t2.t1 VALUES(1,2);
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
do_test attach2-2.11 {
|
||||
# when the write failed in the previous test, the transaction should
|
||||
# have rolled back.
|
||||
#
|
||||
# Update for version 3: A transaction is no longer rolled back if a
|
||||
# database is found to be busy.
|
||||
execsql {rollback}
|
||||
db2 eval ROLLBACK
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {}
|
||||
do_test attach2-2.12 {
|
||||
catchsql {
|
||||
COMMIT
|
||||
}
|
||||
} {1 {cannot commit - no transaction is active}}
|
||||
|
||||
# Ticket #574: Make sure it works using the non-callback API
|
||||
#
|
||||
do_test attach2-3.1 {
|
||||
db close
|
||||
set DB [sqlite3 db test.db]
|
||||
set rc [catch {sqlite3_prepare $DB "ATTACH 'test2.db' AS t2" -1 TAIL} VM]
|
||||
if {$rc} {lappend rc $VM}
|
||||
sqlite3_finalize $VM
|
||||
set rc
|
||||
} {0}
|
||||
do_test attach2-3.2 {
|
||||
set rc [catch {sqlite3_prepare $DB "DETACH t2" -1 TAIL} VM]
|
||||
if {$rc} {lappend rc $VM}
|
||||
sqlite3_finalize $VM
|
||||
set rc
|
||||
} {0}
|
||||
|
||||
db close
|
||||
for {set i 2} {$i<=15} {incr i} {
|
||||
catch {db$i close}
|
||||
}
|
||||
|
||||
# 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
|
||||
}
|
||||
set sqlite_os_trace 0
|
||||
|
||||
# Tests attach2-4.* test that read-locks work correctly with attached
|
||||
# databases.
|
||||
do_test attach2-4.1 {
|
||||
sqlite3 db test.db
|
||||
sqlite3 db2 test.db
|
||||
execsql {ATTACH 'test2.db' as file2}
|
||||
execsql {ATTACH 'test2.db' as file2} db2
|
||||
} {}
|
||||
|
||||
lock_status 4.1.1 db {main unlocked temp closed file2 unlocked}
|
||||
lock_status 4.1.2 db2 {main unlocked temp closed file2 unlocked}
|
||||
|
||||
do_test attach2-4.2 {
|
||||
# Handle 'db' read-locks test.db
|
||||
execsql {BEGIN}
|
||||
execsql {SELECT * FROM t1}
|
||||
# Lock status:
|
||||
# db - shared(main)
|
||||
# db2 -
|
||||
} {}
|
||||
|
||||
lock_status 4.2.1 db {main shared temp closed file2 unlocked}
|
||||
lock_status 4.2.2 db2 {main unlocked temp closed file2 unlocked}
|
||||
|
||||
do_test attach2-4.3 {
|
||||
# The read lock held by db does not prevent db2 from reading test.db
|
||||
execsql {SELECT * FROM t1} db2
|
||||
} {}
|
||||
|
||||
lock_status 4.3.1 db {main shared temp closed file2 unlocked}
|
||||
lock_status 4.3.2 db2 {main unlocked temp closed file2 unlocked}
|
||||
|
||||
do_test attach2-4.4 {
|
||||
# db is holding a read lock on test.db, so we should not be able
|
||||
# to commit a write to test.db from db2
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(1, 2)
|
||||
} db2
|
||||
} {1 {database is locked}}
|
||||
|
||||
lock_status 4.4.1 db {main shared temp closed file2 unlocked}
|
||||
lock_status 4.4.2 db2 {main unlocked temp closed file2 unlocked}
|
||||
|
||||
do_test attach2-4.5 {
|
||||
# Handle 'db2' reserves file2.
|
||||
execsql {BEGIN} db2
|
||||
execsql {INSERT INTO file2.t1 VALUES(1, 2)} db2
|
||||
# Lock status:
|
||||
# db - shared(main)
|
||||
# db2 - reserved(file2)
|
||||
} {}
|
||||
|
||||
lock_status 4.5.1 db {main shared temp closed file2 unlocked}
|
||||
lock_status 4.5.2 db2 {main unlocked temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.6.1 {
|
||||
# Reads are allowed against a reserved database.
|
||||
catchsql {
|
||||
SELECT * FROM file2.t1;
|
||||
}
|
||||
# Lock status:
|
||||
# db - shared(main), shared(file2)
|
||||
# db2 - reserved(file2)
|
||||
} {0 {}}
|
||||
|
||||
lock_status 4.6.1.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.6.1.2 db2 {main unlocked temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.6.2 {
|
||||
# Writes against a reserved database are not allowed.
|
||||
catchsql {
|
||||
UPDATE file2.t1 SET a=0;
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
|
||||
lock_status 4.6.2.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.6.2.2 db2 {main unlocked temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.7 {
|
||||
# Ensure handle 'db' retains the lock on the main file after
|
||||
# failing to obtain a write-lock on file2.
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(1, 2)
|
||||
} db2
|
||||
} {0 {}}
|
||||
|
||||
lock_status 4.7.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.7.2 db2 {main reserved temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.8 {
|
||||
# We should still be able to read test.db from db2
|
||||
execsql {SELECT * FROM t1} db2
|
||||
} {1 2}
|
||||
|
||||
lock_status 4.8.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.8.2 db2 {main reserved temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.9 {
|
||||
# Try to upgrade the handle 'db' lock.
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(1, 2)
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
|
||||
lock_status 4.9.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.9.2 db2 {main reserved temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.10 {
|
||||
# We cannot commit db2 while db is holding a read-lock
|
||||
catchsql {COMMIT} db2
|
||||
} {1 {database is locked}}
|
||||
|
||||
lock_status 4.10.1 db {main shared temp closed file2 shared}
|
||||
lock_status 4.10.2 db2 {main pending temp closed file2 reserved}
|
||||
|
||||
set sqlite_os_trace 0
|
||||
do_test attach2-4.11 {
|
||||
# db is able to commit.
|
||||
catchsql {COMMIT}
|
||||
} {0 {}}
|
||||
|
||||
lock_status 4.11.1 db {main unlocked temp closed file2 unlocked}
|
||||
lock_status 4.11.2 db2 {main pending temp closed file2 reserved}
|
||||
|
||||
do_test attach2-4.12 {
|
||||
# Now we can commit db2
|
||||
catchsql {COMMIT} db2
|
||||
} {0 {}}
|
||||
|
||||
lock_status 4.12.1 db {main unlocked temp closed file2 unlocked}
|
||||
lock_status 4.12.2 db2 {main unlocked temp closed file2 unlocked}
|
||||
|
||||
do_test attach2-4.13 {
|
||||
execsql {SELECT * FROM file2.t1}
|
||||
} {1 2}
|
||||
do_test attach2-4.14 {
|
||||
execsql {INSERT INTO t1 VALUES(1, 2)}
|
||||
} {}
|
||||
do_test attach2-4.15 {
|
||||
execsql {SELECT * FROM t1} db2
|
||||
} {1 2 1 2}
|
||||
|
||||
db close
|
||||
db2 close
|
||||
file delete -force test2.db
|
||||
|
||||
# These tests - attach2-5.* - check that the master journal file is deleted
|
||||
# correctly when a multi-file transaction is committed or rolled back.
|
||||
#
|
||||
# Update: It's not actually created if a rollback occurs, so that test
|
||||
# doesn't really prove too much.
|
||||
foreach f [glob test.db*] {file delete -force $f}
|
||||
do_test attach2-5.1 {
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
ATTACH 'test.db2' AS aux;
|
||||
}
|
||||
} {}
|
||||
do_test attach2-5.2 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE tbl(a, b, c);
|
||||
CREATE TABLE aux.tbl(a, b, c);
|
||||
COMMIT;
|
||||
}
|
||||
} {}
|
||||
do_test attach2-5.3 {
|
||||
lsort [glob test.db*]
|
||||
} {test.db test.db2}
|
||||
do_test attach2-5.4 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
DROP TABLE aux.tbl;
|
||||
DROP TABLE tbl;
|
||||
ROLLBACK;
|
||||
}
|
||||
} {}
|
||||
do_test attach2-5.5 {
|
||||
lsort [glob test.db*]
|
||||
} {test.db test.db2}
|
||||
|
||||
# Check that a database cannot be ATTACHed or DETACHed during a transaction.
|
||||
do_test attach2-6.1 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
}
|
||||
} {}
|
||||
do_test attach2-6.2 {
|
||||
catchsql {
|
||||
ATTACH 'test3.db' as aux2;
|
||||
}
|
||||
} {1 {cannot ATTACH database within transaction}}
|
||||
|
||||
do_test attach2-6.3 {
|
||||
catchsql {
|
||||
DETACH aux;
|
||||
}
|
||||
} {1 {cannot DETACH database within transaction}}
|
||||
do_test attach2-6.4 {
|
||||
execsql {
|
||||
COMMIT;
|
||||
DETACH aux;
|
||||
}
|
||||
} {}
|
||||
|
||||
db close
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
# 2003 July 1
|
||||
#
|
||||
# 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 and DETACH commands
|
||||
# and schema changes to attached databases.
|
||||
#
|
||||
# $Id: attach3.test,v 1.15 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Create tables t1 and t2 in the main database
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE TABLE t2(c, d);
|
||||
}
|
||||
|
||||
# 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);
|
||||
CREATE TABLE t2(c, d);
|
||||
} db2
|
||||
db2 close
|
||||
|
||||
# Create a table in the auxilary database.
|
||||
do_test attach3-1.1 {
|
||||
execsql {
|
||||
ATTACH 'test2.db' AS aux;
|
||||
}
|
||||
} {}
|
||||
do_test attach3-1.2 {
|
||||
execsql {
|
||||
CREATE TABLE aux.t3(e, f);
|
||||
}
|
||||
} {}
|
||||
do_test attach3-1.3 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_master WHERE name = 't3';
|
||||
}
|
||||
} {}
|
||||
do_test attach3-1.4 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 't3';
|
||||
}
|
||||
} "table t3 t3 [expr $AUTOVACUUM?5:4] {CREATE TABLE t3(e, f)}"
|
||||
do_test attach3-1.5 {
|
||||
execsql {
|
||||
INSERT INTO t3 VALUES(1, 2);
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1 2}
|
||||
|
||||
# Create an index on the auxilary database table.
|
||||
do_test attach3-2.1 {
|
||||
execsql {
|
||||
CREATE INDEX aux.i1 on t3(e);
|
||||
}
|
||||
} {}
|
||||
do_test attach3-2.2 {
|
||||
execsql {
|
||||
SELECT * FROM sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} {}
|
||||
do_test attach3-2.3 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} "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 {
|
||||
execsql {
|
||||
DROP INDEX aux.i1;
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} {}
|
||||
do_test attach3-3.2 {
|
||||
execsql {
|
||||
CREATE INDEX aux.i1 on t3(e);
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} "index i1 t3 [expr $AUTOVACUUM?6:5] {CREATE INDEX i1 on t3(e)}"
|
||||
do_test attach3-3.3 {
|
||||
execsql {
|
||||
DROP INDEX i1;
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'i1';
|
||||
}
|
||||
} {}
|
||||
|
||||
# Drop tables t1 and t2 in the auxilary database.
|
||||
do_test attach3-4.1 {
|
||||
execsql {
|
||||
DROP TABLE aux.t1;
|
||||
SELECT name FROM aux.sqlite_master;
|
||||
}
|
||||
} {t2 t3}
|
||||
do_test attach3-4.2 {
|
||||
# This will drop main.t2
|
||||
execsql {
|
||||
DROP TABLE t2;
|
||||
SELECT name FROM aux.sqlite_master;
|
||||
}
|
||||
} {t2 t3}
|
||||
do_test attach3-4.3 {
|
||||
execsql {
|
||||
DROP TABLE t2;
|
||||
SELECT name FROM aux.sqlite_master;
|
||||
}
|
||||
} {t3}
|
||||
|
||||
# Create a view in the auxilary database.
|
||||
ifcapable view {
|
||||
do_test attach3-5.1 {
|
||||
execsql {
|
||||
CREATE VIEW aux.v1 AS SELECT * FROM t3;
|
||||
}
|
||||
} {}
|
||||
do_test attach3-5.2 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'v1';
|
||||
}
|
||||
} {view v1 v1 0 {CREATE VIEW v1 AS SELECT * FROM t3}}
|
||||
do_test attach3-5.3 {
|
||||
execsql {
|
||||
INSERT INTO aux.t3 VALUES('hello', 'world');
|
||||
SELECT * FROM v1;
|
||||
}
|
||||
} {1 2 hello world}
|
||||
|
||||
# Drop the view
|
||||
do_test attach3-6.1 {
|
||||
execsql {
|
||||
DROP VIEW aux.v1;
|
||||
}
|
||||
} {}
|
||||
do_test attach3-6.2 {
|
||||
execsql {
|
||||
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 {
|
||||
CREATE TRIGGER aux.tr1 AFTER INSERT ON t3 BEGIN
|
||||
INSERT INTO t3 VALUES(new.e*2, new.f*2);
|
||||
END;
|
||||
}
|
||||
} {}
|
||||
do_test attach3-7.2 {
|
||||
execsql {
|
||||
DELETE FROM t3;
|
||||
INSERT INTO t3 VALUES(10, 20);
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {10 20 20 40}
|
||||
do_test attach3-5.3 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'tr1';
|
||||
}
|
||||
} {trigger tr1 t3 0 {CREATE TRIGGER tr1 AFTER INSERT ON t3 BEGIN
|
||||
INSERT INTO t3 VALUES(new.e*2, new.f*2);
|
||||
END}}
|
||||
|
||||
# Drop the trigger
|
||||
do_test attach3-8.1 {
|
||||
execsql {
|
||||
DROP TRIGGER aux.tr1;
|
||||
}
|
||||
} {}
|
||||
do_test attach3-8.2 {
|
||||
execsql {
|
||||
SELECT * FROM aux.sqlite_master WHERE name = 'tr1';
|
||||
}
|
||||
} {}
|
||||
|
||||
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 {
|
||||
catchsql {
|
||||
INSERT INTO aux.sqlite_master VALUES(1, 2, 3, 4, 5);
|
||||
}
|
||||
} {1 {table sqlite_master may not be modified}}
|
||||
|
||||
# Failure to attach leaves us in a workable state.
|
||||
# Ticket #811
|
||||
#
|
||||
do_test attach3-11.0 {
|
||||
catchsql {
|
||||
ATTACH DATABASE '/nodir/nofile.x' AS notadb;
|
||||
}
|
||||
} {1 {unable to open database: /nodir/nofile.x}}
|
||||
do_test attach3-11.1 {
|
||||
catchsql {
|
||||
ATTACH DATABASE ':memory:' AS notadb;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach3-11.2 {
|
||||
catchsql {
|
||||
DETACH DATABASE notadb;
|
||||
}
|
||||
} {0 {}}
|
||||
|
||||
finish_test
|
||||
@@ -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
|
||||
+783
-460
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user