Compare commits

..

398 Commits

Author SHA1 Message Date
drh 739aab893a Version 3.2.8 (CVS 2835)
FossilOrigin-Name: e61382aed45a83ad688a0461948f9cd052a527fa
2005-12-19 17:26:59 +00:00
drh 6a42c8f368 Bump the version number on the 3.2 branch to 3.2.8. (CVS 2830)
FossilOrigin-Name: d8e74af5b081a074173c470e9f2115be9b095777
2005-12-19 16:34:31 +00:00
drh 523de6a830 Backport the fix for ticket #1567 into the 3.2 branch. (CVS 2829)
FossilOrigin-Name: 33397742282425351157a92785f83f10ad564af7
2005-12-19 16:29:07 +00:00
drh b842b1a61f Version 3.2.7 (CVS 2736)
FossilOrigin-Name: bd141a7c12c779d15d81acc8f919c37b9a4aa40b
2005-09-24 15:25:01 +00:00
drh 8dc5a288c6 Perparations for version 3.2.7. (CVS 2735)
FossilOrigin-Name: 70937d5cfa10eda66d926d378f30f9961a7822bf
2005-09-24 15:10:59 +00:00
drh 74217cc079 Add the SQLite console source code in the contrib section of the source tree. (CVS 2734)
FossilOrigin-Name: 079c6348f944ad708214f5f335065373d9ae509a
2005-09-24 11:01:11 +00:00
drh 8e647b8191 Fix an uninitialized structure member that was causing a malfunction when
you used deeply nested and very complex views.  Ticket #1449. (CVS 2733)

FossilOrigin-Name: 352cc9f53b7724621ecbf3a6362f34c31a18cce8
2005-09-23 21:11:53 +00:00
drh c035e6e4ab Optionally call fdatasync() instead of fsync() only if _POSIX_SYNCHRONIZED_IO
is positive, which should only be the case on operating systems that
actually support fdatasync(). (CVS 2732)

FossilOrigin-Name: a9b341dccffaf324a64139d6f482599258ef7009
2005-09-22 15:45:04 +00:00
drh de29e3e9be Add VM code comments on the group-by processing. Extra group-by test case. (CVS 2731)
FossilOrigin-Name: 655e75ac7d96b05c118226c5b70443da2df319ec
2005-09-20 18:13:23 +00:00
drh d654be803f Code cleanup and simplification. Three new Mem opcodes added.
The sqlite3VdbeJumpHere function added. (CVS 2730)

FossilOrigin-Name: 2471957feee57538e5e1e50a704a337f0927d10e
2005-09-20 17:42:23 +00:00
drh 4f68623875 Cleanup the implementation and the documentation of the new 0x200 P1 flag
on the VDBE comparison operands. (CVS 2729)

FossilOrigin-Name: f22d0f64a0b9100e16746fb800efa508d286e40e
2005-09-20 13:55:18 +00:00
drh e313382e3e NULLs compare equal to each other when computing GROUP BY categories. (CVS 2728)
FossilOrigin-Name: d9b0c9705379a8b3a28a83bb29fc1cd688fe184e
2005-09-20 13:11:59 +00:00
drh b6fb62d9b4 Update comments in where.c. No code changes. (CVS 2727)
FossilOrigin-Name: bb84d27eda64479d65b13fbbcaeef6a00da4d103
2005-09-20 08:47:20 +00:00
drh e1547a2f1c Documentation updates. (CVS 2726)
FossilOrigin-Name: 6ec8883c366532948e619830ff7d9f63b79fc08b
2005-09-20 01:36:30 +00:00
drh 22d6a53a77 ON-clause terms in a LEFT JOIN that restrict only the left table, should not
really restrict the left table but instead rows that fail to meet the condition
to be joined with NULL rows from the right table. (CVS 2725)

FossilOrigin-Name: ea10f9785e3c5248dafcc297f3a2c5465b6e0dba
2005-09-19 21:05:48 +00:00
drh eb8cbaeb18 Set the default maximum page size to 32768, not 8192. (CVS 2724)
FossilOrigin-Name: b32e9ec2480f9da2c2ea705ed3c88ca77b77cf2a
2005-09-19 19:05:21 +00:00
drh 4b14b4d720 Do not optimize views with an ORDER BY clause if they are used in a UNION ALL
that also has an ORDER BY clause.  Ticket #1444. (CVS 2723)

FossilOrigin-Name: 6cc57fcf15cfa3ce73c78b1cac90f7806e5bae40
2005-09-19 17:35:53 +00:00
drh a7aa59e097 Fix uninitialized value on a UNION ALL select with an ORDER BY clause. (CVS 2722)
FossilOrigin-Name: 92126a216101d30e16390bf063d52d7182fbc763
2005-09-19 15:37:06 +00:00
drh 549c8b68c7 The sqlite3_query_plan debugging variable now only appears with SQLITE_TEST=1. (CVS 2721)
FossilOrigin-Name: 41e226d2ff5c0021fd07388da13f6d750fac508b
2005-09-19 13:15:23 +00:00
drh bbdc2b94fc Work around limitations of MSVC++ 6. Tickets #1429, #1437, and #1440. (CVS 2720)
FossilOrigin-Name: b2d1803c25b0b823c9cbe27989bacb730b18b45b
2005-09-19 12:53:18 +00:00
drh 48083cee4c Change some debugging #defines in order to get SSE working again after
recent upgrades. (CVS 2719)

FossilOrigin-Name: 86eb7d8363559c94bfcd7e48ff6270025ecacb7b
2005-09-19 12:37:27 +00:00
drh a15cdcc4f4 Download page reports sizes in MiB and KiB instead of just bytes. (CVS 2718)
FossilOrigin-Name: e985f02d20d50b0451bfd35a7343e0386336dd71
2005-09-17 19:28:45 +00:00
drh ee2b437f0a Update to the download page on the website. (CVS 2717)
FossilOrigin-Name: 91bc0d0032d5305671da0ebfc6e697b9b882f1ad
2005-09-17 19:14:40 +00:00
drh 8cb1895c74 Version 3.2.6 (CVS 2716)
FossilOrigin-Name: 1cdfe66714c2374b1d93bc62f37873111e090e44
2005-09-17 18:49:49 +00:00
drh 5c959118f1 The sqlite3ReallocOrFree routine should set its pointer to NULL when it fails. (CVS 2715)
FossilOrigin-Name: 0e85af44faca4b625e6ab7cb21a300867298c539
2005-09-17 18:34:11 +00:00
drh e3000ae84c Fix up the busy test so that it can be run multiple times in a row without
giving false errors on 2nd and subsequent runs. (CVS 2714)

FossilOrigin-Name: 7a7ba73fb5d1d493dc2c8c0d5ed4ee6d895bb339
2005-09-17 18:02:36 +00:00
drh ac1733d409 Fix a memory leak that occurs after malloc fails. (CVS 2713)
FossilOrigin-Name: 85b931bf72dac88187e4531053a06abe25d6f462
2005-09-17 17:58:22 +00:00
drh 0aadf33312 Fix the crash.test script to accomodate recent changes. (CVS 2712)
FossilOrigin-Name: d594608ff37bbf1d6866adb337aa2fbcd517eada
2005-09-17 17:05:19 +00:00
drh 432a93ba73 Fix a bug in the lock2 test script introduced by check-in (2709) (CVS 2711)
FossilOrigin-Name: c3bf17436bc1e264b4dbe255876a990a5a2b8b0c
2005-09-17 16:48:18 +00:00
drh a67367e7d1 Fix a problem with the lock_status pragma and the UTF-16 encoding. (CVS 2710)
FossilOrigin-Name: 1a737b457c59286d7d5c3a98391dec17dbc82d09
2005-09-17 16:36:55 +00:00
drh 4928570812 Changes to make corruption errors easier to track down. (CVS 2709)
FossilOrigin-Name: c07330000b9427a77f412918078beffa18de2c36
2005-09-17 15:20:26 +00:00
drh bfcb8909c6 Update the webpage description of 3.2.6 changes to talk about ticket #1432. (CVS 2708)
FossilOrigin-Name: 0e23c28b25aced292cb068bc9a202cb627ba38ec
2005-09-17 15:17:40 +00:00
drh 36da52425b Bug fix in the ORDER BY optimizer. Ticket #1435. (CVS 2707)
FossilOrigin-Name: 553b7ba8f8ae4cb865494f2d301690149d7edb9f
2005-09-17 13:29:23 +00:00
drh f5b1138bae Make sure dependencies on the right-hand side of IN operators are checked
correctly.  Ticket #1433. (CVS 2706)

FossilOrigin-Name: 21740794ab81924442f358a6adbbe6d5590cf58d
2005-09-17 13:07:13 +00:00
drh 4190d4b53e Updates to the FAQ. (CVS 2705)
FossilOrigin-Name: 0eaf430d9538ece1a3d1300db91f269577a5e028
2005-09-17 02:34:04 +00:00
drh 267cb326e9 Do not journal the locking page which doing an autovacuum. Similar to the
problem of #1432 except that this one occurs on autovacuum instead of vacuum.
An assert() has been added to catch any future incidents of this type. (CVS 2704)

FossilOrigin-Name: 5b6dc12b7d25d999be5d282cd0b06e02e2bda765
2005-09-16 17:16:52 +00:00
drh 50f2f43cba Do not journal the file locking page when doing a database copy as
part of a VACUUM.  Ticket #1432. (CVS 2703)

FossilOrigin-Name: 248f77972bb1be3325708ea143fd87bb7ce914a7
2005-09-16 11:32:18 +00:00
danielk1977 15f411dbdd Prevent the sqlite3_pagecount() function from ever returning the pending-byte
page. (CVS 2702)

FossilOrigin-Name: 35a8893537ae5faed6ee49270ac9c01a6010993f
2005-09-16 10:18:45 +00:00
danielk1977 2349c3d151 Move the definition of sqlite3_pending_byte from test2.c to os_common.h. (CVS 2701)
FossilOrigin-Name: bedf702f539636fa3b65fd0d6797b087481b4613
2005-09-16 10:13:41 +00:00
danielk1977 fd5f5b65b4 Fix an auto-vacuum problem with the PENDING_BYTE page. Also link the Tcl
variable sqlite_pending_byte to the internal pending-byte location when in test mode. (CVS 2700)

FossilOrigin-Name: 9115e0621d1fdc5a89a0288b87c0a4ce1e4b50c6
2005-09-16 09:52:29 +00:00
drh a2833a0cf6 Documentation changes in preparation for the release of 3.2.6. (CVS 2698)
FossilOrigin-Name: 243f455c7c4e5c0c56406c197fa78088bc3659ca
2005-09-16 02:55:13 +00:00
drh 688c9f0622 Undo check-in (2694). (CVS 2697)
FossilOrigin-Name: 6017b1962517eb206183042bbb718925d9819063
2005-09-16 02:48:01 +00:00
drh 53f733c7ae Fix a whole host of newly discovered memory leaks the occur after a
failure of realloc(). (CVS 2696)

FossilOrigin-Name: 4686d649756a0aa301ade901ac49c89a976c5402
2005-09-16 02:38:09 +00:00
drh b38ad9991c Fix a memory leak: a failure to deallocate the P3 parameter on a call
to sqlite3VdbeChangeP3. (CVS 2695)

FossilOrigin-Name: 714254cbc12564d44548707043fdcdffb17e4fde
2005-09-16 00:27:01 +00:00
drh 6e4fc2ca2b The table_info pragma now gives the order of columns in the primary key. (CVS 2694)
FossilOrigin-Name: 9b60f48de7fbca96c6e26266a8fb9eed8bc378f2
2005-09-15 21:24:51 +00:00
drh 289ab0760b Correct the sense of a test for SQLITE_DEBUG on the resent NDEBUG change.
Ticket #1425 (CVS 2693)

FossilOrigin-Name: 81fdffdff6fd107c361b1ee69649455143bf3921
2005-09-13 16:12:47 +00:00
drh 111cf34f7a Updates to the documentation on the TCL bindings. (CVS 2692)
FossilOrigin-Name: 94aa2d32459e1cee2df21fcc7df76c73dab903cd
2005-09-13 07:00:05 +00:00
drh b27795c183 Fix a comment typo in the previous check-in. (CVS 2691)
FossilOrigin-Name: 49c952807dabd80bfeb46caf55856aaab988226c
2005-09-13 00:02:16 +00:00
drh 4b529d97ff Automatically set the NDEBUG preprocessor macro unless SQLITE_DEBUG is set.
In this way, assert() statements become opt-in rather than opt-out. (CVS 2690)

FossilOrigin-Name: 2ec2bd85741e36e410f05ff34de430ffbcf51eea
2005-09-13 00:00:00 +00:00
drh 9d4673a9ea Bug fix in the new COUNT(DISTINCT) logic. Ticket #1420. (CVS 2689)
FossilOrigin-Name: 37116550d33d8e3bdc15cd9998b9d2b97dec312b
2005-09-12 23:03:16 +00:00
drh c99130fd82 COUNT(DISTINCT x) is now fully functional, though it could benefit from
additional testing. (CVS 2688)

FossilOrigin-Name: 2f397bd8142ec5e8f7238127012d14fdb558d918
2005-09-11 11:56:27 +00:00
drh 00b950d71e The ".dump" command from the shell correctly saves the state of the
sqlite_sequence and sqlite_stat1 tables, if they exist.  Ticket #1419. (CVS 2687)

FossilOrigin-Name: 3f191cf497e5798a8620ebc5a85e34187f58371c
2005-09-11 02:03:03 +00:00
drh 0c35667b02 The shell does not output the sqlite_stat1 table on .dump or .schema.
The ANALYZE command now gathers statistics on tables that have only
a single index because this sometimes helps when reordering tables
in a join. (CVS 2686)

FossilOrigin-Name: 26565b8931419031f9a8dd3947e1e2bd23ccbff2
2005-09-10 22:40:53 +00:00
drh ecc9242f6f Add the experimental EXPLAIN QUERY PLAN diagnostic capability. (CVS 2685)
FossilOrigin-Name: 986efb7b12643800805ad4b1f1e90e30fcf6d38a
2005-09-10 16:46:12 +00:00
drh d891967052 Avoid a memory leak and/or assertion failure when parsing a table
declaration that contains a duplicate column name.
Ticket #1418. (CVS 2684)

FossilOrigin-Name: f43427742b1c086f2621c900f4ede1a34a8b44ee
2005-09-10 15:35:06 +00:00
drh 3dec223ca0 Use of the CROSS keyword in a join prevents table reordering. Ticket #1414. (CVS 2683)
FossilOrigin-Name: 415b8b24629aa12756d8285c094b5f85d8a8e532
2005-09-10 15:28:09 +00:00
drh f307a4aaf8 Enhanced disk-full tests. (CVS 2682)
FossilOrigin-Name: 0288fa5d25886f6fbef0be782f12285d62bebd68
2005-09-09 10:46:19 +00:00
drh e08b814d72 Detect errors returned by SetFilePointer on windows. (CVS 2681)
FossilOrigin-Name: bc8c33f94ce069f7bcfc32a59d5c40e034e023b5
2005-09-09 10:17:33 +00:00
drh fd35797469 Infrastructure for the DISTINCT keyword in aggregate functions. But it does
not work yet.  If you try to use it you get an error message. (CVS 2680)

FossilOrigin-Name: 4d62e36fe3819c2a1412737c2ec8a91ddc5e1777
2005-09-09 01:33:19 +00:00
drh b4746b9e33 Defend against disk I/O errors that happen during an sqlite3OsSeek(). (CVS 2679)
FossilOrigin-Name: 461e3a0a27ff083b0bae10c9880e3b41bb85ee31
2005-09-09 01:32:06 +00:00
drh c2bd913a40 SUM returns NULL when it has no inputs. Ticket #1413. (CVS 2678)
FossilOrigin-Name: 6281859425d39c11d82875301fefafad1f08416d
2005-09-08 20:37:43 +00:00
drh 3f219f46fc A SUM() of all NULLs returns NULL. A SUM() of nothing return 0.
A SUM() of a mixture of NULLs and numbers returns the sum of the
numbers.  Ticket #1413. (CVS 2677)

FossilOrigin-Name: 2e6230edfd651b40481ebad8aa01a22ac92ce80c
2005-09-08 19:45:57 +00:00
drh 825c662e66 Remove a C++ism that snuck in on one of the reason changes. (CVS 2676)
FossilOrigin-Name: 48f6a331efea419fe948cd366f9c60ae41edddfd
2005-09-08 19:01:05 +00:00
drh 4f26bb62a8 Remove a few unused variables detected by Borland C. Ticket #1412. (CVS 2675)
FossilOrigin-Name: cdfe372a958fb446485913e860d52b87fffd34e4
2005-09-08 14:17:20 +00:00
drh 97571957a1 Aggregates with GROUP BY can sometimes return no result rows. (CVS 2674)
FossilOrigin-Name: 0c3e368d4766685b94a44f2c514e2dea806c297c
2005-09-08 12:57:28 +00:00
drh eb796a7c8f While doing a transaction comment, use fdatasync() instead of fsync() in
cases there the file size is unchanged. (CVS 2673)

FossilOrigin-Name: 3c555a87493128620ac967faf7c63c2a58856e9e
2005-09-08 12:38:41 +00:00
drh f80bcd73af Fix another test to account for SUM() returning integer rather than float. (CVS 2672)
FossilOrigin-Name: bc723235e65eb4da7d2e4b18653f1173374cb407
2005-09-08 12:37:28 +00:00
drh 2af6742d86 Fix typos in documentation. Ticket #1239. (CVS 2671)
FossilOrigin-Name: 73fbb8d9689fecec18c36814e4358e691bcd647e
2005-09-08 11:04:57 +00:00
drh 3224b32b00 Fix a comment in sqlite.h. Ticket #1321. (CVS 2670)
FossilOrigin-Name: ed4e9e751be2b982af9561aba20c8e1367828b81
2005-09-08 10:58:51 +00:00
drh 3d1d95e625 The SUM() aggregate function returns an integer result if all inputs are
integers.  Any single non-integer input causes the result to be a floating
point value. (CVS 2669)

FossilOrigin-Name: 21adf4bd99e732650a1e8e9a1cc954126983a654
2005-09-08 10:37:01 +00:00
drh d49c16ee9b Changes to comments only in sqliteInt.h. No changes to code. (CVS 2668)
FossilOrigin-Name: cc2a61650ea0d4b2ef67e144424327362999526d
2005-09-08 02:00:25 +00:00
drh 9d2985c7b4 Optimizations and refinements. Improvements to test coverage. (CVS 2667)
FossilOrigin-Name: 7283f7c29db4f622380b6a5cb745a4dc0c8e6a25
2005-09-08 01:58:42 +00:00
drh 5360ad34b1 All regression tests now pass. But I am sure there must still be problems.
New tests need to be added. (CVS 2666)

FossilOrigin-Name: bcc7d722cea4487a3adf9d9b2af4b74bfbfc5f39
2005-09-08 00:13:27 +00:00
drh d1c301e804 More bug fixes. All of the "quick" tests pass. The full test suite still
shows problems. (CVS 2665)

FossilOrigin-Name: a1b6d910cdbb53f12366402d9585dce2aad3ba3d
2005-09-07 23:05:21 +00:00
drh 5774b80629 More bug fixes. But there are still tests that fail. (CVS 2664)
FossilOrigin-Name: 7e85a162d0ecf0acdbffcacc62b60d97fe123881
2005-09-07 22:48:16 +00:00
drh a10a34b88f Bug fixes in aggregate processing. Fewer tests fail. (CVS 2663)
FossilOrigin-Name: c3ac58592f5e6305640868cdf42c129f1a25255d
2005-09-07 22:09:48 +00:00
drh 13449892ef Rewrite the aggregate handling logic so that it runs in O(1) space.
This is the first cut at the code.  Many regression tests fail. (CVS 2662)

FossilOrigin-Name: 17039ec3ff4396862beedf4a8af89654b2140f58
2005-09-07 21:22:45 +00:00
drh 79158e1865 Changes to reduce the amount of stack space required. (CVS 2661)
FossilOrigin-Name: b86bd70f301205d6ca66475a425e157b976107e2
2005-09-06 21:40:45 +00:00
drh abfcea25ea Cleanup the processing of MEM_Agg elements. (CVS 2660)
FossilOrigin-Name: 7ecf3654aa9a275a4cf0c3ec5f63a8c1e0a11fc9
2005-09-06 20:36:48 +00:00
drh 1ec43c9a5a Fix ANALYZE so that it works even if the empty_result_callbacks pragma is
enabled. Ticket #1409. (CVS 2659)

FossilOrigin-Name: bfdaef1224d741deefe211e1e607bac4c80f2d89
2005-09-06 10:26:47 +00:00
drh b726ee6d1c Make due with "sub()" instead of "gsub()" in awk scripts so that builds will
work on Solaris which will runs an archiac version of AWK. (CVS 2658)

FossilOrigin-Name: 449a7895995013720f5d4c7b3b7f5bd6a5413717
2005-09-05 20:35:25 +00:00
drh d81bd4e209 Fix bugs introduced by checkin (2656) and do some modest code enhancements. (CVS 2657)
FossilOrigin-Name: 7b56763a8b514834198d2392639d6d726b17d901
2005-09-05 20:06:49 +00:00
drh c092998715 Use the unicode API to win32 where available.
Tickets #1407, #1396, #1331, #1243, #1206 (CVS 2656)

FossilOrigin-Name: 3ec58c673ae4cf0695ea0c287cc9bcbdcdb1a200
2005-09-05 19:08:29 +00:00
drh a21c8495f9 Fix over-aggressive optimization of ORDER BY as reported on the mailing list. (CVS 2655)
FossilOrigin-Name: efbb4bc83cd86b6a26d58c5818c58c2e3edaab18
2005-09-01 17:47:51 +00:00
drh 4db38a7092 All regression tests now pass with the new bounded-memory sort code.
There is still lots of opportunity for optimization, however. (CVS 2654)

FossilOrigin-Name: 81259a01f1e85ba50a1d017b1282bf841b16f0a5
2005-09-01 12:16:28 +00:00
drh 0342b1f542 Sorting is now done using a sorting index rather than loading the entire
result set into memory and doing a merge sort.  The old merge sort technique
was a carry-over from SQLite version 1.  The new method uses a bounded amount
of memory and scales to much larger result sets.  There are still errors:
some 39 regression tests fail. (CVS 2653)

FossilOrigin-Name: 09db0a24241f9248584250d1728117b8a3159626
2005-09-01 03:07:44 +00:00
drh dece1a8464 {quote: KeyInfo} generation moved to a common subroutine. (CVS 2652)
FossilOrigin-Name: a25801df06e218e70570a6b9eae71603d590fe3a
2005-08-31 18:20:00 +00:00
drh 6242b9511d Updates to the query optimizer overview document. (CVS 2651)
FossilOrigin-Name: b1dceef0508ffe20ab2ff8fa5e5b5a44f4f224aa
2005-08-31 13:48:34 +00:00
drh 37108e112a Explicit typecasts to silence nuisance compiler warnings. Ticket #1398. (CVS 2650)
FossilOrigin-Name: 90712ea7273597214d6c77a01e41f84146d201c8
2005-08-31 13:13:31 +00:00
drh a91965b38a Refinements to the optimizer overview and integration into the website. (CVS 2649)
FossilOrigin-Name: ccd12e9e790e271cb1dbbae1c13e9cb980eaf11d
2005-08-31 03:13:12 +00:00
drh b64d5ee42c Update the FAQ to include an entry about binary versus decimal numbers. (CVS 2648)
FossilOrigin-Name: 0bbe73fccfe52700c2ae1122388764e81a78bc22
2005-08-31 02:46:21 +00:00
drh f6ac657f27 Adding the first cut of the optimizer overview document. (CVS 2647)
FossilOrigin-Name: 4c8d0a4c26e44088ffb9f21aa7641a5ebd0058be
2005-08-31 01:49:59 +00:00
drh 8897f6fa3f Adjust the makefile for new optimizer documentation. (CVS 2646)
FossilOrigin-Name: 14668c85b87f7c9b83efd592ddc693522c764969
2005-08-30 22:44:29 +00:00
drh 3e60cdc3c0 Initial work on documentation describing the optimizer. (CVS 2645)
FossilOrigin-Name: 5cebd7ba3ccbdd0f4c8fe77091992f52d3a4b24c
2005-08-30 22:44:05 +00:00
drh 0a8640d4f2 The CSV output mode does not sign-extend bytes where the high-order bit is set.
Ticket #1397. (CVS 2644)

FossilOrigin-Name: 528df777e5d76077d8766f04ee222fd64d9373a6
2005-08-30 20:12:02 +00:00
drh 63782855ee Fix printf.c so that it handles 10.0 correctly. (CVS 2643)
FossilOrigin-Name: 0f7a53f78d9dd5c426be834f2d50a6fe4e860141
2005-08-30 19:30:59 +00:00
drh 5d9a4af9af Minor code enhancements. (CVS 2642)
FossilOrigin-Name: 4ab994a87ee844f453d693555abd61b51bb44a0e
2005-08-30 00:54:01 +00:00
drh 220b10285b Update the home page to brag about 150KiB code footprint when optional
features are omitted. (CVS 2641)

FossilOrigin-Name: 0e1ac1284c0547af0bb0eb4ff320b9f5ae9c248d
2005-08-30 00:10:45 +00:00
drh 01b4171e57 Make the shell aware of SQLITE_OMIT_MEMORYDB. Ticket #1395. (CVS 2640)
FossilOrigin-Name: 71a71cef5b3c97744322ceceb48ac3055512c987
2005-08-29 23:06:23 +00:00
drh 19e2d37f1d Increase resolution of time-of-day on unix. Add an experimental
sqlite3_profile() API. (CVS 2639)

FossilOrigin-Name: ed2ca0873fa89d6cfd123541d5d1c6b92c72b6ab
2005-08-29 23:00:03 +00:00
drh b46b57745d Initialize a local variable to avoid a nuisance compiler warning.
Ticket #1394. (CVS 2638)

FossilOrigin-Name: 9b914901a18f8ea39c39a51509c0b3b862c13d6a
2005-08-29 16:40:52 +00:00
drh d64fe2f374 The LIKE optimization does the right thing when collating sequences are
present.  LIKE expressions where the left-hand side has COLLATE NOCASE
are optimized in the default case. (CVS 2637)

FossilOrigin-Name: ef84ff795c85e9d28f1cac84ff42d8d4ef84cfc4
2005-08-28 17:00:23 +00:00
drh bfd6b03554 Improvements to the formatting and layout of the code in the previous checkin. (CVS 2636)
FossilOrigin-Name: 73b430de0c0f3cd230861fc1a53691818f17de0d
2005-08-28 01:38:44 +00:00
drh de941c605e Add an assert to verify that floating point values and integers use the
same byte order.  Add a comment to the SELECT code generator. (CVS 2635)

FossilOrigin-Name: 07b4892149a436dbd904c781b46e3b9a82a7a744
2005-08-28 01:34:21 +00:00
drh 9b4b45d5cf Version 3.2.5 (CVS 2634)
FossilOrigin-Name: b2415a749ca5352e5bb4ad08df0c947ec8b02d18
2005-08-27 17:23:00 +00:00
drh 0b9693556d Change the wording of the news line for release 3.2.5. (CVS 2633)
FossilOrigin-Name: 70db46d3efa4c7da4b99f7385afff03f778ab9c4
2005-08-27 17:22:11 +00:00
drh c5ee956611 Get the date right. Today is the 27th, not the 25th or the 28th. (CVS 2632)
FossilOrigin-Name: 905b9d6c5e624f35272bf49df0d88ceea2bb73e8
2005-08-27 17:19:33 +00:00
drh f9dc42d870 Increase the version number and update web pages for the next release. (CVS 2631)
FossilOrigin-Name: e6039e909a3fe807e1499fa99265ffe6c5c2008e
2005-08-27 17:06:15 +00:00
drh 2c8997b9a5 Disable synchronous writes to the master journal when PRAGMA synchronous=OFF
for all database files.  Ticket #1375. (CVS 2630)

FossilOrigin-Name: 644b96aa23de7e828280d35785db840a4fa9413d
2005-08-27 16:36:48 +00:00
drh 9cc5abd769 Fix comment in vdbeapi.c. Remove unused structure definition from func.c. (CVS 2629)
FossilOrigin-Name: 51a381345db45967567dd0a18905d352bf1081e0
2005-08-27 13:16:32 +00:00
drh ff8a0983d2 Remove the words "statically linked" from the description of the shell on
the download page.  Ticket #1391. (CVS 2628)

FossilOrigin-Name: ecb9604457d5ab6bcd81b582cc4dd85a8f371b86
2005-08-27 13:11:20 +00:00
drh 77207ab7c6 Remove GNUmake extensions from the makefile. Ticket #1390. (CVS 2627)
FossilOrigin-Name: d0691fed4344869830ea9ec2390bc1e7c1679844
2005-08-27 09:07:14 +00:00
drh 6e4b7cd4ef Do not change fields of stale sqlite3 handles. Ticket #1384. (CVS 2626)
FossilOrigin-Name: 7e05b7ca0ce72b1c6125196f4b21bbb676bc488c
2005-08-27 01:51:44 +00:00
drh e69cc5b742 Widen the opcode column of explain output in the shell. (CVS 2625)
FossilOrigin-Name: dd3b00aa0bf3b847b0b2f20f6df60d4e3a2d81df
2005-08-27 01:50:53 +00:00
drh 87abf5c033 When the left-hand side of an IN operator is constant and the right-hand
side is a SELECT, recognize that the IN operator is not constant.
Ticket #1380. (CVS 2624)

FossilOrigin-Name: fc9e04609b6968fc5039a6f9f808aac681f4fc41
2005-08-25 12:45:04 +00:00
drh 65d415cb72 Fix the --enable-threadsafe option to the configure script. Ticket #1378. (CVS 2623)
FossilOrigin-Name: 76ec0b3d3a6cc82965e4f993375780b954c53dd1
2005-08-24 18:04:51 +00:00
drh 0f77f5dc0b Additional defense against the rowid-fifo overflow problem. (CVS 2622)
FossilOrigin-Name: 881dcf5fb16997830ff347d2eb2610784b415f25
2005-08-24 17:07:37 +00:00
drh 978468d488 Remove a stray C++ style comment causing problems for some compilers. (CVS 2621)
FossilOrigin-Name: aa7dd3f2c72335fe7778c021e4b6bbbc4ec322df
2005-08-24 16:54:05 +00:00
drh 3ca84ba0a0 Fix a bug in DELETE that might cause a segfault when deleting more
than 40940 rows of data all at once. (CVS 2620)

FossilOrigin-Name: 7c599bae33ba4eb10fc486ae3dab76330ce69936
2005-08-24 16:13:51 +00:00
drh 3268f2b10c Version 3.2.4 (CVS 2619)
FossilOrigin-Name: 8cef2c1ae728970a38d794f9903115da5d0fcd55
2005-08-24 11:14:46 +00:00
drh 96c52a9b48 Increase the version number and update the change log prior to release. (CVS 2618)
FossilOrigin-Name: 139a28d231875e72538fd6842168c458441ad1d0
2005-08-24 11:07:19 +00:00
drh 9eb2028fbc After calling realloc() on an array to resize it, be sure not to use pointers
into the old array.  Ticket #1376. (CVS 2617)

FossilOrigin-Name: 9f9a257123274779150cbc290b9f86a09b3b2c03
2005-08-24 03:52:18 +00:00
drh 7681618c18 Allow floating point literals to being or end with a decimal point.
Ticket #1371. (CVS 2616)

FossilOrigin-Name: a715e7001247e84e0982335570593f0802774635
2005-08-23 11:31:26 +00:00
drh 6c8c6cec1f Handle empty blob constants correctly. Ticket #1373. (CVS 2615)
FossilOrigin-Name: 5cada745ac9bf18a65d21705a398b2bb8bd1aaa2
2005-08-23 11:17:58 +00:00
drh 75757853a0 Fix another documentation typo. (CVS 2614)
FossilOrigin-Name: 55f4b14e1958ff3d2b0c99749f0c01192bafbf37
2005-08-23 11:03:02 +00:00
drh 8c154875b1 Fix typos in syntax documentation. Ticket #1374 and a report on the mailing
list. (CVS 2613)

FossilOrigin-Name: 990d1f3a5b13cadc2930334c4bd7007e3645e75b
2005-08-23 11:00:39 +00:00
drh ff1bc76916 Update the download page of the website to handle TEA builds and starkits. (CVS 2612)
FossilOrigin-Name: 1fab599b6f89534152c53b820b5e6ee1ba30c059
2005-08-22 02:10:46 +00:00
drh ad81e87054 Clean up possible locking problem in multithreaded applications that take
a malloc failure. (CVS 2611)

FossilOrigin-Name: 545e702a23c7a6b09e10441d4137efe5a9618a84
2005-08-21 21:45:01 +00:00
drh 03e7954732 Version 3.2.3 (CVS 2610)
FossilOrigin-Name: f620319b440dab9f8a0ad9ada3e6ee5560d5c623
2005-08-21 18:54:48 +00:00
drh 7a22af6a60 Increase the version number and adjust documentation prior to the next release. (CVS 2609)
FossilOrigin-Name: b15ed7db4d5186d8b22c0b51cd44c4d9d7001318
2005-08-21 18:40:20 +00:00
drh 788581d78a Disable malloc tests when not compiled with SQLITE_DEBUG. (CVS 2608)
FossilOrigin-Name: f372682fa375c22213da0e4cd8413eab3c6ac85b
2005-08-21 18:21:50 +00:00
drh 130b9f4040 Do not create an error message if there is no error. (CVS 2607)
FossilOrigin-Name: 3aa47c5587819a5fc3e2cb53a7fbc79ba65f0c3b
2005-08-21 17:48:46 +00:00
drh 992f2d781d Do not overwrite small files (less than 1024 bytes) that are not databases.
Ticket #1370. (CVS 2606)

FossilOrigin-Name: 7f4302686e55f22b281d98a8a3b89300f4ce4eb6
2005-08-21 16:54:25 +00:00
drh f0bce09cdd More test coverage improvements. (CVS 2605)
FossilOrigin-Name: e559e810a51427def6928763ae0d6f7347366d04
2005-08-20 13:47:41 +00:00
drh 85c23c61e2 Increased test coverage. Some malloc tests now fail though this is believed
to be an instrumentation problem not a real error. (CVS 2604)

FossilOrigin-Name: f786f37a5e31f42aaf81b3ad4a734f12855da69e
2005-08-20 03:03:04 +00:00
drh 0bbaa1ba9a Increase test coverage of alter.c to 100%. Fix bugs found in the process. (CVS 2603)
FossilOrigin-Name: b550d04d43a92f33a01438ae03df14678db3cdee
2005-08-19 19:14:12 +00:00
drh f14fd03899 Additional tests for better coverage. (CVS 2602)
FossilOrigin-Name: 4281a838f2f531af24b008d2834e8318798472c5
2005-08-19 03:03:51 +00:00
drh 5eba8c09df Increased test coverage on trigger.c and printf.c. (CVS 2601)
FossilOrigin-Name: 842a80bd8f18d6fd046604f9a057bcd738234f1f
2005-08-19 02:26:27 +00:00
drh fc23314a0b More test coverage enhancements. (CVS 2600)
FossilOrigin-Name: 0b6cd5acc0ede3367623f40ccfaa96116e686824
2005-08-19 01:07:15 +00:00
drh 8b3d990b71 Bring testing coverage of the analyze.c file up to 100%. Bugs found and
fixed in the process. (CVS 2599)

FossilOrigin-Name: 2fe0ac4fa4d5911e266979021fa7e413d96c558d
2005-08-19 00:14:42 +00:00
drh 91124b3545 Comment fixes. No changes to the underlying code. (CVS 2598)
FossilOrigin-Name: b865e243ee772f009dbf466d69525f2cdef78c0e
2005-08-18 18:15:05 +00:00
drh 731c96b412 Fix typo in documentation. (CVS 2597)
FossilOrigin-Name: 32efcd24612908516fb5bc58ab3fe4790586a220
2005-08-16 14:44:48 +00:00
drh ce604012ac Null-terminate the strings array passed to Tcl_GetIndexFromObj. Bug
reported on the mailing list. (CVS 2596)

FossilOrigin-Name: 3a7918a66bf98368c2520f94e505a21a1df3383c
2005-08-16 11:11:34 +00:00
drh c182d16302 General code cleanup resulting in smaller footprint. (CVS 2595)
FossilOrigin-Name: 98338abf9e8cfbf8efa81cff0e40ea37e34fd9b2
2005-08-14 20:47:16 +00:00
drh a2b902d66d Split the sqlite3_complete() API out into a separate source file so that
in static links where it is not used it will not take up space in the
resulting binary. (CVS 2594)

FossilOrigin-Name: 62b87751dea56c565bcc2aca88a2edda7dfc2a57
2005-08-14 17:53:20 +00:00
drh 9abc9c6aff Declare local-use functions as static. Ticket #1363. (CVS 2593)
FossilOrigin-Name: 94efd7908880c7d99c08ebc9a3437cfbefc42f7e
2005-08-14 01:34:19 +00:00
drh 55ef4d9758 The case_sensitive_like pragma added.
Test cases added for the LIKE optimization. (CVS 2592)

FossilOrigin-Name: 72ee21c05e618b6f46f5460f8c85779c72fe32d7
2005-08-14 01:20:37 +00:00
drh 3d94662a06 Provide grave accent quoting of identifiers for MySQL compatibility.
Ticket #1337. (CVS 2591)

FossilOrigin-Name: 6b7a4e97528a4e179e0bbae69469cb1a3d1f794b
2005-08-13 18:15:42 +00:00
drh d645967aaa Give the same access permissions to journal files as is given to databases. (CVS 2590)
FossilOrigin-Name: 7961ec0ccbc99d890689013b9602635941f308a6
2005-08-13 17:17:01 +00:00
drh 8718f52624 Disable an overzealous optimization the omitted sorting on a join if the first
table gave a unique result.  The sort can only be omitted if all tables in
the join are unique.  Ticket #1358. (CVS 2589)

FossilOrigin-Name: 4f07661279fb11a06b3ddffeda672f077c0d306a
2005-08-13 16:13:04 +00:00
drh 531fe87834 Fix a comment in printf. (CVS 2588)
FossilOrigin-Name: 1054685f15095ef147d9e9a32bd56b0eaaf9fa54
2005-08-13 13:40:42 +00:00
drh 3e9aeec03f Additional cleanup and optimization of the printf function. (CVS 2587)
FossilOrigin-Name: 240bb049001b0d1419d72b6ef909236e12bd5949
2005-08-13 13:39:02 +00:00
drh 557cc60f4d Add the "!" flag to the "%g" mprintf conversion parameter to force a
decimal point.  This prevents floating point values from appearing as
integers.  Use this flag when converting floating point to text.
Ticket #1362. (CVS 2586)

FossilOrigin-Name: 4b98dace6b90abf4a6fe1cd51e6392fd213358c4
2005-08-13 12:59:14 +00:00
drh 592ac8cb6c Make the round() function work correctly on numbers with very large exponents.
Ticket #1340. (CVS 2585)

FossilOrigin-Name: 4f47c3c884e38b810450b6127ab33c7b86e6743c
2005-08-13 03:07:47 +00:00
drh 42b9d7c561 Fix a memory leak that occurs when a CREATE TABLE that contains a
DEFAULT VALUE fails due to a name conflict.  Tickets #1356 and #1357. (CVS 2584)

FossilOrigin-Name: 25cfe9390dda79bb2a7740b3d7380f517a4e8d1b
2005-08-13 00:56:27 +00:00
drh 2501eb1df6 3rd argument to sqlite3Error() should always be a format string, never
user-supplied error message text.  Ticket #1354. (CVS 2583)

FossilOrigin-Name: d6146a542aacd10d349d432fe343cc17cc3b3ab5
2005-08-12 23:20:53 +00:00
drh bb7ac00bf0 Improved error message when a #NNN parameter appears on user input.
Additional coverage testing. (CVS 2582)

FossilOrigin-Name: 3c00f5982ae61dfcd26c33ccdb81736628dbfce5
2005-08-12 22:58:53 +00:00
drh d2687b7731 Optimize LIKE and GLOB operators in the WHERE clause. Code passes all
regression tests but still needs additional tests. (CVS 2581)

FossilOrigin-Name: 3edbe8d6217fd1180883e6b9f1e5b9011a39f80d
2005-08-12 22:56:09 +00:00
drh 2db0bbc24b Improve the error message associated with SQLITE_FULL. Ticket #1353.
Also remove error messages for obsolete error codes SQLITE_INTERNAL,
SQLITE_NOTFOUND, and SQLITE_TOOBIG. (CVS 2580)

FossilOrigin-Name: fa7403c7d9948cc4a6c6ed00a614e3d6a3682e78
2005-08-11 02:10:18 +00:00
drh 4dcbdbff40 Add 2005 open source award badge and news announcement. (CVS 2579)
FossilOrigin-Name: 8e007f8c06748c5f02068c1f244bc8e3026e16fd
2005-08-11 01:25:22 +00:00
drh 1cd7f83ef5 Make sure the .import command strips newlines off the end of the last
field in each line imported.  Ticket #1348 (CVS 2578)

FossilOrigin-Name: 73fafd2148b8cd0f92747fca03e3df5778e1070f
2005-08-05 18:50:51 +00:00
drh 7018030d06 Comment out the use of memory high-water marks when not compiling with
SQLITE_MEMDEBUG. (CVS 2577)

FossilOrigin-Name: fb7a258fd35fdf81772b9d47711d30a30dfa4564
2005-08-02 21:42:16 +00:00
drh 45b1ee44a4 Minor refactoring of the new optimizer code. (CVS 2576)
FossilOrigin-Name: 868322f7b7176486dfb4b54d99cf6662b79e639d
2005-08-02 17:48:22 +00:00
drh 586e4b2f30 Update the documentation for the new transaction method on the TCL interface. (CVS 2575)
FossilOrigin-Name: 3dc823a0ac12f640a3c54fe1eb7be878d2738529
2005-08-02 17:38:19 +00:00
drh b5555e7e34 Tests and bug fixes on the new transaction method in the TCL interface. (CVS 2574)
FossilOrigin-Name: 68dd0ed5e312ecd5e98ee0fa1c21b70ff330f711
2005-08-02 17:15:14 +00:00
drh 09d0debf3b Fix a bug in the btree balancer. ticket #1346. (CVS 2573)
FossilOrigin-Name: 3af69a49289f52f321ccd365e92d22b820c3139e
2005-08-02 17:13:09 +00:00
drh 3d21423c65 Add the "transaction" coommand to the TCL interface. Untested. (CVS 2572)
FossilOrigin-Name: a5ce6c58c3bfc0e1c9953fe4ad4991ac56a4fb87
2005-08-02 12:21:08 +00:00
drh 943af3cda1 Fix problems caused by over-agressive optimization of ORDER BY in joins.
Lots more testing needed. (CVS 2571)

FossilOrigin-Name: 1a4e526d46280970b43505a5c8a4090767c63043
2005-07-29 19:43:58 +00:00
drh 2ce99ecf8b Fix authentication so that it works with AS aliases. Ticket #1338. (CVS 2570)
FossilOrigin-Name: cc7ae73ed01f0b89e31dd8de48b913bbd83887b8
2005-07-29 15:36:14 +00:00
drh 6c30be8e51 Optimizer now converts OR-connected WHERE-clause terms into an IN operator so
that they can be used with indices.  There are known problems with the
ORDER BY optimization in this and in several prior check-ins.  This
check-in is not recommended for production use. (CVS 2569)

FossilOrigin-Name: d23c8bf81e508722e92ff1b9c8bc98dc026a31f2
2005-07-29 15:10:17 +00:00
drh ed37800693 The BETWEEN operator in a WHERE clause is now able to use indices. (CVS 2568)
FossilOrigin-Name: cdf8c9584b945212e065e044df801c207aedb675
2005-07-28 23:12:08 +00:00
drh a611040eea Test cases and tuning of the new optimizer code. (CVS 2567)
FossilOrigin-Name: 4b02703dec71aa78e5f8d8cab5b950966a4c6abc
2005-07-28 20:51:19 +00:00
drh 3adc9cedb0 The new optimizer now passes all regression tests. (CVS 2566)
FossilOrigin-Name: a21212843359fb9fdbd60799ae50ad3566f4399a
2005-07-28 16:51:51 +00:00
drh 28c4cf42da More work on the new optimizer. Fewer tests fail now. (CVS 2565)
FossilOrigin-Name: ee3a08e353f563c36e904479393fcb56f96ee975
2005-07-27 20:41:43 +00:00
drh 51147baa6d A new optimizer that breaks a lot of tests. But none of them critically, I
think.  Nevertheless, there is a lot of work ahead to stabilize the code. (CVS 2564)

FossilOrigin-Name: 86ce56ccea8297b1fba2b9ee53b5f1a3f228662f
2005-07-23 22:59:55 +00:00
drh 17a18f2f36 Store the total number of rows as part of the ANALYZE statistics. (CVS 2563)
FossilOrigin-Name: 868279c78e056d27b2d1bea81127fe689b2ce478
2005-07-23 14:52:12 +00:00
drh 497e446d76 The results of ANALYZE are now loaded into internal data structures where
they can be used.  But they are not actually used yet. (CVS 2562)

FossilOrigin-Name: 1996bacfb97180965304e2a6d6784b6ecbbf8575
2005-07-23 03:18:40 +00:00
drh e6e049694d Full-coverage testing and documentation for the ANALYZE command. The
results of analysis are still not loaded or used, however. (CVS 2561)

FossilOrigin-Name: bd7583a5d63412785a9c5de54d25b509da241605
2005-07-23 02:17:03 +00:00
drh ff2d5ea408 First code for the ANALYZE command. Mostly untested. The analysis is
not loaded into the symbol tables and is not used by the optimizer. (CVS 2560)

FossilOrigin-Name: a4886b114d2ccb3841d3d219f6b97f67745b13c2
2005-07-23 00:41:48 +00:00
drh d00ada9a00 Clarify the meaning of the TEMP keyword on CREATE TABLE. (CVS 2559)
FossilOrigin-Name: 1a573619f558d1d67775d17aabb9d704f82ad1a8
2005-07-22 23:56:49 +00:00
drh ed90e26313 Correct the documentation to show that sqlite3_column_text() returns
a NULL pointer (not an empty string) when the column value is NULL.
The same goes for sqlite3_column_blob().  Ticket #1334. (CVS 2558)

FossilOrigin-Name: fd1e013a14710ed2ecabddedc0d110562cfdbfc2
2005-07-22 22:53:15 +00:00
drh e23399fc9c Begin adding code to support multiple IN constraints on the same index. (CVS 2557)
FossilOrigin-Name: 103f8ccb9013689a480766ebffbf570d4aa8bac5
2005-07-22 00:31:39 +00:00
drh 29dda4ae65 Split the OP_Integer opcode into OP_Integer and OP_Int64. This allows
comments to be added to OP_Integer.  Cleanup in the optimizer.  Allow
terms of the FROM clause to be reordered automatically. (CVS 2556)

FossilOrigin-Name: e2f822ac82d0a5a59de0b63cce65d4fd6c178ff1
2005-07-21 18:23:20 +00:00
drh 7ec764a29e Add comments to test cases. Improvements to the query plan test variable. (CVS 2555)
FossilOrigin-Name: ef3a157f469d72cbd2f713f997598ddf47f340d2
2005-07-21 03:48:20 +00:00
drh fe05af87f8 In where.c, split out the code that selects an index into a separate
subroutine. (CVS 2554)

FossilOrigin-Name: c30cbba9ead1b4d07f225b1e8a65d5d5230ea45d
2005-07-21 03:14:59 +00:00
drh 013972052e Extra memory usage instrumentation added. (CVS 2553)
FossilOrigin-Name: ac669f56c0759a7e3eaa6f0018c8fb9d614e7d69
2005-07-20 14:31:53 +00:00
drh e8b9727835 More refactoring in where.c. (CVS 2552)
FossilOrigin-Name: a35bd50af8961133adc66e40c38402e81a02bb56
2005-07-19 22:22:12 +00:00
drh 0fcef5e110 Refactoring of the query optimizer in advance of adding better optimization. (CVS 2551)
FossilOrigin-Name: 57c6bd3760163c174be4a2ece58f414e82b55938
2005-07-19 17:38:22 +00:00
drh 0aa74edd72 Allow an unlimited number of terms in the WHERE clause. The old limit was 100. (CVS 2550)
FossilOrigin-Name: ca69f36832d57775e73ac5cdbe0a32d7b759432b
2005-07-16 13:33:20 +00:00
drh 9042f395cc Fix bugs in the new query plan instrumention logic. (CVS 2549)
FossilOrigin-Name: 578490c91331a386f84652db0b3bfd74c82046e1
2005-07-15 23:24:23 +00:00
drh 84bfda41db Add test instrumentation that will be needed during the development of
forthcoming optimizer enhancements. (CVS 2548)

FossilOrigin-Name: dfd5fd77b0764853f847eeee3c1fe047d60fee7e
2005-07-15 13:05:21 +00:00
drh 4cfb644e5f Add remark in the changelog that mentions 64-bit alignment fixes in 3.2.2. (CVS 2547)
FossilOrigin-Name: ead583cfad7c6ea84c3685d89f40104f4d33bc81
2005-07-09 23:11:22 +00:00
drh c0f2a01926 Fix a comment error. No changes to code. Ticket #1320. (CVS 2546)
FossilOrigin-Name: e050af70adcdac8f9c9d8cffd1658f7fb2ebd362
2005-07-09 02:39:40 +00:00
drh e866fcb923 Use the internal sqlite3_snprintf function instead of sprintf to avoid
cross-platform incompatibilities.  Ticket #1316. (CVS 2545)

FossilOrigin-Name: 431999da7bf0079e0d514483b3bfd9f8471cba7d
2005-07-09 02:38:06 +00:00
drh df3816974c Patch to Makefile.in so that it works with OS X. Ticket #1292. (CVS 2544)
FossilOrigin-Name: 0dfabca641371690027634213632c914ad6f2b8b
2005-07-09 02:23:24 +00:00
drh a4afb65cb7 Make sure there is only one busy counter. Ticket #1315. (CVS 2543)
FossilOrigin-Name: af2a0ba4a38abf208db1ff6f018cf756de2afd5b
2005-07-09 02:16:02 +00:00
drh 57dbd7b324 Allow the IN operator to take a list of arbitrary expressions on its
right-hand side.  The expressions no longer need to be constant.  The
current implementation seems to work but needs more testing and optimization. (CVS 2542)

FossilOrigin-Name: ba56478dd8bc2135749966ff55831fd497883781
2005-07-08 18:25:26 +00:00
drh 9170dd7e1c Change the name of the OpenTemp opcode to OpenVirtual which is more
descriptive of what it does. (CVS 2541)

FossilOrigin-Name: 3bb9ce5f20d0a6bc19df31df9b8e82044c3e6004
2005-07-08 17:13:46 +00:00
drh 392e597c8a Add the EP_OptOnly flag on expressions for WHERE clause
terms that are added by the optimizer but should not be coded. (CVS 2540)

FossilOrigin-Name: f4a66ed04dfd8714746b766b4859682ea18e328f
2005-07-08 14:14:22 +00:00
drh 70031fa396 Add the SQLITE_CASE_SENSITIVE_LIKE compile-time option. (CVS 2539)
FossilOrigin-Name: b72bff81f9937378417a0af0610d8558279b67a7
2005-07-08 13:53:21 +00:00
drh a01f79df49 Replace OP_List with OP_Fifo. This is the first step toward allowing
recursive delete triggers and later foreign keys with cascading deletes. (CVS 2538)

FossilOrigin-Name: 94c120bb782fed53142317d1755e70c858930486
2005-07-08 13:07:59 +00:00
drh 9f18e8a0c4 Add infrastructure for the ANALYZE command. Does not yet actually
do anything. (CVS 2537)

FossilOrigin-Name: 05b6ac9a76fd5765c50e81588f8e71c59fe35ce4
2005-07-08 12:13:04 +00:00
drh 26d0e2a6da Fix a quoting problem in the configure script. (CVS 2536)
FossilOrigin-Name: b34647a2ebec6f915f9914034e9370459873215e
2005-07-06 13:51:27 +00:00
drh 7bac700686 Fix typos in comments. No changes to code. (CVS 2535)
FossilOrigin-Name: d3b03495a46e79a9d82525a61bad99eef9469ad1
2005-07-01 11:38:44 +00:00
drh eb55bd2fe9 Allow the DEFAULT value of a column to be obtained by calling a
function that has constant arguments, such as julianday('now'). (CVS 2534)

FossilOrigin-Name: d273766ef2442eb87971b07f9ecf5682c88298ee
2005-06-30 17:04:21 +00:00
drh 67ce73b466 Check for zero-byte allocations in sqlite3MallocRaw. (CVS 2533)
FossilOrigin-Name: 78cb8a9a17a29bb8d9ffb6298b25cc43f9cbfed9
2005-06-29 17:24:23 +00:00
drh ba336867c4 Make sqlite3Malloc always return NULL when the number of bytes to allocate
is 0. (CVS 2532)

FossilOrigin-Name: 657d74ebc1d91c99e8ac6cd68fdac3864ebd8d71
2005-06-29 15:33:00 +00:00
drh 54f080e82c Update SQL syntax documentation to describe the new CAST expressions. (CVS 2531)
FossilOrigin-Name: d5392866bfd6e06c6d072f649356050b82273a23
2005-06-26 20:00:46 +00:00
drh d1e4733d07 Tcl interface uses Tcl_Objs to implement user-defined functions, thus allowing
BLOB values to be transferred correctly.  Ticket #1304. (CVS 2530)

FossilOrigin-Name: 514aaab3f99637ebb8b6e352f4e29738102579b4
2005-06-26 17:55:33 +00:00
drh 8a15132904 Documentation fixes. Ticket #1306. (CVS 2529)
FossilOrigin-Name: 3dcdb7942ea9a9e5d708a198ba5183103d5075d9
2005-06-25 19:42:37 +00:00
drh df0bddaef3 The TCL interface binds variables as BLOB only if they have a bytearray
representation but no text representation. Ticket #1287. (CVS 2528)

FossilOrigin-Name: 8c99dca60aebee0ec5de9ed11350de864bc76584
2005-06-25 19:31:48 +00:00
drh 487e262f44 Remove the blob(), text() and numeric() functions added in (2524) and
replace them with the standard CAST operator.
Ticket #1287. (CVS 2527)

FossilOrigin-Name: 17631785f9ee8ab280c82677eb53886912e085bc
2005-06-25 18:42:14 +00:00
drh 7f057c9166 NULL values in a row of a unique index cause the row to be distinct.
Ticket #1301.  More testing and optimization needs to be done on this
before closing the ticket. (CVS 2526)

FossilOrigin-Name: 06a71b162b032fc5b56d18919a784d4ee94dde7c
2005-06-24 03:53:06 +00:00
drh 2f47149691 Make sure the String8 opcode always has a non-null P3 argument in
the foreign_key_list pragma.  Ticket #1297. (CVS 2525)

FossilOrigin-Name: bcf62dc7a1e8e7a3180138cf9b8944eb8fbd5490
2005-06-23 03:15:07 +00:00
drh 5708d2deac Add built-in functions numeric(), text(), and blob() that coerce types.
Ticket #1287. (CVS 2524)

FossilOrigin-Name: affb0fa2e8c5ff497838ba3c2994cdb1f6f50c68
2005-06-22 10:53:59 +00:00
drh 288d37f1b4 Allow parameters to be introduced by characters ':', '$' and '#'. This
is an experimental change. (CVS 2523)

FossilOrigin-Name: f3427a139c3bd4faf9134ec6290b3eb829c0a19f
2005-06-22 08:48:06 +00:00
drh edef8fcd73 Fix a bug in an assert found while investigating ticket #1287 but otherwise
unrelated to that problem. (CVS 2522)

FossilOrigin-Name: 60f752ed1817e6710c13c2ce393c3bf51dae76ad
2005-06-22 02:36:37 +00:00
drh 13aebc66f2 Change the documentation to explain that a database handle can only be
used in the same thread in which it was created.  Ticket #1272. (CVS 2521)

FossilOrigin-Name: 59c95731f70ed9b9e135584f62d0a2b0f1a3bb96
2005-06-16 19:48:39 +00:00
drh cf5f58fa3e Fix the THREADSAFE macro in Makefile.in. We really need to rework the
whole autoconf build system.... (CVS 2520)

FossilOrigin-Name: 98a4de76e0593ef1d1d3e8b785d420cd554a08e8
2005-06-16 18:47:38 +00:00
drh bf8f1b3460 Change to Makefile.in to fix a problem with the Borland linker.
Ticket #1291. (CVS 2519)

FossilOrigin-Name: bc25397735c1485e3533507bed507250ea07534a
2005-06-16 16:51:15 +00:00
drh 6eb8577cae Fix to the "make doc" makefile target. Ticket #1289. (CVS 2518)
FossilOrigin-Name: 4713b1e1040f2e0645fa593638e392df44b5bfc1
2005-06-15 18:07:39 +00:00
drh 2b4b5962c4 Changes to the unix OS layer aimed at finding and fixing tickets
#1272 and #1285. (CVS 2517)

FossilOrigin-Name: 006dda3119f025d703da4e0215c378206e20cfd0
2005-06-15 17:47:55 +00:00
drh 8d904f058b Fix an NDEBUG versus SQLITE_DEBUG confusion issue. (CVS 2516)
FossilOrigin-Name: 833c016023e9e17c226fdd722dcb10bc51ab6f9e
2005-06-14 17:47:58 +00:00
drh 556b2a2322 Provide the SQLITE_FILE_HEADER command-line option for changing the text
that appears at the beginning of databases. (CVS 2515)

FossilOrigin-Name: 3d7ee5b92d7e30f90cb7a8b3efd649b36480b61b
2005-06-14 16:04:05 +00:00
drh 3f73708ce4 Fix a bug in the default busy handler for systems that lack usleep().
Ticket #1284. (CVS 2514)

FossilOrigin-Name: a42cb81d1173532537aed4e71091d4cd3f3a88a0
2005-06-14 02:24:31 +00:00
drh 78776ecdb1 Do not record existance the sqlite_sequence table until it is actually
created.  Ticket #1283. (CVS 2513)

FossilOrigin-Name: 95256d953c179372dcc5ead6c407672c8161a8c1
2005-06-14 02:12:46 +00:00
drh 7c3d49c275 Fix documentation typo. Ticket #1282. (CVS 2512)
FossilOrigin-Name: ce6b62fa46bc67085801c48d6a28944d4d373ba9
2005-06-13 00:47:59 +00:00
drh 4fd81a51fa Version 3.2.2 (CVS 2511)
FossilOrigin-Name: 0e190e9d9137e9d29fc53ce6f1136047d578bb55
2005-06-12 23:17:23 +00:00
drh 3d334bcb1f Update the EXPORT definitions list to include the latest additions to the API. (CVS 2510)
FossilOrigin-Name: 44e54b132e03d86e52055dc0a2815b653ec179e8
2005-06-12 23:16:20 +00:00
drh e44d483818 Updates in preparation for the release of version 3.2.2. (CVS 2509)
FossilOrigin-Name: e9602c4a9d2b62a9b3a86b94f47971c56ee6733e
2005-06-12 22:23:40 +00:00
drh 65efb65e46 Fix documentation typos. (CVS 2508)
FossilOrigin-Name: 41049062cdefdc111398589daff464a9a13600aa
2005-06-12 22:12:39 +00:00
drh 51942bc3c3 Documentation updates (ticket #1279). Add the sqlite3_db_handle API.
(ticket #1275). (CVS 2507)

FossilOrigin-Name: 21d44fa5e7163dc658f7147885518d90218347f7
2005-06-12 22:01:42 +00:00
drh f0863fe568 Update older opcode names to be more meaningful in light of the latest
code design. (CVS 2506)

FossilOrigin-Name: 36f2da1f8d8d434f861ecad55c9d86549751c954
2005-06-12 21:35:51 +00:00
drh 4a9f241c37 Elminiate a VM opcode that was no longer needed. (CVS 2505)
FossilOrigin-Name: 97b348a5ad2f090ba7a75467b97c6dfb575df09c
2005-06-12 12:01:19 +00:00
drh 0ccebe7e2d Changes to support linking without a parser and without a disk I/O interface. (CVS 2504)
FossilOrigin-Name: 62a7353d4af4886b1561832e8b36e8e788b38834
2005-06-07 22:22:50 +00:00
drh 80f93bf41f In the documentation, amplify the fact that encodings cannot be changed
on a database that already exists.  Ticket #1277. (CVS 2503)

FossilOrigin-Name: 4704f3a19af73261ec03c0192c74a0416aeba794
2005-06-07 20:07:24 +00:00
danielk1977 db0441b155 Remove SSE vacuum hook. (CVS 2502)
FossilOrigin-Name: 59960a59151ae6c711dee404e60e12d4edaa3dda
2005-06-07 09:21:07 +00:00
danielk1977 cbe21be330 Add "#ifndef OMIT_DISKIO" condition around sqlite3_opentemp_count variable
in test interface code. (CVS 2501)

FossilOrigin-Name: f2ce662e81cea4983f335606ed18a74b97d35609
2005-06-07 07:58:48 +00:00
drh af6df11f8a Add tests to make sure statement journals are only opened when necessary. (CVS 2500)
FossilOrigin-Name: 914d6e6549446a6ddf25e5da57d2fe9446750625
2005-06-07 02:12:30 +00:00
drh 3844990cfc Do not open a statement journal unless absolutely necessary. (CVS 2499)
FossilOrigin-Name: 989573a53b58c1e959ad276119298ba2ea7448e6
2005-06-07 01:43:41 +00:00
drh ed8a3bb108 Reference count Table structures so that they are not deallocated too soon.
Ticket #1210. (CVS 2498)

FossilOrigin-Name: e73d25c7419d580c47925494621df26d2fb9f27e
2005-06-06 21:19:56 +00:00
drh 473d179d8a Return SQLITE_MISUSE when passing a NULL pointer into sqlite3_bind routines.
Ticket #1219. (CVS 2497)

FossilOrigin-Name: 12c32f139bae3cb7ca520451bfc15f9f7d94833d
2005-06-06 17:54:55 +00:00
drh ba0232a0df Any non-zero value is considered TRUE in a WHERE clause. Ticket #1211. (CVS 2496)
FossilOrigin-Name: 0f7af623791d8d2ed35c3978ab12316912d9b6f8
2005-06-06 17:27:19 +00:00
drh 873fac0cae Avoid ambiguous column name errors when the column name is in the USING clause
of a join.  Ticket #743. (CVS 2495)

FossilOrigin-Name: 6a51bdeeff8312fa54fa2b1200f823428f35d605
2005-06-06 17:11:46 +00:00
drh 355ef36114 Naming the join columns in the result set of a natural join does not result
in an "ambiguous column name" error.  Ticket #1217. (CVS 2494)

FossilOrigin-Name: 265fb6079c0a4b7a93f063939436db494ff1d56c
2005-06-06 16:59:24 +00:00
drh d70dc52d79 Honor the full_column_names pragma on * results. Ticket #1263. (CVS 2493)
FossilOrigin-Name: 0d57f851ae4f483985710db149c8f541e45cdb86
2005-06-06 16:34:33 +00:00
drh 7c3d64f151 Do not allow parameters in VIEW definitions. Ticket #1270. (CVS 2492)
FossilOrigin-Name: 0d46289f02aad526f462a3ceceb1bca1b9f6a543
2005-06-06 15:32:08 +00:00
drh 41f5852eea Handle failures of getcwd() without segfaulting. Ticket #1274. (CVS 2490)
FossilOrigin-Name: c1691004d6d81b683a4ca5b1723c0de8b9b4e376
2005-06-06 15:06:39 +00:00
drh defc997230 Fix a bug in the malloc2 tests introduced by checkin (2473). (CVS 2489)
FossilOrigin-Name: fafaa18eea1e7142e1094b5f6d544d20c9df7c0f
2005-06-06 14:45:42 +00:00
danielk1977 a38b4134e7 Omit a couple of test cases if the library is compiled without subqueries. (CVS 2488)
FossilOrigin-Name: 6bc372978364a1a4bfa14732a818a6bba613b1e3
2005-05-29 14:23:12 +00:00
danielk1977 44ee5bf795 Minor changes to help build and test SSE. (CVS 2487)
FossilOrigin-Name: 3ac4a212bd70abb94d24830c73f7121df51125c7
2005-05-27 09:41:12 +00:00
drh 3e1d8e6356 Add an experimental sqlite3_get_autocommit() API used to test whether or not
changes are committed automatically. (CVS 2486)

FossilOrigin-Name: 4a7f1275857602e3841ccb2d43a5c4d3d3e87bff
2005-05-26 16:23:34 +00:00
danielk1977 105afed6a0 Add a -cleanup option to Tcl test proc do_ioerr_test. (CVS 2485)
FossilOrigin-Name: b0a898c05a2285c87d7da4d47dd697c58a0d4d58
2005-05-26 15:20:53 +00:00
danielk1977 5c2d9155de If SSE is enabled, set the P1 field of OP_AggInit instructions to the
number of arguments that will be passed to the aggregate function. (CVS 2484)

FossilOrigin-Name: 7f67b9f0f398583651d226fabf2fafd2635d772a
2005-05-26 14:41:47 +00:00
danielk1977 1f723bd904 Fix minor problems with the SSE hooks. (CVS 2483)
FossilOrigin-Name: 3516ca29da5f28adc1fd4da42ca5551d154b6320
2005-05-26 12:37:29 +00:00
danielk1977 4dade03788 Rearrange code so that SSE can invoke the collation factory. (CVS 2482)
FossilOrigin-Name: ea061d2ed3b25908fcfcb88e35ba612e5832a217
2005-05-25 10:45:10 +00:00
danielk1977 fa256a3306 Split main.c into two files to make building without the parser easier. (CVS 2481)
FossilOrigin-Name: d50915fafbde6859a5c2c3fc5cc9b99553b54e21
2005-05-25 04:11:56 +00:00
drh 97903fef77 Remove the config.h file from the build. Ticket #1224. (CVS 2480)
FossilOrigin-Name: 3e64f1ab417f371e9875915303b898c5b45f0807
2005-05-24 20:19:57 +00:00
danielk1977 fd9a0a45a7 Move a few things around to make building without the parser easier. (CVS 2479)
FossilOrigin-Name: 5fadb464eb77b4b998d8555f83401769960ea904
2005-05-24 12:01:00 +00:00
drh b71090fdfb The REGEXP operator is recognized. It tries to invoke a function named
regexp() which does not exist in the native build.  But users who want to
can add an appropriate regexp() function using sqlite3_create_function(). (CVS 2478)

FossilOrigin-Name: 42a626ace126f730f33ecb6c41ac5679d6766a31
2005-05-23 17:26:51 +00:00
drh 15ccce1c0d Make sure that the use of a double-quoted string literal does not trick
the optimizer into using a correlated subquery when a static
subquery would suffice. (CVS 2477)

FossilOrigin-Name: ef4059e3afa1a61a9e59df00cdfedc57d8df9fec
2005-05-23 15:06:39 +00:00
danielk1977 0bb8f36d05 Retain the error string if an error is generated by SSE during a VACUUM. (CVS 2476)
FossilOrigin-Name: f7b76d02e003faf0310b87949d3cb0f38062853f
2005-05-23 13:00:57 +00:00
danielk1977 7e900abf0a Add pFetch variable (used by SSE) to sqlite3 structure. (CVS 2475)
FossilOrigin-Name: 2a8ac869671b627d4d01655bbce7a781bc74af44
2005-05-23 04:51:01 +00:00
drh eb43e5c7b7 The cache_size pragma should not reset the synchronous pragma. Ticket #1260. (CVS 2474)
FossilOrigin-Name: 2db2b32f269062b006ae5c4a302d116cdab8f9ec
2005-05-22 20:30:39 +00:00
drh 132d8d6ab9 Never user a pointer to standard library routines malloc() and free().
This rule is to
work around limitations of MSVC and the _fastcall calling convention.
Ticket #1256. (CVS 2473)

FossilOrigin-Name: a39c446726099e4915a1ad72c019d3c2cfe065bb
2005-05-22 20:12:37 +00:00
drh edc1cc5b3e Fix a memory leak. Ticket #1259. (CVS 2472)
FossilOrigin-Name: 254ac2213e695ead065ba3807d5d285046212fe1
2005-05-22 19:21:51 +00:00
danielk1977 fd9e1f3179 Add hook to register SSE user-functions. (CVS 2471)
FossilOrigin-Name: 20bd303e8c6f7e69ba82ce1dc3041ea4e02d55cf
2005-05-22 10:44:34 +00:00
danielk1977 3a3f38e090 Allow schema objects beginning with sqlite_ to be created if the
SQLITE_WriteSchema flag is set. (CVS 2470)

FossilOrigin-Name: afc8ce42b6c321463f6451727d0f85c490c8e9ae
2005-05-22 06:49:56 +00:00
drh 3c68582188 Speed improvements as described by tickets #1257 and #1258. These changes
help some but are nowhere near the 23% claimed in the tickets. (CVS 2469)

FossilOrigin-Name: 3fa177c54a8589dcfa0bfad0ca124cb73b363f18
2005-05-21 18:32:18 +00:00
drh fcd35c7b8c More structure rearrangements for additional size reductions. Ticket #1253. (CVS 2468)
FossilOrigin-Name: 6b6e525b294a5bbf8a5e56a2f60aa096865aedbd
2005-05-21 02:48:08 +00:00
drh 6d156e464d Reorder structure fields to reduce code footprint. Ticket #1253. Need
to do more of this. (CVS 2467)

FossilOrigin-Name: 27025613bc2970b0c23e08fbe5251103794ab6cb
2005-05-20 20:11:20 +00:00
drh 1c7880e501 Do not allow the pagesize of :memory: databases to be changed. Silently
ignore PRAGMA page_size=N requests for :memory: databases.
Ticket #1144 and #1252. (CVS 2466)

FossilOrigin-Name: f29a1d882623d8ff14f35a302aef63a16388bcb3
2005-05-20 20:01:55 +00:00
drh e590fbde7c Comment changes in vdbeapi.c (CVS 2465)
FossilOrigin-Name: ab7805fb2fb29abc1311e23a93ba03883db7b30e
2005-05-20 19:36:01 +00:00
danielk1977 562e8d3c3b Fix memory leaks in Tcl user function interface. (CVS 2464)
FossilOrigin-Name: f5d9a8061a6d650f207669b121243abb8dd28be2
2005-05-20 09:40:55 +00:00
danielk1977 1f55c05660 Always use a more specific type (P3_FUNCDEF) instead of P3_POINTER as the
P3 type of a vdbe instruction. (CVS 2463)

FossilOrigin-Name: 79a41674be2c0a1990598428d8b1e9d09d3ea389
2005-05-19 08:42:59 +00:00
drh dd9f8b45ef Fix an array index that is out of bounds. Ticket #1251. (CVS 2462)
FossilOrigin-Name: bcf87e4d1681d6c2856e716aae0135c2b14989d8
2005-05-19 01:26:14 +00:00
drh 8e855770de Provide a compile-time parameter to set the default file creation permissions
under Unix.  Ticket #1247. (CVS 2461)

FossilOrigin-Name: bfa55bec3233eed899606c309773f441857605ae
2005-05-17 11:25:31 +00:00
drh c43e8be80c Fix an uninitialized variable. Ticket #1244. (CVS 2460)
FossilOrigin-Name: 582cb77d72031f78b560f67222a0e6ce5e3ca3f2
2005-05-16 22:37:54 +00:00
danielk1977 5205b40393 Modify documentation to explain default value of "pragma synchronous".
No code changes. (CVS 2459)

FossilOrigin-Name: 453014421e9a739b47d4c28b0342454e4c686199
2005-05-16 02:13:17 +00:00
drh 29f214bdaa Change to the lemon parser suggested by Geert Janssen. Appears to have no
impact on SQLite. (CVS 2458)

FossilOrigin-Name: 6fda60083f258a4943c859d768ea7142de831594
2005-05-11 14:28:14 +00:00
drh 6601e9e898 Fix a typo in the CREATE TABLE documentation. (CVS 2457)
FossilOrigin-Name: 748771a8ad7f175e49f253d0c1ace3fc55814418
2005-05-10 16:11:41 +00:00
drh 68cb6192c1 Timing fix in the default busy handler. (CVS 2456)
FossilOrigin-Name: 76090ed84c73a9b9c7099e2986390ca8967128f4
2005-05-06 22:05:56 +00:00
drh 8d97f1f141 Patch to fix an alignment problem on sparc. Ticket #1234. (CVS 2455)
FossilOrigin-Name: 240cce10d4b9d595a267e392ce322472b10f286d
2005-05-05 18:14:13 +00:00
drh 0405a34d11 Fix a datatype in trigger6.test that changed due to the previous check-in. (CVS 2454)
FossilOrigin-Name: c2af7d2c947bcec507087cc3a1e5b21e6322e4cd
2005-05-05 11:04:50 +00:00
drh c7f269d551 In the TCL interface, user-defined functions preserve the datatype returned
by the Tcl procedure. (CVS 2453)

FossilOrigin-Name: 99dcba1fb1fdaa2b8bc85046b00c14f6af596e8f
2005-05-05 10:30:29 +00:00
drh c96d8530ca Make sure all data structures have 8-byte alignment - necessary for the
sparc architecture and helpful on other 64-bit platforms.  Ticket #1232.
Also update some comments in build.c. (CVS 2452)

FossilOrigin-Name: d9418851cebc1605d8d62aad7987c0d61a905e81
2005-05-03 12:30:33 +00:00
drh 07d183da90 Remove the psAligned value from the BTree structure - the pageSize is now
always aligned to an 8-byte boundary.  Add comments on a confusing bit
of code.  Ticket #1231. (CVS 2451)

FossilOrigin-Name: 535523e1be692adc940d256a7b3d23c62a4cc947
2005-05-01 22:52:42 +00:00
drh 7e62779a58 Prevent a segfault described by ticket #1229. (CVS 2450)
FossilOrigin-Name: 0667eae9a97059125a77bd90452d19dc17c30a12
2005-04-29 02:10:00 +00:00
drh 89dec819d2 Add hooks for the SSE extension. (CVS 2449)
FossilOrigin-Name: 90f4cf2ad57309dbd20954fc7fd60859bc44bcf4
2005-04-28 19:03:37 +00:00
drh 2e66f0b972 Enhancements to allow for extensions. (CVS 2448)
FossilOrigin-Name: 6863703abcb2bf31d65792d4de9ae20aba2eadb5
2005-04-28 17:18:48 +00:00
drh ee570fa498 Fix an array index bug in the default busy callback handler.
Ticket #1198. (CVS 2447)

FossilOrigin-Name: 3cc14b7606681d04eb56003a0996322e3b3bdc73
2005-04-28 12:06:05 +00:00
drh f8db1bc03b Remove some vestigal code. Add the experimental sqlite3_transfer_bindings()
API. (CVS 2446)

FossilOrigin-Name: 88b39436f00d645cdb6333a7413c698c42227d3f
2005-04-22 02:38:37 +00:00
drh b47d45ccbf Correctly store large integers. Ticket #1212. (CVS 2445)
FossilOrigin-Name: 00e20690bb8cc6522c9c48f36f0c3336ae007827
2005-04-15 12:04:34 +00:00
kwel c7e22ee254 Added tests to exercise delete, insert, and update triggers on views (tkt #1169) (CVS 2444)
FossilOrigin-Name: 6cd19ddcba5fbea1be04b44699c911294618e948
2005-04-08 19:48:27 +00:00
kwel d536273abf Fixed stack growth in update trigger on views (tkt #1169) (CVS 2443)
FossilOrigin-Name: 99fcd5561b539010b7e76cad7815bb2350541f00
2005-04-08 16:08:36 +00:00
kwel ae87f0ed25 Fixed stack growth in delete trigger on views (tkt #1169) (CVS 2442)
FossilOrigin-Name: 1a757ba13292577d01bd7b66811bcfd6748b9f7e
2005-04-08 16:07:47 +00:00
danielk1977 55c45f2e1e Apply Tcl 'nullvalue' patch from Stefan Finzel. (CVS 2441)
FossilOrigin-Name: 9906ae37b9be684b615a1190cf8798513baa799a
2005-04-03 23:54:43 +00:00
drh 2b70fb90e1 Documentation updates. (CVS 2440)
FossilOrigin-Name: 7e6f688d468099a6e62e405086c9172459d43e3f
2005-04-01 16:29:12 +00:00
drh 495c09a49a Make the ORDER BY clause return equal elements in the same order they were
seen (a stable sort).  It was returning them in exactly the reverse order. (CVS 2439)

FossilOrigin-Name: e8391491a68018406e30c2a699a4cab9e0de092c
2005-04-01 10:47:40 +00:00
drh 9a7e60865d Add a "const" declaration to a constant. Fix a typo in a comment. (CVS 2438)
FossilOrigin-Name: 67aaa269068ea6b6f784979c09b3deb091928563
2005-03-31 22:26:19 +00:00
drh 4fb90f2bff Update comments and documentation to give the true maximum page size as 32K,
not 64K as was previously (and erroneously) reported.  Ticket #1194. (CVS 2437)

FossilOrigin-Name: 58dd436b6572d38ea67960b8d08a0ca4359602f0
2005-03-31 21:02:45 +00:00
drh f4f8fd51e4 Make sure integer primary keys larger than 2^31 are handled
properly.  Ticket #1188. (CVS 2436)

FossilOrigin-Name: 1d04c2ab299430959b8a193d4679cbc4c0be31a4
2005-03-31 18:40:04 +00:00
drh 3ced14a616 Fix a memory leak in the TCL bindings. (CVS 2435)
FossilOrigin-Name: c31ea6332f53d361be864554b83662d3fc0d52f7
2005-03-31 18:26:20 +00:00
danielk1977 3eb8db90ba Fix a problem with threads and the global database list in main.c. (CVS 2434)
FossilOrigin-Name: 4aa05d2251b0cf6323ea695330de9ccf7e071bed
2005-03-29 23:34:58 +00:00
drh 60625c4c84 Version 3.2.1 (CVS 2433)
FossilOrigin-Name: 844f01af726f5e478a4ef32f39be9f20360a0d96
2005-03-29 13:37:46 +00:00
drh d2d62b31ce Change the date of the 3.2.1 release. (CVS 2432)
FossilOrigin-Name: afa42e2fa4487e4671ee481df09659a447f9c2a8
2005-03-29 13:19:01 +00:00
drh faf60c7a0d Fix minor display bugs in sqlite3_analyzer. (CVS 2431)
FossilOrigin-Name: d89aaba5b0fe6b2787531cadd7806ab5a3fdeb98
2005-03-29 13:18:16 +00:00
drh 19642e5d65 Fix a C++-ism in the code. (CVS 2430)
FossilOrigin-Name: 312587acf9e94e1d12390a9a0206c9464815e8d7
2005-03-29 13:17:45 +00:00
danielk1977 7a5147c5c9 Change 'stack' to the more descriptive 'no-push' in vdbe.c. (CVS 2429)
FossilOrigin-Name: 7e54d3c7289c091d449844d21b923e553f1d1f5f
2005-03-29 13:07:00 +00:00
danielk1977 bc04f8529d Reduce the space allocated for the runtime virtual machine stack. (CVS 2428)
FossilOrigin-Name: 7d6818da33a87076d1faf35ffc15a3aada0533b3
2005-03-29 08:26:13 +00:00
danielk1977 53c0f7480b Add the SQLITE_OMIT_TEMPDB compile time macro. (CVS 2427)
FossilOrigin-Name: c41d55443c2dd532147962b87f542fb7d37075fd
2005-03-29 03:10:59 +00:00
danielk1977 50f059b871 Fix segfault due to exception handler being run with uninitialised variable. (CVS 2426)
FossilOrigin-Name: 78df3d040443414ae5b440eeabc0c8c205ab311d
2005-03-29 02:54:03 +00:00
drh 88b01a13c6 Fix another memory leak in the pager. (CVS 2425)
FossilOrigin-Name: 4ca11ca015d798655170593c1b76d312185d6ed2
2005-03-28 18:04:27 +00:00
drh 6cdc5d0269 Increment version number and update documentation in preparation for
version 3.2.1. (CVS 2424)

FossilOrigin-Name: b0409b93108096a81245170887d60d076d639c60
2005-03-28 16:56:09 +00:00
drh 92fd9d285f Changes to alter3.test to allow it to work with a codec. (CVS 2423)
FossilOrigin-Name: 9e856bab2bbb77004b049827b4a275aa6c48096b
2005-03-28 16:50:22 +00:00
danielk1977 634f298c89 Modifications to reduce memory consumption. (CVS 2422)
FossilOrigin-Name: 0fd5ce4eefdc429ce0493f15d0dba9e8a3a0b0e2
2005-03-28 08:44:07 +00:00
drh dd5b2fa5f2 Fix some memory leaks that occur after a malloc failure. (CVS 2421)
FossilOrigin-Name: bcb5d72ef146b1019c72220701d385c7b0b5d0bd
2005-03-28 03:39:55 +00:00
danielk1977 f0b5792bdc Use SQL function substr() correctly from ALTER TABLE code. Ticket #1182. (CVS 2420)
FossilOrigin-Name: ccb9f4022b3ccb1cc2ab001628fd38becfbf8efe
2005-03-28 00:07:16 +00:00
danielk1977 b3a2cced6b Correctly allocate new columns array in ALTER TABLE .. ADD COLUMN. Ticket #1183. (CVS 2419)
FossilOrigin-Name: 3c86e63389b286a49106d8d7009cc63e3914d40f
2005-03-27 01:56:30 +00:00
drh d960d0641e Fix a typo in vdbeInt.h. This was potentially a serious mistake, but we got
lucky and it is benign. (CVS 2418)

FossilOrigin-Name: f0d64dc8aa65b25af551e6e5f07746bd77c8112a
2005-03-23 01:48:47 +00:00
drh 1d5de64d20 Fix typo in the formatchng.html document. (CVS 2417)
FossilOrigin-Name: 35ace66f3ebefd4cd1455c923199511ab3b72bb6
2005-03-23 01:05:14 +00:00
drh 3ee003d8f7 Version 3.2.0 (CVS 2415)
FossilOrigin-Name: debf40e8ffa35406685ec027ced1f147ef0487df
2005-03-21 19:51:30 +00:00
drh 3d07343c84 Documentation changes prior to the release of version 3.2.0. (CVS 2416)
FossilOrigin-Name: cc5a2c8e5d2ddb87f3bce6efaf3e62d7fa00d9ca
2005-03-21 19:48:00 +00:00
danielk1977 6b456a2b46 Add function to recover from a malloc() failure. (CVS 2414)
FossilOrigin-Name: 1f9d10d7965c95d1e35f64cf4c3f128adabd41f2
2005-03-21 04:04:02 +00:00
danielk1977 e94ddc9e43 Assorted fixes to the handling of various malloc() failures. (CVS 2413)
FossilOrigin-Name: e7844a01c248e8d9204ea9214bec84c81dc07f32
2005-03-21 03:53:38 +00:00
drh 7a8245b525 Update docs to say that the default_synchronous pragma has been removed.
Ticket #1049. (CVS 2412)

FossilOrigin-Name: 21012bba176035ff69f860936794a6c2a8eac9df
2005-03-21 01:31:36 +00:00
drh 6062d8f5f2 fix typo in CREATE VIEW documentation. Ticket #1135. (CVS 2411)
FossilOrigin-Name: 38897a509a98188a06c49c01a71ddf8835c7b607
2005-03-21 01:24:02 +00:00
drh 38fba69135 Fix an infinite loop in the code generator for INSERT. Ticket #1140. (CVS 2410)
FossilOrigin-Name: 876d09d9145775956913e975c29e81d7553839ac
2005-03-21 01:20:58 +00:00
drh 6841f162c6 README file updated to suggest running "make install". Ticket #1168. (CVS 2409)
FossilOrigin-Name: b48784cf65420da5ccdf779504e3c0b5c0f2471d
2005-03-21 00:47:18 +00:00
drh 4cb29b4cfc Allow the character "T" between date and time in ISO-8601 date/time formats.
Ticket #1170. (CVS 2408)

FossilOrigin-Name: 2bf88daa57b01216c7bbe67972f479ee12be1193
2005-03-21 00:43:44 +00:00
drh 09bf0e8d5e Improved support for cygwin. Ticket #1165. (CVS 2407)
FossilOrigin-Name: fcb5cee440ab49e39b62b177cbb04ab0b061a477
2005-03-21 00:36:08 +00:00
drh 47fb54da2e Fix a formatting error in the syntax documentation. Ticket #1145. (CVS 2406)
FossilOrigin-Name: 59892be6a4c344cb6654f76e4b3b9db96d52f132
2005-03-21 00:28:24 +00:00
drh ab34b8f65a Fix for ticket #1167 (CVS 2405)
FossilOrigin-Name: d9aa0aa9ae2ca0dec976ba2ae4cd7047132be45b
2005-03-20 23:18:57 +00:00
drh 8aa60cb746 Do not attempt to read the journal file on windows because manditory locking
on windows will not allow it.  Ticket #1166. (CVS 2404)

FossilOrigin-Name: 1865e0d81c827cc879dde96c6a9f42e740b6a560
2005-03-20 22:54:56 +00:00
drh 9636284e32 More changes for ticket #1171 after additional analysis. (CVS 2403)
FossilOrigin-Name: 0471d6b86fd67c22da832beb280b31305c5aa812
2005-03-20 22:47:56 +00:00
drh 41712ef171 Tentative fix for ticket #1171. More research and testing needed. (CVS 2402)
FossilOrigin-Name: f0a39cee78472b93cce5304fc255285ddea7d2bf
2005-03-20 19:10:12 +00:00
drh c2cb4c10c8 More documentation updates. (CVS 2401)
FossilOrigin-Name: f065b6102db838d48f1a1a9ed68b2a09cd440cf8
2005-03-19 15:10:45 +00:00
drh 47b4b29b12 Preparations for the release of version 3.2.0. (CVS 2400)
FossilOrigin-Name: 90a00e90663749e5d1f8e28709dfbe981f8afc8b
2005-03-19 14:45:48 +00:00
drh 255d448726 Fix typos in documentation. (CVS 2399)
FossilOrigin-Name: aee888ca58a7d059ff3ccb26bf0924550d54ab1c
2005-03-19 03:41:57 +00:00
drh ddba9e54e7 Updates to comments and documentation. No changes to code. (CVS 2398)
FossilOrigin-Name: e53c77268cd16802bd8c6fc4c6cd5280dc12f9c1
2005-03-19 01:41:21 +00:00
drh e29b915e9b Remove unused code from util.c. Enhance the trace output in os_unix.c. (CVS 2397)
FossilOrigin-Name: f2f31919fdd181c79b86f849d46c60f1ed7a0db1
2005-03-18 14:03:15 +00:00
drh 072192dffa Fixed a typo in alter3.test. (CVS 2396)
FossilOrigin-Name: 698be25d3e8f0eb2b5a4c6c7d20343b3c8a06134
2005-03-17 12:33:14 +00:00
danielk1977 37b69a0130 Don't run the tests in alter3.test if SQLITE_OMIT_ALTERTABLE is defined. (CVS 2395)
FossilOrigin-Name: 800fb3bf06f73af53af57f5b172c85406af374ad
2005-03-17 07:00:55 +00:00
danielk1977 c4a41b12f4 Update to keyword list for ALTER TABLE ... ADD COLUMN command. (CVS 2394)
FossilOrigin-Name: 173e26961faec434cd4e4abc1dcb238ab9a942b8
2005-03-17 05:06:28 +00:00
danielk1977 19a8e7e882 Add the ALTER TABLE ... ADD COLUMN command. (CVS 2393)
FossilOrigin-Name: 94185dd4f7e2e941c74a521488d1212a75927218
2005-03-17 05:03:38 +00:00
drh 44dcbda393 Version 3.1.6 (CVS 2392)
FossilOrigin-Name: 6a3f4e4be6f294f756ed882f220f579252735f3f
2005-03-17 04:01:24 +00:00
drh 4ff55083e5 Strengthen an assert() in vdbe.c. (CVS 2391)
FossilOrigin-Name: 3f45cf3516be9919fe2c0673d6f445fa83d42126
2005-03-17 03:52:47 +00:00
drh fb189328de Preparing for the release of 3.1.6. (CVS 2390)
FossilOrigin-Name: 45cbf27e8079754941225e87867711504bf3d60c
2005-03-17 03:33:16 +00:00
drh cb9882a753 Fix a bug in the calculation of the table record header size.
Ticket #1163. (CVS 2389)

FossilOrigin-Name: bf82a04ff7c24a38d45721b3fae69d88d6e83149
2005-03-17 03:15:40 +00:00
danielk1977 d5d565235b Fix some memory leaks that can occur if a memory allocation fails. (CVS 2388)
FossilOrigin-Name: 9a358fc33d726d0b5782bf65b50f61f2bd096d56
2005-03-16 12:15:20 +00:00
drh 165ffe9708 When creating a new database, delete any preexisting journal that might be
left over from a prior database with the same name.  Ticket #1152. (CVS 2387)

FossilOrigin-Name: 856e2ec9688affbfe496cf184f460b18408e3dc0
2005-03-15 17:09:30 +00:00
drh ae8b3615ee Allow the database name in a DETACH statement to be quoted.
Ticket #1151. (CVS 2386)

FossilOrigin-Name: 24e887735256499e58dabe90463524d9e6eb08ce
2005-03-15 02:04:12 +00:00
drh b8ef32c3e8 Be more aggressive about using the busy handler. Ticket #1159. (CVS 2385)
FossilOrigin-Name: 644c6398e52481e5dda87671e1c196b26b1e4990
2005-03-14 02:01:49 +00:00
drh 556927f944 Fix typo in documentation. (CVS 2384)
FossilOrigin-Name: 78012246fc1c1fe844d192cfff69a736e388ce7a
2005-03-12 18:03:58 +00:00
drh 9179fd93ff Documentation updates. Added the "distinctive features" page. (CVS 2383)
FossilOrigin-Name: 33a0191638a4d6b33422f62487bfb9a0089d3cff
2005-03-12 15:55:10 +00:00
drh f580380463 Version 3.1.5 (CVS 2382)
FossilOrigin-Name: b1792ae51666f27bc47cf986937a3caacdd3a9f7
2005-03-11 18:06:53 +00:00
drh 9c2ba47eac Disable GNU readline in the build of the command-line shell for linux since
some systems (ex: SuSE) do not support it. (CVS 2381)

FossilOrigin-Name: baddb06450e6948334faef4afa7cbfba40a2aa0f
2005-03-11 18:06:40 +00:00
drh 70e15d6cbb Updates to the homepage prior to 3.1.5. (CVS 2380)
FossilOrigin-Name: c78611f620587d392b978d4218e3b464ccc74730
2005-03-11 17:55:32 +00:00
drh f30cc9496a Fix bugs discovered in 3.1.4. F_FULLFSYNC not F_FULLSYNC. And a bug in
"make doc".  Also typos in the documentation. (CVS 2379)

FossilOrigin-Name: 3c57a4571fc8463ce9de1cbe5be45538bf2f0de9
2005-03-11 17:52:34 +00:00
drh 05501af78b Version 3.1.4 (CVS 2378)
FossilOrigin-Name: 3d070a9b4d680d952464b53b51e82b95982bbfca
2005-03-11 04:53:17 +00:00
drh 748f763f7a Fixes so that the FULLSYNC changes will build on windows. They do not have
any effect, but neither do they cause errors. (CVS 2377)

FossilOrigin-Name: ace3e30de1cde2e8990d8429b730ca5b68acd714
2005-03-11 04:41:39 +00:00
drh 4835fc5c9b Increase the version number to 3.1.4. (CVS 2376)
FossilOrigin-Name: e438b65cf9606f5564b28857ba9625665d57f1f6
2005-03-11 04:40:23 +00:00
drh a8f9361f1d Documentation updates for version 3.1.4. (CVS 2375)
FossilOrigin-Name: a7261f1590367932db23f5c8d6d785887df1e8dd
2005-03-11 04:39:58 +00:00
drh 6575a222d5 Another case of returning SQLITE_CORRUPT when a corrupt database file
is detected. (CVS 2374)

FossilOrigin-Name: 8710192797b5b22f29b2af90198d03664665bd83
2005-03-10 17:06:34 +00:00
drh 75ea0289cc Fix a problem with crashtest caused by the F_FULLSYNC change. (CVS 2373)
FossilOrigin-Name: f11c6e745200525056ae7cf97b4bdf1c7f1db588
2005-03-10 14:32:24 +00:00
drh b851b2c938 Disable F_FULLSYNC if the sychronous pragma is not set to FULL. (CVS 2372)
FossilOrigin-Name: 58b8733b96165126ee8514f2ce0f88d249792847
2005-03-10 14:11:12 +00:00
drh cca76c2f7e Disable the use of ./crashtest in builds that include a codec. (CVS 2371)
FossilOrigin-Name: 7e4af62238bf8fa3d3cbc79e2c8951e621a0c0b4
2005-03-10 12:58:21 +00:00
drh fec8066734 Disable the alter2 tests if there is a codec compiled into the library. (CVS 2370)
FossilOrigin-Name: 06a48da67b142e92624cdfd46947bd4ccc6842b7
2005-03-10 12:52:47 +00:00
drh 33fa535dca Fix a #ifdef in util.c. (CVS 2369)
FossilOrigin-Name: f426c625c4c3de626b5f5f8b5a6343a7ec3b16e9
2005-03-10 12:35:45 +00:00
danielk1977 5fd057af68 Fix a file corruption bug in CREATE INDEX in auto-vacuum databases. (CVS 2368)
FossilOrigin-Name: 64c4c717d35c8fce9b4be073196c507f6d471188
2005-03-09 13:09:43 +00:00
danielk1977 aee18ef8e2 Support for a future ALTER TABLE command to add columns with default values. (CVS 2367)
FossilOrigin-Name: 9d5abc1ddf6da37563c12d5a0401b89bb4e51c59
2005-03-09 12:26:50 +00:00
drh 97ba4c94fc Print an error message and quit if the regression tests are run as root.
Ticket #1153. (CVS 2366)

FossilOrigin-Name: 9b96078763949a2723482328e7b90c939ba8d2d8
2005-03-02 05:18:57 +00:00
drh d61c443e6a Fix the header comment on experimental.c. (CVS 2365)
FossilOrigin-Name: 0c4d2b11c922b41d0e03bfbd885dfdf52ce7ccab
2005-03-02 05:18:29 +00:00
drh 737b6e83a1 Version 3.1.3.1 (not an official release) (CVS 2364)
FossilOrigin-Name: 957333a7b203373e89030766f693e691f049c66a
2005-02-28 01:52:56 +00:00
drh de4fb7b050 Bump the version number to 3.1.3.1. (CVS 2363)
FossilOrigin-Name: 1ca8bbf749988fd3c88b25c08255c2096f833808
2005-02-28 01:42:23 +00:00
drh bf21627b6f Add the SQLITE_OMIT_FLAG_PRAGMAS compile-time option. (CVS 2362)
FossilOrigin-Name: c167e9054249361d1f464d3840a5c277e6ed44ab
2005-02-26 18:10:44 +00:00
drh ccae6026e6 Fix an assertion fault that can occur while autovacuuming a corrupt database
file.  Add the SQLITE_OMIT_COMPLETE compile-time parameter. (CVS 2361)

FossilOrigin-Name: bb0e7e3857a06347b08d93553ac603e737322262
2005-02-26 17:31:26 +00:00
drh 7530873132 Revised man page from Bill Bumgarner. (CVS 2360)
FossilOrigin-Name: 5c99bea5a480edc7b15ae80be952b212e730d452
2005-02-24 04:51:51 +00:00
drh 51e75cafb0 Remove strcasecmp from shell.c. Tickets #1108, #1122. (CVS 2359)
FossilOrigin-Name: 4ae1a9fc2c484e59ef1e58972aa25772cede1187
2005-02-23 12:35:41 +00:00
drh 29088eb6c9 The script that cross-compiles the windows DLLs now exports the symbols
Tclsqlite_Init and Sqlite_Init used to initialize the TCL extension.
Ticket #1137. (CVS 2358)

FossilOrigin-Name: f18704777407d84f5ba23333e8d4bcdcb09b4a70
2005-02-23 00:26:12 +00:00
danielk1977 3fdf826699 Fix bug reported on the mailing list for WHERE clauses like (rowid<'2'). (CVS 2357)
FossilOrigin-Name: b323f0f2832ac5d225d880db6f56314d2f766a25
2005-02-22 09:47:18 +00:00
drh dcc2b9882b Version 3.1.3 (CVS 2356)
FossilOrigin-Name: 36dbf5e929ede7768e8b63219e54548384a8fab5
2005-02-20 02:25:57 +00:00
drh 30375de10e Prepare for the release of 3.1.3. (CVS 2355)
FossilOrigin-Name: 5b66631fd4820e721fd506b233ca9259360139be
2005-02-19 13:46:25 +00:00
drh 30963453c5 Rework parts of the pragma documentation. Ticket #1081. (CVS 2354)
FossilOrigin-Name: 25141d9e213005940c4e57deca408e09c3e615d1
2005-02-19 13:05:47 +00:00
drh 0ab5fcccc7 Add documentation on the EXISTS expression. Ticket #1082. (CVS 2353)
FossilOrigin-Name: 76cacb4a39d2dd79a27624a8bd1ff65eeedd4ac8
2005-02-19 12:44:15 +00:00
drh e1b4f0374c Remove duplicate word from documentation. Ticket #1103. (CVS 2352)
FossilOrigin-Name: c1fc0a8aa96d2bd615f815b2477b801bda9e9c50
2005-02-19 12:32:57 +00:00
danielk1977 36963fdca8 Support for a future file format that includes 'short' records. (CVS 2351)
FossilOrigin-Name: 173aeb256e2c09098a4392874f8623e8a760d951
2005-02-19 08:18:05 +00:00
danielk1977 25d39a83ac Fix typos in documentation for pragma short_column_names. Ticket #1130. (CVS 2350)
FossilOrigin-Name: fac56fa1e06e15ffd738cb9b780d422a73a743ae
2005-02-18 01:15:23 +00:00
drh 75f86a4b0b Compile-time option to limit the size of AUTOINCREMENT rowids to 32-bits. (CVS 2349)
FossilOrigin-Name: c5366deaf5beca9c99558c0f375ba73f817acd92
2005-02-17 00:03:06 +00:00
danielk1977 46dd62bc69 Clarify that columns are indexed from 0 when using sqlite3_column_XXX() APIs. No code changes. (CVS 2348)
FossilOrigin-Name: d5eb25d8d0d444ab98b26f7f1ac763919e692806
2005-02-16 23:43:33 +00:00
drh b797783d68 Change to configure.ac contributed by a reader. (CVS 2346)
FossilOrigin-Name: 0cd3bf02d25933286085708308ff963c50c8d33d
2005-02-16 03:45:51 +00:00
drh dc30dd3158 Patch the command-line error message printing for lemon. Ticket #1120. (CVS 2345)
FossilOrigin-Name: 97c7aaf1870a86955f0f3a0cbe06187e3c3ccc90
2005-02-16 03:35:15 +00:00
drh 0f68fd1bd9 Get vacuum working on database that used to have autoincrement tables but
where all such tables have been dropped.  Ticket #1121. (CVS 2344)

FossilOrigin-Name: 8f7c639da0f862fa2dd2f55eb7e4d453cd321540
2005-02-16 03:27:04 +00:00
drh 1f01ec1b7a Move the special built-in SQL functions used by ALTER TABLE out of func.c
and into alter.c. (CVS 2343)

FossilOrigin-Name: dbd11a0c581b447bb2f220a1a185d9fd36933ee3
2005-02-15 21:36:18 +00:00
drh d0e4a6c11d Split the logic for the ALTER TABLE command off into a separate source
code file. (CVS 2342)

FossilOrigin-Name: 90d6573c2631fac92b9e572e9e21698ae2480c9d
2005-02-15 20:47:57 +00:00
drh 057cd3a0aa Btree checks the autovacuum flag after locking the database file. (CVS 2341)
FossilOrigin-Name: 6610188f09d08c65c46a140685b403aa74f71a19
2005-02-15 16:23:02 +00:00
drh 39171f390d Append the version number to the directory name in source code tarballs.
Tickets #793, #855, and #1055. (CVS 2340)

FossilOrigin-Name: 138577d0a5c41f3de4f9adc9ab6e312a65ff8888
2005-02-15 16:15:09 +00:00
drh a10da477c2 Fix a hyperlink bug on the homepage. (CVS 2338)
FossilOrigin-Name: 9fd9d9fbeefcc76e7262f488f99ac11eaf58e88e
2005-02-15 13:38:46 +00:00
206 changed files with 21061 additions and 9347 deletions
+42 -33
View File
@@ -52,7 +52,7 @@ LIBREADLINE = @TARGET_READLINE_LIBS@
# Should the database engine be compiled threadsafe
#
THREADSAFE = -DTHREADSAFE=@THREADSAFE@
TCC += -DTHREADSAFE=@THREADSAFE@
# The pthreads library if needed
#
@@ -112,22 +112,28 @@ TCC += -DSQLITE_OMIT_CURSOR
# Object files for the SQLite library.
#
LIBOBJ = attach.lo auth.lo btree.lo build.lo date.lo \
LIBOBJ = alter.lo analyze.lo attach.lo auth.lo btree.lo build.lo \
callback.lo complete.lo date.lo \
delete.lo expr.lo func.lo hash.lo insert.lo \
main.lo opcodes.lo os_unix.lo os_win.lo \
pager.lo parse.lo pragma.lo printf.lo random.lo \
pager.lo parse.lo pragma.lo prepare.lo printf.lo random.lo \
select.lo table.lo tokenize.lo trigger.lo update.lo \
util.lo vacuum.lo vdbe.lo vdbeapi.lo vdbeaux.lo vdbemem.lo \
util.lo vacuum.lo \
vdbe.lo vdbeapi.lo vdbeaux.lo vdbefifo.lo vdbemem.lo \
where.lo utf.lo legacy.lo
# All of the source code files.
#
SRC = \
$(TOP)/src/alter.c \
$(TOP)/src/analyze.c \
$(TOP)/src/attach.c \
$(TOP)/src/auth.c \
$(TOP)/src/btree.c \
$(TOP)/src/btree.h \
$(TOP)/src/build.c \
$(TOP)/src/callback.c \
$(TOP)/src/complete.c \
$(TOP)/src/date.c \
$(TOP)/src/delete.c \
$(TOP)/src/expr.c \
@@ -143,6 +149,7 @@ SRC = \
$(TOP)/src/pager.h \
$(TOP)/src/parse.y \
$(TOP)/src/pragma.c \
$(TOP)/src/prepare.c \
$(TOP)/src/printf.c \
$(TOP)/src/random.c \
$(TOP)/src/select.c \
@@ -161,6 +168,7 @@ SRC = \
$(TOP)/src/vdbe.h \
$(TOP)/src/vdbeapi.c \
$(TOP)/src/vdbeaux.c \
$(TOP)/src/vdbefifo.c \
$(TOP)/src/vdbemem.c \
$(TOP)/src/vdbeInt.h \
$(TOP)/src/where.c
@@ -184,14 +192,14 @@ TESTSRC = \
$(TOP)/src/utf.c \
$(TOP)/src/util.c \
$(TOP)/src/vdbe.c \
$(TOP)/src/md5.c
$(TOP)/src/md5.c \
$(TOP)/src/where.c
# Header files used by all library source files.
#
HDR = \
sqlite3.h \
$(TOP)/src/btree.h \
config.h \
$(TOP)/src/hash.h \
opcodes.h \
$(TOP)/src/os.h \
@@ -260,6 +268,12 @@ lemon$(BEXE): $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
# Rules to build individual files
#
alter.lo: $(TOP)/src/alter.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/alter.c
analyze.lo: $(TOP)/src/analyze.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/analyze.c
attach.lo: $(TOP)/src/attach.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/attach.c
@@ -272,21 +286,11 @@ btree.lo: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
build.lo: $(TOP)/src/build.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/build.c
# The config.h file will contain a single #define that tells us how
# many bytes are in a pointer. This only works if a pointer is the
# same size on the host as it is on the target. If you are cross-compiling
# to a target with a different pointer size, you'll need to manually
# configure the config.h file.
#
config.h:
echo '#include <stdio.h>' >temp.c
echo 'int main(){printf(' >>temp.c
echo '"#define SQLITE_PTR_SZ %d",sizeof(char*));' >>temp.c
echo 'exit(0);}' >>temp.c
$(BCC) -o temp temp.c
./temp >config.h
echo >>config.h
rm -f temp.c temp
callback.lo: $(TOP)/src/callback.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/callback.c
complete.lo: $(TOP)/src/complete.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/complete.c
date.lo: $(TOP)/src/date.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/date.c
@@ -325,10 +329,10 @@ opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk
cat parse.h $(TOP)/src/vdbe.c | awk -f $(TOP)/mkopcodeh.awk >opcodes.h
os_unix.lo: $(TOP)/src/os_unix.c $(HDR)
$(LTCOMPILE) $(THREADSAFE) -c $(TOP)/src/os_unix.c
$(LTCOMPILE) -c $(TOP)/src/os_unix.c
os_win.lo: $(TOP)/src/os_win.c $(HDR)
$(LTCOMPILE) $(THREADSAFE) -c $(TOP)/src/os_win.c
$(LTCOMPILE) -c $(TOP)/src/os_win.c
parse.lo: parse.c $(HDR)
$(LTCOMPILE) -c parse.c
@@ -342,6 +346,9 @@ parse.c: $(TOP)/src/parse.y lemon$(BEXE)
pragma.lo: $(TOP)/src/pragma.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/pragma.c
prepare.lo: $(TOP)/src/prepare.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/prepare.c
printf.lo: $(TOP)/src/printf.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/printf.c
@@ -392,6 +399,9 @@ vdbeapi.lo: $(TOP)/src/vdbeapi.c $(VDBEHDR)
vdbeaux.lo: $(TOP)/src/vdbeaux.c $(VDBEHDR)
$(LTCOMPILE) -c $(TOP)/src/vdbeaux.c
vdbefifo.lo: $(TOP)/src/vdbefifo.c $(VDBEHDR)
$(LTCOMPILE) -c $(TOP)/src/vdbefifo.c
vdbemem.lo: $(TOP)/src/vdbemem.c $(VDBEHDR)
$(LTCOMPILE) -c $(TOP)/src/vdbemem.c
@@ -408,17 +418,16 @@ tclsqlite3: tclsqlite-shell.lo libsqlite3.la
$(LTLINK) -o tclsqlite3 tclsqlite-shell.lo \
libsqlite3.la $(LIBTCL)
testfixture$(TEXE): $(TOP)/src/tclsqlite.c libtclsqlite3.la libsqlite3.la $(TESTSRC)
$(LTLINK) -DTCLSH=1 -DSQLITE_TEST=1\
$(THREADSAFE) $(TEMP_STORE)\
-o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
libtclsqlite3.la $(LIBTCL)
testfixture$(TEXE): $(TOP)/src/tclsqlite.c libsqlite3.la $(TESTSRC)
$(LTLINK) -DTCLSH=1 -DSQLITE_TEST=1 $(TEMP_STORE) \
-o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
libsqlite3.la $(LIBTCL)
crashtest$(TEXE): $(TOP)/src/tclsqlite.c libsqlite3.la $(TESTSRC) $(TOP)/src/os_test.c
$(LTLINK) -DOS_TEST=1 -DTCLSH=1 -DSQLITE_TEST=1 \
-o crashtest \
$(TESTSRC) $(TOP)/src/os_test.c $(TOP)/src/tclsqlite.c \
libsqlite3.la $(LIBTCL) $(THREADLIB)
libsqlite3.la $(LIBTCL)
@@ -437,8 +446,7 @@ sqlite3_analyzer$(TEXE): $(TOP)/src/tclsqlite.c libtclsqlite3.la \
-e 's,^,",' \
-e 's,$$,\\n",' \
$(TOP)/tool/spaceanal.tcl >spaceanal_tcl.h
$(LTLINK) -DTCLSH=2 -DSQLITE_TEST=1\
$(THREADSAFE) $(TEMP_STORE)\
$(LTLINK) -DTCLSH=2 -DSQLITE_TEST=1 $(TEMP_STORE)\
-o sqlite3_analyzer$(EXE) $(TESTSRC) $(TOP)/src/tclsqlite.c \
libtclsqlite3.la $(LIBTCL)
@@ -561,7 +569,7 @@ version3.html: $(TOP)/www/version3.tcl
#
DOC = \
arch.html \
arch.png \
arch2.gif \
autoinc.html \
c_interface.html \
capi3.html \
@@ -644,7 +652,8 @@ implib: sqlite3.lib
#make Borland C++ and/or Microsoft VC import library for the dll
# ignore any errors (usually due to missing programs)
sqlite3.lib: sqlite3.dll
-implib -a sqlite3.lib sqlite3.dll
-impdef -a sqlite3.def sqlite3.dll
-implib sqlite3.lib sqlite3.def
-lib /machine:i386 /def:$(TOP)/sqlite3.def
distclean: clean
+4 -4
View File
@@ -94,13 +94,13 @@ LIBTCL = /home/drh/tcltk/8.4linux/libtcl8.4g.a -lm -ldl
#### Compiler options needed for programs that use the readline() library.
#
#READLINE_FLAGS =
READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline
READLINE_FLAGS =
#READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline
#### Linker options needed by programs using readline() must link against.
#
#LIBREADLINE =
LIBREADLINE = -static -lreadline -ltermcap
LIBREADLINE =
#LIBREADLINE = -static -lreadline -ltermcap
#### Should the database engine assume text is coded as UTF-8 or iso8859?
#
+1
View File
@@ -15,6 +15,7 @@ For example:
cd bld ;# Change to the build directory
../sqlite/configure ;# Run the configure script
make ;# Run the makefile.
make install ;# (Optional) Install the build products
The configure script uses autoconf 2.50 and libtool. If the configure
script does not work out for you, there is a generic makefile named
+1 -1
View File
@@ -1 +1 @@
3.1.2
3.2.8
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Vendored
+5 -5
View File
@@ -463,7 +463,7 @@ ac_includes_default="\
# include <unistd.h>
#endif"
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP CPP CXX CXXFLAGS ac_ct_CXX CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA program_prefix VERSION VERSION_NUMBER RELEASE BUILD_CC BUILD_CFLAGS BUILD_LIBS TARGET_CC TARGET_CFLAGS TARGET_LINK TARGET_LFLAGS TARGET_RANLIB TARGET_AR THREADSAFE TARGET_THREAD_LIB ALLOWRELEASE TEMP_STORE BUILD_EXEEXT OS_UNIX OS_WIN TARGET_EXEEXT TARGET_LIBS TCL_VERSION TCL_BIN_DIR TCL_SRC_DIR TCL_LIBS TCL_INCLUDE_SPEC TCL_LIB_FILE TCL_LIB_FLAG TCL_LIB_SPEC TCL_STUB_LIB_FILE TCL_STUB_LIB_FLAG TCL_STUB_LIB_SPEC HAVE_TCL TARGET_READLINE_LIBS TARGET_READLINE_INC TARGET_HAVE_READLINE TARGET_DEBUG LIBOBJS LTLIBOBJS'
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP CPP CXX CXXFLAGS ac_ct_CXX CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA program_prefix VERSION RELEASE VERSION_NUMBER BUILD_CC BUILD_CFLAGS BUILD_LIBS TARGET_CC TARGET_CFLAGS TARGET_LINK TARGET_LFLAGS TARGET_RANLIB TARGET_AR THREADSAFE TARGET_THREAD_LIB ALLOWRELEASE TEMP_STORE BUILD_EXEEXT OS_UNIX OS_WIN TARGET_EXEEXT TARGET_LIBS TCL_VERSION TCL_BIN_DIR TCL_SRC_DIR TCL_LIBS TCL_INCLUDE_SPEC TCL_LIB_FILE TCL_LIB_FLAG TCL_LIB_SPEC TCL_STUB_LIB_FILE TCL_STUB_LIB_FLAG TCL_STUB_LIB_SPEC HAVE_TCL TARGET_READLINE_LIBS TARGET_READLINE_INC TARGET_HAVE_READLINE TARGET_DEBUG LIBOBJS LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
@@ -1496,7 +1496,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
# The following RCS revision string applies to configure.in
# $Revision: 1.30 $
# $Revision: 1.31 $
#########
# Programs needed
@@ -18430,11 +18430,11 @@ RELEASE=`cat $srcdir/VERSION`
echo "Release set to $RELEASE"
VERSION_NUMBER=`cat $srcdir/VERSION \
| sed 's/[^0-9]/ /g' \
| sed 's/[^0-9]/ /g' \
| awk '{printf "%d%03d%03d",$1,$2,$3}'`
echo "Version number set to $VERSION_NUMBER"
#########
# 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
@@ -21018,8 +21018,8 @@ s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t
s,@INSTALL_DATA@,$INSTALL_DATA,;t t
s,@program_prefix@,$program_prefix,;t t
s,@VERSION@,$VERSION,;t t
s,@VERSION_NUMBER@,$VERSION_NUMBER,;t t
s,@RELEASE@,$RELEASE,;t t
s,@VERSION_NUMBER@,$VERSION_NUMBER,;t t
s,@BUILD_CC@,$BUILD_CC,;t t
s,@BUILD_CFLAGS@,$BUILD_CFLAGS,;t t
s,@BUILD_LIBS@,$BUILD_LIBS,;t t
+6 -1
View File
@@ -116,7 +116,7 @@ AC_INIT(src/sqlite.h.in)
dnl Put the RCS revision string after AC_INIT so that it will also
dnl show in in configure.
# The following RCS revision string applies to configure.in
# $Revision: 1.15 $
# $Revision: 1.17 $
#########
# Programs needed
@@ -138,6 +138,11 @@ AC_SUBST(VERSION)
RELEASE=`cat $srcdir/VERSION`
echo "Release set to $RELEASE"
AC_SUBST(RELEASE)
VERSION_NUMBER=[`cat $srcdir/VERSION \
| sed 's/[^0-9]/ /g' \
| awk '{printf "%d%03d%03d",$1,$2,$3}'`]
echo "Version number set to $VERSION_NUMBER"
AC_SUBST(VERSION_NUMBER)
#########
# Check to see if the --with-hints=FILE option is used. If there is none,
+679
View File
@@ -0,0 +1,679 @@
# A Tk console widget for SQLite. Invoke sqlitecon::create with a window name,
# a prompt string, a title to set a new top-level window, and the SQLite
# database handle. For example:
#
# sqlitecon::create .sqlcon {sql:- } {SQL Console} db
#
# A toplevel window is created that allows you to type in SQL commands to
# be processed on the spot.
#
# A limited set of dot-commands are supported:
#
# .table
# .schema ?TABLE?
# .mode list|column|multicolumn|line
# .exit
#
# In addition, a new SQL function named "edit()" is created. This function
# takes a single text argument and returns a text result. Whenever the
# the function is called, it pops up a new toplevel window containing a
# text editor screen initialized to the argument. When the "OK" button
# is pressed, whatever revised text is in the text editor is returned as
# the result of the edit() function. This allows text fields of SQL tables
# to be edited quickly and easily as follows:
#
# UPDATE table1 SET dscr = edit(dscr) WHERE rowid=15;
#
# Create a namespace to work in
#
namespace eval ::sqlitecon {
# do nothing
}
# Create a console widget named $w. The prompt string is $prompt.
# The title at the top of the window is $title. The database connection
# object is $db
#
proc sqlitecon::create {w prompt title db} {
upvar #0 $w.t v
if {[winfo exists $w]} {destroy $w}
if {[info exists v]} {unset v}
toplevel $w
wm title $w $title
wm iconname $w $title
frame $w.mb -bd 2 -relief raised
pack $w.mb -side top -fill x
menubutton $w.mb.file -text File -menu $w.mb.file.m
menubutton $w.mb.edit -text Edit -menu $w.mb.edit.m
pack $w.mb.file $w.mb.edit -side left -padx 8 -pady 1
set m [menu $w.mb.file.m -tearoff 0]
$m add command -label {Close} -command "destroy $w"
sqlitecon::create_child $w $prompt $w.mb.edit.m
set v(db) $db
$db function edit ::sqlitecon::_edit
}
# This routine creates a console as a child window within a larger
# window. It also creates an edit menu named "$editmenu" if $editmenu!="".
# The calling function is responsible for posting the edit menu.
#
proc sqlitecon::create_child {w prompt editmenu} {
upvar #0 $w.t v
if {$editmenu!=""} {
set m [menu $editmenu -tearoff 0]
$m add command -label Cut -command "sqlitecon::Cut $w.t"
$m add command -label Copy -command "sqlitecon::Copy $w.t"
$m add command -label Paste -command "sqlitecon::Paste $w.t"
$m add command -label {Clear Screen} -command "sqlitecon::Clear $w.t"
$m add separator
$m add command -label {Save As...} -command "sqlitecon::SaveFile $w.t"
catch {$editmenu config -postcommand "sqlitecon::EnableEditMenu $w"}
}
scrollbar $w.sb -orient vertical -command "$w.t yview"
pack $w.sb -side right -fill y
text $w.t -font fixed -yscrollcommand "$w.sb set"
pack $w.t -side right -fill both -expand 1
bindtags $w.t Sqlitecon
set v(editmenu) $editmenu
set v(history) 0
set v(historycnt) 0
set v(current) -1
set v(prompt) $prompt
set v(prior) {}
set v(plength) [string length $v(prompt)]
set v(x) 0
set v(y) 0
set v(mode) column
set v(header) on
$w.t mark set insert end
$w.t tag config ok -foreground blue
$w.t tag config err -foreground red
$w.t insert end $v(prompt)
$w.t mark set out 1.0
after idle "focus $w.t"
}
bind Sqlitecon <1> {sqlitecon::Button1 %W %x %y}
bind Sqlitecon <B1-Motion> {sqlitecon::B1Motion %W %x %y}
bind Sqlitecon <B1-Leave> {sqlitecon::B1Leave %W %x %y}
bind Sqlitecon <B1-Enter> {sqlitecon::cancelMotor %W}
bind Sqlitecon <ButtonRelease-1> {sqlitecon::cancelMotor %W}
bind Sqlitecon <KeyPress> {sqlitecon::Insert %W %A}
bind Sqlitecon <Left> {sqlitecon::Left %W}
bind Sqlitecon <Control-b> {sqlitecon::Left %W}
bind Sqlitecon <Right> {sqlitecon::Right %W}
bind Sqlitecon <Control-f> {sqlitecon::Right %W}
bind Sqlitecon <BackSpace> {sqlitecon::Backspace %W}
bind Sqlitecon <Control-h> {sqlitecon::Backspace %W}
bind Sqlitecon <Delete> {sqlitecon::Delete %W}
bind Sqlitecon <Control-d> {sqlitecon::Delete %W}
bind Sqlitecon <Home> {sqlitecon::Home %W}
bind Sqlitecon <Control-a> {sqlitecon::Home %W}
bind Sqlitecon <End> {sqlitecon::End %W}
bind Sqlitecon <Control-e> {sqlitecon::End %W}
bind Sqlitecon <Return> {sqlitecon::Enter %W}
bind Sqlitecon <KP_Enter> {sqlitecon::Enter %W}
bind Sqlitecon <Up> {sqlitecon::Prior %W}
bind Sqlitecon <Control-p> {sqlitecon::Prior %W}
bind Sqlitecon <Down> {sqlitecon::Next %W}
bind Sqlitecon <Control-n> {sqlitecon::Next %W}
bind Sqlitecon <Control-k> {sqlitecon::EraseEOL %W}
bind Sqlitecon <<Cut>> {sqlitecon::Cut %W}
bind Sqlitecon <<Copy>> {sqlitecon::Copy %W}
bind Sqlitecon <<Paste>> {sqlitecon::Paste %W}
bind Sqlitecon <<Clear>> {sqlitecon::Clear %W}
# Insert a single character at the insertion cursor
#
proc sqlitecon::Insert {w a} {
$w insert insert $a
$w yview insert
}
# Move the cursor one character to the left
#
proc sqlitecon::Left {w} {
upvar #0 $w v
scan [$w index insert] %d.%d row col
if {$col>$v(plength)} {
$w mark set insert "insert -1c"
}
}
# Erase the character to the left of the cursor
#
proc sqlitecon::Backspace {w} {
upvar #0 $w v
scan [$w index insert] %d.%d row col
if {$col>$v(plength)} {
$w delete {insert -1c}
}
}
# Erase to the end of the line
#
proc sqlitecon::EraseEOL {w} {
upvar #0 $w v
scan [$w index insert] %d.%d row col
if {$col>=$v(plength)} {
$w delete insert {insert lineend}
}
}
# Move the cursor one character to the right
#
proc sqlitecon::Right {w} {
$w mark set insert "insert +1c"
}
# Erase the character to the right of the cursor
#
proc sqlitecon::Delete w {
$w delete insert
}
# Move the cursor to the beginning of the current line
#
proc sqlitecon::Home w {
upvar #0 $w v
scan [$w index insert] %d.%d row col
$w mark set insert $row.$v(plength)
}
# Move the cursor to the end of the current line
#
proc sqlitecon::End w {
$w mark set insert {insert lineend}
}
# Add a line to the history
#
proc sqlitecon::addHistory {w line} {
upvar #0 $w v
if {$v(historycnt)>0} {
set last [lindex $v(history) [expr $v(historycnt)-1]]
if {[string compare $last $line]} {
lappend v(history) $line
incr v(historycnt)
}
} else {
set v(history) [list $line]
set v(historycnt) 1
}
set v(current) $v(historycnt)
}
# Called when "Enter" is pressed. Do something with the line
# of text that was entered.
#
proc sqlitecon::Enter w {
upvar #0 $w v
scan [$w index insert] %d.%d row col
set start $row.$v(plength)
set line [$w get $start "$start lineend"]
$w insert end \n
$w mark set out end
if {$v(prior)==""} {
set cmd $line
} else {
set cmd $v(prior)\n$line
}
if {[string index $cmd 0]=="." || [$v(db) complete $cmd]} {
regsub -all {\n} [string trim $cmd] { } cmd2
addHistory $w $cmd2
set rc [catch {DoCommand $w $cmd} res]
if {![winfo exists $w]} return
if {$rc} {
$w insert end $res\n err
} elseif {[string length $res]>0} {
$w insert end $res\n ok
}
set v(prior) {}
$w insert end $v(prompt)
} else {
set v(prior) $cmd
regsub -all {[^ ]} $v(prompt) . x
$w insert end $x
}
$w mark set insert end
$w mark set out {insert linestart}
$w yview insert
}
# Execute a single SQL command. Pay special attention to control
# directives that begin with "."
#
# The return value is the text output from the command, properly
# formatted.
#
proc sqlitecon::DoCommand {w cmd} {
upvar #0 $w v
set mode $v(mode)
set header $v(header)
if {[regexp {^(\.[a-z]+)} $cmd all word]} {
if {$word==".mode"} {
regexp {^.[a-z]+ +([a-z]+)} $cmd all v(mode)
return {}
} elseif {$word==".exit"} {
destroy [winfo toplevel $w]
return {}
} elseif {$word==".header"} {
regexp {^.[a-z]+ +([a-z]+)} $cmd all v(header)
return {}
} elseif {$word==".tables"} {
set mode multicolumn
set cmd {SELECT name FROM sqlite_master WHERE type='table'
UNION ALL
SELECT name FROM sqlite_temp_master WHERE type='table'}
$v(db) eval {PRAGMA database_list} {
if {$name!="temp" && $name!="main"} {
append cmd "UNION ALL SELECT name FROM $name.sqlite_master\
WHERE type='table'"
}
}
append cmd { ORDER BY 1}
} elseif {$word==".fullschema"} {
set pattern %
regexp {^.[a-z]+ +([^ ]+)} $cmd all pattern
set mode list
set header 0
set cmd "SELECT sql FROM sqlite_master WHERE tbl_name LIKE '$pattern'
AND sql NOT NULL UNION ALL SELECT sql FROM sqlite_temp_master
WHERE tbl_name LIKE '$pattern' AND sql NOT NULL"
$v(db) eval {PRAGMA database_list} {
if {$name!="temp" && $name!="main"} {
append cmd " UNION ALL SELECT sql FROM $name.sqlite_master\
WHERE tbl_name LIKE '$pattern' AND sql NOT NULL"
}
}
} elseif {$word==".schema"} {
set pattern %
regexp {^.[a-z]+ +([^ ]+)} $cmd all pattern
set mode list
set header 0
set cmd "SELECT sql FROM sqlite_master WHERE name LIKE '$pattern'
AND sql NOT NULL UNION ALL SELECT sql FROM sqlite_temp_master
WHERE name LIKE '$pattern' AND sql NOT NULL"
$v(db) eval {PRAGMA database_list} {
if {$name!="temp" && $name!="main"} {
append cmd " UNION ALL SELECT sql FROM $name.sqlite_master\
WHERE name LIKE '$pattern' AND sql NOT NULL"
}
}
} else {
return \
".exit\n.mode line|list|column\n.schema ?TABLENAME?\n.tables"
}
}
set res {}
if {$mode=="list"} {
$v(db) eval $cmd x {
set sep {}
foreach col $x(*) {
append res $sep$x($col)
set sep |
}
append res \n
}
if {[info exists x(*)] && $header} {
set sep {}
set hdr {}
foreach col $x(*) {
append hdr $sep$col
set sep |
}
set res $hdr\n$res
}
} elseif {[string range $mode 0 2]=="col"} {
set y {}
$v(db) eval $cmd x {
foreach col $x(*) {
if {![info exists cw($col)] || $cw($col)<[string length $x($col)]} {
set cw($col) [string length $x($col)]
}
lappend y $x($col)
}
}
if {[info exists x(*)] && $header} {
set hdr {}
set ln {}
set dash ---------------------------------------------------------------
append dash ------------------------------------------------------------
foreach col $x(*) {
if {![info exists cw($col)] || $cw($col)<[string length $col]} {
set cw($col) [string length $col]
}
lappend hdr $col
lappend ln [string range $dash 1 $cw($col)]
}
set y [concat $hdr $ln $y]
}
if {[info exists x(*)]} {
set format {}
set arglist {}
set arglist2 {}
set i 0
foreach col $x(*) {
lappend arglist x$i
append arglist2 " \$x$i"
incr i
append format " %-$cw($col)s"
}
set format [string trimleft $format]\n
if {[llength $arglist]>0} {
foreach $arglist $y "append res \[format [list $format] $arglist2\]"
}
}
} elseif {$mode=="multicolumn"} {
set y [$v(db) eval $cmd]
set max 0
foreach e $y {
if {$max<[string length $e]} {set max [string length $e]}
}
set ncol [expr {int(80/($max+2))}]
if {$ncol<1} {set ncol 1}
set nelem [llength $y]
set nrow [expr {($nelem+$ncol-1)/$ncol}]
set format "%-${max}s"
for {set i 0} {$i<$nrow} {incr i} {
set j $i
while 1 {
append res [format $format [lindex $y $j]]
incr j $nrow
if {$j>=$nelem} break
append res { }
}
append res \n
}
} else {
$v(db) eval $cmd x {
foreach col $x(*) {append res "$col = $x($col)\n"}
append res \n
}
}
return [string trimright $res]
}
# Change the line to the previous line
#
proc sqlitecon::Prior w {
upvar #0 $w v
if {$v(current)<=0} return
incr v(current) -1
set line [lindex $v(history) $v(current)]
sqlitecon::SetLine $w $line
}
# Change the line to the next line
#
proc sqlitecon::Next w {
upvar #0 $w v
if {$v(current)>=$v(historycnt)} return
incr v(current) 1
set line [lindex $v(history) $v(current)]
sqlitecon::SetLine $w $line
}
# Change the contents of the entry line
#
proc sqlitecon::SetLine {w line} {
upvar #0 $w v
scan [$w index insert] %d.%d row col
set start $row.$v(plength)
$w delete $start end
$w insert end $line
$w mark set insert end
$w yview insert
}
# Called when the mouse button is pressed at position $x,$y on
# the console widget.
#
proc sqlitecon::Button1 {w x y} {
global tkPriv
upvar #0 $w v
set v(mouseMoved) 0
set v(pressX) $x
set p [sqlitecon::nearestBoundry $w $x $y]
scan [$w index insert] %d.%d ix iy
scan $p %d.%d px py
if {$px==$ix} {
$w mark set insert $p
}
$w mark set anchor $p
focus $w
}
# Find the boundry between characters that is nearest
# to $x,$y
#
proc sqlitecon::nearestBoundry {w x y} {
set p [$w index @$x,$y]
set bb [$w bbox $p]
if {![string compare $bb ""]} {return $p}
if {($x-[lindex $bb 0])<([lindex $bb 2]/2)} {return $p}
$w index "$p + 1 char"
}
# This routine extends the selection to the point specified by $x,$y
#
proc sqlitecon::SelectTo {w x y} {
upvar #0 $w v
set cur [sqlitecon::nearestBoundry $w $x $y]
if {[catch {$w index anchor}]} {
$w mark set anchor $cur
}
set anchor [$w index anchor]
if {[$w compare $cur != $anchor] || (abs($v(pressX) - $x) >= 3)} {
if {$v(mouseMoved)==0} {
$w tag remove sel 0.0 end
}
set v(mouseMoved) 1
}
if {[$w compare $cur < anchor]} {
set first $cur
set last anchor
} else {
set first anchor
set last $cur
}
if {$v(mouseMoved)} {
$w tag remove sel 0.0 $first
$w tag add sel $first $last
$w tag remove sel $last end
update idletasks
}
}
# Called whenever the mouse moves while button-1 is held down.
#
proc sqlitecon::B1Motion {w x y} {
upvar #0 $w v
set v(y) $y
set v(x) $x
sqlitecon::SelectTo $w $x $y
}
# Called whenever the mouse leaves the boundries of the widget
# while button 1 is held down.
#
proc sqlitecon::B1Leave {w x y} {
upvar #0 $w v
set v(y) $y
set v(x) $x
sqlitecon::motor $w
}
# This routine is called to automatically scroll the window when
# the mouse drags offscreen.
#
proc sqlitecon::motor w {
upvar #0 $w v
if {![winfo exists $w]} return
if {$v(y)>=[winfo height $w]} {
$w yview scroll 1 units
} elseif {$v(y)<0} {
$w yview scroll -1 units
} else {
return
}
sqlitecon::SelectTo $w $v(x) $v(y)
set v(timer) [after 50 sqlitecon::motor $w]
}
# This routine cancels the scrolling motor if it is active
#
proc sqlitecon::cancelMotor w {
upvar #0 $w v
catch {after cancel $v(timer)}
catch {unset v(timer)}
}
# Do a Copy operation on the stuff currently selected.
#
proc sqlitecon::Copy w {
if {![catch {set text [$w get sel.first sel.last]}]} {
clipboard clear -displayof $w
clipboard append -displayof $w $text
}
}
# Return 1 if the selection exists and is contained
# entirely on the input line. Return 2 if the selection
# exists but is not entirely on the input line. Return 0
# if the selection does not exist.
#
proc sqlitecon::canCut w {
set r [catch {
scan [$w index sel.first] %d.%d s1x s1y
scan [$w index sel.last] %d.%d s2x s2y
scan [$w index insert] %d.%d ix iy
}]
if {$r==1} {return 0}
if {$s1x==$ix && $s2x==$ix} {return 1}
return 2
}
# Do a Cut operation if possible. Cuts are only allowed
# if the current selection is entirely contained on the
# current input line.
#
proc sqlitecon::Cut w {
if {[sqlitecon::canCut $w]==1} {
sqlitecon::Copy $w
$w delete sel.first sel.last
}
}
# Do a paste opeation.
#
proc sqlitecon::Paste w {
if {[sqlitecon::canCut $w]==1} {
$w delete sel.first sel.last
}
if {[catch {selection get -displayof $w -selection CLIPBOARD} topaste]
&& [catch {selection get -displayof $w -selection PRIMARY} topaste]} {
return
}
if {[info exists ::$w]} {
set prior 0
foreach line [split $topaste \n] {
if {$prior} {
sqlitecon::Enter $w
update
}
set prior 1
$w insert insert $line
}
} else {
$w insert insert $topaste
}
}
# Enable or disable entries in the Edit menu
#
proc sqlitecon::EnableEditMenu w {
upvar #0 $w.t v
set m $v(editmenu)
if {$m=="" || ![winfo exists $m]} return
switch [sqlitecon::canCut $w.t] {
0 {
$m entryconf Copy -state disabled
$m entryconf Cut -state disabled
}
1 {
$m entryconf Copy -state normal
$m entryconf Cut -state normal
}
2 {
$m entryconf Copy -state normal
$m entryconf Cut -state disabled
}
}
}
# Prompt the user for the name of a writable file. Then write the
# entire contents of the console screen to that file.
#
proc sqlitecon::SaveFile w {
set types {
{{Text Files} {.txt}}
{{All Files} *}
}
set f [tk_getSaveFile -filetypes $types -title "Write Screen To..."]
if {$f!=""} {
if {[catch {open $f w} fd]} {
tk_messageBox -type ok -icon error -message $fd
} else {
puts $fd [string trimright [$w get 1.0 end] \n]
close $fd
}
}
}
# Erase everything from the console above the insertion line.
#
proc sqlitecon::Clear w {
$w delete 1.0 {insert linestart}
}
# An in-line editor for SQL
#
proc sqlitecon::_edit {origtxt {title {}}} {
for {set i 0} {[winfo exists .ed$i]} {incr i} continue
set w .ed$i
toplevel $w
wm protocol $w WM_DELETE_WINDOW "$w.b.can invoke"
wm title $w {Inline SQL Editor}
frame $w.b
pack $w.b -side bottom -fill x
button $w.b.can -text Cancel -width 6 -command [list set ::$w 0]
button $w.b.ok -text OK -width 6 -command [list set ::$w 1]
button $w.b.cut -text Cut -width 6 -command [list ::sqlitecon::Cut $w.t]
button $w.b.copy -text Copy -width 6 -command [list ::sqlitecon::Copy $w.t]
button $w.b.paste -text Paste -width 6 -command [list ::sqlitecon::Paste $w.t]
set ::$w {}
pack $w.b.cut $w.b.copy $w.b.paste $w.b.can $w.b.ok\
-side left -padx 5 -pady 5 -expand 1
if {$title!=""} {
label $w.title -text $title
pack $w.title -side top -padx 5 -pady 5
}
text $w.t -bg white -fg black -yscrollcommand [list $w.sb set]
pack $w.t -side left -fill both -expand 1
scrollbar $w.sb -orient vertical -command [list $w.t yview]
pack $w.sb -side left -fill y
$w.t insert end $origtxt
vwait ::$w
if {[set ::$w]} {
set txt [string trimright [$w.t get 1.0 end]]
} else {
set txt $origtxt
}
destroy $w
return $txt
}
+48 -34
View File
@@ -54,23 +54,28 @@ TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
# Object files for the SQLite library.
#
LIBOBJ+= attach.o auth.o btree.o build.o date.o delete.o \
LIBOBJ+= alter.o analyze.o attach.o auth.o btree.o build.o \
callback.o complete.o date.o delete.o \
expr.o func.o hash.o insert.o \
main.o opcodes.o os_unix.o os_win.o \
pager.o parse.o pragma.o printf.o random.o \
pager.o parse.o pragma.o prepare.o printf.o random.o \
select.o table.o tclsqlite.o tokenize.o trigger.o \
update.o util.o vacuum.o \
vdbe.o vdbeapi.o vdbeaux.o vdbemem.o \
vdbe.o vdbeapi.o vdbeaux.o vdbefifo.o vdbemem.o \
where.o utf.o legacy.o
# All of the source code files.
#
SRC = \
$(TOP)/src/alter.c \
$(TOP)/src/analyze.c \
$(TOP)/src/attach.c \
$(TOP)/src/auth.c \
$(TOP)/src/btree.c \
$(TOP)/src/btree.h \
$(TOP)/src/build.c \
$(TOP)/src/callback.c \
$(TOP)/src/complete.c \
$(TOP)/src/date.c \
$(TOP)/src/delete.c \
$(TOP)/src/expr.c \
@@ -86,6 +91,7 @@ SRC = \
$(TOP)/src/pager.h \
$(TOP)/src/parse.y \
$(TOP)/src/pragma.c \
$(TOP)/src/prepare.c \
$(TOP)/src/printf.c \
$(TOP)/src/random.c \
$(TOP)/src/select.c \
@@ -104,6 +110,7 @@ SRC = \
$(TOP)/src/vdbe.h \
$(TOP)/src/vdbeapi.c \
$(TOP)/src/vdbeaux.c \
$(TOP)/src/vdbefifo.c \
$(TOP)/src/vdbemem.c \
$(TOP)/src/vdbeInt.h \
$(TOP)/src/where.c
@@ -127,14 +134,14 @@ TESTSRC = \
$(TOP)/src/utf.c \
$(TOP)/src/util.c \
$(TOP)/src/vdbe.c \
$(TOP)/src/md5.c
$(TOP)/src/md5.c \
$(TOP)/src/where.c
# Header files used by all library source files.
#
HDR = \
sqlite3.h \
$(TOP)/src/btree.h \
config.h \
$(TOP)/src/hash.h \
opcodes.h \
$(TOP)/src/os.h \
@@ -154,7 +161,7 @@ VDBEHDR = \
# This is the default Makefile target. The objects listed here
# are what get build when you type just "make" with no arguments.
#
all: sqlite3.h config.h libsqlite3.a sqlite3$(EXE)
all: sqlite3.h libsqlite3.a sqlite3$(EXE)
# Generate the file "last_change" which contains the date of change
# of the most recently modified source code file
@@ -195,6 +202,12 @@ lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
# Rules to build individual files
#
alter.o: $(TOP)/src/alter.c $(HDR)
$(TCCX) -c $(TOP)/src/alter.c
analyze.o: $(TOP)/src/analyze.c $(HDR)
$(TCCX) -c $(TOP)/src/analyze.c
attach.o: $(TOP)/src/attach.c $(HDR)
$(TCCX) -c $(TOP)/src/attach.c
@@ -207,21 +220,11 @@ btree.o: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
build.o: $(TOP)/src/build.c $(HDR)
$(TCCX) -c $(TOP)/src/build.c
# The config.h file will contain a single #define that tells us how
# many bytes are in a pointer. This only works if a pointer is the
# same size on the host as it is on the target. If you are cross-compiling
# to a target with a different pointer size, you'll need to manually
# configure the config.h file.
#
config.h:
echo '#include <stdio.h>' >temp.c
echo 'int main(){printf(' >>temp.c
echo '"#define SQLITE_PTR_SZ %d",sizeof(char*));' >>temp.c
echo 'exit(0);}' >>temp.c
$(BCC) -o temp temp.c
./temp >config.h
echo >>config.h
rm -f temp.c temp
callback.o: $(TOP)/src/callback.c $(HDR)
$(TCCX) -c $(TOP)/src/callback.c
complete.o: $(TOP)/src/complete.c $(HDR)
$(TCCX) -c $(TOP)/src/complete.c
date.o: $(TOP)/src/date.c $(HDR)
$(TCCX) -c $(TOP)/src/date.c
@@ -277,6 +280,9 @@ parse.c: $(TOP)/src/parse.y lemon
pragma.o: $(TOP)/src/pragma.c $(HDR)
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
prepare.o: $(TOP)/src/prepare.c $(HDR)
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/prepare.c
printf.o: $(TOP)/src/printf.c $(HDR)
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/printf.c
@@ -328,6 +334,9 @@ vdbeapi.o: $(TOP)/src/vdbeapi.c $(VDBEHDR)
vdbeaux.o: $(TOP)/src/vdbeaux.c $(VDBEHDR)
$(TCCX) -c $(TOP)/src/vdbeaux.c
vdbefifo.o: $(TOP)/src/vdbefifo.c $(VDBEHDR)
$(TCCX) -c $(TOP)/src/vdbefifo.c
vdbemem.o: $(TOP)/src/vdbemem.c $(VDBEHDR)
$(TCCX) -c $(TOP)/src/vdbemem.c
@@ -375,9 +384,6 @@ sqlite3_analyzer$(EXE): $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC) \
arch.html: $(TOP)/www/arch.tcl
tclsh $(TOP)/www/arch.tcl >arch.html
arch.png: $(TOP)/www/arch.png
cp $(TOP)/www/arch.png .
autoinc.html: $(TOP)/www/autoinc.tcl
tclsh $(TOP)/www/autoinc.tcl >autoinc.html
@@ -417,6 +423,9 @@ datatypes.html: $(TOP)/www/datatypes.tcl
datatype3.html: $(TOP)/www/datatype3.tcl
tclsh $(TOP)/www/datatype3.tcl >datatype3.html
different.html: $(TOP)/www/different.tcl
tclsh $(TOP)/www/different.tcl >different.html
docs.html: $(TOP)/www/docs.tcl
tclsh $(TOP)/www/docs.tcl >docs.html
@@ -445,6 +454,12 @@ pragma.html: $(TOP)/www/pragma.tcl
lockingv3.html: $(TOP)/www/lockingv3.tcl
tclsh $(TOP)/www/lockingv3.tcl >lockingv3.html
mingw.html: $(TOP)/www/mingw.tcl
tclsh $(TOP)/www/mingw.tcl >mingw.html
nulls.html: $(TOP)/www/nulls.tcl
tclsh $(TOP)/www/nulls.tcl >nulls.html
oldnews.html: $(TOP)/www/oldnews.tcl
tclsh $(TOP)/www/oldnews.tcl >oldnews.html
@@ -454,11 +469,11 @@ omitted.html: $(TOP)/www/omitted.tcl
opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
mingw.html: $(TOP)/www/mingw.tcl
tclsh $(TOP)/www/mingw.tcl >mingw.html
optimizer.html: $(TOP)/www/optimizer.tcl
tclsh $(TOP)/www/optimizer.tcl >optimizer.html
nulls.html: $(TOP)/www/nulls.tcl
tclsh $(TOP)/www/nulls.tcl >nulls.html
optoverview.html: $(TOP)/www/optoverview.tcl
tclsh $(TOP)/www/optoverview.tcl >optoverview.html
quickstart.html: $(TOP)/www/quickstart.tcl
tclsh $(TOP)/www/quickstart.tcl >quickstart.html
@@ -466,9 +481,6 @@ quickstart.html: $(TOP)/www/quickstart.tcl
speed.html: $(TOP)/www/speed.tcl
tclsh $(TOP)/www/speed.tcl >speed.html
sqlite.gif: $(TOP)/art/SQLite.gif
cp $(TOP)/art/SQLite.gif sqlite.gif
sqlite.html: $(TOP)/www/sqlite.tcl
tclsh $(TOP)/www/sqlite.tcl >sqlite.html
@@ -492,7 +504,6 @@ whentouse.html: $(TOP)/www/whentouse.tcl
#
DOC = \
arch.html \
arch.png \
autoinc.html \
c_interface.html \
capi3.html \
@@ -505,6 +516,7 @@ DOC = \
conflict.html \
datatypes.html \
datatype3.html \
different.html \
docs.html \
download.html \
faq.html \
@@ -518,10 +530,11 @@ DOC = \
oldnews.html \
omitted.html \
opcode.html \
optimizer.html \
optoverview.html \
pragma.html \
quickstart.html \
speed.html \
sqlite.gif \
sqlite.html \
support.html \
tclsqlite.html \
@@ -532,6 +545,7 @@ DOC = \
doc: common.tcl $(DOC)
mkdir -p doc
mv $(DOC) doc
cp $(TOP)/www/*.gif $(TOP)/art/*.gif doc
# Standard install and cleanup targets
#
@@ -541,7 +555,7 @@ install: sqlite3 libsqlite3.a sqlite3.h
mv sqlite3.h /usr/include
clean:
rm -f *.o sqlite3 libsqlite3.a sqlite3.h opcodes.*
rm -f *.o sqlite3 libsqlite3.a sqlite3.h opcodes.* crashtest
rm -f lemon lempar.c parse.* sqlite*.tar.gz mkkeywordhash keywordhash.h
rm -f $(PUBLISH)
rm -f *.da *.bb *.bbg gmon.out
+205 -167
View File
@@ -1,228 +1,259 @@
C Version\s3.1.2\s(CVS\s2337)
D 2005-02-15T13:08:10
F Makefile.in d928187101fa3d78426cf48ca30e39d0fb714e57
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
F VERSION 9e556d0985199b130268c3b8e5615b90dda7e829
C Version\s3.2.8\s(CVS\s2835)
D 2005-12-19T17:27:00
F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F VERSION 4cef1bf020a669a809eb9ae30b049af780c5b52b
F aclocal.m4 7daea4c35e88de30d5a3f6f7a2ab99720e803bbd
F art/2005osaward.gif 0d1851b2a7c1c9d0ccce545f3e14bca42d7fd248
F art/SQLite.eps 9b43cc99cfd2be687d386faea6862ea68d6a72b2
F art/SQLite.gif 1bbb94484963f1382e27e1c5e86dd0c1061eba2b
F art/SQLiteLogo3.tiff b9e6bf022ae939bc986cddb8ab99583ca1b02cb3
F config.guess 2103e94b15dc57112d7b9ee152c6fac5288895b4
F config.sub 9bf686ec001ae7bc53f5b3563c90c62d4c6d48be
F configure ae39c037bbd1fad89d87a89c505d012b975e9f97 x
F configure.ac a3e521f42b4352215c2499bc2a7138b076d30c59
F configure b36e5d4156002b857e4c741626a7ac8412c2885c x
F configure.ac fe941d9e98fff7edecdaca36a730da76f397f378
F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad
F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
F main.mk 834d5f2feb8d0f79fb3d2bb9db5afac2b3da7349
F mkdll.sh 468d4f41d3ea98221371df4825cfbffbaac4d7e4
F main.mk 72176d7299c2fd6ca2850623195a6984f75380a6
F mkdll.sh 5ec23622515d5bf8969404e80cfb5e220ddf0512
F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d
F mkopcodeh.awk e4d010870a3e98fd4323635c31565a3ca8584741
F mkopcodeh.awk c5ed62f101d408e64bcad0a8c036d85e99905480
F mkso.sh 125868def279650a07d3f0f5e8476fecf99613fd
F publish.sh 72bde067dda3fc2d33e92f20253b924e3b97da30
F publish.sh ed0aba4ffdfadb36597d03ce8efdae96efc038cb
F spec.template b2f6c4e488cbc3b993a57deba22cbc36203c4da3
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
F sqlite3.1 01fdb467ce387a83248857c92f9e801df9e4611c
F sqlite3.def dbaeb20c153e1d366e8f421b55a573f5dfc00863
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
F sqlite3.def c413e514217736884254739a105c8c942fdf0c2f
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
F src/attach.c f78f76bc6a8e5e487ca53636e21ccba2484a9a61
F src/auth.c 18c5a0befe20f3a58a41e3ddd78f372faeeefe1f
F src/btree.c 2432adf957c68e7243b198c174b0f316f9717844
F src/btree.h 2e2cc923224649337d7217df0dd32b06673ca180
F src/build.c 09333b6006d26d411dbaa918601be1054c09fff3
F src/date.c f3d1f5cd1503dabf426a198f3ebef5afbc122a7f
F src/delete.c 4b94395b52a8f7785acd71135c2ce54f3f5550b3
F src/experimental.c 8cc66b2be6a011055d75ef19ed2584bcfbb585ad
F src/expr.c e160aabb59ff3c02e8e00ca4b30d00b94664c519
F src/func.c 4538f82c8ae5f753012f15c4f22cffd578280c56
F src/alter.c 26d755f2143719dd3f5b8aaf6cbe3c7f95332528
F src/analyze.c 21a4cd125bedd3cb15857595c45c2a49c0556d26
F src/attach.c 4b21689700a72ae281fa85dbaff06b2a62bd49ee
F src/auth.c 31e2304bef67f44d635655f44234387ea7d21454
F src/btree.c 236126155d5607da945d33514218cbec762d887e
F src/btree.h 1ed561263ca0e335bc3e81d761c9d5ff8c22f61e
F src/build.c aa9591839c00731370c1ba53a9c0045f70d764c4
F src/callback.c 9a1162c8f9dae9fad6d548339669aacb5f6cf76b
F src/complete.c 4de937dfdd4c79a501772ab2035b26082f337a79
F src/date.c 7444b0900a28da77e57e3337a636873cff0ae940
F src/delete.c 29dac493f4d83b05f91233b116827c133bcdab72
F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
F src/expr.c bb2cf5d5b065eaa23d5ae2620f6de0568768147d
F src/func.c f63d417248808ff2632a3b576536abffcc21d858
F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
F src/insert.c 0456649d4d48396f918e7ea1fecbf3d66ed90816
F src/insert.c 1f51566d7cf4b243a2792f5fda37343d6e9377fa
F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
F src/main.c 981099f5f73a71e54b0858b01e03d29b83168f7b
F src/main.c 422014201f22aa17b96c76650163178a91a825af
F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
F src/os.h ae44064dc118b20d39450cb331409a775e8bb1c6
F src/os_common.h 0e7f428ba0a6c40a61bc56c4e96f493231301b73
F src/os_test.c 91e5f22dd89491e5e1554820e715805f43fa4ece
F src/os_test.h 6a26a4978492e4bbdbf385554958418ff02db162
F src/os_unix.c 68d3d32937eee90fe1f50d500d1a4ee826cbe790
F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13
F src/os_win.c bddeae1c3299be0fbe47077dd4e98b786a067f71
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 835028769569971c7dbd63d11d3517392f1cdae0
F src/pager.h 70d496f372163abb6340f474288c4bb9ea962cf7
F src/parse.y 450fc9c4d5a737be6fdba6e4b2e3de5800d4d750
F src/pragma.c 7e65c5545d83909238adf231e2a6eee6eb43e0d5
F src/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
F src/select.c 69e6093d52e871a243477e9746f820456538dd03
F src/shell.c 3cb0ef124ed9cd582ce89aec59ff7c659bc6e61b
F src/sqlite.h.in c85f6bad9ca7de29f505fe886646cfff7df4c55e
F src/sqliteInt.h 3ebdaeee801f79950c38986639dcfb90782042ed
F src/os.h c51f2747f7bd1840447e2c7d26db749604626814
F src/os_common.h 1ff88c7e7e6bd3e5f85443106c91cc26a4f8600b
F src/os_unix.c 407dd07818d13807c396acf3f7570af81cbb666c
F src/os_win.c fbccc85e7011174068c27d54256746321a1f0059
F src/pager.c b74ebe5aca00ad5f831e19ae17193fe7b83a7ddf
F src/pager.h e7b41ce8e7b5f629d456708b7ad9a8c8ede37140
F src/parse.y 5602d5cb894dda2932bf50b7e88782a4440ae3ae
F src/pragma.c 126149668aa7086e86cfa3e32c8523513c19dd63
F src/prepare.c fc098db25d2a121affb08686cf04833fd50452d4
F src/printf.c bd421c1ad5e01013c89af63c60eab02852ccd15e
F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
F src/select.c 034c7f7447b8711f85bef578a437ea12ca7cac53
F src/shell.c 3596c1e559b82663057940d19ba533ad421c7dd3
F src/sqlite.h.in 461b2535550cf77aedfd44385da11ef7d63e57a2
F src/sqliteInt.h 53daa72541b4336c5e89773cf39717ed695bd523
F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
F src/tclsqlite.c 101994a2c4c0eaa69f1de9bfe4a02167f6049e7d
F src/test1.c feac8a742aca920c8ab18a43b3208ae3a834fe9d
F src/test2.c 7f0ef466706ac01414e1136b96e5d8a65cb97545
F src/test3.c 683e1e3819152ffd35da2f201e507228921148d0
F src/test4.c 7c6b9fc33dd1f3f93c7f1ee6e5e6d016afa6c1df
F src/tclsqlite.c ac94682f9e601dd373912c46414a5a842db2089a
F src/test1.c 0f1a66f65a54fba029f7e93b7500d49443dc959b
F src/test2.c 4196848c845626e7df894470f27329e80bfe92aa
F src/test3.c f4e6a16a602091696619a1171bda25c0e3df49f7
F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5
F src/tokenize.c bbeee5e30019261fe2d36330d2bf70d9d7c3eee9
F src/trigger.c 038c8e128d4551cd016426cd11bbf5c478816481
F src/update.c b6f4668c11059f86b71581187d09197fa28ec4be
F src/tokenize.c e1faf5637f3f4f90933785a0ecf64595f3ac3530
F src/trigger.c f51dec15921629591cb98bf2e350018e268b109a
F src/update.c ac506fb7400158f826ec6c3a0dbe65e7ed3928d5
F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c
F src/util.c 1b7b9a127b66743ab6cba8d44597aeb570723c99
F src/vacuum.c ccb34e92fd662b2d975e3c8d8cfd229c9081cb78
F src/vdbe.c d9ec62c9f63768b4d4f8513b25aded8faf2de17b
F src/vdbe.h bb9186484f749a839c6c43953e79a6530253f7cd
F src/vdbeInt.h e80721cd8ff611789e20743eec43363a9fb5a48e
F src/vdbeapi.c 467caa6e6fb9247528b1c7ab9132ae1b4748e8ac
F src/vdbeaux.c 8d8cc8992cb78cab35e034fa81ad0c1a771c39f1
F src/vdbemem.c 62fe89471b656a922e9879be005abf690509ead3
F src/where.c c4b6a799ed9cc99c63d298c8741956156eeb05eb
F src/util.c 55caaffbb2716f9928ab452d20f3e9cbbeab872d
F src/vacuum.c 829d9e1a6d7c094b80e0899686670932eafd768c
F src/vdbe.c 3f1adcf4535dd35e4244d19d332fb6b515491c0d
F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
F src/vdbeInt.h 7bedbb9553a10e86b53f75d99e197f3f00a732bf
F src/vdbeapi.c 85bbe1d0243a89655433d60711b4bd71979b59cd
F src/vdbeaux.c 2b728d82cf2095386a90051b66e7faf1a143f27d
F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
F src/vdbemem.c ff426ff6e72aa3f0300a56ec8c7f18099be96b43
F src/where.c 3ed72ca029b3010a76e3a41b7b02ec1bdf849f00
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
F test/alter.test 3a20ce14c3989f7e2e75da50797065c2e56f838b
F test/attach.test 5147d531ca5fc5c2539fd20ce3b07a00420e1fbb
F test/attach2.test 6f3a3a3a7f5be40388dd4d805e0e0712718dca9d
F test/attach3.test c05c70b933afbde0901dab9da3e66ee842c09f38
F test/auth.test b24d12de3a6ba49237216429f8dc672a8a52b342
F test/autoinc.test c6daf10ffce8a898cd375b4a71615a741a6029d0
F test/autovacuum.test 8ba29face873300394f9446ded0e4a142d24e7e4
F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
F test/alter2.test 60ba0a7057dc71ad630a1cc7c487104346849d50
F test/alter3.test d4eecd8dbd008d0e66f1c201fa6dc2edca853c38
F test/altermalloc.test 6e1f404ec021eb2ba6582e3c77b0a35cf206b7af
F test/analyze.test 2f55535aa335785db1a2f97d3f3831c16c09f8b0
F test/attach.test f320e98bcca68d100cab7666a0c9a93ac5f236bd
F test/attach2.test 3396c012a39ddf7ba6b528d80bd79554168aa115
F test/attach3.test 63013383adc4380af69779f34f4af19bd49f7cbe
F test/attachmalloc.test cdb26c42850f04698377ccec05f5fa89d987837c
F test/auth.test 973ae7274eae32c4453fbbcbd0ec2b80c5b1eeb3
F test/autoinc.test 395fbac8bc158d3599995c73bfb15c418a5429f0
F test/autovacuum.test 9471d58a08b14dc0d2c15b87583c46d1744343d6
F test/autovacuum_crash.test 05a63b8805b20cfba7ace82856ce4ccdda075a31
F test/autovacuum_ioerr.test 9cf27275ca47b72e188a47c53b61b6d583a01d24
F test/autovacuum_ioerr2.test 2f8a3fb31f833fd0ca86ad4ad98913c73e807572
F test/bigfile.test d3744a8821ce9abb8697f2826a3e3d22b719e89f
F test/between.test ca092fa28b665ca92172b182c6c360a92f7ca348
F test/bigfile.test f768fb6078604cefb73dba0690f0115cc60e6305
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
F test/bind.test 04ff6df093ce9b8108f5f450410a60a910f44340
F test/blob.test fc41fe95bdc10da51f0dee73ce86e75ce1d6eb9d
F test/bind.test 3169339a9fb7aaa8244d0ed8651fe6b6796d809c
F test/bindxfer.test 856830e9e5552b9882c9d5c6647f90e25bdae4ac
F test/blob.test 0b4ee6fef7a50685b88d921e2992606999510881
F test/btree.test 8aa7424aeec844df990273fe36447e5d7e407261
F test/btree2.test dbce930b549d5ac883a7d8905c976209ea241db3
F test/btree4.test 3797b4305694c7af6828675b0f4b1424b8ca30e4
F test/btree5.test 8e5ff32c02e685d36516c6499add9375fe1377f2
F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027
F test/btree7.test a6d3b842db22af97dd14b989e90a2fd96066b72f
F test/capi2.test 2bd71f573b32e3ac5b97441a55873eae14eeab0d
F test/capi3.test f50dd4666deba96275f9927fe8ec089a3d8c0efa
F test/btree8.test fadc112bcbd6a0c622d34c813fc8a648eacf8804
F test/busy.test 0271c854738e23ad76e10d4096a698e5af29d211
F test/capi2.test f897209386fb21cfdc9267595e0c667ebaca9164
F test/capi3.test fc8e573467049add3bfaf81f53827e8ff153cf8f
F test/capi3b.test 5b6a66f9f295f79f443b5d3f33187fa5ef6cf336
F test/cast.test 937af85faabdb189b6cd05879977f2469223be59
F test/collate1.test f79736d2ebf5492167ee4d1f4ab4c09dda776b03
F test/collate2.test 224a632ba04907c049804b08162efd234aa7871f
F test/collate3.test 51362bdfb43a72bd2b087d90b2623b0695538e7a
F test/collate4.test b8668612691c4dcf90f67a8df1eeb1544e7fdaf8
F test/collate5.test 581775b94604b7435dc6a5c6e72fbbf7d69e3830
F test/collate3.test 947a77f5b8227e037a7094d0e338a5504f155cc4
F test/collate4.test daf498e294dcd596b961d425c3f2dda117e4717e
F test/collate5.test 8fb4e7e0241839356bd8710f437c32efb47bfff8
F test/collate6.test 6c9470d1606ee3e564675b229653e320c49ec638
F test/conflict.test c5b849b01cfbe0a4f63a90cba6f68e2fe3a75f87
F test/corrupt.test c34304baf2f027e05942af2efeb26844adca9a53
F test/conflict.test 774e10709f5e9a9a7352dc929b856929ec805e58
F test/corrupt.test 18c7a995b1af76a8c8600b996257f2c7b7bff083
F test/corrupt2.test 88342570828f2b8cbbd8369eff3891f5c0bdd5ba
F test/crash.test f38b980a0508655d08c957a6dd27d66bca776504
F test/crash.test 131259005bb5dbe776eba8de99408a493c69c06c
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
F test/date.test ef6c679d0b59502457dbd78ee1c3c085c949c4c4
F test/delete.test fc29491f6a7ac899ce29f4549a104809e245d9a6
F test/date.test 30ca15e608a45d868fd419c901795382efe27020
F test/default.test 252298e42a680146b1dd64f563b95bdf088d94fb
F test/delete.test 33e1670049364fc3604217a6c2eda042a47115ab
F test/delete2.test e382b6a97787197eb8b93dd4ccd37797c3725ea3
F test/diskfull.test e2f6cfd868713ead06dc82b84a4938e868128fc0
F test/delete3.test 555e84a00a99230b7d049d477a324a631126a6ab
F test/diskfull.test d828d72adfc9e2d1a194d25996718c1989152cf9
F test/distinctagg.test 2b89d1c5220d966a30ba4b40430338669301188b
F test/enc.test 7a03417a1051fe8bc6c7641cf4c8c3f7e0066d52
F test/enc2.test af13bb35708413ee86d6dd95032634c5bbfb8466
F test/enc2.test 76c13b8c00beaf95b15c152e95dab51292eb1f0d
F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837
F test/expr.test 54d9d1cc05eb731fa62daa70f2d7163f8a03c54d
F test/fkey1.test 81bb13caaa78f58d7d191d7f535529f7c91d821a
F test/func.test 9a467351e2a50c8846623ac7451d3bc2516b6e6d
F test/expr.test 71b8cba7fe5c228147c93e530e098144565aaa46
F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
F test/func.test 431f8e07a30aadf2a2a0c8c32f918a497bc4331d
F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda
F test/in.test ed134f8d477a6280297ced1646de83cccf8f196d
F test/in.test cead6165aebbe0d451bb2263a307173acfeb6240
F test/index.test 51e01a0928b4b61228917ddd8c6c0e2466547f6f
F test/index2.test 9ad98243fd7fe833795a9cc662f371f0eed4ff4f
F test/index3.test 72bd07b508022db688ec536c460345d24a3912e3
F test/insert.test f39cb2306199c6f9d8959b843c9199d799217055
F test/insert2.test 065f179a21b42f9746b97571b8ad10b092e90913
F test/index3.test f66718cd92ce1216819d47e6a156755e4b2c4ca1
F test/insert.test b0a89e1568fe9890758f8f2b43b68e840e8f1a1a
F test/insert2.test 792ad079f59c7e14cf9397712725224e2112c838
F test/insert3.test c67f0240b1c17e71fa2ed8bb6de064928f549f95
F test/interrupt.test 5b4d8389e6cf2d01b94f87cfd02d9df1073bfb2d
F test/intpkey.test b57cf5236fde1bd8cbc1388fa0c91908f6fd9194
F test/ioerr.test 7eff0a5cb552a6532ccc5c62bb4911127f2c9562
F test/join.test e08471279574487cac0d17fa1ea66aca15c4de7f
F test/interrupt.test 170f87c2819f0e56c76e0a754949ea103d05009c
F test/intpkey.test af4fd826c4784ec5c93b444de07adea0254d0d30
F test/ioerr.test c3f71a60be73404bc5ae344e171b505d9af49320
F test/join.test db3802739fb695bdfa2e88805e3d64ec5ffbebd1
F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
F test/join4.test cc6cafe85e11aacacd0abcd247a46bed251308f8
F test/lastinsert.test b6a1db3e1ce2d3f0d6afe99d445084f543b6feaa
F test/laststmtchanges.test 07cbdabc52407c29e40abc25050f2434f044a6b1
F test/limit.test 270b076f31c5c32f7187de5727e74da4de43e477
F test/lock.test a19aab9a963273fe61c1058e3d1b648d6a0a2425
F test/lock2.test 59c3dd7d9b24d1bf7ec91b2d1541c37e97939d5f
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
F test/join5.test 2646825693a6e066ea89b498176d4a68df45ab68
F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19
F test/lastinsert.test eaa89c6ee1f13062d87139fd32c1e56753d2fd89
F test/laststmtchanges.test 19a6d0c11f7a31dc45465b495f7b845a62cbec17
F test/like.test 145382e6a1f3d2edf266ca7d0236ab1b7c0ba66f
F test/limit.test 39f084f4e5f11e0b984cb517b56867cbf88df156
F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107
F test/lock2.test d83ba79d3c4fffdb5b926c7d8ca7a36c34288a55
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
F test/main.test a60a1d234b5f5784097973bd395514ca56003ef1
F test/malloc.test b7bc72bb1627e09d6003f58de9bcd6e4be839753
F test/main.test 249f139ef2f75710db1b49bb79e8b27767eacae1
F test/malloc.test 666c77a878ce50f5c22b9211ed43e889cabb63a6
F test/malloc2.test 655b972372d2754a3f6c6ed54d7cfd18fde9bd32
F test/memdb.test 1860e060be810bf0775bc57408a5b7c4954bcaea
F test/memleak.test c0af09191af44a7501ec2494fdd079ac538a256c
F test/minmax.test 9429a06f1f93acf76fcacafd17160a4392e88526
F test/misc1.test ff817d3740458884fea535b44821ec7e84700457
F test/misc2.test fc052267d5178367f955538ae34aae1b2f696a92
F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
F test/minmax.test cad887abca5504396718e2cd5729ca40758743e8
F test/misc1.test c991617666991e11513e46cb646fd2e45ae68599
F test/misc2.test 5c699af2fede2694736a9f45aea7e2f052686e15
F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
F test/misc4.test 98e5fb5544aeac6cbbc529c79d4144b0936c22de
F test/misc4.test fbb81c1d520f34deea819a5d94d787d3d38dc35b
F test/misc5.test 24bd03404039ec727028ac9cf7fd9066fd209ec9
F test/misuse.test 1c7fee3c4c0cb4008717ecccf5c72281fac0008e
F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
F test/null.test 69c62daf1630bf54c87bbc7ef2e22012e58d6da8
F test/null.test 012fe5455f4fc3102490b4bad373a674e5741fdd
F test/pager.test 1579e8f07291ae8e24db62ffade5c101c3e76597
F test/pager2.test 49c0f57c7da0b060f0486b85fdd074025caa694e
F test/pager3.test 647f696a9cf7409df00a1e0047c2eb55585a1b85
F test/pagesize.test 1b826d1608fd86d2303aa895b5586052ad07eba1
F test/pragma.test 52e4ba758004e2200ff153d09c8b92f19bf940bc
F test/printf.test 92ba4c510b4fc61120ffa4a01820446ed917ae57
F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
F test/pagesize.test cbc6a312b6f6c0f02619b189985df2a14164b690
F test/pragma.test 95ea907adf68459e1be6f310c9ae94d1d59c465b
F test/printf.test 9e10c74e16bf889f8495ddb3d6f5f891e75ff1b7
F test/progress.test 16496001da445e6534afb94562c286708316d82f x
F test/quick.test 91e5b8ae6663dc9e3e754b271f0384f0cae706e6
F test/quote.test 6d75cf635d93ba2484dc9cb378d88cbae9dc2c62
F test/quick.test a94d12658a2b590c1a5be580bef09bbb04c1266b
F test/quote.test c1ca5e18800455f1c882baf5b0274755a3836549
F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b
F test/rollback.test 94cd981ee3a627d9f6466f69dcf1f7dbfe695d7a
F test/rowid.test 040a3bef06f970c45f5fcd14b2355f7f4d62f0cf
F test/safety.test 907b64fee719554a3622853812af3886fddbbb4f
F test/schema.test 21cbe7dac652f6d7eb058f3dec369bdbf46bbde6
F test/select1.test ad700a2a1c325a23a7206ad4d189e33917de526f
F test/select2.test 01b9cbc06e5ed662ce0289aa5f47314d54541e82
F test/select3.test 9de435aa84fc406708cd8dc1b1d60e7f27cea685
F test/select1.test 480233d4f5a81d7d59a55e40d05084d97e57ecdf
F test/select2.test f3c2678c3a9f3cf08ec4988a3845bda64be6d9e3
F test/select3.test 576df1a5cc5e01dadae9176384e2d506315afdcf
F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca
F test/select5.test 2d414f712bff8e590091e08f9b7287600731be00
F test/select6.test 6e5a1a70a788cdbe515d1252dd0917d7e9d1d71e
F test/select7.test 8f3362336c10d828ab6fe9c1b8897b484da8b592
F test/sort.test 312eade533cb3c7667110ccfa6e818db1078fd6c
F test/subquery.test 6274cce7617bc7f625490759cbe4f0c0eef24895
F test/subselect.test 3f3f7a940dc3195c3139f4d530385cb54665d614
F test/table.test a2a58cae70ef2511cbf27d40fb8f570106a2677e
F test/select5.test 07a90ab3c7e3f0a241a9cdea1d997b2c8a89ff0b
F test/select6.test 21b72c56e7cbcefd063fdf9bc6c89342aedabccf
F test/select7.test 1bf795b948c133a15a2a5e99d3270e652ec58ce6
F test/sort.test 0c33a8ae1c238377ad197387c3872175f40d3843
F test/subquery.test e6de53332c0301b3cfa34edc3f3cd5fa1e859efd
F test/subselect.test 2d13fb7f450db3595adcdd24079a0dd1d2d6abc2
F test/sync.test d769caaec48456119316775e35e0fdee2fa852d7
F test/table.test ec0e6c2186bb8f6824f470caa118524dfd8fe057
F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1
F test/tclsqlite.test 4b26cad242ef5c634fd52e0465c723d9e0c00901
F test/temptable.test 63a16e3ad19adf073cfbcdf7624c92ac5236522c
F test/tester.tcl 69c0dc1accaf0ff26bff62b33e13590a4ecba17d
F test/tclsqlite.test 2da3e4b3a79b13c1511c9d0cd995e08f8362e782
F test/temptable.test 7927261befdbc7b0a7ffebb85ecc70a74fa7b15b
F test/tester.tcl 1e75553d320f5d2720613d8483c934488fc2c56f
F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
F test/threadtest2.c 97a830d53c24c42290501fdfba4a6e5bdd34748b
F test/trace.test a54fa8df0d01cf827289a7659d78959e8fd2f955
F test/trans.test 29645b344d2b9b6792793562b12340177ddd8f96
F test/trigger1.test 9db1a7c91930baa2dc60ce72c7e969900bf2ae8a
F test/trigger2.test cbc8fe3775904d5b49ff26888aa39df7341fae7c
F test/tkt1435.test f768e5415d102fa1d8de3f548469d8fd1b79abd8
F test/tkt1443.test 1e83b6a1e7f6e261682e67106ab3bc05f6c70e90
F test/tkt1444.test 0f0fc1f277691f904dea2abece6db919dcae2351
F test/tkt1449.test f8de8a84ec12ee805ed80055e1209560f8bee4d8
F test/trace.test 9fd28695c463b90c2d32c387a432e01eb26e8ccf
F test/trans.test 10506dc30305cfb8c4098359f7f6f64786f69c5e
F test/trigger1.test 152aed5a1fa90709fe171f2ca501a6b7f7901479
F test/trigger2.test dea71f4b05e22896e72527278bc8ef71b7475bf2
F test/trigger3.test 9102fd3933db294dc654b5aee9edfe9e94f2b9e2
F test/trigger4.test e7c0812b14750754602468f15495260e8c6625e0
F test/trigger4.test 9615207f3746b1f3965113007869e45a895d2497
F test/trigger5.test 619391a3e9fc194081d22cefd830d811e7badf83
F test/trigger6.test 88b4c0c9f67e4244af39627538526bbaf97132f5
F test/trigger6.test 0e411654f122552da6590f0b4e6f781048a4a9b9
F test/trigger7.test 0afa870be2ce1b132cdb85b17a4a4ef45aa8cece
F test/types.test f0a98d10c5ecc9865d19dc94486f9873afc6bb6b
F test/types2.test 81dd1897be8ef4b5b73d0006e6076abe40610de3
F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b
F test/types3.test 5c63c9cdbafe8fcb73a70a0beb0ecb65b7fa061d
F test/unique.test 0253c4227a5dc533e312202ce21ecfad18058d18
F test/update.test 7669ca789d62c258b678e8aa7a22a57eac10f2cf
F test/utf16.test 459c2f5ab80c60092c603630a348c32d6e59c558
F test/vacuum.test 76c4bc4589353d071e81c003a25338d02560474d
F test/utf16.test 5fb019e09601774743858ef7380b6c02103ff120
F test/vacuum.test 5d4857ae2afc9c20d0edb8acc58bdc8d630126a9
F test/vacuum2.test 5d77e98c458bcdbeecc6327de5107179ba1aa095
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
F test/view.test 306cc4342eb03c28de1a92c681836189e03e5af9
F test/where.test ffb790dfda75d977bae7a1f5830351623f76861b
F test/view.test ce0f0ad39fa4a3572acffcf1e634850ee151aae0
F test/where.test ce21f4910ef6a0c08f8172857baecefca20a3b0c
F test/where2.test 503e2e2b6abe14c5c10222e72d08ef84c1bf1ffb
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
F tool/lemon.c 4a3b5ccc76d959b8caa5f127d23a7e14d4470b4e
F tool/lempar.c e8b0eb00a6b905ce2ebd55965ed243574482cd5f
F tool/lemon.c c88936c67f6411608db8fa4254d254f509fa40f6
F tool/lempar.c f0c30abcae762a7d1eb37cd88b2232ab8dd625fb
F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133
F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
F tool/memleak3.tcl b8eb053190e95a55dc188896afb972e8108822d6
F tool/mkkeywordhash.c c54532f08211938e03bb3a831781d950e619bb31
F tool/memleak3.tcl 009da0ea82dc5893edca76cf1a21fb7260e9412e
F tool/mkkeywordhash.c 5263a654e5c9fd8d6e3238fb39c2d5c3126be32f
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
F tool/spaceanal.tcl 184f5e590ccadb0b3d05e252c4e867c214e7ecd2
F tool/spaceanal.tcl 5b47b70b9a0d216ec63a5b5547b3642dd308e53a
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
@@ -235,43 +266,50 @@ F www/arch2b.fig d22a2c9642d584b89d4088b1e51e2bb0f7c04bed
F www/audit.tcl 90e09d580f79c7efec0c7d6f447b7ec5c2dce5c0
F www/autoinc.tcl b357f5ba954b046ee35392ce0f884a2fcfcdea06
F www/c_interface.tcl b51b08591554c16a0c3ef718364a508ac25abc7e
F www/capi3.tcl 9676103393dbf1c313b5618c9da59033f82cd924
F www/capi3ref.tcl c5a3ae75fc3505c034f3c4bbb62ab94cf359ac39
F www/changes.tcl 34c1ddc0920970e2d8f50dbfe7685bdcda66eece
F www/capi3.tcl 7a7cc225fe02eb7ab861a6019b08baa0014409e1
F www/capi3ref.tcl 885f2aa112e2e9b8822753bf2972d5afd0cfeba9
F www/changes.tcl 5f09e69c5498cf388b3158978664db090708ed83
F www/common.tcl de758130d54d95d151ea0d17a2ae5b92e1bb01de
F www/compile.tcl 65b26bdfc964b66c5f0af841718a52f9795ceb05
F www/compile.tcl 276546d7eb445add5a867193bbd80f6919a6b084
F www/conflict.tcl cdd0f4b59b0ba6d61f67e6a38f3ae45853bacb30
F www/copyright-release.html 294e011760c439c44951a6bfecd4c81a1ae359e8
F www/copyright-release.pdf cfca3558fc97095e57c6117d08f1f5b80d95125a
F www/copyright.tcl 82c9670c7ddb0311912ab7fe24703f33c531066c
F www/datatype3.tcl 1d14f70ab73075556b95e76a5c13e5b03f7f6c47
F www/datatype3.tcl 0197a60590da421fc6516dabfa725c3d53ef90d1
F www/datatypes.tcl 7c786d2e8ff434346764534ec015966d17efce60
F www/different.tcl 051086bc273a36808dc08d58ed098611fb53e315
F www/docs.tcl 09e5eccffad783fe65fac87772f5265e9bb64abe
F www/download.tcl 3af00c0e8fd915961707cddb4c2260f5cf59f3c1
F www/different.tcl 81377eb0c8e27d3bdf812bde357281c4c44bec0c
F www/direct1b.gif 32b48b764244817b6b591898dc52a04299a7b8a7
F www/docs.tcl 4e2d716f004cc4c4dae773206ed58f50d4468a87
F www/download.tcl d56a1c30b1c3c18f62926a806179976eb133ce94
F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
F www/faq.tcl 1e348dec52dc0f21f4216fd6918c69c56daa4cfd
F www/faq.tcl eb7fb7b7242ccfec65820f01b94d0d83956236c1
F www/fileformat.tcl 900c95b9633abc3dcfc384d9ddd8eb4876793059
F www/formatchng.tcl bfbf14dbf5181e771d06da7797767b0200b36d8a
F www/index.tcl e04bbdb51ade47d8da32580e9cfcbaa2c17649a9
F www/lang.tcl fad1d8d12b6c4e5185d9ca12c31c5cf7309b615c
F www/formatchng.tcl 053ddb73646701353a5b1c9ca6274d5900739b45
F www/fullscanb.gif f7c94cb227f060511f8909e10f570157263e9a25
F www/index-ex1-x-b.gif f9b1d85c3fa2435cf38b15970c7e3aa1edae23a3
F www/index.tcl 2fff45565fd52fba6746b27eb60ea1d7834042ec
F www/indirect1b1.gif adfca361d2df59e34f9c5cac52a670c2bfc303a1
F www/lang.tcl b04a87ce05cdbd8d356d6b760a9a0b6f6fce927e
F www/lockingv3.tcl f59b19d6c8920a931f096699d6faaf61c05db55f
F www/mingw.tcl d96b451568c5d28545fefe0c80bee3431c73f69c
F www/nulls.tcl ec35193f92485b87b90a994a01d0171b58823fcf
F www/oldnews.tcl 1e4c67ca29b4d9621fca846e75702dd9ae9c9868
F www/omitted.tcl 9f332aea97b47ec53234f4cd9aa4b4a6da8641ec
F www/opcode.tcl dafa030a5a3cc24a2f9fd4cfbfb7d7323d2151b0
F www/oldnews.tcl 1a808d86882621557774bf7741ed81c7f4ef9f19
F www/omitted.tcl 658ebdc83781ac419dc8a08b3f6cf93929023470
F www/opcode.tcl 5bd68059416b223515a680d410a9f7cb6736485f
F www/optimizer.tcl d6812a10269bd0d7c488987aac0ad5036cace9dc
F www/optimizing.tcl f0b2538988d1bbad16cbfe63ec6e8f48c9eb04e5
F www/pragma.tcl f2f507d50755fea3636fbb956048aac4b14ee837
F www/optoverview.tcl 28b6f114a33bfd91bbe3440611ceed6090587211
F www/pragma.tcl 44f7b665ca598ad24724f35991653638a36a6e3f
F www/quickstart.tcl 6f6f694b6139be2d967b1492eb9a6bdf7058aa60
F www/speed.tcl 1f8fb33df0d5bebf29508af763db3ee019c45967
F www/speed.tcl 656ed5be8cc9d536353e1a96927b925634a62933
F www/sqlite.tcl b51fd15f0531a54874de785a9efba323eecd5975
F www/support.tcl 3955da0fd82be68cc5c83d347c05095e80967051
F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl 3e522a06ad41992023c80ca29a048ae2331ca5bd
P 363590d37fd3a2cdfb4c2887b790395dae2fb97e
R 68681a8d527e977dcd4b50066d1a1025
F www/table-ex1b2.gif a588d21a2d88bb2a2ef0431fcc5ed5aa48c0bbc5
F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P d8e74af5b081a074173c470e9f2115be9b095777
R 3ef1bc3892118ec529a39c9be34b97bf
U drh
Z f89ada5b338d6301e641bdf256a6f32b
Z ad60d4c3881558341fdd282b95f7c97a
+1 -1
View File
@@ -1 +1 @@
e9012d917a97a2f62ea58e85afa4879d213558e8
e61382aed45a83ad688a0461948f9cd052a527fa
+2
View File
@@ -21,7 +21,9 @@ for i in *.c; do
done
echo 'EXPORTS' >tclsqlite3.def
echo 'Tclsqlite3_Init' >>tclsqlite3.def
echo 'Tclsqlite_Init' >>tclsqlite3.def
echo 'Sqlite3_Init' >>tclsqlite3.def
echo 'Sqlite_Init' >>tclsqlite3.def
i386-mingw32msvc-dllwrap \
--def tclsqlite3.def -v --export-all \
--driver-name i386-mingw32msvc-gcc \
+37 -5
View File
@@ -24,6 +24,7 @@
# the total library smaller.
#
# Remember the TK_ values from the parse.h file
/^#define TK_/ {
tk[$2] = $3
@@ -32,14 +33,19 @@
# Scan for "case OP_aaaa:" lines in the vdbe.c file
/^case OP_/ {
name = $2
gsub(/:/,"",name)
gsub("\r","",name)
sub(/:/,"",name)
sub("\r","",name)
op[name] = -1
for(i=3; i<NF-2; i++){
for(i=3; i<NF; i++){
if($i=="same" && $(i+1)=="as"){
op[name] = tk[$(i+2)]
sym = $(i+2)
sub(/,/,"",sym)
op[name] = tk[sym]
used[op[name]] = 1
sameas[op[name]] = $(i+2)
sameas[op[name]] = sym
}
if($i=="no-push"){
nopush[name] = 1
}
}
}
@@ -75,4 +81,30 @@ END {
printf "#define %-25s %15d\n", sprintf( "OP_NotUsed_%-3d", i ), i
}
}
# Generate the 10 16-bit bitmasks used by function opcodeUsesStack()
# in vdbeaux.c. See comments in that function for details.
#
nopush[0] = 0 # 0..15
nopush[1] = 0 # 16..31
nopush[2] = 0 # 32..47
nopush[3] = 0 # 48..63
nopush[4] = 0 # 64..79
nopush[5] = 0 # 80..95
nopush[6] = 0 # 96..111
nopush[7] = 0 # 112..127
nopush[8] = 0 # 128..143
nopush[9] = 0 # 144..159
for(name in op){
if( nopush[name] ){
n = op[name]
j = n%16
i = ((n - j)/16)
nopush[i] = nopush[i] + (2^j)
}
}
printf "\n"
for(i=0; i<10; i++){
printf "#define NOPUSH_MASK_%d %d\n", i, nopush[i]
}
}
+4 -2
View File
@@ -75,8 +75,10 @@ cd ..
ORIGIN=`pwd`
cd $srcdir
cd ..
EXCLUDE=`find sqlite -print | grep CVS | sed 's,^, --exclude ,'`
tar czf $ORIGIN/doc/sqlite-$VERS.tar.gz $EXCLUDE sqlite
mv sqlite sqlite-$VERS
EXCLUDE=`find sqlite-$VERS -print | grep CVS | sed 's,^, --exclude ,'`
tar czf $ORIGIN/doc/sqlite-$VERS.tar.gz $EXCLUDE sqlite-$VERS
mv sqlite-$VERS sqlite
cd $ORIGIN
#
+146 -120
View File
@@ -2,7 +2,7 @@
.\" 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"
.TH SQLITE3 1 "Mon Apr 15 23:49:17 2002"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@@ -16,96 +16,126 @@
.\" .sp <n> insert n+1 empty lines
.\" for manpage-specific macros, see man(7)
.SH NAME
sqlite3 \- A command line interface for SQLite verson 3
.B sqlite3
\- A command line interface for SQLite version 3
.SH SYNOPSIS
.B sqlite
.RI [ options ] " filename " [ SQL ]
.SS SUMMARY
.B sqlite3
.RI [ options ]
.RI [ databasefile ]
.RI [ SQL ]
.SH 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.
.B sqlite3
is a terminal-based front-end to the SQLite library that can evaluate
queries interactively and display the results in multiple formats.
.B sqlite3
can also be used within shell scripts and other applications to provide
batch processing features.
.SH DESCRIPTION
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.
To start a
.B sqlite3
interactive session, invoke the
.B sqlite3
command and optionally provide the name of a database file. If the
database file does not exist, it will be created. If the database file
does exist, it will be opened.
For example, to create a new SQLite database named "ex1" with a single
table named "tbl1", you might do this:
For example, to create a new database file named "mydata.db", create
a table named "memos" and insert a couple of records into that table:
.sp
.nf
$ sqlite3 ex1
SQLite version 3.0.8
$
.B sqlite3 mydata.db
.br
SQLite version 3.1.3
.br
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
.br
sqlite>
.B create table memos(text, priority INTEGER);
.br
sqlite>
.B insert into memos values('deliver project description', 10);
.br
sqlite>
.B insert into memos values('lunch with Christine', 100);
.br
sqlite>
.B select * from memos;
.br
deliver project description|10
.br
lunch with Christine|100
.br
sqlite>
.sp
.fi
If no database name is supplied, the ATTACH sql command can be used
to attach to existing or create new database files. ATTACH can also
be used to attach to multiple databases within the same interactive
session. This is useful for migrating data between databases,
possibly changing the schema along the way.
Optionally, a SQL statement or set of SQL statements can be supplied as
a single argument. Multiple statements should be separated by
semi-colons.
For example:
.sp
$
.B sqlite3 -line mydata.db 'select * from memos where priority > 20;'
.br
text = lunch with Christine
.br
priority = 100
.br
.sp
.SS SQLITE META-COMMANDS
.PP
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.
The interactive interpreter offers a set of meta-commands that can be
used to control the output format, examine the currently attached
database files, or perform administrative operations upon the
attached databases (such as rebuilding indices). Meta-commands are
always prefixed with a dot (.).
For a listing of the available dot commands, you can enter ".help" at
any time. For example:
A list of available meta-commands can be viewed at any time by issuing
the '.help' command. For example:
.sp
sqlite>
.B .help
.nf
.cc |
sqlite> .help
.dump ?TABLE? ... Dump the database in an text format
.databases List names and files of attached databases
.dump ?TABLE? ... Dump the database in an SQL text format
.echo ON|OFF Turn command echo on or off
.exit Exit this program
.explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
"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
.import FILE TABLE Import data from FILE into TABLE
.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
.mode MODE ?TABLE? Set output mode where MODE is one of:
csv Comma-separated values
column Left-aligned columns. (See .width)
html HTML <table> code
insert SQL insert statements for TABLE
line One value per line
list Values delimited by .separator string
tabs Tab-separated values
tcl TCL list elements
.nullvalue STRING Print STRING in place of NULL values
.output FILENAME Send output to FILENAME
.output stdout Send output to the screen
.prompt MAIN CONTINUE Replace the standard prompts
"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
.separator STRING Change separator used by output mode and .import
.show Show the current values for various settings
.tables ?PATTERN? List names of tables matching a LIKE pattern
.timeout MS Try opening locked tables for MS milliseconds
.width NUM NUM ... Set column widths for "column" mode
sqlite>
@@ -114,59 +144,59 @@ sqlite>
.fi
.SH OPTIONS
The program has the following options:
.B sqlite3
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.
Read and execute commands from
.I file
, which can contain a mix of SQL statements and meta-commands.
.TP
.B \-echo
Print commands before execution.
.TP
.B \-[no]header
Turn headers on or off.
.TP
.B \-column
Query results will be displayed in a table like form, using
whitespace characters to separate the columns and align the
output.
.TP
.B \-html
Query results will be output as simple HTML tables.
.TP
.B \-line
Query results will be displayed with one value per line, rows
separated by a blank line. Designed to be easily parsed by
scripts or other programs
.TP
.B \-list
Query results will be displayed with the separator (|, by default)
character between each field value. The default.
.TP
.BI \-separator\ separator
Set output field separator. Default is '|'.
.TP
.BI \-nullvalue\ string
Set string used to represent NULL values. Default is ''
(empty string).
.TP
.B \-version
Show SQLite version.
.TP
.B \-help
Show help on options and exit.
.SH 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:
.B sqlite3
reads an initialization file to set the configuration of the
interactive environment. Throughout initialization, any previously
specified setting can be overridden. The sequence of initialization is
as follows:
o The defaults of
o The default configuration is established as follows:
.sp
.nf
@@ -179,25 +209,21 @@ continue prompt = " ...> "
.sp
.fi
are established.
o If the file
.B ~/.sqliterc
exists, it is processed first.
can be found in the user's home directory, it is
read and processed. It should generally only contain meta-commands.
o If 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 the -init option is present, the specified file is processed.
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.
o All other command line options are processed.
.SH SEE ALSO
http://www.hwaci.com/sw/sqlite/
http://www.sqlite.org/
.br
The sqlite-doc package
.SH AUTHOR
This manual page was originally written by Andreas Rottmann
<rotty@debian.org>, for the Debian GNU/Linux system (but may be used
by others).
by others). It was subsequently revised by Bill Bumgarner <bbum@mac.com>.
+6
View File
@@ -39,18 +39,23 @@ sqlite3_create_collation16
sqlite3_create_function
sqlite3_create_function16
sqlite3_data_count
sqlite3_db_handle
sqlite3_errcode
sqlite3_errmsg
sqlite3_errmsg16
sqlite3_exec
sqlite3_expired
sqlite3_finalize
sqlite3_free
sqlite3_free_table
sqlite3_get_autocommit
sqlite3_get_auxdata
sqlite3_get_table
sqlite3_global_recover
sqlite3_interrupt
sqlite3_last_insert_rowid
sqlite3_libversion
sqlite3_libversion_number
sqlite3_mprintf
sqlite3_open
sqlite3_open16
@@ -76,6 +81,7 @@ sqlite3_snprintf
sqlite3_step
sqlite3_total_changes
sqlite3_trace
sqlite3_transfer_bindings
sqlite3_user_data
sqlite3_value_blob
sqlite3_value_bytes
+557
View File
@@ -0,0 +1,557 @@
/*
** 2005 February 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
**
** $Id: alter.c,v 1.8 2005/08/19 19:14:13 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
/*
** The code in this file only exists if we are not omitting the
** ALTER TABLE logic from the build.
*/
#ifndef SQLITE_OMIT_ALTERTABLE
/*
** This function is used by SQL generated to implement the
** ALTER TABLE command. The first argument is the text of a CREATE TABLE or
** CREATE INDEX command. The second is a table name. The table name in
** the CREATE TABLE or CREATE INDEX statement is replaced with the second
** argument and the result returned. Examples:
**
** sqlite_rename_table('CREATE TABLE abc(a, b, c)', 'def')
** -> 'CREATE TABLE def(a, b, c)'
**
** sqlite_rename_table('CREATE INDEX i ON abc(a)', 'def')
** -> 'CREATE INDEX i ON def(a, b, c)'
*/
static void renameTableFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
unsigned char const *zSql = sqlite3_value_text(argv[0]);
unsigned char const *zTableName = sqlite3_value_text(argv[1]);
int token;
Token tname;
char const *zCsr = zSql;
int len = 0;
char *zRet;
/* The principle used to locate the table name in the CREATE TABLE
** statement is that the table name is the first token that is immediatedly
** followed by a left parenthesis - TK_LP.
*/
if( zSql ){
do {
/* Store the token that zCsr points to in tname. */
tname.z = zCsr;
tname.n = len;
/* Advance zCsr to the next token. Store that token type in 'token',
** and it's length in 'len' (to be used next iteration of this loop).
*/
do {
zCsr += len;
len = sqlite3GetToken(zCsr, &token);
} while( token==TK_SPACE );
assert( len>0 );
} while( token!=TK_LP );
zRet = sqlite3MPrintf("%.*s%Q%s", tname.z - zSql, zSql,
zTableName, tname.z+tname.n);
sqlite3_result_text(context, zRet, -1, sqlite3FreeX);
}
}
#ifndef SQLITE_OMIT_TRIGGER
/* This function is used by SQL generated to implement the ALTER TABLE
** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER
** statement. The second is a table name. The table name in the CREATE
** TRIGGER statement is replaced with the second argument and the result
** returned. This is analagous to renameTableFunc() above, except for CREATE
** TRIGGER, not CREATE INDEX and CREATE TABLE.
*/
static void renameTriggerFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
unsigned char const *zSql = sqlite3_value_text(argv[0]);
unsigned char const *zTableName = sqlite3_value_text(argv[1]);
int token;
Token tname;
int dist = 3;
char const *zCsr = zSql;
int len = 0;
char *zRet;
/* The principle used to locate the table name in the CREATE TRIGGER
** statement is that the table name is the first token that is immediatedly
** preceded by either TK_ON or TK_DOT and immediatedly followed by one
** of TK_WHEN, TK_BEGIN or TK_FOR.
*/
if( zSql ){
do {
/* Store the token that zCsr points to in tname. */
tname.z = zCsr;
tname.n = len;
/* Advance zCsr to the next token. Store that token type in 'token',
** and it's length in 'len' (to be used next iteration of this loop).
*/
do {
zCsr += len;
len = sqlite3GetToken(zCsr, &token);
}while( token==TK_SPACE );
assert( len>0 );
/* Variable 'dist' stores the number of tokens read since the most
** recent TK_DOT or TK_ON. This means that when a WHEN, FOR or BEGIN
** token is read and 'dist' equals 2, the condition stated above
** to be met.
**
** Note that ON cannot be a database, table or column name, so
** there is no need to worry about syntax like
** "CREATE TRIGGER ... ON ON.ON BEGIN ..." etc.
*/
dist++;
if( token==TK_DOT || token==TK_ON ){
dist = 0;
}
} while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );
/* Variable tname now contains the token that is the old table-name
** in the CREATE TRIGGER statement.
*/
zRet = sqlite3MPrintf("%.*s%Q%s", tname.z - zSql, zSql,
zTableName, tname.z+tname.n);
sqlite3_result_text(context, zRet, -1, sqlite3FreeX);
}
}
#endif /* !SQLITE_OMIT_TRIGGER */
/*
** Register built-in functions used to help implement ALTER TABLE
*/
void sqlite3AlterFunctions(sqlite3 *db){
static const struct {
char *zName;
signed char nArg;
void (*xFunc)(sqlite3_context*,int,sqlite3_value **);
} aFuncs[] = {
{ "sqlite_rename_table", 2, renameTableFunc},
#ifndef SQLITE_OMIT_TRIGGER
{ "sqlite_rename_trigger", 2, renameTriggerFunc},
#endif
};
int i;
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
SQLITE_UTF8, 0, aFuncs[i].xFunc, 0, 0);
}
}
/*
** Generate the text of a WHERE expression which can be used to select all
** temporary triggers on table pTab from the sqlite_temp_master table. If
** table pTab has no temporary triggers, or is itself stored in the
** temporary database, NULL is returned.
*/
static char *whereTempTriggers(Parse *pParse, Table *pTab){
Trigger *pTrig;
char *zWhere = 0;
char *tmp = 0;
if( pTab->iDb!=1 ){
for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
if( pTrig->iDb==1 ){
if( !zWhere ){
zWhere = sqlite3MPrintf("name=%Q", pTrig->name);
}else{
tmp = zWhere;
zWhere = sqlite3MPrintf("%s OR name=%Q", zWhere, pTrig->name);
sqliteFree(tmp);
}
}
}
}
return zWhere;
}
/*
** Generate code to drop and reload the internal representation of table
** pTab from the database, including triggers and temporary triggers.
** Argument zName is the name of the table in the database schema at
** the time the generated code is executed. This can be different from
** pTab->zName if this function is being called to code part of an
** "ALTER TABLE RENAME TO" statement.
*/
static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
Vdbe *v;
char *zWhere;
int iDb;
#ifndef SQLITE_OMIT_TRIGGER
Trigger *pTrig;
#endif
v = sqlite3GetVdbe(pParse);
if( !v ) return;
iDb = pTab->iDb;
#ifndef SQLITE_OMIT_TRIGGER
/* Drop any table triggers from the internal schema. */
for(pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext){
assert( pTrig->iDb==iDb || pTrig->iDb==1 );
sqlite3VdbeOp3(v, OP_DropTrigger, pTrig->iDb, 0, pTrig->name, 0);
}
#endif
/* Drop the table and index from the internal schema */
sqlite3VdbeOp3(v, OP_DropTable, iDb, 0, pTab->zName, 0);
/* Reload the table, index and permanent trigger schemas. */
zWhere = sqlite3MPrintf("tbl_name=%Q", zName);
if( !zWhere ) return;
sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, zWhere, P3_DYNAMIC);
#ifndef SQLITE_OMIT_TRIGGER
/* Now, if the table is not stored in the temp database, reload any temp
** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined.
*/
if( (zWhere=whereTempTriggers(pParse, pTab)) ){
sqlite3VdbeOp3(v, OP_ParseSchema, 1, 0, zWhere, P3_DYNAMIC);
}
#endif
}
/*
** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
** command.
*/
void sqlite3AlterRenameTable(
Parse *pParse, /* Parser context. */
SrcList *pSrc, /* The table to rename. */
Token *pName /* The new table name. */
){
int iDb; /* Database that contains the table */
char *zDb; /* Name of database iDb */
Table *pTab; /* Table being renamed */
char *zName = 0; /* NULL-terminated version of pName */
sqlite3 *db = pParse->db; /* Database connection */
Vdbe *v;
#ifndef SQLITE_OMIT_TRIGGER
char *zWhere = 0; /* Where clause to locate temp triggers */
#endif
if( sqlite3_malloc_failed ) goto exit_rename_table;
assert( pSrc->nSrc==1 );
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
if( !pTab ) goto exit_rename_table;
iDb = pTab->iDb;
zDb = db->aDb[iDb].zName;
/* Get a NULL terminated version of the new table name. */
zName = sqlite3NameFromToken(pName);
if( !zName ) goto exit_rename_table;
/* Check that a table or index named 'zName' does not already exist
** in database iDb. If so, this is an error.
*/
if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
sqlite3ErrorMsg(pParse,
"there is already another table or index with this name: %s", zName);
goto exit_rename_table;
}
/* Make sure it is not a system table being altered, or a reserved name
** that the table is being renamed to.
*/
if( strlen(pTab->zName)>6 && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ){
sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);
goto exit_rename_table;
}
if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
goto exit_rename_table;
}
#ifndef SQLITE_OMIT_AUTHORIZATION
/* Invoke the authorization callback. */
if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
goto exit_rename_table;
}
#endif
/* Begin a transaction and code the VerifyCookie for database iDb.
** Then modify the schema cookie (since the ALTER TABLE modifies the
** schema).
*/
v = sqlite3GetVdbe(pParse);
if( v==0 ){
goto exit_rename_table;
}
sqlite3BeginWriteOperation(pParse, 0, iDb);
sqlite3ChangeCookie(db, v, iDb);
/* Modify the sqlite_master table to use the new table name. */
sqlite3NestedParse(pParse,
"UPDATE %Q.%s SET "
#ifdef SQLITE_OMIT_TRIGGER
"sql = sqlite_rename_table(sql, %Q), "
#else
"sql = CASE "
"WHEN type = 'trigger' THEN sqlite_rename_trigger(sql, %Q)"
"ELSE sqlite_rename_table(sql, %Q) END, "
#endif
"tbl_name = %Q, "
"name = CASE "
"WHEN type='table' THEN %Q "
"WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
"'sqlite_autoindex_' || %Q || substr(name, %d+18,10) "
"ELSE name END "
"WHERE tbl_name=%Q AND "
"(type='table' OR type='index' OR type='trigger');",
zDb, SCHEMA_TABLE(iDb), zName, zName, zName,
#ifndef SQLITE_OMIT_TRIGGER
zName,
#endif
zName, strlen(pTab->zName), pTab->zName
);
#ifndef SQLITE_OMIT_AUTOINCREMENT
/* If the sqlite_sequence table exists in this database, then update
** it with the new table name.
*/
if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
sqlite3NestedParse(pParse,
"UPDATE %Q.sqlite_sequence set name = %Q WHERE name = %Q",
zDb, zName, pTab->zName);
}
#endif
#ifndef SQLITE_OMIT_TRIGGER
/* If there are TEMP triggers on this table, modify the sqlite_temp_master
** table. Don't do this if the table being ALTERed is itself located in
** the temp database.
*/
if( (zWhere=whereTempTriggers(pParse, pTab)) ){
sqlite3NestedParse(pParse,
"UPDATE sqlite_temp_master SET "
"sql = sqlite_rename_trigger(sql, %Q), "
"tbl_name = %Q "
"WHERE %s;", zName, zName, zWhere);
sqliteFree(zWhere);
}
#endif
/* Drop and reload the internal table schema. */
reloadTableSchema(pParse, pTab, zName);
exit_rename_table:
sqlite3SrcListDelete(pSrc);
sqliteFree(zName);
}
/*
** This function is called after an "ALTER TABLE ... ADD" statement
** has been parsed. Argument pColDef contains the text of the new
** column definition.
**
** The Table structure pParse->pNewTable was extended to include
** the new column during parsing.
*/
void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
Table *pNew; /* Copy of pParse->pNewTable */
Table *pTab; /* Table being altered */
int iDb; /* Database number */
const char *zDb; /* Database name */
const char *zTab; /* Table name */
char *zCol; /* Null-terminated column definition */
Column *pCol; /* The new column */
Expr *pDflt; /* Default value for the new column */
Vdbe *v;
if( pParse->nErr ) return;
pNew = pParse->pNewTable;
assert( pNew );
iDb = pNew->iDb;
zDb = pParse->db->aDb[iDb].zName;
zTab = pNew->zName;
pCol = &pNew->aCol[pNew->nCol-1];
pDflt = pCol->pDflt;
pTab = sqlite3FindTable(pParse->db, zTab, zDb);
assert( pTab );
/* If the default value for the new column was specified with a
** literal NULL, then set pDflt to 0. This simplifies checking
** for an SQL NULL default below.
*/
if( pDflt && pDflt->op==TK_NULL ){
pDflt = 0;
}
/* Check that the new column is not specified as PRIMARY KEY or UNIQUE.
** If there is a NOT NULL constraint, then the default value for the
** column must not be NULL.
*/
if( pCol->isPrimKey ){
sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column");
return;
}
if( pNew->pIndex ){
sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column");
return;
}
if( pCol->notNull && !pDflt ){
sqlite3ErrorMsg(pParse,
"Cannot add a NOT NULL column with default value NULL");
return;
}
/* Ensure the default expression is something that sqlite3ValueFromExpr()
** can handle (i.e. not CURRENT_TIME etc.)
*/
if( pDflt ){
sqlite3_value *pVal;
if( sqlite3ValueFromExpr(pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
/* malloc() has failed */
return;
}
if( !pVal ){
sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default");
return;
}
sqlite3ValueFree(pVal);
}
/* Modify the CREATE TABLE statement. */
zCol = sqliteStrNDup(pColDef->z, pColDef->n);
if( zCol ){
char *zEnd = &zCol[pColDef->n-1];
while( (zEnd>zCol && *zEnd==';') || isspace(*(unsigned char *)zEnd) ){
*zEnd-- = '\0';
}
sqlite3NestedParse(pParse,
"UPDATE %Q.%s SET "
"sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d,length(sql)) "
"WHERE type = 'table' AND name = %Q",
zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1,
zTab
);
sqliteFree(zCol);
}
/* If the default value of the new column is NULL, then set the file
** format to 2. If the default value of the new column is not NULL,
** the file format becomes 3.
*/
if( (v=sqlite3GetVdbe(pParse)) ){
int f = (pDflt?3:2);
/* Only set the file format to $f if it is currently less than $f. */
sqlite3VdbeAddOp(v, OP_ReadCookie, iDb, 1);
sqlite3VdbeAddOp(v, OP_Integer, f, 0);
sqlite3VdbeAddOp(v, OP_Ge, 0, sqlite3VdbeCurrentAddr(v)+3);
sqlite3VdbeAddOp(v, OP_Integer, f, 0);
sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 1);
}
/* Reload the schema of the modified table. */
reloadTableSchema(pParse, pTab, pTab->zName);
}
/*
** This function is called by the parser after the table-name in
** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
** pSrc is the full-name of the table being altered.
**
** This routine makes a (partial) copy of the Table structure
** for the table being altered and sets Parse.pNewTable to point
** to it. Routines called by the parser as the column definition
** is parsed (i.e. sqlite3AddColumn()) add the new Column data to
** the copy. The copy of the Table structure is deleted by tokenize.c
** after parsing is finished.
**
** Routine sqlite3AlterFinishAddColumn() will be called to complete
** coding the "ALTER TABLE ... ADD" statement.
*/
void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
Table *pNew;
Table *pTab;
Vdbe *v;
int iDb;
int i;
int nAlloc;
/* Look up the table being altered. */
assert( pParse->pNewTable==0 );
if( sqlite3_malloc_failed ) goto exit_begin_add_column;
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
if( !pTab ) goto exit_begin_add_column;
/* Make sure this is not an attempt to ALTER a view. */
if( pTab->pSelect ){
sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
goto exit_begin_add_column;
}
assert( pTab->addColOffset>0 );
iDb = pTab->iDb;
/* Put a copy of the Table struct in Parse.pNewTable for the
** sqlite3AddColumn() function and friends to modify.
*/
pNew = (Table *)sqliteMalloc(sizeof(Table));
if( !pNew ) goto exit_begin_add_column;
pParse->pNewTable = pNew;
pNew->nRef = 1;
pNew->nCol = pTab->nCol;
assert( pNew->nCol>0 );
nAlloc = (((pNew->nCol-1)/8)*8)+8;
assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
pNew->aCol = (Column *)sqliteMalloc(sizeof(Column)*nAlloc);
pNew->zName = sqliteStrDup(pTab->zName);
if( !pNew->aCol || !pNew->zName ){
goto exit_begin_add_column;
}
memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
for(i=0; i<pNew->nCol; i++){
Column *pCol = &pNew->aCol[i];
pCol->zName = sqliteStrDup(pCol->zName);
pCol->zType = 0;
pCol->pDflt = 0;
}
pNew->iDb = iDb;
pNew->addColOffset = pTab->addColOffset;
pNew->nRef = 1;
/* Begin a transaction and increment the schema cookie. */
sqlite3BeginWriteOperation(pParse, 0, iDb);
v = sqlite3GetVdbe(pParse);
if( !v ) goto exit_begin_add_column;
sqlite3ChangeCookie(pParse->db, v, iDb);
exit_begin_add_column:
sqlite3SrcListDelete(pSrc);
return;
}
#endif /* SQLITE_ALTER_TABLE */
+386
View File
@@ -0,0 +1,386 @@
/*
** 2005 July 8
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
** @(#) $Id: analyze.c,v 1.9 2005/09/20 17:42:23 drh Exp $
*/
#ifndef SQLITE_OMIT_ANALYZE
#include "sqliteInt.h"
/*
** This routine generates code that opens the sqlite_stat1 table on cursor
** iStatCur.
**
** If the sqlite_stat1 tables does not previously exist, it is created.
** If it does previously exist, all entires associated with table zWhere
** are removed. If zWhere==0 then all entries are removed.
*/
static void openStatTable(
Parse *pParse, /* Parsing context */
int iDb, /* The database we are looking in */
int iStatCur, /* Open the sqlite_stat1 table on this cursor */
const char *zWhere /* Delete entries associated with this table */
){
sqlite3 *db = pParse->db;
Db *pDb;
int iRootPage;
Table *pStat;
Vdbe *v = sqlite3GetVdbe(pParse);
pDb = &db->aDb[iDb];
if( (pStat = sqlite3FindTable(db, "sqlite_stat1", pDb->zName))==0 ){
/* The sqlite_stat1 tables does not exist. Create it.
** Note that a side-effect of the CREATE TABLE statement is to leave
** the rootpage of the new table on the top of the stack. This is
** important because the OpenWrite opcode below will be needing it. */
sqlite3NestedParse(pParse,
"CREATE TABLE %Q.sqlite_stat1(tbl,idx,stat)",
pDb->zName
);
iRootPage = 0; /* Cause rootpage to be taken from top of stack */
}else if( zWhere ){
/* The sqlite_stat1 table exists. Delete all entries associated with
** the table zWhere. */
sqlite3NestedParse(pParse,
"DELETE FROM %Q.sqlite_stat1 WHERE tbl=%Q",
pDb->zName, zWhere
);
iRootPage = pStat->tnum;
}else{
/* The sqlite_stat1 table already exists. Delete all rows. */
iRootPage = pStat->tnum;
sqlite3VdbeAddOp(v, OP_Clear, pStat->tnum, iDb);
}
/* Open the sqlite_stat1 table for writing.
*/
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
sqlite3VdbeAddOp(v, OP_OpenWrite, iStatCur, iRootPage);
sqlite3VdbeAddOp(v, OP_SetNumColumns, iStatCur, 3);
}
/*
** Generate code to do an analysis of all indices associated with
** a single table.
*/
static void analyzeOneTable(
Parse *pParse, /* Parser context */
Table *pTab, /* Table whose indices are to be analyzed */
int iStatCur, /* Cursor that writes to the sqlite_stat1 table */
int iMem /* Available memory locations begin here */
){
Index *pIdx; /* An index to being analyzed */
int iIdxCur; /* Cursor number for index being analyzed */
int nCol; /* Number of columns in the index */
Vdbe *v; /* The virtual machine being built up */
int i; /* Loop counter */
int topOfLoop; /* The top of the loop */
int endOfLoop; /* The end of the loop */
int addr; /* The address of an instruction */
v = sqlite3GetVdbe(pParse);
if( pTab==0 || pTab->pIndex==0 ){
/* Do no analysis for tables that have no indices */
return;
}
#ifndef SQLITE_OMIT_AUTHORIZATION
if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
pParse->db->aDb[pTab->iDb].zName ) ){
return;
}
#endif
iIdxCur = pParse->nTab;
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
/* Open a cursor to the index to be analyzed
*/
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
VdbeComment((v, "# %s", pIdx->zName));
sqlite3VdbeOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum,
(char*)&pIdx->keyInfo, P3_KEYINFO);
nCol = pIdx->nColumn;
if( iMem+nCol*2>=pParse->nMem ){
pParse->nMem = iMem+nCol*2+1;
}
sqlite3VdbeAddOp(v, OP_SetNumColumns, iIdxCur, nCol+1);
/* Memory cells are used as follows:
**
** mem[iMem]: The total number of rows in the table.
** mem[iMem+1]: Number of distinct values in column 1
** ...
** mem[iMem+nCol]: Number of distinct values in column N
** mem[iMem+nCol+1] Last observed value of column 1
** ...
** mem[iMem+nCol+nCol]: Last observed value of column N
**
** Cells iMem through iMem+nCol are initialized to 0. The others
** are initialized to NULL.
*/
for(i=0; i<=nCol; i++){
sqlite3VdbeAddOp(v, OP_MemInt, 0, iMem+i);
}
for(i=0; i<nCol; i++){
sqlite3VdbeAddOp(v, OP_MemNull, iMem+nCol+i+1, 0);
}
/* Do the analysis.
*/
endOfLoop = sqlite3VdbeMakeLabel(v);
sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, endOfLoop);
topOfLoop = sqlite3VdbeCurrentAddr(v);
sqlite3VdbeAddOp(v, OP_MemIncr, iMem, 0);
for(i=0; i<nCol; i++){
sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+nCol+i+1, 0);
sqlite3VdbeAddOp(v, OP_Ne, 0x100, 0);
}
sqlite3VdbeAddOp(v, OP_Goto, 0, endOfLoop);
for(i=0; i<nCol; i++){
addr = sqlite3VdbeAddOp(v, OP_MemIncr, iMem+i+1, 0);
sqlite3VdbeChangeP2(v, topOfLoop + 3*i + 3, addr);
sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);
sqlite3VdbeAddOp(v, OP_MemStore, iMem+nCol+i+1, 1);
}
sqlite3VdbeResolveLabel(v, endOfLoop);
sqlite3VdbeAddOp(v, OP_Next, iIdxCur, topOfLoop);
sqlite3VdbeAddOp(v, OP_Close, iIdxCur, 0);
/* Store the results.
**
** The result is a single row of the sqlite_stmt1 table. The first
** two columns are the names of the table and index. The third column
** is a string composed of a list of integer statistics about the
** index. The first integer in the list is the total number of entires
** in the index. There is one additional integer in the list for each
** column of the table. This additional integer is a guess of how many
** rows of the table the index will select. If D is the count of distinct
** values and K is the total number of rows, then the integer is computed
** as:
**
** I = (K+D-1)/D
**
** If K==0 then no entry is made into the sqlite_stat1 table.
** If K>0 then it is always the case the D>0 so division by zero
** is never possible.
*/
sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0);
addr = sqlite3VdbeAddOp(v, OP_IfNot, 0, 0);
sqlite3VdbeAddOp(v, OP_NewRowid, iStatCur, 0);
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0);
sqlite3VdbeOp3(v, OP_String8, 0, 0, " ", 0);
for(i=0; i<nCol; i++){
sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0);
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+i+1, 0);
sqlite3VdbeAddOp(v, OP_Add, 0, 0);
sqlite3VdbeAddOp(v, OP_AddImm, -1, 0);
sqlite3VdbeAddOp(v, OP_MemLoad, iMem+i+1, 0);
sqlite3VdbeAddOp(v, OP_Divide, 0, 0);
if( i==nCol-1 ){
sqlite3VdbeAddOp(v, OP_Concat, nCol*2-1, 0);
}else{
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
}
}
sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "ttt", 0);
sqlite3VdbeAddOp(v, OP_Insert, iStatCur, 0);
sqlite3VdbeJumpHere(v, addr);
}
}
/*
** Generate code that will cause the most recent index analysis to
** be laoded into internal hash tables where is can be used.
*/
static void loadAnalysis(Parse *pParse, int iDb){
Vdbe *v = sqlite3GetVdbe(pParse);
sqlite3VdbeAddOp(v, OP_LoadAnalysis, iDb, 0);
}
/*
** Generate code that will do an analysis of an entire database
*/
static void analyzeDatabase(Parse *pParse, int iDb){
sqlite3 *db = pParse->db;
HashElem *k;
int iStatCur;
int iMem;
sqlite3BeginWriteOperation(pParse, 0, iDb);
iStatCur = pParse->nTab++;
openStatTable(pParse, iDb, iStatCur, 0);
iMem = pParse->nMem;
for(k=sqliteHashFirst(&db->aDb[iDb].tblHash); k; k=sqliteHashNext(k)){
Table *pTab = (Table*)sqliteHashData(k);
analyzeOneTable(pParse, pTab, iStatCur, iMem);
}
loadAnalysis(pParse, iDb);
}
/*
** Generate code that will do an analysis of a single table in
** a database.
*/
static void analyzeTable(Parse *pParse, Table *pTab){
int iDb;
int iStatCur;
assert( pTab!=0 );
iDb = pTab->iDb;
sqlite3BeginWriteOperation(pParse, 0, iDb);
iStatCur = pParse->nTab++;
openStatTable(pParse, iDb, iStatCur, pTab->zName);
analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem);
loadAnalysis(pParse, iDb);
}
/*
** Generate code for the ANALYZE command. The parser calls this routine
** when it recognizes an ANALYZE command.
**
** ANALYZE -- 1
** ANALYZE <database> -- 2
** ANALYZE ?<database>.?<tablename> -- 3
**
** Form 1 causes all indices in all attached databases to be analyzed.
** Form 2 analyzes all indices the single database named.
** Form 3 analyzes all indices associated with the named table.
*/
void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){
sqlite3 *db = pParse->db;
int iDb;
int i;
char *z, *zDb;
Table *pTab;
Token *pTableName;
/* Read the database schema. If an error occurs, leave an error message
** and code in pParse and return NULL. */
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
return;
}
if( pName1==0 ){
/* Form 1: Analyze everything */
for(i=0; i<db->nDb; i++){
if( i==1 ) continue; /* Do not analyze the TEMP database */
analyzeDatabase(pParse, i);
}
}else if( pName2==0 || pName2->n==0 ){
/* Form 2: Analyze the database or table named */
iDb = sqlite3FindDb(db, pName1);
if( iDb>=0 ){
analyzeDatabase(pParse, iDb);
}else{
z = sqlite3NameFromToken(pName1);
pTab = sqlite3LocateTable(pParse, z, 0);
sqliteFree(z);
if( pTab ){
analyzeTable(pParse, pTab);
}
}
}else{
/* Form 3: Analyze the fully qualified table name */
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
if( iDb>=0 ){
zDb = db->aDb[iDb].zName;
z = sqlite3NameFromToken(pTableName);
pTab = sqlite3LocateTable(pParse, z, zDb);
sqliteFree(z);
if( pTab ){
analyzeTable(pParse, pTab);
}
}
}
}
/*
** Used to pass information from the analyzer reader through to the
** callback routine.
*/
typedef struct analysisInfo analysisInfo;
struct analysisInfo {
sqlite3 *db;
const char *zDatabase;
};
/*
** This callback is invoked once for each index when reading the
** sqlite_stat1 table.
**
** argv[0] = name of the index
** argv[1] = results of analysis - on integer for each column
*/
static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){
analysisInfo *pInfo = (analysisInfo*)pData;
Index *pIndex;
int i, c;
unsigned int v;
const char *z;
assert( argc==2 );
if( argv==0 || argv[0]==0 || argv[1]==0 ){
return 0;
}
pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase);
if( pIndex==0 ){
return 0;
}
z = argv[1];
for(i=0; *z && i<=pIndex->nColumn; i++){
v = 0;
while( (c=z[0])>='0' && c<='9' ){
v = v*10 + c - '0';
z++;
}
pIndex->aiRowEst[i] = v;
if( *z==' ' ) z++;
}
return 0;
}
/*
** Load the content of the sqlite_stat1 table into the index hash tables.
*/
void sqlite3AnalysisLoad(sqlite3 *db, int iDb){
analysisInfo sInfo;
HashElem *i;
char *zSql;
/* Clear any prior statistics */
for(i=sqliteHashFirst(&db->aDb[iDb].idxHash); i; i=sqliteHashNext(i)){
Index *pIdx = sqliteHashData(i);
sqlite3DefaultRowEst(pIdx);
}
/* Check to make sure the sqlite_stat1 table existss */
sInfo.db = db;
sInfo.zDatabase = db->aDb[iDb].zName;
if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
return;
}
/* Load new statistics out of the sqlite_stat1 table */
zSql = sqlite3MPrintf("SELECT idx, stat FROM %Q.sqlite_stat1",
sInfo.zDatabase);
sqlite3SafetyOff(db);
sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
sqlite3SafetyOn(db);
sqliteFree(zSql);
}
#endif /* SQLITE_OMIT_ANALYZE */
+34 -20
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.31 2005/01/24 10:25:59 danielk1977 Exp $
** $Id: attach.c,v 1.34 2005/08/20 03:03:04 drh Exp $
*/
#include "sqliteInt.h"
@@ -32,7 +32,8 @@ void sqlite3Attach(
){
Db *aNew;
int rc, i;
char *zFile, *zName;
char *zFile = 0;
char *zName = 0;
sqlite3 *db;
Vdbe *v;
@@ -55,34 +56,40 @@ void sqlite3Attach(
return;
}
zFile = sqlite3NameFromToken(pFilename);;
if( zFile==0 ) return;
zFile = sqlite3NameFromToken(pFilename);
if( zFile==0 ){
goto attach_end;
}
#ifndef SQLITE_OMIT_AUTHORIZATION
if( sqlite3AuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
sqliteFree(zFile);
return;
goto attach_end;
}
#endif /* SQLITE_OMIT_AUTHORIZATION */
zName = sqlite3NameFromToken(pDbname);
if( zName==0 ) return;
if( zName==0 ){
goto attach_end;
}
for(i=0; i<db->nDb; i++){
char *z = db->aDb[i].zName;
if( z && sqlite3StrICmp(z, zName)==0 ){
sqlite3ErrorMsg(pParse, "database %z is already in use", zName);
sqlite3ErrorMsg(pParse, "database %s is already in use", zName);
pParse->rc = SQLITE_ERROR;
sqliteFree(zFile);
return;
goto attach_end;
}
}
if( db->aDb==db->aDbStatic ){
aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );
if( aNew==0 ) return;
if( aNew==0 ){
goto attach_end;
}
memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
}else{
aNew = sqliteRealloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
if( aNew==0 ) return;
if( aNew==0 ){
goto attach_end;
}
}
db->aDb = aNew;
aNew = &db->aDb[db->nDb++];
@@ -92,6 +99,7 @@ void sqlite3Attach(
sqlite3HashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);
sqlite3HashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);
aNew->zName = zName;
zName = 0;
aNew->safety_level = 3;
rc = sqlite3BtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
if( rc ){
@@ -126,7 +134,6 @@ void sqlite3Attach(
}
}
#endif
sqliteFree(zFile);
db->flags &= ~SQLITE_Initialized;
if( pParse->nErr==0 && rc==SQLITE_OK ){
rc = sqlite3ReadSchema(pParse);
@@ -139,11 +146,15 @@ void sqlite3Attach(
db->aDb[i].pBt = 0;
}
sqlite3ResetInternalSchema(db, 0);
if( 0==pParse->nErr ){
pParse->nErr++;
assert( pParse->nErr>0 ); /* Always set by sqlite3ReadSchema() */
if( pParse->rc==SQLITE_OK ){
pParse->rc = SQLITE_ERROR;
}
}
attach_end:
sqliteFree(zFile);
sqliteFree(zName);
}
/*
@@ -158,6 +169,7 @@ void sqlite3Detach(Parse *pParse, Token *pDbname){
sqlite3 *db;
Vdbe *v;
Db *pDb = 0;
char *zName;
v = sqlite3GetVdbe(pParse);
if( !v ) return;
@@ -165,20 +177,22 @@ void sqlite3Detach(Parse *pParse, Token *pDbname){
sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
if( pParse->explain ) return;
db = pParse->db;
zName = sqlite3NameFromToken(pDbname);
if( zName==0 ) return;
for(i=0; i<db->nDb; i++){
pDb = &db->aDb[i];
if( pDb->pBt==0 || pDb->zName==0 ) continue;
if( strlen(pDb->zName)!=pDbname->n ) continue;
if( sqlite3StrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break;
if( pDb->pBt==0 ) continue;
if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
}
if( i>=db->nDb ){
sqlite3ErrorMsg(pParse, "no such database: %T", pDbname);
sqlite3ErrorMsg(pParse, "no such database: %z", zName);
return;
}
if( i<2 ){
sqlite3ErrorMsg(pParse, "cannot detach database %T", pDbname);
sqlite3ErrorMsg(pParse, "cannot detach database %z", zName);
return;
}
sqliteFree(zName);
if( !db->autoCommit ){
sqlite3ErrorMsg(pParse, "cannot DETACH database within transaction");
pParse->rc = SQLITE_ERROR;
+2 -1
View File
@@ -14,7 +14,7 @@
** systems that do not need this facility may omit it by recompiling
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
**
** $Id: auth.c,v 1.21 2005/01/29 08:32:44 danielk1977 Exp $
** $Id: auth.c,v 1.22 2005/07/29 15:36:15 drh Exp $
*/
#include "sqliteInt.h"
@@ -114,6 +114,7 @@ void sqlite3AuthRead(
TriggerStack *pStack; /* The stack of current triggers */
if( db->xAuth==0 ) return;
if( pExpr->op==TK_AS ) return;
assert( pExpr->op==TK_COLUMN );
for(iSrc=0; pTabList && iSrc<pTabList->nSrc; iSrc++){
if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break;
+289 -185
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -13,7 +13,7 @@
** subsystem. See comments in the source code for a detailed description
** of what each interface routine does.
**
** @(#) $Id: btree.h,v 1.62 2005/02/06 02:45:42 drh Exp $
** @(#) $Id: btree.h,v 1.64 2005/08/27 16:36:49 drh Exp $
*/
#ifndef _BTREE_H_
#define _BTREE_H_
@@ -58,6 +58,7 @@ int sqlite3BtreeClose(Btree*);
int sqlite3BtreeSetBusyHandler(Btree*,BusyHandler*);
int sqlite3BtreeSetCacheSize(Btree*,int);
int sqlite3BtreeSetSafetyLevel(Btree*,int);
int sqlite3BtreeSyncDisabled(Btree*);
int sqlite3BtreeSetPageSize(Btree*,int,int);
int sqlite3BtreeGetPageSize(Btree*);
int sqlite3BtreeGetReserve(Btree*);
@@ -73,6 +74,7 @@ int sqlite3BtreeCreateTable(Btree*, int*, int flags);
int sqlite3BtreeIsInTrans(Btree*);
int sqlite3BtreeIsInStmt(Btree*);
int sqlite3BtreeSync(Btree*, const char *zMaster);
int sqlite3BtreeReset(Btree *);
const char *sqlite3BtreeGetFilename(Btree *);
const char *sqlite3BtreeGetDirname(Btree *);
+261 -496
View File
File diff suppressed because it is too large Load Diff
+305
View File
@@ -0,0 +1,305 @@
/*
** 2005 May 23
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences.
**
** $Id: callback.c,v 1.3 2005/08/14 01:20:38 drh Exp $
*/
#include "sqliteInt.h"
/*
** Invoke the 'collation needed' callback to request a collation sequence
** in the database text encoding of name zName, length nName.
** If the collation sequence
*/
static void callCollNeeded(sqlite3 *db, const char *zName, int nName){
assert( !db->xCollNeeded || !db->xCollNeeded16 );
if( nName<0 ) nName = strlen(zName);
if( db->xCollNeeded ){
char *zExternal = sqliteStrNDup(zName, nName);
if( !zExternal ) return;
db->xCollNeeded(db->pCollNeededArg, db, (int)db->enc, zExternal);
sqliteFree(zExternal);
}
#ifndef SQLITE_OMIT_UTF16
if( db->xCollNeeded16 ){
char const *zExternal;
sqlite3_value *pTmp = sqlite3GetTransientValue(db);
sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF8, SQLITE_STATIC);
zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
if( !zExternal ) return;
db->xCollNeeded16(db->pCollNeededArg, db, (int)db->enc, zExternal);
}
#endif
}
/*
** This routine is called if the collation factory fails to deliver a
** collation function in the best encoding but there may be other versions
** of this collation function (for other text encodings) available. Use one
** of these instead if they exist. Avoid a UTF-8 <-> UTF-16 conversion if
** possible.
*/
static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
CollSeq *pColl2;
char *z = pColl->zName;
int n = strlen(z);
int i;
static const u8 aEnc[] = { SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8 };
for(i=0; i<3; i++){
pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, n, 0);
if( pColl2->xCmp!=0 ){
memcpy(pColl, pColl2, sizeof(CollSeq));
return SQLITE_OK;
}
}
return SQLITE_ERROR;
}
/*
** This function is responsible for invoking the collation factory callback
** or substituting a collation sequence of a different encoding when the
** requested collation sequence is not available in the database native
** encoding.
**
** If it is not NULL, then pColl must point to the database native encoding
** collation sequence with name zName, length nName.
**
** The return value is either the collation sequence to be used in database
** db for collation type name zName, length nName, or NULL, if no collation
** sequence can be found.
*/
CollSeq *sqlite3GetCollSeq(
sqlite3* db,
CollSeq *pColl,
const char *zName,
int nName
){
CollSeq *p;
p = pColl;
if( !p ){
p = sqlite3FindCollSeq(db, db->enc, zName, nName, 0);
}
if( !p || !p->xCmp ){
/* No collation sequence of this type for this encoding is registered.
** Call the collation factory to see if it can supply us with one.
*/
callCollNeeded(db, zName, nName);
p = sqlite3FindCollSeq(db, db->enc, zName, nName, 0);
}
if( p && !p->xCmp && synthCollSeq(db, p) ){
p = 0;
}
assert( !p || p->xCmp );
return p;
}
/*
** This routine is called on a collation sequence before it is used to
** check that it is defined. An undefined collation sequence exists when
** a database is loaded that contains references to collation sequences
** that have not been defined by sqlite3_create_collation() etc.
**
** If required, this routine calls the 'collation needed' callback to
** request a definition of the collating sequence. If this doesn't work,
** an equivalent collating sequence that uses a text encoding different
** from the main database is substituted, if one is available.
*/
int sqlite3CheckCollSeq(Parse *pParse, CollSeq *pColl){
if( pColl ){
const char *zName = pColl->zName;
CollSeq *p = sqlite3GetCollSeq(pParse->db, pColl, zName, -1);
if( !p ){
if( pParse->nErr==0 ){
sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName);
}
pParse->nErr++;
return SQLITE_ERROR;
}
}
return SQLITE_OK;
}
/*
** Locate and return an entry from the db.aCollSeq hash table. If the entry
** specified by zName and nName is not found and parameter 'create' is
** true, then create a new entry. Otherwise return NULL.
**
** Each pointer stored in the sqlite3.aCollSeq hash table contains an
** array of three CollSeq structures. The first is the collation sequence
** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be.
**
** Stored immediately after the three collation sequences is a copy of
** the collation sequence name. A pointer to this string is stored in
** each collation sequence structure.
*/
static CollSeq *findCollSeqEntry(
sqlite3 *db,
const char *zName,
int nName,
int create
){
CollSeq *pColl;
if( nName<0 ) nName = strlen(zName);
pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
if( 0==pColl && create ){
pColl = sqliteMalloc( 3*sizeof(*pColl) + nName + 1 );
if( pColl ){
CollSeq *pDel = 0;
pColl[0].zName = (char*)&pColl[3];
pColl[0].enc = SQLITE_UTF8;
pColl[1].zName = (char*)&pColl[3];
pColl[1].enc = SQLITE_UTF16LE;
pColl[2].zName = (char*)&pColl[3];
pColl[2].enc = SQLITE_UTF16BE;
memcpy(pColl[0].zName, zName, nName);
pColl[0].zName[nName] = 0;
pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
/* If a malloc() failure occured in sqlite3HashInsert(), it will
** return the pColl pointer to be deleted (because it wasn't added
** to the hash table).
*/
assert( !pDel || (sqlite3_malloc_failed && pDel==pColl) );
sqliteFree(pDel);
}
}
return pColl;
}
/*
** Parameter zName points to a UTF-8 encoded string nName bytes long.
** Return the CollSeq* pointer for the collation sequence named zName
** for the encoding 'enc' from the database 'db'.
**
** If the entry specified is not found and 'create' is true, then create a
** new entry. Otherwise return NULL.
*/
CollSeq *sqlite3FindCollSeq(
sqlite3 *db,
u8 enc,
const char *zName,
int nName,
int create
){
CollSeq *pColl = findCollSeqEntry(db, zName, nName, create);
assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
if( pColl ) pColl += enc-1;
return pColl;
}
/*
** Locate a user function given a name, a number of arguments and a flag
** indicating whether the function prefers UTF-16 over UTF-8. Return a
** pointer to the FuncDef structure that defines that function, or return
** NULL if the function does not exist.
**
** If the createFlag argument is true, then a new (blank) FuncDef
** structure is created and liked into the "db" structure if a
** no matching function previously existed. When createFlag is true
** and the nArg parameter is -1, then only a function that accepts
** any number of arguments will be returned.
**
** If createFlag is false and nArg is -1, then the first valid
** function found is returned. A function is valid if either xFunc
** or xStep is non-zero.
**
** If createFlag is false, then a function with the required name and
** number of arguments may be returned even if the eTextRep flag does not
** match that requested.
*/
FuncDef *sqlite3FindFunction(
sqlite3 *db, /* An open database */
const char *zName, /* Name of the function. Not null-terminated */
int nName, /* Number of characters in the name */
int nArg, /* Number of arguments. -1 means any number */
u8 enc, /* Preferred text encoding */
int createFlag /* Create new entry if true and does not otherwise exist */
){
FuncDef *p; /* Iterator variable */
FuncDef *pFirst; /* First function with this name */
FuncDef *pBest = 0; /* Best match found so far */
int bestmatch = 0;
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
if( nArg<-1 ) nArg = -1;
pFirst = (FuncDef*)sqlite3HashFind(&db->aFunc, zName, nName);
for(p=pFirst; p; p=p->pNext){
/* During the search for the best function definition, bestmatch is set
** as follows to indicate the quality of the match with the definition
** pointed to by pBest:
**
** 0: pBest is NULL. No match has been found.
** 1: A variable arguments function that prefers UTF-8 when a UTF-16
** encoding is requested, or vice versa.
** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is
** requested, or vice versa.
** 3: A variable arguments function using the same text encoding.
** 4: A function with the exact number of arguments requested that
** prefers UTF-8 when a UTF-16 encoding is requested, or vice versa.
** 5: A function with the exact number of arguments requested that
** prefers UTF-16LE when UTF-16BE is requested, or vice versa.
** 6: An exact match.
**
** A larger value of 'matchqual' indicates a more desirable match.
*/
if( p->nArg==-1 || p->nArg==nArg || nArg==-1 ){
int match = 1; /* Quality of this match */
if( p->nArg==nArg || nArg==-1 ){
match = 4;
}
if( enc==p->iPrefEnc ){
match += 2;
}
else if( (enc==SQLITE_UTF16LE && p->iPrefEnc==SQLITE_UTF16BE) ||
(enc==SQLITE_UTF16BE && p->iPrefEnc==SQLITE_UTF16LE) ){
match += 1;
}
if( match>bestmatch ){
pBest = p;
bestmatch = match;
}
}
}
/* If the createFlag parameter is true, and the seach did not reveal an
** exact match for the name, number of arguments and encoding, then add a
** new entry to the hash table and return it.
*/
if( createFlag && bestmatch<6 &&
(pBest = sqliteMalloc(sizeof(*pBest)+nName)) ){
pBest->nArg = nArg;
pBest->pNext = pFirst;
pBest->iPrefEnc = enc;
memcpy(pBest->zName, zName, nName);
pBest->zName[nName] = 0;
if( pBest==sqlite3HashInsert(&db->aFunc,pBest->zName,nName,(void*)pBest) ){
sqliteFree(pBest);
return 0;
}
}
if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){
return pBest;
}
return 0;
}
+263
View File
@@ -0,0 +1,263 @@
/*
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** An tokenizer for SQL
**
** This file contains C code that implements the sqlite3_complete() API.
** This code used to be part of the tokenizer.c source file. But by
** separating it out, the code will be automatically omitted from
** static links that do not use it.
**
** $Id: complete.c,v 1.1 2005/08/14 17:53:21 drh Exp $
*/
#include "sqliteInt.h"
#ifndef SQLITE_OMIT_COMPLETE
/*
** This is defined in tokenize.c. We just have to import the definition.
*/
extern const char sqlite3IsIdChar[];
#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20]))
/*
** Token types used by the sqlite3_complete() routine. See the header
** comments on that procedure for additional information.
*/
#define tkSEMI 0
#define tkWS 1
#define tkOTHER 2
#define tkEXPLAIN 3
#define tkCREATE 4
#define tkTEMP 5
#define tkTRIGGER 6
#define tkEND 7
/*
** Return TRUE if the given SQL string ends in a semicolon.
**
** Special handling is require for CREATE TRIGGER statements.
** Whenever the CREATE TRIGGER keywords are seen, the statement
** must end with ";END;".
**
** This implementation uses a state machine with 7 states:
**
** (0) START At the beginning or end of an SQL statement. This routine
** returns 1 if it ends in the START state and 0 if it ends
** in any other state.
**
** (1) NORMAL We are in the middle of statement which ends with a single
** semicolon.
**
** (2) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
** a statement.
**
** (3) CREATE The keyword CREATE has been seen at the beginning of a
** statement, possibly preceeded by EXPLAIN and/or followed by
** TEMP or TEMPORARY
**
** (4) TRIGGER We are in the middle of a trigger definition that must be
** ended by a semicolon, the keyword END, and another semicolon.
**
** (5) SEMI We've seen the first semicolon in the ";END;" that occurs at
** the end of a trigger definition.
**
** (6) END We've seen the ";END" of the ";END;" that occurs at the end
** of a trigger difinition.
**
** Transitions between states above are determined by tokens extracted
** from the input. The following tokens are significant:
**
** (0) tkSEMI A semicolon.
** (1) tkWS Whitespace
** (2) tkOTHER Any other SQL token.
** (3) tkEXPLAIN The "explain" keyword.
** (4) tkCREATE The "create" keyword.
** (5) tkTEMP The "temp" or "temporary" keyword.
** (6) tkTRIGGER The "trigger" keyword.
** (7) tkEND The "end" keyword.
**
** Whitespace never causes a state transition and is always ignored.
**
** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed
** to recognize the end of a trigger can be omitted. All we have to do
** is look for a semicolon that is not part of an string or comment.
*/
int sqlite3_complete(const char *zSql){
u8 state = 0; /* Current state, using numbers defined in header comment */
u8 token; /* Value of the next token */
#ifndef SQLITE_OMIT_TRIGGER
/* A complex statement machine used to detect the end of a CREATE TRIGGER
** statement. This is the normal case.
*/
static const u8 trans[7][8] = {
/* Token: */
/* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
/* 0 START: */ { 0, 0, 1, 2, 3, 1, 1, 1, },
/* 1 NORMAL: */ { 0, 1, 1, 1, 1, 1, 1, 1, },
/* 2 EXPLAIN: */ { 0, 2, 1, 1, 3, 1, 1, 1, },
/* 3 CREATE: */ { 0, 3, 1, 1, 1, 3, 4, 1, },
/* 4 TRIGGER: */ { 5, 4, 4, 4, 4, 4, 4, 4, },
/* 5 SEMI: */ { 5, 5, 4, 4, 4, 4, 4, 6, },
/* 6 END: */ { 0, 6, 4, 4, 4, 4, 4, 4, },
};
#else
/* If triggers are not suppored by this compile then the statement machine
** used to detect the end of a statement is much simplier
*/
static const u8 trans[2][3] = {
/* Token: */
/* State: ** SEMI WS OTHER */
/* 0 START: */ { 0, 0, 1, },
/* 1 NORMAL: */ { 0, 1, 1, },
};
#endif /* SQLITE_OMIT_TRIGGER */
while( *zSql ){
switch( *zSql ){
case ';': { /* A semicolon */
token = tkSEMI;
break;
}
case ' ':
case '\r':
case '\t':
case '\n':
case '\f': { /* White space is ignored */
token = tkWS;
break;
}
case '/': { /* C-style comments */
if( zSql[1]!='*' ){
token = tkOTHER;
break;
}
zSql += 2;
while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
if( zSql[0]==0 ) return 0;
zSql++;
token = tkWS;
break;
}
case '-': { /* SQL-style comments from "--" to end of line */
if( zSql[1]!='-' ){
token = tkOTHER;
break;
}
while( *zSql && *zSql!='\n' ){ zSql++; }
if( *zSql==0 ) return state==0;
token = tkWS;
break;
}
case '[': { /* Microsoft-style identifiers in [...] */
zSql++;
while( *zSql && *zSql!=']' ){ zSql++; }
if( *zSql==0 ) return 0;
token = tkOTHER;
break;
}
case '`': /* Grave-accent quoted symbols used by MySQL */
case '"': /* single- and double-quoted strings */
case '\'': {
int c = *zSql;
zSql++;
while( *zSql && *zSql!=c ){ zSql++; }
if( *zSql==0 ) return 0;
token = tkOTHER;
break;
}
default: {
int c;
if( IdChar((u8)*zSql) ){
/* Keywords and unquoted identifiers */
int nId;
for(nId=1; IdChar(zSql[nId]); nId++){}
#ifdef SQLITE_OMIT_TRIGGER
token = tkOTHER;
#else
switch( *zSql ){
case 'c': case 'C': {
if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
token = tkCREATE;
}else{
token = tkOTHER;
}
break;
}
case 't': case 'T': {
if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
token = tkTRIGGER;
}else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
token = tkTEMP;
}else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
token = tkTEMP;
}else{
token = tkOTHER;
}
break;
}
case 'e': case 'E': {
if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
token = tkEND;
}else
#ifndef SQLITE_OMIT_EXPLAIN
if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
token = tkEXPLAIN;
}else
#endif
{
token = tkOTHER;
}
break;
}
default: {
token = tkOTHER;
break;
}
}
#endif /* SQLITE_OMIT_TRIGGER */
zSql += nId-1;
}else{
/* Operators and special symbols */
token = tkOTHER;
}
break;
}
}
state = trans[state][token];
zSql++;
}
return state==0;
}
#ifndef SQLITE_OMIT_UTF16
/*
** This routine is the same as the sqlite3_complete() routine described
** above, except that the parameter is required to be UTF-16 encoded, not
** UTF-8.
*/
int sqlite3_complete16(const void *zSql){
sqlite3_value *pVal;
char const *zSql8;
int rc = 0;
pVal = sqlite3ValueNew();
sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
if( zSql8 ){
rc = sqlite3_complete(zSql8);
}
sqlite3ValueFree(pVal);
return rc;
}
#endif /* SQLITE_OMIT_UTF16 */
#endif /* SQLITE_OMIT_COMPLETE */
+4 -8
View File
@@ -16,7 +16,7 @@
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.43 2005/01/15 01:52:32 drh Exp $
** $Id: date.c,v 1.45 2005/06/25 18:42:14 drh Exp $
**
** NOTES:
**
@@ -124,11 +124,7 @@ static int getDigits(const char *zDate, ...){
** Read text from z[] and convert into a floating point number. Return
** the number of digits converted.
*/
static int getValue(const char *z, double *pR){
const char *zEnd;
*pR = sqlite3AtoF(z, &zEnd);
return zEnd - z;
}
#define getValue sqlite3AtoF
/*
** Parse a timezone extension on the end of a date-time.
@@ -272,7 +268,7 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
return 1;
}
zDate += 10;
while( isspace(*(u8*)zDate) ){ zDate++; }
while( isspace(*(u8*)zDate) || 'T'==*(u8*)zDate ){ zDate++; }
if( parseHhMmSs(zDate, p)==0 ){
/* We got the time */
}else if( *zDate==0 ){
@@ -320,7 +316,7 @@ static int parseDateOrTime(const char *zDate, DateTime *p){
p->validJD = 1;
return 0;
}else if( sqlite3IsNumber(zDate, 0, SQLITE_UTF8) ){
p->rJD = sqlite3AtoF(zDate, 0);
getValue(zDate, &p->rJD);
p->validJD = 1;
return 0;
}
+24 -22
View File
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** in order to generate code for DELETE FROM statements.
**
** $Id: delete.c,v 1.100 2005/01/29 08:32:45 danielk1977 Exp $
** $Id: delete.c,v 1.111 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
@@ -27,7 +27,11 @@ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
struct SrcList_item *pItem;
for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
pTab = sqlite3LocateTable(pParse, pItem->zName, pItem->zDatabase);
sqlite3DeleteTable(pParse->db, pItem->pTab);
pItem->pTab = pTab;
if( pTab ){
pTab->nRef++;
}
}
return pTab;
}
@@ -61,8 +65,8 @@ void sqlite3OpenTableForReading(
Table *pTab /* The table to be opened */
){
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
VdbeComment((v, "# %s", pTab->zName));
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
}
@@ -99,7 +103,6 @@ void sqlite3DeleteFrom(
sContext.pParse = 0;
if( pParse->nErr || sqlite3_malloc_failed ){
pTabList = 0;
goto delete_from_cleanup;
}
db = pParse->db;
@@ -175,12 +178,12 @@ void sqlite3DeleteFrom(
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
sqlite3BeginWriteOperation(pParse, triggers_exist, pTab->iDb);
/* If we are trying to delete from a view, construct that view into
** a temporary table.
/* If we are trying to delete from a view, realize that view into
** a ephemeral table.
*/
if( isView ){
Select *pView = sqlite3SelectDup(pTab->pSelect);
sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0);
sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0);
sqlite3SelectDelete(pView);
}
@@ -231,13 +234,13 @@ void sqlite3DeleteFrom(
/* Begin the database scan
*/
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0);
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0);
if( pWInfo==0 ) goto delete_from_cleanup;
/* Remember the rowid of every item to be deleted.
*/
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0);
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0);
if( db->flags & SQLITE_CountRows ){
sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
}
@@ -257,35 +260,34 @@ void sqlite3DeleteFrom(
** database scan. We have to delete items after the scan is complete
** because deleting an item can change the scan order.
*/
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
end = sqlite3VdbeMakeLabel(v);
/* This is the beginning of the delete loop when there are
** row triggers.
*/
if( triggers_exist ){
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end);
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end);
if( !isView ){
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
sqlite3OpenTableForReading(v, iCur, pTab);
}
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0);
if( !isView ){
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
}
(void)sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TRIGGER_BEFORE, pTab,
-1, oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
addr);
addr);
}
if( !isView ){
/* Open cursors for the table we are deleting from and all its
** indices. If there are row triggers, this happens inside the
** OP_ListRead loop because the cursor have to all be closed
** OP_FifoRead loop because the cursor have to all be closed
** before the trigger fires. If there are no row triggers, the
** cursors are opened only once on the outside the loop.
*/
@@ -294,7 +296,7 @@ void sqlite3DeleteFrom(
/* This is the beginning of the delete loop when there are no
** row triggers */
if( !triggers_exist ){
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end);
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end);
}
/* Delete the row */
@@ -313,13 +315,12 @@ void sqlite3DeleteFrom(
}
(void)sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TRIGGER_AFTER, pTab, -1,
oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
addr);
addr);
}
/* End of the delete loop */
sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
sqlite3VdbeResolveLabel(v, end);
sqlite3VdbeAddOp(v, OP_ListReset, 0, 0);
/* Close the cursors after the loop if there are no row triggers */
if( !triggers_exist ){
@@ -379,7 +380,7 @@ void sqlite3GenerateRowDelete(
addr = sqlite3VdbeAddOp(v, OP_NotExists, iCur, 0);
sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, 0);
sqlite3VdbeAddOp(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, addr);
}
/*
@@ -429,15 +430,16 @@ void sqlite3GenerateIndexKey(
int j;
Table *pTab = pIdx->pTable;
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
for(j=0; j<pIdx->nColumn; j++){
int idx = pIdx->aiColumn[j];
if( idx==pTab->iPKey ){
sqlite3VdbeAddOp(v, OP_Dup, j, 0);
}else{
sqlite3VdbeAddOp(v, OP_Column, iCur, idx);
sqlite3ColumnDefault(v, pTab, idx);
}
}
sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24));
sqlite3VdbeAddOp(v, OP_MakeIdxRec, pIdx->nColumn, 0);
sqlite3IndexAffinityStr(v, pIdx);
}
+4 -6
View File
@@ -1,6 +1,5 @@
/*
** 2001 September 15
** 2005 January 20
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
@@ -10,10 +9,10 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
** This file contains C code routines that are not a part of the official
** SQLite API. These routines are unsupported.
**
** $Id: experimental.c,v 1.2 2005/01/20 01:17:44 danielk1977 Exp $
** $Id: experimental.c,v 1.3 2005/03/02 05:18:30 drh Exp $
*/
#include "sqliteInt.h"
@@ -35,4 +34,3 @@ int sqlite3_clear_bindings(sqlite3_stmt *pStmt){
int sqlite3_sleep(int ms){
return sqlite3OsSleep(ms);
}
+377 -297
View File
File diff suppressed because it is too large Load Diff
+130 -207
View File
@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.94 2005/02/09 01:40:25 danielk1977 Exp $
** $Id: func.c,v 1.110 2005/09/08 20:37:43 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -26,6 +26,9 @@
#include "vdbeInt.h"
#include "os.h"
/*
** Return the collating function associated with a function.
*/
static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
return context->pColl;
}
@@ -78,6 +81,7 @@ static void typeofFunc(
sqlite3_result_text(context, z, -1, SQLITE_STATIC);
}
/*
** Implementation of the length() function
*/
@@ -183,7 +187,7 @@ static void substrFunc(
static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
int n = 0;
double r;
char zBuf[100];
char zBuf[500]; /* larger than the %f representation of the largest double */
assert( argc==1 || argc==2 );
if( argc==2 ){
if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return;
@@ -193,7 +197,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
}
if( SQLITE_NULL==sqlite3_value_type(argv[0]) ) return;
r = sqlite3_value_double(argv[0]);
sprintf(zBuf,"%.*f",n,r);
sqlite3_snprintf(sizeof(zBuf),zBuf,"%.*f",n,r);
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
}
@@ -307,8 +311,14 @@ struct compareInfo {
u8 matchSet;
u8 noCase;
};
static const struct compareInfo globInfo = { '*', '?', '[', 0 };
static const struct compareInfo likeInfo = { '%', '_', 0, 1 };
/* The correct SQL-92 behavior is for the LIKE operator to ignore
** case. Thus 'a' LIKE 'A' would be true. */
static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 };
/* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator
** is case sensitive causing 'a' LIKE 'A' to be false */
static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
/*
** X is a pointer to the first byte of a UTF-8 character. Increment
@@ -450,6 +460,15 @@ static int patternCompare(
return *zString==0;
}
/*
** Count the number of times that the LIKE operator (or GLOB which is
** just a variation of LIKE) gets called. This is used for testing
** only.
*/
#ifdef SQLITE_TEST
int sqlite3_like_count = 0;
#endif
/*
** Implementation of the like() SQL function. This function implements
@@ -460,8 +479,8 @@ static int patternCompare(
**
** is implemented as like(B,A).
**
** If the pointer retrieved by via a call to sqlite3_user_data() is
** not NULL, then this function uses UTF-16. Otherwise UTF-8.
** This same function (with a different compareInfo structure) computes
** the GLOB operator.
*/
static void likeFunc(
sqlite3_context *context,
@@ -484,24 +503,11 @@ static void likeFunc(
escape = sqlite3ReadUtf8(zEsc);
}
if( zA && zB ){
sqlite3_result_int(context, patternCompare(zA, zB, &likeInfo, escape));
}
}
/*
** 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(B,A).
*/
static void globFunc(sqlite3_context *context, int arg, sqlite3_value **argv){
const unsigned char *zA = sqlite3_value_text(argv[0]);
const unsigned char *zB = sqlite3_value_text(argv[1]);
if( zA && zB ){
sqlite3_result_int(context, patternCompare(zA, zB, &globInfo, 0));
struct compareInfo *pInfo = sqlite3_user_data(context);
#ifdef SQLITE_TEST
sqlite3_like_count++;
#endif
sqlite3_result_int(context, patternCompare(zA, zB, pInfo, escape));
}
}
@@ -533,130 +539,6 @@ static void versionFunc(
sqlite3_result_text(context, sqlite3_version, -1, SQLITE_STATIC);
}
#ifndef SQLITE_OMIT_ALTERTABLE
/*
** This function is used by SQL generated to implement the
** ALTER TABLE command. The first argument is the text of a CREATE TABLE or
** CREATE INDEX command. The second is a table name. The table name in
** the CREATE TABLE or CREATE INDEX statement is replaced with the second
** argument and the result returned. Examples:
**
** sqlite_alter_table('CREATE TABLE abc(a, b, c)', 'def')
** -> 'CREATE TABLE def(a, b, c)'
**
** sqlite_alter_table('CREATE INDEX i ON abc(a)', 'def')
** -> 'CREATE INDEX i ON def(a, b, c)'
*/
static void altertableFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
unsigned char const *zSql = sqlite3_value_text(argv[0]);
unsigned char const *zTableName = sqlite3_value_text(argv[1]);
int token;
Token tname;
char const *zCsr = zSql;
int len = 0;
char *zRet;
/* The principle used to locate the table name in the CREATE TABLE
** statement is that the table name is the first token that is immediatedly
** followed by a left parenthesis - TK_LP.
*/
if( zSql ){
do {
/* Store the token that zCsr points to in tname. */
tname.z = zCsr;
tname.n = len;
/* Advance zCsr to the next token. Store that token type in 'token',
** and it's length in 'len' (to be used next iteration of this loop).
*/
do {
zCsr += len;
len = sqlite3GetToken(zCsr, &token);
} while( token==TK_SPACE );
assert( len>0 );
} while( token!=TK_LP );
zRet = sqlite3MPrintf("%.*s%Q%s", tname.z - zSql, zSql,
zTableName, tname.z+tname.n);
sqlite3_result_text(context, zRet, -1, sqlite3FreeX);
}
}
#endif
#ifndef SQLITE_OMIT_ALTERTABLE
#ifndef SQLITE_OMIT_TRIGGER
/* This function is used by SQL generated to implement the ALTER TABLE
** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER
** statement. The second is a table name. The table name in the CREATE
** TRIGGER statement is replaced with the second argument and the result
** returned. This is analagous to altertableFunc() above, except for CREATE
** TRIGGER, not CREATE INDEX and CREATE TABLE.
*/
static void altertriggerFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
unsigned char const *zSql = sqlite3_value_text(argv[0]);
unsigned char const *zTableName = sqlite3_value_text(argv[1]);
int token;
Token tname;
int dist = 3;
char const *zCsr = zSql;
int len = 0;
char *zRet;
/* The principle used to locate the table name in the CREATE TRIGGER
** statement is that the table name is the first token that is immediatedly
** preceded by either TK_ON or TK_DOT and immediatedly followed by one
** of TK_WHEN, TK_BEGIN or TK_FOR.
*/
if( zSql ){
do {
/* Store the token that zCsr points to in tname. */
tname.z = zCsr;
tname.n = len;
/* Advance zCsr to the next token. Store that token type in 'token',
** and it's length in 'len' (to be used next iteration of this loop).
*/
do {
zCsr += len;
len = sqlite3GetToken(zCsr, &token);
}while( token==TK_SPACE );
assert( len>0 );
/* Variable 'dist' stores the number of tokens read since the most
** recent TK_DOT or TK_ON. This means that when a WHEN, FOR or BEGIN
** token is read and 'dist' equals 2, the condition stated above
** to be met.
**
** Note that ON cannot be a database, table or column name, so
** there is no need to worry about syntax like
** "CREATE TRIGGER ... ON ON.ON BEGIN ..." etc.
*/
dist++;
if( token==TK_DOT || token==TK_ON ){
dist = 0;
}
} while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );
/* Variable tname now contains the token that is the old table-name
** in the CREATE TRIGGER statement.
*/
zRet = sqlite3MPrintf("%.*s%Q%s", tname.z - zSql, zSql,
zTableName, tname.z+tname.n);
sqlite3_result_text(context, zRet, -1, sqlite3FreeX);
}
}
#endif /* !SQLITE_OMIT_TRIGGER */
#endif /* !SQLITE_OMIT_ALTERTABLE */
/*
** EXPERIMENTAL - This is not an official function. The interface may
@@ -937,6 +819,7 @@ typedef struct SumCtx SumCtx;
struct SumCtx {
double sum; /* Sum of terms */
int cnt; /* Number of elements summed */
u8 seenFloat; /* True if there has been any floating point value */
};
/*
@@ -944,21 +827,32 @@ struct SumCtx {
*/
static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){
SumCtx *p;
if( argc<1 ) return;
int type;
assert( argc==1 );
p = sqlite3_aggregate_context(context, sizeof(*p));
if( p && SQLITE_NULL!=sqlite3_value_type(argv[0]) ){
type = sqlite3_value_type(argv[0]);
if( p && type!=SQLITE_NULL ){
p->sum += sqlite3_value_double(argv[0]);
p->cnt++;
if( type==SQLITE_FLOAT ){
p->seenFloat = 1;
}
}
}
static void sumFinalize(sqlite3_context *context){
SumCtx *p;
p = sqlite3_aggregate_context(context, sizeof(*p));
sqlite3_result_double(context, p ? p->sum : 0.0);
p = sqlite3_aggregate_context(context, 0);
if( p && p->cnt>0 ){
if( p->seenFloat ){
sqlite3_result_double(context, p->sum);
}else{
sqlite3_result_int64(context, (i64)p->sum);
}
}
}
static void avgFinalize(sqlite3_context *context){
SumCtx *p;
p = sqlite3_aggregate_context(context, sizeof(*p));
p = sqlite3_aggregate_context(context, 0);
if( p && p->cnt>0 ){
sqlite3_result_double(context, p->sum/(double)p->cnt);
}
@@ -975,33 +869,6 @@ struct StdDevCtx {
int cnt; /* Number of terms counted */
};
#if 0 /* Omit because math library is required */
/*
** Routines used to compute the standard deviation as an aggregate.
*/
static void stdDevStep(sqlite3_context *context, int argc, const char **argv){
StdDevCtx *p;
double x;
if( argc<1 ) return;
p = sqlite3_aggregate_context(context, sizeof(*p));
if( p && argv[0] ){
x = sqlite3AtoF(argv[0], 0);
p->sum += x;
p->sum2 += x*x;
p->cnt++;
}
}
static void stdDevFinalize(sqlite3_context *context){
double rN = sqlite3_aggregate_count(context);
StdDevCtx *p = sqlite3_aggregate_context(context, sizeof(*p));
if( p && p->cnt>1 ){
double rCnt = cnt;
sqlite3_set_result_double(context,
sqrt((p->sum2 - p->sum*p->sum/rCnt)/(rCnt-1.0)));
}
}
#endif
/*
** The following structure keeps track of state information for the
** count() aggregate function.
@@ -1023,20 +890,10 @@ static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){
}
static void countFinalize(sqlite3_context *context){
CountCtx *p;
p = sqlite3_aggregate_context(context, sizeof(*p));
p = sqlite3_aggregate_context(context, 0);
sqlite3_result_int(context, p ? p->n : 0);
}
/*
** This function tracks state information for the min() and max()
** aggregate functions.
*/
typedef struct MinMaxCtx MinMaxCtx;
struct MinMaxCtx {
char *z; /* The best so far */
char zBuf[28]; /* Space that can be used for storage */
};
/*
** Routines to implement min() and max() aggregate functions.
*/
@@ -1071,11 +928,13 @@ static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv)
}
static void minMaxFinalize(sqlite3_context *context){
sqlite3_value *pRes;
pRes = (sqlite3_value *)sqlite3_aggregate_context(context, sizeof(Mem));
if( pRes->flags ){
sqlite3_result_value(context, pRes);
pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0);
if( pRes ){
if( pRes->flags ){
sqlite3_result_value(context, pRes);
}
sqlite3VdbeMemRelease(pRes);
}
sqlite3VdbeMemRelease(pRes);
}
@@ -1113,21 +972,12 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
{ "coalesce", 1, 0, SQLITE_UTF8, 0, 0 },
{ "ifnull", 2, 0, SQLITE_UTF8, 1, ifnullFunc },
{ "random", -1, 0, SQLITE_UTF8, 0, randomFunc },
{ "like", 2, 0, SQLITE_UTF8, 0, likeFunc },
{ "like", 3, 0, SQLITE_UTF8, 0, likeFunc },
{ "glob", 2, 0, SQLITE_UTF8, 0, globFunc },
{ "nullif", 2, 0, SQLITE_UTF8, 1, nullifFunc },
{ "sqlite_version", 0, 0, SQLITE_UTF8, 0, versionFunc},
{ "quote", 1, 0, SQLITE_UTF8, 0, quoteFunc },
{ "last_insert_rowid", 0, 1, SQLITE_UTF8, 0, last_insert_rowid },
{ "changes", 0, 1, SQLITE_UTF8, 0, changes },
{ "total_changes", 0, 1, SQLITE_UTF8, 0, total_changes },
#ifndef SQLITE_OMIT_ALTERTABLE
{ "sqlite_alter_table", 2, 0, SQLITE_UTF8, 0, altertableFunc},
#ifndef SQLITE_OMIT_TRIGGER
{ "sqlite_alter_trigger", 2, 0, SQLITE_UTF8, 0, altertriggerFunc},
#endif
#endif
#ifdef SQLITE_SOUNDEX
{ "soundex", 1, 0, SQLITE_UTF8, 0, soundexFunc},
#endif
@@ -1153,9 +1003,6 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
{ "avg", 1, 0, 0, sumStep, avgFinalize },
{ "count", 0, 0, 0, countStep, countFinalize },
{ "count", 1, 0, 0, countStep, countFinalize },
#if 0
{ "stddev", 1, 0, stdDevStep, stdDevFinalize },
#endif
};
int i;
@@ -1175,6 +1022,9 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
}
}
}
#ifndef SQLITE_OMIT_ALTERTABLE
sqlite3AlterFunctions(db);
#endif
for(i=0; i<sizeof(aAggs)/sizeof(aAggs[0]); i++){
void *pArg = 0;
switch( aAggs[i].argType ){
@@ -1192,4 +1042,77 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
}
}
sqlite3RegisterDateTimeFunctions(db);
#ifdef SQLITE_SSE
sqlite3SseFunctions(db);
#endif
#ifdef SQLITE_CASE_SENSITIVE_LIKE
sqlite3RegisterLikeFunctions(db, 1);
#else
sqlite3RegisterLikeFunctions(db, 0);
#endif
}
/*
** Set the LIKEOPT flag on the 2-argument function with the given name.
*/
static void setLikeOptFlag(sqlite3 *db, const char *zName, int flagVal){
FuncDef *pDef;
pDef = sqlite3FindFunction(db, zName, strlen(zName), 2, SQLITE_UTF8, 0);
if( pDef ){
pDef->flags = flagVal;
}
}
/*
** Register the built-in LIKE and GLOB functions. The caseSensitive
** parameter determines whether or not the LIKE operator is case
** sensitive. GLOB is always case sensitive.
*/
void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
struct compareInfo *pInfo;
if( caseSensitive ){
pInfo = (struct compareInfo*)&likeInfoAlt;
}else{
pInfo = (struct compareInfo*)&likeInfoNorm;
}
sqlite3_create_function(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0);
sqlite3_create_function(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0);
sqlite3_create_function(db, "glob", 2, SQLITE_UTF8,
(struct compareInfo*)&globInfo, likeFunc, 0,0);
setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
setLikeOptFlag(db, "like",
caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
}
/*
** pExpr points to an expression which implements a function. If
** it is appropriate to apply the LIKE optimization to that function
** then set aWc[0] through aWc[2] to the wildcard characters and
** return TRUE. If the function is not a LIKE-style function then
** return FALSE.
*/
int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
FuncDef *pDef;
if( pExpr->op!=TK_FUNCTION ){
return 0;
}
if( pExpr->pList->nExpr!=2 ){
return 0;
}
pDef = sqlite3FindFunction(db, pExpr->token.z, pExpr->token.n, 2,
SQLITE_UTF8, 0);
if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){
return 0;
}
/* The memcpy() statement assumes that the wildcard characters are
** the first three statements in the compareInfo structure. The
** asserts() that follow verify that assumption
*/
memcpy(aWc, pDef->pUserData, 3);
assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
*pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0;
return 1;
}
+47 -51
View File
@@ -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.136 2005/02/08 08:42:28 danielk1977 Exp $
** $Id: insert.c,v 1.143 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
@@ -108,7 +108,7 @@ static int selectReadsTable(Select *p, int iDb, int iTab){
if( p->pSrc==0 ) return 0;
for(i=0, pItem=p->pSrc->a; i<p->pSrc->nSrc; i++, pItem++){
if( pItem->pSelect ){
if( selectReadsTable(p, iDb, iTab) ) return 1;
if( selectReadsTable(pItem->pSelect, iDb, iTab) ) return 1;
}else{
if( pItem->pTab->iDb==iDb && pItem->pTab->tnum==iTab ) return 1;
}
@@ -308,7 +308,7 @@ void sqlite3Insert(
sqlite3VdbeAddOp(v, OP_Column, iCur, 0);
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
sqlite3VdbeAddOp(v, OP_Ne, 28417, base+12);
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
sqlite3VdbeAddOp(v, OP_MemStore, counterRowid, 1);
sqlite3VdbeAddOp(v, OP_Column, iCur, 1);
sqlite3VdbeAddOp(v, OP_MemStore, counterMem, 1);
@@ -363,22 +363,22 @@ void sqlite3Insert(
sqlite3VdbeResolveLabel(v, iInsertBlock);
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
sqlite3TableAffinityStr(v, pTab);
sqlite3VdbeAddOp(v, OP_NewRecno, srcTab, 0);
sqlite3VdbeAddOp(v, OP_NewRowid, srcTab, 0);
sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
sqlite3VdbeAddOp(v, OP_PutIntKey, srcTab, 0);
sqlite3VdbeAddOp(v, OP_Insert, srcTab, 0);
sqlite3VdbeAddOp(v, OP_Return, 0, 0);
/* The following code runs first because the GOTO at the very top
** of the program jumps to it. Create the temporary table, then jump
** back up and execute the SELECT code above.
*/
sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeAddOp(v, OP_OpenTemp, srcTab, 0);
sqlite3VdbeJumpHere(v, iInitCode);
sqlite3VdbeAddOp(v, OP_OpenVirtual, srcTab, 0);
sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, nColumn);
sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop);
sqlite3VdbeResolveLabel(v, iCleanup);
}else{
sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, iInitCode);
}
}else{
/* This is the case if the data for the INSERT is coming from a VALUES
@@ -470,8 +470,7 @@ void sqlite3Insert(
*/
if( db->flags & SQLITE_CountRows ){
iCntMem = pParse->nMem++;
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
sqlite3VdbeAddOp(v, OP_MemStore, iCntMem, 1);
sqlite3VdbeAddOp(v, OP_MemInt, 0, iCntMem);
}
/* Open tables and indices if there are no row triggers */
@@ -547,7 +546,7 @@ void sqlite3Insert(
if( !isView ){
sqlite3TableAffinityStr(v, pTab);
}
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
/* Fire BEFORE or INSTEAD OF triggers */
if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TRIGGER_BEFORE, pTab,
@@ -565,7 +564,7 @@ void sqlite3Insert(
}
/* Push the record number for the new entry onto the stack. The
** record number is a randomly generate integer created by NewRecno
** record number is a randomly generate integer created by NewRowid
** except when the table has an INTEGER PRIMARY KEY column, in which
** case the record number is the same as that column.
*/
@@ -578,15 +577,15 @@ void sqlite3Insert(
}else{
sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr);
}
/* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
/* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
** to generate a unique primary key value.
*/
sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3);
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
sqlite3VdbeAddOp(v, OP_NewRecno, base, counterMem);
sqlite3VdbeAddOp(v, OP_NewRowid, base, counterMem);
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
}else{
sqlite3VdbeAddOp(v, OP_NewRecno, base, counterMem);
sqlite3VdbeAddOp(v, OP_NewRowid, base, counterMem);
}
#ifndef SQLITE_OMIT_AUTOINCREMENT
if( pTab->autoInc ){
@@ -603,7 +602,7 @@ void sqlite3Insert(
** Whenever this column is read, the record number will be substituted
** in its place. So will fill this column with a NULL to avoid
** taking up data space with information that will never be used. */
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
continue;
}
if( pColumn==0 ){
@@ -690,11 +689,11 @@ void sqlite3Insert(
sqlite3VdbeAddOp(v, OP_MemLoad, counterRowid, 0);
sqlite3VdbeAddOp(v, OP_NotNull, -1, base+7);
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
sqlite3VdbeAddOp(v, OP_NewRecno, iCur, 0);
sqlite3VdbeAddOp(v, OP_NewRowid, iCur, 0);
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
sqlite3VdbeAddOp(v, OP_MemLoad, counterMem, 0);
sqlite3VdbeAddOp(v, OP_MakeRecord, 2, 0);
sqlite3VdbeAddOp(v, OP_PutIntKey, iCur, 0);
sqlite3VdbeAddOp(v, OP_Insert, iCur, 0);
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
}
#endif
@@ -713,8 +712,8 @@ void sqlite3Insert(
insert_cleanup:
sqlite3SrcListDelete(pTabList);
if( pList ) sqlite3ExprListDelete(pList);
if( pSelect ) sqlite3SelectDelete(pSelect);
sqlite3ExprListDelete(pList);
sqlite3SelectDelete(pSelect);
sqlite3IdListDelete(pColumn);
}
@@ -724,11 +723,11 @@ insert_cleanup:
** When this routine is called, the stack contains (from bottom to top)
** the following values:
**
** 1. The recno of the row to be updated before the update. This
** 1. The rowid of the row to be updated before the update. This
** value is omitted unless we are doing an UPDATE that involves a
** change to the record number.
**
** 2. The recno of the row after the update.
** 2. The rowid of the row after the update.
**
** 3. The data in the first column of the entry after the update.
**
@@ -736,9 +735,9 @@ insert_cleanup:
**
** N. The data in the last column of the entry after the update.
**
** The old recno shown as entry (1) above is omitted unless both isUpdate
** and recnoChng are 1. isUpdate is true for UPDATEs and false for
** INSERTs and recnoChng is true if the record number is being changed.
** The old rowid shown as entry (1) above is omitted unless both isUpdate
** and rowidChng are 1. isUpdate is true for UPDATEs and false for
** INSERTs and rowidChng is true if the record number is being changed.
**
** The code generated by this routine pushes additional entries onto
** the stack which are the keys for new index entries for the new record.
@@ -802,7 +801,7 @@ void sqlite3GenerateConstraintChecks(
Table *pTab, /* the table into which we are inserting */
int base, /* Index of a read/write cursor pointing at pTab */
char *aIdxUsed, /* Which indices are used. NULL means all are used */
int recnoChng, /* True if the record number will change */
int rowidChng, /* True if the record number will change */
int isUpdate, /* True for UPDATE, False for INSERT */
int overrideError, /* Override onError to this if not OE_Default */
int ignoreDest /* Jump to this label on an OE_Ignore resolution */
@@ -817,8 +816,7 @@ void sqlite3GenerateConstraintChecks(
Index *pIdx;
int seenReplace = 0;
int jumpInst1=0, jumpInst2;
int contAddr;
int hasTwoRecnos = (isUpdate && recnoChng);
int hasTwoRowids = (isUpdate && rowidChng);
v = sqlite3GetVdbe(pParse);
assert( v!=0 );
@@ -857,7 +855,7 @@ void sqlite3GenerateConstraintChecks(
break;
}
case OE_Ignore: {
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
break;
}
@@ -867,7 +865,7 @@ void sqlite3GenerateConstraintChecks(
break;
}
}
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, addr);
}
/* Test all CHECK constraints
@@ -878,7 +876,7 @@ void sqlite3GenerateConstraintChecks(
** of the new record does not previously exist. Except, if this
** is an UPDATE and the primary key is not changing, that is OK.
*/
if( recnoChng ){
if( rowidChng ){
onError = pTab->keyConf;
if( overrideError!=OE_Default ){
onError = overrideError;
@@ -908,7 +906,7 @@ void sqlite3GenerateConstraintChecks(
case OE_Replace: {
sqlite3GenerateRowIndexDelete(pParse->db, v, pTab, base, 0);
if( isUpdate ){
sqlite3VdbeAddOp(v, OP_Dup, nCol+hasTwoRecnos, 1);
sqlite3VdbeAddOp(v, OP_Dup, nCol+hasTwoRowids, 1);
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
}
seenReplace = 1;
@@ -916,15 +914,14 @@ void sqlite3GenerateConstraintChecks(
}
case OE_Ignore: {
assert( seenReplace==0 );
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
break;
}
}
contAddr = sqlite3VdbeCurrentAddr(v);
sqlite3VdbeChangeP2(v, jumpInst2, contAddr);
sqlite3VdbeJumpHere(v, jumpInst2);
if( isUpdate ){
sqlite3VdbeChangeP2(v, jumpInst1, contAddr);
sqlite3VdbeJumpHere(v, jumpInst1);
sqlite3VdbeAddOp(v, OP_Dup, nCol+1, 1);
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
}
@@ -949,7 +946,7 @@ void sqlite3GenerateConstraintChecks(
sqlite3VdbeAddOp(v, OP_Dup, i+extra+nCol-idx, 1);
}
}
jumpInst1 = sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24));
jumpInst1 = sqlite3VdbeAddOp(v, OP_MakeIdxRec, pIdx->nColumn, 0);
sqlite3IndexAffinityStr(v, pIdx);
/* Find out what action to take in case there is an indexing conflict */
@@ -967,7 +964,7 @@ void sqlite3GenerateConstraintChecks(
/* Check to see if the new index entry will be unique */
sqlite3VdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRecnos, 1);
sqlite3VdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRowids, 1);
jumpInst2 = sqlite3VdbeAddOp(v, OP_IsUnique, base+iCur+1, 0);
/* Generate code that executes if the new index entry is not unique */
@@ -1004,26 +1001,24 @@ void sqlite3GenerateConstraintChecks(
}
case OE_Ignore: {
assert( seenReplace==0 );
sqlite3VdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRecnos, 0);
sqlite3VdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRowids, 0);
sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
break;
}
case OE_Replace: {
sqlite3GenerateRowDelete(pParse->db, v, pTab, base, 0);
if( isUpdate ){
sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRecnos, 1);
sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRowids, 1);
sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
}
seenReplace = 1;
break;
}
}
contAddr = sqlite3VdbeCurrentAddr(v);
assert( contAddr<(1<<24) );
#if NULL_DISTINCT_FOR_UNIQUE
sqlite3VdbeChangeP2(v, jumpInst1, contAddr | (1<<24));
sqlite3VdbeJumpHere(v, jumpInst1);
#endif
sqlite3VdbeChangeP2(v, jumpInst2, contAddr);
sqlite3VdbeJumpHere(v, jumpInst2);
}
}
@@ -1031,7 +1026,7 @@ void sqlite3GenerateConstraintChecks(
** This routine generates code to finish the INSERT or UPDATE operation
** that was started by a prior call to sqlite3GenerateConstraintChecks.
** The stack must contain keys for all active indices followed by data
** and the recno for the new entry. This routine creates the new
** and the rowid for the new entry. This routine creates the new
** entries in all indices and in the main table.
**
** The arguments to this routine should be the same as the first six
@@ -1042,7 +1037,7 @@ void sqlite3CompleteInsertion(
Table *pTab, /* the table into which we are inserting */
int base, /* Index of a read/write cursor pointing at pTab */
char *aIdxUsed, /* Which indices are used. NULL means all are used */
int recnoChng, /* True if the record number will change */
int rowidChng, /* True if the record number will change */
int isUpdate, /* True for UPDATE, False for INSERT */
int newIdx /* Index of NEW table for triggers. -1 if none */
){
@@ -1058,7 +1053,7 @@ void sqlite3CompleteInsertion(
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
for(i=nIdx-1; i>=0; i--){
if( aIdxUsed && aIdxUsed[i]==0 ) continue;
sqlite3VdbeAddOp(v, OP_IdxPut, base+i+1, 0);
sqlite3VdbeAddOp(v, OP_IdxInsert, base+i+1, 0);
}
sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
sqlite3TableAffinityStr(v, pTab);
@@ -1066,7 +1061,7 @@ void sqlite3CompleteInsertion(
if( newIdx>=0 ){
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
}
#endif
if( pParse->nested ){
@@ -1074,9 +1069,9 @@ void sqlite3CompleteInsertion(
}else{
pik_flags = (OPFLAG_NCHANGE|(isUpdate?0:OPFLAG_LASTROWID));
}
sqlite3VdbeAddOp(v, OP_PutIntKey, base, pik_flags);
sqlite3VdbeAddOp(v, OP_Insert, base, pik_flags);
if( isUpdate && recnoChng ){
if( isUpdate && rowidChng ){
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
}
}
@@ -1097,11 +1092,12 @@ void sqlite3OpenTableAndIndices(
Vdbe *v = sqlite3GetVdbe(pParse);
assert( v!=0 );
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeAddOp(v, op, base, pTab->tnum);
VdbeComment((v, "# %s", pTab->zName));
sqlite3VdbeAddOp(v, op, base, pTab->tnum);
sqlite3VdbeAddOp(v, OP_SetNumColumns, base, pTab->nCol);
for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
VdbeComment((v, "# %s", pIdx->zName));
sqlite3VdbeOp3(v, op, i+base, pIdx->tnum,
(char*)&pIdx->keyInfo, P3_KEYINFO);
}
+186 -515
View File
@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.280 2005/02/06 02:45:42 drh Exp $
** $Id: main.c,v 1.302 2005/09/17 15:20:27 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -26,346 +26,27 @@
*/
const int sqlite3one = 1;
#ifndef SQLITE_OMIT_GLOBALRECOVER
/*
** Fill the InitData structure with an error message that indicates
** that the database is corrupt.
** Linked list of all open database handles. This is used by the
** sqlite3_global_recover() function. Entries are added to the list
** by openDatabase() and removed by sqlite3_close().
*/
static void corruptSchema(InitData *pData, const char *zExtra){
if( !sqlite3_malloc_failed ){
sqlite3SetString(pData->pzErrMsg, "malformed database schema",
zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0);
}
}
static sqlite3 *pDbList = 0;
#endif
/*
** This is the callback routine for the code that initializes the
** database. See sqlite3Init() below for additional information.
** This routine is also called from the OP_ParseSchema opcode of the VDBE.
**
** Each callback contains the following information:
**
** argv[0] = name of thing being created
** argv[1] = root page number for table or index. NULL for trigger or view.
** argv[2] = SQL text for the CREATE statement.
** argv[3] = "1" for temporary files, "0" for main database, "2" or more
** for auxiliary database files.
**
#ifndef SQLITE_OMIT_UTF16
/*
** Return the transient sqlite3_value object used for encoding conversions
** during SQL compilation.
*/
int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
InitData *pData = (InitData*)pInit;
sqlite3 *db = pData->db;
int iDb;
assert( argc==4 );
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
if( argv[1]==0 || argv[3]==0 ){
corruptSchema(pData, 0);
return 1;
sqlite3_value *sqlite3GetTransientValue(sqlite3 *db){
if( !db->pValue ){
db->pValue = sqlite3ValueNew();
}
iDb = atoi(argv[3]);
assert( iDb>=0 && iDb<db->nDb );
if( argv[2] && argv[2][0] ){
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
** But because db->init.busy is set to 1, no VDBE code is generated
** or executed. All the parser does is build the internal data
** structures that describe the table, index, or view.
*/
char *zErr;
int rc;
assert( db->init.busy );
db->init.iDb = iDb;
db->init.newTnum = atoi(argv[1]);
rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
db->init.iDb = 0;
if( SQLITE_OK!=rc ){
corruptSchema(pData, zErr);
sqlite3_free(zErr);
return rc;
}
}else{
/* If the SQL column is blank it means this is an index that
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
** constraint for a CREATE TABLE. The index should have already
** been created when we processed the CREATE TABLE. All we have
** to do here is record the root page number for that index.
*/
Index *pIndex;
pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
if( pIndex==0 || pIndex->tnum!=0 ){
/* This can occur if there exists an index on a TEMP table which
** has the same name as another index on a permanent index. Since
** the permanent table is hidden by the TEMP table, we can also
** safely ignore the index on the permanent table.
*/
/* Do Nothing */;
}else{
pIndex->tnum = atoi(argv[1]);
}
}
return 0;
}
/*
** Attempt to read the database schema and initialize internal
** data structures for a single database file. The index of the
** database file is given by iDb. iDb==0 is used for the main
** database. iDb==1 should never be used. iDb>=2 is used for
** auxiliary databases. Return one of the SQLITE_ error codes to
** indicate success or failure.
*/
static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
int rc;
BtCursor *curMain;
int size;
Table *pTab;
char const *azArg[5];
char zDbNum[30];
int meta[10];
InitData initData;
char const *zMasterSchema;
char const *zMasterName;
/*
** The master database table has a structure like this
*/
static const char master_schema[] =
"CREATE TABLE sqlite_master(\n"
" type text,\n"
" name text,\n"
" tbl_name text,\n"
" rootpage integer,\n"
" sql text\n"
")"
;
static const char temp_master_schema[] =
"CREATE TEMP TABLE sqlite_temp_master(\n"
" type text,\n"
" name text,\n"
" tbl_name text,\n"
" rootpage integer,\n"
" sql text\n"
")"
;
assert( iDb>=0 && iDb<db->nDb );
/* zMasterSchema and zInitScript are set to point at the master schema
** and initialisation script appropriate for the database being
** initialised. zMasterName is the name of the master table.
*/
if( iDb==1 ){
zMasterSchema = temp_master_schema;
zMasterName = TEMP_MASTER_NAME;
}else{
zMasterSchema = master_schema;
zMasterName = MASTER_NAME;
}
/* Construct the schema tables. */
sqlite3SafetyOff(db);
azArg[0] = zMasterName;
azArg[1] = "1";
azArg[2] = zMasterSchema;
sprintf(zDbNum, "%d", iDb);
azArg[3] = zDbNum;
azArg[4] = 0;
initData.db = db;
initData.pzErrMsg = pzErrMsg;
rc = sqlite3InitCallback(&initData, 4, (char **)azArg, 0);
if( rc!=SQLITE_OK ){
sqlite3SafetyOn(db);
return rc;
}
pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
if( pTab ){
pTab->readOnly = 1;
}
sqlite3SafetyOn(db);
/* Create a cursor to hold the database open
*/
if( db->aDb[iDb].pBt==0 ){
if( iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
return SQLITE_OK;
}
rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain);
if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
return rc;
}
/* Get the database meta information.
**
** Meta values are as follows:
** meta[0] Schema cookie. Changes with each schema change.
** meta[1] File format of schema layer.
** meta[2] Size of the page cache.
** meta[3] Use freelist if 0. Autovacuum if greater than zero.
** meta[4] Db text encoding. 1:UTF-8 3:UTF-16 LE 4:UTF-16 BE
** meta[5] The user cookie. Used by the application.
** meta[6]
** meta[7]
** meta[8]
** meta[9]
**
** Note: The hash defined SQLITE_UTF* symbols in sqliteInt.h correspond to
** the possible values of meta[4].
*/
if( rc==SQLITE_OK ){
int i;
for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){
rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, i+1, (u32 *)&meta[i]);
}
if( rc ){
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
sqlite3BtreeCloseCursor(curMain);
return rc;
}
}else{
memset(meta, 0, sizeof(meta));
}
db->aDb[iDb].schema_cookie = meta[0];
/* If opening a non-empty database, check the text encoding. For the
** main database, set sqlite3.enc to the encoding of the main database.
** For an attached db, it is an error if the encoding is not the same
** as sqlite3.enc.
*/
if( meta[4] ){ /* text encoding */
if( iDb==0 ){
/* If opening the main database, set db->enc. */
db->enc = (u8)meta[4];
db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0);
}else{
/* If opening an attached database, the encoding much match db->enc */
if( meta[4]!=db->enc ){
sqlite3BtreeCloseCursor(curMain);
sqlite3SetString(pzErrMsg, "attached databases must use the same"
" text encoding as main database", (char*)0);
return SQLITE_ERROR;
}
}
}
size = meta[2];
if( size==0 ){ size = MAX_PAGES; }
db->aDb[iDb].cache_size = size;
if( iDb==0 ){
db->file_format = meta[1];
if( db->file_format==0 ){
/* This happens if the database was initially empty */
db->file_format = 1;
}
}
/*
** file_format==1 Version 3.0.0.
*/
if( meta[1]>1 ){
sqlite3BtreeCloseCursor(curMain);
sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0);
return SQLITE_ERROR;
}
sqlite3BtreeSetCacheSize(db->aDb[iDb].pBt, db->aDb[iDb].cache_size);
/* Read the schema information out of the schema tables
*/
assert( db->init.busy );
if( rc==SQLITE_EMPTY ){
/* For an empty database, there is nothing to read */
rc = SQLITE_OK;
}else{
char *zSql;
zSql = sqlite3MPrintf(
"SELECT name, rootpage, sql, '%s' FROM '%q'.%s",
zDbNum, db->aDb[iDb].zName, zMasterName);
sqlite3SafetyOff(db);
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
sqlite3SafetyOn(db);
sqliteFree(zSql);
sqlite3BtreeCloseCursor(curMain);
}
if( sqlite3_malloc_failed ){
sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
rc = SQLITE_NOMEM;
sqlite3ResetInternalSchema(db, 0);
}
if( rc==SQLITE_OK ){
DbSetProperty(db, iDb, DB_SchemaLoaded);
}else{
sqlite3ResetInternalSchema(db, iDb);
}
return rc;
}
/*
** Initialize all database files - the main database file, the file
** used to store temporary tables, and any additional database files
** created using ATTACH statements. Return a success code. If an
** error occurs, write an error message into *pzErrMsg.
**
** After the database is initialized, the SQLITE_Initialized
** bit is set in the flags field of the sqlite structure.
*/
int sqlite3Init(sqlite3 *db, char **pzErrMsg){
int i, rc;
if( db->init.busy ) return SQLITE_OK;
assert( (db->flags & SQLITE_Initialized)==0 );
rc = SQLITE_OK;
db->init.busy = 1;
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
rc = sqlite3InitOne(db, i, pzErrMsg);
if( rc ){
sqlite3ResetInternalSchema(db, i);
}
}
/* Once all the other databases have been initialised, load the schema
** for the TEMP database. This is loaded last, as the TEMP database
** schema may contain references to objects in other databases.
*/
if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
rc = sqlite3InitOne(db, 1, pzErrMsg);
if( rc ){
sqlite3ResetInternalSchema(db, 1);
}
}
db->init.busy = 0;
if( rc==SQLITE_OK ){
db->flags |= SQLITE_Initialized;
sqlite3CommitInternalChanges(db);
}
if( rc!=SQLITE_OK ){
db->flags &= ~SQLITE_Initialized;
}
return rc;
}
/*
** This routine is a no-op if the database schema is already initialised.
** Otherwise, the schema is loaded. An error code is returned.
*/
int sqlite3ReadSchema(Parse *pParse){
int rc = SQLITE_OK;
sqlite3 *db = pParse->db;
if( !db->init.busy ){
if( (db->flags & SQLITE_Initialized)==0 ){
rc = sqlite3Init(db, &pParse->zErrMsg);
}
}
assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized)||db->init.busy );
if( rc!=SQLITE_OK ){
pParse->rc = rc;
pParse->nErr++;
}
return rc;
return db->pValue;
}
#endif
/*
** The version of the library
@@ -450,6 +131,10 @@ int sqlite3_close(sqlite3 *db){
return SQLITE_MISUSE;
}
#ifdef SQLITE_SSE
sqlite3_finalize(db->pFetch);
#endif
/* If there are any outstanding VMs, return SQLITE_BUSY. */
if( db->pVdbe ){
sqlite3Error(db, SQLITE_BUSY,
@@ -501,6 +186,24 @@ int sqlite3_close(sqlite3 *db){
sqlite3ValueFree(db->pErr);
}
#ifndef SQLITE_OMIT_GLOBALRECOVER
{
sqlite3 *pPrev;
sqlite3OsEnterMutex();
pPrev = pDbList;
while( pPrev && pPrev->pNext!=db ){
pPrev = pPrev->pNext;
}
if( pPrev ){
pPrev->pNext = db->pNext;
}else{
assert( pDbList==db );
pDbList = db->pNext;
}
sqlite3OsLeaveMutex();
}
#endif
db->magic = SQLITE_MAGIC_ERROR;
sqliteFree(db);
return SQLITE_OK;
@@ -531,7 +234,6 @@ const char *sqlite3ErrStr(int rc){
case SQLITE_DONE:
case SQLITE_OK: z = "not an error"; break;
case SQLITE_ERROR: z = "SQL logic error or missing database"; break;
case SQLITE_INTERNAL: z = "internal SQLite implementation flaw"; break;
case SQLITE_PERM: z = "access permission denied"; break;
case SQLITE_ABORT: z = "callback requested query abort"; break;
case SQLITE_BUSY: z = "database is locked"; break;
@@ -541,13 +243,11 @@ const char *sqlite3ErrStr(int rc){
case SQLITE_INTERRUPT: z = "interrupted"; break;
case SQLITE_IOERR: z = "disk I/O error"; break;
case SQLITE_CORRUPT: z = "database disk image is malformed"; break;
case SQLITE_NOTFOUND: z = "table or record not found"; break;
case SQLITE_FULL: z = "database is full"; break;
case SQLITE_FULL: z = "database or disk is full"; break;
case SQLITE_CANTOPEN: z = "unable to open database file"; break;
case SQLITE_PROTOCOL: z = "database locking protocol failure"; break;
case SQLITE_EMPTY: z = "table contains no data"; break;
case SQLITE_SCHEMA: z = "database schema has changed"; break;
case SQLITE_TOOBIG: z = "too much data for one table row"; break;
case SQLITE_CONSTRAINT: z = "constraint failed"; break;
case SQLITE_MISMATCH: z = "datatype mismatch"; break;
case SQLITE_MISUSE: z = "library routine called out of sequence";break;
@@ -568,24 +268,25 @@ const char *sqlite3ErrStr(int rc){
** argument.
*/
static int sqliteDefaultBusyCallback(
void *Timeout, /* Maximum amount of time to wait */
void *ptr, /* Database connection */
int count /* Number of times table has been busy */
){
#if SQLITE_MIN_SLEEP_MS==1
static const char delays[] =
{ 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 50, 100};
static const short int totals[] =
{ 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228, 287};
static const u8 delays[] =
{ 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
static const u8 totals[] =
{ 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
# define NDELAY (sizeof(delays)/sizeof(delays[0]))
ptr timeout = (ptr)Timeout;
ptr delay, prior;
int timeout = ((sqlite3 *)ptr)->busyTimeout;
int delay, prior;
if( count <= NDELAY ){
delay = delays[count-1];
prior = totals[count-1];
assert( count>=0 );
if( count < NDELAY ){
delay = delays[count];
prior = totals[count];
}else{
delay = delays[NDELAY-1];
prior = totals[NDELAY-1] + delay*(count-NDELAY-1);
prior = totals[NDELAY-1] + delay*(count-(NDELAY-1));
}
if( prior + delay > timeout ){
delay = timeout - prior;
@@ -594,7 +295,7 @@ static int sqliteDefaultBusyCallback(
sqlite3OsSleep(delay);
return 1;
#else
int timeout = (int)Timeout;
int timeout = ((sqlite3 *)ptr)->busyTimeout;
if( (count+1)*1000 > timeout ){
return 0;
}
@@ -603,6 +304,25 @@ static int sqliteDefaultBusyCallback(
#endif
}
/*
** Invoke the given busy handler.
**
** This routine is called when an operation failed with a lock.
** If this routine returns non-zero, the lock is retried. If it
** returns 0, the operation aborts with an SQLITE_BUSY error.
*/
int sqlite3InvokeBusyHandler(BusyHandler *p){
int rc;
if( p==0 || p->xFunc==0 || p->nBusy<0 ) return 0;
rc = p->xFunc(p->pArg, p->nBusy);
if( rc==0 ){
p->nBusy = -1;
}else{
p->nBusy++;
}
return rc;
}
/*
** This routine sets the busy callback for an Sqlite database to the
** given callback function with the given argument.
@@ -617,6 +337,7 @@ int sqlite3_busy_handler(
}
db->busyHandler.xFunc = xBusy;
db->busyHandler.pArg = pArg;
db->busyHandler.nBusy = 0;
return SQLITE_OK;
}
@@ -653,7 +374,8 @@ void sqlite3_progress_handler(
*/
int sqlite3_busy_timeout(sqlite3 *db, int ms){
if( ms>0 ){
sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)(ptr)ms);
db->busyTimeout = ms;
sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
}else{
sqlite3_busy_handler(db, 0, 0);
}
@@ -749,6 +471,7 @@ int sqlite3_create_function(
p = sqlite3FindFunction(db, zFunctionName, nName, nArg, enc, 1);
if( p==0 ) return SQLITE_NOMEM;
p->flags = 0;
p->xFunc = xFunc;
p->xStep = xStep;
p->xFinalize = xFinal;
@@ -786,13 +509,14 @@ int sqlite3_create_function16(
}
#endif
#ifndef SQLITE_OMIT_TRACE
/*
** Register a trace function. The pArg from the previously registered trace
** is returned.
**
** A NULL trace function means that no tracing is executes. A non-NULL
** trace is a pointer to a function that is invoked at the start of each
** sqlite3_exec().
** SQL statement.
*/
void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
void *pOld = db->pTraceArg;
@@ -800,6 +524,25 @@ void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
db->pTraceArg = pArg;
return pOld;
}
/*
** Register a profile function. The pArg from the previously registered
** profile function is returned.
**
** A NULL profile function means that no profiling is executes. A non-NULL
** profile is a pointer to a function that is invoked at the conclusion of
** each SQL statement that is run.
*/
void *sqlite3_profile(
sqlite3 *db,
void (*xProfile)(void*,const char*,sqlite_uint64),
void *pArg
){
void *pOld = db->pProfileArg;
db->xProfile = xProfile;
db->pProfileArg = pArg;
return pOld;
}
#endif /* SQLITE_OMIT_TRACE */
/*** EXPERIMENTAL ***
**
@@ -825,11 +568,11 @@ void *sqlite3_commit_hook(
** opened and used. If zFilename is the magic name ":memory:" then
** the database is stored in memory (and is thus forgotten as soon as
** the connection is closed.) If zFilename is NULL then the database
** is for temporary use only and is deleted as soon as the connection
** is closed.
** is a "virtual" database for transient use only and is deleted as
** soon as the connection is closed.
**
** A temporary database can be either a disk file (that is automatically
** deleted when the file is closed) or a set of red-black trees held in memory,
** A virtual database can be either a disk file (that is automatically
** deleted when the file is closed) or it an be held entirely in memory,
** depending on the values of the TEMP_STORE compile-time macro and the
** db->temp_store variable, according to the following chart:
**
@@ -960,161 +703,10 @@ int sqlite3_errcode(sqlite3 *db){
return db->errCode;
}
/*
** Check schema cookies in all databases. If any cookie is out
** of date, return 0. If all schema cookies are current, return 1.
*/
static int schemaIsValid(sqlite3 *db){
int iDb;
int rc;
BtCursor *curTemp;
int cookie;
int allOk = 1;
for(iDb=0; allOk && iDb<db->nDb; iDb++){
Btree *pBt;
pBt = db->aDb[iDb].pBt;
if( pBt==0 ) continue;
rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, 0, &curTemp);
if( rc==SQLITE_OK ){
rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&cookie);
if( rc==SQLITE_OK && cookie!=db->aDb[iDb].schema_cookie ){
allOk = 0;
}
sqlite3BtreeCloseCursor(curTemp);
}
}
return allOk;
}
/*
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
*/
int sqlite3_prepare(
sqlite3 *db, /* Database handle. */
const char *zSql, /* UTF-8 encoded SQL statement. */
int nBytes, /* Length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
const char** pzTail /* OUT: End of parsed string */
){
Parse sParse;
char *zErrMsg = 0;
int rc = SQLITE_OK;
if( sqlite3_malloc_failed ){
return SQLITE_NOMEM;
}
assert( ppStmt );
*ppStmt = 0;
if( sqlite3SafetyOn(db) ){
return SQLITE_MISUSE;
}
memset(&sParse, 0, sizeof(sParse));
sParse.db = db;
sqlite3RunParser(&sParse, zSql, &zErrMsg);
if( sqlite3_malloc_failed ){
rc = SQLITE_NOMEM;
sqlite3RollbackAll(db);
sqlite3ResetInternalSchema(db, 0);
db->flags &= ~SQLITE_InTrans;
goto prepare_out;
}
if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
if( sParse.rc!=SQLITE_OK && sParse.checkSchema && !schemaIsValid(db) ){
sParse.rc = SQLITE_SCHEMA;
}
if( sParse.rc==SQLITE_SCHEMA ){
sqlite3ResetInternalSchema(db, 0);
}
if( pzTail ) *pzTail = sParse.zTail;
rc = sParse.rc;
#ifndef SQLITE_OMIT_EXPLAIN
if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
sqlite3VdbeSetNumCols(sParse.pVdbe, 5);
sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC);
}
#endif
prepare_out:
if( sqlite3SafetyOff(db) ){
rc = SQLITE_MISUSE;
}
if( rc==SQLITE_OK ){
*ppStmt = (sqlite3_stmt*)sParse.pVdbe;
}else if( sParse.pVdbe ){
sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
}
if( zErrMsg ){
sqlite3Error(db, rc, "%s", zErrMsg);
sqliteFree(zErrMsg);
}else{
sqlite3Error(db, rc, 0);
}
return rc;
}
#ifndef SQLITE_OMIT_UTF16
/*
** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
*/
int sqlite3_prepare16(
sqlite3 *db, /* Database handle. */
const void *zSql, /* UTF-8 encoded SQL statement. */
int nBytes, /* Length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
const void **pzTail /* OUT: End of parsed string */
){
/* This function currently works by first transforming the UTF-16
** encoded string to UTF-8, then invoking sqlite3_prepare(). The
** tricky bit is figuring out the pointer to return in *pzTail.
*/
char const *zSql8 = 0;
char const *zTail8 = 0;
int rc;
sqlite3_value *pTmp;
if( sqlite3SafetyCheck(db) ){
return SQLITE_MISUSE;
}
pTmp = sqlite3GetTransientValue(db);
sqlite3ValueSetStr(pTmp, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
zSql8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
if( !zSql8 ){
sqlite3Error(db, SQLITE_NOMEM, 0);
return SQLITE_NOMEM;
}
rc = sqlite3_prepare(db, zSql8, -1, ppStmt, &zTail8);
if( zTail8 && pzTail ){
/* If sqlite3_prepare returns a tail pointer, we calculate the
** equivalent pointer into the UTF-16 string by counting the unicode
** characters between zSql8 and zTail8, and then returning a pointer
** the same number of characters into the UTF-16 string.
*/
int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
*pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
}
return rc;
}
#endif /* SQLITE_OMIT_UTF16 */
/*
** This routine does the work of opening a database on behalf of
** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
** is UTF-8 encoded. The fourth argument, "def_enc" is one of the TEXT_*
** macros from sqliteInt.h. If we end up creating a new database file
** (not opening an existing one), the text encoding of the database
** will be set to this value.
** is UTF-8 encoded.
*/
static int openDatabase(
const char *zFilename, /* Database filename UTF-8 encoded */
@@ -1122,6 +714,7 @@ static int openDatabase(
){
sqlite3 *db;
int rc, i;
CollSeq *pColl;
/* Allocate the sqlite data structure */
db = sqliteMalloc( sizeof(sqlite3) );
@@ -1158,6 +751,13 @@ static int openDatabase(
/* Also add a UTF-8 case-insensitive collation sequence. */
sqlite3_create_collation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc);
/* Set flags on the built-in collating sequences */
db->pDfltColl->type = SQLITE_COLL_BINARY;
pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "NOCASE", 6, 0);
if( pColl ){
pColl->type = SQLITE_COLL_NOCASE;
}
/* Open the backend database driver */
rc = sqlite3BtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt);
if( rc!=SQLITE_OK ){
@@ -1165,13 +765,17 @@ static int openDatabase(
db->magic = SQLITE_MAGIC_CLOSED;
goto opendb_out;
}
db->aDb[0].zName = "main";
db->aDb[1].zName = "temp";
/* The default safety_level for the main database is 'full' for the temp
** database it is 'NONE'. This matches the pager layer defaults. */
/* The default safety_level for the main database is 'full'; for the temp
** database it is 'NONE'. This matches the pager layer defaults.
*/
db->aDb[0].zName = "main";
db->aDb[0].safety_level = 3;
#ifndef SQLITE_OMIT_TEMPDB
db->aDb[1].zName = "temp";
db->aDb[1].safety_level = 1;
#endif
/* Register all built-in functions, but do not attempt to read the
** database schema yet. This is delayed until the first time the database
@@ -1186,6 +790,14 @@ opendb_out:
sqlite3Error(db, SQLITE_NOMEM, 0);
}
*ppDb = db;
#ifndef SQLITE_OMIT_GLOBALRECOVER
if( db ){
sqlite3OsEnterMutex();
db->pNext = pDbList;
pDbList = db;
sqlite3OsLeaveMutex();
}
#endif
return sqlite3_errcode(db);
}
@@ -1263,7 +875,7 @@ int sqlite3_reset(sqlite3_stmt *pStmt){
rc = SQLITE_OK;
}else{
rc = sqlite3VdbeReset((Vdbe*)pStmt);
sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0, 0, 0, 0);
sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0, 0, 0);
}
return rc;
}
@@ -1317,7 +929,7 @@ int sqlite3_create_collation(
pColl = sqlite3FindCollSeq(db, (u8)enc, zName, strlen(zName), 1);
if( 0==pColl ){
rc = SQLITE_NOMEM;
rc = SQLITE_NOMEM;
}else{
pColl->xCmp = xCompare;
pColl->pUser = pCtx;
@@ -1387,3 +999,62 @@ int sqlite3_collation_needed16(
return SQLITE_OK;
}
#endif /* SQLITE_OMIT_UTF16 */
#ifndef SQLITE_OMIT_GLOBALRECOVER
/*
** This function is called to recover from a malloc failure that occured
** within SQLite.
**
** This function is *not* threadsafe. Calling this from within a threaded
** application when threads other than the caller have used SQLite is
** dangerous and will almost certainly result in malfunctions.
*/
int sqlite3_global_recover(){
int rc = SQLITE_OK;
if( sqlite3_malloc_failed ){
sqlite3 *db;
int i;
sqlite3_malloc_failed = 0;
for(db=pDbList; db; db=db->pNext ){
sqlite3ExpirePreparedStatements(db);
for(i=0; i<db->nDb; i++){
Btree *pBt = db->aDb[i].pBt;
if( pBt && (rc=sqlite3BtreeReset(pBt)) ){
goto recover_out;
}
}
db->autoCommit = 1;
}
}
recover_out:
if( rc!=SQLITE_OK ){
sqlite3_malloc_failed = 1;
}
return rc;
}
#endif
/*
** Test to see whether or not the database connection is in autocommit
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
** by default. Autocommit is disabled by a BEGIN statement and reenabled
** by the next COMMIT or ROLLBACK.
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
int sqlite3_get_autocommit(sqlite3 *db){
return db->autoCommit;
}
#ifdef SQLITE_DEBUG
/*
** The following routine is subtituted for constant SQLITE_CORRUPT in
** debugging builds. This provides a way to set a breakpoint for when
** corruption is first detected.
*/
int sqlite3Corrupt(void){
return SQLITE_CORRUPT;
}
#endif
+34 -9
View File
@@ -23,7 +23,8 @@
** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
** The MacOS build is designed to use CodeWarrior (tested with v8)
*/
#if !defined(OS_UNIX) && !defined(OS_TEST)
#if !defined(OS_UNIX) && !defined(OS_TEST) && !defined(OS_OTHER)
# define OS_OTHER 0
# ifndef OS_WIN
# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
# define OS_WIN 1
@@ -54,6 +55,21 @@
# include "os_win.h"
#endif
/* os_other.c and os_other.h are not delivered with SQLite. These files
** are place-holders that can be filled in by third-party developers to
** implement backends to their on proprietary operating systems.
*/
#if OS_OTHER
# include "os_other.h"
#endif
/* If the SET_FULLSYNC macro is not defined above, then make it
** a no-op
*/
#ifndef SET_FULLSYNC
# define SET_FULLSYNC(x,y)
#endif
/*
** Temporary files are named starting with this prefix followed by 16 random
** alphanumeric characters, and no file extension. They are stored in the
@@ -145,8 +161,13 @@
** 1GB boundary.
**
*/
#ifndef SQLITE_TEST
#define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
/* #define PENDING_BYTE 0x5400 // Page 22 - for testing */
#else
extern unsigned int sqlite3_pending_byte;
#define PENDING_BYTE sqlite3_pending_byte
#endif
#define RESERVED_BYTE (PENDING_BYTE+1)
#define SHARED_FIRST (PENDING_BYTE+2)
#define SHARED_SIZE 510
@@ -165,18 +186,22 @@ int sqlite3OsClose(OsFile*);
int sqlite3OsRead(OsFile*, void*, int amt);
int sqlite3OsWrite(OsFile*, const void*, int amt);
int sqlite3OsSeek(OsFile*, i64 offset);
int sqlite3OsSync(OsFile*);
int sqlite3OsSync(OsFile*, int);
int sqlite3OsTruncate(OsFile*, i64 size);
int sqlite3OsFileSize(OsFile*, i64 *pSize);
int sqlite3OsRandomSeed(char*);
int sqlite3OsSleep(int ms);
int sqlite3OsCurrentTime(double*);
int sqlite3OsFileModTime(OsFile*, double*);
void sqlite3OsEnterMutex(void);
void sqlite3OsLeaveMutex(void);
char *sqlite3OsFullPathname(const char*);
int sqlite3OsLock(OsFile*, int);
int sqlite3OsUnlock(OsFile*, int);
int sqlite3OsCheckReservedLock(OsFile *id);
/* The interface for file I/O is above. Other miscellaneous functions
** are below */
int sqlite3OsRandomSeed(char*);
int sqlite3OsSleep(int ms);
int sqlite3OsCurrentTime(double*);
void sqlite3OsEnterMutex(void);
void sqlite3OsLeaveMutex(void);
#endif /* _SQLITE_OS_H_ */
+18 -2
View File
@@ -28,6 +28,14 @@
#endif
/*
* When testing, this global variable stores the location of the
* pending-byte in the database file.
*/
#ifdef SQLITE_TEST
unsigned int sqlite3_pending_byte = 0x40000000;
#endif
int sqlite3_os_trace = 0;
#ifdef SQLITE_DEBUG
static int last_page = 0;
@@ -82,6 +90,7 @@ static unsigned int elapse;
#ifdef SQLITE_TEST
int sqlite3_io_error_pending = 0;
int sqlite3_diskfull_pending = 0;
int sqlite3_diskfull = 0;
#define SimulateIOError(A) \
if( sqlite3_io_error_pending ) \
if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
@@ -89,8 +98,15 @@ static void local_ioerr(){
sqlite3_io_error_pending = 0; /* Really just a place to set a breakpoint */
}
#define SimulateDiskfullError \
if( sqlite3_diskfull_pending ) \
if( sqlite3_diskfull_pending-- == 1 ){ local_ioerr(); return SQLITE_FULL; }
if( sqlite3_diskfull_pending ){ \
if( sqlite3_diskfull_pending == 1 ){ \
local_ioerr(); \
sqlite3_diskfull = 1; \
return SQLITE_FULL; \
}else{ \
sqlite3_diskfull_pending--; \
} \
}
#else
#define SimulateIOError(A)
#define SimulateDiskfullError
-463
View File
@@ -1,463 +0,0 @@
/*
** 2004 May 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains code that is specific to Unix systems. It is used
** for testing SQLite only.
*/
#if OS_TEST /* This file is used for the test backend only */
#include "sqliteInt.h"
#include "os.h" /* Must be first to enable large file support */
#define sqlite3OsOpenReadWrite sqlite3RealOpenReadWrite
#define sqlite3OsOpenExclusive sqlite3RealOpenExclusive
#define sqlite3OsOpenReadOnly sqlite3RealOpenReadOnly
#define sqlite3OsOpenDirectory sqlite3RealOpenDirectory
#define sqlite3OsClose sqlite3RealClose
#define sqlite3OsRead sqlite3RealRead
#define sqlite3OsWrite sqlite3RealWrite
#define sqlite3OsSeek sqlite3RealSeek
#define sqlite3OsSync sqlite3RealSync
#define sqlite3OsTruncate sqlite3RealTruncate
#define sqlite3OsFileSize sqlite3RealFileSize
#define sqlite3OsLock sqlite3RealLock
#define sqlite3OsUnlock sqlite3RealUnlock
#define sqlite3OsCheckReservedLock sqlite3RealCheckReservedLock
#define OsFile OsRealFile
#define OS_UNIX 1
#include "os_unix.c"
#undef OS_UNIX
#undef OsFile
#undef sqlite3OsOpenReadWrite
#undef sqlite3OsOpenExclusive
#undef sqlite3OsOpenReadOnly
#undef sqlite3OsOpenDirectory
#undef sqlite3OsClose
#undef sqlite3OsRead
#undef sqlite3OsWrite
#undef sqlite3OsSeek
#undef sqlite3OsSync
#undef sqlite3OsTruncate
#undef sqlite3OsFileSize
#undef sqlite3OsLock
#undef sqlite3OsUnlock
#undef sqlite3OsCheckReservedLock
#define BLOCKSIZE 512
#define BLOCK_OFFSET(x) ((x) * BLOCKSIZE)
/*
** The following variables control when a simulated crash occurs.
**
** If iCrashDelay is non-zero, then zCrashFile contains (full path) name of
** a file that SQLite will call sqlite3OsSync() on. Each time this happens
** iCrashDelay is decremented. If iCrashDelay is zero after being
** decremented, a "crash" occurs during the sync() operation.
**
** In other words, a crash occurs the iCrashDelay'th time zCrashFile is
** synced.
*/
static int iCrashDelay = 0;
char zCrashFile[256];
/*
** Set the value of the two crash parameters.
*/
void sqlite3SetCrashParams(int iDelay, char const *zFile){
sqlite3OsEnterMutex();
assert( strlen(zFile)<256 );
strcpy(zCrashFile, zFile);
iCrashDelay = iDelay;
sqlite3OsLeaveMutex();
}
/*
** File zPath is being sync()ed. Return non-zero if this should
** cause a crash.
*/
static int crashRequired(char const *zPath){
int r;
int n;
sqlite3OsEnterMutex();
n = strlen(zCrashFile);
if( zCrashFile[n-1]=='*' ){
n--;
}else if( strlen(zPath)>n ){
n = strlen(zPath);
}
r = 0;
if( iCrashDelay>0 && strncmp(zPath, zCrashFile, n)==0 ){
iCrashDelay--;
if( iCrashDelay<=0 ){
r = 1;
}
}
sqlite3OsLeaveMutex();
return r;
}
static OsTestFile *pAllFiles = 0;
/*
** Initialise the os_test.c specific fields of pFile.
*/
static void initFile(OsFile *id, char const *zName){
OsTestFile *pFile = (OsTestFile *)
sqliteMalloc(sizeof(OsTestFile) + strlen(zName)+1);
pFile->nMaxWrite = 0;
pFile->nBlk = 0;
pFile->apBlk = 0;
pFile->zName = (char *)(&pFile[1]);
strcpy(pFile->zName, zName);
*id = pFile;
pFile->pNext = pAllFiles;
pAllFiles = pFile;
}
/*
** Undo the work done by initFile. Delete the OsTestFile structure
** and unlink the structure from the pAllFiles list.
*/
static void closeFile(OsFile *id){
OsTestFile *pFile = *id;
if( pFile==pAllFiles ){
pAllFiles = pFile->pNext;
}else{
OsTestFile *p;
for(p=pAllFiles; p->pNext!=pFile; p=p->pNext ){
assert( p );
}
p->pNext = pFile->pNext;
}
sqliteFree(pFile);
*id = 0;
}
/*
** Return the current seek offset from the start of the file. This
** is unix-only code.
*/
static i64 osTell(OsTestFile *pFile){
return lseek(pFile->fd.h, 0, SEEK_CUR);
}
/*
** Load block 'blk' into the cache of pFile.
*/
static int cacheBlock(OsTestFile *pFile, int blk){
if( blk>=pFile->nBlk ){
int n = ((pFile->nBlk * 2) + 100 + blk);
/* if( pFile->nBlk==0 ){ printf("DIRTY %s\n", pFile->zName); } */
pFile->apBlk = (u8 **)sqliteRealloc(pFile->apBlk, n * sizeof(u8*));
if( !pFile->apBlk ) return SQLITE_NOMEM;
memset(&pFile->apBlk[pFile->nBlk], 0, (n - pFile->nBlk)*sizeof(u8*));
pFile->nBlk = n;
}
if( !pFile->apBlk[blk] ){
i64 filesize;
int rc;
u8 *p = sqliteMalloc(BLOCKSIZE);
if( !p ) return SQLITE_NOMEM;
pFile->apBlk[blk] = p;
rc = sqlite3RealFileSize(&pFile->fd, &filesize);
if( rc!=SQLITE_OK ) return rc;
if( BLOCK_OFFSET(blk)<filesize ){
int len = BLOCKSIZE;
rc = sqlite3RealSeek(&pFile->fd, blk*BLOCKSIZE);
if( BLOCK_OFFSET(blk+1)>filesize ){
len = filesize - BLOCK_OFFSET(blk);
}
if( rc!=SQLITE_OK ) return rc;
rc = sqlite3RealRead(&pFile->fd, p, len);
if( rc!=SQLITE_OK ) return rc;
}
}
return SQLITE_OK;
}
/* #define TRACE_WRITECACHE */
/*
** Write the cache of pFile to disk. If crash is non-zero, randomly
** skip blocks when writing. The cache is deleted before returning.
*/
static int writeCache2(OsTestFile *pFile, int crash){
int i;
int nMax = pFile->nMaxWrite;
i64 offset;
int rc = SQLITE_OK;
offset = osTell(pFile);
for(i=0; i<pFile->nBlk; i++){
u8 *p = pFile->apBlk[i];
if( p ){
int skip = 0;
int trash = 0;
if( crash ){
char random;
sqlite3Randomness(1, &random);
if( random & 0x01 ){
if( random & 0x02 ){
trash = 1;
#ifdef TRACE_WRITECACHE
printf("Trashing block %d of %s\n", i, pFile->zName);
#endif
}else{
skip = 1;
#ifdef TRACE_WRITECACHE
printf("Skiping block %d of %s\n", i, pFile->zName);
#endif
}
}else{
#ifdef TRACE_WRITECACHE
printf("Writing block %d of %s\n", i, pFile->zName);
#endif
}
}
if( rc==SQLITE_OK ){
rc = sqlite3RealSeek(&pFile->fd, BLOCK_OFFSET(i));
}
if( rc==SQLITE_OK && !skip ){
int len = BLOCKSIZE;
if( BLOCK_OFFSET(i+1)>nMax ){
len = nMax-BLOCK_OFFSET(i);
}
if( len>0 ){
if( trash ){
sqlite3Randomness(len, p);
}
rc = sqlite3RealWrite(&pFile->fd, p, len);
}
}
sqliteFree(p);
}
}
sqliteFree(pFile->apBlk);
pFile->nBlk = 0;
pFile->apBlk = 0;
pFile->nMaxWrite = 0;
if( rc==SQLITE_OK ){
rc = sqlite3RealSeek(&pFile->fd, offset);
}
return rc;
}
/*
** Write the cache to disk.
*/
static int writeCache(OsTestFile *pFile){
if( pFile->apBlk ){
int c = crashRequired(pFile->zName);
if( c ){
OsTestFile *p;
#ifdef TRACE_WRITECACHE
printf("\nCrash during sync of %s\n", pFile->zName);
#endif
for(p=pAllFiles; p; p=p->pNext){
writeCache2(p, 1);
}
exit(-1);
}else{
return writeCache2(pFile, 0);
}
}
return SQLITE_OK;
}
/*
** Close the file.
*/
int sqlite3OsClose(OsFile *id){
if( !(*id) ) return SQLITE_OK;
if( (*id)->fd.isOpen ){
/* printf("CLOSE %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */
writeCache(*id);
sqlite3RealClose(&(*id)->fd);
}
closeFile(id);
return SQLITE_OK;
}
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
i64 offset; /* The current offset from the start of the file */
i64 end; /* The byte just past the last byte read */
int blk; /* Block number the read starts on */
int i;
u8 *zCsr;
int rc = SQLITE_OK;
OsTestFile *pFile = *id;
offset = osTell(pFile);
end = offset+amt;
blk = (offset/BLOCKSIZE);
zCsr = (u8 *)pBuf;
for(i=blk; i*BLOCKSIZE<end; i++){
int off = 0;
int len = 0;
if( BLOCK_OFFSET(i) < offset ){
off = offset-BLOCK_OFFSET(i);
}
len = BLOCKSIZE - off;
if( BLOCK_OFFSET(i+1) > end ){
len = len - (BLOCK_OFFSET(i+1)-end);
}
if( i<pFile->nBlk && pFile->apBlk[i]){
u8 *pBlk = pFile->apBlk[i];
memcpy(zCsr, &pBlk[off], len);
}else{
rc = sqlite3RealSeek(&pFile->fd, BLOCK_OFFSET(i) + off);
if( rc!=SQLITE_OK ) return rc;
rc = sqlite3RealRead(&pFile->fd, zCsr, len);
if( rc!=SQLITE_OK ) return rc;
}
zCsr += len;
}
assert( zCsr==&((u8 *)pBuf)[amt] );
rc = sqlite3RealSeek(&pFile->fd, end);
return rc;
}
int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
i64 offset; /* The current offset from the start of the file */
i64 end; /* The byte just past the last byte written */
int blk; /* Block number the write starts on */
int i;
const u8 *zCsr;
int rc = SQLITE_OK;
OsTestFile *pFile = *id;
offset = osTell(pFile);
end = offset+amt;
blk = (offset/BLOCKSIZE);
zCsr = (u8 *)pBuf;
for(i=blk; i*BLOCKSIZE<end; i++){
u8 *pBlk;
int off = 0;
int len = 0;
/* Make sure the block is in the cache */
rc = cacheBlock(pFile, i);
if( rc!=SQLITE_OK ) return rc;
/* Write into the cache */
pBlk = pFile->apBlk[i];
assert( pBlk );
if( BLOCK_OFFSET(i) < offset ){
off = offset-BLOCK_OFFSET(i);
}
len = BLOCKSIZE - off;
if( BLOCK_OFFSET(i+1) > end ){
len = len - (BLOCK_OFFSET(i+1)-end);
}
memcpy(&pBlk[off], zCsr, len);
zCsr += len;
}
if( pFile->nMaxWrite<end ){
pFile->nMaxWrite = end;
}
assert( zCsr==&((u8 *)pBuf)[amt] );
rc = sqlite3RealSeek(&pFile->fd, end);
return rc;
}
/*
** Sync the file. First flush the write-cache to disk, then call the
** real sync() function.
*/
int sqlite3OsSync(OsFile *id){
int rc;
/* printf("SYNC %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */
rc = writeCache(*id);
if( rc!=SQLITE_OK ) return rc;
rc = sqlite3RealSync(&(*id)->fd);
return rc;
}
/*
** Truncate the file. Set the internal OsFile.nMaxWrite variable to the new
** file size to ensure that nothing in the write-cache past this point
** is written to disk.
*/
int sqlite3OsTruncate(OsFile *id, i64 nByte){
(*id)->nMaxWrite = nByte;
return sqlite3RealTruncate(&(*id)->fd, nByte);
}
/*
** Return the size of the file. If the cache contains a write that extended
** the file, then return this size instead of the on-disk size.
*/
int sqlite3OsFileSize(OsFile *id, i64 *pSize){
int rc = sqlite3RealFileSize(&(*id)->fd, pSize);
if( rc==SQLITE_OK && pSize && *pSize<(*id)->nMaxWrite ){
*pSize = (*id)->nMaxWrite;
}
return rc;
}
/*
** The three functions used to open files. All that is required is to
** initialise the os_test.c specific fields and then call the corresponding
** os_unix.c function to really open the file.
*/
int sqlite3OsOpenReadWrite(const char *zFilename, OsFile *id, int *pReadonly){
initFile(id, zFilename);
return sqlite3RealOpenReadWrite(zFilename, &(*id)->fd, pReadonly);
}
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
initFile(id, zFilename);
return sqlite3RealOpenExclusive(zFilename, &(*id)->fd, delFlag);
}
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
initFile(id, zFilename);
return sqlite3RealOpenReadOnly(zFilename, &(*id)->fd);
}
/*
** These six function calls are passed straight through to the os_unix.c
** backend.
*/
int sqlite3OsSeek(OsFile *id, i64 offset){
return sqlite3RealSeek(&(*id)->fd, offset);
}
int sqlite3OsCheckReservedLock(OsFile *id){
return sqlite3RealCheckReservedLock(&(*id)->fd);
}
int sqlite3OsLock(OsFile *id, int locktype){
return sqlite3RealLock(&(*id)->fd, locktype);
}
int sqlite3OsUnlock(OsFile *id, int locktype){
return sqlite3RealUnlock(&(*id)->fd, locktype);
}
int sqlite3OsOpenDirectory(const char *zDirname, OsFile *id){
return sqlite3RealOpenDirectory(zDirname, &(*id)->fd);
}
#endif /* OS_TEST */
-39
View File
@@ -1,39 +0,0 @@
/*
** 2004 May 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
*/
#ifndef _SQLITE_OS_TEST_H_
#define _SQLITE_OS_TEST_H_
#define OsFile OsRealFile
#define OS_UNIX 1
#include "os_unix.h"
#undef OS_UNIX
#undef OsFile
/* Include sqliteInt.h now to get the type u8. */
#include "sqliteInt.h"
typedef struct OsTestFile* OsFile;
typedef struct OsTestFile OsTestFile;
struct OsTestFile {
u8 **apBlk; /* Array of blocks that have been written to. */
int nBlk; /* Size of apBlock. */
int nMaxWrite; /* Largest offset written to. */
char *zName; /* File name */
OsRealFile fd;
OsTestFile *pNext;
};
void sqlite3SetCrashParams(int iDelay, char const *zFile);
#endif /* _SQLITE_OS_UNIX_H_ */
+235 -84
View File
@@ -18,8 +18,21 @@
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <unistd.h>
/*
** Do not include any of the File I/O interface procedures if the
** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
** will be in-memory only)
*/
#ifndef SQLITE_OMIT_DISKIO
/*
** Define various macros that are missing from some systems.
*/
#ifndef O_LARGEFILE
# define O_LARGEFILE 0
#endif
@@ -34,7 +47,6 @@
# define O_BINARY 0
#endif
/*
** The DJGPP compiler environment looks mostly like Unix, but it
** lacks the fcntl() system call. So redefine fcntl() to be something
@@ -45,25 +57,36 @@
# define fcntl(A,B,C) 0
#endif
/*
** Macros used to determine whether or not to use threads. The
** SQLITE_UNIX_THREADS macro is defined if we are synchronizing for
** Posix threads and SQLITE_W32_THREADS is defined if we are
** synchronizing using Win32 threads.
*/
#if defined(THREADSAFE) && THREADSAFE
# include <pthread.h>
# define SQLITE_UNIX_THREADS 1
#endif
/*
** Include code that is common to all os_*.c files
*/
#include "os_common.h"
#if defined(THREADSAFE) && THREADSAFE && defined(__linux__)
#define getpid pthread_self
/*
** The threadid macro resolves to the thread-id or to 0. Used for
** testing and debugging only.
*/
#ifdef SQLITE_UNIX_THREADS
#define threadid pthread_self()
#else
#define threadid 0
#endif
/*
** Set or check the OsFile.tid field. This field is set when an OsFile
** is first opened. All subsequent uses of the OsFile verify that the
** same thread is operating on the OsFile. Some operating systems do
** not allow locks to be overridden by other threads and that restriction
** means that sqlite3* database handles cannot be moved from one thread
** to another. This logic makes sure a user does not try to do that
** by mistake.
*/
#ifdef SQLITE_UNIX_THREADS
# define SET_THREADID(X) X->tid = pthread_self()
# define CHECK_THREADID(X) (!pthread_equal(X->tid, pthread_self()))
#else
# define SET_THREADID(X)
# define CHECK_THREADID(X) 0
#endif
/*
@@ -253,6 +276,65 @@ struct threadTestData {
int result; /* Result of the locking operation */
};
#ifdef SQLITE_LOCK_TRACE
/*
** Print out information about all locking operations.
**
** This routine is used for troubleshooting locks on multithreaded
** platforms. Enable by compiling with the -DSQLITE_LOCK_TRACE
** command-line option on the compiler. This code is normally
** turnned off.
*/
static int lockTrace(int fd, int op, struct flock *p){
char *zOpName, *zType;
int s;
int savedErrno;
if( op==F_GETLK ){
zOpName = "GETLK";
}else if( op==F_SETLK ){
zOpName = "SETLK";
}else{
s = fcntl(fd, op, p);
sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s);
return s;
}
if( p->l_type==F_RDLCK ){
zType = "RDLCK";
}else if( p->l_type==F_WRLCK ){
zType = "WRLCK";
}else if( p->l_type==F_UNLCK ){
zType = "UNLCK";
}else{
assert( 0 );
}
assert( p->l_whence==SEEK_SET );
s = fcntl(fd, op, p);
savedErrno = errno;
sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n",
threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len,
(int)p->l_pid, s);
if( s && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){
struct flock l2;
l2 = *p;
fcntl(fd, F_GETLK, &l2);
if( l2.l_type==F_RDLCK ){
zType = "RDLCK";
}else if( l2.l_type==F_WRLCK ){
zType = "WRLCK";
}else if( l2.l_type==F_UNLCK ){
zType = "UNLCK";
}else{
assert( 0 );
}
sqlite3DebugPrintf("fcntl-failure-reason: %s %d %d %d\n",
zType, (int)l2.l_start, (int)l2.l_len, (int)l2.l_pid);
}
errno = savedErrno;
return s;
}
#define fcntl lockTrace
#endif /* SQLITE_LOCK_TRACE */
/*
** The testThreadLockingBehavior() routine launches two separate
** threads on this routine. This routine attempts to lock a file
@@ -432,7 +514,9 @@ int sqlite3OsOpenReadWrite(
int rc;
assert( !id->isOpen );
id->dirfd = -1;
id->h = open(zFilename, O_RDWR|O_CREAT|O_LARGEFILE|O_BINARY, 0644);
SET_THREADID(id);
id->h = open(zFilename, O_RDWR|O_CREAT|O_LARGEFILE|O_BINARY,
SQLITE_DEFAULT_FILE_PERMISSIONS);
if( id->h<0 ){
#ifdef EISDIR
if( errno==EISDIR ){
@@ -482,9 +566,11 @@ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
if( access(zFilename, 0)==0 ){
return SQLITE_CANTOPEN;
}
SET_THREADID(id);
id->dirfd = -1;
id->h = open(zFilename,
O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_LARGEFILE|O_BINARY, 0600);
O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_LARGEFILE|O_BINARY,
SQLITE_DEFAULT_FILE_PERMISSIONS);
if( id->h<0 ){
return SQLITE_CANTOPEN;
}
@@ -516,6 +602,7 @@ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
int rc;
assert( !id->isOpen );
SET_THREADID(id);
id->dirfd = -1;
id->h = open(zFilename, O_RDONLY|O_LARGEFILE|O_BINARY);
if( id->h<0 ){
@@ -560,8 +647,9 @@ int sqlite3OsOpenDirectory(
** open. */
return SQLITE_CANTOPEN;
}
SET_THREADID(id);
assert( id->dirfd<0 );
id->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0644);
id->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0);
if( id->dirfd<0 ){
return SQLITE_CANTOPEN;
}
@@ -644,7 +732,7 @@ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
TIMER_START;
got = read(id->h, pBuf, amt);
TIMER_END;
TRACE4("READ %-3d %7d %d\n", id->h, last_page, TIMER_ELAPSED);
TRACE5("READ %-3d %5d %7d %d\n", id->h, got, last_page, TIMER_ELAPSED);
SEEK(0);
/* if( got<0 ) got = 0; */
if( got==amt ){
@@ -670,7 +758,7 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
pBuf = &((char*)pBuf)[wrote];
}
TIMER_END;
TRACE4("WRITE %-3d %7d %d\n", id->h, last_page, TIMER_ELAPSED);
TRACE5("WRITE %-3d %5d %7d %d\n", id->h, wrote, last_page, TIMER_ELAPSED);
SEEK(0);
if( amt>0 ){
return SQLITE_FULL;
@@ -684,10 +772,23 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
int sqlite3OsSeek(OsFile *id, i64 offset){
assert( id->isOpen );
SEEK(offset/1024 + 1);
#ifdef SQLITE_TEST
if( offset ) SimulateDiskfullError
#endif
lseek(id->h, offset, SEEK_SET);
return SQLITE_OK;
}
#ifdef SQLITE_TEST
/*
** Count the number of fullsyncs and normal syncs. This is used to test
** that syncs and fullsyncs are occuring at the right times.
*/
int sqlite3_sync_count = 0;
int sqlite3_fullsync_count = 0;
#endif
/*
** The fsync() system call does not work as advertised on many
** unix systems. The following procedure is an attempt to make
@@ -699,24 +800,56 @@ int sqlite3OsSeek(OsFile *id, i64 offset){
** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash
** or power failure will likely corrupt the database file.
*/
static int full_fsync(int fd){
#ifdef SQLITE_NO_SYNC
return SQLITE_OK;
#else
static int full_fsync(int fd, int fullSync, int dataOnly){
int rc;
#ifdef F_FULLFSYNC
rc = fcntl(fd, F_FULLFSYNC, 0);
if( rc ) rc = fsync(fd);
/* Record the number of times that we do a normal fsync() and
** FULLSYNC. This is used during testing to verify that this procedure
** gets called with the correct arguments.
*/
#ifdef SQLITE_TEST
if( fullSync ) sqlite3_fullsync_count++;
sqlite3_sync_count++;
#endif
/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
** no-op
*/
#ifdef SQLITE_NO_SYNC
rc = SQLITE_OK;
#else
rc = fsync(fd);
#endif
#ifdef F_FULLFSYNC
if( fullSync ){
rc = fcntl(fd, F_FULLFSYNC, 0);
}else{
rc = 1;
}
/* If the FULLSYNC failed, try to do a normal fsync() */
if( rc ) rc = fsync(fd);
#else /* if !defined(F_FULLSYNC) */
#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO>0
if( dataOnly ){
rc = fdatasync(fd);
}else
#endif /* _POSIX_SYNCHRONIZED_IO > 0 */
{
rc = fsync(fd);
}
#endif /* defined(F_FULLFSYNC) */
#endif /* defined(SQLITE_NO_SYNC) */
return rc;
#endif
}
/*
** Make sure all writes to a particular file are committed to disk.
**
** If dataOnly==0 then both the file itself and its metadata (file
** size, access time, etc) are synced. If dataOnly!=0 then only the
** file data is synced.
**
** Under Unix, also make sure that the directory entry for the file
** has been created by fsync-ing the directory that contains the file.
** If we do not do this and we encounter a power failure, the directory
@@ -725,16 +858,16 @@ static int full_fsync(int fd){
** the directory entry for the journal was never created) and the transaction
** will not roll back - possibly leading to database corruption.
*/
int sqlite3OsSync(OsFile *id){
int sqlite3OsSync(OsFile *id, int dataOnly){
assert( id->isOpen );
SimulateIOError(SQLITE_IOERR);
TRACE2("SYNC %-3d\n", id->h);
if( full_fsync(id->h) ){
if( full_fsync(id->h, id->fullSync, dataOnly) ){
return SQLITE_IOERR;
}
if( id->dirfd>=0 ){
TRACE2("DIRSYNC %-3d\n", id->dirfd);
full_fsync(id->dirfd);
full_fsync(id->dirfd, id->fullSync, 0);
close(id->dirfd); /* Only need to sync once, so close the directory */
id->dirfd = -1; /* when we are done. */
}
@@ -744,12 +877,16 @@ int sqlite3OsSync(OsFile *id){
/*
** Sync the directory zDirname. This is a no-op on operating systems other
** than UNIX.
**
** This is used to make sure the master journal file has truely been deleted
** before making changes to individual journals on a multi-database commit.
** The F_FULLFSYNC option is not needed here.
*/
int sqlite3OsSyncDirectory(const char *zDirname){
int fd;
int r;
SimulateIOError(SQLITE_IOERR);
fd = open(zDirname, O_RDONLY|O_BINARY, 0644);
fd = open(zDirname, O_RDONLY|O_BINARY, 0);
TRACE3("DIRSYNC %-3d (%s)\n", fd, zDirname);
if( fd<0 ){
return SQLITE_CANTOPEN;
@@ -792,6 +929,7 @@ int sqlite3OsCheckReservedLock(OsFile *id){
int r = 0;
assert( id->isOpen );
if( CHECK_THREADID(id) ) return SQLITE_MISUSE;
sqlite3OsEnterMutex(); /* Needed because id->pLock is shared across threads */
/* Check if a thread in this process holds such a lock */
@@ -906,16 +1044,17 @@ int sqlite3OsLock(OsFile *id, int locktype){
int s;
assert( id->isOpen );
TRACE7("LOCK %d %s was %s(%s,%d) pid=%d\n", id->h, locktypeName(locktype),
TRACE7("LOCK %d %s was %s(%s,%d) pid=%d\n", id->h, locktypeName(locktype),
locktypeName(id->locktype), locktypeName(pLock->locktype), pLock->cnt
,getpid() );
if( CHECK_THREADID(id) ) return SQLITE_MISUSE;
/* If there is already a lock of this type or more restrictive on the
** OsFile, do nothing. Don't use the end_lock: exit path, as
** sqlite3OsEnterMutex() hasn't been called yet.
*/
if( id->locktype>=locktype ){
TRACE3("LOCK %d %s ok (already held)\n", id->h, locktypeName(locktype));
TRACE3("LOCK %d %s ok (already held)\n", id->h, locktypeName(locktype));
return SQLITE_OK;
}
@@ -955,6 +1094,7 @@ int sqlite3OsLock(OsFile *id, int locktype){
}
lock.l_len = 1L;
lock.l_whence = SEEK_SET;
/* A PENDING lock is needed before acquiring a SHARED lock and before
@@ -990,7 +1130,10 @@ int sqlite3OsLock(OsFile *id, int locktype){
lock.l_start = PENDING_BYTE;
lock.l_len = 1L;
lock.l_type = F_UNLCK;
fcntl(id->h, F_SETLK, &lock);
if( fcntl(id->h, F_SETLK, &lock)!=0 ){
rc = SQLITE_IOERR; /* This should never happen */
goto end_lock;
}
if( s ){
rc = (errno==EINVAL) ? SQLITE_NOLFS : SQLITE_BUSY;
}else{
@@ -1036,7 +1179,7 @@ int sqlite3OsLock(OsFile *id, int locktype){
end_lock:
sqlite3OsLeaveMutex();
TRACE4("LOCK %d %s %s\n", id->h, locktypeName(locktype),
TRACE4("LOCK %d %s %s\n", id->h, locktypeName(locktype),
rc==SQLITE_OK ? "ok" : "failed");
return rc;
}
@@ -1058,8 +1201,9 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
int rc = SQLITE_OK;
assert( id->isOpen );
TRACE7("UNLOCK %d %d was %d(%d,%d) pid=%d\n", id->h, locktype, id->locktype,
TRACE7("UNLOCK %d %d was %d(%d,%d) pid=%d\n", id->h, locktype, id->locktype,
id->pLock->locktype, id->pLock->cnt, getpid());
if( CHECK_THREADID(id) ) return SQLITE_MISUSE;
assert( locktype<=SHARED_LOCK );
if( id->locktype<=locktype ){
@@ -1084,8 +1228,11 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
lock.l_whence = SEEK_SET;
lock.l_start = PENDING_BYTE;
lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE );
fcntl(id->h, F_SETLK, &lock);
pLock->locktype = SHARED_LOCK;
if( fcntl(id->h, F_SETLK, &lock)==0 ){
pLock->locktype = SHARED_LOCK;
}else{
rc = SQLITE_IOERR; /* This should never happen */
}
}
if( locktype==NO_LOCK ){
struct openCnt *pOpen;
@@ -1099,8 +1246,11 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
lock.l_type = F_UNLCK;
lock.l_whence = SEEK_SET;
lock.l_start = lock.l_len = 0L;
fcntl(id->h, F_SETLK, &lock);
pLock->locktype = NO_LOCK;
if( fcntl(id->h, F_SETLK, &lock)==0 ){
pLock->locktype = NO_LOCK;
}else{
rc = SQLITE_IOERR; /* This should never happen */
}
}
/* Decrement the count of locks against this same file. When the
@@ -1130,6 +1280,7 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
*/
int sqlite3OsClose(OsFile *id){
if( !id->isOpen ) return SQLITE_OK;
if( CHECK_THREADID(id) ) return SQLITE_MISUSE;
sqlite3OsUnlock(id, NO_LOCK);
if( id->dirfd>=0 ) close(id->dirfd);
id->dirfd = -1;
@@ -1142,13 +1293,13 @@ int sqlite3OsClose(OsFile *id){
*/
int *aNew;
struct openCnt *pOpen = id->pOpen;
pOpen->nPending++;
aNew = sqliteRealloc( pOpen->aPending, pOpen->nPending*sizeof(int) );
aNew = sqliteRealloc( pOpen->aPending, (pOpen->nPending+1)*sizeof(int) );
if( aNew==0 ){
/* If a malloc fails, just leak the file descriptor */
}else{
pOpen->aPending = aNew;
pOpen->aPending[pOpen->nPending-1] = id->h;
pOpen->aPending[pOpen->nPending] = id->h;
pOpen->nPending++;
}
}else{
/* There are no outstanding locks so we can close the file immediately */
@@ -1163,6 +1314,37 @@ int sqlite3OsClose(OsFile *id){
return SQLITE_OK;
}
/*
** Turn a relative pathname into a full pathname. Return a pointer
** to the full pathname stored in space obtained from sqliteMalloc().
** The calling function is responsible for freeing this space once it
** is no longer needed.
*/
char *sqlite3OsFullPathname(const char *zRelative){
char *zFull = 0;
if( zRelative[0]=='/' ){
sqlite3SetString(&zFull, zRelative, (char*)0);
}else{
char *zBuf = sqliteMalloc(5000);
if( zBuf==0 ){
return 0;
}
zBuf[0] = 0;
sqlite3SetString(&zFull, getcwd(zBuf, 5000), "/", zRelative,
(char*)0);
sqliteFree(zBuf);
}
return zFull;
}
#endif /* SQLITE_OMIT_DISKIO */
/***************************************************************************
** Everything above deals with file I/O. Everything that follows deals
** with other miscellanous aspects of the operating system interface
****************************************************************************/
/*
** Get information to seed the random number generator. The seed
** is written into the buffer zBuf[256]. The calling function must
@@ -1243,24 +1425,6 @@ void sqlite3OsLeaveMutex(){
#endif
}
/*
** Turn a relative pathname into a full pathname. Return a pointer
** to the full pathname stored in space obtained from sqliteMalloc().
** The calling function is responsible for freeing this space once it
** is no longer needed.
*/
char *sqlite3OsFullPathname(const char *zRelative){
char *zFull = 0;
if( zRelative[0]=='/' ){
sqlite3SetString(&zFull, zRelative, (char*)0);
}else{
char zBuf[5000];
sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), "/", zRelative,
(char*)0);
}
return zFull;
}
/*
** The following variable, if set to a non-zero value, becomes the result
** returned from sqlite3OsCurrentTime(). This is used for testing.
@@ -1275,9 +1439,16 @@ int sqlite3_current_time = 0;
** return 0. Return 1 if the time and date cannot be found.
*/
int sqlite3OsCurrentTime(double *prNow){
#ifdef NO_GETTOD
time_t t;
time(&t);
*prNow = t/86400.0 + 2440587.5;
#else
struct timeval sNow;
struct timezone sTz; /* Not used */
gettimeofday(&sNow, &sTz);
*prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0;
#endif
#ifdef SQLITE_TEST
if( sqlite3_current_time ){
*prNow = sqlite3_current_time/86400.0 + 2440587.5;
@@ -1286,24 +1457,4 @@ int sqlite3OsCurrentTime(double *prNow){
return 0;
}
#if 0 /* NOT USED */
/*
** Find the time that the file was last modified. Write the
** modification time and date as a Julian Day number into *prNow and
** return SQLITE_OK. Return SQLITE_ERROR if the modification
** time cannot be found.
*/
int sqlite3OsFileModTime(OsFile *id, double *prNow){
int rc;
struct stat statbuf;
if( fstat(id->h, &statbuf)==0 ){
*prNow = statbuf.st_mtime/86400.0 + 2440587.5;
rc = SQLITE_OK;
}else{
rc = SQLITE_ERROR;
}
return rc;
}
#endif /* NOT USED */
#endif /* OS_UNIX */
-89
View File
@@ -1,89 +0,0 @@
/*
** 2004 May 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This header file defined OS-specific features for Unix.
*/
#ifndef _SQLITE_OS_UNIX_H_
#define _SQLITE_OS_UNIX_H_
/*
** Helpful hint: To get this to compile on HP/UX, add -D_INCLUDE_POSIX_SOURCE
** to the compiler command line.
*/
/*
** These #defines should enable >2GB file support on Posix if the
** underlying operating system supports it. If the OS lacks
** large file support, or if the OS is windows, these should be no-ops.
**
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
** on the compiler command line. This is necessary if you are compiling
** on a recent machine (ex: RedHat 7.2) but you want your code to work
** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2
** without this option, LFS is enable. But LFS does not exist in the kernel
** in RedHat 6.0, so the code won't work. Hence, for maximum binary
** portability you should omit LFS.
**
** Similar is true for MacOS. LFS is only supported on MacOS 9 and later.
*/
#ifndef SQLITE_DISABLE_LFS
# define _LARGE_FILE 1
# ifndef _FILE_OFFSET_BITS
# define _FILE_OFFSET_BITS 64
# endif
# define _LARGEFILE_SOURCE 1
#endif
/*
** standard include files.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
/*
** The OsFile structure is a operating-system independing representation
** of an open file handle. It is defined differently for each architecture.
**
** This is the definition for Unix.
**
** OsFile.locktype takes one of the values SHARED_LOCK, RESERVED_LOCK,
** PENDING_LOCK or EXCLUSIVE_LOCK.
*/
typedef struct OsFile OsFile;
struct OsFile {
struct Pager *pPager; /* The pager that owns this OsFile. Might be 0 */
struct openCnt *pOpen; /* Info about all open fd's on this inode */
struct lockInfo *pLock; /* Info about locks on this inode */
int h; /* The file descriptor */
unsigned char locktype; /* The type of lock held on this fd */
unsigned char isOpen; /* True if needs to be closed */
int dirfd; /* File descriptor for the directory */
};
/*
** Maximum number of characters in a temporary file name
*/
#define SQLITE_TEMPNAME_SIZE 200
/*
** Minimum interval supported by sqlite3OsSleep().
*/
#if defined(HAVE_USLEEP) && HAVE_USLEEP
# define SQLITE_MIN_SLEEP_MS 1
#else
# define SQLITE_MIN_SLEEP_MS 1000
#endif
#endif /* _SQLITE_OS_UNIX_H_ */
+274 -100
View File
@@ -18,6 +18,10 @@
#include <winbase.h>
#ifdef __CYGWIN__
# include <sys/cygwin.h>
#endif
/*
** Macros used to determine whether or not to use threads.
*/
@@ -30,11 +34,106 @@
*/
#include "os_common.h"
/*
** Do not include any of the File I/O interface procedures if the
** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
** will be in-memory only)
*/
#ifndef SQLITE_OMIT_DISKIO
/*
** The following variable is (normally) set once and never changes
** thereafter. It records whether the operating system is Win95
** or WinNT.
**
** 0: Operating system unknown.
** 1: Operating system is Win95.
** 2: Operating system is WinNT.
**
** In order to facilitate testing on a WinNT system, the test fixture
** can manually set this value to 1 to emulate Win98 behavior.
*/
int sqlite3_os_type = 0;
/*
** Return true (non-zero) if we are running under WinNT, Win2K or WinXP.
** Return false (zero) for Win95, Win98, or WinME.
**
** Here is an interesting observation: Win95, Win98, and WinME lack
** the LockFileEx() API. But we can still statically link against that
** API as long as we don't call it win running Win95/98/ME. A call to
** this routine is used to determine if the host is Win95/98/ME or
** WinNT/2K/XP so that we will know whether or not we can safely call
** the LockFileEx() API.
*/
static int isNT(void){
if( sqlite3_os_type==0 ){
OSVERSIONINFO sInfo;
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
GetVersionEx(&sInfo);
sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
}
return sqlite3_os_type==2;
}
/*
** Convert a UTF-8 string to UTF-32. Space to hold the returned string
** is obtained from sqliteMalloc.
*/
static WCHAR *utf8ToUnicode(const char *zFilename){
int nByte;
WCHAR *zWideFilename;
if( !isNT() ){
return 0;
}
nByte = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0)*sizeof(WCHAR);
zWideFilename = sqliteMalloc( nByte*sizeof(zWideFilename[0]) );
if( zWideFilename==0 ){
return 0;
}
nByte = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, nByte);
if( nByte==0 ){
sqliteFree(zWideFilename);
zWideFilename = 0;
}
return zWideFilename;
}
/*
** Convert UTF-32 to UTF-8. Space to hold the returned string is
** obtained from sqliteMalloc().
*/
static char *unicodeToUtf8(const WCHAR *zWideFilename){
int nByte;
char *zFilename;
nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
zFilename = sqliteMalloc( nByte );
if( zFilename==0 ){
return 0;
}
nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
0, 0);
if( nByte == 0 ){
sqliteFree(zFilename);
zFilename = 0;
}
return zFilename;
}
/*
** Delete the named file
*/
int sqlite3OsDelete(const char *zFilename){
DeleteFileA(zFilename);
WCHAR *zWide = utf8ToUnicode(zFilename);
if( zWide ){
DeleteFileW(zWide);
sqliteFree(zWide);
}else{
DeleteFileA(zFilename);
}
TRACE2("DELETE \"%s\"\n", zFilename);
return SQLITE_OK;
}
@@ -43,7 +142,15 @@ int sqlite3OsDelete(const char *zFilename){
** Return TRUE if the named file exists.
*/
int sqlite3OsFileExists(const char *zFilename){
return GetFileAttributesA(zFilename) != 0xffffffff;
int exists = 0;
WCHAR *zWide = utf8ToUnicode(zFilename);
if( zWide ){
exists = GetFileAttributesW(zWide) != 0xffffffff;
sqliteFree(zWide);
}else{
exists = GetFileAttributesA(zFilename) != 0xffffffff;
}
return exists;
}
/*
@@ -65,30 +172,60 @@ int sqlite3OsOpenReadWrite(
int *pReadonly
){
HANDLE h;
WCHAR *zWide = utf8ToUnicode(zFilename);
assert( !id->isOpen );
h = CreateFileA(zFilename,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
NULL
);
if( h==INVALID_HANDLE_VALUE ){
h = CreateFileA(zFilename,
GENERIC_READ,
FILE_SHARE_READ,
if( zWide ){
h = CreateFileW(zWide,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
NULL
);
if( h==INVALID_HANDLE_VALUE ){
return SQLITE_CANTOPEN;
h = CreateFileW(zWide,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
NULL
);
if( h==INVALID_HANDLE_VALUE ){
sqliteFree(zWide);
return SQLITE_CANTOPEN;
}
*pReadonly = 1;
}else{
*pReadonly = 0;
}
*pReadonly = 1;
sqliteFree(zWide);
}else{
*pReadonly = 0;
h = CreateFileA(zFilename,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
NULL
);
if( h==INVALID_HANDLE_VALUE ){
h = CreateFileA(zFilename,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
NULL
);
if( h==INVALID_HANDLE_VALUE ){
return SQLITE_CANTOPEN;
}
*pReadonly = 1;
}else{
*pReadonly = 0;
}
}
id->h = h;
id->locktype = NO_LOCK;
@@ -117,6 +254,7 @@ int sqlite3OsOpenReadWrite(
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
HANDLE h;
int fileflags;
WCHAR *zWide = utf8ToUnicode(zFilename);
assert( !id->isOpen );
if( delFlag ){
fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS
@@ -124,14 +262,26 @@ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
}else{
fileflags = FILE_FLAG_RANDOM_ACCESS;
}
h = CreateFileA(zFilename,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
fileflags,
NULL
);
if( zWide ){
h = CreateFileW(zWide,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
fileflags,
NULL
);
sqliteFree(zWide);
}else{
h = CreateFileA(zFilename,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
fileflags,
NULL
);
}
if( h==INVALID_HANDLE_VALUE ){
return SQLITE_CANTOPEN;
}
@@ -153,15 +303,28 @@ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
*/
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
HANDLE h;
WCHAR *zWide = utf8ToUnicode(zFilename);
assert( !id->isOpen );
h = CreateFileA(zFilename,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
NULL
);
if( zWide ){
h = CreateFileW(zWide,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
NULL
);
sqliteFree(zWide);
}else{
h = CreateFileA(zFilename,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
NULL
);
}
if( h==INVALID_HANDLE_VALUE ){
return SQLITE_CANTOPEN;
}
@@ -218,6 +381,16 @@ int sqlite3OsTempFileName(char *zBuf){
if( sqlite3_temp_directory ){
strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30);
zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
}else if( isNT() ){
char *zMulti;
WCHAR zWidePath[SQLITE_TEMPNAME_SIZE];
GetTempPathW(SQLITE_TEMPNAME_SIZE-30, zWidePath);
zMulti = unicodeToUtf8(zWidePath);
if( zMulti ){
strncpy(zTempPath, zMulti, SQLITE_TEMPNAME_SIZE-30);
zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
sqliteFree(zMulti);
}
}else{
GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath);
}
@@ -292,6 +465,13 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
return SQLITE_OK;
}
/*
** Some microsoft compilers lack this definition.
*/
#ifndef INVALID_SET_FILE_POINTER
# define INVALID_SET_FILE_POINTER ((DWORD)-1)
#endif
/*
** Move the read/write pointer in a file.
*/
@@ -300,16 +480,22 @@ int sqlite3OsSeek(OsFile *id, i64 offset){
LONG lowerBits = offset & 0xffffffff;
DWORD rc;
assert( id->isOpen );
#ifdef SQLITE_TEST
if( offset ) SimulateDiskfullError
#endif
SEEK(offset/1024 + 1);
rc = SetFilePointer(id->h, lowerBits, &upperBits, FILE_BEGIN);
TRACE3("SEEK %d %lld\n", id->h, offset);
if( rc==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR ){
return SQLITE_FULL;
}
return SQLITE_OK;
}
/*
** Make sure all writes to a particular file are committed to disk.
*/
int sqlite3OsSync(OsFile *id){
int sqlite3OsSync(OsFile *id, int dataOnly){
assert( id->isOpen );
TRACE3("SYNC %d lock=%d\n", id->h, id->locktype);
if( FlushFileBuffers(id->h) ){
@@ -353,28 +539,6 @@ int sqlite3OsFileSize(OsFile *id, i64 *pSize){
return SQLITE_OK;
}
/*
** Return true (non-zero) if we are running under WinNT, Win2K or WinXP.
** Return false (zero) for Win95, Win98, or WinME.
**
** Here is an interesting observation: Win95, Win98, and WinME lack
** the LockFileEx() API. But we can still statically link against that
** API as long as we don't call it win running Win95/98/ME. A call to
** this routine is used to determine if the host is Win95/98/ME or
** WinNT/2K/XP so that we will know whether or not we can safely call
** the LockFileEx() API.
*/
static int isNT(void){
static int osType = 0; /* 0=unknown 1=win95 2=winNT */
if( osType==0 ){
OSVERSIONINFO sInfo;
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
GetVersionEx(&sInfo);
osType = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
}
return osType==2;
}
/*
** Acquire a reader lock.
** Different API routines are called depending on whether or not this
@@ -415,11 +579,18 @@ static int unlockReadLock(OsFile *id){
** Check that a given pathname is a directory and is writable
**
*/
int sqlite3OsIsDirWritable(char *zBuf){
int sqlite3OsIsDirWritable(char *zDirname){
int fileAttr;
if(! zBuf ) return 0;
if(! isNT() && strlen(zBuf) > MAX_PATH ) return 0;
fileAttr = GetFileAttributesA(zBuf);
WCHAR *zWide;
if( zDirname==0 ) return 0;
if( !isNT() && strlen(zDirname)>MAX_PATH ) return 0;
zWide = utf8ToUnicode(zDirname);
if( zWide ){
fileAttr = GetFileAttributesW(zWide);
sqliteFree(zWide);
}else{
fileAttr = GetFileAttributesA(zDirname);
}
if( fileAttr == 0xffffffff ) return 0;
if( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ){
return 0;
@@ -621,6 +792,49 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
return rc;
}
/*
** Turn a relative pathname into a full pathname. Return a pointer
** to the full pathname stored in space obtained from sqliteMalloc().
** The calling function is responsible for freeing this space once it
** is no longer needed.
*/
char *sqlite3OsFullPathname(const char *zRelative){
char *zNotUsed;
char *zFull;
WCHAR *zWide;
int nByte;
#ifdef __CYGWIN__
nByte = strlen(zRelative) + MAX_PATH + 1001;
zFull = sqliteMalloc( nByte );
if( zFull==0 ) return 0;
if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0;
#else
zWide = utf8ToUnicode(zRelative);
if( zWide ){
WCHAR *zTemp, *zNotUsedW;
nByte = GetFullPathNameW(zWide, 0, 0, &zNotUsedW) + 1;
zTemp = sqliteMalloc( nByte*sizeof(zTemp[0]) );
if( zTemp==0 ) return 0;
GetFullPathNameW(zWide, nByte, zTemp, &zNotUsedW);
sqliteFree(zWide);
zFull = unicodeToUtf8(zTemp);
sqliteFree(zTemp);
}else{
nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
zFull = sqliteMalloc( nByte*sizeof(zFull[0]) );
if( zFull==0 ) return 0;
GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
}
#endif
return zFull;
}
#endif /* SQLITE_OMIT_DISKIO */
/***************************************************************************
** Everything above deals with file I/O. Everything that follows deals
** with other miscellanous aspects of the operating system interface
****************************************************************************/
/*
** Get information to seed the random number generator. The seed
** is written into the buffer zBuf[256]. The calling function must
@@ -693,23 +907,6 @@ void sqlite3OsLeaveMutex(){
#endif
}
/*
** Turn a relative pathname into a full pathname. Return a pointer
** to the full pathname stored in space obtained from sqliteMalloc().
** The calling function is responsible for freeing this space once it
** is no longer needed.
*/
char *sqlite3OsFullPathname(const char *zRelative){
char *zNotUsed;
char *zFull;
int nByte;
nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
zFull = sqliteMalloc( nByte );
if( zFull==0 ) return 0;
GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
return zFull;
}
/*
** The following variable, if set to a non-zero value, becomes the result
** returned from sqlite3OsCurrentTime(). This is used for testing.
@@ -740,27 +937,4 @@ int sqlite3OsCurrentTime(double *prNow){
return 0;
}
/*
** Find the time that the file was last modified. Write the
** modification time and date as a Julian Day number into *prNow and
** return SQLITE_OK. Return SQLITE_ERROR if the modification
** time cannot be found.
*/
int sqlite3OsFileModTime(OsFile *id, double *prMTime){
int rc;
FILETIME ft;
/* FILETIME structure is a 64-bit value representing the number of
** 100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
*/
if( GetFileTime(id->h, 0, 0, &ft) ){
double t;
t = ((double)ft.dwHighDateTime) * 4294967296.0;
*prMTime = (t + ft.dwLowDateTime)/864000000000.0 + 2305813.5;
rc = SQLITE_OK;
}else{
rc = SQLITE_ERROR;
}
return rc;
}
#endif /* OS_WIN */
-40
View File
@@ -1,40 +0,0 @@
/*
** 2004 May 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This header file defines OS-specific features for Win32
*/
#ifndef _SQLITE_OS_WIN_H_
#define _SQLITE_OS_WIN_H_
#include <windows.h>
#include <winbase.h>
/*
** The OsFile structure is a operating-system independing representation
** of an open file handle. It is defined differently for each architecture.
**
** This is the definition for Win32.
*/
typedef struct OsFile OsFile;
struct OsFile {
HANDLE h; /* Handle for accessing the file */
unsigned char locktype; /* Type of lock currently held on this file */
unsigned char isOpen; /* True if needs to be closed */
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
};
#define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
#define SQLITE_MIN_SLEEP_MS 1
#endif /* _SQLITE_OS_WIN_H_ */
+242 -127
View File
@@ -18,8 +18,9 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.190 2005/02/15 03:38:06 danielk1977 Exp $
** @(#) $Id: pager.c,v 1.215.2.1 2005/12/19 16:29:07 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
@@ -171,7 +172,7 @@ struct PgHdr {
#ifdef SQLITE_CHECK_PAGES
u32 pageHash;
#endif
/* pPager->psAligned bytes of page data follow this header */
/* pPager->pageSize bytes of page data follow this header */
/* Pager.nExtra bytes of local data follow the page data */
};
@@ -207,15 +208,22 @@ struct PgHistory {
*/
#define PGHDR_TO_DATA(P) ((void*)(&(P)[1]))
#define DATA_TO_PGHDR(D) (&((PgHdr*)(D))[-1])
#define PGHDR_TO_EXTRA(G,P) ((void*)&((char*)(&(G)[1]))[(P)->psAligned])
#define PGHDR_TO_EXTRA(G,P) ((void*)&((char*)(&(G)[1]))[(P)->pageSize])
#define PGHDR_TO_HIST(P,PGR) \
((PgHistory*)&((char*)(&(P)[1]))[(PGR)->psAligned+(PGR)->nExtra])
((PgHistory*)&((char*)(&(P)[1]))[(PGR)->pageSize+(PGR)->nExtra])
/*
** How big to make the hash table used for locating in-memory pages
** by page number.
** by page number. This macro looks a little silly, but is evaluated
** at compile-time, not run-time (at least for gcc this is true).
*/
#define N_PG_HASH 2048
#define N_PG_HASH (\
(MAX_PAGES>1024)?2048: \
(MAX_PAGES>512)?1024: \
(MAX_PAGES>256)?512: \
(MAX_PAGES>128)?256: \
(MAX_PAGES>64)?128:64 \
)
/*
** Hash a page number
@@ -226,30 +234,6 @@ struct PgHistory {
** A open page cache is an instance of the following structure.
*/
struct Pager {
char *zFilename; /* Name of the database file */
char *zJournal; /* Name of the journal file */
char *zDirectory; /* Directory hold database and journal files */
OsFile fd, jfd; /* File descriptors for database and journal */
OsFile stfd; /* File descriptor for the statement subjournal*/
int dbSize; /* Number of pages in the file */
int origDbSize; /* dbSize before the current change */
int stmtSize; /* Size of database (in pages) at stmt_begin() */
i64 stmtJSize; /* Size of journal at stmt_begin() */
int nRec; /* Number of pages written to the journal */
u32 cksumInit; /* Quasi-random value added to every checksum */
int stmtNRec; /* Number of records in stmt subjournal */
int nExtra; /* Add this many bytes to each in-memory page */
void (*xDestructor)(void*,int); /* Call this routine when freeing pages */
void (*xReiniter)(void*,int); /* Call this routine when reloading pages */
int pageSize; /* Number of bytes in a page */
int psAligned; /* pageSize rounded up to a multiple of 8 */
int nPage; /* Total number of in-memory pages */
int nRef; /* Number of in-memory pages with PgHdr.nRef>0 */
int mxPage; /* Maximum number of pages to hold in cache */
int nHit, nMiss, nOvfl; /* Cache hits, missing, and LRU overflows */
int nRead,nWrite; /* Database pages read/written */
void (*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
void *pCodecArg; /* First argument to xCodec() */
u8 journalOpen; /* True if journal file descriptors is valid */
u8 journalStarted; /* True if header of journal is synced */
u8 useJournal; /* Use a rollback journal on this file */
@@ -267,9 +251,26 @@ struct Pager {
u8 dirtyCache; /* True if cached pages have changed */
u8 alwaysRollback; /* Disable dont_rollback() for all pages */
u8 memDb; /* True to inhibit all file I/O */
u8 setMaster; /* True if a m-j name has been written to jrnl */
int dbSize; /* Number of pages in the file */
int origDbSize; /* dbSize before the current change */
int stmtSize; /* Size of database (in pages) at stmt_begin() */
int nRec; /* Number of pages written to the journal */
u32 cksumInit; /* Quasi-random value added to every checksum */
int stmtNRec; /* Number of records in stmt subjournal */
int nExtra; /* Add this many bytes to each in-memory page */
int pageSize; /* Number of bytes in a page */
int nPage; /* Total number of in-memory pages */
int nMaxPage; /* High water mark of nPage */
int nRef; /* Number of in-memory pages with PgHdr.nRef>0 */
int mxPage; /* Maximum number of pages to hold in cache */
u8 *aInJournal; /* One bit for each page in the database file */
u8 *aInStmt; /* One bit for each page in the database */
u8 setMaster; /* True if a m-j name has been written to jrnl */
char *zFilename; /* Name of the database file */
char *zJournal; /* Name of the journal file */
char *zDirectory; /* Directory hold database and journal files */
OsFile fd, jfd; /* File descriptors for database and journal */
OsFile stfd; /* File descriptor for the statement subjournal*/
BusyHandler *pBusyHandler; /* Pointer to sqlite.busyHandler */
PgHdr *pFirst, *pLast; /* List of free pages */
PgHdr *pFirstSynced; /* First free page with PgHdr.needSync==0 */
@@ -279,10 +280,29 @@ struct Pager {
i64 journalHdr; /* Byte offset to previous journal header */
i64 stmtHdrOff; /* First journal header written this statement */
i64 stmtCksum; /* cksumInit when statement was started */
i64 stmtJSize; /* Size of journal at stmt_begin() */
int sectorSize; /* Assumed sector size during rollback */
#ifdef SQLITE_TEST
int nHit, nMiss, nOvfl; /* Cache hits, missing, and LRU overflows */
int nRead,nWrite; /* Database pages read/written */
#endif
void (*xDestructor)(void*,int); /* Call this routine when freeing pages */
void (*xReiniter)(void*,int); /* Call this routine when reloading pages */
void (*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
void *pCodecArg; /* First argument to xCodec() */
PgHdr *aHash[N_PG_HASH]; /* Hash table to map page number to PgHdr */
};
/*
** If SQLITE_TEST is defined then increment the variable given in
** the argument
*/
#ifdef SQLITE_TEST
# define TEST_INCR(x) x++
#else
# define TEST_INCR(x)
#endif
/*
** These are bits that can be set in Pager.errMask.
*/
@@ -637,8 +657,10 @@ static int writeJournalHdr(Pager *pPager){
** file descriptor to the end of the journal header sector.
*/
if( rc==SQLITE_OK ){
sqlite3OsSeek(&pPager->jfd, pPager->journalOff-1);
rc = sqlite3OsWrite(&pPager->jfd, "\000", 1);
rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff-1);
if( rc==SQLITE_OK ){
rc = sqlite3OsWrite(&pPager->jfd, "\000", 1);
}
}
return rc;
}
@@ -759,7 +781,7 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
if( rc!=SQLITE_OK ) return rc;
rc = sqlite3OsWrite(&pPager->jfd, aJournalMagic, sizeof(aJournalMagic));
pPager->needSync = 1;
pPager->needSync = !pPager->noSync;
return rc;
}
@@ -822,6 +844,7 @@ static PgHdr *pager_lookup(Pager *pPager, Pgno pgno){
*/
static void pager_reset(Pager *pPager){
PgHdr *pPg, *pNext;
if( pPager->errMask ) return;
for(pPg=pPager->pAll; pPg; pPg=pNext){
pNext = pPg->pNextAll;
sqliteFree(pPg);
@@ -842,6 +865,29 @@ static void pager_reset(Pager *pPager){
assert( pPager->journalOpen==0 );
}
/*
** This function is used to reset the pager after a malloc() failure. This
** doesn't work with in-memory databases. If a malloc() fails when an
** in-memory database is in use it is not possible to recover.
**
** If a transaction or statement transaction is active, it is rolled back.
**
** It is an error to call this function if any pages are in use.
*/
#ifndef SQLITE_OMIT_GLOBALRECOVER
int sqlite3pager_reset(Pager *pPager){
if( pPager ){
if( pPager->nRef || MEMDB ){
return SQLITE_ERROR;
}
pPager->errMask &= ~(PAGER_ERR_MEM);
pager_reset(pPager);
}
return SQLITE_OK;
}
#endif
/*
** When this routine is called, the pager has the journal file open and
** a RESERVED or EXCLUSIVE lock on the database. This routine releases
@@ -881,6 +927,7 @@ static int pager_unwritelock(Pager *pPager){
pPager->dirtyCache = 0;
pPager->nRec = 0;
}else{
assert( pPager->aInJournal==0 );
assert( pPager->dirtyCache==0 || pPager->useJournal==0 );
}
rc = sqlite3OsUnlock(&pPager->fd, SHARED_LOCK);
@@ -935,6 +982,12 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
u32 cksum; /* Checksum used for sanity checking */
u8 aData[SQLITE_MAX_PAGE_SIZE]; /* Temp storage for a page */
/* useCksum should be true for the main journal and false for
** statement journals. Verify that this is always the case
*/
assert( jfd == (useCksum ? &pPager->jfd : &pPager->stfd) );
rc = read32bits(jfd, &pgno);
if( rc!=SQLITE_OK ) return rc;
rc = sqlite3OsRead(jfd, &aData, pPager->pageSize);
@@ -969,13 +1022,29 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
**
** If in EXCLUSIVE state, then we update the pager cache if it exists
** and the main file. The page is then marked not dirty.
**
** Ticket #1171: The statement journal might contain page content that is
** different from the page content at the start of the transaction.
** This occurs when a page is changed prior to the start of a statement
** then changed again within the statement. When rolling back such a
** statement we must not write to the original database unless we know
** for certain that original page contents are in the main rollback
** journal. Otherwise, if a full ROLLBACK occurs after the statement
** rollback the full ROLLBACK will not restore the page to its original
** content. Two conditions must be met before writing to the database
** files. (1) the database must be locked. (2) we know that the original
** page content is in the main journal either because the page is not in
** cache or else it is marked as needSync==0.
*/
pPg = pager_lookup(pPager, pgno);
assert( pPager->state>=PAGER_EXCLUSIVE || pPg );
assert( pPager->state>=PAGER_EXCLUSIVE || pPg!=0 );
TRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno);
if( pPager->state>=PAGER_EXCLUSIVE ){
sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize);
if( pPager->state>=PAGER_EXCLUSIVE && (pPg==0 || pPg->needSync==0) ){
rc = sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
if( rc==SQLITE_OK ){
rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize);
}
if( pPg ) pPg->dirty = 0;
}
if( pPg ){
/* No page should ever be explicitly rolled back that is in use, except
@@ -991,13 +1060,9 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
if( pPager->xDestructor ){ /*** FIX ME: Should this be xReinit? ***/
pPager->xDestructor(pData, pPager->pageSize);
}
if( pPager->state>=PAGER_EXCLUSIVE ){
pPg->dirty = 0;
pPg->needSync = 0;
#ifdef SQLITE_CHECK_PAGES
pPg->pageHash = pager_pagehash(pPg);
pPg->pageHash = pager_pagehash(pPg);
#endif
}
CODEC(pPager, pData, pPg->pgno, 3);
}
return rc;
@@ -1107,8 +1172,10 @@ static int pager_reload_cache(Pager *pPager){
char zBuf[SQLITE_MAX_PAGE_SIZE];
if( !pPg->dirty ) continue;
if( (int)pPg->pgno <= pPager->origDbSize ){
sqlite3OsSeek(&pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1));
rc = sqlite3OsRead(&pPager->fd, zBuf, pPager->pageSize);
rc = sqlite3OsSeek(&pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1));
if( rc==SQLITE_OK ){
rc = sqlite3OsRead(&pPager->fd, zBuf, pPager->pageSize);
}
TRACE3("REFETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
if( rc ) break;
CODEC(pPager, zBuf, pPg->pgno, 2);
@@ -1424,7 +1491,7 @@ static int pager_stmt_playback(Pager *pPager){
end_stmt_playback:
if( rc!=SQLITE_OK ){
pPager->errMask |= PAGER_ERR_CORRUPT;
rc = SQLITE_CORRUPT; /* bkpt-CORRUPT */
rc = SQLITE_CORRUPT;
}else{
pPager->journalOff = szJ;
/* pager_reload_cache(pPager); */
@@ -1434,22 +1501,8 @@ end_stmt_playback:
/*
** Change the maximum number of in-memory pages that are allowed.
**
** The maximum number is the absolute value of the mxPage parameter.
** If mxPage is negative, the noSync flag is also set. noSync bypasses
** calls to sqlite3OsSync(). The pager runs much faster with noSync on,
** but if the operating system crashes or there is an abrupt power
** failure, the database file might be left in an inconsistent and
** unrepairable state.
*/
void sqlite3pager_set_cachesize(Pager *pPager, int mxPage){
if( mxPage>=0 ){
pPager->noSync = pPager->tempFile;
if( pPager->noSync ) pPager->needSync = 0;
}else{
pPager->noSync = 1;
mxPage = -mxPage;
}
if( mxPage>10 ){
pPager->mxPage = mxPage;
}else{
@@ -1492,8 +1545,15 @@ void sqlite3pager_set_safety_level(Pager *pPager, int level){
#endif
/*
** Open a temporary file. Write the name of the file into zName
** (zName must be at least SQLITE_TEMPNAME_SIZE bytes long.) Write
** The following global variable is incremented whenever the library
** attempts to open a temporary file. This information is used for
** testing and analysis only.
*/
int sqlite3_opentemp_count = 0;
/*
** Open a temporary file. Write the name of the file into zFile
** (zFile must be at least SQLITE_TEMPNAME_SIZE bytes long.) Write
** the file descriptor into *fd. Return SQLITE_OK on success or some
** other error code if we fail.
**
@@ -1503,6 +1563,7 @@ void sqlite3pager_set_safety_level(Pager *pPager, int level){
static int sqlite3pager_opentemp(char *zFile, OsFile *fd){
int cnt = 8;
int rc;
sqlite3_opentemp_count++; /* Used for testing and analysis only */
do{
cnt--;
sqlite3OsTempFileName(zFile);
@@ -1610,10 +1671,10 @@ int sqlite3pager_open(
pPager->nRef = 0;
pPager->dbSize = memDb-1;
pPager->pageSize = SQLITE_DEFAULT_PAGE_SIZE;
pPager->psAligned = FORCE_ALIGNMENT(pPager->pageSize);
pPager->stmtSize = 0;
pPager->stmtJSize = 0;
pPager->nPage = 0;
pPager->nMaxPage = 0;
pPager->mxPage = 100;
pPager->state = PAGER_UNLOCK;
pPager->errMask = 0;
@@ -1665,14 +1726,16 @@ void sqlite3pager_set_reiniter(Pager *pPager, void (*xReinit)(void*,int)){
}
/*
** Set the page size.
**
** The page size must only be changed when the cache is empty.
** Set the page size. Return the new size. If the suggest new page
** size is inappropriate, then an alternative page size is selected
** and returned.
*/
void sqlite3pager_set_pagesize(Pager *pPager, int pageSize){
int sqlite3pager_set_pagesize(Pager *pPager, int pageSize){
assert( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE );
pPager->pageSize = pageSize;
pPager->psAligned = FORCE_ALIGNMENT(pageSize);
if( !pPager->memDb ){
pPager->pageSize = pageSize;
}
return pPager->pageSize;
}
/*
@@ -1689,25 +1752,35 @@ void sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){
/*
** Return the total number of pages in the disk file associated with
** pPager.
** pPager.
**
** If the PENDING_BYTE lies on the page directly after the end of the
** file, then consider this page part of the file too. For example, if
** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the
** file is 4096 bytes, 5 is returned instead of 4.
*/
int sqlite3pager_pagecount(Pager *pPager){
i64 n;
assert( pPager!=0 );
if( pPager->dbSize>=0 ){
return pPager->dbSize;
n = pPager->dbSize;
} else {
if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){
pPager->errMask |= PAGER_ERR_DISK;
return 0;
}
if( n>0 && n<pPager->pageSize ){
n = 1;
}else{
n /= pPager->pageSize;
}
if( pPager->state!=PAGER_UNLOCK ){
pPager->dbSize = n;
}
}
if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){
pPager->errMask |= PAGER_ERR_DISK;
return 0;
}
n /= pPager->pageSize;
if( !MEMDB && n==PENDING_BYTE/pPager->pageSize ){
if( n==(PENDING_BYTE/pPager->pageSize) ){
n++;
}
if( pPager->state!=PAGER_UNLOCK ){
pPager->dbSize = n;
}
return n;
}
@@ -1809,7 +1882,7 @@ static void memoryTruncate(Pager *pPager){
/*
** Try to obtain a lock on a file. Invoke the busy callback if the lock
** is currently not available. Repeate until the busy callback returns
** is currently not available. Repeat until the busy callback returns
** false or until the lock succeeds.
**
** Return SQLITE_OK on success and an error code if we cannot obtain
@@ -1823,14 +1896,9 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
if( pPager->state>=locktype ){
rc = SQLITE_OK;
}else{
int busy = 1;
do {
rc = sqlite3OsLock(&pPager->fd, locktype);
}while( rc==SQLITE_BUSY &&
pPager->pBusyHandler &&
pPager->pBusyHandler->xFunc &&
pPager->pBusyHandler->xFunc(pPager->pBusyHandler->pArg, busy++)
);
}while( rc==SQLITE_BUSY && sqlite3InvokeBusyHandler(pPager->pBusyHandler) );
if( rc==SQLITE_OK ){
pPager->state = locktype;
}
@@ -1905,7 +1973,7 @@ int sqlite3pager_close(Pager *pPager){
if( !MEMDB ){
sqlite3OsUnlock(&pPager->fd, NO_LOCK);
}
assert( pPager->journalOpen==0 );
assert( pPager->errMask || pPager->journalOpen==0 );
break;
}
case PAGER_SHARED: {
@@ -1932,8 +2000,15 @@ int sqlite3pager_close(Pager *pPager){
sqliteFree(pPg);
}
TRACE2("CLOSE %d\n", PAGERID(pPager));
assert( pPager->errMask || (pPager->journalOpen==0 && pPager->stmtOpen==0) );
if( pPager->journalOpen ){
sqlite3OsClose(&pPager->jfd);
}
sqliteFree(pPager->aInJournal);
if( pPager->stmtOpen ){
sqlite3OsClose(&pPager->stfd);
}
sqlite3OsClose(&pPager->fd);
assert( pPager->journalOpen==0 );
/* Temp files are automatically deleted by the OS
** if( pPager->tempFile ){
** sqlite3OsDelete(pPager->zFilename);
@@ -2058,17 +2133,20 @@ static int syncJournal(Pager *pPager){
*/
if( pPager->fullSync ){
TRACE2("SYNC journal of %d\n", PAGERID(pPager));
rc = sqlite3OsSync(&pPager->jfd);
rc = sqlite3OsSync(&pPager->jfd, 0);
if( rc!=0 ) return rc;
}
sqlite3OsSeek(&pPager->jfd, pPager->journalHdr + sizeof(aJournalMagic));
rc = sqlite3OsSeek(&pPager->jfd,
pPager->journalHdr + sizeof(aJournalMagic));
if( rc ) return rc;
rc = write32bits(&pPager->jfd, pPager->nRec);
if( rc ) return rc;
sqlite3OsSeek(&pPager->jfd, pPager->journalOff);
rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff);
if( rc ) return rc;
}
TRACE2("SYNC journal of %d\n", PAGERID(pPager));
rc = sqlite3OsSync(&pPager->jfd);
rc = sqlite3OsSync(&pPager->jfd, pPager->fullSync);
if( rc!=0 ) return rc;
pPager->journalStarted = 1;
}
@@ -2133,7 +2211,8 @@ static int pager_write_pagelist(PgHdr *pList){
while( pList ){
assert( pList->dirty );
sqlite3OsSeek(&pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize);
rc = sqlite3OsSeek(&pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize);
if( rc ) return rc;
/* If there are dirty pages in the page cache with page numbers greater
** than Pager.dbSize, this means sqlite3pager_truncate() was called to
** make the file smaller (presumably by auto-vacuum code). Do not write
@@ -2144,7 +2223,7 @@ static int pager_write_pagelist(PgHdr *pList){
TRACE3("STORE %d page %d\n", PAGERID(pPager), pList->pgno);
rc = sqlite3OsWrite(&pPager->fd, PGHDR_TO_DATA(pList), pPager->pageSize);
CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 0);
pPager->nWrite++;
TEST_INCR(pPager->nWrite);
}
#ifndef NDEBUG
else{
@@ -2178,6 +2257,26 @@ static PgHdr *pager_get_all_dirty_pages(Pager *pPager){
return pList;
}
/*
** Return TRUE if there is a hot journal on the given pager.
** A hot journal is one that needs to be played back.
**
** If the current size of the database file is 0 but a journal file
** exists, that is probably an old journal left over from a prior
** database with the same name. Just delete the journal.
*/
static int hasHotJournal(Pager *pPager){
if( !pPager->useJournal ) return 0;
if( !sqlite3OsFileExists(pPager->zJournal) ) return 0;
if( sqlite3OsCheckReservedLock(&pPager->fd) ) return 0;
if( sqlite3pager_pagecount(pPager)==0 ){
sqlite3OsDelete(pPager->zJournal);
return 0;
}else{
return 1;
}
}
/*
** Acquire a page.
**
@@ -2203,13 +2302,13 @@ static PgHdr *pager_get_all_dirty_pages(Pager *pPager){
*/
int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
PgHdr *pPg;
int rc, n;
int rc;
/* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
** number greater than this, or zero, is requested.
*/
if( pgno>PAGER_MAX_PGNO || pgno==0 ){
return SQLITE_CORRUPT;
if( pgno>PAGER_MAX_PGNO || pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
return SQLITE_CORRUPT_BKPT;
}
/* Make sure we have not hit any critical errors.
@@ -2234,10 +2333,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
/* If a journal file exists, and there is no RESERVED lock on the
** database file, then it either needs to be played back or deleted.
*/
if( pPager->useJournal &&
sqlite3OsFileExists(pPager->zJournal) &&
!sqlite3OsCheckReservedLock(&pPager->fd)
){
if( hasHotJournal(pPager) ){
int rc;
/* Get an EXCLUSIVE lock on the database file. At this point it is
@@ -2298,16 +2394,13 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
if( pPg==0 ){
/* The requested page is not in the page cache. */
int h;
pPager->nMiss++;
TEST_INCR(pPager->nMiss);
if( pPager->nPage<pPager->mxPage || pPager->pFirst==0 || MEMDB ){
/* Create a new page */
pPg = sqliteMallocRaw( sizeof(*pPg) + pPager->psAligned
pPg = sqliteMallocRaw( sizeof(*pPg) + pPager->pageSize
+ sizeof(u32) + pPager->nExtra
+ MEMDB*sizeof(PgHistory) );
if( pPg==0 ){
if( !MEMDB ){
pager_unwritelock(pPager);
}
pPager->errMask |= PAGER_ERR_MEM;
return SQLITE_NOMEM;
}
@@ -2319,6 +2412,10 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
pPg->pNextAll = pPager->pAll;
pPager->pAll = pPg;
pPager->nPage++;
if( pPager->nPage>pPager->nMaxPage ){
assert( pPager->nMaxPage==(pPager->nPage-1) );
pPager->nMaxPage++;
}
}else{
/* Find a page to recycle. Try to locate a page that does not
** require us to do an fsync() on the journal.
@@ -2383,7 +2480,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
/* Unlink the old page from the free list and the hash table
*/
unlinkPage(pPg);
pPager->nOvfl++;
TEST_INCR(pPager->nOvfl);
}
pPg->pgno = pgno;
if( pPager->aInJournal && (int)pgno<=pPager->origDbSize ){
@@ -2415,19 +2512,20 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
if( pPager->nExtra>0 ){
memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra);
}
n = sqlite3pager_pagecount(pPager);
if( pPager->errMask!=0 ){
sqlite3pager_unref(PGHDR_TO_DATA(pPg));
rc = pager_errcode(pPager);
return rc;
}
if( n<(int)pgno ){
if( sqlite3pager_pagecount(pPager)<(int)pgno ){
memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
}else{
int rc;
assert( MEMDB==0 );
sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
rc = sqlite3OsRead(&pPager->fd, PGHDR_TO_DATA(pPg), pPager->pageSize);
rc = sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
if( rc==SQLITE_OK ){
rc = sqlite3OsRead(&pPager->fd, PGHDR_TO_DATA(pPg), pPager->pageSize);
}
TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
if( rc!=SQLITE_OK ){
@@ -2440,7 +2538,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
}
}else{
pPager->nRead++;
TEST_INCR(pPager->nRead);
}
}
#ifdef SQLITE_CHECK_PAGES
@@ -2448,7 +2546,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
#endif
}else{
/* The requested page is in the page cache. */
pPager->nHit++;
TEST_INCR(pPager->nHit);
page_ref(pPg);
}
*ppPage = PGHDR_TO_DATA(pPg);
@@ -2546,6 +2644,7 @@ static int pager_open_journal(Pager *pPager){
assert( pPager->state>=PAGER_RESERVED );
assert( pPager->journalOpen==0 );
assert( pPager->useJournal );
assert( pPager->aInJournal==0 );
sqlite3pager_pagecount(pPager);
pPager->aInJournal = sqliteMalloc( pPager->dbSize/8 + 1 );
if( pPager->aInJournal==0 ){
@@ -2559,6 +2658,8 @@ static int pager_open_journal(Pager *pPager){
if( rc!=SQLITE_OK ){
goto failed_to_open_journal;
}
SET_FULLSYNC(pPager->jfd, pPager->fullSync);
SET_FULLSYNC(pPager->fd, pPager->fullSync);
sqlite3OsOpenDirectory(pPager->zDirectory, &pPager->jfd);
pPager->journalOpen = 1;
pPager->journalStarted = 0;
@@ -2567,7 +2668,7 @@ static int pager_open_journal(Pager *pPager){
pPager->nRec = 0;
if( pPager->errMask!=0 ){
rc = pager_errcode(pPager);
return rc;
goto failed_to_open_journal;
}
pPager->origDbSize = pPager->dbSize;
@@ -2631,11 +2732,7 @@ int sqlite3pager_begin(void *pData, int exFlag){
pPager->state = PAGER_EXCLUSIVE;
pPager->origDbSize = pPager->dbSize;
}else{
if( SQLITE_BUSY_RESERVED_LOCK || exFlag ){
rc = pager_wait_on_lock(pPager, RESERVED_LOCK);
}else{
rc = sqlite3OsLock(&pPager->fd, RESERVED_LOCK);
}
rc = sqlite3OsLock(&pPager->fd, RESERVED_LOCK);
if( rc==SQLITE_OK ){
pPager->state = PAGER_RESERVED;
if( exFlag ){
@@ -2736,6 +2833,10 @@ int sqlite3pager_write(void *pData){
}
}else{
u32 cksum;
/* We should never write to the journal file the page that
** contains the database locks. The following assert verifies
** that we do not. */
assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
CODEC(pPager, pData, pPg->pgno, 7);
cksum = pager_cksum(pPager, pPg->pgno, pData);
saved = *(u32*)PGHDR_TO_EXTRA(pPg, pPager);
@@ -2880,7 +2981,7 @@ void sqlite3pager_dont_write(Pager *pPager, Pgno pgno){
pPg = pager_lookup(pPager, pgno);
pPg->alwaysRollback = 1;
if( pPg && pPg->dirty ){
if( pPg && pPg->dirty && !pPager->stmtInUse ){
if( pPager->dbSize==(int)pPg->pgno && pPager->origDbSize<pPager->dbSize ){
/* If this pages is the last page in the file and the file has grown
** during the current transaction, then do NOT mark the page as clean.
@@ -3092,7 +3193,7 @@ int sqlite3pager_rollback(Pager *pPager){
rc = pager_playback(pPager);
}
if( rc!=SQLITE_OK ){
rc = SQLITE_CORRUPT; /* bkpt-CORRUPT */
rc = SQLITE_CORRUPT_BKPT;
pPager->errMask |= PAGER_ERR_CORRUPT;
}
pPager->dbSize = -1;
@@ -3118,11 +3219,13 @@ int *sqlite3pager_stats(Pager *pPager){
a[3] = pPager->dbSize;
a[4] = pPager->state;
a[5] = pPager->errMask;
#ifdef SQLITE_TEST
a[6] = pPager->nHit;
a[7] = pPager->nMiss;
a[8] = pPager->nOvfl;
a[9] = pPager->nRead;
a[10] = pPager->nWrite;
#endif
return a;
}
@@ -3264,6 +3367,14 @@ const char *sqlite3pager_journalname(Pager *pPager){
return pPager->zJournal;
}
/*
** Return true if fsync() calls are disabled for this pager. Return FALSE
** if fsync()s are executed normally.
*/
int sqlite3pager_nosync(Pager *pPager){
return pPager->noSync;
}
/*
** Set the codec for this pager
*/
@@ -3352,8 +3463,9 @@ int sqlite3pager_sync(Pager *pPager, const char *zMaster, Pgno nTrunc){
*/
Pgno i;
void *pPage;
int iSkip = PAGER_MJ_PGNO(pPager);
for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){
if( !(pPager->aInJournal[i/8] & (1<<(i&7))) ){
if( !(pPager->aInJournal[i/8] & (1<<(i&7))) && i!=iSkip ){
rc = sqlite3pager_get(pPager, i, &pPage);
if( rc!=SQLITE_OK ) goto sync_exit;
rc = sqlite3pager_write(pPage);
@@ -3383,7 +3495,7 @@ int sqlite3pager_sync(Pager *pPager, const char *zMaster, Pgno nTrunc){
/* Sync the database file. */
if( !pPager->noSync ){
rc = sqlite3OsSync(&pPager->fd);
rc = sqlite3OsSync(&pPager->fd, 0);
}
pPager->state = PAGER_SYNCED;
@@ -3406,8 +3518,10 @@ sync_exit:
** meta-data associated with page pData (i.e. data stored in the nExtra bytes
** allocated along with the page) is the responsibility of the caller.
**
** A transaction must be active when this routine is called, however it is
** illegal to call this routine if a statment transaction is active.
** A transaction must be active when this routine is called. It used to be
** required that a statement transaction was not active, but this restriction
** has been removed (CREATE INDEX needs to move a page when a statement
** transaction is active).
*/
int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){
PgHdr *pPg = DATA_TO_PGHDR(pData);
@@ -3415,7 +3529,6 @@ int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){
int h;
Pgno needSyncPgno = 0;
assert( !pPager->stmtInUse );
assert( pPg->nRef>0 );
TRACE5("MOVE %d page %d (needSync=%d) moves to %d\n",
@@ -3517,3 +3630,5 @@ void sqlite3pager_refdump(Pager *pPager){
}
}
#endif
#endif /* SQLITE_OMIT_DISKIO */
+14 -9
View File
@@ -13,7 +13,7 @@
** subsystem. The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
**
** @(#) $Id: pager.h,v 1.41 2005/02/06 02:45:42 drh Exp $
** @(#) $Id: pager.h,v 1.46 2005/09/19 19:05:21 drh Exp $
*/
/*
@@ -23,15 +23,18 @@
# define SQLITE_DEFAULT_PAGE_SIZE 1024
#endif
/* Maximum page size. The upper bound on this value is 65536 (a limit
** imposed by the 2-byte size of cell array pointers.) The
** maximum page size determines the amount of stack space allocated
** by many of the routines in pager.c and btree.c On embedded architectures
** or any machine where memory and especially stack memory is limited,
** one may wish to chose a smaller value for the maximum page size.
/* Maximum page size. The upper bound on this value is 32768. This a limit
** imposed by necessity of storing the value in a 2-byte unsigned integer
** and the fact that the page size must be a power of 2.
**
** This value is used to initialize certain arrays on the stack at
** various places in the code. On embedded machines where stack space
** is limited and the flexibility of having large pages is not needed,
** it makes good sense to reduce the maximum page size to something more
** reasonable, like 1024.
*/
#ifndef SQLITE_MAX_PAGE_SIZE
# define SQLITE_MAX_PAGE_SIZE 8192
# define SQLITE_MAX_PAGE_SIZE 32768
#endif
/*
@@ -68,7 +71,7 @@ int sqlite3pager_open(Pager **ppPager, const char *zFilename,
void sqlite3pager_set_busyhandler(Pager*, BusyHandler *pBusyHandler);
void sqlite3pager_set_destructor(Pager*, void(*)(void*,int));
void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int));
void sqlite3pager_set_pagesize(Pager*, int);
int sqlite3pager_set_pagesize(Pager*, int);
void sqlite3pager_read_fileheader(Pager*, int, unsigned char*);
void sqlite3pager_set_cachesize(Pager*, int);
int sqlite3pager_close(Pager *pPager);
@@ -97,9 +100,11 @@ void sqlite3pager_set_safety_level(Pager*,int);
const char *sqlite3pager_filename(Pager*);
const char *sqlite3pager_dirname(Pager*);
const char *sqlite3pager_journalname(Pager*);
int sqlite3pager_nosync(Pager*);
int sqlite3pager_rename(Pager*, const char *zNewName);
void sqlite3pager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);
int sqlite3pager_movepage(Pager*,void*,Pgno);
int sqlite3pager_reset(Pager*);
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
int sqlite3pager_lockstate(Pager*);
+139 -45
View File
@@ -14,12 +14,23 @@
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.166 2005/02/14 06:38:40 danielk1977 Exp $
** @(#) $Id: parse.y,v 1.180 2005/09/16 02:38:10 drh Exp $
*/
// All token codes are small integers with #defines that begin with "TK_"
%token_prefix TK_
// The type of the data attached to each token is Token. This is also the
// default type for non-terminals.
//
%token_type {Token}
%default_type {Token}
// The generated parser function takes a 4th argument as follows:
%extra_argument {Parse *pParse}
// This code runs whenever there is a syntax error
//
%syntax_error {
if( pParse->zErrMsg==0 ){
if( TOKEN.z[0] ){
@@ -29,7 +40,14 @@
}
}
}
// The name of the generated procedure that implements the parser
// is as follows:
%name sqlite3Parser
// The following text is included near the beginning of the C source
// code file that implements the parser.
//
%include {
#include "sqliteInt.h"
#include "parse.h"
@@ -48,8 +66,8 @@ struct LimitVal {
** GLOB, NOT LIKE, and NOT GLOB operators.
*/
struct LikeOp {
int opcode; /* Either TK_GLOB or TK_LIKE */
int not; /* True if the NOT keyword is present */
Token operator; /* "like" or "glob" or "regexp" */
int not; /* True if the NOT keyword is present */
};
/*
@@ -75,7 +93,7 @@ struct AttachKey { int type; Token key; };
// add them to the parse.h output file.
//
%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
COLUMN AGG_FUNCTION.
COLUMN AGG_FUNCTION AGG_COLUMN CONST_FUNC.
// Input is a single SQL command
input ::= cmdlist.
@@ -86,7 +104,8 @@ ecmd ::= SEMI.
ecmd ::= explain cmdx SEMI.
explain ::= . { sqlite3BeginParse(pParse, 0); }
%ifndef SQLITE_OMIT_EXPLAIN
explain ::= EXPLAIN. { sqlite3BeginParse(pParse, 1); }
explain ::= EXPLAIN. { sqlite3BeginParse(pParse, 1); }
explain ::= EXPLAIN QUERY PLAN. { sqlite3BeginParse(pParse, 2); }
%endif
///////////////////// Begin and end transactions. ////////////////////////////
@@ -112,24 +131,34 @@ create_table ::= CREATE(X) temp(T) TABLE nm(Y) dbnm(Z). {
sqlite3StartTable(pParse,&X,&Y,&Z,T,0);
}
%type temp {int}
%ifndef SQLITE_OMIT_TEMPDB
temp(A) ::= TEMP. {A = 1;}
%endif
temp(A) ::= . {A = 0;}
create_table_args ::= LP columnlist conslist_opt RP(X). {
sqlite3EndTable(pParse,&X,0);
create_table_args ::= LP columnlist conslist_opt(X) RP(Y). {
sqlite3EndTable(pParse,&X,&Y,0);
}
create_table_args ::= AS select(S). {
sqlite3EndTable(pParse,0,S);
sqlite3EndTable(pParse,0,0,S);
sqlite3SelectDelete(S);
}
columnlist ::= columnlist COMMA column.
columnlist ::= column.
// About the only information used for a column is the name of the
// column. The type is always just "text". But the code will accept
// an elaborate typename. Perhaps someday we'll do something with it.
// A "column" is a complete description of a single column in a
// CREATE TABLE statement. This includes the column name, its
// datatype, and other keywords such as PRIMARY KEY, UNIQUE, REFERENCES,
// NOT NULL and so forth.
//
column ::= columnid type carglist.
columnid ::= nm(X). {sqlite3AddColumn(pParse,&X);}
column(A) ::= columnid(X) type carglist. {
A.z = X.z;
A.n = (pParse->sLastToken.z-X.z) + pParse->sLastToken.n;
}
columnid(A) ::= nm(X). {
sqlite3AddColumn(pParse,&X);
A = X;
}
// An IDENTIFIER can be a generic identifier, or one of several
// keywords. Any non-standard keyword can also be an identifier.
@@ -142,15 +171,15 @@ id(A) ::= ID(X). {A = X;}
// This obviates the need for the "id" nonterminal.
//
%fallback ID
ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CONFLICT
ABORT AFTER ANALYZE ASC ATTACH BEFORE BEGIN CASCADE CAST CONFLICT
DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR
GLOB IGNORE IMMEDIATE INITIALLY INSTEAD LIKE MATCH KEY
IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH PLAN QUERY KEY
OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT
TEMP TRIGGER VACUUM VIEW
%ifdef SQLITE_OMIT_COMPOUND_SELECT
EXCEPT INTERSECT UNION
%endif
REINDEX RENAME CDATE CTIME CTIMESTAMP ALTER
REINDEX RENAME CTIME_KW ALTER
.
// Define operator precedence early so that this is the first occurance
@@ -167,7 +196,7 @@ id(A) ::= ID(X). {A = X;}
%left OR.
%left AND.
%right NOT.
%left IS LIKE GLOB BETWEEN IN ISNULL NOTNULL NE EQ.
%left IS LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ.
%left GT LE LT GE.
%right ESCAPE.
%left BITAND BITOR LSHIFT RSHIFT.
@@ -189,22 +218,38 @@ nm(A) ::= ID(X). {A = X;}
nm(A) ::= STRING(X). {A = X;}
nm(A) ::= JOIN_KW(X). {A = X;}
// A typetoken is really one or more tokens that form a type name such
// as can be found after the column name in a CREATE TABLE statement.
// Multiple tokens are concatenated to form the value of the typetoken.
//
%type typetoken {Token}
type ::= .
type ::= typename(X). {sqlite3AddColumnType(pParse,&X,&X);}
type ::= typename(X) LP signed RP(Y). {sqlite3AddColumnType(pParse,&X,&Y);}
type ::= typename(X) LP signed COMMA signed RP(Y).
{sqlite3AddColumnType(pParse,&X,&Y);}
type ::= typetoken(X). {sqlite3AddColumnType(pParse,&X);}
typetoken(A) ::= typename(X). {A = X;}
typetoken(A) ::= typename(X) LP signed RP(Y). {
A.z = X.z;
A.n = &Y.z[Y.n] - X.z;
}
typetoken(A) ::= typename(X) LP signed COMMA signed RP(Y). {
A.z = X.z;
A.n = &Y.z[Y.n] - X.z;
}
%type typename {Token}
typename(A) ::= ids(X). {A = X;}
typename(A) ::= typename(X) ids(Y). {A.z=X.z; A.n=Y.n+(Y.z-X.z);}
%type signed {int}
signed(A) ::= plus_num(X). { A = atoi(X.z); }
signed(A) ::= minus_num(X). { A = -atoi(X.z); }
// "carglist" is a list of additional constraints that come after the
// column name and column type in a CREATE TABLE statement.
//
carglist ::= carglist carg.
carglist ::= .
carg ::= CONSTRAINT nm ccons.
carg ::= ccons.
carg ::= DEFAULT term(X). {sqlite3AddDefaultValue(pParse,X);}
carg ::= DEFAULT LP expr(X) RP. {sqlite3AddDefaultValue(pParse,X);}
carg ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,X);}
carg ::= DEFAULT MINUS term(X). {
Expr *p = sqlite3Expr(TK_UMINUS, X, 0, 0);
@@ -223,7 +268,7 @@ ccons ::= NOT NULL onconf(R). {sqlite3AddNotNull(pParse, R);}
ccons ::= PRIMARY KEY sortorder onconf(R) autoinc(I).
{sqlite3AddPrimaryKey(pParse,0,R,I);}
ccons ::= UNIQUE onconf(R). {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0);}
ccons ::= CHECK LP expr RP onconf.
ccons ::= CHECK LP expr(X) RP onconf. {sqlite3ExprDelete(X);}
ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R).
{sqlite3CreateForeignKey(pParse,0,&T,TA,R);}
ccons ::= defer_subclause(D). {sqlite3DeferForeignKey(pParse,D);}
@@ -263,8 +308,8 @@ init_deferred_pred_opt(A) ::= INITIALLY IMMEDIATE. {A = 0;}
// For the time being, the only constraint we care about is the primary
// key and UNIQUE. Both create indices.
//
conslist_opt ::= .
conslist_opt ::= COMMA conslist.
conslist_opt(A) ::= . {A.n = 0; A.z = 0;}
conslist_opt(A) ::= COMMA(X) conslist. {A = X;}
conslist ::= conslist COMMA tcons.
conslist ::= conslist tcons.
conslist ::= tcons.
@@ -534,14 +579,14 @@ cmd ::= DELETE FROM fullname(X) where_opt(Y). {sqlite3DeleteFrom(pParse,X,Y);}
where_opt(A) ::= . {A = 0;}
where_opt(A) ::= WHERE expr(X). {A = X;}
%type setlist {ExprList*}
%destructor setlist {sqlite3ExprListDelete($$);}
////////////////////////// The UPDATE command ////////////////////////////////
//
cmd ::= UPDATE orconf(R) fullname(X) SET setlist(Y) where_opt(Z).
{sqlite3Update(pParse,X,Y,Z,R);}
%type setlist {ExprList*}
%destructor setlist {sqlite3ExprListDelete($$);}
setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y).
{A = sqlite3ExprListAppend(Z,Y,&X);}
setlist(A) ::= nm(X) EQ expr(Y). {A = sqlite3ExprListAppend(0,Y,&X);}
@@ -603,24 +648,36 @@ expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
term(A) ::= INTEGER(X). {A = sqlite3Expr(@X, 0, 0, &X);}
term(A) ::= FLOAT(X). {A = sqlite3Expr(@X, 0, 0, &X);}
term(A) ::= STRING(X). {A = sqlite3Expr(@X, 0, 0, &X);}
expr(A) ::= BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);}
term(A) ::= BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);}
expr(A) ::= REGISTER(X). {A = sqlite3RegisterExpr(pParse, &X);}
expr(A) ::= VARIABLE(X). {
Token *pToken = &X;
Expr *pExpr = A = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
sqlite3ExprAssignVarNumber(pParse, pExpr);
}
expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
%ifndef SQLITE_OMIT_CAST
expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). {
A = sqlite3Expr(TK_CAST, E, 0, &T);
sqlite3ExprSpan(A,&X,&Y);
}
%endif // SQLITE_OMIT_CAST
expr(A) ::= ID(X) LP distinct(D) exprlist(Y) RP(E). {
A = sqlite3ExprFunction(Y, &X);
sqlite3ExprSpan(A,&X,&E);
if( D ){
A->flags |= EP_Distinct;
}
}
expr(A) ::= ID(X) LP STAR RP(E). {
A = sqlite3ExprFunction(0, &X);
sqlite3ExprSpan(A,&X,&E);
}
term(A) ::= CTIME(OP). {A = sqlite3Expr(@OP,0,0,0);}
term(A) ::= CDATE(OP). {A = sqlite3Expr(@OP,0,0,0);}
term(A) ::= CTIMESTAMP(OP). {A = sqlite3Expr(@OP,0,0,0);}
term(A) ::= CTIME_KW(OP). {
/* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
** treated as functions that return constants */
A = sqlite3ExprFunction(0,&OP);
if( A ) A->op = TK_CONST_FUNC;
}
expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
expr(A) ::= expr(X) LT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
@@ -640,21 +697,18 @@ expr(A) ::= expr(X) SLASH(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
expr(A) ::= expr(X) REM(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
%type likeop {struct LikeOp}
likeop(A) ::= LIKE. {A.opcode = TK_LIKE; A.not = 0;}
likeop(A) ::= GLOB. {A.opcode = TK_GLOB; A.not = 0;}
likeop(A) ::= NOT LIKE. {A.opcode = TK_LIKE; A.not = 1;}
likeop(A) ::= NOT GLOB. {A.opcode = TK_GLOB; A.not = 1;}
likeop(A) ::= LIKE_KW(X). {A.operator = X; A.not = 0;}
likeop(A) ::= NOT LIKE_KW(X). {A.operator = X; A.not = 1;}
%type escape {Expr*}
escape(X) ::= ESCAPE expr(A). [ESCAPE] {X = A;}
escape(X) ::= . [ESCAPE] {X = 0;}
expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E). [LIKE] {
expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E). [LIKE_KW] {
ExprList *pList = sqlite3ExprListAppend(0, Y, 0);
pList = sqlite3ExprListAppend(pList, X, 0);
if( E ){
pList = sqlite3ExprListAppend(pList, E, 0);
}
A = sqlite3ExprFunction(pList, 0);
if( A ) A->op = OP.opcode;
A = sqlite3ExprFunction(pList, &OP.operator);
if( OP.not ) A = sqlite3Expr(TK_NOT, A, 0, 0);
sqlite3ExprSpan(A, &X->span, &Y->span);
}
@@ -702,7 +756,11 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
ExprList *pList = sqlite3ExprListAppend(0, X, 0);
pList = sqlite3ExprListAppend(pList, Y, 0);
A = sqlite3Expr(TK_BETWEEN, W, 0, 0);
if( A ) A->pList = pList;
if( A ){
A->pList = pList;
}else{
sqlite3ExprListDelete(pList);
}
if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
sqlite3ExprSpan(A,&W->span,&Y->span);
}
@@ -712,25 +770,41 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
in_op(A) ::= NOT IN. {A = 1;}
expr(A) ::= expr(X) in_op(N) LP exprlist(Y) RP(E). [IN] {
A = sqlite3Expr(TK_IN, X, 0, 0);
if( A ) A->pList = Y;
if( A ){
A->pList = Y;
}else{
sqlite3ExprListDelete(Y);
}
if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
sqlite3ExprSpan(A,&X->span,&E);
}
expr(A) ::= LP(B) select(X) RP(E). {
A = sqlite3Expr(TK_SELECT, 0, 0, 0);
if( A ) A->pSelect = X;
if( A ){
A->pSelect = X;
}else{
sqlite3SelectDelete(X);
}
sqlite3ExprSpan(A,&B,&E);
}
expr(A) ::= expr(X) in_op(N) LP select(Y) RP(E). [IN] {
A = sqlite3Expr(TK_IN, X, 0, 0);
if( A ) A->pSelect = Y;
if( A ){
A->pSelect = Y;
}else{
sqlite3SelectDelete(Y);
}
if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
sqlite3ExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) in_op(N) nm(Y) dbnm(Z). [IN] {
SrcList *pSrc = sqlite3SrcListAppend(0,&Y,&Z);
A = sqlite3Expr(TK_IN, X, 0, 0);
if( A ) A->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0);
if( A ){
A->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0);
}else{
sqlite3SrcListDelete(pSrc);
}
if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
sqlite3ExprSpan(A,&X->span,Z.z?&Z:&Y);
}
@@ -739,6 +813,8 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
if( p ){
p->pSelect = Y;
sqlite3ExprSpan(p,&B,&E);
}else{
sqlite3SelectDelete(Y);
}
}
%endif // SQLITE_OMIT_SUBQUERY
@@ -746,7 +822,11 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
/* CASE expressions */
expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
A = sqlite3Expr(TK_CASE, X, Z, 0);
if( A ) A->pList = Y;
if( A ){
A->pList = Y;
}else{
sqlite3ExprListDelete(Y);
}
sqlite3ExprSpan(A, &C, &E);
}
%type case_exprlist {ExprList*}
@@ -963,9 +1043,23 @@ cmd ::= REINDEX. {sqlite3Reindex(pParse, 0, 0);}
cmd ::= REINDEX nm(X) dbnm(Y). {sqlite3Reindex(pParse, &X, &Y);}
%endif
/////////////////////////////////// ANALYZE ///////////////////////////////////
%ifndef SQLITE_OMIT_ANALYZE
cmd ::= ANALYZE. {sqlite3Analyze(pParse, 0, 0);}
cmd ::= ANALYZE nm(X) dbnm(Y). {sqlite3Analyze(pParse, &X, &Y);}
%endif
//////////////////////// ALTER TABLE table ... ////////////////////////////////
%ifndef SQLITE_OMIT_ALTERTABLE
cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). {
sqlite3AlterRenameTable(pParse,X,&Z);
}
cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column(Y). {
sqlite3AlterFinishAddColumn(pParse, &Y);
}
add_column_fullname ::= fullname(X). {
sqlite3AlterBeginAddColumn(pParse, X);
}
kwcolumn_opt ::= .
kwcolumn_opt ::= COLUMNKW.
%endif
+62 -39
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.89 2005/02/09 03:20:37 danielk1977 Exp $
** $Id: pragma.c,v 1.100 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -19,7 +19,7 @@
/* Ignore this whole file if pragmas are disabled
*/
#ifndef SQLITE_OMIT_PRAGMA
#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
# include "pager.h"
@@ -79,7 +79,9 @@ static int getTempStore(const char *z){
return 0;
}
}
#endif /* SQLITE_PAGER_PRAGMAS */
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
/*
** Invalidate temp storage, either when the temp storage is changed
** from default, or when 'file' and the temp_store_directory has changed
@@ -98,7 +100,9 @@ static int invalidateTempStorage(Parse *pParse){
}
return SQLITE_OK;
}
#endif /* SQLITE_PAGER_PRAGMAS */
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
/*
** If the TEMP database is open, close it and mark the database schema
** as needing reloading. This must be done when using the TEMP_STORE
@@ -114,7 +118,7 @@ static int changeTempStorage(Parse *pParse, const char *zStorageType){
db->temp_store = ts;
return SQLITE_OK;
}
#endif
#endif /* SQLITE_PAGER_PRAGMAS */
/*
** Generate code to return a single integer value.
@@ -129,6 +133,7 @@ static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
}
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
/*
** Check to see if zRight and zLeft refer to a pragma that queries
** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
@@ -177,6 +182,7 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
}
return 0;
}
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
/*
** Process a pragma statement.
@@ -428,10 +434,12 @@ void sqlite3Pragma(
}else
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
if( flagPragma(pParse, zLeft, zRight) ){
/* The flagPragma() subroutine also generates any necessary code
** there is nothing more to do here */
}else
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
/*
@@ -575,12 +583,13 @@ void sqlite3Pragma(
while(pFK){
int j;
for(j=0; j<pFK->nCol; j++){
char *zCol = pFK->aCol[j].zCol;
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
sqlite3VdbeAddOp(v, OP_Integer, j, 0);
sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);
sqlite3VdbeOp3(v, OP_String8, 0, 0,
pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->aCol[j].zCol, 0);
sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0);
sqlite3VdbeAddOp(v, OP_Callback, 5, 0);
}
++i;
@@ -594,26 +603,29 @@ void sqlite3Pragma(
#ifndef NDEBUG
if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
extern void sqlite3ParserTrace(FILE*, char *);
if( getBoolean(zRight) ){
sqlite3ParserTrace(stdout, "parser: ");
}else{
sqlite3ParserTrace(0, 0);
if( zRight ){
if( getBoolean(zRight) ){
sqlite3ParserTrace(stderr, "parser: ");
}else{
sqlite3ParserTrace(0, 0);
}
}
}else
#endif
/* Reinstall the LIKE and GLOB functions. The variant of LIKE
** used will be case sensitive or not depending on the RHS.
*/
if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
if( zRight ){
sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
}
}else
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){
int i, j, addr;
/* Code that initializes the integrity check program. Set the
** error count 0
*/
static const VdbeOpList initCode[] = {
{ OP_Integer, 0, 0, 0},
{ OP_MemStore, 0, 1, 0},
};
/* Code that appears at the end of the integrity check. If no error
** messages have been generated, output OK. Otherwise output the
** error message
@@ -630,13 +642,15 @@ void sqlite3Pragma(
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, "integrity_check", P3_STATIC);
sqlite3VdbeAddOpList(v, ArraySize(initCode), initCode);
sqlite3VdbeAddOp(v, OP_MemInt, 0, 0); /* Initialize error count to 0 */
/* Do an integrity check on each database file */
for(i=0; i<db->nDb; i++){
HashElem *x;
int cnt = 0;
if( OMIT_TEMPDB && i==1 ) continue;
sqlite3CodeVerifySchema(pParse, i);
/* Do an integrity check of the B-Tree
@@ -674,8 +688,7 @@ void sqlite3Pragma(
if( pTab->pIndex==0 ) continue;
sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
sqlite3VdbeAddOp(v, OP_MemStore, 1, 1);
sqlite3VdbeAddOp(v, OP_MemInt, 0, 1);
loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0);
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
@@ -683,7 +696,7 @@ void sqlite3Pragma(
static const VdbeOpList idxErr[] = {
{ OP_MemIncr, 0, 0, 0},
{ OP_String8, 0, 0, "rowid "},
{ OP_Recno, 1, 0, 0},
{ OP_Rowid, 1, 0, 0},
{ OP_String8, 0, 0, " missing from index "},
{ OP_String8, 0, 0, 0}, /* 4 */
{ OP_Concat, 2, 0, 0},
@@ -693,39 +706,38 @@ void sqlite3Pragma(
jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0);
addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
sqlite3VdbeChangeP2(v, jmp2, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, jmp2);
}
sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1);
sqlite3VdbeChangeP2(v, loopTop, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, loopTop);
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
static const VdbeOpList cntIdx[] = {
{ OP_Integer, 0, 0, 0},
{ OP_MemStore, 2, 1, 0},
{ OP_Rewind, 0, 0, 0}, /* 2 */
{ OP_MemInt, 0, 2, 0},
{ OP_Rewind, 0, 0, 0}, /* 1 */
{ OP_MemIncr, 2, 0, 0},
{ OP_Next, 0, 0, 0}, /* 4 */
{ OP_Next, 0, 0, 0}, /* 3 */
{ OP_MemLoad, 1, 0, 0},
{ OP_MemLoad, 2, 0, 0},
{ OP_Eq, 0, 0, 0}, /* 7 */
{ OP_Eq, 0, 0, 0}, /* 6 */
{ OP_MemIncr, 0, 0, 0},
{ OP_String8, 0, 0, "wrong # of entries in index "},
{ OP_String8, 0, 0, 0}, /* 10 */
{ OP_String8, 0, 0, 0}, /* 9 */
{ OP_Concat, 0, 0, 0},
{ OP_Callback, 1, 0, 0},
};
if( pIdx->tnum==0 ) continue;
addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
sqlite3VdbeChangeP1(v, addr+2, j+2);
sqlite3VdbeChangeP2(v, addr+2, addr+5);
sqlite3VdbeChangeP1(v, addr+4, j+2);
sqlite3VdbeChangeP2(v, addr+4, addr+3);
sqlite3VdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
sqlite3VdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
sqlite3VdbeChangeP1(v, addr+1, j+2);
sqlite3VdbeChangeP2(v, addr+1, addr+4);
sqlite3VdbeChangeP1(v, addr+3, j+2);
sqlite3VdbeChangeP2(v, addr+3, addr+2);
sqlite3VdbeJumpHere(v, addr+6);
sqlite3VdbeChangeP3(v, addr+9, pIdx->zName, P3_STATIC);
}
}
}
addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
sqlite3VdbeChangeP2(v, addr+2, addr+ArraySize(endCode));
sqlite3VdbeJumpHere(v, addr+2);
}else
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
@@ -881,13 +893,13 @@ void sqlite3Pragma(
Btree *pBt;
Pager *pPager;
if( db->aDb[i].zName==0 ) continue;
sqlite3VdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, P3_STATIC);
sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC);
pBt = db->aDb[i].pBt;
if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
sqlite3VdbeOp3(v, OP_String, 0, 0, "closed", P3_STATIC);
sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC);
}else{
int j = sqlite3pager_lockstate(pPager);
sqlite3VdbeOp3(v, OP_String, 0, 0,
sqlite3VdbeOp3(v, OP_String8, 0, 0,
(j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC);
}
sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
@@ -895,6 +907,17 @@ void sqlite3Pragma(
}else
#endif
#ifdef SQLITE_SSE
/*
** Check to see if the sqlite_statements table exists. Create it
** if it does not.
*/
if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){
extern int sqlite3CreateStatementsTable(Parse*);
sqlite3CreateStatementsTable(pParse);
}else
#endif
{}
if( v ){
@@ -909,4 +932,4 @@ pragma_out:
sqliteFree(zRight);
}
#endif /* SQLITE_OMIT_PRAGMA */
#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */
+540
View File
@@ -0,0 +1,540 @@
/*
** 2005 May 25
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the implementation of the sqlite3_prepare()
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.4 2005/09/10 16:46:13 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
/*
** Fill the InitData structure with an error message that indicates
** that the database is corrupt.
*/
static void corruptSchema(InitData *pData, const char *zExtra){
if( !sqlite3_malloc_failed ){
sqlite3SetString(pData->pzErrMsg, "malformed database schema",
zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0);
}
}
/*
** This is the callback routine for the code that initializes the
** database. See sqlite3Init() below for additional information.
** This routine is also called from the OP_ParseSchema opcode of the VDBE.
**
** Each callback contains the following information:
**
** argv[0] = name of thing being created
** argv[1] = root page number for table or index. NULL for trigger or view.
** argv[2] = SQL text for the CREATE statement.
** argv[3] = "1" for temporary files, "0" for main database, "2" or more
** for auxiliary database files.
**
*/
int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
InitData *pData = (InitData*)pInit;
sqlite3 *db = pData->db;
int iDb;
assert( argc==4 );
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
if( argv[1]==0 || argv[3]==0 ){
corruptSchema(pData, 0);
return 1;
}
iDb = atoi(argv[3]);
assert( iDb>=0 && iDb<db->nDb );
if( argv[2] && argv[2][0] ){
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
** But because db->init.busy is set to 1, no VDBE code is generated
** or executed. All the parser does is build the internal data
** structures that describe the table, index, or view.
*/
char *zErr;
int rc;
assert( db->init.busy );
db->init.iDb = iDb;
db->init.newTnum = atoi(argv[1]);
rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
db->init.iDb = 0;
if( SQLITE_OK!=rc ){
corruptSchema(pData, zErr);
sqlite3_free(zErr);
return rc;
}
}else{
/* If the SQL column is blank it means this is an index that
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
** constraint for a CREATE TABLE. The index should have already
** been created when we processed the CREATE TABLE. All we have
** to do here is record the root page number for that index.
*/
Index *pIndex;
pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
if( pIndex==0 || pIndex->tnum!=0 ){
/* This can occur if there exists an index on a TEMP table which
** has the same name as another index on a permanent index. Since
** the permanent table is hidden by the TEMP table, we can also
** safely ignore the index on the permanent table.
*/
/* Do Nothing */;
}else{
pIndex->tnum = atoi(argv[1]);
}
}
return 0;
}
/*
** Attempt to read the database schema and initialize internal
** data structures for a single database file. The index of the
** database file is given by iDb. iDb==0 is used for the main
** database. iDb==1 should never be used. iDb>=2 is used for
** auxiliary databases. Return one of the SQLITE_ error codes to
** indicate success or failure.
*/
static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
int rc;
BtCursor *curMain;
int size;
Table *pTab;
char const *azArg[5];
char zDbNum[30];
int meta[10];
InitData initData;
char const *zMasterSchema;
char const *zMasterName = SCHEMA_TABLE(iDb);
/*
** The master database table has a structure like this
*/
static const char master_schema[] =
"CREATE TABLE sqlite_master(\n"
" type text,\n"
" name text,\n"
" tbl_name text,\n"
" rootpage integer,\n"
" sql text\n"
")"
;
#ifndef SQLITE_OMIT_TEMPDB
static const char temp_master_schema[] =
"CREATE TEMP TABLE sqlite_temp_master(\n"
" type text,\n"
" name text,\n"
" tbl_name text,\n"
" rootpage integer,\n"
" sql text\n"
")"
;
#else
#define temp_master_schema 0
#endif
assert( iDb>=0 && iDb<db->nDb );
/* zMasterSchema and zInitScript are set to point at the master schema
** and initialisation script appropriate for the database being
** initialised. zMasterName is the name of the master table.
*/
if( !OMIT_TEMPDB && iDb==1 ){
zMasterSchema = temp_master_schema;
}else{
zMasterSchema = master_schema;
}
zMasterName = SCHEMA_TABLE(iDb);
/* Construct the schema tables. */
sqlite3SafetyOff(db);
azArg[0] = zMasterName;
azArg[1] = "1";
azArg[2] = zMasterSchema;
sprintf(zDbNum, "%d", iDb);
azArg[3] = zDbNum;
azArg[4] = 0;
initData.db = db;
initData.pzErrMsg = pzErrMsg;
rc = sqlite3InitCallback(&initData, 4, (char **)azArg, 0);
if( rc!=SQLITE_OK ){
sqlite3SafetyOn(db);
return rc;
}
pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
if( pTab ){
pTab->readOnly = 1;
}
sqlite3SafetyOn(db);
/* Create a cursor to hold the database open
*/
if( db->aDb[iDb].pBt==0 ){
if( !OMIT_TEMPDB && iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
return SQLITE_OK;
}
rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain);
if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
return rc;
}
/* Get the database meta information.
**
** Meta values are as follows:
** meta[0] Schema cookie. Changes with each schema change.
** meta[1] File format of schema layer.
** meta[2] Size of the page cache.
** meta[3] Use freelist if 0. Autovacuum if greater than zero.
** meta[4] Db text encoding. 1:UTF-8 3:UTF-16 LE 4:UTF-16 BE
** meta[5] The user cookie. Used by the application.
** meta[6]
** meta[7]
** meta[8]
** meta[9]
**
** Note: The hash defined SQLITE_UTF* symbols in sqliteInt.h correspond to
** the possible values of meta[4].
*/
if( rc==SQLITE_OK ){
int i;
for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){
rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, i+1, (u32 *)&meta[i]);
}
if( rc ){
sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
sqlite3BtreeCloseCursor(curMain);
return rc;
}
}else{
memset(meta, 0, sizeof(meta));
}
db->aDb[iDb].schema_cookie = meta[0];
/* If opening a non-empty database, check the text encoding. For the
** main database, set sqlite3.enc to the encoding of the main database.
** For an attached db, it is an error if the encoding is not the same
** as sqlite3.enc.
*/
if( meta[4] ){ /* text encoding */
if( iDb==0 ){
/* If opening the main database, set db->enc. */
db->enc = (u8)meta[4];
db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0);
}else{
/* If opening an attached database, the encoding much match db->enc */
if( meta[4]!=db->enc ){
sqlite3BtreeCloseCursor(curMain);
sqlite3SetString(pzErrMsg, "attached databases must use the same"
" text encoding as main database", (char*)0);
return SQLITE_ERROR;
}
}
}
size = meta[2];
if( size==0 ){ size = MAX_PAGES; }
db->aDb[iDb].cache_size = size;
if( iDb==0 ){
db->file_format = meta[1];
if( db->file_format==0 ){
/* This happens if the database was initially empty */
db->file_format = 1;
}
if( db->file_format==2 || db->file_format==3 ){
/* File format 2 is treated exactly as file format 1. New
** databases are created with file format 1.
*/
db->file_format = 1;
}
}
/*
** file_format==1 Version 3.0.0.
** file_format==2 Version 3.1.3.
** file_format==3 Version 3.1.4.
**
** Version 3.0 can only use files with file_format==1. Version 3.1.3
** can read and write files with file_format==1 or file_format==2.
** Version 3.1.4 can read and write file formats 1, 2 and 3.
*/
if( meta[1]>3 ){
sqlite3BtreeCloseCursor(curMain);
sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0);
return SQLITE_ERROR;
}
sqlite3BtreeSetCacheSize(db->aDb[iDb].pBt, db->aDb[iDb].cache_size);
/* Read the schema information out of the schema tables
*/
assert( db->init.busy );
if( rc==SQLITE_EMPTY ){
/* For an empty database, there is nothing to read */
rc = SQLITE_OK;
}else{
char *zSql;
zSql = sqlite3MPrintf(
"SELECT name, rootpage, sql, '%s' FROM '%q'.%s",
zDbNum, db->aDb[iDb].zName, zMasterName);
sqlite3SafetyOff(db);
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
sqlite3SafetyOn(db);
sqliteFree(zSql);
#ifndef SQLITE_OMIT_ANALYZE
if( rc==SQLITE_OK ){
sqlite3AnalysisLoad(db, iDb);
}
#endif
sqlite3BtreeCloseCursor(curMain);
}
if( sqlite3_malloc_failed ){
sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
rc = SQLITE_NOMEM;
sqlite3ResetInternalSchema(db, 0);
}
if( rc==SQLITE_OK ){
DbSetProperty(db, iDb, DB_SchemaLoaded);
}else{
sqlite3ResetInternalSchema(db, iDb);
}
return rc;
}
/*
** Initialize all database files - the main database file, the file
** used to store temporary tables, and any additional database files
** created using ATTACH statements. Return a success code. If an
** error occurs, write an error message into *pzErrMsg.
**
** After the database is initialized, the SQLITE_Initialized
** bit is set in the flags field of the sqlite structure.
*/
int sqlite3Init(sqlite3 *db, char **pzErrMsg){
int i, rc;
if( db->init.busy ) return SQLITE_OK;
assert( (db->flags & SQLITE_Initialized)==0 );
rc = SQLITE_OK;
db->init.busy = 1;
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
rc = sqlite3InitOne(db, i, pzErrMsg);
if( rc ){
sqlite3ResetInternalSchema(db, i);
}
}
/* Once all the other databases have been initialised, load the schema
** for the TEMP database. This is loaded last, as the TEMP database
** schema may contain references to objects in other databases.
*/
#ifndef SQLITE_OMIT_TEMPDB
if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
rc = sqlite3InitOne(db, 1, pzErrMsg);
if( rc ){
sqlite3ResetInternalSchema(db, 1);
}
}
#endif
db->init.busy = 0;
if( rc==SQLITE_OK ){
db->flags |= SQLITE_Initialized;
sqlite3CommitInternalChanges(db);
}
if( rc!=SQLITE_OK ){
db->flags &= ~SQLITE_Initialized;
}
return rc;
}
/*
** This routine is a no-op if the database schema is already initialised.
** Otherwise, the schema is loaded. An error code is returned.
*/
int sqlite3ReadSchema(Parse *pParse){
int rc = SQLITE_OK;
sqlite3 *db = pParse->db;
if( !db->init.busy ){
if( (db->flags & SQLITE_Initialized)==0 ){
rc = sqlite3Init(db, &pParse->zErrMsg);
}
}
assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized) || db->init.busy );
if( rc!=SQLITE_OK ){
pParse->rc = rc;
pParse->nErr++;
}
return rc;
}
/*
** Check schema cookies in all databases. If any cookie is out
** of date, return 0. If all schema cookies are current, return 1.
*/
static int schemaIsValid(sqlite3 *db){
int iDb;
int rc;
BtCursor *curTemp;
int cookie;
int allOk = 1;
for(iDb=0; allOk && iDb<db->nDb; iDb++){
Btree *pBt;
pBt = db->aDb[iDb].pBt;
if( pBt==0 ) continue;
rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, 0, &curTemp);
if( rc==SQLITE_OK ){
rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&cookie);
if( rc==SQLITE_OK && cookie!=db->aDb[iDb].schema_cookie ){
allOk = 0;
}
sqlite3BtreeCloseCursor(curTemp);
}
}
return allOk;
}
/*
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
*/
int sqlite3_prepare(
sqlite3 *db, /* Database handle. */
const char *zSql, /* UTF-8 encoded SQL statement. */
int nBytes, /* Length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
const char** pzTail /* OUT: End of parsed string */
){
Parse sParse;
char *zErrMsg = 0;
int rc = SQLITE_OK;
if( sqlite3_malloc_failed ){
return SQLITE_NOMEM;
}
assert( ppStmt );
*ppStmt = 0;
if( sqlite3SafetyOn(db) ){
return SQLITE_MISUSE;
}
memset(&sParse, 0, sizeof(sParse));
sParse.db = db;
sqlite3RunParser(&sParse, zSql, &zErrMsg);
if( sqlite3_malloc_failed ){
rc = SQLITE_NOMEM;
sqlite3RollbackAll(db);
sqlite3ResetInternalSchema(db, 0);
db->flags &= ~SQLITE_InTrans;
goto prepare_out;
}
if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
if( sParse.rc!=SQLITE_OK && sParse.checkSchema && !schemaIsValid(db) ){
sParse.rc = SQLITE_SCHEMA;
}
if( sParse.rc==SQLITE_SCHEMA ){
sqlite3ResetInternalSchema(db, 0);
}
if( pzTail ) *pzTail = sParse.zTail;
rc = sParse.rc;
#ifndef SQLITE_OMIT_EXPLAIN
if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
if( sParse.explain==2 ){
sqlite3VdbeSetNumCols(sParse.pVdbe, 3);
sqlite3VdbeSetColName(sParse.pVdbe, 0, "order", P3_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 1, "from", P3_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 2, "detail", P3_STATIC);
}else{
sqlite3VdbeSetNumCols(sParse.pVdbe, 5);
sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC);
}
}
#endif
prepare_out:
if( sqlite3SafetyOff(db) ){
rc = SQLITE_MISUSE;
}
if( rc==SQLITE_OK ){
*ppStmt = (sqlite3_stmt*)sParse.pVdbe;
}else if( sParse.pVdbe ){
sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
}
if( zErrMsg ){
sqlite3Error(db, rc, "%s", zErrMsg);
sqliteFree(zErrMsg);
}else{
sqlite3Error(db, rc, 0);
}
return rc;
}
#ifndef SQLITE_OMIT_UTF16
/*
** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
*/
int sqlite3_prepare16(
sqlite3 *db, /* Database handle. */
const void *zSql, /* UTF-8 encoded SQL statement. */
int nBytes, /* Length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
const void **pzTail /* OUT: End of parsed string */
){
/* This function currently works by first transforming the UTF-16
** encoded string to UTF-8, then invoking sqlite3_prepare(). The
** tricky bit is figuring out the pointer to return in *pzTail.
*/
char const *zSql8 = 0;
char const *zTail8 = 0;
int rc;
sqlite3_value *pTmp;
if( sqlite3SafetyCheck(db) ){
return SQLITE_MISUSE;
}
pTmp = sqlite3GetTransientValue(db);
sqlite3ValueSetStr(pTmp, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
zSql8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
if( !zSql8 ){
sqlite3Error(db, SQLITE_NOMEM, 0);
return SQLITE_NOMEM;
}
rc = sqlite3_prepare(db, zSql8, -1, ppStmt, &zTail8);
if( zTail8 && pzTail ){
/* If sqlite3_prepare returns a tail pointer, we calculate the
** equivalent pointer into the UTF-16 string by counting the unicode
** characters between zSql8 and zTail8, and then returning a pointer
** the same number of characters into the UTF-16 string.
*/
int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
*pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
}
return rc;
}
#endif /* SQLITE_OMIT_UTF16 */
+124 -89
View File
@@ -111,6 +111,7 @@ static const char aPrefix[] = "-x0\000X0";
static const et_info fmtinfo[] = {
{ 'd', 10, 1, etRADIX, 0, 0 },
{ 's', 0, 4, etSTRING, 0, 0 },
{ 'g', 0, 1, etGENERIC, 30, 0 },
{ 'z', 0, 6, etDYNSTRING, 0, 0 },
{ 'q', 0, 4, etSQLESCAPE, 0, 0 },
{ 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
@@ -122,7 +123,6 @@ static const et_info fmtinfo[] = {
{ 'f', 0, 1, etFLOAT, 0, 0 },
{ 'e', 0, 1, etEXP, 30, 0 },
{ 'E', 0, 1, etEXP, 14, 0 },
{ 'g', 0, 1, etGENERIC, 30, 0 },
{ 'G', 0, 1, etGENERIC, 14, 0 },
{ 'i', 10, 1, etRADIX, 0, 0 },
{ 'n', 0, 0, etSIZE, 0, 0 },
@@ -163,7 +163,15 @@ static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
}
#endif
#define etBUFSIZE 1000 /* Size of the output buffer */
/*
** On machines with a small stack size, you can redefine the
** SQLITE_PRINT_BUF_SIZE to be less than 350. But beware - for
** smaller values some %f conversions may go into an infinite loop.
*/
#ifndef SQLITE_PRINT_BUF_SIZE
# define SQLITE_PRINT_BUF_SIZE 350
#endif
#define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
/*
** The root program. All variations call this core.
@@ -210,9 +218,11 @@ static int vxprintf(
etByte flag_plussign; /* True if "+" flag is present */
etByte flag_blanksign; /* True if " " flag is present */
etByte flag_alternateform; /* True if "#" flag is present */
etByte flag_altform2; /* True if "!" flag is present */
etByte flag_zeropad; /* True if field width constant starts with zero */
etByte flag_long; /* True if "l" flag is present */
etByte flag_longlong; /* True if the "ll" flag is present */
etByte done; /* Loop termination flag */
UINT64_TYPE longvalue; /* Value for integer types */
LONGDOUBLE_TYPE realvalue; /* Value for real types */
const et_info *infop; /* Pointer to the appropriate info structure */
@@ -225,7 +235,7 @@ static int vxprintf(
" ";
#define etSPACESIZE (sizeof(spaces)-1)
#ifndef etNOFLOATINGPOINT
int exp; /* exponent of real numbers */
int exp, e2; /* exponent of real numbers */
double rounder; /* Used for rounding floating point values */
etByte flag_dp; /* True if decimal point should be shown */
etByte flag_rtz; /* True if trailing zeros should be removed */
@@ -254,17 +264,19 @@ static int vxprintf(
}
/* Find out what flags are present */
flag_leftjustify = flag_plussign = flag_blanksign =
flag_alternateform = flag_zeropad = 0;
flag_alternateform = flag_altform2 = flag_zeropad = 0;
done = 0;
do{
switch( c ){
case '-': flag_leftjustify = 1; c = 0; break;
case '+': flag_plussign = 1; c = 0; break;
case ' ': flag_blanksign = 1; c = 0; break;
case '#': flag_alternateform = 1; c = 0; break;
case '0': flag_zeropad = 1; c = 0; break;
default: break;
case '-': flag_leftjustify = 1; break;
case '+': flag_plussign = 1; break;
case ' ': flag_blanksign = 1; break;
case '#': flag_alternateform = 1; break;
case '!': flag_altform2 = 1; break;
case '0': flag_zeropad = 1; break;
default: done = 1; break;
}
}while( c==0 && (c=(*++fmt))!=0 );
}while( !done && (c=(*++fmt))!=0 );
/* Get the field width */
width = 0;
if( c=='*' ){
@@ -336,6 +348,7 @@ static int vxprintf(
** At this point, variables are initialized as follows:
**
** flag_alternateform TRUE if a '#' is present.
** flag_altform2 TRUE if a '!' is present.
** flag_plussign TRUE if a '+' is present.
** flag_leftjustify TRUE if a '-' is present or if the
** field width was negative.
@@ -414,7 +427,7 @@ static int vxprintf(
realvalue = va_arg(ap,double);
#ifndef etNOFLOATINGPOINT
if( precision<0 ) precision = 6; /* Set default precision */
if( precision>etBUFSIZE-10 ) precision = etBUFSIZE-10;
if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10;
if( realvalue<0.0 ){
realvalue = -realvalue;
prefix = '-';
@@ -423,8 +436,7 @@ static int vxprintf(
else if( flag_blanksign ) prefix = ' ';
else prefix = 0;
}
if( infop->type==etGENERIC && precision>0 ) precision--;
rounder = 0.0;
if( xtype==etGENERIC && precision>0 ) precision--;
#if 0
/* Rounding works like BSD when the constant 0.4999 is used. Wierd! */
for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);
@@ -432,10 +444,11 @@ static int vxprintf(
/* It makes more sense to use 0.5 */
for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1);
#endif
if( infop->type==etFLOAT ) realvalue += rounder;
if( xtype==etFLOAT ) realvalue += rounder;
/* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
exp = 0;
if( realvalue>0.0 ){
while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
@@ -467,51 +480,67 @@ static int vxprintf(
}else{
flag_rtz = 0;
}
/*
** The "exp+precision" test causes output to be of type etEXP if
** the precision is too large to fit in buf[].
*/
if( xtype==etEXP ){
e2 = 0;
}else{
e2 = exp;
}
nsd = 0;
if( xtype==etFLOAT && exp+precision<etBUFSIZE-30 ){
flag_dp = (precision>0 || flag_alternateform);
if( prefix ) *(bufpt++) = prefix; /* Sign */
if( exp<0 ) *(bufpt++) = '0'; /* Digits before "." */
else for(; exp>=0; exp--) *(bufpt++) = et_getdigit(&realvalue,&nsd);
if( flag_dp ) *(bufpt++) = '.'; /* The decimal point */
for(exp++; exp<0 && precision>0; precision--, exp++){
*(bufpt++) = '0';
}
while( (precision--)>0 ) *(bufpt++) = et_getdigit(&realvalue,&nsd);
*(bufpt--) = 0; /* Null terminate */
if( flag_rtz && flag_dp ){ /* Remove trailing zeros and "." */
while( bufpt>=buf && *bufpt=='0' ) *(bufpt--) = 0;
if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0;
}
bufpt++; /* point to next free slot */
}else{ /* etEXP or etGENERIC */
flag_dp = (precision>0 || flag_alternateform);
if( prefix ) *(bufpt++) = prefix; /* Sign */
*(bufpt++) = et_getdigit(&realvalue,&nsd); /* First digit */
if( flag_dp ) *(bufpt++) = '.'; /* Decimal point */
while( (precision--)>0 ) *(bufpt++) = et_getdigit(&realvalue,&nsd);
bufpt--; /* point to last digit */
if( flag_rtz && flag_dp ){ /* Remove tail zeros */
while( bufpt>=buf && *bufpt=='0' ) *(bufpt--) = 0;
if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0;
}
bufpt++; /* point to next free slot */
if( exp || flag_exp ){
*(bufpt++) = aDigits[infop->charset];
if( exp<0 ){ *(bufpt++) = '-'; exp = -exp; } /* sign of exp */
else { *(bufpt++) = '+'; }
if( exp>=100 ){
*(bufpt++) = (exp/100)+'0'; /* 100's digit */
exp %= 100;
}
*(bufpt++) = exp/10+'0'; /* 10's digit */
*(bufpt++) = exp%10+'0'; /* 1's digit */
flag_dp = (precision>0) | flag_alternateform | flag_altform2;
/* The sign in front of the number */
if( prefix ){
*(bufpt++) = prefix;
}
/* Digits prior to the decimal point */
if( e2<0 ){
*(bufpt++) = '0';
}else{
for(; e2>=0; e2--){
*(bufpt++) = et_getdigit(&realvalue,&nsd);
}
}
/* The decimal point */
if( flag_dp ){
*(bufpt++) = '.';
}
/* "0" digits after the decimal point but before the first
** significant digit of the number */
for(e2++; e2<0 && precision>0; precision--, e2++){
*(bufpt++) = '0';
}
/* Significant digits after the decimal point */
while( (precision--)>0 ){
*(bufpt++) = et_getdigit(&realvalue,&nsd);
}
/* Remove trailing zeros and the "." if no digits follow the "." */
if( flag_rtz && flag_dp ){
while( bufpt[-1]=='0' ) *(--bufpt) = 0;
assert( bufpt>buf );
if( bufpt[-1]=='.' ){
if( flag_altform2 ){
*(bufpt++) = '0';
}else{
*(--bufpt) = 0;
}
}
}
/* Add the "eNNN" suffix */
if( flag_exp || (xtype==etEXP && exp) ){
*(bufpt++) = aDigits[infop->charset];
if( exp<0 ){
*(bufpt++) = '-'; exp = -exp;
}else{
*(bufpt++) = '+';
}
if( exp>=100 ){
*(bufpt++) = (exp/100)+'0'; /* 100's digit */
exp %= 100;
}
*(bufpt++) = exp/10+'0'; /* 10's digit */
*(bufpt++) = exp%10+'0'; /* 1's digit */
}
*bufpt = 0;
/* The converted number is in buf[] and zero terminated. Output it.
** Note that the number is in the usual order, not reversed as with
** integer conversions. */
@@ -564,36 +593,35 @@ static int vxprintf(
if( precision>=0 && precision<length ) length = precision;
break;
case etSQLESCAPE:
case etSQLESCAPE2:
{
int i, j, n, c, isnull;
int needQuote;
char *arg = va_arg(ap,char*);
isnull = arg==0;
if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
for(i=n=0; (c=arg[i])!=0; i++){
if( c=='\'' ) n++;
}
needQuote = !isnull && xtype==etSQLESCAPE2;
n += i + 1 + needQuote*2;
if( n>etBUFSIZE ){
bufpt = zExtra = sqliteMalloc( n );
if( bufpt==0 ) return -1;
}else{
bufpt = buf;
}
j = 0;
if( needQuote ) bufpt[j++] = '\'';
for(i=0; (c=arg[i])!=0; i++){
bufpt[j++] = c;
if( c=='\'' ) bufpt[j++] = c;
}
if( needQuote ) bufpt[j++] = '\'';
bufpt[j] = 0;
length = j;
if( precision>=0 && precision<length ) length = precision;
case etSQLESCAPE2: {
int i, j, n, c, isnull;
int needQuote;
char *arg = va_arg(ap,char*);
isnull = arg==0;
if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
for(i=n=0; (c=arg[i])!=0; i++){
if( c=='\'' ) n++;
}
needQuote = !isnull && xtype==etSQLESCAPE2;
n += i + 1 + needQuote*2;
if( n>etBUFSIZE ){
bufpt = zExtra = sqliteMalloc( n );
if( bufpt==0 ) return -1;
}else{
bufpt = buf;
}
j = 0;
if( needQuote ) bufpt[j++] = '\'';
for(i=0; (c=arg[i])!=0; i++){
bufpt[j++] = c;
if( c=='\'' ) bufpt[j++] = c;
}
if( needQuote ) bufpt[j++] = '\'';
bufpt[j] = 0;
length = j;
if( precision>=0 && precision<length ) length = precision;
break;
}
case etTOKEN: {
Token *pToken = va_arg(ap, Token*);
if( pToken && pToken->z ){
@@ -698,7 +726,11 @@ static void mout(void *arg, const char *zNewText, int nNewChar){
memcpy(pM->zText, pM->zBase, pM->nChar);
}
}else{
pM->zText = pM->xRealloc(pM->zText, pM->nAlloc);
char *zNew;
zNew = pM->xRealloc(pM->zText, pM->nAlloc);
if( zNew ){
pM->zText = zNew;
}
}
}
}
@@ -736,7 +768,10 @@ static char *base_vprintf(
memcpy(sM.zText, sM.zBase, sM.nChar+1);
}
}else if( sM.nAlloc>sM.nChar+10 ){
sM.zText = xRealloc(sM.zText, sM.nChar+1);
char *zNew = xRealloc(sM.zText, sM.nChar+1);
if( zNew ){
sM.zText = zNew;
}
}
}
return sM.zText;
@@ -754,7 +789,7 @@ static void *printf_realloc(void *old, int size){
** %-conversion extensions.
*/
char *sqlite3VMPrintf(const char *zFormat, va_list ap){
char zBase[1000];
char zBase[SQLITE_PRINT_BUF_SIZE];
return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
}
@@ -765,7 +800,7 @@ char *sqlite3VMPrintf(const char *zFormat, va_list ap){
char *sqlite3MPrintf(const char *zFormat, ...){
va_list ap;
char *z;
char zBase[1000];
char zBase[SQLITE_PRINT_BUF_SIZE];
va_start(ap, zFormat);
z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
va_end(ap);
+5 -5
View File
@@ -15,7 +15,7 @@
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
**
** $Id: random.c,v 1.12 2004/05/08 08:23:32 danielk1977 Exp $
** $Id: random.c,v 1.13 2005/06/12 21:35:52 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -26,13 +26,16 @@
** must be held while executing this routine.
**
** Why not just use a library random generator like lrand48() for this?
** Because the OP_NewRecno opcode in the VDBE depends on having a very
** Because the OP_NewRowid opcode in the VDBE depends on having a very
** good source of random numbers. The lrand48() library function may
** well be good enough. But maybe not. Or maybe lrand48() has some
** subtle problems on some systems that could cause problems. It is hard
** to know. To minimize the risk of problems due to bad lrand48()
** implementations, SQLite uses this random number generator based
** on RC4, which we know works very well.
**
** (Later): Actually, OP_NewRowid does not depend on a good source of
** randomness any more. But we will leave this code in all the same.
*/
static int randomByte(){
unsigned char t;
@@ -95,6 +98,3 @@ void sqlite3Randomness(int N, void *pBuf){
}
sqlite3OsLeaveMutex();
}
+759 -509
View File
File diff suppressed because it is too large Load Diff
+21 -9
View File
@@ -12,7 +12,7 @@
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
** $Id: shell.c,v 1.121 2005/02/03 00:42:35 drh Exp $
** $Id: shell.c,v 1.128 2005/09/11 02:03:04 drh Exp $
*/
#include <stdlib.h>
#include <string.h>
@@ -313,7 +313,7 @@ static void output_c_string(FILE *out, const char *z){
fputc('\\', out);
fputc('r', out);
}else if( !isprint(c) ){
fprintf(out, "\\%03o", c);
fprintf(out, "\\%03o", c&0xff);
}else{
fputc(c, out);
}
@@ -656,10 +656,14 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
zType = azArg[1];
zSql = azArg[2];
if( strcasecmp(zTable,"sqlite_sequence")!=0 ){
fprintf(p->out, "%s;\n", zSql);
}else{
if( strcmp(zTable, "sqlite_sequence")==0 ){
fprintf(p->out, "DELETE FROM sqlite_sequence;\n");
}else if( strcmp(zTable, "sqlite_stat1")==0 ){
fprintf(p->out, "ANALYZE sqlite_master;\n");
}else if( strncmp(zTable, "sqlite_", 7)==0 ){
return 0;
}else{
fprintf(p->out, "%s;\n", zSql);
}
if( strcmp(zType, "table")==0 ){
@@ -984,10 +988,10 @@ static int do_meta_command(char *zLine, struct callback_data *p){
p->showHeader = 1;
memset(p->colWidth,0,ArraySize(p->colWidth));
p->colWidth[0] = 4;
p->colWidth[1] = 12;
p->colWidth[1] = 14;
p->colWidth[2] = 10;
p->colWidth[3] = 10;
p->colWidth[4] = 35;
p->colWidth[4] = 33;
}else if (p->explainPrev.valid) {
p->explainPrev.valid = 0;
p->mode = p->explainPrev.mode;
@@ -1093,6 +1097,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
}
}
}
*z = 0;
if( i+1!=nCol ){
fprintf(stderr,"%s line %d: expected %d columns of data but found %d\n",
zFile, lineno, nCol, i+1);
@@ -1289,7 +1294,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
"SELECT sql FROM "
" (SELECT * FROM sqlite_master UNION ALL"
" SELECT * FROM sqlite_temp_master) "
"WHERE type!='meta' AND sql NOTNULL "
"WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
"ORDER BY substr(type,2,1), name",
callback, &data, &zErrMsg
);
@@ -1333,7 +1338,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
if( nArg==1 ){
rc = sqlite3_get_table(p->db,
"SELECT name FROM sqlite_master "
"WHERE type IN ('table','view') "
"WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'"
"UNION ALL "
"SELECT name FROM sqlite_temp_master "
"WHERE type IN ('table','view') "
@@ -1697,6 +1702,13 @@ int main(int argc, char **argv){
}
data.out = stdout;
#ifdef SQLITE_OMIT_MEMORYDB
if( data.zDbFilename==0 ){
fprintf(stderr,"%s: no database filename specified\n", argv[0]);
exit(1);
}
#endif
/* Go ahead and open the database file if it already exists. If the
** file does not exist, delay opening it. This prevents empty database
** files from being created if a user mistypes the database name argument
+70 -21
View File
@@ -12,7 +12,7 @@
** This header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite.h.in,v 1.130 2005/02/05 07:33:35 danielk1977 Exp $
** @(#) $Id: sqlite.h.in,v 1.141 2005/09/08 10:58:52 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -158,7 +158,7 @@ int sqlite3_exec(
*/
#define SQLITE_OK 0 /* Successful result */
#define SQLITE_ERROR 1 /* SQL error or missing database */
#define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */
#define SQLITE_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */
#define SQLITE_PERM 3 /* Access permission denied */
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
#define SQLITE_BUSY 5 /* The database file is locked */
@@ -168,13 +168,13 @@ int sqlite3_exec(
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
#define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */
#define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
#define SQLITE_FULL 13 /* Insertion failed because database is full */
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
#define SQLITE_EMPTY 16 /* Database is empty */
#define SQLITE_SCHEMA 17 /* The database schema changed */
#define SQLITE_TOOBIG 18 /* Too much data for one row of a table */
#define SQLITE_TOOBIG 18 /* NOT USED. Too much data for one row */
#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */
#define SQLITE_MISMATCH 20 /* Data type mismatch */
#define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -373,8 +373,9 @@ void sqlite3_free_table(char **result);
**
** We can use this text in an SQL statement as follows:
**
** sqlite3_exec_printf(db, "INSERT INTO table VALUES('%q')",
** callback1, 0, 0, zText);
** char *z = sqlite3_mprintf("INSERT INTO TABLES('%q')", zText);
** sqlite3_exec(db, z, callback1, 0, 0);
** sqlite3_free(z);
**
** Because the %q format string is used, the '\'' character in zText
** is escaped and the SQL generated is as follows:
@@ -452,6 +453,7 @@ int sqlite3_set_authorizer(
#define SQLITE_DETACH 25 /* Database Name NULL */
#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
#define SQLITE_REINDEX 27 /* Index Name NULL */
#define SQLITE_ANALYZE 28 /* Table Name NULL */
/*
@@ -463,11 +465,18 @@ int sqlite3_set_authorizer(
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
/*
** Register a function that is called at every invocation of sqlite3_exec()
** or sqlite3_prepare(). This function can be used (for example) to generate
** a log file of all SQL executed against a database.
** Register a function for tracing SQL command evaluation. The function
** registered by sqlite3_trace() is invoked at the first sqlite3_step()
** for the evaluation of an SQL statement. The function registered by
** sqlite3_profile() runs at the end of each SQL statement and includes
** information on how long that statement ran.
**
** The sqlite3_profile() API is currently considered experimental and
** is subject to change.
*/
void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
void *sqlite3_profile(sqlite3*,
void(*xProfile)(void*,const char*,sqlite_uint64), void*);
/*
** This routine configures a callback function - the progress callback - that
@@ -688,8 +697,6 @@ int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
/*
** Set all the parameters in the compiled SQL statement to NULL.
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
int sqlite3_clear_bindings(sqlite3_stmt*);
@@ -1004,10 +1011,9 @@ int sqlite3_value_type(sqlite3_value*);
void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
/*
** The pUserData parameter to the sqlite3_create_function() and
** sqlite3_create_aggregate() routines used to register user functions
** is available to the implementation of the function using this
** call.
** The pUserData parameter to the sqlite3_create_function()
** routine used to register user functions is available to
** the implementation of the function using this call.
*/
void *sqlite3_user_data(sqlite3_context*);
@@ -1191,23 +1197,29 @@ int sqlite3_rekey(
** milisecond time resolution, then the time will be rounded up to
** the nearest second. The number of miliseconds of sleep actually
** requested from the operating system is returned.
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
int sqlite3_sleep(int);
/*
** Return TRUE (non-zero) of the statement supplied as an argument needs
** Return TRUE (non-zero) if the statement supplied as an argument needs
** to be recompiled. A statement needs to be recompiled whenever the
** execution environment changes in a way that would alter the program
** that sqlite3_prepare() generates. For example, if new functions or
** collating sequences are registered or if an authorizer function is
** added or changed.
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
int sqlite3_expired(sqlite3_stmt*);
/*
** Move all bindings from the first prepared statement over to the second.
** This routine is useful, for example, if the first prepared statement
** fails with an SQLITE_SCHEMA error. The same SQL can be prepared into
** the second prepared statement then all of the bindings transfered over
** to the second statement before the first statement is finalized.
*/
int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
/*
** If the following global variable is made to point to a
** string which is the name of a directory, then all temporary files
@@ -1215,11 +1227,48 @@ int sqlite3_expired(sqlite3_stmt*);
** is NULL pointer, then SQLite does a search for an appropriate temporary
** file directory.
**
** Once sqlite3_open() has been called, changing this variable will invalidate the
** current temporary database, if any.
** Once sqlite3_open() has been called, changing this variable will invalidate
** the current temporary database, if any.
*/
extern char *sqlite3_temp_directory;
/*
** This function is called to recover from a malloc() failure that occured
** within the SQLite library. Normally, after a single malloc() fails the
** library refuses to function (all major calls return SQLITE_NOMEM).
** This function restores the library state so that it can be used again.
**
** All existing statements (sqlite3_stmt pointers) must be finalized or
** reset before this call is made. Otherwise, SQLITE_BUSY is returned.
** If any in-memory databases are in use, either as a main or TEMP
** database, SQLITE_ERROR is returned. In either of these cases, the
** library is not reset and remains unusable.
**
** This function is *not* threadsafe. Calling this from within a threaded
** application when threads other than the caller have used SQLite is
** dangerous and will almost certainly result in malfunctions.
**
** This functionality can be omitted from a build by defining the
** SQLITE_OMIT_GLOBALRECOVER at compile time.
*/
int sqlite3_global_recover();
/*
** Test to see whether or not the database connection is in autocommit
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
** by default. Autocommit is disabled by a BEGIN statement and reenabled
** by the next COMMIT or ROLLBACK.
*/
int sqlite3_get_autocommit(sqlite3*);
/*
** Return the sqlite3* database handle to which the prepared statement given
** in the argument belongs. This is the same database handle that was
** the first argument to the sqlite3_prepare() that was used to create
** the statement in the first place.
*/
sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
#ifdef __cplusplus
} /* End of the 'extern "C"' block */
#endif
+259 -144
View File
@@ -11,11 +11,22 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.370 2005/02/09 01:40:25 danielk1977 Exp $
** @(#) $Id: sqliteInt.h,v 1.421 2005/09/19 21:05:49 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
/*
** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
** Setting NDEBUG makes the code smaller and run faster. So the following
** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out
** feature.
*/
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
# define NDEBUG 1
#endif
/*
** These #defines should enable >2GB file support on Posix if the
** underlying operating system supports it. If the OS lacks
@@ -39,7 +50,6 @@
# define _LARGEFILE_SOURCE 1
#endif
#include "config.h"
#include "sqlite3.h"
#include "hash.h"
#include "parse.h"
@@ -67,6 +77,17 @@
# define TEMP_PAGES 500
#endif
/*
** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
** afterward. Having this macro allows us to cause the C compiler
** to omit code used by TEMP tables without messy #ifndef statements.
*/
#ifdef SQLITE_OMIT_TEMPDB
#define OMIT_TEMPDB 1
#else
#define OMIT_TEMPDB 0
#endif
/*
** If the following macro is set to 1, then NULL values are considered
** distinct for the SELECT DISTINCT statement and for UNION or EXCEPT
@@ -169,20 +190,6 @@
#ifndef LONGDOUBLE_TYPE
# define LONGDOUBLE_TYPE long double
#endif
#ifndef INTPTR_TYPE
# if SQLITE_PTR_SZ==4
# define INTPTR_TYPE int
# else
# define INTPTR_TYPE sqlite_int64
# endif
#endif
#ifndef UINTPTR_TYPE
# if SQLITE_PTR_SZ==4
# define UINTPTR_TYPE unsigned int
# else
# define UINTPTR_TYPE sqlite_uint64
# endif
#endif
typedef sqlite_int64 i64; /* 8-byte signed integer */
typedef UINT64_TYPE u64; /* 8-byte unsigned integer */
typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
@@ -190,8 +197,6 @@ typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
typedef INT16_TYPE i16; /* 2-byte signed integer */
typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
typedef UINT8_TYPE i8; /* 1-byte signed integer */
typedef INTPTR_TYPE ptr; /* Big enough to hold a pointer */
typedef UINTPTR_TYPE uptr; /* Big enough to hold a pointer */
/*
** Macros to determine whether the machine is big or little endian,
@@ -214,6 +219,7 @@ typedef struct BusyHandler BusyHandler;
struct BusyHandler {
int (*xFunc)(void *,int); /* The busy callback */
void *pArg; /* First arg to busy callback */
int nBusy; /* Incremented with each busy call */
};
/*
@@ -292,7 +298,7 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
/*
** The name of the schema table.
*/
#define SCHEMA_TABLE(x) (x==1?TEMP_MASTER_NAME:MASTER_NAME)
#define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
/*
** A convenience macro that returns the number of elements in
@@ -303,32 +309,30 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
/*
** Forward references to structures
*/
typedef struct AggInfo AggInfo;
typedef struct AuthContext AuthContext;
typedef struct CollSeq CollSeq;
typedef struct Column Column;
typedef struct Table Table;
typedef struct Index Index;
typedef struct Instruction Instruction;
typedef struct Db Db;
typedef struct Expr Expr;
typedef struct ExprList ExprList;
typedef struct Parse Parse;
typedef struct Token Token;
typedef struct IdList IdList;
typedef struct SrcList SrcList;
typedef struct WhereInfo WhereInfo;
typedef struct WhereLevel WhereLevel;
typedef struct Select Select;
typedef struct AggExpr AggExpr;
typedef struct FuncDef FuncDef;
typedef struct Trigger Trigger;
typedef struct TriggerStep TriggerStep;
typedef struct TriggerStack TriggerStack;
typedef struct FKey FKey;
typedef struct Db Db;
typedef struct AuthContext AuthContext;
typedef struct FuncDef FuncDef;
typedef struct IdList IdList;
typedef struct Index Index;
typedef struct KeyClass KeyClass;
typedef struct CollSeq CollSeq;
typedef struct KeyInfo KeyInfo;
typedef struct NameContext NameContext;
typedef struct Fetch Fetch;
typedef struct Parse Parse;
typedef struct Select Select;
typedef struct SrcList SrcList;
typedef struct Table Table;
typedef struct Token Token;
typedef struct TriggerStack TriggerStack;
typedef struct TriggerStep TriggerStep;
typedef struct Trigger Trigger;
typedef struct WhereInfo WhereInfo;
typedef struct WhereLevel WhereLevel;
/*
** Each database file to be accessed by the system is an instance
@@ -407,16 +411,13 @@ struct Db {
struct sqlite3 {
int nDb; /* Number of backends currently in use */
Db *aDb; /* All backends */
Db aDbStatic[2]; /* Static space for the 2 default backends */
int flags; /* Miscellanous flags. See below */
int errCode; /* Most recent error code (SQLITE_*) */
u8 enc; /* Text encoding for this database. */
u8 autoCommit; /* The auto-commit flag. */
u8 file_format; /* What file format version is this database? */
u8 temp_store; /* 1: file 2: memory 0: default */
int nTable; /* Number of tables in the database */
BusyHandler busyHandler; /* Busy callback */
void *pCommitArg; /* Argument to xCommitCallback() */
int (*xCommitCallback)(void*);/* Invoked at every commit. */
Hash aFunc; /* All functions that can be in SQL exprs */
Hash aCollSeq; /* All collating sequences */
CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
i64 lastRowid; /* ROWID of most recent insert (see above) */
i64 priorNewRowid; /* Last randomly generated ROWID */
@@ -430,8 +431,19 @@ struct sqlite3 {
} init;
struct Vdbe *pVdbe; /* List of active virtual machines */
int activeVdbeCnt; /* Number of vdbes currently executing */
void (*xTrace)(void*,const char*); /* Trace function */
void *pTraceArg; /* Argument to the trace function */
void (*xTrace)(void*,const char*); /* Trace function */
void *pTraceArg; /* Argument to the trace function */
void (*xProfile)(void*,const char*,u64); /* Profiling function */
void *pProfileArg; /* Argument to profile function */
void *pCommitArg; /* Argument to xCommitCallback() */
int (*xCommitCallback)(void*);/* Invoked at every commit. */
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
void *pCollNeededArg;
sqlite3_value *pValue; /* Value used for transient conversions */
sqlite3_value *pErr; /* Most recent error message */
char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */
#ifndef SQLITE_OMIT_AUTHORIZATION
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
/* Access authorization function */
@@ -442,16 +454,17 @@ struct sqlite3 {
void *pProgressArg; /* Argument to the progress callback */
int nProgressOps; /* Number of opcodes for progress callback */
#endif
int errCode; /* Most recent error code (SQLITE_*) */
u8 enc; /* Text encoding for this database. */
u8 autoCommit; /* The auto-commit flag. */
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
void *pCollNeededArg;
sqlite3_value *pValue; /* Value used for transient conversions */
sqlite3_value *pErr; /* Most recent error message */
char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */
#ifndef SQLITE_OMIT_GLOBALRECOVER
sqlite3 *pNext; /* Linked list of open db handles. */
#endif
Hash aFunc; /* All functions that can be in SQL exprs */
Hash aCollSeq; /* All collating sequences */
BusyHandler busyHandler; /* Busy callback */
int busyTimeout; /* Busy handler timeout, in msec */
Db aDbStatic[2]; /* Static space for the 2 default backends */
#ifdef SQLITE_SSE
sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */
#endif
};
/*
@@ -496,17 +509,24 @@ struct sqlite3 {
** points to a linked list of these structures.
*/
struct FuncDef {
char *zName; /* SQL name of the function */
int nArg; /* Number of arguments. -1 means unlimited */
i16 nArg; /* Number of arguments. -1 means unlimited */
u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */
u8 flags; /* Some combination of SQLITE_FUNC_* */
void *pUserData; /* User data parameter */
FuncDef *pNext; /* Next function with same name */
void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */
u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */
char zName[1]; /* SQL name of the function. MUST BE LAST */
};
/*
** Possible values for FuncDef.flags
*/
#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
/*
** information about each column of an SQL table is held in an instance
** of this structure.
@@ -545,10 +565,19 @@ struct Column {
struct CollSeq {
char *zName; /* Name of the collating sequence, UTF-8 encoded */
u8 enc; /* Text encoding handled by xCmp() */
u8 type; /* One of the SQLITE_COLL_... values below */
void *pUser; /* First argument to xCmp() */
int (*xCmp)(void*,int, const void*, int, const void*);
};
/*
** Allowed values of CollSeq flags:
*/
#define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */
#define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */
#define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */
#define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */
/*
** A sort order can be either ASC or DESC.
*/
@@ -608,9 +637,13 @@ struct Table {
u8 hasPrimKey; /* True if there exists a primary key */
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
u8 autoInc; /* True if the integer primary key is autoincrement */
int nRef; /* Number of pointers to this Table */
Trigger *pTrigger; /* List of SQL triggers on this table */
FKey *pFKey; /* Linked list of all foreign keys in this table */
char *zColAff; /* String defining the affinity of each column */
#ifndef SQLITE_OMIT_ALTERTABLE
int addColOffset; /* Offset in CREATE TABLE statement to add a new column */
#endif
};
/*
@@ -700,7 +733,8 @@ struct FKey {
** comparison of the two index keys.
**
** If the KeyInfo.incrKey value is true and the comparison would
** otherwise be equal, then return a result as if the second key larger.
** otherwise be equal, then return a result as if the second key
** were larger.
*/
struct KeyInfo {
u8 enc; /* Text encoding - one of the TEXT_Utf* values */
@@ -740,6 +774,7 @@ struct Index {
char *zName; /* Name of this index */
int nColumn; /* Number of columns in the table used by this index */
int *aiColumn; /* Which columns are used by this index. 1st is 0 */
unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
Table *pTable; /* The SQL table being indexed */
int tnum; /* Page containing root of this index in database file */
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
@@ -764,6 +799,49 @@ struct Token {
unsigned n : 31; /* Number of characters in this token */
};
/*
** An instance of this structure contains information needed to generate
** code for a SELECT that contains aggregate functions.
**
** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
** pointer to this structure. The Expr.iColumn field is the index in
** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
** code for that node.
**
** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
** original Select structure that describes the SELECT statement. These
** fields do not need to be freed when deallocating the AggInfo structure.
*/
struct AggInfo {
u8 directMode; /* Direct rendering mode means take data directly
** from source tables rather than from accumulators */
u8 useSortingIdx; /* In direct mode, reference the sorting index rather
** than the source table */
int sortingIdx; /* Cursor number of the sorting index */
ExprList *pGroupBy; /* The group by clause */
int nSortingColumn; /* Number of columns in the sorting index */
struct AggInfo_col { /* For each column used in source tables */
int iTable; /* Cursor number of the source table */
int iColumn; /* Column number within the source table */
int iSorterColumn; /* Column number in the sorting index */
int iMem; /* Memory location that acts as accumulator */
Expr *pExpr; /* The original expression */
} *aCol;
int nColumn; /* Number of used entries in aCol[] */
int nColumnAlloc; /* Number of slots allocated for aCol[] */
int nAccumulator; /* Number of columns that show through to the output.
** Additional columns are used only as parameters to
** aggregate functions */
struct AggInfo_func { /* For each aggregate function */
Expr *pExpr; /* Expression encoding the function */
FuncDef *pFunc; /* The aggregate function implementation */
int iMem; /* Memory location that acts as accumulator */
int iDistinct; /* Virtual table used to enforce DISTINCT */
} *aFunc;
int nFunc; /* Number of entries in aFunc[] */
int nFuncAlloc; /* Number of slots allocated for aFunc[] */
};
/*
** Each node of an expression in the parse tree is an instance
** of this structure.
@@ -805,6 +883,10 @@ struct Token {
** be the right operand of an IN operator. Or, if a scalar SELECT appears
** in an expression the opcode is TK_SELECT and Expr.pSelect is the only
** operand.
**
** If the Expr is of type OP_Column, and the table it is selecting from
** is a disk table or the "old.*" pseudo-table, then pTab points to the
** corresponding table definition.
*/
struct Expr {
u8 op; /* Operation performed by this node */
@@ -819,22 +901,24 @@ struct Expr {
Token span; /* Complete text of the expression */
int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the
** iColumn-th field of the iTable-th table. */
int iAgg; /* When op==TK_COLUMN and pParse->fillAgg==FALSE, pull
** result from the iAgg-th element of the aggregator */
int iAggCtx; /* The value to pass as P1 of OP_AggGet. */
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
int iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
Select *pSelect; /* When the expression is a sub-select. Also the
** right side of "<expr> IN (<select>)" */
Table *pTab; /* Table for OP_Column expressions. */
};
/*
** The following are the meanings of bits in the Expr.flags field.
*/
#define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
#define EP_Agg 0x0002 /* Contains one or more aggregate functions */
#define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */
#define EP_Error 0x0008 /* Expression contains one or more errors */
#define EP_Not 0x0010 /* Operator preceeded by NOT */
#define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */
#define EP_FromJoin 0x01 /* Originated in ON or USING clause of a join */
#define EP_Agg 0x02 /* Contains one or more aggregate functions */
#define EP_Resolved 0x04 /* IDs have been resolved to COLUMNs */
#define EP_Error 0x08 /* Expression contains one or more errors */
#define EP_Distinct 0x10 /* Aggregate function with DISTINCT keyword */
#define EP_VarSelect 0x20 /* pSelect is correlated, not constant */
#define EP_Dequoted 0x40 /* True if the string has been dequoted */
/*
** These macros can be used to test, set, or clear bits in the
@@ -856,6 +940,7 @@ struct Expr {
struct ExprList {
int nExpr; /* Number of expressions on the list */
int nAlloc; /* Number of entries allocated below */
int iECursor; /* VDBE Cursor associated with this ExprList */
struct ExprList_item {
Expr *pExpr; /* The list of expressions */
char *zName; /* Token associated with this expression */
@@ -881,12 +966,12 @@ struct ExprList {
** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
*/
struct IdList {
int nId; /* Number of identifiers on the list */
int nAlloc; /* Number of entries allocated for a[] below */
struct IdList_item {
char *zName; /* Name of the identifier */
int idx; /* Index in some Table.aCol[] of a column named zName */
} *a;
int nId; /* Number of identifiers on the list */
int nAlloc; /* Number of entries allocated for a[] below */
};
/*
@@ -914,8 +999,8 @@ struct SrcList {
char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
Table *pTab; /* An SQL table corresponding to zName */
Select *pSelect; /* A SELECT statement used in place of a table name */
int jointype; /* Type of join between this table and the next */
int iCursor; /* The VDBE cursor number used to access this table */
u8 jointype; /* Type of join between this table and the next */
i16 iCursor; /* The VDBE cursor number used to access this table */
Expr *pOn; /* The ON clause of a join */
IdList *pUsing; /* The USING clause of a join */
Bitmask colUsed; /* Bit N (1<<N) set if column N or pTab is used */
@@ -926,11 +1011,12 @@ struct SrcList {
** Permitted values of the SrcList.a.jointype field
*/
#define JT_INNER 0x0001 /* Any kind of inner or cross join */
#define JT_NATURAL 0x0002 /* True for a "natural" join */
#define JT_LEFT 0x0004 /* Left outer join */
#define JT_RIGHT 0x0008 /* Right outer join */
#define JT_OUTER 0x0010 /* The "OUTER" keyword is present */
#define JT_ERROR 0x0020 /* unknown or unsupported join type */
#define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */
#define JT_NATURAL 0x0004 /* True for a "natural" join */
#define JT_LEFT 0x0008 /* Left outer join */
#define JT_RIGHT 0x0010 /* Right outer join */
#define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
#define JT_ERROR 0x0040 /* unknown or unsupported join type */
/*
** For each nested loop in a WHERE clause implementation, the WhereInfo
@@ -939,18 +1025,20 @@ struct SrcList {
** access or modified by other modules.
*/
struct WhereLevel {
int iMem; /* Memory cell used by this level */
Index *pIdx; /* Index used. NULL if no index */
int iTabCur; /* The VDBE cursor used to access the table */
int iIdxCur; /* The VDBE cursor used to acesss pIdx */
int score; /* How well this index scored */
int brk; /* Jump here to break out of the loop */
int cont; /* Jump here to continue with the next loop cycle */
int op, p1, p2; /* Opcode used to terminate the loop */
int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
int top; /* First instruction of interior of the loop */
int inOp, inP1, inP2;/* Opcode used to implement an IN operator */
int bRev; /* Do the scan in the reverse direction */
int iFrom; /* Which entry in the FROM clause */
int flags; /* Flags associated with this level */
int iMem; /* First memory cell used by this level */
int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
Index *pIdx; /* Index used. NULL if no index */
int iTabCur; /* The VDBE cursor used to access the table */
int iIdxCur; /* The VDBE cursor used to acesss pIdx */
int brk; /* Jump here to break out of the loop */
int cont; /* Jump here to continue with the next loop cycle */
int top; /* First instruction of interior of the loop */
int op, p1, p2; /* Opcode used to terminate the loop */
int nEq; /* Number of == or IN constraints on this loop */
int nIn; /* Number of IN operators constraining this loop */
int *aInLoop; /* Loop terminators for IN operators */
};
/*
@@ -998,8 +1086,9 @@ struct NameContext {
int nRef; /* Number of names resolved by this context */
int nErr; /* Number of errors encountered while resolving names */
u8 allowAgg; /* Aggregate functions allowed here */
u8 hasAgg;
u8 hasAgg; /* True if aggregates are seen */
int nDepth; /* Depth of subquery recursion. 1 for no recursion */
AggInfo *pAggInfo; /* Information about aggregates at this level */
NameContext *pNext; /* Next outer name context. NULL for outermost */
};
@@ -1012,65 +1101,55 @@ struct NameContext {
** limit and nOffset to the value of the offset (or 0 if there is not
** offset). But later on, nLimit and nOffset become the memory locations
** in the VDBE that record the limit and offset counters.
**
** addrOpenVirt[] entries contain the address of OP_OpenVirtual opcodes.
** These addresses must be stored so that we can go back and fill in
** the P3_KEYINFO and P2 parameters later. Neither the KeyInfo nor
** the number of columns in P2 can be computed at the same time
** as the OP_OpenVirtual instruction is coded because not
** enough information about the compound query is known at that point.
** The KeyInfo for addrOpenVirt[0] and [1] contains collating sequences
** for the result set. The KeyInfo for addrOpenVirt[2] contains collating
** sequences for the ORDER BY clause.
*/
struct Select {
ExprList *pEList; /* The fields of the result */
u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
u8 isDistinct; /* True if the DISTINCT keyword is present */
u8 isResolved; /* True once sqlite3SelectResolve() has run. */
u8 isAgg; /* True if this is an aggregate query */
u8 usesVirt; /* True if uses an OpenVirtual opcode */
u8 disallowOrderBy; /* Do not allow an ORDER BY to be attached if TRUE */
SrcList *pSrc; /* The FROM clause */
Expr *pWhere; /* The WHERE clause */
ExprList *pGroupBy; /* The GROUP BY clause */
Expr *pHaving; /* The HAVING clause */
ExprList *pOrderBy; /* The ORDER BY clause */
Select *pPrior; /* Prior select in a compound select statement */
Select *pRightmost; /* Right-most select in a compound select statement */
Expr *pLimit; /* LIMIT expression. NULL means not used. */
Expr *pOffset; /* OFFSET expression. NULL means not used. */
int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
IdList **ppOpenTemp; /* OP_OpenTemp addresses used by multi-selects */
Fetch *pFetch; /* If this stmt is part of a FETCH command */
u8 isResolved; /* True once sqlite3SelectResolve() has run. */
u8 isAgg; /* True if this is an aggregate query */
int addrOpenVirt[3]; /* OP_OpenVirtual opcodes related to this select */
};
/*
** The results of a select can be distributed in several ways.
*/
#define SRT_Callback 1 /* Invoke a callback with each row of result */
#define SRT_Mem 2 /* Store result in a memory cell */
#define SRT_Set 3 /* Store result as unique keys in a table */
#define SRT_Union 5 /* Store result as keys in a table */
#define SRT_Except 6 /* Remove result from a UNION table */
#define SRT_Table 7 /* Store result as data with a unique key */
#define SRT_TempTable 8 /* Store result in a trasient table */
#define SRT_Discard 9 /* Do not save the results anywhere */
#define SRT_Sorter 10 /* Store results in the sorter */
#define SRT_Subroutine 11 /* Call a subroutine to handle results */
#define SRT_Exists 12 /* Put 0 or 1 in a memory cell */
#define SRT_Union 1 /* Store result as keys in an index */
#define SRT_Except 2 /* Remove result from a UNION index */
#define SRT_Discard 3 /* Do not save the results anywhere */
/*
** When a SELECT uses aggregate functions (like "count(*)" or "avg(f1)")
** we have to do some additional analysis of expressions. An instance
** of the following structure holds information about a single subexpression
** somewhere in the SELECT statement. An array of these structures holds
** all the information we need to generate code for aggregate
** expressions.
**
** Note that when analyzing a SELECT containing aggregates, both
** non-aggregate field variables and aggregate functions are stored
** in the AggExpr array of the Parser structure.
**
** The pExpr field points to an expression that is part of either the
** field list, the GROUP BY clause, the HAVING clause or the ORDER BY
** clause. The expression will be freed when those clauses are cleaned
** up. Do not try to delete the expression attached to AggExpr.pExpr.
**
** If AggExpr.pExpr==0, that means the expression is "count(*)".
*/
struct AggExpr {
int isAgg; /* if TRUE contains an aggregate function */
Expr *pExpr; /* The expression */
FuncDef *pFunc; /* Information about the aggregate function */
};
/* The ORDER BY clause is ignored for all of the above */
#define IgnorableOrderby(X) (X<=SRT_Discard)
#define SRT_Callback 4 /* Invoke a callback with each row of result */
#define SRT_Mem 5 /* Store result in a memory cell */
#define SRT_Set 6 /* Store non-null results as keys in an index */
#define SRT_Table 7 /* Store result as data with an automatic rowid */
#define SRT_VirtualTab 8 /* Create virtual table and store like SRT_Table */
#define SRT_Subroutine 9 /* Call a subroutine to handle results */
#define SRT_Exists 10 /* Put 0 or 1 in a memory cell */
/*
** An SQL parser context. A copy of this structure is passed through
@@ -1095,11 +1174,10 @@ struct Parse {
int nTab; /* Number of previously allocated VDBE cursors */
int nMem; /* Number of memory cells used so far */
int nSet; /* Number of sets used so far */
u32 cookieMask; /* Bitmask of schema verified databases */
int cookieValue[MAX_ATTACHED+2]; /* Values of cookies to verify */
int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
u32 writeMask; /* Start a write transaction on these databases */
u8 fillAgg; /* If true, ignore the Expr.iAgg field. Normally false */
u32 cookieMask; /* Bitmask of schema verified databases */
int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
int cookieValue[MAX_ATTACHED+2]; /* Values of cookies to verify */
/* Above is constant between recursions. Below is reset before and after
** each recursion */
@@ -1118,9 +1196,6 @@ struct Parse {
Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
TriggerStack *trigStack; /* Trigger actions being coded */
const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
int nAgg; /* Number of aggregate expressions */
AggExpr *aAgg; /* An array of aggregate expressions */
int nMaxDepth; /* Maximum depth of subquery recursion */
};
/*
@@ -1133,7 +1208,7 @@ struct AuthContext {
};
/*
** Bitfield flags for P2 value in OP_PutIntKey and OP_Delete
** Bitfield flags for P2 value in OP_Insert and OP_Delete
*/
#define OPFLAG_NCHANGE 1 /* Set to update db->nChange */
#define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */
@@ -1300,6 +1375,19 @@ typedef struct {
*/
extern int sqlite3_always_code_trigger_setup;
/*
** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production
** builds) or a function call (for debugging). If it is a function call,
** it allows the operator to set a breakpoint at the spot where database
** corruption is first detected.
*/
#ifdef SQLITE_DEBUG
extern int sqlite3Corrupt(void);
# define SQLITE_CORRUPT_BKPT sqlite3Corrupt()
#else
# define SQLITE_CORRUPT_BKPT SQLITE_CORRUPT
#endif
/*
** Internal function prototypes
*/
@@ -1325,15 +1413,19 @@ void sqlite3RealToSortable(double r, char *);
char *sqlite3StrDup(const char*);
char *sqlite3StrNDup(const char*, int);
# define sqlite3CheckMemory(a,b)
# define sqlite3MallocX sqlite3Malloc
#endif
void sqlite3ReallocOrFree(void**,int);
void sqlite3FreeX(void*);
void *sqlite3MallocX(int);
char *sqlite3MPrintf(const char*, ...);
char *sqlite3VMPrintf(const char*, va_list);
void sqlite3DebugPrintf(const char*, ...);
void *sqlite3TextToPtr(const char*);
void sqlite3SetString(char **, const char *, ...);
void sqlite3SetString(char **, ...);
void sqlite3ErrorMsg(Parse*, const char*, ...);
void sqlite3Dequote(char*);
void sqlite3DequoteExpr(Expr*);
int sqlite3KeywordCode(const char*, int);
int sqlite3RunParser(Parse*, const char*, char **);
void sqlite3FinishCoding(Parse*);
@@ -1359,10 +1451,10 @@ void sqlite3StartTable(Parse*,Token*,Token*,Token*,int,int);
void sqlite3AddColumn(Parse*,Token*);
void sqlite3AddNotNull(Parse*, int);
void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int);
void sqlite3AddColumnType(Parse*,Token*,Token*);
void sqlite3AddColumnType(Parse*,Token*);
void sqlite3AddDefaultValue(Parse*,Expr*);
void sqlite3AddCollateType(Parse*, const char*, int);
void sqlite3EndTable(Parse*,Token*,Select*);
void sqlite3EndTable(Parse*,Token*,Token*,Select*);
#ifndef SQLITE_OMIT_VIEW
void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int);
@@ -1374,6 +1466,7 @@ void sqlite3EndTable(Parse*,Token*,Select*);
void sqlite3DropTable(Parse*, SrcList*, int);
void sqlite3DeleteTable(sqlite3*, Table*);
void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
int sqlite3ArrayAllocate(void**,int,int);
IdList *sqlite3IdListAppend(IdList*, Token*);
int sqlite3IdListIndex(IdList*,const char*);
SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
@@ -1397,7 +1490,7 @@ void sqlite3OpenTableForReading(Vdbe*, int iCur, Table*);
void sqlite3OpenTable(Vdbe*, int iCur, Table*, int);
void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, Fetch*);
WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**);
void sqlite3WhereEnd(WhereInfo*);
void sqlite3ExprCode(Parse*, Expr*);
void sqlite3ExprCodeAndCache(Parse*, Expr*);
@@ -1418,6 +1511,7 @@ int sqlite3ExprCompare(Expr*, Expr*);
int sqliteFuncId(Token*);
int sqlite3ExprResolveNames(NameContext *, Expr *);
int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
Vdbe *sqlite3GetVdbe(Parse*);
void sqlite3Randomness(int, void*);
void sqlite3RollbackAll(sqlite3*);
@@ -1426,6 +1520,7 @@ void sqlite3BeginTransaction(Parse*, int);
void sqlite3CommitTransaction(Parse*);
void sqlite3RollbackTransaction(Parse*);
int sqlite3ExprIsConstant(Expr*);
int sqlite3ExprIsConstantOrFunction(Expr*);
int sqlite3ExprIsInteger(Expr*, int*);
int sqlite3IsRowid(const char*);
void sqlite3GenerateRowDelete(sqlite3*, Vdbe*, Table*, int, int);
@@ -1498,7 +1593,7 @@ int sqlite3FixSelect(DbFixer*, Select*);
int sqlite3FixExpr(DbFixer*, Expr*);
int sqlite3FixExprList(DbFixer*, ExprList*);
int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
double sqlite3AtoF(const char *z, const char **);
int sqlite3AtoF(const char *z, double*);
char *sqlite3_snprintf(int,char*,const char*,...);
int sqlite3GetInt32(const char *, int*);
int sqlite3FitsIn64Bits(const char *);
@@ -1534,16 +1629,36 @@ const void *sqlite3ValueText(sqlite3_value*, u8);
int sqlite3ValueBytes(sqlite3_value*, u8);
void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
void sqlite3ValueFree(sqlite3_value*);
sqlite3_value *sqlite3ValueNew();
sqlite3_value *sqlite3ValueNew(void);
sqlite3_value *sqlite3GetTransientValue(sqlite3*db);
int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
extern const unsigned char sqlite3UpperToLower[];
void sqlite3RootPageMoved(Db*, int, int);
void sqlite3Reindex(Parse*, Token*, Token*);
void sqlite3AlterFunctions(sqlite3*);
void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
int sqlite3GetToken(const unsigned char *, int *);
void sqlite3NestedParse(Parse*, const char*, ...);
void sqlite3ExpirePreparedStatements(sqlite3*);
void sqlite3CodeSubselect(Parse *, Expr *);
int sqlite3SelectResolve(Parse *, Select *, NameContext *);
void sqlite3ColumnDefault(Vdbe *, Table *, int);
void sqlite3AlterFinishAddColumn(Parse *, Token *);
void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
const char *sqlite3TestErrorName(int);
CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int);
char sqlite3AffinityType(const Token*);
void sqlite3Analyze(Parse*, Token*, Token*);
int sqlite3InvokeBusyHandler(BusyHandler*);
int sqlite3FindDb(sqlite3*, Token*);
void sqlite3AnalysisLoad(sqlite3*,int iDB);
void sqlite3DefaultRowEst(Index*);
void sqlite3RegisterLikeFunctions(sqlite3*, int);
int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
#ifdef SQLITE_SSE
#include "sseInt.h"
#endif
#endif
+953 -632
View File
File diff suppressed because it is too large Load Diff
+287 -26
View File
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.129 2005/02/04 04:07:18 danielk1977 Exp $
** $Id: test1.c,v 1.162 2005/09/19 13:15:23 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -21,12 +21,11 @@
#include <stdlib.h>
#include <string.h>
static const char * errorName(int rc){
const char *sqlite3TestErrorName(int rc){
const char *zName = 0;
switch( rc ){
case SQLITE_OK: zName = "SQLITE_OK"; break;
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
@@ -36,13 +35,11 @@ static const char * errorName(int rc){
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
@@ -57,12 +54,13 @@ static const char * errorName(int rc){
}
return zName;
}
#define errorName sqlite3TestErrorName
/*
** Convert an sqlite3_stmt* into an sqlite3*. This depends on the
** fact that the sqlite3* is the first field in the Vdbe structure.
*/
#define StmtToDb(X) (*(sqlite3**)(X))
#define StmtToDb(X) sqlite3_db_handle(X)
/*
** Check a return value to make sure it agrees with the results
@@ -663,7 +661,7 @@ static int sqlite3_mprintf_str(
}
/*
** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER DOUBLE
** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE
**
** Call mprintf with two integer arguments and one double argument
*/
@@ -678,7 +676,7 @@ static int sqlite3_mprintf_double(
char *z;
if( argc!=5 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" FORMAT INT INT STRING\"", 0);
" FORMAT INT INT DOUBLE\"", 0);
return TCL_ERROR;
}
for(i=2; i<4; i++){
@@ -692,7 +690,7 @@ static int sqlite3_mprintf_double(
}
/*
** Usage: sqlite3_mprintf_str FORMAT DOUBLE DOUBLE
** Usage: sqlite3_mprintf_scaled 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
@@ -746,6 +744,40 @@ static int sqlite3_mprintf_stronly(
return TCL_OK;
}
/*
** Usage: sqlite3_mprintf_hexdouble FORMAT HEX
**
** Call mprintf with a single double argument which is derived from the
** hexadecimal encoding of an IEEE double.
*/
static int sqlite3_mprintf_hexdouble(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
char *z;
double r;
unsigned x1, x2;
long long unsigned d;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" FORMAT STRING\"", 0);
return TCL_ERROR;
}
if( sscanf(argv[2], "%08x%08x", &x2, &x1)!=2 ){
Tcl_AppendResult(interp, "2nd argument should be 16-characters of hex", 0);
return TCL_ERROR;
}
d = x2;
d = (d<<32) + x1;
memcpy(&r, &d, sizeof(r));
z = sqlite3_mprintf(argv[1], r);
Tcl_AppendResult(interp, z, 0);
sqlite3_free(z);
return TCL_OK;
}
/*
** Usage: sqlite_malloc_fail N ?REPEAT-INTERVAL?
**
@@ -971,6 +1003,30 @@ static int test_expired(
return TCL_OK;
}
/*
** Usage: sqlite3_transfer_bindings FROMSTMT TOSTMT
**
** Transfer all bindings from FROMSTMT over to TOSTMT
*/
static int test_transfer_bind(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
sqlite3_stmt *pStmt1, *pStmt2;
if( objc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"",
Tcl_GetStringFromObj(objv[0], 0), " FROM-STMT TO-STMT", 0);
return TCL_ERROR;
}
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt1)) return TCL_ERROR;
if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt2)) return TCL_ERROR;
Tcl_SetObjResult(interp,
Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1,pStmt2)));
return TCL_OK;
}
/*
** Usage: sqlite3_changes DB
**
@@ -1085,6 +1141,7 @@ static int test_collate_func(
Tcl_Interp *i = pTestCollateInterp;
int encin = (int)pCtx;
int res;
int n;
sqlite3_value *pVal;
Tcl_Obj *pX;
@@ -1108,9 +1165,11 @@ static int test_collate_func(
pVal = sqlite3ValueNew();
sqlite3ValueSetStr(pVal, nA, zA, encin, SQLITE_STATIC);
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj(sqlite3_value_text(pVal),-1));
n = sqlite3_value_bytes(pVal);
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj(sqlite3_value_text(pVal),n));
sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC);
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj(sqlite3_value_text(pVal),-1));
n = sqlite3_value_bytes(pVal);
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj(sqlite3_value_text(pVal),n));
sqlite3ValueFree(pVal);
Tcl_EvalObjEx(i, pX, 0);
@@ -1580,6 +1639,7 @@ static int test_bind_text(
rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT);
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
return TCL_ERROR;
}
@@ -2032,7 +2092,7 @@ static int test_complete16(
int objc,
Tcl_Obj *CONST objv[]
){
#ifndef SQLITE_OMIT_UTF16
#if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16)
char *zBuf;
if( objc!=2 ){
@@ -2042,7 +2102,7 @@ static int test_complete16(
zBuf = Tcl_GetByteArrayFromObj(objv[1], 0);
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_complete16(zBuf)));
#endif /* SQLITE_OMIT_UTF16 */
#endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */
return TCL_OK;
}
@@ -2294,6 +2354,24 @@ static int test_stmt_utf8(
return TCL_OK;
}
static int test_global_recover(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
#ifndef SQLITE_OMIT_GLOBALRECOVER
int rc;
if( objc!=1 ){
Tcl_WrongNumArgs(interp, 1, objv, "");
return TCL_ERROR;
}
rc = sqlite3_global_recover();
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
#endif
return TCL_OK;
}
/*
** Usage: sqlite3_column_text STMT column
**
@@ -2364,6 +2442,7 @@ static int test_stmt_int(
return TCL_OK;
}
#ifndef SQLITE_OMIT_DISKIO
/*
** Usage: sqlite3OsOpenReadWrite <filename>
*/
@@ -2523,6 +2602,7 @@ static int test_sqlite3OsTempFileName(
Tcl_AppendResult(interp, zFile, 0);
return TCL_OK;
}
#endif
/*
** Usage: sqlite_set_magic DB MAGIC-NUMBER
@@ -2577,27 +2657,51 @@ static int test_interrupt(
return TCL_OK;
}
static u8 *sqlite3_stack_baseline = 0;
/*
** Usage: sqlite3_sleep ms
**
** Sleep for the specified number of ms.
** Fill the stack with a known bitpattern.
*/
#if 0
static int test_sleep(
static void prepStack(void){
int i;
u32 bigBuf[65536];
for(i=0; i<sizeof(bigBuf); i++) bigBuf[i] = 0xdeadbeef;
sqlite3_stack_baseline = (u8*)&bigBuf[65536];
}
/*
** Get the current stack depth. Used for debugging only.
*/
u64 sqlite3StackDepth(void){
u8 x;
return (u64)(sqlite3_stack_baseline - &x);
}
/*
** Usage: sqlite3_stack_used DB SQL
**
** Try to measure the amount of stack space used by a call to sqlite3_exec
*/
static int test_stack_used(
void * clientData,
Tcl_Interp *interp,
int argc,
char **argv
){
sqlite3 *db;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ms", 0);
int i;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" DB SQL", 0);
return TCL_ERROR;
}
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_sleep(atoi(argv[1]))));
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
prepStack();
sqlite3_exec(db, argv[2], 0, 0, 0);
for(i=65535; i>=0 && ((u32*)sqlite3_stack_baseline)[-i]==0xdeadbeef; i--){}
Tcl_SetObjResult(interp, Tcl_NewIntObj(i*4));
return TCL_OK;
}
#endif
/*
** Usage: sqlite_delete_function DB function-name
@@ -2651,6 +2755,31 @@ static int delete_collation(
return TCL_OK;
}
/*
** Usage: sqlite3_get_autocommit DB
**
** Return true if the database DB is currently in auto-commit mode.
** Return false if not.
*/
static int get_autocommit(
void * clientData,
Tcl_Interp *interp,
int argc,
char **argv
){
char zBuf[30];
sqlite3 *db;
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", sqlite3_get_autocommit(db));
Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK;
}
/*
** Usage: tcl_variable_type VARIABLENAME
**
@@ -2682,12 +2811,30 @@ static int tcl_variable_type(
** procedures use this to determine when tests should be omitted.
*/
static void set_options(Tcl_Interp *interp){
#ifdef SQLITE_32BIT_ROWID
Tcl_SetVar2(interp, "sqlite_options", "rowid32", "1", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "rowid32", "0", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_CASE_SENSITIVE_LIKE
Tcl_SetVar2(interp, "sqlite_options","casesensitivelike","1",TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options","casesensitivelike","0",TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_ALTERTABLE
Tcl_SetVar2(interp, "sqlite_options", "altertable", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "altertable", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_ANALYZE
Tcl_SetVar2(interp, "sqlite_options", "analyze", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "analyze", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_AUTHORIZATION
Tcl_SetVar2(interp, "sqlite_options", "auth", "0", TCL_GLOBAL_ONLY);
#else
@@ -2711,12 +2858,30 @@ static void set_options(Tcl_Interp *interp){
Tcl_SetVar2(interp,"sqlite_options","default_autovacuum","1",TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
Tcl_SetVar2(interp, "sqlite_options", "between_opt", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "between_opt", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_BLOB_LITERAL
Tcl_SetVar2(interp, "sqlite_options", "bloblit", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "bloblit", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_CAST
Tcl_SetVar2(interp, "sqlite_options", "cast", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "cast", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_COMPLETE
Tcl_SetVar2(interp, "sqlite_options", "complete", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "complete", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_COMPOUND_SELECT
Tcl_SetVar2(interp, "sqlite_options", "compound", "0", TCL_GLOBAL_ONLY);
#else
@@ -2735,6 +2900,12 @@ static void set_options(Tcl_Interp *interp){
Tcl_SetVar2(interp, "sqlite_options", "datetime", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_DISKIO
Tcl_SetVar2(interp, "sqlite_options", "diskio", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "diskio", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_EXPLAIN
Tcl_SetVar2(interp, "sqlite_options", "explain", "0", TCL_GLOBAL_ONLY);
#else
@@ -2753,25 +2924,49 @@ static void set_options(Tcl_Interp *interp){
Tcl_SetVar2(interp, "sqlite_options", "foreignkey", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_GLOBALRECOVER
Tcl_SetVar2(interp, "sqlite_options", "globalrecover", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "globalrecover", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_INTEGRITY_CHECK
Tcl_SetVar2(interp, "sqlite_options", "integrityck", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "integrityck", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
Tcl_SetVar2(interp, "sqlite_options", "like_opt", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "like_opt", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_MEMORYDB
Tcl_SetVar2(interp, "sqlite_options", "memorydb", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "memorydb", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_OR_OPTIMIZATION
Tcl_SetVar2(interp, "sqlite_options", "or_opt", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "or_opt", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_PAGER_PRAGMAS
Tcl_SetVar2(interp, "sqlite_options", "pager_pragmas", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "pager_pragmas", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_PRAGMA
#ifdef SQLITE_OMIT_PARSER
Tcl_SetVar2(interp, "sqlite_options", "parser", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "parser", "1", TCL_GLOBAL_ONLY);
#endif
#if defined(SQLITE_OMIT_PRAGMA) || defined(SQLITE_OMIT_FLAG_PRAGMAS)
Tcl_SetVar2(interp, "sqlite_options", "pragma", "0", TCL_GLOBAL_ONLY);
Tcl_SetVar2(interp, "sqlite_options", "integrityck", "0", TCL_GLOBAL_ONLY);
#else
@@ -2820,12 +3015,24 @@ static void set_options(Tcl_Interp *interp){
Tcl_SetVar2(interp, "sqlite_options", "threadsafe", "0", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_TRACE
Tcl_SetVar2(interp, "sqlite_options", "trace", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "trace", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_TRIGGER
Tcl_SetVar2(interp, "sqlite_options", "trigger", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "trigger", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_TEMPDB
Tcl_SetVar2(interp, "sqlite_options", "tempdb", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "tempdb", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_UTF16
Tcl_SetVar2(interp, "sqlite_options", "utf16", "0", TCL_GLOBAL_ONLY);
#else
@@ -2864,6 +3071,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite3_mprintf_stronly", (Tcl_CmdProc*)sqlite3_mprintf_stronly},
{ "sqlite3_mprintf_double", (Tcl_CmdProc*)sqlite3_mprintf_double },
{ "sqlite3_mprintf_scaled", (Tcl_CmdProc*)sqlite3_mprintf_scaled },
{ "sqlite3_mprintf_hexdouble", (Tcl_CmdProc*)sqlite3_mprintf_hexdouble},
{ "sqlite3_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z },
{ "sqlite3_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid },
{ "sqlite3_exec_printf", (Tcl_CmdProc*)test_exec_printf },
@@ -2886,8 +3094,10 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
#if 0
{ "sqlite3_sleep", (Tcl_CmdProc*)test_sleep },
#endif
{ "sqlite_delete_function", (Tcl_CmdProc*)delete_function },
{ "sqlite_delete_collation", (Tcl_CmdProc*)delete_collation }
{ "sqlite_delete_function", (Tcl_CmdProc*)delete_function },
{ "sqlite_delete_collation", (Tcl_CmdProc*)delete_collation },
{ "sqlite3_get_autocommit", (Tcl_CmdProc*)get_autocommit },
{ "sqlite3_stack_used", (Tcl_CmdProc*)test_stack_used },
};
static struct {
char *zName;
@@ -2919,6 +3129,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite3_finalize", test_finalize ,0 },
{ "sqlite3_reset", test_reset ,0 },
{ "sqlite3_expired", test_expired ,0 },
{ "sqlite3_transfer_bindings", test_transfer_bind ,0 },
{ "sqlite3_changes", test_changes ,0 },
{ "sqlite3_step", test_step ,0 },
@@ -2940,8 +3151,10 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite3_column_decltype16", test_stmt_utf16, sqlite3_column_decltype16},
{ "sqlite3_column_name16", test_stmt_utf16, sqlite3_column_name16 },
#endif
{ "sqlite3_global_recover", test_global_recover, 0 },
/* Functions from os.h */
#ifndef SQLITE_OMIT_DISKIO
{ "sqlite3OsOpenReadWrite",test_sqlite3OsOpenReadWrite, 0 },
{ "sqlite3OsClose", test_sqlite3OsClose, 0 },
{ "sqlite3OsLock", test_sqlite3OsLock, 0 },
@@ -2949,6 +3162,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
/* Custom test interfaces */
{ "sqlite3OsUnlock", test_sqlite3OsUnlock, 0 },
#endif
#ifndef SQLITE_OMIT_UTF16
{ "add_test_collate", test_collate, 0 },
{ "add_test_collate_needed", test_collate_needed, 0 },
@@ -2961,7 +3175,22 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
static int bitmask_size = sizeof(Bitmask)*8;
int i;
extern int sqlite3_os_trace;
extern int sqlite3_where_trace;
extern int sqlite3_sync_count, sqlite3_fullsync_count;
extern int sqlite3_opentemp_count;
extern int sqlite3_memUsed;
extern int sqlite3_memMax;
extern int sqlite3_like_count;
#if OS_WIN
extern int sqlite3_os_type;
#endif
#ifdef SQLITE_DEBUG
extern int sqlite3_vdbe_addop_trace;
#endif
#ifdef SQLITE_TEST
extern char sqlite3_query_plan[];
static char *query_plan = sqlite3_query_plan;
#endif
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
@@ -2974,6 +3203,8 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
(char*)&sqlite3_search_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_sort_count",
(char*)&sqlite3_sort_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_like_count",
(char*)&sqlite3_like_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_interrupt_count",
(char*)&sqlite3_interrupt_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_open_file_count",
@@ -2982,12 +3213,42 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
(char*)&sqlite3_current_time, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_os_trace",
(char*)&sqlite3_os_trace, TCL_LINK_INT);
#if OS_WIN
Tcl_LinkVar(interp, "sqlite_os_type",
(char*)&sqlite3_os_type, TCL_LINK_INT);
#endif
#ifdef SQLITE_TEST
Tcl_LinkVar(interp, "sqlite_query_plan",
(char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
#endif
#ifdef SQLITE_DEBUG
Tcl_LinkVar(interp, "sqlite_addop_trace",
(char*)&sqlite3_vdbe_addop_trace, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_where_trace",
(char*)&sqlite3_where_trace, TCL_LINK_INT);
#endif
#ifdef SQLITE_MEMDEBUG
Tcl_LinkVar(interp, "sqlite_memused",
(char*)&sqlite3_memUsed, TCL_LINK_INT | TCL_LINK_READ_ONLY);
Tcl_LinkVar(interp, "sqlite_memmax",
(char*)&sqlite3_memMax, TCL_LINK_INT | TCL_LINK_READ_ONLY);
#endif
#ifndef SQLITE_OMIT_DISKIO
Tcl_LinkVar(interp, "sqlite_opentemp_count",
(char*)&sqlite3_opentemp_count, TCL_LINK_INT);
#endif
Tcl_LinkVar(interp, "sqlite_static_bind_value",
(char*)&sqlite_static_bind_value, TCL_LINK_STRING);
Tcl_LinkVar(interp, "sqlite_temp_directory",
(char*)&sqlite3_temp_directory, TCL_LINK_STRING);
Tcl_LinkVar(interp, "bitmask_size",
(char*)&bitmask_size, TCL_LINK_INT|TCL_LINK_READ_ONLY);
#if OS_UNIX
Tcl_LinkVar(interp, "sqlite_sync_count",
(char*)&sqlite3_sync_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_fullsync_count",
(char*)&sqlite3_fullsync_count, TCL_LINK_INT);
#endif /* OS_UNIX */
set_options(interp);
return TCL_OK;
}
+10 -4
View File
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test2.c,v 1.29 2005/02/06 02:45:43 drh Exp $
** $Id: test2.c,v 1.34 2005/09/16 10:13:42 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -30,7 +30,6 @@ static char *errorName(int rc){
switch( rc ){
case SQLITE_OK: zName = "SQLITE_OK"; break;
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
@@ -39,13 +38,11 @@ static char *errorName(int rc){
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
@@ -508,6 +505,7 @@ static int page_write(
return TCL_OK;
}
#ifndef SQLITE_OMIT_DISKIO
/*
** Usage: fake_big_file N FILENAME
**
@@ -555,6 +553,7 @@ static int fake_big_file(
}
return TCL_OK;
}
#endif
/*
** Register commands with the TCL interpreter.
@@ -562,6 +561,7 @@ static int fake_big_file(
int Sqlitetest2_Init(Tcl_Interp *interp){
extern int sqlite3_io_error_pending;
extern int sqlite3_diskfull_pending;
extern int sqlite3_diskfull;
static struct {
char *zName;
Tcl_CmdProc *xProc;
@@ -582,7 +582,9 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
{ "page_write", (Tcl_CmdProc*)page_write },
{ "page_number", (Tcl_CmdProc*)page_number },
{ "pager_truncate", (Tcl_CmdProc*)pager_truncate },
#ifndef SQLITE_OMIT_DISKIO
{ "fake_big_file", (Tcl_CmdProc*)fake_big_file },
#endif
};
int i;
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
@@ -592,6 +594,10 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
(char*)&sqlite3_io_error_pending, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_diskfull_pending",
(char*)&sqlite3_diskfull_pending, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_diskfull",
(char*)&sqlite3_diskfull, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_pending_byte",
(char*)&sqlite3_pending_byte, TCL_LINK_INT);
Tcl_LinkVar(interp, "pager_pagesize",
(char*)&test_pagesize, TCL_LINK_INT);
return TCL_OK;
+1 -3
View File
@@ -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.61 2005/01/21 08:13:15 danielk1977 Exp $
** $Id: test3.c,v 1.62 2005/08/11 02:10:19 drh Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
@@ -30,7 +30,6 @@ static char *errorName(int rc){
switch( rc ){
case SQLITE_OK: zName = "SQLITE_OK"; break;
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
@@ -39,7 +38,6 @@ static char *errorName(int rc){
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
+1 -4
View File
@@ -11,7 +11,7 @@
*************************************************************************
** Code for testing the the SQLite library in a multithreaded environment.
**
** $Id: test4.c,v 1.12 2004/09/06 17:24:13 drh Exp $
** $Id: test4.c,v 1.13 2005/08/11 02:10:19 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -375,7 +375,6 @@ static int tcl_thread_result(
switch( threadset[i].rc ){
case SQLITE_OK: zName = "SQLITE_OK"; break;
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
@@ -385,13 +384,11 @@ static int tcl_thread_result(
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
+54 -285
View File
@@ -15,7 +15,7 @@
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.100 2005/01/31 12:42:29 danielk1977 Exp $
** $Id: tokenize.c,v 1.107 2005/08/23 11:31:26 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -38,9 +38,9 @@
/*
** If X is a character that can be used in an identifier and
** X&0x80==0 then isIdChar[X] will be 1. If X&0x80==0x80 then
** X&0x80==0 then sqlite3IsIdChar[X] will be 1. If X&0x80==0x80 then
** X is always an identifier character. (Hence all UTF-8
** characters can be part of an identifier). isIdChar[X] will
** characters can be part of an identifier). sqlite3IsIdChar[X] will
** be 0 for every character in the lower 128 ASCII characters
** that cannot be used as part of an identifier.
**
@@ -55,7 +55,7 @@
** SQLite will allow '$' in identifiers for compatibility.
** But the feature is undocumented.
*/
static const char isIdChar[] = {
const char sqlite3IsIdChar[] = {
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
@@ -65,7 +65,7 @@ static const char isIdChar[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
};
#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && isIdChar[c-0x20]))
#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20]))
/*
** Return the length of the token that begins at z[0].
@@ -183,12 +183,9 @@ static int getToken(const unsigned char *z, int *tokenType){
*tokenType = TK_BITNOT;
return 1;
}
case '#': {
for(i=1; isdigit(z[i]) || (i==1 && z[1]=='-'); i++){}
*tokenType = TK_REGISTER;
return i;
}
case '\'': case '"': {
case '`':
case '\'':
case '"': {
int delim = z[0];
for(i=1; (c=z[i])!=0; i++){
if( c==delim ){
@@ -204,16 +201,23 @@ static int getToken(const unsigned char *z, int *tokenType){
return i;
}
case '.': {
*tokenType = TK_DOT;
return 1;
#ifndef SQLITE_OMIT_FLOATING_POINT
if( !isdigit(z[1]) )
#endif
{
*tokenType = TK_DOT;
return 1;
}
/* If the next character is a digit, this is a floating point
** number that begins with ".". Fall thru into the next case */
}
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
*tokenType = TK_INTEGER;
for(i=1; isdigit(z[i]); i++){}
for(i=0; isdigit(z[i]); i++){}
#ifndef SQLITE_OMIT_FLOATING_POINT
if( z[i]=='.' && isdigit(z[i+1]) ){
i += 2;
if( z[i]=='.' ){
i++;
while( isdigit(z[i]) ){ i++; }
*tokenType = TK_FLOAT;
}
@@ -239,50 +243,47 @@ static int getToken(const unsigned char *z, int *tokenType){
for(i=1; isdigit(z[i]); i++){}
return i;
}
case ':': {
for(i=1; IdChar(z[i]); i++){}
*tokenType = i>1 ? TK_VARIABLE : TK_ILLEGAL;
return i;
case '#': {
for(i=1; isdigit(z[i]); i++){}
if( i>1 ){
/* Parameters of the form #NNN (where NNN is a number) are used
** internally by sqlite3NestedParse. */
*tokenType = TK_REGISTER;
return i;
}
/* Fall through into the next case if the '#' is not followed by
** a digit. Try to match #AAAA where AAAA is a parameter name. */
}
#ifndef SQLITE_OMIT_TCL_VARIABLE
case '$': {
case '$':
#endif
case ':': {
int n = 0;
*tokenType = TK_VARIABLE;
if( z[1]=='{' ){
int nBrace = 1;
for(i=2; (c=z[i])!=0 && nBrace; i++){
if( c=='{' ){
nBrace++;
}else if( c=='}' ){
nBrace--;
}
}
if( c==0 ) *tokenType = TK_ILLEGAL;
}else{
int n = 0;
for(i=1; (c=z[i])!=0; i++){
if( isalnum(c) || c=='_' ){
n++;
}else if( c=='(' && n>0 ){
do{
i++;
}while( (c=z[i])!=0 && !isspace(c) && c!=')' );
if( c==')' ){
i++;
}else{
*tokenType = TK_ILLEGAL;
}
break;
}else if( c==':' && z[i+1]==':' ){
for(i=1; (c=z[i])!=0; i++){
if( IdChar(c) ){
n++;
#ifndef SQLITE_OMIT_TCL_VARIABLE
}else if( c=='(' && n>0 ){
do{
i++;
}while( (c=z[i])!=0 && !isspace(c) && c!=')' );
if( c==')' ){
i++;
}else{
break;
*tokenType = TK_ILLEGAL;
}
break;
}else if( c==':' && z[i+1]==':' ){
i++;
#endif
}else{
break;
}
if( n==0 ) *tokenType = TK_ILLEGAL;
}
if( n==0 ) *tokenType = TK_ILLEGAL;
return i;
}
#endif
#ifndef SQLITE_OMIT_BLOB_LITERAL
case 'x': case 'X': {
if( (c=z[1])=='\'' || c=='"' ){
@@ -341,10 +342,10 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
db->flags &= ~SQLITE_Interrupt;
pParse->rc = SQLITE_OK;
i = 0;
pEngine = sqlite3ParserAlloc((void*(*)(int))malloc);
pEngine = sqlite3ParserAlloc((void*(*)(int))sqlite3MallocX);
if( pEngine==0 ){
sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
return 1;
return SQLITE_NOMEM;
}
assert( pParse->sLastToken.dyn==0 );
assert( pParse->pNewTable==0 );
@@ -401,7 +402,7 @@ abort_parse:
}
sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
}
sqlite3ParserFree(pEngine, free);
sqlite3ParserFree(pEngine, sqlite3FreeX);
if( sqlite3_malloc_failed ){
pParse->rc = SQLITE_NOMEM;
}
@@ -430,235 +431,3 @@ abort_parse:
}
return nErr;
}
/*
** Token types used by the sqlite3_complete() routine. See the header
** comments on that procedure for additional information.
*/
#define tkSEMI 0
#define tkWS 1
#define tkOTHER 2
#define tkEXPLAIN 3
#define tkCREATE 4
#define tkTEMP 5
#define tkTRIGGER 6
#define tkEND 7
/*
** Return TRUE if the given SQL string ends in a semicolon.
**
** Special handling is require for CREATE TRIGGER statements.
** Whenever the CREATE TRIGGER keywords are seen, the statement
** must end with ";END;".
**
** This implementation uses a state machine with 7 states:
**
** (0) START At the beginning or end of an SQL statement. This routine
** returns 1 if it ends in the START state and 0 if it ends
** in any other state.
**
** (1) NORMAL We are in the middle of statement which ends with a single
** semicolon.
**
** (2) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
** a statement.
**
** (3) CREATE The keyword CREATE has been seen at the beginning of a
** statement, possibly preceeded by EXPLAIN and/or followed by
** TEMP or TEMPORARY
**
** (4) TRIGGER We are in the middle of a trigger definition that must be
** ended by a semicolon, the keyword END, and another semicolon.
**
** (5) SEMI We've seen the first semicolon in the ";END;" that occurs at
** the end of a trigger definition.
**
** (6) END We've seen the ";END" of the ";END;" that occurs at the end
** of a trigger difinition.
**
** Transitions between states above are determined by tokens extracted
** from the input. The following tokens are significant:
**
** (0) tkSEMI A semicolon.
** (1) tkWS Whitespace
** (2) tkOTHER Any other SQL token.
** (3) tkEXPLAIN The "explain" keyword.
** (4) tkCREATE The "create" keyword.
** (5) tkTEMP The "temp" or "temporary" keyword.
** (6) tkTRIGGER The "trigger" keyword.
** (7) tkEND The "end" keyword.
**
** Whitespace never causes a state transition and is always ignored.
**
** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed
** to recognize the end of a trigger can be omitted. All we have to do
** is look for a semicolon that is not part of an string or comment.
*/
int sqlite3_complete(const char *zSql){
u8 state = 0; /* Current state, using numbers defined in header comment */
u8 token; /* Value of the next token */
#ifndef SQLITE_OMIT_TRIGGER
/* A complex statement machine used to detect the end of a CREATE TRIGGER
** statement. This is the normal case.
*/
static const u8 trans[7][8] = {
/* Token: */
/* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
/* 0 START: */ { 0, 0, 1, 2, 3, 1, 1, 1, },
/* 1 NORMAL: */ { 0, 1, 1, 1, 1, 1, 1, 1, },
/* 2 EXPLAIN: */ { 0, 2, 1, 1, 3, 1, 1, 1, },
/* 3 CREATE: */ { 0, 3, 1, 1, 1, 3, 4, 1, },
/* 4 TRIGGER: */ { 5, 4, 4, 4, 4, 4, 4, 4, },
/* 5 SEMI: */ { 5, 5, 4, 4, 4, 4, 4, 6, },
/* 6 END: */ { 0, 6, 4, 4, 4, 4, 4, 4, },
};
#else
/* If triggers are not suppored by this compile then the statement machine
** used to detect the end of a statement is much simplier
*/
static const u8 trans[2][3] = {
/* Token: */
/* State: ** SEMI WS OTHER */
/* 0 START: */ { 0, 0, 1, },
/* 1 NORMAL: */ { 0, 1, 1, },
};
#endif /* SQLITE_OMIT_TRIGGER */
while( *zSql ){
switch( *zSql ){
case ';': { /* A semicolon */
token = tkSEMI;
break;
}
case ' ':
case '\r':
case '\t':
case '\n':
case '\f': { /* White space is ignored */
token = tkWS;
break;
}
case '/': { /* C-style comments */
if( zSql[1]!='*' ){
token = tkOTHER;
break;
}
zSql += 2;
while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
if( zSql[0]==0 ) return 0;
zSql++;
token = tkWS;
break;
}
case '-': { /* SQL-style comments from "--" to end of line */
if( zSql[1]!='-' ){
token = tkOTHER;
break;
}
while( *zSql && *zSql!='\n' ){ zSql++; }
if( *zSql==0 ) return state==0;
token = tkWS;
break;
}
case '[': { /* Microsoft-style identifiers in [...] */
zSql++;
while( *zSql && *zSql!=']' ){ zSql++; }
if( *zSql==0 ) return 0;
token = tkOTHER;
break;
}
case '"': /* single- and double-quoted strings */
case '\'': {
int c = *zSql;
zSql++;
while( *zSql && *zSql!=c ){ zSql++; }
if( *zSql==0 ) return 0;
token = tkOTHER;
break;
}
default: {
int c;
if( IdChar((u8)*zSql) ){
/* Keywords and unquoted identifiers */
int nId;
for(nId=1; IdChar(zSql[nId]); nId++){}
#ifdef SQLITE_OMIT_TRIGGER
token = tkOTHER;
#else
switch( *zSql ){
case 'c': case 'C': {
if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
token = tkCREATE;
}else{
token = tkOTHER;
}
break;
}
case 't': case 'T': {
if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
token = tkTRIGGER;
}else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
token = tkTEMP;
}else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
token = tkTEMP;
}else{
token = tkOTHER;
}
break;
}
case 'e': case 'E': {
if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
token = tkEND;
}else
#ifndef SQLITE_OMIT_EXPLAIN
if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
token = tkEXPLAIN;
}else
#endif
{
token = tkOTHER;
}
break;
}
default: {
token = tkOTHER;
break;
}
}
#endif /* SQLITE_OMIT_TRIGGER */
zSql += nId-1;
}else{
/* Operators and special symbols */
token = tkOTHER;
}
break;
}
}
state = trans[state][token];
zSql++;
}
return state==0;
}
#ifndef SQLITE_OMIT_UTF16
/*
** This routine is the same as the sqlite3_complete() routine described
** above, except that the parameter is required to be UTF-16 encoded, not
** UTF-8.
*/
int sqlite3_complete16(const void *zSql){
sqlite3_value *pVal;
char const *zSql8;
int rc = 0;
pVal = sqlite3ValueNew();
sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
if( zSql8 ){
rc = sqlite3_complete(zSql8);
}
sqlite3ValueFree(pVal);
return rc;
}
#endif /* SQLITE_OMIT_UTF16 */
+29 -15
View File
@@ -51,7 +51,7 @@ void sqlite3BeginTrigger(
Expr *pWhen, /* WHEN clause */
int isTemp /* True if the TEMPORARY keyword is present */
){
Trigger *pTrigger;
Trigger *pTrigger = 0;
Table *pTab;
char *zName = 0; /* Name of the trigger */
sqlite3 *db = pParse->db;
@@ -161,7 +161,6 @@ void sqlite3BeginTrigger(
pTrigger->name = zName;
zName = 0;
pTrigger->table = sqliteStrDup(pTableName->a[0].zName);
if( sqlite3_malloc_failed ) goto trigger_cleanup;
pTrigger->iDb = iDb;
pTrigger->iTabDb = pTab->iDb;
pTrigger->op = op;
@@ -178,6 +177,11 @@ trigger_cleanup:
sqlite3SrcListDelete(pTableName);
sqlite3IdListDelete(pColumns);
sqlite3ExprDelete(pWhen);
if( !pParse->pNewTrigger ){
sqlite3DeleteTrigger(pTrigger);
}else{
assert( pParse->pNewTrigger==pTrigger );
}
}
/*
@@ -193,9 +197,9 @@ void sqlite3FinishTrigger(
sqlite3 *db = pParse->db; /* The database */
DbFixer sFix;
if( pParse->nErr || pParse->pNewTrigger==0 ) goto triggerfinish_cleanup;
pTrig = pParse->pNewTrigger;
pParse->pNewTrigger = 0;
if( pParse->nErr || pTrig==0 ) goto triggerfinish_cleanup;
pTrig->step_list = pStepList;
while( pStepList ){
pStepList->pTrig = pTrig;
@@ -211,7 +215,7 @@ void sqlite3FinishTrigger(
*/
if( !db->init.busy ){
static const VdbeOpList insertTrig[] = {
{ OP_NewRecno, 0, 0, 0 },
{ OP_NewRowid, 0, 0, 0 },
{ OP_String8, 0, 0, "trigger" },
{ OP_String8, 0, 0, 0 }, /* 2: trigger name */
{ OP_String8, 0, 0, 0 }, /* 3: table name */
@@ -220,7 +224,7 @@ void sqlite3FinishTrigger(
{ OP_String8, 0, 0, 0 }, /* 6: SQL */
{ OP_Concat, 0, 0, 0 },
{ OP_MakeRecord, 5, 0, "tttit" },
{ OP_PutIntKey, 0, 0, 0 },
{ OP_Insert, 0, 0, 0 },
};
int addr;
Vdbe *v;
@@ -242,8 +246,13 @@ void sqlite3FinishTrigger(
if( db->init.busy ){
Table *pTab;
sqlite3HashInsert(&db->aDb[pTrig->iDb].trigHash,
Trigger *pDel;
pDel = sqlite3HashInsert(&db->aDb[pTrig->iDb].trigHash,
pTrig->name, strlen(pTrig->name)+1, pTrig);
if( pDel ){
assert( sqlite3_malloc_failed && pDel==pTrig );
goto triggerfinish_cleanup;
}
pTab = sqlite3LocateTable(pParse,pTrig->table,db->aDb[pTrig->iTabDb].zName);
assert( pTab!=0 );
pTrig->pNext = pTab->pTrigger;
@@ -328,18 +337,23 @@ TriggerStep *sqlite3TriggerInsertStep(
int orconf /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */
){
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
if( pTriggerStep==0 ) return 0;
assert(pEList == 0 || pSelect == 0);
assert(pEList != 0 || pSelect != 0);
pTriggerStep->op = TK_INSERT;
pTriggerStep->pSelect = pSelect;
pTriggerStep->target = *pTableName;
pTriggerStep->pIdList = pColumn;
pTriggerStep->pExprList = pEList;
pTriggerStep->orconf = orconf;
sqlitePersistTriggerStep(pTriggerStep);
if( pTriggerStep ){
pTriggerStep->op = TK_INSERT;
pTriggerStep->pSelect = pSelect;
pTriggerStep->target = *pTableName;
pTriggerStep->pIdList = pColumn;
pTriggerStep->pExprList = pEList;
pTriggerStep->orconf = orconf;
sqlitePersistTriggerStep(pTriggerStep);
}else{
sqlite3IdListDelete(pColumn);
sqlite3ExprListDelete(pEList);
sqlite3SelectDup(pSelect);
}
return pTriggerStep;
}
@@ -425,7 +439,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
zDb = pName->a[0].zDatabase;
zName = pName->a[0].zName;
nName = strlen(zName);
for(i=0; i<db->nDb; i++){
for(i=OMIT_TEMPDB; i<db->nDb; i++){
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1);
+78 -40
View File
@@ -12,10 +12,49 @@
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
**
** $Id: update.c,v 1.104 2005/01/29 08:32:45 danielk1977 Exp $
** $Id: update.c,v 1.112 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
/*
** The most recently coded instruction was an OP_Column to retrieve column
** 'i' of table pTab. This routine sets the P3 parameter of the
** OP_Column to the default value, if any.
**
** The default value of a column is specified by a DEFAULT clause in the
** column definition. This was either supplied by the user when the table
** was created, or added later to the table definition by an ALTER TABLE
** command. If the latter, then the row-records in the table btree on disk
** may not contain a value for the column and the default value, taken
** from the P3 parameter of the OP_Column instruction, is returned instead.
** If the former, then all row-records are guaranteed to include a value
** for the column and the P3 value is not required.
**
** Column definitions created by an ALTER TABLE command may only have
** literal default values specified: a number, null or a string. (If a more
** complicated default expression value was provided, it is evaluated
** when the ALTER TABLE is executed and one of the literal values written
** into the sqlite_master table.)
**
** Therefore, the P3 parameter is only required if the default value for
** the column is a literal number, string or null. The sqlite3ValueFromExpr()
** function is capable of transforming these types of expressions into
** sqlite3_value objects.
*/
void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i){
if( pTab && !pTab->pSelect ){
sqlite3_value *pValue;
u8 enc = sqlite3VdbeDb(v)->enc;
Column *pCol = &pTab->aCol[i];
sqlite3ValueFromExpr(pCol->pDflt, enc, pCol->affinity, &pValue);
if( pValue ){
sqlite3VdbeChangeP3(v, -1, (const char *)pValue, P3_MEM);
}else{
VdbeComment((v, "# %s.%s", pTab->zName, pCol->zName));
}
}
}
/*
** Process an UPDATE statement.
**
@@ -45,8 +84,8 @@ void sqlite3Update(
int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
** an expression for the i-th column of the table.
** aXRef[i]==-1 if the i-th column is not changed. */
int chngRecno; /* True if the record number is being changed */
Expr *pRecnoExpr = 0; /* Expression defining the new record number */
int chngRowid; /* True if the record number is being changed */
Expr *pRowidExpr = 0; /* Expression defining the new record number */
int openAll = 0; /* True if all indices need to be opened */
AuthContext sContext; /* The authorization context */
NameContext sNC; /* The name-context to resolve expressions in */
@@ -125,7 +164,7 @@ void sqlite3Update(
** column to be updated, make sure we have authorization to change
** that column.
*/
chngRecno = 0;
chngRowid = 0;
for(i=0; i<pChanges->nExpr; i++){
if( sqlite3ExprResolveNames(&sNC, pChanges->a[i].pExpr) ){
goto update_cleanup;
@@ -133,8 +172,8 @@ void sqlite3Update(
for(j=0; j<pTab->nCol; j++){
if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
if( j==pTab->iPKey ){
chngRecno = 1;
pRecnoExpr = pChanges->a[i].pExpr;
chngRowid = 1;
pRowidExpr = pChanges->a[i].pExpr;
}
aXRef[j] = i;
break;
@@ -142,8 +181,8 @@ void sqlite3Update(
}
if( j>=pTab->nCol ){
if( sqlite3IsRowid(pChanges->a[i].zName) ){
chngRecno = 1;
pRecnoExpr = pChanges->a[i].pExpr;
chngRowid = 1;
pRowidExpr = pChanges->a[i].pExpr;
}else{
sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
goto update_cleanup;
@@ -169,7 +208,7 @@ void sqlite3Update(
** number of the original table entry is changing.
*/
for(nIdx=nIdxTotal=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdxTotal++){
if( chngRecno ){
if( chngRowid ){
i = 0;
}else {
for(i=0; i<pIdx->nColumn; i++){
@@ -184,7 +223,7 @@ void sqlite3Update(
aIdxUsed = (char*)&apIdx[nIdx];
}
for(nIdx=j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
if( chngRecno ){
if( chngRowid ){
i = 0;
}else{
for(i=0; i<pIdx->nColumn; i++){
@@ -220,25 +259,25 @@ void sqlite3Update(
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
sqlite3BeginWriteOperation(pParse, 1, pTab->iDb);
/* If we are trying to update a view, construct that view into
** a temporary table.
/* If we are trying to update a view, realize that view into
** a ephemeral table.
*/
if( isView ){
Select *pView;
pView = sqlite3SelectDup(pTab->pSelect);
sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0);
sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0);
sqlite3SelectDelete(pView);
}
/* Begin the database scan
*/
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0);
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0);
if( pWInfo==0 ) goto update_cleanup;
/* Remember the index of every item to be updated.
*/
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0);
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0);
/* End the database scan loop.
*/
@@ -260,40 +299,40 @@ void sqlite3Update(
/* The top of the update loop for when there are triggers.
*/
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0);
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0);
/* Open a cursor and make it point to the record that is
** being updated.
*/
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
if( !isView ){
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
/* Open a cursor and make it point to the record that is
** being updated.
*/
sqlite3OpenTableForReading(v, iCur, pTab);
}
sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
/* Generate the OLD table
*/
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0);
/* Generate the NEW table
*/
if( chngRecno ){
sqlite3ExprCodeAndCache(pParse, pRecnoExpr);
if( chngRowid ){
sqlite3ExprCodeAndCache(pParse, pRowidExpr);
}else{
sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
}
for(i=0; i<pTab->nCol; i++){
if( i==pTab->iPKey ){
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
continue;
}
j = aXRef[i];
if( j<0 ){
sqlite3VdbeAddOp(v, OP_Column, iCur, i);
sqlite3ColumnDefault(v, pTab, i);
}else{
sqlite3ExprCodeAndCache(pParse, pChanges->a[j].pExpr);
}
@@ -303,7 +342,7 @@ void sqlite3Update(
sqlite3TableAffinityStr(v, pTab);
}
if( pParse->nErr ) goto update_cleanup;
sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
if( !isView ){
sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
}
@@ -353,8 +392,7 @@ void sqlite3Update(
** So make the cursor point at the old record.
*/
if( !triggers_exist ){
sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0);
addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0);
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
}
sqlite3VdbeAddOp(v, OP_NotExists, iCur, addr);
@@ -363,8 +401,8 @@ void sqlite3Update(
** will be after the update. (The old record number is currently
** on top of the stack.)
*/
if( chngRecno ){
sqlite3ExprCode(pParse, pRecnoExpr);
if( chngRowid ){
sqlite3ExprCode(pParse, pRowidExpr);
sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
}
@@ -372,12 +410,13 @@ void sqlite3Update(
*/
for(i=0; i<pTab->nCol; i++){
if( i==pTab->iPKey ){
sqlite3VdbeAddOp(v, OP_String8, 0, 0);
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
continue;
}
j = aXRef[i];
if( j<0 ){
sqlite3VdbeAddOp(v, OP_Column, iCur, i);
sqlite3ColumnDefault(v, pTab, i);
}else{
sqlite3ExprCode(pParse, pChanges->a[j].pExpr);
}
@@ -385,7 +424,7 @@ void sqlite3Update(
/* Do constraint checks
*/
sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1,
sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRowid, 1,
onError, addr);
/* Delete the old indices for the current record.
@@ -394,13 +433,13 @@ void sqlite3Update(
/* If changing the record number, delete the old record.
*/
if( chngRecno ){
if( chngRowid ){
sqlite3VdbeAddOp(v, OP_Delete, iCur, 0);
}
/* Create the new index entries and the new record.
*/
sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, -1);
sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRowid, 1, -1);
}
/* Increment the row counter
@@ -430,8 +469,7 @@ void sqlite3Update(
** all record selected by the WHERE clause have been updated.
*/
sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeAddOp(v, OP_ListReset, 0, 0);
sqlite3VdbeJumpHere(v, addr);
/* Close all tables if there were no FOR EACH ROW triggers */
if( !triggers_exist ){
+77 -41
View File
@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.130 2005/02/01 10:35:07 danielk1977 Exp $
** $Id: util.c,v 1.146 2005/09/17 18:34:11 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -58,6 +58,8 @@ int sqlite3_malloc_failed = 0;
*/
int sqlite3_nMalloc; /* Number of sqliteMalloc() calls */
int sqlite3_nFree; /* Number of sqliteFree() calls */
int sqlite3_memUsed; /* Total memory obtained from malloc */
int sqlite3_memMax; /* Mem usage high-water mark */
int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls */
int sqlite3_iMallocReset = -1; /* When iMallocFail reaches 0, set to this */
#if SQLITE_MEMDEBUG>1
@@ -65,18 +67,17 @@ static int memcnt = 0;
#endif
/*
** Number of 32-bit guard words
** Number of 32-bit guard words. This should probably be a multiple of
** 2 since on 64-bit machines we want the value returned by sqliteMalloc()
** to be 8-byte aligned.
*/
#define N_GUARD 1
#define N_GUARD 2
/*
** Allocate new memory and set it to zero. Return NULL if
** no memory is available.
** Check for a simulated memory allocation failure. Return true if
** the failure should be simulated. Return false to proceed as normal.
*/
void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
void *p;
int *pi;
int i, k;
static int simulatedMallocFailure(int n, char *zFile, int line){
if( sqlite3_iMallocFail>=0 ){
sqlite3_iMallocFail--;
if( sqlite3_iMallocFail==0 ){
@@ -86,10 +87,28 @@ void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
n, zFile,line);
#endif
sqlite3_iMallocFail = sqlite3_iMallocReset;
return 0;
return 1;
}
}
if( n==0 ) return 0;
return 0;
}
/*
** Allocate new memory and set it to zero. Return NULL if
** no memory is available.
*/
void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
void *p;
int *pi;
int i, k;
if( n==0 ){
return 0;
}
if( simulatedMallocFailure(n, zFile, line) ){
return 0;
}
sqlite3_memUsed += n;
if( sqlite3_memMax<sqlite3_memUsed ) sqlite3_memMax = sqlite3_memUsed;
k = (n+sizeof(int)-1)/sizeof(int);
pi = malloc( (N_GUARD*2+1+k)*sizeof(int));
if( pi==0 ){
@@ -110,6 +129,13 @@ void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
return p;
}
/*
** This version of malloc is always a real function, never a macro
*/
void *sqlite3MallocX(int n){
return sqlite3Malloc_(n, 0, __FILE__, __LINE__);
}
/*
** Check to see if the given pointer was obtained from sqliteMalloc()
** and is able to hold at least N bytes. Raise an exception if this
@@ -148,6 +174,7 @@ void sqlite3Free_(void *p, char *zFile, int line){
}
}
n = pi[N_GUARD];
sqlite3_memUsed -= n;
k = (n+sizeof(int)-1)/sizeof(int);
for(i=0; i<N_GUARD; i++){
if( pi[k+N_GUARD+1+i]!=0xdead3344 ){
@@ -179,6 +206,9 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
sqlite3Free_(oldP,zFile,line);
return 0;
}
if( simulatedMallocFailure(n, zFile, line) ){
return 0;
}
oldPi = oldP;
oldPi -= N_GUARD+1;
if( oldPi[0]!=0xdead1122 ){
@@ -186,6 +216,7 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
return 0;
}
oldN = oldPi[N_GUARD];
sqlite3_memUsed -= oldN;
oldK = (oldN+sizeof(int)-1)/sizeof(int);
for(i=0; i<N_GUARD; i++){
if( oldPi[oldK+N_GUARD+1+i]!=0xdead3344 ){
@@ -202,6 +233,8 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
}
for(i=0; i<N_GUARD; i++) pi[i] = 0xdead1122;
pi[N_GUARD] = n;
sqlite3_memUsed += n;
if( sqlite3_memMax<sqlite3_memUsed ) sqlite3_memMax = sqlite3_memUsed;
for(i=0; i<N_GUARD; i++) pi[k+N_GUARD+1+i] = 0xdead3344;
p = &pi[N_GUARD+1];
memcpy(p, oldP, n>oldN ? oldN : n);
@@ -259,6 +292,7 @@ void sqlite3FreeX(void *p){
*/
void *sqlite3Malloc(int n){
void *p;
if( n==0 ) return 0;
if( (p = malloc(n))==0 ){
if( n>0 ) sqlite3_malloc_failed++;
}else{
@@ -273,6 +307,7 @@ void *sqlite3Malloc(int n){
*/
void *sqlite3MallocRaw(int n){
void *p;
if( n==0 ) return 0;
if( (p = malloc(n))==0 ){
if( n>0 ) sqlite3_malloc_failed++;
}
@@ -331,6 +366,19 @@ char *sqlite3StrNDup(const char *z, int n){
}
#endif /* !defined(SQLITE_MEMDEBUG) */
/*
** Reallocate a buffer to a different size. This is similar to
** sqliteRealloc() except that if the allocation fails the buffer
** is freed.
*/
void sqlite3ReallocOrFree(void **ppBuf, int newSize){
void *pNew = sqliteRealloc(*ppBuf, newSize);
if( pNew==0 ){
sqliteFree(*ppBuf);
}
*ppBuf = pNew;
}
/*
** Create a string from the 2nd and subsequent arguments (up to the
** first NULL argument), store the string in memory obtained from
@@ -338,15 +386,15 @@ char *sqlite3StrNDup(const char *z, int n){
** point to that string. The 1st argument must either be NULL or
** point to memory obtained from sqliteMalloc().
*/
void sqlite3SetString(char **pz, const char *zFirst, ...){
void sqlite3SetString(char **pz, ...){
va_list ap;
int nByte;
const char *z;
char *zResult;
if( pz==0 ) return;
nByte = strlen(zFirst) + 1;
va_start(ap, zFirst);
nByte = 1;
va_start(ap, pz);
while( (z = va_arg(ap, const char*))!=0 ){
nByte += strlen(z);
}
@@ -356,16 +404,15 @@ void sqlite3SetString(char **pz, const char *zFirst, ...){
if( zResult==0 ){
return;
}
strcpy(zResult, zFirst);
zResult += strlen(zResult);
va_start(ap, zFirst);
*zResult = 0;
va_start(ap, pz);
while( (z = va_arg(ap, const char*))!=0 ){
strcpy(zResult, z);
zResult += strlen(zResult);
}
va_end(ap);
#ifdef SQLITE_DEBUG
#if SQLITE_DEBUG>1
#ifdef SQLITE_MEMDEBUG
#if SQLITE_MEMDEBUG>1
fprintf(stderr,"string at 0x%x is %s\n", (int)*pz, *pz);
#endif
#endif
@@ -388,7 +435,7 @@ void sqlite3SetString(char **pz, const char *zFirst, ...){
** zFormat and any string tokens that follow it are assumed to be
** encoded in UTF-8.
**
** To clear the most recent error for slqite handle "db", sqlite3Error
** To clear the most recent error for sqlite handle "db", sqlite3Error
** should be called with err_code set to SQLITE_OK and zFormat set
** to NULL.
*/
@@ -452,7 +499,8 @@ void sqlite3Dequote(char *z){
switch( quote ){
case '\'': break;
case '"': break;
case '[': quote = ']'; break;
case '`': break; /* For MySQL compatibility */
case '[': quote = ']'; break; /* For MS SqlServer compatibility */
default: return;
}
for(i=1, j=0; z[i]; i++){
@@ -557,8 +605,9 @@ int sqlite3IsNumber(const char *z, int *realnum, u8 enc){
** of "." depending on how locale is set. But that would cause problems
** for SQL. So this routine always uses "." regardless of locale.
*/
double sqlite3AtoF(const char *z, const char **pzEnd){
int sqlite3AtoF(const char *z, double *pResult){
int sign = 1;
const char *zBegin = z;
LONGDOUBLE_TYPE v1 = 0.0;
if( *z=='-' ){
sign = -1;
@@ -605,8 +654,8 @@ double sqlite3AtoF(const char *z, const char **pzEnd){
v1 *= scale;
}
}
if( pzEnd ) *pzEnd = z;
return sign<0 ? -v1 : v1;
*pResult = sign<0 ? -v1 : v1;
return z - zBegin;
}
/*
@@ -712,7 +761,7 @@ int sqlite3SafetyOn(sqlite3 *db){
if( db->magic==SQLITE_MAGIC_OPEN ){
db->magic = SQLITE_MAGIC_BUSY;
return 0;
}else if( db->magic==SQLITE_MAGIC_BUSY || db->magic==SQLITE_MAGIC_ERROR ){
}else if( db->magic==SQLITE_MAGIC_BUSY ){
db->magic = SQLITE_MAGIC_ERROR;
db->flags |= SQLITE_Interrupt;
}
@@ -728,7 +777,7 @@ int sqlite3SafetyOff(sqlite3 *db){
if( db->magic==SQLITE_MAGIC_BUSY ){
db->magic = SQLITE_MAGIC_OPEN;
return 0;
}else if( db->magic==SQLITE_MAGIC_OPEN || db->magic==SQLITE_MAGIC_ERROR ){
}else if( db->magic==SQLITE_MAGIC_OPEN ){
db->magic = SQLITE_MAGIC_ERROR;
db->flags |= SQLITE_Interrupt;
}
@@ -858,18 +907,6 @@ int sqlite3GetVarint32(const unsigned char *p, u32 *v){
u32 x;
int n;
unsigned char c;
#if 0
if( ((c = p[0]) & 0x80)==0 ){
*v = c;
return 1;
}
x = c & 0x7f;
if( ((c = p[1]) & 0x80)==0 ){
*v = (x<<7) | c;
return 2;
}
x = (x<<7) | (c & 0x7f);
#else
if( ((signed char*)p)[0]>=0 ){
*v = p[0];
return 1;
@@ -880,7 +917,6 @@ int sqlite3GetVarint32(const unsigned char *p, u32 *v){
return 2;
}
x = (x<<7) | (p[1] & 0x7f);
#endif
n = 2;
do{
x = (x<<7) | ((c = p[n++])&0x7f);
@@ -902,7 +938,7 @@ int sqlite3VarintLen(u64 v){
return i;
}
#if (!defined(SQLITE_OMIT_BLOB_LITERAL) && !defined(SQLITE_HAS_CODEC)) \
#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) \
|| defined(SQLITE_TEST)
/*
** Translate a single byte of Hex into an integer.
@@ -917,7 +953,7 @@ static int hexToInt(int h){
return h - 'A' + 10;
}
}
#endif /* (!SQLITE_OMIT_BLOB_LITERAL && !SQLITE_HAS_CODEC) || SQLITE_TEST */
#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC || SQLITE_TEST */
#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
/*
+13 -3
View File
@@ -14,7 +14,7 @@
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
**
** $Id: vacuum.c,v 1.39 2005/02/12 00:19:30 drh Exp $
** $Id: vacuum.c,v 1.45 2005/06/07 09:21:07 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -100,6 +100,11 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
Btree *pMain; /* The database being vacuumed */
Btree *pTemp;
char *zSql = 0;
int writeschema_flag; /* Saved value of the write-schema flag */
/* Save the current value of the write-schema flag before setting it. */
writeschema_flag = db->flags&SQLITE_WriteSchema;
db->flags |= SQLITE_WriteSchema;
if( !db->autoCommit ){
sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction",
@@ -211,13 +216,13 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
*/
rc = execExecSql(db,
"SELECT 'DELETE FROM vacuum_db.' || quote(name) || ';' "
"FROM sqlite_master WHERE name='sqlite_sequence' "
"FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence' "
);
if( rc!=SQLITE_OK ) goto end_of_vacuum;
rc = execExecSql(db,
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
"|| ' SELECT * FROM ' || quote(name) || ';' "
"FROM sqlite_master WHERE name=='sqlite_sequence';"
"FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';"
);
if( rc!=SQLITE_OK ) goto end_of_vacuum;
@@ -276,6 +281,10 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
}
end_of_vacuum:
/* Restore the original value of the write-schema flag. */
db->flags &= ~SQLITE_WriteSchema;
db->flags |= writeschema_flag;
/* Currently there is an SQL level transaction open on the vacuum
** database. No locks are held on any other files (since the main file
** was committed at the btree level). So it safe to end the transaction
@@ -296,5 +305,6 @@ end_of_vacuum:
if( zSql ) sqliteFree( zSql );
sqlite3ResetInternalSchema(db, 0);
#endif
return rc;
}
+650 -878
View File
File diff suppressed because it is too large Load Diff
+7 -7
View File
@@ -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.92 2005/01/29 08:32:45 danielk1977 Exp $
** $Id: vdbe.h,v 1.99 2005/09/20 17:42:23 drh Exp $
*/
#ifndef _SQLITE_VDBE_H_
#define _SQLITE_VDBE_H_
@@ -38,7 +38,7 @@ struct VdbeOp {
int p1; /* First operand */
int p2; /* Second parameter (often the jump destination) */
char *p3; /* Third parameter */
int p3type; /* P3_STATIC, P3_DYNAMIC or P3_POINTER */
int p3type; /* One of the P3_xxx constants defined below */
#ifdef VDBE_PROFILE
int cnt; /* Number of times this instruction was executed */
long long cycles; /* Total time spend executing this instruction */
@@ -64,11 +64,11 @@ typedef struct VdbeOpList VdbeOpList;
#define P3_NOTUSED 0 /* The P3 parameter is not used */
#define P3_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
#define P3_STATIC (-2) /* Pointer to a static string */
#define P3_POINTER (-3) /* P3 is a pointer to some structure or object */
#define P3_COLLSEQ (-4) /* P3 is a pointer to a CollSeq structure */
#define P3_FUNCDEF (-5) /* P3 is a pointer to a FuncDef structure */
#define P3_KEYINFO (-6) /* P3 is a pointer to a KeyInfo structure */
#define P3_VDBEFUNC (-7) /* P3 is a pointer to a VdbeFunc structure */
#define P3_MEM (-8) /* P3 is a pointer to a Mem* structure */
/* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
** is made. That copy is freed when the Vdbe is finalized. But if the
@@ -77,7 +77,7 @@ typedef struct VdbeOpList VdbeOpList;
** from a single sqliteMalloc(). But no copy is made and the calling
** function should *not* try to free the KeyInfo.
*/
#define P3_KEYINFO_HANDOFF (-7)
#define P3_KEYINFO_HANDOFF (-9)
/*
** The following macro converts a relative address in the p2 field
@@ -104,13 +104,12 @@ int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
void sqlite3VdbeJumpHere(Vdbe*, int addr);
void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
void sqlite3VdbeDequoteP3(Vdbe*, int addr);
int sqlite3VdbeFindOp(Vdbe*, int, int, int);
VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
int sqlite3VdbeMakeLabel(Vdbe*);
void sqlite3VdbeDelete(Vdbe*);
void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int,int);
void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
int sqlite3VdbeFinalize(Vdbe*);
void sqlite3VdbeResolveLabel(Vdbe*, int);
int sqlite3VdbeCurrentAddr(Vdbe*);
@@ -120,6 +119,7 @@ int sqliteVdbeSetVariables(Vdbe*,int,const char**);
void sqlite3VdbeSetNumCols(Vdbe*,int);
int sqlite3VdbeSetColName(Vdbe*, int, const char *, int);
void sqlite3VdbeCountChanges(Vdbe*);
sqlite3 *sqlite3VdbeDb(Vdbe*);
#ifndef NDEBUG
void sqlite3VdbeComment(Vdbe*, const char*, ...);
+46 -81
View File
@@ -60,19 +60,18 @@ typedef unsigned char Bool;
*/
struct Cursor {
BtCursor *pCursor; /* The cursor structure of the backend */
i64 lastRecno; /* Last recno from a Next or NextIdx operation */
i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
i64 nextRowid; /* Next rowid returned by OP_NewRowid */
Bool zeroed; /* True if zeroed out and ready for reuse */
Bool recnoIsValid; /* True if lastRecno is valid */
Bool keyAsData; /* The OP_Column command works on key instead of data */
Bool rowidIsValid; /* True if lastRowid is valid */
Bool atFirst; /* True if pointing to first entry */
Bool useRandomRowid; /* Generate new record numbers semi-randomly */
Bool nullRow; /* True if pointing to a row with no data */
Bool nextRowidValid; /* True if the nextRowid field is valid */
Bool pseudoTable; /* This is a NEW or OLD pseudo-tables of a trigger */
Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
Bool intKey; /* True if the table requires integer keys */
Bool zeroData; /* True if table contains keys only - no data */
Bool isTable; /* True if a table requiring integer keys */
Bool isIndex; /* True if an index containing keys only - no data */
u8 bogusIncrKey; /* Something for pIncrKey to point to if pKeyInfo==0 */
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
Btree *pBt; /* Separate file holding temporary table */
@@ -82,6 +81,7 @@ struct Cursor {
u8 *pIncrKey; /* Pointer to pKeyInfo->incrKey */
KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
int nField; /* Number of fields in the header */
i64 seqCount; /* Sequence counter */
/* Cached information about the header for the data record that the
** cursor is currently pointing to. Only valid if cacheValid is true.
@@ -114,35 +114,18 @@ typedef struct Cursor Cursor;
** SQLITE_BLOB.
*/
struct Mem {
i64 i; /* Integer value */
i64 i; /* Integer value. Or FuncDef* when flags==MEM_Agg */
double r; /* Real value */
char *z; /* String or BLOB value */
int n; /* Number of characters in string value, including '\0' */
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
u8 type; /* One of MEM_Null, MEM_Str, etc. */
u8 enc; /* TEXT_Utf8, TEXT_Utf16le, or TEXT_Utf16be */
double r; /* Real value */
char *z; /* String or BLOB value */
void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
char zShort[NBFS]; /* Space for short strings */
};
typedef struct Mem Mem;
/*
** A sorter builds a list of elements to be sorted. Each element of
** the list is an instance of the following structure.
*/
typedef struct Sorter Sorter;
struct Sorter {
int nKey; /* Number of bytes in the key */
char *zKey; /* The key by which we will sort */
Mem data;
Sorter *pNext; /* Next in the list */
};
/*
** Number of buckets used for merge-sort.
*/
#define NSORT 30
/* One or more of the following flags are set to indicate the validOK
** representations of the value stored in the Mem struct.
**
@@ -174,12 +157,7 @@ struct Sorter {
#define MEM_Static 0x0080 /* Mem.z points to a static string */
#define MEM_Ephem 0x0100 /* Mem.z points to an ephemeral string */
#define MEM_Short 0x0200 /* Mem.z points to Mem.zShort */
/* The following MEM_ value appears only in AggElem.aMem.s.flag fields.
** It indicates that the corresponding AggElem.aMem.z points to a
** aggregate function context that needs to be finalized.
*/
#define MEM_AggCtx 0x0400 /* Mem.z points to an agg function context */
#define MEM_Agg 0x0400 /* Mem.z points to an agg function context */
/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
@@ -211,41 +189,16 @@ typedef struct VdbeFunc VdbeFunc;
** But this file is the only place where the internal details of this
** structure are known.
**
** This structure is defined inside of vdbe.c because it uses substructures
** This structure is defined inside of vdbeInt.h because it uses substructures
** (Mem) which are only defined there.
*/
struct sqlite3_context {
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
Mem s; /* The return value is stored here */
void *pAgg; /* Aggregate context */
u8 isError; /* Set to true for an error */
int cnt; /* Number of times that the step function has been called */
CollSeq *pColl;
};
/*
** An Agg structure describes an Aggregator. Each Agg consists of
** zero or more Aggregator elements (AggElem). Each AggElem contains
** a key and one or more values. The values are used in processing
** aggregate functions in a SELECT. The key is used to implement
** the GROUP BY clause of a select.
*/
typedef struct Agg Agg;
typedef struct AggElem AggElem;
struct Agg {
int nMem; /* Number of values stored in each AggElem */
AggElem *pCurrent; /* The AggElem currently in focus */
FuncDef **apFunc; /* Information about aggregate functions */
Btree *pBtree; /* The tmp. btree used to group elements, if required. */
BtCursor *pCsr; /* Read/write cursor to the table in pBtree */
int nTab; /* Root page of the table in pBtree */
u8 searching; /* True between the first AggNext and AggReset */
};
struct AggElem {
char *zKey; /* The key to this AggElem */
int nKey; /* Number of bytes in the key, including '\0' at end */
Mem aMem[1]; /* The values for this AggElem */
Mem s; /* The return value is stored here */
Mem *pMem; /* Memory cell used to store aggregate context */
u8 isError; /* Set to true for an error */
CollSeq *pColl; /* Collating sequence */
};
/*
@@ -261,17 +214,29 @@ struct Set {
};
/*
** A Keylist is a bunch of keys into a table. The keylist can
** grow without bound. The keylist stores the ROWIDs of database
** records that need to be deleted or updated.
** A FifoPage structure holds a single page of valves. Pages are arranged
** in a list.
*/
typedef struct Keylist Keylist;
struct Keylist {
int nKey; /* Number of slots in aKey[] */
int nUsed; /* Next unwritten slot in aKey[] */
int nRead; /* Next unread slot in aKey[] */
Keylist *pNext; /* Next block of keys */
i64 aKey[1]; /* One or more keys. Extra space allocated as needed */
typedef struct FifoPage FifoPage;
struct FifoPage {
int nSlot; /* Number of entries aSlot[] */
int iWrite; /* Push the next value into this entry in aSlot[] */
int iRead; /* Read the next value from this entry in aSlot[] */
FifoPage *pNext; /* Next page in the fifo */
i64 aSlot[1]; /* One or more slots for rowid values */
};
/*
** The Fifo structure is typedef-ed in vdbeInt.h. But the implementation
** of that structure is private to this file.
**
** The Fifo structure describes the entire fifo.
*/
typedef struct Fifo Fifo;
struct Fifo {
int nEntry; /* Total number of entries */
FifoPage *pFirst; /* First page on the list */
FifoPage *pLast; /* Last page on the list */
};
/*
@@ -287,7 +252,7 @@ typedef struct Context Context;
struct Context {
int lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
int nChange; /* Statement changes (Vdbe.nChanges) */
Keylist *pList; /* Records that will participate in a DELETE or UPDATE */
Fifo sFifo; /* Records that will participate in a DELETE or UPDATE */
};
/*
@@ -313,7 +278,6 @@ struct Vdbe {
Mem *aColName; /* Column names to return */
int nCursor; /* Number of slots in apCsr[] */
Cursor **apCsr; /* One element of this array for each open cursor */
Sorter *pSort; /* A linked list of objects to be sorted */
int nVar; /* Number of entries in aVar[] */
Mem *aVar; /* Values for the OP_Variable opcode. */
char **azVar; /* Name of variables */
@@ -321,11 +285,8 @@ struct Vdbe {
int magic; /* Magic number for sanity checking */
int nMem; /* Number of memory locations currently allocated */
Mem *aMem; /* The memory locations */
int nAgg; /* Number of elements in apAgg */
Agg *apAgg; /* Array of aggregate contexts */
Agg *pAgg; /* Current aggregate context */
int nCallback; /* Number of callbacks invoked so far */
Keylist *pList; /* A list of ROWIDs */
Fifo sFifo; /* A list of ROWIDs */
int contextStackTop; /* Index of top element in the context stack */
int contextStackDepth; /* The size of the "context" stack */
Context *contextStack; /* Stack used by opcodes ContextPush & ContextPop*/
@@ -346,6 +307,7 @@ struct Vdbe {
u8 aborted; /* True if ROLLBACK in another VM causes an abort */
u8 expired; /* True if the VM needs to be recompiled */
int nChange; /* Number of db changes made since last reset */
i64 startTime; /* Time when query started - used for profiling */
};
/*
@@ -360,9 +322,6 @@ struct Vdbe {
** Function prototypes
*/
void sqlite3VdbeFreeCursor(Cursor*);
void sqlite3VdbeSorterReset(Vdbe*);
int sqlite3VdbeAggReset(sqlite3*, Agg *, KeyInfo *);
void sqlite3VdbeKeylistFree(Keylist*);
void sqliteVdbePopStack(Vdbe*,int);
int sqlite3VdbeCursorMoveto(Cursor*);
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
@@ -404,9 +363,15 @@ double sqlite3VdbeRealValue(Mem*);
int sqlite3VdbeMemRealify(Mem*);
int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
void sqlite3VdbeMemRelease(Mem *p);
void sqlite3VdbeMemFinalize(Mem*, FuncDef*);
#ifndef NDEBUG
void sqlite3VdbeMemSanity(Mem*, u8);
int sqlite3VdbeOpcodeNoPush(u8);
#endif
int sqlite3VdbeMemTranslate(Mem*, u8);
void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf);
int sqlite3VdbeMemHandleBom(Mem *pMem);
void sqlite3VdbeFifoInit(Fifo*);
int sqlite3VdbeFifoPush(Fifo*, i64);
int sqlite3VdbeFifoPop(Fifo*, i64*);
void sqlite3VdbeFifoClear(Fifo*);
+150 -37
View File
@@ -15,6 +15,7 @@
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
#include "os.h"
/*
** Return TRUE (non-zero) of the statement supplied as an argument needs
@@ -23,8 +24,6 @@
** that sqlite3_prepare() generates. For example, if new functions or
** collating sequences are registered or if an authorizer function is
** added or changed.
**
***** EXPERIMENTAL ******
*/
int sqlite3_expired(sqlite3_stmt *pStmt){
Vdbe *p = (Vdbe*)pStmt;
@@ -86,7 +85,7 @@ void sqlite3_result_blob(
int n,
void (*xDel)(void *)
){
assert( n>0 );
assert( n>=0 );
sqlite3VdbeMemSetStr(&pCtx->s, z, n, 0, xDel);
}
void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
@@ -175,9 +174,10 @@ int sqlite3_step(sqlite3_stmt *pStmt){
return SQLITE_MISUSE;
}
if( p->pc<0 ){
#ifndef SQLITE_OMIT_TRACE
/* Invoke the trace callback if there is one
*/
if( (db = p->db)->xTrace && !db->init.busy ){
if( db->xTrace && !db->init.busy ){
assert( p->nOp>0 );
assert( p->aOp[p->nOp-1].opcode==OP_Noop );
assert( p->aOp[p->nOp-1].p3!=0 );
@@ -189,6 +189,12 @@ int sqlite3_step(sqlite3_stmt *pStmt){
return SQLITE_MISUSE;
}
}
if( db->xProfile && !db->init.busy ){
double rNow;
sqlite3OsCurrentTime(&rNow);
p->startTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0;
}
#endif
/* Print a copy of SQL as it is executed if the SQL_TRACE pragma is turned
** on in debugging mode.
@@ -215,7 +221,24 @@ int sqlite3_step(sqlite3_stmt *pStmt){
rc = SQLITE_MISUSE;
}
sqlite3Error(p->db, rc, p->zErrMsg);
#ifndef SQLITE_OMIT_TRACE
/* Invoke the profile callback if there is one
*/
if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy ){
double rNow;
u64 elapseTime;
sqlite3OsCurrentTime(&rNow);
elapseTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0 - p->startTime;
assert( p->nOp>0 );
assert( p->aOp[p->nOp-1].opcode==OP_Noop );
assert( p->aOp[p->nOp-1].p3!=0 );
assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );
db->xProfile(db->pProfileArg, p->aOp[p->nOp-1].p3, elapseTime);
}
#endif
sqlite3Error(p->db, rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
return rc;
}
@@ -232,22 +255,27 @@ void *sqlite3_user_data(sqlite3_context *p){
** Allocate or return the aggregate context for a user function. A new
** context is allocated on the first call. Subsequent calls return the
** same context that was returned on prior calls.
**
** This routine is defined here in vdbe.c because it depends on knowing
** the internals of the sqlite3_context structure which is only defined in
** this source file.
*/
void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){
Mem *pMem = p->pMem;
assert( p && p->pFunc && p->pFunc->xStep );
if( p->pAgg==0 ){
if( nByte<=NBFS ){
p->pAgg = (void*)p->s.z;
memset(p->pAgg, 0, nByte);
if( (pMem->flags & MEM_Agg)==0 ){
if( nByte==0 ){
assert( pMem->flags==MEM_Null );
pMem->z = 0;
}else{
p->pAgg = sqliteMalloc( nByte );
pMem->flags = MEM_Agg;
pMem->xDel = sqlite3FreeX;
*(FuncDef**)&pMem->i = p->pFunc;
if( nByte<=NBFS ){
pMem->z = pMem->zShort;
memset(pMem->z, 0, nByte);
}else{
pMem->z = sqliteMalloc( nByte );
}
}
}
return p->pAgg;
return (void*)pMem->z;
}
/*
@@ -280,8 +308,9 @@ void sqlite3_set_auxdata(
pVdbeFunc = pCtx->pVdbeFunc;
if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
pCtx->pVdbeFunc = pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc);
pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc);
if( !pVdbeFunc ) return;
pCtx->pVdbeFunc = pVdbeFunc;
memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0,
sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux));
pVdbeFunc->nAux = iArg+1;
@@ -306,7 +335,7 @@ void sqlite3_set_auxdata(
*/
int sqlite3_aggregate_count(sqlite3_context *p){
assert( p && p->pFunc && p->pFunc->xStep );
return p->cnt;
return p->pMem->n;
}
/*
@@ -371,6 +400,11 @@ sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
return sqlite3_value_text( columnMem(pStmt,i) );
}
#if 0
sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
return columnMem(pStmt, i);
}
#endif
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
return sqlite3_value_text16( columnMem(pStmt,i) );
@@ -383,8 +417,18 @@ int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
/*
** Convert the N-th element of pStmt->pColName[] into a string using
** xFunc() then return that string. If N is out of range, return 0.
** If useType is 1, then use the second set of N elements (the datatype
** names) instead of the first set.
**
** There are up to 5 names for each column. useType determines which
** name is returned. Here are the names:
**
** 0 The column name as it should be displayed for output
** 1 The datatype name for the column
** 2 The name of the database that the column derives from
** 3 The name of the table that the column derives from
** 4 The name of the table column that the result column derives from
**
** If the result is not a simple column reference (if it is an expression
** or a constant) then useTypes 2, 3, and 4 return NULL.
*/
static const void *columnName(
sqlite3_stmt *pStmt,
@@ -398,9 +442,7 @@ static const void *columnName(
if( p==0 || N>=n || N<0 ){
return 0;
}
if( useType ){
N += n;
}
N += useType*n;
return xFunc(&p->aColName[N]);
}
@@ -412,33 +454,72 @@ static const void *columnName(
const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 0);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 0);
}
#endif
/*
** Return the column declaration type (if applicable) of the 'i'th column
** of the result set of SQL statement pStmt, encoded as UTF-8.
** of the result set of SQL statement pStmt.
*/
const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 1);
}
#ifndef SQLITE_OMIT_UTF16
/*
** Return the name of the 'i'th column of the result set of SQL statement
** pStmt, encoded as UTF-16.
*/
const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 0);
}
/*
** Return the column declaration type (if applicable) of the 'i'th column
** of the result set of SQL statement pStmt, encoded as UTF-16.
*/
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 1);
}
#endif /* SQLITE_OMIT_UTF16 */
#if !defined(SQLITE_OMIT_ORIGIN_NAMES) && 0
/*
** Return the name of the database from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 2);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 2);
}
#endif /* SQLITE_OMIT_UTF16 */
/*
** Return the name of the table from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 3);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 3);
}
#endif /* SQLITE_OMIT_UTF16 */
/*
** Return the name of the table column from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 4);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 4);
}
#endif /* SQLITE_OMIT_UTF16 */
#endif /* SQLITE_OMIT_ORIGIN_NAMES */
/******************************* sqlite3_bind_ ***************************
**
** Routines used to attach values to wildcards in a compiled SQL statement.
@@ -454,7 +535,7 @@ const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
static int vdbeUnbind(Vdbe *p, int i){
Mem *pVar;
if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
sqlite3Error(p->db, SQLITE_MISUSE, 0);
if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
return SQLITE_MISUSE;
}
if( i<1 || i>p->nVar ){
@@ -622,3 +703,35 @@ int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
}
return 0;
}
/*
** Transfer all bindings from the first statement over to the second.
** If the two statements contain a different number of bindings, then
** an SQLITE_ERROR is returned.
*/
int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
Vdbe *pFrom = (Vdbe*)pFromStmt;
Vdbe *pTo = (Vdbe*)pToStmt;
int i, rc = SQLITE_OK;
if( (pFrom->magic!=VDBE_MAGIC_RUN && pFrom->magic!=VDBE_MAGIC_HALT)
|| (pTo->magic!=VDBE_MAGIC_RUN && pTo->magic!=VDBE_MAGIC_HALT) ){
return SQLITE_MISUSE;
}
if( pFrom->nVar!=pTo->nVar ){
return SQLITE_ERROR;
}
for(i=0; rc==SQLITE_OK && i<pFrom->nVar; i++){
rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);
}
return rc;
}
/*
** Return the sqlite3* database handle to which the prepared statement given
** in the argument belongs. This is the same database handle that was
** the first argument to the sqlite3_prepare() that was used to create
** the statement in the first place.
*/
sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){
return pStmt ? ((Vdbe*)pStmt)->db : 0;
}
+292 -322
View File
@@ -25,7 +25,7 @@
** set the sqlite3_vdbe_addop_trace to 1 and all opcodes will be printed
** as they are added to the instruction stream.
*/
#ifndef NDEBUG
#ifdef SQLITE_DEBUG
int sqlite3_vdbe_addop_trace = 0;
#endif
@@ -57,15 +57,23 @@ void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
/*
** Resize the Vdbe.aOp array so that it contains at least N
** elements. If the Vdbe is in VDBE_MAGIC_RUN state, then
** the Vdbe.aOp array will be sized to contain exactly N
** elements.
*/
static void resizeOpArray(Vdbe *p, int N){
if( p->nOpAlloc<N ){
int runMode = p->magic==VDBE_MAGIC_RUN;
if( runMode || p->nOpAlloc<N ){
VdbeOp *pNew;
int nNew = N + 100*(!runMode);
int oldSize = p->nOpAlloc;
p->nOpAlloc = N+100;
p->aOp = sqliteRealloc(p->aOp, p->nOpAlloc*sizeof(Op));
if( p->aOp ){
memset(&p->aOp[oldSize], 0, (p->nOpAlloc-oldSize)*sizeof(Op));
pNew = sqliteRealloc(p->aOp, nNew*sizeof(Op));
if( pNew ){
p->nOpAlloc = nNew;
p->aOp = pNew;
if( nNew>oldSize ){
memset(&p->aOp[oldSize], 0, (nNew-oldSize)*sizeof(Op));
}
}
}
}
@@ -94,7 +102,7 @@ int sqlite3VdbeAddOp(Vdbe *p, int op, int p1, int p2){
p->nOp++;
assert( p->magic==VDBE_MAGIC_INIT );
resizeOpArray(p, i+1);
if( p->aOp==0 ){
if( sqlite3_malloc_failed ){
return 0;
}
pOp = &p->aOp[i];
@@ -103,6 +111,7 @@ int sqlite3VdbeAddOp(Vdbe *p, int op, int p1, int p2){
pOp->p2 = p2;
pOp->p3 = 0;
pOp->p3type = P3_NOTUSED;
p->expired = 0;
#ifdef SQLITE_DEBUG
if( sqlite3_vdbe_addop_trace ) sqlite3VdbePrintOp(0, i, &p->aOp[i]);
#endif
@@ -138,7 +147,8 @@ int sqlite3VdbeMakeLabel(Vdbe *p){
assert( p->magic==VDBE_MAGIC_INIT );
if( i>=p->nLabelAlloc ){
p->nLabelAlloc = p->nLabelAlloc*2 + 10;
p->aLabel = sqliteRealloc( p->aLabel, p->nLabelAlloc*sizeof(p->aLabel[0]));
sqlite3ReallocOrFree((void**)&p->aLabel,
p->nLabelAlloc*sizeof(p->aLabel[0]));
}
if( p->aLabel ){
p->aLabel[i] = -1;
@@ -160,25 +170,118 @@ void sqlite3VdbeResolveLabel(Vdbe *p, int x){
}
}
/*
** Return non-zero if opcode 'op' is guarenteed not to push more values
** onto the VDBE stack than it pops off.
*/
static int opcodeNoPush(u8 op){
/* The 10 NOPUSH_MASK_n constants are defined in the automatically
** generated header file opcodes.h. Each is a 16-bit bitmask, one
** bit corresponding to each opcode implemented by the virtual
** machine in vdbe.c. The bit is true if the word "no-push" appears
** in a comment on the same line as the "case OP_XXX:" in
** sqlite3VdbeExec() in vdbe.c.
**
** If the bit is true, then the corresponding opcode is guarenteed not
** to grow the stack when it is executed. Otherwise, it may grow the
** stack by at most one entry.
**
** NOPUSH_MASK_0 corresponds to opcodes 0 to 15. NOPUSH_MASK_1 contains
** one bit for opcodes 16 to 31, and so on.
**
** 16-bit bitmasks (rather than 32-bit) are specified in opcodes.h
** because the file is generated by an awk program. Awk manipulates
** all numbers as floating-point and we don't want to risk a rounding
** error if someone builds with an awk that uses (for example) 32-bit
** IEEE floats.
*/
static const u32 masks[5] = {
NOPUSH_MASK_0 + (NOPUSH_MASK_1<<16),
NOPUSH_MASK_2 + (NOPUSH_MASK_3<<16),
NOPUSH_MASK_4 + (NOPUSH_MASK_5<<16),
NOPUSH_MASK_6 + (NOPUSH_MASK_7<<16),
NOPUSH_MASK_8 + (NOPUSH_MASK_9<<16)
};
return (masks[op>>5] & (1<<(op&0x1F)));
}
#ifndef NDEBUG
int sqlite3VdbeOpcodeNoPush(u8 op){
return opcodeNoPush(op);
}
#endif
/*
** Loop through the program looking for P2 values that are negative.
** Each such value is a label. Resolve the label by setting the P2
** value to its correct non-zero value.
**
** This routine is called once after all opcodes have been inserted.
**
** Variable *pMaxFuncArgs is set to the maximum value of any P2 argument
** to an OP_Function or OP_AggStep opcode. This is used by
** sqlite3VdbeMakeReady() to size the Vdbe.apArg[] array.
**
** The integer *pMaxStack is set to the maximum number of vdbe stack
** entries that static analysis reveals this program might need.
**
** This routine also does the following optimization: It scans for
** Halt instructions where P1==SQLITE_CONSTRAINT or P2==OE_Abort or for
** IdxInsert instructions where P2!=0. If no such instruction is
** found, then every Statement instruction is changed to a Noop. In
** this way, we avoid creating the statement journal file unnecessarily.
*/
static void resolveP2Values(Vdbe *p){
static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs, int *pMaxStack){
int i;
int nMaxArgs = 0;
int nMaxStack = p->nOp;
Op *pOp;
int *aLabel = p->aLabel;
if( aLabel==0 ) return;
int doesStatementRollback = 0;
int hasStatementBegin = 0;
for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
u8 opcode = pOp->opcode;
if( opcode==OP_Function || opcode==OP_AggStep ){
if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
}else if( opcode==OP_Halt ){
if( pOp->p1==SQLITE_CONSTRAINT && pOp->p2==OE_Abort ){
doesStatementRollback = 1;
}
}else if( opcode==OP_IdxInsert ){
if( pOp->p2 ){
doesStatementRollback = 1;
}
}else if( opcode==OP_Statement ){
hasStatementBegin = 1;
}
if( opcodeNoPush(opcode) ){
nMaxStack--;
}
if( pOp->p2>=0 ) continue;
assert( -1-pOp->p2<p->nLabel );
pOp->p2 = aLabel[-1-pOp->p2];
}
sqliteFree(p->aLabel);
p->aLabel = 0;
*pMaxFuncArgs = nMaxArgs;
*pMaxStack = nMaxStack;
/* If we never rollback a statement transaction, then statement
** transactions are not needed. So change every OP_Statement
** opcode into an OP_Noop. This avoid a call to sqlite3OsOpenExclusive()
** which can be expensive on some platforms.
*/
if( hasStatementBegin && !doesStatementRollback ){
for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
if( pOp->opcode==OP_Statement ){
pOp->opcode = OP_Noop;
}
}
}
}
/*
@@ -197,7 +300,7 @@ int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
int addr;
assert( p->magic==VDBE_MAGIC_INIT );
resizeOpArray(p, p->nOp + nOp);
if( p->aOp==0 ){
if( sqlite3_malloc_failed ){
return 0;
}
addr = p->nOp;
@@ -248,6 +351,41 @@ void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
}
}
/*
** Change teh P2 operand of instruction addr so that it points to
** the address of the next instruction to be coded.
*/
void sqlite3VdbeJumpHere(Vdbe *p, int addr){
sqlite3VdbeChangeP2(p, addr, p->nOp);
}
/*
** Delete a P3 value if necessary.
*/
static void freeP3(int p3type, void *p3){
if( p3 ){
switch( p3type ){
case P3_DYNAMIC:
case P3_KEYINFO:
case P3_KEYINFO_HANDOFF: {
sqliteFree(p3);
break;
}
case P3_VDBEFUNC: {
VdbeFunc *pVdbeFunc = (VdbeFunc *)p3;
sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
sqliteFree(pVdbeFunc);
break;
}
case P3_MEM: {
sqlite3ValueFree((sqlite3_value*)p3);
break;
}
}
}
}
/*
** Change the value of the P3 operand for a specific instruction.
** This routine is useful when a large program is loaded from a
@@ -259,34 +397,45 @@ void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
** A value of n==0 means copy bytes of zP3 up to and including the
** first null byte. If n>0 then copy n+1 bytes of zP3.
**
** If n==P3_STATIC it means that zP3 is a pointer to a constant static
** string and we can just copy the pointer. n==P3_POINTER means zP3 is
** a pointer to some object other than a string. n==P3_COLLSEQ and
** n==P3_KEYINFO mean that zP3 is a pointer to a CollSeq or KeyInfo
** structure. A copy is made of KeyInfo structures into memory obtained
** from sqliteMalloc.
** If n==P3_KEYINFO it means that zP3 is a pointer to a KeyInfo structure.
** A copy is made of the KeyInfo structure into memory obtained from
** sqliteMalloc, to be freed when the Vdbe is finalized.
** n==P3_KEYINFO_HANDOFF indicates that zP3 points to a KeyInfo structure
** stored in memory that the caller has obtained from sqliteMalloc. The
** caller should not free the allocation, it will be freed when the Vdbe is
** finalized.
**
** Other values of n (P3_STATIC, P3_COLLSEQ etc.) indicate that zP3 points
** to a string or structure that is guaranteed to exist for the lifetime of
** the Vdbe. In these cases we can just copy the pointer.
**
** If addr<0 then change P3 on the most recently inserted instruction.
*/
void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
Op *pOp;
assert( p->magic==VDBE_MAGIC_INIT );
if( p==0 || p->aOp==0 ) return;
if( p==0 || p->aOp==0 ){
freeP3(n, (void*)*(char**)&zP3);
return;
}
if( addr<0 || addr>=p->nOp ){
addr = p->nOp - 1;
if( addr<0 ) return;
}
pOp = &p->aOp[addr];
if( pOp->p3 && pOp->p3type==P3_DYNAMIC ){
sqliteFree(pOp->p3);
pOp->p3 = 0;
}
freeP3(pOp->p3type, pOp->p3);
pOp->p3 = 0;
if( zP3==0 ){
pOp->p3 = 0;
pOp->p3type = P3_NOTUSED;
}else if( n==P3_KEYINFO ){
KeyInfo *pKeyInfo;
int nField, nByte;
/* KeyInfo structures that include an KeyInfo.aSortOrder are always
** sent in using P3_KEYINFO_HANDOFF. The KeyInfo.aSortOrder array
** is not duplicated when P3_KEYINFO is used. */
/* assert( pKeyInfo->aSortOrder==0 ); */
nField = ((KeyInfo*)zP3)->nField;
nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]);
pKeyInfo = sqliteMallocRaw( nByte );
@@ -325,47 +474,6 @@ void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
}
#endif
/*
** If the P3 operand to the specified instruction appears
** to be a quoted string token, then this procedure removes
** the quotes.
**
** The quoting operator can be either a grave ascent (ASCII 0x27)
** or a double quote character (ASCII 0x22). Two quotes in a row
** resolve to be a single actual quote character within the string.
*/
void sqlite3VdbeDequoteP3(Vdbe *p, int addr){
Op *pOp;
assert( p->magic==VDBE_MAGIC_INIT );
if( p->aOp==0 ) return;
if( addr<0 || addr>=p->nOp ){
addr = p->nOp - 1;
if( addr<0 ) return;
}
pOp = &p->aOp[addr];
if( pOp->p3==0 || pOp->p3[0]==0 ) return;
if( pOp->p3type==P3_STATIC ){
pOp->p3 = sqliteStrDup(pOp->p3);
pOp->p3type = P3_DYNAMIC;
}
assert( pOp->p3type==P3_DYNAMIC );
sqlite3Dequote(pOp->p3);
}
/*
** Search the current program starting at instruction addr for the given
** opcode and P2 value. Return the address plus 1 if found and 0 if not
** found.
*/
int sqlite3VdbeFindOp(Vdbe *p, int addr, int op, int p2){
int i;
assert( p->magic==VDBE_MAGIC_INIT );
for(i=addr; i<p->nOp; i++){
if( p->aOp[i].opcode==op && p->aOp[i].p2==p2 ) return i+1;
}
return 0;
}
/*
** Return the opcode for a given address.
*/
@@ -385,11 +493,6 @@ static char *displayP3(Op *pOp, char *zTemp, int nTemp){
char *zP3;
assert( nTemp>=20 );
switch( pOp->p3type ){
case P3_POINTER: {
sprintf(zTemp, "ptr(%#x)", (int)pOp->p3);
zP3 = zTemp;
break;
}
case P3_KEYINFO: {
int i, j;
KeyInfo *pKeyInfo = (KeyInfo*)pOp->p3;
@@ -505,8 +608,9 @@ int sqlite3VdbeList(
}
p->resOnStack = 0;
i = p->pc++;
do{
i = p->pc++;
}while( i<p->nOp && p->explain==2 && p->aOp[i].opcode!=OP_Explain );
if( i>=p->nOp ){
p->rc = SQLITE_OK;
rc = SQLITE_DONE;
@@ -545,7 +649,7 @@ int sqlite3VdbeList(
pMem->type = SQLITE_TEXT;
pMem->enc = SQLITE_UTF8;
p->nResColumn = 5;
p->nResColumn = 5 - 2*(p->explain-1);
p->pTos = pMem;
p->rc = SQLITE_OK;
p->resOnStack = 1;
@@ -586,7 +690,6 @@ void sqlite3VdbeMakeReady(
int nVar, /* Number of '?' see in the SQL statement */
int nMem, /* Number of memory cells to allocate */
int nCursor, /* Number of cursors to allocate */
int nAgg, /* Number of aggregate contexts required */
int isExplain /* True if the EXPLAIN keywords is present */
){
int n;
@@ -598,46 +701,53 @@ void sqlite3VdbeMakeReady(
*/
assert( p->nOp>0 );
/* Set the magic to VDBE_MAGIC_RUN sooner rather than later. This
* is because the call to resizeOpArray() below may shrink the
* p->aOp[] array to save memory if called when in VDBE_MAGIC_RUN
* state.
*/
p->magic = VDBE_MAGIC_RUN;
/* No instruction ever pushes more than a single element onto the
** stack. And the stack never grows on successive executions of the
** same loop. So the total number of instructions is an upper bound
** on the maximum stack depth required.
** on the maximum stack depth required. (Added later:) The
** resolveP2Values() call computes a tighter upper bound on the
** stack size.
**
** Allocation all the stack space we will ever need.
*/
if( p->aStack==0 ){
resolveP2Values(p);
int nArg; /* Maximum number of args passed to a user function. */
int nStack; /* Maximum number of stack entries required */
resolveP2Values(p, &nArg, &nStack);
resizeOpArray(p, p->nOp);
assert( nVar>=0 );
n = isExplain ? 10 : p->nOp;
assert( nStack<p->nOp );
nStack = isExplain ? 10 : nStack;
p->aStack = sqliteMalloc(
n*sizeof(p->aStack[0]) /* aStack */
+ n*sizeof(Mem*) /* apArg */
nStack*sizeof(p->aStack[0]) /* aStack */
+ nArg*sizeof(Mem*) /* apArg */
+ nVar*sizeof(Mem) /* aVar */
+ nVar*sizeof(char*) /* azVar */
+ nMem*sizeof(Mem) /* aMem */
+ nCursor*sizeof(Cursor*) /* apCsr */
+ nAgg*sizeof(Agg) /* Aggregate contexts */
);
if( !sqlite3_malloc_failed ){
p->aMem = &p->aStack[n];
p->aMem = &p->aStack[nStack];
p->nMem = nMem;
p->aVar = &p->aMem[nMem];
p->nVar = nVar;
p->okVar = 0;
p->apArg = (Mem**)&p->aVar[nVar];
p->azVar = (char**)&p->apArg[n];
p->azVar = (char**)&p->apArg[nArg];
p->apCsr = (Cursor**)&p->azVar[nVar];
if( nAgg>0 ){
p->nAgg = nAgg;
p->apAgg = (Agg*)&p->apCsr[nCursor];
}
p->nCursor = nCursor;
for(n=0; n<nVar; n++){
p->aVar[n].flags = MEM_Null;
}
}
}
p->pAgg = p->apAgg;
for(n=0; n<p->nMem; n++){
p->aMem[n].flags = MEM_Null;
}
@@ -678,166 +788,6 @@ void sqlite3VdbeMakeReady(
#endif
}
/*
** Remove any elements that remain on the sorter for the VDBE given.
*/
void sqlite3VdbeSorterReset(Vdbe *p){
while( p->pSort ){
Sorter *pSorter = p->pSort;
p->pSort = pSorter->pNext;
sqliteFree(pSorter->zKey);
sqlite3VdbeMemRelease(&pSorter->data);
sqliteFree(pSorter);
}
}
/*
** Free all resources allociated with AggElem pElem, an element of
** aggregate pAgg.
*/
static void freeAggElem(AggElem *pElem, Agg *pAgg){
int i;
for(i=0; i<pAgg->nMem; i++){
Mem *pMem = &pElem->aMem[i];
if( pAgg->apFunc && pAgg->apFunc[i] && (pMem->flags & MEM_AggCtx)!=0 ){
sqlite3_context ctx;
ctx.pFunc = pAgg->apFunc[i];
ctx.s.flags = MEM_Null;
ctx.pAgg = pMem->z;
ctx.cnt = pMem->i;
ctx.isError = 0;
(*ctx.pFunc->xFinalize)(&ctx);
pMem->z = ctx.pAgg;
if( pMem->z!=0 && pMem->z!=pMem->zShort ){
sqliteFree(pMem->z);
}
sqlite3VdbeMemRelease(&ctx.s);
}else{
sqlite3VdbeMemRelease(pMem);
}
}
sqliteFree(pElem);
}
/*
** Reset an Agg structure. Delete all its contents.
**
** For installable aggregate functions, if the step function has been
** called, make sure the finalizer function has also been called. The
** finalizer might need to free memory that was allocated as part of its
** private context. If the finalizer has not been called yet, call it
** now.
**
** If db is NULL, then this is being called from sqliteVdbeReset(). In
** this case clean up all references to the temp-table used for
** aggregates (if it was ever opened).
**
** If db is not NULL, then this is being called from with an OP_AggReset
** opcode. Open the temp-table, if it has not already been opened and
** delete the contents of the table used for aggregate information, ready
** for the next round of aggregate processing.
*/
int sqlite3VdbeAggReset(sqlite3 *db, Agg *pAgg, KeyInfo *pKeyInfo){
int rc = 0;
BtCursor *pCsr;
if( !pAgg ) return SQLITE_OK;
pCsr = pAgg->pCsr;
assert( (pCsr && pAgg->nTab>0) || (!pCsr && pAgg->nTab==0)
|| sqlite3_malloc_failed );
/* If pCsr is not NULL, then the table used for aggregate information
** is open. Loop through it and free the AggElem* structure pointed at
** by each entry. If the finalizer has not been called for an AggElem,
** do that too. Finally, clear the btree table itself.
*/
if( pCsr ){
int res;
assert( pAgg->pBtree );
assert( pAgg->nTab>0 );
rc=sqlite3BtreeFirst(pCsr, &res);
while( res==0 && rc==SQLITE_OK ){
AggElem *pElem;
rc = sqlite3BtreeData(pCsr, 0, sizeof(AggElem*), (char *)&pElem);
if( rc!=SQLITE_OK ){
return rc;
}
assert( pAgg->apFunc!=0 );
freeAggElem(pElem, pAgg);
rc=sqlite3BtreeNext(pCsr, &res);
}
if( rc!=SQLITE_OK ){
return rc;
}
sqlite3BtreeCloseCursor(pCsr);
sqlite3BtreeClearTable(pAgg->pBtree, pAgg->nTab);
}else{
/* The cursor may not be open because the aggregator was never used,
** or it could be that it was used but there was no GROUP BY clause.
*/
if( pAgg->pCurrent ){
freeAggElem(pAgg->pCurrent, pAgg);
}
}
/* If db is not NULL and we have not yet and we have not yet opened
** the temporary btree then do so and create the table to store aggregate
** information.
**
** If db is NULL, then close the temporary btree if it is open.
*/
if( db ){
if( !pAgg->pBtree ){
assert( pAgg->nTab==0 );
#ifndef SQLITE_OMIT_MEMORYDB
rc = sqlite3BtreeFactory(db, ":memory:", 0, TEMP_PAGES, &pAgg->pBtree);
#else
rc = sqlite3BtreeFactory(db, 0, 0, TEMP_PAGES, &pAgg->pBtree);
#endif
if( rc!=SQLITE_OK ) return rc;
sqlite3BtreeBeginTrans(pAgg->pBtree, 1);
rc = sqlite3BtreeCreateTable(pAgg->pBtree, &pAgg->nTab, 0);
if( rc!=SQLITE_OK ) return rc;
}
assert( pAgg->nTab!=0 );
rc = sqlite3BtreeCursor(pAgg->pBtree, pAgg->nTab, 1,
sqlite3VdbeRecordCompare, pKeyInfo, &pAgg->pCsr);
if( rc!=SQLITE_OK ) return rc;
}else{
if( pAgg->pBtree ){
sqlite3BtreeClose(pAgg->pBtree);
pAgg->pBtree = 0;
pAgg->nTab = 0;
}
pAgg->pCsr = 0;
}
if( pAgg->apFunc ){
sqliteFree(pAgg->apFunc);
pAgg->apFunc = 0;
}
pAgg->pCurrent = 0;
pAgg->nMem = 0;
pAgg->searching = 0;
return SQLITE_OK;
}
/*
** Delete a keylist
*/
void sqlite3VdbeKeylistFree(Keylist *p){
while( p ){
Keylist *pNext = p->pNext;
sqliteFree(p);
p = pNext;
}
}
/*
** Close a cursor and release all the resources that cursor happens
** to hold.
@@ -884,20 +834,13 @@ static void Cleanup(Vdbe *p){
}
closeAllCursors(p);
releaseMemArray(p->aMem, p->nMem);
if( p->pList ){
sqlite3VdbeKeylistFree(p->pList);
p->pList = 0;
}
sqlite3VdbeFifoClear(&p->sFifo);
if( p->contextStack ){
for(i=0; i<p->contextStackTop; i++){
sqlite3VdbeKeylistFree(p->contextStack[i].pList);
sqlite3VdbeFifoClear(&p->contextStack[i].sFifo);
}
sqliteFree(p->contextStack);
}
sqlite3VdbeSorterReset(p);
for(i=0; i<p->nAgg; i++){
sqlite3VdbeAggReset(0, &p->apAgg[i], 0);
}
p->contextStack = 0;
p->contextStackDepth = 0;
p->contextStackTop = 0;
@@ -1017,7 +960,9 @@ static int vdbeCommit(sqlite3 *db){
** This requires a master journal file to ensure the transaction is
** committed atomicly.
*/
#ifndef SQLITE_OMIT_DISKIO
else{
int needSync = 0;
char *zMaster = 0; /* File-name for the master journal */
char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
OsFile master;
@@ -1053,6 +998,9 @@ static int vdbeCommit(sqlite3 *db){
if( pBt && sqlite3BtreeIsInTrans(pBt) ){
char const *zFile = sqlite3BtreeGetJournalname(pBt);
if( zFile[0]==0 ) continue; /* Ignore :memory: databases */
if( !needSync && !sqlite3BtreeSyncDisabled(pBt) ){
needSync = 1;
}
rc = sqlite3OsWrite(&master, zFile, strlen(zFile)+1);
if( rc!=SQLITE_OK ){
sqlite3OsClose(&master);
@@ -1069,7 +1017,8 @@ static int vdbeCommit(sqlite3 *db){
*/
zMainFile = sqlite3BtreeGetDirname(db->aDb[0].pBt);
rc = sqlite3OsOpenDirectory(zMainFile, &master);
if( rc!=SQLITE_OK || (rc = sqlite3OsSync(&master))!=SQLITE_OK ){
if( rc!=SQLITE_OK ||
(needSync && (rc=sqlite3OsSync(&master,0))!=SQLITE_OK) ){
sqlite3OsClose(&master);
sqlite3OsDelete(zMaster);
sqliteFree(zMaster);
@@ -1133,6 +1082,7 @@ static int vdbeCommit(sqlite3 *db){
}
}
}
#endif
return rc;
}
@@ -1412,14 +1362,7 @@ void sqlite3VdbeDelete(Vdbe *p){
if( p->aOp ){
for(i=0; i<p->nOp; i++){
Op *pOp = &p->aOp[i];
if( pOp->p3type==P3_DYNAMIC || pOp->p3type==P3_KEYINFO ){
sqliteFree(pOp->p3);
}
if( pOp->p3type==P3_VDBEFUNC ){
VdbeFunc *pVdbeFunc = (VdbeFunc *)pOp->p3;
sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
sqliteFree(pVdbeFunc);
}
freeP3(pOp->p3type, pOp->p3);
}
sqliteFree(p->aOp);
}
@@ -1441,8 +1384,8 @@ int sqlite3VdbeCursorMoveto(Cursor *p){
if( p->deferredMoveto ){
int res, rc;
extern int sqlite3_search_count;
assert( p->intKey );
if( p->intKey ){
assert( p->isTable );
if( p->isTable ){
rc = sqlite3BtreeMoveto(p->pCursor, 0, p->movetoTarget, &res);
}else{
rc = sqlite3BtreeMoveto(p->pCursor,(char*)&p->movetoTarget,
@@ -1450,8 +1393,8 @@ int sqlite3VdbeCursorMoveto(Cursor *p){
}
if( rc ) return rc;
*p->pIncrKey = 0;
p->lastRecno = keyToInt(p->movetoTarget);
p->recnoIsValid = res==0;
p->lastRowid = keyToInt(p->movetoTarget);
p->rowidIsValid = res==0;
if( res<0 ){
rc = sqlite3BtreeNext(p->pCursor, &res);
if( rc ) return rc;
@@ -1512,7 +1455,7 @@ u32 sqlite3VdbeSerialType(Mem *pMem){
}
if( flags&MEM_Int ){
/* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
# define MAX_6BYTE ((((i64)0x00010000)<<32)-1)
# define MAX_6BYTE ((((i64)0x00001000)<<32)-1)
i64 i = pMem->i;
u64 u = i<0 ? -i : i;
if( u<=127 ) return 1;
@@ -1595,61 +1538,81 @@ int sqlite3VdbeSerialGet(
u32 serial_type, /* Serial type to deserialize */
Mem *pMem /* Memory cell to write value into */
){
int len;
if( serial_type==0 ){
/* NULL */
pMem->flags = MEM_Null;
return 0;
}
len = sqlite3VdbeSerialTypeLen(serial_type);
if( serial_type<=7 ){
/* Integer and Real */
if( serial_type<=4 ){
/* 32-bit integer type. This is handled by a special case for
** performance reasons. */
int v = buf[0];
int n;
if( v&0x80 ){
v |= -256;
}
for(n=1; n<len; n++){
v = (v<<8) | buf[n];
}
switch( serial_type ){
case 8: /* Reserved for future use */
case 9: /* Reserved for future use */
case 10: /* Reserved for future use */
case 11: /* Reserved for future use */
case 0: { /* NULL */
pMem->flags = MEM_Null;
break;
}
case 1: { /* 1-byte signed integer */
pMem->i = (signed char)buf[0];
pMem->flags = MEM_Int;
pMem->i = v;
return n;
}else{
u64 v = 0;
int n;
if( buf[0]&0x80 ){
v = -1;
}
for(n=0; n<len; n++){
v = (v<<8) | buf[n];
}
if( serial_type==7 ){
pMem->flags = MEM_Real;
pMem->r = *(double*)&v;
}else{
pMem->flags = MEM_Int;
pMem->i = *(i64*)&v;
}
return 1;
}
}else{
/* String or blob */
assert( serial_type>=12 );
pMem->z = (char *)buf;
pMem->n = len;
pMem->xDel = 0;
if( serial_type&0x01 ){
pMem->flags = MEM_Str | MEM_Ephem;
}else{
pMem->flags = MEM_Blob | MEM_Ephem;
case 2: { /* 2-byte signed integer */
pMem->i = (((signed char)buf[0])<<8) | buf[1];
pMem->flags = MEM_Int;
return 2;
}
case 3: { /* 3-byte signed integer */
pMem->i = (((signed char)buf[0])<<16) | (buf[1]<<8) | buf[2];
pMem->flags = MEM_Int;
return 3;
}
case 4: { /* 4-byte signed integer */
pMem->i = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
pMem->flags = MEM_Int;
return 4;
}
case 5: { /* 6-byte signed integer */
u64 x = (((signed char)buf[0])<<8) | buf[1];
u32 y = (buf[2]<<24) | (buf[3]<<16) | (buf[4]<<8) | buf[5];
x = (x<<32) | y;
pMem->i = *(i64*)&x;
pMem->flags = MEM_Int;
return 6;
}
case 6: /* 8-byte signed integer */
case 7: { /* IEEE floating point */
u64 x;
u32 y;
#ifndef NDEBUG
/* Verify that integers and floating point values use the same
** byte order. The byte order differs on some (broken) architectures.
*/
static const u64 t1 = ((u64)0x3ff00000)<<32;
assert( 1.0==*(double*)&t1 );
#endif
x = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
y = (buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7];
x = (x<<32) | y;
if( serial_type==6 ){
pMem->i = *(i64*)&x;
pMem->flags = MEM_Int;
}else{
pMem->r = *(double*)&x;
pMem->flags = MEM_Real;
}
return 8;
}
default: {
int len = (serial_type-12)/2;
pMem->z = (char *)buf;
pMem->n = len;
pMem->xDel = 0;
if( serial_type&0x01 ){
pMem->flags = MEM_Str | MEM_Ephem;
}else{
pMem->flags = MEM_Blob | MEM_Ephem;
}
return len;
}
}
return len;
return 0;
}
/*
@@ -1703,8 +1666,8 @@ int sqlite3VdbeRecordCompare(
d2 += sqlite3VdbeSerialGet(&aKey2[d2], serial_type2, &mem2);
rc = sqlite3MemCompare(&mem1, &mem2, i<nField ? pKeyInfo->aColl[i] : 0);
sqlite3VdbeMemRelease(&mem1);
sqlite3VdbeMemRelease(&mem2);
if( mem1.flags & MEM_Dyn ) sqlite3VdbeMemRelease(&mem1);
if( mem2.flags & MEM_Dyn ) sqlite3VdbeMemRelease(&mem2);
if( rc!=0 ){
break;
}
@@ -1763,7 +1726,7 @@ int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){
sqlite3BtreeKeySize(pCur, &nCellKey);
if( nCellKey<=0 ){
return SQLITE_CORRUPT;
return SQLITE_CORRUPT_BKPT;
}
rc = sqlite3VdbeMemFromBtree(pCur, 0, nCellKey, 1, &m);
if( rc ){
@@ -1847,3 +1810,10 @@ void sqlite3ExpirePreparedStatements(sqlite3 *db){
p->expired = 1;
}
}
/*
** Return the database associated with the Vdbe.
*/
sqlite3 *sqlite3VdbeDb(Vdbe *v){
return v->db;
}
+114
View File
@@ -0,0 +1,114 @@
/*
** 2005 June 16
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file implements a FIFO queue of rowids used for processing
** UPDATE and DELETE statements.
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
/*
** Allocate a new FifoPage and return a pointer to it. Return NULL if
** we run out of memory. Leave space on the page for nEntry entries.
*/
static FifoPage *allocatePage(int nEntry){
FifoPage *pPage;
if( nEntry>32767 ){
nEntry = 32767;
}
pPage = sqliteMallocRaw( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) );
if( pPage ){
pPage->nSlot = nEntry;
pPage->iWrite = 0;
pPage->iRead = 0;
pPage->pNext = 0;
}
return pPage;
}
/*
** Initialize a Fifo structure.
*/
void sqlite3VdbeFifoInit(Fifo *pFifo){
memset(pFifo, 0, sizeof(*pFifo));
}
/*
** Push a single 64-bit integer value into the Fifo. Return SQLITE_OK
** normally. SQLITE_NOMEM is returned if we are unable to allocate
** memory.
*/
int sqlite3VdbeFifoPush(Fifo *pFifo, i64 val){
FifoPage *pPage;
pPage = pFifo->pLast;
if( pPage==0 ){
pPage = pFifo->pLast = pFifo->pFirst = allocatePage(20);
if( pPage==0 ){
return SQLITE_NOMEM;
}
}else if( pPage->iWrite>=pPage->nSlot ){
pPage->pNext = allocatePage(pFifo->nEntry);
if( pPage->pNext==0 ){
return SQLITE_NOMEM;
}
pPage = pFifo->pLast = pPage->pNext;
}
pPage->aSlot[pPage->iWrite++] = val;
pFifo->nEntry++;
return SQLITE_OK;
}
/*
** Extract a single 64-bit integer value from the Fifo. The integer
** extracted is the one least recently inserted. If the Fifo is empty
** return SQLITE_DONE.
*/
int sqlite3VdbeFifoPop(Fifo *pFifo, i64 *pVal){
FifoPage *pPage;
if( pFifo->nEntry==0 ){
return SQLITE_DONE;
}
assert( pFifo->nEntry>0 );
pPage = pFifo->pFirst;
assert( pPage!=0 );
assert( pPage->iWrite>pPage->iRead );
assert( pPage->iWrite<=pPage->nSlot );
assert( pPage->iRead<pPage->nSlot );
assert( pPage->iRead>=0 );
*pVal = pPage->aSlot[pPage->iRead++];
pFifo->nEntry--;
if( pPage->iRead>=pPage->iWrite ){
pFifo->pFirst = pPage->pNext;
sqliteFree(pPage);
if( pFifo->nEntry==0 ){
assert( pFifo->pLast==pPage );
pFifo->pLast = 0;
}else{
assert( pFifo->pFirst!=0 );
}
}else{
assert( pFifo->nEntry>0 );
}
return SQLITE_OK;
}
/*
** Delete all information from a Fifo object. Free all memory held
** by the Fifo.
*/
void sqlite3VdbeFifoClear(Fifo *pFifo){
FifoPage *pPage, *pNextPage;
for(pPage=pFifo->pFirst; pPage; pPage=pNextPage){
pNextPage = pPage->pNext;
sqliteFree(pPage);
}
sqlite3VdbeFifoInit(pFifo);
}
+114 -9
View File
@@ -174,7 +174,7 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){
** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
*/
if( fg & MEM_Real ){
sqlite3_snprintf(NBFS, z, "%.15g", pMem->r);
sqlite3_snprintf(NBFS, z, "%!.15g", pMem->r);
}else{
assert( fg & MEM_Int );
sqlite3_snprintf(NBFS, z, "%lld", pMem->i);
@@ -187,15 +187,45 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){
return rc;
}
/*
** Memory cell pMem contains the context of an aggregate function.
** This routine calls the finalize method for that function. The
** result of the aggregate is stored back into pMem.
*/
void sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
if( pFunc && pFunc->xFinalize ){
sqlite3_context ctx;
assert( (pMem->flags & MEM_Null)!=0 || pFunc==*(FuncDef**)&pMem->i );
ctx.s.flags = MEM_Null;
ctx.s.z = pMem->zShort;
ctx.pMem = pMem;
ctx.pFunc = pFunc;
pFunc->xFinalize(&ctx);
if( pMem->z && pMem->z!=pMem->zShort ){
sqliteFree( pMem->z );
}
*pMem = ctx.s;
if( pMem->flags & MEM_Short ){
pMem->z = pMem->zShort;
}
}
}
/*
** Release any memory held by the Mem. This may leave the Mem in an
** inconsistent state, for example with (Mem.z==0) and
** (Mem.type==SQLITE_TEXT).
*/
void sqlite3VdbeMemRelease(Mem *p){
if( p->flags & MEM_Dyn ){
if( p->flags & (MEM_Dyn|MEM_Agg) ){
if( p->xDel ){
p->xDel((void *)p->z);
if( p->flags & MEM_Agg ){
sqlite3VdbeMemFinalize(p, *(FuncDef**)&p->i);
assert( (p->flags & MEM_Agg)==0 );
sqlite3VdbeMemRelease(p);
}else{
p->xDel((void *)p->z);
}
}else{
sqliteFree(p->z);
}
@@ -256,12 +286,14 @@ double sqlite3VdbeRealValue(Mem *pMem){
}else if( pMem->flags & MEM_Int ){
return (double)pMem->i;
}else if( pMem->flags & (MEM_Str|MEM_Blob) ){
double val = 0.0;
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|| sqlite3VdbeMemNulTerminate(pMem) ){
return SQLITE_NOMEM;
}
assert( pMem->z );
return sqlite3AtoF(pMem->z, 0);
sqlite3AtoF(pMem->z, &val);
return val;
}else{
return 0.0;
}
@@ -285,6 +317,7 @@ void sqlite3VdbeMemSetNull(Mem *pMem){
sqlite3VdbeMemRelease(pMem);
pMem->flags = MEM_Null;
pMem->type = SQLITE_NULL;
pMem->n = 0;
}
/*
@@ -406,6 +439,7 @@ int sqlite3VdbeMemSetStr(
switch( enc ){
case 0:
pMem->flags |= MEM_Blob;
pMem->enc = SQLITE_UTF8;
break;
case SQLITE_UTF8:
@@ -608,8 +642,13 @@ int sqlite3VdbeMemFromBtree(
zData[amt] = 0;
zData[amt+1] = 0;
if( rc!=SQLITE_OK ){
if( amt>NBFS ){
if( amt>NBFS-2 ){
assert( zData!=pMem->zShort );
assert( pMem->flags & MEM_Dyn );
sqliteFree(zData);
} else {
assert( zData==pMem->zShort );
assert( pMem->flags & MEM_Short );
}
return rc;
}
@@ -661,9 +700,9 @@ void sqlite3VdbeMemSanity(Mem *pMem, u8 db_enc){
/* MEM_Null excludes all other types */
assert( (pMem->flags&(MEM_Str|MEM_Int|MEM_Real|MEM_Blob))==0
|| (pMem->flags&MEM_Null)==0 );
if( (pMem->flags & (MEM_Int|MEM_Real))==(MEM_Int|MEM_Real) ){
assert( pMem->r==pMem->i );
}
/* If the MEM is both real and integer, the values are equal */
assert( (pMem->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real)
|| pMem->r==pMem->i );
}
#endif
@@ -691,7 +730,7 @@ const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
/*
** Create a new sqlite3_value object.
*/
sqlite3_value* sqlite3ValueNew(){
sqlite3_value* sqlite3ValueNew(void){
Mem *p = sqliteMalloc(sizeof(*p));
if( p ){
p->flags = MEM_Null;
@@ -700,6 +739,72 @@ sqlite3_value* sqlite3ValueNew(){
return p;
}
/*
** Create a new sqlite3_value object, containing the value of pExpr.
**
** This only works for very simple expressions that consist of one constant
** token (i.e. "5", "5.1", "NULL", "'a string'"). If the expression can
** be converted directly into a value, then the value is allocated and
** a pointer written to *ppVal. The caller is responsible for deallocating
** the value by passing it to sqlite3ValueFree() later on. If the expression
** cannot be converted to a value, then *ppVal is set to NULL.
*/
int sqlite3ValueFromExpr(
Expr *pExpr,
u8 enc,
u8 affinity,
sqlite3_value **ppVal
){
int op;
char *zVal = 0;
sqlite3_value *pVal = 0;
if( !pExpr ){
*ppVal = 0;
return SQLITE_OK;
}
op = pExpr->op;
if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
zVal = sqliteStrNDup(pExpr->token.z, pExpr->token.n);
pVal = sqlite3ValueNew();
if( !zVal || !pVal ) goto no_mem;
sqlite3Dequote(zVal);
sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, sqlite3FreeX);
if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, enc);
}else{
sqlite3ValueApplyAffinity(pVal, affinity, enc);
}
}else if( op==TK_UMINUS ) {
if( SQLITE_OK==sqlite3ValueFromExpr(pExpr->pLeft, enc, affinity, &pVal) ){
pVal->i = -1 * pVal->i;
pVal->r = -1.0 * pVal->r;
}
}
#ifndef SQLITE_OMIT_BLOB_LITERAL
else if( op==TK_BLOB ){
int nVal;
pVal = sqlite3ValueNew();
zVal = sqliteStrNDup(pExpr->token.z+1, pExpr->token.n-1);
if( !zVal || !pVal ) goto no_mem;
sqlite3Dequote(zVal);
nVal = strlen(zVal)/2;
sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(zVal), nVal, 0, sqlite3FreeX);
sqliteFree(zVal);
}
#endif
*ppVal = pVal;
return SQLITE_OK;
no_mem:
sqliteFree(zVal);
sqlite3ValueFree(pVal);
*ppVal = 0;
return SQLITE_NOMEM;
}
/*
** Change the string value of an sqlite3_value object
*/
+1280 -670
View File
File diff suppressed because it is too large Load Diff
+76 -43
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is testing the ALTER TABLE statement.
#
# $Id: alter.test,v 1.10 2005/02/14 06:38:40 danielk1977 Exp $
# $Id: alter.test,v 1.11 2005/03/29 03:11:00 danielk1977 Exp $
#
set testdir [file dirname $argv0]
@@ -43,7 +43,12 @@ ifcapable !altertable {
# and some tables with odd names.
#
do_test alter-1.1 {
execsql {
ifcapable tempdb {
set ::temp TEMP
} else {
set ::temp {}
}
execsql [subst -nocommands {
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,2);
CREATE TABLE [t1'x1](c UNIQUE, b PRIMARY KEY);
@@ -51,10 +56,10 @@ do_test alter-1.1 {
CREATE INDEX t1i1 ON T1(B);
CREATE INDEX t1i2 ON t1(a,b);
CREATE INDEX i3 ON [t1'x1](b,c);
CREATE TEMP TABLE "temp table"(e,f,g UNIQUE);
CREATE $::temp TABLE "temp table"(e,f,g UNIQUE);
CREATE INDEX i2 ON [temp table](f);
INSERT INTO [temp table] VALUES(5,6,7);
}
}]
execsql {
SELECT 't1', * FROM t1;
SELECT 't1''x1', * FROM "t1'x1";
@@ -62,11 +67,19 @@ do_test alter-1.1 {
}
} {t1 1 2 t1'x1 3 4 5 6 7}
do_test alter-1.2 {
execsql [subst {
CREATE $::temp TABLE objlist(type, name, tbl_name);
INSERT INTO objlist SELECT type, name, tbl_name
FROM sqlite_master WHERE NAME!='objlist';
}]
ifcapable tempdb {
execsql {
INSERT INTO objlist SELECT type, name, tbl_name
FROM sqlite_temp_master WHERE NAME!='objlist';
}
}
execsql {
CREATE TEMP TABLE objlist(type, name, tbl_name);
INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
INSERT INTO objlist
SELECT type, name, tbl_name FROM sqlite_temp_master WHERE NAME!='objlist';
SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name;
}
} [list \
@@ -102,9 +115,14 @@ do_test alter-1.4 {
do_test alter-1.5 {
execsql {
DELETE FROM objlist;
INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
INSERT INTO objlist
SELECT type, name, tbl_name FROM sqlite_temp_master WHERE NAME!='objlist';
INSERT INTO objlist SELECT type, name, tbl_name
FROM sqlite_master WHERE NAME!='objlist';
}
catchsql {
INSERT INTO objlist SELECT type, name, tbl_name
FROM sqlite_temp_master WHERE NAME!='objlist';
}
execsql {
SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name;
}
} [list \
@@ -123,27 +141,33 @@ do_test alter-1.5 {
# Make sure the changes persist after restarting the database.
# (The TEMP table will not persist, of course.)
#
do_test alter-1.6 {
db close
set DB [sqlite3 db test.db]
ifcapable tempdb {
do_test alter-1.6 {
db close
set DB [sqlite3 db test.db]
execsql {
CREATE TEMP TABLE objlist(type, name, tbl_name);
INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
INSERT INTO objlist
SELECT type, name, tbl_name FROM sqlite_temp_master
WHERE NAME!='objlist';
SELECT type, name, tbl_name FROM objlist
ORDER BY tbl_name, type desc, name;
}
} [list \
table -t1- -t1- \
index t1i1 -t1- \
index t1i2 -t1- \
table T2 T2 \
index i3 T2 \
index {sqlite_autoindex_T2_1} T2 \
index {sqlite_autoindex_T2_2} T2 \
]
} else {
execsql {
CREATE TEMP TABLE objlist(type, name, tbl_name);
INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
INSERT INTO objlist
SELECT type, name, tbl_name FROM sqlite_temp_master
WHERE NAME!='objlist';
SELECT type, name, tbl_name FROM objlist
ORDER BY tbl_name, type desc, name;
DROP TABLE TempTab;
}
} [list \
table -t1- -t1- \
index t1i1 -t1- \
index t1i2 -t1- \
table T2 T2 \
index i3 T2 \
index {sqlite_autoindex_T2_1} T2 \
index {sqlite_autoindex_T2_2} T2 \
]
}
# Make sure the ALTER TABLE statements work with the
# non-callback API
@@ -155,12 +179,15 @@ do_test alter-1.7 {
}
execsql {
DELETE FROM objlist;
INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master;
INSERT INTO objlist
SELECT type, name, tbl_name FROM sqlite_temp_master
WHERE NAME!='objlist';
SELECT type, name, tbl_name FROM objlist
ORDER BY tbl_name, type desc, name;
INSERT INTO objlist SELECT type, name, tbl_name
FROM sqlite_master WHERE NAME!='objlist';
}
catchsql {
INSERT INTO objlist SELECT type, name, tbl_name
FROM sqlite_temp_master WHERE NAME!='objlist';
}
execsql {
SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name;
}
} [list \
table *t1* *t1* \
@@ -419,12 +446,12 @@ do_test alter-3.2.10 {
} {}
do_test alter-3.3.1 {
execsql {
execsql [subst {
CREATE TABLE tbl1(a, b, c);
CREATE TEMP TRIGGER trig1 AFTER INSERT ON tbl1 BEGIN
CREATE $::temp TRIGGER trig1 AFTER INSERT ON tbl1 BEGIN
SELECT trigfunc('trig1', new.a, new.b, new.c);
END;
}
}]
} {}
do_test alter-3.3.2 {
execsql {
@@ -440,11 +467,11 @@ do_test alter-3.3.3 {
set ::TRIGGER
} {trig1 d e f}
do_test alter-3.3.4 {
execsql {
CREATE TEMP TRIGGER trig2 AFTER UPDATE ON tbl2 BEGIN
execsql [subst {
CREATE $::temp TRIGGER trig2 AFTER UPDATE ON tbl2 BEGIN
SELECT trigfunc('trig2', new.a, new.b, new.c);
END;
}
}]
} {}
do_test alter-3.3.5 {
execsql {
@@ -462,9 +489,15 @@ do_test alter-3.3.6 {
do_test alter-3.3.7 {
execsql {
DROP TABLE tbl3;
SELECT * FROM sqlite_temp_master WHERE type = 'trigger';
}
} {}
ifcapable tempdb {
do_test alter-3.3.8 {
execsql {
SELECT * FROM sqlite_temp_master WHERE type = 'trigger';
}
} {}
}
} ;# ifcapable trigger
+438
View File
@@ -0,0 +1,438 @@
# 2005 February 18
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is testing that SQLite can handle a subtle
# file format change that may be used in the future to implement
# "ALTER TABLE ... ADD COLUMN".
#
# $Id: alter2.test,v 1.4 2005/03/10 12:52:47 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# We have to have pragmas in order to do this test
ifcapable {!pragma} return
# These tests do not work if there is a codec. The
# btree_open command does not know how to handle codecs.
#
if {[catch {sqlite3 -has_codec} r] || $r} return
# The file format change affects the way row-records stored in tables (but
# not indices) are interpreted. Before version 3.1.3, a row-record for a
# table with N columns was guaranteed to contain exactly N fields. As
# of version 3.1.3, the record may contain up to N fields. In this case
# the M fields that are present are the values for the left-most M
# columns. The (N-M) rightmost columns contain NULL.
#
# If any records in the database contain less fields than their table
# has columns, then the file-format meta value should be set to (at least) 2.
#
# This procedure sets the value of the file-format in file 'test.db'
# to $newval. Also, the schema cookie is incremented.
#
proc set_file_format {newval} {
set bt [btree_open test.db 10 0]
btree_begin_transaction $bt
set meta [btree_get_meta $bt]
lset meta 2 $newval ;# File format
lset meta 1 [expr [lindex $meta 1]+1] ;# Schema cookie
eval "btree_update_meta $bt $meta"
btree_commit $bt
btree_close $bt
}
# This procedure returns the value of the file-format in file 'test.db'.
#
proc get_file_format {{fname test.db}} {
set bt [btree_open $fname 10 0]
set meta [btree_get_meta $bt]
btree_close $bt
lindex $meta 2
}
# This procedure sets the SQL statement stored for table $tbl in the
# sqlite_master table of file 'test.db' to $sql. Also set the file format
# to the supplied value. This is 2 if the added column has a default that is
# NULL, or 3 otherwise.
#
proc alter_table {tbl sql {file_format 2}} {
sqlite3 dbat test.db
puts one
dbat eval {
PRAGMA writable_schema = 1;
UPDATE sqlite_master SET sql = $sql WHERE name = $tbl AND type = 'table';
PRAGMA writable_schema = 0;
}
puts two
dbat close
puts three
set_file_format 2
puts four
}
#-----------------------------------------------------------------------
# Some basic tests to make sure short rows are handled.
#
do_test alter2-1.1 {
execsql {
CREATE TABLE abc(a, b);
INSERT INTO abc VALUES(1, 2);
INSERT INTO abc VALUES(3, 4);
INSERT INTO abc VALUES(5, 6);
}
} {}
do_test alter2-1.2 {
# ALTER TABLE abc ADD COLUMN c;
alter_table abc {CREATE TABLE abc(a, b, c);}
} {}
exit
do_test alter2-1.3 {
execsql {
SELECT * FROM abc;
}
} {1 2 {} 3 4 {} 5 6 {}}
do_test alter2-1.4 {
execsql {
UPDATE abc SET c = 10 WHERE a = 1;
SELECT * FROM abc;
}
} {1 2 10 3 4 {} 5 6 {}}
do_test alter2-1.5 {
execsql {
CREATE INDEX abc_i ON abc(c);
}
} {}
do_test alter2-1.6 {
execsql {
SELECT c FROM abc ORDER BY c;
}
} {{} {} 10}
do_test alter2-1.7 {
execsql {
SELECT * FROM abc WHERE c = 10;
}
} {1 2 10}
do_test alter2-1.8 {
execsql {
SELECT sum(a), c FROM abc GROUP BY c;
}
} {8.0 {} 1.0 10}
do_test alter2-1.9 {
# ALTER TABLE abc ADD COLUMN d;
alter_table abc {CREATE TABLE abc(a, b, c, d);}
execsql { SELECT * FROM abc; }
execsql {
UPDATE abc SET d = 11 WHERE c IS NULL AND a<4;
SELECT * FROM abc;
}
} {1 2 10 {} 3 4 {} 11 5 6 {} {}}
do_test alter2-1.10 {
execsql {
SELECT typeof(d) FROM abc;
}
} {null integer null}
do_test alter2-1.99 {
execsql {
DROP TABLE abc;
}
} {}
#-----------------------------------------------------------------------
# Test that views work when the underlying table structure is changed.
#
ifcapable view {
do_test alter2-2.1 {
execsql {
CREATE TABLE abc2(a, b, c);
INSERT INTO abc2 VALUES(1, 2, 10);
INSERT INTO abc2 VALUES(3, 4, NULL);
INSERT INTO abc2 VALUES(5, 6, NULL);
CREATE VIEW abc2_v AS SELECT * FROM abc2;
SELECT * FROM abc2_v;
}
} {1 2 10 3 4 {} 5 6 {}}
do_test alter2-2.2 {
# ALTER TABLE abc ADD COLUMN d;
alter_table abc2 {CREATE TABLE abc2(a, b, c, d);}
execsql {
SELECT * FROM abc2_v;
}
} {1 2 10 {} 3 4 {} {} 5 6 {} {}}
do_test alter2-2.3 {
execsql {
DROP TABLE abc2;
DROP VIEW abc2_v;
}
} {}
}
#-----------------------------------------------------------------------
# Test that triggers work when a short row is copied to the old.*
# trigger pseudo-table.
#
ifcapable trigger {
do_test alter2-3.1 {
execsql {
CREATE TABLE abc3(a, b);
CREATE TABLE blog(o, n);
CREATE TRIGGER abc3_t AFTER UPDATE OF b ON abc3 BEGIN
INSERT INTO blog VALUES(old.b, new.b);
END;
}
} {}
do_test alter2-3.2 {
execsql {
INSERT INTO abc3 VALUES(1, 4);
UPDATE abc3 SET b = 2 WHERE b = 4;
SELECT * FROM blog;
}
} {4 2}
do_test alter2-3.3 {
execsql {
INSERT INTO abc3 VALUES(3, 4);
INSERT INTO abc3 VALUES(5, 6);
}
alter_table abc3 {CREATE TABLE abc3(a, b, c);}
execsql {
SELECT * FROM abc3;
}
} {1 2 {} 3 4 {} 5 6 {}}
do_test alter2-3.4 {
execsql {
UPDATE abc3 SET b = b*2 WHERE a<4;
SELECT * FROM abc3;
}
} {1 4 {} 3 8 {} 5 6 {}}
do_test alter2-3.5 {
execsql {
SELECT * FROM blog;
}
} {4 2 2 4 4 8}
do_test alter2-3.6 {
execsql {
CREATE TABLE clog(o, n);
CREATE TRIGGER abc3_t2 AFTER UPDATE OF c ON abc3 BEGIN
INSERT INTO clog VALUES(old.c, new.c);
END;
UPDATE abc3 SET c = a*2;
SELECT * FROM clog;
}
} {{} 2 {} 6 {} 10}
}
#---------------------------------------------------------------------
# Check that an error occurs if the database is upgraded to a file
# format that SQLite does not support (in this case 4). Note: The
# file format is checked each time the schema is read, so changing the
# file format requires incrementing the schema cookie.
#
do_test alter2-4.1 {
set_file_format 4
} {}
do_test alter2-4.2 {
catchsql {
SELECT * FROM sqlite_master;
}
} {1 {unsupported file format}}
do_test alter2-4.3 {
sqlite3_errcode $::DB
} {SQLITE_ERROR}
do_test alter2-4.4 {
db close
set ::DB [sqlite3 db test.db]
catchsql {
SELECT * FROM sqlite_master;
}
} {1 {unsupported file format}}
do_test alter2-4.5 {
sqlite3_errcode $::DB
} {SQLITE_ERROR}
#---------------------------------------------------------------------
# Check that executing VACUUM on a file with file-format version 2
# resets the file format to 1.
#
do_test alter2-5.1 {
set_file_format 2
get_file_format
} {2}
do_test alter2-5.2 {
execsql {
VACUUM;
}
} {}
do_test alter2-5.3 {
get_file_format
} {1}
#---------------------------------------------------------------------
# Test that when a database with file-format 2 is opened, new
# databases are still created with file-format 1.
#
do_test alter2-6.1 {
db close
set_file_format 2
set ::DB [sqlite3 db test.db]
get_file_format
} {2}
do_test alter2-6.2 {
file delete -force test2.db-journal
file delete -force test2.db
execsql {
ATTACH 'test2.db' AS aux;
CREATE TABLE aux.t1(a, b);
}
get_file_format test2.db
} {1}
do_test alter2-6.3 {
execsql {
CREATE TABLE t1(a, b);
}
get_file_format
} {2}
#---------------------------------------------------------------------
# Test that types and values for columns added with default values
# other than NULL work with SELECT statements.
#
do_test alter2-7.1 {
execsql {
DROP TABLE t1;
CREATE TABLE t1(a);
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES(2);
INSERT INTO t1 VALUES(3);
INSERT INTO t1 VALUES(4);
SELECT * FROM t1;
}
} {1 2 3 4}
do_test alter2-7.2 {
set sql {CREATE TABLE t1(a, b DEFAULT '123', c INTEGER DEFAULT '123')}
alter_table t1 $sql 3
execsql {
SELECT * FROM t1 LIMIT 1;
}
} {1 123 123}
do_test alter2-7.3 {
execsql {
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
}
} {1 integer 123 text 123 integer}
do_test alter2-7.4 {
execsql {
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
}
} {1 integer 123 text 123 integer}
do_test alter2-7.5 {
set sql {CREATE TABLE t1(a, b DEFAULT -123.0, c VARCHAR(10) default 5)}
alter_table t1 $sql 3
execsql {
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
}
} {1 integer -123.0 real 5 text}
#-----------------------------------------------------------------------
# Test that UPDATE trigger tables work with default values, and that when
# a row is updated the default values are correctly transfered to the
# new row.
#
ifcapable trigger {
db function set_val {set ::val}
do_test alter2-8.1 {
execsql {
CREATE TRIGGER trig1 BEFORE UPDATE ON t1 BEGIN
SELECT set_val(
old.b||' '||typeof(old.b)||' '||old.c||' '||typeof(old.c)||' '||
new.b||' '||typeof(new.b)||' '||new.c||' '||typeof(new.c)
);
END;
}
list
} {}
}
do_test alter2-8.2 {
execsql {
UPDATE t1 SET c = 10 WHERE a = 1;
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
}
} {1 integer -123.0 real 10 text}
ifcapable trigger {
do_test alter2-8.3 {
set ::val
} {-123 real 5 text -123 real 10 text}
}
#-----------------------------------------------------------------------
# Test that DELETE trigger tables work with default values, and that when
# a row is updated the default values are correctly transfered to the
# new row.
#
ifcapable trigger {
do_test alter2-9.1 {
execsql {
CREATE TRIGGER trig2 BEFORE DELETE ON t1 BEGIN
SELECT set_val(
old.b||' '||typeof(old.b)||' '||old.c||' '||typeof(old.c)
);
END;
}
list
} {}
do_test alter2-9.2 {
execsql {
DELETE FROM t1 WHERE a = 2;
}
set ::val
} {-123 real 5 text}
}
#-----------------------------------------------------------------------
# Test creating an index on a column added with a default value.
#
do_test alter2-10.1 {
execsql {
CREATE TABLE t2(a);
INSERT INTO t2 VALUES('a');
INSERT INTO t2 VALUES('b');
INSERT INTO t2 VALUES('c');
INSERT INTO t2 VALUES('d');
}
alter_table t2 {CREATE TABLE t2(a, b DEFAULT X'ABCD', c DEFAULT NULL);} 3
catchsql {
SELECT * FROM sqlite_master;
}
execsql {
SELECT quote(a), quote(b), quote(c) FROM t2 LIMIT 1;
}
} {'a' X'ABCD' NULL}
do_test alter2-10.2 {
execsql {
CREATE INDEX i1 ON t2(b);
SELECT a FROM t2 WHERE b = X'ABCD';
}
} {a b c d}
do_test alter2-10.3 {
execsql {
DELETE FROM t2 WHERE a = 'c';
SELECT a FROM t2 WHERE b = X'ABCD';
}
} {a b d}
do_test alter2-10.4 {
execsql {
SELECT count(b) FROM t2 WHERE b = X'ABCD';
}
} {3}
finish_test
+380
View File
@@ -0,0 +1,380 @@
# 2005 February 19
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is testing that SQLite can handle a subtle
# file format change that may be used in the future to implement
# "ALTER TABLE ... ADD COLUMN".
#
# $Id: alter3.test,v 1.6 2005/03/29 03:11:00 danielk1977 Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
ifcapable !altertable {
finish_test
return
}
# Determine if there is a codec available on this test.
#
if {[catch {sqlite3 -has_codec} r] || $r} {
set has_codec 1
} else {
set has_codec 0
}
# Test Organisation:
# ------------------
#
# alter3-1.*: Test that ALTER TABLE correctly modifies the CREATE TABLE sql.
# alter3-2.*: Test error messages.
# alter3-3.*: Test adding columns with default value NULL.
# alter3-4.*: Test adding columns with default values other than NULL.
# alter3-5.*: Test adding columns to tables in ATTACHed databases.
# alter3-6.*: Test that temp triggers are not accidentally dropped.
# alter3-7.*: Test that VACUUM resets the file-format.
#
# This procedure returns the value of the file-format in file 'test.db'.
#
proc get_file_format {{fname test.db}} {
set bt [btree_open $fname 10 0]
set meta [btree_get_meta $bt]
btree_close $bt
lindex $meta 2
}
do_test alter3-1.1 {
execsql {
CREATE TABLE abc(a, b, c);
SELECT sql FROM sqlite_master;
}
} {{CREATE TABLE abc(a, b, c)}}
do_test alter3-1.2 {
execsql {ALTER TABLE abc ADD d INTEGER;}
execsql {
SELECT sql FROM sqlite_master;
}
} {{CREATE TABLE abc(a, b, c, d INTEGER)}}
do_test alter3-1.3 {
execsql {ALTER TABLE abc ADD e}
execsql {
SELECT sql FROM sqlite_master;
}
} {{CREATE TABLE abc(a, b, c, d INTEGER, e)}}
do_test alter3-1.4 {
execsql {
CREATE TABLE main.t1(a, b);
ALTER TABLE t1 ADD c;
SELECT sql FROM sqlite_master WHERE tbl_name = 't1';
}
} {{CREATE TABLE t1(a, b, c)}}
do_test alter3-1.5 {
execsql {
ALTER TABLE t1 ADD d CHECK (a>d);
SELECT sql FROM sqlite_master WHERE tbl_name = 't1';
}
} {{CREATE TABLE t1(a, b, c, d CHECK (a>d))}}
do_test alter3-1.6 {
execsql {
CREATE TABLE t2(a, b, UNIQUE(a, b));
ALTER TABLE t2 ADD c REFERENCES t1(c) ;
SELECT sql FROM sqlite_master WHERE tbl_name = 't2' AND type = 'table';
}
} {{CREATE TABLE t2(a, b, c REFERENCES t1(c), UNIQUE(a, b))}}
do_test alter3-1.7 {
execsql {
CREATE TABLE t3(a, b, UNIQUE(a, b));
ALTER TABLE t3 ADD COLUMN c VARCHAR(10, 20);
SELECT sql FROM sqlite_master WHERE tbl_name = 't3' AND type = 'table';
}
} {{CREATE TABLE t3(a, b, c VARCHAR(10, 20), UNIQUE(a, b))}}
do_test alter3-1.99 {
execsql {
DROP TABLE abc;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
}
} {}
do_test alter3-2.1 {
execsql {
CREATE TABLE t1(a, b);
}
catchsql {
ALTER TABLE t1 ADD c PRIMARY KEY;
}
} {1 {Cannot add a PRIMARY KEY column}}
do_test alter3-2.2 {
catchsql {
ALTER TABLE t1 ADD c UNIQUE
}
} {1 {Cannot add a UNIQUE column}}
do_test alter3-2.3 {
catchsql {
ALTER TABLE t1 ADD b VARCHAR(10)
}
} {1 {duplicate column name: b}}
do_test alter3-2.3 {
catchsql {
ALTER TABLE t1 ADD c NOT NULL;
}
} {1 {Cannot add a NOT NULL column with default value NULL}}
do_test alter3-2.4 {
catchsql {
ALTER TABLE t1 ADD c NOT NULL DEFAULT 10;
}
} {0 {}}
do_test alter3-2.5 {
execsql {
CREATE VIEW v1 AS SELECT * FROM t1;
}
catchsql {
alter table v1 add column d;
}
} {1 {Cannot add a column to a view}}
do_test alter3-2.6 {
catchsql {
alter table t1 add column d DEFAULT CURRENT_TIME;
}
} {1 {Cannot add a column with non-constant default}}
do_test alter3-2.99 {
execsql {
DROP TABLE t1;
}
} {}
do_test alter3-3.1 {
execsql {
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 100);
INSERT INTO t1 VALUES(2, 300);
SELECT * FROM t1;
}
} {1 100 2 300}
do_test alter3-3.1 {
execsql {
PRAGMA schema_version = 10;
}
} {}
do_test alter3-3.2 {
execsql {
ALTER TABLE t1 ADD c;
SELECT * FROM t1;
}
} {1 100 {} 2 300 {}}
if {!$has_codec} {
do_test alter3-3.3 {
get_file_format
} {3}
}
do_test alter3-3.4 {
execsql {
PRAGMA schema_version;
}
} {11}
do_test alter3-4.1 {
db close
file delete -force test.db
set ::DB [sqlite3 db test.db]
execsql {
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 100);
INSERT INTO t1 VALUES(2, 300);
SELECT * FROM t1;
}
} {1 100 2 300}
do_test alter3-4.1 {
execsql {
PRAGMA schema_version = 20;
}
} {}
do_test alter3-4.2 {
execsql {
ALTER TABLE t1 ADD c DEFAULT 'hello world';
SELECT * FROM t1;
}
} {1 100 {hello world} 2 300 {hello world}}
if {!$has_codec} {
do_test alter3-4.3 {
get_file_format
} {3}
}
do_test alter3-4.4 {
execsql {
PRAGMA schema_version;
}
} {21}
do_test alter3-4.99 {
execsql {
DROP TABLE t1;
}
} {}
do_test alter3-5.1 {
file delete -force test2.db
file delete -force test2.db-journal
execsql {
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
ATTACH 'test2.db' AS aux;
CREATE TABLE aux.t1 AS SELECT * FROM t1;
PRAGMA aux.schema_version = 30;
SELECT sql FROM aux.sqlite_master;
}
} {{CREATE TABLE t1(a,b)}}
do_test alter3-5.2 {
execsql {
ALTER TABLE aux.t1 ADD COLUMN c VARCHAR(128);
SELECT sql FROM aux.sqlite_master;
}
} {{CREATE TABLE t1(a,b, c VARCHAR(128))}}
do_test alter3-5.3 {
execsql {
SELECT * FROM aux.t1;
}
} {1 one {} 2 two {}}
do_test alter3-5.4 {
execsql {
PRAGMA aux.schema_version;
}
} {31}
if {!$has_codec} {
do_test alter3-5.5 {
list [get_file_format test2.db] [get_file_format]
} {2 3}
}
do_test alter3-5.6 {
execsql {
ALTER TABLE aux.t1 ADD COLUMN d DEFAULT 1000;
SELECT sql FROM aux.sqlite_master;
}
} {{CREATE TABLE t1(a,b, c VARCHAR(128), d DEFAULT 1000)}}
do_test alter3-5.7 {
execsql {
SELECT * FROM aux.t1;
}
} {1 one {} 1000 2 two {} 1000}
do_test alter3-5.8 {
execsql {
PRAGMA aux.schema_version;
}
} {32}
do_test alter3-5.9 {
execsql {
SELECT * FROM t1;
}
} {1 one 2 two}
do_test alter3-5.99 {
execsql {
DROP TABLE aux.t1;
DROP TABLE t1;
}
} {}
#----------------------------------------------------------------
# Test that the table schema is correctly reloaded when a column
# is added to a table.
#
ifcapable trigger&&tempdb {
do_test alter3-6.1 {
execsql {
CREATE TABLE t1(a, b);
CREATE TABLE log(trig, a, b);
CREATE TRIGGER t1_a AFTER INSERT ON t1 BEGIN
INSERT INTO log VALUES('a', new.a, new.b);
END;
CREATE TEMP TRIGGER t1_b AFTER INSERT ON t1 BEGIN
INSERT INTO log VALUES('b', new.a, new.b);
END;
INSERT INTO t1 VALUES(1, 2);
SELECT * FROM log;
}
} {b 1 2 a 1 2}
do_test alter3-6.2 {
execsql {
ALTER TABLE t1 ADD COLUMN c DEFAULT 'c';
INSERT INTO t1(a, b) VALUES(3, 4);
SELECT * FROM log;
}
} {b 1 2 a 1 2 b 3 4 a 3 4}
}
if {!$has_codec} {
ifcapable vacuum {
do_test alter3-7.1 {
execsql {
VACUUM;
}
get_file_format
} {1}
do_test alter3-7.2 {
execsql {
CREATE TABLE abc(a, b, c);
ALTER TABLE abc ADD d DEFAULT NULL;
}
get_file_format
} {2}
do_test alter3-7.3 {
execsql {
ALTER TABLE abc ADD e DEFAULT 10;
}
get_file_format
} {3}
do_test alter3-7.4 {
execsql {
ALTER TABLE abc ADD f DEFAULT NULL;
}
get_file_format
} {3}
do_test alter3-7.5 {
execsql {
VACUUM;
}
get_file_format
} {1}
}
}
# Ticket #1183 - Make sure adding columns to large tables does not cause
# memory corruption (as was the case before this bug was fixed).
do_test alter3-8.1 {
execsql {
CREATE TABLE t4(c1);
}
} {}
do_test alter3-8.2 {
set cols c1
for {set i 2} {$i < 100} {incr i} {
execsql "
ALTER TABLE t4 ADD c$i
"
lappend cols c$i
}
set ::sql "CREATE TABLE t4([join $cols {, }])"
list
} {}
do_test alter3-8.2 {
execsql {
SELECT sql FROM sqlite_master WHERE name = 't4';
}
} [list $::sql]
finish_test
+126
View File
@@ -0,0 +1,126 @@
# 2005 September 19
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is testing the ALTER TABLE statement and
# specifically out-of-memory conditions within that command.
#
# $Id: altermalloc.test,v 1.2 2005/08/21 18:21:50 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
puts "Skipping malloc tests: not compiled with -DSQLITE_DEBUG..."
finish_test
return
}
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
ifcapable !altertable {
finish_test
return
}
# Usage: do_malloc_test <test name> <options...>
#
# The first argument, <test number>, is an integer used to name the
# tests executed by this proc. Options are as follows:
#
# -tclprep TCL script to run to prepare test.
# -sqlprep SQL script to run to prepare test.
# -tclbody TCL script to run with malloc failure simulation.
# -sqlbody TCL script to run with malloc failure simulation.
# -cleanup TCL script to run after the test.
#
# This command runs a series of tests to verify SQLite's ability
# to handle an out-of-memory condition gracefully. It is assumed
# that if this condition occurs a malloc() call will return a
# NULL pointer. Linux, for example, doesn't do that by default. See
# the "BUGS" section of malloc(3).
#
# Each iteration of a loop, the TCL commands in any argument passed
# to the -tclbody switch, followed by the SQL commands in any argument
# passed to the -sqlbody switch are executed. Each iteration the
# Nth call to sqliteMalloc() is made to fail, where N is increased
# each time the loop runs starting from 1. When all commands execute
# successfully, the loop ends.
#
proc do_malloc_test {tn args} {
array set ::mallocopts $args
set ::go 1
for {set ::n 1} {$::go} {incr ::n} {
do_test $tn.$::n {
sqlite_malloc_fail 0
catch {db close}
catch {file delete -force test.db}
catch {file delete -force test.db-journal}
catch {file delete -force test2.db}
catch {file delete -force test2.db-journal}
set ::DB [sqlite3 db test.db]
if {[info exists ::mallocopts(-tclprep)]} {
eval $::mallocopts(-tclprep)
}
if {[info exists ::mallocopts(-sqlprep)]} {
execsql $::mallocopts(-sqlprep)
}
sqlite_malloc_fail $::n
set ::mallocbody {}
if {[info exists ::mallocopts(-tclbody)]} {
append ::mallocbody "$::mallocopts(-tclbody)\n"
}
if {[info exists ::mallocopts(-sqlbody)]} {
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
}
set v [catch $::mallocbody msg]
set leftover [lindex [sqlite_malloc_stat] 2]
if {$leftover>0} {
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
set ::go 0
set v {1 1}
} else {
set v2 [expr {$msg=="" || $msg=="out of memory"}]
if {!$v2} {puts "\nError message returned: $msg"}
lappend v $v2
}
} {1 1}
sqlite_malloc_fail 0
if {[info exists ::mallocopts(-cleanup)]} {
catch $::mallocopts(-cleanup)
}
}
unset ::mallocopts
}
do_malloc_test altermalloc-1 -tclprep {
db close
} -tclbody {
if {[catch {sqlite3 db test.db}]} {
error "out of memory"
}
} -sqlbody {
CREATE TABLE t1(a int);
ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL;
ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text';
ALTER TABLE t1 RENAME TO t2;
}
finish_test
+257
View File
@@ -0,0 +1,257 @@
# 2005 July 22
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
# This file implements tests for the ANALYZE command.
#
# $Id: analyze.test,v 1.5 2005/09/10 22:40:54 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# There is nothing to test if ANALYZE is disable for this build.
#
ifcapable {!analyze} {
finish_test
return
}
# Basic sanity checks.
#
do_test analyze-1.1 {
catchsql {
ANALYZE no_such_table
}
} {1 {no such table: no_such_table}}
do_test analyze-1.2 {
execsql {
SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1'
}
} {0}
do_test analyze-1.3 {
catchsql {
ANALYZE no_such_db.no_such_table
}
} {1 {unknown database no_such_db}}
do_test analyze-1.4 {
execsql {
SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1'
}
} {0}
do_test analyze-1.5.1 {
catchsql {
ANALYZE
}
} {0 {}}
do_test analyze-1.5.2 {
catchsql {
PRAGMA empty_result_callbacks=1;
ANALYZE
}
} {0 {}}
do_test analyze-1.6 {
execsql {
SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1'
}
} {1}
do_test analyze-1.7 {
execsql {
SELECT * FROM sqlite_stat1
}
} {}
do_test analyze-1.8 {
catchsql {
ANALYZE main
}
} {0 {}}
do_test analyze-1.9 {
execsql {
SELECT * FROM sqlite_stat1
}
} {}
do_test analyze-1.10 {
catchsql {
CREATE TABLE t1(a,b);
ANALYZE main.t1;
}
} {0 {}}
do_test analyze-1.11 {
execsql {
SELECT * FROM sqlite_stat1
}
} {}
do_test analyze-1.12 {
catchsql {
ANALYZE t1;
}
} {0 {}}
do_test analyze-1.13 {
execsql {
SELECT * FROM sqlite_stat1
}
} {}
# Create some indices that can be analyzed. But do not yet add
# data. Without data in the tables, no analysis is done.
#
do_test analyze-2.1 {
execsql {
CREATE INDEX t1i1 ON t1(a);
ANALYZE main.t1;
SELECT * FROM sqlite_stat1 ORDER BY idx;
}
} {}
do_test analyze-2.2 {
execsql {
CREATE INDEX t1i2 ON t1(b);
ANALYZE t1;
SELECT * FROM sqlite_stat1 ORDER BY idx;
}
} {}
do_test analyze-2.3 {
execsql {
CREATE INDEX t1i3 ON t1(a,b);
ANALYZE main;
SELECT * FROM sqlite_stat1 ORDER BY idx;
}
} {}
# Start adding data to the table. Verify that the analysis
# is done correctly.
#
do_test analyze-3.1 {
execsql {
INSERT INTO t1 VALUES(1,2);
INSERT INTO t1 VALUES(1,3);
ANALYZE main.t1;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t1i1 {2 2} t1i2 {2 1} t1i3 {2 2 1}}
do_test analyze-3.2 {
execsql {
INSERT INTO t1 VALUES(1,4);
INSERT INTO t1 VALUES(1,5);
ANALYZE t1;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t1i1 {4 4} t1i2 {4 1} t1i3 {4 4 1}}
do_test analyze-3.3 {
execsql {
INSERT INTO t1 VALUES(2,5);
ANALYZE main;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1}}
do_test analyze-3.4 {
execsql {
CREATE TABLE t2 AS SELECT * FROM t1;
CREATE INDEX t2i1 ON t2(a);
CREATE INDEX t2i2 ON t2(b);
CREATE INDEX t2i3 ON t2(a,b);
ANALYZE;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2} t2i3 {5 3 1}}
do_test analyze-3.5 {
execsql {
DROP INDEX t2i3;
ANALYZE t1;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2} t2i3 {5 3 1}}
do_test analyze-3.6 {
execsql {
ANALYZE t2;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2}}
do_test analyze-3.7 {
execsql {
DROP INDEX t2i2;
ANALYZE t2;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3}}
do_test analyze-3.8 {
execsql {
CREATE TABLE t3 AS SELECT a, b, rowid AS c, 'hi' AS d FROM t1;
CREATE INDEX t3i1 ON t3(a);
CREATE INDEX t3i2 ON t3(a,b,c,d);
CREATE INDEX t3i3 ON t3(d,b,c,a);
DROP TABLE t1;
DROP TABLE t2;
ANALYZE;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}}
# Try corrupting the sqlite_stat1 table and make sure the
# database is still able to function.
#
do_test analyze-4.0 {
sqlite3 db2 test.db
db2 eval {
CREATE TABLE t4(x,y,z);
CREATE INDEX t4i1 ON t4(x);
CREATE INDEX t4i2 ON t4(y);
INSERT INTO t4 SELECT a,b,c FROM t3;
}
db2 close
db close
sqlite3 db test.db
execsql {
ANALYZE;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1} t4i1 {5 3} t4i2 {5 2}}
do_test analyze-4.1 {
execsql {
PRAGMA writable_schema=on;
INSERT INTO sqlite_stat1 VALUES(null,null,null);
PRAGMA writable_schema=off;
}
db close
sqlite3 db test.db
execsql {
SELECT * FROM t4 WHERE x=1234;
}
} {}
do_test analyze-4.2 {
execsql {
PRAGMA writable_schema=on;
DELETE FROM sqlite_stat1;
INSERT INTO sqlite_stat1 VALUES('t4','t4i1','nonsense');
INSERT INTO sqlite_stat1 VALUES('t4','t4i2','120897349817238741092873198273409187234918720394817209384710928374109827172901827349871928741910');
PRAGMA writable_schema=off;
}
db close
sqlite3 db test.db
execsql {
SELECT * FROM t4 WHERE x=1234;
}
} {}
# This test corrupts the database file so it must be the last test
# in the series.
#
do_test analyze-99.1 {
execsql {
PRAGMA writable_schema=on;
UPDATE sqlite_master SET sql='nonsense';
}
db close
sqlite3 db test.db
catchsql {
ANALYZE
}
} {1 {malformed database schema - near "nonsense": syntax error}}
finish_test
+73 -33
View File
@@ -12,7 +12,7 @@
# focus of this script is testing the ATTACH and DETACH commands
# and related functionality.
#
# $Id: attach.test,v 1.37 2005/01/24 10:26:00 danielk1977 Exp $
# $Id: attach.test,v 1.40 2005/03/29 03:11:00 danielk1977 Exp $
#
set testdir [file dirname $argv0]
@@ -80,7 +80,7 @@ do_test attach-1.9 {
} {0 {}}
do_test attach-1.10 {
catchsql {
DETACH DATABASE three;
DETACH DATABASE [three];
}
} {0 {}}
do_test attach-1.11 {
@@ -127,11 +127,13 @@ do_test attach-1.15 {
ATTACH 'test.db' as main;
}
} {1 {database main is already in use}}
do_test attach-1.16 {
catchsql {
ATTACH 'test.db' as temp;
}
} {1 {database temp is already in use}}
ifcapable tempdb {
do_test attach-1.16 {
catchsql {
ATTACH 'test.db' as temp;
}
} {1 {database temp is already in use}}
}
do_test attach-1.17 {
catchsql {
ATTACH 'test.db' as MAIN;
@@ -159,7 +161,9 @@ do_test attach-1.20.2 {
} {0 main 2 db2 3 db3 4 db4 5 db6 6 db7 7 db8 8 db9 9 db10 10 db11}
} ;# ifcapable schema_pragmas
integrity_check attach-1.20.3
execsql {select * from sqlite_temp_master}
ifcapable tempdb {
execsql {select * from sqlite_temp_master}
}
do_test attach-1.21 {
catchsql {
ATTACH 'test.db' as db12;
@@ -172,7 +176,7 @@ do_test attach-1.22 {
} {1 {too many attached databases - max 10}}
do_test attach-1.23 {
catchsql {
DETACH db14;
DETACH "db14";
}
} {1 {no such database: db14}}
do_test attach-1.24 {
@@ -190,11 +194,21 @@ do_test attach-1.26 {
DETACH main;
}
} {1 {cannot detach database main}}
do_test attach-1.27 {
catchsql {
DETACH Temp;
}
} {1 {cannot detach database Temp}}
ifcapable tempdb {
do_test attach-1.27 {
catchsql {
DETACH Temp;
}
} {1 {cannot detach database Temp}}
} else {
do_test attach-1.27 {
catchsql {
DETACH Temp;
}
} {1 {no such database: Temp}}
}
do_test attach-1.28 {
catchsql {
DETACH db11;
@@ -209,9 +223,15 @@ do_test attach-1.28 {
}
} {0 {}}
ifcapable schema_pragmas {
do_test attach-1.29 {
db_list db
} {0 main 1 temp}
ifcapable tempdb {
do_test attach-1.29 {
db_list db
} {0 main 1 temp}
} else {
do_test attach-1.29 {
db_list db
} {0 main}
}
} ;# ifcapable schema_pragmas
ifcapable {trigger} { # Only do the following tests if triggers are enabled
@@ -257,11 +277,18 @@ do_test attach-2.7 {
SELECT type, name, tbl_name FROM db2.sqlite_master;
}
} {table t2 t2 table tx tx trigger r1 t2}
ifcapable schema_pragmas {
do_test attach-2.8 {
db_list db
} {0 main 1 temp 2 db2}
} ;# ifcapable schema_pragmas
ifcapable schema_pragmas&&tempdb {
do_test attach-2.8 {
db_list db
} {0 main 1 temp 2 db2}
} ;# ifcapable schema_pragmas&&tempdb
ifcapable schema_pragmas&&!tempdb {
do_test attach-2.8 {
db_list db
} {0 main 2 db2}
} ;# ifcapable schema_pragmas&&!tempdb
do_test attach-2.9 {
execsql {
CREATE INDEX i2 ON t2(x);
@@ -279,9 +306,15 @@ do_test attach-2.10 {
# }
#} {1 {database schema has changed}}
ifcapable schema_pragmas {
do_test attach-2.12 {
db_list db
} {0 main 1 temp 2 db2}
ifcapable tempdb {
do_test attach-2.12 {
db_list db
} {0 main 1 temp 2 db2}
} else {
do_test attach-2.12 {
db_list db
} {0 main 2 db2}
}
} ;# ifcapable schema_pragmas
do_test attach-2.13 {
catchsql {
@@ -606,14 +639,16 @@ do_test attach-5.3 {
END;
} db2
} {1 {trigger r5 cannot reference objects in database orig}}
do_test attach-5.4 {
catchsql {
CREATE TEMP TABLE t6(p,q,r);
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' FROM temp.t6;
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
ifcapable tempdb {
do_test attach-5.4 {
catchsql {
CREATE TEMP TABLE t6(p,q,r);
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' FROM temp.t6;
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
}
ifcapable subquery {
do_test attach-5.5 {
catchsql {
@@ -674,6 +709,11 @@ if {$tcl_platform(platform)=="unix"} {
dbx eval {CREATE TABLE t1(a,b,c)}
dbx close
file attributes cannot-read -permission 0000
if {[file writable cannot-read]} {
puts "\n**** Tests do not work when run as root ****"
file delete -force cannot-read
exit 1
}
catchsql {
ATTACH DATABASE 'cannot-read' AS noread;
}
+11 -1
View File
@@ -12,7 +12,7 @@
# focus of this script is testing the ATTACH and DETACH commands
# and related functionality.
#
# $Id: attach2.test,v 1.31 2005/01/24 01:38:33 drh Exp $
# $Id: attach2.test,v 1.32 2005/03/29 03:11:00 danielk1977 Exp $
#
set testdir [file dirname $argv0]
@@ -152,6 +152,16 @@ for {set i 2} {$i<=15} {incr i} {
# A procedure to verify the status of locks on a database.
#
proc lock_status {testnum db expected_result} {
# If the database was compiled with OMIT_TEMPDB set, then
# the lock_status list will not contain an entry for the temp
# db. But the test code doesn't know this, so it's easiest
# to filter it out here.
ifcapable !tempdb {
set expected_result [concat \
[lrange $expected_result 0 1] \
[lrange $expected_result 4 end] \
]
}
do_test attach2-$testnum [subst {
$db cache flush ;# The lock_status pragma should not be cached
execsql {PRAGMA lock_status} $db
+26 -24
View File
@@ -12,7 +12,7 @@
# focus of this script is testing the ATTACH and DETACH commands
# and schema changes to attached databases.
#
# $Id: attach3.test,v 1.14 2004/11/22 08:43:32 danielk1977 Exp $
# $Id: attach3.test,v 1.15 2005/03/29 03:11:00 danielk1977 Exp $
#
@@ -189,29 +189,31 @@ do_test attach3-8.2 {
}
} {}
# Try to trick SQLite into dropping the wrong temp trigger.
do_test attach3-9.0 {
execsql {
CREATE TABLE main.t4(a, b, c);
CREATE TABLE aux.t4(a, b, c);
CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN
SELECT 'hello world';
END;
SELECT count(*) FROM sqlite_temp_master;
}
} {1}
do_test attach3-9.1 {
execsql {
DROP TABLE main.t4;
SELECT count(*) FROM sqlite_temp_master;
}
} {1}
do_test attach3-9.2 {
execsql {
DROP TABLE aux.t4;
SELECT count(*) FROM sqlite_temp_master;
}
} {0}
ifcapable tempdb {
# Try to trick SQLite into dropping the wrong temp trigger.
do_test attach3-9.0 {
execsql {
CREATE TABLE main.t4(a, b, c);
CREATE TABLE aux.t4(a, b, c);
CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN
SELECT 'hello world';
END;
SELECT count(*) FROM sqlite_temp_master;
}
} {1}
do_test attach3-9.1 {
execsql {
DROP TABLE main.t4;
SELECT count(*) FROM sqlite_temp_master;
}
} {1}
do_test attach3-9.2 {
execsql {
DROP TABLE aux.t4;
SELECT count(*) FROM sqlite_temp_master;
}
} {0}
}
} ;# endif trigger
# Make sure the aux.sqlite_master table is read-only
+127
View File
@@ -0,0 +1,127 @@
# 2005 September 19
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is testing the ATTACH statement and
# specifically out-of-memory conditions within that command.
#
# $Id: attachmalloc.test,v 1.2 2005/08/21 18:21:50 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
puts "Skipping malloc tests: not compiled with -DSQLITE_DEBUG..."
finish_test
return
}
# Usage: do_malloc_test <test name> <options...>
#
# The first argument, <test number>, is an integer used to name the
# tests executed by this proc. Options are as follows:
#
# -tclprep TCL script to run to prepare test.
# -sqlprep SQL script to run to prepare test.
# -tclbody TCL script to run with malloc failure simulation.
# -sqlbody TCL script to run with malloc failure simulation.
# -cleanup TCL script to run after the test.
#
# This command runs a series of tests to verify SQLite's ability
# to handle an out-of-memory condition gracefully. It is assumed
# that if this condition occurs a malloc() call will return a
# NULL pointer. Linux, for example, doesn't do that by default. See
# the "BUGS" section of malloc(3).
#
# Each iteration of a loop, the TCL commands in any argument passed
# to the -tclbody switch, followed by the SQL commands in any argument
# passed to the -sqlbody switch are executed. Each iteration the
# Nth call to sqliteMalloc() is made to fail, where N is increased
# each time the loop runs starting from 1. When all commands execute
# successfully, the loop ends.
#
proc do_malloc_test {tn args} {
array set ::mallocopts $args
set ::go 1
for {set ::n 1} {$::go} {incr ::n} {
do_test $tn.$::n {
sqlite_malloc_fail 0
catch {db close}
catch {file delete -force test.db}
catch {file delete -force test.db-journal}
catch {file delete -force test2.db}
catch {file delete -force test2.db-journal}
set ::DB [sqlite3 db test.db]
if {[info exists ::mallocopts(-tclprep)]} {
eval $::mallocopts(-tclprep)
}
if {[info exists ::mallocopts(-sqlprep)]} {
execsql $::mallocopts(-sqlprep)
}
sqlite_malloc_fail $::n
set ::mallocbody {}
if {[info exists ::mallocopts(-tclbody)]} {
append ::mallocbody "$::mallocopts(-tclbody)\n"
}
if {[info exists ::mallocopts(-sqlbody)]} {
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
}
set v [catch $::mallocbody msg]
set leftover [lindex [sqlite_malloc_stat] 2]
if {$leftover>0} {
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
set ::go 0
set v {1 1}
} else {
set v2 [expr {$msg=="" || $msg=="out of memory"}]
if {!$v2} {puts "\nError message returned: $msg"}
lappend v $v2
}
} {1 1}
sqlite_malloc_fail 0
if {[info exists ::mallocopts(-cleanup)]} {
catch $::mallocopts(-cleanup)
}
}
unset ::mallocopts
}
do_malloc_test attachmalloc-1 -tclprep {
db close
for {set i 2} {$i<=4} {incr i} {
file delete -force test$i.db
file delete -force test$i.db-journal
}
} -tclbody {
if {[catch {sqlite3 db test.db}]} {
error "out of memory"
}
} -sqlbody {
ATTACH 'test2.db' AS two;
CREATE TABLE two.t1(x);
ATTACH 'test3.db' AS three;
CREATE TABLE three.t1(x);
ATTACH 'test4.db' AS four;
CREATE TABLE four.t1(x);
}
finish_test
+622 -529
View File
File diff suppressed because it is too large Load Diff
+200 -153
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is testing the AUTOINCREMENT features.
#
# $Id: autoinc.test,v 1.3 2005/01/21 11:55:27 danielk1977 Exp $
# $Id: autoinc.test,v 1.7 2005/08/11 02:10:19 drh Exp $
#
set testdir [file dirname $argv0]
@@ -235,48 +235,53 @@ do_test autoinc-2.51 {
SELECT * FROM sqlite_sequence
}
} {t1 1241}
do_test autoinc-2.52 {
execsql {
CREATE TEMP TABLE t2 AS SELECT y FROM t1;
INSERT INTO t1 SELECT NULL, y+4 FROM t2;
SELECT * FROM t1;
}
} {235 1 1235 2 1240 3 1241 4 1242 5 1243 6 1244 7 1245 8}
do_test autoinc-2.53 {
execsql {
SELECT * FROM sqlite_sequence
}
} {t1 1245}
do_test autoinc-2.54 {
execsql {
DELETE FROM t1;
INSERT INTO t1 SELECT NULL, y FROM t2;
SELECT * FROM t1;
}
} {1246 1 1247 2 1248 3 1249 4}
do_test autoinc-2.55 {
execsql {
SELECT * FROM sqlite_sequence
}
} {t1 1249}
ifcapable tempdb {
do_test autoinc-2.52 {
execsql {
CREATE TEMP TABLE t2 AS SELECT y FROM t1;
INSERT INTO t1 SELECT NULL, y+4 FROM t2;
SELECT * FROM t1;
}
} {235 1 1235 2 1240 3 1241 4 1242 5 1243 6 1244 7 1245 8}
do_test autoinc-2.53 {
execsql {
SELECT * FROM sqlite_sequence
}
} {t1 1245}
do_test autoinc-2.54 {
execsql {
DELETE FROM t1;
INSERT INTO t1 SELECT NULL, y FROM t2;
SELECT * FROM t1;
}
} {1246 1 1247 2 1248 3 1249 4}
do_test autoinc-2.55 {
execsql {
SELECT * FROM sqlite_sequence
}
} {t1 1249}
}
# Create multiple AUTOINCREMENT tables. Make sure all sequences are
# tracked separately and do not interfere with one another.
#
do_test autoinc-2.70 {
execsql {
catchsql {
DROP TABLE t2;
}
execsql {
CREATE TABLE t2(d, e INTEGER PRIMARY KEY AUTOINCREMENT, f);
INSERT INTO t2(d) VALUES(1);
SELECT * FROM sqlite_sequence;
}
} {t1 1249 t2 1}
} [ifcapable tempdb {list t1 1249 t2 1} else {list t1 1241 t2 1}]
do_test autoinc-2.71 {
execsql {
INSERT INTO t2(d) VALUES(2);
SELECT * FROM sqlite_sequence;
}
} {t1 1249 t2 2}
} [ifcapable tempdb {list t1 1249 t2 2} else {list t1 1241 t2 2}]
do_test autoinc-2.72 {
execsql {
INSERT INTO t1(x) VALUES(10000);
@@ -326,141 +331,156 @@ do_test autoinc-3.4 {
# AUTOINCREMENT on TEMP tables.
#
do_test autoinc-4.1 {
execsql {
SELECT 1, name FROM sqlite_master WHERE type='table';
SELECT 2, name FROM sqlite_temp_master WHERE type='table';
}
} {1 sqlite_sequence}
do_test autoinc-4.2 {
execsql {
CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
CREATE TEMP TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
SELECT 1, name FROM sqlite_master WHERE type='table';
SELECT 2, name FROM sqlite_temp_master WHERE type='table';
}
} {1 sqlite_sequence 1 t1 2 t3 2 sqlite_sequence}
do_test autoinc-4.3 {
execsql {
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {}
do_test autoinc-4.4 {
execsql {
INSERT INTO t1 VALUES(10,1);
INSERT INTO t3 VALUES(20,2);
INSERT INTO t1 VALUES(NULL,3);
INSERT INTO t3 VALUES(NULL,4);
}
} {}
ifcapable compound {
do_test autoinc-4.4.1 {
execsql {
SELECT * FROM t1 UNION ALL SELECT * FROM t3;
}
} {10 1 11 3 20 2 21 4}
} ;# ifcapable compound
do_test autoinc-4.5 {
execsql {
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {1 t1 11 2 t3 21}
do_test autoinc-4.6 {
execsql {
INSERT INTO t1 SELECT * FROM t3;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {1 t1 21 2 t3 21}
do_test autoinc-4.7 {
execsql {
INSERT INTO t3 SELECT x+100, y FROM t1;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {1 t1 21 2 t3 121}
do_test autoinc-4.8 {
execsql {
DROP TABLE t3;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {1 t1 21}
do_test autoinc-4.9 {
execsql {
CREATE TEMP TABLE t2(p INTEGER PRIMARY KEY AUTOINCREMENT, q);
INSERT INTO t2 SELECT * FROM t1;
DROP TABLE t1;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {2 t2 21}
do_test autoinc-4.10 {
execsql {
DROP TABLE t2;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {}
ifcapable tempdb {
do_test autoinc-4.1 {
execsql {
SELECT 1, name FROM sqlite_master WHERE type='table';
SELECT 2, name FROM sqlite_temp_master WHERE type='table';
}
} {1 sqlite_sequence}
do_test autoinc-4.2 {
execsql {
CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
CREATE TEMP TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
SELECT 1, name FROM sqlite_master WHERE type='table';
SELECT 2, name FROM sqlite_temp_master WHERE type='table';
}
} {1 sqlite_sequence 1 t1 2 t3 2 sqlite_sequence}
do_test autoinc-4.3 {
execsql {
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {}
do_test autoinc-4.4 {
execsql {
INSERT INTO t1 VALUES(10,1);
INSERT INTO t3 VALUES(20,2);
INSERT INTO t1 VALUES(NULL,3);
INSERT INTO t3 VALUES(NULL,4);
}
} {}
ifcapable compound {
do_test autoinc-4.4.1 {
execsql {
SELECT * FROM t1 UNION ALL SELECT * FROM t3;
}
} {10 1 11 3 20 2 21 4}
} ;# ifcapable compound
do_test autoinc-4.5 {
execsql {
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {1 t1 11 2 t3 21}
do_test autoinc-4.6 {
execsql {
INSERT INTO t1 SELECT * FROM t3;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {1 t1 21 2 t3 21}
do_test autoinc-4.7 {
execsql {
INSERT INTO t3 SELECT x+100, y FROM t1;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {1 t1 21 2 t3 121}
do_test autoinc-4.8 {
execsql {
DROP TABLE t3;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {1 t1 21}
do_test autoinc-4.9 {
execsql {
CREATE TEMP TABLE t2(p INTEGER PRIMARY KEY AUTOINCREMENT, q);
INSERT INTO t2 SELECT * FROM t1;
DROP TABLE t1;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {2 t2 21}
do_test autoinc-4.10 {
execsql {
DROP TABLE t2;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
}
} {}
}
# Make sure AUTOINCREMENT works on ATTACH-ed tables.
#
do_test autoinc-5.1 {
file delete -force test2.db
file delete -force test2.db-journal
sqlite3 db2 test2.db
execsql {
CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n);
CREATE TABLE t5(o, p INTEGER PRIMARY KEY AUTOINCREMENT);
} db2;
execsql {
ATTACH 'test2.db' as aux;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
SELECT 3, * FROM aux.sqlite_sequence;
}
} {}
do_test autoinc-5.2 {
execsql {
INSERT INTO t4 VALUES(NULL,1);
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
SELECT 3, * FROM aux.sqlite_sequence;
}
} {3 t4 1}
do_test autoinc-5.3 {
execsql {
INSERT INTO t5 VALUES(100,200);
SELECT * FROM sqlite_sequence
} db2
} {t4 1 t5 200}
do_test autoinc-5.4 {
execsql {
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
SELECT 3, * FROM aux.sqlite_sequence;
}
} {3 t4 1 3 t5 200}
ifcapable tempdb {
do_test autoinc-5.1 {
file delete -force test2.db
file delete -force test2.db-journal
sqlite3 db2 test2.db
execsql {
CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n);
CREATE TABLE t5(o, p INTEGER PRIMARY KEY AUTOINCREMENT);
} db2;
execsql {
ATTACH 'test2.db' as aux;
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
SELECT 3, * FROM aux.sqlite_sequence;
}
} {}
do_test autoinc-5.2 {
execsql {
INSERT INTO t4 VALUES(NULL,1);
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
SELECT 3, * FROM aux.sqlite_sequence;
}
} {3 t4 1}
do_test autoinc-5.3 {
execsql {
INSERT INTO t5 VALUES(100,200);
SELECT * FROM sqlite_sequence
} db2
} {t4 1 t5 200}
do_test autoinc-5.4 {
execsql {
SELECT 1, * FROM main.sqlite_sequence;
SELECT 2, * FROM temp.sqlite_sequence;
SELECT 3, * FROM aux.sqlite_sequence;
}
} {3 t4 1 3 t5 200}
}
# Requirement REQ00310: Make sure an insert fails if the sequence is
# already at its maximum value.
#
do_test autoinc-6.1 {
execsql {
CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w);
INSERT INTO t6 VALUES(9223372036854775807,1);
SELECT seq FROM main.sqlite_sequence WHERE name='t6';
}
} 9223372036854775807
ifcapable {rowid32} {
do_test autoinc-6.1 {
execsql {
CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w);
INSERT INTO t6 VALUES(2147483647,1);
SELECT seq FROM main.sqlite_sequence WHERE name='t6';
}
} 2147483647
}
ifcapable {!rowid32} {
do_test autoinc-6.1 {
execsql {
CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w);
INSERT INTO t6 VALUES(9223372036854775807,1);
SELECT seq FROM main.sqlite_sequence WHERE name='t6';
}
} 9223372036854775807
}
do_test autoinc-6.2 {
catchsql {
INSERT INTO t6 VALUES(NULL,1);
}
} {1 {database is full}}
} {1 {database or disk is full}}
# Allow the AUTOINCREMENT keyword inside the parentheses
# on a separate PRIMARY KEY designation.
@@ -484,5 +504,32 @@ do_test autoinc-7.2 {
}
} {1 {AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY}}
catch {db2 close}
# Ticket #1283. Make sure that preparing but never running a statement
# that creates the sqlite_sequence table does not mess up the database.
#
do_test autoinc-8.1 {
catch {db2 close}
catch {db close}
file delete -force test.db
set DB [sqlite3 db test.db]
set STMT [sqlite3_prepare $DB {
CREATE TABLE t1(
x INTEGER PRIMARY KEY AUTOINCREMENT
)
} -1 TAIL]
sqlite3_finalize $STMT
set STMT [sqlite3_prepare $DB {
CREATE TABLE t1(
x INTEGER PRIMARY KEY AUTOINCREMENT
)
} -1 TAIL]
sqlite3_step $STMT
sqlite3_finalize $STMT
execsql {
INSERT INTO t1 VALUES(NULL);
SELECT * FROM t1;
}
} {1}
finish_test
+40 -3
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the SELECT statement.
#
# $Id: autovacuum.test,v 1.16 2005/01/24 10:26:00 danielk1977 Exp $
# $Id: autovacuum.test,v 1.19 2005/09/16 09:52:30 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -279,12 +279,16 @@ do_test autovacuum-2.4.4 {
"
} {}
set root_page_list [list]
set pending_byte_page [expr ($::sqlite_pending_byte / 1024) + 1]
for {set i 3} {$i<=532} {incr i} {
# 207 and 412 are pointer-map pages.
if { $i!=207 && $i!=412 } {
if { $i!=207 && $i!=412 && $i != $pending_byte_page} {
lappend root_page_list $i
}
}
if {$i >= $pending_byte_page} {
lappend root_page_list $i
}
do_test autovacuum-2.4.5 {
for {set i 11} {$i<=530} {incr i} {
execsql "CREATE TABLE av$i (x)"
@@ -298,7 +302,7 @@ do_test autovacuum-2.4.5 {
do_test autovacuum-2.4.6 {
execsql COMMIT;
file_pages
} 561
} [expr 561 + (($i >= $pending_byte_page)?1:0)]
integrity_check autovacuum-2.4.6
do_test autovacuum-2.4.7 {
execsql BEGIN
@@ -488,4 +492,37 @@ do_test autovacuum-3.7 {
file_pages
} [expr $AUTOVACUUM?1:2]
#-----------------------------------------------------------------------
# Test that if a statement transaction around a CREATE INDEX statement is
# rolled back no corruption occurs.
#
do_test autovacuum-4.1 {
execsql {
CREATE TABLE av1(a, b);
BEGIN;
}
for {set i 0} {$i<100} {incr i} {
execsql "INSERT INTO av1 VALUES($i, '[string repeat X 200]');"
}
execsql "INSERT INTO av1 VALUES(99, '[string repeat X 200]');"
execsql {
SELECT sum(a) FROM av1;
}
} {5049}
do_test autovacuum-4.2 {
catchsql {
CREATE UNIQUE INDEX av1_i ON av1(a);
}
} {1 {indexed columns are not unique}}
do_test autovacuum-4.3 {
execsql {
SELECT sum(a) FROM av1;
}
} {5049}
do_test autovacuum-4.4 {
execsql {
COMMIT;
}
} {}
finish_test
+106
View File
@@ -0,0 +1,106 @@
# 2005 July 28
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this file is testing the use of indices in WHERE clauses
# when the WHERE clause contains the BETWEEN operator.
#
# $Id: between.test,v 1.1 2005/07/28 23:12:08 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Build some test data
#
do_test between-1.0 {
execsql {
BEGIN;
CREATE TABLE t1(w int, x int, y int, z int);
}
for {set i 1} {$i<=100} {incr i} {
set w $i
set x [expr {int(log($i)/log(2))}]
set y [expr {$i*$i + 2*$i + 1}]
set z [expr {$x+$y}]
execsql {INSERT INTO t1 VALUES($::w,$::x,$::y,$::z)}
}
execsql {
CREATE UNIQUE INDEX i1w ON t1(w);
CREATE INDEX i1xy ON t1(x,y);
CREATE INDEX i1zyx ON t1(z,y,x);
COMMIT;
}
} {}
# This procedure executes the SQL. Then it appends to the result the
# "sort" or "nosort" keyword depending on whether or not any sorting
# is done. Then it appends the ::sqlite_query_plan variable.
#
proc queryplan {sql} {
set ::sqlite_sort_count 0
set data [execsql $sql]
if {$::sqlite_sort_count} {set x sort} {set x nosort}
lappend data $x
return [concat $data $::sqlite_query_plan]
}
do_test between-1.1.1 {
queryplan {
SELECT * FROM t1 WHERE w BETWEEN 5 AND 6 ORDER BY +w
}
} {5 2 36 38 6 2 49 51 sort t1 i1w}
do_test between-1.1.2 {
queryplan {
SELECT * FROM t1 WHERE +w BETWEEN 5 AND 6 ORDER BY +w
}
} {5 2 36 38 6 2 49 51 sort t1 {}}
do_test between-1.2.1 {
queryplan {
SELECT * FROM t1 WHERE w BETWEEN 5 AND 65-y ORDER BY +w
}
} {5 2 36 38 6 2 49 51 sort t1 i1w}
do_test between-1.2.2 {
queryplan {
SELECT * FROM t1 WHERE +w BETWEEN 5 AND 65-y ORDER BY +w
}
} {5 2 36 38 6 2 49 51 sort t1 {}}
do_test between-1.3.1 {
queryplan {
SELECT * FROM t1 WHERE w BETWEEN 41-y AND 6 ORDER BY +w
}
} {5 2 36 38 6 2 49 51 sort t1 i1w}
do_test between-1.3.2 {
queryplan {
SELECT * FROM t1 WHERE +w BETWEEN 41-y AND 6 ORDER BY +w
}
} {5 2 36 38 6 2 49 51 sort t1 {}}
do_test between-1.4 {
queryplan {
SELECT * FROM t1 WHERE w BETWEEN 41-y AND 65-y ORDER BY +w
}
} {5 2 36 38 6 2 49 51 sort t1 {}}
do_test between-1.5.1 {
queryplan {
SELECT * FROM t1 WHERE 26 BETWEEN y AND z ORDER BY +w
}
} {4 2 25 27 sort t1 i1zyx}
do_test between-1.5.2 {
queryplan {
SELECT * FROM t1 WHERE 26 BETWEEN +y AND z ORDER BY +w
}
} {4 2 25 27 sort t1 i1zyx}
do_test between-1.5.3 {
queryplan {
SELECT * FROM t1 WHERE 26 BETWEEN y AND +z ORDER BY +w
}
} {4 2 25 27 sort t1 {}}
finish_test
+6 -1
View File
@@ -12,7 +12,7 @@
# focus of this script testing the ability of SQLite to handle database
# files larger than 4GB.
#
# $Id: bigfile.test,v 1.7 2004/10/30 20:23:09 drh Exp $
# $Id: bigfile.test,v 1.8 2005/09/07 23:05:22 drh Exp $
#
set testdir [file dirname $argv0]
@@ -175,6 +175,11 @@ do_test bigfile-1.16 {
SELECT md5sum(x) FROM t3;
}
} $::MAGIC_SUM
do_test bigfile-1.17 {
execsql {
SELECT md5sum(x) FROM t4;
}
} $::MAGIC_SUM
} ;# End of the "if( db command exists )"
+6 -4
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script testing the sqlite_bind API.
#
# $Id: bind.test,v 1.30 2005/02/12 08:59:59 danielk1977 Exp $
# $Id: bind.test,v 1.32 2005/06/22 08:48:07 drh Exp $
#
set testdir [file dirname $argv0]
@@ -104,13 +104,13 @@ ifcapable {tclvar} {
execsql {
DELETE FROM t1;
}
set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES($one,$::two,${x{y}z})}\
set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES($one,$::two,$x(-z-))}\
-1 TX]
set TX
} {}
set v1 {$one}
set v2 {$::two}
set v3 {${x{y}z}}
set v3 {$x(-z-)}
}
ifcapable {!tclvar} {
do_test bind-2.1 {
@@ -200,7 +200,9 @@ do_test bind-4.1 {
sqlite3_bind_double $VM 3 123456789
sqlite_step $VM N VALUES COLNAMES
sqlite3_reset $VM
execsql {SELECT rowid, * FROM t1}
set x [execsql {SELECT rowid, * FROM t1}]
regsub {1e-005} $x {1e-05} y
set y
} {1 1234.1234 1e-05 123456789.0}
do_test bind-4.2 {
execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
+74
View File
@@ -0,0 +1,74 @@
# 2005 April 21
#
# 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_transfer_bindings() API.
#
# $Id: bindxfer.test,v 1.1 2005/04/22 02:38:39 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
proc sqlite_step {stmt VALS COLS} {
upvar #0 $VALS vals
upvar #0 $COLS cols
set vals [list]
set cols [list]
set rc [sqlite3_step $stmt]
for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} {
lappend cols [sqlite3_column_name $stmt $i]
}
for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} {
lappend vals [sqlite3_column_text $stmt $i]
}
return $rc
}
do_test bindxfer-1.1 {
db close
set DB [sqlite3 db test.db]
execsql {CREATE TABLE t1(a,b,c);}
set VM1 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL]
set TAIL
} {}
do_test bindxfer-1.2 {
sqlite3_bind_parameter_count $VM1
} 3
do_test bindxfer-1.3 {
set VM2 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL]
set TAIL
} {}
do_test bindxfer-1.4 {
sqlite3_bind_parameter_count $VM2
} 3
do_test bindxfer-1.5 {
sqlite_bind $VM1 1 one normal
set sqlite_static_bind_value two
sqlite_bind $VM1 2 {} static
sqlite_bind $VM1 3 {} null
sqlite3_transfer_bindings $VM1 $VM2
sqlite_step $VM1 VALUES COLNAMES
} SQLITE_ROW
do_test bindxfer-1.6 {
set VALUES
} {{} {} {}}
do_test bindxfer-1.7 {
sqlite_step $VM2 VALUES COLNAMES
} SQLITE_ROW
do_test bindxfer-1.8 {
set VALUES
} {one two {}}
catch {sqlite3_finalize $VM1}
catch {sqlite3_finalize $VM2}
finish_test
+5 -5
View File
@@ -10,7 +10,7 @@
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# $Id: blob.test,v 1.3 2004/11/03 13:59:06 drh Exp $
# $Id: blob.test,v 1.4 2005/08/23 11:17:59 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -30,19 +30,19 @@ proc bin_to_hex {blob} {
# Simplest possible case. Specify a blob literal
do_test blob-1.0 {
set blob [execsql {SELECT X'01020304'}]
set blob [execsql {SELECT X'01020304';}]
bin_to_hex [lindex $blob 0]
} {01020304}
do_test blob-1.1 {
set blob [execsql {SELECT x'ABCDEF'}]
set blob [execsql {SELECT x'ABCDEF';}]
bin_to_hex [lindex $blob 0]
} {ABCDEF}
do_test blob-1.2 {
set blob [execsql {SELECT x''}]
set blob [execsql {SELECT x'';}]
bin_to_hex [lindex $blob 0]
} {}
do_test blob-1.3 {
set blob [execsql {SELECT x'abcdEF12'}]
set blob [execsql {SELECT x'abcdEF12';}]
bin_to_hex [lindex $blob 0]
} {ABCDEF12}
+43
View File
@@ -0,0 +1,43 @@
# 2005 August 2
#
# 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.
#
# $Id: btree8.test,v 1.6 2005/08/02 17:13:12 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Ticket #1346: If the table rooted on page 1 contains a single entry
# and that single entries has to flow out into another page because
# page 1 is 100-bytes smaller than most other pages, then you delete that
# one entry, everything should still work.
#
do_test btree8-1.1 {
execsql {
CREATE TABLE t1(x
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
);
DROP table t1;
}
} {}
integrity_check btree8-1.2
+44
View File
@@ -0,0 +1,44 @@
# 2005 july 8
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file test the busy handler
#
# $Id: busy.test,v 1.2 2005/09/17 18:02:37 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test busy-1.1 {
sqlite3 db2 test.db
execsql {
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(1);
SELECT * FROM t1
}
} 1
proc busy x {
lappend ::busyargs $x
if {$x>2} {return 1}
return 0
}
set busyargs {}
do_test busy-1.2 {
db busy busy
db2 eval {begin exclusive}
catchsql {begin immediate}
} {1 {database is locked}}
do_test busy-1.3 {
set busyargs
} {0 1 2 3}
db2 close
finish_test
+3 -3
View File
@@ -11,7 +11,7 @@
# 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.25 2005/02/04 04:07:18 danielk1977 Exp $
# $Id: capi2.test,v 1.26 2005/03/29 03:11:00 danielk1977 Exp $
#
set testdir [file dirname $argv0]
@@ -97,13 +97,13 @@ do_test capi2-1.11 {
do_test capi2-2.1 {
set SQL {
SELECT name, rowid FROM sqlite_master;
SELECT name, rowid FROM sqlite_temp_master;
SELECT name, rowid FROM sqlite_master WHERE 0;
-- A comment at the end
}
set VM [sqlite3_prepare $DB $SQL -1 SQL]
set SQL
} {
SELECT name, rowid FROM sqlite_temp_master;
SELECT name, rowid FROM sqlite_master WHERE 0;
-- A comment at the end
}
do_test capi2-2.2 {
+42 -7
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.29 2005/01/24 10:26:00 danielk1977 Exp $
# $Id: capi3.test,v 1.34 2005/08/11 02:10:19 drh Exp $
#
set testdir [file dirname $argv0]
@@ -54,6 +54,9 @@ proc utf8 {str} {
db close
set DB [sqlite3 db test.db]
do_test capi3-1.0 {
sqlite3_get_autocommit $DB
} 1
do_test capi3-1.1 {
set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL]
sqlite3_finalize $STMT
@@ -487,7 +490,7 @@ if {![sqlite3 -has-codec]} {
set ::bt [btree_open test.db 10 0]
btree_begin_transaction $::bt
set meta [btree_get_meta $::bt]
lset meta 2 2
lset meta 2 4
eval [concat btree_update_meta $::bt [lrange $meta 0 end]]
btree_commit $::bt
btree_close $::bt
@@ -572,7 +575,6 @@ file delete -force test.db-journal
set code2english [list \
SQLITE_OK {not an error} \
SQLITE_ERROR {SQL logic error or missing database} \
SQLITE_INTERNAL {internal SQLite implementation flaw} \
SQLITE_PERM {access permission denied} \
SQLITE_ABORT {callback requested query abort} \
SQLITE_BUSY {database is locked} \
@@ -582,13 +584,11 @@ SQLITE_READONLY {attempt to write a readonly database} \
SQLITE_INTERRUPT {interrupted} \
SQLITE_IOERR {disk I/O error} \
SQLITE_CORRUPT {database disk image is malformed} \
SQLITE_NOTFOUND {table or record not found} \
SQLITE_FULL {database is full} \
SQLITE_FULL {database or disk is full} \
SQLITE_CANTOPEN {unable to open database file} \
SQLITE_PROTOCOL {database locking protocol failure} \
SQLITE_EMPTY {table contains no data} \
SQLITE_SCHEMA {database schema has changed} \
SQLITE_TOOBIG {too much data for one table row} \
SQLITE_CONSTRAINT {constraint failed} \
SQLITE_MISMATCH {datatype mismatch} \
SQLITE_MISUSE {library routine called out of sequence} \
@@ -641,6 +641,9 @@ do_test capi3-11.1 {
INSERT INTO t1 VALUES(2, 'notatype');
}
} {}
do_test capi3-11.1.1 {
sqlite3_get_autocommit $DB
} 0
do_test capi3-11.2 {
set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]
sqlite3_step $STMT
@@ -650,6 +653,9 @@ do_test capi3-11.3 {
COMMIT;
}
} {1 {cannot commit transaction - SQL statements in progress}}
do_test capi3-11.3.1 {
sqlite3_get_autocommit $DB
} 0
do_test capi3-11.4 {
sqlite3_step $STMT
} {SQLITE_ERROR}
@@ -661,11 +667,17 @@ do_test capi3-11.6 {
SELECT * FROM t1;
}
} {0 {1 int 2 notatype}}
do_test capi3-11.6.1 {
sqlite3_get_autocommit $DB
} 0
do_test capi3-11.7 {
catchsql {
COMMIT;
}
} {0 {}}
do_test capi3-11.7.1 {
sqlite3_get_autocommit $DB
} 1
do_test capi3-11.8 {
execsql {
CREATE TABLE t2(a);
@@ -675,15 +687,24 @@ do_test capi3-11.8 {
INSERT INTO t2 VALUES(3);
}
} {}
do_test capi3-11.8.1 {
sqlite3_get_autocommit $DB
} 0
do_test capi3-11.9 {
set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
sqlite3_step $STMT
} {SQLITE_ROW}
do_test capi3-11.3 {
do_test capi3-11.9.1 {
sqlite3_get_autocommit $DB
} 0
do_test capi3-11.9.2 {
catchsql {
ROLLBACK;
}
} {1 {cannot rollback transaction - SQL statements in progress}}
do_test capi3-11.9.3 {
sqlite3_get_autocommit $DB
} 0
do_test capi3-11.10 {
sqlite3_step $STMT
} {SQLITE_ROW}
@@ -701,11 +722,17 @@ do_test capi3-11.14 {
SELECT a FROM t2;
}
} {1 2 3}
do_test capi3-11.14.1 {
sqlite3_get_autocommit $DB
} 0
do_test capi3-11.15 {
catchsql {
ROLLBACK;
}
} {0 {}}
do_test capi3-11.15.1 {
sqlite3_get_autocommit $DB
} 1
do_test capi3-11.16 {
execsql {
SELECT a FROM t2;
@@ -823,4 +850,12 @@ if {[llength [info commands sqlite3_sleep]]>0} {
} {1}
}
# Ticket #1219: Make sure binding APIs can handle a NULL pointer.
#
do_test capi3-14.1 {
set rc [catch {sqlite3_bind_text 0 1 hello 5} msg]
lappend rc $msg
} {1 SQLITE_MISUSE}
finish_test
+184
View File
@@ -0,0 +1,184 @@
# 2005 June 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 implements regression tests for SQLite library. The
# focus of this file is testing the CAST operator.
#
# $Id: cast.test,v 1.2 2005/06/25 19:31:48 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Only run these tests if the build includes the CAST operator
ifcapable !cast {
finish_test
return
}
# Tests for the CAST( AS blob), CAST( AS text) and CAST( AS numeric) built-ins
#
do_test cast-1.1 {
execsql {SELECT x'616263'}
} abc
do_test cast-1.2 {
execsql {SELECT typeof(x'616263')}
} blob
do_test cast-1.3 {
execsql {SELECT CAST(x'616263' AS text)}
} abc
do_test cast-1.4 {
execsql {SELECT typeof(CAST(x'616263' AS text))}
} text
do_test cast-1.5 {
execsql {SELECT CAST(x'616263' AS numeric)}
} 0.0
do_test cast-1.6 {
execsql {SELECT typeof(CAST(x'616263' AS numeric))}
} real
do_test cast-1.7 {
execsql {SELECT CAST(x'616263' AS blob)}
} abc
do_test cast-1.8 {
execsql {SELECT typeof(CAST(x'616263' AS blob))}
} blob
do_test cast-1.9 {
execsql {SELECT CAST(x'616263' AS integer)}
} 0
do_test cast-1.10 {
execsql {SELECT typeof(CAST(x'616263' AS integer))}
} integer
do_test cast-1.11 {
execsql {SELECT null}
} {{}}
do_test cast-1.12 {
execsql {SELECT typeof(NULL)}
} null
do_test cast-1.13 {
execsql {SELECT CAST(NULL AS text)}
} {{}}
do_test cast-1.14 {
execsql {SELECT typeof(CAST(NULL AS text))}
} null
do_test cast-1.15 {
execsql {SELECT CAST(NULL AS numeric)}
} {{}}
do_test cast-1.16 {
execsql {SELECT typeof(CAST(NULL AS numeric))}
} null
do_test cast-1.17 {
execsql {SELECT CAST(NULL AS blob)}
} {{}}
do_test cast-1.18 {
execsql {SELECT typeof(CAST(NULL AS blob))}
} null
do_test cast-1.19 {
execsql {SELECT CAST(NULL AS integer)}
} {{}}
do_test cast-1.20 {
execsql {SELECT typeof(CAST(NULL AS integer))}
} null
do_test cast-1.21 {
execsql {SELECT 123}
} {123}
do_test cast-1.22 {
execsql {SELECT typeof(123)}
} integer
do_test cast-1.23 {
execsql {SELECT CAST(123 AS text)}
} {123}
do_test cast-1.24 {
execsql {SELECT typeof(CAST(123 AS text))}
} text
do_test cast-1.25 {
execsql {SELECT CAST(123 AS numeric)}
} 123
do_test cast-1.26 {
execsql {SELECT typeof(CAST(123 AS numeric))}
} integer
do_test cast-1.27 {
execsql {SELECT CAST(123 AS blob)}
} {123}
do_test cast-1.28 {
execsql {SELECT typeof(CAST(123 AS blob))}
} blob
do_test cast-1.29 {
execsql {SELECT CAST(123 AS integer)}
} {123}
do_test cast-1.30 {
execsql {SELECT typeof(CAST(123 AS integer))}
} integer
do_test cast-1.31 {
execsql {SELECT 123.456}
} {123.456}
do_test cast-1.32 {
execsql {SELECT typeof(123.456)}
} real
do_test cast-1.33 {
execsql {SELECT CAST(123.456 AS text)}
} {123.456}
do_test cast-1.34 {
execsql {SELECT typeof(CAST(123.456 AS text))}
} text
do_test cast-1.35 {
execsql {SELECT CAST(123.456 AS numeric)}
} 123.456
do_test cast-1.36 {
execsql {SELECT typeof(CAST(123.456 AS numeric))}
} real
do_test cast-1.37 {
execsql {SELECT CAST(123.456 AS blob)}
} {123.456}
do_test cast-1.38 {
execsql {SELECT typeof(CAST(123.456 AS blob))}
} blob
do_test cast-1.39 {
execsql {SELECT CAST(123.456 AS integer)}
} {123}
do_test cast-1.38 {
execsql {SELECT typeof(CAST(123.456 AS integer))}
} integer
do_test cast-1.41 {
execsql {SELECT '123abc'}
} {123abc}
do_test cast-1.42 {
execsql {SELECT typeof('123abc')}
} text
do_test cast-1.43 {
execsql {SELECT CAST('123abc' AS text)}
} {123abc}
do_test cast-1.44 {
execsql {SELECT typeof(CAST('123abc' AS text))}
} text
do_test cast-1.45 {
execsql {SELECT CAST('123abc' AS numeric)}
} 123.0
do_test cast-1.46 {
execsql {SELECT typeof(CAST('123abc' AS numeric))}
} real
do_test cast-1.47 {
execsql {SELECT CAST('123abc' AS blob)}
} {123abc}
do_test cast-1.48 {
execsql {SELECT typeof(CAST('123abc' AS blob))}
} blob
do_test cast-1.49 {
execsql {SELECT CAST('123abc' AS integer)}
} 123
do_test cast-1.50 {
execsql {SELECT typeof(CAST('123abc' AS integer))}
} integer
do_test cast-1.51 {
execsql {SELECT CAST('123.5abc' AS numeric)}
} 123.5
do_test cast-1.53 {
execsql {SELECT CAST('123.5abc' AS integer)}
} 123
finish_test
+2 -1
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is page cache subsystem.
#
# $Id: collate3.test,v 1.10 2005/01/29 08:32:46 danielk1977 Exp $
# $Id: collate3.test,v 1.11 2005/09/08 01:58:43 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -152,6 +152,7 @@ ifcapable compound {
}
} {0 {}}
do_test collate3-2.13 {
btree_breakpoint
catchsql {
SELECT 10 UNION ALL SELECT 20 ORDER BY 1 COLLATE string_compare;
}
+7 -7
View File
@@ -12,7 +12,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is page cache subsystem.
#
# $Id: collate4.test,v 1.7 2005/01/21 03:12:16 danielk1977 Exp $
# $Id: collate4.test,v 1.8 2005/04/01 10:47:40 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -95,7 +95,7 @@ do_test collate4-1.1.5 {
} {{} A B a b nosort}
do_test collate4-1.1.6 {
cksort {SELECT b FROM collate4t1 ORDER BY b COLLATE NOCASE}
} {{} A a B b sort}
} {{} a A b B sort}
do_test collate4-1.1.7 {
execsql {
@@ -172,10 +172,10 @@ do_test collate4-1.1.21 {
} {}
do_test collate4-1.1.22 {
cksort {SELECT a FROM collate4t4 ORDER BY a}
} {{} A a B b sort}
} {{} a A b B sort}
do_test collate4-1.1.23 {
cksort {SELECT a FROM collate4t4 ORDER BY a COLLATE NOCASE}
} {{} A a B b sort}
} {{} a A b B sort}
do_test collate4-1.1.24 {
cksort {SELECT a FROM collate4t4 ORDER BY a COLLATE TEXT}
} {{} A B a b nosort}
@@ -223,7 +223,7 @@ do_test collate4-1.2.4 {
} {{} A a B b nosort}
do_test collate4-1.2.5 {
cksort {SELECT a FROM collate4t1 ORDER BY a, b COLLATE nocase}
} {{} A a B b sort}
} {{} a A b B sort}
do_test collate4-1.2.6 {
cksort {SELECT a FROM collate4t1 ORDER BY a, b COLLATE text}
} {{} A a B b nosort}
@@ -272,10 +272,10 @@ do_test collate4-1.2.14 {
} {}
do_test collate4-1.2.15 {
cksort {SELECT a FROM collate4t3 ORDER BY a}
} {{} A a B b sort}
} {{} a A b B sort}
do_test collate4-1.2.16 {
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE nocase}
} {{} A a B b sort}
} {{} a A b B sort}
do_test collate4-1.2.17 {
cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text}
} {{} A B a b nosort}
+6 -6
View File
@@ -14,7 +14,7 @@
# SELECT statements that use user-defined collation sequences. Also
# GROUP BY clauses that use user-defined collation sequences.
#
# $Id: collate5.test,v 1.3 2005/01/21 04:25:47 danielk1977 Exp $
# $Id: collate5.test,v 1.5 2005/09/07 22:48:16 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -199,7 +199,7 @@ do_test collate5-3.0 {
execsql {
SELECT a FROM collate5t1 UNION ALL SELECT a FROM collate5t2 ORDER BY 1;
}
} {A a A a B b B b N n}
} {a A a A b B b B n N}
do_test collate5-3.1 {
execsql {
SELECT a FROM collate5t2 UNION ALL SELECT a FROM collate5t1 ORDER BY 1;
@@ -252,15 +252,15 @@ do_test collate5-4.0 {
}
} {}
do_test collate5-4.1 {
execsql {
string tolower [execsql {
SELECT a, count(*) FROM collate5t1 GROUP BY a;
}
}]
} {a 2 b 2}
do_test collate5-4.2 {
execsql {
SELECT a, b, count(*) FROM collate5t1 GROUP BY a, b;
SELECT a, b, count(*) FROM collate5t1 GROUP BY a, b ORDER BY a, b;
}
} {a 1 2 b 2 1 B 3 1}
} {A 1.0 2 b 2 1 B 3 1}
do_test collate5-4.3 {
execsql {
DROP TABLE collate5t1;
+204 -98
View File
@@ -13,7 +13,7 @@
# This file implements tests for the conflict resolution extension
# to SQLite.
#
# $Id: conflict.test,v 1.22 2004/06/21 06:50:29 danielk1977 Exp $
# $Id: conflict.test,v 1.25 2005/09/01 03:07:45 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -31,40 +31,37 @@ do_test conflict-1.0 {
# 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
# t3 Number of temporary files created by this test
#
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 {} {}
foreach {i cmd t0 t1 t2 t3} {
1 INSERT 1 {} 1 0
2 {INSERT OR IGNORE} 0 3 1 0
3 {INSERT OR REPLACE} 0 4 1 0
4 REPLACE 0 4 1 0
5 {INSERT OR FAIL} 1 {} 1 0
6 {INSERT OR ABORT} 1 {} 1 0
7 {INSERT OR ROLLBACK} 1 {} {} 0
} {
if { $conf=={} } {
do_test conflict-1.$i {
if {$conf!=""} {set conf "ON CONFLICT $conf"}
set ::sqlite_opentemp_count 0
set r0 [catch {execsql [subst {
DELETE FROM t1;
DELETE FROM t2;
INSERT INTO t1 VALUES(1,2,3);
BEGIN $conf;
BEGIN;
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]
}
set r3 $::sqlite_opentemp_count
list $r0 $r1 $r2 $r3
} [list $t0 $t1 $t2 $t3]
}
# Create tables for the first group of tests.
@@ -82,28 +79,26 @@ do_test conflict-2.0 {
# 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 {} {}
foreach {i 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 {} {}
} {
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;
BEGIN;
INSERT INTO t2 VALUES(1);
$cmd INTO t1 VALUES(1,2,4);
}]} r1]
@@ -129,28 +124,26 @@ do_test conflict-3.0 {
# 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 {} {}
foreach {i 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 {} {}
} {
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;
BEGIN;
INSERT INTO t2 VALUES(1);
$cmd INTO t1 VALUES(1,2,4);
}]} r1]
@@ -173,34 +166,32 @@ do_test conflict-4.0 {
#
# 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
foreach {i conf1 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
} {
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;
BEGIN;
INSERT INTO t2 VALUES(1);
$cmd INTO t1 VALUES(1,2,4);
}]} r1]
@@ -223,39 +214,37 @@ do_test conflict-5.0 {
#
# 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 {} {}
foreach {i conf1 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 {} {}
} {
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;
BEGIN;
INSERT INTO t2 VALUES(1);
$cmd INTO t1 VALUES(1,2,NULL);
}]} r1]
@@ -284,40 +273,42 @@ do_test conflict-6.0 {
#
# 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
# t3 Number of temporary files created
#
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
foreach {i conf1 cmd t0 t1 t2 t3} {
1 {} UPDATE 1 {6 7 8 9} 1 1
2 REPLACE UPDATE 0 {7 6 9} 1 1
3 IGNORE UPDATE 0 {6 7 3 9} 1 1
4 FAIL UPDATE 1 {6 7 3 4} 1 0
5 ABORT UPDATE 1 {1 2 3 4} 1 1
6 ROLLBACK UPDATE 1 {1 2 3 4} 0 0
7 REPLACE {UPDATE OR IGNORE} 0 {6 7 3 9} 1 1
8 IGNORE {UPDATE OR REPLACE} 0 {7 6 9} 1 1
9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 1
10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 1
11 ROLLBACK {UPDATE OR IGNORE} 0 {6 7 3 9} 1 1
12 {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 1
13 {} {UPDATE OR REPLACE} 0 {7 6 9} 1 1
14 {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 0
15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 1
16 {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 0
} {
if {$t0} {set t1 {column a is not unique}}
do_test conflict-6.$i {
db close
sqlite3 db test.db
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
set ::sqlite_opentemp_count 0
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;
BEGIN;
$cmd t3 SET x=1;
$cmd t1 SET b=b*2;
$cmd t1 SET a=c+5;
@@ -325,8 +316,8 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
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]
list $r0 $r1 $r2 $::sqlite_opentemp_count
} [list $t0 $t1 $t2 $t3]
}
# Test to make sure a lot of IGNOREs don't cause a stack overflow
@@ -637,6 +628,121 @@ do_test conflict-10.2 {
execsql {SELECT * FROM t4}
} {}
integrity_check conflict-99.0
# Ticket #1171. Make sure statement rollbacks do not
# damage the database.
#
do_test conflict-11.1 {
execsql {
-- Create a database object (pages 2, 3 of the file)
BEGIN;
CREATE TABLE abc(a UNIQUE, b, c);
INSERT INTO abc VALUES(1, 2, 3);
INSERT INTO abc VALUES(4, 5, 6);
INSERT INTO abc VALUES(7, 8, 9);
COMMIT;
}
# Set a small cache size so that changes will spill into
# the database file.
execsql {
PRAGMA cache_size = 10;
}
# Make lots of changes. Because of the small cache, some
# (most?) of these changes will spill into the disk file.
# In other words, some of the changes will not be held in
# cache.
#
execsql {
BEGIN;
-- Make sure the pager is in EXCLUSIVE state.
CREATE TABLE def(d, e, f);
INSERT INTO def VALUES
('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz');
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
DELETE FROM abc WHERE a = 4;
}
# Execute a statement that does a statement rollback due to
# a constraint failure.
#
catchsql {
INSERT INTO abc SELECT 10, 20, 30 FROM def;
}
# Rollback the database. Verify that the state of the ABC table
# is unchanged from the beginning of the transaction. In other words,
# make sure the DELETE on table ABC that occurred within the transaction
# had no effect.
#
execsql {
ROLLBACK;
SELECT * FROM abc;
}
} {1 2 3 4 5 6 7 8 9}
integrity_check conflict-11.2
# Repeat test conflict-11.1 but this time commit.
#
do_test conflict-11.3 {
execsql {
BEGIN;
-- Make sure the pager is in EXCLUSIVE state.
UPDATE abc SET a=a+1;
CREATE TABLE def(d, e, f);
INSERT INTO def VALUES
('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz');
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
DELETE FROM abc WHERE a = 4;
}
catchsql {
INSERT INTO abc SELECT 10, 20, 30 FROM def;
}
execsql {
ROLLBACK;
SELECT * FROM abc;
}
} {1 2 3 4 5 6 7 8 9}
# Repeat test conflict-11.1 but this time commit.
#
do_test conflict-11.5 {
execsql {
BEGIN;
-- Make sure the pager is in EXCLUSIVE state.
CREATE TABLE def(d, e, f);
INSERT INTO def VALUES
('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz');
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
INSERT INTO def SELECT * FROM def;
DELETE FROM abc WHERE a = 4;
}
catchsql {
INSERT INTO abc SELECT 10, 20, 30 FROM def;
}
execsql {
COMMIT;
SELECT * FROM abc;
}
} {1 2 3 7 8 9}
integrity_check conflict-11.6
finish_test
+13 -13
View File
@@ -13,7 +13,7 @@
# This file implements tests to make sure SQLite does not crash or
# segfault if it sees a corrupt database file.
#
# $Id: corrupt.test,v 1.7 2005/02/05 12:48:49 danielk1977 Exp $
# $Id: corrupt.test,v 1.8 2005/02/19 08:18:06 danielk1977 Exp $
catch {file delete -force test.db}
catch {file delete -force test.db-journal}
@@ -27,18 +27,18 @@ do_test corrupt-1.1 {
execsql {
BEGIN;
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(randstr(10,100));
INSERT INTO t1 VALUES(randstr(10,100));
INSERT INTO t1 VALUES(randstr(10,100));
INSERT INTO t1 SELECT x || randstr(5,10) FROM t1;
INSERT INTO t1 SELECT x || randstr(5,10) FROM t1;
INSERT INTO t1 SELECT x || randstr(5,10) FROM t1;
INSERT INTO t1 SELECT x || randstr(5,10) FROM t1;
INSERT INTO t1 VALUES(randstr(2100,3000));
INSERT INTO t1 SELECT x || randstr(5,10) FROM t1;
INSERT INTO t1 SELECT x || randstr(5,10) FROM t1;
INSERT INTO t1 SELECT x || randstr(5,10) FROM t1;
INSERT INTO t1 SELECT x || randstr(5,10) FROM t1;
INSERT INTO t1 VALUES(randstr(100,100));
INSERT INTO t1 VALUES(randstr(90,90));
INSERT INTO t1 VALUES(randstr(80,80));
INSERT INTO t1 SELECT x || randstr(5,5) FROM t1;
INSERT INTO t1 SELECT x || randstr(6,6) FROM t1;
INSERT INTO t1 SELECT x || randstr(7,7) FROM t1;
INSERT INTO t1 SELECT x || randstr(8,8) FROM t1;
INSERT INTO t1 VALUES(randstr(3000,3000));
INSERT INTO t1 SELECT x || randstr(9,9) FROM t1;
INSERT INTO t1 SELECT x || randstr(10,10) FROM t1;
INSERT INTO t1 SELECT x || randstr(11,11) FROM t1;
INSERT INTO t1 SELECT x || randstr(12,12) FROM t1;
CREATE INDEX t1i1 ON t1(x);
CREATE TABLE t2 AS SELECT * FROM t1;
DELETE FROM t2 WHERE rowid%5!=0;
+3 -2
View File
@@ -20,7 +20,7 @@
# The special crash-test module with its os_test.c backend only works
# on Unix.
#
# $Id: crash.test,v 1.17 2005/01/20 05:24:33 danielk1977 Exp $
# $Id: crash.test,v 1.19 2005/09/17 17:05:19 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -46,6 +46,7 @@ proc crashsql {crashdelay crashfile sql} {
set f [open crash.tcl w]
puts $f "sqlite3_crashparams $crashdelay $cfile"
puts $f "set sqlite_pending_byte $::sqlite_pending_byte"
puts $f {sqlite3 db test.db}
# This block sets the cache size of the main database to 10
@@ -174,7 +175,7 @@ do_test crash-2.1 {
execsql { COMMIT }
set ::sig [signature]
execsql { SELECT sum(a), sum(b), sum(c) from abc }
} {499500.0 999000.0 1498500.0}
} {499500 999000 1498500}
do_test crash-2.2 {
expr ([file size test.db] / 1024)>16
} {1}
+6 -2
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing date and time functions.
#
# $Id: date.test,v 1.12 2005/01/15 01:52:33 drh Exp $
# $Id: date.test,v 1.13 2005/03/21 00:43:44 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -47,7 +47,11 @@ 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.0
datetest 1.18.1 {julianday('2000-01-01 12:00:00')} 2451545.0
datetest 1.18.2 {julianday('2000-01-01T12:00:00')} 2451545.0
datetest 1.18.3 {julianday('2000-01-01 T12:00:00')} 2451545.0
datetest 1.18.4 {julianday('2000-01-01T 12:00:00')} 2451545.0
datetest 1.18.4 {julianday('2000-01-01 T 12:00:00')} 2451545.0
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
+52
View File
@@ -0,0 +1,52 @@
# 2005 August 18
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this file is testing corner cases of the DEFAULT syntax
# on table definitions.
#
# $Id: default.test,v 1.2 2005/08/20 03:03:04 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable bloblit {
do_test default-1.1 {
execsql {
CREATE TABLE t1(
a INTEGER,
b BLOB DEFAULT x'6869'
);
INSERT INTO t1(a) VALUES(1);
SELECT * from t1;
}
} {1 hi}
}
do_test default-1.2 {
execsql {
CREATE TABLE t2(
x INTEGER,
y INTEGER DEFAULT NULL
);
INSERT INTO t2(x) VALUES(1);
SELECT * FROM t2;
}
} {1 {}}
do_test default-1.3 {
catchsql {
CREATE TABLE t3(
x INTEGER,
y INTEGER DEFAULT (max(x,5))
)
}
} {1 {default value of column [y] is not constant}}
finish_test
+2 -2
View File
@@ -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.18 2004/11/04 04:42:28 drh Exp $
# $Id: delete.test,v 1.19 2005/05/27 09:41:13 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -274,7 +274,7 @@ do_test delete-8.0 {
db close
catch {file attributes test.db -permissions 0444}
catch {file attributes test.db -readonly 1}
sqlite3 db test.db
set ::DB [sqlite3 db test.db]
do_test delete-8.1 {
catchsql {
DELETE FROM t3;

Some files were not shown because too many files have changed in this diff Show More