Compare commits

...

206 Commits

Author SHA1 Message Date
drh 4ebf07fafe Version 3.6.6.1 (CVS 5948)
FossilOrigin-Name: c2266aa094411346a73ab704c03ec919d6e5f46d
2008-11-22 15:51:27 +00:00
drh cef4deecd7 Port the corruption bug fix of check-in (5938) into a branch off of
version 3.6.6. (CVS 5947)

FossilOrigin-Name: 15d88edf7671822c57238c3f85adf0b40b13e3e2
2008-11-22 14:07:49 +00:00
drh d164fd3483 When a memory allocation fails on the %Q conversion in sqlite3_mprintf(),
make sure the error is reported back up the call stack. (CVS 5933)

FossilOrigin-Name: eebacbc9d7d0625dfbe6367046fa4a0ca9c04e74
2008-11-20 18:20:28 +00:00
shane c7b7f1ae1d In os_win.c, if SQLITE_TEST defined, winRandomness() should return all zeroes like os_unix.c. (CVS 5932)
FossilOrigin-Name: 00b68a1e3164fbf04dabb480c2037be45612b4e4
2008-11-19 21:35:46 +00:00
drh 10ec0fa557 Version 3.6.6 (CVS 5931)
FossilOrigin-Name: 01a6e2820af0729f01ce90664ce9a6aa63e5b09a
2008-11-19 21:03:37 +00:00
drh 1e9db16c55 Force the corruptC.test script to use file format 1. (CVS 5930)
FossilOrigin-Name: deadc2548d1e43cbbfe3af049cc5f59ee55bda46
2008-11-19 18:43:07 +00:00
shane 6468ad04e4 In bitvec.c: removed some of the recursion, minor optimizations, added comments, improved consistency. (CVS 5929)
FossilOrigin-Name: 54d714fba6624e0c7adb961317c75a8a8c5fa8de
2008-11-19 18:30:34 +00:00
drh 1feb7dd391 Update the SECURE_DELETE code to track the latest changes in the pager. (CVS 5928)
FossilOrigin-Name: e058f509374e98e48eafeba2f1dadff9633d1190
2008-11-19 18:30:29 +00:00
danielk1977 f3d3c27a0c Fix some compiler warnings that show up when building the amalgamation only. (CVS 5927)
FossilOrigin-Name: d1abe8a1c9a990b02c71d6c249436381c9fde443
2008-11-19 16:52:44 +00:00
danielk1977 a03396aafb Fix a few more compiler warnings. (CVS 5926)
FossilOrigin-Name: 70b2f6839ca97dfc08f72875283f5c75c8fcf0cc
2008-11-19 14:35:46 +00:00
danielk1977 c70dfc477f In os_unix.c, use "IS_VXWORKS" instead of "defined(__RTP__) || defined(_WRS_KERNEL)". Purely because it's easier on the eyes. (CVS 5925)
FossilOrigin-Name: 92c91a6cd7bcbe79206bdf7708fe9049a7b7fdd6
2008-11-19 13:52:30 +00:00
drh 1aa690c87c Version number to 3.6.6. (CVS 5924)
FossilOrigin-Name: 8cc120fb3aed835a2cd081963317b7f1b1ac4b73
2008-11-19 12:43:20 +00:00
danielk1977 397d65f641 Eliminate some of the "unused parameter" warnings in os_unix.c. (CVS 5923)
FossilOrigin-Name: 2f5aaad90b7e3bbb31866c43db3e24a1be26f03b
2008-11-19 11:35:39 +00:00
danielk1977 1ceedd3736 Simplify the way the pager layer invokes the busy-handler callback. (CVS 5922)
FossilOrigin-Name: 7bd1ac189906d87ed360875551d50147dd2186f6
2008-11-19 10:22:33 +00:00
danielk1977 62c14b3487 Changes to avoid "unused parameter" compiler warnings. (CVS 5921)
FossilOrigin-Name: 88134322c36b41304aaeef99c39b4ef5b495ca3b
2008-11-19 09:05:26 +00:00
drh b232c23297 Add an alternative application-defined pcache implementation and add test
cases to permutations.test to invoke it.  Added the SQLITE_CONFIG_GETPCACHE
method to sqlite3_config(). (CVS 5920)

FossilOrigin-Name: 16f1e6ec2ad92f68c0079a0c2b5ca08a3b4af816
2008-11-19 01:20:26 +00:00
drh 4c6517848f Fix to the lemon parser template when YYSTACKSIZE is 0 (dynamically
allocated stack space). (CVS 5919)

FossilOrigin-Name: 00ccc5967f8912961029a3513445c5e2ac713560
2008-11-18 23:25:54 +00:00
pweilbacher 50128aea6a Add support for SQLITE_NO_SYNC for OS/2, too. (CVS 5918)
FossilOrigin-Name: 2990b5b8e7bd8f91af24e5a606666077855ae283
2008-11-18 23:03:39 +00:00
drh 1d2988554c Expose the MBCS->UTF8 convert routine in the Win32 backend. (CVS 5917)
FossilOrigin-Name: f4411f0c8075adc8a37002ac7ad958ff3158c0c0
2008-11-18 19:18:52 +00:00
drh 2161474f62 Application-defined page cache documentation updates. (CVS 5916)
FossilOrigin-Name: db0f1203591fcc4c554c47cdf28abe279cf7f1d5
2008-11-18 19:18:08 +00:00
danielk1977 cdcfe95cec Reduce the number of "missing initializer" warnings. (CVS 5915)
FossilOrigin-Name: d68e2795e72f1bfc0bf3b8e75cdec2e0b3d5bfcb
2008-11-18 07:27:24 +00:00
danielk1977 00e136135e Modifications to avoid unsigned/signed comparisons in various files. (CVS 5914)
FossilOrigin-Name: 8009220c36635dd9b6efea7dc13281ca9625c40a
2008-11-17 19:18:54 +00:00
danielk1977 234329761a Modifications to avoid unsigned/signed comparisons in where.c. (CVS 5913)
FossilOrigin-Name: f35606d1d8cd6dba541a79dcb1307698b8831854
2008-11-17 16:42:00 +00:00
danielk1977 64202cfec6 Modifications to avoid signed/unsigned warnings in vdbe.c. (CVS 5912)
FossilOrigin-Name: 9939dd839ac13708f9b5b877c48729b1781eedf3
2008-11-17 15:31:47 +00:00
danielk1977 89d4004f03 Changes to btree.c to avoid the unsigned/signed comparison warnings. (CVS 5911)
FossilOrigin-Name: 24469dbace433ca89e22274f741f382052c5d17d
2008-11-17 14:20:56 +00:00
chw 971854898a Added support for vxworks >= 6.4; RTP mode tested, kernel mode untested. (CVS 5910)
FossilOrigin-Name: f45a1493636a5ee474dd6c0b5d286be2249b05aa
2008-11-17 08:05:31 +00:00
danielk1977 d92db531c8 Modifications to pager.c to avoid the unsigned/signed warnings. (CVS 5909)
FossilOrigin-Name: cb6be84dfc5d6546d07359b32fe04555561325de
2008-11-17 04:56:24 +00:00
danielk1977 44cd45c85d Fix compiler warnings in pcache1.c related to comparison of unsigned and signed values. (CVS 5908)
FossilOrigin-Name: ce77ea989ea0bf4b44d5b9d0e58d30fd956038d3
2008-11-15 11:22:45 +00:00
danielk1977 032c0c14f9 Add a line to genfkey.README showing how to link against a shared library. Ticket #3502. (CVS 5907)
FossilOrigin-Name: 800274b76945a41ca4ea72c455d220103a6b01dc
2008-11-15 04:54:31 +00:00
danielk1977 777da0848d Fix a couple of memory leaks that may follow malloc failures. (CVS 5906)
FossilOrigin-Name: 4cf8a8e1bf22e1d8f7166e64328a95fe36c75033
2008-11-13 19:12:34 +00:00
shane dcc50b74e6 Fixed several more crashes due to corrupt db files. Added corruptC.test to soak.test. (CVS 5905)
FossilOrigin-Name: 9b7a52e952c81e50611e04d2d79003b0ddc57ee5
2008-11-13 18:29:50 +00:00
shane 84ca3837c2 Added support for -DSQLITE_NO_SYNC to os_win.c. (CVS 5904)
FossilOrigin-Name: 2649337937077d2dba7cdc7473fcd176aa252a52
2008-11-13 18:20:43 +00:00
shane ec21707dd7 Fixed typo in tkt3472.test that prevented the test from running. (CVS 5903)
FossilOrigin-Name: 428a5479200dc24e2ee9b4a85ef6caadacbdbbd7
2008-11-13 18:02:51 +00:00
danielk1977 093e0f6ffe Avoid committing a transaction from within the xSync() method of a virtual table. Fix for #3497. (CVS 5902)
FossilOrigin-Name: eabb8b7591eab164c637d78ca4df00fcb5bd3c5b
2008-11-13 18:00:14 +00:00
danielk1977 ac8d7b35fa Minor changes to get memsys5 compiling and its tests passing. Ticket #3495. (CVS 5901)
FossilOrigin-Name: 96453ca16e90bc0c0cbfb75b3e39899f56d6ea66
2008-11-13 16:21:50 +00:00
danielk1977 d17e71c95c Update mksqlite3c.tcl to include new file pcache1.c. (CVS 5900)
FossilOrigin-Name: 00442e0f57b52808d087154c84ece531bf1cfb62
2008-11-13 14:42:18 +00:00
danielk1977 bc2ca9eb39 Add an API to support custom page cache implementations. (CVS 5899)
FossilOrigin-Name: 47866d6708e9b69e367937fd85f93580fd025447
2008-11-13 14:28:28 +00:00
danielk1977 0d0654119f Avoid some buffer overreads detected by valgrind while running corruptC.test. (CVS 5898)
FossilOrigin-Name: faa6bd7b615837c920b5b3b027115caa2f56ec15
2008-11-12 18:21:36 +00:00
drh f99b7c8d56 Version 3.6.5 (CVS 5897)
FossilOrigin-Name: 369f74983bb1b6a6426260148018cdc084fc2b49
2008-11-12 15:38:53 +00:00
drh 7ab49bfd1e Do not redefine the MIN and MAX macros if they are already defined. (CVS 5896)
FossilOrigin-Name: f41dd2053c8a297a05b47d0ef631b4d9a7db2fff
2008-11-12 15:24:27 +00:00
danielk1977 ef988b47a4 In corruptC.test, explicitly set "PRAGMA auto_vacuum = 0". (CVS 5895)
FossilOrigin-Name: b6563af8f9517760c2346a820e241b0517a10fe0
2008-11-12 14:22:25 +00:00
drh 03c7a2f1a1 Update the version number to 3.6.5. (CVS 5894)
FossilOrigin-Name: f150b870e3a24d407d8d5ac374e2a7d0f4072a2d
2008-11-12 14:21:05 +00:00
drh 0d7f4fc4b0 Omit the threadOverrideEachOthersLocks tests for builds that non-unix
or non-threadsafe. (CVS 5893)

FossilOrigin-Name: ab418656dbf3d2e055b2462a155d90863fef6582
2008-11-12 14:07:51 +00:00
drh d72a276e9a Fix a faulty assert in select.c. Ticket #3494. (CVS 5892)
FossilOrigin-Name: e89f9c806328e0de2e8633e09242f67e26f43d76
2008-11-12 12:27:31 +00:00
danielk1977 ab396298c4 Modify a failing test case in corruptC.test. The test case was failing only because the integrity_check was returning a slightly different error message than expected. (CVS 5891)
FossilOrigin-Name: 0953f300f8e8b2bed79ef3189a1cb29f058f388b
2008-11-12 11:57:41 +00:00
danielk1977 360e634ed4 Fix a database corruption related crash uncovered by corruptC.test. (CVS 5890)
FossilOrigin-Name: 395084acbb4c8ef878d858f640f1ed6be908d175
2008-11-12 08:49:51 +00:00
danielk1977 259a455f71 Make sure affinities and implicit collation sequences are correctly used by comparison expressions in the select-list or having clause of an aggregate query. Ticket #3493. (CVS 5889)
FossilOrigin-Name: b8ceaa00500f29bbbd0cc5aec71a6ffa91ae6b43
2008-11-12 08:07:12 +00:00
shane 0af3f8935f Fixed a few more crashes when dealing with corrupt db files. (CVS 5888)
FossilOrigin-Name: f8bb34e40917e55696376d2def932a41ad43d0ae
2008-11-12 04:55:34 +00:00
shane 34ac18daf5 Fixed crash during an UPDATE when free cell size is corrupt. (CVS 5887)
FossilOrigin-Name: ec18667e2d2826a27f2c052ba3790ab5b8cf0bc4
2008-11-11 22:18:20 +00:00
shane 826d5b7e1c Prevent a crash during an UPDATE when the cell offset is corrupt. (CVS 5886)
FossilOrigin-Name: 99d4172ed6825c7efb6cbb28eb00d98323a13954
2008-11-11 20:51:50 +00:00
drh dfef499856 Send the "Incomplete SQL" error message of the CLI to stderr instead of
stdout.  Ticket #3476. (CVS 5885)

FossilOrigin-Name: dacae200477afffec826b3ca1517f33b110b6122
2008-11-11 18:55:03 +00:00
danielk1977 95338ab70c Remove some asserts that refer to variables removed in (5830). (CVS 5884)
FossilOrigin-Name: 9d880a6fd244fb73d0fce7e8180177c54d95cde2
2008-11-11 18:43:00 +00:00
danielk1977 41a6a61d94 Change the way threadsOverrideEachOthersLocks() works to avoid trying to write-lock a (potentially) read-only files. Also, assume that on non-linux systems threads do override each others locks. Ticket #3472. (CVS 5883)
FossilOrigin-Name: 8ecae0943b06102fe22133db0dcaf58ecbd39545
2008-11-11 18:34:35 +00:00
drh a78c22c433 Cleanup in flattenSubquery. Add OOM tests for flattenSubquery. Fix issues
with OOM errors causes problems for flattenSubquery.  Ticket #3485. (CVS 5882)

FossilOrigin-Name: ea5f4baa041aed934600f0f96b84afb92a14bc47
2008-11-11 18:28:58 +00:00
shane 5780ebdf79 Fixed crash in integrity_check with corrupt content offset size in page header. (CVS 5881)
FossilOrigin-Name: 0659a666ff0a9fc81ee4df3c35e535164c79e588
2008-11-11 17:36:30 +00:00
drh 86a7a69cbe Avoid signed/unsigned comparison warnings in bitvec.c by changing the
types of loop variables to unsigned int. (CVS 5880)

FossilOrigin-Name: da869446c53ec6ed769bba01cdc2b6fd69a8b5c9
2008-11-11 15:48:48 +00:00
drh 4d01aeedbb When an assignment occurs in a boolean, always test the result using "!=0"
to avoid confusion and make it clear that assignment is intended, not
an equality test.  Ticket #3491. (CVS 5879)

FossilOrigin-Name: 89ee5295bdea6f2c093eb6a44d69917dcc8459e3
2008-11-11 00:36:16 +00:00
drh c717b382b8 Fix the CLI so that it does not terminate input when an Oracle or MS-SQL
command terminator mark is seen in the middle of a string literal.
Ticket #3490. (CVS 5878)

FossilOrigin-Name: 68662e3b487b80b2c94cd2376060388bd8df0e4e
2008-11-11 00:30:11 +00:00
drh 753cc1077b When an OOM error occurs while resizing an sqlite_value object, make sure
the value of the object is set to NULL.  Ticket #3488. (CVS 5877)

FossilOrigin-Name: 7b9c9b35fffb233e76148182426199d51243fba7
2008-11-11 00:21:30 +00:00
drh 2e904c5f9e Fix the documentation of the SQLITE_FUNCTION authorizer code so that it
agrees with how SQLite has always behaved.  Ticket #3489. (CVS 5876)

FossilOrigin-Name: 806b6ed202292e386ac3e51cebcfb67f3870cd2f
2008-11-10 23:54:05 +00:00
shane b2111838c6 #ifdef out unused static function mutexIsNT(). Ticket #3481. (CVS 5875)
FossilOrigin-Name: 239186804c7541abc512da33bba8f6fc7d24a374
2008-11-10 20:01:40 +00:00
shane c782f69abb Updated comment in source. Ticket #3453. (CVS 5874)
FossilOrigin-Name: 83caa22087bcaa184eff559971262e4d7eecd0e0
2008-11-10 19:24:38 +00:00
shane c8330f4b1d Add check for ifcapable autovacuum to vacuum2-3.3 test. Ticket #3435. (CVS 5873)
FossilOrigin-Name: fc36f2fc45b2d319ef0be97e1af1748d3e862690
2008-11-10 18:20:16 +00:00
shane 2479de3a20 Removed a few more small parts of memsys6 code, including some config and test code for it; (CVS 5872)
FossilOrigin-Name: a11241d6fbc9e0408d5adc73d494b85124d2d609
2008-11-10 18:05:35 +00:00
shane 831c329542 In btree.c, omit calls to setChildPtrmaps() if SQLITE_OMIT_AUTOVACUUM is defined. Ticket #3439. (CVS 5871)
FossilOrigin-Name: e0f07323e878c44ad2ccc38628c74c27f79e35ef
2008-11-10 17:14:58 +00:00
shane 7ba429a61c Fixed typos; Consistent use of Mac OS X name; (CVS 5870)
FossilOrigin-Name: dfc94743378e576ecc5c567ae4020bf9594a3fb9
2008-11-10 17:08:49 +00:00
drh bbf695d6ea Prevent buffer overruns when converting malformed UTF16 to UTF8. Ticket #3482. (CVS 5869)
FossilOrigin-Name: 3f657e88767f60d305dd6151e7aa54363341d052
2008-11-07 03:29:33 +00:00
drh 98c58356ae Prevent a rollback from crashing if the sector-size field of the
rollback journal is corrupted. (CVS 5868)

FossilOrigin-Name: cf9d1d933f6b6713018928d9a7680ae63e8edcd0
2008-11-07 00:24:53 +00:00
drh 4c17c3fb11 Add documentation to make it clear that short reads from xRead in the VFS
must be zero-filled. (CVS 5867)

FossilOrigin-Name: fb311d6f4098a08f05b3fac9a2a7e2a53c38bb5f
2008-11-07 00:06:18 +00:00
drh 1735fa8892 Fix a bug in the CAST operator associated with the column cache. (CVS 5866)
FossilOrigin-Name: 1b6a5140446da896f69fddc8d1ea076815bb45e3
2008-11-06 15:33:03 +00:00
drh 0793f1bdb4 Fix memory allocation problems when string length exceeds limits. (CVS 5865)
FossilOrigin-Name: b568e325205acaa2f63bce2d6cc2808edc9f2e01
2008-11-05 17:41:19 +00:00
drh ad4a4b8047 The COMMIT command now works even if there are pending queries, as long
as the pending queries are reading and not writing the database. (CVS 5864)

FossilOrigin-Name: 51f04aaff2803487933b9dfcf39f27a249f18a98
2008-11-05 16:37:34 +00:00
shane 7b607a081f Should be 'memjournal.lo' instead of 'memjournal.o'. Ticket #3480. (CVS 5863)
FossilOrigin-Name: 8b868604217571cf2f60cdf46adb9721ca071bf9
2008-11-04 21:51:03 +00:00
danielk1977 5f6d0268fb Add test cases for sqlite3_db_mutex(). (CVS 5862)
FossilOrigin-Name: f818e8e5cb20c51922d0b5424f17649e0692f273
2008-11-04 14:55:47 +00:00
drh 2838b47234 Enhance documentation of sqlite3_db_mutex(). (CVS 5861)
FossilOrigin-Name: 3aed410ab08557ec92101e5d7c4c90ba50555ddc
2008-11-04 14:48:22 +00:00
drh c46f52034f Avoid a segfault when OOM on a simple EXPLAIN query. Ticket #3478. (CVS 5860)
FossilOrigin-Name: acf26cc0f77b3a308d86f6dc02ecda66a4b12fd0
2008-11-04 14:25:06 +00:00
drh 4413d0e976 Add the sqlite3_db_mutex() interface. No test cases yet. (CVS 5859)
FossilOrigin-Name: d95de32e8ded397adeef8f7a29b87bc85669ac95
2008-11-04 13:46:27 +00:00
drh 3e0a3c9df4 Test cases to verify that COMMIT and ROLLBACK return SQLITE_BUSY when
there are active statements. (CVS 5858)

FossilOrigin-Name: cedfa214e4e979ab04a30f558f767d46862151de
2008-11-03 21:40:00 +00:00
drh dfe88ece74 Change the name of the Cursor object to VdbeCursor. (CVS 5857)
FossilOrigin-Name: fdb98fd8c1706085ebeef8e48ac6737839bed5e5
2008-11-03 20:55:06 +00:00
danielk1977 e435975093 Modify an assert() statement to fix #3473. No other code changes. (CVS 5856)
FossilOrigin-Name: aca6b260c0dd1a1515b70f3567a0653b6bcdeea2
2008-11-03 09:39:45 +00:00
danielk1977 3072c5ea11 Fix a bug reported on the mailing list triggered by the pattern "SELECT <col>, (SELECT ... FROM tbl WHERE rowid > <col>) FROM ...". (CVS 5855)
FossilOrigin-Name: 6c918c4eb9362ebfdbe0486515679102b2862970
2008-11-03 09:06:05 +00:00
shane 2d16fb1d34 Test that single byte corruptions in increasingly larger quantities are handled gracefully. (CVS 5854)
FossilOrigin-Name: c73d915923e393f72e1c0897526a20527db2e03c
2008-10-31 13:57:40 +00:00
danielk1977 10fb749b37 Change the way sqlite3VdbeSetColName() is called so as to remove a few lines of code. This also fixes #3470. (CVS 5853)
FossilOrigin-Name: bfce91429b1dad6e0ca36929e41a7adfb30f8522
2008-10-31 10:53:22 +00:00
drh 1c0dc8256b Fix a faulty assert() in the merge implementation of the UNION operator.
Ticket #3467. (CVS 5852)

FossilOrigin-Name: cd1662e964d9c071a41038676c5a6ef2c990f1ac
2008-10-30 22:13:23 +00:00
danielk1977 f150c9de55 Fix a crash that can follow a malloc failure in sqlite3ValueFromExpr(). Ticket #3468. (CVS 5851)
FossilOrigin-Name: 0996783b1b7e6dda166565071cbd19f23e7edbbc
2008-10-30 17:21:12 +00:00
drh 99dfe5eb47 Add the sqlite3_extended_errcode() interface. Change to return
SQLITE_BUSY instead of SQLITE_ERROR when a COMMIT is attempted and one
or more queries are still pending. (CVS 5850)

FossilOrigin-Name: 4c6a90a16627b1664bf7f15ab40b440b3bd60b48
2008-10-30 15:03:15 +00:00
danielk1977 281d8bd3ac If a hot-journal file is detected but the application does not have the required read/write permissions, return SQLITE_CANTOPEN. Prior to this change, SQLITE_BUSY was returned. Ticket #3457. (CVS 5849)
FossilOrigin-Name: dc5308c7629abe6a3bad21489c8e97087c264e5a
2008-10-29 07:01:56 +00:00
drh d1370b6d92 Remove the vestigial mem4 and mem6 memory allocators. Add the
SQLITE_ZERO_MALLOC compile-time option and the mem0.c module to
handle memory allocation for that case. (CVS 5848)

FossilOrigin-Name: 4651f590f0b8bf13938b2b15d5082136e763af8d
2008-10-28 18:58:20 +00:00
drh 27c3bd7b73 Add data structure description comments to memjournal.c. (CVS 5847)
FossilOrigin-Name: e9c2adbcbf5c28837b06e0fbba93f1764cc3607f
2008-10-28 18:12:36 +00:00
danielk1977 0f3f072d9f Avoid exposing internal interfaces sqlite_attach() and sqlite_detach() as SQL scalar functions. Ticket #3466. (CVS 5846)
FossilOrigin-Name: 679c0b35aaa1ea488a205cc03802e7078a2bcf29
2008-10-28 17:52:39 +00:00
danielk1977 52bd7912af If an SQLITE_DELETE authorization callback returns SQLITE_IGNORE, proceed with the delete operation but disable the truncate optimization. (CVS 5845)
FossilOrigin-Name: 65a2e131732399f0f14f982eb0689482fdb87b6c
2008-10-27 15:34:32 +00:00
danielk1977 c7af484b4b Make sqlite3_count_changes() and total_changes() work with "DELETE FROM <table-name>". (CVS 5844)
FossilOrigin-Name: e68e4282adb9003aa297d033aeb5d9cadee215cd
2008-10-27 13:59:33 +00:00
danielk1977 9a02fb444c Remove some if() conditions that are always true from delete.c. (CVS 5843)
FossilOrigin-Name: 297ad90dd3a69002e6e4175e9e3938b3a627574d
2008-10-27 08:24:38 +00:00
danielk1977 a7435e31ab Remove unused parameter from function rtreeInit() (part of the r-tree extension). (CVS 5842)
FossilOrigin-Name: 3224ea59812d0f3b5685bd92751054b81e3b681e
2008-10-25 17:10:10 +00:00
drh 31daa63f3e Disable the result-set alias cache when on conditional code branches.
Ticket #3461.  The column cache and result set alias cache mechanisms are
prone to this kind of error and need to be refactored.  This check-in should
be considered a temporary fix in advance of a more general redesign of the
whole mechanism. (CVS 5841)

FossilOrigin-Name: 1fa3bbd8220ce073e91935ea362b6f5d5d6d2859
2008-10-25 15:03:20 +00:00
danielk1977 a2f8c24ca3 Add file tkt3461.test with a few examples of bug #3461. Because these tests currently fail they are disabled for now. (CVS 5840)
FossilOrigin-Name: f2cc159159278201809022706c28bc53b6c3c859
2008-10-25 09:34:59 +00:00
danielk1977 f96a3778f9 Fix a bug in pragma table_info. Column default values specified as negative numbers (col DEFAULT -1) were being reported as NULL by the pragma. (CVS 5839)
FossilOrigin-Name: 0e448bc6096c7ee3b21dbd22dc4ca9470ae7ba31
2008-10-23 05:45:07 +00:00
shane b1cd7308dc Updated configure/makefiles to handle SQLITE_ENABLE* compile options. Made sure makefile passes command line options (OPTS=-Dfoo) to the compiler. Add -DSQLITE_COVERAGE_TEST=1 if gcov being used. (CVS 5838)
FossilOrigin-Name: acb106e51f8bb7449a0e214075c559cc66497277
2008-10-22 18:27:31 +00:00
shane 891adeac5c Removed some more dead code and fixed some unresolved externals for WINCE. Ticket #3420. (CVS 5837)
FossilOrigin-Name: 5276e31d42070e7b94bd6050c4fa484dfbfe98ca
2008-10-22 16:55:47 +00:00
shane 049fc21db9 Make sure variable declarations occur first in code blocks. (CVS 5836)
FossilOrigin-Name: b78f44c91fcf3920e69c11a6f72e8f032905a3c7
2008-10-22 16:26:47 +00:00
shane 3ed4e64cd8 Test cases for ticket #3442. (CVS 5835)
FossilOrigin-Name: a8bb5acf708c8f7e52d3f67b85094116386f10fa
2008-10-22 16:04:42 +00:00
danielk1977 d207d8084e Fix an assert() failure that can occur following a malloc() failure. Ticket #3455. (CVS 5834)
FossilOrigin-Name: e0d3aa75b4fa0e706185a3058b5962916e30d066
2008-10-22 10:45:37 +00:00
danielk1977 6553c5c81a Update the autoconf build system to include memjournal.c. (CVS 5833)
FossilOrigin-Name: a3c810f0c80e3e9dfe60a0ffd8688d7c76a30d50
2008-10-21 04:30:31 +00:00
drh 1885d1c201 When a name in double quotes falls back to being a string literal,
make sure it has no affinity.  Ticket #3442. (CVS 5832)

FossilOrigin-Name: 81cfee5c14f241f5ae7f607d73b0b5cb821cda24
2008-10-19 21:03:27 +00:00
danielk1977 39281b4b42 Add the memjournal.c file that should have been with the previous checkin. (CVS 5831)
FossilOrigin-Name: 0509eff0e6b5cdeeb52c12c0574ea63e9715bcb5
2008-10-17 19:13:04 +00:00
danielk1977 b3175389c7 Add "pragma journal_mode=memory". Change the way rollback works for in-memory databases so that it reuses the journal_mode=memory code. (CVS 5830)
FossilOrigin-Name: 39ebf01addf9d0867daafd06a38719e725128f9c
2008-10-17 18:51:52 +00:00
drh 7b228b3e39 Fix a typo in documentation. Ticket #3447. (CVS 5829)
FossilOrigin-Name: 5ce2ddffea807d45318619cc9e259a99dfa14346
2008-10-17 15:10:37 +00:00
danielk1977 d39fa70c79 Fix an error in (5826). (CVS 5828)
FossilOrigin-Name: 8065a92f705dfa04863ba4a828f5bd2803901be8
2008-10-16 13:27:40 +00:00
drh 9e885cd885 Fix a naming problem when SQLITE_MUTEX_NOOP is used. (CVS 5827)
FossilOrigin-Name: 35ce71c6f19953a17aa37abe1c0c97685070e2f6
2008-10-15 19:03:02 +00:00
danielk1977 d138dd8687 Do not open and sync the directory in unixDelete() if the SQLITE_DISABLE_DIRSYNC option is defined. (CVS 5826)
FossilOrigin-Name: 8ef141644edc5182785c6a554222c2ffbe92fef5
2008-10-15 16:02:48 +00:00
drh 3ad92f1b64 Version 3.6.4 (CVS 5825)
FossilOrigin-Name: cd73cffab39d80393f26a20c90aa97cb73d595ea
2008-10-15 11:59:23 +00:00
danielk1977 ab7bee892b After running speed1.test and speed1p.test, reset the size of the lookaside buffer. Otherwise, subsequent runs of malloc5.test may report an error. Changes to test code only. (CVS 5824)
FossilOrigin-Name: 9283478e69d84aa99b2d4636587c8c0b34e7c4da
2008-10-15 11:43:55 +00:00
danielk1977 4bd3ce69ac Disable the page-cache at the end of pcache2.test. (CVS 5823)
FossilOrigin-Name: 3d2d05b6286e2a22a711e02f37748065b3b7f86e
2008-10-14 19:21:51 +00:00
drh 9965a04a63 Fix the amalgamation generator to recognize indented #include directives.
Ticket #3438. (CVS 5822)

FossilOrigin-Name: 494510d8f25c69f5a5f5937b92f505849def6745
2008-10-14 18:21:11 +00:00
drh 72cbd078c3 Fix the xRandomness() method on the unix VFS to return the number of bytes
of randomness obtained. (CVS 5821)

FossilOrigin-Name: b7687e2f2dfa5b0a01ba87ae0bf13684cda50499
2008-10-14 17:58:38 +00:00
drh 7cd30bd3d0 Make sure malloc3.test runs even if a CREATE TABLE transaction commits
prior to the last OOM error. (CVS 5820)

FossilOrigin-Name: 603c40e5b47e4798136af5420a1fa1511791a934
2008-10-14 15:54:08 +00:00
danielk1977 a0042db80f Update main.mk so that a couple of fts3 files are compiled with SQLITE_TEST when building testfixture. (CVS 5819)
FossilOrigin-Name: 8eb315ee5c2a15919171b7d495ac4f1c851b2da9
2008-10-14 14:56:01 +00:00
danielk1977 376687518e Modifications to main.mk so that -DSQLITE_ENABLE_FTS3 works. (CVS 5818)
FossilOrigin-Name: a06d226dee0df0df1aedb9c17353332c6a6e712f
2008-10-14 14:28:35 +00:00
pweilbacher ab88e17ce3 fix a few return codes in the OS/2 VFS (CVS 5817)
FossilOrigin-Name: 4e978a40f7ee93b09093e82173edc74a992aadeb
2008-10-13 21:46:46 +00:00
drh 104d74c752 Get the load extension tests working on amd64. Needed for test coverage. (CVS 5816)
FossilOrigin-Name: 119b69fba0c27c4c479749360176b6eb69d2e70f
2008-10-13 17:09:11 +00:00
drh 21717ed6f0 Fix the SQLITE_OMIT_DATETIME_FUNCS compile-time option so that it builds
successfully. (CVS 5815)

FossilOrigin-Name: c3f91645159511250c9f86c2a97d819f0253d182
2008-10-13 15:35:08 +00:00
drh 1554262148 In rollback.test, do not check for journal deletion if the journal mode
is not DELETE.  Call show_memstats after each test module in all.test
and quick.test. (CVS 5814)

FossilOrigin-Name: df2c28dc7310510bada292a2e8c1be073803858c
2008-10-13 14:16:11 +00:00
danielk1977 30629571f6 Use one less temporary table in genfkey.c. The retired table was being used to workaround the bug fixed by (5812). (CVS 5813)
FossilOrigin-Name: 73efca985a05930df761b42886a3ba1c5199f32a
2008-10-13 10:56:48 +00:00
danielk1977 d0ffa1e815 If sqlite3_column_value() is called to obtain a value with the MEM_Static flag set, clear it and set the MEM_Ephem flag before returning. Otherwise, if the value is passed to sqlite3_bind_value() or sqlite3_result_value(), sqlite may attempt to use the buffer after the statement has been finalized. This is not always valid, as MEM_Static only guarantees that a MEM.z buffer will be valid for the lifetime of the owner statement, not that it is actually a static buffer. (CVS 5812)
FossilOrigin-Name: b055bfc4e5268d8a66d6a4f5e8aec1285fe4b8e7
2008-10-13 10:37:49 +00:00
shane a3465f2d78 Check for failures in winTruncate. Ticket #3415. (CVS 5811)
FossilOrigin-Name: 500c50561fba88948aad21d1aef1e1e96ab8c3aa
2008-10-12 02:27:38 +00:00
shane e5447f5c1c Added -DSQLITE_ENABLE_RTREE=1 to the mkdll.sh script. Ticket #3427. (CVS 5810)
FossilOrigin-Name: 66f57ecb1626f3c5292070c1b9a9c1a9a9164d4f
2008-10-12 02:03:37 +00:00
shane b0650c26a5 Add gcov compile options to link line when GCOV option enabled. (CVS 5809)
FossilOrigin-Name: 3ddda111867f64d9dfd729c50c4d0555cac1499d
2008-10-12 01:49:41 +00:00
shane eec556d3b7 Added SQLITE_OMIT_DEPRECATED compile time option to leave out deprecated functions. Updated test scripts to skip tests of deprecated functions if they are compiled out. (CVS 5808)
FossilOrigin-Name: ba3711acee6f4659bbf133a23d8f9f37e14d0f38
2008-10-12 00:27:53 +00:00
drh 189077f376 Add macros tests so that the compiler always recognizes that x86_64 is little endian. (CVS 5807)
FossilOrigin-Name: b201e7093c7c47b23b0f17a0890a344f3792d6d3
2008-10-11 18:11:21 +00:00
danielk1977 9ff3f3f772 When transfering an error message from a statement handle to the database handle so that it can be accessed by sqlite3_errmsg(), a malloc may fail. If this malloc fails, it is considered benign. (CVS 5806)
FossilOrigin-Name: 311003aff85e6b6c47e854d33f46eee31da6f30c
2008-10-11 17:51:38 +00:00
drh 419fcf66db Conditionally omit prototypes in pcache.h when the corresponding routines
are not used.  Ticket #3430. (CVS 5805)

FossilOrigin-Name: 977ae12c365846e1bc582fd17146151953b5ed68
2008-10-11 17:42:28 +00:00
drh ddecae7995 Fix to sqlite3DbMallocRaw() when SQLITE_OMIT_LOOKASIDE is defined so that
once it fails it continues to fail.  Add a comment explaining why this is
important. (CVS 5804)

FossilOrigin-Name: 63dd8be70d333c56171dfd254406abb1af685b0f
2008-10-11 17:35:16 +00:00
drh 8867e38aab Fix a OOM segfault in the BETWEEN operator parsing - discovered while
using SQLITE_OMIT_LOOKASIDE. Add SQLITE_OMIT_LOOKASIDE to test_config.c and
bypass lookaside.test when defined. (CVS 5803)

FossilOrigin-Name: 2a21d52c651ba113c472b6686dcf8ba009924305
2008-10-11 17:06:04 +00:00
danielk1977 435f29d6eb Add "nolookaside" case to permutations.test. (CVS 5802)
FossilOrigin-Name: 56fb7a22864774fcbd8cd00195359dc0f223ec8b
2008-10-11 17:04:04 +00:00
drh 10fe840e4d Fix a memory leak on ORDER BY of a compound select caused by the resolver
on a flattened query.  Also fix a OOM segfault in WHERE clause processing. (CVS 5801)

FossilOrigin-Name: d2c252d6bbde4ae14da6c9e6c2683d763d11c59f
2008-10-11 16:47:35 +00:00
drh 4150ebf86f Added an assert() to detect lookaside memory leaks. Also added the
SQLITE_OMIT_LOOKASIDE compile-time option which is useful in trying to
track down lookaside memory leaks. (CVS 5800)

FossilOrigin-Name: 0c4c66071a46cecc5f87afb8f8f01ae2c90ee9b3
2008-10-11 15:38:29 +00:00
drh 99655beecf Fix an assertion fault that occurs with SQLITE_THREADSAFE=0. (CVS 5799)
FossilOrigin-Name: 28bba42b338afd63e1dad9f431d631f6f3027275
2008-10-11 15:20:04 +00:00
drh f8cecdab84 Add the SQLITE_OMIT_TRUNCATE_OPTIMIZATION option. Other unrelated
documentation enhancements. (CVS 5798)

FossilOrigin-Name: fab4940d54fd1e5459a3d0d9b64b491e6972fd8d
2008-10-10 23:48:25 +00:00
shane 49ffdbf47e Further simplifications of the code for the LIMIT clause on an UPDATE or DELETE. Added a few test cases to wherelimit.test. (CVS 5797)
FossilOrigin-Name: 282c6a46b25f4e4278fd4c8b0b1cde1de28d8f51
2008-10-10 18:25:45 +00:00
danielk1977 c30bfeee4e Add the genfkey program to the tool/ directory. (CVS 5796)
FossilOrigin-Name: 84e73fe8a6f538c4b1bb4f641a661d6fafb60c76
2008-10-10 17:58:26 +00:00
danielk1977 50af3e1d2d Change 'pragma foreign_key_list' to return some extra information. (CVS 5795)
FossilOrigin-Name: 3bb33cf59da49f13201c0226e964cda067a4e780
2008-10-10 17:47:21 +00:00
drh 1b67f3caf2 Simplify the symbol hash table to use only a single key class. Other
changes to improve code coverage. (CVS 5794)

FossilOrigin-Name: ff50a8a7e5a15fac192939ff3206fa18d1c5a6dd
2008-10-10 17:41:28 +00:00
drh adfae6c68b Documentation updates. No changes to code. (CVS 5793)
FossilOrigin-Name: 07b5f70317a0b2d32df86a01bdeec79ead00f68c
2008-10-10 17:26:35 +00:00
drh 931577f1cc Simplify the parser reduction code for the LIMIT clause on an UPDATE or
DELETE. (CVS 5792)

FossilOrigin-Name: 3de179630e812396ec29e77f7a06758472d0802f
2008-10-10 14:27:16 +00:00
shane b235db9c7b Re-factored memory allocation failure handling in the sqlite3LimitWhere() function based on failures in the mallocJ.test script. (CVS 5791)
FossilOrigin-Name: 43507bbefbf79e8db8fe31319ad621d48247983f
2008-10-10 13:35:57 +00:00
shane 468327f16a Added mallocJ.test to test allocation failure handling of the new LIMIT/OFFSET support for UPDATE/DELETE. (CVS 5790)
FossilOrigin-Name: 5375b348b12a4ae149472c84d6f05a78a5542a21
2008-10-10 13:34:29 +00:00
shane 8a7389f276 Initial test cases for the new LIMIT/OFFSET support for DELETE/UPDATE. (CVS 5789)
FossilOrigin-Name: d9f5e15ca00d4d54dc395926e4c9171f1d24982a
2008-10-10 06:01:59 +00:00
shane 273f619b58 Updated LIMIT support for DELETE/UPDATE. Omit option changed to SQLITE_ENABLE_UPDATE_DELETE_LIMIT. (CVS 5788)
FossilOrigin-Name: c10e8a3c7ab7f21c95f24d0aba590f5b18a4b028
2008-10-10 04:34:16 +00:00
danielk1977 510f96590b Fix an assert() failure that can occur if the user attempts to set an into an integer primary key column to a text value in a table that has a BEFORE UPDATE trigger. (CVS 5787)
FossilOrigin-Name: c2cf9d60d6626844193b008a37e4417aa0a0f323
2008-10-09 18:48:30 +00:00
drh 5eddafeb64 New speed testing tools. (CVS 5786)
FossilOrigin-Name: 2d427746d53104ca032c404f7f65c51b41b7a20e
2008-10-09 17:57:33 +00:00
drh da81eab599 Add a test to verify the sqlite3_column_name() interface returns the
correct value when the query is of the form: "SELECT rowid,* FROM...".
Ticket #3429. (CVS 5785)

FossilOrigin-Name: e90d5a5515f7096e247e6059cf77f8089ed90b2c
2008-10-09 15:56:45 +00:00
drh 9583d53e8f Update the version number to 3.6.4. (CVS 5784)
FossilOrigin-Name: 4b973ac98d027cc1097fa9845eb4a8489b633ea4
2008-10-09 15:56:06 +00:00
drh 073e7b1ca3 Minor cleanup of the new "status" command on the TCL bindings. (CVS 5783)
FossilOrigin-Name: ec01bd72ee875df179c680c1a40304d2f807fe38
2008-10-09 14:45:25 +00:00
danielk1977 be51a65dbc After an OP_NullRow is executed on a cursor, cause any subsequent OP_Next or OP_Prev to behave as if there were no more rows to traverse. Ticket #3424. (CVS 5782)
FossilOrigin-Name: af679f6170b346fe61df7dae963b2a2853e62a62
2008-10-08 17:58:48 +00:00
drh d1d384888b Add the experimental sqlite3_stmt_status() interface. (CVS 5781)
FossilOrigin-Name: de473efb35ffdf9a8222a70a84dfd7d3198c87c1
2008-10-07 23:46:38 +00:00
drh e82f5d04c3 Raise the hard upper bound on SQLITE_MAX_FUNCTION_ARG to 1000 from 100.
The default upper bound is still 100, but it can now be raised as high
as 1000 at compile-time. (CVS 5780)

FossilOrigin-Name: 79df72ee836db91647913055ba6cf55558679b01
2008-10-07 19:53:14 +00:00
drh 18472fa7b8 Remove the SQLITE_MUTEX_APPDEF compile-time option. The SQLITE_THREADSAFE=0
option always removes all mutex code.  For application-defined mutexes only,
use SQLITE_THREADSAFE=1 with SQLITE_MUTEX_NOOP=1.  Ticket #3421. (CVS 5779)

FossilOrigin-Name: 02a12eb1cfe9307c66556105a1a99d657cc01ab5
2008-10-07 15:25:48 +00:00
danielk1977 3d9cf5177f Fix a recently introduced test script bug causing rollback.test to throw an exception when run using the "onefile" variation. (CVS 5778)
FossilOrigin-Name: 7d55ec374d62c6d3d588949b96e194920083fe4e
2008-10-07 15:00:08 +00:00
danielk1977 0bfbaa8aa5 Have sqlite3_bind_value() call sqlite3ApiExit() before returning. Otherwise the db->mallocFailed flag may not be cleared. (CVS 5777)
FossilOrigin-Name: 6b7c8d56403f6b9b88b8494c86f3d62e487cb2ac
2008-10-07 14:06:11 +00:00
drh f65c76d49c Do not use double unnecessarily in date+time functions. Ticket #3422. (CVS 5776)
FossilOrigin-Name: b03231323a7f06c736c38ae3c5535d2fd025583f
2008-10-07 12:32:13 +00:00
danielk1977 c56774e234 Fix a problem with hot-journal rollback. SQLITE_CANTOPEN was being returned if the hot-journal file contained a pointer to a master journal file that did not exist. (CVS 5775)
FossilOrigin-Name: 22d1feb9b20b8fd9c86066b94e4220cf8929b043
2008-10-07 11:51:20 +00:00
shane 4281bd4204 Initial support for LIMIT clause on DELETEs and UPDATEs. Changes likely with more testing. The code can be omitted with the define SQLITE_OMIT_UPDATE_DELETE_LIMIT. (CVS 5774)
FossilOrigin-Name: 9c8b132e34bc6024bc9898182f8f93127ca52ac9
2008-10-07 05:27:11 +00:00
shane 359a8f80f1 Removed redundant assert(). (CVS 5773)
FossilOrigin-Name: 486b1124f76bcf0505b6be908f2a3e988ad6e05d
2008-10-07 01:18:59 +00:00
danielk1977 b1c685b0c8 Allow INDEXED BY and NOT INDEXED to be used in UPDATE and DELETE statements. (CVS 5772)
FossilOrigin-Name: 83a7e446b2d4846a6f92bd831a2adaa265f5a786
2008-10-06 16:18:39 +00:00
drh 6ef7f85801 Add a test script to verify that ticket #3419 stays fixed. (CVS 5771)
FossilOrigin-Name: c3cf54a1b6bbaaeab4cab701c6cbbed02695facc
2008-10-06 15:31:13 +00:00
drh 3d1c1e8722 Fix a typo in check-in (5769) (CVS 5770)
FossilOrigin-Name: 24891902fa625445aa47ae930f0cb340cc73d25d
2008-10-06 15:18:02 +00:00
drh 41204f1fdd Expression nodes of type TK_ROW mean the rowid of the first table in the
source list. (CVS 5769)

FossilOrigin-Name: 2f7db6c98f17e0b7110258093c283091a91d4e4f
2008-10-06 13:54:35 +00:00
drh 488e7b6323 In sqlite3_bind() interfaces, avoid acquiring the mutex until after the
statement handle has been validated.  Ticket #3418. (CVS 5768)

FossilOrigin-Name: 693503e241001271512f4ce3e8cc932ba6a3106c
2008-10-06 12:46:43 +00:00
danielk1977 de89c4cc17 Add a test to indexedby.test to check that automatic indexes (sqlite_autoindex_xxx) can be used with the INDEXED BY syntax. (CVS 5767)
FossilOrigin-Name: bb51c34506b3353506b6f3566fbe2a10d02e8ebc
2008-10-06 11:29:49 +00:00
danielk1977 85574e31cb Allow INDEXED BY and NOT INDEXED clauses in SELECT statements. (CVS 5766)
FossilOrigin-Name: 98ca5580f5acd2e7b3ce512520ec0527f221505e
2008-10-06 05:32:18 +00:00
danielk1977 98c408289c Modifications to bind.test to account for different values of SQLITE_MAX_VARIABLE_NUMBER. Ticket #3409. (CVS 5765)
FossilOrigin-Name: 1a91f3fd58608e258b60305d1d18c3d07d2e9c46
2008-10-03 09:10:45 +00:00
danielk1977 740ed546fc Change one of the test cases in incrblob2.test to avoid allocating a 10MB block of heap memory. (CVS 5764)
FossilOrigin-Name: 83b7dd737a16555b9eb4ad9faacac3d705b0a90e
2008-10-03 08:44:54 +00:00
danielk1977 4e7f36a27f Change to reduce the number of OP_Null opcodes in "WHERE <rowid> IN (x,y,z)" queries. (CVS 5763)
FossilOrigin-Name: 33b59a3db0b1797663ae840ceaca1b23a9a9e3b0
2008-10-02 16:42:06 +00:00
danielk1977 a8b3018da4 Fix for sqlite3_blob_write(): If either 3rd or 4th argument is less than zero, return SQLITE_ERROR. H17879. (CVS 5762)
FossilOrigin-Name: f6074c0b9b5ba51d131509dba2aec80d0fcf3b7e
2008-10-02 14:49:01 +00:00
drh 25ef8f1c2c Fix a typo that prevents the sqlite3_sql() interface from appearing
in the official documentation. (CVS 5761)

FossilOrigin-Name: b46814b202f4cc355b925551c90ea811f3f9e44a
2008-10-02 14:33:56 +00:00
danielk1977 41a05b7bee Optimize queries that contain "WHERE rowid IN (x, y, z...)" by using an intkey btree to store the (x, y, z...) set instead of an index btree. (CVS 5760)
FossilOrigin-Name: 803a1736d56b3c07b8ad38715fe0e39196ecc507
2008-10-02 13:50:55 +00:00
drh 0368072905 Adjust the memory usage bounds on the memsubsys1.test script so that
it works on amd64. (CVS 5759)

FossilOrigin-Name: aabde23fe19bd95371fdebdde66ac553dfd53f8e
2008-10-01 13:55:50 +00:00
danielk1977 2d60549926 Fix a bug in where.c where a non-temp register was being incorrectly deallocated. Ticket #3408. (CVS 5758)
FossilOrigin-Name: 59d2e89e2181c26b18eac68ccc80ea3018f70a5e
2008-10-01 08:43:03 +00:00
drh f94a173a95 Add some testcase() and assert() macros to btree.c to aid with testing
recent changes. (CVS 5757)

FossilOrigin-Name: fb461b78dfc2501fafa8bce03da5487fdfdff959
2008-09-30 17:18:17 +00:00
danielk1977 a69fda25ff Fix a comment in btree.c. No code changes. (CVS 5756)
FossilOrigin-Name: 0f3c56330b43fb7c9dc43a444ca38bace9397ede
2008-09-30 16:48:10 +00:00
drh 7b682804c7 Change leading tabs into spaces. (CVS 5755)
FossilOrigin-Name: 4e536463c1aa9991de85c7efc826c28896ca61d3
2008-09-30 14:06:28 +00:00
danielk1977 2f78fc66b5 Fix a recently introduced problem with deleting entries from index tables. (CVS 5754)
FossilOrigin-Name: 83c064cae481ca95b7107e22e98fc599fe85a2da
2008-09-30 09:31:45 +00:00
shane d94b0556f8 Misc clean up. Wrapped a CE only variable in if-defs. Changed to only provide cache hint for CE builds (as this prevents CE from compressing the file.) Performance testing on XP and Vista showed caching hint had little effect when the DB size was much smaller than the O/S disk cache size, and provided only marginal benefit when the DB size was much larger than the cache. On Vista, overall system performance was hurt for very large DBs. Ticket #3387. (CVS 5753)
FossilOrigin-Name: 15dd0169a4c5e2ff9e3894eec10799cb89d462e5
2008-09-30 04:20:07 +00:00
drh 798fadd14c A few minor changes to test scripts so that they work on linux-amd64. (CVS 5752)
FossilOrigin-Name: 78d075ff38d96cc58659a7097dec0e49402aa960
2008-09-30 00:31:38 +00:00
danielk1977 00a696d6d1 Remove the reparentPage() and reparentChildPages() functions from btree.c. All calls to these functions can now be replaced by a call to setChildPtrmaps(). (CVS 5751)
FossilOrigin-Name: 35e8e4dcd24b050b535ae005ca3b25e6a673eb89
2008-09-29 16:41:31 +00:00
danielk1977 bf93c56737 Remove the MemPage.idxShift variable. It is no longer required. (CVS 5750)
FossilOrigin-Name: 7354abd03be756b1d7d0a3d5b8958f5c0c985ff5
2008-09-29 15:53:25 +00:00
danielk1977 47dd228e60 Do not run vacuum.test as part of the "exclusive" permutation test. (CVS 5749)
FossilOrigin-Name: 2fb15ae9e9af716a5684a21826814bc4c332a596
2008-09-29 14:27:41 +00:00
danielk1977 7aad2983c9 Update shared_err.test to work with (5668) (return SQLITE_CORRUPT if rollback fails). (CVS 5748)
FossilOrigin-Name: 292acaf7c4e68b532cc8d1763e02aa79d90ea20c
2008-09-29 14:12:56 +00:00
danielk1977 71d5d2cd49 Instead of storing a pointer to the parent page in the MemPage structure, have each B-Tree cursor keep track of the ancestry of the current page. (CVS 5747)
FossilOrigin-Name: 40425e93421286cca1965d7a5769084526210c7a
2008-09-29 11:49:47 +00:00
vapier d0507d691e fix #3077: use full version in pkg-config files (CVS 5746)
FossilOrigin-Name: efe095e0cb8e0f8a11fd9cc321ec83b556458bf2
2008-09-29 00:11:22 +00:00
drh 04335886a1 Add the "truncate" journal mode which commits transactions by truncating the
rollback journal file to zero length and not calling fsync(). (CVS 5745)

FossilOrigin-Name: 7c561f2e9264de676c1028943f6c3d06542fd802
2008-09-26 21:08:08 +00:00
drh 9e2d64b8d3 Make sure the queueMutex is held prior to writing the pQueueLast field
of the write queue in the async demonstration code.  Ticket #3405. (CVS 5744)

FossilOrigin-Name: 5622a1e285fc4d5720f7180a0eb551952f2df331
2008-09-26 20:02:50 +00:00
danielk1977 d326064e0d Performance enhancement: avoid calling reparentChildPages() from balance_nonroot(). (CVS 5743)
FossilOrigin-Name: 28fd0a50ca8529892f5b1ababd38d494889eed6d
2008-09-26 17:31:55 +00:00
danielk1977 e5dd389698 On windows, avoid running those tests in exclusive.test that require the journal file to be externally accessed while SQLite is holding it open. This doesn't work on windows. (CVS 5742)
FossilOrigin-Name: 5debf12fa46520946ac5da44c03448fffbc9940c
2008-09-24 14:03:43 +00:00
danielk1977 f9449d0e9c Add file fts3_icu.c to the amalgamation. Because of the way header files are included into sqlite3.c, fts3_icu.c has to appear after all the other fts3 and icu extension files. Ticket #3398. (CVS 5741)
FossilOrigin-Name: 0acca5842f83943228d4225b60dc7e8a42bae577
2008-09-24 09:58:00 +00:00
danielk1977 0afae93fa4 Fix some function declarations (change "int foo()" to "int foo(void)"). Ticket #3399. (CVS 5740)
FossilOrigin-Name: 0fb98c35353d8c0a8d669bbe45fe84e3a5060621
2008-09-24 09:12:46 +00:00
danielk1977 45e60aabc6 Catch another case where SQLITE_IOERR could be returned instead of SQLITE_NOMEM following an out-of-memory error. (CVS 5739)
FossilOrigin-Name: 18d030da0c1755aab458e5aa0d3ad0a714706d67
2008-09-23 17:39:26 +00:00
danielk1977 98c21903bd Always transform error code SQLITE_IOERR_NOMEM to SQLITE_NOMEM before returning. This was already happening in most places. (CVS 5738)
FossilOrigin-Name: 046ef07261d520c9399bd8cdfdfd5281956b7a27
2008-09-23 16:41:29 +00:00
drh 40bbb0a3e8 Enable the LOCKING_STYLE extensions by default on a Mac. Leave them
disabled on all other posix platforms. (CVS 5737)

FossilOrigin-Name: bae1d5b16948705b7dec7b139e3586b4b510cbfa
2008-09-23 10:23:26 +00:00
drh c21658beaa Remove an unused variable from the test logic. (CVS 5736)
FossilOrigin-Name: 309ba380d985d77419a6e185373493e043823258
2008-09-23 10:16:04 +00:00
drh 3e59c01255 Fix the TCL installer so that it omits the release number. Ticket #3396.
Use strcmp() instead of sqlite3StrICmp() in the "copy" method of the SQLite
object in the TCL interface. (CVS 5735)

FossilOrigin-Name: a88606245760eaf8054d67773db7d8b795e8ca25
2008-09-23 10:12:13 +00:00
drh e2c3a659a9 Add no-op Unload entry points to the TCL interface. Ticket #3397. (CVS 5734)
FossilOrigin-Name: b31dd1e3f1d927b9236b7ebeb331268cbd253083
2008-09-23 09:58:46 +00:00
drh 9606781667 Fix for ticket #3382 was mistakenly removed by (5712). Add an assert to
prevent it from being removed again. (CVS 5733)

FossilOrigin-Name: 01d26b3df7029f7fa09231c18a7b9f9a1a967916
2008-09-23 09:36:10 +00:00
drh 4d6618f9ed Get rid of all of the compiler magic associated with SQLITE_EXPERIMENTAL
and SQLITE_DEPRECATED.  It was causing more problems than it was solving.
Ticket #3395 et al. (CVS 5732)

FossilOrigin-Name: bc040073c7c059e91fddece27f99fa359cc1405d
2008-09-22 17:54:46 +00:00
danielk1977 77eb5bb6f7 Fix a memory leak that can follow a malloc failure in sqlite3_initialize. (CVS 5731)
FossilOrigin-Name: 118dc0ba082dd9abba5602dafc86bd56e756db86
2008-09-22 17:22:19 +00:00
danielk1977 cd3b3c8902 Add instrumentation to os_unix.c to test that a return value of SQLITE_FULL from an xSync() callback is handled correctly. (CVS 5730)
FossilOrigin-Name: 7bd2da93c6cce52edbbe53fe26a82ad159dd6b6b
2008-09-22 11:46:32 +00:00
172 changed files with 11283 additions and 4991 deletions
+34 -19
View File
@@ -76,13 +76,17 @@ TLIBS = @LIBS@
TEMP_STORE = -DSQLITE_TEMP_STORE=@TEMP_STORE@
# Enable/disable loadable extensions, and other optional features
# based on configuration. (-DSQLITE_OMIT*). The same set of OMIT
# flags should be passed to the LEMON parser generator and the
# mkkeywordhash tool as well.
# based on configuration. (-DSQLITE_OMIT*, -DSQLITE_ENABLE*).
# The same set of OMIT and ENABLE flags should be passed to the
# LEMON parser generator and the mkkeywordhash tool as well.
OPT_FEATURE_FLAGS = @OPT_FEATURE_FLAGS@
TCC += $(OPT_FEATURE_FLAGS)
# Add in any optional parameters specified on the make commane line
# ie. make "OPTS=-DSQLITE_ENABLE_FOO=1 -DSQLITE_OMIT_FOO=1".
TCC += $(OPTS)
# Version numbers and release number for the SQLite being compiled.
#
VERSION = @VERSION@
@@ -121,7 +125,7 @@ SHLIB_SUFFIX = @TCL_SHLIB_SUFFIX@
#
# for more info.
#
GCOV_CFLAGS1 = -fprofile-arcs -ftest-coverage
GCOV_CFLAGS1 = -DSQLITE_COVERAGE_TEST=1 -fprofile-arcs -ftest-coverage
GCOV_LDFLAGS1 = -lgcov
USE_GCOV = @USE_GCOV@
LTCOMPILE_EXTRAS += $(GCOV_CFLAGS$(USE_GCOV))
@@ -144,7 +148,7 @@ ALLOWRELEASE = @ALLOWRELEASE@
# libtool compile/link/install
LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(TCC) $(LTCOMPILE_EXTRAS)
LTLINK = $(LIBTOOL) --mode=link $(TCC) @LDFLAGS@ $(LTLINK_EXTRAS)
LTLINK = $(LIBTOOL) --mode=link $(TCC) $(LTCOMPILE_EXTRAS) @LDFLAGS@ $(LTLINK_EXTRAS)
LTINSTALL = $(LIBTOOL) --mode=install $(INSTALL)
# nawk compatible awk.
@@ -159,11 +163,12 @@ OBJS0 = alter.lo analyze.lo attach.lo auth.lo bitvec.lo btmutex.lo \
btree.lo build.lo callback.lo complete.lo date.lo \
delete.lo expr.lo fault.lo func.lo global.lo \
hash.lo journal.lo insert.lo legacy.lo loadext.lo \
main.lo malloc.lo mem1.lo mem2.lo mem3.lo mem4.lo mem5.lo mem6.lo \
mutex.lo mutex_os2.lo mutex_unix.lo mutex_w32.lo \
main.lo malloc.lo mem0.lo mem1.lo mem2.lo mem3.lo mem5.lo \
memjournal.lo \
mutex.lo mutex_noop.lo mutex_os2.lo mutex_unix.lo mutex_w32.lo \
opcodes.lo os.lo os_unix.lo os_win.lo os_os2.lo \
pager.lo parse.lo pcache.lo pragma.lo prepare.lo printf.lo random.lo \
resolve.lo select.lo status.lo \
pager.lo parse.lo pcache.lo pcache1.lo pragma.lo prepare.lo printf.lo \
random.lo resolve.lo select.lo status.lo \
table.lo tokenize.lo trigger.lo update.lo \
util.lo vacuum.lo \
vdbe.lo vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbefifo.lo vdbemem.lo \
@@ -209,14 +214,15 @@ SRC = \
$(TOP)/src/loadext.c \
$(TOP)/src/main.c \
$(TOP)/src/malloc.c \
$(TOP)/src/mem0.c \
$(TOP)/src/mem1.c \
$(TOP)/src/mem2.c \
$(TOP)/src/mem3.c \
$(TOP)/src/mem4.c \
$(TOP)/src/mem5.c \
$(TOP)/src/mem6.c \
$(TOP)/src/memjournal.c \
$(TOP)/src/mutex.c \
$(TOP)/src/mutex.h \
$(TOP)/src/mutex_noop.c \
$(TOP)/src/mutex_os2.c \
$(TOP)/src/mutex_unix.c \
$(TOP)/src/mutex_w32.c \
@@ -231,6 +237,7 @@ SRC = \
$(TOP)/src/parse.y \
$(TOP)/src/pcache.c \
$(TOP)/src/pcache.h \
$(TOP)/src/pcache1.c \
$(TOP)/src/pragma.c \
$(TOP)/src/prepare.c \
$(TOP)/src/printf.c \
@@ -329,6 +336,7 @@ TESTSRC2 = \
$(TOP)/src/os_win.c \
$(TOP)/src/pager.c \
$(TOP)/src/pcache.c \
$(TOP)/src/pcache1.c \
$(TOP)/src/pragma.c \
$(TOP)/src/prepare.c \
$(TOP)/src/printf.c \
@@ -368,6 +376,7 @@ TESTSRC = \
$(TOP)/src/test_mutex.c \
$(TOP)/src/test_onefile.c \
$(TOP)/src/test_osinst.c \
$(TOP)/src/test_pcache.c \
$(TOP)/src/test_schema.c \
$(TOP)/src/test_server.c \
$(TOP)/src/test_tclvar.c \
@@ -551,6 +560,9 @@ main.lo: $(TOP)/src/main.c $(HDR)
malloc.lo: $(TOP)/src/malloc.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/malloc.c
mem0.lo: $(TOP)/src/mem0.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem0.c
mem1.lo: $(TOP)/src/mem1.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem1.c
@@ -560,18 +572,18 @@ mem2.lo: $(TOP)/src/mem2.c $(HDR)
mem3.lo: $(TOP)/src/mem3.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem3.c
mem4.lo: $(TOP)/src/mem4.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem4.c
mem5.lo: $(TOP)/src/mem5.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem5.c
mem6.lo: $(TOP)/src/mem6.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem6.c
memjournal.lo: $(TOP)/src/memjournal.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/memjournal.c
mutex.lo: $(TOP)/src/mutex.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mutex.c
mutex_noop.lo: $(TOP)/src/mutex_noop.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mutex_noop.c
mutex_os2.lo: $(TOP)/src/mutex_os2.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mutex_os2.c
@@ -587,6 +599,9 @@ pager.lo: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
pcache.lo: $(TOP)/src/pcache.c $(HDR) $(TOP)/src/pcache.h
$(LTCOMPILE) -c $(TOP)/src/pcache.c
pcache1.lo: $(TOP)/src/pcache1.c $(HDR) $(TOP)/src/pcache.h
$(LTCOMPILE) -c $(TOP)/src/pcache1.c
opcodes.lo: opcodes.c
$(LTCOMPILE) -c opcodes.c
@@ -615,7 +630,7 @@ parse.h: parse.c
parse.c: $(TOP)/src/parse.y lemon$(BEXE) $(TOP)/addopcodes.awk
cp $(TOP)/src/parse.y .
./lemon$(BEXE) $(OPTS) $(OPT_FEATURE_FLAGS) parse.y
./lemon$(BEXE) $(OPT_FEATURE_FLAGS) $(OPTS) parse.y
mv parse.h parse.h.temp
$(NAWK) -f $(TOP)/addopcodes.awk parse.h.temp >parse.h
@@ -654,7 +669,7 @@ tokenize.lo: $(TOP)/src/tokenize.c keywordhash.h $(HDR)
$(LTCOMPILE) -c $(TOP)/src/tokenize.c
keywordhash.h: $(TOP)/tool/mkkeywordhash.c
$(BCC) -o mkkeywordhash$(BEXE) $(OPTS) $(OPT_FEATURE_FLAGS) $(TOP)/tool/mkkeywordhash.c
$(BCC) -o mkkeywordhash$(BEXE) $(OPT_FEATURE_FLAGS) $(OPTS) $(TOP)/tool/mkkeywordhash.c
./mkkeywordhash$(BEXE) >keywordhash.h
trigger.lo: $(TOP)/src/trigger.c $(HDR)
@@ -747,7 +762,7 @@ install: sqlite3$(BEXE) libsqlite3.la sqlite3.h ${HAVE_TCL:1=tcl_install}
$(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(pkgconfigdir)
tcl_install: libtclsqlite3.la
$(TCLSH_CMD) $(TOP)/tclinstaller.tcl $(VERSION)
$(TCLSH_CMD) $(TOP)/tclinstaller.tcl $(RELEASE)
clean:
rm -f *.lo *.la *.o sqlite3$(TEXE) libsqlite3.la
+635
View File
@@ -0,0 +1,635 @@
#!/usr/make
#
# Makefile for SQLITE on VxWorks
ifeq ($(FORCPU),)
FORCPU = SH32gnule
endif
TOOL_FAMILY = gnu
include $(WIND_USR)/tool/gnu/make.$(FORCPU)
#### The toplevel directory of the source tree. This is the directory
# that contains this "Makefile.in" and the "configure.in" script.
#
TOP = ../sqlite-3.6.5
#### C Compiler and options for use in building executables that
# will run on the platform that is doing the build.
#
BCC = gcc -g -O2
#BCC = /opt/ancic/bin/c89 -0
#### If the target operating system supports the "usleep()" system
# call, then define the HAVE_USLEEP macro for all C modules.
#
USLEEP =
#USLEEP = -DHAVE_USLEEP=1
#### If you want the SQLite library to be safe for use within a
# multi-threaded program, then define the following macro
# appropriately:
#
THREADSAFE = -DSQLITE_THREADSAFE=1
#THREADSAFE = -DSQLITE_THREADSAFE=0
#### Specify any extra linker options needed to make the library
# thread safe
#
#THREADLIB = -lpthread
THREADLIB =
#### Specify any extra libraries needed to access required functions.
#
#TLIBS = -lrt # fdatasync on Solaris 8
#for x86 vxWorks
#TLIBS += TLIBS = $(LD_LINK_PATH_ATEND) $(LD_PARTIAL_LAST_FLAGS)
#for SH4 shared library
TLIBS_SHARED += -L$(WIND_USR)/lib/sh/SH32/commonle/PIC
#TLIBS_SHARED += $(LD_LINK_PATH_ATEND) $(LD_PARTIAL_LAST_FLAGS)
#for SH4 static
TLIBS += $(LD_LINK_PATH_ATEND) $(LD_PARTIAL_LAST_FLAGS)
#### Leave SQLITE_DEBUG undefined for maximum speed. Use SQLITE_DEBUG=1
# to check for memory leaks. Use SQLITE_DEBUG=2 to print a log of all
# malloc()s and free()s in order to track down memory leaks.
#
# SQLite uses some expensive assert() statements in the inner loop.
# You can make the library go almost twice as fast if you compile
# with -DNDEBUG=1
#
#OPTS = -DSQLITE_DEBUG=2
#OPTS = -DSQLITE_DEBUG=1
#OPTS =
OPTS = -DNDEBUG=1 -DSQLITE_OS_UNIX=1 $(THREADSAFE)
OPTS += -DSQLITE_OMIT_LOAD_EXTENSION=1
OPTS += -DSQLITE_ENABLE_LOCKING_STYLE=1
OPTS += -DSQLITE_THREAD_OVERRIDE_LOCK=0
OPTS += -DSQLITE_ENABLE_COLUMN_METADATA=1
OPTS += -DHAVE_FDATASYNC=1
#### The suffix to add to executable files. ".exe" for windows.
# Nothing for unix.
#
EXE = .vxe
#EXE =
#### C Compile and options for use in building executables that
# will run on the target platform. This is usually the same
# as BCC, unless you are cross-compiling.
#
#TCC = gcc -O6
#TCC = gcc -g -O0 -Wall
#TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage
#TCC = /opt/mingw/bin/i386-mingw32-gcc -O6
TCC = $(CC) $(DEFINE_CC) -O2 -g -mrtp $(CC_ARCH_SPEC) -D_REENTRANT=1 -D_VX_CPU=_VX_$(CPU) -D_VX_TOOL_FAMILY=$(TOOL_FAMILY) -D_VX_TOOL=$(TOOL)
TCC += -I$(WIND_USR)/h -I$(WIND_USR)/h/wrn/coreip
#TCC = /opt/ansic/bin/c89 -O +z -Wl,-a,archive
#TCC_SHARED = $(TCC) -fPIC
TCC_SHARED = $(TCC)
#### Tools used to build a static library.
#
#ARX = ar cr
#ARX = /opt/mingw/bin/i386-mingw32-ar cr
AR += cr
#RANLIB = ranlib
#RANLIB = /opt/mingw/bin/i386-mingw32-ranlib
#MKSHLIB = gcc -shared
#SO = so
#SHPREFIX = lib
MKSHLIB = $(CC) $(DEFINE_CC) -mrtp -shared $(CC_ARCH_SPEC) -D_VX_CPU=_VX_$(CPU) -D_VX_TOOL_FAMILY=$(TOOL_FAMILY) -D_VX_TOOL=$(TOOL)
SO = so
SHPREFIX = lib
#### Extra compiler options needed for programs that use the TCL library.
#
#TCL_FLAGS =
#TCL_FLAGS = -DSTATIC_BUILD=1
TCL_FLAGS = -I/home/drh/tcltk/8.4linux
#TCL_FLAGS = -I/home/drh/tcltk/8.4win -DSTATIC_BUILD=1
#TCL_FLAGS = -I/home/drh/tcltk/8.3hpux
#### Linker options needed to link against the TCL library.
#
#LIBTCL = -ltcl -lm -ldl
LIBTCL = /home/drh/tcltk/8.4linux/libtcl8.4g.a -lm -ldl
#LIBTCL = /home/drh/tcltk/8.4win/libtcl84s.a -lmsvcrt
#LIBTCL = /home/drh/tcltk/8.3hpux/libtcl8.3.a -ldld -lm -lc
#### Additional objects for SQLite library when TCL support is enabled.
TCLOBJ =
#TCLOBJ = tclsqlite.o
#### Compiler options needed for programs that use the readline() library.
#
READLINE_FLAGS =
#READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline
#### Linker options needed by programs using readline() must link against.
#
LIBREADLINE =
#LIBREADLINE = -static -lreadline -ltermcap
#### Which "awk" program provides nawk compatibilty
#
# NAWK = nawk
NAWK = awk
#### Pasted and adapted main.mk file
###############################################################################
# The following macros should be defined before this script is
# invoked:
#
# TOP The toplevel directory of the source tree. This is the
# directory that contains this "Makefile.in" and the
# "configure.in" script.
#
# BCC C Compiler and options for use in building executables that
# will run on the platform that is doing the build.
#
# THREADLIB Specify any extra linker options needed to make the library
# thread safe
#
# OPTS Extra compiler command-line options.
#
# EXE The suffix to add to executable files. ".exe" for windows
# and "" for Unix.
#
# TCC C Compiler and options for use in building executables that
# will run on the target platform. This is usually the same
# as BCC, unless you are cross-compiling.
#
# AR Tools used to build a static library.
# RANLIB
#
# TCL_FLAGS Extra compiler options needed for programs that use the
# TCL library.
#
# LIBTCL Linker options needed to link against the TCL library.
#
# READLINE_FLAGS Compiler options needed for programs that use the
# readline() library.
#
# LIBREADLINE Linker options needed by programs using readline() must
# link against.
#
# NAWK Nawk compatible awk program. Older (obsolete?) solaris
# systems need this to avoid using the original AT&T AWK.
#
# Once the macros above are defined, the rest of this make script will
# build the SQLite library and testing tools.
################################################################################
# This is how we compile
#
TCCX = $(TCC) $(OPTS) -I. -I$(TOP)/src -I$(TOP) -I$(TOP)/ext/rtree
TCCX_SHARED = $(TCC_SHARED) $(OPTS) -I. -I$(TOP)/src -I$(TOP) -I$(TOP)/ext/rtree
# Object files for the SQLite library.
#
LIBOBJ+= alter.o analyze.o attach.o auth.o \
bitvec.o btmutex.o btree.o build.o \
callback.o complete.o date.o delete.o \
expr.o fault.o func.o global.o hash.o \
icu.o insert.o journal.o legacy.o loadext.o \
main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.o memjournal.o \
mutex.o mutex_os2.o mutex_unix.o mutex_w32.o mutex_noop.o \
opcodes.o os.o os_os2.o os_unix.o os_win.o \
pager.o parse.o pcache.o pragma.o prepare.o printf.o \
random.o resolve.o rtree.o select.o status.o \
table.o tokenize.o trigger.o \
update.o util.o vacuum.o \
vdbe.o vdbeapi.o vdbeaux.o vdbeblob.o vdbefifo.o vdbemem.o \
walker.o where.o utf.o vtab.o
# All of the source code files.
#
SRC = \
$(TOP)/src/alter.c \
$(TOP)/src/analyze.c \
$(TOP)/src/attach.c \
$(TOP)/src/auth.c \
$(TOP)/src/bitvec.c \
$(TOP)/src/btmutex.c \
$(TOP)/src/btree.c \
$(TOP)/src/btree.h \
$(TOP)/src/btreeInt.h \
$(TOP)/src/build.c \
$(TOP)/src/callback.c \
$(TOP)/src/complete.c \
$(TOP)/src/date.c \
$(TOP)/src/delete.c \
$(TOP)/src/expr.c \
$(TOP)/src/fault.c \
$(TOP)/src/func.c \
$(TOP)/src/global.c \
$(TOP)/src/hash.c \
$(TOP)/src/hash.h \
$(TOP)/src/hwtime.h \
$(TOP)/src/insert.c \
$(TOP)/src/journal.c \
$(TOP)/src/legacy.c \
$(TOP)/src/loadext.c \
$(TOP)/src/main.c \
$(TOP)/src/malloc.c \
$(TOP)/src/mem0.c \
$(TOP)/src/mem1.c \
$(TOP)/src/mem2.c \
$(TOP)/src/mem3.c \
$(TOP)/src/mem5.c \
$(TOP)/src/memjournal.c \
$(TOP)/src/mutex.c \
$(TOP)/src/mutex.h \
$(TOP)/src/mutex_os2.c \
$(TOP)/src/mutex_unix.c \
$(TOP)/src/mutex_w32.c \
$(TOP)/src/mutex_noop.c \
$(TOP)/src/os.c \
$(TOP)/src/os.h \
$(TOP)/src/os_common.h \
$(TOP)/src/os_os2.c \
$(TOP)/src/os_unix.c \
$(TOP)/src/os_win.c \
$(TOP)/src/pager.c \
$(TOP)/src/pager.h \
$(TOP)/src/parse.y \
$(TOP)/src/pcache.c \
$(TOP)/src/pcache.h \
$(TOP)/src/pragma.c \
$(TOP)/src/prepare.c \
$(TOP)/src/printf.c \
$(TOP)/src/random.c \
$(TOP)/src/resolve.c \
$(TOP)/src/select.c \
$(TOP)/src/status.c \
$(TOP)/src/shell.c \
$(TOP)/src/sqlite.h.in \
$(TOP)/src/sqlite3ext.h \
$(TOP)/src/sqliteInt.h \
$(TOP)/src/sqliteLimit.h \
$(TOP)/src/table.c \
$(TOP)/src/tclsqlite.c \
$(TOP)/src/tokenize.c \
$(TOP)/src/trigger.c \
$(TOP)/src/utf.c \
$(TOP)/src/update.c \
$(TOP)/src/util.c \
$(TOP)/src/vacuum.c \
$(TOP)/src/vdbe.c \
$(TOP)/src/vdbe.h \
$(TOP)/src/vdbeapi.c \
$(TOP)/src/vdbeaux.c \
$(TOP)/src/vdbeblob.c \
$(TOP)/src/vdbefifo.c \
$(TOP)/src/vdbemem.c \
$(TOP)/src/vdbeInt.h \
$(TOP)/src/vtab.c \
$(TOP)/src/walker.c \
$(TOP)/src/where.c
# Source code for extensions
#
SRC += \
$(TOP)/ext/fts1/fts1.c \
$(TOP)/ext/fts1/fts1.h \
$(TOP)/ext/fts1/fts1_hash.c \
$(TOP)/ext/fts1/fts1_hash.h \
$(TOP)/ext/fts1/fts1_porter.c \
$(TOP)/ext/fts1/fts1_tokenizer.h \
$(TOP)/ext/fts1/fts1_tokenizer1.c
SRC += \
$(TOP)/ext/fts2/fts2.c \
$(TOP)/ext/fts2/fts2.h \
$(TOP)/ext/fts2/fts2_hash.c \
$(TOP)/ext/fts2/fts2_hash.h \
$(TOP)/ext/fts2/fts2_icu.c \
$(TOP)/ext/fts2/fts2_porter.c \
$(TOP)/ext/fts2/fts2_tokenizer.h \
$(TOP)/ext/fts2/fts2_tokenizer.c \
$(TOP)/ext/fts2/fts2_tokenizer1.c
SRC += \
$(TOP)/ext/fts3/fts3.c \
$(TOP)/ext/fts3/fts3.h \
$(TOP)/ext/fts3/fts3_hash.c \
$(TOP)/ext/fts3/fts3_hash.h \
$(TOP)/ext/fts3/fts3_icu.c \
$(TOP)/ext/fts3/fts3_porter.c \
$(TOP)/ext/fts3/fts3_tokenizer.h \
$(TOP)/ext/fts3/fts3_tokenizer.c \
$(TOP)/ext/fts3/fts3_tokenizer1.c
SRC += \
$(TOP)/ext/icu/icu.c \
$(TOP)/ext/icu/sqliteicu.h
SRC += \
$(TOP)/ext/rtree/rtree.h \
$(TOP)/ext/rtree/rtree.c
# Generated source code files
#
SRC += \
keywordhash.h \
opcodes.c \
opcodes.h \
parse.c \
parse.h \
sqlite3.h
# Source code to the test files.
#
TESTSRC = \
$(TOP)/src/test1.c \
$(TOP)/src/test2.c \
$(TOP)/src/test3.c \
$(TOP)/src/test4.c \
$(TOP)/src/test5.c \
$(TOP)/src/test6.c \
$(TOP)/src/test7.c \
$(TOP)/src/test8.c \
$(TOP)/src/test9.c \
$(TOP)/src/test_autoext.c \
$(TOP)/src/test_async.c \
$(TOP)/src/test_btree.c \
$(TOP)/src/test_config.c \
$(TOP)/src/test_devsym.c \
$(TOP)/src/test_func.c \
$(TOP)/src/test_hexio.c \
$(TOP)/src/test_malloc.c \
$(TOP)/src/test_md5.c \
$(TOP)/src/test_mutex.c \
$(TOP)/src/test_onefile.c \
$(TOP)/src/test_osinst.c \
$(TOP)/src/test_schema.c \
$(TOP)/src/test_server.c \
$(TOP)/src/test_tclvar.c \
$(TOP)/src/test_thread.c \
#TESTSRC += $(TOP)/ext/fts2/fts2_tokenizer.c
#TESTSRC += $(TOP)/ext/fts3/fts3_tokenizer.c
TESTSRC2 = \
$(TOP)/src/attach.c $(TOP)/src/btree.c $(TOP)/src/build.c $(TOP)/src/date.c \
$(TOP)/src/expr.c $(TOP)/src/func.c $(TOP)/src/insert.c $(TOP)/src/os.c \
$(TOP)/src/os_os2.c $(TOP)/src/os_unix.c $(TOP)/src/os_win.c \
$(TOP)/src/pager.c $(TOP)/src/pragma.c $(TOP)/src/prepare.c \
$(TOP)/src/printf.c $(TOP)/src/random.c $(TOP)/src/pcache.c \
$(TOP)/src/select.c $(TOP)/src/tokenize.c \
$(TOP)/src/utf.c $(TOP)/src/util.c $(TOP)/src/vdbeapi.c $(TOP)/src/vdbeaux.c \
$(TOP)/src/vdbe.c $(TOP)/src/vdbemem.c $(TOP)/src/where.c parse.c
# Header files used by all library source files.
#
HDR = \
$(TOP)/src/btree.h \
$(TOP)/src/btreeInt.h \
$(TOP)/src/hash.h \
$(TOP)/src/hwtime.h \
keywordhash.h \
$(TOP)/src/mutex.h \
opcodes.h \
$(TOP)/src/os.h \
$(TOP)/src/os_common.h \
$(TOP)/src/pager.h \
$(TOP)/src/pcache.h \
parse.h \
sqlite3.h \
$(TOP)/src/sqlite3ext.h \
$(TOP)/src/sqliteInt.h \
$(TOP)/src/sqliteLimit.h \
$(TOP)/src/vdbe.h \
$(TOP)/src/vdbeInt.h
# Header files used by extensions
#
EXTHDR += \
$(TOP)/ext/fts1/fts1.h \
$(TOP)/ext/fts1/fts1_hash.h \
$(TOP)/ext/fts1/fts1_tokenizer.h
EXTHDR += \
$(TOP)/ext/fts2/fts2.h \
$(TOP)/ext/fts2/fts2_hash.h \
$(TOP)/ext/fts2/fts2_tokenizer.h
EXTHDR += \
$(TOP)/ext/fts3/fts3.h \
$(TOP)/ext/fts3/fts3_hash.h \
$(TOP)/ext/fts3/fts3_tokenizer.h
EXTHDR += \
$(TOP)/ext/rtree/rtree.h
# This is the default Makefile target. The objects listed here
# are what get build when you type just "make" with no arguments.
#
all: sqlite3.h libsqlite3.a sqlite3$(EXE)
libsqlite3.a: $(LIBOBJ)
$(AR) libsqlite3.a $(LIBOBJ)
$(RANLIB) libsqlite3.a
$(SHPREFIX)sqlite3.$(SO): $(LIBOBJ)
$(MKSHLIB) -o $(SHPREFIX)sqlite3.$(SO) $(LIBOBJ) $(TLIBS_SHARED)
sqlite3$(EXE): $(TOP)/src/shell.c libsqlite3.a sqlite3.h
$(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE) \
$(TOP)/src/shell.c \
$(LIBREADLINE) $(TLIBS) $(THREADLIB) -L. -lsqlite3
# This target creates a directory named "tsrc" and fills it with
# copies of all of the C source code and header files needed to
# build on the target system. Some of the C source code and header
# files are automatically generated. This target takes care of
# all that automatic generation.
#
target_source: $(SRC)
rm -rf tsrc
mkdir tsrc
cp -f $(SRC) tsrc
rm tsrc/sqlite.h.in tsrc/parse.y
touch target_source
sqlite3.c: target_source $(TOP)/tool/mksqlite3c.tcl
tclsh $(TOP)/tool/mksqlite3c.tcl
cp sqlite3.c tclsqlite3.c
cat $(TOP)/src/tclsqlite.c >>tclsqlite3.c
fts2amal.c: target_source $(TOP)/ext/fts2/mkfts2amal.tcl
tclsh $(TOP)/ext/fts2/mkfts2amal.tcl
fts3amal.c: target_source $(TOP)/ext/fts3/mkfts3amal.tcl
tclsh $(TOP)/ext/fts3/mkfts3amal.tcl
# Rules to build the LEMON compiler generator
#
lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
$(BCC) -o lemon $(TOP)/tool/lemon.c
cp $(TOP)/tool/lempar.c .
# Rules to build individual *.o files from generated *.c files. This
# applies to:
#
# parse.o
# opcodes.o
#
%.o: %.c $(HDR)
$(TCCX_SHARED) -c $<
# Rules to build individual *.o files from files in the src directory.
#
%.o: $(TOP)/src/%.c $(HDR)
$(TCCX_SHARED) -c $<
tclsqlite.o: $(TOP)/src/tclsqlite.c $(HDR)
$(TCCX_SHARED) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
# Rules to build opcodes.c and opcodes.h
#
opcodes.c: opcodes.h $(TOP)/mkopcodec.awk
sort -n -b -k 3 opcodes.h | $(NAWK) -f $(TOP)/mkopcodec.awk >opcodes.c
opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk
cat parse.h $(TOP)/src/vdbe.c | \
$(NAWK) -f $(TOP)/mkopcodeh.awk >opcodes.h
# Rules to build parse.c and parse.h - the outputs of lemon.
#
parse.h: parse.c
parse.c: $(TOP)/src/parse.y lemon $(TOP)/addopcodes.awk
cp $(TOP)/src/parse.y .
rm -f parse.h
./lemon $(OPTS) parse.y
mv parse.h parse.h.temp
awk -f $(TOP)/addopcodes.awk parse.h.temp >parse.h
sqlite3.h: $(TOP)/src/sqlite.h.in
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
-e s/--VERSION-NUMBER--/`cat ${TOP}/VERSION | sed 's/[^0-9]/ /g' | $(NAWK) '{printf "%d%03d%03d",$$1,$$2,$$3}'`/ \
$(TOP)/src/sqlite.h.in >sqlite3.h
keywordhash.h: $(TOP)/tool/mkkeywordhash.c
$(BCC) -o mkkeywordhash $(OPTS) $(TOP)/tool/mkkeywordhash.c
./mkkeywordhash >keywordhash.h
# Rules to build the extension objects.
#
icu.o: $(TOP)/ext/icu/icu.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/icu/icu.c
fts2.o: $(TOP)/ext/fts2/fts2.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2.c
fts2_hash.o: $(TOP)/ext/fts2/fts2_hash.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_hash.c
fts2_icu.o: $(TOP)/ext/fts2/fts2_icu.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_icu.c
fts2_porter.o: $(TOP)/ext/fts2/fts2_porter.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_porter.c
fts2_tokenizer.o: $(TOP)/ext/fts2/fts2_tokenizer.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_tokenizer.c
fts2_tokenizer1.o: $(TOP)/ext/fts2/fts2_tokenizer1.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_tokenizer1.c
fts3.o: $(TOP)/ext/fts3/fts3.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3.c
fts3_hash.o: $(TOP)/ext/fts3/fts3_hash.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_hash.c
fts3_icu.o: $(TOP)/ext/fts3/fts3_icu.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_icu.c
fts3_porter.o: $(TOP)/ext/fts3/fts3_porter.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_porter.c
fts3_tokenizer.o: $(TOP)/ext/fts3/fts3_tokenizer.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_tokenizer.c
fts3_tokenizer1.o: $(TOP)/ext/fts3/fts3_tokenizer1.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_tokenizer1.c
rtree.o: $(TOP)/ext/rtree/rtree.c $(HDR) $(EXTHDR)
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/rtree/rtree.c
# Rules for building test programs and for running tests
#
tclsqlite3: $(TOP)/src/tclsqlite.c libsqlite3.a
$(TCCX_SHARED) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite3 \
$(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB)
# Rules to build the 'testfixture' application.
#
TESTFIXTURE_FLAGS = -DTCLSH=1 -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1
TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE
testfixture$(EXE): $(TESTSRC2) libsqlite3.a $(TESTSRC) $(TOP)/src/tclsqlite.c
$(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \
$(TESTSRC) $(TESTSRC2) $(TOP)/src/tclsqlite.c \
-o testfixture$(EXE) $(LIBTCL) $(THREADLIB) libsqlite3.a
amalgamation-testfixture$(EXE): sqlite3.c $(TESTSRC) $(TOP)/src/tclsqlite.c
$(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \
$(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c \
-o testfixture$(EXE) $(LIBTCL) $(THREADLIB)
fts3-testfixture$(EXE): sqlite3.c fts3amal.c $(TESTSRC) $(TOP)/src/tclsqlite.c
$(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \
-DSQLITE_ENABLE_FTS3=1 \
$(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c fts3amal.c \
-o testfixture$(EXE) $(LIBTCL) $(THREADLIB)
fulltest: testfixture$(EXE) sqlite3$(EXE)
./testfixture$(EXE) $(TOP)/test/all.test
soaktest: testfixture$(EXE) sqlite3$(EXE)
./testfixture$(EXE) $(TOP)/test/all.test -soak 1
test: testfixture$(EXE) sqlite3$(EXE)
./testfixture$(EXE) $(TOP)/test/veryquick.test
sqlite3_analyzer$(EXE): $(TOP)/src/tclsqlite.c sqlite3.c $(TESTSRC) \
$(TOP)/tool/spaceanal.tcl
sed \
-e '/^#/d' \
-e 's,\\,\\\\,g' \
-e 's,",\\",g' \
-e 's,^,",' \
-e 's,$$,\\n",' \
$(TOP)/tool/spaceanal.tcl >spaceanal_tcl.h
$(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \
-DTCLSH=2 -DSQLITE_TEST=1 -DSQLITE_DEBUG=1 -DSQLITE_PRIVATE="" \
$(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c \
-o sqlite3_analyzer$(EXE) \
$(LIBTCL) $(THREADLIB)
TEST_EXTENSION = $(SHPREFIX)testloadext.$(SO)
$(TEST_EXTENSION): $(TOP)/src/test_loadext.c
$(MKSHLIB) $(TOP)/src/test_loadext.c -o $(TEST_EXTENSION)
extensiontest: testfixture$(EXE) $(TEST_EXTENSION)
./testfixture$(EXE) $(TOP)/test/loadext.test
clean:
rm -f *.o sqlite3$(EXE) libsqlite3.a sqlite3.h opcodes.*
rm -f lemon lempar.c parse.* sqlite*.tar.gz mkkeywordhash keywordhash.h
rm -f $(PUBLISH)
rm -f *.da *.bb *.bbg gmon.out
rm -rf tsrc target_source
rm -f testloadext.dll libtestloadext.so
rm -f sqlite3.c fts?amal.c tclsqlite3.c
rm -f $(SHPREFIX)sqlite3.$(SO)
+1 -1
View File
@@ -1 +1 @@
3.6.3
3.6.6.1
Vendored
+8 -4
View File
@@ -1489,7 +1489,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
# The following RCS revision string applies to configure.in
# $Revision: 1.64 $
# $Revision: 1.65 $
#########
# Programs needed
@@ -12071,34 +12071,37 @@ else
fi
#########
# attempt to duplicate any OMITS into the $(OPT_FEATURE_FLAGS) parameter
# attempt to duplicate any OMITS and ENABLES into the $(OPT_FEATURE_FLAGS) parameter
for option in $CFLAGS $CPPFLAGS
do
case $option in
-DSQLITE_OMIT*) OPT_FEATURE_FLAGS="$OPT_FEATURE_FLAGS $option";;
-DSQLITE_ENABLE*) OPT_FEATURE_FLAGS="$OPT_FEATURE_FLAGS $option";;
esac
done
# attempt to remove any OMITS from the $(CFLAGS) parameter
# attempt to remove any OMITS and ENABLES from the $(CFLAGS) parameter
ac_temp_CFLAGS=""
for option in $CFLAGS
do
case $option in
-DSQLITE_OMIT*) ;;
-DSQLITE_ENABLE*) ;;
*) ac_temp_CFLAGS="$ac_temp_CFLAGS $option";;
esac
done
CFLAGS=$ac_temp_CFLAGS
# attempt to remove any OMITS from the $(CPPFLAGS) parameter
# attempt to remove any OMITS and ENABLES from the $(CPPFLAGS) parameter
ac_temp_CPPFLAGS=""
for option in $CPPFLAGS
do
case $option in
-DSQLITE_OMIT*) ;;
-DSQLITE_ENABLE*) ;;
*) ac_temp_CPPFLAGS="$ac_temp_CPPFLAGS $option";;
esac
done
@@ -12111,6 +12114,7 @@ for option in $BUILD_CFLAGS
do
case $option in
-DSQLITE_OMIT*) ;;
-DSQLITE_ENABLE*) ;;
*) ac_temp_BUILD_CFLAGS="$ac_temp_BUILD_CFLAGS $option";;
esac
done
+9 -5
View File
@@ -92,7 +92,7 @@ AC_INIT(sqlite, m4_esyscmd([cat VERSION | tr -d '\n']))
dnl Put the RCS revision string after AC_INIT so that it will also
dnl show in in configure.
# The following RCS revision string applies to configure.in
# $Revision: 1.49 $
# $Revision: 1.50 $
#########
# Programs needed
@@ -611,46 +611,50 @@ else
fi
#########
# attempt to duplicate any OMITS into the $(OPT_FEATURE_FLAGS) parameter
# attempt to duplicate any OMITS and ENABLES into the $(OPT_FEATURE_FLAGS) parameter
for option in $CFLAGS $CPPFLAGS
do
case $option in
-DSQLITE_OMIT*) OPT_FEATURE_FLAGS="$OPT_FEATURE_FLAGS $option";;
-DSQLITE_ENABLE*) OPT_FEATURE_FLAGS="$OPT_FEATURE_FLAGS $option";;
esac
done
AC_SUBST(OPT_FEATURE_FLAGS)
# attempt to remove any OMITS from the $(CFLAGS) parameter
# attempt to remove any OMITS and ENABLES from the $(CFLAGS) parameter
ac_temp_CFLAGS=""
for option in $CFLAGS
do
case $option in
-DSQLITE_OMIT*) ;;
-DSQLITE_ENABLE*) ;;
*) ac_temp_CFLAGS="$ac_temp_CFLAGS $option";;
esac
done
CFLAGS=$ac_temp_CFLAGS
# attempt to remove any OMITS from the $(CPPFLAGS) parameter
# attempt to remove any OMITS and ENABLES from the $(CPPFLAGS) parameter
ac_temp_CPPFLAGS=""
for option in $CPPFLAGS
do
case $option in
-DSQLITE_OMIT*) ;;
-DSQLITE_ENABLE*) ;;
*) ac_temp_CPPFLAGS="$ac_temp_CPPFLAGS $option";;
esac
done
CPPFLAGS=$ac_temp_CPPFLAGS
# attempt to remove any OMITS from the $(BUILD_CFLAGS) parameter
# attempt to remove any OMITS and ENABLES from the $(BUILD_CFLAGS) parameter
ac_temp_BUILD_CFLAGS=""
for option in $BUILD_CFLAGS
do
case $option in
-DSQLITE_OMIT*) ;;
-DSQLITE_ENABLE*) ;;
*) ac_temp_BUILD_CFLAGS="$ac_temp_BUILD_CFLAGS $option";;
esac
done
+7 -8
View File
@@ -338,6 +338,13 @@ void *sqlite3Fts3HashInsert(
return old_data;
}
if( data==0 ) return 0;
if( pH->htsize==0 ){
fts3Rehash(pH,8);
if( pH->htsize==0 ){
pH->count = 0;
return data;
}
}
new_elem = (fts3HashElem*)fts3HashMalloc( sizeof(fts3HashElem) );
if( new_elem==0 ) return data;
if( pH->copyKey && pKey!=0 ){
@@ -352,14 +359,6 @@ void *sqlite3Fts3HashInsert(
}
new_elem->nKey = nKey;
pH->count++;
if( pH->htsize==0 ){
fts3Rehash(pH,8);
if( pH->htsize==0 ){
pH->count = 0;
fts3HashFree(new_elem);
return data;
}
}
if( pH->count > pH->htsize ){
fts3Rehash(pH,pH->htsize*2);
}
+13 -9
View File
@@ -12,7 +12,7 @@
** This file contains code for implementations of the r-tree and r*-tree
** algorithms packaged as an SQLite virtual table module.
**
** $Id: rtree.c,v 1.9 2008/09/08 11:07:03 danielk1977 Exp $
** $Id: rtree.c,v 1.11 2008/11/12 15:24:27 drh Exp $
*/
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
@@ -226,8 +226,12 @@ struct RtreeCell {
RtreeCoord aCoord[RTREE_MAX_DIMENSIONS*2];
};
#define MAX(x,y) ((x) < (y) ? (y) : (x))
#define MIN(x,y) ((x) > (y) ? (y) : (x))
#ifndef MAX
# define MAX(x,y) ((x) < (y) ? (y) : (x))
#endif
#ifndef MIN
# define MIN(x,y) ((x) > (y) ? (y) : (x))
#endif
/*
** Functions to deserialize a 16 bit integer, 32 bit real number and
@@ -600,7 +604,7 @@ static void nodeGetCell(
** the virtual table module xCreate() and xConnect() methods.
*/
static int rtreeInit(
sqlite3 *, void *, int, const char *const*, sqlite3_vtab **, char **, int, int
sqlite3 *, void *, int, const char *const*, sqlite3_vtab **, char **, int
);
/*
@@ -613,7 +617,7 @@ static int rtreeCreate(
sqlite3_vtab **ppVtab,
char **pzErr
){
return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1, (int)pAux);
return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
}
/*
@@ -626,7 +630,7 @@ static int rtreeConnect(
sqlite3_vtab **ppVtab,
char **pzErr
){
return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0, (int)pAux);
return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
}
/*
@@ -2651,18 +2655,18 @@ static int getPageSize(sqlite3 *db, const char *zDb, int *piPageSize){
*/
static int rtreeInit(
sqlite3 *db, /* Database connection */
void *pAux, /* Pointer to head of rtree list */
void *pAux, /* One of the RTREE_COORD_* constants */
int argc, const char *const*argv, /* Parameters to CREATE TABLE statement */
sqlite3_vtab **ppVtab, /* OUT: New virtual table */
char **pzErr, /* OUT: Error message, if any */
int isCreate, /* True for xCreate, false for xConnect */
int eCoordType /* One of the RTREE_COORD_* constants */
int isCreate /* True for xCreate, false for xConnect */
){
int rc = SQLITE_OK;
int iPageSize = 0;
Rtree *pRtree;
int nDb; /* Length of string argv[1] */
int nName; /* Length of string argv[2] */
int eCoordType = (int)pAux;
const char *aErrMsg[] = {
0, /* 0 */
+19 -10
View File
@@ -44,19 +44,23 @@
# This is how we compile
#
TCCX = $(TCC) $(OPTS) -I. -I$(TOP)/src -I$(TOP) -I$(TOP)/ext/rtree -I$(TOP)/ext/icu
TCCX = $(TCC) $(OPTS) -I. -I$(TOP)/src -I$(TOP)
TCCX += -I$(TOP)/ext/rtree -I$(TOP)/ext/icu -I$(TOP)/ext/fts3
# Object files for the SQLite library.
#
LIBOBJ+= alter.o analyze.o attach.o auth.o \
bitvec.o btmutex.o btree.o build.o \
callback.o complete.o date.o delete.o \
expr.o fault.o func.o global.o hash.o \
callback.o complete.o date.o delete.o expr.o fault.o \
fts3.o fts3_hash.o fts3_icu.o fts3_porter.o \
fts3_tokenizer.o fts3_tokenizer1.o \
func.o global.o hash.o \
icu.o insert.o journal.o legacy.o loadext.o \
main.o malloc.o mem1.o mem2.o mem3.o mem4.o mem5.o mem6.o \
mutex.o mutex_os2.o mutex_unix.o mutex_w32.o \
main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.o \
memjournal.o \
mutex.o mutex_noop.o mutex_os2.o mutex_unix.o mutex_w32.o \
opcodes.o os.o os_os2.o os_unix.o os_win.o \
pager.o parse.o pcache.o pragma.o prepare.o printf.o \
pager.o parse.o pcache.o pcache1.o pragma.o prepare.o printf.o \
random.o resolve.o rtree.o select.o status.o \
table.o tokenize.o trigger.o \
update.o util.o vacuum.o \
@@ -64,6 +68,7 @@ LIBOBJ+= alter.o analyze.o attach.o auth.o \
walker.o where.o utf.o vtab.o
# All of the source code files.
#
SRC = \
@@ -94,14 +99,15 @@ SRC = \
$(TOP)/src/loadext.c \
$(TOP)/src/main.c \
$(TOP)/src/malloc.c \
$(TOP)/src/mem0.c \
$(TOP)/src/mem1.c \
$(TOP)/src/mem2.c \
$(TOP)/src/mem3.c \
$(TOP)/src/mem4.c \
$(TOP)/src/mem5.c \
$(TOP)/src/mem6.c \
$(TOP)/src/memjournal.c \
$(TOP)/src/mutex.c \
$(TOP)/src/mutex.h \
$(TOP)/src/mutex_noop.c \
$(TOP)/src/mutex_os2.c \
$(TOP)/src/mutex_unix.c \
$(TOP)/src/mutex_w32.c \
@@ -116,6 +122,7 @@ SRC = \
$(TOP)/src/parse.y \
$(TOP)/src/pcache.c \
$(TOP)/src/pcache.h \
$(TOP)/src/pcache1.c \
$(TOP)/src/pragma.c \
$(TOP)/src/prepare.c \
$(TOP)/src/printf.c \
@@ -221,6 +228,7 @@ TESTSRC = \
$(TOP)/src/test_mutex.c \
$(TOP)/src/test_onefile.c \
$(TOP)/src/test_osinst.c \
$(TOP)/src/test_pcache.c \
$(TOP)/src/test_schema.c \
$(TOP)/src/test_server.c \
$(TOP)/src/test_tclvar.c \
@@ -236,9 +244,10 @@ TESTSRC2 = \
$(TOP)/src/os_os2.c $(TOP)/src/os_unix.c $(TOP)/src/os_win.c \
$(TOP)/src/pager.c $(TOP)/src/pragma.c $(TOP)/src/prepare.c \
$(TOP)/src/printf.c $(TOP)/src/random.c $(TOP)/src/pcache.c \
$(TOP)/src/select.c $(TOP)/src/tokenize.c \
$(TOP)/src/pcache1.c $(TOP)/src/select.c $(TOP)/src/tokenize.c \
$(TOP)/src/utf.c $(TOP)/src/util.c $(TOP)/src/vdbeapi.c $(TOP)/src/vdbeaux.c \
$(TOP)/src/vdbe.c $(TOP)/src/vdbemem.c $(TOP)/src/where.c parse.c
$(TOP)/src/vdbe.c $(TOP)/src/vdbemem.c $(TOP)/src/where.c parse.c \
$(TOP)/ext/fts3/fts3.c $(TOP)/ext/fts3/fts3_tokenizer.c
# Header files used by all library source files.
#
+173 -151
View File
@@ -1,10 +1,11 @@
C Version\s3.6.3\s(CVS\s5729)
D 2008-09-22T10:44:32
C Version\s3.6.6.1\s(CVS\s5948)
D 2008-11-22T15:51:28
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in d15a7ebfe5e057a72a49805ffb302dbb601c8329
F Makefile.in 0aa7bbe3be6acc4045706e3bb3fd0b8f38f4a3b5
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F Makefile.vxwSH4 d53b4be86491060d498b22148951b6d765884cab
F README b974cdc3f9f12b87e851b04e75996d720ebf81ac
F VERSION 708c93c5dbb97b8a8e4c39eb77c53dae43d96910
F VERSION 0fb8ff48a435ea7ea0f720a79cb3c4911a7ab06c
F aclocal.m4 7d02b11fed45174e11156144227278deb6236eea
F addopcodes.awk 215333be9d99c260e076c3080a81dba3ae928c45
F art/2005osaward.gif 0d1851b2a7c1c9d0ccce545f3e14bca42d7fd248
@@ -17,8 +18,8 @@ F art/powered_by_sqlite.gif 7fbcd7d3675391fd3d21672c14c05f5999eb60d1
F config.guess 226d9a188c6196f3033ffc651cbc9dcee1a42977
F config.h.in 3fda160d9a0ebbd6c22c0391354fa0036474680f
F config.sub 9ebe4c3b3dab6431ece34f16828b594fb420da55
F configure a013a40a9215b92fb9267603823f95d007ab5b00 x
F configure.ac 24d54c19c2fb8045598495250230d117c2464502
F configure f5bb190d8e9290c4e95349fd6919fd611b438bcf x
F configure.ac 34d1ef70f1170b770049660b5de8398aa0ed7d28
F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad
F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
@@ -53,7 +54,7 @@ F ext/fts3/README.tokenizers 226644a0eab97724e8de83061912e8bb248461b6
F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
F ext/fts3/fts3.c e67453b6ac421b79e600385491ed7f038b3bb271
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
F ext/fts3/fts3_hash.c 83e7bb4042106b32811681dd2859b4577a7a6b35
F ext/fts3/fts3_hash.c e15e84d18f8df149ab290029872d4559c4c7c15a
F ext/fts3/fts3_hash.h 004b759e1602ff16dfa02fea3ca1c77336ad6798
F ext/fts3/fts3_icu.c ac494aed69835008185299315403044664bda295
F ext/fts3/fts3_porter.c 3063da945fb0a935781c135f7575f39166173eca
@@ -65,7 +66,7 @@ F ext/icu/README.txt 3b130aa66e7a681136f6add198b076a2f90d1e33
F ext/icu/icu.c 12e763d288d23b5a49de37caa30737b971a2f1e2
F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
F ext/rtree/rtree.c 9a9ef98ea5c36841cedf95d8cfbe79ebb411fef6
F ext/rtree/rtree.c 05d517734dad60165255581cc8dacea00c03b5c0
F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e
F ext/rtree/rtree1.test 620223886bf1a319317e63235aac20790375c544
F ext/rtree/rtree2.test 9ac9d28fa948779df66916c67a5dcf9704c3cb74
@@ -79,8 +80,8 @@ F ext/rtree/tkt3363.test 6662237ea75bb431cd5d262dfc9535e1023315fc
F ext/rtree/viewrtree.tcl 09526398dae87a5a87c5aac2b3854dbaf8376869
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh 09fe5815427dc7d0abb188bbcdf0e34896577210
F main.mk b207901cca3301dcb08892be8563eab126f10037
F mkdll.sh 79d1ed6ae221c10589dd969f130f8a3cccfffbb7
F main.mk 87a73e91a3d0827dc796a249260866335e38a36e
F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac
F mkopcodec.awk 3fb9bf077053c968451f4dd03d11661ac373f9d1
@@ -89,125 +90,128 @@ F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
F publish.sh 5d092a0d7b0d9de009cb7aeff8bcd1608b49dd01
F publish_osx.sh 2ad2ee7d50632dff99949edc9c162dbb052f7534
F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca
F sqlite.pc.in c322c6244c6395955dca34d87955aabde7df7623
F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
F sqlite3.def a1be7b9a4b8b51ac41c6ff6e8e44a14ef66b338b
F sqlite3.pc.in 32b8a014799c2028c8e0c9cc5659718262fc493f
F src/alter.c f462b637bac6c6576a9b7bc6da59c7a82ed5aab2
F src/analyze.c 747ce8cb6b318bb0d0576cfb5277aed98cbbeb5c
F src/attach.c db3f4a60538733c1e4dcb9d0217a6e0d6ccd615b
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
F src/alter.c 0a00c184052b7fd20271e783f65fec4efec6fe30
F src/analyze.c 301a1358f4f4d84d96608927d8ddcf471c53ad9a
F src/attach.c 85c6a3d0daf11965b47604190d7cf5597dc88382
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d
F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53
F src/btree.c 4d642d23fc4507089f702eb24b506be2ce7e0efd
F src/btree.h 6371c5e599fab391a150c96afbc10062b276d107
F src/btreeInt.h e36f77e6621d671beb19ae581af1eba116cdfdc4
F src/build.c 160c71acca8f643f436ed6c1ee2f684c88df4dfe
F src/callback.c 7a40fd44da3eb89e7f6eff30aa6f940c45d73a97
F src/bitvec.c 4300d311b17fb3c1476623fd895a8feac02a0b08
F src/btmutex.c 63c5cc4ad5715690767ffcb741e185d7bc35ec1a
F src/btree.c adfb7974429f79f188fabcdb26145fca3a7d04ed
F src/btree.h 179c3ea813780df78a289a8f5130db18e6d4616e
F src/btreeInt.h 8d21590c97b6a2c00cce1f78ed5dc5756e835108
F src/build.c a89e901ea24d8ec845286f9a1fbfd14572a7777e
F src/callback.c e970e5beddbdb23f89a6d05cb1a6419d9f755624
F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
F src/date.c 5c092296c03d658e84884121a694150964d6861d
F src/delete.c bae6684aa02e1f7cf6328023157c91d9cf94200b
F src/expr.c 04822d5c7af85fd195a5f72501ab5e8d99768fae
F src/date.c 88898ae96a0d7f66711caffa40b2cf30e623a387
F src/delete.c 2f85d6d00333343a76824a899e15f241ca383c7c
F src/expr.c 01b1cf0783a6d0093d72b799fcb22c86146362ef
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
F src/func.c 8431b40a7843d1024145684d303c55b4ee087bbe
F src/func.c b4570eb73d873041b8e68f5cdbb4556ff13a94c3
F src/global.c 20a3fe46c8287a01ba3a7442558f0eb70c66b19a
F src/hash.c eb64e48f3781100e5934f759fbe72a63a8fe78cb
F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
F src/hash.c 582c00618efe2051785e66ba1b6430d5a129de3f
F src/hash.h 28f38ebb1006a5beedcb013bcdfe31befe7437ae
F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb
F src/insert.c 110cca7845ed5a66c08fdd413b02e706ae34455f
F src/insert.c 73c4b33767d9540f8ead5d903504ed93f48ad147
F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3
F src/loadext.c 6581a5bbc4d74fcd46dbbcfd695a6a5417f778a2
F src/main.c 8704f23153fdcf3b748d8e7ca7e4ec7d7cd319be
F src/malloc.c 6c3bcae8ee8885f1705f36306062f82a64d96118
F src/mem1.c 5a529ff121c55ab067be14de00f86f6dcc4f4fb9
F src/mem2.c f87e681d0d1ed8436870d089332ed0d27d885b5c
F src/mem3.c 1594f117fde4cf11a6c16521f3f30af8d04bbe68
F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909
F src/mem5.c 706d462c13a9819dfec7c10d9dccedf8d199960c
F src/mem6.c febe4db9ddef73df500989e68a9d4ac68602a075
F src/mutex.c 81174f600553c25832e9a8705b609f16c73a4c01
F src/mutex.h e52ffa1dfc6a6077e8b1823d2c2b7dfcbcf85594
F src/loadext.c 3872457afdf25bb174fd383cb4e3e0d2a9e60552
F src/main.c d67d2eee7a643a4a894e5de91231a99ad88400b9
F src/malloc.c 4e7bf5a3fcfd848a09f7ce7abb00f7b358128161
F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c
F src/mem1.c bb8e26adde7d463270e961f045802c61dbabc8f1
F src/mem2.c 5d9968f576ba1babc787adbfb613cf428ab484ec
F src/mem3.c 67153ec933e08b70714055e872efb58a6b287939
F src/mem5.c 838309b521c96a2a34507f74a5a739d28de4aac6
F src/memjournal.c bd536c4d6d701b4fa7428545128c5684d2adf779
F src/mutex.c e9cb5fbe94afb4328869afaf3ac49bd1327559eb
F src/mutex.h 9e686e83a88838dac8b9c51271c651e833060f1e
F src/mutex_noop.c 0004efdbc2fd48d261d5b3416fe537e888c79a54
F src/mutex_os2.c 9c5637aa4c307c552566d0f0b3bd206245b54a97
F src/mutex_unix.c 29049a61755cccddb2ee53904e6906bb7674223c
F src/mutex_w32.c f0d21ff1f6981e5aedc56796adf3a347423ef736
F src/os.c 543976efc0b177b40779d5fc00f709d6888d6903
F src/mutex_unix.c 3b1c895a044d45812ea1eae9019daeff8cfb27ce
F src/mutex_w32.c 017b522f63ef09b834fefc9daa876c9ec167e7b5
F src/os.c 0b411644b87ad689d7250bbfd1834d99b81a3df4
F src/os.h ef8abeb9afc694b82dbd169a91c9b7e26db3c892
F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
F src/os_os2.c e391fc95adc744bbdcefd4d11e3066998185a0a0
F src/os_unix.c 8f4def6a92681735908fa1b87b5cc0291ebafde6
F src/os_win.c 3209dc0ed734291764393ea8d534ba0d8696a540
F src/pager.c 131746ea47383daf89fce08e0cb09b84cffa39eb
F src/pager.h 1ef5a3f8e0b4c8b30f19c8e01d4fca2db9bb5797
F src/parse.y d0f76d2cb8d6883d5600dc20beb961a6022b94b8
F src/pcache.c e2a4dd0ae4118c95499b97806ea26ece8d12127a
F src/pcache.h 0b6871e820159629915e8688b5c67a81a203773f
F src/pragma.c e633b6b7dabc110e2abfed4e35ba34a4039cb65c
F src/prepare.c c7e00ed1b0bdcf699b1aad651247d4dc3d281b0b
F src/printf.c 785f87120589c1db672e37c6eb1087c456e6f84d
F src/random.c 11bbdf7def3746a762fbdb56c9d04648135ad6d8
F src/resolve.c a6abf83125bce0c80ba04acc27c3565155ad305c
F src/select.c 4d25fe8da35abb5b5317a0248bedc3c9570416e9
F src/shell.c d83b578a8ccdd3e0e7fef4388a0887ce9f810967
F src/sqlite.h.in 81dc1e8e50fb5c7cccf0a67a34cb796efc1d2a1e
F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
F src/sqliteInt.h dbe2797806c48f4a90adfea69dfbea95edd722ae
F src/os_os2.c d12285d66df674c42f6f544a6f7c21bf1a954ee1
F src/os_unix.c 03c76b5269361adcd68cf9d6713181922535ac6e
F src/os_win.c 3dff41670fb9798a869c636626bb7d6d8b6a45bb
F src/pager.c db12a8333e54e7bbf62dc621ada5507adb3a6493
F src/pager.h a02ef8e6cc7e78b54874166e5ce786c9d4c489bf
F src/parse.y 2c4758b4c5ead6de8cf7112f5a7cce7561d313fe
F src/pcache.c f3121a531745b20f5b824201eb63949a7e2959ac
F src/pcache.h f20c3e82dd6da622c3fe296170cb1801f9a2d75a
F src/pcache1.c 2453a3e925841fdb610f39bba24def8b2ad4a908
F src/pragma.c 0a5051029c5b687e2f2669d91aa3281ebcbe4fdb
F src/prepare.c fcadb25d2ad722d87103517333c825b56b79a770
F src/printf.c ce86aed93a704938ca4d0344aaa763271842a4b0
F src/random.c a87afbd598aa877e23ac676ee92fd8ee5c786a51
F src/resolve.c 4af5391d2b4c1d6c583a6805ac6660181de4545b
F src/select.c e01537d4d8b8b81a6507e07ebb17fc232dacdda7
F src/shell.c 650d1a87408682280d0e9d014d0d328c59c84b38
F src/sqlite.h.in e9a0aa2502dfe01bf166956051528f28871474c3
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
F src/sqliteInt.h beacd5768e55285097fbb419bcd741721b455003
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
F src/tclsqlite.c a6a346f42322ae1df980228306da6c3cea4dd680
F src/test1.c c4de690aad182606e5914f6f3c8f43869fbdaaa8
F src/test2.c eaa77124786649eedf47d3c5e94d8070c0da228f
F src/test3.c e85b7ce5c28c3ce7fbdbf7f98e1467b19786c62b
F src/test4.c 41056378671e7b00e6305fa9ac6fa27e6f96f406
F src/tclsqlite.c 96049bd454f1547abff0a57c45f0dfa57701e076
F src/test1.c 9b440b38e1710e9be1512c003fa141e0e3948e05
F src/test2.c 897528183edf2839c2a3c991d415905db56f1240
F src/test3.c 88a246b56b824275300e6c899634fbac1dc94b14
F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c
F src/test5.c 162a1cea2105a2c460a3f39fa6919617b562a288
F src/test6.c 0a0304a69cfa4962a429d084c6d451ff9e4fb572
F src/test7.c 475b1fa7e3275408b40a3cbdc9508cbdc41ffa02
F src/test7.c b94e68c2236de76889d82b8d7d8e00ad6a4d80b1
F src/test8.c 3637439424d0d21ff2dcf9b015c30fcc1e7bcb24
F src/test9.c 904ebe0ed1472d6bad17a81e2ecbfc20017dc237
F src/test_async.c de6661370d96f660e0f0d604582c193c6144b19c
F src/test_async.c 45024094ed7cf780c5d5dccda645145f95cf78ef
F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
F src/test_btree.c 8d5b835054f1dd15992e09864a8bc04386bab701
F src/test_config.c b2681a8e1b570f0c3686c934d6ef6112921af05d
F src/test_btree.c d7b8716544611c323860370ee364e897c861f1b0
F src/test_config.c bc71818f468494ff95ac1fe1f5906a21b25f937b
F src/test_devsym.c 802d10e65b4217208cb47059b84adf46318bcdf4
F src/test_func.c a55c4d5479ff2eb5c0a22d4d88e9528ab59c953b
F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
F src/test_loadext.c 97dc8800e46a46ed002c2968572656f37e9c0dd9
F src/test_malloc.c 49abbf5d9c71fb06cf7a7cf96f9b9a799b77a421
F src/test_malloc.c 5127337c9fb4c851a7f604c0170e0e5ca1fbfe33
F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
F src/test_mutex.c d3422d9f60cc1330249d102e74b333f0d24a0cb6
F src/test_mutex.c 66c4ab4e0396a440ddb17cd9b58a05305144f05d
F src/test_onefile.c 243157b10275251c5dc2d6619aee2ff9ae22379c
F src/test_osinst.c ae29e9c09485622a157849508302dd9ffe44f21f
F src/test_pcache.c 0008968cc36558c8253585e5d321eccba44edb80
F src/test_schema.c 4b4bf7bb329326458c491b0e6facd4c8c4c5b479
F src/test_server.c f0a403b5f699c09bd2b1236b6f69830fd6221f6b
F src/test_tclvar.c 9e42fa59d3d2f064b7ab8628e7ab2dc8a9fe93d4
F src/test_thread.c d74fc445e0dba0e00806117eb449b307c0b146bf
F src/test_wsd.c a36c7fbb93eebf7c917d00fcaab25ad4d8a7918b
F src/test_wsd.c c297d7d6b8a990239e1bd25935e81d612d8ae31d
F src/tokenize.c aaa5fa6a4536a9dd7c855a3f66f32508f1612138
F src/trigger.c 649940b5bf5838a33721fb72372e7c9d1faf56a9
F src/update.c 206fffc877379affe3a9b42c78e478ea0874c9fe
F src/utf.c c63e6f69082f85c19ab88d62dedaf91d71ac1a50
F src/util.c afe659ccc05d1f8af9e8631dabfec3ee3a7144af
F src/vacuum.c fd77433d0c26d3ff1eb96eab017a1787ac5aa642
F src/vdbe.c c9499f1824049cfef00a6146ef832b742f477920
F src/vdbe.h 41c99aaad9167c1b5431993db446de74b2f71fc3
F src/vdbeInt.h b48c74d86a9fb62b707a3186ccca76bb32f1c6be
F src/vdbeapi.c c0f87aabb2bcf8c760ff9cb289119f7f6ba1797a
F src/vdbeaux.c 20a7d109c95e32beee7891fba828c63e419af26c
F src/vdbeblob.c f93110888ddc246215e9ba1f831d3d375bfd8355
F src/vdbefifo.c 20fda2a7c4c0bcee1b90eb7e545fefcdbf2e1de7
F src/vdbemem.c ead88713b852576e2a924bc4ae696964bfbaec0a
F src/vtab.c 527c180e9c5fca417c9167d02af4b5039f892b4b
F src/trigger.c b86eb6d216c0014138f858a04185113cb54518e4
F src/update.c 37d03659f4d2186ffb8d0ab1df9c3038273fb488
F src/utf.c 86dc0f8076f606432a01f1498ae054c32de1f9d2
F src/util.c b9a5d1c4c1a433e17d5828f9717fac763016a2cb
F src/vacuum.c 383d6297bddc011ab04a9eed110db6eaf523e8e9
F src/vdbe.c c5270245fcb5368634a9301481ab94a22e7a21b2
F src/vdbe.h 03516f28bf5aca00a53c4dccd6c313f96adb94f6
F src/vdbeInt.h 6b1082480832d406c57a7f469a1c61f1a8759aca
F src/vdbeapi.c 20722164e7701a0747eaea03cddbbe0de5cb37bf
F src/vdbeaux.c 18dea7bbaf3657d77331b03a3ec34363348ea5b0
F src/vdbeblob.c b0dcebfafedcf9c0addc7901ad98f6f986c08935
F src/vdbefifo.c e6326ad6d16ccd8c2ef659046e3a509c0ae4990a
F src/vdbemem.c 223e03281855515e9474dbf66f157452093a77c2
F src/vtab.c 02c51eac45dbff1a1d6e73f58febf92ecb563f7f
F src/walker.c 488c2660e13224ff70c0c82761118efb547f8f0d
F src/where.c a9958b26cc87ea1446fbe6d004a7959b8d5d75c1
F src/where.c 96f7c2bd9e83c252d90ee2794f7a902fc5ba505b
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/alias.test c321c114a8a31a33e3cbda910fa39949f5d9dcb2
F test/all.test e15e9df483e1a72ac0c9d6cad216c4c0bdc1c1c9
F test/alias.test 597662c5d777a122f9a3df0047ea5c5bd383a911
F test/all.test 03cdd58d389e35bee8d57b7d24357b827aecc463
F test/alter.test 6353aae6839e486c9b7d8f73b1f4a1e98e57332c
F test/alter2.test dd55146e812622c8fc51fd2216bcd8dca8880752
F test/alter3.test 25b95a136708f22b87184fa6a4309eea03d65153
F test/altermalloc.test 11116c58953b6275a48a87c2912b7d4b72c52840
F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc
F test/analyze.test ad5329098fe4de4a96852231d53e3e9e6283ad4b
F test/async.test 0ed384c12d556ce38a4fe21fd41cda7e6dbf55be
F test/async2.test 8998e089b0fbb3d84cdd51c25a78833486d721af
@@ -215,9 +219,10 @@ F test/async3.test 9ffa0977a78cc6351862a1583be2b1eecd41736d
F test/attach.test 75a5d22f88e730967d68f2c9f95e786e3953d8e3
F test/attach2.test a295d2d7061adcee5884ef4a93c7c96a82765437
F test/attach3.test 7b92dc8e40c1ebca9732ca6f2d3fefbd46f196df
F test/attachmalloc.test ccbde53bcb0a61020afa3e0670ca9c6c5b99af32
F test/auth.test 9eb4b6b99eee54c95711c74c4b9694acf4d850ed
F test/attachmalloc.test cf8cf17d183de357b1147a9baacbdfc85b940b61
F test/auth.test 0e901aeb399f766fd58f5e19b8b9a09e2df9a341
F test/auth2.test ee3ba272e2b975e913afc9b041ee75706e190005
F test/auth3.test b3308950d3839a45193cdcd0473432e33fe38b61
F test/autoinc.test ab549b48b389cabd92967b86c379ec8b31fa6c16
F test/autovacuum.test 61260e25744189ff766f61ca3df23c1eeec0060e
F test/autovacuum_ioerr2.test 598b0663074d3673a9c1bc9a16e80971313bafe6
@@ -226,18 +231,18 @@ F test/badutf.test d5360fc31f643d37a973ab0d8b4fb85799c3169f
F test/between.test 16b1776c6323faadb097a52d673e8e3d8be7d070
F test/bigfile.test 9a6a8346e4042d9c781ed6cb6553ac871ae30618
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
F test/bind.test b5e3ffbad2b43b7cf675dd3624176510d8379978
F test/bindxfer.test 995d2cf8df61204d748cde6960443121c4ccd2e1
F test/bitvec.test 62a512c3f7041d1df12558eb25990e5a19820571
F test/bind.test 1134441f1ea47abd1c740090435a6ecbe9ceb263
F test/bindxfer.test d4f573750e06c34ef2309acb95ad57da1d3c983f
F test/bitvec.test ecea9aa315f36991e56e326701279b7775cb2bef
F test/blob.test 2a38d867bdf08f9ce081776acec1ac8d4bca66be
F test/busy.test 76b4887f8b9160ba903c1ac22e8ff406ad6ae2f0
F test/cache.test 3ff445c445742a7b6b9ba6e1d62a25263f9424b9
F test/capi2.test 36f87803c811b5986dd31eb5492cb704552776b4
F test/capi3.test ffc1156d1f28738eb335df0b88dd294bb3c94c27
F test/capi3.test 4d9c110e8c78fdfe0ea61171a17609e627630ca6
F test/capi3b.test 664eb55318132f292f2c436f90906f578cad6b97
F test/capi3c.test 208713e5f3a63442c3574c55b83baa7cf8ac5f28
F test/capi3c.test ce0fcbbaccfc9703fb247ea9ac5ada96dc9ca047
F test/capi3d.test 57d83b690d7364bde02cddbf8339a4b50d80ce23
F test/cast.test ce8f14fc80f70b30ed984480cc0d8914a459e8f9
F test/cast.test 166951664a0b0a2e0f8fb5997a152490c6363932
F test/check.test 024ed399600b799160378cf9d9f436bdf5dfd184
F test/collate1.test e3eaa48c21e150814be1a7b852d2a8af24458d04
F test/collate2.test 04cebe4a033be319d6ddbb3bbc69464e01700b49
@@ -250,10 +255,10 @@ F test/collate8.test df26649cfcbddf109c04122b340301616d3a88f6
F test/collate9.test 3adcc799229545940df2f25308dd1ad65869145a
F test/collateA.test b8218ab90d1fa5c59dcf156efabb1b2599c580d6
F test/colmeta.test 087c42997754b8c648819832241daf724f813322
F test/colname.test 0f05fea3e5c9260ece53117ad400657515c34280
F test/colname.test 69fea30632d55862a012d3786c7d5fd1329f78db
F test/conflict.test bb29b052c60a1f7eb6382be77902061d1f305318
F test/corrupt.test 5bcf7a986358123b8055dfa64b45fc2fb54dcaa9
F test/corrupt2.test 08fb049fdf4f72902ff39b1c609e7c1c2e985d8b
F test/corrupt2.test b83f690753525ddac4a9c96e6ba11886ddaf24ea
F test/corrupt3.test 263e8bb04e2728df832fddf6973cf54c91db0c32
F test/corrupt4.test acdb01afaedf529004b70e55de1a6f5a05ae7fff
F test/corrupt5.test 7796d5bdfe155ed824cee9dff371f49da237cfe0
@@ -263,6 +268,7 @@ F test/corrupt8.test 9992ef7f67cefc576b92373f6bf5ab8775280f51
F test/corrupt9.test 794d284109c65c8f10a2b275479045e02d163bae
F test/corruptA.test 99e95620b980161cb3e79f06a884a4bb8ae265ff
F test/corruptB.test 505331779fe7a96fe38ecbb817f19c63bc27d171
F test/corruptC.test c798aa395a8d052fba88bd1be8e1945309e3f94a
F test/crash.test 1b6ac8410689ff78028887f445062dc897c9ac89
F test/crash2.test 5b14d4eb58b880e231361d3b609b216acda86651
F test/crash3.test 776f9363554c029fcce71d9e6600fa0ba6359ce7
@@ -286,14 +292,14 @@ F test/distinctagg.test 2b89d1c5220d966a30ba4b40430338669301188b
F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398
F test/enc3.test 5c550d59ff31dccdba5d1a02ae11c7047d77c041
F test/eval.test 020a21a236667bd4c56205d999c9992f1d944cac
F test/exclusive.test 5390ddf1f90a6d055111c0ebe6311045dd3035e1
F test/eval.test bc269c365ba877554948441e91ad5373f9f91be3
F test/exclusive.test 8d32ccf8eaf0260977dc8406bd70080ca2d7e6f8
F test/exclusive2.test 7d2b1c0370f1e1dac4a728bd653f2dea5100fcf6
F test/exec.test e949714dc127eaa5ecc7d723efec1ec27118fdd7
F test/expr.test 135ed46c049916688171e618c5c14312811618d4
F test/filectrl.test 524853082d5d7fb442599730ec3a0f3f84a3a936
F test/filefmt.test 053b622009fbbb74dd37921ffad374d852c13cd8
F test/fkey1.test dcb4f28eb22d5141f15161d6bdca9a4f58c95729
F test/fkey1.test c373e4f1ec43416957e0591c4a5cebb63b8a12e7
F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb
F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7
F test/fts1b.test 5d8a01aefbecc8b7442b36c94c05eb7a845462d5
@@ -351,7 +357,7 @@ F test/fts3c.test 4c7ef29b37aca3e8ebb6a39b57910caa6506034e
F test/fts3d.test d92a47fe8ed59c9e53d2d8e6d2685bb380aadadc
F test/fts3e.test 1f6c6ac9cc8b772ca256e6b22aaeed50c9350851
F test/fts3near.test e8a9b4e16c63a795918b334b74d4aec14815bf8b
F test/func.test 628dc9b321fc66dd6d055fca6525e157004744e1
F test/func.test a50f0a4b69ac251debe1dce3ba29da7476dc8c52
F test/fuzz.test 62fc19dd36a427777fd671b569df07166548628a
F test/fuzz2.test ea38692ce2da99ad79fe0be5eb1a452c1c4d37bb
F test/fuzz3.test 3856b9340b801671424ff0c581ef74342962aa7d
@@ -362,8 +368,9 @@ F test/icu.test f51d0f4407ff8bb1e872f51a0e8b08fdc5a6897e
F test/in.test d49419c6df515852f477fa513f3317181d46bc92
F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75
F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0
F test/incrblob.test e50cf41ac64e76ca4f8881ecb8d28fd988503ad5
F test/incrblob2.test c82a780356bdf4d0c77f1adf0ea888248904fc07
F test/in4.test c043f75147295e9f6ad5040a5cda2c485736c2c8
F test/incrblob.test 4b9437bbb38724343dadbbcca6356bc2a9b435d1
F test/incrblob2.test 5cca1c3cb29064c504b3b0cc3e2cd43e8053cfdf
F test/incrblob_err.test c577c91d4ed9e8336cdb188b15d6ee2a6fe9604e
F test/incrvacuum.test 9a6346c56ffa141024054ae7ba6c8655edf2d137
F test/incrvacuum2.test 46ef65f377e3937cfd1ba66e818309dab46f590d
@@ -371,6 +378,7 @@ F test/incrvacuum_ioerr.test 57d2f5777ab13fa03b87b262a4ea1bad5cfc0291
F test/index.test cbf301cdb2da43e4eac636c3400c2439af1834ad
F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
F test/index3.test 727d55dceb9a4ec36675057bb5becfc265e28ca6
F test/indexedby.test 03af52375e50d146e78f56442b6677d2932c4963
F test/insert.test aef273dd1cee84cc92407469e6bd1b3cdcb76908
F test/insert2.test 4f3a04d168c728ed5ec2c88842e772606c7ce435
F test/insert3.test 9a4ef3526fd3cca8b05278020ec3100448b4c677
@@ -390,23 +398,23 @@ F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
F test/join5.test 86675fc2919269aa923c84dd00ee4249b97990fe
F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19
F test/jrnlmode.test 1ab9729d6bbb6fb355cbb4bb41f1f0c271fc251a
F test/jrnlmode.test c4e4e40afdb6a128957e1f8ee404c8d670c4ce6f
F test/lastinsert.test 474d519c68cb79d07ecae56a763aa7f322c72f51
F test/laststmtchanges.test 18ead86c8a87ade949a1d5658f6dc4bb111d1b02
F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200
F test/like.test fef924922828d5a2a5bff80b9bdd9ff57a1ca500
F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da
F test/limit.test 2db7b3b34fb925b8e847d583d2eb67531d0ce67e
F test/loadext.test 4972cb5a12ba70f23f827452b8265be08bb6d8cd
F test/loadext.test 18db29c081380fdedcfbd8c633847712059ae104
F test/loadext2.test 0bcaeb4d81cd5b6e883fdfea3c1bdbe1f173cbca
F test/lock.test 6825aea0b5885578b1b63a3b178803842c4ee9f1
F test/lock2.test 018b846f6f3b3b695fad07e317b7988442b556f4
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
F test/lock4.test 09d97d52cae18fadfe631552af9880dac6b3ae90
F test/lock5.test f4eeb0400cf65c37f733cb3c74401136f8c46acd
F test/lookaside.test 8866ea41301d74993423c99e523322fca09c259e
F test/lock5.test 904c20aec51d5dbff0a3aec6a4d35c5ae0257449
F test/lookaside.test e69f822f13745f1d5c445c6e30e30f059f30c8e5
F test/main.test 187a9a1b5248ed74a83838c581c15ec6023b555b
F test/malloc.test cdc0bb8675b972f56bffdb48e7d52a18500ff66f
F test/malloc3.test 094f8195fe8e409bd4da0f1d769f7745faec62c8
F test/malloc.test 248fc5e0be632d8db1d771ed5413a93c47212c5a
F test/malloc3.test 4bc57f850b212f706f3e1b37c4eced1d5a727cd1
F test/malloc4.test 957337613002b7058a85116493a262f679f3a261
F test/malloc5.test c8d0f7673337e8a29afa558735ae937a0d629751
F test/malloc6.test 2f039d9821927eacae43e1831f815e157659a151
@@ -423,11 +431,12 @@ F test/mallocF.test 2d5c590ebc2fc7f0dcebdf5aa8498b9aed69107e
F test/mallocG.test 4584d0d8ddb8009f16ca0c8bab1fa37f6358efa2
F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb
F test/mallocI.test 6e24fe6444bd2999ccc81f984977b44c0d6e5591
F test/malloc_common.tcl e082fe4791dad22b49d2ad3f7dcf1dcbee1a4cec
F test/mallocJ.test 44dfbbaca731cb933818ad300b4566265d652609
F test/malloc_common.tcl 984baeb6c6b185e798827d1187d426acc2bc4962
F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
F test/memleak.test d2d2a1ff7105d32dc3fdf691458cf6cba58c7217
F test/memsubsys1.test c12d1e4ad7f0ec7a45b56b5c49fe7397fa8d6d8f
F test/memsubsys1.test bdc24a38d198679d777ca4efcc089fd3948567a6
F test/memsubsys2.test 72a731225997ad5e8df89fdbeae9224616b6aecc
F test/minmax.test 722d80816f7e096bf2c04f4111f1a6c1ba65453d
F test/minmax2.test 33504c01a03bd99226144e4b03f7631a274d66e0
@@ -438,32 +447,32 @@ F test/misc3.test 7212ed8dad01427e9acab9bd3e7e5e2c2e89be9e
F test/misc4.test 91e8ed25c092c2bb4e0bb01864631e2930f8d7de
F test/misc5.test 6a5c1e3217a95b0db05ff9a0f1ecb5ce9043ffef
F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
F test/misc7.test 0d763f703a34521e55ab30145b747aafa0e5f794
F test/misc7.test edbbe77d48c7d70a60f8c33e2c7d182ca25f0181
F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
F test/mutex1.test dbcf556502389abcca65a80af45b80c141714ccc
F test/mutex2.test 56f282f436596e9febdc6e0db2c507432b6724bb
F test/mutex1.test 820bf4a91af8cf3c9aa63c261d6c65e07b3705b9
F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660
F test/nan.test c627d79b3d36ea892563fd67584b3e8a18f0618a
F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82
F test/null.test a8b09b8ed87852742343b33441a9240022108993
F test/openv2.test f5dd6b23e4dce828eb211649b600763c42a668df
F test/pager.test 1e1832795e9e07a359c959ffdddcf7275a88f54c
F test/pager2.test 070983b89a308adaba525a2f9c1ba0592c72fa3d
F test/pager.test fd3f5009985728ef7bf0dfe32a1bbc112e6895c5
F test/pager2.test d84c59ae4a803e03d19d72cbb5b14c71850c6163
F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
F test/pageropt.test 3ee6578891baaca967f0bd349e4abfa736229e1a
F test/pagesize.test 0d9ff3fedfce6e5ffe8fa7aca9b6d3433a2e843b
F test/pcache.test 515b4c26e9f57660357dfff5b6b697acac1abc5f
F test/pcache2.test 2b4fa1bee5cfc338d8c04eb6ed7eaf41f478bf7c
F test/permutations.test 41832b86c152c140bcdf75a35a7c82badd8912b9
F test/pragma.test c86359a8e0b28abdcc0ff4936f7966c446d0479a
F test/pcache2.test 46efd980a89f737847b99327bda19e08fe11e402
F test/permutations.test 5308a94878efc81a8e8ce133926dfb2c53d19133
F test/pragma.test 165372b62391d233715cde82d99f34d306f9257f
F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
F test/printf.test 262a5acd3158f788e9bdf7f18d718f3af32ff6ef
F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x
F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc
F test/quick.test bbaa1fbdac766cab2219d5599e9cd5bc2614d01e
F test/quick.test 70695607082b3e1ca54023b2c856991604b07703
F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
F test/rdonly.test bd054831f8a3078e765a0657e247182486f0cb47
F test/reindex.test 44edd3966b474468b823d481eafef0c305022254
F test/rollback.test 0bd29070ba2f76da939347773fbda53337ebd61c
F test/rollback.test 1f70ab4301d8d105d41438a436cad1fc8897f5e5
F test/rowid.test 1c8fc43c60d273e6ea44dfb992db587f3164312c
F test/rtree.test b85fd4f0861a40ca366ac195e363be2528dcfadf
F test/safety.test b69e2b2dd5d52a3f78e216967086884bbc1a09c6
@@ -486,15 +495,15 @@ F test/shared.test b9f3bbd3ba727c5f1f8c815b7d0199262aacf214
F test/shared2.test 0ee9de8964d70e451936a48c41cb161d9134ccf4
F test/shared3.test 9c880afc081d797da514ef64bccf36f3fce2f09c
F test/shared4.test d0fadacb50bb6981b2fb9dc6d1da30fa1edddf83
F test/shared_err.test 63628d33e0d59325c63650f5d67f4c8798cef5db
F test/shared_err.test 91e26ec4f3fbe07951967955585137e2f18993de
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329
F test/soak.test 3c317b3e55e1160731030c8e865d1858fab66fea
F test/soak.test d9d0a5e5c0157115c9a17f526f12691fe146768d
F test/softheap1.test 73ebd6e020d2954d965da2072baba5922fc8fb6a
F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
F test/speed1.test 155493358a9aa96b61e51ba546dc80c7ce501251
F test/speed1.test c74564fea46e094d6b518bf464c355991905eea2
F test/speed1p.explain d841e650a04728b39e6740296b852dccdca9b2cb
F test/speed1p.test a656e04f07e6f7ba55d031e8287abdefa48ddbd7
F test/speed1p.test 7f046639ffd70e6b1deb38684ef2208a43b45df3
F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded
F test/speed3.test e312d7e442a5047d730569fdae2ba99bc94e1a13
F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715
@@ -507,15 +516,15 @@ F test/substr.test 4be572ac017143e59b4058dc75c91a0d0dc6d4e0
F test/sync.test ded6b39d8d8ca3c0c5518516c6371b3316d3e3a3
F test/table.test 13b1c2e2fb4727b35ee1fb7641fc469214fd2455
F test/tableapi.test 505031f15b18a750184d967d2c896cf88fcc969c
F test/tclsqlite.test b2074cf37a6f7b3fb0544a7bac7bc8ff3ac6ea77
F test/tclsqlite.test 001682e3c188967fbd790c617991efadf9518386
F test/tempdb.test b88ac8a19823cf771d742bf61eef93ef337c06b1
F test/temptable.test 19b851b9e3e64d91e9867619b2a3f5fffee6e125
F test/tester.tcl 12fd8394caeb71f7d961707da8668756389bc9d3
F test/thread001.test 3fb08080e1fe84d1bb7ec7bbc9e13743a77e5bc5
F test/thread002.test ed9b800460df01e3cf9428ee11dc4e3f04b9b896
F test/thread003.test 047fb3b971f5dac856d34394186bf8a4bdd39e3e
F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
F test/thread2.test 6d7b30102d600f51b4055ee3a5a19228799049fb
F test/thread001.test dda1d39cea954d7d43f520891d77a93d3325ab58
F test/thread002.test 84c03a9fc4f7a5f92eefe551266afa840c2eb6ae
F test/thread003.test e17754799649c2b732c295620dca041c32f01e16
F test/thread1.test 862dd006d189e8b0946935db17399dcac2f8ef91
F test/thread2.test 91f105374f18a66e73a3254c28fe7c77af69bdea
F test/thread_common.tcl 8a9d7a4500dfdbbd36679c977831b62c130b76b1
F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
F test/threadtest2.c ace893054fa134af3fc8d6e7cfecddb8e3acefb9
@@ -555,7 +564,7 @@ F test/tkt2854.test a2bc584ac26bcebe174229e7a1ad4e6d43c3d569
F test/tkt2920.test a8737380e4ae6424e00c0273dc12775704efbebf
F test/tkt2927.test 4752868b9eeeb07a217f7f19f4cbaac98d6d086d
F test/tkt2942.test c5c87d179799ca6d1fbe83c815510b87cd5ec7ce
F test/tkt3080.test 31a02e87a4c80ed443831c2c5b0e8216ff95ac14
F test/tkt3080.test 1bca7579260920a66b4dd7e196e807c0f25ff804
F test/tkt3093.test fbdbc5b4969244ad11f540759003e361fcaf391f
F test/tkt3121.test 536df66a02838c26a12fe98639354ca1290ca68b
F test/tkt3201.test 607d433ad2c1f6a8cb1af55aaca427f63c83191b
@@ -564,11 +573,19 @@ F test/tkt3298.test a735582095ca2e90a0c1391c7e781a90de6c1f34
F test/tkt3334.test ea13a53cb176e90571a76c86605b14a09efe366d
F test/tkt3346.test 2f9a2be8621a87cbdb6283177dd419c7c46dd2a1
F test/tkt3357.test b37a51a12ba5e143d6714778276438606f8f9e27
F test/tkt3419.test 1bbf36d7ea03b638c15804251287c2391f5c1f6b
F test/tkt3424.test 3171193ce340cff6b7ea81c03b8fa1cbc34ec36e
F test/tkt3442.test 33722a3fa4bdc0614448044eb5e28765aea28eb7
F test/tkt3457.test e9ca2b90f0eb1fb8be73a30d29aacb2e3abedeb9
F test/tkt3461.test 5a63e8d8ee5ce00f076b1e2f82aba5480a0f14ed
F test/tkt3472.test e689a687631e59c7a47d9438148115fee23b16c3
F test/tkt3493.test 8472b3464e49a27ff7271308eec46154209e667b
F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
F test/trace.test 951cd0f5f571e7f36bf7bfe04be70f90fb16fb00
F test/trans.test 2fd24cd7aa0b879d49a224cbd647d698f1e7ac5c
F test/trans2.test d5337e61de45e66b1fcbf9db833fa8c82e624b22
F test/trigger1.test 7c13f39ca36f529bf856e05c7d004fc0531d48b4
F test/trans3.test d728abaa318ca364dc370e06576aa7e5fbed7e97
F test/trigger1.test 53342dfd582155a599518f1918fdc997e9413177
F test/trigger2.test 33bf8ae9b788013be194efe5f66c04a202facbb4
F test/trigger3.test 501b8489eb6b9cb5b005f60b071583c01a3c3041
F test/trigger4.test 8e90ee98cba940cd5f96493f82e55083806ab8a0
@@ -584,15 +601,15 @@ F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84
F test/types3.test a0f66bf12f80fad89493535474f7a6d16fa58150
F test/unique.test 0253c4227a5dc533e312202ce21ecfad18058d18
F test/update.test 8bc86fd7ef1a00014f76dc6a6a7c974df4aef172
F test/utf16align.test 7360e84472095518c56746f76b1f9d4dce99fb4d
F test/utf16align.test 54cd35a27c005a9b6e7815d887718780b6a462ae
F test/vacuum.test 0bc75ee74ab9c69322d6563aa2287375697e630b
F test/vacuum2.test e7c5f5bf5e1f2266ca668d420393820cf501fdfc
F test/vacuum2.test fd87eec0ed72c6cc0809f7867929e2895affed92
F test/vacuum3.test f39ad1428347c5808cd2da7578c470f186a4d0ce
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
F test/veryquick.test e265401afefa994cdf2fe4b6f286b1e87c2f9b9d
F test/view.test 7fba28a47f76541f6aea9542f62f3412e3519bad
F test/vtab1.test e321e3c80434fe8de97fa4ad815882d2c7838d21
F test/vtab2.test 1da49b015582965a8fc386aa23d051a5a622b08e
F test/vtab2.test 7bcffc050da5c68f4f312e49e443063e2d391c0d
F test/vtab3.test baad99fd27217f5d6db10660522e0b7192446de1
F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275
F test/vtab5.test a0a84a89c622f4e2e816ebf39883dc319b4a1024
@@ -606,25 +623,30 @@ F test/vtabC.test 9f2d9eb84bf65e606d6616f20977c5a32a11f548
F test/vtab_alter.test 3a299749fee97ca3d53bd55717f536e4a2284856
F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
F test/vtab_shared.test c19b2555b807ef2ee014c882cdda5bc8d84fcf48
F test/where.test ea8e56f3c7b18fa4d250d32a08ffab44c0ff64ba
F test/where2.test 7012c0ad022a54430dd22c98288d3f4d6599dbcf
F test/where.test de337a3fe0a459ec7c93db16a519657a90552330
F test/where2.test e446f55417f434929522d87164cd1473d54f10e2
F test/where3.test 97d3936e6a443b968f1a61cdcc0f673252000e94
F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
F test/where6.test 42c4373595f4409d9c6a9987b4a60000ad664faf
F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31
F test/zeroblob.test 792124852ec61458a2eb527b5091791215e0be95
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439
F tool/genfkey.README 080ca2269f727fcf14c8e76d52e85d157e3a8e9a
F tool/genfkey.c e1b9c93da828db10c1109c7b4fa611aec8adc407
F tool/genfkey.test 182829596fb15785b94b2493c5f735b847d91076
F tool/lemon.c 6cb39632ef3bfec2cea8f81b4d7f63c09fe12802
F tool/lempar.c 770dc64b74429daf9611676f43bfbd7c1bed0152
F tool/lempar.c 9ef6809804f9066fa94a0bdc02224ce015951843
F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133
F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
F tool/memleak3.tcl 7707006ee908cffff210c98158788d85bb3fcdbf
F tool/mkkeywordhash.c ef93810fc41fb3d3dbacf9a33a29be88ea99ffa9
F tool/mkkeywordhash.c c219ee2b8b5b8e7011cccfa1caec62d9812e82e7
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
F tool/mksqlite3c.tcl 370dca60b92731699887f92e0b1e69f8732a79eb
F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
F tool/mksqlite3c.tcl 619c0629ac51f670f1f522cd0ab1fbb62ca97d45
F tool/mksqlite3internalh.tcl 7b43894e21bcb1bb39e11547ce7e38a063357e87
F tool/omittest.tcl 4be55add3ec87f45fe041b7bfa8f16dab8105431
F tool/omittest.tcl 27d6f6e3b1e95aeb26a1c140e6eb57771c6d794a
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
F tool/showdb.c a086a3d788c7a23cb008317c3180ceb19f20bce0
@@ -635,9 +657,9 @@ F tool/spaceanal.tcl b87db46ae29e3116411b1686e136b9b994d7de39
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 915679431a70c593a83cf5e8b1dcce1555e9518e
R 04d214daa28a8779c3e21d3d214f0f79
P 15d88edf7671822c57238c3f85adf0b40b13e3e2
R d2ce2d5b91c1f6ae4cf2c6a18038f9fd
U drh
Z f2e5c0e22e4c94edc3b9d5fe99da766d
Z d6e85c23f6cca1b4a3eb502f6411e7b2
+1 -1
View File
@@ -1 +1 @@
1634fd223d65a6ad461f79ca922b5ef967ae763d
c2266aa094411346a73ab704c03ec919d6e5f46d
+1
View File
@@ -13,6 +13,7 @@ TCLSTUBLIB=$TCLDIR/libtcl84stub.a
OPTS='-DUSE_TCL_STUBS=1 -DBUILD_sqlite=1 -DSQLITE_OS_WIN=1'
OPTS="$OPTS -DSQLITE_THREADSAFE=1"
OPTS="$OPTS -DSQLITE_ENABLE_FTS3=1"
OPTS="$OPTS -DSQLITE_ENABLE_RTREE=1"
OPTS="$OPTS -DSQLITE_ENABLE_COLUMN_METADATA=1"
CC="i386-mingw32msvc-gcc -Os $OPTS -Itsrc -I$TCLDIR"
NM="i386-mingw32msvc-nm"
+1 -1
View File
@@ -7,7 +7,7 @@ includedir=@includedir@
Name: SQLite
Description: SQL database engine
Version: @VERSION@
Version: @RELEASE@
Libs: -L${libdir} -lsqlite
Libs.private: @LIBS@
Cflags: -I${includedir}
+1 -1
View File
@@ -7,7 +7,7 @@ includedir=@includedir@
Name: SQLite
Description: SQL database engine
Version: @VERSION@
Version: @RELEASE@
Libs: -L${libdir} -lsqlite3
Libs.private: @LIBS@
Cflags: -I${includedir}
+9 -6
View File
@@ -12,7 +12,7 @@
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
**
** $Id: alter.c,v 1.48 2008/08/08 14:19:41 drh Exp $
** $Id: alter.c,v 1.50 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -39,7 +39,7 @@
*/
static void renameTableFunc(
sqlite3_context *context,
int argc,
int NotUsed,
sqlite3_value **argv
){
unsigned char const *zSql = sqlite3_value_text(argv[0]);
@@ -53,6 +53,8 @@ static void renameTableFunc(
sqlite3 *db = sqlite3_context_db_handle(context);
UNUSED_PARAMETER(NotUsed);
/* The principle used to locate the table name in the CREATE TABLE
** statement is that the table name is the first non-space token that
** is immediately followed by a TK_LP or TK_USING token.
@@ -94,7 +96,7 @@ static void renameTableFunc(
*/
static void renameTriggerFunc(
sqlite3_context *context,
int argc,
int NotUsed,
sqlite3_value **argv
){
unsigned char const *zSql = sqlite3_value_text(argv[0]);
@@ -106,9 +108,10 @@ static void renameTriggerFunc(
unsigned char const *zCsr = zSql;
int len = 0;
char *zRet;
sqlite3 *db = sqlite3_context_db_handle(context);
UNUSED_PARAMETER(NotUsed);
/* The principle used to locate the table name in the CREATE TRIGGER
** statement is that the table name is the first token that is immediatedly
** preceded by either TK_ON or TK_DOT and immediatedly followed by one
@@ -441,11 +444,11 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
Expr *pDflt; /* Default value for the new column */
sqlite3 *db; /* The database connection; */
if( pParse->nErr ) return;
db = pParse->db;
if( pParse->nErr || db->mallocFailed ) return;
pNew = pParse->pNewTable;
assert( pNew );
db = pParse->db;
assert( sqlite3BtreeHoldsAllMutexes(db) );
iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
zDb = db->aDb[iDb].zName;
+6 -4
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
** @(#) $Id: analyze.c,v 1.43 2008/07/28 19:34:53 drh Exp $
** @(#) $Id: analyze.c,v 1.46 2008/11/19 16:52:44 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_ANALYZE
#include "sqliteInt.h"
@@ -86,11 +86,11 @@ static void openStatTable(
static void analyzeOneTable(
Parse *pParse, /* Parser context */
Table *pTab, /* Table whose indices are to be analyzed */
int iStatCur, /* Cursor that writes to the sqlite_stat1 table */
int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */
int iMem /* Available memory locations begin here */
){
Index *pIdx; /* An index to being analyzed */
int iIdxCur; /* Cursor number for index being analyzed */
int iIdxCur; /* Index of VdbeCursor for index being analyzed */
int nCol; /* Number of columns in the index */
Vdbe *v; /* The virtual machine being built up */
int i; /* Loop counter */
@@ -356,7 +356,7 @@ struct analysisInfo {
** argv[0] = name of the index
** argv[1] = results of analysis - on integer for each column
*/
static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){
static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
analysisInfo *pInfo = (analysisInfo*)pData;
Index *pIndex;
int i, c;
@@ -364,6 +364,8 @@ static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){
const char *z;
assert( argc==2 );
UNUSED_PARAMETER2(NotUsed, argc);
if( argv==0 || argv[0]==0 || argv[1]==0 ){
return 0;
}
+36 -22
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.78 2008/08/20 16:35:10 drh Exp $
** $Id: attach.c,v 1.80 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -64,7 +64,7 @@ static int resolveAttachExpr(NameContext *pName, Expr *pExpr)
*/
static void attachFunc(
sqlite3_context *context,
int argc,
int NotUsed,
sqlite3_value **argv
){
int i;
@@ -76,6 +76,8 @@ static void attachFunc(
char *zErrDyn = 0;
char zErr[128];
UNUSED_PARAMETER(NotUsed);
zFile = (const char *)sqlite3_value_text(argv[0]);
zName = (const char *)sqlite3_value_text(argv[1]);
if( zFile==0 ) zFile = "";
@@ -232,7 +234,7 @@ attach_error:
*/
static void detachFunc(
sqlite3_context *context,
int argc,
int NotUsed,
sqlite3_value **argv
){
const char *zName = (const char *)sqlite3_value_text(argv[0]);
@@ -241,6 +243,8 @@ static void detachFunc(
Db *pDb = 0;
char zErr[128];
UNUSED_PARAMETER(NotUsed);
if( zName==0 ) zName = "";
for(i=0; i<db->nDb; i++){
pDb = &db->aDb[i];
@@ -283,8 +287,7 @@ detach_error:
static void codeAttach(
Parse *pParse, /* The parser context */
int type, /* Either SQLITE_ATTACH or SQLITE_DETACH */
const char *zFunc, /* Either "sqlite_attach" or "sqlite_detach */
int nFunc, /* Number of args to pass to zFunc */
FuncDef *pFunc, /* FuncDef wrapper for detachFunc() or attachFunc() */
Expr *pAuthArg, /* Expression to pass to authorization callback */
Expr *pFilename, /* Name of database file */
Expr *pDbname, /* Name of the database to use internally */
@@ -293,7 +296,6 @@ static void codeAttach(
int rc;
NameContext sName;
Vdbe *v;
FuncDef *pFunc;
sqlite3* db = pParse->db;
int regArgs;
@@ -332,9 +334,8 @@ static void codeAttach(
assert( v || db->mallocFailed );
if( v ){
sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-nFunc, regArgs+3);
sqlite3VdbeChangeP5(v, nFunc);
pFunc = sqlite3FindFunction(db, zFunc, strlen(zFunc), nFunc, SQLITE_UTF8,0);
sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);
sqlite3VdbeChangeP5(v, pFunc->nArg);
sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);
/* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
@@ -356,7 +357,19 @@ attach_end:
** DETACH pDbname
*/
void sqlite3Detach(Parse *pParse, Expr *pDbname){
codeAttach(pParse, SQLITE_DETACH, "sqlite_detach", 1, pDbname, 0, 0, pDbname);
static FuncDef detach_func = {
1, /* nArg */
SQLITE_UTF8, /* iPrefEnc */
0, /* flags */
0, /* pUserData */
0, /* pNext */
detachFunc, /* xFunc */
0, /* xStep */
0, /* xFinalize */
"sqlite_detach", /* zName */
0 /* pHash */
};
codeAttach(pParse, SQLITE_DETACH, &detach_func, pDbname, 0, 0, pDbname);
}
/*
@@ -365,21 +378,22 @@ void sqlite3Detach(Parse *pParse, Expr *pDbname){
** ATTACH p AS pDbname KEY pKey
*/
void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
codeAttach(pParse, SQLITE_ATTACH, "sqlite_attach", 3, p, p, pDbname, pKey);
static FuncDef attach_func = {
3, /* nArg */
SQLITE_UTF8, /* iPrefEnc */
0, /* flags */
0, /* pUserData */
0, /* pNext */
attachFunc, /* xFunc */
0, /* xStep */
0, /* xFinalize */
"sqlite_attach", /* zName */
0 /* pHash */
};
codeAttach(pParse, SQLITE_ATTACH, &attach_func, p, p, pDbname, pKey);
}
#endif /* SQLITE_OMIT_ATTACH */
/*
** Register the functions sqlite_attach and sqlite_detach.
*/
void sqlite3AttachFunctions(sqlite3 *db){
#ifndef SQLITE_OMIT_ATTACH
static const int enc = SQLITE_UTF8;
sqlite3CreateFunc(db, "sqlite_attach", 3, enc, 0, attachFunc, 0, 0);
sqlite3CreateFunc(db, "sqlite_detach", 1, enc, 0, detachFunc, 0, 0);
#endif
}
/*
** Initialize a DbFixer structure. This routine must be called prior
** to passing the structure to one of the sqliteFixAAAA() routines below.
+118 -55
View File
@@ -12,12 +12,14 @@
** This file implements an object that represents a fixed-length
** bitmap. Bits are numbered starting with 1.
**
** A bitmap is used to record what pages a database file have been
** journalled during a transaction. Usually only a few pages are
** journalled. So the bitmap is usually sparse and has low cardinality.
** A bitmap is used to record which pages of a database file have been
** journalled during a transaction, or which pages have the "dont-write"
** property. Usually only a few pages are meet either condition.
** So the bitmap is usually sparse and has low cardinality.
** But sometimes (for example when during a DROP of a large table) most
** or all of the pages get journalled. In those cases, the bitmap becomes
** dense. The algorithm needs to handle both cases well.
** or all of the pages in a database can get journalled. In those cases,
** the bitmap becomes dense with high cardinality. The algorithm needs
** to handle both cases well.
**
** The size of the bitmap is fixed when the object is created.
**
@@ -32,21 +34,42 @@
** start of a transaction, and is thus usually less than a few thousand,
** but can be as large as 2 billion for a really big database.
**
** @(#) $Id: bitvec.c,v 1.6 2008/06/20 14:59:51 danielk1977 Exp $
** @(#) $Id: bitvec.c,v 1.9 2008/11/19 18:30:35 shane Exp $
*/
#include "sqliteInt.h"
/* Size of the Bitvec structure in bytes. */
#define BITVEC_SZ 512
/* Round the union size down to the nearest pointer boundary, since that's how
** it will be aligned within the Bitvec struct. */
#define BITVEC_USIZE (((BITVEC_SZ-12)/sizeof(Bitvec*))*sizeof(Bitvec*))
#define BITVEC_NCHAR BITVEC_USIZE
#define BITVEC_NBIT (BITVEC_NCHAR*8)
#define BITVEC_NINT (BITVEC_USIZE/4)
#define BITVEC_USIZE (((BITVEC_SZ-(3*sizeof(u32)))/sizeof(Bitvec*))*sizeof(Bitvec*))
/* Type of the array "element" for the bitmap representation.
** Should be a power of 2, and ideally, evenly divide into BITVEC_USIZE.
** Setting this to the "natural word" size of your CPU may improve
** performance. */
#define BITVEC_TELEM u8
/* Size, in bits, of the bitmap element. */
#define BITVEC_SZELEM 8
/* Number of elements in a bitmap array. */
#define BITVEC_NELEM (BITVEC_USIZE/sizeof(BITVEC_TELEM))
/* Number of bits in the bitmap array. */
#define BITVEC_NBIT (BITVEC_NELEM*BITVEC_SZELEM)
/* Number of u32 values in hash table. */
#define BITVEC_NINT (BITVEC_USIZE/sizeof(u32))
/* Maximum number of entries in hash table before
** sub-dividing and re-hashing. */
#define BITVEC_MXHASH (BITVEC_NINT/2)
/* Hashing function for the aHash representation.
** Empirical testing showed that the *37 multiplier
** (an arbitrary prime)in the hash function provided
** no fewer collisions than the no-op *1. */
#define BITVEC_HASH(X) (((X)*1)%BITVEC_NINT)
#define BITVEC_NPTR (BITVEC_USIZE/sizeof(Bitvec *))
#define BITVEC_HASH(X) (((X)*37)%BITVEC_NINT)
/*
** A bitmap is an instance of the following structure.
@@ -70,11 +93,15 @@
** to hold deal with values between 1 and iDivisor.
*/
struct Bitvec {
u32 iSize; /* Maximum bit index */
u32 nSet; /* Number of bits that are set */
u32 iDivisor; /* Number of bits handled by each apSub[] entry */
u32 iSize; /* Maximum bit index. Max iSize is 4,294,967,296. */
u32 nSet; /* Number of bits that are set - only valid for aHash element */
/* Max nSet is BITVEC_NINT. For BITVEC_SZ of 512, this would be 125. */
u32 iDivisor; /* Number of bits handled by each apSub[] entry. */
/* Should >=0 for apSub element. */
/* Max iDivisor is max(u32) / BITVEC_NPTR + 1. */
/* For a BITVEC_SZ of 512, this would be 34,359,739. */
union {
u8 aBitmap[BITVEC_NCHAR]; /* Bitmap representation */
BITVEC_TELEM aBitmap[BITVEC_NELEM]; /* Bitmap representation */
u32 aHash[BITVEC_NINT]; /* Hash table representation */
Bitvec *apSub[BITVEC_NPTR]; /* Recursive representation */
} u;
@@ -103,16 +130,19 @@ Bitvec *sqlite3BitvecCreate(u32 iSize){
int sqlite3BitvecTest(Bitvec *p, u32 i){
if( p==0 ) return 0;
if( i>p->iSize || i==0 ) return 0;
if( p->iSize<=BITVEC_NBIT ){
i--;
return (p->u.aBitmap[i/8] & (1<<(i&7)))!=0;
i--;
while( p->iDivisor ){
u32 bin = i/p->iDivisor;
i = i%p->iDivisor;
p = p->u.apSub[bin];
if (!p) {
return 0;
}
}
if( p->iDivisor>0 ){
u32 bin = (i-1)/p->iDivisor;
i = (i-1)%p->iDivisor + 1;
return sqlite3BitvecTest(p->u.apSub[bin], i);
}else{
u32 h = BITVEC_HASH(i);
if( p->iSize<=BITVEC_NBIT ){
return (p->u.aBitmap[i/BITVEC_SZELEM] & (1<<(i&(BITVEC_SZELEM-1))))!=0;
} else{
u32 h = BITVEC_HASH(i++);
while( p->u.aHash[h] ){
if( p->u.aHash[h]==i ) return 1;
h++;
@@ -125,40 +155,64 @@ int sqlite3BitvecTest(Bitvec *p, u32 i){
/*
** Set the i-th bit. Return 0 on success and an error code if
** anything goes wrong.
**
** This routine might cause sub-bitmaps to be allocated. Failing
** to get the memory needed to hold the sub-bitmap is the only
** that can go wrong with an insert, assuming p and i are valid.
**
** The calling function must ensure that p is a valid Bitvec object
** and that the value for "i" is within range of the Bitvec object.
** Otherwise the behavior is undefined.
*/
int sqlite3BitvecSet(Bitvec *p, u32 i){
u32 h;
assert( p!=0 );
assert( i>0 );
assert( i<=p->iSize );
if( p->iSize<=BITVEC_NBIT ){
i--;
p->u.aBitmap[i/8] |= 1 << (i&7);
return SQLITE_OK;
}
if( p->iDivisor ){
u32 bin = (i-1)/p->iDivisor;
i = (i-1)%p->iDivisor + 1;
i--;
while((p->iSize > BITVEC_NBIT) && p->iDivisor) {
u32 bin = i/p->iDivisor;
i = i%p->iDivisor;
if( p->u.apSub[bin]==0 ){
sqlite3BeginBenignMalloc();
p->u.apSub[bin] = sqlite3BitvecCreate( p->iDivisor );
sqlite3EndBenignMalloc();
if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM;
}
return sqlite3BitvecSet(p->u.apSub[bin], i);
p = p->u.apSub[bin];
}
h = BITVEC_HASH(i);
while( p->u.aHash[h] ){
if( p->iSize<=BITVEC_NBIT ){
p->u.aBitmap[i/BITVEC_SZELEM] |= 1 << (i&(BITVEC_SZELEM-1));
return SQLITE_OK;
}
h = BITVEC_HASH(i++);
/* if there wasn't a hash collision, and this doesn't */
/* completely fill the hash, then just add it without */
/* worring about sub-dividing and re-hashing. */
if( !p->u.aHash[h] ){
if (p->nSet<(BITVEC_NINT-1)) {
goto bitvec_set_end;
} else {
goto bitvec_set_rehash;
}
}
/* there was a collision, check to see if it's already */
/* in hash, if not, try to find a spot for it */
do {
if( p->u.aHash[h]==i ) return SQLITE_OK;
h++;
if( h==BITVEC_NINT ) h = 0;
}
p->nSet++;
if( h>=BITVEC_NINT ) h = 0;
} while( p->u.aHash[h] );
/* we didn't find it in the hash. h points to the first */
/* available free spot. check to see if this is going to */
/* make our hash too "full". */
bitvec_set_rehash:
if( p->nSet>=BITVEC_MXHASH ){
int j, rc;
unsigned int j;
int rc;
u32 aiValues[BITVEC_NINT];
memcpy(aiValues, p->u.aHash, sizeof(aiValues));
memset(p->u.apSub, 0, sizeof(p->u.apSub[0])*BITVEC_NPTR);
memset(p->u.apSub, 0, sizeof(aiValues));
p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR;
rc = sqlite3BitvecSet(p, i);
for(j=0; j<BITVEC_NINT; j++){
@@ -166,35 +220,44 @@ int sqlite3BitvecSet(Bitvec *p, u32 i){
}
return rc;
}
bitvec_set_end:
p->nSet++;
p->u.aHash[h] = i;
return SQLITE_OK;
}
/*
** Clear the i-th bit. Return 0 on success and an error code if
** anything goes wrong.
** Clear the i-th bit.
*/
void sqlite3BitvecClear(Bitvec *p, u32 i){
assert( p!=0 );
assert( i>0 );
if( p->iSize<=BITVEC_NBIT ){
i--;
p->u.aBitmap[i/8] &= ~(1 << (i&7));
}else if( p->iDivisor ){
u32 bin = (i-1)/p->iDivisor;
i = (i-1)%p->iDivisor + 1;
if( p->u.apSub[bin] ){
sqlite3BitvecClear(p->u.apSub[bin], i);
i--;
while( p->iDivisor ){
u32 bin = i/p->iDivisor;
i = i%p->iDivisor;
p = p->u.apSub[bin];
if (!p) {
return;
}
}
if( p->iSize<=BITVEC_NBIT ){
p->u.aBitmap[i/BITVEC_SZELEM] &= ~(1 << (i&(BITVEC_SZELEM-1)));
}else{
int j;
unsigned int j;
u32 aiValues[BITVEC_NINT];
memcpy(aiValues, p->u.aHash, sizeof(aiValues));
memset(p->u.aHash, 0, sizeof(p->u.aHash[0])*BITVEC_NINT);
memset(p->u.aHash, 0, sizeof(aiValues));
p->nSet = 0;
for(j=0; j<BITVEC_NINT; j++){
if( aiValues[j] && aiValues[j]!=i ){
sqlite3BitvecSet(p, aiValues[j]);
if( aiValues[j] && aiValues[j]!=(i+1) ){
u32 h = BITVEC_HASH(aiValues[j]-1);
p->nSet++;
while( p->u.aHash[h] ){
h++;
if( h>=BITVEC_NINT ) h = 0;
}
p->u.aHash[h] = aiValues[j];
}
}
}
@@ -206,7 +269,7 @@ void sqlite3BitvecClear(Bitvec *p, u32 i){
void sqlite3BitvecDestroy(Bitvec *p){
if( p==0 ) return;
if( p->iDivisor ){
int i;
unsigned int i;
for(i=0; i<BITVEC_NPTR; i++){
sqlite3BitvecDestroy(p->u.apSub[i]);
}
+2 -4
View File
@@ -10,7 +10,7 @@
**
*************************************************************************
**
** $Id: btmutex.c,v 1.10 2008/07/14 19:39:17 drh Exp $
** $Id: btmutex.c,v 1.12 2008/11/17 19:18:55 danielk1977 Exp $
**
** This file contains code used to implement mutexes on Btree objects.
** This code really belongs in btree.c. But btree.c is getting too
@@ -61,7 +61,6 @@ void sqlite3BtreeEnter(Btree *p){
p->wantToLock++;
if( p->locked ) return;
#ifndef SQLITE_MUTEX_NOOP
/* In most cases, we should be able to acquire the lock we
** want without having to go throught the ascending lock
** procedure that follows. Just be sure not to block.
@@ -93,7 +92,6 @@ void sqlite3BtreeEnter(Btree *p){
pLater->locked = 1;
}
}
#endif /* SQLITE_MUTEX_NOOP */
}
/*
@@ -250,7 +248,7 @@ void sqlite3BtreeMutexArrayInsert(BtreeMutexArray *pArray, Btree *pBtree){
}
#endif
assert( pArray->nMutex>=0 );
assert( pArray->nMutex<sizeof(pArray->aBtree)/sizeof(pArray->aBtree[0])-1 );
assert( pArray->nMutex<ArraySize(pArray->aBtree)-1 );
pBt = pBtree->pBt;
for(i=0; i<pArray->nMutex; i++){
assert( pArray->aBtree[i]!=pBtree );
+528 -528
View File
File diff suppressed because it is too large Load Diff
+3 -2
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.103 2008/08/13 19:11:48 drh Exp $
** @(#) $Id: btree.h,v 1.105 2008/10/27 13:59:34 danielk1977 Exp $
*/
#ifndef _BTREE_H_
#define _BTREE_H_
@@ -117,7 +117,7 @@ int sqlite3BtreeIncrVacuum(Btree *);
#define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */
int sqlite3BtreeDropTable(Btree*, int, int*);
int sqlite3BtreeClearTable(Btree*, int);
int sqlite3BtreeClearTable(Btree*, int, int*);
int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
void sqlite3BtreeTripAllCursors(Btree*, int);
@@ -170,6 +170,7 @@ struct Pager *sqlite3BtreePager(Btree*);
int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
void sqlite3BtreeCacheOverflow(BtCursor *);
void sqlite3BtreeClearCursor(BtCursor *);
#ifdef SQLITE_TEST
int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
+21 -23
View File
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btreeInt.h,v 1.31 2008/09/18 17:34:44 danielk1977 Exp $
** $Id: btreeInt.h,v 1.36 2008/11/19 10:22:33 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@@ -271,7 +271,6 @@ typedef struct BtLock BtLock;
*/
struct MemPage {
u8 isInit; /* True if previously initialized. MUST BE FIRST! */
u8 idxShift; /* True if Cell indices have changed */
u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
u8 intKey; /* True if intkey flag is set */
u8 leaf; /* True if leaf flag is set */
@@ -281,7 +280,6 @@ struct MemPage {
u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
u16 cellOffset; /* Index in aData of first cell pointer */
u16 idxParent; /* Index in parent of this node */
u16 nFree; /* Number of free bytes on the page */
u16 nCell; /* Number of cells on this page, local and ovfl */
u16 maskPage; /* Mask for page offset */
@@ -293,21 +291,8 @@ struct MemPage {
u8 *aData; /* Pointer to disk image of the page data */
DbPage *pDbPage; /* Pager page handle */
Pgno pgno; /* Page number for this page */
MemPage *pParent; /* The parent of this page. NULL for root */
};
/*
** Possible values for the MemPage.isInit variable. When a page is first
** loaded or if the data stored in the MemPage struct is invalidated,
** MemPage.isInit is set to PAGE_ISINIT_NONE. If the MemPage structure
** is fully initialized, then MemPage.isInit is set to PAGE_ISINIT_FULL.
** MemPage.isInit is set to PAGE_ISINIT_DATA when the MemPage struct is
** populated, but the MemPage.pParent variable is not necessarily correct.
*/
#define PAGE_ISINIT_NONE 0
#define PAGE_ISINIT_DATA 1
#define PAGE_ISINIT_FULL 2
/*
** The in-memory image of a disk page has the auxiliary information appended
** to the end. EXTRA_SIZE is the number of bytes of space needed to hold
@@ -399,7 +384,6 @@ struct BtShared {
void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */
sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
BusyHandler busyHdr; /* The busy handler for this btree */
#ifndef SQLITE_OMIT_SHARED_CACHE
int nRef; /* Number of references to this structure */
BtShared *pNext; /* Next on a list of sharable BtShared structs */
@@ -426,6 +410,17 @@ struct CellInfo {
u16 nSize; /* Size of the cell content on the main b-tree page */
};
/*
** Maximum depth of an SQLite B-Tree structure. Any B-Tree deeper than
** this will be declared corrupt. This value is calculated based on a
** maximum database size of 2^31 pages a minimum fanout of 2 for a
** root-node and 3 for all other internal nodes.
**
** If a tree that appears to be taller than this is encountered, it is
** assumed that the database is corrupt.
*/
#define BTCURSOR_MAX_DEPTH 20
/*
** A cursor is a pointer to a particular entry within a particular
** b-tree within a database file.
@@ -446,8 +441,6 @@ struct BtCursor {
BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */
struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
Pgno pgnoRoot; /* The root page of this tree */
MemPage *pPage; /* Page that contains the entry */
int idx; /* Index of the entry in pPage->aCell[] */
CellInfo info; /* A parse of the cell we are pointing at */
u8 wrFlag; /* True if writable */
u8 atLast; /* Cursor pointing to the last entry */
@@ -460,6 +453,12 @@ struct BtCursor {
u8 isIncrblobHandle; /* True if this cursor is an incr. io handle */
Pgno *aOverflow; /* Cache of overflow page locations */
#endif
#ifndef NDEBUG
u8 pagesShuffled; /* True if Btree pages are rearranged by balance()*/
#endif
i16 iPage; /* Index of current page in apPage */
MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
};
/*
@@ -502,7 +501,7 @@ struct BtCursor {
#ifdef SQLITE_OMIT_DISKIO
# define PENDING_BYTE_PAGE(pBt) 0x7fffffff
#else
# define PENDING_BYTE_PAGE(pBt) ((PENDING_BYTE/(pBt)->pageSize)+1)
# define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/(pBt)->pageSize)+1))
#endif
/*
@@ -609,7 +608,7 @@ typedef struct IntegrityCk IntegrityCk;
struct IntegrityCk {
BtShared *pBt; /* The tree being checked out */
Pager *pPager; /* The associated pager. Also accessible by pBt->pPager */
int nPage; /* Number of pages in the database */
Pgno nPage; /* Number of pages in the database */
int *anRef; /* Number of times each page is referenced */
int mxErr; /* Stop accumulating errors when this reaches zero */
int nErr; /* Number of messages written to zErrMsg so far */
@@ -629,11 +628,10 @@ struct IntegrityCk {
** Internal routines that should be accessed by the btree layer only.
*/
int sqlite3BtreeGetPage(BtShared*, Pgno, MemPage**, int);
int sqlite3BtreeInitPage(MemPage *pPage, MemPage *pParent);
int sqlite3BtreeInitPage(MemPage *pPage);
void sqlite3BtreeParseCellPtr(MemPage*, u8*, CellInfo*);
void sqlite3BtreeParseCell(MemPage*, int, CellInfo*);
int sqlite3BtreeRestoreCursorPosition(BtCursor *pCur);
void sqlite3BtreeGetTempCursor(BtCursor *pCur, BtCursor *pTempCur);
void sqlite3BtreeReleaseTempCursor(BtCursor *pCur);
int sqlite3BtreeIsRootPage(MemPage *pPage);
void sqlite3BtreeMoveToParent(BtCursor *pCur);
+105 -22
View File
@@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
** $Id: build.c,v 1.496 2008/08/20 16:35:10 drh Exp $
** $Id: build.c,v 1.503 2008/11/17 19:18:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -626,7 +626,7 @@ void sqlite3OpenMasterTable(Parse *p, int iDb){
*/
int sqlite3FindDb(sqlite3 *db, Token *pName){
int i = -1; /* Database number */
int n; /* Number of characters in the name */
size_t n; /* Number of characters in the name */
Db *pDb; /* A database whose name space is being searched */
char *zName; /* Name we are searching for */
@@ -670,7 +670,11 @@ int sqlite3TwoPartName(
sqlite3 *db = pParse->db;
if( pName2 && pName2->n>0 ){
assert( !db->init.busy );
if( db->init.busy ) {
sqlite3ErrorMsg(pParse, "corrupt database");
pParse->nErr++;
return -1;
}
*pUnqual = pName2;
iDb = sqlite3FindDb(db, pName1);
if( iDb<0 ){
@@ -1392,7 +1396,7 @@ static char *createTableStmt(sqlite3 *db, Table *p, int isTemp){
identPut(zStmt, &k, pCol->zName);
if( (z = pCol->zType)!=0 ){
zStmt[k++] = ' ';
assert( strlen(z)+k+1<=n );
assert( (int)(strlen(z)+k+1)<=n );
sqlite3_snprintf(n-k, &zStmt[k], "%s", z);
k += strlen(z);
}
@@ -2401,7 +2405,7 @@ void sqlite3CreateIndex(
}
pTab = sqlite3LocateTable(pParse, 0, pTblName->a[0].zName,
pTblName->a[0].zDatabase);
if( !pTab ) goto exit_create_index;
if( !pTab || db->mallocFailed ) goto exit_create_index;
assert( db->aDb[iDb].pSchema==pTab->pSchema );
}else{
assert( pName==0 );
@@ -2991,11 +2995,81 @@ int sqlite3IdListIndex(IdList *pList, const char *zName){
return -1;
}
/*
** Expand the space allocated for the given SrcList object by
** creating nExtra new slots beginning at iStart. iStart is zero based.
** New slots are zeroed.
**
** For example, suppose a SrcList initially contains two entries: A,B.
** To append 3 new entries onto the end, do this:
**
** sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
**
** After the call above it would contain: A, B, nil, nil, nil.
** If the iStart argument had been 1 instead of 2, then the result
** would have been: A, nil, nil, nil, B. To prepend the new slots,
** the iStart value would be 0. The result then would
** be: nil, nil, nil, A, B.
**
** If a memory allocation fails the SrcList is unchanged. The
** db->mallocFailed flag will be set to true.
*/
SrcList *sqlite3SrcListEnlarge(
sqlite3 *db, /* Database connection to notify of OOM errors */
SrcList *pSrc, /* The SrcList to be enlarged */
int nExtra, /* Number of new slots to add to pSrc->a[] */
int iStart /* Index in pSrc->a[] of first new slot */
){
int i;
/* Sanity checking on calling parameters */
assert( iStart>=0 );
assert( nExtra>=1 );
if( pSrc==0 || iStart>pSrc->nSrc ){
assert( db->mallocFailed );
return pSrc;
}
/* Allocate additional space if needed */
if( pSrc->nSrc+nExtra>pSrc->nAlloc ){
SrcList *pNew;
int nAlloc = pSrc->nSrc+nExtra;
pNew = sqlite3DbRealloc(db, pSrc,
sizeof(*pSrc) + (nAlloc-1)*sizeof(pSrc->a[0]) );
if( pNew==0 ){
assert( db->mallocFailed );
return pSrc;
}
pSrc = pNew;
pSrc->nAlloc = nAlloc;
}
/* Move existing slots that come after the newly inserted slots
** out of the way */
for(i=pSrc->nSrc-1; i>=iStart; i--){
pSrc->a[i+nExtra] = pSrc->a[i];
}
pSrc->nSrc += nExtra;
/* Zero the newly allocated slots */
memset(&pSrc->a[iStart], 0, sizeof(pSrc->a[0])*nExtra);
for(i=iStart; i<iStart+nExtra; i++){
pSrc->a[i].iCursor = -1;
}
/* Return a pointer to the enlarged SrcList */
return pSrc;
}
/*
** Append a new table name to the given SrcList. Create a new SrcList if
** need be. A new entry is created in the SrcList even if pToken is NULL.
**
** A new SrcList is returned, or NULL if malloc() fails.
** A SrcList is returned, or NULL if there is an OOM error. The returned
** SrcList might be the same as the SrcList that was input or it might be
** a new one. If an OOM error does occurs, then the prior value of pList
** that is input to this routine is automatically freed.
**
** If pDatabase is not null, it means that the table has an optional
** database name prefix. Like this: "database.table". The pDatabase
@@ -3028,19 +3102,12 @@ SrcList *sqlite3SrcListAppend(
if( pList==0 ) return 0;
pList->nAlloc = 1;
}
if( pList->nSrc>=pList->nAlloc ){
SrcList *pNew;
pList->nAlloc *= 2;
pNew = sqlite3DbRealloc(db, pList,
sizeof(*pList) + (pList->nAlloc-1)*sizeof(pList->a[0]) );
if( pNew==0 ){
sqlite3SrcListDelete(db, pList);
return 0;
}
pList = pNew;
pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
if( db->mallocFailed ){
sqlite3SrcListDelete(db, pList);
return 0;
}
pItem = &pList->a[pList->nSrc];
memset(pItem, 0, sizeof(pList->a[0]));
pItem = &pList->a[pList->nSrc-1];
if( pDatabase && pDatabase->z==0 ){
pDatabase = 0;
}
@@ -3051,14 +3118,11 @@ SrcList *sqlite3SrcListAppend(
}
pItem->zName = sqlite3NameFromToken(db, pTable);
pItem->zDatabase = sqlite3NameFromToken(db, pDatabase);
pItem->iCursor = -1;
pItem->isPopulated = 0;
pList->nSrc++;
return pList;
}
/*
** Assign cursors to all tables in a SrcList
** Assign VdbeCursor index numbers to all tables in a SrcList
*/
void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){
int i;
@@ -3086,6 +3150,7 @@ void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
sqlite3DbFree(db, pItem->zDatabase);
sqlite3DbFree(db, pItem->zName);
sqlite3DbFree(db, pItem->zAlias);
sqlite3DbFree(db, pItem->zIndex);
sqlite3DeleteTable(pItem->pTab);
sqlite3SelectDelete(db, pItem->pSelect);
sqlite3ExprDelete(db, pItem->pOn);
@@ -3139,6 +3204,24 @@ SrcList *sqlite3SrcListAppendFromTerm(
return p;
}
/*
** Add an INDEXED BY or NOT INDEXED clause to the most recently added
** element of the source-list passed as the second argument.
*/
void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
if( pIndexedBy && p && p->nSrc>0 ){
struct SrcList_item *pItem = &p->a[p->nSrc-1];
assert( pItem->notIndexed==0 && pItem->zIndex==0 );
if( pIndexedBy->n==1 && !pIndexedBy->z ){
/* A "NOT INDEXED" clause was supplied. See parse.y
** construct "indexed_opt" for details. */
pItem->notIndexed = 1;
}else{
pItem->zIndex = sqlite3NameFromToken(pParse->db, pIndexedBy);
}
}
}
/*
** When building up a FROM clause in the parser, the join operator
** is initially attached to the left operand. But the code generator
+7 -7
View File
@@ -13,7 +13,7 @@
** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences.
**
** $Id: callback.c,v 1.31 2008/09/09 12:31:34 drh Exp $
** $Id: callback.c,v 1.32 2008/10/10 17:41:29 drh Exp $
*/
#include "sqliteInt.h"
@@ -410,14 +410,14 @@ void sqlite3SchemaFree(void *p){
temp1 = pSchema->tblHash;
temp2 = pSchema->trigHash;
sqlite3HashInit(&pSchema->trigHash, SQLITE_HASH_STRING, 0);
sqlite3HashInit(&pSchema->trigHash, 0);
sqlite3HashClear(&pSchema->aFKey);
sqlite3HashClear(&pSchema->idxHash);
for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
sqlite3DeleteTrigger(0, (Trigger*)sqliteHashData(pElem));
}
sqlite3HashClear(&temp2);
sqlite3HashInit(&pSchema->tblHash, SQLITE_HASH_STRING, 0);
sqlite3HashInit(&pSchema->tblHash, 0);
for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
Table *pTab = sqliteHashData(pElem);
sqlite3DeleteTable(pTab);
@@ -441,10 +441,10 @@ Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
if( !p ){
db->mallocFailed = 1;
}else if ( 0==p->file_format ){
sqlite3HashInit(&p->tblHash, SQLITE_HASH_STRING, 0);
sqlite3HashInit(&p->idxHash, SQLITE_HASH_STRING, 0);
sqlite3HashInit(&p->trigHash, SQLITE_HASH_STRING, 0);
sqlite3HashInit(&p->aFKey, SQLITE_HASH_STRING, 1);
sqlite3HashInit(&p->tblHash, 0);
sqlite3HashInit(&p->idxHash, 0);
sqlite3HashInit(&p->trigHash, 0);
sqlite3HashInit(&p->aFKey, 1);
p->enc = SQLITE_UTF8;
}
return p;
+16 -13
View File
@@ -16,7 +16,7 @@
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.90 2008/09/03 17:11:16 drh Exp $
** $Id: date.c,v 1.94 2008/11/19 09:05:27 danielk1977 Exp $
**
** SQLite processes all times and dates as Julian Day numbers. The
** dates and times are stored as the number of days since noon
@@ -521,7 +521,7 @@ static int parseModifier(const char *zMod, DateTime *p){
double r;
char *z, zBuf[30];
z = zBuf;
for(n=0; n<sizeof(zBuf)-1 && zMod[n]; n++){
for(n=0; n<ArraySize(zBuf)-1 && zMod[n]; n++){
z[n] = tolower(zMod[n]);
}
z[n] = 0;
@@ -556,7 +556,7 @@ static int parseModifier(const char *zMod, DateTime *p){
}
#ifndef SQLITE_OMIT_LOCALTIME
else if( strcmp(z, "utc")==0 ){
double c1;
int c1;
computeJD(p);
c1 = localtimeOffset(p);
p->iJD -= c1;
@@ -889,7 +889,7 @@ static void strftimeFunc(
}
if( n<sizeof(zBuf) ){
z = zBuf;
}else if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
}else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
sqlite3_result_error_toobig(context);
return;
}else{
@@ -968,9 +968,10 @@ static void strftimeFunc(
*/
static void ctimeFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
int NotUsed,
sqlite3_value **NotUsed2
){
UNUSED_PARAMETER2(NotUsed, NotUsed2);
timeFunc(context, 0, 0);
}
@@ -981,9 +982,10 @@ static void ctimeFunc(
*/
static void cdateFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
int NotUsed,
sqlite3_value **NotUsed2
){
UNUSED_PARAMETER2(NotUsed, NotUsed2);
dateFunc(context, 0, 0);
}
@@ -994,9 +996,10 @@ static void cdateFunc(
*/
static void ctimestampFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
int NotUsed,
sqlite3_value **NotUsed2
){
UNUSED_PARAMETER2(NotUsed, NotUsed2);
datetimeFunc(context, 0, 0);
}
#endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */
@@ -1064,9 +1067,9 @@ void sqlite3RegisterDateTimeFunctions(void){
FUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
FUNCTION(current_date, 0, 0, 0, cdateFunc ),
#else
FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
FUNCTION(current_timestamp, 0, "%Y-%m-%d", 0, currentTimeFunc),
FUNCTION(current_date, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc),
STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d", 0, currentTimeFunc),
STR_FUNCTION(current_date, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc),
#endif
};
int i;
+123 -38
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.175 2008/09/01 21:59:43 shane Exp $
** $Id: delete.c,v 1.187 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -22,16 +22,17 @@
** are found, return a pointer to the last table.
*/
Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
Table *pTab = 0;
int i;
struct SrcList_item *pItem;
for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase);
sqlite3DeleteTable(pItem->pTab);
pItem->pTab = pTab;
if( pTab ){
pTab->nRef++;
}
struct SrcList_item *pItem = pSrc->a;
Table *pTab;
assert( pItem && pSrc->nSrc==1 );
pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase);
sqlite3DeleteTable(pItem->pTab);
pItem->pTab = pTab;
if( pTab ){
pTab->nRef++;
}
if( sqlite3IndexedByLookup(pParse, pItem) ){
pTab = 0;
}
return pTab;
}
@@ -115,6 +116,97 @@ void sqlite3MaterializeView(
}
#endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
/*
** Generate an expression tree to implement the WHERE, ORDER BY,
** and LIMIT/OFFSET portion of DELETE and UPDATE statements.
**
** DELETE FROM table_wxyz WHERE a<5 ORDER BY a LIMIT 1;
** \__________________________/
** pLimitWhere (pInClause)
*/
Expr *sqlite3LimitWhere(
Parse *pParse, /* The parser context */
SrcList *pSrc, /* the FROM clause -- which tables to scan */
Expr *pWhere, /* The WHERE clause. May be null */
ExprList *pOrderBy, /* The ORDER BY clause. May be null */
Expr *pLimit, /* The LIMIT clause. May be null */
Expr *pOffset, /* The OFFSET clause. May be null */
char *zStmtType /* Either DELETE or UPDATE. For error messages. */
){
Expr *pWhereRowid = NULL; /* WHERE rowid .. */
Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
Expr *pSelectRowid = NULL; /* SELECT rowid ... */
ExprList *pEList = NULL; /* Expression list contaning only pSelectRowid */
SrcList *pSelectSrc = NULL; /* SELECT rowid FROM x ... (dup of pSrc) */
Select *pSelect = NULL; /* Complete SELECT tree */
/* Check that there isn't an ORDER BY without a LIMIT clause.
*/
if( pOrderBy && (pLimit == 0) ) {
sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
pParse->parseError = 1;
goto limit_where_cleanup_2;
}
/* We only need to generate a select expression if there
** is a limit/offset term to enforce.
*/
if( pLimit == 0 ) {
/* if pLimit is null, pOffset will always be null as well. */
assert( pOffset == 0 );
return pWhere;
}
/* Generate a select expression tree to enforce the limit/offset
** term for the DELETE or UPDATE statement. For example:
** DELETE FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
** becomes:
** DELETE FROM table_a WHERE rowid IN (
** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
** );
*/
pSelectRowid = sqlite3Expr(pParse->db, TK_ROW, 0, 0, 0);
if( pSelectRowid == 0 ) goto limit_where_cleanup_2;
pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid, 0);
if( pEList == 0 ) goto limit_where_cleanup_2;
/* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
** and the SELECT subtree. */
pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc);
if( pSelectSrc == 0 ) {
sqlite3ExprListDelete(pParse->db, pEList);
goto limit_where_cleanup_2;
}
/* generate the SELECT expression tree. */
pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,pOrderBy,0,pLimit,pOffset);
if( pSelect == 0 ) return 0;
/* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
pWhereRowid = sqlite3Expr(pParse->db, TK_ROW, 0, 0, 0);
if( pWhereRowid == 0 ) goto limit_where_cleanup_1;
pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0);
if( pInClause == 0 ) goto limit_where_cleanup_1;
pInClause->pSelect = pSelect;
sqlite3ExprSetHeight(pParse, pInClause);
return pInClause;
/* something went wrong. clean up anything allocated. */
limit_where_cleanup_1:
sqlite3SelectDelete(pParse->db, pSelect);
return 0;
limit_where_cleanup_2:
sqlite3ExprDelete(pParse->db, pWhere);
sqlite3ExprListDelete(pParse->db, pOrderBy);
sqlite3ExprDelete(pParse->db, pLimit);
sqlite3ExprDelete(pParse->db, pOffset);
return 0;
}
#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */
/*
** Generate code for a DELETE FROM statement.
@@ -141,7 +233,8 @@ void sqlite3DeleteFrom(
int oldIdx = -1; /* Cursor for the OLD table of AFTER triggers */
NameContext sNC; /* Name context to resolve expressions in */
int iDb; /* Database number */
int memCnt = 0; /* Memory cell used for change counting */
int memCnt = -1; /* Memory cell used for change counting */
int rcauth; /* Value returned by authorization callback */
#ifndef SQLITE_OMIT_TRIGGER
int isView; /* True if attempting to delete from a view */
@@ -172,7 +265,7 @@ void sqlite3DeleteFrom(
** deleted from is a view
*/
#ifndef SQLITE_OMIT_TRIGGER
triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0);
triggers_exist = sqlite3TriggersExist(pTab, TK_DELETE, 0);
isView = pTab->pSelect!=0;
#else
# define triggers_exist 0
@@ -189,9 +282,12 @@ void sqlite3DeleteFrom(
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
assert( iDb<db->nDb );
zDb = db->aDb[iDb].zName;
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
if( rcauth==SQLITE_DENY ){
goto delete_from_cleanup;
}
assert(!isView || triggers_exist);
/* If pTab is really a view, make sure it has been initialized.
*/
@@ -272,38 +368,27 @@ void sqlite3DeleteFrom(
sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);
}
#ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
/* Special case: A DELETE without a WHERE clause deletes everything.
** It is easier just to erase the whole table. Note, however, that
** this means that the row change count will be incorrect.
*/
if( pWhere==0 && !triggers_exist && !IsVirtual(pTab) ){
if( db->flags & SQLITE_CountRows ){
/* If counting rows deleted, just count the total number of
** entries in the table. */
int addr2;
if( !isView ){
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
}
sqlite3VdbeAddOp2(v, OP_Rewind, iCur, sqlite3VdbeCurrentAddr(v)+2);
addr2 = sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
sqlite3VdbeAddOp2(v, OP_Next, iCur, addr2);
sqlite3VdbeAddOp1(v, OP_Close, iCur);
if( rcauth==SQLITE_OK && pWhere==0 && !triggers_exist && !IsVirtual(pTab) ){
assert( !isView );
sqlite3VdbeAddOp3(v, OP_Clear, pTab->tnum, iDb, memCnt);
if( !pParse->nested ){
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
}
if( !isView ){
sqlite3VdbeAddOp2(v, OP_Clear, pTab->tnum, iDb);
if( !pParse->nested ){
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
}
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
assert( pIdx->pSchema==pTab->pSchema );
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
}
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
assert( pIdx->pSchema==pTab->pSchema );
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
}
}
}else
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
/* The usual case: There is a WHERE clause so we have to scan through
** the table and pick which records to delete.
*/
else{
{
int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
/* Begin the database scan
@@ -416,7 +501,7 @@ void sqlite3DeleteFrom(
if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
sqlite3VdbeAddOp2(v, OP_ResultRow, memCnt, 1);
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC);
}
delete_from_cleanup:
+77 -28
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.394 2008/09/17 00:13:12 drh Exp $
** $Id: expr.c,v 1.404 2008/11/19 16:52:44 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -43,7 +43,9 @@ char sqlite3ExprAffinity(Expr *pExpr){
return sqlite3AffinityType(&pExpr->token);
}
#endif
if( (op==TK_COLUMN || op==TK_REGISTER) && pExpr->pTab!=0 ){
if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER)
&& pExpr->pTab!=0
){
/* op==TK_REGISTER && pExpr->pTab!=0 happens when pExpr was originally
** a TK_COLUMN but was previously evaluated and cached in a register */
int j = pExpr->iColumn;
@@ -89,7 +91,7 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){
pColl = p->pColl;
if( pColl ) break;
op = p->op;
if( (op==TK_COLUMN || op==TK_REGISTER) && p->pTab!=0 ){
if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER) && p->pTab!=0 ){
/* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally
** a TK_COLUMN but was previously evaluated and cached in a register */
const char *zColl;
@@ -601,16 +603,24 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
}
/*
** Recursively delete an expression tree.
** Clear an expression structure without deleting the structure itself.
** Substructure is deleted.
*/
void sqlite3ExprDelete(sqlite3 *db, Expr *p){
if( p==0 ) return;
void sqlite3ExprClear(sqlite3 *db, Expr *p){
if( p->span.dyn ) sqlite3DbFree(db, (char*)p->span.z);
if( p->token.dyn ) sqlite3DbFree(db, (char*)p->token.z);
sqlite3ExprDelete(db, p->pLeft);
sqlite3ExprDelete(db, p->pRight);
sqlite3ExprListDelete(db, p->pList);
sqlite3SelectDelete(db, p->pSelect);
}
/*
** Recursively delete an expression tree.
*/
void sqlite3ExprDelete(sqlite3 *db, Expr *p){
if( p==0 ) return;
sqlite3ExprClear(db, p);
sqlite3DbFree(db, p);
}
@@ -733,6 +743,9 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p){
pNewItem->jointype = pOldItem->jointype;
pNewItem->iCursor = pOldItem->iCursor;
pNewItem->isPopulated = pOldItem->isPopulated;
pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex);
pNewItem->notIndexed = pOldItem->notIndexed;
pNewItem->pIndex = pOldItem->pIndex;
pTab = pNewItem->pTab = pOldItem->pTab;
if( pTab ){
pTab->nRef++;
@@ -926,7 +939,8 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
return WRC_Continue;
}
}
static int selectNodeIsConstant(Walker *pWalker, Select *pSelect){
static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){
UNUSED_PARAMETER(NotUsed);
pWalker->u.i = 0;
return WRC_Abort;
}
@@ -1214,11 +1228,13 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
if( eType==0 ){
int rMayHaveNull = 0;
eType = IN_INDEX_EPH;
if( prNotFound ){
*prNotFound = rMayHaveNull = ++pParse->nMem;
}else if( pX->pLeft->iColumn<0 && pX->pSelect==0 ){
eType = IN_INDEX_ROWID;
}
sqlite3CodeSubselect(pParse, pX, rMayHaveNull);
eType = IN_INDEX_EPH;
sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
}else{
pX->iTable = iTab;
}
@@ -1237,9 +1253,20 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
**
** The pExpr parameter describes the expression that contains the IN
** operator or subquery.
**
** If parameter isRowid is non-zero, then expression pExpr is guaranteed
** to be of the form "<rowid> IN (?, ?, ?)", where <rowid> is a reference
** to some integer key column of a table B-Tree. In this case, use an
** intkey B-Tree to store the set of IN(...) values instead of the usual
** (slower) variable length keys B-Tree.
*/
#ifndef SQLITE_OMIT_SUBQUERY
void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr, int rMayHaveNull){
void sqlite3CodeSubselect(
Parse *pParse,
Expr *pExpr,
int rMayHaveNull,
int isRowid
){
int testAddr = 0; /* One-time test address */
Vdbe *v = sqlite3GetVdbe(pParse);
if( v==0 ) return;
@@ -1267,12 +1294,13 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr, int rMayHaveNull){
char affinity;
KeyInfo keyInfo;
int addr; /* Address of OP_OpenEphemeral instruction */
Expr *pLeft = pExpr->pLeft;
if( rMayHaveNull ){
sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull);
}
affinity = sqlite3ExprAffinity(pExpr->pLeft);
affinity = sqlite3ExprAffinity(pLeft);
/* Whether this is an 'x IN(SELECT...)' or an 'x IN(<exprlist>)'
** expression it is handled the same way. A virtual table is
@@ -1288,7 +1316,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr, int rMayHaveNull){
** is used.
*/
pExpr->iTable = pParse->nTab++;
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, 1);
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
memset(&keyInfo, 0, sizeof(keyInfo));
keyInfo.nField = 1;
@@ -1301,6 +1329,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr, int rMayHaveNull){
SelectDest dest;
ExprList *pEList;
assert( !isRowid );
sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
dest.affinity = (int)affinity;
assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
@@ -1333,6 +1362,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr, int rMayHaveNull){
/* Loop through each expression in <exprlist>. */
r1 = sqlite3GetTempReg(pParse);
r2 = sqlite3GetTempReg(pParse);
sqlite3VdbeAddOp2(v, OP_Null, 0, r2);
for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
Expr *pE2 = pItem->pExpr;
@@ -1351,14 +1381,22 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr, int rMayHaveNull){
r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
assert( pParse->disableColCache>0 );
pParse->disableColCache--;
sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
sqlite3ExprCacheAffinityChange(pParse, r3, 1);
sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
if( isRowid ){
sqlite3VdbeAddOp2(v, OP_MustBeInt, r3, sqlite3VdbeCurrentAddr(v)+2);
sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
}else{
sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
sqlite3ExprCacheAffinityChange(pParse, r3, 1);
sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
}
}
sqlite3ReleaseTempReg(pParse, r1);
sqlite3ReleaseTempReg(pParse, r2);
}
sqlite3VdbeChangeP4(v, addr, (void *)&keyInfo, P4_KEYINFO);
if( !isRowid ){
sqlite3VdbeChangeP4(v, addr, (void *)&keyInfo, P4_KEYINFO);
}
break;
}
@@ -1422,10 +1460,11 @@ static char *dup8bytes(Vdbe *v, const char *in){
*/
static void codeReal(Vdbe *v, const char *z, int n, int negateFlag, int iMem){
assert( z || v==0 || sqlite3VdbeDb(v)->mallocFailed );
assert( !z || !isdigit(z[n]) );
UNUSED_PARAMETER(n);
if( z ){
double value;
char *zV;
assert( !isdigit(z[n]) );
sqlite3AtoF(z, &value);
if( sqlite3IsNaN(value) ){
sqlite3VdbeAddOp2(v, OP_Null, 0, iMem);
@@ -1683,7 +1722,7 @@ void sqlite3ExprHardCopy(Parse *pParse, int iReg, int nReg){
** of the iAlias-th alias is stored. If zero, that means that the
** alias has not yet been computed.
*/
static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr){
static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr, int target){
sqlite3 *db = pParse->db;
int iReg;
if( pParse->aAlias==0 ){
@@ -1694,9 +1733,13 @@ static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr){
assert( iAlias>0 && iAlias<=pParse->nAlias );
iReg = pParse->aAlias[iAlias-1];
if( iReg==0 ){
iReg = ++pParse->nMem;
sqlite3ExprCode(pParse, pExpr, iReg);
pParse->aAlias[iAlias-1] = iReg;
if( pParse->disableColCache ){
iReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
}else{
iReg = ++pParse->nMem;
sqlite3ExprCode(pParse, pExpr, iReg);
pParse->aAlias[iAlias-1] = iReg;
}
}
return iReg;
}
@@ -1805,7 +1848,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
break;
}
case TK_AS: {
inReg = codeAlias(pParse, pExpr->iTable, pExpr->pLeft);
inReg = codeAlias(pParse, pExpr->iTable, pExpr->pLeft, target);
break;
}
#ifndef SQLITE_OMIT_CAST
@@ -1825,6 +1868,10 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
testcase( to_op==OP_ToNumeric );
testcase( to_op==OP_ToInt );
testcase( to_op==OP_ToReal );
if( inReg!=target ){
sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
inReg = target;
}
sqlite3VdbeAddOp1(v, to_op, inReg);
testcase( usedAsColumnCache(pParse, inReg, inReg) );
sqlite3ExprCacheAffinityChange(pParse, inReg, 1);
@@ -2003,11 +2050,11 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
if( sqlite3ExprIsConstant(pList->a[i].pExpr) ){
constMask |= (1<<i);
}
if( pDef->needCollSeq && !pColl ){
if( (pDef->flags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
}
}
if( pDef->needCollSeq ){
if( pDef->flags & SQLITE_FUNC_NEEDCOLL ){
if( !pColl ) pColl = db->pDfltColl;
sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
}
@@ -2026,7 +2073,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
testcase( op==TK_EXISTS );
testcase( op==TK_SELECT );
if( pExpr->iColumn==0 ){
sqlite3CodeSubselect(pParse, pExpr, 0);
sqlite3CodeSubselect(pParse, pExpr, 0, 0);
}
inReg = pExpr->iColumn;
break;
@@ -2109,7 +2156,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
sqlite3VdbeJumpHere(v, j3);
/* Copy the value of register rNotFound (which is either NULL or 0)
** into the target register. This will be the result of the
** into the target register. This will be the result of the
** expression.
*/
sqlite3VdbeAddOp2(v, OP_Copy, rNotFound, target);
@@ -2465,9 +2512,11 @@ int sqlite3ExprCodeExprList(
n = pList->nExpr;
for(pItem=pList->a, i=0; i<n; i++, pItem++){
if( pItem->iAlias ){
int iReg = codeAlias(pParse, pItem->iAlias, pItem->pExpr);
int iReg = codeAlias(pParse, pItem->iAlias, pItem->pExpr, target+i);
Vdbe *v = sqlite3GetVdbe(pParse);
sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target+i);
if( iReg!=target+i ){
sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target+i);
}
}else{
sqlite3ExprCode(pParse, pItem->pExpr, target+i);
}
+33 -17
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.203 2008/09/03 17:11:16 drh Exp $
** $Id: func.c,v 1.206 2008/11/19 16:52:44 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -65,10 +65,11 @@ static void minmaxFunc(
*/
static void typeofFunc(
sqlite3_context *context,
int argc,
int NotUsed,
sqlite3_value **argv
){
const char *z = 0;
UNUSED_PARAMETER(NotUsed);
switch( sqlite3_value_type(argv[0]) ){
case SQLITE_NULL: z = "null"; break;
case SQLITE_INTEGER: z = "integer"; break;
@@ -91,6 +92,7 @@ static void lengthFunc(
int len;
assert( argc==1 );
UNUSED_PARAMETER(argc);
switch( sqlite3_value_type(argv[0]) ){
case SQLITE_BLOB:
case SQLITE_INTEGER:
@@ -121,6 +123,7 @@ static void lengthFunc(
*/
static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
assert( argc==1 );
UNUSED_PARAMETER(argc);
switch( sqlite3_value_type(argv[0]) ){
case SQLITE_INTEGER: {
i64 iVal = sqlite3_value_int64(argv[0]);
@@ -324,10 +327,11 @@ static void ifnullFunc(
*/
static void randomFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
int NotUsed,
sqlite3_value **NotUsed2
){
sqlite_int64 r;
UNUSED_PARAMETER2(NotUsed, NotUsed2);
sqlite3_randomness(sizeof(r), &r);
if( (r<<1)==0 ) r = 0; /* Prevent 0x8000.... as the result so that we */
/* can always do abs() of the result */
@@ -346,6 +350,7 @@ static void randomBlob(
int n;
unsigned char *p;
assert( argc==1 );
UNUSED_PARAMETER(argc);
n = sqlite3_value_int(argv[0]);
if( n<1 ){
n = 1;
@@ -363,10 +368,11 @@ static void randomBlob(
*/
static void last_insert_rowid(
sqlite3_context *context,
int arg,
sqlite3_value **argv
int NotUsed,
sqlite3_value **NotUsed2
){
sqlite3 *db = sqlite3_context_db_handle(context);
UNUSED_PARAMETER2(NotUsed, NotUsed2);
sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
}
@@ -376,10 +382,11 @@ static void last_insert_rowid(
*/
static void changes(
sqlite3_context *context,
int arg,
sqlite3_value **argv
int NotUsed,
sqlite3_value **NotUsed2
){
sqlite3 *db = sqlite3_context_db_handle(context);
UNUSED_PARAMETER2(NotUsed, NotUsed2);
sqlite3_result_int(context, sqlite3_changes(db));
}
@@ -389,10 +396,11 @@ static void changes(
*/
static void total_changes(
sqlite3_context *context,
int arg,
sqlite3_value **argv
int NotUsed,
sqlite3_value **NotUsed2
){
sqlite3 *db = sqlite3_context_db_handle(context);
UNUSED_PARAMETER2(NotUsed, NotUsed2);
sqlite3_result_int(context, sqlite3_total_changes(db));
}
@@ -637,10 +645,11 @@ static void likeFunc(
*/
static void nullifFunc(
sqlite3_context *context,
int argc,
int NotUsed,
sqlite3_value **argv
){
CollSeq *pColl = sqlite3GetFuncCollSeq(context);
UNUSED_PARAMETER(NotUsed);
if( sqlite3MemCompare(argv[0], argv[1], pColl)!=0 ){
sqlite3_result_value(context, argv[0]);
}
@@ -652,9 +661,10 @@ static void nullifFunc(
*/
static void versionFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
int NotUsed,
sqlite3_value **NotUsed2
){
UNUSED_PARAMETER2(NotUsed, NotUsed2);
sqlite3_result_text(context, sqlite3_version, -1, SQLITE_STATIC);
}
@@ -747,6 +757,7 @@ static void hexFunc(
const unsigned char *pBlob;
char *zHex, *z;
assert( argc==1 );
UNUSED_PARAMETER(argc);
pBlob = sqlite3_value_blob(argv[0]);
n = sqlite3_value_bytes(argv[0]);
assert( pBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
@@ -772,6 +783,7 @@ static void zeroblobFunc(
){
i64 n;
assert( argc==1 );
UNUSED_PARAMETER(argc);
n = sqlite3_value_int64(argv[0]);
if( n>SQLITE_MAX_LENGTH ){
sqlite3_result_error_toobig(context);
@@ -803,6 +815,7 @@ static void replaceFunc(
int i, j; /* Loop counters */
assert( argc==3 );
UNUSED_PARAMETER(argc);
zStr = sqlite3_value_text(argv[0]);
if( zStr==0 ) return;
nStr = sqlite3_value_bytes(argv[0]);
@@ -1040,6 +1053,7 @@ static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){
SumCtx *p;
int type;
assert( argc==1 );
UNUSED_PARAMETER(argc);
p = sqlite3_aggregate_context(context, sizeof(*p));
type = sqlite3_value_numeric_type(argv[0]);
if( p && type!=SQLITE_NULL ){
@@ -1115,9 +1129,14 @@ static void countFinalize(sqlite3_context *context){
/*
** Routines to implement min() and max() aggregate functions.
*/
static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){
static void minmaxStep(
sqlite3_context *context,
int NotUsed,
sqlite3_value **argv
){
Mem *pArg = (Mem *)argv[0];
Mem *pBest;
UNUSED_PARAMETER(NotUsed);
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest));
@@ -1216,9 +1235,6 @@ static void groupConcatFinalize(sqlite3_context *context){
void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
#ifndef SQLITE_OMIT_ALTERTABLE
sqlite3AlterFunctions(db);
#endif
#ifndef SQLITE_OMIT_PARSER
sqlite3AttachFunctions(db);
#endif
if( !db->mallocFailed ){
int rc = sqlite3_overload_function(db, "MATCH", 2);
+9 -129
View File
@@ -12,7 +12,7 @@
** This is the implementation of generic hash-tables
** used in SQLite.
**
** $Id: hash.c,v 1.30 2008/06/20 14:59:51 danielk1977 Exp $
** $Id: hash.c,v 1.31 2008/10/10 17:41:29 drh Exp $
*/
#include "sqliteInt.h"
#include <assert.h>
@@ -21,22 +21,12 @@
** fields of the Hash structure.
**
** "pNew" is a pointer to the hash table that is to be initialized.
** keyClass is one of the constants SQLITE_HASH_INT, SQLITE_HASH_POINTER,
** SQLITE_HASH_BINARY, or SQLITE_HASH_STRING. The value of keyClass
** determines what kind of key the hash table will use. "copyKey" is
** true if the hash table should make its own private copy of keys and
** false if it should just use the supplied pointer. CopyKey only makes
** sense for SQLITE_HASH_STRING and SQLITE_HASH_BINARY and is ignored
** for other key classes.
** "copyKey" is true if the hash table should make its own private
** copy of keys and false if it should just use the supplied pointer.
*/
void sqlite3HashInit(Hash *pNew, int keyClass, int copyKey){
void sqlite3HashInit(Hash *pNew, int copyKey){
assert( pNew!=0 );
assert( keyClass>=SQLITE_HASH_STRING && keyClass<=SQLITE_HASH_BINARY );
pNew->keyClass = keyClass;
#if 0
if( keyClass==SQLITE_HASH_POINTER || keyClass==SQLITE_HASH_INT ) copyKey = 0;
#endif
pNew->copyKey = copyKey;
pNew->copyKey = copyKey!=0;
pNew->first = 0;
pNew->count = 0;
pNew->htsize = 0;
@@ -67,33 +57,6 @@ void sqlite3HashClear(Hash *pH){
pH->count = 0;
}
#if 0 /* NOT USED */
/*
** Hash and comparison functions when the mode is SQLITE_HASH_INT
*/
static int intHash(const void *pKey, int nKey){
return nKey ^ (nKey<<8) ^ (nKey>>8);
}
static int intCompare(const void *pKey1, int n1, const void *pKey2, int n2){
return n2 - n1;
}
#endif
#if 0 /* NOT USED */
/*
** Hash and comparison functions when the mode is SQLITE_HASH_POINTER
*/
static int ptrHash(const void *pKey, int nKey){
uptr x = Addr(pKey);
return x ^ (x<<8) ^ (x>>8);
}
static int ptrCompare(const void *pKey1, int n1, const void *pKey2, int n2){
if( pKey1==pKey2 ) return 0;
if( pKey1<pKey2 ) return -1;
return 1;
}
#endif
/*
** Hash and comparison functions when the mode is SQLITE_HASH_STRING
*/
@@ -112,79 +75,6 @@ static int strCompare(const void *pKey1, int n1, const void *pKey2, int n2){
return sqlite3StrNICmp((const char*)pKey1,(const char*)pKey2,n1);
}
/*
** Hash and comparison functions when the mode is SQLITE_HASH_BINARY
*/
static int binHash(const void *pKey, int nKey){
int h = 0;
const char *z = (const char *)pKey;
while( nKey-- > 0 ){
h = (h<<3) ^ h ^ *(z++);
}
return h & 0x7fffffff;
}
static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
if( n1!=n2 ) return 1;
return memcmp(pKey1,pKey2,n1);
}
/*
** Return a pointer to the appropriate hash function given the key class.
**
** The C syntax in this function definition may be unfamilar to some
** programmers, so we provide the following additional explanation:
**
** The name of the function is "hashFunction". The function takes a
** single parameter "keyClass". The return value of hashFunction()
** is a pointer to another function. Specifically, the return value
** of hashFunction() is a pointer to a function that takes two parameters
** with types "const void*" and "int" and returns an "int".
*/
static int (*hashFunction(int keyClass))(const void*,int){
#if 0 /* HASH_INT and HASH_POINTER are never used */
switch( keyClass ){
case SQLITE_HASH_INT: return &intHash;
case SQLITE_HASH_POINTER: return &ptrHash;
case SQLITE_HASH_STRING: return &strHash;
case SQLITE_HASH_BINARY: return &binHash;;
default: break;
}
return 0;
#else
if( keyClass==SQLITE_HASH_STRING ){
return &strHash;
}else{
assert( keyClass==SQLITE_HASH_BINARY );
return &binHash;
}
#endif
}
/*
** Return a pointer to the appropriate hash function given the key class.
**
** For help in interpreted the obscure C code in the function definition,
** see the header comment on the previous function.
*/
static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
#if 0 /* HASH_INT and HASH_POINTER are never used */
switch( keyClass ){
case SQLITE_HASH_INT: return &intCompare;
case SQLITE_HASH_POINTER: return &ptrCompare;
case SQLITE_HASH_STRING: return &strCompare;
case SQLITE_HASH_BINARY: return &binCompare;
default: break;
}
return 0;
#else
if( keyClass==SQLITE_HASH_STRING ){
return &strCompare;
}else{
assert( keyClass==SQLITE_HASH_BINARY );
return &binCompare;
}
#endif
}
/* Link an element into the hash table
*/
@@ -219,7 +109,6 @@ static void insertElement(
static void rehash(Hash *pH, int new_size){
struct _ht *new_ht; /* The new hash table */
HashElem *elem, *next_elem; /* For looping over existing elements */
int (*xHash)(const void*,int); /* The hash function */
#ifdef SQLITE_MALLOC_SOFT_LIMIT
if( new_size*sizeof(struct _ht)>SQLITE_MALLOC_SOFT_LIMIT ){
@@ -241,9 +130,8 @@ static void rehash(Hash *pH, int new_size){
sqlite3_free(pH->ht);
pH->ht = new_ht;
pH->htsize = new_size;
xHash = hashFunction(pH->keyClass);
for(elem=pH->first, pH->first=0; elem; elem = next_elem){
int h = (*xHash)(elem->pKey, elem->nKey) & (new_size-1);
int h = strHash(elem->pKey, elem->nKey) & (new_size-1);
next_elem = elem->next;
insertElement(pH, &new_ht[h], elem);
}
@@ -261,15 +149,13 @@ static HashElem *findElementGivenHash(
){
HashElem *elem; /* Used to loop thru the element list */
int count; /* Number of elements left to test */
int (*xCompare)(const void*,int,const void*,int); /* comparison function */
if( pH->ht ){
struct _ht *pEntry = &pH->ht[h];
elem = pEntry->chain;
count = pEntry->count;
xCompare = compareFunction(pH->keyClass);
while( count-- && elem ){
if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){
if( strCompare(elem->pKey,elem->nKey,pKey,nKey)==0 ){
return elem;
}
elem = elem->next;
@@ -323,12 +209,9 @@ static void removeElementGivenHash(
HashElem *sqlite3HashFindElem(const Hash *pH, const void *pKey, int nKey){
int h; /* A hash on key */
HashElem *elem; /* The element that matches key */
int (*xHash)(const void*,int); /* The hash function */
if( pH==0 || pH->ht==0 ) return 0;
xHash = hashFunction(pH->keyClass);
assert( xHash!=0 );
h = (*xHash)(pKey,nKey);
h = strHash(pKey,nKey);
elem = findElementGivenHash(pH,pKey,nKey, h % pH->htsize);
return elem;
}
@@ -363,12 +246,9 @@ void *sqlite3HashInsert(Hash *pH, const void *pKey, int nKey, void *data){
int h; /* the hash of the key modulo hash table size */
HashElem *elem; /* Used to loop thru the element list */
HashElem *new_elem; /* New element added to the pH */
int (*xHash)(const void*,int); /* The hash function */
assert( pH!=0 );
xHash = hashFunction(pH->keyClass);
assert( xHash!=0 );
hraw = (*xHash)(pKey, nKey);
hraw = strHash(pKey, nKey);
if( pH->htsize ){
h = hraw % pH->htsize;
elem = findElementGivenHash(pH,pKey,nKey,h);
+9 -32
View File
@@ -12,7 +12,7 @@
** This is the header file for the generic hash-table implemenation
** used in SQLite.
**
** $Id: hash.h,v 1.11 2007/09/04 14:31:47 danielk1977 Exp $
** $Id: hash.h,v 1.12 2008/10/10 17:41:29 drh Exp $
*/
#ifndef _SQLITE_HASH_H_
#define _SQLITE_HASH_H_
@@ -30,14 +30,13 @@ typedef struct HashElem HashElem;
** this structure opaque.
*/
struct Hash {
char keyClass; /* SQLITE_HASH_INT, _POINTER, _STRING, _BINARY */
char copyKey; /* True if copy of key made on insert */
int count; /* Number of entries in this table */
int htsize; /* Number of buckets in the hash table */
HashElem *first; /* The first element of the array */
struct _ht { /* the hash table */
int count; /* Number of entries with this hash */
HashElem *chain; /* Pointer to first entry with this hash */
unsigned int copyKey: 1; /* True if copy of key made on insert */
unsigned int htsize : 31; /* Number of buckets in the hash table */
unsigned int count; /* Number of entries in this table */
HashElem *first; /* The first element of the array */
struct _ht { /* the hash table */
int count; /* Number of entries with this hash */
HashElem *chain; /* Pointer to first entry with this hash */
} *ht;
};
@@ -53,32 +52,10 @@ struct HashElem {
void *pKey; int nKey; /* Key associated with this element */
};
/*
** There are 4 different modes of operation for a hash table:
**
** SQLITE_HASH_INT nKey is used as the key and pKey is ignored.
**
** SQLITE_HASH_POINTER pKey is used as the key and nKey is ignored.
**
** SQLITE_HASH_STRING pKey points to a string that is nKey bytes long
** (including the null-terminator, if any). Case
** is ignored in comparisons.
**
** SQLITE_HASH_BINARY pKey points to binary data nKey bytes long.
** memcmp() is used to compare keys.
**
** A copy of the key is made for SQLITE_HASH_STRING and SQLITE_HASH_BINARY
** if the copyKey parameter to HashInit is 1.
*/
/* #define SQLITE_HASH_INT 1 // NOT USED */
/* #define SQLITE_HASH_POINTER 2 // NOT USED */
#define SQLITE_HASH_STRING 3
#define SQLITE_HASH_BINARY 4
/*
** Access routines. To delete, insert a NULL pointer.
*/
void sqlite3HashInit(Hash*, int keytype, int copyKey);
void sqlite3HashInit(Hash*, int copyKey);
void *sqlite3HashInsert(Hash*, const void *pKey, int nKey, void *pData);
void *sqlite3HashFind(const Hash*, const void *pKey, int nKey);
HashElem *sqlite3HashFindElem(const Hash*, const void *pKey, int nKey);
+11 -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.249 2008/08/20 16:35:10 drh Exp $
** $Id: insert.c,v 1.253 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -430,7 +430,7 @@ void sqlite3Insert(
** inserted into is a view
*/
#ifndef SQLITE_OMIT_TRIGGER
triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0);
triggers_exist = sqlite3TriggersExist(pTab, TK_INSERT, 0);
isView = pTab->pSelect!=0;
#else
# define triggers_exist 0
@@ -936,7 +936,6 @@ void sqlite3Insert(
regIns,
aRegIdx,
0,
0,
(triggers_exist & TRIGGER_AFTER)!=0 ? newIdx : -1,
appendFlag
);
@@ -992,7 +991,7 @@ void sqlite3Insert(
if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", SQLITE_STATIC);
}
insert_cleanup:
@@ -1272,26 +1271,26 @@ void sqlite3GenerateConstraintChecks(
case OE_Fail: {
int j, n1, n2;
char zErrMsg[200];
sqlite3_snprintf(sizeof(zErrMsg), zErrMsg,
sqlite3_snprintf(ArraySize(zErrMsg), zErrMsg,
pIdx->nColumn>1 ? "columns " : "column ");
n1 = strlen(zErrMsg);
for(j=0; j<pIdx->nColumn && n1<sizeof(zErrMsg)-30; j++){
for(j=0; j<pIdx->nColumn && n1<ArraySize(zErrMsg)-30; j++){
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
n2 = strlen(zCol);
if( j>0 ){
sqlite3_snprintf(sizeof(zErrMsg)-n1, &zErrMsg[n1], ", ");
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1], ", ");
n1 += 2;
}
if( n1+n2>sizeof(zErrMsg)-30 ){
sqlite3_snprintf(sizeof(zErrMsg)-n1, &zErrMsg[n1], "...");
if( n1+n2>ArraySize(zErrMsg)-30 ){
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1], "...");
n1 += 3;
break;
}else{
sqlite3_snprintf(sizeof(zErrMsg)-n1, &zErrMsg[n1], "%s", zCol);
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1], "%s", zCol);
n1 += n2;
}
}
sqlite3_snprintf(sizeof(zErrMsg)-n1, &zErrMsg[n1],
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1],
pIdx->nColumn>1 ? " are not unique" : " is not unique");
sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CONSTRAINT, onError, 0, zErrMsg,0);
break;
@@ -1328,7 +1327,6 @@ void sqlite3CompleteInsertion(
int baseCur, /* Index of a read/write cursor pointing at pTab */
int regRowid, /* Range of content */
int *aRegIdx, /* Register used by each index. 0 for unused indices */
int rowidChng, /* True if the record number will change */
int isUpdate, /* True for UPDATE, False for INSERT */
int newIdx, /* Index of NEW table for triggers. -1 if none */
int appendBias /* True if this is likely to be an append */
@@ -1385,7 +1383,7 @@ void sqlite3CompleteInsertion(
int sqlite3OpenTableAndIndices(
Parse *pParse, /* Parsing context */
Table *pTab, /* Table to be opened */
int baseCur, /* Cursor number assigned to the table */
int baseCur, /* Cursor number assigned to the table */
int op /* OP_OpenRead or OP_OpenWrite */
){
int i;
+21 -5
View File
@@ -12,7 +12,7 @@
** This file contains code used to dynamically load extensions into
** the SQLite library.
**
** $Id: loadext.c,v 1.54 2008/09/02 00:52:52 drh Exp $
** $Id: loadext.c,v 1.56 2008/10/12 00:27:53 shane Exp $
*/
#ifndef SQLITE_CORE
@@ -124,7 +124,11 @@
*/
static const sqlite3_api_routines sqlite3Apis = {
sqlite3_aggregate_context,
#ifndef SQLITE_OMIT_DEPRECATED
sqlite3_aggregate_count,
#else
0,
#endif
sqlite3_bind_blob,
sqlite3_bind_double,
sqlite3_bind_int,
@@ -179,7 +183,11 @@ static const sqlite3_api_routines sqlite3Apis = {
sqlite3_errmsg,
sqlite3_errmsg16,
sqlite3_exec,
#ifndef SQLITE_OMIT_DEPRECATED
sqlite3_expired,
#else
0,
#endif
sqlite3_finalize,
sqlite3_free,
sqlite3_free_table,
@@ -219,10 +227,18 @@ static const sqlite3_api_routines sqlite3Apis = {
sqlite3_snprintf,
sqlite3_step,
sqlite3_table_column_metadata,
#ifndef SQLITE_OMIT_DEPRECATED
sqlite3_thread_cleanup,
#else
0,
#endif
sqlite3_total_changes,
sqlite3_trace,
#ifndef SQLITE_OMIT_DEPRECATED
sqlite3_transfer_bindings,
#else
0,
#endif
sqlite3_update_hook,
sqlite3_user_data,
sqlite3_value_blob,
@@ -273,7 +289,7 @@ static const sqlite3_api_routines sqlite3Apis = {
sqlite3_file_control,
sqlite3_memory_highwater,
sqlite3_memory_used,
#ifdef SQLITE_MUTEX_NOOP
#ifdef SQLITE_MUTEX_OMIT
0,
0,
0,
@@ -502,7 +518,7 @@ int sqlite3_auto_extension(void *xInit){
#endif
{
int i;
#ifndef SQLITE_MUTEX_NOOP
#if SQLITE_THREADSAFE
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
wsdAutoextInit;
@@ -536,7 +552,7 @@ void sqlite3_reset_auto_extension(void){
if( sqlite3_initialize()==SQLITE_OK )
#endif
{
#ifndef SQLITE_MUTEX_NOOP
#if SQLITE_THREADSAFE
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
wsdAutoextInit;
@@ -564,7 +580,7 @@ int sqlite3AutoLoadExtensions(sqlite3 *db){
}
for(i=0; go; i++){
char *zErrmsg = 0;
#ifndef SQLITE_MUTEX_NOOP
#if SQLITE_THREADSAFE
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
sqlite3_mutex_enter(mutex);
+68 -30
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.500 2008/09/08 08:08:09 danielk1977 Exp $
** $Id: main.c,v 1.514 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -135,6 +135,8 @@ int sqlite3_initialize(void){
rc = SQLITE_NOMEM;
}
}
}
if( rc==SQLITE_OK ){
sqlite3GlobalConfig.nRefInitMutex++;
}
sqlite3_mutex_leave(pMaster);
@@ -214,12 +216,8 @@ int sqlite3_shutdown(void){
if( sqlite3GlobalConfig.isInit ){
sqlite3_os_end();
}
if( sqlite3GlobalConfig.m.xShutdown ){
sqlite3MallocEnd();
}
if( sqlite3GlobalConfig.mutex.xMutexEnd ){
sqlite3MutexEnd();
}
sqlite3MallocEnd();
sqlite3MutexEnd();
sqlite3GlobalConfig.isInit = 0;
return SQLITE_OK;
}
@@ -243,6 +241,11 @@ int sqlite3_config(int op, ...){
va_start(ap, op);
switch( op ){
/* Mutex configuration options are only available in a threadsafe
** compile.
*/
#if SQLITE_THREADSAFE
case SQLITE_CONFIG_SINGLETHREAD: {
/* Disable all mutexing */
sqlite3GlobalConfig.bCoreMutex = 0;
@@ -262,6 +265,19 @@ int sqlite3_config(int op, ...){
sqlite3GlobalConfig.bFullMutex = 1;
break;
}
case SQLITE_CONFIG_MUTEX: {
/* Specify an alternative mutex implementation */
sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
break;
}
case SQLITE_CONFIG_GETMUTEX: {
/* Retrieve the current mutex implementation */
*va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
break;
}
#endif
case SQLITE_CONFIG_MALLOC: {
/* Specify an alternative malloc implementation */
sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
@@ -273,16 +289,6 @@ int sqlite3_config(int op, ...){
*va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
break;
}
case SQLITE_CONFIG_MUTEX: {
/* Specify an alternative mutex implementation */
sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
break;
}
case SQLITE_CONFIG_GETMUTEX: {
/* Retrieve the current mutex implementation */
*va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
break;
}
case SQLITE_CONFIG_MEMSTATUS: {
/* Enable or disable the malloc status collection */
sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
@@ -303,6 +309,20 @@ int sqlite3_config(int op, ...){
break;
}
case SQLITE_CONFIG_PCACHE: {
/* Specify an alternative malloc implementation */
sqlite3GlobalConfig.pcache = *va_arg(ap, sqlite3_pcache_methods*);
break;
}
case SQLITE_CONFIG_GETPCACHE: {
if( sqlite3GlobalConfig.pcache.xInit==0 ){
sqlite3PCacheSetDefault();
}
*va_arg(ap, sqlite3_pcache_methods*) = sqlite3GlobalConfig.pcache;
break;
}
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
case SQLITE_CONFIG_HEAP: {
/* Designate a buffer for heap memory space */
@@ -334,14 +354,6 @@ int sqlite3_config(int op, ...){
}
#endif
#if defined(SQLITE_ENABLE_MEMSYS6)
case SQLITE_CONFIG_CHUNKALLOC: {
sqlite3GlobalConfig.nSmall = va_arg(ap, int);
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys6();
break;
}
#endif
case SQLITE_CONFIG_LOOKASIDE: {
sqlite3GlobalConfig.szLookaside = va_arg(ap, int);
sqlite3GlobalConfig.nLookaside = va_arg(ap, int);
@@ -409,6 +421,13 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
return SQLITE_OK;
}
/*
** Return the mutex associated with a database connection.
*/
sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
return db->mutex;
}
/*
** Configuration settings for an individual database connection
*/
@@ -496,6 +515,7 @@ static int nocaseCollatingFunc(
){
int r = sqlite3StrNICmp(
(const char *)pKey1, (const char *)pKey2, (nKey1<nKey2)?nKey1:nKey2);
UNUSED_PARAMETER(NotUsed);
if( 0==r ){
r = nKey1-nKey2;
}
@@ -629,6 +649,7 @@ int sqlite3_close(sqlite3 *db){
sqlite3_mutex_leave(db->mutex);
db->magic = SQLITE_MAGIC_CLOSED;
sqlite3_mutex_free(db->mutex);
assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
if( db->lookaside.bMalloced ){
sqlite3_free(db->lookaside.pStart);
}
@@ -1259,6 +1280,15 @@ int sqlite3_errcode(sqlite3 *db){
}
return db->errCode & db->errMask;
}
int sqlite3_extended_errcode(sqlite3 *db){
if( db && !sqlite3SafetyCheckSickOrOk(db) ){
return SQLITE_MISUSE;
}
if( !db || db->mallocFailed ){
return SQLITE_NOMEM;
}
return db->errCode;
}
/*
** Create a new collating function for database "db". The name is zName
@@ -1373,8 +1403,8 @@ static const int aHardLimit[] = {
#if SQLITE_MAX_VDBE_OP<40
# error SQLITE_MAX_VDBE_OP must be at least 40
#endif
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>127
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 127
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000
#endif
#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>30
# error SQLITE_MAX_ATTACHED must be between 0 and 30
@@ -1490,9 +1520,9 @@ static int openDatabase(
| SQLITE_LoadExtension
#endif
;
sqlite3HashInit(&db->aCollSeq, SQLITE_HASH_STRING, 0);
sqlite3HashInit(&db->aCollSeq, 0);
#ifndef SQLITE_OMIT_VIRTUALTABLE
sqlite3HashInit(&db->aModule, SQLITE_HASH_STRING, 0);
sqlite3HashInit(&db->aModule, 0);
#endif
db->pVfs = sqlite3_vfs_find(zVfs);
@@ -1532,6 +1562,9 @@ static int openDatabase(
flags | SQLITE_OPEN_MAIN_DB,
&db->aDb[0].pBt);
if( rc!=SQLITE_OK ){
if( rc==SQLITE_IOERR_NOMEM ){
rc = SQLITE_NOMEM;
}
sqlite3Error(db, rc, 0);
goto opendb_out;
}
@@ -1614,7 +1647,8 @@ static int openDatabase(
#endif
/* Enable the lookaside-malloc subsystem */
setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside, sqlite3GlobalConfig.nLookaside);
setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
sqlite3GlobalConfig.nLookaside);
opendb_out:
if( db ){
@@ -1791,6 +1825,7 @@ int sqlite3_collation_needed16(
#endif /* SQLITE_OMIT_UTF16 */
#ifndef SQLITE_OMIT_GLOBALRECOVER
#ifndef SQLITE_OMIT_DEPRECATED
/*
** This function is now an anachronism. It used to be used to recover from a
** malloc() failure, but SQLite now does this automatically.
@@ -1799,6 +1834,7 @@ int sqlite3_global_recover(void){
return SQLITE_OK;
}
#endif
#endif
/*
** Test to see whether or not the database connection is in autocommit
@@ -1823,6 +1859,7 @@ int sqlite3Corrupt(void){
}
#endif
#ifndef SQLITE_OMIT_DEPRECATED
/*
** This is a convenience routine that makes sure that all thread-specific
** data for this thread has been deallocated.
@@ -1832,6 +1869,7 @@ int sqlite3Corrupt(void){
*/
void sqlite3_thread_cleanup(void){
}
#endif
/*
** Return meta information about a specific column of a database table.
+33 -5
View File
@@ -12,7 +12,7 @@
**
** Memory allocation functions used throughout sqlite.
**
** $Id: malloc.c,v 1.41 2008/09/04 04:32:49 shane Exp $
** $Id: malloc.c,v 1.48 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -25,9 +25,10 @@
*/
static void softHeapLimitEnforcer(
void *NotUsed,
sqlite3_int64 inUse,
sqlite3_int64 NotUsed2,
int allocSize
){
UNUSED_PARAMETER2(NotUsed, NotUsed2);
sqlite3_release_memory(allocSize);
}
@@ -69,6 +70,7 @@ int sqlite3_release_memory(int n){
nRet += sqlite3PcacheReleaseMemory(n-nRet);
return nRet;
#else
UNUSED_PARAMETER(n);
return SQLITE_OK;
#endif
}
@@ -102,7 +104,7 @@ static SQLITE_WSD struct Mem0Global {
*/
u32 *aScratchFree;
u32 *aPageFree;
} mem0 = { 62560955 };
} mem0 = { 62560955, 0, 0, 0, 0, 0, 0, 0, 0 };
#define mem0 GLOBAL(struct Mem0Global, mem0)
@@ -196,6 +198,7 @@ int sqlite3MemoryAlarm(
return SQLITE_OK;
}
#ifndef SQLITE_OMIT_DEPRECATED
/*
** Deprecated external interface. Internal/core SQLite code
** should call sqlite3MemoryAlarm.
@@ -207,6 +210,7 @@ int sqlite3_memory_alarm(
){
return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
}
#endif
/*
** Trigger the alarm
@@ -385,7 +389,7 @@ void sqlite3ScratchFree(void *p){
i /= sqlite3GlobalConfig.szScratch;
assert( i>=0 && i<sqlite3GlobalConfig.nScratch );
sqlite3_mutex_enter(mem0.mutex);
assert( mem0.nScratchFree<sqlite3GlobalConfig.nScratch );
assert( mem0.nScratchFree<(u32)sqlite3GlobalConfig.nScratch );
mem0.aScratchFree[mem0.nScratchFree++] = i;
sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
sqlite3_mutex_leave(mem0.mutex);
@@ -485,9 +489,13 @@ void sqlite3PageFree(void *p){
/*
** TRUE if p is a lookaside memory allocation from db
*/
#ifndef SQLITE_OMIT_LOOKASIDE
static int isLookaside(sqlite3 *db, void *p){
return db && p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
}
#else
#define isLookaside(A,B) 0
#endif
/*
** Return the size of a memory allocation previously obtained from
@@ -614,9 +622,24 @@ void *sqlite3DbMallocZero(sqlite3 *db, int n){
/*
** Allocate and zero memory. If the allocation fails, make
** the mallocFailed flag in the connection pointer.
**
** If db!=0 and db->mallocFailed is true (indicating a prior malloc
** failure on the same database connection) then always return 0.
** Hence for a particular database connection, once malloc starts
** failing, it fails consistently until mallocFailed is reset.
** This is an important assumption. There are many places in the
** code that do things like this:
**
** int *a = (int*)sqlite3DbMallocRaw(db, 100);
** int *b = (int*)sqlite3DbMallocRaw(db, 200);
** if( b ) a[10] = 9;
**
** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
** that all prior mallocs (ex: "a") worked too.
*/
void *sqlite3DbMallocRaw(sqlite3 *db, int n){
void *p;
#ifndef SQLITE_OMIT_LOOKASIDE
if( db ){
LookasideSlot *pBuf;
if( db->mallocFailed ){
@@ -632,6 +655,11 @@ void *sqlite3DbMallocRaw(sqlite3 *db, int n){
return (void*)pBuf;
}
}
#else
if( db && db->mallocFailed ){
return 0;
}
#endif
p = sqlite3Malloc(n);
if( !p && db ){
db->mallocFailed = 1;
@@ -752,7 +780,7 @@ int sqlite3ApiExit(sqlite3* db, int rc){
** is unsafe, as is the call to sqlite3Error().
*/
assert( !db || sqlite3_mutex_held(db->mutex) );
if( db && db->mallocFailed ){
if( db && (db->mallocFailed || rc==SQLITE_IOERR_NOMEM) ){
sqlite3Error(db, SQLITE_NOMEM, 0);
db->mallocFailed = 0;
rc = SQLITE_NOMEM;
+61
View File
@@ -0,0 +1,61 @@
/*
** 2008 October 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 contains a no-op memory allocation drivers for use when
** SQLITE_ZERO_MALLOC is defined. The allocation drivers implemented
** here always fail. SQLite will not operate with these drivers. These
** are merely placeholders. Real drivers must be substituted using
** sqlite3_config() before SQLite will operate.
**
** $Id: mem0.c,v 1.1 2008/10/28 18:58:20 drh Exp $
*/
#include "sqliteInt.h"
/*
** This version of the memory allocator is the default. It is
** used when no other memory allocator is specified using compile-time
** macros.
*/
#ifdef SQLITE_ZERO_MALLOC
/*
** No-op versions of all memory allocation routines
*/
static void *sqlite3MemMalloc(int nByte){ return 0; }
static void sqlite3MemFree(void *pPrior){ return; }
static void *sqlite3MemRealloc(void *pPrior, int nByte){ return 0; }
static int sqlite3MemSize(void *pPrior){ return 0; }
static int sqlite3MemRoundup(int n){ return n; }
static int sqlite3MemInit(void *NotUsed){ return SQLITE_OK; }
static void sqlite3MemShutdown(void *NotUsed){ return; }
/*
** This routine is the only routine in this file with external linkage.
**
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file.
*/
void sqlite3MemSetDefault(void){
static const sqlite3_mem_methods defaultMethods = {
sqlite3MemMalloc,
sqlite3MemFree,
sqlite3MemRealloc,
sqlite3MemSize,
sqlite3MemRoundup,
sqlite3MemInit,
sqlite3MemShutdown,
0
};
sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
}
#endif /* SQLITE_ZERO_MALLOC */
+11 -13
View File
@@ -17,7 +17,7 @@
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.
**
** $Id: mem1.c,v 1.26 2008/09/01 18:34:20 danielk1977 Exp $
** $Id: mem1.c,v 1.28 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -110,6 +110,7 @@ static int sqlite3MemRoundup(int n){
** Initialize this module.
*/
static int sqlite3MemInit(void *NotUsed){
UNUSED_PARAMETER(NotUsed);
return SQLITE_OK;
}
@@ -117,10 +118,17 @@ static int sqlite3MemInit(void *NotUsed){
** Deinitialize this module.
*/
static void sqlite3MemShutdown(void *NotUsed){
UNUSED_PARAMETER(NotUsed);
return;
}
const sqlite3_mem_methods *sqlite3MemGetDefault(void){
/*
** This routine is the only routine in this file with external linkage.
**
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file.
*/
void sqlite3MemSetDefault(void){
static const sqlite3_mem_methods defaultMethods = {
sqlite3MemMalloc,
sqlite3MemFree,
@@ -131,17 +139,7 @@ const sqlite3_mem_methods *sqlite3MemGetDefault(void){
sqlite3MemShutdown,
0
};
return &defaultMethods;
}
/*
** This routine is the only routine in this file with external linkage.
**
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file.
*/
void sqlite3MemSetDefault(void){
sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetDefault());
sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
}
#endif /* SQLITE_SYSTEM_MALLOC */
+7 -12
View File
@@ -19,7 +19,7 @@
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.
**
** $Id: mem2.c,v 1.39 2008/09/01 18:34:20 danielk1977 Exp $
** $Id: mem2.c,v 1.40 2008/10/28 18:58:20 drh Exp $
*/
#include "sqliteInt.h"
@@ -323,8 +323,11 @@ static void *sqlite3MemRealloc(void *pPrior, int nByte){
return pNew;
}
const sqlite3_mem_methods *sqlite3MemGetDefault(void){
/*
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file.
*/
void sqlite3MemSetDefault(void){
static const sqlite3_mem_methods defaultMethods = {
sqlite3MemMalloc,
sqlite3MemFree,
@@ -335,15 +338,7 @@ const sqlite3_mem_methods *sqlite3MemGetDefault(void){
sqlite3MemShutdown,
0
};
return &defaultMethods;
}
/*
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file.
*/
void sqlite3MemSetDefault(void){
sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetDefault());
sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
}
/*
+10 -6
View File
@@ -23,7 +23,7 @@
** This version of the memory allocation subsystem is included
** in the build only if SQLITE_ENABLE_MEMSYS3 is defined.
**
** $Id: mem3.c,v 1.23 2008/09/02 17:52:52 danielk1977 Exp $
** $Id: mem3.c,v 1.25 2008/11/19 16:52:44 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -251,7 +251,7 @@ static void memsys3OutOfMemory(int nByte){
** size parameters for check-out and return a pointer to the
** user portion of the chunk.
*/
static void *memsys3Checkout(u32 i, int nBlock){
static void *memsys3Checkout(u32 i, u32 nBlock){
u32 x;
assert( sqlite3_mutex_held(mem3.mutex) );
assert( i>=1 );
@@ -269,7 +269,7 @@ static void *memsys3Checkout(u32 i, int nBlock){
** Return a pointer to the new allocation. Or, if the master chunk
** is not large enough, return 0.
*/
static void *memsys3FromMaster(int nBlock){
static void *memsys3FromMaster(u32 nBlock){
assert( sqlite3_mutex_held(mem3.mutex) );
assert( mem3.szMaster>=nBlock );
if( nBlock>=mem3.szMaster-1 ){
@@ -355,8 +355,8 @@ static void memsys3Merge(u32 *pRoot){
*/
static void *memsys3MallocUnsafe(int nByte){
u32 i;
int nBlock;
int toFree;
u32 nBlock;
u32 toFree;
assert( sqlite3_mutex_held(mem3.mutex) );
assert( sizeof(Mem3Block)==8 );
@@ -552,6 +552,7 @@ void *memsys3Realloc(void *pPrior, int nBytes){
** Initialize this module.
*/
static int memsys3Init(void *NotUsed){
UNUSED_PARAMETER(NotUsed);
if( !sqlite3GlobalConfig.pHeap ){
return SQLITE_ERROR;
}
@@ -576,6 +577,7 @@ static int memsys3Init(void *NotUsed){
** Deinitialize this module.
*/
static void memsys3Shutdown(void *NotUsed){
UNUSED_PARAMETER(NotUsed);
return;
}
@@ -588,7 +590,7 @@ static void memsys3Shutdown(void *NotUsed){
void sqlite3Memsys3Dump(const char *zFilename){
#ifdef SQLITE_DEBUG
FILE *out;
int i, j;
u32 i, j;
u32 size;
if( zFilename==0 || zFilename[0]==0 ){
out = stdout;
@@ -653,6 +655,8 @@ void sqlite3Memsys3Dump(const char *zFilename){
}else{
fclose(out);
}
#else
UNUSED_PARAMETER(zFilename);
#endif
}
-393
View File
@@ -1,393 +0,0 @@
/*
** 2007 August 14
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement a memory
** allocation subsystem for use by SQLite.
**
** $Id: mem4.c,v 1.3 2008/06/18 17:09:10 danielk1977 Exp $
*/
#include "sqliteInt.h"
/*
** This version of the memory allocator attempts to obtain memory
** from mmap() if the size of the allocation is close to the size
** of a virtual memory page. If the size of the allocation is different
** from the virtual memory page size, then ordinary malloc() is used.
** Ordinary malloc is also used if space allocated to mmap() is
** exhausted.
**
** Enable this memory allocation by compiling with -DSQLITE_MMAP_HEAP_SIZE=nnn
** where nnn is the maximum number of bytes of mmap-ed memory you want
** to support. This module may choose to use less memory than requested.
**
*/
#ifdef SQLITE_MMAP_HEAP_SIZE
/*
** This is a test version of the memory allocator that attempts to
** use mmap() and madvise() for allocations and frees of approximately
** the virtual memory page size.
*/
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <unistd.h>
/*
** All of the static variables used by this module are collected
** into a single structure named "mem". This is to keep the
** static variables organized and to reduce namespace pollution
** when this module is combined with other in the amalgamation.
*/
static struct {
/*
** The alarm callback and its arguments. The mem.mutex lock will
** be held while the callback is running. Recursive calls into
** the memory subsystem are allowed, but no new callbacks will be
** issued. The alarmBusy variable is set to prevent recursive
** callbacks.
*/
sqlite3_int64 alarmThreshold;
void (*alarmCallback)(void*, sqlite3_int64,int);
void *alarmArg;
int alarmBusy;
/*
** Mutex to control access to the memory allocation subsystem.
*/
sqlite3_mutex *mutex;
/*
** Current allocation and high-water mark.
*/
sqlite3_int64 nowUsed;
sqlite3_int64 mxUsed;
/*
** Current allocation and high-water marks for mmap allocated memory.
*/
sqlite3_int64 nowUsedMMap;
sqlite3_int64 mxUsedMMap;
/*
** Size of a single mmap page. Obtained from sysconf().
*/
int szPage;
int mnPage;
/*
** The number of available mmap pages.
*/
int nPage;
/*
** Index of the first free page. 0 means no pages have been freed.
*/
int firstFree;
/* First unused page on the top of the heap.
*/
int firstUnused;
/*
** Bulk memory obtained from from mmap().
*/
char *mmapHeap; /* first byte of the heap */
} mem;
/*
** Enter the mutex mem.mutex. Allocate it if it is not already allocated.
** The mmap() region is initialized the first time this routine is called.
*/
static void memsys4Enter(void){
if( mem.mutex==0 ){
mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
}
sqlite3_mutex_enter(mem.mutex);
}
/*
** Attempt to free memory to the mmap heap. This only works if
** the pointer p is within the range of memory addresses that
** comprise the mmap heap. Return 1 if the memory was freed
** successfully. Return 0 if the pointer is out of range.
*/
static int mmapFree(void *p){
char *z;
int idx, *a;
if( mem.mmapHeap==MAP_FAILED || mem.nPage==0 ){
return 0;
}
z = (char*)p;
idx = (z - mem.mmapHeap)/mem.szPage;
if( idx<1 || idx>=mem.nPage ){
return 0;
}
a = (int*)mem.mmapHeap;
a[idx] = a[mem.firstFree];
mem.firstFree = idx;
mem.nowUsedMMap -= mem.szPage;
madvise(p, mem.szPage, MADV_DONTNEED);
return 1;
}
/*
** Attempt to allocate nBytes from the mmap heap. Return a pointer
** to the allocated page. Or, return NULL if the allocation fails.
**
** The allocation will fail if nBytes is not the right size.
** Or, the allocation will fail if the mmap heap has been exhausted.
*/
static void *mmapAlloc(int nBytes){
int idx = 0;
if( nBytes>mem.szPage || nBytes<mem.mnPage ){
return 0;
}
if( mem.nPage==0 ){
mem.szPage = sysconf(_SC_PAGE_SIZE);
mem.mnPage = mem.szPage - mem.szPage/10;
mem.nPage = SQLITE_MMAP_HEAP_SIZE/mem.szPage;
if( mem.nPage * sizeof(int) > mem.szPage ){
mem.nPage = mem.szPage/sizeof(int);
}
mem.mmapHeap = mmap(0, mem.szPage*mem.nPage, PROT_WRITE|PROT_READ,
MAP_ANONYMOUS|MAP_SHARED, -1, 0);
if( mem.mmapHeap==MAP_FAILED ){
mem.firstUnused = errno;
}else{
mem.firstUnused = 1;
mem.nowUsedMMap = mem.szPage;
}
}
if( mem.mmapHeap==MAP_FAILED ){
return 0;
}
if( mem.firstFree ){
int idx = mem.firstFree;
int *a = (int*)mem.mmapHeap;
mem.firstFree = a[idx];
}else if( mem.firstUnused<mem.nPage ){
idx = mem.firstUnused++;
}
if( idx ){
mem.nowUsedMMap += mem.szPage;
if( mem.nowUsedMMap>mem.mxUsedMMap ){
mem.mxUsedMMap = mem.nowUsedMMap;
}
return (void*)&mem.mmapHeap[idx*mem.szPage];
}else{
return 0;
}
}
/*
** Release the mmap-ed memory region if it is currently allocated and
** is not in use.
*/
static void mmapUnmap(void){
if( mem.mmapHeap==MAP_FAILED ) return;
if( mem.nPage==0 ) return;
if( mem.nowUsedMMap>mem.szPage ) return;
munmap(mem.mmapHeap, mem.nPage*mem.szPage);
mem.nowUsedMMap = 0;
mem.nPage = 0;
}
/*
** Return the amount of memory currently checked out.
*/
sqlite3_int64 sqlite3_memory_used(void){
sqlite3_int64 n;
memsys4Enter();
n = mem.nowUsed + mem.nowUsedMMap;
sqlite3_mutex_leave(mem.mutex);
return n;
}
/*
** Return the maximum amount of memory that has ever been
** checked out since either the beginning of this process
** or since the most recent reset.
*/
sqlite3_int64 sqlite3_memory_highwater(int resetFlag){
sqlite3_int64 n;
memsys4Enter();
n = mem.mxUsed + mem.mxUsedMMap;
if( resetFlag ){
mem.mxUsed = mem.nowUsed;
mem.mxUsedMMap = mem.nowUsedMMap;
}
sqlite3_mutex_leave(mem.mutex);
return n;
}
/*
** Change the alarm callback
*/
int sqlite3_memory_alarm(
void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
void *pArg,
sqlite3_int64 iThreshold
){
memsys4Enter();
mem.alarmCallback = xCallback;
mem.alarmArg = pArg;
mem.alarmThreshold = iThreshold;
sqlite3_mutex_leave(mem.mutex);
return SQLITE_OK;
}
/*
** Trigger the alarm
*/
static void sqlite3MemsysAlarm(int nByte){
void (*xCallback)(void*,sqlite3_int64,int);
sqlite3_int64 nowUsed;
void *pArg;
if( mem.alarmCallback==0 || mem.alarmBusy ) return;
mem.alarmBusy = 1;
xCallback = mem.alarmCallback;
nowUsed = mem.nowUsed;
pArg = mem.alarmArg;
sqlite3_mutex_leave(mem.mutex);
xCallback(pArg, nowUsed, nByte);
sqlite3_mutex_enter(mem.mutex);
mem.alarmBusy = 0;
}
/*
** Allocate nBytes of memory
*/
static void *memsys4Malloc(int nBytes){
sqlite3_int64 *p = 0;
if( mem.alarmCallback!=0
&& mem.nowUsed+mem.nowUsedMMap+nBytes>=mem.alarmThreshold ){
sqlite3MemsysAlarm(nBytes);
}
if( (p = mmapAlloc(nBytes))==0 ){
p = malloc(nBytes+8);
if( p==0 ){
sqlite3MemsysAlarm(nBytes);
p = malloc(nBytes+8);
}
if( p ){
p[0] = nBytes;
p++;
mem.nowUsed += nBytes;
if( mem.nowUsed>mem.mxUsed ){
mem.mxUsed = mem.nowUsed;
}
}
}
return (void*)p;
}
/*
** Return the size of a memory allocation
*/
static int memsys4Size(void *pPrior){
char *z = (char*)pPrior;
int idx = mem.nPage ? (z - mem.mmapHeap)/mem.szPage : 0;
int nByte;
if( idx>=1 && idx<mem.nPage ){
nByte = mem.szPage;
}else{
sqlite3_int64 *p = pPrior;
p--;
nByte = (int)*p;
}
return nByte;
}
/*
** Free memory.
*/
static void memsys4Free(void *pPrior){
sqlite3_int64 *p;
int nByte;
if( mmapFree(pPrior)==0 ){
p = pPrior;
p--;
nByte = (int)*p;
mem.nowUsed -= nByte;
free(p);
if( mem.nowUsed==0 ){
mmapUnmap();
}
}
}
/*
** Allocate nBytes of memory
*/
void *sqlite3_malloc(int nBytes){
sqlite3_int64 *p = 0;
if( nBytes>0 ){
memsys4Enter();
p = memsys4Malloc(nBytes);
sqlite3_mutex_leave(mem.mutex);
}
return (void*)p;
}
/*
** Free memory.
*/
void sqlite3_free(void *pPrior){
if( pPrior==0 ){
return;
}
assert( mem.mutex!=0 );
sqlite3_mutex_enter(mem.mutex);
memsys4Free(pPrior);
sqlite3_mutex_leave(mem.mutex);
}
/*
** Change the size of an existing memory allocation
*/
void *sqlite3_realloc(void *pPrior, int nBytes){
int nOld;
sqlite3_int64 *p;
if( pPrior==0 ){
return sqlite3_malloc(nBytes);
}
if( nBytes<=0 ){
sqlite3_free(pPrior);
return 0;
}
nOld = memsys4Size(pPrior);
if( nBytes<=nOld && nBytes>=nOld-128 ){
return pPrior;
}
assert( mem.mutex!=0 );
sqlite3_mutex_enter(mem.mutex);
p = memsys4Malloc(nBytes);
if( p ){
if( nOld<nBytes ){
memcpy(p, pPrior, nOld);
}else{
memcpy(p, pPrior, nBytes);
}
memsys4Free(pPrior);
}
assert( mem.mutex!=0 );
sqlite3_mutex_leave(mem.mutex);
return (void*)p;
}
#endif /* SQLITE_MMAP_HEAP_SIZE */
+11 -29
View File
@@ -23,38 +23,16 @@
** This version of the memory allocation subsystem is included
** in the build only if SQLITE_ENABLE_MEMSYS5 is defined.
**
** $Id: mem5.c,v 1.14 2008/09/02 17:52:52 danielk1977 Exp $
** $Id: mem5.c,v 1.19 2008/11/19 16:52:44 danielk1977 Exp $
*/
#include "sqliteInt.h"
/*
** This version of the memory allocator is used only when
** SQLITE_POW2_MEMORY_SIZE is defined.
** SQLITE_ENABLE_MEMSYS5 is defined.
*/
#ifdef SQLITE_ENABLE_MEMSYS5
/*
** Log2 of the minimum size of an allocation. For example, if
** 4 then all allocations will be rounded up to at least 16 bytes.
** If 5 then all allocations will be rounded up to at least 32 bytes.
*/
#ifndef SQLITE_POW2_LOGMIN
# define SQLITE_POW2_LOGMIN 6
#endif
/*
** Log2 of the maximum size of an allocation.
*/
#ifndef SQLITE_POW2_LOGMAX
# define SQLITE_POW2_LOGMAX 20
#endif
#define POW2_MAX (((unsigned int)1)<<SQLITE_POW2_LOGMAX)
/*
** Number of distinct allocation sizes.
*/
#define NSIZE (SQLITE_POW2_LOGMAX - SQLITE_POW2_LOGMIN + 1)
/*
** A minimum allocation is an instance of the following structure.
** Larger allocations are an array of these structures where the
@@ -230,12 +208,11 @@ static void *memsys5MallocUnsafe(int nByte){
/* Keep track of the maximum allocation request. Even unfulfilled
** requests are counted */
if( nByte>mem5.maxRequest ){
if( (u32)nByte>mem5.maxRequest ){
mem5.maxRequest = nByte;
}
/* Round nByte up to the next valid power of two */
if( nByte>POW2_MAX ) return 0;
for(iFullSz=mem5.nAtom, iLogsize=0; iFullSz<nByte; iFullSz *= 2, iLogsize++){}
/* Make sure mem5.aiFreelist[iLogsize] contains at least one free
@@ -287,12 +264,12 @@ static void memsys5FreeUnsafe(void *pOld){
iLogsize = mem5.aCtrl[iBlock] & CTRL_LOGSIZE;
size = 1<<iLogsize;
assert( iBlock+size-1<mem5.nBlock );
assert( iBlock+size-1<(u32)mem5.nBlock );
mem5.aCtrl[iBlock] |= CTRL_FREE;
mem5.aCtrl[iBlock+size-1] |= CTRL_FREE;
assert( mem5.currentCount>0 );
assert( mem5.currentOut>=0 );
assert( mem5.currentOut>=(size*mem5.nAtom) );
mem5.currentCount--;
mem5.currentOut -= size*mem5.nAtom;
assert( mem5.currentOut>0 || mem5.currentCount==0 );
@@ -402,13 +379,15 @@ static int memsys5Init(void *NotUsed){
int nMinLog; /* Log of minimum allocation size in bytes*/
int iOffset;
UNUSED_PARAMETER(NotUsed);
if( !zByte ){
return SQLITE_ERROR;
}
nMinLog = memsys5Log(sqlite3GlobalConfig.mnReq);
mem5.nAtom = (1<<nMinLog);
while( sizeof(Mem5Link)>mem5.nAtom ){
while( (int)sizeof(Mem5Link)>mem5.nAtom ){
mem5.nAtom = mem5.nAtom << 1;
}
@@ -438,6 +417,7 @@ static int memsys5Init(void *NotUsed){
** Deinitialize this module.
*/
static void memsys5Shutdown(void *NotUsed){
UNUSED_PARAMETER(NotUsed);
return;
}
@@ -481,6 +461,8 @@ void sqlite3Memsys5Dump(const char *zFilename){
}else{
fclose(out);
}
#else
UNUSED_PARAMETER(zFilename);
#endif
}
-498
View File
@@ -1,498 +0,0 @@
/*
** 2008 July 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 contains an alternative memory allocation system for SQLite.
** This system is implemented as a wrapper around the system provided
** by the operating system - vanilla malloc(), realloc() and free().
**
** This system differentiates between requests for "small" allocations
** (by default those of 128 bytes or less) and "large" allocations (all
** others). The 256 byte threshhold is configurable at runtime.
**
** All requests for large allocations are passed through to the
** default system.
**
** Requests for small allocations are met by allocating space within
** one or more larger "chunks" of memory obtained from the default
** memory allocation system. Chunks of memory are usually 64KB or
** larger. The algorithm used to manage space within each chunk is
** the same as that used by mem5.c.
**
** This strategy is designed to prevent the default memory allocation
** system (usually the system malloc) from suffering from heap
** fragmentation. On some systems, heap fragmentation can cause a
** significant real-time slowdown.
**
** $Id: mem6.c,v 1.10 2008/09/02 17:52:52 danielk1977 Exp $
*/
#ifdef SQLITE_ENABLE_MEMSYS6
#include "sqliteInt.h"
/*
** Maximum size of any "small" allocation is ((1<<LOGMAX)*Mem6Chunk.nAtom).
** Mem6Chunk.nAtom is always at least 8, so this is not a practical
** limitation
*/
#define LOGMAX 30
/*
** Default value for the "small" allocation size threshold.
*/
#define SMALL_MALLOC_DEFAULT_THRESHOLD 256
/*
** Minimum size for a memory chunk.
*/
#define MIN_CHUNKSIZE (1<<16)
#define LOG2_MINALLOC 4
typedef struct Mem6Chunk Mem6Chunk;
typedef struct Mem6Link Mem6Link;
/*
** A minimum allocation is an instance of the following structure.
** Larger allocations are an array of these structures where the
** size of the array is a power of 2.
*/
struct Mem6Link {
int next; /* Index of next free chunk */
int prev; /* Index of previous free chunk */
};
/*
** Masks used for mem5.aCtrl[] elements.
*/
#define CTRL_LOGSIZE 0x1f /* Log2 Size of this block relative to POW2_MIN */
#define CTRL_FREE 0x20 /* True if not checked out */
struct Mem6Chunk {
Mem6Chunk *pNext;
/*
** Lists of free blocks of various sizes.
*/
int aiFreelist[LOGMAX+1];
int nCheckedOut; /* Number of currently outstanding allocations */
/*
** Space for tracking which blocks are checked out and the size
** of each block. One byte per block.
*/
u8 *aCtrl;
/*
** Memory available for allocation
*/
int nAtom; /* Smallest possible allocation in bytes */
int nBlock; /* Number of nAtom sized blocks in zPool */
u8 *zPool; /* Pointer to memory chunk from which allocations are made */
};
#define MEM6LINK(idx) ((Mem6Link *)(&pChunk->zPool[(idx)*pChunk->nAtom]))
static SQLITE_WSD struct Mem6Global {
int nMinAlloc; /* Minimum allowed allocation size */
int nThreshold; /* Allocs larger than this go to malloc() */
int nLogThreshold; /* log2 of (nThreshold/nMinAlloc) */
sqlite3_mutex *mutex;
Mem6Chunk *pChunk; /* Singly linked list of all memory chunks */
} mem6 = { 48642791 };
#define mem6 GLOBAL(struct Mem6Global, mem6)
/*
** Unlink the chunk at pChunk->aPool[i] from list it is currently
** on. It should be found on pChunk->aiFreelist[iLogsize].
*/
static void memsys6Unlink(Mem6Chunk *pChunk, int i, int iLogsize){
int next, prev;
assert( i>=0 && i<pChunk->nBlock );
assert( iLogsize>=0 && iLogsize<=mem6.nLogThreshold );
assert( (pChunk->aCtrl[i] & CTRL_LOGSIZE)==iLogsize );
next = MEM6LINK(i)->next;
prev = MEM6LINK(i)->prev;
if( prev<0 ){
pChunk->aiFreelist[iLogsize] = next;
}else{
MEM6LINK(prev)->next = next;
}
if( next>=0 ){
MEM6LINK(next)->prev = prev;
}
}
/*
** Link the chunk at mem5.aPool[i] so that is on the iLogsize
** free list.
*/
static void memsys6Link(Mem6Chunk *pChunk, int i, int iLogsize){
int x;
assert( i>=0 && i<pChunk->nBlock );
assert( iLogsize>=0 && iLogsize<=mem6.nLogThreshold );
assert( (pChunk->aCtrl[i] & CTRL_LOGSIZE)==iLogsize );
x = MEM6LINK(i)->next = pChunk->aiFreelist[iLogsize];
MEM6LINK(i)->prev = -1;
if( x>=0 ){
assert( x<pChunk->nBlock );
MEM6LINK(x)->prev = i;
}
pChunk->aiFreelist[iLogsize] = i;
}
/*
** Find the first entry on the freelist iLogsize. Unlink that
** entry and return its index.
*/
static int memsys6UnlinkFirst(Mem6Chunk *pChunk, int iLogsize){
int i;
int iFirst;
assert( iLogsize>=0 && iLogsize<=mem6.nLogThreshold );
i = iFirst = pChunk->aiFreelist[iLogsize];
assert( iFirst>=0 );
memsys6Unlink(pChunk, iFirst, iLogsize);
return iFirst;
}
static int roundupLog2(int n){
static const char LogTable256[256] = {
0, /* 1 */
1, /* 2 */
2, 2, /* 3..4 */
3, 3, 3, 3, /* 5..8 */
4, 4, 4, 4, 4, 4, 4, 4, /* 9..16 */
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, /* 17..32 */
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, /* 33..64 */
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* 65..128 */
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, /* 129..256 */
};
assert(n<=(1<<16) && n>0);
if( n<=256 ) return LogTable256[n-1];
return LogTable256[(n>>8) - ((n&0xFF)?0:1)] + 8;
}
/*
** Allocate and return a block of (pChunk->nAtom << iLogsize) bytes from chunk
** pChunk. If the allocation request cannot be satisfied, return 0.
*/
static void *chunkMalloc(Mem6Chunk *pChunk, int iLogsize){
int i; /* Index of a mem5.aPool[] slot */
int iBin; /* Index into mem5.aiFreelist[] */
/* Make sure mem5.aiFreelist[iLogsize] contains at least one free
** block. If not, then split a block of the next larger power of
** two in order to create a new free block of size iLogsize.
*/
for(iBin=iLogsize; pChunk->aiFreelist[iBin]<0 && iBin<=mem6.nLogThreshold; iBin++){}
if( iBin>mem6.nLogThreshold ) return 0;
i = memsys6UnlinkFirst(pChunk, iBin);
while( iBin>iLogsize ){
int newSize;
iBin--;
newSize = 1 << iBin;
pChunk->aCtrl[i+newSize] = CTRL_FREE | iBin;
memsys6Link(pChunk, i+newSize, iBin);
}
pChunk->aCtrl[i] = iLogsize;
/* Return a pointer to the allocated memory. */
pChunk->nCheckedOut++;
return (void*)&pChunk->zPool[i*pChunk->nAtom];
}
/*
** Free the allocation pointed to by p, which is guaranteed to be non-zero
** and a part of chunk object pChunk.
*/
static void chunkFree(Mem6Chunk *pChunk, void *pOld){
u32 size, iLogsize;
int iBlock;
/* Set iBlock to the index of the block pointed to by pOld in
** the array of pChunk->nAtom byte blocks pointed to by pChunk->zPool.
*/
iBlock = ((u8 *)pOld-pChunk->zPool)/pChunk->nAtom;
/* Check that the pointer pOld points to a valid, non-free block. */
assert( iBlock>=0 && iBlock<pChunk->nBlock );
assert( ((u8 *)pOld-pChunk->zPool)%pChunk->nAtom==0 );
assert( (pChunk->aCtrl[iBlock] & CTRL_FREE)==0 );
iLogsize = pChunk->aCtrl[iBlock] & CTRL_LOGSIZE;
size = 1<<iLogsize;
assert( iBlock+size-1<pChunk->nBlock );
pChunk->aCtrl[iBlock] |= CTRL_FREE;
pChunk->aCtrl[iBlock+size-1] |= CTRL_FREE;
pChunk->aCtrl[iBlock] = CTRL_FREE | iLogsize;
while( iLogsize<mem6.nLogThreshold ){
int iBuddy;
if( (iBlock>>iLogsize) & 1 ){
iBuddy = iBlock - size;
}else{
iBuddy = iBlock + size;
}
assert( iBuddy>=0 );
if( (iBuddy+(1<<iLogsize))>pChunk->nBlock ) break;
if( pChunk->aCtrl[iBuddy]!=(CTRL_FREE | iLogsize) ) break;
memsys6Unlink(pChunk, iBuddy, iLogsize);
iLogsize++;
if( iBuddy<iBlock ){
pChunk->aCtrl[iBuddy] = CTRL_FREE | iLogsize;
pChunk->aCtrl[iBlock] = 0;
iBlock = iBuddy;
}else{
pChunk->aCtrl[iBlock] = CTRL_FREE | iLogsize;
pChunk->aCtrl[iBuddy] = 0;
}
size *= 2;
}
pChunk->nCheckedOut--;
memsys6Link(pChunk, iBlock, iLogsize);
}
/*
** Return the actual size of the block pointed to by p, which is guaranteed
** to have been allocated from chunk pChunk.
*/
static int chunkSize(Mem6Chunk *pChunk, void *p){
int iSize = 0;
if( p ){
int i = ((u8 *)p-pChunk->zPool)/pChunk->nAtom;
assert( i>=0 && i<pChunk->nBlock );
iSize = pChunk->nAtom * (1 << (pChunk->aCtrl[i]&CTRL_LOGSIZE));
}
return iSize;
}
/*
** Return true if there are currently no outstanding allocations.
*/
static int chunkIsEmpty(Mem6Chunk *pChunk){
return (pChunk->nCheckedOut==0);
}
/*
** Initialize the buffer zChunk, which is nChunk bytes in size, as
** an Mem6Chunk object. Return a copy of the zChunk pointer.
*/
static Mem6Chunk *chunkInit(u8 *zChunk, int nChunk, int nMinAlloc){
int ii;
int iOffset;
Mem6Chunk *pChunk = (Mem6Chunk *)zChunk;
assert( nChunk>sizeof(Mem6Chunk) );
assert( nMinAlloc>sizeof(Mem6Link) );
memset(pChunk, 0, sizeof(Mem6Chunk));
pChunk->nAtom = nMinAlloc;
pChunk->nBlock = ((nChunk-sizeof(Mem6Chunk)) / (pChunk->nAtom+sizeof(u8)));
pChunk->zPool = (u8 *)&pChunk[1];
pChunk->aCtrl = &pChunk->zPool[pChunk->nBlock*pChunk->nAtom];
for(ii=0; ii<=mem6.nLogThreshold; ii++){
pChunk->aiFreelist[ii] = -1;
}
iOffset = 0;
for(ii=mem6.nLogThreshold; ii>=0; ii--){
int nAlloc = (1<<ii);
while( (iOffset+nAlloc)<=pChunk->nBlock ){
pChunk->aCtrl[iOffset] = ii | CTRL_FREE;
memsys6Link(pChunk, iOffset, ii);
iOffset += nAlloc;
}
}
return pChunk;
}
static void mem6Enter(void){
sqlite3_mutex_enter(mem6.mutex);
}
static void mem6Leave(void){
sqlite3_mutex_leave(mem6.mutex);
}
/*
** Based on the number and size of the currently allocated chunks, return
** the size of the next chunk to allocate, in bytes.
*/
static int nextChunkSize(void){
int iTotal = MIN_CHUNKSIZE;
Mem6Chunk *p;
for(p=mem6.pChunk; p; p=p->pNext){
iTotal = iTotal*2;
}
return iTotal;
}
static void freeChunk(Mem6Chunk *pChunk){
Mem6Chunk **pp = &mem6.pChunk;
for( pp=&mem6.pChunk; *pp!=pChunk; pp = &(*pp)->pNext );
*pp = (*pp)->pNext;
free(pChunk);
}
static void *memsys6Malloc(int nByte){
Mem6Chunk *pChunk;
void *p = 0;
int nTotal = nByte+8;
int iOffset = 0;
if( nTotal>mem6.nThreshold ){
p = malloc(nTotal);
}else{
int iLogsize = 0;
if( nTotal>(1<<LOG2_MINALLOC) ){
iLogsize = roundupLog2(nTotal) - LOG2_MINALLOC;
}
mem6Enter();
for(pChunk=mem6.pChunk; pChunk; pChunk=pChunk->pNext){
p = chunkMalloc(pChunk, iLogsize);
if( p ){
break;
}
}
if( !p ){
int iSize = nextChunkSize();
p = malloc(iSize);
if( p ){
pChunk = chunkInit((u8 *)p, iSize, mem6.nMinAlloc);
pChunk->pNext = mem6.pChunk;
mem6.pChunk = pChunk;
p = chunkMalloc(pChunk, iLogsize);
assert(p);
}
}
iOffset = ((u8*)p - (u8*)pChunk);
mem6Leave();
}
if( !p ){
return 0;
}
((u32 *)p)[0] = iOffset;
((u32 *)p)[1] = nByte;
return &((u32 *)p)[2];
}
static int memsys6Size(void *pPrior){
if( pPrior==0 ) return 0;
return ((u32*)pPrior)[-1];
}
static void memsys6Free(void *pPrior){
int iSlot;
void *p = &((u32 *)pPrior)[-2];
iSlot = ((u32 *)p)[0];
if( iSlot ){
Mem6Chunk *pChunk;
mem6Enter();
pChunk = (Mem6Chunk *)(&((u8 *)p)[-1 * iSlot]);
chunkFree(pChunk, p);
if( chunkIsEmpty(pChunk) ){
freeChunk(pChunk);
}
mem6Leave();
}else{
free(p);
}
}
static void *memsys6Realloc(void *p, int nByte){
void *p2;
if( p && nByte<=memsys6Size(p) ){
p2 = p;
}else{
p2 = memsys6Malloc(nByte);
if( p && p2 ){
memcpy(p2, p, memsys6Size(p));
memsys6Free(p);
}
}
return p2;
}
static int memsys6Roundup(int n){
if( n>mem6.nThreshold ){
return n;
}else{
return (1<<roundupLog2(n));
}
}
static int memsys6Init(void *pCtx){
u8 bMemstat = sqlite3GlobalConfig.bMemstat;
mem6.nMinAlloc = (1 << LOG2_MINALLOC);
mem6.pChunk = 0;
mem6.nThreshold = sqlite3GlobalConfig.nSmall;
if( mem6.nThreshold<=0 ){
mem6.nThreshold = SMALL_MALLOC_DEFAULT_THRESHOLD;
}
mem6.nLogThreshold = roundupLog2(mem6.nThreshold) - LOG2_MINALLOC;
if( !bMemstat ){
mem6.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
}
return SQLITE_OK;
}
static void memsys6Shutdown(void *pCtx){
memset(&mem6, 0, sizeof(mem6));
}
/*
** This routine is the only routine in this file with external
** linkage. It returns a pointer to a static sqlite3_mem_methods
** struct populated with the memsys6 methods.
*/
const sqlite3_mem_methods *sqlite3MemGetMemsys6(void){
static const sqlite3_mem_methods memsys6Methods = {
memsys6Malloc,
memsys6Free,
memsys6Realloc,
memsys6Size,
memsys6Roundup,
memsys6Init,
memsys6Shutdown,
0
};
return &memsys6Methods;
}
#endif
+245
View File
@@ -0,0 +1,245 @@
/*
** 2008 October 7
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code use to implement an in-memory rollback journal.
** The in-memory rollback journal is used to journal transactions for
** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
**
** @(#) $Id: memjournal.c,v 1.5 2008/11/19 16:52:44 danielk1977 Exp $
*/
#include "sqliteInt.h"
/* Forward references to internal structures */
typedef struct MemJournal MemJournal;
typedef struct FilePoint FilePoint;
typedef struct FileChunk FileChunk;
/* Space to hold the rollback journal is allocated in increments of
** this many bytes.
*/
#define JOURNAL_CHUNKSIZE 1024
/* Macro to find the minimum of two numeric values.
*/
#ifndef MIN
# define MIN(x,y) ((x)<(y)?(x):(y))
#endif
/*
** The rollback journal is composed of a linked list of these structures.
*/
struct FileChunk {
FileChunk *pNext; /* Next chunk in the journal */
u8 zChunk[JOURNAL_CHUNKSIZE]; /* Content of this chunk */
};
/*
** An instance of this object serves as a cursor into the rollback journal.
** The cursor can be either for reading or writing.
*/
struct FilePoint {
sqlite3_int64 iOffset; /* Offset from the beginning of the file */
FileChunk *pChunk; /* Specific chunk into which cursor points */
};
/*
** This subclass is a subclass of sqlite3_file. Each open memory-journal
** is an instance of this class.
*/
struct MemJournal {
sqlite3_io_methods *pMethod; /* Parent class. MUST BE FIRST */
FileChunk *pFirst; /* Head of in-memory chunk-list */
FilePoint endpoint; /* Pointer to the end of the file */
FilePoint readpoint; /* Pointer to the end of the last xRead() */
};
/*
** Read data from the file.
*/
static int memjrnlRead(
sqlite3_file *pJfd, /* The journal file from which to read */
void *zBuf, /* Put the results here */
int iAmt, /* Number of bytes to read */
sqlite_int64 iOfst /* Begin reading at this offset */
){
MemJournal *p = (MemJournal *)pJfd;
u8 *zOut = zBuf;
int nRead = iAmt;
int iChunkOffset;
FileChunk *pChunk;
assert( iOfst+iAmt<=p->endpoint.iOffset );
if( p->readpoint.iOffset!=iOfst || iOfst==0 ){
sqlite3_int64 iOff = 0;
for(pChunk=p->pFirst;
pChunk && (iOff+JOURNAL_CHUNKSIZE)<=iOfst;
pChunk=pChunk->pNext
){
iOff += JOURNAL_CHUNKSIZE;
}
}else{
pChunk = p->readpoint.pChunk;
}
iChunkOffset = (iOfst%JOURNAL_CHUNKSIZE);
do {
int iSpace = JOURNAL_CHUNKSIZE - iChunkOffset;
int nCopy = MIN(nRead, (JOURNAL_CHUNKSIZE - iChunkOffset));
memcpy(zOut, &pChunk->zChunk[iChunkOffset], nCopy);
zOut += nCopy;
nRead -= iSpace;
iChunkOffset = 0;
} while( nRead>=0 && (pChunk=pChunk->pNext) && nRead>0 );
p->readpoint.iOffset = iOfst+iAmt;
p->readpoint.pChunk = pChunk;
return SQLITE_OK;
}
/*
** Write data to the file.
*/
static int memjrnlWrite(
sqlite3_file *pJfd, /* The journal file into which to write */
const void *zBuf, /* Take data to be written from here */
int iAmt, /* Number of bytes to write */
sqlite_int64 iOfst /* Begin writing at this offset into the file */
){
MemJournal *p = (MemJournal *)pJfd;
int nWrite = iAmt;
u8 *zWrite = (u8 *)zBuf;
/* An in-memory journal file should only ever be appended to. Random
** access writes are not required by sqlite.
*/
assert(iOfst==p->endpoint.iOffset);
UNUSED_PARAMETER(iOfst);
while( nWrite>0 ){
FileChunk *pChunk = p->endpoint.pChunk;
int iChunkOffset = p->endpoint.iOffset%JOURNAL_CHUNKSIZE;
int iSpace = MIN(nWrite, JOURNAL_CHUNKSIZE - iChunkOffset);
if( iChunkOffset==0 ){
/* New chunk is required to extend the file. */
FileChunk *pNew = sqlite3_malloc(sizeof(FileChunk));
if( !pNew ){
return SQLITE_IOERR_NOMEM;
}
pNew->pNext = 0;
if( pChunk ){
assert( p->pFirst );
pChunk->pNext = pNew;
}else{
assert( !p->pFirst );
p->pFirst = pNew;
}
p->endpoint.pChunk = pNew;
}
memcpy(&p->endpoint.pChunk->zChunk[iChunkOffset], zWrite, iSpace);
zWrite += iSpace;
nWrite -= iSpace;
p->endpoint.iOffset += iSpace;
}
return SQLITE_OK;
}
/*
** Truncate the file.
*/
static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){
MemJournal *p = (MemJournal *)pJfd;
FileChunk *pChunk;
assert(size==0);
UNUSED_PARAMETER(size);
pChunk = p->pFirst;
while( pChunk ){
FileChunk *pTmp = pChunk;
pChunk = pChunk->pNext;
sqlite3_free(pTmp);
}
sqlite3MemJournalOpen(pJfd);
return SQLITE_OK;
}
/*
** Close the file.
*/
static int memjrnlClose(sqlite3_file *pJfd){
memjrnlTruncate(pJfd, 0);
return SQLITE_OK;
}
/*
** Sync the file.
*/
static int memjrnlSync(sqlite3_file *NotUsed, int NotUsed2){
UNUSED_PARAMETER2(NotUsed, NotUsed2);
return SQLITE_OK;
}
/*
** Query the size of the file in bytes.
*/
static int memjrnlFileSize(sqlite3_file *pJfd, sqlite_int64 *pSize){
MemJournal *p = (MemJournal *)pJfd;
*pSize = (sqlite_int64) p->endpoint.iOffset;
return SQLITE_OK;
}
/*
** Table of methods for MemJournal sqlite3_file object.
*/
static struct sqlite3_io_methods MemJournalMethods = {
1, /* iVersion */
memjrnlClose, /* xClose */
memjrnlRead, /* xRead */
memjrnlWrite, /* xWrite */
memjrnlTruncate, /* xTruncate */
memjrnlSync, /* xSync */
memjrnlFileSize, /* xFileSize */
0, /* xLock */
0, /* xUnlock */
0, /* xCheckReservedLock */
0, /* xFileControl */
0, /* xSectorSize */
0 /* xDeviceCharacteristics */
};
/*
** Open a journal file.
*/
void sqlite3MemJournalOpen(sqlite3_file *pJfd){
MemJournal *p = (MemJournal *)pJfd;
memset(p, 0, sqlite3MemJournalSize());
p->pMethod = &MemJournalMethods;
}
/*
** Return true if the file-handle passed as an argument is
** an in-memory journal
*/
int sqlite3IsMemJournal(sqlite3_file *pJfd){
return pJfd->pMethods==&MemJournalMethods;
}
/*
** Return the number of bytes required to store a MemJournal that uses vfs
** pVfs to create the underlying on-disk files.
*/
int sqlite3MemJournalSize(){
return sizeof(MemJournal);
}
+5 -131
View File
@@ -11,19 +11,14 @@
*************************************************************************
** This file contains the C functions that implement mutexes.
**
** The implementation in this file does not provide any mutual
** exclusion and is thus suitable for use only in applications
** that use SQLite in a single thread. But this implementation
** does do a lot of error checking on mutexes to make sure they
** are called correctly and at appropriate times. Hence, this
** implementation is suitable for testing.
** debugging purposes
** This file contains code that is common across all mutex implementations.
**
** $Id: mutex.c,v 1.28 2008/09/01 18:34:20 danielk1977 Exp $
** $Id: mutex.c,v 1.29 2008/10/07 15:25:48 drh Exp $
*/
#include "sqliteInt.h"
#ifndef SQLITE_MUTEX_NOOP
#ifndef SQLITE_MUTEX_OMIT
/*
** Initialize the mutex system.
*/
@@ -149,125 +144,4 @@ int sqlite3_mutex_notheld(sqlite3_mutex *p){
}
#endif
#endif
#ifdef SQLITE_MUTEX_NOOP_DEBUG
/*
** In this implementation, mutexes do not provide any mutual exclusion.
** But the error checking is provided. This implementation is useful
** for test purposes.
*/
/*
** The mutex object
*/
struct sqlite3_mutex {
int id; /* The mutex type */
int cnt; /* Number of entries without a matching leave */
};
/*
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
** intended for use inside assert() statements.
*/
static int noopMutexHeld(sqlite3_mutex *p){
return p==0 || p->cnt>0;
}
static int noopMutexNotheld(sqlite3_mutex *p){
return p==0 || p->cnt==0;
}
/*
** Initialize and deinitialize the mutex subsystem.
*/
static int noopMutexInit(void){ return SQLITE_OK; }
static int noopMutexEnd(void){ return SQLITE_OK; }
/*
** The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it. If it returns NULL
** that means that a mutex could not be allocated.
*/
static sqlite3_mutex *noopMutexAlloc(int id){
static sqlite3_mutex aStatic[6];
sqlite3_mutex *pNew = 0;
switch( id ){
case SQLITE_MUTEX_FAST:
case SQLITE_MUTEX_RECURSIVE: {
pNew = sqlite3Malloc(sizeof(*pNew));
if( pNew ){
pNew->id = id;
pNew->cnt = 0;
}
break;
}
default: {
assert( id-2 >= 0 );
assert( id-2 < sizeof(aStatic)/sizeof(aStatic[0]) );
pNew = &aStatic[id-2];
pNew->id = id;
break;
}
}
return pNew;
}
/*
** This routine deallocates a previously allocated mutex.
*/
static void noopMutexFree(sqlite3_mutex *p){
assert( p->cnt==0 );
assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
sqlite3_free(p);
}
/*
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
** to enter a mutex. If another thread is already within the mutex,
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK
** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can
** be entered multiple times by the same thread. In such cases the,
** mutex must be exited an equal number of times before another thread
** can enter. If the same thread tries to enter any other kind of mutex
** more than once, the behavior is undefined.
*/
static void noopMutexEnter(sqlite3_mutex *p){
assert( p->id==SQLITE_MUTEX_RECURSIVE || noopMutexNotheld(p) );
p->cnt++;
}
static int noopMutexTry(sqlite3_mutex *p){
assert( p->id==SQLITE_MUTEX_RECURSIVE || noopMutexNotheld(p) );
p->cnt++;
return SQLITE_OK;
}
/*
** The sqlite3_mutex_leave() routine exits a mutex that was
** previously entered by the same thread. The behavior
** is undefined if the mutex is not currently entered or
** is not currently allocated. SQLite will never do either.
*/
static void noopMutexLeave(sqlite3_mutex *p){
assert( noopMutexHeld(p) );
p->cnt--;
assert( p->id==SQLITE_MUTEX_RECURSIVE || noopMutexNotheld(p) );
}
sqlite3_mutex_methods *sqlite3DefaultMutex(void){
static sqlite3_mutex_methods sMutex = {
noopMutexInit,
noopMutexEnd,
noopMutexAlloc,
noopMutexFree,
noopMutexEnter,
noopMutexTry,
noopMutexLeave,
noopMutexHeld,
noopMutexNotheld
};
return &sMutex;
}
#endif /* SQLITE_MUTEX_NOOP_DEBUG */
#endif /* SQLITE_OMIT_MUTEX */
+22 -34
View File
@@ -19,28 +19,21 @@
** Source files should #include the sqliteInt.h file and let that file
** include this one indirectly.
**
** $Id: mutex.h,v 1.8 2008/06/26 10:41:19 danielk1977 Exp $
** $Id: mutex.h,v 1.9 2008/10/07 15:25:48 drh Exp $
*/
#ifdef SQLITE_MUTEX_APPDEF
/*
** If SQLITE_MUTEX_APPDEF is defined, then this whole module is
** omitted and equivalent functionality must be provided by the
** application that links against the SQLite library.
*/
#else
/*
** Figure out what version of the code to use. The choices are
**
** SQLITE_MUTEX_NOOP For single-threaded applications that
** do not desire error checking.
** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The
** mutexes implemention cannot be overridden
** at start-time.
**
** SQLITE_MUTEX_NOOP_DEBUG For single-threaded applications with
** error checking to help verify that mutexes
** are being used correctly even though they
** are not needed. Used when SQLITE_DEBUG is
** defined on single-threaded builds.
** SQLITE_MUTEX_NOOP For single-threaded applications. No
** mutual exclusion is provided. But this
** implementation can be overridden at
** start-time.
**
** SQLITE_MUTEX_PTHREADS For multi-threaded applications on Unix.
**
@@ -48,25 +41,22 @@
**
** SQLITE_MUTEX_OS2 For multi-threaded applications on OS/2.
*/
#define SQLITE_MUTEX_NOOP 1 /* The default */
#if defined(SQLITE_DEBUG) && !SQLITE_THREADSAFE
# undef SQLITE_MUTEX_NOOP
# define SQLITE_MUTEX_NOOP_DEBUG
#if !SQLITE_THREADSAFE
# define SQLITE_MUTEX_OMIT
#endif
#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && SQLITE_OS_UNIX
# undef SQLITE_MUTEX_NOOP
# define SQLITE_MUTEX_PTHREADS
#endif
#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && SQLITE_OS_WIN
# undef SQLITE_MUTEX_NOOP
# define SQLITE_MUTEX_W32
#endif
#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && SQLITE_OS_OS2
# undef SQLITE_MUTEX_NOOP
# define SQLITE_MUTEX_OS2
#if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP)
# if SQLITE_OS_UNIX
# define SQLITE_MUTEX_PTHREADS
# elif SQLITE_OS_WIN
# define SQLITE_MUTEX_W32
# elif SQLITE_OS_OS2
# define SQLITE_MUTEX_OS2
# else
# define SQLITE_MUTEX_NOOP
# endif
#endif
#ifdef SQLITE_MUTEX_NOOP
#ifdef SQLITE_MUTEX_OMIT
/*
** If this is a no-op implementation, implement everything as macros.
*/
@@ -80,6 +70,4 @@
#define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
#define sqlite3MutexInit() SQLITE_OK
#define sqlite3MutexEnd()
#endif
#endif /* SQLITE_MUTEX_APPDEF */
#endif /* defined(SQLITE_OMIT_MUTEX) */
+186
View File
@@ -0,0 +1,186 @@
/*
** 2008 October 07
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement mutexes.
**
** This implementation in this file does not provide any mutual
** exclusion and is thus suitable for use only in applications
** that use SQLite in a single thread. The routines defined
** here are place-holders. Applications can substitute working
** mutex routines at start-time using the
**
** sqlite3_config(SQLITE_CONFIG_MUTEX,...)
**
** interface.
**
** If compiled with SQLITE_DEBUG, then additional logic is inserted
** that does error checking on mutexes to make sure they are being
** called correctly.
**
** $Id: mutex_noop.c,v 1.2 2008/10/15 19:03:03 drh Exp $
*/
#include "sqliteInt.h"
#if defined(SQLITE_MUTEX_NOOP) && !defined(SQLITE_DEBUG)
/*
** Stub routines for all mutex methods.
**
** This routines provide no mutual exclusion or error checking.
*/
static int noopMutexHeld(sqlite3_mutex *p){ return 1; }
static int noopMutexNotheld(sqlite3_mutex *p){ return 1; }
static int noopMutexInit(void){ return SQLITE_OK; }
static int noopMutexEnd(void){ return SQLITE_OK; }
static sqlite3_mutex *noopMutexAlloc(int id){ return (sqlite3_mutex*)8; }
static void noopMutexFree(sqlite3_mutex *p){ return; }
static void noopMutexEnter(sqlite3_mutex *p){ return; }
static int noopMutexTry(sqlite3_mutex *p){ return SQLITE_OK; }
static void noopMutexLeave(sqlite3_mutex *p){ return; }
sqlite3_mutex_methods *sqlite3DefaultMutex(void){
static sqlite3_mutex_methods sMutex = {
noopMutexInit,
noopMutexEnd,
noopMutexAlloc,
noopMutexFree,
noopMutexEnter,
noopMutexTry,
noopMutexLeave,
noopMutexHeld,
noopMutexNotheld
};
return &sMutex;
}
#endif /* defined(SQLITE_MUTEX_NOOP) && !defined(SQLITE_DEBUG) */
#if defined(SQLITE_MUTEX_NOOP) && defined(SQLITE_DEBUG)
/*
** In this implementation, error checking is provided for testing
** and debugging purposes. The mutexes still do not provide any
** mutual exclusion.
*/
/*
** The mutex object
*/
struct sqlite3_mutex {
int id; /* The mutex type */
int cnt; /* Number of entries without a matching leave */
};
/*
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
** intended for use inside assert() statements.
*/
static int debugMutexHeld(sqlite3_mutex *p){
return p==0 || p->cnt>0;
}
static int debugMutexNotheld(sqlite3_mutex *p){
return p==0 || p->cnt==0;
}
/*
** Initialize and deinitialize the mutex subsystem.
*/
static int debugMutexInit(void){ return SQLITE_OK; }
static int debugMutexEnd(void){ return SQLITE_OK; }
/*
** The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it. If it returns NULL
** that means that a mutex could not be allocated.
*/
static sqlite3_mutex *debugMutexAlloc(int id){
static sqlite3_mutex aStatic[6];
sqlite3_mutex *pNew = 0;
switch( id ){
case SQLITE_MUTEX_FAST:
case SQLITE_MUTEX_RECURSIVE: {
pNew = sqlite3Malloc(sizeof(*pNew));
if( pNew ){
pNew->id = id;
pNew->cnt = 0;
}
break;
}
default: {
assert( id-2 >= 0 );
assert( id-2 < sizeof(aStatic)/sizeof(aStatic[0]) );
pNew = &aStatic[id-2];
pNew->id = id;
break;
}
}
return pNew;
}
/*
** This routine deallocates a previously allocated mutex.
*/
static void debugMutexFree(sqlite3_mutex *p){
assert( p->cnt==0 );
assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
sqlite3_free(p);
}
/*
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
** to enter a mutex. If another thread is already within the mutex,
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK
** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can
** be entered multiple times by the same thread. In such cases the,
** mutex must be exited an equal number of times before another thread
** can enter. If the same thread tries to enter any other kind of mutex
** more than once, the behavior is undefined.
*/
static void debugMutexEnter(sqlite3_mutex *p){
assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(p) );
p->cnt++;
}
static int debugMutexTry(sqlite3_mutex *p){
assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(p) );
p->cnt++;
return SQLITE_OK;
}
/*
** The sqlite3_mutex_leave() routine exits a mutex that was
** previously entered by the same thread. The behavior
** is undefined if the mutex is not currently entered or
** is not currently allocated. SQLite will never do either.
*/
static void debugMutexLeave(sqlite3_mutex *p){
assert( debugMutexHeld(p) );
p->cnt--;
assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(p) );
}
sqlite3_mutex_methods *sqlite3DefaultMutex(void){
static sqlite3_mutex_methods sMutex = {
debugMutexInit,
debugMutexEnd,
debugMutexAlloc,
debugMutexFree,
debugMutexEnter,
debugMutexTry,
debugMutexLeave,
debugMutexHeld,
debugMutexNotheld
};
return &sMutex;
}
#endif /* defined(SQLITE_MUTEX_NOOP) && defined(SQLITE_DEBUG) */
+3 -3
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains the C functions that implement mutexes for pthreads
**
** $Id: mutex_unix.c,v 1.13 2008/07/16 12:33:24 drh Exp $
** $Id: mutex_unix.c,v 1.15 2008/11/17 19:18:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -61,7 +61,7 @@ struct sqlite3_mutex {
** make sure no assert() statements are evaluated and hence these
** routines are never called.
*/
#ifndef NDEBUG
#if !defined(NDEBUG) || defined(SQLITE_DEBUG)
static int pthreadMutexHeld(sqlite3_mutex *p){
return (p->nRef!=0 && pthread_equal(p->owner, pthread_self()));
}
@@ -157,7 +157,7 @@ static sqlite3_mutex *pthreadMutexAlloc(int iType){
}
default: {
assert( iType-2 >= 0 );
assert( iType-2 < sizeof(staticMutexes)/sizeof(staticMutexes[0]) );
assert( iType-2 < ArraySize(staticMutexes) );
p = &staticMutexes[iType-2];
p->id = iType;
break;
+9 -2
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains the C functions that implement mutexes for win32
**
** $Id: mutex_w32.c,v 1.11 2008/06/26 10:41:19 danielk1977 Exp $
** $Id: mutex_w32.c,v 1.12 2008/11/10 20:01:41 shane Exp $
*/
#include "sqliteInt.h"
@@ -41,7 +41,14 @@ struct sqlite3_mutex {
** 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.
**
** mutexIsNT() is only used for the TryEnterCriticalSection() API call,
** which is only available if your application was compiled with
** _WIN32_WINNT defined to a value >= 0x0400. Currently, the only
** call to TryEnterCriticalSection() is #ifdef'ed out, so #ifdef
** this out as well.
*/
#if 0
#if SQLITE_OS_WINCE
# define mutexIsNT() (1)
#else
@@ -56,7 +63,7 @@ struct sqlite3_mutex {
return osType==2;
}
#endif /* SQLITE_OS_WINCE */
#endif
#ifdef SQLITE_DEBUG
/*
+5 -5
View File
@@ -13,7 +13,7 @@
** This file contains OS interface code that is common to all
** architectures.
**
** $Id: os.c,v 1.122 2008/09/02 17:18:52 danielk1977 Exp $
** $Id: os.c,v 1.124 2008/10/07 15:25:48 drh Exp $
*/
#define _SQLITE_OS_C_ 1
#include "sqliteInt.h"
@@ -36,7 +36,7 @@
** sqlite3OsLock()
**
*/
#if defined(SQLITE_TEST) && (SQLITE_OS_WIN==0) && 0
#if defined(SQLITE_TEST) && (SQLITE_OS_WIN==0)
#define DO_OS_MALLOC_TEST if (1) { \
void *pTstAlloc = sqlite3Malloc(10); \
if (!pTstAlloc) return SQLITE_IOERR_NOMEM; \
@@ -199,14 +199,14 @@ static sqlite3_vfs * SQLITE_WSD vfsList = 0;
*/
sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){
sqlite3_vfs *pVfs = 0;
#ifndef SQLITE_MUTEX_NOOP
#if SQLITE_THREADSAFE
sqlite3_mutex *mutex;
#endif
#ifndef SQLITE_OMIT_AUTOINIT
int rc = sqlite3_initialize();
if( rc ) return 0;
#endif
#ifndef SQLITE_MUTEX_NOOP
#if SQLITE_THREADSAFE
mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
sqlite3_mutex_enter(mutex);
@@ -268,7 +268,7 @@ int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
** Unregister a VFS so that it is no longer accessible.
*/
int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
#ifndef SQLITE_MUTEX_NOOP
#if SQLITE_THREADSAFE
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
sqlite3_mutex_enter(mutex);
+13 -5
View File
@@ -12,7 +12,7 @@
**
** This file contains code that is specific to OS/2.
**
** $Id: os_os2.c,v 1.56 2008/08/22 13:47:57 pweilbacher Exp $
** $Id: os_os2.c,v 1.59 2008/11/18 23:03:40 pweilbacher Exp $
*/
#include "sqliteInt.h"
@@ -124,6 +124,7 @@ static int os2Read(
if( got == (ULONG)amt )
return SQLITE_OK;
else {
/* Unread portions of the input buffer must be zero-filled */
memset(&((char*)pBuf)[got], 0, amt-got);
return SQLITE_IOERR_SHORT_READ;
}
@@ -171,7 +172,7 @@ static int os2Truncate( sqlite3_file *id, i64 nByte ){
OSTRACE3( "TRUNCATE %d %lld\n", pFile->h, nByte );
SimulateIOError( return SQLITE_IOERR_TRUNCATE );
rc = DosSetFileSize( pFile->h, nByte );
return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;
return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR_TRUNCATE;
}
#ifdef SQLITE_TEST
@@ -195,7 +196,14 @@ static int os2Sync( sqlite3_file *id, int flags ){
}
sqlite3_sync_count++;
#endif
/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
** no-op
*/
#ifdef SQLITE_NO_SYNC
return SQLITE_OK;
#else
return DosResetBuffer( pFile->h ) == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;
#endif
}
/*
@@ -206,13 +214,13 @@ static int os2FileSize( sqlite3_file *id, sqlite3_int64 *pSize ){
FILESTATUS3 fsts3FileInfo;
memset(&fsts3FileInfo, 0, sizeof(fsts3FileInfo));
assert( id!=0 );
SimulateIOError( return SQLITE_IOERR );
SimulateIOError( return SQLITE_IOERR_FSTAT );
rc = DosQueryFileInfo( ((os2File*)id)->h, FIL_STANDARD, &fsts3FileInfo, sizeof(FILESTATUS3) );
if( rc == NO_ERROR ){
*pSize = fsts3FileInfo.cbFile;
return SQLITE_OK;
}else{
return SQLITE_IOERR;
return SQLITE_IOERR_FSTAT;
}
}
@@ -864,7 +872,7 @@ static int os2Delete(
rc = DosDelete( (PSZ)zFilenameCp );
free( zFilenameCp );
OSTRACE2( "DELETE \"%s\"\n", zFilename );
return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;
return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR_DELETE;
}
/*
+612 -81
View File
File diff suppressed because it is too large Load Diff
+87 -16
View File
@@ -12,7 +12,7 @@
**
** This file contains code that is specific to windows.
**
** $Id: os_win.c,v 1.133 2008/09/01 22:15:19 shane Exp $
** $Id: os_win.c,v 1.140 2008/11/19 21:35:47 shane Exp $
*/
#include "sqliteInt.h"
#if SQLITE_OS_WIN /* This file is used for windows only */
@@ -73,7 +73,7 @@
** Determine if we are dealing with WindowsCE - which has a much
** reduced API.
*/
#if defined(SQLITE_OS_WINCE)
#if SQLITE_OS_WINCE
# define AreFileApisANSI() 1
#endif
@@ -252,7 +252,7 @@ static char *unicodeToMbcs(const WCHAR *zWideFilename){
** Convert multibyte character string to UTF-8. Space to hold the
** returned string is obtained from malloc().
*/
static char *mbcsToUtf8(const char *zFilename){
char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){
char *zFilenameUtf8;
WCHAR *zTmpWide;
@@ -610,7 +610,7 @@ static int winClose(sqlite3_file *id){
OSTRACE2("CLOSE %d\n", pFile->h);
do{
rc = CloseHandle(pFile->h);
}while( rc==0 && cnt++ < MX_CLOSE_ATTEMPT && (Sleep(100), 1) );
}while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (Sleep(100), 1) );
#if SQLITE_OS_WINCE
#define WINCE_DELETION_ATTEMPTS 3
winceDestroyLock(pFile);
@@ -666,6 +666,7 @@ static int winRead(
if( got==(DWORD)amt ){
return SQLITE_OK;
}else{
/* Unread parts of the buffer must be zero-filled */
memset(&((char*)pBuf)[got], 0, amt-got);
return SQLITE_IOERR_SHORT_READ;
}
@@ -713,14 +714,20 @@ static int winWrite(
** Truncate an open file to a specified size
*/
static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
DWORD rc;
LONG upperBits = (nByte>>32) & 0x7fffffff;
LONG lowerBits = nByte & 0xffffffff;
winFile *pFile = (winFile*)id;
OSTRACE3("TRUNCATE %d %lld\n", pFile->h, nByte);
SimulateIOError(return SQLITE_IOERR_TRUNCATE);
SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
SetEndOfFile(pFile->h);
return SQLITE_OK;
rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
if( INVALID_SET_FILE_POINTER != rc ){
/* SetEndOfFile will fail if nByte is negative */
if( SetEndOfFile(pFile->h) ){
return SQLITE_OK;
}
}
return SQLITE_IOERR_TRUNCATE;
}
#ifdef SQLITE_TEST
@@ -744,11 +751,18 @@ static int winSync(sqlite3_file *id, int flags){
}
sqlite3_sync_count++;
#endif
/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
** no-op
*/
#ifdef SQLITE_NO_SYNC
return SQLITE_OK;
#else
if( FlushFileBuffers(pFile->h) ){
return SQLITE_OK;
}else{
return SQLITE_IOERR;
}
#endif
}
/*
@@ -784,11 +798,15 @@ static int getReadLock(winFile *pFile){
ovlp.hEvent = 0;
res = LockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY,
0, SHARED_SIZE, 0, &ovlp);
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
*/
#if SQLITE_OS_WINCE==0
}else{
int lk;
sqlite3_randomness(sizeof(lk), &lk);
pFile->sharedLockByte = (lk & 0x7fffffff)%(SHARED_SIZE - 1);
res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
#endif
}
return res;
}
@@ -800,8 +818,12 @@ static int unlockReadLock(winFile *pFile){
int res;
if( isNT() ){
res = UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
*/
#if SQLITE_OS_WINCE==0
}else{
res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
#endif
}
return res;
}
@@ -1074,8 +1096,12 @@ static void *convertUtf8Filename(const char *zFilename){
void *zConverted = 0;
if( isNT() ){
zConverted = utf8ToUnicode(zFilename);
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
*/
#if SQLITE_OS_WINCE==0
}else{
zConverted = utf8ToMbcs(zFilename);
#endif
}
/* caller will handle out of memory */
return zConverted;
@@ -1105,17 +1131,23 @@ static int getTempname(int nBuf, char *zBuf){
}else{
return SQLITE_NOMEM;
}
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
** Since the ASCII version of these Windows API do not exist for WINCE,
** it's important to not reference them for WINCE builds.
*/
#if SQLITE_OS_WINCE==0
}else{
char *zUtf8;
char zMbcsPath[MAX_PATH];
GetTempPathA(MAX_PATH-30, zMbcsPath);
zUtf8 = mbcsToUtf8(zMbcsPath);
zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
if( zUtf8 ){
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
free(zUtf8);
}else{
return SQLITE_NOMEM;
}
#endif
}
for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
zTempPath[i] = 0;
@@ -1177,7 +1209,9 @@ static int winOpen(
DWORD dwShareMode;
DWORD dwCreationDisposition;
DWORD dwFlagsAndAttributes = 0;
int isTemp;
#if SQLITE_OS_WINCE
int isTemp = 0;
#endif
winFile *pFile = (winFile*)id;
void *zConverted; /* Filename in OS encoding */
const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
@@ -1218,19 +1252,20 @@ static int winOpen(
if( flags & SQLITE_OPEN_DELETEONCLOSE ){
#if SQLITE_OS_WINCE
dwFlagsAndAttributes = FILE_ATTRIBUTE_HIDDEN;
isTemp = 1;
#else
dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY
| FILE_ATTRIBUTE_HIDDEN
| FILE_FLAG_DELETE_ON_CLOSE;
#endif
isTemp = 1;
}else{
dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
isTemp = 0;
}
/* Reports from the internet are that performance is always
** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */
#if SQLITE_OS_WINCE
dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
#endif
if( isNT() ){
h = CreateFileW((WCHAR*)zConverted,
dwDesiredAccess,
@@ -1240,6 +1275,11 @@ static int winOpen(
dwFlagsAndAttributes,
NULL
);
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
** Since the ASCII version of these Windows API do not exist for WINCE,
** it's important to not reference them for WINCE builds.
*/
#if SQLITE_OS_WINCE==0
}else{
h = CreateFileA((char*)zConverted,
dwDesiredAccess,
@@ -1249,6 +1289,7 @@ static int winOpen(
dwFlagsAndAttributes,
NULL
);
#endif
}
if( h==INVALID_HANDLE_VALUE ){
free(zConverted);
@@ -1308,7 +1349,7 @@ static int winDelete(
int syncDir /* Not used on win32 */
){
int cnt = 0;
int rc;
DWORD rc;
DWORD error;
void *zConverted = convertUtf8Filename(zFilename);
if( zConverted==0 ){
@@ -1320,19 +1361,25 @@ static int winDelete(
DeleteFileW(zConverted);
}while( ( ((rc = GetFileAttributesW(zConverted)) != INVALID_FILE_ATTRIBUTES)
|| ((error = GetLastError()) == ERROR_ACCESS_DENIED))
&& (cnt++ < MX_DELETION_ATTEMPTS)
&& (++cnt < MX_DELETION_ATTEMPTS)
&& (Sleep(100), 1) );
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
** Since the ASCII version of these Windows API do not exist for WINCE,
** it's important to not reference them for WINCE builds.
*/
#if SQLITE_OS_WINCE==0
}else{
do{
DeleteFileA(zConverted);
}while( ( ((rc = GetFileAttributesA(zConverted)) != INVALID_FILE_ATTRIBUTES)
|| ((error = GetLastError()) == ERROR_ACCESS_DENIED))
&& (cnt++ < MX_DELETION_ATTEMPTS)
&& (++cnt < MX_DELETION_ATTEMPTS)
&& (Sleep(100), 1) );
#endif
}
free(zConverted);
OSTRACE2("DELETE \"%s\"\n", zFilename);
return ( (rc==INVALID_FILE_ATTRIBUTES)
return ( (rc == INVALID_FILE_ATTRIBUTES)
&& (error == ERROR_FILE_NOT_FOUND)) ? SQLITE_OK : SQLITE_IOERR_DELETE;
}
@@ -1353,8 +1400,14 @@ static int winAccess(
}
if( isNT() ){
attr = GetFileAttributesW((WCHAR*)zConverted);
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
** Since the ASCII version of these Windows API do not exist for WINCE,
** it's important to not reference them for WINCE builds.
*/
#if SQLITE_OS_WINCE==0
}else{
attr = GetFileAttributesA((char*)zConverted);
#endif
}
free(zConverted);
switch( flags ){
@@ -1413,6 +1466,11 @@ static int winFullPathname(
free(zConverted);
zOut = unicodeToUtf8(zTemp);
free(zTemp);
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
** Since the ASCII version of these Windows API do not exist for WINCE,
** it's important to not reference them for WINCE builds.
*/
#if SQLITE_OS_WINCE==0
}else{
char *zTemp;
nByte = GetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
@@ -1423,8 +1481,9 @@ static int winFullPathname(
}
GetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
free(zConverted);
zOut = mbcsToUtf8(zTemp);
zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
free(zTemp);
#endif
}
if( zOut ){
sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zOut);
@@ -1453,8 +1512,14 @@ static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
}
if( isNT() ){
h = LoadLibraryW((WCHAR*)zConverted);
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
** Since the ASCII version of these Windows API do not exist for WINCE,
** it's important to not reference them for WINCE builds.
*/
#if SQLITE_OS_WINCE==0
}else{
h = LoadLibraryA((char*)zConverted);
#endif
}
free(zConverted);
return (void*)h;
@@ -1488,6 +1553,11 @@ void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
*/
static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
int n = 0;
UNUSED_PARAMETER(pVfs);
#if defined(SQLITE_TEST)
n = nBuf;
memset(zBuf, 0, nBuf);
#else
if( sizeof(SYSTEMTIME)<=nBuf-n ){
SYSTEMTIME x;
GetSystemTime(&x);
@@ -1510,6 +1580,7 @@ static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
memcpy(&zBuf[n], &i, sizeof(i));
n += sizeof(i);
}
#endif
return n;
}
+407 -430
View File
File diff suppressed because it is too large Load Diff
+6 -3
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.83 2008/09/18 17:34:44 danielk1977 Exp $
** @(#) $Id: pager.h,v 1.87 2008/11/19 10:22:33 danielk1977 Exp $
*/
#ifndef _PAGER_H_
@@ -65,13 +65,15 @@ typedef struct PgHdr DbPage;
#define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
#define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
#define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
#define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */
#define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
/*
** See source code comments for a detailed description of the following
** routines:
*/
int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char*, void(*)(DbPage*), int,int,int);
void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler);
int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char*, int,int,int);
void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *);
void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*));
int sqlite3PagerSetPagesize(Pager*, u16*);
int sqlite3PagerMaxPageCount(Pager*, int);
@@ -81,6 +83,7 @@ int sqlite3PagerClose(Pager *pPager);
int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
#define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
int sqlite3PagerPageRefcount(DbPage*);
int sqlite3PagerRef(DbPage*);
int sqlite3PagerUnref(DbPage*);
int sqlite3PagerWrite(DbPage*);
+48 -7
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.252 2008/08/20 16:35:10 drh Exp $
** @(#) $Id: parse.y,v 1.262 2008/10/23 05:45:07 danielk1977 Exp $
*/
// All token codes are small integers with #defines that begin with "TK_"
@@ -246,8 +246,9 @@ carg ::= ccons.
ccons ::= DEFAULT term(X). {sqlite3AddDefaultValue(pParse,X);}
ccons ::= DEFAULT LP expr(X) RP. {sqlite3AddDefaultValue(pParse,X);}
ccons ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,X);}
ccons ::= DEFAULT MINUS term(X). {
ccons ::= DEFAULT MINUS(A) term(X). {
Expr *p = sqlite3PExpr(pParse, TK_UMINUS, X, 0, 0);
sqlite3ExprSpan(p,&A,&X->span);
sqlite3AddDefaultValue(pParse,p);
}
ccons ::= DEFAULT id(X). {
@@ -281,7 +282,7 @@ autoinc(X) ::= AUTOINCR. {X = 1;}
//
%type refargs {int}
refargs(A) ::= . { A = OE_Restrict * 0x010101; }
refargs(A) ::= refargs(X) refarg(Y). { A = (X & Y.mask) | Y.value; }
refargs(A) ::= refargs(X) refarg(Y). { A = (X & ~Y.mask) | Y.value; }
%type refarg {struct {int value; int mask;}}
refarg(A) ::= MATCH nm. { A.value = 0; A.mask = 0x000000; }
refarg(A) ::= ON DELETE refact(X). { A.value = X; A.mask = 0x0000ff; }
@@ -456,8 +457,9 @@ stl_prefix(A) ::= seltablist(X) joinop(Y). {
if( A && A->nSrc>0 ) A->a[A->nSrc-1].jointype = Y;
}
stl_prefix(A) ::= . {A = 0;}
seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) on_opt(N) using_opt(U). {
seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I) on_opt(N) using_opt(U). {
A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U);
sqlite3SrcListIndexedBy(pParse, A, &I);
}
%ifndef SQLITE_OMIT_SUBQUERY
seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP
@@ -499,6 +501,21 @@ joinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN.
on_opt(N) ::= ON expr(E). {N = E;}
on_opt(N) ::= . {N = 0;}
// Note that this block abuses the Token type just a little. If there is
// no "INDEXED BY" clause, the returned token is empty (z==0 && n==0). If
// there is an INDEXED BY clause, then the token is populated as per normal,
// with z pointing to the token data and n containing the number of bytes
// in the token.
//
// If there is a "NOT INDEXED" clause, then (z==0 && n==1), which is
// normally illegal. The sqlite3SrcListIndexedBy() function
// recognizes and interprets this as a special case.
//
%type indexed_opt {Token}
indexed_opt(A) ::= . {A.z=0; A.n=0;}
indexed_opt(A) ::= INDEXED BY nm(X). {A = X;}
indexed_opt(A) ::= NOT INDEXED. {A.z=0; A.n=1;}
%type using_opt {IdList*}
%destructor using_opt {sqlite3IdListDelete(pParse->db, $$);}
using_opt(U) ::= USING LP inscollist(L) RP. {U = L;}
@@ -562,7 +579,20 @@ limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y).
/////////////////////////// The DELETE statement /////////////////////////////
//
cmd ::= DELETE FROM fullname(X) where_opt(Y). {sqlite3DeleteFrom(pParse,X,Y);}
%ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W)
orderby_opt(O) limit_opt(L). {
sqlite3SrcListIndexedBy(pParse, X, &I);
W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset, "DELETE");
sqlite3DeleteFrom(pParse,X,W);
}
%endif
%ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W). {
sqlite3SrcListIndexedBy(pParse, X, &I);
sqlite3DeleteFrom(pParse,X,W);
}
%endif
%type where_opt {Expr*}
%destructor where_opt {sqlite3ExprDelete(pParse->db, $$);}
@@ -572,10 +602,21 @@ where_opt(A) ::= WHERE expr(X). {A = X;}
////////////////////////// The UPDATE command ////////////////////////////////
//
cmd ::= UPDATE orconf(R) fullname(X) SET setlist(Y) where_opt(Z). {
%ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W) orderby_opt(O) limit_opt(L). {
sqlite3SrcListIndexedBy(pParse, X, &I);
sqlite3ExprListCheckLength(pParse,Y,"set list");
sqlite3Update(pParse,X,Y,Z,R);
W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset, "UPDATE");
sqlite3Update(pParse,X,Y,W,R);
}
%endif
%ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W). {
sqlite3SrcListIndexedBy(pParse, X, &I);
sqlite3ExprListCheckLength(pParse,Y,"set list");
sqlite3Update(pParse,X,Y,W,R);
}
%endif
%type setlist {ExprList*}
%destructor setlist {sqlite3ExprListDelete(pParse->db, $$);}
+229 -933
View File
File diff suppressed because it is too large Load Diff
+23 -35
View File
@@ -12,7 +12,7 @@
** This header file defines the interface that the sqlite page cache
** subsystem.
**
** @(#) $Id: pcache.h,v 1.11 2008/09/18 17:34:44 danielk1977 Exp $
** @(#) $Id: pcache.h,v 1.16 2008/11/19 16:52:44 danielk1977 Exp $
*/
#ifndef _PCACHE_H_
@@ -34,25 +34,19 @@ struct PgHdr {
u32 pageHash; /* Hash of page content */
#endif
u16 flags; /* PGHDR flags defined below */
/**********************************************************************
** Elements above are public. All that follows is private to pcache.c
** and should not be accessed by other modules.
*/
i16 nRef; /* Number of users of this page */
PCache *pCache; /* Cache that owns this page */
void *apSave[2]; /* Journal entries for in-memory databases */
/**********************************************************************
** Elements above are accessible at any time by the owner of the cache
** without the need for a mutex. The elements that follow can only be
** accessed while holding the SQLITE_MUTEX_STATIC_LRU mutex.
*/
PgHdr *pNextHash, *pPrevHash; /* Hash collision chain for PgHdr.pgno */
PgHdr *pNext, *pPrev; /* List of clean or dirty pages */
PgHdr *pNextLru, *pPrevLru; /* Part of global LRU list */
PgHdr *pDirtyNext; /* Next element in list of dirty pages */
PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
};
/* Bit values for PgHdr.flags */
#define PGHDR_IN_JOURNAL 0x001 /* Page is in rollback journal */
#define PGHDR_DIRTY 0x002 /* Page has changed */
#define PGHDR_NEED_SYNC 0x004 /* Fsync the rollback journal before
** writing this page to the database */
@@ -68,8 +62,6 @@ void sqlite3PcacheShutdown(void);
** These routines implement SQLITE_CONFIG_PAGECACHE.
*/
void sqlite3PCacheBufferSetup(void *, int sz, int n);
void *sqlite3PCacheMalloc(int sz);
void sqlite3PCacheFree(void*);
/* Create a new pager cache.
** Under memory stress, invoke xStress to try to make pages clean.
@@ -79,7 +71,6 @@ void sqlite3PcacheOpen(
int szPage, /* Size of every page */
int szExtra, /* Extra space associated with each page */
int bPurgeable, /* True if pages are on backing store */
void (*xDestroy)(PgHdr *), /* Called to destroy a page */
int (*xStress)(void*, PgHdr*), /* Call to try to make pages clean */
void *pStress, /* Argument to xStress */
PCache *pToInit /* Preallocated space for the PCache */
@@ -110,11 +101,6 @@ void sqlite3PcacheMove(PgHdr*, Pgno);
/* Remove all pages with pgno>x. Reset the cache if x==0 */
void sqlite3PcacheTruncate(PCache*, Pgno x);
/* Routines used to implement transactions on memory-only databases. */
int sqlite3PcachePreserve(PgHdr*, int); /* Preserve current page content */
void sqlite3PcacheCommit(PCache*, int); /* Drop preserved copy */
void sqlite3PcacheRollback(PCache*, int, void (*xReiniter)(PgHdr*));
/* Get a list of all dirty pages in the cache, sorted by page number */
PgHdr *sqlite3PcacheDirtyList(PCache*);
@@ -122,17 +108,7 @@ PgHdr *sqlite3PcacheDirtyList(PCache*);
void sqlite3PcacheClose(PCache*);
/* Clear flags from pages of the page cache */
void sqlite3PcacheClearFlags(PCache*, int mask);
/* Assert flags settings on all pages. Debugging only */
#ifndef NDEBUG
void sqlite3PcacheAssertFlags(PCache*, int trueMask, int falseMask);
#else
# define sqlite3PcacheAssertFlags(A,B,C)
#endif
/* Return true if the number of dirty pages is 0 or 1 */
int sqlite3PcacheZeroOrOneDirtyPages(PCache*);
void sqlite3PcacheClearSyncFlags(PCache *);
/* Discard the contents of the cache */
int sqlite3PcacheClear(PCache*);
@@ -143,14 +119,18 @@ int sqlite3PcacheRefCount(PCache*);
/* Increment the reference count of an existing page */
void sqlite3PcacheRef(PgHdr*);
int sqlite3PcachePageRefcount(PgHdr*);
/* Return the total number of pages stored in the cache */
int sqlite3PcachePagecount(PCache*);
/* Iterate through all pages currently stored in the cache. This interface
** is only available if SQLITE_CHECK_PAGES is defined when the library is
** built.
#ifdef SQLITE_CHECK_PAGES
/* Iterate through all dirty pages currently stored in the cache. This
** interface is only available if SQLITE_CHECK_PAGES is defined when the
** library is built.
*/
void sqlite3PcacheIterate(PCache *pCache, void (*xIter)(PgHdr *));
void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
#endif
/* Set and get the suggested cache-size for the specified pager-cache.
**
@@ -158,12 +138,20 @@ void sqlite3PcacheIterate(PCache *pCache, void (*xIter)(PgHdr *));
** the total number of pages cached by purgeable pager-caches to the sum
** of the suggested cache-sizes.
*/
int sqlite3PcacheGetCachesize(PCache *);
void sqlite3PcacheSetCachesize(PCache *, int);
#ifdef SQLITE_TEST
int sqlite3PcacheGetCachesize(PCache *);
#endif
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
/* Try to return memory used by the pcache module to the main memory heap */
int sqlite3PcacheReleaseMemory(int);
#endif
#ifdef SQLITE_TEST
void sqlite3PcacheStats(int*,int*,int*,int*);
#endif
void sqlite3PCacheSetDefault(void);
#endif /* _PCACHE_H_ */
+737
View File
@@ -0,0 +1,737 @@
/*
** 2008 November 05
**
** 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 the default page cache implementation (the
** sqlite3_pcache interface). It also contains part of the implementation
** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
** If the default page cache implementation is overriden, then neither of
** these two features are available.
**
** @(#) $Id: pcache1.c,v 1.3 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
typedef struct PCache1 PCache1;
typedef struct PgHdr1 PgHdr1;
typedef struct PgFreeslot PgFreeslot;
/* Pointers to structures of this type are cast and returned as
** opaque sqlite3_pcache* handles
*/
struct PCache1 {
/* Cache configuration parameters. Page size (szPage) and the purgeable
** flag (bPurgeable) are set when the cache is created. nMax may be
** modified at any time by a call to the pcache1CacheSize() method.
** The global mutex must be held when accessing nMax.
*/
int szPage; /* Size of allocated pages in bytes */
int bPurgeable; /* True if cache is purgeable */
unsigned int nMin; /* Minimum number of pages reserved */
unsigned int nMax; /* Configured "cache_size" value */
/* Hash table of all pages. The following variables may only be accessed
** when the accessor is holding the global mutex (see pcache1EnterMutex()
** and pcache1LeaveMutex()).
*/
unsigned int nRecyclable; /* Number of pages in the LRU list */
unsigned int nPage; /* Total number of pages in apHash */
unsigned int nHash; /* Number of slots in apHash[] */
PgHdr1 **apHash; /* Hash table for fast lookup by key */
};
/*
** Each cache entry is represented by an instance of the following
** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
** directly after the structure in memory (see the PGHDR1_TO_PAGE()
** macro below).
*/
struct PgHdr1 {
unsigned int iKey; /* Key value (page number) */
PgHdr1 *pNext; /* Next in hash table chain */
PCache1 *pCache; /* Cache that currently owns this page */
PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
};
/*
** Free slots in the allocator used to divide up the buffer provided using
** the SQLITE_CONFIG_PAGECACHE mechanism.
*/
struct PgFreeslot {
PgFreeslot *pNext; /* Next free slot */
};
/*
** Global data used by this cache.
*/
static SQLITE_WSD struct PCacheGlobal {
sqlite3_mutex *mutex; /* static mutex MUTEX_STATIC_LRU */
int nMaxPage; /* Sum of nMaxPage for purgeable caches */
int nMinPage; /* Sum of nMinPage for purgeable caches */
int nCurrentPage; /* Number of purgeable pages allocated */
PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
/* Variables related to SQLITE_CONFIG_PAGECACHE settings. */
int szSlot; /* Size of each free slot */
void *pStart, *pEnd; /* Bounds of pagecache malloc range */
PgFreeslot *pFree; /* Free page blocks */
} pcache1_g;
/*
** All code in this file should access the global structure above via the
** alias "pcache1". This ensures that the WSD emulation is used when
** compiling for systems that do not support real WSD.
*/
#define pcache1 (GLOBAL(struct PCacheGlobal, pcache1_g))
/*
** When a PgHdr1 structure is allocated, the associated PCache1.szPage
** bytes of data are located directly after it in memory (i.e. the total
** size of the allocation is sizeof(PgHdr1)+PCache1.szPage byte). The
** PGHDR1_TO_PAGE() macro takes a pointer to a PgHdr1 structure as
** an argument and returns a pointer to the associated block of szPage
** bytes. The PAGE_TO_PGHDR1() macro does the opposite: its argument is
** a pointer to a block of szPage bytes of data and the return value is
** a pointer to the associated PgHdr1 structure.
**
** assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(X))==X );
*/
#define PGHDR1_TO_PAGE(p) (void *)(&((unsigned char *)p)[sizeof(PgHdr1)])
#define PAGE_TO_PGHDR1(p) (PgHdr1 *)(&((unsigned char *)p)[-1*sizeof(PgHdr1)])
/*
** Macros to enter and leave the global LRU mutex.
*/
#define pcache1EnterMutex() sqlite3_mutex_enter(pcache1.mutex)
#define pcache1LeaveMutex() sqlite3_mutex_leave(pcache1.mutex)
/******************************************************************************/
/******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/
/*
** This function is called during initialization if a static buffer is
** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
** verb to sqlite3_config(). Parameter pBuf points to an allocation large
** enough to contain 'n' buffers of 'sz' bytes each.
*/
void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
PgFreeslot *p;
sz &= ~7;
pcache1.szSlot = sz;
pcache1.pStart = pBuf;
pcache1.pFree = 0;
while( n-- ){
p = (PgFreeslot*)pBuf;
p->pNext = pcache1.pFree;
pcache1.pFree = p;
pBuf = (void*)&((char*)pBuf)[sz];
}
pcache1.pEnd = pBuf;
}
/*
** Malloc function used within this file to allocate space from the buffer
** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
** such buffer exists or there is no space left in it, this function falls
** back to sqlite3Malloc().
*/
static void *pcache1Alloc(int nByte){
void *p;
assert( sqlite3_mutex_held(pcache1.mutex) );
if( nByte<=pcache1.szSlot && pcache1.pFree ){
p = (PgHdr1 *)pcache1.pFree;
pcache1.pFree = pcache1.pFree->pNext;
sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
}else{
/* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the
** global pcache mutex and unlock the pager-cache object pCache. This is
** so that if the attempt to allocate a new buffer causes the the
** configured soft-heap-limit to be breached, it will be possible to
** reclaim memory from this pager-cache.
*/
pcache1LeaveMutex();
p = sqlite3Malloc(nByte);
pcache1EnterMutex();
if( p ){
int sz = sqlite3MallocSize(p);
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
}
}
return p;
}
/*
** Free an allocated buffer obtained from pcache1Alloc().
*/
static void pcache1Free(void *p){
assert( sqlite3_mutex_held(pcache1.mutex) );
if( p==0 ) return;
if( p>=pcache1.pStart && p<pcache1.pEnd ){
PgFreeslot *pSlot;
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
pSlot = (PgFreeslot*)p;
pSlot->pNext = pcache1.pFree;
pcache1.pFree = pSlot;
}else{
int iSize = sqlite3MallocSize(p);
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
sqlite3_free(p);
}
}
/*
** Allocate a new page object initially associated with cache pCache.
*/
static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
int nByte = sizeof(PgHdr1) + pCache->szPage;
PgHdr1 *p = (PgHdr1 *)pcache1Alloc(nByte);
if( p ){
memset(p, 0, nByte);
if( pCache->bPurgeable ){
pcache1.nCurrentPage++;
}
}
return p;
}
/*
** Free a page object allocated by pcache1AllocPage().
*/
static void pcache1FreePage(PgHdr1 *p){
if( p ){
if( p->pCache->bPurgeable ){
pcache1.nCurrentPage--;
}
pcache1Free(p);
}
}
/*
** Malloc function used by SQLite to obtain space from the buffer configured
** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
** exists, this function falls back to sqlite3Malloc().
*/
void *sqlite3PageMalloc(int sz){
void *p;
pcache1EnterMutex();
p = pcache1Alloc(sz);
pcache1LeaveMutex();
return p;
}
/*
** Free an allocated buffer obtained from sqlite3PageMalloc().
*/
void sqlite3PageFree(void *p){
pcache1EnterMutex();
pcache1Free(p);
pcache1LeaveMutex();
}
/******************************************************************************/
/******** General Implementation Functions ************************************/
/*
** This function is used to resize the hash table used by the cache passed
** as the first argument.
**
** The global mutex must be held when this function is called.
*/
static int pcache1ResizeHash(PCache1 *p){
PgHdr1 **apNew;
unsigned int nNew;
unsigned int i;
assert( sqlite3_mutex_held(pcache1.mutex) );
nNew = p->nHash*2;
if( nNew<256 ){
nNew = 256;
}
pcache1LeaveMutex();
apNew = (PgHdr1 **)sqlite3_malloc(sizeof(PgHdr1 *)*nNew);
pcache1EnterMutex();
if( apNew ){
memset(apNew, 0, sizeof(PgHdr1 *)*nNew);
for(i=0; i<p->nHash; i++){
PgHdr1 *pPage;
PgHdr1 *pNext = p->apHash[i];
while( (pPage = pNext) ){
unsigned int h = pPage->iKey % nNew;
pNext = pPage->pNext;
pPage->pNext = apNew[h];
apNew[h] = pPage;
}
}
sqlite3_free(p->apHash);
p->apHash = apNew;
p->nHash = nNew;
}
return (p->apHash ? SQLITE_OK : SQLITE_NOMEM);
}
/*
** This function is used internally to remove the page pPage from the
** global LRU list, if is part of it. If pPage is not part of the global
** LRU list, then this function is a no-op.
**
** The global mutex must be held when this function is called.
*/
static void pcache1PinPage(PgHdr1 *pPage){
assert( sqlite3_mutex_held(pcache1.mutex) );
if( pPage && (pPage->pLruNext || pPage==pcache1.pLruTail) ){
if( pPage->pLruPrev ){
pPage->pLruPrev->pLruNext = pPage->pLruNext;
}
if( pPage->pLruNext ){
pPage->pLruNext->pLruPrev = pPage->pLruPrev;
}
if( pcache1.pLruHead==pPage ){
pcache1.pLruHead = pPage->pLruNext;
}
if( pcache1.pLruTail==pPage ){
pcache1.pLruTail = pPage->pLruPrev;
}
pPage->pLruNext = 0;
pPage->pLruPrev = 0;
pPage->pCache->nRecyclable--;
}
}
/*
** Remove the page supplied as an argument from the hash table
** (PCache1.apHash structure) that it is currently stored in.
**
** The global mutex must be held when this function is called.
*/
static void pcache1RemoveFromHash(PgHdr1 *pPage){
unsigned int h;
PCache1 *pCache = pPage->pCache;
PgHdr1 **pp;
h = pPage->iKey % pCache->nHash;
for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
*pp = (*pp)->pNext;
pCache->nPage--;
}
/*
** If there are currently more than pcache.nMaxPage pages allocated, try
** to recycle pages to reduce the number allocated to pcache.nMaxPage.
*/
static void pcache1EnforceMaxPage(void){
assert( sqlite3_mutex_held(pcache1.mutex) );
while( pcache1.nCurrentPage>pcache1.nMaxPage && pcache1.pLruTail ){
PgHdr1 *p = pcache1.pLruTail;
pcache1PinPage(p);
pcache1RemoveFromHash(p);
pcache1FreePage(p);
}
}
/*
** Discard all pages from cache pCache with a page number (key value)
** greater than or equal to iLimit. Any pinned pages that meet this
** criteria are unpinned before they are discarded.
**
** The global mutex must be held when this function is called.
*/
static void pcache1TruncateUnsafe(
PCache1 *pCache,
unsigned int iLimit
){
unsigned int h;
assert( sqlite3_mutex_held(pcache1.mutex) );
for(h=0; h<pCache->nHash; h++){
PgHdr1 **pp = &pCache->apHash[h];
PgHdr1 *pPage;
while( (pPage = *pp) ){
if( pPage->iKey>=iLimit ){
pcache1PinPage(pPage);
*pp = pPage->pNext;
pcache1FreePage(pPage);
}else{
pp = &pPage->pNext;
}
}
}
}
/******************************************************************************/
/******** sqlite3_pcache Methods **********************************************/
/*
** Implementation of the sqlite3_pcache.xInit method.
*/
static int pcache1Init(void *NotUsed){
UNUSED_PARAMETER(NotUsed);
memset(&pcache1, 0, sizeof(pcache1));
if( sqlite3GlobalConfig.bCoreMutex ){
pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
}
return SQLITE_OK;
}
/*
** Implementation of the sqlite3_pcache.xShutdown method.
*/
static void pcache1Shutdown(void *NotUsed){
UNUSED_PARAMETER(NotUsed);
/* no-op */
}
/*
** Implementation of the sqlite3_pcache.xCreate method.
**
** Allocate a new cache.
*/
static sqlite3_pcache *pcache1Create(int szPage, int bPurgeable){
PCache1 *pCache;
pCache = (PCache1 *)sqlite3_malloc(sizeof(PCache1));
if( pCache ){
memset(pCache, 0, sizeof(PCache1));
pCache->szPage = szPage;
pCache->bPurgeable = (bPurgeable ? 1 : 0);
if( bPurgeable ){
pCache->nMin = 10;
pcache1EnterMutex();
pcache1.nMinPage += pCache->nMin;
pcache1LeaveMutex();
}
}
return (sqlite3_pcache *)pCache;
}
/*
** Implementation of the sqlite3_pcache.xCachesize method.
**
** Configure the cache_size limit for a cache.
*/
static void pcache1Cachesize(sqlite3_pcache *p, int nMax){
PCache1 *pCache = (PCache1 *)p;
if( pCache->bPurgeable ){
pcache1EnterMutex();
pcache1.nMaxPage += (nMax - pCache->nMax);
pCache->nMax = nMax;
pcache1EnforceMaxPage();
pcache1LeaveMutex();
}
}
/*
** Implementation of the sqlite3_pcache.xPagecount method.
*/
static int pcache1Pagecount(sqlite3_pcache *p){
int n;
pcache1EnterMutex();
n = ((PCache1 *)p)->nPage;
pcache1LeaveMutex();
return n;
}
/*
** Implementation of the sqlite3_pcache.xFetch method.
**
** Fetch a page by key value.
**
** Whether or not a new page may be allocated by this function depends on
** the value of the createFlag argument.
**
** There are three different approaches to obtaining space for a page,
** depending on the value of parameter createFlag (which may be 0, 1 or 2).
**
** 1. Regardless of the value of createFlag, the cache is searched for a
** copy of the requested page. If one is found, it is returned.
**
** 2. If createFlag==0 and the page is not already in the cache, NULL is
** returned.
**
** 3. If createFlag is 1, the cache is marked as purgeable and the page is
** not already in the cache, and if either of the following are true,
** return NULL:
**
** (a) the number of pages pinned by the cache is greater than
** PCache1.nMax, or
** (b) the number of pages pinned by the cache is greater than
** the sum of nMax for all purgeable caches, less the sum of
** nMin for all other purgeable caches.
**
** 4. If none of the first three conditions apply and the cache is marked
** as purgeable, and if one of the following is true:
**
** (a) The number of pages allocated for the cache is already
** PCache1.nMax, or
**
** (b) The number of pages allocated for all purgeable caches is
** already equal to or greater than the sum of nMax for all
** purgeable caches,
**
** then attempt to recycle a page from the LRU list. If it is the right
** size, return the recycled buffer. Otherwise, free the buffer and
** proceed to step 5.
**
** 5. Otherwise, allocate and return a new page buffer.
*/
static void *pcache1Fetch(sqlite3_pcache *p, unsigned int iKey, int createFlag){
unsigned int nPinned;
PCache1 *pCache = (PCache1 *)p;
PgHdr1 *pPage = 0;
pcache1EnterMutex();
if( createFlag==1 ) sqlite3BeginBenignMalloc();
/* Search the hash table for an existing entry. */
if( pCache->nHash>0 ){
unsigned int h = iKey % pCache->nHash;
for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
}
if( pPage || createFlag==0 ){
pcache1PinPage(pPage);
goto fetch_out;
}
/* Step 3 of header comment. */
nPinned = pCache->nPage - pCache->nRecyclable;
if( createFlag==1 && pCache->bPurgeable && (
nPinned>=(pcache1.nMaxPage+pCache->nMin-pcache1.nMinPage)
|| nPinned>=(pCache->nMax)
)){
goto fetch_out;
}
if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
goto fetch_out;
}
/* Step 4. Try to recycle a page buffer if appropriate. */
if( pCache->bPurgeable && pcache1.pLruTail && (
pCache->nPage>=pCache->nMax-1 || pcache1.nCurrentPage>=pcache1.nMaxPage
)){
pPage = pcache1.pLruTail;
pcache1RemoveFromHash(pPage);
pcache1PinPage(pPage);
if( pPage->pCache->szPage!=pCache->szPage ){
pcache1FreePage(pPage);
pPage = 0;
}else{
pcache1.nCurrentPage -= (pPage->pCache->bPurgeable - pCache->bPurgeable);
}
}
/* Step 5. If a usable page buffer has still not been found,
** attempt to allocate a new one.
*/
if( !pPage ){
pPage = pcache1AllocPage(pCache);
}
if( pPage ){
unsigned int h = iKey % pCache->nHash;
memset(pPage, 0, pCache->szPage + sizeof(PgHdr1));
pCache->nPage++;
pPage->iKey = iKey;
pPage->pNext = pCache->apHash[h];
pPage->pCache = pCache;
pCache->apHash[h] = pPage;
}
fetch_out:
if( createFlag==1 ) sqlite3EndBenignMalloc();
pcache1LeaveMutex();
return (pPage ? PGHDR1_TO_PAGE(pPage) : 0);
}
/*
** Implementation of the sqlite3_pcache.xUnpin method.
**
** Mark a page as unpinned (eligible for asynchronous recycling).
*/
static void pcache1Unpin(sqlite3_pcache *p, void *pPg, int reuseUnlikely){
PCache1 *pCache = (PCache1 *)p;
PgHdr1 *pPage = PAGE_TO_PGHDR1(pPg);
pcache1EnterMutex();
/* It is an error to call this function if the page is already
** part of the global LRU list.
*/
assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
assert( pcache1.pLruHead!=pPage && pcache1.pLruTail!=pPage );
if( reuseUnlikely || pcache1.nCurrentPage>pcache1.nMaxPage ){
pcache1RemoveFromHash(pPage);
pcache1FreePage(pPage);
}else{
/* Add the page to the global LRU list. Normally, the page is added to
** the head of the list (last page to be recycled). However, if the
** reuseUnlikely flag passed to this function is true, the page is added
** to the tail of the list (first page to be recycled).
*/
if( pcache1.pLruHead ){
pcache1.pLruHead->pLruPrev = pPage;
pPage->pLruNext = pcache1.pLruHead;
pcache1.pLruHead = pPage;
}else{
pcache1.pLruTail = pPage;
pcache1.pLruHead = pPage;
}
pCache->nRecyclable++;
}
pcache1LeaveMutex();
}
/*
** Implementation of the sqlite3_pcache.xRekey method.
*/
static void pcache1Rekey(
sqlite3_pcache *p,
void *pPg,
unsigned int iOld,
unsigned int iNew
){
PCache1 *pCache = (PCache1 *)p;
PgHdr1 *pPage = PAGE_TO_PGHDR1(pPg);
PgHdr1 **pp;
unsigned int h;
assert( pPage->iKey==iOld );
pcache1EnterMutex();
h = iOld%pCache->nHash;
pp = &pCache->apHash[h];
while( (*pp)!=pPage ){
pp = &(*pp)->pNext;
}
*pp = pPage->pNext;
h = iNew%pCache->nHash;
pPage->iKey = iNew;
pPage->pNext = pCache->apHash[h];
pCache->apHash[h] = pPage;
pcache1LeaveMutex();
}
/*
** Implementation of the sqlite3_pcache.xTruncate method.
**
** Discard all unpinned pages in the cache with a page number equal to
** or greater than parameter iLimit. Any pinned pages with a page number
** equal to or greater than iLimit are implicitly unpinned.
*/
static void pcache1Truncate(sqlite3_pcache *p, unsigned int iLimit){
PCache1 *pCache = (PCache1 *)p;
pcache1EnterMutex();
pcache1TruncateUnsafe(pCache, iLimit);
pcache1LeaveMutex();
}
/*
** Implementation of the sqlite3_pcache.xDestroy method.
**
** Destroy a cache allocated using pcache1Create().
*/
static void pcache1Destroy(sqlite3_pcache *p){
PCache1 *pCache = (PCache1 *)p;
pcache1EnterMutex();
pcache1TruncateUnsafe(pCache, 0);
pcache1.nMaxPage -= pCache->nMax;
pcache1.nMinPage -= pCache->nMin;
pcache1EnforceMaxPage();
pcache1LeaveMutex();
sqlite3_free(pCache->apHash);
sqlite3_free(pCache);
}
/*
** This function is called during initialization (sqlite3_initialize()) to
** install the default pluggable cache module, assuming the user has not
** already provided an alternative.
*/
void sqlite3PCacheSetDefault(void){
static sqlite3_pcache_methods defaultMethods = {
0, /* pArg */
pcache1Init, /* xInit */
pcache1Shutdown, /* xShutdown */
pcache1Create, /* xCreate */
pcache1Cachesize, /* xCachesize */
pcache1Pagecount, /* xPagecount */
pcache1Fetch, /* xFetch */
pcache1Unpin, /* xUnpin */
pcache1Rekey, /* xRekey */
pcache1Truncate, /* xTruncate */
pcache1Destroy /* xDestroy */
};
sqlite3_config(SQLITE_CONFIG_PCACHE, &defaultMethods);
}
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
/*
** This function is called to free superfluous dynamically allocated memory
** held by the pager system. Memory in use by any SQLite pager allocated
** by the current thread may be sqlite3_free()ed.
**
** nReq is the number of bytes of memory required. Once this much has
** been released, the function returns. The return value is the total number
** of bytes of memory released.
*/
int sqlite3PcacheReleaseMemory(int nReq){
int nFree = 0;
if( pcache1.pStart==0 ){
PgHdr1 *p;
pcache1EnterMutex();
while( (nReq<0 || nFree<nReq) && (p=pcache1.pLruTail) ){
nFree += sqlite3MallocSize(p);
pcache1PinPage(p);
pcache1RemoveFromHash(p);
pcache1FreePage(p);
}
pcache1LeaveMutex();
}
return nFree;
}
#endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
#ifdef SQLITE_TEST
/*
** This function is used by test procedures to inspect the internal state
** of the global cache.
*/
void sqlite3PcacheStats(
int *pnCurrent, /* OUT: Total number of pages cached */
int *pnMax, /* OUT: Global maximum cache size */
int *pnMin, /* OUT: Sum of PCache1.nMin for purgeable caches */
int *pnRecyclable /* OUT: Total number of pages available for recycling */
){
PgHdr1 *p;
int nRecyclable = 0;
for(p=pcache1.pLruHead; p; p=p->pLruNext){
nRecyclable++;
}
*pnCurrent = pcache1.nCurrentPage;
*pnMax = pcache1.nMaxPage;
*pnMin = pcache1.nMinPage;
*pnRecyclable = nRecyclable;
}
#endif
+66 -44
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.187 2008/09/16 14:38:03 danielk1977 Exp $
** $Id: pragma.c,v 1.194 2008/11/17 19:18:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -41,7 +41,7 @@ static int getSafetyLevel(const char *z){
return atoi(z);
}
n = strlen(z);
for(i=0; i<sizeof(iLength); i++){
for(i=0; i<ArraySize(iLength); i++){
if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
return iValue[i];
}
@@ -151,7 +151,7 @@ static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
sqlite3VdbeAddOp2(v, OP_Integer, value, mem);
if( pParse->explain==0 ){
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
}
sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
}
@@ -191,7 +191,7 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
};
int i;
const struct sPragmaType *p;
for(i=0, p=aPragma; i<sizeof(aPragma)/sizeof(aPragma[0]); i++, p++){
for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
if( sqlite3StrICmp(zLeft, p->zName)==0 ){
sqlite3 *db = pParse->db;
Vdbe *v;
@@ -221,6 +221,16 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
}
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
static const char *actionName(u8 action){
switch( action ){
case OE_SetNull: return "SET NULL";
case OE_SetDflt: return "SET DEFAULT";
case OE_Restrict: return "RESTRICT";
case OE_Cascade: return "CASCADE";
}
return "";
}
/*
** Process a pragma statement.
**
@@ -312,7 +322,7 @@ void sqlite3Pragma(
sqlite3VdbeUsesBtree(v, iDb);
if( !zRight ){
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
pParse->nMem += 2;
addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
sqlite3VdbeChangeP1(v, addr, iDb);
@@ -393,7 +403,7 @@ void sqlite3Pragma(
sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", SQLITE_STATIC);
}else
/*
@@ -438,24 +448,26 @@ void sqlite3Pragma(
zRet = "exclusive";
}
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
}else
/*
** PRAGMA [database.]journal_mode
** PRAGMA [database.]journal_mode = (delete|persist|off)
** PRAGMA [database.]journal_mode = (delete|persist|off|truncate|memory)
*/
if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
int eMode;
static char * const azModeName[] = {"delete", "persist", "off"};
static char * const azModeName[] = {
"delete", "persist", "off", "truncate", "memory"
};
if( zRight==0 ){
eMode = PAGER_JOURNALMODE_QUERY;
}else{
int n = strlen(zRight);
eMode = 2;
eMode = sizeof(azModeName)/sizeof(azModeName[0]) - 1;
while( eMode>=0 && sqlite3StrNICmp(zRight, azModeName[eMode], n)!=0 ){
eMode--;
}
@@ -491,10 +503,12 @@ void sqlite3Pragma(
eMode = sqlite3PagerJournalMode(pPager, eMode);
}
assert( eMode==PAGER_JOURNALMODE_DELETE
|| eMode==PAGER_JOURNALMODE_TRUNCATE
|| eMode==PAGER_JOURNALMODE_PERSIST
|| eMode==PAGER_JOURNALMODE_OFF );
|| eMode==PAGER_JOURNALMODE_OFF
|| eMode==PAGER_JOURNALMODE_MEMORY );
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0,
azModeName[eMode], P4_STATIC);
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
@@ -661,7 +675,7 @@ void sqlite3Pragma(
if( sqlite3_temp_directory ){
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
"temp_store_directory", P4_STATIC);
"temp_store_directory", SQLITE_STATIC);
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
}
@@ -746,12 +760,12 @@ void sqlite3Pragma(
Column *pCol;
sqlite3VdbeSetNumCols(v, 6);
pParse->nMem = 6;
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P4_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P4_STATIC);
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P4_STATIC);
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P4_STATIC);
sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
sqlite3ViewGetColumnNames(pParse, pTab);
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
const Token *pDflt;
@@ -763,7 +777,7 @@ void sqlite3Pragma(
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
pCol->zType ? pCol->zType : "", 0);
sqlite3VdbeAddOp2(v, OP_Integer, pCol->notNull, 4);
sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){
sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pDflt->z, pDflt->n);
}else{
@@ -785,9 +799,9 @@ void sqlite3Pragma(
pTab = pIdx->pTable;
sqlite3VdbeSetNumCols(v, 3);
pParse->nMem = 3;
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P4_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P4_STATIC);
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
for(i=0; i<pIdx->nColumn; i++){
int cnum = pIdx->aiColumn[i];
sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
@@ -811,9 +825,9 @@ void sqlite3Pragma(
int i = 0;
sqlite3VdbeSetNumCols(v, 3);
pParse->nMem = 3;
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P4_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
while(pIdx){
sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
@@ -831,9 +845,9 @@ void sqlite3Pragma(
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
sqlite3VdbeSetNumCols(v, 3);
pParse->nMem = 3;
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P4_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
for(i=0; i<db->nDb; i++){
if( db->aDb[i].pBt==0 ) continue;
assert( db->aDb[i].zName!=0 );
@@ -850,8 +864,8 @@ void sqlite3Pragma(
HashElem *p;
sqlite3VdbeSetNumCols(v, 2);
pParse->nMem = 2;
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P4_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
CollSeq *pColl = (CollSeq *)sqliteHashData(p);
sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
@@ -872,24 +886,32 @@ void sqlite3Pragma(
pFK = pTab->pFKey;
if( pFK ){
int i = 0;
sqlite3VdbeSetNumCols(v, 5);
pParse->nMem = 5;
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P4_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P4_STATIC);
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P4_STATIC);
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P4_STATIC);
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P4_STATIC);
sqlite3VdbeSetNumCols(v, 8);
pParse->nMem = 8;
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
while(pFK){
int j;
for(j=0; j<pFK->nCol; j++){
char *zCol = pFK->aCol[j].zCol;
char *zOnUpdate = (char *)actionName(pFK->updateConf);
char *zOnDelete = (char *)actionName(pFK->deleteConf);
sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
sqlite3VdbeAddOp2(v, OP_Integer, j, 2);
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0);
sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0);
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0);
sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0);
sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0);
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
}
++i;
pFK = pFK->pNextFrom;
@@ -951,7 +973,7 @@ void sqlite3Pragma(
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
pParse->nMem = 6;
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
/* Set the maximum error count */
mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
@@ -1130,7 +1152,7 @@ void sqlite3Pragma(
if( !zRight ){ /* "PRAGMA encoding" */
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
if( pEnc->enc==ENC(pParse->db) ){
@@ -1231,7 +1253,7 @@ void sqlite3Pragma(
sqlite3VdbeChangeP1(v, addr, iDb);
sqlite3VdbeChangeP3(v, addr, iCookie);
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, P4_TRANSIENT);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
}
}else
#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
@@ -1248,8 +1270,8 @@ void sqlite3Pragma(
Vdbe *v = sqlite3GetVdbe(pParse);
sqlite3VdbeSetNumCols(v, 2);
pParse->nMem = 2;
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P4_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
for(i=0; i<db->nDb; i++){
Btree *pBt;
Pager *pPager;
+16 -15
View File
@@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.97 2008/09/08 09:06:19 danielk1977 Exp $
** $Id: prepare.c,v 1.101 2008/11/19 16:52:44 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -52,11 +52,13 @@ static void corruptSchema(
** argv[2] = SQL text for the CREATE statement.
**
*/
int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){
InitData *pData = (InitData*)pInit;
sqlite3 *db = pData->db;
int iDb = pData->iDb;
assert( argc==3 );
UNUSED_PARAMETER2(NotUsed, argc);
assert( sqlite3_mutex_held(db->mutex) );
DbClearProperty(db, iDb, DB_Empty);
if( db->mallocFailed ){
@@ -64,7 +66,6 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
return SQLITE_NOMEM;
}
assert( argc==3 );
assert( iDb>=0 && iDb<db->nDb );
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
if( argv[1]==0 ){
@@ -244,7 +245,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
*/
if( rc==SQLITE_OK ){
int i;
for(i=0; i<sizeof(meta)/sizeof(meta[0]); i++){
for(i=0; i<ArraySize(meta); i++){
rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
if( rc ){
sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
@@ -601,19 +602,19 @@ static int sqlite3Prepare(
if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
if( sParse.explain==2 ){
sqlite3VdbeSetNumCols(sParse.pVdbe, 3);
sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "order", P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "order", SQLITE_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", SQLITE_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", SQLITE_STATIC);
}else{
sqlite3VdbeSetNumCols(sParse.pVdbe, 8);
sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 5, COLNAME_NAME, "p4", P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 6, COLNAME_NAME, "p5", P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 7, COLNAME_NAME, "comment",P4_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", SQLITE_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", SQLITE_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", SQLITE_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", SQLITE_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", SQLITE_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 5, COLNAME_NAME, "p4", SQLITE_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 6, COLNAME_NAME, "p5", SQLITE_STATIC);
sqlite3VdbeSetColName(sParse.pVdbe, 7, COLNAME_NAME, "comment", SQLITE_STATIC);
}
}
#endif
+7 -5
View File
@@ -5,7 +5,7 @@
** an historical reference. Most of the "enhancements" have been backed
** out so that the functionality is now the same as standard printf().
**
** $Id: printf.c,v 1.94 2008/08/22 14:08:36 drh Exp $
** $Id: printf.c,v 1.96 2008/11/20 18:20:28 drh Exp $
**
**************************************************************************
**
@@ -137,7 +137,6 @@ static const et_info fmtinfo[] = {
{ 'S', 0, 2, etSRCLIST, 0, 0 },
{ 'r', 10, 3, etORDINAL, 0, 0 },
};
#define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
/*
** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
@@ -174,7 +173,7 @@ static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
*/
static void appendSpace(StrAccum *pAccum, int N){
static const char zSpaces[] = " ";
while( N>=sizeof(zSpaces)-1 ){
while( N>=(int)sizeof(zSpaces)-1 ){
sqlite3StrAccumAppend(pAccum, zSpaces, sizeof(zSpaces)-1);
N -= sizeof(zSpaces)-1;
}
@@ -337,7 +336,7 @@ void sqlite3VXPrintf(
}
/* Fetch the info entry for the field */
infop = 0;
for(idx=0; idx<etNINFO; idx++){
for(idx=0; idx<ArraySize(fmtinfo); idx++){
if( c==fmtinfo[idx].fmttype ){
infop = &fmtinfo[idx];
if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
@@ -646,7 +645,10 @@ void sqlite3VXPrintf(
n += i + 1 + needQuote*2;
if( n>etBUFSIZE ){
bufpt = zExtra = sqlite3Malloc( n );
if( bufpt==0 ) return;
if( bufpt==0 ){
pAccum->mallocFailed = 1;
return;
}
}else{
bufpt = buf;
}
+2 -2
View File
@@ -15,7 +15,7 @@
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
**
** $Id: random.c,v 1.26 2008/09/02 00:52:52 drh Exp $
** $Id: random.c,v 1.27 2008/10/07 15:25:48 drh Exp $
*/
#include "sqliteInt.h"
@@ -106,7 +106,7 @@ static int randomByte(void){
*/
void sqlite3_randomness(int N, void *pBuf){
unsigned char *zBuf = pBuf;
#ifndef SQLITE_MUTEX_NOOP
#if SQLITE_THREADSAFE
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
#endif
sqlite3_mutex_enter(mutex);
+26 -6
View File
@@ -14,7 +14,7 @@
** resolve all identifiers by associating them with a particular
** table and column.
**
** $Id: resolve.c,v 1.5 2008/08/29 02:14:03 drh Exp $
** $Id: resolve.c,v 1.11 2008/11/17 19:18:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
@@ -77,8 +77,7 @@ static void resolveAlias(
pDup->pColl = pExpr->pColl;
pDup->flags |= EP_ExpCollate;
}
if( pExpr->span.dyn ) sqlite3DbFree(db, (char*)pExpr->span.z);
if( pExpr->token.dyn ) sqlite3DbFree(db, (char*)pExpr->token.z);
sqlite3ExprClear(db, pExpr);
memcpy(pExpr, pDup, sizeof(*pExpr));
sqlite3DbFree(db, pDup);
}
@@ -321,6 +320,7 @@ static int lookupName(
if( cnt==0 && zTab==0 && pColumnToken->z[0]=='"' ){
sqlite3DbFree(db, zCol);
pExpr->op = TK_STRING;
pExpr->pTab = 0;
return 0;
}
@@ -349,9 +349,9 @@ static int lookupName(
*/
if( pExpr->iColumn>=0 && pMatch!=0 ){
int n = pExpr->iColumn;
testcase( n==sizeof(Bitmask)*8-1 );
if( n>=sizeof(Bitmask)*8 ){
n = sizeof(Bitmask)*8-1;
testcase( n==BMS-1 );
if( n>=BMS ){
n = BMS-1;
}
assert( pMatch->iCursor==pExpr->iTable );
pMatch->colUsed |= ((Bitmask)1)<<n;
@@ -418,6 +418,26 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
}
#endif
switch( pExpr->op ){
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
/* The special operator TK_ROW means use the rowid for the first
** column in the FROM clause. This is used by the LIMIT and ORDER BY
** clause processing on UPDATE and DELETE statements.
*/
case TK_ROW: {
SrcList *pSrcList = pNC->pSrcList;
struct SrcList_item *pItem;
assert( pSrcList && pSrcList->nSrc==1 );
pItem = pSrcList->a;
pExpr->op = TK_COLUMN;
pExpr->pTab = pItem->pTab;
pExpr->iTable = pItem->iCursor;
pExpr->iColumn = -1;
pExpr->affinity = SQLITE_AFF_INTEGER;
break;
}
#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */
/* A lone identifier is the name of a column.
*/
case TK_ID: {
+166 -77
View File
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.475 2008/09/17 00:13:12 drh Exp $
** $Id: select.c,v 1.486 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -65,7 +65,7 @@ Select *sqlite3SelectNew(
Select standin;
sqlite3 *db = pParse->db;
pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
assert( !pOffset || pLimit ); /* Can't have OFFSET without LIMIT. */
assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
if( pNew==0 ){
pNew = &standin;
memset(pNew, 0, sizeof(*pNew));
@@ -81,7 +81,6 @@ Select *sqlite3SelectNew(
pNew->pOrderBy = pOrderBy;
pNew->selFlags = isDistinct ? SF_Distinct : 0;
pNew->op = TK_SELECT;
assert( pOffset==0 || pLimit!=0 );
pNew->pLimit = pLimit;
pNew->pOffset = pOffset;
pNew->addrOpenEphm[0] = -1;
@@ -145,14 +144,14 @@ int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){
apAll[2] = pC;
for(i=0; i<3 && apAll[i]; i++){
p = apAll[i];
for(j=0; j<sizeof(keywords)/sizeof(keywords[0]); j++){
for(j=0; j<ArraySize(keywords); j++){
if( p->n==keywords[j].nChar
&& sqlite3StrNICmp((char*)p->z, keywords[j].zKeyword, p->n)==0 ){
jointype |= keywords[j].code;
break;
}
}
if( j>=sizeof(keywords)/sizeof(keywords[0]) ){
if( j>=ArraySize(keywords) ){
jointype |= JT_ERROR;
break;
}
@@ -1034,13 +1033,13 @@ static void generateColumnTypes(
** column specific strings, in case the schema is reset before this
** virtual machine is deleted.
*/
sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, P4_TRANSIENT);
sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, P4_TRANSIENT);
sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, P4_TRANSIENT);
sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, SQLITE_TRANSIENT);
sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, SQLITE_TRANSIENT);
sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, SQLITE_TRANSIENT);
#else
zType = columnType(&sNC, p, 0, 0, 0);
#endif
sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, P4_TRANSIENT);
sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
}
#endif /* SQLITE_OMIT_DECLTYPE */
}
@@ -1079,7 +1078,7 @@ static void generateColumnNames(
if( p==0 ) continue;
if( pEList->a[i].zName ){
char *zName = pEList->a[i].zName;
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, strlen(zName));
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
}else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN) && pTabList ){
Table *pTab;
char *zCol;
@@ -1095,7 +1094,8 @@ static void generateColumnNames(
zCol = pTab->aCol[iCol].zName;
}
if( !shortNames && !fullNames ){
sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n);
sqlite3VdbeSetColName(v, i, COLNAME_NAME,
sqlite3DbStrNDup(db, (char*)p->span.z, p->span.n), SQLITE_DYNAMIC);
}else if( fullNames || (!shortNames && pTabList->nSrc>1) ){
char *zName = 0;
char *zTab;
@@ -1103,12 +1103,13 @@ static void generateColumnNames(
zTab = pTabList->a[j].zAlias;
if( fullNames || zTab==0 ) zTab = pTab->zName;
zName = sqlite3MPrintf(db, "%s.%s", zTab, zCol);
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, P4_DYNAMIC);
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
}else{
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, strlen(zCol));
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT);
}
}else{
sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n);
sqlite3VdbeSetColName(v, i, COLNAME_NAME,
sqlite3DbStrNDup(db, (char*)p->span.z, p->span.n), SQLITE_DYNAMIC);
}
}
generateColumnTypes(pParse, pTabList, pEList);
@@ -2047,7 +2048,7 @@ static int multiSelectOrderBy(
int labelEnd; /* Label for the end of the overall SELECT stmt */
int j1; /* Jump instructions that get retargetted */
int op; /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */
KeyInfo *pKeyDup; /* Comparison information for duplicate removal */
KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
KeyInfo *pKeyMerge; /* Comparison information for merging rows */
sqlite3 *db; /* Database connection */
ExprList *pOrderBy; /* The ORDER BY clause */
@@ -2055,6 +2056,7 @@ static int multiSelectOrderBy(
int *aPermute; /* Mapping from ORDER BY terms to result set columns */
assert( p->pOrderBy!=0 );
assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */
db = pParse->db;
v = pParse->pVdbe;
if( v==0 ) return SQLITE_NOMEM;
@@ -2144,7 +2146,7 @@ static int multiSelectOrderBy(
regPrev = 0;
}else{
int nExpr = p->pEList->nExpr;
assert( nOrderBy>=nExpr );
assert( nOrderBy>=nExpr || db->mallocFailed );
regPrev = sqlite3GetTempRange(pParse, nExpr+1);
sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
pKeyDup = sqlite3DbMallocZero(db,
@@ -2571,7 +2573,9 @@ static int flattenSubquery(
/* Check to see if flattening is permitted. Return 0 if not.
*/
assert( p!=0 );
if( p==0 ) return 0;
assert( p->pPrior==0 ); /* Unable to flatten compound queries */
pSrc = p->pSrc;
assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
pSubitem = &pSrc->a[iFrom];
@@ -2683,92 +2687,146 @@ static int flattenSubquery(
** SELECT <expr-list> FROM (<sub-query>) <where-clause>
**
** followed by any ORDER BY, LIMIT and/or OFFSET clauses. This block
** creates N copies of the parent query without any ORDER BY, LIMIT or
** creates N-1 copies of the parent query without any ORDER BY, LIMIT or
** OFFSET clauses and joins them to the left-hand-side of the original
** using UNION ALL operators. In this case N is the number of simple
** select statements in the compound sub-query.
**
** Example:
**
** SELECT a+1 FROM (
** SELECT x FROM tab
** UNION ALL
** SELECT y FROM tab
** UNION ALL
** SELECT abs(z*2) FROM tab2
** ) WHERE a!=5 ORDER BY 1
**
** Transformed into:
**
** SELECT x+1 FROM tab WHERE x+1!=5
** UNION ALL
** SELECT y+1 FROM tab WHERE y+1!=5
** UNION ALL
** SELECT abs(z*2)+1 FROM tab2 WHERE abs(z*2)+1!=5
** ORDER BY 1
**
** We call this the "compound-subquery flattening".
*/
for(pSub=pSub->pPrior; pSub; pSub=pSub->pPrior){
Select *pNew;
ExprList *pOrderBy = p->pOrderBy;
Expr *pLimit = p->pLimit;
Expr *pOffset = p->pOffset;
Select *pPrior = p->pPrior;
p->pOrderBy = 0;
p->pSrc = 0;
p->pPrior = 0;
p->pLimit = 0;
pNew = sqlite3SelectDup(db, p);
pNew->pPrior = pPrior;
p->pPrior = pNew;
p->pOrderBy = pOrderBy;
p->op = TK_ALL;
p->pSrc = pSrc;
p->pLimit = pLimit;
p->pOffset = pOffset;
p->pOrderBy = pOrderBy;
p->pSrc = pSrc;
p->op = TK_ALL;
p->pRightmost = 0;
pNew->pRightmost = 0;
if( pNew==0 ){
pNew = pPrior;
}else{
pNew->pPrior = pPrior;
pNew->pRightmost = 0;
}
p->pPrior = pNew;
if( db->mallocFailed ) return 1;
}
/* Begin flattening the iFrom-th entry of the FROM clause
** in the outer query.
*/
pSub = pSub1 = pSubitem->pSelect;
/* Delete the transient table structure associated with the
** subquery
*/
sqlite3DbFree(db, pSubitem->zDatabase);
sqlite3DbFree(db, pSubitem->zName);
sqlite3DbFree(db, pSubitem->zAlias);
pSubitem->zDatabase = 0;
pSubitem->zName = 0;
pSubitem->zAlias = 0;
pSubitem->pSelect = 0;
/* Defer deleting the Table object associated with the
** subquery until code generation is
** complete, since there may still exist Expr.pTab entries that
** refer to the subquery even after flattening. Ticket #3346.
*/
if( pSubitem->pTab!=0 ){
Table *pTabToDel = pSubitem->pTab;
if( pTabToDel->nRef==1 ){
pTabToDel->pNextZombie = pParse->pZombieTab;
pParse->pZombieTab = pTabToDel;
}else{
pTabToDel->nRef--;
}
pSubitem->pTab = 0;
}
/* The following loop runs once for each term in a compound-subquery
** flattening (as described above). If we are doing a different kind
** of flattening - a flattening other than a compound-subquery flattening -
** then this loop only runs once.
**
** This loop moves all of the FROM elements of the subquery into the
** the FROM clause of the outer query. Before doing this, remember
** the cursor number for the original outer query FROM element in
** iParent. The iParent cursor will never be used. Subsequent code
** will scan expressions looking for iParent references and replace
** those references with expressions that resolve to the subquery FROM
** elements we are now copying in.
*/
for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){
int nSubSrc = pSubSrc->nSrc;
int nSubSrc;
int jointype = 0;
pSubSrc = pSub->pSrc;
pSrc = pParent->pSrc;
pSubSrc = pSub->pSrc; /* FROM clause of subquery */
nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
pSrc = pParent->pSrc; /* FROM clause of the outer query */
/* Move all of the FROM elements of the subquery into the
** the FROM clause of the outer query. Before doing this, remember
** the cursor number for the original outer query FROM element in
** iParent. The iParent cursor will never be used. Subsequent code
** will scan expressions looking for iParent references and replace
** those references with expressions that resolve to the subquery FROM
** elements we are now copying in.
*/
if( pSrc ){
Table *pTabToDel;
pSubitem = &pSrc->a[iFrom];
nSubSrc = pSubSrc->nSrc;
assert( pParent==p ); /* First time through the loop */
jointype = pSubitem->jointype;
sqlite3DbFree(db, pSubitem->zDatabase);
sqlite3DbFree(db, pSubitem->zName);
sqlite3DbFree(db, pSubitem->zAlias);
pSubitem->zDatabase = 0;
pSubitem->zName = 0;
pSubitem->zAlias = 0;
}else{
assert( pParent!=p ); /* 2nd and subsequent times through the loop */
pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
if( pSrc==0 ){
assert( db->mallocFailed );
break;
}
}
/* If the FROM element is a subquery, defer deleting the Table
** object associated with that subquery until code generation is
** complete, since there may still exist Expr.pTab entires that
** refer to the subquery even after flattening. Ticket #3346.
*/
if( (pTabToDel = pSubitem->pTab)!=0 ){
if( pTabToDel->nRef==1 ){
pTabToDel->pNextZombie = pParse->pZombieTab;
pParse->pZombieTab = pTabToDel;
}else{
pTabToDel->nRef--;
}
}
pSubitem->pTab = 0;
}
if( nSubSrc!=1 || !pSrc ){
int extra = nSubSrc - 1;
for(i=(pSrc?1:0); i<nSubSrc; i++){
pSrc = sqlite3SrcListAppend(db, pSrc, 0, 0);
if( pSrc==0 ){
pParent->pSrc = 0;
return 1;
}
}
pParent->pSrc = pSrc;
for(i=pSrc->nSrc-1; i-extra>=iFrom; i--){
pSrc->a[i] = pSrc->a[i-extra];
/* The subquery uses a single slot of the FROM clause of the outer
** query. If the subquery has more than one element in its FROM clause,
** then expand the outer query to make space for it to hold all elements
** of the subquery.
**
** Example:
**
** SELECT * FROM tabA, (SELECT * FROM sub1, sub2), tabB;
**
** The outer query has 3 slots in its FROM clause. One slot of the
** outer query (the middle slot) is used by the subquery. The next
** block of code will expand the out query to 4 slots. The middle
** slot is expanded to two slots in order to make space for the
** two elements in the FROM clause of the subquery.
*/
if( nSubSrc>1 ){
pParent->pSrc = pSrc = sqlite3SrcListEnlarge(db, pSrc, nSubSrc-1,iFrom+1);
if( db->mallocFailed ){
break;
}
}
/* Transfer the FROM clause terms from the subquery into the
** outer query.
*/
for(i=0; i<nSubSrc; i++){
pSrc->a[i+iFrom] = pSubSrc->a[i];
memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
@@ -2863,7 +2921,7 @@ static int flattenSubquery(
** 2. There is a single expression in the result set, and it is
** either min(x) or max(x), where x is a column reference.
*/
static int minMaxQuery(Parse *pParse, Select *p){
static int minMaxQuery(Select *p){
Expr *pExpr;
ExprList *pEList = p->pEList;
@@ -2881,6 +2939,31 @@ static int minMaxQuery(Parse *pParse, Select *p){
return WHERE_ORDERBY_NORMAL;
}
/*
** If the source-list item passed as an argument was augmented with an
** INDEXED BY clause, then try to locate the specified index. If there
** was such a clause and the named index cannot be found, return
** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
** pFrom->pIndex and return SQLITE_OK.
*/
int sqlite3IndexedByLookup(Parse *pParse, struct SrcList_item *pFrom){
if( pFrom->pTab && pFrom->zIndex ){
Table *pTab = pFrom->pTab;
char *zIndex = pFrom->zIndex;
Index *pIdx;
for(pIdx=pTab->pIndex;
pIdx && sqlite3StrICmp(pIdx->zName, zIndex);
pIdx=pIdx->pNext
);
if( !pIdx ){
sqlite3ErrorMsg(pParse, "no such index: %s", zIndex, 0);
return SQLITE_ERROR;
}
pFrom->pIndex = pIdx;
}
return SQLITE_OK;
}
/*
** This routine is a Walker callback for "expanding" a SELECT statement.
** "Expanding" means to do the following:
@@ -2981,6 +3064,11 @@ static int selectExpander(Walker *pWalker, Select *p){
}
#endif
}
/* Locate the index named by the INDEXED BY clause, if any. */
if( sqlite3IndexedByLookup(pParse, pFrom) ){
return WRC_Abort;
}
}
/* Process NATURAL keywords, and ON and USING clauses of joins.
@@ -3133,7 +3221,8 @@ static int selectExpander(Walker *pWalker, Select *p){
** Walker.xSelectCallback is set to do something useful for every
** subquery in the parser tree.
*/
static int exprWalkNoop(Walker *pWalker, Expr *pExpr){
static int exprWalkNoop(Walker *NotUsed, Expr *NotUsed2){
UNUSED_PARAMETER2(NotUsed, NotUsed2);
return WRC_Continue;
}
@@ -3325,11 +3414,11 @@ static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){
assert( nArg==1 );
codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
}
if( pF->pFunc->needCollSeq ){
if( pF->pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
CollSeq *pColl = 0;
struct ExprList_item *pItem;
int j;
assert( pList!=0 ); /* pList!=0 if pF->pFunc->needCollSeq is true */
assert( pList!=0 ); /* pList!=0 if pF->pFunc has NEEDCOLL */
for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
}
@@ -3924,7 +4013,7 @@ int sqlite3Select(
** satisfying the 'ORDER BY' clause than it does in other cases.
** Refer to code and comments in where.c for details.
*/
flag = minMaxQuery(pParse, p);
flag = minMaxQuery(p);
if( flag ){
pDel = pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->pList);
if( pMinMax && !db->mallocFailed ){
+10 -6
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.185 2008/08/11 19:12:35 drh Exp $
** $Id: shell.c,v 1.188 2008/11/17 08:05:32 chw Exp $
*/
#include <stdlib.h>
#include <string.h>
@@ -24,7 +24,9 @@
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__)
# include <signal.h>
# include <pwd.h>
# if !defined(__RTP__) && !defined(_WRS_KERNEL)
# include <pwd.h>
# endif
# include <unistd.h>
# include <sys/types.h>
#endif
@@ -60,7 +62,7 @@ extern int isatty();
#define isatty(x) 1
#endif
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__)
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(__RTP__) && !defined(_WRS_KERNEL)
#include <sys/time.h>
#include <sys/resource.h>
@@ -1699,7 +1701,7 @@ static int process_input(struct callback_data *p, FILE *in){
}
continue;
}
if( _is_command_terminator(zLine) ){
if( _is_command_terminator(zLine) && sqlite3_complete(zSql) ){
memcpy(zLine,";",2);
}
nSqlPrior = nSql;
@@ -1757,7 +1759,7 @@ static int process_input(struct callback_data *p, FILE *in){
}
}
if( zSql ){
if( !_all_whitespace(zSql) ) printf("Incomplete SQL: %s\n", zSql);
if( !_all_whitespace(zSql) ) fprintf(stderr, "Incomplete SQL: %s\n", zSql);
free(zSql);
}
free(zLine);
@@ -1773,7 +1775,7 @@ static int process_input(struct callback_data *p, FILE *in){
static char *find_home_dir(void){
char *home_dir = NULL;
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(_WIN32_WCE)
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL)
struct passwd *pwent;
uid_t uid = getuid();
if( (pwent=getpwuid(uid)) != NULL) {
@@ -1843,7 +1845,9 @@ static void process_sqliterc(
if (sqliterc == NULL) {
home_dir = find_home_dir();
if( home_dir==0 ){
#if !defined(__RTP__) && !defined(_WRS_KERNEL)
fprintf(stderr,"%s: cannot locate your home directory!\n", Argv0);
#endif
return;
}
nBuf = strlen(home_dir) + 16;
+459 -95
View File
@@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.398 2008/09/10 13:09:24 drh Exp $
** @(#) $Id: sqlite.h.in,v 1.415 2008/11/19 01:20:26 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -52,29 +52,20 @@ extern "C" {
#endif
/*
** Add the ability to mark interfaces as deprecated.
** These no-op macros are used in front of interfaces to mark those
** interfaces as either deprecated or experimental. New applications
** should not use deprecated intrfaces - they are support for backwards
** compatibility only. Application writers should be aware that
** experimental interfaces are subject to change in point releases.
**
** These macros used to resolve to various kinds of compiler magic that
** would generate warning messages when they were used. But that
** compiler magic ended up generating such a flurry of bug reports
** that we have taken it all out and gone back to using simple
** noop macros.
*/
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
/* GCC added the deprecated attribute in version 3.1 */
#define SQLITE_DEPRECATED __attribute__ ((deprecated))
#elif defined(_MSC_VER) && (_MSC_VER>1200)
#define SQLITE_DEPRECATED __declspec(deprecated)
#else
#define SQLITE_DEPRECATED
#endif
/*
** Add the ability to mark interfaces as experimental.
*/
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
/* I can confirm that it does not work on version 4.1.0... */
/* First appears in GCC docs for version 4.3.0 */
#define SQLITE_EXPERIMENTAL __attribute__ ((warning ("is experimental")))
#elif defined(_MSC_VER) && (_MSC_VER>1200)
#define SQLITE_EXPERIMENTAL __declspec(deprecated("was declared experimental"))
#else
#define SQLITE_EXPERIMENTAL
#endif
#define SQLITE_DEPRECATED
#define SQLITE_EXPERIMENTAL
/*
** Ensure these symbols were not defined by some previous header file.
@@ -182,16 +173,11 @@ int sqlite3_libversion_number(void);
**
** INVARIANTS:
**
** {H10101} The [sqlite3_threadsafe()] function shall return nonzero if
** and only if
** SQLite was compiled with the its mutexes enabled by default.
** {H10101} The [sqlite3_threadsafe()] function shall return zero if
** and only if SQLite was compiled with mutexing code omitted.
**
** {H10102} The value returned by the [sqlite3_threadsafe()] function
** shall not change when mutex setting are modified at
** runtime using the [sqlite3_config()] interface and
** especially the [SQLITE_CONFIG_SINGLETHREAD],
** [SQLITE_CONFIG_MULTITHREAD], [SQLITE_CONFIG_SERIALIZED],
** and [SQLITE_CONFIG_MUTEX] verbs.
** shall remain the same across calls to [sqlite3_config()].
*/
int sqlite3_threadsafe(void);
@@ -288,7 +274,7 @@ typedef sqlite_uint64 sqlite3_uint64;
** an [SQLITE_BUSY] error code.
**
** {H12015} A call to [sqlite3_close(C)] where C is a NULL pointer shall
** return SQLITE_OK.
** be a harmless no-op returning SQLITE_OK.
**
** {H12019} When [sqlite3_close(C)] is invoked on a [database connection] C
** that has a pending transaction, the transaction shall be
@@ -392,12 +378,14 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**);
** *E to NULL if E is not NULL and there are no errors.
**
** {H12137} The [sqlite3_exec(D,S,C,A,E)] function shall set the [error code]
** and message accessible via [sqlite3_errcode()],
** and message accessible via [sqlite3_errcode()],
** [sqlite3_extended_errcode()],
** [sqlite3_errmsg()], and [sqlite3_errmsg16()].
**
** {H12138} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL or an
** empty string or contains nothing other than whitespace, comments,
** and/or semicolons, then results of [sqlite3_errcode()],
** [sqlite3_extended_errcode()],
** [sqlite3_errmsg()], and [sqlite3_errmsg16()]
** shall reset to indicate no errors.
**
@@ -599,7 +587,7 @@ int sqlite3_exec(
** sync operation only needs to flush data to mass storage. Inode
** information need not be flushed. The SQLITE_SYNC_NORMAL flag means
** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means
** to use Mac OS-X style fullsync instead of fsync().
** to use Mac OS X style fullsync instead of fsync().
*/
#define SQLITE_SYNC_NORMAL 0x00002
#define SQLITE_SYNC_FULL 0x00003
@@ -631,7 +619,7 @@ struct sqlite3_file {
**
** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
** The second choice is a Mac OS-X style fullsync. The [SQLITE_SYNC_DATAONLY]
** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
** flag may be ORed in to indicate that only the data of the file
** and not its inode needs to be synced.
**
@@ -694,6 +682,12 @@ struct sqlite3_file {
** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
** information is written to disk in the same order as calls
** to xWrite().
**
** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
** in the unread portions of the buffer with zeros. A VFS that
** fails to zero-fill short reads might seem to work. However,
** failure to zero-fill short reads will eventually lead to
** database corruption.
*/
typedef struct sqlite3_io_methods sqlite3_io_methods;
struct sqlite3_io_methods {
@@ -920,24 +914,24 @@ struct sqlite3_vfs {
** sqlite3_os_init(). Similarly, sqlite3_shutdown()
** shall invoke sqlite3_os_end().
**
** The sqlite3_initialize() routine returns SQLITE_OK on success.
** The sqlite3_initialize() routine returns [SQLITE_OK] on success.
** If for some reason, sqlite3_initialize() is unable to initialize
** the library (perhaps it is unable to allocate a needed resource such
** as a mutex) it returns an [error code] other than SQLITE_OK.
** as a mutex) it returns an [error code] other than [SQLITE_OK].
**
** The sqlite3_initialize() routine is called internally by many other
** SQLite interfaces so that an application usually does not need to
** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
** calls sqlite3_initialize() so the SQLite library will be automatically
** initialized when [sqlite3_open()] is called if it has not be initialized
** already. However, if SQLite is compiled with the SQLITE_OMIT_AUTOINIT
** already. However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
** compile-time option, then the automatic calls to sqlite3_initialize()
** are omitted and the application must call sqlite3_initialize() directly
** prior to using any other SQLite interface. For maximum portability,
** it is recommended that applications always invoke sqlite3_initialize()
** directly prior to using any other SQLite interface. Future releases
** of SQLite may require this. In other words, the behavior exhibited
** when SQLite is compiled with SQLITE_OMIT_AUTOINIT might become the
** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
** default behavior in some future release of SQLite.
**
** The sqlite3_os_init() routine does operating-system specific
@@ -955,11 +949,11 @@ struct sqlite3_vfs {
** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
** implementations for sqlite3_os_init() and sqlite3_os_end()
** are built into SQLite when it is compiled for unix, windows, or os/2.
** When built for other platforms (using the SQLITE_OS_OTHER=1 compile-time
** When built for other platforms (using the [SQLITE_OS_OTHER=1] compile-time
** option) the application must supply a suitable implementation for
** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
** implementation of sqlite3_os_init() or sqlite3_os_end()
** must return SQLITE_OK on success and some other [error code] upon
** must return [SQLITE_OK] on success and some other [error code] upon
** failure.
*/
int sqlite3_initialize(void);
@@ -968,7 +962,7 @@ int sqlite3_os_init(void);
int sqlite3_os_end(void);
/*
** CAPI3REF: Configuring The SQLite Library {H10145} <S20000><S30200>
** CAPI3REF: Configuring The SQLite Library {H14100} <S20000><S30200>
** EXPERIMENTAL
**
** The sqlite3_config() interface is used to make global configuration
@@ -991,14 +985,103 @@ int sqlite3_os_end(void);
** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
** in the first argument.
**
** When a configuration option is set, sqlite3_config() returns SQLITE_OK.
** When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
** If the option is unknown or SQLite is unable to set the option
** then this routine returns a non-zero [error code].
**
** INVARIANTS:
**
** {H14103} A successful invocation of [sqlite3_config()] shall return
** [SQLITE_OK].
**
** {H14106} The [sqlite3_config()] interface shall return [SQLITE_MISUSE]
** if it is invoked in between calls to [sqlite3_initialize()] and
** [sqlite3_shutdown()].
**
** {H14120} A successful call to [sqlite3_config]([SQLITE_CONFIG_SINGLETHREAD])
** shall set the default [threading mode] to Single-thread.
**
** {H14123} A successful call to [sqlite3_config]([SQLITE_CONFIG_MULTITHREAD])
** shall set the default [threading mode] to Multi-thread.
**
** {H14126} A successful call to [sqlite3_config]([SQLITE_CONFIG_SERIALIZED])
** shall set the default [threading mode] to Serialized.
**
** {H14129} A successful call to [sqlite3_config]([SQLITE_CONFIG_MUTEX],X)
** where X is a pointer to an initialized [sqlite3_mutex_methods]
** object shall cause all subsequent mutex operations performed
** by SQLite to use the mutex methods that were present in X
** during the call to [sqlite3_config()].
**
** {H14132} A successful call to [sqlite3_config]([SQLITE_CONFIG_GETMUTEX],X)
** where X is a pointer to an [sqlite3_mutex_methods] object
** shall overwrite the content of [sqlite3_mutex_methods] object
** with the mutex methods currently in use by SQLite.
**
** {H14135} A successful call to [sqlite3_config]([SQLITE_CONFIG_MALLOC],M)
** where M is a pointer to an initialized [sqlite3_mem_methods]
** object shall cause all subsequent memory allocation operations
** performed by SQLite to use the methods that were present in
** M during the call to [sqlite3_config()].
**
** {H14138} A successful call to [sqlite3_config]([SQLITE_CONFIG_GETMALLOC],M)
** where M is a pointer to an [sqlite3_mem_methods] object shall
** overwrite the content of [sqlite3_mem_methods] object with
** the memory allocation methods currently in use by
** SQLite.
**
** {H14141} A successful call to [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],1)
** shall enable the memory allocation status collection logic.
**
** {H14144} A successful call to [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],0)
** shall disable the memory allocation status collection logic.
**
** {H14147} The memory allocation status collection logic shall be
** enabled by default.
**
** {H14150} A successful call to [sqlite3_config]([SQLITE_CONFIG_SCRATCH],S,Z,N)
** where Z and N are non-negative integers and
** S is a pointer to an aligned memory buffer not less than
** Z*N bytes in size shall cause S to be used by the
** [scratch memory allocator] for as many as N simulataneous
** allocations each of size Z.
**
** {H14153} A successful call to [sqlite3_config]([SQLITE_CONFIG_SCRATCH],S,Z,N)
** where S is a NULL pointer shall disable the
** [scratch memory allocator].
**
** {H14156} A successful call to
** [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],S,Z,N)
** where Z and N are non-negative integers and
** S is a pointer to an aligned memory buffer not less than
** Z*N bytes in size shall cause S to be used by the
** [pagecache memory allocator] for as many as N simulataneous
** allocations each of size Z.
**
** {H14159} A successful call to
** [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],S,Z,N)
** where S is a NULL pointer shall disable the
** [pagecache memory allocator].
**
** {H14162} A successful call to [sqlite3_config]([SQLITE_CONFIG_HEAP],H,Z,N)
** where Z and N are non-negative integers and
** H is a pointer to an aligned memory buffer not less than
** Z bytes in size shall enable the [memsys5] memory allocator
** and cause it to use buffer S as its memory source and to use
** a minimum allocation size of N.
**
** {H14165} A successful call to [sqlite3_config]([SQLITE_CONFIG_HEAP],H,Z,N)
** where H is a NULL pointer shall disable the
** [memsys5] memory allocator.
**
** {H14168} A successful call to [sqlite3_config]([SQLITE_CONFIG_LOOKASIDE],Z,N)
** shall cause the default [lookaside memory allocator] configuration
** for new [database connections] to be N slots of Z bytes each.
*/
SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
/*
** CAPI3REF: Configure database connections {H10180} <S20000>
** CAPI3REF: Configure database connections {H14200} <S20000>
** EXPERIMENTAL
**
** The sqlite3_db_config() interface is used to make configuration
@@ -1015,6 +1098,38 @@ SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
** New verbs are likely to be added in future releases of SQLite.
** Additional arguments depend on the verb.
**
** INVARIANTS:
**
** {H14203} A call to [sqlite3_db_config(D,V,...)] shall return [SQLITE_OK]
** if and only if the call is successful.
**
** {H14206} If one or more slots of the [lookaside memory allocator] for
** [database connection] D are in use, then a call to
** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],...) shall
** fail with an [SQLITE_BUSY] return code.
**
** {H14209} A successful call to
** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where
** D is an open [database connection] and Z and N are positive
** integers and B is an aligned buffer at least Z*N bytes in size
** shall cause the [lookaside memory allocator] for D to use buffer B
** with N slots of Z bytes each.
**
** {H14212} A successful call to
** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where
** D is an open [database connection] and Z and N are positive
** integers and B is NULL pointer shall cause the
** [lookaside memory allocator] for D to a obtain Z*N byte buffer
** from the primary memory allocator and use that buffer
** with N lookaside slots of Z bytes each.
**
** {H14215} A successful call to
** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where
** D is an open [database connection] and Z and N are zero shall
** disable the [lookaside memory allocator] for D.
**
**
*/
SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
@@ -1159,7 +1274,10 @@ struct sqlite3_mem_methods {
**
** <dt>SQLITE_CONFIG_PAGECACHE</dt>
** <dd>This option specifies a static memory buffer that SQLite can use for
** the database page cache. There are three arguments: A pointer to the
** the database page cache with the default page cache implemenation.
** This configuration should not be used if an application-define page
** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
** There are three arguments to this option: A pointer to the
** memory, the size of each page buffer (sz), and the number of pages (N).
** The sz argument must be a power of two between 512 and 32768. The first
** argument should point to an allocation of at least sz*N bytes of memory.
@@ -1204,6 +1322,17 @@ struct sqlite3_mem_methods {
** size of each lookaside buffer slot and the second is the number of
** slots allocated to each database connection.</dd>
**
** <dt>SQLITE_CONFIG_PCACHE</dt>
** <dd>This option takes a single argument which is a pointer to
** an [sqlite3_pcache_methods] object. This object specifies the interface
** to a custom page cache implementation. SQLite makes a copy of the
** object and uses it for page cache memory allocations.</dd>
**
** <dt>SQLITE_CONFIG_GETPCACHE</dt>
** <dd>This option takes a single argument which is a pointer to an
** [sqlite3_pcache_methods] object. SQLite copies of the current
** page cache implementation into that object.</dd>
**
** </dl>
*/
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
@@ -1217,8 +1346,10 @@ struct sqlite3_mem_methods {
#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
#define SQLITE_CONFIG_CHUNKALLOC 12 /* int threshold */
/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
#define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
#define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
/*
** CAPI3REF: Configuration Options {H10170} <S20000>
@@ -1280,17 +1411,17 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff);
** is another alias for the rowid.
**
** This routine returns the rowid of the most recent
** successful INSERT into the database from the [database connection]
** in the first argument. If no successful INSERTs
** successful [INSERT] into the database from the [database connection]
** in the first argument. If no successful [INSERT]s
** have ever occurred on that database connection, zero is returned.
**
** If an INSERT occurs within a trigger, then the rowid of the inserted
** If an [INSERT] occurs within a trigger, then the rowid of the inserted
** row is returned by this routine as long as the trigger is running.
** But once the trigger terminates, the value returned by this routine
** reverts to the last value inserted before the trigger fired.
**
** An INSERT that fails due to a constraint violation is not a
** successful INSERT and does not change the value returned by this
** An [INSERT] that fails due to a constraint violation is not a
** successful [INSERT] and does not change the value returned by this
** routine. Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
** and INSERT OR ABORT make no changes to the return value of this
** routine when their insertion fails. When INSERT OR REPLACE
@@ -1299,23 +1430,24 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff);
** the constraint problem so INSERT OR REPLACE will always change
** the return value of this interface.
**
** For the purposes of this routine, an INSERT is considered to
** For the purposes of this routine, an [INSERT] is considered to
** be successful even if it is subsequently rolled back.
**
** INVARIANTS:
**
** {H12221} The [sqlite3_last_insert_rowid()] function returns the rowid
** of the most recent successful INSERT performed on the same
** {H12221} The [sqlite3_last_insert_rowid()] function shall return the rowid
** of the most recent successful [INSERT] performed on the same
** [database connection] and within the same or higher level
** trigger context, or zero if there have been no qualifying inserts.
** trigger context, or zero if there have been no qualifying
** [INSERT] statements.
**
** {H12223} The [sqlite3_last_insert_rowid()] function returns the
** {H12223} The [sqlite3_last_insert_rowid()] function shall return the
** same value when called from the same trigger context
** immediately before and after a ROLLBACK.
** immediately before and after a [ROLLBACK].
**
** ASSUMPTIONS:
**
** {A12232} If a separate thread performs a new INSERT on the same
** {A12232} If a separate thread performs a new [INSERT] on the same
** database connection while the [sqlite3_last_insert_rowid()]
** function is running and thus changes the last insert rowid,
** then the value returned by [sqlite3_last_insert_rowid()] is
@@ -1330,8 +1462,8 @@ sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
** This function returns the number of database rows that were changed
** or inserted or deleted by the most recently completed SQL statement
** on the [database connection] specified by the first parameter.
** Only changes that are directly specified by the INSERT, UPDATE,
** or DELETE statement are counted. Auxiliary changes caused by
** Only changes that are directly specified by the [INSERT], [UPDATE],
** or [DELETE] statement are counted. Auxiliary changes caused by
** triggers are not counted. Use the [sqlite3_total_changes()] function
** to find the total number of changes including changes caused by triggers.
**
@@ -1365,13 +1497,15 @@ sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
** caused by subtriggers since those have their own context.
**
** SQLite implements the command "DELETE FROM table" without a WHERE clause
** by dropping and recreating the table. (This is much faster than going
** through and deleting individual elements from the table.) Because of this
** by dropping and recreating the table. Doing so is much faster than going
** through and deleting individual elements from the table. Because of this
** optimization, the deletions in "DELETE FROM table" are not row changes and
** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()]
** functions, regardless of the number of elements that were originally
** in the table. To get an accurate count of the number of rows deleted, use
** "DELETE FROM table WHERE 1" instead.
** "DELETE FROM table WHERE 1" instead. Or recompile using the
** [SQLITE_OMIT_TRUNCATE_OPTIMIZATION] compile-time option to disable the
** optimization on all queries.
**
** INVARIANTS:
**
@@ -1413,7 +1547,9 @@ int sqlite3_changes(sqlite3*);
** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()]
** functions, regardless of the number of elements that were originally
** in the table. To get an accurate count of the number of rows deleted, use
** "DELETE FROM table WHERE 1" instead.
** "DELETE FROM table WHERE 1" instead. Or recompile using the
** [SQLITE_OMIT_TRUNCATE_OPTIMIZATION] compile-time option to disable the
** optimization on all queries.
**
** See also the [sqlite3_changes()] interface.
**
@@ -1892,7 +2028,7 @@ char *sqlite3_snprintf(int,char*,const char*, ...);
** memory might result in a segmentation fault or other severe error.
** Memory corruption, a segmentation fault, or other severe error
** might result if sqlite3_free() is called with a non-NULL pointer that
** was not obtained from sqlite3_malloc() or sqlite3_free().
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
**
** The sqlite3_realloc() interface attempts to resize a
** prior memory allocation to be at least N bytes, where N is the
@@ -2263,7 +2399,7 @@ int sqlite3_set_authorizer(
#define SQLITE_ANALYZE 28 /* Table Name NULL */
#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
#define SQLITE_FUNCTION 31 /* Function Name NULL */
#define SQLITE_FUNCTION 31 /* NULL Function Name */
#define SQLITE_COPY 0 /* No longer used */
/*
@@ -2546,7 +2682,10 @@ int sqlite3_open_v2(
** [extended result code] for the most recent failed sqlite3_* API call
** associated with a [database connection]. If a prior API call failed
** but the most recent API call succeeded, the return value from
** sqlite3_errcode() is undefined.
** sqlite3_errcode() is undefined. The sqlite3_extended_errcode()
** interface is the same except that it always returns the
** [extended result code] even when extended result codes are
** disabled.
**
** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
** text that describes the error, as either UTF-8 or UTF-16 respectively.
@@ -2555,6 +2694,16 @@ int sqlite3_open_v2(
** However, the error string might be overwritten or deallocated by
** subsequent calls to other SQLite interface functions.
**
** When the serialized [threading mode] is in use, it might be the
** case that a second error occurs on a separate thread in between
** the time of the first error and the call to these interfaces.
** When that happens, the second error will be reported since these
** interfaces always report the most recent result. To avoid
** this, each thread can obtain exclusive use of the [database connection] D
** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
** all calls to the interfaces listed here are completed.
**
** If an interface fails with SQLITE_MISUSE, that means the interface
** was invoked incorrectly by the application. In that case, the
** error code and message may or may not be set.
@@ -2565,6 +2714,10 @@ int sqlite3_open_v2(
** [result code] or [extended result code] for the most recently
** failed interface call associated with the [database connection] D.
**
** {H12802} The [sqlite3_extended_errcode(D)] interface returns the numeric
** [extended result code] for the most recently
** failed interface call associated with the [database connection] D.
**
** {H12803} The [sqlite3_errmsg(D)] and [sqlite3_errmsg16(D)]
** interfaces return English-language text that describes
** the error in the mostly recently failed interface call,
@@ -2576,15 +2729,18 @@ int sqlite3_open_v2(
** {H12808} Calls to API routines that do not return an error code
** (example: [sqlite3_data_count()]) do not
** change the error code or message returned by
** [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()].
** [sqlite3_errcode()], [sqlite3_extended_errcode()],
** [sqlite3_errmsg()], or [sqlite3_errmsg16()].
**
** {H12809} Interfaces that are not associated with a specific
** [database connection] (examples:
** [sqlite3_mprintf()] or [sqlite3_enable_shared_cache()]
** do not change the values returned by
** [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()].
** [sqlite3_errcode()], [sqlite3_extended_errcode()],
** [sqlite3_errmsg()], or [sqlite3_errmsg16()].
*/
int sqlite3_errcode(sqlite3 *db);
int sqlite3_extended_errcode(sqlite3 *db);
const char *sqlite3_errmsg(sqlite3*);
const void *sqlite3_errmsg16(sqlite3*);
@@ -2853,7 +3009,7 @@ int sqlite3_prepare16_v2(
);
/*
** CAPIREF: Retrieving Statement SQL {H13100} <H13000>
** CAPI3REF: Retrieving Statement SQL {H13100} <H13000>
**
** This interface can be used to retrieve a saved copy of the original
** SQL text used to create a [prepared statement] if that statement was
@@ -4011,14 +4167,16 @@ int sqlite3_create_function16(
** backwards compatibility with older code, these functions continue
** to be supported. However, new applications should avoid
** the use of these functions. To help encourage people to avoid
** using these functions, we are not going to tell you want they do.
** using these functions, we are not going to tell you what they do.
*/
#ifndef SQLITE_OMIT_DEPRECATED
SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
SQLITE_DEPRECATED int sqlite3_global_recover(void);
SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
#endif
/*
** CAPI3REF: Obtaining SQL Function Parameter Values {H15100} <S20200>
@@ -5651,6 +5809,7 @@ typedef struct sqlite3_blob sqlite3_blob;
**
** {H17821} If an error occurs during evaluation of [sqlite3_blob_open(D,...)]
** then subsequent calls to [sqlite3_errcode(D)],
** [sqlite3_extended_errcode()],
** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
** information appropriate for that error.
**
@@ -5764,6 +5923,7 @@ int sqlite3_blob_bytes(sqlite3_blob *);
**
** {H17868} If an error occurs during evaluation of [sqlite3_blob_read(P,...)]
** then subsequent calls to [sqlite3_errcode(D)],
** [sqlite3_extended_errcode()],
** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
** information appropriate for that error, where D is the
** [database connection] that was used to open the [BLOB handle] P.
@@ -5833,6 +5993,7 @@ int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
**
** {H17888} If an error occurs during evaluation of [sqlite3_blob_write(D,...)]
** then subsequent calls to [sqlite3_errcode(D)],
** [sqlite3_extended_errcode()],
** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
** information appropriate for that error.
*/
@@ -6130,6 +6291,17 @@ int sqlite3_mutex_notheld(sqlite3_mutex*);
#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
#define SQLITE_MUTEX_STATIC_LRU2 7 /* lru page list */
/*
** CAPI3REF: Retrieve the mutex for a database connection {H17002} <H17000>
**
** This interface returns a pointer the [sqlite3_mutex] object that
** serializes access to the [database connection] given in the argument
** when the [threading mode] is Serialized.
** If the [threading mode] is Single-thread or Multi-thread then this
** routine returns a NULL pointer.
*/
sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
/*
** CAPI3REF: Low-Level Control Of Database Files {H11300} <S30800>
**
@@ -6225,29 +6397,6 @@ int sqlite3_test_control(int op, ...);
*/
SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
/*
** CAPI3REF: Database Connection Status {H17201} <S60200>
** EXPERIMENTAL
**
** This interface is used to retrieve runtime status information
** about a single [database connection]. The first argument is the
** database connection object to be interrogated. The second argument
** is the parameter to interrogate. Currently, the only allowed value
** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
** Additional options will likely appear in future releases of SQLite.
**
** The current value of the request parameter is written into *pCur
** and the highest instantaneous value is written into *pHiwtr. If
** the resetFlg is true, then the highest instantaneous value is
** reset back down to the current value.
**
** See also: [sqlite3_status()].
*/
SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
int sqlite3_wsd_init(int N, int J);
void *sqlite3_wsd_find(void *K, int L);
/*
** CAPI3REF: Status Parameters {H17250} <H17200>
@@ -6337,7 +6486,27 @@ void *sqlite3_wsd_find(void *K, int L);
#define SQLITE_STATUS_SCRATCH_SIZE 8
/*
** CAPI3REF: Status Parameters for database connections {H17275} <H17200>
** CAPI3REF: Database Connection Status {H17500} <S60200>
** EXPERIMENTAL
**
** This interface is used to retrieve runtime status information
** about a single [database connection]. The first argument is the
** database connection object to be interrogated. The second argument
** is the parameter to interrogate. Currently, the only allowed value
** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
** Additional options will likely appear in future releases of SQLite.
**
** The current value of the requested parameter is written into *pCur
** and the highest instantaneous value is written into *pHiwtr. If
** the resetFlg is true, then the highest instantaneous value is
** reset back down to the current value.
**
** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
*/
SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
/*
** CAPI3REF: Status Parameters for database connections {H17520} <H17500>
** EXPERIMENTAL
**
** Status verbs for [sqlite3_db_status()].
@@ -6350,6 +6519,201 @@ void *sqlite3_wsd_find(void *K, int L);
*/
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
/*
** CAPI3REF: Prepared Statement Status {H17550} <S60200>
** EXPERIMENTAL
**
** Each prepared statement maintains various
** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
** of times it has performed specific operations. These counters can
** be used to monitor the performance characteristics of the prepared
** statements. For example, if the number of table steps greatly exceeds
** the number of table searches or result rows, that would tend to indicate
** that the prepared statement is using a full table scan rather than
** an index.
**
** This interface is used to retrieve and reset counter values from
** a [prepared statement]. The first argument is the prepared statement
** object to be interrogated. The second argument
** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
** to be interrogated.
** The current value of the requested counter is returned.
** If the resetFlg is true, then the counter is reset to zero after this
** interface call returns.
**
** See also: [sqlite3_status()] and [sqlite3_db_status()].
*/
SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
/*
** CAPI3REF: Status Parameters for prepared statements {H17570} <H17550>
** EXPERIMENTAL
**
** These preprocessor macros define integer codes that name counter
** values associated with the [sqlite3_stmt_status()] interface.
** The meanings of the various counters are as follows:
**
** <dl>
** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
** <dd>This is the number of times that SQLite has stepped forward in
** a table as part of a full table scan. Large numbers for this counter
** may indicate opportunities for performance improvement through
** careful use of indices.</dd>
**
** <dt>SQLITE_STMTSTATUS_SORT</dt>
** <dd>This is the number of sort operations that have occurred.
** A non-zero value in this counter may indicate an opportunity to
** improvement performance through careful use of indices.</dd>
**
** </dl>
*/
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
#define SQLITE_STMTSTATUS_SORT 2
/*
** CAPI3REF: Custom Page Cache Object
** EXPERIMENTAL
**
** The sqlite3_pcache type is opaque. It is implemented by
** the pluggable module. The SQLite core has no knowledge of
** its size or internal structure and never deals with the
** sqlite3_pcache object except by holding and passing pointers
** to the object.
**
** See [sqlite3_pcache_methods] for additional information.
*/
typedef struct sqlite3_pcache sqlite3_pcache;
/*
** CAPI3REF: Application Defined Page Cache.
** EXPERIMENTAL
**
** The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
** register an alternative page cache implementation by passing in an
** instance of the sqlite3_pcache_methods structure. The majority of the
** heap memory used by sqlite is used by the page cache to cache data read
** from, or ready to be written to, the database file. By implementing a
** custom page cache using this API, an application can control more
** precisely the amount of memory consumed by sqlite, the way in which
** said memory is allocated and released, and the policies used to
** determine exactly which parts of a database file are cached and for
** how long.
**
** The contents of the structure are copied to an internal buffer by sqlite
** within the call to [sqlite3_config].
**
** The xInit() method is called once for each call to [sqlite3_initialize()]
** (usually only once during the lifetime of the process). It is passed
** a copy of the sqlite3_pcache_methods.pArg value. It can be used to set
** up global structures and mutexes required by the custom page cache
** implementation. The xShutdown() method is called from within
** [sqlite3_shutdown()], if the application invokes this API. It can be used
** to clean up any outstanding resources before process shutdown, if required.
**
** The xCreate() method is used to construct a new cache instance. The
** first parameter, szPage, is the size in bytes of the pages that must
** be allocated by the cache. szPage will not be a power of two. The
** second argument, bPurgeable, is true if the cache being created will
** be used to cache database pages read from a file stored on disk, or
** false if it is used for an in-memory database. The cache implementation
** does not have to do anything special based on the value of bPurgeable,
** it is purely advisory.
**
** The xCachesize() method may be called at any time by SQLite to set the
** suggested maximum cache-size (number of pages stored by) the cache
** instance passed as the first argument. This is the value configured using
** the SQLite "[PRAGMA cache_size]" command. As with the bPurgeable parameter,
** the implementation is not required to do anything special with this
** value, it is advisory only.
**
** The xPagecount() method should return the number of pages currently
** stored in the cache supplied as an argument.
**
** The xFetch() method is used to fetch a page and return a pointer to it.
** A 'page', in this context, is a buffer of szPage bytes aligned at an
** 8-byte boundary. The page to be fetched is determined by the key. The
** mimimum key value is 1. After it has been retrieved using xFetch, the page
** is considered to be pinned.
**
** If the requested page is already in the page cache, then a pointer to
** the cached buffer should be returned with its contents intact. If the
** page is not already in the cache, then the expected behaviour of the
** cache is determined by the value of the createFlag parameter passed
** to xFetch, according to the following table:
**
** <table border=1 width=85% align=center>
** <tr><th>createFlag<th>Expected Behaviour
** <tr><td>0<td>NULL should be returned. No new cache entry is created.
** <tr><td>1<td>If createFlag is set to 1, this indicates that
** SQLite is holding pinned pages that can be unpinned
** by writing their contents to the database file (a
** relatively expensive operation). In this situation the
** cache implementation has two choices: it can return NULL,
** in which case SQLite will attempt to unpin one or more
** pages before re-requesting the same page, or it can
** allocate a new page and return a pointer to it. If a new
** page is allocated, then it must be completely zeroed before
** it is returned.
** <tr><td>2<td>If createFlag is set to 2, then SQLite is not holding any
** pinned pages associated with the specific cache passed
** as the first argument to xFetch() that can be unpinned. The
** cache implementation should attempt to allocate a new
** cache entry and return a pointer to it. Again, the new
** page should be zeroed before it is returned. If the xFetch()
** method returns NULL when createFlag==2, SQLite assumes that
** a memory allocation failed and returns SQLITE_NOMEM to the
** user.
** </table>
**
** xUnpin() is called by SQLite with a pointer to a currently pinned page
** as its second argument. If the third parameter, discard, is non-zero,
** then the page should be evicted from the cache. In this case SQLite
** assumes that the next time the page is retrieved from the cache using
** the xFetch() method, it will be zeroed. If the discard parameter is
** zero, then the page is considered to be unpinned. The cache implementation
** may choose to reclaim (free or recycle) unpinned pages at any time.
** SQLite assumes that next time the page is retrieved from the cache
** it will either be zeroed, or contain the same data that it did when it
** was unpinned.
**
** The cache is not required to perform any reference counting. A single
** call to xUnpin() unpins the page regardless of the number of prior calls
** to xFetch().
**
** The xRekey() method is used to change the key value associated with the
** page passed as the second argument from oldKey to newKey. If the cache
** previously contains an entry associated with newKey, it should be
** discarded. Any prior cache entry associated with newKey is guaranteed not
** to be pinned.
**
** When SQLite calls the xTruncate() method, the cache must discard all
** existing cache entries with page numbers (keys) greater than or equal
** to the value of the iLimit parameter passed to xTruncate(). If any
** of these pages are pinned, they are implicitly unpinned, meaning that
** they can be safely discarded.
**
** The xDestroy() method is used to delete a cache allocated by xCreate().
** All resources associated with the specified cache should be freed. After
** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
** handle invalid, and will not use it with any other sqlite3_pcache_methods
** functions.
*/
typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
struct sqlite3_pcache_methods {
void *pArg;
int (*xInit)(void*);
void (*xShutdown)(void*);
sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
void (*xCachesize)(sqlite3_pcache*, int nCachesize);
int (*xPagecount)(sqlite3_pcache*);
void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
void (*xUnpin)(sqlite3_pcache*, void*, int discard);
void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
void (*xDestroy)(sqlite3_pcache*);
};
/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
+9 -1
View File
@@ -15,7 +15,7 @@
** as extensions by SQLite should #include this file instead of
** sqlite3.h.
**
** @(#) $Id: sqlite3ext.h,v 1.24 2008/06/30 15:09:29 danielk1977 Exp $
** @(#) $Id: sqlite3ext.h,v 1.25 2008/10/12 00:27:54 shane Exp $
*/
#ifndef _SQLITE3EXT_H_
#define _SQLITE3EXT_H_
@@ -208,7 +208,9 @@ struct sqlite3_api_routines {
*/
#ifndef SQLITE_CORE
#define sqlite3_aggregate_context sqlite3_api->aggregate_context
#ifndef SQLITE_OMIT_DEPRECATED
#define sqlite3_aggregate_count sqlite3_api->aggregate_count
#endif
#define sqlite3_bind_blob sqlite3_api->bind_blob
#define sqlite3_bind_double sqlite3_api->bind_double
#define sqlite3_bind_int sqlite3_api->bind_int
@@ -264,14 +266,18 @@ struct sqlite3_api_routines {
#define sqlite3_errmsg sqlite3_api->errmsg
#define sqlite3_errmsg16 sqlite3_api->errmsg16
#define sqlite3_exec sqlite3_api->exec
#ifndef SQLITE_OMIT_DEPRECATED
#define sqlite3_expired sqlite3_api->expired
#endif
#define sqlite3_finalize sqlite3_api->finalize
#define sqlite3_free sqlite3_api->free
#define sqlite3_free_table sqlite3_api->free_table
#define sqlite3_get_autocommit sqlite3_api->get_autocommit
#define sqlite3_get_auxdata sqlite3_api->get_auxdata
#define sqlite3_get_table sqlite3_api->get_table
#ifndef SQLITE_OMIT_DEPRECATED
#define sqlite3_global_recover sqlite3_api->global_recover
#endif
#define sqlite3_interrupt sqlite3_api->interruptx
#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid
#define sqlite3_libversion sqlite3_api->libversion
@@ -309,7 +315,9 @@ struct sqlite3_api_routines {
#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup
#define sqlite3_total_changes sqlite3_api->total_changes
#define sqlite3_trace sqlite3_api->trace
#ifndef SQLITE_OMIT_DEPRECATED
#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings
#endif
#define sqlite3_update_hook sqlite3_api->update_hook
#define sqlite3_user_data sqlite3_api->user_data
#define sqlite3_value_blob sqlite3_api->value_blob
+78 -30
View File
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.772 2008/09/12 16:03:48 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.798 2008/11/19 16:52:44 danielk1977 Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@@ -387,7 +387,8 @@ const int sqlite3one;
#else
extern const int sqlite3one;
#endif
#if defined(i386) || defined(__i386__) || defined(_M_IX86)
#if defined(i386) || defined(__i386__) || defined(_M_IX86)\
|| defined(__x86_64) || defined(__x86_64__)
# define SQLITE_BIGENDIAN 0
# define SQLITE_LITTLEENDIAN 1
# define SQLITE_UTF16NATIVE SQLITE_UTF16LE
@@ -443,7 +444,7 @@ struct BusyHandler {
** A convenience macro that returns the number of elements in
** an array.
*/
#define ArraySize(X) (sizeof(X)/sizeof(X[0]))
#define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0])))
/*
** The following value as a destructor means to use sqlite3DbFree().
@@ -462,19 +463,40 @@ struct BusyHandler {
** buffer that holds real variable. The constant is also the initializer
** for the run-time allocated buffer.
**
** In the usually case where WSD is supported, the SQLITE_WSD and GLOBAL
** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
** macros become no-ops and have zero performance impact.
*/
#ifdef SQLITE_OMIT_WSD
#define SQLITE_WSD const
#define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))
#define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
int sqlite3_wsd_init(int N, int J);
void *sqlite3_wsd_find(void *K, int L);
#else
#define SQLITE_WSD
#define GLOBAL(t,v) v
#define sqlite3GlobalConfig sqlite3Config
#endif
/*
** The following macros are used to suppress compiler warnings and to
** make it clear to human readers when a function parameter is deliberately
** left unused within the body of a function. This usually happens when
** a function is called via a function pointer. For example the
** implementation of an SQL aggregate step callback may not use the
** parameter indicating the number of arguments passed to the aggregate,
** if it knows that this is enforced elsewhere.
**
** When a function parameter is not used at all within the body of a function,
** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
** However, these macros may also be used to suppress warnings related to
** parameters that may or may not be used depending on compilation options.
** For example those parameters only used in assert() statements. In these
** cases the parameters are named as per the usual conventions.
*/
#define UNUSED_PARAMETER(x) (void)(x)
#define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y)
/*
** Forward references to structures
*/
@@ -682,7 +704,7 @@ struct sqlite3 {
CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
i64 lastRowid; /* ROWID of most recent insert (see above) */
i64 priorNewRowid; /* Last randomly generated ROWID */
int magic; /* Magic number for detect library misuse */
u32 magic; /* Magic number for detect library misuse */
int nChange; /* Value returned by sqlite3_changes() */
int nTotalChange; /* Value returned by sqlite3_total_changes() */
sqlite3_mutex *mutex; /* Connection mutex */
@@ -696,6 +718,7 @@ struct sqlite3 {
void **aExtension; /* Array of shared libraray handles */
struct Vdbe *pVdbe; /* List of active virtual machines */
int activeVdbeCnt; /* Number of vdbes currently executing */
int writeVdbeCnt; /* Number of active VDBEs that are writing */
void (*xTrace)(void*,const char*); /* Trace function */
void *pTraceArg; /* Argument to the trace function */
void (*xProfile)(void*,const char*,u64); /* Profiling function */
@@ -798,9 +821,8 @@ struct sqlite3 {
** points to a linked list of these structures.
*/
struct FuncDef {
i8 nArg; /* Number of arguments. -1 means unlimited */
i16 nArg; /* Number of arguments. -1 means unlimited */
u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */
u8 flags; /* Some combination of SQLITE_FUNC_* */
void *pUserData; /* User data parameter */
FuncDef *pNext; /* Next function with same name */
@@ -814,9 +836,10 @@ struct FuncDef {
/*
** Possible values for FuncDef.flags
*/
#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
#define SQLITE_FUNC_EPHEM 0x04 /* Ephermeral. Delete with VDBE */
#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
#define SQLITE_FUNC_EPHEM 0x04 /* Ephermeral. Delete with VDBE */
#define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */
/*
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
@@ -844,11 +867,13 @@ struct FuncDef {
** parameter.
*/
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
{nArg, SQLITE_UTF8, bNC, 0, SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName}
{nArg, SQLITE_UTF8, bNC*8, SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0}
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
{nArg, SQLITE_UTF8, bNC*8, pArg, 0, xFunc, 0, 0, #zName, 0}
#define LIKEFUNC(zName, nArg, arg, flags) \
{nArg, SQLITE_UTF8, 0, flags, (void *)arg, 0, likeFunc, 0, 0, #zName}
{nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0}
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
{nArg, SQLITE_UTF8, nc, 0, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal, #zName}
{nArg, SQLITE_UTF8, nc*8, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0}
/*
@@ -1417,6 +1442,11 @@ struct IdList {
*/
typedef u64 Bitmask;
/*
** The number of bits in a Bitmask. "BMS" means "BitMask Size".
*/
#define BMS ((int)(sizeof(Bitmask)*8))
/*
** The following structure describes the FROM clause of a SELECT statement.
** Each table or subquery in the FROM clause is a separate element of
@@ -1448,6 +1478,9 @@ struct SrcList {
Expr *pOn; /* The ON clause of a join */
IdList *pUsing; /* The USING clause of a join */
Bitmask colUsed; /* Bit N (1<<N) set if column N or pTab is used */
u8 notIndexed; /* True if there is a NOT INDEXED clause */
char *zIndex; /* Identifier from "INDEXED BY <zIndex>" clause */
Index *pIndex; /* Index structure corresponding to zIndex, if any */
} a[1]; /* One entry for each identifier on the list */
};
@@ -1493,7 +1526,7 @@ struct WhereLevel {
int nxt; /* Jump here to start the next IN combination */
int cont; /* Jump here to continue with the next loop cycle */
int top; /* First instruction of interior of the loop */
int op, p1, p2; /* Opcode used to terminate the loop */
int op, p1, p2, p5; /* Opcode used to terminate the loop */
int nEq; /* Number of == or IN constraints on this loop */
int nIn; /* Number of IN operators constraining this loop */
struct InLoop {
@@ -1949,6 +1982,7 @@ struct Sqlite3Config {
int nLookaside; /* Default lookaside buffer count */
sqlite3_mem_methods m; /* Low-level memory allocation interface */
sqlite3_mutex_methods mutex; /* Low-level mutex interface */
sqlite3_pcache_methods pcache; /* Low-level page-cache interface */
void *pHeap; /* Heap storage space */
int nHeap; /* Size of pHeap[] */
int mnReq, mxReq; /* Min and max heap requests sizes */
@@ -1963,7 +1997,6 @@ struct Sqlite3Config {
int isMallocInit; /* True after malloc is initialized */
sqlite3_mutex *pInitMutex; /* Mutex used by sqlite3_initialize() */
int nRefInitMutex; /* Number of users of pInitMutex */
int nSmall; /* alloc size threshold used by mem6.c */
int mxParserStack; /* maximum depth of the parser stack */
int sharedCacheEnabled; /* true if shared-cache mode enabled */
};
@@ -2046,14 +2079,18 @@ void sqlite3ScratchFree(void*);
void *sqlite3PageMalloc(int);
void sqlite3PageFree(void*);
void sqlite3MemSetDefault(void);
const sqlite3_mem_methods *sqlite3MemGetDefault(void);
const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
const sqlite3_mem_methods *sqlite3MemGetMemsys6(void);
void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
int sqlite3MemoryAlarm(void (*)(void*, sqlite3_int64, int), void*, sqlite3_int64);
#ifndef SQLITE_MUTEX_NOOP
#ifdef SQLITE_ENABLE_MEMSYS3
const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
#endif
#ifdef SQLITE_ENABLE_MEMSYS5
const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
#endif
#ifndef SQLITE_MUTEX_OMIT
sqlite3_mutex_methods *sqlite3DefaultMutex(void);
sqlite3_mutex *sqlite3MutexAlloc(int);
int sqlite3MutexInit(void);
@@ -2095,6 +2132,7 @@ Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
void sqlite3ExprSpan(Expr*,Token*,Token*);
Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
void sqlite3ExprAssignVarNumber(Parse*, Expr*);
void sqlite3ExprClear(sqlite3*, Expr*);
void sqlite3ExprDelete(sqlite3*, Expr*);
ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*,Token*);
void sqlite3ExprListDelete(sqlite3*, ExprList*);
@@ -2137,9 +2175,12 @@ void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*);
IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
int sqlite3IdListIndex(IdList*,const char*);
SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*, Token*,
Select*, Expr*, IdList*);
SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
Token*, Select*, Expr*, IdList*);
void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
void sqlite3SrcListShiftJoinType(SrcList*);
void sqlite3SrcListAssignCursors(Parse*, SrcList*);
void sqlite3IdListDelete(sqlite3*, IdList*);
@@ -2154,6 +2195,9 @@ void sqlite3SelectDelete(sqlite3*, Select*);
Table *sqlite3SrcListLookup(Parse*, SrcList*);
int sqlite3IsReadOnly(Parse*, Table*, int);
void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *);
#endif
void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u8);
@@ -2204,7 +2248,7 @@ void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int*);
int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int);
void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int,
int*,int,int,int,int);
void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*,int,int,int,int);
void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int);
int sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
void sqlite3BeginWriteOperation(Parse*, int, int);
Expr *sqlite3ExprDup(sqlite3*,Expr*);
@@ -2218,7 +2262,6 @@ FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
void sqlite3RegisterBuiltinFunctions(sqlite3*);
void sqlite3RegisterDateTimeFunctions(void);
void sqlite3RegisterGlobalFunctions(void);
int sqlite3GetBuiltinFunction(const char *, int, FuncDef **);
#ifdef SQLITE_DEBUG
int sqlite3SafetyOn(sqlite3*);
int sqlite3SafetyOff(sqlite3*);
@@ -2240,7 +2283,7 @@ void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
void sqlite3DropTrigger(Parse*, SrcList*, int);
void sqlite3DropTriggerPtr(Parse*, Trigger*);
int sqlite3TriggersExist(Parse*, Table*, int, ExprList*);
int sqlite3TriggersExist(Table*, int, ExprList*);
int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int,
int, int, u32*, u32*);
void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
@@ -2253,7 +2296,7 @@ void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
void sqlite3DeleteTrigger(sqlite3*, Trigger*);
void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
#else
# define sqlite3TriggersExist(A,B,C,D,E,F) 0
# define sqlite3TriggersExist(B,C,D,E,F) 0
# define sqlite3DeleteTrigger(A,B)
# define sqlite3DropTriggerPtr(A,B)
# define sqlite3UnlinkAndDeleteTrigger(A,B,C)
@@ -2321,8 +2364,8 @@ int sqlite3VarintLen(u64 v);
** x = putVarint32( A, B );
**
*/
#define getVarint32(A,B) ((*(A)<(unsigned char)0x80) ? ((B) = (u32)*(A)),1 : sqlite3GetVarint32((A), &(B)))
#define putVarint32(A,B) (((B)<(u32)0x80) ? (*(A) = (unsigned char)(B)),1 : sqlite3PutVarint32((A), (B)))
#define getVarint32(A,B) ((*(A)<(unsigned char)0x80) ? ((B) = (u32)*(A)),1 : sqlite3GetVarint32((A), (u32 *)&(B)))
#define putVarint32(A,B) (((u32)(B)<(u32)0x80) ? (*(A) = (unsigned char)(B)),1 : sqlite3PutVarint32((A), (B)))
#define getVarint sqlite3GetVarint
#define putVarint sqlite3PutVarint
@@ -2367,7 +2410,7 @@ void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
int sqlite3GetToken(const unsigned char *, int *);
void sqlite3NestedParse(Parse*, const char*, ...);
void sqlite3ExpirePreparedStatements(sqlite3*);
void sqlite3CodeSubselect(Parse *, Expr *, int);
void sqlite3CodeSubselect(Parse *, Expr *, int, int);
void sqlite3SelectPrep(Parse*, Select*, NameContext*);
int sqlite3ResolveExprNames(NameContext*, Expr*);
void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
@@ -2384,7 +2427,6 @@ int sqlite3AnalysisLoad(sqlite3*,int iDB);
void sqlite3DefaultRowEst(Index*);
void sqlite3RegisterLikeFunctions(sqlite3*, int);
int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
void sqlite3AttachFunctions(sqlite3 *);
void sqlite3MinimumFileFormat(Parse*, int, int);
void sqlite3SchemaFree(void *);
Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
@@ -2434,11 +2476,13 @@ int sqlite3AutoLoadExtensions(sqlite3*);
# define sqlite3VtabSync(X,Y) SQLITE_OK
# define sqlite3VtabRollback(X)
# define sqlite3VtabCommit(X)
# define sqlite3VtabInSync(db) 0
#else
void sqlite3VtabClear(Table*);
int sqlite3VtabSync(sqlite3 *db, char **);
int sqlite3VtabRollback(sqlite3 *db);
int sqlite3VtabCommit(sqlite3 *db);
# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
#endif
void sqlite3VtabMakeWritable(Parse*,Table*);
void sqlite3VtabLock(sqlite3_vtab*);
@@ -2491,6 +2535,10 @@ int sqlite3FindInIndex(Parse *, Expr *, int*);
#define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile)
#endif
void sqlite3MemJournalOpen(sqlite3_file *);
int sqlite3MemJournalSize();
int sqlite3IsMemJournal(sqlite3_file *);
#if SQLITE_MAX_EXPR_DEPTH>0
void sqlite3ExprSetHeight(Parse *pParse, Expr *p);
int sqlite3SelectExprHeight(Select *);
+57 -11
View File
@@ -12,7 +12,7 @@
** A TCL Interface to SQLite. Append this file to sqlite3.c and
** compile the whole thing to build a TCL-enabled version of SQLite.
**
** $Id: tclsqlite.c,v 1.224 2008/09/09 12:31:34 drh Exp $
** $Id: tclsqlite.c,v 1.228 2008/10/09 14:45:26 drh Exp $
*/
#include "tcl.h"
#include <errno.h>
@@ -117,6 +117,7 @@ struct SqliteDb {
int maxStmt; /* The next maximum number of stmtList */
int nStmt; /* Number of statements in stmtList */
IncrblobChannel *pIncrblob;/* Linked list of open incrblob channels */
int nStep, nSort; /* Statistics for most recent operation */
};
struct IncrblobChannel {
@@ -977,9 +978,9 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
"incrblob", "interrupt", "last_insert_rowid",
"nullvalue", "onecolumn", "profile",
"progress", "rekey", "rollback_hook",
"timeout", "total_changes", "trace",
"transaction", "update_hook", "version",
0
"status", "timeout", "total_changes",
"trace", "transaction", "update_hook",
"version", 0
};
enum DB_enum {
DB_AUTHORIZER, DB_BUSY, DB_CACHE,
@@ -990,8 +991,9 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
DB_INCRBLOB, DB_INTERRUPT, DB_LAST_INSERT_ROWID,
DB_NULLVALUE, DB_ONECOLUMN, DB_PROFILE,
DB_PROGRESS, DB_REKEY, DB_ROLLBACK_HOOK,
DB_TIMEOUT, DB_TOTAL_CHANGES, DB_TRACE,
DB_TRANSACTION, DB_UPDATE_HOOK, DB_VERSION
DB_STATUS, DB_TIMEOUT, DB_TOTAL_CHANGES,
DB_TRACE, DB_TRANSACTION, DB_UPDATE_HOOK,
DB_VERSION
};
/* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
@@ -1343,11 +1345,11 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
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 ) {
if(strcmp(zConflict, "rollback") != 0 &&
strcmp(zConflict, "abort" ) != 0 &&
strcmp(zConflict, "fail" ) != 0 &&
strcmp(zConflict, "ignore" ) != 0 &&
strcmp(zConflict, "replace" ) != 0 ) {
Tcl_AppendResult(interp, "Error: \"", zConflict,
"\", conflict-algorithm must be one of: rollback, "
"abort, fail, ignore, or replace", 0);
@@ -1760,6 +1762,10 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
}
if( pScript ){
pDb->nStep = sqlite3_stmt_status(pStmt,
SQLITE_STMTSTATUS_FULLSCAN_STEP, 0);
pDb->nSort = sqlite3_stmt_status(pStmt,
SQLITE_STMTSTATUS_SORT, 0);
rc = Tcl_EvalObjEx(interp, pScript, 0);
if( rc==TCL_CONTINUE ){
rc = TCL_OK;
@@ -1798,6 +1804,10 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
** flush the statement cache and try the statement again.
*/
rc2 = sqlite3_reset(pStmt);
pDb->nStep = sqlite3_stmt_status(pStmt,
SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
pDb->nSort = sqlite3_stmt_status(pStmt,
SQLITE_STMTSTATUS_SORT, 1);
if( SQLITE_OK!=rc2 ){
/* If a run-time error occurs, report the error and stop reading
** the SQL
@@ -2126,6 +2136,33 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
break;
}
/*
** $db status (step|sort)
**
** Display SQLITE_STMTSTATUS_FULLSCAN_STEP or
** SQLITE_STMTSTATUS_SORT for the most recent eval.
*/
case DB_STATUS: {
int v;
const char *zOp;
if( objc!=3 ){
Tcl_WrongNumArgs(interp, 2, objv, "(step|sort)");
return TCL_ERROR;
}
zOp = Tcl_GetString(objv[2]);
if( strcmp(zOp, "step")==0 ){
v = pDb->nStep;
}else if( strcmp(zOp, "sort")==0 ){
v = pDb->nSort;
}else{
Tcl_AppendResult(interp, "bad argument: should be step or sort",
(char*)0);
return TCL_ERROR;
}
Tcl_SetObjResult(interp, Tcl_NewIntObj(v));
break;
}
/*
** $db timeout MILLESECONDS
**
@@ -2488,12 +2525,21 @@ EXTERN int Sqlite3_Init(Tcl_Interp *interp){
EXTERN int Tclsqlite3_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
EXTERN int Sqlite3_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
EXTERN int Tclsqlite3_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
EXTERN int Sqlite3_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; }
EXTERN int Tclsqlite3_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; }
EXTERN int Sqlite3_SafeUnload(Tcl_Interp *interp, int flags){ return TCL_OK; }
EXTERN int Tclsqlite3_SafeUnload(Tcl_Interp *interp, int flags){ return TCL_OK;}
#ifndef SQLITE_3_SUFFIX_ONLY
EXTERN int Sqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
EXTERN int Tclsqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
EXTERN int Sqlite_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
EXTERN int Tclsqlite_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
EXTERN int Sqlite_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; }
EXTERN int Tclsqlite_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; }
EXTERN int Sqlite_SafeUnload(Tcl_Interp *interp, int flags){ return TCL_OK; }
EXTERN int Tclsqlite_SafeUnload(Tcl_Interp *interp, int flags){ return TCL_OK;}
#endif
#ifdef TCLSH
+142 -45
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.325 2008/09/11 10:29:16 danielk1977 Exp $
** $Id: test1.c,v 1.329 2008/10/30 15:03:16 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -117,35 +117,53 @@ int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
const char *sqlite3TestErrorName(int rc){
const char *zName = 0;
switch( rc & 0xff ){
case SQLITE_OK: zName = "SQLITE_OK"; break;
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break;
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
default: zName = "SQLITE_Unknown"; break;
switch( rc ){
case SQLITE_OK: zName = "SQLITE_OK"; break;
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break;
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
case SQLITE_IOERR_FSYNC: zName = "SQLITE_IOERR_FSYNC"; break;
case SQLITE_IOERR_DIR_FSYNC: zName = "SQLITE_IOERR_DIR_FSYNC"; break;
case SQLITE_IOERR_TRUNCATE: zName = "SQLITE_IOERR_TRUNCATE"; break;
case SQLITE_IOERR_FSTAT: zName = "SQLITE_IOERR_FSTAT"; break;
case SQLITE_IOERR_UNLOCK: zName = "SQLITE_IOERR_UNLOCK"; break;
case SQLITE_IOERR_RDLOCK: zName = "SQLITE_IOERR_RDLOCK"; break;
case SQLITE_IOERR_DELETE: zName = "SQLITE_IOERR_DELETE"; break;
case SQLITE_IOERR_BLOCKED: zName = "SQLITE_IOERR_BLOCKED"; break;
case SQLITE_IOERR_NOMEM: zName = "SQLITE_IOERR_NOMEM"; break;
case SQLITE_IOERR_ACCESS: zName = "SQLITE_IOERR_ACCESS"; break;
case SQLITE_IOERR_CHECKRESERVEDLOCK:
zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
case SQLITE_IOERR_LOCK: zName = "SQLITE_IOERR_LOCK"; break;
default: zName = "SQLITE_Unknown"; break;
}
return zName;
}
@@ -1039,9 +1057,12 @@ static void legacyCountStep(
){
/* no-op */
}
#ifndef SQLITE_OMIT_DEPRECATED
static void legacyCountFinalize(sqlite3_context *context){
sqlite3_result_int(context, sqlite3_aggregate_count(context));
}
#endif
/*
** Usage: sqlite3_create_aggregate DB
@@ -1082,11 +1103,13 @@ static int test_create_aggregate(
rc = sqlite3_create_function(db, "x_count", 1, SQLITE_UTF8, 0, 0,
t1CountStep,t1CountFinalize);
}
#ifndef SQLITE_OMIT_DEPRECATED
if( rc==SQLITE_OK ){
rc = sqlite3_create_function(db, "legacy_count", 0, SQLITE_ANY, 0, 0,
legacyCountStep, legacyCountFinalize
);
}
#endif
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
return TCL_OK;
@@ -1559,7 +1582,7 @@ static int test_blob_read(
}
/*
** sqlite3_blob_write CHANNEL OFFSET DATA
** sqlite3_blob_write CHANNEL OFFSET DATA ?NDATA?
**
** This command is used to test the sqlite3_blob_write() in ways that
** the Tcl channel interface does not. The first argument should
@@ -1588,16 +1611,13 @@ static int test_blob_write(
unsigned char *zBuf;
int nBuf;
if( objc!=4 ){
Tcl_WrongNumArgs(interp, 1, objv, "CHANNEL OFFSET DATA");
if( objc!=4 && objc!=5 ){
Tcl_WrongNumArgs(interp, 1, objv, "CHANNEL OFFSET DATA ?NDATA?");
return TCL_ERROR;
}
channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), &notUsed);
if( !channel
|| TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &iOffset)
|| iOffset<0
){
if( !channel || TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &iOffset) ){
return TCL_ERROR;
}
@@ -1605,6 +1625,9 @@ static int test_blob_write(
pBlob = *((sqlite3_blob **)instanceData);
zBuf = Tcl_GetByteArrayFromObj(objv[3], &nBuf);
if( objc==5 && Tcl_GetIntFromObj(interp, objv[4], &nBuf) ){
return TCL_ERROR;
}
rc = sqlite3_blob_write(pBlob, zBuf, nBuf, iOffset);
if( rc!=SQLITE_OK ){
Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
@@ -1912,6 +1935,50 @@ static int test_finalize(
return TCL_OK;
}
/*
** Usage: sqlite3_stmt_status STMT CODE RESETFLAG
**
** Get the value of a status counter from a statement.
*/
static int test_stmt_status(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
int iValue;
int i, op, resetFlag;
const char *zOpName;
sqlite3_stmt *pStmt;
static const struct {
const char *zName;
int op;
} aOp[] = {
{ "SQLITE_STMTSTATUS_FULLSCAN_STEP", SQLITE_STMTSTATUS_FULLSCAN_STEP },
{ "SQLITE_STMTSTATUS_SORT", SQLITE_STMTSTATUS_SORT },
};
if( objc!=4 ){
Tcl_WrongNumArgs(interp, 1, objv, "STMT PARAMETER RESETFLAG");
return TCL_ERROR;
}
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
zOpName = Tcl_GetString(objv[2]);
for(i=0; i<ArraySize(aOp); i++){
if( strcmp(aOp[i].zName, zOpName)==0 ){
op = aOp[i].op;
break;
}
}
if( i>=ArraySize(aOp) ){
if( Tcl_GetIntFromObj(interp, objv[2], &op) ) return TCL_ERROR;
}
if( Tcl_GetBooleanFromObj(interp, objv[3], &resetFlag) ) return TCL_ERROR;
iValue = sqlite3_stmt_status(pStmt, op, resetFlag);
Tcl_SetObjResult(interp, Tcl_NewIntObj(iValue));
return TCL_OK;
}
/*
** Usage: sqlite3_next_stmt DB STMT
**
@@ -1990,6 +2057,7 @@ static int test_expired(
int objc,
Tcl_Obj *CONST objv[]
){
#ifndef SQLITE_OMIT_DEPRECATED
sqlite3_stmt *pStmt;
if( objc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"",
@@ -1998,6 +2066,7 @@ static int test_expired(
}
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(sqlite3_expired(pStmt)));
#endif
return TCL_OK;
}
@@ -2012,6 +2081,7 @@ static int test_transfer_bind(
int objc,
Tcl_Obj *CONST objv[]
){
#ifndef SQLITE_OMIT_DEPRECATED
sqlite3_stmt *pStmt1, *pStmt2;
if( objc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"",
@@ -2022,6 +2092,7 @@ static int test_transfer_bind(
if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt2)) return TCL_ERROR;
Tcl_SetObjResult(interp,
Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1,pStmt2)));
#endif
return TCL_OK;
}
@@ -3011,6 +3082,33 @@ static int test_sleep(
return TCL_OK;
}
/*
** Usage: sqlite3_extended_errcode DB
**
** Return the string representation of the most recent sqlite3_* API
** error code. e.g. "SQLITE_ERROR".
*/
static int test_ex_errcode(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
sqlite3 *db;
int rc;
if( objc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"",
Tcl_GetString(objv[0]), " DB", 0);
return TCL_ERROR;
}
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
rc = sqlite3_extended_errcode(db);
Tcl_AppendResult(interp, (char *)t1ErrorName(rc), 0);
return TCL_OK;
}
/*
** Usage: sqlite3_errcode DB
**
@@ -3025,7 +3123,6 @@ static int test_errcode(
){
sqlite3 *db;
int rc;
char zBuf[30];
if( objc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"",
@@ -3034,12 +3131,7 @@ static int test_errcode(
}
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
rc = sqlite3_errcode(db);
if( (rc&0xff)==rc ){
zBuf[0] = 0;
}else{
sprintf(zBuf,"+%d", rc>>8);
}
Tcl_AppendResult(interp, (char *)t1ErrorName(rc), zBuf, 0);
Tcl_AppendResult(interp, (char *)t1ErrorName(rc), 0);
return TCL_OK;
}
@@ -3712,6 +3804,7 @@ static int test_global_recover(
Tcl_Obj *CONST objv[]
){
#ifndef SQLITE_OMIT_GLOBALRECOVER
#ifndef SQLITE_OMIT_DEPRECATED
int rc;
if( objc!=1 ){
Tcl_WrongNumArgs(interp, 1, objv, "");
@@ -3719,6 +3812,7 @@ static int test_global_recover(
}
rc = sqlite3_global_recover();
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
#endif
#endif
return TCL_OK;
}
@@ -4095,11 +4189,12 @@ static int test_thread_cleanup(
int objc,
Tcl_Obj *CONST objv[]
){
#ifndef SQLITE_OMIT_DEPRECATED
sqlite3_thread_cleanup();
#endif
return TCL_OK;
}
/*
** Usage: sqlite3_pager_refcounts DB
**
@@ -4611,6 +4706,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite3_clear_bindings", test_clear_bindings, 0},
{ "sqlite3_sleep", test_sleep, 0},
{ "sqlite3_errcode", test_errcode ,0 },
{ "sqlite3_extended_errcode", test_ex_errcode ,0 },
{ "sqlite3_errmsg", test_errmsg ,0 },
{ "sqlite3_errmsg16", test_errmsg16 ,0 },
{ "sqlite3_open", test_open ,0 },
@@ -4623,6 +4719,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite3_prepare_tkt3134", test_prepare_tkt3134, 0},
{ "sqlite3_prepare16_v2", test_prepare16_v2 ,0 },
{ "sqlite3_finalize", test_finalize ,0 },
{ "sqlite3_stmt_status", test_stmt_status ,0 },
{ "sqlite3_reset", test_reset ,0 },
{ "sqlite3_expired", test_expired ,0 },
{ "sqlite3_transfer_bindings", test_transfer_bind ,0 },
+2 -2
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.61 2008/08/26 18:05:48 danielk1977 Exp $
** $Id: test2.c,v 1.62 2008/09/29 11:49:48 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -78,7 +78,7 @@ static int pager_open(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR;
rc = sqlite3PagerOpen(sqlite3_vfs_find(0), &pPager, argv[1], 0, 0, 0,
rc = sqlite3PagerOpen(sqlite3_vfs_find(0), &pPager, argv[1], 0, 0,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
+2 -2
View File
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test3.c,v 1.101 2008/08/13 19:11:48 drh Exp $
** $Id: test3.c,v 1.102 2008/10/27 13:59:34 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "btreeInt.h"
@@ -389,7 +389,7 @@ static int btree_clear_table(
pBt = sqlite3TestTextToPtr(argv[1]);
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
sqlite3BtreeEnter(pBt);
rc = sqlite3BtreeClearTable(pBt, iTable);
rc = sqlite3BtreeClearTable(pBt, iTable, 0);
sqlite3BtreeLeave(pBt);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
+3 -1
View File
@@ -11,7 +11,7 @@
*************************************************************************
** Code for testing the the SQLite library in a multithreaded environment.
**
** $Id: test4.c,v 1.23 2008/07/28 19:34:54 drh Exp $
** $Id: test4.c,v 1.24 2008/10/12 00:27:54 shane Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -96,7 +96,9 @@ static void *thread_main(void *pArg){
p->zErr = 0;
}
p->completed++;
#ifndef SQLITE_OMIT_DEPRECATED
sqlite3_thread_cleanup();
#endif
return 0;
}
+3 -1
View File
@@ -12,7 +12,7 @@
** Code for testing the client/server version of the SQLite library.
** Derived from test4.c.
**
** $Id: test7.c,v 1.12 2008/07/28 19:34:54 drh Exp $
** $Id: test7.c,v 1.13 2008/10/12 00:27:54 shane Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -118,7 +118,9 @@ static void *client_main(void *pArg){
p->zErr = 0;
}
p->completed++;
#ifndef SQLITE_OMIT_DEPRECATED
sqlite3_thread_cleanup();
#endif
return 0;
}
+26 -1
View File
@@ -10,7 +10,7 @@
**
*************************************************************************
**
** $Id: test_async.c,v 1.47 2008/09/15 15:49:34 danielk1977 Exp $
** $Id: test_async.c,v 1.48 2008/09/26 20:02:50 drh Exp $
**
** This file contains an example implementation of an asynchronous IO
** backend for SQLite.
@@ -571,12 +571,31 @@ static int async_cond_wait(pthread_cond_t *pCond, pthread_mutex_t *pMutex){
return rc;
}
/*
** Assert that the mutex is held by the current thread.
*/
static void assert_mutex_is_held(pthread_mutex_t *pMutex){
int iIdx;
pthread_mutex_t *aMutex = (pthread_mutex_t *)(&async);
pthread_t *aHolder = (pthread_t *)(&asyncdebug);
for(iIdx=0; iIdx<3; iIdx++){
if( pMutex==&aMutex[iIdx] ) break;
}
assert(iIdx<3);
assert( aHolder[iIdx]==pthread_self() );
}
/* Call our async_XX wrappers instead of selected pthread_XX functions */
#define pthread_mutex_lock async_mutex_lock
#define pthread_mutex_unlock async_mutex_unlock
#define pthread_mutex_trylock async_mutex_trylock
#define pthread_cond_wait async_cond_wait
#else /* if defined(NDEBUG) */
#define assert_mutex_is_held(X) /* A no-op when not debugging */
#endif /* !defined(NDEBUG) */
/*
@@ -1482,6 +1501,11 @@ static void *asyncWriterThread(void *pIsStarted){
rc = unlinkAsyncFile(pData);
pthread_mutex_unlock(&async.lockMutex);
if( !holdingMutex ){
pthread_mutex_lock(&async.queueMutex);
holdingMutex = 1;
}
assert_mutex_is_held(&async.queueMutex);
async.pQueueFirst = p->pNext;
sqlite3_free(pData);
doNotFree = 1;
@@ -1534,6 +1558,7 @@ static void *asyncWriterThread(void *pIsStarted){
async.pQueueLast = 0;
}
if( !doNotFree ){
assert_mutex_is_held(&async.queueMutex);
async.pQueueFirst = p->pNext;
sqlite3_free(p);
}
+6 -4
View File
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test_btree.c,v 1.7 2008/09/02 00:52:52 drh Exp $
** $Id: test_btree.c,v 1.8 2008/09/29 11:49:48 danielk1977 Exp $
*/
#include "btreeInt.h"
#include <tcl.h>
@@ -52,11 +52,11 @@ void sqlite3BtreeCursorList(Btree *p){
BtCursor *pCur;
BtShared *pBt = p->pBt;
for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
MemPage *pPage = pCur->pPage;
MemPage *pPage = pCur->apPage[pCur->iPage];
char *zMode = pCur->wrFlag ? "rw" : "ro";
sqlite3DebugPrintf("CURSOR %p rooted at %4d(%s) currently at %d.%d%s\n",
pCur, pCur->pgnoRoot, zMode,
pPage ? pPage->pgno : 0, pCur->idx,
pPage ? pPage->pgno : 0, pCur->aiIdx[pCur->iPage],
(pCur->eState==CURSOR_VALID) ? "" : " eof"
);
}
@@ -83,8 +83,9 @@ void sqlite3BtreeCursorList(Btree *p){
** This routine is used for testing and debugging only.
*/
int sqlite3BtreeCursorInfo(BtCursor *pCur, int *aResult, int upCnt){
#if 0
int cnt, idx;
MemPage *pPage = pCur->pPage;
MemPage *pPage = pCur->apPage[pCur->iPage];
BtCursor tmpCur;
int rc;
@@ -136,5 +137,6 @@ int sqlite3BtreeCursorInfo(BtCursor *pCur, int *aResult, int upCnt){
aResult[10] = 0;
}
sqlite3BtreeReleaseTempCursor(&tmpCur);
#endif
return SQLITE_OK;
}
+34 -6
View File
@@ -16,7 +16,7 @@
** The focus of this file is providing the TCL testing layer
** access to compile-time constants.
**
** $Id: test_config.c,v 1.36 2008/09/10 10:57:28 danielk1977 Exp $
** $Id: test_config.c,v 1.42 2008/10/12 00:27:54 shane Exp $
*/
#include "sqliteLimit.h"
@@ -39,8 +39,6 @@
** procedures use this to determine when tests should be omitted.
*/
static void set_options(Tcl_Interp *interp){
int rc = 0;
#ifdef SQLITE_32BIT_ROWID
Tcl_SetVar2(interp, "sqlite_options", "rowid32", "1", TCL_GLOBAL_ONLY);
#else
@@ -89,6 +87,12 @@ static void set_options(Tcl_Interp *interp){
Tcl_SetVar2(interp, "sqlite_options", "mem5", "0", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_MUTEX_OMIT
Tcl_SetVar2(interp, "sqlite_options", "mutex", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "mutex", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_ALTERTABLE
Tcl_SetVar2(interp, "sqlite_options", "altertable", "0", TCL_GLOBAL_ONLY);
#else
@@ -209,6 +213,12 @@ static void set_options(Tcl_Interp *interp){
Tcl_SetVar2(interp, "sqlite_options", "decltype", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_DEPRECATED
Tcl_SetVar2(interp, "sqlite_options", "deprecated", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "deprecated", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_DISKIO
Tcl_SetVar2(interp, "sqlite_options", "diskio", "0", TCL_GLOBAL_ONLY);
#else
@@ -305,6 +315,12 @@ static void set_options(Tcl_Interp *interp){
Tcl_SetVar2(interp, "sqlite_options", "localtime", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_LOOKASIDE
Tcl_SetVar2(interp, "sqlite_options", "lookaside", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "lookaside", "1", TCL_GLOBAL_ONLY);
#endif
Tcl_SetVar2(interp, "sqlite_options", "long_double",
sizeof(LONGDOUBLE_TYPE)>sizeof(double) ? "1" : "0",
TCL_GLOBAL_ONLY);
@@ -398,6 +414,12 @@ Tcl_SetVar2(interp, "sqlite_options", "long_double",
STRINGVALUE(SQLITE_THREADSAFE), TCL_GLOBAL_ONLY);
assert( sqlite3_threadsafe()==SQLITE_THREADSAFE );
#ifdef SQLITE_OMIT_TEMPDB
Tcl_SetVar2(interp, "sqlite_options", "tempdb", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "tempdb", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_TRACE
Tcl_SetVar2(interp, "sqlite_options", "trace", "0", TCL_GLOBAL_ONLY);
#else
@@ -410,10 +432,10 @@ Tcl_SetVar2(interp, "sqlite_options", "long_double",
Tcl_SetVar2(interp, "sqlite_options", "trigger", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_TEMPDB
Tcl_SetVar2(interp, "sqlite_options", "tempdb", "0", TCL_GLOBAL_ONLY);
#ifdef SQLITE_OMIT_TRUCATE_OPTIMIZATION
Tcl_SetVar2(interp, "sqlite_options", "truncate_opt", "0", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "tempdb", "1", TCL_GLOBAL_ONLY);
Tcl_SetVar2(interp, "sqlite_options", "truncate_opt", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_UTF16
@@ -446,6 +468,12 @@ Tcl_SetVar2(interp, "sqlite_options", "long_double",
Tcl_SetVar2(interp, "sqlite_options", "wsd", "1", TCL_GLOBAL_ONLY);
#endif
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
Tcl_SetVar2(interp, "sqlite_options", "update_delete_limit", "1", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "update_delete_limit", "0", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_SECURE_DELETE
Tcl_SetVar2(interp, "sqlite_options", "secure_delete", "1", TCL_GLOBAL_ONLY);
#else
+57 -26
View File
@@ -13,7 +13,7 @@
** This file contains code used to implement test interfaces to the
** memory allocation subsystem.
**
** $Id: test_malloc.c,v 1.47 2008/08/05 17:53:24 drh Exp $
** $Id: test_malloc.c,v 1.51 2008/11/19 01:20:26 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -204,7 +204,16 @@ static int faultsimInstall(int install){
faultsimBeginBenign, faultsimEndBenign
);
}else{
sqlite3_mem_methods m;
assert(memfault.m.xMalloc);
/* One should be able to reset the default memory allocator by storing
** a zeroed allocator then calling GETMALLOC. */
memset(&m, 0, sizeof(m));
sqlite3_config(SQLITE_CONFIG_MALLOC, &m);
sqlite3_config(SQLITE_CONFIG_GETMALLOC, &m);
assert( memcmp(&m, &memfault.m, sizeof(m))==0 );
rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memfault.m);
sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, 0, 0);
}
@@ -936,6 +945,42 @@ static int test_config_pagecache(
return TCL_OK;
}
/*
** Usage: sqlite3_config_alt_pcache INSTALL_FLAG DISCARD_CHANCE PRNG_SEED
**
** Set up the alternative test page cache. Install if INSTALL_FLAG is
** true and uninstall (reverting to the default page cache) if INSTALL_FLAG
** is false. DISCARD_CHANGE is an integer between 0 and 100 inclusive
** which determines the chance of discarding a page when unpinned. 100
** is certainty. 0 is never. PRNG_SEED is the pseudo-random number generator
** seed.
*/
static int test_alt_pcache(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
int installFlag;
int discardChance;
int prngSeed;
extern void installTestPCache(int,unsigned,unsigned);
if( objc!=4 ){
Tcl_WrongNumArgs(interp, 1, objv, "INSTALLFLAG DISCARDCHANCE PRNGSEEED");
return TCL_ERROR;
}
if( Tcl_GetIntFromObj(interp, objv[1], &installFlag) ) return TCL_ERROR;
if( Tcl_GetIntFromObj(interp, objv[2], &discardChance) ) return TCL_ERROR;
if( Tcl_GetIntFromObj(interp, objv[3], &prngSeed) ) return TCL_ERROR;
if( discardChance<0 || discardChance>100 ){
Tcl_AppendResult(interp, "discard-chance should be between 0 and 100",
(char*)0);
return TCL_ERROR;
}
installTestPCache(installFlag, (unsigned)discardChance, (unsigned)prngSeed);
return TCL_OK;
}
/*
** Usage: sqlite3_config_memstatus BOOLEAN
**
@@ -958,28 +1003,6 @@ static int test_config_memstatus(
return TCL_OK;
}
/*
** Usage: sqlite3_config_chunkalloc
**
*/
static int test_config_chunkalloc(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
int rc;
int nThreshold;
if( objc!=2 ){
Tcl_WrongNumArgs(interp, 1, objv, "THRESHOLD");
return TCL_ERROR;
}
if( Tcl_GetIntFromObj(interp, objv[1], &nThreshold) ) return TCL_ERROR;
rc = sqlite3_config(SQLITE_CONFIG_CHUNKALLOC, nThreshold);
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
return TCL_OK;
}
/*
** Usage: sqlite3_config_lookaside SIZE COUNT
**
@@ -992,14 +1015,22 @@ static int test_config_lookaside(
){
int rc;
int sz, cnt;
Tcl_Obj *pRet;
if( objc!=3 ){
Tcl_WrongNumArgs(interp, 1, objv, "SIZE COUNT");
return TCL_ERROR;
}
if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR;
if( Tcl_GetIntFromObj(interp, objv[2], &cnt) ) return TCL_ERROR;
pRet = Tcl_NewObj();
Tcl_ListObjAppendElement(
interp, pRet, Tcl_NewIntObj(sqlite3GlobalConfig.szLookaside)
);
Tcl_ListObjAppendElement(
interp, pRet, Tcl_NewIntObj(sqlite3GlobalConfig.nLookaside)
);
rc = sqlite3_config(SQLITE_CONFIG_LOOKASIDE, sz, cnt);
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
Tcl_SetObjResult(interp, pRet);
return TCL_OK;
}
@@ -1317,17 +1348,17 @@ int Sqlitetest_malloc_Init(Tcl_Interp *interp){
{ "sqlite3_memdebug_log", test_memdebug_log ,0 },
{ "sqlite3_config_scratch", test_config_scratch ,0 },
{ "sqlite3_config_pagecache", test_config_pagecache ,0 },
{ "sqlite3_config_alt_pcache", test_alt_pcache ,0 },
{ "sqlite3_status", test_status ,0 },
{ "sqlite3_db_status", test_db_status ,0 },
{ "install_malloc_faultsim", test_install_malloc_faultsim ,0 },
{ "sqlite3_config_heap", test_config_heap ,0 },
{ "sqlite3_config_memstatus", test_config_memstatus ,0 },
{ "sqlite3_config_chunkalloc", test_config_chunkalloc ,0 },
{ "sqlite3_config_lookaside", test_config_lookaside ,0 },
{ "sqlite3_config_error", test_config_error ,0 },
{ "sqlite3_db_config_lookaside",test_db_config_lookaside ,0 },
{ "sqlite3_dump_memsys3", test_dump_memsys3 ,3 },
{ "sqlite3_dump_memsys5", test_dump_memsys3 ,5 }
{ "sqlite3_dump_memsys5", test_dump_memsys3 ,5 },
};
int i;
for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
+55 -1
View File
@@ -10,7 +10,7 @@
**
*************************************************************************
**
** $Id: test_mutex.c,v 1.11 2008/07/19 13:43:24 danielk1977 Exp $
** $Id: test_mutex.c,v 1.12 2008/11/04 14:55:47 danielk1977 Exp $
*/
#include "tcl.h"
@@ -359,6 +359,57 @@ static int test_config(
return TCL_OK;
}
static sqlite3 *getDbPointer(Tcl_Interp *pInterp, Tcl_Obj *pObj){
sqlite3 *db;
Tcl_CmdInfo info;
char *zCmd = Tcl_GetString(pObj);
if( 1!=Tcl_GetCommandInfo(pInterp, zCmd, &info) ){
Tcl_AppendResult(pInterp, "No such db-handle: \"", zCmd, "\"", 0);
return 0;
}
db = *((sqlite3 **)info.objClientData);
assert( db );
return db;
}
static int test_enter_db_mutex(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
sqlite3 *db;
if( objc!=2 ){
Tcl_WrongNumArgs(interp, 1, objv, "DB");
return TCL_ERROR;
}
db = getDbPointer(interp, objv[1]);
if( !db ){
return TCL_ERROR;
}
sqlite3_mutex_enter(sqlite3_db_mutex(db));
return TCL_OK;
}
static int test_leave_db_mutex(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
sqlite3 *db;
if( objc!=2 ){
Tcl_WrongNumArgs(interp, 1, objv, "DB");
return TCL_ERROR;
}
db = getDbPointer(interp, objv[1]);
if( !db ){
return TCL_ERROR;
}
sqlite3_mutex_leave(sqlite3_db_mutex(db));
return TCL_OK;
}
int Sqlitetest_mutex_Init(Tcl_Interp *interp){
static struct {
char *zName;
@@ -368,6 +419,9 @@ int Sqlitetest_mutex_Init(Tcl_Interp *interp){
{ "sqlite3_initialize", (Tcl_ObjCmdProc*)test_initialize },
{ "sqlite3_config", (Tcl_ObjCmdProc*)test_config },
{ "enter_db_mutex", (Tcl_ObjCmdProc*)test_enter_db_mutex },
{ "leave_db_mutex", (Tcl_ObjCmdProc*)test_leave_db_mutex },
{ "alloc_dealloc_mutex", (Tcl_ObjCmdProc*)test_alloc_mutex },
{ "install_mutex_counters", (Tcl_ObjCmdProc*)test_install_mutex_counters },
{ "read_mutex_counters", (Tcl_ObjCmdProc*)test_read_mutex_counters },
+438
View File
@@ -0,0 +1,438 @@
/*
** 2008 November 18
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used for testing the SQLite system.
** None of the code in this file goes into a deliverable build.
**
** This file contains an application-defined pager cache
** implementation that can be plugged in in place of the
** default pcache. This alternative pager cache will throw
** some errors that the default cache does not.
**
** This pagecache implementation is designed for simplicity
** not speed.
**
** $Id: test_pcache.c,v 1.1 2008/11/19 01:20:26 drh Exp $
*/
#include "sqlite3.h"
#include <string.h>
#include <assert.h>
/*
** Global data used by this test implementation. There is no
** mutexing, which means this page cache will not work in a
** multi-threaded test.
*/
typedef struct testpcacheGlobalType testpcacheGlobalType;
struct testpcacheGlobalType {
void *pDummy; /* Dummy allocation to simulate failures */
int nInstance; /* Number of current instances */
unsigned discardChance; /* Chance of discarding on an unpin */
unsigned prngSeed; /* Seed for the PRNG */
};
static testpcacheGlobalType testpcacheGlobal;
/*
** Initializer.
**
** Verify that the initializer is only called when the system is
** uninitialized. Allocate some memory and report SQLITE_NOMEM if
** the allocation fails. This provides a means to test the recovery
** from a failed initialization attempt. It also verifies that the
** the destructor always gets call - otherwise there would be a
** memory leak.
*/
static int testpcacheInit(void *pArg){
assert( pArg==(void*)&testpcacheGlobal );
assert( testpcacheGlobal.pDummy==0 );
assert( testpcacheGlobal.nInstance==0 );
testpcacheGlobal.pDummy = sqlite3_malloc(10);
return testpcacheGlobal.pDummy==0 ? SQLITE_NOMEM : SQLITE_OK;
}
/*
** Destructor
**
** Verify that this is only called after initialization.
** Free the memory allocated by the initializer.
*/
static void testpcacheShutdown(void *pArg){
assert( pArg==(void*)&testpcacheGlobal );
assert( testpcacheGlobal.pDummy!=0 );
assert( testpcacheGlobal.nInstance==0 );
sqlite3_free( testpcacheGlobal.pDummy );
testpcacheGlobal.pDummy = 0;
}
/*
** Number of pages in a cache
*/
#define TESTPCACHE_NPAGE 217
#define TESTPCACHE_RESERVE 17
/*
** Magic numbers used to determine validity of the page cache.
*/
#define TESTPCACHE_VALID 0x364585fd
#define TESTPCACHE_CLEAR 0xd42670d4
/*
** Private implementation of a page cache.
*/
typedef struct testpcache testpcache;
struct testpcache {
int szPage; /* Size of each page. Multiple of 8. */
int bPurgeable; /* True if the page cache is purgeable */
int nFree; /* Number of unused slots in a[] */
int nPinned; /* Number of pinned slots in a[] */
unsigned iRand; /* State of the PRNG */
unsigned iMagic; /* Magic number for sanity checking */
struct testpcachePage {
unsigned key; /* The key for this page. 0 means unallocated */
int isPinned; /* True if the page is pinned */
void *pData; /* Data for this page */
} a[TESTPCACHE_NPAGE]; /* All pages in the cache */
};
/*
** Get a random number using the PRNG in the given page cache.
*/
static unsigned testpcacheRandom(testpcache *p){
unsigned x = 0;
int i;
for(i=0; i<4; i++){
p->iRand = (p->iRand*69069 + 5);
x = (x<<8) | ((p->iRand>>16)&0xff);
}
return x;
}
/*
** Allocate a new page cache instance.
*/
static sqlite3_pcache *testpcacheCreate(int szPage, int bPurgeable){
int nMem;
char *x;
testpcache *p;
int i;
assert( testpcacheGlobal.pDummy!=0 );
szPage = (szPage+7)&~7;
nMem = sizeof(testpcache) + TESTPCACHE_NPAGE*szPage;
p = sqlite3_malloc( nMem );
if( p==0 ) return 0;
x = (char*)&p[1];
p->szPage = szPage;
p->nFree = TESTPCACHE_NPAGE;
p->nPinned = 0;
p->iRand = testpcacheGlobal.prngSeed;
p->bPurgeable = bPurgeable;
p->iMagic = TESTPCACHE_VALID;
for(i=0; i<TESTPCACHE_NPAGE; i++, x += szPage){
p->a[i].key = 0;
p->a[i].isPinned = 0;
p->a[i].pData = (void*)x;
}
testpcacheGlobal.nInstance++;
return (sqlite3_pcache*)p;
}
/*
** Set the cache size
*/
static void testpcacheCachesize(sqlite3_pcache *pCache, int newSize){
testpcache *p = (testpcache*)pCache;
assert( p->iMagic==TESTPCACHE_VALID );
assert( newSize>=1 );
assert( testpcacheGlobal.pDummy!=0 );
assert( testpcacheGlobal.nInstance>0 );
}
/*
** Return the number of pages in the cache that are being used.
** This includes both pinned and unpinned pages.
*/
static int testpcachePagecount(sqlite3_pcache *pCache){
testpcache *p = (testpcache*)pCache;
assert( p->iMagic==TESTPCACHE_VALID );
assert( testpcacheGlobal.pDummy!=0 );
assert( testpcacheGlobal.nInstance>0 );
return TESTPCACHE_NPAGE - p->nFree;
}
/*
** Fetch a page.
*/
static void *testpcacheFetch(
sqlite3_pcache *pCache,
unsigned key,
int createFlag
){
testpcache *p = (testpcache*)pCache;
int i, j;
assert( p->iMagic==TESTPCACHE_VALID );
assert( testpcacheGlobal.pDummy!=0 );
assert( testpcacheGlobal.nInstance>0 );
/* See if the page is already in cache. Return immediately if it is */
for(i=0; i<TESTPCACHE_NPAGE; i++){
if( p->a[i].key==key ){
if( !p->a[i].isPinned ){
p->nPinned++;
assert( p->nPinned <= TESTPCACHE_NPAGE - p->nFree );
p->a[i].isPinned = 1;
}
return p->a[i].pData;
}
}
/* If createFlag is 0, never allocate a new page */
if( createFlag==0 ){
return 0;
}
/* If no pages are available, always fail */
if( p->nPinned==TESTPCACHE_NPAGE ){
return 0;
}
/* Do not allocate the last TESTPCACHE_RESERVE pages unless createFlag is 2 */
if( p->nPinned>=TESTPCACHE_NPAGE-TESTPCACHE_RESERVE && createFlag<2 ){
return 0;
}
/* Find a free page to allocate if there are any free pages.
** Withhold TESTPCACHE_RESERVE free pages until createFlag is 2.
*/
if( p->nFree>TESTPCACHE_RESERVE || (createFlag==2 && p->nFree>0) ){
j = testpcacheRandom(p) % TESTPCACHE_NPAGE;
for(i=0; i<TESTPCACHE_NPAGE; i++, j = (j+1)%TESTPCACHE_NPAGE){
if( p->a[j].key==0 ){
p->a[j].key = key;
p->a[j].isPinned = 1;
memset(p->a[j].pData, 0, p->szPage);
p->nPinned++;
p->nFree--;
assert( p->nPinned <= TESTPCACHE_NPAGE - p->nFree );
return p->a[j].pData;
}
}
/* The prior loop always finds a freepage to allocate */
assert( 0 );
}
/* If this cache is not purgeable then we have to fail.
*/
if( p->bPurgeable==0 ){
return 0;
}
/* If there are no free pages, recycle a page. The page to
** recycle is selected at random from all unpinned pages.
*/
j = testpcacheRandom(p) % TESTPCACHE_NPAGE;
for(i=0; i<TESTPCACHE_NPAGE; i++, j = (j+1)%TESTPCACHE_NPAGE){
if( p->a[j].key>0 && p->a[j].isPinned==0 ){
p->a[j].key = key;
p->a[j].isPinned = 1;
memset(p->a[j].pData, 0, p->szPage);
p->nPinned++;
assert( p->nPinned <= TESTPCACHE_NPAGE - p->nFree );
return p->a[j].pData;
}
}
/* The previous loop always finds a page to recycle. */
assert(0);
return 0;
}
/*
** Unpin a page.
*/
static void testpcacheUnpin(
sqlite3_pcache *pCache,
void *pOldPage,
int discard
){
testpcache *p = (testpcache*)pCache;
int i;
assert( p->iMagic==TESTPCACHE_VALID );
assert( testpcacheGlobal.pDummy!=0 );
assert( testpcacheGlobal.nInstance>0 );
/* Randomly discard pages as they are unpinned according to the
** discardChance setting. If discardChance is 0, the random discard
** never happens. If discardChance is 100, it always happens.
*/
if( p->bPurgeable
&& (100-testpcacheGlobal.discardChance) <= (testpcacheRandom(p)%100)
){
discard = 1;
}
for(i=0; i<TESTPCACHE_NPAGE; i++){
if( p->a[i].pData==pOldPage ){
/* The pOldPage pointer always points to a pinned page */
assert( p->a[i].isPinned );
p->a[i].isPinned = 0;
p->nPinned--;
assert( p->nPinned>=0 );
if( discard ){
p->a[i].key = 0;
p->nFree++;
assert( p->nFree<=TESTPCACHE_NPAGE );
}
return;
}
}
/* The pOldPage pointer always points to a valid page */
assert( 0 );
}
/*
** Rekey a single page.
*/
static void testpcacheRekey(
sqlite3_pcache *pCache,
void *pOldPage,
unsigned oldKey,
unsigned newKey
){
testpcache *p = (testpcache*)pCache;
int i;
assert( p->iMagic==TESTPCACHE_VALID );
assert( testpcacheGlobal.pDummy!=0 );
assert( testpcacheGlobal.nInstance>0 );
/* If there already exists another page at newKey, verify that
** the other page is unpinned and discard it.
*/
for(i=0; i<TESTPCACHE_NPAGE; i++){
if( p->a[i].key==newKey ){
/* The new key is never a page that is already pinned */
assert( p->a[i].isPinned==0 );
p->a[i].key = 0;
p->nFree++;
assert( p->nFree<=TESTPCACHE_NPAGE );
break;
}
}
/* Find the page to be rekeyed and rekey it.
*/
for(i=0; i<TESTPCACHE_NPAGE; i++){
if( p->a[i].key==oldKey ){
/* The oldKey and pOldPage parameters match */
assert( p->a[i].pData==pOldPage );
/* Page to be rekeyed must be pinned */
assert( p->a[i].isPinned );
p->a[i].key = newKey;
return;
}
}
/* Rekey is always given a valid page to work with */
assert( 0 );
}
/*
** Truncate the page cache. Every page with a key of iLimit or larger
** is discarded.
*/
static void testpcacheTruncate(sqlite3_pcache *pCache, unsigned iLimit){
testpcache *p = (testpcache*)pCache;
unsigned int i;
assert( p->iMagic==TESTPCACHE_VALID );
assert( testpcacheGlobal.pDummy!=0 );
assert( testpcacheGlobal.nInstance>0 );
for(i=0; i<TESTPCACHE_NPAGE; i++){
if( p->a[i].key>=iLimit ){
p->a[i].key = 0;
if( p->a[i].isPinned ){
p->nPinned--;
assert( p->nPinned>=0 );
}
p->nFree++;
assert( p->nFree<=TESTPCACHE_NPAGE );
}
}
}
/*
** Destroy a page cache.
*/
static void testpcacheDestroy(sqlite3_pcache *pCache){
testpcache *p = (testpcache*)pCache;
assert( p->iMagic==TESTPCACHE_VALID );
assert( testpcacheGlobal.pDummy!=0 );
assert( testpcacheGlobal.nInstance>0 );
p->iMagic = TESTPCACHE_CLEAR;
sqlite3_free(p);
testpcacheGlobal.nInstance--;
}
/*
** Invoke this routine to register or unregister the testing pager cache
** implemented by this file.
**
** Install the test pager cache if installFlag is 1 and uninstall it if
** installFlag is 0.
**
** When installing, discardChance is a number between 0 and 100 that
** indicates the probability of discarding a page when unpinning the
** page. 0 means never discard (unless the discard flag is set).
** 100 means always discard.
*/
void installTestPCache(
int installFlag, /* True to install. False to uninstall. */
unsigned discardChance, /* 0-100. Chance to discard on unpin */
unsigned prngSeed /* Seed for the PRNG */
){
static const sqlite3_pcache_methods testPcache = {
(void*)&testpcacheGlobal,
testpcacheInit,
testpcacheShutdown,
testpcacheCreate,
testpcacheCachesize,
testpcachePagecount,
testpcacheFetch,
testpcacheUnpin,
testpcacheRekey,
testpcacheTruncate,
testpcacheDestroy,
};
static sqlite3_pcache_methods defaultPcache;
static int isInstalled = 0;
assert( testpcacheGlobal.nInstance==0 );
assert( testpcacheGlobal.pDummy==0 );
assert( discardChance<=100 );
testpcacheGlobal.discardChance = discardChance;
testpcacheGlobal.prngSeed = prngSeed ^ (prngSeed<<16);
if( installFlag!=isInstalled ){
if( installFlag ){
sqlite3_config(SQLITE_CONFIG_GETPCACHE, &defaultPcache);
assert( defaultPcache.xCreate!=testpcacheCreate );
sqlite3_config(SQLITE_CONFIG_PCACHE, &testPcache);
}else{
assert( defaultPcache.xCreate!=0 );
sqlite3_config(SQLITE_CONFIG_PCACHE, &defaultPcache);
}
isInstalled = installFlag;
}
}
+1 -2
View File
@@ -14,7 +14,7 @@
** sqlite3_wsd_init() and sqlite3_wsd_find() functions required if the
** SQLITE_OMIT_WSD symbol is defined at build time.
**
** $Id: test_wsd.c,v 1.2 2008/09/02 16:22:29 danielk1977 Exp $
** $Id: test_wsd.c,v 1.3 2008/10/07 15:25:49 drh Exp $
*/
#if defined(SQLITE_OMIT_WSD) && defined(SQLITE_TEST)
@@ -84,4 +84,3 @@ void *sqlite3_wsd_find(void *K, int L){
}
#endif
+1 -2
View File
@@ -10,7 +10,7 @@
*************************************************************************
**
**
** $Id: trigger.c,v 1.129 2008/08/20 16:35:10 drh Exp $
** $Id: trigger.c,v 1.130 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -603,7 +603,6 @@ static int checkColumnOverLap(IdList *pIdList, ExprList *pEList){
** TRIGGER_AFTER.
*/
int sqlite3TriggersExist(
Parse *pParse, /* Used to check for recursive triggers */
Table *pTab, /* The table the contains the triggers */
int op, /* one of TK_DELETE, TK_INSERT, TK_UPDATE */
ExprList *pChanges /* Columns that change in an UPDATE statement */
+5 -4
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.184 2008/09/01 21:59:43 shane Exp $
** $Id: update.c,v 1.187 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -142,7 +142,7 @@ void sqlite3Update(
** updated is a view
*/
#ifndef SQLITE_OMIT_TRIGGER
triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges);
triggers_exist = sqlite3TriggersExist(pTab, TK_UPDATE, pChanges);
isView = pTab->pSelect!=0;
#else
# define triggers_exist 0
@@ -433,6 +433,7 @@ void sqlite3Update(
*/
if( chngRowid ){
sqlite3ExprCodeAndCache(pParse, pRowidExpr, regRowid);
sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid);
}else{
sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regRowid);
}
@@ -524,7 +525,7 @@ void sqlite3Update(
/* Create the new index entries and the new record.
*/
sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid,
aRegIdx, chngRowid, 1, -1, 0);
aRegIdx, 1, -1, 0);
}
/* Increment the row counter
@@ -567,7 +568,7 @@ void sqlite3Update(
if( db->flags & SQLITE_CountRows && !pParse->trigStack && pParse->nested==0 ){
sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", P4_STATIC);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
}
update_cleanup:
+3 -2
View File
@@ -12,7 +12,7 @@
** This file contains routines used to translate between UTF-8,
** UTF-16, UTF-16BE, and UTF-16LE.
**
** $Id: utf.c,v 1.65 2008/08/12 15:04:59 danielk1977 Exp $
** $Id: utf.c,v 1.66 2008/11/07 03:29:34 drh Exp $
**
** Notes on UTF-8:
**
@@ -226,7 +226,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
return SQLITE_NOMEM;
}
zIn = (u8*)pMem->z;
zTerm = &zIn[pMem->n];
zTerm = &zIn[pMem->n&~1];
while( zIn<zTerm ){
temp = *zIn;
*zIn = *(zIn+1);
@@ -244,6 +244,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
** A single byte is required for the output string
** nul-terminator.
*/
pMem->n &= ~1;
len = pMem->n * 2 + 1;
}else{
/* When converting from UTF-8 to UTF-16 the maximum growth is caused
+4 -4
View File
@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.241 2008/07/28 19:34:54 drh Exp $
** $Id: util.c,v 1.242 2008/11/17 19:18:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -57,7 +57,7 @@ int sqlite3IsNaN(double x){
int sqlite3Strlen(sqlite3 *db, const char *z){
const char *z2 = z;
int len;
size_t x;
int x;
while( *z2 ){ z2++; }
x = z2 - z;
len = 0x7fffffff & x;
@@ -934,7 +934,7 @@ int sqlite3SafetyOff(sqlite3 *db){
** used as an argument to sqlite3_errmsg() or sqlite3_close().
*/
int sqlite3SafetyCheckOk(sqlite3 *db){
int magic;
u32 magic;
if( db==0 ) return 0;
magic = db->magic;
if( magic!=SQLITE_MAGIC_OPEN &&
@@ -942,7 +942,7 @@ int sqlite3SafetyCheckOk(sqlite3 *db){
return 1;
}
int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
int magic;
u32 magic;
if( db==0 ) return 0;
magic = db->magic;
if( magic!=SQLITE_MAGIC_SICK &&
+2 -2
View File
@@ -14,7 +14,7 @@
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
**
** $Id: vacuum.c,v 1.83 2008/08/26 21:07:27 drh Exp $
** $Id: vacuum.c,v 1.84 2008/11/17 19:18:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@@ -251,7 +251,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
assert( 1==sqlite3BtreeIsInTrans(pMain) );
/* Copy Btree meta values */
for(i=0; i<sizeof(aCopy)/sizeof(aCopy[0]); i+=2){
for(i=0; i<ArraySize(aCopy); i+=2){
rc = sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);
if( rc!=SQLITE_OK ) goto end_of_vacuum;
rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);
+103 -76
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.779 2008/09/22 06:13:32 danielk1977 Exp $
** $Id: vdbe.c,v 1.788 2008/11/17 15:31:48 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -177,25 +177,25 @@ static const unsigned char opcodeProperty[] = OPFLG_INITIALIZER;
** specified by mask.
*/
int sqlite3VdbeOpcodeHasProperty(int opcode, int mask){
assert( opcode>0 && opcode<sizeof(opcodeProperty) );
assert( opcode>0 && opcode<(int)sizeof(opcodeProperty) );
return (opcodeProperty[opcode]&mask)!=0;
}
/*
** Allocate cursor number iCur. Return a pointer to it. Return NULL
** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
** if we run out of memory.
*/
static Cursor *allocateCursor(
Vdbe *p,
int iCur,
Op *pOp,
int iDb,
int isBtreeCursor
static VdbeCursor *allocateCursor(
Vdbe *p, /* The virtual machine */
int iCur, /* Index of the new VdbeCursor */
Op *pOp, /* */
int iDb, /* */
int isBtreeCursor /* */
){
/* Find the memory cell that will be used to store the blob of memory
** required for this Cursor structure. It is convenient to use a
** required for this VdbeCursor structure. It is convenient to use a
** vdbe memory cell to manage the memory allocation required for a
** Cursor structure for the following reasons:
** VdbeCursor structure for the following reasons:
**
** * Sometimes cursor numbers are used for a couple of different
** purposes in a vdbe program. The different uses might require
@@ -213,18 +213,18 @@ static Cursor *allocateCursor(
Mem *pMem = &p->aMem[p->nMem-iCur];
int nByte;
Cursor *pCx = 0;
VdbeCursor *pCx = 0;
/* If the opcode of pOp is OP_SetNumColumns, then pOp->p2 contains
** the number of fields in the records contained in the table or
** index being opened. Use this to reserve space for the
** Cursor.aType[] array.
** VdbeCursor.aType[] array.
*/
int nField = 0;
if( pOp->opcode==OP_SetNumColumns || pOp->opcode==OP_OpenEphemeral ){
nField = pOp->p2;
}
nByte =
sizeof(Cursor) +
sizeof(VdbeCursor) +
(isBtreeCursor?sqlite3BtreeCursorSize():0) +
2*nField*sizeof(u32);
@@ -234,15 +234,16 @@ static Cursor *allocateCursor(
p->apCsr[iCur] = 0;
}
if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
p->apCsr[iCur] = pCx = (Cursor *)pMem->z;
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
memset(pMem->z, 0, nByte);
pCx->iDb = iDb;
pCx->nField = nField;
if( nField ){
pCx->aType = (u32 *)&pMem->z[sizeof(Cursor)];
pCx->aType = (u32 *)&pMem->z[sizeof(VdbeCursor)];
}
if( isBtreeCursor ){
pCx->pCursor = (BtCursor *)&pMem->z[sizeof(Cursor)+2*nField*sizeof(u32)];
pCx->pCursor = (BtCursor*)
&pMem->z[sizeof(VdbeCursor)+2*nField*sizeof(u32)];
}
}
return pCx;
@@ -551,7 +552,6 @@ int sqlite3VdbeExec(
#endif
UnpackedRecord aTempRec[16]; /* Space to hold a transient UnpackedRecord */
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
assert( db->magic==SQLITE_MAGIC_BUSY );
sqlite3BtreeMutexArrayEnter(&p->aMutex);
@@ -1322,7 +1322,7 @@ case OP_Function: {
MemSetTypeFlag(&ctx.s, MEM_Null);
ctx.isError = 0;
if( ctx.pFunc->needCollSeq ){
if( ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
assert( pOp>p->aOp );
assert( pOp[-1].p4type==P4_COLLSEQ );
assert( pOp[-1].opcode==OP_CollSeq );
@@ -1958,23 +1958,20 @@ case OP_SetNumColumns: {
**
** The value extracted is stored in register P3.
**
** If the KeyAsData opcode has previously executed on this cursor, then the
** field might be extracted from the key rather than the data.
**
** If the column contains fewer than P2 fields, then extract a NULL. Or,
** if the P4 argument is a P4_MEM use the value of the P4 argument as
** the result.
*/
case OP_Column: {
u32 payloadSize; /* Number of bytes in the record */
int payloadSize; /* Number of bytes in the record */
int p1 = pOp->p1; /* P1 value of the opcode */
int p2 = pOp->p2; /* column number to retrieve */
Cursor *pC = 0; /* The VDBE cursor */
VdbeCursor *pC = 0;/* The VDBE cursor */
char *zRec; /* Pointer to complete record-data */
BtCursor *pCrsr; /* The BTree cursor */
u32 *aType; /* aType[i] holds the numeric type of the i-th column */
u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
u32 nField; /* number of fields in the record */
int nField; /* number of fields in the record */
int len; /* The length of the serialized data for the column */
int i; /* Loop counter */
char *zData; /* Part of the record being decoded */
@@ -1999,7 +1996,7 @@ case OP_Column: {
** If the data is unavailable, zRec is set to NULL.
**
** We also compute the number of columns in the record. For cursors,
** the number of columns is stored in the Cursor.nField element.
** the number of columns is stored in the VdbeCursor.nField element.
*/
pC = p->apCsr[p1];
assert( pC!=0 );
@@ -2022,7 +2019,7 @@ case OP_Column: {
sqlite3BtreeKeySize(pCrsr, &payloadSize64);
payloadSize = payloadSize64;
}else{
sqlite3BtreeDataSize(pCrsr, &payloadSize);
sqlite3BtreeDataSize(pCrsr, (u32 *)&payloadSize);
}
nField = pC->nField;
}else{
@@ -2056,7 +2053,7 @@ case OP_Column: {
}else{
u8 *zIdx; /* Index into header */
u8 *zEndHdr; /* Pointer to first byte after the header */
u32 offset; /* Offset into the data */
int offset; /* Offset into the data */
int szHdrSz; /* Size of the header size field at start of record */
int avail; /* Number of bytes of available data */
@@ -2257,7 +2254,7 @@ case OP_MakeRecord: {
Mem *pRec; /* The new record */
u64 nData = 0; /* Number of bytes of data space */
int nHdr = 0; /* Number of bytes of header space */
u64 nByte = 0; /* Data space required for this record */
i64 nByte = 0; /* Data space required for this record */
int nZero = 0; /* Number of zero bytes at the end of the record */
int nVarint; /* Number of bytes in a varint */
u32 serial_type; /* Type field */
@@ -2395,33 +2392,40 @@ case OP_Statement: {
** This instruction causes the VM to halt.
*/
case OP_AutoCommit: {
u8 i = pOp->p1;
u8 rollback = pOp->p2;
int desiredAutoCommit = pOp->p1;
int rollback = pOp->p2;
int turnOnAC = desiredAutoCommit && !db->autoCommit;
assert( i==1 || i==0 );
assert( i==1 || rollback==0 );
assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
assert( desiredAutoCommit==1 || rollback==0 );
assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */
if( db->activeVdbeCnt>1 && i && !db->autoCommit ){
/* If this instruction implements a COMMIT or ROLLBACK, other VMs are
if( turnOnAC && rollback && db->activeVdbeCnt>1 ){
/* If this instruction implements a ROLLBACK and other VMs are
** still running, and a transaction is active, return an error indicating
** that the other VMs must complete first.
*/
sqlite3SetString(&p->zErrMsg, db, "cannot %s transaction - "
"SQL statements in progress",
rollback ? "rollback" : "commit");
rc = SQLITE_ERROR;
}else if( i!=db->autoCommit ){
sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
"SQL statements in progress");
rc = SQLITE_BUSY;
}else if( turnOnAC && !rollback && db->writeVdbeCnt>1 ){
/* If this instruction implements a COMMIT and other VMs are writing
** return an error indicating that the other VMs must complete first.
*/
sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
"SQL statements in progress");
rc = SQLITE_BUSY;
}else if( desiredAutoCommit!=db->autoCommit ){
if( pOp->p2 ){
assert( i==1 );
assert( desiredAutoCommit==1 );
sqlite3RollbackAll(db);
db->autoCommit = 1;
}else{
db->autoCommit = i;
db->autoCommit = desiredAutoCommit;
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
p->pc = pc;
db->autoCommit = 1-i;
db->autoCommit = 1-desiredAutoCommit;
p->rc = rc = SQLITE_BUSY;
goto vdbe_return;
}
@@ -2434,7 +2438,7 @@ case OP_AutoCommit: {
goto vdbe_return;
}else{
sqlite3SetString(&p->zErrMsg, db,
(!i)?"cannot start a transaction within a transaction":(
(!desiredAutoCommit)?"cannot start a transaction within a transaction":(
(rollback)?"cannot rollback - no transaction is active":
"cannot commit - no transaction is active"));
@@ -2671,7 +2675,7 @@ case OP_OpenWrite: {
int iDb = pOp->p3;
int wrFlag;
Btree *pX;
Cursor *pCur;
VdbeCursor *pCur;
Db *pDb;
assert( iDb>=0 && iDb<db->nDb );
@@ -2693,7 +2697,10 @@ case OP_OpenWrite: {
pIn2 = &p->aMem[p2];
sqlite3VdbeMemIntegerify(pIn2);
p2 = pIn2->u.i;
assert( p2>=2 );
if( p2<2 ) {
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
}
}
assert( i>=0 );
pCur = allocateCursor(p, i, &pOp[-1], iDb, 1);
@@ -2771,7 +2778,7 @@ case OP_OpenWrite: {
*/
case OP_OpenEphemeral: {
int i = pOp->p1;
Cursor *pCx;
VdbeCursor *pCx;
static const int openFlags =
SQLITE_OPEN_READWRITE |
SQLITE_OPEN_CREATE |
@@ -2837,7 +2844,7 @@ case OP_OpenEphemeral: {
*/
case OP_OpenPseudo: {
int i = pOp->p1;
Cursor *pCx;
VdbeCursor *pCx;
assert( i>=0 );
pCx = allocateCursor(p, i, &pOp[-1], -1, 0);
if( pCx==0 ) goto no_mem;
@@ -2926,7 +2933,7 @@ case OP_MoveLe: /* jump, in3 */
case OP_MoveGe: /* jump, in3 */
case OP_MoveGt: { /* jump, in3 */
int i = pOp->p1;
Cursor *pC;
VdbeCursor *pC;
assert( i>=0 && i<p->nCursor );
pC = p->apCsr[i];
@@ -3043,7 +3050,7 @@ case OP_NotFound: /* jump, in3 */
case OP_Found: { /* jump, in3 */
int i = pOp->p1;
int alreadyExists = 0;
Cursor *pC;
VdbeCursor *pC;
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
if( (pC = p->apCsr[i])->pCursor!=0 ){
@@ -3099,7 +3106,7 @@ case OP_Found: { /* jump, in3 */
*/
case OP_IsUnique: { /* jump, in3 */
int i = pOp->p1;
Cursor *pCx;
VdbeCursor *pCx;
BtCursor *pCrsr;
Mem *pK;
i64 R;
@@ -3196,7 +3203,7 @@ case OP_IsUnique: { /* jump, in3 */
*/
case OP_NotExists: { /* jump, in3 */
int i = pOp->p1;
Cursor *pC;
VdbeCursor *pC;
BtCursor *pCrsr;
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
@@ -3265,7 +3272,7 @@ case OP_Sequence: { /* out2-prerelease */
case OP_NewRowid: { /* out2-prerelease */
int i = pOp->p1;
i64 v = 0;
Cursor *pC;
VdbeCursor *pC;
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
if( (pC = p->apCsr[i])->pCursor==0 ){
@@ -3320,7 +3327,7 @@ case OP_NewRowid: { /* out2-prerelease */
** Others complain about 0x7ffffffffffffffffLL. The following macro seems
** to provide the constant while making all compilers happy.
*/
# define MAX_ROWID ( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
# define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
#endif
if( !pC->useRandomRowid ){
@@ -3433,7 +3440,7 @@ case OP_Insert: {
i64 iKey; /* The integer ROWID or key for the record to be inserted */
int i = pOp->p1;
Cursor *pC;
VdbeCursor *pC;
assert( i>=0 && i<p->nCursor );
pC = p->apCsr[i];
assert( pC!=0 );
@@ -3527,7 +3534,7 @@ case OP_Insert: {
case OP_Delete: {
int i = pOp->p1;
i64 iKey;
Cursor *pC;
VdbeCursor *pC;
assert( i>=0 && i<p->nCursor );
pC = p->apCsr[i];
@@ -3598,7 +3605,7 @@ case OP_ResetCount: {
case OP_RowKey:
case OP_RowData: {
int i = pOp->p1;
Cursor *pC;
VdbeCursor *pC;
BtCursor *pCrsr;
u32 n;
@@ -3626,7 +3633,7 @@ case OP_RowData: {
n = n64;
}else{
sqlite3BtreeDataSize(pCrsr, &n);
if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
if( (int)n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
goto too_big;
}
}
@@ -3652,7 +3659,7 @@ case OP_RowData: {
*/
case OP_Rowid: { /* out2-prerelease */
int i = pOp->p1;
Cursor *pC;
VdbeCursor *pC;
i64 v;
assert( i>=0 && i<p->nCursor );
@@ -3685,13 +3692,16 @@ case OP_Rowid: { /* out2-prerelease */
*/
case OP_NullRow: {
int i = pOp->p1;
Cursor *pC;
VdbeCursor *pC;
assert( i>=0 && i<p->nCursor );
pC = p->apCsr[i];
assert( pC!=0 );
pC->nullRow = 1;
pC->rowidIsValid = 0;
if( pC->pCursor ){
sqlite3BtreeClearCursor(pC->pCursor);
}
break;
}
@@ -3705,7 +3715,7 @@ case OP_NullRow: {
*/
case OP_Last: { /* jump */
int i = pOp->p1;
Cursor *pC;
VdbeCursor *pC;
BtCursor *pCrsr;
int res;
@@ -3742,6 +3752,7 @@ case OP_Sort: { /* jump */
sqlite3_sort_count++;
sqlite3_search_count--;
#endif
p->aCounter[SQLITE_STMTSTATUS_SORT-1]++;
/* Fall through into OP_Rewind */
}
/* Opcode: Rewind P1 P2 * * *
@@ -3754,7 +3765,7 @@ case OP_Sort: { /* jump */
*/
case OP_Rewind: { /* jump */
int i = pOp->p1;
Cursor *pC;
VdbeCursor *pC;
BtCursor *pCrsr;
int res;
@@ -3799,7 +3810,7 @@ case OP_Rewind: { /* jump */
*/
case OP_Prev: /* jump */
case OP_Next: { /* jump */
Cursor *pC;
VdbeCursor *pC;
BtCursor *pCrsr;
int res;
@@ -3819,6 +3830,7 @@ case OP_Next: { /* jump */
pC->cacheStatus = CACHE_STALE;
if( res==0 ){
pc = pOp->p2 - 1;
if( pOp->p5 ) p->aCounter[pOp->p5-1]++;
#ifdef SQLITE_TEST
sqlite3_search_count++;
#endif
@@ -3841,7 +3853,7 @@ case OP_Next: { /* jump */
*/
case OP_IdxInsert: { /* in2 */
int i = pOp->p1;
Cursor *pC;
VdbeCursor *pC;
BtCursor *pCrsr;
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
@@ -3860,7 +3872,7 @@ case OP_IdxInsert: { /* in2 */
break;
}
/* Opcode: IdxDeleteM P1 P2 P3 * *
/* Opcode: IdxDelete P1 P2 P3 * *
**
** The content of P3 registers starting at register P2 form
** an unpacked index key. This opcode removes that entry from the
@@ -3868,7 +3880,7 @@ case OP_IdxInsert: { /* in2 */
*/
case OP_IdxDelete: {
int i = pOp->p1;
Cursor *pC;
VdbeCursor *pC;
BtCursor *pCrsr;
assert( pOp->p3>0 );
assert( pOp->p2>0 && pOp->p2+pOp->p3<=p->nMem );
@@ -3902,7 +3914,7 @@ case OP_IdxDelete: {
case OP_IdxRowid: { /* out2-prerelease */
int i = pOp->p1;
BtCursor *pCrsr;
Cursor *pC;
VdbeCursor *pC;
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
@@ -3952,7 +3964,7 @@ case OP_IdxRowid: { /* out2-prerelease */
case OP_IdxLT: /* jump, in3 */
case OP_IdxGE: { /* jump, in3 */
int i= pOp->p1;
Cursor *pC;
VdbeCursor *pC;
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
@@ -4037,7 +4049,7 @@ case OP_Destroy: { /* out2-prerelease */
break;
}
/* Opcode: Clear P1 P2 *
/* Opcode: Clear P1 P2 P3
**
** Delete all contents of the database table or index whose root page
** in the database file is given by P1. But, unlike Destroy, do not
@@ -4047,11 +4059,26 @@ case OP_Destroy: { /* out2-prerelease */
** P2==1 then the table to be clear is in the auxiliary database file
** that is used to store tables create using CREATE TEMPORARY TABLE.
**
** If the P3 value is non-zero, then the table refered to must be an
** intkey table (an SQL table, not an index). In this case the row change
** count is incremented by the number of rows in the table being cleared.
** If P3 is greater than zero, then the value stored in register P3 is
** also incremented by the number of rows in the table being cleared.
**
** See also: Destroy
*/
case OP_Clear: {
int nChange = 0;
assert( (p->btreeMask & (1<<pOp->p2))!=0 );
rc = sqlite3BtreeClearTable(db->aDb[pOp->p2].pBt, pOp->p1);
rc = sqlite3BtreeClearTable(
db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
);
if( pOp->p3 ){
p->nChange += nChange;
if( pOp->p3>0 ){
p->aMem[pOp->p3].u.i += nChange;
}
}
break;
}
@@ -4434,7 +4461,7 @@ case OP_AggStep: {
ctx.s.db = db;
ctx.isError = 0;
ctx.pColl = 0;
if( ctx.pFunc->needCollSeq ){
if( ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
assert( pOp>p->aOp );
assert( pOp[-1].p4type==P4_COLLSEQ );
assert( pOp[-1].opcode==OP_CollSeq );
@@ -4620,7 +4647,7 @@ case OP_VDestroy: {
** table and stores that cursor in P1.
*/
case OP_VOpen: {
Cursor *pCur = 0;
VdbeCursor *pCur = 0;
sqlite3_vtab_cursor *pVtabCursor = 0;
sqlite3_vtab *pVtab = pOp->p4.pVtab;
@@ -4679,7 +4706,7 @@ case OP_VFilter: { /* jump */
sqlite3_vtab_cursor *pVtabCursor;
sqlite3_vtab *pVtab;
Cursor *pCur = p->apCsr[pOp->p1];
VdbeCursor *pCur = p->apCsr[pOp->p1];
REGISTER_TRACE(pOp->p3, pQuery);
assert( pCur->pVtabCursor );
@@ -4736,7 +4763,7 @@ case OP_VRowid: { /* out2-prerelease */
sqlite3_vtab *pVtab;
const sqlite3_module *pModule;
sqlite_int64 iRow;
Cursor *pCur = p->apCsr[pOp->p1];
VdbeCursor *pCur = p->apCsr[pOp->p1];
assert( pCur->pVtabCursor );
if( pCur->nullRow ){
@@ -4770,7 +4797,7 @@ case OP_VColumn: {
Mem *pDest;
sqlite3_context sContext;
Cursor *pCur = p->apCsr[pOp->p1];
VdbeCursor *pCur = p->apCsr[pOp->p1];
assert( pCur->pVtabCursor );
assert( pOp->p3>0 && pOp->p3<=p->nMem );
pDest = &p->aMem[pOp->p3];
@@ -4828,7 +4855,7 @@ case OP_VNext: { /* jump */
const sqlite3_module *pModule;
int res = 0;
Cursor *pCur = p->apCsr[pOp->p1];
VdbeCursor *pCur = p->apCsr[pOp->p1];
assert( pCur->pVtabCursor );
if( pCur->nullRow ){
break;
+2 -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.138 2008/08/20 22:06:48 drh Exp $
** $Id: vdbe.h,v 1.139 2008/10/31 10:53:23 danielk1977 Exp $
*/
#ifndef _SQLITE_VDBE_H_
#define _SQLITE_VDBE_H_
@@ -178,7 +178,7 @@ int sqlite3VdbeCurrentAddr(Vdbe*);
void sqlite3VdbeResetStepResult(Vdbe*);
int sqlite3VdbeReset(Vdbe*);
void sqlite3VdbeSetNumCols(Vdbe*,int);
int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
void sqlite3VdbeCountChanges(Vdbe*);
sqlite3 *sqlite3VdbeDb(Vdbe*);
void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
+17 -14
View File
@@ -15,7 +15,7 @@
** 6000 lines long) it was split up into several smaller files and
** this header information was factored out.
**
** $Id: vdbeInt.h,v 1.154 2008/08/13 19:11:48 drh Exp $
** $Id: vdbeInt.h,v 1.158 2008/11/17 15:31:48 danielk1977 Exp $
*/
#ifndef _VDBEINT_H_
#define _VDBEINT_H_
@@ -50,12 +50,12 @@ typedef unsigned char Bool;
** Every cursor that the virtual machine has open is represented by an
** instance of the following structure.
**
** If the Cursor.isTriggerRow flag is set it means that this cursor is
** If the VdbeCursor.isTriggerRow flag is set it means that this cursor is
** really a single row that represents the NEW or OLD pseudo-table of
** a row trigger. The data for the row is stored in Cursor.pData and
** the rowid is in Cursor.iKey.
** a row trigger. The data for the row is stored in VdbeCursor.pData and
** the rowid is in VdbeCursor.iKey.
*/
struct Cursor {
struct VdbeCursor {
BtCursor *pCursor; /* The cursor structure of the backend */
int iDb; /* Index of cursor database in db->aDb[] (or -1) */
i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
@@ -93,10 +93,10 @@ struct Cursor {
u32 *aOffset; /* Cached offsets to the start of each columns data */
u8 *aRow; /* Data for the current row, if all on one page */
};
typedef struct Cursor Cursor;
typedef struct VdbeCursor VdbeCursor;
/*
** A value for Cursor.cacheValid that means the cache is always invalid.
** A value for VdbeCursor.cacheValid that means the cache is always invalid.
*/
#define CACHE_STALE 0
@@ -291,16 +291,16 @@ struct Vdbe {
Mem **apArg; /* Arguments to currently executing user function */
Mem *aColName; /* Column names to return */
int nCursor; /* Number of slots in apCsr[] */
Cursor **apCsr; /* One element of this array for each open cursor */
VdbeCursor **apCsr; /* One element of this array for each open cursor */
int nVar; /* Number of entries in aVar[] */
Mem *aVar; /* Values for the OP_Variable opcode. */
char **azVar; /* Name of variables */
int okVar; /* True if azVar[] has been initialized */
int magic; /* Magic number for sanity checking */
u32 magic; /* Magic number for sanity checking */
int nMem; /* Number of memory locations currently allocated */
Mem *aMem; /* The memory locations */
int nCallback; /* Number of callbacks invoked so far */
int cacheCtr; /* Cursor row cache generation counter */
int cacheCtr; /* VdbeCursor row cache generation counter */
Fifo sFifo; /* A list of ROWIDs */
int contextStackTop; /* Index of top element in the context stack */
int contextStackDepth; /* The size of the "context" stack */
@@ -319,14 +319,17 @@ struct Vdbe {
u8 expired; /* True if the VM needs to be recompiled */
u8 minWriteFileFormat; /* Minimum file format for writable database files */
u8 inVtabMethod; /* See comments above */
u8 usesStmtJournal; /* True if uses a statement journal */
u8 readOnly; /* True for read-only statements */
int nChange; /* Number of db changes made since last reset */
i64 startTime; /* Time when query started - used for profiling */
int btreeMask; /* Bitmask of db->aDb[] entries referenced */
BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
int aCounter[2]; /* Counters used by sqlite3_stmt_status() */
int nSql; /* Number of bytes in zSql */
char *zSql; /* Text of the SQL statement that generated this */
#ifdef SQLITE_DEBUG
FILE *trace; /* Write an execution trace here, if not NULL */
FILE *trace; /* Write an execution trace here, if not NULL */
#endif
int openedStatement; /* True if this VM has opened a statement journal */
#ifdef SQLITE_SSE
@@ -350,9 +353,9 @@ struct Vdbe {
/*
** Function prototypes
*/
void sqlite3VdbeFreeCursor(Vdbe *, Cursor*);
void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
void sqliteVdbePopStack(Vdbe*,int);
int sqlite3VdbeCursorMoveto(Cursor*);
int sqlite3VdbeCursorMoveto(VdbeCursor*);
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
void sqlite3VdbePrintOp(FILE*, int, Op*);
#endif
@@ -363,7 +366,7 @@ int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
int sqlite3VdbeIdxKeyCompare(Cursor*,UnpackedRecord*,int*);
int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
int sqlite3VdbeIdxRowid(BtCursor *, i64 *);
int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
int sqlite3VdbeExec(Vdbe*);
+55 -31
View File
@@ -13,7 +13,7 @@
** This file contains code use to implement APIs that are part of the
** VDBE.
**
** $Id: vdbeapi.c,v 1.141 2008/09/04 12:03:43 shane Exp $
** $Id: vdbeapi.c,v 1.149 2008/11/19 09:05:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@@ -174,6 +174,7 @@ int vdbeReprepare(Vdbe *p){
#endif
#ifndef SQLITE_OMIT_DEPRECATED
/*
** Return TRUE (non-zero) of the statement supplied as an argument needs
** to be recompiled. A statement needs to be recompiled whenever the
@@ -186,6 +187,7 @@ int sqlite3_expired(sqlite3_stmt *pStmt){
Vdbe *p = (Vdbe*)pStmt;
return p==0 || p->expired;
}
#endif
/*
** The following routine destroys a virtual machine that is created by
@@ -202,7 +204,7 @@ int sqlite3_finalize(sqlite3_stmt *pStmt){
rc = SQLITE_OK;
}else{
Vdbe *v = (Vdbe*)pStmt;
#ifndef SQLITE_MUTEX_NOOP
#if SQLITE_THREADSAFE
sqlite3_mutex *mutex = v->db->mutex;
#endif
sqlite3_mutex_enter(mutex);
@@ -244,7 +246,7 @@ int sqlite3_clear_bindings(sqlite3_stmt *pStmt){
int i;
int rc = SQLITE_OK;
Vdbe *p = (Vdbe*)pStmt;
#ifndef SQLITE_MUTEX_NOOP
#if SQLITE_THREADSAFE
sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
#endif
sqlite3_mutex_enter(mutex);
@@ -466,6 +468,7 @@ static int sqlite3Step(Vdbe *p){
#endif
db->activeVdbeCnt++;
if( p->readOnly==0 ) db->writeVdbeCnt++;
p->pc = 0;
stmtLruRemove(p);
}
@@ -598,11 +601,12 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
*/
void sqlite3InvalidFunction(
sqlite3_context *context, /* The function calling context */
int argc, /* Number of arguments to the function */
sqlite3_value **argv /* Value of each argument */
int NotUsed, /* Number of arguments to the function */
sqlite3_value **NotUsed2 /* Value of each argument */
){
const char *zName = context->pFunc->zName;
char *zErr;
UNUSED_PARAMETER2(NotUsed, NotUsed2);
zErr = sqlite3MPrintf(0,
"unable to use function %s in the requested context", zName);
sqlite3_result_error(context, zErr, -1);
@@ -695,6 +699,7 @@ failed:
}
}
#ifndef SQLITE_OMIT_DEPRECATED
/*
** Return the number of times the Step function of a aggregate has been
** called.
@@ -708,6 +713,7 @@ int sqlite3_aggregate_count(sqlite3_context *p){
assert( p && p->pFunc && p->pFunc->xStep );
return p->pMem->n;
}
#endif
/*
** Return the number of columns in the result set for the statement pStmt.
@@ -833,9 +839,13 @@ const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
return val;
}
sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
sqlite3_value *pOut = columnMem(pStmt, i);
Mem *pOut = columnMem(pStmt, i);
if( pOut->flags&MEM_Static ){
pOut->flags &= ~MEM_Static;
pOut->flags |= MEM_Ephem;
}
columnMallocFailure(pStmt);
return pOut;
return (sqlite3_value *)pOut;
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
@@ -1005,17 +1015,24 @@ const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
** the same as binding a NULL value to the column. If the "i" parameter is
** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK.
**
** A successful evaluation of this routine acquires the mutex on p.
** the mutex is released if any kind of error occurs.
**
** The error code stored in database p->db is overwritten with the return
** value in any case.
*/
static int vdbeUnbind(Vdbe *p, int i){
Mem *pVar;
if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
if( p==0 ) return SQLITE_MISUSE;
sqlite3_mutex_enter(p->db->mutex);
if( p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
sqlite3Error(p->db, SQLITE_MISUSE, 0);
sqlite3_mutex_leave(p->db->mutex);
return SQLITE_MISUSE;
}
if( i<1 || i>p->nVar ){
sqlite3Error(p->db, SQLITE_RANGE, 0);
sqlite3_mutex_leave(p->db->mutex);
return SQLITE_RANGE;
}
i--;
@@ -1041,21 +1058,19 @@ static int bindText(
Mem *pVar;
int rc;
if( p==0 ){
return SQLITE_MISUSE;
}
sqlite3_mutex_enter(p->db->mutex);
rc = vdbeUnbind(p, i);
if( rc==SQLITE_OK && zData!=0 ){
pVar = &p->aVar[i-1];
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
if( rc==SQLITE_OK && encoding!=0 ){
rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
if( rc==SQLITE_OK ){
if( zData!=0 ){
pVar = &p->aVar[i-1];
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
if( rc==SQLITE_OK && encoding!=0 ){
rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
}
sqlite3Error(p->db, rc, 0);
rc = sqlite3ApiExit(p->db, rc);
}
sqlite3Error(p->db, rc, 0);
rc = sqlite3ApiExit(p->db, rc);
sqlite3_mutex_leave(p->db->mutex);
}
sqlite3_mutex_leave(p->db->mutex);
return rc;
}
@@ -1075,12 +1090,11 @@ int sqlite3_bind_blob(
int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
int rc;
Vdbe *p = (Vdbe *)pStmt;
sqlite3_mutex_enter(p->db->mutex);
rc = vdbeUnbind(p, i);
if( rc==SQLITE_OK ){
sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
sqlite3_mutex_leave(p->db->mutex);
}
sqlite3_mutex_leave(p->db->mutex);
return rc;
}
int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
@@ -1089,20 +1103,20 @@ int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
int rc;
Vdbe *p = (Vdbe *)pStmt;
sqlite3_mutex_enter(p->db->mutex);
rc = vdbeUnbind(p, i);
if( rc==SQLITE_OK ){
sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
sqlite3_mutex_leave(p->db->mutex);
}
sqlite3_mutex_leave(p->db->mutex);
return rc;
}
int sqlite3_bind_null(sqlite3_stmt *pStmt, int i){
int rc;
Vdbe *p = (Vdbe*)pStmt;
sqlite3_mutex_enter(p->db->mutex);
rc = vdbeUnbind(p, i);
sqlite3_mutex_leave(p->db->mutex);
if( rc==SQLITE_OK ){
sqlite3_mutex_leave(p->db->mutex);
}
return rc;
}
int sqlite3_bind_text(
@@ -1128,27 +1142,25 @@ int sqlite3_bind_text16(
int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
int rc;
Vdbe *p = (Vdbe *)pStmt;
sqlite3_mutex_enter(p->db->mutex);
rc = vdbeUnbind(p, i);
if( rc==SQLITE_OK ){
rc = sqlite3VdbeMemCopy(&p->aVar[i-1], pValue);
if( rc==SQLITE_OK ){
rc = sqlite3VdbeChangeEncoding(&p->aVar[i-1], ENC(p->db));
}
sqlite3_mutex_leave(p->db->mutex);
}
rc = sqlite3ApiExit(p->db, rc);
sqlite3_mutex_leave(p->db->mutex);
return rc;
}
int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
int rc;
Vdbe *p = (Vdbe *)pStmt;
sqlite3_mutex_enter(p->db->mutex);
rc = vdbeUnbind(p, i);
if( rc==SQLITE_OK ){
sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
sqlite3_mutex_leave(p->db->mutex);
}
sqlite3_mutex_leave(p->db->mutex);
return rc;
}
@@ -1248,6 +1260,7 @@ int sqlite3TransferBindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
return rc;
}
#ifndef SQLITE_OMIT_DEPRECATED
/*
** Deprecated external interface. Internal/core SQLite code
** should call sqlite3TransferBindings.
@@ -1255,6 +1268,7 @@ int sqlite3TransferBindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
return sqlite3TransferBindings(pFromStmt, pToStmt);
}
#endif
/*
** Return the sqlite3* database handle to which the prepared statement given
@@ -1283,3 +1297,13 @@ sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){
sqlite3_mutex_leave(pDb->mutex);
return pNext;
}
/*
** Return the value of a status counter for a prepared statement
*/
int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
Vdbe *pVdbe = (Vdbe*)pStmt;
int v = pVdbe->aCounter[op-1];
if( resetFlag ) pVdbe->aCounter[op-1] = 0;
return v;
}
+69 -85
View File
@@ -14,7 +14,7 @@
** to version 2.8.7, all this code was combined into the vdbe.c source file.
** But that file was getting too big so this subroutines were split out.
**
** $Id: vdbeaux.c,v 1.411 2008/09/19 18:32:27 danielk1977 Exp $
** $Id: vdbeaux.c,v 1.420 2008/11/17 19:18:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -100,21 +100,23 @@ void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
#endif
/*
** Resize the Vdbe.aOp array so that it contains at least N
** elements.
** Resize the Vdbe.aOp array so that it is at least one op larger than
** it was.
**
** If an out-of-memory error occurs while resizing the array,
** Vdbe.aOp and Vdbe.nOpAlloc remain unchanged (this is so that
** any opcodes already allocated can be correctly deallocated
** along with the rest of the Vdbe).
** If an out-of-memory error occurs while resizing the array, return
** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain
** unchanged (this is so that any opcodes already allocated can be
** correctly deallocated along with the rest of the Vdbe).
*/
static void resizeOpArray(Vdbe *p, int N){
static int growOpArray(Vdbe *p){
VdbeOp *pNew;
pNew = sqlite3DbRealloc(p->db, p->aOp, N*sizeof(Op));
int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
if( pNew ){
p->nOpAlloc = N;
p->nOpAlloc = nNew;
p->aOp = pNew;
}
return (pNew ? SQLITE_OK : SQLITE_NOMEM);
}
/*
@@ -140,8 +142,7 @@ int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
i = p->nOp;
assert( p->magic==VDBE_MAGIC_INIT );
if( p->nOpAlloc<=i ){
resizeOpArray(p, p->nOpAlloc ? p->nOpAlloc*2 : 1024/sizeof(Op));
if( p->db->mallocFailed ){
if( growOpArray(p) ){
return 0;
}
}
@@ -267,6 +268,8 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
int *aLabel = p->aLabel;
int doesStatementRollback = 0;
int hasStatementBegin = 0;
p->readOnly = 1;
p->usesStmtJournal = 0;
for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
u8 opcode = pOp->opcode;
@@ -283,8 +286,11 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
}
}else if( opcode==OP_Statement ){
hasStatementBegin = 1;
p->usesStmtJournal = 1;
}else if( opcode==OP_Destroy ){
doesStatementRollback = 1;
}else if( opcode==OP_Transaction && pOp->p2!=0 ){
p->readOnly = 0;
#ifndef SQLITE_OMIT_VIRTUALTABLE
}else if( opcode==OP_VUpdate || opcode==OP_VRename ){
doesStatementRollback = 1;
@@ -313,6 +319,7 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
** which can be expensive on some platforms.
*/
if( hasStatementBegin && !doesStatementRollback ){
p->usesStmtJournal = 0;
for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
if( pOp->opcode==OP_Statement ){
pOp->opcode = OP_Noop;
@@ -336,11 +343,7 @@ int sqlite3VdbeCurrentAddr(Vdbe *p){
int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
int addr;
assert( p->magic==VDBE_MAGIC_INIT );
if( p->nOp + nOp > p->nOpAlloc ){
resizeOpArray(p, p->nOpAlloc ? p->nOpAlloc*2 : 1024/sizeof(Op));
assert( p->nOp+nOp<=p->nOpAlloc || p->db->mallocFailed );
}
if( p->db->mallocFailed ){
if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){
return 0;
}
addr = p->nOp;
@@ -725,7 +728,7 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){
void sqlite3VdbeUsesBtree(Vdbe *p, int i){
int mask;
assert( i>=0 && i<p->db->nDb );
assert( i<sizeof(p->btreeMask)*8 );
assert( i<(int)sizeof(p->btreeMask)*8 );
mask = 1<<i;
if( (p->btreeMask & mask)==0 ){
p->btreeMask |= mask;
@@ -1011,17 +1014,13 @@ void sqlite3VdbeMakeReady(
*/
assert( p->nOp>0 );
/* Set the magic to VDBE_MAGIC_RUN sooner rather than later. This
* is because the call to resizeOpArray() below may shrink the
* p->aOp[] array to save memory if called when in VDBE_MAGIC_RUN
* state.
*/
/* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */
p->magic = VDBE_MAGIC_RUN;
/* For each cursor required, also allocate a memory cell. Memory
** cells (nMem+1-nCursor)..nMem, inclusive, will never be used by
** the vdbe program. Instead they are used to allocate space for
** Cursor/BtCursor structures. The blob of memory associated with
** VdbeCursor/BtCursor structures. The blob of memory associated with
** cursor 0 is stored in memory cell nMem. Memory cell (nMem-1)
** stores the blob of memory associated with cursor 1, etc.
**
@@ -1035,17 +1034,16 @@ void sqlite3VdbeMakeReady(
if( p->aMem==0 ){
int nArg; /* Maximum number of args passed to a user function. */
resolveP2Values(p, &nArg);
/*resizeOpArray(p, p->nOp);*/
assert( nVar>=0 );
if( isExplain && nMem<10 ){
p->nMem = nMem = 10;
nMem = 10;
}
p->aMem = sqlite3DbMallocZero(db,
nMem*sizeof(Mem) /* aMem */
+ nVar*sizeof(Mem) /* aVar */
+ nArg*sizeof(Mem*) /* apArg */
+ nVar*sizeof(char*) /* azVar */
+ nCursor*sizeof(Cursor*) + 1 /* apCsr */
+ nCursor*sizeof(VdbeCursor*)+1 /* apCsr */
);
if( !db->mallocFailed ){
p->aMem--; /* aMem[] goes from 1..nMem */
@@ -1055,7 +1053,7 @@ void sqlite3VdbeMakeReady(
p->okVar = 0;
p->apArg = (Mem**)&p->aVar[nVar];
p->azVar = (char**)&p->apArg[nArg];
p->apCsr = (Cursor**)&p->azVar[nVar];
p->apCsr = (VdbeCursor**)&p->azVar[nVar];
p->nCursor = nCursor;
for(n=0; n<nVar; n++){
p->aVar[n].flags = MEM_Null;
@@ -1098,7 +1096,7 @@ void sqlite3VdbeMakeReady(
** Close a VDBE cursor and release all the resources that cursor
** happens to hold.
*/
void sqlite3VdbeFreeCursor(Vdbe *p, Cursor *pCx){
void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
if( pCx==0 ){
return;
}
@@ -1133,7 +1131,7 @@ static void closeAllCursorsExceptActiveVtabs(Vdbe *p){
int i;
if( p->apCsr==0 ) return;
for(i=0; i<p->nCursor; i++){
Cursor *pC = p->apCsr[i];
VdbeCursor *pC = p->apCsr[i];
if( pC && (!p->inVtabMethod || !pC->pVtabCursor) ){
sqlite3VdbeFreeCursor(p, pC);
p->apCsr[i] = 0;
@@ -1201,28 +1199,29 @@ void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){
**
** This call must be made after a call to sqlite3VdbeSetNumCols().
**
** If N==P4_STATIC it means that zName is a pointer to a constant static
** string and we can just copy the pointer. If it is P4_DYNAMIC, then
** the string is freed using sqlite3DbFree(db, ) when the vdbe is finished with
** it. Otherwise, N bytes of zName are copied.
** The final parameter, xDel, must be one of SQLITE_DYNAMIC, SQLITE_STATIC
** or SQLITE_TRANSIENT. If it is SQLITE_DYNAMIC, then the buffer pointed
** to by zName will be freed by sqlite3DbFree() when the vdbe is destroyed.
*/
int sqlite3VdbeSetColName(Vdbe *p, int idx, int var, const char *zName, int N){
int sqlite3VdbeSetColName(
Vdbe *p, /* Vdbe being configured */
int idx, /* Index of column zName applies to */
int var, /* One of the COLNAME_* constants */
const char *zName, /* Pointer to buffer containing name */
void (*xDel)(void*) /* Memory management strategy for zName */
){
int rc;
Mem *pColName;
assert( idx<p->nResColumn );
assert( var<COLNAME_N );
if( p->db->mallocFailed ) return SQLITE_NOMEM;
if( p->db->mallocFailed ){
assert( !zName || xDel!=SQLITE_DYNAMIC );
return SQLITE_NOMEM;
}
assert( p->aColName!=0 );
pColName = &(p->aColName[idx+var*p->nResColumn]);
if( N==P4_DYNAMIC || N==P4_STATIC ){
rc = sqlite3VdbeMemSetStr(pColName, zName, -1, SQLITE_UTF8, SQLITE_STATIC);
}else{
rc = sqlite3VdbeMemSetStr(pColName, zName, N, SQLITE_UTF8,SQLITE_TRANSIENT);
}
if( rc==SQLITE_OK && N==P4_DYNAMIC ){
pColName->flags &= (~MEM_Static);
pColName->zMalloc = pColName->z;
}
rc = sqlite3VdbeMemSetStr(pColName, zName, -1, SQLITE_UTF8, xDel);
assert( rc!=0 || !zName || (pColName->flags&MEM_Term)!=0 );
return rc;
}
@@ -1453,14 +1452,17 @@ static int vdbeCommit(sqlite3 *db, Vdbe *p){
static void checkActiveVdbeCnt(sqlite3 *db){
Vdbe *p;
int cnt = 0;
int nWrite = 0;
p = db->pVdbe;
while( p ){
if( p->magic==VDBE_MAGIC_RUN && p->pc>=0 ){
cnt++;
if( p->readOnly==0 ) nWrite++;
}
p = p->pNext;
}
assert( cnt==db->activeVdbeCnt );
assert( nWrite==db->writeVdbeCnt );
}
#else
#define checkActiveVdbeCnt(x)
@@ -1548,42 +1550,15 @@ int sqlite3VdbeHalt(Vdbe *p){
isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR
|| mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL;
if( isSpecialError ){
/* This loop does static analysis of the query to see which of the
** following three categories it falls into:
**
** Read-only
** Query with statement journal
** Query without statement journal
**
** We could do something more elegant than this static analysis (i.e.
** store the type of query as part of the compliation phase), but
** handling malloc() or IO failure is a fairly obscure edge case so
** this is probably easier. Todo: Might be an opportunity to reduce
** code size a very small amount though...
*/
int notReadOnly = 0;
int isStatement = 0;
assert(p->aOp || p->nOp==0);
for(i=0; i<p->nOp; i++){
switch( p->aOp[i].opcode ){
case OP_Transaction:
notReadOnly |= p->aOp[i].p2;
break;
case OP_Statement:
isStatement = 1;
break;
}
}
/* If the query was read-only, we need do no rollback at all. Otherwise,
** proceed with the special handling.
*/
if( notReadOnly || mrc!=SQLITE_INTERRUPT ){
if( p->rc==SQLITE_IOERR_BLOCKED && isStatement ){
if( !p->readOnly || mrc!=SQLITE_INTERRUPT ){
if( p->rc==SQLITE_IOERR_BLOCKED && p->usesStmtJournal ){
xFunc = sqlite3BtreeRollbackStmt;
p->rc = SQLITE_BUSY;
} else if( (mrc==SQLITE_NOMEM || mrc==SQLITE_FULL) && isStatement ){
}else if( (mrc==SQLITE_NOMEM || mrc==SQLITE_FULL)
&& p->usesStmtJournal ){
xFunc = sqlite3BtreeRollbackStmt;
}else{
/* We are forced to roll back the active transaction. Before doing
@@ -1600,9 +1575,12 @@ int sqlite3VdbeHalt(Vdbe *p){
** we do either a commit or rollback of the current transaction.
**
** Note: This block also runs if one of the special errors handled
** above has occured.
** above has occurred.
*/
if( db->autoCommit && db->activeVdbeCnt==1 ){
if( !sqlite3VtabInSync(db)
&& db->autoCommit
&& db->writeVdbeCnt==(p->readOnly==0)
){
if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
/* The auto-commit flag is true, and the vdbe program was
** successful or hit an 'OR FAIL' constraint. This means a commit
@@ -1682,6 +1660,10 @@ int sqlite3VdbeHalt(Vdbe *p){
/* We have successfully halted and closed the VM. Record this fact. */
if( p->pc>=0 ){
db->activeVdbeCnt--;
if( !p->readOnly ){
db->writeVdbeCnt--;
}
assert( db->activeVdbeCnt>=db->writeVdbeCnt );
}
p->magic = VDBE_MAGIC_HALT;
checkActiveVdbeCnt(db);
@@ -1731,7 +1713,9 @@ int sqlite3VdbeReset(Vdbe *p){
*/
if( p->pc>=0 ){
if( p->zErrMsg ){
sqlite3BeginBenignMalloc();
sqlite3ValueSetStr(db->pErr,-1,p->zErrMsg,SQLITE_UTF8,SQLITE_TRANSIENT);
sqlite3EndBenignMalloc();
db->errCode = p->rc;
sqlite3DbFree(db, p->zErrMsg);
p->zErrMsg = 0;
@@ -1863,7 +1847,7 @@ void sqlite3VdbeDelete(Vdbe *p){
** MoveTo now. Return an error code. If no MoveTo is pending, this
** routine does nothing and returns SQLITE_OK.
*/
int sqlite3VdbeCursorMoveto(Cursor *p){
int sqlite3VdbeCursorMoveto(VdbeCursor *p){
if( p->deferredMoveto ){
int res, rc;
#ifdef SQLITE_TEST
@@ -1966,7 +1950,7 @@ u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){
if( flags&MEM_Real ){
return 7;
}
assert( flags&(MEM_Str|MEM_Blob) );
assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
n = pMem->n;
if( flags & MEM_Zero ){
n += pMem->u.i;
@@ -2223,8 +2207,8 @@ UnpackedRecord *sqlite3VdbeRecordUnpack(
){
const unsigned char *aKey = (const unsigned char *)pKey;
UnpackedRecord *p;
int nByte;
int idx, d;
int nByte, d;
u32 idx;
u16 u; /* Unsigned loop counter */
u32 szHdr;
Mem *pMem;
@@ -2248,7 +2232,7 @@ UnpackedRecord *sqlite3VdbeRecordUnpack(
while( idx<szHdr && u<p->nField ){
u32 serial_type;
idx += getVarint32( aKey+idx, serial_type);
idx += getVarint32(&aKey[idx], serial_type);
if( d>=nKey && sqlite3VdbeSerialTypeLen(serial_type)>0 ) break;
pMem->enc = pKeyInfo->enc;
pMem->db = pKeyInfo->db;
@@ -2313,7 +2297,7 @@ int sqlite3VdbeRecordCompare(
int nKey1, const void *pKey1, /* Left key */
UnpackedRecord *pPKey2 /* Right key */
){
u32 d1; /* Offset into aKey[] of next data element */
int d1; /* Offset into aKey[] of next data element */
u32 idx1; /* Offset into aKey[] of next header element */
u32 szHdr1; /* Number of bytes in header */
int i = 0;
@@ -2430,7 +2414,7 @@ int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){
** supplied it is used in place of pKey,nKey.
*/
int sqlite3VdbeIdxKeyCompare(
Cursor *pC, /* The cursor to compare against */
VdbeCursor *pC, /* The cursor to compare against */
UnpackedRecord *pUnpacked, /* Unpacked version of pKey and nKey */
int *res /* Write the comparison result here */
){
+10 -10
View File
@@ -12,7 +12,7 @@
**
** This file contains code used to implement incremental BLOB I/O.
**
** $Id: vdbeblob.c,v 1.25 2008/07/28 19:34:54 drh Exp $
** $Id: vdbeblob.c,v 1.26 2008/10/02 14:49:02 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -287,17 +287,17 @@ static int blobReadWrite(
Vdbe *v;
sqlite3 *db = p->db;
/* Request is out of range. Return a transient error. */
if( (iOffset+n)>p->nByte ){
return SQLITE_ERROR;
}
sqlite3_mutex_enter(db->mutex);
/* If there is no statement handle, then the blob-handle has
** already been invalidated. Return SQLITE_ABORT in this case.
*/
v = (Vdbe*)p->pStmt;
if( v==0 ){
if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
/* Request is out of range. Return a transient error. */
rc = SQLITE_ERROR;
sqlite3Error(db, SQLITE_ERROR, 0);
} else if( v==0 ){
/* If there is no statement handle, then the blob-handle has
** already been invalidated. Return SQLITE_ABORT in this case.
*/
rc = SQLITE_ABORT;
}else{
/* Call either BtreeData() or BtreePutData(). If SQLITE_ABORT is
+3 -3
View File
@@ -12,7 +12,7 @@
** This file implements a FIFO queue of rowids used for processing
** UPDATE and DELETE statements.
**
** $Id: vdbefifo.c,v 1.8 2008/07/28 19:34:54 drh Exp $
** $Id: vdbefifo.c,v 1.9 2008/11/17 19:18:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@@ -24,9 +24,9 @@
*/
#define FIFOSIZE_FIRST (((128-sizeof(FifoPage))/8)+1)
#ifdef SQLITE_MALLOC_SOFT_LIMIT
# define FIFOSIZE_MAX (((SQLITE_MALLOC_SOFT_LIMIT-sizeof(FifoPage))/8)+1)
# define FIFOSIZE_MAX (int)(((SQLITE_MALLOC_SOFT_LIMIT-sizeof(FifoPage))/8)+1)
#else
# define FIFOSIZE_MAX (((262144-sizeof(FifoPage))/8)+1)
# define FIFOSIZE_MAX (int)(((262144-sizeof(FifoPage))/8)+1)
#endif
/*
+13 -8
View File
@@ -15,7 +15,7 @@
** only within the VDBE. Interface routines refer to a Mem using the
** name sqlite_value
**
** $Id: vdbemem.c,v 1.123 2008/09/16 12:06:08 danielk1977 Exp $
** $Id: vdbemem.c,v 1.126 2008/11/11 00:21:30 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -86,9 +86,6 @@ int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){
if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
if( preserve && pMem->z==pMem->zMalloc ){
pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
if( !pMem->z ){
pMem->flags = MEM_Null;
}
preserve = 0;
}else{
sqlite3DbFree(pMem->db, pMem->zMalloc);
@@ -104,7 +101,11 @@ int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){
}
pMem->z = pMem->zMalloc;
pMem->flags &= ~(MEM_Ephem|MEM_Static);
if( pMem->z==0 ){
pMem->flags = MEM_Null;
}else{
pMem->flags &= ~(MEM_Ephem|MEM_Static);
}
pMem->xDel = 0;
return (pMem->z ? SQLITE_OK : SQLITE_NOMEM);
}
@@ -606,9 +607,6 @@ int sqlite3VdbeMemSetStr(
}
flags |= MEM_Term;
}
if( nByte>iLimit ){
return SQLITE_TOOBIG;
}
/* The following block sets the new values of Mem.z and Mem.xDel. It
** also sets a flag in local variable "flags" to indicate the memory
@@ -619,6 +617,9 @@ int sqlite3VdbeMemSetStr(
if( flags&MEM_Term ){
nAlloc += (enc==SQLITE_UTF8?1:2);
}
if( nByte>iLimit ){
return SQLITE_TOOBIG;
}
if( sqlite3VdbeMemGrow(pMem, nAlloc, 0) ){
return SQLITE_NOMEM;
}
@@ -633,6 +634,9 @@ int sqlite3VdbeMemSetStr(
pMem->xDel = xDel;
flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
}
if( nByte>iLimit ){
return SQLITE_TOOBIG;
}
pMem->n = nByte;
pMem->flags = flags;
@@ -985,6 +989,7 @@ int sqlite3ValueFromExpr(
assert( pExpr->token.z[1]=='\'' );
assert( pExpr->token.z[pExpr->token.n-1]=='\'' );
pVal = sqlite3ValueNew(db);
if( !pVal ) goto no_mem;
nVal = pExpr->token.n - 3;
zVal = (char*)pExpr->token.z + 2;
sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
+4 -2
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to help implement virtual tables.
**
** $Id: vtab.c,v 1.76 2008/08/20 16:35:10 drh Exp $
** $Id: vtab.c,v 1.78 2008/11/13 19:12:36 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h"
@@ -46,6 +46,8 @@ static int createModule(
db->mallocFailed = 1;
}
sqlite3ResetInternalSchema(db, 0);
}else if( xDestroy ){
xDestroy(pAux);
}
rc = sqlite3ApiExit(db, SQLITE_OK);
sqlite3_mutex_leave(db->mutex);
@@ -710,7 +712,7 @@ int sqlite3VtabBegin(sqlite3 *db, sqlite3_vtab *pVtab){
** virtual module xSync() callback. It is illegal to write to
** virtual module tables in this case, so return SQLITE_LOCKED.
*/
if( 0==db->aVTrans && db->nVTrans>0 ){
if( sqlite3VtabInSync(db) ){
return SQLITE_LOCKED;
}
if( !pVtab ){
+131 -91
View File
@@ -16,15 +16,10 @@
** 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.322 2008/09/06 14:19:11 danielk1977 Exp $
** $Id: where.c,v 1.330 2008/11/17 19:18:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
/*
** The number of bits in a Bitmask. "BMS" means "BitMask Size".
*/
#define BMS (sizeof(Bitmask)*8)
/*
** Trace output macros
*/
@@ -139,7 +134,7 @@ struct WhereClause {
*/
struct ExprMaskSet {
int n; /* Number of assigned cursor values */
int ix[sizeof(Bitmask)*8]; /* Cursor assigned to each bit */
int ix[BMS]; /* Cursor assigned to each bit */
};
@@ -1473,6 +1468,16 @@ static double bestVirtualIndex(
** * Whether or not there must be separate lookups in the
** index and in the main table.
**
** If there was an INDEXED BY clause attached to the table in the SELECT
** statement, then this function only considers strategies using the
** named index. If one cannot be found, then the returned cost is
** SQLITE_BIG_DBL. If a strategy can be found that uses the named index,
** then the cost is calculated in the usual way.
**
** If a NOT INDEXED clause was attached to the table in the SELECT
** statement, then no indexes are considered. However, the selected
** stategy may still take advantage of the tables built-in rowid
** index.
*/
static double bestIndex(
Parse *pParse, /* The parsing context */
@@ -1500,6 +1505,9 @@ static double bestIndex(
WHERETRACE(("bestIndex: tbl=%s notReady=%llx\n", pSrc->pTab->zName, notReady));
lowestCost = SQLITE_BIG_DBL;
pProbe = pSrc->pTab->pIndex;
if( pSrc->notIndexed ){
pProbe = 0;
}
/* If the table has no indices and there are no terms in the where
** clause that refer to the ROWID, then we will never be able to do
@@ -1516,74 +1524,77 @@ static double bestIndex(
return 0.0;
}
/* Check for a rowid=EXPR or rowid IN (...) constraints
/* Check for a rowid=EXPR or rowid IN (...) constraints. If there was
** an INDEXED BY clause attached to this table, skip this step.
*/
pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
if( pTerm ){
Expr *pExpr;
*ppIndex = 0;
bestFlags = WHERE_ROWID_EQ;
if( pTerm->eOperator & WO_EQ ){
/* Rowid== is always the best pick. Look no further. Because only
** a single row is generated, output is always in sorted order */
*pFlags = WHERE_ROWID_EQ | WHERE_UNIQUE;
*pnEq = 1;
WHERETRACE(("... best is rowid\n"));
return 0.0;
}else if( (pExpr = pTerm->pExpr)->pList!=0 ){
/* Rowid IN (LIST): cost is NlogN where N is the number of list
** elements. */
lowestCost = pExpr->pList->nExpr;
lowestCost *= estLog(lowestCost);
}else{
/* Rowid IN (SELECT): cost is NlogN where N is the number of rows
** in the result of the inner select. We have no way to estimate
** that value so make a wild guess. */
lowestCost = 200;
}
WHERETRACE(("... rowid IN cost: %.9g\n", lowestCost));
}
/* Estimate the cost of a table scan. If we do not know how many
** entries are in the table, use 1 million as a guess.
*/
cost = pProbe ? pProbe->aiRowEst[0] : 1000000;
WHERETRACE(("... table scan base cost: %.9g\n", cost));
flags = WHERE_ROWID_RANGE;
/* Check for constraints on a range of rowids in a table scan.
*/
pTerm = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE|WO_GT|WO_GE, 0);
if( pTerm ){
if( findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0) ){
flags |= WHERE_TOP_LIMIT;
cost /= 3; /* Guess that rowid<EXPR eliminates two-thirds or rows */
}
if( findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0) ){
flags |= WHERE_BTM_LIMIT;
cost /= 3; /* Guess that rowid>EXPR eliminates two-thirds of rows */
}
WHERETRACE(("... rowid range reduces cost to %.9g\n", cost));
}else{
flags = 0;
}
/* If the table scan does not satisfy the ORDER BY clause, increase
** the cost by NlogN to cover the expense of sorting. */
if( pOrderBy ){
if( sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev) ){
flags |= WHERE_ORDERBY|WHERE_ROWID_RANGE;
if( rev ){
flags |= WHERE_REVERSE;
if( !pSrc->pIndex ){
pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
if( pTerm ){
Expr *pExpr;
*ppIndex = 0;
bestFlags = WHERE_ROWID_EQ;
if( pTerm->eOperator & WO_EQ ){
/* Rowid== is always the best pick. Look no further. Because only
** a single row is generated, output is always in sorted order */
*pFlags = WHERE_ROWID_EQ | WHERE_UNIQUE;
*pnEq = 1;
WHERETRACE(("... best is rowid\n"));
return 0.0;
}else if( (pExpr = pTerm->pExpr)->pList!=0 ){
/* Rowid IN (LIST): cost is NlogN where N is the number of list
** elements. */
lowestCost = pExpr->pList->nExpr;
lowestCost *= estLog(lowestCost);
}else{
/* Rowid IN (SELECT): cost is NlogN where N is the number of rows
** in the result of the inner select. We have no way to estimate
** that value so make a wild guess. */
lowestCost = 200;
}
}else{
cost += cost*estLog(cost);
WHERETRACE(("... sorting increases cost to %.9g\n", cost));
WHERETRACE(("... rowid IN cost: %.9g\n", lowestCost));
}
/* Estimate the cost of a table scan. If we do not know how many
** entries are in the table, use 1 million as a guess.
*/
cost = pProbe ? pProbe->aiRowEst[0] : 1000000;
WHERETRACE(("... table scan base cost: %.9g\n", cost));
flags = WHERE_ROWID_RANGE;
/* Check for constraints on a range of rowids in a table scan.
*/
pTerm = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE|WO_GT|WO_GE, 0);
if( pTerm ){
if( findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0) ){
flags |= WHERE_TOP_LIMIT;
cost /= 3; /* Guess that rowid<EXPR eliminates two-thirds or rows */
}
if( findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0) ){
flags |= WHERE_BTM_LIMIT;
cost /= 3; /* Guess that rowid>EXPR eliminates two-thirds of rows */
}
WHERETRACE(("... rowid range reduces cost to %.9g\n", cost));
}else{
flags = 0;
}
/* If the table scan does not satisfy the ORDER BY clause, increase
** the cost by NlogN to cover the expense of sorting. */
if( pOrderBy ){
if( sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev) ){
flags |= WHERE_ORDERBY|WHERE_ROWID_RANGE;
if( rev ){
flags |= WHERE_REVERSE;
}
}else{
cost += cost*estLog(cost);
WHERETRACE(("... sorting increases cost to %.9g\n", cost));
}
}
if( cost<lowestCost ){
lowestCost = cost;
bestFlags = flags;
}
}
if( cost<lowestCost ){
lowestCost = cost;
bestFlags = flags;
}
/* If the pSrc table is the right table of a LEFT JOIN then we may not
@@ -1599,7 +1610,10 @@ static double bestIndex(
/* Look at each index.
*/
for(; pProbe; pProbe=pProbe->pNext){
if( pSrc->pIndex ){
pProbe = pSrc->pIndex;
}
for(; pProbe; pProbe=(pSrc->pIndex ? 0 : pProbe->pNext)){
int i; /* Loop counter */
double inMultiplier = 1;
@@ -1784,9 +1798,7 @@ static int codeEqualityTerm(
Vdbe *v = pParse->pVdbe;
int iReg; /* Register holding results */
if( iTarget<=0 ){
iReg = iTarget = sqlite3GetTempReg(pParse);
}
assert( iTarget>0 );
if( pX->op==TK_EQ ){
iReg = sqlite3ExprCodeTarget(pParse, pX->pRight, iTarget);
}else if( pX->op==TK_ISNULL ){
@@ -1914,10 +1926,9 @@ static int nQPlan = 0; /* Next free slow in _query_plan[] */
/*
** Free a WhereInfo structure
*/
static void whereInfoFree(WhereInfo *pWInfo){
static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
if( pWInfo ){
int i;
sqlite3 *db = pWInfo->pParse->db;
for(i=0; i<pWInfo->nLevel; i++){
sqlite3_index_info *pInfo = pWInfo->a[i].pIdxInfo;
if( pInfo ){
@@ -2067,7 +2078,7 @@ WhereInfo *sqlite3WhereBegin(
pWInfo = sqlite3DbMallocZero(db,
sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel));
if( db->mallocFailed ){
goto whereBeginNoMem;
goto whereBeginError;
}
pWInfo->nLevel = pTabList->nSrc;
pWInfo->pParse = pParse;
@@ -2114,7 +2125,7 @@ WhereInfo *sqlite3WhereBegin(
*/
exprAnalyzeAll(pTabList, &wc);
if( db->mallocFailed ){
goto whereBeginNoMem;
goto whereBeginError;
}
/* Chose the best index to use for each table in the FROM clause.
@@ -2124,7 +2135,7 @@ WhereInfo *sqlite3WhereBegin(
** pWInfo->a[].pIdx The index to use for this level of the loop.
** pWInfo->a[].flags WHERE_xxx flags associated with pIdx
** pWInfo->a[].nEq The number of == and IN constraints
** pWInfo->a[].iFrom When term of the FROM clause is being coded
** pWInfo->a[].iFrom Which term of the FROM clause is being coded
** pWInfo->a[].iTabCur The VDBE cursor for the database table
** pWInfo->a[].iIdxCur The VDBE cursor for the index
**
@@ -2221,6 +2232,18 @@ WhereInfo *sqlite3WhereBegin(
}
notReady &= ~getMask(&maskSet, pTabList->a[bestJ].iCursor);
pLevel->iFrom = bestJ;
/* Check that if the table scanned by this loop iteration had an
** INDEXED BY clause attached to it, that the named index is being
** used for the scan. If not, then query compilation has failed.
** Return an error.
*/
pIdx = pTabList->a[bestJ].pIndex;
assert( !pIdx || !pBest || pIdx==pBest );
if( pIdx && pBest!=pIdx ){
sqlite3ErrorMsg(pParse, "cannot use index: %s", pIdx->zName);
goto whereBeginError;
}
}
WHERETRACE(("*** Optimizer Finished ***\n"));
@@ -2292,7 +2315,7 @@ WhereInfo *sqlite3WhereBegin(
if( (pLevel->flags & WHERE_IDX_ONLY)==0 ){
int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
if( !pWInfo->okOnePass && pTab->nCol<(sizeof(Bitmask)*8) ){
if( !pWInfo->okOnePass && pTab->nCol<BMS ){
Bitmask b = pTabItem->colUsed;
int n = 0;
for(; b; b=b>>1, n++){}
@@ -2321,7 +2344,7 @@ WhereInfo *sqlite3WhereBegin(
*/
notReady = ~(Bitmask)0;
for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
int j;
int j, k;
int iCur = pTabItem->iCursor; /* The VDBE cursor for the table */
Index *pIdx; /* The index we will be using */
int nxt; /* Where to jump to continue with the next IN case */
@@ -2414,16 +2437,17 @@ WhereInfo *sqlite3WhereBegin(
** construct.
*/
int r1;
int rtmp = sqlite3GetTempReg(pParse);
pTerm = findTerm(&wc, iCur, -1, notReady, WO_EQ|WO_IN, 0);
assert( pTerm!=0 );
assert( pTerm->pExpr!=0 );
assert( pTerm->leftCursor==iCur );
assert( omitTable==0 );
r1 = codeEqualityTerm(pParse, pTerm, pLevel, 0);
r1 = codeEqualityTerm(pParse, pTerm, pLevel, rtmp);
nxt = pLevel->nxt;
sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, nxt);
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, nxt, r1);
sqlite3ReleaseTempReg(pParse, r1);
sqlite3ReleaseTempReg(pParse, rtmp);
VdbeComment((v, "pk"));
pLevel->op = OP_Noop;
}else if( pLevel->flags & WHERE_ROWID_RANGE ){
@@ -2443,16 +2467,26 @@ WhereInfo *sqlite3WhereBegin(
}
if( pStart ){
Expr *pX;
int r1, regFree1;
int r1;
pX = pStart->pExpr;
assert( pX!=0 );
assert( pStart->leftCursor==iCur );
r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &regFree1);
/* The ForceInt instruction may modify the register that it operates
** on. For example it may replace a real value with an integer one,
** or if p3 is true it may increment the register value. For this
** reason we need to make sure that register r1 is really a newly
** allocated temporary register, and not part of the column-cache.
** For this reason we cannot use sqlite3ExprCodeTemp() here.
*/
r1 = sqlite3GetTempReg(pParse);
sqlite3ExprCode(pParse, pX->pRight, r1);
sqlite3VdbeAddOp3(v, OP_ForceInt, r1, brk,
pX->op==TK_LE || pX->op==TK_GT);
sqlite3VdbeAddOp3(v, bRev ? OP_MoveLt : OP_MoveGe, iCur, brk, r1);
VdbeComment((v, "pk"));
sqlite3ReleaseTempReg(pParse, regFree1);
sqlite3ReleaseTempReg(pParse, r1);
disableTerm(pLevel, pStart);
}else{
sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, brk);
@@ -2680,12 +2714,14 @@ WhereInfo *sqlite3WhereBegin(
pLevel->op = OP_Next;
pLevel->p1 = iCur;
pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, OP_Rewind, iCur, brk);
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
}
notReady &= ~getMask(&maskSet, iCur);
/* Insert code to test every subexpression that can be completely
** computed using the current set of tables.
*/
k = 0;
for(pTerm=wc.a, j=wc.nTerm; j>0; j--, pTerm++){
Expr *pE;
testcase( pTerm->flags & TERM_VIRTUAL );
@@ -2697,7 +2733,10 @@ WhereInfo *sqlite3WhereBegin(
if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
continue;
}
pParse->disableColCache += k;
sqlite3ExprIfFalse(pParse, pE, cont, SQLITE_JUMPIFNULL);
pParse->disableColCache -= k;
k = 1;
pTerm->flags |= TERM_CODED;
}
@@ -2779,9 +2818,9 @@ WhereInfo *sqlite3WhereBegin(
return pWInfo;
/* Jump here if malloc fails */
whereBeginNoMem:
whereBeginError:
whereClauseClear(&wc);
whereInfoFree(pWInfo);
whereInfoFree(db, pWInfo);
return 0;
}
@@ -2805,6 +2844,7 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
sqlite3VdbeResolveLabel(v, pLevel->cont);
if( pLevel->op!=OP_Noop ){
sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
sqlite3VdbeChangeP5(v, pLevel->p5);
}
if( pLevel->nIn ){
struct InLoop *pIn;
@@ -2894,6 +2934,6 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
/* Final cleanup
*/
whereInfoFree(pWInfo);
whereInfoFree(db, pWInfo);
return;
}
+7 -8
View File
@@ -13,7 +13,7 @@
# focus of this script is correct code generation of aliased result-set
# values. See ticket #3343.
#
# $Id: alias.test,v 1.1 2008/08/29 02:14:03 drh Exp $
# $Id: alias.test,v 1.2 2008/10/25 15:03:21 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -47,7 +47,6 @@ do_test alias-1.1 {
do_test alias-1.2 {
::seq::reset
db eval {
--pragma vdbe_listing=on; pragma vdbe_trace=on;
SELECT x, sequence() AS y FROM t1 WHERE y>0
}
} {9 1 8 2 7 3}
@@ -77,12 +76,12 @@ do_test alias-1.6 {
SELECT x, sequence() AS y FROM t1 WHERE y BETWEEN 0 AND 99
}
} {9 1 8 2 7 3}
do_test alias-1.7 {
::seq::reset
db eval {
SELECT x, sequence() AS y FROM t1 WHERE y IN (55,66,3)
}
} {7 3}
#do_test alias-1.7 {
# ::seq::reset
# db eval {
# SELECT x, sequence() AS y FROM t1 WHERE y IN (55,66,3)
# }
#} {7 3}
do_test alias-1.8 {
::seq::reset
db eval {
+3 -2
View File
@@ -10,13 +10,14 @@
#***********************************************************************
# This file runs all tests.
#
# $Id: all.test,v 1.58 2008/09/09 18:28:07 danielk1977 Exp $
# $Id: all.test,v 1.59 2008/10/13 14:16:11 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
rename finish_test really_finish_test
proc finish_test {} {
# no-op
catch {db close}
show_memstats
}
if {[file exists ./sqlite_test_count]} {
+2 -1
View File
@@ -12,7 +12,7 @@
# focus of this script is testing the ALTER TABLE statement and
# specifically out-of-memory conditions within that command.
#
# $Id: altermalloc.test,v 1.9 2008/08/04 20:13:27 drh Exp $
# $Id: altermalloc.test,v 1.10 2008/10/30 17:21:13 danielk1977 Exp $
#
set testdir [file dirname $argv0]
@@ -39,6 +39,7 @@ do_malloc_test altermalloc-1 -tclprep {
ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL;
ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text';
ALTER TABLE t1 RENAME TO t2;
ALTER TABLE t2 ADD COLUMN d BLOB DEFAULT X'ABCD';
}
# Test malloc() failure on an ALTER TABLE on a virtual table.
+15 -1
View File
@@ -12,7 +12,7 @@
# focus of this script is testing the ATTACH statement and
# specifically out-of-memory conditions within that command.
#
# $Id: attachmalloc.test,v 1.9 2008/08/04 20:13:27 drh Exp $
# $Id: attachmalloc.test,v 1.10 2008/10/22 10:45:38 danielk1977 Exp $
#
set testdir [file dirname $argv0]
@@ -46,4 +46,18 @@ do_malloc_test attachmalloc-1 -tclprep {
CREATE TABLE four.t1(x);
}
do_malloc_test attachmalloc-2 -tclprep {
file delete -force test2.db
file delete -force test2.db-journal
sqlite3 db2 test2.db
db2 eval {
CREATE TABLE t1(a, b, c);
CREATE INDEX i1 ON t1(a, b);
}
db2 close
} -sqlbody {
CREATE TABLE t1(d, e, f);
ATTACH 'test2.db' AS db1;
}
finish_test
+5 -2
View File
@@ -12,7 +12,7 @@
# focus of this script is testing the sqlite3_set_authorizer() API
# and related functionality.
#
# $Id: auth.test,v 1.43 2008/07/02 13:13:52 danielk1977 Exp $
# $Id: auth.test,v 1.44 2008/10/27 15:34:33 danielk1977 Exp $
#
set testdir [file dirname $argv0]
@@ -418,7 +418,10 @@ do_test auth-1.49 {
} {0 {}}
do_test auth-1.50 {
execsql {SELECT * FROM t2}
} {11 2 33}
} {}
do_test auth-1.50.2 {
execsql {INSERT INTO t2 VALUES(11, 2, 33)}
} {}
do_test auth-1.51 {
proc auth {code arg1 arg2 arg3 arg4} {
+111
View File
@@ -0,0 +1,111 @@
# 2008 October 27
#
# 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.
#
#***********************************************************************
#
# Test that the truncate optimization is disabled if the SQLITE_DELETE
# authorization callback returns SQLITE_IGNORE.
#
# $Id: auth3.test,v 1.1 2008/10/27 15:34:33 danielk1977 Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
# defined during compilation.
if {[catch {db auth {}} msg]} {
finish_test
return
}
# Disable the statement cache for these tests.
#
db cache size 0
db authorizer ::auth
proc auth {code arg1 arg2 arg3 arg4} {
if {$code=="SQLITE_DELETE"} {
return $::authcode
}
return SQLITE_OK
}
#--------------------------------------------------------------------------
# The following tests - auth3-1.* - test that return values of SQLITE_DENY,
# SQLITE_IGNORE, SQLITE_OK and <invalid> are correctly handled when returned
# by an SQLITE_DELETE authorization callback triggered by a
# "DELETE FROM <table-name>" statement.
#
do_test auth3-1.1 {
execsql {
CREATE TABLE t1(a,b,c);
INSERT INTO t1 VALUES(1, 2, 3);
INSERT INTO t1 VALUES(4, 5, 6);
}
} {}
do_test auth3.1.2 {
set ::authcode SQLITE_DENY
catchsql { DELETE FROM t1 }
} {1 {not authorized}}
do_test auth3.1.3 {
set ::authcode SQLITE_INVALID
catchsql { DELETE FROM t1 }
} {1 {illegal return value (1) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
do_test auth3.1.4 {
execsql { SELECT * FROM t1 }
} {1 2 3 4 5 6}
do_test auth3-1.5 {
set ::authcode SQLITE_IGNORE
execsql {
DELETE FROM t1;
SELECT * FROM t1;
}
} {}
do_test auth3-1.6 {
set ::authcode SQLITE_OK
execsql {
INSERT INTO t1 VALUES(1, 2, 3);
INSERT INTO t1 VALUES(4, 5, 6);
DELETE FROM t1;
SELECT * FROM t1;
}
} {}
#--------------------------------------------------------------------------
# These tests - auth3-2.* - test that returning SQLITE_IGNORE really does
# disable the truncate optimization.
#
do_test auth3-2.1 {
set ::authcode SQLITE_OK
execsql {
INSERT INTO t1 VALUES(1, 2, 3);
INSERT INTO t1 VALUES(4, 5, 6);
}
set sqlite_search_count 0
execsql {
DELETE FROM t1;
}
set sqlite_search_count
} {0}
do_test auth3-2.2 {
set ::authcode SQLITE_IGNORE
execsql {
INSERT INTO t1 VALUES(1, 2, 3);
INSERT INTO t1 VALUES(4, 5, 6);
}
set sqlite_search_count 0
execsql {
DELETE FROM t1;
}
set sqlite_search_count
} {1}
finish_test

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