Compare commits
1040 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b9a61f715 | |||
| fb7b4f204b | |||
| b3dc0431c7 | |||
| 66a01c4554 | |||
| 6f65beb084 | |||
| 7a5b729aa7 | |||
| ec88191019 | |||
| e1b6c821d6 | |||
| b2292faf9c | |||
| 5cfe9a78f9 | |||
| 19aca9eddb | |||
| 85a5dfef26 | |||
| 82ab315f73 | |||
| 3ec28d5d81 | |||
| e1175bd650 | |||
| 0c3ab2d6ac | |||
| 73003316a2 | |||
| bde845ce70 | |||
| 4cf73f61fb | |||
| 5d7f6e84f1 | |||
| 8c8ec4fd3e | |||
| 2d97242175 | |||
| 0e93442494 | |||
| 9c46d69216 | |||
| a8734da09b | |||
| 90ddc11b77 | |||
| 0aaa1c038e | |||
| 6951f39c72 | |||
| 805e7d5b42 | |||
| 06d55ce8f3 | |||
| 24b8cb36bc | |||
| afcfc0eecb | |||
| ea024eee62 | |||
| ca69323478 | |||
| 52e50d6aaa | |||
| 0f156745bd | |||
| f4ed02a34f | |||
| 463ff298d6 | |||
| 5d5398b089 | |||
| f3a5a57ddb | |||
| 1832890357 | |||
| 97117601d2 | |||
| f9ec81c84d | |||
| 45041e263a | |||
| 3e5c826219 | |||
| 4e0e4d7a9e | |||
| 064cf76bb1 | |||
| a38518d673 | |||
| 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 | |||
| 96e9f565ad | |||
| 27ff9f87b8 | |||
| 4925ca00a3 | |||
| 0802fd836d | |||
| b3549d43e2 | |||
| 0a5294bc06 | |||
| 000ca2b208 | |||
| 7014aff37d | |||
| b48484a6d7 | |||
| 63a1e49859 | |||
| 8548a059ff | |||
| fdbf928b08 | |||
| 8b582012de | |||
| 348bb5d6c8 | |||
| 4df92bbd44 | |||
| 191c0323c0 | |||
| 319e4e7484 | |||
| 4f88c849f3 | |||
| dab3518880 | |||
| 5b8424b9e4 | |||
| 3775084a75 | |||
| 562528c480 | |||
| f911221a1e | |||
| 3b5543c46d | |||
| 28f79f7bda | |||
| 225656c50a | |||
| 61b487d02a | |||
| 9faae94118 | |||
| 82a4851a4b | |||
| 7c972dec5c | |||
| 9a32464b54 | |||
| 5045789694 | |||
| c023e03ea5 | |||
| 1dcafe1ad8 | |||
| e4c616931d | |||
| 0d4f801c28 | |||
| ec1bd0bd72 | |||
| 8460ea0652 | |||
| 03ab7336cd | |||
| 901afd4341 | |||
| 263659be4d | |||
| 6ab95d3e85 | |||
| 3ca65151d5 | |||
| 78100cc928 | |||
| 73d3667ef2 | |||
| a866b82244 | |||
| 02b2011cb3 | |||
| 4739470341 | |||
| 5d9d757626 | |||
| e5e3760e1c | |||
| 9b1b01bb76 | |||
| 8e18bac793 | |||
| b2446f9bbf | |||
| 41a8230fef | |||
| 87adaa9a99 | |||
| 771d8c3bae | |||
| 37ed48ed2f | |||
| 4305d10360 | |||
| a76c82eb0d | |||
| 98e3e60012 | |||
| dc2d94de56 | |||
| 48647b390b | |||
| 8dd5a314eb | |||
| ee513831a7 | |||
| 999af643a0 | |||
| 4d87325d61 | |||
| 7b58daeafe | |||
| e5f50722b4 | |||
| 9347b20050 | |||
| 9cb733c39d | |||
| a3b6cfa6cf | |||
| a88dc3f629 | |||
| ef0cae500d | |||
| d4f5ee2805 | |||
| da808d56dc | |||
| 073e5a7751 | |||
| 23af2f6eb2 | |||
| 3e4c852889 | |||
| d0cc954fa1 | |||
| 1dd59e0f94 | |||
| 3c8bf55a04 | |||
| c5aceb33cb | |||
| ef2d1b100c | |||
| 631e276202 | |||
| dc339ee29c | |||
| d6ae597393 | |||
| 27fb6f6a99 | |||
| 88c0df2a84 | |||
| 82f725df08 | |||
| 937dd84de8 | |||
| d60ccc6a75 | |||
| 18706c08cb | |||
| 6cb2c52d96 | |||
| 8ce10ba65e | |||
| 44ce7e20f8 | |||
| 7a73eb48f8 | |||
| d93d8a812e | |||
| 3fc673e622 | |||
| f817b6be7f | |||
| 4d9fc3231b | |||
| ed717fe3b2 | |||
| 3ca691106b | |||
| 1420010fa4 | |||
| 831961217d | |||
| c45d95f9de | |||
| e2227f0092 | |||
| 892f671cf3 | |||
| 2e0d738b60 | |||
| 7571c96c4c | |||
| 05e45910ca | |||
| 6f8fd3c171 | |||
| 94ce4c1e3b | |||
| 048aa234ef | |||
| 5fa7eb0dd9 | |||
| 81e293b4b2 | |||
| 70dc85a4c2 | |||
| d36a483704 | |||
| b5333fa6e4 | |||
| 8649d6a1a8 | |||
| 7d02cb73ca | |||
| b8ec20925d | |||
| 5e8e1981dc | |||
| ca3bdaca19 | |||
| b6ec9fed20 | |||
| bc2bca0843 | |||
| 5383ae5c12 | |||
| 4312db55d9 | |||
| 1aa4965ae3 | |||
| 2394e376d6 | |||
| ade106c14a | |||
| 5959abd5d0 | |||
| 02be20d4f5 | |||
| 5a56422a29 | |||
| a0217ba720 | |||
| f26e09c87f | |||
| 8372b8d134 | |||
| 9ac717d7f6 | |||
| 124e74e685 | |||
| 6e1d288a9f | |||
| 6b8611126b | |||
| 79a519c047 | |||
| 24f1eb74c8 | |||
| 369986a75f | |||
| 8bf8dc9208 | |||
| 0594f5b97e | |||
| 8971527208 | |||
| 8625f9fe38 | |||
| 299fa266df | |||
| 9335247003 | |||
| a996e477d0 | |||
| 931634915d | |||
| 39581966a0 | |||
| 3b2129cf77 | |||
| fe4184f8d1 | |||
| e62720d1f1 | |||
| 5364f60302 | |||
| 5ca89c3d28 | |||
| 672a1edfc8 | |||
| 5fe2d8c913 | |||
| a3643a2697 | |||
| f60482044d | |||
| 9098056e6f | |||
| df2245df05 | |||
| f94e371bbf | |||
| 3aacc84e45 | |||
| b2ca13ed4d | |||
| 8af4d3ace6 | |||
| 66b4ebafb2 | |||
| e1e38c4d7d | |||
| 7ad4334add | |||
| 5640433e48 | |||
| 6a65bb3c06 | |||
| b24fe71970 | |||
| e96fa95e8a | |||
| 2bfc9dbdcf | |||
| e9ffc168d8 | |||
| c31c2eb82c | |||
| 6a3ea0e6ef | |||
| 56e452cf3a | |||
| 44c2eb128d | |||
| a9b1716296 | |||
| 86e5cc058d | |||
| 63eb5f294c | |||
| 7d8085a8e4 | |||
| 70c7a4b1da | |||
| 4328c8b7c7 | |||
| aba46b19f5 | |||
| 524a5bf5f6 | |||
| 85e2096fb6 | |||
| 2e6d11bc07 | |||
| 9c05dc6298 | |||
| f7c5753174 | |||
| fd9903de51 | |||
| 45a304ee8c | |||
| 5cf590c128 | |||
| b5a20d3ceb | |||
| e22a334b78 | |||
| 3837237959 | |||
| f0f258b11b | |||
| 881b890af4 | |||
| b2fe7d8cb7 | |||
| 2dc96f9eb8 | |||
| f00993a30a | |||
| ea1ba17cda | |||
| 7bdc0c1def | |||
| 37ea94b8c9 | |||
| 9d10f1d0f6 | |||
| cab20050bb | |||
| a5f668327b | |||
| a69d91681d | |||
| d4d595f94c | |||
| 8396566204 | |||
| 95b5084409 | |||
| 027850b676 | |||
| bb07e9a34f | |||
| 144f9eadf6 | |||
| 70ce3f0c58 | |||
| 048bd5937b | |||
| 49449834fc | |||
| f9a2e7bb8d | |||
| 13bff81537 | |||
| b0208ccaa3 | |||
| c11d4f9360 | |||
| e1051c653e | |||
| 73509eee84 | |||
| a73af533de | |||
| 2d4583473b | |||
| f539f6a7e9 | |||
| 0d1a643aea | |||
| 048c530c01 | |||
| b95a8864c9 | |||
| 738a68b250 | |||
| 665de47ac3 | |||
| da93d238c2 | |||
| 1c2d84148a | |||
| 180487389b | |||
| 3aa31a16e6 | |||
| 9077ba8ee5 | |||
| 1dd8c40e8f | |||
| 0be9df076a | |||
| 812d7a21dd | |||
| 0951d703f2 | |||
| 1694cab424 | |||
| d24cc427b7 | |||
| 84e6335c0c | |||
| 62507b650a | |||
| c7e9383a9e | |||
| 113088ec68 | |||
| 001bbcbb8f | |||
| 9468c7f489 | |||
| 2299706c2a | |||
| dde85d9e00 | |||
| 627a71efa7 | |||
| e0194f2bbd | |||
| 50cceb36b6 | |||
| e6da3c1816 | |||
| 30710453ca | |||
| be992ef9c9 | |||
| ad636221bb | |||
| 94e9203247 | |||
| 99ee360003 | |||
| 4303feedd3 | |||
| 32c4a833e0 | |||
| 5527f8ff4a | |||
| 4a0681ef1b | |||
| 8ba1b31379 | |||
| 973b6e333d | |||
| d8d66e8ca0 | |||
| 968af52acf | |||
| 324ccefeb5 | |||
| bb999ef6fa | |||
| 17e9e29d1e | |||
| dcd997ea2e | |||
| 88eee38afd | |||
| 3a84069da3 | |||
| 483750ba8a | |||
| 326dce7451 | |||
| b86ccfb26e | |||
| 70c15b48ae | |||
| 79740a572e | |||
| a218b6a22a | |||
| a3da6fafd7 | |||
| 2ac83073e0 | |||
| ced87a65a8 | |||
| d62d3d0d24 | |||
| 2554f8b0c0 | |||
| 4764f161ab | |||
| 341eae8d35 | |||
| e78e8284ad | |||
| 79104c9d2a | |||
| fcb78a4900 | |||
| be4f31c226 | |||
| 799550beb0 | |||
| 18de4824f6 | |||
| db48ee02c4 | |||
| 2c3831cb23 | |||
| bf0c78af2f | |||
| 77ad4e4133 | |||
| 7160220495 | |||
| e5f9c6442f | |||
| 1962bda764 | |||
| e6d01c3a04 | |||
| ed6c8671b3 | |||
| 49f0936ec7 | |||
| f27134cdc4 | |||
| fa9e0df21b | |||
| fd15981daa | |||
| 5a38705ecb | |||
| 836faa4843 | |||
| 820f3812d8 | |||
| 9bd47a97c0 | |||
| 2b8ef743af | |||
| 371ac44d1c | |||
| caec2f12a9 | |||
| 32eb7b47ca | |||
| 3e87c7abeb | |||
| 8178a75a11 | |||
| c3b7057705 | |||
| bb49aba82a | |||
| 428ae8cb41 | |||
| 2c79995565 | |||
| 8c1238aebd | |||
| 7b39686749 | |||
| c64e0ba45c | |||
| 919792ecb9 | |||
| 80eb79055e | |||
| 5d1f0d4c89 | |||
| 3450e1d3c2 | |||
| f1337bb5ff | |||
| f33cb428e5 | |||
| e7e8bc7739 | |||
| 3e7a609667 | |||
| 1a844c380b | |||
| dd4852c3d1 | |||
| c045ec51be | |||
| 2dcc9aa2a8 | |||
| c66c5a266b | |||
| 174b619591 | |||
| da47d7748f | |||
| d0d006e29c | |||
| 86bc1c8273 | |||
| 58f391b36f | |||
| 7cdbd32c8e | |||
| 7d686b2d57 | |||
| 4d9ef4c4ef | |||
| 32c05e993f | |||
| 03eb96a7b2 | |||
| 8766c34348 | |||
| 829e802992 | |||
| 20e9ab16d8 | |||
| f87e9de4c4 | |||
| 28be87c7c4 | |||
| 647cb0e159 | |||
| 7bc09d3111 | |||
| 194a7b6469 | |||
| 1f3e905cd0 | |||
| bd1edfa321 | |||
| 38dd0b4ff0 | |||
| 1f16230b5c | |||
| 6977fea801 | |||
| e958bb4aef | |||
| edbbbdf8f7 | |||
| 3c2007a546 | |||
| 275ed72c9b | |||
| 315555ca50 | |||
| 2678058853 | |||
| 32fbe342db | |||
| 906bf2a316 | |||
| 16aaf451b7 | |||
| 710dcfbde5 | |||
| f1f0fa0769 | |||
| c8f8b632c3 | |||
| 294fb92b50 | |||
| c4ca897b9a | |||
| d042ddb31b | |||
| a226d05408 | |||
| df68f6b768 | |||
| 3e56c04c4e | |||
| 995d71b715 | |||
| cabb081971 | |||
| 41a3bd0a01 | |||
| 6eba16f3d7 | |||
| ac82fcf5f0 | |||
| 85a1c4a609 | |||
| 8f619ccd3c | |||
| 8c90ebb0e2 | |||
| 96ddd6db58 | |||
| 4e371ee41c | |||
| b798fa6481 | |||
| 96f4531077 | |||
| 0e1cfb8574 | |||
| f74b8d9b89 | |||
| c2eef3b32b | |||
| b680a344e5 | |||
| 56cdb3b237 | |||
| df01cdf9b0 | |||
| b7dadd4d85 | |||
| 1e0ccab9f0 | |||
| 142e30df99 | |||
| 66105a8ea0 | |||
| da30d3696b | |||
| d2df27e41d | |||
| 305f99a0fb | |||
| 8c74a8ca5b | |||
| d94a669894 | |||
| 4b59ab5e64 | |||
| 79983d03e8 | |||
| bd842babb5 | |||
| f04d5081a7 | |||
| 6b8b8749d4 | |||
| d8acdb3c36 | |||
| cb48588297 | |||
| c277413089 | |||
| 310ae7be1e | |||
| 3d037a91a5 | |||
| b27b83a941 | |||
| d1efac52d5 | |||
| c330af1dca | |||
| 0c44e2edf3 | |||
| fbe4375cae | |||
| a9e99aee95 | |||
| 76800328b2 | |||
| 72ca3794ab | |||
| 7f09b3e36b | |||
| f8b593e964 | |||
| 74587e5567 | |||
| 94f3331a0b | |||
| 0d316a40cc | |||
| 6e397e447e | |||
| 68d2e5918a | |||
| e0e5ef1471 | |||
| f1351b6759 | |||
| 4eb9c6b9fd | |||
| 4dec5b40ec | |||
| f573c99ba7 | |||
| 92ed08a9d7 | |||
| c51d204464 | |||
| 62160e798c | |||
| 368c7f6df1 | |||
| 77fc55904e | |||
| 096c497eb3 | |||
| 26b3e1bc06 | |||
| 426cc56a6b | |||
| c231172f3f | |||
| b782325617 | |||
| ac729e224e | |||
| 199e3cf1b6 | |||
| bd44700073 | |||
| 3c2c354e0e | |||
| 8e5ba84643 | |||
| 491791a827 | |||
| 53e3fc70bf | |||
| 0c36cbe0c2 | |||
| 704027f16d | |||
| ad16844f35 | |||
| 7f953e2052 | |||
| 70562cd342 | |||
| 289f6c2336 | |||
| 674d712126 | |||
| 25197f4835 | |||
| 485b39b401 | |||
| 5080aaa7ab | |||
| fa173a764a | |||
| 6276c1cbf0 | |||
| bea00b9a2b | |||
| 6b30867ff6 | |||
| 6f08d709b1 | |||
| 5e5377fb80 | |||
| 193a6b4142 | |||
| af1c9661a4 | |||
| 0de8c11292 | |||
| 8e298f92f6 | |||
| 38640e15af | |||
| 2f2c01e51d | |||
| 1f66c57a9c | |||
| ea1c936a1e | |||
| a4db7ee12d | |||
| 5ad1a6c8c4 | |||
| 6cbe1f1bc4 | |||
| a9f9d1c08b | |||
| 3b167c7583 | |||
| 83dcb1ad37 | |||
| ac83f718fc | |||
| 06b2718a5f | |||
| b13632063d | |||
| 411995dc0d | |||
| e3c163e4e0 | |||
| ee6bfdf99c | |||
| 8124a30f82 | |||
| 2150432e7c | |||
| 90c0bb0b07 | |||
| e0bc4048a0 | |||
| 1cc093c2b5 | |||
| bf5cd97ed7 | |||
| f46f905a1e | |||
| d11d382c99 | |||
| 7aa128dbc5 | |||
| bb3a6dbd2e | |||
| ef1360635c | |||
| c9b84a1fb1 | |||
| c926afbc2d | |||
| 27a32783ab | |||
| 9bc542e999 | |||
| e31847449e | |||
| c2bb7c3dd9 | |||
| af33486ebb | |||
| 8e2ca029a3 | |||
| e0140fc13a | |||
| 4d60361fe3 | |||
| b22f1b58ac | |||
| 0cfcf3fbd1 | |||
| f220b24fc6 | |||
| df199a25bd | |||
| c27a1ce4bd | |||
| c67980bedc | |||
| 6ca62f21e3 | |||
| c3d2ac6561 | |||
| 6f34903e85 | |||
| 28f4b6885b | |||
| 48185c15c7 | |||
| d9e3093038 | |||
| d99f70680f | |||
| f5db2d3ea2 | |||
| d5c644c0b1 | |||
| 5df72a5ad6 | |||
| 34e33bb835 | |||
| 0bd1f4ea5a | |||
| bd790ee395 | |||
| 04738cb9ff | |||
| e4de1feb3e | |||
| 1288c9561d | |||
| f570f011eb | |||
| 0f89253e21 | |||
| 461c281a2e | |||
| 739105c72c | |||
| f1756d2a79 | |||
| 993b173e55 | |||
| d7489c3987 | |||
| c754fa5486 | |||
| bb113518f9 | |||
| d702fccbce | |||
| 8912d106e1 | |||
| f5905aa7be | |||
| 195e6967fb | |||
| ad2d8307ac | |||
| 01f3f25376 | |||
| 2e392e2c53 | |||
| ad3cab52fe | |||
| bd5a451d5d | |||
| 0b4efed236 | |||
| 07d6e3a74c | |||
| e4697f5e90 | |||
| 1873cd508a | |||
| 97fc3d060a | |||
| 2ce1a6ec60 | |||
| 2398937b7f | |||
| 1d1f30555d | |||
| b05789ff2b | |||
| 79b0c95687 | |||
| c977f7f596 | |||
| f29ce55958 | |||
| 633ed08d95 | |||
| d99bc930f7 | |||
| b6b2de0c35 | |||
| ce9079c8f2 | |||
| dc3794561f | |||
| 9adf9ac4e4 | |||
| 5b87fa2a57 | |||
| b38f58b51a | |||
| c3f9bad209 | |||
| 9456bcc975 | |||
| 4d908a3b43 | |||
| c22bd47d55 | |||
| 247be43d60 | |||
| d5feede1ff | |||
| 0f18b450ad | |||
| 891da435d6 | |||
| 685b941542 | |||
| 0bb28106be | |||
| cc47c28068 | |||
| 0fface6e33 | |||
| 133224676a | |||
| 2e18abf43c | |||
| 08192d5f76 | |||
| ef9f708e8f | |||
| f7bd5d75db | |||
| e8a49c12a6 | |||
| 7caf776079 | |||
| 41202ccae2 | |||
| 60ea3720f2 | |||
| 85b988c803 | |||
| e98d4fafe4 | |||
| 77155c480a | |||
| 57809db9c5 | |||
| 0ac6589202 | |||
| 67505e78c6 | |||
| c8cacb3704 | |||
| dd45df8a5b | |||
| 45698a3a03 | |||
| 1d0b872d43 | |||
| 7e2dfdd726 | |||
| a168045f7d | |||
| fc6cdfe9dc | |||
| 6b0e620fda | |||
| adbe353fc6 | |||
| c8d30ac109 | |||
| b04a5d8768 | |||
| feeb1394ee | |||
| fe1a1773a8 | |||
| 8b32e17d26 | |||
| 6ed41ad735 | |||
| bf3a4fa4cb | |||
| 41e941dda6 | |||
| 5447322939 | |||
| f238f700c2 | |||
| 7b7307fb7c | |||
| 3f6b548961 | |||
| 11f61696bc | |||
| dd579122da | |||
| 5efc18b6da | |||
| 29f5befc43 | |||
| e1e68f4974 | |||
| 035bd01d6a | |||
| 132ebed2bf | |||
| f18543ca39 | |||
| edaa6ebfdd | |||
| 203c211064 | |||
| 1d36650fa3 | |||
| 3c0d1ec01c | |||
| 2676a611ec | |||
| d4037e801a | |||
| 41f03d1d26 | |||
| 17a7f8ddab | |||
| 6b54e74cf4 | |||
| f1a7a13928 | |||
| 1cc3d75f69 | |||
| 545c23dc42 | |||
| 27a3220c54 | |||
| 5aed9c7410 | |||
| f2d74ffb74 | |||
| 84e5920738 | |||
| 38b360bb80 | |||
| 51fa3215fa | |||
| 094b2bbfc7 | |||
| 56c0e926f1 | |||
| 1f245e488a | |||
| 54ea6427df | |||
| 28b4e4890b | |||
| 7218ac7098 | |||
| 5191b7e699 | |||
| acd4c69580 | |||
| 2a0e11df42 | |||
| cd61c2816f | |||
| e684090012 | |||
| 4b845d7ef4 | |||
| 603240cf5d | |||
| ef2daf547d | |||
| 4ff6dfa7de | |||
| 417be79cd1 | |||
| 75148a27b4 | |||
| c0a165b304 | |||
| 2d0794e325 | |||
| 1b2e032999 | |||
| 30e58750c1 | |||
| f9ffac96a7 | |||
| 832508b7ea | |||
| 567c604bb5 | |||
| 47c8a67907 | |||
| 653bc75992 | |||
| fbc990826c | |||
| 89425d5e02 | |||
| f55f25f02f | |||
| 3212e18238 | |||
| 0bce8354b4 | |||
| dd5baa95e8 | |||
| 1350b030c1 | |||
| 4e0f995347 | |||
| ff78bd2f07 | |||
| a2ed56016f | |||
| cd7d2732bf | |||
| d3a149efca | |||
| e5095355d6 | |||
| dc04c58360 | |||
| 8e0a2f903a | |||
| b29b0a5227 | |||
| b59499c73b | |||
| a76b5dfca6 | |||
| 17f7193434 | |||
| 2af0b2d78f | |||
| 77c679c096 | |||
| 5cf8e8c7fa | |||
| 9562b55115 | |||
| aaab5725db | |||
| a80a1e6ae4 | |||
| 9e2751da83 | |||
| b1feb840df | |||
| 0a36c57eb0 | |||
| 969fa7c128 | |||
| e64e7b203e | |||
| cf9095061c | |||
| 5ae7af7cc2 | |||
| d820cb1b75 | |||
| 22f70c32f0 | |||
| 1d83f05257 | |||
| 2f4392ff5b | |||
| cffa014dc3 | |||
| 1e336b42f1 | |||
| 3cf9084a37 | |||
| 976658734c | |||
| 3e3a8ab13f | |||
| 8c87e6e0ff | |||
| 24e97df9c7 | |||
| 1bffb9c84f | |||
| 1dd397f091 | |||
| 0d65dc0e90 | |||
| 663fc63a77 | |||
| fa86c4127d | |||
| 1c92853dac | |||
| b419a926d4 | |||
| ef6764a1d9 | |||
| bb37fdc782 | |||
| 0ca3e24b2e | |||
| 9cfcf5d4f6 | |||
| 881a99e493 | |||
| 6b12545f4f | |||
| 71172c5c51 | |||
| a0f07f1919 | |||
| 9208643d2a | |||
| 7613bfae56 | |||
| a2e00042a1 | |||
| 555fcb489b | |||
| af9ff33ac1 | |||
| a297b5c3cf | |||
| 1ab4300ebc | |||
| 75c3edf8eb | |||
| 9647ff85fe | |||
| da9e034610 | |||
| be67d9cb4b | |||
| af989ba546 | |||
| d229ca9406 | |||
| 74e24cd0fa | |||
| 3a88fbda19 | |||
| 462768612b | |||
| e638bbf820 | |||
| aacc543e23 | |||
| c6b52df32d | |||
| c839258651 | |||
| f7f07c7aef | |||
| 9aa028daa2 | |||
| e7ec22019d | |||
| 8aff10153e | |||
| 4a32431ce7 | |||
| 7c917d196f | |||
| 6446c4dc67 | |||
| a3cf986fa5 | |||
| c38f3d510c | |||
| 4cbd68f805 | |||
| 0ce92edd57 | |||
| 653851f577 | |||
| 251d4b870d | |||
| a7fcb05988 | |||
| 6a6cfb9b31 | |||
| 2cf65aad6c | |||
| 7df884e0d6 | |||
| 208611fbca | |||
| 03c1e9262e | |||
| b8ca307e7b | |||
| 6ff13859d5 | |||
| e68fefdaa5 | |||
| e91d6fd3c3 | |||
| 59fefbab1a | |||
| 44ebccbe26 | |||
| 7a7c73905d | |||
| ece4ea4af4 | |||
| f5bf0a78be | |||
| c3a64ba0a6 | |||
| 5a2c2c20af | |||
| bc1bd58acf | |||
| f6e515b804 | |||
| a84f6005a9 | |||
| 606c0ddcfc | |||
| 7900eaded1 | |||
| 84e6b7b5ae | |||
| 778326010c | |||
| 58a11680d1 | |||
| 04096485f4 | |||
| ce927065c2 | |||
| 487ab3ca18 | |||
| 6b56344d4a | |||
| 8721ce4ae7 | |||
| 17e24df621 | |||
| 9bbca4c1c0 | |||
| 80ff32f5be | |||
| b70ce0c69c | |||
| 0f24678d8c | |||
| 9f71c2e002 | |||
| a8b38d286e | |||
| 18b81e5a93 | |||
| 33f51c9b71 | |||
| ba99af57ac | |||
| 6c32cf70d2 | |||
| 6d4abfbee5 | |||
| 01a346616f | |||
| af27914d2a | |||
| 6a535340bc | |||
| 98808babd3 | |||
| a411288fe8 | |||
| 1bee3d7b43 | |||
| f2d6a64495 | |||
| e21a57320e | |||
| e73e180933 | |||
| bf4133cba1 | |||
| 99fcd718e1 | |||
| 81a20f21d5 |
+262
-63
@@ -31,8 +31,15 @@ TCC = @TARGET_CC@ @TARGET_CFLAGS@ -I. -I${TOP}/src
|
||||
# Some standard variables and programs
|
||||
#
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
INSTALL = @INSTALL@
|
||||
LIBTOOL = ./libtool
|
||||
RELEASE = @ALLOWRELEASE@
|
||||
|
||||
# libtool compile/link/install
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(TCC)
|
||||
LTLINK = $(LIBTOOL) --mode=link $(TCC)
|
||||
LTINSTALL = $(LIBTOOL) --mode=install $(INSTALL)
|
||||
|
||||
# Compiler options needed for programs that use the TCL library.
|
||||
#
|
||||
@@ -56,30 +63,63 @@ LIBREADLINE = @TARGET_READLINE_LIBS@
|
||||
# ENCODING = ISO8859
|
||||
ENCODING = @ENCODING@
|
||||
|
||||
# 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@
|
||||
|
||||
ifeq (${INMEMORYDB},0)
|
||||
INCOREFLAGS += -DSQLITE_OMIT_INMEMORYDB=1
|
||||
endif
|
||||
|
||||
# You should not have to change anything below this line
|
||||
###############################################################################
|
||||
|
||||
# Object files for the SQLite library.
|
||||
#
|
||||
LIBOBJ = btree.lo build.lo delete.lo expr.lo hash.lo insert.lo \
|
||||
main.lo os.lo pager.lo parse.lo printf.lo random.lo select.lo \
|
||||
table.lo tokenize.lo update.lo util.lo vdbe.lo where.lo
|
||||
LIBOBJ = attach.lo auth.lo btree.lo build.lo copy.lo date.lo \
|
||||
delete.lo encode.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
|
||||
|
||||
# All of the source code files.
|
||||
#
|
||||
SRC = \
|
||||
$(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/date.c \
|
||||
$(TOP)/src/delete.c \
|
||||
$(TOP)/src/encode.c \
|
||||
$(TOP)/src/expr.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/hash.c \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pager.h \
|
||||
$(TOP)/src/parse.y \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/random.c \
|
||||
$(TOP)/src/select.c \
|
||||
@@ -89,9 +129,12 @@ SRC = \
|
||||
$(TOP)/src/table.c \
|
||||
$(TOP)/src/tclsqlite.c \
|
||||
$(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/trigger.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/where.c
|
||||
|
||||
@@ -99,16 +142,42 @@ SRC = \
|
||||
#
|
||||
TESTSRC = \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/md5.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
sqlite.h \
|
||||
$(TOP)/src/btree.h \
|
||||
config.h \
|
||||
$(TOP)/src/hash.h \
|
||||
opcodes.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
parse.h
|
||||
|
||||
# Header files used by the VDBE submodule
|
||||
#
|
||||
VDBEHDR = \
|
||||
$(HDR) \
|
||||
$(TOP)/src/vdbeInt.h
|
||||
|
||||
# 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: sqlite.h libsqlite.la sqlite@TARGET_EXEEXT@
|
||||
|
||||
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
|
||||
@@ -118,116 +187,188 @@ last_change: $(SRC)
|
||||
| awk '{print $$5,$$6}' >last_change
|
||||
|
||||
libsqlite.la: $(LIBOBJ)
|
||||
$(LIBTOOL) $(TCC) -o libsqlite.la $(LIBOBJ) -rpath $(prefix)/lib
|
||||
$(LTLINK) -o libsqlite.la $(LIBOBJ) ${RELEASE} -rpath @exec_prefix@/lib \
|
||||
-version-info "8:6:8"
|
||||
|
||||
libtclsqlite.la: $(LIBOBJ) tclsqlite.lo
|
||||
$(LIBTOOL) $(TCC) -o libtclsqlite.la $(LIBOBJ) tclsqlite.lo \
|
||||
$(LIBTCL) -rpath $(prefix)/lib
|
||||
libtclsqlite.la: tclsqlite.lo libsqlite.la
|
||||
$(LTLINK) -o libtclsqlite.la tclsqlite.lo \
|
||||
libsqlite.la $(LIBTCL) -rpath @exec_prefix@/lib/sqlite \
|
||||
-version-info "8:6:8"
|
||||
|
||||
sqlite: $(TOP)/src/shell.c libsqlite.la sqlite.h
|
||||
$(LIBTOOL) $(TCC) $(READLINE_FLAGS) -o sqlite $(TOP)/src/shell.c \
|
||||
sqlite@TARGET_EXEEXT@: $(TOP)/src/shell.c libsqlite.la sqlite.h
|
||||
$(LTLINK) $(READLINE_FLAGS) -o sqlite $(TOP)/src/shell.c \
|
||||
libsqlite.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
|
||||
# build on the target system. Some of the C source code and header
|
||||
# files are automatically generated. This target takes care of
|
||||
# all that automatic generation.
|
||||
#
|
||||
target_source: $(SRC) $(VDBEHDR)
|
||||
rm -rf tsrc
|
||||
mkdir tsrc
|
||||
cp $(SRC) $(VDBEHDR) tsrc
|
||||
rm tsrc/sqlite.h.in tsrc/parse.y
|
||||
cp parse.c opcodes.c tsrc
|
||||
|
||||
# Rules to build the LEMON compiler generator
|
||||
#
|
||||
lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
lemon@BUILD_EXEEXT@: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
$(BCC) -o lemon $(TOP)/tool/lemon.c
|
||||
cp $(TOP)/tool/lempar.c .
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
sqlite.h \
|
||||
$(TOP)/src/btree.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
parse.h
|
||||
|
||||
btree.lo: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/btree.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/btree.c
|
||||
|
||||
btree_rb.lo: $(TOP)/src/btree_rb.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/btree_rb.c
|
||||
|
||||
build.lo: $(TOP)/src/build.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/build.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/build.c
|
||||
|
||||
main.lo: $(TOP)/src/main.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/main.c
|
||||
$(LTCOMPILE) -c ${INCOREFLAGS} $(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
|
||||
$(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.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.lo: $(TOP)/src/os.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/os.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/os.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@BUILD_EXEEXT@
|
||||
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
|
||||
$(LTCOMPILE) -c $(TOP)/src/tokenize.c
|
||||
|
||||
util.lo: $(TOP)/src/util.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/util.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/util.c
|
||||
|
||||
vdbe.lo: $(TOP)/src/vdbe.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/vdbe.c
|
||||
vdbe.lo: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbe.c
|
||||
|
||||
vdbeaux.lo: $(TOP)/src/vdbe.c $(VDBEHDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vdbeaux.c
|
||||
|
||||
where.lo: $(TOP)/src/where.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/where.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/where.c
|
||||
|
||||
copy.lo: $(TOP)/src/copy.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/copy.c
|
||||
|
||||
date.lo: $(TOP)/src/date.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/date.c
|
||||
|
||||
delete.lo: $(TOP)/src/delete.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/delete.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/delete.c
|
||||
|
||||
encode.lo: $(TOP)/src/encode.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/encode.c
|
||||
|
||||
expr.lo: $(TOP)/src/expr.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/expr.c
|
||||
$(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)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/hash.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/hash.c
|
||||
|
||||
insert.lo: $(TOP)/src/insert.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/insert.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/insert.c
|
||||
|
||||
random.lo: $(TOP)/src/random.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/random.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/random.c
|
||||
|
||||
select.lo: $(TOP)/src/select.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/select.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/select.c
|
||||
|
||||
table.lo: $(TOP)/src/table.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/table.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/table.c
|
||||
|
||||
trigger.lo: $(TOP)/src/trigger.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/trigger.c
|
||||
|
||||
update.lo: $(TOP)/src/update.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) -c $(TOP)/src/update.c
|
||||
$(LTCOMPILE) -c $(TOP)/src/update.c
|
||||
|
||||
vacuum.lo: $(TOP)/src/vacuum.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/vacuum.c
|
||||
|
||||
tclsqlite.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
pragma.lo: $(TOP)/src/pragma.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
|
||||
|
||||
printf.lo: $(TOP)/src/printf.c $(HDR)
|
||||
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
|
||||
tclsqlite: $(TOP)/src/tclsqlite.c libsqlite.la
|
||||
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite \
|
||||
$(TOP)/src/tclsqlite.c libsqlite.la $(LIBTCL)
|
||||
attach.lo: $(TOP)/src/attach.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/attach.c
|
||||
|
||||
testfixture: $(TOP)/src/tclsqlite.c libtclsqlite.la $(TESTSRC)
|
||||
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1\
|
||||
auth.lo: $(TOP)/src/auth.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/auth.c
|
||||
|
||||
tclsqlite-sh.lo: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(LTCOMPILE) $(TCL_FLAGS) -DTCLSH=1 -o $@ -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
tclsqlite: tclsqlite-sh.lo libsqlite.la
|
||||
$(LTLINK) $(TCL_FLAGS) -o tclsqlite tclsqlite-sh.lo libsqlite.la $(LIBTCL)
|
||||
|
||||
testfixture@TARGET_EXEEXT@: $(TOP)/src/tclsqlite.c libtclsqlite.la libsqlite.la $(TESTSRC)
|
||||
$(LTLINK) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1\
|
||||
-o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libtclsqlite.la $(LIBTCL)
|
||||
libtclsqlite.la libsqlite.la $(LIBTCL)
|
||||
|
||||
fulltest: testfixture sqlite
|
||||
fulltest: testfixture@TARGET_EXEEXT@ sqlite@TARGET_EXEEXT@
|
||||
./testfixture $(TOP)/test/all.test
|
||||
|
||||
test: testfixture sqlite
|
||||
test: testfixture@TARGET_EXEEXT@ sqlite@TARGET_EXEEXT@
|
||||
./testfixture $(TOP)/test/quick.test
|
||||
|
||||
index.html: $(TOP)/www/index.tcl last_change
|
||||
@@ -257,9 +398,6 @@ arch.png: $(TOP)/www/arch.png
|
||||
opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
|
||||
tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
|
||||
|
||||
crosscompile.html: $(TOP)/www/crosscompile.tcl
|
||||
tclsh $(TOP)/www/crosscompile.tcl >crosscompile.html
|
||||
|
||||
mingw.html: $(TOP)/www/mingw.tcl
|
||||
tclsh $(TOP)/www/mingw.tcl >mingw.html
|
||||
|
||||
@@ -269,9 +407,33 @@ tclsqlite.html: $(TOP)/www/tclsqlite.tcl
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
nulls.html: $(TOP)/www/nulls.tcl
|
||||
tclsh $(TOP)/www/nulls.tcl >nulls.html
|
||||
|
||||
|
||||
# Files to be published on the website.
|
||||
#
|
||||
@@ -285,25 +447,62 @@ DOC = \
|
||||
arch.png \
|
||||
vdbe.html \
|
||||
c_interface.html \
|
||||
crosscompile.html \
|
||||
mingw.html \
|
||||
tclsqlite.html \
|
||||
download.html \
|
||||
speed.html
|
||||
speed.html \
|
||||
faq.html \
|
||||
formatchng.html \
|
||||
conflict.html \
|
||||
omitted.html \
|
||||
datatypes.html \
|
||||
quickstart.html \
|
||||
fileformat.html \
|
||||
nulls.html
|
||||
|
||||
doc: $(DOC)
|
||||
mkdir -p doc
|
||||
mv $(DOC) doc
|
||||
|
||||
install: sqlite libsqlite.la sqlite.h
|
||||
$(LIBTOOL) $(INSTALL) libsqlite.la $(prefix)/lib
|
||||
$(LIBTOOL) $(INSTALL) sqlite $(prefix)/bin
|
||||
$(INSTALL) sqlite.h $(prefix)/include
|
||||
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/lib
|
||||
$(LTINSTALL) libsqlite.la $(DESTDIR)$(exec_prefix)/lib
|
||||
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/bin
|
||||
$(LTINSTALL) sqlite $(DESTDIR)$(exec_prefix)/bin
|
||||
$(INSTALL) -d $(DESTDIR)$(prefix)/include
|
||||
$(INSTALL) -m 0644 sqlite.h $(DESTDIR)$(prefix)/include
|
||||
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/lib/pkgconfig;
|
||||
$(INSTALL) -m 0644 sqlite.pc $(DESTDIR)$(exec_prefix)/lib/pkgconfig;
|
||||
|
||||
clean:
|
||||
rm -f *.lo *.la *.o sqlite libsqlite.la sqlite.h
|
||||
rm -rf .libs .deps
|
||||
rm -f lemon lempar.c parse.* sqlite*.tar.gz
|
||||
rm -f *.lo *.la *.o sqlite@TARGET_EXEEXT@ libsqlite.la sqlite.h opcodes.*
|
||||
rm -rf .libs .deps
|
||||
rm -f lemon@BUILD_EXEEXT@ lempar.c parse.* sqlite*.tar.gz
|
||||
rm -f $(PUBLISH)
|
||||
rm -f *.da *.bb *.bbg gmon.out
|
||||
rm -f testfixture test.db
|
||||
rm -f testfixture@TARGET_EXEEXT@ test.db
|
||||
rm -rf doc
|
||||
rm -f sqlite.dll sqlite.lib
|
||||
|
||||
#
|
||||
# Windows section; all this funky .dll stuff ;-)
|
||||
#
|
||||
dll: sqlite.dll
|
||||
|
||||
REAL_LIBOBJ = $(LIBOBJ:%.lo=.libs/%.o)
|
||||
|
||||
sqlite.dll: $(LIBOBJ) $(TOP)/sqlite.def
|
||||
dllwrap --dllname sqlite.dll --def $(TOP)/sqlite.def $(REAL_LIBOBJ)
|
||||
strip sqlite.dll
|
||||
|
||||
#target for dll import libraries
|
||||
implib: sqlite.lib
|
||||
|
||||
#make Borland C++ and/or Microsoft VC import library for the dll
|
||||
# ignore any errors (usually due to missing programs)
|
||||
sqlite.lib: sqlite.dll
|
||||
-implib -a sqlite.lib sqlite.dll
|
||||
-lib /machine:i386 /def:$(TOP)/sqlite.def
|
||||
|
||||
distclean: clean
|
||||
rm -f config.log config.status libtool Makefile config.h
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
#!/usr/make
|
||||
#
|
||||
# Makefile for SQLITE
|
||||
#
|
||||
# This is a template makefile for SQLite. Most people prefer to
|
||||
# use the autoconf generated "configure" script to generate the
|
||||
# makefile automatically. But that does not work for everybody
|
||||
# and in every situation. If you are having problems with the
|
||||
# "configure" script, you might want to try this makefile as an
|
||||
# alternative. Create a copy of this file, edit the parameters
|
||||
# below and type "make".
|
||||
#
|
||||
|
||||
#### The toplevel directory of the source tree. This is the directory
|
||||
# that contains this "Makefile.in" and the "configure.in" script.
|
||||
#
|
||||
TOP = ../sqlite
|
||||
|
||||
#### C Compiler and options for use in building executables that
|
||||
# will run on the platform that is doing the build.
|
||||
#
|
||||
BCC = gcc -g -O2
|
||||
#BCC = /opt/ancic/bin/c89 -0
|
||||
|
||||
#### If the target operating system supports the "usleep()" system
|
||||
# call, then define the HAVE_USLEEP macro for all C modules.
|
||||
#
|
||||
#USLEEP =
|
||||
USLEEP = -DHAVE_USLEEP=1
|
||||
|
||||
#### If you want the SQLite library to be safe for use within a
|
||||
# multi-threaded program, then define the following macro
|
||||
# appropriately:
|
||||
#
|
||||
#THREADSAFE = -DTHREADSAFE=1
|
||||
THREADSAFE = -DTHREADSAFE=0
|
||||
|
||||
#### Specify any extra linker options needed to make the library
|
||||
# thread safe
|
||||
#
|
||||
#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
|
||||
# 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 =
|
||||
OPTS = -DNDEBUG=1
|
||||
|
||||
#### The suffix to add to executable files. ".exe" for windows.
|
||||
# Nothing for unix.
|
||||
#
|
||||
#EXE = .exe
|
||||
EXE =
|
||||
|
||||
#### C Compile and options for use in building executables that
|
||||
# will run on the target platform. This is usually the same
|
||||
# as BCC, unless you are cross-compiling.
|
||||
#
|
||||
TCC = gcc -O6
|
||||
#TCC = gcc -g -O0 -Wall
|
||||
#TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage
|
||||
#TCC = /opt/mingw/bin/i386-mingw32-gcc -O6
|
||||
#TCC = /opt/ansic/bin/c89 -O +z -Wl,-a,archive
|
||||
|
||||
#### Tools used to build a static library.
|
||||
#
|
||||
AR = ar cr
|
||||
#AR = /opt/mingw/bin/i386-mingw32-ar cr
|
||||
RANLIB = ranlib
|
||||
#RANLIB = /opt/mingw/bin/i386-mingw32-ranlib
|
||||
|
||||
#### Extra compiler options needed for programs that use the TCL library.
|
||||
#
|
||||
#TCL_FLAGS =
|
||||
#TCL_FLAGS = -DSTATIC_BUILD=1
|
||||
TCL_FLAGS = -I/home/drh/tcltk/8.4linux
|
||||
#TCL_FLAGS = -I/home/drh/tcltk/8.4win -DSTATIC_BUILD=1
|
||||
#TCL_FLAGS = -I/home/drh/tcltk/8.3hpux
|
||||
|
||||
#### Linker options needed to link against the TCL library.
|
||||
#
|
||||
#LIBTCL = -ltcl -lm -ldl
|
||||
LIBTCL = /home/drh/tcltk/8.4linux/libtcl8.4g.a -lm -ldl
|
||||
#LIBTCL = /home/drh/tcltk/8.4win/libtcl84s.a -lmsvcrt
|
||||
#LIBTCL = /home/drh/tcltk/8.3hpux/libtcl8.3.a -ldld -lm -lc
|
||||
|
||||
#### Compiler options needed for programs that use the readline() library.
|
||||
#
|
||||
#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
|
||||
|
||||
#### Should the database engine assume text is coded as UTF-8 or iso8859?
|
||||
#
|
||||
# ENCODING = UTF8
|
||||
ENCODING = ISO8859
|
||||
|
||||
# You should not have to change anything below this line
|
||||
###############################################################################
|
||||
include $(TOP)/main.mk
|
||||
@@ -1,366 +0,0 @@
|
||||
#!/usr/make
|
||||
#
|
||||
# Makefile for SQLITE
|
||||
#
|
||||
# This is a template makefile for SQLite. Most people prefer to
|
||||
# use the autoconf generated "configure" script to generate the
|
||||
# makefile automatically. But that does not work for everybody
|
||||
# and in every situation. If you are having problems with the
|
||||
# "configure" script, you might want to try this makefile as an
|
||||
# alternative. Create a copy of this file, edit the parameters
|
||||
# below and type "make".
|
||||
#
|
||||
|
||||
#### The toplevel directory of the source tree. This is the directory
|
||||
# that contains this "Makefile.in" and the "configure.in" script.
|
||||
#
|
||||
TOP = ../sqlite
|
||||
|
||||
#### C Compiler and options for use in building executables that
|
||||
# will run on the platform that is doing the build.
|
||||
#
|
||||
BCC = gcc -g -O2
|
||||
#BCC = /opt/ancic/bin/c89 -0
|
||||
|
||||
#### If the target operating system supports the "usleep()" system
|
||||
# call, then define the HAVE_USLEEP macro for all C modules.
|
||||
#
|
||||
#USLEEP =
|
||||
USLEEP = -DHAVE_USLEEP=1
|
||||
|
||||
#### 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
|
||||
# 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 =
|
||||
OPTS = -DNDEBUG=1
|
||||
|
||||
#### Compiler flags that change according to the operating system.
|
||||
#
|
||||
#OSFLAGS = -DOS_UNIX=0 -DOS_WIN=1
|
||||
OSFLAGS = -DOS_UNIX=1 -DOS_WIN=0
|
||||
|
||||
#### The suffix to add to executable files. ".exe" for windows.
|
||||
# Nothing for unix.
|
||||
#
|
||||
#EXE = .exe
|
||||
EXE =
|
||||
|
||||
#### C Compile and options for use in building executables that
|
||||
# will run on the target platform. This is usually the same
|
||||
# as BCC, unless you are cross-compiling.
|
||||
#
|
||||
TCC = gcc -O6
|
||||
#TCC = gcc -g -O0 -Wall
|
||||
#TCC = /opt/mingw/bin/i386-mingw32-gcc -O6
|
||||
#TCC = /opt/ansic/bin/c89 -O +z -Wl,-a,archive
|
||||
|
||||
#### Tools used to build a static library.
|
||||
#
|
||||
AR = ar cr
|
||||
#AR = /opt/mingw/bin/i386-mingw32-ar cr
|
||||
RANLIB = ranlib
|
||||
#RANLIB = /opt/mingw/bin/i386-mingw32-ranlib
|
||||
|
||||
#### Extra compiler options needed for programs that use the TCL library.
|
||||
#
|
||||
#TCL_FLAGS =
|
||||
#TCL_FLAGS = -DSTATIC_BUILD=1
|
||||
TCL_FLAGS = -I/home/drh/tcltk/8.4linux
|
||||
#TCL_FLAGS = -I/home/drh/tcltk/8.4win -DSTATIC_BUILD=1
|
||||
#TCL_FLAGS = -I/home/drh/tcltk/8.3hpux
|
||||
|
||||
#### Linker options needed to link against the TCL library.
|
||||
#
|
||||
#LIBTCL = -ltcl -lm -ldl
|
||||
LIBTCL = /home/drh/tcltk/8.4linux/libtcl8.4g.a -lm -ldl
|
||||
#LIBTCL = /home/drh/tcltk/8.4win/libtcl84s.a -lmsvcrt
|
||||
#LIBTCL = /home/drh/tcltk/8.3hpux/libtcl8.3.a -ldld -lm -lc
|
||||
|
||||
#### Compiler options needed for programs that use the readline() library.
|
||||
#
|
||||
#READLINE_FLAGS =
|
||||
READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline
|
||||
|
||||
#### Linker options needed by programs using readline() must link against.
|
||||
#
|
||||
#LIBREADLINE =
|
||||
LIBREADLINE = -lreadline
|
||||
|
||||
#### Should the database engine assume text is coded as UTF-8 or iso8859?
|
||||
#
|
||||
# ENCODING = UTF8
|
||||
ENCODING = ISO8859
|
||||
|
||||
# You should not have to change anything below this line
|
||||
###############################################################################
|
||||
|
||||
# This is how we compile
|
||||
#
|
||||
TCCX = $(TCC) $(OPTS) $(OSFLAGS) $(USLEEP) -I. -I$(TOP)/src
|
||||
|
||||
# Object files for the SQLite library.
|
||||
#
|
||||
LIBOBJ = btree.o build.o delete.o expr.o hash.o insert.o \
|
||||
main.o os.o pager.o parse.o printf.o random.o select.o table.o \
|
||||
tokenize.o update.o util.o vdbe.o where.o tclsqlite.o
|
||||
|
||||
# All of the source code files.
|
||||
#
|
||||
SRC = \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/btree.h \
|
||||
$(TOP)/src/build.c \
|
||||
$(TOP)/src/delete.c \
|
||||
$(TOP)/src/expr.c \
|
||||
$(TOP)/src/hash.c \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pager.h \
|
||||
$(TOP)/src/parse.y \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/random.c \
|
||||
$(TOP)/src/select.c \
|
||||
$(TOP)/src/shell.c \
|
||||
$(TOP)/src/sqlite.h.in \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/table.c \
|
||||
$(TOP)/src/tclsqlite.c \
|
||||
$(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/update.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/where.c
|
||||
|
||||
# Source code to the test files.
|
||||
#
|
||||
TESTSRC = \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/md5.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
sqlite.h \
|
||||
$(TOP)/src/btree.h \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
parse.h
|
||||
|
||||
# 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.a sqlite$(EXE)
|
||||
|
||||
# Generate the file "last_change" which contains the date of change
|
||||
# of the most recently modified source code file
|
||||
#
|
||||
last_change: $(SRC)
|
||||
cat $(SRC) | grep '$$Id: ' | sort +4 | tail -1 \
|
||||
| awk '{print $$5,$$6}' >last_change
|
||||
|
||||
libsqlite.a: $(LIBOBJ) tclsqlite.o
|
||||
$(AR) libsqlite.a $(LIBOBJ) tclsqlite.o
|
||||
$(RANLIB) libsqlite.a
|
||||
|
||||
sqlite$(EXE): $(TOP)/src/shell.c libsqlite.a sqlite.h
|
||||
$(TCCX) $(READLINE_FLAGS) -o sqlite$(EXE) $(TOP)/src/shell.c \
|
||||
libsqlite.a $(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
|
||||
# build on the target system. Some of the C source code and header
|
||||
# files are automatically generated. This target takes care of
|
||||
# all that automatic generation.
|
||||
#
|
||||
target_source: $(SRC) $(HDR)
|
||||
rm -rf tsrc
|
||||
mkdir tsrc
|
||||
cp $(SRC) $(HDR) tsrc
|
||||
rm tsrc/sqlite.h.in tsrc/parse.y
|
||||
cp parse.c tsrc
|
||||
|
||||
# Rules to build the LEMON compiler generator
|
||||
#
|
||||
lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
$(BCC) -o lemon $(TOP)/tool/lemon.c
|
||||
cp $(TOP)/tool/lempar.c .
|
||||
|
||||
btree.o: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
|
||||
$(TCCX) -c $(TOP)/src/btree.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
|
||||
|
||||
pager.o: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
$(TCCX) -c $(TOP)/src/pager.c
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
util.o: $(TOP)/src/util.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/util.c
|
||||
|
||||
vdbe.o: $(TOP)/src/vdbe.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/vdbe.c
|
||||
|
||||
where.o: $(TOP)/src/where.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/where.c
|
||||
|
||||
delete.o: $(TOP)/src/delete.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/delete.c
|
||||
|
||||
expr.o: $(TOP)/src/expr.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/expr.c
|
||||
|
||||
hash.o: $(TOP)/src/hash.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/hash.c
|
||||
|
||||
insert.o: $(TOP)/src/insert.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/insert.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
|
||||
|
||||
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
|
||||
|
||||
printf.o: $(TOP)/src/printf.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
|
||||
tclsqlite: $(TOP)/src/tclsqlite.c libsqlite.a
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite \
|
||||
$(TOP)/src/tclsqlite.c libsqlite.a $(LIBTCL)
|
||||
|
||||
testfixture$(EXE): $(TOP)/src/tclsqlite.c libsqlite.a $(TESTSRC)
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -o testfixture$(EXE) \
|
||||
$(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite.a $(LIBTCL)
|
||||
|
||||
fulltest: testfixture$(EXE) sqlite$(EXE)
|
||||
./testfixture$(EXE) $(TOP)/test/all.test
|
||||
|
||||
test: testfixture$(EXE) sqlite$(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
|
||||
|
||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
|
||||
|
||||
c_interface.html: $(TOP)/www/c_interface.tcl
|
||||
tclsh $(TOP)/www/c_interface.tcl >c_interface.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
|
||||
|
||||
vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
tclsh $(TOP)/www/vdbe.tcl >vdbe.html
|
||||
|
||||
arch.html: $(TOP)/www/arch.tcl
|
||||
tclsh $(TOP)/www/arch.tcl >arch.html
|
||||
|
||||
arch.png: $(TOP)/www/arch.png
|
||||
cp $(TOP)/www/arch.png .
|
||||
|
||||
opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
|
||||
tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
|
||||
|
||||
crosscompile.html: $(TOP)/www/crosscompile.tcl
|
||||
tclsh $(TOP)/www/crosscompile.tcl >crosscompile.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
|
||||
|
||||
download.html: $(TOP)/www/download.tcl
|
||||
tclsh $(TOP)/www/download.tcl >download.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 \
|
||||
c_interface.html \
|
||||
crosscompile.html \
|
||||
mingw.html \
|
||||
tclsqlite.html \
|
||||
download.html \
|
||||
speed.html
|
||||
|
||||
doc: $(DOC)
|
||||
mkdir -p doc
|
||||
mv $(DOC) doc
|
||||
|
||||
install: sqlite libsqlite.a sqlite.h
|
||||
mv sqlite /usr/bin
|
||||
mv libsqlite.a /usr/lib
|
||||
mv sqlite.h /usr/include
|
||||
|
||||
clean:
|
||||
rm -f *.o sqlite libsqlite.a sqlite.h
|
||||
rm -f lemon lempar.c parse.* sqlite*.tar.gz
|
||||
rm -f $(PUBLISH)
|
||||
rm -f *.da *.bb *.bbg gmon.out
|
||||
rm -rf tsrc
|
||||
@@ -1,6 +1,6 @@
|
||||
This directory contains source code to
|
||||
|
||||
SQLite: An SQL Database Engine in a C Library
|
||||
SQLite: An Embeddable SQL Database Engine
|
||||
|
||||
To compile the project, first create a directory in which to place
|
||||
the build products. It is recommended, but not required, that the
|
||||
@@ -18,6 +18,20 @@ For example:
|
||||
|
||||
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
|
||||
"Makefile.template" in the top directory of the source tree that you
|
||||
"Makefile.linux-gcc" in the top directory of the source tree that you
|
||||
can copy and edit to suite your needs. Comments on the generic makefile
|
||||
show what changes are needed.
|
||||
|
||||
The linux binaries on the website are created using the generic makefile,
|
||||
not the configure script. The configure script is unmaintained. (You
|
||||
can volunteer to take over maintenance of the configure script, if you want!)
|
||||
The windows binaries on the website are created using MinGW32 configured
|
||||
as a cross-compiler running under Linux. For details, see the ./publish.sh
|
||||
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
+2289
-1534
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
Vendored
+337
-222
@@ -1,9 +1,9 @@
|
||||
#! /bin/sh
|
||||
# Attempt to guess a canonical system name.
|
||||
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
|
||||
# Free Software Foundation, Inc.
|
||||
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
|
||||
# 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
|
||||
timestamp='2001-09-04'
|
||||
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
|
||||
@@ -24,8 +24,9 @@ timestamp='2001-09-04'
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# Written by Per Bothner <bothner@cygnus.com>.
|
||||
# Please send patches to <config-patches@gnu.org>.
|
||||
# Originally written by Per Bothner <per@bothner.com>.
|
||||
# Please send patches to <config-patches@gnu.org>. Submit a context
|
||||
# diff and a properly formatted ChangeLog entry.
|
||||
#
|
||||
# This script attempts to guess a canonical system name similar to
|
||||
# config.sub. If it succeeds, it prints the system name on stdout, and
|
||||
@@ -87,30 +88,42 @@ if test $# != 0; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
trap 'exit 1' 1 2 15
|
||||
|
||||
dummy=dummy-$$
|
||||
trap 'rm -f $dummy.c $dummy.o $dummy.rel $dummy; exit 1' 1 2 15
|
||||
# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
|
||||
# compiler to aid in system detection is discouraged as it requires
|
||||
# temporary files to be created and, as you can see below, it is a
|
||||
# headache to deal with in a portable fashion.
|
||||
|
||||
# CC_FOR_BUILD -- compiler used by this script.
|
||||
# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
|
||||
# use `HOST_CC' if defined, but it is deprecated.
|
||||
|
||||
set_cc_for_build='case $CC_FOR_BUILD,$HOST_CC,$CC in
|
||||
,,) echo "int dummy(){}" > $dummy.c ;
|
||||
for c in cc gcc c89 ; do
|
||||
($c $dummy.c -c -o $dummy.o) >/dev/null 2>&1 ;
|
||||
if test $? = 0 ; then
|
||||
# Portable tmp directory creation inspired by the Autoconf team.
|
||||
|
||||
set_cc_for_build='
|
||||
trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
|
||||
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" ;
|
||||
case $CC_FOR_BUILD,$HOST_CC,$CC in
|
||||
,,) echo "int x;" > $dummy.c ;
|
||||
for c in cc gcc c89 c99 ; do
|
||||
if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
|
||||
CC_FOR_BUILD="$c"; break ;
|
||||
fi ;
|
||||
done ;
|
||||
rm -f $dummy.c $dummy.o $dummy.rel ;
|
||||
if test x"$CC_FOR_BUILD" = x ; then
|
||||
CC_FOR_BUILD=no_compiler_found ;
|
||||
fi
|
||||
;;
|
||||
,,*) CC_FOR_BUILD=$CC ;;
|
||||
,*,*) CC_FOR_BUILD=$HOST_CC ;;
|
||||
esac'
|
||||
esac ;'
|
||||
|
||||
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
|
||||
# (ghazi@noc.rutgers.edu 1994-08-24)
|
||||
@@ -127,29 +140,30 @@ UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
|
||||
|
||||
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
*:NetBSD:*:*)
|
||||
# Netbsd (nbsd) targets should (where applicable) match one or
|
||||
# NetBSD (nbsd) targets should (where applicable) match one or
|
||||
# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
|
||||
# *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
|
||||
# switched to ELF, *-*-netbsd* would select the old
|
||||
# object file format. This provides both forward
|
||||
# compatibility and a consistent mechanism for selecting the
|
||||
# object file format.
|
||||
# Determine the machine/vendor (is the vendor relevant).
|
||||
case "${UNAME_MACHINE}" in
|
||||
amiga) machine=m68k-unknown ;;
|
||||
arm32) machine=arm-unknown ;;
|
||||
atari*) machine=m68k-atari ;;
|
||||
sun3*) machine=m68k-sun ;;
|
||||
mac68k) machine=m68k-apple ;;
|
||||
macppc) machine=powerpc-apple ;;
|
||||
hp3[0-9][05]) machine=m68k-hp ;;
|
||||
ibmrt|romp-ibm) machine=romp-ibm ;;
|
||||
*) machine=${UNAME_MACHINE}-unknown ;;
|
||||
#
|
||||
# Note: NetBSD doesn't particularly care about the vendor
|
||||
# portion of the name. We always set it to "unknown".
|
||||
sysctl="sysctl -n hw.machine_arch"
|
||||
UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
|
||||
/usr/sbin/$sysctl 2>/dev/null || echo unknown)`
|
||||
case "${UNAME_MACHINE_ARCH}" in
|
||||
armeb) machine=armeb-unknown ;;
|
||||
arm*) machine=arm-unknown ;;
|
||||
sh3el) machine=shl-unknown ;;
|
||||
sh3eb) machine=sh-unknown ;;
|
||||
*) machine=${UNAME_MACHINE_ARCH}-unknown ;;
|
||||
esac
|
||||
# The Operating System including object format, if it has switched
|
||||
# to ELF recently, or will in the future.
|
||||
case "${UNAME_MACHINE}" in
|
||||
i386|sparc|amiga|arm*|hp300|mvme68k|vax|atari|luna68k|mac68k|news68k|next68k|pc532|sun3*|x68k)
|
||||
case "${UNAME_MACHINE_ARCH}" in
|
||||
arm*|i386|m68k|ns32k|sh3*|sparc|vax)
|
||||
eval $set_cc_for_build
|
||||
if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
|
||||
| grep __ELF__ >/dev/null
|
||||
@@ -166,75 +180,115 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
;;
|
||||
esac
|
||||
# The OS release
|
||||
release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
|
||||
# Debian GNU/NetBSD machines have a different userland, and
|
||||
# thus, need a distinct triplet. However, they do not need
|
||||
# kernel version information, so it can be replaced with a
|
||||
# suitable tag, in the style of linux-gnu.
|
||||
case "${UNAME_VERSION}" in
|
||||
Debian*)
|
||||
release='-gnu'
|
||||
;;
|
||||
*)
|
||||
release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
|
||||
;;
|
||||
esac
|
||||
# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
|
||||
# contains redundant information, the shorter form:
|
||||
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
|
||||
echo "${machine}-${os}${release}"
|
||||
exit 0 ;;
|
||||
amiga:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
arc:OpenBSD:*:*)
|
||||
echo mipsel-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
hp300:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
mac68k:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
macppc:OpenBSD:*:*)
|
||||
echo powerpc-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
mvme68k:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
mvme88k:OpenBSD:*:*)
|
||||
echo m88k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
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 ;;
|
||||
sgi:OpenBSD:*:*)
|
||||
echo mipseb-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
sun3:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
wgrisc:OpenBSD:*:*)
|
||||
echo mipsel-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:OpenBSD:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-openbsd${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.
|
||||
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
|
||||
eval $set_cc_for_build
|
||||
$CC_FOR_BUILD $dummy.s -o $dummy 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"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
rm -f $dummy.s $dummy
|
||||
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
|
||||
@@ -247,33 +301,18 @@ EOF
|
||||
Amiga*:UNIX_System_V:4.0:*)
|
||||
echo m68k-unknown-sysv4
|
||||
exit 0;;
|
||||
amiga:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:[Aa]miga[Oo][Ss]:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-amigaos
|
||||
exit 0 ;;
|
||||
arc64:OpenBSD:*:*)
|
||||
echo mips64el-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
arc:OpenBSD:*:*)
|
||||
echo mipsel-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
hkmips:OpenBSD:*:*)
|
||||
echo mips-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
pmax:OpenBSD:*:*)
|
||||
echo mipsel-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
sgi:OpenBSD:*:*)
|
||||
echo mips-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
wgrisc:OpenBSD:*:*)
|
||||
echo mipsel-unknown-openbsd${UNAME_RELEASE}
|
||||
*:[Mm]orph[Oo][Ss]:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-morphos
|
||||
exit 0 ;;
|
||||
*: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;;
|
||||
@@ -291,6 +330,13 @@ 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 ;;
|
||||
esac ;;
|
||||
sun4H:SunOS:5.*:*)
|
||||
echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
exit 0 ;;
|
||||
@@ -319,7 +365,7 @@ EOF
|
||||
echo m68k-sun-sunos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
sun*:*:4.2BSD:*)
|
||||
UNAME_RELEASE=`(head -1 /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
|
||||
UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
|
||||
test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
|
||||
case "`/bin/arch`" in
|
||||
sun3)
|
||||
@@ -333,12 +379,6 @@ EOF
|
||||
aushp:SunOS:*:*)
|
||||
echo sparc-auspex-sunos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
sparc*:NetBSD:*)
|
||||
echo `uname -p`-unknown-netbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
atari*:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
# The situation for MiNT is a little confusing. The machine name
|
||||
# can be virtually everything (everything which is not
|
||||
# "atarist" or "atariste" at least should have a processor
|
||||
@@ -365,18 +405,6 @@ EOF
|
||||
*:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
|
||||
echo m68k-unknown-mint${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
sun3*:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
mac68k:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
mvme68k:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
mvme88k:OpenBSD:*:*)
|
||||
echo m88k-unknown-openbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
powerpc:machten:*:*)
|
||||
echo powerpc-apple-machten${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
@@ -415,15 +443,20 @@ EOF
|
||||
exit (-1);
|
||||
}
|
||||
EOF
|
||||
$CC_FOR_BUILD $dummy.c -o $dummy \
|
||||
&& ./$dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
|
||||
&& rm -f $dummy.c $dummy && exit 0
|
||||
rm -f $dummy.c $dummy
|
||||
$CC_FOR_BUILD -o $dummy $dummy.c \
|
||||
&& $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
|
||||
&& exit 0
|
||||
echo mips-mips-riscos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
Motorola:PowerMAX_OS:*:*)
|
||||
echo powerpc-motorola-powermax
|
||||
exit 0 ;;
|
||||
Motorola:*:4.3:PL8-*)
|
||||
echo powerpc-harris-powermax
|
||||
exit 0 ;;
|
||||
Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
|
||||
echo powerpc-harris-powermax
|
||||
exit 0 ;;
|
||||
Night_Hawk:Power_UNIX:*:*)
|
||||
echo powerpc-harris-powerunix
|
||||
exit 0 ;;
|
||||
@@ -496,8 +529,7 @@ EOF
|
||||
exit(0);
|
||||
}
|
||||
EOF
|
||||
$CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0
|
||||
rm -f $dummy.c $dummy
|
||||
$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
|
||||
echo rs6000-ibm-aix3.2.5
|
||||
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
|
||||
echo rs6000-ibm-aix3.2.4
|
||||
@@ -506,7 +538,7 @@ EOF
|
||||
fi
|
||||
exit 0 ;;
|
||||
*:AIX:*:[45])
|
||||
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ print $1 }'`
|
||||
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
|
||||
if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
|
||||
IBM_ARCH=rs6000
|
||||
else
|
||||
@@ -546,10 +578,8 @@ EOF
|
||||
9000/31? ) HP_ARCH=m68000 ;;
|
||||
9000/[34]?? ) HP_ARCH=m68k ;;
|
||||
9000/[678][0-9][0-9])
|
||||
case "${HPUX_REV}" in
|
||||
11.[0-9][0-9])
|
||||
if [ -x /usr/bin/getconf ]; then
|
||||
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
|
||||
if [ -x /usr/bin/getconf ]; then
|
||||
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
|
||||
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
|
||||
case "${sc_cpu_version}" in
|
||||
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
|
||||
@@ -558,13 +588,13 @@ EOF
|
||||
case "${sc_kernel_bits}" in
|
||||
32) HP_ARCH="hppa2.0n" ;;
|
||||
64) HP_ARCH="hppa2.0w" ;;
|
||||
'') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
|
||||
esac ;;
|
||||
esac
|
||||
fi ;;
|
||||
esac
|
||||
if [ "${HP_ARCH}" = "" ]; then
|
||||
eval $set_cc_for_build
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
fi
|
||||
if [ "${HP_ARCH}" = "" ]; then
|
||||
eval $set_cc_for_build
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
|
||||
#define _HPUX_SOURCE
|
||||
#include <stdlib.h>
|
||||
@@ -597,11 +627,21 @@ EOF
|
||||
exit (0);
|
||||
}
|
||||
EOF
|
||||
(CCOPTS= $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null ) && HP_ARCH=`./$dummy`
|
||||
if test -z "$HP_ARCH"; then HP_ARCH=hppa; fi
|
||||
rm -f $dummy.c $dummy
|
||||
fi ;;
|
||||
(CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
|
||||
test -z "$HP_ARCH" && HP_ARCH=hppa
|
||||
fi ;;
|
||||
esac
|
||||
if [ ${HP_ARCH} = "hppa2.0w" ]
|
||||
then
|
||||
# avoid double evaluation of $set_cc_for_build
|
||||
test -n "$CC_FOR_BUILD" || eval $set_cc_for_build
|
||||
if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null
|
||||
then
|
||||
HP_ARCH="hppa2.0w"
|
||||
else
|
||||
HP_ARCH="hppa64"
|
||||
fi
|
||||
fi
|
||||
echo ${HP_ARCH}-hp-hpux${HPUX_REV}
|
||||
exit 0 ;;
|
||||
ia64:HP-UX:*:*)
|
||||
@@ -635,8 +675,7 @@ EOF
|
||||
exit (0);
|
||||
}
|
||||
EOF
|
||||
$CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0
|
||||
rm -f $dummy.c $dummy
|
||||
$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
|
||||
echo unknown-hitachi-hiuxwe2
|
||||
exit 0 ;;
|
||||
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
|
||||
@@ -664,9 +703,6 @@ EOF
|
||||
parisc*:Lites*:*:*)
|
||||
echo hppa1.1-hp-lites
|
||||
exit 0 ;;
|
||||
hppa*:OpenBSD:*:*)
|
||||
echo hppa-unknown-openbsd
|
||||
exit 0 ;;
|
||||
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
|
||||
echo c1-convex-bsd
|
||||
exit 0 ;;
|
||||
@@ -685,9 +721,6 @@ EOF
|
||||
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
|
||||
echo c4-convex-bsd
|
||||
exit 0 ;;
|
||||
CRAY*X-MP:*:*:*)
|
||||
echo xmp-cray-unicos
|
||||
exit 0 ;;
|
||||
CRAY*Y-MP:*:*:*)
|
||||
echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
|
||||
exit 0 ;;
|
||||
@@ -700,26 +733,25 @@ EOF
|
||||
CRAY*TS:*:*:*)
|
||||
echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
|
||||
exit 0 ;;
|
||||
CRAY*T3D:*:*:*)
|
||||
echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
|
||||
exit 0 ;;
|
||||
CRAY*T3E:*:*:*)
|
||||
echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
|
||||
exit 0 ;;
|
||||
CRAY*SV1:*:*:*)
|
||||
echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
|
||||
exit 0 ;;
|
||||
CRAY-2:*:*:*)
|
||||
echo cray2-cray-unicos
|
||||
exit 0 ;;
|
||||
*:UNICOS/mp:*:*)
|
||||
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'`
|
||||
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
|
||||
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
|
||||
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
|
||||
exit 0 ;;
|
||||
hp300:OpenBSD:*:*)
|
||||
echo m68k-unknown-openbsd${UNAME_RELEASE}
|
||||
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}
|
||||
@@ -731,10 +763,21 @@ EOF
|
||||
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:FreeBSD:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
|
||||
exit 0 ;;
|
||||
*:OpenBSD:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
|
||||
# Determine whether the default compiler uses glibc.
|
||||
eval $set_cc_for_build
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
#include <features.h>
|
||||
#if __GLIBC__ >= 2
|
||||
LIBC=gnu
|
||||
#else
|
||||
LIBC=
|
||||
#endif
|
||||
EOF
|
||||
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^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
|
||||
@@ -745,11 +788,17 @@ EOF
|
||||
i*:PW*:*)
|
||||
echo ${UNAME_MACHINE}-pc-pw32
|
||||
exit 0 ;;
|
||||
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
|
||||
exit 0 ;;
|
||||
i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
|
||||
# How do we know it's Interix rather than the generic POSIX subsystem?
|
||||
# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
|
||||
# UNAME_MACHINE based on the output of uname instead of i386?
|
||||
echo i386-pc-interix
|
||||
echo i586-pc-interix
|
||||
exit 0 ;;
|
||||
i*:UWIN*:*)
|
||||
echo ${UNAME_MACHINE}-pc-uwin
|
||||
@@ -761,25 +810,65 @@ 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
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
exit 0 ;;
|
||||
m68*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
exit 0 ;;
|
||||
mips:Linux:*:*)
|
||||
case `sed -n '/^byte/s/^.*: \(.*\) endian/\1/p' < /proc/cpuinfo` in
|
||||
big) echo mips-unknown-linux-gnu && exit 0 ;;
|
||||
little) echo mipsel-unknown-linux-gnu && exit 0 ;;
|
||||
esac
|
||||
eval $set_cc_for_build
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
#undef CPU
|
||||
#undef mips
|
||||
#undef mipsel
|
||||
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
|
||||
CPU=mipsel
|
||||
#else
|
||||
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
|
||||
CPU=mips
|
||||
#else
|
||||
CPU=
|
||||
#endif
|
||||
#endif
|
||||
EOF
|
||||
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
|
||||
test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
|
||||
;;
|
||||
mips64:Linux:*:*)
|
||||
eval $set_cc_for_build
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
#undef CPU
|
||||
#undef mips64
|
||||
#undef mips64el
|
||||
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
|
||||
CPU=mips64el
|
||||
#else
|
||||
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
|
||||
CPU=mips64
|
||||
#else
|
||||
CPU=
|
||||
#endif
|
||||
#endif
|
||||
EOF
|
||||
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
|
||||
test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
|
||||
;;
|
||||
ppc:Linux:*:*)
|
||||
echo powerpc-unknown-linux-gnu
|
||||
@@ -815,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 ;;
|
||||
@@ -828,7 +920,8 @@ EOF
|
||||
# The BFD linker knows what the default object file format is, so
|
||||
# first see if it will tell us. cd to the root directory to prevent
|
||||
# problems with other programs or directories called `ld' in the path.
|
||||
ld_supported_targets=`cd /; ld --help 2>&1 \
|
||||
# Set LC_ALL=C to ensure ld outputs messages in English.
|
||||
ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
|
||||
| sed -ne '/supported targets:/!d
|
||||
s/[ ][ ]*/ /g
|
||||
s/.*supported targets: *//
|
||||
@@ -840,7 +933,7 @@ EOF
|
||||
;;
|
||||
a.out-i386-linux)
|
||||
echo "${UNAME_MACHINE}-pc-linux-gnuaout"
|
||||
exit 0 ;;
|
||||
exit 0 ;;
|
||||
coff-i386)
|
||||
echo "${UNAME_MACHINE}-pc-linux-gnucoff"
|
||||
exit 0 ;;
|
||||
@@ -852,32 +945,31 @@ EOF
|
||||
esac
|
||||
# Determine whether the default compiler is a.out or elf
|
||||
eval $set_cc_for_build
|
||||
cat >$dummy.c <<EOF
|
||||
#include <features.h>
|
||||
#ifdef __cplusplus
|
||||
#include <stdio.h> /* for printf() prototype */
|
||||
int main (int argc, char *argv[]) {
|
||||
#else
|
||||
int main (argc, argv) int argc; char *argv[]; {
|
||||
#endif
|
||||
#ifdef __ELF__
|
||||
# ifdef __GLIBC__
|
||||
# if __GLIBC__ >= 2
|
||||
printf ("%s-pc-linux-gnu\n", argv[1]);
|
||||
# else
|
||||
printf ("%s-pc-linux-gnulibc1\n", argv[1]);
|
||||
# endif
|
||||
# else
|
||||
printf ("%s-pc-linux-gnulibc1\n", argv[1]);
|
||||
# endif
|
||||
#else
|
||||
printf ("%s-pc-linux-gnuaout\n", argv[1]);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
#include <features.h>
|
||||
#ifdef __ELF__
|
||||
# ifdef __GLIBC__
|
||||
# if __GLIBC__ >= 2
|
||||
LIBC=gnu
|
||||
# else
|
||||
LIBC=gnulibc1
|
||||
# endif
|
||||
# else
|
||||
LIBC=gnulibc1
|
||||
# endif
|
||||
#else
|
||||
#ifdef __INTEL_COMPILER
|
||||
LIBC=gnu
|
||||
#else
|
||||
LIBC=gnuaout
|
||||
#endif
|
||||
#endif
|
||||
#ifdef __dietlibc__
|
||||
LIBC=dietlibc
|
||||
#endif
|
||||
EOF
|
||||
$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm -f $dummy.c $dummy && exit 0
|
||||
rm -f $dummy.c $dummy
|
||||
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
|
||||
test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
|
||||
test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
|
||||
;;
|
||||
i*86:DYNIX/ptx:4*:*)
|
||||
@@ -894,6 +986,26 @@ EOF
|
||||
# Use sysv4.2uw... so that sysv4* matches it.
|
||||
echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
|
||||
exit 0 ;;
|
||||
i*86:OS/2:*:*)
|
||||
# If we were able to find `uname', then EMX Unix compatibility
|
||||
# is probably installed.
|
||||
echo ${UNAME_MACHINE}-pc-os2-emx
|
||||
exit 0 ;;
|
||||
i*86:XTS-300:*:STOP)
|
||||
echo ${UNAME_MACHINE}-unknown-stop
|
||||
exit 0 ;;
|
||||
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 ;;
|
||||
i*86:*DOS:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-msdosdjgpp
|
||||
exit 0 ;;
|
||||
i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
|
||||
UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
|
||||
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
|
||||
@@ -915,22 +1027,19 @@ EOF
|
||||
UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
|
||||
echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
|
||||
elif /bin/uname -X 2>/dev/null >/dev/null ; then
|
||||
UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')`
|
||||
(/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486
|
||||
(/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
|
||||
UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
|
||||
(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
|
||||
(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
|
||||
&& UNAME_MACHINE=i586
|
||||
(/bin/uname -X|egrep '^Machine.*Pent ?II' >/dev/null) \
|
||||
(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
|
||||
&& UNAME_MACHINE=i686
|
||||
(/bin/uname -X|egrep '^Machine.*Pentium Pro' >/dev/null) \
|
||||
(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
|
||||
&& UNAME_MACHINE=i686
|
||||
echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
|
||||
else
|
||||
echo ${UNAME_MACHINE}-pc-sysv32
|
||||
fi
|
||||
exit 0 ;;
|
||||
i*86:*DOS:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-msdosdjgpp
|
||||
exit 0 ;;
|
||||
pc:*:*:*)
|
||||
# Left here for compatibility:
|
||||
# uname -m prints for DJGPP always 'pc', but it prints nothing about
|
||||
@@ -954,9 +1063,15 @@ EOF
|
||||
# "miniframe"
|
||||
echo m68010-convergent-sysv
|
||||
exit 0 ;;
|
||||
mc68k:UNIX:SYSTEM5:3.51m)
|
||||
echo m68k-convergent-sysv
|
||||
exit 0 ;;
|
||||
M680?0:D-NIX:5.3:*)
|
||||
echo m68k-diab-dnix
|
||||
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 | 4850:*: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`
|
||||
@@ -973,9 +1088,6 @@ EOF
|
||||
mc68030:UNIX_System_V:4.*:*)
|
||||
echo m68k-atari-sysv4
|
||||
exit 0 ;;
|
||||
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
|
||||
echo i386-unknown-lynxos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
TSUNAMI:LynxOS:2.*:*)
|
||||
echo sparc-unknown-lynxos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
@@ -1047,6 +1159,9 @@ EOF
|
||||
SX-5:SUPER-UX:*:*)
|
||||
echo sx5-nec-superux${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
SX-6:SUPER-UX:*:*)
|
||||
echo sx6-nec-superux${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
Power*:Rhapsody:*:*)
|
||||
echo powerpc-apple-rhapsody${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
@@ -1054,18 +1169,24 @@ EOF
|
||||
echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:Darwin:*:*)
|
||||
echo `uname -p`-apple-darwin${UNAME_RELEASE}
|
||||
case `uname -p` in
|
||||
*86) UNAME_PROCESSOR=i686 ;;
|
||||
powerpc) UNAME_PROCESSOR=powerpc ;;
|
||||
esac
|
||||
echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:procnto*:*:* | *:QNX:[0123456789]*:*)
|
||||
if test "${UNAME_MACHINE}" = "x86pc"; then
|
||||
UNAME_PROCESSOR=`uname -p`
|
||||
if test "$UNAME_PROCESSOR" = "x86"; then
|
||||
UNAME_PROCESSOR=i386
|
||||
UNAME_MACHINE=pc
|
||||
fi
|
||||
echo `uname -p`-${UNAME_MACHINE}-nto-qnx
|
||||
echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:QNX:*:4*)
|
||||
echo i386-pc-qnx
|
||||
exit 0 ;;
|
||||
NSR-[KW]:NONSTOP_KERNEL:*:*)
|
||||
NSR-?:NONSTOP_KERNEL:*:*)
|
||||
echo nsr-tandem-nsk${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:NonStop-UX:*:*)
|
||||
@@ -1088,11 +1209,6 @@ EOF
|
||||
fi
|
||||
echo ${UNAME_MACHINE}-unknown-plan9
|
||||
exit 0 ;;
|
||||
i*86:OS/2:*:*)
|
||||
# If we were able to find `uname', then EMX Unix compatibility
|
||||
# is probably installed.
|
||||
echo ${UNAME_MACHINE}-pc-os2-emx
|
||||
exit 0 ;;
|
||||
*:TOPS-10:*:*)
|
||||
echo pdp10-unknown-tops10
|
||||
exit 0 ;;
|
||||
@@ -1111,11 +1227,11 @@ EOF
|
||||
*:ITS:*:*)
|
||||
echo pdp10-unknown-its
|
||||
exit 0 ;;
|
||||
i*86:XTS-300:*:STOP)
|
||||
echo ${UNAME_MACHINE}-unknown-stop
|
||||
SEI:*:*:SEIUX)
|
||||
echo mips-sei-seiux${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
i*86:atheos:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-atheos
|
||||
*:DRAGONFLY:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-dragonfly${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
esac
|
||||
|
||||
@@ -1237,8 +1353,7 @@ main ()
|
||||
}
|
||||
EOF
|
||||
|
||||
$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm -f $dummy.c $dummy && exit 0
|
||||
rm -f $dummy.c $dummy
|
||||
$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0
|
||||
|
||||
# Apollos put the system type in the environment.
|
||||
|
||||
|
||||
-171
@@ -1,171 +0,0 @@
|
||||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by configure, which was
|
||||
generated by GNU Autoconf 2.52. Invocation command line was
|
||||
|
||||
$ ./configure --disable-static
|
||||
|
||||
## ---------- ##
|
||||
## Platform. ##
|
||||
## ---------- ##
|
||||
|
||||
hostname = alice
|
||||
uname -m = i686
|
||||
uname -r = 2.4.7
|
||||
uname -s = Linux
|
||||
uname -v = #1 Sun Aug 5 19:04:40 CEST 2001
|
||||
|
||||
/usr/bin/uname -p = unknown
|
||||
/bin/uname -X = unknown
|
||||
|
||||
/bin/arch = i686
|
||||
/usr/bin/arch -k = unknown
|
||||
/usr/convex/getsysinfo = unknown
|
||||
hostinfo = unknown
|
||||
/bin/machine = unknown
|
||||
/usr/bin/oslevel = unknown
|
||||
/bin/universe = unknown
|
||||
|
||||
PATH = /home/andy/bin:/usr/local/games:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
|
||||
|
||||
## ------------ ##
|
||||
## Core tests. ##
|
||||
## ------------ ##
|
||||
|
||||
configure:1105: PATH=".;."; conftest.sh
|
||||
./configure: conftest.sh: command not found
|
||||
configure:1108: $? = 127
|
||||
configure:1236: checking build system type
|
||||
configure:1254: result: i686-pc-linux-gnu
|
||||
|
||||
## ----------------- ##
|
||||
## Cache variables. ##
|
||||
## ----------------- ##
|
||||
|
||||
ac_cv_build=i686-pc-linux-gnu
|
||||
ac_cv_build_alias=i686-pc-linux-gnu
|
||||
ac_cv_env_CC_set=
|
||||
ac_cv_env_CC_value=
|
||||
ac_cv_env_CFLAGS_set=
|
||||
ac_cv_env_CFLAGS_value=
|
||||
ac_cv_env_CPPFLAGS_set=
|
||||
ac_cv_env_CPPFLAGS_value=
|
||||
ac_cv_env_CPP_set=
|
||||
ac_cv_env_CPP_value=
|
||||
ac_cv_env_CXXCPP_set=
|
||||
ac_cv_env_CXXCPP_value=
|
||||
ac_cv_env_CXXFLAGS_set=
|
||||
ac_cv_env_CXXFLAGS_value=
|
||||
ac_cv_env_CXX_set=
|
||||
ac_cv_env_CXX_value=
|
||||
ac_cv_env_LDFLAGS_set=
|
||||
ac_cv_env_LDFLAGS_value=
|
||||
ac_cv_env_build_alias_set=
|
||||
ac_cv_env_build_alias_value=
|
||||
ac_cv_env_host_alias_set=
|
||||
ac_cv_env_host_alias_value=
|
||||
ac_cv_env_target_alias_set=
|
||||
ac_cv_env_target_alias_value=
|
||||
|
||||
|
||||
configure: caught signal 2
|
||||
configure: exit 1
|
||||
|
||||
## ----------------------- ##
|
||||
## Running config.status. ##
|
||||
## ----------------------- ##
|
||||
|
||||
This file was extended by config.status 2.52, executed with
|
||||
CONFIG_FILES =
|
||||
CONFIG_HEADERS =
|
||||
CONFIG_LINKS =
|
||||
CONFIG_COMMANDS =
|
||||
> ./config.status
|
||||
on alice
|
||||
|
||||
config.status:14086: creating Makefile
|
||||
|
||||
## ----------------------- ##
|
||||
## Running config.status. ##
|
||||
## ----------------------- ##
|
||||
|
||||
This file was extended by config.status 2.52, executed with
|
||||
CONFIG_FILES =
|
||||
CONFIG_HEADERS =
|
||||
CONFIG_LINKS =
|
||||
CONFIG_COMMANDS =
|
||||
> ./config.status
|
||||
on alice
|
||||
|
||||
config.status:14086: creating Makefile
|
||||
|
||||
## ----------------------- ##
|
||||
## Running config.status. ##
|
||||
## ----------------------- ##
|
||||
|
||||
This file was extended by config.status 2.52, executed with
|
||||
CONFIG_FILES =
|
||||
CONFIG_HEADERS =
|
||||
CONFIG_LINKS =
|
||||
CONFIG_COMMANDS =
|
||||
> ./config.status
|
||||
on alice
|
||||
|
||||
config.status:14086: creating Makefile
|
||||
|
||||
## ----------------------- ##
|
||||
## Running config.status. ##
|
||||
## ----------------------- ##
|
||||
|
||||
This file was extended by config.status 2.52, executed with
|
||||
CONFIG_FILES =
|
||||
CONFIG_HEADERS =
|
||||
CONFIG_LINKS =
|
||||
CONFIG_COMMANDS =
|
||||
> ./config.status
|
||||
on alice
|
||||
|
||||
config.status:14086: creating Makefile
|
||||
|
||||
## ----------------------- ##
|
||||
## Running config.status. ##
|
||||
## ----------------------- ##
|
||||
|
||||
This file was extended by config.status 2.52, executed with
|
||||
CONFIG_FILES =
|
||||
CONFIG_HEADERS =
|
||||
CONFIG_LINKS =
|
||||
CONFIG_COMMANDS =
|
||||
> ./config.status
|
||||
on alice
|
||||
|
||||
config.status:14086: creating Makefile
|
||||
|
||||
## ----------------------- ##
|
||||
## Running config.status. ##
|
||||
## ----------------------- ##
|
||||
|
||||
This file was extended by config.status 2.52, executed with
|
||||
CONFIG_FILES =
|
||||
CONFIG_HEADERS =
|
||||
CONFIG_LINKS =
|
||||
CONFIG_COMMANDS =
|
||||
> ./config.status
|
||||
on alice
|
||||
|
||||
config.status:14086: creating Makefile
|
||||
|
||||
## ----------------------- ##
|
||||
## Running config.status. ##
|
||||
## ----------------------- ##
|
||||
|
||||
This file was extended by config.status 2.52, executed with
|
||||
CONFIG_FILES =
|
||||
CONFIG_HEADERS =
|
||||
CONFIG_LINKS =
|
||||
CONFIG_COMMANDS =
|
||||
> ./config.status
|
||||
on alice
|
||||
|
||||
config.status:14086: creating Makefile
|
||||
-476
@@ -1,476 +0,0 @@
|
||||
#! /bin/sh
|
||||
# Generated automatically by configure.
|
||||
# Run this file to recreate the current configuration.
|
||||
# Compiler output produced by configure, useful for debugging
|
||||
# configure, is in config.log if it exists.
|
||||
|
||||
debug=false
|
||||
SHELL=${CONFIG_SHELL-/bin/sh}
|
||||
ac_cs_invocation="$0 $@"
|
||||
|
||||
# Be Bourne compatible
|
||||
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
|
||||
emulate sh
|
||||
NULLCMD=:
|
||||
elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
|
||||
set -o posix
|
||||
fi
|
||||
|
||||
# Name of the executable.
|
||||
as_me=`echo "$0" |sed 's,.*[\\/],,'`
|
||||
|
||||
if expr a : '\(a\)' >/dev/null 2>&1; then
|
||||
as_expr=expr
|
||||
else
|
||||
as_expr=false
|
||||
fi
|
||||
|
||||
rm -f conf$$ conf$$.exe conf$$.file
|
||||
echo >conf$$.file
|
||||
if ln -s conf$$.file conf$$ 2>/dev/null; then
|
||||
# We could just check for DJGPP; but this test a) works b) is more generic
|
||||
# and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
|
||||
if test -f conf$$.exe; then
|
||||
# Don't use ln at all; we don't have any links
|
||||
as_ln_s='cp -p'
|
||||
else
|
||||
as_ln_s='ln -s'
|
||||
fi
|
||||
elif ln conf$$.file conf$$ 2>/dev/null; then
|
||||
as_ln_s=ln
|
||||
else
|
||||
as_ln_s='cp -p'
|
||||
fi
|
||||
rm -f conf$$ conf$$.exe conf$$.file
|
||||
|
||||
as_executable_p="test -f"
|
||||
|
||||
# Support unset when possible.
|
||||
if (FOO=FOO; unset FOO) >/dev/null 2>&1; then
|
||||
as_unset=unset
|
||||
else
|
||||
as_unset=false
|
||||
fi
|
||||
|
||||
# NLS nuisances.
|
||||
$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; }
|
||||
$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; }
|
||||
$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; }
|
||||
$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; }
|
||||
$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; }
|
||||
$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; }
|
||||
$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; }
|
||||
$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; }
|
||||
|
||||
# IFS
|
||||
# We need space, tab and new line, in precisely that order.
|
||||
as_nl='
|
||||
'
|
||||
IFS=" $as_nl"
|
||||
|
||||
# CDPATH.
|
||||
$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; }
|
||||
|
||||
exec 6>&1
|
||||
|
||||
config_files=" Makefile"
|
||||
|
||||
ac_cs_usage="\
|
||||
\`$as_me' instantiates files from templates according to the
|
||||
current configuration.
|
||||
|
||||
Usage: $0 [OPTIONS] [FILE]...
|
||||
|
||||
-h, --help print this help, then exit
|
||||
-V, --version print version number, then exit
|
||||
-d, --debug don't remove temporary files
|
||||
--recheck update $as_me by reconfiguring in the same conditions
|
||||
--file=FILE[:TEMPLATE]
|
||||
instantiate the configuration file FILE
|
||||
|
||||
Configuration files:
|
||||
$config_files
|
||||
|
||||
Report bugs to <bug-autoconf@gnu.org>."
|
||||
ac_cs_version="\
|
||||
config.status
|
||||
configured by ./configure, generated by GNU Autoconf 2.52,
|
||||
with options \"\"
|
||||
|
||||
Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
|
||||
Free Software Foundation, Inc.
|
||||
This config.status script is free software; the Free Software Foundation
|
||||
gives unlimited permission to copy, distribute and modify it."
|
||||
srcdir=.
|
||||
# If no file are specified by the user, then we need to provide default
|
||||
# value. By we need to know if files were specified by the user.
|
||||
ac_need_defaults=:
|
||||
while test $# != 0
|
||||
do
|
||||
case $1 in
|
||||
--*=*)
|
||||
ac_option=`expr "x$1" : 'x\([^=]*\)='`
|
||||
ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
|
||||
shift
|
||||
set dummy "$ac_option" "$ac_optarg" ${1+"$@"}
|
||||
shift
|
||||
;;
|
||||
-*);;
|
||||
*) # This is not an option, so the user has probably given explicit
|
||||
# arguments.
|
||||
ac_need_defaults=false;;
|
||||
esac
|
||||
|
||||
case $1 in
|
||||
# Handling of the options.
|
||||
-recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
|
||||
echo "running /bin/sh ./configure " " --no-create --no-recursion"
|
||||
exec /bin/sh ./configure --no-create --no-recursion ;;
|
||||
--version | --vers* | -V )
|
||||
echo "$ac_cs_version"; exit 0 ;;
|
||||
--he | --h)
|
||||
# Conflict between --help and --header
|
||||
{ { echo "$as_me:13794: error: ambiguous option: $1
|
||||
Try \`$0 --help' for more information." >&5
|
||||
echo "$as_me: error: ambiguous option: $1
|
||||
Try \`$0 --help' for more information." >&2;}
|
||||
{ (exit 1); exit 1; }; };;
|
||||
--help | --hel | -h )
|
||||
echo "$ac_cs_usage"; exit 0 ;;
|
||||
--debug | --d* | -d )
|
||||
debug=: ;;
|
||||
--file | --fil | --fi | --f )
|
||||
shift
|
||||
CONFIG_FILES="$CONFIG_FILES $1"
|
||||
ac_need_defaults=false;;
|
||||
--header | --heade | --head | --hea )
|
||||
shift
|
||||
CONFIG_HEADERS="$CONFIG_HEADERS $1"
|
||||
ac_need_defaults=false;;
|
||||
|
||||
# This is an error.
|
||||
-*) { { echo "$as_me:13813: error: unrecognized option: $1
|
||||
Try \`$0 --help' for more information." >&5
|
||||
echo "$as_me: error: unrecognized option: $1
|
||||
Try \`$0 --help' for more information." >&2;}
|
||||
{ (exit 1); exit 1; }; } ;;
|
||||
|
||||
*) ac_config_targets="$ac_config_targets $1" ;;
|
||||
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
exec 5>>config.log
|
||||
cat >&5 << _ACEOF
|
||||
|
||||
## ----------------------- ##
|
||||
## Running config.status. ##
|
||||
## ----------------------- ##
|
||||
|
||||
This file was extended by $as_me 2.52, executed with
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
CONFIG_HEADERS = $CONFIG_HEADERS
|
||||
CONFIG_LINKS = $CONFIG_LINKS
|
||||
CONFIG_COMMANDS = $CONFIG_COMMANDS
|
||||
> $ac_cs_invocation
|
||||
on `(hostname || uname -n) 2>/dev/null | sed 1q`
|
||||
|
||||
_ACEOF
|
||||
for ac_config_target in $ac_config_targets
|
||||
do
|
||||
case "$ac_config_target" in
|
||||
# Handling of arguments.
|
||||
"Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
|
||||
*) { { echo "$as_me:13849: error: invalid argument: $ac_config_target" >&5
|
||||
echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
|
||||
{ (exit 1); exit 1; }; };;
|
||||
esac
|
||||
done
|
||||
|
||||
# If the user did not use the arguments to specify the items to instantiate,
|
||||
# then the envvar interface is used. Set only those that are not.
|
||||
# We use the long form for the default assignment because of an extremely
|
||||
# bizarre bug on SunOS 4.1.3.
|
||||
if $ac_need_defaults; then
|
||||
test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
|
||||
fi
|
||||
|
||||
# Create a temporary directory, and hook for its removal unless debugging.
|
||||
$debug ||
|
||||
{
|
||||
trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0
|
||||
trap '{ (exit 1); exit 1; }' 1 2 13 15
|
||||
}
|
||||
|
||||
# Create a (secure) tmp directory for tmp files.
|
||||
: ${TMPDIR=/tmp}
|
||||
{
|
||||
tmp=`(umask 077 && mktemp -d -q "$TMPDIR/csXXXXXX") 2>/dev/null` &&
|
||||
test -n "$tmp" && test -d "$tmp"
|
||||
} ||
|
||||
{
|
||||
tmp=$TMPDIR/cs$$-$RANDOM
|
||||
(umask 077 && mkdir $tmp)
|
||||
} ||
|
||||
{
|
||||
echo "$me: cannot create a temporary directory in $TMPDIR" >&2
|
||||
{ (exit 1); exit 1; }
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# CONFIG_FILES section.
|
||||
#
|
||||
|
||||
# No need to generate the scripts if there are no CONFIG_FILES.
|
||||
# This happens for instance when ./config.status config.h
|
||||
if test -n "$CONFIG_FILES"; then
|
||||
# Protect against being on the right side of a sed subst in config.status.
|
||||
sed 's/,@/@@/; s/@,/@@/; s/,;t t$/@;t t/; /@;t t$/s/[\\&,]/\\&/g;
|
||||
s/@@/,@/; s/@@/@,/; s/@;t t$/,;t t/' >$tmp/subs.sed <<\CEOF
|
||||
s,@SHELL@,/bin/sh,;t t
|
||||
s,@exec_prefix@,${prefix},;t t
|
||||
s,@prefix@,/usr/local,;t t
|
||||
s,@program_transform_name@,s,x,x,,;t t
|
||||
s,@bindir@,${exec_prefix}/bin,;t t
|
||||
s,@sbindir@,${exec_prefix}/sbin,;t t
|
||||
s,@libexecdir@,${exec_prefix}/libexec,;t t
|
||||
s,@datadir@,${prefix}/share,;t t
|
||||
s,@sysconfdir@,${prefix}/etc,;t t
|
||||
s,@sharedstatedir@,${prefix}/com,;t t
|
||||
s,@localstatedir@,${prefix}/var,;t t
|
||||
s,@libdir@,${exec_prefix}/lib,;t t
|
||||
s,@includedir@,${prefix}/include,;t t
|
||||
s,@oldincludedir@,/usr/include,;t t
|
||||
s,@infodir@,${prefix}/info,;t t
|
||||
s,@mandir@,${prefix}/man,;t t
|
||||
s,@PACKAGE_NAME@,,;t t
|
||||
s,@PACKAGE_TARNAME@,,;t t
|
||||
s,@PACKAGE_VERSION@,,;t t
|
||||
s,@PACKAGE_STRING@,,;t t
|
||||
s,@PACKAGE_BUGREPORT@,,;t t
|
||||
s,@build_alias@,,;t t
|
||||
s,@host_alias@,,;t t
|
||||
s,@target_alias@,,;t t
|
||||
s,@ECHO_C@,,;t t
|
||||
s,@ECHO_N@,-n,;t t
|
||||
s,@ECHO_T@,,;t t
|
||||
s,@PATH_SEPARATOR@,:,;t t
|
||||
s,@DEFS@,-DHAVE_DLFCN_H=1 -DHAVE_LIBDL=1 ,;t t
|
||||
s,@LIBS@,-lreadline ,;t t
|
||||
s,@build@,i686-pc-linux-gnu,;t t
|
||||
s,@build_cpu@,i686,;t t
|
||||
s,@build_vendor@,pc,;t t
|
||||
s,@build_os@,linux-gnu,;t t
|
||||
s,@host@,alice,;t t
|
||||
s,@host_cpu@,i686,;t t
|
||||
s,@host_vendor@,pc,;t t
|
||||
s,@host_os@,linux-gnu,;t t
|
||||
s,@CC@,gcc,;t t
|
||||
s,@CFLAGS@,-g -O2,;t t
|
||||
s,@LDFLAGS@,,;t t
|
||||
s,@CPPFLAGS@,,;t t
|
||||
s,@ac_ct_CC@,gcc,;t t
|
||||
s,@EXEEXT@,,;t t
|
||||
s,@OBJEXT@,o,;t t
|
||||
s,@LN_S@,ln -s,;t t
|
||||
s,@ECHO@,echo,;t t
|
||||
s,@RANLIB@,ranlib,;t t
|
||||
s,@ac_ct_RANLIB@,ranlib,;t t
|
||||
s,@STRIP@,strip,;t t
|
||||
s,@ac_ct_STRIP@,strip,;t t
|
||||
s,@CPP@,gcc -E,;t t
|
||||
s,@CXX@,g++,;t t
|
||||
s,@CXXFLAGS@,-g -O2,;t t
|
||||
s,@ac_ct_CXX@,g++,;t t
|
||||
s,@CXXCPP@,g++ -E,;t t
|
||||
s,@LIBTOOL@,$(SHELL) $(top_builddir)/libtool,;t t
|
||||
s,@program_prefix@,,;t t
|
||||
s,@BUILD_CC@,gcc,;t t
|
||||
s,@BUILD_CFLAGS@,-g -O2,;t t
|
||||
s,@BUILD_LIBS@,,;t t
|
||||
s,@TARGET_CC@,gcc,;t t
|
||||
s,@TARGET_CFLAGS@,-g -O2 -DOS_UNIX=1 -DOS_WIN=0 -DHAVE_USLEEP=1,;t t
|
||||
s,@TARGET_LINK@,gcc,;t t
|
||||
s,@TARGET_LFLAGS@,,;t t
|
||||
s,@TARGET_RANLIB@,ranlib,;t t
|
||||
s,@TARGET_AR@,ar cr,;t t
|
||||
s,@ENCODING@,ISO8859,;t t
|
||||
s,@BUILD_EXEEXT@,,;t t
|
||||
s,@OS_UNIX@,1,;t t
|
||||
s,@OS_WIN@,0,;t t
|
||||
s,@TARGET_EXEEXT@,,;t t
|
||||
s,@TARGET_LIBS@,,;t t
|
||||
s,@TARGET_TCL_LIBS@,-ltcl8.3 -ldl -lm,;t t
|
||||
s,@TARGET_TCL_INC@,-I/usr/include/tcl8.3/,;t t
|
||||
s,@TARGET_READLINE_LIBS@,-lreadline ,;t t
|
||||
s,@TARGET_READLINE_INC@,-I/usr/include/readline,;t t
|
||||
s,@TARGET_HAVE_READLINE@,1,;t t
|
||||
CEOF
|
||||
|
||||
# Split the substitutions into bite-sized pieces for seds with
|
||||
# small command number limits, like on Digital OSF/1 and HP-UX.
|
||||
ac_max_sed_lines=48
|
||||
ac_sed_frag=1 # Number of current file.
|
||||
ac_beg=1 # First line for current file.
|
||||
ac_end=$ac_max_sed_lines # Line after last line for current file.
|
||||
ac_more_lines=:
|
||||
ac_sed_cmds=
|
||||
while $ac_more_lines; do
|
||||
if test $ac_beg -gt 1; then
|
||||
sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
|
||||
else
|
||||
sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
|
||||
fi
|
||||
if test ! -s $tmp/subs.frag; then
|
||||
ac_more_lines=false
|
||||
else
|
||||
# The purpose of the label and of the branching condition is to
|
||||
# speed up the sed processing (if there are no `@' at all, there
|
||||
# is no need to browse any of the substitutions).
|
||||
# These are the two extra sed commands mentioned above.
|
||||
(echo ':t
|
||||
/@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed
|
||||
if test -z "$ac_sed_cmds"; then
|
||||
ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed"
|
||||
else
|
||||
ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed"
|
||||
fi
|
||||
ac_sed_frag=`expr $ac_sed_frag + 1`
|
||||
ac_beg=$ac_end
|
||||
ac_end=`expr $ac_end + $ac_max_sed_lines`
|
||||
fi
|
||||
done
|
||||
if test -z "$ac_sed_cmds"; then
|
||||
ac_sed_cmds=cat
|
||||
fi
|
||||
fi # test -n "$CONFIG_FILES"
|
||||
|
||||
for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue
|
||||
# Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
|
||||
case $ac_file in
|
||||
- | *:- | *:-:* ) # input from stdin
|
||||
cat >$tmp/stdin
|
||||
ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
|
||||
ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
|
||||
*:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
|
||||
ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
|
||||
* ) ac_file_in=$ac_file.in ;;
|
||||
esac
|
||||
|
||||
# Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories.
|
||||
ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
|
||||
X"$ac_file" : 'X\(//\)[^/]' \| \
|
||||
X"$ac_file" : 'X\(//\)$' \| \
|
||||
X"$ac_file" : 'X\(/\)' \| \
|
||||
. : '\(.\)' 2>/dev/null ||
|
||||
echo X"$ac_file" |
|
||||
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
|
||||
/^X\(\/\/\)[^/].*/{ s//\1/; q; }
|
||||
/^X\(\/\/\)$/{ s//\1/; q; }
|
||||
/^X\(\/\).*/{ s//\1/; q; }
|
||||
s/.*/./; q'`
|
||||
if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
|
||||
{ case "$ac_dir" in
|
||||
[\\/]* | ?:[\\/]* ) as_incr_dir=;;
|
||||
*) as_incr_dir=.;;
|
||||
esac
|
||||
as_dummy="$ac_dir"
|
||||
for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do
|
||||
case $as_mkdir_dir in
|
||||
# Skip DOS drivespec
|
||||
?:) as_incr_dir=$as_mkdir_dir ;;
|
||||
*)
|
||||
as_incr_dir=$as_incr_dir/$as_mkdir_dir
|
||||
test -d "$as_incr_dir" || mkdir "$as_incr_dir"
|
||||
;;
|
||||
esac
|
||||
done; }
|
||||
|
||||
ac_dir_suffix="/`echo $ac_dir|sed 's,^\./,,'`"
|
||||
# A "../" for each directory in $ac_dir_suffix.
|
||||
ac_dots=`echo "$ac_dir_suffix" | sed 's,/[^/]*,../,g'`
|
||||
else
|
||||
ac_dir_suffix= ac_dots=
|
||||
fi
|
||||
|
||||
case $srcdir in
|
||||
.) ac_srcdir=.
|
||||
if test -z "$ac_dots"; then
|
||||
ac_top_srcdir=.
|
||||
else
|
||||
ac_top_srcdir=`echo $ac_dots | sed 's,/$,,'`
|
||||
fi ;;
|
||||
[\\/]* | ?:[\\/]* )
|
||||
ac_srcdir=$srcdir$ac_dir_suffix;
|
||||
ac_top_srcdir=$srcdir ;;
|
||||
*) # Relative path.
|
||||
ac_srcdir=$ac_dots$srcdir$ac_dir_suffix
|
||||
ac_top_srcdir=$ac_dots$srcdir ;;
|
||||
esac
|
||||
|
||||
if test x"$ac_file" != x-; then
|
||||
{ echo "$as_me:14086: creating $ac_file" >&5
|
||||
echo "$as_me: creating $ac_file" >&6;}
|
||||
rm -f "$ac_file"
|
||||
fi
|
||||
# Let's still pretend it is `configure' which instantiates (i.e., don't
|
||||
# use $as_me), people would be surprised to read:
|
||||
# /* config.h. Generated automatically by config.status. */
|
||||
configure_input="Generated automatically from `echo $ac_file_in |
|
||||
sed 's,.*/,,'` by configure."
|
||||
|
||||
# First look for the input files in the build tree, otherwise in the
|
||||
# src tree.
|
||||
ac_file_inputs=`IFS=:
|
||||
for f in $ac_file_in; do
|
||||
case $f in
|
||||
-) echo $tmp/stdin ;;
|
||||
[\\/$]*)
|
||||
# Absolute (can't be DOS-style, as IFS=:)
|
||||
test -f "$f" || { { echo "$as_me:14104: error: cannot find input file: $f" >&5
|
||||
echo "$as_me: error: cannot find input file: $f" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
echo $f;;
|
||||
*) # Relative
|
||||
if test -f "$f"; then
|
||||
# Build tree
|
||||
echo $f
|
||||
elif test -f "$srcdir/$f"; then
|
||||
# Source tree
|
||||
echo $srcdir/$f
|
||||
else
|
||||
# /dev/null tree
|
||||
{ { echo "$as_me:14117: error: cannot find input file: $f" >&5
|
||||
echo "$as_me: error: cannot find input file: $f" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
fi;;
|
||||
esac
|
||||
done` || { (exit 1); exit 1; }
|
||||
sed "/^[ ]*VPATH[ ]*=/{
|
||||
s/:*\$(srcdir):*/:/;
|
||||
s/:*\${srcdir}:*/:/;
|
||||
s/:*@srcdir@:*/:/;
|
||||
s/^\([^=]*=[ ]*\):*/\1/;
|
||||
s/:*$//;
|
||||
s/^[^=]*=[ ]*$//;
|
||||
}
|
||||
|
||||
:t
|
||||
/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
|
||||
s,@configure_input@,$configure_input,;t t
|
||||
s,@srcdir@,$ac_srcdir,;t t
|
||||
s,@top_srcdir@,$ac_top_srcdir,;t t
|
||||
" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out
|
||||
rm -f $tmp/stdin
|
||||
if test x"$ac_file" != x-; then
|
||||
mv $tmp/out $ac_file
|
||||
else
|
||||
cat $tmp/out
|
||||
rm -f $tmp/out
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
{ (exit 0); exit 0; }
|
||||
Vendored
+233
-107
@@ -1,9 +1,9 @@
|
||||
#! /bin/sh
|
||||
# Configuration validation subroutine script.
|
||||
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
|
||||
# Free Software Foundation, Inc.
|
||||
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
|
||||
# 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
|
||||
timestamp='2001-09-07'
|
||||
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
|
||||
@@ -29,7 +29,8 @@ timestamp='2001-09-07'
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# Please send patches to <config-patches@gnu.org>.
|
||||
# Please send patches to <config-patches@gnu.org>. Submit a context
|
||||
# diff and a properly formatted ChangeLog entry.
|
||||
#
|
||||
# Configuration subroutine to validate and canonicalize a configuration type.
|
||||
# Supply the specified configuration type as an argument.
|
||||
@@ -117,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* | storm-chaos* | os2-emx* | windows32-*)
|
||||
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/'`
|
||||
;;
|
||||
@@ -226,32 +228,46 @@ case $basic_machine in
|
||||
1750a | 580 \
|
||||
| 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 \
|
||||
| c4x | clipper \
|
||||
| d10v | d30v | dsp16xx \
|
||||
| fr30 \
|
||||
| d10v | d30v | dlx | dsp16xx \
|
||||
| fr30 | frv \
|
||||
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
|
||||
| i370 | i860 | i960 | ia64 \
|
||||
| ip2k | iq2000 \
|
||||
| m32r | m68000 | m68k | m88k | mcore \
|
||||
| mips16 | mips64 | mips64el | mips64orion | mips64orionel \
|
||||
| mips64vr4100 | mips64vr4100el | mips64vr4300 \
|
||||
| mips64vr4300el | mips64vr5000 | mips64vr5000el \
|
||||
| mipsbe | mipseb | mipsel | mipsle | mipstx39 | mipstx39el \
|
||||
| mipsisa32 \
|
||||
| mips | mipsbe | mipseb | mipsel | mipsle \
|
||||
| mips16 \
|
||||
| mips64 | mips64el \
|
||||
| mips64vr | mips64vrel \
|
||||
| mips64orion | mips64orionel \
|
||||
| mips64vr4100 | mips64vr4100el \
|
||||
| mips64vr4300 | mips64vr4300el \
|
||||
| mips64vr5000 | mips64vr5000el \
|
||||
| mipsisa32 | mipsisa32el \
|
||||
| mipsisa32r2 | mipsisa32r2el \
|
||||
| mipsisa64 | mipsisa64el \
|
||||
| mipsisa64r2 | mipsisa64r2el \
|
||||
| mipsisa64sb1 | mipsisa64sb1el \
|
||||
| mipsisa64sr71k | mipsisa64sr71kel \
|
||||
| mipstx39 | mipstx39el \
|
||||
| mn10200 | mn10300 \
|
||||
| msp430 \
|
||||
| ns16k | ns32k \
|
||||
| openrisc \
|
||||
| openrisc | or32 \
|
||||
| pdp10 | pdp11 | pj | pjl \
|
||||
| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
|
||||
| pyramid \
|
||||
| s390 | s390x \
|
||||
| sh | sh[34] | sh[34]eb | shbe | shle \
|
||||
| sparc | sparc64 | sparclet | sparclite | sparcv9 | sparcv9b \
|
||||
| stormy16 | strongarm \
|
||||
| tahoe | thumb | tic80 | tron \
|
||||
| v850 \
|
||||
| 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 | tic4x | tic80 | tron \
|
||||
| v850 | v850e \
|
||||
| we32k \
|
||||
| x86 | xscale \
|
||||
| x86 | xscale | xstormy16 | xtensa \
|
||||
| z8k)
|
||||
basic_machine=$basic_machine-unknown
|
||||
;;
|
||||
@@ -278,38 +294,56 @@ case $basic_machine in
|
||||
580-* \
|
||||
| a29k-* \
|
||||
| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
|
||||
| alphapca5[67]-* | arc-* \
|
||||
| arm-* | armbe-* | armle-* | armv*-* \
|
||||
| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
|
||||
| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
|
||||
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \
|
||||
| avr-* \
|
||||
| bs2000-* \
|
||||
| c[123]* | c30-* | [cjt]90-* | c54x-* \
|
||||
| clipper-* | cray2-* | cydra-* \
|
||||
| d10v-* | d30v-* \
|
||||
| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
|
||||
| clipper-* | cydra-* \
|
||||
| d10v-* | d30v-* | dlx-* \
|
||||
| elxsi-* \
|
||||
| f30[01]-* | f700-* | fr30-* | fx80-* \
|
||||
| f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \
|
||||
| h8300-* | h8500-* \
|
||||
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
|
||||
| i*86-* | i860-* | i960-* | ia64-* \
|
||||
| ip2k-* | iq2000-* \
|
||||
| m32r-* \
|
||||
| m68000-* | m680[01234]0-* | m68360-* | m683?2-* | m68k-* \
|
||||
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
|
||||
| m88110-* | m88k-* | mcore-* \
|
||||
| mips-* | mips16-* | mips64-* | mips64el-* | mips64orion-* \
|
||||
| mips64orionel-* | mips64vr4100-* | mips64vr4100el-* \
|
||||
| mips64vr4300-* | mips64vr4300el-* | mipsbe-* | mipseb-* \
|
||||
| mipsle-* | mipsel-* | mipstx39-* | mipstx39el-* \
|
||||
| none-* | np1-* | ns16k-* | ns32k-* \
|
||||
| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
|
||||
| mips16-* \
|
||||
| mips64-* | mips64el-* \
|
||||
| mips64vr-* | mips64vrel-* \
|
||||
| mips64orion-* | mips64orionel-* \
|
||||
| mips64vr4100-* | mips64vr4100el-* \
|
||||
| mips64vr4300-* | mips64vr4300el-* \
|
||||
| mips64vr5000-* | mips64vr5000el-* \
|
||||
| mipsisa32-* | mipsisa32el-* \
|
||||
| mipsisa32r2-* | mipsisa32r2el-* \
|
||||
| mipsisa64-* | mipsisa64el-* \
|
||||
| mipsisa64r2-* | mipsisa64r2el-* \
|
||||
| mipsisa64sb1-* | mipsisa64sb1el-* \
|
||||
| mipsisa64sr71k-* | mipsisa64sr71kel-* \
|
||||
| mipstx39-* | mipstx39el-* \
|
||||
| msp430-* \
|
||||
| none-* | np1-* | nv1-* | ns16k-* | ns32k-* \
|
||||
| orion-* \
|
||||
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
|
||||
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
|
||||
| pyramid-* \
|
||||
| romp-* | rs6000-* \
|
||||
| s390-* | s390x-* \
|
||||
| sh-* | sh[34]-* | sh[34]eb-* | shbe-* | shle-* \
|
||||
| sparc-* | sparc64-* | sparc86x-* | sparclite-* \
|
||||
| sparcv9-* | sparcv9b-* | stormy16-* | strongarm-* | sv1-* \
|
||||
| t3e-* | tahoe-* | thumb-* | tic30-* | tic54x-* | tic80-* | tron-* \
|
||||
| v850-* | vax-* \
|
||||
| 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-* | tic55x-* | tic6x-* | tic80-* \
|
||||
| tron-* \
|
||||
| v850-* | v850e-* | vax-* \
|
||||
| we32k-* \
|
||||
| x86-* | x86_64-* | xmp-* | xps100-* | xscale-* \
|
||||
| x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \
|
||||
| xtensa-* \
|
||||
| ymp-* \
|
||||
| z8k-*)
|
||||
;;
|
||||
@@ -343,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
|
||||
@@ -374,6 +414,10 @@ case $basic_machine in
|
||||
basic_machine=ns32k-sequent
|
||||
os=-dynix
|
||||
;;
|
||||
c90)
|
||||
basic_machine=c90-cray
|
||||
os=-unicos
|
||||
;;
|
||||
convex-c1)
|
||||
basic_machine=c1-convex
|
||||
os=-bsd
|
||||
@@ -394,16 +438,8 @@ case $basic_machine in
|
||||
basic_machine=c38-convex
|
||||
os=-bsd
|
||||
;;
|
||||
cray | ymp)
|
||||
basic_machine=ymp-cray
|
||||
os=-unicos
|
||||
;;
|
||||
cray2)
|
||||
basic_machine=cray2-cray
|
||||
os=-unicos
|
||||
;;
|
||||
[cjt]90)
|
||||
basic_machine=${basic_machine}-cray
|
||||
cray | j90)
|
||||
basic_machine=j90-cray
|
||||
os=-unicos
|
||||
;;
|
||||
crds | unos)
|
||||
@@ -418,6 +454,14 @@ case $basic_machine in
|
||||
decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
|
||||
basic_machine=mips-dec
|
||||
;;
|
||||
decsystem10* | dec10*)
|
||||
basic_machine=pdp10-dec
|
||||
os=-tops10
|
||||
;;
|
||||
decsystem20* | dec20*)
|
||||
basic_machine=pdp10-dec
|
||||
os=-tops20
|
||||
;;
|
||||
delta | 3300 | motorola-3300 | motorola-delta \
|
||||
| 3300-motorola | delta-motorola)
|
||||
basic_machine=m68k-motorola
|
||||
@@ -598,14 +642,6 @@ case $basic_machine in
|
||||
basic_machine=m68k-atari
|
||||
os=-mint
|
||||
;;
|
||||
mipsel*-linux*)
|
||||
basic_machine=mipsel-unknown
|
||||
os=-linux-gnu
|
||||
;;
|
||||
mips*-linux*)
|
||||
basic_machine=mips-unknown
|
||||
os=-linux-gnu
|
||||
;;
|
||||
mips3*-*)
|
||||
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
|
||||
;;
|
||||
@@ -620,6 +656,10 @@ case $basic_machine in
|
||||
basic_machine=m68k-rom68k
|
||||
os=-coff
|
||||
;;
|
||||
morphos)
|
||||
basic_machine=powerpc-unknown
|
||||
os=-morphos
|
||||
;;
|
||||
msdos)
|
||||
basic_machine=i386-pc
|
||||
os=-msdos
|
||||
@@ -692,6 +732,10 @@ case $basic_machine in
|
||||
np1)
|
||||
basic_machine=np1-gould
|
||||
;;
|
||||
nv1)
|
||||
basic_machine=nv1-cray
|
||||
os=-unicosmp
|
||||
;;
|
||||
nsr-tandem)
|
||||
basic_machine=nsr-tandem
|
||||
;;
|
||||
@@ -699,6 +743,14 @@ case $basic_machine in
|
||||
basic_machine=hppa1.1-oki
|
||||
os=-proelf
|
||||
;;
|
||||
or32 | or32-*)
|
||||
basic_machine=or32-unknown
|
||||
os=-coff
|
||||
;;
|
||||
os400)
|
||||
basic_machine=powerpc-ibm
|
||||
os=-os400
|
||||
;;
|
||||
OSE68000 | ose68000)
|
||||
basic_machine=m68000-ericsson
|
||||
os=-ose
|
||||
@@ -721,49 +773,55 @@ case $basic_machine in
|
||||
pbb)
|
||||
basic_machine=m68k-tti
|
||||
;;
|
||||
pc532 | pc532-*)
|
||||
pc532 | pc532-*)
|
||||
basic_machine=ns32k-pc532
|
||||
;;
|
||||
pentium | p5 | k5 | k6 | nexgen)
|
||||
pentium | p5 | k5 | k6 | nexgen | viac3)
|
||||
basic_machine=i586-pc
|
||||
;;
|
||||
pentiumpro | p6 | 6x86 | athlon)
|
||||
pentiumpro | p6 | 6x86 | athlon | athlon_*)
|
||||
basic_machine=i686-pc
|
||||
;;
|
||||
pentiumii | pentium2)
|
||||
pentiumii | pentium2 | pentiumiii | pentium3)
|
||||
basic_machine=i686-pc
|
||||
;;
|
||||
pentium-* | p5-* | k5-* | k6-* | nexgen-*)
|
||||
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
|
||||
;;
|
||||
power) basic_machine=power-ibm
|
||||
;;
|
||||
ppc) basic_machine=powerpc-unknown
|
||||
;;
|
||||
;;
|
||||
ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
ppcle | powerpclittle | ppc-le | powerpc-little)
|
||||
basic_machine=powerpcle-unknown
|
||||
;;
|
||||
;;
|
||||
ppcle-* | powerpclittle-*)
|
||||
basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
ppc64) basic_machine=powerpc64-unknown
|
||||
;;
|
||||
;;
|
||||
ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
ppc64le | powerpc64little | ppc64-le | powerpc64-little)
|
||||
basic_machine=powerpc64le-unknown
|
||||
;;
|
||||
;;
|
||||
ppc64le-* | powerpc64little-*)
|
||||
basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
@@ -784,10 +842,26 @@ case $basic_machine in
|
||||
rtpc | rtpc-*)
|
||||
basic_machine=romp-ibm
|
||||
;;
|
||||
s390 | s390-*)
|
||||
basic_machine=s390-ibm
|
||||
;;
|
||||
s390x | s390x-*)
|
||||
basic_machine=s390x-ibm
|
||||
;;
|
||||
sa29200)
|
||||
basic_machine=a29k-amd
|
||||
os=-udi
|
||||
;;
|
||||
sb1)
|
||||
basic_machine=mipsisa64sb1-unknown
|
||||
;;
|
||||
sb1el)
|
||||
basic_machine=mipsisa64sb1el-unknown
|
||||
;;
|
||||
sei)
|
||||
basic_machine=mips-sei
|
||||
os=-seiux
|
||||
;;
|
||||
sequent)
|
||||
basic_machine=i386-sequent
|
||||
;;
|
||||
@@ -795,7 +869,10 @@ case $basic_machine in
|
||||
basic_machine=sh-hitachi
|
||||
os=-hms
|
||||
;;
|
||||
sparclite-wrs)
|
||||
sh64)
|
||||
basic_machine=sh64-unknown
|
||||
;;
|
||||
sparclite-wrs | simso-wrs)
|
||||
basic_machine=sparclite-wrs
|
||||
os=-vxworks
|
||||
;;
|
||||
@@ -862,22 +939,42 @@ case $basic_machine in
|
||||
os=-dynix
|
||||
;;
|
||||
t3e)
|
||||
basic_machine=t3e-cray
|
||||
basic_machine=alphaev5-cray
|
||||
os=-unicos
|
||||
;;
|
||||
t90)
|
||||
basic_machine=t90-cray
|
||||
os=-unicos
|
||||
;;
|
||||
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
|
||||
;;
|
||||
tx39el)
|
||||
basic_machine=mipstx39el-unknown
|
||||
;;
|
||||
toad1)
|
||||
basic_machine=pdp10-xkl
|
||||
os=-tops20
|
||||
;;
|
||||
tower | tower-32)
|
||||
basic_machine=m68k-ncr
|
||||
;;
|
||||
tpf)
|
||||
basic_machine=s390x-ibm
|
||||
os=-tpf
|
||||
;;
|
||||
udi29k)
|
||||
basic_machine=a29k-amd
|
||||
os=-udi
|
||||
@@ -899,8 +996,8 @@ case $basic_machine in
|
||||
os=-vms
|
||||
;;
|
||||
vpp*|vx|vx-*)
|
||||
basic_machine=f301-fujitsu
|
||||
;;
|
||||
basic_machine=f301-fujitsu
|
||||
;;
|
||||
vxworks960)
|
||||
basic_machine=i960-wrs
|
||||
os=-vxworks
|
||||
@@ -921,17 +1018,13 @@ case $basic_machine in
|
||||
basic_machine=hppa1.1-winbond
|
||||
os=-proelf
|
||||
;;
|
||||
windows32)
|
||||
basic_machine=i386-pc
|
||||
os=-windows32-msvcrt
|
||||
;;
|
||||
xmp)
|
||||
basic_machine=xmp-cray
|
||||
os=-unicos
|
||||
;;
|
||||
xps | xps100)
|
||||
xps | xps100)
|
||||
basic_machine=xps100-honeywell
|
||||
;;
|
||||
ymp)
|
||||
basic_machine=ymp-cray
|
||||
os=-unicos
|
||||
;;
|
||||
z8k-*-coff)
|
||||
basic_machine=z8k-unknown
|
||||
os=-sim
|
||||
@@ -952,13 +1045,6 @@ case $basic_machine in
|
||||
op60c)
|
||||
basic_machine=hppa1.1-oki
|
||||
;;
|
||||
mips)
|
||||
if [ x$os = x-linux-gnu ]; then
|
||||
basic_machine=mips-unknown
|
||||
else
|
||||
basic_machine=mips-mips
|
||||
fi
|
||||
;;
|
||||
romp)
|
||||
basic_machine=romp-ibm
|
||||
;;
|
||||
@@ -978,13 +1064,16 @@ case $basic_machine in
|
||||
we32k)
|
||||
basic_machine=we32k-att
|
||||
;;
|
||||
sh3 | sh4 | sh3eb | sh4eb)
|
||||
sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele)
|
||||
basic_machine=sh-unknown
|
||||
;;
|
||||
sh64)
|
||||
basic_machine=sh64-unknown
|
||||
;;
|
||||
sparc | sparcv9 | sparcv9b)
|
||||
basic_machine=sparc-sun
|
||||
;;
|
||||
cydra)
|
||||
cydra)
|
||||
basic_machine=cydra-cydrome
|
||||
;;
|
||||
orion)
|
||||
@@ -999,10 +1088,6 @@ case $basic_machine in
|
||||
pmac | pmac-mpw)
|
||||
basic_machine=powerpc-apple
|
||||
;;
|
||||
c4x*)
|
||||
basic_machine=c4x-none
|
||||
os=-coff
|
||||
;;
|
||||
*-unknown)
|
||||
# Make sure to match an already-canonicalized machine name.
|
||||
;;
|
||||
@@ -1058,17 +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* \
|
||||
| -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \
|
||||
| -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*)
|
||||
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
|
||||
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
|
||||
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly*)
|
||||
# Remember, each alternative MUST END IN *, to match a version number.
|
||||
;;
|
||||
-qnx*)
|
||||
@@ -1080,8 +1167,10 @@ case $os in
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
-nto-qnx*)
|
||||
;;
|
||||
-nto*)
|
||||
os=-nto-qnx
|
||||
os=`echo $os | sed -e 's|nto|nto-qnx|'`
|
||||
;;
|
||||
-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
|
||||
| -windows* | -osx | -abug | -netware* | -os9* | -beos* \
|
||||
@@ -1090,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|'`
|
||||
;;
|
||||
@@ -1102,6 +1194,9 @@ case $os in
|
||||
-opened*)
|
||||
os=-openedition
|
||||
;;
|
||||
-os400*)
|
||||
os=-os400
|
||||
;;
|
||||
-wince*)
|
||||
os=-wince
|
||||
;;
|
||||
@@ -1120,14 +1215,23 @@ case $os in
|
||||
-acis*)
|
||||
os=-aos
|
||||
;;
|
||||
-atheos*)
|
||||
os=-atheos
|
||||
;;
|
||||
-syllable*)
|
||||
os=-syllable
|
||||
;;
|
||||
-386bsd)
|
||||
os=-bsd
|
||||
;;
|
||||
-ctix* | -uts*)
|
||||
os=-sysv
|
||||
;;
|
||||
-nova*)
|
||||
os=-rtmk-nova
|
||||
;;
|
||||
-ns2 )
|
||||
os=-nextstep2
|
||||
os=-nextstep2
|
||||
;;
|
||||
-nsk*)
|
||||
os=-nsk
|
||||
@@ -1139,6 +1243,9 @@ case $os in
|
||||
-sinix*)
|
||||
os=-sysv4
|
||||
;;
|
||||
-tpf*)
|
||||
os=-tpf
|
||||
;;
|
||||
-triton*)
|
||||
os=-sysv3
|
||||
;;
|
||||
@@ -1166,8 +1273,14 @@ case $os in
|
||||
-xenix)
|
||||
os=-xenix
|
||||
;;
|
||||
-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
|
||||
os=-mint
|
||||
-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
|
||||
os=-mint
|
||||
;;
|
||||
-aros*)
|
||||
os=-aros
|
||||
;;
|
||||
-kaos*)
|
||||
os=-kaos
|
||||
;;
|
||||
-none)
|
||||
;;
|
||||
@@ -1200,10 +1313,14 @@ case $basic_machine in
|
||||
arm*-semi)
|
||||
os=-aout
|
||||
;;
|
||||
c4x-* | tic4x-*)
|
||||
os=-coff
|
||||
;;
|
||||
# This must come before the *-dec entry.
|
||||
pdp10-*)
|
||||
os=-tops20
|
||||
;;
|
||||
pdp11-*)
|
||||
pdp11-*)
|
||||
os=-none
|
||||
;;
|
||||
*-dec | vax-*)
|
||||
@@ -1230,6 +1347,9 @@ case $basic_machine in
|
||||
mips*-*)
|
||||
os=-elf
|
||||
;;
|
||||
or32-*)
|
||||
os=-coff
|
||||
;;
|
||||
*-tti) # must be before sparc entry or we get the wrong os.
|
||||
os=-sysv3
|
||||
;;
|
||||
@@ -1293,19 +1413,19 @@ case $basic_machine in
|
||||
*-next)
|
||||
os=-nextstep3
|
||||
;;
|
||||
*-gould)
|
||||
*-gould)
|
||||
os=-sysv
|
||||
;;
|
||||
*-highlevel)
|
||||
*-highlevel)
|
||||
os=-bsd
|
||||
;;
|
||||
*-encore)
|
||||
os=-bsd
|
||||
;;
|
||||
*-sgi)
|
||||
*-sgi)
|
||||
os=-irix
|
||||
;;
|
||||
*-siemens)
|
||||
*-siemens)
|
||||
os=-sysv4
|
||||
;;
|
||||
*-masscomp)
|
||||
@@ -1374,10 +1494,16 @@ case $basic_machine in
|
||||
-mvs* | -opened*)
|
||||
vendor=ibm
|
||||
;;
|
||||
-os400*)
|
||||
vendor=ibm
|
||||
;;
|
||||
-ptx*)
|
||||
vendor=sequent
|
||||
;;
|
||||
-vxsim* | -vxworks*)
|
||||
-tpf*)
|
||||
vendor=ibm
|
||||
;;
|
||||
-vxsim* | -vxworks* | -windiss*)
|
||||
vendor=wrs
|
||||
;;
|
||||
-aux*)
|
||||
|
||||
+77
-6
@@ -138,7 +138,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.1 $
|
||||
# $Revision: 1.7 $
|
||||
|
||||
#########
|
||||
# Programs needed
|
||||
@@ -154,6 +154,12 @@ 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
|
||||
AC_SUBST(VERSION)
|
||||
|
||||
#########
|
||||
# Check to see if the --with-hints=FILE option is used. If there is none,
|
||||
# then check for a files named "$host.hints" and ../$hosts.hints where
|
||||
@@ -299,6 +305,67 @@ else
|
||||
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_MSG_RESULT([no])
|
||||
else
|
||||
INMEMORYDB=1
|
||||
AC_MSG_RESULT([yes])
|
||||
fi
|
||||
AC_SUBST(ALLOWATTACHMEM)
|
||||
|
||||
##########
|
||||
# Do we want to support release
|
||||
#
|
||||
AC_ARG_ENABLE(releasemode,
|
||||
[ --enable-releasemode Support libtool link to release mode],,enable_releasemode=no)
|
||||
AC_MSG_CHECKING([whether to support shared library linked as release mode or not])
|
||||
if test "$enable_releasemode" = "no"; then
|
||||
ALLOWRELEASE=""
|
||||
AC_MSG_RESULT([no])
|
||||
else
|
||||
ALLOWRELEASE="-release `cat VERSION`"
|
||||
AC_MSG_RESULT([yes])
|
||||
fi
|
||||
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_MSG_CHECKING([whether to use an in-ram database for temporary tables])
|
||||
case "$enable_tempdb_in_ram" 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
|
||||
AC_MSG_RESULT([always])
|
||||
;;
|
||||
* )
|
||||
INMEMORYDB=1
|
||||
TEMP_STORE=2
|
||||
AC_MSG_RESULT([yes])
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_SUBST(INMEMORYDB)
|
||||
AC_SUBST(TEMP_STORE)
|
||||
|
||||
###########
|
||||
# Lots of things are different if we are compiling for Windows using
|
||||
# the CYGWIN environment. So check for that special case and handle
|
||||
@@ -317,7 +384,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
|
||||
@@ -368,7 +435,7 @@ else
|
||||
else
|
||||
LIBS=""
|
||||
AC_SEARCH_LIBS(Tcl_Init, dnl
|
||||
tcl8.4 tcl8.3 tcl8.2 tcl8.1 tcl8.0 tcl80 tcl,,,$otherlibs)
|
||||
tcl8.4 tcl8.3 tcl84 tcl83 tcl,,,$otherlibs)
|
||||
fi
|
||||
TARGET_TCL_LIBS="$LIBS $otherlibs"
|
||||
fi
|
||||
@@ -420,7 +487,8 @@ if test "$config_TARGET_READLINE_LIBS" != ""; then
|
||||
else
|
||||
CC=$TARGET_CC
|
||||
LIBS=""
|
||||
AC_SEARCH_LIBS(readline, readline,,,)
|
||||
AC_SEARCH_LIBS(tgetent, [readline ncurses curses termcap])
|
||||
AC_CHECK_LIB([readline], [readline])
|
||||
TARGET_READLINE_LIBS="$LIBS"
|
||||
fi
|
||||
AC_SUBST(TARGET_READLINE_LIBS)
|
||||
@@ -441,7 +509,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"
|
||||
@@ -474,4 +542,7 @@ AC_CHECK_FUNC(usleep, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_USLEEP=1"])
|
||||
#########
|
||||
# Generate the output files.
|
||||
#
|
||||
AC_OUTPUT(Makefile)
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
sqlite.pc
|
||||
])
|
||||
|
||||
-489
@@ -1,489 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
# build and target systems:
|
||||
#
|
||||
# srcdir
|
||||
#
|
||||
# The is the name of the directory that contains the
|
||||
# "configure" shell script. All source files are
|
||||
# located relative to this directory.
|
||||
#
|
||||
# bindir
|
||||
#
|
||||
# The name of the directory where executables should be
|
||||
# written by the "install" target of the makefile.
|
||||
#
|
||||
# program_prefix
|
||||
#
|
||||
# Add this prefix to the names of all executables that run
|
||||
# on the target machine. Default: ""
|
||||
#
|
||||
# ENABLE_SHARED
|
||||
#
|
||||
# True if shared libraries should be generated.
|
||||
#
|
||||
# BUILD_CC
|
||||
#
|
||||
# The name of a command that is used to convert C
|
||||
# source files into executables that run on the build
|
||||
# platform.
|
||||
#
|
||||
# BUILD_CFLAGS
|
||||
#
|
||||
# Switches that the build compiler needs in order to construct
|
||||
# command-line programs.
|
||||
#
|
||||
# BUILD_LIBS
|
||||
#
|
||||
# Libraries that the build compiler needs in order to construct
|
||||
# command-line programs.
|
||||
#
|
||||
# BUILD_EXEEXT
|
||||
#
|
||||
# The filename extension for executables on the build
|
||||
# platform. "" for Unix and ".exe" for Windows.
|
||||
#
|
||||
# TARGET_CC
|
||||
#
|
||||
# The name of a command that runs on the build platform
|
||||
# and converts C source files into *.o files for the
|
||||
# target platform. In other words, the cross-compiler.
|
||||
#
|
||||
# TARGET_CFLAGS
|
||||
#
|
||||
# Switches that the target compiler needs to turn C source files
|
||||
# into *.o files. Do not include TARGET_TCL_INC in this list.
|
||||
# Makefiles might add additional switches such as "-I.".
|
||||
#
|
||||
# TARGET_TCL_LIBS
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# TARGET_READLINE_LIBS
|
||||
#
|
||||
# This is the library directives passed to the target linker
|
||||
# that cause the executable to link against the readline library.
|
||||
# This might be a switch like "-lreadline" or pathnames of library
|
||||
# file like "../../src/libreadline.a".
|
||||
#
|
||||
# TARGET_READLINE_INC
|
||||
#
|
||||
# This variables define the directory that contain header
|
||||
# files for the readline library. If the compiler is able
|
||||
# to find <readline.h> on its own, then this can be blank.
|
||||
#
|
||||
# TARGET_LINK
|
||||
#
|
||||
# The name of the linker that combines *.o files generated
|
||||
# by TARGET_CC into executables for the target platform.
|
||||
#
|
||||
# TARGET_LIBS
|
||||
#
|
||||
# Additional libraries or other switch that the target linker needs
|
||||
# to build an executable on the target. Do not include
|
||||
# on this list any libraries in TARGET_TCL_LIBS and
|
||||
# TARGET_READLINE_LIBS, etc.
|
||||
#
|
||||
# TARGET_EXEEXT
|
||||
#
|
||||
# The filename extension for executables on the
|
||||
# target platform. "" for Unix and ".exe" for windows.
|
||||
#
|
||||
# The generated configure script will make an attempt to guess
|
||||
# at all of the above parameters. You can override any of
|
||||
# the guesses by setting the environment variable named
|
||||
# "config_AAAA" where "AAAA" is the name of the parameter
|
||||
# described above. (Exception: srcdir cannot be set this way.)
|
||||
# If you have a file that sets one or more of these environment
|
||||
# variables, you can invoke configure as follows:
|
||||
#
|
||||
# configure --with-hints=FILE
|
||||
#
|
||||
# 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
|
||||
# the corresponding code.
|
||||
#
|
||||
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.11 $
|
||||
|
||||
#########
|
||||
# Make sure we are not building in a subdirectory of the source tree.
|
||||
#
|
||||
changequote(<<<,>>>)
|
||||
temp=`echo $srcdir | grep '[^./]'`
|
||||
changequote([,])
|
||||
if test "$temp" = ""; then
|
||||
AC_MSG_ERROR([
|
||||
**************************************************************************
|
||||
** This program may not be compiled in the same directory that contains **
|
||||
** the configure script or any subdirectory of that directory. Rerun **
|
||||
** the configure script from a directory that is separate from the **
|
||||
** source tree. **
|
||||
** **
|
||||
** See the README file for additional information. **
|
||||
**************************************************************************])
|
||||
fi
|
||||
|
||||
#########
|
||||
# Set up an appropriate program prefix
|
||||
#
|
||||
if test "$program_prefix" = "NONE"; then
|
||||
program_prefix=""
|
||||
fi
|
||||
AC_SUBST(program_prefix)
|
||||
|
||||
#########
|
||||
# Check to see if the --with-hints=FILE option is used. If there is none,
|
||||
# then check for a files named "$host.hints" and ../$hosts.hints where
|
||||
# $host is the hostname of the build system. If still no hints are
|
||||
# found, try looking in $system.hints and ../$system.hints where
|
||||
# $system is the result of uname -s.
|
||||
#
|
||||
AC_ARG_WITH(hints,
|
||||
[ --with-hints=FILE Read configuration options from FILE],
|
||||
hints=$withval)
|
||||
if test "$hints" = ""; then
|
||||
host=`hostname | sed 's/\..*//'`
|
||||
if test -r $host.hints; then
|
||||
hints=$host.hints
|
||||
else
|
||||
if test -r ../$host.hints; then
|
||||
hints=../$host.hints
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if test "$hints" = ""; then
|
||||
sys=`uname -s`
|
||||
if test -r $sys.hints; then
|
||||
hints=$sys.hints
|
||||
else
|
||||
if test -r ../$sys.hints; then
|
||||
hints=../$sys.hints
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if test "$hints" != ""; then
|
||||
AC_MSG_RESULT(reading hints from $hints)
|
||||
. $hints
|
||||
fi
|
||||
|
||||
#########
|
||||
# Locate a compiler for the build machine. This compiler should
|
||||
# generate command-line programs that run on the build machine.
|
||||
#
|
||||
default_build_cflags="-g"
|
||||
if test "$config_BUILD_CC" = ""; then
|
||||
AC_PROG_CC
|
||||
if test "$cross_compiling" = "yes"; then
|
||||
AC_MSG_ERROR([unable to find a compiler for building build tools])
|
||||
fi
|
||||
BUILD_CC=$CC
|
||||
default_build_cflags=$CFLAGS
|
||||
else
|
||||
BUILD_CC=$config_BUILD_CC
|
||||
AC_MSG_CHECKING([host compiler])
|
||||
CC=$BUILD_CC
|
||||
AC_MSG_RESULT($BUILD_CC)
|
||||
fi
|
||||
AC_MSG_CHECKING([switches for the host compiler])
|
||||
if test "$config_BUILD_CFLAGS" != ""; then
|
||||
CFLAGS=$config_BUILD_CFLAGS
|
||||
BUILD_CFLAGS=$config_BUILD_CFLAGS
|
||||
else
|
||||
BUILD_CFLAGS=$default_build_cflags
|
||||
fi
|
||||
AC_MSG_RESULT($BUILD_CFLAGS)
|
||||
if test "$config_BUILD_LIBS" != ""; then
|
||||
BUILD_LIBS=$config_BUILD_LIBS
|
||||
fi
|
||||
AC_SUBST(BUILD_CC)
|
||||
AC_SUBST(BUILD_CFLAGS)
|
||||
AC_SUBST(BUILD_LIBS)
|
||||
|
||||
##########
|
||||
# Locate a compiler that converts C code into *.o files that run on
|
||||
# the target machine.
|
||||
#
|
||||
AC_MSG_CHECKING([target compiler])
|
||||
if test "$config_TARGET_CC" != ""; then
|
||||
TARGET_CC=$config_TARGET_CC
|
||||
else
|
||||
TARGET_CC=$BUILD_CC
|
||||
fi
|
||||
AC_MSG_RESULT($TARGET_CC)
|
||||
AC_MSG_CHECKING([switches on the target compiler])
|
||||
if test "$config_TARGET_CFLAGS" != ""; then
|
||||
TARGET_CFLAGS=$config_TARGET_CFLAGS
|
||||
else
|
||||
TARGET_CFLAGS=$BUILD_CFLAGS
|
||||
fi
|
||||
AC_MSG_RESULT($TARGET_CFLAGS)
|
||||
AC_MSG_CHECKING([target linker])
|
||||
if test "$config_TARGET_LINK" = ""; then
|
||||
TARGET_LINK=$TARGET_CC
|
||||
else
|
||||
TARGET_LINK=$config_TARGET_LINK
|
||||
fi
|
||||
AC_MSG_RESULT($TARGET_LINK)
|
||||
AC_MSG_CHECKING([switches on the target compiler])
|
||||
if test "$config_TARGET_TFLAGS" != ""; then
|
||||
TARGET_TFLAGS=$config_TARGET_TFLAGS
|
||||
else
|
||||
TARGET_TFLAGS=$BUILD_CFLAGS
|
||||
fi
|
||||
if test "$config_TARGET_RANLIB" != ""; then
|
||||
TARGET_RANLIB=$config_TARGET_RANLIB
|
||||
else
|
||||
AC_PROG_RANLIB
|
||||
TARGET_RANLIB=$RANLIB
|
||||
fi
|
||||
if test "$config_TARGET_AR" != ""; then
|
||||
TARGET_AR=$config_TARGET_AR
|
||||
else
|
||||
TARGET_AR='ar cr'
|
||||
fi
|
||||
AC_MSG_RESULT($TARGET_TFLAGS)
|
||||
AC_SUBST(TARGET_CC)
|
||||
AC_SUBST(TARGET_CFLAGS)
|
||||
AC_SUBST(TARGET_LINK)
|
||||
AC_SUBST(TARGET_LFLAGS)
|
||||
AC_SUBST(TARGET_RANLIB)
|
||||
AC_SUBST(TARGET_AR)
|
||||
|
||||
# Set the $cross variable if we are cross-compiling. Make
|
||||
# it 0 if we are not.
|
||||
#
|
||||
AC_MSG_CHECKING([if host and target compilers are the same])
|
||||
if test "$BUILD_CC" = "$TARGET_CC"; then
|
||||
cross=0
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
cross=1
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
##########
|
||||
# Are we using UTF-8 or iso8859 encodings?
|
||||
#
|
||||
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)
|
||||
|
||||
###########
|
||||
# Lots of things are different if we are compiling for Windows using
|
||||
# the CYGWIN environment. So check for that special case and handle
|
||||
# things accordingly.
|
||||
#
|
||||
AC_MSG_CHECKING([if executables have the .exe suffix])
|
||||
if test "$config_BUILD_EXEEXT" = ".exe"; then
|
||||
CYGWIN=yes
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(unknown)
|
||||
fi
|
||||
if test "$CYGWIN" != "yes"; then
|
||||
AC_CYGWIN
|
||||
fi
|
||||
if test "$CYGWIN" = "yes"; then
|
||||
BUILD_EXEEXT=.exe
|
||||
else
|
||||
BUILD_EXEEXT=""
|
||||
fi
|
||||
if test "$cross" = "0"; then
|
||||
TARGET_EXEEXT=$BUILD_EXEEXT
|
||||
else
|
||||
TARGET_EXEEXT=$config_TARGET_EXEEXT
|
||||
fi
|
||||
if test "$TARGET_EXEEXT" = ".exe"; then
|
||||
OS_UNIX=0
|
||||
OS_WIN=1
|
||||
tclsubdir=win
|
||||
else
|
||||
OS_UNIX=1
|
||||
OS_WIN=0
|
||||
tclsubdir=unix
|
||||
fi
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -DOS_UNIX=$OS_UNIX -DOS_WIN=$OS_WIN"
|
||||
|
||||
AC_SUBST(BUILD_EXEEXT)
|
||||
AC_SUBST(OS_UNIX)
|
||||
AC_SUBST(OS_WIN)
|
||||
AC_SUBST(TARGET_EXEEXT)
|
||||
|
||||
##########
|
||||
# Extract generic linker options from the environment.
|
||||
#
|
||||
if test "$config_TARGET_LIBS" != ""; then
|
||||
TARGET_LIBS=$config_TARGET_LIBS
|
||||
else
|
||||
TARGET_LIBS=""
|
||||
fi
|
||||
AC_SUBST(TARGET_LIBS)
|
||||
|
||||
##########
|
||||
# Figure out what C libraries are required to compile Tcl programs.
|
||||
#
|
||||
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.
|
||||
#
|
||||
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
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if test "$found" = "no"; then
|
||||
TARGET_TCL_INC="-DNO_TCL=1"
|
||||
fi
|
||||
AC_SUBST(TARGET_TCL_INC)
|
||||
|
||||
##########
|
||||
# Figure out what C libraries are required to compile programs
|
||||
# that use "readline()" library.
|
||||
#
|
||||
if test "$config_TARGET_READLINE_LIBS" != ""; then
|
||||
TARGET_READLINE_LIBS="$config_TARGET_READLINE_LIBS"
|
||||
else
|
||||
CC=$TARGET_CC
|
||||
LIBS=""
|
||||
AC_SEARCH_LIBS(readline, readline,,,)
|
||||
TARGET_READLINE_LIBS="$LIBS"
|
||||
fi
|
||||
AC_SUBST(TARGET_READLINE_LIBS)
|
||||
|
||||
##########
|
||||
# Figure out where to get the READLINE header files.
|
||||
#
|
||||
AC_MSG_CHECKING([readline header files])
|
||||
found=no
|
||||
if test "$config_TARGET_READLINE_INC" != ""; then
|
||||
TARGET_READLINE_INC=$config_TARGET_READLINE_INC
|
||||
found=yes
|
||||
fi
|
||||
if test "$found" = "yes"; then
|
||||
AC_MSG_RESULT($TARGET_READLINE_INC)
|
||||
else
|
||||
AC_MSG_RESULT(not specified: still searching...)
|
||||
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
|
||||
AC_CHECK_FILE($dir/include/readline.h, found=yes)
|
||||
if test "$found" = "yes"; then
|
||||
TARGET_READLINE_INC="-I$dir/include"
|
||||
break
|
||||
fi
|
||||
AC_CHECK_FILE($dir/include/readline/readline.h, found=yes)
|
||||
if test "$found" = "yes"; then
|
||||
TARGET_READLINE_INC="-I$dir/include/readline"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if test "$found" = "yes"; then
|
||||
if test "$TARGET_READLINE_LIBS" = ""; then
|
||||
TARGET_HAVE_READLINE=0
|
||||
else
|
||||
TARGET_HAVE_READLINE=1
|
||||
fi
|
||||
else
|
||||
TARGET_HAVE_READLINE=0
|
||||
fi
|
||||
AC_SUBST(TARGET_READLINE_INC)
|
||||
AC_SUBST(TARGET_HAVE_READLINE)
|
||||
|
||||
#########
|
||||
# Figure out whether or not we have a "usleep()" function.
|
||||
#
|
||||
AC_CHECK_FUNC(usleep, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_USLEEP=1"])
|
||||
|
||||
#########
|
||||
# Generate the output files.
|
||||
#
|
||||
AC_OUTPUT(Makefile)
|
||||
@@ -0,0 +1,446 @@
|
||||
###############################################################################
|
||||
# The following macros should be defined before this script is
|
||||
# invoked:
|
||||
#
|
||||
# TOP The toplevel directory of the source tree. This is the
|
||||
# directory that contains this "Makefile.in" and the
|
||||
# "configure.in" script.
|
||||
#
|
||||
# BCC C Compiler and options for use in building executables that
|
||||
# will run on the platform that is doing the build.
|
||||
#
|
||||
# USLEEP If the target operating system supports the "usleep()" system
|
||||
# call, then define the HAVE_USLEEP macro for all C modules.
|
||||
#
|
||||
# THREADSAFE If you want the SQLite library to be safe for use within a
|
||||
# multi-threaded program, then define the following macro
|
||||
# appropriately:
|
||||
#
|
||||
# THREADLIB Specify any extra linker options needed to make the library
|
||||
# thread safe
|
||||
#
|
||||
# OPTS Extra compiler command-line options.
|
||||
#
|
||||
# EXE The suffix to add to executable files. ".exe" for windows
|
||||
# and "" for Unix.
|
||||
#
|
||||
# TCC C Compiler and options for use in building executables that
|
||||
# will run on the target platform. This is usually the same
|
||||
# as BCC, unless you are cross-compiling.
|
||||
#
|
||||
# AR Tools used to build a static library.
|
||||
# RANLIB
|
||||
#
|
||||
# TCL_FLAGS Extra compiler options needed for programs that use the
|
||||
# TCL library.
|
||||
#
|
||||
# LIBTCL Linker options needed to link against the TCL library.
|
||||
#
|
||||
# READLINE_FLAGS Compiler options needed for programs that use the
|
||||
# readline() library.
|
||||
#
|
||||
# LIBREADLINE Linker options needed by programs using readline() must
|
||||
# link against.
|
||||
#
|
||||
# ENCODING "UTF8" or "ISO8859"
|
||||
#
|
||||
# Once the macros above are defined, the rest of this make script will
|
||||
# build the SQLite library and testing tools.
|
||||
################################################################################
|
||||
|
||||
# This is how we compile
|
||||
#
|
||||
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 \
|
||||
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
|
||||
|
||||
# All of the source code files.
|
||||
#
|
||||
SRC = \
|
||||
$(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/date.c \
|
||||
$(TOP)/src/delete.c \
|
||||
$(TOP)/src/encode.c \
|
||||
$(TOP)/src/expr.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/hash.c \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pager.h \
|
||||
$(TOP)/src/parse.y \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/random.c \
|
||||
$(TOP)/src/select.c \
|
||||
$(TOP)/src/shell.c \
|
||||
$(TOP)/src/sqlite.h.in \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/table.c \
|
||||
$(TOP)/src/tclsqlite.c \
|
||||
$(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/trigger.c \
|
||||
$(TOP)/src/update.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vacuum.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/vdbeaux.c \
|
||||
$(TOP)/src/vdbeInt.h \
|
||||
$(TOP)/src/where.c
|
||||
|
||||
# Source code to the test files.
|
||||
#
|
||||
TESTSRC = \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/md5.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
sqlite.h \
|
||||
$(TOP)/src/btree.h \
|
||||
config.h \
|
||||
$(TOP)/src/hash.h \
|
||||
opcodes.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
parse.h
|
||||
|
||||
# Header files used by the VDBE submodule
|
||||
#
|
||||
VDBEHDR = \
|
||||
$(HDR) \
|
||||
$(TOP)/src/vdbeInt.h
|
||||
|
||||
# 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)
|
||||
|
||||
# Generate the file "last_change" which contains the date of change
|
||||
# of the most recently modified source code file
|
||||
#
|
||||
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
|
||||
|
||||
sqlite$(EXE): $(TOP)/src/shell.c libsqlite.a sqlite.h
|
||||
$(TCCX) $(READLINE_FLAGS) -o sqlite$(EXE) $(TOP)/src/shell.c \
|
||||
libsqlite.a $(LIBREADLINE) $(THREADLIB)
|
||||
|
||||
sqlite_analyzer$(EXE): $(TOP)/src/tclsqlite.c libsqlite.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 -static -o \
|
||||
sqlite_analyzer$(EXE) $(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite.a $(LIBTCL)
|
||||
|
||||
|
||||
# This target creates a directory named "tsrc" and fills it with
|
||||
# copies of all of the C source code and header files needed to
|
||||
# build on the target system. Some of the C source code and header
|
||||
# files are automatically generated. This target takes care of
|
||||
# all that automatic generation.
|
||||
#
|
||||
target_source: $(SRC) $(VDBEHDR) opcodes.c
|
||||
rm -rf tsrc
|
||||
mkdir tsrc
|
||||
cp $(SRC) $(VDBEHDR) tsrc
|
||||
rm tsrc/sqlite.h.in tsrc/parse.y
|
||||
cp parse.c opcodes.c tsrc
|
||||
|
||||
# Rules to build the LEMON compiler generator
|
||||
#
|
||||
lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
$(BCC) -o lemon $(TOP)/tool/lemon.c
|
||||
cp $(TOP)/tool/lempar.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
|
||||
|
||||
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
|
||||
|
||||
date.o: $(TOP)/src/date.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/date.c
|
||||
|
||||
delete.o: $(TOP)/src/delete.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/delete.c
|
||||
|
||||
encode.o: $(TOP)/src/encode.c
|
||||
$(TCCX) -c $(TOP)/src/encode.c
|
||||
|
||||
expr.o: $(TOP)/src/expr.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/expr.c
|
||||
|
||||
func.o: $(TOP)/src/func.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/func.c
|
||||
|
||||
hash.o: $(TOP)/src/hash.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/hash.c
|
||||
|
||||
insert.o: $(TOP)/src/insert.c $(HDR)
|
||||
$(TCCX) -c $(TOP)/src/insert.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
|
||||
|
||||
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
|
||||
|
||||
printf.o: $(TOP)/src/printf.c $(HDR)
|
||||
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/printf.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
|
||||
|
||||
tclsqlite: $(TOP)/src/tclsqlite.c libsqlite.a
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite \
|
||||
$(TOP)/src/tclsqlite.c libsqlite.a $(LIBTCL)
|
||||
|
||||
testfixture$(EXE): $(TOP)/src/tclsqlite.c libsqlite.a $(TESTSRC)
|
||||
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -o testfixture$(EXE) \
|
||||
$(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
fulltest: testfixture$(EXE) sqlite$(EXE)
|
||||
./testfixture$(EXE) $(TOP)/test/all.test
|
||||
|
||||
test: testfixture$(EXE) sqlite$(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
|
||||
|
||||
sqlite.html: $(TOP)/www/sqlite.tcl
|
||||
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
|
||||
|
||||
c_interface.html: $(TOP)/www/c_interface.tcl
|
||||
tclsh $(TOP)/www/c_interface.tcl >c_interface.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
|
||||
|
||||
vdbe.html: $(TOP)/www/vdbe.tcl
|
||||
tclsh $(TOP)/www/vdbe.tcl >vdbe.html
|
||||
|
||||
arch.html: $(TOP)/www/arch.tcl
|
||||
tclsh $(TOP)/www/arch.tcl >arch.html
|
||||
|
||||
arch.png: $(TOP)/www/arch.png
|
||||
cp $(TOP)/www/arch.png .
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
fileformat.html: $(TOP)/www/fileformat.tcl
|
||||
tclsh $(TOP)/www/fileformat.tcl >fileformat.html
|
||||
|
||||
nulls.html: $(TOP)/www/nulls.tcl
|
||||
tclsh $(TOP)/www/nulls.tcl >nulls.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 \
|
||||
c_interface.html \
|
||||
mingw.html \
|
||||
tclsqlite.html \
|
||||
download.html \
|
||||
speed.html \
|
||||
faq.html \
|
||||
formatchng.html \
|
||||
conflict.html \
|
||||
omitted.html \
|
||||
datatypes.html \
|
||||
quickstart.html \
|
||||
fileformat.html \
|
||||
nulls.html
|
||||
|
||||
doc: $(DOC)
|
||||
mkdir -p doc
|
||||
mv $(DOC) doc
|
||||
|
||||
install: sqlite libsqlite.a sqlite.h
|
||||
mv sqlite /usr/bin
|
||||
mv libsqlite.a /usr/lib
|
||||
mv sqlite.h /usr/include
|
||||
|
||||
clean:
|
||||
rm -f *.o sqlite libsqlite.a sqlite.h opcodes.*
|
||||
rm -f lemon lempar.c parse.* sqlite*.tar.gz
|
||||
rm -f $(PUBLISH)
|
||||
rm -f *.da *.bb *.bbg gmon.out
|
||||
rm -rf tsrc
|
||||
@@ -1,119 +1,197 @@
|
||||
C Version\s2.0.2\s(CVS\s468)
|
||||
D 2001-10-09T14:00:00
|
||||
F Makefile.in 98d4627cb364537e4c3a29ee806171f3abf5211a
|
||||
F Makefile.template 1e54087c0390c4ce0bb5be43e14ba028283751e6
|
||||
F README 93d2977cc5c6595c448de16bdefc312b9d401533
|
||||
F VERSION 73e5f5e088b67ed1629b08ca531b81c778ab8695
|
||||
F aclocal.m4 11faa843caa38fd451bc6aeb43e248d1723a269d
|
||||
F config.guess f38b1e93d1e0fa6f5a6913e9e7b12774b9232588
|
||||
F config.log 6a73d03433669b10a3f0c221198c3f26b9413914
|
||||
F config.status eea88b8fe8b8b82d69b886382061efa9b77131cc
|
||||
F config.sub f14b07d544ca26b5d698259045136b783e18fc7f
|
||||
F configure 9303d975dbd577fbe61e615045ddc02015b59fb5 x
|
||||
F configure.ac 38e2e5594cab99eb3a753b0614fcc36f4ddbbb48
|
||||
F configure.in 0000c0d62beb47cae1d2d81a197c7fe6efd56a45
|
||||
C Version\s2.8.16\s(CVS\s2336)
|
||||
D 2005-02-15T13:07:51
|
||||
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
|
||||
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||
F VERSION e100aeefc5ef366c7dbecc865e47faa2047802ca
|
||||
F aclocal.m4 7daea4c35e88de30d5a3f6f7a2ab99720e803bbd
|
||||
F art/SQLite.eps 9b43cc99cfd2be687d386faea6862ea68d6a72b2
|
||||
F art/SQLite.gif 1bbb94484963f1382e27e1c5e86dd0c1061eba2b
|
||||
F config.guess 2103e94b15dc57112d7b9ee152c6fac5288895b4
|
||||
F config.sub 9bf686ec001ae7bc53f5b3563c90c62d4c6d48be
|
||||
F configure 6a156e79aaddba2e0e6816972d99989f48cc1699 x
|
||||
F configure.ac 684143ce9ee7bafc4291d0e17f2dfdc70514d1d6
|
||||
F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
|
||||
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||
F libtool c56e618713c9510a103bda6b95f3ea3900dcacd6
|
||||
F ltmain.sh e9ed72eb1d690f447c13945eaf69e28af531eda1
|
||||
F publish.sh badcd69b8e3a8bc69b162c4c9d7c209b2a0b119e
|
||||
F src/TODO af7f3cab0228e34149cf98e073aa83d45878e7e6
|
||||
F src/btree.c 7e9c33a714ed1630562f89ad19847f5f28bd6d4d
|
||||
F src/btree.h 57d653ef5137b91f2a068aaf71a2905468dd2cb7
|
||||
F src/build.c 707f6ef58dcdd50ead9ead914d673b08e7121bc5
|
||||
F src/delete.c 93c9d5e160395020a25d59371625db74c97c7c4d
|
||||
F src/expr.c 2f68829d983ec3f92eeb8b89ce4b9e5704169a80
|
||||
F src/hash.c bf36fb4cba114015123b0050f137d2c4553778a1
|
||||
F src/hash.h a5f5b3ce2d086a172c5879b0b06a27a82eac9fac
|
||||
F src/insert.c a48ba850461b203fb8dbc7add83fc6b6a9cf47f3
|
||||
F src/main.c ece73e5a44fab98144c4a93084d68b4fc413ba66
|
||||
F src/md5.c 52f677bfc590e09f71d07d7e327bd59da738d07c
|
||||
F src/os.c a83f4cb85e4d3b98c1659a799f9e318fcaf1c76c
|
||||
F src/os.h bed702c9e3b768bc3cb1b12c90b83d099c1546be
|
||||
F src/pager.c 3445bd7c18cbfdffd8d6d1077f0b2bdf788da4fe
|
||||
F src/pager.h a0d4c5ae271914aa07b62aee0707997d6932b6ca
|
||||
F src/parse.y e88f1efe096a1a01c9076099fe1d81deedfa11de
|
||||
F src/printf.c b1e22a47be8cdf707815647239991e08e8cb69f9
|
||||
F src/random.c 2a9cc2c9716d14815fd4c2accf89d87a1143e46b
|
||||
F src/select.c 0ef8ca1b7de2467fe082bcb35a5ab3b5be56153c
|
||||
F src/shell.c cb8c41f1b2173efd212dab3f35f1fc6bf32ead76
|
||||
F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
|
||||
F src/sqlite.h.in b95c161abf1d58bceb05290fa3f657d8f388fc11
|
||||
F src/sqliteInt.h 603566f58dff0e0295e57792e9313fe5d253f1a2
|
||||
F src/table.c abd0adbe0fee39d995287b3bcccd908d174dfcac
|
||||
F src/tclsqlite.c 765599686c19ed777ac379928d732c8bfc63ebac
|
||||
F src/test1.c e4b31f62ea71963cbae44338acf477a04fc8fc49
|
||||
F src/test2.c 0168b39225b768cfdadd534406f9dec58c27879e
|
||||
F src/test3.c 4a0d7b882fdae731dbb759f512ad867122452f96
|
||||
F src/tokenize.c 15d349b68d9dc5722956bd7549752ace62034787
|
||||
F src/update.c 49a1edb1a3e44dfff3f799e00f2a3319f2393cd8
|
||||
F src/util.c 4da3be37d0fd3c640d2d3033503768afdc8e5387
|
||||
F src/vdbe.c 594050d9a8dc51b97320c52d4665de313b842c27
|
||||
F src/vdbe.h 7eb7e9e6c58fe9430efab35e168f96cb4bd6cb45
|
||||
F src/where.c b676765ad0360769173b09f46265ddec8d48367a
|
||||
F test/all.test a2320eb40b462f25bd3e33115b1cabf3791450dd
|
||||
F test/bigrow.test a35f2de9948b24e427fb292c35947795efe182d0
|
||||
F test/btree.test 47952c7a0c22660566264c68c0664592b7da85ce
|
||||
F test/btree2.test 20ce47ab804f15b6563736528bdd38aabe5193dc
|
||||
F test/copy.test 768e6f1701a07d08090e1ca7f7dcce0a7a72b43e
|
||||
F test/delete.test 5ebb114582457428b3e0e30b21b477fedcb85609
|
||||
F test/expr.test b3475005ea19d53bf8c4573fb6e4a4498be5b434
|
||||
F test/func.test dfee65686b8ba06071c2f007243a25c96ce82cf2
|
||||
F test/in.test 9323681388be301dc73f370b4cd62c5a33f79d1e
|
||||
F test/index.test 6076f29d09a4f26a2efa38b03b8cc338b8662f0e
|
||||
F test/insert.test a5c122aa726f1cef6f07d6767e8fd6f220994c11
|
||||
F test/insert2.test 252d7130d8cc20f649b31a4f503cd87e660abda8
|
||||
F test/lock.test 19593689260c419efe7ced55b1418653a4b7bcd1
|
||||
F test/main.test 085ece17913a487caacbc0a392638c958c83a75d
|
||||
F test/malloc.test f1400a8d002eb96f1ca0a34abe56d2ab3e324740
|
||||
F test/misc1.test 50a5ca3481fc1f3cd6b978bcd6ed04c06f26a1e6
|
||||
F test/pager.test 59bbc4e3d489529ed33db6e15595789e51056077
|
||||
F test/printf.test 3cb415073754cb8ff076f26173143c3cd293a9da
|
||||
F test/quick.test b6ec50f808efc06595fd324bf4f3fabadb9c7e9c
|
||||
F test/quote.test 286db944717afa9a9bf829dd85e59185c65d5435
|
||||
F test/rowid.test 427bfbbe9684fe7a2f851aa05badaae6d4972ce8
|
||||
F test/select1.test b59e8c713277d7545f5b6e782e6223e51fea45a5
|
||||
F test/select2.test f91c903e2bab0e9d45274855a981eebf846d5e32
|
||||
F test/select3.test 5e1fe8e5a4e63fb2827ab3b89527e0fd4ae35259
|
||||
F test/select4.test 29a2ffb187f3d8b6ca42a0a6b619e9cabe12e228
|
||||
F test/select5.test 00a240e3311b6c4ff0f27a252ad33811211fa8d8
|
||||
F test/sort.test 462c1161eee1abaa7cc93990e0b34d5fdb70ce19
|
||||
F test/subselect.test 335d3dad8d585726c447dfee8d9c4f7383c76b78
|
||||
F test/table.test 3ef4254d62ece31a3872ab11cdaec846f6fa8fd1
|
||||
F test/tableapi.test 162840153191a91a7dce6395f2334f9aef713b37
|
||||
F test/tclsqlite.test a57bb478d7e9f0b2c927f92e161f391e2896631a
|
||||
F test/temptable.test 37acd9e39781c2ff7cff2ba741b6b27ce020a44a
|
||||
F test/tester.tcl c7ddeebc14cc841abb37134cd5d40c1e3ad367c1
|
||||
F test/trans.test 855337b8a178c73c433fcf8ee88e4b2f5efff0d9
|
||||
F test/unique.test ef1f67607a7109e9c0842cd8557550fb121d7ec6
|
||||
F test/update.test b320ea22899e80b32b4d21c54591eb7a6ba4d6bd
|
||||
F test/vacuum.test 8acf8669f3b627e54149b25165b034aa06c2432e
|
||||
F test/where.test 43d5ac94da3f3722375307f948884dc79b326a91
|
||||
F tool/lemon.c 5533b63e5cdbb1efc939abac3c2f4f37ac839488
|
||||
F tool/lempar.c 9b604e6a8b3d55c0b9cbcb130a7302fb8bafe2b9
|
||||
F tool/memleak.awk a0a11dd84bf4582acc81c3c61271021ae49b3f15
|
||||
F tool/opNames.awk 5ba1f48aa854ee3b7c3d2b54233665bc3e649ea2
|
||||
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
|
||||
F main.mk 7dfbd08ac90b15debd84ebd2606f0dbab739a4ab
|
||||
F publish.sh 5b6a0545bcea61ec30fec7aafd6746fd6a669939
|
||||
F spec.template a38492f1c1dd349fc24cb0565e08afc53045304b
|
||||
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
|
||||
F sqlite.def fc4f5734786fe4743cfe2aa98eb2da4b089edb5f
|
||||
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
|
||||
F src/attach.c 026702566f941bf2bb158a0aaa86bfeb65910aa6
|
||||
F src/auth.c 8d678ab13950801e10fd09781a7c1ed3bfeffb7c
|
||||
F src/btree.c 08a05b925b348c05d79b9b062b79e50d565678de
|
||||
F src/btree.h 41cb3ff6ebc3f6da2d0a074e39ff8c7a2287469f
|
||||
F src/btree_rb.c af40501eedd7b673ffd5e02f3a4702c76596d64a
|
||||
F src/build.c ee7905531ed592bd68b484f0821fc3cd007e1576
|
||||
F src/copy.c 750e13828c3e4a293123e36aaa7cf0f22466248a
|
||||
F src/date.c 54befeafe3e2af041c22bcc49fd79f0396b75c4d
|
||||
F src/delete.c 82001c74882319f94dab5f6b92a27311b31092ae
|
||||
F src/encode.c fc8c51f0b61bc803ccdec092e130bebe762b0a2f
|
||||
F src/expr.c 6bb3961c0391f2efe788fcfde3c2ff2ff283d5a8
|
||||
F src/func.c ab5c57f0ebb975e66cc13f09141247c2f7a2c293
|
||||
F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e
|
||||
F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7
|
||||
F src/insert.c c0485ee2d1b99322894e2d1e0b576fd05ed75616
|
||||
F src/main.c 7802ab78b2f2e66750be2192b2c1334c99bc10a5
|
||||
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
|
||||
F src/os.c 989942fc5d209128d1f371f29447914ec98006ef
|
||||
F src/os.h 250a3789be609adfee5c5aa20137ce8683276f24
|
||||
F src/pager.c b246986e5ba31b15aa3cf91d3b9ec2e608aceb8e
|
||||
F src/pager.h 82332878799280145639a48d88cdb4058925e3f6
|
||||
F src/parse.y 023720cb8c3bef74e51738bca78335d0dc6d2cfd
|
||||
F src/pragma.c f9c157b0591419d2d3407dac90222020d2a6d822
|
||||
F src/printf.c 378ec63d9303993eef24814a56a9fc7260aacbea
|
||||
F src/random.c 775913e0b7fbd6295d21f12a7bd35b46387c44b2
|
||||
F src/select.c a1c18cab14b49f28ed7629a53fe02adeb13083d2
|
||||
F src/shell.c 920af040d3a33ea8919c82cee45b424ad841cee0
|
||||
F src/sqlite.h.in b1414cc6686c77917024d8196efa4531e76cf194
|
||||
F src/sqliteInt.h 3e9203f16d12baf3a364fae9d64903d813651abd
|
||||
F src/table.c eea34544be947e4939ba9e46391d5da998f90b84
|
||||
F src/tclsqlite.c 2daaaa41378fbaf167905363197e1d44464b6eb6
|
||||
F src/test1.c 4ae20bc125b1a7d7824cccca55d538d81f0b4949
|
||||
F src/test2.c 75819b0f2c63c6a0fd6995445881f2eb94036996
|
||||
F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
|
||||
F src/test4.c 6e3e31acfaf21d66420fc35fda5b17dc0000cc8d
|
||||
F src/tokenize.c 6676b946fd8825b67ab52140af4fdc57a70bda48
|
||||
F src/trigger.c a9927b57c865b6f3df3fb5e40c9824d722660ded
|
||||
F src/update.c bd391079138e67d09c9af34528ca4137c29242d1
|
||||
F src/util.c 48f1e99803e924433477a7ccbdab35663acb621d
|
||||
F src/vacuum.c 12de02a8dec2b3f8d30ea496b66a0f989322a2c4
|
||||
F src/vdbe.c f78a26f5bbd647fac84c26e0a54b85361613a004
|
||||
F src/vdbe.h ac987945e4dd6f987bca534c6005899f089fc270
|
||||
F src/vdbeInt.h b40ff02ce39fd076e6ff3369e19c1bbfe1986682
|
||||
F src/vdbeaux.c 14ff0eb6ed9d5998f927433c91b0a3d13d81f4f6
|
||||
F src/where.c ce4968e37382808ec76a47385384ee21ad9e979e
|
||||
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
|
||||
F test/attach.test ba8261d38da6b6a7d4f78ec543c548c4418582ef
|
||||
F test/attach2.test ce61e6185b3cd891cc0e9a4c868fcc65eb92fc55
|
||||
F test/auth.test 3bd865e3069af8aa703158ff69cfc5e57b29033b
|
||||
F test/bigfile.test ea904b853ce2d703b16c5ce90e2b54951bc1ae81
|
||||
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
|
||||
F test/bind.test 56a57043b42c4664ca705f6050e56717a8a6699a
|
||||
F test/btree.test 677aeaac7b7b81980b446ca9cab15aa0cc5550d5
|
||||
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 f07ea8d60878da7a67416ab62f78e9706b9d3c45
|
||||
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
|
||||
F test/date.test aa4bc2aae379bed3f838ea73de0cde1c352c5545
|
||||
F test/delete.test 92256384f1801760180ded129f7427884cf28886
|
||||
F test/expr.test ad985242e140f87eeef329d98257b8369a2066dc
|
||||
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
|
||||
F test/format3.test 149cc166c97923fa60def047e90dd3fb32bba916
|
||||
F test/func.test 56b12001d4d8239c6af2864e3d64916cf5dad711
|
||||
F test/hook.test 1a67ce0cd64a6455d016962542f2822458dccc49
|
||||
F test/in.test 0de39b02ceeca90993b096822fb5a884661c5b47
|
||||
F test/index.test 491d721e9b442a51b118894323f2885a2187a8dd
|
||||
F test/insert.test a17b7f7017097afb2727aa5b67ceeb7ab0a120a1
|
||||
F test/insert2.test c288375a64dad3295044714f0dfed4a193cf067f
|
||||
F test/interrupt.test 0d50985f1aa6c39fe2cca4cf4a272c79ff1648e8
|
||||
F test/intpkey.test 9320af48415c594afd4e15f8ef0daa272e05502e
|
||||
F test/ioerr.test 5dbaf09f96b56ee01cf3edd762b96eb4ad2c9ca4
|
||||
F test/join.test 9ef6aabaac9de51d5fc41e68d1f4355da05a84cd
|
||||
F test/join2.test c97e4c5aa65dea462145529e58212a709b4722b8
|
||||
F test/join3_28.test dbfbca6e102d30205e7c1854b0d4fdfcd04de938
|
||||
F test/join4_28.test aa3dba47dcc9c835ac505111ff3d925f0657ef15
|
||||
F test/lastinsert.test 31382f88b9b0270333ac9e4a17f2c2f4732da718
|
||||
F test/laststmtchanges.test cabd11bdfbaf73a4486c50b58297d9c2038ccc18
|
||||
F test/limit.test c6365450f3180170c0fa1b0bf1ae48522c33b731
|
||||
F test/lock.test 226ef831dad60ad4d200dc83e25479ba952aac7e
|
||||
F test/main.test 6a851b5992c4881a725a3d9647e629199df8de9d
|
||||
F test/malloc.test 2cfcffb7c858640e01e6520ee1cd54ca57d98e80
|
||||
F test/memdb.test 6ece25c7c0e6500199d3662607a3edca081abb2a
|
||||
F test/memleak.test 4d5d374c8ea1fc5ac634aed58cac1047848ce65e
|
||||
F test/minmax.test 9dc011a23b897718004b38f4f99e0171f9d5a3fe
|
||||
F test/misc1.test 0b98d493b0cf55cb5f53e1f3df8107c166eecb5a
|
||||
F test/misc2.test 10c2ce26407d37411b96273e552d5095393732be
|
||||
F test/misc3.test 3b5e369514a3ba3f919fb7eafa7d027440b5079e
|
||||
F test/misuse.test 1095f26d1aed406c65e1d2eba651c4bb7c38cbff
|
||||
F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
|
||||
F test/null.test 675e6823d72d4866d2aca6bf5b7259c9cd713703
|
||||
F test/pager.test 331519008889d45f6df6697395e5bce6ee602fd9
|
||||
F test/pragma.test 24a3f7a697b45cb90d664ebce5566bec7ac41571
|
||||
F test/printf.test 46b3d07d59d871d0831b4a657f6dfcafe0574850
|
||||
F test/progress.test 701b6115c2613128ececdfe1398a1bd0e1a4cfb3 x
|
||||
F test/quick.test 5a6bccf5c02f16841a79fbac7409a02138880c10
|
||||
F test/quote.test 08f23385c685d3dc7914ec760d492cacea7f6e3d
|
||||
F test/rowid.test 77f7e8c7ca626a15ff91a536595b695cfce7c845
|
||||
F test/select1.test 1eab1f8aa85b8d4e3474c0769fb81313548929ab
|
||||
F test/select2.test aceea74fd895b9d007512f72499db589735bd8e4
|
||||
F test/select3.test 445a1a3dde4e2fd32541b311f55da5e2f8079d76
|
||||
F test/select4.test e7e9a32fa745246cb99fadbeb63af4843a17925b
|
||||
F test/select5.test c2a6c4a003316ee42cbbd689eebef8fdce0db2ac
|
||||
F test/select6.test a9e31906e700e7c7592c4d0acfc022808f718baf
|
||||
F test/sort.test ba07b107c16070208e6aab3cadea66ba079d85ba
|
||||
F test/subselect.test f0fea8cf9f386d416d64d152e3c65f9116d0f50f
|
||||
F test/table.test 371a1fc1c470982b2f68f9732f903a5d96f949c4
|
||||
F test/tableapi.test e0c4cce61e58343caa84dab33fa6823cb35fe1e1
|
||||
F test/tclsqlite.test 109ed5fbfe23e24f49eff6984dfa8a6bed8b5281
|
||||
F test/temptable.test a770ba6308d7f7332fce985086b8e06bed6430c2
|
||||
F test/tester.tcl 2f1d43df1311c9dc06acaa7a82e87bfea85dea5f
|
||||
F test/thread1.test 53f050d5be6932d9430df7756edd379366508ff6
|
||||
F test/threadtest1.c f7f896e62ed46feae1dc411114a48c15a0f82ee2
|
||||
F test/threadtest2.c d94ca4114fd1504f7e0ae724bcd83d4b40931d86
|
||||
F test/trans.test 0cb8256daff1ae0da75321e00125338c6681158d
|
||||
F test/trigger1.test d2d38d8a81a2c4a033b27965aaf28a0b7aa99f31
|
||||
F test/trigger2.test 0767ab30cb5a2c8402c8524f3d566b410b6f5263
|
||||
F test/trigger3.test a95ccace88291449f5eae7139ec438a42f90654d
|
||||
F test/trigger4.test 542afce45774e8f8e1130b96b8675f414d6e4bd8
|
||||
F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b
|
||||
F test/update.test b29bd9061a1150426dab6959806fcc73a41b1217
|
||||
F test/vacuum.test a2a44544df719666efb51afbfeb6062fd59a672a
|
||||
F test/version.test 92adee5d98cf6e3eb0d1cf5186952e8114931bf6
|
||||
F test/view.test ac151928890d17716d5c1f7acc5924af61a7dacf
|
||||
F test/where.test cb3a2ed062ce4b5f08aff2d08027c6a46d68c47b
|
||||
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
|
||||
F tool/lemon.c db6a3bfaf3388c0f7aea3adb5e05acddcd427016
|
||||
F tool/lempar.c 0b5e7a58634e0d448929b8e85f7981c2aa708d57
|
||||
F tool/memleak.awk b744b6109566206c746d826f6ecdba34662216bc
|
||||
F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
|
||||
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
|
||||
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
|
||||
F tool/renumberOps.awk 6d067177ad5f8d711b79577b462da9b3634bd0a9
|
||||
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
|
||||
F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
|
||||
F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
|
||||
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
|
||||
F tool/spaceanal.tcl fec9907072011cd2b8b956fe7322cf6c50429ba9
|
||||
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
|
||||
F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4
|
||||
F www/arch.tcl 03b521d252575f93b9c52f7c8b0007011512fcfb
|
||||
F www/c_interface.tcl 8e8d9e66e8467c5751116c3427296bde77f474a6
|
||||
F www/changes.tcl 2b416b49a136312678317f509821cf9359e421b5
|
||||
F www/crosscompile.tcl c99efacb3aefaa550c6e80d91b240f55eb9fd33e
|
||||
F www/download.tcl 3e51c9ff1326b0a182846134987301310dff7d60
|
||||
F www/arch.tcl b329ca2c8dc75cd1cf0dd714b8bb47bdd458d0da
|
||||
F www/arch2.fig 613b5ac63511109064c2f93c5754ee662219937d
|
||||
F www/arch2.gif 49c6bb36160f03ca2b89eaa5bfb1f560c7d68ee7
|
||||
F www/audit.tcl 90e09d580f79c7efec0c7d6f447b7ec5c2dce5c0
|
||||
F www/c_interface.tcl 17d8bd9e7b4fbdca47c30c8b9bcb728c351d55c0
|
||||
F www/changes.tcl a3d043896631a14091dbafdb4068980974c3834c
|
||||
F www/conflict.tcl 81dd21f9a679e60aae049e9dd8ab53d59570cda2
|
||||
F www/datatypes.tcl 0fe2b810f114a909b844e50ad37a25e6ed8c7271
|
||||
F www/download.tcl 0932d7f4f0e8b2adbbd22fac73132f86e43ab4a9
|
||||
F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
|
||||
F www/index.tcl 68c815d64b35b2dcc4d4f6845827df71c6869f9f
|
||||
F www/lang.tcl 3a7900e3f80cab50f322d925e573bd9f0acd57e1
|
||||
F www/mingw.tcl fc5f4ba9d336b6e8c97347cc6496d6162461ef60
|
||||
F www/opcode.tcl 4365ad9798872491dbd7d3071510ebe461785ac3
|
||||
F www/speed.tcl ab7d6d3bc898472bd94320a5d3c63de928d4804b
|
||||
F www/sqlite.tcl 6a21242a272e9c0939a04419a51c3d50cae33e3e
|
||||
F www/tclsqlite.tcl 13d50723f583888fc80ae1a38247c0ab415066fa
|
||||
F www/vdbe.tcl bb7d620995f0a987293e9d4fb6185a3b077e9b44
|
||||
P abe5a25b9dcf1e47f3cb37fd419f620db03bd4da
|
||||
R 811a44282886ed3bd9485148120cee71
|
||||
F www/faq.tcl 88d3b95d9cd8e374772daa3a646c4d107e7f3e9b
|
||||
F www/fileformat.tcl 56f77e435a6306b337b20b416e3b89500ba2d029
|
||||
F www/formatchng.tcl ca6cc1cb1bef9bc36f0619049d3c95e749bc6983
|
||||
F www/index.tcl bacb2a0d052845bbe3bf078765cce907ed7080a4
|
||||
F www/lang.tcl 17954f37c8bb1d25e026d97041ff6459fb89ac95
|
||||
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
|
||||
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
|
||||
P affde4431749e0c57e786cec926895b3c0f8a04f
|
||||
R dd9f6bcae9ce8f6c1595e339d4e239bd
|
||||
U drh
|
||||
Z bb72d0236472bbdc7b77722d8537d4bf
|
||||
Z d67bbcce34bf232ebe03651d1d7d8311
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
44d00a6f58c71ca11423df12530177baaa054a01
|
||||
2efbbba55a851a5b83726720aaa9e59b8387556c
|
||||
+121
-33
@@ -11,34 +11,49 @@
|
||||
#
|
||||
srcdir=`echo "$0" | sed 's%\(^.*\)/[^/][^/]*$%\1%'`
|
||||
|
||||
# Get the makefile.
|
||||
# Clear out the build directory "doc"
|
||||
#
|
||||
cp $srcdir/Makefile.template ./Makefile
|
||||
#rm -rf doc
|
||||
#make doc
|
||||
|
||||
# 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
|
||||
mv sqlite sqlite-$VERS.bin
|
||||
rm -f sqlite.bin.gz
|
||||
gzip sqlite.bin
|
||||
gzip sqlite-$VERS.bin
|
||||
mv sqlite-$VERS.bin.gz doc
|
||||
|
||||
# Build the tclsqlite.so shared library for import into tclsh or wish
|
||||
# under Linux
|
||||
#
|
||||
make target_source
|
||||
rm -f doc/sqlite-source-$VERSW.zip
|
||||
cd tsrc
|
||||
zip ../doc/sqlite-source-$VERSW.zip *
|
||||
rm shell.c
|
||||
TCLDIR=/home/drh/tcltk/8.2linux
|
||||
TCLSTUBLIB=$TCLDIR/libtclstub8.2g.a
|
||||
OPTS='-DUSE_TCL_STUBS=1 -DNDEBUG=1 -DOS_UNIX=1 -DOS_WIN=0'
|
||||
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 ..
|
||||
mv tclsqlite.so tclsqlite-$VERS.so
|
||||
gzip tclsqlite-$VERS.so
|
||||
mv tclsqlite-$VERS.so.gz ../doc
|
||||
rm tclsqlite.c
|
||||
gcc -fPIC -DNDEBUG=1 -O2 -I. -shared *.c -o sqlite.so
|
||||
strip sqlite.so
|
||||
mv sqlite.so sqlite-$VERS.so
|
||||
gzip sqlite-$VERS.so
|
||||
mv sqlite-$VERS.so.gz ../doc
|
||||
cd ..
|
||||
rm -f tclsqlite.so
|
||||
gzip tclsqlite.so
|
||||
|
||||
# Build the tclsqlite.dll shared library that can be imported into tclsh
|
||||
# or wish on windows.
|
||||
@@ -49,8 +64,8 @@ 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 -DOS_UNIX=0 -DOS_WIN=1'
|
||||
CC="i386-mingw32-gcc -O2 $OPTS -I. -I$TCLDIR"
|
||||
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"
|
||||
@@ -60,45 +75,118 @@ done
|
||||
echo 'EXPORTS' >tclsqlite.def
|
||||
echo 'Tclsqlite_Init' >>tclsqlite.def
|
||||
echo 'Sqlite_Init' >>tclsqlite.def
|
||||
i386-mingw32-dllwrap \
|
||||
i386-mingw32msvc-dllwrap \
|
||||
--def tclsqlite.def -v --export-all \
|
||||
--driver-name i386-mingw32-gcc \
|
||||
--dlltool-name i386-mingw32-dlltool \
|
||||
--as i386-mingw32-as \
|
||||
--driver-name i386-mingw32msvc-gcc \
|
||||
--dlltool-name i386-mingw32msvc-dlltool \
|
||||
--as i386-mingw32msvc-as \
|
||||
--target i386-mingw32 \
|
||||
-dllname tclsqlite.dll -lmsvcrt *.o $TCLSTUBLIB
|
||||
i386-mingw32-strip tclsqlite.dll
|
||||
mv tclsqlite.dll ..
|
||||
i386-mingw32msvc-strip tclsqlite.dll
|
||||
#mv tclsqlite.dll ../tclsqlite-$VERSW.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
|
||||
sqlite_reset
|
||||
sqlite_bind
|
||||
sqlite_last_statement_changes
|
||||
sqlite_encode_binary
|
||||
sqlite_decode_binary
|
||||
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
|
||||
zip ../doc/tclsqlite-$VERSW.zip tclsqlite.dll
|
||||
zip ../doc/sqlitedll-$VERSW.zip sqlite.dll sqlite.def
|
||||
cd ..
|
||||
rm -f tclsqlite.zip
|
||||
zip tclsqlite.zip tclsqlite.dll
|
||||
|
||||
# Build the sqlite.exe executable for windows.
|
||||
#
|
||||
make target_source
|
||||
cd tsrc
|
||||
rm tclsqlite.c
|
||||
OPTS='-DSTATIC_BUILD=1 -DNDEBUG=1 -DOS_UNIX=0 -DOS_WIN=1'
|
||||
i386-mingw32-gcc -O2 $OPTS -I. -I$TCLDIR *.c -o sqlite.exe
|
||||
mv sqlite.exe ..
|
||||
OPTS='-DSTATIC_BUILD=1 -DNDEBUG=1'
|
||||
i386-mingw32msvc-gcc -O2 $OPTS -I. -I$TCLDIR *.c -o sqlite.exe
|
||||
zip ../doc/sqlite-$VERSW.zip sqlite.exe
|
||||
cd ..
|
||||
rm -f sqlite.zip
|
||||
zip sqlite.zip sqlite.exe
|
||||
|
||||
# Construct a tarball of the source tree
|
||||
#
|
||||
ORIGIN=`pwd`
|
||||
cd $srcdir
|
||||
cd ..
|
||||
tar czf $ORIGIN/sqlite.tar.gz sqlite
|
||||
EXCLUDE=`find sqlite -print | grep CVS | sed 's,^, --exclude ,'`
|
||||
tar czf $ORIGIN/doc/sqlite-$VERS.tar.gz $EXCLUDE sqlite
|
||||
cd $ORIGIN
|
||||
vers=`cat $srcdir/VERSION`
|
||||
rm -f sqlite-$vers.tar.gz
|
||||
ln sqlite.tar.gz sqlite-$vers.tar.gz
|
||||
|
||||
# Build the website
|
||||
#
|
||||
cp $srcdir/../historical/* .
|
||||
rm -rf doc
|
||||
make doc
|
||||
ln sqlite.bin.gz sqlite.zip sqlite*.tar.gz tclsqlite.so.gz tclsqlite.zip doc
|
||||
# Build RPMS (binary) and Source RPM
|
||||
#
|
||||
|
||||
# Make sure we are properly setup to build RPMs
|
||||
#
|
||||
echo "%HOME %{expand:%%(cd; pwd)}" > $HOME/.rpmmacros
|
||||
echo "%_topdir %{HOME}/rpm" >> $HOME/.rpmmacros
|
||||
mkdir $HOME/rpm
|
||||
mkdir $HOME/rpm/BUILD
|
||||
mkdir $HOME/rpm/SOURCES
|
||||
mkdir $HOME/rpm/RPMS
|
||||
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
|
||||
|
||||
# copy the source tarball to the rpm directory
|
||||
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.
|
||||
mv $HOME/rpm/RPMS/i386/sqlite*-$VERS*.rpm doc
|
||||
mv $HOME/rpm/SRPMS/sqlite-$VERS*.rpm doc
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
%define name sqlite
|
||||
%define version SQLITE_VERSION
|
||||
%define release 1
|
||||
|
||||
Name: %{name}
|
||||
Summary: SQLite is a C library that implements an embeddable SQL database engine
|
||||
Version: %{version}
|
||||
Release: %{release}
|
||||
Source: %{name}-%{version}.tar.gz
|
||||
Group: System/Libraries
|
||||
URL: http://www.hwaci.com/sw/sqlite/
|
||||
License: Public Domain
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-root
|
||||
|
||||
%description
|
||||
SQLite is a C library that implements an embeddable SQL database engine.
|
||||
Programs that link with the SQLite library can have SQL database access
|
||||
without running a separate RDBMS process. The distribution comes with a
|
||||
standalone command-line access program (sqlite) that can be used to
|
||||
administer an SQLite database and which serves as an example of how to
|
||||
use the SQLite library.
|
||||
|
||||
%package -n %{name}-devel
|
||||
Summary: Header files and libraries for developing apps which will use sqlite
|
||||
Group: Development/C
|
||||
Requires: %{name} = %{version}-%{release}
|
||||
|
||||
%description -n %{name}-devel
|
||||
The sqlite-devel package contains the header files and libraries needed
|
||||
to develop programs that use the sqlite database library.
|
||||
|
||||
%prep
|
||||
%setup -q -n %{name}
|
||||
|
||||
%build
|
||||
CFLAGS="%optflags -DNDEBUG=1" CXXFLAGS="%optflags -DNDEBUG=1" ./configure --prefix=%{_prefix}
|
||||
|
||||
make
|
||||
make doc
|
||||
|
||||
%install
|
||||
install -d $RPM_BUILD_ROOT/%{_prefix}
|
||||
install -d $RPM_BUILD_ROOT/%{_prefix}/bin
|
||||
install -d $RPM_BUILD_ROOT/%{_prefix}/include
|
||||
install -d $RPM_BUILD_ROOT/%{_prefix}/lib
|
||||
make install prefix=$RPM_BUILD_ROOT/%{_prefix}
|
||||
|
||||
%clean
|
||||
rm -fr $RPM_BUILD_ROOT
|
||||
|
||||
%files
|
||||
%defattr(-, root, root)
|
||||
%{_libdir}/*.so*
|
||||
%{_bindir}/*
|
||||
|
||||
%files -n %{name}-devel
|
||||
%defattr(-, root, root)
|
||||
%{_libdir}/pkgconfig/sqlite.pc
|
||||
%{_libdir}/*.a
|
||||
%{_libdir}/*.la
|
||||
%{_includedir}/*
|
||||
%doc doc/*
|
||||
@@ -0,0 +1,203 @@
|
||||
.\" 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).
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
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
|
||||
sqlite_reset
|
||||
sqlite_bind
|
||||
sqlite_last_statement_changes
|
||||
sqlite_encode_binary
|
||||
sqlite_decode_binary
|
||||
@@ -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} -lsqlite
|
||||
Cflags: -I${includedir}
|
||||
@@ -1,6 +0,0 @@
|
||||
* Document all the changes and release Sqlite 2.0.
|
||||
* Implement CLUSTER command like in PostgreSQL.
|
||||
* "OPTIMIZE select" statement to automatically create indices and/or
|
||||
invoke a CLUSTER command.
|
||||
* "CREATE INDEX FOR select" to automatically generate needed indices.
|
||||
* Parse and use constraints.
|
||||
+311
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
** 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 ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.10.2.1 2004/05/07 01:46:01 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This routine is called by the parser to process an ATTACH statement:
|
||||
**
|
||||
** ATTACH DATABASE filename AS dbname
|
||||
**
|
||||
** 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, Token *pKey){
|
||||
Db *aNew;
|
||||
int rc, i;
|
||||
char *zFile, *zName;
|
||||
sqlite *db;
|
||||
Vdbe *v;
|
||||
|
||||
v = sqliteGetVdbe(pParse);
|
||||
sqliteVdbeAddOp(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",
|
||||
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);
|
||||
return;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
|
||||
zName = 0;
|
||||
sqliteSetNString(&zName, pDbname->z, pDbname->n, 0);
|
||||
if( zName==0 ) return;
|
||||
sqliteDequote(zName);
|
||||
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);
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
sqliteFree(zFile);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if( db->aDb==db->aDbStatic ){
|
||||
aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );
|
||||
if( aNew==0 ) return;
|
||||
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;
|
||||
}
|
||||
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);
|
||||
aNew->zName = zName;
|
||||
rc = sqliteBtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
|
||||
if( rc ){
|
||||
sqliteErrorMsg(pParse, "unable to open database: %s", zFile);
|
||||
}
|
||||
#if SQLITE_HAS_CODEC
|
||||
{
|
||||
extern int sqliteCodecAttach(sqlite*, int, void*, int);
|
||||
char *zKey = 0;
|
||||
int nKey;
|
||||
if( pKey && pKey->z && pKey->n ){
|
||||
sqliteSetNString(&zKey, pKey->z, pKey->n, 0);
|
||||
sqliteDequote(zKey);
|
||||
nKey = strlen(zKey);
|
||||
}else{
|
||||
zKey = 0;
|
||||
nKey = 0;
|
||||
}
|
||||
sqliteCodecAttach(db, db->nDb-1, zKey, nKey);
|
||||
}
|
||||
#endif
|
||||
sqliteFree(zFile);
|
||||
db->flags &= ~SQLITE_Initialized;
|
||||
if( pParse->nErr ) return;
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqliteInit(pParse->db, &pParse->zErrMsg);
|
||||
}
|
||||
if( rc ){
|
||||
int i = db->nDb - 1;
|
||||
assert( i>=2 );
|
||||
if( db->aDb[i].pBt ){
|
||||
sqliteBtreeClose(db->aDb[i].pBt);
|
||||
db->aDb[i].pBt = 0;
|
||||
}
|
||||
sqliteResetInternalSchema(db, 0);
|
||||
pParse->nErr++;
|
||||
pParse->rc = SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called by the parser to process a DETACH statement:
|
||||
**
|
||||
** DETACH DATABASE dbname
|
||||
**
|
||||
** The pDbname argument is the name of the database in the DETACH statement.
|
||||
*/
|
||||
void sqliteDetach(Parse *pParse, Token *pDbname){
|
||||
int i;
|
||||
sqlite *db;
|
||||
Vdbe *v;
|
||||
Db *pDb;
|
||||
|
||||
v = sqliteGetVdbe(pParse);
|
||||
sqliteVdbeAddOp(v, OP_Halt, 0, 0);
|
||||
if( pParse->explain ) return;
|
||||
db = pParse->db;
|
||||
for(i=0; i<db->nDb; i++){
|
||||
pDb = &db->aDb[i];
|
||||
if( pDb->pBt==0 || pDb->zName==0 ) continue;
|
||||
if( strlen(pDb->zName)!=pDbname->n ) continue;
|
||||
if( sqliteStrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break;
|
||||
}
|
||||
if( i>=db->nDb ){
|
||||
sqliteErrorMsg(pParse, "no such database: %T", pDbname);
|
||||
return;
|
||||
}
|
||||
if( i<2 ){
|
||||
sqliteErrorMsg(pParse, "cannot detach database %T", pDbname);
|
||||
return;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( sqliteAuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){
|
||||
return;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
sqliteBtreeClose(pDb->pBt);
|
||||
pDb->pBt = 0;
|
||||
sqliteFree(pDb->zName);
|
||||
sqliteResetInternalSchema(db, i);
|
||||
if( pDb->pAux && pDb->xFreeAux ) pDb->xFreeAux(pDb->pAux);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Initialize a DbFixer structure. This routine must be called prior
|
||||
** to passing the structure to one of the sqliteFixAAAA() routines below.
|
||||
**
|
||||
** 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(
|
||||
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 */
|
||||
const char *zType, /* "view", "trigger", or "index" */
|
||||
const Token *pName /* Name of the view, trigger, or index */
|
||||
){
|
||||
sqlite *db;
|
||||
|
||||
if( iDb<0 || iDb==1 ) return 0;
|
||||
db = pParse->db;
|
||||
assert( db->nDb>iDb );
|
||||
pFix->pParse = pParse;
|
||||
pFix->zDb = db->aDb[iDb].zName;
|
||||
pFix->zType = zType;
|
||||
pFix->pName = pName;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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().
|
||||
**
|
||||
** 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.
|
||||
** (Exception: indices, triggers, and views in the TEMP database are
|
||||
** allowed to refer to anything.) If a reference is explicitly made
|
||||
** to an object in a different database, an error message is added to
|
||||
** pParse->zErrMsg and these routines return non-zero. If everything
|
||||
** checks out, these routines return 0.
|
||||
*/
|
||||
int sqliteFixSrcList(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
SrcList *pList /* The Source list to check and modify */
|
||||
){
|
||||
int i;
|
||||
const char *zDb;
|
||||
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixSelect(pFix, pList->a[i].pSelect) ) return 1;
|
||||
if( sqliteFixExpr(pFix, pList->a[i].pOn) ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqliteFixSelect(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
Select *pSelect /* The SELECT statement to be fixed to one database */
|
||||
){
|
||||
while( pSelect ){
|
||||
if( sqliteFixExprList(pFix, pSelect->pEList) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixSrcList(pFix, pSelect->pSrc) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExpr(pFix, pSelect->pWhere) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExpr(pFix, pSelect->pHaving) ){
|
||||
return 1;
|
||||
}
|
||||
pSelect = pSelect->pPrior;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqliteFixExpr(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
Expr *pExpr /* The expression to be fixed to one database */
|
||||
){
|
||||
while( pExpr ){
|
||||
if( sqliteFixSelect(pFix, pExpr->pSelect) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExprList(pFix, pExpr->pList) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExpr(pFix, pExpr->pRight) ){
|
||||
return 1;
|
||||
}
|
||||
pExpr = pExpr->pLeft;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqliteFixExprList(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
ExprList *pList /* The expression to be fixed to one database */
|
||||
){
|
||||
int i;
|
||||
if( pList==0 ) return 0;
|
||||
for(i=0; i<pList->nExpr; i++){
|
||||
if( sqliteFixExpr(pFix, pList->a[i].pExpr) ){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sqliteFixTriggerStep(
|
||||
DbFixer *pFix, /* Context of the fixation */
|
||||
TriggerStep *pStep /* The trigger step be fixed to one database */
|
||||
){
|
||||
while( pStep ){
|
||||
if( sqliteFixSelect(pFix, pStep->pSelect) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExpr(pFix, pStep->pWhere) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqliteFixExprList(pFix, pStep->pExprList) ){
|
||||
return 1;
|
||||
}
|
||||
pStep = pStep->pNext;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
** 2003 January 11
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the sqlite_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.12.2.2 2004/09/09 13:54:30 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** All of the code in this file may be omitted by defining a single
|
||||
** macro.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
|
||||
/*
|
||||
** Set or clear the access authorization function.
|
||||
**
|
||||
** The access authorization function is be called during the compilation
|
||||
** phase to verify that the user has read and/or write access permission on
|
||||
** various fields of the database. The first argument to the auth function
|
||||
** 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
|
||||
** SQLITE_CREATE_TEMP_TABLE
|
||||
** SQLITE_CREATE_TEMP_TRIGGER
|
||||
** SQLITE_CREATE_TEMP_VIEW
|
||||
** SQLITE_CREATE_TRIGGER
|
||||
** SQLITE_CREATE_VIEW
|
||||
** SQLITE_DELETE
|
||||
** SQLITE_DROP_INDEX
|
||||
** SQLITE_DROP_TABLE
|
||||
** SQLITE_DROP_TEMP_INDEX
|
||||
** SQLITE_DROP_TEMP_TABLE
|
||||
** SQLITE_DROP_TEMP_TRIGGER
|
||||
** SQLITE_DROP_TEMP_VIEW
|
||||
** SQLITE_DROP_TRIGGER
|
||||
** SQLITE_DROP_VIEW
|
||||
** SQLITE_INSERT
|
||||
** SQLITE_PRAGMA
|
||||
** SQLITE_READ
|
||||
** SQLITE_SELECT
|
||||
** SQLITE_TRANSACTION
|
||||
** SQLITE_UPDATE
|
||||
**
|
||||
** The third and fourth arguments to the auth function are the name of
|
||||
** 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
|
||||
** 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.
|
||||
**
|
||||
** 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 (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
|
||||
void *pArg
|
||||
){
|
||||
db->xAuth = xAuth;
|
||||
db->pAuthArg = pArg;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write an error message into pParse->zErrMsg that explains that the
|
||||
** user-supplied authorization function returned an illegal value.
|
||||
*/
|
||||
static void sqliteAuthBadReturnCode(Parse *pParse, int rc){
|
||||
sqliteErrorMsg(pParse, "illegal return value (%d) from the "
|
||||
"authorization function - should be SQLITE_OK, SQLITE_IGNORE, "
|
||||
"or SQLITE_DENY", rc);
|
||||
pParse->rc = SQLITE_MISUSE;
|
||||
}
|
||||
|
||||
/*
|
||||
** The pExpr should be a TK_COLUMN expression. The table referred to
|
||||
** is in pTabList or else it is the NEW or OLD table of a trigger.
|
||||
** Check to see if it is OK to read this particular column.
|
||||
**
|
||||
** If the auth function returns SQLITE_IGNORE, change the TK_COLUMN
|
||||
** instruction into a TK_NULL. If the auth function returns SQLITE_DENY,
|
||||
** then generate an error.
|
||||
*/
|
||||
void sqliteAuthRead(
|
||||
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;
|
||||
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;
|
||||
assert( pExpr->op==TK_COLUMN );
|
||||
for(iSrc=0; iSrc<pTabList->nSrc; iSrc++){
|
||||
if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break;
|
||||
}
|
||||
if( iSrc>=0 && iSrc<pTabList->nSrc ){
|
||||
pTab = pTabList->a[iSrc].pTab;
|
||||
}else if( (pStack = pParse->trigStack)!=0 ){
|
||||
/* This must be an attempt to read the NEW or OLD pseudo-tables
|
||||
** of a trigger.
|
||||
*/
|
||||
assert( pExpr->iTable==pStack->newIdx || pExpr->iTable==pStack->oldIdx );
|
||||
pTab = pStack->pTab;
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
if( pTab==0 ) return;
|
||||
if( pExpr->iColumn>=0 ){
|
||||
assert( pExpr->iColumn<pTab->nCol );
|
||||
zCol = pTab->aCol[pExpr->iColumn].zName;
|
||||
}else if( pTab->iPKey>=0 ){
|
||||
assert( pTab->iPKey<pTab->nCol );
|
||||
zCol = pTab->aCol[pTab->iPKey].zName;
|
||||
}else{
|
||||
zCol = "ROWID";
|
||||
}
|
||||
assert( pExpr->iDb<db->nDb );
|
||||
zDBase = db->aDb[pExpr->iDb].zName;
|
||||
rc = db->xAuth(db->pAuthArg, SQLITE_READ, pTab->zName, zCol, zDBase,
|
||||
pParse->zAuthContext);
|
||||
if( rc==SQLITE_IGNORE ){
|
||||
pExpr->op = TK_NULL;
|
||||
}else if( rc==SQLITE_DENY ){
|
||||
if( db->nDb>2 || pExpr->iDb!=0 ){
|
||||
sqliteErrorMsg(pParse, "access to %s.%s.%s is prohibited",
|
||||
zDBase, pTab->zName, zCol);
|
||||
}else{
|
||||
sqliteErrorMsg(pParse, "access to %s.%s is prohibited", pTab->zName,zCol);
|
||||
}
|
||||
pParse->rc = SQLITE_AUTH;
|
||||
}else if( rc!=SQLITE_OK ){
|
||||
sqliteAuthBadReturnCode(pParse, rc);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Do an authorization check using the code and arguments given. Return
|
||||
** either SQLITE_OK (zero) or SQLITE_IGNORE or SQLITE_DENY. If SQLITE_DENY
|
||||
** is returned, then the error count and error message in pParse are
|
||||
** modified appropriately.
|
||||
*/
|
||||
int sqliteAuthCheck(
|
||||
Parse *pParse,
|
||||
int code,
|
||||
const char *zArg1,
|
||||
const char *zArg2,
|
||||
const char *zArg3
|
||||
){
|
||||
sqlite *db = pParse->db;
|
||||
int rc;
|
||||
|
||||
if( db->init.busy || db->xAuth==0 ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
|
||||
if( rc==SQLITE_DENY ){
|
||||
sqliteErrorMsg(pParse, "not authorized");
|
||||
pParse->rc = SQLITE_AUTH;
|
||||
}else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
|
||||
rc = SQLITE_DENY;
|
||||
sqliteAuthBadReturnCode(pParse, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Push an authorization context. After this routine is called, the
|
||||
** zArg3 argument to authorization callbacks will be zContext until
|
||||
** popped. Or if pParse==0, this routine is a no-op.
|
||||
*/
|
||||
void sqliteAuthContextPush(
|
||||
Parse *pParse,
|
||||
AuthContext *pContext,
|
||||
const char *zContext
|
||||
){
|
||||
pContext->pParse = pParse;
|
||||
if( pParse ){
|
||||
pContext->zAuthContext = pParse->zAuthContext;
|
||||
pParse->zAuthContext = zContext;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Pop an authorization context that was previously pushed
|
||||
** by sqliteAuthContextPush
|
||||
*/
|
||||
void sqliteAuthContextPop(AuthContext *pContext){
|
||||
if( pContext->pParse ){
|
||||
pContext->pParse->zAuthContext = pContext->zAuthContext;
|
||||
pContext->pParse = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_AUTHORIZATION */
|
||||
+1327
-534
File diff suppressed because it is too large
Load Diff
+129
-34
@@ -10,52 +10,147 @@
|
||||
**
|
||||
*************************************************************************
|
||||
** This header file defines the interface that the sqlite B-Tree file
|
||||
** subsystem.
|
||||
** subsystem. See comments in the source code for a detailed description
|
||||
** of what each interface routine does.
|
||||
**
|
||||
** @(#) $Id: btree.h,v 1.16 2001/09/27 03:22:33 drh Exp $
|
||||
** @(#) $Id: btree.h,v 1.36 2004/02/10 02:57:59 drh Exp $
|
||||
*/
|
||||
#ifndef _BTREE_H_
|
||||
#define _BTREE_H_
|
||||
|
||||
/*
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
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*);
|
||||
struct Pager *(*Pager)(Btree*);
|
||||
#ifdef SQLITE_TEST
|
||||
int (*PageDump)(Btree*, int, int);
|
||||
#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*);
|
||||
#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 sqliteBtreeClose(Btree*);
|
||||
int sqliteBtreeSetCacheSize(Btree*, int);
|
||||
int sqliteRbtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
|
||||
|
||||
int sqliteBtreeBeginTrans(Btree*);
|
||||
int sqliteBtreeCommit(Btree*);
|
||||
int sqliteBtreeRollback(Btree*);
|
||||
|
||||
int sqliteBtreeCreateTable(Btree*, int*);
|
||||
int sqliteBtreeDropTable(Btree*, int);
|
||||
int sqliteBtreeClearTable(Btree*, int);
|
||||
|
||||
int sqliteBtreeCursor(Btree*, int iTable, int wrFlag, BtCursor **ppCur);
|
||||
int sqliteBtreeMoveto(BtCursor*, const void *pKey, int nKey, int *pRes);
|
||||
int sqliteBtreeDelete(BtCursor*);
|
||||
int sqliteBtreeInsert(BtCursor*, const void *pKey, int nKey,
|
||||
const void *pData, int nData);
|
||||
int sqliteBtreeFirst(BtCursor*, int *pRes);
|
||||
int sqliteBtreeNext(BtCursor*, int *pRes);
|
||||
int sqliteBtreeKeySize(BtCursor*, int *pSize);
|
||||
int sqliteBtreeKey(BtCursor*, int offset, int amt, char *zBuf);
|
||||
int sqliteBtreeKeyCompare(BtCursor*, const void *pKey, int nKey, int *pRes);
|
||||
int sqliteBtreeDataSize(BtCursor*, int *pSize);
|
||||
int sqliteBtreeData(BtCursor*, int offset, int amt, char *zBuf);
|
||||
int sqliteBtreeCloseCursor(BtCursor*);
|
||||
|
||||
#define SQLITE_N_BTREE_META 4
|
||||
int sqliteBtreeGetMeta(Btree*, int*);
|
||||
int sqliteBtreeUpdateMeta(Btree*, int*);
|
||||
#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))
|
||||
#define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt))
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
int sqliteBtreePageDump(Btree*, int, int);
|
||||
int sqliteBtreeCursorDump(BtCursor*, int*);
|
||||
struct Pager *sqliteBtreePager(Btree*);
|
||||
char *sqliteBtreeSanityCheck(Btree*, int*, int);
|
||||
#endif
|
||||
#define sqliteBtreePageDump(pBt, pgno, recursive)\
|
||||
(btOps(pBt)->PageDump(pBt, pgno, recursive))
|
||||
#define sqliteBtreeCursorDump(pCur, aResult)\
|
||||
(btCOps(pCur)->CursorDump(pCur, aResult))
|
||||
int btree_native_byte_order;
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
|
||||
#endif /* _BTREE_H_ */
|
||||
|
||||
+1488
File diff suppressed because it is too large
Load Diff
+1487
-825
File diff suppressed because it is too large
Load Diff
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
** 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.9 2004/02/25 13:47:31 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;
|
||||
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 = sqliteVdbeOp3(v, OP_FileOpen, 0, 0, pFilename->z, pFilename->n);
|
||||
sqliteVdbeDequoteP3(v, addr);
|
||||
sqliteOpenTableAndIndices(pParse, pTab, 0);
|
||||
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, 1);
|
||||
sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
copy_cleanup:
|
||||
sqliteSrcListDelete(pTableName);
|
||||
sqliteFree(zFile);
|
||||
return;
|
||||
}
|
||||
+875
@@ -0,0 +1,875 @@
|
||||
/*
|
||||
** 2003 October 31
|
||||
**
|
||||
** 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 C functions that implement date and time
|
||||
** functions for SQLite.
|
||||
**
|
||||
** There is only one exported symbol in this file - the function
|
||||
** sqliteRegisterDateTimeFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: date.c,v 1.16.2.2 2004/07/20 00:40:01 drh Exp $
|
||||
**
|
||||
** NOTES:
|
||||
**
|
||||
** SQLite processes all times and dates as Julian Day numbers. The
|
||||
** dates and times are stored as the number of days since noon
|
||||
** in Greenwich on November 24, 4714 B.C. according to the Gregorian
|
||||
** calendar system.
|
||||
**
|
||||
** 1970-01-01 00:00:00 is JD 2440587.5
|
||||
** 2000-01-01 00:00:00 is JD 2451544.5
|
||||
**
|
||||
** This implemention requires years to be expressed as a 4-digit number
|
||||
** which means that only dates between 0000-01-01 and 9999-12-31 can
|
||||
** be represented, even though julian day numbers allow a much wider
|
||||
** range of dates.
|
||||
**
|
||||
** The Gregorian calendar system is used for all dates and times,
|
||||
** even those that predate the Gregorian calendar. Historians usually
|
||||
** use the Julian calendar for dates prior to 1582-10-15 and for some
|
||||
** dates afterwards, depending on locale. Beware of this difference.
|
||||
**
|
||||
** The conversion algorithms are implemented based on descriptions
|
||||
** in the following text:
|
||||
**
|
||||
** Jean Meeus
|
||||
** Astronomical Algorithms, 2nd Edition, 1998
|
||||
** ISBM 0-943396-61-1
|
||||
** Willmann-Bell, Inc
|
||||
** Richmond, Virginia (USA)
|
||||
*/
|
||||
#include "os.h"
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
|
||||
/*
|
||||
** A structure for holding a single date and time.
|
||||
*/
|
||||
typedef struct DateTime DateTime;
|
||||
struct DateTime {
|
||||
double rJD; /* The julian day number */
|
||||
int Y, M, D; /* Year, month, and day */
|
||||
int h, m; /* Hour and minutes */
|
||||
int tz; /* Timezone offset in minutes */
|
||||
double s; /* Seconds */
|
||||
char validYMD; /* True if Y,M,D are valid */
|
||||
char validHMS; /* True if h,m,s are valid */
|
||||
char validJD; /* True if rJD is valid */
|
||||
char validTZ; /* True if tz is valid */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** 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, ...){
|
||||
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(*zDate) ){
|
||||
return cnt;
|
||||
}
|
||||
val = val*10 + *zDate - '0';
|
||||
zDate++;
|
||||
}
|
||||
if( val<min || val>max || (nextC!=0 && nextC!=*zDate) ){
|
||||
return cnt;
|
||||
}
|
||||
*pVal = val;
|
||||
zDate++;
|
||||
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){
|
||||
const char *zEnd;
|
||||
*pR = sqliteAtoF(z, &zEnd);
|
||||
return zEnd - z;
|
||||
}
|
||||
|
||||
/*
|
||||
** Parse a timezone extension on the end of a date-time.
|
||||
** The extension is of the form:
|
||||
**
|
||||
** (+/-)HH:MM
|
||||
**
|
||||
** If the parse is successful, write the number of minutes
|
||||
** of change in *pnMin and return 0. If a parser error occurs,
|
||||
** return 0.
|
||||
**
|
||||
** A missing specifier is not considered an error.
|
||||
*/
|
||||
static int parseTimezone(const char *zDate, DateTime *p){
|
||||
int sgn = 0;
|
||||
int nHr, nMn;
|
||||
while( isspace(*zDate) ){ zDate++; }
|
||||
p->tz = 0;
|
||||
if( *zDate=='-' ){
|
||||
sgn = -1;
|
||||
}else if( *zDate=='+' ){
|
||||
sgn = +1;
|
||||
}else{
|
||||
return *zDate!=0;
|
||||
}
|
||||
zDate++;
|
||||
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++; }
|
||||
return *zDate!=0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Parse times of the form HH:MM or HH:MM:SS or HH:MM:SS.FFFF.
|
||||
** The HH, MM, and SS must each be exactly 2 digits. The
|
||||
** fractional seconds FFFF can be one or more digits.
|
||||
**
|
||||
** Return 1 if there is a parsing error and 0 on success.
|
||||
*/
|
||||
static int parseHhMmSs(const char *zDate, DateTime *p){
|
||||
int h, m, s;
|
||||
double ms = 0.0;
|
||||
if( getDigits(zDate, 2, 0, 24, ':', &h, 2, 0, 59, 0, &m)!=2 ){
|
||||
return 1;
|
||||
}
|
||||
zDate += 5;
|
||||
if( *zDate==':' ){
|
||||
zDate++;
|
||||
if( getDigits(zDate, 2, 0, 59, 0, &s)!=1 ){
|
||||
return 1;
|
||||
}
|
||||
zDate += 2;
|
||||
if( *zDate=='.' && isdigit(zDate[1]) ){
|
||||
double rScale = 1.0;
|
||||
zDate++;
|
||||
while( isdigit(*zDate) ){
|
||||
ms = ms*10.0 + *zDate - '0';
|
||||
rScale *= 10.0;
|
||||
zDate++;
|
||||
}
|
||||
ms /= rScale;
|
||||
}
|
||||
}else{
|
||||
s = 0;
|
||||
}
|
||||
p->validJD = 0;
|
||||
p->validHMS = 1;
|
||||
p->h = h;
|
||||
p->m = m;
|
||||
p->s = s + ms;
|
||||
if( parseTimezone(zDate, p) ) return 1;
|
||||
p->validTZ = p->tz!=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert from YYYY-MM-DD HH:MM:SS to julian day. We always assume
|
||||
** that the YYYY-MM-DD is according to the Gregorian calendar.
|
||||
**
|
||||
** Reference: Meeus page 61
|
||||
*/
|
||||
static void computeJD(DateTime *p){
|
||||
int Y, M, D, A, B, X1, X2;
|
||||
|
||||
if( p->validJD ) return;
|
||||
if( p->validYMD ){
|
||||
Y = p->Y;
|
||||
M = p->M;
|
||||
D = p->D;
|
||||
}else{
|
||||
Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
|
||||
M = 1;
|
||||
D = 1;
|
||||
}
|
||||
if( M<=2 ){
|
||||
Y--;
|
||||
M += 12;
|
||||
}
|
||||
A = Y/100;
|
||||
B = 2 - A + (A/4);
|
||||
X1 = 365.25*(Y+4716);
|
||||
X2 = 30.6001*(M+1);
|
||||
p->rJD = X1 + X2 + D + B - 1524.5;
|
||||
p->validJD = 1;
|
||||
p->validYMD = 0;
|
||||
if( p->validHMS ){
|
||||
p->rJD += (p->h*3600.0 + p->m*60.0 + p->s)/86400.0;
|
||||
if( p->validTZ ){
|
||||
p->rJD += p->tz*60/86400.0;
|
||||
p->validHMS = 0;
|
||||
p->validTZ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Parse dates of the form
|
||||
**
|
||||
** YYYY-MM-DD HH:MM:SS.FFF
|
||||
** YYYY-MM-DD HH:MM:SS
|
||||
** YYYY-MM-DD HH:MM
|
||||
** YYYY-MM-DD
|
||||
**
|
||||
** Write the result into the DateTime structure and return 0
|
||||
** on success and 1 if the input string is not a well-formed
|
||||
** date.
|
||||
*/
|
||||
static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
||||
int Y, M, D, neg;
|
||||
|
||||
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(*zDate) ){ zDate++; }
|
||||
if( parseHhMmSs(zDate, p)==0 ){
|
||||
/* We got the time */
|
||||
}else if( *zDate==0 ){
|
||||
p->validHMS = 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
p->validJD = 0;
|
||||
p->validYMD = 1;
|
||||
p->Y = neg ? -Y : Y;
|
||||
p->M = M;
|
||||
p->D = D;
|
||||
if( p->validTZ ){
|
||||
computeJD(p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to parse the given string into a Julian Day Number. Return
|
||||
** the number of errors.
|
||||
**
|
||||
** The following are acceptable forms for the input string:
|
||||
**
|
||||
** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
|
||||
** DDDD.DD
|
||||
** now
|
||||
**
|
||||
** In the first form, the +/-HH:MM is always optional. The fractional
|
||||
** seconds extension (the ".FFF") is optional. The seconds portion
|
||||
** (":SS.FFF") is option. The year and date can be omitted as long
|
||||
** as there is a time string. The time string can be omitted as long
|
||||
** as there is a year and date.
|
||||
*/
|
||||
static int parseDateOrTime(const char *zDate, DateTime *p){
|
||||
memset(p, 0, sizeof(*p));
|
||||
if( parseYyyyMmDd(zDate,p)==0 ){
|
||||
return 0;
|
||||
}else if( parseHhMmSs(zDate, p)==0 ){
|
||||
return 0;
|
||||
}else if( sqliteStrICmp(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 = sqliteAtoF(zDate, 0);
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Compute the Year, Month, and Day from the julian day number.
|
||||
*/
|
||||
static void computeYMD(DateTime *p){
|
||||
int Z, A, B, C, D, E, X1;
|
||||
if( p->validYMD ) return;
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
** Compute the Hour, Minute, and Seconds from the julian day number.
|
||||
*/
|
||||
static void computeHMS(DateTime *p){
|
||||
int Z, s;
|
||||
if( p->validHMS ) return;
|
||||
Z = p->rJD + 0.5;
|
||||
s = (p->rJD + 0.5 - Z)*86400000.0 + 0.5;
|
||||
p->s = 0.001*s;
|
||||
s = p->s;
|
||||
p->s -= s;
|
||||
p->h = s/3600;
|
||||
s -= p->h*3600;
|
||||
p->m = s/60;
|
||||
p->s += s - p->m*60;
|
||||
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;
|
||||
sqliteOsEnterMutex();
|
||||
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;
|
||||
sqliteOsLeaveMutex();
|
||||
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:
|
||||
**
|
||||
** NNN days
|
||||
** NNN hours
|
||||
** NNN minutes
|
||||
** NNN.NNNN seconds
|
||||
** NNN months
|
||||
** NNN years
|
||||
** start of month
|
||||
** start of year
|
||||
** start of week
|
||||
** start of day
|
||||
** weekday N
|
||||
** unixepoch
|
||||
** localtime
|
||||
** utc
|
||||
**
|
||||
** Return 0 on success and 1 if there is any kind of error.
|
||||
*/
|
||||
static int parseModifier(const char *zMod, DateTime *p){
|
||||
int rc = 1;
|
||||
int n;
|
||||
double r;
|
||||
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
|
||||
**
|
||||
** Treat the current value of p->rJD as the number of
|
||||
** seconds since 1970. Convert to a real julian day number.
|
||||
*/
|
||||
if( strcmp(z, "unixepoch")==0 && p->validJD ){
|
||||
p->rJD = p->rJD/86400.0 + 2440587.5;
|
||||
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;
|
||||
}
|
||||
case 'w': {
|
||||
/*
|
||||
** weekday N
|
||||
**
|
||||
** Move the date to the same time on the next occurrance of
|
||||
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
|
||||
** 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_HMS(p);
|
||||
p->validTZ = 0;
|
||||
p->validJD = 0;
|
||||
computeJD(p);
|
||||
Z = p->rJD + 1.5;
|
||||
Z %= 7;
|
||||
if( Z>n ) Z -= 7;
|
||||
p->rJD += n - Z;
|
||||
clearYMD_HMS_TZ(p);
|
||||
rc = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
/*
|
||||
** start of TTTTT
|
||||
**
|
||||
** Move the date backwards to the beginning of the current day,
|
||||
** or month or year.
|
||||
*/
|
||||
if( strncmp(z, "start of ", 9)!=0 ) break;
|
||||
z += 9;
|
||||
computeYMD(p);
|
||||
p->validHMS = 1;
|
||||
p->h = p->m = 0;
|
||||
p->s = 0.0;
|
||||
p->validTZ = 0;
|
||||
p->validJD = 0;
|
||||
if( strcmp(z,"month")==0 ){
|
||||
p->D = 1;
|
||||
rc = 0;
|
||||
}else if( strcmp(z,"year")==0 ){
|
||||
computeYMD(p);
|
||||
p->M = 1;
|
||||
p->D = 1;
|
||||
rc = 0;
|
||||
}else if( strcmp(z,"day")==0 ){
|
||||
rc = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '+':
|
||||
case '-':
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9': {
|
||||
n = getValue(z, &r);
|
||||
if( n<=0 ) break;
|
||||
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(*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(z[0]) ) z++;
|
||||
n = strlen(z);
|
||||
if( n>10 || n<3 ) break;
|
||||
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 ){
|
||||
p->rJD += r/24.0;
|
||||
}else if( n==6 && strcmp(z,"minute")==0 ){
|
||||
p->rJD += r/(24.0*60.0);
|
||||
}else if( n==6 && strcmp(z,"second")==0 ){
|
||||
p->rJD += r/(24.0*60.0*60.0);
|
||||
}else if( n==5 && strcmp(z,"month")==0 ){
|
||||
int x, y;
|
||||
computeYMD_HMS(p);
|
||||
p->M += r;
|
||||
x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
|
||||
p->Y += x;
|
||||
p->M -= x*12;
|
||||
p->validJD = 0;
|
||||
computeJD(p);
|
||||
y = r;
|
||||
if( y!=r ){
|
||||
p->rJD += (r - y)*30.0;
|
||||
}
|
||||
}else if( n==4 && strcmp(z,"year")==0 ){
|
||||
computeYMD_HMS(p);
|
||||
p->Y += r;
|
||||
p->validJD = 0;
|
||||
computeJD(p);
|
||||
}else{
|
||||
rc = 1;
|
||||
}
|
||||
clearYMD_HMS_TZ(p);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Process time function arguments. argv[0] is a date-time stamp.
|
||||
** argv[1] and following are modifiers. Parse them all and write
|
||||
** 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){
|
||||
int i;
|
||||
if( argc==0 ) return 1;
|
||||
if( argv[0]==0 || parseDateOrTime(argv[0], p) ) return 1;
|
||||
for(i=1; i<argc; i++){
|
||||
if( argv[i]==0 || parseModifier(argv[i], p) ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** The following routines implement the various date and time functions
|
||||
** of SQLite.
|
||||
*/
|
||||
|
||||
/*
|
||||
** julianday( TIMESTRING, MOD, MOD, ...)
|
||||
**
|
||||
** Return the julian day number of the date specified in the arguments
|
||||
*/
|
||||
static void juliandayFunc(sqlite_func *context, int argc, const char **argv){
|
||||
DateTime x;
|
||||
if( isDate(argc, argv, &x)==0 ){
|
||||
computeJD(&x);
|
||||
sqlite_set_result_double(context, x.rJD);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** datetime( TIMESTRING, MOD, MOD, ...)
|
||||
**
|
||||
** Return YYYY-MM-DD HH:MM:SS
|
||||
*/
|
||||
static void datetimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
DateTime x;
|
||||
if( isDate(argc, argv, &x)==0 ){
|
||||
char zBuf[100];
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** time( TIMESTRING, MOD, MOD, ...)
|
||||
**
|
||||
** Return HH:MM:SS
|
||||
*/
|
||||
static void timeFunc(sqlite_func *context, int argc, const char **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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** date( TIMESTRING, MOD, MOD, ...)
|
||||
**
|
||||
** Return YYYY-MM-DD
|
||||
*/
|
||||
static void dateFunc(sqlite_func *context, int argc, const char **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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
|
||||
**
|
||||
** Return a string described by FORMAT. Conversions as follows:
|
||||
**
|
||||
** %d day of month
|
||||
** %f ** fractional seconds SS.SSS
|
||||
** %H hour 00-24
|
||||
** %j day of year 000-366
|
||||
** %J ** Julian day number
|
||||
** %m month 01-12
|
||||
** %M minute 00-59
|
||||
** %s seconds since 1970-01-01
|
||||
** %S seconds 00-59
|
||||
** %w day of week 0-6 sunday==0
|
||||
** %W week of year 00-53
|
||||
** %Y year 0000-9999
|
||||
** %% %
|
||||
*/
|
||||
static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
|
||||
DateTime x;
|
||||
int n, i, j;
|
||||
char *z;
|
||||
const char *zFmt = argv[0];
|
||||
char zBuf[100];
|
||||
if( argv[0]==0 || isDate(argc-1, argv+1, &x) ) return;
|
||||
for(i=0, n=1; zFmt[i]; i++, n++){
|
||||
if( zFmt[i]=='%' ){
|
||||
switch( zFmt[i+1] ){
|
||||
case 'd':
|
||||
case 'H':
|
||||
case 'm':
|
||||
case 'M':
|
||||
case 'S':
|
||||
case 'W':
|
||||
n++;
|
||||
/* fall thru */
|
||||
case 'w':
|
||||
case '%':
|
||||
break;
|
||||
case 'f':
|
||||
n += 8;
|
||||
break;
|
||||
case 'j':
|
||||
n += 3;
|
||||
break;
|
||||
case 'Y':
|
||||
n += 8;
|
||||
break;
|
||||
case 's':
|
||||
case 'J':
|
||||
n += 50;
|
||||
break;
|
||||
default:
|
||||
return; /* ERROR. return a NULL */
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if( n<sizeof(zBuf) ){
|
||||
z = zBuf;
|
||||
}else{
|
||||
z = sqliteMalloc( n );
|
||||
if( z==0 ) return;
|
||||
}
|
||||
computeJD(&x);
|
||||
computeYMD_HMS(&x);
|
||||
for(i=j=0; zFmt[i]; i++){
|
||||
if( zFmt[i]!='%' ){
|
||||
z[j++] = zFmt[i];
|
||||
}else{
|
||||
i++;
|
||||
switch( zFmt[i] ){
|
||||
case 'd': sprintf(&z[j],"%02d",x.D); j+=2; break;
|
||||
case 'f': {
|
||||
int s = x.s;
|
||||
int ms = (x.s - s)*1000.0;
|
||||
sprintf(&z[j],"%02d.%03d",s,ms);
|
||||
j += strlen(&z[j]);
|
||||
break;
|
||||
}
|
||||
case 'H': sprintf(&z[j],"%02d",x.h); j+=2; break;
|
||||
case 'W': /* Fall thru */
|
||||
case 'j': {
|
||||
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;
|
||||
if( zFmt[i]=='W' ){
|
||||
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+1);
|
||||
j += 3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'J': sprintf(&z[j],"%.16g",x.rJD); j+=strlen(&z[j]); break;
|
||||
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 + 0.5));
|
||||
j += strlen(&z[j]);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
z[j] = 0;
|
||||
sqlite_set_result_string(context, z, -1);
|
||||
if( z!=zBuf ){
|
||||
sqliteFree(z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */
|
||||
|
||||
/*
|
||||
** 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){
|
||||
#ifndef SQLITE_OMIT_DATETIME_FUNCS
|
||||
static struct {
|
||||
char *zName;
|
||||
int nArg;
|
||||
int dataType;
|
||||
void (*xFunc)(sqlite_func*,int,const char**);
|
||||
} aFuncs[] = {
|
||||
{ "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 },
|
||||
};
|
||||
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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+304
-69
@@ -12,63 +12,117 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle DELETE FROM statements.
|
||||
**
|
||||
** $Id: delete.c,v 1.16 2001/10/08 13:22:32 drh Exp $
|
||||
** $Id: delete.c,v 1.61 2004/02/24 01:05:32 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Look up every table that is named in pSrc. If any table is not found,
|
||||
** 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 *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;
|
||||
}
|
||||
return pTab;
|
||||
}
|
||||
|
||||
/*
|
||||
** Check to make sure the given table is writable. If it is not
|
||||
** writable, generate an error message and return 1. If it is
|
||||
** writable return 0;
|
||||
*/
|
||||
int sqliteIsReadOnly(Parse *pParse, Table *pTab, int viewOk){
|
||||
if( pTab->readOnly ){
|
||||
sqliteErrorMsg(pParse, "table %s may not be modified", pTab->zName);
|
||||
return 1;
|
||||
}
|
||||
if( !viewOk && pTab->pSelect ){
|
||||
sqliteErrorMsg(pParse, "cannot modify %s because it is a view",pTab->zName);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Process a DELETE FROM statement.
|
||||
*/
|
||||
void sqliteDeleteFrom(
|
||||
Parse *pParse, /* The parser context */
|
||||
Token *pTableName, /* The table from which we should delete things */
|
||||
SrcList *pTabList, /* The table from which we should delete things */
|
||||
Expr *pWhere /* The WHERE clause. May be null */
|
||||
){
|
||||
Vdbe *v; /* The virtual database engine */
|
||||
Table *pTab; /* The table from which records will be deleted */
|
||||
IdList *pTabList; /* An ID list holding pTab and nothing else */
|
||||
const char *zDb; /* Name of database holding pTab */
|
||||
int end, addr; /* 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 base; /* Index of the first available table cursor */
|
||||
int iCur; /* VDBE Cursor number for pTab */
|
||||
sqlite *db; /* Main database structure */
|
||||
int isView; /* True if attempting to delete from a view */
|
||||
AuthContext sContext; /* Authorization context */
|
||||
|
||||
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 */
|
||||
|
||||
sContext.pParse = 0;
|
||||
if( pParse->nErr || sqlite_malloc_failed ){
|
||||
pTabList = 0;
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
db = pParse->db;
|
||||
assert( pTabList->nSrc==1 );
|
||||
|
||||
/* Locate the table which we want to delete. This table has to be
|
||||
** put in an IdList structure because some of the subroutines we
|
||||
** put in an SrcList structure because some of the subroutines we
|
||||
** will be calling are designed to work with multiple tables and expect
|
||||
** an IdList* parameter instead of just a Table* parameger.
|
||||
** an SrcList* parameter instead of just a Table* parameter.
|
||||
*/
|
||||
pTabList = sqliteIdListAppend(0, pTableName);
|
||||
if( pTabList==0 ) goto delete_from_cleanup;
|
||||
for(i=0; i<pTabList->nId; i++){
|
||||
pTabList->a[i].pTab = sqliteFindTable(db, pTabList->a[i].zName);
|
||||
if( pTabList->a[i].pTab==0 ){
|
||||
sqliteSetString(&pParse->zErrMsg, "no such table: ",
|
||||
pTabList->a[i].zName, 0);
|
||||
pParse->nErr++;
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
if( pTabList->a[i].pTab->readOnly ){
|
||||
sqliteSetString(&pParse->zErrMsg, "table ", pTabList->a[i].zName,
|
||||
" may not be modified", 0);
|
||||
pParse->nErr++;
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
pTab = sqliteSrcListLookup(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;
|
||||
isView = pTab->pSelect!=0;
|
||||
if( sqliteIsReadOnly(pParse, pTab, before_triggers) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
assert( pTab->iDb<db->nDb );
|
||||
zDb = db->aDb[pTab->iDb].zName;
|
||||
if( sqliteAuthCheck(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) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
|
||||
/* Allocate a cursor used to store the old.* data for a trigger.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
oldIdx = pParse->nTab++;
|
||||
}
|
||||
pTab = pTabList->a[0].pTab;
|
||||
|
||||
/* Resolve the column names in all the expressions.
|
||||
*/
|
||||
assert( pTabList->nSrc==1 );
|
||||
iCur = pTabList->a[0].iCursor = pParse->nTab++;
|
||||
if( pWhere ){
|
||||
sqliteExprResolveInSelect(pParse, pWhere);
|
||||
if( sqliteExprResolveIds(pParse, pTabList, pWhere) ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, 0, pWhere) ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
|
||||
@@ -76,83 +130,264 @@ void sqliteDeleteFrom(
|
||||
}
|
||||
}
|
||||
|
||||
/* Start the view context
|
||||
*/
|
||||
if( isView ){
|
||||
sqliteAuthContextPush(pParse, &sContext, pTab->zName);
|
||||
}
|
||||
|
||||
/* Begin generating code.
|
||||
*/
|
||||
v = sqliteGetVdbe(pParse);
|
||||
if( v==0 ) goto delete_from_cleanup;
|
||||
if( (db->flags & SQLITE_InTrans)==0 ){
|
||||
sqliteVdbeAddOp(v, OP_Transaction, 0, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_VerifyCookie, db->schema_cookie, 0, 0, 0);
|
||||
pParse->schemaVerified = 1;
|
||||
if( v==0 ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
sqliteBeginWriteOperation(pParse, row_triggers_exist, pTab->iDb);
|
||||
|
||||
/* If we are trying to delete from a view, construct that view into
|
||||
** a temporary table.
|
||||
*/
|
||||
if( isView ){
|
||||
Select *pView = sqliteSelectDup(pTab->pSelect);
|
||||
sqliteSelect(pParse, pView, SRT_TempTable, iCur, 0, 0, 0);
|
||||
sqliteSelectDelete(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);
|
||||
}
|
||||
|
||||
/* Special case: A DELETE without a WHERE clause deletes everything.
|
||||
** It is easier just to erase the whole table.
|
||||
** 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 ){
|
||||
sqliteVdbeAddOp(v, OP_Clear, pTab->tnum, pTab->isTemp, 0, 0);
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
sqliteVdbeAddOp(v, OP_Clear, pIdx->tnum, pTab->isTemp, 0, 0);
|
||||
if( pWhere==0 && !row_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 addr;
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
}
|
||||
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);
|
||||
}
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Clear, pTab->tnum, pTab->iDb);
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
sqliteVdbeAddOp(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{
|
||||
int openOp;
|
||||
|
||||
/* Begin the database scan
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_ListOpen, 0, 0, 0, 0);
|
||||
pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 1);
|
||||
pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 1, 0);
|
||||
if( pWInfo==0 ) goto delete_from_cleanup;
|
||||
|
||||
/* Remember the key of every item to be deleted.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_ListWrite, 0, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
|
||||
}
|
||||
|
||||
/* End the database scan loop.
|
||||
*/
|
||||
sqliteWhereEnd(pWInfo);
|
||||
|
||||
/* Open the pseudo-table used to store OLD if there are triggers.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
}
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
base = pParse->nTab;
|
||||
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0, 0, 0);
|
||||
openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite;
|
||||
sqliteVdbeAddOp(v, openOp, base, pTab->tnum, 0, 0);
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
sqliteVdbeAddOp(v, openOp, base+i, pIdx->tnum, 0, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
end = sqliteVdbeMakeLabel(v);
|
||||
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, base, 0, 0, 0);
|
||||
if( pTab->pIndex ){
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
int j;
|
||||
sqliteVdbeAddOp(v, OP_Recno, base, 0, 0, 0);
|
||||
for(j=0; j<pIdx->nColumn; j++){
|
||||
sqliteVdbeAddOp(v, OP_Column, base, pIdx->aiColumn[j], 0, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_DeleteIdx, base+i, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Delete, base, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, addr, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_ListClose, 0, 0, 0, end);
|
||||
}
|
||||
if( (db->flags & SQLITE_InTrans)==0 ){
|
||||
sqliteVdbeAddOp(v, OP_Commit, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/* 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( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
|
||||
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
|
||||
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_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
|
||||
** 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;
|
||||
sqliteOpenTableAndIndices(pParse, pTab, iCur);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Delete the row */
|
||||
sqliteGenerateRowDelete(db, v, pTab, iCur, pParse->trigStack==0);
|
||||
}
|
||||
|
||||
/* If there are row triggers, close all cursors then invoke
|
||||
** the AFTER triggers
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
if( !isView ){
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1,
|
||||
oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
|
||||
addr);
|
||||
}
|
||||
|
||||
/* End of the delete loop */
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, addr);
|
||||
sqliteVdbeResolveLabel(v, end);
|
||||
sqliteVdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
|
||||
/* Close the cursors after the loop if there are no row triggers */
|
||||
if( !row_triggers_exist ){
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
pParse->nTab = iCur;
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_SetCounts, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
|
||||
/*
|
||||
** Return the number of rows that were deleted.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
|
||||
sqliteVdbeChangeP3(v, -1, "rows deleted", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
|
||||
delete_from_cleanup:
|
||||
sqliteIdListDelete(pTabList);
|
||||
sqliteAuthContextPop(&sContext);
|
||||
sqliteSrcListDelete(pTabList);
|
||||
sqliteExprDelete(pWhere);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine generates VDBE code that causes a single row of a
|
||||
** single table to be deleted.
|
||||
**
|
||||
** The VDBE must be in a particular state when this routine is called.
|
||||
** These are the requirements:
|
||||
**
|
||||
** 1. A read/write cursor pointing to pTab, the table containing the row
|
||||
** to be deleted, must be opened as cursor number "base".
|
||||
**
|
||||
** 2. Read/write cursors for all indices of pTab must be open as
|
||||
** cursor number base+i for the i-th index.
|
||||
**
|
||||
** 3. The record number of the row to be deleted must be on the top
|
||||
** of the stack.
|
||||
**
|
||||
** This routine pops the top of the stack to remove the record number
|
||||
** 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 */
|
||||
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?OPFLAG_NCHANGE:0) | OPFLAG_CSCHANGE);
|
||||
sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine generates VDBE code that causes the deletion of all
|
||||
** index entries associated with a single row of a single table.
|
||||
**
|
||||
** The VDBE must be in a particular state when this routine is called.
|
||||
** These are the requirements:
|
||||
**
|
||||
** 1. A read/write cursor pointing to pTab, the table containing the row
|
||||
** to be deleted, must be opened as cursor number "iCur".
|
||||
**
|
||||
** 2. Read/write cursors for all indices of pTab must be open as
|
||||
** cursor number iCur+i for the i-th index.
|
||||
**
|
||||
** 3. The "iCur" cursor must be pointing to the row that is to be
|
||||
** deleted.
|
||||
*/
|
||||
void sqliteGenerateRowIndexDelete(
|
||||
sqlite *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 */
|
||||
char *aIdxUsed /* Only delete if aIdxUsed!=0 && aIdxUsed[i]!=0 */
|
||||
){
|
||||
int i;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+254
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
** 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.12 2004/03/17 18:44:46 drh Exp $
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
** How This Encoder Works
|
||||
**
|
||||
** The output is allowed to contain any character except 0x27 (') and
|
||||
** 0x00. This is accomplished by using an escape character to encode
|
||||
** 0x27 and 0x00 as a two-byte sequence. The escape character is always
|
||||
** 0x01. An 0x00 is encoded as the two byte sequence 0x01 0x01. The
|
||||
** 0x27 character is encoded as the two byte sequence 0x01 0x28. Finally,
|
||||
** the escape character itself is encoded as the two-character sequence
|
||||
** 0x01 0x02.
|
||||
**
|
||||
** To summarize, the encoder works by using an escape sequences as follows:
|
||||
**
|
||||
** 0x00 -> 0x01 0x01
|
||||
** 0x01 -> 0x01 0x02
|
||||
** 0x27 -> 0x01 0x28
|
||||
**
|
||||
** If that were all the encoder did, it would work, but in certain cases
|
||||
** it could double the size of the encoded string. For example, to
|
||||
** encode a string of 100 0x27 characters would require 100 instances of
|
||||
** the 0x01 0x03 escape sequence resulting in a 200-character output.
|
||||
** We would prefer to keep the size of the encoded string smaller than
|
||||
** this.
|
||||
**
|
||||
** To minimize the encoding size, we first add a fixed offset value to each
|
||||
** byte in the sequence. The addition is modulo 256. (That is to say, if
|
||||
** the sum of the original character value and the offset exceeds 256, then
|
||||
** the higher order bits are truncated.) The offset is chosen to minimize
|
||||
** the number of characters in the string that need to be escaped. For
|
||||
** example, in the case above where the string was composed of 100 0x27
|
||||
** characters, the offset might be 0x01. Each of the 0x27 characters would
|
||||
** then be converted into an 0x28 character which would not need to be
|
||||
** escaped at all and so the 100 character input string would be converted
|
||||
** into just 100 characters of output. Actually 101 characters of output -
|
||||
** we have to record the offset used as the first byte in the sequence so
|
||||
** that the string can be decoded. Since the offset value is stored as
|
||||
** part of the output string and the output string is not allowed to contain
|
||||
** characters 0x00 or 0x27, the offset cannot be 0x00 or 0x27.
|
||||
**
|
||||
** Here, then, are the encoding steps:
|
||||
**
|
||||
** (1) Choose an offset value and make it the first character of
|
||||
** output.
|
||||
**
|
||||
** (2) Copy each input character into the output buffer, one by
|
||||
** one, adding the offset value as you copy.
|
||||
**
|
||||
** (3) If the value of an input character plus offset is 0x00, replace
|
||||
** that one character by the two-character sequence 0x01 0x01.
|
||||
** If the sum is 0x01, replace it with 0x01 0x02. If the sum
|
||||
** is 0x27, replace it with 0x01 0x03.
|
||||
**
|
||||
** (4) Put a 0x00 terminator at the end of the output.
|
||||
**
|
||||
** Decoding is obvious:
|
||||
**
|
||||
** (5) Copy encoded characters except the first into the decode
|
||||
** buffer. Set the first encoded character aside for use as
|
||||
** the offset in step 7 below.
|
||||
**
|
||||
** (6) Convert each 0x01 0x01 sequence into a single character 0x00.
|
||||
** Convert 0x01 0x02 into 0x01. Convert 0x01 0x28 into 0x27.
|
||||
**
|
||||
** (7) Subtract the offset value that was the first character of
|
||||
** the encoded buffer from all characters in the output buffer.
|
||||
**
|
||||
** The only tricky part is step (1) - how to compute an offset value to
|
||||
** minimize the size of the output buffer. This is accomplished by testing
|
||||
** all offset values and picking the one that results in the fewest number
|
||||
** of escapes. To do that, we first scan the entire input and count the
|
||||
** number of occurances of each character value in the input. Suppose
|
||||
** the number of 0x00 characters is N(0), the number of occurances of 0x01
|
||||
** is N(1), and so forth up to the number of occurances of 0xff is N(255).
|
||||
** An offset of 0 is not allowed so we don't have to test it. The number
|
||||
** of escapes required for an offset of 1 is N(1)+N(2)+N(40). The number
|
||||
** of escapes required for an offset of 2 is N(2)+N(3)+N(41). And so forth.
|
||||
** In this way we find the offset that gives the minimum number of escapes,
|
||||
** and thus minimizes the length of the output string.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Encode a binary buffer "in" of size n bytes so that it contains
|
||||
** no instances of characters '\'' or '\000'. The output is
|
||||
** null-terminated and can be used as a string value in an INSERT
|
||||
** or UPDATE statement. Use sqlite_decode_binary() to convert the
|
||||
** string back into its original binary.
|
||||
**
|
||||
** The result is written into a preallocated output buffer "out".
|
||||
** "out" must be able to hold at least 2 +(257*n)/254 bytes.
|
||||
** In other words, the output will be expanded by as much as 3
|
||||
** bytes for every 254 bytes of input plus 2 bytes of fixed overhead.
|
||||
** (This is approximately 2 + 1.0118*n or about a 1.2% size increase.)
|
||||
**
|
||||
** The return value is the number of characters in the encoded
|
||||
** string, excluding the "\000" terminator.
|
||||
**
|
||||
** If out==NULL then no output is generated but the routine still returns
|
||||
** the number of characters that would have been generated if out had
|
||||
** not been NULL.
|
||||
*/
|
||||
int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
|
||||
int i, j, e, m;
|
||||
unsigned char x;
|
||||
int cnt[256];
|
||||
if( n<=0 ){
|
||||
if( out ){
|
||||
out[0] = 'x';
|
||||
out[1] = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
memset(cnt, 0, sizeof(cnt));
|
||||
for(i=n-1; i>=0; i--){ cnt[in[i]]++; }
|
||||
m = n;
|
||||
for(i=1; i<256; i++){
|
||||
int sum;
|
||||
if( i=='\'' ) continue;
|
||||
sum = cnt[i] + cnt[(i+1)&0xff] + cnt[(i+'\'')&0xff];
|
||||
if( sum<m ){
|
||||
m = sum;
|
||||
e = i;
|
||||
if( m==0 ) break;
|
||||
}
|
||||
}
|
||||
if( out==0 ){
|
||||
return n+m+1;
|
||||
}
|
||||
out[0] = e;
|
||||
j = 1;
|
||||
for(i=0; i<n; i++){
|
||||
x = in[i] - e;
|
||||
if( x==0 || x==1 || x=='\''){
|
||||
out[j++] = 1;
|
||||
x++;
|
||||
}
|
||||
out[j++] = x;
|
||||
}
|
||||
out[j] = 0;
|
||||
assert( j==n+m+1 );
|
||||
return j;
|
||||
}
|
||||
|
||||
/*
|
||||
** Decode the string "in" into binary data and write it into "out".
|
||||
** This routine reverses the encoding created by sqlite_encode_binary().
|
||||
** The output will always be a few bytes less than the input. The number
|
||||
** of bytes of output is returned. If the input is not a well-formed
|
||||
** encoding, -1 is returned.
|
||||
**
|
||||
** The "in" and "out" parameters may point to the same buffer in order
|
||||
** to decode a string in place.
|
||||
*/
|
||||
int sqlite_decode_binary(const unsigned char *in, unsigned char *out){
|
||||
int i, e;
|
||||
unsigned char c;
|
||||
e = *(in++);
|
||||
i = 0;
|
||||
while( (c = *(in++))!=0 ){
|
||||
if( c==1 ){
|
||||
c = *(in++) - 1;
|
||||
}
|
||||
out[i++] = c + e;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
#ifdef ENCODER_TEST
|
||||
#include <stdio.h>
|
||||
/*
|
||||
** The subroutines above are not tested by the usual test suite. To test
|
||||
** these routines, compile just this one file with a -DENCODER_TEST=1 option
|
||||
** and run the result.
|
||||
*/
|
||||
int main(int argc, char **argv){
|
||||
int i, j, n, m, nOut, nByteIn, nByteOut;
|
||||
unsigned char in[30000];
|
||||
unsigned char out[33000];
|
||||
|
||||
nByteIn = nByteOut = 0;
|
||||
for(i=0; i<sizeof(in); i++){
|
||||
printf("Test %d: ", i+1);
|
||||
n = rand() % (i+1);
|
||||
if( i%100==0 ){
|
||||
int k;
|
||||
for(j=k=0; j<n; j++){
|
||||
/* if( k==0 || k=='\'' ) k++; */
|
||||
in[j] = k;
|
||||
k = (k+1)&0xff;
|
||||
}
|
||||
}else{
|
||||
for(j=0; j<n; j++) in[j] = rand() & 0xff;
|
||||
}
|
||||
nByteIn += n;
|
||||
nOut = sqlite_encode_binary(in, n, out);
|
||||
nByteOut += nOut;
|
||||
if( nOut!=strlen(out) ){
|
||||
printf(" ERROR return value is %d instead of %d\n", nOut, strlen(out));
|
||||
exit(1);
|
||||
}
|
||||
if( nOut!=sqlite_encode_binary(in, n, 0) ){
|
||||
printf(" ERROR actual output size disagrees with predicted size\n");
|
||||
exit(1);
|
||||
}
|
||||
m = (256*n + 1262)/253;
|
||||
printf("size %d->%d (max %d)", n, strlen(out)+1, m);
|
||||
if( strlen(out)+1>m ){
|
||||
printf(" ERROR output too big\n");
|
||||
exit(1);
|
||||
}
|
||||
for(j=0; out[j]; j++){
|
||||
if( out[j]=='\'' ){
|
||||
printf(" ERROR contains (')\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
j = sqlite_decode_binary(out, out);
|
||||
if( j!=n ){
|
||||
printf(" ERROR decode size %d\n", j);
|
||||
exit(1);
|
||||
}
|
||||
if( memcmp(in, out, n)!=0 ){
|
||||
printf(" ERROR decode mismatch\n");
|
||||
exit(1);
|
||||
}
|
||||
printf(" OK\n");
|
||||
}
|
||||
fprintf(stderr,"Finished. Total encoding: %d->%d bytes\n",
|
||||
nByteIn, nByteOut);
|
||||
fprintf(stderr,"Avg size increase: %.3f%%\n",
|
||||
(nByteOut-nByteIn)*100.0/(double)nByteIn);
|
||||
}
|
||||
#endif /* ENCODER_TEST */
|
||||
+1157
-487
File diff suppressed because it is too large
Load Diff
+658
@@ -0,0 +1,658 @@
|
||||
/*
|
||||
** 2002 February 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 the C functions that implement various SQL
|
||||
** functions of SQLite.
|
||||
**
|
||||
** There is only one exported symbol in this file - the function
|
||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.43.2.3 2004/07/18 23:03:11 drh Exp $
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
** Implementation of the non-aggregate min() and max() functions
|
||||
*/
|
||||
static void minmaxFunc(sqlite_func *context, int argc, const char **argv){
|
||||
const char *zBest;
|
||||
int i;
|
||||
int (*xCompare)(const char*, const char*);
|
||||
int mask; /* 0 for min() or 0xffffffff for max() */
|
||||
|
||||
if( argc==0 ) return;
|
||||
mask = (int)sqlite_user_data(context);
|
||||
zBest = argv[0];
|
||||
if( zBest==0 ) return;
|
||||
if( argv[1][0]=='n' ){
|
||||
xCompare = sqliteCompare;
|
||||
}else{
|
||||
xCompare = strcmp;
|
||||
}
|
||||
for(i=2; i<argc; i+=2){
|
||||
if( argv[i]==0 ) return;
|
||||
if( (xCompare(argv[i], zBest)^mask)<0 ){
|
||||
zBest = argv[i];
|
||||
}
|
||||
}
|
||||
sqlite_set_result_string(context, zBest, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the type of the argument.
|
||||
*/
|
||||
static void typeofFunc(sqlite_func *context, int argc, const char **argv){
|
||||
assert( argc==2 );
|
||||
sqlite_set_result_string(context, argv[1], -1);
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the length() function
|
||||
*/
|
||||
static void lengthFunc(sqlite_func *context, int argc, const char **argv){
|
||||
const char *z;
|
||||
int len;
|
||||
|
||||
assert( argc==1 );
|
||||
z = argv[0];
|
||||
if( z==0 ) return;
|
||||
#ifdef SQLITE_UTF8
|
||||
for(len=0; *z; z++){ if( (0xc0&*z)!=0x80 ) len++; }
|
||||
#else
|
||||
len = strlen(z);
|
||||
#endif
|
||||
sqlite_set_result_int(context, len);
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the abs() function
|
||||
*/
|
||||
static void absFunc(sqlite_func *context, int argc, const char **argv){
|
||||
const char *z;
|
||||
assert( argc==1 );
|
||||
z = argv[0];
|
||||
if( z==0 ) return;
|
||||
if( z[0]=='-' && isdigit(z[1]) ) z++;
|
||||
sqlite_set_result_string(context, z, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the substr() function
|
||||
*/
|
||||
static void substrFunc(sqlite_func *context, int argc, const char **argv){
|
||||
const char *z;
|
||||
#ifdef SQLITE_UTF8
|
||||
const char *z2;
|
||||
int i;
|
||||
#endif
|
||||
int p1, p2, len;
|
||||
assert( argc==3 );
|
||||
z = argv[0];
|
||||
if( z==0 ) return;
|
||||
p1 = atoi(argv[1]?argv[1]:0);
|
||||
p2 = atoi(argv[2]?argv[2]:0);
|
||||
#ifdef SQLITE_UTF8
|
||||
for(len=0, z2=z; *z2; z2++){ if( (0xc0&*z2)!=0x80 ) len++; }
|
||||
#else
|
||||
len = strlen(z);
|
||||
#endif
|
||||
if( p1<0 ){
|
||||
p1 += len;
|
||||
if( p1<0 ){
|
||||
p2 += p1;
|
||||
p1 = 0;
|
||||
}
|
||||
}else if( p1>0 ){
|
||||
p1--;
|
||||
}
|
||||
if( p1+p2>len ){
|
||||
p2 = len-p1;
|
||||
}
|
||||
#ifdef SQLITE_UTF8
|
||||
for(i=0; i<p1 && z[i]; i++){
|
||||
if( (z[i]&0xc0)==0x80 ) p1++;
|
||||
}
|
||||
while( z[i] && (z[i]&0xc0)==0x80 ){ i++; p1++; }
|
||||
for(; i<p1+p2 && z[i]; i++){
|
||||
if( (z[i]&0xc0)==0x80 ) p2++;
|
||||
}
|
||||
while( z[i] && (z[i]&0xc0)==0x80 ){ i++; p2++; }
|
||||
#endif
|
||||
if( p2<0 ) p2 = 0;
|
||||
sqlite_set_result_string(context, &z[p1], p2);
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the round() function
|
||||
*/
|
||||
static void roundFunc(sqlite_func *context, int argc, const char **argv){
|
||||
int n;
|
||||
double r;
|
||||
char zBuf[100];
|
||||
assert( argc==1 || argc==2 );
|
||||
if( argv[0]==0 || (argc==2 && argv[1]==0) ) return;
|
||||
n = argc==2 ? atoi(argv[1]) : 0;
|
||||
if( n>30 ) n = 30;
|
||||
if( n<0 ) n = 0;
|
||||
r = sqliteAtoF(argv[0], 0);
|
||||
sprintf(zBuf,"%.*f",n,r);
|
||||
sqlite_set_result_string(context, zBuf, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the upper() and lower() SQL functions.
|
||||
*/
|
||||
static void upperFunc(sqlite_func *context, int argc, const char **argv){
|
||||
unsigned char *z;
|
||||
int i;
|
||||
if( argc<1 || argv[0]==0 ) return;
|
||||
z = (unsigned char*)sqlite_set_result_string(context, argv[0], -1);
|
||||
if( z==0 ) return;
|
||||
for(i=0; z[i]; i++){
|
||||
if( islower(z[i]) ) z[i] = toupper(z[i]);
|
||||
}
|
||||
}
|
||||
static void lowerFunc(sqlite_func *context, int argc, const char **argv){
|
||||
unsigned char *z;
|
||||
int i;
|
||||
if( argc<1 || argv[0]==0 ) return;
|
||||
z = (unsigned char*)sqlite_set_result_string(context, argv[0], -1);
|
||||
if( z==0 ) return;
|
||||
for(i=0; z[i]; i++){
|
||||
if( isupper(z[i]) ) z[i] = tolower(z[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the IFNULL(), NVL(), and COALESCE() functions.
|
||||
** All three do the same thing. They return the first non-NULL
|
||||
** argument.
|
||||
*/
|
||||
static void ifnullFunc(sqlite_func *context, int argc, const char **argv){
|
||||
int i;
|
||||
for(i=0; i<argc; i++){
|
||||
if( argv[i] ){
|
||||
sqlite_set_result_string(context, argv[i], -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of random(). Return a random integer.
|
||||
*/
|
||||
static void randomFunc(sqlite_func *context, int argc, const char **argv){
|
||||
int r;
|
||||
sqliteRandomness(sizeof(r), &r);
|
||||
sqlite_set_result_int(context, r);
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the last_insert_rowid() SQL function. The return
|
||||
** value is the same as the sqlite_last_insert_rowid() API function.
|
||||
*/
|
||||
static void last_insert_rowid(sqlite_func *context, int arg, const char **argv){
|
||||
sqlite *db = sqlite_user_data(context);
|
||||
sqlite_set_result_int(context, sqlite_last_insert_rowid(db));
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the change_count() SQL function. The return
|
||||
** value is the same as the sqlite_changes() API function.
|
||||
*/
|
||||
static void change_count(sqlite_func *context, int arg, const char **argv){
|
||||
sqlite *db = sqlite_user_data(context);
|
||||
sqlite_set_result_int(context, sqlite_changes(db));
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the last_statement_change_count() SQL function. The
|
||||
** return value is the same as the sqlite_last_statement_changes() API function.
|
||||
*/
|
||||
static void last_statement_change_count(sqlite_func *context, int arg,
|
||||
const char **argv){
|
||||
sqlite *db = sqlite_user_data(context);
|
||||
sqlite_set_result_int(context, sqlite_last_statement_changes(db));
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the like() SQL function. This function implements
|
||||
** the build-in LIKE operator. The first argument to the function is the
|
||||
** string and the second argument is the pattern. So, the SQL statements:
|
||||
**
|
||||
** A LIKE B
|
||||
**
|
||||
** is implemented as like(A,B).
|
||||
*/
|
||||
static void likeFunc(sqlite_func *context, int arg, const char **argv){
|
||||
if( argv[0]==0 || argv[1]==0 ) return;
|
||||
sqlite_set_result_int(context,
|
||||
sqliteLikeCompare((const unsigned char*)argv[0],
|
||||
(const unsigned char*)argv[1]));
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the glob() SQL function. This function implements
|
||||
** the build-in GLOB operator. The first argument to the function is the
|
||||
** string and the second argument is the pattern. So, the SQL statements:
|
||||
**
|
||||
** A GLOB B
|
||||
**
|
||||
** is implemented as glob(A,B).
|
||||
*/
|
||||
static void globFunc(sqlite_func *context, int arg, const char **argv){
|
||||
if( argv[0]==0 || argv[1]==0 ) return;
|
||||
sqlite_set_result_int(context,
|
||||
sqliteGlobCompare((const unsigned char*)argv[0],
|
||||
(const unsigned char*)argv[1]));
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the NULLIF(x,y) function. The result is the first
|
||||
** argument if the arguments are different. The result is NULL if the
|
||||
** arguments are equal to each other.
|
||||
*/
|
||||
static void nullifFunc(sqlite_func *context, int argc, const char **argv){
|
||||
if( argv[0]!=0 && sqliteCompare(argv[0],argv[1])!=0 ){
|
||||
sqlite_set_result_string(context, argv[0], -1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the VERSION(*) function. The result is the version
|
||||
** of the SQLite library that is running.
|
||||
*/
|
||||
static void versionFunc(sqlite_func *context, int argc, const char **argv){
|
||||
sqlite_set_result_string(context, sqlite_version, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
** EXPERIMENTAL - This is not an official function. The interface may
|
||||
** change. This function may disappear. Do not write code that depends
|
||||
** on this function.
|
||||
**
|
||||
** Implementation of the QUOTE() function. This function takes a single
|
||||
** argument. If the argument is numeric, the return value is the same as
|
||||
** the argument. If the argument is NULL, the return value is the string
|
||||
** "NULL". Otherwise, the argument is enclosed in single quotes with
|
||||
** single-quote escapes.
|
||||
*/
|
||||
static void quoteFunc(sqlite_func *context, int argc, const char **argv){
|
||||
if( argc<1 ) return;
|
||||
if( argv[0]==0 ){
|
||||
sqlite_set_result_string(context, "NULL", 4);
|
||||
}else if( sqliteIsNumber(argv[0]) ){
|
||||
sqlite_set_result_string(context, argv[0], -1);
|
||||
}else{
|
||||
int i,j,n;
|
||||
char *z;
|
||||
for(i=n=0; argv[0][i]; i++){ if( argv[0][i]=='\'' ) n++; }
|
||||
z = sqliteMalloc( i+n+3 );
|
||||
if( z==0 ) return;
|
||||
z[0] = '\'';
|
||||
for(i=0, j=1; argv[0][i]; i++){
|
||||
z[j++] = argv[0][i];
|
||||
if( argv[0][i]=='\'' ){
|
||||
z[j++] = '\'';
|
||||
}
|
||||
}
|
||||
z[j++] = '\'';
|
||||
z[j] = 0;
|
||||
sqlite_set_result_string(context, z, j);
|
||||
sqliteFree(z);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SQLITE_SOUNDEX
|
||||
/*
|
||||
** Compute the soundex encoding of a word.
|
||||
*/
|
||||
static void soundexFunc(sqlite_func *context, int argc, const char **argv){
|
||||
char zResult[8];
|
||||
const char *zIn;
|
||||
int i, j;
|
||||
static const unsigned char iCode[] = {
|
||||
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, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
|
||||
1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
|
||||
1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
|
||||
};
|
||||
assert( argc==1 );
|
||||
zIn = argv[0];
|
||||
for(i=0; zIn[i] && !isalpha(zIn[i]); i++){}
|
||||
if( zIn[i] ){
|
||||
zResult[0] = toupper(zIn[i]);
|
||||
for(j=1; j<4 && zIn[i]; i++){
|
||||
int code = iCode[zIn[i]&0x7f];
|
||||
if( code>0 ){
|
||||
zResult[j++] = code + '0';
|
||||
}
|
||||
}
|
||||
while( j<4 ){
|
||||
zResult[j++] = '0';
|
||||
}
|
||||
zResult[j] = 0;
|
||||
sqlite_set_result_string(context, zResult, 4);
|
||||
}else{
|
||||
sqlite_set_result_string(context, "?000", 4);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** This function generates a string of random characters. Used for
|
||||
** generating test data.
|
||||
*/
|
||||
static void randStr(sqlite_func *context, int argc, const char **argv){
|
||||
static const unsigned char zSrc[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"0123456789"
|
||||
".-!,:*^+=_|?/<> ";
|
||||
int iMin, iMax, n, r, i;
|
||||
unsigned char zBuf[1000];
|
||||
if( argc>=1 ){
|
||||
iMin = atoi(argv[0]);
|
||||
if( iMin<0 ) iMin = 0;
|
||||
if( iMin>=sizeof(zBuf) ) iMin = sizeof(zBuf)-1;
|
||||
}else{
|
||||
iMin = 1;
|
||||
}
|
||||
if( argc>=2 ){
|
||||
iMax = atoi(argv[1]);
|
||||
if( iMax<iMin ) iMax = iMin;
|
||||
if( iMax>=sizeof(zBuf) ) iMax = sizeof(zBuf)-1;
|
||||
}else{
|
||||
iMax = 50;
|
||||
}
|
||||
n = iMin;
|
||||
if( iMax>iMin ){
|
||||
sqliteRandomness(sizeof(r), &r);
|
||||
r &= 0x7fffffff;
|
||||
n += r%(iMax + 1 - iMin);
|
||||
}
|
||||
assert( n<sizeof(zBuf) );
|
||||
sqliteRandomness(n, zBuf);
|
||||
for(i=0; i<n; i++){
|
||||
zBuf[i] = zSrc[zBuf[i]%(sizeof(zSrc)-1)];
|
||||
}
|
||||
zBuf[n] = 0;
|
||||
sqlite_set_result_string(context, zBuf, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** An instance of the following structure holds the context of a
|
||||
** sum() or avg() aggregate computation.
|
||||
*/
|
||||
typedef struct SumCtx SumCtx;
|
||||
struct SumCtx {
|
||||
double sum; /* Sum of terms */
|
||||
int cnt; /* Number of elements summed */
|
||||
};
|
||||
|
||||
/*
|
||||
** Routines used to compute the sum or average.
|
||||
*/
|
||||
static void sumStep(sqlite_func *context, int argc, const char **argv){
|
||||
SumCtx *p;
|
||||
if( argc<1 ) return;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
if( p && argv[0] ){
|
||||
p->sum += sqliteAtoF(argv[0], 0);
|
||||
p->cnt++;
|
||||
}
|
||||
}
|
||||
static void sumFinalize(sqlite_func *context){
|
||||
SumCtx *p;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
sqlite_set_result_double(context, p ? p->sum : 0.0);
|
||||
}
|
||||
static void avgFinalize(sqlite_func *context){
|
||||
SumCtx *p;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
if( p && p->cnt>0 ){
|
||||
sqlite_set_result_double(context, p->sum/(double)p->cnt);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** An instance of the following structure holds the context of a
|
||||
** variance or standard deviation computation.
|
||||
*/
|
||||
typedef struct StdDevCtx StdDevCtx;
|
||||
struct StdDevCtx {
|
||||
double sum; /* Sum of terms */
|
||||
double sum2; /* Sum of the squares of terms */
|
||||
int cnt; /* Number of terms counted */
|
||||
};
|
||||
|
||||
#if 0 /* Omit because math library is required */
|
||||
/*
|
||||
** Routines used to compute the standard deviation as an aggregate.
|
||||
*/
|
||||
static void stdDevStep(sqlite_func *context, int argc, const char **argv){
|
||||
StdDevCtx *p;
|
||||
double x;
|
||||
if( argc<1 ) return;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
if( p && argv[0] ){
|
||||
x = sqliteAtoF(argv[0], 0);
|
||||
p->sum += x;
|
||||
p->sum2 += x*x;
|
||||
p->cnt++;
|
||||
}
|
||||
}
|
||||
static void stdDevFinalize(sqlite_func *context){
|
||||
double rN = sqlite_aggregate_count(context);
|
||||
StdDevCtx *p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
if( p && p->cnt>1 ){
|
||||
double rCnt = cnt;
|
||||
sqlite_set_result_double(context,
|
||||
sqrt((p->sum2 - p->sum*p->sum/rCnt)/(rCnt-1.0)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The following structure keeps track of state information for the
|
||||
** count() aggregate function.
|
||||
*/
|
||||
typedef struct CountCtx CountCtx;
|
||||
struct CountCtx {
|
||||
int n;
|
||||
};
|
||||
|
||||
/*
|
||||
** Routines to implement the count() aggregate function.
|
||||
*/
|
||||
static void countStep(sqlite_func *context, int argc, const char **argv){
|
||||
CountCtx *p;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
if( (argc==0 || argv[0]) && p ){
|
||||
p->n++;
|
||||
}
|
||||
}
|
||||
static void countFinalize(sqlite_func *context){
|
||||
CountCtx *p;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
sqlite_set_result_int(context, p ? p->n : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** This function tracks state information for the min() and max()
|
||||
** aggregate functions.
|
||||
*/
|
||||
typedef struct MinMaxCtx MinMaxCtx;
|
||||
struct MinMaxCtx {
|
||||
char *z; /* The best so far */
|
||||
char zBuf[28]; /* Space that can be used for storage */
|
||||
};
|
||||
|
||||
/*
|
||||
** Routines to implement min() and max() aggregate functions.
|
||||
*/
|
||||
static void minmaxStep(sqlite_func *context, int argc, const char **argv){
|
||||
MinMaxCtx *p;
|
||||
int (*xCompare)(const char*, const char*);
|
||||
int mask; /* 0 for min() or 0xffffffff for max() */
|
||||
|
||||
assert( argc==2 );
|
||||
if( argv[0]==0 ) return; /* Ignore NULL values */
|
||||
if( argv[1][0]=='n' ){
|
||||
xCompare = sqliteCompare;
|
||||
}else{
|
||||
xCompare = strcmp;
|
||||
}
|
||||
mask = (int)sqlite_user_data(context);
|
||||
assert( mask==0 || mask==-1 );
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
if( p==0 || argc<1 ) return;
|
||||
if( p->z==0 || (xCompare(argv[0],p->z)^mask)<0 ){
|
||||
int len;
|
||||
if( p->zBuf[0] ){
|
||||
sqliteFree(p->z);
|
||||
}
|
||||
len = strlen(argv[0]);
|
||||
if( len < sizeof(p->zBuf)-1 ){
|
||||
p->z = &p->zBuf[1];
|
||||
p->zBuf[0] = 0;
|
||||
}else{
|
||||
p->z = sqliteMalloc( len+1 );
|
||||
p->zBuf[0] = 1;
|
||||
if( p->z==0 ) return;
|
||||
}
|
||||
strcpy(p->z, argv[0]);
|
||||
}
|
||||
}
|
||||
static void minMaxFinalize(sqlite_func *context){
|
||||
MinMaxCtx *p;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
if( p && p->z && p->zBuf[0]<2 ){
|
||||
sqlite_set_result_string(context, p->z, strlen(p->z));
|
||||
}
|
||||
if( p && p->zBuf[0] ){
|
||||
sqliteFree(p->z);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** 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 sqliteRegisterBuiltinFunctions(sqlite *db){
|
||||
static struct {
|
||||
char *zName;
|
||||
signed char nArg;
|
||||
signed char dataType;
|
||||
u8 argType; /* 0: none. 1: db 2: (-1) */
|
||||
void (*xFunc)(sqlite_func*,int,const char**);
|
||||
} aFuncs[] = {
|
||||
{ "min", -1, SQLITE_ARGS, 0, minmaxFunc },
|
||||
{ "min", 0, 0, 0, 0 },
|
||||
{ "max", -1, SQLITE_ARGS, 2, minmaxFunc },
|
||||
{ "max", 0, 0, 2, 0 },
|
||||
{ "typeof", 1, SQLITE_TEXT, 0, typeofFunc },
|
||||
{ "length", 1, SQLITE_NUMERIC, 0, lengthFunc },
|
||||
{ "substr", 3, SQLITE_TEXT, 0, substrFunc },
|
||||
{ "abs", 1, SQLITE_NUMERIC, 0, absFunc },
|
||||
{ "round", 1, SQLITE_NUMERIC, 0, roundFunc },
|
||||
{ "round", 2, SQLITE_NUMERIC, 0, roundFunc },
|
||||
{ "upper", 1, SQLITE_TEXT, 0, upperFunc },
|
||||
{ "lower", 1, SQLITE_TEXT, 0, lowerFunc },
|
||||
{ "coalesce", -1, SQLITE_ARGS, 0, ifnullFunc },
|
||||
{ "coalesce", 0, 0, 0, 0 },
|
||||
{ "coalesce", 1, 0, 0, 0 },
|
||||
{ "ifnull", 2, SQLITE_ARGS, 0, ifnullFunc },
|
||||
{ "random", -1, SQLITE_NUMERIC, 0, randomFunc },
|
||||
{ "like", 2, SQLITE_NUMERIC, 0, likeFunc },
|
||||
{ "glob", 2, SQLITE_NUMERIC, 0, globFunc },
|
||||
{ "nullif", 2, SQLITE_ARGS, 0, nullifFunc },
|
||||
{ "sqlite_version",0,SQLITE_TEXT, 0, versionFunc},
|
||||
{ "quote", 1, SQLITE_ARGS, 0, quoteFunc },
|
||||
{ "last_insert_rowid", 0, SQLITE_NUMERIC, 1, last_insert_rowid },
|
||||
{ "change_count", 0, SQLITE_NUMERIC, 1, change_count },
|
||||
{ "last_statement_change_count",
|
||||
0, SQLITE_NUMERIC, 1, last_statement_change_count },
|
||||
#ifdef SQLITE_SOUNDEX
|
||||
{ "soundex", 1, SQLITE_TEXT, 0, soundexFunc},
|
||||
#endif
|
||||
#ifdef SQLITE_TEST
|
||||
{ "randstr", 2, SQLITE_TEXT, 0, randStr },
|
||||
#endif
|
||||
};
|
||||
static struct {
|
||||
char *zName;
|
||||
signed char nArg;
|
||||
signed char dataType;
|
||||
u8 argType;
|
||||
void (*xStep)(sqlite_func*,int,const char**);
|
||||
void (*xFinalize)(sqlite_func*);
|
||||
} aAggs[] = {
|
||||
{ "min", 1, 0, 0, minmaxStep, minMaxFinalize },
|
||||
{ "max", 1, 0, 2, minmaxStep, minMaxFinalize },
|
||||
{ "sum", 1, SQLITE_NUMERIC, 0, sumStep, sumFinalize },
|
||||
{ "avg", 1, SQLITE_NUMERIC, 0, sumStep, avgFinalize },
|
||||
{ "count", 0, SQLITE_NUMERIC, 0, countStep, countFinalize },
|
||||
{ "count", 1, SQLITE_NUMERIC, 0, countStep, countFinalize },
|
||||
#if 0
|
||||
{ "stddev", 1, SQLITE_NUMERIC, 0, stdDevStep, stdDevFinalize },
|
||||
#endif
|
||||
};
|
||||
static const char *azTypeFuncs[] = { "min", "max", "typeof" };
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
|
||||
void *pArg;
|
||||
switch( aFuncs[i].argType ){
|
||||
case 0: pArg = 0; break;
|
||||
case 1: pArg = db; break;
|
||||
case 2: pArg = (void*)(-1); break;
|
||||
}
|
||||
sqlite_create_function(db, aFuncs[i].zName,
|
||||
aFuncs[i].nArg, aFuncs[i].xFunc, pArg);
|
||||
if( aFuncs[i].xFunc ){
|
||||
sqlite_function_type(db, aFuncs[i].zName, aFuncs[i].dataType);
|
||||
}
|
||||
}
|
||||
for(i=0; i<sizeof(aAggs)/sizeof(aAggs[0]); i++){
|
||||
void *pArg;
|
||||
switch( aAggs[i].argType ){
|
||||
case 0: pArg = 0; break;
|
||||
case 1: pArg = db; break;
|
||||
case 2: pArg = (void*)(-1); break;
|
||||
}
|
||||
sqlite_create_aggregate(db, aAggs[i].zName,
|
||||
aAggs[i].nArg, aAggs[i].xStep, aAggs[i].xFinalize, pArg);
|
||||
sqlite_function_type(db, aAggs[i].zName, aAggs[i].dataType);
|
||||
}
|
||||
for(i=0; i<sizeof(azTypeFuncs)/sizeof(azTypeFuncs[0]); i++){
|
||||
int n = strlen(azTypeFuncs[i]);
|
||||
FuncDef *p = sqliteHashFind(&db->aFunc, azTypeFuncs[i], n);
|
||||
while( p ){
|
||||
p->includeTypes = 1;
|
||||
p = p->pNext;
|
||||
}
|
||||
}
|
||||
sqliteRegisterDateTimeFunctions(db);
|
||||
}
|
||||
+64
-36
@@ -12,13 +12,22 @@
|
||||
** This is the implementation of generic hash-tables
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.c,v 1.1 2001/09/22 18:12:10 drh Exp $
|
||||
** $Id: hash.c,v 1.11 2004/01/08 02:17:33 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <assert.h>
|
||||
|
||||
/* 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.
|
||||
** 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
|
||||
** true if the hash table should make its own private copy of keys and
|
||||
** false if it should just use the supplied pointer. CopyKey only makes
|
||||
** 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 );
|
||||
@@ -33,6 +42,8 @@ void sqliteHashInit(Hash *new, int keyClass, int copyKey){
|
||||
}
|
||||
|
||||
/* 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){
|
||||
HashElem *elem; /* For looping over all elements of the table */
|
||||
@@ -64,16 +75,20 @@ static int intCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
return n2 - n1;
|
||||
}
|
||||
|
||||
#if 0 /* NOT USED */
|
||||
/*
|
||||
** Hash and comparison functions when the mode is SQLITE_HASH_POINTER
|
||||
*/
|
||||
static int ptrHash(const void *pKey, int nKey){
|
||||
nKey = (int)pKey;
|
||||
return nKey ^ (nKey<<8) ^ (nKey>>8);
|
||||
uptr x = Addr(pKey);
|
||||
return x ^ (x<<8) ^ (x>>8);
|
||||
}
|
||||
static int ptrCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
return ((int)pKey2) - (int)pKey1;
|
||||
if( pKey1==pKey2 ) return 0;
|
||||
if( pKey1<pKey2 ) return -1;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Hash and comparison functions when the mode is SQLITE_HASH_STRING
|
||||
@@ -95,8 +110,7 @@ static int binHash(const void *pKey, int nKey){
|
||||
while( nKey-- > 0 ){
|
||||
h = (h<<3) ^ h ^ *(z++);
|
||||
}
|
||||
if( h<0 ) h = -h;
|
||||
return h;
|
||||
return h & 0x7fffffff;
|
||||
}
|
||||
static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
if( n1!=n2 ) return n2-n1;
|
||||
@@ -105,13 +119,22 @@ static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
|
||||
|
||||
/*
|
||||
** Return a pointer to the appropriate hash function given the key class.
|
||||
**
|
||||
** The C syntax in this function definition may be unfamilar to some
|
||||
** programmers, so we provide the following additional explanation:
|
||||
**
|
||||
** The name of the function is "hashFunction". The function takes a
|
||||
** single parameter "keyClass". The return value of hashFunction()
|
||||
** is a pointer to another function. Specifically, the return value
|
||||
** of hashFunction() is a pointer to a function that takes two parameters
|
||||
** with types "const void*" and "int" and returns an "int".
|
||||
*/
|
||||
static int (*hashFunction(int keyClass))(const void*,int){
|
||||
switch( keyClass ){
|
||||
case SQLITE_HASH_INT: return intHash;
|
||||
case SQLITE_HASH_POINTER: return ptrHash;
|
||||
case SQLITE_HASH_STRING: return strHash;
|
||||
case SQLITE_HASH_BINARY: return binHash;;
|
||||
case SQLITE_HASH_INT: return &intHash;
|
||||
/* case SQLITE_HASH_POINTER: return &ptrHash; // NOT USED */
|
||||
case SQLITE_HASH_STRING: return &strHash;
|
||||
case SQLITE_HASH_BINARY: return &binHash;;
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
@@ -119,21 +142,25 @@ static int (*hashFunction(int keyClass))(const void*,int){
|
||||
|
||||
/*
|
||||
** Return a pointer to the appropriate hash function given the key class.
|
||||
**
|
||||
** For help in interpreted the obscure C code in the function definition,
|
||||
** see the header comment on the previous function.
|
||||
*/
|
||||
static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
|
||||
switch( keyClass ){
|
||||
case SQLITE_HASH_INT: return intCompare;
|
||||
case SQLITE_HASH_POINTER: return ptrCompare;
|
||||
case SQLITE_HASH_STRING: return strCompare;
|
||||
case SQLITE_HASH_BINARY: return binCompare;
|
||||
case SQLITE_HASH_INT: return &intCompare;
|
||||
/* case SQLITE_HASH_POINTER: return &ptrCompare; // NOT USED */
|
||||
case SQLITE_HASH_STRING: return &strCompare;
|
||||
case SQLITE_HASH_BINARY: return &binCompare;
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Resize the hash table. new_size must be a power of 2.
|
||||
** The hash table might fail to resize if sqliteMalloc() fails.
|
||||
/* Resize the hash table so that it cantains "new_size" buckets.
|
||||
** "new_size" must be a power of 2. The hash table might fail
|
||||
** to resize if sqliteMalloc() fails.
|
||||
*/
|
||||
static void rehash(Hash *pH, int new_size){
|
||||
struct _ht *new_ht; /* The new hash table */
|
||||
@@ -170,8 +197,8 @@ static void rehash(Hash *pH, int new_size){
|
||||
}
|
||||
|
||||
/* This function (for internal use only) locates an element in an
|
||||
** pH that matches the given key. The hash for this key has
|
||||
** already been computed and is passed as the 3rd parameter.
|
||||
** hash table that matches the given key. The hash for this key has
|
||||
** already been computed and is passed as the 4th parameter.
|
||||
*/
|
||||
static HashElem *findElementGivenHash(
|
||||
const Hash *pH, /* The pH to be searched */
|
||||
@@ -197,13 +224,13 @@ static HashElem *findElementGivenHash(
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Remove a single entry from the pH given a pointer to that
|
||||
/* Remove a single entry from the hash table given a pointer to that
|
||||
** element and a hash on the element's key.
|
||||
*/
|
||||
static void removeElementGivenHash(
|
||||
Hash *pH, /* The pH containing "elem" */
|
||||
HashElem* elem, /* The element to be removed from the pH */
|
||||
int h /* Hash value for the element */
|
||||
int h /* Hash value for the element */
|
||||
){
|
||||
if( elem->prev ){
|
||||
elem->prev->next = elem->next;
|
||||
@@ -227,9 +254,9 @@ static void removeElementGivenHash(
|
||||
pH->count--;
|
||||
}
|
||||
|
||||
/* Attempt to locate an element of the associative pH with a key
|
||||
** that matches "key". Return the data for this element if it is
|
||||
** found, or NULL if no match is found.
|
||||
/* Attempt to locate an element of the hash table pH with a key
|
||||
** 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){
|
||||
int h; /* A hash on key */
|
||||
@@ -245,21 +272,22 @@ void *sqliteHashFind(const Hash *pH, const void *pKey, int nKey){
|
||||
return elem ? elem->data : 0;
|
||||
}
|
||||
|
||||
/* Insert an element into the pH. The key will be "key" and
|
||||
** the data will be "data".
|
||||
/* Insert an element into the hash table pH. The key is pKey,nKey
|
||||
** and the data is "data".
|
||||
**
|
||||
** If no pH element exists with a matching key, then a new
|
||||
** pH element is created. The key is copied (using the copy
|
||||
** function of the key class) into the new element. NULL is returned.
|
||||
** If no element exists with a matching key, then a new
|
||||
** element is created. A copy of the key is made if the copyKey
|
||||
** flag is set. NULL is returned.
|
||||
**
|
||||
** If another element already exists with the same key, then the
|
||||
** new data replaces the old data and the old data is returned.
|
||||
** The key is not copied in this instance.
|
||||
** The key is not copied in this instance. If a malloc fails, then
|
||||
** the new data is returned and the hash table is unchanged.
|
||||
**
|
||||
** If the "data" parameter to this function is NULL, then the
|
||||
** element corresponding to "key" is removed from the pH.
|
||||
** element corresponding to "key" is removed from the hash table.
|
||||
*/
|
||||
void *sqliteHashInsert(Hash *pH, void *pKey, int nKey, void *data){
|
||||
void *sqliteHashInsert(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 */
|
||||
@@ -284,16 +312,16 @@ void *sqliteHashInsert(Hash *pH, void *pKey, int nKey, void *data){
|
||||
}
|
||||
if( data==0 ) return 0;
|
||||
new_elem = (HashElem*)sqliteMalloc( sizeof(HashElem) );
|
||||
if( new_elem==0 ) return 0;
|
||||
if( new_elem==0 ) return data;
|
||||
if( pH->copyKey && pKey!=0 ){
|
||||
new_elem->pKey = sqliteMalloc( nKey );
|
||||
new_elem->pKey = sqliteMallocRaw( nKey );
|
||||
if( new_elem->pKey==0 ){
|
||||
sqliteFree(new_elem);
|
||||
return 0;
|
||||
return data;
|
||||
}
|
||||
memcpy((void*)new_elem->pKey, pKey, nKey);
|
||||
}else{
|
||||
new_elem->pKey = pKey;
|
||||
new_elem->pKey = (void*)pKey;
|
||||
}
|
||||
new_elem->nKey = nKey;
|
||||
pH->count++;
|
||||
@@ -301,7 +329,7 @@ void *sqliteHashInsert(Hash *pH, void *pKey, int nKey, void *data){
|
||||
if( pH->htsize==0 ){
|
||||
pH->count = 0;
|
||||
sqliteFree(new_elem);
|
||||
return 0;
|
||||
return data;
|
||||
}
|
||||
if( pH->count > pH->htsize ){
|
||||
rehash(pH,pH->htsize*2);
|
||||
|
||||
+10
-3
@@ -12,7 +12,7 @@
|
||||
** This is the header file for the generic hash-table implemenation
|
||||
** used in SQLite.
|
||||
**
|
||||
** $Id: hash.h,v 1.2 2001/10/09 04:19:47 drh Exp $
|
||||
** $Id: hash.h,v 1.6 2004/01/08 02:17:33 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_HASH_H_
|
||||
#define _SQLITE_HASH_H_
|
||||
@@ -71,7 +71,7 @@ struct HashElem {
|
||||
** if the copyKey parameter to HashInit is 1.
|
||||
*/
|
||||
#define SQLITE_HASH_INT 1
|
||||
#define SQLITE_HASH_POINTER 2
|
||||
/* #define SQLITE_HASH_POINTER 2 // NOT USED */
|
||||
#define SQLITE_HASH_STRING 3
|
||||
#define SQLITE_HASH_BINARY 4
|
||||
|
||||
@@ -79,7 +79,7 @@ struct HashElem {
|
||||
** Access routines. To delete, insert a NULL pointer.
|
||||
*/
|
||||
void sqliteHashInit(Hash*, int keytype, int copyKey);
|
||||
void *sqliteHashInsert(Hash*, void *pKey, int nKey, void *pData);
|
||||
void *sqliteHashInsert(Hash*, const void *pKey, int nKey, void *pData);
|
||||
void *sqliteHashFind(const Hash*, const void *pKey, int nKey);
|
||||
void sqliteHashClear(Hash*);
|
||||
|
||||
@@ -98,5 +98,12 @@ void sqliteHashClear(Hash*);
|
||||
#define sqliteHashFirst(H) ((H)->first)
|
||||
#define sqliteHashNext(E) ((E)->next)
|
||||
#define sqliteHashData(E) ((E)->data)
|
||||
#define sqliteHashKey(E) ((E)->pKey)
|
||||
#define sqliteHashKeysize(E) ((E)->nKey)
|
||||
|
||||
/*
|
||||
** Number of entries in a hash table
|
||||
*/
|
||||
#define sqliteHashCount(H) ((H)->count)
|
||||
|
||||
#endif /* _SQLITE_HASH_H_ */
|
||||
|
||||
+779
-104
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle INSERT statements in SQLite.
|
||||
**
|
||||
** $Id: insert.c,v 1.22 2001/10/08 13:22:33 drh Exp $
|
||||
** $Id: insert.c,v 1.94 2004/02/24 01:05:33 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -30,45 +30,128 @@
|
||||
** statement above, and pSelect is NULL. For the second form, pList is
|
||||
** NULL and pSelect is a pointer to the select statement used to generate
|
||||
** data for the insert.
|
||||
**
|
||||
** The code generated follows one of three templates. For a simple
|
||||
** select with data coming from a VALUES clause, the code executes
|
||||
** once straight down through. The template looks like this:
|
||||
**
|
||||
** open write cursor to <table> and its indices
|
||||
** puts VALUES clause expressions onto the stack
|
||||
** write the resulting record into <table>
|
||||
** cleanup
|
||||
**
|
||||
** If the statement is of the form
|
||||
**
|
||||
** INSERT INTO <table> SELECT ...
|
||||
**
|
||||
** And the SELECT clause does not read from <table> at any time, then
|
||||
** the generated code follows this template:
|
||||
**
|
||||
** goto B
|
||||
** A: setup for the SELECT
|
||||
** loop over the tables in the SELECT
|
||||
** gosub C
|
||||
** end loop
|
||||
** cleanup after the SELECT
|
||||
** goto D
|
||||
** B: open write cursor to <table> and its indices
|
||||
** goto A
|
||||
** C: insert the select result into <table>
|
||||
** return
|
||||
** D: cleanup
|
||||
**
|
||||
** The third template is used if the insert statement takes its
|
||||
** values from a SELECT but the data is being inserted into a table
|
||||
** that is also read as part of the SELECT. In the third form,
|
||||
** we have to use a intermediate table to store the results of
|
||||
** the select. The template is like this:
|
||||
**
|
||||
** goto B
|
||||
** A: setup for the SELECT
|
||||
** loop over the tables in the SELECT
|
||||
** gosub C
|
||||
** end loop
|
||||
** cleanup after the SELECT
|
||||
** goto D
|
||||
** C: insert the select result into the intermediate table
|
||||
** return
|
||||
** B: open a cursor to an intermediate table
|
||||
** goto A
|
||||
** D: open write cursor to <table> and its indices
|
||||
** loop over the intermediate table
|
||||
** transfer values form intermediate table into <table>
|
||||
** end the loop
|
||||
** cleanup
|
||||
*/
|
||||
void sqliteInsert(
|
||||
Parse *pParse, /* Parser context */
|
||||
Token *pTableName, /* Name of table into which we are inserting */
|
||||
SrcList *pTabList, /* Name of table into which we are inserting */
|
||||
ExprList *pList, /* List of values to be inserted */
|
||||
Select *pSelect, /* A SELECT statement to use as the data source */
|
||||
IdList *pColumn /* Column names corresponding to IDLIST. */
|
||||
IdList *pColumn, /* Column names corresponding to IDLIST. */
|
||||
int onError /* How to handle constraint errors */
|
||||
){
|
||||
Table *pTab; /* The table to insert into */
|
||||
char *zTab; /* Name of the table into which we are inserting */
|
||||
const char *zDb; /* Name of the database holding this table */
|
||||
int i, j, idx; /* Loop counters */
|
||||
Vdbe *v; /* Generate code into this virtual machine */
|
||||
Index *pIdx; /* For looping over indices of the table */
|
||||
int srcTab; /* Date comes from this temporary cursor if >=0 */
|
||||
int nColumn; /* Number of columns in the data */
|
||||
int base; /* First available cursor */
|
||||
int base; /* VDBE Cursor number for pTab */
|
||||
int iCont, iBreak; /* Beginning and end of the loop over srcTab */
|
||||
sqlite *db; /* The main database structure */
|
||||
int openOp; /* Opcode used to open cursors */
|
||||
int keyColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
|
||||
int endOfLoop; /* Label for the end of the insertion loop */
|
||||
int useTempTable; /* Store SELECT results in intermediate table */
|
||||
int srcTab; /* Data comes from this temporary cursor if >=0 */
|
||||
int iSelectLoop; /* Address of code that implements the SELECT */
|
||||
int iCleanup; /* Address of the cleanup code */
|
||||
int iInsertBlock; /* Address of the subroutine used to insert data */
|
||||
int iCntMem; /* Memory cell used for the row counter */
|
||||
int isView; /* True if attempting to insert into a view */
|
||||
|
||||
int row_triggers_exist = 0; /* True if there are FOR EACH ROW triggers */
|
||||
int before_triggers; /* True if there are BEFORE triggers */
|
||||
int after_triggers; /* True if there are AFTER triggers */
|
||||
int newIdx = -1; /* Cursor for the NEW table */
|
||||
|
||||
if( pParse->nErr || sqlite_malloc_failed ) goto insert_cleanup;
|
||||
db = pParse->db;
|
||||
|
||||
/* Locate the table into which we will be inserting new information.
|
||||
*/
|
||||
zTab = sqliteTableNameFromToken(pTableName);
|
||||
assert( pTabList->nSrc==1 );
|
||||
zTab = pTabList->a[0].zName;
|
||||
if( zTab==0 ) goto insert_cleanup;
|
||||
pTab = sqliteFindTable(db, zTab);
|
||||
sqliteFree(zTab);
|
||||
pTab = sqliteSrcListLookup(pParse, pTabList);
|
||||
if( pTab==0 ){
|
||||
sqliteSetNString(&pParse->zErrMsg, "no such table: ", 0,
|
||||
pTableName->z, pTableName->n, 0);
|
||||
pParse->nErr++;
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( pTab->readOnly ){
|
||||
sqliteSetString(&pParse->zErrMsg, "table ", pTab->zName,
|
||||
" may not be modified", 0);
|
||||
pParse->nErr++;
|
||||
assert( pTab->iDb<db->nDb );
|
||||
zDb = db->aDb[pTab->iDb].zName;
|
||||
if( sqliteAuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
|
||||
/* Ensure that:
|
||||
* (a) the table is not read-only,
|
||||
* (b) that if it is a view then ON INSERT triggers exist
|
||||
*/
|
||||
before_triggers = sqliteTriggersExist(pParse, pTab->pTrigger, TK_INSERT,
|
||||
TK_BEFORE, TK_ROW, 0);
|
||||
after_triggers = sqliteTriggersExist(pParse, pTab->pTrigger, TK_INSERT,
|
||||
TK_AFTER, TK_ROW, 0);
|
||||
row_triggers_exist = before_triggers || after_triggers;
|
||||
isView = pTab->pSelect!=0;
|
||||
if( sqliteIsReadOnly(pParse, pTab, before_triggers) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( pTab==0 ) goto insert_cleanup;
|
||||
|
||||
/* If pTab is really a view, make sure it has been initialized.
|
||||
*/
|
||||
if( isView && sqliteViewGetColumnNames(pParse, pTab) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
|
||||
@@ -76,61 +159,124 @@ void sqliteInsert(
|
||||
*/
|
||||
v = sqliteGetVdbe(pParse);
|
||||
if( v==0 ) goto insert_cleanup;
|
||||
if( (db->flags & SQLITE_InTrans)==0 ){
|
||||
sqliteVdbeAddOp(v, OP_Transaction, 0, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_VerifyCookie, db->schema_cookie, 0, 0, 0);
|
||||
pParse->schemaVerified = 1;
|
||||
sqliteBeginWriteOperation(pParse, pSelect || row_triggers_exist, pTab->iDb);
|
||||
|
||||
/* if there are row triggers, allocate a temp table for new.* references. */
|
||||
if( row_triggers_exist ){
|
||||
newIdx = pParse->nTab++;
|
||||
}
|
||||
|
||||
/* Figure out how many columns of data are supplied. If the data
|
||||
** is comming from a SELECT statement, then this step has to generate
|
||||
** all the code to implement the SELECT statement and leave the data
|
||||
** in a temporary table. If data is coming from an expression list,
|
||||
** then we just have to count the number of expressions.
|
||||
** is coming from a SELECT statement, then this step also generates
|
||||
** all the code to implement the SELECT statement and invoke a subroutine
|
||||
** to process each row of the result. (Template 2.) If the SELECT
|
||||
** statement uses the the table that is being inserted into, then the
|
||||
** subroutine is also coded here. That subroutine stores the SELECT
|
||||
** results in a temporary table. (Template 3.)
|
||||
*/
|
||||
if( pSelect ){
|
||||
int rc;
|
||||
srcTab = pParse->nTab++;
|
||||
sqliteVdbeAddOp(v, OP_OpenTemp, srcTab, 0, 0, 0);
|
||||
rc = sqliteSelect(pParse, pSelect, SRT_Table, srcTab);
|
||||
/* Data is coming from a SELECT. Generate code to implement that SELECT
|
||||
*/
|
||||
int rc, iInitCode;
|
||||
iInitCode = sqliteVdbeAddOp(v, OP_Goto, 0, 0);
|
||||
iSelectLoop = sqliteVdbeCurrentAddr(v);
|
||||
iInsertBlock = sqliteVdbeMakeLabel(v);
|
||||
rc = sqliteSelect(pParse, pSelect, SRT_Subroutine, iInsertBlock, 0,0,0);
|
||||
if( rc || pParse->nErr || sqlite_malloc_failed ) goto insert_cleanup;
|
||||
iCleanup = sqliteVdbeMakeLabel(v);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, iCleanup);
|
||||
assert( pSelect->pEList );
|
||||
nColumn = pSelect->pEList->nExpr;
|
||||
|
||||
/* Set useTempTable to TRUE if the result of the SELECT statement
|
||||
** should be written into a temporary table. Set to FALSE if each
|
||||
** row of the SELECT can be written directly into the result table.
|
||||
**
|
||||
** A temp table must be used if the table being updated is also one
|
||||
** of the tables being read by the SELECT statement. Also use a
|
||||
** temp table in the case of row triggers.
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
useTempTable = 1;
|
||||
}else{
|
||||
int addr = sqliteVdbeFindOp(v, OP_OpenRead, pTab->tnum);
|
||||
useTempTable = 0;
|
||||
if( addr>0 ){
|
||||
VdbeOp *pOp = sqliteVdbeGetOp(v, addr-2);
|
||||
if( pOp->opcode==OP_Integer && pOp->p1==pTab->iDb ){
|
||||
useTempTable = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( useTempTable ){
|
||||
/* Generate the subroutine that SELECT calls to process each row of
|
||||
** the result. Store the result in a temporary table
|
||||
*/
|
||||
srcTab = pParse->nTab++;
|
||||
sqliteVdbeResolveLabel(v, iInsertBlock);
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, nColumn, 0);
|
||||
sqliteVdbeAddOp(v, OP_NewRecno, srcTab, 0);
|
||||
sqliteVdbeAddOp(v, OP_Pull, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, srcTab, 0);
|
||||
sqliteVdbeAddOp(v, OP_Return, 0, 0);
|
||||
|
||||
/* The following code runs first because the GOTO at the very top
|
||||
** of the program jumps to it. Create the temporary table, then jump
|
||||
** back up and execute the SELECT code above.
|
||||
*/
|
||||
sqliteVdbeChangeP2(v, iInitCode, sqliteVdbeCurrentAddr(v));
|
||||
sqliteVdbeAddOp(v, OP_OpenTemp, srcTab, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, iSelectLoop);
|
||||
sqliteVdbeResolveLabel(v, iCleanup);
|
||||
}else{
|
||||
sqliteVdbeChangeP2(v, iInitCode, sqliteVdbeCurrentAddr(v));
|
||||
}
|
||||
}else{
|
||||
/* This is the case if the data for the INSERT is coming from a VALUES
|
||||
** clause
|
||||
*/
|
||||
SrcList dummy;
|
||||
assert( pList!=0 );
|
||||
srcTab = -1;
|
||||
useTempTable = 0;
|
||||
assert( pList );
|
||||
nColumn = pList->nExpr;
|
||||
dummy.nSrc = 0;
|
||||
for(i=0; i<nColumn; i++){
|
||||
if( sqliteExprResolveIds(pParse, &dummy, 0, pList->a[i].pExpr) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pList->a[i].pExpr, 0, 0) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure the number of columns in the source data matches the number
|
||||
** of columns to be inserted into the table.
|
||||
*/
|
||||
if( pColumn==0 && nColumn!=pTab->nCol ){
|
||||
char zNum1[30];
|
||||
char zNum2[30];
|
||||
sprintf(zNum1,"%d", nColumn);
|
||||
sprintf(zNum2,"%d", pTab->nCol);
|
||||
sqliteSetString(&pParse->zErrMsg, "table ", pTab->zName,
|
||||
" has ", zNum2, " columns but ",
|
||||
zNum1, " values were supplied", 0);
|
||||
pParse->nErr++;
|
||||
sqliteErrorMsg(pParse,
|
||||
"table %S has %d columns but %d values were supplied",
|
||||
pTabList, 0, pTab->nCol, nColumn);
|
||||
goto insert_cleanup;
|
||||
}
|
||||
if( pColumn!=0 && nColumn!=pColumn->nId ){
|
||||
char zNum1[30];
|
||||
char zNum2[30];
|
||||
sprintf(zNum1,"%d", nColumn);
|
||||
sprintf(zNum2,"%d", pColumn->nId);
|
||||
sqliteSetString(&pParse->zErrMsg, zNum1, " values for ",
|
||||
zNum2, " columns", 0);
|
||||
pParse->nErr++;
|
||||
sqliteErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
|
||||
goto insert_cleanup;
|
||||
}
|
||||
|
||||
/* If the INSERT statement included an IDLIST term, then make sure
|
||||
** all elements of the IDLIST really are columns of the table and
|
||||
** remember the column indices.
|
||||
**
|
||||
** If the table has an INTEGER PRIMARY KEY column and that column
|
||||
** is named in the IDLIST, then record in the keyColumn variable
|
||||
** the index into IDLIST of the primary key column. keyColumn is
|
||||
** the index of the primary key as it appears in IDLIST, not as
|
||||
** is appears in the original table. (The index of the primary
|
||||
** key in the original table is pTab->iPKey.)
|
||||
*/
|
||||
if( pColumn ){
|
||||
for(i=0; i<pColumn->nId; i++){
|
||||
@@ -140,105 +286,634 @@ void sqliteInsert(
|
||||
for(j=0; j<pTab->nCol; j++){
|
||||
if( sqliteStrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
|
||||
pColumn->a[i].idx = j;
|
||||
if( j==pTab->iPKey ){
|
||||
keyColumn = i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( j>=pTab->nCol ){
|
||||
sqliteSetString(&pParse->zErrMsg, "table ", pTab->zName,
|
||||
" has no column named ", pColumn->a[i].zName, 0);
|
||||
pParse->nErr++;
|
||||
goto insert_cleanup;
|
||||
if( sqliteIsRowid(pColumn->a[i].zName) ){
|
||||
keyColumn = i;
|
||||
}else{
|
||||
sqliteErrorMsg(pParse, "table %S has no column named %s",
|
||||
pTabList, 0, pColumn->a[i].zName);
|
||||
pParse->nErr++;
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Open cursors into the table that is received the new data and
|
||||
** all indices of that table.
|
||||
/* If there is no IDLIST term but the table has an integer primary
|
||||
** key, the set the keyColumn variable to the primary key column index
|
||||
** in the original table definition.
|
||||
*/
|
||||
base = pParse->nTab;
|
||||
openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite;
|
||||
sqliteVdbeAddOp(v, openOp, base, pTab->tnum, pTab->zName, 0);
|
||||
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
|
||||
sqliteVdbeAddOp(v, openOp, idx+base, pIdx->tnum, pIdx->zName, 0);
|
||||
if( pColumn==0 ){
|
||||
keyColumn = pTab->iPKey;
|
||||
}
|
||||
|
||||
/* If the data source is a SELECT statement, then we have to create
|
||||
/* Open the temp table for FOR EACH ROW triggers
|
||||
*/
|
||||
if( row_triggers_exist ){
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
|
||||
}
|
||||
|
||||
/* Initialize the count of rows to be inserted
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
iCntMem = pParse->nMem++;
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, iCntMem, 1);
|
||||
}
|
||||
|
||||
/* Open tables and indices if there are no row triggers */
|
||||
if( !row_triggers_exist ){
|
||||
base = pParse->nTab;
|
||||
idx = sqliteOpenTableAndIndices(pParse, pTab, base);
|
||||
pParse->nTab += idx;
|
||||
}
|
||||
|
||||
/* If the data source is a temporary table, then we have to create
|
||||
** a loop because there might be multiple rows of data. If the data
|
||||
** source is an expression list, then exactly one row will be inserted
|
||||
** and the loop is not used.
|
||||
** source is a subroutine call from the SELECT statement, then we need
|
||||
** to launch the SELECT statement processing.
|
||||
*/
|
||||
if( srcTab>=0 ){
|
||||
sqliteVdbeAddOp(v, OP_Rewind, srcTab, 0, 0, 0);
|
||||
if( useTempTable ){
|
||||
iBreak = sqliteVdbeMakeLabel(v);
|
||||
iCont = sqliteVdbeAddOp(v, OP_Next, srcTab, iBreak, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Rewind, srcTab, iBreak);
|
||||
iCont = sqliteVdbeCurrentAddr(v);
|
||||
}else if( pSelect ){
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, iSelectLoop);
|
||||
sqliteVdbeResolveLabel(v, iInsertBlock);
|
||||
}
|
||||
|
||||
/* Create a new entry in the table and fill it with data.
|
||||
/* Run the BEFORE and INSTEAD OF triggers, if there are any
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_NewRecno, base, 0, 0, 0);
|
||||
if( pTab->pIndex ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0, 0, 0);
|
||||
}
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( pColumn==0 ){
|
||||
j = i;
|
||||
}else{
|
||||
for(j=0; j<pColumn->nId; j++){
|
||||
if( pColumn->a[j].idx==i ) break;
|
||||
}
|
||||
}
|
||||
if( pColumn && j>=pColumn->nId ){
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0, pTab->aCol[i].zDflt, 0);
|
||||
}else if( srcTab>=0 ){
|
||||
sqliteVdbeAddOp(v, OP_Column, srcTab, i, 0, 0);
|
||||
}else{
|
||||
sqliteExprCode(pParse, pList->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Put, base, 0, 0, 0);
|
||||
endOfLoop = sqliteVdbeMakeLabel(v);
|
||||
if( before_triggers ){
|
||||
|
||||
/* Create appropriate entries for the new data row in all indices
|
||||
** of the table.
|
||||
*/
|
||||
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
|
||||
if( pIdx->pNext ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0, 0, 0);
|
||||
/* build the NEW.* reference row. Note that if there is an INTEGER
|
||||
** PRIMARY KEY into which a NULL is being inserted, that NULL will be
|
||||
** translated into a unique ID for the row. But on a BEFORE trigger,
|
||||
** we do not know what the unique ID will be (because the insert has
|
||||
** not happened yet) so we substitute a rowid of -1
|
||||
*/
|
||||
if( keyColumn<0 ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, -1, 0);
|
||||
}else if( useTempTable ){
|
||||
sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
|
||||
}else if( pSelect ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, nColumn - keyColumn - 1, 1);
|
||||
}else{
|
||||
sqliteExprCode(pParse, pList->a[keyColumn].pExpr);
|
||||
sqliteVdbeAddOp(v, OP_NotNull, -1, sqliteVdbeCurrentAddr(v)+3);
|
||||
sqliteVdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, -1, 0);
|
||||
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
int idx = pIdx->aiColumn[i];
|
||||
|
||||
/* Create the new column data
|
||||
*/
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( pColumn==0 ){
|
||||
j = idx;
|
||||
j = i;
|
||||
}else{
|
||||
for(j=0; j<pColumn->nId; j++){
|
||||
if( pColumn->a[j].idx==idx ) break;
|
||||
if( pColumn->a[j].idx==i ) break;
|
||||
}
|
||||
}
|
||||
if( pColumn && j>=pColumn->nId ){
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0, pTab->aCol[idx].zDflt, 0);
|
||||
}else if( srcTab>=0 ){
|
||||
sqliteVdbeAddOp(v, OP_Column, srcTab, idx, 0, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
}else if( useTempTable ){
|
||||
sqliteVdbeAddOp(v, OP_Column, srcTab, j);
|
||||
}else if( pSelect ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, nColumn-j-1, 1);
|
||||
}else{
|
||||
sqliteExprCode(pParse, pList->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIdx, idx+base, pIdx->isUnique, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
|
||||
/* Fire BEFORE or INSTEAD OF triggers */
|
||||
if( sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab,
|
||||
newIdx, -1, onError, endOfLoop) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* If any triggers exists, the opening of tables and indices is deferred
|
||||
** until now.
|
||||
*/
|
||||
if( row_triggers_exist && !isView ){
|
||||
base = pParse->nTab;
|
||||
idx = sqliteOpenTableAndIndices(pParse, pTab, base);
|
||||
pParse->nTab += idx;
|
||||
}
|
||||
|
||||
/* Push the record number for the new entry onto the stack. The
|
||||
** record number is a randomly generate integer created by NewRecno
|
||||
** except when the table has an INTEGER PRIMARY KEY column, in which
|
||||
** case the record number is the same as that column.
|
||||
*/
|
||||
if( !isView ){
|
||||
if( keyColumn>=0 ){
|
||||
if( useTempTable ){
|
||||
sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
|
||||
}else if( pSelect ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, nColumn - keyColumn - 1, 1);
|
||||
}else{
|
||||
sqliteExprCode(pParse, pList->a[keyColumn].pExpr);
|
||||
}
|
||||
/* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
|
||||
** to generate a unique primary key value.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_NotNull, -1, sqliteVdbeCurrentAddr(v)+3);
|
||||
sqliteVdbeAddOp(v, OP_Pop, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
|
||||
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
|
||||
}
|
||||
|
||||
/* Push onto the stack, data for all columns of the new entry, beginning
|
||||
** with the first column.
|
||||
*/
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
/* The value of the INTEGER PRIMARY KEY column is always a NULL.
|
||||
** Whenever this column is read, the record number will be substituted
|
||||
** in its place. So will fill this column with a NULL to avoid
|
||||
** taking up data space with information that will never be used. */
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
continue;
|
||||
}
|
||||
if( pColumn==0 ){
|
||||
j = i;
|
||||
}else{
|
||||
for(j=0; j<pColumn->nId; j++){
|
||||
if( pColumn->a[j].idx==i ) break;
|
||||
}
|
||||
}
|
||||
if( pColumn && j>=pColumn->nId ){
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
}else if( useTempTable ){
|
||||
sqliteVdbeAddOp(v, OP_Column, srcTab, j);
|
||||
}else if( pSelect ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, i+nColumn-j, 1);
|
||||
}else{
|
||||
sqliteExprCode(pParse, pList->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate code to check constraints and generate index keys and
|
||||
** do the insertion.
|
||||
*/
|
||||
sqliteGenerateConstraintChecks(pParse, pTab, base, 0, keyColumn>=0,
|
||||
0, onError, endOfLoop);
|
||||
sqliteCompleteInsertion(pParse, pTab, base, 0,0,0,
|
||||
after_triggers ? newIdx : -1);
|
||||
}
|
||||
|
||||
/* Update the count of rows that are inserted
|
||||
*/
|
||||
if( (db->flags & SQLITE_CountRows)!=0 ){
|
||||
sqliteVdbeAddOp(v, OP_MemIncr, iCntMem, 0);
|
||||
}
|
||||
|
||||
if( row_triggers_exist ){
|
||||
/* Close all tables opened */
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Close, base, 0);
|
||||
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
|
||||
sqliteVdbeAddOp(v, OP_Close, idx+base, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Code AFTER triggers */
|
||||
if( sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_AFTER, pTab, newIdx, -1,
|
||||
onError, endOfLoop) ){
|
||||
goto insert_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* The bottom of the loop, if the data source is a SELECT statement
|
||||
*/
|
||||
if( srcTab>=0 ){
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, iCont, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Noop, 0, 0, 0, iBreak);
|
||||
}
|
||||
if( (db->flags & SQLITE_InTrans)==0 ){
|
||||
sqliteVdbeAddOp(v, OP_Commit, 0, 0, 0, 0);
|
||||
sqliteVdbeResolveLabel(v, endOfLoop);
|
||||
if( useTempTable ){
|
||||
sqliteVdbeAddOp(v, OP_Next, srcTab, iCont);
|
||||
sqliteVdbeResolveLabel(v, iBreak);
|
||||
sqliteVdbeAddOp(v, OP_Close, srcTab, 0);
|
||||
}else if( pSelect ){
|
||||
sqliteVdbeAddOp(v, OP_Pop, nColumn, 0);
|
||||
sqliteVdbeAddOp(v, OP_Return, 0, 0);
|
||||
sqliteVdbeResolveLabel(v, iCleanup);
|
||||
}
|
||||
|
||||
if( !row_triggers_exist ){
|
||||
/* Close all tables opened */
|
||||
sqliteVdbeAddOp(v, OP_Close, base, 0);
|
||||
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
|
||||
sqliteVdbeAddOp(v, OP_Close, idx+base, 0);
|
||||
}
|
||||
}
|
||||
|
||||
sqliteVdbeAddOp(v, OP_SetCounts, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
|
||||
/*
|
||||
** Return the number of rows inserted.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
sqliteVdbeOp3(v, OP_ColumnName, 0, 1, "rows inserted", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_MemLoad, iCntMem, 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
|
||||
insert_cleanup:
|
||||
sqliteSrcListDelete(pTabList);
|
||||
if( pList ) sqliteExprListDelete(pList);
|
||||
if( pSelect ) sqliteSelectDelete(pSelect);
|
||||
sqliteIdListDelete(pColumn);
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code to do a constraint check prior to an INSERT or an UPDATE.
|
||||
**
|
||||
** When this routine is called, the stack contains (from bottom to top)
|
||||
** the following values:
|
||||
**
|
||||
** 1. The recno of the row to be updated before the update. This
|
||||
** value is omitted unless we are doing an UPDATE that involves a
|
||||
** change to the record number.
|
||||
**
|
||||
** 2. The recno of the row after the update.
|
||||
**
|
||||
** 3. The data in the first column of the entry after the update.
|
||||
**
|
||||
** i. Data from middle columns...
|
||||
**
|
||||
** N. The data in the last column of the entry after the update.
|
||||
**
|
||||
** The old recno shown as entry (1) above is omitted unless both isUpdate
|
||||
** and recnoChng are 1. isUpdate is true for UPDATEs and false for
|
||||
** INSERTs and recnoChng is true if the record number is being changed.
|
||||
**
|
||||
** The code generated by this routine pushes additional entries onto
|
||||
** the stack which are the keys for new index entries for the new record.
|
||||
** The order of index keys is the same as the order of the indices on
|
||||
** the pTable->pIndex list. A key is only created for index i if
|
||||
** aIdxUsed!=0 and aIdxUsed[i]!=0.
|
||||
**
|
||||
** This routine also generates code to check constraints. NOT NULL,
|
||||
** CHECK, and UNIQUE constraints are all checked. If a constraint fails,
|
||||
** then the appropriate action is performed. There are five possible
|
||||
** actions: ROLLBACK, ABORT, FAIL, REPLACE, and IGNORE.
|
||||
**
|
||||
** Constraint type Action What Happens
|
||||
** --------------- ---------- ----------------------------------------
|
||||
** any ROLLBACK The current transaction is rolled back and
|
||||
** sqlite_exec() returns immediately with a
|
||||
** return code of SQLITE_CONSTRAINT.
|
||||
**
|
||||
** any ABORT Back out changes from the current command
|
||||
** only (do not do a complete rollback) then
|
||||
** cause sqlite_exec() to return immediately
|
||||
** with SQLITE_CONSTRAINT.
|
||||
**
|
||||
** any FAIL Sqlite_exec() returns immediately with a
|
||||
** return code of SQLITE_CONSTRAINT. The
|
||||
** transaction is not rolled back and any
|
||||
** prior changes are retained.
|
||||
**
|
||||
** any IGNORE The record number and data is popped from
|
||||
** the stack and there is an immediate jump
|
||||
** to label ignoreDest.
|
||||
**
|
||||
** NOT NULL REPLACE The NULL value is replace by the default
|
||||
** value for that column. If the default value
|
||||
** is NULL, the action is the same as ABORT.
|
||||
**
|
||||
** UNIQUE REPLACE The other row that conflicts with the row
|
||||
** being inserted is removed.
|
||||
**
|
||||
** CHECK REPLACE Illegal. The results in an exception.
|
||||
**
|
||||
** Which action to take is determined by the overrideError parameter.
|
||||
** Or if overrideError==OE_Default, then the pParse->onError parameter
|
||||
** is used. Or if pParse->onError==OE_Default then the onError value
|
||||
** for the constraint is used.
|
||||
**
|
||||
** The calling routine must open a read/write cursor for pTab with
|
||||
** cursor number "base". All indices of pTab must also have open
|
||||
** read/write cursors with cursor number base+i for the i-th cursor.
|
||||
** Except, if there is no possibility of a REPLACE action then
|
||||
** cursors do not need to be open for indices where aIdxUsed[i]==0.
|
||||
**
|
||||
** If the isUpdate flag is true, it means that the "base" cursor is
|
||||
** initially pointing to an entry that is being updated. The isUpdate
|
||||
** flag causes extra code to be generated so that the "base" cursor
|
||||
** is still pointing at the same entry after the routine returns.
|
||||
** Without the isUpdate flag, the "base" cursor might be moved.
|
||||
*/
|
||||
void sqliteGenerateConstraintChecks(
|
||||
Parse *pParse, /* The parser context */
|
||||
Table *pTab, /* the table into which we are inserting */
|
||||
int base, /* Index of a read/write cursor pointing at pTab */
|
||||
char *aIdxUsed, /* Which indices are used. NULL means all are used */
|
||||
int recnoChng, /* True if the record number will change */
|
||||
int isUpdate, /* True for UPDATE, False for INSERT */
|
||||
int overrideError, /* Override onError to this if not OE_Default */
|
||||
int ignoreDest /* Jump to this label on an OE_Ignore resolution */
|
||||
){
|
||||
int i;
|
||||
Vdbe *v;
|
||||
int nCol;
|
||||
int onError;
|
||||
int addr;
|
||||
int extra;
|
||||
int iCur;
|
||||
Index *pIdx;
|
||||
int seenReplace = 0;
|
||||
int jumpInst1, jumpInst2;
|
||||
int contAddr;
|
||||
int hasTwoRecnos = (isUpdate && recnoChng);
|
||||
|
||||
v = sqliteGetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
|
||||
nCol = pTab->nCol;
|
||||
|
||||
/* Test all NOT NULL constraints.
|
||||
*/
|
||||
for(i=0; i<nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
continue;
|
||||
}
|
||||
onError = pTab->aCol[i].notNull;
|
||||
if( onError==OE_None ) continue;
|
||||
if( overrideError!=OE_Default ){
|
||||
onError = overrideError;
|
||||
}else if( pParse->db->onError!=OE_Default ){
|
||||
onError = pParse->db->onError;
|
||||
}else if( onError==OE_Default ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
if( onError==OE_Replace && pTab->aCol[i].zDflt==0 ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol-1-i, 1);
|
||||
addr = sqliteVdbeAddOp(v, OP_NotNull, 1, 0);
|
||||
switch( onError ){
|
||||
case OE_Rollback:
|
||||
case OE_Abort:
|
||||
case OE_Fail: {
|
||||
char *zMsg = 0;
|
||||
sqliteVdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, onError);
|
||||
sqliteSetString(&zMsg, pTab->zName, ".", pTab->aCol[i].zName,
|
||||
" may not be NULL", (char*)0);
|
||||
sqliteVdbeChangeP3(v, -1, zMsg, P3_DYNAMIC);
|
||||
break;
|
||||
}
|
||||
case OE_Ignore: {
|
||||
sqliteVdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
case OE_Replace: {
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Push, nCol-i, 0);
|
||||
break;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
|
||||
}
|
||||
|
||||
/* Test all CHECK constraints
|
||||
*/
|
||||
/**** TBD ****/
|
||||
|
||||
/* If we have an INTEGER PRIMARY KEY, make sure the primary key
|
||||
** of the new record does not previously exist. Except, if this
|
||||
** is an UPDATE and the primary key is not changing, that is OK.
|
||||
*/
|
||||
if( recnoChng ){
|
||||
onError = pTab->keyConf;
|
||||
if( overrideError!=OE_Default ){
|
||||
onError = overrideError;
|
||||
}else if( pParse->db->onError!=OE_Default ){
|
||||
onError = pParse->db->onError;
|
||||
}else if( onError==OE_Default ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
|
||||
if( isUpdate ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
jumpInst1 = sqliteVdbeAddOp(v, OP_Eq, 0, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol, 1);
|
||||
jumpInst2 = sqliteVdbeAddOp(v, OP_NotExists, base, 0);
|
||||
switch( onError ){
|
||||
default: {
|
||||
onError = OE_Abort;
|
||||
/* Fall thru into the next case */
|
||||
}
|
||||
case OE_Rollback:
|
||||
case OE_Abort:
|
||||
case OE_Fail: {
|
||||
sqliteVdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError,
|
||||
"PRIMARY KEY must be unique", P3_STATIC);
|
||||
break;
|
||||
}
|
||||
case OE_Replace: {
|
||||
sqliteGenerateRowIndexDelete(pParse->db, v, pTab, base, 0);
|
||||
if( isUpdate ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+hasTwoRecnos, 1);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
|
||||
}
|
||||
seenReplace = 1;
|
||||
break;
|
||||
}
|
||||
case OE_Ignore: {
|
||||
assert( seenReplace==0 );
|
||||
sqliteVdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
}
|
||||
contAddr = sqliteVdbeCurrentAddr(v);
|
||||
sqliteVdbeChangeP2(v, jumpInst2, contAddr);
|
||||
if( isUpdate ){
|
||||
sqliteVdbeChangeP2(v, jumpInst1, contAddr);
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Test all UNIQUE constraints by creating entries for each UNIQUE
|
||||
** index and making sure that duplicate entries do not already exist.
|
||||
** Add the new records to the indices as we go.
|
||||
*/
|
||||
extra = -1;
|
||||
for(iCur=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, iCur++){
|
||||
if( aIdxUsed && aIdxUsed[iCur]==0 ) continue; /* Skip unused indices */
|
||||
extra++;
|
||||
|
||||
/* Create a key for accessing the index entry */
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+extra, 1);
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
int idx = pIdx->aiColumn[i];
|
||||
if( idx==pTab->iPKey ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, i+extra+nCol+1, 1);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_Dup, i+extra+nCol-idx, 1);
|
||||
}
|
||||
}
|
||||
jumpInst1 = sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
|
||||
if( pParse->db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
|
||||
|
||||
/* Find out what action to take in case there is an indexing conflict */
|
||||
onError = pIdx->onError;
|
||||
if( onError==OE_None ) continue; /* pIdx is not a UNIQUE index */
|
||||
if( overrideError!=OE_Default ){
|
||||
onError = overrideError;
|
||||
}else if( pParse->db->onError!=OE_Default ){
|
||||
onError = pParse->db->onError;
|
||||
}else if( onError==OE_Default ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
if( seenReplace ){
|
||||
if( onError==OE_Ignore ) onError = OE_Replace;
|
||||
else if( onError==OE_Fail ) onError = OE_Abort;
|
||||
}
|
||||
|
||||
|
||||
/* Check to see if the new index entry will be unique */
|
||||
sqliteVdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRecnos, 1);
|
||||
jumpInst2 = sqliteVdbeAddOp(v, OP_IsUnique, base+iCur+1, 0);
|
||||
|
||||
/* Generate code that executes if the new index entry is not unique */
|
||||
switch( onError ){
|
||||
case OE_Rollback:
|
||||
case OE_Abort:
|
||||
case OE_Fail: {
|
||||
int j, n1, n2;
|
||||
char zErrMsg[200];
|
||||
strcpy(zErrMsg, pIdx->nColumn>1 ? "columns " : "column ");
|
||||
n1 = strlen(zErrMsg);
|
||||
for(j=0; j<pIdx->nColumn && n1<sizeof(zErrMsg)-30; j++){
|
||||
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
|
||||
n2 = strlen(zCol);
|
||||
if( j>0 ){
|
||||
strcpy(&zErrMsg[n1], ", ");
|
||||
n1 += 2;
|
||||
}
|
||||
if( n1+n2>sizeof(zErrMsg)-30 ){
|
||||
strcpy(&zErrMsg[n1], "...");
|
||||
n1 += 3;
|
||||
break;
|
||||
}else{
|
||||
strcpy(&zErrMsg[n1], zCol);
|
||||
n1 += n2;
|
||||
}
|
||||
}
|
||||
strcpy(&zErrMsg[n1],
|
||||
pIdx->nColumn>1 ? " are not unique" : " is not unique");
|
||||
sqliteVdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError, zErrMsg, 0);
|
||||
break;
|
||||
}
|
||||
case OE_Ignore: {
|
||||
assert( seenReplace==0 );
|
||||
sqliteVdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRecnos, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, ignoreDest);
|
||||
break;
|
||||
}
|
||||
case OE_Replace: {
|
||||
sqliteGenerateRowDelete(pParse->db, v, pTab, base, 0);
|
||||
if( isUpdate ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRecnos, 1);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
|
||||
}
|
||||
seenReplace = 1;
|
||||
break;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
contAddr = sqliteVdbeCurrentAddr(v);
|
||||
#if NULL_DISTINCT_FOR_UNIQUE
|
||||
sqliteVdbeChangeP2(v, jumpInst1, contAddr);
|
||||
#endif
|
||||
sqliteVdbeChangeP2(v, jumpInst2, contAddr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine generates code to finish the INSERT or UPDATE operation
|
||||
** that was started by a prior call to sqliteGenerateConstraintChecks.
|
||||
** The stack must contain keys for all active indices followed by data
|
||||
** and the recno for the new entry. This routine creates the new
|
||||
** entries in all indices and in the main table.
|
||||
**
|
||||
** The arguments to this routine should be the same as the first six
|
||||
** arguments to sqliteGenerateConstraintChecks.
|
||||
*/
|
||||
void sqliteCompleteInsertion(
|
||||
Parse *pParse, /* The parser context */
|
||||
Table *pTab, /* the table into which we are inserting */
|
||||
int base, /* Index of a read/write cursor pointing at pTab */
|
||||
char *aIdxUsed, /* Which indices are used. NULL means all are used */
|
||||
int recnoChng, /* True if the record number will change */
|
||||
int isUpdate, /* True for UPDATE, False for INSERT */
|
||||
int newIdx /* Index of NEW table for triggers. -1 if none */
|
||||
){
|
||||
int i;
|
||||
Vdbe *v;
|
||||
int nIdx;
|
||||
Index *pIdx;
|
||||
|
||||
v = sqliteGetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
|
||||
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
|
||||
for(i=nIdx-1; i>=0; i--){
|
||||
if( aIdxUsed && aIdxUsed[i]==0 ) continue;
|
||||
sqliteVdbeAddOp(v, OP_IdxPut, base+i+1, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
if( newIdx>=0 ){
|
||||
sqliteVdbeAddOp(v, OP_Dup, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, base,
|
||||
(pParse->trigStack?0:OPFLAG_NCHANGE) |
|
||||
(isUpdate?0:OPFLAG_LASTROWID) | OPFLAG_CSCHANGE);
|
||||
if( isUpdate && recnoChng ){
|
||||
sqliteVdbeAddOp(v, OP_Pop, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code that will open write cursors for a table and for all
|
||||
** indices of that table. The "base" parameter is the cursor number used
|
||||
** for the table. Indices are opened on subsequent cursors.
|
||||
**
|
||||
** Return the total number of cursors opened. This is always at least
|
||||
** 1 (for the main table) plus more for each cursor.
|
||||
*/
|
||||
int sqliteOpenTableAndIndices(Parse *pParse, Table *pTab, int base){
|
||||
int i;
|
||||
Index *pIdx;
|
||||
Vdbe *v = sqliteGetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenWrite, base, pTab->tnum, pTab->zName, P3_STATIC);
|
||||
for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenWrite, i+base, pIdx->tnum, pIdx->zName, P3_STATIC);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
+886
-266
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
#include <tcl.h>
|
||||
#include <string.h>
|
||||
#include "sqlite.h"
|
||||
|
||||
/*
|
||||
* If compiled on a machine that doesn't have a 32-bit integer,
|
||||
@@ -54,13 +55,13 @@ typedef char MD5Context[88];
|
||||
* Note: this code is harmless on little-endian machines.
|
||||
*/
|
||||
static void byteReverse (unsigned char *buf, unsigned longs){
|
||||
uint32 t;
|
||||
do {
|
||||
t = (uint32)((unsigned)buf[3]<<8 | buf[2]) << 16 |
|
||||
((unsigned)buf[1]<<8 | buf[0]);
|
||||
*(uint32 *)buf = t;
|
||||
buf += 4;
|
||||
} while (--longs);
|
||||
uint32 t;
|
||||
do {
|
||||
t = (uint32)((unsigned)buf[3]<<8 | buf[2]) << 16 |
|
||||
((unsigned)buf[1]<<8 | buf[0]);
|
||||
*(uint32 *)buf = t;
|
||||
buf += 4;
|
||||
} while (--longs);
|
||||
}
|
||||
/* The four core functions - F1 is optimized somewhat */
|
||||
|
||||
@@ -72,7 +73,7 @@ static void byteReverse (unsigned char *buf, unsigned longs){
|
||||
|
||||
/* This is the central step in the MD5 algorithm. */
|
||||
#define MD5STEP(f, w, x, y, z, data, s) \
|
||||
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
|
||||
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
|
||||
|
||||
/*
|
||||
* The core of the MD5 algorithm, this alters an existing MD5 hash to
|
||||
@@ -80,85 +81,85 @@ static void byteReverse (unsigned char *buf, unsigned longs){
|
||||
* the data and converts bytes into longwords for this routine.
|
||||
*/
|
||||
static void MD5Transform(uint32 buf[4], const uint32 in[16]){
|
||||
register uint32 a, b, c, d;
|
||||
register uint32 a, b, c, d;
|
||||
|
||||
a = buf[0];
|
||||
b = buf[1];
|
||||
c = buf[2];
|
||||
d = buf[3];
|
||||
a = buf[0];
|
||||
b = buf[1];
|
||||
c = buf[2];
|
||||
d = buf[3];
|
||||
|
||||
MD5STEP(F1, a, b, c, d, in[ 0]+0xd76aa478, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[ 1]+0xe8c7b756, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[ 2]+0x242070db, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[ 3]+0xc1bdceee, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[ 4]+0xf57c0faf, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[ 5]+0x4787c62a, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[ 6]+0xa8304613, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[ 7]+0xfd469501, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[ 8]+0x698098d8, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[ 9]+0x8b44f7af, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[10]+0xffff5bb1, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[11]+0x895cd7be, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[12]+0x6b901122, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[13]+0xfd987193, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[14]+0xa679438e, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[15]+0x49b40821, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[ 0]+0xd76aa478, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[ 1]+0xe8c7b756, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[ 2]+0x242070db, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[ 3]+0xc1bdceee, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[ 4]+0xf57c0faf, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[ 5]+0x4787c62a, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[ 6]+0xa8304613, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[ 7]+0xfd469501, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[ 8]+0x698098d8, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[ 9]+0x8b44f7af, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[10]+0xffff5bb1, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[11]+0x895cd7be, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[12]+0x6b901122, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[13]+0xfd987193, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[14]+0xa679438e, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[15]+0x49b40821, 22);
|
||||
|
||||
MD5STEP(F2, a, b, c, d, in[ 1]+0xf61e2562, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[ 6]+0xc040b340, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[11]+0x265e5a51, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[ 0]+0xe9b6c7aa, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[ 5]+0xd62f105d, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[10]+0x02441453, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[15]+0xd8a1e681, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[ 4]+0xe7d3fbc8, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[ 9]+0x21e1cde6, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[14]+0xc33707d6, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[ 3]+0xf4d50d87, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[ 8]+0x455a14ed, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[13]+0xa9e3e905, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[ 2]+0xfcefa3f8, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[ 7]+0x676f02d9, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[12]+0x8d2a4c8a, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[ 1]+0xf61e2562, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[ 6]+0xc040b340, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[11]+0x265e5a51, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[ 0]+0xe9b6c7aa, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[ 5]+0xd62f105d, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[10]+0x02441453, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[15]+0xd8a1e681, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[ 4]+0xe7d3fbc8, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[ 9]+0x21e1cde6, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[14]+0xc33707d6, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[ 3]+0xf4d50d87, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[ 8]+0x455a14ed, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[13]+0xa9e3e905, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[ 2]+0xfcefa3f8, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[ 7]+0x676f02d9, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[12]+0x8d2a4c8a, 20);
|
||||
|
||||
MD5STEP(F3, a, b, c, d, in[ 5]+0xfffa3942, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[ 8]+0x8771f681, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[11]+0x6d9d6122, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[14]+0xfde5380c, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[ 1]+0xa4beea44, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[ 4]+0x4bdecfa9, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[ 7]+0xf6bb4b60, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[10]+0xbebfbc70, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[13]+0x289b7ec6, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[ 0]+0xeaa127fa, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[ 3]+0xd4ef3085, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[ 6]+0x04881d05, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[ 9]+0xd9d4d039, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[12]+0xe6db99e5, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[15]+0x1fa27cf8, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[ 2]+0xc4ac5665, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[ 5]+0xfffa3942, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[ 8]+0x8771f681, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[11]+0x6d9d6122, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[14]+0xfde5380c, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[ 1]+0xa4beea44, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[ 4]+0x4bdecfa9, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[ 7]+0xf6bb4b60, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[10]+0xbebfbc70, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[13]+0x289b7ec6, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[ 0]+0xeaa127fa, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[ 3]+0xd4ef3085, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[ 6]+0x04881d05, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[ 9]+0xd9d4d039, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[12]+0xe6db99e5, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[15]+0x1fa27cf8, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[ 2]+0xc4ac5665, 23);
|
||||
|
||||
MD5STEP(F4, a, b, c, d, in[ 0]+0xf4292244, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[ 7]+0x432aff97, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[14]+0xab9423a7, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[ 5]+0xfc93a039, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[12]+0x655b59c3, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[ 3]+0x8f0ccc92, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[10]+0xffeff47d, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[ 1]+0x85845dd1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[ 8]+0x6fa87e4f, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[15]+0xfe2ce6e0, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[ 6]+0xa3014314, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[13]+0x4e0811a1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[ 4]+0xf7537e82, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[11]+0xbd3af235, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[ 2]+0x2ad7d2bb, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[ 9]+0xeb86d391, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[ 0]+0xf4292244, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[ 7]+0x432aff97, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[14]+0xab9423a7, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[ 5]+0xfc93a039, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[12]+0x655b59c3, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[ 3]+0x8f0ccc92, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[10]+0xffeff47d, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[ 1]+0x85845dd1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[ 8]+0x6fa87e4f, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[15]+0xfe2ce6e0, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[ 6]+0xa3014314, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[13]+0x4e0811a1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[ 4]+0xf7537e82, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[11]+0xbd3af235, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[ 2]+0x2ad7d2bb, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[ 9]+0xeb86d391, 21);
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -167,12 +168,12 @@ static void MD5Transform(uint32 buf[4], const uint32 in[16]){
|
||||
*/
|
||||
static void MD5Init(MD5Context *pCtx){
|
||||
struct Context *ctx = (struct Context *)pCtx;
|
||||
ctx->buf[0] = 0x67452301;
|
||||
ctx->buf[1] = 0xefcdab89;
|
||||
ctx->buf[2] = 0x98badcfe;
|
||||
ctx->buf[3] = 0x10325476;
|
||||
ctx->bits[0] = 0;
|
||||
ctx->bits[1] = 0;
|
||||
ctx->buf[0] = 0x67452301;
|
||||
ctx->buf[1] = 0xefcdab89;
|
||||
ctx->buf[2] = 0x98badcfe;
|
||||
ctx->buf[3] = 0x10325476;
|
||||
ctx->bits[0] = 0;
|
||||
ctx->bits[1] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -182,47 +183,47 @@ static void MD5Init(MD5Context *pCtx){
|
||||
static
|
||||
void MD5Update(MD5Context *pCtx, const unsigned char *buf, unsigned int len){
|
||||
struct Context *ctx = (struct Context *)pCtx;
|
||||
uint32 t;
|
||||
uint32 t;
|
||||
|
||||
/* Update bitcount */
|
||||
/* Update bitcount */
|
||||
|
||||
t = ctx->bits[0];
|
||||
if ((ctx->bits[0] = t + ((uint32)len << 3)) < t)
|
||||
ctx->bits[1]++; /* Carry from low to high */
|
||||
ctx->bits[1] += len >> 29;
|
||||
t = ctx->bits[0];
|
||||
if ((ctx->bits[0] = t + ((uint32)len << 3)) < t)
|
||||
ctx->bits[1]++; /* Carry from low to high */
|
||||
ctx->bits[1] += len >> 29;
|
||||
|
||||
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
|
||||
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
|
||||
|
||||
/* Handle any leading odd-sized chunks */
|
||||
/* Handle any leading odd-sized chunks */
|
||||
|
||||
if ( t ) {
|
||||
unsigned char *p = (unsigned char *)ctx->in + t;
|
||||
if ( t ) {
|
||||
unsigned char *p = (unsigned char *)ctx->in + t;
|
||||
|
||||
t = 64-t;
|
||||
if (len < t) {
|
||||
memcpy(p, buf, len);
|
||||
return;
|
||||
}
|
||||
memcpy(p, buf, t);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
buf += t;
|
||||
len -= t;
|
||||
}
|
||||
t = 64-t;
|
||||
if (len < t) {
|
||||
memcpy(p, buf, len);
|
||||
return;
|
||||
}
|
||||
memcpy(p, buf, t);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
buf += t;
|
||||
len -= t;
|
||||
}
|
||||
|
||||
/* Process data in 64-byte chunks */
|
||||
/* Process data in 64-byte chunks */
|
||||
|
||||
while (len >= 64) {
|
||||
memcpy(ctx->in, buf, 64);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
}
|
||||
while (len >= 64) {
|
||||
memcpy(ctx->in, buf, 64);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
/* Handle any remaining bytes of data. */
|
||||
/* Handle any remaining bytes of data. */
|
||||
|
||||
memcpy(ctx->in, buf, len);
|
||||
memcpy(ctx->in, buf, len);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -231,43 +232,43 @@ void MD5Update(MD5Context *pCtx, const unsigned char *buf, unsigned int len){
|
||||
*/
|
||||
static void MD5Final(unsigned char digest[16], MD5Context *pCtx){
|
||||
struct Context *ctx = (struct Context *)pCtx;
|
||||
unsigned count;
|
||||
unsigned char *p;
|
||||
unsigned count;
|
||||
unsigned char *p;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
count = (ctx->bits[0] >> 3) & 0x3F;
|
||||
/* Compute number of bytes mod 64 */
|
||||
count = (ctx->bits[0] >> 3) & 0x3F;
|
||||
|
||||
/* Set the first char of padding to 0x80. This is safe since there is
|
||||
always at least one byte free */
|
||||
p = ctx->in + count;
|
||||
*p++ = 0x80;
|
||||
/* Set the first char of padding to 0x80. This is safe since there is
|
||||
always at least one byte free */
|
||||
p = ctx->in + count;
|
||||
*p++ = 0x80;
|
||||
|
||||
/* Bytes of padding needed to make 64 bytes */
|
||||
count = 64 - 1 - count;
|
||||
/* Bytes of padding needed to make 64 bytes */
|
||||
count = 64 - 1 - count;
|
||||
|
||||
/* Pad out to 56 mod 64 */
|
||||
if (count < 8) {
|
||||
/* Two lots of padding: Pad the first block to 64 bytes */
|
||||
memset(p, 0, count);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
/* Pad out to 56 mod 64 */
|
||||
if (count < 8) {
|
||||
/* Two lots of padding: Pad the first block to 64 bytes */
|
||||
memset(p, 0, count);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
|
||||
/* Now fill the next block with 56 bytes */
|
||||
memset(ctx->in, 0, 56);
|
||||
} else {
|
||||
/* Pad block to 56 bytes */
|
||||
memset(p, 0, count-8);
|
||||
}
|
||||
byteReverse(ctx->in, 14);
|
||||
/* Now fill the next block with 56 bytes */
|
||||
memset(ctx->in, 0, 56);
|
||||
} else {
|
||||
/* Pad block to 56 bytes */
|
||||
memset(p, 0, count-8);
|
||||
}
|
||||
byteReverse(ctx->in, 14);
|
||||
|
||||
/* Append length in bits and transform */
|
||||
((uint32 *)ctx->in)[ 14 ] = ctx->bits[0];
|
||||
((uint32 *)ctx->in)[ 15 ] = ctx->bits[1];
|
||||
/* Append length in bits and transform */
|
||||
((uint32 *)ctx->in)[ 14 ] = ctx->bits[0];
|
||||
((uint32 *)ctx->in)[ 15 ] = ctx->bits[1];
|
||||
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
byteReverse((unsigned char *)ctx->buf, 4);
|
||||
memcpy(digest, ctx->buf, 16);
|
||||
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
byteReverse((unsigned char *)ctx->buf, 4);
|
||||
memcpy(digest, ctx->buf, 16);
|
||||
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -292,7 +293,7 @@ static void DigestToBase16(unsigned char *digest, char *zBuf){
|
||||
** A TCL command for md5. The argument is the text to be hashed. The
|
||||
** Result is the hash in base64.
|
||||
*/
|
||||
static int md5_cmd(ClientData cd, Tcl_Interp *interp, int argc, char **argv){
|
||||
static int md5_cmd(void*cd, Tcl_Interp *interp, int argc, const char **argv){
|
||||
MD5Context ctx;
|
||||
unsigned char digest[16];
|
||||
|
||||
@@ -312,7 +313,7 @@ static int md5_cmd(ClientData cd, Tcl_Interp *interp, int argc, char **argv){
|
||||
** A TCL command to take the md5 hash of a file. The argument is the
|
||||
** name of the file.
|
||||
*/
|
||||
static int md5file_cmd(ClientData cd, Tcl_Interp*interp, int argc, char **argv){
|
||||
static int md5file_cmd(void*cd, Tcl_Interp*interp, int argc, const char **argv){
|
||||
FILE *in;
|
||||
MD5Context ctx;
|
||||
unsigned char digest[16];
|
||||
@@ -346,7 +347,39 @@ static int md5file_cmd(ClientData cd, Tcl_Interp*interp, int argc, char **argv){
|
||||
** Register the two TCL commands above with the TCL interpreter.
|
||||
*/
|
||||
int Md5_Init(Tcl_Interp *interp){
|
||||
Tcl_CreateCommand(interp, "md5", md5_cmd, 0, 0);
|
||||
Tcl_CreateCommand(interp, "md5file", md5file_cmd, 0, 0);
|
||||
Tcl_CreateCommand(interp, "md5", (Tcl_CmdProc*)md5_cmd, 0, 0);
|
||||
Tcl_CreateCommand(interp, "md5file", (Tcl_CmdProc*)md5file_cmd, 0, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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){
|
||||
MD5Context *p;
|
||||
int i;
|
||||
if( argc<1 ) return;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
if( p==0 ) return;
|
||||
if( sqlite_aggregate_count(context)==1 ){
|
||||
MD5Init(p);
|
||||
}
|
||||
for(i=0; i<argc; i++){
|
||||
if( argv[i] ){
|
||||
MD5Update(p, (unsigned char*)argv[i], strlen(argv[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
static void md5finalize(sqlite_func *context){
|
||||
MD5Context *p;
|
||||
unsigned char digest[16];
|
||||
char zBuf[33];
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
MD5Final(digest,p);
|
||||
DigestToBase16(digest, zBuf);
|
||||
sqlite_set_result_string(context, zBuf, strlen(zBuf));
|
||||
}
|
||||
void Md5_Register(sqlite *db){
|
||||
sqlite_create_aggregate(db, "md5sum", -1, md5step, md5finalize, 0);
|
||||
}
|
||||
|
||||
@@ -17,14 +17,99 @@
|
||||
#ifndef _SQLITE_OS_H_
|
||||
#define _SQLITE_OS_H_
|
||||
|
||||
/*
|
||||
** Helpful hint: To get this to compile on HP/UX, add -D_INCLUDE_POSIX_SOURCE
|
||||
** to the compiler command line.
|
||||
*/
|
||||
|
||||
/*
|
||||
** These #defines should enable >2GB file support on Posix if the
|
||||
** underlying operating system supports it. If the OS lacks
|
||||
** large file support, or if the OS is windows, these should be no-ops.
|
||||
**
|
||||
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
|
||||
** on the compiler command line. This is necessary if you are compiling
|
||||
** on a recent machine (ex: RedHat 7.2) but you want your code to work
|
||||
** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2
|
||||
** without this option, LFS is enable. But LFS does not exist in the kernel
|
||||
** in RedHat 6.0, so the code won't work. Hence, for maximum binary
|
||||
** portability you should omit LFS.
|
||||
**
|
||||
** Similar is true for MacOS. LFS is only supported on MacOS 9 and later.
|
||||
*/
|
||||
#ifndef SQLITE_DISABLE_LFS
|
||||
# define _LARGE_FILE 1
|
||||
# ifndef _FILE_OFFSET_BITS
|
||||
# define _FILE_OFFSET_BITS 64
|
||||
# endif
|
||||
# define _LARGEFILE_SOURCE 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Temporary files are named starting with this prefix followed by 16 random
|
||||
** alphanumeric characters, and no file extension. They are stored in the
|
||||
** OS's standard temporary file directory, and are deleted prior to exit.
|
||||
** If sqlite is being embedded in another program, you may wish to change the
|
||||
** prefix to reflect your program's name, so that if your program exits
|
||||
** prematurely, old temporary files can be easily identified. This can be done
|
||||
** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
|
||||
*/
|
||||
#ifndef TEMP_FILE_PREFIX
|
||||
# define TEMP_FILE_PREFIX "sqlite_"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** 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)
|
||||
*/
|
||||
#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
|
||||
|
||||
/*
|
||||
** A handle for an open file is stored in an OsFile object.
|
||||
*/
|
||||
#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 */
|
||||
struct openCnt *pOpen; /* Info about all open fd's on this inode */
|
||||
struct lockInfo *pLock; /* Info about locks on this inode */
|
||||
int fd; /* The file descriptor */
|
||||
int locked; /* True if this instance holds the lock */
|
||||
int dirfd; /* File descriptor for the directory */
|
||||
};
|
||||
# define SQLITE_TEMPNAME_SIZE 200
|
||||
# if defined(HAVE_USLEEP) && HAVE_USLEEP
|
||||
@@ -37,30 +122,69 @@
|
||||
#if OS_WIN
|
||||
#include <windows.h>
|
||||
#include <winbase.h>
|
||||
typedef HANDLE OsFile;
|
||||
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;
|
||||
# if defined(__MINGW32__)
|
||||
# define _OFF_T_
|
||||
# endif
|
||||
# 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 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, int offset);
|
||||
int sqliteOsSync(OsFile);
|
||||
int sqliteOsTruncate(OsFile, int size);
|
||||
int sqliteOsFileSize(OsFile, int *pSize);
|
||||
int sqliteOsLock(OsFile, int wrlock);
|
||||
int sqliteOsUnlock(OsFile);
|
||||
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);
|
||||
void sqliteOsEnterMutex();
|
||||
void sqliteOsLeaveMutex();
|
||||
int sqliteOsCurrentTime(double*);
|
||||
void sqliteOsEnterMutex(void);
|
||||
void sqliteOsLeaveMutex(void);
|
||||
char *sqliteOsFullPathname(const char*);
|
||||
|
||||
|
||||
|
||||
|
||||
+1418
-302
File diff suppressed because it is too large
Load Diff
+48
-2
@@ -13,13 +13,41 @@
|
||||
** 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.11 2001/09/16 00:13:27 drh Exp $
|
||||
** @(#) $Id: pager.h,v 1.26 2004/02/11 02:18:07 drh Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
** The size of one page
|
||||
**
|
||||
** You can change this value to another (reasonable) value you want.
|
||||
** It need not be a power of two, though the interface to the disk
|
||||
** will likely be faster if it is.
|
||||
**
|
||||
** Experiments show that a page size of 1024 gives the best speed
|
||||
** for common usages. The speed differences for different sizes
|
||||
** such as 512, 2048, 4096, an so forth, is minimal. Note, however,
|
||||
** that changing the page size results in a completely imcompatible
|
||||
** file format.
|
||||
*/
|
||||
#ifndef SQLITE_PAGE_SIZE
|
||||
#define SQLITE_PAGE_SIZE 1024
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Number of extra bytes of data allocated at the end of each page and
|
||||
** stored on disk but not used by the higher level btree layer. Changing
|
||||
** this value results in a completely incompatible file format.
|
||||
*/
|
||||
#ifndef SQLITE_PAGE_RESERVE
|
||||
#define SQLITE_PAGE_RESERVE 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The total number of usable bytes stored on disk for each page.
|
||||
** The usable bytes come at the beginning of the page and the reserve
|
||||
** bytes come at the end.
|
||||
*/
|
||||
#define SQLITE_USABLE_SIZE (SQLITE_PAGE_SIZE-SQLITE_PAGE_RESERVE)
|
||||
|
||||
/*
|
||||
** Maximum number of pages in one database. (This is a limitation of
|
||||
@@ -38,7 +66,12 @@ typedef unsigned int Pgno;
|
||||
*/
|
||||
typedef struct Pager Pager;
|
||||
|
||||
int sqlitepager_open(Pager **ppPager,const char *zFilename,int nPage,int nEx);
|
||||
/*
|
||||
** 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);
|
||||
@@ -49,13 +82,26 @@ 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);
|
||||
void sqlitepager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
void sqlitepager_refdump(Pager*);
|
||||
int pager_refinfo_enable;
|
||||
int journal_format;
|
||||
#endif
|
||||
|
||||
+540
-160
@@ -14,21 +14,47 @@
|
||||
** the parser. Lemon will also generate a header file containing
|
||||
** numeric codes for all of the tokens.
|
||||
**
|
||||
** @(#) $Id: parse.y,v 1.35 2001/10/08 13:22:33 drh Exp $
|
||||
** @(#) $Id: parse.y,v 1.112 2004/02/22 18:40:57 drh Exp $
|
||||
*/
|
||||
%token_prefix TK_
|
||||
%token_type {Token}
|
||||
%default_type {Token}
|
||||
%extra_argument {Parse *pParse}
|
||||
%syntax_error {
|
||||
sqliteSetString(&pParse->zErrMsg,"syntax error",0);
|
||||
pParse->sErrToken = TOKEN;
|
||||
if( pParse->zErrMsg==0 ){
|
||||
if( TOKEN.z[0] ){
|
||||
sqliteErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
|
||||
}else{
|
||||
sqliteErrorMsg(pParse, "incomplete SQL statement");
|
||||
}
|
||||
}
|
||||
}
|
||||
%name sqliteParser
|
||||
%include {
|
||||
#include "sqliteInt.h"
|
||||
#include "parse.h"
|
||||
}
|
||||
|
||||
/*
|
||||
** An instance of this structure holds information about the
|
||||
** LIMIT clause of a SELECT statement.
|
||||
*/
|
||||
struct LimitVal {
|
||||
int limit; /* The LIMIT value. -1 if there is no limit */
|
||||
int offset; /* The OFFSET. 0 if there is none */
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of the following structure describes the event of a
|
||||
** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
|
||||
** TK_DELETE, or TK_INSTEAD. If the event is of the form
|
||||
**
|
||||
** UPDATE ON (a,b,c)
|
||||
**
|
||||
** Then the "b" IdList records the list "a,b,c".
|
||||
*/
|
||||
struct TrigEvent { int a; IdList * b; };
|
||||
|
||||
} // end %include
|
||||
|
||||
// These are extra tokens used by the lexer but never seen by the
|
||||
// parser. We put them in a rule so that the parser generator will
|
||||
@@ -37,24 +63,23 @@
|
||||
%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
|
||||
COLUMN AGG_FUNCTION.
|
||||
|
||||
// Input is zero or more commands.
|
||||
// Input is a single SQL command
|
||||
input ::= cmdlist.
|
||||
|
||||
// A list of commands is zero or more commands
|
||||
//
|
||||
cmdlist ::= cmdlist ecmd.
|
||||
cmdlist ::= ecmd.
|
||||
cmdlist ::= cmdlist SEMI ecmd.
|
||||
ecmd ::= explain cmd. {sqliteExec(pParse);}
|
||||
ecmd ::= cmd. {sqliteExec(pParse);}
|
||||
ecmd ::= .
|
||||
explain ::= EXPLAIN. {pParse->explain = 1;}
|
||||
ecmd ::= explain cmdx SEMI.
|
||||
ecmd ::= SEMI.
|
||||
cmdx ::= cmd. { sqliteExec(pParse); }
|
||||
explain ::= EXPLAIN. { sqliteBeginParse(pParse, 1); }
|
||||
explain ::= . { sqliteBeginParse(pParse, 0); }
|
||||
|
||||
///////////////////// Begin and end transactions. ////////////////////////////
|
||||
//
|
||||
cmd ::= BEGIN trans_opt. {sqliteBeginTransaction(pParse);}
|
||||
|
||||
cmd ::= BEGIN trans_opt onconf(R). {sqliteBeginTransaction(pParse,R);}
|
||||
trans_opt ::= .
|
||||
trans_opt ::= TRANSACTION.
|
||||
trans_opt ::= TRANSACTION ids.
|
||||
trans_opt ::= TRANSACTION nm.
|
||||
cmd ::= COMMIT trans_opt. {sqliteCommitTransaction(pParse);}
|
||||
cmd ::= END trans_opt. {sqliteCommitTransaction(pParse);}
|
||||
cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);}
|
||||
@@ -62,13 +87,19 @@ cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);}
|
||||
///////////////////// The CREATE TABLE statement ////////////////////////////
|
||||
//
|
||||
cmd ::= create_table create_table_args.
|
||||
create_table ::= CREATE(X) temp(T) TABLE ids(Y).
|
||||
{sqliteStartTable(pParse,&X,&Y,T);}
|
||||
create_table ::= CREATE(X) temp(T) TABLE nm(Y). {
|
||||
sqliteStartTable(pParse,&X,&Y,T,0);
|
||||
}
|
||||
%type temp {int}
|
||||
temp(A) ::= TEMP. {A = 1;}
|
||||
temp(A) ::= . {A = 0;}
|
||||
create_table_args ::= LP columnlist conslist_opt RP(X).
|
||||
{sqliteEndTable(pParse,&X);}
|
||||
create_table_args ::= LP columnlist conslist_opt RP(X). {
|
||||
sqliteEndTable(pParse,&X,0);
|
||||
}
|
||||
create_table_args ::= AS select(S). {
|
||||
sqliteEndTable(pParse,0,S);
|
||||
sqliteSelectDelete(S);
|
||||
}
|
||||
columnlist ::= columnlist COMMA column.
|
||||
columnlist ::= column.
|
||||
|
||||
@@ -77,32 +108,54 @@ columnlist ::= column.
|
||||
// an elaborate typename. Perhaps someday we'll do something with it.
|
||||
//
|
||||
column ::= columnid type carglist.
|
||||
columnid ::= ids(X). {sqliteAddColumn(pParse,&X);}
|
||||
columnid ::= nm(X). {sqliteAddColumn(pParse,&X);}
|
||||
|
||||
// An IDENTIFIER can be a generic identifier, or one of several
|
||||
// keywords. Any non-standard keyword can also be an identifier.
|
||||
// We also make DESC and identifier since it comes up so often (as
|
||||
// an abbreviation of "description").
|
||||
//
|
||||
%type id {Token}
|
||||
id(A) ::= DESC(X). {A = X;}
|
||||
id(A) ::= ASC(X). {A = X;}
|
||||
id(A) ::= DELIMITERS(X). {A = X;}
|
||||
id(A) ::= EXPLAIN(X). {A = X;}
|
||||
id(A) ::= VACUUM(X). {A = X;}
|
||||
id(A) ::= BEGIN(X). {A = X;}
|
||||
id(A) ::= END(X). {A = X;}
|
||||
id(A) ::= PRAGMA(X). {A = X;}
|
||||
id(A) ::= CLUSTER(X). {A = X;}
|
||||
id(A) ::= ID(X). {A = X;}
|
||||
id(A) ::= TEMP(X). {A = X;}
|
||||
|
||||
// The following directive causes tokens ABORT, AFTER, ASC, etc. to
|
||||
// fallback to ID if they will not parse as their original value.
|
||||
// This obviates the need for the "id" nonterminal.
|
||||
//
|
||||
%fallback ID
|
||||
ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT
|
||||
COPY DATABASE DEFERRED DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR
|
||||
GLOB IGNORE IMMEDIATE INITIALLY INSTEAD LIKE MATCH KEY
|
||||
OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT
|
||||
TEMP TRIGGER VACUUM VIEW.
|
||||
|
||||
// Define operator precedence early so that this is the first occurance
|
||||
// of the operator tokens in the grammer. Keeping the operators together
|
||||
// causes them to be assigned integer values that are close together,
|
||||
// which keeps parser tables smaller.
|
||||
//
|
||||
%left OR.
|
||||
%left AND.
|
||||
%right NOT.
|
||||
%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
|
||||
%left GT GE LT LE.
|
||||
%left BITAND BITOR LSHIFT RSHIFT.
|
||||
%left PLUS MINUS.
|
||||
%left STAR SLASH REM.
|
||||
%left CONCAT.
|
||||
%right UMINUS UPLUS BITNOT.
|
||||
|
||||
// And "ids" is an identifer-or-string.
|
||||
//
|
||||
%type ids {Token}
|
||||
ids(A) ::= id(X). {A = X;}
|
||||
ids(A) ::= ID(X). {A = X;}
|
||||
ids(A) ::= STRING(X). {A = X;}
|
||||
|
||||
// The name of a column or table can be any of the following:
|
||||
//
|
||||
%type nm {Token}
|
||||
nm(A) ::= ID(X). {A = X;}
|
||||
nm(A) ::= STRING(X). {A = X;}
|
||||
nm(A) ::= JOIN_KW(X). {A = X;}
|
||||
|
||||
type ::= .
|
||||
type ::= typename(X). {sqliteAddColumnType(pParse,&X,&X);}
|
||||
type ::= typename(X) LP signed RP(Y). {sqliteAddColumnType(pParse,&X,&Y);}
|
||||
@@ -111,12 +164,13 @@ type ::= typename(X) LP signed COMMA signed RP(Y).
|
||||
%type typename {Token}
|
||||
typename(A) ::= ids(X). {A = X;}
|
||||
typename(A) ::= typename(X) ids. {A = X;}
|
||||
signed ::= INTEGER.
|
||||
signed ::= PLUS INTEGER.
|
||||
signed ::= MINUS INTEGER.
|
||||
%type signed {int}
|
||||
signed(A) ::= INTEGER(X). { A = atoi(X.z); }
|
||||
signed(A) ::= PLUS INTEGER(X). { A = atoi(X.z); }
|
||||
signed(A) ::= MINUS INTEGER(X). { A = -atoi(X.z); }
|
||||
carglist ::= carglist carg.
|
||||
carglist ::= .
|
||||
carg ::= CONSTRAINT ids ccons.
|
||||
carg ::= CONSTRAINT nm ccons.
|
||||
carg ::= ccons.
|
||||
carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
|
||||
@@ -131,10 +185,43 @@ carg ::= DEFAULT NULL.
|
||||
// In addition to the type name, we also care about the primary key and
|
||||
// UNIQUE constraints.
|
||||
//
|
||||
ccons ::= NOT NULL. {sqliteAddNotNull(pParse);}
|
||||
ccons ::= PRIMARY KEY sortorder. {sqliteCreateIndex(pParse,0,0,0,1,0,0);}
|
||||
ccons ::= UNIQUE. {sqliteCreateIndex(pParse,0,0,0,1,0,0);}
|
||||
ccons ::= CHECK LP expr RP.
|
||||
ccons ::= NULL onconf.
|
||||
ccons ::= NOT NULL onconf(R). {sqliteAddNotNull(pParse, R);}
|
||||
ccons ::= PRIMARY KEY sortorder onconf(R). {sqliteAddPrimaryKey(pParse,0,R);}
|
||||
ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);}
|
||||
ccons ::= CHECK LP expr RP onconf.
|
||||
ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R).
|
||||
{sqliteCreateForeignKey(pParse,0,&T,TA,R);}
|
||||
ccons ::= defer_subclause(D). {sqliteDeferForeignKey(pParse,D);}
|
||||
ccons ::= COLLATE id(C). {
|
||||
sqliteAddCollateType(pParse, sqliteCollateType(C.z, C.n));
|
||||
}
|
||||
|
||||
// The next group of rules parses the arguments to a REFERENCES clause
|
||||
// that determine if the referential integrity checking is deferred or
|
||||
// or immediate and which determine what action to take if a ref-integ
|
||||
// check fails.
|
||||
//
|
||||
%type refargs {int}
|
||||
refargs(A) ::= . { A = OE_Restrict * 0x010101; }
|
||||
refargs(A) ::= refargs(X) refarg(Y). { A = (X & Y.mask) | Y.value; }
|
||||
%type refarg {struct {int value; int mask;}}
|
||||
refarg(A) ::= MATCH nm. { A.value = 0; A.mask = 0x000000; }
|
||||
refarg(A) ::= ON DELETE refact(X). { A.value = X; A.mask = 0x0000ff; }
|
||||
refarg(A) ::= ON UPDATE refact(X). { A.value = X<<8; A.mask = 0x00ff00; }
|
||||
refarg(A) ::= ON INSERT refact(X). { A.value = X<<16; A.mask = 0xff0000; }
|
||||
%type refact {int}
|
||||
refact(A) ::= SET NULL. { A = OE_SetNull; }
|
||||
refact(A) ::= SET DEFAULT. { A = OE_SetDflt; }
|
||||
refact(A) ::= CASCADE. { A = OE_Cascade; }
|
||||
refact(A) ::= RESTRICT. { A = OE_Restrict; }
|
||||
%type defer_subclause {int}
|
||||
defer_subclause(A) ::= NOT DEFERRABLE init_deferred_pred_opt(X). {A = X;}
|
||||
defer_subclause(A) ::= DEFERRABLE init_deferred_pred_opt(X). {A = X;}
|
||||
%type init_deferred_pred_opt {int}
|
||||
init_deferred_pred_opt(A) ::= . {A = 0;}
|
||||
init_deferred_pred_opt(A) ::= INITIALLY DEFERRED. {A = 1;}
|
||||
init_deferred_pred_opt(A) ::= INITIALLY IMMEDIATE. {A = 0;}
|
||||
|
||||
// For the time being, the only constraint we care about is the primary
|
||||
// key and UNIQUE. Both create indices.
|
||||
@@ -144,19 +231,54 @@ conslist_opt ::= COMMA conslist.
|
||||
conslist ::= conslist COMMA tcons.
|
||||
conslist ::= conslist tcons.
|
||||
conslist ::= tcons.
|
||||
tcons ::= CONSTRAINT ids.
|
||||
tcons ::= PRIMARY KEY LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,1,0,0);}
|
||||
tcons ::= UNIQUE LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,1,0,0);}
|
||||
tcons ::= CHECK expr.
|
||||
tcons ::= CONSTRAINT nm.
|
||||
tcons ::= PRIMARY KEY LP idxlist(X) RP onconf(R).
|
||||
{sqliteAddPrimaryKey(pParse,X,R);}
|
||||
tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
|
||||
{sqliteCreateIndex(pParse,0,0,X,R,0,0);}
|
||||
tcons ::= CHECK expr onconf.
|
||||
tcons ::= FOREIGN KEY LP idxlist(FA) RP
|
||||
REFERENCES nm(T) idxlist_opt(TA) refargs(R) defer_subclause_opt(D). {
|
||||
sqliteCreateForeignKey(pParse, FA, &T, TA, R);
|
||||
sqliteDeferForeignKey(pParse, D);
|
||||
}
|
||||
%type defer_subclause_opt {int}
|
||||
defer_subclause_opt(A) ::= . {A = 0;}
|
||||
defer_subclause_opt(A) ::= defer_subclause(X). {A = X;}
|
||||
|
||||
// The following is a non-standard extension that allows us to declare the
|
||||
// default behavior when there is a constraint conflict.
|
||||
//
|
||||
%type onconf {int}
|
||||
%type orconf {int}
|
||||
%type resolvetype {int}
|
||||
onconf(A) ::= . { A = OE_Default; }
|
||||
onconf(A) ::= ON CONFLICT resolvetype(X). { A = X; }
|
||||
orconf(A) ::= . { A = OE_Default; }
|
||||
orconf(A) ::= OR resolvetype(X). { A = X; }
|
||||
resolvetype(A) ::= ROLLBACK. { A = OE_Rollback; }
|
||||
resolvetype(A) ::= ABORT. { A = OE_Abort; }
|
||||
resolvetype(A) ::= FAIL. { A = OE_Fail; }
|
||||
resolvetype(A) ::= IGNORE. { A = OE_Ignore; }
|
||||
resolvetype(A) ::= REPLACE. { A = OE_Replace; }
|
||||
|
||||
////////////////////////// The DROP TABLE /////////////////////////////////////
|
||||
//
|
||||
cmd ::= DROP TABLE ids(X). {sqliteDropTable(pParse,&X);}
|
||||
cmd ::= DROP TABLE nm(X). {sqliteDropTable(pParse,&X,0);}
|
||||
|
||||
///////////////////// The CREATE VIEW statement /////////////////////////////
|
||||
//
|
||||
cmd ::= CREATE(X) temp(T) VIEW nm(Y) AS select(S). {
|
||||
sqliteCreateView(pParse, &X, &Y, S, T);
|
||||
}
|
||||
cmd ::= DROP VIEW nm(X). {
|
||||
sqliteDropTable(pParse, &X, 1);
|
||||
}
|
||||
|
||||
//////////////////////// The SELECT statement /////////////////////////////////
|
||||
//
|
||||
cmd ::= select(X). {
|
||||
sqliteSelect(pParse, X, SRT_Callback, 0);
|
||||
sqliteSelect(pParse, X, SRT_Callback, 0, 0, 0, 0);
|
||||
sqliteSelectDelete(X);
|
||||
}
|
||||
|
||||
@@ -166,21 +288,21 @@ cmd ::= select(X). {
|
||||
%destructor oneselect {sqliteSelectDelete($$);}
|
||||
|
||||
select(A) ::= oneselect(X). {A = X;}
|
||||
select(A) ::= select(X) joinop(Y) oneselect(Z). {
|
||||
select(A) ::= select(X) multiselect_op(Y) oneselect(Z). {
|
||||
if( Z ){
|
||||
Z->op = Y;
|
||||
Z->pPrior = X;
|
||||
}
|
||||
A = Z;
|
||||
}
|
||||
%type joinop {int}
|
||||
joinop(A) ::= UNION. {A = TK_UNION;}
|
||||
joinop(A) ::= UNION ALL. {A = TK_ALL;}
|
||||
joinop(A) ::= INTERSECT. {A = TK_INTERSECT;}
|
||||
joinop(A) ::= EXCEPT. {A = TK_EXCEPT;}
|
||||
%type multiselect_op {int}
|
||||
multiselect_op(A) ::= UNION. {A = TK_UNION;}
|
||||
multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
|
||||
multiselect_op(A) ::= INTERSECT. {A = TK_INTERSECT;}
|
||||
multiselect_op(A) ::= EXCEPT. {A = TK_EXCEPT;}
|
||||
oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
|
||||
groupby_opt(P) having_opt(Q) orderby_opt(Z). {
|
||||
A = sqliteSelectNew(W,X,Y,P,Q,Z,D);
|
||||
groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
|
||||
A = sqliteSelectNew(W,X,Y,P,Q,Z,D,L.limit,L.offset);
|
||||
}
|
||||
|
||||
// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
|
||||
@@ -192,8 +314,9 @@ distinct(A) ::= ALL. {A = 0;}
|
||||
distinct(A) ::= . {A = 0;}
|
||||
|
||||
// selcollist is a list of expressions that are to become the return
|
||||
// values of the SELECT statement. In the case of "SELECT * FROM ..."
|
||||
// the selcollist value is NULL.
|
||||
// values of the SELECT statement. The "*" in statements like
|
||||
// "SELECT * FROM ..." is encoded as a special expression with an
|
||||
// opcode of TK_ALL.
|
||||
//
|
||||
%type selcollist {ExprList*}
|
||||
%destructor selcollist {sqliteExprListDelete($$);}
|
||||
@@ -201,28 +324,108 @@ distinct(A) ::= . {A = 0;}
|
||||
%destructor sclp {sqliteExprListDelete($$);}
|
||||
sclp(A) ::= selcollist(X) COMMA. {A = X;}
|
||||
sclp(A) ::= . {A = 0;}
|
||||
selcollist(A) ::= STAR. {A = 0;}
|
||||
selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);}
|
||||
selcollist(A) ::= sclp(P) expr(X) as ids(Y). {A = sqliteExprListAppend(P,X,&Y);}
|
||||
as ::= .
|
||||
as ::= AS.
|
||||
|
||||
|
||||
%type seltablist {IdList*}
|
||||
%destructor seltablist {sqliteIdListDelete($$);}
|
||||
%type stl_prefix {IdList*}
|
||||
%destructor stl_prefix {sqliteIdListDelete($$);}
|
||||
%type from {IdList*}
|
||||
%destructor from {sqliteIdListDelete($$);}
|
||||
|
||||
from(A) ::= FROM seltablist(X). {A = X;}
|
||||
stl_prefix(A) ::= seltablist(X) COMMA. {A = X;}
|
||||
stl_prefix(A) ::= . {A = 0;}
|
||||
seltablist(A) ::= stl_prefix(X) ids(Y). {A = sqliteIdListAppend(X,&Y);}
|
||||
seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). {
|
||||
A = sqliteIdListAppend(X,&Y);
|
||||
sqliteIdListAddAlias(A,&Z);
|
||||
selcollist(A) ::= sclp(P) expr(X) as(Y). {
|
||||
A = sqliteExprListAppend(P,X,Y.n?&Y:0);
|
||||
}
|
||||
selcollist(A) ::= sclp(P) STAR. {
|
||||
A = sqliteExprListAppend(P, sqliteExpr(TK_ALL, 0, 0, 0), 0);
|
||||
}
|
||||
selcollist(A) ::= sclp(P) nm(X) DOT STAR. {
|
||||
Expr *pRight = sqliteExpr(TK_ALL, 0, 0, 0);
|
||||
Expr *pLeft = sqliteExpr(TK_ID, 0, 0, &X);
|
||||
A = sqliteExprListAppend(P, sqliteExpr(TK_DOT, pLeft, pRight, 0), 0);
|
||||
}
|
||||
|
||||
// An option "AS <id>" phrase that can follow one of the expressions that
|
||||
// define the result set, or one of the tables in the FROM clause.
|
||||
//
|
||||
%type as {Token}
|
||||
as(X) ::= AS nm(Y). { X = Y; }
|
||||
as(X) ::= ids(Y). { X = Y; }
|
||||
as(X) ::= . { X.n = 0; }
|
||||
|
||||
|
||||
%type seltablist {SrcList*}
|
||||
%destructor seltablist {sqliteSrcListDelete($$);}
|
||||
%type stl_prefix {SrcList*}
|
||||
%destructor stl_prefix {sqliteSrcListDelete($$);}
|
||||
%type from {SrcList*}
|
||||
%destructor from {sqliteSrcListDelete($$);}
|
||||
|
||||
// A complete FROM clause.
|
||||
//
|
||||
from(A) ::= . {A = sqliteMalloc(sizeof(*A));}
|
||||
from(A) ::= FROM seltablist(X). {A = X;}
|
||||
|
||||
// "seltablist" is a "Select Table List" - the content of the FROM clause
|
||||
// in a SELECT statement. "stl_prefix" is a prefix of this list.
|
||||
//
|
||||
stl_prefix(A) ::= seltablist(X) joinop(Y). {
|
||||
A = X;
|
||||
if( A && A->nSrc>0 ) A->a[A->nSrc-1].jointype = Y;
|
||||
}
|
||||
stl_prefix(A) ::= . {A = 0;}
|
||||
seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) on_opt(N) using_opt(U). {
|
||||
A = sqliteSrcListAppend(X,&Y,&D);
|
||||
if( Z.n ) sqliteSrcListAddAlias(A,&Z);
|
||||
if( N ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
|
||||
else { sqliteExprDelete(N); }
|
||||
}
|
||||
if( U ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
|
||||
else { sqliteIdListDelete(U); }
|
||||
}
|
||||
}
|
||||
seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP
|
||||
as(Z) on_opt(N) using_opt(U). {
|
||||
A = sqliteSrcListAppend(X,0,0);
|
||||
A->a[A->nSrc-1].pSelect = S;
|
||||
if( Z.n ) sqliteSrcListAddAlias(A,&Z);
|
||||
if( N ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
|
||||
else { sqliteExprDelete(N); }
|
||||
}
|
||||
if( U ){
|
||||
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
|
||||
else { sqliteIdListDelete(U); }
|
||||
}
|
||||
}
|
||||
|
||||
// A seltablist_paren nonterminal represents anything in a FROM that
|
||||
// is contained inside parentheses. This can be either a subquery or
|
||||
// a grouping of table and subqueries.
|
||||
//
|
||||
%type seltablist_paren {Select*}
|
||||
%destructor seltablist_paren {sqliteSelectDelete($$);}
|
||||
seltablist_paren(A) ::= select(S). {A = S;}
|
||||
seltablist_paren(A) ::= seltablist(F). {
|
||||
A = sqliteSelectNew(0,F,0,0,0,0,0,-1,0);
|
||||
}
|
||||
|
||||
%type dbnm {Token}
|
||||
dbnm(A) ::= . {A.z=0; A.n=0;}
|
||||
dbnm(A) ::= DOT nm(X). {A = X;}
|
||||
|
||||
%type joinop {int}
|
||||
%type joinop2 {int}
|
||||
joinop(X) ::= COMMA. { X = JT_INNER; }
|
||||
joinop(X) ::= JOIN. { X = JT_INNER; }
|
||||
joinop(X) ::= JOIN_KW(A) JOIN. { X = sqliteJoinType(pParse,&A,0,0); }
|
||||
joinop(X) ::= JOIN_KW(A) nm(B) JOIN. { X = sqliteJoinType(pParse,&A,&B,0); }
|
||||
joinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN.
|
||||
{ X = sqliteJoinType(pParse,&A,&B,&C); }
|
||||
|
||||
%type on_opt {Expr*}
|
||||
%destructor on_opt {sqliteExprDelete($$);}
|
||||
on_opt(N) ::= ON expr(E). {N = E;}
|
||||
on_opt(N) ::= . {N = 0;}
|
||||
|
||||
%type using_opt {IdList*}
|
||||
%destructor using_opt {sqliteIdListDelete($$);}
|
||||
using_opt(U) ::= USING LP idxlist(L) RP. {U = L;}
|
||||
using_opt(U) ::= . {U = 0;}
|
||||
|
||||
|
||||
%type orderby_opt {ExprList*}
|
||||
%destructor orderby_opt {sqliteExprListDelete($$);}
|
||||
@@ -233,21 +436,24 @@ seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). {
|
||||
|
||||
orderby_opt(A) ::= . {A = 0;}
|
||||
orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
|
||||
sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
|
||||
sortlist(A) ::= sortlist(X) COMMA sortitem(Y) collate(C) sortorder(Z). {
|
||||
A = sqliteExprListAppend(X,Y,0);
|
||||
if( A ) A->a[A->nExpr-1].sortOrder = Z; /* 0=ascending, 1=decending */
|
||||
if( A ) A->a[A->nExpr-1].sortOrder = C+Z;
|
||||
}
|
||||
sortlist(A) ::= sortitem(Y) sortorder(Z). {
|
||||
sortlist(A) ::= sortitem(Y) collate(C) sortorder(Z). {
|
||||
A = sqliteExprListAppend(0,Y,0);
|
||||
if( A ) A->a[0].sortOrder = Z;
|
||||
if( A ) A->a[0].sortOrder = C+Z;
|
||||
}
|
||||
sortitem(A) ::= expr(X). {A = X;}
|
||||
|
||||
%type sortorder {int}
|
||||
%type collate {int}
|
||||
|
||||
sortorder(A) ::= ASC. {A = 0;}
|
||||
sortorder(A) ::= DESC. {A = 1;}
|
||||
sortorder(A) ::= . {A = 0;}
|
||||
sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;}
|
||||
sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;}
|
||||
sortorder(A) ::= . {A = SQLITE_SO_ASC;}
|
||||
collate(C) ::= . {C = SQLITE_SO_UNK;}
|
||||
collate(C) ::= COLLATE id(X). {C = sqliteCollateType(X.z, X.n);}
|
||||
|
||||
%type groupby_opt {ExprList*}
|
||||
%destructor groupby_opt {sqliteExprListDelete($$);}
|
||||
@@ -259,10 +465,19 @@ groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
|
||||
having_opt(A) ::= . {A = 0;}
|
||||
having_opt(A) ::= HAVING expr(X). {A = X;}
|
||||
|
||||
%type limit_opt {struct LimitVal}
|
||||
limit_opt(A) ::= . {A.limit = -1; A.offset = 0;}
|
||||
limit_opt(A) ::= LIMIT signed(X). {A.limit = X; A.offset = 0;}
|
||||
limit_opt(A) ::= LIMIT signed(X) OFFSET signed(Y).
|
||||
{A.limit = X; A.offset = Y;}
|
||||
limit_opt(A) ::= LIMIT signed(X) COMMA signed(Y).
|
||||
{A.limit = Y; A.offset = X;}
|
||||
|
||||
/////////////////////////// The DELETE statement /////////////////////////////
|
||||
//
|
||||
cmd ::= DELETE FROM ids(X) where_opt(Y).
|
||||
{sqliteDeleteFrom(pParse, &X, Y);}
|
||||
cmd ::= DELETE FROM nm(X) dbnm(D) where_opt(Y). {
|
||||
sqliteDeleteFrom(pParse, sqliteSrcListAppend(0,&X,&D), Y);
|
||||
}
|
||||
|
||||
%type where_opt {Expr*}
|
||||
%destructor where_opt {sqliteExprDelete($$);}
|
||||
@@ -275,42 +490,31 @@ where_opt(A) ::= WHERE expr(X). {A = X;}
|
||||
|
||||
////////////////////////// The UPDATE command ////////////////////////////////
|
||||
//
|
||||
cmd ::= UPDATE ids(X) SET setlist(Y) where_opt(Z).
|
||||
{sqliteUpdate(pParse,&X,Y,Z);}
|
||||
cmd ::= UPDATE orconf(R) nm(X) dbnm(D) SET setlist(Y) where_opt(Z).
|
||||
{sqliteUpdate(pParse,sqliteSrcListAppend(0,&X,&D),Y,Z,R);}
|
||||
|
||||
setlist(A) ::= setlist(Z) COMMA ids(X) EQ expr(Y).
|
||||
setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y).
|
||||
{A = sqliteExprListAppend(Z,Y,&X);}
|
||||
setlist(A) ::= ids(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
|
||||
setlist(A) ::= nm(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
|
||||
|
||||
////////////////////////// The INSERT command /////////////////////////////////
|
||||
//
|
||||
cmd ::= INSERT INTO ids(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
|
||||
{sqliteInsert(pParse, &X, Y, 0, F);}
|
||||
cmd ::= INSERT INTO ids(X) inscollist_opt(F) select(S).
|
||||
{sqliteInsert(pParse, &X, 0, S, F);}
|
||||
cmd ::= insert_cmd(R) INTO nm(X) dbnm(D) inscollist_opt(F)
|
||||
VALUES LP itemlist(Y) RP.
|
||||
{sqliteInsert(pParse, sqliteSrcListAppend(0,&X,&D), Y, 0, F, R);}
|
||||
cmd ::= insert_cmd(R) INTO nm(X) dbnm(D) inscollist_opt(F) select(S).
|
||||
{sqliteInsert(pParse, sqliteSrcListAppend(0,&X,&D), 0, S, F, R);}
|
||||
|
||||
%type insert_cmd {int}
|
||||
insert_cmd(A) ::= INSERT orconf(R). {A = R;}
|
||||
insert_cmd(A) ::= REPLACE. {A = OE_Replace;}
|
||||
|
||||
|
||||
%type itemlist {ExprList*}
|
||||
%destructor itemlist {sqliteExprListDelete($$);}
|
||||
%type item {Expr*}
|
||||
%destructor item {sqliteExprDelete($$);}
|
||||
|
||||
itemlist(A) ::= itemlist(X) COMMA item(Y). {A = sqliteExprListAppend(X,Y,0);}
|
||||
itemlist(A) ::= item(X). {A = sqliteExprListAppend(0,X,0);}
|
||||
item(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
|
||||
item(A) ::= PLUS INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
|
||||
item(A) ::= MINUS INTEGER(X). {
|
||||
A = sqliteExpr(TK_UMINUS, 0, 0, 0);
|
||||
if( A ) A->pLeft = sqliteExpr(TK_INTEGER, 0, 0, &X);
|
||||
}
|
||||
item(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
|
||||
item(A) ::= PLUS FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
|
||||
item(A) ::= MINUS FLOAT(X). {
|
||||
A = sqliteExpr(TK_UMINUS, 0, 0, 0);
|
||||
if( A ) A->pLeft = sqliteExpr(TK_FLOAT, 0, 0, &X);
|
||||
}
|
||||
item(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
|
||||
item(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);}
|
||||
itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = sqliteExprListAppend(X,Y,0);}
|
||||
itemlist(A) ::= expr(X). {A = sqliteExprListAppend(0,X,0);}
|
||||
|
||||
%type inscollist_opt {IdList*}
|
||||
%destructor inscollist_opt {sqliteIdListDelete($$);}
|
||||
@@ -319,35 +523,38 @@ item(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);}
|
||||
|
||||
inscollist_opt(A) ::= . {A = 0;}
|
||||
inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
|
||||
inscollist(A) ::= inscollist(X) COMMA ids(Y). {A = sqliteIdListAppend(X,&Y);}
|
||||
inscollist(A) ::= ids(Y). {A = sqliteIdListAppend(0,&Y);}
|
||||
inscollist(A) ::= inscollist(X) COMMA nm(Y). {A = sqliteIdListAppend(X,&Y);}
|
||||
inscollist(A) ::= nm(Y). {A = sqliteIdListAppend(0,&Y);}
|
||||
|
||||
/////////////////////////// Expression Processing /////////////////////////////
|
||||
//
|
||||
%left OR.
|
||||
%left AND.
|
||||
%right NOT.
|
||||
%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
|
||||
%left GT GE LT LE.
|
||||
%left PLUS MINUS.
|
||||
%left STAR SLASH.
|
||||
%left CONCAT.
|
||||
%right UMINUS.
|
||||
|
||||
%type expr {Expr*}
|
||||
%destructor expr {sqliteExprDelete($$);}
|
||||
|
||||
expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
|
||||
expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E); }
|
||||
expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
|
||||
expr(A) ::= id(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= ids(X) DOT ids(Y). {
|
||||
expr(A) ::= ID(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= JOIN_KW(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= nm(X) DOT nm(Y). {
|
||||
Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
|
||||
Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
|
||||
A = sqliteExpr(TK_DOT, temp1, temp2, 0);
|
||||
}
|
||||
expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
|
||||
Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
|
||||
Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
|
||||
Expr *temp3 = sqliteExpr(TK_ID, 0, 0, &Z);
|
||||
Expr *temp4 = sqliteExpr(TK_DOT, temp2, temp3, 0);
|
||||
A = sqliteExpr(TK_DOT, temp1, temp4, 0);
|
||||
}
|
||||
expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
|
||||
expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
|
||||
expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
|
||||
expr(A) ::= VARIABLE(X). {
|
||||
A = sqliteExpr(TK_VARIABLE, 0, 0, &X);
|
||||
if( A ) A->iTable = ++pParse->nVar;
|
||||
}
|
||||
expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
|
||||
A = sqliteExprFunction(Y, &X);
|
||||
sqliteExprSpan(A,&X,&E);
|
||||
@@ -364,22 +571,33 @@ expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
|
||||
expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
|
||||
expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
|
||||
expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LIKE expr(Y). {A = sqliteExpr(TK_LIKE, X, Y, 0);}
|
||||
expr(A) ::= expr(X) NOT LIKE expr(Y). {
|
||||
A = sqliteExpr(TK_LIKE, X, Y, 0);
|
||||
A = sqliteExpr(TK_NOT, A, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&Y->span);
|
||||
}
|
||||
expr(A) ::= expr(X) GLOB expr(Y). {A = sqliteExpr(TK_GLOB,X,Y,0);}
|
||||
expr(A) ::= expr(X) NOT GLOB expr(Y). {
|
||||
A = sqliteExpr(TK_GLOB, X, Y, 0);
|
||||
expr(A) ::= expr(X) BITAND expr(Y). {A = sqliteExpr(TK_BITAND, X, Y, 0);}
|
||||
expr(A) ::= expr(X) BITOR expr(Y). {A = sqliteExpr(TK_BITOR, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LSHIFT expr(Y). {A = sqliteExpr(TK_LSHIFT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) RSHIFT expr(Y). {A = sqliteExpr(TK_RSHIFT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) likeop(OP) expr(Y). [LIKE] {
|
||||
ExprList *pList = sqliteExprListAppend(0, Y, 0);
|
||||
pList = sqliteExprListAppend(pList, X, 0);
|
||||
A = sqliteExprFunction(pList, 0);
|
||||
if( A ) A->op = OP;
|
||||
sqliteExprSpan(A, &X->span, &Y->span);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT likeop(OP) expr(Y). [LIKE] {
|
||||
ExprList *pList = sqliteExprListAppend(0, Y, 0);
|
||||
pList = sqliteExprListAppend(pList, X, 0);
|
||||
A = sqliteExprFunction(pList, 0);
|
||||
if( A ) A->op = OP;
|
||||
A = sqliteExpr(TK_NOT, A, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&Y->span);
|
||||
}
|
||||
%type likeop {int}
|
||||
likeop(A) ::= LIKE. {A = TK_LIKE;}
|
||||
likeop(A) ::= GLOB. {A = TK_GLOB;}
|
||||
expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
|
||||
expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
|
||||
expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
|
||||
expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
|
||||
expr(A) ::= expr(X) REM expr(Y). {A = sqliteExpr(TK_REM, X, Y, 0);}
|
||||
expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
|
||||
expr(A) ::= expr(X) ISNULL(E). {
|
||||
A = sqliteExpr(TK_ISNULL, X, 0, 0);
|
||||
@@ -397,16 +615,24 @@ expr(A) ::= expr(X) NOT NULL(E). {
|
||||
A = sqliteExpr(TK_NOTNULL, X, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) IS NOT NULL(E). {
|
||||
A = sqliteExpr(TK_NOTNULL, X, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= NOT(B) expr(X). {
|
||||
A = sqliteExpr(TK_NOT, X, 0, 0);
|
||||
sqliteExprSpan(A,&B,&X->span);
|
||||
}
|
||||
expr(A) ::= BITNOT(B) expr(X). {
|
||||
A = sqliteExpr(TK_BITNOT, X, 0, 0);
|
||||
sqliteExprSpan(A,&B,&X->span);
|
||||
}
|
||||
expr(A) ::= MINUS(B) expr(X). [UMINUS] {
|
||||
A = sqliteExpr(TK_UMINUS, X, 0, 0);
|
||||
sqliteExprSpan(A,&B,&X->span);
|
||||
}
|
||||
expr(A) ::= PLUS(B) expr(X). [UMINUS] {
|
||||
A = X;
|
||||
expr(A) ::= PLUS(B) expr(X). [UPLUS] {
|
||||
A = sqliteExpr(TK_UPLUS, X, 0, 0);
|
||||
sqliteExprSpan(A,&B,&X->span);
|
||||
}
|
||||
expr(A) ::= LP(B) select(X) RP(E). {
|
||||
@@ -451,8 +677,43 @@ expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
|
||||
A = sqliteExpr(TK_NOT, A, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,&E);
|
||||
}
|
||||
expr(A) ::= expr(X) IN nm(Y) dbnm(D). {
|
||||
SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D);
|
||||
A = sqliteExpr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = sqliteSelectNew(0,pSrc,0,0,0,0,0,-1,0);
|
||||
sqliteExprSpan(A,&X->span,D.z?&D:&Y);
|
||||
}
|
||||
expr(A) ::= expr(X) NOT IN nm(Y) dbnm(D). {
|
||||
SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D);
|
||||
A = sqliteExpr(TK_IN, X, 0, 0);
|
||||
if( A ) A->pSelect = sqliteSelectNew(0,pSrc,0,0,0,0,0,-1,0);
|
||||
A = sqliteExpr(TK_NOT, A, 0, 0);
|
||||
sqliteExprSpan(A,&X->span,D.z?&D:&Y);
|
||||
}
|
||||
|
||||
|
||||
/* CASE expressions */
|
||||
expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
|
||||
A = sqliteExpr(TK_CASE, X, Z, 0);
|
||||
if( A ) A->pList = Y;
|
||||
sqliteExprSpan(A, &C, &E);
|
||||
}
|
||||
%type case_exprlist {ExprList*}
|
||||
%destructor case_exprlist {sqliteExprListDelete($$);}
|
||||
case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). {
|
||||
A = sqliteExprListAppend(X, Y, 0);
|
||||
A = sqliteExprListAppend(A, Z, 0);
|
||||
}
|
||||
case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). {
|
||||
A = sqliteExprListAppend(0, Y, 0);
|
||||
A = sqliteExprListAppend(A, Z, 0);
|
||||
}
|
||||
%type case_else {Expr*}
|
||||
case_else(A) ::= ELSE expr(X). {A = X;}
|
||||
case_else(A) ::= . {A = 0;}
|
||||
%type case_operand {Expr*}
|
||||
case_operand(A) ::= expr(X). {A = X;}
|
||||
case_operand(A) ::= . {A = 0;}
|
||||
|
||||
%type exprlist {ExprList*}
|
||||
%destructor exprlist {sqliteExprListDelete($$);}
|
||||
@@ -467,51 +728,170 @@ expritem(A) ::= . {A = 0;}
|
||||
|
||||
///////////////////////////// The CREATE INDEX command ///////////////////////
|
||||
//
|
||||
cmd ::= CREATE(S) uniqueflag(U) INDEX ids(X) ON ids(Y) LP idxlist(Z) RP(E).
|
||||
{sqliteCreateIndex(pParse, &X, &Y, Z, U, &S, &E);}
|
||||
cmd ::= CREATE(S) uniqueflag(U) INDEX nm(X)
|
||||
ON nm(Y) dbnm(D) LP idxlist(Z) RP(E) onconf(R). {
|
||||
SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D);
|
||||
if( U!=OE_None ) U = R;
|
||||
if( U==OE_Default) U = OE_Abort;
|
||||
sqliteCreateIndex(pParse, &X, pSrc, Z, U, &S, &E);
|
||||
}
|
||||
|
||||
%type uniqueflag {int}
|
||||
uniqueflag(A) ::= UNIQUE. { A = 1; }
|
||||
uniqueflag(A) ::= . { A = 0; }
|
||||
uniqueflag(A) ::= UNIQUE. { A = OE_Abort; }
|
||||
uniqueflag(A) ::= . { A = OE_None; }
|
||||
|
||||
%type idxlist {IdList*}
|
||||
%destructor idxlist {sqliteIdListDelete($$);}
|
||||
%type idxlist_opt {IdList*}
|
||||
%destructor idxlist_opt {sqliteIdListDelete($$);}
|
||||
%type idxitem {Token}
|
||||
|
||||
idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
|
||||
{A = sqliteIdListAppend(X,&Y);}
|
||||
idxlist(A) ::= idxitem(Y).
|
||||
{A = sqliteIdListAppend(0,&Y);}
|
||||
idxitem(A) ::= ids(X). {A = X;}
|
||||
|
||||
///////////////////////////// The CREATE INDEX command ///////////////////////
|
||||
//
|
||||
|
||||
cmd ::= DROP INDEX ids(X). {sqliteDropIndex(pParse, &X);}
|
||||
|
||||
idxlist_opt(A) ::= . {A = 0;}
|
||||
idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;}
|
||||
idxlist(A) ::= idxlist(X) COMMA idxitem(Y). {A = sqliteIdListAppend(X,&Y);}
|
||||
idxlist(A) ::= idxitem(Y). {A = sqliteIdListAppend(0,&Y);}
|
||||
idxitem(A) ::= nm(X) sortorder. {A = X;}
|
||||
|
||||
///////////////////////////// The DROP INDEX command /////////////////////////
|
||||
//
|
||||
cmd ::= COPY ids(X) FROM ids(Y) USING DELIMITERS STRING(Z).
|
||||
{sqliteCopy(pParse,&X,&Y,&Z);}
|
||||
cmd ::= COPY ids(X) FROM ids(Y).
|
||||
{sqliteCopy(pParse,&X,&Y,0);}
|
||||
|
||||
cmd ::= DROP INDEX nm(X) dbnm(Y). {
|
||||
sqliteDropIndex(pParse, sqliteSrcListAppend(0,&X,&Y));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////// The COPY command ///////////////////////////////
|
||||
//
|
||||
cmd ::= COPY orconf(R) nm(X) dbnm(D) FROM nm(Y) USING DELIMITERS STRING(Z).
|
||||
{sqliteCopy(pParse,sqliteSrcListAppend(0,&X,&D),&Y,&Z,R);}
|
||||
cmd ::= COPY orconf(R) nm(X) dbnm(D) FROM nm(Y).
|
||||
{sqliteCopy(pParse,sqliteSrcListAppend(0,&X,&D),&Y,0,R);}
|
||||
|
||||
///////////////////////////// The VACUUM command /////////////////////////////
|
||||
//
|
||||
cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
|
||||
cmd ::= VACUUM ids(X). {sqliteVacuum(pParse,&X);}
|
||||
cmd ::= VACUUM nm(X). {sqliteVacuum(pParse,&X);}
|
||||
|
||||
///////////////////////////// The PRAGMA command /////////////////////////////
|
||||
//
|
||||
cmd ::= PRAGMA ids(X) EQ ids(Y). {sqlitePragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ nm(Y). {sqlitePragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlitePragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlitePragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlitePragma(pParse,&X,&Y,1);}
|
||||
cmd ::= PRAGMA ids(X) LP ids(Y) RP. {sqlitePragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X) LP nm(Y) RP. {sqlitePragma(pParse,&X,&Y,0);}
|
||||
cmd ::= PRAGMA ids(X). {sqlitePragma(pParse,&X,&X,0);}
|
||||
plus_num(A) ::= plus_opt number(X). {A = X;}
|
||||
minus_num(A) ::= MINUS number(X). {A = X;}
|
||||
number(A) ::= INTEGER(X). {A = X;}
|
||||
number(A) ::= FLOAT(X). {A = X;}
|
||||
plus_opt ::= PLUS.
|
||||
plus_opt ::= .
|
||||
|
||||
//////////////////////////// The CREATE TRIGGER command /////////////////////
|
||||
|
||||
cmd ::= CREATE(A) trigger_decl BEGIN trigger_cmd_list(S) END(Z). {
|
||||
Token all;
|
||||
all.z = A.z;
|
||||
all.n = (Z.z - A.z) + Z.n;
|
||||
sqliteFinishTrigger(pParse, S, &all);
|
||||
}
|
||||
|
||||
trigger_decl ::= temp(T) TRIGGER nm(B) trigger_time(C) trigger_event(D)
|
||||
ON nm(E) dbnm(DB) foreach_clause(F) when_clause(G). {
|
||||
SrcList *pTab = sqliteSrcListAppend(0, &E, &DB);
|
||||
sqliteBeginTrigger(pParse, &B, C, D.a, D.b, pTab, F, G, T);
|
||||
}
|
||||
|
||||
%type trigger_time {int}
|
||||
trigger_time(A) ::= BEFORE. { A = TK_BEFORE; }
|
||||
trigger_time(A) ::= AFTER. { A = TK_AFTER; }
|
||||
trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;}
|
||||
trigger_time(A) ::= . { A = TK_BEFORE; }
|
||||
|
||||
%type trigger_event {struct TrigEvent}
|
||||
%destructor trigger_event {sqliteIdListDelete($$.b);}
|
||||
trigger_event(A) ::= DELETE. { A.a = TK_DELETE; A.b = 0; }
|
||||
trigger_event(A) ::= INSERT. { A.a = TK_INSERT; A.b = 0; }
|
||||
trigger_event(A) ::= UPDATE. { A.a = TK_UPDATE; A.b = 0;}
|
||||
trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X; }
|
||||
|
||||
%type foreach_clause {int}
|
||||
foreach_clause(A) ::= . { A = TK_ROW; }
|
||||
foreach_clause(A) ::= FOR EACH ROW. { A = TK_ROW; }
|
||||
foreach_clause(A) ::= FOR EACH STATEMENT. { A = TK_STATEMENT; }
|
||||
|
||||
%type when_clause {Expr *}
|
||||
when_clause(A) ::= . { A = 0; }
|
||||
when_clause(A) ::= WHEN expr(X). { A = X; }
|
||||
|
||||
%type trigger_cmd_list {TriggerStep *}
|
||||
%destructor trigger_cmd_list {sqliteDeleteTriggerStep($$);}
|
||||
trigger_cmd_list(A) ::= trigger_cmd(X) SEMI trigger_cmd_list(Y). {
|
||||
X->pNext = Y;
|
||||
A = X;
|
||||
}
|
||||
trigger_cmd_list(A) ::= . { A = 0; }
|
||||
|
||||
%type trigger_cmd {TriggerStep *}
|
||||
%destructor trigger_cmd {sqliteDeleteTriggerStep($$);}
|
||||
// UPDATE
|
||||
trigger_cmd(A) ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z).
|
||||
{ A = sqliteTriggerUpdateStep(&X, Y, Z, R); }
|
||||
|
||||
// INSERT
|
||||
trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F)
|
||||
VALUES LP itemlist(Y) RP.
|
||||
{A = sqliteTriggerInsertStep(&X, F, Y, 0, R);}
|
||||
|
||||
trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S).
|
||||
{A = sqliteTriggerInsertStep(&X, F, 0, S, R);}
|
||||
|
||||
// DELETE
|
||||
trigger_cmd(A) ::= DELETE FROM nm(X) where_opt(Y).
|
||||
{A = sqliteTriggerDeleteStep(&X, Y);}
|
||||
|
||||
// SELECT
|
||||
trigger_cmd(A) ::= select(X). {A = sqliteTriggerSelectStep(X); }
|
||||
|
||||
// The special RAISE expression that may occur in trigger programs
|
||||
expr(A) ::= RAISE(X) LP IGNORE RP(Y). {
|
||||
A = sqliteExpr(TK_RAISE, 0, 0, 0);
|
||||
A->iColumn = OE_Ignore;
|
||||
sqliteExprSpan(A, &X, &Y);
|
||||
}
|
||||
expr(A) ::= RAISE(X) LP ROLLBACK COMMA nm(Z) RP(Y). {
|
||||
A = sqliteExpr(TK_RAISE, 0, 0, &Z);
|
||||
A->iColumn = OE_Rollback;
|
||||
sqliteExprSpan(A, &X, &Y);
|
||||
}
|
||||
expr(A) ::= RAISE(X) LP ABORT COMMA nm(Z) RP(Y). {
|
||||
A = sqliteExpr(TK_RAISE, 0, 0, &Z);
|
||||
A->iColumn = OE_Abort;
|
||||
sqliteExprSpan(A, &X, &Y);
|
||||
}
|
||||
expr(A) ::= RAISE(X) LP FAIL COMMA nm(Z) RP(Y). {
|
||||
A = sqliteExpr(TK_RAISE, 0, 0, &Z);
|
||||
A->iColumn = OE_Fail;
|
||||
sqliteExprSpan(A, &X, &Y);
|
||||
}
|
||||
|
||||
//////////////////////// DROP TRIGGER statement //////////////////////////////
|
||||
cmd ::= DROP TRIGGER nm(X) dbnm(D). {
|
||||
sqliteDropTrigger(pParse,sqliteSrcListAppend(0,&X,&D));
|
||||
}
|
||||
|
||||
//////////////////////// ATTACH DATABASE file AS name /////////////////////////
|
||||
cmd ::= ATTACH database_kw_opt ids(F) AS nm(D) key_opt(K). {
|
||||
sqliteAttach(pParse, &F, &D, &K);
|
||||
}
|
||||
%type key_opt {Token}
|
||||
key_opt(A) ::= USING ids(X). { A = X; }
|
||||
key_opt(A) ::= . { A.z = 0; A.n = 0; }
|
||||
|
||||
database_kw_opt ::= DATABASE.
|
||||
database_kw_opt ::= .
|
||||
|
||||
//////////////////////// DETACH DATABASE name /////////////////////////////////
|
||||
cmd ::= DETACH database_kw_opt nm(D). {
|
||||
sqliteDetach(pParse, &D);
|
||||
}
|
||||
|
||||
+712
@@ -0,0 +1,712 @@
|
||||
/*
|
||||
** 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 PRAGMA command.
|
||||
**
|
||||
** $Id: pragma.c,v 1.19 2004/04/23 17:04:45 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
** Interpret the given string as a boolean value.
|
||||
*/
|
||||
static int getBoolean(const char *z){
|
||||
static char *azTrue[] = { "yes", "on", "true" };
|
||||
int i;
|
||||
if( z[0]==0 ) return 0;
|
||||
if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){
|
||||
return atoi(z);
|
||||
}
|
||||
for(i=0; i<sizeof(azTrue)/sizeof(azTrue[0]); i++){
|
||||
if( sqliteStrICmp(z,azTrue[i])==0 ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Interpret the given string as a safety level. Return 0 for OFF,
|
||||
** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
|
||||
** unrecognized string argument.
|
||||
**
|
||||
** Note that the values returned are one less that the values that
|
||||
** should be passed into sqliteBtreeSetSafetyLevel(). The is done
|
||||
** to support legacy SQL code. The safety level used to be boolean
|
||||
** and older scripts may have used numbers 0 for OFF and 1 for ON.
|
||||
*/
|
||||
static int getSafetyLevel(char *z){
|
||||
static const struct {
|
||||
const char *zWord;
|
||||
int val;
|
||||
} aKey[] = {
|
||||
{ "no", 0 },
|
||||
{ "off", 0 },
|
||||
{ "false", 0 },
|
||||
{ "yes", 1 },
|
||||
{ "on", 1 },
|
||||
{ "true", 1 },
|
||||
{ "full", 2 },
|
||||
};
|
||||
int i;
|
||||
if( z[0]==0 ) return 1;
|
||||
if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){
|
||||
return atoi(z);
|
||||
}
|
||||
for(i=0; i<sizeof(aKey)/sizeof(aKey[0]); i++){
|
||||
if( sqliteStrICmp(z,aKey[i].zWord)==0 ) return aKey[i].val;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Interpret the given string as a temp db location. Return 1 for file
|
||||
** backed temporary databases, 2 for the Red-Black tree in memory database
|
||||
** and 0 to use the compile-time default.
|
||||
*/
|
||||
static int getTempStore(const char *z){
|
||||
if( z[0]>='0' && z[0]<='2' ){
|
||||
return z[0] - '0';
|
||||
}else if( sqliteStrICmp(z, "file")==0 ){
|
||||
return 1;
|
||||
}else if( sqliteStrICmp(z, "memory")==0 ){
|
||||
return 2;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** If the TEMP database is open, close it and mark the database schema
|
||||
** as needing reloading. This must be done when using the TEMP_STORE
|
||||
** or DEFAULT_TEMP_STORE pragmas.
|
||||
*/
|
||||
static int changeTempStorage(Parse *pParse, const char *zStorageType){
|
||||
int ts = getTempStore(zStorageType);
|
||||
sqlite *db = pParse->db;
|
||||
if( db->temp_store==ts ) return SQLITE_OK;
|
||||
if( db->aDb[1].pBt!=0 ){
|
||||
if( db->flags & SQLITE_InTrans ){
|
||||
sqliteErrorMsg(pParse, "temporary storage cannot be changed "
|
||||
"from within a transaction");
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
sqliteBtreeClose(db->aDb[1].pBt);
|
||||
db->aDb[1].pBt = 0;
|
||||
sqliteResetInternalSchema(db, 0);
|
||||
}
|
||||
db->temp_store = ts;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Check to see if zRight and zLeft refer to a pragma that queries
|
||||
** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
|
||||
** Also, implement the pragma.
|
||||
*/
|
||||
static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
|
||||
static const struct {
|
||||
const char *zName; /* Name of the pragma */
|
||||
int mask; /* Mask for the db->flags value */
|
||||
} aPragma[] = {
|
||||
{ "vdbe_trace", SQLITE_VdbeTrace },
|
||||
{ "full_column_names", SQLITE_FullColNames },
|
||||
{ "short_column_names", SQLITE_ShortColNames },
|
||||
{ "show_datatypes", SQLITE_ReportTypes },
|
||||
{ "count_changes", SQLITE_CountRows },
|
||||
{ "empty_result_callbacks", SQLITE_NullCallback },
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aPragma)/sizeof(aPragma[0]); i++){
|
||||
if( sqliteStrICmp(zLeft, aPragma[i].zName)==0 ){
|
||||
sqlite *db = pParse->db;
|
||||
Vdbe *v;
|
||||
if( strcmp(zLeft,zRight)==0 && (v = sqliteGetVdbe(pParse))!=0 ){
|
||||
sqliteVdbeOp3(v, OP_ColumnName, 0, 1, aPragma[i].zName, P3_STATIC);
|
||||
sqliteVdbeOp3(v, OP_ColumnName, 1, 0, "boolean", P3_STATIC);
|
||||
sqliteVdbeCode(v, OP_Integer, (db->flags & aPragma[i].mask)!=0, 0,
|
||||
OP_Callback, 1, 0,
|
||||
0);
|
||||
}else if( getBoolean(zRight) ){
|
||||
db->flags |= aPragma[i].mask;
|
||||
}else{
|
||||
db->flags &= ~aPragma[i].mask;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Process a pragma statement.
|
||||
**
|
||||
** Pragmas are of this form:
|
||||
**
|
||||
** PRAGMA id = value
|
||||
**
|
||||
** The identifier might also be a string. The value is a string, and
|
||||
** identifier, or a number. If minusFlag is true, then the value is
|
||||
** a number that was preceded by a minus sign.
|
||||
*/
|
||||
void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
char *zLeft = 0;
|
||||
char *zRight = 0;
|
||||
sqlite *db = pParse->db;
|
||||
Vdbe *v = sqliteGetVdbe(pParse);
|
||||
if( v==0 ) return;
|
||||
|
||||
zLeft = sqliteStrNDup(pLeft->z, pLeft->n);
|
||||
sqliteDequote(zLeft);
|
||||
if( minusFlag ){
|
||||
zRight = 0;
|
||||
sqliteSetNString(&zRight, "-", 1, pRight->z, pRight->n, 0);
|
||||
}else{
|
||||
zRight = sqliteStrNDup(pRight->z, pRight->n);
|
||||
sqliteDequote(zRight);
|
||||
}
|
||||
if( sqliteAuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, 0) ){
|
||||
sqliteFree(zLeft);
|
||||
sqliteFree(zRight);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** PRAGMA default_cache_size
|
||||
** PRAGMA default_cache_size=N
|
||||
**
|
||||
** The first form reports the current persistent setting for the
|
||||
** page cache size. The value returned is the maximum number of
|
||||
** pages in the page cache. The second form sets both the current
|
||||
** page cache size value and the persistent page cache size value
|
||||
** stored in the database file.
|
||||
**
|
||||
** The default cache size is stored in meta-value 2 of page 1 of the
|
||||
** database file. The cache size is actually the absolute value of
|
||||
** this memory location. The sign of meta-value 2 determines the
|
||||
** synchronous setting. A negative value means synchronous is off
|
||||
** and a positive value means synchronous is on.
|
||||
*/
|
||||
if( sqliteStrICmp(zLeft,"default_cache_size")==0 ){
|
||||
static VdbeOpList getCacheSize[] = {
|
||||
{ OP_ReadCookie, 0, 2, 0},
|
||||
{ OP_AbsValue, 0, 0, 0},
|
||||
{ OP_Dup, 0, 0, 0},
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_Ne, 0, 6, 0},
|
||||
{ OP_Integer, 0, 0, 0}, /* 5 */
|
||||
{ OP_ColumnName, 0, 1, "cache_size"},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
int addr;
|
||||
if( pRight->z==pLeft->z ){
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
|
||||
sqliteVdbeChangeP1(v, addr+5, MAX_PAGES);
|
||||
}else{
|
||||
int size = atoi(zRight);
|
||||
if( size<0 ) size = -size;
|
||||
sqliteBeginWriteOperation(pParse, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, size, 0);
|
||||
sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2);
|
||||
addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Ge, 0, addr+3);
|
||||
sqliteVdbeAddOp(v, OP_Negative, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_SetCookie, 0, 2);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
db->cache_size = db->cache_size<0 ? -size : size;
|
||||
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
}
|
||||
}else
|
||||
|
||||
/*
|
||||
** PRAGMA cache_size
|
||||
** PRAGMA cache_size=N
|
||||
**
|
||||
** The first form reports the current local setting for the
|
||||
** page cache size. The local setting can be different from
|
||||
** the persistent cache size value that is stored in the database
|
||||
** file itself. The value returned is the maximum number of
|
||||
** pages in the page cache. The second form sets the local
|
||||
** page cache size value. It does not change the persistent
|
||||
** cache size stored on the disk so the cache size will revert
|
||||
** to its default value when the database is closed and reopened.
|
||||
** N should be a positive integer.
|
||||
*/
|
||||
if( sqliteStrICmp(zLeft,"cache_size")==0 ){
|
||||
static VdbeOpList getCacheSize[] = {
|
||||
{ OP_ColumnName, 0, 1, "cache_size"},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
if( pRight->z==pLeft->z ){
|
||||
int size = db->cache_size;;
|
||||
if( size<0 ) size = -size;
|
||||
sqliteVdbeAddOp(v, OP_Integer, size, 0);
|
||||
sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
|
||||
}else{
|
||||
int size = atoi(zRight);
|
||||
if( size<0 ) size = -size;
|
||||
if( db->cache_size<0 ) size = -size;
|
||||
db->cache_size = size;
|
||||
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
}
|
||||
}else
|
||||
|
||||
/*
|
||||
** PRAGMA default_synchronous
|
||||
** PRAGMA default_synchronous=ON|OFF|NORMAL|FULL
|
||||
**
|
||||
** The first form returns the persistent value of the "synchronous" setting
|
||||
** that is stored in the database. This is the synchronous setting that
|
||||
** is used whenever the database is opened unless overridden by a separate
|
||||
** "synchronous" pragma. The second form changes the persistent and the
|
||||
** local synchronous setting to the value given.
|
||||
**
|
||||
** If synchronous is OFF, SQLite does not attempt any fsync() systems calls
|
||||
** to make sure data is committed to disk. Write operations are very fast,
|
||||
** but a power failure can leave the database in an inconsistent state.
|
||||
** If synchronous is ON or NORMAL, SQLite will do an fsync() system call to
|
||||
** make sure data is being written to disk. The risk of corruption due to
|
||||
** a power loss in this mode is negligible but non-zero. If synchronous
|
||||
** is FULL, extra fsync()s occur to reduce the risk of corruption to near
|
||||
** zero, but with a write performance penalty. The default mode is NORMAL.
|
||||
*/
|
||||
if( sqliteStrICmp(zLeft,"default_synchronous")==0 ){
|
||||
static VdbeOpList getSync[] = {
|
||||
{ OP_ColumnName, 0, 1, "synchronous"},
|
||||
{ OP_ReadCookie, 0, 3, 0},
|
||||
{ OP_Dup, 0, 0, 0},
|
||||
{ OP_If, 0, 0, 0}, /* 3 */
|
||||
{ OP_ReadCookie, 0, 2, 0},
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_Lt, 0, 5, 0},
|
||||
{ OP_AddImm, 1, 0, 0},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
{ OP_Halt, 0, 0, 0},
|
||||
{ OP_AddImm, -1, 0, 0}, /* 10 */
|
||||
{ OP_Callback, 1, 0, 0}
|
||||
};
|
||||
if( pRight->z==pLeft->z ){
|
||||
int addr = sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
|
||||
sqliteVdbeChangeP2(v, addr+3, addr+10);
|
||||
}else{
|
||||
int addr;
|
||||
int size = db->cache_size;
|
||||
if( size<0 ) size = -size;
|
||||
sqliteBeginWriteOperation(pParse, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Ne, 0, addr+3);
|
||||
sqliteVdbeAddOp(v, OP_AddImm, MAX_PAGES, 0);
|
||||
sqliteVdbeAddOp(v, OP_AbsValue, 0, 0);
|
||||
db->safety_level = getSafetyLevel(zRight)+1;
|
||||
if( db->safety_level==1 ){
|
||||
sqliteVdbeAddOp(v, OP_Negative, 0, 0);
|
||||
size = -size;
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_SetCookie, 0, 2);
|
||||
sqliteVdbeAddOp(v, OP_Integer, db->safety_level, 0);
|
||||
sqliteVdbeAddOp(v, OP_SetCookie, 0, 3);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
db->cache_size = size;
|
||||
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
|
||||
}
|
||||
}else
|
||||
|
||||
/*
|
||||
** PRAGMA synchronous
|
||||
** PRAGMA synchronous=OFF|ON|NORMAL|FULL
|
||||
**
|
||||
** Return or set the local value of the synchronous flag. Changing
|
||||
** the local value does not make changes to the disk file and the
|
||||
** default value will be restored the next time the database is
|
||||
** opened.
|
||||
*/
|
||||
if( sqliteStrICmp(zLeft,"synchronous")==0 ){
|
||||
static VdbeOpList getSync[] = {
|
||||
{ OP_ColumnName, 0, 1, "synchronous"},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
if( pRight->z==pLeft->z ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, db->safety_level-1, 0);
|
||||
sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
|
||||
}else{
|
||||
int size = db->cache_size;
|
||||
if( size<0 ) size = -size;
|
||||
db->safety_level = getSafetyLevel(zRight)+1;
|
||||
if( db->safety_level==1 ) size = -size;
|
||||
db->cache_size = size;
|
||||
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
|
||||
sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
|
||||
}
|
||||
}else
|
||||
|
||||
#ifndef NDEBUG
|
||||
if( sqliteStrICmp(zLeft, "trigger_overhead_test")==0 ){
|
||||
if( getBoolean(zRight) ){
|
||||
always_code_trigger_setup = 1;
|
||||
}else{
|
||||
always_code_trigger_setup = 0;
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
|
||||
if( flagPragma(pParse, zLeft, zRight) ){
|
||||
/* The flagPragma() call also generates any necessary code */
|
||||
}else
|
||||
|
||||
if( sqliteStrICmp(zLeft, "table_info")==0 ){
|
||||
Table *pTab;
|
||||
pTab = sqliteFindTable(db, zRight, 0);
|
||||
if( pTab ){
|
||||
static VdbeOpList tableInfoPreface[] = {
|
||||
{ OP_ColumnName, 0, 0, "cid"},
|
||||
{ OP_ColumnName, 1, 0, "name"},
|
||||
{ OP_ColumnName, 2, 0, "type"},
|
||||
{ OP_ColumnName, 3, 0, "notnull"},
|
||||
{ OP_ColumnName, 4, 0, "dflt_value"},
|
||||
{ OP_ColumnName, 5, 1, "pk"},
|
||||
};
|
||||
int i;
|
||||
sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
|
||||
sqliteViewGetColumnNames(pParse, pTab);
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zName, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0,
|
||||
pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0,
|
||||
pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 6, 0);
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqliteStrICmp(zLeft, "index_info")==0 ){
|
||||
Index *pIdx;
|
||||
Table *pTab;
|
||||
pIdx = sqliteFindIndex(db, zRight, 0);
|
||||
if( pIdx ){
|
||||
static VdbeOpList tableInfoPreface[] = {
|
||||
{ OP_ColumnName, 0, 0, "seqno"},
|
||||
{ OP_ColumnName, 1, 0, "cid"},
|
||||
{ OP_ColumnName, 2, 1, "name"},
|
||||
};
|
||||
int i;
|
||||
pTab = pIdx->pTable;
|
||||
sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
int cnum = pIdx->aiColumn[i];
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, cnum, 0);
|
||||
assert( pTab->nCol>cnum );
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[cnum].zName, 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqliteStrICmp(zLeft, "index_list")==0 ){
|
||||
Index *pIdx;
|
||||
Table *pTab;
|
||||
pTab = sqliteFindTable(db, zRight, 0);
|
||||
if( pTab ){
|
||||
v = sqliteGetVdbe(pParse);
|
||||
pIdx = pTab->pIndex;
|
||||
}
|
||||
if( pTab && pIdx ){
|
||||
int i = 0;
|
||||
static VdbeOpList indexListPreface[] = {
|
||||
{ OP_ColumnName, 0, 0, "seq"},
|
||||
{ OP_ColumnName, 1, 0, "name"},
|
||||
{ OP_ColumnName, 2, 1, "unique"},
|
||||
};
|
||||
|
||||
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
|
||||
while(pIdx){
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pIdx->zName, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
|
||||
++i;
|
||||
pIdx = pIdx->pNext;
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqliteStrICmp(zLeft, "foreign_key_list")==0 ){
|
||||
FKey *pFK;
|
||||
Table *pTab;
|
||||
pTab = sqliteFindTable(db, zRight, 0);
|
||||
if( pTab ){
|
||||
v = sqliteGetVdbe(pParse);
|
||||
pFK = pTab->pFKey;
|
||||
}
|
||||
if( pTab && pFK ){
|
||||
int i = 0;
|
||||
static VdbeOpList indexListPreface[] = {
|
||||
{ OP_ColumnName, 0, 0, "id"},
|
||||
{ OP_ColumnName, 1, 0, "seq"},
|
||||
{ OP_ColumnName, 2, 0, "table"},
|
||||
{ OP_ColumnName, 3, 0, "from"},
|
||||
{ OP_ColumnName, 4, 1, "to"},
|
||||
};
|
||||
|
||||
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
|
||||
while(pFK){
|
||||
int j;
|
||||
for(j=0; j<pFK->nCol; j++){
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, j, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pFK->zTo, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0,
|
||||
pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, pFK->aCol[j].zCol, 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 5, 0);
|
||||
}
|
||||
++i;
|
||||
pFK = pFK->pNextFrom;
|
||||
}
|
||||
}
|
||||
}else
|
||||
|
||||
if( sqliteStrICmp(zLeft, "database_list")==0 ){
|
||||
int i;
|
||||
static VdbeOpList indexListPreface[] = {
|
||||
{ OP_ColumnName, 0, 0, "seq"},
|
||||
{ OP_ColumnName, 1, 0, "name"},
|
||||
{ OP_ColumnName, 2, 1, "file"},
|
||||
};
|
||||
|
||||
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( db->aDb[i].pBt==0 ) continue;
|
||||
assert( db->aDb[i].zName!=0 );
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, 0);
|
||||
sqliteVdbeOp3(v, OP_String, 0, 0,
|
||||
sqliteBtreeGetFilename(db->aDb[i].pBt), 0);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
|
||||
}
|
||||
}else
|
||||
|
||||
|
||||
/*
|
||||
** PRAGMA temp_store
|
||||
** PRAGMA temp_store = "default"|"memory"|"file"
|
||||
**
|
||||
** Return or set the local value of the temp_store flag. Changing
|
||||
** the local value does not make changes to the disk file and the default
|
||||
** value will be restored the next time the database is opened.
|
||||
**
|
||||
** Note that it is possible for the library compile-time options to
|
||||
** override this setting
|
||||
*/
|
||||
if( sqliteStrICmp(zLeft, "temp_store")==0 ){
|
||||
static VdbeOpList getTmpDbLoc[] = {
|
||||
{ OP_ColumnName, 0, 1, "temp_store"},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
if( pRight->z==pLeft->z ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0);
|
||||
sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
|
||||
}else{
|
||||
changeTempStorage(pParse, zRight);
|
||||
}
|
||||
}else
|
||||
|
||||
/*
|
||||
** PRAGMA default_temp_store
|
||||
** PRAGMA default_temp_store = "default"|"memory"|"file"
|
||||
**
|
||||
** Return or set the value of the persistent temp_store flag. Any
|
||||
** change does not take effect until the next time the database is
|
||||
** opened.
|
||||
**
|
||||
** Note that it is possible for the library compile-time options to
|
||||
** override this setting
|
||||
*/
|
||||
if( sqliteStrICmp(zLeft, "default_temp_store")==0 ){
|
||||
static VdbeOpList getTmpDbLoc[] = {
|
||||
{ OP_ColumnName, 0, 1, "temp_store"},
|
||||
{ OP_ReadCookie, 0, 5, 0},
|
||||
{ OP_Callback, 1, 0, 0}};
|
||||
if( pRight->z==pLeft->z ){
|
||||
sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
|
||||
}else{
|
||||
sqliteBeginWriteOperation(pParse, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Integer, getTempStore(zRight), 0);
|
||||
sqliteVdbeAddOp(v, OP_SetCookie, 0, 5);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
}
|
||||
}else
|
||||
|
||||
#ifndef NDEBUG
|
||||
if( sqliteStrICmp(zLeft, "parser_trace")==0 ){
|
||||
extern void sqliteParserTrace(FILE*, char *);
|
||||
if( getBoolean(zRight) ){
|
||||
sqliteParserTrace(stdout, "parser: ");
|
||||
}else{
|
||||
sqliteParserTrace(0, 0);
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
|
||||
if( sqliteStrICmp(zLeft, "integrity_check")==0 ){
|
||||
int i, j, addr;
|
||||
|
||||
/* Code that initializes the integrity check program. Set the
|
||||
** error count 0
|
||||
*/
|
||||
static VdbeOpList initCode[] = {
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_MemStore, 0, 1, 0},
|
||||
{ OP_ColumnName, 0, 1, "integrity_check"},
|
||||
};
|
||||
|
||||
/* Code to do an BTree integrity check on a single database file.
|
||||
*/
|
||||
static VdbeOpList checkDb[] = {
|
||||
{ OP_SetInsert, 0, 0, "2"},
|
||||
{ OP_Integer, 0, 0, 0}, /* 1 */
|
||||
{ OP_OpenRead, 0, 2, 0},
|
||||
{ OP_Rewind, 0, 7, 0}, /* 3 */
|
||||
{ OP_Column, 0, 3, 0}, /* 4 */
|
||||
{ OP_SetInsert, 0, 0, 0},
|
||||
{ OP_Next, 0, 4, 0}, /* 6 */
|
||||
{ OP_IntegrityCk, 0, 0, 0}, /* 7 */
|
||||
{ OP_Dup, 0, 1, 0},
|
||||
{ OP_String, 0, 0, "ok"},
|
||||
{ OP_StrEq, 0, 12, 0}, /* 10 */
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_String, 0, 0, "*** in database "},
|
||||
{ OP_String, 0, 0, 0}, /* 13 */
|
||||
{ OP_String, 0, 0, " ***\n"},
|
||||
{ OP_Pull, 3, 0, 0},
|
||||
{ OP_Concat, 4, 1, 0},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
|
||||
/* Code that appears at the end of the integrity check. If no error
|
||||
** messages have been generated, output OK. Otherwise output the
|
||||
** error message
|
||||
*/
|
||||
static VdbeOpList endCode[] = {
|
||||
{ OP_MemLoad, 0, 0, 0},
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_Ne, 0, 0, 0}, /* 2 */
|
||||
{ OP_String, 0, 0, "ok"},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
|
||||
/* Initialize the VDBE program */
|
||||
sqliteVdbeAddOpList(v, ArraySize(initCode), initCode);
|
||||
|
||||
/* Do an integrity check on each database file */
|
||||
for(i=0; i<db->nDb; i++){
|
||||
HashElem *x;
|
||||
|
||||
/* Do an integrity check of the B-Tree
|
||||
*/
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb);
|
||||
sqliteVdbeChangeP1(v, addr+1, i);
|
||||
sqliteVdbeChangeP2(v, addr+3, addr+7);
|
||||
sqliteVdbeChangeP2(v, addr+6, addr+4);
|
||||
sqliteVdbeChangeP2(v, addr+7, i);
|
||||
sqliteVdbeChangeP2(v, addr+10, addr+ArraySize(checkDb));
|
||||
sqliteVdbeChangeP3(v, addr+13, db->aDb[i].zName, P3_STATIC);
|
||||
|
||||
/* Make sure all the indices are constructed correctly.
|
||||
*/
|
||||
sqliteCodeVerifySchema(pParse, i);
|
||||
for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
|
||||
Table *pTab = sqliteHashData(x);
|
||||
Index *pIdx;
|
||||
int loopTop;
|
||||
|
||||
if( pTab->pIndex==0 ) continue;
|
||||
sqliteVdbeAddOp(v, OP_Integer, i, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenRead, 1, pTab->tnum, pTab->zName, 0);
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
if( pIdx->tnum==0 ) continue;
|
||||
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
|
||||
sqliteVdbeOp3(v, OP_OpenRead, j+2, pIdx->tnum, pIdx->zName, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, 1, 1);
|
||||
loopTop = sqliteVdbeAddOp(v, OP_Rewind, 1, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemIncr, 1, 0);
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
int k, jmp2;
|
||||
static VdbeOpList idxErr[] = {
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_String, 0, 0, "rowid "},
|
||||
{ OP_Recno, 1, 0, 0},
|
||||
{ OP_String, 0, 0, " missing from index "},
|
||||
{ OP_String, 0, 0, 0}, /* 4 */
|
||||
{ OP_Concat, 4, 0, 0},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
sqliteVdbeAddOp(v, OP_Recno, 1, 0);
|
||||
for(k=0; k<pIdx->nColumn; k++){
|
||||
int idx = pIdx->aiColumn[k];
|
||||
if( idx==pTab->iPKey ){
|
||||
sqliteVdbeAddOp(v, OP_Recno, 1, 0);
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_Column, 1, idx);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
|
||||
if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
|
||||
jmp2 = sqliteVdbeAddOp(v, OP_Found, j+2, 0);
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(idxErr), idxErr);
|
||||
sqliteVdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
|
||||
sqliteVdbeChangeP2(v, jmp2, sqliteVdbeCurrentAddr(v));
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Next, 1, loopTop+1);
|
||||
sqliteVdbeChangeP2(v, loopTop, sqliteVdbeCurrentAddr(v));
|
||||
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
|
||||
static VdbeOpList cntIdx[] = {
|
||||
{ OP_Integer, 0, 0, 0},
|
||||
{ OP_MemStore, 2, 1, 0},
|
||||
{ OP_Rewind, 0, 0, 0}, /* 2 */
|
||||
{ OP_MemIncr, 2, 0, 0},
|
||||
{ OP_Next, 0, 0, 0}, /* 4 */
|
||||
{ OP_MemLoad, 1, 0, 0},
|
||||
{ OP_MemLoad, 2, 0, 0},
|
||||
{ OP_Eq, 0, 0, 0}, /* 7 */
|
||||
{ OP_MemIncr, 0, 0, 0},
|
||||
{ OP_String, 0, 0, "wrong # of entries in index "},
|
||||
{ OP_String, 0, 0, 0}, /* 10 */
|
||||
{ OP_Concat, 2, 0, 0},
|
||||
{ OP_Callback, 1, 0, 0},
|
||||
};
|
||||
if( pIdx->tnum==0 ) continue;
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
|
||||
sqliteVdbeChangeP1(v, addr+2, j+2);
|
||||
sqliteVdbeChangeP2(v, addr+2, addr+5);
|
||||
sqliteVdbeChangeP1(v, addr+4, j+2);
|
||||
sqliteVdbeChangeP2(v, addr+4, addr+3);
|
||||
sqliteVdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
|
||||
sqliteVdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
|
||||
}
|
||||
}
|
||||
}
|
||||
addr = sqliteVdbeAddOpList(v, ArraySize(endCode), endCode);
|
||||
sqliteVdbeChangeP2(v, addr+2, addr+ArraySize(endCode));
|
||||
}else
|
||||
|
||||
{}
|
||||
sqliteFree(zLeft);
|
||||
sqliteFree(zRight);
|
||||
}
|
||||
+274
-206
@@ -1,10 +1,14 @@
|
||||
/*
|
||||
** The "printf" code that follows dates from the 1980's. It is in
|
||||
** the public domain. The original comments are included here for
|
||||
** completeness. They are slightly out-of-date.
|
||||
** completeness. They are very out-of-date but might be useful as
|
||||
** an historical reference. Most of the "enhancements" have been backed
|
||||
** out so that the functionality is now the same as standard printf().
|
||||
**
|
||||
** The following modules is an enhanced replacement for the "printf" programs
|
||||
** found in the standard library. The following enhancements are
|
||||
**************************************************************************
|
||||
**
|
||||
** The following modules is an enhanced replacement for the "printf" subroutines
|
||||
** found in the standard C library. The following enhancements are
|
||||
** supported:
|
||||
**
|
||||
** + Additional functions. The standard set of "printf" functions
|
||||
@@ -48,71 +52,80 @@
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Undefine COMPATIBILITY to make some slight changes in the way things
|
||||
** work. I think the changes are an improvement, but they are not
|
||||
** backwards compatible.
|
||||
*/
|
||||
/* #define COMPATIBILITY / * Compatible with SUN OS 4.1 */
|
||||
|
||||
/*
|
||||
** Conversion types fall into various categories as defined by the
|
||||
** following enumeration.
|
||||
*/
|
||||
enum et_type { /* The type of the format field */
|
||||
etRADIX, /* Integer types. %d, %x, %o, and so forth */
|
||||
etFLOAT, /* Floating point. %f */
|
||||
etEXP, /* Exponentional notation. %e and %E */
|
||||
etGENERIC, /* Floating or exponential, depending on exponent. %g */
|
||||
etSIZE, /* Return number of characters processed so far. %n */
|
||||
etSTRING, /* Strings. %s */
|
||||
etPERCENT, /* Percent symbol. %% */
|
||||
etCHARX, /* Characters. %c */
|
||||
etERROR, /* Used to indicate no such conversion type */
|
||||
#define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */
|
||||
#define etFLOAT 2 /* Floating point. %f */
|
||||
#define etEXP 3 /* Exponentional notation. %e and %E */
|
||||
#define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */
|
||||
#define etSIZE 5 /* Return number of characters processed so far. %n */
|
||||
#define etSTRING 6 /* Strings. %s */
|
||||
#define etDYNSTRING 7 /* Dynamically allocated strings. %z */
|
||||
#define etPERCENT 8 /* Percent symbol. %% */
|
||||
#define etCHARX 9 /* Characters. %c */
|
||||
#define etERROR 10 /* Used to indicate no such conversion type */
|
||||
/* The rest are extensions, not normally found in printf() */
|
||||
etCHARLIT, /* Literal characters. %' */
|
||||
etSQLESCAPE, /* Strings with '\'' doubled. %q */
|
||||
etORDINAL /* 1st, 2nd, 3rd and so forth */
|
||||
};
|
||||
#define etCHARLIT 11 /* Literal characters. %' */
|
||||
#define etSQLESCAPE 12 /* Strings with '\'' doubled. %q */
|
||||
#define etSQLESCAPE2 13 /* Strings with '\'' doubled and enclosed in '',
|
||||
NULL pointers replaced by SQL NULL. %Q */
|
||||
#define etTOKEN 14 /* a pointer to a Token structure */
|
||||
#define etSRCLIST 15 /* a pointer to a SrcList */
|
||||
|
||||
|
||||
/*
|
||||
** An "etByte" is an 8-bit unsigned value.
|
||||
*/
|
||||
typedef unsigned char etByte;
|
||||
|
||||
/*
|
||||
** Each builtin conversion character (ex: the 'd' in "%d") is described
|
||||
** by an instance of the following structure
|
||||
*/
|
||||
typedef struct et_info { /* Information about each format field */
|
||||
int fmttype; /* The format field code letter */
|
||||
int base; /* The base for radix conversion */
|
||||
char *charset; /* The character set for conversion */
|
||||
int flag_signed; /* Is the quantity signed? */
|
||||
char *prefix; /* Prefix on non-zero values in alt format */
|
||||
enum et_type type; /* Conversion paradigm */
|
||||
char fmttype; /* The format field code letter */
|
||||
etByte base; /* The base for radix conversion */
|
||||
etByte flags; /* One or more of FLAG_ constants below */
|
||||
etByte type; /* Conversion paradigm */
|
||||
char *charset; /* The character set for conversion */
|
||||
char *prefix; /* Prefix on non-zero values in alt format */
|
||||
} et_info;
|
||||
|
||||
/*
|
||||
** Allowed values for et_info.flags
|
||||
*/
|
||||
#define FLAG_SIGNED 1 /* True if the value to convert is signed */
|
||||
#define FLAG_INTERN 2 /* True if for internal use only */
|
||||
|
||||
|
||||
/*
|
||||
** The following table is searched linearly, so it is good to put the
|
||||
** most frequently used conversion types first.
|
||||
*/
|
||||
static et_info fmtinfo[] = {
|
||||
{ 'd', 10, "0123456789", 1, 0, etRADIX, },
|
||||
{ 's', 0, 0, 0, 0, etSTRING, },
|
||||
{ 'q', 0, 0, 0, 0, etSQLESCAPE, },
|
||||
{ 'c', 0, 0, 0, 0, etCHARX, },
|
||||
{ 'o', 8, "01234567", 0, "0", etRADIX, },
|
||||
{ 'u', 10, "0123456789", 0, 0, etRADIX, },
|
||||
{ 'x', 16, "0123456789abcdef", 0, "x0", etRADIX, },
|
||||
{ 'X', 16, "0123456789ABCDEF", 0, "X0", etRADIX, },
|
||||
{ 'r', 10, "0123456789", 0, 0, etORDINAL, },
|
||||
{ 'f', 0, 0, 1, 0, etFLOAT, },
|
||||
{ 'e', 0, "e", 1, 0, etEXP, },
|
||||
{ 'E', 0, "E", 1, 0, etEXP, },
|
||||
{ 'g', 0, "e", 1, 0, etGENERIC, },
|
||||
{ 'G', 0, "E", 1, 0, etGENERIC, },
|
||||
{ 'i', 10, "0123456789", 1, 0, etRADIX, },
|
||||
{ 'n', 0, 0, 0, 0, etSIZE, },
|
||||
{ '%', 0, 0, 0, 0, etPERCENT, },
|
||||
{ 'b', 2, "01", 0, "b0", etRADIX, }, /* Binary */
|
||||
{ 'p', 10, "0123456789", 0, 0, etRADIX, }, /* Pointers */
|
||||
{ '\'', 0, 0, 0, 0, etCHARLIT, }, /* Literal char */
|
||||
{ 'd', 10, 1, etRADIX, "0123456789", 0 },
|
||||
{ 's', 0, 0, etSTRING, 0, 0 },
|
||||
{ 'z', 0, 2, etDYNSTRING, 0, 0 },
|
||||
{ 'q', 0, 0, etSQLESCAPE, 0, 0 },
|
||||
{ 'Q', 0, 0, etSQLESCAPE2, 0, 0 },
|
||||
{ 'c', 0, 0, etCHARX, 0, 0 },
|
||||
{ 'o', 8, 0, etRADIX, "01234567", "0" },
|
||||
{ 'u', 10, 0, etRADIX, "0123456789", 0 },
|
||||
{ 'x', 16, 0, etRADIX, "0123456789abcdef", "x0" },
|
||||
{ 'X', 16, 0, etRADIX, "0123456789ABCDEF", "X0" },
|
||||
{ 'f', 0, 1, etFLOAT, 0, 0 },
|
||||
{ 'e', 0, 1, etEXP, "e", 0 },
|
||||
{ 'E', 0, 1, etEXP, "E", 0 },
|
||||
{ 'g', 0, 1, etGENERIC, "e", 0 },
|
||||
{ 'G', 0, 1, etGENERIC, "E", 0 },
|
||||
{ 'i', 10, 1, etRADIX, "0123456789", 0 },
|
||||
{ 'n', 0, 0, etSIZE, 0, 0 },
|
||||
{ '%', 0, 0, etPERCENT, 0, 0 },
|
||||
{ 'p', 10, 0, etRADIX, "0123456789", 0 },
|
||||
{ 'T', 0, 2, etTOKEN, 0, 0 },
|
||||
{ 'S', 0, 2, etSRCLIST, 0, 0 },
|
||||
};
|
||||
#define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
|
||||
|
||||
@@ -134,9 +147,9 @@ static et_info fmtinfo[] = {
|
||||
** 16 (the number of significant digits in a 64-bit float) '0' is
|
||||
** always returned.
|
||||
*/
|
||||
static int et_getdigit(double *val, int *cnt){
|
||||
static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
|
||||
int digit;
|
||||
double d;
|
||||
LONGDOUBLE_TYPE d;
|
||||
if( (*cnt)++ >= 16 ) return '0';
|
||||
digit = (int)*val;
|
||||
d = digit;
|
||||
@@ -176,53 +189,50 @@ static int et_getdigit(double *val, int *cnt){
|
||||
** will run.
|
||||
*/
|
||||
static int vxprintf(
|
||||
void (*func)(void*,char*,int),
|
||||
void *arg,
|
||||
const char *format,
|
||||
va_list ap
|
||||
void (*func)(void*,const char*,int), /* Consumer of text */
|
||||
void *arg, /* First argument to the consumer */
|
||||
int useExtended, /* Allow extended %-conversions */
|
||||
const char *fmt, /* Format string */
|
||||
va_list ap /* arguments */
|
||||
){
|
||||
register const char *fmt; /* The format string. */
|
||||
register int c; /* Next character in the format string */
|
||||
register char *bufpt; /* Pointer to the conversion buffer */
|
||||
register int precision; /* Precision of the current field */
|
||||
register int length; /* Length of the field */
|
||||
register int idx; /* A general purpose loop counter */
|
||||
int count; /* Total number of characters output */
|
||||
int width; /* Width of the current field */
|
||||
int flag_leftjustify; /* True if "-" flag is present */
|
||||
int flag_plussign; /* True if "+" flag is present */
|
||||
int flag_blanksign; /* True if " " flag is present */
|
||||
int flag_alternateform; /* True if "#" flag is present */
|
||||
int flag_zeropad; /* True if field width constant starts with zero */
|
||||
int flag_long; /* True if "l" flag is present */
|
||||
int flag_center; /* True if "=" flag is present */
|
||||
unsigned long longvalue; /* Value for integer types */
|
||||
double realvalue; /* Value for real types */
|
||||
et_info *infop; /* Pointer to the appropriate info structure */
|
||||
char buf[etBUFSIZE]; /* Conversion buffer */
|
||||
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
|
||||
int errorflag = 0; /* True if an error is encountered */
|
||||
enum et_type xtype; /* Conversion paradigm */
|
||||
char *zMem; /* String to be freed */
|
||||
char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
|
||||
static char spaces[] = " "
|
||||
" ";
|
||||
int c; /* Next character in the format string */
|
||||
char *bufpt; /* Pointer to the conversion buffer */
|
||||
int precision; /* Precision of the current field */
|
||||
int length; /* Length of the field */
|
||||
int idx; /* A general purpose loop counter */
|
||||
int count; /* Total number of characters output */
|
||||
int width; /* Width of the current field */
|
||||
etByte flag_leftjustify; /* True if "-" flag is present */
|
||||
etByte flag_plussign; /* True if "+" flag is present */
|
||||
etByte flag_blanksign; /* True if " " flag is present */
|
||||
etByte flag_alternateform; /* True if "#" flag is present */
|
||||
etByte flag_zeropad; /* True if field width constant starts with zero */
|
||||
etByte flag_long; /* True if "l" flag is present */
|
||||
unsigned long longvalue; /* Value for integer types */
|
||||
LONGDOUBLE_TYPE realvalue; /* Value for real types */
|
||||
et_info *infop; /* Pointer to the appropriate info structure */
|
||||
char buf[etBUFSIZE]; /* Conversion buffer */
|
||||
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
|
||||
etByte errorflag = 0; /* True if an error is encountered */
|
||||
etByte xtype; /* Conversion paradigm */
|
||||
char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
|
||||
static char spaces[] = " ";
|
||||
#define etSPACESIZE (sizeof(spaces)-1)
|
||||
#ifndef etNOFLOATINGPOINT
|
||||
int exp; /* exponent of real numbers */
|
||||
double rounder; /* Used for rounding floating point values */
|
||||
int flag_dp; /* True if decimal point should be shown */
|
||||
int flag_rtz; /* True if trailing zeros should be removed */
|
||||
int flag_exp; /* True to force display of the exponent */
|
||||
int nsd; /* Number of significant digits returned */
|
||||
int exp; /* exponent of real numbers */
|
||||
double rounder; /* Used for rounding floating point values */
|
||||
etByte flag_dp; /* True if decimal point should be shown */
|
||||
etByte flag_rtz; /* True if trailing zeros should be removed */
|
||||
etByte flag_exp; /* True to force display of the exponent */
|
||||
int nsd; /* Number of significant digits returned */
|
||||
#endif
|
||||
|
||||
fmt = format; /* Put in a register for speed */
|
||||
func(arg,"",0);
|
||||
count = length = 0;
|
||||
bufpt = 0;
|
||||
for(; (c=(*fmt))!=0; ++fmt){
|
||||
if( c!='%' ){
|
||||
register int amt;
|
||||
int amt;
|
||||
bufpt = (char *)fmt;
|
||||
amt = 1;
|
||||
while( (c=(*++fmt))!='%' && c!=0 ) amt++;
|
||||
@@ -238,7 +248,7 @@ static int vxprintf(
|
||||
}
|
||||
/* Find out what flags are present */
|
||||
flag_leftjustify = flag_plussign = flag_blanksign =
|
||||
flag_alternateform = flag_zeropad = flag_center = 0;
|
||||
flag_alternateform = flag_zeropad = 0;
|
||||
do{
|
||||
switch( c ){
|
||||
case '-': flag_leftjustify = 1; c = 0; break;
|
||||
@@ -246,11 +256,9 @@ static int vxprintf(
|
||||
case ' ': flag_blanksign = 1; c = 0; break;
|
||||
case '#': flag_alternateform = 1; c = 0; break;
|
||||
case '0': flag_zeropad = 1; c = 0; break;
|
||||
case '=': flag_center = 1; c = 0; break;
|
||||
default: break;
|
||||
}
|
||||
}while( c==0 && (c=(*++fmt))!=0 );
|
||||
if( flag_center ) flag_leftjustify = 0;
|
||||
/* Get the field width */
|
||||
width = 0;
|
||||
if( c=='*' ){
|
||||
@@ -275,10 +283,7 @@ static int vxprintf(
|
||||
c = *++fmt;
|
||||
if( c=='*' ){
|
||||
precision = va_arg(ap,int);
|
||||
#ifndef etCOMPATIBILITY
|
||||
/* This is sensible, but SUN OS 4.1 doesn't do it. */
|
||||
if( precision<0 ) precision = -precision;
|
||||
#endif
|
||||
c = *++fmt;
|
||||
}else{
|
||||
while( c>='0' && c<='9' ){
|
||||
@@ -300,18 +305,16 @@ static int vxprintf(
|
||||
}
|
||||
/* Fetch the info entry for the field */
|
||||
infop = 0;
|
||||
xtype = etERROR;
|
||||
for(idx=0; idx<etNINFO; idx++){
|
||||
if( c==fmtinfo[idx].fmttype ){
|
||||
infop = &fmtinfo[idx];
|
||||
if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
|
||||
xtype = infop->type;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* No info entry found. It must be an error. */
|
||||
if( infop==0 ){
|
||||
xtype = etERROR;
|
||||
}else{
|
||||
xtype = infop->type;
|
||||
}
|
||||
zExtra = 0;
|
||||
|
||||
/*
|
||||
@@ -333,11 +336,10 @@ static int vxprintf(
|
||||
** infop Pointer to the appropriate info struct.
|
||||
*/
|
||||
switch( xtype ){
|
||||
case etORDINAL:
|
||||
case etRADIX:
|
||||
if( flag_long ) longvalue = va_arg(ap,long);
|
||||
else longvalue = va_arg(ap,int);
|
||||
#ifdef etCOMPATIBILITY
|
||||
else longvalue = va_arg(ap,int);
|
||||
#if 1
|
||||
/* For the format %#x, the value zero is printed "0" not "0x0".
|
||||
** I think this is stupid. */
|
||||
if( longvalue==0 ) flag_alternateform = 0;
|
||||
@@ -346,7 +348,7 @@ static int vxprintf(
|
||||
** but leave the prefix for hex. */
|
||||
if( longvalue==0 && infop->base==8 ) flag_alternateform = 0;
|
||||
#endif
|
||||
if( infop->flag_signed ){
|
||||
if( infop->flags & FLAG_SIGNED ){
|
||||
if( *(long*)&longvalue<0 ){
|
||||
longvalue = -*(long*)&longvalue;
|
||||
prefix = '-';
|
||||
@@ -356,27 +358,8 @@ static int vxprintf(
|
||||
}else prefix = 0;
|
||||
if( flag_zeropad && precision<width-(prefix!=0) ){
|
||||
precision = width-(prefix!=0);
|
||||
}
|
||||
bufpt = &buf[etBUFSIZE];
|
||||
if( xtype==etORDINAL ){
|
||||
long a,b;
|
||||
a = longvalue%10;
|
||||
b = longvalue%100;
|
||||
bufpt -= 2;
|
||||
if( a==0 || a>3 || (b>10 && b<14) ){
|
||||
bufpt[0] = 't';
|
||||
bufpt[1] = 'h';
|
||||
}else if( a==1 ){
|
||||
bufpt[0] = 's';
|
||||
bufpt[1] = 't';
|
||||
}else if( a==2 ){
|
||||
bufpt[0] = 'n';
|
||||
bufpt[1] = 'd';
|
||||
}else if( a==3 ){
|
||||
bufpt[0] = 'r';
|
||||
bufpt[1] = 'd';
|
||||
}
|
||||
}
|
||||
bufpt = &buf[etBUFSIZE-1];
|
||||
{
|
||||
register char *cset; /* Use registers for speed */
|
||||
register int base;
|
||||
@@ -386,20 +369,20 @@ static int vxprintf(
|
||||
*(--bufpt) = cset[longvalue%base];
|
||||
longvalue = longvalue/base;
|
||||
}while( longvalue>0 );
|
||||
}
|
||||
length = (long)&buf[etBUFSIZE]-(long)bufpt;
|
||||
}
|
||||
length = &buf[etBUFSIZE-1]-bufpt;
|
||||
for(idx=precision-length; idx>0; idx--){
|
||||
*(--bufpt) = '0'; /* Zero pad */
|
||||
}
|
||||
}
|
||||
if( prefix ) *(--bufpt) = prefix; /* Add sign */
|
||||
if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */
|
||||
char *pre, x;
|
||||
pre = infop->prefix;
|
||||
if( *bufpt!=pre[0] ){
|
||||
for(pre=infop->prefix; (x=(*pre))!=0; pre++) *(--bufpt) = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
length = (long)&buf[etBUFSIZE]-(long)bufpt;
|
||||
length = &buf[etBUFSIZE-1]-bufpt;
|
||||
break;
|
||||
case etFLOAT:
|
||||
case etEXP:
|
||||
@@ -411,14 +394,14 @@ static int vxprintf(
|
||||
if( realvalue<0.0 ){
|
||||
realvalue = -realvalue;
|
||||
prefix = '-';
|
||||
}else{
|
||||
}else{
|
||||
if( flag_plussign ) prefix = '+';
|
||||
else if( flag_blanksign ) prefix = ' ';
|
||||
else prefix = 0;
|
||||
}
|
||||
}
|
||||
if( infop->type==etGENERIC && precision>0 ) precision--;
|
||||
rounder = 0.0;
|
||||
#ifdef COMPATIBILITY
|
||||
#if 0
|
||||
/* Rounding works like BSD when the constant 0.4999 is used. Wierd! */
|
||||
for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);
|
||||
#else
|
||||
@@ -429,17 +412,16 @@ static int vxprintf(
|
||||
/* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
|
||||
exp = 0;
|
||||
if( realvalue>0.0 ){
|
||||
int k = 0;
|
||||
while( realvalue>=1e8 && k++<100 ){ realvalue *= 1e-8; exp+=8; }
|
||||
while( realvalue>=10.0 && k++<100 ){ realvalue *= 0.1; exp++; }
|
||||
while( realvalue<1e-8 && k++<100 ){ realvalue *= 1e8; exp-=8; }
|
||||
while( realvalue<1.0 && k++<100 ){ realvalue *= 10.0; exp--; }
|
||||
if( k>=100 ){
|
||||
while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
|
||||
while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
|
||||
while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
|
||||
while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
|
||||
if( exp>350 || exp<-350 ){
|
||||
bufpt = "NaN";
|
||||
length = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
bufpt = buf;
|
||||
/*
|
||||
** If the field type is etGENERIC, then convert to either etEXP
|
||||
@@ -458,9 +440,9 @@ static int vxprintf(
|
||||
precision = precision - exp;
|
||||
xtype = etFLOAT;
|
||||
}
|
||||
}else{
|
||||
}else{
|
||||
flag_rtz = 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
** The "exp+precision" test causes output to be of type etEXP if
|
||||
** the precision is too large to fit in buf[].
|
||||
@@ -482,7 +464,7 @@ static int vxprintf(
|
||||
if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0;
|
||||
}
|
||||
bufpt++; /* point to next free slot */
|
||||
}else{ /* etEXP or etGENERIC */
|
||||
}else{ /* etEXP or etGENERIC */
|
||||
flag_dp = (precision>0 || flag_alternateform);
|
||||
if( prefix ) *(bufpt++) = prefix; /* Sign */
|
||||
*(bufpt++) = et_getdigit(&realvalue,&nsd); /* First digit */
|
||||
@@ -501,15 +483,15 @@ static int vxprintf(
|
||||
if( exp>=100 ){
|
||||
*(bufpt++) = (exp/100)+'0'; /* 100's digit */
|
||||
exp %= 100;
|
||||
}
|
||||
}
|
||||
*(bufpt++) = exp/10+'0'; /* 10's digit */
|
||||
*(bufpt++) = exp%10+'0'; /* 1's digit */
|
||||
}
|
||||
}
|
||||
}
|
||||
/* The converted number is in buf[] and zero terminated. Output it.
|
||||
** Note that the number is in the usual order, not reversed as with
|
||||
** integer conversions. */
|
||||
length = (long)bufpt-(long)buf;
|
||||
length = bufpt-buf;
|
||||
bufpt = buf;
|
||||
|
||||
/* Special case: Add leading zeros if the flag_zeropad flag is
|
||||
@@ -541,41 +523,70 @@ static int vxprintf(
|
||||
if( precision>=0 ){
|
||||
for(idx=1; idx<precision; idx++) buf[idx] = c;
|
||||
length = precision;
|
||||
}else{
|
||||
}else{
|
||||
length =1;
|
||||
}
|
||||
}
|
||||
bufpt = buf;
|
||||
break;
|
||||
case etSTRING:
|
||||
zMem = bufpt = va_arg(ap,char*);
|
||||
if( bufpt==0 ) bufpt = "(null)";
|
||||
case etDYNSTRING:
|
||||
bufpt = va_arg(ap,char*);
|
||||
if( bufpt==0 ){
|
||||
bufpt = "";
|
||||
}else if( xtype==etDYNSTRING ){
|
||||
zExtra = bufpt;
|
||||
}
|
||||
length = strlen(bufpt);
|
||||
if( precision>=0 && precision<length ) length = precision;
|
||||
break;
|
||||
case etSQLESCAPE:
|
||||
case etSQLESCAPE2:
|
||||
{
|
||||
int i, j, n, c;
|
||||
int i, j, n, c, isnull;
|
||||
char *arg = va_arg(ap,char*);
|
||||
if( arg==0 ) arg = "(NULL)";
|
||||
isnull = arg==0;
|
||||
if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
|
||||
for(i=n=0; (c=arg[i])!=0; i++){
|
||||
if( c=='\'' ) n++;
|
||||
}
|
||||
n += i + 1;
|
||||
n += i + 1 + ((!isnull && xtype==etSQLESCAPE2) ? 2 : 0);
|
||||
if( n>etBUFSIZE ){
|
||||
bufpt = zExtra = sqliteMalloc( n );
|
||||
if( bufpt==0 ) return -1;
|
||||
}else{
|
||||
bufpt = buf;
|
||||
}
|
||||
for(i=j=0; (c=arg[i])!=0; i++){
|
||||
j = 0;
|
||||
if( !isnull && xtype==etSQLESCAPE2 ) bufpt[j++] = '\'';
|
||||
for(i=0; (c=arg[i])!=0; i++){
|
||||
bufpt[j++] = c;
|
||||
if( c=='\'' ) bufpt[j++] = c;
|
||||
}
|
||||
if( !isnull && xtype==etSQLESCAPE2 ) bufpt[j++] = '\'';
|
||||
bufpt[j] = 0;
|
||||
length = j;
|
||||
if( precision>=0 && precision<length ) length = precision;
|
||||
}
|
||||
break;
|
||||
case etTOKEN: {
|
||||
Token *pToken = va_arg(ap, Token*);
|
||||
(*func)(arg, pToken->z, pToken->n);
|
||||
length = width = 0;
|
||||
break;
|
||||
}
|
||||
case etSRCLIST: {
|
||||
SrcList *pSrc = va_arg(ap, SrcList*);
|
||||
int k = va_arg(ap, int);
|
||||
struct SrcList_item *pItem = &pSrc->a[k];
|
||||
assert( k>=0 && k<pSrc->nSrc );
|
||||
if( pItem->zDatabase && pItem->zDatabase[0] ){
|
||||
(*func)(arg, pItem->zDatabase, strlen(pItem->zDatabase));
|
||||
(*func)(arg, ".", 1);
|
||||
}
|
||||
(*func)(arg, pItem->zName, strlen(pItem->zName));
|
||||
length = width = 0;
|
||||
break;
|
||||
}
|
||||
case etERROR:
|
||||
buf[0] = '%';
|
||||
buf[1] = c;
|
||||
@@ -595,11 +606,6 @@ static int vxprintf(
|
||||
register int nspace;
|
||||
nspace = width-length;
|
||||
if( nspace>0 ){
|
||||
if( flag_center ){
|
||||
nspace = nspace/2;
|
||||
width -= nspace;
|
||||
flag_leftjustify = 1;
|
||||
}
|
||||
count += nspace;
|
||||
while( nspace>=etSPACESIZE ){
|
||||
(*func)(arg,spaces,etSPACESIZE);
|
||||
@@ -639,7 +645,9 @@ struct sgMprintf {
|
||||
char *zBase; /* A base allocation */
|
||||
char *zText; /* The string collected so far */
|
||||
int nChar; /* Length of the string so far */
|
||||
int nTotal; /* Output size if unconstrained */
|
||||
int nAlloc; /* Amount of space allocated in zText */
|
||||
void *(*xRealloc)(void*,int); /* Function used to realloc memory */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -648,70 +656,130 @@ struct sgMprintf {
|
||||
** This routine add nNewChar characters of text in zNewText to
|
||||
** the sgMprintf structure pointed to by "arg".
|
||||
*/
|
||||
static void mout(void *arg, char *zNewText, int nNewChar){
|
||||
static void mout(void *arg, const char *zNewText, int nNewChar){
|
||||
struct sgMprintf *pM = (struct sgMprintf*)arg;
|
||||
pM->nTotal += nNewChar;
|
||||
if( pM->nChar + nNewChar + 1 > pM->nAlloc ){
|
||||
pM->nAlloc = pM->nChar + nNewChar*2 + 1;
|
||||
if( pM->zText==pM->zBase ){
|
||||
pM->zText = sqliteMalloc(pM->nAlloc);
|
||||
if( pM->zText && pM->nChar ) memcpy(pM->zText,pM->zBase,pM->nChar);
|
||||
if( pM->xRealloc==0 ){
|
||||
nNewChar = pM->nAlloc - pM->nChar - 1;
|
||||
}else{
|
||||
pM->zText = sqliteRealloc(pM->zText, pM->nAlloc);
|
||||
pM->nAlloc = pM->nChar + nNewChar*2 + 1;
|
||||
if( pM->zText==pM->zBase ){
|
||||
pM->zText = pM->xRealloc(0, pM->nAlloc);
|
||||
if( pM->zText && pM->nChar ){
|
||||
memcpy(pM->zText, pM->zBase, pM->nChar);
|
||||
}
|
||||
}else{
|
||||
pM->zText = pM->xRealloc(pM->zText, pM->nAlloc);
|
||||
}
|
||||
}
|
||||
}
|
||||
if( pM->zText ){
|
||||
memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
|
||||
pM->nChar += nNewChar;
|
||||
if( nNewChar>0 ){
|
||||
memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
|
||||
pM->nChar += nNewChar;
|
||||
}
|
||||
pM->zText[pM->nChar] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** sqlite_mprintf() works like printf(), but allocations memory to hold the
|
||||
** resulting string and returns a pointer to the allocated memory. Use
|
||||
** sqliteFree() to release the memory allocated.
|
||||
** This routine is a wrapper around xprintf() that invokes mout() as
|
||||
** the consumer.
|
||||
*/
|
||||
static char *base_vprintf(
|
||||
void *(*xRealloc)(void*,int), /* Routine to realloc memory. May be NULL */
|
||||
int useInternal, /* Use internal %-conversions if true */
|
||||
char *zInitBuf, /* Initially write here, before mallocing */
|
||||
int nInitBuf, /* Size of zInitBuf[] */
|
||||
const char *zFormat, /* format string */
|
||||
va_list ap /* arguments */
|
||||
){
|
||||
struct sgMprintf sM;
|
||||
sM.zBase = sM.zText = zInitBuf;
|
||||
sM.nChar = sM.nTotal = 0;
|
||||
sM.nAlloc = nInitBuf;
|
||||
sM.xRealloc = xRealloc;
|
||||
vxprintf(mout, &sM, useInternal, zFormat, ap);
|
||||
if( xRealloc ){
|
||||
if( sM.zText==sM.zBase ){
|
||||
sM.zText = xRealloc(0, sM.nChar+1);
|
||||
memcpy(sM.zText, sM.zBase, sM.nChar+1);
|
||||
}else if( sM.nAlloc>sM.nChar+10 ){
|
||||
sM.zText = xRealloc(sM.zText, sM.nChar+1);
|
||||
}
|
||||
}
|
||||
return sM.zText;
|
||||
}
|
||||
|
||||
/*
|
||||
** Realloc that is a real function, not a macro.
|
||||
*/
|
||||
static void *printf_realloc(void *old, int size){
|
||||
return sqliteRealloc(old,size);
|
||||
}
|
||||
|
||||
/*
|
||||
** Print into memory obtained from sqliteMalloc(). Use the internal
|
||||
** %-conversion extensions.
|
||||
*/
|
||||
char *sqliteVMPrintf(const char *zFormat, va_list ap){
|
||||
char zBase[1000];
|
||||
return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
|
||||
}
|
||||
|
||||
/*
|
||||
** Print into memory obtained from sqliteMalloc(). Use the internal
|
||||
** %-conversion extensions.
|
||||
*/
|
||||
char *sqliteMPrintf(const char *zFormat, ...){
|
||||
va_list ap;
|
||||
char *z;
|
||||
char zBase[1000];
|
||||
va_start(ap, zFormat);
|
||||
z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
|
||||
va_end(ap);
|
||||
return z;
|
||||
}
|
||||
|
||||
/*
|
||||
** Print into memory obtained from malloc(). Do not use the internal
|
||||
** %-conversion extensions. This routine is for use by external users.
|
||||
*/
|
||||
char *sqlite_mprintf(const char *zFormat, ...){
|
||||
va_list ap;
|
||||
struct sgMprintf sMprintf;
|
||||
char *zNew;
|
||||
char *z;
|
||||
char zBuf[200];
|
||||
|
||||
sMprintf.nChar = 0;
|
||||
sMprintf.nAlloc = sizeof(zBuf);
|
||||
sMprintf.zText = zBuf;
|
||||
sMprintf.zBase = zBuf;
|
||||
va_start(ap,zFormat);
|
||||
vxprintf(mout,&sMprintf,zFormat,ap);
|
||||
z = base_vprintf((void*(*)(void*,int))realloc, 0,
|
||||
zBuf, sizeof(zBuf), zFormat, ap);
|
||||
va_end(ap);
|
||||
sMprintf.zText[sMprintf.nChar] = 0;
|
||||
if( sMprintf.zText==sMprintf.zBase ){
|
||||
zNew = sqliteMalloc( sMprintf.nChar+1 );
|
||||
if( zNew ) strcpy(zNew,zBuf);
|
||||
}else{
|
||||
zNew = sqliteRealloc(sMprintf.zText,sMprintf.nChar+1);
|
||||
}
|
||||
return zNew;
|
||||
return z;
|
||||
}
|
||||
|
||||
/* This is the varargs version of sqlite_mprintf.
|
||||
*/
|
||||
char *sqlite_vmprintf(const char *zFormat, va_list ap){
|
||||
struct sgMprintf sMprintf;
|
||||
char zBuf[200];
|
||||
sMprintf.nChar = 0;
|
||||
sMprintf.zText = zBuf;
|
||||
sMprintf.nAlloc = sizeof(zBuf);
|
||||
sMprintf.zBase = zBuf;
|
||||
vxprintf(mout,&sMprintf,zFormat,ap);
|
||||
sMprintf.zText[sMprintf.nChar] = 0;
|
||||
if( sMprintf.zText==sMprintf.zBase ){
|
||||
sMprintf.zText = sqliteMalloc( strlen(zBuf)+1 );
|
||||
if( sMprintf.zText ) strcpy(sMprintf.zText,zBuf);
|
||||
}else{
|
||||
sMprintf.zText = sqliteRealloc(sMprintf.zText,sMprintf.nChar+1);
|
||||
}
|
||||
return sMprintf.zText;
|
||||
return base_vprintf((void*(*)(void*,int))realloc, 0,
|
||||
zBuf, sizeof(zBuf), zFormat, ap);
|
||||
}
|
||||
|
||||
/*
|
||||
** sqlite_snprintf() works like snprintf() except that it ignores the
|
||||
** current locale settings. This is important for SQLite because we
|
||||
** are not able to use a "," as the decimal point in place of "." as
|
||||
** specified by some locales.
|
||||
*/
|
||||
char *sqlite_snprintf(int n, char *zBuf, const char *zFormat, ...){
|
||||
char *z;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap,zFormat);
|
||||
z = base_vprintf(0, 0, zBuf, n, zFormat, ap);
|
||||
va_end(ap);
|
||||
return z;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -724,7 +792,7 @@ char *sqlite_vmprintf(const char *zFormat, va_list ap){
|
||||
*/
|
||||
int sqlite_exec_printf(
|
||||
sqlite *db, /* An open database */
|
||||
char *sqlFormat, /* printf-style format string for the SQL */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
sqlite_callback xCallback, /* Callback function */
|
||||
void *pArg, /* 1st argument to callback function */
|
||||
char **errmsg, /* Error msg written here */
|
||||
@@ -740,7 +808,7 @@ int sqlite_exec_printf(
|
||||
}
|
||||
int sqlite_exec_vprintf(
|
||||
sqlite *db, /* An open database */
|
||||
char *sqlFormat, /* printf-style format string for the SQL */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
sqlite_callback xCallback, /* Callback function */
|
||||
void *pArg, /* 1st argument to callback function */
|
||||
char **errmsg, /* Error msg written here */
|
||||
@@ -751,12 +819,12 @@ int sqlite_exec_vprintf(
|
||||
|
||||
zSql = sqlite_vmprintf(sqlFormat, ap);
|
||||
rc = sqlite_exec(db, zSql, xCallback, pArg, errmsg);
|
||||
sqliteFree(zSql);
|
||||
free(zSql);
|
||||
return rc;
|
||||
}
|
||||
int sqlite_get_table_printf(
|
||||
sqlite *db, /* An open database */
|
||||
char *sqlFormat, /* printf-style format string for the SQL */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
char ***resultp, /* Result written to a char *[] that this points to */
|
||||
int *nrow, /* Number of result rows written here */
|
||||
int *ncol, /* Number of result columns written here */
|
||||
@@ -773,7 +841,7 @@ int sqlite_get_table_printf(
|
||||
}
|
||||
int sqlite_get_table_vprintf(
|
||||
sqlite *db, /* An open database */
|
||||
char *sqlFormat, /* printf-style format string for the SQL */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
char ***resultp, /* Result written to a char *[] that this points to */
|
||||
int *nrow, /* Number of result rows written here */
|
||||
int *ncolumn, /* Number of result columns written here */
|
||||
@@ -785,6 +853,6 @@ int sqlite_get_table_vprintf(
|
||||
|
||||
zSql = sqlite_vmprintf(sqlFormat, ap);
|
||||
rc = sqlite_get_table(db, zSql, resultp, nrow, ncolumn, errmsg);
|
||||
sqliteFree(zSql);
|
||||
free(zSql);
|
||||
return rc;
|
||||
}
|
||||
|
||||
+25
-31
@@ -15,25 +15,35 @@
|
||||
** 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.8 2001/10/09 04:19:47 drh Exp $
|
||||
** $Id: random.c,v 1.11 2004/02/11 09:46:33 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
|
||||
|
||||
/*
|
||||
** Get a single 8-bit random value from the RC4 PRNG. The Mutex
|
||||
** 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
|
||||
** 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.
|
||||
*/
|
||||
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,
|
||||
@@ -55,8 +65,7 @@ static int randomByte(){
|
||||
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;
|
||||
@@ -66,38 +75,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;
|
||||
void sqliteRandomness(int N, void *pBuf){
|
||||
unsigned char *zBuf = pBuf;
|
||||
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();
|
||||
while( N-- ){
|
||||
*(zBuf++) = randomByte();
|
||||
}
|
||||
sqliteOsLeaveMutex();
|
||||
return r;
|
||||
}
|
||||
|
||||
+1880
-422
File diff suppressed because it is too large
Load Diff
+639
-208
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
|
||||
+546
-16
@@ -12,17 +12,12 @@
|
||||
** This header file defines the interface that the SQLite library
|
||||
** presents to client programs.
|
||||
**
|
||||
** @(#) $Id: sqlite.h.in,v 1.21 2001/10/06 16:33:03 drh Exp $
|
||||
** @(#) $Id: sqlite.h.in,v 1.60.2.1 2004/10/06 15:52:36 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_H_
|
||||
#define _SQLITE_H_
|
||||
#include <stdarg.h> /* Needed for the definition of va_list */
|
||||
|
||||
/*
|
||||
** The version of the SQLite library.
|
||||
*/
|
||||
#define SQLITE_VERSION "--VERS--"
|
||||
|
||||
/*
|
||||
** Make sure we can call this stuff from C++.
|
||||
*/
|
||||
@@ -30,6 +25,15 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The version of the SQLite library.
|
||||
*/
|
||||
#ifdef SQLITE_VERSION
|
||||
# undef SQLITE_VERSION
|
||||
#else
|
||||
# define SQLITE_VERSION "--VERS--"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The version string is also compiled into the library so that a program
|
||||
** can check to make sure that the lib*.a file and the *.h file are from
|
||||
@@ -73,7 +77,7 @@ typedef struct sqlite sqlite;
|
||||
** The Truth: As currently implemented, all databases are opened
|
||||
** for writing all the time. Maybe someday we will provide the
|
||||
** ability to open a database readonly. The mode parameters is
|
||||
** provide in anticipation of that enhancement.
|
||||
** provided in anticipation of that enhancement.
|
||||
*/
|
||||
sqlite *sqlite_open(const char *filename, int mode, char **errmsg);
|
||||
|
||||
@@ -118,7 +122,8 @@ typedef int (*sqlite_callback)(void*,int,char**, char**);
|
||||
** message is written into memory obtained from malloc() and
|
||||
** *errmsg is made to point to that message. The calling function
|
||||
** is responsible for freeing the memory that holds the error
|
||||
** message. If errmsg==NULL, then no error message is ever written.
|
||||
** message. Use sqlite_freemem() for this. If errmsg==NULL,
|
||||
** then no error message is ever written.
|
||||
**
|
||||
** The return value is is SQLITE_OK if there are no errors and
|
||||
** some other return code if there is an error. The particular
|
||||
@@ -131,14 +136,14 @@ typedef int (*sqlite_callback)(void*,int,char**, char**);
|
||||
*/
|
||||
int sqlite_exec(
|
||||
sqlite*, /* An open database */
|
||||
char *sql, /* SQL to be executed */
|
||||
const char *sql, /* SQL to be executed */
|
||||
sqlite_callback, /* Callback function */
|
||||
void *, /* 1st argument to callback function */
|
||||
char **errmsg /* Error msg written here */
|
||||
);
|
||||
|
||||
/*
|
||||
** Return values for sqlite_exec()
|
||||
** Return values for sqlite_exec() and sqlite_step()
|
||||
*/
|
||||
#define SQLITE_OK 0 /* Successful result */
|
||||
#define SQLITE_ERROR 1 /* SQL error or missing database */
|
||||
@@ -160,12 +165,81 @@ int sqlite_exec(
|
||||
#define SQLITE_SCHEMA 17 /* The database schema changed */
|
||||
#define SQLITE_TOOBIG 18 /* Too much data for one row of a table */
|
||||
#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */
|
||||
#define SQLITE_MISMATCH 20 /* Data type mismatch */
|
||||
#define SQLITE_MISUSE 21 /* Library used incorrectly */
|
||||
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
|
||||
#define SQLITE_AUTH 23 /* Authorization denied */
|
||||
#define SQLITE_FORMAT 24 /* Auxiliary database format error */
|
||||
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite_bind out of range */
|
||||
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
|
||||
#define SQLITE_ROW 100 /* sqlite_step() has another row ready */
|
||||
#define SQLITE_DONE 101 /* sqlite_step() has finished executing */
|
||||
|
||||
/*
|
||||
** Each entry in an SQLite table has a unique integer key. (The key is
|
||||
** the value of the INTEGER PRIMARY KEY column if there is such a column,
|
||||
** otherwise the key is generated at random. The unique key is always
|
||||
** available as the ROWID, OID, or _ROWID_ column.) The following routine
|
||||
** returns the integer key of the most recent insert in the database.
|
||||
**
|
||||
** This function is similar to the mysql_insert_id() function from MySQL.
|
||||
*/
|
||||
int sqlite_last_insert_rowid(sqlite*);
|
||||
|
||||
/*
|
||||
** This function returns the number of database rows that were changed
|
||||
** (or inserted or deleted) by the most recent called sqlite_exec().
|
||||
**
|
||||
** All changes are counted, even if they were later undone by a
|
||||
** ROLLBACK or ABORT. Except, changes associated with creating and
|
||||
** dropping tables are not counted.
|
||||
**
|
||||
** If a callback invokes sqlite_exec() recursively, then the changes
|
||||
** in the inner, recursive call are counted together with the changes
|
||||
** in the outer call.
|
||||
**
|
||||
** SQLite implements the command "DELETE FROM table" without a WHERE clause
|
||||
** by dropping and recreating the table. (This is much faster than going
|
||||
** through and deleting individual elements form the table.) Because of
|
||||
** this optimization, the change count for "DELETE FROM table" will be
|
||||
** zero regardless of the number of elements that were originally in the
|
||||
** table. To get an accurate count of the number of rows deleted, use
|
||||
** "DELETE FROM table WHERE 1" instead.
|
||||
*/
|
||||
int sqlite_changes(sqlite*);
|
||||
|
||||
/*
|
||||
** This function returns the number of database rows that were changed
|
||||
** by the last INSERT, UPDATE, or DELETE statment executed by sqlite_exec(),
|
||||
** or by the last VM to run to completion. The change count is not updated
|
||||
** by SQL statements other than INSERT, UPDATE or DELETE.
|
||||
**
|
||||
** Changes are counted, even if they are later undone by a ROLLBACK or
|
||||
** ABORT. Changes associated with trigger programs that execute as a
|
||||
** result of the INSERT, UPDATE, or DELETE statement are not counted.
|
||||
**
|
||||
** If a callback invokes sqlite_exec() recursively, then the changes
|
||||
** in the inner, recursive call are counted together with the changes
|
||||
** in the outer call.
|
||||
**
|
||||
** SQLite implements the command "DELETE FROM table" without a WHERE clause
|
||||
** by dropping and recreating the table. (This is much faster than going
|
||||
** through and deleting individual elements form the table.) Because of
|
||||
** this optimization, the change count for "DELETE FROM table" will be
|
||||
** zero regardless of the number of elements that were originally in the
|
||||
** table. To get an accurate count of the number of rows deleted, use
|
||||
** "DELETE FROM table WHERE 1" instead.
|
||||
**
|
||||
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
|
||||
*/
|
||||
int sqlite_last_statement_changes(sqlite*);
|
||||
|
||||
/* If the parameter to this routine is one of the return value constants
|
||||
** defined above, then this routine returns a constant text string which
|
||||
** descripts (in English) the meaning of the return value.
|
||||
*/
|
||||
const char *sqliteErrStr(int);
|
||||
const char *sqlite_error_string(int);
|
||||
#define sqliteErrStr sqlite_error_string /* Legacy. Do not use in new code. */
|
||||
|
||||
/* This function causes any pending database operation to abort and
|
||||
** return at its earliest opportunity. This routine is typically
|
||||
@@ -264,7 +338,7 @@ void sqlite_busy_timeout(sqlite*, int ms);
|
||||
*/
|
||||
int sqlite_get_table(
|
||||
sqlite*, /* An open database */
|
||||
char *sql, /* SQL to be executed */
|
||||
const char *sql, /* SQL to be executed */
|
||||
char ***resultp, /* Result written to a char *[] that this points to */
|
||||
int *nrow, /* Number of result rows written here */
|
||||
int *ncolumn, /* Number of result columns written here */
|
||||
@@ -316,7 +390,7 @@ void sqlite_free_table(char **result);
|
||||
*/
|
||||
int sqlite_exec_printf(
|
||||
sqlite*, /* An open database */
|
||||
char *sqlFormat, /* printf-style format string for the SQL */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
sqlite_callback, /* Callback function */
|
||||
void *, /* 1st argument to callback function */
|
||||
char **errmsg, /* Error msg written here */
|
||||
@@ -324,7 +398,7 @@ int sqlite_exec_printf(
|
||||
);
|
||||
int sqlite_exec_vprintf(
|
||||
sqlite*, /* An open database */
|
||||
char *sqlFormat, /* printf-style format string for the SQL */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
sqlite_callback, /* Callback function */
|
||||
void *, /* 1st argument to callback function */
|
||||
char **errmsg, /* Error msg written here */
|
||||
@@ -332,7 +406,7 @@ int sqlite_exec_vprintf(
|
||||
);
|
||||
int sqlite_get_table_printf(
|
||||
sqlite*, /* An open database */
|
||||
char *sqlFormat, /* printf-style format string for the SQL */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
char ***resultp, /* Result written to a char *[] that this points to */
|
||||
int *nrow, /* Number of result rows written here */
|
||||
int *ncolumn, /* Number of result columns written here */
|
||||
@@ -341,13 +415,469 @@ int sqlite_get_table_printf(
|
||||
);
|
||||
int sqlite_get_table_vprintf(
|
||||
sqlite*, /* An open database */
|
||||
char *sqlFormat, /* printf-style format string for the SQL */
|
||||
const char *sqlFormat, /* printf-style format string for the SQL */
|
||||
char ***resultp, /* Result written to a char *[] that this points to */
|
||||
int *nrow, /* Number of result rows written here */
|
||||
int *ncolumn, /* Number of result columns written here */
|
||||
char **errmsg, /* Error msg written here */
|
||||
va_list ap /* Arguments to the format string */
|
||||
);
|
||||
char *sqlite_mprintf(const char*,...);
|
||||
char *sqlite_vmprintf(const char*, va_list);
|
||||
|
||||
/*
|
||||
** Windows systems should call this routine to free memory that
|
||||
** is returned in the in the errmsg parameter of sqlite_open() when
|
||||
** SQLite is a DLL. For some reason, it does not work to call free()
|
||||
** directly.
|
||||
*/
|
||||
void sqlite_freemem(void *p);
|
||||
|
||||
/*
|
||||
** Windows systems need functions to call to return the sqlite_version
|
||||
** and sqlite_encoding strings.
|
||||
*/
|
||||
const char *sqlite_libversion(void);
|
||||
const char *sqlite_libencoding(void);
|
||||
|
||||
/*
|
||||
** A pointer to the following structure is used to communicate with
|
||||
** the implementations of user-defined functions.
|
||||
*/
|
||||
typedef struct sqlite_func sqlite_func;
|
||||
|
||||
/*
|
||||
** Use the following routines to create new user-defined functions. See
|
||||
** the documentation for details.
|
||||
*/
|
||||
int sqlite_create_function(
|
||||
sqlite*, /* Database where the new function is registered */
|
||||
const char *zName, /* Name of the new function */
|
||||
int nArg, /* Number of arguments. -1 means any number */
|
||||
void (*xFunc)(sqlite_func*,int,const char**), /* C code to implement */
|
||||
void *pUserData /* Available via the sqlite_user_data() call */
|
||||
);
|
||||
int sqlite_create_aggregate(
|
||||
sqlite*, /* Database where the new function is registered */
|
||||
const char *zName, /* Name of the function */
|
||||
int nArg, /* Number of arguments */
|
||||
void (*xStep)(sqlite_func*,int,const char**), /* Called for each row */
|
||||
void (*xFinalize)(sqlite_func*), /* Called once to get final result */
|
||||
void *pUserData /* Available via the sqlite_user_data() call */
|
||||
);
|
||||
|
||||
/*
|
||||
** Use the following routine to define the datatype returned by a
|
||||
** user-defined function. The second argument can be one of the
|
||||
** constants SQLITE_NUMERIC, SQLITE_TEXT, or SQLITE_ARGS or it
|
||||
** can be an integer greater than or equal to zero. When the datatype
|
||||
** parameter is non-negative, the type of the result will be the
|
||||
** same as the datatype-th argument. If datatype==SQLITE_NUMERIC
|
||||
** then the result is always numeric. If datatype==SQLITE_TEXT then
|
||||
** the result is always text. If datatype==SQLITE_ARGS then the result
|
||||
** is numeric if any argument is numeric and is text otherwise.
|
||||
*/
|
||||
int sqlite_function_type(
|
||||
sqlite *db, /* The database there the function is registered */
|
||||
const char *zName, /* Name of the function */
|
||||
int datatype /* The datatype for this function */
|
||||
);
|
||||
#define SQLITE_NUMERIC (-1)
|
||||
/* #define SQLITE_TEXT (-2) // See below */
|
||||
#define SQLITE_ARGS (-3)
|
||||
|
||||
/*
|
||||
** SQLite version 3 defines SQLITE_TEXT differently. To allow both
|
||||
** version 2 and version 3 to be included, undefine them both if a
|
||||
** conflict is seen. Define SQLITE2_TEXT to be the version 2 value.
|
||||
*/
|
||||
#ifdef SQLITE_TEXT
|
||||
# undef SQLITE_TEXT
|
||||
#else
|
||||
# define SQLITE_TEXT (-2)
|
||||
#endif
|
||||
#define SQLITE2_TEXT (-2)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** The user function implementations call one of the following four routines
|
||||
** in order to return their results. The first parameter to each of these
|
||||
** routines is a copy of the first argument to xFunc() or xFinialize().
|
||||
** The second parameter to these routines is the result to be returned.
|
||||
** A NULL can be passed as the second parameter to sqlite_set_result_string()
|
||||
** in order to return a NULL result.
|
||||
**
|
||||
** The 3rd argument to _string and _error is the number of characters to
|
||||
** take from the string. If this argument is negative, then all characters
|
||||
** up to and including the first '\000' are used.
|
||||
**
|
||||
** The sqlite_set_result_string() function allocates a buffer to hold the
|
||||
** result and returns a pointer to this buffer. The calling routine
|
||||
** (that is, the implmentation of a user function) can alter the content
|
||||
** of this buffer if desired.
|
||||
*/
|
||||
char *sqlite_set_result_string(sqlite_func*,const char*,int);
|
||||
void sqlite_set_result_int(sqlite_func*,int);
|
||||
void sqlite_set_result_double(sqlite_func*,double);
|
||||
void sqlite_set_result_error(sqlite_func*,const char*,int);
|
||||
|
||||
/*
|
||||
** The pUserData parameter to the sqlite_create_function() and
|
||||
** sqlite_create_aggregate() routines used to register user functions
|
||||
** is available to the implementation of the function using this
|
||||
** call.
|
||||
*/
|
||||
void *sqlite_user_data(sqlite_func*);
|
||||
|
||||
/*
|
||||
** Aggregate functions use the following routine to allocate
|
||||
** a structure for storing their state. The first time this routine
|
||||
** is called for a particular aggregate, a new structure of size nBytes
|
||||
** is allocated, zeroed, and returned. On subsequent calls (for the
|
||||
** same aggregate instance) the same buffer is returned. The implementation
|
||||
** of the aggregate can use the returned buffer to accumulate data.
|
||||
**
|
||||
** The buffer allocated is freed automatically be SQLite.
|
||||
*/
|
||||
void *sqlite_aggregate_context(sqlite_func*, int nBytes);
|
||||
|
||||
/*
|
||||
** The next routine returns the number of calls to xStep for a particular
|
||||
** aggregate function instance. The current call to xStep counts so this
|
||||
** routine always returns at least 1.
|
||||
*/
|
||||
int sqlite_aggregate_count(sqlite_func*);
|
||||
|
||||
/*
|
||||
** This routine registers a callback with the SQLite library. The
|
||||
** callback is invoked (at compile-time, not at run-time) for each
|
||||
** attempt to access a column of a table in the database. The callback
|
||||
** returns SQLITE_OK if access is allowed, SQLITE_DENY if the entire
|
||||
** SQL statement should be aborted with an error and SQLITE_IGNORE
|
||||
** if the column should be treated as a NULL value.
|
||||
*/
|
||||
int sqlite_set_authorizer(
|
||||
sqlite*,
|
||||
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
|
||||
void *pUserData
|
||||
);
|
||||
|
||||
/*
|
||||
** The second parameter to the access authorization function above will
|
||||
** be one of the values below. These values signify what kind of operation
|
||||
** is to be authorized. The 3rd and 4th parameters to the authorization
|
||||
** function will be parameters or NULL depending on which of the following
|
||||
** codes is used as the second parameter. The 5th parameter is the name
|
||||
** of the database ("main", "temp", etc.) if applicable. The 6th parameter
|
||||
** is the name of the inner-most trigger or view that is responsible for
|
||||
** the access attempt or NULL if this access attempt is directly from
|
||||
** input SQL code.
|
||||
**
|
||||
** Arg-3 Arg-4
|
||||
*/
|
||||
#define SQLITE_COPY 0 /* Table Name File Name */
|
||||
#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
|
||||
#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
|
||||
#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
|
||||
#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
|
||||
#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
|
||||
#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
|
||||
#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
|
||||
#define SQLITE_CREATE_VIEW 8 /* View Name NULL */
|
||||
#define SQLITE_DELETE 9 /* Table Name NULL */
|
||||
#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
|
||||
#define SQLITE_DROP_TABLE 11 /* Table Name NULL */
|
||||
#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
|
||||
#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
|
||||
#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
|
||||
#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
|
||||
#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
|
||||
#define SQLITE_DROP_VIEW 17 /* View Name NULL */
|
||||
#define SQLITE_INSERT 18 /* Table Name NULL */
|
||||
#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
|
||||
#define SQLITE_READ 20 /* Table Name Column Name */
|
||||
#define SQLITE_SELECT 21 /* NULL NULL */
|
||||
#define SQLITE_TRANSACTION 22 /* NULL NULL */
|
||||
#define SQLITE_UPDATE 23 /* Table Name Column Name */
|
||||
#define SQLITE_ATTACH 24 /* Filename NULL */
|
||||
#define SQLITE_DETACH 25 /* Database Name NULL */
|
||||
|
||||
|
||||
/*
|
||||
** The return value of the authorization function should be one of the
|
||||
** following constants:
|
||||
*/
|
||||
/* #define SQLITE_OK 0 // Allow access (This is actually defined above) */
|
||||
#define SQLITE_DENY 1 /* Abort the SQL statement with an error */
|
||||
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
|
||||
|
||||
/*
|
||||
** Register a function that is called at every invocation of sqlite_exec()
|
||||
** or sqlite_compile(). This function can be used (for example) to generate
|
||||
** a log file of all SQL executed against a database.
|
||||
*/
|
||||
void *sqlite_trace(sqlite*, void(*xTrace)(void*,const char*), void*);
|
||||
|
||||
/*** The Callback-Free API
|
||||
**
|
||||
** The following routines implement a new way to access SQLite that does not
|
||||
** involve the use of callbacks.
|
||||
**
|
||||
** An sqlite_vm is an opaque object that represents a single SQL statement
|
||||
** that is ready to be executed.
|
||||
*/
|
||||
typedef struct sqlite_vm sqlite_vm;
|
||||
|
||||
/*
|
||||
** To execute an SQLite query without the use of callbacks, you first have
|
||||
** to compile the SQL using this routine. The 1st parameter "db" is a pointer
|
||||
** to an sqlite object obtained from sqlite_open(). The 2nd parameter
|
||||
** "zSql" is the text of the SQL to be compiled. The remaining parameters
|
||||
** are all outputs.
|
||||
**
|
||||
** *pzTail is made to point to the first character past the end of the first
|
||||
** SQL statement in zSql. This routine only compiles the first statement
|
||||
** in zSql, so *pzTail is left pointing to what remains uncompiled.
|
||||
**
|
||||
** *ppVm is left pointing to a "virtual machine" that can be used to execute
|
||||
** the compiled statement. Or if there is an error, *ppVm may be set to NULL.
|
||||
** If the input text contained no SQL (if the input is and empty string or
|
||||
** a comment) then *ppVm is set to NULL.
|
||||
**
|
||||
** If any errors are detected during compilation, an error message is written
|
||||
** into space obtained from malloc() and *pzErrMsg is made to point to that
|
||||
** error message. The calling routine is responsible for freeing the text
|
||||
** of this message when it has finished with it. Use sqlite_freemem() to
|
||||
** free the message. pzErrMsg may be NULL in which case no error message
|
||||
** will be generated.
|
||||
**
|
||||
** On success, SQLITE_OK is returned. Otherwise and error code is returned.
|
||||
*/
|
||||
int sqlite_compile(
|
||||
sqlite *db, /* The open database */
|
||||
const char *zSql, /* SQL statement to be compiled */
|
||||
const char **pzTail, /* OUT: uncompiled tail of zSql */
|
||||
sqlite_vm **ppVm, /* OUT: the virtual machine to execute zSql */
|
||||
char **pzErrmsg /* OUT: Error message. */
|
||||
);
|
||||
|
||||
/*
|
||||
** After an SQL statement has been compiled, it is handed to this routine
|
||||
** to be executed. This routine executes the statement as far as it can
|
||||
** go then returns. The return value will be one of SQLITE_DONE,
|
||||
** SQLITE_ERROR, SQLITE_BUSY, SQLITE_ROW, or SQLITE_MISUSE.
|
||||
**
|
||||
** SQLITE_DONE means that the execute of the SQL statement is complete
|
||||
** an no errors have occurred. sqlite_step() should not be called again
|
||||
** for the same virtual machine. *pN is set to the number of columns in
|
||||
** the result set and *pazColName is set to an array of strings that
|
||||
** describe the column names and datatypes. The name of the i-th column
|
||||
** is (*pazColName)[i] and the datatype of the i-th column is
|
||||
** (*pazColName)[i+*pN]. *pazValue is set to NULL.
|
||||
**
|
||||
** SQLITE_ERROR means that the virtual machine encountered a run-time
|
||||
** error. sqlite_step() should not be called again for the same
|
||||
** virtual machine. *pN is set to 0 and *pazColName and *pazValue are set
|
||||
** to NULL. Use sqlite_finalize() to obtain the specific error code
|
||||
** and the error message text for the error.
|
||||
**
|
||||
** SQLITE_BUSY means that an attempt to open the database failed because
|
||||
** another thread or process is holding a lock. The calling routine
|
||||
** can try again to open the database by calling sqlite_step() again.
|
||||
** The return code will only be SQLITE_BUSY if no busy handler is registered
|
||||
** using the sqlite_busy_handler() or sqlite_busy_timeout() routines. If
|
||||
** a busy handler callback has been registered but returns 0, then this
|
||||
** routine will return SQLITE_ERROR and sqltie_finalize() will return
|
||||
** SQLITE_BUSY when it is called.
|
||||
**
|
||||
** SQLITE_ROW means that a single row of the result is now available.
|
||||
** The data is contained in *pazValue. The value of the i-th column is
|
||||
** (*azValue)[i]. *pN and *pazColName are set as described in SQLITE_DONE.
|
||||
** Invoke sqlite_step() again to advance to the next row.
|
||||
**
|
||||
** SQLITE_MISUSE is returned if sqlite_step() is called incorrectly.
|
||||
** For example, if you call sqlite_step() after the virtual machine
|
||||
** has halted (after a prior call to sqlite_step() has returned SQLITE_DONE)
|
||||
** or if you call sqlite_step() with an incorrectly initialized virtual
|
||||
** machine or a virtual machine that has been deleted or that is associated
|
||||
** with an sqlite structure that has been closed.
|
||||
*/
|
||||
int sqlite_step(
|
||||
sqlite_vm *pVm, /* The virtual machine to execute */
|
||||
int *pN, /* OUT: Number of columns in result */
|
||||
const char ***pazValue, /* OUT: Column data */
|
||||
const char ***pazColName /* OUT: Column names and datatypes */
|
||||
);
|
||||
|
||||
/*
|
||||
** This routine is called to delete a virtual machine after it has finished
|
||||
** executing. The return value is the result code. SQLITE_OK is returned
|
||||
** if the statement executed successfully and some other value is returned if
|
||||
** there was any kind of error. If an error occurred and pzErrMsg is not
|
||||
** NULL, then an error message is written into memory obtained from malloc()
|
||||
** and *pzErrMsg is made to point to that error message. The calling routine
|
||||
** should use sqlite_freemem() to delete this message when it has finished
|
||||
** with it.
|
||||
**
|
||||
** This routine can be called at any point during the execution of the
|
||||
** virtual machine. If the virtual machine has not completed execution
|
||||
** when this routine is called, that is like encountering an error or
|
||||
** an interrupt. (See sqlite_interrupt().) Incomplete updates may be
|
||||
** rolled back and transactions cancelled, depending on the circumstances,
|
||||
** and the result code returned will be SQLITE_ABORT.
|
||||
*/
|
||||
int sqlite_finalize(sqlite_vm*, char **pzErrMsg);
|
||||
|
||||
/*
|
||||
** This routine deletes the virtual machine, writes any error message to
|
||||
** *pzErrMsg and returns an SQLite return code in the same way as the
|
||||
** sqlite_finalize() function.
|
||||
**
|
||||
** Additionally, if ppVm is not NULL, *ppVm is left pointing to a new virtual
|
||||
** machine loaded with the compiled version of the original query ready for
|
||||
** execution.
|
||||
**
|
||||
** If sqlite_reset() returns SQLITE_SCHEMA, then *ppVm is set to NULL.
|
||||
**
|
||||
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
|
||||
*/
|
||||
int sqlite_reset(sqlite_vm*, char **pzErrMsg);
|
||||
|
||||
/*
|
||||
** If the SQL that was handed to sqlite_compile contains variables that
|
||||
** are represeted in the SQL text by a question mark ('?'). This routine
|
||||
** is used to assign values to those variables.
|
||||
**
|
||||
** The first parameter is a virtual machine obtained from sqlite_compile().
|
||||
** The 2nd "idx" parameter determines which variable in the SQL statement
|
||||
** to bind the value to. The left most '?' is 1. The 3rd parameter is
|
||||
** the value to assign to that variable. The 4th parameter is the number
|
||||
** of bytes in the value, including the terminating \000 for strings.
|
||||
** Finally, the 5th "copy" parameter is TRUE if SQLite should make its
|
||||
** own private copy of this value, or false if the space that the 3rd
|
||||
** parameter points to will be unchanging and can be used directly by
|
||||
** SQLite.
|
||||
**
|
||||
** Unbound variables are treated as having a value of NULL. To explicitly
|
||||
** set a variable to NULL, call this routine with the 3rd parameter as a
|
||||
** NULL pointer.
|
||||
**
|
||||
** If the 4th "len" parameter is -1, then strlen() is used to find the
|
||||
** length.
|
||||
**
|
||||
** This routine can only be called immediately after sqlite_compile()
|
||||
** or sqlite_reset() and before any calls to sqlite_step().
|
||||
**
|
||||
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
|
||||
*/
|
||||
int sqlite_bind(sqlite_vm*, int idx, const char *value, int len, int copy);
|
||||
|
||||
/*
|
||||
** This routine configures a callback function - the progress callback - that
|
||||
** is invoked periodically during long running calls to sqlite_exec(),
|
||||
** sqlite_step() and sqlite_get_table(). An example use for this API is to keep
|
||||
** a GUI updated during a large query.
|
||||
**
|
||||
** The progress callback is invoked once for every N virtual machine opcodes,
|
||||
** where N is the second argument to this function. The progress callback
|
||||
** itself is identified by the third argument to this function. The fourth
|
||||
** argument to this function is a void pointer passed to the progress callback
|
||||
** function each time it is invoked.
|
||||
**
|
||||
** If a call to sqlite_exec(), sqlite_step() or sqlite_get_table() results
|
||||
** in less than N opcodes being executed, then the progress callback is not
|
||||
** invoked.
|
||||
**
|
||||
** Calling this routine overwrites any previously installed progress callback.
|
||||
** To remove the progress callback altogether, pass NULL as the third
|
||||
** argument to this function.
|
||||
**
|
||||
** If the progress callback returns a result other than 0, then the current
|
||||
** query is immediately terminated and any database changes rolled back. If the
|
||||
** query was part of a larger transaction, then the transaction is not rolled
|
||||
** back and remains active. The sqlite_exec() call returns SQLITE_ABORT.
|
||||
**
|
||||
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
|
||||
*/
|
||||
void sqlite_progress_handler(sqlite*, int, int(*)(void*), void*);
|
||||
|
||||
/*
|
||||
** Register a callback function to be invoked whenever a new transaction
|
||||
** is committed. The pArg argument is passed through to the callback.
|
||||
** callback. If the callback function returns non-zero, then the commit
|
||||
** is converted into a rollback.
|
||||
**
|
||||
** If another function was previously registered, its pArg value is returned.
|
||||
** Otherwise NULL is returned.
|
||||
**
|
||||
** Registering a NULL function disables the callback.
|
||||
**
|
||||
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
|
||||
*/
|
||||
void *sqlite_commit_hook(sqlite*, int(*)(void*), void*);
|
||||
|
||||
/*
|
||||
** Open an encrypted SQLite database. If pKey==0 or nKey==0, this routine
|
||||
** is the same as sqlite_open().
|
||||
**
|
||||
** The code to implement this API is not available in the public release
|
||||
** of SQLite.
|
||||
*/
|
||||
sqlite *sqlite_open_encrypted(
|
||||
const char *zFilename, /* Name of the encrypted database */
|
||||
const void *pKey, /* Pointer to the key */
|
||||
int nKey, /* Number of bytes in the key */
|
||||
int *pErrcode, /* Write error code here */
|
||||
char **pzErrmsg /* Write error message here */
|
||||
);
|
||||
|
||||
/*
|
||||
** Change the key on an open database. If the current database is not
|
||||
** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
|
||||
** database is decrypted.
|
||||
**
|
||||
** The code to implement this API is not available in the public release
|
||||
** of SQLite.
|
||||
*/
|
||||
int sqlite_rekey(
|
||||
sqlite *db, /* Database to be rekeyed */
|
||||
const void *pKey, int nKey /* The new key */
|
||||
);
|
||||
|
||||
/*
|
||||
** Encode a binary buffer "in" of size n bytes so that it contains
|
||||
** no instances of characters '\'' or '\000'. The output is
|
||||
** null-terminated and can be used as a string value in an INSERT
|
||||
** or UPDATE statement. Use sqlite_decode_binary() to convert the
|
||||
** string back into its original binary.
|
||||
**
|
||||
** The result is written into a preallocated output buffer "out".
|
||||
** "out" must be able to hold at least 2 +(257*n)/254 bytes.
|
||||
** In other words, the output will be expanded by as much as 3
|
||||
** bytes for every 254 bytes of input plus 2 bytes of fixed overhead.
|
||||
** (This is approximately 2 + 1.0118*n or about a 1.2% size increase.)
|
||||
**
|
||||
** The return value is the number of characters in the encoded
|
||||
** string, excluding the "\000" terminator.
|
||||
**
|
||||
** If out==NULL then no output is generated but the routine still returns
|
||||
** the number of characters that would have been generated if out had
|
||||
** not been NULL.
|
||||
*/
|
||||
int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out);
|
||||
|
||||
/*
|
||||
** 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* End of the 'extern "C"' block */
|
||||
|
||||
+929
-128
File diff suppressed because it is too large
Load Diff
+51
-21
@@ -17,7 +17,8 @@
|
||||
** if they are not used.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include "sqlite.h"
|
||||
#include <string.h>
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This structure is used to pass data from sqlite_get_table() through
|
||||
@@ -25,11 +26,12 @@
|
||||
*/
|
||||
typedef struct TabResult {
|
||||
char **azResult;
|
||||
char *zErrMsg;
|
||||
int nResult;
|
||||
int nAlloc;
|
||||
int nRow;
|
||||
int nColumn;
|
||||
int nData;
|
||||
long nData;
|
||||
int rc;
|
||||
} TabResult;
|
||||
|
||||
@@ -47,25 +49,27 @@ static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
/* Make sure there is enough space in p->azResult to hold everything
|
||||
** we need to remember from this invocation of the callback.
|
||||
*/
|
||||
if( p->nRow==0 ){
|
||||
p->nColumn = nCol;
|
||||
if( p->nRow==0 && argv!=0 ){
|
||||
need = nCol*2;
|
||||
}else{
|
||||
need = nCol;
|
||||
}
|
||||
if( p->nData + need >= p->nAlloc ){
|
||||
char **azNew;
|
||||
p->nAlloc = p->nAlloc*2 + need + 1;
|
||||
p->azResult = realloc( p->azResult, sizeof(char*)*p->nAlloc );
|
||||
if( p->azResult==0 ){
|
||||
azNew = realloc( p->azResult, sizeof(char*)*p->nAlloc );
|
||||
if( azNew==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
p->azResult = azNew;
|
||||
}
|
||||
|
||||
/* If this is the first row, then generate an extra row containing
|
||||
** the names of all columns.
|
||||
*/
|
||||
if( p->nRow==0 ){
|
||||
p->nColumn = nCol;
|
||||
for(i=0; i<nCol; i++){
|
||||
if( colv[i]==0 ){
|
||||
z = 0;
|
||||
@@ -79,24 +83,32 @@ static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
}
|
||||
p->azResult[p->nData++] = z;
|
||||
}
|
||||
}else if( p->nColumn!=nCol ){
|
||||
sqliteSetString(&p->zErrMsg,
|
||||
"sqlite_get_table() called with two or more incompatible queries",
|
||||
(char*)0);
|
||||
p->rc = SQLITE_ERROR;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Copy over the row data
|
||||
*/
|
||||
for(i=0; i<nCol; i++){
|
||||
if( argv[i]==0 ){
|
||||
z = 0;
|
||||
}else{
|
||||
z = malloc( strlen(argv[i])+1 );
|
||||
if( z==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
if( argv!=0 ){
|
||||
for(i=0; i<nCol; i++){
|
||||
if( argv[i]==0 ){
|
||||
z = 0;
|
||||
}else{
|
||||
z = malloc( strlen(argv[i])+1 );
|
||||
if( z==0 ){
|
||||
p->rc = SQLITE_NOMEM;
|
||||
return 1;
|
||||
}
|
||||
strcpy(z, argv[i]);
|
||||
}
|
||||
strcpy(z, argv[i]);
|
||||
p->azResult[p->nData++] = z;
|
||||
}
|
||||
p->azResult[p->nData++] = z;
|
||||
p->nRow++;
|
||||
}
|
||||
p->nRow++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -112,7 +124,7 @@ static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
|
||||
*/
|
||||
int sqlite_get_table(
|
||||
sqlite *db, /* The database on which the SQL executes */
|
||||
char *zSql, /* The SQL to be executed */
|
||||
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 */
|
||||
int *pnColumn, /* Write the number of columns of result here */
|
||||
@@ -124,6 +136,7 @@ int sqlite_get_table(
|
||||
*pazResult = 0;
|
||||
if( pnColumn ) *pnColumn = 0;
|
||||
if( pnRow ) *pnRow = 0;
|
||||
res.zErrMsg = 0;
|
||||
res.nResult = 0;
|
||||
res.nRow = 0;
|
||||
res.nColumn = 0;
|
||||
@@ -141,15 +154,31 @@ int sqlite_get_table(
|
||||
}
|
||||
if( rc==SQLITE_ABORT ){
|
||||
sqlite_free_table(&res.azResult[1]);
|
||||
if( res.zErrMsg ){
|
||||
if( pzErrMsg ){
|
||||
free(*pzErrMsg);
|
||||
*pzErrMsg = res.zErrMsg;
|
||||
sqliteStrRealloc(pzErrMsg);
|
||||
}else{
|
||||
sqliteFree(res.zErrMsg);
|
||||
}
|
||||
}
|
||||
return res.rc;
|
||||
}
|
||||
sqliteFree(res.zErrMsg);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite_free_table(&res.azResult[1]);
|
||||
return rc;
|
||||
}
|
||||
if( res.nAlloc>res.nData ){
|
||||
res.azResult = realloc( res.azResult, sizeof(char*)*(res.nData+1) );
|
||||
if( res.azResult==0 ) return SQLITE_NOMEM;
|
||||
char **azNew;
|
||||
azNew = realloc( res.azResult, sizeof(char*)*(res.nData+1) );
|
||||
if( azNew==0 ){
|
||||
sqlite_free_table(&res.azResult[1]);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
res.nAlloc = res.nData+1;
|
||||
res.azResult = azNew;
|
||||
}
|
||||
*pazResult = &res.azResult[1];
|
||||
if( pnColumn ) *pnColumn = res.nColumn;
|
||||
@@ -166,7 +195,8 @@ void sqlite_free_table(
|
||||
if( azResult ){
|
||||
int i, n;
|
||||
azResult--;
|
||||
n = (int)azResult[0];
|
||||
if( azResult==0 ) return;
|
||||
n = (int)(long)azResult[0];
|
||||
for(i=1; i<n; i++){ if( azResult[i] ) free(azResult[i]); }
|
||||
free(azResult);
|
||||
}
|
||||
|
||||
+838
-95
File diff suppressed because it is too large
Load Diff
+729
-21
@@ -13,13 +13,74 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test1.c,v 1.4 2001/09/24 03:12:40 drh Exp $
|
||||
** $Id: test1.c,v 1.36.2.1 2004/05/07 00:57:06 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
#include "os.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if OS_WIN
|
||||
# define PTR_FMT "%x"
|
||||
#else
|
||||
# define PTR_FMT "%p"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Decode a pointer to an sqlite object.
|
||||
*/
|
||||
static int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite **ppDb){
|
||||
if( sscanf(zA, PTR_FMT, (void**)ppDb)!=1 &&
|
||||
(zA[0]!='0' || zA[1]!='x' || sscanf(&zA[2], PTR_FMT, (void**)ppDb)!=1)
|
||||
){
|
||||
Tcl_AppendResult(interp, "\"", zA, "\" is not a valid pointer value", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Decode a pointer to an sqlite_vm object.
|
||||
*/
|
||||
static int getVmPointer(Tcl_Interp *interp, const char *zArg, sqlite_vm **ppVm){
|
||||
if( sscanf(zArg, PTR_FMT, (void**)ppVm)!=1 ){
|
||||
Tcl_AppendResult(interp, "\"", zArg, "\" is not a valid pointer value", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate a text representation of a pointer that can be understood
|
||||
** by the getDbPointer and getVmPointer routines above.
|
||||
**
|
||||
** The problem is, on some machines (Solaris) if you do a printf with
|
||||
** "%p" you cannot turn around and do a scanf with the same "%p" and
|
||||
** get your pointer back. You have to prepend a "0x" before it will
|
||||
** work. Or at least that is what is reported to me (drh). But this
|
||||
** behavior varies from machine to machine. The solution used her is
|
||||
** to test the string right after it is generated to see if it can be
|
||||
** understood by scanf, and if not, try prepending an "0x" to see if
|
||||
** that helps. If nothing works, a fatal error is generated.
|
||||
*/
|
||||
static int makePointerStr(Tcl_Interp *interp, char *zPtr, void *p){
|
||||
void *p2;
|
||||
sprintf(zPtr, PTR_FMT, p);
|
||||
if( sscanf(zPtr, PTR_FMT, &p2)!=1 || p2!=p ){
|
||||
sprintf(zPtr, "0x" PTR_FMT, p);
|
||||
if( sscanf(zPtr, PTR_FMT, &p2)!=1 || p2!=p ){
|
||||
Tcl_AppendResult(interp, "unable to convert a pointer to a string "
|
||||
"in the file " __FILE__ " in function makePointerStr(). Please "
|
||||
"report this problem to the SQLite mailing list or as a new but "
|
||||
"report. Please provide detailed information about how you compiled "
|
||||
"SQLite and what computer you are running on.", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_open filename
|
||||
**
|
||||
@@ -45,7 +106,7 @@ static int sqlite_test_open(
|
||||
free(zErr);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",(int)db);
|
||||
if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR;
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -91,7 +152,7 @@ static int test_exec_printf(
|
||||
" DB FORMAT STRING", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
db = (sqlite*)atoi(argv[1]);
|
||||
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
||||
Tcl_DStringInit(&str);
|
||||
rc = sqlite_exec_printf(db, argv[2], exec_printf_cb, &str, &zErr, argv[3]);
|
||||
sprintf(zBuf, "%d", rc);
|
||||
@@ -102,6 +163,30 @@ static int test_exec_printf(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_mprintf_z_test SEPARATOR ARG0 ARG1 ...
|
||||
**
|
||||
** Test the %z format of mprintf(). Use multiple mprintf() calls to
|
||||
** concatenate arg0 through argn using separator as the separator.
|
||||
** Return the result.
|
||||
*/
|
||||
static int test_mprintf_z(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
char *zResult = 0;
|
||||
int i;
|
||||
|
||||
for(i=2; i<argc; i++){
|
||||
zResult = sqliteMPrintf("%z%s%s", zResult, argv[1], argv[i]);
|
||||
}
|
||||
Tcl_AppendResult(interp, zResult, 0);
|
||||
sqliteFree(zResult);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_get_table_printf DB FORMAT STRING
|
||||
**
|
||||
@@ -128,7 +213,7 @@ static int test_get_table_printf(
|
||||
" DB FORMAT STRING", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
db = (sqlite*)atoi(argv[1]);
|
||||
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
||||
Tcl_DStringInit(&str);
|
||||
rc = sqlite_get_table_printf(db, argv[2], &aResult, &nRow, &nCol,
|
||||
&zErr, argv[3]);
|
||||
@@ -150,6 +235,31 @@ static int test_get_table_printf(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Usage: sqlite_last_insert_rowid DB
|
||||
**
|
||||
** Returns the integer ROWID of the most recent insert.
|
||||
*/
|
||||
static int test_last_rowid(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
sqlite *db;
|
||||
char zBuf[30];
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
||||
sprintf(zBuf, "%d", sqlite_last_insert_rowid(db));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_close DB
|
||||
**
|
||||
@@ -167,11 +277,178 @@ static int sqlite_test_close(
|
||||
" FILENAME\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
db = (sqlite*)atoi(argv[1]);
|
||||
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
||||
sqlite_close(db);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the x_coalesce() function.
|
||||
** Return the first argument non-NULL argument.
|
||||
*/
|
||||
static void ifnullFunc(sqlite_func *context, int argc, const char **argv){
|
||||
int i;
|
||||
for(i=0; i<argc; i++){
|
||||
if( argv[i] ){
|
||||
sqlite_set_result_string(context, argv[i], -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** A structure into which to accumulate text.
|
||||
*/
|
||||
struct dstr {
|
||||
int nAlloc; /* Space allocated */
|
||||
int nUsed; /* Space used */
|
||||
char *z; /* The space */
|
||||
};
|
||||
|
||||
/*
|
||||
** Append text to a dstr
|
||||
*/
|
||||
static void dstrAppend(struct dstr *p, const char *z, int divider){
|
||||
int n = strlen(z);
|
||||
if( p->nUsed + n + 2 > p->nAlloc ){
|
||||
char *zNew;
|
||||
p->nAlloc = p->nAlloc*2 + n + 200;
|
||||
zNew = sqliteRealloc(p->z, p->nAlloc);
|
||||
if( zNew==0 ){
|
||||
sqliteFree(p->z);
|
||||
memset(p, 0, sizeof(*p));
|
||||
return;
|
||||
}
|
||||
p->z = zNew;
|
||||
}
|
||||
if( divider && p->nUsed>0 ){
|
||||
p->z[p->nUsed++] = divider;
|
||||
}
|
||||
memcpy(&p->z[p->nUsed], z, n+1);
|
||||
p->nUsed += n;
|
||||
}
|
||||
|
||||
/*
|
||||
** Invoked for each callback from sqliteExecFunc
|
||||
*/
|
||||
static int execFuncCallback(void *pData, int argc, char **argv, char **NotUsed){
|
||||
struct dstr *p = (struct dstr*)pData;
|
||||
int i;
|
||||
for(i=0; i<argc; i++){
|
||||
if( argv[i]==0 ){
|
||||
dstrAppend(p, "NULL", ' ');
|
||||
}else{
|
||||
dstrAppend(p, argv[i], ' ');
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the x_sqlite_exec() function. This function takes
|
||||
** a single argument and attempts to execute that argument as SQL code.
|
||||
** This is illegal and should set the SQLITE_MISUSE flag on the database.
|
||||
**
|
||||
** 2004-Jan-07: We have changed this to make it legal to call sqlite_exec()
|
||||
** from within a function call.
|
||||
**
|
||||
** This routine simulates the effect of having two threads attempt to
|
||||
** use the same database at the same time.
|
||||
*/
|
||||
static void sqliteExecFunc(sqlite_func *context, int argc, const char **argv){
|
||||
struct dstr x;
|
||||
memset(&x, 0, sizeof(x));
|
||||
sqlite_exec((sqlite*)sqlite_user_data(context), argv[0],
|
||||
execFuncCallback, &x, 0);
|
||||
sqlite_set_result_string(context, x.z, x.nUsed);
|
||||
sqliteFree(x.z);
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_test_create_function DB
|
||||
**
|
||||
** Call the sqlite_create_function API on the given database in order
|
||||
** to create a function named "x_coalesce". This function does the same thing
|
||||
** as the "coalesce" function. This function also registers an SQL function
|
||||
** named "x_sqlite_exec" that invokes sqlite_exec(). Invoking sqlite_exec()
|
||||
** in this way is illegal recursion and should raise an SQLITE_MISUSE error.
|
||||
** The effect is similar to trying to use the same database connection from
|
||||
** two threads at the same time.
|
||||
**
|
||||
** The original motivation for this routine was to be able to call the
|
||||
** sqlite_create_function function while a query is in progress in order
|
||||
** to test the SQLITE_MISUSE detection logic.
|
||||
*/
|
||||
static int test_create_function(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
sqlite *db;
|
||||
extern void Md5_Register(sqlite*);
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" FILENAME\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
||||
sqlite_create_function(db, "x_coalesce", -1, ifnullFunc, 0);
|
||||
sqlite_create_function(db, "x_sqlite_exec", 1, sqliteExecFunc, db);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Routines to implement the x_count() aggregate function.
|
||||
*/
|
||||
typedef struct CountCtx CountCtx;
|
||||
struct CountCtx {
|
||||
int n;
|
||||
};
|
||||
static void countStep(sqlite_func *context, int argc, const char **argv){
|
||||
CountCtx *p;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
if( (argc==0 || argv[0]) && p ){
|
||||
p->n++;
|
||||
}
|
||||
}
|
||||
static void countFinalize(sqlite_func *context){
|
||||
CountCtx *p;
|
||||
p = sqlite_aggregate_context(context, sizeof(*p));
|
||||
sqlite_set_result_int(context, p ? p->n : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_test_create_aggregate DB
|
||||
**
|
||||
** Call the sqlite_create_function API on the given database in order
|
||||
** to create a function named "x_count". This function does the same thing
|
||||
** as the "md5sum" function.
|
||||
**
|
||||
** The original motivation for this routine was to be able to call the
|
||||
** sqlite_create_aggregate function while a query is in progress in order
|
||||
** to test the SQLITE_MISUSE detection logic.
|
||||
*/
|
||||
static int test_create_aggregate(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
sqlite *db;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" FILENAME\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
||||
sqlite_create_aggregate(db, "x_count", 0, countStep, countFinalize, 0);
|
||||
sqlite_create_aggregate(db, "x_count", 1, countStep, countFinalize, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Usage: sqlite_mprintf_int FORMAT INTEGER INTEGER INTEGER
|
||||
**
|
||||
@@ -195,7 +472,7 @@ static int sqlite_mprintf_int(
|
||||
}
|
||||
z = sqlite_mprintf(argv[1], a[0], a[1], a[2]);
|
||||
Tcl_AppendResult(interp, z, 0);
|
||||
sqliteFree(z);
|
||||
sqlite_freemem(z);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -212,17 +489,17 @@ static int sqlite_mprintf_str(
|
||||
){
|
||||
int a[3], i;
|
||||
char *z;
|
||||
if( argc!=5 ){
|
||||
if( argc<4 || argc>5 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" FORMAT INT INT STRING\"", 0);
|
||||
" FORMAT INT INT ?STRING?\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
for(i=2; i<4; i++){
|
||||
if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR;
|
||||
}
|
||||
z = sqlite_mprintf(argv[1], a[0], a[1], argv[4]);
|
||||
z = sqlite_mprintf(argv[1], a[0], a[1], argc>4 ? argv[4] : NULL);
|
||||
Tcl_AppendResult(interp, z, 0);
|
||||
sqliteFree(z);
|
||||
sqlite_freemem(z);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -251,7 +528,37 @@ static int sqlite_mprintf_double(
|
||||
if( Tcl_GetDouble(interp, argv[4], &r) ) return TCL_ERROR;
|
||||
z = sqlite_mprintf(argv[1], a[0], a[1], r);
|
||||
Tcl_AppendResult(interp, z, 0);
|
||||
sqliteFree(z);
|
||||
sqlite_freemem(z);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_mprintf_str FORMAT DOUBLE DOUBLE
|
||||
**
|
||||
** Call mprintf with a single double argument which is the product of the
|
||||
** two arguments given above. This is used to generate overflow and underflow
|
||||
** doubles to test that they are converted properly.
|
||||
*/
|
||||
static int sqlite_mprintf_scaled(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
int i;
|
||||
double r[2];
|
||||
char *z;
|
||||
if( argc!=4 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" FORMAT DOUBLE DOUBLE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
for(i=2; i<4; i++){
|
||||
if( Tcl_GetDouble(interp, argv[i], &r[i-2]) ) return TCL_ERROR;
|
||||
}
|
||||
z = sqlite_mprintf(argv[1], r[0]*r[1]);
|
||||
Tcl_AppendResult(interp, z, 0);
|
||||
sqlite_freemem(z);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -299,21 +606,422 @@ static int sqlite_malloc_stat(
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Usage: sqlite_abort
|
||||
**
|
||||
** Shutdown the process immediately. This is not a clean shutdown.
|
||||
** This command is used to test the recoverability of a database in
|
||||
** the event of a program crash.
|
||||
*/
|
||||
static int sqlite_abort(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
assert( interp==0 ); /* This will always fail */
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following routine is a user-defined SQL function whose purpose
|
||||
** is to test the sqlite_set_result() API.
|
||||
*/
|
||||
static void testFunc(sqlite_func *context, int argc, const char **argv){
|
||||
while( argc>=2 ){
|
||||
if( argv[0]==0 ){
|
||||
sqlite_set_result_error(context, "first argument to test function "
|
||||
"may not be NULL", -1);
|
||||
}else if( sqliteStrICmp(argv[0],"string")==0 ){
|
||||
sqlite_set_result_string(context, argv[1], -1);
|
||||
}else if( argv[1]==0 ){
|
||||
sqlite_set_result_error(context, "2nd argument may not be NULL if the "
|
||||
"first argument is not \"string\"", -1);
|
||||
}else if( sqliteStrICmp(argv[0],"int")==0 ){
|
||||
sqlite_set_result_int(context, atoi(argv[1]));
|
||||
}else if( sqliteStrICmp(argv[0],"double")==0 ){
|
||||
sqlite_set_result_double(context, sqliteAtoF(argv[1], 0));
|
||||
}else{
|
||||
sqlite_set_result_error(context,"first argument should be one of: "
|
||||
"string int double", -1);
|
||||
}
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_register_test_function DB NAME
|
||||
**
|
||||
** Register the test SQL function on the database DB under the name NAME.
|
||||
*/
|
||||
static int test_register_func(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
sqlite *db;
|
||||
int rc;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" DB FUNCTION-NAME", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
||||
rc = sqlite_create_function(db, argv[2], -1, testFunc, 0);
|
||||
if( rc!=0 ){
|
||||
Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This SQLite callback records the datatype of all columns.
|
||||
**
|
||||
** The pArg argument is really a pointer to a TCL interpreter. The
|
||||
** column names are inserted as the result of this interpreter.
|
||||
**
|
||||
** This routine returns non-zero which causes the query to abort.
|
||||
*/
|
||||
static int rememberDataTypes(void *pArg, int nCol, char **argv, char **colv){
|
||||
int i;
|
||||
Tcl_Interp *interp = (Tcl_Interp*)pArg;
|
||||
Tcl_Obj *pList, *pElem;
|
||||
if( colv[nCol+1]==0 ){
|
||||
return 1;
|
||||
}
|
||||
pList = Tcl_NewObj();
|
||||
for(i=0; i<nCol; i++){
|
||||
pElem = Tcl_NewStringObj(colv[i+nCol] ? colv[i+nCol] : "NULL", -1);
|
||||
Tcl_ListObjAppendElement(interp, pList, pElem);
|
||||
}
|
||||
Tcl_SetObjResult(interp, pList);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Invoke an SQL statement but ignore all the data in the result. Instead,
|
||||
** return a list that consists of the datatypes of the various columns.
|
||||
**
|
||||
** This only works if "PRAGMA show_datatypes=on" has been executed against
|
||||
** the database connection.
|
||||
*/
|
||||
static int sqlite_datatypes(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
sqlite *db;
|
||||
int rc;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" DB SQL", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
||||
rc = sqlite_exec(db, argv[2], rememberDataTypes, interp, 0);
|
||||
if( rc!=0 && rc!=SQLITE_ABORT ){
|
||||
Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_compile DB SQL ?TAILVAR?
|
||||
**
|
||||
** Attempt to compile an SQL statement. Return a pointer to the virtual
|
||||
** machine used to execute that statement. Unprocessed SQL is written
|
||||
** into TAILVAR.
|
||||
*/
|
||||
static int test_compile(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
sqlite *db;
|
||||
sqlite_vm *vm;
|
||||
int rc;
|
||||
char *zErr = 0;
|
||||
const char *zTail;
|
||||
char zBuf[50];
|
||||
if( argc!=3 && argc!=4 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" DB SQL TAILVAR", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
||||
rc = sqlite_compile(db, argv[2], argc==4 ? &zTail : 0, &vm, &zErr);
|
||||
if( argc==4 ) Tcl_SetVar(interp, argv[3], zTail, 0);
|
||||
if( rc ){
|
||||
assert( vm==0 );
|
||||
sprintf(zBuf, "(%d) ", rc);
|
||||
Tcl_AppendResult(interp, zBuf, zErr, 0);
|
||||
sqlite_freemem(zErr);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( vm ){
|
||||
if( makePointerStr(interp, zBuf, vm) ) return TCL_ERROR;
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_step VM ?NVAR? ?VALUEVAR? ?COLNAMEVAR?
|
||||
**
|
||||
** Step a virtual machine. Return a the result code as a string.
|
||||
** Column results are written into three variables.
|
||||
*/
|
||||
static int test_step(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
sqlite_vm *vm;
|
||||
int rc, i;
|
||||
const char **azValue = 0;
|
||||
const char **azColName = 0;
|
||||
int N = 0;
|
||||
char *zRc;
|
||||
char zBuf[50];
|
||||
if( argc<2 || argc>5 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" VM NVAR VALUEVAR COLNAMEVAR", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getVmPointer(interp, argv[1], &vm) ) return TCL_ERROR;
|
||||
rc = sqlite_step(vm, argc>=3?&N:0, argc>=4?&azValue:0, argc==5?&azColName:0);
|
||||
if( argc>=3 ){
|
||||
sprintf(zBuf, "%d", N);
|
||||
Tcl_SetVar(interp, argv[2], zBuf, 0);
|
||||
}
|
||||
if( argc>=4 ){
|
||||
Tcl_SetVar(interp, argv[3], "", 0);
|
||||
if( azValue ){
|
||||
for(i=0; i<N; i++){
|
||||
Tcl_SetVar(interp, argv[3], azValue[i] ? azValue[i] : "",
|
||||
TCL_APPEND_VALUE | TCL_LIST_ELEMENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
if( argc==5 ){
|
||||
Tcl_SetVar(interp, argv[4], "", 0);
|
||||
if( azColName ){
|
||||
for(i=0; i<N*2; i++){
|
||||
Tcl_SetVar(interp, argv[4], azColName[i] ? azColName[i] : "",
|
||||
TCL_APPEND_VALUE | TCL_LIST_ELEMENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
switch( rc ){
|
||||
case SQLITE_DONE: zRc = "SQLITE_DONE"; break;
|
||||
case SQLITE_BUSY: zRc = "SQLITE_BUSY"; break;
|
||||
case SQLITE_ROW: zRc = "SQLITE_ROW"; break;
|
||||
case SQLITE_ERROR: zRc = "SQLITE_ERROR"; break;
|
||||
case SQLITE_MISUSE: zRc = "SQLITE_MISUSE"; break;
|
||||
default: zRc = "unknown"; break;
|
||||
}
|
||||
Tcl_AppendResult(interp, zRc, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_finalize VM
|
||||
**
|
||||
** Shutdown a virtual machine.
|
||||
*/
|
||||
static int test_finalize(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
sqlite_vm *vm;
|
||||
int rc;
|
||||
char *zErrMsg = 0;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" VM\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getVmPointer(interp, argv[1], &vm) ) return TCL_ERROR;
|
||||
rc = sqlite_finalize(vm, &zErrMsg);
|
||||
if( rc ){
|
||||
char zBuf[50];
|
||||
sprintf(zBuf, "(%d) ", rc);
|
||||
Tcl_AppendResult(interp, zBuf, zErrMsg, 0);
|
||||
sqlite_freemem(zErrMsg);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite_reset VM
|
||||
**
|
||||
** Reset a virtual machine and prepare it to be run again.
|
||||
*/
|
||||
static int test_reset(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
sqlite_vm *vm;
|
||||
int rc;
|
||||
char *zErrMsg = 0;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" VM\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getVmPointer(interp, argv[1], &vm) ) return TCL_ERROR;
|
||||
rc = sqlite_reset(vm, &zErrMsg);
|
||||
if( rc ){
|
||||
char zBuf[50];
|
||||
sprintf(zBuf, "(%d) ", rc);
|
||||
Tcl_AppendResult(interp, zBuf, zErrMsg, 0);
|
||||
sqlite_freemem(zErrMsg);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is the "static_bind_value" that variables are bound to when
|
||||
** the FLAG option of sqlite_bind is "static"
|
||||
*/
|
||||
static char *sqlite_static_bind_value = 0;
|
||||
|
||||
/*
|
||||
** Usage: sqlite_bind VM IDX VALUE FLAGS
|
||||
**
|
||||
** Sets the value of the IDX-th occurance of "?" in the original SQL
|
||||
** string. VALUE is the new value. If FLAGS=="null" then VALUE is
|
||||
** ignored and the value is set to NULL. If FLAGS=="static" then
|
||||
** the value is set to the value of a static variable named
|
||||
** "sqlite_static_bind_value". If FLAGS=="normal" then a copy
|
||||
** of the VALUE is made.
|
||||
*/
|
||||
static int test_bind(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
sqlite_vm *vm;
|
||||
int rc;
|
||||
int idx;
|
||||
if( argc!=5 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" VM IDX VALUE (null|static|normal)\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getVmPointer(interp, argv[1], &vm) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &idx) ) return TCL_ERROR;
|
||||
if( strcmp(argv[4],"null")==0 ){
|
||||
rc = sqlite_bind(vm, idx, 0, 0, 0);
|
||||
}else if( strcmp(argv[4],"static")==0 ){
|
||||
rc = sqlite_bind(vm, idx, sqlite_static_bind_value, -1, 0);
|
||||
}else if( strcmp(argv[4],"normal")==0 ){
|
||||
rc = sqlite_bind(vm, idx, argv[3], -1, 1);
|
||||
}else{
|
||||
Tcl_AppendResult(interp, "4th argument should be "
|
||||
"\"null\" or \"static\" or \"normal\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( rc ){
|
||||
char zBuf[50];
|
||||
sprintf(zBuf, "(%d) ", rc);
|
||||
Tcl_AppendResult(interp, zBuf, sqlite_error_string(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: breakpoint
|
||||
**
|
||||
** This routine exists for one purpose - to provide a place to put a
|
||||
** breakpoint with GDB that can be triggered using TCL code. The use
|
||||
** for this is when a particular test fails on (say) the 1485th iteration.
|
||||
** In the TCL test script, we can add code like this:
|
||||
**
|
||||
** if {$i==1485} breakpoint
|
||||
**
|
||||
** Then run testfixture in the debugger and wait for the breakpoint to
|
||||
** fire. Then additional breakpoints can be set to trace down the bug.
|
||||
*/
|
||||
static int test_breakpoint(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
return TCL_OK; /* Do nothing */
|
||||
}
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
Tcl_CreateCommand(interp, "sqlite_mprintf_int", sqlite_mprintf_int, 0, 0);
|
||||
Tcl_CreateCommand(interp, "sqlite_mprintf_str", sqlite_mprintf_str, 0, 0);
|
||||
Tcl_CreateCommand(interp, "sqlite_mprintf_double", sqlite_mprintf_double,0,0);
|
||||
Tcl_CreateCommand(interp, "sqlite_open", sqlite_test_open, 0, 0);
|
||||
Tcl_CreateCommand(interp, "sqlite_exec_printf", test_exec_printf, 0, 0);
|
||||
Tcl_CreateCommand(interp, "sqlite_get_table_printf", test_get_table_printf,
|
||||
0, 0);
|
||||
Tcl_CreateCommand(interp, "sqlite_close", sqlite_test_close, 0, 0);
|
||||
extern int sqlite_search_count;
|
||||
extern int sqlite_interrupt_count;
|
||||
extern int sqlite_open_file_count;
|
||||
extern int sqlite_current_time;
|
||||
extern int sqlite_temp_directory;
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_CmdProc *xProc;
|
||||
} aCmd[] = {
|
||||
{ "sqlite_mprintf_int", (Tcl_CmdProc*)sqlite_mprintf_int },
|
||||
{ "sqlite_mprintf_str", (Tcl_CmdProc*)sqlite_mprintf_str },
|
||||
{ "sqlite_mprintf_double", (Tcl_CmdProc*)sqlite_mprintf_double },
|
||||
{ "sqlite_mprintf_scaled", (Tcl_CmdProc*)sqlite_mprintf_scaled },
|
||||
{ "sqlite_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z },
|
||||
{ "sqlite_open", (Tcl_CmdProc*)sqlite_test_open },
|
||||
{ "sqlite_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid },
|
||||
{ "sqlite_exec_printf", (Tcl_CmdProc*)test_exec_printf },
|
||||
{ "sqlite_get_table_printf", (Tcl_CmdProc*)test_get_table_printf },
|
||||
{ "sqlite_close", (Tcl_CmdProc*)sqlite_test_close },
|
||||
{ "sqlite_create_function", (Tcl_CmdProc*)test_create_function },
|
||||
{ "sqlite_create_aggregate", (Tcl_CmdProc*)test_create_aggregate },
|
||||
{ "sqlite_register_test_function", (Tcl_CmdProc*)test_register_func },
|
||||
{ "sqlite_abort", (Tcl_CmdProc*)sqlite_abort },
|
||||
{ "sqlite_datatypes", (Tcl_CmdProc*)sqlite_datatypes },
|
||||
#ifdef MEMORY_DEBUG
|
||||
Tcl_CreateCommand(interp, "sqlite_malloc_fail", sqlite_malloc_fail, 0, 0);
|
||||
Tcl_CreateCommand(interp, "sqlite_malloc_stat", sqlite_malloc_stat, 0, 0);
|
||||
{ "sqlite_malloc_fail", (Tcl_CmdProc*)sqlite_malloc_fail },
|
||||
{ "sqlite_malloc_stat", (Tcl_CmdProc*)sqlite_malloc_stat },
|
||||
#endif
|
||||
{ "sqlite_compile", (Tcl_CmdProc*)test_compile },
|
||||
{ "sqlite_step", (Tcl_CmdProc*)test_step },
|
||||
{ "sqlite_finalize", (Tcl_CmdProc*)test_finalize },
|
||||
{ "sqlite_bind", (Tcl_CmdProc*)test_bind },
|
||||
{ "sqlite_reset", (Tcl_CmdProc*)test_reset },
|
||||
{ "breakpoint", (Tcl_CmdProc*)test_breakpoint },
|
||||
};
|
||||
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_search_count",
|
||||
(char*)&sqlite_search_count, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_interrupt_count",
|
||||
(char*)&sqlite_interrupt_count, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_open_file_count",
|
||||
(char*)&sqlite_open_file_count, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_current_time",
|
||||
(char*)&sqlite_current_time, TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "sqlite_static_bind_value",
|
||||
(char*)&sqlite_static_bind_value, TCL_LINK_STRING);
|
||||
Tcl_LinkVar(interp, "sqlite_temp_directory",
|
||||
(char*)&sqlite_temp_directory, TCL_LINK_STRING);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
+191
-28
@@ -13,8 +13,9 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test2.c,v 1.5 2001/09/16 00:13:27 drh Exp $
|
||||
** $Id: test2.c,v 1.16 2004/02/10 01:54:28 drh Exp $
|
||||
*/
|
||||
#include "os.h"
|
||||
#include "sqliteInt.h"
|
||||
#include "pager.h"
|
||||
#include "tcl.h"
|
||||
@@ -42,6 +43,13 @@ static char *errorName(int rc){
|
||||
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;
|
||||
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
|
||||
default: zName = "SQLITE_Unknown"; break;
|
||||
}
|
||||
return zName;
|
||||
@@ -56,7 +64,7 @@ static int pager_open(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int nPage;
|
||||
@@ -68,7 +76,7 @@ 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);
|
||||
rc = sqlitepager_open(&pPager, argv[1], nPage, 0, 1);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
@@ -87,7 +95,7 @@ static int pager_close(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int rc;
|
||||
@@ -114,7 +122,7 @@ static int pager_rollback(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int rc;
|
||||
@@ -141,7 +149,7 @@ static int pager_commit(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int rc;
|
||||
@@ -159,6 +167,87 @@ static int pager_commit(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_ckpt_begin ID
|
||||
**
|
||||
** Start a new checkpoint.
|
||||
*/
|
||||
static int pager_ckpt_begin(
|
||||
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;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_ckpt_begin(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_ckpt_rollback ID
|
||||
**
|
||||
** Rollback changes to a checkpoint
|
||||
*/
|
||||
static int pager_ckpt_rollback(
|
||||
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;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_ckpt_rollback(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_ckpt_commit ID
|
||||
**
|
||||
** Commit changes to a checkpoint
|
||||
*/
|
||||
static int pager_ckpt_commit(
|
||||
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;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_ckpt_commit(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_stats ID
|
||||
**
|
||||
@@ -168,7 +257,7 @@ static int pager_stats(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int i, *a;
|
||||
@@ -201,7 +290,7 @@ static int pager_pagecount(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
char zBuf[100];
|
||||
@@ -225,7 +314,7 @@ static int page_get(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
char zBuf[100];
|
||||
@@ -259,7 +348,7 @@ static int page_lookup(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
char zBuf[100];
|
||||
@@ -289,7 +378,7 @@ static int page_unref(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
void *pPage;
|
||||
int rc;
|
||||
@@ -316,7 +405,7 @@ static int page_read(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
char zBuf[100];
|
||||
void *pPage;
|
||||
@@ -340,7 +429,7 @@ static int page_number(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
char zBuf[100];
|
||||
void *pPage;
|
||||
@@ -364,7 +453,7 @@ static int page_write(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
void *pPage;
|
||||
int rc;
|
||||
@@ -379,8 +468,55 @@ static int page_write(
|
||||
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], SQLITE_USABLE_SIZE-1);
|
||||
((char*)pPage)[SQLITE_USABLE_SIZE-1] = 0;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: fake_big_file N FILENAME
|
||||
**
|
||||
** Write a few bytes at the N megabyte point of FILENAME. This will
|
||||
** create a large file. If the file was a valid SQLite database, then
|
||||
** the next time the database is opened, SQLite will begin allocating
|
||||
** new pages after N. If N is 2096 or bigger, this will test the
|
||||
** ability of SQLite to write to large files.
|
||||
*/
|
||||
static int fake_big_file(
|
||||
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 rc;
|
||||
int n;
|
||||
off_t offset;
|
||||
OsFile fd;
|
||||
int readOnly = 0;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" N-MEGABYTES FILE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
|
||||
rc = sqliteOsOpenReadWrite(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);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "seek failed: ", errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqliteOsWrite(&fd, "Hello, World!", 14);
|
||||
sqliteOsClose(&fd);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, "write failed: ", errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -388,17 +524,44 @@ static int page_write(
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
Tcl_CreateCommand(interp, "pager_open", pager_open, 0, 0);
|
||||
Tcl_CreateCommand(interp, "pager_close", pager_close, 0, 0);
|
||||
Tcl_CreateCommand(interp, "pager_commit", pager_commit, 0, 0);
|
||||
Tcl_CreateCommand(interp, "pager_rollback", pager_rollback, 0, 0);
|
||||
Tcl_CreateCommand(interp, "pager_stats", pager_stats, 0, 0);
|
||||
Tcl_CreateCommand(interp, "pager_pagecount", pager_pagecount, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_get", page_get, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_lookup", page_lookup, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_unref", page_unref, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_read", page_read, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_write", page_write, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_number", page_number, 0, 0);
|
||||
extern int sqlite_io_error_pending;
|
||||
char zBuf[100];
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_CmdProc *xProc;
|
||||
} aCmd[] = {
|
||||
{ "pager_open", (Tcl_CmdProc*)pager_open },
|
||||
{ "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_stats", (Tcl_CmdProc*)pager_stats },
|
||||
{ "pager_pagecount", (Tcl_CmdProc*)pager_pagecount },
|
||||
{ "page_get", (Tcl_CmdProc*)page_get },
|
||||
{ "page_lookup", (Tcl_CmdProc*)page_lookup },
|
||||
{ "page_unref", (Tcl_CmdProc*)page_unref },
|
||||
{ "page_read", (Tcl_CmdProc*)page_read },
|
||||
{ "page_write", (Tcl_CmdProc*)page_write },
|
||||
{ "page_number", (Tcl_CmdProc*)page_number },
|
||||
{ "fake_big_file", (Tcl_CmdProc*)fake_big_file },
|
||||
};
|
||||
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
|
||||
sprintf(zBuf, "%d", SQLITE_PAGE_SIZE);
|
||||
Tcl_SetVar(interp, "SQLITE_PAGE_SIZE", zBuf, TCL_GLOBAL_ONLY);
|
||||
sprintf(zBuf, "%d", SQLITE_PAGE_RESERVE);
|
||||
Tcl_SetVar(interp, "SQLITE_PAGE_RESERVE", zBuf, TCL_GLOBAL_ONLY);
|
||||
sprintf(zBuf, "%d", SQLITE_USABLE_SIZE);
|
||||
Tcl_SetVar(interp, "SQLITE_USABLE_SIZE", zBuf, TCL_GLOBAL_ONLY);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
+212
-58
@@ -13,7 +13,7 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test3.c,v 1.12 2001/09/23 02:35:53 drh Exp $
|
||||
** $Id: test3.c,v 1.23 2003/04/13 18:26:52 paul Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "pager.h"
|
||||
@@ -57,7 +57,7 @@ static int btree_open(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
@@ -67,12 +67,15 @@ static int btree_open(
|
||||
" FILENAME\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqliteBtreeOpen(argv[1], 0666, 10, &pBt);
|
||||
rc = sqliteBtreeFactory(0, argv[1], 0, 1000, &pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"0x%x",(int)pBt);
|
||||
sprintf(zBuf,"%p", pBt);
|
||||
if( strncmp(zBuf,"0x",2) ){
|
||||
sprintf(zBuf, "0x%p", pBt);
|
||||
}
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -86,7 +89,7 @@ static int btree_close(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
@@ -113,7 +116,7 @@ static int btree_begin_transaction(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
@@ -140,7 +143,7 @@ static int btree_rollback(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
@@ -167,7 +170,7 @@ static int btree_commit(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
@@ -194,7 +197,7 @@ static int btree_create_table(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc, iTable;
|
||||
@@ -224,7 +227,7 @@ static int btree_drop_table(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int iTable;
|
||||
@@ -253,7 +256,7 @@ static int btree_clear_table(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int iTable;
|
||||
@@ -282,7 +285,7 @@ static int btree_get_meta(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
@@ -316,7 +319,7 @@ static int btree_update_meta(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int rc;
|
||||
@@ -351,7 +354,7 @@ static int btree_page_dump(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int iPage;
|
||||
@@ -381,7 +384,7 @@ static int btree_tree_dump(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int iPage;
|
||||
@@ -411,7 +414,7 @@ static int btree_pager_stats(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int i;
|
||||
@@ -446,7 +449,7 @@ static int btree_pager_ref_dump(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
|
||||
@@ -461,17 +464,17 @@ static int btree_pager_ref_dump(
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_sanity_check ID ROOT ...
|
||||
** Usage: btree_integrity_check ID ROOT ...
|
||||
**
|
||||
** Look through every page of the given BTree file to verify correct
|
||||
** formatting and linkage. Return a line of text for each problem found.
|
||||
** Return an empty string if everything worked.
|
||||
*/
|
||||
static int btree_sanity_check(
|
||||
static int btree_integrity_check(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
char *zResult;
|
||||
@@ -490,10 +493,10 @@ static int btree_sanity_check(
|
||||
for(i=0; i<argc-2; i++){
|
||||
if( Tcl_GetInt(interp, argv[i+2], &aRoot[i]) ) return TCL_ERROR;
|
||||
}
|
||||
zResult = sqliteBtreeSanityCheck(pBt, aRoot, nRoot);
|
||||
zResult = sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot);
|
||||
if( zResult ){
|
||||
Tcl_AppendResult(interp, zResult, 0);
|
||||
free(zResult);
|
||||
sqliteFree(zResult);
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -507,7 +510,7 @@ static int btree_cursor(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
Btree *pBt;
|
||||
int iTable;
|
||||
@@ -543,7 +546,7 @@ static int btree_close_cursor(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
@@ -571,7 +574,7 @@ static int btree_move_to(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
@@ -589,6 +592,8 @@ static int btree_move_to(
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( res<0 ) res = -1;
|
||||
if( res>0 ) res = 1;
|
||||
sprintf(zBuf,"%d",res);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
@@ -603,7 +608,7 @@ static int btree_delete(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
@@ -632,7 +637,7 @@ static int btree_insert(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
@@ -655,16 +660,20 @@ static int btree_insert(
|
||||
/*
|
||||
** Usage: btree_next ID
|
||||
**
|
||||
** Move the cursor to the next entry in the table.
|
||||
** Move the cursor to the next entry in the table. Return 0 on success
|
||||
** or 1 if the cursor was already on the last entry in the table or if
|
||||
** the table is empty.
|
||||
*/
|
||||
static int btree_next(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
int res = 0;
|
||||
char zBuf[100];
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
@@ -672,11 +681,113 @@ static int btree_next(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqliteBtreeNext(pCur, 0);
|
||||
rc = sqliteBtreeNext(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",res);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_prev ID
|
||||
**
|
||||
** Move the cursor to the previous entry in the table. Return 0 on
|
||||
** success and 1 if the cursor was already on the first entry in
|
||||
** the table or if the table was empty.
|
||||
*/
|
||||
static int btree_prev(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
int res = 0;
|
||||
char zBuf[100];
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqliteBtreePrevious(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",res);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_first ID
|
||||
**
|
||||
** Move the cursor to the first entry in the table. Return 0 if the
|
||||
** cursor was left point to something and 1 if the table is empty.
|
||||
*/
|
||||
static int btree_first(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
int res = 0;
|
||||
char zBuf[100];
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqliteBtreeFirst(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",res);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_last ID
|
||||
**
|
||||
** Move the cursor to the last entry in the table. Return 0 if the
|
||||
** cursor was left point to something and 1 if the table is empty.
|
||||
*/
|
||||
static int btree_last(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
int res = 0;
|
||||
char zBuf[100];
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
rc = sqliteBtreeLast(pCur, &res);
|
||||
if( rc ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"%d",res);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -689,7 +800,7 @@ static int btree_key(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
@@ -727,7 +838,7 @@ static int btree_data(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
@@ -756,6 +867,34 @@ static int btree_data(
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_payload_size ID
|
||||
**
|
||||
** Return the number of bytes of payload
|
||||
*/
|
||||
static int btree_payload_size(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int n1, n2;
|
||||
char zBuf[50];
|
||||
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
|
||||
sqliteBtreeKeySize(pCur, &n1);
|
||||
sqliteBtreeDataSize(pCur, &n2);
|
||||
sprintf(zBuf, "%d", n1+n2);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: btree_cursor_dump ID
|
||||
**
|
||||
@@ -775,7 +914,7 @@ static int btree_cursor_dump(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
const char **argv /* Text of each argument */
|
||||
){
|
||||
BtCursor *pCur;
|
||||
int rc;
|
||||
@@ -807,32 +946,47 @@ static int btree_cursor_dump(
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest3_Init(Tcl_Interp *interp){
|
||||
Tcl_CreateCommand(interp, "btree_open", btree_open, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_close", btree_close, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_begin_transaction",
|
||||
btree_begin_transaction, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_commit", btree_commit, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_rollback", btree_rollback, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_create_table", btree_create_table, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_drop_table", btree_drop_table, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_clear_table", btree_clear_table, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_get_meta", btree_get_meta, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_update_meta", btree_update_meta, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_page_dump", btree_page_dump, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_tree_dump", btree_tree_dump, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_pager_stats", btree_pager_stats, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_pager_ref_dump", btree_pager_ref_dump, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_cursor", btree_cursor, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_close_cursor", btree_close_cursor, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_move_to", btree_move_to, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_delete", btree_delete, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_insert", btree_insert, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_next", btree_next, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_key", btree_key, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_data", btree_data, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_cursor_dump", btree_cursor_dump, 0, 0);
|
||||
Tcl_CreateCommand(interp, "btree_sanity_check", btree_sanity_check, 0, 0);
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_CmdProc *xProc;
|
||||
} aCmd[] = {
|
||||
{ "btree_open", (Tcl_CmdProc*)btree_open },
|
||||
{ "btree_close", (Tcl_CmdProc*)btree_close },
|
||||
{ "btree_begin_transaction", (Tcl_CmdProc*)btree_begin_transaction },
|
||||
{ "btree_commit", (Tcl_CmdProc*)btree_commit },
|
||||
{ "btree_rollback", (Tcl_CmdProc*)btree_rollback },
|
||||
{ "btree_create_table", (Tcl_CmdProc*)btree_create_table },
|
||||
{ "btree_drop_table", (Tcl_CmdProc*)btree_drop_table },
|
||||
{ "btree_clear_table", (Tcl_CmdProc*)btree_clear_table },
|
||||
{ "btree_get_meta", (Tcl_CmdProc*)btree_get_meta },
|
||||
{ "btree_update_meta", (Tcl_CmdProc*)btree_update_meta },
|
||||
{ "btree_page_dump", (Tcl_CmdProc*)btree_page_dump },
|
||||
{ "btree_tree_dump", (Tcl_CmdProc*)btree_tree_dump },
|
||||
{ "btree_pager_stats", (Tcl_CmdProc*)btree_pager_stats },
|
||||
{ "btree_pager_ref_dump", (Tcl_CmdProc*)btree_pager_ref_dump },
|
||||
{ "btree_cursor", (Tcl_CmdProc*)btree_cursor },
|
||||
{ "btree_close_cursor", (Tcl_CmdProc*)btree_close_cursor },
|
||||
{ "btree_move_to", (Tcl_CmdProc*)btree_move_to },
|
||||
{ "btree_delete", (Tcl_CmdProc*)btree_delete },
|
||||
{ "btree_insert", (Tcl_CmdProc*)btree_insert },
|
||||
{ "btree_next", (Tcl_CmdProc*)btree_next },
|
||||
{ "btree_prev", (Tcl_CmdProc*)btree_prev },
|
||||
{ "btree_key", (Tcl_CmdProc*)btree_key },
|
||||
{ "btree_data", (Tcl_CmdProc*)btree_data },
|
||||
{ "btree_payload_size", (Tcl_CmdProc*)btree_payload_size },
|
||||
{ "btree_first", (Tcl_CmdProc*)btree_first },
|
||||
{ "btree_last", (Tcl_CmdProc*)btree_last },
|
||||
{ "btree_cursor_dump", (Tcl_CmdProc*)btree_cursor_dump },
|
||||
{ "btree_integrity_check", (Tcl_CmdProc*)btree_integrity_check },
|
||||
};
|
||||
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, "pager_refinfo_enable", (char*)&pager_refinfo_enable,
|
||||
TCL_LINK_INT);
|
||||
Tcl_LinkVar(interp, "btree_native_byte_order",(char*)&btree_native_byte_order,
|
||||
TCL_LINK_INT);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
+634
@@ -0,0 +1,634 @@
|
||||
/*
|
||||
** 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.3 2004/04/23 17:04:45 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.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 */
|
||||
sqlite *db; /* Open database */
|
||||
sqlite_vm *vm; /* 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; /* result columns */
|
||||
const char **colv; /* 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 ){
|
||||
sqlite_close(p->db);
|
||||
}
|
||||
p->db = sqlite_open(p->zFilename, 0, &p->zErr);
|
||||
p->vm = 0;
|
||||
p->completed = 1;
|
||||
while( p->opnum<=p->completed ) sched_yield();
|
||||
while( p->xOp ){
|
||||
if( p->zErr && p->zErr!=p->zStaticErr ){
|
||||
sqlite_freemem(p->zErr);
|
||||
p->zErr = 0;
|
||||
}
|
||||
(*p->xOp)(p);
|
||||
p->completed++;
|
||||
while( p->opnum<=p->completed ) sched_yield();
|
||||
}
|
||||
if( p->vm ){
|
||||
sqlite_finalize(p->vm, 0);
|
||||
p->vm = 0;
|
||||
}
|
||||
if( p->db ){
|
||||
sqlite_close(p->db);
|
||||
p->db = 0;
|
||||
}
|
||||
if( p->zErr && p->zErr!=p->zStaticErr ){
|
||||
sqlite_freemem(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(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_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;
|
||||
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_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;
|
||||
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->vm ){
|
||||
sqlite_finalize(p->vm, 0);
|
||||
p->vm = 0;
|
||||
}
|
||||
p->rc = sqlite_compile(p->db, p->zArg, 0, &p->vm, &p->zErr);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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){
|
||||
if( p->vm==0 ){
|
||||
p->zErr = p->zStaticErr = "no virtual machine available";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
p->rc = sqlite_step(p->vm, &p->argc, &p->argv, &p->colv);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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->vm==0 ){
|
||||
p->zErr = p->zStaticErr = "no virtual machine available";
|
||||
p->rc = SQLITE_ERROR;
|
||||
return;
|
||||
}
|
||||
p->rc = sqlite_finalize(p->vm, &p->zErr);
|
||||
p->vm = 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;
|
||||
sqlite *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 */
|
||||
+430
-156
@@ -15,7 +15,7 @@
|
||||
** individual tokens and sends those tokens one-by-one over to the
|
||||
** parser for analysis.
|
||||
**
|
||||
** $Id: tokenize.c,v 1.26 2001/10/09 04:19:47 drh Exp $
|
||||
** $Id: tokenize.c,v 1.68 2004/02/14 23:59:58 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -29,79 +29,122 @@
|
||||
typedef struct Keyword Keyword;
|
||||
struct Keyword {
|
||||
char *zName; /* The keyword name */
|
||||
int len; /* Number of characters in the keyword */
|
||||
int tokenType; /* The token value for this keyword */
|
||||
Keyword *pNext; /* Next keyword with the same hash */
|
||||
u8 tokenType; /* Token value for this keyword */
|
||||
u8 len; /* Length of this keyword */
|
||||
u8 iNext; /* Index in aKeywordTable[] of next with same hash */
|
||||
};
|
||||
|
||||
/*
|
||||
** These are the keywords
|
||||
*/
|
||||
static Keyword aKeywordTable[] = {
|
||||
{ "ALL", 0, TK_ALL, 0 },
|
||||
{ "AND", 0, TK_AND, 0 },
|
||||
{ "AS", 0, TK_AS, 0 },
|
||||
{ "ASC", 0, TK_ASC, 0 },
|
||||
{ "BEGIN", 0, TK_BEGIN, 0 },
|
||||
{ "BETWEEN", 0, TK_BETWEEN, 0 },
|
||||
{ "BY", 0, TK_BY, 0 },
|
||||
{ "CHECK", 0, TK_CHECK, 0 },
|
||||
{ "CLUSTER", 0, TK_CLUSTER, 0 },
|
||||
{ "COMMIT", 0, TK_COMMIT, 0 },
|
||||
{ "CONSTRAINT", 0, TK_CONSTRAINT, 0 },
|
||||
{ "COPY", 0, TK_COPY, 0 },
|
||||
{ "CREATE", 0, TK_CREATE, 0 },
|
||||
{ "DEFAULT", 0, TK_DEFAULT, 0 },
|
||||
{ "DELETE", 0, TK_DELETE, 0 },
|
||||
{ "DELIMITERS", 0, TK_DELIMITERS, 0 },
|
||||
{ "DESC", 0, TK_DESC, 0 },
|
||||
{ "DISTINCT", 0, TK_DISTINCT, 0 },
|
||||
{ "DROP", 0, TK_DROP, 0 },
|
||||
{ "END", 0, TK_END, 0 },
|
||||
{ "EXCEPT", 0, TK_EXCEPT, 0 },
|
||||
{ "EXPLAIN", 0, TK_EXPLAIN, 0 },
|
||||
{ "FROM", 0, TK_FROM, 0 },
|
||||
{ "GLOB", 0, TK_GLOB, 0 },
|
||||
{ "GROUP", 0, TK_GROUP, 0 },
|
||||
{ "HAVING", 0, TK_HAVING, 0 },
|
||||
{ "IN", 0, TK_IN, 0 },
|
||||
{ "INDEX", 0, TK_INDEX, 0 },
|
||||
{ "INSERT", 0, TK_INSERT, 0 },
|
||||
{ "INTERSECT", 0, TK_INTERSECT, 0 },
|
||||
{ "INTO", 0, TK_INTO, 0 },
|
||||
{ "IS", 0, TK_IS, 0 },
|
||||
{ "ISNULL", 0, TK_ISNULL, 0 },
|
||||
{ "KEY", 0, TK_KEY, 0 },
|
||||
{ "LIKE", 0, TK_LIKE, 0 },
|
||||
{ "NOT", 0, TK_NOT, 0 },
|
||||
{ "NOTNULL", 0, TK_NOTNULL, 0 },
|
||||
{ "NULL", 0, TK_NULL, 0 },
|
||||
{ "ON", 0, TK_ON, 0 },
|
||||
{ "OR", 0, TK_OR, 0 },
|
||||
{ "ORDER", 0, TK_ORDER, 0 },
|
||||
{ "PRAGMA", 0, TK_PRAGMA, 0 },
|
||||
{ "PRIMARY", 0, TK_PRIMARY, 0 },
|
||||
{ "ROLLBACK", 0, TK_ROLLBACK, 0 },
|
||||
{ "SELECT", 0, TK_SELECT, 0 },
|
||||
{ "SET", 0, TK_SET, 0 },
|
||||
{ "TABLE", 0, TK_TABLE, 0 },
|
||||
{ "TEMP", 0, TK_TEMP, 0 },
|
||||
{ "TEMPORARY", 0, TK_TEMP, 0 },
|
||||
{ "TRANSACTION", 0, TK_TRANSACTION, 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 },
|
||||
{ "WHERE", 0, TK_WHERE, 0 },
|
||||
{ "ABORT", TK_ABORT, },
|
||||
{ "AFTER", TK_AFTER, },
|
||||
{ "ALL", TK_ALL, },
|
||||
{ "AND", TK_AND, },
|
||||
{ "AS", TK_AS, },
|
||||
{ "ASC", TK_ASC, },
|
||||
{ "ATTACH", TK_ATTACH, },
|
||||
{ "BEFORE", TK_BEFORE, },
|
||||
{ "BEGIN", TK_BEGIN, },
|
||||
{ "BETWEEN", TK_BETWEEN, },
|
||||
{ "BY", TK_BY, },
|
||||
{ "CASCADE", TK_CASCADE, },
|
||||
{ "CASE", TK_CASE, },
|
||||
{ "CHECK", TK_CHECK, },
|
||||
{ "CLUSTER", TK_CLUSTER, },
|
||||
{ "COLLATE", TK_COLLATE, },
|
||||
{ "COMMIT", TK_COMMIT, },
|
||||
{ "CONFLICT", TK_CONFLICT, },
|
||||
{ "CONSTRAINT", TK_CONSTRAINT, },
|
||||
{ "COPY", TK_COPY, },
|
||||
{ "CREATE", TK_CREATE, },
|
||||
{ "CROSS", TK_JOIN_KW, },
|
||||
{ "DATABASE", TK_DATABASE, },
|
||||
{ "DEFAULT", TK_DEFAULT, },
|
||||
{ "DEFERRED", TK_DEFERRED, },
|
||||
{ "DEFERRABLE", TK_DEFERRABLE, },
|
||||
{ "DELETE", TK_DELETE, },
|
||||
{ "DELIMITERS", TK_DELIMITERS, },
|
||||
{ "DESC", TK_DESC, },
|
||||
{ "DETACH", TK_DETACH, },
|
||||
{ "DISTINCT", TK_DISTINCT, },
|
||||
{ "DROP", TK_DROP, },
|
||||
{ "END", TK_END, },
|
||||
{ "EACH", TK_EACH, },
|
||||
{ "ELSE", TK_ELSE, },
|
||||
{ "EXCEPT", TK_EXCEPT, },
|
||||
{ "EXPLAIN", TK_EXPLAIN, },
|
||||
{ "FAIL", TK_FAIL, },
|
||||
{ "FOR", TK_FOR, },
|
||||
{ "FOREIGN", TK_FOREIGN, },
|
||||
{ "FROM", TK_FROM, },
|
||||
{ "FULL", TK_JOIN_KW, },
|
||||
{ "GLOB", TK_GLOB, },
|
||||
{ "GROUP", TK_GROUP, },
|
||||
{ "HAVING", TK_HAVING, },
|
||||
{ "IGNORE", TK_IGNORE, },
|
||||
{ "IMMEDIATE", TK_IMMEDIATE, },
|
||||
{ "IN", TK_IN, },
|
||||
{ "INDEX", TK_INDEX, },
|
||||
{ "INITIALLY", TK_INITIALLY, },
|
||||
{ "INNER", TK_JOIN_KW, },
|
||||
{ "INSERT", TK_INSERT, },
|
||||
{ "INSTEAD", TK_INSTEAD, },
|
||||
{ "INTERSECT", TK_INTERSECT, },
|
||||
{ "INTO", TK_INTO, },
|
||||
{ "IS", TK_IS, },
|
||||
{ "ISNULL", TK_ISNULL, },
|
||||
{ "JOIN", TK_JOIN, },
|
||||
{ "KEY", TK_KEY, },
|
||||
{ "LEFT", TK_JOIN_KW, },
|
||||
{ "LIKE", TK_LIKE, },
|
||||
{ "LIMIT", TK_LIMIT, },
|
||||
{ "MATCH", TK_MATCH, },
|
||||
{ "NATURAL", TK_JOIN_KW, },
|
||||
{ "NOT", TK_NOT, },
|
||||
{ "NOTNULL", TK_NOTNULL, },
|
||||
{ "NULL", TK_NULL, },
|
||||
{ "OF", TK_OF, },
|
||||
{ "OFFSET", TK_OFFSET, },
|
||||
{ "ON", TK_ON, },
|
||||
{ "OR", TK_OR, },
|
||||
{ "ORDER", TK_ORDER, },
|
||||
{ "OUTER", TK_JOIN_KW, },
|
||||
{ "PRAGMA", TK_PRAGMA, },
|
||||
{ "PRIMARY", TK_PRIMARY, },
|
||||
{ "RAISE", TK_RAISE, },
|
||||
{ "REFERENCES", TK_REFERENCES, },
|
||||
{ "REPLACE", TK_REPLACE, },
|
||||
{ "RESTRICT", TK_RESTRICT, },
|
||||
{ "RIGHT", TK_JOIN_KW, },
|
||||
{ "ROLLBACK", TK_ROLLBACK, },
|
||||
{ "ROW", TK_ROW, },
|
||||
{ "SELECT", TK_SELECT, },
|
||||
{ "SET", TK_SET, },
|
||||
{ "STATEMENT", TK_STATEMENT, },
|
||||
{ "TABLE", TK_TABLE, },
|
||||
{ "TEMP", TK_TEMP, },
|
||||
{ "TEMPORARY", TK_TEMP, },
|
||||
{ "THEN", TK_THEN, },
|
||||
{ "TRANSACTION", TK_TRANSACTION, },
|
||||
{ "TRIGGER", TK_TRIGGER, },
|
||||
{ "UNION", TK_UNION, },
|
||||
{ "UNIQUE", TK_UNIQUE, },
|
||||
{ "UPDATE", TK_UPDATE, },
|
||||
{ "USING", TK_USING, },
|
||||
{ "VACUUM", TK_VACUUM, },
|
||||
{ "VALUES", TK_VALUES, },
|
||||
{ "VIEW", TK_VIEW, },
|
||||
{ "WHEN", TK_WHEN, },
|
||||
{ "WHERE", TK_WHERE, },
|
||||
};
|
||||
|
||||
/*
|
||||
** This is the hash table
|
||||
*/
|
||||
#define KEY_HASH_SIZE 71
|
||||
static Keyword *apHashTable[KEY_HASH_SIZE];
|
||||
#define KEY_HASH_SIZE 101
|
||||
static u8 aiHashTable[KEY_HASH_SIZE];
|
||||
|
||||
|
||||
/*
|
||||
@@ -109,28 +152,30 @@ static Keyword *apHashTable[KEY_HASH_SIZE];
|
||||
** 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.
|
||||
*/
|
||||
static int sqliteKeywordCode(const char *z, int n){
|
||||
int h;
|
||||
int sqliteKeywordCode(const char *z, int n){
|
||||
int h, i;
|
||||
Keyword *p;
|
||||
if( aKeywordTable[0].len==0 ){
|
||||
static char needInit = 1;
|
||||
if( needInit ){
|
||||
/* 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++){
|
||||
if( needInit ){
|
||||
int nk;
|
||||
nk = sizeof(aKeywordTable)/sizeof(aKeywordTable[0]);
|
||||
for(i=0; i<nk; 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];
|
||||
aKeywordTable[i].iNext = aiHashTable[h];
|
||||
aiHashTable[h] = i+1;
|
||||
}
|
||||
needInit = 0;
|
||||
}
|
||||
sqliteOsLeaveMutex();
|
||||
}
|
||||
h = sqliteHashNoCase(z, n) % KEY_HASH_SIZE;
|
||||
for(p=apHashTable[h]; p; p=p->pNext){
|
||||
for(i=aiHashTable[h]; i; i=p->iNext){
|
||||
p = &aKeywordTable[i-1];
|
||||
if( p->len==n && sqliteStrNICmp(p->zName, z, n)==0 ){
|
||||
return p->tokenType;
|
||||
}
|
||||
@@ -138,21 +183,47 @@ static int sqliteKeywordCode(const char *z, int n){
|
||||
return TK_ID;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Return the length of the token that begins at z[0]. Return
|
||||
** -1 if the token is (or might be) incomplete. Store the token
|
||||
** type in *tokenType before returning.
|
||||
** If X is a character that can be used in an identifier and
|
||||
** X&0x80==0 then isIdChar[X] will be 1. If X&0x80==0x80 then
|
||||
** X is always an identifier character. (Hence all UTF-8
|
||||
** characters can be part of an identifier). isIdChar[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.
|
||||
*/
|
||||
int sqliteGetToken(const char *z, int *tokenType){
|
||||
static const char isIdChar[] = {
|
||||
/* 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 */
|
||||
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 */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** 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;
|
||||
switch( *z ){
|
||||
case ' ': case '\t': case '\n': case '\f': case '\r': {
|
||||
for(i=1; z[i] && isspace(z[i]); i++){}
|
||||
for(i=1; isspace(z[i]); i++){}
|
||||
*tokenType = TK_SPACE;
|
||||
return i;
|
||||
}
|
||||
case '-': {
|
||||
if( z[1]==0 ) return -1;
|
||||
if( z[1]=='-' ){
|
||||
for(i=2; z[i] && z[i]!='\n'; i++){}
|
||||
*tokenType = TK_COMMENT;
|
||||
@@ -182,7 +253,17 @@ int sqliteGetToken(const char *z, int *tokenType){
|
||||
return 1;
|
||||
}
|
||||
case '/': {
|
||||
*tokenType = TK_SLASH;
|
||||
if( z[1]!='*' || z[2]==0 ){
|
||||
*tokenType = TK_SLASH;
|
||||
return 1;
|
||||
}
|
||||
for(i=3; z[i] && (z[i]!='/' || z[i-1]!='*'); i++){}
|
||||
if( z[i] ) i++;
|
||||
*tokenType = TK_COMMENT;
|
||||
return i;
|
||||
}
|
||||
case '%': {
|
||||
*tokenType = TK_REM;
|
||||
return 1;
|
||||
}
|
||||
case '=': {
|
||||
@@ -196,6 +277,9 @@ int sqliteGetToken(const char *z, int *tokenType){
|
||||
}else if( z[1]=='>' ){
|
||||
*tokenType = TK_NE;
|
||||
return 2;
|
||||
}else if( z[1]=='<' ){
|
||||
*tokenType = TK_LSHIFT;
|
||||
return 2;
|
||||
}else{
|
||||
*tokenType = TK_LT;
|
||||
return 1;
|
||||
@@ -205,6 +289,9 @@ int sqliteGetToken(const char *z, int *tokenType){
|
||||
if( z[1]=='=' ){
|
||||
*tokenType = TK_GE;
|
||||
return 2;
|
||||
}else if( z[1]=='>' ){
|
||||
*tokenType = TK_RSHIFT;
|
||||
return 2;
|
||||
}else{
|
||||
*tokenType = TK_GT;
|
||||
return 1;
|
||||
@@ -221,7 +308,7 @@ int sqliteGetToken(const char *z, int *tokenType){
|
||||
}
|
||||
case '|': {
|
||||
if( z[1]!='|' ){
|
||||
*tokenType = TK_ILLEGAL;
|
||||
*tokenType = TK_BITOR;
|
||||
return 1;
|
||||
}else{
|
||||
*tokenType = TK_CONCAT;
|
||||
@@ -232,6 +319,14 @@ int sqliteGetToken(const char *z, int *tokenType){
|
||||
*tokenType = TK_COMMA;
|
||||
return 1;
|
||||
}
|
||||
case '&': {
|
||||
*tokenType = TK_BITAND;
|
||||
return 1;
|
||||
}
|
||||
case '~': {
|
||||
*tokenType = TK_BITNOT;
|
||||
return 1;
|
||||
}
|
||||
case '\'': case '"': {
|
||||
int delim = z[0];
|
||||
for(i=1; z[i]; i++){
|
||||
@@ -248,19 +343,16 @@ int sqliteGetToken(const char *z, int *tokenType){
|
||||
return i;
|
||||
}
|
||||
case '.': {
|
||||
if( !isdigit(z[1]) ){
|
||||
*tokenType = TK_DOT;
|
||||
return 1;
|
||||
}
|
||||
/* Fall thru into the next case */
|
||||
*tokenType = TK_DOT;
|
||||
return 1;
|
||||
}
|
||||
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; z[i] && isdigit(z[i]); i++){}
|
||||
if( z[i]=='.' ){
|
||||
i++;
|
||||
while( z[i] && isdigit(z[i]) ){ i++; }
|
||||
for(i=1; isdigit(z[i]); i++){}
|
||||
if( z[i]=='.' && isdigit(z[i+1]) ){
|
||||
i += 2;
|
||||
while( isdigit(z[i]) ){ i++; }
|
||||
*tokenType = TK_FLOAT;
|
||||
}
|
||||
if( (z[i]=='e' || z[i]=='E') &&
|
||||
@@ -269,29 +361,27 @@ int sqliteGetToken(const char *z, int *tokenType){
|
||||
)
|
||||
){
|
||||
i += 2;
|
||||
while( z[i] && isdigit(z[i]) ){ i++; }
|
||||
*tokenType = TK_FLOAT;
|
||||
}else if( z[0]=='.' ){
|
||||
while( isdigit(z[i]) ){ i++; }
|
||||
*tokenType = TK_FLOAT;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
|
||||
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
|
||||
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
|
||||
case 'y': case 'z': case '_':
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
|
||||
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
|
||||
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
|
||||
case 'Y': case 'Z': {
|
||||
for(i=1; z[i] && (isalnum(z[i]) || z[i]=='_'); i++){}
|
||||
*tokenType = sqliteKeywordCode(z, i);
|
||||
case '[': {
|
||||
for(i=1; z[i] && z[i-1]!=']'; i++){}
|
||||
*tokenType = TK_ID;
|
||||
return i;
|
||||
}
|
||||
case '?': {
|
||||
*tokenType = TK_VARIABLE;
|
||||
return 1;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
if( (*z&0x80)==0 && !isIdChar[*z] ){
|
||||
break;
|
||||
}
|
||||
for(i=1; (z[i]&0x80)!=0 || isIdChar[z[i]]; i++){}
|
||||
*tokenType = sqliteKeywordCode((char*)z, i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
*tokenType = TK_ILLEGAL;
|
||||
@@ -305,91 +395,86 @@ int sqliteGetToken(const char *z, int *tokenType){
|
||||
** memory obtained from malloc() and *pzErrMsg made to point to that
|
||||
** error message. Or maybe not.
|
||||
*/
|
||||
int sqliteRunParser(Parse *pParse, char *zSql, char **pzErrMsg){
|
||||
int sqliteRunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
||||
int nErr = 0;
|
||||
int i;
|
||||
void *pEngine;
|
||||
int once = 1;
|
||||
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*);
|
||||
|
||||
pParse->db->flags &= ~SQLITE_Interrupt;
|
||||
db->flags &= ~SQLITE_Interrupt;
|
||||
pParse->rc = SQLITE_OK;
|
||||
i = 0;
|
||||
sqliteParseInfoReset(pParse);
|
||||
pEngine = sqliteParserAlloc((void*(*)(int))malloc);
|
||||
if( pEngine==0 ){
|
||||
sqliteSetString(pzErrMsg, "out of memory", 0);
|
||||
sqliteSetString(pzErrMsg, "out of memory", (char*)0);
|
||||
return 1;
|
||||
}
|
||||
while( sqlite_malloc_failed==0 && nErr==0 && i>=0 && zSql[i]!=0 ){
|
||||
int tokenType;
|
||||
|
||||
if( (pParse->db->flags & SQLITE_Interrupt)!=0 ){
|
||||
pParse->rc = SQLITE_INTERRUPT;
|
||||
sqliteSetString(pzErrMsg, "interrupt", 0);
|
||||
break;
|
||||
}
|
||||
pParse->sLastToken.dyn = 0;
|
||||
pParse->zTail = zSql;
|
||||
while( sqlite_malloc_failed==0 && zSql[i]!=0 ){
|
||||
assert( i>=0 );
|
||||
pParse->sLastToken.z = &zSql[i];
|
||||
pParse->sLastToken.n = sqliteGetToken(&zSql[i], &tokenType);
|
||||
assert( pParse->sLastToken.dyn==0 );
|
||||
pParse->sLastToken.n = sqliteGetToken((unsigned char*)&zSql[i], &tokenType);
|
||||
i += pParse->sLastToken.n;
|
||||
if( once ){
|
||||
pParse->sFirstToken = pParse->sLastToken;
|
||||
once = 0;
|
||||
}
|
||||
switch( tokenType ){
|
||||
case TK_SPACE:
|
||||
case TK_COMMENT: {
|
||||
if( (db->flags & SQLITE_Interrupt)!=0 ){
|
||||
pParse->rc = SQLITE_INTERRUPT;
|
||||
sqliteSetString(pzErrMsg, "interrupt", (char*)0);
|
||||
goto abort_parse;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TK_ILLEGAL:
|
||||
case TK_ILLEGAL: {
|
||||
sqliteSetNString(pzErrMsg, "unrecognized token: \"", -1,
|
||||
pParse->sLastToken.z, pParse->sLastToken.n, "\"", 1, 0);
|
||||
nErr++;
|
||||
break;
|
||||
default:
|
||||
goto abort_parse;
|
||||
}
|
||||
case TK_SEMI: {
|
||||
pParse->zTail = &zSql[i];
|
||||
/* Fall thru into the default case */
|
||||
}
|
||||
default: {
|
||||
sqliteParser(pEngine, tokenType, pParse->sLastToken, pParse);
|
||||
if( pParse->zErrMsg && pParse->sErrToken.z ){
|
||||
sqliteSetNString(pzErrMsg, "near \"", -1,
|
||||
pParse->sErrToken.z, pParse->sErrToken.n,
|
||||
"\": ", -1,
|
||||
pParse->zErrMsg, -1,
|
||||
0);
|
||||
nErr++;
|
||||
sqliteFree(pParse->zErrMsg);
|
||||
pParse->zErrMsg = 0;
|
||||
}else if( pParse->rc!=SQLITE_OK ){
|
||||
sqliteSetString(pzErrMsg, sqliteErrStr(pParse->rc), 0);
|
||||
nErr++;
|
||||
lastTokenParsed = tokenType;
|
||||
if( pParse->rc!=SQLITE_OK ){
|
||||
goto abort_parse;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( nErr==0 && (pParse->db->flags & SQLITE_Interrupt)==0 ){
|
||||
sqliteParser(pEngine, 0, pParse->sLastToken, pParse);
|
||||
if( pParse->zErrMsg && pParse->sErrToken.z ){
|
||||
sqliteSetNString(pzErrMsg, "near \"", -1,
|
||||
pParse->sErrToken.z, pParse->sErrToken.n,
|
||||
"\": ", -1,
|
||||
pParse->zErrMsg, -1,
|
||||
0);
|
||||
nErr++;
|
||||
sqliteFree(pParse->zErrMsg);
|
||||
pParse->zErrMsg = 0;
|
||||
abort_parse:
|
||||
if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
|
||||
if( lastTokenParsed!=TK_SEMI ){
|
||||
sqliteParser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
|
||||
pParse->zTail = &zSql[i];
|
||||
}
|
||||
sqliteParser(pEngine, 0, pParse->sLastToken, pParse);
|
||||
}
|
||||
sqliteParserFree(pEngine, free);
|
||||
if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
|
||||
sqliteSetString(&pParse->zErrMsg, sqlite_error_string(pParse->rc),
|
||||
(char*)0);
|
||||
}
|
||||
if( pParse->zErrMsg ){
|
||||
if( pzErrMsg ){
|
||||
sqliteFree(*pzErrMsg);
|
||||
if( pzErrMsg && *pzErrMsg==0 ){
|
||||
*pzErrMsg = pParse->zErrMsg;
|
||||
}else{
|
||||
sqliteFree(pParse->zErrMsg);
|
||||
}
|
||||
pParse->zErrMsg = 0;
|
||||
if( !nErr ) nErr++;
|
||||
}
|
||||
if( pParse->pVdbe ){
|
||||
if( pParse->pVdbe && pParse->nErr>0 ){
|
||||
sqliteVdbeDelete(pParse->pVdbe);
|
||||
pParse->pVdbe = 0;
|
||||
}
|
||||
@@ -397,9 +482,198 @@ int sqliteRunParser(Parse *pParse, char *zSql, char **pzErrMsg){
|
||||
sqliteDeleteTable(pParse->db, pParse->pNewTable);
|
||||
pParse->pNewTable = 0;
|
||||
}
|
||||
sqliteParseInfoReset(pParse);
|
||||
if( nErr>0 && pParse->rc==SQLITE_OK ){
|
||||
if( pParse->pNewTrigger ){
|
||||
sqliteDeleteTrigger(pParse->pNewTrigger);
|
||||
pParse->pNewTrigger = 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
+764
@@ -0,0 +1,764 @@
|
||||
/*
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
*
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Delete a linked list of TriggerStep structures.
|
||||
*/
|
||||
void sqliteDeleteTriggerStep(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);
|
||||
|
||||
sqliteFree(pTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This is called by the parser when it sees a CREATE TRIGGER statement
|
||||
** 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
|
||||
** construction process.
|
||||
*/
|
||||
void sqliteBeginTrigger(
|
||||
Parse *pParse, /* The parse context of the CREATE TRIGGER statement */
|
||||
Token *pName, /* 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 */
|
||||
SrcList *pTableName,/* The name of the table/view the trigger applies to */
|
||||
int foreach, /* One of TK_ROW or TK_STATEMENT */
|
||||
Expr *pWhen, /* WHEN clause */
|
||||
int isTemp /* True if the TEMPORARY keyword is present */
|
||||
){
|
||||
Trigger *nt;
|
||||
Table *tab;
|
||||
char *zName = 0; /* Name of the trigger */
|
||||
sqlite *db = pParse->db;
|
||||
int iDb; /* When database to store the trigger in */
|
||||
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( sqlite_malloc_failed ) goto trigger_cleanup;
|
||||
assert( pTableName->nSrc==1 );
|
||||
if( db->init.busy
|
||||
&& sqliteFixInit(&sFix, pParse, db->init.iDb, "trigger", pName)
|
||||
&& sqliteFixSrcList(&sFix, pTableName)
|
||||
){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
tab = sqliteSrcListLookup(pParse, pTableName);
|
||||
if( !tab ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
iDb = isTemp ? 1 : tab->iDb;
|
||||
if( iDb>=2 && !db->init.busy ){
|
||||
sqliteErrorMsg(pParse, "triggers may not be added to auxiliary "
|
||||
"database %s", db->aDb[tab->iDb].zName);
|
||||
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);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqliteStrNICmp(tab->zName, "sqlite_", 7)==0 ){
|
||||
sqliteErrorMsg(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",
|
||||
(tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( !tab->pSelect && tr_tm == TK_INSTEAD ){
|
||||
sqliteErrorMsg(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 *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) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
if( sqliteAuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(tab->iDb), 0, zDb)){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* INSTEAD OF triggers can only appear on views and BEGIN triggers
|
||||
** cannot appear on views. So we might as well translate every
|
||||
** INSTEAD OF trigger into a BEFORE trigger. It simplifies code
|
||||
** elsewhere.
|
||||
*/
|
||||
if (tr_tm == TK_INSTEAD){
|
||||
tr_tm = TK_BEFORE;
|
||||
}
|
||||
|
||||
/* Build the Trigger object */
|
||||
nt = (Trigger*)sqliteMalloc(sizeof(Trigger));
|
||||
if( nt==0 ) goto trigger_cleanup;
|
||||
nt->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);
|
||||
assert( pParse->pNewTrigger==0 );
|
||||
pParse->pNewTrigger = nt;
|
||||
|
||||
trigger_cleanup:
|
||||
sqliteFree(zName);
|
||||
sqliteSrcListDelete(pTableName);
|
||||
sqliteIdListDelete(pColumns);
|
||||
sqliteExprDelete(pWhen);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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(
|
||||
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 */
|
||||
DbFixer sFix;
|
||||
|
||||
if( pParse->nErr || pParse->pNewTrigger==0 ) goto triggerfinish_cleanup;
|
||||
nt = pParse->pNewTrigger;
|
||||
pParse->pNewTrigger = 0;
|
||||
nt->step_list = pStepList;
|
||||
while( pStepList ){
|
||||
pStepList->pTrig = nt;
|
||||
pStepList = pStepList->pNext;
|
||||
}
|
||||
if( sqliteFixInit(&sFix, pParse, nt->iDb, "trigger", &nt->nameToken)
|
||||
&& sqliteFixTriggerStep(&sFix, nt->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( !db->init.busy ){
|
||||
static VdbeOpList 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 */
|
||||
{ OP_Integer, 0, 0, 0 },
|
||||
{ OP_String, 0, 0, 0 }, /* 5: SQL */
|
||||
{ OP_MakeRecord, 5, 0, 0 },
|
||||
{ OP_PutIntKey, 0, 0, 0 },
|
||||
};
|
||||
int addr;
|
||||
Vdbe *v;
|
||||
|
||||
/* Make an entry in the sqlite_master table */
|
||||
v = sqliteGetVdbe(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);
|
||||
}
|
||||
|
||||
if( !pParse->explain ){
|
||||
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);
|
||||
assert( pTab!=0 );
|
||||
nt->pNext = pTab->pTrigger;
|
||||
pTab->pTrigger = nt;
|
||||
nt = 0;
|
||||
}
|
||||
|
||||
triggerfinish_cleanup:
|
||||
sqliteDeleteTrigger(nt);
|
||||
sqliteDeleteTrigger(pParse->pNewTrigger);
|
||||
pParse->pNewTrigger = 0;
|
||||
sqliteDeleteTriggerStep(pStepList);
|
||||
}
|
||||
|
||||
/*
|
||||
** Make a copy of all components of the given trigger step. This has
|
||||
** 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()
|
||||
** 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.
|
||||
*/
|
||||
static void sqlitePersistTriggerStep(TriggerStep *p){
|
||||
if( p->target.z ){
|
||||
p->target.z = sqliteStrNDup(p->target.z, p->target.n);
|
||||
p->target.dyn = 1;
|
||||
}
|
||||
if( p->pSelect ){
|
||||
Select *pNew = sqliteSelectDup(p->pSelect);
|
||||
sqliteSelectDelete(p->pSelect);
|
||||
p->pSelect = pNew;
|
||||
}
|
||||
if( p->pWhere ){
|
||||
Expr *pNew = sqliteExprDup(p->pWhere);
|
||||
sqliteExprDelete(p->pWhere);
|
||||
p->pWhere = pNew;
|
||||
}
|
||||
if( p->pExprList ){
|
||||
ExprList *pNew = sqliteExprListDup(p->pExprList);
|
||||
sqliteExprListDelete(p->pExprList);
|
||||
p->pExprList = pNew;
|
||||
}
|
||||
if( p->pIdList ){
|
||||
IdList *pNew = sqliteIdListDup(p->pIdList);
|
||||
sqliteIdListDelete(p->pIdList);
|
||||
p->pIdList = pNew;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Turn a SELECT statement (that the pSelect parameter points to) into
|
||||
** a trigger step. Return a pointer to a TriggerStep structure.
|
||||
**
|
||||
** The parser calls this routine when it finds a SELECT statement in
|
||||
** body of a TRIGGER.
|
||||
*/
|
||||
TriggerStep *sqliteTriggerSelectStep(Select *pSelect){
|
||||
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
|
||||
if( pTriggerStep==0 ) return 0;
|
||||
|
||||
pTriggerStep->op = TK_SELECT;
|
||||
pTriggerStep->pSelect = pSelect;
|
||||
pTriggerStep->orconf = OE_Default;
|
||||
sqlitePersistTriggerStep(pTriggerStep);
|
||||
|
||||
return pTriggerStep;
|
||||
}
|
||||
|
||||
/*
|
||||
** Build a trigger step out of an INSERT statement. Return a pointer
|
||||
** to the new trigger step.
|
||||
**
|
||||
** The parser calls this routine when it sees an INSERT inside the
|
||||
** body of a trigger.
|
||||
*/
|
||||
TriggerStep *sqliteTriggerInsertStep(
|
||||
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 */
|
||||
Select *pSelect, /* A SELECT statement that supplies values */
|
||||
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);
|
||||
|
||||
return pTriggerStep;
|
||||
}
|
||||
|
||||
/*
|
||||
** Construct a trigger step that implements an UPDATE statement and return
|
||||
** 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(
|
||||
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 */
|
||||
int orconf /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */
|
||||
){
|
||||
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
|
||||
if( pTriggerStep==0 ) return 0;
|
||||
|
||||
pTriggerStep->op = TK_UPDATE;
|
||||
pTriggerStep->target = *pTableName;
|
||||
pTriggerStep->pExprList = pEList;
|
||||
pTriggerStep->pWhere = pWhere;
|
||||
pTriggerStep->orconf = orconf;
|
||||
sqlitePersistTriggerStep(pTriggerStep);
|
||||
|
||||
return pTriggerStep;
|
||||
}
|
||||
|
||||
/*
|
||||
** Construct a trigger step that implements a DELETE statement and return
|
||||
** 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 *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
|
||||
if( pTriggerStep==0 ) return 0;
|
||||
|
||||
pTriggerStep->op = TK_DELETE;
|
||||
pTriggerStep->target = *pTableName;
|
||||
pTriggerStep->pWhere = pWhere;
|
||||
pTriggerStep->orconf = OE_Default;
|
||||
sqlitePersistTriggerStep(pTriggerStep);
|
||||
|
||||
return pTriggerStep;
|
||||
}
|
||||
|
||||
/*
|
||||
** Recursively delete a Trigger structure
|
||||
*/
|
||||
void sqliteDeleteTrigger(Trigger *pTrigger){
|
||||
if( pTrigger==0 ) return;
|
||||
sqliteDeleteTriggerStep(pTrigger->step_list);
|
||||
sqliteFree(pTrigger->name);
|
||||
sqliteFree(pTrigger->table);
|
||||
sqliteExprDelete(pTrigger->pWhen);
|
||||
sqliteIdListDelete(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;
|
||||
int i;
|
||||
const char *zDb;
|
||||
const char *zName;
|
||||
int nName;
|
||||
sqlite *db = pParse->db;
|
||||
|
||||
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++){
|
||||
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( pTrigger ) break;
|
||||
}
|
||||
if( !pTrigger ){
|
||||
sqliteErrorMsg(pParse, "no such trigger: %S", pName, 0);
|
||||
goto drop_trigger_cleanup;
|
||||
}
|
||||
sqliteDropTriggerPtr(pParse, pTrigger, 0);
|
||||
|
||||
drop_trigger_cleanup:
|
||||
sqliteSrcListDelete(pName);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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){
|
||||
Table *pTable;
|
||||
Vdbe *v;
|
||||
sqlite *db = pParse->db;
|
||||
|
||||
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);
|
||||
assert(pTable);
|
||||
assert( pTable->iDb==pTrigger->iDb || pTrigger->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) ){
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Generate code to destroy the database record of the trigger.
|
||||
*/
|
||||
if( pTable!=0 && !nested && (v = sqliteGetVdbe(pParse))!=0 ){
|
||||
int base;
|
||||
static VdbeOpList dropTrigger[] = {
|
||||
{ OP_Rewind, 0, ADDR(9), 0},
|
||||
{ OP_String, 0, 0, 0}, /* 1 */
|
||||
{ OP_Column, 0, 1, 0},
|
||||
{ OP_Ne, 0, ADDR(8), 0},
|
||||
{ OP_String, 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);
|
||||
}
|
||||
|
||||
/*
|
||||
* If this is not an "explain", then delete the trigger structure.
|
||||
*/
|
||||
if( !pParse->explain ){
|
||||
const char *zName = pTrigger->name;
|
||||
int nName = strlen(zName);
|
||||
if( pTable->pTrigger == pTrigger ){
|
||||
pTable->pTrigger = pTrigger->pNext;
|
||||
}else{
|
||||
Trigger *cc = pTable->pTrigger;
|
||||
while( cc ){
|
||||
if( cc->pNext == pTrigger ){
|
||||
cc->pNext = cc->pNext->pNext;
|
||||
break;
|
||||
}
|
||||
cc = cc->pNext;
|
||||
}
|
||||
assert(cc);
|
||||
}
|
||||
sqliteHashInsert(&(db->aDb[pTrigger->iDb].trigHash), zName, nName+1, 0);
|
||||
sqliteDeleteTrigger(pTrigger);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** pEList is the SET clause of an UPDATE statement. Each entry
|
||||
** in pEList is of the format <id>=<expr>. If any of the entries
|
||||
** in pEList have an <id> which matches an identifier in pIdList,
|
||||
** then return TRUE. If pIdList==NULL, then it is considered a
|
||||
** wildcard that matches anything. Likewise if pEList==NULL then
|
||||
** it matches anything so always return true. Return false only
|
||||
** if there is no match.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
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(
|
||||
Parse *pParse, /* Used to check for recursive triggers */
|
||||
Trigger *pTrigger, /* A list of triggers associated with a table */
|
||||
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;
|
||||
|
||||
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;
|
||||
ss = pParse->trigStack;
|
||||
while( ss && ss->pTrigger != pTrigger ){
|
||||
ss = ss->pNext;
|
||||
}
|
||||
if( !ss )return 1;
|
||||
}
|
||||
pTriggerCursor = pTriggerCursor->pNext;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert the pStep->target token into a SrcList and return a pointer
|
||||
** to that SrcList.
|
||||
**
|
||||
** This routine adds a specific database name, if needed, to the target when
|
||||
** forming the SrcList. This prevents a trigger in one database from
|
||||
** referring to a target in another database. An exception is when the
|
||||
** trigger is in TEMP in which case it can refer to any other database it
|
||||
** wants.
|
||||
*/
|
||||
static SrcList *targetSrcList(
|
||||
Parse *pParse, /* The parsing context */
|
||||
TriggerStep *pStep /* The trigger containing the target token */
|
||||
){
|
||||
Token sDb; /* Dummy database name token */
|
||||
int iDb; /* Index of the database to use */
|
||||
SrcList *pSrc; /* SrcList to be returned */
|
||||
|
||||
iDb = pStep->pTrig->iDb;
|
||||
if( iDb==0 || iDb>=2 ){
|
||||
assert( iDb<pParse->db->nDb );
|
||||
sDb.z = pParse->db->aDb[iDb].zName;
|
||||
sDb.n = strlen(sDb.z);
|
||||
pSrc = sqliteSrcListAppend(0, &sDb, &pStep->target);
|
||||
} else {
|
||||
pSrc = sqliteSrcListAppend(0, &pStep->target, 0);
|
||||
}
|
||||
return pSrc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate VDBE code for zero or more statements inside the body of a
|
||||
** trigger.
|
||||
*/
|
||||
static int codeTriggerProgram(
|
||||
Parse *pParse, /* The parser context */
|
||||
TriggerStep *pStepList, /* List of statements inside the trigger body */
|
||||
int orconfin /* Conflict algorithm. (OE_Abort, etc) */
|
||||
){
|
||||
TriggerStep * pTriggerStep = pStepList;
|
||||
int orconf;
|
||||
|
||||
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);
|
||||
assert(ss);
|
||||
assert(ss->pSrc);
|
||||
sqliteSelect(pParse, ss, SRT_Discard, 0, 0, 0, 0);
|
||||
sqliteSelectDelete(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);
|
||||
break;
|
||||
}
|
||||
case TK_INSERT: {
|
||||
SrcList *pSrc;
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqliteInsert(pParse, pSrc,
|
||||
sqliteExprListDup(pTriggerStep->pExprList),
|
||||
sqliteSelectDup(pTriggerStep->pSelect),
|
||||
sqliteIdListDup(pTriggerStep->pIdList), orconf);
|
||||
break;
|
||||
}
|
||||
case TK_DELETE: {
|
||||
SrcList *pSrc;
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
|
||||
pSrc = targetSrcList(pParse, pTriggerStep);
|
||||
sqliteDeleteFrom(pParse, pSrc, sqliteExprDup(pTriggerStep->pWhere));
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
pParse->nTab = saveNTab;
|
||||
pTriggerStep = pTriggerStep->pNext;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is called to code FOR EACH ROW triggers.
|
||||
**
|
||||
** When the code that this function generates is executed, the following
|
||||
** must be true:
|
||||
**
|
||||
** 1. No cursors may be open in the main database. (But newIdx and oldIdx
|
||||
** can be indices of cursors in temporary tables. See below.)
|
||||
**
|
||||
** 2. If the triggers being coded are ON INSERT or ON UPDATE triggers, then
|
||||
** a temporary vdbe cursor (index newIdx) must be open and pointing at
|
||||
** a row containing values to be substituted for new.* expressions in the
|
||||
** trigger program(s).
|
||||
**
|
||||
** 3. If the triggers being coded are ON DELETE or ON UPDATE triggers, then
|
||||
** a temporary vdbe cursor (index oldIdx) must be open and pointing at
|
||||
** a row containing values to be substituted for old.* expressions in the
|
||||
** trigger program(s).
|
||||
**
|
||||
*/
|
||||
int sqliteCodeRowTrigger(
|
||||
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 */
|
||||
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;
|
||||
|
||||
assert(op == TK_UPDATE || op == TK_INSERT || op == TK_DELETE);
|
||||
assert(tr_tm == TK_BEFORE || tr_tm == TK_AFTER );
|
||||
|
||||
assert(newIdx != -1 || oldIdx != -1);
|
||||
|
||||
pTrigger = pTab->pTrigger;
|
||||
while( pTrigger ){
|
||||
int fire_this = 0;
|
||||
|
||||
/* determine whether we should code this trigger */
|
||||
if( pTrigger->op == op && pTrigger->tr_tm == tr_tm &&
|
||||
pTrigger->foreach == TK_ROW ){
|
||||
fire_this = 1;
|
||||
pTriggerStack = pParse->trigStack;
|
||||
while( pTriggerStack ){
|
||||
if( pTriggerStack->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 ){
|
||||
int endTrigger;
|
||||
SrcList dummyTablist;
|
||||
Expr * whenExpr;
|
||||
AuthContext sContext;
|
||||
|
||||
dummyTablist.nSrc = 0;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
return 1;
|
||||
}
|
||||
sqliteExprIfFalse(pParse, whenExpr, endTrigger, 1);
|
||||
sqliteExprDelete(whenExpr);
|
||||
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ContextPush, 0, 0);
|
||||
codeTriggerProgram(pParse, pTrigger->step_list, orconf);
|
||||
sqliteVdbeAddOp(pParse->pVdbe, OP_ContextPop, 0, 0);
|
||||
|
||||
/* Pop the entry off the trigger stack */
|
||||
pParse->trigStack = pParse->trigStack->pNext;
|
||||
sqliteAuthContextPop(&sContext);
|
||||
sqliteFree(pTriggerStack);
|
||||
|
||||
sqliteVdbeResolveLabel(pParse->pVdbe, endTrigger);
|
||||
}
|
||||
pTrigger = pTrigger->pNext;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+346
-122
@@ -12,85 +12,109 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle UPDATE statements.
|
||||
**
|
||||
** $Id: update.c,v 1.17 2001/10/08 13:22:33 drh Exp $
|
||||
** $Id: update.c,v 1.70.2.1 2004/04/29 16:16:29 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Process an UPDATE statement.
|
||||
**
|
||||
** UPDATE OR IGNORE table_wxyz SET a=b, c=d WHERE e<5 AND f NOT NULL;
|
||||
** \_______/ \________/ \______/ \________________/
|
||||
* onError pTabList pChanges pWhere
|
||||
*/
|
||||
void sqliteUpdate(
|
||||
Parse *pParse, /* The parser context */
|
||||
Token *pTableName, /* The table in which we should change things */
|
||||
SrcList *pTabList, /* The table in which we should change things */
|
||||
ExprList *pChanges, /* Things to be changed */
|
||||
Expr *pWhere /* The WHERE clause. May be null */
|
||||
Expr *pWhere, /* The WHERE clause. May be null */
|
||||
int onError /* How to handle constraint errors */
|
||||
){
|
||||
int i, j; /* Loop counters */
|
||||
Table *pTab; /* The table to be updated */
|
||||
IdList *pTabList = 0; /* List containing only pTab */
|
||||
int end, addr; /* A couple of addresses in the generated code */
|
||||
int loopStart; /* VDBE instruction address of the start of the loop */
|
||||
int jumpInst; /* Addr of VDBE instruction to jump out of 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 base; /* Index of first available table cursor */
|
||||
int nIdxTotal; /* Total number of indices */
|
||||
int iCur; /* VDBE Cursor number of pTab */
|
||||
sqlite *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 openOp; /* Opcode used to open tables */
|
||||
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 iStackDepth; /* Index of memory cell holding stack depth */
|
||||
AuthContext sContext; /* The authorization context */
|
||||
|
||||
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 */
|
||||
|
||||
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;
|
||||
db = pParse->db;
|
||||
assert( pTabList->nSrc==1 );
|
||||
iStackDepth = pParse->nMem++;
|
||||
|
||||
/* Locate the table which we want to update. This table has to be
|
||||
** put in an IdList structure because some of the subroutines we
|
||||
** will be calling are designed to work with multiple tables and expect
|
||||
** an IdList* parameter instead of just a Table* parameger.
|
||||
/* Locate the table which we want to update.
|
||||
*/
|
||||
pTabList = sqliteIdListAppend(0, pTableName);
|
||||
if( pTabList==0 ) goto update_cleanup;
|
||||
for(i=0; i<pTabList->nId; i++){
|
||||
pTabList->a[i].pTab = sqliteFindTable(db, pTabList->a[i].zName);
|
||||
if( pTabList->a[i].pTab==0 ){
|
||||
sqliteSetString(&pParse->zErrMsg, "no such table: ",
|
||||
pTabList->a[i].zName, 0);
|
||||
pParse->nErr++;
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( pTabList->a[i].pTab->readOnly ){
|
||||
sqliteSetString(&pParse->zErrMsg, "table ", pTabList->a[i].zName,
|
||||
" may not be modified", 0);
|
||||
pParse->nErr++;
|
||||
pTab = sqliteSrcListLookup(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;
|
||||
isView = pTab->pSelect!=0;
|
||||
if( sqliteIsReadOnly(pParse, pTab, before_triggers) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( isView ){
|
||||
if( sqliteViewGetColumnNames(pParse, pTab) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
pTab = pTabList->a[0].pTab;
|
||||
aXRef = sqliteMalloc( sizeof(int) * pTab->nCol );
|
||||
if( aXRef==0 ) goto update_cleanup;
|
||||
for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
|
||||
|
||||
/* Resolve the column names in all the expressions in both the
|
||||
** WHERE clause and in the new values. Also find the column index
|
||||
** for each column to be updated in the pChanges array.
|
||||
/* If there are FOR EACH ROW triggers, allocate cursors for the
|
||||
** special OLD and NEW tables
|
||||
*/
|
||||
if( pWhere ){
|
||||
sqliteExprResolveInSelect(pParse, pWhere);
|
||||
if( row_triggers_exist ){
|
||||
newIdx = pParse->nTab++;
|
||||
oldIdx = pParse->nTab++;
|
||||
}
|
||||
|
||||
/* Allocate a cursors for the main database table and for all indices.
|
||||
** The index cursors might not be used, but if they are used they
|
||||
** need to occur right after the database cursor. So go ahead and
|
||||
** allocate enough space, just in case.
|
||||
*/
|
||||
pTabList->a[0].iCursor = iCur = pParse->nTab++;
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
pParse->nTab++;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
for(i=0; i<pChanges->nExpr; i++){
|
||||
sqliteExprResolveInSelect(pParse, pChanges->a[i].pExpr);
|
||||
}
|
||||
if( pWhere ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, pWhere) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
for(i=0; i<pChanges->nExpr; i++){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, pChanges->a[i].pExpr) ){
|
||||
if( sqliteExprResolveIds(pParse, pTabList, 0, pChanges->a[i].pExpr) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
if( sqliteExprCheck(pParse, pChanges->a[i].pExpr, 0, 0) ){
|
||||
@@ -98,137 +122,337 @@ void sqliteUpdate(
|
||||
}
|
||||
for(j=0; j<pTab->nCol; j++){
|
||||
if( sqliteStrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
|
||||
if( j==pTab->iPKey ){
|
||||
chngRecno = 1;
|
||||
pRecnoExpr = pChanges->a[i].pExpr;
|
||||
}
|
||||
aXRef[j] = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( j>=pTab->nCol ){
|
||||
sqliteSetString(&pParse->zErrMsg, "no such column: ",
|
||||
pChanges->a[i].zName, 0);
|
||||
pParse->nErr++;
|
||||
if( sqliteIsRowid(pChanges->a[i].zName) ){
|
||||
chngRecno = 1;
|
||||
pRecnoExpr = pChanges->a[i].pExpr;
|
||||
}else{
|
||||
sqliteErrorMsg(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,
|
||||
pTab->aCol[j].zName, db->aDb[pTab->iDb].zName);
|
||||
if( rc==SQLITE_DENY ){
|
||||
goto update_cleanup;
|
||||
}else if( rc==SQLITE_IGNORE ){
|
||||
aXRef[j] = -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Allocate memory for the array apIdx[] and fill it with pointers to every
|
||||
** index that needs to be updated. Indices only need updating if their
|
||||
** key includes one of the columns named in pChanges or if the record
|
||||
** number of the original table entry is changing.
|
||||
*/
|
||||
for(nIdx=nIdxTotal=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdxTotal++){
|
||||
if( chngRecno ){
|
||||
i = 0;
|
||||
}else {
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
if( aXRef[pIdx->aiColumn[i]]>=0 ) break;
|
||||
}
|
||||
}
|
||||
if( i<pIdx->nColumn ) nIdx++;
|
||||
}
|
||||
if( nIdxTotal>0 ){
|
||||
apIdx = sqliteMalloc( 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 ){
|
||||
i = 0;
|
||||
}else{
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
if( aXRef[pIdx->aiColumn[i]]>=0 ) break;
|
||||
}
|
||||
}
|
||||
if( i<pIdx->nColumn ){
|
||||
apIdx[nIdx++] = pIdx;
|
||||
aIdxUsed[j] = 1;
|
||||
}else{
|
||||
aIdxUsed[j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate memory for the array apIdx[] and fill it pointers to every
|
||||
** index that needs to be updated. Indices only need updating if their
|
||||
** key includes one of the columns named in pChanges.
|
||||
/* Start the view context
|
||||
*/
|
||||
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
if( aXRef[pIdx->aiColumn[i]]>=0 ) break;
|
||||
}
|
||||
if( i<pIdx->nColumn ) nIdx++;
|
||||
}
|
||||
if( nIdx>0 ){
|
||||
apIdx = sqliteMalloc( sizeof(Index*) * nIdx );
|
||||
if( apIdx==0 ) goto update_cleanup;
|
||||
}
|
||||
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
if( aXRef[pIdx->aiColumn[i]]>=0 ) break;
|
||||
}
|
||||
if( i<pIdx->nColumn ) apIdx[nIdx++] = pIdx;
|
||||
if( isView ){
|
||||
sqliteAuthContextPush(pParse, &sContext, pTab->zName);
|
||||
}
|
||||
|
||||
/* Begin generating code.
|
||||
*/
|
||||
v = sqliteGetVdbe(pParse);
|
||||
if( v==0 ) goto update_cleanup;
|
||||
if( (db->flags & SQLITE_InTrans)==0 ){
|
||||
sqliteVdbeAddOp(v, OP_Transaction, 0, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_VerifyCookie, db->schema_cookie, 0, 0, 0);
|
||||
pParse->schemaVerified = 1;
|
||||
sqliteBeginWriteOperation(pParse, 1, pTab->iDb);
|
||||
|
||||
/* If we are trying to update a view, construct that view into
|
||||
** a temporary table.
|
||||
*/
|
||||
if( isView ){
|
||||
Select *pView;
|
||||
pView = sqliteSelectDup(pTab->pSelect);
|
||||
sqliteSelect(pParse, pView, SRT_TempTable, iCur, 0, 0, 0);
|
||||
sqliteSelectDelete(pView);
|
||||
}
|
||||
|
||||
/* Begin the database scan
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_ListOpen, 0, 0, 0, 0);
|
||||
pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 1);
|
||||
pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 1, 0);
|
||||
if( pWInfo==0 ) goto update_cleanup;
|
||||
|
||||
/* Remember the index of every item to be updated.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_ListWrite, 0, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_ListWrite, 0, 0);
|
||||
|
||||
/* End the database scan loop.
|
||||
*/
|
||||
sqliteWhereEnd(pWInfo);
|
||||
|
||||
/* Rewind the list of records that need to be updated and
|
||||
** open every index that needs updating.
|
||||
/* Initialize the count of updated rows
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0, 0, 0);
|
||||
base = pParse->nTab;
|
||||
openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite;
|
||||
sqliteVdbeAddOp(v, openOp, base, pTab->tnum, 0, 0);
|
||||
for(i=0; i<nIdx; i++){
|
||||
sqliteVdbeAddOp(v, openOp, base+i+1, apIdx[i]->tnum, 0, 0);
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
|
||||
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
|
||||
}
|
||||
|
||||
/* Loop over every record that needs updating. We have to load
|
||||
** the old data for each record to be updated because some columns
|
||||
** might not change and we will need to copy the old value.
|
||||
** Also, the old data is needed to delete the old index entires.
|
||||
*/
|
||||
end = sqliteVdbeMakeLabel(v);
|
||||
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, base, 0, 0, 0);
|
||||
if( row_triggers_exist ){
|
||||
/* Create pseudo-tables for NEW and OLD
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
|
||||
|
||||
/* Delete the old indices for the current record.
|
||||
*/
|
||||
for(i=0; i<nIdx; i++){
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0, 0, 0);
|
||||
pIdx = apIdx[i];
|
||||
for(j=0; j<pIdx->nColumn; j++){
|
||||
sqliteVdbeAddOp(v, OP_Column, base, pIdx->aiColumn[j], 0, 0);
|
||||
/* The top of the update loop for when there are triggers.
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_StackDepth, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_MemStore, iStackDepth, 1);
|
||||
loopStart = sqliteVdbeAddOp(v, OP_MemLoad, iStackDepth, 0);
|
||||
sqliteVdbeAddOp(v, OP_StackReset, 0, 0);
|
||||
jumpInst = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 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);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_DeleteIdx, base+i+1, 0, 0, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
|
||||
|
||||
/* Compute a completely new data for this record.
|
||||
*/
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
j = aXRef[i];
|
||||
if( j<0 ){
|
||||
sqliteVdbeAddOp(v, OP_Column, base, i, 0, 0);
|
||||
/* Generate the OLD table
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_RowData, iCur, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
|
||||
|
||||
/* Generate the NEW table
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqliteExprCode(pParse, pRecnoExpr);
|
||||
}else{
|
||||
sqliteExprCode(pParse, pChanges->a[j].pExpr);
|
||||
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
|
||||
}
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
continue;
|
||||
}
|
||||
j = aXRef[i];
|
||||
if( j<0 ){
|
||||
sqliteVdbeAddOp(v, OP_Column, iCur, i);
|
||||
}else{
|
||||
sqliteExprCode(pParse, pChanges->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
|
||||
if( !isView ){
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
}
|
||||
|
||||
/* Fire the BEFORE and INSTEAD OF triggers
|
||||
*/
|
||||
if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, pTab,
|
||||
newIdx, oldIdx, onError, loopStart) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert new index entries that correspond to the new data
|
||||
*/
|
||||
for(i=0; i<nIdx; i++){
|
||||
sqliteVdbeAddOp(v, OP_Dup, pTab->nCol, 0, 0, 0); /* The KEY */
|
||||
pIdx = apIdx[i];
|
||||
for(j=0; j<pIdx->nColumn; j++){
|
||||
sqliteVdbeAddOp(v, OP_Dup, j+pTab->nCol-pIdx->aiColumn[j], 0, 0, 0);
|
||||
if( !isView ){
|
||||
/*
|
||||
** Open every index that needs updating. Note that if any
|
||||
** index could potentially invoke a REPLACE conflict resolution
|
||||
** 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);
|
||||
if( onError==OE_Replace ){
|
||||
openAll = 1;
|
||||
}else{
|
||||
openAll = 0;
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
if( pIdx->onError==OE_Replace ){
|
||||
openAll = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_PutIdx, base+i+1, pIdx->isUnique, 0, 0);
|
||||
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);
|
||||
assert( pParse->nTab>iCur+i+1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Loop over every record that needs updating. We have to load
|
||||
** the old data for each record to be updated because some columns
|
||||
** might not change and we will need to copy the old value.
|
||||
** 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);
|
||||
jumpInst = loopStart = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_NotExists, iCur, loopStart);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Compute new data for this record.
|
||||
*/
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( i==pTab->iPKey ){
|
||||
sqliteVdbeAddOp(v, OP_String, 0, 0);
|
||||
continue;
|
||||
}
|
||||
j = aXRef[i];
|
||||
if( j<0 ){
|
||||
sqliteVdbeAddOp(v, OP_Column, iCur, i);
|
||||
}else{
|
||||
sqliteExprCode(pParse, pChanges->a[j].pExpr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Do constraint checks
|
||||
*/
|
||||
sqliteGenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1,
|
||||
onError, loopStart);
|
||||
|
||||
/* Delete the old indices for the current record.
|
||||
*/
|
||||
sqliteGenerateRowIndexDelete(db, v, pTab, iCur, aIdxUsed);
|
||||
|
||||
/* If changing the record number, delete the old record.
|
||||
*/
|
||||
if( chngRecno ){
|
||||
sqliteVdbeAddOp(v, OP_Delete, iCur, 0);
|
||||
}
|
||||
|
||||
/* Create the new index entries and the new record.
|
||||
*/
|
||||
sqliteCompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, -1);
|
||||
}
|
||||
|
||||
/* Write the new data back into the database.
|
||||
/* Increment the row counter
|
||||
*/
|
||||
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Put, base, 0, 0, 0);
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack){
|
||||
sqliteVdbeAddOp(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( !isView ){
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
if( openAll || aIdxUsed[i] )
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur+i+1, 0);
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
pParse->nTab = iCur;
|
||||
}
|
||||
if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, pTab,
|
||||
newIdx, oldIdx, onError, loopStart) ){
|
||||
goto update_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_ListClose, 0, 0, 0, end);
|
||||
if( (db->flags & SQLITE_InTrans)==0 ){
|
||||
sqliteVdbeAddOp(v, OP_Commit, 0, 0, 0, 0);
|
||||
sqliteVdbeAddOp(v, OP_Goto, 0, loopStart);
|
||||
sqliteVdbeChangeP2(v, jumpInst, sqliteVdbeCurrentAddr(v));
|
||||
sqliteVdbeAddOp(v, OP_ListReset, 0, 0);
|
||||
|
||||
/* Close all tables if there were no FOR EACH ROW triggers */
|
||||
if( !row_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);
|
||||
}
|
||||
}
|
||||
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
|
||||
pParse->nTab = iCur;
|
||||
}else{
|
||||
sqliteVdbeAddOp(v, OP_Close, newIdx, 0);
|
||||
sqliteVdbeAddOp(v, OP_Close, oldIdx, 0);
|
||||
}
|
||||
|
||||
sqliteVdbeAddOp(v, OP_SetCounts, 0, 0);
|
||||
sqliteEndWriteOperation(pParse);
|
||||
|
||||
/*
|
||||
** Return the number of rows that were changed.
|
||||
*/
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
|
||||
sqliteVdbeOp3(v, OP_ColumnName, 0, 1, "rows updated", P3_STATIC);
|
||||
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
|
||||
}
|
||||
|
||||
update_cleanup:
|
||||
sqliteAuthContextPop(&sContext);
|
||||
sqliteFree(apIdx);
|
||||
sqliteFree(aXRef);
|
||||
sqliteIdListDelete(pTabList);
|
||||
sqliteSrcListDelete(pTabList);
|
||||
sqliteExprListDelete(pChanges);
|
||||
sqliteExprDelete(pWhere);
|
||||
return;
|
||||
|
||||
+524
-383
File diff suppressed because it is too large
Load Diff
+305
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
** 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 VACUUM command.
|
||||
**
|
||||
** Most of the code in this file may be omitted by defining the
|
||||
** SQLITE_OMIT_VACUUM macro.
|
||||
**
|
||||
** $Id: vacuum.c,v 1.13.2.5 2005/02/14 00:25:48 drh 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 */
|
||||
char **pzErrMsg; /* Write errors here */
|
||||
int rc; /* Set to non-zero on an error */
|
||||
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 *pzErrMsg and return non-zero.
|
||||
*/
|
||||
static int execsql(char **pzErrMsg, sqlite *db, const char *zSql){
|
||||
char *zErrMsg = 0;
|
||||
int rc;
|
||||
|
||||
/* printf("***** executing *****\n%s\n", zSql); */
|
||||
rc = sqlite_exec(db, zSql, 0, 0, &zErrMsg);
|
||||
if( zErrMsg ){
|
||||
sqliteSetString(pzErrMsg, zErrMsg, (char*)0);
|
||||
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;
|
||||
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);
|
||||
p->rc = execsql(p->pzErrMsg, p->dbNew, p->s2.z);
|
||||
return p->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->pzErrMsg, 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( zErrMsg ){
|
||||
sqliteSetString(p->pzErrMsg, zErrMsg, (char*)0);
|
||||
sqlite_freemem(zErrMsg);
|
||||
}
|
||||
}
|
||||
if( rc!=SQLITE_ABORT ) p->rc = rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate a random name of 20 character in length.
|
||||
*/
|
||||
static void randomName(unsigned char *zBuf){
|
||||
static const unsigned char zChars[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789";
|
||||
int i;
|
||||
sqliteRandomness(20, zBuf);
|
||||
for(i=0; i<20; i++){
|
||||
zBuf[i] = zChars[ zBuf[i]%(sizeof(zChars)-1) ];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The non-standard VACUUM command is used to clean up the database,
|
||||
** collapse free space, etc. It is modelled after the VACUUM command
|
||||
** in PostgreSQL.
|
||||
**
|
||||
** In version 1.0.x of SQLite, the VACUUM command would call
|
||||
** gdbm_reorganize() on all the database tables. But beginning
|
||||
** with 2.0.0, SQLite no longer uses GDBM so this command has
|
||||
** become a no-op.
|
||||
*/
|
||||
void sqliteVacuum(Parse *pParse, Token *pTableName){
|
||||
Vdbe *v = sqliteGetVdbe(pParse);
|
||||
sqliteVdbeAddOp(v, OP_Vacuum, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine implements the OP_Vacuum opcode of the VDBE.
|
||||
*/
|
||||
int sqliteRunVacuum(char **pzErrMsg, sqlite *db){
|
||||
#if !defined(SQLITE_OMIT_VACUUM) || 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 */
|
||||
int rc = SQLITE_OK; /* Return code from service routines */
|
||||
int i; /* Loop counter */
|
||||
char *zErrMsg; /* Error message */
|
||||
vacuumStruct sVac; /* Information passed to callbacks */
|
||||
|
||||
if( db->flags & SQLITE_InTrans ){
|
||||
sqliteSetString(pzErrMsg, "cannot VACUUM from within a transaction",
|
||||
(char*)0);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
if( db->flags & SQLITE_Interrupt ){
|
||||
return SQLITE_INTERRUPT;
|
||||
}
|
||||
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.
|
||||
*/
|
||||
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 SQLITE_OK;
|
||||
}
|
||||
nFilename = strlen(zFilename);
|
||||
zTemp = sqliteMalloc( nFilename+100 );
|
||||
if( zTemp==0 ) return SQLITE_NOMEM;
|
||||
strcpy(zTemp, zFilename);
|
||||
for(i=0; i<10; i++){
|
||||
zTemp[nFilename] = '-';
|
||||
randomName((unsigned char*)&zTemp[nFilename+1]);
|
||||
if( !sqliteOsFileExists(zTemp) ) break;
|
||||
}
|
||||
if( i>=10 ){
|
||||
sqliteSetString(pzErrMsg, "unable to create a temporary database file "
|
||||
"in the same directory as the original database", (char*)0);
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
|
||||
|
||||
dbNew = sqlite_open(zTemp, 0, &zErrMsg);
|
||||
if( dbNew==0 ){
|
||||
sqliteSetString(pzErrMsg, "unable to open a temporary database at ",
|
||||
zTemp, " - ", zErrMsg, (char*)0);
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
if( (rc = execsql(pzErrMsg, db, "BEGIN"))!=0 ) goto end_of_vacuum;
|
||||
if( (rc = execsql(pzErrMsg, dbNew, "PRAGMA synchronous=off; BEGIN"))!=0 ){
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
|
||||
sVac.dbOld = db;
|
||||
sVac.dbNew = dbNew;
|
||||
sVac.pzErrMsg = pzErrMsg;
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite_exec(db,
|
||||
"SELECT type, name, sql FROM sqlite_master "
|
||||
"WHERE sql NOT NULL AND type!='view' "
|
||||
"UNION ALL "
|
||||
"SELECT type, name, sql FROM sqlite_master "
|
||||
"WHERE sql NOT NULL AND type=='view'",
|
||||
vacuumCallback1, &sVac, &zErrMsg);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
int meta1[SQLITE_N_BTREE_META];
|
||||
int meta2[SQLITE_N_BTREE_META];
|
||||
sqliteBtreeGetMeta(db->aDb[0].pBt, meta1);
|
||||
sqliteBtreeGetMeta(dbNew->aDb[0].pBt, meta2);
|
||||
meta2[1] = meta1[1]+1;
|
||||
meta2[3] = meta1[3];
|
||||
meta2[4] = meta1[4];
|
||||
meta2[6] = meta1[6];
|
||||
rc = sqliteBtreeUpdateMeta(dbNew->aDb[0].pBt, meta2);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqliteBtreeCopyFile(db->aDb[0].pBt, dbNew->aDb[0].pBt);
|
||||
sqlite_exec(db, "COMMIT", 0, 0, 0);
|
||||
sqliteResetInternalSchema(db, 0);
|
||||
}
|
||||
|
||||
end_of_vacuum:
|
||||
if( rc && zErrMsg!=0 ){
|
||||
sqliteSetString(pzErrMsg, "unable to vacuum database - ",
|
||||
zErrMsg, (char*)0);
|
||||
}
|
||||
sqlite_exec(db, "ROLLBACK", 0, 0, 0);
|
||||
if( (dbNew && (dbNew->flags & SQLITE_Interrupt))
|
||||
|| (db->flags & SQLITE_Interrupt) ){
|
||||
rc = SQLITE_INTERRUPT;
|
||||
}
|
||||
if( dbNew ) sqlite_close(dbNew);
|
||||
sqliteOsDelete(zTemp);
|
||||
sqliteFree(zTemp);
|
||||
sqliteFree(sVac.s1.z);
|
||||
sqliteFree(sVac.s2.z);
|
||||
if( zErrMsg ) sqlite_freemem(zErrMsg);
|
||||
if( rc==SQLITE_ABORT && sVac.rc!=SQLITE_INTERRUPT ) sVac.rc = SQLITE_ERROR;
|
||||
return sVac.rc;
|
||||
#endif
|
||||
}
|
||||
+3278
-2315
File diff suppressed because it is too large
Load Diff
+44
-141
@@ -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.26 2001/10/08 13:22:33 drh Exp $
|
||||
** $Id: vdbe.h,v 1.71 2004/02/22 20:05:02 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_VDBE_H_
|
||||
#define _SQLITE_VDBE_H_
|
||||
@@ -34,14 +34,38 @@ 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 p3dyn; /* True if p3 is malloced. False if it is static */
|
||||
int p3type; /* P3_STATIC, P3_DYNAMIC or P3_POINTER */
|
||||
#ifdef VDBE_PROFILE
|
||||
int cnt; /* Number of times this instruction was executed */
|
||||
long long cycles; /* Total time spend executing this instruction */
|
||||
#endif
|
||||
};
|
||||
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 */
|
||||
|
||||
/*
|
||||
** The following macro converts a relative address in the p2 field
|
||||
** of a VdbeOp structure into a negative number so that
|
||||
@@ -51,138 +75,10 @@ typedef struct VdbeOp VdbeOp;
|
||||
#define ADDR(X) (-1-(X))
|
||||
|
||||
/*
|
||||
** These are the available opcodes.
|
||||
**
|
||||
** If any of the values changes or if opcodes are added or removed,
|
||||
** be sure to also update the zOpName[] array in sqliteVdbe.c to
|
||||
** mirror the change.
|
||||
**
|
||||
** The source tree contains an AWK script named renumberOps.awk that
|
||||
** can be used to renumber these opcodes when new opcodes are inserted.
|
||||
** The makefile scans the vdbe.c source file and creates the "opcodes.h"
|
||||
** header file that defines a number for each opcode used by the VDBE.
|
||||
*/
|
||||
#define OP_Transaction 1
|
||||
#define OP_Commit 2
|
||||
#define OP_Rollback 3
|
||||
|
||||
#define OP_ReadCookie 4
|
||||
#define OP_SetCookie 5
|
||||
#define OP_VerifyCookie 6
|
||||
|
||||
#define OP_Open 7
|
||||
#define OP_OpenTemp 8
|
||||
#define OP_OpenWrite 9
|
||||
#define OP_OpenAux 10
|
||||
#define OP_OpenWrAux 11
|
||||
#define OP_Close 12
|
||||
#define OP_MoveTo 13
|
||||
#define OP_Fcnt 14
|
||||
#define OP_NewRecno 15
|
||||
#define OP_Put 16
|
||||
#define OP_Distinct 17
|
||||
#define OP_Found 18
|
||||
#define OP_NotFound 19
|
||||
#define OP_Delete 20
|
||||
#define OP_Column 21
|
||||
#define OP_KeyAsData 22
|
||||
#define OP_Recno 23
|
||||
#define OP_FullKey 24
|
||||
#define OP_Rewind 25
|
||||
#define OP_Next 26
|
||||
|
||||
#define OP_Destroy 27
|
||||
#define OP_Clear 28
|
||||
#define OP_CreateIndex 29
|
||||
#define OP_CreateTable 30
|
||||
#define OP_Reorganize 31
|
||||
|
||||
#define OP_BeginIdx 32
|
||||
#define OP_NextIdx 33
|
||||
#define OP_PutIdx 34
|
||||
#define OP_DeleteIdx 35
|
||||
|
||||
#define OP_MemLoad 36
|
||||
#define OP_MemStore 37
|
||||
|
||||
#define OP_ListOpen 38
|
||||
#define OP_ListWrite 39
|
||||
#define OP_ListRewind 40
|
||||
#define OP_ListRead 41
|
||||
#define OP_ListClose 42
|
||||
|
||||
#define OP_SortOpen 43
|
||||
#define OP_SortPut 44
|
||||
#define OP_SortMakeRec 45
|
||||
#define OP_SortMakeKey 46
|
||||
#define OP_Sort 47
|
||||
#define OP_SortNext 48
|
||||
#define OP_SortKey 49
|
||||
#define OP_SortCallback 50
|
||||
#define OP_SortClose 51
|
||||
|
||||
#define OP_FileOpen 52
|
||||
#define OP_FileRead 53
|
||||
#define OP_FileColumn 54
|
||||
#define OP_FileClose 55
|
||||
|
||||
#define OP_AggReset 56
|
||||
#define OP_AggFocus 57
|
||||
#define OP_AggIncr 58
|
||||
#define OP_AggNext 59
|
||||
#define OP_AggSet 60
|
||||
#define OP_AggGet 61
|
||||
|
||||
#define OP_SetInsert 62
|
||||
#define OP_SetFound 63
|
||||
#define OP_SetNotFound 64
|
||||
#define OP_SetClear 65
|
||||
|
||||
#define OP_MakeRecord 66
|
||||
#define OP_MakeKey 67
|
||||
#define OP_MakeIdxKey 68
|
||||
|
||||
#define OP_Goto 69
|
||||
#define OP_If 70
|
||||
#define OP_Halt 71
|
||||
|
||||
#define OP_ColumnCount 72
|
||||
#define OP_ColumnName 73
|
||||
#define OP_Callback 74
|
||||
|
||||
#define OP_Integer 75
|
||||
#define OP_String 76
|
||||
#define OP_Null 77
|
||||
#define OP_Pop 78
|
||||
#define OP_Dup 79
|
||||
#define OP_Pull 80
|
||||
|
||||
#define OP_Add 81
|
||||
#define OP_AddImm 82
|
||||
#define OP_Subtract 83
|
||||
#define OP_Multiply 84
|
||||
#define OP_Divide 85
|
||||
#define OP_Min 86
|
||||
#define OP_Max 87
|
||||
#define OP_Like 88
|
||||
#define OP_Glob 89
|
||||
#define OP_Eq 90
|
||||
#define OP_Ne 91
|
||||
#define OP_Lt 92
|
||||
#define OP_Le 93
|
||||
#define OP_Gt 94
|
||||
#define OP_Ge 95
|
||||
#define OP_IsNull 96
|
||||
#define OP_NotNull 97
|
||||
#define OP_Negative 98
|
||||
#define OP_And 99
|
||||
#define OP_Or 100
|
||||
#define OP_Not 101
|
||||
#define OP_Concat 102
|
||||
#define OP_Noop 103
|
||||
|
||||
#define OP_Strlen 104
|
||||
#define OP_Substr 105
|
||||
|
||||
#define OP_MAX 105
|
||||
#include "opcodes.h"
|
||||
|
||||
/*
|
||||
** Prototypes for the VDBE interface. See comments on the implementation
|
||||
@@ -190,20 +86,27 @@ typedef struct VdbeOp VdbeOp;
|
||||
*/
|
||||
Vdbe *sqliteVdbeCreate(sqlite*);
|
||||
void sqliteVdbeCreateCallback(Vdbe*, int*);
|
||||
int sqliteVdbeAddOp(Vdbe*,int,int,int,const char*,int);
|
||||
int sqliteVdbeAddOpList(Vdbe*, int nOp, VdbeOp const *aOp);
|
||||
int sqliteVdbeAddOp(Vdbe*,int,int,int);
|
||||
int sqliteVdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
|
||||
int sqliteVdbeCode(Vdbe*,...);
|
||||
int sqliteVdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
|
||||
void sqliteVdbeChangeP1(Vdbe*, int addr, int P1);
|
||||
void sqliteVdbeChangeP3(Vdbe*, int addr, char *zP1, int N);
|
||||
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*);
|
||||
int sqliteVdbeOpcode(const char *zName);
|
||||
int sqliteVdbeExec(Vdbe*,sqlite_callback,void*,char**,void*,
|
||||
int(*)(void*,const char*,int));
|
||||
int sqliteVdbeList(Vdbe*,sqlite_callback,void*,char**);
|
||||
void sqliteVdbeMakeReady(Vdbe*,int,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 **);
|
||||
int sqliteVdbeSetVariables(Vdbe*,int,const char**);
|
||||
|
||||
#endif
|
||||
|
||||
+303
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
** 2003 September 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 is the header file for information that is private to the
|
||||
** VDBE. This information used to all be at the top of the single
|
||||
** source code file "vdbe.c". When that file became too big (over
|
||||
** 6000 lines long) it was split up into several smaller files and
|
||||
** this header information was factored out.
|
||||
*/
|
||||
|
||||
/*
|
||||
** When converting from the native format to the key format and back
|
||||
** again, in addition to changing the byte order we invert the high-order
|
||||
** bit of the most significant byte. This causes negative numbers to
|
||||
** sort before positive numbers in the memcmp() function.
|
||||
*/
|
||||
#define keyToInt(X) (sqliteVdbeByteSwap(X) ^ 0x80000000)
|
||||
#define intToKey(X) (sqliteVdbeByteSwap((X) ^ 0x80000000))
|
||||
|
||||
/*
|
||||
** 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.
|
||||
*/
|
||||
extern char *sqliteOpcodeNames[];
|
||||
|
||||
/*
|
||||
** SQL is translated into a sequence of instructions to be
|
||||
** executed by a virtual machine. Each instruction is an instance
|
||||
** of the following structure.
|
||||
*/
|
||||
typedef struct VdbeOp Op;
|
||||
|
||||
/*
|
||||
** Boolean values
|
||||
*/
|
||||
typedef unsigned char Bool;
|
||||
|
||||
/*
|
||||
** A cursor is a pointer into a single BTree within a database file.
|
||||
** The cursor can seek to a BTree entry with a particular key, or
|
||||
** loop over all entries of the Btree. You can also insert new BTree
|
||||
** entries or retrieve the key or data from the entry that the cursor
|
||||
** is currently pointing to.
|
||||
**
|
||||
** Every cursor that the virtual machine has open is represented by an
|
||||
** instance of the following structure.
|
||||
**
|
||||
** If the Cursor.isTriggerRow flag is set it means that this cursor is
|
||||
** really a single row that represents the NEW or OLD pseudo-table of
|
||||
** a row trigger. The data for the row is stored in Cursor.pData and
|
||||
** the rowid is in Cursor.iKey.
|
||||
*/
|
||||
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 */
|
||||
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 sqliteBtreeMoveto() is needed */
|
||||
int movetoTarget; /* Argument to the deferred sqliteBtreeMoveto() */
|
||||
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 */
|
||||
};
|
||||
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
|
||||
** For Strings.
|
||||
*/
|
||||
#define NBFS 32
|
||||
|
||||
/*
|
||||
** A single level of the stack or a single memory cell
|
||||
** is an instance of the following structure.
|
||||
*/
|
||||
struct Mem {
|
||||
int i; /* Integer value */
|
||||
int n; /* Number of characters in string value, including '\0' */
|
||||
int flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
|
||||
double r; /* Real value */
|
||||
char *z; /* String value */
|
||||
char zShort[NBFS]; /* Space for short strings */
|
||||
};
|
||||
typedef struct Mem Mem;
|
||||
|
||||
/*
|
||||
** Allowed values for Mem.flags
|
||||
*/
|
||||
#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_Dyn 0x0010 /* Need to call sqliteFree() on Mem.z */
|
||||
#define MEM_Static 0x0020 /* Mem.z points to a static string */
|
||||
#define MEM_Ephem 0x0040 /* Mem.z points to an ephemeral string */
|
||||
#define MEM_Short 0x0080 /* Mem.z points to Mem.zShort */
|
||||
|
||||
/* The following MEM_ value appears only in AggElem.aMem.s.flag fields.
|
||||
** It indicates that the corresponding AggElem.aMem.z points to a
|
||||
** aggregate function context that needs to be finalized.
|
||||
*/
|
||||
#define MEM_AggCtx 0x0100 /* Mem.z points to an agg function context */
|
||||
|
||||
/*
|
||||
** The "context" argument for a installable function. A pointer to an
|
||||
** instance of this structure is the first argument to the routines used
|
||||
** implement the SQL functions.
|
||||
**
|
||||
** There is a typedef for this structure in sqlite.h. So all routines,
|
||||
** even the public interface to SQLite, can use a pointer to this structure.
|
||||
** 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
|
||||
** (Mem) which are only defined there.
|
||||
*/
|
||||
struct sqlite_func {
|
||||
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
|
||||
Mem s; /* The return value is stored here */
|
||||
void *pAgg; /* Aggregate context */
|
||||
u8 isError; /* Set to true for an error */
|
||||
u8 isStep; /* Current in the step function */
|
||||
int cnt; /* Number of times that the step function has been called */
|
||||
};
|
||||
|
||||
/*
|
||||
** 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 */
|
||||
};
|
||||
|
||||
/*
|
||||
** A Set structure is used for quick testing to see if a value
|
||||
** is part of a small set. Sets are used to implement code like
|
||||
** this:
|
||||
** x.y IN ('hi','hoo','hum')
|
||||
*/
|
||||
typedef struct Set Set;
|
||||
struct Set {
|
||||
Hash hash; /* A set is just a hash table */
|
||||
HashElem *prev; /* Previously accessed hash elemen */
|
||||
};
|
||||
|
||||
/*
|
||||
** 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.
|
||||
*/
|
||||
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 */
|
||||
};
|
||||
|
||||
/*
|
||||
** A Context stores the last insert rowid, the last statement change count,
|
||||
** and the current statement change count (i.e. changes since last statement).
|
||||
** Elements of Context structure type make up the ContextStack, which is
|
||||
** updated by the ContextPush and ContextPop opcodes (used by triggers)
|
||||
*/
|
||||
typedef struct Context Context;
|
||||
struct Context {
|
||||
int lastRowid; /* Last insert rowid (from db->lastRowid) */
|
||||
int lsChange; /* Last statement change count (from db->lsChange) */
|
||||
int csChange; /* Current statement change count (from db->csChange) */
|
||||
};
|
||||
|
||||
/*
|
||||
** 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()
|
||||
** is really a pointer to an instance of this structure.
|
||||
*/
|
||||
struct Vdbe {
|
||||
sqlite *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 */
|
||||
int nOpAlloc; /* Number of slots allocated for aOp[] */
|
||||
Op *aOp; /* Space to hold the virtual machine's program */
|
||||
int nLabel; /* Number of labels used */
|
||||
int nLabelAlloc; /* Number of slots allocated in aLabel[] */
|
||||
int *aLabel; /* Space to hold the labels */
|
||||
Mem *aStack; /* The operand stack, except string values */
|
||||
Mem *pTos; /* Top entry in the operand stack */
|
||||
char **zArgv; /* Text values used by the callback */
|
||||
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 */
|
||||
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 */
|
||||
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 popStack; /* Pop the stack this much on entry to VdbeExec() */
|
||||
char *zErrMsg; /* Error message written here */
|
||||
u8 explain; /* True if EXPLAIN present on SQL command */
|
||||
};
|
||||
|
||||
/*
|
||||
** The following are allowed values for Vdbe.magic
|
||||
*/
|
||||
#define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */
|
||||
#define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */
|
||||
#define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */
|
||||
#define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */
|
||||
|
||||
/*
|
||||
** Function prototypes
|
||||
*/
|
||||
void sqliteVdbeCleanupCursor(Cursor*);
|
||||
void sqliteVdbeSorterReset(Vdbe*);
|
||||
void sqliteVdbeAggReset(Agg*);
|
||||
void sqliteVdbeKeylistFree(Keylist*);
|
||||
void sqliteVdbePopStack(Vdbe*,int);
|
||||
int sqliteVdbeCursorMoveto(Cursor*);
|
||||
int sqliteVdbeByteSwap(int);
|
||||
#if !defined(NDEBUG) || defined(VDBE_PROFILE)
|
||||
void sqliteVdbePrintOp(FILE*, int, Op*);
|
||||
#endif
|
||||
+1061
File diff suppressed because it is too large
Load Diff
+984
-194
File diff suppressed because it is too large
Load Diff
+42
-5
@@ -10,7 +10,7 @@
|
||||
#***********************************************************************
|
||||
# This file runs all tests.
|
||||
#
|
||||
# $Id: all.test,v 1.10 2001/09/16 00:13:28 drh Exp $
|
||||
# $Id: all.test,v 1.19 2003/02/16 22:21:33 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -20,9 +20,27 @@ proc finish_test {} {memleak_check}
|
||||
if {[file exists ./sqlite_test_count]} {
|
||||
set COUNT [exec cat ./sqlite_test_count]
|
||||
} else {
|
||||
set COUNT 3
|
||||
set COUNT 4
|
||||
}
|
||||
|
||||
if {[llength $argv]>0} {
|
||||
foreach {name value} $argv {
|
||||
switch -- $name {
|
||||
-count {
|
||||
set COUNT $value
|
||||
}
|
||||
-quick {
|
||||
set ISQUICK $value
|
||||
}
|
||||
default {
|
||||
puts stderr "Unknown option: $name"
|
||||
exit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
set argv {}
|
||||
|
||||
# LeakList will hold a list of the number of unfreed mallocs after
|
||||
# each round of the test. This number should be constant. If it
|
||||
# grows, it may mean there is a memory leak in the library.
|
||||
@@ -33,13 +51,28 @@ set EXCLUDE {
|
||||
all.test
|
||||
quick.test
|
||||
malloc.test
|
||||
misuse.test
|
||||
memleak.test
|
||||
}
|
||||
# btree2.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 {
|
||||
catch {unset ::SETUP_SQL}
|
||||
}
|
||||
foreach testfile [lsort -dictionary [glob $testdir/*.test]] {
|
||||
set tail [file tail $testfile]
|
||||
if {[lsearch -exact $EXCLUDE $tail]>=0} continue
|
||||
source $testfile
|
||||
catch {db close}
|
||||
if {$sqlite_open_file_count>0} {
|
||||
puts "$tail did not close all files: $sqlite_open_file_count"
|
||||
incr nErr
|
||||
lappend ::failList $tail
|
||||
}
|
||||
}
|
||||
if {[info exists Leak]} {
|
||||
lappend LeakList $Leak
|
||||
@@ -65,8 +98,12 @@ if {$LeakList!=""} {
|
||||
puts " Ok"
|
||||
}
|
||||
|
||||
if {[file readable $testdir/malloc.test]} {
|
||||
source $testdir/malloc.test
|
||||
}
|
||||
# Run the malloc tests and the misuse test after memory leak detection.
|
||||
# Both tests leak memory.
|
||||
#
|
||||
catch {source $testdir/misuse.test}
|
||||
catch {source $testdir/malloc.test}
|
||||
|
||||
catch {db close}
|
||||
set sqlite_open_file_count 0
|
||||
really_finish_test
|
||||
|
||||
@@ -0,0 +1,586 @@
|
||||
# 2003 April 4
|
||||
#
|
||||
# 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 related functionality.
|
||||
#
|
||||
# $Id: attach.test,v 1.13 2004/02/14 01:39:50 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
for {set i 2} {$i<=15} {incr i} {
|
||||
file delete -force test$i.db
|
||||
file delete -force test$i.db-journal
|
||||
}
|
||||
|
||||
do_test attach-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b);
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
INSERT INTO t1 VALUES(3,4);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 2 3 4}
|
||||
do_test attach-1.2 {
|
||||
sqlite db2 test2.db
|
||||
execsql {
|
||||
CREATE TABLE t2(x,y);
|
||||
INSERT INTO t2 VALUES(1,'x');
|
||||
INSERT INTO t2 VALUES(2,'y');
|
||||
SELECT * FROM t2;
|
||||
} db2
|
||||
} {1 x 2 y}
|
||||
do_test attach-1.3 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS two;
|
||||
SELECT * FROM two.t2;
|
||||
}
|
||||
} {1 x 2 y}
|
||||
do_test attach-1.4 {
|
||||
execsql {
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 x 2 y}
|
||||
do_test attach-1.5 {
|
||||
execsql {
|
||||
DETACH DATABASE two;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 2 3 4}
|
||||
do_test attach-1.6 {
|
||||
catchsql {
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {no such table: t2}}
|
||||
do_test attach-1.7 {
|
||||
catchsql {
|
||||
SELECT * FROM two.t2;
|
||||
}
|
||||
} {1 {no such table: two.t2}}
|
||||
do_test attach-1.8 {
|
||||
catchsql {
|
||||
ATTACH DATABASE 'test3.db' AS three;
|
||||
}
|
||||
} {1 {cannot attach empty database: three}}
|
||||
do_test attach-1.9 {
|
||||
catchsql {
|
||||
SELECT * FROM three.sqlite_master;
|
||||
}
|
||||
} {1 {no such table: three.sqlite_master}}
|
||||
do_test attach-1.10 {
|
||||
catchsql {
|
||||
DETACH DATABASE three;
|
||||
}
|
||||
} {1 {no such database: three}}
|
||||
do_test attach-1.11 {
|
||||
execsql {
|
||||
ATTACH 'test.db' AS db2;
|
||||
ATTACH 'test.db' AS db3;
|
||||
ATTACH 'test.db' AS db4;
|
||||
ATTACH 'test.db' AS db5;
|
||||
ATTACH 'test.db' AS db6;
|
||||
ATTACH 'test.db' AS db7;
|
||||
ATTACH 'test.db' AS db8;
|
||||
ATTACH 'test.db' AS db9;
|
||||
}
|
||||
} {}
|
||||
proc db_list {db} {
|
||||
set list {}
|
||||
foreach {idx name file} [execsql {PRAGMA database_list} $db] {
|
||||
lappend list $idx $name
|
||||
}
|
||||
return $list
|
||||
}
|
||||
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}
|
||||
do_test attach-1.12 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as db2;
|
||||
}
|
||||
} {1 {database db2 is already in use}}
|
||||
do_test attach-1.13 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as db5;
|
||||
}
|
||||
} {1 {database db5 is already in use}}
|
||||
do_test attach-1.14 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as db9;
|
||||
}
|
||||
} {1 {database db9 is already in use}}
|
||||
do_test attach-1.15 {
|
||||
catchsql {
|
||||
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}}
|
||||
do_test attach-1.17 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as MAIN;
|
||||
}
|
||||
} {1 {database MAIN is already in use}}
|
||||
do_test attach-1.18 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as db10;
|
||||
ATTACH 'test.db' as db11;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach-1.19 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as db12;
|
||||
}
|
||||
} {1 {too many attached databases - max 10}}
|
||||
do_test attach-1.20.1 {
|
||||
execsql {
|
||||
DETACH db5;
|
||||
}
|
||||
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
|
||||
do_test attach-1.21 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as db12;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach-1.22 {
|
||||
catchsql {
|
||||
ATTACH 'test.db' as db13;
|
||||
}
|
||||
} {1 {too many attached databases - max 10}}
|
||||
do_test attach-1.23 {
|
||||
catchsql {
|
||||
DETACH db14;
|
||||
}
|
||||
} {1 {no such database: db14}}
|
||||
do_test attach-1.24 {
|
||||
catchsql {
|
||||
DETACH db12;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach-1.25 {
|
||||
catchsql {
|
||||
DETACH db12;
|
||||
}
|
||||
} {1 {no such database: db12}}
|
||||
do_test attach-1.26 {
|
||||
catchsql {
|
||||
DETACH main;
|
||||
}
|
||||
} {1 {cannot detach database main}}
|
||||
do_test attach-1.27 {
|
||||
catchsql {
|
||||
DETACH Temp;
|
||||
}
|
||||
} {1 {cannot detach database Temp}}
|
||||
do_test attach-1.28 {
|
||||
catchsql {
|
||||
DETACH db11;
|
||||
DETACH db10;
|
||||
DETACH db9;
|
||||
DETACH db8;
|
||||
DETACH db7;
|
||||
DETACH db6;
|
||||
DETACH db4;
|
||||
DETACH db3;
|
||||
DETACH db2;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach-1.29 {
|
||||
db_list db
|
||||
} {0 main 1 temp}
|
||||
|
||||
do_test attach-2.1 {
|
||||
execsql {
|
||||
CREATE TABLE tx(x1,x2,y1,y2);
|
||||
CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
|
||||
INSERT INTO tx(x1,x2,y1,y2) VALUES(OLD.x,NEW.x,OLD.y,NEW.y);
|
||||
END;
|
||||
SELECT * FROM tx;
|
||||
} db2;
|
||||
} {}
|
||||
do_test attach-2.2 {
|
||||
execsql {
|
||||
UPDATE t2 SET x=x+10;
|
||||
SELECT * FROM tx;
|
||||
} db2;
|
||||
} {1 11 x x 2 12 y y}
|
||||
do_test attach-2.3 {
|
||||
execsql {
|
||||
CREATE TABLE tx(x1,x2,y1,y2);
|
||||
SELECT * FROM tx;
|
||||
}
|
||||
} {}
|
||||
do_test attach-2.4 {
|
||||
execsql {
|
||||
ATTACH 'test2.db' AS db2;
|
||||
}
|
||||
} {}
|
||||
do_test attach-2.5 {
|
||||
execsql {
|
||||
UPDATE db2.t2 SET x=x+10;
|
||||
SELECT * FROM db2.tx;
|
||||
}
|
||||
} {1 11 x x 2 12 y y 11 21 x x 12 22 y y}
|
||||
do_test attach-2.6 {
|
||||
execsql {
|
||||
SELECT * FROM main.tx;
|
||||
}
|
||||
} {}
|
||||
do_test attach-2.7 {
|
||||
execsql {
|
||||
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}
|
||||
do_test attach-2.9 {
|
||||
execsql {
|
||||
CREATE INDEX i2 ON t2(x);
|
||||
SELECT * FROM t2 WHERE x>5;
|
||||
} db2
|
||||
} {21 x 22 y}
|
||||
do_test attach-2.10 {
|
||||
execsql {
|
||||
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;
|
||||
# }
|
||||
#} {1 {database schema has changed}}
|
||||
do_test attach-2.12 {
|
||||
db_list db
|
||||
} {0 main 1 temp 2 db2}
|
||||
do_test attach-2.13 {
|
||||
catchsql {
|
||||
SELECT * FROM t2 WHERE x>5;
|
||||
}
|
||||
} {0 {21 x 22 y}}
|
||||
do_test attach-2.14 {
|
||||
execsql {
|
||||
SELECT type, name, tbl_name FROM sqlite_master;
|
||||
}
|
||||
} {table t1 t1 table tx tx}
|
||||
do_test attach-2.15 {
|
||||
execsql {
|
||||
SELECT type, name, tbl_name FROM db2.sqlite_master;
|
||||
}
|
||||
} {table t2 t2 table tx tx trigger r1 t2 index i2 t2}
|
||||
do_test attach-2.16 {
|
||||
db close
|
||||
sqlite 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}
|
||||
|
||||
do_test attach-3.1 {
|
||||
db close
|
||||
db2 close
|
||||
sqlite db test.db
|
||||
sqlite db2 test2.db
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 2 3 4}
|
||||
do_test attach-3.2 {
|
||||
catchsql {
|
||||
SELECT * FROM t2
|
||||
}
|
||||
} {1 {no such table: t2}}
|
||||
do_test attach-3.3 {
|
||||
catchsql {
|
||||
ATTACH DATABASE 'test2.db' AS db2;
|
||||
SELECT * FROM t2
|
||||
}
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# Even though main has a transaction, test2.db should not be locked.
|
||||
do_test attach-3.4 {
|
||||
execsql BEGIN
|
||||
catchsql {
|
||||
SELECT * FROM t2;
|
||||
} db2;
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# Reading from db2 should not lock test2.db
|
||||
do_test attach-3.5 {
|
||||
execsql {SELECT * FROM t2}
|
||||
catchsql {
|
||||
SELECT * FROM t2;
|
||||
} db2;
|
||||
} {0 {21 x 22 y}}
|
||||
|
||||
# Making a change to db2 causes test2.ddb to become locked.
|
||||
do_test attach-3.6 {
|
||||
execsql {
|
||||
UPDATE t2 SET x=x+1 WHERE x=50;
|
||||
}
|
||||
catchsql {
|
||||
SELECT * FROM t2;
|
||||
} db2;
|
||||
} {1 {database is locked}}
|
||||
|
||||
do_test attach-3.7 {
|
||||
execsql ROLLBACK
|
||||
execsql {SELECT * FROM t2} db2
|
||||
} {21 x 22 y}
|
||||
do_test attach-3.8 {
|
||||
execsql BEGIN
|
||||
execsql BEGIN db2
|
||||
catchsql {SELECT * FROM t2}
|
||||
} {1 {database is locked}}
|
||||
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}
|
||||
do_test attach-3.13 {
|
||||
catchsql {UPDATE t2 SET x=x+1 WHERE x=50}
|
||||
} {1 {database is locked}}
|
||||
do_test attach-3.14 {
|
||||
# Unable to reinitialize the schema tables because the aux database
|
||||
# is still locked.
|
||||
catchsql {SELECT * FROM t1}
|
||||
} {1 {database is locked}}
|
||||
do_test attach-3.15 {
|
||||
execsql COMMIT db2
|
||||
execsql {SELECT * FROM t1}
|
||||
} {1 2 3 4}
|
||||
|
||||
# Ticket #323
|
||||
do_test attach-4.1 {
|
||||
execsql {DETACH db2}
|
||||
db2 close
|
||||
sqlite db2 test2.db
|
||||
execsql {
|
||||
CREATE TABLE t3(x,y);
|
||||
CREATE UNIQUE INDEX t3i1 ON t3(x);
|
||||
INSERT INTO t3 VALUES(1,2);
|
||||
SELECT * FROM t3;
|
||||
} db2;
|
||||
} {1 2}
|
||||
do_test attach-4.2 {
|
||||
execsql {
|
||||
CREATE TABLE t3(a,b);
|
||||
CREATE UNIQUE INDEX t3i1b ON t3(a);
|
||||
INSERT INTO t3 VALUES(9,10);
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {9 10}
|
||||
do_test attach-4.3 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS db2;
|
||||
SELECT * FROM db2.t3;
|
||||
}
|
||||
} {1 2}
|
||||
do_test attach-4.4 {
|
||||
execsql {
|
||||
SELECT * FROM main.t3;
|
||||
}
|
||||
} {9 10}
|
||||
do_test attach-4.5 {
|
||||
execsql {
|
||||
INSERT INTO db2.t3 VALUES(9,10);
|
||||
SELECT * FROM db2.t3;
|
||||
}
|
||||
} {1 2 9 10}
|
||||
do_test attach-4.6 {
|
||||
execsql {
|
||||
DETACH db2;
|
||||
}
|
||||
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}
|
||||
do_test attach-4.8 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS db2;
|
||||
INSERT INTO db2.t3 VALUES(13,14);
|
||||
SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4;
|
||||
}
|
||||
} {db2.6 db2.13 main.11}
|
||||
do_test attach-4.9 {
|
||||
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}
|
||||
do_test attach-4.10 {
|
||||
execsql {
|
||||
DETACH DATABASE db2;
|
||||
}
|
||||
execsql {
|
||||
CREATE VIEW v3 AS SELECT x*100+y FROM t3;
|
||||
SELECT * FROM v3;
|
||||
} db2
|
||||
} {102 910 607 1314}
|
||||
do_test attach-4.11 {
|
||||
execsql {
|
||||
CREATE VIEW v3 AS SELECT a*100+b FROM t3;
|
||||
SELECT * FROM v3;
|
||||
}
|
||||
} {910 1112 1516}
|
||||
do_test attach-4.12 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS db2;
|
||||
SELECT * FROM db2.v3;
|
||||
}
|
||||
} {102 910 607 1314}
|
||||
do_test attach-4.13 {
|
||||
execsql {
|
||||
SELECT * FROM main.v3;
|
||||
}
|
||||
} {910 1112 1516}
|
||||
|
||||
# Tests for the sqliteFix...() routines in attach.c
|
||||
#
|
||||
do_test attach-5.1 {
|
||||
db close
|
||||
sqlite db test.db
|
||||
db2 close
|
||||
file delete -force test2.db
|
||||
sqlite 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}}
|
||||
do_test attach-5.2 {
|
||||
catchsql {
|
||||
CREATE TABLE t5(x,y);
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT 'no-op';
|
||||
END;
|
||||
} db2
|
||||
} {0 {}}
|
||||
do_test attach-5.3 {
|
||||
catchsql {
|
||||
DROP TRIGGER r5;
|
||||
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
|
||||
SELECT 'no-op' FROM orig.t1;
|
||||
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}}
|
||||
|
||||
# Check to make sure we get a sensible error if unable to open
|
||||
# the file that we are trying to attach.
|
||||
#
|
||||
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
|
||||
if {$tcl_platform(platform)=="unix"} {
|
||||
do_test attach-6.2 {
|
||||
sqlite dbx cannot-read
|
||||
dbx eval {CREATE TABLE t1(a,b,c)}
|
||||
dbx close
|
||||
file attributes cannot-read -permission 0000
|
||||
catchsql {
|
||||
ATTACH DATABASE 'cannot-read' AS noread;
|
||||
}
|
||||
} {1 {unable to open database: cannot-read}}
|
||||
file delete -force cannot-read
|
||||
}
|
||||
|
||||
for {set i 2} {$i<=15} {incr i} {
|
||||
catch {db$i close}
|
||||
}
|
||||
file delete -force test2.db
|
||||
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,146 @@
|
||||
# 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 related functionality.
|
||||
#
|
||||
# $Id: attach2.test,v 1.5 2004/02/12 15:31:22 drh Exp $
|
||||
#
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Ticket #354
|
||||
#
|
||||
do_test attach2-1.1 {
|
||||
db eval {
|
||||
CREATE TABLE t1(a,b);
|
||||
CREATE INDEX x1 ON t1(a);
|
||||
}
|
||||
file delete -force test2.db
|
||||
file delete -force test2.db-journal
|
||||
sqlite db2 test2.db
|
||||
db2 eval {
|
||||
CREATE TABLE t1(a,b);
|
||||
CREATE INDEX x1 ON t1(a);
|
||||
}
|
||||
catchsql {
|
||||
ATTACH 'test2.db' AS t2;
|
||||
}
|
||||
} {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. Should get an error.
|
||||
db2 eval {BEGIN}
|
||||
catchsql {
|
||||
ATTACH 'test2.db' AS t2;
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
do_test attach2-2.2 {
|
||||
# make sure test2.db did not get attached.
|
||||
db_list db
|
||||
} {0 main 1 temp}
|
||||
do_test attach2-2.3 {
|
||||
# unlock test2.db and try to attach again. should work this time.
|
||||
db2 eval {COMMIT}
|
||||
catchsql {
|
||||
ATTACH 'test2.db' AS t2;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach2-2.4 {
|
||||
db_list db
|
||||
} {0 main 1 temp 2 t2}
|
||||
do_test attach2-2.5 {
|
||||
catchsql {
|
||||
SELECT name FROM t2.sqlite_master;
|
||||
}
|
||||
} {0 {t1 x1}}
|
||||
do_test attach2-2.6 {
|
||||
# lock test2.db and try to read from it. should get an error.
|
||||
db2 eval BEGIN
|
||||
catchsql {
|
||||
SELECT name FROM t2.sqlite_master;
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
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.
|
||||
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 usingi the non-callback API
|
||||
#
|
||||
do_test attach2-3.1 {
|
||||
db close
|
||||
set DB [sqlite db test.db]
|
||||
set rc [catch {sqlite_compile $DB "ATTACH 'test2.db' AS t2" TAIL} VM]
|
||||
if {$rc} {lappend rc $VM}
|
||||
sqlite_finalize $VM
|
||||
set rc
|
||||
} {0}
|
||||
do_test attach2-3.2 {
|
||||
set rc [catch {sqlite_compile $DB "DETACH t2" TAIL} VM]
|
||||
if {$rc} {lappend rc $VM}
|
||||
sqlite_finalize $VM
|
||||
set rc
|
||||
} {0}
|
||||
|
||||
db close
|
||||
for {set i 2} {$i<=15} {incr i} {
|
||||
catch {db$i close}
|
||||
}
|
||||
file delete -force test2.db
|
||||
|
||||
|
||||
finish_test
|
||||
+1898
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,177 @@
|
||||
# 2002 November 30
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the ability of SQLite to handle database
|
||||
# files larger than 4GB.
|
||||
#
|
||||
# $Id: bigfile.test,v 1.3 2003/12/19 12:31:22 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# These tests only work for Tcl version 8.4 and later. Prior to 8.4,
|
||||
# Tcl was unable to handle large files.
|
||||
#
|
||||
scan $::tcl_version %f vx
|
||||
if {$vx<8.4} return
|
||||
|
||||
# This is the md5 checksum of all the data in table t1 as created
|
||||
# by the first test. We will use this number to make sure that data
|
||||
# never changes.
|
||||
#
|
||||
set MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf}
|
||||
|
||||
do_test bigfile-1.1 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE t1(x);
|
||||
INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz');
|
||||
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
|
||||
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
|
||||
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
|
||||
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
|
||||
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
|
||||
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
|
||||
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
|
||||
COMMIT;
|
||||
}
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
|
||||
# Try to create a large file - a file that is larger than 2^32 bytes.
|
||||
# If this fails, it means that the system being tested does not support
|
||||
# large files. So skip all of the remaining tests in this file.
|
||||
#
|
||||
db close
|
||||
if {[catch {fake_big_file 4096 test.db}]} {
|
||||
puts "**** Unable to create a file larger than 4096 MB. *****"
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_test bigfile-1.2 {
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
|
||||
# The previous test may fail on some systems because they are unable
|
||||
# to handle large files. If that is so, then skip all of the following
|
||||
# tests. We will know the above test failed because the "db" command
|
||||
# does not exist.
|
||||
#
|
||||
if {[llength [info command db]]>0} {
|
||||
|
||||
do_test bigfile-1.3 {
|
||||
execsql {
|
||||
CREATE TABLE t2 AS SELECT * FROM t1;
|
||||
SELECT md5sum(x) FROM t2;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.4 {
|
||||
db close
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.5 {
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t2;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
|
||||
db close
|
||||
if {[catch {fake_big_file 8192 test.db}]} {
|
||||
puts "**** Unable to create a file larger than 8192 MB. *****"
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_test bigfile-1.6 {
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.7 {
|
||||
execsql {
|
||||
CREATE TABLE t3 AS SELECT * FROM t1;
|
||||
SELECT md5sum(x) FROM t3;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.8 {
|
||||
db close
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.9 {
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t2;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.10 {
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t3;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
|
||||
db close
|
||||
if {[catch {fake_big_file 16384 test.db}]} {
|
||||
puts "**** Unable to create a file larger than 16384 MB. *****"
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_test bigfile-1.11 {
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.12 {
|
||||
execsql {
|
||||
CREATE TABLE t4 AS SELECT * FROM t1;
|
||||
SELECT md5sum(x) FROM t4;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.13 {
|
||||
db close
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t1;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.14 {
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t2;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.15 {
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t3;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
do_test bigfile-1.16 {
|
||||
execsql {
|
||||
SELECT md5sum(x) FROM t3;
|
||||
}
|
||||
} $::MAGIC_SUM
|
||||
|
||||
} ;# End of the "if( db command exists )"
|
||||
|
||||
finish_test
|
||||
+115
-5
@@ -12,7 +12,7 @@
|
||||
# focus of this file is stressing the library by putting large amounts
|
||||
# of data in a single row of a table.
|
||||
#
|
||||
# $Id: bigrow.test,v 1.1 2001/09/24 03:12:40 drh Exp $
|
||||
# $Id: bigrow.test,v 1.4 2001/11/24 00:31:47 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -50,11 +50,22 @@ do_test bigrow-1.3 {
|
||||
execsql {SELECT b FROM t1}
|
||||
} [list $::big1]
|
||||
do_test bigrow-1.4 {
|
||||
set sql "INSERT INTO t1 VALUES('abc',"
|
||||
append sql "'[string range $::bigstr 0 65520]', 'xyz');"
|
||||
set ::big2 [string range $::bigstr 0 65520]
|
||||
set sql "INSERT INTO t1 VALUES('abc2',"
|
||||
append sql "'$::big2', 'xyz2');"
|
||||
set r [catch {execsql $sql} msg]
|
||||
lappend r $msg
|
||||
} {1 {too much data for one table row}}
|
||||
} {0 {}}
|
||||
do_test bigrow-1.4.1 {
|
||||
execsql {SELECT b FROM t1 ORDER BY c}
|
||||
} [list $::big1 $::big2]
|
||||
do_test bigrow-1.4.2 {
|
||||
execsql {SELECT c FROM t1 ORDER BY c}
|
||||
} {xyz xyz2}
|
||||
do_test bigrow-1.4.3 {
|
||||
execsql {DELETE FROM t1 WHERE a='abc2'}
|
||||
execsql {SELECT c FROM t1}
|
||||
} {xyz}
|
||||
|
||||
do_test bigrow-1.5 {
|
||||
execsql {
|
||||
@@ -79,7 +90,7 @@ do_test bigrow-1.8 {
|
||||
} {abc}
|
||||
do_test bigrow-1.9 {
|
||||
execsql "SELECT b FROM t1 WHERE a!='$::big1' ORDER BY a"
|
||||
} {B 2}
|
||||
} {2 B}
|
||||
|
||||
# Try doing some indexing on big columns
|
||||
#
|
||||
@@ -101,5 +112,104 @@ do_test bigrow-2.3 {
|
||||
}
|
||||
execsql "SELECT b FROM t1 WHERE a=='$::big1'"
|
||||
} {abc}
|
||||
catch {unset ::bigstr}
|
||||
catch {unset ::big1}
|
||||
catch {unset ::big2}
|
||||
|
||||
# Mosts of the tests above were created back when rows were limited in
|
||||
# size to 64K. Now rows can be much bigger. Test that logic. Also
|
||||
# make sure things work correctly at the transition boundries between
|
||||
# row sizes of 256 to 257 bytes and from 65536 to 65537 bytes.
|
||||
#
|
||||
# We begin by testing the 256..257 transition.
|
||||
#
|
||||
do_test bigrow-3.1 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
|
||||
}
|
||||
execsql {SELECT a,length(b),c FROM t1}
|
||||
} {one 30 hi}
|
||||
do_test bigrow-3.2 {
|
||||
execsql {
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
}
|
||||
execsql {SELECT a,length(b),c FROM t1}
|
||||
} {one 240 hi}
|
||||
for {set i 1} {$i<10} {incr i} {
|
||||
do_test bigrow-3.3.$i {
|
||||
execsql "UPDATE t1 SET b=b||'$i'"
|
||||
execsql {SELECT a,length(b),c FROM t1}
|
||||
} "one [expr {240+$i}] hi"
|
||||
}
|
||||
|
||||
# Now test the 65536..65537 row-size transition.
|
||||
#
|
||||
do_test bigrow-4.1 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
|
||||
}
|
||||
execsql {SELECT a,length(b),c FROM t1}
|
||||
} {one 30 hi}
|
||||
do_test bigrow-4.2 {
|
||||
execsql {
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
UPDATE t1 SET b=b||b;
|
||||
}
|
||||
execsql {SELECT a,length(b),c FROM t1}
|
||||
} {one 122880 hi}
|
||||
do_test bigrow-4.3 {
|
||||
execsql {
|
||||
UPDATE t1 SET b=substr(b,1,65515)
|
||||
}
|
||||
execsql {SELECT a,length(b),c FROM t1}
|
||||
} {one 65515 hi}
|
||||
for {set i 1} {$i<10} {incr i} {
|
||||
do_test bigrow-4.4.$i {
|
||||
execsql "UPDATE t1 SET b=b||'$i'"
|
||||
execsql {SELECT a,length(b),c FROM t1}
|
||||
} "one [expr {65515+$i}] hi"
|
||||
}
|
||||
|
||||
# Check to make sure the library recovers safely if a row contains
|
||||
# too much data.
|
||||
#
|
||||
do_test bigrow-5.1 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
|
||||
}
|
||||
execsql {SELECT a,length(b),c FROM t1}
|
||||
} {one 30 hi}
|
||||
set i 1
|
||||
for {set sz 60} {$sz<1048560} {incr sz $sz} {
|
||||
do_test bigrow-5.2.$i {
|
||||
execsql {
|
||||
UPDATE t1 SET b=b||b;
|
||||
SELECT a,length(b),c FROM t1;
|
||||
}
|
||||
} "one $sz hi"
|
||||
incr i
|
||||
}
|
||||
do_test bigrow-5.3 {
|
||||
set r [catch {execsql {UPDATE t1 SET b=b||b}} msg]
|
||||
lappend r $msg
|
||||
} {1 {too much data for one table row}}
|
||||
do_test bigrow-5.4 {
|
||||
execsql {DROP TABLE t1}
|
||||
} {}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# 2003 September 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 implements regression tests for SQLite library. The
|
||||
# focus of this script testing the sqlite_bind API.
|
||||
#
|
||||
# $Id: bind.test,v 1.1 2003/09/06 22:45:21 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
do_test bind-1.1 {
|
||||
db close
|
||||
set DB [sqlite db test.db]
|
||||
execsql {CREATE TABLE t1(a,b,c)}
|
||||
set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test bind-1.2 {
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} {SQLITE_DONE}
|
||||
do_test bind-1.3 {
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 {} {} {}}
|
||||
do_test bind-1.4 {
|
||||
sqlite_reset $VM
|
||||
sqlite_bind $VM 1 {test value 1} normal
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} SQLITE_DONE
|
||||
do_test bind-1.5 {
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 {} {} {} 2 {test value 1} {} {}}
|
||||
do_test bind-1.6 {
|
||||
sqlite_reset $VM
|
||||
sqlite_bind $VM 3 {'test value 2'} normal
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} SQLITE_DONE
|
||||
do_test bind-1.7 {
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}}
|
||||
do_test bind-1.8 {
|
||||
sqlite_reset $VM
|
||||
set sqlite_static_bind_value 123
|
||||
sqlite_bind $VM 1 {} static
|
||||
sqlite_bind $VM 2 {abcdefg} normal
|
||||
sqlite_bind $VM 3 {} null
|
||||
execsql {DELETE FROM t1}
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 123 abcdefg {}}
|
||||
do_test bind-1.9 {
|
||||
sqlite_reset $VM
|
||||
sqlite_bind $VM 1 {456} normal
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
execsql {SELECT rowid, * FROM t1}
|
||||
} {1 123 abcdefg {} 2 456 abcdefg {}}
|
||||
|
||||
|
||||
do_test bind-1.99 {
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
|
||||
|
||||
finish_test
|
||||
+14
-12
@@ -11,13 +11,14 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# $Id: btree.test,v 1.10 2001/09/23 02:35:53 drh Exp $
|
||||
# $Id: btree.test,v 1.15 2004/02/10 01:54:28 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
if {[info commands btree_open]!=""} {
|
||||
if {[info commands btree_open]!="" && $SQLITE_PAGE_SIZE==1024
|
||||
&& $SQLITE_USABLE_SIZE==1024} {
|
||||
|
||||
# Basic functionality. Open and close a database.
|
||||
#
|
||||
@@ -344,6 +345,7 @@ do_test btree-4.8 {
|
||||
} {2}
|
||||
do_test btree-4.9 {
|
||||
set r {}
|
||||
btree_first $::c1
|
||||
while 1 {
|
||||
set key [btree_key $::c1]
|
||||
if {$key==""} break
|
||||
@@ -358,30 +360,30 @@ do_test btree-4.9 {
|
||||
#
|
||||
do_test btree-5.1 {
|
||||
btree_get_meta $::b1
|
||||
} {0 0 0 0}
|
||||
} {0 0 0 0 0 0 0 0 0 0}
|
||||
do_test btree-5.2 {
|
||||
set rc [catch {btree_update_meta $::b1 1 2 3 4} msg]
|
||||
set rc [catch {btree_update_meta $::b1 1 2 3 4 5 6 7 8 9 10} msg]
|
||||
lappend rc $msg
|
||||
} {1 SQLITE_ERROR}
|
||||
do_test btree-5.3 {
|
||||
btree_begin_transaction $::b1
|
||||
set rc [catch {btree_update_meta $::b1 1 2 3 4} msg]
|
||||
set rc [catch {btree_update_meta $::b1 1 2 3 4 5 6 7 8 9 10} msg]
|
||||
lappend rc $msg
|
||||
} {0 {}}
|
||||
do_test btree-5.4 {
|
||||
btree_get_meta $::b1
|
||||
} {0 2 3 4}
|
||||
} {0 2 3 4 5 6 7 8 9 10}
|
||||
do_test btree-5.5 {
|
||||
btree_close_cursor $::c1
|
||||
btree_rollback $::b1
|
||||
btree_get_meta $::b1
|
||||
} {0 0 0 0}
|
||||
} {0 0 0 0 0 0 0 0 0 0}
|
||||
do_test btree-5.6 {
|
||||
btree_begin_transaction $::b1
|
||||
btree_update_meta $::b1 999 10 20 30
|
||||
btree_update_meta $::b1 999 10 20 30 40 50 60 70 80 90
|
||||
btree_commit $::b1
|
||||
btree_get_meta $::b1
|
||||
} {0 10 20 30}
|
||||
} {0 10 20 30 40 50 60 70 80 90}
|
||||
|
||||
proc select_all {cursor} {
|
||||
set r {}
|
||||
@@ -986,7 +988,7 @@ do_test btree-12.12 {
|
||||
btree_key $::c1
|
||||
} {402}
|
||||
do_test btree-13.1 {
|
||||
btree_sanity_check $::b1 2 3
|
||||
btree_integrity_check $::b1 2 3
|
||||
} {}
|
||||
|
||||
# To Do:
|
||||
@@ -997,11 +999,11 @@ do_test btree-13.1 {
|
||||
# 4. Implement btree_sanity and put it throughout this script
|
||||
#
|
||||
|
||||
do_test btree-10.98 {
|
||||
do_test btree-15.98 {
|
||||
btree_close_cursor $::c1
|
||||
lindex [btree_pager_stats $::b1] 1
|
||||
} {1}
|
||||
do_test btree-10.99 {
|
||||
do_test btree-15.99 {
|
||||
btree_rollback $::b1
|
||||
lindex [btree_pager_stats $::b1] 1
|
||||
} {0}
|
||||
|
||||
+27
-18
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# $Id: btree2.test,v 1.8 2001/09/23 02:35:53 drh Exp $
|
||||
# $Id: btree2.test,v 1.10 2002/02/19 13:39:23 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -53,7 +53,7 @@ do_test btree2-1.5 {
|
||||
btree_delete $::c2
|
||||
btree_close_cursor $::c2
|
||||
btree_commit $::b
|
||||
btree_sanity_check $::b 2 3 4 5 6
|
||||
btree_integrity_check $::b 2 3 4 5 6
|
||||
} {}
|
||||
|
||||
# This test module works by making lots of pseudo-random changes to a
|
||||
@@ -125,7 +125,7 @@ proc make_payload {keynum L len} {
|
||||
# success or an error message if something is amiss.
|
||||
#
|
||||
proc check_invariants {} {
|
||||
set ck [btree_sanity_check $::b 2 3 4 5 6]
|
||||
set ck [btree_integrity_check $::b 2 3 4 5 6]
|
||||
if {$ck!=""} {
|
||||
puts "\n*** SANITY:\n$ck"
|
||||
exit
|
||||
@@ -259,7 +259,7 @@ proc random_changes {n I K D} {
|
||||
} elseif {[btree_move_to $::c6 $basekey]==0} {
|
||||
btree_delete $::c6
|
||||
}
|
||||
# set ck [btree_sanity_check $::b 2 3 4 5 6]
|
||||
# set ck [btree_integrity_check $::b 2 3 4 5 6]
|
||||
# if {$ck!=""} {
|
||||
# puts "\nSANITY CHECK FAILED!\n$ck"
|
||||
# exit
|
||||
@@ -326,15 +326,8 @@ foreach {N L} {
|
||||
} {0}
|
||||
do_test btree2-$testno.7 {
|
||||
btree_close $::b
|
||||
set ::b [btree_open test2.bt]
|
||||
set ::c2 [btree_cursor $::b 2 1]
|
||||
set ::c3 [btree_cursor $::b 3 1]
|
||||
set ::c4 [btree_cursor $::b 4 1]
|
||||
set ::c5 [btree_cursor $::b 5 1]
|
||||
set ::c6 [btree_cursor $::b 6 1]
|
||||
check_invariants
|
||||
} {}
|
||||
|
||||
after 100
|
||||
# For each database size, run various changes tests.
|
||||
#
|
||||
set num2 1
|
||||
@@ -348,6 +341,16 @@ foreach {N L} {
|
||||
2.0 1.0 0.0 0.0
|
||||
} {
|
||||
set testid btree2-$testno.8.$num2
|
||||
set hash [md5file test2.bt]
|
||||
do_test $testid.0 {
|
||||
set ::b [btree_open test2.bt]
|
||||
set ::c2 [btree_cursor $::b 2 1]
|
||||
set ::c3 [btree_cursor $::b 3 1]
|
||||
set ::c4 [btree_cursor $::b 4 1]
|
||||
set ::c5 [btree_cursor $::b 5 1]
|
||||
set ::c6 [btree_cursor $::b 6 1]
|
||||
check_invariants
|
||||
} {}
|
||||
set cnt 6
|
||||
for {set i 2} {$i<=6} {incr i} {
|
||||
if {[lindex [btree_cursor_dump [set ::c$i]] 0]!=$i} {incr cnt}
|
||||
@@ -356,7 +359,6 @@ foreach {N L} {
|
||||
btree_begin_transaction $::b
|
||||
lindex [btree_pager_stats $::b] 1
|
||||
} $cnt
|
||||
set hash [md5file test2.bt]
|
||||
# exec cp test2.bt test2.bt.bu1
|
||||
do_test $testid.2 [subst {
|
||||
random_changes $n $I $K $D
|
||||
@@ -409,14 +411,21 @@ foreach {N L} {
|
||||
set ::c6 [btree_cursor $::b 6 1]
|
||||
check_invariants
|
||||
} {}
|
||||
do_test $testid.10 {
|
||||
btree_close_cursor $::c2
|
||||
btree_close_cursor $::c3
|
||||
btree_close_cursor $::c4
|
||||
btree_close_cursor $::c5
|
||||
btree_close_cursor $::c6
|
||||
lindex [btree_pager_stats $::b] 1
|
||||
} {0}
|
||||
do_test $testid.11 {
|
||||
btree_close $::b
|
||||
} {}
|
||||
incr num2
|
||||
}
|
||||
btree_close_cursor $::c2
|
||||
btree_close_cursor $::c3
|
||||
btree_close_cursor $::c4
|
||||
btree_close_cursor $::c5
|
||||
btree_close_cursor $::c6
|
||||
incr testno
|
||||
set ::b [btree_open test2.bt]
|
||||
}
|
||||
|
||||
# Testing is complete. Shut everything down.
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
# 2001 November 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. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# In particular, this file tests a small part of the Delete logic
|
||||
# for the BTree backend. When a row is deleted from a table, the
|
||||
# cursor is suppose to be left pointing at either the previous or
|
||||
# next entry in that table. If the cursor is left pointing at the
|
||||
# next entry, then the next Next operation is ignored. So the
|
||||
# sequence of operations (Delete, Next) should always leave the
|
||||
# cursor pointing at the first entry past the one that was deleted.
|
||||
# This test is designed to verify that behavior.
|
||||
#
|
||||
# $Id: btree3.test,v 1.2 2002/12/04 13:40:27 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
if {[info commands btree_open]!=""} {
|
||||
|
||||
# Open a test database.
|
||||
#
|
||||
file delete -force test1.bt
|
||||
file delete -force test1.bt-journal
|
||||
set b1 [btree_open test1.bt]
|
||||
btree_begin_transaction $::b1
|
||||
|
||||
# Insert a few one records
|
||||
#
|
||||
set data {abcdefghijklmnopqrstuvwxyz0123456789}
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
for {set k 2} {$k<=10} {incr k} {
|
||||
for {set j 1} {$j<=$k} {incr j} {
|
||||
set jkey [format %02d $j]
|
||||
btree_clear_table $::b1 2
|
||||
set ::c1 [btree_cursor $::b1 2 1]
|
||||
for {set i 1} {$i<=$k} {incr i} {
|
||||
set key [format %02d $i]
|
||||
do_test btree3-$k.$j.1.$i {
|
||||
btree_insert $::c1 $::key $::data
|
||||
} {}
|
||||
# btree_tree_dump $::b1 2
|
||||
}
|
||||
do_test btree3-$k.$j.2 {
|
||||
btree_move_to $::c1 $::jkey
|
||||
btree_key $::c1
|
||||
} $::jkey
|
||||
do_test btree3-$k.$j.3 {
|
||||
btree_delete $::c1
|
||||
} {}
|
||||
if {$j<$k} {
|
||||
do_test btree3-$k.$j.4 {
|
||||
btree_next $::c1
|
||||
btree_key $::c1
|
||||
} [format %02d [expr $j+1]]
|
||||
}
|
||||
if {$j>1} {
|
||||
do_test btree3-$k.$j.5 {
|
||||
btree_prev $::c1
|
||||
btree_key $::c1
|
||||
} [format %02d [expr $j-1]]
|
||||
}
|
||||
btree_close_cursor $::c1
|
||||
}
|
||||
}
|
||||
|
||||
btree_rollback $::b1
|
||||
btree_pager_ref_dump $::b1
|
||||
btree_close $::b1
|
||||
|
||||
} ;# end if( not mem: and has pager_open command );
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,84 @@
|
||||
# 2001 November 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. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# In particular, this file tests a small part of the Delete logic
|
||||
# for the BTree backend. When a row is deleted from a table, the
|
||||
# cursor is suppose to be left pointing at either the previous or
|
||||
# next entry in that table. If the cursor is left pointing at the
|
||||
# next entry, then the next Next operation is ignored. So the
|
||||
# sequence of operations (Delete, Next) should always leave the
|
||||
# cursor pointing at the first entry past the one that was deleted.
|
||||
# This test is designed to verify that behavior.
|
||||
#
|
||||
# $Id: btree3rb.test,v 1.1 2003/04/20 23:45:23 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
if {[info commands btree_open]!=""} {
|
||||
|
||||
# Open a test database.
|
||||
#
|
||||
set b1 [btree_open :memory:]
|
||||
btree_begin_transaction $::b1
|
||||
|
||||
# Insert a few one records
|
||||
#
|
||||
set data {abcdefghijklmnopqrstuvwxyz0123456789}
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
for {set k 2} {$k<=20} {incr k} {
|
||||
for {set j 1} {$j<=$k} {incr j} {
|
||||
set jkey [format %02d $j]
|
||||
btree_clear_table $::b1 2
|
||||
set ::c1 [btree_cursor $::b1 2 1]
|
||||
for {set i 1} {$i<=$k} {incr i} {
|
||||
set key [format %02d $i]
|
||||
do_test btree3rb-$k.$j.1.$i {
|
||||
btree_insert $::c1 $::key $::data
|
||||
} {}
|
||||
# btree_tree_dump $::b1 2
|
||||
}
|
||||
do_test btree3rb-$k.$j.2 {
|
||||
btree_move_to $::c1 $::jkey
|
||||
btree_key $::c1
|
||||
} $::jkey
|
||||
do_test btree3rb-$k.$j.3 {
|
||||
btree_delete $::c1
|
||||
} {}
|
||||
if {$j<$k} {
|
||||
do_test btree3rb-$k.$j.4 {
|
||||
btree_next $::c1
|
||||
btree_key $::c1
|
||||
} [format %02d [expr $j+1]]
|
||||
}
|
||||
if {$j>1} {
|
||||
do_test btree3rb-$k.$j.5 {
|
||||
btree_prev $::c1
|
||||
btree_key $::c1
|
||||
} [format %02d [expr $j-1]]
|
||||
}
|
||||
btree_close_cursor $::c1
|
||||
}
|
||||
}
|
||||
|
||||
btree_rollback $::b1
|
||||
#btree_pager_ref_dump $::b1
|
||||
btree_close $::b1
|
||||
|
||||
} ;# end if( not mem: and has pager_open command );
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,98 @@
|
||||
# 2002 December 03
|
||||
#
|
||||
# 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 btree database backend
|
||||
#
|
||||
# This file focuses on testing the sqliteBtreeNext() and
|
||||
# sqliteBtreePrevious() procedures and making sure they are able
|
||||
# to step through an entire table from either direction.
|
||||
#
|
||||
# $Id: btree4.test,v 1.1 2002/12/04 13:40:27 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
if {[info commands btree_open]!=""} {
|
||||
|
||||
# Open a test database.
|
||||
#
|
||||
file delete -force test1.bt
|
||||
file delete -force test1.bt-journal
|
||||
set b1 [btree_open test1.bt]
|
||||
btree_begin_transaction $::b1
|
||||
|
||||
set data {abcdefghijklmnopqrstuvwxyz0123456789}
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
|
||||
foreach N {10 100 1000} {
|
||||
btree_clear_table $::b1 2
|
||||
set ::c1 [btree_cursor $::b1 2 1]
|
||||
do_test btree4-$N.1 {
|
||||
for {set i 1} {$i<=$N} {incr i} {
|
||||
btree_insert $::c1 [format k-%05d $i] $::data-$i
|
||||
}
|
||||
btree_first $::c1
|
||||
btree_key $::c1
|
||||
} {k-00001}
|
||||
do_test btree4-$N.2 {
|
||||
btree_data $::c1
|
||||
} $::data-1
|
||||
for {set i 2} {$i<=$N} {incr i} {
|
||||
do_test btree-$N.3.$i.1 {
|
||||
btree_next $::c1
|
||||
} 0
|
||||
do_test btree-$N.3.$i.2 {
|
||||
btree_key $::c1
|
||||
} [format k-%05d $i]
|
||||
do_test btree-$N.3.$i.3 {
|
||||
btree_data $::c1
|
||||
} $::data-$i
|
||||
}
|
||||
do_test btree4-$N.4 {
|
||||
btree_next $::c1
|
||||
} 1
|
||||
do_test btree4-$N.5 {
|
||||
btree_last $::c1
|
||||
} 0
|
||||
do_test btree4-$N.6 {
|
||||
btree_key $::c1
|
||||
} [format k-%05d $N]
|
||||
do_test btree4-$N.7 {
|
||||
btree_data $::c1
|
||||
} $::data-$N
|
||||
for {set i [expr {$N-1}]} {$i>=1} {incr i -1} {
|
||||
do_test btree4-$N.8.$i.1 {
|
||||
btree_prev $::c1
|
||||
} 0
|
||||
do_test btree4-$N.8.$i.2 {
|
||||
btree_key $::c1
|
||||
} [format k-%05d $i]
|
||||
do_test btree4-$N.8.$i.3 {
|
||||
btree_data $::c1
|
||||
} $::data-$i
|
||||
}
|
||||
do_test btree4-$N.9 {
|
||||
btree_prev $::c1
|
||||
} 1
|
||||
btree_close_cursor $::c1
|
||||
}
|
||||
|
||||
btree_rollback $::b1
|
||||
btree_pager_ref_dump $::b1
|
||||
btree_close $::b1
|
||||
|
||||
} ;# end if( not mem: and has pager_open command );
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,95 @@
|
||||
# 2002 December 03
|
||||
#
|
||||
# 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 btree database backend
|
||||
#
|
||||
# This file focuses on testing the sqliteBtreeNext() and
|
||||
# sqliteBtreePrevious() procedures and making sure they are able
|
||||
# to step through an entire table from either direction.
|
||||
#
|
||||
# $Id: btree4rb.test,v 1.1 2003/04/20 23:45:23 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
if {[info commands btree_open]!=""} {
|
||||
|
||||
# Open a test database.
|
||||
#
|
||||
set b1 [btree_open :memory:]
|
||||
btree_begin_transaction $::b1
|
||||
|
||||
set data {abcdefghijklmnopqrstuvwxyz0123456789}
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
append data $data
|
||||
|
||||
foreach N {10 100 1000} {
|
||||
btree_clear_table $::b1 2
|
||||
set ::c1 [btree_cursor $::b1 2 1]
|
||||
do_test btree4rb-$N.1 {
|
||||
for {set i 1} {$i<=$N} {incr i} {
|
||||
btree_insert $::c1 [format k-%05d $i] $::data-$i
|
||||
}
|
||||
btree_first $::c1
|
||||
btree_key $::c1
|
||||
} {k-00001}
|
||||
do_test btree4rb-$N.2 {
|
||||
btree_data $::c1
|
||||
} $::data-1
|
||||
for {set i 2} {$i<=$N} {incr i} {
|
||||
do_test btree-$N.3.$i.1 {
|
||||
btree_next $::c1
|
||||
} 0
|
||||
do_test btree-$N.3.$i.2 {
|
||||
btree_key $::c1
|
||||
} [format k-%05d $i]
|
||||
do_test btree-$N.3.$i.3 {
|
||||
btree_data $::c1
|
||||
} $::data-$i
|
||||
}
|
||||
do_test btree4rb-$N.4 {
|
||||
btree_next $::c1
|
||||
} 1
|
||||
do_test btree4rb-$N.5 {
|
||||
btree_last $::c1
|
||||
} 0
|
||||
do_test btree4rb-$N.6 {
|
||||
btree_key $::c1
|
||||
} [format k-%05d $N]
|
||||
do_test btree4rb-$N.7 {
|
||||
btree_data $::c1
|
||||
} $::data-$N
|
||||
for {set i [expr {$N-1}]} {$i>=1} {incr i -1} {
|
||||
do_test btree4rb-$N.8.$i.1 {
|
||||
btree_prev $::c1
|
||||
} 0
|
||||
do_test btree4rb-$N.8.$i.2 {
|
||||
btree_key $::c1
|
||||
} [format k-%05d $i]
|
||||
do_test btree4rb-$N.8.$i.3 {
|
||||
btree_data $::c1
|
||||
} $::data-$i
|
||||
}
|
||||
do_test btree4rb-$N.9 {
|
||||
btree_prev $::c1
|
||||
} 1
|
||||
btree_close_cursor $::c1
|
||||
}
|
||||
|
||||
btree_rollback $::b1
|
||||
btree_close $::b1
|
||||
|
||||
} ;# end if( not mem: and has pager_open command );
|
||||
|
||||
finish_test
|
||||
+475
@@ -0,0 +1,475 @@
|
||||
# 2003 January 29
|
||||
#
|
||||
# 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 testing the callback-free C/C++ API.
|
||||
#
|
||||
# $Id: capi2.test,v 1.10 2003/08/05 13:13:38 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Check basic functionality
|
||||
#
|
||||
do_test capi2-1.1 {
|
||||
db close
|
||||
set DB [sqlite db test.db]
|
||||
execsql {CREATE TABLE t1(a,b,c)}
|
||||
set VM [sqlite_compile $DB {SELECT name, rowid FROM sqlite_master} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-1.2 {
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} {SQLITE_ROW}
|
||||
do_test capi2-1.3 {
|
||||
set N
|
||||
} {2}
|
||||
do_test capi2-1.4 {
|
||||
set VALUES
|
||||
} {t1 1}
|
||||
do_test capi2-1.5 {
|
||||
set COLNAMES
|
||||
} {name rowid text INTEGER}
|
||||
do_test capi2-1.6 {
|
||||
set N x
|
||||
set VALUES y
|
||||
set COLNAMES z
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} {SQLITE_DONE}
|
||||
do_test capi2-1.7 {
|
||||
list $N $VALUES $COLNAMES
|
||||
} {2 {} {name rowid text INTEGER}}
|
||||
do_test capi2-1.8 {
|
||||
set N x
|
||||
set VALUES y
|
||||
set COLNAMES z
|
||||
sqlite_step $VM N VALUES COLNAMES
|
||||
} {SQLITE_MISUSE}
|
||||
do_test capi2-1.9 {
|
||||
list $N $VALUES $COLNAMES
|
||||
} {0 {} {}}
|
||||
do_test capi2-1.10 {
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
|
||||
# Check to make sure that the "tail" of a multi-statement SQL script
|
||||
# is returned by sqlite_compile.
|
||||
#
|
||||
do_test capi2-2.1 {
|
||||
set SQL {
|
||||
SELECT name, rowid FROM sqlite_master;
|
||||
SELECT name, rowid FROM sqlite_temp_master;
|
||||
-- A comment at the end
|
||||
}
|
||||
set VM [sqlite_compile $DB $SQL SQL]
|
||||
set SQL
|
||||
} {
|
||||
SELECT name, rowid FROM sqlite_temp_master;
|
||||
-- A comment at the end
|
||||
}
|
||||
do_test capi2-2.2 {
|
||||
set r [sqlite_step $VM n val colname]
|
||||
lappend r $n $val $colname
|
||||
} {SQLITE_ROW 2 {t1 1} {name rowid text INTEGER}}
|
||||
do_test capi2-2.3 {
|
||||
set r [sqlite_step $VM n val colname]
|
||||
lappend r $n $val $colname
|
||||
} {SQLITE_DONE 2 {} {name rowid text INTEGER}}
|
||||
do_test capi2-2.4 {
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
do_test capi2-2.5 {
|
||||
set VM [sqlite_compile $DB $SQL SQL]
|
||||
set SQL
|
||||
} {
|
||||
-- A comment at the end
|
||||
}
|
||||
do_test capi2-2.6 {
|
||||
set r [sqlite_step $VM n val colname]
|
||||
lappend r $n $val $colname
|
||||
} {SQLITE_DONE 2 {} {name rowid text INTEGER}}
|
||||
do_test capi2-2.7 {
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
do_test capi2-2.8 {
|
||||
set VM [sqlite_compile $DB $SQL SQL]
|
||||
list $SQL $VM
|
||||
} {{} {}}
|
||||
|
||||
# Check the error handling.
|
||||
#
|
||||
do_test capi2-3.1 {
|
||||
set rc [catch {
|
||||
sqlite_compile $DB {select bogus from sqlite_master} TAIL
|
||||
} msg]
|
||||
lappend rc $msg $TAIL
|
||||
} {1 {(1) no such column: bogus} {}}
|
||||
do_test capi2-3.2 {
|
||||
set rc [catch {
|
||||
sqlite_compile $DB {select bogus from } TAIL
|
||||
} msg]
|
||||
lappend rc $msg $TAIL
|
||||
} {1 {(1) near " ": syntax error} {}}
|
||||
do_test capi2-3.3 {
|
||||
set rc [catch {
|
||||
sqlite_compile $DB {;;;;select bogus from sqlite_master} TAIL
|
||||
} msg]
|
||||
lappend rc $msg $TAIL
|
||||
} {1 {(1) no such column: bogus} {}}
|
||||
do_test capi2-3.4 {
|
||||
set rc [catch {
|
||||
sqlite_compile $DB {select bogus from sqlite_master;x;} TAIL
|
||||
} msg]
|
||||
lappend rc $msg $TAIL
|
||||
} {1 {(1) no such column: bogus} {x;}}
|
||||
do_test capi2-3.5 {
|
||||
set rc [catch {
|
||||
sqlite_compile $DB {select bogus from sqlite_master;;;x;} TAIL
|
||||
} msg]
|
||||
lappend rc $msg $TAIL
|
||||
} {1 {(1) no such column: bogus} {;;x;}}
|
||||
do_test capi2-3.6 {
|
||||
set rc [catch {
|
||||
sqlite_compile $DB {select 5/0} TAIL
|
||||
} VM]
|
||||
lappend rc $TAIL
|
||||
} {0 {}}
|
||||
do_test capi2-3.7 {
|
||||
set N {}
|
||||
set VALUE {}
|
||||
set COLNAME {}
|
||||
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 {{}} {5/0 NUMERIC}}
|
||||
do_test capi2-3.8 {
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
do_test capi2-3.9 {
|
||||
execsql {CREATE UNIQUE INDEX i1 ON t1(a)}
|
||||
set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(1,2,3)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-3.9b {db changes} {0}
|
||||
do_test capi2-3.10 {
|
||||
set N {}
|
||||
set VALUE {}
|
||||
set COLNAME {}
|
||||
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 0 {} {}}
|
||||
do_test capi2-3.10b {db changes} {1}
|
||||
do_test capi2-3.11 {
|
||||
sqlite_finalize $VM
|
||||
} {}
|
||||
do_test capi2-3.11b {db changes} {1}
|
||||
do_test capi2-3.12 {
|
||||
list [catch {sqlite_finalize $VM} msg] [set msg]
|
||||
} {1 {(21) library routine called out of sequence}}
|
||||
do_test capi2-3.13 {
|
||||
set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(1,3,4)} TAIL]
|
||||
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ERROR 0 {} {}}
|
||||
do_test capi2-3.13b {db changes} {0}
|
||||
do_test capi2-3.14 {
|
||||
list [catch {sqlite_finalize $VM} msg] [set msg]
|
||||
} {1 {(19) column a is not unique}}
|
||||
do_test capi2-3.15 {
|
||||
set VM [sqlite_compile $DB {CREATE TABLE t2(a NOT NULL, b)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-3.16 {
|
||||
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 0 {} {}}
|
||||
do_test capi2-3.17 {
|
||||
list [catch {sqlite_finalize $VM} msg] [set msg]
|
||||
} {0 {}}
|
||||
do_test capi2-3.18 {
|
||||
set VM [sqlite_compile $DB {INSERT INTO t2 VALUES(NULL,2)} TAIL]
|
||||
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ERROR 0 {} {}}
|
||||
do_test capi2-3.19 {
|
||||
list [catch {sqlite_finalize $VM} msg] [set msg]
|
||||
} {1 {(19) t2.a may not be NULL}}
|
||||
|
||||
# Two or more virtual machines exists at the same time.
|
||||
#
|
||||
do_test capi2-4.1 {
|
||||
set VM1 [sqlite_compile $DB {INSERT INTO t2 VALUES(1,2)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-4.2 {
|
||||
set VM2 [sqlite_compile $DB {INSERT INTO t2 VALUES(2,3)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-4.3 {
|
||||
set VM3 [sqlite_compile $DB {INSERT INTO t2 VALUES(3,4)} TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi2-4.4 {
|
||||
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 0 {} {}}
|
||||
do_test capi2-4.5 {
|
||||
execsql {SELECT * FROM t2 ORDER BY a}
|
||||
} {2 3}
|
||||
do_test capi2-4.6 {
|
||||
list [catch {sqlite_finalize $VM2} msg] [set msg]
|
||||
} {0 {}}
|
||||
do_test capi2-4.7 {
|
||||
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 0 {} {}}
|
||||
do_test capi2-4.8 {
|
||||
execsql {SELECT * FROM t2 ORDER BY a}
|
||||
} {2 3 3 4}
|
||||
do_test capi2-4.9 {
|
||||
list [catch {sqlite_finalize $VM3} msg] [set msg]
|
||||
} {0 {}}
|
||||
do_test capi2-4.10 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 0 {} {}}
|
||||
do_test capi2-4.11 {
|
||||
execsql {SELECT * FROM t2 ORDER BY a}
|
||||
} {1 2 2 3 3 4}
|
||||
do_test capi2-4.12 {
|
||||
list [catch {sqlite_finalize $VM1} msg] [set msg]
|
||||
} {0 {}}
|
||||
|
||||
# Interleaved SELECTs
|
||||
#
|
||||
do_test capi2-5.1 {
|
||||
set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
|
||||
set VM2 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
|
||||
set VM3 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {2 3} {a b {} {}}}
|
||||
do_test capi2-5.2 {
|
||||
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {2 3} {a b {} {}}}
|
||||
do_test capi2-5.3 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {3 4} {a b {} {}}}
|
||||
do_test capi2-5.4 {
|
||||
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {2 3} {a b {} {}}}
|
||||
do_test capi2-5.5 {
|
||||
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {3 4} {a b {} {}}}
|
||||
do_test capi2-5.6 {
|
||||
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {1 2} {a b {} {}}}
|
||||
do_test capi2-5.7 {
|
||||
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_DONE 2 {} {a b {} {}}}
|
||||
do_test capi2-5.8 {
|
||||
list [catch {sqlite_finalize $VM3} msg] [set msg]
|
||||
} {0 {}}
|
||||
do_test capi2-5.9 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {1 2} {a b {} {}}}
|
||||
do_test capi2-5.10 {
|
||||
list [catch {sqlite_finalize $VM1} msg] [set msg]
|
||||
} {0 {}}
|
||||
do_test capi2-5.11 {
|
||||
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {3 4} {a b {} {}}}
|
||||
do_test capi2-5.12 {
|
||||
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 2 {1 2} {a b {} {}}}
|
||||
do_test capi2-5.11 {
|
||||
list [catch {sqlite_finalize $VM2} msg] [set msg]
|
||||
} {0 {}}
|
||||
|
||||
# Check for proper SQLITE_BUSY returns.
|
||||
#
|
||||
do_test capi2-6.1 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE t3(x counter);
|
||||
INSERT INTO t3 VALUES(1);
|
||||
INSERT INTO t3 VALUES(2);
|
||||
INSERT INTO t3 SELECT x+2 FROM t3;
|
||||
INSERT INTO t3 SELECT x+4 FROM t3;
|
||||
INSERT INTO t3 SELECT x+8 FROM t3;
|
||||
COMMIT;
|
||||
}
|
||||
set VM1 [sqlite_compile $DB {SELECT * FROM t3} TAIL]
|
||||
sqlite db2 test.db
|
||||
execsql {BEGIN} db2
|
||||
} {}
|
||||
do_test capi2-6.2 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_BUSY 0 {} {}}
|
||||
do_test capi2-6.3 {
|
||||
execsql {COMMIT} db2
|
||||
} {}
|
||||
do_test capi2-6.4 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 1 {x counter}}
|
||||
do_test capi2-6.5 {
|
||||
catchsql {BEGIN} db2
|
||||
} {1 {database is locked}}
|
||||
do_test capi2-6.6 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 2 {x counter}}
|
||||
do_test capi2-6.7 {
|
||||
execsql {SELECT * FROM t2} db2
|
||||
} {2 3 3 4 1 2}
|
||||
do_test capi2-6.8 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 3 {x counter}}
|
||||
do_test capi2-6.9 {
|
||||
execsql {SELECT * FROM t2}
|
||||
} {2 3 3 4 1 2}
|
||||
do_test capi2-6.10 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 4 {x counter}}
|
||||
do_test capi2-6.11 {
|
||||
execsql {BEGIN}
|
||||
} {}
|
||||
do_test capi2-6.12 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 5 {x counter}}
|
||||
# execsql {pragma vdbe_trace=on}
|
||||
do_test capi2-6.13 {
|
||||
catchsql {UPDATE t3 SET x=x+1}
|
||||
} {1 {database table is locked}}
|
||||
do_test capi2-6.14 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 6 {x counter}}
|
||||
# puts [list [catch {sqlite_finalize $VM1} msg] [set msg]]; exit
|
||||
do_test capi2-6.15 {
|
||||
execsql {SELECT * FROM t1}
|
||||
} {1 2 3}
|
||||
do_test capi2-6.16 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 7 {x counter}}
|
||||
do_test capi2-6.17 {
|
||||
catchsql {UPDATE t1 SET b=b+1}
|
||||
} {0 {}}
|
||||
do_test capi2-6.18 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 8 {x counter}}
|
||||
do_test capi2-6.19 {
|
||||
execsql {SELECT * FROM t1}
|
||||
} {1 3 3}
|
||||
do_test capi2-6.20 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 9 {x counter}}
|
||||
do_test capi2-6.21 {
|
||||
execsql {ROLLBACK; SELECT * FROM t1}
|
||||
} {1 2 3}
|
||||
do_test capi2-6.22 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 10 {x counter}}
|
||||
do_test capi2-6.23 {
|
||||
execsql {BEGIN TRANSACTION ON CONFLICT ROLLBACK;}
|
||||
} {}
|
||||
do_test capi2-6.24 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 11 {x counter}}
|
||||
do_test capi2-6.25 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(2,3,4);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 2 3 2 3 4}
|
||||
do_test capi2-6.26 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 12 {x counter}}
|
||||
do_test capi2-6.27 {
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(2,4,5);
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 {column a is not unique}}
|
||||
do_test capi2-6.28 {
|
||||
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
|
||||
} {SQLITE_ROW 1 13 {x counter}}
|
||||
do_test capi2-6.99 {
|
||||
list [catch {sqlite_finalize $VM1} msg] [set msg]
|
||||
} {0 {}}
|
||||
catchsql {ROLLBACK}
|
||||
|
||||
do_test capi2-7.1 {
|
||||
stepsql $DB {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {0 1 2 3}
|
||||
do_test capi2-7.2 {
|
||||
stepsql $DB {
|
||||
PRAGMA count_changes=on
|
||||
}
|
||||
} {0}
|
||||
do_test capi2-7.3 {
|
||||
stepsql $DB {
|
||||
UPDATE t1 SET a=a+10;
|
||||
}
|
||||
} {0 1}
|
||||
do_test capi2-7.4 {
|
||||
stepsql $DB {
|
||||
INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1;
|
||||
}
|
||||
} {0 1}
|
||||
do_test capi2-7.4b {db changes} {1}
|
||||
do_test capi2-7.5 {
|
||||
stepsql $DB {
|
||||
UPDATE t1 SET a=a+10;
|
||||
}
|
||||
} {0 2}
|
||||
do_test capi2-7.5b {db changes} {2}
|
||||
do_test capi2-7.6 {
|
||||
stepsql $DB {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 21 2 3 22 3 4}
|
||||
do_test capi2-7.7 {
|
||||
stepsql $DB {
|
||||
INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1;
|
||||
}
|
||||
} {0 2}
|
||||
do_test capi2-7.8 {
|
||||
db changes
|
||||
} {2}
|
||||
do_test capi2-7.9 {
|
||||
stepsql $DB {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 21 2 3 22 3 4 23 4 5 24 5 6}
|
||||
do_test capi2-7.10 {
|
||||
stepsql $DB {
|
||||
UPDATE t1 SET a=a-20;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 4 1 2 3 2 3 4 3 4 5 4 5 6}
|
||||
do_test capi2-7.11 {
|
||||
db changes
|
||||
} {0}
|
||||
do_test capi2-7.12 {
|
||||
set x [stepsql $DB {EXPLAIN SELECT * FROM t1}]
|
||||
lindex $x 0
|
||||
} {0}
|
||||
|
||||
# Ticket #261 - make sure we can finalize before the end of a query.
|
||||
#
|
||||
do_test capi2-8.1 {
|
||||
set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
|
||||
sqlite_finalize $VM1
|
||||
} {}
|
||||
|
||||
# Tickets #384 and #385 - make sure the TAIL argument to sqlite_compile
|
||||
# and all of the return pointers in sqlite_step can be null.
|
||||
#
|
||||
do_test capi2-9.1 {
|
||||
set VM1 [sqlite_compile $DB {SELECT * FROM t2}]
|
||||
sqlite_step $VM1
|
||||
sqlite_finalize $VM1
|
||||
} {}
|
||||
|
||||
db2 close
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,694 @@
|
||||
# 2002 January 29
|
||||
#
|
||||
# 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 conflict resolution extension
|
||||
# to SQLite.
|
||||
#
|
||||
# $Id: conflict.test,v 1.19 2003/08/05 13:13:39 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Create tables for the first group of tests.
|
||||
#
|
||||
do_test conflict-1.0 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b, c, UNIQUE(a,b));
|
||||
CREATE TABLE t2(x);
|
||||
SELECT c FROM t1 ORDER BY c;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Six columns of configuration data as follows:
|
||||
#
|
||||
# i The reference number of the test
|
||||
# conf The conflict resolution algorithm on the BEGIN statement
|
||||
# cmd An INSERT or REPLACE command to execute against table t1
|
||||
# t0 True if there is an error from $cmd
|
||||
# t1 Content of "c" column of t1 assuming no error in $cmd
|
||||
# t2 Content of "x" column of t2
|
||||
#
|
||||
foreach {i conf cmd t0 t1 t2} {
|
||||
1 {} INSERT 1 {} 1
|
||||
2 {} {INSERT OR IGNORE} 0 3 1
|
||||
3 {} {INSERT OR REPLACE} 0 4 1
|
||||
4 {} REPLACE 0 4 1
|
||||
5 {} {INSERT OR FAIL} 1 {} 1
|
||||
6 {} {INSERT OR ABORT} 1 {} 1
|
||||
7 {} {INSERT OR ROLLBACK} 1 {} {}
|
||||
8 IGNORE INSERT 0 3 1
|
||||
9 IGNORE {INSERT OR IGNORE} 0 3 1
|
||||
10 IGNORE {INSERT OR REPLACE} 0 4 1
|
||||
11 IGNORE REPLACE 0 4 1
|
||||
12 IGNORE {INSERT OR FAIL} 1 {} 1
|
||||
13 IGNORE {INSERT OR ABORT} 1 {} 1
|
||||
14 IGNORE {INSERT OR ROLLBACK} 1 {} {}
|
||||
15 REPLACE INSERT 0 4 1
|
||||
16 FAIL INSERT 1 {} 1
|
||||
17 ABORT INSERT 1 {} 1
|
||||
18 ROLLBACK INSERT 1 {} {}
|
||||
} {
|
||||
do_test conflict-1.$i {
|
||||
if {$conf!=""} {set conf "ON CONFLICT $conf"}
|
||||
set r0 [catch {execsql [subst {
|
||||
DELETE FROM t1;
|
||||
DELETE FROM t2;
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
BEGIN $conf;
|
||||
INSERT INTO t2 VALUES(1);
|
||||
$cmd INTO t1 VALUES(1,2,4);
|
||||
}]} r1]
|
||||
catch {execsql {COMMIT}}
|
||||
if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
|
||||
set r2 [execsql {SELECT x FROM t2}]
|
||||
list $r0 $r1 $r2
|
||||
} [list $t0 $t1 $t2]
|
||||
}
|
||||
|
||||
# Create tables for the first group of tests.
|
||||
#
|
||||
do_test conflict-2.0 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(a,b));
|
||||
CREATE TABLE t2(x);
|
||||
SELECT c FROM t1 ORDER BY c;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Six columns of configuration data as follows:
|
||||
#
|
||||
# i The reference number of the test
|
||||
# conf The conflict resolution algorithm on the BEGIN statement
|
||||
# cmd An INSERT or REPLACE command to execute against table t1
|
||||
# t0 True if there is an error from $cmd
|
||||
# t1 Content of "c" column of t1 assuming no error in $cmd
|
||||
# t2 Content of "x" column of t2
|
||||
#
|
||||
foreach {i conf cmd t0 t1 t2} {
|
||||
1 {} INSERT 1 {} 1
|
||||
2 {} {INSERT OR IGNORE} 0 3 1
|
||||
3 {} {INSERT OR REPLACE} 0 4 1
|
||||
4 {} REPLACE 0 4 1
|
||||
5 {} {INSERT OR FAIL} 1 {} 1
|
||||
6 {} {INSERT OR ABORT} 1 {} 1
|
||||
7 {} {INSERT OR ROLLBACK} 1 {} {}
|
||||
8 IGNORE INSERT 0 3 1
|
||||
9 IGNORE {INSERT OR IGNORE} 0 3 1
|
||||
10 IGNORE {INSERT OR REPLACE} 0 4 1
|
||||
11 IGNORE REPLACE 0 4 1
|
||||
12 IGNORE {INSERT OR FAIL} 1 {} 1
|
||||
13 IGNORE {INSERT OR ABORT} 1 {} 1
|
||||
14 IGNORE {INSERT OR ROLLBACK} 1 {} {}
|
||||
15 REPLACE INSERT 0 4 1
|
||||
16 FAIL INSERT 1 {} 1
|
||||
17 ABORT INSERT 1 {} 1
|
||||
18 ROLLBACK INSERT 1 {} {}
|
||||
} {
|
||||
do_test conflict-2.$i {
|
||||
if {$conf!=""} {set conf "ON CONFLICT $conf"}
|
||||
set r0 [catch {execsql [subst {
|
||||
DELETE FROM t1;
|
||||
DELETE FROM t2;
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
BEGIN $conf;
|
||||
INSERT INTO t2 VALUES(1);
|
||||
$cmd INTO t1 VALUES(1,2,4);
|
||||
}]} r1]
|
||||
catch {execsql {COMMIT}}
|
||||
if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
|
||||
set r2 [execsql {SELECT x FROM t2}]
|
||||
list $r0 $r1 $r2
|
||||
} [list $t0 $t1 $t2]
|
||||
}
|
||||
|
||||
# Create tables for the first group of tests.
|
||||
#
|
||||
do_test conflict-3.0 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
CREATE TABLE t1(a, b, c INTEGER, PRIMARY KEY(c), UNIQUE(a,b));
|
||||
CREATE TABLE t2(x);
|
||||
SELECT c FROM t1 ORDER BY c;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Six columns of configuration data as follows:
|
||||
#
|
||||
# i The reference number of the test
|
||||
# conf The conflict resolution algorithm on the BEGIN statement
|
||||
# cmd An INSERT or REPLACE command to execute against table t1
|
||||
# t0 True if there is an error from $cmd
|
||||
# t1 Content of "c" column of t1 assuming no error in $cmd
|
||||
# t2 Content of "x" column of t2
|
||||
#
|
||||
foreach {i conf cmd t0 t1 t2} {
|
||||
1 {} INSERT 1 {} 1
|
||||
2 {} {INSERT OR IGNORE} 0 3 1
|
||||
3 {} {INSERT OR REPLACE} 0 4 1
|
||||
4 {} REPLACE 0 4 1
|
||||
5 {} {INSERT OR FAIL} 1 {} 1
|
||||
6 {} {INSERT OR ABORT} 1 {} 1
|
||||
7 {} {INSERT OR ROLLBACK} 1 {} {}
|
||||
8 IGNORE INSERT 0 3 1
|
||||
9 IGNORE {INSERT OR IGNORE} 0 3 1
|
||||
10 IGNORE {INSERT OR REPLACE} 0 4 1
|
||||
11 IGNORE REPLACE 0 4 1
|
||||
12 IGNORE {INSERT OR FAIL} 1 {} 1
|
||||
13 IGNORE {INSERT OR ABORT} 1 {} 1
|
||||
14 IGNORE {INSERT OR ROLLBACK} 1 {} {}
|
||||
15 REPLACE INSERT 0 4 1
|
||||
16 FAIL INSERT 1 {} 1
|
||||
17 ABORT INSERT 1 {} 1
|
||||
18 ROLLBACK INSERT 1 {} {}
|
||||
} {
|
||||
do_test conflict-3.$i {
|
||||
if {$conf!=""} {set conf "ON CONFLICT $conf"}
|
||||
set r0 [catch {execsql [subst {
|
||||
DELETE FROM t1;
|
||||
DELETE FROM t2;
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
BEGIN $conf;
|
||||
INSERT INTO t2 VALUES(1);
|
||||
$cmd INTO t1 VALUES(1,2,4);
|
||||
}]} r1]
|
||||
catch {execsql {COMMIT}}
|
||||
if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
|
||||
set r2 [execsql {SELECT x FROM t2}]
|
||||
list $r0 $r1 $r2
|
||||
} [list $t0 $t1 $t2]
|
||||
}
|
||||
|
||||
do_test conflict-4.0 {
|
||||
execsql {
|
||||
DROP TABLE t2;
|
||||
CREATE TABLE t2(x);
|
||||
SELECT x FROM t2;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Six columns of configuration data as follows:
|
||||
#
|
||||
# i The reference number of the test
|
||||
# conf1 The conflict resolution algorithm on the UNIQUE constraint
|
||||
# conf2 The conflict resolution algorithm on the BEGIN statement
|
||||
# cmd An INSERT or REPLACE command to execute against table t1
|
||||
# t0 True if there is an error from $cmd
|
||||
# t1 Content of "c" column of t1 assuming no error in $cmd
|
||||
# t2 Content of "x" column of t2
|
||||
#
|
||||
foreach {i conf1 conf2 cmd t0 t1 t2} {
|
||||
1 {} {} INSERT 1 {} 1
|
||||
2 REPLACE {} INSERT 0 4 1
|
||||
3 IGNORE {} INSERT 0 3 1
|
||||
4 FAIL {} INSERT 1 {} 1
|
||||
5 ABORT {} INSERT 1 {} 1
|
||||
6 ROLLBACK {} INSERT 1 {} {}
|
||||
7 REPLACE {} {INSERT OR IGNORE} 0 3 1
|
||||
8 IGNORE {} {INSERT OR REPLACE} 0 4 1
|
||||
9 FAIL {} {INSERT OR IGNORE} 0 3 1
|
||||
10 ABORT {} {INSERT OR REPLACE} 0 4 1
|
||||
11 ROLLBACK {} {INSERT OR IGNORE } 0 3 1
|
||||
12 REPLACE IGNORE INSERT 0 3 1
|
||||
13 IGNORE REPLACE INSERT 0 4 1
|
||||
14 FAIL IGNORE INSERT 0 3 1
|
||||
15 ABORT REPLACE INSERT 0 4 1
|
||||
16 ROLLBACK IGNORE INSERT 0 3 1
|
||||
12 IGNORE REPLACE INSERT 0 4 1
|
||||
13 IGNORE FAIL INSERT 1 {} 1
|
||||
14 IGNORE ABORT INSERT 1 {} 1
|
||||
15 IGNORE ROLLBACK INSERT 1 {} {}
|
||||
} {
|
||||
do_test conflict-4.$i {
|
||||
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
|
||||
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
|
||||
set r0 [catch {execsql [subst {
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a,b,c,UNIQUE(a,b) $conf1);
|
||||
DELETE FROM t2;
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
BEGIN $conf2;
|
||||
INSERT INTO t2 VALUES(1);
|
||||
$cmd INTO t1 VALUES(1,2,4);
|
||||
}]} r1]
|
||||
catch {execsql {COMMIT}}
|
||||
if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
|
||||
set r2 [execsql {SELECT x FROM t2}]
|
||||
list $r0 $r1 $r2
|
||||
} [list $t0 $t1 $t2]
|
||||
}
|
||||
|
||||
do_test conflict-5.0 {
|
||||
execsql {
|
||||
DROP TABLE t2;
|
||||
CREATE TABLE t2(x);
|
||||
SELECT x FROM t2;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Six columns of configuration data as follows:
|
||||
#
|
||||
# i The reference number of the test
|
||||
# conf1 The conflict resolution algorithm on the NOT NULL constraint
|
||||
# conf2 The conflict resolution algorithm on the BEGIN statement
|
||||
# cmd An INSERT or REPLACE command to execute against table t1
|
||||
# t0 True if there is an error from $cmd
|
||||
# t1 Content of "c" column of t1 assuming no error in $cmd
|
||||
# t2 Content of "x" column of t2
|
||||
#
|
||||
foreach {i conf1 conf2 cmd t0 t1 t2} {
|
||||
1 {} {} INSERT 1 {} 1
|
||||
2 REPLACE {} INSERT 0 5 1
|
||||
3 IGNORE {} INSERT 0 {} 1
|
||||
4 FAIL {} INSERT 1 {} 1
|
||||
5 ABORT {} INSERT 1 {} 1
|
||||
6 ROLLBACK {} INSERT 1 {} {}
|
||||
7 REPLACE {} {INSERT OR IGNORE} 0 {} 1
|
||||
8 IGNORE {} {INSERT OR REPLACE} 0 5 1
|
||||
9 FAIL {} {INSERT OR IGNORE} 0 {} 1
|
||||
10 ABORT {} {INSERT OR REPLACE} 0 5 1
|
||||
11 ROLLBACK {} {INSERT OR IGNORE} 0 {} 1
|
||||
12 {} {} {INSERT OR IGNORE} 0 {} 1
|
||||
13 {} {} {INSERT OR REPLACE} 0 5 1
|
||||
14 {} {} {INSERT OR FAIL} 1 {} 1
|
||||
15 {} {} {INSERT OR ABORT} 1 {} 1
|
||||
16 {} {} {INSERT OR ROLLBACK} 1 {} {}
|
||||
17 {} IGNORE INSERT 0 {} 1
|
||||
18 {} REPLACE INSERT 0 5 1
|
||||
19 {} FAIL INSERT 1 {} 1
|
||||
20 {} ABORT INSERT 1 {} 1
|
||||
21 {} ROLLBACK INSERT 1 {} {}
|
||||
22 REPLACE FAIL INSERT 1 {} 1
|
||||
23 IGNORE ROLLBACK INSERT 1 {} {}
|
||||
} {
|
||||
if {$t0} {set t1 {t1.c may not be NULL}}
|
||||
do_test conflict-5.$i {
|
||||
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
|
||||
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
|
||||
set r0 [catch {execsql [subst {
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5);
|
||||
DELETE FROM t2;
|
||||
BEGIN $conf2;
|
||||
INSERT INTO t2 VALUES(1);
|
||||
$cmd INTO t1 VALUES(1,2,NULL);
|
||||
}]} r1]
|
||||
catch {execsql {COMMIT}}
|
||||
if {!$r0} {set r1 [execsql {SELECT c FROM t1}]}
|
||||
set r2 [execsql {SELECT x FROM t2}]
|
||||
list $r0 $r1 $r2
|
||||
} [list $t0 $t1 $t2]
|
||||
}
|
||||
|
||||
do_test conflict-6.0 {
|
||||
execsql {
|
||||
DROP TABLE t2;
|
||||
CREATE TABLE t2(a,b,c);
|
||||
INSERT INTO t2 VALUES(1,2,1);
|
||||
INSERT INTO t2 VALUES(2,3,2);
|
||||
INSERT INTO t2 VALUES(3,4,1);
|
||||
INSERT INTO t2 VALUES(4,5,4);
|
||||
SELECT c FROM t2 ORDER BY b;
|
||||
CREATE TABLE t3(x);
|
||||
INSERT INTO t3 VALUES(1);
|
||||
}
|
||||
} {1 2 1 4}
|
||||
|
||||
# Six columns of configuration data as follows:
|
||||
#
|
||||
# i The reference number of the test
|
||||
# conf1 The conflict resolution algorithm on the UNIQUE constraint
|
||||
# conf2 The conflict resolution algorithm on the BEGIN statement
|
||||
# cmd An UPDATE command to execute against table t1
|
||||
# t0 True if there is an error from $cmd
|
||||
# t1 Content of "b" column of t1 assuming no error in $cmd
|
||||
# t2 Content of "x" column of t3
|
||||
#
|
||||
foreach {i conf1 conf2 cmd t0 t1 t2} {
|
||||
1 {} {} UPDATE 1 {6 7 8 9} 1
|
||||
2 REPLACE {} UPDATE 0 {7 6 9} 1
|
||||
3 IGNORE {} UPDATE 0 {6 7 3 9} 1
|
||||
4 FAIL {} UPDATE 1 {6 7 3 4} 1
|
||||
5 ABORT {} UPDATE 1 {1 2 3 4} 1
|
||||
6 ROLLBACK {} UPDATE 1 {1 2 3 4} 0
|
||||
7 REPLACE {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
|
||||
8 IGNORE {} {UPDATE OR REPLACE} 0 {7 6 9} 1
|
||||
9 FAIL {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
|
||||
10 ABORT {} {UPDATE OR REPLACE} 0 {7 6 9} 1
|
||||
11 ROLLBACK {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
|
||||
12 {} {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
|
||||
13 {} {} {UPDATE OR REPLACE} 0 {7 6 9} 1
|
||||
14 {} {} {UPDATE OR FAIL} 1 {6 7 3 4} 1
|
||||
15 {} {} {UPDATE OR ABORT} 1 {1 2 3 4} 1
|
||||
16 {} {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0
|
||||
17 {} IGNORE UPDATE 0 {6 7 3 9} 1
|
||||
18 {} REPLACE UPDATE 0 {7 6 9} 1
|
||||
19 {} FAIL UPDATE 1 {6 7 3 4} 1
|
||||
20 {} ABORT UPDATE 1 {1 2 3 4} 1
|
||||
21 {} ROLLBACK UPDATE 1 {1 2 3 4} 0
|
||||
22 REPLACE IGNORE UPDATE 0 {6 7 3 9} 1
|
||||
23 IGNORE REPLACE UPDATE 0 {7 6 9} 1
|
||||
24 REPLACE FAIL UPDATE 1 {6 7 3 4} 1
|
||||
25 IGNORE ABORT UPDATE 1 {1 2 3 4} 1
|
||||
26 REPLACE ROLLBACK UPDATE 1 {1 2 3 4} 0
|
||||
} {
|
||||
if {$t0} {set t1 {column a is not unique}}
|
||||
do_test conflict-6.$i {
|
||||
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
|
||||
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
|
||||
set r0 [catch {execsql [subst {
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1);
|
||||
INSERT INTO t1 SELECT * FROM t2;
|
||||
UPDATE t3 SET x=0;
|
||||
BEGIN $conf2;
|
||||
$cmd t3 SET x=1;
|
||||
$cmd t1 SET b=b*2;
|
||||
$cmd t1 SET a=c+5;
|
||||
}]} r1]
|
||||
catch {execsql {COMMIT}}
|
||||
if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]}
|
||||
set r2 [execsql {SELECT x FROM t3}]
|
||||
list $r0 $r1 $r2
|
||||
} [list $t0 $t1 $t2]
|
||||
}
|
||||
|
||||
# Test to make sure a lot of IGNOREs don't cause a stack overflow
|
||||
#
|
||||
do_test conflict-7.1 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
DROP TABLE t3;
|
||||
CREATE TABLE t1(a unique, b);
|
||||
}
|
||||
for {set i 1} {$i<=50} {incr i} {
|
||||
execsql "INSERT into t1 values($i,[expr {$i+1}]);"
|
||||
}
|
||||
execsql {
|
||||
SELECT count(*), min(a), max(b) FROM t1;
|
||||
}
|
||||
} {50 1 51}
|
||||
do_test conflict-7.2 {
|
||||
execsql {
|
||||
PRAGMA count_changes=on;
|
||||
UPDATE OR IGNORE t1 SET a=1000;
|
||||
}
|
||||
} {1}
|
||||
do_test conflict-7.2.1 {
|
||||
db changes
|
||||
} {1}
|
||||
do_test conflict-7.3 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a=1000;
|
||||
}
|
||||
} {2}
|
||||
do_test conflict-7.4 {
|
||||
execsql {
|
||||
SELECT count(*) FROM t1;
|
||||
}
|
||||
} {50}
|
||||
do_test conflict-7.5 {
|
||||
execsql {
|
||||
PRAGMA count_changes=on;
|
||||
UPDATE OR REPLACE t1 SET a=1001;
|
||||
}
|
||||
} {50}
|
||||
do_test conflict-7.5.1 {
|
||||
db changes
|
||||
} {50}
|
||||
do_test conflict-7.6 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a=1001;
|
||||
}
|
||||
} {51}
|
||||
do_test conflict-7.7 {
|
||||
execsql {
|
||||
SELECT count(*) FROM t1;
|
||||
}
|
||||
} {1}
|
||||
do_test conflict-7.7.1 {
|
||||
db changes
|
||||
} {0}
|
||||
|
||||
# Make sure the row count is right for rows that are ignored on
|
||||
# an insert.
|
||||
#
|
||||
do_test conflict-8.1 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
}
|
||||
execsql {
|
||||
INSERT OR IGNORE INTO t1 VALUES(2,3);
|
||||
}
|
||||
} {1}
|
||||
do_test conflict-8.1.1 {
|
||||
db changes
|
||||
} {1}
|
||||
do_test conflict-8.2 {
|
||||
execsql {
|
||||
INSERT OR IGNORE INTO t1 VALUES(2,4);
|
||||
}
|
||||
} {0}
|
||||
do_test conflict-8.2.1 {
|
||||
db changes
|
||||
} {0}
|
||||
do_test conflict-8.3 {
|
||||
execsql {
|
||||
INSERT OR REPLACE INTO t1 VALUES(2,4);
|
||||
}
|
||||
} {1}
|
||||
do_test conflict-8.3.1 {
|
||||
db changes
|
||||
} {1}
|
||||
do_test conflict-8.4 {
|
||||
execsql {
|
||||
INSERT OR IGNORE INTO t1 SELECT * FROM t1;
|
||||
}
|
||||
} {0}
|
||||
do_test conflict-8.4.1 {
|
||||
db changes
|
||||
} {0}
|
||||
do_test conflict-8.5 {
|
||||
execsql {
|
||||
INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1;
|
||||
}
|
||||
} {2}
|
||||
do_test conflict-8.5.1 {
|
||||
db changes
|
||||
} {2}
|
||||
do_test conflict-8.6 {
|
||||
execsql {
|
||||
INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1;
|
||||
}
|
||||
} {3}
|
||||
do_test conflict-8.6.1 {
|
||||
db changes
|
||||
} {3}
|
||||
|
||||
integrity_check conflict-8.99
|
||||
|
||||
do_test conflict-9.1 {
|
||||
execsql {
|
||||
PRAGMA count_changes=0;
|
||||
CREATE TABLE t2(
|
||||
a INTEGER UNIQUE ON CONFLICT IGNORE,
|
||||
b INTEGER UNIQUE ON CONFLICT FAIL,
|
||||
c INTEGER UNIQUE ON CONFLICT REPLACE,
|
||||
d INTEGER UNIQUE ON CONFLICT ABORT,
|
||||
e INTEGER UNIQUE ON CONFLICT ROLLBACK
|
||||
);
|
||||
CREATE TABLE t3(x);
|
||||
INSERT INTO t3 VALUES(1);
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1}
|
||||
do_test conflict-9.2 {
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(1,1,1,1,1);
|
||||
INSERT INTO t2 VALUES(2,2,2,2,2);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {0 {1 1 1 1 1 2 2 2 2 2}}
|
||||
do_test conflict-9.3 {
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(1,3,3,3,3);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {0 {1 1 1 1 1 2 2 2 2 2}}
|
||||
do_test conflict-9.4 {
|
||||
catchsql {
|
||||
UPDATE t2 SET a=a+1 WHERE a=1;
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {0 {1 1 1 1 1 2 2 2 2 2}}
|
||||
do_test conflict-9.5 {
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(3,1,3,3,3);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column b is not unique}}
|
||||
do_test conflict-9.6 {
|
||||
catchsql {
|
||||
UPDATE t2 SET b=b+1 WHERE b=1;
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column b is not unique}}
|
||||
do_test conflict-9.7 {
|
||||
catchsql {
|
||||
BEGIN;
|
||||
UPDATE t3 SET x=x+1;
|
||||
INSERT INTO t2 VALUES(3,1,3,3,3);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column b is not unique}}
|
||||
do_test conflict-9.8 {
|
||||
execsql {COMMIT}
|
||||
execsql {SELECT * FROM t3}
|
||||
} {2}
|
||||
do_test conflict-9.9 {
|
||||
catchsql {
|
||||
BEGIN;
|
||||
UPDATE t3 SET x=x+1;
|
||||
UPDATE t2 SET b=b+1 WHERE b=1;
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column b is not unique}}
|
||||
do_test conflict-9.10 {
|
||||
execsql {COMMIT}
|
||||
execsql {SELECT * FROM t3}
|
||||
} {3}
|
||||
do_test conflict-9.11 {
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(3,3,3,1,3);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column d is not unique}}
|
||||
do_test conflict-9.12 {
|
||||
catchsql {
|
||||
UPDATE t2 SET d=d+1 WHERE d=1;
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column d is not unique}}
|
||||
do_test conflict-9.13 {
|
||||
catchsql {
|
||||
BEGIN;
|
||||
UPDATE t3 SET x=x+1;
|
||||
INSERT INTO t2 VALUES(3,3,3,1,3);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column d is not unique}}
|
||||
do_test conflict-9.14 {
|
||||
execsql {COMMIT}
|
||||
execsql {SELECT * FROM t3}
|
||||
} {4}
|
||||
do_test conflict-9.15 {
|
||||
catchsql {
|
||||
BEGIN;
|
||||
UPDATE t3 SET x=x+1;
|
||||
UPDATE t2 SET d=d+1 WHERE d=1;
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column d is not unique}}
|
||||
do_test conflict-9.16 {
|
||||
execsql {COMMIT}
|
||||
execsql {SELECT * FROM t3}
|
||||
} {5}
|
||||
do_test conflict-9.17 {
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(3,3,3,3,1);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column e is not unique}}
|
||||
do_test conflict-9.18 {
|
||||
catchsql {
|
||||
UPDATE t2 SET e=e+1 WHERE e=1;
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column e is not unique}}
|
||||
do_test conflict-9.19 {
|
||||
catchsql {
|
||||
BEGIN;
|
||||
UPDATE t3 SET x=x+1;
|
||||
INSERT INTO t2 VALUES(3,3,3,3,1);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column e is not unique}}
|
||||
do_test conflict-9.20 {
|
||||
catch {execsql {COMMIT}}
|
||||
execsql {SELECT * FROM t3}
|
||||
} {5}
|
||||
do_test conflict-9.21 {
|
||||
catchsql {
|
||||
BEGIN;
|
||||
UPDATE t3 SET x=x+1;
|
||||
UPDATE t2 SET e=e+1 WHERE e=1;
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {column e is not unique}}
|
||||
do_test conflict-9.22 {
|
||||
catch {execsql {COMMIT}}
|
||||
execsql {SELECT * FROM t3}
|
||||
} {5}
|
||||
do_test conflict-9.23 {
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(3,3,1,3,3);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {0 {2 2 2 2 2 3 3 1 3 3}}
|
||||
do_test conflict-9.24 {
|
||||
catchsql {
|
||||
UPDATE t2 SET c=c-1 WHERE c=2;
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {0 {2 2 1 2 2}}
|
||||
do_test conflict-9.25 {
|
||||
catchsql {
|
||||
BEGIN;
|
||||
UPDATE t3 SET x=x+1;
|
||||
INSERT INTO t2 VALUES(3,3,1,3,3);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {0 {3 3 1 3 3}}
|
||||
do_test conflict-9.26 {
|
||||
catch {execsql {COMMIT}}
|
||||
execsql {SELECT * FROM t3}
|
||||
} {6}
|
||||
|
||||
do_test conflict-10.1 {
|
||||
catchsql {
|
||||
DELETE FROM t1;
|
||||
BEGIN ON CONFLICT ROLLBACK;
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
INSERT INTO t1 VALUES(1,3);
|
||||
COMMIT;
|
||||
}
|
||||
execsql {SELECT * FROM t1}
|
||||
} {}
|
||||
do_test conflict-10.2 {
|
||||
catchsql {
|
||||
CREATE TABLE t4(x);
|
||||
CREATE UNIQUE INDEX t4x ON t4(x);
|
||||
BEGIN ON CONFLICT ROLLBACK;
|
||||
INSERT INTO t4 VALUES(1);
|
||||
INSERT INTO t4 VALUES(1);
|
||||
COMMIT;
|
||||
}
|
||||
execsql {SELECT * FROM t4}
|
||||
} {}
|
||||
|
||||
integrity_check conflict-99.0
|
||||
|
||||
finish_test
|
||||
+122
-2
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the COPY statement.
|
||||
#
|
||||
# $Id: copy.test,v 1.6 2001/09/16 00:13:28 drh Exp $
|
||||
# $Id: copy.test,v 1.17 2004/02/17 18:26:57 dougcurrie Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -39,6 +39,15 @@ set f [open data5.txt w]
|
||||
puts $f "11|22|33"
|
||||
puts $f "22|33|11"
|
||||
close $f
|
||||
set f [open dataX.txt w]
|
||||
fconfigure $f -translation binary
|
||||
puts -nonewline $f "11|22|33\r"
|
||||
puts -nonewline $f "22|33|44\r\n"
|
||||
puts -nonewline $f "33|44|55\n"
|
||||
puts -nonewline $f "44|55|66\r"
|
||||
puts -nonewline $f "55|66|77\r\n"
|
||||
puts -nonewline $f "66|77|88\n"
|
||||
close $f
|
||||
|
||||
# Try to COPY into a non-existant table.
|
||||
#
|
||||
@@ -123,6 +132,7 @@ do_test copy-2.1 {
|
||||
execsql {COPY test2 FROM 'data21.txt'}
|
||||
execsql {SELECT x from test2}
|
||||
} $x
|
||||
file delete -force data21.txt
|
||||
|
||||
# Test the escape character mechanism
|
||||
#
|
||||
@@ -137,9 +147,119 @@ do_test copy-3.1 {
|
||||
SELECT * FROM t1 ORDER BY a;
|
||||
}
|
||||
} {hello {world 2} {hello world} 1}
|
||||
do_test copy-3.2 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "1\thello\\\nworld"
|
||||
puts $fd "2\thello world"
|
||||
close $fd
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
COPY t1 FROM 'data6.txt';
|
||||
SELECT * FROM t1 ORDER BY a;
|
||||
}
|
||||
} {1 {hello
|
||||
world} 2 {hello world}}
|
||||
do_test copy-3.3 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "1:hello\\b\\f\\n\\r\\t\\vworld"
|
||||
puts $fd "2:hello world"
|
||||
close $fd
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
COPY t1 FROM 'data6.txt' USING DELIMITERS ':';
|
||||
SELECT * FROM t1 ORDER BY a;
|
||||
}
|
||||
} [list 1 "hello\b\f\n\r\t\vworld" 2 "hello world"]
|
||||
|
||||
# Test the embedded NULL logic.
|
||||
#
|
||||
do_test copy-4.1 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "1\t\\N"
|
||||
puts $fd "\\N\thello world"
|
||||
close $fd
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
COPY t1 FROM 'data6.txt';
|
||||
SELECT * FROM t1 WHERE a IS NULL;
|
||||
}
|
||||
} {{} {hello world}}
|
||||
do_test copy-4.2 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE b IS NULL;
|
||||
}
|
||||
} {1 {}}
|
||||
|
||||
# Test the conflict resolution logic for COPY
|
||||
#
|
||||
do_test copy-5.1 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE, c);
|
||||
COPY t1 FROM 'data5.txt' USING DELIMITERS '|';
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {11 22 33 22 33 11}
|
||||
do_test copy-5.2 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "33|22|44"
|
||||
close $fd
|
||||
catchsql {
|
||||
COPY t1 FROM 'data6.txt' USING DELIMITERS '|';
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 {column b is not unique}}
|
||||
do_test copy-5.3 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "33|22|44"
|
||||
close $fd
|
||||
catchsql {
|
||||
COPY OR IGNORE t1 FROM 'data6.txt' USING DELIMITERS '|';
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 {11 22 33 22 33 11}}
|
||||
do_test copy-5.4 {
|
||||
set fd [open data6.txt w]
|
||||
puts $fd "33|22|44"
|
||||
close $fd
|
||||
catchsql {
|
||||
COPY OR REPLACE t1 FROM 'data6.txt' USING DELIMITERS '|';
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 {22 33 11 33 22 44}}
|
||||
|
||||
do_test copy-5.5 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
PRAGMA count_changes=on;
|
||||
COPY t1 FROM 'data5.txt' USING DELIMITERS '|';
|
||||
}
|
||||
} {2}
|
||||
do_test copy-5.6 {
|
||||
execsql {
|
||||
COPY OR REPLACE t1 FROM 'data5.txt' USING DELIMITERS '|';
|
||||
}
|
||||
} {2}
|
||||
do_test copy-5.7 {
|
||||
execsql {
|
||||
COPY OR IGNORE t1 FROM 'data5.txt' USING DELIMITERS '|';
|
||||
}
|
||||
} {0}
|
||||
|
||||
do_test copy-6.1 {
|
||||
execsql {
|
||||
PRAGMA count_changes=off;
|
||||
CREATE TABLE t2(a,b,c);
|
||||
COPY t2 FROM 'dataX.txt' USING DELIMITERS '|';
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {11 22 33 22 33 44 33 44 55 44 55 66 55 66 77 66 77 88}
|
||||
|
||||
integrity_check copy-7.1
|
||||
|
||||
# Cleanup
|
||||
#
|
||||
file delete -force data1.txt data2.txt data3.txt data4.txt data5.txt data21.txt
|
||||
#file delete -force data1.txt data2.txt data3.txt data4.txt data5.txt \
|
||||
data6.txt dataX.txt
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
** This program tests the ability of SQLite database to recover from a crash.
|
||||
** This program runs under Unix only, but the results are applicable to all
|
||||
** systems.
|
||||
**
|
||||
** The main process first constructs a test database, then starts creating
|
||||
** subprocesses that write to that database. Each subprocess is killed off,
|
||||
** without a chance to clean up its database connection, after a random
|
||||
** delay. This killing of the subprocesses simulates a crash or power
|
||||
** failure. The next subprocess to open the database should rollback
|
||||
** whatever operation was in process at the time of the simulated crash.
|
||||
**
|
||||
** If any problems are encountered, an error is reported and the test stops.
|
||||
** If no problems are seen after a large number of tests, we assume that
|
||||
** the rollback mechanism is working.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sched.h>
|
||||
#include "sqlite.h"
|
||||
|
||||
static void do_some_sql(int parent){
|
||||
char *zErr;
|
||||
int rc = SQLITE_OK;
|
||||
sqlite *db;
|
||||
int cnt = 0;
|
||||
static char zBig[] =
|
||||
"-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
if( access("./test.db-journal",0)==0 ){
|
||||
/*printf("pid %d: journal exists. rollback will be required\n",getpid());*/ unlink("test.db-saved");
|
||||
system("cp test.db test.db-saved");
|
||||
unlink("test.db-journal-saved");
|
||||
system("cp test.db-journal test.db-journal-saved");
|
||||
}
|
||||
db = sqlite_open("./test.db", 0, &zErr);
|
||||
if( db==0 ){
|
||||
printf("ERROR: %s\n", zErr);
|
||||
if( strcmp(zErr,"database disk image is malformed")==0 ){
|
||||
kill(parent, SIGKILL);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
srand(getpid());
|
||||
while( rc==SQLITE_OK ){
|
||||
cnt++;
|
||||
rc = sqlite_exec_printf(db,
|
||||
"INSERT INTO t1 VALUES(%d,'%d%s')", 0, 0, &zErr,
|
||||
rand(), rand(), zBig);
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
printf("ERROR #%d: %s\n", rc, zErr);
|
||||
if( rc==SQLITE_CORRUPT ){
|
||||
kill(parent, SIGKILL);
|
||||
}
|
||||
}
|
||||
printf("pid %d: cnt=%d\n", getpid(), cnt);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int i;
|
||||
sqlite *db;
|
||||
char *zErr;
|
||||
int status;
|
||||
int parent = getpid();
|
||||
|
||||
unlink("test.db");
|
||||
unlink("test.db-journal");
|
||||
db = sqlite_open("test.db", 0, &zErr);
|
||||
if( db==0 ){
|
||||
printf("Cannot initialize: %s\n", zErr);
|
||||
return 1;
|
||||
}
|
||||
sqlite_exec(db, "CREATE TABLE t1(a,b)", 0, 0, 0);
|
||||
sqlite_close(db);
|
||||
for(i=0; i<10000; i++){
|
||||
int pid = fork();
|
||||
if( pid==0 ){
|
||||
sched_yield();
|
||||
do_some_sql(parent);
|
||||
return 0;
|
||||
}
|
||||
printf("test %d, pid=%d\n", i, pid);
|
||||
usleep(rand()%10000 + 1000);
|
||||
kill(pid, SIGKILL);
|
||||
waitpid(pid, &status, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+257
@@ -0,0 +1,257 @@
|
||||
# 2003 October 31
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing date and time functions.
|
||||
#
|
||||
# $Id: date.test,v 1.7.2.1 2004/07/18 22:25:16 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
proc datetest {tnum expr result} {
|
||||
do_test date-$tnum [subst {
|
||||
execsql "SELECT coalesce($expr,'NULL')"
|
||||
}] [list $result]
|
||||
}
|
||||
|
||||
datetest 1.1 julianday('2000-01-01') 2451544.5
|
||||
datetest 1.2 julianday('1970-01-01') 2440587.5
|
||||
datetest 1.3 julianday('1910-04-20') 2418781.5
|
||||
datetest 1.4 julianday('1986-02-09') 2446470.5
|
||||
datetest 1.5 julianday('12:00:00') 2451545
|
||||
datetest 1.6 {julianday('2000-01-01 12:00:00')} 2451545
|
||||
datetest 1.7 {julianday('2000-01-01 12:00')} 2451545
|
||||
datetest 1.8 julianday('bogus') NULL
|
||||
datetest 1.9 julianday('1999-12-31') 2451543.5
|
||||
datetest 1.10 julianday('1999-12-32') NULL
|
||||
datetest 1.11 julianday('1999-13-01') NULL
|
||||
datetest 1.12 julianday('2003-02-31') 2452701.5
|
||||
datetest 1.13 julianday('2003-03-03') 2452701.5
|
||||
datetest 1.14 julianday('+2000-01-01') NULL
|
||||
datetest 1.15 julianday('200-01-01') NULL
|
||||
datetest 1.16 julianday('2000-1-01') NULL
|
||||
datetest 1.17 julianday('2000-01-1') NULL
|
||||
datetest 1.18 {julianday('2000-01-01 12:00:00')} 2451545
|
||||
datetest 1.19 {julianday('2000-01-01 12:00:00.1')} 2451545.00000116
|
||||
datetest 1.20 {julianday('2000-01-01 12:00:00.01')} 2451545.00000012
|
||||
datetest 1.21 {julianday('2000-01-01 12:00:00.001')} 2451545.00000001
|
||||
datetest 1.22 {julianday('2000-01-01 12:00:00.')} NULL
|
||||
datetest 1.23 julianday(12345.6) 12345.6
|
||||
datetest 1.24 {julianday('2001-01-01 12:00:00 bogus')} NULL
|
||||
datetest 1.25 {julianday('2001-01-01 bogus')} NULL
|
||||
|
||||
datetest 2.1 datetime(0,'unixepoch') {1970-01-01 00:00:00}
|
||||
datetest 2.2 datetime(946684800,'unixepoch') {2000-01-01 00:00:00}
|
||||
datetest 2.3 {date('2003-10-22','weekday 0')} 2003-10-26
|
||||
datetest 2.4 {date('2003-10-22','weekday 1')} 2003-10-27
|
||||
datetest 2.5 {date('2003-10-22','weekday 2')} 2003-10-28
|
||||
datetest 2.6 {date('2003-10-22','weekday 3')} 2003-10-22
|
||||
datetest 2.7 {date('2003-10-22','weekday 4')} 2003-10-23
|
||||
datetest 2.8 {date('2003-10-22','weekday 5')} 2003-10-24
|
||||
datetest 2.9 {date('2003-10-22','weekday 6')} 2003-10-25
|
||||
datetest 2.10 {date('2003-10-22','weekday 7')} NULL
|
||||
datetest 2.11 {date('2003-10-22','weekday 5.5')} NULL
|
||||
datetest 2.12 {datetime('2003-10-22 12:34','weekday 0')} {2003-10-26 12:34:00}
|
||||
datetest 2.13 {datetime('2003-10-22 12:34','start of month')} \
|
||||
{2003-10-01 00:00:00}
|
||||
datetest 2.14 {datetime('2003-10-22 12:34','start of year')} \
|
||||
{2003-01-01 00:00:00}
|
||||
datetest 2.15 {datetime('2003-10-22 12:34','start of day')} \
|
||||
{2003-10-22 00:00:00}
|
||||
datetest 2.16 time('12:34:56.43') 12:34:56
|
||||
datetest 2.17 {datetime('2003-10-22 12:34','1 day')} {2003-10-23 12:34:00}
|
||||
datetest 2.18 {datetime('2003-10-22 12:34','+1 day')} {2003-10-23 12:34:00}
|
||||
datetest 2.19 {datetime('2003-10-22 12:34','+1.25 day')} {2003-10-23 18:34:00}
|
||||
datetest 2.20 {datetime('2003-10-22 12:34','-1.0 day')} {2003-10-21 12:34:00}
|
||||
datetest 2.21 {datetime('2003-10-22 12:34','1 month')} {2003-11-22 12:34:00}
|
||||
datetest 2.22 {datetime('2003-10-22 12:34','11 month')} {2004-09-22 12:34:00}
|
||||
datetest 2.23 {datetime('2003-10-22 12:34','-13 month')} {2002-09-22 12:34:00}
|
||||
datetest 2.24 {datetime('2003-10-22 12:34','1.5 months')} {2003-12-07 12:34:00}
|
||||
datetest 2.25 {datetime('2003-10-22 12:34','-5 years')} {1998-10-22 12:34:00}
|
||||
datetest 2.26 {datetime('2003-10-22 12:34','+10.5 minutes')} \
|
||||
{2003-10-22 12:44:30}
|
||||
datetest 2.27 {datetime('2003-10-22 12:34','-1.25 hours')} \
|
||||
{2003-10-22 11:19:00}
|
||||
datetest 2.28 {datetime('2003-10-22 12:34','11.25 seconds')} \
|
||||
{2003-10-22 12:34:11}
|
||||
datetest 2.29 {datetime('2003-10-22 12:24','+5 bogus')} NULL
|
||||
|
||||
|
||||
datetest 3.1 {strftime('%d','2003-10-31 12:34:56.432')} 31
|
||||
datetest 3.2 {strftime('%f','2003-10-31 12:34:56.432')} 56.432
|
||||
datetest 3.3 {strftime('%H','2003-10-31 12:34:56.432')} 12
|
||||
datetest 3.4 {strftime('%j','2003-10-31 12:34:56.432')} 304
|
||||
datetest 3.5 {strftime('%J','2003-10-31 12:34:56.432')} 2452944.024264259
|
||||
datetest 3.6 {strftime('%m','2003-10-31 12:34:56.432')} 10
|
||||
datetest 3.7 {strftime('%M','2003-10-31 12:34:56.432')} 34
|
||||
datetest 3.8 {strftime('%s','2003-10-31 12:34:56.432')} 1067603696
|
||||
datetest 3.9 {strftime('%S','2003-10-31 12:34:56.432')} 56
|
||||
datetest 3.10 {strftime('%w','2003-10-31 12:34:56.432')} 5
|
||||
datetest 3.11.1 {strftime('%W','2003-10-31 12:34:56.432')} 43
|
||||
datetest 3.11.2 {strftime('%W','2004-01-01')} 00
|
||||
datetest 3.11.3 {strftime('%W','2004-01-02')} 00
|
||||
datetest 3.11.4 {strftime('%W','2004-01-03')} 00
|
||||
datetest 3.11.5 {strftime('%W','2004-01-04')} 00
|
||||
datetest 3.11.6 {strftime('%W','2004-01-05')} 01
|
||||
datetest 3.11.7 {strftime('%W','2004-01-06')} 01
|
||||
datetest 3.11.8 {strftime('%W','2004-01-07')} 01
|
||||
datetest 3.11.9 {strftime('%W','2004-01-08')} 01
|
||||
datetest 3.11.10 {strftime('%W','2004-01-09')} 01
|
||||
datetest 3.11.11 {strftime('%W','2004-07-18')} 28
|
||||
datetest 3.11.12 {strftime('%W','2004-12-31')} 52
|
||||
datetest 3.11.13 {strftime('%W','2007-12-31')} 53
|
||||
datetest 3.11.14 {strftime('%W','2007-01-01')} 01
|
||||
datetest 3.12 {strftime('%Y','2003-10-31 12:34:56.432')} 2003
|
||||
datetest 3.13 {strftime('%%','2003-10-31 12:34:56.432')} %
|
||||
datetest 3.14 {strftime('%_','2003-10-31 12:34:56.432')} NULL
|
||||
datetest 3.15 {strftime('%Y-%m-%d','2003-10-31')} 2003-10-31
|
||||
proc repeat {n txt} {
|
||||
set x {}
|
||||
while {$n>0} {
|
||||
append x $txt
|
||||
incr n -1
|
||||
}
|
||||
return $x
|
||||
}
|
||||
datetest 3.16 "strftime('[repeat 200 %Y]','2003-10-31')" [repeat 200 2003]
|
||||
datetest 3.17 "strftime('[repeat 200 abc%m123]','2003-10-31')" \
|
||||
[repeat 200 abc10123]
|
||||
|
||||
set now [clock format [clock seconds] -format "%Y-%m-%d" -gmt 1]
|
||||
datetest 4.1 {date('now')} $now
|
||||
|
||||
datetest 5.1 {datetime('1994-04-16 14:00:00 -05:00')} {1994-04-16 09:00:00}
|
||||
datetest 5.2 {datetime('1994-04-16 14:00:00 +05:15')} {1994-04-16 19:15:00}
|
||||
datetest 5.3 {datetime('1994-04-16 05:00:00 -08:30')} {1994-04-15 20:30:00}
|
||||
datetest 5.4 {datetime('1994-04-16 14:00:00 +11:55')} {1994-04-17 01:55:00}
|
||||
|
||||
# localtime->utc and utc->localtime conversions. These tests only work
|
||||
# if the localtime is in the US Eastern Time (the time in Charlotte, NC
|
||||
# and in New York.)
|
||||
#
|
||||
if {[clock scan [clock format 0 -format {%b %d, %Y %H:%M:%S}] -gmt 1]==-18000} {
|
||||
datetest 6.1 {datetime('2000-10-29 05:59:00','localtime')}\
|
||||
{2000-10-29 01:59:00}
|
||||
datetest 6.2 {datetime('2000-10-29 06:00:00','localtime')}\
|
||||
{2000-10-29 01:00:00}
|
||||
datetest 6.3 {datetime('2000-04-02 06:59:00','localtime')}\
|
||||
{2000-04-02 01:59:00}
|
||||
datetest 6.4 {datetime('2000-04-02 07:00:00','localtime')}\
|
||||
{2000-04-02 03:00:00}
|
||||
datetest 6.5 {datetime('2000-10-29 01:59:00','utc')} {2000-10-29 05:59:00}
|
||||
datetest 6.6 {datetime('2000-10-29 02:00:00','utc')} {2000-10-29 07:00:00}
|
||||
datetest 6.7 {datetime('2000-04-02 01:59:00','utc')} {2000-04-02 06:59:00}
|
||||
datetest 6.8 {datetime('2000-04-02 02:00:00','utc')} {2000-04-02 06:00:00}
|
||||
|
||||
datetest 6.10 {datetime('2000-01-01 12:00:00','localtime')} \
|
||||
{2000-01-01 07:00:00}
|
||||
datetest 6.11 {datetime('1969-01-01 12:00:00','localtime')} \
|
||||
{1969-01-01 07:00:00}
|
||||
datetest 6.12 {datetime('2039-01-01 12:00:00','localtime')} \
|
||||
{2039-01-01 07:00:00}
|
||||
datetest 6.13 {datetime('2000-07-01 12:00:00','localtime')} \
|
||||
{2000-07-01 08:00:00}
|
||||
datetest 6.14 {datetime('1969-07-01 12:00:00','localtime')} \
|
||||
{1969-07-01 07:00:00}
|
||||
datetest 6.15 {datetime('2039-07-01 12:00:00','localtime')} \
|
||||
{2039-07-01 07:00:00}
|
||||
set sqlite_current_time \
|
||||
[db eval {SELECT strftime('%s','2000-07-01 12:34:56')}]
|
||||
datetest 6.16 {datetime('now','localtime')} {2000-07-01 08:34:56}
|
||||
set sqlite_current_time 0
|
||||
}
|
||||
|
||||
# Date-time functions that contain NULL arguments return a NULL
|
||||
# result.
|
||||
#
|
||||
datetest 7.1 {datetime(null)} NULL
|
||||
datetest 7.2 {datetime('now',null)} NULL
|
||||
datetest 7.3 {datetime('now','localtime',null)} NULL
|
||||
datetest 7.4 {time(null)} NULL
|
||||
datetest 7.5 {time('now',null)} NULL
|
||||
datetest 7.6 {time('now','localtime',null)} NULL
|
||||
datetest 7.7 {date(null)} NULL
|
||||
datetest 7.8 {date('now',null)} NULL
|
||||
datetest 7.9 {date('now','localtime',null)} NULL
|
||||
datetest 7.10 {julianday(null)} NULL
|
||||
datetest 7.11 {julianday('now',null)} NULL
|
||||
datetest 7.12 {julianday('now','localtime',null)} NULL
|
||||
datetest 7.13 {strftime(null,'now')} NULL
|
||||
datetest 7.14 {strftime('%s',null)} NULL
|
||||
datetest 7.15 {strftime('%s','now',null)} NULL
|
||||
datetest 7.16 {strftime('%s','now','localtime',null)} NULL
|
||||
|
||||
# Test modifiers when the date begins as a julian day number - to
|
||||
# make sure the HH:MM:SS is preserved. Ticket #551.
|
||||
#
|
||||
set sqlite_current_time [db eval {SELECT strftime('%s','2003-10-22 12:34:00')}]
|
||||
datetest 8.1 {datetime('now','weekday 0')} {2003-10-26 12:34:00}
|
||||
datetest 8.2 {datetime('now','weekday 1')} {2003-10-27 12:34:00}
|
||||
datetest 8.3 {datetime('now','weekday 2')} {2003-10-28 12:34:00}
|
||||
datetest 8.4 {datetime('now','weekday 3')} {2003-10-22 12:34:00}
|
||||
datetest 8.5 {datetime('now','start of month')} {2003-10-01 00:00:00}
|
||||
datetest 8.6 {datetime('now','start of year')} {2003-01-01 00:00:00}
|
||||
datetest 8.7 {datetime('now','start of day')} {2003-10-22 00:00:00}
|
||||
datetest 8.8 {datetime('now','1 day')} {2003-10-23 12:34:00}
|
||||
datetest 8.9 {datetime('now','+1 day')} {2003-10-23 12:34:00}
|
||||
datetest 8.10 {datetime('now','+1.25 day')} {2003-10-23 18:34:00}
|
||||
datetest 8.11 {datetime('now','-1.0 day')} {2003-10-21 12:34:00}
|
||||
datetest 8.12 {datetime('now','1 month')} {2003-11-22 12:34:00}
|
||||
datetest 8.13 {datetime('now','11 month')} {2004-09-22 12:34:00}
|
||||
datetest 8.14 {datetime('now','-13 month')} {2002-09-22 12:34:00}
|
||||
datetest 8.15 {datetime('now','1.5 months')} {2003-12-07 12:34:00}
|
||||
datetest 8.16 {datetime('now','-5 years')} {1998-10-22 12:34:00}
|
||||
datetest 8.17 {datetime('now','+10.5 minutes')} {2003-10-22 12:44:30}
|
||||
datetest 8.18 {datetime('now','-1.25 hours')} {2003-10-22 11:19:00}
|
||||
datetest 8.19 {datetime('now','11.25 seconds')} {2003-10-22 12:34:11}
|
||||
set sqlite_current_time 0
|
||||
|
||||
# Negative years work. Example: '-4713-11-26' is JD 1.5.
|
||||
#
|
||||
datetest 9.1 {julianday('-4713-11-24 12:00:00')} {0}
|
||||
datetest 9.2 {julianday(datetime(5))} {5}
|
||||
datetest 9.3 {julianday(datetime(10))} {10}
|
||||
datetest 9.4 {julianday(datetime(100))} {100}
|
||||
datetest 9.5 {julianday(datetime(1000))} {1000}
|
||||
datetest 9.6 {julianday(datetime(10000))} {10000}
|
||||
datetest 9.7 {julianday(datetime(100000))} {100000}
|
||||
|
||||
# datetime() with just an HH:MM:SS correctly inserts the date 2000-01-01.
|
||||
#
|
||||
datetest 10.1 {datetime('01:02:03')} {2000-01-01 01:02:03}
|
||||
datetest 10.2 {date('01:02:03')} {2000-01-01}
|
||||
datetest 10.3 {strftime('%Y-%m-%d %H:%M','01:02:03')} {2000-01-01 01:02}
|
||||
|
||||
# Test the new HH:MM:SS modifier
|
||||
#
|
||||
datetest 11.1 {datetime('2004-02-28 20:00:00', '-01:20:30')} \
|
||||
{2004-02-28 18:39:30}
|
||||
datetest 11.2 {datetime('2004-02-28 20:00:00', '+12:30:00')} \
|
||||
{2004-02-29 08:30:00}
|
||||
datetest 11.3 {datetime('2004-02-28 20:00:00', '+12:30')} \
|
||||
{2004-02-29 08:30:00}
|
||||
datetest 11.4 {datetime('2004-02-28 20:00:00', '12:30')} \
|
||||
{2004-02-29 08:30:00}
|
||||
datetest 11.5 {datetime('2004-02-28 20:00:00', '-12:00')} \
|
||||
{2004-02-28 08:00:00}
|
||||
datetest 11.6 {datetime('2004-02-28 20:00:00', '-12:01')} \
|
||||
{2004-02-28 07:59:00}
|
||||
datetest 11.7 {datetime('2004-02-28 20:00:00', '-11:59')} \
|
||||
{2004-02-28 08:01:00}
|
||||
datetest 11.8 {datetime('2004-02-28 20:00:00', '11:59')} \
|
||||
{2004-02-29 07:59:00}
|
||||
datetest 11.9 {datetime('2004-02-28 20:00:00', '12:01')} \
|
||||
{2004-02-29 08:01:00}
|
||||
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
+138
-8
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the DELETE FROM statement.
|
||||
#
|
||||
# $Id: delete.test,v 1.9 2001/09/16 00:13:28 drh Exp $
|
||||
# $Id: delete.test,v 1.13 2003/06/15 23:42:25 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -32,7 +32,7 @@ do_test delete-2.1 {
|
||||
|
||||
# Delete selected entries from a table with and without an index.
|
||||
#
|
||||
do_test delete-3.1a {
|
||||
do_test delete-3.1.1 {
|
||||
execsql {CREATE TABLE table1(f1 int, f2 int)}
|
||||
execsql {INSERT INTO table1 VALUES(1,2)}
|
||||
execsql {INSERT INTO table1 VALUES(2,4)}
|
||||
@@ -40,19 +40,28 @@ do_test delete-3.1a {
|
||||
execsql {INSERT INTO table1 VALUES(4,16)}
|
||||
execsql {SELECT * FROM table1 ORDER BY f1}
|
||||
} {1 2 2 4 3 8 4 16}
|
||||
do_test delete-3.1b {
|
||||
do_test delete-3.1.2 {
|
||||
execsql {DELETE FROM table1 WHERE f1=3}
|
||||
} {}
|
||||
do_test delete-3.1.3 {
|
||||
execsql {SELECT * FROM table1 ORDER BY f1}
|
||||
} {1 2 2 4 4 16}
|
||||
do_test delete-3.1c {
|
||||
do_test delete-3.1.4 {
|
||||
execsql {CREATE INDEX index1 ON table1(f1)}
|
||||
execsql {PRAGMA count_changes=on}
|
||||
execsql {DELETE FROM 'table1' WHERE f1=3}
|
||||
} {0}
|
||||
do_test delete-3.1.5 {
|
||||
execsql {SELECT * FROM table1 ORDER BY f1}
|
||||
} {1 2 2 4 4 16}
|
||||
do_test delete-3.1d {
|
||||
do_test delete-3.1.6 {
|
||||
execsql {DELETE FROM table1 WHERE f1=2}
|
||||
} {1}
|
||||
do_test delete-3.1.7 {
|
||||
execsql {SELECT * FROM table1 ORDER BY f1}
|
||||
} {1 2 4 16}
|
||||
integrity_check delete-3.2
|
||||
|
||||
|
||||
# Semantic errors in the WHERE clause
|
||||
#
|
||||
@@ -66,17 +75,48 @@ do_test delete-4.2 {
|
||||
set v [catch {execsql {DELETE FROM table2 WHERE xyzzy(f1+4)}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such function: xyzzy}}
|
||||
integrity_check delete-4.3
|
||||
|
||||
# Lots of deletes
|
||||
#
|
||||
do_test delete-5.1 {
|
||||
do_test delete-5.1.1 {
|
||||
execsql {DELETE FROM table1}
|
||||
} {2}
|
||||
do_test delete-5.1.2 {
|
||||
execsql {SELECT count(*) FROM table1}
|
||||
} {}
|
||||
do_test delete-5.2 {
|
||||
} {0}
|
||||
do_test delete-5.2.1 {
|
||||
execsql {BEGIN TRANSACTION}
|
||||
for {set i 1} {$i<=200} {incr i} {
|
||||
execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])"
|
||||
}
|
||||
execsql {COMMIT}
|
||||
execsql {SELECT count(*) FROM table1}
|
||||
} {200}
|
||||
do_test delete-5.2.2 {
|
||||
execsql {DELETE FROM table1}
|
||||
} {200}
|
||||
do_test delete-5.2.3 {
|
||||
execsql {BEGIN TRANSACTION}
|
||||
for {set i 1} {$i<=200} {incr i} {
|
||||
execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])"
|
||||
}
|
||||
execsql {COMMIT}
|
||||
execsql {SELECT count(*) FROM table1}
|
||||
} {200}
|
||||
do_test delete-5.2.4 {
|
||||
execsql {PRAGMA count_changes=off}
|
||||
execsql {DELETE FROM table1}
|
||||
} {}
|
||||
do_test delete-5.2.5 {
|
||||
execsql {SELECT count(*) FROM table1}
|
||||
} {0}
|
||||
do_test delete-5.2.6 {
|
||||
execsql {BEGIN TRANSACTION}
|
||||
for {set i 1} {$i<=200} {incr i} {
|
||||
execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])"
|
||||
}
|
||||
execsql {COMMIT}
|
||||
execsql {SELECT count(*) FROM table1}
|
||||
} {200}
|
||||
do_test delete-5.3 {
|
||||
@@ -105,6 +145,8 @@ do_test delete-5.7 {
|
||||
execsql "DELETE FROM table1 WHERE f1!=48"
|
||||
execsql {SELECT f1 FROM table1 ORDER BY f1}
|
||||
} {48}
|
||||
integrity_check delete-5.8
|
||||
|
||||
|
||||
# Delete large quantities of data. We want to test the List overflow
|
||||
# mechanism in the vdbe.
|
||||
@@ -155,7 +197,95 @@ do_test delete-6.10 {
|
||||
execsql {INSERT INTO table2 VALUES(2,3)}
|
||||
execsql {SELECT f1 FROM table2}
|
||||
} {2}
|
||||
integrity_check delete-6.11
|
||||
|
||||
do_test delete-7.1 {
|
||||
execsql {
|
||||
CREATE TABLE t3(a);
|
||||
INSERT INTO t3 VALUES(1);
|
||||
INSERT INTO t3 SELECT a+1 FROM t3;
|
||||
INSERT INTO t3 SELECT a+2 FROM t3;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1 2 3 4}
|
||||
do_test delete-7.2 {
|
||||
execsql {
|
||||
CREATE TABLE cnt(del);
|
||||
INSERT INTO cnt VALUES(0);
|
||||
CREATE TRIGGER r1 AFTER DELETE ON t3 FOR EACH ROW BEGIN
|
||||
UPDATE cnt SET del=del+1;
|
||||
END;
|
||||
DELETE FROM t3 WHERE a<2;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {2 3 4}
|
||||
do_test delete-7.3 {
|
||||
execsql {
|
||||
SELECT * FROM cnt;
|
||||
}
|
||||
} {1}
|
||||
do_test delete-7.4 {
|
||||
execsql {
|
||||
DELETE FROM t3;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {}
|
||||
do_test delete-7.5 {
|
||||
execsql {
|
||||
SELECT * FROM cnt;
|
||||
}
|
||||
} {4}
|
||||
do_test delete-7.6 {
|
||||
execsql {
|
||||
INSERT INTO t3 VALUES(1);
|
||||
INSERT INTO t3 SELECT a+1 FROM t3;
|
||||
INSERT INTO t3 SELECT a+2 FROM t3;
|
||||
CREATE TABLE t4 AS SELECT * FROM t3;
|
||||
PRAGMA count_changes=ON;
|
||||
DELETE FROM t3;
|
||||
DELETE FROM t4;
|
||||
}
|
||||
} {4 4}
|
||||
integrity_check delete-7.7
|
||||
|
||||
# Make sure error messages are consistent when attempting to delete
|
||||
# from a read-only database. Ticket #304.
|
||||
#
|
||||
do_test delete-8.0 {
|
||||
execsql {
|
||||
PRAGMA count_changes=OFF;
|
||||
INSERT INTO t3 VALUES(123);
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {123}
|
||||
db close
|
||||
catch {file attributes test.db -permissions 0444}
|
||||
catch {file attributes test.db -readonly 1}
|
||||
sqlite db test.db
|
||||
do_test delete-8.1 {
|
||||
catchsql {
|
||||
DELETE FROM t3;
|
||||
}
|
||||
} {1 {attempt to write a readonly database}}
|
||||
do_test delete-8.2 {
|
||||
execsql {SELECT * FROM t3}
|
||||
} {123}
|
||||
do_test delete-8.3 {
|
||||
catchsql {
|
||||
DELETE FROM t3 WHERE 1;
|
||||
}
|
||||
} {1 {attempt to write a readonly database}}
|
||||
do_test delete-8.4 {
|
||||
execsql {SELECT * FROM t3}
|
||||
} {123}
|
||||
do_test delete-8.5 {
|
||||
catchsql {
|
||||
DELETE FROM t3 WHERE a<100;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test delete-8.6 {
|
||||
execsql {SELECT * FROM t3}
|
||||
} {123}
|
||||
integrity_check delete-8.7
|
||||
|
||||
finish_test
|
||||
|
||||
+227
-17
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing expressions.
|
||||
#
|
||||
# $Id: expr.test,v 1.15 2001/09/16 00:13:28 drh Exp $
|
||||
# $Id: expr.test,v 1.31 2004/03/03 01:51:25 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -22,8 +22,7 @@ execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)}
|
||||
execsql {INSERT INTO test1 VALUES(1,2,1.1,2.2,'hello','world')}
|
||||
proc test_expr {name settings expr result} {
|
||||
do_test $name [format {
|
||||
execsql {UPDATE test1 SET %s}
|
||||
execsql {SELECT %s FROM test1}
|
||||
execsql {BEGIN; UPDATE test1 SET %s; SELECT %s FROM test1; ROLLBACK;}
|
||||
} $settings $expr] $result
|
||||
}
|
||||
|
||||
@@ -63,11 +62,74 @@ test_expr expr-1.33 {i1=1, i2=2} {i1=1 OR i2=1} {1}
|
||||
test_expr expr-1.34 {i1=1, i2=2} {i1=2 OR i2=2} {1}
|
||||
test_expr expr-1.35 {i1=1, i2=2} {i1-i2=-1} {1}
|
||||
test_expr expr-1.36 {i1=1, i2=0} {not i1} {0}
|
||||
test_expr expr-1.37 {i1=1, i2=NULL} {not i2} {1}
|
||||
test_expr expr-1.37 {i1=1, i2=0} {not i2} {1}
|
||||
test_expr expr-1.38 {i1=1} {-i1} {-1}
|
||||
test_expr expr-1.39 {i1=1} {+i1} {1}
|
||||
test_expr expr-1.40 {i1=1, i2=2} {+(i2+i1)} {3}
|
||||
test_expr expr-1.41 {i1=1, i2=2} {-(i2+i1)} {-3}
|
||||
test_expr expr-1.42 {i1=1, i2=2} {i1|i2} {3}
|
||||
test_expr expr-1.42b {i1=1, i2=2} {4|2} {6}
|
||||
test_expr expr-1.43 {i1=1, i2=2} {i1&i2} {0}
|
||||
test_expr expr-1.43b {i1=1, i2=2} {4&5} {4}
|
||||
test_expr expr-1.44 {i1=1} {~i1} {-2}
|
||||
test_expr expr-1.45 {i1=1, i2=3} {i1<<i2} {8}
|
||||
test_expr expr-1.46 {i1=32, i2=3} {i1>>i2} {4}
|
||||
test_expr expr-1.47 {i1=9999999999, i2=8888888888} {i1<i2} 0
|
||||
test_expr expr-1.48 {i1=9999999999, i2=8888888888} {i1=i2} 0
|
||||
test_expr expr-1.49 {i1=9999999999, i2=8888888888} {i1>i2} 1
|
||||
test_expr expr-1.50 {i1=99999999999, i2=99999999998} {i1<i2} 0
|
||||
test_expr expr-1.51 {i1=99999999999, i2=99999999998} {i1=i2} 0
|
||||
test_expr expr-1.52 {i1=99999999999, i2=99999999998} {i1>i2} 1
|
||||
test_expr expr-1.53 {i1=099999999999, i2=99999999999} {i1<i2} 0
|
||||
test_expr expr-1.54 {i1=099999999999, i2=99999999999} {i1=i2} 1
|
||||
test_expr expr-1.55 {i1=099999999999, i2=99999999999} {i1>i2} 0
|
||||
test_expr expr-1.56 {i1=25, i2=11} {i1%i2} 3
|
||||
test_expr expr-1.58 {i1=NULL, i2=1} {coalesce(i1+i2,99)} 99
|
||||
test_expr expr-1.59 {i1=1, i2=NULL} {coalesce(i1+i2,99)} 99
|
||||
test_expr expr-1.60 {i1=NULL, i2=NULL} {coalesce(i1+i2,99)} 99
|
||||
test_expr expr-1.61 {i1=NULL, i2=1} {coalesce(i1-i2,99)} 99
|
||||
test_expr expr-1.62 {i1=1, i2=NULL} {coalesce(i1-i2,99)} 99
|
||||
test_expr expr-1.63 {i1=NULL, i2=NULL} {coalesce(i1-i2,99)} 99
|
||||
test_expr expr-1.64 {i1=NULL, i2=1} {coalesce(i1*i2,99)} 99
|
||||
test_expr expr-1.65 {i1=1, i2=NULL} {coalesce(i1*i2,99)} 99
|
||||
test_expr expr-1.66 {i1=NULL, i2=NULL} {coalesce(i1*i2,99)} 99
|
||||
test_expr expr-1.67 {i1=NULL, i2=1} {coalesce(i1/i2,99)} 99
|
||||
test_expr expr-1.68 {i1=1, i2=NULL} {coalesce(i1/i2,99)} 99
|
||||
test_expr expr-1.69 {i1=NULL, i2=NULL} {coalesce(i1/i2,99)} 99
|
||||
test_expr expr-1.70 {i1=NULL, i2=1} {coalesce(i1<i2,99)} 99
|
||||
test_expr expr-1.71 {i1=1, i2=NULL} {coalesce(i1>i2,99)} 99
|
||||
test_expr expr-1.72 {i1=NULL, i2=NULL} {coalesce(i1<=i2,99)} 99
|
||||
test_expr expr-1.73 {i1=NULL, i2=1} {coalesce(i1>=i2,99)} 99
|
||||
test_expr expr-1.74 {i1=1, i2=NULL} {coalesce(i1!=i2,99)} 99
|
||||
test_expr expr-1.75 {i1=NULL, i2=NULL} {coalesce(i1==i2,99)} 99
|
||||
test_expr expr-1.76 {i1=NULL, i2=NULL} {coalesce(not i1,99)} 99
|
||||
test_expr expr-1.77 {i1=NULL, i2=NULL} {coalesce(-i1,99)} 99
|
||||
test_expr expr-1.78 {i1=NULL, i2=NULL} {coalesce(i1 IS NULL AND i2=5,99)} 99
|
||||
test_expr expr-1.79 {i1=NULL, i2=NULL} {coalesce(i1 IS NULL OR i2=5,99)} 1
|
||||
test_expr expr-1.80 {i1=NULL, i2=NULL} {coalesce(i1=5 AND i2 IS NULL,99)} 99
|
||||
test_expr expr-1.81 {i1=NULL, i2=NULL} {coalesce(i1=5 OR i2 IS NULL,99)} 1
|
||||
test_expr expr-1.82 {i1=NULL, i2=3} {coalesce(min(i1,i2,1),99)} 99
|
||||
test_expr expr-1.83 {i1=NULL, i2=3} {coalesce(max(i1,i2,1),99)} 99
|
||||
test_expr expr-1.84 {i1=3, i2=NULL} {coalesce(min(i1,i2,1),99)} 99
|
||||
test_expr expr-1.85 {i1=3, i2=NULL} {coalesce(max(i1,i2,1),99)} 99
|
||||
test_expr expr-1.86 {i1=3, i2=8} {5 between i1 and i2} 1
|
||||
test_expr expr-1.87 {i1=3, i2=8} {5 not between i1 and i2} 0
|
||||
test_expr expr-1.88 {i1=3, i2=8} {55 between i1 and i2} 0
|
||||
test_expr expr-1.89 {i1=3, i2=8} {55 not between i1 and i2} 1
|
||||
test_expr expr-1.90 {i1=3, i2=NULL} {5 between i1 and i2} {{}}
|
||||
test_expr expr-1.91 {i1=3, i2=NULL} {5 not between i1 and i2} {{}}
|
||||
test_expr expr-1.92 {i1=3, i2=NULL} {2 between i1 and i2} 0
|
||||
test_expr expr-1.93 {i1=3, i2=NULL} {2 not between i1 and i2} 1
|
||||
test_expr expr-1.94 {i1=NULL, i2=8} {2 between i1 and i2} {{}}
|
||||
test_expr expr-1.95 {i1=NULL, i2=8} {2 not between i1 and i2} {{}}
|
||||
test_expr expr-1.94 {i1=NULL, i2=8} {55 between i1 and i2} 0
|
||||
test_expr expr-1.95 {i1=NULL, i2=8} {55 not between i1 and i2} 1
|
||||
test_expr expr-1.96 {i1=NULL, i2=3} {coalesce(i1<<i2,99)} 99
|
||||
test_expr expr-1.97 {i1=32, i2=NULL} {coalesce(i1>>i2,99)} 99
|
||||
test_expr expr-1.98 {i1=NULL, i2=NULL} {coalesce(i1|i2,99)} 99
|
||||
test_expr expr-1.99 {i1=32, i2=NULL} {coalesce(i1&i2,99)} 99
|
||||
test_expr expr-1.100 {i1=1, i2=''} {i1=i2} 0
|
||||
test_expr expr-1.101 {i1=0, i2=''} {i1=i2} 0
|
||||
|
||||
test_expr expr-2.1 {r1=1.23, r2=2.34} {r1+r2} 3.57
|
||||
test_expr expr-2.2 {r1=1.23, r2=2.34} {r1-r2} -1.11
|
||||
@@ -92,6 +154,8 @@ test_expr expr-2.20 {r1=2.34, r2=2.34} {r2<>r1} 0
|
||||
test_expr expr-2.21 {r1=2.34, r2=2.34} {r2==r1} 1
|
||||
test_expr expr-2.22 {r1=1.23, r2=2.34} {min(r1,r2,r1+r2,r1-r2)} {-1.11}
|
||||
test_expr expr-2.23 {r1=1.23, r2=2.34} {max(r1,r2,r1+r2,r1-r2)} {3.57}
|
||||
test_expr expr-2.24 {r1=25.0, r2=11.0} {r1%r2} 3
|
||||
test_expr expr-2.25 {r1=1.23, r2=NULL} {coalesce(r1+r2,99.0)} 99.0
|
||||
|
||||
test_expr expr-3.1 {t1='abc', t2='xyz'} {t1<t2} 1
|
||||
test_expr expr-3.2 {t1='xyz', t2='abc'} {t1<t2} 0
|
||||
@@ -118,18 +182,49 @@ test_expr expr-3.22 {t1='abc', t2='xyz'} {t1!=t2} 1
|
||||
test_expr expr-3.23 {t1='xyz', t2='abc'} {t1!=t2} 1
|
||||
test_expr expr-3.24 {t1='abc', t2='abc'} {t1!=t2} 0
|
||||
test_expr expr-3.25 {t1=NULL, t2='hi'} {t1 isnull} 1
|
||||
test_expr expr-3.25b {t1=NULL, t2='hi'} {t1 is null} 1
|
||||
test_expr expr-3.26 {t1=NULL, t2='hi'} {t2 isnull} 0
|
||||
test_expr expr-3.27 {t1=NULL, t2='hi'} {t1 notnull} 0
|
||||
test_expr expr-3.28 {t1=NULL, t2='hi'} {t2 notnull} 1
|
||||
test_expr expr-3.28b {t1=NULL, t2='hi'} {t2 is not null} 1
|
||||
test_expr expr-3.29 {t1='xyz', t2='abc'} {t1||t2} {xyzabc}
|
||||
test_expr expr-3.30 {t1=NULL, t2='abc'} {t1||t2} {abc}
|
||||
test_expr expr-3.31 {t1='xyz', t2=NULL} {t1||t2} {xyz}
|
||||
test_expr expr-3.30 {t1=NULL, t2='abc'} {t1||t2} {{}}
|
||||
test_expr expr-3.31 {t1='xyz', t2=NULL} {t1||t2} {{}}
|
||||
test_expr expr-3.32 {t1='xyz', t2='abc'} {t1||' hi '||t2} {{xyz hi abc}}
|
||||
test_expr epxr-3.33 {t1='abc', t2=NULL} {coalesce(t1<t2,99)} 99
|
||||
test_expr epxr-3.34 {t1='abc', t2=NULL} {coalesce(t2<t1,99)} 99
|
||||
test_expr epxr-3.35 {t1='abc', t2=NULL} {coalesce(t1>t2,99)} 99
|
||||
test_expr epxr-3.36 {t1='abc', t2=NULL} {coalesce(t2>t1,99)} 99
|
||||
test_expr epxr-3.37 {t1='abc', t2=NULL} {coalesce(t1<=t2,99)} 99
|
||||
test_expr epxr-3.38 {t1='abc', t2=NULL} {coalesce(t2<=t1,99)} 99
|
||||
test_expr epxr-3.39 {t1='abc', t2=NULL} {coalesce(t1>=t2,99)} 99
|
||||
test_expr epxr-3.40 {t1='abc', t2=NULL} {coalesce(t2>=t1,99)} 99
|
||||
test_expr epxr-3.41 {t1='abc', t2=NULL} {coalesce(t1==t2,99)} 99
|
||||
test_expr epxr-3.42 {t1='abc', t2=NULL} {coalesce(t2==t1,99)} 99
|
||||
test_expr epxr-3.43 {t1='abc', t2=NULL} {coalesce(t1!=t2,99)} 99
|
||||
test_expr epxr-3.44 {t1='abc', t2=NULL} {coalesce(t2!=t1,99)} 99
|
||||
|
||||
|
||||
test_expr expr-4.1 {t1='abc', t2='Abc'} {t1<t2} 0
|
||||
test_expr expr-4.2 {t1='abc', t2='Abc'} {t1>t2} 1
|
||||
test_expr expr-4.3 {t1='abc', t2='Bbc'} {t1<t2} 1
|
||||
test_expr expr-4.4 {t1='abc', t2='Bbc'} {t1>t2} 0
|
||||
test_expr expr-4.3 {t1='abc', t2='Bbc'} {t1<t2} 0
|
||||
test_expr expr-4.4 {t1='abc', t2='Bbc'} {t1>t2} 1
|
||||
test_expr expr-4.5 {t1='0', t2='0.0'} {t1==t2} 0
|
||||
test_expr expr-4.6 {t1='0.000', t2='0.0'} {t1==t2} 0
|
||||
test_expr expr-4.7 {t1=' 0.000', t2=' 0.0'} {t1==t2} 0
|
||||
test_expr expr-4.8 {t1='0.0', t2='abc'} {t1<t2} 1
|
||||
test_expr expr-4.9 {t1='0.0', t2='abc'} {t1==t2} 0
|
||||
test_expr expr-4.10 {r1='0.0', r2='abc'} {r1>r2} 0
|
||||
test_expr expr-4.11 {r1='abc', r2='Abc'} {r1<r2} 0
|
||||
test_expr expr-4.12 {r1='abc', r2='Abc'} {r1>r2} 1
|
||||
test_expr expr-4.13 {r1='abc', r2='Bbc'} {r1<r2} 0
|
||||
test_expr expr-4.14 {r1='abc', r2='Bbc'} {r1>r2} 1
|
||||
test_expr expr-4.15 {r1='0', r2='0.0'} {r1==r2} 1
|
||||
test_expr expr-4.16 {r1='0.000', r2='0.0'} {r1==r2} 1
|
||||
test_expr expr-4.17 {r1=' 0.000', r2=' 0.0'} {r1==r2} 0
|
||||
test_expr expr-4.18 {r1='0.0', r2='abc'} {r1<r2} 1
|
||||
test_expr expr-4.19 {r1='0.0', r2='abc'} {r1==r2} 0
|
||||
test_expr expr-4.20 {r1='0.0', r2='abc'} {r1>r2} 0
|
||||
|
||||
test_expr expr-5.1 {t1='abc', t2='xyz'} {t1 LIKE t2} 0
|
||||
test_expr expr-5.2 {t1='abc', t2='ABC'} {t1 LIKE t2} 1
|
||||
@@ -182,6 +277,11 @@ if {[sqlite -encoding]=="iso8859"} {
|
||||
test_expr expr-5.53 "t1='ax\241', t2='A_%'" {t1 LIKE t2} 1
|
||||
}
|
||||
}
|
||||
test_expr expr-5.54 {t1='abc', t2=NULL} {t1 LIKE t2} {{}}
|
||||
test_expr expr-5.55 {t1='abc', t2=NULL} {t1 NOT LIKE t2} {{}}
|
||||
test_expr expr-5.56 {t1='abc', t2=NULL} {t2 LIKE t1} {{}}
|
||||
test_expr expr-5.57 {t1='abc', t2=NULL} {t2 NOT LIKE t1} {{}}
|
||||
|
||||
|
||||
test_expr expr-6.1 {t1='abc', t2='xyz'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.2 {t1='abc', t2='ABC'} {t1 GLOB t2} 0
|
||||
@@ -203,12 +303,17 @@ test_expr expr-6.17 {t1='abc', t2='a[A-Dc]c'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.18 {t1='abc', t2='a[^A-Dc]c'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.19 {t1='abc', t2='a[]b]c'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.20 {t1='abc', t2='a[^]b]c'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.21 {t1='abcdefg', t2='a*[de]g'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.22 {t1='abcdefg', t2='a*[^de]g'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.21a {t1='abcdefg', t2='a*[de]g'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.21b {t1='abcdefg', t2='a*[df]g'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.21c {t1='abcdefg', t2='a*[d-h]g'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.21d {t1='abcdefg', t2='a*[b-e]g'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.22a {t1='abcdefg', t2='a*[^de]g'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.22b {t1='abcdefg', t2='a*[^def]g'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.23 {t1='abcdefg', t2='a*?g'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.24 {t1='ac', t2='a*c'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.25 {t1='ac', t2='a*?c'} {t1 GLOB t2} 0
|
||||
|
||||
|
||||
# These tests only work on versions of TCL that support Unicode
|
||||
#
|
||||
if {"\u1234"!="u1234" && [sqlite -encoding]=="UTF-8"} {
|
||||
@@ -230,6 +335,35 @@ if {"\u1234"!="u1234" && [sqlite -encoding]=="UTF-8"} {
|
||||
test_expr expr-6.41 "t1='a\u1234b', t2='a\[a-\u1233\]b'" {t1 GLOB t2} 0
|
||||
}
|
||||
|
||||
test_expr expr-6.51 {t1='ABC', t2='xyz'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.52 {t1='ABC', t2='abc'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.53 {t1='ABC', t2='a?c'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.54 {t1='ABC', t2='A?C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.55 {t1='ABC', t2='abc?'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.56 {t1='ABC', t2='a*c'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.57 {t1='ABC', t2='A*C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.58 {t1='ABxyzzyC', t2='A*C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.59 {t1='ABxyzzy', t2='A*C'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.60 {t1='ABxyzzyCx', t2='A*C'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.61 {t1='ABC', t2='xyz'} {t1 NOT GLOB t2} 1
|
||||
test_expr expr-6.62 {t1='ABC', t2='ABC'} {t1 NOT GLOB t2} 0
|
||||
test_expr expr-6.63 {t1='ABC', t2='A[Bx]C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.64 {t1='ABC', t2='A[Cx]C'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.65 {t1='ABC', t2='A[A-D]C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.66 {t1='ABC', t2='A[^A-D]C'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.67 {t1='ABC', t2='A[a-dC]C'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.68 {t1='ABC', t2='A[^a-dC]C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.69a {t1='ABC', t2='A[]B]C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.69b {t1='A]C', t2='A[]B]C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.70a {t1='ABC', t2='A[^]B]C'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.70b {t1='AxC', t2='A[^]B]C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.70c {t1='A]C', t2='A[^]B]C'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.71 {t1='ABCDEFG', t2='A*[DE]G'} {t1 GLOB t2} 0
|
||||
test_expr expr-6.72 {t1='ABCDEFG', t2='A*[^DE]G'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.73 {t1='ABCDEFG', t2='A*?G'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.74 {t1='AC', t2='A*C'} {t1 GLOB t2} 1
|
||||
test_expr expr-6.75 {t1='AC', t2='A*?C'} {t1 GLOB t2} 0
|
||||
|
||||
# Theses tests are for when SQLite assumes iso8859 characters.
|
||||
#
|
||||
if {[sqlite -encoding]=="iso8859"} {
|
||||
@@ -256,6 +390,40 @@ if {[sqlite -encoding]=="iso8859"} {
|
||||
test_expr expr-6.62 "t1='a\266b', t2='a\[x-\265\]b'" {t1 GLOB t2} 0
|
||||
}
|
||||
}
|
||||
test_expr expr-6.63 {t1=NULL, t2='a*?c'} {t1 GLOB t2} {{}}
|
||||
test_expr expr-6.64 {t1='ac', t2=NULL} {t1 GLOB t2} {{}}
|
||||
test_expr expr-6.65 {t1=NULL, t2='a*?c'} {t1 NOT GLOB t2} {{}}
|
||||
test_expr expr-6.66 {t1='ac', t2=NULL} {t1 NOT GLOB t2} {{}}
|
||||
|
||||
test_expr expr-case.1 {i1=1, i2=2} \
|
||||
{CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} ne
|
||||
test_expr expr-case.2 {i1=2, i2=2} \
|
||||
{CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} eq
|
||||
test_expr expr-case.3 {i1=NULL, i2=2} \
|
||||
{CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} ne
|
||||
test_expr expr-case.4 {i1=2, i2=NULL} \
|
||||
{CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} ne
|
||||
test_expr expr-case.5 {i1=2} \
|
||||
{CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'error' END} two
|
||||
test_expr expr-case.6 {i1=1} \
|
||||
{CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} one
|
||||
test_expr expr-case.7 {i1=2} \
|
||||
{CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} error
|
||||
test_expr expr-case.8 {i1=3} \
|
||||
{CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} error
|
||||
test_expr expr-case.9 {i1=3} \
|
||||
{CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'error' END} error
|
||||
test_expr expr-case.10 {i1=3} \
|
||||
{CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' END} {{}}
|
||||
test_expr expr-case.11 {i1=null} \
|
||||
{CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 3 END} 3
|
||||
test_expr expr-case.12 {i1=1} \
|
||||
{CASE i1 WHEN 1 THEN null WHEN 2 THEN 'two' ELSE 3 END} {{}}
|
||||
test_expr expr-case.13 {i1=7} \
|
||||
{ CASE WHEN i1 < 5 THEN 'low'
|
||||
WHEN i1 < 10 THEN 'medium'
|
||||
WHEN i1 < 15 THEN 'high' ELSE 'error' END} medium
|
||||
|
||||
|
||||
# The sqliteExprIfFalse and sqliteExprIfTrue routines are only
|
||||
# executed as part of a WHERE clause. Create a table suitable
|
||||
@@ -280,8 +448,8 @@ proc test_expr2 {name expr result} {
|
||||
test_expr2 expr-7.2 {a<10 AND a>8} {9}
|
||||
test_expr2 expr-7.3 {a<=10 AND a>=8} {8 9 10}
|
||||
test_expr2 expr-7.4 {a>=8 AND a<=10} {8 9 10}
|
||||
test_expr2 expr-7.5 {a>=20 OR a<=1} {{} 1 20}
|
||||
test_expr2 expr-7.6 {b!=4 AND a<=3} {{} 1 3}
|
||||
test_expr2 expr-7.5 {a>=20 OR a<=1} {1 20}
|
||||
test_expr2 expr-7.6 {b!=4 AND a<=3} {1 3}
|
||||
test_expr2 expr-7.7 {b==8 OR b==16 OR b==32} {3 4 5}
|
||||
test_expr2 expr-7.8 {NOT b<>8 OR b==1024} {3 10}
|
||||
test_expr2 expr-7.9 {b LIKE '10%'} {10 20}
|
||||
@@ -292,18 +460,60 @@ test_expr2 expr-7.13 {b GLOB '*1[456]'} {4}
|
||||
test_expr2 expr-7.14 {a ISNULL} {{}}
|
||||
test_expr2 expr-7.15 {a NOTNULL AND a<3} {1 2}
|
||||
test_expr2 expr-7.16 {a AND a<3} {1 2}
|
||||
test_expr2 expr-7.17 {NOT a} {{}}
|
||||
test_expr2 expr-7.17 {NOT a} {}
|
||||
test_expr2 expr-7.18 {a==11 OR (b>1000 AND b<2000)} {10 11}
|
||||
test_expr2 expr-7.19 {a<=1 OR a>=20} {{} 1 20}
|
||||
test_expr2 expr-7.20 {a<1 OR a>20} {{}}
|
||||
test_expr2 expr-7.21 {a>19 OR a<1} {{} 20}
|
||||
test_expr2 expr-7.19 {a<=1 OR a>=20} {1 20}
|
||||
test_expr2 expr-7.20 {a<1 OR a>20} {}
|
||||
test_expr2 expr-7.21 {a>19 OR a<1} {20}
|
||||
test_expr2 expr-7.22 {a!=1 OR a=100} \
|
||||
{{} 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
|
||||
{2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
|
||||
test_expr2 expr-7.23 {(a notnull AND a<4) OR a==8} {1 2 3 8}
|
||||
test_expr2 expr-7.24 {a LIKE '2_' OR a==8} {8 20}
|
||||
test_expr2 expr-7.25 {a GLOB '2?' OR a==8} {8 20}
|
||||
test_expr2 expr-7.26 {a isnull OR a=8} {{} 8}
|
||||
test_expr2 expr-7.27 {a notnull OR a=8} \
|
||||
{1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
|
||||
test_expr2 expr-7.28 {a<0 OR b=0} {{}}
|
||||
test_expr2 expr-7.29 {b=0 OR a<0} {{}}
|
||||
test_expr2 expr-7.30 {a<0 AND b=0} {}
|
||||
test_expr2 expr-7.31 {b=0 AND a<0} {}
|
||||
test_expr2 expr-7.32 {a IS NULL AND (a<0 OR b=0)} {{}}
|
||||
test_expr2 expr-7.33 {a IS NULL AND (b=0 OR a<0)} {{}}
|
||||
test_expr2 expr-7.34 {a IS NULL AND (a<0 AND b=0)} {}
|
||||
test_expr2 expr-7.35 {a IS NULL AND (b=0 AND a<0)} {}
|
||||
test_expr2 expr-7.32 {(a<0 OR b=0) AND a IS NULL} {{}}
|
||||
test_expr2 expr-7.33 {(b=0 OR a<0) AND a IS NULL} {{}}
|
||||
test_expr2 expr-7.34 {(a<0 AND b=0) AND a IS NULL} {}
|
||||
test_expr2 expr-7.35 {(b=0 AND a<0) AND a IS NULL} {}
|
||||
test_expr2 expr-7.36 {a<2 OR (a<0 OR b=0)} {{} 1}
|
||||
test_expr2 expr-7.37 {a<2 OR (b=0 OR a<0)} {{} 1}
|
||||
test_expr2 expr-7.38 {a<2 OR (a<0 AND b=0)} {1}
|
||||
test_expr2 expr-7.39 {a<2 OR (b=0 AND a<0)} {1}
|
||||
test_expr2 expr-7.40 {((a<2 OR a IS NULL) AND b<3) OR b>1e10} {{} 1}
|
||||
test_expr2 expr-7.41 {a BETWEEN -1 AND 1} {1}
|
||||
test_expr2 expr-7.42 {a NOT BETWEEN 2 AND 100} {1}
|
||||
test_expr2 expr-7.43 {(b+1234)||'this is a string that is at least 32 characters long' BETWEEN 1 AND 2} {}
|
||||
test_expr2 expr-7.44 {123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a BETWEEN '123a' AND '123b'} {}
|
||||
test_expr2 expr-7.45 {((123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a) BETWEEN '123a' AND '123b')<0} {}
|
||||
test_expr2 expr-7.46 {((123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a) BETWEEN '123a' AND '123z')>0} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
|
||||
|
||||
test_expr2 expr-7.50 {((a between 1 and 2 OR 0) AND 1) OR 0} {1 2}
|
||||
test_expr2 expr-7.51 {((a not between 3 and 100 OR 0) AND 1) OR 0} {1 2}
|
||||
test_expr2 expr-7.52 {((a in (1,2) OR 0) AND 1) OR 0} {1 2}
|
||||
test_expr2 expr-7.53 {((a not in (3,4,5,6,7,8,9,10) OR 0) AND a<11) OR 0} {1 2}
|
||||
test_expr2 expr-7.54 {((a>0 OR 0) AND a<3) OR 0} {1 2}
|
||||
test_expr2 expr-7.55 {((a in (1,2) OR 0) IS NULL AND 1) OR 0} {{}}
|
||||
test_expr2 expr-7.56 {((a not in (3,4,5,6,7,8,9,10) IS NULL OR 0) AND 1) OR 0} \
|
||||
{{}}
|
||||
test_expr2 expr-7.57 {((a>0 IS NULL OR 0) AND 1) OR 0} {{}}
|
||||
|
||||
test_expr2 expr-7.58 {(a||'')<='1'} {1}
|
||||
|
||||
test_expr2 expr-7.59 {LIKE('10%',b)} {10 20}
|
||||
test_expr2 expr-7.60 {LIKE('_4',b)} {6}
|
||||
test_expr2 expr-7.61 {GLOB('1?',a)} {10 11 12 13 14 15 16 17 18 19}
|
||||
test_expr2 expr-7.62 {GLOB('1*4',b)} {10 14}
|
||||
test_expr2 expr-7.63 {GLOB('*1[456]',b)} {4}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# 2001 September 15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
# This file implements tests for foreign keys.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Create a table and some data to work with.
|
||||
#
|
||||
do_test fkey1-1.0 {
|
||||
execsql {
|
||||
CREATE TABLE t1(
|
||||
a INTEGER PRIMARY KEY,
|
||||
b INTEGER
|
||||
REFERENCES t1 ON DELETE CASCADE
|
||||
REFERENCES t2,
|
||||
c TEXT,
|
||||
FOREIGN KEY (b,c) REFERENCES t2(x,y) ON UPDATE CASCADE
|
||||
);
|
||||
}
|
||||
} {}
|
||||
do_test fkey1-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t2(
|
||||
x INTEGER PRIMARY KEY,
|
||||
y TEXT
|
||||
);
|
||||
}
|
||||
} {}
|
||||
do_test fkey1-1.2 {
|
||||
execsql {
|
||||
CREATE TABLE t3(
|
||||
a INTEGER REFERENCES t2,
|
||||
b INTEGER REFERENCES t1,
|
||||
FOREIGN KEY (a,b) REFERENCES t2(x,y)
|
||||
);
|
||||
}
|
||||
} {}
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,738 @@
|
||||
# 2001 September 15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the the library is able to correctly
|
||||
# handle file-format 3 (version 2.6.x) databases.
|
||||
#
|
||||
# $Id: format3.test,v 1.4 2003/12/23 02:17:35 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Create a bunch of data to sort against
|
||||
#
|
||||
do_test format3-1.0 {
|
||||
set fd [open data.txt w]
|
||||
puts $fd "1\tone\t0\tI\t3.141592653"
|
||||
puts $fd "2\ttwo\t1\tII\t2.15"
|
||||
puts $fd "3\tthree\t1\tIII\t4221.0"
|
||||
puts $fd "4\tfour\t2\tIV\t-0.0013442"
|
||||
puts $fd "5\tfive\t2\tV\t-11"
|
||||
puts $fd "6\tsix\t2\tVI\t0.123"
|
||||
puts $fd "7\tseven\t2\tVII\t123.0"
|
||||
puts $fd "8\teight\t3\tVIII\t-1.6"
|
||||
close $fd
|
||||
execsql {
|
||||
CREATE TABLE t1(
|
||||
n int,
|
||||
v varchar(10),
|
||||
log int,
|
||||
roman varchar(10),
|
||||
flt real
|
||||
);
|
||||
COPY t1 FROM 'data.txt'
|
||||
}
|
||||
file delete data.txt
|
||||
db close
|
||||
set ::bt [btree_open test.db]
|
||||
btree_begin_transaction $::bt
|
||||
set m [btree_get_meta $::bt]
|
||||
set m [lreplace $m 2 2 3]
|
||||
eval btree_update_meta $::bt $m
|
||||
btree_commit $::bt
|
||||
btree_close $::bt
|
||||
sqlite db test.db
|
||||
execsql {SELECT count(*) FROM t1}
|
||||
} {8}
|
||||
|
||||
do_test format3-1.1 {
|
||||
execsql {SELECT n FROM t1 ORDER BY n}
|
||||
} {1 2 3 4 5 6 7 8}
|
||||
do_test format3-1.1.1 {
|
||||
execsql {SELECT n FROM t1 ORDER BY n ASC}
|
||||
} {1 2 3 4 5 6 7 8}
|
||||
do_test format3-1.1.1 {
|
||||
execsql {SELECT ALL n FROM t1 ORDER BY n ASC}
|
||||
} {1 2 3 4 5 6 7 8}
|
||||
do_test format3-1.2 {
|
||||
execsql {SELECT n FROM t1 ORDER BY n DESC}
|
||||
} {8 7 6 5 4 3 2 1}
|
||||
do_test format3-1.3a {
|
||||
execsql {SELECT v FROM t1 ORDER BY v}
|
||||
} {eight five four one seven six three two}
|
||||
do_test format3-1.3b {
|
||||
execsql {SELECT n FROM t1 ORDER BY v}
|
||||
} {8 5 4 1 7 6 3 2}
|
||||
do_test format3-1.4 {
|
||||
execsql {SELECT n FROM t1 ORDER BY v DESC}
|
||||
} {2 3 6 7 1 4 5 8}
|
||||
do_test format3-1.5 {
|
||||
execsql {SELECT flt FROM t1 ORDER BY flt}
|
||||
} {-11 -1.6 -0.0013442 0.123 2.15 3.141592653 123.0 4221.0}
|
||||
do_test format3-1.6 {
|
||||
execsql {SELECT flt FROM t1 ORDER BY flt DESC}
|
||||
} {4221.0 123.0 3.141592653 2.15 0.123 -0.0013442 -1.6 -11}
|
||||
do_test format3-1.7 {
|
||||
execsql {SELECT roman FROM t1 ORDER BY roman}
|
||||
} {I II III IV V VI VII VIII}
|
||||
do_test format3-1.8 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log, flt}
|
||||
} {1 2 3 5 4 6 7 8}
|
||||
do_test format3-1.8.1 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log asc, flt}
|
||||
} {1 2 3 5 4 6 7 8}
|
||||
do_test format3-1.8.2 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log, flt ASC}
|
||||
} {1 2 3 5 4 6 7 8}
|
||||
do_test format3-1.8.3 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log ASC, flt asc}
|
||||
} {1 2 3 5 4 6 7 8}
|
||||
do_test format3-1.9 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log, flt DESC}
|
||||
} {1 3 2 7 6 4 5 8}
|
||||
do_test format3-1.9.1 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log ASC, flt DESC}
|
||||
} {1 3 2 7 6 4 5 8}
|
||||
do_test format3-1.10 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log DESC, flt}
|
||||
} {8 5 4 6 7 2 3 1}
|
||||
do_test format3-1.11 {
|
||||
execsql {SELECT n FROM t1 ORDER BY log DESC, flt DESC}
|
||||
} {8 7 6 4 5 3 2 1}
|
||||
|
||||
# These tests are designed to reach some hard-to-reach places
|
||||
# inside the string comparison routines.
|
||||
#
|
||||
# (Later) The sorting behavior changed in 2.7.0. But we will
|
||||
# keep these tests. You can never have too many test cases!
|
||||
#
|
||||
do_test format3-2.1.1 {
|
||||
execsql {
|
||||
UPDATE t1 SET v='x' || -flt;
|
||||
UPDATE t1 SET v='x-2b' where v=='x-0.123';
|
||||
SELECT v FROM t1 ORDER BY v;
|
||||
}
|
||||
} {x-123 x-2.15 x-2b x-3.141592653 x-4221 x0.0013442 x1.6 x11}
|
||||
do_test format3-2.1.2 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY substr(v,2,999);
|
||||
}
|
||||
} {x-4221 x-123 x-3.141592653 x-2.15 x0.0013442 x1.6 x11 x-2b}
|
||||
do_test format3-2.1.3 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY substr(v,2,999)+0.0;
|
||||
}
|
||||
} {x-4221 x-123 x-3.141592653 x-2.15 x-2b x0.0013442 x1.6 x11}
|
||||
do_test format3-2.1.4 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY substr(v,2,999) DESC;
|
||||
}
|
||||
} {x-2b x11 x1.6 x0.0013442 x-2.15 x-3.141592653 x-123 x-4221}
|
||||
do_test format3-2.1.5 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY substr(v,2,999)+0.0 DESC;
|
||||
}
|
||||
} {x11 x1.6 x0.0013442 x-2b x-2.15 x-3.141592653 x-123 x-4221}
|
||||
|
||||
# This is a bug fix for 2.2.4.
|
||||
# Strings are normally mapped to upper-case for a caseless comparison.
|
||||
# But this can cause problems for characters in between 'Z' and 'a'.
|
||||
#
|
||||
do_test format3-3.1 {
|
||||
execsql {
|
||||
CREATE TABLE t2(a,b);
|
||||
INSERT INTO t2 VALUES('AGLIENTU',1);
|
||||
INSERT INTO t2 VALUES('AGLIE`',2);
|
||||
INSERT INTO t2 VALUES('AGNA',3);
|
||||
SELECT a, b FROM t2 ORDER BY a;
|
||||
}
|
||||
} {AGLIENTU 1 AGLIE` 2 AGNA 3}
|
||||
do_test format3-3.2 {
|
||||
execsql {
|
||||
SELECT a, b FROM t2 ORDER BY a DESC;
|
||||
}
|
||||
} {AGNA 3 AGLIE` 2 AGLIENTU 1}
|
||||
do_test format3-3.3 {
|
||||
execsql {
|
||||
DELETE FROM t2;
|
||||
INSERT INTO t2 VALUES('aglientu',1);
|
||||
INSERT INTO t2 VALUES('aglie`',2);
|
||||
INSERT INTO t2 VALUES('agna',3);
|
||||
SELECT a, b FROM t2 ORDER BY a;
|
||||
}
|
||||
} {aglie` 2 aglientu 1 agna 3}
|
||||
do_test format3-3.4 {
|
||||
execsql {
|
||||
SELECT a, b FROM t2 ORDER BY a DESC;
|
||||
}
|
||||
} {agna 3 aglientu 1 aglie` 2}
|
||||
|
||||
# Version 2.7.0 testing.
|
||||
#
|
||||
do_test format3-4.1 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(9,'x2.7',3,'IX',4.0e5);
|
||||
INSERT INTO t1 VALUES(10,'x5.0e10',3,'X',-4.0e5);
|
||||
INSERT INTO t1 VALUES(11,'x-4.0e9',3,'XI',4.1e4);
|
||||
INSERT INTO t1 VALUES(12,'x01234567890123456789',3,'XII',-4.2e3);
|
||||
SELECT n FROM t1 ORDER BY n;
|
||||
}
|
||||
} {1 2 3 4 5 6 7 8 9 10 11 12}
|
||||
do_test format3-4.2 {
|
||||
execsql {
|
||||
SELECT n||'' FROM t1 ORDER BY 1;
|
||||
}
|
||||
} {1 2 3 4 5 6 7 8 9 10 11 12}
|
||||
do_test format3-4.3 {
|
||||
execsql {
|
||||
SELECT n+0 FROM t1 ORDER BY 1;
|
||||
}
|
||||
} {1 2 3 4 5 6 7 8 9 10 11 12}
|
||||
do_test format3-4.4 {
|
||||
execsql {
|
||||
SELECT n||'' FROM t1 ORDER BY 1 DESC;
|
||||
}
|
||||
} {12 11 10 9 8 7 6 5 4 3 2 1}
|
||||
do_test format3-4.5 {
|
||||
execsql {
|
||||
SELECT n+0 FROM t1 ORDER BY 1 DESC;
|
||||
}
|
||||
} {12 11 10 9 8 7 6 5 4 3 2 1}
|
||||
do_test format3-4.6 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY 1;
|
||||
}
|
||||
} {x-123 x-2.15 x-2b x-3.141592653 x-4.0e9 x-4221 x0.0013442 x01234567890123456789 x1.6 x11 x2.7 x5.0e10}
|
||||
do_test format3-4.7 {
|
||||
execsql {
|
||||
SELECT v FROM t1 ORDER BY 1 DESC;
|
||||
}
|
||||
} {x5.0e10 x2.7 x11 x1.6 x01234567890123456789 x0.0013442 x-4221 x-4.0e9 x-3.141592653 x-2b x-2.15 x-123}
|
||||
do_test format3-4.8 {
|
||||
execsql {
|
||||
SELECT substr(v,2,99) FROM t1 ORDER BY 1;
|
||||
}
|
||||
} {-4.0e9 -4221 -123 -3.141592653 -2.15 0.0013442 1.6 2.7 11 5.0e10 01234567890123456789 -2b}
|
||||
|
||||
# Build some new test data, this time with indices.
|
||||
#
|
||||
do_test format3-5.0 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(w int, x text, y blob);
|
||||
DROP TABLE t2;
|
||||
CREATE TABLE t2(p varchar(1), q clob, r real, s numeric(8));
|
||||
}
|
||||
for {set i 1} {$i<=100} {incr i} {
|
||||
set w $i
|
||||
set x [expr {int(log($i)/log(2))}]
|
||||
set y [expr {$i*$i + 2*$i + 1}]
|
||||
execsql "INSERT INTO t1 VALUES($w,$x,$y)"
|
||||
}
|
||||
execsql {
|
||||
INSERT INTO t2 SELECT 101-w, x, (SELECT max(y) FROM t1)+1-y, y FROM t1;
|
||||
CREATE INDEX i1w ON t1(w);
|
||||
CREATE INDEX i1xy ON t1(x,y);
|
||||
CREATE INDEX i2p ON t2(p);
|
||||
CREATE INDEX i2r ON t2(r);
|
||||
CREATE INDEX i2qs ON t2(q, s);
|
||||
}
|
||||
} {}
|
||||
|
||||
# Do an SQL statement. Append the search count to the end of the result.
|
||||
#
|
||||
proc count sql {
|
||||
set ::sqlite_search_count 0
|
||||
return [concat [execsql $sql] $::sqlite_search_count]
|
||||
}
|
||||
|
||||
# Verify that queries use an index. We are using the special variable
|
||||
# "sqlite_search_count" which tallys the number of executions of MoveTo
|
||||
# and Next operators in the VDBE. By verifing that the search count is
|
||||
# small we can be assured that indices are being used properly.
|
||||
#
|
||||
do_test format3-5.1 {
|
||||
db close
|
||||
sqlite db test.db
|
||||
count {SELECT x, y FROM t1 WHERE w=10}
|
||||
} {3 121 3}
|
||||
do_test format3-5.2 {
|
||||
count {SELECT x, y FROM t1 WHERE w=11}
|
||||
} {3 144 3}
|
||||
do_test format3-5.3 {
|
||||
count {SELECT x, y FROM t1 WHERE 11=w}
|
||||
} {3 144 3}
|
||||
do_test format3-5.4 {
|
||||
count {SELECT x, y FROM t1 WHERE 11=w AND x>2}
|
||||
} {3 144 3}
|
||||
do_test format3-5.5 {
|
||||
count {SELECT x, y FROM t1 WHERE y<200 AND w=11 AND x>2}
|
||||
} {3 144 3}
|
||||
do_test format3-5.6 {
|
||||
count {SELECT x, y FROM t1 WHERE y<200 AND x>2 AND w=11}
|
||||
} {3 144 3}
|
||||
do_test format3-5.7 {
|
||||
count {SELECT x, y FROM t1 WHERE w=11 AND y<200 AND x>2}
|
||||
} {3 144 3}
|
||||
do_test format3-5.8 {
|
||||
count {SELECT x, y FROM t1 WHERE w>10 AND y=144 AND x=3}
|
||||
} {3 144 3}
|
||||
do_test format3-5.9 {
|
||||
count {SELECT x, y FROM t1 WHERE y=144 AND w>10 AND x=3}
|
||||
} {3 144 3}
|
||||
do_test format3-5.10 {
|
||||
count {SELECT x, y FROM t1 WHERE x=3 AND w>=10 AND y=121}
|
||||
} {3 121 3}
|
||||
do_test format3-5.11 {
|
||||
count {SELECT x, y FROM t1 WHERE x=3 AND y=100 AND w<10}
|
||||
} {3 100 3}
|
||||
|
||||
# New for SQLite version 2.1: Verify that that inequality constraints
|
||||
# are used correctly.
|
||||
#
|
||||
do_test format3-5.12 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y<100}
|
||||
} {8 3}
|
||||
do_test format3-5.13 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 100>y}
|
||||
} {8 3}
|
||||
do_test format3-5.14 {
|
||||
count {SELECT w FROM t1 WHERE 3=x AND y<100}
|
||||
} {8 3}
|
||||
do_test format3-5.15 {
|
||||
count {SELECT w FROM t1 WHERE 3=x AND 100>y}
|
||||
} {8 3}
|
||||
do_test format3-5.16 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y<=100}
|
||||
} {8 9 5}
|
||||
do_test format3-5.17 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 100>=y}
|
||||
} {8 9 5}
|
||||
do_test format3-5.18 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y>225}
|
||||
} {15 3}
|
||||
do_test format3-5.19 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 225<y}
|
||||
} {15 3}
|
||||
do_test format3-5.20 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y>=225}
|
||||
} {14 15 5}
|
||||
do_test format3-5.21 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 225<=y}
|
||||
} {14 15 5}
|
||||
do_test format3-5.22 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y>121 AND y<196}
|
||||
} {11 12 5}
|
||||
do_test format3-5.23 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<=196}
|
||||
} {10 11 12 13 9}
|
||||
do_test format3-5.24 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 121<y AND 196>y}
|
||||
} {11 12 5}
|
||||
do_test format3-5.25 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND 121<=y AND 196>=y}
|
||||
} {10 11 12 13 9}
|
||||
|
||||
# Need to work on optimizing the BETWEEN operator.
|
||||
#
|
||||
# do_test format3-5.26 {
|
||||
# count {SELECT w FROM t1 WHERE x=3 AND y BETWEEN 121 AND 196}
|
||||
# } {10 11 12 13 9}
|
||||
|
||||
do_test format3-5.27 {
|
||||
count {SELECT w FROM t1 WHERE x=3 AND y+1==122}
|
||||
} {10 17}
|
||||
do_test format3-5.28 {
|
||||
count {SELECT w FROM t1 WHERE x+1=4 AND y+1==122}
|
||||
} {10 99}
|
||||
do_test format3-5.29 {
|
||||
count {SELECT w FROM t1 WHERE y==121}
|
||||
} {10 99}
|
||||
|
||||
|
||||
do_test format3-5.30 {
|
||||
count {SELECT w FROM t1 WHERE w>97}
|
||||
} {98 99 100 6}
|
||||
do_test format3-5.31 {
|
||||
count {SELECT w FROM t1 WHERE w>=97}
|
||||
} {97 98 99 100 8}
|
||||
do_test format3-5.33 {
|
||||
count {SELECT w FROM t1 WHERE w==97}
|
||||
} {97 3}
|
||||
do_test format3-5.34 {
|
||||
count {SELECT w FROM t1 WHERE w+1==98}
|
||||
} {97 99}
|
||||
do_test format3-5.35 {
|
||||
count {SELECT w FROM t1 WHERE w<3}
|
||||
} {1 2 4}
|
||||
do_test format3-5.36 {
|
||||
count {SELECT w FROM t1 WHERE w<=3}
|
||||
} {1 2 3 6}
|
||||
do_test format3-5.37 {
|
||||
count {SELECT w FROM t1 WHERE w+1<=4 ORDER BY w}
|
||||
} {1 2 3 199}
|
||||
|
||||
|
||||
# Do the same kind of thing except use a join as the data source.
|
||||
#
|
||||
do_test format3-6.1 {
|
||||
db close
|
||||
sqlite db test.db
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE x=q AND y=s AND r=8977
|
||||
}
|
||||
} {34 67 6}
|
||||
do_test format3-6.2 {
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE x=q AND s=y AND r=8977
|
||||
}
|
||||
} {34 67 6}
|
||||
do_test format3-6.3 {
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE x=q AND s=y AND r=8977 AND w>10
|
||||
}
|
||||
} {34 67 6}
|
||||
do_test format3-6.4 {
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE p<80 AND x=q AND s=y AND r=8977 AND w>10
|
||||
}
|
||||
} {34 67 6}
|
||||
do_test format3-6.5 {
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE p<80 AND x=q AND 8977=r AND s=y AND w>10
|
||||
}
|
||||
} {34 67 6}
|
||||
do_test format3-6.6 {
|
||||
count {
|
||||
SELECT w, p FROM t2, t1
|
||||
WHERE x=q AND p=77 AND s=y AND w>5
|
||||
}
|
||||
} {24 77 6}
|
||||
do_test format3-6.7 {
|
||||
count {
|
||||
SELECT w, p FROM t1, t2
|
||||
WHERE x=q AND p>77 AND s=y AND w=5
|
||||
}
|
||||
} {5 96 6}
|
||||
|
||||
# Lets do a 3-way join.
|
||||
#
|
||||
do_test format3-7.1 {
|
||||
count {
|
||||
SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C
|
||||
WHERE C.w=101-B.p AND B.r=10202-A.y AND A.w=11
|
||||
}
|
||||
} {11 90 11 9}
|
||||
do_test format3-7.2 {
|
||||
count {
|
||||
SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C
|
||||
WHERE C.w=101-B.p AND B.r=10202-A.y AND A.w=12
|
||||
}
|
||||
} {12 89 12 9}
|
||||
do_test format3-7.3 {
|
||||
count {
|
||||
SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C
|
||||
WHERE A.w=15 AND B.p=C.w AND B.r=10202-A.y
|
||||
}
|
||||
} {15 86 86 9}
|
||||
|
||||
# Test to see that the special case of a constant WHERE clause is
|
||||
# handled.
|
||||
#
|
||||
do_test format3-8.1 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE 0
|
||||
}
|
||||
} {0}
|
||||
do_test format3-8.2 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE 1 LIMIT 1
|
||||
}
|
||||
} {1 0 4 1}
|
||||
do_test format3-8.3 {
|
||||
execsql {
|
||||
SELECT 99 WHERE 0
|
||||
}
|
||||
} {}
|
||||
do_test format3-8.4 {
|
||||
execsql {
|
||||
SELECT 99 WHERE 1
|
||||
}
|
||||
} {99}
|
||||
|
||||
# Verify that IN operators in a WHERE clause are handled correctly.
|
||||
#
|
||||
do_test format3-9.1 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE rowid IN (1,2,3,1234) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 0}
|
||||
do_test format3-9.2 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE rowid+0 IN (1,2,3,1234) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 199}
|
||||
do_test format3-9.3 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 10}
|
||||
do_test format3-9.4 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w+0 IN (-1,1,2,3) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 199}
|
||||
do_test format3-9.5 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE rowid IN
|
||||
(select rowid from t1 where rowid IN (-1,2,4))
|
||||
ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 4 2 25 1}
|
||||
do_test format3-9.6 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE rowid+0 IN
|
||||
(select rowid from t1 where rowid IN (-1,2,4))
|
||||
ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 4 2 25 199}
|
||||
do_test format3-9.7 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w IN
|
||||
(select rowid from t1 where rowid IN (-1,2,4))
|
||||
ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 4 2 25 7}
|
||||
do_test format3-9.8 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w+0 IN
|
||||
(select rowid from t1 where rowid IN (-1,2,4))
|
||||
ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 4 2 25 199}
|
||||
do_test format3-9.9 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE x IN (1,7) ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 3 1 16 6}
|
||||
do_test format3-9.10 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE x+0 IN (1,7) ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 3 1 16 199}
|
||||
do_test format3-9.11 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE y IN (6400,8100) ORDER BY 1;
|
||||
}
|
||||
} {79 6 6400 89 6 8100 199}
|
||||
do_test format3-9.12 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE x=6 AND y IN (6400,8100) ORDER BY 1;
|
||||
}
|
||||
} {79 6 6400 89 6 8100 74}
|
||||
do_test format3-9.13 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE x IN (1,7) AND y NOT IN (6400,8100) ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 3 1 16 6}
|
||||
do_test format3-9.14 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,10) ORDER BY 1;
|
||||
}
|
||||
} {2 1 9 6}
|
||||
|
||||
# This procedure executes the SQL. Then it checks the generated program
|
||||
# for the SQL and appends a "nosort" to the result if the program contains the
|
||||
# SortCallback opcode. If the program does not contain the SortCallback
|
||||
# opcode it appends "sort"
|
||||
#
|
||||
proc cksort {sql} {
|
||||
set data [execsql $sql]
|
||||
set prog [execsql "EXPLAIN $sql"]
|
||||
if {[regexp SortCallback $prog]} {set x sort} {set x nosort}
|
||||
lappend data $x
|
||||
return $data
|
||||
}
|
||||
# Check out the logic that attempts to implement the ORDER BY clause
|
||||
# using an index rather than by sorting.
|
||||
#
|
||||
do_test format3-10.1 {
|
||||
execsql {
|
||||
CREATE TABLE t3(a,b,c);
|
||||
CREATE INDEX t3a ON t3(a);
|
||||
CREATE INDEX t3bc ON t3(b,c);
|
||||
CREATE INDEX t3acb ON t3(a,c,b);
|
||||
INSERT INTO t3 SELECT w, 101-w, y FROM t1;
|
||||
SELECT count(*), sum(a), sum(b), sum(c) FROM t3;
|
||||
}
|
||||
} {100 5050 5050 348550}
|
||||
do_test format3-10.2 {
|
||||
cksort {
|
||||
SELECT * FROM t3 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 nosort}
|
||||
do_test format3-10.3 {
|
||||
cksort {
|
||||
SELECT * FROM t3 ORDER BY a+1 LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 sort}
|
||||
do_test format3-10.4 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a<10 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 nosort}
|
||||
do_test format3-10.5 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a>0 AND a<10 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 nosort}
|
||||
do_test format3-10.6 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a>0 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 nosort}
|
||||
do_test format3-10.7 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE b>0 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 sort}
|
||||
do_test format3-10.8 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a IN (3,5,7,1,9,4,2) ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 sort}
|
||||
do_test format3-10.9 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 nosort}
|
||||
do_test format3-10.10 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 nosort}
|
||||
do_test format3-10.11 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c LIMIT 3
|
||||
}
|
||||
} {1 100 4 nosort}
|
||||
do_test format3-10.12 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c,b LIMIT 3
|
||||
}
|
||||
} {1 100 4 nosort}
|
||||
do_test format3-10.13 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a>0 ORDER BY a DESC LIMIT 3
|
||||
}
|
||||
} {100 1 10201 99 2 10000 98 3 9801 nosort}
|
||||
do_test format3-10.13.1 {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a>0 ORDER BY a+1 DESC LIMIT 3
|
||||
}
|
||||
} {100 1 10201 99 2 10000 98 3 9801 sort}
|
||||
do_test format3-10.14 {
|
||||
cksort {
|
||||
SELECT * FROM t3 ORDER BY b LIMIT 3
|
||||
}
|
||||
} {100 1 10201 99 2 10000 98 3 9801 nosort}
|
||||
do_test format3-10.15 {
|
||||
cksort {
|
||||
SELECT t3.a, t1.x FROM t3, t1 WHERE t3.a=t1.w ORDER BY t3.a LIMIT 3
|
||||
}
|
||||
} {1 0 2 1 3 1 nosort}
|
||||
do_test format3-10.16 {
|
||||
cksort {
|
||||
SELECT t3.a, t1.x FROM t3, t1 WHERE t3.a=t1.w ORDER BY t1.x, t3.a LIMIT 3
|
||||
}
|
||||
} {1 0 2 1 3 1 sort}
|
||||
do_test format3-10.17 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY w COLLATE text LIMIT 3;
|
||||
}
|
||||
} {4 121 10201 sort}
|
||||
do_test format3-10.18 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY w COLLATE numeric LIMIT 3;
|
||||
}
|
||||
} {4 9 16 sort}
|
||||
do_test format3-10.19 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY w LIMIT 3;
|
||||
}
|
||||
} {4 9 16 nosort}
|
||||
|
||||
# Check that all comparisons are numeric. Similar tests in misc1.test
|
||||
# check the same comparisons on a format4+ database and find that some
|
||||
# are numeric and some are text.
|
||||
#
|
||||
do_test format3-11.1 {
|
||||
execsql {SELECT '0'=='0.0'}
|
||||
} {1}
|
||||
do_test format3-11.2 {
|
||||
execsql {SELECT '0'==0.0}
|
||||
} {1}
|
||||
do_test format3-11.3 {
|
||||
execsql {SELECT '123456789012345678901'=='123456789012345678900'}
|
||||
} {1}
|
||||
do_test format3-11.4 {
|
||||
execsql {
|
||||
CREATE TABLE t6(a INT UNIQUE, b TEXT UNIQUE);
|
||||
INSERT INTO t6 VALUES('0','0.0');
|
||||
SELECT * FROM t6;
|
||||
}
|
||||
} {0 0.0}
|
||||
do_test format3-11.5 {
|
||||
execsql {
|
||||
INSERT OR IGNORE INTO t6 VALUES(0.0,'x');
|
||||
SELECT * FROM t6;
|
||||
}
|
||||
} {0 0.0}
|
||||
do_test format3-11.6 {
|
||||
execsql {
|
||||
INSERT OR IGNORE INTO t6 VALUES('y',0);
|
||||
SELECT * FROM t6;
|
||||
}
|
||||
} {0 0.0}
|
||||
do_test format3-11.7 {
|
||||
execsql {
|
||||
CREATE TABLE t7(x INTEGER, y TEXT, z);
|
||||
INSERT INTO t7 VALUES(0,0,1);
|
||||
INSERT INTO t7 VALUES(0.0,0,2);
|
||||
INSERT INTO t7 VALUES(0,0.0,3);
|
||||
INSERT INTO t7 VALUES(0.0,0.0,4);
|
||||
SELECT DISTINCT x, y FROM t7 ORDER BY z;
|
||||
}
|
||||
} {0 0}
|
||||
|
||||
# Make sure attempts to attach a format 3 database fail.
|
||||
#
|
||||
do_test format3-12.1 {
|
||||
file delete -force test2.db
|
||||
sqlite db2 test2.db
|
||||
catchsql {
|
||||
CREATE TABLE t8(x,y);
|
||||
ATTACH DATABASE 'test.db' AS format3;
|
||||
} db2;
|
||||
} {1 {incompatible file format in auxiliary database: format3}}
|
||||
do_test format3-12.2 {
|
||||
catchsql {
|
||||
ATTACH DATABASE 'test2.db' AS test2;
|
||||
}
|
||||
} {1 {cannot attach auxiliary databases to an older format master database}}
|
||||
db2 close
|
||||
|
||||
finish_test
|
||||
+235
-14
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing built-in functions.
|
||||
#
|
||||
# $Id: func.test,v 1.4 2001/09/16 00:13:28 drh Exp $
|
||||
# $Id: func.test,v 1.16.2.2 2004/07/18 21:14:05 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -25,6 +25,17 @@ do_test func-0.0 {
|
||||
}
|
||||
execsql {SELECT t1 FROM tbl1 ORDER BY t1}
|
||||
} {free is program software this}
|
||||
do_test func-0.1 {
|
||||
execsql {
|
||||
CREATE TABLE t2(a);
|
||||
INSERT INTO t2 VALUES(1);
|
||||
INSERT INTO t2 VALUES(NULL);
|
||||
INSERT INTO t2 VALUES(345);
|
||||
INSERT INTO t2 VALUES(NULL);
|
||||
INSERT INTO t2 VALUES(67890);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {1 {} 345 {} 67890}
|
||||
|
||||
# Check out the length() function
|
||||
#
|
||||
@@ -34,15 +45,18 @@ do_test func-1.0 {
|
||||
do_test func-1.1 {
|
||||
set r [catch {execsql {SELECT length(*) FROM tbl1 ORDER BY t1}} msg]
|
||||
lappend r $msg
|
||||
} {1 {too few arguments to function length()}}
|
||||
} {1 {wrong number of arguments to function length()}}
|
||||
do_test func-1.2 {
|
||||
set r [catch {execsql {SELECT length(t1,5) FROM tbl1 ORDER BY t1}} msg]
|
||||
lappend r $msg
|
||||
} {1 {too many arguments to function length()}}
|
||||
} {1 {wrong number of arguments to function length()}}
|
||||
do_test func-1.3 {
|
||||
execsql {SELECT length(t1), count(*) FROM tbl1 GROUP BY length(t1)
|
||||
ORDER BY length(t1)}
|
||||
} {2 1 4 2 7 1 8 1}
|
||||
do_test func-1.4 {
|
||||
execsql {SELECT coalesce(length(a),-1) FROM t2}
|
||||
} {1 -1 3 -1 5}
|
||||
|
||||
# Check out the substr() function
|
||||
#
|
||||
@@ -73,6 +87,12 @@ do_test func-2.7 {
|
||||
do_test func-2.8 {
|
||||
execsql {SELECT t1 FROM tbl1 ORDER BY substr(t1,2,20)}
|
||||
} {this software free program is}
|
||||
do_test func-2.9 {
|
||||
execsql {SELECT substr(a,1,1) FROM t2}
|
||||
} {1 {} 3 {} 6}
|
||||
do_test func-2.10 {
|
||||
execsql {SELECT substr(a,2,2) FROM t2}
|
||||
} {{} {} 45 {} 78}
|
||||
|
||||
# Only do the following tests if TCL has UTF-8 capabilities and
|
||||
# the UTF-8 encoding is turned on in the SQLite library.
|
||||
@@ -87,38 +107,239 @@ do_test func-3.0 {
|
||||
execsql "INSERT INTO tbl1 VALUES('$word')"
|
||||
}
|
||||
execsql {SELECT t1 FROM tbl1 ORDER BY t1}
|
||||
} "characters contains hi\u1234ho UTF-8"
|
||||
} "UTF-8 characters contains hi\u1234ho"
|
||||
do_test func-3.1 {
|
||||
execsql {SELECT length(t1) FROM tbl1 ORDER BY t1}
|
||||
} {10 8 5 5}
|
||||
} {5 10 8 5}
|
||||
do_test func-3.2 {
|
||||
execsql {SELECT substr(t1,1,2) FROM tbl1 ORDER BY t1}
|
||||
} {ch co hi UT}
|
||||
} {UT ch co hi}
|
||||
do_test func-3.3 {
|
||||
execsql {SELECT substr(t1,1,3) FROM tbl1 ORDER BY t1}
|
||||
} "cha con hi\u1234 UTF"
|
||||
} "UTF cha con hi\u1234"
|
||||
do_test func-3.4 {
|
||||
execsql {SELECT substr(t1,2,2) FROM tbl1 ORDER BY t1}
|
||||
} "ha on i\u1234 TF"
|
||||
} "TF ha on i\u1234"
|
||||
do_test func-3.5 {
|
||||
execsql {SELECT substr(t1,2,3) FROM tbl1 ORDER BY t1}
|
||||
} "har ont i\u1234h TF-"
|
||||
} "TF- har ont i\u1234h"
|
||||
do_test func-3.6 {
|
||||
execsql {SELECT substr(t1,3,2) FROM tbl1 ORDER BY t1}
|
||||
} "ar nt \u1234h F-"
|
||||
} "F- ar nt \u1234h"
|
||||
do_test func-3.7 {
|
||||
execsql {SELECT substr(t1,4,2) FROM tbl1 ORDER BY t1}
|
||||
} "ra ta ho -8"
|
||||
} "-8 ra ta ho"
|
||||
do_test func-3.8 {
|
||||
execsql {SELECT substr(t1,-1,1) FROM tbl1 ORDER BY t1}
|
||||
} "s s o 8"
|
||||
} "8 s s o"
|
||||
do_test func-3.9 {
|
||||
execsql {SELECT substr(t1,-3,2) FROM tbl1 ORDER BY t1}
|
||||
} "er in \u1234h F-"
|
||||
} "F- er in \u1234h"
|
||||
do_test func-3.10 {
|
||||
execsql {SELECT substr(t1,-4,3) FROM tbl1 ORDER BY t1}
|
||||
} "ter ain i\u1234h TF-"
|
||||
} "TF- ter ain i\u1234h"
|
||||
do_test func-3.99 {
|
||||
execsql {DELETE FROM tbl1}
|
||||
foreach word {this program is free software} {
|
||||
execsql "INSERT INTO tbl1 VALUES('$word')"
|
||||
}
|
||||
execsql {SELECT t1 FROM tbl1}
|
||||
} {this program is free software}
|
||||
|
||||
} ;# End [sqlite -encoding]==UTF-8 and \u1234!=u1234
|
||||
|
||||
# Test the abs() and round() functions.
|
||||
#
|
||||
do_test func-4.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b,c);
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
INSERT INTO t1 VALUES(2,1.2345678901234,-12345.67890);
|
||||
INSERT INTO t1 VALUES(3,-2,-5);
|
||||
}
|
||||
catchsql {SELECT abs(a,b) FROM t1}
|
||||
} {1 {wrong number of arguments to function abs()}}
|
||||
do_test func-4.2 {
|
||||
catchsql {SELECT abs() FROM t1}
|
||||
} {1 {wrong number of arguments to function abs()}}
|
||||
do_test func-4.3 {
|
||||
catchsql {SELECT abs(b) FROM t1 ORDER BY a}
|
||||
} {0 {2 1.2345678901234 2}}
|
||||
do_test func-4.4 {
|
||||
catchsql {SELECT abs(c) FROM t1 ORDER BY a}
|
||||
} {0 {3 12345.67890 5}}
|
||||
do_test func-4.4.1 {
|
||||
execsql {SELECT abs(a) FROM t2}
|
||||
} {1 {} 345 {} 67890}
|
||||
do_test func-4.4.2 {
|
||||
execsql {SELECT abs(t1) FROM tbl1}
|
||||
} {this program is free software}
|
||||
|
||||
do_test func-4.5 {
|
||||
catchsql {SELECT round(a,b,c) FROM t1}
|
||||
} {1 {wrong number of arguments to function round()}}
|
||||
do_test func-4.6 {
|
||||
catchsql {SELECT round(b,2) FROM t1 ORDER BY b}
|
||||
} {0 {-2.00 1.23 2.00}}
|
||||
do_test func-4.7 {
|
||||
catchsql {SELECT round(b,0) FROM t1 ORDER BY a}
|
||||
} {0 {2 1 -2}}
|
||||
do_test func-4.8 {
|
||||
catchsql {SELECT round(c) FROM t1 ORDER BY a}
|
||||
} {0 {3 -12346 -5}}
|
||||
do_test func-4.9 {
|
||||
catchsql {SELECT round(c,a) FROM t1 ORDER BY a}
|
||||
} {0 {3.0 -12345.68 -5.000}}
|
||||
do_test func-4.10 {
|
||||
catchsql {SELECT 'x' || round(c,a) || 'y' FROM t1 ORDER BY a}
|
||||
} {0 {x3.0y x-12345.68y x-5.000y}}
|
||||
do_test func-4.11 {
|
||||
catchsql {SELECT round() FROM t1 ORDER BY a}
|
||||
} {1 {wrong number of arguments to function round()}}
|
||||
do_test func-4.12 {
|
||||
execsql {SELECT coalesce(round(a,2),'nil') FROM t2}
|
||||
} {1.00 nil 345.00 nil 67890.00}
|
||||
do_test func-4.13 {
|
||||
execsql {SELECT round(t1,2) FROM tbl1}
|
||||
} {0.00 0.00 0.00 0.00 0.00}
|
||||
|
||||
# Test the upper() and lower() functions
|
||||
#
|
||||
do_test func-5.1 {
|
||||
execsql {SELECT upper(t1) FROM tbl1}
|
||||
} {THIS PROGRAM IS FREE SOFTWARE}
|
||||
do_test func-5.2 {
|
||||
execsql {SELECT lower(upper(t1)) FROM tbl1}
|
||||
} {this program is free software}
|
||||
do_test func-5.3 {
|
||||
execsql {SELECT upper(a), lower(a) FROM t2}
|
||||
} {1 1 {} {} 345 345 {} {} 67890 67890}
|
||||
do_test func-5.4 {
|
||||
catchsql {SELECT upper(a,5) FROM t2}
|
||||
} {1 {wrong number of arguments to function upper()}}
|
||||
do_test func-5.5 {
|
||||
catchsql {SELECT upper(*) FROM t2}
|
||||
} {1 {wrong number of arguments to function upper()}}
|
||||
|
||||
# Test the coalesce() and nullif() functions
|
||||
#
|
||||
do_test func-6.1 {
|
||||
execsql {SELECT coalesce(a,'xyz') FROM t2}
|
||||
} {1 xyz 345 xyz 67890}
|
||||
do_test func-6.2 {
|
||||
execsql {SELECT coalesce(upper(a),'nil') FROM t2}
|
||||
} {1 nil 345 nil 67890}
|
||||
do_test func-6.3 {
|
||||
execsql {SELECT coalesce(nullif(1,1),'nil')}
|
||||
} {nil}
|
||||
do_test func-6.4 {
|
||||
execsql {SELECT coalesce(nullif(1,2),'nil')}
|
||||
} {1}
|
||||
do_test func-6.5 {
|
||||
execsql {SELECT coalesce(nullif(1,NULL),'nil')}
|
||||
} {1}
|
||||
|
||||
|
||||
# Test the last_insert_rowid() function
|
||||
#
|
||||
do_test func-7.1 {
|
||||
execsql {SELECT last_insert_rowid()}
|
||||
} [db last_insert_rowid]
|
||||
|
||||
# Tests for aggregate functions and how they handle NULLs.
|
||||
#
|
||||
do_test func-8.1 {
|
||||
execsql {
|
||||
SELECT sum(a), count(a), round(avg(a),2), min(a), max(a), count(*) FROM t2;
|
||||
}
|
||||
} {68236 3 22745.33 1 67890 5}
|
||||
do_test func-8.2 {
|
||||
execsql {
|
||||
SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t2;
|
||||
}
|
||||
} {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
|
||||
do_test func-8.3 {
|
||||
execsql {
|
||||
CREATE TEMP TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC;
|
||||
SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
|
||||
}
|
||||
} {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
|
||||
do_test func-8.4 {
|
||||
execsql {
|
||||
SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
|
||||
}
|
||||
} {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
|
||||
|
||||
# How do you test the random() function in a meaningful, deterministic way?
|
||||
#
|
||||
do_test func-9.1 {
|
||||
execsql {
|
||||
SELECT random() is not null;
|
||||
}
|
||||
} {1}
|
||||
|
||||
# Use the "sqlite_register_test_function" TCL command which is part of
|
||||
# the text fixture in order to verify correct operation of some of
|
||||
# the user-defined SQL function APIs that are not used by the built-in
|
||||
# functions.
|
||||
#
|
||||
db close
|
||||
set ::DB [sqlite db test.db]
|
||||
sqlite_register_test_function $::DB testfunc
|
||||
do_test func-10.1 {
|
||||
catchsql {
|
||||
SELECT testfunc(NULL,NULL);
|
||||
}
|
||||
} {1 {first argument to test function may not be NULL}}
|
||||
do_test func-10.2 {
|
||||
execsql {
|
||||
SELECT testfunc(
|
||||
'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'int', 1234
|
||||
);
|
||||
}
|
||||
} {1234}
|
||||
do_test func-10.3 {
|
||||
execsql {
|
||||
SELECT testfunc(
|
||||
'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'string', NULL
|
||||
);
|
||||
}
|
||||
} {{}}
|
||||
do_test func-10.4 {
|
||||
execsql {
|
||||
SELECT testfunc(
|
||||
'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'double', 1.234
|
||||
);
|
||||
}
|
||||
} {1.234}
|
||||
do_test func-10.5 {
|
||||
execsql {
|
||||
SELECT testfunc(
|
||||
'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'int', 1234,
|
||||
'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'string', NULL,
|
||||
'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'double', 1.234,
|
||||
'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'int', 1234,
|
||||
'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'string', NULL,
|
||||
'string', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'double', 1.234
|
||||
);
|
||||
}
|
||||
} {1.234}
|
||||
|
||||
# Test the built-in sqlite_version(*) SQL function.
|
||||
#
|
||||
do_test func-11.1 {
|
||||
execsql {
|
||||
SELECT sqlite_version(*);
|
||||
}
|
||||
} [sqlite -version]
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
# 2004 Jan 14
|
||||
#
|
||||
# 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 TCL interface to the
|
||||
# SQLite library.
|
||||
#
|
||||
# The focus of the tests in this file is the following interface:
|
||||
#
|
||||
# sqlite_commit_hook
|
||||
#
|
||||
# $Id: hook.test,v 1.3 2004/01/15 02:44:03 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
do_test hook-1.2 {
|
||||
db commit_hook
|
||||
} {}
|
||||
|
||||
|
||||
do_test hook-3.1 {
|
||||
set commit_cnt 0
|
||||
proc commit_hook {} {
|
||||
incr ::commit_cnt
|
||||
return 0
|
||||
}
|
||||
db commit_hook ::commit_hook
|
||||
db commit_hook
|
||||
} {::commit_hook}
|
||||
do_test hook-3.2 {
|
||||
set commit_cnt
|
||||
} {0}
|
||||
do_test hook-3.3 {
|
||||
execsql {
|
||||
CREATE TABLE t2(a,b);
|
||||
}
|
||||
set commit_cnt
|
||||
} {1}
|
||||
do_test hook-3.4 {
|
||||
execsql {
|
||||
INSERT INTO t2 VALUES(1,2);
|
||||
INSERT INTO t2 SELECT a+1, b+1 FROM t2;
|
||||
INSERT INTO t2 SELECT a+2, b+2 FROM t2;
|
||||
}
|
||||
set commit_cnt
|
||||
} {4}
|
||||
do_test hook-3.5 {
|
||||
set commit_cnt {}
|
||||
proc commit_hook {} {
|
||||
set ::commit_cnt [execsql {SELECT * FROM t2}]
|
||||
return 0
|
||||
}
|
||||
execsql {
|
||||
INSERT INTO t2 VALUES(5,6);
|
||||
}
|
||||
set commit_cnt
|
||||
} {1 2 2 3 3 4 4 5 5 6}
|
||||
do_test hook-3.6 {
|
||||
set commit_cnt {}
|
||||
proc commit_hook {} {
|
||||
set ::commit_cnt [execsql {SELECT * FROM t2}]
|
||||
return 1
|
||||
}
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(6,7);
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test hook-3.7 {
|
||||
set commit_cnt
|
||||
} {1 2 2 3 3 4 4 5 5 6 6 7}
|
||||
do_test hook-3.8 {
|
||||
execsql {SELECT * FROM t2}
|
||||
} {1 2 2 3 3 4 4 5 5 6}
|
||||
|
||||
|
||||
finish_test
|
||||
+147
-3
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the IN and BETWEEN operator.
|
||||
#
|
||||
# $Id: in.test,v 1.5 2001/09/16 00:13:28 drh Exp $
|
||||
# $Id: in.test,v 1.11 2004/01/15 03:30:25 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -84,9 +84,9 @@ do_test in-2.8 {
|
||||
execsql {SELECT a FROM t1 WHERE b IN (8*2,64/2) ORDER BY b}
|
||||
} {4 5}
|
||||
do_test in-2.9 {
|
||||
set v [catch {execsql {SELECT a FROM t1 WHERE b IN (xyz(5,10),20)}} msg]
|
||||
set v [catch {execsql {SELECT a FROM t1 WHERE b IN (max(5,10),20)}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such function: xyz}}
|
||||
} {1 {right-hand side of IN operator must be constant}}
|
||||
do_test in-2.10 {
|
||||
set v [catch {execsql {SELECT a FROM t1 WHERE min(0,b IN (a,30))}} msg]
|
||||
lappend v $msg
|
||||
@@ -156,4 +156,148 @@ do_test in-5.1 {
|
||||
}
|
||||
} {hello world}
|
||||
|
||||
# Make sure the IN operator works with INTEGER PRIMARY KEY fields.
|
||||
#
|
||||
do_test in-6.1 {
|
||||
execsql {
|
||||
CREATE TABLE ta(a INTEGER PRIMARY KEY, b);
|
||||
INSERT INTO ta VALUES(1,1);
|
||||
INSERT INTO ta VALUES(2,2);
|
||||
INSERT INTO ta VALUES(3,3);
|
||||
INSERT INTO ta VALUES(4,4);
|
||||
INSERT INTO ta VALUES(6,6);
|
||||
INSERT INTO ta VALUES(8,8);
|
||||
INSERT INTO ta VALUES(10,
|
||||
'This is a key that is long enough to require a malloc in the VDBE');
|
||||
SELECT * FROM ta WHERE a<10;
|
||||
}
|
||||
} {1 1 2 2 3 3 4 4 6 6 8 8}
|
||||
do_test in-6.2 {
|
||||
execsql {
|
||||
CREATE TABLE tb(a INTEGER PRIMARY KEY, b);
|
||||
INSERT INTO tb VALUES(1,1);
|
||||
INSERT INTO tb VALUES(2,2);
|
||||
INSERT INTO tb VALUES(3,3);
|
||||
INSERT INTO tb VALUES(5,5);
|
||||
INSERT INTO tb VALUES(7,7);
|
||||
INSERT INTO tb VALUES(9,9);
|
||||
INSERT INTO tb VALUES(11,
|
||||
'This is a key that is long enough to require a malloc in the VDBE');
|
||||
SELECT * FROM tb WHERE a<10;
|
||||
}
|
||||
} {1 1 2 2 3 3 5 5 7 7 9 9}
|
||||
do_test in-6.3 {
|
||||
execsql {
|
||||
SELECT a FROM ta WHERE b IN (SELECT a FROM tb);
|
||||
}
|
||||
} {1 2 3}
|
||||
do_test in-6.4 {
|
||||
execsql {
|
||||
SELECT a FROM ta WHERE b NOT IN (SELECT a FROM tb);
|
||||
}
|
||||
} {4 6 8 10}
|
||||
do_test in-6.5 {
|
||||
execsql {
|
||||
SELECT a FROM ta WHERE b IN (SELECT b FROM tb);
|
||||
}
|
||||
} {1 2 3 10}
|
||||
do_test in-6.6 {
|
||||
execsql {
|
||||
SELECT a FROM ta WHERE b NOT IN (SELECT b FROM tb);
|
||||
}
|
||||
} {4 6 8}
|
||||
do_test in-6.7 {
|
||||
execsql {
|
||||
SELECT a FROM ta WHERE a IN (SELECT a FROM tb);
|
||||
}
|
||||
} {1 2 3}
|
||||
do_test in-6.8 {
|
||||
execsql {
|
||||
SELECT a FROM ta WHERE a NOT IN (SELECT a FROM tb);
|
||||
}
|
||||
} {4 6 8 10}
|
||||
do_test in-6.9 {
|
||||
execsql {
|
||||
SELECT a FROM ta WHERE a IN (SELECT b FROM tb);
|
||||
}
|
||||
} {1 2 3}
|
||||
do_test in-6.10 {
|
||||
execsql {
|
||||
SELECT a FROM ta WHERE a NOT IN (SELECT b FROM tb);
|
||||
}
|
||||
} {4 6 8 10}
|
||||
|
||||
# Tests of IN operator against empty sets. (Ticket #185)
|
||||
#
|
||||
do_test in-7.1 {
|
||||
execsql {
|
||||
SELECT a FROM t1 WHERE a IN ();
|
||||
}
|
||||
} {}
|
||||
do_test in-7.2 {
|
||||
execsql {
|
||||
SELECT a FROM t1 WHERE a IN (5);
|
||||
}
|
||||
} {5}
|
||||
do_test in-7.3 {
|
||||
execsql {
|
||||
SELECT a FROM t1 WHERE a NOT IN () ORDER BY a;
|
||||
}
|
||||
} {5 6 7 8 hello}
|
||||
do_test in-7.4 {
|
||||
execsql {
|
||||
SELECT a FROM t1 WHERE a IN (5) AND b IN ();
|
||||
}
|
||||
} {}
|
||||
do_test in-7.5 {
|
||||
execsql {
|
||||
SELECT a FROM t1 WHERE a IN (5) AND b NOT IN ();
|
||||
}
|
||||
} {5}
|
||||
do_test in-7.6 {
|
||||
execsql {
|
||||
SELECT a FROM ta WHERE a IN ();
|
||||
}
|
||||
} {}
|
||||
do_test in-7.7 {
|
||||
execsql {
|
||||
SELECT a FROM ta WHERE a NOT IN ();
|
||||
}
|
||||
} {1 2 3 4 6 8 10}
|
||||
|
||||
do_test in-8.1 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a IN ('hello','there')
|
||||
}
|
||||
} {world}
|
||||
do_test in-8.2 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a IN ("hello",'there')
|
||||
}
|
||||
} {world}
|
||||
|
||||
# Test constructs of the form: expr IN tablename
|
||||
#
|
||||
do_test in-9.1 {
|
||||
execsql {
|
||||
CREATE TABLE t4 AS SELECT a FROM tb;
|
||||
SELECT * FROM t4;
|
||||
}
|
||||
} {1 2 3 5 7 9 11}
|
||||
do_test in-9.2 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a IN t4;
|
||||
}
|
||||
} {32 128}
|
||||
do_test in-9.3 {
|
||||
execsql {
|
||||
SELECT b FROM t1 WHERE a NOT IN t4;
|
||||
}
|
||||
} {64 256 world}
|
||||
do_test in-9.4 {
|
||||
catchsql {
|
||||
SELECT b FROM t1 WHERE a NOT IN tb;
|
||||
}
|
||||
} {1 {only a single result allowed for a SELECT that is part of an expression}}
|
||||
|
||||
finish_test
|
||||
|
||||
+216
-6
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the CREATE INDEX statement.
|
||||
#
|
||||
# $Id: index.test,v 1.14 2001/09/27 15:11:55 drh Exp $
|
||||
# $Id: index.test,v 1.24.2.1 2004/07/20 00:50:30 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -74,12 +74,12 @@ do_test index-2.2 {
|
||||
#
|
||||
set r {}
|
||||
for {set i 1} {$i<100} {incr i} {
|
||||
lappend r index$i
|
||||
lappend r [format index%02d $i]
|
||||
}
|
||||
do_test index-3.1 {
|
||||
execsql {CREATE TABLE test1(f1 int, f2 int, f3 int, f4 int, f5 int)}
|
||||
for {set i 1} {$i<100} {incr i} {
|
||||
set sql "CREATE INDEX index$i ON test1(f[expr {($i%5)+1}])"
|
||||
set sql "CREATE INDEX [format index%02d $i] ON test1(f[expr {($i%5)+1}])"
|
||||
execsql $sql
|
||||
}
|
||||
execsql {SELECT name FROM sqlite_master
|
||||
@@ -154,13 +154,14 @@ do_test index-4.13 {
|
||||
execsql {DROP TABLE test1}
|
||||
execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name}
|
||||
} {}
|
||||
integrity_check index-4.14
|
||||
|
||||
# Do not allow indices to be added to sqlite_master
|
||||
#
|
||||
do_test index-5.1 {
|
||||
set v [catch {execsql {CREATE INDEX index1 ON sqlite_master(name)}} msg]
|
||||
lappend v $msg
|
||||
} {1 {table sqlite_master may not have new indices added}}
|
||||
} {1 {table sqlite_master may not be indexed}}
|
||||
do_test index-5.2 {
|
||||
execsql {SELECT name FROM sqlite_master WHERE type!='meta'}
|
||||
} {}
|
||||
@@ -189,6 +190,18 @@ do_test index-6.3 {
|
||||
execsql {DROP TABLE test2}
|
||||
execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name}
|
||||
} {}
|
||||
do_test index-6.4 {
|
||||
execsql {
|
||||
CREATE TABLE test1(a,b);
|
||||
CREATE INDEX index1 ON test1(a);
|
||||
CREATE INDEX index2 ON test1(b);
|
||||
CREATE INDEX index3 ON test1(a,b);
|
||||
DROP TABLE test1;
|
||||
SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name;
|
||||
}
|
||||
} {}
|
||||
integrity_check index-6.5
|
||||
|
||||
|
||||
# Create a primary key
|
||||
#
|
||||
@@ -212,6 +225,7 @@ do_test index-7.4 {
|
||||
execsql {DROP table test1}
|
||||
execsql {SELECT name FROM sqlite_master WHERE type!='meta'}
|
||||
} {}
|
||||
integrity_check index-7.5
|
||||
|
||||
# Make sure we cannot drop a non-existant index.
|
||||
#
|
||||
@@ -232,6 +246,7 @@ do_test index-9.2 {
|
||||
execsql {CREATE INDEX idx1 ON tab1(a)}
|
||||
execsql {SELECT name FROM sqlite_master WHERE tbl_name='tab1' ORDER BY name}
|
||||
} {idx1 tab1}
|
||||
integrity_check index-9.3
|
||||
|
||||
# Allow more than one entry with the same key.
|
||||
#
|
||||
@@ -302,6 +317,7 @@ do_test index-10.8 {
|
||||
SELECT b FROM t1 ORDER BY b;
|
||||
}
|
||||
} {0}
|
||||
integrity_check index-10.9
|
||||
|
||||
# Automatically create an index when we specify a primary key.
|
||||
#
|
||||
@@ -317,7 +333,201 @@ do_test index-11.1 {
|
||||
for {set i 1} {$i<=50} {incr i} {
|
||||
execsql "INSERT INTO t3 VALUES('x${i}x',$i,0.$i)"
|
||||
}
|
||||
execsql {SELECT c, fcnt() FROM t3 WHERE b==10}
|
||||
} {0.10 1}
|
||||
set sqlite_search_count 0
|
||||
concat [execsql {SELECT c FROM t3 WHERE b==10}] $sqlite_search_count
|
||||
} {0.10 3}
|
||||
integrity_check index-11.2
|
||||
|
||||
|
||||
# Numeric strings should compare as if they were numbers. So even if the
|
||||
# strings are not character-by-character the same, if they represent the
|
||||
# same number they should compare equal to one another. Verify that this
|
||||
# is true in indices.
|
||||
#
|
||||
do_test index-12.1 {
|
||||
execsql {
|
||||
CREATE TABLE t4(a,b);
|
||||
INSERT INTO t4 VALUES('0.0',1);
|
||||
INSERT INTO t4 VALUES('0.00',2);
|
||||
INSERT INTO t4 VALUES('abc',3);
|
||||
INSERT INTO t4 VALUES('-1.0',4);
|
||||
INSERT INTO t4 VALUES('+1.0',5);
|
||||
INSERT INTO t4 VALUES('0',6);
|
||||
INSERT INTO t4 VALUES('00000',7);
|
||||
SELECT a FROM t4 ORDER BY b;
|
||||
}
|
||||
} {0.0 0.00 abc -1.0 +1.0 0 00000}
|
||||
do_test index-12.2 {
|
||||
execsql {
|
||||
SELECT a FROM t4 WHERE a==0 ORDER BY b
|
||||
}
|
||||
} {0.0 0.00 0 00000}
|
||||
do_test index-12.3 {
|
||||
execsql {
|
||||
SELECT a FROM t4 WHERE a<0.5 ORDER BY b
|
||||
}
|
||||
} {0.0 0.00 -1.0 0 00000}
|
||||
do_test index-12.4 {
|
||||
execsql {
|
||||
SELECT a FROM t4 WHERE a>-0.5 ORDER BY b
|
||||
}
|
||||
} {0.0 0.00 abc +1.0 0 00000}
|
||||
do_test index-12.5 {
|
||||
execsql {
|
||||
CREATE INDEX t4i1 ON t4(a);
|
||||
SELECT a FROM t4 WHERE a==0 ORDER BY b
|
||||
}
|
||||
} {0.0 0.00 0 00000}
|
||||
do_test index-12.6 {
|
||||
execsql {
|
||||
SELECT a FROM t4 WHERE a<0.5 ORDER BY b
|
||||
}
|
||||
} {0.0 0.00 -1.0 0 00000}
|
||||
do_test index-12.7 {
|
||||
execsql {
|
||||
SELECT a FROM t4 WHERE a>-0.5 ORDER BY b
|
||||
}
|
||||
} {0.0 0.00 abc +1.0 0 00000}
|
||||
integrity_check index-12.8
|
||||
|
||||
# Make sure we cannot drop an automatically created index.
|
||||
#
|
||||
do_test index-13.1 {
|
||||
execsql {
|
||||
CREATE TABLE t5(
|
||||
a int UNIQUE,
|
||||
b float PRIMARY KEY,
|
||||
c varchar(10),
|
||||
UNIQUE(a,c)
|
||||
);
|
||||
INSERT INTO t5 VALUES(1,2,3);
|
||||
SELECT * FROM t5;
|
||||
}
|
||||
} {1 2 3}
|
||||
do_test index-13.2 {
|
||||
set ::idxlist [execsql {
|
||||
SELECT name FROM sqlite_master WHERE type="index" AND tbl_name="t5";
|
||||
}]
|
||||
llength $::idxlist
|
||||
} {3}
|
||||
for {set i 0} {$i<[llength $::idxlist]} {incr i} {
|
||||
do_test index-13.3.$i {
|
||||
catchsql "
|
||||
DROP INDEX '[lindex $::idxlist $i]';
|
||||
"
|
||||
} {1 {index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped}}
|
||||
}
|
||||
do_test index-13.4 {
|
||||
execsql {
|
||||
INSERT INTO t5 VALUES('a','b','c');
|
||||
SELECT * FROM t5;
|
||||
}
|
||||
} {1 2 3 a b c}
|
||||
integrity_check index-13.5
|
||||
|
||||
# Check the sort order of data in an index.
|
||||
#
|
||||
do_test index-14.1 {
|
||||
execsql {
|
||||
CREATE TABLE t6(a,b,c);
|
||||
CREATE INDEX t6i1 ON t6(a,b);
|
||||
INSERT INTO t6 VALUES('','',1);
|
||||
INSERT INTO t6 VALUES('',NULL,2);
|
||||
INSERT INTO t6 VALUES(NULL,'',3);
|
||||
INSERT INTO t6 VALUES('abc',123,4);
|
||||
INSERT INTO t6 VALUES(123,'abc',5);
|
||||
SELECT c FROM t6 ORDER BY a,b;
|
||||
}
|
||||
} {3 5 2 1 4}
|
||||
do_test index-14.2 {
|
||||
execsql {
|
||||
SELECT c FROM t6 WHERE a='';
|
||||
}
|
||||
} {2 1}
|
||||
do_test index-14.3 {
|
||||
execsql {
|
||||
SELECT c FROM t6 WHERE b='';
|
||||
}
|
||||
} {1 3}
|
||||
do_test index-14.4 {
|
||||
execsql {
|
||||
SELECT c FROM t6 WHERE a>'';
|
||||
}
|
||||
} {4}
|
||||
do_test index-14.5 {
|
||||
execsql {
|
||||
SELECT c FROM t6 WHERE a>='';
|
||||
}
|
||||
} {2 1 4}
|
||||
do_test index-14.6 {
|
||||
execsql {
|
||||
SELECT c FROM t6 WHERE a>123;
|
||||
}
|
||||
} {2 1 4}
|
||||
do_test index-14.7 {
|
||||
execsql {
|
||||
SELECT c FROM t6 WHERE a>=123;
|
||||
}
|
||||
} {5 2 1 4}
|
||||
do_test index-14.8 {
|
||||
execsql {
|
||||
SELECT c FROM t6 WHERE a<'abc';
|
||||
}
|
||||
} {5 2 1}
|
||||
do_test index-14.9 {
|
||||
execsql {
|
||||
SELECT c FROM t6 WHERE a<='abc';
|
||||
}
|
||||
} {5 2 1 4}
|
||||
do_test index-14.10 {
|
||||
execsql {
|
||||
SELECT c FROM t6 WHERE a<='';
|
||||
}
|
||||
} {5 2 1}
|
||||
do_test index-14.11 {
|
||||
execsql {
|
||||
SELECT c FROM t6 WHERE a<'';
|
||||
}
|
||||
} {5}
|
||||
integrity_check index-14.12
|
||||
|
||||
do_test index-15.1 {
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {}
|
||||
do_test index-15.2 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES('1.234e5',1);
|
||||
INSERT INTO t1 VALUES('12.33e04',2);
|
||||
INSERT INTO t1 VALUES('12.35E4',3);
|
||||
INSERT INTO t1 VALUES('12.34e',4);
|
||||
INSERT INTO t1 VALUES('12.32e+4',5);
|
||||
INSERT INTO t1 VALUES('12.36E+04',6);
|
||||
INSERT INTO t1 VALUES('12.36E+',7);
|
||||
INSERT INTO t1 VALUES('+123.10000E+0003',8);
|
||||
INSERT INTO t1 VALUES('+',9);
|
||||
INSERT INTO t1 VALUES('+12347.E+02',10);
|
||||
INSERT INTO t1 VALUES('+12347E+02',11);
|
||||
SELECT b FROM t1 ORDER BY a;
|
||||
}
|
||||
} {8 5 2 1 3 6 11 9 10 4 7}
|
||||
integrity_check index-15.1
|
||||
|
||||
# Drop index with a quoted name. Ticket #695.
|
||||
#
|
||||
do_test index-16.1 {
|
||||
execsql {
|
||||
CREATE INDEX "t6i2" ON t6(c);
|
||||
DROP INDEX "t6i2";
|
||||
}
|
||||
} {}
|
||||
do_test index-16.2 {
|
||||
execsql {
|
||||
DROP INDEX "t6i1";
|
||||
}
|
||||
} {}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
+127
-1
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the INSERT statement.
|
||||
#
|
||||
# $Id: insert.test,v 1.6 2001/09/16 00:13:28 drh Exp $
|
||||
# $Id: insert.test,v 1.15 2003/06/15 23:42:25 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -156,5 +156,131 @@ do_test insert-3.3 {
|
||||
do_test insert-3.4 {
|
||||
execsql {SELECT * FROM test2 WHERE f1=22 AND f2=-4.44}
|
||||
} {22 -4.44 hi abc-123 wham}
|
||||
integrity_check insert-3.5
|
||||
|
||||
# Test of expressions in the VALUES clause
|
||||
#
|
||||
do_test insert-4.1 {
|
||||
execsql {
|
||||
CREATE TABLE t3(a,b,c);
|
||||
INSERT INTO t3 VALUES(1+2+3,4,5);
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {6 4 5}
|
||||
do_test insert-4.2 {
|
||||
execsql {
|
||||
INSERT INTO t3 VALUES((SELECT max(a) FROM t3)+1,5,6);
|
||||
SELECT * FROM t3 ORDER BY a;
|
||||
}
|
||||
} {6 4 5 7 5 6}
|
||||
do_test insert-4.3 {
|
||||
catchsql {
|
||||
INSERT INTO t3 VALUES((SELECT max(a) FROM t3)+1,t3.a,6);
|
||||
SELECT * FROM t3 ORDER BY a;
|
||||
}
|
||||
} {1 {no such column: t3.a}}
|
||||
do_test insert-4.4 {
|
||||
execsql {
|
||||
INSERT INTO t3 VALUES((SELECT b FROM t3 WHERE a=0),6,7);
|
||||
SELECT * FROM t3 ORDER BY a;
|
||||
}
|
||||
} {{} 6 7 6 4 5 7 5 6}
|
||||
do_test insert-4.5 {
|
||||
execsql {
|
||||
SELECT b,c FROM t3 WHERE a IS NULL;
|
||||
}
|
||||
} {6 7}
|
||||
do_test insert-4.6 {
|
||||
catchsql {
|
||||
INSERT INTO t3 VALUES(notafunc(2,3),2,3);
|
||||
}
|
||||
} {1 {no such function: notafunc}}
|
||||
do_test insert-4.7 {
|
||||
execsql {
|
||||
INSERT INTO t3 VALUES(min(1,2,3),max(1,2,3),99);
|
||||
SELECT * FROM t3 WHERE c=99;
|
||||
}
|
||||
} {1 3 99}
|
||||
|
||||
# Test the ability to insert from a temporary table into itself.
|
||||
# Ticket #275.
|
||||
#
|
||||
do_test insert-5.1 {
|
||||
execsql {
|
||||
CREATE TEMP TABLE t4(x);
|
||||
INSERT INTO t4 VALUES(1);
|
||||
SELECT * FROM t4;
|
||||
}
|
||||
} {1}
|
||||
do_test insert-5.2 {
|
||||
execsql {
|
||||
INSERT INTO t4 SELECT x+1 FROM t4;
|
||||
SELECT * FROM t4;
|
||||
}
|
||||
} {1 2}
|
||||
do_test insert-5.3 {
|
||||
# verify that a temporary table is used to copy t4 to t4
|
||||
set x [execsql {
|
||||
EXPLAIN INSERT INTO t4 SELECT x+2 FROM t4;
|
||||
}]
|
||||
expr {[lsearch $x OpenTemp]>0}
|
||||
} {1}
|
||||
do_test insert-5.4 {
|
||||
# Verify that table "test1" begins on page 3. This should be the same
|
||||
# page number used by "t4" above.
|
||||
execsql {
|
||||
SELECT rootpage FROM sqlite_master WHERE name='test1';
|
||||
}
|
||||
} {3}
|
||||
do_test insert-5.5 {
|
||||
# Verify that "t4" begins on page 3.
|
||||
execsql {
|
||||
SELECT rootpage FROM sqlite_temp_master WHERE name='t4';
|
||||
}
|
||||
} {3}
|
||||
do_test insert-5.6 {
|
||||
# This should not use an intermediate temporary table.
|
||||
execsql {
|
||||
INSERT INTO t4 SELECT one FROM test1 WHERE three=7;
|
||||
SELECT * FROM t4
|
||||
}
|
||||
} {1 2 8}
|
||||
do_test insert-5.7 {
|
||||
# verify that no temporary table is used to copy test1 to t4
|
||||
set x [execsql {
|
||||
EXPLAIN INSERT INTO t4 SELECT one FROM test1;
|
||||
}]
|
||||
expr {[lsearch $x OpenTemp]>0}
|
||||
} {0}
|
||||
|
||||
# Ticket #334: REPLACE statement corrupting indices.
|
||||
#
|
||||
do_test insert-6.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE);
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
INSERT INTO t1 VALUES(2,3);
|
||||
SELECT b FROM t1 WHERE b=2;
|
||||
}
|
||||
} {2}
|
||||
do_test insert-6.2 {
|
||||
execsql {
|
||||
REPLACE INTO t1 VALUES(1,4);
|
||||
SELECT b FROM t1 WHERE b=2;
|
||||
}
|
||||
} {}
|
||||
do_test insert-6.3 {
|
||||
execsql {
|
||||
UPDATE OR REPLACE t1 SET a=2 WHERE b=4;
|
||||
SELECT * FROM t1 WHERE b=4;
|
||||
}
|
||||
} {2 4}
|
||||
do_test insert-6.4 {
|
||||
execsql {
|
||||
SELECT * FROM t1 WHERE b=3;
|
||||
}
|
||||
} {}
|
||||
|
||||
integrity_check insert-99.0
|
||||
|
||||
finish_test
|
||||
|
||||
+124
-5
@@ -12,7 +12,7 @@
|
||||
# focus of this file is testing the INSERT statement that takes is
|
||||
# result from a SELECT.
|
||||
#
|
||||
# $Id: insert2.test,v 1.4 2001/09/16 00:13:28 drh Exp $
|
||||
# $Id: insert2.test,v 1.10 2002/06/25 13:16:04 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -30,32 +30,46 @@ do_test insert2-1.0 {
|
||||
|
||||
# Insert into a new table from the old one.
|
||||
#
|
||||
do_test insert2-1.1 {
|
||||
do_test insert2-1.1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(log int, cnt int);
|
||||
---vdbe-trace-on--
|
||||
PRAGMA count_changes=on;
|
||||
INSERT INTO t1 SELECT log, count(*) FROM d1 GROUP BY log;
|
||||
}
|
||||
} {6}
|
||||
do_test insert2-1.1.2 {
|
||||
db changes
|
||||
} {6}
|
||||
do_test insert2-1.1.3 {
|
||||
execsql {SELECT * FROM t1 ORDER BY log}
|
||||
} {0 1 1 1 2 2 3 4 4 8 5 4}
|
||||
|
||||
do_test insert2-1.2 {
|
||||
do_test insert2-1.2.1 {
|
||||
catch {execsql {DROP TABLE t1}}
|
||||
execsql {
|
||||
CREATE TABLE t1(log int, cnt int);
|
||||
INSERT INTO t1
|
||||
SELECT log, count(*) FROM d1 GROUP BY log
|
||||
EXCEPT SELECT n-1,log FROM d1;
|
||||
}
|
||||
} {4}
|
||||
do_test insert2-1.2.2 {
|
||||
execsql {
|
||||
SELECT * FROM t1 ORDER BY log;
|
||||
}
|
||||
} {0 1 3 4 4 8 5 4}
|
||||
do_test insert2-1.3 {
|
||||
do_test insert2-1.3.1 {
|
||||
catch {execsql {DROP TABLE t1}}
|
||||
execsql {
|
||||
CREATE TABLE t1(log int, cnt int);
|
||||
PRAGMA count_changes=off;
|
||||
INSERT INTO t1
|
||||
SELECT log, count(*) FROM d1 GROUP BY log
|
||||
INTERSECT SELECT n-1,log FROM d1;
|
||||
}
|
||||
} {}
|
||||
do_test insert2-1.3.2 {
|
||||
execsql {
|
||||
SELECT * FROM t1 ORDER BY log;
|
||||
}
|
||||
} {1 1 2 2}
|
||||
@@ -72,4 +86,109 @@ do_test insert2-1.4 {
|
||||
lappend r [execsql {SELECT log FROM t1 WHERE cnt=4 ORDER BY log}]
|
||||
} {0 1 1 1 2 2 3 4 4 8 5 4 4 {3 5}}
|
||||
|
||||
do_test insert2-2.0 {
|
||||
execsql {
|
||||
CREATE TABLE t3(a,b,c);
|
||||
CREATE TABLE t4(x,y);
|
||||
INSERT INTO t4 VALUES(1,2);
|
||||
SELECT * FROM t4;
|
||||
}
|
||||
} {1 2}
|
||||
do_test insert2-2.1 {
|
||||
execsql {
|
||||
INSERT INTO t3(a,c) SELECT * FROM t4;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1 {} 2}
|
||||
do_test insert2-2.2 {
|
||||
execsql {
|
||||
DELETE FROM t3;
|
||||
INSERT INTO t3(c,b) SELECT * FROM t4;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {{} 2 1}
|
||||
do_test insert2-2.3 {
|
||||
execsql {
|
||||
DELETE FROM t3;
|
||||
INSERT INTO t3(c,a,b) SELECT x, 'hi', y FROM t4;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {hi 2 1}
|
||||
|
||||
integrity_check insert2-3.0
|
||||
|
||||
# File table t4 with lots of data
|
||||
#
|
||||
do_test insert2-3.1 {
|
||||
execsql {
|
||||
SELECT * from t4;
|
||||
}
|
||||
} {1 2}
|
||||
do_test insert2-3.2 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO t4 VALUES(2,4);
|
||||
INSERT INTO t4 VALUES(3,6);
|
||||
INSERT INTO t4 VALUES(4,8);
|
||||
INSERT INTO t4 VALUES(5,10);
|
||||
INSERT INTO t4 VALUES(6,12);
|
||||
INSERT INTO t4 VALUES(7,14);
|
||||
INSERT INTO t4 VALUES(8,16);
|
||||
INSERT INTO t4 VALUES(9,18);
|
||||
INSERT INTO t4 VALUES(10,20);
|
||||
COMMIT;
|
||||
}
|
||||
db changes
|
||||
} {9}
|
||||
do_test insert2-3.2.1 {
|
||||
execsql {
|
||||
SELECT count(*) FROM t4;
|
||||
}
|
||||
} {10}
|
||||
do_test insert2-3.3 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO t4 SELECT x+(SELECT max(x) FROM t4),y FROM t4;
|
||||
INSERT INTO t4 SELECT x+(SELECT max(x) FROM t4),y FROM t4;
|
||||
INSERT INTO t4 SELECT x+(SELECT max(x) FROM t4),y FROM t4;
|
||||
INSERT INTO t4 SELECT x+(SELECT max(x) FROM t4),y FROM t4;
|
||||
COMMIT;
|
||||
SELECT count(*) FROM t4;
|
||||
}
|
||||
} {160}
|
||||
do_test insert2-3.4 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
UPDATE t4 SET y='lots of data for the row where x=' || x
|
||||
|| ' and y=' || y || ' - even more data to fill space';
|
||||
COMMIT;
|
||||
SELECT count(*) FROM t4;
|
||||
}
|
||||
} {160}
|
||||
do_test insert2-3.5 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO t4 SELECT x+(SELECT max(x)+1 FROM t4),y FROM t4;
|
||||
SELECT count(*) from t4;
|
||||
ROLLBACK;
|
||||
}
|
||||
} {320}
|
||||
do_test insert2-3.6 {
|
||||
execsql {
|
||||
SELECT count(*) FROM t4;
|
||||
}
|
||||
} {160}
|
||||
do_test insert2-3.7 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
DELETE FROM t4 WHERE x!=123;
|
||||
SELECT count(*) FROM t4;
|
||||
ROLLBACK;
|
||||
}
|
||||
} {1}
|
||||
do_test insert2-3.8 {
|
||||
db changes
|
||||
} {159}
|
||||
integrity_check insert2-3.9
|
||||
|
||||
finish_test
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user