Compare commits

..

119 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
108 changed files with 5862 additions and 3079 deletions
+9 -12
View File
@@ -52,7 +52,7 @@ LIBREADLINE = @TARGET_READLINE_LIBS@
# Should the database engine be compiled threadsafe
#
OPTS += -DTHREADSAFE=@THREADSAFE@
TCC += -DTHREADSAFE=@THREADSAFE@
# The pthreads library if needed
#
@@ -195,10 +195,6 @@ TESTSRC = \
$(TOP)/src/md5.c \
$(TOP)/src/where.c
# In LIBOBJ but not TESTSRC
COMMONOBJ = $(foreach obj,$(LIBOBJ),\
$(if $(findstring $(patsubst %.lo,%.c,$(obj)),$(TESTSRC)),,$(obj)))
# Header files used by all library source files.
#
HDR = \
@@ -422,15 +418,16 @@ tclsqlite3: tclsqlite-shell.lo libsqlite3.la
$(LTLINK) -o tclsqlite3 tclsqlite-shell.lo \
libsqlite3.la $(LIBTCL)
testfixture$(TEXE): $(TOP)/src/tclsqlite.c $(TESTSRC) $(COMMONOBJ)
$(LTLINK) -DTCLSH=1 -DSQLITE_TEST=1 $(THREADSAFE) $(TEMP_STORE)\
-o testfixture \
$(TESTSRC) $(TOP)/src/tclsqlite.c $(COMMONOBJ) $(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 $(TOP)/src/os_test.c $(TESTSRC) $(COMMONOBJ)
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 $(TOP)/src/os_test.c \
$(TESTSRC) $(TOP)/src/tclsqlite.c $(COMMONOBJ) $(LIBTCL)
-o crashtest \
$(TESTSRC) $(TOP)/src/os_test.c $(TOP)/src/tclsqlite.c \
libsqlite3.la $(LIBTCL)
+1 -1
View File
@@ -1 +1 @@
3.2.4
3.2.8
+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
}
+13 -16
View File
@@ -384,12 +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 .
arch2.gif: $(TOP)/www/arch2.gif
cp $(TOP)/www/arch2.gif .
autoinc.html: $(TOP)/www/autoinc.tcl
tclsh $(TOP)/www/autoinc.tcl >autoinc.html
@@ -460,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
@@ -469,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
@@ -481,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
@@ -507,8 +504,6 @@ whentouse.html: $(TOP)/www/whentouse.tcl
#
DOC = \
arch.html \
arch.png \
arch2.gif \
autoinc.html \
c_interface.html \
capi3.html \
@@ -535,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 \
@@ -549,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
#
+107 -95
View File
@@ -1,9 +1,9 @@
C Version\s3.2.4\s(CVS\s2619)
D 2005-08-24T11:14:47
F Makefile.in b109ddb46a5550d0732dcd6caca01c123f6d5cdd
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 ecc511d6f3cf01f5fdcb1707f9aee0cbb41ea35d
F VERSION 4cef1bf020a669a809eb9ae30b049af780c5b52b
F aclocal.m4 7daea4c35e88de30d5a3f6f7a2ab99720e803bbd
F art/2005osaward.gif 0d1851b2a7c1c9d0ccce545f3e14bca42d7fd248
F art/SQLite.eps 9b43cc99cfd2be687d386faea6862ea68d6a72b2
@@ -13,14 +13,15 @@ F config.guess 2103e94b15dc57112d7b9ee152c6fac5288895b4
F config.sub 9bf686ec001ae7bc53f5b3563c90c62d4c6d48be
F configure b36e5d4156002b857e4c741626a7ac8412c2885c x
F configure.ac fe941d9e98fff7edecdaca36a730da76f397f378
F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad
F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
F main.mk c1cf11f7f14085e5686068fb4f67b6c45b677951
F main.mk 72176d7299c2fd6ca2850623195a6984f75380a6
F mkdll.sh 5ec23622515d5bf8969404e80cfb5e220ddf0512
F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d
F mkopcodeh.awk 7563ad235670e864ead95cf672be3fe081450ae0
F mkopcodeh.awk c5ed62f101d408e64bcad0a8c036d85e99905480
F mkso.sh 125868def279650a07d3f0f5e8476fecf99613fd
F publish.sh ed0aba4ffdfadb36597d03ce8efdae96efc038cb
F spec.template b2f6c4e488cbc3b993a57deba22cbc36203c4da3
@@ -29,84 +30,80 @@ F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
F sqlite3.def c413e514217736884254739a105c8c942fdf0c2f
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
F src/alter.c 26d755f2143719dd3f5b8aaf6cbe3c7f95332528
F src/analyze.c 3ab32927f4d3067ead10e4c4f6fb61b2a93479cc
F src/analyze.c 21a4cd125bedd3cb15857595c45c2a49c0556d26
F src/attach.c 4b21689700a72ae281fa85dbaff06b2a62bd49ee
F src/auth.c 31e2304bef67f44d635655f44234387ea7d21454
F src/btree.c 667227e4375d8bf6abd748cf6bad7a2004bf5d87
F src/btree.h 41a71ce027db9ddee72cb43df2316bbe3a1d92af
F src/build.c 55e7e915a538bb25b1b7448cfb9189cccba554b2
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 be1fc25c9e109cd8cbab42a43ee696263da7c04b
F src/delete.c 29dac493f4d83b05f91233b116827c133bcdab72
F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
F src/expr.c 43d49f124badc9b883cd7315c42a7564c9a59be9
F src/func.c 5b12db87f0bc7d978eaf87c7a348ada5d1934da4
F src/expr.c bb2cf5d5b065eaa23d5ae2620f6de0568768147d
F src/func.c f63d417248808ff2632a3b576536abffcc21d858
F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
F src/insert.c 484c73bc1309f283a31baa0e114f3ee980536397
F src/insert.c 1f51566d7cf4b243a2792f5fda37343d6e9377fa
F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
F src/main.c dce7e4bf2280e57de1492dec61c7310d14b5e179
F src/main.c 422014201f22aa17b96c76650163178a91a825af
F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
F src/os.h c4b34bd4d6fea51a420f337468b907f4edecb161
F src/os_common.h 0e7f428ba0a6c40a61bc56c4e96f493231301b73
F src/os_test.c 91e5f22dd89491e5e1554820e715805f43fa4ece
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
F src/os_unix.c 7fae44e25c6137340b786b83ecb29db6ba525a64
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c fe7b99cfcfb61d9bf54493ddf5857885a657fb89
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 4c6c6a553d6d23ff6a3a50df5fe53f730f3e387f
F src/pager.h 0d9153d6269d60d04af3dd84a0cc0a96253cf4a4
F src/parse.y d57cdd2adc0923762b40314f08683c836a2e0c90
F src/pragma.c 69413fbdc0c6aaa493a776ea52c1b3e6cf35dfb2
F src/prepare.c 86f0d8e744b8d956eff6bc40e29049efee017610
F src/printf.c cea584c5888688c650d856563aadc4296b5afac7
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 f441648eb191dcf1e67ae61475ea3b40a0eeb787
F src/shell.c 86c16f0d534aa51cc82cf9f66903d4eb681580e7
F src/sqlite.h.in a3b75a6b2e66865fba4ec1b698d00c7d95fe27a2
F src/sqliteInt.h e5fb91af1d607f3bc84bfb7da8534fd3298a38b0
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 e86b5483de6cb1ec1154cc5b76e3427d4b214961
F src/test1.c 6a36fa85e9d0d4f0eaa7eadd087e40ce9cf35074
F src/test2.c 792f203be69fea88668fa221321194f0a28dfdfa
F src/tclsqlite.c ac94682f9e601dd373912c46414a5a842db2089a
F src/test1.c 0f1a66f65a54fba029f7e93b7500d49443dc959b
F src/test2.c 4196848c845626e7df894470f27329e80bfe92aa
F src/test3.c f4e6a16a602091696619a1171bda25c0e3df49f7
F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5
F src/tokenize.c e1faf5637f3f4f90933785a0ecf64595f3ac3530
F src/trigger.c f51dec15921629591cb98bf2e350018e268b109a
F src/update.c a9d2c5f504212d62da1b094476f1389c0e02f83f
F src/update.c ac506fb7400158f826ec6c3a0dbe65e7ed3928d5
F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c
F src/util.c f4678297585c69811724468554393b898548e9c6
F src/util.c 55caaffbb2716f9928ab452d20f3e9cbbeab872d
F src/vacuum.c 829d9e1a6d7c094b80e0899686670932eafd768c
F src/vdbe.c 69f33e22c7d0a64b23fbb69e6da95a1bb6869032
F src/vdbe.h 3b29a9af6c7a64ed692bef1fc5f61338f40d2f67
F src/vdbeInt.h 9be9a6c43d38124bd03cc5cf05715605b1789fd9
F src/vdbeapi.c 7790e9f8da2dde29510a196d1e41ff53da7eb8a8
F src/vdbeaux.c 874624698fad54a59c6a0bcccea9d5aaa8655ab6
F src/vdbefifo.c b8805850afe13b43f1de78d58088cb5d66f88e1e
F src/vdbemem.c 4732fd4d1a75dc38549493d7f9a81d02bf7c59b5
F src/where.c 485041aa51fb33f43b346e018f7c01422847f364
F src/vdbe.c 3f1adcf4535dd35e4244d19d332fb6b515491c0d
F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
F src/vdbeInt.h 7bedbb9553a10e86b53f75d99e197f3f00a732bf
F src/vdbeapi.c 85bbe1d0243a89655433d60711b4bd71979b59cd
F src/vdbeaux.c 2b728d82cf2095386a90051b66e7faf1a143f27d
F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
F src/vdbemem.c ff426ff6e72aa3f0300a56ec8c7f18099be96b43
F src/where.c 3ed72ca029b3010a76e3a41b7b02ec1bdf849f00
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
F test/alter2.test 60ba0a7057dc71ad630a1cc7c487104346849d50
F test/alter3.test d4eecd8dbd008d0e66f1c201fa6dc2edca853c38
F test/altermalloc.test 6e1f404ec021eb2ba6582e3c77b0a35cf206b7af
F test/analyze.test a1206c7430606ffa20bcbb220c87c2873f5efdd4
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 cf2719b17659f7a011202ad05905654cedf26023
F test/autovacuum.test 9471d58a08b14dc0d2c15b87583c46d1744343d6
F test/autovacuum_crash.test 05a63b8805b20cfba7ace82856ce4ccdda075a31
F test/autovacuum_ioerr.test 9cf27275ca47b72e188a47c53b61b6d583a01d24
F test/autovacuum_ioerr2.test 2f8a3fb31f833fd0ca86ad4ad98913c73e807572
F test/between.test ca092fa28b665ca92172b182c6c360a92f7ca348
F test/bigfile.test d3744a8821ce9abb8697f2826a3e3d22b719e89f
F test/bigfile.test f768fb6078604cefb73dba0690f0115cc60e6305
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
F test/bind.test 3169339a9fb7aaa8244d0ed8651fe6b6796d809c
F test/bindxfer.test 856830e9e5552b9882c9d5c6647f90e25bdae4ac
@@ -118,33 +115,35 @@ F test/btree5.test 8e5ff32c02e685d36516c6499add9375fe1377f2
F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027
F test/btree7.test a6d3b842db22af97dd14b989e90a2fd96066b72f
F test/btree8.test fadc112bcbd6a0c622d34c813fc8a648eacf8804
F test/busy.test e355bee7d32aae35ccb3786f7a6470b73559d0f9
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/collate3.test 947a77f5b8227e037a7094d0e338a5504f155cc4
F test/collate4.test daf498e294dcd596b961d425c3f2dda117e4717e
F test/collate5.test 5a49cd169e7565e4f92b42695667d6d5db25670d
F test/collate5.test 8fb4e7e0241839356bd8710f437c32efb47bfff8
F test/collate6.test 6c9470d1606ee3e564675b229653e320c49ec638
F test/conflict.test 3e7beba8c253095330c6853c00aaf6356e84cc68
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 30ca15e608a45d868fd419c901795382efe27020
F test/default.test 252298e42a680146b1dd64f563b95bdf088d94fb
F test/delete.test 33e1670049364fc3604217a6c2eda042a47115ab
F test/delete2.test e382b6a97787197eb8b93dd4ccd37797c3725ea3
F test/diskfull.test ba27afd587af1216f92d2bb00132cbc0e39354fc
F test/delete3.test 555e84a00a99230b7d049d477a324a631126a6ab
F test/diskfull.test d828d72adfc9e2d1a194d25996718c1989152cf9
F test/distinctagg.test 2b89d1c5220d966a30ba4b40430338669301188b
F test/enc.test 7a03417a1051fe8bc6c7641cf4c8c3f7e0066d52
F test/enc2.test d1ab077b84f4d3099246915422b1ab6b81481e0a
F test/enc2.test 76c13b8c00beaf95b15c152e95dab51292eb1f0d
F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837
F test/expr.test 71b8cba7fe5c228147c93e530e098144565aaa46
F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
F test/func.test 8f9165f0454b03f35c1f35668d516a96cbf4a41b
F test/func.test 431f8e07a30aadf2a2a0c8c32f918a497bc4331d
F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda
F test/in.test cead6165aebbe0d451bb2263a307173acfeb6240
F test/index.test 51e01a0928b4b61228917ddd8c6c0e2466547f6f
@@ -160,34 +159,35 @@ F test/join.test db3802739fb695bdfa2e88805e3d64ec5ffbebd1
F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
F test/join5.test 2646825693a6e066ea89b498176d4a68df45ab68
F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19
F test/lastinsert.test eaa89c6ee1f13062d87139fd32c1e56753d2fd89
F test/laststmtchanges.test 19a6d0c11f7a31dc45465b495f7b845a62cbec17
F test/like.test b1e77e327add19ac4ddc371cbf4f208b344ab878
F test/limit.test 270b076f31c5c32f7187de5727e74da4de43e477
F test/like.test 145382e6a1f3d2edf266ca7d0236ab1b7c0ba66f
F test/limit.test 39f084f4e5f11e0b984cb517b56867cbf88df156
F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107
F test/lock2.test 59c3dd7d9b24d1bf7ec91b2d1541c37e97939d5f
F test/lock2.test d83ba79d3c4fffdb5b926c7d8ca7a36c34288a55
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
F test/main.test 249f139ef2f75710db1b49bb79e8b27767eacae1
F test/malloc.test 06d8dd2ed854693fc4e63b3e7dfd0fd8981cd628
F test/malloc.test 666c77a878ce50f5c22b9211ed43e889cabb63a6
F test/malloc2.test 655b972372d2754a3f6c6ed54d7cfd18fde9bd32
F test/memdb.test 1860e060be810bf0775bc57408a5b7c4954bcaea
F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
F test/minmax.test 9429a06f1f93acf76fcacafd17160a4392e88526
F test/misc1.test 4ca69ca2e2ef33c7a0b0fc8b324111e37a522d29
F test/minmax.test cad887abca5504396718e2cd5729ca40758743e8
F test/misc1.test c991617666991e11513e46cb646fd2e45ae68599
F test/misc2.test 5c699af2fede2694736a9f45aea7e2f052686e15
F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
F test/misc4.test edd3e3adf5b6e3b995b29843565ca58dd602f9a7
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 2323bf27fd5bd887b580247e5bce500ceee994b4
F test/pagesize.test cbc6a312b6f6c0f02619b189985df2a14164b690
F test/pragma.test 95ea907adf68459e1be6f310c9ae94d1d59c465b
F test/printf.test 4a91651d4fd5eea999eee82a9bdd0a1b797b9ad9
F test/printf.test 9e10c74e16bf889f8495ddb3d6f5f891e75ff1b7
F test/progress.test 16496001da445e6534afb94562c286708316d82f x
F test/quick.test a94d12658a2b590c1a5be580bef09bbb04c1266b
F test/quote.test c1ca5e18800455f1c882baf5b0274755a3836549
@@ -196,28 +196,33 @@ 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/select1.test 480233d4f5a81d7d59a55e40d05084d97e57ecdf
F test/select2.test f3c2678c3a9f3cf08ec4988a3845bda64be6d9e3
F test/select3.test 44dccad96a1b9940bb8c6f982d4d218dcd262760
F test/select3.test 576df1a5cc5e01dadae9176384e2d506315afdcf
F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca
F test/select5.test ae1b5ee2485c5fdc610207a391cfdc23e59c7834
F test/select6.test 6559d16ad16edb7d6864f7e74a3d204d0af72486
F test/select5.test 07a90ab3c7e3f0a241a9cdea1d997b2c8a89ff0b
F test/select6.test 21b72c56e7cbcefd063fdf9bc6c89342aedabccf
F test/select7.test 1bf795b948c133a15a2a5e99d3270e652ec58ce6
F test/sort.test 3b871d6e032f0a6c84d9f3d2d4b226e8fda97de0
F test/subquery.test 0df3de0dbb65165b96ebe895550f1549d5439856
F test/subselect.test 3f3f7a940dc3195c3139f4d530385cb54665d614
F test/table.test d0e05ede3f6e5a8b79f8661ddcc4618cf7e69f8a
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 a8d9afe680c466881a40252a86ef0fca457ab08c
F test/tclsqlite.test 2da3e4b3a79b13c1511c9d0cd995e08f8362e782
F test/temptable.test 7927261befdbc7b0a7ffebb85ecc70a74fa7b15b
F test/tester.tcl 98ecdc5723b3b2be5a8a5c3a7f38fa53031466ee
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/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 f671b922c88f70c3cd2c6f03fe7c256ae7a52fc4
F test/trigger2.test dea71f4b05e22896e72527278bc8ef71b7475bf2
F test/trigger3.test 9102fd3933db294dc654b5aee9edfe9e94f2b9e2
F test/trigger4.test 9615207f3746b1f3965113007869e45a895d2497
F test/trigger5.test 619391a3e9fc194081d22cefd830d811e7badf83
@@ -233,7 +238,7 @@ F test/vacuum.test 5d4857ae2afc9c20d0edb8acc58bdc8d630126a9
F test/vacuum2.test 5d77e98c458bcdbeecc6327de5107179ba1aa095
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
F test/view.test ce0f0ad39fa4a3572acffcf1e634850ee151aae0
F test/where.test 8fcdf3e787d16d3be2d96a94d30273a98c9bbed1
F test/where.test ce21f4910ef6a0c08f8172857baecefca20a3b0c
F test/where2.test 503e2e2b6abe14c5c10222e72d08ef84c1bf1ffb
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
F tool/lemon.c c88936c67f6411608db8fa4254d254f509fa40f6
@@ -241,7 +246,7 @@ F tool/lempar.c f0c30abcae762a7d1eb37cd88b2232ab8dd625fb
F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133
F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
F tool/memleak3.tcl 009da0ea82dc5893edca76cf1a21fb7260e9412e
F tool/mkkeywordhash.c e0b7833fef924e3c75d5e5c28fdcdb879909bdfb
F tool/mkkeywordhash.c 5263a654e5c9fd8d6e3238fb39c2d5c3126be32f
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
@@ -263,41 +268,48 @@ F www/autoinc.tcl b357f5ba954b046ee35392ce0f884a2fcfcdea06
F www/c_interface.tcl b51b08591554c16a0c3ef718364a508ac25abc7e
F www/capi3.tcl 7a7cc225fe02eb7ab861a6019b08baa0014409e1
F www/capi3ref.tcl 885f2aa112e2e9b8822753bf2972d5afd0cfeba9
F www/changes.tcl 06318d864d7667972bb2c2f47a335e6463e6989a
F www/changes.tcl 5f09e69c5498cf388b3158978664db090708ed83
F www/common.tcl de758130d54d95d151ea0d17a2ae5b92e1bb01de
F www/compile.tcl 276546d7eb445add5a867193bbd80f6919a6b084
F www/conflict.tcl cdd0f4b59b0ba6d61f67e6a38f3ae45853bacb30
F www/copyright-release.html 294e011760c439c44951a6bfecd4c81a1ae359e8
F www/copyright-release.pdf cfca3558fc97095e57c6117d08f1f5b80d95125a
F www/copyright.tcl 82c9670c7ddb0311912ab7fe24703f33c531066c
F www/datatype3.tcl 1d14f70ab73075556b95e76a5c13e5b03f7f6c47
F www/datatype3.tcl 0197a60590da421fc6516dabfa725c3d53ef90d1
F www/datatypes.tcl 7c786d2e8ff434346764534ec015966d17efce60
F www/different.tcl d01064946c588db0a0e87563a30aef1b3efb4434
F www/docs.tcl 6c0b2c567404b15bd46a0cda2dc69615a8e679a8
F www/download.tcl 57273154166d928963ad30c7076d027bb0200768
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 49f31a703f74c71ce66da646aaf18b07a5042672
F www/faq.tcl eb7fb7b7242ccfec65820f01b94d0d83956236c1
F www/fileformat.tcl 900c95b9633abc3dcfc384d9ddd8eb4876793059
F www/formatchng.tcl 053ddb73646701353a5b1c9ca6274d5900739b45
F www/index.tcl 6ab20018db082b73219e4f3bed1d72af8fd68181
F www/lang.tcl 9e27ecd2a2d3194191f820068f7bc70714178882
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 01fcaa22e6343b03acddaebe534b831f2ac71ae0
F www/omitted.tcl f1e57977299c3ed54fbae55e4b5ea6a64de39e19
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 56d29b0c14b38d61b12c17f3e3e6025a8e15c057
F www/optoverview.tcl 28b6f114a33bfd91bbe3440611ceed6090587211
F www/pragma.tcl 44f7b665ca598ad24724f35991653638a36a6e3f
F www/quickstart.tcl 6f6f694b6139be2d967b1492eb9a6bdf7058aa60
F www/speed.tcl 656ed5be8cc9d536353e1a96927b925634a62933
F www/sqlite.tcl b51fd15f0531a54874de785a9efba323eecd5975
F www/support.tcl 3955da0fd82be68cc5c83d347c05095e80967051
F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955
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 139a28d231875e72538fd6842168c458441ad1d0
R 2f6c9b894551e0a3c64b6097033bd8f9
P d8e74af5b081a074173c470e9f2115be9b095777
R 3ef1bc3892118ec529a39c9be34b97bf
U drh
Z fbfbdff77016e0ef0591035e80b41a64
Z ad60d4c3881558341fdd282b95f7c97a
+1 -1
View File
@@ -1 +1 @@
8cef2c1ae728970a38d794f9903115da5d0fcd55
e61382aed45a83ad688a0461948f9cd052a527fa
+2 -2
View File
@@ -33,8 +33,8 @@
# 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; i++){
if($i=="same" && $(i+1)=="as"){
+7 -9
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
** @(#) $Id: analyze.c,v 1.6 2005/07/23 22:59:56 drh Exp $
** @(#) $Id: analyze.c,v 1.9 2005/09/20 17:42:23 drh Exp $
*/
#ifndef SQLITE_OMIT_ANALYZE
#include "sqliteInt.h"
@@ -88,8 +88,8 @@ static void analyzeOneTable(
int addr; /* The address of an instruction */
v = sqlite3GetVdbe(pParse);
if( pTab==0 || pTab->pIndex==0 || pTab->pIndex->pNext==0 ){
/* Do no analysis for tables with fewer than 2 indices */
if( pTab==0 || pTab->pIndex==0 ){
/* Do no analysis for tables that have no indices */
return;
}
@@ -127,13 +127,11 @@ static void analyzeOneTable(
** Cells iMem through iMem+nCol are initialized to 0. The others
** are initialized to NULL.
*/
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
for(i=0; i<=nCol; i++){
sqlite3VdbeAddOp(v, OP_MemStore, iMem+i, i==nCol);
sqlite3VdbeAddOp(v, OP_MemInt, 0, iMem+i);
}
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
for(i=0; i<nCol; i++){
sqlite3VdbeAddOp(v, OP_MemStore, iMem+nCol+i+1, i==nCol-1);
sqlite3VdbeAddOp(v, OP_MemNull, iMem+nCol+i+1, 0);
}
/* Do the analysis.
@@ -198,7 +196,7 @@ static void analyzeOneTable(
}
sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "ttt", 0);
sqlite3VdbeAddOp(v, OP_Insert, iStatCur, 0);
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, addr);
}
}
@@ -333,7 +331,7 @@ static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){
const char *z;
assert( argc==2 );
if( argv[0]==0 || argv[1]==0 ){
if( argv==0 || argv[0]==0 || argv[1]==0 ){
return 0;
}
pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase);
+38 -31
View File
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.264 2005/08/02 17:13:10 drh Exp $
** $Id: btree.c,v 1.269 2005/09/17 15:20:27 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@@ -494,7 +494,7 @@ static int ptrmapPut(Btree *pBt, Pgno key, u8 eType, Pgno parent){
assert( pBt->autoVacuum );
if( key==0 ){
return SQLITE_CORRUPT;
return SQLITE_CORRUPT_BKPT;
}
iPtrmap = PTRMAP_PAGENO(pBt->usableSize, key);
rc = sqlite3pager_get(pBt->pPager, iPtrmap, (void **)&pPtrmap);
@@ -540,7 +540,7 @@ static int ptrmapGet(Btree *pBt, Pgno key, u8 *pEType, Pgno *pPgno){
if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]);
sqlite3pager_unref(pPtrmap);
if( *pEType<1 || *pEType>5 ) return SQLITE_CORRUPT;
if( *pEType<1 || *pEType>5 ) return SQLITE_CORRUPT_BKPT;
return SQLITE_OK;
}
@@ -1030,7 +1030,7 @@ static int initPage(
assert( pPage->aData == &((unsigned char*)pPage)[-pBt->pageSize] );
if( pPage->pParent!=pParent && (pPage->pParent!=0 || pPage->isInit) ){
/* The parent page should never change unless the file is corrupt */
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
}
if( pPage->isInit ) return SQLITE_OK;
if( pPage->pParent==0 && pParent!=0 ){
@@ -1048,11 +1048,11 @@ static int initPage(
pPage->nCell = get2byte(&data[hdr+3]);
if( pPage->nCell>MX_CELL(pBt) ){
/* To many cells for a single page. The page must be corrupt */
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
}
if( pPage->nCell==0 && pParent!=0 && pParent->pgno!=1 ){
/* All pages must have at least one cell, except for root pages */
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
}
/* Compute the total free space on the page */
@@ -1062,13 +1062,13 @@ static int initPage(
int next, size;
if( pc>usableSize-4 ){
/* Free block is off the page */
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
}
next = get2byte(&data[pc]);
size = get2byte(&data[pc+2]);
if( next>0 && next<=pc+size+3 ){
/* Free blocks must be in accending order */
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
}
nFree += size;
pc = next;
@@ -1076,7 +1076,7 @@ static int initPage(
pPage->nFree = nFree;
if( nFree>=usableSize ){
/* Free space cannot exceed total page size */
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
}
pPage->isInit = 1;
@@ -1146,7 +1146,7 @@ static int getAndInitPage(
){
int rc;
if( pgno==0 ){
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
}
rc = getPage(pBt, pgno, ppPage);
if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){
@@ -1345,6 +1345,15 @@ int sqlite3BtreeSetSafetyLevel(Btree *pBt, int level){
}
#endif
/*
** Return TRUE if the given btree is set to safety level 1. In other
** words, return TRUE if no sync() occurs on the disk files.
*/
int sqlite3BtreeSyncDisabled(Btree *pBt){
assert( pBt && pBt->pPager );
return sqlite3pager_nosync(pBt->pPager);
}
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM)
/*
** Change the default pages size and the number of reserved bytes per page.
@@ -1705,7 +1714,7 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){
if( eType==PTRMAP_OVERFLOW2 ){
/* The pointer is always the first 4 bytes of the page in this case. */
if( get4byte(pPage->aData)!=iFrom ){
return SQLITE_CORRUPT;
return SQLITE_CORRUPT_BKPT;
}
put4byte(pPage->aData, iTo);
}else{
@@ -1738,7 +1747,7 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){
if( i==nCell ){
if( eType!=PTRMAP_BTREE ||
get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
return SQLITE_CORRUPT;
return SQLITE_CORRUPT_BKPT;
}
put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
}
@@ -1851,7 +1860,7 @@ static int autoVacuumCommit(Btree *pBt, Pgno *nTrunc){
assert( pBt->autoVacuum );
if( PTRMAP_ISPAGE(pgsz, sqlite3pager_pagecount(pPager)) ){
return SQLITE_CORRUPT;
return SQLITE_CORRUPT_BKPT;
}
/* Figure out how many free-pages are in the database. If there are no
@@ -1866,7 +1875,7 @@ static int autoVacuumCommit(Btree *pBt, Pgno *nTrunc){
origSize = sqlite3pager_pagecount(pPager);
nPtrMap = (nFreeList-origSize+PTRMAP_PAGENO(pgsz, origSize)+pgsz/5)/(pgsz/5);
finSize = origSize - nFreeList - nPtrMap;
if( origSize>PENDING_BYTE_PAGE(pBt) && finSize<=PENDING_BYTE_PAGE(pBt) ){
if( origSize>=PENDING_BYTE_PAGE(pBt) && finSize<=PENDING_BYTE_PAGE(pBt) ){
finSize--;
if( PTRMAP_ISPAGE(pBt->usableSize, finSize) ){
finSize--;
@@ -1889,7 +1898,7 @@ static int autoVacuumCommit(Btree *pBt, Pgno *nTrunc){
rc = ptrmapGet(pBt, iDbPage, &eType, &iPtrPage);
if( rc!=SQLITE_OK ) goto autovacuum_out;
if( eType==PTRMAP_ROOTPAGE ){
rc = SQLITE_CORRUPT;
rc = SQLITE_CORRUPT_BKPT;
goto autovacuum_out;
}
@@ -2405,7 +2414,7 @@ static int getPayload(
}
if( amt>0 ){
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
}
return SQLITE_OK;
}
@@ -2423,7 +2432,7 @@ int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
assert( pCur->isValid );
assert( pCur->pPage!=0 );
if( pCur->pPage->intKey ){
return SQLITE_CORRUPT;
return SQLITE_CORRUPT_BKPT;
}
assert( pCur->pPage->intKey==0 );
assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell );
@@ -2472,13 +2481,11 @@ static const unsigned char *fetchPayload(
){
unsigned char *aPayload;
MemPage *pPage;
Btree *pBt;
u32 nKey;
int nLocal;
assert( pCur!=0 && pCur->pPage!=0 );
assert( pCur->isValid );
pBt = pCur->pBt;
pPage = pCur->pPage;
pageIntegrity(pPage);
assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
@@ -2545,7 +2552,7 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){
pCur->idx = 0;
pCur->info.nSize = 0;
if( pNewPage->nCell<1 ){
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
}
return SQLITE_OK;
}
@@ -2576,7 +2583,6 @@ static int isRootPage(MemPage *pPage){
** the largest cell index.
*/
static void moveToParent(BtCursor *pCur){
Pgno oldPgno;
MemPage *pParent;
MemPage *pPage;
int idxParent;
@@ -2591,7 +2597,6 @@ static void moveToParent(BtCursor *pCur){
pageIntegrity(pParent);
idxParent = pPage->idxParent;
sqlite3pager_ref(pParent->aData);
oldPgno = pPage->pgno;
releasePage(pPage);
pCur->pPage = pParent;
pCur->info.nSize = 0;
@@ -2756,7 +2761,7 @@ int sqlite3BtreeMoveto(BtCursor *pCur, const void *pKey, i64 nKey, int *pRes){
lwr = 0;
upr = pPage->nCell-1;
if( !pPage->intKey && pKey==0 ){
return SQLITE_CORRUPT;
return SQLITE_CORRUPT_BKPT;
}
pageIntegrity(pPage);
while( lwr<=upr ){
@@ -3041,7 +3046,7 @@ static int allocatePage(
TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1));
}else if( k>pBt->usableSize/4 - 8 ){
/* Value of k is out of range. Database corruption */
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
#ifndef SQLITE_OMIT_AUTOVACUUM
}else if( searchList && nearby==iTrunk ){
/* The list is being searched and this trunk page is the page
@@ -3116,7 +3121,7 @@ static int allocatePage(
*pPgno = iPage;
if( *pPgno>sqlite3pager_pagecount(pBt->pPager) ){
/* Free page off the end of the file */
return SQLITE_CORRUPT; /* bkpt-CORRUPT */
return SQLITE_CORRUPT_BKPT;
}
TRACE(("ALLOCATE: %d was leaf %d of %d on trunk %d"
": %d more free pages\n",
@@ -3257,7 +3262,7 @@ static int clearCell(MemPage *pPage, unsigned char *pCell){
while( ovflPgno!=0 ){
MemPage *pOvfl;
if( ovflPgno>sqlite3pager_pagecount(pBt->pPager) ){
return SQLITE_CORRUPT;
return SQLITE_CORRUPT_BKPT;
}
rc = getPage(pBt, ovflPgno, &pOvfl);
if( rc ) return rc;
@@ -4663,7 +4668,7 @@ int sqlite3BtreeDelete(BtCursor *pCur){
rc = sqlite3BtreeNext(&leafCur, &notUsed);
if( rc!=SQLITE_OK ){
if( rc!=SQLITE_NOMEM ){
rc = SQLITE_CORRUPT; /* bkpt-CORRUPT */
rc = SQLITE_CORRUPT_BKPT;
}
}
if( rc==SQLITE_OK ){
@@ -4849,7 +4854,7 @@ static int clearDatabasePage(
int i;
if( pgno>sqlite3pager_pagecount(pBt->pPager) ){
return SQLITE_CORRUPT;
return SQLITE_CORRUPT_BKPT;
}
rc = getAndInitPage(pBt, pgno, &pPage, pParent);
@@ -5471,7 +5476,7 @@ static int checkTreePage(
u8 *data;
BtCursor cur;
Btree *pBt;
int maxLocal, usableSize;
int usableSize;
char zContext[100];
char *hit;
@@ -5488,7 +5493,6 @@ static int checkTreePage(
"unable to get the page. error code=%d", rc);
return 0;
}
maxLocal = pPage->leafData ? pBt->maxLeaf : pBt->maxLocal;
if( (rc = initPage(pPage, pParent))!=0 ){
checkAppendMsg(pCheck, zContext, "initPage() returns error code %d", rc);
releasePage(pPage);
@@ -5735,7 +5739,7 @@ const char *sqlite3BtreeGetJournalname(Btree *pBt){
*/
int sqlite3BtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){
int rc = SQLITE_OK;
Pgno i, nPage, nToPage;
Pgno i, nPage, nToPage, iSkip;
if( pBtTo->inTrans!=TRANS_WRITE || pBtFrom->inTrans!=TRANS_WRITE ){
return SQLITE_ERROR;
@@ -5743,8 +5747,10 @@ int sqlite3BtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){
if( pBtTo->pCursor ) return SQLITE_BUSY;
nToPage = sqlite3pager_pagecount(pBtTo->pPager);
nPage = sqlite3pager_pagecount(pBtFrom->pPager);
iSkip = PENDING_BYTE_PAGE(pBtTo);
for(i=1; rc==SQLITE_OK && i<=nPage; i++){
void *pPage;
if( i==iSkip ) continue;
rc = sqlite3pager_get(pBtFrom->pPager, i, &pPage);
if( rc ) break;
rc = sqlite3pager_overwrite(pBtTo->pPager, i, pPage);
@@ -5753,6 +5759,7 @@ int sqlite3BtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){
}
for(i=nPage+1; rc==SQLITE_OK && i<=nToPage; i++){
void *pPage;
if( i==iSkip ) continue;
rc = sqlite3pager_get(pBtTo->pPager, i, &pPage);
if( rc ) break;
rc = sqlite3pager_write(pPage);
+2 -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.63 2005/03/21 04:04:03 danielk1977 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*);
+63 -29
View File
@@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
** $Id: build.c,v 1.342 2005/08/20 03:03:04 drh Exp $
** $Id: build.c,v 1.351 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -76,7 +76,7 @@ void sqlite3FinishCoding(Parse *pParse){
if( pParse->cookieGoto>0 ){
u32 mask;
int iDb;
sqlite3VdbeChangeP2(v, pParse->cookieGoto-1, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
if( (mask & pParse->cookieMask)==0 ) continue;
sqlite3VdbeAddOp(v, OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
@@ -85,6 +85,7 @@ void sqlite3FinishCoding(Parse *pParse){
sqlite3VdbeAddOp(v, OP_Goto, 0, pParse->cookieGoto);
}
#ifndef SQLITE_OMIT_TRACE
/* Add a No-op that contains the complete text of the compiled SQL
** statement as its P3 argument. This does not change the functionality
** of the program.
@@ -92,6 +93,7 @@ void sqlite3FinishCoding(Parse *pParse){
** This is used to implement sqlite3_trace().
*/
sqlite3VdbeOp3(v, OP_Noop, 0, 0, pParse->zSql, pParse->zTail-pParse->zSql);
#endif /* SQLITE_OMIT_TRACE */
}
@@ -101,7 +103,7 @@ void sqlite3FinishCoding(Parse *pParse){
FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
sqlite3VdbeTrace(v, trace);
sqlite3VdbeMakeReady(v, pParse->nVar, pParse->nMem+3,
pParse->nTab+3, pParse->nMaxDepth+1, pParse->explain);
pParse->nTab+3, pParse->explain);
pParse->rc = SQLITE_DONE;
pParse->colNamesSet = 0;
}else if( pParse->rc==SQLITE_OK ){
@@ -130,7 +132,6 @@ void sqlite3FinishCoding(Parse *pParse){
void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
va_list ap;
char *zSql;
int rc;
# define SAVE_SZ (sizeof(Parse) - offsetof(Parse,nVar))
char saveBuf[SAVE_SZ];
@@ -145,7 +146,7 @@ void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
pParse->nested++;
memcpy(saveBuf, &pParse->nVar, SAVE_SZ);
memset(&pParse->nVar, 0, SAVE_SZ);
rc = sqlite3RunParser(pParse, zSql, 0);
sqlite3RunParser(pParse, zSql, 0);
sqliteFree(zSql);
memcpy(&pParse->nVar, saveBuf, SAVE_SZ);
pParse->nested--;
@@ -634,7 +635,6 @@ void sqlite3StartTable(
int isView /* True if this is a VIEW */
){
Table *pTable;
Index *pIdx;
char *zName = 0; /* The name of the new table */
sqlite3 *db = pParse->db;
Vdbe *v;
@@ -713,8 +713,7 @@ void sqlite3StartTable(
sqlite3ErrorMsg(pParse, "table %T already exists", pName);
goto begin_table_error;
}
if( (pIdx = sqlite3FindIndex(db, zName, 0))!=0 &&
( iDb==0 || !db->init.busy) ){
if( sqlite3FindIndex(db, zName, 0)!=0 && (iDb==0 || !db->init.busy) ){
sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
goto begin_table_error;
}
@@ -941,7 +940,7 @@ void sqlite3AddColumnType(Parse *pParse, Token *pType){
i = p->nCol-1;
if( i<0 ) return;
pCol = &p->aCol[i];
assert( pCol->zType==0 );
sqliteFree(pCol->zType);
pCol->zType = sqlite3NameFromToken(pType);
pCol->affinity = sqlite3AffinityType(pType);
}
@@ -1016,7 +1015,9 @@ void sqlite3AddPrimaryKey(
break;
}
}
if( iCol<pTab->nCol ) pTab->aCol[iCol].isPrimKey = 1;
if( iCol<pTab->nCol ){
pTab->aCol[iCol].isPrimKey = 1;
}
}
if( pList->nExpr>1 ) iCol = -1;
}
@@ -2001,7 +2002,7 @@ static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
}
sqlite3VdbeAddOp(v, OP_IdxInsert, iIdx, 0);
sqlite3VdbeAddOp(v, OP_Next, iTab, addr1+1);
sqlite3VdbeChangeP2(v, addr1, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, addr1);
sqlite3VdbeAddOp(v, OP_Close, iTab, 0);
sqlite3VdbeAddOp(v, OP_Close, iIdx, 0);
}
@@ -2114,14 +2115,12 @@ void sqlite3CreateIndex(
goto exit_create_index;
}
if( !db->init.busy ){
Index *pISameName; /* Another index with the same name */
Table *pTSameName; /* A table with same name as the index */
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index;
if( (pISameName = sqlite3FindIndex(db, zName, db->aDb[iDb].zName))!=0 ){
if( sqlite3FindIndex(db, zName, db->aDb[iDb].zName)!=0 ){
sqlite3ErrorMsg(pParse, "index %s already exists", zName);
goto exit_create_index;
}
if( (pTSameName = sqlite3FindTable(db, zName, 0))!=0 ){
if( sqlite3FindTable(db, zName, 0)!=0 ){
sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
goto exit_create_index;
}
@@ -2171,7 +2170,7 @@ void sqlite3CreateIndex(
(sizeof(int)*2 + sizeof(CollSeq*))*pList->nExpr );
if( sqlite3_malloc_failed ) goto exit_create_index;
pIndex->aiColumn = (int*)&pIndex->keyInfo.aColl[pList->nExpr];
pIndex->aiRowEst = &pIndex->aiColumn[pList->nExpr];
pIndex->aiRowEst = (unsigned*)&pIndex->aiColumn[pList->nExpr];
pIndex->zName = (char*)&pIndex->aiRowEst[pList->nExpr+1];
strcpy(pIndex->zName, zName);
pIndex->pTable = pTab;
@@ -2394,7 +2393,7 @@ exit_create_index:
** are based on typical values found in actual indices.
*/
void sqlite3DefaultRowEst(Index *pIdx){
int *a = pIdx->aiRowEst;
unsigned *a = pIdx->aiRowEst;
int i;
assert( a!=0 );
a[0] = 1000000;
@@ -2467,6 +2466,47 @@ exit_drop_index:
sqlite3SrcListDelete(pName);
}
/*
** ppArray points into a structure where there is an array pointer
** followed by two integers. The first integer is the
** number of elements in the structure array. The second integer
** is the number of allocated slots in the array.
**
** In other words, the structure looks something like this:
**
** struct Example1 {
** struct subElem *aEntry;
** int nEntry;
** int nAlloc;
** }
**
** The pnEntry parameter points to the equivalent of Example1.nEntry.
**
** This routine allocates a new slot in the array, zeros it out,
** and returns its index. If malloc fails a negative number is returned.
**
** szEntry is the sizeof of a single array entry. initSize is the
** number of array entries allocated on the initial allocation.
*/
int sqlite3ArrayAllocate(void **ppArray, int szEntry, int initSize){
char *p;
int *an = (int*)&ppArray[1];
if( an[0]>=an[1] ){
void *pNew;
int newSize;
newSize = an[1]*2 + initSize;
pNew = sqliteRealloc(*ppArray, newSize*szEntry);
if( pNew==0 ){
return -1;
}
an[1] = newSize;
*ppArray = pNew;
}
p = *ppArray;
memset(&p[an[0]*szEntry], 0, szEntry);
return an[0]++;
}
/*
** Append a new element to the given IdList. Create a new IdList if
** need be.
@@ -2474,24 +2514,18 @@ exit_drop_index:
** A new IdList is returned, or NULL if malloc() fails.
*/
IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){
int i;
if( pList==0 ){
pList = sqliteMalloc( sizeof(IdList) );
if( pList==0 ) return 0;
pList->nAlloc = 0;
}
if( pList->nId>=pList->nAlloc ){
struct IdList_item *a;
pList->nAlloc = pList->nAlloc*2 + 5;
a = sqliteRealloc(pList->a, pList->nAlloc*sizeof(pList->a[0]) );
if( a==0 ){
sqlite3IdListDelete(pList);
return 0;
}
pList->a = a;
i = sqlite3ArrayAllocate((void**)&pList->a, sizeof(pList->a[0]), 5);
if( i<0 ){
sqlite3IdListDelete(pList);
return 0;
}
memset(&pList->a[pList->nId], 0, sizeof(pList->a[0]));
pList->a[pList->nId].zName = sqlite3NameFromToken(pToken);
pList->nId++;
pList->a[i].zName = sqlite3NameFromToken(pToken);
return pList;
}
+5 -5
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.109 2005/07/21 18:23:20 drh Exp $
** $Id: delete.c,v 1.111 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
@@ -178,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);
}
@@ -380,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);
}
/*
+181 -73
View File
@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.219 2005/08/23 11:17:59 drh Exp $
** $Id: expr.c,v 1.230 2005/09/23 21:11:54 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -355,7 +355,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
pExpr->iTable = ++pParse->nVar;
if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){
pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10;
pParse->apVarExpr = sqliteRealloc(pParse->apVarExpr,
sqlite3ReallocOrFree((void**)&pParse->apVarExpr,
pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) );
}
if( !sqlite3_malloc_failed ){
@@ -546,9 +546,14 @@ Select *sqlite3SelectDup(Select *p){
pNew->pOffset = sqlite3ExprDup(p->pOffset);
pNew->iLimit = -1;
pNew->iOffset = -1;
pNew->ppOpenVirtual = 0;
pNew->isResolved = p->isResolved;
pNew->isAgg = p->isAgg;
pNew->usesVirt = 0;
pNew->disallowOrderBy = 0;
pNew->pRightmost = 0;
pNew->addrOpenVirt[0] = -1;
pNew->addrOpenVirt[1] = -1;
pNew->addrOpenVirt[2] = -1;
return pNew;
}
#else
@@ -624,6 +629,8 @@ void sqlite3ExprListDelete(ExprList *pList){
**
** The return value from this routine is 1 to abandon the tree walk
** and 0 to continue.
**
** NOTICE: This routine does *not* descend into subqueries.
*/
static int walkExprList(ExprList *, int (*)(void *, Expr*), void *);
static int walkExprTree(Expr *pExpr, int (*xFunc)(void*,Expr*), void *pArg){
@@ -690,12 +697,18 @@ static int exprNodeIsConstant(void *pArg, Expr *pExpr){
case TK_COLUMN:
case TK_DOT:
case TK_AGG_FUNCTION:
case TK_AGG_COLUMN:
#ifndef SQLITE_OMIT_SUBQUERY
case TK_SELECT:
case TK_EXISTS:
#endif
*((int*)pArg) = 0;
return 2;
case TK_IN:
if( pExpr->pSelect ){
*((int*)pArg) = 0;
return 2;
}
default:
return 0;
}
@@ -1220,11 +1233,19 @@ int sqlite3ExprResolveNames(
NameContext *pNC, /* Namespace to resolve expressions in. */
Expr *pExpr /* The expression to be analyzed. */
){
int savedHasAgg;
if( pExpr==0 ) return 0;
savedHasAgg = pNC->hasAgg;
pNC->hasAgg = 0;
walkExprTree(pExpr, nameResolverStep, pNC);
if( pNC->nErr>0 ){
ExprSetProperty(pExpr, EP_Error);
}
if( pNC->hasAgg ){
ExprSetProperty(pExpr, EP_Agg);
}else if( savedHasAgg ){
pNC->hasAgg = 1;
}
return ExprHasProperty(pExpr, EP_Error);
}
@@ -1272,13 +1293,8 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
int mem = pParse->nMem++;
sqlite3VdbeAddOp(v, OP_MemLoad, mem, 0);
testAddr = sqlite3VdbeAddOp(v, OP_If, 0, 0);
assert( testAddr>0 );
sqlite3VdbeAddOp(v, OP_Integer, 1, 0);
sqlite3VdbeAddOp(v, OP_MemStore, mem, 1);
}
if( pExpr->pSelect ){
sqlite3VdbeAddOp(v, OP_AggContextPush, 0, 0);
assert( testAddr>0 || sqlite3_malloc_failed );
sqlite3VdbeAddOp(v, OP_MemInt, 1, mem);
}
switch( pExpr->op ){
@@ -1352,7 +1368,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
if( testAddr>0 && !sqlite3ExprIsConstant(pE2) ){
VdbeOp *aOp = sqlite3VdbeGetOp(v, testAddr-1);
int i;
for(i=0; i<4; i++){
for(i=0; i<3; i++){
aOp[i].opcode = OP_Noop;
}
testAddr = 0;
@@ -1393,11 +1409,8 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
}
}
if( pExpr->pSelect ){
sqlite3VdbeAddOp(v, OP_AggContextPop, 0, 0);
}
if( testAddr ){
sqlite3VdbeChangeP2(v, testAddr, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, testAddr);
}
return;
}
@@ -1438,10 +1451,21 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
}
op = pExpr->op;
switch( op ){
case TK_AGG_COLUMN: {
AggInfo *pAggInfo = pExpr->pAggInfo;
struct AggInfo_col *pCol = &pAggInfo->aCol[pExpr->iAgg];
if( !pAggInfo->directMode ){
sqlite3VdbeAddOp(v, OP_MemLoad, pCol->iMem, 0);
break;
}else if( pAggInfo->useSortingIdx ){
sqlite3VdbeAddOp(v, OP_Column, pAggInfo->sortingIdx,
pCol->iSorterColumn);
break;
}
/* Otherwise, fall thru into the TK_COLUMN case */
}
case TK_COLUMN: {
if( !pParse->fillAgg && pExpr->iAgg>=0 ){
sqlite3VdbeAddOp(v, OP_AggGet, pExpr->iAggCtx, pExpr->iAgg);
}else if( pExpr->iColumn>=0 ){
if( pExpr->iColumn>=0 ){
sqlite3VdbeAddOp(v, OP_Column, pExpr->iTable, pExpr->iColumn);
sqlite3ColumnDefault(v, pExpr->pTab, pExpr->iColumn);
}else{
@@ -1590,7 +1614,8 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
break;
}
case TK_AGG_FUNCTION: {
sqlite3VdbeAddOp(v, OP_AggGet, 0, pExpr->iAgg);
AggInfo *pInfo = pExpr->pAggInfo;
sqlite3VdbeAddOp(v, OP_MemLoad, pInfo->aFunc[pExpr->iAgg].iMem, 0);
break;
}
case TK_CONST_FUNC:
@@ -1600,7 +1625,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
FuncDef *pDef;
int nId;
const char *zId;
int p2 = 0;
int constMask = 0;
int i;
u8 enc = pParse->db->enc;
CollSeq *pColl = 0;
@@ -1611,7 +1636,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
nExpr = sqlite3ExprCodeExprList(pParse, pList);
for(i=0; i<nExpr && i<32; i++){
if( sqlite3ExprIsConstant(pList->a[i].pExpr) ){
p2 |= (1<<i);
constMask |= (1<<i);
}
if( pDef->needCollSeq && !pColl ){
pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
@@ -1621,7 +1646,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
if( !pColl ) pColl = pParse->db->pDfltColl;
sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ);
}
sqlite3VdbeOp3(v, OP_Function, nExpr, p2, (char*)pDef, P3_FUNCDEF);
sqlite3VdbeOp3(v, OP_Function, constMask, nExpr, (char*)pDef, P3_FUNCDEF);
break;
}
#ifndef SQLITE_OMIT_SUBQUERY
@@ -1685,7 +1710,6 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
case TK_CASE: {
int expr_end_label;
int jumpInst;
int addr;
int nExpr;
int i;
ExprList *pEList;
@@ -1713,8 +1737,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
}
sqlite3ExprCode(pParse, aListelem[i+1].pExpr);
sqlite3VdbeAddOp(v, OP_Goto, 0, expr_end_label);
addr = sqlite3VdbeCurrentAddr(v);
sqlite3VdbeChangeP2(v, jumpInst, addr);
sqlite3VdbeJumpHere(v, jumpInst);
}
if( pExpr->pLeft ){
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
@@ -1741,7 +1764,6 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
sqlite3DequoteExpr(pExpr);
sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn,
pExpr->token.z, pExpr->token.n);
// sqlite3VdbeDequoteP3(v, -1);
} else {
assert( pExpr->iColumn == OE_Ignore );
sqlite3VdbeAddOp(v, OP_ContextPop, 0, 0);
@@ -1882,7 +1904,7 @@ void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
codeCompare(pParse, pLeft, pRight, OP_Le, dest, jumpIfNull);
sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, addr);
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
break;
}
@@ -2015,6 +2037,7 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB){
return 0;
}
if( pA->op!=pB->op ) return 0;
if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 0;
if( !sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 0;
if( !sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 0;
if( pA->pList ){
@@ -2038,23 +2061,32 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB){
return 1;
}
/*
** Add a new element to the pParse->aAgg[] array and return its index.
** The new element is initialized to zero. The calling function is
** expected to fill it in.
** Add a new element to the pAggInfo->aCol[] array. Return the index of
** the new element. Return a negative number if malloc fails.
*/
static int appendAggInfo(Parse *pParse){
if( (pParse->nAgg & 0x7)==0 ){
int amt = pParse->nAgg + 8;
AggExpr *aAgg = sqliteRealloc(pParse->aAgg, amt*sizeof(pParse->aAgg[0]));
if( aAgg==0 ){
return -1;
}
pParse->aAgg = aAgg;
static int addAggInfoColumn(AggInfo *pInfo){
int i;
i = sqlite3ArrayAllocate((void**)&pInfo->aCol, sizeof(pInfo->aCol[0]), 3);
if( i<0 ){
return -1;
}
memset(&pParse->aAgg[pParse->nAgg], 0, sizeof(pParse->aAgg[0]));
return pParse->nAgg++;
}
return i;
}
/*
** Add a new element to the pAggInfo->aFunc[] array. Return the index of
** the new element. Return a negative number if malloc fails.
*/
static int addAggInfoFunc(AggInfo *pInfo){
int i;
i = sqlite3ArrayAllocate((void**)&pInfo->aFunc, sizeof(pInfo->aFunc[0]), 2);
if( i<0 ){
return -1;
}
return i;
}
/*
** This is an xFunc for walkExprTree() used to implement
@@ -2065,60 +2097,118 @@ static int appendAggInfo(Parse *pParse){
*/
static int analyzeAggregate(void *pArg, Expr *pExpr){
int i;
AggExpr *aAgg;
NameContext *pNC = (NameContext *)pArg;
Parse *pParse = pNC->pParse;
SrcList *pSrcList = pNC->pSrcList;
AggInfo *pAggInfo = pNC->pAggInfo;
switch( pExpr->op ){
case TK_COLUMN: {
for(i=0; pSrcList && i<pSrcList->nSrc; i++){
if( pExpr->iTable==pSrcList->a[i].iCursor ){
aAgg = pParse->aAgg;
for(i=0; i<pParse->nAgg; i++){
if( aAgg[i].isAgg ) continue;
if( aAgg[i].pExpr->iTable==pExpr->iTable
&& aAgg[i].pExpr->iColumn==pExpr->iColumn ){
break;
/* Check to see if the column is in one of the tables in the FROM
** clause of the aggregate query */
if( pSrcList ){
struct SrcList_item *pItem = pSrcList->a;
for(i=0; i<pSrcList->nSrc; i++, pItem++){
struct AggInfo_col *pCol;
if( pExpr->iTable==pItem->iCursor ){
/* If we reach this point, it means that pExpr refers to a table
** that is in the FROM clause of the aggregate query.
**
** Make an entry for the column in pAggInfo->aCol[] if there
** is not an entry there already.
*/
pCol = pAggInfo->aCol;
for(i=0; i<pAggInfo->nColumn; i++, pCol++){
if( pCol->iTable==pExpr->iTable &&
pCol->iColumn==pExpr->iColumn ){
break;
}
}
}
if( i>=pParse->nAgg ){
i = appendAggInfo(pParse);
if( i<0 ) return 1;
pParse->aAgg[i].isAgg = 0;
pParse->aAgg[i].pExpr = pExpr;
}
pExpr->iAgg = i;
pExpr->iAggCtx = pNC->nDepth;
return 1;
}
if( i>=pAggInfo->nColumn && (i = addAggInfoColumn(pAggInfo))>=0 ){
pCol = &pAggInfo->aCol[i];
pCol->iTable = pExpr->iTable;
pCol->iColumn = pExpr->iColumn;
pCol->iMem = pParse->nMem++;
pCol->iSorterColumn = -1;
pCol->pExpr = pExpr;
if( pAggInfo->pGroupBy ){
int j, n;
ExprList *pGB = pAggInfo->pGroupBy;
struct ExprList_item *pTerm = pGB->a;
n = pGB->nExpr;
for(j=0; j<n; j++, pTerm++){
Expr *pE = pTerm->pExpr;
if( pE->op==TK_COLUMN && pE->iTable==pExpr->iTable &&
pE->iColumn==pExpr->iColumn ){
pCol->iSorterColumn = j;
break;
}
}
}
if( pCol->iSorterColumn<0 ){
pCol->iSorterColumn = pAggInfo->nSortingColumn++;
}
}
/* There is now an entry for pExpr in pAggInfo->aCol[] (either
** because it was there before or because we just created it).
** Convert the pExpr to be a TK_AGG_COLUMN referring to that
** pAggInfo->aCol[] entry.
*/
pExpr->pAggInfo = pAggInfo;
pExpr->op = TK_AGG_COLUMN;
pExpr->iAgg = i;
break;
} /* endif pExpr->iTable==pItem->iCursor */
} /* end loop over pSrcList */
}
return 1;
}
case TK_AGG_FUNCTION: {
/* The pNC->nDepth==0 test causes aggregate functions in subqueries
** to be ignored */
if( pNC->nDepth==0 ){
aAgg = pParse->aAgg;
for(i=0; i<pParse->nAgg; i++){
if( !aAgg[i].isAgg ) continue;
if( sqlite3ExprCompare(aAgg[i].pExpr, pExpr) ){
/* Check to see if pExpr is a duplicate of another aggregate
** function that is already in the pAggInfo structure
*/
struct AggInfo_func *pItem = pAggInfo->aFunc;
for(i=0; i<pAggInfo->nFunc; i++, pItem++){
if( sqlite3ExprCompare(pItem->pExpr, pExpr) ){
break;
}
}
if( i>=pParse->nAgg ){
if( i>=pAggInfo->nFunc ){
/* pExpr is original. Make a new entry in pAggInfo->aFunc[]
*/
u8 enc = pParse->db->enc;
i = appendAggInfo(pParse);
if( i<0 ) return 1;
pParse->aAgg[i].isAgg = 1;
pParse->aAgg[i].pExpr = pExpr;
pParse->aAgg[i].pFunc = sqlite3FindFunction(pParse->db,
pExpr->token.z, pExpr->token.n,
pExpr->pList ? pExpr->pList->nExpr : 0, enc, 0);
i = addAggInfoFunc(pAggInfo);
if( i>=0 ){
pItem = &pAggInfo->aFunc[i];
pItem->pExpr = pExpr;
pItem->iMem = pParse->nMem++;
pItem->pFunc = sqlite3FindFunction(pParse->db,
pExpr->token.z, pExpr->token.n,
pExpr->pList ? pExpr->pList->nExpr : 0, enc, 0);
if( pExpr->flags & EP_Distinct ){
pItem->iDistinct = pParse->nTab++;
}else{
pItem->iDistinct = -1;
}
}
}
/* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
*/
pExpr->iAgg = i;
pExpr->pAggInfo = pAggInfo;
return 1;
}
}
}
/* Recursively walk subqueries looking for TK_COLUMN nodes that need
** to be changed to TK_AGG_COLUMN. But increment nDepth so that
** TK_AGG_FUNCTION nodes in subqueries will be unchanged.
*/
if( pExpr->pSelect ){
pNC->nDepth++;
walkSelectExpr(pExpr->pSelect, analyzeAggregate, pNC);
@@ -2143,3 +2233,21 @@ int sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){
walkExprTree(pExpr, analyzeAggregate, pNC);
return pNC->pParse->nErr - nErr;
}
/*
** Call sqlite3ExprAnalyzeAggregates() for every expression in an
** expression list. Return the number of errors.
**
** If an error is found, the analysis is cut short.
*/
int sqlite3ExprAnalyzeAggList(NameContext *pNC, ExprList *pList){
struct ExprList_item *pItem;
int i;
int nErr = 0;
if( pList ){
for(pItem=pList->a, i=0; nErr==0 && i<pList->nExpr; i++, pItem++){
nErr += sqlite3ExprAnalyzeAggregates(pNC, pItem->pExpr);
}
}
return nErr;
}
+33 -30
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.104 2005/08/14 01:20:38 drh Exp $
** $Id: func.c,v 1.110 2005/09/08 20:37:43 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -819,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 */
};
/*
@@ -826,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);
}
@@ -878,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.
*/
@@ -926,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);
}
@@ -1051,11 +1055,11 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
/*
** Set the LIKEOPT flag on the 2-argument function with the given name.
*/
static void setLikeOptFlag(sqlite3 *db, const char *zName){
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 = SQLITE_FUNC_LIKEOPT;
pDef->flags = flagVal;
}
}
@@ -1075,10 +1079,9 @@ void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
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");
if( caseSensitive ){
setLikeOptFlag(db, "like");
}
setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
setLikeOptFlag(db, "like",
caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
}
/*
@@ -1088,7 +1091,7 @@ void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
** return TRUE. If the function is not a LIKE-style function then
** return FALSE.
*/
int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, char *aWc){
int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
FuncDef *pDef;
if( pExpr->op!=TK_FUNCTION ){
return 0;
@@ -1098,7 +1101,7 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, char *aWc){
}
pDef = sqlite3FindFunction(db, pExpr->token.z, pExpr->token.n, 2,
SQLITE_UTF8, 0);
if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKEOPT)==0 ){
if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){
return 0;
}
@@ -1110,6 +1113,6 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, char *aWc){
assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
*pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0;
return 1;
}
+9 -13
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.142 2005/07/21 18:23:20 drh Exp $
** $Id: insert.c,v 1.143 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
@@ -372,13 +372,13 @@ void sqlite3Insert(
** 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));
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 */
@@ -817,7 +816,6 @@ void sqlite3GenerateConstraintChecks(
Index *pIdx;
int seenReplace = 0;
int jumpInst1=0, jumpInst2;
int contAddr;
int hasTwoRowids = (isUpdate && rowidChng);
v = sqlite3GetVdbe(pParse);
@@ -867,7 +865,7 @@ void sqlite3GenerateConstraintChecks(
break;
}
}
sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeJumpHere(v, addr);
}
/* Test all CHECK constraints
@@ -921,10 +919,9 @@ void sqlite3GenerateConstraintChecks(
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);
}
@@ -1018,11 +1015,10 @@ void sqlite3GenerateConstraintChecks(
break;
}
}
contAddr = sqlite3VdbeCurrentAddr(v);
#if NULL_DISTINCT_FOR_UNIQUE
sqlite3VdbeChangeP2(v, jumpInst1, contAddr);
sqlite3VdbeJumpHere(v, jumpInst1);
#endif
sqlite3VdbeChangeP2(v, jumpInst2, contAddr);
sqlite3VdbeJumpHere(v, jumpInst2);
}
}
+43 -4
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.298 2005/08/14 01:20:39 drh Exp $
** $Id: main.c,v 1.302 2005/09/17 15:20:27 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -509,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;
@@ -523,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 ***
**
@@ -694,6 +714,7 @@ static int openDatabase(
){
sqlite3 *db;
int rc, i;
CollSeq *pColl;
/* Allocate the sqlite data structure */
db = sqliteMalloc( sizeof(sqlite3) );
@@ -730,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 ){
@@ -847,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;
}
@@ -901,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;
@@ -1019,3 +1047,14 @@ recover_out:
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
+7 -2
View File
@@ -161,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
@@ -181,7 +186,7 @@ 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);
char *sqlite3OsFullPathname(const char*);
+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 */
-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.
**
******************************************************************************
**
*/
#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
#undef SET_FULLSYNC
/* 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_ */
+34 -8
View File
@@ -18,6 +18,7 @@
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <unistd.h>
@@ -771,6 +772,9 @@ 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;
}
@@ -796,7 +800,7 @@ int sqlite3_fullsync_count = 0;
** 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, int fullSync){
static int full_fsync(int fd, int fullSync, int dataOnly){
int rc;
/* Record the number of times that we do a normal fsync() and
@@ -824,8 +828,15 @@ static int full_fsync(int fd, int fullSync){
/* If the FULLSYNC failed, try to do a normal fsync() */
if( rc ) rc = fsync(fd);
#else
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) */
@@ -835,6 +846,10 @@ static int full_fsync(int fd, int fullSync){
/*
** 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
@@ -843,16 +858,16 @@ static int full_fsync(int fd, int fullSync){
** 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, id->fullSync) ){
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, id->fullSync);
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. */
}
@@ -1310,10 +1325,14 @@ char *sqlite3OsFullPathname(const char *zRelative){
if( zRelative[0]=='/' ){
sqlite3SetString(&zFull, zRelative, (char*)0);
}else{
char zBuf[5000];
char *zBuf = sqliteMalloc(5000);
if( zBuf==0 ){
return 0;
}
zBuf[0] = 0;
sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), "/", zRelative,
sqlite3SetString(&zFull, getcwd(zBuf, 5000), "/", zRelative,
(char*)0);
sqliteFree(zBuf);
}
return zFull;
}
@@ -1420,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;
-116
View File
@@ -1,116 +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>
/*
** 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
/*
** 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 */
unsigned char fullSync; /* Use F_FULLSYNC if available */
int dirfd; /* File descriptor for the directory */
#ifdef SQLITE_UNIX_THREADS
pthread_t tid; /* The thread authorized to use this OsFile */
#endif
};
/*
** A macro to set the OsFile.fullSync flag, if it exists.
*/
#define SET_FULLSYNC(x,y) ((x).fullSync = (y))
/*
** 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
/*
** Default permissions when creating a new file
*/
#ifndef SQLITE_DEFAULT_FILE_PERMISSIONS
# define SQLITE_DEFAULT_FILE_PERMISSIONS 0644
#endif
#endif /* _SQLITE_OS_UNIX_H_ */
+237 -64
View File
@@ -41,11 +41,99 @@
*/
#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;
}
@@ -54,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;
}
/*
@@ -76,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;
@@ -128,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
@@ -135,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;
}
@@ -164,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;
}
@@ -229,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);
}
@@ -303,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.
*/
@@ -311,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) ){
@@ -364,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
@@ -426,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;
@@ -641,6 +801,7 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
char *sqlite3OsFullPathname(const char *zRelative){
char *zNotUsed;
char *zFull;
WCHAR *zWide;
int nByte;
#ifdef __CYGWIN__
nByte = strlen(zRelative) + MAX_PATH + 1001;
@@ -648,10 +809,22 @@ char *sqlite3OsFullPathname(const char *zRelative){
if( zFull==0 ) return 0;
if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0;
#else
nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
zFull = sqliteMalloc( nByte );
if( zFull==0 ) return 0;
GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
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;
}
-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_ */
+68 -37
View File
@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.209 2005/08/21 16:54:25 drh Exp $
** @(#) $Id: pager.c,v 1.215.2.1 2005/12/19 16:29:07 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@@ -657,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;
}
@@ -779,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;
}
@@ -1038,8 +1040,10 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
assert( pPager->state>=PAGER_EXCLUSIVE || pPg!=0 );
TRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno);
if( pPager->state>=PAGER_EXCLUSIVE && (pPg==0 || pPg->needSync==0) ){
sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize);
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 ){
@@ -1168,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);
@@ -1485,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); */
@@ -1746,29 +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;
}
if( n>0 && n<pPager->pageSize ){
n = 1;
}else{
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;
}
@@ -2121,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;
}
@@ -2196,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
@@ -2291,8 +2307,8 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
/* 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.
@@ -2506,8 +2522,10 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
}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 ){
@@ -2815,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);
@@ -2959,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.
@@ -3171,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;
@@ -3345,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
*/
@@ -3433,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);
@@ -3464,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;
+3 -2
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.44 2005/05/20 20:01:56 drh Exp $
** @(#) $Id: pager.h,v 1.46 2005/09/19 19:05:21 drh Exp $
*/
/*
@@ -34,7 +34,7 @@
** reasonable, like 1024.
*/
#ifndef SQLITE_MAX_PAGE_SIZE
# define SQLITE_MAX_PAGE_SIZE 8192
# define SQLITE_MAX_PAGE_SIZE 32768
#endif
/*
@@ -100,6 +100,7 @@ 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);
+36 -13
View File
@@ -14,7 +14,7 @@
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.175 2005/07/08 12:13:05 drh Exp $
** @(#) $Id: parse.y,v 1.180 2005/09/16 02:38:10 drh Exp $
*/
// All token codes are small integers with #defines that begin with "TK_"
@@ -93,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 CONST_FUNC.
COLUMN AGG_FUNCTION AGG_COLUMN CONST_FUNC.
// Input is a single SQL command
input ::= cmdlist.
@@ -104,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. ////////////////////////////
@@ -172,7 +173,7 @@ id(A) ::= ID(X). {A = X;}
%fallback ID
ABORT AFTER ANALYZE ASC ATTACH BEFORE BEGIN CASCADE CAST CONFLICT
DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR
IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH 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
@@ -660,9 +661,12 @@ expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). {
sqlite3ExprSpan(A,&X,&Y);
}
%endif // SQLITE_OMIT_CAST
expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
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);
@@ -752,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);
}
@@ -772,21 +780,31 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
}
expr(A) ::= LP(B) select(X) RP(E). {
A = sqlite3Expr(TK_SELECT, 0, 0, 0);
if( A ) A->pSelect = X;
if( !A ) sqlite3SelectDelete(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 ) sqlite3SelectDelete(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);
}
@@ -795,15 +813,20 @@ 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);
}
if( !p ) sqlite3SelectDelete(Y);
}
%endif // SQLITE_OMIT_SUBQUERY
/* CASE expressions */
expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
A = sqlite3Expr(TK_CASE, X, Z, 0);
if( A ) A->pList = Y;
if( A ){
A->pList = Y;
}else{
sqlite3ExprListDelete(Y);
}
sqlite3ExprSpan(A, &C, &E);
}
%type case_exprlist {ExprList*}
+20 -30
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.98 2005/08/14 01:20:39 drh Exp $
** $Id: pragma.c,v 1.100 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -626,14 +626,6 @@ void sqlite3Pragma(
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
@@ -650,7 +642,7 @@ 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++){
@@ -696,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++){
@@ -715,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 */
@@ -903,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);
+14 -7
View File
@@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.3 2005/08/19 00:14:42 drh Exp $
** $Id: prepare.c,v 1.4 2005/09/10 16:46:13 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -458,12 +458,19 @@ int sqlite3_prepare(
#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);
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
+23 -8
View File
@@ -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.
@@ -440,9 +448,9 @@ static int vxprintf(
/* 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>=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; }
while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
if( exp>350 || exp<-350 ){
@@ -718,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;
}
}
}
}
@@ -756,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;
@@ -774,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);
}
@@ -785,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);
+685 -417
View File
File diff suppressed because it is too large Load Diff
+20 -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.123 2005/08/05 18:50:52 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( strcmp(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;
@@ -1290,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
);
@@ -1334,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') "
@@ -1698,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
+14 -6
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.139 2005/08/11 02:10:19 drh Exp $
** @(#) $Id: sqlite.h.in,v 1.141 2005/09/08 10:58:52 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -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:
@@ -464,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
+133 -61
View File
@@ -11,11 +11,22 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.403 2005/08/19 00:14:42 drh 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
@@ -298,7 +309,7 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
/*
** Forward references to structures
*/
typedef struct AggExpr AggExpr;
typedef struct AggInfo AggInfo;
typedef struct AuthContext AuthContext;
typedef struct CollSeq CollSeq;
typedef struct Column Column;
@@ -420,8 +431,10 @@ 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*);
@@ -511,7 +524,8 @@ struct FuncDef {
/*
** Possible values for FuncDef.flags
*/
#define SQLITE_FUNC_LIKEOPT 0x01 /* Candidate for the LIKE optimization */
#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
@@ -551,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.
*/
@@ -776,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.
@@ -835,9 +901,9 @@ 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. */
@@ -850,7 +916,7 @@ struct Expr {
#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_Not 0x10 /* Operator preceeded by NOT */
#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 */
@@ -874,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 */
@@ -899,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 */
};
/*
@@ -944,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
@@ -1018,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 */
};
@@ -1032,64 +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 **ppOpenVirtual;/* OP_OpenVirtual addresses used by multi-selects */
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
@@ -1110,7 +1170,6 @@ struct Parse {
u8 nameClash; /* A permanent table name clashes with temp table name */
u8 checkSchema; /* Causes schema cookie check after an error */
u8 nested; /* Number of nested calls to the parser/code generator */
u8 fillAgg; /* If true, ignore the Expr.iAgg field. Normally false */
int nErr; /* Number of errors seen */
int nTab; /* Number of previously allocated VDBE cursors */
int nMem; /* Number of memory cells used so far */
@@ -1137,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 */
};
/*
@@ -1319,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
*/
@@ -1346,6 +1415,7 @@ void sqlite3RealToSortable(double r, char *);
# define sqlite3CheckMemory(a,b)
# define sqlite3MallocX sqlite3Malloc
#endif
void sqlite3ReallocOrFree(void**,int);
void sqlite3FreeX(void*);
void *sqlite3MallocX(int);
char *sqlite3MPrintf(const char*, ...);
@@ -1396,6 +1466,7 @@ void sqlite3EndTable(Parse*,Token*,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*);
@@ -1440,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*);
@@ -1557,7 +1629,7 @@ 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);
@@ -1583,7 +1655,7 @@ int sqlite3FindDb(sqlite3*, Token*);
void sqlite3AnalysisLoad(sqlite3*,int iDB);
void sqlite3DefaultRowEst(Index*);
void sqlite3RegisterLikeFunctions(sqlite3*, int);
int sqlite3IsLikeFunction(sqlite3*,Expr*,char*);
int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
#ifdef SQLITE_SSE
#include "sseInt.h"
+327 -262
View File
@@ -11,7 +11,7 @@
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.131 2005/08/16 11:11:35 drh Exp $
** $Id: tclsqlite.c,v 1.132 2005/08/29 23:00:04 drh Exp $
*/
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
@@ -84,6 +84,7 @@ struct SqliteDb {
char *zBusy; /* The busy callback routine */
char *zCommit; /* The commit hook callback routine */
char *zTrace; /* The trace callback routine */
char *zProfile; /* The profile callback routine */
char *zProgress; /* The progress callback routine */
char *zAuth; /* The authorization callback routine */
char *zNull; /* Text to substitute for an SQL NULL value */
@@ -190,6 +191,9 @@ static void DbDeleteCmd(void *db){
if( pDb->zTrace ){
Tcl_Free(pDb->zTrace);
}
if( pDb->zProfile ){
Tcl_Free(pDb->zProfile);
}
if( pDb->zAuth ){
Tcl_Free(pDb->zAuth);
}
@@ -247,6 +251,25 @@ static void DbTraceHandler(void *cd, const char *zSql){
Tcl_ResetResult(pDb->interp);
}
/*
** This routine is called by the SQLite profile handler after a statement
** SQL has executed. The TCL script in pDb->zProfile is evaluated.
*/
static void DbProfileHandler(void *cd, const char *zSql, sqlite_uint64 tm){
SqliteDb *pDb = (SqliteDb*)cd;
Tcl_DString str;
char zTm[100];
sqlite3_snprintf(sizeof(zTm)-1, zTm, "%lld", tm);
Tcl_DStringInit(&str);
Tcl_DStringAppend(&str, pDb->zProfile, -1);
Tcl_DStringAppendElement(&str, zSql);
Tcl_DStringAppendElement(&str, zTm);
Tcl_Eval(pDb->interp, Tcl_DStringValue(&str));
Tcl_DStringFree(&str);
Tcl_ResetResult(pDb->interp);
}
/*
** This routine is called when a transaction is committed. The
** TCL script in pDb->zCommit is executed. If it returns non-zero or
@@ -589,9 +612,10 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
"collation_needed", "commit_hook", "complete",
"copy", "errorcode", "eval",
"function", "last_insert_rowid", "nullvalue",
"onecolumn", "progress", "rekey",
"timeout", "total_changes", "trace",
"transaction", "version", 0
"onecolumn", "profile", "progress",
"rekey", "timeout", "total_changes",
"trace", "transaction", "version",
0
};
enum DB_enum {
DB_AUTHORIZER, DB_BUSY, DB_CACHE,
@@ -599,9 +623,9 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
DB_COLLATION_NEEDED, DB_COMMIT_HOOK, DB_COMPLETE,
DB_COPY, DB_ERRORCODE, DB_EVAL,
DB_FUNCTION, DB_LAST_INSERT_ROWID,DB_NULLVALUE,
DB_ONECOLUMN, DB_PROGRESS, DB_REKEY,
DB_TIMEOUT, DB_TOTAL_CHANGES, DB_TRACE,
DB_TRANSACTION, DB_VERSION,
DB_ONECOLUMN, DB_PROFILE, DB_PROGRESS,
DB_REKEY, DB_TIMEOUT, DB_TOTAL_CHANGES,
DB_TRACE, DB_TRANSACTION, DB_VERSION
};
/* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
@@ -780,44 +804,6 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
break;
}
/* $db commit_hook ?CALLBACK?
**
** Invoke the given callback just before committing every SQL transaction.
** If the callback throws an exception or returns non-zero, then the
** transaction is aborted. If CALLBACK is an empty string, the callback
** is disabled.
*/
case DB_COMMIT_HOOK: {
if( objc>3 ){
Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
return TCL_ERROR;
}else if( objc==2 ){
if( pDb->zCommit ){
Tcl_AppendResult(interp, pDb->zCommit, 0);
}
}else{
char *zCommit;
int len;
if( pDb->zCommit ){
Tcl_Free(pDb->zCommit);
}
zCommit = Tcl_GetStringFromObj(objv[2], &len);
if( zCommit && len>0 ){
pDb->zCommit = Tcl_Alloc( len + 1 );
strcpy(pDb->zCommit, zCommit);
}else{
pDb->zCommit = 0;
}
if( pDb->zCommit ){
pDb->interp = interp;
sqlite3_commit_hook(pDb->db, DbCommitHandler, pDb);
}else{
sqlite3_commit_hook(pDb->db, 0, 0);
}
}
break;
}
/*
** $db collate NAME SCRIPT
**
@@ -870,6 +856,44 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
break;
}
/* $db commit_hook ?CALLBACK?
**
** Invoke the given callback just before committing every SQL transaction.
** If the callback throws an exception or returns non-zero, then the
** transaction is aborted. If CALLBACK is an empty string, the callback
** is disabled.
*/
case DB_COMMIT_HOOK: {
if( objc>3 ){
Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
return TCL_ERROR;
}else if( objc==2 ){
if( pDb->zCommit ){
Tcl_AppendResult(interp, pDb->zCommit, 0);
}
}else{
char *zCommit;
int len;
if( pDb->zCommit ){
Tcl_Free(pDb->zCommit);
}
zCommit = Tcl_GetStringFromObj(objv[2], &len);
if( zCommit && len>0 ){
pDb->zCommit = Tcl_Alloc( len + 1 );
strcpy(pDb->zCommit, zCommit);
}else{
pDb->zCommit = 0;
}
if( pDb->zCommit ){
pDb->interp = interp;
sqlite3_commit_hook(pDb->db, DbCommitHandler, pDb);
}else{
sqlite3_commit_hook(pDb->db, 0, 0);
}
}
break;
}
/* $db complete SQL
**
** Return TRUE if SQL is a complete SQL statement. Return FALSE if
@@ -891,6 +915,192 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
break;
}
/* $db copy conflict-algorithm table filename ?SEPARATOR? ?NULLINDICATOR?
**
** Copy data into table from filename, optionally using SEPARATOR
** as column separators. If a column contains a null string, or the
** value of NULLINDICATOR, a NULL is inserted for the column.
** conflict-algorithm is one of the sqlite conflict algorithms:
** rollback, abort, fail, ignore, replace
** On success, return the number of lines processed, not necessarily same
** as 'db changes' due to conflict-algorithm selected.
**
** This code is basically an implementation/enhancement of
** the sqlite3 shell.c ".import" command.
**
** This command usage is equivalent to the sqlite2.x COPY statement,
** which imports file data into a table using the PostgreSQL COPY file format:
** $db copy $conflit_algo $table_name $filename \t \\N
*/
case DB_COPY: {
char *zTable; /* Insert data into this table */
char *zFile; /* The file from which to extract data */
char *zConflict; /* The conflict algorithm to use */
sqlite3_stmt *pStmt; /* A statement */
int rc; /* Result code */
int nCol; /* Number of columns in the table */
int nByte; /* Number of bytes in an SQL string */
int i, j; /* Loop counters */
int nSep; /* Number of bytes in zSep[] */
int nNull; /* Number of bytes in zNull[] */
char *zSql; /* An SQL statement */
char *zLine; /* A single line of input from the file */
char **azCol; /* zLine[] broken up into columns */
char *zCommit; /* How to commit changes */
FILE *in; /* The input file */
int lineno = 0; /* Line number of input file */
char zLineNum[80]; /* Line number print buffer */
Tcl_Obj *pResult; /* interp result */
char *zSep;
char *zNull;
if( objc<5 || objc>7 ){
Tcl_WrongNumArgs(interp, 2, objv,
"CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?");
return TCL_ERROR;
}
if( objc>=6 ){
zSep = Tcl_GetStringFromObj(objv[5], 0);
}else{
zSep = "\t";
}
if( objc>=7 ){
zNull = Tcl_GetStringFromObj(objv[6], 0);
}else{
zNull = "";
}
zConflict = Tcl_GetStringFromObj(objv[2], 0);
zTable = Tcl_GetStringFromObj(objv[3], 0);
zFile = Tcl_GetStringFromObj(objv[4], 0);
nSep = strlen(zSep);
nNull = strlen(zNull);
if( nSep==0 ){
Tcl_AppendResult(interp, "Error: non-null separator required for copy", 0);
return TCL_ERROR;
}
if(sqlite3StrICmp(zConflict, "rollback") != 0 &&
sqlite3StrICmp(zConflict, "abort" ) != 0 &&
sqlite3StrICmp(zConflict, "fail" ) != 0 &&
sqlite3StrICmp(zConflict, "ignore" ) != 0 &&
sqlite3StrICmp(zConflict, "replace" ) != 0 ) {
Tcl_AppendResult(interp, "Error: \"", zConflict,
"\", conflict-algorithm must be one of: rollback, "
"abort, fail, ignore, or replace", 0);
return TCL_ERROR;
}
zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable);
if( zSql==0 ){
Tcl_AppendResult(interp, "Error: no such table: ", zTable, 0);
return TCL_ERROR;
}
nByte = strlen(zSql);
rc = sqlite3_prepare(pDb->db, zSql, 0, &pStmt, 0);
sqlite3_free(zSql);
if( rc ){
Tcl_AppendResult(interp, "Error: ", sqlite3_errmsg(pDb->db), 0);
nCol = 0;
}else{
nCol = sqlite3_column_count(pStmt);
}
sqlite3_finalize(pStmt);
if( nCol==0 ) {
return TCL_ERROR;
}
zSql = malloc( nByte + 50 + nCol*2 );
if( zSql==0 ) {
Tcl_AppendResult(interp, "Error: can't malloc()", 0);
return TCL_ERROR;
}
sqlite3_snprintf(nByte+50, zSql, "INSERT OR %q INTO '%q' VALUES(?",
zConflict, zTable);
j = strlen(zSql);
for(i=1; i<nCol; i++){
zSql[j++] = ',';
zSql[j++] = '?';
}
zSql[j++] = ')';
zSql[j] = 0;
rc = sqlite3_prepare(pDb->db, zSql, 0, &pStmt, 0);
free(zSql);
if( rc ){
Tcl_AppendResult(interp, "Error: ", sqlite3_errmsg(pDb->db), 0);
sqlite3_finalize(pStmt);
return TCL_ERROR;
}
in = fopen(zFile, "rb");
if( in==0 ){
Tcl_AppendResult(interp, "Error: cannot open file: ", zFile, NULL);
sqlite3_finalize(pStmt);
return TCL_ERROR;
}
azCol = malloc( sizeof(azCol[0])*(nCol+1) );
if( azCol==0 ) {
Tcl_AppendResult(interp, "Error: can't malloc()", 0);
return TCL_ERROR;
}
sqlite3_exec(pDb->db, "BEGIN", 0, 0, 0);
zCommit = "COMMIT";
while( (zLine = local_getline(0, in))!=0 ){
char *z;
i = 0;
lineno++;
azCol[0] = zLine;
for(i=0, z=zLine; *z; z++){
if( *z==zSep[0] && strncmp(z, zSep, nSep)==0 ){
*z = 0;
i++;
if( i<nCol ){
azCol[i] = &z[nSep];
z += nSep-1;
}
}
}
if( i+1!=nCol ){
char *zErr;
zErr = malloc(200 + strlen(zFile));
sprintf(zErr,"Error: %s line %d: expected %d columns of data but found %d",
zFile, lineno, nCol, i+1);
Tcl_AppendResult(interp, zErr, 0);
free(zErr);
zCommit = "ROLLBACK";
break;
}
for(i=0; i<nCol; i++){
/* check for null data, if so, bind as null */
if ((nNull>0 && strcmp(azCol[i], zNull)==0) || strlen(azCol[i])==0) {
sqlite3_bind_null(pStmt, i+1);
}else{
sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
}
}
sqlite3_step(pStmt);
rc = sqlite3_reset(pStmt);
free(zLine);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp,"Error: ", sqlite3_errmsg(pDb->db), 0);
zCommit = "ROLLBACK";
break;
}
}
free(azCol);
fclose(in);
sqlite3_finalize(pStmt);
sqlite3_exec(pDb->db, zCommit, 0, 0, 0);
if( zCommit[0] == 'C' ){
/* success, set result as number of lines processed */
pResult = Tcl_GetObjResult(interp);
Tcl_SetIntObj(pResult, lineno);
rc = TCL_OK;
}else{
/* failure, append lineno where failed */
sprintf(zLineNum,"%d",lineno);
Tcl_AppendResult(interp,", failed while processing line: ",zLineNum,0);
rc = TCL_ERROR;
}
break;
}
/*
** $db errorcode
**
@@ -1301,6 +1511,37 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
break;
}
/*
** $db nullvalue ?STRING?
**
** Change text used when a NULL comes back from the database. If ?STRING?
** is not present, then the current string used for NULL is returned.
** If STRING is present, then STRING is returned.
**
*/
case DB_NULLVALUE: {
if( objc!=2 && objc!=3 ){
Tcl_WrongNumArgs(interp, 2, objv, "NULLVALUE");
return TCL_ERROR;
}
if( objc==3 ){
int len;
char *zNull = Tcl_GetStringFromObj(objv[2], &len);
if( pDb->zNull ){
Tcl_Free(pDb->zNull);
}
if( zNull && len>0 ){
pDb->zNull = Tcl_Alloc( len + 1 );
strncpy(pDb->zNull, zNull, len);
pDb->zNull[len] = '\0';
}else{
pDb->zNull = 0;
}
}
Tcl_SetObjResult(interp, dbTextToObj(pDb->zNull));
break;
}
/*
** $db last_insert_rowid
**
@@ -1365,6 +1606,45 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
break;
}
/* $db profile ?CALLBACK?
**
** Make arrangements to invoke the CALLBACK routine after each SQL statement
** that has run. The text of the SQL and the amount of elapse time are
** appended to CALLBACK before the script is run.
*/
case DB_PROFILE: {
if( objc>3 ){
Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
return TCL_ERROR;
}else if( objc==2 ){
if( pDb->zProfile ){
Tcl_AppendResult(interp, pDb->zProfile, 0);
}
}else{
char *zProfile;
int len;
if( pDb->zProfile ){
Tcl_Free(pDb->zProfile);
}
zProfile = Tcl_GetStringFromObj(objv[2], &len);
if( zProfile && len>0 ){
pDb->zProfile = Tcl_Alloc( len + 1 );
strcpy(pDb->zProfile, zProfile);
}else{
pDb->zProfile = 0;
}
#ifndef SQLITE_OMIT_TRACE
if( pDb->zProfile ){
pDb->interp = interp;
sqlite3_profile(pDb->db, DbProfileHandler, pDb);
}else{
sqlite3_profile(pDb->db, 0, 0);
}
#endif
}
break;
}
/*
** $db rekey KEY
**
@@ -1403,37 +1683,6 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
sqlite3_busy_timeout(pDb->db, ms);
break;
}
/*
** $db nullvalue ?STRING?
**
** Change text used when a NULL comes back from the database. If ?STRING?
** is not present, then the current string used for NULL is returned.
** If STRING is present, then STRING is returned.
**
*/
case DB_NULLVALUE: {
if( objc!=2 && objc!=3 ){
Tcl_WrongNumArgs(interp, 2, objv, "NULLVALUE");
return TCL_ERROR;
}
if( objc==3 ){
int len;
char *zNull = Tcl_GetStringFromObj(objv[2], &len);
if( pDb->zNull ){
Tcl_Free(pDb->zNull);
}
if( zNull && len>0 ){
pDb->zNull = Tcl_Alloc( len + 1 );
strncpy(pDb->zNull, zNull, len);
pDb->zNull[len] = '\0';
}else{
pDb->zNull = 0;
}
}
Tcl_SetObjResult(interp, dbTextToObj(pDb->zNull));
break;
}
/*
** $db total_changes
@@ -1479,12 +1728,14 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
}else{
pDb->zTrace = 0;
}
#ifndef SQLITE_OMIT_TRACE
if( pDb->zTrace ){
pDb->interp = interp;
sqlite3_trace(pDb->db, DbTraceHandler, pDb);
}else{
sqlite3_trace(pDb->db, 0, 0);
}
#endif
}
break;
}
@@ -1546,192 +1797,6 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
break;
}
/* $db copy conflict-algorithm table filename ?SEPARATOR? ?NULLINDICATOR?
**
** Copy data into table from filename, optionally using SEPARATOR
** as column separators. If a column contains a null string, or the
** value of NULLINDICATOR, a NULL is inserted for the column.
** conflict-algorithm is one of the sqlite conflict algorithms:
** rollback, abort, fail, ignore, replace
** On success, return the number of lines processed, not necessarily same
** as 'db changes' due to conflict-algorithm selected.
**
** This code is basically an implementation/enhancement of
** the sqlite3 shell.c ".import" command.
**
** This command usage is equivalent to the sqlite2.x COPY statement,
** which imports file data into a table using the PostgreSQL COPY file format:
** $db copy $conflit_algo $table_name $filename \t \\N
*/
case DB_COPY: {
char *zTable; /* Insert data into this table */
char *zFile; /* The file from which to extract data */
char *zConflict; /* The conflict algorithm to use */
sqlite3_stmt *pStmt; /* A statement */
int rc; /* Result code */
int nCol; /* Number of columns in the table */
int nByte; /* Number of bytes in an SQL string */
int i, j; /* Loop counters */
int nSep; /* Number of bytes in zSep[] */
int nNull; /* Number of bytes in zNull[] */
char *zSql; /* An SQL statement */
char *zLine; /* A single line of input from the file */
char **azCol; /* zLine[] broken up into columns */
char *zCommit; /* How to commit changes */
FILE *in; /* The input file */
int lineno = 0; /* Line number of input file */
char zLineNum[80]; /* Line number print buffer */
Tcl_Obj *pResult; /* interp result */
char *zSep;
char *zNull;
if( objc<5 || objc>7 ){
Tcl_WrongNumArgs(interp, 2, objv,
"CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?");
return TCL_ERROR;
}
if( objc>=6 ){
zSep = Tcl_GetStringFromObj(objv[5], 0);
}else{
zSep = "\t";
}
if( objc>=7 ){
zNull = Tcl_GetStringFromObj(objv[6], 0);
}else{
zNull = "";
}
zConflict = Tcl_GetStringFromObj(objv[2], 0);
zTable = Tcl_GetStringFromObj(objv[3], 0);
zFile = Tcl_GetStringFromObj(objv[4], 0);
nSep = strlen(zSep);
nNull = strlen(zNull);
if( nSep==0 ){
Tcl_AppendResult(interp, "Error: non-null separator required for copy", 0);
return TCL_ERROR;
}
if(sqlite3StrICmp(zConflict, "rollback") != 0 &&
sqlite3StrICmp(zConflict, "abort" ) != 0 &&
sqlite3StrICmp(zConflict, "fail" ) != 0 &&
sqlite3StrICmp(zConflict, "ignore" ) != 0 &&
sqlite3StrICmp(zConflict, "replace" ) != 0 ) {
Tcl_AppendResult(interp, "Error: \"", zConflict,
"\", conflict-algorithm must be one of: rollback, "
"abort, fail, ignore, or replace", 0);
return TCL_ERROR;
}
zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable);
if( zSql==0 ){
Tcl_AppendResult(interp, "Error: no such table: ", zTable, 0);
return TCL_ERROR;
}
nByte = strlen(zSql);
rc = sqlite3_prepare(pDb->db, zSql, 0, &pStmt, 0);
sqlite3_free(zSql);
if( rc ){
Tcl_AppendResult(interp, "Error: ", sqlite3_errmsg(pDb->db), 0);
nCol = 0;
}else{
nCol = sqlite3_column_count(pStmt);
}
sqlite3_finalize(pStmt);
if( nCol==0 ) {
return TCL_ERROR;
}
zSql = malloc( nByte + 50 + nCol*2 );
if( zSql==0 ) {
Tcl_AppendResult(interp, "Error: can't malloc()", 0);
return TCL_ERROR;
}
sqlite3_snprintf(nByte+50, zSql, "INSERT OR %q INTO '%q' VALUES(?",
zConflict, zTable);
j = strlen(zSql);
for(i=1; i<nCol; i++){
zSql[j++] = ',';
zSql[j++] = '?';
}
zSql[j++] = ')';
zSql[j] = 0;
rc = sqlite3_prepare(pDb->db, zSql, 0, &pStmt, 0);
free(zSql);
if( rc ){
Tcl_AppendResult(interp, "Error: ", sqlite3_errmsg(pDb->db), 0);
sqlite3_finalize(pStmt);
return TCL_ERROR;
}
in = fopen(zFile, "rb");
if( in==0 ){
Tcl_AppendResult(interp, "Error: cannot open file: ", zFile, NULL);
sqlite3_finalize(pStmt);
return TCL_ERROR;
}
azCol = malloc( sizeof(azCol[0])*(nCol+1) );
if( azCol==0 ) {
Tcl_AppendResult(interp, "Error: can't malloc()", 0);
return TCL_ERROR;
}
sqlite3_exec(pDb->db, "BEGIN", 0, 0, 0);
zCommit = "COMMIT";
while( (zLine = local_getline(0, in))!=0 ){
char *z;
i = 0;
lineno++;
azCol[0] = zLine;
for(i=0, z=zLine; *z; z++){
if( *z==zSep[0] && strncmp(z, zSep, nSep)==0 ){
*z = 0;
i++;
if( i<nCol ){
azCol[i] = &z[nSep];
z += nSep-1;
}
}
}
if( i+1!=nCol ){
char *zErr;
zErr = malloc(200 + strlen(zFile));
sprintf(zErr,"Error: %s line %d: expected %d columns of data but found %d",
zFile, lineno, nCol, i+1);
Tcl_AppendResult(interp, zErr, 0);
free(zErr);
zCommit = "ROLLBACK";
break;
}
for(i=0; i<nCol; i++){
/* check for null data, if so, bind as null */
if ((nNull>0 && strcmp(azCol[i], zNull)==0) || strlen(azCol[i])==0) {
sqlite3_bind_null(pStmt, i+1);
}else{
sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
}
}
sqlite3_step(pStmt);
rc = sqlite3_reset(pStmt);
free(zLine);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp,"Error: ", sqlite3_errmsg(pDb->db), 0);
zCommit = "ROLLBACK";
break;
}
}
free(azCol);
fclose(in);
sqlite3_finalize(pStmt);
sqlite3_exec(pDb->db, zCommit, 0, 0, 0);
if( zCommit[0] == 'C' ){
/* success, set result as number of lines processed */
pResult = Tcl_GetObjResult(interp);
Tcl_SetIntObj(pResult, lineno);
rc = TCL_OK;
}else{
/* failure, append lineno where failed */
sprintf(zLineNum,"%d",lineno);
Tcl_AppendResult(interp,", failed while processing line: ",zLineNum,0);
rc = TCL_ERROR;
}
break;
}
/* $db version
**
** Return the version string for this database.
+100 -20
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.155 2005/08/19 00:14:42 drh Exp $
** $Id: test1.c,v 1.162 2005/09/19 13:15:23 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -661,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
*/
@@ -676,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++){
@@ -690,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
@@ -744,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?
**
@@ -1107,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;
@@ -1130,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);
@@ -2620,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
@@ -2954,6 +3015,12 @@ 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
@@ -3004,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 },
@@ -3029,6 +3097,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "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;
@@ -3111,12 +3180,17 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
extern int sqlite3_opentemp_count;
extern int sqlite3_memUsed;
extern int sqlite3_memMax;
extern char sqlite3_query_plan[];
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);
@@ -3139,11 +3213,19 @@ 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);
Tcl_LinkVar(interp, "sqlite_where_trace",
(char*)&sqlite3_where_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",
@@ -3151,8 +3233,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
Tcl_LinkVar(interp, "sqlite_memmax",
(char*)&sqlite3_memMax, TCL_LINK_INT | TCL_LINK_READ_ONLY);
#endif
Tcl_LinkVar(interp, "sqlite_query_plan",
(char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
#ifndef SQLITE_OMIT_DISKIO
Tcl_LinkVar(interp, "sqlite_opentemp_count",
(char*)&sqlite3_opentemp_count, TCL_LINK_INT);
+6 -1
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.31 2005/08/11 02:10:19 drh Exp $
** $Id: test2.c,v 1.34 2005/09/16 10:13:42 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -561,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;
@@ -593,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;
+5 -5
View File
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
**
** $Id: update.c,v 1.110 2005/07/21 18:23:20 drh Exp $
** $Id: update.c,v 1.112 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
@@ -259,13 +259,13 @@ 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);
}
@@ -469,7 +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));
sqlite3VdbeJumpHere(v, addr);
/* Close all tables if there were no FOR EACH ROW triggers */
if( !triggers_exist ){
+16 -3
View File
@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.143 2005/08/20 03:03:04 drh Exp $
** $Id: util.c,v 1.146 2005/09/17 18:34:11 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -366,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
@@ -748,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;
}
@@ -764,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;
}
+146 -434
View File
@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.478 2005/07/28 20:51:19 drh Exp $
** $Id: vdbe.c,v 1.491 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -160,38 +160,6 @@ static void _storeTypeInfo(Mem *pMem){
}
}
/*
** Insert a new aggregate element and make it the element that
** has focus.
**
** Return 0 on success and 1 if memory is exhausted.
*/
static int AggInsert(Agg *p, char *zKey, int nKey){
AggElem *pElem;
int i;
int rc;
pElem = sqliteMalloc( sizeof(AggElem) + nKey +
(p->nMem-1)*sizeof(pElem->aMem[0]) );
if( pElem==0 ) return SQLITE_NOMEM;
pElem->zKey = (char*)&pElem->aMem[p->nMem];
memcpy(pElem->zKey, zKey, nKey);
pElem->nKey = nKey;
if( p->pCsr ){
rc = sqlite3BtreeInsert(p->pCsr, zKey, nKey, &pElem, sizeof(AggElem*));
if( rc!=SQLITE_OK ){
sqliteFree(pElem);
return rc;
}
}
for(i=0; i<p->nMem; i++){
pElem->aMem[i].flags = MEM_Null;
}
p->pCurrent = pElem;
return 0;
}
/*
** Pop the stack N times.
*/
@@ -205,39 +173,6 @@ static void popStack(Mem **ppTos, int N){
*ppTos = pTos;
}
/*
** The parameters are pointers to the head of two sorted lists
** of Sorter structures. Merge these two lists together and return
** a single sorted list. This routine forms the core of the merge-sort
** algorithm.
**
** In the case of a tie, left sorts in front of right.
*/
static Sorter *Merge(Sorter *pLeft, Sorter *pRight, KeyInfo *pKeyInfo){
Sorter sHead;
Sorter *pTail;
pTail = &sHead;
pTail->pNext = 0;
while( pLeft && pRight ){
int c = sqlite3VdbeRecordCompare(pKeyInfo, pLeft->nKey, pLeft->zKey,
pRight->nKey, pRight->zKey);
if( c<=0 ){
pTail->pNext = pLeft;
pLeft = pLeft->pNext;
}else{
pTail->pNext = pRight;
pRight = pRight->pNext;
}
pTail = pTail->pNext;
}
if( pLeft ){
pTail->pNext = pLeft;
}else if( pRight ){
pTail->pNext = pRight;
}
return sHead.pNext;
}
/*
** Allocate cursor number iCur. Return a pointer to it. Return NULL
** if we run out of memory.
@@ -635,7 +570,7 @@ case OP_Return: { /* no-push */
/* Opcode: Halt P1 P2 P3
**
** Exit immediately. All open cursors, Lists, Sorts, etc are closed
** Exit immediately. All open cursors, Fifos, etc are closed
** automatically.
**
** P1 is the result code returned by sqlite3_exec(), sqlite3_reset(),
@@ -773,6 +708,7 @@ case OP_String: {
case OP_Null: {
pTos++;
pTos->flags = MEM_Null;
pTos->n = 0;
break;
}
@@ -1164,26 +1100,25 @@ case OP_CollSeq: { /* no-push */
/* Opcode: Function P1 P2 P3
**
** Invoke a user function (P3 is a pointer to a Function structure that
** defines the function) with P1 arguments taken from the stack. Pop all
** defines the function) with P2 arguments taken from the stack. Pop all
** arguments from the stack and push back the result.
**
** P2 is a 32-bit bitmask indicating whether or not each argument to the
** P1 is a 32-bit bitmask indicating whether or not each argument to the
** function was determined to be constant at compile time. If the first
** argument was constant then bit 0 of P2 is set. This is used to determine
** argument was constant then bit 0 of P1 is set. This is used to determine
** whether meta data associated with a user function argument using the
** sqlite3_set_auxdata() API may be safely retained until the next
** invocation of this opcode.
**
** See also: AggFunc
** See also: AggStep and AggFinal
*/
case OP_Function: {
int i;
Mem *pArg;
sqlite3_context ctx;
sqlite3_value **apVal;
int n = pOp->p1;
int n = pOp->p2;
n = pOp->p1;
apVal = p->apArg;
assert( apVal || n==0 );
@@ -1222,7 +1157,7 @@ case OP_Function: {
** immediately call the destructor for any non-static values.
*/
if( ctx.pVdbeFunc ){
sqlite3VdbeDeleteAuxData(ctx.pVdbeFunc, pOp->p2);
sqlite3VdbeDeleteAuxData(ctx.pVdbeFunc, pOp->p1);
pOp->p3 = (char *)ctx.pVdbeFunc;
pOp->p3type = P3_VDBEFUNC;
}
@@ -1476,9 +1411,16 @@ case OP_ToBlob: { /* no-push */
** jump to instruction P2. Otherwise, continue to the next instruction.
**
** If the 0x100 bit of P1 is true and either operand is NULL then take the
** jump. If the 0x100 bit of P1 is false then fall thru if either operand
** jump. If the 0x100 bit of P1 is clear then fall thru if either operand
** is NULL.
**
** If the 0x200 bit of P1 is set and either operand is NULL then
** both operands are converted to integers prior to comparison.
** NULL operands are converted to zero and non-NULL operands are
** converted to 1. Thus, for example, with 0x200 set, NULL==NULL is true
** whereas it would normally be NULL. Similarly, NULL==123 is false when
** 0x200 is set but is NULL when the 0x200 bit of P1 is clear.
**
** The least significant byte of P1 (mask 0xff) must be an affinity character -
** 'n', 't', 'i' or 'o' - or 0x00. An attempt is made to coerce both values
** according to the affinity before the comparison is made. If the byte is
@@ -1546,14 +1488,36 @@ case OP_Ge: { /* same as TK_GE, no-push */
** the stack.
*/
if( flags&MEM_Null ){
popStack(&pTos, 2);
if( pOp->p2 ){
if( pOp->p1 & 0x100 ) pc = pOp->p2-1;
if( (pOp->p1 & 0x200)!=0 ){
/* The 0x200 bit of P1 means, roughly "do not treat NULL as the
** magic SQL value it normally is - treat it as if it were another
** integer".
**
** With 0x200 set, if either operand is NULL then both operands
** are converted to integers prior to being passed down into the
** normal comparison logic below. NULL operands are converted to
** zero and non-NULL operands are converted to 1. Thus, for example,
** with 0x200 set, NULL==NULL is true whereas it would normally
** be NULL. Similarly, NULL!=123 is true.
*/
sqlite3VdbeMemSetInt64(pTos, (pTos->flags & MEM_Null)==0);
sqlite3VdbeMemSetInt64(pNos, (pNos->flags & MEM_Null)==0);
}else{
pTos++;
pTos->flags = MEM_Null;
/* If the 0x200 bit of P1 is clear and either operand is NULL then
** the result is always NULL. The jump is taken if the 0x100 bit
** of P1 is set.
*/
popStack(&pTos, 2);
if( pOp->p2 ){
if( pOp->p1 & 0x100 ){
pc = pOp->p2-1;
}
}else{
pTos++;
pTos->flags = MEM_Null;
}
break;
}
break;
}
affinity = pOp->p1 & 0xFF;
@@ -1710,6 +1674,13 @@ case OP_BitNot: { /* same as TK_BITNOT, no-push */
** Do nothing. This instruction is often useful as a jump
** destination.
*/
/*
** The magic Explain opcode are only inserted when explain==2 (which
** is to say when the EXPLAIN QUERY PLAN syntax is used.)
** This opcode records information from the optimizer. It is the
** the same as a no-op. This opcodesnever appears in a real VM program.
*/
case OP_Explain:
case OP_Noop: { /* no-push */
break;
}
@@ -2020,7 +1991,7 @@ case OP_Column: {
** we are dealing with a malformed record.
*/
if( idx!=szHdr || offset!=payloadSize ){
rc = SQLITE_CORRUPT;
rc = SQLITE_CORRUPT_BKPT;
goto op_column_out;
}
@@ -2574,7 +2545,7 @@ case OP_OpenWrite: { /* no-push */
** only mean that we are dealing with a corrupt database file
*/
if( (flags & 0xf0)!=0 || ((flags & 0x07)!=5 && (flags & 0x07)!=2) ){
rc = SQLITE_CORRUPT;
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
}
pCur->isTable = (flags & BTREE_INTKEY)!=0;
@@ -2585,7 +2556,7 @@ case OP_OpenWrite: { /* no-push */
*/
if( (pCur->isTable && pOp->p3type==P3_KEYINFO)
|| (pCur->isIndex && pOp->p3type!=P3_KEYINFO) ){
rc = SQLITE_CORRUPT;
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
}
break;
@@ -2603,13 +2574,14 @@ case OP_OpenWrite: { /* no-push */
break;
}
/* Opcode: OpenVirtual P1 * P3
/* Opcode: OpenVirtual P1 P2 P3
**
** Open a new cursor to a transient or virtual table.
** Open a new cursor P1 to a transient or virtual table.
** The cursor is always opened read/write even if
** the main database is read-only. The transient or virtual
** table is deleted automatically when the cursor is closed.
**
** P2 is the number of columns in the virtual table.
** The cursor points to a BTree table if P3==0 and to a BTree index
** if P3 is not 0. If P3 is not NULL, it points to a KeyInfo structure
** that defines the format of keys in the index.
@@ -2650,6 +2622,7 @@ case OP_OpenVirtual: { /* no-push */
pCx->pIncrKey = &pCx->bogusIncrKey;
}
}
pCx->nField = pOp->p2;
pCx->isIndex = !pCx->isTable;
break;
}
@@ -3035,6 +3008,24 @@ case OP_NotExists: { /* no-push */
break;
}
/* Opcode: Sequence P1 * *
**
** Push an integer onto the stack which is the next available
** sequence number for cursor P1. The sequence number on the
** cursor is incremented after the push.
*/
case OP_Sequence: {
int i = pOp->p1;
assert( pTos>=p->aStack );
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
pTos++;
pTos->i = p->apCsr[i]->seqCount++;
pTos->flags = MEM_Int;
break;
}
/* Opcode: NewRowid P1 P2 *
**
** Get a new integer record number (a.k.a "rowid") used as the key to a table.
@@ -3094,7 +3085,7 @@ case OP_NewRowid: {
cnt = 0;
if( (sqlite3BtreeFlags(pC->pCursor)&(BTREE_INTKEY|BTREE_ZERODATA)) !=
BTREE_INTKEY ){
rc = SQLITE_CORRUPT;
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
}
assert( (sqlite3BtreeFlags(pC->pCursor) & BTREE_INTKEY)!=0 );
@@ -3464,6 +3455,24 @@ case OP_Last: { /* no-push */
break;
}
/* Opcode: Sort P1 P2 *
**
** This opcode does exactly the same thing as OP_Rewind except that
** it increments an undocumented global variable used for testing.
**
** Sorting is accomplished by writing records into a sorting index,
** then rewinding that index and playing it back from beginning to
** end. We use the OP_Sort opcode instead of OP_Rewind to do the
** rewinding so that the global variable will be incremented and
** regression tests can determine whether or not the optimizer is
** correctly optimizing out sorts.
*/
case OP_Sort: { /* no-push */
sqlite3_sort_count++;
sqlite3_search_count--;
/* Fall through into OP_Rewind */
}
/* Opcode: Rewind P1 P2 *
**
** The next use of the Rowid or Column or Next instruction for P1
@@ -3685,13 +3694,12 @@ case OP_IdxLT: /* no-push */
case OP_IdxGT: /* no-push */
case OP_IdxGE: { /* no-push */
int i= pOp->p1;
BtCursor *pCrsr;
Cursor *pC;
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
assert( pTos>=p->aStack );
if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
if( (pC = p->apCsr[i])->pCursor!=0 ){
int res, rc;
assert( pTos->flags & MEM_Blob ); /* Created using OP_Make*Key */
@@ -4023,31 +4031,6 @@ case OP_FifoRead: {
break;
}
#ifndef SQLITE_OMIT_SUBQUERY
/* Opcode: AggContextPush * * *
**
** Save the state of the current aggregator. It is restored an
** AggContextPop opcode.
**
*/
case OP_AggContextPush: { /* no-push */
p->pAgg++;
assert( p->pAgg<&p->apAgg[p->nAgg] );
break;
}
/* Opcode: AggContextPop * * *
**
** Restore the aggregator to the state it was in when AggContextPush
** was last called. Any data in the current aggregator is deleted.
*/
case OP_AggContextPop: { /* no-push */
p->pAgg--;
assert( p->pAgg>=p->apAgg );
break;
}
#endif
#ifndef SQLITE_OMIT_TRIGGER
/* Opcode: ContextPush * * *
**
@@ -4063,7 +4046,7 @@ case OP_ContextPush: { /* no-push */
/* FIX ME: This should be allocated as part of the vdbe at compile-time */
if( i>=p->contextStackDepth ){
p->contextStackDepth = i+1;
p->contextStack = sqliteRealloc(p->contextStack, sizeof(Context)*(i+1));
sqlite3ReallocOrFree((void**)&p->contextStack, sizeof(Context)*(i+1));
if( p->contextStack==0 ) goto no_mem;
}
pContext = &p->contextStack[i];
@@ -4091,108 +4074,6 @@ case OP_ContextPop: { /* no-push */
}
#endif /* #ifndef SQLITE_OMIT_TRIGGER */
/* Opcode: SortInsert * * *
**
** The TOS is the key and the NOS is the data. Pop both from the stack
** and put them on the sorter. The key and data should have been
** made using the MakeRecord opcode.
*/
case OP_SortInsert: { /* no-push */
Mem *pNos = &pTos[-1];
Sorter *pSorter;
assert( pNos>=p->aStack );
if( Dynamicify(pTos, db->enc) ) goto no_mem;
pSorter = sqliteMallocRaw( sizeof(Sorter) );
if( pSorter==0 ) goto no_mem;
pSorter->pNext = 0;
if( p->pSortTail ){
p->pSortTail->pNext = pSorter;
}else{
p->pSort = pSorter;
}
p->pSortTail = pSorter;
assert( pTos->flags & MEM_Dyn );
pSorter->nKey = pTos->n;
pSorter->zKey = pTos->z;
pSorter->data.flags = MEM_Null;
rc = sqlite3VdbeMemMove(&pSorter->data, pNos);
pTos -= 2;
break;
}
/* Opcode: Sort * * P3
**
** Sort all elements on the sorter. The algorithm is a
** mergesort. The P3 argument is a pointer to a KeyInfo structure
** that describes the keys to be sorted.
*/
case OP_Sort: { /* no-push */
int i;
KeyInfo *pKeyInfo = (KeyInfo*)pOp->p3;
Sorter *pElem;
Sorter *apSorter[NSORT];
sqlite3_sort_count++;
pKeyInfo->enc = p->db->enc;
for(i=0; i<NSORT; i++){
apSorter[i] = 0;
}
while( p->pSort ){
pElem = p->pSort;
p->pSort = pElem->pNext;
pElem->pNext = 0;
for(i=0; i<NSORT-1; i++){
if( apSorter[i]==0 ){
apSorter[i] = pElem;
break;
}else{
pElem = Merge(apSorter[i], pElem, pKeyInfo);
apSorter[i] = 0;
}
}
if( i>=NSORT-1 ){
apSorter[NSORT-1] = Merge(apSorter[NSORT-1],pElem, pKeyInfo);
}
}
pElem = 0;
for(i=0; i<NSORT; i++){
pElem = Merge(apSorter[i], pElem, pKeyInfo);
}
p->pSort = pElem;
break;
}
/* Opcode: SortNext * P2 *
**
** Push the data for the topmost element in the sorter onto the
** stack, then remove the element from the sorter. If the sorter
** is empty, push nothing on the stack and instead jump immediately
** to instruction P2.
*/
case OP_SortNext: {
Sorter *pSorter = p->pSort;
CHECK_FOR_INTERRUPT;
if( pSorter!=0 ){
p->pSort = pSorter->pNext;
pTos++;
pTos->flags = MEM_Null;
rc = sqlite3VdbeMemMove(pTos, &pSorter->data);
sqliteFree(pSorter->zKey);
sqliteFree(pSorter);
}else{
pc = pOp->p2 - 1;
}
break;
}
/* Opcode: SortReset * * *
**
** Remove any elements that remain on the sorter.
*/
case OP_SortReset: { /* no-push */
sqlite3VdbeSorterReset(p);
break;
}
/* Opcode: MemStore P1 P2 *
**
** Write the top of the stack into memory location P1.
@@ -4296,64 +4177,49 @@ case OP_IfMemPos: { /* no-push */
break;
}
/* Opcode: AggReset P1 P2 P3
/* Opcode: MemNull P1 * *
**
** Reset the current aggregator context so that it no longer contains any
** data. Future aggregator elements will contain P2 values each and be sorted
** using the KeyInfo structure pointed to by P3.
**
** If P1 is non-zero, then only a single aggregator row is available (i.e.
** there is no GROUP BY expression). In this case it is illegal to invoke
** OP_AggFocus.
** Store a NULL in memory cell P1
*/
case OP_AggReset: { /* no-push */
assert( !pOp->p3 || pOp->p3type==P3_KEYINFO );
if( pOp->p1 ){
rc = sqlite3VdbeAggReset(0, p->pAgg, (KeyInfo *)pOp->p3);
p->pAgg->nMem = pOp->p2; /* Agg.nMem is used by AggInsert() */
rc = AggInsert(p->pAgg, 0, 0);
}else{
rc = sqlite3VdbeAggReset(db, p->pAgg, (KeyInfo *)pOp->p3);
p->pAgg->nMem = pOp->p2;
}
if( rc!=SQLITE_OK ){
goto abort_due_to_error;
}
p->pAgg->apFunc = sqliteMalloc( p->pAgg->nMem*sizeof(p->pAgg->apFunc[0]) );
if( p->pAgg->apFunc==0 ) goto no_mem;
case OP_MemNull: {
assert( pOp->p1>=0 && pOp->p1<p->nMem );
sqlite3VdbeMemSetNull(&p->aMem[pOp->p1]);
break;
}
/* Opcode: AggInit P1 P2 P3
/* Opcode: MemInt P1 P2 *
**
** Initialize the function parameters for an aggregate function.
** The aggregate will operate out of aggregate column P2.
** P3 is a pointer to the FuncDef structure for the function.
**
** The P1 argument is not used by this opcode. However if the SSE
** extension is compiled in, P1 is set to the number of arguments that
** will be passed to the aggregate function, if any. This is used
** by SSE to select the correct function when (de)serializing statements.
** Store the integer value P1 in memory cell P2.
*/
case OP_AggInit: { /* no-push */
int i = pOp->p2;
assert( i>=0 && i<p->pAgg->nMem );
p->pAgg->apFunc[i] = (FuncDef*)pOp->p3;
case OP_MemInt: {
assert( pOp->p2>=0 && pOp->p2<p->nMem );
sqlite3VdbeMemSetInt64(&p->aMem[pOp->p2], pOp->p1);
break;
}
/* Opcode: AggFunc * P2 P3
/* Opcode: MemMove P1 P2 *
**
** Move the content of memory cell P2 over to memory cell P1.
** Any prior content of P1 is erased. Memory cell P2 is left
** containing a NULL.
*/
case OP_MemMove: {
assert( pOp->p1>=0 && pOp->p1<p->nMem );
assert( pOp->p2>=0 && pOp->p2<p->nMem );
rc = sqlite3VdbeMemMove(&p->aMem[pOp->p1], &p->aMem[pOp->p2]);
break;
}
/* Opcode: AggStep P1 P2 P3
**
** Execute the step function for an aggregate. The
** function has P2 arguments. P3 is a pointer to the FuncDef
** structure that specifies the function.
** structure that specifies the function. Use memory location
** P1 as the accumulator.
**
** The top of the stack must be an integer which is the index of
** the aggregate column that corresponds to this aggregate function.
** Ideally, this index would be another parameter, but there are
** no free parameters left. The integer is popped from the stack.
** The P2 arguments are popped from the stack.
*/
case OP_AggFunc: { /* no-push */
case OP_AggStep: { /* no-push */
int n = pOp->p2;
int i;
Mem *pMem, *pRec;
@@ -4361,24 +4227,18 @@ case OP_AggFunc: { /* no-push */
sqlite3_value **apVal;
assert( n>=0 );
assert( pTos->flags==MEM_Int );
pRec = &pTos[-n];
pRec = &pTos[1-n];
assert( pRec>=p->aStack );
apVal = p->apArg;
assert( apVal || n==0 );
for(i=0; i<n; i++, pRec++){
apVal[i] = pRec;
storeTypeInfo(pRec, db->enc);
}
i = pTos->i;
assert( i>=0 && i<p->pAgg->nMem );
ctx.pFunc = (FuncDef*)pOp->p3;
pMem = &p->pAgg->pCurrent->aMem[i];
ctx.s.z = pMem->zShort; /* Space used for small aggregate contexts */
ctx.pAgg = pMem->z;
ctx.cnt = ++pMem->i;
assert( pOp->p1>=0 && pOp->p1<p->nMem );
ctx.pMem = pMem = &p->aMem[pOp->p1];
pMem->n++;
ctx.isError = 0;
ctx.pColl = 0;
if( ctx.pFunc->needCollSeq ){
@@ -4388,182 +4248,34 @@ case OP_AggFunc: { /* no-push */
ctx.pColl = (CollSeq *)pOp[-1].p3;
}
(ctx.pFunc->xStep)(&ctx, n, apVal);
pMem->z = ctx.pAgg;
pMem->flags = MEM_AggCtx;
popStack(&pTos, n+1);
popStack(&pTos, n);
if( ctx.isError ){
rc = SQLITE_ERROR;
}
break;
}
/* Opcode: AggFocus * P2 *
/* Opcode: AggFinal P1 P2 P3
**
** Pop the top of the stack and use that as an aggregator key. If
** an aggregator with that same key already exists, then make the
** aggregator the current aggregator and jump to P2. If no aggregator
** with the given key exists, create one and make it current but
** do not jump.
** Execute the finalizer function for an aggregate. P1 is
** the memory location that is the accumulator for the aggregate.
**
** The order of aggregator opcodes is important. The order is:
** AggReset AggFocus AggNext. In other words, you must execute
** AggReset first, then zero or more AggFocus operations, then
** zero or more AggNext operations. You must not execute an AggFocus
** in between an AggNext and an AggReset.
** P2 is the number of arguments that the step function takes and
** P3 is a pointer to the FuncDef for this function. The P2
** argument is not used by this opcode. It is only there to disambiguate
** functions that can take varying numbers of arguments. The
** P3 argument is only needed for the degenerate case where
** the step function was not previously called.
*/
case OP_AggFocus: { /* no-push */
char *zKey;
int nKey;
int res;
assert( pTos>=p->aStack );
Stringify(pTos, db->enc);
zKey = pTos->z;
nKey = pTos->n;
assert( p->pAgg->pBtree );
assert( p->pAgg->pCsr );
rc = sqlite3BtreeMoveto(p->pAgg->pCsr, zKey, nKey, &res);
if( rc!=SQLITE_OK ){
goto abort_due_to_error;
}
if( res==0 ){
rc = sqlite3BtreeData(p->pAgg->pCsr, 0, sizeof(AggElem*),
(char *)&p->pAgg->pCurrent);
pc = pOp->p2 - 1;
}else{
rc = AggInsert(p->pAgg, zKey, nKey);
}
if( rc!=SQLITE_OK ){
goto abort_due_to_error;
}
Release(pTos);
pTos--;
break;
}
/* Opcode: AggSet * P2 *
**
** Move the top of the stack into the P2-th field of the current
** aggregate. String values are duplicated into new memory.
*/
case OP_AggSet: { /* no-push */
AggElem *pFocus;
int i = pOp->p2;
pFocus = p->pAgg->pCurrent;
assert( pTos>=p->aStack );
if( pFocus==0 ) goto no_mem;
assert( i>=0 && i<p->pAgg->nMem );
rc = sqlite3VdbeMemMove(&pFocus->aMem[i], pTos);
pTos--;
case OP_AggFinal: { /* no-push */
Mem *pMem;
assert( pOp->p1>=0 && pOp->p1<p->nMem );
pMem = &p->aMem[pOp->p1];
assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
sqlite3VdbeMemFinalize(pMem, (FuncDef*)pOp->p3);
break;
}
/* Opcode: AggGet P1 P2 *
**
** Push a new entry onto the stack which is a copy of the P2-th field
** of the current aggregate. Strings are not duplicated so
** string values will be ephemeral.
**
** If P1 is zero, then the value is pulled out of the current aggregate
** in the current aggregate context. If P1 is greater than zero, then
** the value is taken from the P1th outer aggregate context. (i.e. if
** P1==1 then read from the aggregate context that will be restored
** by the next OP_AggContextPop opcode).
*/
case OP_AggGet: {
AggElem *pFocus;
int i = pOp->p2;
Agg *pAgg = &p->pAgg[-pOp->p1];
assert( pAgg>=p->apAgg );
pFocus = pAgg->pCurrent;
if( pFocus==0 ){
int res;
if( sqlite3_malloc_failed ) goto no_mem;
rc = sqlite3BtreeFirst(pAgg->pCsr, &res);
if( rc!=SQLITE_OK ){
return rc;
}
if( res!=0 ){
rc = AggInsert(pAgg, "", 1);
pFocus = pAgg->pCurrent;
}else{
rc = sqlite3BtreeData(pAgg->pCsr, 0, 4, (char *)&pFocus);
}
}
assert( i>=0 && i<pAgg->nMem );
pTos++;
sqlite3VdbeMemShallowCopy(pTos, &pFocus->aMem[i], MEM_Ephem);
if( pTos->flags&MEM_Str ){
sqlite3VdbeChangeEncoding(pTos, db->enc);
}
break;
}
/* Opcode: AggNext * P2 *
**
** Make the next aggregate value the current aggregate. The prior
** aggregate is deleted. If all aggregate values have been consumed,
** jump to P2.
**
** The order of aggregator opcodes is important. The order is:
** AggReset AggFocus AggNext. In other words, you must execute
** AggReset first, then zero or more AggFocus operations, then
** zero or more AggNext operations. You must not execute an AggFocus
** in between an AggNext and an AggReset.
*/
case OP_AggNext: { /* no-push */
int res;
assert( rc==SQLITE_OK );
CHECK_FOR_INTERRUPT;
if( p->pAgg->searching==0 ){
p->pAgg->searching = 1;
if( p->pAgg->pCsr ){
rc = sqlite3BtreeFirst(p->pAgg->pCsr, &res);
}else{
res = 0;
}
}else{
if( p->pAgg->pCsr ){
rc = sqlite3BtreeNext(p->pAgg->pCsr, &res);
}else{
res = 1;
}
}
if( rc!=SQLITE_OK ) goto abort_due_to_error;
if( res!=0 ){
pc = pOp->p2 - 1;
}else{
int i;
sqlite3_context ctx;
Mem *aMem;
if( p->pAgg->pCsr ){
rc = sqlite3BtreeData(p->pAgg->pCsr, 0, sizeof(AggElem*),
(char *)&p->pAgg->pCurrent);
if( rc!=SQLITE_OK ) goto abort_due_to_error;
}
aMem = p->pAgg->pCurrent->aMem;
for(i=0; i<p->pAgg->nMem; i++){
FuncDef *pFunc = p->pAgg->apFunc[i];
Mem *pMem = &aMem[i];
if( pFunc==0 || pFunc->xFinalize==0 ) continue;
ctx.s.flags = MEM_Null;
ctx.s.z = pMem->zShort;
ctx.pAgg = (void*)pMem->z;
ctx.cnt = pMem->i;
ctx.pFunc = pFunc;
pFunc->xFinalize(&ctx);
pMem->z = ctx.pAgg;
if( pMem->z && pMem->z!=pMem->zShort ){
sqliteFree( pMem->z );
}
*pMem = ctx.s;
if( pMem->flags & MEM_Short ){
pMem->z = pMem->zShort;
}
}
}
break;
}
/* Opcode: Vacuum * * *
**
+3 -2
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.97 2005/08/19 01:07:16 drh Exp $
** $Id: vdbe.h,v 1.99 2005/09/20 17:42:23 drh Exp $
*/
#ifndef _SQLITE_VDBE_H_
#define _SQLITE_VDBE_H_
@@ -104,11 +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);
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*);
+16 -67
View File
@@ -81,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.
@@ -113,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.
**
@@ -173,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
@@ -210,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 */
};
/*
@@ -265,9 +219,9 @@ struct Set {
*/
typedef struct FifoPage FifoPage;
struct FifoPage {
u16 nSlot; /* Number of entries aSlot[] */
u16 iWrite; /* Push the next value into this entry in aSlot[] */
i16 iRead; /* Read the next value from this entry in aSlot[] */
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 */
};
@@ -324,8 +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 */
Sorter *pSortTail; /* Last element on the pSort list */
int nVar; /* Number of entries in aVar[] */
Mem *aVar; /* Values for the OP_Variable opcode. */
char **azVar; /* Name of variables */
@@ -333,9 +285,6 @@ 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 */
Fifo sFifo; /* A list of ROWIDs */
int contextStackTop; /* Index of top element in the context stack */
@@ -358,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 */
};
/*
@@ -372,8 +322,6 @@ struct Vdbe {
** Function prototypes
*/
void sqlite3VdbeFreeCursor(Cursor*);
void sqlite3VdbeSorterReset(Vdbe*);
int sqlite3VdbeAggReset(sqlite3*, Agg *, KeyInfo *);
void sqliteVdbePopStack(Vdbe*,int);
int sqlite3VdbeCursorMoveto(Cursor*);
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
@@ -415,6 +363,7 @@ 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);
+44 -13
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
@@ -173,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 );
@@ -187,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.
@@ -213,6 +221,23 @@ int sqlite3_step(sqlite3_stmt *pStmt){
rc = SQLITE_MISUSE;
}
#ifndef SQLITE_OMIT_TRACE
/* Invoke the profile callback if there is one
*/
if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy ){
double rNow;
u64 elapseTime;
sqlite3OsCurrentTime(&rNow);
elapseTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0 - p->startTime;
assert( p->nOp>0 );
assert( p->aOp[p->nOp-1].opcode==OP_Noop );
assert( p->aOp[p->nOp-1].p3!=0 );
assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );
db->xProfile(db->pProfileArg, p->aOp[p->nOp-1].p3, elapseTime);
}
#endif
sqlite3Error(p->db, rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
return rc;
}
@@ -230,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;
}
/*
@@ -278,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;
@@ -304,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;
}
/*
+85 -208
View File
@@ -62,16 +62,18 @@ void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
** elements.
*/
static void resizeOpArray(Vdbe *p, int N){
if( p->magic==VDBE_MAGIC_RUN ){
assert( N==p->nOp );
p->nOpAlloc = N;
p->aOp = sqliteRealloc(p->aOp, N*sizeof(Op));
}else 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));
}
}
}
}
@@ -100,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];
@@ -145,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;
@@ -215,8 +218,8 @@ int sqlite3VdbeOpcodeNoPush(u8 op){
**
** This routine is called once after all opcodes have been inserted.
**
** Variable *pMaxFuncArgs is set to the maximum value of any P1 argument
** to an OP_Function or P2 to an OP_AggFunc opcode. This is used by
** 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
@@ -239,12 +242,7 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs, int *pMaxStack){
for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
u8 opcode = pOp->opcode;
/* Todo: Maybe OP_AggFunc should change to use P1 in the same
* way as OP_Function.
*/
if( opcode==OP_Function ){
if( pOp->p1>nMaxArgs ) nMaxArgs = pOp->p1;
}else if( opcode==OP_AggFunc ){
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 ){
@@ -302,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;
@@ -353,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
@@ -382,12 +415,7 @@ 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 ){
if( n==P3_DYNAMIC || n==P3_KEYINFO_HANDOFF ){
sqliteFree((void*)zP3);
}
if( n==P3_MEM ){
sqlite3ValueFree((sqlite3_value *)zP3);
}
freeP3(n, (void*)*(char**)&zP3);
return;
}
if( addr<0 || addr>=p->nOp ){
@@ -395,16 +423,19 @@ void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
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 );
@@ -577,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;
@@ -617,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;
@@ -658,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;
@@ -701,7 +732,6 @@ void sqlite3VdbeMakeReady(
+ 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[nStack];
@@ -712,17 +742,12 @@ void sqlite3VdbeMakeReady(
p->apArg = (Mem**)&p->aVar[nVar];
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;
}
@@ -763,155 +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);
}
p->pSortTail = 0;
}
/*
** 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;
}
/*
** Close a cursor and release all the resources that cursor happens
** to hold.
@@ -965,10 +841,6 @@ static void Cleanup(Vdbe *p){
}
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;
@@ -1090,6 +962,7 @@ static int vdbeCommit(sqlite3 *db){
*/
#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;
@@ -1125,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);
@@ -1141,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);
@@ -1485,17 +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);
}
if( pOp->p3type==P3_MEM ){
sqlite3ValueFree((sqlite3_value*)pOp->p3);
}
freeP3(pOp->p3type, pOp->p3);
}
sqliteFree(p->aOp);
}
@@ -1710,8 +1577,18 @@ int sqlite3VdbeSerialGet(
}
case 6: /* 8-byte signed integer */
case 7: { /* IEEE floating point */
u64 x = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
u32 y = (buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7];
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;
@@ -1849,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 ){
+5
View File
@@ -21,6 +21,9 @@
*/
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;
@@ -77,7 +80,9 @@ int sqlite3VdbeFifoPop(Fifo *pFifo, i64 *pVal){
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 ){
+34 -3
View File
@@ -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);
}
@@ -287,6 +317,7 @@ void sqlite3VdbeMemSetNull(Mem *pMem){
sqlite3VdbeMemRelease(pMem);
pMem->flags = MEM_Null;
pMem->type = SQLITE_NULL;
pMem->n = 0;
}
/*
@@ -699,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;
+98 -43
View File
@@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
** $Id: where.c,v 1.165 2005/08/24 03:52:19 drh Exp $
** $Id: where.c,v 1.179 2005/09/20 17:42:23 drh Exp $
*/
#include "sqliteInt.h"
@@ -232,7 +232,7 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, int flags){
/*
** This routine identifies subexpressions in the WHERE clause where
** each subexpression is separate by the AND operator or some other
** each subexpression is separated by the AND operator or some other
** operator specified in the op parameter. The WhereClause structure
** is filled with pointers to subexpressions. For example:
**
@@ -281,7 +281,7 @@ static Bitmask getMask(ExprMaskSet *pMaskSet, int iCursor){
**
** There is one cursor per table in the FROM clause. The number of
** tables in the FROM clause is limited by a test early in the
** sqlite3WhereBegin() routien. So we know that the pMaskSet->ix[]
** sqlite3WhereBegin() routine. So we know that the pMaskSet->ix[]
** array will never overflow.
*/
static void createMask(ExprMaskSet *pMaskSet, int iCursor){
@@ -303,7 +303,8 @@ static void createMask(ExprMaskSet *pMaskSet, int iCursor){
** translate the cursor numbers into bitmask values and OR all
** the bitmasks together.
*/
static Bitmask exprListTableUsage(ExprMaskSet *, ExprList *);
static Bitmask exprListTableUsage(ExprMaskSet*, ExprList*);
static Bitmask exprSelectTableUsage(ExprMaskSet*, Select*);
static Bitmask exprTableUsage(ExprMaskSet *pMaskSet, Expr *p){
Bitmask mask = 0;
if( p==0 ) return 0;
@@ -314,14 +315,7 @@ static Bitmask exprTableUsage(ExprMaskSet *pMaskSet, Expr *p){
mask = exprTableUsage(pMaskSet, p->pRight);
mask |= exprTableUsage(pMaskSet, p->pLeft);
mask |= exprListTableUsage(pMaskSet, p->pList);
if( p->pSelect ){
Select *pS = p->pSelect;
mask |= exprListTableUsage(pMaskSet, pS->pEList);
mask |= exprListTableUsage(pMaskSet, pS->pGroupBy);
mask |= exprListTableUsage(pMaskSet, pS->pOrderBy);
mask |= exprTableUsage(pMaskSet, pS->pWhere);
mask |= exprTableUsage(pMaskSet, pS->pHaving);
}
mask |= exprSelectTableUsage(pMaskSet, p->pSelect);
return mask;
}
static Bitmask exprListTableUsage(ExprMaskSet *pMaskSet, ExprList *pList){
@@ -334,6 +328,19 @@ static Bitmask exprListTableUsage(ExprMaskSet *pMaskSet, ExprList *pList){
}
return mask;
}
static Bitmask exprSelectTableUsage(ExprMaskSet *pMaskSet, Select *pS){
Bitmask mask;
if( pS==0 ){
mask = 0;
}else{
mask = exprListTableUsage(pMaskSet, pS->pEList);
mask |= exprListTableUsage(pMaskSet, pS->pGroupBy);
mask |= exprListTableUsage(pMaskSet, pS->pOrderBy);
mask |= exprTableUsage(pMaskSet, pS->pWhere);
mask |= exprTableUsage(pMaskSet, pS->pHaving);
}
return mask;
}
/*
** Return TRUE if the given operator is one of the operators that is
@@ -479,8 +486,11 @@ static int isLikeOrGlob(
Expr *pRight, *pLeft;
ExprList *pList;
int c, cnt;
int noCase;
char wc[3];
if( !sqlite3IsLikeFunction(db, pExpr, wc) ){
CollSeq *pColl;
if( !sqlite3IsLikeFunction(db, pExpr, &noCase, wc) ){
return 0;
}
pList = pExpr->pList;
@@ -492,6 +502,14 @@ static int isLikeOrGlob(
if( pLeft->op!=TK_COLUMN ){
return 0;
}
pColl = pLeft->pColl;
if( pColl==0 ){
pColl = db->pDfltColl;
}
if( (pColl->type!=SQLITE_COLL_BINARY || noCase) &&
(pColl->type!=SQLITE_COLL_NOCASE || !noCase) ){
return 0;
}
sqlite3DequoteExpr(pRight);
z = pRight->token.z;
for(cnt=0; (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2]; cnt++){}
@@ -514,7 +532,7 @@ static int isLikeOrGlob(
** to the standard form of "X <op> <expr>". If the expression is of
** the form "X <op> Y" where both X and Y are columns, then the original
** expression is unchanged and a new virtual expression of the form
** "Y <op> X" is added to the WHERE clause.
** "Y <op> X" is added to the WHERE clause and analyzed separately.
*/
static void exprAnalyze(
SrcList *pSrc, /* the FROM clause */
@@ -526,18 +544,26 @@ static void exprAnalyze(
Expr *pExpr = pTerm->pExpr;
Bitmask prereqLeft;
Bitmask prereqAll;
int idxRight;
int nPattern;
int isComplete;
if( sqlite3_malloc_failed ) return;
prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft);
pTerm->prereqRight = exprTableUsage(pMaskSet, pExpr->pRight);
pTerm->prereqAll = prereqAll = exprTableUsage(pMaskSet, pExpr);
if( pExpr->op==TK_IN ){
assert( pExpr->pRight==0 );
pTerm->prereqRight = exprListTableUsage(pMaskSet, pExpr->pList)
| exprSelectTableUsage(pMaskSet, pExpr->pSelect);
}else{
pTerm->prereqRight = exprTableUsage(pMaskSet, pExpr->pRight);
}
prereqAll = exprTableUsage(pMaskSet, pExpr);
if( ExprHasProperty(pExpr, EP_FromJoin) ){
prereqAll |= getMask(pMaskSet, pExpr->iRightJoinTable);
}
pTerm->prereqAll = prereqAll;
pTerm->leftCursor = -1;
pTerm->iParent = -1;
pTerm->operator = 0;
idxRight = -1;
if( allowedOp(pExpr->op) && (pTerm->prereqRight & prereqLeft)==0 ){
Expr *pLeft = pExpr->pLeft;
Expr *pRight = pExpr->pRight;
@@ -599,7 +625,13 @@ static void exprAnalyze(
#ifndef SQLITE_OMIT_OR_OPTIMIZATION
/* Attempt to convert OR-connected terms into an IN operator so that
** they can make use of indices.
** they can make use of indices. Example:
**
** x = expr1 OR expr2 = x OR x = expr3
**
** is converted into
**
** x IN (expr1,expr2,expr3)
*/
else if( pExpr->op==TK_OR ){
int ok;
@@ -647,7 +679,11 @@ static void exprAnalyze(
pDup->iColumn = iColumn;
}
pNew = sqlite3Expr(TK_IN, pDup, 0, 0);
if( pNew ) pNew->pList = pList;
if( pNew ){
pNew->pList = pList;
}else{
sqlite3ExprListDelete(pList);
}
pTerm->pExpr = pNew;
pTerm->flags |= TERM_DYNAMIC;
exprAnalyze(pSrc, pMaskSet, pWC, idxTerm);
@@ -725,10 +761,10 @@ static int isSortingIndex(
int nEqCol, /* Number of index columns with == constraints */
int *pbRev /* Set to 1 if ORDER BY is DESC */
){
int i, j; /* Loop counters */
int sortOrder; /* Which direction we are sorting */
int nTerm; /* Number of ORDER BY terms */
struct ExprList_item *pTerm; /* A term of the ORDER BY clause */
int i, j; /* Loop counters */
int sortOrder = SQLITE_SO_ASC; /* Which direction we are sorting */
int nTerm; /* Number of ORDER BY terms */
struct ExprList_item *pTerm; /* A term of the ORDER BY clause */
sqlite3 *db = pParse->db;
assert( pOrderBy!=0 );
@@ -802,7 +838,8 @@ static int sortableByRowid(
assert( pOrderBy!=0 );
assert( pOrderBy->nExpr>0 );
p = pOrderBy->a[0].pExpr;
if( p->op==TK_COLUMN && p->iTable==base && p->iColumn==-1 ){
if( pOrderBy->nExpr==1 && p->op==TK_COLUMN && p->iTable==base
&& p->iColumn==-1 ){
*pbRev = pOrderBy->a[0].sortOrder;
return 1;
}
@@ -810,7 +847,7 @@ static int sortableByRowid(
}
/*
** Prepare a crude estimate of the logorithm of the input value.
** Prepare a crude estimate of the logarithm of the input value.
** The results need not be exact. This is only used for estimating
** the total cost of performing operatings with O(logN) or O(NlogN)
** complexity. Because N is just a guess, it is no great tragedy if
@@ -1069,11 +1106,12 @@ static double bestIndex(
** of a LEFT OUTER JOIN. In (1), the term is not disabled.
**
** Disabling a term causes that term to not be tested in the inner loop
** of the join. Disabling is an optimization. We would get the correct
** results if nothing were ever disabled, but joins might run a little
** slower. The trick is to disable as much as we can without disabling
** too much. If we disabled in (1), we'd get the wrong answer.
** See ticket #813.
** of the join. Disabling is an optimization. When terms are satisfied
** by indices, we disable them to prevent redundant tests in the inner
** loop. We would get the correct results if nothing were ever disabled,
** but joins might run a little slower. The trick is to disable as much
** as we can without disabling too much. If we disabled in (1), we'd get
** the wrong answer. See ticket #813.
*/
static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
if( pTerm
@@ -1142,8 +1180,9 @@ static void codeEqualityTerm(
sqlite3VdbeAddOp(v, OP_Rewind, iTab, brk);
VdbeComment((v, "# %.*s", pX->span.n, pX->span.z));
pLevel->nIn++;
pLevel->aInLoop = aIn = sqliteRealloc(pLevel->aInLoop,
sqlite3ReallocOrFree((void**)&pLevel->aInLoop,
sizeof(pLevel->aInLoop[0])*3*pLevel->nIn);
aIn = pLevel->aInLoop;
if( aIn ){
aIn += pLevel->nIn*3 - 3;
aIn[0] = OP_Next;
@@ -1229,7 +1268,7 @@ static void codeAllEqualityTerms(
}
}
#ifdef SQLITE_TEST
#if defined(SQLITE_TEST)
/*
** The following variable holds a text description of query plan generated
** by the most recent call to sqlite3WhereBegin(). Each call to WhereBegin
@@ -1387,7 +1426,7 @@ WhereInfo *sqlite3WhereBegin(
/* Analyze all of the subexpressions. Note that exprAnalyze() might
** add new virtual terms onto the end of the WHERE clause. We do not
** want to analyze these virtual terms, so start analyzing at the end
** and work forward so that they added virtual terms are never processed.
** and work forward so that the added virtual terms are never processed.
*/
for(i=0; i<pTabList->nSrc; i++){
createMask(&maskSet, pTabList->a[i].iCursor);
@@ -1415,6 +1454,7 @@ WhereInfo *sqlite3WhereBegin(
pTabItem = pTabList->a;
pLevel = pWInfo->a;
andFlags = ~0;
TRACE(("*** Optimizer Start ***\n"));
for(i=iFrom=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
Index *pIdx; /* Index for FROM table at pTabItem */
int flags; /* Flags asssociated with pIdx */
@@ -1435,7 +1475,7 @@ WhereInfo *sqlite3WhereBegin(
continue;
}
cost = bestIndex(pParse, &wc, pTabItem, notReady,
(j==0 && ppOrderBy) ? *ppOrderBy : 0,
(i==0 && ppOrderBy) ? *ppOrderBy : 0,
&pIdx, &flags, &nEq);
if( cost<lowestCost ){
lowestCost = cost;
@@ -1444,12 +1484,14 @@ WhereInfo *sqlite3WhereBegin(
bestNEq = nEq;
bestJ = j;
}
if( (pTabItem->jointype & JT_LEFT)!=0
|| (j>0 && (pTabItem[-1].jointype & JT_LEFT)!=0)
if( (pTabItem->jointype & (JT_LEFT|JT_CROSS))!=0
|| (j>0 && (pTabItem[-1].jointype & (JT_LEFT|JT_CROSS))!=0)
){
break;
}
}
TRACE(("*** Optimizer choose table %d for loop %d\n", bestJ,
pLevel-pWInfo->a));
if( (bestFlags & WHERE_ORDERBY)!=0 ){
*ppOrderBy = 0;
}
@@ -1467,6 +1509,7 @@ WhereInfo *sqlite3WhereBegin(
notReady &= ~getMask(&maskSet, pTabList->a[bestJ].iCursor);
pLevel->iFrom = bestJ;
}
TRACE(("*** Optimizer Finished ***\n"));
/* If the total query only selects a single row, then the ORDER BY
** clause is irrelevant.
@@ -1485,6 +1528,20 @@ WhereInfo *sqlite3WhereBegin(
Index *pIx;
int iIdxCur = pLevel->iIdxCur;
#ifndef SQLITE_OMIT_EXPLAIN
if( pParse->explain==2 ){
char *zMsg;
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
zMsg = sqlite3MPrintf("TABLE %s", pItem->zName);
if( pItem->zAlias ){
zMsg = sqlite3MPrintf("%z AS %s", zMsg, pItem->zAlias);
}
if( (pIx = pLevel->pIdx)!=0 ){
zMsg = sqlite3MPrintf("%z WITH INDEX %s", zMsg, pIx->zName);
}
sqlite3VdbeOp3(v, OP_Explain, i, pLevel->iFrom, zMsg, P3_DYNAMIC);
}
#endif /* SQLITE_OMIT_EXPLAIN */
pTabItem = &pTabList->a[pLevel->iFrom];
pTab = pTabItem->pTab;
if( pTab->isTransient || pTab->pSelect ) continue;
@@ -1540,8 +1597,7 @@ WhereInfo *sqlite3WhereBegin(
if( pLevel->iFrom>0 && (pTabItem[-1].jointype & JT_LEFT)!=0 ){
if( !pParse->nMem ) pParse->nMem++;
pLevel->iLeftJoin = pParse->nMem++;
sqlite3VdbeAddOp(v, OP_Null, 0, 0);
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iLeftJoin, 1);
sqlite3VdbeAddOp(v, OP_MemInt, 0, pLevel->iLeftJoin);
VdbeComment((v, "# init LEFT JOIN no-match flag"));
}
@@ -1821,8 +1877,7 @@ WhereInfo *sqlite3WhereBegin(
*/
if( pLevel->iLeftJoin ){
pLevel->top = sqlite3VdbeCurrentAddr(v);
sqlite3VdbeAddOp(v, OP_Integer, 1, 0);
sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iLeftJoin, 1);
sqlite3VdbeAddOp(v, OP_MemInt, 1, pLevel->iLeftJoin);
VdbeComment((v, "# record LEFT JOIN hit"));
for(pTerm=wc.a, j=0; j<wc.nTerm; j++, pTerm++){
if( pTerm->flags & (TERM_VIRTUAL|TERM_CODED) ) continue;
@@ -1924,13 +1979,13 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
}
if( pLevel->iLeftJoin ){
int addr;
addr = sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iLeftJoin, 0);
sqlite3VdbeAddOp(v, OP_NotNull, 1, addr+4 + (pLevel->iIdxCur>=0));
addr = sqlite3VdbeAddOp(v, OP_IfMemPos, pLevel->iLeftJoin, 0);
sqlite3VdbeAddOp(v, OP_NullRow, pTabList->a[i].iCursor, 0);
if( pLevel->iIdxCur>=0 ){
sqlite3VdbeAddOp(v, OP_NullRow, pLevel->iIdxCur, 0);
}
sqlite3VdbeAddOp(v, OP_Goto, 0, pLevel->top);
sqlite3VdbeJumpHere(v, addr);
}
}
+9 -3
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library.
# This file implements tests for the ANALYZE command.
#
# $Id: analyze.test,v 1.3 2005/08/19 00:14:43 drh Exp $
# $Id: analyze.test,v 1.5 2005/09/10 22:40:54 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -45,11 +45,17 @@ do_test analyze-1.4 {
SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1'
}
} {0}
do_test analyze-1.5 {
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'
@@ -172,7 +178,7 @@ do_test analyze-3.7 {
ANALYZE t2;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1}}
} {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;
+9 -5
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.17 2005/03/09 13:09:45 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
@@ -504,7 +508,7 @@ do_test autovacuum-4.1 {
execsql {
SELECT sum(a) FROM av1;
}
} {5049.0}
} {5049}
do_test autovacuum-4.2 {
catchsql {
CREATE UNIQUE INDEX av1_i ON av1(a);
@@ -514,7 +518,7 @@ do_test autovacuum-4.3 {
execsql {
SELECT sum(a) FROM av1;
}
} {5049.0}
} {5049}
do_test autovacuum-4.4 {
execsql {
COMMIT;
+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 )"
+2 -1
View File
@@ -10,7 +10,7 @@
#***********************************************************************
# This file test the busy handler
#
# $Id: busy.test,v 1.1 2005/07/09 02:16:03 drh Exp $
# $Id: busy.test,v 1.2 2005/09/17 18:02:37 drh Exp $
set testdir [file dirname $argv0]
@@ -29,6 +29,7 @@ proc busy x {
if {$x>2} {return 1}
return 0
}
set busyargs {}
do_test busy-1.2 {
db busy busy
db2 eval {begin exclusive}
+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;
}
+5 -5
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.4 2005/04/01 10:47:40 drh Exp $
# $Id: collate5.test,v 1.5 2005/09/07 22:48:16 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -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;
+10 -10
View File
@@ -13,7 +13,7 @@
# This file implements tests for the conflict resolution extension
# to SQLite.
#
# $Id: conflict.test,v 1.24 2005/06/07 02:12:30 drh Exp $
# $Id: conflict.test,v 1.25 2005/09/01 03:07:45 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -281,18 +281,18 @@ do_test conflict-6.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 0
3 IGNORE UPDATE 0 {6 7 3 9} 1 0
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 0
8 IGNORE {UPDATE OR REPLACE} 0 {7 6 9} 1 0
9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0
10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 0
11 ROLLBACK {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0
12 {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0
13 {} {UPDATE OR REPLACE} 0 {7 6 9} 1 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
+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}
+57
View File
@@ -0,0 +1,57 @@
# 2005 August 24
#
# 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 a test of the DELETE command where a
# large number of rows are deleted.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Create a table that contains a large number of rows.
#
do_test delete3-1.1 {
execsql {
CREATE TABLE t1(x integer primary key);
BEGIN;
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES(2);
INSERT INTO t1 SELECT x+2 FROM t1;
INSERT INTO t1 SELECT x+4 FROM t1;
INSERT INTO t1 SELECT x+8 FROM t1;
INSERT INTO t1 SELECT x+16 FROM t1;
INSERT INTO t1 SELECT x+32 FROM t1;
INSERT INTO t1 SELECT x+64 FROM t1;
INSERT INTO t1 SELECT x+128 FROM t1;
INSERT INTO t1 SELECT x+256 FROM t1;
INSERT INTO t1 SELECT x+512 FROM t1;
INSERT INTO t1 SELECT x+1024 FROM t1;
INSERT INTO t1 SELECT x+2048 FROM t1;
INSERT INTO t1 SELECT x+4096 FROM t1;
INSERT INTO t1 SELECT x+8192 FROM t1;
INSERT INTO t1 SELECT x+16384 FROM t1;
INSERT INTO t1 SELECT x+32768 FROM t1;
INSERT INTO t1 SELECT x+65536 FROM t1;
INSERT INTO t1 SELECT x+131072 FROM t1;
INSERT INTO t1 SELECT x+262144 FROM t1;
COMMIT;
SELECT count(*) FROM t1;
}
} {524288}
do_test delete3-1.2 {
execsql {
DELETE FROM t1 WHERE x%2==0;
SELECT count(*) FROM t1;
}
} {262144}
integrity_check delete3-1.3
finish_test
+38 -3
View File
@@ -12,7 +12,7 @@
# focus of this file is testing for correct handling of disk full
# errors.
#
# $Id: diskfull.test,v 1.2 2005/08/11 02:10:19 drh Exp $
# $Id: diskfull.test,v 1.3 2005/09/09 10:46:19 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -22,19 +22,54 @@ do_test diskfull-1.1 {
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(randstr(1000,1000));
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
CREATE INDEX t1i1 ON t1(x);
CREATE TABLE t2 AS SELECT x AS a, x AS b FROM t1;
CREATE INDEX t2i1 ON t2(b);
}
} {}
do_test diskfull-1.2 {
set sqlite_diskfull_pending 0
integrity_check diskfull-1.2
do_test diskfull-1.3 {
set sqlite_diskfull_pending 1
catchsql {
INSERT INTO t1 SELECT * FROM t1;
}
} {1 {database or disk is full}}
do_test diskfull-1.3 {
set sqlite_diskfull_pending 0
integrity_check diskfull-1.4
do_test diskfull-1.5 {
set sqlite_diskfull_pending 1
catchsql {
DELETE FROM t1;
}
} {1 {database or disk is full}}
set sqlite_diskfull_pending 0
integrity_check diskfull-1.6
set go 1
set i 0
while {$go} {
incr i
do_test diskfull-2.$i.1 {
set sqlite_diskfull_pending $i
set sqlite_diskfull 0
set r [catchsql {VACUUM}]
if {!$sqlite_diskfull} {
set r {1 {database or disk is full}}
set go 0
}
if {$r=="1 {disk I/O error}"} {
set r {1 {database or disk is full}}
}
set r
} {1 {database or disk is full}}
set sqlite_diskfull_pending 0
db close
sqlite3 db test.db
integrity_check diskfull-2.$i.2
}
finish_test
+57
View File
@@ -0,0 +1,57 @@
# 2005 September 11
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is the DISTINCT modifier on aggregate functions.
#
# $Id: distinctagg.test,v 1.2 2005/09/12 23:03:17 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test distinctagg-1.1 {
execsql {
CREATE TABLE t1(a,b,c);
INSERT INTO t1 VALUES(1,2,3);
INSERT INTO t1 VALUES(1,3,4);
INSERT INTO t1 VALUES(1,3,5);
SELECT count(distinct a),
count(distinct b),
count(distinct c),
count(all a) FROM t1;
}
} {1 2 3 3}
do_test distinctagg-1.2 {
execsql {
SELECT b, count(distinct c) FROM t1 GROUP BY b ORDER BY b
}
} {2 1 3 2}
do_test distinctagg-1.3 {
execsql {
INSERT INTO t1 SELECT a+1, b+3, c+5 FROM t1;
INSERT INTO t1 SELECT a+2, b+6, c+10 FROM t1;
INSERT INTO t1 SELECT a+4, b+12, c+20 FROM t1;
SELECT count(*), count(distinct a), count(distinct b) FROM t1
}
} {24 8 16}
do_test distinctagg-1.4 {
execsql {
SELECT a, count(distinct c) FROM t1 GROUP BY a ORDER BY a
}
} {1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3}
do_test distinctagg-2.1 {
catchsql {
SELECT count(distinct) FROM t1;
}
} {1 {DISTINCT in aggregate must be followed by an expression}}
finish_test
+2 -1
View File
@@ -13,7 +13,7 @@
# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
# UTF-16be).
#
# $Id: enc2.test,v 1.22 2005/02/26 17:31:28 drh Exp $
# $Id: enc2.test,v 1.23 2005/09/01 12:16:29 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -185,6 +185,7 @@ proc test_collate {enc lhs rhs} {
set l [lsearch -exact $::values $lhs]
set r [lsearch -exact $::values $rhs]
set res [expr $l - $r]
# puts "enc=$enc lhs=$lhs/$l rhs=$rhs/$r res=$res"
return $res
}
+45 -2
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing built-in functions.
#
# $Id: func.test,v 1.37 2005/08/12 23:20:53 drh Exp $
# $Id: func.test,v 1.40 2005/09/08 20:37:44 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -254,7 +254,7 @@ do_test func-8.1 {
execsql {
SELECT sum(a), count(a), round(avg(a),2), min(a), max(a), count(*) FROM t2;
}
} {68236.0 3 22745.33 1 67890 5}
} {68236 3 22745.33 1 67890 5}
do_test func-8.2 {
execsql {
SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t2;
@@ -495,6 +495,49 @@ do_test func-17.1 {
}
} {1 {Error %d with %s percents %p}}
# The SUM function should return integer results when all inputs are integer.
#
do_test func-18.1 {
execsql {
CREATE TABLE t5(x);
INSERT INTO t5 VALUES(1);
INSERT INTO t5 VALUES(-99);
INSERT INTO t5 VALUES(10000);
SELECT sum(x) FROM t5;
}
} {9902}
do_test func-18.2 {
execsql {
INSERT INTO t5 VALUES(0.0);
SELECT sum(x) FROM t5;
}
} {9902.0}
# The sum of nothing is NULL. But the sum of all NULLs is NULL.
#
do_test func-18.3 {
execsql {
DELETE FROM t5;
SELECT sum(x) FROM t5;
}
} {{}}
do_test func-18.4 {
execsql {
INSERT INTO t5 VALUES(NULL);
SELECT sum(x) FROM t5
}
} {{}}
do_test func-18.5 {
execsql {
INSERT INTO t5 VALUES(NULL);
SELECT sum(x) FROM t5
}
} {{}}
do_test func-18.6 {
execsql {
INSERT INTO t5 VALUES(123);
SELECT sum(x) FROM t5
}
} {123}
finish_test
+62
View File
@@ -0,0 +1,62 @@
# 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.
#
# This file implements tests for left outer joins containing ON
# clauses that restrict the scope of the left term of the join.
#
# $Id: join5.test,v 1.1 2005/09/19 21:05:50 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test join5-1.1 {
execsql {
BEGIN;
CREATE TABLE t1(a integer primary key, b integer, c integer);
CREATE TABLE t2(x integer primary key, y);
CREATE TABLE t3(p integer primary key, q);
INSERT INTO t3 VALUES(11,'t3-11');
INSERT INTO t3 VALUES(12,'t3-12');
INSERT INTO t2 VALUES(11,'t2-11');
INSERT INTO t2 VALUES(12,'t2-12');
INSERT INTO t1 VALUES(1, 5, 0);
INSERT INTO t1 VALUES(2, 11, 2);
INSERT INTO t1 VALUES(3, 12, 1);
COMMIT;
}
} {}
do_test join5-1.2 {
execsql {
select * from t1 left join t2 on t1.b=t2.x and t1.c=1
}
} {1 5 0 {} {} 2 11 2 {} {} 3 12 1 12 t2-12}
do_test join5-1.3 {
execsql {
select * from t1 left join t2 on t1.b=t2.x where t1.c=1
}
} {3 12 1 12 t2-12}
do_test join5-1.4 {
execsql {
select * from t1 left join t2 on t1.b=t2.x and t1.c=1
left join t3 on t1.b=t3.p and t1.c=2
}
} {1 5 0 {} {} {} {} 2 11 2 {} {} 11 t3-11 3 12 1 12 t2-12 {} {}}
do_test join5-1.5 {
execsql {
select * from t1 left join t2 on t1.b=t2.x and t1.c=1
left join t3 on t1.b=t3.p where t1.c=2
}
} {2 11 2 {} {} 11 t3-11}
finish_test
+54 -1
View File
@@ -13,7 +13,7 @@
# in particular the optimizations that occur to help those operators
# run faster.
#
# $Id: like.test,v 1.2 2005/08/19 00:14:43 drh Exp $
# $Id: like.test,v 1.3 2005/08/28 17:00:26 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -312,5 +312,58 @@ do_test like-4.6 {
set sqlite_like_count
} 12
# Collating sequences on the index disable the LIKE optimization.
# Or if the NOCASE collating sequence is used, the LIKE optimization
# is enabled when case_sensitive_like is OFF.
#
do_test like-5.1 {
execsql {PRAGMA case_sensitive_like=off}
set sqlite_like_count 0
queryplan {
SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1
}
} {ABC {ABC abc xyz} abc abcd nosort {} i1}
do_test like-5.2 {
set sqlite_like_count
} 12
do_test like-5.3 {
execsql {
CREATE TABLE t2(x COLLATE NOCASE);
INSERT INTO t2 SELECT * FROM t1;
CREATE INDEX i2 ON t2(x COLLATE NOCASE);
}
set sqlite_like_count 0
queryplan {
SELECT x FROM t2 WHERE x LIKE 'abc%' ORDER BY 1
}
} {abc ABC {ABC abc xyz} abcd nosort {} i2}
do_test like-5.4 {
set sqlite_like_count
} 0
do_test like-5.5 {
execsql {
PRAGMA case_sensitive_like=on;
}
set sqlite_like_count 0
queryplan {
SELECT x FROM t2 WHERE x LIKE 'abc%' ORDER BY 1
}
} {abc abcd nosort {} i2}
do_test like-5.6 {
set sqlite_like_count
} 12
do_test like-5.7 {
execsql {
PRAGMA case_sensitive_like=off;
}
set sqlite_like_count 0
queryplan {
SELECT x FROM t2 WHERE x GLOB 'abc*' ORDER BY 1
}
} {abc abcd nosort {} i2}
do_test like-5.8 {
set sqlite_like_count
} 12
finish_test
+2 -2
View File
@@ -12,7 +12,7 @@
# focus of this file is testing the LIMIT ... OFFSET ... clause
# of SELECT statements.
#
# $Id: limit.test,v 1.24 2005/02/05 12:48:49 danielk1977 Exp $
# $Id: limit.test,v 1.25 2005/09/08 10:37:01 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -184,7 +184,7 @@ do_test limit-5.5 {
ORDER BY 1, 2 LIMIT 1000;
SELECT count(*), sum(x), sum(y), min(x), max(x), min(y), max(y) FROM t5;
}
} {1000 1528204.0 593161.0 0 3107 505 1005}
} {1000 1528204 593161 0 3107 505 1005}
# There is some contraversy about whether LIMIT 0 should be the same as
# no limit at all or if LIMIT 0 should result in zero output rows.
+5 -1
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is database locks between competing processes.
#
# $Id: lock2.test,v 1.4 2004/11/10 15:27:38 danielk1977 Exp $
# $Id: lock2.test,v 1.6 2005/09/17 16:48:19 drh Exp $
set testdir [file dirname $argv0]
@@ -88,11 +88,15 @@ close $f
#
do_test lock2-1.1 {
set ::tf1 [launch_testfixture]
testfixture $::tf1 "set sqlite_pending_byte $::sqlite_pending_byte"
testfixture $::tf1 {
sqlite3 db test.db -key xyzzy
db eval {select * from sqlite_master}
}
} {}
do_test lock2-1.1.1 {
execsql {pragma lock_status}
} {main unlocked temp closed}
do_test lock2-1.2 {
execsql {
BEGIN;
+1 -2
View File
@@ -14,7 +14,7 @@
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.23 2005/08/19 01:07:16 drh Exp $
# $Id: malloc.test,v 1.24 2005/09/08 00:13:28 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -56,7 +56,6 @@ proc do_malloc_test {tn args} {
set ::go 1
for {set ::n 1} {$::go} {incr ::n} {
do_test malloc-$tn.$::n {
sqlite_malloc_fail 0
+3 -3
View File
@@ -13,7 +13,7 @@
# aggregate min() and max() functions and which are handled as
# as a special case.
#
# $Id: minmax.test,v 1.16 2005/01/21 04:25:47 danielk1977 Exp $
# $Id: minmax.test,v 1.18 2005/09/08 19:45:58 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -143,11 +143,11 @@ ifcapable {compound && subquery} {
} {1 20}
do_test minmax-4.2 {
execsql {
SELECT y, sum(x) FROM
SELECT y, coalesce(sum(x),0) FROM
(SELECT null, y+1 FROM t1 UNION SELECT * FROM t1)
GROUP BY y ORDER BY y;
}
} {1 1.0 2 5.0 3 22.0 4 92.0 5 90.0 6 0.0}
} {1 1 2 5 3 22 4 92 5 90 6 0}
do_test minmax-4.3 {
execsql {
SELECT y, count(x), count(*) FROM
+3 -3
View File
@@ -13,7 +13,7 @@
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc1.test,v 1.37 2005/08/19 03:03:52 drh Exp $
# $Id: misc1.test,v 1.38 2005/09/08 10:37:01 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -115,11 +115,11 @@ do_test misc1-2.1 {
do_test misc1-2.2 {
execsql {SELECT sum(one), two, four FROM agger
GROUP BY two, four ORDER BY sum(one) desc}
} {8.0 two no 6.0 one yes 4.0 two yes 3.0 thr yes}
} {8 two no 6 one yes 4 two yes 3 thr yes}
do_test misc1-2.3 {
execsql {SELECT sum((one)), (two), (four) FROM agger
GROUP BY (two), (four) ORDER BY sum(one) desc}
} {8.0 two no 6.0 one yes 4.0 two yes 3.0 thr yes}
} {8 two no 6 one yes 4 two yes 3 thr yes}
# Here's a test for a bug found by Joel Lucsy. The code below
# was causing an assertion failure.
+11 -5
View File
@@ -13,7 +13,7 @@
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc4.test,v 1.16 2005/03/29 03:11:00 danielk1977 Exp $
# $Id: misc4.test,v 1.20 2005/09/08 10:37:01 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -96,10 +96,17 @@ do_test misc4-3.1 {
INSERT INTO Table2 VALUES(1, 'z');
INSERT INTO Table2 VALUES (1, 'a');
SELECT ID, Value FROM Table1
UNION SELECT ID, max(Value) FROM Table2 GROUP BY 1,2
UNION SELECT ID, max(Value) FROM Table2 GROUP BY 1
ORDER BY 1, 2;
}
} {{} {} 1 x 1 z}
} {1 x 1 z}
do_test misc4-3.2 {
catchsql {
SELECT ID, Value FROM Table1
UNION SELECT ID, max(Value) FROM Table2 GROUP BY 1, 2
ORDER BY 1, 2;
}
} {1 {aggregate functions are not allowed in the GROUP BY clause}}
} ;# ifcapable compound
# Ticket #1047. Make sure column types are preserved in subqueries.
@@ -121,7 +128,7 @@ ifcapable subquery {
from a, (select key,sum(period) from b group by key) as x
where a.key=x.key;
}
} {01 data01 01 3.0 +1 data+1 +1 7.0}
} {01 data01 01 3 +1 data+1 +1 7}
# This test case tests the same property as misc4-4.1, but it is
# a bit smaller which makes it easier to work with while debugging.
@@ -177,4 +184,3 @@ do_test misc4-6.2 {
} {1}
finish_test
+1 -1
View File
@@ -100,7 +100,7 @@ do_test null-3.1 {
select count(*), count(b), count(c), sum(b), sum(c),
avg(b), avg(c), min(b), max(b) from t1;
}
} {7 4 6 2.0 3.0 0.5 0.5 0 1}
} {7 4 6 2 3 0.5 0.5 0 1}
# Check to see how WHERE clauses handle NULL values. A NULL value
# is the same as UNKNOWN. The WHERE clause should only select those
+15 -2
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the sqlite_*_printf() interface.
#
# $Id: printf.test,v 1.17 2005/08/19 02:26:27 drh Exp $
# $Id: printf.test,v 1.19 2005/09/06 21:40:45 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -110,7 +110,7 @@ do_test printf-4.4 {
do_test printf-5.1 {
set x [sqlite3_mprintf_str {%d %d %100000s} 0 0 {Hello}]
string length $x
} {994}
} {344}
do_test printf-5.2 {
sqlite3_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello}
} {-9 -10 (HelloHello) %}
@@ -219,4 +219,17 @@ do_test printf-12.1 {
sqlite3_mprintf_double {%d %d %.2000g} 1 1 1.0
} {1 1 1}
# Floating point boundary cases
#
do_test printf-13.1 {
sqlite3_mprintf_hexdouble %.20f 4024000000000000
} {10.00000000000000000000}
do_test printf-13.2 {
sqlite3_mprintf_hexdouble %.20f 4197d78400000000
} {100000000.00000000000000000000}
do_test printf-13.3 {
sqlite3_mprintf_hexdouble %.20f 4693b8b5b5056e17
} {100000000000000000000000000000000.00000000000000000000}
finish_test
+5 -5
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: select1.test,v 1.42 2005/01/21 04:25:47 danielk1977 Exp $
# $Id: select1.test,v 1.43 2005/09/08 10:37:01 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -199,7 +199,7 @@ do_test select1-2.14 {
do_test select1-2.15 {
set v [catch {execsql {SELECT Sum(f1) FROM test1}} msg]
lappend v $msg
} {0 44.0}
} {0 44}
do_test select1-2.16 {
set v [catch {execsql {SELECT sum(f1,f2) FROM test1}} msg]
lappend v $msg
@@ -207,10 +207,10 @@ do_test select1-2.16 {
do_test select1-2.17 {
set v [catch {execsql {SELECT SUM(f1)+1 FROM test1}} msg]
lappend v $msg
} {0 45.0}
} {0 45}
do_test select1-2.17.1 {
execsql {SELECT sum(a) FROM t3}
} {44.0}
} {44}
do_test select1-2.18 {
set v [catch {execsql {SELECT XYZZY(f1) FROM test1}} msg]
lappend v $msg
@@ -218,7 +218,7 @@ do_test select1-2.18 {
do_test select1-2.19 {
set v [catch {execsql {SELECT SUM(min(f1,f2)) FROM test1}} msg]
lappend v $msg
} {0 44.0}
} {0 44}
do_test select1-2.20 {
set v [catch {execsql {SELECT SUM(min(f1)) FROM test1}} msg]
lappend v $msg
+16 -2
View File
@@ -12,7 +12,7 @@
# focus of this file is testing aggregate functions and the
# GROUP BY and HAVING clauses of SELECT statements.
#
# $Id: select3.test,v 1.13 2005/04/01 10:47:40 drh Exp $
# $Id: select3.test,v 1.16 2005/09/08 20:37:44 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -44,7 +44,7 @@ do_test select3-1.2 {
SELECT min(n),min(log),max(n),max(log),sum(n),sum(log),avg(n),avg(log)
FROM t1
}
} {1 0 31 5 496.0 124.0 16.0 4.0}
} {1 0 31 5 496 124 16.0 4.0}
do_test select3-1.3 {
execsql {SELECT max(n)/avg(n), max(log)/avg(log) FROM t1}
} {1.9375 1.25}
@@ -220,6 +220,20 @@ do_test select3-6.8 {
}
} {5 17 4 9 3 5 2 3 1 2 0 1}
# Sometimes an aggregate query can return no rows at all.
#
do_test select3-7.1 {
execsql {
CREATE TABLE t2(a,b);
INSERT INTO t2 VALUES(1,2);
SELECT a, sum(b) FROM t2 WHERE b=5 GROUP BY a;
}
} {}
do_test select3-7.2 {
execsql {
SELECT a, sum(b) FROM t2 WHERE b=5;
}
} {{} {}}
finish_test
+30 -3
View File
@@ -12,7 +12,7 @@
# focus of this file is testing aggregate functions and the
# GROUP BY and HAVING clauses of SELECT statements.
#
# $Id: select5.test,v 1.10 2005/08/19 03:03:52 drh Exp $
# $Id: select5.test,v 1.15 2005/09/20 18:13:25 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -118,7 +118,7 @@ do_test select5-4.5 {
execsql {
SELECT sum(x) FROM t1 WHERE x>100
}
} {0.0}
} {{}}
# Some tests for queries with a GROUP BY clause but no aggregate functions.
#
@@ -154,6 +154,33 @@ do_test select5-5.5 {
execsql {
SELECT a, b FROM t2 GROUP BY a;
}
} {1 2 6 4}
} {1 4 6 4}
# NULL compare equal to each other for the purposes of processing
# the GROUP BY clause.
#
do_test select5-6.1 {
execsql {
CREATE TABLE t3(x,y);
INSERT INTO t3 VALUES(1,NULL);
INSERT INTO t3 VALUES(2,NULL);
INSERT INTO t3 VALUES(3,4);
SELECT count(x), y FROM t3 GROUP BY y ORDER BY 1
}
} {1 4 2 {}}
do_test select5-6.2 {
execsql {
CREATE TABLE t4(x,y,z);
INSERT INTO t4 VALUES(1,2,NULL);
INSERT INTO t4 VALUES(2,3,NULL);
INSERT INTO t4 VALUES(3,NULL,5);
INSERT INTO t4 VALUES(4,NULL,6);
INSERT INTO t4 VALUES(4,NULL,6);
INSERT INTO t4 VALUES(5,NULL,NULL);
INSERT INTO t4 VALUES(5,NULL,NULL);
INSERT INTO t4 VALUES(6,7,8);
SELECT max(x), count(x), y, z FROM t4 GROUP BY y, z ORDER BY 1
}
} {1 1 2 {} 2 1 3 {} 3 1 {} 5 4 2 {} 6 5 2 {} {} 6 1 7 8}
finish_test
+2 -1
View File
@@ -12,7 +12,7 @@
# focus of this file is testing SELECT statements that contain
# subqueries in their FROM clause.
#
# $Id: select6.test,v 1.18 2005/07/08 17:13:47 drh Exp $
# $Id: select6.test,v 1.19 2005/09/07 22:48:16 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -194,6 +194,7 @@ do_test select6-3.6 {
}
} {10.5 3.7 14.2}
do_test select6-3.7 {
btree_breakpoint
execsql {
SELECT a,b,a+b FROM (SELECT avg(x) as 'a', avg(y) as 'b' FROM t1)
WHERE a<10
+18 -1
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the CREATE TABLE statement.
#
# $Id: sort.test,v 1.22 2005/08/13 16:13:06 drh Exp $
# $Id: sort.test,v 1.23 2005/09/01 17:47:52 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -447,4 +447,21 @@ do_test sort-11.1 {
}
} {3 4}
# Trouble reported on the mailing list. Check for overly aggressive
# (which is to say, incorrect) optimization of order-by with a rowid
# in a join.
#
do_test sort-12.1 {
execsql {
create table a (id integer primary key);
create table b (id integer primary key, aId integer, text);
insert into a values (1);
insert into b values (2, 1, 'xxx');
insert into b values (1, 1, 'zzz');
insert into b values (3, 1, 'yyy');
select a.id, b.id, b.text from a join b on (a.id = b.aId)
order by a.id, b.text;
}
} {1 2 xxx 1 3 yyy 1 1 zzz}
finish_test
+27 -4
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is testing correlated subqueries
#
# $Id: subquery.test,v 1.11 2005/07/21 03:48:20 drh Exp $
# $Id: subquery.test,v 1.13 2005/09/08 10:37:01 drh Exp $
#
set testdir [file dirname $argv0]
@@ -112,7 +112,7 @@ do_test subquery-1.10.3 {
execsql {
SELECT * FROM (SELECT (SELECT sum(a) FROM t1));
}
} {16.0}
} {16}
do_test subquery-1.10.4 {
execsql {
CREATE TABLE t5 (val int, period text PRIMARY KEY);
@@ -134,7 +134,7 @@ do_test subquery-1.10.4 {
FROM t5 a where a.period between '2002-1' and '2002-4')
WHERE vsum < 45 ;
}
} {2002-2 30.0 2002-3 25.0 2002-4 15.0}
} {2002-2 30 2002-3 25 2002-4 15}
do_test subquery-1.10.5 {
execsql {
SELECT "a.period", vsum from
@@ -143,7 +143,7 @@ do_test subquery-1.10.5 {
FROM t5 a where a.period between '2002-1' and '2002-4')
WHERE vsum < 45 ;
}
} {2002-2 30.0 2002-3 25.0 2002-4 15.0}
} {2002-2 30 2002-3 25 2002-4 15}
do_test subquery-1.10.6 {
execsql {
DROP TABLE t5;
@@ -386,6 +386,29 @@ do_test subquery-5.2 {
} {1}
# Ticket #1380. Make sure correlated subqueries on an IN clause work
# correctly when the left-hand side of the IN operator is constant.
#
do_test subquery-6.1 {
set callcnt 0
execsql {
SELECT x FROM t4 WHERE 1 IN (SELECT callcnt(count(*)) FROM t5 WHERE a=y)
}
} {one two three four}
do_test subquery-6.2 {
set callcnt
} {4}
do_test subquery-6.3 {
set callcnt 0
execsql {
SELECT x FROM t4 WHERE 1 IN (SELECT callcnt(count(*)) FROM t5 WHERE a=1)
}
} {one two three four}
do_test subquery-6.4 {
set callcnt
} {1}
+3 -3
View File
@@ -12,7 +12,7 @@
# focus of this file is testing SELECT statements that are part of
# expressions.
#
# $Id: subselect.test,v 1.12 2005/01/21 03:12:16 danielk1977 Exp $
# $Id: subselect.test,v 1.13 2005/09/08 10:37:01 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -132,12 +132,12 @@ do_test subselect-3.2 {
execsql {
SELECT sum(x) FROM (SELECT x FROM t3 ORDER BY x LIMIT 2);
}
} {3.0}
} {3}
do_test subselect-3.3 {
execsql {
SELECT sum(x) FROM (SELECT x FROM t3 ORDER BY x DESC LIMIT 2);
}
} {11.0}
} {11}
do_test subselect-3.4 {
execsql {
SELECT (SELECT x FROM t3 ORDER BY x);
+81
View File
@@ -0,0 +1,81 @@
# 2005 August 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.
#
# This file implements tests to verify that fsync is disabled when
# pragma synchronous=off even for multi-database commits.
#
# $Id: sync.test,v 1.1 2005/08/27 16:36:49 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
#
# These tests are only applicable on unix when pager pragma are
# enabled.
#
if {$::tcl_platform(platform)!="unix"} {
finish_test
}
ifcapable !pager_pragmas {
finish_test
}
do_test sync-1.1 {
set sqlite_sync_count 0
file delete -force test2.db
file delete -force test2.db-journal
execsql {
CREATE TABLE t1(a,b);
ATTACH DATABASE 'test2.db' AS db2;
CREATE TABLE db2.t2(x,y);
}
set sqlite_sync_count
} 8
do_test sync-1.2 {
set sqlite_sync_count 0
execsql {
PRAGMA main.synchronous=on;
PRAGMA db2.synchronous=on;
BEGIN;
INSERT INTO t1 VALUES(1,2);
INSERT INTO t2 VALUES(3,4);
COMMIT;
}
set sqlite_sync_count
} 8
do_test sync-1.3 {
set sqlite_sync_count 0
execsql {
PRAGMA main.synchronous=full;
PRAGMA db2.synchronous=full;
BEGIN;
INSERT INTO t1 VALUES(3,4);
INSERT INTO t2 VALUES(5,6);
COMMIT;
}
set sqlite_sync_count
} 10
do_test sync-1.4 {
set sqlite_sync_count 0
execsql {
PRAGMA main.synchronous=off;
PRAGMA db2.synchronous=off;
BEGIN;
INSERT INTO t1 VALUES(5,6);
INSERT INTO t2 VALUES(7,8);
COMMIT;
}
set sqlite_sync_count
} 0
finish_test
+6 -1
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the CREATE TABLE statement.
#
# $Id: table.test,v 1.40 2005/08/13 00:56:28 drh Exp $
# $Id: table.test,v 1.41 2005/09/10 15:35:07 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -388,6 +388,11 @@ do_test table-9.1 {
CREATE TABLE t6(a,b,a);
}
} {1 {duplicate column name: a}}
do_test table-9.2 {
catchsql {
CREATE TABLE t6(a varchar(100), b blob, a integer);
}
} {1 {duplicate column name: a}}
# Check the foreign key syntax.
#
+2 -2
View File
@@ -15,7 +15,7 @@
# interface is pretty well tested. This file contains some addition
# tests for fringe issues that the main test suite does not cover.
#
# $Id: tclsqlite.test,v 1.43 2005/08/02 17:15:16 drh Exp $
# $Id: tclsqlite.test,v 1.44 2005/08/29 23:00:05 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -34,7 +34,7 @@ do_test tcl-1.1 {
do_test tcl-1.2 {
set v [catch {db bogus} msg]
lappend v $msg
} {1 {bad option "bogus": must be authorizer, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, errorcode, eval, function, last_insert_rowid, nullvalue, onecolumn, progress, rekey, timeout, total_changes, trace, transaction, or version}}
} {1 {bad option "bogus": must be authorizer, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, errorcode, eval, function, last_insert_rowid, nullvalue, onecolumn, profile, progress, rekey, timeout, total_changes, trace, transaction, or version}}
do_test tcl-1.3 {
execsql {CREATE TABLE t1(a int, b int)}
execsql {INSERT INTO t1 VALUES(10,20)}
+2 -1
View File
@@ -11,7 +11,7 @@
# This file implements some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.49 2005/05/26 15:20:53 danielk1977 Exp $
# $Id: tester.tcl,v 1.50 2005/09/17 15:20:28 drh Exp $
# Make sure tclsqlite3 was compiled correctly. Abort now with an
# error message if not.
@@ -41,6 +41,7 @@ if {[sqlite3 -tcl-uses-utf]} {
}
set tcl_precision 15
set sqlite_pending_byte 0x0010000
# Use the pager codec if it is available
#
+107
View File
@@ -0,0 +1,107 @@
# 2005 September 17
#
# 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 to verify that ticket #1435 has been
# fixed.
#
#
# $Id: tkt1435.test,v 1.1 2005/09/17 13:29:24 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Construct the sample database.
#
do_test tkt1435-1.0 {
sqlite3 db :memory:
execsql {
CREATE TABLE Instances(
instanceId INTEGER PRIMARY KEY,
troveName STR,
versionId INT,
flavorId INT,
timeStamps STR,
isPresent INT,
pinned BOOLEAN
);
INSERT INTO "Instances"
VALUES(1, 'libhello:runtime', 1, 1, 1126929880.094, 1, 1);
INSERT INTO "Instances"
VALUES(2, 'libhello:user', 1, 1, 1126929880.094, 1, 0);
INSERT INTO "Instances"
VALUES(3, 'libhello:script', 1, 1, 1126929880.094, 1, 0);
INSERT INTO "Instances"
VALUES(4, 'libhello', 1, 1, 1126929880.094, 1, 0);
CREATE TABLE Versions(versionId INTEGER PRIMARY KEY,version STR UNIQUE);
INSERT INTO "Versions" VALUES(0, NULL);
INSERT INTO "Versions" VALUES(1, '/localhost@rpl:linux/0-1-1');
CREATE TABLE Flavors(flavorId integer primary key, flavor str unique);
INSERT INTO "Flavors" VALUES(0, NULL);
INSERT INTO "Flavors" VALUES(1, '1#x86');
CREATE TEMPORARY TABLE tlList (
row INTEGER PRIMARY KEY,
name STRING,
version STRING,
flavor STRING
);
INSERT INTO tlList
values(NULL, 'libhello:script', '/localhost@rpl:linux/0-1-1', '1#x86');
INSERT INTO tlList
values(NULL, 'libhello:user', '/localhost@rpl:linux/0-1-1', '1#x86');
INSERT INTO tlList
values(NULL, 'libhello:runtime', '/localhost@rpl:linux/0-1-1', '1#x86');
}
} {}
# Run the query with an index
#
do_test tkt1435-1.1 {
execsql {
select row, pinned from tlList, Instances, Versions, Flavors
where
Instances.troveName = tlList.name
and Versions.version = tlList.version
and Instances.versionId = Versions.versionId
and ( Flavors.flavor = tlList.flavor or Flavors.flavor is NULL
and tlList.flavor = '')
and Instances.flavorId = Flavors.flavorId
order by row asc;
}
} {1 0 2 0 3 1}
# Create a indices, analyze and rerun the query.
# Verify that the results are the same
#
do_test tkt1435-1.2 {
execsql {
CREATE INDEX InstancesNameIdx ON Instances(troveName);
CREATE UNIQUE INDEX InstancesIdx
ON Instances(troveName, versionId, flavorId);
ANALYZE;
select row, pinned from tlList, Instances, Versions, Flavors
where
Instances.troveName = tlList.name
and Versions.version = tlList.version
and Instances.versionId = Versions.versionId
and ( Flavors.flavor = tlList.flavor or Flavors.flavor is NULL
and tlList.flavor = '')
and Instances.flavorId = Flavors.flavorId
order by row asc;
}
} {1 0 2 0 3 1}
finish_test
+176
View File
@@ -0,0 +1,176 @@
# 2005 September 17
#
# 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 to verify that ticket #1433 has been
# fixed.
#
# The problem in ticket #1433 was that the dependencies on the right-hand
# side of an IN operator were not being checked correctly. So in an
# expression of the form:
#
# t1.x IN (1,t2.b,3)
#
# the optimizer was missing the fact that the right-hand side of the IN
# depended on table t2. It was checking dependencies based on the
# Expr.pRight field rather than Expr.pList and Expr.pSelect.
#
# Such a bug could be verifed using a less elaborate test case. But
# this test case (from the original bug poster) exercises so many different
# parts of the system all at once, that it seemed like a good one to
# include in the test suite.
#
# NOTE: Yes, in spite of the name of this file (tkt1443.test) this
# test is for ticket #1433 not #1443. I mistyped the name when I was
# creating the file and I had already checked in the file by the wrong
# name be the time I noticed the error. With CVS it is a really hassle
# to change filenames, so I'll just leave it as is. No harm done.
#
# $Id: tkt1443.test,v 1.2 2005/09/17 13:29:24 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Construct the sample database.
#
do_test tkt1443-1.0 {
sqlite3 db :memory:
execsql {
CREATE TABLE Items(
itemId integer primary key,
item str unique
);
INSERT INTO "Items" VALUES(0, 'ALL');
INSERT INTO "Items" VALUES(1, 'double:source');
INSERT INTO "Items" VALUES(2, 'double');
INSERT INTO "Items" VALUES(3, 'double:runtime');
INSERT INTO "Items" VALUES(4, '.*:runtime');
CREATE TABLE Labels(
labelId INTEGER PRIMARY KEY,
label STR UNIQUE
);
INSERT INTO "Labels" VALUES(0, 'ALL');
INSERT INTO "Labels" VALUES(1, 'localhost@rpl:linux');
INSERT INTO "Labels" VALUES(2, 'localhost@rpl:branch');
CREATE TABLE LabelMap(
itemId INTEGER,
labelId INTEGER,
branchId integer
);
INSERT INTO "LabelMap" VALUES(1, 1, 1);
INSERT INTO "LabelMap" VALUES(2, 1, 1);
INSERT INTO "LabelMap" VALUES(3, 1, 1);
INSERT INTO "LabelMap" VALUES(1, 2, 2);
INSERT INTO "LabelMap" VALUES(2, 2, 3);
INSERT INTO "LabelMap" VALUES(3, 2, 3);
CREATE TABLE Users (
userId INTEGER PRIMARY KEY,
user STRING UNIQUE,
salt BINARY,
password STRING
);
INSERT INTO "Users" VALUES(1, 'test', 'Šæ$d',
'43ba0f45014306bd6df529551ffdb3df');
INSERT INTO "Users" VALUES(2, 'limited', 'ªš>S',
'cf07c8348fdf675cc1f7696b7d45191b');
CREATE TABLE UserGroups (
userGroupId INTEGER PRIMARY KEY,
userGroup STRING UNIQUE
);
INSERT INTO "UserGroups" VALUES(1, 'test');
INSERT INTO "UserGroups" VALUES(2, 'limited');
CREATE TABLE UserGroupMembers (
userGroupId INTEGER,
userId INTEGER
);
INSERT INTO "UserGroupMembers" VALUES(1, 1);
INSERT INTO "UserGroupMembers" VALUES(2, 2);
CREATE TABLE Permissions (
userGroupId INTEGER,
labelId INTEGER NOT NULL,
itemId INTEGER NOT NULL,
write INTEGER,
capped INTEGER,
admin INTEGER
);
INSERT INTO "Permissions" VALUES(1, 0, 0, 1, 0, 1);
INSERT INTO "Permissions" VALUES(2, 2, 4, 0, 0, 0);
}
} {}
# Run the query with an index
#
do_test tkt1443-1.1 {
execsql {
select distinct
Items.Item as trove, UP.pattern as pattern
from
( select
Permissions.labelId as labelId,
PerItems.item as pattern
from
Users, UserGroupMembers, Permissions
left outer join Items as PerItems
on Permissions.itemId = PerItems.itemId
where
Users.user = 'limited'
and Users.userId = UserGroupMembers.userId
and UserGroupMembers.userGroupId = Permissions.userGroupId
) as UP join LabelMap on ( UP.labelId = 0 or
UP.labelId = LabelMap.labelId ),
Labels, Items
where
Labels.label = 'localhost@rpl:branch'
and Labels.labelId = LabelMap.labelId
and LabelMap.itemId = Items.itemId
ORDER BY +trove, +pattern
}
} {double .*:runtime double:runtime .*:runtime double:source .*:runtime}
# Create an index and rerun the query.
# Verify that the results are the same
#
do_test tkt1443-1.2 {
execsql {
CREATE UNIQUE INDEX PermissionsIdx
ON Permissions(userGroupId, labelId, itemId);
select distinct
Items.Item as trove, UP.pattern as pattern
from
( select
Permissions.labelId as labelId,
PerItems.item as pattern
from
Users, UserGroupMembers, Permissions
left outer join Items as PerItems
on Permissions.itemId = PerItems.itemId
where
Users.user = 'limited'
and Users.userId = UserGroupMembers.userId
and UserGroupMembers.userGroupId = Permissions.userGroupId
) as UP join LabelMap on ( UP.labelId = 0 or
UP.labelId = LabelMap.labelId ),
Labels, Items
where
Labels.label = 'localhost@rpl:branch'
and Labels.labelId = LabelMap.labelId
and LabelMap.itemId = Items.itemId
ORDER BY +trove, +pattern
}
} {double .*:runtime double:runtime .*:runtime double:source .*:runtime}
finish_test
+51
View File
@@ -0,0 +1,51 @@
# 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.
#
# This file implements tests to verify that ticket #1444 has been
# fixed.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# The use of a VIEW that contained an ORDER BY clause within a UNION ALL
# was causing problems. See ticket #1444.
#
do_test tkt1444-1.1 {
execsql {
CREATE TABLE DemoTable (x INTEGER, TextKey TEXT, DKey Real);
CREATE INDEX DemoTableIdx ON DemoTable (TextKey);
INSERT INTO DemoTable VALUES(9,8,7);
INSERT INTO DemoTable VALUES(1,2,3);
CREATE VIEW DemoView AS SELECT * FROM DemoTable ORDER BY TextKey;
SELECT * FROM DemoTable UNION ALL SELECT * FROM DemoView ORDER BY 1;
}
} {1 2 3 1 2 3 9 8 7 9 8 7}
do_test tkt1444-1.2 {
execsql {
SELECT * FROM DemoTable UNION ALL SELECT * FROM DemoView;
}
} {9 8 7 1 2 3 1 2 3 9 8 7}
do_test tkt1444-1.3 {
execsql {
DROP VIEW DemoView;
CREATE VIEW DemoView AS SELECT * FROM DemoTable;
SELECT * FROM DemoTable UNION ALL SELECT * FROM DemoView ORDER BY 1;
}
} {1 2 3 1 2 3 9 8 7 9 8 7}
do_test tkt1444-1.4 {
execsql {
SELECT * FROM DemoTable UNION ALL SELECT * FROM DemoView;
}
} {9 8 7 1 2 3 9 8 7 1 2 3}
finish_test
+254
View File
@@ -0,0 +1,254 @@
# 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.
#
# This file implements tests to verify that ticket #1449 has been
# fixed.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# The following schema generated problems in ticket #1449. We've retained
# the original schema here because it is some unbelievably complex, it seemed
# like a good test case for SQLite.
#
do_test tkt1449-1.1 {
execsql {
BEGIN;
CREATE TABLE ACLS(ISSUEID text(50) not null, OBJECTID text(50) not null, PARTICIPANTID text(50) not null, PERMISSIONBITS int not null, constraint PK_ACLS primary key (ISSUEID, OBJECTID, PARTICIPANTID));
CREATE TABLE ACTIONITEMSTATUSES(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, FRIENDLYNAME text(100) not null, REVISION int not null, SHORTNAME text(30) not null, LONGNAME text(200) not null, ATTACHMENTHANDLING int not null, RESULT int not null, NOTIFYCREATOR text(1) null, NOTIFYASSIGNEE text(1) null, NOTIFYFYI text(1) null, NOTIFYCLOSURETEAM text(1) null, NOTIFYCOORDINATORS text(1) null, COMMENTREQUIRED text(1) not null, constraint PK_ACTIONITEMSTATUSES primary key (ISSUEID, OBJECTID));
CREATE TABLE ACTIONITEMTYPES(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, REVISION int not null, LABEL text(200) not null, INSTRUCTIONS text not null, EMAILINSTRUCTIONS text null, ALLOWEDSTATUSES text not null, INITIALSTATUS text(100) not null, COMMENTREQUIRED text(1) not null, ATTACHMENTHANDLING int not null, constraint PK_ACTIONITEMTYPES primary key (ISSUEID, OBJECTID));
CREATE TABLE ATTACHMENTS(TQUNID text(36) not null, OBJECTID text(50) null, ISSUEID text(50) null, DATASTREAM blob not null, CONTENTENCODING text(50) null, CONTENTCHARSET text(50) null, CONTENTTYPE text(100) null, CONTENTID text(100) null, CONTENTLOCATION text(100) null, CONTENTNAME text(100) not null, constraint PK_ATTACHMENTS primary key (TQUNID));
CREATE TABLE COMPLIANCEPOLICIES(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, BODY text null, constraint PK_COMPLIANCEPOLICIES primary key (ISSUEID, OBJECTID));
CREATE TABLE DBHISTORY(DATETIME text(25) not null, OPERATION text(20) not null, KUBIVERSION text(100) not null, FROMVERSION int null, TOVERSION int null);
CREATE TABLE DBINFO(FINGERPRINT text(32) not null, VERSION int not null);
CREATE TABLE DETACHEDATTACHMENTS (TQUNID text(36) not null, ISSUEID text(50) not null, OBJECTID text(50) not null, PATH text(300) not null, DETACHEDFILELASTMODTIMESTAMP text(25) null, CONTENTID text(100) not null, constraint PK_DETACHEDATTACHMENTS primary key (TQUNID));
CREATE TABLE DOCREFERENCES(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, REFERENCEDOCUMENTID text(50) null, constraint PK_DOCREFERENCES primary key (ISSUEID, OBJECTID));
CREATE TABLE DQ (TQUNID text(36) not null, ISSUEID text(50) not null, DEPENDSID text(50) null, DEPENDSTYPE int null, DEPENDSCOMMANDSTREAM blob null, DEPENDSNODEIDSEQNOKEY text(100) null, DEPENDSACLVERSION int null, constraint PK_DQ primary key (TQUNID));
CREATE TABLE EMAILQ(TIMEQUEUED int not null, NODEID text(50) not null, MIME blob not null, TQUNID text(36) not null);
CREATE TABLE ENTERPRISEDATA(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, DATE1 text(25) null, DATE2 text(25) null, DATE3 text(25) null, DATE4 text(25) null, DATE5 text(25) null, DATE6 text(25) null, DATE7 text(25) null, DATE8 text(25) null, DATE9 text(25) null, DATE10 text(25) null, VALUE1 int null, VALUE2 int null, VALUE3 int null, VALUE4 int null, VALUE5 int null, VALUE6 int null, VALUE7 int null, VALUE8 int null, VALUE9 int null, VALUE10 int null, VALUE11 int null, VALUE12 int null, VALUE13 int null, VALUE14 int null, VALUE15 int null, VALUE16 int null, VALUE17 int null, VALUE18 int null, VALUE19 int null, VALUE20 int null, STRING1 text(300) null, STRING2 text(300) null, STRING3 text(300) null, STRING4 text(300) null, STRING5 text(300) null, STRING6 text(300) null, STRING7 text(300) null, STRING8 text(300) null, STRING9 text(300) null, STRING10 text(300) null, LONGSTRING1 text null, LONGSTRING2 text null, LONGSTRING3 text null, LONGSTRING4 text null, LONGSTRING5 text null, LONGSTRING6 text null, LONGSTRING7 text null, LONGSTRING8 text null, LONGSTRING9 text null, LONGSTRING10 text null, constraint PK_ENTERPRISEDATA primary key (ISSUEID, OBJECTID));
CREATE TABLE FILEMORGUE(TQUNID text(36) not null, PATH text(300) not null, DELETEFOLDERWHENEMPTY text(1) null, constraint PK_FILEMORGUE primary key (TQUNID));
CREATE TABLE FILES(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, PARENTENTITYID text(50) null, BODY text null, BODYCONTENTTYPE text(100) null, ISOBSOLETE text(1) null, FILENAME text(300) not null, VISIBLENAME text(300) not null, VERSIONSTRING text(300) not null, DOCUMENTHASH text(40) not null, ISFINAL text(1) null, DOCREFERENCEID text(50) not null, constraint PK_FILES primary key (ISSUEID, OBJECTID));
CREATE TABLE FOLDERS(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, CONTAINERNAME text(300) null, CONTAINERACLSETTINGS text null, constraint PK_FOLDERS primary key (ISSUEID, OBJECTID));
CREATE TABLE GLOBALSETTINGS(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, SINGULARPROJECTLABEL text(30) not null, PLURALPROJECTLABEL text(30) not null, PROJECTREQUIRED text(1) not null, CUSTOMPROJECTSALLOWED text(1) not null, ACTIONITEMSPECXML text null, PROJECTLISTXML text null, ENTERPRISEDATALABELS text null, ENTERPRISEDATATABXSL text null, constraint PK_GLOBALSETTINGS primary key (ISSUEID, OBJECTID));
CREATE TABLE GLOBALSTRINGPROPERTIES(ID int not null, VALUE text(300) not null, constraint PK_GLOBALSTRINGPROPERTIES primary key (ID));
CREATE TABLE IMQ(TQUNID text(36) not null, DATETIMEQUEUED text(25) not null, ISSUEID text(50) not null, KUBIBUILD text(30) not null, FAILCOUNT int not null, LASTRUN text(25) null, ENVELOPESTREAM blob not null, PAYLOADSTREAM blob not null, constraint PK_IMQ primary key (TQUNID));
CREATE TABLE INVITATIONNODES(INVITATIONID text(50) not null, RECIPIENTNODEID text(50) not null, DATECREATED text(25) not null, constraint PK_INVITATIONNODES primary key (INVITATIONID, RECIPIENTNODEID));
CREATE TABLE INVITATIONS (INVITATIONID text(50) not null, SENDERNODEID text(50) not null, RECIPIENTEMAILADDR text(200) not null, RECIPIENTUSERID text(50) null, RECIPIENTNODES text null, ISSUEID text(50) not null, ENVELOPE text not null, MESSAGEBLOB blob not null, INVITATIONSTATE int not null, TQUNID text(36) not null, DATECREATED text(25) not null);
CREATE TABLE ISSUES (CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, CONTAINERNAME text(300) null, CONTAINERACLSETTINGS text null, ISINITIALIZED text(1) null, BLINDINVITES text null, ISSYSTEMISSUE text(1) not null, ISSUETYPE int not null, ACTIVITYTYPEID text(50) null, ISINCOMPLETE text(1) not null, constraint PK_ISSUES primary key (ISSUEID, OBJECTID));
CREATE TABLE ISSUESETTINGS (CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, ISSUENAME text(300) not null, ISSUEACLSETTINGS text not null, ISSUEDUEDATE text(25) null, ISSUEPRIORITY int null, ISSUESTATUS int null, DESCRIPTION text null, PROJECTID text(100) null, PROJECTNAME text null, PROJECTNAMEISCUSTOM text(1) null, ISSYSTEMISSUE text(1) not null, ACTIONITEMREVNUM int not null, constraint PK_ISSUESETTINGS primary key (ISSUEID, OBJECTID));
CREATE TABLE KMTPMSG (MSGID integer not null, SENDERID text(50) null, RECIPIENTIDLIST text not null, ISSUEID text(50) null, MESSAGETYPE int not null, ENVELOPE text null, MESSAGEBLOB blob not null, RECEIVEDDATE text(25) not null, constraint PK_KMTPMSG primary key (MSGID));
CREATE TABLE KMTPNODEQ(NODEID text(50) not null, MSGID int not null, RECEIVEDDATE text(25) not null, SENDCOUNT int not null);
CREATE TABLE KMTPQ(MSGID integer not null, SENDERID text(50) null, RECIPIENTIDLIST text not null, ISSUEID text(50) null, MESSAGETYPE int not null, ENVELOPE text null, MESSAGEBLOB blob not null, constraint PK_KMTPQ primary key (MSGID));
CREATE TABLE LOGENTRIES(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, PARENTENTITYID text(50) null, BODY text null, BODYCONTENTTYPE text(100) null, ISOBSOLETE text(1) null, ACTIONTYPE int not null, ASSOCIATEDOBJECTIDS text null, OLDENTITIES text null, NEWENTITIES text null, OTHERENTITIES text null, constraint PK_LOGENTRIES primary key (ISSUEID, OBJECTID));
CREATE TABLE LSBI(TQUNID text(36) not null, ISSUEID text(50) not null, TABLEITEMID text(50) null, TABLENODEID text(50) null, TABLECMD int null, TABLECONTAINERID text(50) null, TABLESEQNO int null, DIRTYCONTENT text null, STUBBED text(1) null, ENTITYSTUBDATA text null, UPDATENUMBER int not null, constraint PK_LSBI primary key (TQUNID));
CREATE TABLE LSBN(TQUNID text(36) not null, ISSUEID text(50) not null, NODEID text(50) not null, STORESEQNO int not null, SYNCSEQNO int not null, LASTMSGDATE text(25) null, constraint PK_LSBN primary key (TQUNID));
CREATE TABLE MMQ(TQUNID text(36) not null, ISSUEID text(50) not null, TABLEREQUESTNODE text(50) null, MMQENTRYINDEX text(60) null, DIRECTION int null, NODEID text(50) null, TABLEFIRSTSEQNO int null, TABLELASTSEQNO int null, NEXTRESENDTIMEOUT text(25) null, TABLETIMEOUTMULTIPLIER int null, constraint PK_MMQ primary key (TQUNID));
CREATE TABLE NODEREG(NODEID text(50) not null, USERID text(50) null, CREATETIME text(25) not null, TQUNID text(36) not null);
CREATE TABLE NODES (NODEID text(50) not null, USERID text(50) null, NODESTATE int not null, NODECERT text null, KUBIVERSION int not null, KUBIBUILD text(30) not null, TQUNID text(36) not null, LASTBINDDATE text(25) null, LASTUNBINDDATE text(25) null, LASTBINDIP text(15) null, NUMBINDS int not null, NUMSENDS int not null, NUMPOLLS int not null, NUMRECVS int not null);
CREATE TABLE PARTICIPANTNODES(ISSUEID text(50) not null, OBJECTID text(50) not null, NODEID text(50) not null, USERID text(50) null, NODESTATE int not null, NODECERT text null, KUBIVERSION int not null, KUBIBUILD text(30) not null, TQUNID text(36) not null);
CREATE TABLE PARTICIPANTS(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, PARTICIPANTSTATE int not null, PARTICIPANTROLE int not null, PARTICIPANTTEAM int not null, ISREQUIREDMEMBER text(1) null, USERID text(50) null, ISAGENT text(1) null, NAME text(150) not null, EMAILADDRESS text(200) not null, ISEMAILONLY text(1) not null, INVITATION text null, ACCEPTRESENDCOUNT int null, ACCEPTRESENDTIMEOUT text(25) null, ACCEPTLASTSENTTONODEID text(50) null, constraint PK_PARTICIPANTS primary key (ISSUEID, OBJECTID));
CREATE TABLE PARTICIPANTSETTINGS(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, PARTICIPANTID text(50) not null, TASKPIMSYNC text(1) null, MOBILESUPPORT text(1) null, NOTIFYBYEMAIL text(1) null, MARKEDCRITICAL text(1) null, constraint PK_PARTICIPANTSETTINGS primary key (ISSUEID, OBJECTID));
CREATE TABLE PARTITIONS(PARTITIONID text(50) not null, NAME text(100) not null, LDAPDN text(300) not null, SERVERNODEID text(50) not null, TQUNID text(36) not null);
CREATE TABLE PROJECTS(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, NAME text(100) not null, ID text(100) null, constraint PK_PROJECTS primary key (ISSUEID, OBJECTID));
CREATE TABLE TASKCOMPLETIONS(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, PARENTENTITYID text(50) null, BODY text null, BODYCONTENTTYPE text(100) null, ISOBSOLETE text(1) null, TASKID text(50) not null, DISPOSITION int not null, STATUSID text(50) not null, SHORTNAME text(30) not null, LONGNAME text(200) not null, constraint PK_TASKCOMPLETIONS primary key (ISSUEID, OBJECTID));
CREATE TABLE TASKS(CLASSID int null, SEQNO int not null, LASTMODONNODEID text(50) not null, PREVMODONNODEID text(50) null, ISSUEID text(50) not null, OBJECTID text(50) not null, REVISIONNUM int not null, CONTAINERID text(50) not null, AUTHORID text(50) not null, CREATIONDATE text(25) null, LASTMODIFIEDDATE text(25) null, UPDATENUMBER int null, PREVREVISIONNUM int null, LASTCMD int null, LASTCMDACLVERSION int null, USERDEFINEDFIELD text(300) null, LASTMODIFIEDBYID text(50) null, PARENTENTITYID text(50) null, BODY text null, BODYCONTENTTYPE text(100) null, ISOBSOLETE text(1) null, DUETIME text(25) null, ASSIGNEDTO text(50) not null, TARGETOBJECTIDS text null, RESPONSEID text(50) not null, TYPEID text(50) not null, LABEL text(200) not null, INSTRUCTIONS text not null, ALLOWEDSTATUSES text not null, ISSERIALREVIEW text(1) null, DAYSTOREVIEW int null, REVIEWERIDS text(500) null, REVIEWTYPE int null, REVIEWGROUP text(300) null, constraint PK_TASKS primary key (ISSUEID, OBJECTID));
CREATE TABLE USERS (USERID text(50) not null, USERSID text(100) not null, ENTERPRISEUSER text(1) not null, USEREMAILADDRESS text(200) null, EMAILVALIDATED text(1) null, VALIDATIONCOOKIE text(50) null, CREATETIME text(25) not null, TQUNID text(36) not null, PARTITIONID text(50) null);
CREATE VIEW CRITICALISSUES as
select
USERID, ISSUEID, ISSUENAME, min(DATE1) DATE1
from (
select p.USERID USERID, p.ISSUEID ISSUEID, iset.ISSUENAME ISSUENAME, t.DUETIME DATE1
from PARTICIPANTS p
join TASKS t on t.ASSIGNEDTO = p.OBJECTID
join TASKCOMPLETIONS tc on tc.TASKID = t.OBJECTID
join ISSUESETTINGS iset on iset.ISSUEID = p.ISSUEID
where (t.ISOBSOLETE = 'n' or t.ISOBSOLETE is null)
and tc.DISPOSITION = 1
and iset.ISSUESTATUS = 1
union
select p.USERID USERID, p.ISSUEID ISSUEID, iset.ISSUENAME ISSUENAME, iset.ISSUEDUEDATE DATE1
from PARTICIPANTS p
join PARTICIPANTSETTINGS ps on ps.PARTICIPANTID = p.OBJECTID
join ISSUESETTINGS iset on iset.ISSUEID = p.ISSUEID
where ps.MARKEDCRITICAL = 'y'
and iset.ISSUESTATUS = 1
) as CRITICALDATA
group by USERID, ISSUEID, ISSUENAME;
CREATE VIEW CURRENTFILES as
select
d.ISSUEID as ISSUEID,
d.REFERENCEDOCUMENTID as OBJECTID,
f.VISIBLENAME as VISIBLENAME
from
DOCREFERENCES d
join FILES f on f.OBJECTID = d.REFERENCEDOCUMENTID;
CREATE VIEW ISSUEDATA as
select
ISSUES.OBJECTID as ISSUEID,
ISSUES.CREATIONDATE as CREATIONDATE,
ISSUES.AUTHORID as AUTHORID,
ISSUES.LASTMODIFIEDDATE as LASTMODIFIEDDATE,
ISSUES.LASTMODIFIEDBYID as LASTMODIFIEDBYID,
ISSUESETTINGS.ISSUENAME as ISSUENAME,
ISSUES.ISINITIALIZED as ISINITIALIZED,
ISSUES.ISSYSTEMISSUE as ISSYSTEMISSUE,
ISSUES.ISSUETYPE as ISSUETYPE,
ISSUES.ISINCOMPLETE as ISINCOMPLETE,
ISSUESETTINGS.REVISIONNUM as ISSUESETTINGS_REVISIONNUM,
ISSUESETTINGS.LASTMODIFIEDDATE as ISSUESETTINGS_LASTMODIFIEDDATE,
ISSUESETTINGS.LASTMODIFIEDBYID as ISSUESETTINGS_LASTMODIFIEDBYID,
ISSUESETTINGS.ISSUEDUEDATE as ISSUEDUEDATE,
ISSUESETTINGS.ISSUEPRIORITY as ISSUEPRIORITY,
ISSUESETTINGS.ISSUESTATUS as ISSUESTATUS,
ISSUESETTINGS.DESCRIPTION as DESCRIPTION,
ISSUESETTINGS.PROJECTID as PROJECTID,
ISSUESETTINGS.PROJECTNAME as PROJECTNAME,
ISSUESETTINGS.PROJECTNAMEISCUSTOM as PROJECTNAMEISCUSTOM,
ENTERPRISEDATA.REVISIONNUM as ENTERPRISEDATA_REVISIONNUM,
ENTERPRISEDATA.CREATIONDATE as ENTERPRISEDATA_CREATIONDATE,
ENTERPRISEDATA.AUTHORID as ENTERPRISEDATA_AUTHORID,
ENTERPRISEDATA.LASTMODIFIEDDATE as ENTERPRISEDATA_LASTMODIFIEDDATE,
ENTERPRISEDATA.LASTMODIFIEDBYID as ENTERPRISEDATA_LASTMODIFIEDBYID,
ENTERPRISEDATA.DATE1 as DATE1,
ENTERPRISEDATA.DATE2 as DATE2,
ENTERPRISEDATA.DATE3 as DATE3,
ENTERPRISEDATA.DATE4 as DATE4,
ENTERPRISEDATA.DATE5 as DATE5,
ENTERPRISEDATA.DATE6 as DATE6,
ENTERPRISEDATA.DATE7 as DATE7,
ENTERPRISEDATA.DATE8 as DATE8,
ENTERPRISEDATA.DATE9 as DATE9,
ENTERPRISEDATA.DATE10 as DATE10,
ENTERPRISEDATA.VALUE1 as VALUE1,
ENTERPRISEDATA.VALUE2 as VALUE2,
ENTERPRISEDATA.VALUE3 as VALUE3,
ENTERPRISEDATA.VALUE4 as VALUE4,
ENTERPRISEDATA.VALUE5 as VALUE5,
ENTERPRISEDATA.VALUE6 as VALUE6,
ENTERPRISEDATA.VALUE7 as VALUE7,
ENTERPRISEDATA.VALUE8 as VALUE8,
ENTERPRISEDATA.VALUE9 as VALUE9,
ENTERPRISEDATA.VALUE10 as VALUE10,
ENTERPRISEDATA.VALUE11 as VALUE11,
ENTERPRISEDATA.VALUE12 as VALUE12,
ENTERPRISEDATA.VALUE13 as VALUE13,
ENTERPRISEDATA.VALUE14 as VALUE14,
ENTERPRISEDATA.VALUE15 as VALUE15,
ENTERPRISEDATA.VALUE16 as VALUE16,
ENTERPRISEDATA.VALUE17 as VALUE17,
ENTERPRISEDATA.VALUE18 as VALUE18,
ENTERPRISEDATA.VALUE19 as VALUE19,
ENTERPRISEDATA.VALUE20 as VALUE20,
ENTERPRISEDATA.STRING1 as STRING1,
ENTERPRISEDATA.STRING2 as STRING2,
ENTERPRISEDATA.STRING3 as STRING3,
ENTERPRISEDATA.STRING4 as STRING4,
ENTERPRISEDATA.STRING5 as STRING5,
ENTERPRISEDATA.STRING6 as STRING6,
ENTERPRISEDATA.STRING7 as STRING7,
ENTERPRISEDATA.STRING8 as STRING8,
ENTERPRISEDATA.STRING9 as STRING9,
ENTERPRISEDATA.STRING10 as STRING10,
ENTERPRISEDATA.LONGSTRING1 as LONGSTRING1,
ENTERPRISEDATA.LONGSTRING2 as LONGSTRING2,
ENTERPRISEDATA.LONGSTRING3 as LONGSTRING3,
ENTERPRISEDATA.LONGSTRING4 as LONGSTRING4,
ENTERPRISEDATA.LONGSTRING5 as LONGSTRING5,
ENTERPRISEDATA.LONGSTRING6 as LONGSTRING6,
ENTERPRISEDATA.LONGSTRING7 as LONGSTRING7,
ENTERPRISEDATA.LONGSTRING8 as LONGSTRING8,
ENTERPRISEDATA.LONGSTRING9 as LONGSTRING9,
ENTERPRISEDATA.LONGSTRING10 as LONGSTRING10
from
ISSUES
join ISSUESETTINGS on ISSUES.OBJECTID = ISSUESETTINGS.ISSUEID
left outer join ENTERPRISEDATA on ISSUES.OBJECTID = ENTERPRISEDATA.ISSUEID;
CREATE VIEW ITEMS as
select 'FILES' as TABLENAME, CLASSID, SEQNO, LASTMODONNODEID, PREVMODONNODEID, ISSUEID, OBJECTID, REVISIONNUM, CONTAINERID, AUTHORID, CREATIONDATE, LASTMODIFIEDDATE, UPDATENUMBER, PREVREVISIONNUM, LASTCMD, LASTCMDACLVERSION, USERDEFINEDFIELD, LASTMODIFIEDBYID, PARENTENTITYID, BODY, BODYCONTENTTYPE, ISOBSOLETE, FILENAME, VISIBLENAME, VERSIONSTRING, DOCUMENTHASH, ISFINAL, DOCREFERENCEID, NULL as ACTIONTYPE, NULL as ASSOCIATEDOBJECTIDS, NULL as OLDENTITIES, NULL as NEWENTITIES, NULL as OTHERENTITIES, NULL as TQUNID, NULL as TABLEITEMID, NULL as TABLENODEID, NULL as TABLECMD, NULL as TABLECONTAINERID, NULL as TABLESEQNO, NULL as DIRTYCONTENT, NULL as STUBBED, NULL as ENTITYSTUBDATA, NULL as PARTICIPANTSTATE, NULL as PARTICIPANTROLE, NULL as PARTICIPANTTEAM, NULL as ISREQUIREDMEMBER, NULL as USERID, NULL as ISAGENT, NULL as NAME, NULL as EMAILADDRESS, NULL as ISEMAILONLY, NULL as INVITATION, NULL as ACCEPTRESENDCOUNT, NULL as ACCEPTRESENDTIMEOUT, NULL as ACCEPTLASTSENTTONODEID, NULL as TASKID, NULL as DISPOSITION, NULL as STATUSID, NULL as SHORTNAME, NULL as LONGNAME, NULL as DUETIME, NULL as ASSIGNEDTO, NULL as TARGETOBJECTIDS, NULL as RESPONSEID, NULL as TYPEID, NULL as LABEL, NULL as INSTRUCTIONS, NULL as ALLOWEDSTATUSES, NULL as ISSERIALREVIEW, NULL as DAYSTOREVIEW, NULL as REVIEWERIDS, NULL as REVIEWTYPE, NULL as REVIEWGROUP from FILES
union all
select 'LOGENTRIES' as TABLENAME, CLASSID, SEQNO, LASTMODONNODEID, PREVMODONNODEID, ISSUEID, OBJECTID, REVISIONNUM, CONTAINERID, AUTHORID, CREATIONDATE, LASTMODIFIEDDATE, UPDATENUMBER, PREVREVISIONNUM, LASTCMD, LASTCMDACLVERSION, USERDEFINEDFIELD, LASTMODIFIEDBYID, PARENTENTITYID, BODY, BODYCONTENTTYPE, ISOBSOLETE, NULL as FILENAME, NULL as VISIBLENAME, NULL as VERSIONSTRING, NULL as DOCUMENTHASH, NULL as ISFINAL, NULL as DOCREFERENCEID, ACTIONTYPE, ASSOCIATEDOBJECTIDS, OLDENTITIES, NEWENTITIES, OTHERENTITIES, NULL as TQUNID, NULL as TABLEITEMID, NULL as TABLENODEID, NULL as TABLECMD, NULL as TABLECONTAINERID, NULL as TABLESEQNO, NULL as DIRTYCONTENT, NULL as STUBBED, NULL as ENTITYSTUBDATA, NULL as PARTICIPANTSTATE, NULL as PARTICIPANTROLE, NULL as PARTICIPANTTEAM, NULL as ISREQUIREDMEMBER, NULL as USERID, NULL as ISAGENT, NULL as NAME, NULL as EMAILADDRESS, NULL as ISEMAILONLY, NULL as INVITATION, NULL as ACCEPTRESENDCOUNT, NULL as ACCEPTRESENDTIMEOUT, NULL as ACCEPTLASTSENTTONODEID, NULL as TASKID, NULL as DISPOSITION, NULL as STATUSID, NULL as SHORTNAME, NULL as LONGNAME, NULL as DUETIME, NULL as ASSIGNEDTO, NULL as TARGETOBJECTIDS, NULL as RESPONSEID, NULL as TYPEID, NULL as LABEL, NULL as INSTRUCTIONS, NULL as ALLOWEDSTATUSES, NULL as ISSERIALREVIEW, NULL as DAYSTOREVIEW, NULL as REVIEWERIDS, NULL as REVIEWTYPE, NULL as REVIEWGROUP from LOGENTRIES
union all
select 'LSBI' as TABLENAME, NULL as CLASSID, NULL as SEQNO, NULL as LASTMODONNODEID, NULL as PREVMODONNODEID, ISSUEID, NULL as OBJECTID, NULL as REVISIONNUM, NULL as CONTAINERID, NULL as AUTHORID, NULL as CREATIONDATE, NULL as LASTMODIFIEDDATE, UPDATENUMBER, NULL as PREVREVISIONNUM, NULL as LASTCMD, NULL as LASTCMDACLVERSION, NULL as USERDEFINEDFIELD, NULL as LASTMODIFIEDBYID, NULL as PARENTENTITYID, NULL as BODY, NULL as BODYCONTENTTYPE, NULL as ISOBSOLETE, NULL as FILENAME, NULL as VISIBLENAME, NULL as VERSIONSTRING, NULL as DOCUMENTHASH, NULL as ISFINAL, NULL as DOCREFERENCEID, NULL as ACTIONTYPE, NULL as ASSOCIATEDOBJECTIDS, NULL as OLDENTITIES, NULL as NEWENTITIES, NULL as OTHERENTITIES, TQUNID, TABLEITEMID, TABLENODEID, TABLECMD, TABLECONTAINERID, TABLESEQNO, DIRTYCONTENT, STUBBED, ENTITYSTUBDATA, NULL as PARTICIPANTSTATE, NULL as PARTICIPANTROLE, NULL as PARTICIPANTTEAM, NULL as ISREQUIREDMEMBER, NULL as USERID, NULL as ISAGENT, NULL as NAME, NULL as EMAILADDRESS, NULL as ISEMAILONLY, NULL as INVITATION, NULL as ACCEPTRESENDCOUNT, NULL as ACCEPTRESENDTIMEOUT, NULL as ACCEPTLASTSENTTONODEID, NULL as TASKID, NULL as DISPOSITION, NULL as STATUSID, NULL as SHORTNAME, NULL as LONGNAME, NULL as DUETIME, NULL as ASSIGNEDTO, NULL as TARGETOBJECTIDS, NULL as RESPONSEID, NULL as TYPEID, NULL as LABEL, NULL as INSTRUCTIONS, NULL as ALLOWEDSTATUSES, NULL as ISSERIALREVIEW, NULL as DAYSTOREVIEW, NULL as REVIEWERIDS, NULL as REVIEWTYPE, NULL as REVIEWGROUP from LSBI where TABLECMD=3
union all
select 'PARTICIPANTS' as TABLENAME, CLASSID, SEQNO, LASTMODONNODEID, PREVMODONNODEID, ISSUEID, OBJECTID, REVISIONNUM, CONTAINERID, AUTHORID, CREATIONDATE, LASTMODIFIEDDATE, UPDATENUMBER, PREVREVISIONNUM, LASTCMD, LASTCMDACLVERSION, USERDEFINEDFIELD, LASTMODIFIEDBYID, NULL as PARENTENTITYID, NULL as BODY, NULL as BODYCONTENTTYPE, NULL as ISOBSOLETE, NULL as FILENAME, NULL as VISIBLENAME, NULL as VERSIONSTRING, NULL as DOCUMENTHASH, NULL as ISFINAL, NULL as DOCREFERENCEID, NULL as ACTIONTYPE, NULL as ASSOCIATEDOBJECTIDS, NULL as OLDENTITIES, NULL as NEWENTITIES, NULL as OTHERENTITIES, NULL as TQUNID, NULL as TABLEITEMID, NULL as TABLENODEID, NULL as TABLECMD, NULL as TABLECONTAINERID, NULL as TABLESEQNO, NULL as DIRTYCONTENT, NULL as STUBBED, NULL as ENTITYSTUBDATA, PARTICIPANTSTATE, PARTICIPANTROLE, PARTICIPANTTEAM, ISREQUIREDMEMBER, USERID, ISAGENT, NAME, EMAILADDRESS, ISEMAILONLY, INVITATION, ACCEPTRESENDCOUNT, ACCEPTRESENDTIMEOUT, ACCEPTLASTSENTTONODEID, NULL as TASKID, NULL as DISPOSITION, NULL as STATUSID, NULL as SHORTNAME, NULL as LONGNAME, NULL as DUETIME, NULL as ASSIGNEDTO, NULL as TARGETOBJECTIDS, NULL as RESPONSEID, NULL as TYPEID, NULL as LABEL, NULL as INSTRUCTIONS, NULL as ALLOWEDSTATUSES, NULL as ISSERIALREVIEW, NULL as DAYSTOREVIEW, NULL as REVIEWERIDS, NULL as REVIEWTYPE, NULL as REVIEWGROUP from PARTICIPANTS
union all
select 'TASKCOMPLETIONS' as TABLENAME, CLASSID, SEQNO, LASTMODONNODEID, PREVMODONNODEID, ISSUEID, OBJECTID, REVISIONNUM, CONTAINERID, AUTHORID, CREATIONDATE, LASTMODIFIEDDATE, UPDATENUMBER, PREVREVISIONNUM, LASTCMD, LASTCMDACLVERSION, USERDEFINEDFIELD, LASTMODIFIEDBYID, PARENTENTITYID, BODY, BODYCONTENTTYPE, ISOBSOLETE, NULL as FILENAME, NULL as VISIBLENAME, NULL as VERSIONSTRING, NULL as DOCUMENTHASH, NULL as ISFINAL, NULL as DOCREFERENCEID, NULL as ACTIONTYPE, NULL as ASSOCIATEDOBJECTIDS, NULL as OLDENTITIES, NULL as NEWENTITIES, NULL as OTHERENTITIES, NULL as TQUNID, NULL as TABLEITEMID, NULL as TABLENODEID, NULL as TABLECMD, NULL as TABLECONTAINERID, NULL as TABLESEQNO, NULL as DIRTYCONTENT, NULL as STUBBED, NULL as ENTITYSTUBDATA, NULL as PARTICIPANTSTATE, NULL as PARTICIPANTROLE, NULL as PARTICIPANTTEAM, NULL as ISREQUIREDMEMBER, NULL as USERID, NULL as ISAGENT, NULL as NAME, NULL as EMAILADDRESS, NULL as ISEMAILONLY, NULL as INVITATION, NULL as ACCEPTRESENDCOUNT, NULL as ACCEPTRESENDTIMEOUT, NULL as ACCEPTLASTSENTTONODEID, TASKID, DISPOSITION, STATUSID, SHORTNAME, LONGNAME, NULL as DUETIME, NULL as ASSIGNEDTO, NULL as TARGETOBJECTIDS, NULL as RESPONSEID, NULL as TYPEID, NULL as LABEL, NULL as INSTRUCTIONS, NULL as ALLOWEDSTATUSES, NULL as ISSERIALREVIEW, NULL as DAYSTOREVIEW, NULL as REVIEWERIDS, NULL as REVIEWTYPE, NULL as REVIEWGROUP from TASKCOMPLETIONS
union all
select 'TASKS' as TABLENAME, CLASSID, SEQNO, LASTMODONNODEID, PREVMODONNODEID, ISSUEID, OBJECTID, REVISIONNUM, CONTAINERID, AUTHORID, CREATIONDATE, LASTMODIFIEDDATE, UPDATENUMBER, PREVREVISIONNUM, LASTCMD, LASTCMDACLVERSION, USERDEFINEDFIELD, LASTMODIFIEDBYID, PARENTENTITYID, BODY, BODYCONTENTTYPE, ISOBSOLETE, NULL as FILENAME, NULL as VISIBLENAME, NULL as VERSIONSTRING, NULL as DOCUMENTHASH, NULL as ISFINAL, NULL as DOCREFERENCEID, NULL as ACTIONTYPE, NULL as ASSOCIATEDOBJECTIDS, NULL as OLDENTITIES, NULL as NEWENTITIES, NULL as OTHERENTITIES, NULL as TQUNID, NULL as TABLEITEMID, NULL as TABLENODEID, NULL as TABLECMD, NULL as TABLECONTAINERID, NULL as TABLESEQNO, NULL as DIRTYCONTENT, NULL as STUBBED, NULL as ENTITYSTUBDATA, NULL as PARTICIPANTSTATE, NULL as PARTICIPANTROLE, NULL as PARTICIPANTTEAM, NULL as ISREQUIREDMEMBER, NULL as USERID, NULL as ISAGENT, NULL as NAME, NULL as EMAILADDRESS, NULL as ISEMAILONLY, NULL as INVITATION, NULL as ACCEPTRESENDCOUNT, NULL as ACCEPTRESENDTIMEOUT, NULL as ACCEPTLASTSENTTONODEID, NULL as TASKID, NULL as DISPOSITION, NULL as STATUSID, NULL as SHORTNAME, NULL as LONGNAME, DUETIME, ASSIGNEDTO, TARGETOBJECTIDS, RESPONSEID, TYPEID, LABEL, INSTRUCTIONS, ALLOWEDSTATUSES, ISSERIALREVIEW, DAYSTOREVIEW, REVIEWERIDS, REVIEWTYPE, REVIEWGROUP from TASKS;
CREATE VIEW TASKINFO as
select
t.ISSUEID as ISSUEID,
t.OBJECTID as OBJECTID,
t.ASSIGNEDTO as ASSIGNEDTO,
t.TARGETOBJECTIDS as TARGETOBJECTIDS,
t.DUETIME as DUETIME,
t.ISOBSOLETE as ISOBSOLETE,
tc.DISPOSITION as DISPOSITION
from
TASKS t
join TASKCOMPLETIONS tc on tc.TASKID = t.OBJECTID;
CREATE INDEX DQ_ISSUEID_DEPENDSID on DQ (ISSUEID, DEPENDSID);
CREATE INDEX EMAILQ_TIMEQUEUED on EMAILQ (TIMEQUEUED);
CREATE INDEX FOLDERS_CONTAINERID_ISSUEID on FOLDERS (CONTAINERID, ISSUEID);
CREATE INDEX IMQ_DATETIMEQUEUED on IMQ (DATETIMEQUEUED);
CREATE INDEX INVITATIONS_RECIPIENTUSERID_INVITATIONID on INVITATIONS (RECIPIENTUSERID, INVITATIONID);
CREATE INDEX INVITATIONS_TQUNID on INVITATIONS (TQUNID);
CREATE INDEX ISSUESETTINGS_CONTAINERID on ISSUESETTINGS (CONTAINERID);
CREATE INDEX KMTPMSG_RECEIVEDDATE on KMTPMSG (RECEIVEDDATE desc);
CREATE INDEX KMTPNODEQ_MSGID on KMTPNODEQ (MSGID);
CREATE INDEX KMTPNODEQ_NODEID_MSGID on KMTPNODEQ (NODEID, MSGID);
CREATE INDEX KMTPNODEQ_RECEIVEDDATE on KMTPNODEQ (RECEIVEDDATE desc);
CREATE INDEX LSBI_ISSUEID_TABLEITEMID on LSBI (ISSUEID, TABLEITEMID);
CREATE INDEX LSBN_ISSUEID_NODEID on LSBN (ISSUEID, NODEID);
CREATE INDEX MMQ_ISSUEID_MMQENTRYINDEX on MMQ (ISSUEID, MMQENTRYINDEX);
CREATE INDEX NODEREG_NODEID_USERID on NODEREG (NODEID, USERID);
CREATE INDEX NODEREG_TQUNID on NODEREG (TQUNID);
CREATE INDEX NODEREG_USERID_NODEID on NODEREG (USERID, NODEID);
CREATE INDEX NODES_NODEID on NODES (NODEID);
CREATE INDEX NODES_TQUNID on NODES (TQUNID);
CREATE INDEX PARTICIPANTNODES_ISSUEID_OBJECTID_NODEID on PARTICIPANTNODES (ISSUEID, OBJECTID, NODEID);
CREATE INDEX PARTICIPANTNODES_TQUNID on PARTICIPANTNODES (TQUNID);
CREATE INDEX PARTICIPANTSETTINGS_PARTICIPANTID on PARTICIPANTSETTINGS (PARTICIPANTID);
CREATE INDEX PARTITIONS_LDAPDN on PARTITIONS (LDAPDN);
CREATE INDEX PARTITIONS_PARTITIONID_SERVERNODEID on PARTITIONS (PARTITIONID, SERVERNODEID);
CREATE INDEX PARTITIONS_SERVERNODEID_PARTITIONID on PARTITIONS (SERVERNODEID, PARTITIONID);
CREATE INDEX PARTITIONS_TQUNID on PARTITIONS (TQUNID);
CREATE INDEX TASKCOMPLETIONS_TASKID on TASKCOMPLETIONS (TASKID);
CREATE INDEX TASKS_ASSIGNEDTO on TASKS (ASSIGNEDTO);
CREATE INDEX USERS_PARTITIONID_USERID on USERS (PARTITIONID, USERID);
CREATE INDEX USERS_TQUNID on USERS (TQUNID);
CREATE INDEX USERS_USERID_PARTITIONID on USERS (USERID, PARTITIONID);
CREATE INDEX USERS_USERSID_USERID on USERS (USERSID, USERID);
COMMIT;
}
} {}
# Given the schema above, the following query was cause an assertion fault
# do to an uninitialized field in a Select structure.
#
do_test tkt1449-1.2 {
execsql {
select NEWENTITIES from ITEMS where ((ISSUEID = 'x') and (OBJECTID = 'y'))
}
} {}
finish_test
+68 -1
View File
@@ -12,11 +12,16 @@
#
# This file implements tests for the "sqlite3_trace()" API.
#
# $Id: trace.test,v 1.4 2004/09/17 20:46:55 drh Exp $
# $Id: trace.test,v 1.5 2005/08/29 23:00:05 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !trace {
finish_test
return
}
set ::stmtlist {}
do_test trace-1.1 {
set rc [catch {db trace 1 2 3} msg]
@@ -77,5 +82,67 @@ do_test trace-2.5 {
} {SELECT * FROM t1}
catch {sqlite3_finalize $STMT}
# Similar tests, but this time for profiling.
#
do_test trace-3.1 {
set rc [catch {db profile 1 2 3} msg]
lappend rc $msg
} {1 {wrong # args: should be "db profile ?CALLBACK?"}}
set ::stmtlist {}
proc profile_proc {cmd tm} {
lappend ::stmtlist [string trim $cmd]
}
do_test trace-3.2 {
db trace {}
db profile profile_proc
db profile
} {profile_proc}
do_test trace-3.3 {
execsql {
CREATE TABLE t2(a,b);
INSERT INTO t2 VALUES(1,2);
SELECT * FROM t2;
}
} {1 2}
do_test trace-3.4 {
set ::stmtlist
} {{CREATE TABLE t2(a,b);} {INSERT INTO t2 VALUES(1,2);} {SELECT * FROM t2;}}
do_test trace-3.5 {
db profile {}
db profile
} {}
# If we prepare a statement and execute it multiple times, the profile
# happens on each execution.
#
db close
set DB [sqlite3 db test.db]
do_test trace-4.1 {
set STMT [sqlite3_prepare $DB {INSERT INTO t2 VALUES(2,3)} -1 TAIL]
db trace trace_proc
proc profile_proc {sql tm} {
global TRACE_OUT
set TRACE_OUT $sql
}
set TRACE_OUT {}
sqlite3_step $STMT
set TRACE_OUT
} {INSERT INTO t2 VALUES(2,3)}
do_test trace-4.2 {
set TRACE_OUT {}
sqlite3_reset $STMT
set TRACE_OUT
} {}
do_test trace-4.3 {
sqlite3_step $STMT
set TRACE_OUT
} {INSERT INTO t2 VALUES(2,3)}
do_test trace-4.4 {
execsql {SELECT * FROM t1}
} {1 2 2 3 2 3}
do_test trace-4.5 {
set TRACE_OUT
} {SELECT * FROM t1}
catch {sqlite3_finalize $STMT}
finish_test
+16 -9
View File
@@ -93,7 +93,8 @@ ifcapable subquery {
BEGIN
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
old.a, old.b,
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
(SELECT coalesce(sum(a),0) FROM tbl),
(SELECT coalesce(sum(b),0) FROM tbl),
new.a, new.b);
END;
@@ -101,7 +102,8 @@ ifcapable subquery {
BEGIN
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
old.a, old.b,
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
(SELECT coalesce(sum(a),0) FROM tbl),
(SELECT coalesce(sum(b),0) FROM tbl),
new.a, new.b);
END;
@@ -110,7 +112,8 @@ ifcapable subquery {
BEGIN
INSERT INTO clog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM clog),
old.a, old.b,
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
(SELECT coalesce(sum(a),0) FROM tbl),
(SELECT coalesce(sum(b),0) FROM tbl),
new.a, new.b);
END;
}
@@ -140,7 +143,8 @@ ifcapable subquery {
BEGIN
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
old.a, old.b,
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
(SELECT coalesce(sum(a),0) FROM tbl),
(SELECT coalesce(sum(b),0) FROM tbl),
0, 0);
END;
@@ -148,7 +152,8 @@ ifcapable subquery {
BEGIN
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
old.a, old.b,
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
(SELECT coalesce(sum(a),0) FROM tbl),
(SELECT coalesce(sum(b),0) FROM tbl),
0, 0);
END;
}
@@ -172,7 +177,8 @@ ifcapable subquery {
BEGIN
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
0, 0,
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
(SELECT coalesce(sum(a),0) FROM tbl),
(SELECT coalesce(sum(b),0) FROM tbl),
new.a, new.b);
END;
@@ -180,7 +186,8 @@ ifcapable subquery {
BEGIN
INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
0, 0,
(SELECT sum(a) FROM tbl), (SELECT sum(b) FROM tbl),
(SELECT coalesce(sum(a),0) FROM tbl),
(SELECT coalesce(sum(b),0) FROM tbl),
new.a, new.b);
END;
}
@@ -196,8 +203,8 @@ ifcapable subquery {
SELECT * FROM rlog;
}
} [list 1 0 0 0.0 0.0 5 6 \
2 0 0 5.0 6.0 5 6 ]
} [list 1 0 0 0 0 5 6 \
2 0 0 5 6 5 6 ]
integrity_check trigger2-1.$ii.4
}
+13 -13
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the use of indices in WHERE clases.
#
# $Id: where.test,v 1.33 2005/08/24 03:52:19 drh Exp $
# $Id: where.test,v 1.36 2005/09/08 10:37:02 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -336,7 +336,7 @@ ifcapable subquery {
count {
SELECT * FROM t1 WHERE rowid IN (1,2,3,1234) order by 1;
}
} {1 0 4 2 1 9 3 1 16 3}
} {1 0 4 2 1 9 3 1 16 4}
do_test where-5.2 {
count {
SELECT * FROM t1 WHERE rowid+0 IN (1,2,3,1234) order by 1;
@@ -346,7 +346,7 @@ ifcapable subquery {
count {
SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1;
}
} {1 0 4 2 1 9 3 1 16 13}
} {1 0 4 2 1 9 3 1 16 14}
do_test where-5.4 {
count {
SELECT * FROM t1 WHERE w+0 IN (-1,1,2,3) order by 1;
@@ -409,7 +409,7 @@ ifcapable subquery {
count {
SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,10) ORDER BY 1;
}
} {2 1 9 9}
} {2 1 9 8}
do_test where-5.15 {
count {
SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,16) ORDER BY 1;
@@ -443,7 +443,7 @@ do_test where-6.1 {
INSERT INTO t3 SELECT w, 101-w, y FROM t1;
SELECT count(*), sum(a), sum(b), sum(c) FROM t3;
}
} {100 5050.0 5050.0 348550.0}
} {100 5050 5050 348550}
do_test where-6.2 {
cksort {
SELECT * FROM t3 ORDER BY a LIMIT 3
@@ -590,22 +590,22 @@ do_test where-6.21 {
cksort {
SELECT y FROM t1 ORDER BY rowid, y LIMIT 3;
}
} {4 9 16 nosort}
} {4 9 16 sort}
do_test where-6.22 {
cksort {
SELECT y FROM t1 ORDER BY rowid, y DESC LIMIT 3;
}
} {4 9 16 nosort}
} {4 9 16 sort}
do_test where-6.23 {
cksort {
SELECT y FROM t1 WHERE y>4 ORDER BY rowid, w, x LIMIT 3;
}
} {9 16 25 nosort}
} {9 16 25 sort}
do_test where-6.24 {
cksort {
SELECT y FROM t1 WHERE y>=9 ORDER BY rowid, x DESC, w LIMIT 3;
}
} {9 16 25 nosort}
} {9 16 25 sort}
do_test where-6.25 {
cksort {
SELECT y FROM t1 WHERE y>4 AND y<25 ORDER BY rowid;
@@ -620,7 +620,7 @@ do_test where-6.27 {
cksort {
SELECT y FROM t1 WHERE y<=25 ORDER BY _rowid_, w+y;
}
} {4 9 16 25 nosort}
} {4 9 16 25 sort}
# Tests for reverse-order sorting.
@@ -782,19 +782,19 @@ do_test where-7.31 {
} {10201 10000 9801 nosort}
do_test where-7.32 {
cksort {
SELECT y FROM t1 WHERE y<25 ORDER BY rowid DESC, x
SELECT y FROM t1 WHERE y<25 ORDER BY rowid DESC
}
} {16 9 4 nosort}
do_test where-7.33 {
cksort {
SELECT y FROM t1 WHERE y<=25 ORDER BY rowid DESC, x
SELECT y FROM t1 WHERE y<=25 ORDER BY rowid DESC
}
} {25 16 9 4 nosort}
do_test where-7.34 {
cksort {
SELECT y FROM t1 WHERE y<25 AND y>4 ORDER BY rowid DESC, y DESC
}
} {16 9 nosort}
} {16 9 sort}
do_test where-7.35 {
cksort {
SELECT y FROM t1 WHERE y<25 AND y>=4 ORDER BY rowid DESC
+2
View File
@@ -193,8 +193,10 @@ static Keyword aKeywordTable[] = {
{ "OR", "TK_OR", ALWAYS },
{ "ORDER", "TK_ORDER", ALWAYS },
{ "OUTER", "TK_JOIN_KW", ALWAYS },
{ "PLAN", "TK_PLAN", EXPLAIN },
{ "PRAGMA", "TK_PRAGMA", PRAGMA },
{ "PRIMARY", "TK_PRIMARY", ALWAYS },
{ "QUERY", "TK_QUERY", EXPLAIN },
{ "RAISE", "TK_RAISE", TRIGGER },
{ "REFERENCES", "TK_REFERENCES", FKEY },
{ "REGEXP", "TK_LIKE_KW", ALWAYS },
+40
View File
@@ -25,6 +25,46 @@ proc chng {date desc} {
puts "<DD><P><UL>$desc</UL></P></DD>"
}
chng {2005 September 24 (3.2.7)} {
<li>GROUP BY now considers NULLs to be equal again, as it should
</li>
<li>Now compiles on Solaris and OpenBSD and other Unix variants
that lack the fdatasync() function</li>
<li>Now compiles on MSVC++6 again</li>
<li>Fix uninitialized variables causing malfunctions for various obscure
queries</li>
<li>Correctly compute a LEFT OUTER JOINs that is constrained on the
left table only</li>
}
chng {2005 September 17 (3.2.6)} {
<li>Fix a bug that can cause database corruption if a VACUUM (or
autovacuum) fails and is rolled back on a database that is
larger than 1GiB</li>
<li>LIKE optiization now works for columns with COLLATE NOCASE</li>
<li>ORDER BY and GROUP BY now use bounded memory</li>
<li>Added support for COUNT(DISTINCT expr)</li>
<li>Change the way SUM() handles NULL values in order to comply with
the SQL standard</li>
<li>Use fdatasync() instead of fsync() where possible in order to speed
up commits slightly</li>
<li>Use of the CROSS keyword in a join turns off the table reordering
optimization</li>
<li>Added the experimental and undocumented EXPLAIN QUERY PLAN capability</li>
<li>Use the unicode API in windows</li>
}
chng {2005 August 27 (3.2.5)} {
<li>Fix a bug effecting DELETE and UPDATE statements that changed
more than 40960 rows.</li>
<li>Change the makefile so that it no longer requires GNUmake extensions</li>
<li>Fix the --enable-threadsafe option on the configure script</li>
<li>Fix a code generator bug that occurs when the left-hand side of an IN
operator is constant and the right-hand side is a SELECT statement</li>
<li>The PRAGMA synchronous=off statement now disables syncing of the
master journal file in addition to the normal rollback journals</li>
}
chng {2005 August 24 (3.2.4)} {
<li>Fix a bug introduced in the previous release
that can cause a segfault while generating code
+2 -1
View File
@@ -1,4 +1,4 @@
set rcsid {$Id: datatype3.tcl,v 1.10 2004/11/19 11:59:24 danielk1977 Exp $}
set rcsid {$Id: datatype3.tcl,v 1.11 2005/09/17 02:34:05 drh Exp $}
source common.tcl
header {Datatypes In SQLite Version 3}
puts {
@@ -56,6 +56,7 @@ User-defined functions may return values with any storage class. It
is not generally possible to determine the storage class of the
result of an expression at compile time.</P>
<a name="affinity">
<h3>2. Column Affinity</h3>
<p>
+3 -3
View File
@@ -1,4 +1,4 @@
set rcsid {$Id: different.tcl,v 1.5 2005/04/01 16:29:12 drh Exp $}
set rcsid {$Id: different.tcl,v 1.6 2005/09/08 11:04:57 drh Exp $}
source common.tcl
header {Distinctive Features Of SQLite}
puts {
@@ -212,8 +212,8 @@ feature extensions {SQL language extensions} {
<a href="lang_detach.html">DETACH</a> commands that allow multiple
independent databases to be used together in the same query.
And SQLite defines APIs that allows the user to add new
<a href="capi3ref.html#sqlite3_create_function>SQL functions</a>
and <a href="capi3ref.html#sqlite3_create_collation>collating sequences</a>.
<a href="capi3ref.html#sqlite3_create_function">SQL functions</a>
and <a href="capi3ref.html#sqlite3_create_collation">collating sequences</a>.
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+33 -26
View File
@@ -1,7 +1,7 @@
# This script generates the "docs.html" page that describes various
# sources of documentation available for SQLite.
#
set rcsid {$Id: docs.tcl,v 1.11 2005/03/19 14:45:50 drh Exp $}
set rcsid {$Id: docs.tcl,v 1.13 2005/09/08 11:04:57 drh Exp $}
source common.tcl
header {SQLite Documentation}
puts {
@@ -14,7 +14,7 @@ proc doc {name url desc} {
regsub -all { +} $name {\&nbsp;} name
puts "<a href=\"$url\">$name</a></td>"
puts {<td width="10"></td>}
puts {<td align="top" align="left">}
puts {<td valign="top" align="left">}
puts $desc
puts {</td></tr>}
}
@@ -38,16 +38,17 @@ doc {SQL Syntax} {lang.html} {
This document describes the SQL language that is understood by
SQLite.
}
doc {Version 3 C/C++ API<br>Reference} {capi3ref.html} {
This document describes each API function separately.
}
doc {Tcl API} {tclsqlite.html} {
A description of the TCL interface bindings for SQLite.
}
doc {Pragma commands} {pragma.html} {
This document describes SQLite performance tuning options and other
special purpose database commands.
}
doc {Version 2 C/C++ API} {c_interface.html} {
A description of the C/C++ interface bindings for SQLite through version
2.8
}
doc {SQLite Version 3} {version3.html} {
A summary of of the changes between SQLite version 2.8 and SQLite version 3.0.
}
@@ -55,23 +56,6 @@ doc {Version 3 C/C++ API} {capi3.html} {
A description of the C/C++ interface bindings for SQLite version 3.0.0
and following.
}
doc {Version 3 C/C++ API<br>Reference} {capi3ref.html} {
This document describes each API function separately.
}
doc {Tcl API} {tclsqlite.html} {
A description of the TCL interface bindings for SQLite.
}
doc {Locking And Concurrency<br>In SQLite Version 3} {lockingv3.html} {
A description of how the new locking code in version 3 increases
concurrancy and decreases the problem of writer starvation.
}
doc {Version 2 DataTypes } {datatypes.html} {
A description of how SQLite version 2 handles SQL datatypes.
Short summary: Everything is a string.
}
doc {Version 3 DataTypes } {datatype3.html} {
SQLite version 3 introduces the concept of manifest typing, where the
type of a value is associated with the value itself, not the column that
@@ -79,10 +63,17 @@ doc {Version 3 DataTypes } {datatype3.html} {
This page describes data typing for SQLite version 3 in further detail.
}
doc {Release History} {changes.html} {
A chronology of SQLite releases going back to version 1.0.0
doc {Locking And Concurrency<br>In SQLite Version 3} {lockingv3.html} {
A description of how the new locking code in version 3 increases
concurrancy and decreases the problem of writer starvation.
}
doc {Overview Of The Optimizer} {optoverview.html} {
A quick overview of the various query optimizations that are
attempted by the SQLite code generator.
}
doc {Null Handling} {nulls.html} {
Different SQL database engines handle NULLs in different ways. The
SQL standards are ambiguous. This document describes how SQLite handles
@@ -98,6 +89,22 @@ doc {Unsupported SQL} {omitted.html} {
This page describes features of SQL that SQLite does not support.
}
doc {Version 2 C/C++ API} {c_interface.html} {
A description of the C/C++ interface bindings for SQLite through version
2.8
}
doc {Version 2 DataTypes } {datatypes.html} {
A description of how SQLite version 2 handles SQL datatypes.
Short summary: Everything is a string.
}
doc {Release History} {changes.html} {
A chronology of SQLite releases going back to version 1.0.0
}
doc {Speed Comparison} {speed.html} {
The speed of version 2.7.6 of SQLite is compared against PostgreSQL and
MySQL.
+13 -5
View File
@@ -1,7 +1,7 @@
#
# Run this TCL script to generate HTML for the download.html file.
#
set rcsid {$Id: download.tcl,v 1.19 2005/08/22 02:10:46 drh Exp $}
set rcsid {$Id: download.tcl,v 1.22 2005/09/17 19:28:46 drh Exp $}
source common.tcl
header {SQLite Download Page}
@@ -19,9 +19,17 @@ proc Product {pattern desc} {
if {![regexp ^$p2\$ $file all version]} continue
regsub -all _ $version . version
set size [file size $file]
set units bytes
if {$size>1024*1024} {
set size [format %.2f [expr {$size/(1024.0*1024.0)}]]
set units MiB
} elseif {$size>1024} {
set size [format %.2f [expr {$size/(1024.0)}]]
set units KiB
}
puts "<tr><td width=\"10\"></td>"
puts "<td valign=\"top\" align=\"right\">"
puts "<a href=\"$file\">$file</a><br>($size bytes)</td>"
puts "<a href=\"$file\">$file</a><br>($size $units)</td>"
puts "<td width=\"5\"></td>"
regsub -all VERSION $desc $version d2
puts "<td valign=\"top\">[string trim $d2]</td></tr>"
@@ -36,14 +44,14 @@ proc Heading {title} {
Heading {Precompiled Binaries for Linux}
Product sqlite3-VERSION.bin.gz {
A statically linked command-line program for accessing and modifing
A command-line program for accessing and modifing
SQLite databases.
See <a href="sqlite.html">the documentation</a> for additional information.
}
Product sqlite-VERSION.bin.gz {
A statically linked command-line program for accessing and modifing
2 SQLite databases.
A command-line program for accessing and modifing
SQLite databases.
See <a href="sqlite.html">the documentation</a> for additional information.
}
+149 -152
View File
@@ -1,7 +1,7 @@
#
# Run this script to generated a faq.html output file
#
set rcsid {$Id: faq.tcl,v 1.29 2005/06/16 19:48:40 drh Exp $}
set rcsid {$Id: faq.tcl,v 1.31 2005/09/17 02:34:05 drh Exp $}
source common.tcl
header {SQLite Frequently Asked Questions</title>}
@@ -21,11 +21,13 @@ faq {
autoincrement.</p>
<p>Here is the long answer:
Beginning with version SQLite 2.3.4, If you declare a column of
a table to be INTEGER PRIMARY KEY, then whenever you insert a NULL
If you declare a column of a table to be INTEGER PRIMARY KEY, then
whenever you insert a NULL
into that column of the table, the NULL is automatically converted
into an integer which is one greater than the largest value of that
column over all other rows in the table, or 1 if the table is empty.
(If the largest possible integer key, 9223372036854775807, then an
unused key value is chosen at random.)
For example, suppose you have a table like this:
<blockquote><pre>
CREATE TABLE t1(
@@ -41,41 +43,28 @@ INSERT INTO t1 VALUES(NULL,123);
<blockquote><pre>
INSERT INTO t1 VALUES((SELECT max(a) FROM t1)+1,123);
</pre></blockquote>
<p>For SQLite version 2.2.0 through 2.3.3, if you insert a NULL into
an INTEGER PRIMARY KEY column, the NULL will be changed to a unique
integer, but it will a semi-random integer. Unique keys generated this
way will not be sequential. For SQLite version 2.3.4 and beyond, the
unique keys will be sequential until the largest key reaches a value
of 2147483647. That is the largest 32-bit signed integer and cannot
be incremented, so subsequent insert attempts will revert to the
semi-random key generation algorithm of SQLite version 2.3.3 and
earlier.</p>
<p>Beginning with version 2.2.3, there is a new API function named
<b>sqlite3_last_insert_rowid()</b> which will return the integer key
for the most recent insert operation. See the API documentation for
details.</p>
<p>There is a new API function named
<a href="capi3ref.html#sqlite3_last_insert_rowid">
sqlite3_last_insert_rowid()</a> which will return the integer key
for the most recent insert operation.</p>
<p>SQLite version 3.0 expands the size of the rowid to 64 bits.</p>
<p>Note that the integer key is one greater than the largest
key that was in the table just prior to the insert. The new key
will be unique over all keys currently in the table, but it might
overlap with keys that have been previously deleted from the
table. To create keys that are unique over the lifetime of the
table, add the AUTOINCREMENT keyword to the INTEGER PRIMARY KEY
declaration. Then the key chosen will be one more than than the
largest key that has ever existed in that table. If the largest
possible key has previously existed in that table, then the INSERT
will fail with an SQLITE_FULL error code.</p>
}
faq {
What datatypes does SQLite support?
} {
<p>SQLite ignores
the datatype information that follows the column name in CREATE TABLE.
You can put any type of data you want
into any column, without regard to the declared datatype of that column.
</p>
<p>An exception to this rule is a column of type INTEGER PRIMARY KEY.
Such columns must hold an integer. An attempt to put a non-integer
value into an INTEGER PRIMARY KEY column will generate an error.</p>
<p>There is a page on <a href="datatypes.html">datatypes in SQLite
version 2.8</a>
and another for <a href="datatype3.html">version 3.0</a>
that explains this concept further.</p>
<p>See <a href="datatype3.html">http://www.sqlite.org/datatype3.html</a>.</p>
}
faq {
@@ -89,66 +78,27 @@ faq {
CREATE TABLE command does not restrict what data can be put into
that column. Every column is able to hold
an arbitrary length string. (There is one exception: Columns of
type INTEGER PRIMARY KEY may only hold an integer. An error will result
type INTEGER PRIMARY KEY may only hold a 64-bit signed integer.
An error will result
if you try to put anything other than an integer into an
INTEGER PRIMARY KEY column.)</p>
<p>The datatype does effect how values are compared, however. For
columns with a numeric type (such as "integer") any string that looks
like a number is treated as a number for comparison and sorting purposes.
Consider these two command sequences:</p>
<blockquote><pre>
CREATE TABLE t1(a INTEGER UNIQUE); CREATE TABLE t2(b TEXT UNIQUE);
INSERT INTO t1 VALUES('0'); INSERT INTO t2 VALUES(0);
INSERT INTO t1 VALUES('0.0'); INSERT INTO t2 VALUES(0.0);
</pre></blockquote>
<p>In the sequence on the left, the second insert will fail. In this case,
the strings '0' and '0.0' are treated as numbers since they are being
inserted into a numeric column and 0==0.0 which violates the uniqueness
constraint. But the second insert in the right-hand sequence works. In
this case, the constants 0 and 0.0 are treated a strings which means that
they are distinct.</p>
<p>There is a page on <a href="datatypes.html">datatypes in SQLite
version 2.8</a>
and another for <a href="datatype3.html">version 3.0</a>
that explains this concept further.</p>
<p>But SQLite does use the declared type of a column as a hint
that you prefer values in that format. So, for example, if a
column is of type INTEGER and you try to insert a string into
that column, SQLite will attempt to convert the string into an
integer. If it can, it inserts the integer instead. If not,
it inserts the string. This feature is sometimes
call <a href="datatype3.html#affinity">type or column affinity</a>.
</p>
}
faq {
Why does SQLite think that the expression '0'=='00' is TRUE?
} {
<p>As of version 2.7.0, it doesn't.</p>
<p>But if one of the two values being compared is stored in a column that
has a numeric type, the the other value is treated as a number, not a
string and the result succeeds. For example:</p>
<blockquote><pre>
CREATE TABLE t3(a INTEGER, b TEXT);
INSERT INTO t3 VALUES(0,0);
SELECT count(*) FROM t3 WHERE a=='00';
</pre></blockquote>
<p>The SELECT in the above series of commands returns 1. The "a" column
is numeric so in the WHERE clause the string '00' is converted into a
number for comparison against "a". 0==00 so the test is true. Now
consider a different SELECT:</p>
<blockquote><pre>
SELECT count(*) FROM t3 WHERE b=='00';
</pre></blockquote>
<p>In this case the answer is 0. B is a text column so a text comparison
is done against '00'. '0'!='00' so the WHERE clause returns FALSE and
the count is zero.</p>
<p>There is a page on <a href="datatypes.html">datatypes in SQLite
version 2.8</a>
and another for <a href="datatype3.html">version 3.0</a>
that explains this concept further.</p>
<p>As of version 2.7.0, it doesn't. See the document on
<a href="datatype3.html">datatypes in SQLite version 3</a>
for details.</p>
}
faq {
@@ -186,19 +136,14 @@ faq {
<p>Multiple processes can have the same database open at the same
time. Multiple processes can be doing a SELECT
at the same time. But only one process can be making changes to
the database at once.</p>
the database at an given moement in time, however.</p>
<p>Win95/98/ME lacks support for reader/writer locks in the operating
system. Prior to version 2.7.0, this meant that under windows you
could only have a single process reading the database at one time.
This problem was resolved in version 2.7.0 by implementing a user-space
probabilistic reader/writer locking strategy in the windows interface
code file. Windows
now works like Unix in allowing multiple simultaneous readers.</p>
<p>The locking mechanism used to control simultaneous access might
<p>SQLite uses reader/writer locks to control access to the database.
(Under Win95/98/ME which lacks support for reader/writer locks, a
probabilistic simulation is used instead.)
But use caution: this locking mechanism might
not work correctly if the database file is kept on an NFS filesystem.
This is because file locking is broken on some NFS implementations.
This is because fcntl() file locking is broken on many NFS implementations.
You should avoid putting SQLite database files on NFS if multiple
processes might try to access the file at the same time. On Windows,
Microsoft's documentation says that locking may not work under FAT
@@ -208,24 +153,32 @@ faq {
say is true, sharing an SQLite database between two or more Windows
machines might cause unexpected problems.</p>
<p>Locking in SQLite is very course-grained. SQLite locks the
entire database. Big database servers (PostgreSQL, Oracle, etc.)
generally have finer grained locking, such as locking on a single
table or a single row within a table. If you have a massively
parallel database application, you should consider using a big database
server instead of SQLite.</p>
<p>We are aware of no other <i>embedded</i> SQL database engine that
supports as much concurrancy as SQLite. SQLite allows multiple processes
to have the database file open at once, and for multiple processes to
read the database at once. When any process wants to write, it must
lock the entire database file for the duration of its update. But that
normally only takes a few milliseconds. Other processes just wait on
the writer to finish then continue about their business. Other embedded
SQL database engines typically only allow a single process to connect to
the database at once.</p>
<p>However, client/server database engines (such as PostgreSQL, MySQL,
or Oracle) usually support a higher level of concurrency and allow
multiple processes to be writing to the same database at the same time.
This is possible in a client/server database because there is always a
single well-controlled server process available to coordinate access.
If your application has a need for a lot of concurrency, then you should
consider using a client/server database. But experience suggests that
most applications need much less concurrency than their designers imagine.
</p>
<p>When SQLite tries to access a file that is locked by another
process, the default behavior is to return SQLITE_BUSY. You can
adjust this behavior from C code using the <b>sqlite3_busy_handler()</b> or
<b>sqlite3_busy_timeout()</b> API functions. See the API documentation
for details.</p>
<p>If two or more processes have the same database open and one
process creates a new table or index, the other processes might
not be able to see the new table right away. You might have to
get the other processes to close and reopen their connection to
the database before they will be able to see the new table.</p>
adjust this behavior from C code using the
<a href="capi3ref#sqlite3_busy_handler">sqlite3_busy_handler()</a> or
<a href="capi3ref#sqlite3_busy_timeout">sqlite3_busy_timeout()</a>
API functions.</p>
}
faq {
@@ -239,21 +192,20 @@ faq {
<p>"Threadsafe" in the previous paragraph means that two or more threads
can run SQLite at the same time on different "<b>sqlite3</b>" structures
returned from separate calls to <b>sqlite3_open()</b>. It is never safe
to use the same <b>sqlite3</b> structure pointer simultaneously in two
returned from separate calls to
<a href="capi3ref#sqlite3_open">sqlite3_open()</a>. It is never safe
to use the same <b>sqlite3</b> structure pointer in two
or more threads.</p>
<p>An <b>sqlite3</b> structure can only be used in the same thread
that called <b>sqlite3_open</b> to create it. You cannot open a
that called <a href="capi3ref#sqlite3_open">sqlite3_open</a> to create it.
You cannot open a
database in one thread then pass the handle off to another thread for
it to use. This is due to limitations (bugs?) in many common threading
implementations such as on RedHat9.</p>
<p>Note that if two or more threads have the same database open and one
thread creates a new table or index, the other threads might
not be able to see the new table right away. You might have to
get the other threads to close and reopen their connection to
the database before they will be able to see the new table.</p>
implementations such as on RedHat9. There may be ways to work around
these limitations, but they are complex and exceedingly difficult to
test for correctness. For that reason, SQLite currently takes the safe
approach and disallows the sharing of handles among threads.</p>
<p>Under UNIX, you should not carry an open SQLite database across
a fork() system call into the child process. Problems will result
@@ -321,52 +273,64 @@ ORDER BY name
faq {
Are there any known size limits to SQLite databases?
} {
<p>As of version 2.7.4,
SQLite can handle databases up to 2<sup>41</sup> bytes (2 terabytes)
in size on both Windows and Unix. Older version of SQLite
were limited to databases of 2<sup>31</sup> bytes (2 gigabytes).</p>
<p>A database is limited in size to 2 tibibytes (2<sup>41</sup> bytes).
That is a theoretical limitation. In practice, you should try to keep
your SQLite databases below 100 gigabytes to avoid performance problems.
If you need to store 100 gigabytes or more in a database, consider using
an enterprise database engine which is designed for that purpose.</p>
<p>SQLite version 2.8 limits the amount of data in one row to
1 megabyte. SQLite version 3.0 has no limit on the amount of
data that can be stored in a single row.
<p>The theoretical limit on the number of rows in a table is
2<sup>64</sup>-1, though obviously you will run into the file size
limitation prior to reaching the row limit. A single row can hold
up to 2<sup>30</sup> bytes of data in the current implementation. The
underlying file format supports row sizes up to about 2<sup>62</sup> bytes.
</p>
<p>There are probably limits on the number of tables or indices or
the number of columns in a table or index, but nobody is sure what
those limits are. In practice, SQLite must read and parse the original
SQL of all table and index declarations everytime a new database file
is opened, so for the best performance of
<a href="capi3ref.html#sqlite3_open">sqlite3_open()</a> it is best
to keep down the number of declared tables. Likewise, though there
is no limit on the number of columns in a table, more than a few hundred
seems extreme. Only the first 31 columns of a table are candidates for
certain optimizations. You can put as many columns in an index as you like
but indexes with more than 30 columns will not be used to optimize queries.
</p>
<p>The names of tables, indices, view, triggers, and columns can be
as long as desired. However, the names of SQL functions (as created
by the <a href="c_interface.html#cfunc">sqlite3_create_function()</a> API)
may not exceed 255 characters in length.</p>
by the
<a href="capi3ref.html#sqlite3_create_function">sqlite3_create_function()</a>
API) may not exceed 255 characters in length.</p>
}
faq {
What is the maximum size of a VARCHAR in SQLite?
} {
<p>SQLite does not enforce datatype constraints.
A VARCHAR column can hold as much data as you care to put in it.</p>
<p>SQLite does not enforce the length of a VARCHAR. You can declare
a VARCHAR(10) and SQLite will be happy to let you put 500 characters
in it. And it will keep all 500 characters intact - it never truncates.
</p>
}
faq {
Does SQLite support a BLOB type?
} {
<p>SQLite version 3.0 lets you puts BLOB data into any column, even
<p>SQLite versions 3.0 and leter let you puts BLOB data into any column, even
columns that are declared to hold some other type.</p>
<p>SQLite version 2.8 will store any text data without embedded
'\000' characters. If you need to store BLOB data in SQLite version
2.8 you'll want to encode that data first.
There is a source file named
"<b>src/encode.c</b>" in the SQLite version 2.8 distribution that contains
implementations of functions named "<b>sqlite_encode_binary()</b>
and <b>sqlite_decode_binary()</b> that can be used for converting
binary data to ASCII and back again, if you like.</p>
}
faq {
How do I add or delete columns from an existing table in SQLite.
} {
<p>SQLite does yes not support the "ALTER TABLE" SQL command. If you
what to change the structure of a table, you have to recreate the
<p>SQLite has limited
<a href="lang_altertable.html">ALTER TABLE</a> support that you can
use to add a column to the end of a table or to change the name of
a table.
If you what make more complex changes the structure of a table,
you will have to recreate the
table. You can save existing data to a temporary table, drop the
old table, create the new table, then copy the data back in from
the temporary table.</p>
@@ -398,7 +362,8 @@ faq {
neither is it returned to the operating system.</p>
<p>If you delete a lot of data and want to shrink the database file,
run the VACUUM command (version 2.8.1 and later). VACUUM will reconstruct
run the <a href="lang_vacuum.html">VACUUM</a> command.
VACUUM will reconstruct
the database from scratch. This will leave the database with an empty
free-list and a file that is minimal in size. Note, however, that the
VACUUM can take some time to run (around a half second per megabyte
@@ -414,7 +379,8 @@ faq {
faq {
Can I use SQLite in my commercial product without paying royalties?
} {
<p>Yes. SQLite is in the public domain. No claim of ownership is made
<p>Yes. SQLite is in the
<a href="copyright.html">public domain</a>. No claim of ownership is made
to any part of the code. You can do anything you want with it.</p>
}
@@ -433,12 +399,18 @@ faq {
}
faq {What is an SQLITE_SCHEMA error, and why am I getting one?} {
<p>In version 3 of SQLite, an SQLITE_SCHEMA error is returned when a
<p>An SQLITE_SCHEMA error is returned when a
prepared SQL statement is no longer valid and cannot be executed.
When this occurs, the statement must be recompiled from SQL using
the sqlite3_prepare() API. In SQLite 3, an SQLITE_SCHEMA error can
only occur when using the sqlite3_prepare()/sqlite3_step()/sqlite3_finalize()
API to execute SQL, not when using the sqlite3_exec(). This was not
the
<a href="capi3ref.html#sqlite3_prepare">sqlite3_prepare()</a> API.
In SQLite version 3, an SQLITE_SCHEMA error can
only occur when using the
<a href="capi3ref.html#sqlite3_prepare">sqlite3_prepare()</a>/<a
href="capi3ref.html#sqlite3_step">sqlite3_step()</a>/<a
href="capi3ref.html#sqlite3_finalize">sqlite3_finalize()</a>
API to execute SQL, not when using the
<a href="capi3ref.html#sqlite3_exec">sqlite3_exec()</a>. This was not
the case in version 2.</p>
<p>The most common reason for a prepared statement to become invalid
@@ -446,7 +418,8 @@ faq {What is an SQLITE_SCHEMA error, and why am I getting one?} {
prepared (possibly by another process). The other reasons this can
happen are:</p>
<ul>
<li>A database was DETACHed.
<li>A database was <a href="lang_detach.html">DETACH</a>ed.
<li>The database was <a href="lang_vacuum.html">VACUUM</a>ed
<li>A user-function definition was deleted or changed.
<li>A collation sequence definition was deleted or changed.
<li>The authorization function was changed.
@@ -455,7 +428,10 @@ faq {What is an SQLITE_SCHEMA error, and why am I getting one?} {
<p>In all cases, the solution is to recompile the statement from SQL
and attempt to execute it again. Because a prepared statement can be
invalidated by another process changing the database schema, all code
that uses the sqlite3_prepare()/sqlite3_step()/sqlite3_finalize()
that uses the
<a href="capi3ref.html#sqlite3_prepare">sqlite3_prepare()</a>/<a
href="capi3ref.html#sqlite3_step">sqlite3_step()</a>/<a
href="capi3ref.html#sqlite3_finalize">sqlite3_finalize()</a>
API should be prepared to handle SQLITE_SCHEMA errors. An example
of one approach to this follows:</p>
@@ -484,6 +460,27 @@ faq {What is an SQLITE_SCHEMA error, and why am I getting one?} {
</pre></blockquote>
}
faq {Why does ROUND(9.95,1) return 9.9 instead of 10.0?
Shouldn't 9.95 round up?} {
<p>SQLite uses binary arithmetic and in binary, there is no
way to write 9.95 in a finite number of bits. The closest to
you can get to 9.95 in a 64-bit IEEE float (which is what
SQLite uses) is 9.949999999999999289457264239899814128875732421875.
So when you type "9.95", SQLite really understands the number to be
the much longer value shown above. And that value rounds down.</p>
<p>This kind of problem comes up all the time when dealing with
floating point binary numbers. The general rule to remember is
that most fractional numbers that have a finite representation in decimal
(a.k.a "base-10")
do not have a finite representation in binary (a.k.a "base-2").
And so they are
approximated using the closest binary number available. That
approximation is usually very close, but it will be slightly off
and in some cases can cause your results to be a little different
from what you might expect.</p>
}
# End of questions and answers.
#############
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

+30 -37
View File
@@ -7,10 +7,13 @@ puts {
<td width="50%" valign="top">
<h2>About SQLite</h2>
<p>
<table align="right" border="0"><tr><td>
<a href="http://osdir.com/Article6677.phtml">
<img src="2005osaward.gif"></a>
</td></tr></table>
SQLite is a small
C library that implements a self-contained, embeddable,
zero-configuration,
<a href="http://osdir.com/Article6677.phtml">award-winning</a>
zero-configuration
SQL database engine.
Features include:
</p>
@@ -27,8 +30,8 @@ Features include:
<li>Supports databases up to 2 terabytes
(2<sup><small>41</small></sup> bytes) in size.</li>
<li>Sizes of strings and BLOBs limited only by available memory.</li>
<li>Small code footprint: less than 30K lines of C code,
less than 250KB code space (gcc on i486)</li>
<li>Small code footprint: less than 250KiB fully configured or less
than 150KiB with optional features omitted.</li>
<li><a href="speed.html">Faster</a> than popular client/server database
engines for most common operations.</li>
<li>Simple, easy to use <a href="capi3.html">API</a>.</li>
@@ -63,6 +66,28 @@ proc newsitem {date title text} {
puts "<hr width=\"50%\">"
}
newsitem {2005-Sep-24} {Version 3.2.7} {
This version fixes several minor and obscure bugs.
Upgrade only if you are having problems.
}
newsitem {2005-Sep-16} {Version 3.2.6 - Critical Bug Fix} {
This version fixes a bug that can result in database
corruption if a VACUUM of a 1 gibibyte or larger database fails
(perhaps do to running out of disk space or an unexpected power loss)
and is later rolled back.
<p>
Also in this release:
The ORDER BY and GROUP BY processing was rewritten to use less memory.
Support for COUNT(DISTINCT) was added. The LIKE operator can now be
used by the optimizer on columns with COLLATE NOCASE.
}
newsitem {2005-Aug-27} {Version 3.2.5} {
This release fixes a few more lingering bugs in the new code.
We expect that this release will be stable and ready for production use.
}
newsitem {2005-Aug-24} {Version 3.2.4} {
This release fixes a bug in the new optimizer that can lead to segfaults
when parsing very complex WHERE clauses.
@@ -77,46 +102,14 @@ newsitem {2005-Aug-21} {Version 3.2.3} {
}
newsitem {2005-Aug-2} {2005 Open Source Award for SQLite} {
<table align="right" border="0"><tr><td>
<a href="http://osdir.com/Article6677.phtml">
<img src="2005osaward.gif"></a>
</td></tr></table>
SQLite and its primary author D. Richard Hipp have been honored with
a <a href="http://osdir.com/Article6677.phtml">2005 Open Source
Award</a> from Google and O'Reilly.<br clear="right">
}
newsitem {2005-Jun-13} {Version 3.2.2} {
This release includes numerous minor bug fixes, speed improvements,
and code size reductions. There is no reason to upgrade unless you
are having problems or unless you just want to.
}
newsitem {2005-Mar-29} {Version 3.2.1} {
This release fixes a memory allocation problem in the new
<a href="lang_altertable.html">ALTER TABLE ADD COLUMN</a>
command.
}
newsitem {2005-Mar-21} {Version 3.2.0} {
The primary purpose for version 3.2.0 is to add support for
<a href="lang_altertable.html">ALTER TABLE ADD COLUMN</a>.
The new ADD COLUMN capability is made
possible by AOL developers supporting and embracing great
open-source software. Thanks, AOL!
Version 3.2.0 also fixes an obscure but serious bug that was discovered
just prior to release. If you have a multi-statement transaction and
within that transaction an UPDATE or INSERT statement fails due to a
constraint, then you try to rollback the whole transaction, the rollback
might not work correctly. See
<a href="http://www.sqlite.org/cvstrac/tktview?tn=1171">Ticket #1171</a>
for details. Upgrading is recommended for all users.
}
puts {
<p align="right"><a href="oldnews.html">Old news...</a></p>
</td></tr></table>
}
footer {$Id: index.tcl,v 1.119 2005/08/24 11:07:19 drh Exp $}
footer {$Id: index.tcl,v 1.126 2005/09/24 15:11:00 drh Exp $}
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

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