Compare commits

..

560 Commits

Author SHA1 Message Date
drh f3a5a57ddb Version 2.8.14 (CVS 1554)
FossilOrigin-Name: 7d3937743f88acad8859fbbbb1c03271a939bc0b
2004-06-09 23:20:05 +00:00
drh 1832890357 Update the version number to 2.8.14. For whatever reason, the version at
the tip of the 2.8 branch fixes ticket #757. (CVS 1552)

FossilOrigin-Name: 7538d2e5297bdeaf07c6d6e37053c654501ef286
2004-06-09 22:49:56 +00:00
drh 97117601d2 Calling sqlite_interrupt() while VACUUM is running should not cause an error. (CVS 1529)
FossilOrigin-Name: 1cf94a7c41b56506251a9964f133e179bd06825f
2004-06-04 19:07:53 +00:00
drh f9ec81c84d Improvements to testing of sqlite_interrupt. More checking for interrupt
inside of VACUUM. (CVS 1344)

FossilOrigin-Name: d596f513c3acfe0d297dc3f5c66f4b0ea2d12a34
2004-05-10 20:27:41 +00:00
drh 45041e263a Fix a memory leak in DETACH when using the codec. (CVS 1317)
FossilOrigin-Name: c4bd99b79c66217140781309ed06e1ff3ef4a206
2004-05-07 01:46:01 +00:00
drh 3e5c826219 Add the sqlite_temp_directory global variable which, if set, defines the
directory in which temporary files are created. (CVS 1316)

FossilOrigin-Name: c90ed20dc4f95eb06a5259578597593f5968bfb7
2004-05-07 00:57:06 +00:00
drh 4e0e4d7a9e Fix a stack overflow problem with INSTEAD OF triggers. (CVS 1310)
FossilOrigin-Name: 5a33e0b06f495628704d0881940a792f342facc7
2004-04-29 16:16:29 +00:00
drh 064cf76bb1 Changes to lemon.c so that it compiles on OpenWatcom 1.3. Ticket #665. (CVS 1307)
FossilOrigin-Name: b8b8ce5c81ef614d488e0f79df8935ef609dc4f2
2004-04-24 12:59:13 +00:00
drh a38518d673 Add some extra debugging logic to lemon.c. Ticket #692. (CVS 1304)
FossilOrigin-Name: 635f674d20ca3e0b534eba54313004e859de16e9
2004-04-23 23:37:56 +00:00
drh 1bdd9b5787 Get the temp_store and default_temp_store pragmas working. Update the
documentation.  Also fix a malloc problem that popped up during the regression
testing. (CVS 1302)

FossilOrigin-Name: 7ace576215367101904677bd69951755ee9cb1a1
2004-04-23 17:04:44 +00:00
rdc 932ee8f4bb Fix windows DLL section of Makefile.in for use with build dir. (CVS 1301)
FossilOrigin-Name: 1e84f70fb98755651e0c04dc2cf0114e2e6fe39c
2004-03-26 23:16:31 +00:00
drh d888544275 Change the ".database" command in the shell to allocate more characters to
the database name and filename. (CVS 1300)

FossilOrigin-Name: 85238f06902851dd5085395501a0ab2d6a2b9814
2004-03-17 23:42:12 +00:00
drh 8b8891bf0a Fix a VDBE stack overflow that occurs when the left-hand side of an IN
expression is NULL and the result is stored on the stack rather than used
to control a jump.  Ticket #668. (CVS 1299)

FossilOrigin-Name: fc7a7975b03c144c2db3566facd008d3701c735e
2004-03-17 23:32:08 +00:00
drh 276fd588d8 The sqlite_trace() API only works for commands started by the user, not for
SQL commands run during initialization. (CVS 1298)

FossilOrigin-Name: 0a12473c4ae370ec34f1f431dd6d7d6ffa25d41a
2004-03-17 18:44:45 +00:00
dougcurrie a8804c82b8 Makefile.in and sqlite.def changes for encode and non-toplevel build; ticket #667 (CVS 1297)
FossilOrigin-Name: 72205a371ce5be4eac0a77d5d2fa8ccb23bb988f
2004-03-16 21:49:49 +00:00
drh 6ff15d0c49 Prototypes for sqlite_encode_binary() and sqlite_decode_binary() added
to sqlite.h. (CVS 1296)

FossilOrigin-Name: 359f0e787ff2d4d10fd23059e2ce99670e93f66a
2004-03-14 22:12:34 +00:00
drh 6da834a8b4 Make sqlite_encode_binary() and sqlite_decode_binary() an official part of
the library. (CVS 1295)

FossilOrigin-Name: 786fe545560ec6c42bb0e344345031f425bf177a
2004-03-14 22:11:59 +00:00
drh 371cb93a2a Updates to the architecture document. (CVS 1294)
FossilOrigin-Name: c661cc81b6981c536c107f40525ad9783b11ea82
2004-03-14 11:57:58 +00:00
drh 6e17529e97 Fix the min/max optimizer so that it works when the FROM clause is a
subquery.  Ticket #658. (CVS 1293)

FossilOrigin-Name: 31c94acc72d318b5dec0fef1485621943add45c8
2004-03-13 14:00:36 +00:00
drh 1a72d72a7f Typecast to work around a bug in {quote: CodeWarrior} Studio v9.1.
Ticket #654. (CVS 1292)

FossilOrigin-Name: 5864fc6937b933b7da0c00e6c4c2ee1b9b939cff
2004-03-10 18:57:31 +00:00
a.rottmann 7972e32a9e Fixed default target. (CVS 1291)
FossilOrigin-Name: af19ab32c5b329b053f3daf3c812eb593b89cd7f
2004-03-10 18:53:09 +00:00
a.rottmann 66eb270d6b * Added rule for rebuilding Makefile from Makefile.in.
* Fixed double-slash problem induced by adding DESTDIR support. (CVS 1290)

FossilOrigin-Name: 957827e35cca65de11894eb2dfc78327f4034dfc
2004-03-10 16:32:03 +00:00
drh a0c9a112de The BTree layer now returns SQLITE_READONLY on an attempt to open a write
cursor on a read-only database.  Previously, the failure would not occur
until there was an attempt to write to the cursor. (CVS 1289)

FossilOrigin-Name: 8a8be4687bf9fd88952b303f30f93aa6fed75b60
2004-03-10 13:42:37 +00:00
drh 06333689a7 The shell program now ignores extra whitespace at the end of dot-commands. (CVS 1288)
FossilOrigin-Name: b6817e99bd97f427b1cfd16328d612e1a7d70d0a
2004-03-09 13:37:45 +00:00
drh a2cfd57491 Version 2.8.13 (CVS 1287)
FossilOrigin-Name: 4d5bbb3dc32412ee7fa5dec42d3278836a362e8c
2004-03-08 13:57:54 +00:00
drh e3f25eb91e Update change log for version 2.8.13. (CVS 1286)
FossilOrigin-Name: 4431e63746311d2e3429203656f8168c227ecb6e
2004-03-08 13:45:24 +00:00
drh 489c4677a0 Bump the version number to 2.8.13. Patch up the limit test so that it works
in spite of ticket #521 - we don't want any tests failing in an official
release even if there are bugs. :-D (CVS 1285)

FossilOrigin-Name: 2c6bd21ed0e212109cfb4a37cfac2a10ab58a024
2004-03-08 13:26:17 +00:00
rdc aa5707cd5e Correct duplicate tracing of SQL statements. (CVS 1284)
FossilOrigin-Name: bb67311b3db49ce772533da14f62497c55432fae
2004-03-04 19:09:20 +00:00
drh 79f14b7240 A vdbe stack element might have a string value even after a call to
Integerify().  Ticket #641. (CVS 1283)

FossilOrigin-Name: 3cac4b7b526d6c5dbf394009b534707bcb65b0da
2004-03-03 01:51:24 +00:00
drh b1aa04fccc Make sure a LIMIT clause on a SELECT cleans up the vdbe stack so that if it
occurs inside a trigger, it won't cause a stack overflow.  Ticket #640. (CVS 1282)

FossilOrigin-Name: 5aaa2939baa972231def086ed5f9d9ba63302532
2004-03-02 18:37:41 +00:00
a.rottmann 9bc8b93f41 Updated aclocal.m4 and configure. (CVS 1281)
FossilOrigin-Name: 76d42921a475c531a77677c3fe73b6da265a878d
2004-02-29 15:18:31 +00:00
drh 0d131ab716 One more fix to the new HH:MM:SS modifier. This time add some test
procedures too. (CVS 1280)

FossilOrigin-Name: 7b3b8968ee9a5349dd6e9ae1e7a311bf8906607c
2004-02-29 01:08:17 +00:00
drh b6829e94bd Try again to get the HH:MM:SS modifier change right... (CVS 1279)
FossilOrigin-Name: e20d51f94ed67b8864a435e5735f61f396662c21
2004-02-29 00:50:33 +00:00
drh 446536a089 Fix a bug in the HH:MM:SS modifier change that was just checked in. (CVS 1278)
FossilOrigin-Name: 248b5500900bc8f401006aaa9b7dac090ae419fa
2004-02-29 00:48:08 +00:00
drh 33a9ad2f8c Allow time modifiers of the form HH:MM:SS.SSS with an option "+" or "-"
prefix.  The specified amount of time is added into the date-time begin
modified. (CVS 1277)

FossilOrigin-Name: 559002a52fe3c42fe71ffce364eff4a036ae6b83
2004-02-29 00:40:32 +00:00
drh 3039c0a896 Fix some compiler warnings in LCC. The warnings did not indicate real
problems.  Ticket #634.  Not all warnings in ticket #634 were fixed. (CVS 1276)

FossilOrigin-Name: e97089b7df3e2fbfcf36062099d02ecb75e9a870
2004-02-29 00:11:30 +00:00
a.rottmann 1d78a38f51 Make Windows .dll build use the real .o files, not the libtool-faked .lo
ones. (CVS 1275)

FossilOrigin-Name: cce5bbf49b0a30c40d24a559bc6cb4585dd9aea5
2004-02-28 18:02:20 +00:00
a.rottmann 964dbb1e6c Build system update:
* Update of generated/libtoolized files: config.guess, config.sub,
   configure, ltmain.sh
* Removal of libtool, which is generated by configure
* Changes to Makefile.in, adding better support for newer libtools (CVS 1274)

FossilOrigin-Name: 22d63bbf78997f0b31bb39054fbcfccf9d974bd6
2004-02-26 19:47:42 +00:00
rdc f146a77677 Add comments and prototype for experimental sqlite_last_statement_changes() API function. Also, allow function to be called from tcl. (CVS 1273)
FossilOrigin-Name: ca99920b0dbf773962b47766d690154fd1276513
2004-02-25 22:51:06 +00:00
drh 268380ca9e Min() and max() functions honor the distinction between TEXT and NUMERIC
data.  Ticket #623.  typeof() is now a user function.  Some tests are
now failing due to ticket #521. (CVS 1272)

FossilOrigin-Name: adbe31adf1ad0ca723203ca3d7dc480324c60d43
2004-02-25 13:47:31 +00:00
drh d41d73d556 Fix the return type of sqliteRunVacuum. Ticket #627. (CVS 1271)
FossilOrigin-Name: 9c9f4a867a4ea708847cbb0839b7279eb33ecd7c
2004-02-25 02:33:34 +00:00
drh f73287ceb0 Shell program saves command-line history on a ".quit". Ticket #614. (CVS 1270)
FossilOrigin-Name: 114b72f8608b8e08fad863a1446fb1ef59610efd
2004-02-25 02:25:37 +00:00
drh 946966f2a1 Disable an assert which (as it turns out) is not always true. Ticket #615. (CVS 1269)
FossilOrigin-Name: 2773c1d384b750eee037e6ccc61bc56b5204d690
2004-02-25 02:20:41 +00:00
drh cd44690ad0 Refactor parts of write operations. (CVS 1268)
FossilOrigin-Name: 5b0147aece7785373e6f7439c32e5f58c6b12562
2004-02-24 01:05:31 +00:00
drh 02f75f19e5 Make sure BEGIN, COMMIT, and ROLLBACK are really no-ops when preceded
by EXPLAIN.  Ticket #626. (CVS 1267)

FossilOrigin-Name: 2af1f065b5eb39fd3ecac00f8a66d1b4186aead5
2004-02-24 01:04:11 +00:00
drh 701a0aebe2 Use sqliteVdbeOp3 instead of sqliteVdbeChangeP3 where applicable. (CVS 1266)
FossilOrigin-Name: 51f1e8f7539596b33bc3365ec8f34041602d049c
2004-02-22 20:05:00 +00:00
drh d383401c6a Code cleanup in build.c. (CVS 1265)
FossilOrigin-Name: 9211e14cf81f4de125bad246d8a289786f2854aa
2004-02-22 18:56:49 +00:00
drh f7a9e1ac87 Use sqliteErrorMsg instead of sqliteSetString whereever practical. (CVS 1264)
FossilOrigin-Name: 69aac043af7f93e7b3f036622c0ac9261cae1839
2004-02-22 18:40:56 +00:00
drh eb9a9e8888 Code cleanup in the date and time functions. (CVS 1263)
FossilOrigin-Name: 9b3bcde1530091602e551435ffd7820eb79727d5
2004-02-22 17:49:32 +00:00
drh 2d3917da29 Rearrange the grammar some so that tokens that are used together appear
together in the grammar file.  This reduces the size of the parser tables
and some of the jump tables in switch statements. (CVS 1262)

FossilOrigin-Name: d372c16ec6621dbab371bff7f1803ca096862984
2004-02-22 16:27:00 +00:00
drh 60d316542f Do not sort terminal symbols by name. The terminals remain in the same order
that they are encountered in the grammar file.  This results in parse tables
that are 25% smaller. (CVS 1261)

FossilOrigin-Name: f36b122d9767fa9e6dc5bcce04b5606d67cad3d9
2004-02-22 00:08:04 +00:00
drh b621c23775 Test cases for printf of double overflows. (CVS 1260)
FossilOrigin-Name: 96a6d2d3ff5bd0aaff188ee1c5e2f02cbea435b2
2004-02-21 19:41:04 +00:00
drh 3e7bc9ca1c Fix a long-standing memory leak that the new last_insert_rowid() tests
brought to light. (CVS 1259)

FossilOrigin-Name: 7d5ede5b6ef515808995d4631f8d19aca95a9105
2004-02-21 19:17:17 +00:00
drh 5f968436e6 Cleanup the printf code to make it smaller and more modular.
Fix a memory leak in the new OP_ContextPush opcode. (CVS 1258)

FossilOrigin-Name: 2756f7af3382fa9d186ab99cf76f469fb891a3c3
2004-02-21 19:02:30 +00:00
drh 8722318f3c Flag pragmas like vdbe_trace now return their current setting if they
are called with no arguments. (CVS 1257)

FossilOrigin-Name: 6a5fb5b89a98307060bb4a92a499b5d3dba74553
2004-02-21 14:00:29 +00:00
drh 905793e249 More code cleanup and size reduction. (CVS 1256)
FossilOrigin-Name: 8e3eda2a909bd80b2b14ace36ab44303750a4409
2004-02-21 13:31:09 +00:00
drh 8eb2cce55c Enhance date/time functions to work with negative years. Ticket #617. (CVS 1255)
FossilOrigin-Name: ffa971934867b6bbe943c004154d5f161e0ea697
2004-02-21 03:28:18 +00:00
drh 8307ac7521 Turn the short_column_names pragma off by default - for the time being. (CVS 1254)
FossilOrigin-Name: 6954d2c3240459842be655b600c6b160e918e74a
2004-02-20 23:34:07 +00:00
rdc 9d524f6b9c Add sqlite.def file required for correct operation of "make implib" option in Makefile.in (CVS 1253)
FossilOrigin-Name: b1b23c410260293f57614f32232cf1276f41c16b
2004-02-20 22:55:41 +00:00
rdc a503d7312a Fixed behaviour of last_insert_rowid() with triggers and add last_statement_change_count() function that works correctly with triggers. (CVS 1252)
FossilOrigin-Name: 6734c923395ca41ce453f56dd7d6e7794fbb3bb5
2004-02-20 22:54:25 +00:00
rdc b0c374ffbb Fixed behaviour of last_insert_rowid() with triggers and add last_statement_change_count() function that works correctly with triggers. (CVS 1251)
FossilOrigin-Name: 3383413a53bff0fef0765144de3bb9a298a5bb5c
2004-02-20 22:53:38 +00:00
drh fcabd4641e The name of a result column is now the name of column it originated from, by
default.  This can be turned off with PRAGMA short_column_names=OFF.  This
is to be more like PostgreSQL.  More testing needed. (CVS 1250)

FossilOrigin-Name: 574dd444e7ff00e0fccc3436fe617ad832daae40
2004-02-20 14:50:58 +00:00
drh 784d86f716 Fix a bug in the parser table compression algorithm of lemon. (CVS 1249)
FossilOrigin-Name: 8d3e924975681a871e0eeac3b6a62cffdb947ac7
2004-02-19 18:41:53 +00:00
drh 9cbe7ca7db Fix a memory leak that occurs if you call sqlite_interrupt() on a query
using aggregate functions where the aggregate function returns a string
longer than 32 characters. (CVS 1248)

FossilOrigin-Name: 2c1e74e58a702fd2be954467a12e69a33b252831
2004-02-18 16:57:23 +00:00
drh fef9765507 Begin updating the architecture description to better describe how things
are currently put together. (CVS 1247)

FossilOrigin-Name: 062ecc1368d6bb6d15da31e8d6f5953e8f5628b9
2004-02-18 16:56:32 +00:00
drh 230680276c Add more tests of the sqlite_interrupt() logic - looking for a reported
memory leak.  (Didn't find it.) (CVS 1246)

FossilOrigin-Name: e4c8b1c3aa9d288f518c6394187354e6fa18978e
2004-02-18 01:31:53 +00:00
dougcurrie 960ac04f4f Avoid line endings munging by Cygwin; ticket #370 (CVS 1245)
FossilOrigin-Name: 50e67948f89380f2f4b536add0b8179e6db960a5
2004-02-17 18:26:57 +00:00
drh d6502758b4 Remove the NullCallback opcode. Handle the empty_result_set pragma inside
the sqlite_exec() function. (CVS 1244)

FossilOrigin-Name: f72134852bf33d13fd2bc6f35251e4b33bc10fac
2004-02-16 03:44:01 +00:00
drh 826fb5a3f8 Eliminate obsolete code associated with the older callback functionality. (CVS 1243)
FossilOrigin-Name: 2dbc4593ca5c1cf75039c8b4471b1e47faa849f0
2004-02-14 23:59:57 +00:00
drh 1d85d93158 Eliminate the use of callbacks during schema initialization. (CVS 1242)
FossilOrigin-Name: af5c2be4aed1c50f69eb9634cf051a26263dcf51
2004-02-14 23:05:52 +00:00
drh 8a6ac0adbc Fix problems with malloc-failure handling. (CVS 1241)
FossilOrigin-Name: 398bc294c839368e7fa75a97ba8cc8d1639f9436
2004-02-14 17:35:07 +00:00
drh a1f9b5ee0b The sqlite_exec() function is now implemented using sqlite_compile() and
sqlite_step().  This opens up lots of opportunity to remove old code. (CVS 1240)

FossilOrigin-Name: 9771ad1e811e02e10bb738550fbea447749083c5
2004-02-14 16:31:02 +00:00
drh b5f70c2ef1 Disable the malloc.test tests if not compiled with -DMEMORY_DEBUG (CVS 1239)
FossilOrigin-Name: 41b6ad78a6097f35bfac6ff40d2e5d6071a1c4cd
2004-02-14 01:39:50 +00:00
drh eceae45cb5 Fix an uninitialized variable in shell.c that would cause a crash if you
specified SQL on the command-line. (CVS 1238)

FossilOrigin-Name: 5a56090dde10ee29863021356d21c3f8c86e3f46
2004-02-13 20:09:41 +00:00
drh e72daeb0ac Begin the process over converting sqlite_exec() over to use sqlite_compile()
and sqlite_step().  The new sqlite_exec() is still commented out. (CVS 1237)

FossilOrigin-Name: b8f2ba7880b761e380b95ae63d8ab721f018443e
2004-02-13 16:30:09 +00:00
drh 50350a15c4 Fix a bug in the query flattener when trying to find the datatype of the
rowid of a view.  Also fix a problem with sqlite_compile() and authorization
failures. (CVS 1236)

FossilOrigin-Name: aa0490ccd4a820a707dfb4905e67c01ffb4f758b
2004-02-13 16:22:22 +00:00
drh 78a7583828 Fix an uninitialized variable introduced by check-in (1202). (CVS 1235)
FossilOrigin-Name: 9f149fdc1c6af1c663b91c878ed1903f82f80245
2004-02-13 14:07:12 +00:00
drh e384a4ed4e Add a new parameter to the (unimplemented) encryption API. (CVS 1234)
FossilOrigin-Name: 5fe8f02306cf1c0af2148835cee0df3003ad0874
2004-02-12 20:49:36 +00:00
drh c602f9ae01 Add the SQLITE_NOTADB return code for cases when you try to open a file
that does not even remotely resemble an SQLite database file. (CVS 1233)

FossilOrigin-Name: 0c77cee70f078152969933c1d340cea1c86286b0
2004-02-12 19:01:04 +00:00
drh 4d189ca48f Add hooks on each attached database connection for storing auxiliary
information.  Add the USING clause to ATTACH. (CVS 1232)

FossilOrigin-Name: 800c11f4bce014a07110eb539992a609e6418406
2004-02-12 18:46:38 +00:00
drh 3054efee07 All REPLACE INTO syntax inside of triggers. Ticket #610. (CVS 1231)
FossilOrigin-Name: a6b862a9db6d409a53cc13e7008b27d4848b5509
2004-02-12 17:28:13 +00:00
drh 70a931c2ac Remove unused variable. (CVS 1230)
FossilOrigin-Name: 74b234264ba2910ebd38e7b7ebbc369108a235cb
2004-02-12 15:32:53 +00:00
drh 8ef83ffed8 Always reload the schema after a rollback. Ticket #594. (CVS 1229)
FossilOrigin-Name: 12c7a83f8e4055c4590983ef212648c781ebd963
2004-02-12 15:31:21 +00:00
drh 93581642d2 VACUUM returns SQLITE_INTERRUPT when interrupted. Ticket #593. (CVS 1228)
FossilOrigin-Name: 2fe9f5101cb0f743532912ece3d37f6c873e7025
2004-02-12 13:02:55 +00:00
drh ab9426e242 Only define _FILE_OFFSET_BITS if it is not already defined. Ticket #605. (CVS 1227)
FossilOrigin-Name: 300c5543dc83c6b7eacb0c81ed06f95004c0f6d8
2004-02-11 16:38:06 +00:00
drh eb8ed70db5 Fix the shells so that they always enable the codec if it is available,
even if no key is supplied. (CVS 1226)

FossilOrigin-Name: 95989717e17d52b2306374f5cf7613c3bd4e7801
2004-02-11 10:37:23 +00:00
drh 7e26d75094 Fix an uninitialized variable in expr.c. Ticket #604. (CVS 1225)
FossilOrigin-Name: 1673bf7c7b64542530ee03328186be33cb88c98d
2004-02-11 10:35:29 +00:00
drh bbd82df617 Refactor the interface to the randomness generator. (CVS 1224)
FossilOrigin-Name: f2bdccf4bb2f796aafb64c33e55f62a1794d750c
2004-02-11 09:46:30 +00:00
drh 9eb9e26b82 Pass all (relevant) regression tests when using the codec. (CVS 1223)
FossilOrigin-Name: 5200e9edc5fdba0285a3cb1cd808cbf66d7a349e
2004-02-11 02:18:05 +00:00
drh d86a39c866 Adjustments to the codec in the pager. (CVS 1222)
FossilOrigin-Name: be5122e99caacbeb5e568a2782fe2faf634ad355
2004-02-10 23:51:05 +00:00
drh fb044c1d1c Perform updates in search order. Ticket #602. (CVS 1221)
FossilOrigin-Name: cf1cec74ae039cd7cbc8a1032d29f067dedb4210
2004-02-10 13:41:52 +00:00
drh 4bc058593b Fix for ticket #603. (CVS 1220)
FossilOrigin-Name: d0624d257789ac3f4cd3a7473bb741030c999b65
2004-02-10 13:19:35 +00:00
drh 57ced9186a Make the pager accessible from the btree structure always, not just during
debugging. (CVS 1219)

FossilOrigin-Name: 9c6b4758a4b13a91f71be17751a76c0c14b4d4c3
2004-02-10 02:57:59 +00:00
drh 2d71ca94a9 Move the file-format-2 to file-format-3 conversion into sqliteInit(). (CVS 1218)
FossilOrigin-Name: dcbe2800be2f805818724a7b9e468c4fd4f02529
2004-02-10 02:27:04 +00:00
drh d0ba193dc7 Allow SQLITE_PAGE_SIZE to be redefined on the compiler command-line. (CVS 1217)
FossilOrigin-Name: 4c7bf714b5f3d2bb7366367ddf906141a7e36407
2004-02-10 01:54:28 +00:00
drh f620b4e2cb After code is generated for a subquery, delete the Select structure in order
to force the temporary table to be used and to prevent the subquery from
being evaluated a second time.  Ticket #601. (CVS 1216)

FossilOrigin-Name: 1cff18868dab5f8ead8ed8d07e088d7fdda04569
2004-02-09 14:37:50 +00:00
drh e2201971ac Add test case for ticket #601. (CVS 1215)
FossilOrigin-Name: 096312dacb9eb2f8da3cec1504aef8629b505e7f
2004-02-09 14:35:28 +00:00
drh b20ea9d225 Add an optional codec to the pager layer. (CVS 1214)
FossilOrigin-Name: 2f0c122cfb84dea58d112324a0bdd8b85552a9fa
2004-02-09 01:20:36 +00:00
drh 8e6283155e Version 2.8.12 (CVS 1213)
FossilOrigin-Name: 1736d415d776aa1cbdd33d987d21365ebf260f11
2004-02-08 18:10:50 +00:00
drh f603871326 Perpare for the 2.8.12 release. (CVS 1212)
FossilOrigin-Name: 93ccd1b1d63b5b914b84b0463f2267bcfaadafa3
2004-02-08 18:07:34 +00:00
drh f1b07b0ca2 Fix a bug in the VDBE that occurs when a CreateTable or CreateIndex fails. (CVS 1211)
FossilOrigin-Name: 42cfd541dcc31d1ef92387e3fd2346db61d0ecbd
2004-02-08 06:17:19 +00:00
drh 585a3d7c22 Add the crashtest1.c program used to test the ability of the database to
survive a program crash or power failure.  Ticket #599. (CVS 1210)

FossilOrigin-Name: 597a59a72d662b291fb09a069547efd08aa5adb1
2004-02-08 06:06:37 +00:00
drh 34e79ceeb6 Fix inaccuracies and add details to comments in the pager. Change the name
of one function to make its purpose clearer.  Ticket #599. (CVS 1209)

FossilOrigin-Name: 48832d35ed0d5ba02908822c749591e76b790c48
2004-02-08 06:05:46 +00:00
drh 240c5795d5 Preliminary fix for ticket #599. More testing and analysis needed. (CVS 1208)
FossilOrigin-Name: dc5be2c82b591a385adf02863d89e113272e2ebd
2004-02-08 00:40:52 +00:00
drh e84a306b91 Remove undocumented extensions from sqlite_mprintf() and friends in order to
make it about 10% smaller. (CVS 1207)

FossilOrigin-Name: 0b3f552b986fd89c48c350b0746be93b9d276ecc
2004-02-02 12:29:25 +00:00
drh 22fbcb8ddd Fix the handling of -init option to the sqlite shell. Ticket #568.
Also add hooks for encrypting the database. (CVS 1206)

FossilOrigin-Name: 3c796de8d1af55944f396f08feaa9e69c1652896
2004-02-01 01:22:50 +00:00
drh 3914aed1de Fix a bug introduced by the previous check-in. (CVS 1205)
FossilOrigin-Name: 04cf22785e68fcd4098e6c10a89386108cd0bf07
2004-01-31 20:40:42 +00:00
drh 2c79c67fcb A few more optimizations to the VDBE. (CVS 1204)
FossilOrigin-Name: 06e7ff4cb8c73fd690c6d5b5f530a30d83f4f10c
2004-01-31 20:20:29 +00:00
drh 6810ce677d Rework internal data structures to make the VDBE about 15% smaller. (CVS 1203)
FossilOrigin-Name: 8273c74bd09d1a044cb5154498b0a39939f6e3ed
2004-01-31 19:22:56 +00:00
drh 00706be366 Rework the VDBE data structures to combine string representations into the
same structure with integer and floating point.  This opens the door to
significant optimizations. (CVS 1202)

FossilOrigin-Name: c0faa1c67a967f028cd018e58988fb08bc814d3d
2004-01-30 14:49:16 +00:00
drh 0c37e6309b Make sure min() and max() optimizations work for subqueries. Ticket #587. (CVS 1201)
FossilOrigin-Name: af73fbca839f8cbe39c21f1f9e439fe9b79005c8
2004-01-30 02:01:03 +00:00
drh e8a63423da Change permissions on the install-sh file to be executable. Ticket #582. (CVS 1200)
FossilOrigin-Name: eafa714d1f0abe7e4822a6d137c2a7c6179ffab3
2004-01-27 17:46:55 +00:00
drh 11437fa6b1 Add a web page describing when it is appropriate to use SQLite and when it
is not. (CVS 1199)

FossilOrigin-Name: d77e47764818ef495894013fb26b1a510f2f1a7e
2004-01-27 15:58:37 +00:00
drh 8141f61ef2 Modularize the column name resolution code so that it is smaller, faster,
and ready for some enhancements that will fix long-standing name
resolutions problems. (CVS 1198)

FossilOrigin-Name: d3648034b409822909d79eb5aa4e64cafa986541
2004-01-25 22:44:58 +00:00
drh b733d03749 Add the ability to group FROM terms using parentheses. Names of columns in
a join no longer include the table name. (CVS 1197)

FossilOrigin-Name: 3626f6d4a1adb4209d5bd9e6477343b52bddbdf2
2004-01-24 20:18:12 +00:00
drh a8d6243bc7 Fix typo. Ticket #577. (CVS 1196)
FossilOrigin-Name: 3dc951951947a9188ecba1b84e48c65e34c4df16
2004-01-22 23:38:21 +00:00
drh 30c84bfd5f In test programs, an SQLITE_SCHEMA return is retried repeatedly, not just once. (CVS 1195)
FossilOrigin-Name: df3509e13dc05751b7a5af07b57bca449fe5244c
2004-01-21 13:35:13 +00:00
drh 0bca353087 Make ATTACH and DETACH work with the non-callback API. Ticket #574. (CVS 1194)
FossilOrigin-Name: c32a80fe3cd6dda5238e59bd48d9dd22b4856304
2004-01-20 11:54:03 +00:00
jplyon a8fbdd36f8 documented pragma foreign_key_list().
updated docs for removed behavior: Oracle join syntax and temp indexes. (CVS 1193)

FossilOrigin-Name: 06bd5070966b59730a91bc4d384df4f8abaadd37
2004-01-19 05:09:24 +00:00
jplyon 4b11c6d3f4 comment typos (CVS 1192)
FossilOrigin-Name: 7972ee321974380a59fef752f5643d98f9df38cc
2004-01-19 04:57:53 +00:00
jplyon cfa5684d47 comment typos (CVS 1191)
FossilOrigin-Name: de35c36ed7657903ebba0c5acff75baaa0453f87
2004-01-19 04:55:56 +00:00
jplyon 8bc03a7acd coment typo (CVS 1190)
FossilOrigin-Name: 0d2683dc5ecb886ae9625484b51e65df49b3235d
2004-01-19 04:54:28 +00:00
jplyon b6c9e6e6c1 coment typo (CVS 1189)
FossilOrigin-Name: 8210b2d818ab83a97b3b71b432770436116f4770
2004-01-19 04:53:24 +00:00
jplyon b1639ffeb5 comment (CVS 1188)
FossilOrigin-Name: fa55c9861e1cc372a36958383a86895dc311bb4b
2004-01-19 04:52:29 +00:00
drh 4d5b836545 Do not use strcpy() on overlapping buffers. (CVS 1187)
FossilOrigin-Name: ed6bd2eb39a0940c4f41d365ddc81ecc7066cf4e
2004-01-17 01:16:21 +00:00
drh 606c369847 Access to free()ed memory problem fixed. Found by electric fence.
Only an issue when doing an EXPLAIN of a CREATE INDEX. (CVS 1186)

FossilOrigin-Name: 6604e5f7d332b484e84d177f93c9d9f2ab54a32b
2004-01-16 20:01:31 +00:00
dougcurrie a70f2d8d72 See ticket #569; eliminates warnings for Cygwin v1.5 and above. (CVS 1185)
FossilOrigin-Name: a0f8b1f3cea9a0542f8d36898bf98df3c59f12e0
2004-01-16 19:11:28 +00:00
drh 51e9a44592 More compaction of expr.c. (CVS 1184)
FossilOrigin-Name: 92e7f78057c4e8f6214b6e0a2d80c3ffcbfdf68e
2004-01-16 16:42:53 +00:00
drh 4efc4754f3 Incremental code compaction in expr.c. Now about 4% smaller.
Lots more work to do. (CVS 1183)

FossilOrigin-Name: d292ba5148059dce3893b80eabdca4af9f75194e
2004-01-16 15:55:37 +00:00
drh 1dba727946 Fix a buffer-overflow problem in the randStr function (used only for testing). (CVS 1182)
FossilOrigin-Name: 42c79edc2e8d1051b3bca915b4b205c601b8077f
2004-01-16 13:58:18 +00:00
drh d1bec47a3d More aggressive retry schedule in sqlite_busy_timeout(). (CVS 1181)
FossilOrigin-Name: 5e85025be7aa4a03b0cfb4d0f28a2e44653b9d3f
2004-01-15 13:29:31 +00:00
drh 23b2db23b4 Allow "<expr> IN <table>" as a shorthand for
"<expr> IN (SELECT * FROM <table>)" (CVS 1180)

FossilOrigin-Name: 01874d252ac44861e927dea3f5534f67e19b1fa8
2004-01-15 03:30:24 +00:00
drh aa940eacfe Reinsert the experimental sqlite_commit_hook() API. (CVS 1179)
FossilOrigin-Name: 72bc84f2f18f6eeb279a4ad670310e85d154f663
2004-01-15 02:44:03 +00:00
drh 751f41217e Fix comparisons of ROWID against floating point numbers so that they work
correctly.  Ticket #377 and #567. (CVS 1178)

FossilOrigin-Name: c9ac3db8e08403398ec344757385334601a59374
2004-01-14 21:59:22 +00:00
drh d43ce86fa7 Version 2.8.11 (CVS 1177)
FossilOrigin-Name: a9f25347de6d2bf843a8aebf7935e9c8a1f2319c
2004-01-14 13:50:59 +00:00
drh 0ee7ae0f0d Bump the version number for the next release. (CVS 1176)
FossilOrigin-Name: 2812dd5fc99c959f41b24b0f6b280b67b06fe9d9
2004-01-14 13:43:43 +00:00
drh 52b36cabe0 Ignore NULLs in a subquery as the right operand of IN. Ticket #565. (CVS 1175)
FossilOrigin-Name: c9e7996fb9080b715e9b273a3ac3ed3744e10a77
2004-01-14 13:38:54 +00:00
drh f6a7ade6b6 Version 2.8.10 (CVS 1174)
FossilOrigin-Name: 8bef75ab85197d926d924ae689769207df9a12f8
2004-01-14 03:49:43 +00:00
drh c713bdc778 Move some files around and bump the version number in preparation for the
release of 2.8.10. (CVS 1173)

FossilOrigin-Name: 74c661850e1899c457d4e822d8284bb66e1dc651
2004-01-14 03:32:37 +00:00
drh 7bdeb312ed Remove an incomplete comment that somehow snuck into the sources. (CVS 1172)
FossilOrigin-Name: ea1ad4653e6248f112d5516a0dcf3a72aa9b60d7
2004-01-14 03:12:42 +00:00
drh 31e95bcc5d On unix, embargo close() operations until all locks have cleared from the
file.  Ticket #561. (CVS 1171)

FossilOrigin-Name: 1ebe5fc7b03a6b070a5d52ffedb95f0d519ab068
2004-01-12 00:39:05 +00:00
drh 7b40e60800 Previous commit of changes to the in-memory backend was not quite right.
This check-in should square things away. (CVS 1170)

FossilOrigin-Name: 75d91e3bca44787768b1970203878dd4b1e31e55
2004-01-12 00:38:18 +00:00
drh 572b6f5614 Make sure the in-memory database can handle malloc failures. (CVS 1169)
FossilOrigin-Name: ba92af182c6c9c6b2e3816006191eedd424cdf1a
2004-01-12 00:21:52 +00:00
drh ba21256f98 Remove unused code and tighten existing code to make the library a little
smaller. (CVS 1168)

FossilOrigin-Name: 34a6b7416c6c9bcdf301f5e7b072a0362a746105
2004-01-08 02:17:31 +00:00
drh 143f3c45a7 Rework the fix to ticket #461 so that we do not have to do redundant tests
of WHERE clause terms looking for NULLs.  See also check-in (1103). (CVS 1167)

FossilOrigin-Name: 5fd581787e88173f0303f870fc956ec9285cca4e
2004-01-07 20:37:52 +00:00
drh d1d9fc3397 Permit sqlite_exec() to be called from within user-defined functions. (CVS 1166)
FossilOrigin-Name: 03636c94a542b1f90a3acfbe65a9c2976872073f
2004-01-07 19:24:48 +00:00
drh a11846b77a Defer the {quote: MoveTo}
opcode in VDBE until the data is actually needed.  Sometimes
the data is never needed, resulting in a performance increase.  On an indexed
order search with a large OFFSET, queries times can be an order of magnitude
faster. (CVS 1165)

FossilOrigin-Name: d3e96da20d269a068188915b3cc0eb02d330d316
2004-01-07 18:52:56 +00:00
drh 912184b0cf Make it safe to call sqliteMalloc() with a request for 0 bytes. Ticket #534. (CVS 1164)
FossilOrigin-Name: 6c858db2c099c7ba73d72e02b19bf6173620db13
2004-01-07 03:41:03 +00:00
drh c5dd9fa8ab Preserve the HH:MM:SS for most date/time modifiers. Ticket #551. (CVS 1163)
FossilOrigin-Name: 70df32b716b0d6a4f72bb3ae6496431e53733b6a
2004-01-07 03:29:16 +00:00
drh 384eef32fd Use "long double" to hold intermediate values when doing ascii to binary
and binary to ascii conversions of floating point numbers. (CVS 1162)

FossilOrigin-Name: 8371f662d22be0a3c58e0503c7511faea1640955
2004-01-07 03:04:27 +00:00
drh 133cdf6eba Add a typecast to work around a bug in the Metrowerks Code Warrior compiler.
Ticket #553. (CVS 1161)

FossilOrigin-Name: 4146f8cc3ff5339b5685e9c5121888ae08ee0807
2004-01-07 02:52:07 +00:00
drh 3a4e19be6b Version 2.8.9 (CVS 1160)
FossilOrigin-Name: d8ae6bddeb70f1450ccd3a4735ccf6fe3a042a07
2004-01-06 02:23:46 +00:00
drh 9d4280d53f Additional integer overflow boundary case tests. (CVS 1159)
FossilOrigin-Name: 532170d4b8fc7a4e596a817257e9e1f81d364940
2004-01-06 01:52:34 +00:00
drh e8e3920a2e Increase the version number and update the change log prior to the next
release. (CVS 1158)

FossilOrigin-Name: b99b68d026a0d58338a1d578e15a40dcdcdb47a9
2004-01-06 01:27:00 +00:00
drh 202b2df74a Fix problem in the code generator were incorrect code was being created if
the SQL source contained a negative integer that was too large to fit in
a 32-bit signed integer variable.  Ticket #552. (CVS 1157)

FossilOrigin-Name: b8381d9fe99273507e8626638110646801afef06
2004-01-06 01:13:46 +00:00
drh e807febbc2 Add the sqlite_current_time variable for testing purposes. (CVS 1156)
FossilOrigin-Name: 23fa407d50741bc0719259792398f28c1d0f12c2
2004-01-06 00:44:24 +00:00
drh b46d162d8d The "EST" timezone designation is ambiguous. Do not use it in the test
scripts. (CVS 1155)

FossilOrigin-Name: 720b565e2d02344e4d38263f4995dfabc60c0860
2004-01-02 15:08:43 +00:00
drh 7739630451 Avoid an assertion fault that can occur with invalid UTF8 on the LENGTH()
function.  Ticket #548. (CVS 1154)

FossilOrigin-Name: 7080fc39eaf98ef7a7d1c1819603f67841f35c72
2004-01-02 13:17:48 +00:00
drh 4ec2e9612f Remove unused code from the integrity_check logic. Ticket #545. (CVS 1153)
FossilOrigin-Name: ee51e205fb6ef412db6a46077e8bc1554aadcca1
2004-01-01 12:33:43 +00:00
drh cf64d8b820 Fix a bug in the SQLITE_PROFILE conditional compilation. (CVS 1152)
FossilOrigin-Name: 597b33f696c0cde84529cd06a8f95a8ccc8f1e8e
2003-12-31 17:57:10 +00:00
drh 89ef0eeb9b Fix for ticket #542. (CVS 1151)
FossilOrigin-Name: 458cfa5ba82f2d676e398437a4b1d26d77582d10
2003-12-31 17:25:47 +00:00
drh 07fa2a60ea Fix a bug (ticket #541) introduced by the previous check-in ((1149)). (CVS 1150)
FossilOrigin-Name: 646244008fb8a6eef4169291d75da59fa1ab26f9
2003-12-31 16:00:19 +00:00
drh dff7ec2cbd Reduce the randomness in the sqliteRandomSeed() routine in order to silence
bogus errors from valgrind.  Tickets #535 and #536. (CVS 1149)

FossilOrigin-Name: cfe0acf9ec6c89f1e77b8be7dcc23029984de1ce
2003-12-31 13:21:18 +00:00
dougcurrie ae53418df4 minor edits for new date.c with mingw/msys on Windows (CVS 1148)
FossilOrigin-Name: 9392c514501be333a3c22b552dc036e083eb22b4
2003-12-24 01:41:19 +00:00
drh f586aa8b96 Update date/time functions so that they correctly handle NULL arguments. (CVS 1147)
FossilOrigin-Name: a5a5fbd60153dd068ec2559455146e84da075b90
2003-12-23 16:34:12 +00:00
drh 7091cb0566 Add localtime<-->UTC conversions to the date functions. (CVS 1146)
FossilOrigin-Name: 8482b8c44766e7f80fc449b3dbdd3f37396c332b
2003-12-23 16:22:18 +00:00
drh 90f405e3ba Test functions tolerate an "0x" before a pointer value. Ticket #452. (CVS 1145)
FossilOrigin-Name: c6c5e07b65ae1c30117f0276a1002d5036697cf1
2003-12-23 03:06:23 +00:00
drh 93a5c6bdf4 Use a built-in atof() function instead of the one from the library to
avoid problems with locale.  Ticket #305. (CVS 1144)

FossilOrigin-Name: 4d9edbc50f7dee64edbadad2e2dc4f93d8248b3b
2003-12-23 02:17:35 +00:00
drh 3ddfdf7ac6 Optimizations to the LEMON parser template. (CVS 1143)
FossilOrigin-Name: 06db29df8f0c1cd29e696537e622f0c5456056f5
2003-12-22 14:53:19 +00:00
drh 2fd2fa0851 Fix some minor problems with the new test4.c module used for doing thread
testing. (CVS 1142)

FossilOrigin-Name: 952924084aac4a7fa84a7cb7aaac869d35db1896
2003-12-20 04:00:52 +00:00
dougcurrie 6194a5fb75 Update configuration and make files for mingw/msys on Windows (CVS 1141)
FossilOrigin-Name: 1e9689672c94e5ab89f07099c1402e157c8b02c1
2003-12-19 20:09:51 +00:00
drh f93e41442e Remove a comma at the end of an enum definition. Some compilers could not
deal with it. (CVS 1140)

FossilOrigin-Name: b1890a5b9c1222086b3aae92e49eb090a17a6492
2003-12-19 12:32:45 +00:00
drh 5202560ee5 Makefile updates for the new "test4.c" module. Also disable large file
tests for archic TCL versions. (CVS 1139)

FossilOrigin-Name: 55e2488912871381959326ab7fa89123ab30d659
2003-12-19 12:31:19 +00:00
drh acf01e7ddd A better fix for ticket #530 - one that is likely to work on unix
implementations in addition to linux.  Also more tests for multi-thread
locking added. (CVS 1138)

FossilOrigin-Name: 7dddbeb586504de30c64a1e61614da447f18c8ba
2003-12-19 08:40:22 +00:00
drh a6064dcf3b Add new thread-testing code and fix locking under Linux threads. Ticket #530. (CVS 1137)
FossilOrigin-Name: b36a4bb61094d539273c21a9e4042384f10a7806
2003-12-19 02:52:05 +00:00
drh 9c4dcca89e Typo on the "datatypes.html" document. (CVS 1136)
FossilOrigin-Name: 80b1e277123c07b2db7441a9e600dd69ef55a0da
2003-12-18 14:19:41 +00:00
drh 0f5c27a168 Version 2.8.8 (CVS 1135)
FossilOrigin-Name: a0451ccf2d0377536073ecaa2d6b70d05f5a5734
2003-12-18 01:22:54 +00:00
drh 0c9c3d06d4 Bump the version number and update the change log in preparation for the
next release. (CVS 1134)

FossilOrigin-Name: 9ad0bdf624e7dba448587c58eacd1e9cd2784316
2003-12-18 00:02:43 +00:00
drh acf4ac96e3 Make sure the pagers in-memory cache states in sync with the disk file.
Ticket #529. (CVS 1133)

FossilOrigin-Name: da00efb13fe8ccf1c27e4e1193df6b53de9463f4
2003-12-17 23:57:34 +00:00
drh 4be295be07 Improvements to the way PRAGMA integrity_check works. More likely to output
userful information when given a corrupt database. (CVS 1132)

FossilOrigin-Name: b92c31d6c138f9462730cecfe14f7dde19778e79
2003-12-16 03:44:47 +00:00
drh 1285a76973 Updates to the homepage - fix the CVS access instructions. (CVS 1131)
FossilOrigin-Name: 653a7dd97ed95e66bd2973169735ee73ee348576
2003-12-15 17:51:19 +00:00
drh 256ada0fda Fix a bulk-memory initialization problem in the expression list logic. (CVS 1130)
FossilOrigin-Name: d6549954408b01e5eaf865b9100739c94de28f16
2003-12-10 03:13:43 +00:00
drh 0f18bfa789 Fix the code generator to a void a VDBE stack overflow on 3-way joins.
Ticket #519. (CVS 1129)

FossilOrigin-Name: 230a4ff2c8a3927533baf5b22edc9f25490d5443
2003-12-10 01:31:21 +00:00
drh 6f8c91caa0 Make the VACUUM command run out of the VDBE like all other commands.
(Ticket #464).  Make the VACUUM command work even if there are VIEWs
in the SQLITE_MASTER table that come before tables they reference.
(Ticket #515) (CVS 1128)

FossilOrigin-Name: 614cbbafa180469744421f8fbe56cb392f48d05f
2003-12-07 00:24:35 +00:00
drh 447623d9aa Fail an ATTACH if the auxiliary database is locked. Ticket #514. (CVS 1127)
FossilOrigin-Name: ac428c8d4a731678cc26cf198689814a8a56d141
2003-12-06 22:22:35 +00:00
drh 41743984bf Always use "(char*)0" to terminate the argument list of sqliteSetString().
This is needed for 64-bit systems that use a 32-bit integer by default. (CVS 1126)

FossilOrigin-Name: 656c90387a4a714b4f31040ece9b0e15e30934af
2003-12-06 21:43:55 +00:00
drh 3a6629d27e Use sqlite_freemem() instead of free() in the shell. Windows needs this.
(Unix does not care.)  Ticket #444. (CVS 1125)

FossilOrigin-Name: e5e6a8481b2225e826c8e890ddc44f06759fe72b
2003-12-04 20:51:41 +00:00
drh 96e9f565ad Version 2.8.7 (CVS 1124)
FossilOrigin-Name: d48b0b018d47470689cc49f3be4cde50db165454
2003-12-04 13:47:04 +00:00
drh 27ff9f87b8 Update change log and version in preparation for the 2.8.7 release. (CVS 1123)
FossilOrigin-Name: 9e79ab6ce06d68fcd7efa207d0ffcd1c51c13d58
2003-12-04 13:44:32 +00:00
drh 4925ca00a3 Disallow temporary indices on persistent tables. (CVS 1122)
FossilOrigin-Name: 72bf73b2c1e3594aa85920e47fc345bba56c80d0
2003-11-27 00:48:57 +00:00
drh 0802fd836d Fix typos in file format documentation. Ticket #505. (CVS 1121)
FossilOrigin-Name: 4eef93814f4a26de4a088c464545443547281abd
2003-11-25 23:48:57 +00:00
drh b3549d43e2 Fix typo in file format documentation. Ticket #502. (CVS 1120)
FossilOrigin-Name: 72f3e7c2b0258271956ed7a43b3388bb74bf62ec
2003-11-24 23:11:08 +00:00
drh 0a5294bc06 Fix a typo in a #define that was commented out. No impact to working code.
Ticket #476. (CVS 1119)

FossilOrigin-Name: 21c2f96e814004d00691e3d7a632f193b0e49ee5
2003-11-11 23:30:35 +00:00
drh 000ca2b208 Added information on MySQL 4.0.16 to the NULL-handling survey. (CVS 1117)
FossilOrigin-Name: e22e3ab53a841b26984240760b0438efc83661d7
2003-11-08 12:07:01 +00:00
drh 7014aff37d Revised date/time functions - now broken out into a separate source file.
See the DateAndTimeFunctions wiki page for additional information. (CVS 1116)

FossilOrigin-Name: 68ef9b45bd3abdedf3721011ad0fb22e8735e721
2003-11-01 01:53:53 +00:00
drh b48484a6d7 Fork the tree for project "shrike" (CVS 1118)
FossilOrigin-Name: 181260c0aa7837feca9e415225ece0e9c4032c7a
2003-10-30 06:59:59 +00:00
peter 63a1e49859 Fix progress test error 1-2 (CVS 1115)
FossilOrigin-Name: c3a495026c7eafd576042a05a9a5f585ba8ba9b9
2003-10-23 15:27:11 +00:00
drh 8548a059ff Comment changes to the lemon parser template. Change some sqliteMalloc() calls
to sqliteMallocRaw() for speed.  Update the website template. (CVS 1114)

FossilOrigin-Name: c637caf13f579959ecdb6b134d0114e8efbcac60
2003-10-22 22:15:27 +00:00
drh fdbf928b08 Fix bugs in lemon associated with the change to a perfect hash table. (CVS 1113)
FossilOrigin-Name: c0d1b26966aeb445fea5792e5a9e93632e758c2a
2003-10-21 16:34:41 +00:00
drh 8b582012de Convert lemon to use a single perfect hash table for storing the actions.
This should make the resulting parser both smaller and faster. (CVS 1112)

FossilOrigin-Name: 4f955c00076b16166ff837749efb84201eab3c3a
2003-10-21 13:16:03 +00:00
danielk1977 348bb5d6c8 Add sqlite_progress_handler() API for specifying an progress callback (CVS 1111)
FossilOrigin-Name: ddb364635a207658664ea92fc677cf16a143a938
2003-10-18 09:37:26 +00:00
drh 4df92bbd44 Update to the date functions. (CVS 1110)
FossilOrigin-Name: 06d4e88394217fb1390b069bad82d6ac71981f72
2003-10-10 02:09:56 +00:00
drh 191c0323c0 Allow quoted trigger names. Ticket #468. (CVS 1109)
FossilOrigin-Name: 54aa0fb236d17b53b194a667d68c71007c8e7687
2003-10-03 00:13:38 +00:00
drh 319e4e7484 All LIKE and GLOB operators to use function notation. "A LIKE B" can be
expressed as "LIKE(B,A)". (CVS 1108)

FossilOrigin-Name: 95b27ebd1322a877112dee514dffddb0937e45fa
2003-09-30 01:54:13 +00:00
drh 4f88c849f3 Patch the spec.template file (for generating RPMs) as suggested by
Jeremy Hinegardner.  Untested. (CVS 1107)

FossilOrigin-Name: 703741ca1e2b0bf79a4e3cda3cf3c6862d7263eb
2003-09-29 12:20:51 +00:00
drh dab3518880 Remove support for the Oracle8 outer join syntax. (CVS 1106)
FossilOrigin-Name: 824430b3ce435386b83ceb882f1510ac9f27d8fa
2003-09-27 13:39:38 +00:00
drh 5b8424b9e4 Add a test case for ticket #464 but leave it commented out for now. We
will fix this problem when VACUUM is rewritten. (CVS 1105)

FossilOrigin-Name: 7ba8dc9b1e5c788f2c0ab32314754324c86aaa49
2003-09-27 01:08:37 +00:00
drh 3775084a75 Add additional backslash escapes to the COPY command for compatibility
with PostgreSQL.  Ticket #460. (CVS 1104)

FossilOrigin-Name: 70a50bdda318f353c8be1ba200f9aedc34642c93
2003-09-27 00:56:31 +00:00
drh 562528c480 Do all WHERE clauses tests, even if an index is used for lookup so that
we know the test cannot be FALSE.  The test might end up being NULL in which
case it would need to be treated as false.  Ticket #461. (CVS 1103)

FossilOrigin-Name: 5aea81488b2d3bcdc009ccf0f0ffcda046e38d79
2003-09-27 00:41:27 +00:00
drh f911221a1e A failed malloc() could have resulted in a segfault. Fixed by this check-in. (CVS 1102)
FossilOrigin-Name: 4bb256ee3ecd44d71d90556e16bb56c0389fd5b5
2003-09-23 10:25:32 +00:00
xdong 3b5543c46d allow -enable-releasemode as an option and allow Makefile to produce version
independent binary like libsqlite-2.8.6.so instead of libsqlite.so.0.0.0 (CVS 1101)

FossilOrigin-Name: 4fdd44a5ee5f7beb3cff11bc54fd3022b975b9e6
2003-09-23 00:36:50 +00:00
xdong 28f79f7bda regenerate configure to take -enalbe-releasemode as an option (CVS 1100)
FossilOrigin-Name: b85847b8f28f8f4be9e7f3d8674ecf42e1c5db38
2003-09-23 00:35:21 +00:00
xdong 225656c50a modify the configure file to allow cross-compile to work at arm and xscale (CVS 1099)
FossilOrigin-Name: 760f2fa2e5db102b970687f59b79bfb6f4d35b32
2003-09-18 21:59:45 +00:00
drh 61b487d02a The tokenizer should never return a negative size of the next token.
Ticket #453. (CVS 1098)

FossilOrigin-Name: 4fbca3ab09596c530da7c50657f3bc9140178dd5
2003-09-12 02:08:14 +00:00
drh 9faae94118 Add test cases that check out sqlite_get_table() on queries with results sets
containing 100 columns. (CVS 1097)

FossilOrigin-Name: f9feedec32c975235c0d0996962033f6a63312ba
2003-09-09 00:47:47 +00:00
drh 82a4851a4b Add initial test cases for the new sqlite_bind() API. Fix bugs that the new
test cases found. (CVS 1096)

FossilOrigin-Name: f6c4908e9b5b6ac9adc4af50dc5110dbb655dae3
2003-09-06 22:45:20 +00:00
drh 7c972dec5c Update Makefile.in for the new vdbeaux.c file. Remove the experimental
"sqlite_instantiate()" routine and replace it with "sqlite_bind()" which
is more like ODBC and JDBC. (CVS 1095)

FossilOrigin-Name: 990bb11898a539bb0795a4a216fcd989943a0fb2
2003-09-06 22:18:07 +00:00
drh 9a32464b54 Split almost 1300 lines of code out of vdbe.c into separate files
vdbeInt.h and vdbeaux.c. (CVS 1094)

FossilOrigin-Name: bfd69391d3d63675f206ffd8ff0401ea1cbcc073
2003-09-06 20:12:01 +00:00
drh 5045789694 The beginnings of changes to support pre-compiled SQL. Mostly untested,
though all regression tests to pass. (CVS 1093)

FossilOrigin-Name: 912f47c72d3597c6d5acff765d94922bd660339a
2003-09-06 01:10:47 +00:00
drh c023e03ea5 Add a logo from Rasmus Schultz. (CVS 1092)
FossilOrigin-Name: aaa84c6202f6e16828bcd6aff2e424f3dba1f82b
2003-09-02 15:26:33 +00:00
drh 1dcafe1ad8 CVS missed a commit (because I pressed Ctrl-C in the middle). This
extra commit will hopefully help clear things up. (CVS 1091)

FossilOrigin-Name: 522c2efeb5bdccadf3306234d458425b94cdbbe3
2003-08-27 22:57:07 +00:00
drh e4c616931d Add locks to the in-memory backend so that recursive writes will be detected
and rejected.  Ticket #436. (CVS 1089)

FossilOrigin-Name: 3403d28a49b27d3059d3d399ca057e8d33eb857a
2003-08-27 22:54:31 +00:00
drh 0d4f801c28 Add locks to the in-memory database so that recursive writes will be detected
and rejected.  Ticket #436. (CVS 1090)

FossilOrigin-Name: 966b1a16f6687df08f8c21787c1c8b1af1d79e1e
2003-08-27 22:52:34 +00:00
drh ec1bd0bd72 Fix compiler warnings under OpenVMS. Ticket #357. (CVS 1088)
FossilOrigin-Name: c95f347cac27732533a2f6fd4ba50bf00eef59f3
2003-08-26 11:41:27 +00:00
drh 8460ea0652 Try to work around a bug in VC++ by only passing unsigned characters to
the isspace() routine.  Bug reported on the mailing list. (CVS 1087)

FossilOrigin-Name: cbe32216966c987902ceb4d85332fc95801dbda2
2003-08-26 11:35:00 +00:00
drh 03ab7336cd Fix a bug in sqliteRealloc() that only occurs if there is memory corruption
and debugging is enabled.  Ticket #421. (CVS 1086)

FossilOrigin-Name: eebc82b77dbf35a18d2eae47336038d4b67806c6
2003-08-26 11:29:07 +00:00
drh 901afd4341 If the database filename is an empty string, open a temporary file to hold
the database.  Ticket #432. (CVS 1085)

FossilOrigin-Name: da53369f0bf133b89b213bbb1ccea13eb93ab6ed
2003-08-26 11:25:58 +00:00
drh 263659be4d Close files before deleting them on test scripts under Win2k.
Ticket #434. (CVS 1084)

FossilOrigin-Name: 2a40b46140720783cf4002fb9993f7f6766dbf5f
2003-08-26 11:18:19 +00:00
drh 6ab95d3e85 Remove extra backslashes from end of lines in the install target of the
Makefile.  Ticket #435. (CVS 1083)

FossilOrigin-Name: 1aa3658ef54fad7f2b7f61d91641472551468cdc
2003-08-26 10:38:58 +00:00
drh 3ca65151d5 Fix a bug in the new "pk" column of the table_info pragma that was added
by check-in (1081). (CVS 1082)

FossilOrigin-Name: ad7b017a1277c00b356343b36ade565baf404d6a
2003-08-24 16:38:17 +00:00
drh 78100cc928 Add a "pk" column to the table_info pragma which is true for each column
that is part of the primary key.  Add a "foreign_key_list" pragma that gives
information about all foreign keys for a table.  Both changes are experimental. (CVS 1081)

FossilOrigin-Name: 5232b0665b84a9339a85918570093a376a0ea91f
2003-08-23 22:40:53 +00:00
drh 73d3667ef2 Version 2.8.6 (CVS 1080)
FossilOrigin-Name: 0bde7ae2ba57de554c3531f3cb7e36bf56d3b12c
2003-08-22 03:00:00 +00:00
drh a866b82244 Change the CVSTrac website to www.sqlite.org. Update change summary for
the 2.8.6 release. (CVS 1079)

FossilOrigin-Name: a4e3e075e3b36e0f5f692067c5bf5e1b660d893d
2003-08-22 02:34:30 +00:00
drh 02b2011cb3 Update the -version-info number on libtool in Makefile.in. (CVS 1078)
FossilOrigin-Name: dc36365eea7d0c8767d8947393a8d2746c02b220
2003-08-21 14:36:38 +00:00
drh 4739470341 Add the experimental "quote()" function to the set of build-in functions. (CVS 1077)
FossilOrigin-Name: 9699c68508db5da6238904e518835a629d430db6
2003-08-20 01:03:33 +00:00
drh 5d9d757626 Add the "onecolumn" method to the TCL language bindings. (CVS 1076)
FossilOrigin-Name: c7b4c28fbc0bca5645af5750fd353f4eca400b40
2003-08-19 14:31:01 +00:00
drh e5e3760e1c Make the compile work under cygwin.
Tickets #327, #213, #316, #322, #349, #373, and #429. (CVS 1075)

FossilOrigin-Name: 7d8d3252df1e9f6bec5e105b6eca3313cb7e226a
2003-08-16 13:10:51 +00:00
drh 9b1b01bb76 Do not delete tables with the same name when dropping triggers.
Ticket #430. (CVS 1074)

FossilOrigin-Name: ef58f163b08d13f8e9b69459bd83e0bf9d5b404b
2003-08-16 12:37:51 +00:00
drh 8e18bac793 Fix a segfault that occurs in the VACUUM command if run on an empty database
with the EMPTY_RESULT_CALLBACKS pragma enabled.  Ticket #427. (CVS 1073)

FossilOrigin-Name: 3563e9cf9d6b20f09e92deb21fdda93bcd8fb583
2003-08-15 13:24:51 +00:00
drh b2446f9bbf Update the NULL-handling chart with new information about Firebird. (CVS 1072)
FossilOrigin-Name: 17bdfeb284880d82cd546e6c191c3a37121ec861
2003-08-13 11:29:23 +00:00
drh 41a8230fef Make the sqliteOsCurrentTime() function work for Windows. Code contributed
by "e4liberty" on the mailing list. (CVS 1071)

FossilOrigin-Name: 02fac304c9ec9012f3cc4f04d2c4cac5e37b0024
2003-08-10 16:16:22 +00:00
drh 87adaa9a99 tighter coding of the date and time functions. Better comments. A bug fix. (CVS 1070)
FossilOrigin-Name: 94243edac14b90ef898093b85e1959c20fa23ae9
2003-08-10 01:50:54 +00:00
drh 771d8c3bae Add experimental date and time functions based on julian day number. (CVS 1069)
FossilOrigin-Name: a6197e2075fdf9db862484255ac16b2855bbef0a
2003-08-09 21:32:28 +00:00
drh 37ed48ed2f Provide a more informative error message when a uniqueness constraint
fails.  Ticket #419. (CVS 1068)

FossilOrigin-Name: 086aa1c9922b7bf399b3ee8b73ba7353d126b119
2003-08-05 13:13:38 +00:00
drh 4305d10360 The {quote: SrcList} object was not being expanded correctly by a call to
sqliteSrcListAppend() if the {quote: SrcList} had previously been duplicated by
a call to sqliteSrcListDup().  Ticket #416. This check-in fixes that problem
by keeping a separate nAlloc field on {quote: SrcList}.  A similar change is made
to {quote: IdList} and {quote: ExprList} to avoid future problems. (CVS 1067)

FossilOrigin-Name: da6273255471673841fdcadc688aeac80722e130
2003-07-30 12:34:12 +00:00
drh a76c82eb0d When creating a new journal file, open a (read-only) file descriptor on the
directory containing the journal and sync that directory once to make sure
that the journal filename entry gets into the directory.  Ticket #410. (CVS 1066)

FossilOrigin-Name: 09c10fe3c99cffc64ed02c2929f206d99c8e3309
2003-07-27 18:59:42 +00:00
drh 98e3e60012 Make sure the schema loader callback can handle EMPTY_RESULT_CALLBACKS being
on.  Ticket #406. (CVS 1065)

FossilOrigin-Name: 8c163fc0c7c721b7a5fa6727b0e90bff4484c782
2003-07-27 17:26:22 +00:00
drh dc2d94de56 In the VDBE, when an integer value will not fit into a 32-bit int, store it
in a double instead.  Ticket #408. (CVS 1064)

FossilOrigin-Name: 7514c3db165e8cc5c696b2b345844949a0e45a61
2003-07-27 17:16:06 +00:00
drh 48647b390b Version 2.8.5 (CVS 1063)
FossilOrigin-Name: 95fba440e79c066c0d6f6205a3d7dcb6c870b1c9
2003-07-22 13:20:28 +00:00
drh 8dd5a314eb Fix a typo in the index.html homepage. (CVS 1062)
FossilOrigin-Name: 510761cf505222c68ce3404aad94e1cc28b703ed
2003-07-22 12:44:53 +00:00
drh ee513831a7 Increment the version number and update the documentation in preparation
for the 2.8.5 release. (CVS 1061)

FossilOrigin-Name: c2115335de4abc25cbc1664d718dc3a6f70ebe6c
2003-07-22 12:41:59 +00:00
danielk1977 999af643a0 Add experimental sqlite_reset() API (allows pre-compiled queries) (CVS 1060)
FossilOrigin-Name: 1d2fcb017811db90e85d63f2ca76867c00ab8f1b
2003-07-22 09:24:43 +00:00
drh 4d87325d61 Make sure temporary file names in windows have a full 15 characters of
random text at the end. (CVS 1059)

FossilOrigin-Name: 6ccb92b14f2e6e01bb60dac10331fa7be0b4525e
2003-07-22 00:39:13 +00:00
drh 7b58daeafe Fix the LIMIT clause so that it applies to the entire query in a compound
query.  Prior to this change LIMITs on compound queries did not work at
all.  Ticket #393. (CVS 1058)

FossilOrigin-Name: 543479e3aed77976a0c689cf40811bf88353f706
2003-07-20 01:16:46 +00:00
drh e5f50722b4 Make sure the min() and max() optimizer works correctly when there
is a LIMIT clause.  Ticket #396. (CVS 1057)

FossilOrigin-Name: c35e50717678703763c696e3e9b265add2ca6454
2003-07-19 00:44:14 +00:00
drh 9347b20050 In the sqlite shell, change the name of function getline() to local_getline()
to avoid a clash with a library function.  Ticket #400. (CVS 1056)

FossilOrigin-Name: 558969ee8697180c74308f3f880d3240eb575af1
2003-07-18 01:30:59 +00:00
drh 9cb733c39d In the test scripts, do not try to delete files that are still open.
Windows does not like it when you do.  Ticket #397. (CVS 1055)

FossilOrigin-Name: 93a2c961b17d2459272e2d8654bd4b972f52fbe1
2003-07-18 01:25:34 +00:00
drh a3b6cfa6cf Fix typo on the homepage. (CVS 1054)
FossilOrigin-Name: c74107d63ace3d0e51da3b7bd7ee250c2a39205b
2003-07-16 17:10:45 +00:00
drh a88dc3f629 Make LIMIT 0 return no rows. LIMIT -1 still returns all rows. Ticket #346. (CVS 1053)
FossilOrigin-Name: a31d0bd90af7cc95f8e36ca8ece21515f872235e
2003-07-16 11:51:35 +00:00
drh ef0cae500d Allow negative values for LIMIT and OFFSET. Add tests for negative LIMITs
and OFFSETs.  Make the OFFSET work even if LIMIT is 0 or negative. (CVS 1052)

FossilOrigin-Name: e6a752bfef24f773973c151c6262ff331a9dc57a
2003-07-16 02:19:37 +00:00
drh d4f5ee2805 Initialize a variable to prevent an MSVC compiler warning. Ticket #394. (CVS 1051)
FossilOrigin-Name: 96e3c539586bf86c4fe8de0ac25de6655f704035
2003-07-16 00:54:31 +00:00
drh da808d56dc An an extra test associated with ticket #387. (CVS 1050)
FossilOrigin-Name: 6a07ac3782bc18f907ffcf66d908ddaa82ab9293
2003-07-09 16:34:56 +00:00
drh 073e5a7751 Allow the output arguments in sqlite_compile and sqlite_step to be NULL
pointers.  Tickets #384 and #385. (CVS 1049)

FossilOrigin-Name: dd84f88f6c4012e4a093a4881f6fe50527bb2006
2003-07-09 00:28:13 +00:00
drh 23af2f6eb2 Enhance the C/C++ documentation to clarify the meaning of the return value
from sqlite_changes().  Ticket #383. (CVS 1048)

FossilOrigin-Name: 303b2da1acd4b7b9d89dec0653e5f88fc10d56b8
2003-07-08 23:42:25 +00:00
drh 3e4c852889 A proported fix for ticket #374. (CVS 1047)
FossilOrigin-Name: a49ee69e98df80b479aa6bb97a9af9c6abf04e3f
2003-07-07 10:47:10 +00:00
drh d0cc954fa1 Update the NULL-handling document to show current behavior of OCELOT. (CVS 1046)
FossilOrigin-Name: 1d4c92c7325f69ee84b901a2de74a306ace134b6
2003-07-07 00:10:39 +00:00
drh 1dd59e0f94 Correctly handle comparing an INTEGER PRIMARY KEY against a floating point
number.  Ticket #377. (CVS 1045)

FossilOrigin-Name: 982aa3356bcc217003cd9e6a829619219c334797
2003-07-06 17:22:25 +00:00
drh 3c8bf55a04 Make sure indices in ATTACH-ed databases are put into the right hash table.
Ticket #354. (CVS 1044)

FossilOrigin-Name: eb4582831d536cd26a1738f9ad197e40486d0958
2003-07-01 18:13:14 +00:00
drh c5aceb33cb Update the null-handling document to show how SQL Anywhere and Borland
Interbase deal with NULLs. (CVS 1043)

FossilOrigin-Name: 9a87f2f326d7fc8bb9f832d0e3fd31141e14e08f
2003-07-01 01:16:30 +00:00
drh ef2d1b100c Documentation change: refer users to the wiki for additional unsupported
features rather than have them send me e-mail. (CVS 1042)

FossilOrigin-Name: a3920b0804e9993bb21e6c46c612e72bd03178a2
2003-06-30 10:36:23 +00:00
drh 631e276202 Version 2.8.4 (CVS 1041)
FossilOrigin-Name: 7f5e8894ae37761d1015c426b5d383d3deef3e25
2003-06-29 20:45:29 +00:00
drh dc339ee29c The prior fix of ticket #360 was incorrect and caused a memory leak. This
check-in plugs the memory leak and correctly fixes ticket #360. (CVS 1040)

FossilOrigin-Name: fc490f677b89e623b41f9e7f5f3bade9b981562c
2003-06-29 20:25:08 +00:00
drh d6ae597393 Fix a bad memory leak in the in-memory database module. (CVS 1039)
FossilOrigin-Name: 9cca95937837333c91f5dee8c48178cf7e06d59f
2003-06-29 18:29:47 +00:00
drh 27fb6f6a99 Bump the version number in preparation for the next release. (CVS 1038)
FossilOrigin-Name: 0532e1a8f5a310bb19b55dc29aa5b1f1172a14da
2003-06-29 16:16:40 +00:00
drh 88c0df2a84 Documentation updates. (CVS 1037)
FossilOrigin-Name: ab21de5fdd8e45be19411cdba647eada0bc9a9f1
2003-06-29 16:11:12 +00:00
drh 82f725df08 Minor change to a comment in encode.c. (CVS 1036)
FossilOrigin-Name: 3f252b72c9d9ea586161a1b2c5ae297594a1cd4a
2003-06-28 16:25:33 +00:00
drh 937dd84de8 Fix a bug in the soundex() code. Ticket #367. Add tests for ticket #261
even thought the problem could not be reproduced. (CVS 1035)

FossilOrigin-Name: e2ca936feee35b3fce99c95c2cf8c0ad05cd9c3b
2003-06-28 16:20:22 +00:00
drh d60ccc6a75 In a SELECT, the rowid of a view or subquery which is really a join is
set to NULL if the join is flattened.  Ticket #364. (CVS 1034)

FossilOrigin-Name: bad8b55833f5120003a19883154dac5146cc36a3
2003-06-24 10:39:46 +00:00
drh 18706c08cb Remove a surplus "return" statement accidentaly left in check-in (1032). (CVS 1033)
FossilOrigin-Name: c697410af4a61d2037e7e319efe8dd78d7b83365
2003-06-23 15:15:03 +00:00
drh 6cb2c52d96 Remove all references to SQLITE_OMIT_TRACE. Tracing is always enabled.
Ticket #361. (CVS 1032)

FossilOrigin-Name: ec31a5292cbc5d2fb68449838b929638f48e31a7
2003-06-23 11:06:01 +00:00
drh 8ce10ba65e Make sure the source of a PULL opcode is not an ephemeral string. Ticket #360. (CVS 1031)
FossilOrigin-Name: cb70ee67ea9f5a47d58820e0e8b28c8f945217ed
2003-06-22 01:41:49 +00:00
drh 44ce7e20f8 Remove unused variable. Ticket #355. (CVS 1030)
FossilOrigin-Name: 5228cecdb84a665b96750fc0dc7c81e3f50a3ce8
2003-06-17 02:57:17 +00:00
drh 7a73eb48f8 Fix compiler errors and warnings win SQLITE_OMIT_AUTHORIZATION is defined.
Ticket #353. (CVS 1029)

FossilOrigin-Name: 6920b633c2e4a94ee5de7d2db3933a873ee3513b
2003-06-16 19:18:12 +00:00
drh d93d8a812e Add the %z format to the sqlite_mprintf() and related functions. (CVS 1028)
FossilOrigin-Name: eca1398eaac67d772aff2676a470d9a6d96a93ca
2003-06-16 03:08:18 +00:00
drh 3fc673e622 Do not flatten a subquery which is the right term of a LEFT OUTER JOIN
if the subquery contains a WHERE clause.  Ticket #350. (CVS 1027)

FossilOrigin-Name: dd8943e8583cf7ed3b662570a5607856fd246dac
2003-06-16 00:40:34 +00:00
drh f817b6be7f Preserve blank lines in the middle of SQL statements in the shell.
Ticket #352 (CVS 1026)

FossilOrigin-Name: bcf5eeecdfd9897bc7c257119d7515fd34d222c1
2003-06-16 00:16:41 +00:00
drh 4d9fc3231b Update the documentation to reflect the new capabilities of PRAGMA
integrity_check.  Rewording in the VACUUM documentation. (CVS 1025)

FossilOrigin-Name: 38461a7acb5281edd7078b1b3f227bb45f281757
2003-06-15 23:49:38 +00:00
drh ed717fe3b2 Enhance the "PRAGMA integrity_check" command to verify that all indices are
correctly constructed.  New calls to integrity_check are made in the test
suite. These changes are intended to prevent any future problems such
as seen in ticket #334. (CVS 1024)

FossilOrigin-Name: c9734c27074d2039a1896a8c6965c08d03711b13
2003-06-15 23:42:24 +00:00
jplyon 3ca691106b Updated sqlite_encode_binary() comments with tighter bounds on output length. (CVS 1023)
FossilOrigin-Name: 826aab43d5967ece2a272c49ce62021fa4a2ceb3
2003-06-15 10:35:04 +00:00
jplyon 1420010fa4 Documented integer values used by PRAGMAs.
Fixed missing end tags in generated anchors. (CVS 1022)

FossilOrigin-Name: 6c24dfbae56a16dd736de5297c1796818773df80
2003-06-15 10:29:24 +00:00
a.rottmann 831961217d * Added -version-info to shared libraries
* Remove config.h and libtool in the distclean target (CVS 1021)

FossilOrigin-Name: e13e8b05b4d146aa4ca9ed06e414e0c6a4fba4e4
2003-06-14 19:29:08 +00:00
drh c45d95f9de Bug fix: sqliteFree() called twice on the same allocation during error
handling in attach.c. (CVS 1020)

FossilOrigin-Name: 9ec40935b9435ddc3749cab517387477e4045f6b
2003-06-14 12:04:07 +00:00
drh e2227f0092 Open the journal file for read-only when doing a playback. Ticket #351. (CVS 1019)
FossilOrigin-Name: 66ac7aea3df8533a49c8c05ba57c5a7015626828
2003-06-14 11:42:57 +00:00
jplyon 892f671cf3 Added missing error string to sqlite_error_string(). (CVS 1018)
FossilOrigin-Name: 3afb7b3586be81202c76692afea9d2b7a63b4b93
2003-06-12 08:59:00 +00:00
drh 2e0d738b60 Suppress the warning message about print_node() being unused in btree_rb.c.
Ticket #347. (CVS 1017)

FossilOrigin-Name: b52f07e1c894a52bb12459d03fd0efcee05dd08c
2003-06-10 02:46:15 +00:00
drh 7571c96c4c Remove redundant "return" statement from btree_rb.c. (CVS 1016)
FossilOrigin-Name: 373d077173f1b31896dc0e0d724371dd506d52f3
2003-06-09 11:53:12 +00:00
jplyon 05e45910ca Documented SQL fns IFNULL() and NULLIF(). (CVS 1015)
FossilOrigin-Name: 190252fee0a86eb6f8c24a2402e36482e3bd514c
2003-06-08 08:36:33 +00:00
drh 6f8fd3c171 Use sqliteOsFileExists() in the debugging hook in vdbe.c, instead of access().
Ticket #341. (CVS 1014)

FossilOrigin-Name: 7d3405b95bae74e0c476a7bdf708ca518723eaf7
2003-06-07 11:33:45 +00:00
drh 94ce4c1e3b Do not assume that a pointer can fit in a long inside the printf() code.
Ticket #342. (CVS 1013)

FossilOrigin-Name: 5dad7c05e9789e101d5ce75a6f3ea2ffb278b29d
2003-06-07 11:29:50 +00:00
jplyon 048aa234ef Major update of vdbe tutorial to 2.8.0 engine. (CVS 1012)
FossilOrigin-Name: 787d986d0f391d26eef7a2639594c465f9599f5b
2003-06-07 08:57:58 +00:00
jplyon 5fa7eb0dd9 Hyperlinks and minor additions/corrections for lang.tcl (CVS 1011)
FossilOrigin-Name: 685a179aae535431ec46922f1aff50a54112e959
2003-06-07 08:56:09 +00:00
drh 81e293b4b2 Extend the authorization mechanism to disallow the ATTACH and DETACH commands.
Ticket #340. (CVS 1010)

FossilOrigin-Name: a97dca73aed0b42d8dcf944360667ae93c5324fd
2003-06-06 19:00:42 +00:00
drh 70dc85a4c2 Add btree_rb.c and opcodes.c to the source built by the "target_source" target
of the main makefile. (CVS 1009)

FossilOrigin-Name: 09546972991601697925c10b6ef31694b0be2385
2003-06-06 16:13:40 +00:00
drh d36a483704 Add a prototype for the sqlite_vmprintf() function to sqlite.h. (CVS 1008)
FossilOrigin-Name: 048cf55c7da92e363f6a2ab594e17280c9573410
2003-06-06 15:44:00 +00:00
drh b5333fa6e4 Fix a typo in speed.html. (CVS 1007)
FossilOrigin-Name: d01e6fbdde314f2edfcd43fcda3dc8bedb6bf2ba
2003-06-05 15:05:34 +00:00
drh 8649d6a1a8 Remove unused code from util.c. (CVS 1006)
FossilOrigin-Name: 1bcaa841a396e4d592de30d10846f7cefbbdcd0e
2003-06-05 14:27:56 +00:00
drh 7d02cb73ca Fix a bug in UPDATE OR REPLACE that was introduced by check-in (999).
Also clean up some compiler warnings for VC++. (CVS 1005)

FossilOrigin-Name: af6f2bdf59fb621ff3e1d061e429f01ebd7d0b42
2003-06-04 16:24:39 +00:00
drh b8ec20925d Adjust test cases to cope with the extra column returned by the database_list
pragma. (CVS 1004)

FossilOrigin-Name: fa10c6df5a80127508fb198c21ef93acfc93ebe2
2003-06-04 15:53:02 +00:00
drh 5e8e1981dc Change the "database_list" pragma to return a third column containing the
filename of the underlying database file.  Always use an in-memory TEMP
database with an in-memory main database. (CVS 1003)

FossilOrigin-Name: f39100f5759d0d8b9c71e18d38a148dee4643020
2003-06-04 15:48:33 +00:00
drh ca3bdaca19 Version 2.8.3 (CVS 1002)
FossilOrigin-Name: 433570e3e6caa52b9e480a22529dde6385a3c7d3
2003-06-04 12:44:27 +00:00
drh b6ec9fed20 Update the version number to 2.8.3. (CVS 1001)
FossilOrigin-Name: c96f5bf0d7b75c8091f78dc2b9e3937949642ce5
2003-06-04 12:40:43 +00:00
drh bc2bca0843 Disable the unreadable file test (attach-6.2) under windows because of
problems in the OS. (CVS 1000)

FossilOrigin-Name: 4bfb30d20bdd33c6e26c8fb8392a75d3cf2ee4bd
2003-06-04 12:31:53 +00:00
drh 5383ae5c12 Avoid corrupting indices when doing a REPLACE on a table with an
INTEGER PRIMARY KEY that also has another index.  Ticket #334. (CVS 999)

FossilOrigin-Name: e813faae0e4086571d13c769f793add7f1f979af
2003-06-04 12:23:30 +00:00
drh 4312db55d9 Additional testing of the ATTACH command with bug fixes for the new problems
that the tests found. (CVS 998)

FossilOrigin-Name: 3e8889d7ce5e99fc855526fc1bb62ddbe282bfc5
2003-06-03 01:47:11 +00:00
drh 1aa4965ae3 The OP_Checkpoint opcode is now a no-op if invoked on a database that already
has an active checkpoint journal.  Ticket #333. (CVS 997)

FossilOrigin-Name: daf7b94017f03638da1ef65830f3762be030b93c
2003-06-02 23:14:13 +00:00
drh 2394e376d6 Fix a bug in the COPY command introduced by check-in (991). (CVS 996)
FossilOrigin-Name: 77ec13dab85b70795ef06ff2c714cca0cd496837
2003-06-02 22:50:25 +00:00
drh ade106c14a Fix an initialized variable in sqliteInitOne. (CVS 995)
FossilOrigin-Name: 89957b09ce746cf98d5d75cab2a23994e27c4937
2003-06-02 18:17:33 +00:00
jplyon 5959abd5d0 Generate anchors in opcode table html for use by new vdbe tutorial. (CVS 994)
FossilOrigin-Name: 3ae36cf158e1878a66ce9302eae4e62f8a88333f
2003-06-02 06:29:31 +00:00
jplyon 02be20d4f5 Added comments. (CVS 993)
FossilOrigin-Name: 1276ddb3074b74e22c579bad6951ea52384c08dd
2003-06-02 06:17:10 +00:00
jplyon 5a56422a29 Additions and corrections to vdbe documentation comments. (CVS 992)
FossilOrigin-Name: b648987de3383d6835df58aa0efee54fa8f10d26
2003-06-02 06:15:58 +00:00
drh a0217ba720 Add the ability to INSERT or UPDATE using the "rowid" column even on tables
that lack an integer primary key. (CVS 991)

FossilOrigin-Name: 903adbe802ca0e987b867e5ad33aae02ad2a43d4
2003-06-01 01:10:33 +00:00
drh f26e09c87f Tighter binding of views, triggers, and indices to their respective
databases.  Ticket #323.  Much more testing needs to be done to the
sqliteFix...() routines in attach.c. (CVS 990)

FossilOrigin-Name: 7202d4f1a8853368954a967b7ccca9d8a6645a2e
2003-05-31 16:21:12 +00:00
drh 8372b8d134 Change the row-size limit back to 1MB. It was temporarily raised to 16MB.
We'll probably move it to 16MB eventually, but not just yet. (CVS 989)

FossilOrigin-Name: b84c4035c6b06469055798cf412fa4da8b50fa17
2003-05-29 17:50:55 +00:00
drh 9ac717d7f6 Modify the windows locking code so that it works correctly for a database
being shared between Win95/98/ME and WinNT/2K/XP systems.  Ticket #310. (CVS 988)

FossilOrigin-Name: 8c402db7e0745622d9950e5ca5d4d8e933da436c
2003-05-29 17:43:08 +00:00
jplyon 124e74e685 Added typeof() operator.
Minor additions for ATTACH/DETACH. (CVS 987)

FossilOrigin-Name: 8b8fa0fff26107912f0bec4e44df207c7885e273
2003-05-29 04:21:38 +00:00
drh 6e1d288a9f Fix segfault that occurs when opening a non-existing database in the shell
then immediately doing ".q". (CVS 986)

FossilOrigin-Name: e8566cf5a381fa7655caacbc0fe95091e1137fea
2003-05-19 23:55:30 +00:00
drh 6b8611126b Additional attach testing. I now believe that ticket #317 was fixed
by check-in (981). (CVS 985)

FossilOrigin-Name: 24191373796b7fd6255ef9b70ce2344326308113
2003-05-17 19:23:51 +00:00
drh 79a519c047 Prevent an infinite loop when deleting a table that has a TEMP trigger. (CVS 984)
FossilOrigin-Name: c8c823b068916711857fa67db10fb479999b55c2
2003-05-17 19:04:03 +00:00
drh 24f1eb74c8 Version 2.8.2 (CVS 983)
FossilOrigin-Name: f542e5fc8896111e5165cc625607f95e4993bb16
2003-05-17 17:52:34 +00:00
drh 369986a75f Bump the version number and update the change log. We are rushing out
release 2.8.2 because of the database corruption problem fixed by
the previous check-in. (CVS 982)

FossilOrigin-Name: e134459d653b03bfacb98eec2c5d91eef7e4ed24
2003-05-17 17:38:37 +00:00
drh 8bf8dc9208 Fix problems with TEMP indices that lead to corrupt databases. These
problems were discovered while working on ticket #317.  No sure yet if
that ticket is fixed. (CVS 981)

FossilOrigin-Name: 01398fb78bab7e5c6f439f2b743f26e82118468a
2003-05-17 17:35:10 +00:00
drh 0594f5b97e Version 2.8.1 (CVS 980)
FossilOrigin-Name: 590f963b6599e4e235d7369f19c63cece4b2ad95
2003-05-17 02:44:32 +00:00
drh 8971527208 Fix the fix for newlines in echo commands. Tickets #311, #282, #256. (CVS 979)
FossilOrigin-Name: baea7aca10e30f30b874e1e8b6cd3b05954ba83c
2003-05-17 02:27:21 +00:00
drh 8625f9fe38 Bump the version number to 2.8.1. Update documentation prior to release. (CVS 978)
FossilOrigin-Name: 0874814ab01ffc0acffec8e6cec34eaab3428d36
2003-05-17 01:39:39 +00:00
drh 299fa266df Escape backslashes in echo commands in the makefiles. Tickets #311, #282, #256. (CVS 977)
FossilOrigin-Name: d614861b8ad9e661b8f08131b95d730e2c2c35c2
2003-05-17 00:24:21 +00:00
drh 9335247003 Fix memory allocation problem in the sqlite_get_table() API. Ticket #315. (CVS 976)
FossilOrigin-Name: f1d955efd91093994db43a1540080d32442d5ac0
2003-05-17 00:05:49 +00:00
drh a996e477d0 Make sure the ON CONFLICT clause on a BEGIN overrides the conflict resolution
specified by an index.  This fixes a bug reported on the newsgroup. (CVS 975)

FossilOrigin-Name: 0f92736d1fbe3b587592fe1f26dfb3558cc49727
2003-05-16 02:30:27 +00:00
jplyon 931634915d Removed 3rd (file) column from PRAGMA database_list until tests are fixed. (CVS 974)
FossilOrigin-Name: 4183cf97676e64d19978941a7c4a3fe521fcb1fb
2003-05-13 08:01:33 +00:00
drh 39581966a0 Fix another twos-complement negation error. Ticket #313. (CVS 973)
FossilOrigin-Name: f267a8a4ff52eb7ee3ac20a8e3a8ab5fe19e445d
2003-05-13 01:52:31 +00:00
drh 3b2129cf77 A change to lemon related to ticket #313. (CVS 972)
FossilOrigin-Name: b59d9033d5556015543ac5ca23110ccbeb4391f0
2003-05-13 00:34:21 +00:00
drh fe4184f8d1 Remove unnecessary "#include <sqliteInt.h>" from the shell code. (CVS 971)
FossilOrigin-Name: 6e5c497a42e52236edae8d99b4892d4b93db43f5
2003-05-13 00:24:41 +00:00
drh e62720d1f1 Fix a #ifdefs that are used to comment-out the VACUUM command. (CVS 970)
FossilOrigin-Name: 22d5324073a727627d4294870a441fa2316fb049
2003-05-13 00:21:59 +00:00
drh 5364f60302 Make sure hash functions always return non-negative. (CVS 969)
FossilOrigin-Name: 39a3e403f0440acb2f85a064ec23d404f9cdfbc4
2003-05-12 23:06:52 +00:00
jplyon 5ca89c3d28 Changed PRAGMA database_list to show the filename. (CVS 968)
FossilOrigin-Name: 3da10d2d02e331f136fcf857dc4c435c67ee7196
2003-05-11 20:09:19 +00:00
jplyon 672a1edfc8 Changed ".databases" command to use PRAGMA database_list. (CVS 967)
FossilOrigin-Name: bad2065337d8dcaacd519b8f1730a90f1c933c3e
2003-05-11 20:07:05 +00:00
drh 5fe2d8c913 Changes to comments. In particular, a lengthy comment was added to encode.c
that explains how the encoder algorithm works. (CVS 966)

FossilOrigin-Name: 8b388b2f690dbfd50eefc0fdede1c7785f78afa1
2003-05-10 03:36:53 +00:00
jplyon a3643a2697 Removed never-used symbol SQLITE_ResultDetails. (CVS 965)
FossilOrigin-Name: 26bd7bb1779e14f19c00e450aaa9529f2aabf131
2003-05-10 03:04:34 +00:00
jplyon f60482044d Removed never-used pragma "result_set_details". (CVS 964)
FossilOrigin-Name: bf558e79524c04339f1174dc935e39d47cb33457
2003-05-10 03:03:34 +00:00
jplyon 9098056e6f Documented the "GO" and "\" command terminators. (CVS 963)
FossilOrigin-Name: 6a76bd9590f372411e697f002285fe36ff3787ee
2003-05-10 02:54:56 +00:00
jplyon df2245df05 Fixed metacharacter coloring with LP, RP, PLUS.
Added more links. (CVS 962)

FossilOrigin-Name: 2bbb08049508829419dd9a3729241b97b017cf36
2003-05-10 02:54:02 +00:00
drh f94e371bbf Format keyword lists in lang.html using a TCL proc. (CVS 961)
FossilOrigin-Name: ca75f1ca12cd88dce688e272d73c3c2282079547
2003-05-07 13:37:31 +00:00
jplyon 3aacc84e45 - Added entries for PRAGMAs database_list, temp_store and default_temp_store.
- Fixed missing end tags. (CVS 960)

FossilOrigin-Name: 55ae7b35ee2dcebc99256d4b1e22a87ea75e3d03
2003-05-07 04:04:17 +00:00
jplyon b2ca13ed4d Cleaned up keywords section. (CVS 959)
FossilOrigin-Name: bb609f96e00fd62d932601c4aa37bc17baa82257
2003-05-07 03:59:10 +00:00
drh 8af4d3ace6 Restrain the flattener in the presence of outer joins. Ticket #306. (CVS 958)
FossilOrigin-Name: 6d4b6597e560578253960d9876dc8c8657f41fef
2003-05-06 20:35:16 +00:00
drh 66b4ebafb2 Added tests trying (unsuccessfully) to reproduce ticket #304. (CVS 957)
FossilOrigin-Name: fda637f453d35b74f676997fcf056a948ccd771b
2003-05-04 20:42:56 +00:00
drh e1e38c4d7d Shell command-line parsing enhancements suggested by Mike Hall. (CVS 956)
FossilOrigin-Name: 5656fe48b192dc84cb5977f826ff99d81684791f
2003-05-04 18:30:59 +00:00
drh 7ad4334add Fix deficiencies in sqlite_complete() pointed out by R. Dennis Cote. (CVS 955)
FossilOrigin-Name: 54b33a5ed9f7a89435c2f1395a3177e8c778bb8a
2003-05-04 17:58:25 +00:00
jplyon 5640433e48 Added shell command ".databases" to list name and file of open ones.
Added several missing shell commands. (CVS 954)

FossilOrigin-Name: dd57d6ae6a247824e44a6073bc7e73ecb3c500fd
2003-05-04 07:31:09 +00:00
jplyon 6a65bb3c06 added shell command ".databases" to list name and file of open ones. (CVS 953)
FossilOrigin-Name: 741a5a8d3975fb5db18914b7879b12aead59279b
2003-05-04 07:25:57 +00:00
jplyon b24fe71970 new section for keywords, more docs for attached databases , links, cleanup (CVS 952)
FossilOrigin-Name: 87e1b6a936972670771cf90670aeb4308ba0a30a
2003-05-04 07:02:55 +00:00
drh e96fa95e8a More documentation updates. (CVS 951)
FossilOrigin-Name: 24b9b569240d2108b17420d85cafdc718c67269f
2003-05-03 19:04:03 +00:00
jplyon 2bfc9dbdcf - added entry for ATTACH DATABASE.
- added entry for DETACH DATABASE.
- added soundex() function.
- added some new TEMP modifiers.
- added new VACUUM behavior.
- added the Oracle8 outer join "(+)" syntax.
- documented the modulus/remainder operator %.
- added ALL as alternative to DISTINCT in SELECT.
- fixed assignment list in UPDATE to use * metacharacter.
- fixed value in PRAGMA to be optional.
- added link from INSERT topic to REPLACE.
- added optional CONSTRAINT <name> before column constraints.
- skip 2 lines before each Section in the TCL source. (CVS 950)

FossilOrigin-Name: fd28c5229ece1d90e24d0ecaa518d8df5a4f55f0
2003-05-03 04:55:19 +00:00
drh e9ffc168d8 Additional tests of the new flattener added. Ticket #272. (CVS 949)
FossilOrigin-Name: 8d9ee45ab487614191e8d6aef845141fdddf832a
2003-05-02 16:44:25 +00:00
drh c31c2eb82c Enhance the query flattener to handle subqueries that are joins.
All regressions pass but new tests need to be added before release.
Ticket #272. (CVS 948)

FossilOrigin-Name: ad57693e9f1b83a8cc4d028264b35018a9a4a701
2003-05-02 16:04:17 +00:00
drh 6a3ea0e6ef VDBE cursors numbers for tables in a join do not have to be consecutive.
This is one step on the road to fixing ticket #272. (CVS 947)

FossilOrigin-Name: be7aed2011b4af868b6a0c370c3d41354ae0cdf4
2003-05-02 14:32:12 +00:00
drh 56e452cf3a Correctly create an index that uses an INTEGER PRIMARY KEY as one of columns
to be indexed. (CVS 946)

FossilOrigin-Name: 6d019e0baa3219614a9bc5b550a0f9fe3f7e731a
2003-05-01 16:56:03 +00:00
drh 44c2eb128d In the shell tool, delay opening the database until it is needed but also
make sure it is opened before trying to use the "db" pointer.  Ticket #302. (CVS 945)

FossilOrigin-Name: 20fcead42bc875f13eec52971530342ff00c5eda
2003-04-30 11:38:26 +00:00
drh a9b1716296 Accept a "/" or "go" on a line by itself as an SQL statement terminator
in the command-line shell.  This allows SQL Server and Oracle scripts to
be played into SQLite without change. (CVS 944)

FossilOrigin-Name: 8211f57b38b87a42c856e267bd243984b5abf9cc
2003-04-29 18:01:28 +00:00
drh 86e5cc058d Allow the ASC or DESC keyword to appear after a column name in a CREATE INDEX
statement.  SQLite indices are aways ASC (ascending) regardless of which
keyword is used. (CVS 943)

FossilOrigin-Name: 1a0c542088618ba24d1efae9b13a8eca104d6cc8
2003-04-29 17:19:18 +00:00
drh 63eb5f294c The sqlite_complete() function should ignore carriage-return characters.
(Oops - some unrelated edits also made it into this check-in.) (CVS 942)

FossilOrigin-Name: c6bf62e41cf44e8ebf740b103204b00e8b826c90
2003-04-29 16:20:44 +00:00
drh 7d8085a8e4 In the test code, make several attempts to convert a pointer to a string
and test each attempt to make sure it works before returnning, in order to
work around incompatibilities between various systems.  Ticket #284. (CVS 941)

FossilOrigin-Name: 333011ffddc0be91f76811458f03ad1ec0331b51
2003-04-26 13:19:38 +00:00
drh 70c7a4b1da Fix the shell tool to do a better job of ignoring whitespace. Ticket #234. (CVS 940)
FossilOrigin-Name: 639957e9f793eddce027050d2655863d82fe8ac9
2003-04-26 03:03:06 +00:00
drh 4328c8b7c7 Only print the "Loading resources from..." line when the output is a TTY.
Ticket #168. (CVS 939)

FossilOrigin-Name: 92ded93376635f37e2f5a7a8f4077c85d5bce735
2003-04-26 02:50:11 +00:00
drh aba46b19f5 Do not use the return value of fcntl() to find the reason that it failed.
Use errno instead.  Tickets #240 and #270. (CVS 938)

FossilOrigin-Name: acf9e9802fa6396df5653ca4e72ab4ec2333509d
2003-04-26 02:40:45 +00:00
drh 524a5bf5f6 Fix the sqlite_complete() routine so that it recognizes /*...*/ comments.
Ticket #277. (CVS 937)

FossilOrigin-Name: ef8eb580fc6c40264219c2ae77a9c4f8a5803c8b
2003-04-26 02:31:54 +00:00
drh 85e2096fb6 Report the correct authorization context in the authorization callback
when coding an INSTEAD OF trigger on an update or delete. (CVS 936)

FossilOrigin-Name: 67746833fc8de3afff80db413bd63a362bb28218
2003-04-25 17:52:11 +00:00
drh 2e6d11bc07 Add tests to insure VACUUM works in the presence of I/O errors. Fix some
problems that came to light by these tests. (CVS 935)

FossilOrigin-Name: 8d3e879349fc9523c72cb46111e0058b57ce9341
2003-04-25 15:37:57 +00:00
drh 9c05dc6298 Work around a name collision problem on windows. (CVS 934)
FossilOrigin-Name: c3b1f84dfce13b2523c9923e4270577862ca0595
2003-04-25 13:28:02 +00:00
drh f7c5753174 Make VACUUM work even if multiple processes have the database open at once. (CVS 933)
FossilOrigin-Name: caa960289f3d1f5e8f35a94e9e4321996c211ed2
2003-04-25 13:22:51 +00:00
drh fd9903de51 Explicit casts to squelch bogus warnings for vc++. Ticket #194. (CVS 932)
FossilOrigin-Name: cb808c14bc14e7bd1cfff134ae5206ace451f2df
2003-04-25 03:13:25 +00:00
drh 45a304ee8c Get VACUUM working again - with test cases. Some other minor cleanups. (CVS 931)
FossilOrigin-Name: 5afb88008fed253e6d1fc0ed5172370b61d3727b
2003-04-25 02:43:08 +00:00
drh 5cf590c128 Fix some issues with INSTEAD OF triggers. (CVS 930)
FossilOrigin-Name: 206b17397b1d2b55179c935927ff1d8215728c32
2003-04-24 01:45:04 +00:00
drh b5a20d3ceb Remove the begin_hook and commit_hook APIs. They were a bad idea. Add a
"trace" method to the TCL interface. (CVS 929)

FossilOrigin-Name: 6289b863590ecc5de3d1efaaa60aa6f3f64fefb3
2003-04-23 12:25:23 +00:00
drh e22a334b78 Update the authorizer API so that it reports the database that table and
indices belong to and so that it reports when actions are taken in response
to a trigger. (CVS 928)

FossilOrigin-Name: c675a5504138f34cae6def782b5d3add2c67d2bc
2003-04-22 20:30:37 +00:00
paul 3837237959 Check for readline libs now adds appropriate curses or termcap lib when needed (CVS 927)
FossilOrigin-Name: 393dd91c252531bb5abfe424b86a5f7eb20edcfc
2003-04-22 08:04:49 +00:00
drh f0f258b11b Add support for TEMPORARY triggers. Such triggers can write temporary or
permanent tables. (CVS 926)

FossilOrigin-Name: 58ddd587b0f5d565ae3b0ba3a1fa5c20d459f3fc
2003-04-21 18:48:45 +00:00
drh 881b890af4 Add more tests for the in-memory database. (CVS 925)
FossilOrigin-Name: 11cab41c4f02cdddc4fd3f57555573ac2814a81b
2003-04-20 23:45:23 +00:00
drh b2fe7d8cb7 Added tests for the in-memory database backend. Also updated some comments
in other modules. (CVS 924)

FossilOrigin-Name: fb89adf4d1325c5ea471759ebfd8df7faa4f9a80
2003-04-20 17:29:23 +00:00
paul 2dc96f9eb8 Align config vars controlling in-memory DB with code (CVS 923)
FossilOrigin-Name: 921656db9e3df865aea6b1abe1bc40b1acbeeb47
2003-04-20 11:46:34 +00:00
paul f00993a30a Reset pCur->eSkip on a MoveTo (CVS 922)
FossilOrigin-Name: d983accf4a702158f03742fb11959d0fd035a4b4
2003-04-20 11:41:04 +00:00
drh ea1ba17cda Update comments. Remove unused field from the Index structure. (CVS 921)
FossilOrigin-Name: 7084e05093e72f6e5b65ff0b574336898396826f
2003-04-20 00:00:23 +00:00
drh 7bdc0c1def Modify the optimizer so that it does not assume that functions are
constant. (CVS 920)

FossilOrigin-Name: 767f1af236d115e8388e1dcc28a4df1be48d6c85
2003-04-19 17:27:24 +00:00
drh 37ea94b8c9 Bug in WHERE clause processing fixed. Ticket #298. (CVS 919)
FossilOrigin-Name: 9b619c98b586a207a87942640d3a94220ff8ab02
2003-04-19 16:34:04 +00:00
drh 9d10f1d0f6 fix a memory leak in btree_rb.c. (CVS 918)
FossilOrigin-Name: 1e3d0d094776c2a429fa2a3eebc036a0b6374862
2003-04-18 22:52:38 +00:00
drh cab20050bb Fix for ticket #297 - bug in sqliteSortCompare(). (CVS 917)
FossilOrigin-Name: 4ded1965eb83dee0f28c27ba935d615c77331571
2003-04-18 17:45:14 +00:00
drh a5f668327b The VACUUM command is now functioning (again). Need to do more testing. (CVS 916)
FossilOrigin-Name: 6e948d9aaea109c683ac4fcc4714e335b545d22b
2003-04-18 02:31:04 +00:00
drh a69d91681d Fix triggers to work in an ATTACHed database. Ticket #295. (CVS 915)
FossilOrigin-Name: 1e5e00fb73c308378efd034cb291caf338c9fe84
2003-04-17 22:57:53 +00:00
drh d4d595f94c Make sure the min() and max() optimizations work on empty indexed tables.
Ticket #296. (CVS 914)

FossilOrigin-Name: 98ef6110068e5ed3cd77a14b004f890b79b731f7
2003-04-17 12:44:23 +00:00
drh 8396566204 Change the shell to use the sqliteIsNumber() routine for determining if
values are numeric.  Modified os.c so that it should now work with DJGPP -
though I have no way of testing this. (CVS 913)

FossilOrigin-Name: 35caefe31750fd103b5f0231ad36f375771063eb
2003-04-17 02:54:13 +00:00
drh 95b5084409 Rollback if a commit hook fails. (CVS 912)
FossilOrigin-Name: 5cea7554ae9d36434cd7261b5b40f3d467b836f1
2003-04-16 21:03:13 +00:00
drh 027850b676 Fix the authorizer so that it correctly interprets attempts to read the
OLD and NEW pseudo-tables of a trigger. (CVS 911)

FossilOrigin-Name: f04bd43254b3ba3fccc842214115d4c298e28138
2003-04-16 20:24:52 +00:00
drh bb07e9a34f Simplify the number processing code. Fix for ticket #281. (CVS 910)
FossilOrigin-Name: 4326b52a39cad4632dc2db37aa53a285a31af138
2003-04-16 02:17:35 +00:00
drh 144f9eadf6 Remove some unnecessary code and complication from the btree interface. (CVS 909)
FossilOrigin-Name: 35cc7c7d37d9ca486e7f300efe80a78a7f1064e2
2003-04-16 01:28:16 +00:00
drh 70ce3f0c58 Get triggers working on tables with INTEGER PRIMARY KEYs. Ticket #291.
This may also fix #159.  Still need to add tests so both bugs remain open
for the time being. (CVS 908)

FossilOrigin-Name: 0b996959b8d8bc2c82eab9cccc190befd0056505
2003-04-15 19:22:22 +00:00
paul 048bd5937b Added btree_rb.c (CVS 907)
FossilOrigin-Name: 93eb6c52aca8de15a88247ec986c36245527ec7b
2003-04-15 17:22:30 +00:00
drh 49449834fc Do not record the inserted rowid on when doing an INSERT within a trigger.
Ticket #290. (CVS 906)

FossilOrigin-Name: 96a717661a3b7108fe0cacb588d81fd8e91eb640
2003-04-15 14:01:43 +00:00
drh f9a2e7bb8d Change lemon to use <stdarg.h> instead of <varargs.h> because GCC no longer
supports varargs.h.  Tickets #288 and #280.  Ironically, lemon originally
used varargs.h because stdarg.h was not supported by the compiler I was
using in 1989 (which was gcc if I recall correctly.) (CVS 905)

FossilOrigin-Name: 7902e4778ec86e25ad949ae7a6d55b63ac0e85f3
2003-04-15 01:49:48 +00:00
drh 13bff81537 Change some variable names and comments in the new in-memory database file
implementation.  Partial (non-working) implementation of the VACUUM command. (CVS 904)

FossilOrigin-Name: e76787f877c456abdc8bc88bfefc50eaeed68744
2003-04-15 01:19:47 +00:00
paul b0208ccaa3 Support in-memory databases for temp tables (CVS 903)
FossilOrigin-Name: 96336bffde6c441af197a521ee9e56fdfd7efff8
2003-04-13 18:26:49 +00:00
drh c11d4f9360 Split the implementation of COPY, PRAGMA, and ATTACH into separate
source code files. (CVS 902)

FossilOrigin-Name: 73359037ea639abb066c74db9c19e84bf1104006
2003-04-06 21:08:24 +00:00
drh e1051c653e Move the implementation of VACUUM into a separate source file. (CVS 901)
FossilOrigin-Name: b123c165fd3d0a5a86ee8a7baa669105dafb481a
2003-04-06 20:52:32 +00:00
drh 73509eee84 Simplify the BTree interface by shortening names. Added two new methods
for accessing the current filename and for changing the name of the
database file. (CVS 900)

FossilOrigin-Name: 185d8dc8d0c26cef36aeba6992823e5124af4056
2003-04-06 20:44:45 +00:00
drh a73af533de More testing of ATTACH and DETACH. (CVS 899)
FossilOrigin-Name: 51f515f28cb1cc3e8f0c3531724dc8876b25f18e
2003-04-05 16:56:28 +00:00
drh 2d4583473b Begin testing the new ATTACH and DETACH commands. (CVS 898)
FossilOrigin-Name: 7a0f8024a1323a15d0c83afe9302400736f01fe8
2003-04-05 03:42:26 +00:00
drh f539f6a7e9 Fix for ticket #276. (CVS 897)
FossilOrigin-Name: 452128c6fd9a0d82bfab21374fc2041638d264db
2003-04-03 19:35:02 +00:00
drh 0d1a643aea Added experimental APIs: sqlite_begin_hook() and sqlite_commit_hook(). (CVS 896)
FossilOrigin-Name: 5efbf62313519d0a6e8b8f5dbb29d3ef428d73e8
2003-04-03 15:46:04 +00:00
drh 048c530c01 Use a intermediate table when inserting a TEMP table from a SELECT that
reads from that same TEMP table.  Ticket #275. (CVS 895)

FossilOrigin-Name: 087d1e83af12b3a9aedd4945f02774a1043b1eb4
2003-04-03 01:50:44 +00:00
paul b95a8864c9 Add infrastructure to suport multiple btree implementations (CVS 894)
FossilOrigin-Name: 79b3aed2a74a67cbad631c4e2e4a43469d80c162
2003-04-01 21:16:41 +00:00
drh 738a68b250 Minor follow-on changes to the recent ATTACH patch. (CVS 893)
FossilOrigin-Name: 11378c5bf988412f8564cdc0314fc241793b292e
2003-03-31 13:36:09 +00:00
drh 665de47ac3 Minor follow-on changes to the recent ATTACH patch. (CVS 892)
FossilOrigin-Name: e80afe75b33d4eacb40ef6128cf688f7c3253984
2003-03-31 13:36:09 +00:00
drh da93d238c2 Add the sqliteErrorMsg() function and use it to generate error message
text during parsing and code generation.  This simplifies the code
somewhat and makes it easier to handle names with a database prefix. (CVS 891)

FossilOrigin-Name: 1d3fc977211abdc7ba3fd51d661863e8ce5aef69
2003-03-31 02:12:46 +00:00
drh 1c2d84148a The ATTACH and DETACH statements are now coded but are still mostly untested. (CVS 890)
FossilOrigin-Name: c7c5e927a54f0fbc2ca625754787aff4d9c4eff1
2003-03-31 00:30:47 +00:00
drh 180487389b Remove the experimental sqlite_open_aux_file() API. It will soon be replaced
by ATTACH and DETACH SQL commands. (CVS 1732)

FossilOrigin-Name: 0a358844e40020557c1aeea5779b194670350930
2003-03-30 19:17:02 +00:00
drh 3aa31a16e6 Remove the experimental sqlite_open_aux_file() API. It will soon be replaced
by ATTACH and DETACH SQL commands. (CVS 889)

FossilOrigin-Name: b6d6e07f3a5cb493f2cf0675bc6061c5afe5c078
2003-03-30 19:17:01 +00:00
drh 9077ba8ee5 Remove the obsolete documentation on how to crosscompile version 1.0 of
SQLite. (CVS 888)

FossilOrigin-Name: ac0622bf5fca9c8907319a20158e991efdaa6402
2003-03-30 18:58:58 +00:00
drh 1dd8c40e8f Detect when a child node of a btree page has zero entries and report that
as a case of database corruption. (CVS 887)

FossilOrigin-Name: 66c80ae232a78ecb010280ab1aa684cb78b0662f
2003-03-30 18:41:22 +00:00
drh 0be9df076a Fix a memory leak in triggers and update tests to show the latest error
message text. (CVS 886)

FossilOrigin-Name: b90d9de32d10a71fe81f5bfd0cf57faae8c5c3b4
2003-03-30 00:19:49 +00:00
drh 812d7a21dd Regression tests now work - except for some changes in error message
text.  The library is now safe to use for experimental work. (CVS 885)

FossilOrigin-Name: 8a593e9c2d57e758739a7ef54fa40ca6a0071a9a
2003-03-27 13:50:00 +00:00
drh 0951d703f2 Fix a segfault in the trigger code. (CVS 884)
FossilOrigin-Name: 7672914b196cd55744edda8e5d8f1b7b86f898f9
2003-03-27 13:01:28 +00:00
drh 1694cab424 Changes to the "sqlite" structure that allow simultaneous operations on
multiple database files.  Many regession tests pass - but not all of them.
Do not use this version except for debugging SQLite itself. (CVS 1731)

FossilOrigin-Name: 9ac71c329e17a0934d2a824eacc33e9a2ebce7c3
2003-03-27 12:51:25 +00:00
drh d24cc427b7 Changes to the "sqlite" structure that allow simultaneous operations on
multiple database files.  Many regession tests pass - but not all of them.
Do not use this version except for debugging SQLite itself. (CVS 883)

FossilOrigin-Name: d2fb2bb50cf1e13feb90995079f291384abd6ba9
2003-03-27 12:51:24 +00:00
a.rottmann 84e6335c0c Re-generated. (CVS 882)
FossilOrigin-Name: f0c5bcf72cf393ea4c5cd126d085cb959eebd5f2
2003-03-24 09:42:16 +00:00
a.rottmann 62507b650a Updated libtool. (CVS 881)
FossilOrigin-Name: b1ca4e13dcab92cc532f4051f24bf5b1be251463
2003-03-24 09:40:34 +00:00
a.rottmann c7e9383a9e Added pkg-config support. (CVS 880)
FossilOrigin-Name: ec1c5a611307047dd0049353e989e75dcaffaa45
2003-03-24 09:39:32 +00:00
drh 113088ec68 Record the database name in addition to the table name for DELETE, INSERT,
and UPDATE statements. (CVS 879)

FossilOrigin-Name: a5d8fc95ee58dc3205a0bbbcadaa3b9c902a941b
2003-03-20 01:16:58 +00:00
drh 001bbcbb8f Modifications to the VDBE to support more than one database file. (CVS 878)
FossilOrigin-Name: 875da9eed981bfa27b98e95025f9fdbed74b4098
2003-03-19 03:14:00 +00:00
drh 9468c7f489 Do not allow an empty string to be inserted into an INTEGER PRIMARY KEY. (CVS 877)
FossilOrigin-Name: 2aba40bea5fc1c4aef8cfd4c790d40808821ca14
2003-03-07 19:50:07 +00:00
drh 2299706c2a Add more tests to make sure that sqlite_changes() works when using the
non-callback API.  Ticket #250. (CVS 876)

FossilOrigin-Name: 13e501d190e327cc6fc16e182819ea9d7bb9c566
2003-03-01 19:53:15 +00:00
drh dde85d9e00 Get the non-callback API working with the EXPLAIN keyword and for PRAGMAs.
Tickets #258 and #257.  Update the API documentation on the sqlite_changes()
routine to explain how it works with the non-callback API.  Ticket #250. (CVS 875)

FossilOrigin-Name: 620e1065e978545dd7bf6fa6fad1e6b93918dbf8
2003-03-01 19:45:34 +00:00
drh 627a71efa7 Fix a memory leak associated with PRIMARY KEY in a CREATE TABLE statement
that fails.  Ticket #249. (CVS 874)

FossilOrigin-Name: 8e9dc567996c3301c14a1f055ff2265770cbc3e1
2003-02-26 13:52:52 +00:00
drh e0194f2bbd Fix a memory leak associated with PRIMARY KEY in a CREATE TABLE statement
that fails.  Ticket #249. (CVS 1730)

FossilOrigin-Name: 66158843dfa073ffb8779a5170e091cebc018855
2003-02-26 13:52:51 +00:00
drh 50cceb36b6 When the right table in a LEFT OUTER JOIN contains an INTEGER PRIMARY KEY
make sure that key is NULL if there is no row in the right table that
matches the current row in the left table.  Tickets #246 and #247. (CVS 873)

FossilOrigin-Name: 6a45fe3bd7e19cf9c20fc6cb65b0269cdd704490
2003-02-20 01:48:12 +00:00
drh e6da3c1816 Fix the parsing of the LIMIT clause when the limit and offset are separated
by a comma.  The offset comes before the limit in that case. Ticket #245. (CVS 872)

FossilOrigin-Name: 6ef91a364b2922f078b7de81816bca3f2ca0fe46
2003-02-20 00:44:52 +00:00
drh 30710453ca Version 2.8.0 (CVS 870)
FossilOrigin-Name: 5db98b3f4048fc8cd28d8fd225f2b0221ccf1d17
2003-02-16 22:49:47 +00:00
drh be992ef9c9 Couple of last-minute changes before 2.8.0. (CVS 871)
FossilOrigin-Name: 8192c937d524fef703d7ba2eb608c3d74e20440f
2003-02-16 22:48:12 +00:00
drh ad636221bb Update the speed comparison documentation to show the improved performance
of PostgreSQL after performance tuning. (CVS 869)

FossilOrigin-Name: 73c904e57a158820705daf5737e0fc825cfe1aea
2003-02-16 22:36:03 +00:00
drh 94e9203247 Added test code to check for file descriptor leaks. All regression tests pass
now on both win2k and linux. (CVS 868)

FossilOrigin-Name: 75ba78280f7ab6b6acce5878859312f3223ee898
2003-02-16 22:21:32 +00:00
drh 99ee360003 Fix more bugs. The new rollback journal implementation now passes all
regression tests under Linux. (CVS 867)

FossilOrigin-Name: d10adc1c5727d76320d5919be55e86d030e9c8bc
2003-02-16 19:13:36 +00:00
drh 4303feedd3 Fix the pager so that correct rollbacks occur when synchronous is turned off.
This check-in also included unrelated documentation updates. (CVS 866)

FossilOrigin-Name: 3ef0ad8a4f2696a58aff9d812f90038c2c63f3fc
2003-02-15 23:09:17 +00:00
drh 32c4a833e0 Update the documentation for the new journal format to be introduced in
version 2.8.0. (CVS 1729)

FossilOrigin-Name: dc53d92141c931fb133149355c3a1ea64030e676
2003-02-13 02:54:03 +00:00
drh 5527f8ff4a Update the documentation for the new journal format to be introduced in
version 2.8.0. (CVS 865)

FossilOrigin-Name: e05a7a552f694158ee449d8682f5c137f1c2f2ac
2003-02-13 02:54:03 +00:00
drh 4a0681ef1b Fix a bug in the rollback logic for the new journal format. (CVS 864)
FossilOrigin-Name: 7c22aa3f817e737cfd943d903856756468e8678b
2003-02-13 01:58:20 +00:00
drh 8ba1b31379 Added the new FULL option to the SYNCHRONOUS pragma. Still need to test it. (CVS 1728)
FossilOrigin-Name: 8968bc063607856775ad63b6594d40c55cf288c0
2003-02-12 14:09:43 +00:00
drh 973b6e333d Added the new FULL option to the SYNCHRONOUS pragma. Still need to test it. (CVS 863)
FossilOrigin-Name: 792a9e157dd066fcaffd4f5b373010151fb4ca61
2003-02-12 14:09:42 +00:00
drh d8d66e8ca0 Fix a bug in the legacy journal format writing logic. (CVS 862)
FossilOrigin-Name: 6c927dd36c19ebb8bb8222b4d18ed67f4fe733e8
2003-02-12 02:10:15 +00:00
drh 968af52acf Modify the journal format to be more robust against garbage that might appear
in the file after a power failure.  The changes are mostly working but more
testing is still required.  This check-in is to checkpoint the changes so far. (CVS 861)

FossilOrigin-Name: 8ec5632536eea31197a3b1fd6abc57881a0cf1d7
2003-02-11 14:55:40 +00:00
drh 324ccefeb5 Make the shell run much faster for inputs where a single SQL statement spans
thousands of lines by avoiding the call to sqlite_complete() unless the
input ends in a semicolon. (CVS 860)

FossilOrigin-Name: e21afb82b53eade9ee267a97c58db0606f0c0a41
2003-02-05 14:06:20 +00:00
drh bb999ef6fa Make the GROUP BY clause work even if there are no aggregate functions. (CVS 859)
FossilOrigin-Name: b68792315883eed8523f5e11856ec8378dc972c1
2003-02-02 12:41:25 +00:00
drh 17e9e29d1e When a CREATE TABLE ... AS SELECT statement fails, make sure the table name
is removed from the internal hash tables.  Ticket #238. (CVS 858)

FossilOrigin-Name: 65264780c553e8a00ec7a40cf76b89a11b245faf
2003-02-01 13:53:28 +00:00
drh dcd997ea2e The sqlite_exec() function now returns SQLITE_AUTH when authorization fails.
Ticket #231. (CVS 857)

FossilOrigin-Name: d93c1aeb544a5b1056424945eb43854213b30e50
2003-01-31 17:21:49 +00:00
drh 88eee38afd Allow double-quoted strings as string constants in the IN operator. As a
side-efffect, allow the GROUP BY clause to refer to columns by their integer
column number.  Ticket #237. (CVS 856)

FossilOrigin-Name: 187d9c405891e543fc706f8ddb41f3966a842214
2003-01-31 17:16:36 +00:00
drh 3a84069da3 Additional testing and bug fixing with the non-callback API. Updated the
C/C++ interface document to describe the non-callback API. (CVS 855)

FossilOrigin-Name: af1e9299468aa70d7d91e7a5445ba391ccc8ff8b
2003-01-29 22:58:26 +00:00
drh 483750ba8a Better error messages on constraint violations. Additional tests and bug fixes
for the callback-free API. (CVS 854)

FossilOrigin-Name: ccc82f1ab4539a60ee5cc2625743c5389f9ccd8e
2003-01-29 18:46:51 +00:00
drh 326dce7451 The callback-free API is now working, though much more testing is need. (CVS 853)
FossilOrigin-Name: 162b259188e6967fe9c3722da26b81aab5655d83
2003-01-29 14:06:07 +00:00
drh b86ccfb26e First code for the new callback-free API. All regression tests pass but the
new API is mostly untested and is unlikely to work. (CVS 852)

FossilOrigin-Name: 065fa818ffc8d7562889172acea16e4e44e773ef
2003-01-28 23:13:10 +00:00
jplyon 70c15b48ae Added section on comments.
Corrected broken </p> end tags. (CVS 851)

FossilOrigin-Name: c957f4f0c6b486f25bc567dafeed186f91c8c315
2003-01-26 15:28:18 +00:00
drh 79740a572e Version 2.7.6 (CVS 850)
FossilOrigin-Name: bdba796f3b89690ab5d53a9e16924383ef72657c
2003-01-25 16:32:13 +00:00
drh a218b6a22a Fix a bug in the rollback validation logic (code that only runs during
debugging).  The problem was introduced by check-in (835). (CVS 849)

FossilOrigin-Name: b6ea0da76a27a4a67a3978c53405840518de2379
2003-01-25 15:43:22 +00:00
drh a3da6fafd7 Remove an unused variable. (CVS 848)
FossilOrigin-Name: 18f4ffaa2ed89784a1ea3c61c864d20e18fa1e9f
2003-01-25 14:34:23 +00:00
drh 2ac83073e0 Preparations for the release of version 2.7.6. (CVS 847)
FossilOrigin-Name: 5143d4814df1dd440a362a90dd3f328c84527565
2003-01-25 14:32:03 +00:00
drh ced87a65a8 Update the speed.html documentation. Recent optimizations have made the
library much faster. (CVS 846)

FossilOrigin-Name: ed47d162a072a2f98b633cc14f2be1474288d90b
2003-01-25 14:25:42 +00:00
drh d62d3d0d24 Add asserts to btree.c that check for the correct size of various typedefs
and structures.  Ticket #233. (CVS 845)

FossilOrigin-Name: c7e647d011b086a6e57420850f6bc4f28fcb23ee
2003-01-24 12:14:20 +00:00
drh 2554f8b0c0 Minor refinements to the pager. (CVS 844)
FossilOrigin-Name: 19221dee5fee4c8800cbae309f009964c8d646a2
2003-01-22 01:26:44 +00:00
drh 4764f161ab fix a typo on the quickstart.html page. (CVS 843)
FossilOrigin-Name: 61869bb51b981a47d783cc8739833cc0c4733b0a
2003-01-21 23:06:57 +00:00
drh 341eae8d35 In the pager, cache a pointer to the first page on the freelist that does not
need to be synced.  This makes a fetch of a page that is not in cache go a
lot faster when the cache is full.  This check-in also adds some performance
instrumentation to the OS layer. (CVS 842)

FossilOrigin-Name: 00f08fc0b5b6b9c5efbf15a62f9a1cc1cfa71283
2003-01-21 02:39:36 +00:00
drh e78e8284ad Update comments. No changes to code. (CVS 841)
FossilOrigin-Name: f6a8706872c43cee3003b48bb427c7b74b1f89e7
2003-01-19 03:59:45 +00:00
drh 79104c9d2a Update the speed comparison page. (CVS 840)
FossilOrigin-Name: 424cb2edb0c51b911791422ce7a9f5284a57f9ce
2003-01-18 22:01:06 +00:00
drh fcb78a4900 Fix datatype reporting and collating sequence selection so that it works
correctly on views and with the UNION, EXCEPT, and INTERCEPT operators. (CVS 839)

FossilOrigin-Name: 71cc292dce59cf8224b205d1cdbff59ad12f1043
2003-01-18 20:11:05 +00:00
drh be4f31c226 Do not report an error if the input to the sqlite shell ends in a comment.
Ticket #211. (CVS 838)

FossilOrigin-Name: 32a8e6e9771d636c0ad3042632d35865bc08585b
2003-01-18 17:05:00 +00:00
drh 799550beb0 Check the validity of the database connection before the trace callback,
not afterwards. (CVS 837)

FossilOrigin-Name: 960a2e4af3b940d74a82f98e8bf19aeec88a05ce
2003-01-18 17:04:08 +00:00
drh 18de4824f6 Add the sqlite_trace() hook for tracing the SQL that an application executes.
The plan is to leave this API undocumented for the time being, in case we
want to make changes to it later. (CVS 836)

FossilOrigin-Name: f67bff8ff3db9694f87daf1a549d24ea9612da6b
2003-01-16 16:28:53 +00:00
drh db48ee02c4 Improvements to the pager to help large updates against a large database run
faster.  Also improved the testing of the pager rollback algorithms. (CVS 835)

FossilOrigin-Name: 717523d3750dce784fa767ed9a8267d1246798ef
2003-01-16 13:42:43 +00:00
drh 2c3831cb23 Finish out the test suite for the new sqlite_set_authorizer API. (CVS 834)
FossilOrigin-Name: 701a73918db22fd134a8b959670ba7a4a908c8c5
2003-01-14 13:48:20 +00:00
drh bf0c78af2f Fix a memory leak in the PRAGMA authorization code. (CVS 833)
FossilOrigin-Name: ba58979f2ff3ec878a21e7c171fbcd8fa79ace6f
2003-01-14 02:54:08 +00:00
drh 77ad4e4133 More tests of the sqlite_set_authorizer() API together with fixes for bugs
that the new tests uncovered. (CVS 832)

FossilOrigin-Name: cc2ae781ac186f9ee1afacdc9117087421955369
2003-01-14 02:49:27 +00:00
drh 7160220495 Make the GLOB work write with upper-case characters. Ticket #226. (CVS 831)
FossilOrigin-Name: 7ea46e706485cc159f9d1c7e69efcdd048a0bb12
2003-01-14 00:44:08 +00:00
drh e5f9c6442f Revise the sqlite_set_authorizer API to provide more detailed information
about the SQL statement being authorized.  Only partially tested so far. (CVS 830)

FossilOrigin-Name: 45de93f913a18026a45de6254963dbcd1b0f1a19
2003-01-13 23:27:31 +00:00
drh 1962bda764 The initial round of tests for the sqlite_set_authorizer() API. More are
needed before release.  Ticket #215. (CVS 829)

FossilOrigin-Name: 5707b3d56efb6e988f816abefb1836f2f3254117
2003-01-12 19:33:52 +00:00
drh e6d01c3a04 Forgot to include the new "auth.c" source file in the previous checkin. (CVS 828)
FossilOrigin-Name: 7601916419489879fe963c83010b452c49ef063f
2003-01-12 18:07:48 +00:00
drh ed6c8671b3 Initial check-in of the code for the new sqlite_set_authorizer() API function.
The code is mostly untested at this point. (CVS 827)

FossilOrigin-Name: 52d5007f64d0af5286b2a0e1f0b9e53c86bece3f
2003-01-12 18:02:16 +00:00
drh 49f0936ec7 Remove an unused variable from the VDBE. Ticket #223. (CVS 826)
FossilOrigin-Name: 0deaf563fd9784bf0795107cd10e6b3269dfecea
2003-01-12 17:35:00 +00:00
drh f27134cdc4 Change the PopStack() routine so that it doesn't confuse bounds checkers.
Ticket #222. (CVS 825)

FossilOrigin-Name: fc11fa50b8f39f5e0b3674d7df832ffbca0d948f
2003-01-12 17:28:19 +00:00
drh fa9e0df21b Remove the aOrder() array from where.c. (CVS 824)
FossilOrigin-Name: b2c1edb47f481cafe6718bafcdb517cca160a44d
2003-01-11 15:02:44 +00:00
drh fd15981daa Fix two compiler warnings from OS-X. (CVS 823)
FossilOrigin-Name: 4c22da76ca91f3c59dac1c529e82ac3b04b767bd
2003-01-11 14:25:39 +00:00
drh 5a38705ecb Document the SHOW_DATATYPES pragma and add tests for it to the test suite.
Make sure datatypes are show even for aliased columns.
Tickets #220 and #221. (CVS 822)

FossilOrigin-Name: e84d3afe7b9153d003fdcca98221f446c004ffa2
2003-01-11 14:19:51 +00:00
drh 836faa4843 Remove the ColumnCount opcode, which had become a no-op. (CVS 821)
FossilOrigin-Name: 86deb12d68026913d181f9498144fa56445899f2
2003-01-11 13:30:57 +00:00
drh 820f3812d8 Port ot MacOS Classic. Ticket #218. (CVS 820)
FossilOrigin-Name: 13f82d67f60ae869d5bf2e31d9357a860aa62bad
2003-01-08 13:02:52 +00:00
drh 9bd47a97c0 Avoid calling truncate() and stat() on the checkpoint journal to improve the
speed of a large number of UPDATEs within a transaction. (CVS 819)

FossilOrigin-Name: 2f89e9e6963cb715f3671f1fdbf4c966aadff6c8
2003-01-07 14:46:08 +00:00
drh 2b8ef743af In the VDBE, allocate space to hold column names when the VDBE first starts.
The ColumnCount opcode now just writes the null terminator into this space. (CVS 818)

FossilOrigin-Name: 46d8f5e377bf790c18a7acdd1f3bc20b538d69eb
2003-01-07 13:55:22 +00:00
drh 371ac44d1c When constructing records and index keys, use static string space rather than
mallocing (when possible) for a small speed improvement. (CVS 817)

FossilOrigin-Name: 657c9fb5133aef93e4edd433912e6942ad9674ec
2003-01-07 13:43:45 +00:00
drh caec2f12a9 More optimizations. (CVS 816)
FossilOrigin-Name: a362981b20fd33254ad498619eedf75b576682e3
2003-01-07 02:47:47 +00:00
drh 32eb7b47ca Optimizations to the tokenizer. (CVS 815)
FossilOrigin-Name: 032b3daa1d3cf3e00a4a6ba0b09624f1aba6445c
2003-01-07 01:44:37 +00:00
drh 3e87c7abeb Remove unnecessary code from the VDBE. (CVS 814)
FossilOrigin-Name: b96ec281ff29aad8af340b30c6ff4e129ffeeefb
2003-01-06 23:54:05 +00:00
drh 8178a75a11 More optimizations. (CVS 813)
FossilOrigin-Name: 5809132f5bf40bae2331f887e87fe5baecc15c46
2003-01-05 21:41:40 +00:00
drh c3b7057705 Parameterize the number of adjacent pages that participate in the balancing
algorithm in the BTree.  But leave the setting at the current value of 3. (CVS 812)

FossilOrigin-Name: 6c304024bbd21a1886a57ada795531349aa627d7
2003-01-04 19:44:07 +00:00
drh bb49aba82a Another optimization to the btree logic. (CVS 811)
FossilOrigin-Name: 03d20673616cae0dca524fd04557798a98fb7069
2003-01-04 18:53:27 +00:00
drh 428ae8cb41 Optimizations to the BTree module for a modest speed improvement. (CVS 810)
FossilOrigin-Name: 39902a70417475225956704a037493515e9b08b9
2003-01-04 16:48:09 +00:00
drh 2c79995565 Allow the rollback journal to be empty except for its header.
Ticket #212. (CVS 809)

FossilOrigin-Name: 1ba41bc2afab18cc295d9a45845296b46bfa57e5
2003-01-03 02:04:27 +00:00
drh 8c1238aebd Code optimizations to help the library run faster. (CVS 808)
FossilOrigin-Name: db745e87dc26cf1a35cdcec18f4b659742e14120
2003-01-02 14:43:55 +00:00
drh 7b39686749 If compiled with the -DVDBE_PROFILE=1 option, special code is inserted that
uses the pentium RDTSC instruction to compute very precise runtimes on all
VDBE opcodes.  (This only works on i586 processors, of course.)  The results
are written into the vdbe_profile.out file for analysis. Hopefully, this
new feature will reveal hot spots that can be optimized to make the VDBE run
faster. (CVS 807)

FossilOrigin-Name: a1c071ea18766932c90275c704e078134c67be68
2003-01-01 23:06:20 +00:00
drh c64e0ba45c Version 2.7.5 (CVS 806)
FossilOrigin-Name: ee95eefe12c48f28412461125c231122e0d4277a
2002-12-28 01:26:07 +00:00
drh 919792ecb9 Update the version number to 2.7.5. (CVS 805)
FossilOrigin-Name: b0864cc9c89a3c2350ac46634ef3c420f97d11c0
2002-12-28 01:10:14 +00:00
drh 80eb79055e Fix an uninitialized variable in the pager. Tickets #208 and #206.
Bug introduced by check-in (795). (CVS 804)

FossilOrigin-Name: f3dc686e0258a9588e1433a89ac46795f76beeae
2002-12-28 01:06:30 +00:00
drh 5d1f0d4c89 Version 2.7.4 (CVS 803)
FossilOrigin-Name: 0224db6f8ce5e3cecc4432f3966b8f59f80e9303
2002-12-17 22:50:45 +00:00
drh 3450e1d3c2 Preparing for the 2.7.4 release. (CVS 802)
FossilOrigin-Name: f685ae15b1179baeadfadbaef0a73b001c96fac5
2002-12-17 14:30:42 +00:00
drh f1337bb5ff If the "fake_big_file" command fails, be sure to close the file before
returning. (CVS 801)

FossilOrigin-Name: fa1b5e2119617b111c6b463bbf641ddcb9972cae
2002-12-17 14:19:49 +00:00
drh f33cb428e5 Make sure the host machine has enough disk space before running the
large file tests. (CVS 800)

FossilOrigin-Name: b1ec547865a76541951433630bd4528d1988a4de
2002-12-17 14:13:48 +00:00
drh e7e8bc7739 Take care not to modify the sqlite* pointer to sqlite_exec() if we suspect
that the pointer is stale - that it has previously been passed to
sqlite_close().  Possible fix for ticket #202.  Prior to this fix, test
misuse-5.3 was causing a change to a buffer that had been previously free()-ed. (CVS 799)

FossilOrigin-Name: f04547edfa1643ce52925d317915badfc676bd8b
2002-12-17 13:05:25 +00:00
drh 3e7a609667 Save the full pathname of the database file so that journalling still works
even if the user changes working directories after opening the databae.
Ticket #200. (CVS 798)

FossilOrigin-Name: 1c58b4fc032c5975dcce9b8ae844c0e516254a17
2002-12-07 21:45:14 +00:00
drh 1a844c380b Fix a bug in the reverse scan logic that comes up when the table being
scanned is empty.  Add additional tests for the reverse scan. (CVS 797)

FossilOrigin-Name: 0051c87d5e8d07fae09da2eb7b0d8cbd1bbd3c8e
2002-12-04 22:29:28 +00:00
drh dd4852c3d1 Fixes to the logic that decides if the ORDER BY can be ignored due to the
use of an index.  Tests updated. (CVS 796)

FossilOrigin-Name: bfb9a2aa939ecffc5dc2c7c23bddd57d357bdf13
2002-12-04 21:50:16 +00:00
drh c045ec51be Scan the table backwards if there is an ORDER BY ... DESC clause that can
be satisfied by an index. (CVS 795)

FossilOrigin-Name: c7a3487981de0ed5b43ea3ff4d46ab4437068dca
2002-12-04 20:01:06 +00:00
drh 2dcc9aa2a8 Add the sqliteBtreePrevious() routine to the BTree module API. This is
in anticipation of implementing reverse order searching of a table. (CVS 794)

FossilOrigin-Name: 0ad1d93879bee0d34b122591c025192a51b8490f
2002-12-04 13:40:25 +00:00
drh c66c5a266b Allow an aggregate function in the HAVING clause even if no aggregates appear
in the result set.  Ticket #187. (CVS 793)

FossilOrigin-Name: 33c6fd6b3dc271fa1f2d4500b4f76c736accefce
2002-12-03 02:34:49 +00:00
drh 174b619591 Honor ORDER BY clauses in VIEWs. Ticket #193. (CVS 792)
FossilOrigin-Name: dbf7893234a6c5d6bb2d931e52080bb05784c0c9
2002-12-03 02:22:52 +00:00
drh da47d7748f Change to the pager to avoid opening journal files unnecessarily. This can
sometimes results in a significant speed improvement. (CVS 791)

FossilOrigin-Name: fa5c042585c601449ede7319d0c5993cd8ba75a4
2002-12-02 04:25:19 +00:00
drh d0d006e29c Fixed large file support under Linux. I'm unable to test under Windows.
Ticket #191. (CVS 790)

FossilOrigin-Name: 9864a1265b5a37c12b0dd8446d81b84c5a3acc43
2002-12-01 02:00:57 +00:00
drh 86bc1c8273 Add the "space_used.tcl" script to the tools directory. This script is used
to measure how much disk space is used by each table and index of a database. (CVS 789)

FossilOrigin-Name: 83b2c27a568cd67cd5162d513766b23ff9fc2227
2002-11-24 14:52:27 +00:00
drh 58f391b36f Automatically determine if pointers are 4 or 8 bytes in size during the
compilation process.  Ticket #190. (CVS 788)

FossilOrigin-Name: dd5396a73a782b6abe9da3de43a5ee11e0dddbb2
2002-11-20 11:55:18 +00:00
drh 7cdbd32c8e Get the new large file code working with the Borland compiler. Ticket #195. (CVS 787)
FossilOrigin-Name: da4a79e2891aa81e2e6d96689f99b3924f940dd5
2002-11-20 11:07:59 +00:00
drh 7d686b2d57 Remove extra </TD> from HTML output. Ticket #189. (CVS 786)
FossilOrigin-Name: dc5d9c129c566bf57d108b824ba486cfe070dda6
2002-11-11 13:56:47 +00:00
drh 4d9ef4c4ef Back out the changes in the pager that sorted pages prior to writing them
to the database.  Additional measurements showed no performance gains. (CVS 785)

FossilOrigin-Name: 745d66395daf5cb8463305bbc9e4219534d2b7cf
2002-11-11 01:04:47 +00:00
drh 32c05e993f Replace the atoi() library routine with a faster home-grown version in the
VDBE.  This gives a dramatic speed improvement for some kinds of queries. (CVS 784)

FossilOrigin-Name: 263a8ca40f7ff66fbdcb43bf9032391d5b1e68bd
2002-11-11 00:05:42 +00:00
drh 03eb96a7b2 Two optimizations to the pager: (1) Write dirty pages back to the database
file in order and (2) Keep a separate list of in-memory pages that are in
the checkpoint journal in order to speed a checkpoint commit. (CVS 783)

FossilOrigin-Name: a6ef6657a4377684dc2fce7be2bbf009fd2d2f37
2002-11-10 23:32:56 +00:00
drh 8766c34348 Try to better detect when the library is compiled for large file support (LFS)
but the support is not available in the host OS kernel. (CVS 782)

FossilOrigin-Name: a29d60ecc5ee3f535142a81f56eecbef7875ef22
2002-11-09 00:33:15 +00:00
drh 829e802992 Add large file support to Windows. Change large file support for Unix so
that it compiles automatically - without requiring special options on the
compiler command line. (CVS 781)

FossilOrigin-Name: 2008b56fe11e49d52e28f47d14ccd70504e6c094
2002-11-06 14:08:11 +00:00
drh 20e9ab16d8 Changes to include files so that the >2GB file patch will compile under BSD. (CVS 780)
FossilOrigin-Name: 81bb1aed5e9094a9655bd03614bb111d79896928
2002-11-06 00:59:44 +00:00
drh f87e9de4c4 Update the FAQ to explain how to enable large file support. (CVS 779)
FossilOrigin-Name: 4caf624e9061fe7489a8e3c6892975036a2272d5
2002-11-05 23:24:38 +00:00
drh 28be87c7c4 Add support for databases larger than 2GB under Unix. Must be compiled
with -D_FILE_OFFSET_BITS=64 and -D_LARGEFILE_SOURCE in order to work with
larger databases. (CVS 778)

FossilOrigin-Name: a3f67fe9121ca4655510094fe775b8603a87800e
2002-11-05 23:03:02 +00:00
drh 647cb0e159 Add the sqlite_version() SQL function as a built-in. (CVS 777)
FossilOrigin-Name: 7c8c0e7633dca00bde7bc7c22075f688c034c200
2002-11-04 19:32:25 +00:00
drh 7bc09d3111 Improvements in threadtest.c (for Unix) and some minor bug fixes that result
from the better testing. (CVS 776)

FossilOrigin-Name: 326e0983c34b584a3c4a2300399bff0a8281b9f8
2002-11-01 01:55:36 +00:00
drh 194a7b6469 Version 2.7.3 (CVS 775)
FossilOrigin-Name: 4051dbdb0552620eaff2ccef02f64a2ff97a8dfb
2002-10-31 00:15:10 +00:00
drh 1f3e905cd0 Fix an assert that might fail if malloc() fails. (CVS 774)
FossilOrigin-Name: 8ad018944c3aa8f58e1c68b1fa634ef922d6476f
2002-10-31 00:09:39 +00:00
drh bd1edfa321 Bump the version number prior to the release of version 2.7.3. (CVS 773)
FossilOrigin-Name: bc7c7d87e550c786d5bdb4169a0ad75db3fb066a
2002-10-30 23:04:27 +00:00
drh 38dd0b4ff0 In the VDBE, check to make sure a set has been initialized before using it.
Ticket #185. (CVS 772)

FossilOrigin-Name: 8c4cbdd05517e91879a0f2c4559d0f0518d2385b
2002-10-30 22:42:58 +00:00
drh 1f16230b5c Minimal support for oracle8 outer join syntax. (CVS 771)
FossilOrigin-Name: 31df3690d0fe4bd4a293cbe8ca9a26c98c3ed3ce
2002-10-27 19:35:33 +00:00
drh 6977fea801 Correctly handle column names and string constants in parentheses.
Fix for ticket #179. (CVS 770)

FossilOrigin-Name: 3b68aa25c451b7c09ece457ac2b70a9a5d93508a
2002-10-22 23:38:04 +00:00
drh e958bb4aef Take care to track ephemeral strings in the VDBE and make copies of ephemeral
strings that need to be preserved.  Ticket #177. (CVS 769)

FossilOrigin-Name: 562da534bbb605a8ce15824135b012ef2d86bbeb
2002-10-22 15:04:34 +00:00
drh edbbbdf8f7 Rework the changes for ticket #176 (check-ins (760) and (761)) to be
more consistent with the rest of the source code. (CVS 768)

FossilOrigin-Name: f50a177b4239bc7a83563ac9361e830ec04e81fb
2002-10-20 18:19:45 +00:00
drh 3c2007a546 The "table_info" pragma reports unspecified column types as "numeric" instead
of "text".  Fix for ticket #174. (CVS 767)

FossilOrigin-Name: 395ab5fac201a37d6eca833ffd6f58ac8a0121a2
2002-10-20 16:00:27 +00:00
drh 275ed72c9b Export the sqlite_function_type function from windows DLLs. Ticket #173. (CVS 766)
FossilOrigin-Name: d5470dfe102ef9b1dac3b15a2f5cc225e3c26129
2002-10-20 15:55:01 +00:00
drh 315555ca50 Work around a bug in the Borland C compiler. Ticket #172. (CVS 765)
FossilOrigin-Name: 3ef2925650bfbeb4ee5dbd0aaf8e606fc4cd2be1
2002-10-20 15:53:03 +00:00
drh 2678058853 Make sure malloc(0) always returns NULL. Fix for ticket #171. (CVS 764)
FossilOrigin-Name: 4622b7ce8f4727a6405ddf4f0af701db86da86bf
2002-10-20 15:46:22 +00:00
drh 32fbe342db Speed improvement by avoiding a call to sqliteBtreeLast() when inserting a
new row into a table. (CVS 763)

FossilOrigin-Name: d0af59fe6b9d5d026786e7cce1c49c208a0335cc
2002-10-19 20:16:37 +00:00
drh 906bf2a316 Fix the URL for pointing to MinGW on the homepage. (CVS 762)
FossilOrigin-Name: 16aad98aad4d8dd4a8400cdee32004b8c4785d60
2002-10-19 20:13:51 +00:00
mike 16aaf451b7 Minor coding fix in getting the windows platform version, when multithreading (CVS 761)
FossilOrigin-Name: b53ab71d074ada47ce22bd161f6aee24587302af
2002-10-17 09:01:31 +00:00
mike 710dcfbde5 fix for locking in Windows (CVS 760)
FossilOrigin-Name: 83add34f64895a4b465881213eba82f3b1f5c964
2002-10-17 00:38:54 +00:00
drh f1f0fa0769 Remove the call to srand() and add better comments to the sqliteOsRandomSeed()
routine.  Ticket #163. (CVS 759)

FossilOrigin-Name: d87a886d8f63f54466848151e2b0e8565b338593
2002-10-12 13:43:59 +00:00
drh c8f8b632c3 Fix a bug in the left outer join logic. (CVS 758)
FossilOrigin-Name: 6c0f44bd6374010f7a4a091e585eb36e0665f96f
2002-09-30 12:36:26 +00:00
drh 294fb92b50 Fix an uninitialized variable that could cause problems when comparing
two NULLs. (CVS 757)

FossilOrigin-Name: 015425001813971f6d4c97c18d64c7f14fa1955f
2002-09-30 01:31:21 +00:00
166 changed files with 47998 additions and 22921 deletions
+176 -60
View File
@@ -34,6 +34,12 @@ prefix = @prefix@
exec_prefix = @exec_prefix@
INSTALL = @INSTALL@
LIBTOOL = ./libtool
RELEASE = @ALLOWRELEASE@
# libtool compile/link/install
LTCOMPILE = $(LIBTOOL) --mode=compile $(TCC)
LTLINK = $(LIBTOOL) --mode=link $(TCC)
LTINSTALL = $(LIBTOOL) --mode=install $(INSTALL)
# Compiler options needed for programs that use the TCL library.
#
@@ -57,23 +63,52 @@ LIBREADLINE = @TARGET_READLINE_LIBS@
# ENCODING = ISO8859
ENCODING = @ENCODING@
# Flags controlling use of the in memory btree implementation
#
# SQLITE_OMIT_INMEMORYDB is defined in order to omit the in-memory
# red/black tree driver in the file btree_rb.c
#
# TEMP_STORE is 0 to force temporary tables to be in a file, 1 to
# default to file, 2 to default to memory, and 3 to force temporary
# tables to always be in memory.
#
INMEMORYDB = @INMEMORYDB@
INCOREFLAGS = -DTEMP_STORE=@TEMP_STORE@
ifeq (${INMEMORYDB},0)
INCOREFLAGS += -DSQLITE_OMIT_INMEMORYDB=1
endif
# You should not have to change anything below this line
###############################################################################
# Object files for the SQLite library.
#
LIBOBJ = btree.lo build.lo delete.lo expr.lo func.lo hash.lo insert.lo \
main.lo opcodes.lo os.lo pager.lo parse.lo printf.lo random.lo \
select.lo table.lo tokenize.lo update.lo util.lo vdbe.lo \
LIBOBJ = attach.lo auth.lo btree.lo build.lo copy.lo date.lo \
delete.lo encode.lo expr.lo func.lo hash.lo insert.lo \
main.lo opcodes.lo os.lo pager.lo parse.lo pragma.lo \
printf.lo random.lo select.lo table.lo tokenize.lo \
update.lo util.lo vacuum.lo vdbe.lo vdbeaux.lo \
where.lo trigger.lo
# Only build the in-core DB if it is required.
ifeq (${INMEMORYDB},1)
LIBOBJ += btree_rb.lo
endif
# All of the source code files.
#
SRC = \
$(TOP)/src/attach.c \
$(TOP)/src/auth.c \
$(TOP)/src/btree.c \
$(TOP)/src/btree.h \
$(TOP)/src/btree_rb.c \
$(TOP)/src/build.c \
$(TOP)/src/copy.c \
$(TOP)/src/date.c \
$(TOP)/src/delete.c \
$(TOP)/src/encode.c \
$(TOP)/src/expr.c \
$(TOP)/src/func.c \
$(TOP)/src/hash.c \
@@ -84,6 +119,7 @@ SRC = \
$(TOP)/src/pager.c \
$(TOP)/src/pager.h \
$(TOP)/src/parse.y \
$(TOP)/src/pragma.c \
$(TOP)/src/printf.c \
$(TOP)/src/random.c \
$(TOP)/src/select.c \
@@ -96,7 +132,9 @@ SRC = \
$(TOP)/src/trigger.c \
$(TOP)/src/update.c \
$(TOP)/src/util.c \
$(TOP)/src/vacuum.c \
$(TOP)/src/vdbe.c \
$(TOP)/src/vdbeaux.c \
$(TOP)/src/vdbe.h \
$(TOP)/src/where.c
@@ -110,6 +148,8 @@ TESTSRC = \
$(TOP)/src/test1.c \
$(TOP)/src/test2.c \
$(TOP)/src/test3.c \
$(TOP)/src/test4.c \
$(TOP)/src/vdbe.c \
$(TOP)/src/md5.c
# Header files used by all library source files.
@@ -117,6 +157,7 @@ TESTSRC = \
HDR = \
sqlite.h \
$(TOP)/src/btree.h \
config.h \
$(TOP)/src/hash.h \
opcodes.h \
$(TOP)/src/os.h \
@@ -124,10 +165,19 @@ HDR = \
$(TOP)/src/vdbe.h \
parse.h
# Header files used by the VDBE submodule
#
VDBEHDR = \
$(HDR) \
$(TOP)/src/vdbeInt.h
# This is the default Makefile target. The objects listed here
# are what get build when you type just "make" with no arguments.
#
all: sqlite.h libsqlite.la sqlite
all: sqlite.h libsqlite.la sqlite@TARGET_EXEEXT@
Makefile: $(TOP)/Makefile.in
./config.status
# Generate the file "last_change" which contains the date of change
# of the most recently modified source code file
@@ -137,15 +187,17 @@ last_change: $(SRC)
| awk '{print $$5,$$6}' >last_change
libsqlite.la: $(LIBOBJ)
$(LIBTOOL) $(TCC) -o libsqlite.la $(LIBOBJ) -rpath $(exec_prefix)/lib
$(LTLINK) -o libsqlite.la $(LIBOBJ) ${RELEASE} -rpath @exec_prefix@/lib \
-version-info "8:6:8"
libtclsqlite.la: tclsqlite.lo libsqlite.la
$(LIBTOOL) $(TCC) -o libtclsqlite.la tclsqlite.lo \
libsqlite.la $(LIBTCL) -rpath $(exec_prefix)/lib
$(LTLINK) -o libtclsqlite.la tclsqlite.lo \
libsqlite.la $(LIBTCL) -rpath @exec_prefix@/lib/sqlite \
-version-info "8:6:8"
sqlite: $(TOP)/src/shell.c libsqlite.la sqlite.h
$(LIBTOOL) $(TCC) $(READLINE_FLAGS) -o sqlite $(TOP)/src/shell.c \
libsqlite.la $(LIBREADLINE) -rpath $(exec_prefix)/lib
sqlite@TARGET_EXEEXT@: $(TOP)/src/shell.c libsqlite.la sqlite.h
$(LTLINK) $(READLINE_FLAGS) -o sqlite $(TOP)/src/shell.c \
libsqlite.la $(LIBREADLINE)
# This target creates a directory named "tsrc" and fills it with
# copies of all of the C source code and header files needed to
@@ -153,33 +205,36 @@ sqlite: $(TOP)/src/shell.c libsqlite.la sqlite.h
# files are automatically generated. This target takes care of
# all that automatic generation.
#
target_source: $(SRC) $(HDR)
target_source: $(SRC) $(VDBEHDR)
rm -rf tsrc
mkdir tsrc
cp $(SRC) $(HDR) tsrc
cp $(SRC) $(VDBEHDR) tsrc
rm tsrc/sqlite.h.in tsrc/parse.y
cp parse.c tsrc
cp parse.c opcodes.c tsrc
# Rules to build the LEMON compiler generator
#
lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
lemon@BUILD_EXEEXT@: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
$(BCC) -o lemon $(TOP)/tool/lemon.c
cp $(TOP)/tool/lempar.c .
btree.lo: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
$(LIBTOOL) $(TCC) -c $(TOP)/src/btree.c
$(LTCOMPILE) -c $(TOP)/src/btree.c
btree_rb.lo: $(TOP)/src/btree_rb.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/btree_rb.c
build.lo: $(TOP)/src/build.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/build.c
$(LTCOMPILE) -c $(TOP)/src/build.c
main.lo: $(TOP)/src/main.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/main.c
$(LTCOMPILE) -c ${INCOREFLAGS} $(TOP)/src/main.c
pager.lo: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
$(LIBTOOL) $(TCC) -c $(TOP)/src/pager.c
$(LTCOMPILE) -c $(TOP)/src/pager.c
opcodes.lo: opcodes.c
$(LIBTOOL) $(TCC) -c opcodes.c
$(LTCOMPILE) -c opcodes.c
opcodes.c: $(TOP)/src/vdbe.c
echo '/* Automatically generated file. Do not edit */' >opcodes.c
@@ -195,83 +250,125 @@ opcodes.h: $(TOP)/src/vdbe.h
awk '{printf "#define %-30s %3d\n", $$2, ++cnt}' >>opcodes.h
os.lo: $(TOP)/src/os.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/os.c
$(LTCOMPILE) -c $(TOP)/src/os.c
parse.lo: parse.c $(HDR)
$(LIBTOOL) $(TCC) -c parse.c
$(LTCOMPILE) -c parse.c
parse.h: parse.c
parse.c: $(TOP)/src/parse.y lemon
parse.c: $(TOP)/src/parse.y lemon@BUILD_EXEEXT@
cp $(TOP)/src/parse.y .
./lemon parse.y
# The config.h file will contain a single #define that tells us how
# many bytes are in a pointer. This only works if a pointer is the
# same size on the host as it is on the target. If you are cross-compiling
# to a target with a different pointer size, you'll need to manually
# configure the config.h file.
#
config.h:
echo '#include <stdio.h>' >temp.c
echo 'int main(){printf(' >>temp.c
echo '"#define SQLITE_PTR_SZ %d",sizeof(char*));' >>temp.c
echo 'exit(0);}' >>temp.c
$(BCC) -o temp temp.c
./temp >config.h
echo >>config.h
rm -f temp.c temp
sqlite.h: $(TOP)/src/sqlite.h.in
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
-e s/--ENCODING--/$(ENCODING)/ \
$(TOP)/src/sqlite.h.in >sqlite.h
tokenize.lo: $(TOP)/src/tokenize.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/tokenize.c
$(LTCOMPILE) -c $(TOP)/src/tokenize.c
util.lo: $(TOP)/src/util.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/util.c
$(LTCOMPILE) -c $(TOP)/src/util.c
vdbe.lo: $(TOP)/src/vdbe.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/vdbe.c
vdbe.lo: $(TOP)/src/vdbe.c $(VDBEHDR)
$(LTCOMPILE) -c $(TOP)/src/vdbe.c
vdbeaux.lo: $(TOP)/src/vdbe.c $(VDBEHDR)
$(LTCOMPILE) -c $(TOP)/src/vdbeaux.c
where.lo: $(TOP)/src/where.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/where.c
$(LTCOMPILE) -c $(TOP)/src/where.c
copy.lo: $(TOP)/src/copy.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/copy.c
date.lo: $(TOP)/src/date.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/date.c
delete.lo: $(TOP)/src/delete.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/delete.c
$(LTCOMPILE) -c $(TOP)/src/delete.c
encode.lo: $(TOP)/src/encode.c
$(LTCOMPILE) -c $(TOP)/src/encode.c
expr.lo: $(TOP)/src/expr.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/expr.c
$(LTCOMPILE) -c $(TOP)/src/expr.c
func.lo: $(TOP)/src/func.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/func.c
$(LTCOMPILE) -c $(TOP)/src/func.c
hash.lo: $(TOP)/src/hash.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/hash.c
$(LTCOMPILE) -c $(TOP)/src/hash.c
insert.lo: $(TOP)/src/insert.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/insert.c
$(LTCOMPILE) -c $(TOP)/src/insert.c
random.lo: $(TOP)/src/random.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/random.c
$(LTCOMPILE) -c $(TOP)/src/random.c
select.lo: $(TOP)/src/select.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/select.c
$(LTCOMPILE) -c $(TOP)/src/select.c
table.lo: $(TOP)/src/table.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/table.c
$(LTCOMPILE) -c $(TOP)/src/table.c
trigger.lo: $(TOP)/src/trigger.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/trigger.c
$(LTCOMPILE) -c $(TOP)/src/trigger.c
update.lo: $(TOP)/src/update.c $(HDR)
$(LIBTOOL) $(TCC) -c $(TOP)/src/update.c
$(LTCOMPILE) -c $(TOP)/src/update.c
vacuum.lo: $(TOP)/src/vacuum.c $(HDR)
$(LTCOMPILE) -c $(TOP)/src/vacuum.c
tclsqlite.lo: $(TOP)/src/tclsqlite.c $(HDR)
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
pragma.lo: $(TOP)/src/pragma.c $(HDR)
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
printf.lo: $(TOP)/src/printf.c $(HDR)
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -c $(TOP)/src/printf.c
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/printf.c
tclsqlite: $(TOP)/src/tclsqlite.c libsqlite.la
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite \
$(TOP)/src/tclsqlite.c libsqlite.la $(LIBTCL)
attach.lo: $(TOP)/src/attach.c $(HDR)
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/attach.c
testfixture: $(TOP)/src/tclsqlite.c libtclsqlite.la libsqlite.la $(TESTSRC)
$(LIBTOOL) $(TCC) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1\
auth.lo: $(TOP)/src/auth.c $(HDR)
$(LTCOMPILE) $(TCL_FLAGS) -c $(TOP)/src/auth.c
tclsqlite-sh.lo: $(TOP)/src/tclsqlite.c $(HDR)
$(LTCOMPILE) $(TCL_FLAGS) -DTCLSH=1 -o $@ -c $(TOP)/src/tclsqlite.c
tclsqlite: tclsqlite-sh.lo libsqlite.la
$(LTLINK) $(TCL_FLAGS) -o tclsqlite tclsqlite-sh.lo libsqlite.la $(LIBTCL)
testfixture@TARGET_EXEEXT@: $(TOP)/src/tclsqlite.c libtclsqlite.la libsqlite.la $(TESTSRC)
$(LTLINK) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1\
-o testfixture $(TESTSRC) $(TOP)/src/tclsqlite.c \
libtclsqlite.la libsqlite.la $(LIBTCL)
fulltest: testfixture sqlite
fulltest: testfixture@TARGET_EXEEXT@ sqlite@TARGET_EXEEXT@
./testfixture $(TOP)/test/all.test
test: testfixture sqlite
test: testfixture@TARGET_EXEEXT@ sqlite@TARGET_EXEEXT@
./testfixture $(TOP)/test/quick.test
index.html: $(TOP)/www/index.tcl last_change
@@ -301,9 +398,6 @@ arch.png: $(TOP)/www/arch.png
opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
crosscompile.html: $(TOP)/www/crosscompile.tcl
tclsh $(TOP)/www/crosscompile.tcl >crosscompile.html
mingw.html: $(TOP)/www/mingw.tcl
tclsh $(TOP)/www/mingw.tcl >mingw.html
@@ -353,7 +447,6 @@ DOC = \
arch.png \
vdbe.html \
c_interface.html \
crosscompile.html \
mingw.html \
tclsqlite.html \
download.html \
@@ -372,21 +465,44 @@ doc: $(DOC)
mv $(DOC) doc
install: sqlite libsqlite.la sqlite.h
$(INSTALL) -d $(exec_prefix)/lib
$(LIBTOOL) $(INSTALL) libsqlite.la $(exec_prefix)/lib
$(INSTALL) -d $(exec_prefix)/bin
$(LIBTOOL) $(INSTALL) sqlite $(exec_prefix)/bin
$(INSTALL) -d $(prefix)/include
$(INSTALL) -m 0644 sqlite.h $(prefix)/include
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/lib
$(LTINSTALL) libsqlite.la $(DESTDIR)$(exec_prefix)/lib
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/bin
$(LTINSTALL) sqlite $(DESTDIR)$(exec_prefix)/bin
$(INSTALL) -d $(DESTDIR)$(prefix)/include
$(INSTALL) -m 0644 sqlite.h $(DESTDIR)$(prefix)/include
$(INSTALL) -d $(DESTDIR)$(exec_prefix)/lib/pkgconfig;
$(INSTALL) -m 0644 sqlite.pc $(DESTDIR)$(exec_prefix)/lib/pkgconfig;
clean:
rm -f *.lo *.la *.o sqlite libsqlite.la sqlite.h opcodes.*
rm -f *.lo *.la *.o sqlite@TARGET_EXEEXT@ libsqlite.la sqlite.h opcodes.*
rm -rf .libs .deps
rm -f lemon lempar.c parse.* sqlite*.tar.gz
rm -f lemon@BUILD_EXEEXT@ lempar.c parse.* sqlite*.tar.gz
rm -f $(PUBLISH)
rm -f *.da *.bb *.bbg gmon.out
rm -f testfixture test.db
rm -f testfixture@TARGET_EXEEXT@ test.db
rm -rf doc
rm -f sqlite.dll sqlite.lib
#
# Windows section; all this funky .dll stuff ;-)
#
dll: sqlite.dll
REAL_LIBOBJ = $(LIBOBJ:%.lo=.libs/%.o)
sqlite.dll: $(LIBOBJ) $(TOP)/sqlite.def
dllwrap --dllname sqlite.dll --def $(TOP)/sqlite.def $(REAL_LIBOBJ)
strip sqlite.dll
#target for dll import libraries
implib: sqlite.lib
#make Borland C++ and/or Microsoft VC import library for the dll
# ignore any errors (usually due to missing programs)
sqlite.lib: sqlite.dll
-implib -a sqlite.lib sqlite.dll
-lib /machine:i386 /def:$(TOP)/sqlite.def
distclean: clean
rm -f config.log config.status
rm -f config.log config.status libtool Makefile config.h
+1 -1
View File
@@ -1 +1 @@
2.7.2
2.8.14
Vendored
+2289 -1534
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

+337 -222
View File
@@ -1,9 +1,9 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
# Free Software Foundation, Inc.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
timestamp='2001-09-04'
timestamp='2004-01-05'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@@ -24,8 +24,9 @@ timestamp='2001-09-04'
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Written by Per Bothner <bothner@cygnus.com>.
# Please send patches to <config-patches@gnu.org>.
# Originally written by Per Bothner <per@bothner.com>.
# Please send patches to <config-patches@gnu.org>. Submit a context
# diff and a properly formatted ChangeLog entry.
#
# This script attempts to guess a canonical system name similar to
# config.sub. If it succeeds, it prints the system name on stdout, and
@@ -87,30 +88,42 @@ if test $# != 0; then
exit 1
fi
trap 'exit 1' 1 2 15
dummy=dummy-$$
trap 'rm -f $dummy.c $dummy.o $dummy.rel $dummy; exit 1' 1 2 15
# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
# compiler to aid in system detection is discouraged as it requires
# temporary files to be created and, as you can see below, it is a
# headache to deal with in a portable fashion.
# CC_FOR_BUILD -- compiler used by this script.
# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
# use `HOST_CC' if defined, but it is deprecated.
set_cc_for_build='case $CC_FOR_BUILD,$HOST_CC,$CC in
,,) echo "int dummy(){}" > $dummy.c ;
for c in cc gcc c89 ; do
($c $dummy.c -c -o $dummy.o) >/dev/null 2>&1 ;
if test $? = 0 ; then
# Portable tmp directory creation inspired by the Autoconf team.
set_cc_for_build='
trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
: ${TMPDIR=/tmp} ;
{ tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
{ test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
{ tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
{ echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
dummy=$tmp/dummy ;
tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
case $CC_FOR_BUILD,$HOST_CC,$CC in
,,) echo "int x;" > $dummy.c ;
for c in cc gcc c89 c99 ; do
if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
CC_FOR_BUILD="$c"; break ;
fi ;
done ;
rm -f $dummy.c $dummy.o $dummy.rel ;
if test x"$CC_FOR_BUILD" = x ; then
CC_FOR_BUILD=no_compiler_found ;
fi
;;
,,*) CC_FOR_BUILD=$CC ;;
,*,*) CC_FOR_BUILD=$HOST_CC ;;
esac'
esac ;'
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
# (ghazi@noc.rutgers.edu 1994-08-24)
@@ -127,29 +140,30 @@ UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
*:NetBSD:*:*)
# Netbsd (nbsd) targets should (where applicable) match one or
# NetBSD (nbsd) targets should (where applicable) match one or
# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
# *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
# switched to ELF, *-*-netbsd* would select the old
# object file format. This provides both forward
# compatibility and a consistent mechanism for selecting the
# object file format.
# Determine the machine/vendor (is the vendor relevant).
case "${UNAME_MACHINE}" in
amiga) machine=m68k-unknown ;;
arm32) machine=arm-unknown ;;
atari*) machine=m68k-atari ;;
sun3*) machine=m68k-sun ;;
mac68k) machine=m68k-apple ;;
macppc) machine=powerpc-apple ;;
hp3[0-9][05]) machine=m68k-hp ;;
ibmrt|romp-ibm) machine=romp-ibm ;;
*) machine=${UNAME_MACHINE}-unknown ;;
#
# Note: NetBSD doesn't particularly care about the vendor
# portion of the name. We always set it to "unknown".
sysctl="sysctl -n hw.machine_arch"
UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
/usr/sbin/$sysctl 2>/dev/null || echo unknown)`
case "${UNAME_MACHINE_ARCH}" in
armeb) machine=armeb-unknown ;;
arm*) machine=arm-unknown ;;
sh3el) machine=shl-unknown ;;
sh3eb) machine=sh-unknown ;;
*) machine=${UNAME_MACHINE_ARCH}-unknown ;;
esac
# The Operating System including object format, if it has switched
# to ELF recently, or will in the future.
case "${UNAME_MACHINE}" in
i386|sparc|amiga|arm*|hp300|mvme68k|vax|atari|luna68k|mac68k|news68k|next68k|pc532|sun3*|x68k)
case "${UNAME_MACHINE_ARCH}" in
arm*|i386|m68k|ns32k|sh3*|sparc|vax)
eval $set_cc_for_build
if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
| grep __ELF__ >/dev/null
@@ -166,75 +180,115 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
;;
esac
# The OS release
release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
# Debian GNU/NetBSD machines have a different userland, and
# thus, need a distinct triplet. However, they do not need
# kernel version information, so it can be replaced with a
# suitable tag, in the style of linux-gnu.
case "${UNAME_VERSION}" in
Debian*)
release='-gnu'
;;
*)
release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
;;
esac
# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
# contains redundant information, the shorter form:
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
echo "${machine}-${os}${release}"
exit 0 ;;
amiga:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
arc:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
hp300:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mac68k:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
macppc:OpenBSD:*:*)
echo powerpc-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mvme68k:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mvme88k:OpenBSD:*:*)
echo m88k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mvmeppc:OpenBSD:*:*)
echo powerpc-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
pegasos:OpenBSD:*:*)
echo powerpc-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
pmax:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
sgi:OpenBSD:*:*)
echo mipseb-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
sun3:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
wgrisc:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
*:OpenBSD:*:*)
echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
alpha:OSF1:*:*)
if test $UNAME_RELEASE = "V4.0"; then
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
fi
# According to Compaq, /usr/sbin/psrinfo has been available on
# OSF/1 and Tru64 systems produced since 1995. I hope that
# covers most systems running today. This code pipes the CPU
# types through head -n 1, so we only detect the type of CPU 0.
ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
case "$ALPHA_CPU_TYPE" in
"EV4 (21064)")
UNAME_MACHINE="alpha" ;;
"EV4.5 (21064)")
UNAME_MACHINE="alpha" ;;
"LCA4 (21066/21068)")
UNAME_MACHINE="alpha" ;;
"EV5 (21164)")
UNAME_MACHINE="alphaev5" ;;
"EV5.6 (21164A)")
UNAME_MACHINE="alphaev56" ;;
"EV5.6 (21164PC)")
UNAME_MACHINE="alphapca56" ;;
"EV5.7 (21164PC)")
UNAME_MACHINE="alphapca57" ;;
"EV6 (21264)")
UNAME_MACHINE="alphaev6" ;;
"EV6.7 (21264A)")
UNAME_MACHINE="alphaev67" ;;
"EV6.8CB (21264C)")
UNAME_MACHINE="alphaev68" ;;
"EV6.8AL (21264B)")
UNAME_MACHINE="alphaev68" ;;
"EV6.8CX (21264D)")
UNAME_MACHINE="alphaev68" ;;
"EV6.9A (21264/EV69A)")
UNAME_MACHINE="alphaev69" ;;
"EV7 (21364)")
UNAME_MACHINE="alphaev7" ;;
"EV7.9 (21364A)")
UNAME_MACHINE="alphaev79" ;;
esac
# A Vn.n version is a released version.
# A Tn.n version is a released field test version.
# A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r.
cat <<EOF >$dummy.s
.data
\$Lformat:
.byte 37,100,45,37,120,10,0 # "%d-%x\n"
.text
.globl main
.align 4
.ent main
main:
.frame \$30,16,\$26,0
ldgp \$29,0(\$27)
.prologue 1
.long 0x47e03d80 # implver \$0
lda \$2,-1
.long 0x47e20c21 # amask \$2,\$1
lda \$16,\$Lformat
mov \$0,\$17
not \$1,\$18
jsr \$26,printf
ldgp \$29,0(\$26)
mov 0,\$16
jsr \$26,exit
.end main
EOF
eval $set_cc_for_build
$CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null
if test "$?" = 0 ; then
case `./$dummy` in
0-0)
UNAME_MACHINE="alpha"
;;
1-0)
UNAME_MACHINE="alphaev5"
;;
1-1)
UNAME_MACHINE="alphaev56"
;;
1-101)
UNAME_MACHINE="alphapca56"
;;
2-303)
UNAME_MACHINE="alphaev6"
;;
2-307)
UNAME_MACHINE="alphaev67"
;;
2-1307)
UNAME_MACHINE="alphaev68"
;;
esac
fi
rm -f $dummy.s $dummy
echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
exit 0 ;;
Alpha*:OpenVMS:*:*)
echo alpha-hp-vms
exit 0 ;;
Alpha\ *:Windows_NT*:*)
# How do we know it's Interix rather than the generic POSIX subsystem?
# Should we change UNAME_MACHINE based on the output of uname instead
@@ -247,33 +301,18 @@ EOF
Amiga*:UNIX_System_V:4.0:*)
echo m68k-unknown-sysv4
exit 0;;
amiga:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
*:[Aa]miga[Oo][Ss]:*:*)
echo ${UNAME_MACHINE}-unknown-amigaos
exit 0 ;;
arc64:OpenBSD:*:*)
echo mips64el-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
arc:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
hkmips:OpenBSD:*:*)
echo mips-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
pmax:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
sgi:OpenBSD:*:*)
echo mips-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
wgrisc:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
*:[Mm]orph[Oo][Ss]:*:*)
echo ${UNAME_MACHINE}-unknown-morphos
exit 0 ;;
*:OS/390:*:*)
echo i370-ibm-openedition
exit 0 ;;
*:OS400:*:*)
echo powerpc-ibm-os400
exit 0 ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
exit 0;;
@@ -291,6 +330,13 @@ EOF
NILE*:*:*:dcosx)
echo pyramid-pyramid-svr4
exit 0 ;;
DRS?6000:unix:4.0:6*)
echo sparc-icl-nx6
exit 0 ;;
DRS?6000:UNIX_SV:4.2*:7*)
case `/usr/bin/uname -p` in
sparc) echo sparc-icl-nx7 && exit 0 ;;
esac ;;
sun4H:SunOS:5.*:*)
echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
@@ -319,7 +365,7 @@ EOF
echo m68k-sun-sunos${UNAME_RELEASE}
exit 0 ;;
sun*:*:4.2BSD:*)
UNAME_RELEASE=`(head -1 /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
case "`/bin/arch`" in
sun3)
@@ -333,12 +379,6 @@ EOF
aushp:SunOS:*:*)
echo sparc-auspex-sunos${UNAME_RELEASE}
exit 0 ;;
sparc*:NetBSD:*)
echo `uname -p`-unknown-netbsd${UNAME_RELEASE}
exit 0 ;;
atari*:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
# The situation for MiNT is a little confusing. The machine name
# can be virtually everything (everything which is not
# "atarist" or "atariste" at least should have a processor
@@ -365,18 +405,6 @@ EOF
*:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
echo m68k-unknown-mint${UNAME_RELEASE}
exit 0 ;;
sun3*:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mac68k:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mvme68k:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mvme88k:OpenBSD:*:*)
echo m88k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
powerpc:machten:*:*)
echo powerpc-apple-machten${UNAME_RELEASE}
exit 0 ;;
@@ -415,15 +443,20 @@ EOF
exit (-1);
}
EOF
$CC_FOR_BUILD $dummy.c -o $dummy \
&& ./$dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
&& rm -f $dummy.c $dummy && exit 0
rm -f $dummy.c $dummy
$CC_FOR_BUILD -o $dummy $dummy.c \
&& $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
&& exit 0
echo mips-mips-riscos${UNAME_RELEASE}
exit 0 ;;
Motorola:PowerMAX_OS:*:*)
echo powerpc-motorola-powermax
exit 0 ;;
Motorola:*:4.3:PL8-*)
echo powerpc-harris-powermax
exit 0 ;;
Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
echo powerpc-harris-powermax
exit 0 ;;
Night_Hawk:Power_UNIX:*:*)
echo powerpc-harris-powerunix
exit 0 ;;
@@ -496,8 +529,7 @@ EOF
exit(0);
}
EOF
$CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0
rm -f $dummy.c $dummy
$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
echo rs6000-ibm-aix3.2.5
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
echo rs6000-ibm-aix3.2.4
@@ -506,7 +538,7 @@ EOF
fi
exit 0 ;;
*:AIX:*:[45])
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ print $1 }'`
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
IBM_ARCH=rs6000
else
@@ -546,10 +578,8 @@ EOF
9000/31? ) HP_ARCH=m68000 ;;
9000/[34]?? ) HP_ARCH=m68k ;;
9000/[678][0-9][0-9])
case "${HPUX_REV}" in
11.[0-9][0-9])
if [ -x /usr/bin/getconf ]; then
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
if [ -x /usr/bin/getconf ]; then
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
case "${sc_cpu_version}" in
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
@@ -558,13 +588,13 @@ EOF
case "${sc_kernel_bits}" in
32) HP_ARCH="hppa2.0n" ;;
64) HP_ARCH="hppa2.0w" ;;
'') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
esac ;;
esac
fi ;;
esac
if [ "${HP_ARCH}" = "" ]; then
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
fi
if [ "${HP_ARCH}" = "" ]; then
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#define _HPUX_SOURCE
#include <stdlib.h>
@@ -597,11 +627,21 @@ EOF
exit (0);
}
EOF
(CCOPTS= $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null ) && HP_ARCH=`./$dummy`
if test -z "$HP_ARCH"; then HP_ARCH=hppa; fi
rm -f $dummy.c $dummy
fi ;;
(CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
test -z "$HP_ARCH" && HP_ARCH=hppa
fi ;;
esac
if [ ${HP_ARCH} = "hppa2.0w" ]
then
# avoid double evaluation of $set_cc_for_build
test -n "$CC_FOR_BUILD" || eval $set_cc_for_build
if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null
then
HP_ARCH="hppa2.0w"
else
HP_ARCH="hppa64"
fi
fi
echo ${HP_ARCH}-hp-hpux${HPUX_REV}
exit 0 ;;
ia64:HP-UX:*:*)
@@ -635,8 +675,7 @@ EOF
exit (0);
}
EOF
$CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0
rm -f $dummy.c $dummy
$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
echo unknown-hitachi-hiuxwe2
exit 0 ;;
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
@@ -664,9 +703,6 @@ EOF
parisc*:Lites*:*:*)
echo hppa1.1-hp-lites
exit 0 ;;
hppa*:OpenBSD:*:*)
echo hppa-unknown-openbsd
exit 0 ;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
echo c1-convex-bsd
exit 0 ;;
@@ -685,9 +721,6 @@ EOF
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
echo c4-convex-bsd
exit 0 ;;
CRAY*X-MP:*:*:*)
echo xmp-cray-unicos
exit 0 ;;
CRAY*Y-MP:*:*:*)
echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit 0 ;;
@@ -700,26 +733,25 @@ EOF
CRAY*TS:*:*:*)
echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit 0 ;;
CRAY*T3D:*:*:*)
echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit 0 ;;
CRAY*T3E:*:*:*)
echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit 0 ;;
CRAY*SV1:*:*:*)
echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit 0 ;;
CRAY-2:*:*:*)
echo cray2-cray-unicos
exit 0 ;;
*:UNICOS/mp:*:*)
echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit 0 ;;
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit 0 ;;
hp300:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
5000:UNIX_System_V:4.*:*)
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit 0 ;;
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
@@ -731,10 +763,21 @@ EOF
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
exit 0 ;;
*:FreeBSD:*:*)
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit 0 ;;
*:OpenBSD:*:*)
echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
# Determine whether the default compiler uses glibc.
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#include <features.h>
#if __GLIBC__ >= 2
LIBC=gnu
#else
LIBC=
#endif
EOF
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
# GNU/KFreeBSD systems have a "k" prefix to indicate we are using
# FreeBSD's kernel, but not the complete OS.
case ${LIBC} in gnu) kernel_only='k' ;; esac
echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC}
exit 0 ;;
i*:CYGWIN*:*)
echo ${UNAME_MACHINE}-pc-cygwin
@@ -745,11 +788,17 @@ EOF
i*:PW*:*)
echo ${UNAME_MACHINE}-pc-pw32
exit 0 ;;
x86:Interix*:[34]*)
echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//'
exit 0 ;;
[345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
echo i${UNAME_MACHINE}-pc-mks
exit 0 ;;
i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
# How do we know it's Interix rather than the generic POSIX subsystem?
# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
# UNAME_MACHINE based on the output of uname instead of i386?
echo i386-pc-interix
echo i586-pc-interix
exit 0 ;;
i*:UWIN*:*)
echo ${UNAME_MACHINE}-pc-uwin
@@ -761,25 +810,65 @@ EOF
echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
*:GNU:*:*)
# the GNU system
echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
exit 0 ;;
*:GNU/*:*:*)
# other systems with GNU libc and userland
echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
exit 0 ;;
i*86:Minix:*:*)
echo ${UNAME_MACHINE}-pc-minix
exit 0 ;;
arm*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit 0 ;;
cris:Linux:*:*)
echo cris-axis-linux-gnu
exit 0 ;;
ia64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit 0 ;;
m68*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit 0 ;;
mips:Linux:*:*)
case `sed -n '/^byte/s/^.*: \(.*\) endian/\1/p' < /proc/cpuinfo` in
big) echo mips-unknown-linux-gnu && exit 0 ;;
little) echo mipsel-unknown-linux-gnu && exit 0 ;;
esac
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#undef CPU
#undef mips
#undef mipsel
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
CPU=mipsel
#else
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
CPU=mips
#else
CPU=
#endif
#endif
EOF
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
;;
mips64:Linux:*:*)
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#undef CPU
#undef mips64
#undef mips64el
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
CPU=mips64el
#else
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
CPU=mips64
#else
CPU=
#endif
#endif
EOF
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
;;
ppc:Linux:*:*)
echo powerpc-unknown-linux-gnu
@@ -815,6 +904,9 @@ EOF
s390:Linux:*:* | s390x:Linux:*:*)
echo ${UNAME_MACHINE}-ibm-linux
exit 0 ;;
sh64*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit 0 ;;
sh*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit 0 ;;
@@ -828,7 +920,8 @@ EOF
# The BFD linker knows what the default object file format is, so
# first see if it will tell us. cd to the root directory to prevent
# problems with other programs or directories called `ld' in the path.
ld_supported_targets=`cd /; ld --help 2>&1 \
# Set LC_ALL=C to ensure ld outputs messages in English.
ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
| sed -ne '/supported targets:/!d
s/[ ][ ]*/ /g
s/.*supported targets: *//
@@ -840,7 +933,7 @@ EOF
;;
a.out-i386-linux)
echo "${UNAME_MACHINE}-pc-linux-gnuaout"
exit 0 ;;
exit 0 ;;
coff-i386)
echo "${UNAME_MACHINE}-pc-linux-gnucoff"
exit 0 ;;
@@ -852,32 +945,31 @@ EOF
esac
# Determine whether the default compiler is a.out or elf
eval $set_cc_for_build
cat >$dummy.c <<EOF
#include <features.h>
#ifdef __cplusplus
#include <stdio.h> /* for printf() prototype */
int main (int argc, char *argv[]) {
#else
int main (argc, argv) int argc; char *argv[]; {
#endif
#ifdef __ELF__
# ifdef __GLIBC__
# if __GLIBC__ >= 2
printf ("%s-pc-linux-gnu\n", argv[1]);
# else
printf ("%s-pc-linux-gnulibc1\n", argv[1]);
# endif
# else
printf ("%s-pc-linux-gnulibc1\n", argv[1]);
# endif
#else
printf ("%s-pc-linux-gnuaout\n", argv[1]);
#endif
return 0;
}
sed 's/^ //' << EOF >$dummy.c
#include <features.h>
#ifdef __ELF__
# ifdef __GLIBC__
# if __GLIBC__ >= 2
LIBC=gnu
# else
LIBC=gnulibc1
# endif
# else
LIBC=gnulibc1
# endif
#else
#ifdef __INTEL_COMPILER
LIBC=gnu
#else
LIBC=gnuaout
#endif
#endif
#ifdef __dietlibc__
LIBC=dietlibc
#endif
EOF
$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm -f $dummy.c $dummy && exit 0
rm -f $dummy.c $dummy
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
;;
i*86:DYNIX/ptx:4*:*)
@@ -894,6 +986,26 @@ EOF
# Use sysv4.2uw... so that sysv4* matches it.
echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
exit 0 ;;
i*86:OS/2:*:*)
# If we were able to find `uname', then EMX Unix compatibility
# is probably installed.
echo ${UNAME_MACHINE}-pc-os2-emx
exit 0 ;;
i*86:XTS-300:*:STOP)
echo ${UNAME_MACHINE}-unknown-stop
exit 0 ;;
i*86:atheos:*:*)
echo ${UNAME_MACHINE}-unknown-atheos
exit 0 ;;
i*86:syllable:*:*)
echo ${UNAME_MACHINE}-pc-syllable
exit 0 ;;
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
echo i386-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
i*86:*DOS:*:*)
echo ${UNAME_MACHINE}-pc-msdosdjgpp
exit 0 ;;
i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
@@ -915,22 +1027,19 @@ EOF
UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
elif /bin/uname -X 2>/dev/null >/dev/null ; then
UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')`
(/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486
(/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
&& UNAME_MACHINE=i586
(/bin/uname -X|egrep '^Machine.*Pent ?II' >/dev/null) \
(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
&& UNAME_MACHINE=i686
(/bin/uname -X|egrep '^Machine.*Pentium Pro' >/dev/null) \
(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
&& UNAME_MACHINE=i686
echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
else
echo ${UNAME_MACHINE}-pc-sysv32
fi
exit 0 ;;
i*86:*DOS:*:*)
echo ${UNAME_MACHINE}-pc-msdosdjgpp
exit 0 ;;
pc:*:*:*)
# Left here for compatibility:
# uname -m prints for DJGPP always 'pc', but it prints nothing about
@@ -954,9 +1063,15 @@ EOF
# "miniframe"
echo m68010-convergent-sysv
exit 0 ;;
mc68k:UNIX:SYSTEM5:3.51m)
echo m68k-convergent-sysv
exit 0 ;;
M680?0:D-NIX:5.3:*)
echo m68k-diab-dnix
exit 0 ;;
M68*:*:R3V[567]*:*)
test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0)
3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0)
OS_REL=''
test -r /etc/.relid \
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
@@ -973,9 +1088,6 @@ EOF
mc68030:UNIX_System_V:4.*:*)
echo m68k-atari-sysv4
exit 0 ;;
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
echo i386-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
TSUNAMI:LynxOS:2.*:*)
echo sparc-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
@@ -1047,6 +1159,9 @@ EOF
SX-5:SUPER-UX:*:*)
echo sx5-nec-superux${UNAME_RELEASE}
exit 0 ;;
SX-6:SUPER-UX:*:*)
echo sx6-nec-superux${UNAME_RELEASE}
exit 0 ;;
Power*:Rhapsody:*:*)
echo powerpc-apple-rhapsody${UNAME_RELEASE}
exit 0 ;;
@@ -1054,18 +1169,24 @@ EOF
echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
exit 0 ;;
*:Darwin:*:*)
echo `uname -p`-apple-darwin${UNAME_RELEASE}
case `uname -p` in
*86) UNAME_PROCESSOR=i686 ;;
powerpc) UNAME_PROCESSOR=powerpc ;;
esac
echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
exit 0 ;;
*:procnto*:*:* | *:QNX:[0123456789]*:*)
if test "${UNAME_MACHINE}" = "x86pc"; then
UNAME_PROCESSOR=`uname -p`
if test "$UNAME_PROCESSOR" = "x86"; then
UNAME_PROCESSOR=i386
UNAME_MACHINE=pc
fi
echo `uname -p`-${UNAME_MACHINE}-nto-qnx
echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
exit 0 ;;
*:QNX:*:4*)
echo i386-pc-qnx
exit 0 ;;
NSR-[KW]:NONSTOP_KERNEL:*:*)
NSR-?:NONSTOP_KERNEL:*:*)
echo nsr-tandem-nsk${UNAME_RELEASE}
exit 0 ;;
*:NonStop-UX:*:*)
@@ -1088,11 +1209,6 @@ EOF
fi
echo ${UNAME_MACHINE}-unknown-plan9
exit 0 ;;
i*86:OS/2:*:*)
# If we were able to find `uname', then EMX Unix compatibility
# is probably installed.
echo ${UNAME_MACHINE}-pc-os2-emx
exit 0 ;;
*:TOPS-10:*:*)
echo pdp10-unknown-tops10
exit 0 ;;
@@ -1111,11 +1227,11 @@ EOF
*:ITS:*:*)
echo pdp10-unknown-its
exit 0 ;;
i*86:XTS-300:*:STOP)
echo ${UNAME_MACHINE}-unknown-stop
SEI:*:*:SEIUX)
echo mips-sei-seiux${UNAME_RELEASE}
exit 0 ;;
i*86:atheos:*:*)
echo ${UNAME_MACHINE}-unknown-atheos
*:DRAGONFLY:*:*)
echo ${UNAME_MACHINE}-unknown-dragonfly${UNAME_RELEASE}
exit 0 ;;
esac
@@ -1237,8 +1353,7 @@ main ()
}
EOF
$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm -f $dummy.c $dummy && exit 0
rm -f $dummy.c $dummy
$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0
# Apollos put the system type in the environment.
Vendored
+233 -107
View File
@@ -1,9 +1,9 @@
#! /bin/sh
# Configuration validation subroutine script.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
# Free Software Foundation, Inc.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
timestamp='2001-09-07'
timestamp='2004-01-05'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
@@ -29,7 +29,8 @@ timestamp='2001-09-07'
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Please send patches to <config-patches@gnu.org>.
# Please send patches to <config-patches@gnu.org>. Submit a context
# diff and a properly formatted ChangeLog entry.
#
# Configuration subroutine to validate and canonicalize a configuration type.
# Supply the specified configuration type as an argument.
@@ -117,7 +118,8 @@ esac
# Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in
nto-qnx* | linux-gnu* | storm-chaos* | os2-emx* | windows32-*)
nto-qnx* | linux-gnu* | linux-dietlibc | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | \
kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
;;
@@ -226,32 +228,46 @@ case $basic_machine in
1750a | 580 \
| a29k \
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
| am33_2.0 \
| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
| c4x | clipper \
| d10v | d30v | dsp16xx \
| fr30 \
| d10v | d30v | dlx | dsp16xx \
| fr30 | frv \
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| i370 | i860 | i960 | ia64 \
| ip2k | iq2000 \
| m32r | m68000 | m68k | m88k | mcore \
| mips16 | mips64 | mips64el | mips64orion | mips64orionel \
| mips64vr4100 | mips64vr4100el | mips64vr4300 \
| mips64vr4300el | mips64vr5000 | mips64vr5000el \
| mipsbe | mipseb | mipsel | mipsle | mipstx39 | mipstx39el \
| mipsisa32 \
| mips | mipsbe | mipseb | mipsel | mipsle \
| mips16 \
| mips64 | mips64el \
| mips64vr | mips64vrel \
| mips64orion | mips64orionel \
| mips64vr4100 | mips64vr4100el \
| mips64vr4300 | mips64vr4300el \
| mips64vr5000 | mips64vr5000el \
| mipsisa32 | mipsisa32el \
| mipsisa32r2 | mipsisa32r2el \
| mipsisa64 | mipsisa64el \
| mipsisa64r2 | mipsisa64r2el \
| mipsisa64sb1 | mipsisa64sb1el \
| mipsisa64sr71k | mipsisa64sr71kel \
| mipstx39 | mipstx39el \
| mn10200 | mn10300 \
| msp430 \
| ns16k | ns32k \
| openrisc \
| openrisc | or32 \
| pdp10 | pdp11 | pj | pjl \
| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
| pyramid \
| s390 | s390x \
| sh | sh[34] | sh[34]eb | shbe | shle \
| sparc | sparc64 | sparclet | sparclite | sparcv9 | sparcv9b \
| stormy16 | strongarm \
| tahoe | thumb | tic80 | tron \
| v850 \
| sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
| sh64 | sh64le \
| sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \
| strongarm \
| tahoe | thumb | tic4x | tic80 | tron \
| v850 | v850e \
| we32k \
| x86 | xscale \
| x86 | xscale | xstormy16 | xtensa \
| z8k)
basic_machine=$basic_machine-unknown
;;
@@ -278,38 +294,56 @@ case $basic_machine in
580-* \
| a29k-* \
| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
| alphapca5[67]-* | arc-* \
| arm-* | armbe-* | armle-* | armv*-* \
| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \
| avr-* \
| bs2000-* \
| c[123]* | c30-* | [cjt]90-* | c54x-* \
| clipper-* | cray2-* | cydra-* \
| d10v-* | d30v-* \
| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
| clipper-* | cydra-* \
| d10v-* | d30v-* | dlx-* \
| elxsi-* \
| f30[01]-* | f700-* | fr30-* | fx80-* \
| f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \
| h8300-* | h8500-* \
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
| i*86-* | i860-* | i960-* | ia64-* \
| ip2k-* | iq2000-* \
| m32r-* \
| m68000-* | m680[01234]0-* | m68360-* | m683?2-* | m68k-* \
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
| m88110-* | m88k-* | mcore-* \
| mips-* | mips16-* | mips64-* | mips64el-* | mips64orion-* \
| mips64orionel-* | mips64vr4100-* | mips64vr4100el-* \
| mips64vr4300-* | mips64vr4300el-* | mipsbe-* | mipseb-* \
| mipsle-* | mipsel-* | mipstx39-* | mipstx39el-* \
| none-* | np1-* | ns16k-* | ns32k-* \
| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
| mips16-* \
| mips64-* | mips64el-* \
| mips64vr-* | mips64vrel-* \
| mips64orion-* | mips64orionel-* \
| mips64vr4100-* | mips64vr4100el-* \
| mips64vr4300-* | mips64vr4300el-* \
| mips64vr5000-* | mips64vr5000el-* \
| mipsisa32-* | mipsisa32el-* \
| mipsisa32r2-* | mipsisa32r2el-* \
| mipsisa64-* | mipsisa64el-* \
| mipsisa64r2-* | mipsisa64r2el-* \
| mipsisa64sb1-* | mipsisa64sb1el-* \
| mipsisa64sr71k-* | mipsisa64sr71kel-* \
| mipstx39-* | mipstx39el-* \
| msp430-* \
| none-* | np1-* | nv1-* | ns16k-* | ns32k-* \
| orion-* \
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
| pyramid-* \
| romp-* | rs6000-* \
| s390-* | s390x-* \
| sh-* | sh[34]-* | sh[34]eb-* | shbe-* | shle-* \
| sparc-* | sparc64-* | sparc86x-* | sparclite-* \
| sparcv9-* | sparcv9b-* | stormy16-* | strongarm-* | sv1-* \
| t3e-* | tahoe-* | thumb-* | tic30-* | tic54x-* | tic80-* | tron-* \
| v850-* | vax-* \
| sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \
| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
| sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \
| sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
| tahoe-* | thumb-* \
| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
| tron-* \
| v850-* | v850e-* | vax-* \
| we32k-* \
| x86-* | x86_64-* | xmp-* | xps100-* | xscale-* \
| x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \
| xtensa-* \
| ymp-* \
| z8k-*)
;;
@@ -343,6 +377,12 @@ case $basic_machine in
basic_machine=a29k-none
os=-bsd
;;
amd64)
basic_machine=x86_64-pc
;;
amd64-*)
basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
amdahl)
basic_machine=580-amdahl
os=-sysv
@@ -374,6 +414,10 @@ case $basic_machine in
basic_machine=ns32k-sequent
os=-dynix
;;
c90)
basic_machine=c90-cray
os=-unicos
;;
convex-c1)
basic_machine=c1-convex
os=-bsd
@@ -394,16 +438,8 @@ case $basic_machine in
basic_machine=c38-convex
os=-bsd
;;
cray | ymp)
basic_machine=ymp-cray
os=-unicos
;;
cray2)
basic_machine=cray2-cray
os=-unicos
;;
[cjt]90)
basic_machine=${basic_machine}-cray
cray | j90)
basic_machine=j90-cray
os=-unicos
;;
crds | unos)
@@ -418,6 +454,14 @@ case $basic_machine in
decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
basic_machine=mips-dec
;;
decsystem10* | dec10*)
basic_machine=pdp10-dec
os=-tops10
;;
decsystem20* | dec20*)
basic_machine=pdp10-dec
os=-tops20
;;
delta | 3300 | motorola-3300 | motorola-delta \
| 3300-motorola | delta-motorola)
basic_machine=m68k-motorola
@@ -598,14 +642,6 @@ case $basic_machine in
basic_machine=m68k-atari
os=-mint
;;
mipsel*-linux*)
basic_machine=mipsel-unknown
os=-linux-gnu
;;
mips*-linux*)
basic_machine=mips-unknown
os=-linux-gnu
;;
mips3*-*)
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
;;
@@ -620,6 +656,10 @@ case $basic_machine in
basic_machine=m68k-rom68k
os=-coff
;;
morphos)
basic_machine=powerpc-unknown
os=-morphos
;;
msdos)
basic_machine=i386-pc
os=-msdos
@@ -692,6 +732,10 @@ case $basic_machine in
np1)
basic_machine=np1-gould
;;
nv1)
basic_machine=nv1-cray
os=-unicosmp
;;
nsr-tandem)
basic_machine=nsr-tandem
;;
@@ -699,6 +743,14 @@ case $basic_machine in
basic_machine=hppa1.1-oki
os=-proelf
;;
or32 | or32-*)
basic_machine=or32-unknown
os=-coff
;;
os400)
basic_machine=powerpc-ibm
os=-os400
;;
OSE68000 | ose68000)
basic_machine=m68000-ericsson
os=-ose
@@ -721,49 +773,55 @@ case $basic_machine in
pbb)
basic_machine=m68k-tti
;;
pc532 | pc532-*)
pc532 | pc532-*)
basic_machine=ns32k-pc532
;;
pentium | p5 | k5 | k6 | nexgen)
pentium | p5 | k5 | k6 | nexgen | viac3)
basic_machine=i586-pc
;;
pentiumpro | p6 | 6x86 | athlon)
pentiumpro | p6 | 6x86 | athlon | athlon_*)
basic_machine=i686-pc
;;
pentiumii | pentium2)
pentiumii | pentium2 | pentiumiii | pentium3)
basic_machine=i686-pc
;;
pentium-* | p5-* | k5-* | k6-* | nexgen-*)
pentium4)
basic_machine=i786-pc
;;
pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumpro-* | p6-* | 6x86-* | athlon-*)
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumii-* | pentium2-*)
pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentium4-*)
basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pn)
basic_machine=pn-gould
;;
power) basic_machine=power-ibm
;;
ppc) basic_machine=powerpc-unknown
;;
;;
ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppcle | powerpclittle | ppc-le | powerpc-little)
basic_machine=powerpcle-unknown
;;
;;
ppcle-* | powerpclittle-*)
basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppc64) basic_machine=powerpc64-unknown
;;
;;
ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppc64le | powerpc64little | ppc64-le | powerpc64-little)
basic_machine=powerpc64le-unknown
;;
;;
ppc64le-* | powerpc64little-*)
basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
@@ -784,10 +842,26 @@ case $basic_machine in
rtpc | rtpc-*)
basic_machine=romp-ibm
;;
s390 | s390-*)
basic_machine=s390-ibm
;;
s390x | s390x-*)
basic_machine=s390x-ibm
;;
sa29200)
basic_machine=a29k-amd
os=-udi
;;
sb1)
basic_machine=mipsisa64sb1-unknown
;;
sb1el)
basic_machine=mipsisa64sb1el-unknown
;;
sei)
basic_machine=mips-sei
os=-seiux
;;
sequent)
basic_machine=i386-sequent
;;
@@ -795,7 +869,10 @@ case $basic_machine in
basic_machine=sh-hitachi
os=-hms
;;
sparclite-wrs)
sh64)
basic_machine=sh64-unknown
;;
sparclite-wrs | simso-wrs)
basic_machine=sparclite-wrs
os=-vxworks
;;
@@ -862,22 +939,42 @@ case $basic_machine in
os=-dynix
;;
t3e)
basic_machine=t3e-cray
basic_machine=alphaev5-cray
os=-unicos
;;
t90)
basic_machine=t90-cray
os=-unicos
;;
tic54x | c54x*)
basic_machine=tic54x-unknown
os=-coff
;;
tic55x | c55x*)
basic_machine=tic55x-unknown
os=-coff
;;
tic6x | c6x*)
basic_machine=tic6x-unknown
os=-coff
;;
tx39)
basic_machine=mipstx39-unknown
;;
tx39el)
basic_machine=mipstx39el-unknown
;;
toad1)
basic_machine=pdp10-xkl
os=-tops20
;;
tower | tower-32)
basic_machine=m68k-ncr
;;
tpf)
basic_machine=s390x-ibm
os=-tpf
;;
udi29k)
basic_machine=a29k-amd
os=-udi
@@ -899,8 +996,8 @@ case $basic_machine in
os=-vms
;;
vpp*|vx|vx-*)
basic_machine=f301-fujitsu
;;
basic_machine=f301-fujitsu
;;
vxworks960)
basic_machine=i960-wrs
os=-vxworks
@@ -921,17 +1018,13 @@ case $basic_machine in
basic_machine=hppa1.1-winbond
os=-proelf
;;
windows32)
basic_machine=i386-pc
os=-windows32-msvcrt
;;
xmp)
basic_machine=xmp-cray
os=-unicos
;;
xps | xps100)
xps | xps100)
basic_machine=xps100-honeywell
;;
ymp)
basic_machine=ymp-cray
os=-unicos
;;
z8k-*-coff)
basic_machine=z8k-unknown
os=-sim
@@ -952,13 +1045,6 @@ case $basic_machine in
op60c)
basic_machine=hppa1.1-oki
;;
mips)
if [ x$os = x-linux-gnu ]; then
basic_machine=mips-unknown
else
basic_machine=mips-mips
fi
;;
romp)
basic_machine=romp-ibm
;;
@@ -978,13 +1064,16 @@ case $basic_machine in
we32k)
basic_machine=we32k-att
;;
sh3 | sh4 | sh3eb | sh4eb)
sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele)
basic_machine=sh-unknown
;;
sh64)
basic_machine=sh64-unknown
;;
sparc | sparcv9 | sparcv9b)
basic_machine=sparc-sun
;;
cydra)
cydra)
basic_machine=cydra-cydrome
;;
orion)
@@ -999,10 +1088,6 @@ case $basic_machine in
pmac | pmac-mpw)
basic_machine=powerpc-apple
;;
c4x*)
basic_machine=c4x-none
os=-coff
;;
*-unknown)
# Make sure to match an already-canonicalized machine name.
;;
@@ -1058,17 +1143,19 @@ case $os in
| -aos* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
| -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \
| -hiux* | -386bsd* | -knetbsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \
| -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -chorusos* | -chorusrdb* \
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \
| -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \
| -mingw32* | -linux-gnu* | -linux-uclibc* | -uxpv* | -beos* | -mpeix* | -udk* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
| -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
| -os2* | -vos*)
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
@@ -1080,8 +1167,10 @@ case $os in
;;
esac
;;
-nto-qnx*)
;;
-nto*)
os=-nto-qnx
os=`echo $os | sed -e 's|nto|nto-qnx|'`
;;
-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
| -windows* | -osx | -abug | -netware* | -os9* | -beos* \
@@ -1090,6 +1179,9 @@ case $os in
-mac*)
os=`echo $os | sed -e 's|mac|macos|'`
;;
-linux-dietlibc)
os=-linux-dietlibc
;;
-linux*)
os=`echo $os | sed -e 's|linux|linux-gnu|'`
;;
@@ -1102,6 +1194,9 @@ case $os in
-opened*)
os=-openedition
;;
-os400*)
os=-os400
;;
-wince*)
os=-wince
;;
@@ -1120,14 +1215,23 @@ case $os in
-acis*)
os=-aos
;;
-atheos*)
os=-atheos
;;
-syllable*)
os=-syllable
;;
-386bsd)
os=-bsd
;;
-ctix* | -uts*)
os=-sysv
;;
-nova*)
os=-rtmk-nova
;;
-ns2 )
os=-nextstep2
os=-nextstep2
;;
-nsk*)
os=-nsk
@@ -1139,6 +1243,9 @@ case $os in
-sinix*)
os=-sysv4
;;
-tpf*)
os=-tpf
;;
-triton*)
os=-sysv3
;;
@@ -1166,8 +1273,14 @@ case $os in
-xenix)
os=-xenix
;;
-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
os=-mint
-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
os=-mint
;;
-aros*)
os=-aros
;;
-kaos*)
os=-kaos
;;
-none)
;;
@@ -1200,10 +1313,14 @@ case $basic_machine in
arm*-semi)
os=-aout
;;
c4x-* | tic4x-*)
os=-coff
;;
# This must come before the *-dec entry.
pdp10-*)
os=-tops20
;;
pdp11-*)
pdp11-*)
os=-none
;;
*-dec | vax-*)
@@ -1230,6 +1347,9 @@ case $basic_machine in
mips*-*)
os=-elf
;;
or32-*)
os=-coff
;;
*-tti) # must be before sparc entry or we get the wrong os.
os=-sysv3
;;
@@ -1293,19 +1413,19 @@ case $basic_machine in
*-next)
os=-nextstep3
;;
*-gould)
*-gould)
os=-sysv
;;
*-highlevel)
*-highlevel)
os=-bsd
;;
*-encore)
os=-bsd
;;
*-sgi)
*-sgi)
os=-irix
;;
*-siemens)
*-siemens)
os=-sysv4
;;
*-masscomp)
@@ -1374,10 +1494,16 @@ case $basic_machine in
-mvs* | -opened*)
vendor=ibm
;;
-os400*)
vendor=ibm
;;
-ptx*)
vendor=sequent
;;
-vxsim* | -vxworks*)
-tpf*)
vendor=ibm
;;
-vxsim* | -vxworks* | -windiss*)
vendor=wrs
;;
-aux*)
Vendored
+11199 -3927
View File
File diff suppressed because it is too large Load Diff
+77 -6
View File
@@ -138,7 +138,7 @@ AC_INIT(src/sqlite.h.in)
dnl Put the RCS revision string after AC_INIT so that it will also
dnl show in in configure.
# The following RCS revision string applies to configure.in
# $Revision: 1.1 $
# $Revision: 1.7 $
#########
# Programs needed
@@ -154,6 +154,12 @@ if test "$program_prefix" = "NONE"; then
fi
AC_SUBST(program_prefix)
if test -f VERSION; then
VERSION=`cat VERSION`
echo "Version set to $VERSION"
fi
AC_SUBST(VERSION)
#########
# Check to see if the --with-hints=FILE option is used. If there is none,
# then check for a files named "$host.hints" and ../$hosts.hints where
@@ -299,6 +305,67 @@ else
fi
AC_SUBST(ENCODING)
##########
# Do we want to support in-ram databases for ATTACH DATABASE and sqlite_open
#
AC_ARG_ENABLE(incore-db,
[ --enable-incore-db Support incore database],,enable_incore_db=yes)
AC_MSG_CHECKING([whether to support incore databases for attach and open])
if test "$enable_incore_db" = "no"; then
INMEMORYDB=0
AC_MSG_RESULT([no])
else
INMEMORYDB=1
AC_MSG_RESULT([yes])
fi
AC_SUBST(ALLOWATTACHMEM)
##########
# Do we want to support release
#
AC_ARG_ENABLE(releasemode,
[ --enable-releasemode Support libtool link to release mode],,enable_releasemode=no)
AC_MSG_CHECKING([whether to support shared library linked as release mode or not])
if test "$enable_releasemode" = "no"; then
ALLOWRELEASE=""
AC_MSG_RESULT([no])
else
ALLOWRELEASE="-release `cat VERSION`"
AC_MSG_RESULT([yes])
fi
AC_SUBST(ALLOWRELEASE)
##########
# Do we want temporary databases in memory
#
AC_ARG_ENABLE(tempdb-in-ram,
[ --enable-tempdb-in-ram Use an in-ram database for temporary tables],,enable_tempdb_in_ram=no)
AC_MSG_CHECKING([whether to use an in-ram database for temporary tables])
case "$enable_tempdb_in_ram" in
never )
TEMP_STORE=0
AC_MSG_RESULT([never])
;;
no )
INMEMORYDB=1
TEMP_STORE=1
AC_MSG_RESULT([no])
;;
always )
INMEMORYDB=1
TEMP_STORE=3
AC_MSG_RESULT([always])
;;
* )
INMEMORYDB=1
TEMP_STORE=2
AC_MSG_RESULT([yes])
;;
esac
AC_SUBST(INMEMORYDB)
AC_SUBST(TEMP_STORE)
###########
# Lots of things are different if we are compiling for Windows using
# the CYGWIN environment. So check for that special case and handle
@@ -317,7 +384,7 @@ fi
if test "$CYGWIN" = "yes"; then
BUILD_EXEEXT=.exe
else
BUILD_EXEEXT=""
BUILD_EXEEXT=$EXEEXT
fi
if test "$cross" = "0"; then
TARGET_EXEEXT=$BUILD_EXEEXT
@@ -368,7 +435,7 @@ else
else
LIBS=""
AC_SEARCH_LIBS(Tcl_Init, dnl
tcl8.4 tcl8.3 tcl8.2 tcl8.1 tcl8.0 tcl80 tcl,,,$otherlibs)
tcl8.4 tcl8.3 tcl84 tcl83 tcl,,,$otherlibs)
fi
TARGET_TCL_LIBS="$LIBS $otherlibs"
fi
@@ -420,7 +487,8 @@ if test "$config_TARGET_READLINE_LIBS" != ""; then
else
CC=$TARGET_CC
LIBS=""
AC_SEARCH_LIBS(readline, readline,,,)
AC_SEARCH_LIBS(tgetent, [readline ncurses curses termcap])
AC_CHECK_LIB([readline], [readline])
TARGET_READLINE_LIBS="$LIBS"
fi
AC_SUBST(TARGET_READLINE_LIBS)
@@ -441,7 +509,7 @@ else
AC_CHECK_HEADER(readline.h, [found=yes])
fi
if test "$found" = "no"; then
for dir in /usr /usr/local /usr/local/readline /usr/contrib; do
for dir in /usr /usr/local /usr/local/readline /usr/contrib /mingw; do
AC_CHECK_FILE($dir/include/readline.h, found=yes)
if test "$found" = "yes"; then
TARGET_READLINE_INC="-I$dir/include"
@@ -474,4 +542,7 @@ AC_CHECK_FUNC(usleep, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_USLEEP=1"])
#########
# Generate the output files.
#
AC_OUTPUT(Makefile)
AC_OUTPUT([
Makefile
sqlite.pc
])
-6346
View File
File diff suppressed because it is too large Load Diff
+1802 -886
View File
File diff suppressed because it is too large Load Diff
+73 -13
View File
@@ -54,17 +54,25 @@ TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
# Object files for the SQLite library.
#
LIBOBJ = btree.o build.o delete.o expr.o func.o hash.o insert.o main.o \
opcodes.o os.o pager.o parse.o printf.o random.o select.o table.o \
tokenize.o trigger.o update.o util.o vdbe.o where.o tclsqlite.o
LIBOBJ = attach.o auth.o btree.o btree_rb.o build.o copy.o date.o delete.o \
expr.o func.o hash.o insert.o \
main.o opcodes.o os.o pager.o parse.o pragma.o printf.o random.o \
select.o table.o tokenize.o trigger.o update.o util.o \
vacuum.o vdbe.o vdbeaux.o where.o tclsqlite.o
# All of the source code files.
#
SRC = \
$(TOP)/src/attach.c \
$(TOP)/src/auth.c \
$(TOP)/src/btree.c \
$(TOP)/src/btree.h \
$(TOP)/src/btree_rb.c \
$(TOP)/src/build.c \
$(TOP)/src/copy.c \
$(TOP)/src/date.c \
$(TOP)/src/delete.c \
$(TOP)/src/encode.c \
$(TOP)/src/expr.c \
$(TOP)/src/func.c \
$(TOP)/src/hash.c \
@@ -75,6 +83,7 @@ SRC = \
$(TOP)/src/pager.c \
$(TOP)/src/pager.h \
$(TOP)/src/parse.y \
$(TOP)/src/pragma.c \
$(TOP)/src/printf.c \
$(TOP)/src/random.c \
$(TOP)/src/select.c \
@@ -87,8 +96,11 @@ SRC = \
$(TOP)/src/trigger.c \
$(TOP)/src/update.c \
$(TOP)/src/util.c \
$(TOP)/src/vacuum.c \
$(TOP)/src/vdbe.c \
$(TOP)/src/vdbe.h \
$(TOP)/src/vdbeaux.c \
$(TOP)/src/vdbeInt.h \
$(TOP)/src/where.c
# Source code to the test files.
@@ -101,6 +113,8 @@ TESTSRC = \
$(TOP)/src/test1.c \
$(TOP)/src/test2.c \
$(TOP)/src/test3.c \
$(TOP)/src/test4.c \
$(TOP)/src/vdbe.c \
$(TOP)/src/md5.c
# Header files used by all library source files.
@@ -108,17 +122,24 @@ TESTSRC = \
HDR = \
sqlite.h \
$(TOP)/src/btree.h \
config.h \
$(TOP)/src/hash.h \
opcodes.h \
$(TOP)/src/os.h \
$(TOP)/src/sqliteInt.h \
$(TOP)/src/vdbe.h \
$(TOP)/src/vdbe.h \
parse.h
# Header files used by the VDBE submodule
#
VDBEHDR = \
$(HDR) \
$(TOP)/src/vdbeInt.h
# This is the default Makefile target. The objects listed here
# are what get build when you type just "make" with no arguments.
#
all: sqlite.h libsqlite.a sqlite$(EXE)
all: sqlite.h config.h libsqlite.a sqlite$(EXE)
# Generate the file "last_change" which contains the date of change
# of the most recently modified source code file
@@ -141,10 +162,10 @@ sqlite$(EXE): $(TOP)/src/shell.c libsqlite.a sqlite.h
# files are automatically generated. This target takes care of
# all that automatic generation.
#
target_source: $(SRC) $(HDR) opcodes.c
target_source: $(SRC) $(VDBEHDR) opcodes.c
rm -rf tsrc
mkdir tsrc
cp $(SRC) $(HDR) tsrc
cp $(SRC) $(VDBEHDR) tsrc
rm tsrc/sqlite.h.in tsrc/parse.y
cp parse.c opcodes.c tsrc
@@ -157,6 +178,9 @@ lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
btree.o: $(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
$(TCCX) -c $(TOP)/src/btree.c
btree_rb.o: $(TOP)/src/btree_rb.c $(HDR)
$(TCCX) -c $(TOP)/src/btree_rb.c
build.o: $(TOP)/src/build.c $(HDR)
$(TCCX) -c $(TOP)/src/build.c
@@ -194,6 +218,22 @@ parse.c: $(TOP)/src/parse.y lemon
cp $(TOP)/src/parse.y .
./lemon parse.y
# The config.h file will contain a single #define that tells us how
# many bytes are in a pointer. This only works if a pointer is the
# same size on the host as it is on the target. If you are cross-compiling
# to a target with a different pointer size, you'll need to manually
# configure the config.h file.
#
config.h:
echo '#include <stdio.h>' >temp.c
echo 'int main(){printf(' >>temp.c
echo '"#define SQLITE_PTR_SZ %d",sizeof(char*));' >>temp.c
echo 'exit(0);}' >>temp.c
$(BCC) -o temp temp.c
./temp >config.h
echo >>config.h
rm -f temp.c temp
sqlite.h: $(TOP)/src/sqlite.h.in
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
-e s/--ENCODING--/$(ENCODING)/ \
@@ -208,15 +248,30 @@ trigger.o: $(TOP)/src/trigger.c $(HDR)
util.o: $(TOP)/src/util.c $(HDR)
$(TCCX) -c $(TOP)/src/util.c
vdbe.o: $(TOP)/src/vdbe.c $(HDR)
vacuum.o: $(TOP)/src/vacuum.c $(HDR)
$(TCCX) -c $(TOP)/src/vacuum.c
vdbe.o: $(TOP)/src/vdbe.c $(VDBEHDR)
$(TCCX) -c $(TOP)/src/vdbe.c
vdbeaux.o: $(TOP)/src/vdbeaux.c $(VDBEHDR)
$(TCCX) -c $(TOP)/src/vdbeaux.c
where.o: $(TOP)/src/where.c $(HDR)
$(TCCX) -c $(TOP)/src/where.c
copy.o: $(TOP)/src/copy.c $(HDR)
$(TCCX) -c $(TOP)/src/copy.c
date.o: $(TOP)/src/date.c $(HDR)
$(TCCX) -c $(TOP)/src/date.c
delete.o: $(TOP)/src/delete.c $(HDR)
$(TCCX) -c $(TOP)/src/delete.c
encode.o: $(TOP)/src/encode.c
$(TCCX) -c $(TOP)/src/encode.c
expr.o: $(TOP)/src/expr.c $(HDR)
$(TCCX) -c $(TOP)/src/expr.c
@@ -244,9 +299,18 @@ update.o: $(TOP)/src/update.c $(HDR)
tclsqlite.o: $(TOP)/src/tclsqlite.c $(HDR)
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
pragma.o: $(TOP)/src/pragma.c $(HDR)
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
printf.o: $(TOP)/src/printf.c $(HDR)
$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/printf.c
attach.o: $(TOP)/src/attach.c $(HDR)
$(TCCX) -c $(TOP)/src/attach.c
auth.o: $(TOP)/src/auth.c $(HDR)
$(TCCX) -c $(TOP)/src/auth.c
tclsqlite: $(TOP)/src/tclsqlite.c libsqlite.a
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite \
$(TOP)/src/tclsqlite.c libsqlite.a $(LIBTCL)
@@ -254,7 +318,7 @@ tclsqlite: $(TOP)/src/tclsqlite.c libsqlite.a
testfixture$(EXE): $(TOP)/src/tclsqlite.c libsqlite.a $(TESTSRC)
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -o testfixture$(EXE) \
$(TESTSRC) $(TOP)/src/tclsqlite.c \
libsqlite.a $(LIBTCL)
libsqlite.a $(LIBTCL) $(THREADLIB)
fulltest: testfixture$(EXE) sqlite$(EXE)
./testfixture$(EXE) $(TOP)/test/all.test
@@ -289,9 +353,6 @@ arch.png: $(TOP)/www/arch.png
opcode.html: $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
crosscompile.html: $(TOP)/www/crosscompile.tcl
tclsh $(TOP)/www/crosscompile.tcl >crosscompile.html
mingw.html: $(TOP)/www/mingw.tcl
tclsh $(TOP)/www/mingw.tcl >mingw.html
@@ -341,7 +402,6 @@ DOC = \
arch.png \
vdbe.html \
c_interface.html \
crosscompile.html \
mingw.html \
tclsqlite.html \
download.html \
+166 -127
View File
@@ -1,155 +1,194 @@
C Version\s2.7.2\s(CVS\s756)
D 2002-09-25T19:50:18
F Makefile.in d6c9a85c2a5e696843201d090dcf8bf2f8716f2a
C Version\s2.8.14\s(CVS\s1554)
D 2004-06-09T23:20:06
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
F VERSION 7cc70240794db6c8f3c6ef8867090c25d8b442bd
F aclocal.m4 11faa843caa38fd451bc6aeb43e248d1723a269d
F config.guess f38b1e93d1e0fa6f5a6913e9e7b12774b9232588
F config.sub f14b07d544ca26b5d698259045136b783e18fc7f
F configure 9303d975dbd577fbe61e615045ddc02015b59fb5 x
F configure.ac 38e2e5594cab99eb3a753b0614fcc36f4ddbbb48
F VERSION f97edce65ceac3b00185ca009ed810a470837a50
F aclocal.m4 7daea4c35e88de30d5a3f6f7a2ab99720e803bbd
F art/SQLite.eps 9b43cc99cfd2be687d386faea6862ea68d6a72b2
F art/SQLite.gif 1bbb94484963f1382e27e1c5e86dd0c1061eba2b
F config.guess 2103e94b15dc57112d7b9ee152c6fac5288895b4
F config.sub 9bf686ec001ae7bc53f5b3563c90c62d4c6d48be
F configure 6a156e79aaddba2e0e6816972d99989f48cc1699 x
F configure.ac 684143ce9ee7bafc4291d0e17f2dfdc70514d1d6
F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F libtool c56e618713c9510a103bda6b95f3ea3900dcacd6
F ltmain.sh e9ed72eb1d690f447c13945eaf69e28af531eda1
F main.mk d7a9dfc003ab1eeb4fdb46dfcee8af0ab0e38a99
F publish.sh a7a8d23e6525bd25d4f5ba9b0fc6edc107d94050
F spec.template 238f7db425a78dc1bb7682e56e3834c7270a3f5e
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
F main.mk 1b27efb94be53a96c4333584a00a59fcc87ddc37
F publish.sh 1cd5c982388560fa91eedf6a338e210f713b35c8
F spec.template a38492f1c1dd349fc24cb0565e08afc53045304b
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
F src/btree.c 8024b87635c2adf133f153f1bb595125ec1c7d7b
F src/btree.h 0ca6c2631338df62e4f7894252d9347ae234eda9
F src/build.c 37e19378206b043ac6a0b7d53cf0726549a0bbdb
F src/delete.c aad9d4051ab46e6f6391ea5f7b8994a7c05bdd15
F src/encode.c 6c9c87d5b7b2c0101d011ebc283a80abf672a4d1
F src/expr.c e1327eb020a68ff7c49382e121ad4b71b3441b2a
F src/func.c e45cd908b9b723d9b91473d09e12c23f786b3fc2
F src/hash.c 6a6236b89c8c060c65dabd300a1c8ce7c10edb72
F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8
F src/insert.c 764300a0bd8074a2174946c0bf8a550bd833397a
F src/main.c ff7c05ef88fa1374e5540ce20173ae8e1836f8a4
F sqlite.def fc4f5734786fe4743cfe2aa98eb2da4b089edb5f
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
F src/attach.c 026702566f941bf2bb158a0aaa86bfeb65910aa6
F src/auth.c 4fa3b05bd19445d1c474d6751c4a508d6ea0abe1
F src/btree.c 08a05b925b348c05d79b9b062b79e50d565678de
F src/btree.h 41cb3ff6ebc3f6da2d0a074e39ff8c7a2287469f
F src/btree_rb.c 99feb3ff835106d018a483a1ce403e5cf9c718bc
F src/build.c 76fbca30081decd6615dee34b48c927ed5063752
F src/copy.c 750e13828c3e4a293123e36aaa7cf0f22466248a
F src/date.c f055419d602bde622c70f831350b6b52f2235de0
F src/delete.c 82001c74882319f94dab5f6b92a27311b31092ae
F src/encode.c fc8c51f0b61bc803ccdec092e130bebe762b0a2f
F src/expr.c 8c3f5603c3e98b1c146d18076ba3e82cdbb59c11
F src/func.c 34fead7a33e82095f6412d3fafd379d47864b3be
F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e
F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7
F src/insert.c c0485ee2d1b99322894e2d1e0b576fd05ed75616
F src/main.c 94dd355768e2a389e184a069b6880f4bac100307
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
F src/os.c 091a89297bf80927cde146cd1dbf89c908864f3a
F src/os.h 3009379b06941e7796a9812d1b6cbc59b26248c8
F src/pager.c 592e5931fdc65e952a6c3e152bc822580856532a
F src/pager.h 6991c9c2dc5e4c7f2df4d4ba47d1c6458f763a32
F src/parse.y 818b03a73f6b3b8b284b515c5b1d9998d4663dc3
F src/printf.c 5c50fc1da75c8f5bf432b1ad17d91d6653acd167
F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
F src/select.c 74a025cd6887b636fc06a79ff6246c4eb6826ec4
F src/shell.c 9e9a6eb6bca07f01e6472a603f908a0127ea50ff
F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
F src/sqlite.h.in d3999a9c6374675779058d6cfe5431131618e92b
F src/sqliteInt.h 54caf09fbb64b43a060637c46fb7464ea7b6f759
F src/table.c eed2098c9b577aa17f8abe89313a9c4413f57d63
F src/tclsqlite.c fa646506f02509455c1e4a878d1303bd2d4c3ead
F src/test1.c a46e9f61915b32787c5d5a05a4b92e4dacc437d9
F src/test2.c 5fa694d130b3309e3f9c852f0a437750fcb5a006
F src/test3.c 540fa7fc3cb3732517b779b5f90ad9cc4303d0ab
F src/threadtest.c 72bce0a284647314847bbea44616ceb056bfb77f
F src/tokenize.c 62c98842447effe92eba9622bb2f9a2a8a4b97ad
F src/trigger.c 5ba917fc226b96065108da28186c2efaec53e481
F src/update.c 881e4c8e7c786545da4fd2d95da19252b2e31137
F src/util.c c70d5da5357e01b58392faebae3c3620c1d71f14
F src/vdbe.c ac4ccc17d965e5754144cfec493093cf4272c126
F src/vdbe.h b7584044223104ba7896a7f87b66daebdd6022ba
F src/where.c 53959c9d94adaf93b409271815e26eafa6ddd515
F test/all.test efd958d048c70a3247997c482f0b33561f7759f0
F src/os.c edcd42ad1cf13e7322f814c50a3e6eb09d3915bb
F src/os.h 250a3789be609adfee5c5aa20137ce8683276f24
F src/pager.c b246986e5ba31b15aa3cf91d3b9ec2e608aceb8e
F src/pager.h 82332878799280145639a48d88cdb4058925e3f6
F src/parse.y 023720cb8c3bef74e51738bca78335d0dc6d2cfd
F src/pragma.c f9c157b0591419d2d3407dac90222020d2a6d822
F src/printf.c 8c58b7b6d4069eec6ebe2d46bdbc3a89a367bf95
F src/random.c 775913e0b7fbd6295d21f12a7bd35b46387c44b2
F src/select.c 3833e2b64cc6d249385ee44e13bf49c9ae5b903d
F src/shell.c 920af040d3a33ea8919c82cee45b424ad841cee0
F src/sqlite.h.in 35bec264dfb4965bbfeb7e75221f8658f210c30d
F src/sqliteInt.h 235ce244b62bb26cc9ab394fb7a0724dd4e65c83
F src/table.c d845cb101b5afc1f7fea083c99e3d2fa7998d895
F src/tclsqlite.c 819d92d305756c4ea57de023c387d2fa8a256aff
F src/test1.c 4ae20bc125b1a7d7824cccca55d538d81f0b4949
F src/test2.c 75819b0f2c63c6a0fd6995445881f2eb94036996
F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
F src/test4.c 6e3e31acfaf21d66420fc35fda5b17dc0000cc8d
F src/tokenize.c 6676b946fd8825b67ab52140af4fdc57a70bda48
F src/trigger.c a9927b57c865b6f3df3fb5e40c9824d722660ded
F src/update.c bd391079138e67d09c9af34528ca4137c29242d1
F src/util.c 122bc174f6c8c2eb6a9127d9f13c4c74f83b85e4
F src/vacuum.c 36a19aa877c696c4ec8b78300c19f4059d2617a7
F src/vdbe.c 0853ab9983b7adbba8c012bb8b152d8453bf8a97
F src/vdbe.h ac987945e4dd6f987bca534c6005899f089fc270
F src/vdbeInt.h b40ff02ce39fd076e6ff3369e19c1bbfe1986682
F src/vdbeaux.c e2cdd1ab63604a390612c73e26bdd2ef910e9438
F src/where.c b58764861a96bab3f1d294200f9e53519b92c274
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
F test/attach.test ba8261d38da6b6a7d4f78ec543c548c4418582ef
F test/attach2.test ce61e6185b3cd891cc0e9a4c868fcc65eb92fc55
F test/auth.test 5c4d95cdaf539c0c236e20ce1f71a93e7dde9185
F test/bigfile.test ea904b853ce2d703b16c5ce90e2b54951bc1ae81
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
F test/btree.test 10e75aec120ecefc0edc4c912a0980a43db1b6c2
F test/bind.test 56a57043b42c4664ca705f6050e56717a8a6699a
F test/btree.test 677aeaac7b7b81980b446ca9cab15aa0cc5550d5
F test/btree2.test e3b81ec33dc2f89b3e6087436dfe605b870c9080
F test/btree3.test 9caa9e22491dd8cd8aa36d7ac3b48b089817c895
F test/conflict.test 0173a12a257f73bac2c9d53ad44cac9b15ea517e
F test/copy.test 55d60a4d5ed342a0fa08b7cd07d46d43ea0d0d7f
F test/delete.test 5821a95a66061ae09723a88938f23d10d8a881ad
F test/expr.test dea1cd62684a8bf116426447c948f5e8fb2c84b6
F test/fkey1.test 33c850201a6ec35f0b370daf4e57f44456f1b35d
F test/format3.test cbb168d446152fcf1dd85be299ad2d6cd507da4e
F test/func.test bed7ae7a3482df05db0f5eed2debdf25ac2d07fc
F test/in.test e59461f1702b7387880bf08a0ce6bb777925d282
F test/index.test 2a5a1b654f50ca0768fb10ae44b72e6a776b1f18
F test/insert.test a122afb86911e77c181d912348866a5b1a61eeab
F test/btree3.test e597fb59be2ac0ea69c62aaa2064e998e528b665
F test/btree3rb.test 127efcf5cdfcc352054e7db12622b01cdd8b36ac
F test/btree4.test fa955a3d7a8bc91d6084b7f494f9e5d1bdfb15b6
F test/btree4rb.test ae6f0438512edcb45cf483471cd6070a765963a9
F test/capi2.test ec96e0e235d87b53cbaef3d8e3e0f8ccf32c71ca
F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e
F test/copy.test f07ea8d60878da7a67416ab62f78e9706b9d3c45
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
F test/date.test aed5030482ebc02bd8d386c6c86a29f694ab068d
F test/delete.test 92256384f1801760180ded129f7427884cf28886
F test/expr.test ad985242e140f87eeef329d98257b8369a2066dc
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
F test/format3.test 149cc166c97923fa60def047e90dd3fb32bba916
F test/func.test 000515779001ac6899eec4b54e65c6e2501279d4
F test/hook.test 1a67ce0cd64a6455d016962542f2822458dccc49
F test/in.test 0de39b02ceeca90993b096822fb5a884661c5b47
F test/index.test 9295deefbdb6dedbe01be8905f0c448fe5bd4079
F test/insert.test a17b7f7017097afb2727aa5b67ceeb7ab0a120a1
F test/insert2.test c288375a64dad3295044714f0dfed4a193cf067f
F test/intpkey.test f3620158fd7963af1306b01047277f10ae91a30b
F test/ioerr.test 57d9bffaca18b34f9e976f786eadc2591d6efc6a
F test/join.test 90a620f2a2d015e5139d5a4cde0eeb4cf62523bf
F test/limit.test 9f26f874bc765df5b3f5c92d26d1b12eac6d4cf9
F test/lock.test 388a3a10962d2d571c0c1821cc35bf069ee73473
F test/main.test c66b564554b770ee7fdbf6a66c0cd90329bc2c85
F test/malloc.test 7ba32a9ebd3aeed52ae4aaa6d42ca37e444536fd
F test/memleak.test b4f59aa44488793b00feff2011d77d0f05b22468
F test/minmax.test 29bc5727c3e4c792d5c4745833dd4b505905819e
F test/misc1.test 9b0fdc82756bd88da91e5d62f4c93ef6a457c1bc
F test/misuse.test a3aa2b18a97e4c409a1fcaff5151a4dd804a0162
F test/notnull.test b1f3e42fc475b0b5827b27b2e9b562081995ff30
F test/null.test 5c2b57307e4b6178aae825eb65ddbee01e76b0fd
F test/pager.test b0c0d00cd5dce0ce21f16926956b195c0ab5044c
F test/pragma.test 0b9675ef1f5ba5b43abfa337744445fc5b01a34a
F test/printf.test a29b8afa24edb4411adfe473b12ac32c84098fce
F test/quick.test b372c8dad4fa1554747e90683fc72e59c0c98502
F test/interrupt.test 0d50985f1aa6c39fe2cca4cf4a272c79ff1648e8
F test/intpkey.test 9320af48415c594afd4e15f8ef0daa272e05502e
F test/ioerr.test 5dbaf09f96b56ee01cf3edd762b96eb4ad2c9ca4
F test/join.test 9ef6aabaac9de51d5fc41e68d1f4355da05a84cd
F test/join2.test c97e4c5aa65dea462145529e58212a709b4722b8
F test/lastinsert.test 31382f88b9b0270333ac9e4a17f2c2f4732da718
F test/laststmtchanges.test cabd11bdfbaf73a4486c50b58297d9c2038ccc18
F test/limit.test e28ce938ddacefdff860d082be45e1e5e2801441
F test/lock.test 226ef831dad60ad4d200dc83e25479ba952aac7e
F test/main.test 6a851b5992c4881a725a3d9647e629199df8de9d
F test/malloc.test 2cfcffb7c858640e01e6520ee1cd54ca57d98e80
F test/memdb.test 6ece25c7c0e6500199d3662607a3edca081abb2a
F test/memleak.test 4d5d374c8ea1fc5ac634aed58cac1047848ce65e
F test/minmax.test 9dcf52f713b1b9e61d0a88a51eb8bb2e3c52d0ab
F test/misc1.test 0b98d493b0cf55cb5f53e1f3df8107c166eecb5a
F test/misc2.test 10c2ce26407d37411b96273e552d5095393732be
F test/misc3.test 3b5e369514a3ba3f919fb7eafa7d027440b5079e
F test/misuse.test 1095f26d1aed406c65e1d2eba651c4bb7c38cbff
F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
F test/null.test c14d0f4739f21e929b8115b72bf0c765b6bb1721
F test/pager.test 331519008889d45f6df6697395e5bce6ee602fd9
F test/pragma.test 24a3f7a697b45cb90d664ebce5566bec7ac41571
F test/printf.test 46b3d07d59d871d0831b4a657f6dfcafe0574850
F test/progress.test 701b6115c2613128ececdfe1398a1bd0e1a4cfb3 x
F test/quick.test 5a6bccf5c02f16841a79fbac7409a02138880c10
F test/quote.test 08f23385c685d3dc7914ec760d492cacea7f6e3d
F test/rowid.test 4c55943300cddf73dd0f88d40a268cab14c83274
F test/rowid.test 77f7e8c7ca626a15ff91a536595b695cfce7c845
F test/select1.test 0d708cec567104653ec9aa49fecf3444a2e7d150
F test/select2.test aceea74fd895b9d007512f72499db589735bd8e4
F test/select3.test 3e98cec10e755226cbabdd7073ec37baab9ab148
F test/select4.test 10ba54f24ef6ca7958a7045b001079378db2370c
F test/select3.test 445a1a3dde4e2fd32541b311f55da5e2f8079d76
F test/select4.test e7e9a32fa745246cb99fadbeb63af4843a17925b
F test/select5.test c2a6c4a003316ee42cbbd689eebef8fdce0db2ac
F test/select6.test efb8d0c07a440441db87db2c4ade6904e1407e85
F test/sort.test 876b76c5a837af5bead713146c7c65f85e84fbf5
F test/select6.test a9e31906e700e7c7592c4d0acfc022808f718baf
F test/sort.test ba07b107c16070208e6aab3cadea66ba079d85ba
F test/subselect.test f0fea8cf9f386d416d64d152e3c65f9116d0f50f
F test/table.test 10508e5e53fb7971b9fa6acb29d85748e545745c
F test/tableapi.test 3c80421a889e1d106df16e5800fa787f0d2914a6
F test/tclsqlite.test 2441ab135e5af85110326b3e3b057e7257c144e1
F test/temptable.test 03b7bdb7d6ce2c658ad20c94b037652c6cad34e0
F test/tester.tcl 6f603d90881bd835ea27c568a7fecaa57dce91cc
F test/trans.test 10b53c77e2cc4ad9529c15fdcb390b8d5722ea65
F test/trigger1.test ec1da76e1a9f618deb96e505f459dcf8a23f2247
F test/trigger2.test ee346d8c612e7f847c9543058f1b89d094d27ffb
F test/trigger3.test 2bf76f7367a36242f670026af542d9f60efe3dc6
F test/trigger4.test 9a5c1406344d743020c2753ae8d6dfe6eb75f818
F test/unique.test 572aa791327c1e8d797932263e9d67f176cfdb44
F test/update.test 7ffb062d580a972e7870d0f51d5af3ab9bfeae08
F test/vacuum.test 059871b312eb910bbe49dafde1d01490cc2c6bbe
F test/version.test 605fd0d7e7d571370c32b12dbf395b58953de246
F test/view.test 76d3fe155f1215f9dde1ccad1d1bce5c803132d0
F test/where.test c7aba40ad9178acf9c898e53aac9e447e2d2f2f7
F test/table.test 371a1fc1c470982b2f68f9732f903a5d96f949c4
F test/tableapi.test e0c4cce61e58343caa84dab33fa6823cb35fe1e1
F test/tclsqlite.test a684fc191b81e6cded8a81263663d5a130fbb013
F test/temptable.test a770ba6308d7f7332fce985086b8e06bed6430c2
F test/tester.tcl 2f1d43df1311c9dc06acaa7a82e87bfea85dea5f
F test/thread1.test 53f050d5be6932d9430df7756edd379366508ff6
F test/threadtest1.c f7f896e62ed46feae1dc411114a48c15a0f82ee2
F test/threadtest2.c d94ca4114fd1504f7e0ae724bcd83d4b40931d86
F test/trans.test 0cb8256daff1ae0da75321e00125338c6681158d
F test/trigger1.test 4538c1c7d6bbca5dfe619ea6e1682b07ece95b21
F test/trigger2.test 0767ab30cb5a2c8402c8524f3d566b410b6f5263
F test/trigger3.test a95ccace88291449f5eae7139ec438a42f90654d
F test/trigger4.test 542afce45774e8f8e1130b96b8675f414d6e4bd8
F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b
F test/update.test b29bd9061a1150426dab6959806fcc73a41b1217
F test/vacuum.test a2a44544df719666efb51afbfeb6062fd59a672a
F test/version.test 92adee5d98cf6e3eb0d1cf5186952e8114931bf6
F test/view.test 1ee12c6f8f4791a2c0655120d5562a49400cfe53
F test/where.test cb3a2ed062ce4b5f08aff2d08027c6a46d68c47b
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
F tool/lemon.c 022adc2830c2705828f744d2c59798bd462eb465
F tool/lempar.c 73a991cc3017fb34804250fa901488b5147b3717
F tool/memleak.awk 16ef9493dcd36146f806e75148f4bb0201a123ec
F tool/lemon.c db6a3bfaf3388c0f7aea3adb5e05acddcd427016
F tool/lempar.c 0b5e7a58634e0d448929b8e85f7981c2aa708d57
F tool/memleak.awk b744b6109566206c746d826f6ecdba34662216bc
F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
F tool/showjournal.c 9a37d7b05de0591e3102aaf774d01fbc0d053a8b
F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4
F www/arch.tcl 679a0c48817f71bc91d5911ef386e5ef35d4f178
F www/arch.tcl b329ca2c8dc75cd1cf0dd714b8bb47bdd458d0da
F www/arch2.fig 613b5ac63511109064c2f93c5754ee662219937d
F www/arch2.gif 49c6bb36160f03ca2b89eaa5bfb1f560c7d68ee7
F www/audit.tcl 90e09d580f79c7efec0c7d6f447b7ec5c2dce5c0
F www/c_interface.tcl e76c9fd609326c34cd45cd040b508b0e21908800
F www/changes.tcl 5074fcf9ad6186f1ca48cda96081a465e8d41f52
F www/c_interface.tcl 17d8bd9e7b4fbdca47c30c8b9bcb728c351d55c0
F www/changes.tcl a3d043896631a14091dbafdb4068980974c3834c
F www/conflict.tcl 81dd21f9a679e60aae049e9dd8ab53d59570cda2
F www/crosscompile.tcl 3622ebbe518927a3854a12de51344673eb2dd060
F www/datatypes.tcl 0cb28565580554fa7e03e8fcb303e87ce57757ae
F www/datatypes.tcl 0fe2b810f114a909b844e50ad37a25e6ed8c7271
F www/download.tcl 0932d7f4f0e8b2adbbd22fac73132f86e43ab4a9
F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
F www/faq.tcl 207d3e31597c63ed3bbecd58aaeaa38c53d39dd4
F www/fileformat.tcl a4b5c2c6e89b7d42d09f97fd4d7bbd39cbf24936
F www/formatchng.tcl b4449e065d2da38b6563bdf12cf46cfe1d4d765e
F www/index.tcl 190f767c4b0bf44f75bf4af023d644c3e7a1e579
F www/lang.tcl 6be4254a751ab183ec974fe65375f50230c777f3
F www/mingw.tcl f1c7c0a7f53387dd9bb4f8c7e8571b7561510ebc
F www/nulls.tcl 29497dac2bc5b437aa7e2e94577dad4d8933ed26
F www/omitted.tcl 118062f40a203fcb88b8d68ef1d7c0073ac191ec
F www/opcode.tcl 33c5f2061a05c5d227c72b84c080b3bf74c74f8b
F www/quickstart.tcl fde79aa2de20074842b60f780800cdeee6a5dec2
F www/speed.tcl a20a792738475b68756ea7a19321600f23d1d803
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
P a164528e8c6df3569ab178a3b737744dcccb64e7
R 6b3b49333db1fe81ae49602c8806a88b
F www/faq.tcl 88d3b95d9cd8e374772daa3a646c4d107e7f3e9b
F www/fileformat.tcl 56f77e435a6306b337b20b416e3b89500ba2d029
F www/formatchng.tcl ca6cc1cb1bef9bc36f0619049d3c95e749bc6983
F www/index.tcl bacb2a0d052845bbe3bf078765cce907ed7080a4
F www/lang.tcl 17954f37c8bb1d25e026d97041ff6459fb89ac95
F www/mingw.tcl d96b451568c5d28545fefe0c80bee3431c73f69c
F www/nulls.tcl 38117d24afb81efd079b59723b985a6d654cc2e8
F www/omitted.tcl 11037a1b557bd01405092d93dfa08898a4c26cd7
F www/opcode.tcl b8d561f33597c62955796b797646f00144d97332
F www/quickstart.tcl 4e97bef825e6a4153c43afb9f97235fc4da278ab
F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3
F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P 7538d2e5297bdeaf07c6d6e37053c654501ef286
R 4b97b7f3ad71d7fa0ea85a53f9d1556a
U drh
Z d8e6d7ec440fa5d20f0b92f7d17ba232
Z 6e7d236761f1e0f27c9fd9bb6ff1ebec
+1 -1
View File
@@ -1 +1 @@
59ba43449a53fb32e2dd4259285af8b4206c298a
7d3937743f88acad8859fbbbb1c03271a939bc0b
+12
View File
@@ -14,6 +14,7 @@ srcdir=`echo "$0" | sed 's%\(^.*\)/[^/][^/]*$%\1%'`
# Get the makefile.
#
cp $srcdir/Makefile.linux-gcc ./Makefile
chmod +x $srcdir/install-sh
# Start building stuff.
#
@@ -102,6 +103,7 @@ sqlite_libencoding
sqlite_changes
sqlite_create_function
sqlite_create_aggregate
sqlite_function_type
sqlite_user_data
sqlite_aggregate_context
sqlite_aggregate_count
@@ -112,6 +114,16 @@ sqlite_set_result_error
sqliteMalloc
sqliteFree
sqliteRealloc
sqlite_set_authorizer
sqlite_trace
sqlite_compile
sqlite_step
sqlite_finalize
sqlite_reset
sqlite_bind
sqlite_last_statement_changes
sqlite_encode_binary
sqlite_decode_binary
END_OF_FILE
i386-mingw32msvc-dllwrap \
--def sqlite.def -v --export-all \
+1
View File
@@ -55,6 +55,7 @@ rm -fr $RPM_BUILD_ROOT
%files -n %{name}-devel
%defattr(-, root, root)
%{_libdir}/pkgconfig/sqlite.pc
%{_libdir}/*.a
%{_libdir}/*.la
%{_includedir}/*
+45
View File
@@ -0,0 +1,45 @@
EXPORTS
sqlite_open
sqlite_close
sqlite_exec
sqlite_last_insert_rowid
sqlite_error_string
sqlite_interrupt
sqlite_complete
sqlite_busy_handler
sqlite_busy_timeout
sqlite_get_table
sqlite_free_table
sqlite_mprintf
sqlite_vmprintf
sqlite_exec_printf
sqlite_exec_vprintf
sqlite_get_table_printf
sqlite_get_table_vprintf
sqlite_freemem
sqlite_libversion
sqlite_libencoding
sqlite_changes
sqlite_create_function
sqlite_create_aggregate
sqlite_function_type
sqlite_user_data
sqlite_aggregate_context
sqlite_aggregate_count
sqlite_set_result_string
sqlite_set_result_int
sqlite_set_result_double
sqlite_set_result_error
sqliteMalloc
sqliteFree
sqliteRealloc
sqlite_set_authorizer
sqlite_trace
sqlite_compile
sqlite_step
sqlite_finalize
sqlite_reset
sqlite_bind
sqlite_last_statement_changes
sqlite_encode_binary
sqlite_decode_binary
+12
View File
@@ -0,0 +1,12 @@
# Package Information for pkg-config
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: SQLite
Description: SQL database engine
Version: @VERSION@
Libs: -L${libdir} -lsqlite
Cflags: -I${includedir}
+311
View File
@@ -0,0 +1,311 @@
/*
** 2003 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.10.2.1 2004/05/07 01:46:01 drh Exp $
*/
#include "sqliteInt.h"
/*
** This routine is called by the parser to process an ATTACH statement:
**
** ATTACH DATABASE filename AS dbname
**
** The pFilename and pDbname arguments are the tokens that define the
** filename and dbname in the ATTACH statement.
*/
void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey){
Db *aNew;
int rc, i;
char *zFile, *zName;
sqlite *db;
Vdbe *v;
v = sqliteGetVdbe(pParse);
sqliteVdbeAddOp(v, OP_Halt, 0, 0);
if( pParse->explain ) return;
db = pParse->db;
if( db->file_format<4 ){
sqliteErrorMsg(pParse, "cannot attach auxiliary databases to an "
"older format master database", 0);
pParse->rc = SQLITE_ERROR;
return;
}
if( db->nDb>=MAX_ATTACHED+2 ){
sqliteErrorMsg(pParse, "too many attached databases - max %d",
MAX_ATTACHED);
pParse->rc = SQLITE_ERROR;
return;
}
zFile = 0;
sqliteSetNString(&zFile, pFilename->z, pFilename->n, 0);
if( zFile==0 ) return;
sqliteDequote(zFile);
#ifndef SQLITE_OMIT_AUTHORIZATION
if( sqliteAuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
sqliteFree(zFile);
return;
}
#endif /* SQLITE_OMIT_AUTHORIZATION */
zName = 0;
sqliteSetNString(&zName, pDbname->z, pDbname->n, 0);
if( zName==0 ) return;
sqliteDequote(zName);
for(i=0; i<db->nDb; i++){
if( db->aDb[i].zName && sqliteStrICmp(db->aDb[i].zName, zName)==0 ){
sqliteErrorMsg(pParse, "database %z is already in use", zName);
pParse->rc = SQLITE_ERROR;
sqliteFree(zFile);
return;
}
}
if( db->aDb==db->aDbStatic ){
aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );
if( aNew==0 ) return;
memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
}else{
aNew = sqliteRealloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
if( aNew==0 ) return;
}
db->aDb = aNew;
aNew = &db->aDb[db->nDb++];
memset(aNew, 0, sizeof(*aNew));
sqliteHashInit(&aNew->tblHash, SQLITE_HASH_STRING, 0);
sqliteHashInit(&aNew->idxHash, SQLITE_HASH_STRING, 0);
sqliteHashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);
sqliteHashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);
aNew->zName = zName;
rc = sqliteBtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
if( rc ){
sqliteErrorMsg(pParse, "unable to open database: %s", zFile);
}
#if SQLITE_HAS_CODEC
{
extern int sqliteCodecAttach(sqlite*, int, void*, int);
char *zKey = 0;
int nKey;
if( pKey && pKey->z && pKey->n ){
sqliteSetNString(&zKey, pKey->z, pKey->n, 0);
sqliteDequote(zKey);
nKey = strlen(zKey);
}else{
zKey = 0;
nKey = 0;
}
sqliteCodecAttach(db, db->nDb-1, zKey, nKey);
}
#endif
sqliteFree(zFile);
db->flags &= ~SQLITE_Initialized;
if( pParse->nErr ) return;
if( rc==SQLITE_OK ){
rc = sqliteInit(pParse->db, &pParse->zErrMsg);
}
if( rc ){
int i = db->nDb - 1;
assert( i>=2 );
if( db->aDb[i].pBt ){
sqliteBtreeClose(db->aDb[i].pBt);
db->aDb[i].pBt = 0;
}
sqliteResetInternalSchema(db, 0);
pParse->nErr++;
pParse->rc = SQLITE_ERROR;
}
}
/*
** This routine is called by the parser to process a DETACH statement:
**
** DETACH DATABASE dbname
**
** The pDbname argument is the name of the database in the DETACH statement.
*/
void sqliteDetach(Parse *pParse, Token *pDbname){
int i;
sqlite *db;
Vdbe *v;
Db *pDb;
v = sqliteGetVdbe(pParse);
sqliteVdbeAddOp(v, OP_Halt, 0, 0);
if( pParse->explain ) return;
db = pParse->db;
for(i=0; i<db->nDb; i++){
pDb = &db->aDb[i];
if( pDb->pBt==0 || pDb->zName==0 ) continue;
if( strlen(pDb->zName)!=pDbname->n ) continue;
if( sqliteStrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break;
}
if( i>=db->nDb ){
sqliteErrorMsg(pParse, "no such database: %T", pDbname);
return;
}
if( i<2 ){
sqliteErrorMsg(pParse, "cannot detach database %T", pDbname);
return;
}
#ifndef SQLITE_OMIT_AUTHORIZATION
if( sqliteAuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){
return;
}
#endif /* SQLITE_OMIT_AUTHORIZATION */
sqliteBtreeClose(pDb->pBt);
pDb->pBt = 0;
sqliteFree(pDb->zName);
sqliteResetInternalSchema(db, i);
if( pDb->pAux && pDb->xFreeAux ) pDb->xFreeAux(pDb->pAux);
db->nDb--;
if( i<db->nDb ){
db->aDb[i] = db->aDb[db->nDb];
memset(&db->aDb[db->nDb], 0, sizeof(db->aDb[0]));
sqliteResetInternalSchema(db, i);
}
}
/*
** Initialize a DbFixer structure. This routine must be called prior
** to passing the structure to one of the sqliteFixAAAA() routines below.
**
** The return value indicates whether or not fixation is required. TRUE
** means we do need to fix the database references, FALSE means we do not.
*/
int sqliteFixInit(
DbFixer *pFix, /* The fixer to be initialized */
Parse *pParse, /* Error messages will be written here */
int iDb, /* This is the database that must must be used */
const char *zType, /* "view", "trigger", or "index" */
const Token *pName /* Name of the view, trigger, or index */
){
sqlite *db;
if( iDb<0 || iDb==1 ) return 0;
db = pParse->db;
assert( db->nDb>iDb );
pFix->pParse = pParse;
pFix->zDb = db->aDb[iDb].zName;
pFix->zType = zType;
pFix->pName = pName;
return 1;
}
/*
** The following set of routines walk through the parse tree and assign
** a specific database to all table references where the database name
** was left unspecified in the original SQL statement. The pFix structure
** must have been initialized by a prior call to sqliteFixInit().
**
** These routines are used to make sure that an index, trigger, or
** view in one database does not refer to objects in a different database.
** (Exception: indices, triggers, and views in the TEMP database are
** allowed to refer to anything.) If a reference is explicitly made
** to an object in a different database, an error message is added to
** pParse->zErrMsg and these routines return non-zero. If everything
** checks out, these routines return 0.
*/
int sqliteFixSrcList(
DbFixer *pFix, /* Context of the fixation */
SrcList *pList /* The Source list to check and modify */
){
int i;
const char *zDb;
if( pList==0 ) return 0;
zDb = pFix->zDb;
for(i=0; i<pList->nSrc; i++){
if( pList->a[i].zDatabase==0 ){
pList->a[i].zDatabase = sqliteStrDup(zDb);
}else if( sqliteStrICmp(pList->a[i].zDatabase,zDb)!=0 ){
sqliteErrorMsg(pFix->pParse,
"%s %z cannot reference objects in database %s",
pFix->zType, sqliteStrNDup(pFix->pName->z, pFix->pName->n),
pList->a[i].zDatabase);
return 1;
}
if( sqliteFixSelect(pFix, pList->a[i].pSelect) ) return 1;
if( sqliteFixExpr(pFix, pList->a[i].pOn) ) return 1;
}
return 0;
}
int sqliteFixSelect(
DbFixer *pFix, /* Context of the fixation */
Select *pSelect /* The SELECT statement to be fixed to one database */
){
while( pSelect ){
if( sqliteFixExprList(pFix, pSelect->pEList) ){
return 1;
}
if( sqliteFixSrcList(pFix, pSelect->pSrc) ){
return 1;
}
if( sqliteFixExpr(pFix, pSelect->pWhere) ){
return 1;
}
if( sqliteFixExpr(pFix, pSelect->pHaving) ){
return 1;
}
pSelect = pSelect->pPrior;
}
return 0;
}
int sqliteFixExpr(
DbFixer *pFix, /* Context of the fixation */
Expr *pExpr /* The expression to be fixed to one database */
){
while( pExpr ){
if( sqliteFixSelect(pFix, pExpr->pSelect) ){
return 1;
}
if( sqliteFixExprList(pFix, pExpr->pList) ){
return 1;
}
if( sqliteFixExpr(pFix, pExpr->pRight) ){
return 1;
}
pExpr = pExpr->pLeft;
}
return 0;
}
int sqliteFixExprList(
DbFixer *pFix, /* Context of the fixation */
ExprList *pList /* The expression to be fixed to one database */
){
int i;
if( pList==0 ) return 0;
for(i=0; i<pList->nExpr; i++){
if( sqliteFixExpr(pFix, pList->a[i].pExpr) ){
return 1;
}
}
return 0;
}
int sqliteFixTriggerStep(
DbFixer *pFix, /* Context of the fixation */
TriggerStep *pStep /* The trigger step be fixed to one database */
){
while( pStep ){
if( sqliteFixSelect(pFix, pStep->pSelect) ){
return 1;
}
if( sqliteFixExpr(pFix, pStep->pWhere) ){
return 1;
}
if( sqliteFixExprList(pFix, pStep->pExprList) ){
return 1;
}
pStep = pStep->pNext;
}
return 0;
}
+219
View File
@@ -0,0 +1,219 @@
/*
** 2003 January 11
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the sqlite_set_authorizer()
** API. This facility is an optional feature of the library. Embedded
** systems that do not need this facility may omit it by recompiling
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
**
** $Id: auth.c,v 1.12 2004/02/22 18:40:57 drh Exp $
*/
#include "sqliteInt.h"
/*
** All of the code in this file may be omitted by defining a single
** macro.
*/
#ifndef SQLITE_OMIT_AUTHORIZATION
/*
** Set or clear the access authorization function.
**
** The access authorization function is be called during the compilation
** phase to verify that the user has read and/or write access permission on
** various fields of the database. The first argument to the auth function
** is a copy of the 3rd argument to this routine. The second argument
** to the auth function is one of these constants:
**
** SQLITE_COPY
** SQLITE_CREATE_INDEX
** SQLITE_CREATE_TABLE
** SQLITE_CREATE_TEMP_INDEX
** SQLITE_CREATE_TEMP_TABLE
** SQLITE_CREATE_TEMP_TRIGGER
** SQLITE_CREATE_TEMP_VIEW
** SQLITE_CREATE_TRIGGER
** SQLITE_CREATE_VIEW
** SQLITE_DELETE
** SQLITE_DROP_INDEX
** SQLITE_DROP_TABLE
** SQLITE_DROP_TEMP_INDEX
** SQLITE_DROP_TEMP_TABLE
** SQLITE_DROP_TEMP_TRIGGER
** SQLITE_DROP_TEMP_VIEW
** SQLITE_DROP_TRIGGER
** SQLITE_DROP_VIEW
** SQLITE_INSERT
** SQLITE_PRAGMA
** SQLITE_READ
** SQLITE_SELECT
** SQLITE_TRANSACTION
** SQLITE_UPDATE
**
** The third and fourth arguments to the auth function are the name of
** the table and the column that are being accessed. The auth function
** should return either SQLITE_OK, SQLITE_DENY, or SQLITE_IGNORE. If
** SQLITE_OK is returned, it means that access is allowed. SQLITE_DENY
** means that the SQL statement will never-run - the sqlite_exec() call
** will return with an error. SQLITE_IGNORE means that the SQL statement
** should run but attempts to read the specified column will return NULL
** and attempts to write the column will be ignored.
**
** Setting the auth function to NULL disables this hook. The default
** setting of the auth function is NULL.
*/
int sqlite_set_authorizer(
sqlite *db,
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
void *pArg
){
db->xAuth = xAuth;
db->pAuthArg = pArg;
return SQLITE_OK;
}
/*
** Write an error message into pParse->zErrMsg that explains that the
** user-supplied authorization function returned an illegal value.
*/
static void sqliteAuthBadReturnCode(Parse *pParse, int rc){
sqliteErrorMsg(pParse, "illegal return value (%d) from the "
"authorization function - should be SQLITE_OK, SQLITE_IGNORE, "
"or SQLITE_DENY", rc);
pParse->rc = SQLITE_MISUSE;
}
/*
** The pExpr should be a TK_COLUMN expression. The table referred to
** is in pTabList or else it is the NEW or OLD table of a trigger.
** Check to see if it is OK to read this particular column.
**
** If the auth function returns SQLITE_IGNORE, change the TK_COLUMN
** instruction into a TK_NULL. If the auth function returns SQLITE_DENY,
** then generate an error.
*/
void sqliteAuthRead(
Parse *pParse, /* The parser context */
Expr *pExpr, /* The expression to check authorization on */
SrcList *pTabList /* All table that pExpr might refer to */
){
sqlite *db = pParse->db;
int rc;
Table *pTab; /* The table being read */
const char *zCol; /* Name of the column of the table */
int iSrc; /* Index in pTabList->a[] of table being read */
const char *zDBase; /* Name of database being accessed */
if( db->xAuth==0 ) return;
assert( pExpr->op==TK_COLUMN );
for(iSrc=0; iSrc<pTabList->nSrc; iSrc++){
if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break;
}
if( iSrc>=0 && iSrc<pTabList->nSrc ){
pTab = pTabList->a[iSrc].pTab;
}else{
/* This must be an attempt to read the NEW or OLD pseudo-tables
** of a trigger.
*/
TriggerStack *pStack; /* The stack of current triggers */
pStack = pParse->trigStack;
assert( pStack!=0 );
assert( pExpr->iTable==pStack->newIdx || pExpr->iTable==pStack->oldIdx );
pTab = pStack->pTab;
}
if( pTab==0 ) return;
if( pExpr->iColumn>=0 ){
assert( pExpr->iColumn<pTab->nCol );
zCol = pTab->aCol[pExpr->iColumn].zName;
}else if( pTab->iPKey>=0 ){
assert( pTab->iPKey<pTab->nCol );
zCol = pTab->aCol[pTab->iPKey].zName;
}else{
zCol = "ROWID";
}
assert( pExpr->iDb<db->nDb );
zDBase = db->aDb[pExpr->iDb].zName;
rc = db->xAuth(db->pAuthArg, SQLITE_READ, pTab->zName, zCol, zDBase,
pParse->zAuthContext);
if( rc==SQLITE_IGNORE ){
pExpr->op = TK_NULL;
}else if( rc==SQLITE_DENY ){
if( db->nDb>2 || pExpr->iDb!=0 ){
sqliteErrorMsg(pParse, "access to %s.%s.%s is prohibited",
zDBase, pTab->zName, zCol);
}else{
sqliteErrorMsg(pParse, "access to %s.%s is prohibited", pTab->zName,zCol);
}
pParse->rc = SQLITE_AUTH;
}else if( rc!=SQLITE_OK ){
sqliteAuthBadReturnCode(pParse, rc);
}
}
/*
** Do an authorization check using the code and arguments given. Return
** either SQLITE_OK (zero) or SQLITE_IGNORE or SQLITE_DENY. If SQLITE_DENY
** is returned, then the error count and error message in pParse are
** modified appropriately.
*/
int sqliteAuthCheck(
Parse *pParse,
int code,
const char *zArg1,
const char *zArg2,
const char *zArg3
){
sqlite *db = pParse->db;
int rc;
if( db->xAuth==0 ){
return SQLITE_OK;
}
rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
if( rc==SQLITE_DENY ){
sqliteErrorMsg(pParse, "not authorized");
pParse->rc = SQLITE_AUTH;
}else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
rc = SQLITE_DENY;
sqliteAuthBadReturnCode(pParse, rc);
}
return rc;
}
/*
** Push an authorization context. After this routine is called, the
** zArg3 argument to authorization callbacks will be zContext until
** popped. Or if pParse==0, this routine is a no-op.
*/
void sqliteAuthContextPush(
Parse *pParse,
AuthContext *pContext,
const char *zContext
){
pContext->pParse = pParse;
if( pParse ){
pContext->zAuthContext = pParse->zAuthContext;
pParse->zAuthContext = zContext;
}
}
/*
** Pop an authorization context that was previously pushed
** by sqliteAuthContextPush
*/
void sqliteAuthContextPop(AuthContext *pContext){
if( pContext->pParse ){
pContext->pParse->zAuthContext = pContext->zAuthContext;
pContext->pParse = 0;
}
}
#endif /* SQLITE_OMIT_AUTHORIZATION */
+611 -242
View File
File diff suppressed because it is too large Load Diff
+126 -39
View File
@@ -13,57 +13,144 @@
** subsystem. See comments in the source code for a detailed description
** of what each interface routine does.
**
** @(#) $Id: btree.h,v 1.25 2002/08/11 20:10:48 drh Exp $
** @(#) $Id: btree.h,v 1.36 2004/02/10 02:57:59 drh Exp $
*/
#ifndef _BTREE_H_
#define _BTREE_H_
/*
** Forward declarations of structure
*/
typedef struct Btree Btree;
typedef struct BtCursor BtCursor;
typedef struct BtOps BtOps;
typedef struct BtCursorOps BtCursorOps;
/*
** An instance of the following structure contains pointers to all
** methods against an open BTree. Alternative BTree implementations
** (examples: file based versus in-memory) can be created by substituting
** different methods. Users of the BTree cannot tell the difference.
**
** In C++ we could do this by defining a virtual base class and then
** creating subclasses for each different implementation. But this is
** C not C++ so we have to be a little more explicit.
*/
struct BtOps {
int (*Close)(Btree*);
int (*SetCacheSize)(Btree*, int);
int (*SetSafetyLevel)(Btree*, int);
int (*BeginTrans)(Btree*);
int (*Commit)(Btree*);
int (*Rollback)(Btree*);
int (*BeginCkpt)(Btree*);
int (*CommitCkpt)(Btree*);
int (*RollbackCkpt)(Btree*);
int (*CreateTable)(Btree*, int*);
int (*CreateIndex)(Btree*, int*);
int (*DropTable)(Btree*, int);
int (*ClearTable)(Btree*, int);
int (*Cursor)(Btree*, int iTable, int wrFlag, BtCursor **ppCur);
int (*GetMeta)(Btree*, int*);
int (*UpdateMeta)(Btree*, int*);
char *(*IntegrityCheck)(Btree*, int*, int);
const char *(*GetFilename)(Btree*);
int (*Copyfile)(Btree*,Btree*);
struct Pager *(*Pager)(Btree*);
#ifdef SQLITE_TEST
int (*PageDump)(Btree*, int, int);
#endif
};
/*
** An instance of this structure defines all of the methods that can
** be executed against a cursor.
*/
struct BtCursorOps {
int (*Moveto)(BtCursor*, const void *pKey, int nKey, int *pRes);
int (*Delete)(BtCursor*);
int (*Insert)(BtCursor*, const void *pKey, int nKey,
const void *pData, int nData);
int (*First)(BtCursor*, int *pRes);
int (*Last)(BtCursor*, int *pRes);
int (*Next)(BtCursor*, int *pRes);
int (*Previous)(BtCursor*, int *pRes);
int (*KeySize)(BtCursor*, int *pSize);
int (*Key)(BtCursor*, int offset, int amt, char *zBuf);
int (*KeyCompare)(BtCursor*, const void *pKey, int nKey,
int nIgnore, int *pRes);
int (*DataSize)(BtCursor*, int *pSize);
int (*Data)(BtCursor*, int offset, int amt, char *zBuf);
int (*CloseCursor)(BtCursor*);
#ifdef SQLITE_TEST
int (*CursorDump)(BtCursor*, int*);
#endif
};
/*
** The number of 4-byte "meta" values contained on the first page of each
** database file.
*/
#define SQLITE_N_BTREE_META 10
int sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
int sqliteBtreeClose(Btree*);
int sqliteBtreeSetCacheSize(Btree*, int);
int sqliteRbtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
int sqliteBtreeBeginTrans(Btree*);
int sqliteBtreeCommit(Btree*);
int sqliteBtreeRollback(Btree*);
int sqliteBtreeBeginCkpt(Btree*);
int sqliteBtreeCommitCkpt(Btree*);
int sqliteBtreeRollbackCkpt(Btree*);
#define btOps(pBt) (*((BtOps **)(pBt)))
#define btCOps(pCur) (*((BtCursorOps **)(pCur)))
int sqliteBtreeCreateTable(Btree*, int*);
int sqliteBtreeCreateIndex(Btree*, int*);
int sqliteBtreeDropTable(Btree*, int);
int sqliteBtreeClearTable(Btree*, int);
int sqliteBtreeCursor(Btree*, int iTable, int wrFlag, BtCursor **ppCur);
int sqliteBtreeMoveto(BtCursor*, const void *pKey, int nKey, int *pRes);
int sqliteBtreeDelete(BtCursor*);
int sqliteBtreeInsert(BtCursor*, const void *pKey, int nKey,
const void *pData, int nData);
int sqliteBtreeFirst(BtCursor*, int *pRes);
int sqliteBtreeLast(BtCursor*, int *pRes);
int sqliteBtreeNext(BtCursor*, int *pRes);
int sqliteBtreeKeySize(BtCursor*, int *pSize);
int sqliteBtreeKey(BtCursor*, int offset, int amt, char *zBuf);
int sqliteBtreeKeyCompare(BtCursor*, const void *pKey, int nKey,
int nIgnore, int *pRes);
int sqliteBtreeDataSize(BtCursor*, int *pSize);
int sqliteBtreeData(BtCursor*, int offset, int amt, char *zBuf);
int sqliteBtreeCloseCursor(BtCursor*);
#define SQLITE_N_BTREE_META 4
int sqliteBtreeGetMeta(Btree*, int*);
int sqliteBtreeUpdateMeta(Btree*, int*);
char *sqliteBtreeIntegrityCheck(Btree*, int*, int);
#define sqliteBtreeClose(pBt) (btOps(pBt)->Close(pBt))
#define sqliteBtreeSetCacheSize(pBt, sz) (btOps(pBt)->SetCacheSize(pBt, sz))
#define sqliteBtreeSetSafetyLevel(pBt, sl) (btOps(pBt)->SetSafetyLevel(pBt, sl))
#define sqliteBtreeBeginTrans(pBt) (btOps(pBt)->BeginTrans(pBt))
#define sqliteBtreeCommit(pBt) (btOps(pBt)->Commit(pBt))
#define sqliteBtreeRollback(pBt) (btOps(pBt)->Rollback(pBt))
#define sqliteBtreeBeginCkpt(pBt) (btOps(pBt)->BeginCkpt(pBt))
#define sqliteBtreeCommitCkpt(pBt) (btOps(pBt)->CommitCkpt(pBt))
#define sqliteBtreeRollbackCkpt(pBt) (btOps(pBt)->RollbackCkpt(pBt))
#define sqliteBtreeCreateTable(pBt,piTable)\
(btOps(pBt)->CreateTable(pBt,piTable))
#define sqliteBtreeCreateIndex(pBt, piIndex)\
(btOps(pBt)->CreateIndex(pBt, piIndex))
#define sqliteBtreeDropTable(pBt, iTable) (btOps(pBt)->DropTable(pBt, iTable))
#define sqliteBtreeClearTable(pBt, iTable)\
(btOps(pBt)->ClearTable(pBt, iTable))
#define sqliteBtreeCursor(pBt, iTable, wrFlag, ppCur)\
(btOps(pBt)->Cursor(pBt, iTable, wrFlag, ppCur))
#define sqliteBtreeMoveto(pCur, pKey, nKey, pRes)\
(btCOps(pCur)->Moveto(pCur, pKey, nKey, pRes))
#define sqliteBtreeDelete(pCur) (btCOps(pCur)->Delete(pCur))
#define sqliteBtreeInsert(pCur, pKey, nKey, pData, nData) \
(btCOps(pCur)->Insert(pCur, pKey, nKey, pData, nData))
#define sqliteBtreeFirst(pCur, pRes) (btCOps(pCur)->First(pCur, pRes))
#define sqliteBtreeLast(pCur, pRes) (btCOps(pCur)->Last(pCur, pRes))
#define sqliteBtreeNext(pCur, pRes) (btCOps(pCur)->Next(pCur, pRes))
#define sqliteBtreePrevious(pCur, pRes) (btCOps(pCur)->Previous(pCur, pRes))
#define sqliteBtreeKeySize(pCur, pSize) (btCOps(pCur)->KeySize(pCur, pSize) )
#define sqliteBtreeKey(pCur, offset, amt, zBuf)\
(btCOps(pCur)->Key(pCur, offset, amt, zBuf))
#define sqliteBtreeKeyCompare(pCur, pKey, nKey, nIgnore, pRes)\
(btCOps(pCur)->KeyCompare(pCur, pKey, nKey, nIgnore, pRes))
#define sqliteBtreeDataSize(pCur, pSize) (btCOps(pCur)->DataSize(pCur, pSize))
#define sqliteBtreeData(pCur, offset, amt, zBuf)\
(btCOps(pCur)->Data(pCur, offset, amt, zBuf))
#define sqliteBtreeCloseCursor(pCur) (btCOps(pCur)->CloseCursor(pCur))
#define sqliteBtreeGetMeta(pBt, aMeta) (btOps(pBt)->GetMeta(pBt, aMeta))
#define sqliteBtreeUpdateMeta(pBt, aMeta) (btOps(pBt)->UpdateMeta(pBt, aMeta))
#define sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot)\
(btOps(pBt)->IntegrityCheck(pBt, aRoot, nRoot))
#define sqliteBtreeGetFilename(pBt) (btOps(pBt)->GetFilename(pBt))
#define sqliteBtreeCopyFile(pBt1, pBt2) (btOps(pBt1)->Copyfile(pBt1, pBt2))
#define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt))
#ifdef SQLITE_TEST
int sqliteBtreePageDump(Btree*, int, int);
int sqliteBtreeCursorDump(BtCursor*, int*);
struct Pager *sqliteBtreePager(Btree*);
#define sqliteBtreePageDump(pBt, pgno, recursive)\
(btOps(pBt)->PageDump(pBt, pgno, recursive))
#define sqliteBtreeCursorDump(pCur, aResult)\
(btCOps(pCur)->CursorDump(pCur, aResult))
int btree_native_byte_order;
#endif
#endif /* SQLITE_TEST */
#endif /* _BTREE_H_ */
+1488
View File
File diff suppressed because it is too large Load Diff
+649 -914
View File
File diff suppressed because it is too large Load Diff
+110
View File
@@ -0,0 +1,110 @@
/*
** 2003 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the COPY command.
**
** $Id: copy.c,v 1.9 2004/02/25 13:47:31 drh Exp $
*/
#include "sqliteInt.h"
/*
** The COPY command is for compatibility with PostgreSQL and specificially
** for the ability to read the output of pg_dump. The format is as
** follows:
**
** COPY table FROM file [USING DELIMITERS string]
**
** "table" is an existing table name. We will read lines of code from
** file to fill this table with data. File might be "stdin". The optional
** delimiter string identifies the field separators. The default is a tab.
*/
void sqliteCopy(
Parse *pParse, /* The parser context */
SrcList *pTableName, /* The name of the table into which we will insert */
Token *pFilename, /* The file from which to obtain information */
Token *pDelimiter, /* Use this as the field delimiter */
int onError /* What to do if a constraint fails */
){
Table *pTab;
int i;
Vdbe *v;
int addr, end;
char *zFile = 0;
const char *zDb;
sqlite *db = pParse->db;
if( sqlite_malloc_failed ) goto copy_cleanup;
assert( pTableName->nSrc==1 );
pTab = sqliteSrcListLookup(pParse, pTableName);
if( pTab==0 || sqliteIsReadOnly(pParse, pTab, 0) ) goto copy_cleanup;
zFile = sqliteStrNDup(pFilename->z, pFilename->n);
sqliteDequote(zFile);
assert( pTab->iDb<db->nDb );
zDb = db->aDb[pTab->iDb].zName;
if( sqliteAuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb)
|| sqliteAuthCheck(pParse, SQLITE_COPY, pTab->zName, zFile, zDb) ){
goto copy_cleanup;
}
v = sqliteGetVdbe(pParse);
if( v ){
sqliteBeginWriteOperation(pParse, 1, pTab->iDb);
addr = sqliteVdbeOp3(v, OP_FileOpen, 0, 0, pFilename->z, pFilename->n);
sqliteVdbeDequoteP3(v, addr);
sqliteOpenTableAndIndices(pParse, pTab, 0);
if( db->flags & SQLITE_CountRows ){
sqliteVdbeAddOp(v, OP_Integer, 0, 0); /* Initialize the row count */
}
end = sqliteVdbeMakeLabel(v);
addr = sqliteVdbeAddOp(v, OP_FileRead, pTab->nCol, end);
if( pDelimiter ){
sqliteVdbeChangeP3(v, addr, pDelimiter->z, pDelimiter->n);
sqliteVdbeDequoteP3(v, addr);
}else{
sqliteVdbeChangeP3(v, addr, "\t", 1);
}
if( pTab->iPKey>=0 ){
sqliteVdbeAddOp(v, OP_FileColumn, pTab->iPKey, 0);
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
}else{
sqliteVdbeAddOp(v, OP_NewRecno, 0, 0);
}
for(i=0; i<pTab->nCol; i++){
if( i==pTab->iPKey ){
/* The integer primary key column is filled with NULL since its
** value is always pulled from the record number */
sqliteVdbeAddOp(v, OP_String, 0, 0);
}else{
sqliteVdbeAddOp(v, OP_FileColumn, i, 0);
}
}
sqliteGenerateConstraintChecks(pParse, pTab, 0, 0, pTab->iPKey>=0,
0, onError, addr);
sqliteCompleteInsertion(pParse, pTab, 0, 0, 0, 0, -1);
if( (db->flags & SQLITE_CountRows)!=0 ){
sqliteVdbeAddOp(v, OP_AddImm, 1, 0); /* Increment row count */
}
sqliteVdbeAddOp(v, OP_Goto, 0, addr);
sqliteVdbeResolveLabel(v, end);
sqliteVdbeAddOp(v, OP_Noop, 0, 0);
sqliteEndWriteOperation(pParse);
if( db->flags & SQLITE_CountRows ){
sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC);
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
}
}
copy_cleanup:
sqliteSrcListDelete(pTableName);
sqliteFree(zFile);
return;
}
+873
View File
@@ -0,0 +1,873 @@
/*
** 2003 October 31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement date and time
** functions for SQLite.
**
** There is only one exported symbol in this file - the function
** sqliteRegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.16 2004/02/29 01:08:18 drh Exp $
**
** NOTES:
**
** SQLite processes all times and dates as Julian Day numbers. The
** dates and times are stored as the number of days since noon
** in Greenwich on November 24, 4714 B.C. according to the Gregorian
** calendar system.
**
** 1970-01-01 00:00:00 is JD 2440587.5
** 2000-01-01 00:00:00 is JD 2451544.5
**
** This implemention requires years to be expressed as a 4-digit number
** which means that only dates between 0000-01-01 and 9999-12-31 can
** be represented, even though julian day numbers allow a much wider
** range of dates.
**
** The Gregorian calendar system is used for all dates and times,
** even those that predate the Gregorian calendar. Historians usually
** use the Julian calendar for dates prior to 1582-10-15 and for some
** dates afterwards, depending on locale. Beware of this difference.
**
** The conversion algorithms are implemented based on descriptions
** in the following text:
**
** Jean Meeus
** Astronomical Algorithms, 2nd Edition, 1998
** ISBM 0-943396-61-1
** Willmann-Bell, Inc
** Richmond, Virginia (USA)
*/
#include "os.h"
#include "sqliteInt.h"
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#ifndef SQLITE_OMIT_DATETIME_FUNCS
/*
** A structure for holding a single date and time.
*/
typedef struct DateTime DateTime;
struct DateTime {
double rJD; /* The julian day number */
int Y, M, D; /* Year, month, and day */
int h, m; /* Hour and minutes */
int tz; /* Timezone offset in minutes */
double s; /* Seconds */
char validYMD; /* True if Y,M,D are valid */
char validHMS; /* True if h,m,s are valid */
char validJD; /* True if rJD is valid */
char validTZ; /* True if tz is valid */
};
/*
** Convert zDate into one or more integers. Additional arguments
** come in groups of 5 as follows:
**
** N number of digits in the integer
** min minimum allowed value of the integer
** max maximum allowed value of the integer
** nextC first character after the integer
** pVal where to write the integers value.
**
** Conversions continue until one with nextC==0 is encountered.
** The function returns the number of successful conversions.
*/
static int getDigits(const char *zDate, ...){
va_list ap;
int val;
int N;
int min;
int max;
int nextC;
int *pVal;
int cnt = 0;
va_start(ap, zDate);
do{
N = va_arg(ap, int);
min = va_arg(ap, int);
max = va_arg(ap, int);
nextC = va_arg(ap, int);
pVal = va_arg(ap, int*);
val = 0;
while( N-- ){
if( !isdigit(*zDate) ){
return cnt;
}
val = val*10 + *zDate - '0';
zDate++;
}
if( val<min || val>max || (nextC!=0 && nextC!=*zDate) ){
return cnt;
}
*pVal = val;
zDate++;
cnt++;
}while( nextC );
return cnt;
}
/*
** Read text from z[] and convert into a floating point number. Return
** the number of digits converted.
*/
static int getValue(const char *z, double *pR){
const char *zEnd;
*pR = sqliteAtoF(z, &zEnd);
return zEnd - z;
}
/*
** Parse a timezone extension on the end of a date-time.
** The extension is of the form:
**
** (+/-)HH:MM
**
** If the parse is successful, write the number of minutes
** of change in *pnMin and return 0. If a parser error occurs,
** return 0.
**
** A missing specifier is not considered an error.
*/
static int parseTimezone(const char *zDate, DateTime *p){
int sgn = 0;
int nHr, nMn;
while( isspace(*zDate) ){ zDate++; }
p->tz = 0;
if( *zDate=='-' ){
sgn = -1;
}else if( *zDate=='+' ){
sgn = +1;
}else{
return *zDate!=0;
}
zDate++;
if( getDigits(zDate, 2, 0, 14, ':', &nHr, 2, 0, 59, 0, &nMn)!=2 ){
return 1;
}
zDate += 5;
p->tz = sgn*(nMn + nHr*60);
while( isspace(*zDate) ){ zDate++; }
return *zDate!=0;
}
/*
** Parse times of the form HH:MM or HH:MM:SS or HH:MM:SS.FFFF.
** The HH, MM, and SS must each be exactly 2 digits. The
** fractional seconds FFFF can be one or more digits.
**
** Return 1 if there is a parsing error and 0 on success.
*/
static int parseHhMmSs(const char *zDate, DateTime *p){
int h, m, s;
double ms = 0.0;
if( getDigits(zDate, 2, 0, 24, ':', &h, 2, 0, 59, 0, &m)!=2 ){
return 1;
}
zDate += 5;
if( *zDate==':' ){
zDate++;
if( getDigits(zDate, 2, 0, 59, 0, &s)!=1 ){
return 1;
}
zDate += 2;
if( *zDate=='.' && isdigit(zDate[1]) ){
double rScale = 1.0;
zDate++;
while( isdigit(*zDate) ){
ms = ms*10.0 + *zDate - '0';
rScale *= 10.0;
zDate++;
}
ms /= rScale;
}
}else{
s = 0;
}
p->validJD = 0;
p->validHMS = 1;
p->h = h;
p->m = m;
p->s = s + ms;
if( parseTimezone(zDate, p) ) return 1;
p->validTZ = p->tz!=0;
return 0;
}
/*
** Convert from YYYY-MM-DD HH:MM:SS to julian day. We always assume
** that the YYYY-MM-DD is according to the Gregorian calendar.
**
** Reference: Meeus page 61
*/
static void computeJD(DateTime *p){
int Y, M, D, A, B, X1, X2;
if( p->validJD ) return;
if( p->validYMD ){
Y = p->Y;
M = p->M;
D = p->D;
}else{
Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
M = 1;
D = 1;
}
if( M<=2 ){
Y--;
M += 12;
}
A = Y/100;
B = 2 - A + (A/4);
X1 = 365.25*(Y+4716);
X2 = 30.6001*(M+1);
p->rJD = X1 + X2 + D + B - 1524.5;
p->validJD = 1;
p->validYMD = 0;
if( p->validHMS ){
p->rJD += (p->h*3600.0 + p->m*60.0 + p->s)/86400.0;
if( p->validTZ ){
p->rJD += p->tz*60/86400.0;
p->validHMS = 0;
p->validTZ = 0;
}
}
}
/*
** Parse dates of the form
**
** YYYY-MM-DD HH:MM:SS.FFF
** YYYY-MM-DD HH:MM:SS
** YYYY-MM-DD HH:MM
** YYYY-MM-DD
**
** Write the result into the DateTime structure and return 0
** on success and 1 if the input string is not a well-formed
** date.
*/
static int parseYyyyMmDd(const char *zDate, DateTime *p){
int Y, M, D, neg;
if( zDate[0]=='-' ){
zDate++;
neg = 1;
}else{
neg = 0;
}
if( getDigits(zDate,4,0,9999,'-',&Y,2,1,12,'-',&M,2,1,31,0,&D)!=3 ){
return 1;
}
zDate += 10;
while( isspace(*zDate) ){ zDate++; }
if( parseHhMmSs(zDate, p)==0 ){
/* We got the time */
}else if( *zDate==0 ){
p->validHMS = 0;
}else{
return 1;
}
p->validJD = 0;
p->validYMD = 1;
p->Y = neg ? -Y : Y;
p->M = M;
p->D = D;
if( p->validTZ ){
computeJD(p);
}
return 0;
}
/*
** Attempt to parse the given string into a Julian Day Number. Return
** the number of errors.
**
** The following are acceptable forms for the input string:
**
** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
** DDDD.DD
** now
**
** In the first form, the +/-HH:MM is always optional. The fractional
** seconds extension (the ".FFF") is optional. The seconds portion
** (":SS.FFF") is option. The year and date can be omitted as long
** as there is a time string. The time string can be omitted as long
** as there is a year and date.
*/
static int parseDateOrTime(const char *zDate, DateTime *p){
memset(p, 0, sizeof(*p));
if( parseYyyyMmDd(zDate,p)==0 ){
return 0;
}else if( parseHhMmSs(zDate, p)==0 ){
return 0;
}else if( sqliteStrICmp(zDate,"now")==0){
double r;
if( sqliteOsCurrentTime(&r)==0 ){
p->rJD = r;
p->validJD = 1;
return 0;
}
return 1;
}else if( sqliteIsNumber(zDate) ){
p->rJD = sqliteAtoF(zDate, 0);
p->validJD = 1;
return 0;
}
return 1;
}
/*
** Compute the Year, Month, and Day from the julian day number.
*/
static void computeYMD(DateTime *p){
int Z, A, B, C, D, E, X1;
if( p->validYMD ) return;
if( !p->validJD ){
p->Y = 2000;
p->M = 1;
p->D = 1;
}else{
Z = p->rJD + 0.5;
A = (Z - 1867216.25)/36524.25;
A = Z + 1 + A - (A/4);
B = A + 1524;
C = (B - 122.1)/365.25;
D = 365.25*C;
E = (B-D)/30.6001;
X1 = 30.6001*E;
p->D = B - D - X1;
p->M = E<14 ? E-1 : E-13;
p->Y = p->M>2 ? C - 4716 : C - 4715;
}
p->validYMD = 1;
}
/*
** Compute the Hour, Minute, and Seconds from the julian day number.
*/
static void computeHMS(DateTime *p){
int Z, s;
if( p->validHMS ) return;
Z = p->rJD + 0.5;
s = (p->rJD + 0.5 - Z)*86400000.0 + 0.5;
p->s = 0.001*s;
s = p->s;
p->s -= s;
p->h = s/3600;
s -= p->h*3600;
p->m = s/60;
p->s += s - p->m*60;
p->validHMS = 1;
}
/*
** Compute both YMD and HMS
*/
static void computeYMD_HMS(DateTime *p){
computeYMD(p);
computeHMS(p);
}
/*
** Clear the YMD and HMS and the TZ
*/
static void clearYMD_HMS_TZ(DateTime *p){
p->validYMD = 0;
p->validHMS = 0;
p->validTZ = 0;
}
/*
** Compute the difference (in days) between localtime and UTC (a.k.a. GMT)
** for the time value p where p is in UTC.
*/
static double localtimeOffset(DateTime *p){
DateTime x, y;
time_t t;
struct tm *pTm;
x = *p;
computeYMD_HMS(&x);
if( x.Y<1971 || x.Y>=2038 ){
x.Y = 2000;
x.M = 1;
x.D = 1;
x.h = 0;
x.m = 0;
x.s = 0.0;
} else {
int s = x.s + 0.5;
x.s = s;
}
x.tz = 0;
x.validJD = 0;
computeJD(&x);
t = (x.rJD-2440587.5)*86400.0 + 0.5;
sqliteOsEnterMutex();
pTm = localtime(&t);
y.Y = pTm->tm_year + 1900;
y.M = pTm->tm_mon + 1;
y.D = pTm->tm_mday;
y.h = pTm->tm_hour;
y.m = pTm->tm_min;
y.s = pTm->tm_sec;
sqliteOsLeaveMutex();
y.validYMD = 1;
y.validHMS = 1;
y.validJD = 0;
y.validTZ = 0;
computeJD(&y);
return y.rJD - x.rJD;
}
/*
** Process a modifier to a date-time stamp. The modifiers are
** as follows:
**
** NNN days
** NNN hours
** NNN minutes
** NNN.NNNN seconds
** NNN months
** NNN years
** start of month
** start of year
** start of week
** start of day
** weekday N
** unixepoch
** localtime
** utc
**
** Return 0 on success and 1 if there is any kind of error.
*/
static int parseModifier(const char *zMod, DateTime *p){
int rc = 1;
int n;
double r;
char *z, zBuf[30];
z = zBuf;
for(n=0; n<sizeof(zBuf)-1 && zMod[n]; n++){
z[n] = tolower(zMod[n]);
}
z[n] = 0;
switch( z[0] ){
case 'l': {
/* localtime
**
** Assuming the current time value is UTC (a.k.a. GMT), shift it to
** show local time.
*/
if( strcmp(z, "localtime")==0 ){
computeJD(p);
p->rJD += localtimeOffset(p);
clearYMD_HMS_TZ(p);
rc = 0;
}
break;
}
case 'u': {
/*
** unixepoch
**
** Treat the current value of p->rJD as the number of
** seconds since 1970. Convert to a real julian day number.
*/
if( strcmp(z, "unixepoch")==0 && p->validJD ){
p->rJD = p->rJD/86400.0 + 2440587.5;
clearYMD_HMS_TZ(p);
rc = 0;
}else if( strcmp(z, "utc")==0 ){
double c1;
computeJD(p);
c1 = localtimeOffset(p);
p->rJD -= c1;
clearYMD_HMS_TZ(p);
p->rJD += c1 - localtimeOffset(p);
rc = 0;
}
break;
}
case 'w': {
/*
** weekday N
**
** Move the date to the same time on the next occurrance of
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
** date is already on the appropriate weekday, this is a no-op.
*/
if( strncmp(z, "weekday ", 8)==0 && getValue(&z[8],&r)>0
&& (n=r)==r && n>=0 && r<7 ){
int Z;
computeYMD_HMS(p);
p->validTZ = 0;
p->validJD = 0;
computeJD(p);
Z = p->rJD + 1.5;
Z %= 7;
if( Z>n ) Z -= 7;
p->rJD += n - Z;
clearYMD_HMS_TZ(p);
rc = 0;
}
break;
}
case 's': {
/*
** start of TTTTT
**
** Move the date backwards to the beginning of the current day,
** or month or year.
*/
if( strncmp(z, "start of ", 9)!=0 ) break;
z += 9;
computeYMD(p);
p->validHMS = 1;
p->h = p->m = 0;
p->s = 0.0;
p->validTZ = 0;
p->validJD = 0;
if( strcmp(z,"month")==0 ){
p->D = 1;
rc = 0;
}else if( strcmp(z,"year")==0 ){
computeYMD(p);
p->M = 1;
p->D = 1;
rc = 0;
}else if( strcmp(z,"day")==0 ){
rc = 0;
}
break;
}
case '+':
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': {
n = getValue(z, &r);
if( n<=0 ) break;
if( z[n]==':' ){
/* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
** specified number of hours, minutes, seconds, and fractional seconds
** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
** omitted.
*/
const char *z2 = z;
DateTime tx;
int day;
if( !isdigit(*z2) ) z2++;
memset(&tx, 0, sizeof(tx));
if( parseHhMmSs(z2, &tx) ) break;
computeJD(&tx);
tx.rJD -= 0.5;
day = (int)tx.rJD;
tx.rJD -= day;
if( z[0]=='-' ) tx.rJD = -tx.rJD;
computeJD(p);
clearYMD_HMS_TZ(p);
p->rJD += tx.rJD;
rc = 0;
break;
}
z += n;
while( isspace(z[0]) ) z++;
n = strlen(z);
if( n>10 || n<3 ) break;
if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
computeJD(p);
rc = 0;
if( n==3 && strcmp(z,"day")==0 ){
p->rJD += r;
}else if( n==4 && strcmp(z,"hour")==0 ){
p->rJD += r/24.0;
}else if( n==6 && strcmp(z,"minute")==0 ){
p->rJD += r/(24.0*60.0);
}else if( n==6 && strcmp(z,"second")==0 ){
p->rJD += r/(24.0*60.0*60.0);
}else if( n==5 && strcmp(z,"month")==0 ){
int x, y;
computeYMD_HMS(p);
p->M += r;
x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
p->Y += x;
p->M -= x*12;
p->validJD = 0;
computeJD(p);
y = r;
if( y!=r ){
p->rJD += (r - y)*30.0;
}
}else if( n==4 && strcmp(z,"year")==0 ){
computeYMD_HMS(p);
p->Y += r;
p->validJD = 0;
computeJD(p);
}else{
rc = 1;
}
clearYMD_HMS_TZ(p);
break;
}
default: {
break;
}
}
return rc;
}
/*
** Process time function arguments. argv[0] is a date-time stamp.
** argv[1] and following are modifiers. Parse them all and write
** the resulting time into the DateTime structure p. Return 0
** on success and 1 if there are any errors.
*/
static int isDate(int argc, const char **argv, DateTime *p){
int i;
if( argc==0 ) return 1;
if( argv[0]==0 || parseDateOrTime(argv[0], p) ) return 1;
for(i=1; i<argc; i++){
if( argv[i]==0 || parseModifier(argv[i], p) ) return 1;
}
return 0;
}
/*
** The following routines implement the various date and time functions
** of SQLite.
*/
/*
** julianday( TIMESTRING, MOD, MOD, ...)
**
** Return the julian day number of the date specified in the arguments
*/
static void juliandayFunc(sqlite_func *context, int argc, const char **argv){
DateTime x;
if( isDate(argc, argv, &x)==0 ){
computeJD(&x);
sqlite_set_result_double(context, x.rJD);
}
}
/*
** datetime( TIMESTRING, MOD, MOD, ...)
**
** Return YYYY-MM-DD HH:MM:SS
*/
static void datetimeFunc(sqlite_func *context, int argc, const char **argv){
DateTime x;
if( isDate(argc, argv, &x)==0 ){
char zBuf[100];
computeYMD_HMS(&x);
sprintf(zBuf, "%04d-%02d-%02d %02d:%02d:%02d",x.Y, x.M, x.D, x.h, x.m,
(int)(x.s));
sqlite_set_result_string(context, zBuf, -1);
}
}
/*
** time( TIMESTRING, MOD, MOD, ...)
**
** Return HH:MM:SS
*/
static void timeFunc(sqlite_func *context, int argc, const char **argv){
DateTime x;
if( isDate(argc, argv, &x)==0 ){
char zBuf[100];
computeHMS(&x);
sprintf(zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s);
sqlite_set_result_string(context, zBuf, -1);
}
}
/*
** date( TIMESTRING, MOD, MOD, ...)
**
** Return YYYY-MM-DD
*/
static void dateFunc(sqlite_func *context, int argc, const char **argv){
DateTime x;
if( isDate(argc, argv, &x)==0 ){
char zBuf[100];
computeYMD(&x);
sprintf(zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D);
sqlite_set_result_string(context, zBuf, -1);
}
}
/*
** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
**
** Return a string described by FORMAT. Conversions as follows:
**
** %d day of month
** %f ** fractional seconds SS.SSS
** %H hour 00-24
** %j day of year 000-366
** %J ** Julian day number
** %m month 01-12
** %M minute 00-59
** %s seconds since 1970-01-01
** %S seconds 00-59
** %w day of week 0-6 sunday==0
** %W week of year 00-53
** %Y year 0000-9999
** %% %
*/
static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
DateTime x;
int n, i, j;
char *z;
const char *zFmt = argv[0];
char zBuf[100];
if( argv[0]==0 || isDate(argc-1, argv+1, &x) ) return;
for(i=0, n=1; zFmt[i]; i++, n++){
if( zFmt[i]=='%' ){
switch( zFmt[i+1] ){
case 'd':
case 'H':
case 'm':
case 'M':
case 'S':
case 'W':
n++;
/* fall thru */
case 'w':
case '%':
break;
case 'f':
n += 8;
break;
case 'j':
n += 3;
break;
case 'Y':
n += 8;
break;
case 's':
case 'J':
n += 50;
break;
default:
return; /* ERROR. return a NULL */
}
i++;
}
}
if( n<sizeof(zBuf) ){
z = zBuf;
}else{
z = sqliteMalloc( n );
if( z==0 ) return;
}
computeJD(&x);
computeYMD_HMS(&x);
for(i=j=0; zFmt[i]; i++){
if( zFmt[i]!='%' ){
z[j++] = zFmt[i];
}else{
i++;
switch( zFmt[i] ){
case 'd': sprintf(&z[j],"%02d",x.D); j+=2; break;
case 'f': {
int s = x.s;
int ms = (x.s - s)*1000.0;
sprintf(&z[j],"%02d.%03d",s,ms);
j += strlen(&z[j]);
break;
}
case 'H': sprintf(&z[j],"%02d",x.h); j+=2; break;
case 'W': /* Fall thru */
case 'j': {
int n;
DateTime y = x;
y.validJD = 0;
y.M = 1;
y.D = 1;
computeJD(&y);
n = x.rJD - y.rJD + 1;
if( zFmt[i]=='W' ){
sprintf(&z[j],"%02d",(n+6)/7);
j += 2;
}else{
sprintf(&z[j],"%03d",n);
j += 3;
}
break;
}
case 'J': sprintf(&z[j],"%.16g",x.rJD); j+=strlen(&z[j]); break;
case 'm': sprintf(&z[j],"%02d",x.M); j+=2; break;
case 'M': sprintf(&z[j],"%02d",x.m); j+=2; break;
case 's': {
sprintf(&z[j],"%d",(int)((x.rJD-2440587.5)*86400.0 + 0.5));
j += strlen(&z[j]);
break;
}
case 'S': sprintf(&z[j],"%02d",(int)(x.s+0.5)); j+=2; break;
case 'w': z[j++] = (((int)(x.rJD+1.5)) % 7) + '0'; break;
case 'Y': sprintf(&z[j],"%04d",x.Y); j+=strlen(&z[j]); break;
case '%': z[j++] = '%'; break;
}
}
}
z[j] = 0;
sqlite_set_result_string(context, z, -1);
if( z!=zBuf ){
sqliteFree(z);
}
}
#endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */
/*
** This function registered all of the above C functions as SQL
** functions. This should be the only routine in this file with
** external linkage.
*/
void sqliteRegisterDateTimeFunctions(sqlite *db){
static struct {
char *zName;
int nArg;
int dataType;
void (*xFunc)(sqlite_func*,int,const char**);
} aFuncs[] = {
#ifndef SQLITE_OMIT_DATETIME_FUNCS
{ "julianday", -1, SQLITE_NUMERIC, juliandayFunc },
{ "date", -1, SQLITE_TEXT, dateFunc },
{ "time", -1, SQLITE_TEXT, timeFunc },
{ "datetime", -1, SQLITE_TEXT, datetimeFunc },
{ "strftime", -1, SQLITE_TEXT, strftimeFunc },
#endif
};
int i;
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
sqlite_create_function(db, aFuncs[i].zName,
aFuncs[i].nArg, aFuncs[i].xFunc, 0);
if( aFuncs[i].xFunc ){
sqlite_function_type(db, aFuncs[i].zName, aFuncs[i].dataType);
}
}
}
+146 -140
View File
@@ -12,57 +12,42 @@
** This file contains C code routines that are called by the parser
** to handle DELETE FROM statements.
**
** $Id: delete.c,v 1.42 2002/09/14 13:47:32 drh Exp $
** $Id: delete.c,v 1.61 2004/02/24 01:05:32 drh Exp $
*/
#include "sqliteInt.h"
/*
** Given a table name, find the corresponding table and make sure the
** table is writeable. Generate an error and return NULL if not. If
** everything checks out, return a pointer to the Table structure.
** Look up every table that is named in pSrc. If any table is not found,
** add an error message to pParse->zErrMsg and return NULL. If all tables
** are found, return a pointer to the last table.
*/
Table *sqliteTableNameToTable(Parse *pParse, const char *zTab){
Table *pTab;
pTab = sqliteFindTable(pParse->db, zTab);
if( pTab==0 ){
sqliteSetString(&pParse->zErrMsg, "no such table: ", zTab, 0);
pParse->nErr++;
return 0;
}
if( pTab->readOnly || pTab->pSelect ){
sqliteSetString(&pParse->zErrMsg,
pTab->pSelect ? "view " : "table ",
zTab,
" may not be modified", 0);
pParse->nErr++;
return 0;
Table *sqliteSrcListLookup(Parse *pParse, SrcList *pSrc){
Table *pTab = 0;
int i;
for(i=0; i<pSrc->nSrc; i++){
const char *zTab = pSrc->a[i].zName;
const char *zDb = pSrc->a[i].zDatabase;
pTab = sqliteLocateTable(pParse, zTab, zDb);
pSrc->a[i].pTab = pTab;
}
return pTab;
}
/*
** Given a table name, check to make sure the table exists, is writable
** and is not a view. If everything is OK, construct an SrcList holding
** the table and return a pointer to the SrcList. The calling function
** is responsible for freeing the SrcList when it has finished with it.
** If there is an error, leave a message on pParse->zErrMsg and return
** NULL.
** Check to make sure the given table is writable. If it is not
** writable, generate an error message and return 1. If it is
** writable return 0;
*/
SrcList *sqliteTableTokenToSrcList(Parse *pParse, Token *pTableName){
Table *pTab;
SrcList *pTabList;
pTabList = sqliteSrcListAppend(0, pTableName);
if( pTabList==0 ) return 0;
assert( pTabList->nSrc==1 );
pTab = sqliteTableNameToTable(pParse, pTabList->a[0].zName);
if( pTab==0 ){
sqliteSrcListDelete(pTabList);
return 0;
int sqliteIsReadOnly(Parse *pParse, Table *pTab, int viewOk){
if( pTab->readOnly ){
sqliteErrorMsg(pParse, "table %s may not be modified", pTab->zName);
return 1;
}
pTabList->a[0].pTab = pTab;
return pTabList;
if( !viewOk && pTab->pSelect ){
sqliteErrorMsg(pParse, "cannot modify %s because it is a view",pTab->zName);
return 1;
}
return 0;
}
/*
@@ -70,61 +55,61 @@ SrcList *sqliteTableTokenToSrcList(Parse *pParse, Token *pTableName){
*/
void sqliteDeleteFrom(
Parse *pParse, /* The parser context */
Token *pTableName, /* The table from which we should delete things */
SrcList *pTabList, /* The table from which we should delete things */
Expr *pWhere /* The WHERE clause. May be null */
){
Vdbe *v; /* The virtual database engine */
Table *pTab; /* The table from which records will be deleted */
char *zTab; /* Name of the table from which we are deleting */
SrcList *pTabList; /* A fake FROM clause holding just pTab */
const char *zDb; /* Name of database holding pTab */
int end, addr; /* A couple addresses of generated code */
int i; /* Loop counter */
WhereInfo *pWInfo; /* Information about the WHERE clause */
Index *pIdx; /* For looping over indices of the table */
int base; /* Index of the first available table cursor */
int iCur; /* VDBE Cursor number for pTab */
sqlite *db; /* Main database structure */
int openOp; /* Opcode used to open a cursor to the table */
int isView; /* True if attempting to delete from a view */
AuthContext sContext; /* Authorization context */
int row_triggers_exist = 0;
int oldIdx = -1;
int row_triggers_exist = 0; /* True if any triggers exist */
int before_triggers; /* True if there are BEFORE triggers */
int after_triggers; /* True if there are AFTER triggers */
int oldIdx = -1; /* Cursor for the OLD table of AFTER triggers */
sContext.pParse = 0;
if( pParse->nErr || sqlite_malloc_failed ){
pTabList = 0;
goto delete_from_cleanup;
}
db = pParse->db;
/* Check for the special case of a VIEW with one or more ON DELETE triggers
** defined
*/
zTab = sqliteTableNameFromToken(pTableName);
if( zTab != 0 ){
pTab = sqliteFindTable(pParse->db, zTab);
if( pTab ){
row_triggers_exist =
sqliteTriggersExist(pParse, pTab->pTrigger,
TK_DELETE, TK_BEFORE, TK_ROW, 0) ||
sqliteTriggersExist(pParse, pTab->pTrigger,
TK_DELETE, TK_AFTER, TK_ROW, 0);
}
sqliteFree(zTab);
if( row_triggers_exist && pTab->pSelect ){
/* Just fire VIEW triggers */
sqliteViewTriggers(pParse, pTab, pWhere, OE_Replace, 0);
return;
}
}
assert( pTabList->nSrc==1 );
/* Locate the table which we want to delete. This table has to be
** put in an SrcList structure because some of the subroutines we
** will be calling are designed to work with multiple tables and expect
** an SrcList* parameter instead of just a Table* parameter.
*/
pTabList = sqliteTableTokenToSrcList(pParse, pTableName);
if( pTabList==0 ) goto delete_from_cleanup;
assert( pTabList->nSrc==1 );
pTab = pTabList->a[0].pTab;
assert( pTab->pSelect==0 ); /* This table is not a view */
pTab = sqliteSrcListLookup(pParse, pTabList);
if( pTab==0 ) goto delete_from_cleanup;
before_triggers = sqliteTriggersExist(pParse, pTab->pTrigger,
TK_DELETE, TK_BEFORE, TK_ROW, 0);
after_triggers = sqliteTriggersExist(pParse, pTab->pTrigger,
TK_DELETE, TK_AFTER, TK_ROW, 0);
row_triggers_exist = before_triggers || after_triggers;
isView = pTab->pSelect!=0;
if( sqliteIsReadOnly(pParse, pTab, before_triggers) ){
goto delete_from_cleanup;
}
assert( pTab->iDb<db->nDb );
zDb = db->aDb[pTab->iDb].zName;
if( sqliteAuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
goto delete_from_cleanup;
}
/* If pTab is really a view, make sure it has been initialized.
*/
if( isView && sqliteViewGetColumnNames(pParse, pTab) ){
goto delete_from_cleanup;
}
/* Allocate a cursor used to store the old.* data for a trigger.
*/
@@ -134,9 +119,10 @@ void sqliteDeleteFrom(
/* Resolve the column names in all the expressions.
*/
base = pParse->nTab++;
assert( pTabList->nSrc==1 );
iCur = pTabList->a[0].iCursor = pParse->nTab++;
if( pWhere ){
if( sqliteExprResolveIds(pParse, base, pTabList, 0, pWhere) ){
if( sqliteExprResolveIds(pParse, pTabList, 0, pWhere) ){
goto delete_from_cleanup;
}
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
@@ -144,14 +130,28 @@ void sqliteDeleteFrom(
}
}
/* Start the view context
*/
if( isView ){
sqliteAuthContextPush(pParse, &sContext, pTab->zName);
}
/* Begin generating code.
*/
v = sqliteGetVdbe(pParse);
if( v==0 ){
goto delete_from_cleanup;
}
sqliteBeginWriteOperation(pParse, row_triggers_exist,
!row_triggers_exist && pTab->isTemp);
sqliteBeginWriteOperation(pParse, row_triggers_exist, pTab->iDb);
/* If we are trying to delete from a view, construct that view into
** a temporary table.
*/
if( isView ){
Select *pView = sqliteSelectDup(pTab->pSelect);
sqliteSelect(pParse, pView, SRT_TempTable, iCur, 0, 0, 0);
sqliteSelectDelete(pView);
}
/* Initialize the counter of the number of rows deleted, if
** we are counting rows.
@@ -170,27 +170,31 @@ void sqliteDeleteFrom(
** entries in the table. */
int endOfLoop = sqliteVdbeMakeLabel(v);
int addr;
openOp = pTab->isTemp ? OP_OpenAux : OP_Open;
sqliteVdbeAddOp(v, openOp, base, pTab->tnum);
sqliteVdbeAddOp(v, OP_Rewind, base, sqliteVdbeCurrentAddr(v)+2);
if( !isView ){
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
}
sqliteVdbeAddOp(v, OP_Rewind, iCur, sqliteVdbeCurrentAddr(v)+2);
addr = sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
sqliteVdbeAddOp(v, OP_Next, base, addr);
sqliteVdbeAddOp(v, OP_Next, iCur, addr);
sqliteVdbeResolveLabel(v, endOfLoop);
sqliteVdbeAddOp(v, OP_Close, base, 0);
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
}
sqliteVdbeAddOp(v, OP_Clear, pTab->tnum, pTab->isTemp);
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
sqliteVdbeAddOp(v, OP_Clear, pIdx->tnum, pTab->isTemp);
if( !isView ){
sqliteVdbeAddOp(v, OP_Clear, pTab->tnum, pTab->iDb);
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
sqliteVdbeAddOp(v, OP_Clear, pIdx->tnum, pIdx->iDb);
}
}
}
/* The usual case: There is a WHERE clause so we have to scan through
** the table an pick which records to delete.
** the table and pick which records to delete.
*/
else{
/* Begin the database scan
*/
pWInfo = sqliteWhereBegin(pParse, base, pTabList, pWhere, 1, 0);
pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 1, 0);
if( pWInfo==0 ) goto delete_from_cleanup;
/* Remember the key of every item to be deleted.
@@ -204,6 +208,12 @@ void sqliteDeleteFrom(
*/
sqliteWhereEnd(pWInfo);
/* Open the pseudo-table used to store OLD if there are triggers.
*/
if( row_triggers_exist ){
sqliteVdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
}
/* Delete every item whose key was written to the list during the
** database scan. We have to delete items after the scan is complete
** because deleting an item can change the scan order.
@@ -217,60 +227,54 @@ void sqliteDeleteFrom(
if( row_triggers_exist ){
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
openOp = pTab->isTemp ? OP_OpenAux : OP_Open;
sqliteVdbeAddOp(v, openOp, base, pTab->tnum);
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
sqliteVdbeAddOp(v, OP_OpenTemp, oldIdx, 0);
sqliteVdbeAddOp(v, OP_Integer, 13, 0);
for(i = 0; i<pTab->nCol; i++){
if( i==pTab->iPKey ){
sqliteVdbeAddOp(v, OP_Recno, base, 0);
} else {
sqliteVdbeAddOp(v, OP_Column, base, i);
}
if( !isView ){
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
}
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
sqliteVdbeAddOp(v, OP_RowData, iCur, 0);
sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
sqliteVdbeAddOp(v, OP_Close, base, 0);
sqliteVdbeAddOp(v, OP_Rewind, oldIdx, 0);
if( !isView ){
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
}
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_BEFORE, pTab, -1,
oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
addr);
}
/* Open cursors for the table we are deleting from and all its
** indices. If there are row triggers, this happens inside the
** OP_ListRead loop because the cursor have to all be closed
** before the trigger fires. If there are no row triggers, the
** cursors are opened only once on the outside the loop.
*/
pParse->nTab = base + 1;
openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite;
sqliteVdbeAddOp(v, openOp, base, pTab->tnum);
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
sqliteVdbeAddOp(v, openOp, pParse->nTab++, pIdx->tnum);
}
if( !isView ){
/* Open cursors for the table we are deleting from and all its
** indices. If there are row triggers, this happens inside the
** OP_ListRead loop because the cursor have to all be closed
** before the trigger fires. If there are no row triggers, the
** cursors are opened only once on the outside the loop.
*/
pParse->nTab = iCur + 1;
sqliteOpenTableAndIndices(pParse, pTab, iCur);
/* This is the beginning of the delete loop when there are no
** row triggers */
if( !row_triggers_exist ){
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
}
/* This is the beginning of the delete loop when there are no
** row triggers */
if( !row_triggers_exist ){
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
}
/* Delete the row */
sqliteGenerateRowDelete(db, v, pTab, base, pParse->trigStack==0);
/* Delete the row */
sqliteGenerateRowDelete(db, v, pTab, iCur, pParse->trigStack==0);
}
/* If there are row triggers, close all cursors then invoke
** the AFTER triggers
*/
if( row_triggers_exist ){
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
sqliteVdbeAddOp(v, OP_Close, base + i, pIdx->tnum);
if( !isView ){
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
sqliteVdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
}
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
}
sqliteVdbeAddOp(v, OP_Close, base, 0);
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1,
oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
addr);
@@ -284,25 +288,26 @@ void sqliteDeleteFrom(
/* Close the cursors after the loop if there are no row triggers */
if( !row_triggers_exist ){
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
sqliteVdbeAddOp(v, OP_Close, base + i, pIdx->tnum);
sqliteVdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum);
}
sqliteVdbeAddOp(v, OP_Close, base, 0);
pParse->nTab = base;
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
pParse->nTab = iCur;
}
}
sqliteVdbeAddOp(v, OP_SetCounts, 0, 0);
sqliteEndWriteOperation(pParse);
/*
** Return the number of rows that were deleted.
*/
if( db->flags & SQLITE_CountRows ){
sqliteVdbeAddOp(v, OP_ColumnCount, 1, 0);
sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
sqliteVdbeChangeP3(v, -1, "rows deleted", P3_STATIC);
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
}
delete_from_cleanup:
sqliteAuthContextPop(&sContext);
sqliteSrcListDelete(pTabList);
sqliteExprDelete(pWhere);
return;
@@ -332,13 +337,14 @@ void sqliteGenerateRowDelete(
sqlite *db, /* The database containing the index */
Vdbe *v, /* Generate code into this VDBE */
Table *pTab, /* Table containing the row to be deleted */
int base, /* Cursor number for the table */
int iCur, /* Cursor number for the table */
int count /* Increment the row change counter */
){
int addr;
addr = sqliteVdbeAddOp(v, OP_NotExists, base, 0);
sqliteGenerateRowIndexDelete(db, v, pTab, base, 0);
sqliteVdbeAddOp(v, OP_Delete, base, count);
addr = sqliteVdbeAddOp(v, OP_NotExists, iCur, 0);
sqliteGenerateRowIndexDelete(db, v, pTab, iCur, 0);
sqliteVdbeAddOp(v, OP_Delete, iCur,
(count?OPFLAG_NCHANGE:0) | OPFLAG_CSCHANGE);
sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
}
@@ -350,19 +356,19 @@ void sqliteGenerateRowDelete(
** These are the requirements:
**
** 1. A read/write cursor pointing to pTab, the table containing the row
** to be deleted, must be opened as cursor number "base".
** to be deleted, must be opened as cursor number "iCur".
**
** 2. Read/write cursors for all indices of pTab must be open as
** cursor number base+i for the i-th index.
** cursor number iCur+i for the i-th index.
**
** 3. The "base" cursor must be pointing to the row that is to be
** 3. The "iCur" cursor must be pointing to the row that is to be
** deleted.
*/
void sqliteGenerateRowIndexDelete(
sqlite *db, /* The database containing the index */
Vdbe *v, /* Generate code into this VDBE */
Table *pTab, /* Table containing the row to be deleted */
int base, /* Cursor number for the table */
int iCur, /* Cursor number for the table */
char *aIdxUsed /* Only delete if aIdxUsed!=0 && aIdxUsed[i]!=0 */
){
int i;
@@ -371,17 +377,17 @@ void sqliteGenerateRowIndexDelete(
for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
int j;
if( aIdxUsed!=0 && aIdxUsed[i-1]==0 ) continue;
sqliteVdbeAddOp(v, OP_Recno, base, 0);
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
for(j=0; j<pIdx->nColumn; j++){
int idx = pIdx->aiColumn[j];
if( idx==pTab->iPKey ){
sqliteVdbeAddOp(v, OP_Dup, j, 0);
}else{
sqliteVdbeAddOp(v, OP_Column, base, idx);
sqliteVdbeAddOp(v, OP_Column, iCur, idx);
}
}
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
sqliteVdbeAddOp(v, OP_IdxDelete, base+i, 0);
sqliteVdbeAddOp(v, OP_IdxDelete, iCur+i, 0);
}
}
+122 -32
View File
@@ -12,10 +12,92 @@
** This file contains helper routines used to translate binary data into
** a null-terminated string (suitable for use in SQLite) and back again.
** These are convenience routines for use by people who want to store binary
** data in an SQLite database. The code in this file is used by any other
** data in an SQLite database. The code in this file is not used by any other
** part of the SQLite library.
**
** $Id: encode.c,v 1.3 2002/09/16 11:44:06 drh Exp $
** $Id: encode.c,v 1.12 2004/03/17 18:44:46 drh Exp $
*/
#include <string.h>
#include <assert.h>
/*
** How This Encoder Works
**
** The output is allowed to contain any character except 0x27 (') and
** 0x00. This is accomplished by using an escape character to encode
** 0x27 and 0x00 as a two-byte sequence. The escape character is always
** 0x01. An 0x00 is encoded as the two byte sequence 0x01 0x01. The
** 0x27 character is encoded as the two byte sequence 0x01 0x28. Finally,
** the escape character itself is encoded as the two-character sequence
** 0x01 0x02.
**
** To summarize, the encoder works by using an escape sequences as follows:
**
** 0x00 -> 0x01 0x01
** 0x01 -> 0x01 0x02
** 0x27 -> 0x01 0x28
**
** If that were all the encoder did, it would work, but in certain cases
** it could double the size of the encoded string. For example, to
** encode a string of 100 0x27 characters would require 100 instances of
** the 0x01 0x03 escape sequence resulting in a 200-character output.
** We would prefer to keep the size of the encoded string smaller than
** this.
**
** To minimize the encoding size, we first add a fixed offset value to each
** byte in the sequence. The addition is modulo 256. (That is to say, if
** the sum of the original character value and the offset exceeds 256, then
** the higher order bits are truncated.) The offset is chosen to minimize
** the number of characters in the string that need to be escaped. For
** example, in the case above where the string was composed of 100 0x27
** characters, the offset might be 0x01. Each of the 0x27 characters would
** then be converted into an 0x28 character which would not need to be
** escaped at all and so the 100 character input string would be converted
** into just 100 characters of output. Actually 101 characters of output -
** we have to record the offset used as the first byte in the sequence so
** that the string can be decoded. Since the offset value is stored as
** part of the output string and the output string is not allowed to contain
** characters 0x00 or 0x27, the offset cannot be 0x00 or 0x27.
**
** Here, then, are the encoding steps:
**
** (1) Choose an offset value and make it the first character of
** output.
**
** (2) Copy each input character into the output buffer, one by
** one, adding the offset value as you copy.
**
** (3) If the value of an input character plus offset is 0x00, replace
** that one character by the two-character sequence 0x01 0x01.
** If the sum is 0x01, replace it with 0x01 0x02. If the sum
** is 0x27, replace it with 0x01 0x03.
**
** (4) Put a 0x00 terminator at the end of the output.
**
** Decoding is obvious:
**
** (5) Copy encoded characters except the first into the decode
** buffer. Set the first encoded character aside for use as
** the offset in step 7 below.
**
** (6) Convert each 0x01 0x01 sequence into a single character 0x00.
** Convert 0x01 0x02 into 0x01. Convert 0x01 0x28 into 0x27.
**
** (7) Subtract the offset value that was the first character of
** the encoded buffer from all characters in the output buffer.
**
** The only tricky part is step (1) - how to compute an offset value to
** minimize the size of the output buffer. This is accomplished by testing
** all offset values and picking the one that results in the fewest number
** of escapes. To do that, we first scan the entire input and count the
** number of occurances of each character value in the input. Suppose
** the number of 0x00 characters is N(0), the number of occurances of 0x01
** is N(1), and so forth up to the number of occurances of 0xff is N(255).
** An offset of 0 is not allowed so we don't have to test it. The number
** of escapes required for an offset of 1 is N(1)+N(2)+N(40). The number
** of escapes required for an offset of 2 is N(2)+N(3)+N(41). And so forth.
** In this way we find the offset that gives the minimum number of escapes,
** and thus minimizes the length of the output string.
*/
/*
@@ -26,20 +108,27 @@
** string back into its original binary.
**
** The result is written into a preallocated output buffer "out".
** "out" must be able to hold at least (256*n + 1262)/253 bytes.
** "out" must be able to hold at least 2 +(257*n)/254 bytes.
** In other words, the output will be expanded by as much as 3
** bytes for every 253 bytes of input plus 2 bytes of fixed overhead.
** (This is approximately 2 + 1.019*n or about a 2% size increase.)
** bytes for every 254 bytes of input plus 2 bytes of fixed overhead.
** (This is approximately 2 + 1.0118*n or about a 1.2% size increase.)
**
** The return value is the number of characters in the encoded
** string, excluding the "\000" terminator.
**
** If out==NULL then no output is generated but the routine still returns
** the number of characters that would have been generated if out had
** not been NULL.
*/
int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
int i, j, e, m;
unsigned char x;
int cnt[256];
if( n<=0 ){
out[0] = 'x';
out[1] = 0;
if( out ){
out[0] = 'x';
out[1] = 0;
}
return 1;
}
memset(cnt, 0, sizeof(cnt));
@@ -55,30 +144,27 @@ int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
if( m==0 ) break;
}
}
if( out==0 ){
return n+m+1;
}
out[0] = e;
j = 1;
for(i=0; i<n; i++){
int c = (in[i] - e)&0xff;
if( c==0 ){
x = in[i] - e;
if( x==0 || x==1 || x=='\''){
out[j++] = 1;
out[j++] = 1;
}else if( c==1 ){
out[j++] = 1;
out[j++] = 2;
}else if( c=='\'' ){
out[j++] = 1;
out[j++] = 3;
}else{
out[j++] = c;
x++;
}
out[j++] = x;
}
out[j] = 0;
assert( j==n+m+1 );
return j;
}
/*
** Decode the string "in" into binary data and write it into "out".
** This routine reverses the encoded created by sqlite_encode_binary().
** This routine reverses the encoding created by sqlite_encode_binary().
** The output will always be a few bytes less than the input. The number
** of bytes of output is returned. If the input is not a well-formed
** encoding, -1 is returned.
@@ -87,38 +173,32 @@ int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
** to decode a string in place.
*/
int sqlite_decode_binary(const unsigned char *in, unsigned char *out){
int i, c, e;
int i, e;
unsigned char c;
e = *(in++);
i = 0;
while( (c = *(in++))!=0 ){
if( c==1 ){
c = *(in++);
if( c==1 ){
c = 0;
}else if( c==2 ){
c = 1;
}else if( c==3 ){
c = '\'';
}else{
return -1;
}
c = *(in++) - 1;
}
out[i++] = (c + e)&0xff;
out[i++] = c + e;
}
return i;
}
#ifdef ENCODER_TEST
#include <stdio.h>
/*
** The subroutines above are not tested by the usual test suite. To test
** these routines, compile just this one file with a -DENCODER_TEST=1 option
** and run the result.
*/
int main(int argc, char **argv){
int i, j, n, m, nOut;
int i, j, n, m, nOut, nByteIn, nByteOut;
unsigned char in[30000];
unsigned char out[33000];
nByteIn = nByteOut = 0;
for(i=0; i<sizeof(in); i++){
printf("Test %d: ", i+1);
n = rand() % (i+1);
@@ -132,11 +212,17 @@ int main(int argc, char **argv){
}else{
for(j=0; j<n; j++) in[j] = rand() & 0xff;
}
nByteIn += n;
nOut = sqlite_encode_binary(in, n, out);
nByteOut += nOut;
if( nOut!=strlen(out) ){
printf(" ERROR return value is %d instead of %d\n", nOut, strlen(out));
exit(1);
}
if( nOut!=sqlite_encode_binary(in, n, 0) ){
printf(" ERROR actual output size disagrees with predicted size\n");
exit(1);
}
m = (256*n + 1262)/253;
printf("size %d->%d (max %d)", n, strlen(out)+1, m);
if( strlen(out)+1>m ){
@@ -160,5 +246,9 @@ int main(int argc, char **argv){
}
printf(" OK\n");
}
fprintf(stderr,"Finished. Total encoding: %d->%d bytes\n",
nByteIn, nByteOut);
fprintf(stderr,"Avg size increase: %.3f%%\n",
(nByteOut-nByteIn)*100.0/(double)nByteIn);
}
#endif /* ENCODER_TEST */
+418 -366
View File
File diff suppressed because it is too large Load Diff
+221 -97
View File
@@ -16,46 +16,48 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.22 2002/07/07 16:52:47 drh Exp $
** $Id: func.c,v 1.43 2004/02/25 22:51:06 rdc Exp $
*/
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include "sqliteInt.h"
#include "os.h"
/*
** Implementation of the non-aggregate min() and max() functions
*/
static void minFunc(sqlite_func *context, int argc, const char **argv){
static void minmaxFunc(sqlite_func *context, int argc, const char **argv){
const char *zBest;
int i;
int (*xCompare)(const char*, const char*);
int mask; /* 0 for min() or 0xffffffff for max() */
if( argc==0 ) return;
mask = (int)sqlite_user_data(context);
zBest = argv[0];
if( zBest==0 ) return;
for(i=1; i<argc; i++){
if( argv[1][0]=='n' ){
xCompare = sqliteCompare;
}else{
xCompare = strcmp;
}
for(i=2; i<argc; i+=2){
if( argv[i]==0 ) return;
if( sqliteCompare(argv[i], zBest)<0 ){
if( (xCompare(argv[i], zBest)^mask)<0 ){
zBest = argv[i];
}
}
sqlite_set_result_string(context, zBest, -1);
}
static void maxFunc(sqlite_func *context, int argc, const char **argv){
const char *zBest;
int i;
if( argc==0 ) return;
zBest = argv[0];
if( zBest==0 ) return;
for(i=1; i<argc; i++){
if( argv[i]==0 ) return;
if( sqliteCompare(argv[i], zBest)>0 ){
zBest = argv[i];
}
}
sqlite_set_result_string(context, zBest, -1);
/*
** Return the type of the argument.
*/
static void typeofFunc(sqlite_func *context, int argc, const char **argv){
assert( argc==2 );
sqlite_set_result_string(context, argv[1], -1);
}
/*
@@ -121,13 +123,11 @@ static void substrFunc(sqlite_func *context, int argc, const char **argv){
p2 = len-p1;
}
#ifdef SQLITE_UTF8
for(i=0; i<p1; i++){
assert( z[i] );
for(i=0; i<p1 && z[i]; i++){
if( (z[i]&0xc0)==0x80 ) p1++;
}
while( z[i] && (z[i]&0xc0)==0x80 ){ i++; p1++; }
for(; i<p1+p2; i++){
assert( z[i] );
for(; i<p1+p2 && z[i]; i++){
if( (z[i]&0xc0)==0x80 ) p2++;
}
while( z[i] && (z[i]&0xc0)==0x80 ){ i++; p2++; }
@@ -148,7 +148,7 @@ static void roundFunc(sqlite_func *context, int argc, const char **argv){
n = argc==2 ? atoi(argv[1]) : 0;
if( n>30 ) n = 30;
if( n<0 ) n = 0;
r = atof(argv[0]);
r = sqliteAtoF(argv[0], 0);
sprintf(zBuf,"%.*f",n,r);
sqlite_set_result_string(context, zBuf, -1);
}
@@ -179,8 +179,8 @@ static void lowerFunc(sqlite_func *context, int argc, const char **argv){
/*
** Implementation of the IFNULL(), NVL(), and COALESCE() functions.
** All three do the same thing. They return the first argument
** non-NULL argument.
** All three do the same thing. They return the first non-NULL
** argument.
*/
static void ifnullFunc(sqlite_func *context, int argc, const char **argv){
int i;
@@ -196,7 +196,9 @@ static void ifnullFunc(sqlite_func *context, int argc, const char **argv){
** Implementation of random(). Return a random integer.
*/
static void randomFunc(sqlite_func *context, int argc, const char **argv){
sqlite_set_result_int(context, sqliteRandomInteger());
int r;
sqliteRandomness(sizeof(r), &r);
sqlite_set_result_int(context, r);
}
/*
@@ -208,6 +210,25 @@ static void last_insert_rowid(sqlite_func *context, int arg, const char **argv){
sqlite_set_result_int(context, sqlite_last_insert_rowid(db));
}
/*
** Implementation of the change_count() SQL function. The return
** value is the same as the sqlite_changes() API function.
*/
static void change_count(sqlite_func *context, int arg, const char **argv){
sqlite *db = sqlite_user_data(context);
sqlite_set_result_int(context, sqlite_changes(db));
}
/*
** Implementation of the last_statement_change_count() SQL function. The
** return value is the same as the sqlite_last_statement_changes() API function.
*/
static void last_statement_change_count(sqlite_func *context, int arg,
const char **argv){
sqlite *db = sqlite_user_data(context);
sqlite_set_result_int(context, sqlite_last_statement_changes(db));
}
/*
** Implementation of the like() SQL function. This function implements
** the build-in LIKE operator. The first argument to the function is the
@@ -219,7 +240,9 @@ static void last_insert_rowid(sqlite_func *context, int arg, const char **argv){
*/
static void likeFunc(sqlite_func *context, int arg, const char **argv){
if( argv[0]==0 || argv[1]==0 ) return;
sqlite_set_result_int(context, sqliteLikeCompare(argv[0], argv[1]));
sqlite_set_result_int(context,
sqliteLikeCompare((const unsigned char*)argv[0],
(const unsigned char*)argv[1]));
}
/*
@@ -233,7 +256,9 @@ static void likeFunc(sqlite_func *context, int arg, const char **argv){
*/
static void globFunc(sqlite_func *context, int arg, const char **argv){
if( argv[0]==0 || argv[1]==0 ) return;
sqlite_set_result_int(context, sqliteGlobCompare(argv[0], argv[1]));
sqlite_set_result_int(context,
sqliteGlobCompare((const unsigned char*)argv[0],
(const unsigned char*)argv[1]));
}
/*
@@ -247,19 +272,104 @@ static void nullifFunc(sqlite_func *context, int argc, const char **argv){
}
}
/*
** Implementation of the VERSION(*) function. The result is the version
** of the SQLite library that is running.
*/
static void versionFunc(sqlite_func *context, int argc, const char **argv){
sqlite_set_result_string(context, sqlite_version, -1);
}
/*
** EXPERIMENTAL - This is not an official function. The interface may
** change. This function may disappear. Do not write code that depends
** on this function.
**
** Implementation of the QUOTE() function. This function takes a single
** argument. If the argument is numeric, the return value is the same as
** the argument. If the argument is NULL, the return value is the string
** "NULL". Otherwise, the argument is enclosed in single quotes with
** single-quote escapes.
*/
static void quoteFunc(sqlite_func *context, int argc, const char **argv){
if( argc<1 ) return;
if( argv[0]==0 ){
sqlite_set_result_string(context, "NULL", 4);
}else if( sqliteIsNumber(argv[0]) ){
sqlite_set_result_string(context, argv[0], -1);
}else{
int i,j,n;
char *z;
for(i=n=0; argv[0][i]; i++){ if( argv[0][i]=='\'' ) n++; }
z = sqliteMalloc( i+n+3 );
if( z==0 ) return;
z[0] = '\'';
for(i=0, j=1; argv[0][i]; i++){
z[j++] = argv[0][i];
if( argv[0][i]=='\'' ){
z[j++] = '\'';
}
}
z[j++] = '\'';
z[j] = 0;
sqlite_set_result_string(context, z, j);
sqliteFree(z);
}
}
#ifdef SQLITE_SOUNDEX
/*
** Compute the soundex encoding of a word.
*/
static void soundexFunc(sqlite_func *context, int argc, const char **argv){
char zResult[8];
const char *zIn;
int i, j;
static const unsigned char iCode[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
};
assert( argc==1 );
zIn = argv[0];
for(i=0; zIn[i] && !isalpha(zIn[i]); i++){}
if( zIn[i] ){
zResult[0] = toupper(zIn[i]);
for(j=1; j<4 && zIn[i]; i++){
int code = iCode[zIn[i]&0x7f];
if( code>0 ){
zResult[j++] = code + '0';
}
}
while( j<4 ){
zResult[j++] = '0';
}
zResult[j] = 0;
sqlite_set_result_string(context, zResult, 4);
}else{
sqlite_set_result_string(context, "?000", 4);
}
}
#endif
#ifdef SQLITE_TEST
/*
** This function generates a string of random characters. Used for
** generating test data.
*/
static void randStr(sqlite_func *context, int argc, const char **argv){
static const char zSrc[] =
static const unsigned char zSrc[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789"
".-!,:*^+=_|?/<> ";
int iMin, iMax, n, r, i;
char zBuf[1000];
unsigned char zBuf[1000];
if( argc>=1 ){
iMin = atoi(argv[0]);
if( iMin<0 ) iMin = 0;
@@ -270,20 +380,20 @@ static void randStr(sqlite_func *context, int argc, const char **argv){
if( argc>=2 ){
iMax = atoi(argv[1]);
if( iMax<iMin ) iMax = iMin;
if( iMax>=sizeof(zBuf) ) iMax = sizeof(zBuf);
if( iMax>=sizeof(zBuf) ) iMax = sizeof(zBuf)-1;
}else{
iMax = 50;
}
n = iMin;
if( iMax>iMin ){
r = sqliteRandomInteger();
if( r<0 ) r = -r;
sqliteRandomness(sizeof(r), &r);
r &= 0x7fffffff;
n += r%(iMax + 1 - iMin);
}
r = 0;
assert( n<sizeof(zBuf) );
sqliteRandomness(n, zBuf);
for(i=0; i<n; i++){
r = (r + sqliteRandomByte())% (sizeof(zSrc)-1);
zBuf[i] = zSrc[r];
zBuf[i] = zSrc[zBuf[i]%(sizeof(zSrc)-1)];
}
zBuf[n] = 0;
sqlite_set_result_string(context, zBuf, n);
@@ -308,7 +418,7 @@ static void sumStep(sqlite_func *context, int argc, const char **argv){
if( argc<1 ) return;
p = sqlite_aggregate_context(context, sizeof(*p));
if( p && argv[0] ){
p->sum += atof(argv[0]);
p->sum += sqliteAtoF(argv[0], 0);
p->cnt++;
}
}
@@ -346,7 +456,7 @@ static void stdDevStep(sqlite_func *context, int argc, const char **argv){
if( argc<1 ) return;
p = sqlite_aggregate_context(context, sizeof(*p));
if( p && argv[0] ){
x = atof(argv[0]);
x = sqliteAtoF(argv[0], 0);
p->sum += x;
p->sum2 += x*x;
p->cnt++;
@@ -401,39 +511,32 @@ struct MinMaxCtx {
/*
** Routines to implement min() and max() aggregate functions.
*/
static void minStep(sqlite_func *context, int argc, const char **argv){
static void minmaxStep(sqlite_func *context, int argc, const char **argv){
MinMaxCtx *p;
p = sqlite_aggregate_context(context, sizeof(*p));
if( p==0 || argc<1 || argv[0]==0 ) return;
if( p->z==0 || sqliteCompare(argv[0],p->z)<0 ){
int len;
if( p->z && p->z!=p->zBuf ){
sqliteFree(p->z);
}
len = strlen(argv[0]);
if( len < sizeof(p->zBuf) ){
p->z = p->zBuf;
}else{
p->z = sqliteMalloc( len+1 );
if( p->z==0 ) return;
}
strcpy(p->z, argv[0]);
int (*xCompare)(const char*, const char*);
int mask; /* 0 for min() or 0xffffffff for max() */
assert( argc==2 );
if( argv[1][0]=='n' ){
xCompare = sqliteCompare;
}else{
xCompare = strcmp;
}
}
static void maxStep(sqlite_func *context, int argc, const char **argv){
MinMaxCtx *p;
mask = (int)sqlite_user_data(context);
p = sqlite_aggregate_context(context, sizeof(*p));
if( p==0 || argc<1 || argv[0]==0 ) return;
if( p->z==0 || sqliteCompare(argv[0],p->z)>0 ){
if( p->z==0 || (xCompare(argv[0],p->z)^mask)<0 ){
int len;
if( p->z && p->z!=p->zBuf ){
if( !p->zBuf[0] ){
sqliteFree(p->z);
}
len = strlen(argv[0]);
if( len < sizeof(p->zBuf) ){
p->z = p->zBuf;
if( len < sizeof(p->zBuf)-1 ){
p->z = &p->zBuf[1];
p->zBuf[0] = 1;
}else{
p->z = sqliteMalloc( len+1 );
p->zBuf[0] = 0;
if( p->z==0 ) return;
}
strcpy(p->z, argv[0]);
@@ -445,7 +548,7 @@ static void minMaxFinalize(sqlite_func *context){
if( p && p->z ){
sqlite_set_result_string(context, p->z, strlen(p->z));
}
if( p && p->z && p->z!=p->zBuf ){
if( p && !p->zBuf[0] ){
sqliteFree(p->z);
}
}
@@ -458,65 +561,86 @@ static void minMaxFinalize(sqlite_func *context){
void sqliteRegisterBuiltinFunctions(sqlite *db){
static struct {
char *zName;
int nArg;
int dataType;
signed char nArg;
signed char dataType;
u8 argType; /* 0: none. 1: db 2: (-1) */
void (*xFunc)(sqlite_func*,int,const char**);
} aFuncs[] = {
{ "min", -1, SQLITE_ARGS, minFunc },
{ "min", 0, 0, 0 },
{ "max", -1, SQLITE_ARGS, maxFunc },
{ "max", 0, 0, 0 },
{ "length", 1, SQLITE_NUMERIC, lengthFunc },
{ "substr", 3, SQLITE_TEXT, substrFunc },
{ "abs", 1, SQLITE_NUMERIC, absFunc },
{ "round", 1, SQLITE_NUMERIC, roundFunc },
{ "round", 2, SQLITE_NUMERIC, roundFunc },
{ "upper", 1, SQLITE_TEXT, upperFunc },
{ "lower", 1, SQLITE_TEXT, lowerFunc },
{ "coalesce", -1, SQLITE_ARGS, ifnullFunc },
{ "coalesce", 0, 0, 0 },
{ "coalesce", 1, 0, 0 },
{ "ifnull", 2, SQLITE_ARGS, ifnullFunc },
{ "random", -1, SQLITE_NUMERIC, randomFunc },
{ "like", 2, SQLITE_NUMERIC, likeFunc },
{ "glob", 2, SQLITE_NUMERIC, globFunc },
{ "nullif", 2, SQLITE_ARGS, nullifFunc },
{ "min", -1, SQLITE_ARGS, 0, minmaxFunc },
{ "min", 0, 0, 0, 0 },
{ "max", -1, SQLITE_ARGS, 2, minmaxFunc },
{ "max", 0, 0, 2, 0 },
{ "typeof", 1, SQLITE_TEXT, 0, typeofFunc },
{ "length", 1, SQLITE_NUMERIC, 0, lengthFunc },
{ "substr", 3, SQLITE_TEXT, 0, substrFunc },
{ "abs", 1, SQLITE_NUMERIC, 0, absFunc },
{ "round", 1, SQLITE_NUMERIC, 0, roundFunc },
{ "round", 2, SQLITE_NUMERIC, 0, roundFunc },
{ "upper", 1, SQLITE_TEXT, 0, upperFunc },
{ "lower", 1, SQLITE_TEXT, 0, lowerFunc },
{ "coalesce", -1, SQLITE_ARGS, 0, ifnullFunc },
{ "coalesce", 0, 0, 0, 0 },
{ "coalesce", 1, 0, 0, 0 },
{ "ifnull", 2, SQLITE_ARGS, 0, ifnullFunc },
{ "random", -1, SQLITE_NUMERIC, 0, randomFunc },
{ "like", 2, SQLITE_NUMERIC, 0, likeFunc },
{ "glob", 2, SQLITE_NUMERIC, 0, globFunc },
{ "nullif", 2, SQLITE_ARGS, 0, nullifFunc },
{ "sqlite_version",0,SQLITE_TEXT, 0, versionFunc},
{ "quote", 1, SQLITE_ARGS, 0, quoteFunc },
{ "last_insert_rowid", 0, SQLITE_NUMERIC, 1, last_insert_rowid },
{ "change_count", 0, SQLITE_NUMERIC, 1, change_count },
{ "last_statement_change_count",
0, SQLITE_NUMERIC, 1, last_statement_change_count },
#ifdef SQLITE_SOUNDEX
{ "soundex", 1, SQLITE_TEXT, 0, soundexFunc},
#endif
#ifdef SQLITE_TEST
{ "randstr", 2, SQLITE_TEXT, randStr },
{ "randstr", 2, SQLITE_TEXT, 0, randStr },
#endif
};
static struct {
char *zName;
int nArg;
int dataType;
signed char nArg;
signed char dataType;
u8 argType;
void (*xStep)(sqlite_func*,int,const char**);
void (*xFinalize)(sqlite_func*);
} aAggs[] = {
{ "min", 1, 0, minStep, minMaxFinalize },
{ "max", 1, 0, maxStep, minMaxFinalize },
{ "sum", 1, SQLITE_NUMERIC, sumStep, sumFinalize },
{ "avg", 1, SQLITE_NUMERIC, sumStep, avgFinalize },
{ "count", 0, SQLITE_NUMERIC, countStep, countFinalize },
{ "count", 1, SQLITE_NUMERIC, countStep, countFinalize },
{ "min", 1, 0, 0, minmaxStep, minMaxFinalize },
{ "max", 1, 0, 2, minmaxStep, minMaxFinalize },
{ "sum", 1, SQLITE_NUMERIC, 0, sumStep, sumFinalize },
{ "avg", 1, SQLITE_NUMERIC, 0, sumStep, avgFinalize },
{ "count", 0, SQLITE_NUMERIC, 0, countStep, countFinalize },
{ "count", 1, SQLITE_NUMERIC, 0, countStep, countFinalize },
#if 0
{ "stddev", 1, SQLITE_NUMERIC, stdDevStep, stdDevFinalize },
{ "stddev", 1, SQLITE_NUMERIC, 0, stdDevStep, stdDevFinalize },
#endif
};
static const char *azTypeFuncs[] = { "min", "max", "typeof" };
int i;
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
void *pArg = aFuncs[i].argType==2 ? (void*)(-1) : db;
sqlite_create_function(db, aFuncs[i].zName,
aFuncs[i].nArg, aFuncs[i].xFunc, 0);
aFuncs[i].nArg, aFuncs[i].xFunc, pArg);
if( aFuncs[i].xFunc ){
sqlite_function_type(db, aFuncs[i].zName, aFuncs[i].dataType);
}
}
sqlite_create_function(db, "last_insert_rowid", 0,
last_insert_rowid, db);
sqlite_function_type(db, "last_insert_rowid", SQLITE_NUMERIC);
for(i=0; i<sizeof(aAggs)/sizeof(aAggs[0]); i++){
void *pArg = aAggs[i].argType==2 ? (void*)(-1) : db;
sqlite_create_aggregate(db, aAggs[i].zName,
aAggs[i].nArg, aAggs[i].xStep, aAggs[i].xFinalize, 0);
aAggs[i].nArg, aAggs[i].xStep, aAggs[i].xFinalize, pArg);
sqlite_function_type(db, aAggs[i].zName, aAggs[i].dataType);
}
for(i=0; i<sizeof(azTypeFuncs)/sizeof(azTypeFuncs[0]); i++){
int n = strlen(azTypeFuncs[i]);
FuncDef *p = sqliteHashFind(&db->aFunc, azTypeFuncs[i], n);
while( p ){
p->includeTypes = 1;
p = p->pNext;
}
}
sqliteRegisterDateTimeFunctions(db);
}
+7 -6
View File
@@ -12,7 +12,7 @@
** This is the implementation of generic hash-tables
** used in SQLite.
**
** $Id: hash.c,v 1.8 2002/05/21 23:44:30 drh Exp $
** $Id: hash.c,v 1.11 2004/01/08 02:17:33 drh Exp $
*/
#include "sqliteInt.h"
#include <assert.h>
@@ -75,6 +75,7 @@ static int intCompare(const void *pKey1, int n1, const void *pKey2, int n2){
return n2 - n1;
}
#if 0 /* NOT USED */
/*
** Hash and comparison functions when the mode is SQLITE_HASH_POINTER
*/
@@ -87,6 +88,7 @@ static int ptrCompare(const void *pKey1, int n1, const void *pKey2, int n2){
if( pKey1<pKey2 ) return -1;
return 1;
}
#endif
/*
** Hash and comparison functions when the mode is SQLITE_HASH_STRING
@@ -108,8 +110,7 @@ static int binHash(const void *pKey, int nKey){
while( nKey-- > 0 ){
h = (h<<3) ^ h ^ *(z++);
}
if( h<0 ) h = -h;
return h;
return h & 0x7fffffff;
}
static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
if( n1!=n2 ) return n2-n1;
@@ -131,7 +132,7 @@ static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
static int (*hashFunction(int keyClass))(const void*,int){
switch( keyClass ){
case SQLITE_HASH_INT: return &intHash;
case SQLITE_HASH_POINTER: return &ptrHash;
/* case SQLITE_HASH_POINTER: return &ptrHash; // NOT USED */
case SQLITE_HASH_STRING: return &strHash;
case SQLITE_HASH_BINARY: return &binHash;;
default: break;
@@ -148,7 +149,7 @@ static int (*hashFunction(int keyClass))(const void*,int){
static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
switch( keyClass ){
case SQLITE_HASH_INT: return &intCompare;
case SQLITE_HASH_POINTER: return &ptrCompare;
/* case SQLITE_HASH_POINTER: return &ptrCompare; // NOT USED */
case SQLITE_HASH_STRING: return &strCompare;
case SQLITE_HASH_BINARY: return &binCompare;
default: break;
@@ -313,7 +314,7 @@ void *sqliteHashInsert(Hash *pH, const void *pKey, int nKey, void *data){
new_elem = (HashElem*)sqliteMalloc( sizeof(HashElem) );
if( new_elem==0 ) return data;
if( pH->copyKey && pKey!=0 ){
new_elem->pKey = sqliteMalloc( nKey );
new_elem->pKey = sqliteMallocRaw( nKey );
if( new_elem->pKey==0 ){
sqliteFree(new_elem);
return data;
+2 -2
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.5 2002/06/08 23:25:09 drh Exp $
** $Id: hash.h,v 1.6 2004/01/08 02:17:33 drh Exp $
*/
#ifndef _SQLITE_HASH_H_
#define _SQLITE_HASH_H_
@@ -71,7 +71,7 @@ struct HashElem {
** if the copyKey parameter to HashInit is 1.
*/
#define SQLITE_HASH_INT 1
#define SQLITE_HASH_POINTER 2
/* #define SQLITE_HASH_POINTER 2 // NOT USED */
#define SQLITE_HASH_STRING 3
#define SQLITE_HASH_BINARY 4
+237 -142
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.67 2002/09/14 13:47:32 drh Exp $
** $Id: insert.c,v 1.94 2004/02/24 01:05:33 drh Exp $
*/
#include "sqliteInt.h"
@@ -85,22 +85,22 @@
*/
void sqliteInsert(
Parse *pParse, /* Parser context */
Token *pTableName, /* Name of table into which we are inserting */
SrcList *pTabList, /* Name of table into which we are inserting */
ExprList *pList, /* List of values to be inserted */
Select *pSelect, /* A SELECT statement to use as the data source */
IdList *pColumn, /* Column names corresponding to IDLIST. */
int onError /* How to handle constraint errors */
){
Table *pTab; /* The table to insert into */
char *zTab = 0; /* Name of the table into which we are inserting */
char *zTab; /* Name of the table into which we are inserting */
const char *zDb; /* Name of the database holding this table */
int i, j, idx; /* Loop counters */
Vdbe *v; /* Generate code into this virtual machine */
Index *pIdx; /* For looping over indices of the table */
int nColumn; /* Number of columns in the data */
int base; /* First available cursor */
int base; /* VDBE Cursor number for pTab */
int iCont, iBreak; /* Beginning and end of the loop over srcTab */
sqlite *db; /* The main database structure */
int openOp; /* Opcode used to open cursors */
int keyColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
int endOfLoop; /* Label for the end of the insertion loop */
int useTempTable; /* Store SELECT results in intermediate table */
@@ -109,21 +109,28 @@ void sqliteInsert(
int iCleanup; /* Address of the cleanup code */
int iInsertBlock; /* Address of the subroutine used to insert data */
int iCntMem; /* Memory cell used for the row counter */
int isView; /* True if attempting to insert into a view */
int row_triggers_exist = 0; /* True if there are FOR EACH ROW triggers */
int newIdx = -1;
int before_triggers; /* True if there are BEFORE triggers */
int after_triggers; /* True if there are AFTER triggers */
int newIdx = -1; /* Cursor for the NEW table */
if( pParse->nErr || sqlite_malloc_failed ) goto insert_cleanup;
db = pParse->db;
/* Locate the table into which we will be inserting new information.
*/
zTab = sqliteTableNameFromToken(pTableName);
assert( pTabList->nSrc==1 );
zTab = pTabList->a[0].zName;
if( zTab==0 ) goto insert_cleanup;
pTab = sqliteFindTable(pParse->db, zTab);
pTab = sqliteSrcListLookup(pParse, pTabList);
if( pTab==0 ){
sqliteSetString(&pParse->zErrMsg, "no such table: ", zTab, 0);
pParse->nErr++;
goto insert_cleanup;
}
assert( pTab->iDb<db->nDb );
zDb = db->aDb[pTab->iDb].zName;
if( sqliteAuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb) ){
goto insert_cleanup;
}
@@ -131,37 +138,28 @@ void sqliteInsert(
* (a) the table is not read-only,
* (b) that if it is a view then ON INSERT triggers exist
*/
row_triggers_exist =
sqliteTriggersExist(pParse, pTab->pTrigger, TK_INSERT,
TK_BEFORE, TK_ROW, 0) ||
sqliteTriggersExist(pParse, pTab->pTrigger, TK_INSERT, TK_AFTER, TK_ROW, 0);
if( pTab->readOnly || (pTab->pSelect && !row_triggers_exist) ){
sqliteSetString(&pParse->zErrMsg,
pTab->pSelect ? "view " : "table ",
zTab,
" may not be modified", 0);
pParse->nErr++;
before_triggers = sqliteTriggersExist(pParse, pTab->pTrigger, TK_INSERT,
TK_BEFORE, TK_ROW, 0);
after_triggers = sqliteTriggersExist(pParse, pTab->pTrigger, TK_INSERT,
TK_AFTER, TK_ROW, 0);
row_triggers_exist = before_triggers || after_triggers;
isView = pTab->pSelect!=0;
if( sqliteIsReadOnly(pParse, pTab, before_triggers) ){
goto insert_cleanup;
}
sqliteFree(zTab);
zTab = 0;
if( pTab==0 ) goto insert_cleanup;
/* If pTab is really a view, make sure it has been initialized.
*/
if( pTab->pSelect ){
if( sqliteViewGetColumnNames(pParse, pTab) ){
goto insert_cleanup;
}
if( isView && sqliteViewGetColumnNames(pParse, pTab) ){
goto insert_cleanup;
}
/* Allocate a VDBE
*/
v = sqliteGetVdbe(pParse);
if( v==0 ) goto insert_cleanup;
sqliteBeginWriteOperation(pParse, pSelect || row_triggers_exist,
!row_triggers_exist && pTab->isTemp);
sqliteBeginWriteOperation(pParse, pSelect || row_triggers_exist, pTab->iDb);
/* if there are row triggers, allocate a temp table for new.* references. */
if( row_triggers_exist ){
@@ -180,7 +178,6 @@ void sqliteInsert(
/* Data is coming from a SELECT. Generate code to implement that SELECT
*/
int rc, iInitCode;
int opCode;
iInitCode = sqliteVdbeAddOp(v, OP_Goto, 0, 0);
iSelectLoop = sqliteVdbeCurrentAddr(v);
iInsertBlock = sqliteVdbeMakeLabel(v);
@@ -194,9 +191,23 @@ void sqliteInsert(
/* Set useTempTable to TRUE if the result of the SELECT statement
** should be written into a temporary table. Set to FALSE if each
** row of the SELECT can be written directly into the result table.
**
** A temp table must be used if the table being updated is also one
** of the tables being read by the SELECT statement. Also use a
** temp table in the case of row triggers.
*/
opCode = pTab->isTemp ? OP_OpenTemp : OP_Open;
useTempTable = row_triggers_exist || sqliteVdbeFindOp(v,opCode,pTab->tnum);
if( row_triggers_exist ){
useTempTable = 1;
}else{
int addr = sqliteVdbeFindOp(v, OP_OpenRead, pTab->tnum);
useTempTable = 0;
if( addr>0 ){
VdbeOp *pOp = sqliteVdbeGetOp(v, addr-2);
if( pOp->opcode==OP_Integer && pOp->p1==pTab->iDb ){
useTempTable = 1;
}
}
}
if( useTempTable ){
/* Generate the subroutine that SELECT calls to process each row of
@@ -233,7 +244,7 @@ void sqliteInsert(
nColumn = pList->nExpr;
dummy.nSrc = 0;
for(i=0; i<nColumn; i++){
if( sqliteExprResolveIds(pParse, 0, &dummy, 0, pList->a[i].pExpr) ){
if( sqliteExprResolveIds(pParse, &dummy, 0, pList->a[i].pExpr) ){
goto insert_cleanup;
}
if( sqliteExprCheck(pParse, pList->a[i].pExpr, 0, 0) ){
@@ -246,24 +257,13 @@ void sqliteInsert(
** of columns to be inserted into the table.
*/
if( pColumn==0 && nColumn!=pTab->nCol ){
char zNum1[30];
char zNum2[30];
sprintf(zNum1,"%d", nColumn);
sprintf(zNum2,"%d", pTab->nCol);
sqliteSetString(&pParse->zErrMsg, "table ", pTab->zName,
" has ", zNum2, " columns but ",
zNum1, " values were supplied", 0);
pParse->nErr++;
sqliteErrorMsg(pParse,
"table %S has %d columns but %d values were supplied",
pTabList, 0, pTab->nCol, nColumn);
goto insert_cleanup;
}
if( pColumn!=0 && nColumn!=pColumn->nId ){
char zNum1[30];
char zNum2[30];
sprintf(zNum1,"%d", nColumn);
sprintf(zNum2,"%d", pColumn->nId);
sqliteSetString(&pParse->zErrMsg, zNum1, " values for ",
zNum2, " columns", 0);
pParse->nErr++;
sqliteErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
goto insert_cleanup;
}
@@ -293,10 +293,14 @@ void sqliteInsert(
}
}
if( j>=pTab->nCol ){
sqliteSetString(&pParse->zErrMsg, "table ", pTab->zName,
" has no column named ", pColumn->a[i].zName, 0);
pParse->nErr++;
goto insert_cleanup;
if( sqliteIsRowid(pColumn->a[i].zName) ){
keyColumn = i;
}else{
sqliteErrorMsg(pParse, "table %S has no column named %s",
pTabList, 0, pColumn->a[i].zName);
pParse->nErr++;
goto insert_cleanup;
}
}
}
}
@@ -312,7 +316,7 @@ void sqliteInsert(
/* Open the temp table for FOR EACH ROW triggers
*/
if( row_triggers_exist ){
sqliteVdbeAddOp(v, OP_OpenTemp, newIdx, 0);
sqliteVdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
}
/* Initialize the count of rows to be inserted
@@ -326,13 +330,7 @@ void sqliteInsert(
/* Open tables and indices if there are no row triggers */
if( !row_triggers_exist ){
base = pParse->nTab;
openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite;
sqliteVdbeAddOp(v, openOp, base, pTab->tnum);
sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
sqliteVdbeAddOp(v, openOp, idx+base, pIdx->tnum);
sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC);
}
idx = sqliteOpenTableAndIndices(pParse, pTab, base);
pParse->nTab += idx;
}
@@ -350,11 +348,33 @@ void sqliteInsert(
sqliteVdbeResolveLabel(v, iInsertBlock);
}
/* Run the BEFORE and INSTEAD OF triggers, if there are any
*/
endOfLoop = sqliteVdbeMakeLabel(v);
if( row_triggers_exist ){
if( before_triggers ){
/* build the new.* reference row */
sqliteVdbeAddOp(v, OP_Integer, 13, 0);
/* build the NEW.* reference row. Note that if there is an INTEGER
** PRIMARY KEY into which a NULL is being inserted, that NULL will be
** translated into a unique ID for the row. But on a BEFORE trigger,
** we do not know what the unique ID will be (because the insert has
** not happened yet) so we substitute a rowid of -1
*/
if( keyColumn<0 ){
sqliteVdbeAddOp(v, OP_Integer, -1, 0);
}else if( useTempTable ){
sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
}else if( pSelect ){
sqliteVdbeAddOp(v, OP_Dup, nColumn - keyColumn - 1, 1);
}else{
sqliteExprCode(pParse, pList->a[keyColumn].pExpr);
sqliteVdbeAddOp(v, OP_NotNull, -1, sqliteVdbeCurrentAddr(v)+3);
sqliteVdbeAddOp(v, OP_Pop, 1, 0);
sqliteVdbeAddOp(v, OP_Integer, -1, 0);
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
}
/* Create the new column data
*/
for(i=0; i<pTab->nCol; i++){
if( pColumn==0 ){
j = i;
@@ -364,8 +384,7 @@ void sqliteInsert(
}
}
if( pColumn && j>=pColumn->nId ){
sqliteVdbeAddOp(v, OP_String, 0, 0);
sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zDflt, P3_STATIC);
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
}else if( useTempTable ){
sqliteVdbeAddOp(v, OP_Column, srcTab, j);
}else if( pSelect ){
@@ -376,26 +395,21 @@ void sqliteInsert(
}
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
sqliteVdbeAddOp(v, OP_Rewind, newIdx, 0);
/* Fire BEFORE triggers */
if( sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab, newIdx, -1,
onError, endOfLoop) ){
/* Fire BEFORE or INSTEAD OF triggers */
if( sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab,
newIdx, -1, onError, endOfLoop) ){
goto insert_cleanup;
}
}
/* Open the tables and indices for the INSERT */
if( !pTab->pSelect ){
base = pParse->nTab;
openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite;
sqliteVdbeAddOp(v, openOp, base, pTab->tnum);
sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
sqliteVdbeAddOp(v, openOp, idx+base, pIdx->tnum);
sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC);
}
pParse->nTab += idx;
}
/* If any triggers exists, the opening of tables and indices is deferred
** until now.
*/
if( row_triggers_exist && !isView ){
base = pParse->nTab;
idx = sqliteOpenTableAndIndices(pParse, pTab, base);
pParse->nTab += idx;
}
/* Push the record number for the new entry onto the stack. The
@@ -403,7 +417,7 @@ void sqliteInsert(
** except when the table has an INTEGER PRIMARY KEY column, in which
** case the record number is the same as that column.
*/
if( !pTab->pSelect ){
if( !isView ){
if( keyColumn>=0 ){
if( useTempTable ){
sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
@@ -443,8 +457,7 @@ void sqliteInsert(
}
}
if( pColumn && j>=pColumn->nId ){
sqliteVdbeAddOp(v, OP_String, 0, 0);
sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zDflt, P3_STATIC);
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
}else if( useTempTable ){
sqliteVdbeAddOp(v, OP_Column, srcTab, j);
}else if( pSelect ){
@@ -457,19 +470,21 @@ void sqliteInsert(
/* Generate code to check constraints and generate index keys and
** do the insertion.
*/
sqliteGenerateConstraintChecks(pParse, pTab, base, 0,0,0,onError,endOfLoop);
sqliteCompleteInsertion(pParse, pTab, base, 0,0,0);
sqliteGenerateConstraintChecks(pParse, pTab, base, 0, keyColumn>=0,
0, onError, endOfLoop);
sqliteCompleteInsertion(pParse, pTab, base, 0,0,0,
after_triggers ? newIdx : -1);
}
/* Update the count of rows that are inserted
*/
if( (db->flags & SQLITE_CountRows)!=0 ){
sqliteVdbeAddOp(v, OP_MemIncr, iCntMem, 0);
}
/* Update the count of rows that are inserted
*/
if( (db->flags & SQLITE_CountRows)!=0 ){
sqliteVdbeAddOp(v, OP_MemIncr, iCntMem, 0);
}
if( row_triggers_exist ){
/* Close all tables opened */
if( !pTab->pSelect ){
if( !isView ){
sqliteVdbeAddOp(v, OP_Close, base, 0);
for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
sqliteVdbeAddOp(v, OP_Close, idx+base, 0);
@@ -504,23 +519,22 @@ void sqliteInsert(
}
}
sqliteVdbeAddOp(v, OP_SetCounts, 0, 0);
sqliteEndWriteOperation(pParse);
/*
** Return the number of rows inserted.
*/
if( db->flags & SQLITE_CountRows ){
sqliteVdbeAddOp(v, OP_ColumnCount, 1, 0);
sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC);
sqliteVdbeOp3(v, OP_ColumnName, 0, 1, "rows inserted", P3_STATIC);
sqliteVdbeAddOp(v, OP_MemLoad, iCntMem, 0);
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
}
insert_cleanup:
sqliteSrcListDelete(pTabList);
if( pList ) sqliteExprListDelete(pList);
if( pSelect ) sqliteSelectDelete(pSelect);
if ( zTab ) sqliteFree(zTab);
sqliteIdListDelete(pColumn);
}
@@ -530,7 +544,7 @@ insert_cleanup:
** When this routine is called, the stack contains (from bottom to top)
** the following values:
**
** 1. The recno of the row to be updated before it is updated. This
** 1. The recno of the row to be updated before the update. This
** value is omitted unless we are doing an UPDATE that involves a
** change to the record number.
**
@@ -635,16 +649,16 @@ void sqliteGenerateConstraintChecks(
*/
for(i=0; i<nCol; i++){
if( i==pTab->iPKey ){
/* Fix me: Make sure the INTEGER PRIMARY KEY is not NULL. */
continue;
}
onError = pTab->aCol[i].notNull;
if( onError==OE_None ) continue;
if( overrideError!=OE_Default ){
onError = overrideError;
}else if( onError==OE_Default ){
}else if( pParse->db->onError!=OE_Default ){
onError = pParse->db->onError;
if( onError==OE_Default ) onError = OE_Abort;
}else if( onError==OE_Default ){
onError = OE_Abort;
}
if( onError==OE_Replace && pTab->aCol[i].zDflt==0 ){
onError = OE_Abort;
@@ -655,7 +669,11 @@ void sqliteGenerateConstraintChecks(
case OE_Rollback:
case OE_Abort:
case OE_Fail: {
char *zMsg = 0;
sqliteVdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, onError);
sqliteSetString(&zMsg, pTab->zName, ".", pTab->aCol[i].zName,
" may not be NULL", (char*)0);
sqliteVdbeChangeP3(v, -1, zMsg, P3_DYNAMIC);
break;
}
case OE_Ignore: {
@@ -664,8 +682,7 @@ void sqliteGenerateConstraintChecks(
break;
}
case OE_Replace: {
sqliteVdbeAddOp(v, OP_String, 0, 0);
sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zDflt, P3_STATIC);
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
sqliteVdbeAddOp(v, OP_Push, nCol-i, 0);
break;
}
@@ -681,57 +698,71 @@ void sqliteGenerateConstraintChecks(
/* If we have an INTEGER PRIMARY KEY, make sure the primary key
** of the new record does not previously exist. Except, if this
** is an UPDATE and the primary key is not changing, that is OK.
** Also, if the conflict resolution policy is REPLACE, then we
** can skip this test.
*/
if( (recnoChng || !isUpdate) && pTab->iPKey>=0 ){
if( recnoChng ){
onError = pTab->keyConf;
if( overrideError!=OE_Default ){
onError = overrideError;
}else if( onError==OE_Default ){
}else if( pParse->db->onError!=OE_Default ){
onError = pParse->db->onError;
if( onError==OE_Default ) onError = OE_Abort;
}else if( onError==OE_Default ){
onError = OE_Abort;
}
if( onError!=OE_Replace ){
if( isUpdate ){
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
jumpInst1 = sqliteVdbeAddOp(v, OP_Eq, 0, 0);
if( isUpdate ){
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
jumpInst1 = sqliteVdbeAddOp(v, OP_Eq, 0, 0);
}
sqliteVdbeAddOp(v, OP_Dup, nCol, 1);
jumpInst2 = sqliteVdbeAddOp(v, OP_NotExists, base, 0);
switch( onError ){
default: {
onError = OE_Abort;
/* Fall thru into the next case */
}
sqliteVdbeAddOp(v, OP_Dup, nCol, 1);
jumpInst2 = sqliteVdbeAddOp(v, OP_NotExists, base, 0);
switch( onError ){
case OE_Rollback:
case OE_Abort:
case OE_Fail: {
sqliteVdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, onError);
break;
case OE_Rollback:
case OE_Abort:
case OE_Fail: {
sqliteVdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError,
"PRIMARY KEY must be unique", P3_STATIC);
break;
}
case OE_Replace: {
sqliteGenerateRowIndexDelete(pParse->db, v, pTab, base, 0);
if( isUpdate ){
sqliteVdbeAddOp(v, OP_Dup, nCol+hasTwoRecnos, 1);
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
}
case OE_Ignore: {
sqliteVdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
sqliteVdbeAddOp(v, OP_Goto, 0, ignoreDest);
break;
}
default: assert(0);
seenReplace = 1;
break;
}
contAddr = sqliteVdbeCurrentAddr(v);
sqliteVdbeChangeP2(v, jumpInst2, contAddr);
if( isUpdate ){
sqliteVdbeChangeP2(v, jumpInst1, contAddr);
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
case OE_Ignore: {
assert( seenReplace==0 );
sqliteVdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
sqliteVdbeAddOp(v, OP_Goto, 0, ignoreDest);
break;
}
}
contAddr = sqliteVdbeCurrentAddr(v);
sqliteVdbeChangeP2(v, jumpInst2, contAddr);
if( isUpdate ){
sqliteVdbeChangeP2(v, jumpInst1, contAddr);
sqliteVdbeAddOp(v, OP_Dup, nCol+1, 1);
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
}
}
/* Test all UNIQUE constraints by creating entries for each UNIQUE
** index and making sure that duplicate entries do not already exist.
** Add the new records to the indices as we go.
*/
extra = 0;
for(extra=(-1), iCur=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, iCur++){
if( aIdxUsed && aIdxUsed[iCur]==0 ) continue;
extra++;
extra = -1;
for(iCur=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, iCur++){
if( aIdxUsed && aIdxUsed[iCur]==0 ) continue; /* Skip unused indices */
extra++;
/* Create a key for accessing the index entry */
sqliteVdbeAddOp(v, OP_Dup, nCol+extra, 1);
for(i=0; i<pIdx->nColumn; i++){
int idx = pIdx->aiColumn[i];
@@ -743,21 +774,55 @@ void sqliteGenerateConstraintChecks(
}
jumpInst1 = sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
if( pParse->db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
/* Find out what action to take in case there is an indexing conflict */
onError = pIdx->onError;
if( onError==OE_None ) continue;
if( onError==OE_None ) continue; /* pIdx is not a UNIQUE index */
if( overrideError!=OE_Default ){
onError = overrideError;
}else if( onError==OE_Default ){
}else if( pParse->db->onError!=OE_Default ){
onError = pParse->db->onError;
if( onError==OE_Default ) onError = OE_Abort;
}else if( onError==OE_Default ){
onError = OE_Abort;
}
if( seenReplace ){
if( onError==OE_Ignore ) onError = OE_Replace;
else if( onError==OE_Fail ) onError = OE_Abort;
}
/* Check to see if the new index entry will be unique */
sqliteVdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRecnos, 1);
jumpInst2 = sqliteVdbeAddOp(v, OP_IsUnique, base+iCur+1, 0);
/* Generate code that executes if the new index entry is not unique */
switch( onError ){
case OE_Rollback:
case OE_Abort:
case OE_Fail: {
sqliteVdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, onError);
int j, n1, n2;
char zErrMsg[200];
strcpy(zErrMsg, pIdx->nColumn>1 ? "columns " : "column ");
n1 = strlen(zErrMsg);
for(j=0; j<pIdx->nColumn && n1<sizeof(zErrMsg)-30; j++){
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
n2 = strlen(zCol);
if( j>0 ){
strcpy(&zErrMsg[n1], ", ");
n1 += 2;
}
if( n1+n2>sizeof(zErrMsg)-30 ){
strcpy(&zErrMsg[n1], "...");
n1 += 3;
break;
}else{
strcpy(&zErrMsg[n1], zCol);
n1 += n2;
}
}
strcpy(&zErrMsg[n1],
pIdx->nColumn>1 ? " are not unique" : " is not unique");
sqliteVdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError, zErrMsg, 0);
break;
}
case OE_Ignore: {
@@ -801,7 +866,8 @@ void sqliteCompleteInsertion(
int base, /* Index of a read/write cursor pointing at pTab */
char *aIdxUsed, /* Which indices are used. NULL means all are used */
int recnoChng, /* True if the record number will change */
int isUpdate /* True for UPDATE, False for INSERT */
int isUpdate, /* True for UPDATE, False for INSERT */
int newIdx /* Index of NEW table for triggers. -1 if none */
){
int i;
Vdbe *v;
@@ -817,8 +883,37 @@ void sqliteCompleteInsertion(
sqliteVdbeAddOp(v, OP_IdxPut, base+i+1, 0);
}
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
sqliteVdbeAddOp(v, OP_PutIntKey, base, pParse->trigStack?0:1);
if( newIdx>=0 ){
sqliteVdbeAddOp(v, OP_Dup, 1, 0);
sqliteVdbeAddOp(v, OP_Dup, 1, 0);
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
}
sqliteVdbeAddOp(v, OP_PutIntKey, base,
(pParse->trigStack?0:OPFLAG_NCHANGE) |
(isUpdate?0:OPFLAG_LASTROWID) | OPFLAG_CSCHANGE);
if( isUpdate && recnoChng ){
sqliteVdbeAddOp(v, OP_Pop, 1, 0);
}
}
/*
** Generate code that will open write cursors for a table and for all
** indices of that table. The "base" parameter is the cursor number used
** for the table. Indices are opened on subsequent cursors.
**
** Return the total number of cursors opened. This is always at least
** 1 (for the main table) plus more for each cursor.
*/
int sqliteOpenTableAndIndices(Parse *pParse, Table *pTab, int base){
int i;
Index *pIdx;
Vdbe *v = sqliteGetVdbe(pParse);
assert( v!=0 );
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqliteVdbeOp3(v, OP_OpenWrite, base, pTab->tnum, pTab->zName, P3_STATIC);
for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
sqliteVdbeOp3(v, OP_OpenWrite, i+base, pIdx->tnum, pIdx->zName, P3_STATIC);
}
return i;
}
+569 -323
View File
File diff suppressed because it is too large Load Diff
+1104 -164
View File
File diff suppressed because it is too large Load Diff
+114 -13
View File
@@ -17,32 +17,99 @@
#ifndef _SQLITE_OS_H_
#define _SQLITE_OS_H_
/*
** Helpful hint: To get this to compile on HP/UX, add -D_INCLUDE_POSIX_SOURCE
** to the compiler command line.
*/
/*
** These #defines should enable >2GB file support on Posix if the
** underlying operating system supports it. If the OS lacks
** large file support, or if the OS is windows, these should be no-ops.
**
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
** on the compiler command line. This is necessary if you are compiling
** on a recent machine (ex: RedHat 7.2) but you want your code to work
** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2
** without this option, LFS is enable. But LFS does not exist in the kernel
** in RedHat 6.0, so the code won't work. Hence, for maximum binary
** portability you should omit LFS.
**
** Similar is true for MacOS. LFS is only supported on MacOS 9 and later.
*/
#ifndef SQLITE_DISABLE_LFS
# define _LARGE_FILE 1
# ifndef _FILE_OFFSET_BITS
# define _FILE_OFFSET_BITS 64
# endif
# define _LARGEFILE_SOURCE 1
#endif
/*
** Temporary files are named starting with this prefix followed by 16 random
** alphanumeric characters, and no file extension. They are stored in the
** OS's standard temporary file directory, and are deleted prior to exit.
** If sqlite is being embedded in another program, you may wish to change the
** prefix to reflect your program's name, so that if your program exits
** prematurely, old temporary files can be easily identified. This can be done
** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
*/
#ifndef TEMP_FILE_PREFIX
# define TEMP_FILE_PREFIX "sqlite_"
#endif
/*
** Figure out if we are dealing with Unix, Windows or MacOS.
**
** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
** The MacOS build is designed to use CodeWarrior (tested with v8)
*/
#ifndef OS_UNIX
# ifndef OS_WIN
# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
# define OS_WIN 1
# define OS_UNIX 0
# ifndef OS_MAC
# if defined(__MACOS__)
# define OS_MAC 1
# define OS_WIN 0
# define OS_UNIX 0
# elif defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
# define OS_MAC 0
# define OS_WIN 1
# define OS_UNIX 0
# else
# define OS_MAC 0
# define OS_WIN 0
# define OS_UNIX 1
# endif
# else
# define OS_WIN 0
# define OS_UNIX 1
# define OS_UNIX 0
# endif
# else
# define OS_MAC 0
# define OS_UNIX 0
# endif
#endif
#ifndef OS_WIN
# define OS_WIN 0
#else
# define OS_MAC 0
# ifndef OS_WIN
# define OS_WIN 0
# endif
#endif
/*
** A handle for an open file is stored in an OsFile object.
*/
#if OS_UNIX
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
# include <unistd.h>
typedef struct OsFile OsFile;
struct OsFile {
struct lockInfo *pLock; /* Information about locks on this inode */
int fd; /* The file descriptor */
int locked; /* True if this user holds the lock */
struct openCnt *pOpen; /* Info about all open fd's on this inode */
struct lockInfo *pLock; /* Info about locks on this inode */
int fd; /* The file descriptor */
int locked; /* True if this instance holds the lock */
int dirfd; /* File descriptor for the directory */
};
# define SQLITE_TEMPNAME_SIZE 200
# if defined(HAVE_USLEEP) && HAVE_USLEEP
@@ -60,30 +127,64 @@
HANDLE h; /* Handle for accessing the file */
int locked; /* 0: unlocked, <0: write lock, >0: read lock */
};
# if defined(_MSC_VER) || defined(__BORLANDC__)
typedef __int64 off_t;
# else
# if !defined(_CYGWIN_TYPES_H)
typedef long long off_t;
# if defined(__MINGW32__)
# define _OFF_T_
# endif
# endif
# endif
# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
# define SQLITE_MIN_SLEEP_MS 1
#endif
#if OS_MAC
# include <unistd.h>
# include <Files.h>
typedef struct OsFile OsFile;
struct OsFile {
SInt16 refNum; /* Data fork/file reference number */
SInt16 refNumRF; /* Resource fork reference number (for locking) */
int locked; /* 0: unlocked, <0: write lock, >0: read lock */
int delOnClose; /* True if file is to be deleted on close */
char *pathToDel; /* Name of file to delete on close */
};
# ifdef _LARGE_FILE
typedef SInt64 off_t;
# else
typedef SInt32 off_t;
# endif
# define SQLITE_TEMPNAME_SIZE _MAX_PATH
# define SQLITE_MIN_SLEEP_MS 17
#endif
int sqliteOsDelete(const char*);
int sqliteOsFileExists(const char*);
int sqliteOsFileRename(const char*, const char*);
int sqliteOsOpenReadWrite(const char*, OsFile*, int*);
int sqliteOsOpenExclusive(const char*, OsFile*, int);
int sqliteOsOpenReadOnly(const char*, OsFile*);
int sqliteOsOpenDirectory(const char*, OsFile*);
int sqliteOsTempFileName(char*);
int sqliteOsClose(OsFile*);
int sqliteOsRead(OsFile*, void*, int amt);
int sqliteOsWrite(OsFile*, const void*, int amt);
int sqliteOsSeek(OsFile*, int offset);
int sqliteOsSeek(OsFile*, off_t offset);
int sqliteOsSync(OsFile*);
int sqliteOsTruncate(OsFile*, int size);
int sqliteOsFileSize(OsFile*, int *pSize);
int sqliteOsTruncate(OsFile*, off_t size);
int sqliteOsFileSize(OsFile*, off_t *pSize);
int sqliteOsReadLock(OsFile*);
int sqliteOsWriteLock(OsFile*);
int sqliteOsUnlock(OsFile*);
int sqliteOsRandomSeed(char*);
int sqliteOsSleep(int ms);
int sqliteOsCurrentTime(double*);
void sqliteOsEnterMutex(void);
void sqliteOsLeaveMutex(void);
char *sqliteOsFullPathname(const char*);
+927 -265
View File
File diff suppressed because it is too large Load Diff
+37 -7
View File
@@ -13,18 +13,41 @@
** subsystem. The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
**
** @(#) $Id: pager.h,v 1.17 2002/08/12 12:29:57 drh Exp $
** @(#) $Id: pager.h,v 1.26 2004/02/11 02:18:07 drh Exp $
*/
/*
** The size of one page
**
** You can change this value to another (reasonable) power of two
** such as 512, 2048, 4096, or 8192 and things will still work. But
** experiments show that a page size of 1024 gives the best speed.
** (The speed differences are minimal.)
** You can change this value to another (reasonable) value you want.
** It need not be a power of two, though the interface to the disk
** will likely be faster if it is.
**
** Experiments show that a page size of 1024 gives the best speed
** for common usages. The speed differences for different sizes
** such as 512, 2048, 4096, an so forth, is minimal. Note, however,
** that changing the page size results in a completely imcompatible
** file format.
*/
#ifndef SQLITE_PAGE_SIZE
#define SQLITE_PAGE_SIZE 1024
#endif
/*
** Number of extra bytes of data allocated at the end of each page and
** stored on disk but not used by the higher level btree layer. Changing
** this value results in a completely incompatible file format.
*/
#ifndef SQLITE_PAGE_RESERVE
#define SQLITE_PAGE_RESERVE 0
#endif
/*
** The total number of usable bytes stored on disk for each page.
** The usable bytes come at the beginning of the page and the reserve
** bytes come at the end.
*/
#define SQLITE_USABLE_SIZE (SQLITE_PAGE_SIZE-SQLITE_PAGE_RESERVE)
/*
** Maximum number of pages in one database. (This is a limitation of
@@ -47,7 +70,8 @@ typedef struct Pager Pager;
** See source code comments for a detailed description of the following
** routines:
*/
int sqlitepager_open(Pager **ppPager,const char *zFilename,int nPage,int nEx);
int sqlitepager_open(Pager **ppPager, const char *zFilename,
int nPage, int nExtra, int useJournal);
void sqlitepager_set_destructor(Pager*, void(*)(void*));
void sqlitepager_set_cachesize(Pager*, int);
int sqlitepager_close(Pager *pPager);
@@ -58,7 +82,9 @@ int sqlitepager_unref(void*);
Pgno sqlitepager_pagenumber(void*);
int sqlitepager_write(void*);
int sqlitepager_iswriteable(void*);
int sqlitepager_overwrite(Pager *pPager, Pgno pgno, void*);
int sqlitepager_pagecount(Pager*);
int sqlitepager_truncate(Pager*,Pgno);
int sqlitepager_begin(void*);
int sqlitepager_commit(Pager*);
int sqlitepager_rollback(Pager*);
@@ -69,9 +95,13 @@ int sqlitepager_ckpt_rollback(Pager*);
void sqlitepager_dont_rollback(void*);
void sqlitepager_dont_write(Pager*, Pgno);
int *sqlitepager_stats(Pager*);
void sqlitepager_set_safety_level(Pager*,int);
const char *sqlitepager_filename(Pager*);
int sqlitepager_rename(Pager*, const char *zNewName);
void sqlitepager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);
#ifdef SQLITE_TEST
void sqlitepager_refdump(Pager*);
int pager_refinfo_enable;
int pager_old_format;
int journal_format;
#endif
+172 -92
View File
@@ -14,15 +14,20 @@
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.83 2002/08/31 18:53:07 drh Exp $
** @(#) $Id: parse.y,v 1.112 2004/02/22 18:40:57 drh Exp $
*/
%token_prefix TK_
%token_type {Token}
%default_type {Token}
%extra_argument {Parse *pParse}
%syntax_error {
sqliteSetString(&pParse->zErrMsg,"syntax error",0);
pParse->sErrToken = TOKEN;
if( pParse->zErrMsg==0 ){
if( TOKEN.z[0] ){
sqliteErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
}else{
sqliteErrorMsg(pParse, "incomplete SQL statement");
}
}
}
%name sqliteParser
%include {
@@ -48,7 +53,8 @@ struct LimitVal {
** Then the "b" IdList records the list "a,b,c".
*/
struct TrigEvent { int a; IdList * b; };
}
} // end %include
// These are extra tokens used by the lexer but never seen by the
// parser. We put them in a rule so that the parser generator will
@@ -57,15 +63,13 @@ struct TrigEvent { int a; IdList * b; };
%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
COLUMN AGG_FUNCTION.
// Input is zero or more commands.
// Input is a single SQL command
input ::= cmdlist.
// A list of commands is zero or more commands
//
cmdlist ::= ecmd.
cmdlist ::= cmdlist ecmd.
ecmd ::= explain cmd SEMI. {sqliteExec(pParse);}
cmdlist ::= ecmd.
ecmd ::= explain cmdx SEMI.
ecmd ::= SEMI.
cmdx ::= cmd. { sqliteExec(pParse); }
explain ::= EXPLAIN. { sqliteBeginParse(pParse, 1); }
explain ::= . { sqliteBeginParse(pParse, 0); }
@@ -84,11 +88,11 @@ cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);}
//
cmd ::= create_table create_table_args.
create_table ::= CREATE(X) temp(T) TABLE nm(Y). {
sqliteStartTable(pParse,&X,&Y,T);
sqliteStartTable(pParse,&X,&Y,T,0);
}
%type temp {int}
temp(A) ::= TEMP. {A = pParse->isTemp || !pParse->initFlag;}
temp(A) ::= . {A = pParse->isTemp;}
temp(A) ::= TEMP. {A = 1;}
temp(A) ::= . {A = 0;}
create_table_args ::= LP columnlist conslist_opt RP(X). {
sqliteEndTable(pParse,&X,0);
}
@@ -116,13 +120,29 @@ id(A) ::= ID(X). {A = X;}
// fallback to ID if they will not parse as their original value.
// This obviates the need for the "id" nonterminal.
//
%fallback ID
ABORT AFTER ASC BEFORE BEGIN CASCADE CLUSTER CONFLICT
COPY DEFERRED DELIMITERS DESC EACH END EXPLAIN FAIL FOR
IGNORE IMMEDIATE INITIALLY INSTEAD MATCH KEY
%fallback ID
ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT
COPY DATABASE DEFERRED DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR
GLOB IGNORE IMMEDIATE INITIALLY INSTEAD LIKE MATCH KEY
OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT
TEMP TRIGGER VACUUM VIEW.
// Define operator precedence early so that this is the first occurance
// of the operator tokens in the grammer. Keeping the operators together
// causes them to be assigned integer values that are close together,
// which keeps parser tables smaller.
//
%left OR.
%left AND.
%right NOT.
%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
%left GT GE LT LE.
%left BITAND BITOR LSHIFT RSHIFT.
%left PLUS MINUS.
%left STAR SLASH REM.
%left CONCAT.
%right UMINUS UPLUS BITNOT.
// And "ids" is an identifer-or-string.
//
%type ids {Token}
@@ -144,9 +164,10 @@ type ::= typename(X) LP signed COMMA signed RP(Y).
%type typename {Token}
typename(A) ::= ids(X). {A = X;}
typename(A) ::= typename(X) ids. {A = X;}
signed ::= INTEGER.
signed ::= PLUS INTEGER.
signed ::= MINUS INTEGER.
%type signed {int}
signed(A) ::= INTEGER(X). { A = atoi(X.z); }
signed(A) ::= PLUS INTEGER(X). { A = atoi(X.z); }
signed(A) ::= MINUS INTEGER(X). { A = -atoi(X.z); }
carglist ::= carglist carg.
carglist ::= .
carg ::= CONSTRAINT nm ccons.
@@ -167,13 +188,13 @@ carg ::= DEFAULT NULL.
ccons ::= NULL onconf.
ccons ::= NOT NULL onconf(R). {sqliteAddNotNull(pParse, R);}
ccons ::= PRIMARY KEY sortorder onconf(R). {sqliteAddPrimaryKey(pParse,0,R);}
ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);}
ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);}
ccons ::= CHECK LP expr RP onconf.
ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R).
{sqliteCreateForeignKey(pParse,0,&T,TA,R);}
ccons ::= defer_subclause(D). {sqliteDeferForeignKey(pParse,D);}
ccons ::= COLLATE id(C). {
sqliteAddCollateType(pParse, sqliteCollateType(pParse, &C));
sqliteAddCollateType(pParse, sqliteCollateType(C.z, C.n));
}
// The next group of rules parses the arguments to a REFERENCES clause
@@ -344,8 +365,8 @@ 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) as(Z) on_opt(N) using_opt(U). {
A = sqliteSrcListAppend(X,&Y);
seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) on_opt(N) using_opt(U). {
A = sqliteSrcListAppend(X,&Y,&D);
if( Z.n ) sqliteSrcListAddAlias(A,&Z);
if( N ){
if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
@@ -356,8 +377,9 @@ seltablist(A) ::= stl_prefix(X) nm(Y) as(Z) on_opt(N) using_opt(U). {
else { sqliteIdListDelete(U); }
}
}
seltablist(A) ::= stl_prefix(X) LP select(S) RP as(Z) on_opt(N) using_opt(U). {
A = sqliteSrcListAppend(X,0);
seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP
as(Z) on_opt(N) using_opt(U). {
A = sqliteSrcListAppend(X,0,0);
A->a[A->nSrc-1].pSelect = S;
if( Z.n ) sqliteSrcListAddAlias(A,&Z);
if( N ){
@@ -370,6 +392,21 @@ seltablist(A) ::= stl_prefix(X) LP select(S) RP as(Z) on_opt(N) using_opt(U). {
}
}
// A seltablist_paren nonterminal represents anything in a FROM that
// is contained inside parentheses. This can be either a subquery or
// a grouping of table and subqueries.
//
%type seltablist_paren {Select*}
%destructor seltablist_paren {sqliteSelectDelete($$);}
seltablist_paren(A) ::= select(S). {A = S;}
seltablist_paren(A) ::= seltablist(F). {
A = sqliteSelectNew(0,F,0,0,0,0,0,-1,0);
}
%type dbnm {Token}
dbnm(A) ::= . {A.z=0; A.n=0;}
dbnm(A) ::= DOT nm(X). {A = X;}
%type joinop {int}
%type joinop2 {int}
joinop(X) ::= COMMA. { X = JT_INNER; }
@@ -416,7 +453,7 @@ sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;}
sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;}
sortorder(A) ::= . {A = SQLITE_SO_ASC;}
collate(C) ::= . {C = SQLITE_SO_UNK;}
collate(C) ::= COLLATE id(X). {C = sqliteCollateType(pParse, &X);}
collate(C) ::= COLLATE id(X). {C = sqliteCollateType(X.z, X.n);}
%type groupby_opt {ExprList*}
%destructor groupby_opt {sqliteExprListDelete($$);}
@@ -429,17 +466,18 @@ having_opt(A) ::= . {A = 0;}
having_opt(A) ::= HAVING expr(X). {A = X;}
%type limit_opt {struct LimitVal}
limit_opt(A) ::= . {A.limit = -1; A.offset = 0;}
limit_opt(A) ::= LIMIT INTEGER(X). {A.limit = atoi(X.z); A.offset = 0;}
limit_opt(A) ::= LIMIT INTEGER(X) limit_sep INTEGER(Y).
{A.limit = atoi(X.z); A.offset = atoi(Y.z);}
limit_sep ::= OFFSET.
limit_sep ::= COMMA.
limit_opt(A) ::= . {A.limit = -1; A.offset = 0;}
limit_opt(A) ::= LIMIT signed(X). {A.limit = X; A.offset = 0;}
limit_opt(A) ::= LIMIT signed(X) OFFSET signed(Y).
{A.limit = X; A.offset = Y;}
limit_opt(A) ::= LIMIT signed(X) COMMA signed(Y).
{A.limit = Y; A.offset = X;}
/////////////////////////// The DELETE statement /////////////////////////////
//
cmd ::= DELETE FROM nm(X) where_opt(Y).
{sqliteDeleteFrom(pParse, &X, Y);}
cmd ::= DELETE FROM nm(X) dbnm(D) where_opt(Y). {
sqliteDeleteFrom(pParse, sqliteSrcListAppend(0,&X,&D), Y);
}
%type where_opt {Expr*}
%destructor where_opt {sqliteExprDelete($$);}
@@ -452,8 +490,8 @@ where_opt(A) ::= WHERE expr(X). {A = X;}
////////////////////////// The UPDATE command ////////////////////////////////
//
cmd ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z).
{sqliteUpdate(pParse,&X,Y,Z,R);}
cmd ::= UPDATE orconf(R) nm(X) dbnm(D) SET setlist(Y) where_opt(Z).
{sqliteUpdate(pParse,sqliteSrcListAppend(0,&X,&D),Y,Z,R);}
setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y).
{A = sqliteExprListAppend(Z,Y,&X);}
@@ -461,10 +499,11 @@ setlist(A) ::= nm(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
////////////////////////// The INSERT command /////////////////////////////////
//
cmd ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
{sqliteInsert(pParse, &X, Y, 0, F, R);}
cmd ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S).
{sqliteInsert(pParse, &X, 0, S, F, R);}
cmd ::= insert_cmd(R) INTO nm(X) dbnm(D) inscollist_opt(F)
VALUES LP itemlist(Y) RP.
{sqliteInsert(pParse, sqliteSrcListAppend(0,&X,&D), Y, 0, F, R);}
cmd ::= insert_cmd(R) INTO nm(X) dbnm(D) inscollist_opt(F) select(S).
{sqliteInsert(pParse, sqliteSrcListAppend(0,&X,&D), 0, S, F, R);}
%type insert_cmd {int}
insert_cmd(A) ::= INSERT orconf(R). {A = R;}
@@ -489,21 +528,11 @@ inscollist(A) ::= nm(Y). {A = sqliteIdListAppend(0,&Y);}
/////////////////////////// Expression Processing /////////////////////////////
//
%left OR.
%left AND.
%right NOT.
%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
%left GT GE LT LE.
%left BITAND BITOR LSHIFT RSHIFT.
%left PLUS MINUS.
%left STAR SLASH REM.
%left CONCAT.
%right UMINUS UPLUS BITNOT.
%type expr {Expr*}
%destructor expr {sqliteExprDelete($$);}
expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E); }
expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
expr(A) ::= ID(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
expr(A) ::= JOIN_KW(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
@@ -512,18 +541,27 @@ expr(A) ::= nm(X) DOT nm(Y). {
Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
A = sqliteExpr(TK_DOT, temp1, temp2, 0);
}
expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
Expr *temp3 = sqliteExpr(TK_ID, 0, 0, &Z);
Expr *temp4 = sqliteExpr(TK_DOT, temp2, temp3, 0);
A = sqliteExpr(TK_DOT, temp1, temp4, 0);
}
expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
expr(A) ::= VARIABLE(X). {
A = sqliteExpr(TK_VARIABLE, 0, 0, &X);
if( A ) A->iTable = ++pParse->nVar;
}
expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
A = sqliteExprFunction(Y, &X);
sqliteExprSpan(A,&X,&E);
if( A ) A->token.base = 1;
}
expr(A) ::= ID(X) LP STAR RP(E). {
A = sqliteExprFunction(0, &X);
sqliteExprSpan(A,&X,&E);
if( A ) A->token.base = 1;
}
expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
@@ -542,7 +580,7 @@ expr(A) ::= expr(X) likeop(OP) expr(Y). [LIKE] {
pList = sqliteExprListAppend(pList, X, 0);
A = sqliteExprFunction(pList, 0);
if( A ) A->op = OP;
sqliteExprSpan(A, &X->token, &Y->token);
sqliteExprSpan(A, &X->span, &Y->span);
}
expr(A) ::= expr(X) NOT likeop(OP) expr(Y). [LIKE] {
ExprList *pList = sqliteExprListAppend(0, Y, 0);
@@ -550,7 +588,7 @@ expr(A) ::= expr(X) NOT likeop(OP) expr(Y). [LIKE] {
A = sqliteExprFunction(pList, 0);
if( A ) A->op = OP;
A = sqliteExpr(TK_NOT, A, 0, 0);
sqliteExprSpan(A,&X->token,&Y->token);
sqliteExprSpan(A,&X->span,&Y->span);
}
%type likeop {int}
likeop(A) ::= LIKE. {A = TK_LIKE;}
@@ -563,39 +601,39 @@ expr(A) ::= expr(X) REM expr(Y). {A = sqliteExpr(TK_REM, X, Y, 0);}
expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
expr(A) ::= expr(X) ISNULL(E). {
A = sqliteExpr(TK_ISNULL, X, 0, 0);
sqliteExprSpan(A,&X->token,&E);
sqliteExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) IS NULL(E). {
A = sqliteExpr(TK_ISNULL, X, 0, 0);
sqliteExprSpan(A,&X->token,&E);
sqliteExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) NOTNULL(E). {
A = sqliteExpr(TK_NOTNULL, X, 0, 0);
sqliteExprSpan(A,&X->token,&E);
sqliteExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) NOT NULL(E). {
A = sqliteExpr(TK_NOTNULL, X, 0, 0);
sqliteExprSpan(A,&X->token,&E);
sqliteExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) IS NOT NULL(E). {
A = sqliteExpr(TK_NOTNULL, X, 0, 0);
sqliteExprSpan(A,&X->token,&E);
sqliteExprSpan(A,&X->span,&E);
}
expr(A) ::= NOT(B) expr(X). {
A = sqliteExpr(TK_NOT, X, 0, 0);
sqliteExprSpan(A,&B,&X->token);
sqliteExprSpan(A,&B,&X->span);
}
expr(A) ::= BITNOT(B) expr(X). {
A = sqliteExpr(TK_BITNOT, X, 0, 0);
sqliteExprSpan(A,&B,&X->token);
sqliteExprSpan(A,&B,&X->span);
}
expr(A) ::= MINUS(B) expr(X). [UMINUS] {
A = sqliteExpr(TK_UMINUS, X, 0, 0);
sqliteExprSpan(A,&B,&X->token);
sqliteExprSpan(A,&B,&X->span);
}
expr(A) ::= PLUS(B) expr(X). [UPLUS] {
A = sqliteExpr(TK_UPLUS, X, 0, 0);
sqliteExprSpan(A,&B,&X->token);
sqliteExprSpan(A,&B,&X->span);
}
expr(A) ::= LP(B) select(X) RP(E). {
A = sqliteExpr(TK_SELECT, 0, 0, 0);
@@ -607,7 +645,7 @@ expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
pList = sqliteExprListAppend(pList, Y, 0);
A = sqliteExpr(TK_BETWEEN, W, 0, 0);
if( A ) A->pList = pList;
sqliteExprSpan(A,&W->token,&Y->token);
sqliteExprSpan(A,&W->span,&Y->span);
}
expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
ExprList *pList = sqliteExprListAppend(0, X, 0);
@@ -615,30 +653,44 @@ expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
A = sqliteExpr(TK_BETWEEN, W, 0, 0);
if( A ) A->pList = pList;
A = sqliteExpr(TK_NOT, A, 0, 0);
sqliteExprSpan(A,&W->token,&Y->token);
sqliteExprSpan(A,&W->span,&Y->span);
}
expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
A = sqliteExpr(TK_IN, X, 0, 0);
if( A ) A->pList = Y;
sqliteExprSpan(A,&X->token,&E);
sqliteExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) IN LP select(Y) RP(E). {
A = sqliteExpr(TK_IN, X, 0, 0);
if( A ) A->pSelect = Y;
sqliteExprSpan(A,&X->token,&E);
sqliteExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
A = sqliteExpr(TK_IN, X, 0, 0);
if( A ) A->pList = Y;
A = sqliteExpr(TK_NOT, A, 0, 0);
sqliteExprSpan(A,&X->token,&E);
sqliteExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
A = sqliteExpr(TK_IN, X, 0, 0);
if( A ) A->pSelect = Y;
A = sqliteExpr(TK_NOT, A, 0, 0);
sqliteExprSpan(A,&X->token,&E);
sqliteExprSpan(A,&X->span,&E);
}
expr(A) ::= expr(X) IN nm(Y) dbnm(D). {
SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D);
A = sqliteExpr(TK_IN, X, 0, 0);
if( A ) A->pSelect = sqliteSelectNew(0,pSrc,0,0,0,0,0,-1,0);
sqliteExprSpan(A,&X->span,D.z?&D:&Y);
}
expr(A) ::= expr(X) NOT IN nm(Y) dbnm(D). {
SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D);
A = sqliteExpr(TK_IN, X, 0, 0);
if( A ) A->pSelect = sqliteSelectNew(0,pSrc,0,0,0,0,0,-1,0);
A = sqliteExpr(TK_NOT, A, 0, 0);
sqliteExprSpan(A,&X->span,D.z?&D:&Y);
}
/* CASE expressions */
expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
@@ -677,10 +729,11 @@ expritem(A) ::= . {A = 0;}
///////////////////////////// The CREATE INDEX command ///////////////////////
//
cmd ::= CREATE(S) uniqueflag(U) INDEX nm(X)
ON nm(Y) LP idxlist(Z) RP(E) onconf(R). {
ON nm(Y) dbnm(D) LP idxlist(Z) RP(E) onconf(R). {
SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D);
if( U!=OE_None ) U = R;
if( U==OE_Default) U = OE_Abort;
sqliteCreateIndex(pParse, &X, &Y, Z, U, &S, &E);
sqliteCreateIndex(pParse, &X, pSrc, Z, U, &S, &E);
}
%type uniqueflag {int}
@@ -697,20 +750,22 @@ idxlist_opt(A) ::= . {A = 0;}
idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;}
idxlist(A) ::= idxlist(X) COMMA idxitem(Y). {A = sqliteIdListAppend(X,&Y);}
idxlist(A) ::= idxitem(Y). {A = sqliteIdListAppend(0,&Y);}
idxitem(A) ::= nm(X). {A = X;}
idxitem(A) ::= nm(X) sortorder. {A = X;}
///////////////////////////// The DROP INDEX command /////////////////////////
//
cmd ::= DROP INDEX nm(X). {sqliteDropIndex(pParse, &X);}
cmd ::= DROP INDEX nm(X) dbnm(Y). {
sqliteDropIndex(pParse, sqliteSrcListAppend(0,&X,&Y));
}
///////////////////////////// The COPY command ///////////////////////////////
//
cmd ::= COPY orconf(R) nm(X) FROM nm(Y) USING DELIMITERS STRING(Z).
{sqliteCopy(pParse,&X,&Y,&Z,R);}
cmd ::= COPY orconf(R) nm(X) FROM nm(Y).
{sqliteCopy(pParse,&X,&Y,0,R);}
cmd ::= COPY orconf(R) nm(X) dbnm(D) FROM nm(Y) USING DELIMITERS STRING(Z).
{sqliteCopy(pParse,sqliteSrcListAppend(0,&X,&D),&Y,&Z,R);}
cmd ::= COPY orconf(R) nm(X) dbnm(D) FROM nm(Y).
{sqliteCopy(pParse,sqliteSrcListAppend(0,&X,&D),&Y,0,R);}
///////////////////////////// The VACUUM command /////////////////////////////
//
@@ -733,13 +788,18 @@ plus_opt ::= PLUS.
plus_opt ::= .
//////////////////////////// The CREATE TRIGGER command /////////////////////
cmd ::= CREATE(A) TRIGGER nm(B) trigger_time(C) trigger_event(D) ON nm(E)
foreach_clause(F) when_clause(G)
BEGIN trigger_cmd_list(S) END(Z). {
cmd ::= CREATE(A) trigger_decl BEGIN trigger_cmd_list(S) END(Z). {
Token all;
all.z = A.z;
all.n = (Z.z - A.z) + Z.n;
sqliteCreateTrigger(pParse, &B, C, D.a, D.b, &E, F, G, S, &all);
sqliteFinishTrigger(pParse, S, &all);
}
trigger_decl ::= temp(T) TRIGGER nm(B) trigger_time(C) trigger_event(D)
ON nm(E) dbnm(DB) foreach_clause(F) when_clause(G). {
SrcList *pTab = sqliteSrcListAppend(0, &E, &DB);
sqliteBeginTrigger(pParse, &B, C, D.a, D.b, pTab, F, G, T);
}
%type trigger_time {int}
@@ -765,21 +825,25 @@ when_clause(A) ::= . { A = 0; }
when_clause(A) ::= WHEN expr(X). { A = X; }
%type trigger_cmd_list {TriggerStep *}
%destructor trigger_cmd_list {sqliteDeleteTriggerStep($$);}
trigger_cmd_list(A) ::= trigger_cmd(X) SEMI trigger_cmd_list(Y). {
X->pNext = Y ; A = X; }
X->pNext = Y;
A = X;
}
trigger_cmd_list(A) ::= . { A = 0; }
%type trigger_cmd {TriggerStep *}
%destructor trigger_cmd {sqliteDeleteTriggerStep($$);}
// UPDATE
trigger_cmd(A) ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z).
{ A = sqliteTriggerUpdateStep(&X, Y, Z, R); }
// INSERT
trigger_cmd(A) ::= INSERT orconf(R) INTO nm(X) inscollist_opt(F)
trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F)
VALUES LP itemlist(Y) RP.
{A = sqliteTriggerInsertStep(&X, F, Y, 0, R);}
trigger_cmd(A) ::= INSERT orconf(R) INTO nm(X) inscollist_opt(F) select(S).
trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S).
{A = sqliteTriggerInsertStep(&X, F, 0, S, R);}
// DELETE
@@ -793,25 +857,41 @@ trigger_cmd(A) ::= select(X). {A = sqliteTriggerSelectStep(X); }
expr(A) ::= RAISE(X) LP IGNORE RP(Y). {
A = sqliteExpr(TK_RAISE, 0, 0, 0);
A->iColumn = OE_Ignore;
/* sqliteExprSpan(A, &X, &Y); */
sqliteExprSpan(A, &X, &Y);
}
expr(A) ::= RAISE(X) LP ROLLBACK COMMA nm(Z) RP(Y). {
A = sqliteExpr(TK_RAISE, 0, 0, &Z);
A->iColumn = OE_Rollback;
/* sqliteExprSpan(A, &X, &Y); */
sqliteExprSpan(A, &X, &Y);
}
expr(A) ::= RAISE(X) LP ABORT COMMA nm(Z) RP(Y). {
A = sqliteExpr(TK_RAISE, 0, 0, &Z);
A->iColumn = OE_Abort;
/* sqliteExprSpan(A, &X, &Y); */
sqliteExprSpan(A, &X, &Y);
}
expr(A) ::= RAISE(X) LP FAIL COMMA nm(Z) RP(Y). {
A = sqliteExpr(TK_RAISE, 0, 0, &Z);
A->iColumn = OE_Fail;
/* sqliteExprSpan(A, &X, &Y); */
sqliteExprSpan(A, &X, &Y);
}
//////////////////////// DROP TRIGGER statement //////////////////////////////
cmd ::= DROP TRIGGER nm(X). {
sqliteDropTrigger(pParse,&X,0);
cmd ::= DROP TRIGGER nm(X) dbnm(D). {
sqliteDropTrigger(pParse,sqliteSrcListAppend(0,&X,&D));
}
//////////////////////// ATTACH DATABASE file AS name /////////////////////////
cmd ::= ATTACH database_kw_opt ids(F) AS nm(D) key_opt(K). {
sqliteAttach(pParse, &F, &D, &K);
}
%type key_opt {Token}
key_opt(A) ::= USING ids(X). { A = X; }
key_opt(A) ::= . { A.z = 0; A.n = 0; }
database_kw_opt ::= DATABASE.
database_kw_opt ::= .
//////////////////////// DETACH DATABASE name /////////////////////////////////
cmd ::= DETACH database_kw_opt nm(D). {
sqliteDetach(pParse, &D);
}
+712
View File
@@ -0,0 +1,712 @@
/*
** 2003 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.19 2004/04/23 17:04:45 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
/*
** Interpret the given string as a boolean value.
*/
static int getBoolean(const char *z){
static char *azTrue[] = { "yes", "on", "true" };
int i;
if( z[0]==0 ) return 0;
if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){
return atoi(z);
}
for(i=0; i<sizeof(azTrue)/sizeof(azTrue[0]); i++){
if( sqliteStrICmp(z,azTrue[i])==0 ) return 1;
}
return 0;
}
/*
** Interpret the given string as a safety level. Return 0 for OFF,
** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
** unrecognized string argument.
**
** Note that the values returned are one less that the values that
** should be passed into sqliteBtreeSetSafetyLevel(). The is done
** to support legacy SQL code. The safety level used to be boolean
** and older scripts may have used numbers 0 for OFF and 1 for ON.
*/
static int getSafetyLevel(char *z){
static const struct {
const char *zWord;
int val;
} aKey[] = {
{ "no", 0 },
{ "off", 0 },
{ "false", 0 },
{ "yes", 1 },
{ "on", 1 },
{ "true", 1 },
{ "full", 2 },
};
int i;
if( z[0]==0 ) return 1;
if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){
return atoi(z);
}
for(i=0; i<sizeof(aKey)/sizeof(aKey[0]); i++){
if( sqliteStrICmp(z,aKey[i].zWord)==0 ) return aKey[i].val;
}
return 1;
}
/*
** Interpret the given string as a temp db location. Return 1 for file
** backed temporary databases, 2 for the Red-Black tree in memory database
** and 0 to use the compile-time default.
*/
static int getTempStore(const char *z){
if( z[0]>='0' && z[0]<='2' ){
return z[0] - '0';
}else if( sqliteStrICmp(z, "file")==0 ){
return 1;
}else if( sqliteStrICmp(z, "memory")==0 ){
return 2;
}else{
return 0;
}
}
/*
** If the TEMP database is open, close it and mark the database schema
** as needing reloading. This must be done when using the TEMP_STORE
** or DEFAULT_TEMP_STORE pragmas.
*/
static int changeTempStorage(Parse *pParse, const char *zStorageType){
int ts = getTempStore(zStorageType);
sqlite *db = pParse->db;
if( db->temp_store==ts ) return SQLITE_OK;
if( db->aDb[1].pBt!=0 ){
if( db->flags & SQLITE_InTrans ){
sqliteErrorMsg(pParse, "temporary storage cannot be changed "
"from within a transaction");
return SQLITE_ERROR;
}
sqliteBtreeClose(db->aDb[1].pBt);
db->aDb[1].pBt = 0;
sqliteResetInternalSchema(db, 0);
}
db->temp_store = ts;
return SQLITE_OK;
}
/*
** Check to see if zRight and zLeft refer to a pragma that queries
** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
** Also, implement the pragma.
*/
static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
static const struct {
const char *zName; /* Name of the pragma */
int mask; /* Mask for the db->flags value */
} aPragma[] = {
{ "vdbe_trace", SQLITE_VdbeTrace },
{ "full_column_names", SQLITE_FullColNames },
{ "short_column_names", SQLITE_ShortColNames },
{ "show_datatypes", SQLITE_ReportTypes },
{ "count_changes", SQLITE_CountRows },
{ "empty_result_callbacks", SQLITE_NullCallback },
};
int i;
for(i=0; i<sizeof(aPragma)/sizeof(aPragma[0]); i++){
if( sqliteStrICmp(zLeft, aPragma[i].zName)==0 ){
sqlite *db = pParse->db;
Vdbe *v;
if( strcmp(zLeft,zRight)==0 && (v = sqliteGetVdbe(pParse))!=0 ){
sqliteVdbeOp3(v, OP_ColumnName, 0, 1, aPragma[i].zName, P3_STATIC);
sqliteVdbeOp3(v, OP_ColumnName, 1, 0, "boolean", P3_STATIC);
sqliteVdbeCode(v, OP_Integer, (db->flags & aPragma[i].mask)!=0, 0,
OP_Callback, 1, 0,
0);
}else if( getBoolean(zRight) ){
db->flags |= aPragma[i].mask;
}else{
db->flags &= ~aPragma[i].mask;
}
return 1;
}
}
return 0;
}
/*
** Process a pragma statement.
**
** Pragmas are of this form:
**
** PRAGMA id = value
**
** The identifier might also be a string. The value is a string, and
** identifier, or a number. If minusFlag is true, then the value is
** a number that was preceded by a minus sign.
*/
void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
char *zLeft = 0;
char *zRight = 0;
sqlite *db = pParse->db;
Vdbe *v = sqliteGetVdbe(pParse);
if( v==0 ) return;
zLeft = sqliteStrNDup(pLeft->z, pLeft->n);
sqliteDequote(zLeft);
if( minusFlag ){
zRight = 0;
sqliteSetNString(&zRight, "-", 1, pRight->z, pRight->n, 0);
}else{
zRight = sqliteStrNDup(pRight->z, pRight->n);
sqliteDequote(zRight);
}
if( sqliteAuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, 0) ){
sqliteFree(zLeft);
sqliteFree(zRight);
return;
}
/*
** PRAGMA default_cache_size
** PRAGMA default_cache_size=N
**
** The first form reports the current persistent setting for the
** page cache size. The value returned is the maximum number of
** pages in the page cache. The second form sets both the current
** page cache size value and the persistent page cache size value
** stored in the database file.
**
** The default cache size is stored in meta-value 2 of page 1 of the
** database file. The cache size is actually the absolute value of
** this memory location. The sign of meta-value 2 determines the
** synchronous setting. A negative value means synchronous is off
** and a positive value means synchronous is on.
*/
if( sqliteStrICmp(zLeft,"default_cache_size")==0 ){
static VdbeOpList getCacheSize[] = {
{ OP_ReadCookie, 0, 2, 0},
{ OP_AbsValue, 0, 0, 0},
{ OP_Dup, 0, 0, 0},
{ OP_Integer, 0, 0, 0},
{ OP_Ne, 0, 6, 0},
{ OP_Integer, 0, 0, 0}, /* 5 */
{ OP_ColumnName, 0, 1, "cache_size"},
{ OP_Callback, 1, 0, 0},
};
int addr;
if( pRight->z==pLeft->z ){
addr = sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
sqliteVdbeChangeP1(v, addr+5, MAX_PAGES);
}else{
int size = atoi(zRight);
if( size<0 ) size = -size;
sqliteBeginWriteOperation(pParse, 0, 0);
sqliteVdbeAddOp(v, OP_Integer, size, 0);
sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2);
addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0);
sqliteVdbeAddOp(v, OP_Ge, 0, addr+3);
sqliteVdbeAddOp(v, OP_Negative, 0, 0);
sqliteVdbeAddOp(v, OP_SetCookie, 0, 2);
sqliteEndWriteOperation(pParse);
db->cache_size = db->cache_size<0 ? -size : size;
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
}
}else
/*
** PRAGMA cache_size
** PRAGMA cache_size=N
**
** The first form reports the current local setting for the
** page cache size. The local setting can be different from
** the persistent cache size value that is stored in the database
** file itself. The value returned is the maximum number of
** pages in the page cache. The second form sets the local
** page cache size value. It does not change the persistent
** cache size stored on the disk so the cache size will revert
** to its default value when the database is closed and reopened.
** N should be a positive integer.
*/
if( sqliteStrICmp(zLeft,"cache_size")==0 ){
static VdbeOpList getCacheSize[] = {
{ OP_ColumnName, 0, 1, "cache_size"},
{ OP_Callback, 1, 0, 0},
};
if( pRight->z==pLeft->z ){
int size = db->cache_size;;
if( size<0 ) size = -size;
sqliteVdbeAddOp(v, OP_Integer, size, 0);
sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
}else{
int size = atoi(zRight);
if( size<0 ) size = -size;
if( db->cache_size<0 ) size = -size;
db->cache_size = size;
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
}
}else
/*
** PRAGMA default_synchronous
** PRAGMA default_synchronous=ON|OFF|NORMAL|FULL
**
** The first form returns the persistent value of the "synchronous" setting
** that is stored in the database. This is the synchronous setting that
** is used whenever the database is opened unless overridden by a separate
** "synchronous" pragma. The second form changes the persistent and the
** local synchronous setting to the value given.
**
** If synchronous is OFF, SQLite does not attempt any fsync() systems calls
** to make sure data is committed to disk. Write operations are very fast,
** but a power failure can leave the database in an inconsistent state.
** If synchronous is ON or NORMAL, SQLite will do an fsync() system call to
** make sure data is being written to disk. The risk of corruption due to
** a power loss in this mode is negligible but non-zero. If synchronous
** is FULL, extra fsync()s occur to reduce the risk of corruption to near
** zero, but with a write performance penalty. The default mode is NORMAL.
*/
if( sqliteStrICmp(zLeft,"default_synchronous")==0 ){
static VdbeOpList getSync[] = {
{ OP_ColumnName, 0, 1, "synchronous"},
{ OP_ReadCookie, 0, 3, 0},
{ OP_Dup, 0, 0, 0},
{ OP_If, 0, 0, 0}, /* 3 */
{ OP_ReadCookie, 0, 2, 0},
{ OP_Integer, 0, 0, 0},
{ OP_Lt, 0, 5, 0},
{ OP_AddImm, 1, 0, 0},
{ OP_Callback, 1, 0, 0},
{ OP_Halt, 0, 0, 0},
{ OP_AddImm, -1, 0, 0}, /* 10 */
{ OP_Callback, 1, 0, 0}
};
if( pRight->z==pLeft->z ){
int addr = sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
sqliteVdbeChangeP2(v, addr+3, addr+10);
}else{
int addr;
int size = db->cache_size;
if( size<0 ) size = -size;
sqliteBeginWriteOperation(pParse, 0, 0);
sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2);
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0);
sqliteVdbeAddOp(v, OP_Ne, 0, addr+3);
sqliteVdbeAddOp(v, OP_AddImm, MAX_PAGES, 0);
sqliteVdbeAddOp(v, OP_AbsValue, 0, 0);
db->safety_level = getSafetyLevel(zRight)+1;
if( db->safety_level==1 ){
sqliteVdbeAddOp(v, OP_Negative, 0, 0);
size = -size;
}
sqliteVdbeAddOp(v, OP_SetCookie, 0, 2);
sqliteVdbeAddOp(v, OP_Integer, db->safety_level, 0);
sqliteVdbeAddOp(v, OP_SetCookie, 0, 3);
sqliteEndWriteOperation(pParse);
db->cache_size = size;
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
}
}else
/*
** PRAGMA synchronous
** PRAGMA synchronous=OFF|ON|NORMAL|FULL
**
** Return or set the local value of the synchronous flag. Changing
** the local value does not make changes to the disk file and the
** default value will be restored the next time the database is
** opened.
*/
if( sqliteStrICmp(zLeft,"synchronous")==0 ){
static VdbeOpList getSync[] = {
{ OP_ColumnName, 0, 1, "synchronous"},
{ OP_Callback, 1, 0, 0},
};
if( pRight->z==pLeft->z ){
sqliteVdbeAddOp(v, OP_Integer, db->safety_level-1, 0);
sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
}else{
int size = db->cache_size;
if( size<0 ) size = -size;
db->safety_level = getSafetyLevel(zRight)+1;
if( db->safety_level==1 ) size = -size;
db->cache_size = size;
sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
}
}else
#ifndef NDEBUG
if( sqliteStrICmp(zLeft, "trigger_overhead_test")==0 ){
if( getBoolean(zRight) ){
always_code_trigger_setup = 1;
}else{
always_code_trigger_setup = 0;
}
}else
#endif
if( flagPragma(pParse, zLeft, zRight) ){
/* The flagPragma() call also generates any necessary code */
}else
if( sqliteStrICmp(zLeft, "table_info")==0 ){
Table *pTab;
pTab = sqliteFindTable(db, zRight, 0);
if( pTab ){
static VdbeOpList tableInfoPreface[] = {
{ OP_ColumnName, 0, 0, "cid"},
{ OP_ColumnName, 1, 0, "name"},
{ OP_ColumnName, 2, 0, "type"},
{ OP_ColumnName, 3, 0, "notnull"},
{ OP_ColumnName, 4, 0, "dflt_value"},
{ OP_ColumnName, 5, 1, "pk"},
};
int i;
sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
sqliteViewGetColumnNames(pParse, pTab);
for(i=0; i<pTab->nCol; i++){
sqliteVdbeAddOp(v, OP_Integer, i, 0);
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zName, 0);
sqliteVdbeOp3(v, OP_String, 0, 0,
pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", 0);
sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0);
sqliteVdbeOp3(v, OP_String, 0, 0,
pTab->aCol[i].zDflt, P3_STATIC);
sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0);
sqliteVdbeAddOp(v, OP_Callback, 6, 0);
}
}
}else
if( sqliteStrICmp(zLeft, "index_info")==0 ){
Index *pIdx;
Table *pTab;
pIdx = sqliteFindIndex(db, zRight, 0);
if( pIdx ){
static VdbeOpList tableInfoPreface[] = {
{ OP_ColumnName, 0, 0, "seqno"},
{ OP_ColumnName, 1, 0, "cid"},
{ OP_ColumnName, 2, 1, "name"},
};
int i;
pTab = pIdx->pTable;
sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
for(i=0; i<pIdx->nColumn; i++){
int cnum = pIdx->aiColumn[i];
sqliteVdbeAddOp(v, OP_Integer, i, 0);
sqliteVdbeAddOp(v, OP_Integer, cnum, 0);
assert( pTab->nCol>cnum );
sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[cnum].zName, 0);
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
}
}
}else
if( sqliteStrICmp(zLeft, "index_list")==0 ){
Index *pIdx;
Table *pTab;
pTab = sqliteFindTable(db, zRight, 0);
if( pTab ){
v = sqliteGetVdbe(pParse);
pIdx = pTab->pIndex;
}
if( pTab && pIdx ){
int i = 0;
static VdbeOpList indexListPreface[] = {
{ OP_ColumnName, 0, 0, "seq"},
{ OP_ColumnName, 1, 0, "name"},
{ OP_ColumnName, 2, 1, "unique"},
};
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
while(pIdx){
sqliteVdbeAddOp(v, OP_Integer, i, 0);
sqliteVdbeOp3(v, OP_String, 0, 0, pIdx->zName, 0);
sqliteVdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
++i;
pIdx = pIdx->pNext;
}
}
}else
if( sqliteStrICmp(zLeft, "foreign_key_list")==0 ){
FKey *pFK;
Table *pTab;
pTab = sqliteFindTable(db, zRight, 0);
if( pTab ){
v = sqliteGetVdbe(pParse);
pFK = pTab->pFKey;
}
if( pTab && pFK ){
int i = 0;
static VdbeOpList indexListPreface[] = {
{ OP_ColumnName, 0, 0, "id"},
{ OP_ColumnName, 1, 0, "seq"},
{ OP_ColumnName, 2, 0, "table"},
{ OP_ColumnName, 3, 0, "from"},
{ OP_ColumnName, 4, 1, "to"},
};
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
while(pFK){
int j;
for(j=0; j<pFK->nCol; j++){
sqliteVdbeAddOp(v, OP_Integer, i, 0);
sqliteVdbeAddOp(v, OP_Integer, j, 0);
sqliteVdbeOp3(v, OP_String, 0, 0, pFK->zTo, 0);
sqliteVdbeOp3(v, OP_String, 0, 0,
pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
sqliteVdbeOp3(v, OP_String, 0, 0, pFK->aCol[j].zCol, 0);
sqliteVdbeAddOp(v, OP_Callback, 5, 0);
}
++i;
pFK = pFK->pNextFrom;
}
}
}else
if( sqliteStrICmp(zLeft, "database_list")==0 ){
int i;
static VdbeOpList indexListPreface[] = {
{ OP_ColumnName, 0, 0, "seq"},
{ OP_ColumnName, 1, 0, "name"},
{ OP_ColumnName, 2, 1, "file"},
};
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
for(i=0; i<db->nDb; i++){
if( db->aDb[i].pBt==0 ) continue;
assert( db->aDb[i].zName!=0 );
sqliteVdbeAddOp(v, OP_Integer, i, 0);
sqliteVdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, 0);
sqliteVdbeOp3(v, OP_String, 0, 0,
sqliteBtreeGetFilename(db->aDb[i].pBt), 0);
sqliteVdbeAddOp(v, OP_Callback, 3, 0);
}
}else
/*
** PRAGMA temp_store
** PRAGMA temp_store = "default"|"memory"|"file"
**
** Return or set the local value of the temp_store flag. Changing
** the local value does not make changes to the disk file and the default
** value will be restored the next time the database is opened.
**
** Note that it is possible for the library compile-time options to
** override this setting
*/
if( sqliteStrICmp(zLeft, "temp_store")==0 ){
static VdbeOpList getTmpDbLoc[] = {
{ OP_ColumnName, 0, 1, "temp_store"},
{ OP_Callback, 1, 0, 0},
};
if( pRight->z==pLeft->z ){
sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0);
sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
}else{
changeTempStorage(pParse, zRight);
}
}else
/*
** PRAGMA default_temp_store
** PRAGMA default_temp_store = "default"|"memory"|"file"
**
** Return or set the value of the persistent temp_store flag. Any
** change does not take effect until the next time the database is
** opened.
**
** Note that it is possible for the library compile-time options to
** override this setting
*/
if( sqliteStrICmp(zLeft, "default_temp_store")==0 ){
static VdbeOpList getTmpDbLoc[] = {
{ OP_ColumnName, 0, 1, "temp_store"},
{ OP_ReadCookie, 0, 5, 0},
{ OP_Callback, 1, 0, 0}};
if( pRight->z==pLeft->z ){
sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
}else{
sqliteBeginWriteOperation(pParse, 0, 0);
sqliteVdbeAddOp(v, OP_Integer, getTempStore(zRight), 0);
sqliteVdbeAddOp(v, OP_SetCookie, 0, 5);
sqliteEndWriteOperation(pParse);
}
}else
#ifndef NDEBUG
if( sqliteStrICmp(zLeft, "parser_trace")==0 ){
extern void sqliteParserTrace(FILE*, char *);
if( getBoolean(zRight) ){
sqliteParserTrace(stdout, "parser: ");
}else{
sqliteParserTrace(0, 0);
}
}else
#endif
if( sqliteStrICmp(zLeft, "integrity_check")==0 ){
int i, j, addr;
/* Code that initializes the integrity check program. Set the
** error count 0
*/
static VdbeOpList initCode[] = {
{ OP_Integer, 0, 0, 0},
{ OP_MemStore, 0, 1, 0},
{ OP_ColumnName, 0, 1, "integrity_check"},
};
/* Code to do an BTree integrity check on a single database file.
*/
static VdbeOpList checkDb[] = {
{ OP_SetInsert, 0, 0, "2"},
{ OP_Integer, 0, 0, 0}, /* 1 */
{ OP_OpenRead, 0, 2, 0},
{ OP_Rewind, 0, 7, 0}, /* 3 */
{ OP_Column, 0, 3, 0}, /* 4 */
{ OP_SetInsert, 0, 0, 0},
{ OP_Next, 0, 4, 0}, /* 6 */
{ OP_IntegrityCk, 0, 0, 0}, /* 7 */
{ OP_Dup, 0, 1, 0},
{ OP_String, 0, 0, "ok"},
{ OP_StrEq, 0, 12, 0}, /* 10 */
{ OP_MemIncr, 0, 0, 0},
{ OP_String, 0, 0, "*** in database "},
{ OP_String, 0, 0, 0}, /* 13 */
{ OP_String, 0, 0, " ***\n"},
{ OP_Pull, 3, 0, 0},
{ OP_Concat, 4, 1, 0},
{ OP_Callback, 1, 0, 0},
};
/* Code that appears at the end of the integrity check. If no error
** messages have been generated, output OK. Otherwise output the
** error message
*/
static VdbeOpList endCode[] = {
{ OP_MemLoad, 0, 0, 0},
{ OP_Integer, 0, 0, 0},
{ OP_Ne, 0, 0, 0}, /* 2 */
{ OP_String, 0, 0, "ok"},
{ OP_Callback, 1, 0, 0},
};
/* Initialize the VDBE program */
sqliteVdbeAddOpList(v, ArraySize(initCode), initCode);
/* Do an integrity check on each database file */
for(i=0; i<db->nDb; i++){
HashElem *x;
/* Do an integrity check of the B-Tree
*/
addr = sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb);
sqliteVdbeChangeP1(v, addr+1, i);
sqliteVdbeChangeP2(v, addr+3, addr+7);
sqliteVdbeChangeP2(v, addr+6, addr+4);
sqliteVdbeChangeP2(v, addr+7, i);
sqliteVdbeChangeP2(v, addr+10, addr+ArraySize(checkDb));
sqliteVdbeChangeP3(v, addr+13, db->aDb[i].zName, P3_STATIC);
/* Make sure all the indices are constructed correctly.
*/
sqliteCodeVerifySchema(pParse, i);
for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
Table *pTab = sqliteHashData(x);
Index *pIdx;
int loopTop;
if( pTab->pIndex==0 ) continue;
sqliteVdbeAddOp(v, OP_Integer, i, 0);
sqliteVdbeOp3(v, OP_OpenRead, 1, pTab->tnum, pTab->zName, 0);
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
if( pIdx->tnum==0 ) continue;
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
sqliteVdbeOp3(v, OP_OpenRead, j+2, pIdx->tnum, pIdx->zName, 0);
}
sqliteVdbeAddOp(v, OP_Integer, 0, 0);
sqliteVdbeAddOp(v, OP_MemStore, 1, 1);
loopTop = sqliteVdbeAddOp(v, OP_Rewind, 1, 0);
sqliteVdbeAddOp(v, OP_MemIncr, 1, 0);
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
int k, jmp2;
static VdbeOpList idxErr[] = {
{ OP_MemIncr, 0, 0, 0},
{ OP_String, 0, 0, "rowid "},
{ OP_Recno, 1, 0, 0},
{ OP_String, 0, 0, " missing from index "},
{ OP_String, 0, 0, 0}, /* 4 */
{ OP_Concat, 4, 0, 0},
{ OP_Callback, 1, 0, 0},
};
sqliteVdbeAddOp(v, OP_Recno, 1, 0);
for(k=0; k<pIdx->nColumn; k++){
int idx = pIdx->aiColumn[k];
if( idx==pTab->iPKey ){
sqliteVdbeAddOp(v, OP_Recno, 1, 0);
}else{
sqliteVdbeAddOp(v, OP_Column, 1, idx);
}
}
sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
jmp2 = sqliteVdbeAddOp(v, OP_Found, j+2, 0);
addr = sqliteVdbeAddOpList(v, ArraySize(idxErr), idxErr);
sqliteVdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
sqliteVdbeChangeP2(v, jmp2, sqliteVdbeCurrentAddr(v));
}
sqliteVdbeAddOp(v, OP_Next, 1, loopTop+1);
sqliteVdbeChangeP2(v, loopTop, sqliteVdbeCurrentAddr(v));
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
static VdbeOpList cntIdx[] = {
{ OP_Integer, 0, 0, 0},
{ OP_MemStore, 2, 1, 0},
{ OP_Rewind, 0, 0, 0}, /* 2 */
{ OP_MemIncr, 2, 0, 0},
{ OP_Next, 0, 0, 0}, /* 4 */
{ OP_MemLoad, 1, 0, 0},
{ OP_MemLoad, 2, 0, 0},
{ OP_Eq, 0, 0, 0}, /* 7 */
{ OP_MemIncr, 0, 0, 0},
{ OP_String, 0, 0, "wrong # of entries in index "},
{ OP_String, 0, 0, 0}, /* 10 */
{ OP_Concat, 2, 0, 0},
{ OP_Callback, 1, 0, 0},
};
if( pIdx->tnum==0 ) continue;
addr = sqliteVdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
sqliteVdbeChangeP1(v, addr+2, j+2);
sqliteVdbeChangeP2(v, addr+2, addr+5);
sqliteVdbeChangeP1(v, addr+4, j+2);
sqliteVdbeChangeP2(v, addr+4, addr+3);
sqliteVdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
sqliteVdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
}
}
}
addr = sqliteVdbeAddOpList(v, ArraySize(endCode), endCode);
sqliteVdbeChangeP2(v, addr+2, addr+ArraySize(endCode));
}else
{}
sqliteFree(zLeft);
sqliteFree(zRight);
}
+238 -185
View File
@@ -1,10 +1,14 @@
/*
** The "printf" code that follows dates from the 1980's. It is in
** the public domain. The original comments are included here for
** completeness. They are slightly out-of-date.
** completeness. They are very out-of-date but might be useful as
** an historical reference. Most of the "enhancements" have been backed
** out so that the functionality is now the same as standard printf().
**
** The following modules is an enhanced replacement for the "printf" programs
** found in the standard library. The following enhancements are
**************************************************************************
**
** The following modules is an enhanced replacement for the "printf" subroutines
** found in the standard C library. The following enhancements are
** supported:
**
** + Additional functions. The standard set of "printf" functions
@@ -48,74 +52,80 @@
*/
#include "sqliteInt.h"
/*
** Undefine COMPATIBILITY to make some slight changes in the way things
** work. I think the changes are an improvement, but they are not
** backwards compatible.
*/
/* #define COMPATIBILITY / * Compatible with SUN OS 4.1 */
/*
** Conversion types fall into various categories as defined by the
** following enumeration.
*/
enum et_type { /* The type of the format field */
etRADIX, /* Integer types. %d, %x, %o, and so forth */
etFLOAT, /* Floating point. %f */
etEXP, /* Exponentional notation. %e and %E */
etGENERIC, /* Floating or exponential, depending on exponent. %g */
etSIZE, /* Return number of characters processed so far. %n */
etSTRING, /* Strings. %s */
etPERCENT, /* Percent symbol. %% */
etCHARX, /* Characters. %c */
etERROR, /* Used to indicate no such conversion type */
#define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */
#define etFLOAT 2 /* Floating point. %f */
#define etEXP 3 /* Exponentional notation. %e and %E */
#define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */
#define etSIZE 5 /* Return number of characters processed so far. %n */
#define etSTRING 6 /* Strings. %s */
#define etDYNSTRING 7 /* Dynamically allocated strings. %z */
#define etPERCENT 8 /* Percent symbol. %% */
#define etCHARX 9 /* Characters. %c */
#define etERROR 10 /* Used to indicate no such conversion type */
/* The rest are extensions, not normally found in printf() */
etCHARLIT, /* Literal characters. %' */
etSQLESCAPE, /* Strings with '\'' doubled. %q */
etSQLESCAPE2, /* Strings with '\'' doubled and enclosed in '',
#define etCHARLIT 11 /* Literal characters. %' */
#define etSQLESCAPE 12 /* Strings with '\'' doubled. %q */
#define etSQLESCAPE2 13 /* Strings with '\'' doubled and enclosed in '',
NULL pointers replaced by SQL NULL. %Q */
etORDINAL /* 1st, 2nd, 3rd and so forth */
};
#define etTOKEN 14 /* a pointer to a Token structure */
#define etSRCLIST 15 /* a pointer to a SrcList */
/*
** An "etByte" is an 8-bit unsigned value.
*/
typedef unsigned char etByte;
/*
** Each builtin conversion character (ex: the 'd' in "%d") is described
** by an instance of the following structure
*/
typedef struct et_info { /* Information about each format field */
int fmttype; /* The format field code letter */
int base; /* The base for radix conversion */
char *charset; /* The character set for conversion */
int flag_signed; /* Is the quantity signed? */
char *prefix; /* Prefix on non-zero values in alt format */
enum et_type type; /* Conversion paradigm */
char fmttype; /* The format field code letter */
etByte base; /* The base for radix conversion */
etByte flags; /* One or more of FLAG_ constants below */
etByte type; /* Conversion paradigm */
char *charset; /* The character set for conversion */
char *prefix; /* Prefix on non-zero values in alt format */
} et_info;
/*
** Allowed values for et_info.flags
*/
#define FLAG_SIGNED 1 /* True if the value to convert is signed */
#define FLAG_INTERN 2 /* True if for internal use only */
/*
** The following table is searched linearly, so it is good to put the
** most frequently used conversion types first.
*/
static et_info fmtinfo[] = {
{ 'd', 10, "0123456789", 1, 0, etRADIX, },
{ 's', 0, 0, 0, 0, etSTRING, },
{ 'q', 0, 0, 0, 0, etSQLESCAPE, },
{ 'Q', 0, 0, 0, 0, etSQLESCAPE2, },
{ 'c', 0, 0, 0, 0, etCHARX, },
{ 'o', 8, "01234567", 0, "0", etRADIX, },
{ 'u', 10, "0123456789", 0, 0, etRADIX, },
{ 'x', 16, "0123456789abcdef", 0, "x0", etRADIX, },
{ 'X', 16, "0123456789ABCDEF", 0, "X0", etRADIX, },
{ 'r', 10, "0123456789", 0, 0, etORDINAL, },
{ 'f', 0, 0, 1, 0, etFLOAT, },
{ 'e', 0, "e", 1, 0, etEXP, },
{ 'E', 0, "E", 1, 0, etEXP, },
{ 'g', 0, "e", 1, 0, etGENERIC, },
{ 'G', 0, "E", 1, 0, etGENERIC, },
{ 'i', 10, "0123456789", 1, 0, etRADIX, },
{ 'n', 0, 0, 0, 0, etSIZE, },
{ '%', 0, 0, 0, 0, etPERCENT, },
{ 'b', 2, "01", 0, "b0", etRADIX, }, /* Binary */
{ 'p', 10, "0123456789", 0, 0, etRADIX, }, /* Pointers */
{ '\'', 0, 0, 0, 0, etCHARLIT, }, /* Literal char */
{ 'd', 10, 1, etRADIX, "0123456789", 0 },
{ 's', 0, 0, etSTRING, 0, 0 },
{ 'z', 0, 2, etDYNSTRING, 0, 0 },
{ 'q', 0, 0, etSQLESCAPE, 0, 0 },
{ 'Q', 0, 0, etSQLESCAPE2, 0, 0 },
{ 'c', 0, 0, etCHARX, 0, 0 },
{ 'o', 8, 0, etRADIX, "01234567", "0" },
{ 'u', 10, 0, etRADIX, "0123456789", 0 },
{ 'x', 16, 0, etRADIX, "0123456789abcdef", "x0" },
{ 'X', 16, 0, etRADIX, "0123456789ABCDEF", "X0" },
{ 'f', 0, 1, etFLOAT, 0, 0 },
{ 'e', 0, 1, etEXP, "e", 0 },
{ 'E', 0, 1, etEXP, "E", 0 },
{ 'g', 0, 1, etGENERIC, "e", 0 },
{ 'G', 0, 1, etGENERIC, "E", 0 },
{ 'i', 10, 1, etRADIX, "0123456789", 0 },
{ 'n', 0, 0, etSIZE, 0, 0 },
{ '%', 0, 0, etPERCENT, 0, 0 },
{ 'p', 10, 0, etRADIX, "0123456789", 0 },
{ 'T', 0, 2, etTOKEN, 0, 0 },
{ 'S', 0, 2, etSRCLIST, 0, 0 },
};
#define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
@@ -137,9 +147,9 @@ static et_info fmtinfo[] = {
** 16 (the number of significant digits in a 64-bit float) '0' is
** always returned.
*/
static int et_getdigit(double *val, int *cnt){
static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
int digit;
double d;
LONGDOUBLE_TYPE d;
if( (*cnt)++ >= 16 ) return '0';
digit = (int)*val;
d = digit;
@@ -179,52 +189,49 @@ static int et_getdigit(double *val, int *cnt){
** will run.
*/
static int vxprintf(
void (*func)(void*,char*,int),
void *arg,
const char *format,
va_list ap
void (*func)(void*,const char*,int), /* Consumer of text */
void *arg, /* First argument to the consumer */
int useExtended, /* Allow extended %-conversions */
const char *fmt, /* Format string */
va_list ap /* arguments */
){
register const char *fmt; /* The format string. */
register int c; /* Next character in the format string */
register char *bufpt; /* Pointer to the conversion buffer */
register int precision; /* Precision of the current field */
register int length; /* Length of the field */
register int idx; /* A general purpose loop counter */
int count; /* Total number of characters output */
int width; /* Width of the current field */
int flag_leftjustify; /* True if "-" flag is present */
int flag_plussign; /* True if "+" flag is present */
int flag_blanksign; /* True if " " flag is present */
int flag_alternateform; /* True if "#" flag is present */
int flag_zeropad; /* True if field width constant starts with zero */
int flag_long; /* True if "l" flag is present */
int flag_center; /* True if "=" flag is present */
unsigned long longvalue; /* Value for integer types */
double realvalue; /* Value for real types */
et_info *infop; /* Pointer to the appropriate info structure */
char buf[etBUFSIZE]; /* Conversion buffer */
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
int errorflag = 0; /* True if an error is encountered */
enum et_type xtype; /* Conversion paradigm */
char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
static char spaces[] = " "
" ";
int c; /* Next character in the format string */
char *bufpt; /* Pointer to the conversion buffer */
int precision; /* Precision of the current field */
int length; /* Length of the field */
int idx; /* A general purpose loop counter */
int count; /* Total number of characters output */
int width; /* Width of the current field */
etByte flag_leftjustify; /* True if "-" flag is present */
etByte flag_plussign; /* True if "+" flag is present */
etByte flag_blanksign; /* True if " " flag is present */
etByte flag_alternateform; /* True if "#" flag is present */
etByte flag_zeropad; /* True if field width constant starts with zero */
etByte flag_long; /* True if "l" flag is present */
unsigned long longvalue; /* Value for integer types */
LONGDOUBLE_TYPE realvalue; /* Value for real types */
et_info *infop; /* Pointer to the appropriate info structure */
char buf[etBUFSIZE]; /* Conversion buffer */
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
etByte errorflag = 0; /* True if an error is encountered */
etByte xtype; /* Conversion paradigm */
char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
static char spaces[] = " ";
#define etSPACESIZE (sizeof(spaces)-1)
#ifndef etNOFLOATINGPOINT
int exp; /* exponent of real numbers */
double rounder; /* Used for rounding floating point values */
int flag_dp; /* True if decimal point should be shown */
int flag_rtz; /* True if trailing zeros should be removed */
int flag_exp; /* True to force display of the exponent */
int nsd; /* Number of significant digits returned */
int exp; /* exponent of real numbers */
double rounder; /* Used for rounding floating point values */
etByte flag_dp; /* True if decimal point should be shown */
etByte flag_rtz; /* True if trailing zeros should be removed */
etByte flag_exp; /* True to force display of the exponent */
int nsd; /* Number of significant digits returned */
#endif
fmt = format; /* Put in a register for speed */
count = length = 0;
bufpt = 0;
for(; (c=(*fmt))!=0; ++fmt){
if( c!='%' ){
register int amt;
int amt;
bufpt = (char *)fmt;
amt = 1;
while( (c=(*++fmt))!='%' && c!=0 ) amt++;
@@ -240,7 +247,7 @@ static int vxprintf(
}
/* Find out what flags are present */
flag_leftjustify = flag_plussign = flag_blanksign =
flag_alternateform = flag_zeropad = flag_center = 0;
flag_alternateform = flag_zeropad = 0;
do{
switch( c ){
case '-': flag_leftjustify = 1; c = 0; break;
@@ -248,11 +255,9 @@ static int vxprintf(
case ' ': flag_blanksign = 1; c = 0; break;
case '#': flag_alternateform = 1; c = 0; break;
case '0': flag_zeropad = 1; c = 0; break;
case '=': flag_center = 1; c = 0; break;
default: break;
}
}while( c==0 && (c=(*++fmt))!=0 );
if( flag_center ) flag_leftjustify = 0;
/* Get the field width */
width = 0;
if( c=='*' ){
@@ -277,10 +282,7 @@ static int vxprintf(
c = *++fmt;
if( c=='*' ){
precision = va_arg(ap,int);
#ifndef etCOMPATIBILITY
/* This is sensible, but SUN OS 4.1 doesn't do it. */
if( precision<0 ) precision = -precision;
#endif
c = *++fmt;
}else{
while( c>='0' && c<='9' ){
@@ -302,18 +304,16 @@ static int vxprintf(
}
/* Fetch the info entry for the field */
infop = 0;
xtype = etERROR;
for(idx=0; idx<etNINFO; idx++){
if( c==fmtinfo[idx].fmttype ){
infop = &fmtinfo[idx];
if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
xtype = infop->type;
}
break;
}
}
/* No info entry found. It must be an error. */
if( infop==0 ){
xtype = etERROR;
}else{
xtype = infop->type;
}
zExtra = 0;
/*
@@ -335,11 +335,10 @@ static int vxprintf(
** infop Pointer to the appropriate info struct.
*/
switch( xtype ){
case etORDINAL:
case etRADIX:
if( flag_long ) longvalue = va_arg(ap,long);
else longvalue = va_arg(ap,int);
#ifdef etCOMPATIBILITY
#if 1
/* For the format %#x, the value zero is printed "0" not "0x0".
** I think this is stupid. */
if( longvalue==0 ) flag_alternateform = 0;
@@ -348,7 +347,7 @@ static int vxprintf(
** but leave the prefix for hex. */
if( longvalue==0 && infop->base==8 ) flag_alternateform = 0;
#endif
if( infop->flag_signed ){
if( infop->flags & FLAG_SIGNED ){
if( *(long*)&longvalue<0 ){
longvalue = -*(long*)&longvalue;
prefix = '-';
@@ -359,26 +358,7 @@ static int vxprintf(
if( flag_zeropad && precision<width-(prefix!=0) ){
precision = width-(prefix!=0);
}
bufpt = &buf[etBUFSIZE];
if( xtype==etORDINAL ){
long a,b;
a = longvalue%10;
b = longvalue%100;
bufpt -= 2;
if( a==0 || a>3 || (b>10 && b<14) ){
bufpt[0] = 't';
bufpt[1] = 'h';
}else if( a==1 ){
bufpt[0] = 's';
bufpt[1] = 't';
}else if( a==2 ){
bufpt[0] = 'n';
bufpt[1] = 'd';
}else if( a==3 ){
bufpt[0] = 'r';
bufpt[1] = 'd';
}
}
bufpt = &buf[etBUFSIZE-1];
{
register char *cset; /* Use registers for speed */
register int base;
@@ -389,7 +369,7 @@ static int vxprintf(
longvalue = longvalue/base;
}while( longvalue>0 );
}
length = (long)&buf[etBUFSIZE]-(long)bufpt;
length = &buf[etBUFSIZE-1]-bufpt;
for(idx=precision-length; idx>0; idx--){
*(--bufpt) = '0'; /* Zero pad */
}
@@ -401,7 +381,7 @@ static int vxprintf(
for(pre=infop->prefix; (x=(*pre))!=0; pre++) *(--bufpt) = x;
}
}
length = (long)&buf[etBUFSIZE]-(long)bufpt;
length = &buf[etBUFSIZE-1]-bufpt;
break;
case etFLOAT:
case etEXP:
@@ -420,7 +400,7 @@ static int vxprintf(
}
if( infop->type==etGENERIC && precision>0 ) precision--;
rounder = 0.0;
#ifdef COMPATIBILITY
#if 0
/* Rounding works like BSD when the constant 0.4999 is used. Wierd! */
for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);
#else
@@ -431,12 +411,11 @@ static int vxprintf(
/* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
exp = 0;
if( realvalue>0.0 ){
int k = 0;
while( realvalue>=1e8 && k++<100 ){ realvalue *= 1e-8; exp+=8; }
while( realvalue>=10.0 && k++<100 ){ realvalue *= 0.1; exp++; }
while( realvalue<1e-8 && k++<100 ){ realvalue *= 1e8; exp-=8; }
while( realvalue<1.0 && k++<100 ){ realvalue *= 10.0; exp--; }
if( k>=100 ){
while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
if( exp>350 || exp<-350 ){
bufpt = "NaN";
length = 3;
break;
@@ -511,7 +490,7 @@ static int vxprintf(
/* The converted number is in buf[] and zero terminated. Output it.
** Note that the number is in the usual order, not reversed as with
** integer conversions. */
length = (long)bufpt-(long)buf;
length = bufpt-buf;
bufpt = buf;
/* Special case: Add leading zeros if the flag_zeropad flag is
@@ -549,8 +528,13 @@ static int vxprintf(
bufpt = buf;
break;
case etSTRING:
case etDYNSTRING:
bufpt = va_arg(ap,char*);
if( bufpt==0 ) bufpt = "(null)";
if( bufpt==0 ){
bufpt = "";
}else if( xtype==etDYNSTRING ){
zExtra = bufpt;
}
length = strlen(bufpt);
if( precision>=0 && precision<length ) length = precision;
break;
@@ -583,6 +567,25 @@ static int vxprintf(
if( precision>=0 && precision<length ) length = precision;
}
break;
case etTOKEN: {
Token *pToken = va_arg(ap, Token*);
(*func)(arg, pToken->z, pToken->n);
length = width = 0;
break;
}
case etSRCLIST: {
SrcList *pSrc = va_arg(ap, SrcList*);
int k = va_arg(ap, int);
struct SrcList_item *pItem = &pSrc->a[k];
assert( k>=0 && k<pSrc->nSrc );
if( pItem->zDatabase && pItem->zDatabase[0] ){
(*func)(arg, pItem->zDatabase, strlen(pItem->zDatabase));
(*func)(arg, ".", 1);
}
(*func)(arg, pItem->zName, strlen(pItem->zName));
length = width = 0;
break;
}
case etERROR:
buf[0] = '%';
buf[1] = c;
@@ -602,11 +605,6 @@ static int vxprintf(
register int nspace;
nspace = width-length;
if( nspace>0 ){
if( flag_center ){
nspace = nspace/2;
width -= nspace;
flag_leftjustify = 1;
}
count += nspace;
while( nspace>=etSPACESIZE ){
(*func)(arg,spaces,etSPACESIZE);
@@ -646,7 +644,9 @@ struct sgMprintf {
char *zBase; /* A base allocation */
char *zText; /* The string collected so far */
int nChar; /* Length of the string so far */
int nTotal; /* Output size if unconstrained */
int nAlloc; /* Amount of space allocated in zText */
void *(*xRealloc)(void*,int); /* Function used to realloc memory */
};
/*
@@ -655,24 +655,25 @@ struct sgMprintf {
** This routine add nNewChar characters of text in zNewText to
** the sgMprintf structure pointed to by "arg".
*/
static void mout(void *arg, char *zNewText, int nNewChar){
static void mout(void *arg, const char *zNewText, int nNewChar){
struct sgMprintf *pM = (struct sgMprintf*)arg;
pM->nTotal += nNewChar;
if( pM->nChar + nNewChar + 1 > pM->nAlloc ){
pM->nAlloc = pM->nChar + nNewChar*2 + 1;
if( pM->zText==pM->zBase ){
pM->zText = sqliteMalloc(pM->nAlloc);
if( pM->zText && pM->nChar ) memcpy(pM->zText,pM->zBase,pM->nChar);
if( pM->xRealloc==0 ){
nNewChar = pM->nAlloc - pM->nChar - 1;
}else{
char *z = sqliteRealloc(pM->zText, pM->nAlloc);
if( z==0 ){
sqliteFree(pM->zText);
pM->nChar = 0;
pM->nAlloc = 0;
pM->nAlloc = pM->nChar + nNewChar*2 + 1;
if( pM->zText==pM->zBase ){
pM->zText = pM->xRealloc(0, pM->nAlloc);
if( pM->zText && pM->nChar ){
memcpy(pM->zText, pM->zBase, pM->nChar);
}
}else{
pM->zText = pM->xRealloc(pM->zText, pM->nAlloc);
}
pM->zText = z;
}
}
if( pM->zText ){
if( pM->zText && nNewChar>0 ){
memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
pM->nChar += nNewChar;
pM->zText[pM->nChar] = 0;
@@ -680,50 +681,102 @@ static void mout(void *arg, char *zNewText, int nNewChar){
}
/*
** sqlite_mprintf() works like printf(), but allocations memory to hold the
** resulting string and returns a pointer to the allocated memory. Use
** sqliteFree() to release the memory allocated.
** This routine is a wrapper around xprintf() that invokes mout() as
** the consumer.
*/
static char *base_vprintf(
void *(*xRealloc)(void*,int), /* Routine to realloc memory. May be NULL */
int useInternal, /* Use internal %-conversions if true */
char *zInitBuf, /* Initially write here, before mallocing */
int nInitBuf, /* Size of zInitBuf[] */
const char *zFormat, /* format string */
va_list ap /* arguments */
){
struct sgMprintf sM;
sM.zBase = sM.zText = zInitBuf;
sM.nChar = sM.nTotal = 0;
sM.nAlloc = nInitBuf;
sM.xRealloc = xRealloc;
vxprintf(mout, &sM, useInternal, zFormat, ap);
if( xRealloc ){
if( sM.zText==sM.zBase ){
sM.zText = xRealloc(0, sM.nChar+1);
memcpy(sM.zText, sM.zBase, sM.nChar+1);
}else if( sM.nAlloc>sM.nChar+10 ){
sM.zText = xRealloc(sM.zText, sM.nChar+1);
}
}
return sM.zText;
}
/*
** Realloc that is a real function, not a macro.
*/
static void *printf_realloc(void *old, int size){
return sqliteRealloc(old,size);
}
/*
** Print into memory obtained from sqliteMalloc(). Use the internal
** %-conversion extensions.
*/
char *sqliteVMPrintf(const char *zFormat, va_list ap){
char zBase[1000];
return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
}
/*
** Print into memory obtained from sqliteMalloc(). Use the internal
** %-conversion extensions.
*/
char *sqliteMPrintf(const char *zFormat, ...){
va_list ap;
char *z;
char zBase[1000];
va_start(ap, zFormat);
z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
va_end(ap);
return z;
}
/*
** Print into memory obtained from malloc(). Do not use the internal
** %-conversion extensions. This routine is for use by external users.
*/
char *sqlite_mprintf(const char *zFormat, ...){
va_list ap;
struct sgMprintf sMprintf;
char *zNew;
char *z;
char zBuf[200];
sMprintf.nChar = 0;
sMprintf.nAlloc = sizeof(zBuf);
sMprintf.zText = zBuf;
sMprintf.zBase = zBuf;
va_start(ap,zFormat);
vxprintf(mout,&sMprintf,zFormat,ap);
z = base_vprintf((void*(*)(void*,int))realloc, 0,
zBuf, sizeof(zBuf), zFormat, ap);
va_end(ap);
sMprintf.zText[sMprintf.nChar] = 0;
zNew = malloc( sMprintf.nChar+1 );
if( zNew ) strcpy(zNew,sMprintf.zText);
if( sMprintf.zText!=sMprintf.zBase ){
sqliteFree(sMprintf.zText);
}
return zNew;
return z;
}
/* This is the varargs version of sqlite_mprintf.
*/
char *sqlite_vmprintf(const char *zFormat, va_list ap){
struct sgMprintf sMprintf;
char *zNew;
char zBuf[200];
sMprintf.nChar = 0;
sMprintf.zText = zBuf;
sMprintf.nAlloc = sizeof(zBuf);
sMprintf.zBase = zBuf;
vxprintf(mout,&sMprintf,zFormat,ap);
sMprintf.zText[sMprintf.nChar] = 0;
zNew = malloc( sMprintf.nChar+1 );
if( zNew ) strcpy(zNew,sMprintf.zText);
if( sMprintf.zText!=sMprintf.zBase ){
sqliteFree(sMprintf.zText);
}
return zNew;
return base_vprintf((void*(*)(void*,int))realloc, 0,
zBuf, sizeof(zBuf), zFormat, ap);
}
/*
** sqlite_snprintf() works like snprintf() except that it ignores the
** current locale settings. This is important for SQLite because we
** are not able to use a "," as the decimal point in place of "." as
** specified by some locales.
*/
char *sqlite_snprintf(int n, char *zBuf, const char *zFormat, ...){
char *z;
va_list ap;
va_start(ap,zFormat);
z = base_vprintf(0, 0, zBuf, n, zFormat, ap);
va_end(ap);
return z;
}
/*
+15 -31
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.10 2002/02/19 13:39:23 drh Exp $
** $Id: random.c,v 1.11 2004/02/11 09:46:33 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -35,15 +35,15 @@
** on RC4, which we know works very well.
*/
static int randomByte(){
int t;
unsigned char t;
/* All threads share a single random number generator.
** This structure is the current state of the generator.
*/
static struct {
int isInit; /* True if initialized */
int i, j; /* State variables */
int s[256]; /* State variables */
unsigned char isInit; /* True if initialized */
unsigned char i, j; /* State variables */
unsigned char s[256]; /* State variables */
} prng;
/* Initialize the state of the random number generator once,
@@ -65,8 +65,7 @@ static int randomByte(){
prng.s[i] = i;
}
for(i=0; i<256; i++){
int t;
prng.j = (prng.j + prng.s[i] + k[i]) & 0xff;
prng.j += prng.s[i] + k[i];
t = prng.s[prng.j];
prng.s[prng.j] = prng.s[i];
prng.s[i] = t;
@@ -76,38 +75,23 @@ static int randomByte(){
/* Generate and return single random byte
*/
prng.i = (prng.i + 1) & 0xff;
prng.j = (prng.j + prng.s[prng.i]) & 0xff;
prng.i++;
t = prng.s[prng.i];
prng.j += t;
prng.s[prng.i] = prng.s[prng.j];
prng.s[prng.j] = t;
t = prng.s[prng.i] + prng.s[prng.j];
return prng.s[t & 0xff];
t += prng.s[prng.i];
return prng.s[t];
}
/*
** Return an random 8-bit integer.
** Return N random bytes.
*/
int sqliteRandomByte(){
int r;
void sqliteRandomness(int N, void *pBuf){
unsigned char *zBuf = pBuf;
sqliteOsEnterMutex();
r = randomByte();
sqliteOsLeaveMutex();
return r;
}
/*
** Return a random 32-bit integer. The integer is generated by making
** 4 calls to sqliteRandomByte().
*/
int sqliteRandomInteger(){
int r;
int i;
sqliteOsEnterMutex();
r = randomByte();
for(i=1; i<4; i++){
r = (r<<8) + randomByte();
while( N-- ){
*(zBuf++) = randomByte();
}
sqliteOsLeaveMutex();
return r;
}
+701 -394
View File
File diff suppressed because it is too large Load Diff
+320 -160
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.62 2002/08/21 11:26:41 drh Exp $
** $Id: shell.c,v 1.93 2004/03/17 23:42:13 drh Exp $
*/
#include <stdlib.h>
#include <string.h>
@@ -20,24 +20,37 @@
#include "sqlite.h"
#include <ctype.h>
#if !defined(_WIN32) && !defined(WIN32)
#if !defined(_WIN32) && !defined(WIN32) && !defined(__MACOS__)
# include <signal.h>
# include <pwd.h>
# include <unistd.h>
# include <sys/types.h>
#endif
#ifdef __MACOS__
# include <console.h>
# include <signal.h>
# include <unistd.h>
# include <extras.h>
# include <Files.h>
# include <Folders.h>
#endif
#if defined(HAVE_READLINE) && HAVE_READLINE==1
# include <readline/readline.h>
# include <readline/history.h>
#else
# define readline(p) getline(p,stdin)
# define readline(p) local_getline(p,stdin)
# define add_history(X)
# define read_history(X)
# define write_history(X)
# define stifle_history(X)
#endif
/* Make sure isatty() has a prototype.
*/
extern int isatty();
/*
** The following is the open SQLite database. We make a pointer
** to this database a static variable so that it can be accessed
@@ -63,6 +76,12 @@ static char *Argv0;
static char mainPrompt[20]; /* First line prompt. default: "sqlite> "*/
static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */
/*
** Determines if a string is a number of not.
*/
extern int sqliteIsNumber(const char*);
/*
** This routine reads a line of text from standard input, stores
** the text in memory obtained from malloc() and returns a pointer
@@ -72,7 +91,7 @@ static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */
** The interface is like "readline" but no command-line editing
** is done.
*/
static char *getline(char *zPrompt, FILE *in){
static char *local_getline(char *zPrompt, FILE *in){
char *zLine;
int nLine;
int n;
@@ -117,7 +136,7 @@ static char *getline(char *zPrompt, FILE *in){
** Retrieve a single line of input text. "isatty" is true if text
** is coming from a terminal. In that case, we issue a prompt and
** attempt to use "readline" for command-line editing. If "isatty"
** is false, use "getline" instead of "readline" and issue no prompt.
** is false, use "local_getline" instead of "readline" and issue no prompt.
**
** zPrior is a string of prior text retrieved. If not the empty
** string, then issue a continuation prompt.
@@ -126,7 +145,7 @@ static char *one_input_line(const char *zPrior, FILE *in){
char *zPrompt;
char *zResult;
if( in!=0 ){
return getline(0, in);
return local_getline(0, in);
}
if( zPrior && zPrior[0] ){
zPrompt = continuePrompt;
@@ -160,11 +179,14 @@ struct callback_data {
char separator[20]; /* Separator character for MODE_List */
int colWidth[100]; /* Requested width of each column when in column mode*/
int actualWidth[100]; /* Actual width of each column */
char nullvalue[20]; /* The text to print when a NULL comes back from the database */
char nullvalue[20]; /* The text to print when a NULL comes back from
** the database */
struct previous_mode_data explainPrev;
/* Holds the mode information just before .explain ON */
char outfile[FILENAME_MAX];
/* Filename for *out */
/* Holds the mode information just before
** .explain ON */
char outfile[FILENAME_MAX]; /* Filename for *out */
const char *zDbFilename; /* name of the database file */
char *zKey; /* Encryption key */
};
/*
@@ -176,7 +198,7 @@ struct callback_data {
#define MODE_Semi 3 /* Same as MODE_List but append ";" to each line */
#define MODE_Html 4 /* Generate an XHTML table */
#define MODE_Insert 5 /* Generate SQL "insert" statements */
#define MODE_NUM_OF 6
#define MODE_NUM_OF 6 /* The number of modes (not a mode itself) */
char *modeDescr[MODE_NUM_OF] = {
"line",
@@ -192,31 +214,6 @@ char *modeDescr[MODE_NUM_OF] = {
*/
#define ArraySize(X) (sizeof(X)/sizeof(X[0]))
/*
** Return TRUE if the string supplied is a number of some kinds.
*/
static int is_numeric(const char *z){
int seen_digit = 0;
if( *z=='-' || *z=='+' ){
z++;
}
while( isdigit(*z) ){
seen_digit = 1;
z++;
}
if( seen_digit && *z=='.' ){
z++;
while( isdigit(*z) ){ z++; }
}
if( seen_digit && (*z=='e' || *z=='E')
&& (isdigit(z[1]) || ((z[1]=='-' || z[1]=='+') && isdigit(z[2])))
){
z+=2;
while( isdigit(*z) ){ z++; }
}
return seen_digit && *z==0;
}
/*
** Output the given string as a quoted string using SQL quoting conventions.
*/
@@ -294,7 +291,8 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
}
if( p->cnt++>0 ) fprintf(p->out,"\n");
for(i=0; i<nArg; i++){
fprintf(p->out,"%*s = %s\n", w, azCol[i], azArg[i] ? azArg[i] : p->nullvalue);
fprintf(p->out,"%*s = %s\n", w, azCol[i],
azArg[i] ? azArg[i] : p->nullvalue);
}
break;
}
@@ -384,7 +382,7 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
output_html_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
fprintf(p->out,"</TD>\n");
}
fprintf(p->out,"</TD></TR>\n");
fprintf(p->out,"</TR>\n");
break;
}
case MODE_Insert: {
@@ -394,7 +392,7 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
char *zSep = i>0 ? ",": "";
if( azArg[i]==0 ){
fprintf(p->out,"%sNULL",zSep);
}else if( is_numeric(azArg[i]) ){
}else if( sqliteIsNumber(azArg[i]) ){
fprintf(p->out,"%s%s",zSep, azArg[i]);
}else{
if( zSep[0] ) fprintf(p->out,"%s",zSep);
@@ -475,7 +473,8 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
** Text of a help message
*/
static char zHelp[] =
".dump ?TABLE? ... Dump the database in an text format\n"
".databases List names and files of attached databases\n"
".dump ?TABLE? ... Dump the database in a text format\n"
".echo ON|OFF Turn command echo on or off\n"
".exit Exit this program\n"
".explain ON|OFF Turn output mode suitable for EXPLAIN on or off.\n"
@@ -486,12 +485,14 @@ static char zHelp[] =
" \"insert\", \"list\", or \"html\"\n"
".mode insert TABLE Generate SQL insert statements for TABLE\n"
".nullvalue STRING Print STRING instead of nothing for NULL data\n"
".openaux FILENAME Use FILENAME to hold TEMP tables\n"
".output FILENAME Send output to FILENAME\n"
".output stdout Send output to the screen\n"
".prompt MAIN CONTINUE Replace the standard prompts\n"
".quit Exit this program\n"
".read FILENAME Execute SQL in FILENAME\n"
#ifdef SQLITE_HAS_CODEC
".rekey OLD NEW NEW Change the encryption key\n"
#endif
".schema ?TABLE? Show the CREATE statements\n"
".separator STRING Change separator string for \"list\" mode\n"
".show Show the current values for various settings\n"
@@ -503,13 +504,38 @@ static char zHelp[] =
/* Forward reference */
static void process_input(struct callback_data *p, FILE *in);
/*
** Make sure the database is open. If it is not, then open it. If
** the database fails to open, print an error message and exit.
*/
static void open_db(struct callback_data *p){
if( p->db==0 ){
char *zErrMsg = 0;
#ifdef SQLITE_HAS_CODEC
int n = p->zKey ? strlen(p->zKey) : 0;
db = p->db = sqlite_open_encrypted(p->zDbFilename, p->zKey, n, 0, &zErrMsg);
#else
db = p->db = sqlite_open(p->zDbFilename, 0, &zErrMsg);
#endif
if( p->db==0 ){
if( zErrMsg ){
fprintf(stderr,"Unable to open database \"%s\": %s\n",
p->zDbFilename, zErrMsg);
}else{
fprintf(stderr,"Unable to open database %s\n", p->zDbFilename);
}
exit(1);
}
}
}
/*
** If an input line begins with "." then invoke this routine to
** process that line.
**
** Return 1 to exit and 0 to continue.
*/
static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
static int do_meta_command(char *zLine, struct callback_data *p){
int i = 1;
int nArg = 0;
int n, c;
@@ -520,6 +546,7 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
*/
while( zLine[i] && nArg<ArraySize(azArg) ){
while( isspace(zLine[i]) ){ i++; }
if( zLine[i]==0 ) break;
if( zLine[i]=='\'' || zLine[i]=='"' ){
int delim = zLine[i++];
azArg[nArg++] = &zLine[i];
@@ -539,11 +566,29 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
if( nArg==0 ) return rc;
n = strlen(azArg[0]);
c = azArg[0][0];
if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){
struct callback_data data;
char *zErrMsg = 0;
open_db(p);
memcpy(&data, p, sizeof(data));
data.showHeader = 1;
data.mode = MODE_Column;
data.colWidth[0] = 3;
data.colWidth[1] = 15;
data.colWidth[2] = 58;
sqlite_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
if( zErrMsg ){
fprintf(stderr,"Error: %s\n", zErrMsg);
sqlite_freemem(zErrMsg);
}
}else
if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
char *zErrMsg = 0;
open_db(p);
fprintf(p->out, "BEGIN TRANSACTION;\n");
if( nArg==1 ){
sqlite_exec(db,
sqlite_exec(p->db,
"SELECT name, type, sql FROM sqlite_master "
"WHERE type!='meta' AND sql NOT NULL "
"ORDER BY substr(type,2,1), name",
@@ -552,7 +597,7 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
}else{
int i;
for(i=1; i<nArg && zErrMsg==0; i++){
sqlite_exec_printf(db,
sqlite_exec_printf(p->db,
"SELECT name, type, sql FROM sqlite_master "
"WHERE tbl_name LIKE '%q' AND type!='meta' AND sql NOT NULL "
"ORDER BY substr(type,2,1), name",
@@ -562,7 +607,7 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
}
if( zErrMsg ){
fprintf(stderr,"Error: %s\n", zErrMsg);
free(zErrMsg);
sqlite_freemem(zErrMsg);
}else{
fprintf(p->out, "COMMIT;\n");
}
@@ -653,10 +698,11 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg>1 ){
struct callback_data data;
char *zErrMsg = 0;
open_db(p);
memcpy(&data, p, sizeof(data));
data.showHeader = 0;
data.mode = MODE_List;
sqlite_exec_printf(db,
sqlite_exec_printf(p->db,
"SELECT name FROM sqlite_master "
"WHERE type='index' AND tbl_name LIKE '%q' "
"UNION ALL "
@@ -667,7 +713,7 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
);
if( zErrMsg ){
fprintf(stderr,"Error: %s\n", zErrMsg);
free(zErrMsg);
sqlite_freemem(zErrMsg);
}
}else
@@ -701,15 +747,6 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
sprintf(p->nullvalue, "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
}else
if( c=='o' && strncmp(azArg[0], "openaux", n)==0 ){
char *zErrMsg = 0;
sqlite_open_aux_file(db, nArg>=2 ? azArg[1] : 0, &zErrMsg);
if( zErrMsg ){
fprintf(stderr,"Error: %s\n", zErrMsg);
free(zErrMsg);
}
}else
if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
if( p->out!=stdout ){
fclose(p->out);
@@ -718,7 +755,7 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
p->out = stdout;
strcpy(p->outfile,"stdout");
}else{
p->out = fopen(azArg[1], "w");
p->out = fopen(azArg[1], "wb");
if( p->out==0 ){
fprintf(stderr,"can't write to \"%s\"\n", azArg[1]);
p->out = stdout;
@@ -738,12 +775,11 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
}else
if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
sqlite_close(db);
exit(0);
rc = 1;
}else
if( c=='r' && strncmp(azArg[0], "read", n)==0 && nArg==2 ){
FILE *alt = fopen(azArg[1], "r");
FILE *alt = fopen(azArg[1], "rb");
if( alt==0 ){
fprintf(stderr,"can't open \"%s\"\n", azArg[1]);
}else{
@@ -752,9 +788,26 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
}
}else
#ifdef SQLITE_HAS_CODEC
if( c=='r' && strncmp(azArg[0],"rekey", n)==0 && nArg==4 ){
char *zOld = p->zKey;
if( zOld==0 ) zOld = "";
if( strcmp(azArg[1],zOld) ){
fprintf(stderr,"old key is incorrect\n");
}else if( strcmp(azArg[2], azArg[3]) ){
fprintf(stderr,"2nd copy of new key does not match the 1st\n");
}else{
sqlite_freemem(p->zKey);
p->zKey = sqlite_mprintf("%s", azArg[2]);
sqlite_rekey(p->db, p->zKey, strlen(p->zKey));
}
}else
#endif
if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
struct callback_data data;
char *zErrMsg = 0;
open_db(p);
memcpy(&data, p, sizeof(data));
data.showHeader = 0;
data.mode = MODE_Semi;
@@ -787,7 +840,7 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
new_colv[1] = 0;
callback(&data, 1, new_argv, new_colv);
}else{
sqlite_exec_printf(db,
sqlite_exec_printf(p->db,
"SELECT sql FROM "
" (SELECT * FROM sqlite_master UNION ALL"
" SELECT * FROM sqlite_temp_master) "
@@ -796,7 +849,7 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
callback, &data, &zErrMsg, azArg[1]);
}
}else{
sqlite_exec(db,
sqlite_exec(p->db,
"SELECT sql FROM "
" (SELECT * FROM sqlite_master UNION ALL"
" SELECT * FROM sqlite_temp_master) "
@@ -807,7 +860,7 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
}
if( zErrMsg ){
fprintf(stderr,"Error: %s\n", zErrMsg);
free(zErrMsg);
sqlite_freemem(zErrMsg);
}
}else
@@ -836,8 +889,9 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
char **azResult;
int nRow, rc;
char *zErrMsg;
open_db(p);
if( nArg==1 ){
rc = sqlite_get_table(db,
rc = sqlite_get_table(p->db,
"SELECT name FROM sqlite_master "
"WHERE type IN ('table','view') "
"UNION ALL "
@@ -847,7 +901,7 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
&azResult, &nRow, 0, &zErrMsg
);
}else{
rc = sqlite_get_table_printf(db,
rc = sqlite_get_table_printf(p->db,
"SELECT name FROM sqlite_master "
"WHERE type IN ('table','view') AND name LIKE '%%%q%%' "
"UNION ALL "
@@ -859,7 +913,7 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
}
if( zErrMsg ){
fprintf(stderr,"Error: %s\n", zErrMsg);
free(zErrMsg);
sqlite_freemem(zErrMsg);
}
if( rc==SQLITE_OK ){
int len, maxlen = 0;
@@ -885,7 +939,8 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
}else
if( c=='t' && n>1 && strncmp(azArg[0], "timeout", n)==0 && nArg>=2 ){
sqlite_busy_timeout(db, atoi(azArg[1]));
open_db(p);
sqlite_busy_timeout(p->db, atoi(azArg[1]));
}else
if( c=='w' && strncmp(azArg[0], "width", n)==0 ){
@@ -903,6 +958,54 @@ static int do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
return rc;
}
/*
** Return TRUE if the last non-whitespace character in z[] is a semicolon.
** z[] is N characters long.
*/
static int _ends_with_semicolon(const char *z, int N){
while( N>0 && isspace(z[N-1]) ){ N--; }
return N>0 && z[N-1]==';';
}
/*
** Test to see if a line consists entirely of whitespace.
*/
static int _all_whitespace(const char *z){
for(; *z; z++){
if( isspace(*z) ) continue;
if( *z=='/' && z[1]=='*' ){
z += 2;
while( *z && (*z!='*' || z[1]!='/') ){ z++; }
if( *z==0 ) return 0;
z++;
continue;
}
if( *z=='-' && z[1]=='-' ){
z += 2;
while( *z && *z!='\n' ){ z++; }
if( *z==0 ) return 1;
continue;
}
return 0;
}
return 1;
}
/*
** Return TRUE if the line typed in is an SQL command terminator other
** than a semi-colon. The SQL Server style "go" command is understood
** as is the Oracle "/".
*/
static int _is_command_terminator(const char *zLine){
extern int sqliteStrNICmp(const char*,const char*,int);
while( isspace(*zLine) ){ zLine++; };
if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ) return 1; /* Oracle */
if( sqliteStrNICmp(zLine,"go",2)==0 && _all_whitespace(&zLine[2]) ){
return 1; /* SQL Server */
}
return 0;
}
/*
** Read input from *in and process it. If *in==0 then input
** is interactive - the user is typing it it. Otherwise, input
@@ -922,12 +1025,16 @@ static void process_input(struct callback_data *p, FILE *in){
seenInterrupt = 0;
}
if( p->echoOn ) printf("%s\n", zLine);
if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue;
if( zLine && zLine[0]=='.' && nSql==0 ){
int rc = do_meta_command(zLine, db, p);
int rc = do_meta_command(zLine, p);
free(zLine);
if( rc ) break;
continue;
}
if( _is_command_terminator(zLine) ){
strcpy(zLine,";");
}
if( zSql==0 ){
int i;
for(i=0; zLine[i] && isspace(zLine[i]); i++){}
@@ -948,14 +1055,15 @@ static void process_input(struct callback_data *p, FILE *in){
nSql += len;
}
free(zLine);
if( zSql && sqlite_complete(zSql) ){
if( zSql && _ends_with_semicolon(zSql, nSql) && sqlite_complete(zSql) ){
p->cnt = 0;
rc = sqlite_exec(db, zSql, callback, p, &zErrMsg);
open_db(p);
rc = sqlite_exec(p->db, zSql, callback, p, &zErrMsg);
if( rc || zErrMsg ){
if( in!=0 && !p->echoOn ) printf("%s\n",zSql);
if( zErrMsg!=0 ){
printf("SQL error: %s\n", zErrMsg);
free(zErrMsg);
sqlite_freemem(zErrMsg);
zErrMsg = 0;
}else{
printf("SQL error: %s\n", sqlite_error_string(rc));
@@ -967,7 +1075,7 @@ static void process_input(struct callback_data *p, FILE *in){
}
}
if( zSql ){
printf("Incomplete SQL: %s\n", zSql);
if( !_all_whitespace(zSql) ) printf("Incomplete SQL: %s\n", zSql);
free(zSql);
}
}
@@ -981,7 +1089,7 @@ static void process_input(struct callback_data *p, FILE *in){
static char *find_home_dir(void){
char *home_dir = NULL;
#if !defined(_WIN32) && !defined(WIN32)
#if !defined(_WIN32) && !defined(WIN32) && !defined(__MACOS__)
struct passwd *pwent;
uid_t uid = getuid();
if( (pwent=getpwuid(uid)) != NULL) {
@@ -989,6 +1097,11 @@ static char *find_home_dir(void){
}
#endif
#ifdef __MACOS__
char home_path[_MAX_PATH+1];
home_dir = getcwd(home_path, _MAX_PATH);
#endif
if (!home_dir) {
home_dir = getenv("HOME");
if (!home_dir) {
@@ -1015,9 +1128,13 @@ static char *find_home_dir(void){
** Read input from the file given by sqliterc_override. Or if that
** parameter is NULL, take input from ~/.sqliterc
*/
static void process_sqliterc(struct callback_data *p, char *sqliterc_override){
static void process_sqliterc(
struct callback_data *p, /* Configuration data */
const char *sqliterc_override /* Name of config file. NULL to use default */
){
char *home_dir = NULL;
char *sqliterc = sqliterc_override;
const char *sqliterc = sqliterc_override;
char *zBuf;
FILE *in = NULL;
if (sqliterc == NULL) {
@@ -1026,23 +1143,55 @@ static void process_sqliterc(struct callback_data *p, char *sqliterc_override){
fprintf(stderr,"%s: cannot locate your home directory!\n", Argv0);
return;
}
sqliterc = malloc(strlen(home_dir) + 15);
if( sqliterc==0 ){
zBuf = malloc(strlen(home_dir) + 15);
if( zBuf==0 ){
fprintf(stderr,"%s: out of memory!\n", Argv0);
exit(1);
}
sprintf(sqliterc,"%s/.sqliterc",home_dir);
sprintf(zBuf,"%s/.sqliterc",home_dir);
free(home_dir);
sqliterc = (const char*)zBuf;
}
in = fopen(sqliterc,"r");
if(in) {
printf("Loading resources from %s\n",sqliterc);
in = fopen(sqliterc,"rb");
if( in ){
if( isatty(fileno(stdout)) ){
printf("Loading resources from %s\n",sqliterc);
}
process_input(p,in);
fclose(in);
}
return;
}
/*
** Show available command line options
*/
static const char zOptions[] =
" -init filename read/process named file\n"
" -echo print commands before execution\n"
" -[no]header turn headers on or off\n"
" -column set output mode to 'column'\n"
" -html set output mode to HTML\n"
#ifdef SQLITE_HAS_CODEC
" -key KEY encryption key\n"
#endif
" -line set output mode to 'line'\n"
" -list set output mode to 'list'\n"
" -separator 'x' set output field separator (|)\n"
" -nullvalue 'text' set text string for NULL values\n"
" -version show SQLite version\n"
" -help show this text, also show dot-commands\n"
;
static void usage(int showDetail){
fprintf(stderr, "Usage: %s [OPTIONS] FILENAME [SQL]\n", Argv0);
if( showDetail ){
fprintf(stderr, "Options are:\n%s", zOptions);
}else{
fprintf(stderr, "Use the -help option for additional information\n");
}
exit(1);
}
/*
** Initialize the state information in data
*/
@@ -1058,115 +1207,126 @@ void main_init(struct callback_data *data) {
int main(int argc, char **argv){
char *zErrMsg = 0;
struct callback_data data;
int origArgc = argc;
char **origArgv = argv;
const char *zInitFile = 0;
char *zFirstCmd = 0;
int i;
extern int sqliteOsFileExists(const char*);
#ifdef __MACOS__
argc = ccommand(&argv);
#endif
Argv0 = argv[0];
main_init(&data);
process_sqliterc(&data,NULL);
/* Make sure we have a valid signal handler early, before anything
** else is done.
*/
#ifdef SIGINT
signal(SIGINT, interrupt_handler);
#endif
while( argc>=2 && argv[1][0]=='-' ){
if( argc>=3 && strcmp(argv[1],"-init")==0 ){
/* If we get a -init to do, we have to pretend that
** it replaced the .sqliterc file. Soooo, in order to
** do that we need to start from scratch...*/
main_init(&data);
/* treat this file as the sqliterc... */
process_sqliterc(&data,argv[2]);
/* Do an initial pass through the command-line argument to locate
** the name of the database file, the name of the initialization file,
** and the first command to execute.
*/
for(i=1; i<argc-1; i++){
if( argv[i][0]!='-' ) break;
if( strcmp(argv[i],"-separator")==0 || strcmp(argv[i],"-nullvalue")==0 ){
i++;
}else if( strcmp(argv[i],"-init")==0 ){
i++;
zInitFile = argv[i];
}else if( strcmp(argv[i],"-key")==0 ){
i++;
data.zKey = sqlite_mprintf("%s",argv[i]);
}
}
if( i<argc ){
data.zDbFilename = argv[i++];
}else{
data.zDbFilename = ":memory:";
}
if( i<argc ){
zFirstCmd = argv[i++];
}
data.out = stdout;
/* fix up the command line so we do not re-read
** the option next time around... */
{
int i = 1;
for(i=1;i<=argc-2;i++) {
argv[i] = argv[i+2];
}
}
origArgc-=2;
/* Go ahead and open the database file if it already exists. If the
** file does not exist, delay opening it. This prevents empty database
** files from being created if a user mistypes the database name argument
** to the sqlite command-line tool.
*/
if( sqliteOsFileExists(data.zDbFilename) ){
open_db(&data);
}
/* and reset the command line options to be re-read.*/
argv = origArgv;
argc = origArgc;
/* Process the initialization file if there is one. If no -init option
** is given on the command line, look for a file named ~/.sqliterc and
** try to process it.
*/
process_sqliterc(&data,zInitFile);
}else if( strcmp(argv[1],"-html")==0 ){
/* Make a second pass through the command-line argument and set
** options. This second pass is delayed until after the initialization
** file is processed so that the command-line arguments will override
** settings in the initialization file.
*/
for(i=1; i<argc && argv[i][0]=='-'; i++){
char *z = argv[i];
if( strcmp(z,"-init")==0 || strcmp(z,"-key")==0 ){
i++;
}else if( strcmp(z,"-html")==0 ){
data.mode = MODE_Html;
argc--;
argv++;
}else if( strcmp(argv[1],"-list")==0 ){
}else if( strcmp(z,"-list")==0 ){
data.mode = MODE_List;
argc--;
argv++;
}else if( strcmp(argv[1],"-line")==0 ){
}else if( strcmp(z,"-line")==0 ){
data.mode = MODE_Line;
argc--;
argv++;
}else if( strcmp(argv[1],"-column")==0 ){
}else if( strcmp(z,"-column")==0 ){
data.mode = MODE_Column;
argc--;
argv++;
}else if( argc>=3 && strcmp(argv[1],"-separator")==0 ){
sprintf(data.separator,"%.*s",(int)sizeof(data.separator)-1,argv[2]);
argc -= 2;
argv += 2;
}else if( argc>=3 && strcmp(argv[1],"-nullvalue")==0 ){
sprintf(data.nullvalue,"%.*s",(int)sizeof(data.nullvalue)-1,argv[2]);
argc -= 2;
argv += 2;
}else if( strcmp(argv[1],"-header")==0 ){
}else if( strcmp(z,"-separator")==0 ){
i++;
sprintf(data.separator,"%.*s",(int)sizeof(data.separator)-1,argv[i]);
}else if( strcmp(z,"-nullvalue")==0 ){
i++;
sprintf(data.nullvalue,"%.*s",(int)sizeof(data.nullvalue)-1,argv[i]);
}else if( strcmp(z,"-header")==0 ){
data.showHeader = 1;
argc--;
argv++;
}else if( strcmp(argv[1],"-noheader")==0 ){
}else if( strcmp(z,"-noheader")==0 ){
data.showHeader = 0;
argc--;
argv++;
}else if( strcmp(argv[1],"-echo")==0 ){
}else if( strcmp(z,"-echo")==0 ){
data.echoOn = 1;
argc--;
argv++;
}else if( strcmp(z,"-version")==0 ){
printf("%s\n", sqlite_version);
return 1;
}else if( strcmp(z,"-help")==0 ){
usage(1);
}else{
fprintf(stderr,"%s: unknown option: %s\n", Argv0, argv[1]);
fprintf(stderr,"%s: unknown option: %s\n", Argv0, z);
fprintf(stderr,"Use -help for a list of options.\n");
return 1;
}
}
if( argc!=2 && argc!=3 ){
fprintf(stderr,"Usage: %s ?OPTIONS? FILENAME ?SQL?\n", Argv0);
exit(1);
}
data.db = db = sqlite_open(argv[1], 0666, &zErrMsg);
if( db==0 ){
data.db = db = sqlite_open(argv[1], 0444, &zErrMsg);
if( db==0 ){
if( zErrMsg ){
fprintf(stderr,"Unable to open database \"%s\": %s\n", argv[1],zErrMsg);
}else{
fprintf(stderr,"Unable to open database %s\n", argv[1]);
}
exit(1);
}else{
fprintf(stderr,"Database \"%s\" opened READ ONLY!\n", argv[1]);
}
}
data.out = stdout;
if( argc==3 ){
if( argv[2][0]=='.' ){
do_meta_command(argv[2], db, &data);
if( zFirstCmd ){
/* Run just the command that follows the database name
*/
if( zFirstCmd[0]=='.' ){
do_meta_command(zFirstCmd, &data);
exit(0);
}else{
int rc;
rc = sqlite_exec(db, argv[2], callback, &data, &zErrMsg);
open_db(&data);
rc = sqlite_exec(data.db, zFirstCmd, callback, &data, &zErrMsg);
if( rc!=0 && zErrMsg!=0 ){
fprintf(stderr,"SQL error: %s\n", zErrMsg);
exit(1);
}
}
}else{
extern int isatty();
if( isatty(0) ){
/* Run commands received from standard input
*/
if( isatty(fileno(stdout)) && isatty(fileno(stdin)) ){
char *zHome;
char *zHistory = 0;
printf(
@@ -1189,6 +1349,6 @@ int main(int argc, char **argv){
}
}
set_table_name(&data, 0);
sqlite_close(db);
if( db ) sqlite_close(db);
return 0;
}
-596
View File
@@ -1,596 +0,0 @@
#!/usr/bin/wish
#
# A GUI shell for SQLite
#
# The following code is slighly modified from the original. See comments
# for the modifications...
############################################################################
# A console widget for Tcl/Tk. Invoke console:create with a window name,
# a prompt string, and a title to get a new top-level window that allows
# the user to enter tcl commands. This is mainly useful for testing and
# debugging.
#
# Copyright (C) 1998, 1999 D. Richard Hipp
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
# Author contact information:
# drh@acm.org
# http://www.hwaci.com/drh/
# Create a console widget named $w. The prompt string is $prompt.
# The title at the top of the window is $title
#
proc console:create {w prompt title} {
upvar #0 $w.t v
if {[winfo exists $w]} {destroy $w}
if {[info exists v]} {unset v}
toplevel $w
wm title $w $title
wm iconname $w $title
frame $w.mb -bd 2 -relief raised
pack $w.mb -side top -fill x
menubutton $w.mb.file -text File -menu $w.mb.file.m
menubutton $w.mb.edit -text Edit -menu $w.mb.edit.m
pack $w.mb.file $w.mb.edit -side left -padx 8 -pady 1
set m [menu $w.mb.file.m]
# $m add command -label {Source...} -command "console:SourceFile $w.t"
# $m add command -label {Save As...} -command "console:SaveFile $w.t"
# $m add separator
$m add command -label {Close} -command "destroy $w"
$m add command -label {Exit} -command exit
console:create_child $w $prompt $w.mb.edit.m
}
# This routine creates a console as a child window within a larger
# window. It also creates an edit menu named "$editmenu" if $editmenu!="".
# The calling function is responsible for posting the edit menu.
#
proc console:create_child {w prompt editmenu} {
upvar #0 $w.t v
if {$editmenu!=""} {
set m [menu $editmenu]
$m add command -label Cut -command "console:Cut $w.t"
$m add command -label Copy -command "console:Copy $w.t"
$m add command -label Paste -command "console:Paste $w.t"
$m add command -label {Clear Screen} -command "console:Clear $w.t"
$m add separator
$m add command -label {Source...} -command "console:SourceFile $w.t"
$m add command -label {Save As...} -command "console:SaveFile $w.t"
catch {$editmenu config -postcommand "console:EnableEditMenu $w"}
}
scrollbar $w.sb -orient vertical -command "$w.t yview"
pack $w.sb -side right -fill y
text $w.t -font fixed -yscrollcommand "$w.sb set"
pack $w.t -side right -fill both -expand 1
bindtags $w.t Console
set v(editmenu) $editmenu
set v(text) $w.t
set v(history) 0
set v(historycnt) 0
set v(current) -1
set v(prompt) $prompt
set v(prior) {}
set v(plength) [string length $v(prompt)]
set v(x) 0
set v(y) 0
$w.t mark set insert end
$w.t tag config ok -foreground blue
$w.t tag config err -foreground red
$w.t insert end $v(prompt)
$w.t mark set out 1.0
catch {rename puts console:oldputs$w}
proc puts args [format {
if {![winfo exists %s]} {
rename puts {}
rename console:oldputs%s puts
return [uplevel #0 puts $args]
}
switch -glob -- "[llength $args] $args" {
{1 *} {
set msg [lindex $args 0]\n
set tag ok
}
{2 stdout *} {
set msg [lindex $args 1]\n
set tag ok
}
{2 stderr *} {
set msg [lindex $args 1]\n
set tag err
}
{2 -nonewline *} {
set msg [lindex $args 1]
set tag ok
}
{3 -nonewline stdout *} {
set msg [lindex $args 2]
set tag ok
}
{3 -nonewline stderr *} {
set msg [lindex $args 2]
set tag err
}
default {
uplevel #0 console:oldputs%s $args
return
}
}
console:Puts %s $msg $tag
} $w $w $w $w.t]
after idle "focus $w.t"
}
bind Console <1> {console:Button1 %W %x %y}
bind Console <B1-Motion> {console:B1Motion %W %x %y}
bind Console <B1-Leave> {console:B1Leave %W %x %y}
bind Console <B1-Enter> {console:cancelMotor %W}
bind Console <ButtonRelease-1> {console:cancelMotor %W}
bind Console <KeyPress> {console:Insert %W %A}
bind Console <Left> {console:Left %W}
bind Console <Control-b> {console:Left %W}
bind Console <Right> {console:Right %W}
bind Console <Control-f> {console:Right %W}
bind Console <BackSpace> {console:Backspace %W}
bind Console <Control-h> {console:Backspace %W}
bind Console <Delete> {console:Delete %W}
bind Console <Control-d> {console:Delete %W}
bind Console <Home> {console:Home %W}
bind Console <Control-a> {console:Home %W}
bind Console <End> {console:End %W}
bind Console <Control-e> {console:End %W}
bind Console <Return> {console:Enter %W}
bind Console <KP_Enter> {console:Enter %W}
bind Console <Up> {console:Prior %W}
bind Console <Control-p> {console:Prior %W}
bind Console <Down> {console:Next %W}
bind Console <Control-n> {console:Next %W}
bind Console <Control-k> {console:EraseEOL %W}
bind Console <<Cut>> {console:Cut %W}
bind Console <<Copy>> {console:Copy %W}
bind Console <<Paste>> {console:Paste %W}
bind Console <<Clear>> {console:Clear %W}
# Insert test at the "out" mark. The "out" mark is always
# before the input line. New text appears on the line prior
# to the current input line.
#
proc console:Puts {w t tag} {
set nc [string length $t]
set endc [string index $t [expr $nc-1]]
if {$endc=="\n"} {
if {[$w index out]<[$w index {insert linestart}]} {
$w insert out [string range $t 0 [expr $nc-2]] $tag
$w mark set out {out linestart +1 lines}
} else {
$w insert out $t $tag
}
} else {
if {[$w index out]<[$w index {insert linestart}]} {
$w insert out $t $tag
} else {
$w insert out $t\n $tag
$w mark set out {out -1 char}
}
}
$w yview insert
}
# Insert a single character at the insertion cursor
#
proc console:Insert {w a} {
$w insert insert $a
$w yview insert
}
# Move the cursor one character to the left
#
proc console:Left {w} {
upvar #0 $w v
scan [$w index insert] %d.%d row col
if {$col>$v(plength)} {
$w mark set insert "insert -1c"
}
}
# Erase the character to the left of the cursor
#
proc console:Backspace {w} {
upvar #0 $w v
scan [$w index insert] %d.%d row col
if {$col>$v(plength)} {
$w delete {insert -1c}
}
}
# Erase to the end of the line
#
proc console:EraseEOL {w} {
upvar #0 $w v
scan [$w index insert] %d.%d row col
if {$col>=$v(plength)} {
$w delete insert {insert lineend}
}
}
# Move the cursor one character to the right
#
proc console:Right {w} {
$w mark set insert "insert +1c"
}
# Erase the character to the right of the cursor
#
proc console:Delete w {
$w delete insert
}
# Move the cursor to the beginning of the current line
#
proc console:Home w {
upvar #0 $w v
scan [$w index insert] %d.%d row col
$w mark set insert $row.$v(plength)
}
# Move the cursor to the end of the current line
#
proc console:End w {
$w mark set insert {insert lineend}
}
# Called when "Enter" is pressed. Do something with the line
# of text that was entered.
#
proc console:Enter w {
upvar #0 $w v
scan [$w index insert] %d.%d row col
set start $row.$v(plength)
set line [$w get $start "$start lineend"]
if {$v(historycnt)>0} {
set last [lindex $v(history) [expr $v(historycnt)-1]]
if {[string compare $last $line]} {
lappend v(history) $line
incr v(historycnt)
}
} else {
set v(history) [list $line]
set v(historycnt) 1
}
set v(current) $v(historycnt)
$w insert end \n
$w mark set out end
if {$v(prior)==""} {
set cmd $line
} else {
set cmd $v(prior)\n$line
}
##### Original
# if {[info complete $cmd]} { }
# set rc [catch {uplevel #0 $cmd} res]
##### New
global DB
if {[$DB complete $cmd]} {
set CODE {}
set rc [catch {$DB eval $cmd RESULT $CODE}]
##### End Of Changes
if {![winfo exists $w]} return
if {$rc} {
$w insert end $res\n err
} elseif {[string length $res]>0} {
$w insert end $res\n ok
}
set v(prior) {}
$w insert end $v(prompt)
} else {
set v(prior) $cmd
regsub -all {[^ ]} $v(prompt) . x
$w insert end $x
}
$w mark set insert end
$w mark set out {insert linestart}
$w yview insert
}
# Change the line to the previous line
#
proc console:Prior w {
upvar #0 $w v
if {$v(current)<=0} return
incr v(current) -1
set line [lindex $v(history) $v(current)]
console:SetLine $w $line
}
# Change the line to the next line
#
proc console:Next w {
upvar #0 $w v
if {$v(current)>=$v(historycnt)} return
incr v(current) 1
set line [lindex $v(history) $v(current)]
console:SetLine $w $line
}
# Change the contents of the entry line
#
proc console:SetLine {w line} {
upvar #0 $w v
scan [$w index insert] %d.%d row col
set start $row.$v(plength)
$w delete $start end
$w insert end $line
$w mark set insert end
$w yview insert
}
# Called when the mouse button is pressed at position $x,$y on
# the console widget.
#
proc console:Button1 {w x y} {
global tkPriv
upvar #0 $w v
set v(mouseMoved) 0
set v(pressX) $x
set p [console:nearestBoundry $w $x $y]
scan [$w index insert] %d.%d ix iy
scan $p %d.%d px py
if {$px==$ix} {
$w mark set insert $p
}
$w mark set anchor $p
focus $w
}
# Find the boundry between characters that is nearest
# to $x,$y
#
proc console:nearestBoundry {w x y} {
set p [$w index @$x,$y]
set bb [$w bbox $p]
if {![string compare $bb ""]} {return $p}
if {($x-[lindex $bb 0])<([lindex $bb 2]/2)} {return $p}
$w index "$p + 1 char"
}
# This routine extends the selection to the point specified by $x,$y
#
proc console:SelectTo {w x y} {
upvar #0 $w v
set cur [console:nearestBoundry $w $x $y]
if {[catch {$w index anchor}]} {
$w mark set anchor $cur
}
set anchor [$w index anchor]
if {[$w compare $cur != $anchor] || (abs($v(pressX) - $x) >= 3)} {
if {$v(mouseMoved)==0} {
$w tag remove sel 0.0 end
}
set v(mouseMoved) 1
}
if {[$w compare $cur < anchor]} {
set first $cur
set last anchor
} else {
set first anchor
set last $cur
}
if {$v(mouseMoved)} {
$w tag remove sel 0.0 $first
$w tag add sel $first $last
$w tag remove sel $last end
update idletasks
}
}
# Called whenever the mouse moves while button-1 is held down.
#
proc console:B1Motion {w x y} {
upvar #0 $w v
set v(y) $y
set v(x) $x
console:SelectTo $w $x $y
}
# Called whenever the mouse leaves the boundries of the widget
# while button 1 is held down.
#
proc console:B1Leave {w x y} {
upvar #0 $w v
set v(y) $y
set v(x) $x
console:motor $w
}
# This routine is called to automatically scroll the window when
# the mouse drags offscreen.
#
proc console:motor w {
upvar #0 $w v
if {![winfo exists $w]} return
if {$v(y)>=[winfo height $w]} {
$w yview scroll 1 units
} elseif {$v(y)<0} {
$w yview scroll -1 units
} else {
return
}
console:SelectTo $w $v(x) $v(y)
set v(timer) [after 50 console:motor $w]
}
# This routine cancels the scrolling motor if it is active
#
proc console:cancelMotor w {
upvar #0 $w v
catch {after cancel $v(timer)}
catch {unset v(timer)}
}
# Do a Copy operation on the stuff currently selected.
#
proc console:Copy w {
if {![catch {set text [$w get sel.first sel.last]}]} {
clipboard clear -displayof $w
clipboard append -displayof $w $text
}
}
# Return 1 if the selection exists and is contained
# entirely on the input line. Return 2 if the selection
# exists but is not entirely on the input line. Return 0
# if the selection does not exist.
#
proc console:canCut w {
set r [catch {
scan [$w index sel.first] %d.%d s1x s1y
scan [$w index sel.last] %d.%d s2x s2y
scan [$w index insert] %d.%d ix iy
}]
if {$r==1} {return 0}
if {$s1x==$ix && $s2x==$ix} {return 1}
return 2
}
# Do a Cut operation if possible. Cuts are only allowed
# if the current selection is entirely contained on the
# current input line.
#
proc console:Cut w {
if {[console:canCut $w]==1} {
console:Copy $w
$w delete sel.first sel.last
}
}
# Do a paste opeation.
#
proc console:Paste w {
if {[console:canCut $w]==1} {
$w delete sel.first sel.last
}
if {[catch {selection get -displayof $w -selection CLIPBOARD} topaste]} {
return
}
set prior 0
foreach line [split $topaste \n] {
if {$prior} {
console:Enter $w
update
}
set prior 1
$w insert insert $line
}
}
# Enable or disable entries in the Edit menu
#
proc console:EnableEditMenu w {
upvar #0 $w.t v
set m $v(editmenu)
if {$m=="" || ![winfo exists $m]} return
switch [console:canCut $w.t] {
0 {
$m entryconf Copy -state disabled
$m entryconf Cut -state disabled
}
1 {
$m entryconf Copy -state normal
$m entryconf Cut -state normal
}
2 {
$m entryconf Copy -state normal
$m entryconf Cut -state disabled
}
}
}
# Prompt for the user to select an input file, the "source" that file.
#
proc console:SourceFile w {
set types {
{{TCL Scripts} {.tcl}}
{{All Files} *}
}
set f [tk_getOpenFile -filetypes $types -title "TCL Script To Source..."]
if {$f!=""} {
uplevel #0 source $f
}
}
# Prompt the user for the name of a writable file. Then write the
# entire contents of the console screen to that file.
#
proc console:SaveFile w {
set types {
{{Text Files} {.txt}}
{{All Files} *}
}
set f [tk_getSaveFile -filetypes $types -title "Write Screen To..."]
if {$f!=""} {
if {[catch {open $f w} fd]} {
tk_messageBox -type ok -icon error -message $fd
} else {
puts $fd [string trimright [$w get 1.0 end] \n]
close $fd
}
}
}
# Erase everything from the console above the insertion line.
#
proc console:Clear w {
$w delete 1.0 {insert linestart}
}
# Start the console
#
# console:create {.@console} {% } {Tcl/Tk Console}
###############################################################################
if {[info command sqlite]==""} {
load ./tclsqlite.so sqlite
}
proc set_title {title} {
if {$title==""} {
set main SQLite
} else {
set main "SQLite - $title"
}
wm title . $main
wm iconname . SQLite
}
set_title {}
frame .mb -bd 1 -relief raised
pack .mb -side top -fill x
menubutton .mb.file -text File -underline 0 -menu .mb.file.m
pack .mb.file -side left -padx 5
set m [menu .mb.file.m]
$m add separator
$m add command -label Exit -command exit
menubutton .mb.edit -text Edit -underline 0 -menu .mb.edit.m
pack .mb.edit -side left -padx 5
#menu .mb.edit.m
frame .f
pack .f -side top -fill both -expand 1
console:create_child .f {sqlite> } .mb.edit.m
+377 -21
View File
@@ -12,17 +12,12 @@
** This header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite.h.in,v 1.34 2002/07/30 17:20:40 drh Exp $
** @(#) $Id: sqlite.h.in,v 1.60 2004/03/14 22:12:35 drh Exp $
*/
#ifndef _SQLITE_H_
#define _SQLITE_H_
#include <stdarg.h> /* Needed for the definition of va_list */
/*
** The version of the SQLite library.
*/
#define SQLITE_VERSION "--VERS--"
/*
** Make sure we can call this stuff from C++.
*/
@@ -30,6 +25,11 @@
extern "C" {
#endif
/*
** The version of the SQLite library.
*/
#define SQLITE_VERSION "--VERS--"
/*
** The version string is also compiled into the library so that a program
** can check to make sure that the lib*.a file and the *.h file are from
@@ -73,7 +73,7 @@ typedef struct sqlite sqlite;
** The Truth: As currently implemented, all databases are opened
** for writing all the time. Maybe someday we will provide the
** ability to open a database readonly. The mode parameters is
** provide in anticipation of that enhancement.
** provided in anticipation of that enhancement.
*/
sqlite *sqlite_open(const char *filename, int mode, char **errmsg);
@@ -118,7 +118,8 @@ typedef int (*sqlite_callback)(void*,int,char**, char**);
** message is written into memory obtained from malloc() and
** *errmsg is made to point to that message. The calling function
** is responsible for freeing the memory that holds the error
** message. If errmsg==NULL, then no error message is ever written.
** message. Use sqlite_freemem() for this. If errmsg==NULL,
** then no error message is ever written.
**
** The return value is is SQLITE_OK if there are no errors and
** some other return code if there is an error. The particular
@@ -138,7 +139,7 @@ int sqlite_exec(
);
/*
** Return values for sqlite_exec()
** Return values for sqlite_exec() and sqlite_step()
*/
#define SQLITE_OK 0 /* Successful result */
#define SQLITE_ERROR 1 /* SQL error or missing database */
@@ -162,6 +163,13 @@ int sqlite_exec(
#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */
#define SQLITE_MISMATCH 20 /* Data type mismatch */
#define SQLITE_MISUSE 21 /* Library used incorrectly */
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
#define SQLITE_AUTH 23 /* Authorization denied */
#define SQLITE_FORMAT 24 /* Auxiliary database format error */
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite_bind out of range */
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
#define SQLITE_ROW 100 /* sqlite_step() has another row ready */
#define SQLITE_DONE 101 /* sqlite_step() has finished executing */
/*
** Each entry in an SQLite table has a unique integer key. (The key is
@@ -196,6 +204,32 @@ int sqlite_last_insert_rowid(sqlite*);
*/
int sqlite_changes(sqlite*);
/*
** This function returns the number of database rows that were changed
** by the last INSERT, UPDATE, or DELETE statment executed by sqlite_exec(),
** or by the last VM to run to completion. The change count is not updated
** by SQL statements other than INSERT, UPDATE or DELETE.
**
** Changes are counted, even if they are later undone by a ROLLBACK or
** ABORT. Changes associated with trigger programs that execute as a
** result of the INSERT, UPDATE, or DELETE statement are not counted.
**
** If a callback invokes sqlite_exec() recursively, then the changes
** in the inner, recursive call are counted together with the changes
** in the outer call.
**
** SQLite implements the command "DELETE FROM table" without a WHERE clause
** by dropping and recreating the table. (This is much faster than going
** through and deleting individual elements form the table.) Because of
** this optimization, the change count for "DELETE FROM table" will be
** zero regardless of the number of elements that were originally in the
** table. To get an accurate count of the number of rows deleted, use
** "DELETE FROM table WHERE 1" instead.
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
int sqlite_last_statement_changes(sqlite*);
/* If the parameter to this routine is one of the return value constants
** defined above, then this routine returns a constant text string which
** descripts (in English) the meaning of the return value.
@@ -385,6 +419,7 @@ int sqlite_get_table_vprintf(
va_list ap /* Arguments to the format string */
);
char *sqlite_mprintf(const char*,...);
char *sqlite_vmprintf(const char*, va_list);
/*
** Windows systems should call this routine to free memory that
@@ -431,13 +466,12 @@ int sqlite_create_aggregate(
** Use the following routine to define the datatype returned by a
** user-defined function. The second argument can be one of the
** constants SQLITE_NUMERIC, SQLITE_TEXT, or SQLITE_ARGS or it
** can be an integer greater than or equal to zero. The datatype
** will be numeric or text (the only two types supported) if the
** argument is SQLITE_NUMERIC or SQLITE_TEXT. If the argument is
** SQLITE_ARGS, then the datatype is numeric if any argument to the
** function is numeric and is text otherwise. If the second argument
** is an integer, then the datatype of the result is the same as the
** parameter to the function that corresponds to that integer.
** can be an integer greater than or equal to zero. When the datatype
** parameter is non-negative, the type of the result will be the
** same as the datatype-th argument. If datatype==SQLITE_NUMERIC
** then the result is always numeric. If datatype==SQLITE_TEXT then
** the result is always text. If datatype==SQLITE_ARGS then the result
** is numeric if any argument is numeric and is text otherwise.
*/
int sqlite_function_type(
sqlite *db, /* The database there the function is registered */
@@ -498,12 +532,334 @@ void *sqlite_aggregate_context(sqlite_func*, int nBytes);
int sqlite_aggregate_count(sqlite_func*);
/*
** Attempt to open the file named in the argument as the auxiliary database
** file. The auxiliary database file is used to store TEMP tables. But
** by using this API, it is possible to trick SQLite into opening two
** separate databases and acting on them as if they were one.
** This routine registers a callback with the SQLite library. The
** callback is invoked (at compile-time, not at run-time) for each
** attempt to access a column of a table in the database. The callback
** returns SQLITE_OK if access is allowed, SQLITE_DENY if the entire
** SQL statement should be aborted with an error and SQLITE_IGNORE
** if the column should be treated as a NULL value.
*/
int sqlite_open_aux_file(sqlite *db, const char *zName, char **pzErrMsg);
int sqlite_set_authorizer(
sqlite*,
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
void *pUserData
);
/*
** The second parameter to the access authorization function above will
** be one of the values below. These values signify what kind of operation
** is to be authorized. The 3rd and 4th parameters to the authorization
** function will be parameters or NULL depending on which of the following
** codes is used as the second parameter. The 5th parameter is the name
** of the database ("main", "temp", etc.) if applicable. The 6th parameter
** is the name of the inner-most trigger or view that is responsible for
** the access attempt or NULL if this access attempt is directly from
** input SQL code.
**
** Arg-3 Arg-4
*/
#define SQLITE_COPY 0 /* Table Name File Name */
#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
#define SQLITE_CREATE_VIEW 8 /* View Name NULL */
#define SQLITE_DELETE 9 /* Table Name NULL */
#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
#define SQLITE_DROP_TABLE 11 /* Table Name NULL */
#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
#define SQLITE_DROP_VIEW 17 /* View Name NULL */
#define SQLITE_INSERT 18 /* Table Name NULL */
#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
#define SQLITE_READ 20 /* Table Name Column Name */
#define SQLITE_SELECT 21 /* NULL NULL */
#define SQLITE_TRANSACTION 22 /* NULL NULL */
#define SQLITE_UPDATE 23 /* Table Name Column Name */
#define SQLITE_ATTACH 24 /* Filename NULL */
#define SQLITE_DETACH 25 /* Database Name NULL */
/*
** The return value of the authorization function should be one of the
** following constants:
*/
/* #define SQLITE_OK 0 // Allow access (This is actually defined above) */
#define SQLITE_DENY 1 /* Abort the SQL statement with an error */
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
/*
** Register a function that is called at every invocation of sqlite_exec()
** or sqlite_compile(). This function can be used (for example) to generate
** a log file of all SQL executed against a database.
*/
void *sqlite_trace(sqlite*, void(*xTrace)(void*,const char*), void*);
/*** The Callback-Free API
**
** The following routines implement a new way to access SQLite that does not
** involve the use of callbacks.
**
** An sqlite_vm is an opaque object that represents a single SQL statement
** that is ready to be executed.
*/
typedef struct sqlite_vm sqlite_vm;
/*
** To execute an SQLite query without the use of callbacks, you first have
** to compile the SQL using this routine. The 1st parameter "db" is a pointer
** to an sqlite object obtained from sqlite_open(). The 2nd parameter
** "zSql" is the text of the SQL to be compiled. The remaining parameters
** are all outputs.
**
** *pzTail is made to point to the first character past the end of the first
** SQL statement in zSql. This routine only compiles the first statement
** in zSql, so *pzTail is left pointing to what remains uncompiled.
**
** *ppVm is left pointing to a "virtual machine" that can be used to execute
** the compiled statement. Or if there is an error, *ppVm may be set to NULL.
** If the input text contained no SQL (if the input is and empty string or
** a comment) then *ppVm is set to NULL.
**
** If any errors are detected during compilation, an error message is written
** into space obtained from malloc() and *pzErrMsg is made to point to that
** error message. The calling routine is responsible for freeing the text
** of this message when it has finished with it. Use sqlite_freemem() to
** free the message. pzErrMsg may be NULL in which case no error message
** will be generated.
**
** On success, SQLITE_OK is returned. Otherwise and error code is returned.
*/
int sqlite_compile(
sqlite *db, /* The open database */
const char *zSql, /* SQL statement to be compiled */
const char **pzTail, /* OUT: uncompiled tail of zSql */
sqlite_vm **ppVm, /* OUT: the virtual machine to execute zSql */
char **pzErrmsg /* OUT: Error message. */
);
/*
** After an SQL statement has been compiled, it is handed to this routine
** to be executed. This routine executes the statement as far as it can
** go then returns. The return value will be one of SQLITE_DONE,
** SQLITE_ERROR, SQLITE_BUSY, SQLITE_ROW, or SQLITE_MISUSE.
**
** SQLITE_DONE means that the execute of the SQL statement is complete
** an no errors have occurred. sqlite_step() should not be called again
** for the same virtual machine. *pN is set to the number of columns in
** the result set and *pazColName is set to an array of strings that
** describe the column names and datatypes. The name of the i-th column
** is (*pazColName)[i] and the datatype of the i-th column is
** (*pazColName)[i+*pN]. *pazValue is set to NULL.
**
** SQLITE_ERROR means that the virtual machine encountered a run-time
** error. sqlite_step() should not be called again for the same
** virtual machine. *pN is set to 0 and *pazColName and *pazValue are set
** to NULL. Use sqlite_finalize() to obtain the specific error code
** and the error message text for the error.
**
** SQLITE_BUSY means that an attempt to open the database failed because
** another thread or process is holding a lock. The calling routine
** can try again to open the database by calling sqlite_step() again.
** The return code will only be SQLITE_BUSY if no busy handler is registered
** using the sqlite_busy_handler() or sqlite_busy_timeout() routines. If
** a busy handler callback has been registered but returns 0, then this
** routine will return SQLITE_ERROR and sqltie_finalize() will return
** SQLITE_BUSY when it is called.
**
** SQLITE_ROW means that a single row of the result is now available.
** The data is contained in *pazValue. The value of the i-th column is
** (*azValue)[i]. *pN and *pazColName are set as described in SQLITE_DONE.
** Invoke sqlite_step() again to advance to the next row.
**
** SQLITE_MISUSE is returned if sqlite_step() is called incorrectly.
** For example, if you call sqlite_step() after the virtual machine
** has halted (after a prior call to sqlite_step() has returned SQLITE_DONE)
** or if you call sqlite_step() with an incorrectly initialized virtual
** machine or a virtual machine that has been deleted or that is associated
** with an sqlite structure that has been closed.
*/
int sqlite_step(
sqlite_vm *pVm, /* The virtual machine to execute */
int *pN, /* OUT: Number of columns in result */
const char ***pazValue, /* OUT: Column data */
const char ***pazColName /* OUT: Column names and datatypes */
);
/*
** This routine is called to delete a virtual machine after it has finished
** executing. The return value is the result code. SQLITE_OK is returned
** if the statement executed successfully and some other value is returned if
** there was any kind of error. If an error occurred and pzErrMsg is not
** NULL, then an error message is written into memory obtained from malloc()
** and *pzErrMsg is made to point to that error message. The calling routine
** should use sqlite_freemem() to delete this message when it has finished
** with it.
**
** This routine can be called at any point during the execution of the
** virtual machine. If the virtual machine has not completed execution
** when this routine is called, that is like encountering an error or
** an interrupt. (See sqlite_interrupt().) Incomplete updates may be
** rolled back and transactions cancelled, depending on the circumstances,
** and the result code returned will be SQLITE_ABORT.
*/
int sqlite_finalize(sqlite_vm*, char **pzErrMsg);
/*
** This routine deletes the virtual machine, writes any error message to
** *pzErrMsg and returns an SQLite return code in the same way as the
** sqlite_finalize() function.
**
** Additionally, if ppVm is not NULL, *ppVm is left pointing to a new virtual
** machine loaded with the compiled version of the original query ready for
** execution.
**
** If sqlite_reset() returns SQLITE_SCHEMA, then *ppVm is set to NULL.
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
int sqlite_reset(sqlite_vm*, char **pzErrMsg);
/*
** If the SQL that was handed to sqlite_compile contains variables that
** are represeted in the SQL text by a question mark ('?'). This routine
** is used to assign values to those variables.
**
** The first parameter is a virtual machine obtained from sqlite_compile().
** The 2nd "idx" parameter determines which variable in the SQL statement
** to bind the value to. The left most '?' is 1. The 3rd parameter is
** the value to assign to that variable. The 4th parameter is the number
** of bytes in the value, including the terminating \000 for strings.
** Finally, the 5th "copy" parameter is TRUE if SQLite should make its
** own private copy of this value, or false if the space that the 3rd
** parameter points to will be unchanging and can be used directly by
** SQLite.
**
** Unbound variables are treated as having a value of NULL. To explicitly
** set a variable to NULL, call this routine with the 3rd parameter as a
** NULL pointer.
**
** If the 4th "len" parameter is -1, then strlen() is used to find the
** length.
**
** This routine can only be called immediately after sqlite_compile()
** or sqlite_reset() and before any calls to sqlite_step().
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
int sqlite_bind(sqlite_vm*, int idx, const char *value, int len, int copy);
/*
** This routine configures a callback function - the progress callback - that
** is invoked periodically during long running calls to sqlite_exec(),
** sqlite_step() and sqlite_get_table(). An example use for this API is to keep
** a GUI updated during a large query.
**
** The progress callback is invoked once for every N virtual machine opcodes,
** where N is the second argument to this function. The progress callback
** itself is identified by the third argument to this function. The fourth
** argument to this function is a void pointer passed to the progress callback
** function each time it is invoked.
**
** If a call to sqlite_exec(), sqlite_step() or sqlite_get_table() results
** in less than N opcodes being executed, then the progress callback is not
** invoked.
**
** Calling this routine overwrites any previously installed progress callback.
** To remove the progress callback altogether, pass NULL as the third
** argument to this function.
**
** If the progress callback returns a result other than 0, then the current
** query is immediately terminated and any database changes rolled back. If the
** query was part of a larger transaction, then the transaction is not rolled
** back and remains active. The sqlite_exec() call returns SQLITE_ABORT.
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
void sqlite_progress_handler(sqlite*, int, int(*)(void*), void*);
/*
** Register a callback function to be invoked whenever a new transaction
** is committed. The pArg argument is passed through to the callback.
** callback. If the callback function returns non-zero, then the commit
** is converted into a rollback.
**
** If another function was previously registered, its pArg value is returned.
** Otherwise NULL is returned.
**
** Registering a NULL function disables the callback.
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
void *sqlite_commit_hook(sqlite*, int(*)(void*), void*);
/*
** Open an encrypted SQLite database. If pKey==0 or nKey==0, this routine
** is the same as sqlite_open().
**
** The code to implement this API is not available in the public release
** of SQLite.
*/
sqlite *sqlite_open_encrypted(
const char *zFilename, /* Name of the encrypted database */
const void *pKey, /* Pointer to the key */
int nKey, /* Number of bytes in the key */
int *pErrcode, /* Write error code here */
char **pzErrmsg /* Write error message here */
);
/*
** Change the key on an open database. If the current database is not
** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
** database is decrypted.
**
** The code to implement this API is not available in the public release
** of SQLite.
*/
int sqlite_rekey(
sqlite *db, /* Database to be rekeyed */
const void *pKey, int nKey /* The new key */
);
/*
** Encode a binary buffer "in" of size n bytes so that it contains
** no instances of characters '\'' or '\000'. The output is
** null-terminated and can be used as a string value in an INSERT
** or UPDATE statement. Use sqlite_decode_binary() to convert the
** string back into its original binary.
**
** The result is written into a preallocated output buffer "out".
** "out" must be able to hold at least 2 +(257*n)/254 bytes.
** In other words, the output will be expanded by as much as 3
** bytes for every 254 bytes of input plus 2 bytes of fixed overhead.
** (This is approximately 2 + 1.0118*n or about a 1.2% size increase.)
**
** The return value is the number of characters in the encoded
** string, excluding the "\000" terminator.
**
** If out==NULL then no output is generated but the routine still returns
** the number of characters that would have been generated if out had
** not been NULL.
*/
int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out);
/*
** Decode the string "in" into binary data and write it into "out".
** This routine reverses the encoding created by sqlite_encode_binary().
** The output will always be a few bytes less than the input. The number
** of bytes of output is returned. If the input is not a well-formed
** encoding, -1 is returned.
**
** The "in" and "out" parameters may point to the same buffer in order
** to decode a string in place.
*/
int sqlite_decode_binary(const unsigned char *in, unsigned char *out);
#ifdef __cplusplus
} /* End of the 'extern "C"' block */
+367 -109
View File
@@ -11,11 +11,11 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.146 2002/09/14 13:47:32 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.220 2004/02/25 13:47:33 drh Exp $
*/
#include "config.h"
#include "sqlite.h"
#include "hash.h"
#include "vdbe.h"
#include "parse.h"
#include "btree.h"
#include <stdio.h>
@@ -56,6 +56,39 @@
*/
#define NULL_DISTINCT_FOR_UNIQUE 1
/*
** The maximum number of attached databases. This must be at least 2
** in order to support the main database file (0) and the file used to
** hold temporary tables (1). And it must be less than 256 because
** an unsigned character is used to stored the database index.
*/
#define MAX_ATTACHED 10
/*
** The next macro is used to determine where TEMP tables and indices
** are stored. Possible values:
**
** 0 Always use a temporary files
** 1 Use a file unless overridden by "PRAGMA temp_store"
** 2 Use memory unless overridden by "PRAGMA temp_store"
** 3 Always use memory
*/
#ifndef TEMP_STORE
# define TEMP_STORE 1
#endif
/*
** When building SQLite for embedded systems where memory is scarce,
** you can define one or more of the following macros to omit extra
** features of the library and thus keep the size of the library to
** a minimum.
*/
/* #define SQLITE_OMIT_AUTHORIZATION 1 */
/* #define SQLITE_OMIT_INMEMORYDB 1 */
/* #define SQLITE_OMIT_VACUUM 1 */
/* #define SQLITE_OMIT_DATETIME_FUNCS 1 */
/* #define SQLITE_OMIT_PROGRESS_CALLBACK 1 */
/*
** Integers of known sizes. These typedefs might change for architectures
** where the sizes very. Preprocessor macros are available so that the
@@ -72,15 +105,37 @@
#ifndef UINT8_TYPE
# define UINT8_TYPE unsigned char
#endif
#ifndef INT8_TYPE
# define INT8_TYPE signed char
#endif
#ifndef INTPTR_TYPE
# define INTPTR_TYPE int
# if SQLITE_PTR_SZ==4
# define INTPTR_TYPE int
# else
# define INTPTR_TYPE long long
# endif
#endif
typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
typedef UINT8_TYPE i8; /* 1-byte signed integer */
typedef INTPTR_TYPE ptr; /* Big enough to hold a pointer */
typedef unsigned INTPTR_TYPE uptr; /* Big enough to hold a pointer */
/*
** Defer sourcing vdbe.h until after the "u8" typedef is defined.
*/
#include "vdbe.h"
/*
** Most C compilers these days recognize "long double", don't they?
** Just in case we encounter one that does not, we will create a macro
** for long double so that it can be easily changed to just "double".
*/
#ifndef LONGDOUBLE_TYPE
# define LONGDOUBLE_TYPE long double
#endif
/*
** This macro casts a pointer to an integer. Useful for doing
** pointer arithmetic.
@@ -96,8 +151,13 @@ typedef unsigned INTPTR_TYPE uptr; /* Big enough to hold a pointer */
** multi-megabyte records are OK. If your needs are different, you can
** change this define and recompile to increase or decrease the record
** size.
**
** The 16777198 is computed as follows: 238 bytes of payload on the
** original pages plus 16448 overflow pages each holding 1020 bytes of
** data.
*/
#define MAX_BYTES_PER_ROW 1048576
/* #define MAX_BYTES_PER_ROW 16777198 */
/*
** If memory allocation problems are found, recompile with
@@ -114,13 +174,15 @@ typedef unsigned INTPTR_TYPE uptr; /* Big enough to hold a pointer */
** by an AWK script to determine if there are any leaks.
*/
#ifdef MEMORY_DEBUG
# define sqliteMalloc(X) sqliteMalloc_(X,__FILE__,__LINE__)
# define sqliteMalloc(X) sqliteMalloc_(X,1,__FILE__,__LINE__)
# define sqliteMallocRaw(X) sqliteMalloc_(X,0,__FILE__,__LINE__)
# define sqliteFree(X) sqliteFree_(X,__FILE__,__LINE__)
# define sqliteRealloc(X,Y) sqliteRealloc_(X,Y,__FILE__,__LINE__)
# define sqliteStrDup(X) sqliteStrDup_(X,__FILE__,__LINE__)
# define sqliteStrNDup(X,Y) sqliteStrNDup_(X,Y,__FILE__,__LINE__)
void sqliteStrRealloc(char**);
#else
# define sqliteRealloc_(X,Y) sqliteRealloc(X,Y)
# define sqliteStrRealloc(X)
#endif
@@ -148,6 +210,11 @@ extern int sqlite_iMallocFail; /* Fail sqliteMalloc() after this many calls */
#define MASTER_NAME "sqlite_master"
#define TEMP_MASTER_NAME "sqlite_temp_master"
/*
** The name of the schema table.
*/
#define SCHEMA_TABLE(x) (x?TEMP_MASTER_NAME:MASTER_NAME)
/*
** A convenience macro that returns the number of elements in
** an array.
@@ -176,6 +243,61 @@ typedef struct Trigger Trigger;
typedef struct TriggerStep TriggerStep;
typedef struct TriggerStack TriggerStack;
typedef struct FKey FKey;
typedef struct Db Db;
typedef struct AuthContext AuthContext;
/*
** Each database file to be accessed by the system is an instance
** of the following structure. There are normally two of these structures
** in the sqlite.aDb[] array. aDb[0] is the main database file and
** aDb[1] is the database file used to hold temporary tables. Additional
** databases may be attached.
*/
struct Db {
char *zName; /* Name of this database */
Btree *pBt; /* The B*Tree structure for this database file */
int schema_cookie; /* Database schema version number for this file */
Hash tblHash; /* All tables indexed by name */
Hash idxHash; /* All (named) indices indexed by name */
Hash trigHash; /* All triggers indexed by name */
Hash aFKey; /* Foreign keys indexed by to-table */
u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */
u16 flags; /* Flags associated with this database */
void *pAux; /* Auxiliary data. Usually NULL */
void (*xFreeAux)(void*); /* Routine to free pAux */
};
/*
** These macros can be used to test, set, or clear bits in the
** Db.flags field.
*/
#define DbHasProperty(D,I,P) (((D)->aDb[I].flags&(P))==(P))
#define DbHasAnyProperty(D,I,P) (((D)->aDb[I].flags&(P))!=0)
#define DbSetProperty(D,I,P) (D)->aDb[I].flags|=(P)
#define DbClearProperty(D,I,P) (D)->aDb[I].flags&=~(P)
/*
** Allowed values for the DB.flags field.
**
** The DB_Locked flag is set when the first OP_Transaction or OP_Checkpoint
** opcode is emitted for a database. This prevents multiple occurances
** of those opcodes for the same database in the same program. Similarly,
** the DB_Cookie flag is set when the OP_VerifyCookie opcode is emitted,
** and prevents duplicate OP_VerifyCookies from taking up space and slowing
** down execution.
**
** The DB_SchemaLoaded flag is set after the database schema has been
** read into internal hash tables.
**
** DB_UnresetViews means that one or more views have column names that
** have been filled out. If the schema changes, these column names might
** changes and so the view will need to be reset.
*/
#define DB_Locked 0x0001 /* OP_Transaction opcode has been emitted */
#define DB_Cookie 0x0002 /* OP_VerifyCookie opcode has been emiited */
#define DB_SchemaLoaded 0x0004 /* The schema has been loaded */
#define DB_UnresetViews 0x0008 /* Some views have defined column names */
/*
** Each database is an instance of the following structure.
@@ -191,33 +313,80 @@ typedef struct FKey FKey;
** file_format==3 Version 2.6.0. Fix empty-string index bug.
** file_format==4 Version 2.7.0. Add support for separate numeric and
** text datatypes.
**
** The sqlite.temp_store determines where temporary database files
** are stored. If 1, then a file is created to hold those tables. If
** 2, then they are held in memory. 0 means use the default value in
** the TEMP_STORE macro.
**
** The sqlite.lastRowid records the last insert rowid generated by an
** insert statement. Inserts on views do not affect its value. Each
** trigger has its own context, so that lastRowid can be updated inside
** triggers as usual. The previous value will be restored once the trigger
** exits. Upon entering a before or instead of trigger, lastRowid is no
** longer (since after version 2.8.12) reset to -1.
**
** The sqlite.nChange does not count changes within triggers and keeps no
** context. It is reset at start of sqlite_exec.
** The sqlite.lsChange represents the number of changes made by the last
** insert, update, or delete statement. It remains constant throughout the
** length of a statement and is then updated by OP_SetCounts. It keeps a
** context stack just like lastRowid so that the count of changes
** within a trigger is not seen outside the trigger. Changes to views do not
** affect the value of lsChange.
** The sqlite.csChange keeps track of the number of current changes (since
** the last statement) and is used to update sqlite_lsChange.
*/
struct sqlite {
Btree *pBe; /* The B*Tree backend */
Btree *pBeTemp; /* Backend for session temporary tables */
int nDb; /* Number of backends currently in use */
Db *aDb; /* All backends */
Db aDbStatic[2]; /* Static space for the 2 default backends */
int flags; /* Miscellanous flags. See below */
int file_format; /* What file format version is this database? */
int schema_cookie; /* Magic number that changes with the schema */
int next_cookie; /* Value of schema_cookie after commit */
u8 file_format; /* What file format version is this database? */
u8 safety_level; /* How aggressive at synching data to disk */
u8 want_to_close; /* Close after all VDBEs are deallocated */
u8 temp_store; /* 1=file, 2=memory, 0=compile-time default */
u8 onError; /* Default conflict algorithm */
int next_cookie; /* Next value of aDb[0].schema_cookie */
int cache_size; /* Number of pages to use in the cache */
int nTable; /* Number of tables in the database */
void *pBusyArg; /* 1st Argument to the busy callback */
int (*xBusyCallback)(void *,const char*,int); /* The busy callback */
Hash tblHash; /* All tables indexed by name */
Hash idxHash; /* All (named) indices indexed by name */
Hash trigHash; /* All triggers indexed by name */
void *pCommitArg; /* Argument to xCommitCallback() */
int (*xCommitCallback)(void*);/* Invoked at every commit. */
Hash aFunc; /* All functions that can be in SQL exprs */
Hash aFKey; /* Foreign keys indexed by to-table */
int lastRowid; /* ROWID of most recent insert */
int lastRowid; /* ROWID of most recent insert (see above) */
int priorNewRowid; /* Last randomly generated ROWID */
int onError; /* Default conflict algorithm */
int magic; /* Magic number for detect library misuse */
int nChange; /* Number of rows changed */
int recursionDepth; /* Number of nested calls to sqlite_exec() */
int nChange; /* Number of rows changed (see above) */
int lsChange; /* Last statement change count (see above) */
int csChange; /* Current statement change count (see above) */
struct sqliteInitInfo { /* Information used during initialization */
int iDb; /* When back is being initialized */
int newTnum; /* Rootpage of table being initialized */
u8 busy; /* TRUE if currently initializing */
} init;
struct Vdbe *pVdbe; /* List of active virtual machines */
void (*xTrace)(void*,const char*); /* Trace function */
void *pTraceArg; /* Argument to the trace function */
#ifndef SQLITE_OMIT_AUTHORIZATION
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
/* Access authorization function */
void *pAuthArg; /* 1st argument to the access auth function */
#endif
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
int (*xProgress)(void *); /* The progress callback */
void *pProgressArg; /* Argument to the progress callback */
int nProgressOps; /* Number of opcodes for progress callback */
#endif
};
/*
** Possible values for the sqlite.flags.
** Possible values for the sqlite.flags and or Db.flags fields.
**
** On sqlite.flags, the SQLITE_InTrans value means that we have
** executed a BEGIN. On Db.flags, SQLITE_InTrans means a statement
** transaction is active on that particular database file.
*/
#define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
#define SQLITE_Initialized 0x00000002 /* True after initialization */
@@ -225,15 +394,13 @@ struct sqlite {
#define SQLITE_InTrans 0x00000008 /* True if in a transaction */
#define SQLITE_InternChanges 0x00000010 /* Uncommitted Hash table changes */
#define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */
#define SQLITE_CountRows 0x00000040 /* Count rows changed by INSERT, */
#define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
#define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */
/* DELETE, or UPDATE and return */
/* the count using a callback. */
#define SQLITE_NullCallback 0x00000080 /* Invoke the callback once if the */
#define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
/* result set is empty */
#define SQLITE_ResultDetails 0x00000100 /* Details added to result set */
#define SQLITE_UnresetViews 0x00000200 /* True if one or more views have */
/* defined column names */
#define SQLITE_ReportTypes 0x00000400 /* Include information on datatypes */
#define SQLITE_ReportTypes 0x00000200 /* Include information on datatypes */
/* in 4th argument of callback */
/*
@@ -256,10 +423,12 @@ struct FuncDef {
void (*xFunc)(sqlite_func*,int,const char**); /* Regular function */
void (*xStep)(sqlite_func*,int,const char**); /* Aggregate function step */
void (*xFinalize)(sqlite_func*); /* Aggregate function finializer */
int nArg; /* Number of arguments */
int dataType; /* Datatype of the result */
void *pUserData; /* User data parameter */
FuncDef *pNext; /* Next function with same name */
signed char nArg; /* Number of arguments. -1 means unlimited */
signed char dataType; /* Arg that determines datatype. -1=NUMERIC, */
/* -2=TEXT. -3=SQLITE_ARGS */
u8 includeTypes; /* Add datatypes to args of xFunc and xStep */
void *pUserData; /* User data parameter */
FuncDef *pNext; /* Next function with same name */
};
/*
@@ -271,8 +440,9 @@ struct Column {
char *zDflt; /* Default value of this column */
char *zType; /* Data type for this column */
u8 notNull; /* True if there is a NOT NULL constraint */
u8 isPrimKey; /* True if this column is an INTEGER PRIMARY KEY */
u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */
u8 sortOrder; /* Some combination of SQLITE_SO_... values */
u8 dottedName; /* True if zName contains a "." character */
};
/*
@@ -293,26 +463,27 @@ struct Column {
** Each SQL table is represented in memory by an instance of the
** following structure.
**
** Expr.zName is the name of the table. The case of the original
** Table.zName is the name of the table. The case of the original
** CREATE TABLE statement is stored, but case is not significant for
** comparisons.
**
** Expr.nCol is the number of columns in this table. Expr.aCol is a
** Table.nCol is the number of columns in this table. Table.aCol is a
** pointer to an array of Column structures, one for each column.
**
** If the table has an INTEGER PRIMARY KEY, then Expr.iPKey is the index of
** the column that is that key. Otherwise Expr.iPKey is negative. Note
** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
** the column that is that key. Otherwise Table.iPKey is negative. Note
** that the datatype of the PRIMARY KEY must be INTEGER for this field to
** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
** is generated for each row of the table. Expr.hasPrimKey is true if
** is generated for each row of the table. Table.hasPrimKey is true if
** the table has any PRIMARY KEY, INTEGER or otherwise.
**
** Expr.tnum is the page number for the root BTree page of the table in the
** database file. If Expr.isTemp is true, then this page occurs in the
** auxiliary database file, not the main database file. If Expr.isTransient
** Table.tnum is the page number for the root BTree page of the table in the
** database file. If Table.iDb is the index of the database table backend
** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
** holds temporary tables and indices. If Table.isTransient
** is true, then the table is stored in a file that is automatically deleted
** when the VDBE cursor to the table is closed. In this case Expr.tnum
** when the VDBE cursor to the table is closed. In this case Table.tnum
** refers VDBE cursor number that holds the table open, not to the root
** page number. Transient tables are used to hold the results of a
** sub-query that appears instead of a real table name in the FROM clause
@@ -327,7 +498,7 @@ struct Table {
int tnum; /* Root BTree node for this table (see note above) */
Select *pSelect; /* NULL for tables. Points to definition if a view. */
u8 readOnly; /* True if this table should not be written by the user */
u8 isTemp; /* True if stored in db->pBeTemp instead of db->pBe */
u8 iDb; /* Index into sqlite.aDb[] of the backend for this table */
u8 isTransient; /* True if automatically deleted when VDBE finishes */
u8 hasPrimKey; /* True if there exists a primary key */
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
@@ -355,7 +526,7 @@ struct Table {
** the from-table is created. The existance of the to-table is not checked
** until an attempt is made to insert data into the from-table.
**
** The sqlite.aFKey hash table stores pointers to to this structure
** The sqlite.aFKey hash table stores pointers to this structure
** given the name of a to-table. For each to-table, all foreign keys
** associated with that table are on a linked list using the FKey.pNextTo
** field.
@@ -398,7 +569,7 @@ struct FKey {
** referenced table row is propagated into the row that holds the
** foreign key.
**
** The following there symbolic values are used to record which type
** The following symbolic values are used to record which type
** of action to take.
*/
#define OE_None 0 /* There is no constraint to check */
@@ -433,6 +604,13 @@ struct FKey {
** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
** The second column to be indexed (c1) has an index of 0 in
** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
**
** The Index.onError field determines whether or not the indexed columns
** must be unique and what to do if they are not. When Index.onError=OE_None,
** it means this is not a unique index. Otherwise it is a unique index
** and the value of Index.onError indicate the which conflict resolution
** algorithm to employ whenever an attempt is made to insert a non-unique
** element.
*/
struct Index {
char *zName; /* Name of this index */
@@ -440,9 +618,9 @@ struct Index {
int *aiColumn; /* Which columns are used by this index. 1st is 0 */
Table *pTable; /* The SQL table being indexed */
int tnum; /* Page containing root of this index in database file */
u8 isUnique; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
u8 iDb; /* Index in sqlite.aDb[] of where this index is stored */
Index *pNext; /* The next index associated with the same table */
};
@@ -450,17 +628,14 @@ struct Index {
** Each token coming out of the lexer is an instance of
** this structure. Tokens are also used as part of an expression.
**
** A "base" token is a real single token such as would come out of the
** lexer. There are also compound tokens which are aggregates of one
** or more base tokens. Compound tokens are used to name columns in the
** result set of a SELECT statement. In the expression "a+b+c", "b"
** is a base token but "a+b" is a compound token.
** Note if Token.z==0 then Token.dyn and Token.n are undefined and
** may contain random values. Do not make any assuptions about Token.dyn
** and Token.n when Token.z==0.
*/
struct Token {
const char *z; /* Text of the token. Not NULL-terminated! */
unsigned dyn : 1; /* True for malloced memory, false for static */
unsigned base : 1; /* True for a base token, false for compounds */
unsigned n : 30; /* Number of characters in this token */
unsigned n : 31; /* Number of characters in this token */
};
/*
@@ -490,7 +665,9 @@ struct Token {
** it can be accessed after all aggregates are computed.
**
** If the expression is a function, the Expr.iTable is an integer code
** representing which function.
** representing which function. If the expression is an unbound variable
** marker (a question mark character '?' in the original SQL) then the
** Expr.iTable holds the index number for that variable.
**
** The Expr.pSelect field points to a SELECT statement. The SELECT might
** be the right operand of an IN operator. Or, if a scalar SELECT appears
@@ -500,12 +677,13 @@ struct Token {
struct Expr {
u8 op; /* Operation performed by this node */
u8 dataType; /* Either SQLITE_SO_TEXT or SQLITE_SO_NUM */
u8 isJoinExpr; /* Origin is the ON or USING phrase of a join */
u8 nFuncName; /* Number of characters in a function name */
u8 iDb; /* Database referenced by this expression */
u8 flags; /* Various flags. See below */
Expr *pLeft, *pRight; /* Left and right subnodes */
ExprList *pList; /* A list of expressions used as function arguments
** or in "<expr> IN (<expr-list)" */
Token token; /* An operand token */
Token span; /* Complete text of the expression */
int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the
** iColumn-th field of the iTable-th table. */
int iAgg; /* When op==TK_COLUMN and pParse->useAgg==TRUE, pull
@@ -514,6 +692,20 @@ struct Expr {
** right side of "<expr> IN (<select>)" */
};
/*
** The following are the meanings of bits in the Expr.flags field.
*/
#define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
/*
** These macros can be used to test, set, or clear bits in the
** Expr.flags field.
*/
#define ExprHasProperty(E,P) (((E)->flags&(P))==(P))
#define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)
#define ExprSetProperty(E,P) (E)->flags|=(P)
#define ExprClearProperty(E,P) (E)->flags&=~(P)
/*
** A list of expressions. Each expression may optionally have a
** name. An expr/name combination can be used in several ways, such
@@ -524,6 +716,7 @@ struct Expr {
*/
struct ExprList {
int nExpr; /* Number of expressions on the list */
int nAlloc; /* Number of entries allocated below */
struct ExprList_item {
Expr *pExpr; /* The list of expressions */
char *zName; /* Token associated with this expression */
@@ -550,6 +743,7 @@ struct ExprList {
*/
struct IdList {
int nId; /* Number of identifiers on the list */
int nAlloc; /* Number of entries allocated for a[] below */
struct IdList_item {
char *zName; /* Name of the identifier */
int idx; /* Index in some Table.aCol[] of a column named zName */
@@ -560,18 +754,27 @@ struct IdList {
** The following structure describes the FROM clause of a SELECT statement.
** Each table or subquery in the FROM clause is a separate element of
** the SrcList.a[] array.
**
** With the addition of multiple database support, the following structure
** can also be used to describe a particular table such as the table that
** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
** such a table must be a simple name: ID. But in SQLite, the table can
** now be identified by a database name, a dot, then the table name: ID.ID.
*/
struct SrcList {
int nSrc; /* Number of tables or subqueries in the FROM clause */
u16 nSrc; /* Number of tables or subqueries in the FROM clause */
u16 nAlloc; /* Number of entries allocated in a[] below */
struct SrcList_item {
char *zDatabase; /* Name of database holding this table */
char *zName; /* Name of the table */
char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
Table *pTab; /* An SQL table corresponding to zName */
Select *pSelect; /* A SELECT statement used in place of a table name */
int jointype; /* Type of join between this table and the next */
int iCursor; /* The VDBE cursor number used to access this table */
Expr *pOn; /* The ON clause of a join */
IdList *pUsing; /* The USING clause of a join */
} *a; /* One entry for each identifier on the list */
} a[1]; /* One entry for each identifier on the list */
};
/*
@@ -601,6 +804,7 @@ struct WhereLevel {
int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
int top; /* First instruction of interior of the loop */
int inOp, inP1, inP2;/* Opcode used to implement an IN operator */
int bRev; /* Do the scan in the reverse direction */
};
/*
@@ -615,7 +819,6 @@ struct WhereInfo {
SrcList *pTabList; /* List of tables in the join */
int iContinue; /* Jump here to continue with next record */
int iBreak; /* Jump here to break out of the loop */
int base; /* Index of first Open opcode */
int nLevel; /* Number of nested loop */
int savedNTab; /* Value of pParse->nTab before WhereBegin() */
int peakNTab; /* Value of pParse->nTab after WhereBegin() */
@@ -641,18 +844,18 @@ struct WhereInfo {
** in the VDBE that record the limit and offset counters.
*/
struct Select {
int isDistinct; /* True if the DISTINCT keyword is present */
ExprList *pEList; /* The fields of the result */
u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
u8 isDistinct; /* True if the DISTINCT keyword is present */
SrcList *pSrc; /* The FROM clause */
Expr *pWhere; /* The WHERE clause */
ExprList *pGroupBy; /* The GROUP BY clause */
Expr *pHaving; /* The HAVING clause */
ExprList *pOrderBy; /* The ORDER BY clause */
int op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
Select *pPrior; /* Prior select in a compound select statement */
int nLimit, nOffset; /* LIMIT and OFFSET values. -1 means not used */
int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
char *zSelect; /* Complete text of the SELECT command */
int base; /* Index of VDBE cursor for left-most FROM table */
};
/*
@@ -701,35 +904,47 @@ struct AggExpr {
*/
struct Parse {
sqlite *db; /* The main database structure */
Btree *pBe; /* The database backend */
int rc; /* Return code from execution */
sqlite_callback xCallback; /* The callback function */
void *pArg; /* First argument to the callback function */
char *zErrMsg; /* An error message */
Token sErrToken; /* The token at which the error occurred */
Token sFirstToken; /* The first token parsed */
Token sLastToken; /* The last token parsed */
const char *zTail; /* All SQL text past the last semicolon parsed */
Table *pNewTable; /* A table being constructed by CREATE TABLE */
Vdbe *pVdbe; /* An engine for executing database bytecode */
u8 colNamesSet; /* TRUE after OP_ColumnCount has been issued to pVdbe */
u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
u8 explain; /* True if the EXPLAIN flag is found on the query */
u8 initFlag; /* True if reparsing CREATE TABLEs */
u8 nameClash; /* A permanent table name clashes with temp table name */
u8 useAgg; /* If true, extract field values from the aggregator
** while generating expressions. Normally false */
u8 schemaVerified; /* True if an OP_VerifySchema has been coded someplace
** other than after an OP_Transaction */
u8 isTemp; /* True if parsing temporary tables */
int newTnum; /* Table number to use when reparsing CREATE TABLEs */
int nErr; /* Number of errors seen */
int nTab; /* Number of previously allocated VDBE cursors */
int nMem; /* Number of memory cells used so far */
int nSet; /* Number of sets used so far */
int nAgg; /* Number of aggregate expressions */
int nVar; /* Number of '?' variables seen in the SQL so far */
AggExpr *aAgg; /* An array of aggregate expressions */
TriggerStack *trigStack;
const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
TriggerStack *trigStack; /* Trigger actions being coded */
};
/*
** An instance of the following structure can be declared on a stack and used
** to save the Parse.zAuthContext value so that it can be restored later.
*/
struct AuthContext {
const char *zAuthContext; /* Put saved Parse.zAuthContext here */
Parse *pParse; /* The Parse structure */
};
/*
** Bitfield flags for P2 value in OP_PutIntKey and OP_Delete
*/
#define OPFLAG_NCHANGE 1 /* Set to update db->nChange */
#define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */
#define OPFLAG_CSCHANGE 4 /* Set to update db->csChange */
/*
* Each trigger present in the database schema is stored as an instance of
* struct Trigger.
@@ -744,28 +959,19 @@ struct Parse {
*
* The "step_list" member points to the first element of a linked list
* containing the SQL statements specified as the trigger program.
*
* When a trigger is initially created, the "isCommit" member is set to FALSE.
* When a transaction is rolled back, any Trigger structures with "isCommit" set
* to FALSE are deleted by the logic in sqliteRollbackInternalChanges(). When
* a transaction is commited, the "isCommit" member is set to TRUE for any
* Trigger structures for which it is FALSE.
*
* When a trigger is dropped, using the sqliteDropTrigger() interfaced, it is
* removed from the trigHash hash table and added to the trigDrop hash table.
* If the transaction is rolled back, the trigger is re-added into the trigHash
* hash table (and hence the database schema). If the transaction is commited,
* then the Trigger structure is deleted permanently.
*/
struct Trigger {
char *name; /* The name of the trigger */
char *table; /* The table or view to which the trigger applies */
int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
int tr_tm; /* One of TK_BEFORE, TK_AFTER */
u8 iDb; /* Database containing this trigger */
u8 iTabDb; /* Database containing Trigger.table */
u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
u8 tr_tm; /* One of TK_BEFORE, TK_AFTER */
Expr *pWhen; /* The WHEN clause of the expresion (may be NULL) */
IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
the <column-list> is stored here */
int foreach; /* One of TK_ROW or TK_STATEMENT */
Token nameToken; /* Token containing zName. Use during parsing only */
TriggerStep *step_list; /* Link list of trigger program steps */
Trigger *pNext; /* Next trigger associated with the table */
@@ -812,6 +1018,7 @@ struct Trigger {
struct TriggerStep {
int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
int orconf; /* OE_Rollback etc. */
Trigger *pTrig; /* The trigger that this step is a part of */
Select *pSelect; /* Valid for SELECT and sometimes
INSERT steps (when pExprList == 0) */
@@ -857,9 +1064,21 @@ struct TriggerStack {
int oldIdx; /* Index of vdbe cursor to "old" temp table */
int orconf; /* Current orconf policy */
int ignoreJump; /* where to jump to for a RAISE(IGNORE) */
Trigger *pTrigger;
Trigger *pTrigger; /* The trigger currently being coded */
TriggerStack *pNext; /* Next trigger down on the trigger stack */
};
TriggerStack *pNext;
/*
** The following structure contains information used by the sqliteFix...
** routines as they walk the parse tree to make database references
** explicit.
*/
typedef struct DbFixer DbFixer;
struct DbFixer {
Parse *pParse; /* The parsing context. Error messages written here */
const char *zDb; /* Make sure all objects are contained in this database */
const char *zType; /* Type of the container - used for error messages */
const Token *pName; /* Name of the container - used for error messages */
};
/*
@@ -875,24 +1094,31 @@ extern int always_code_trigger_setup;
int sqliteStrICmp(const char *, const char *);
int sqliteStrNICmp(const char *, const char *, int);
int sqliteHashNoCase(const char *, int);
int sqliteIsNumber(const char*);
int sqliteCompare(const char *, const char *);
int sqliteSortCompare(const char *, const char *);
void sqliteRealToSortable(double r, char *);
#ifdef MEMORY_DEBUG
void *sqliteMalloc_(int,char*,int);
void *sqliteMalloc_(int,int,char*,int);
void sqliteFree_(void*,char*,int);
void *sqliteRealloc_(void*,int,char*,int);
char *sqliteStrDup_(const char*,char*,int);
char *sqliteStrNDup_(const char*, int,char*,int);
void sqliteCheckMemory(void*,int);
#else
void *sqliteMalloc(int);
void *sqliteMallocRaw(int);
void sqliteFree(void*);
void *sqliteRealloc(void*,int);
char *sqliteStrDup(const char*);
char *sqliteStrNDup(const char*, int);
# define sqliteCheckMemory(a,b)
#endif
char *sqliteMPrintf(const char*, ...);
char *sqliteVMPrintf(const char*, va_list);
void sqliteSetString(char **, const char *, ...);
void sqliteSetNString(char **, ...);
void sqliteErrorMsg(Parse*, const char*, ...);
void sqliteDequote(char*);
int sqliteKeywordCode(const char*, int);
int sqliteRunParser(Parse*, const char*, char **);
@@ -903,37 +1129,37 @@ Expr *sqliteExprFunction(ExprList*, Token*);
void sqliteExprDelete(Expr*);
ExprList *sqliteExprListAppend(ExprList*,Expr*,Token*);
void sqliteExprListDelete(ExprList*);
void sqlitePragma(Parse*,Token*,Token*,int);
void sqliteResetInternalSchema(sqlite*);
int sqliteInit(sqlite*, char**);
void sqlitePragma(Parse*,Token*,Token*,int);
void sqliteResetInternalSchema(sqlite*, int);
void sqliteBeginParse(Parse*,int);
void sqliteRollbackInternalChanges(sqlite*);
void sqliteCommitInternalChanges(sqlite*);
Table *sqliteResultSetOfSelect(Parse*,char*,Select*);
void sqliteOpenMasterTable(Vdbe *v, int);
void sqliteStartTable(Parse*,Token*,Token*,int);
void sqliteStartTable(Parse*,Token*,Token*,int,int);
void sqliteAddColumn(Parse*,Token*);
void sqliteAddNotNull(Parse*, int);
void sqliteAddPrimaryKey(Parse*, IdList*, int);
void sqliteAddColumnType(Parse*,Token*,Token*);
void sqliteAddDefaultValue(Parse*,Token*,int);
int sqliteCollateType(Parse*, Token*);
int sqliteCollateType(const char*, int);
void sqliteAddCollateType(Parse*, int);
void sqliteEndTable(Parse*,Token*,Select*);
void sqliteCreateView(Parse*,Token*,Token*,Select*,int);
int sqliteViewGetColumnNames(Parse*,Table*);
void sqliteViewResetAll(sqlite*);
void sqliteDropTable(Parse*, Token*, int);
void sqliteDeleteTable(sqlite*, Table*);
void sqliteInsert(Parse*, Token*, ExprList*, Select*, IdList*, int);
void sqliteInsert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
IdList *sqliteIdListAppend(IdList*, Token*);
int sqliteIdListIndex(IdList*,const char*);
SrcList *sqliteSrcListAppend(SrcList*, Token*);
SrcList *sqliteSrcListAppend(SrcList*, Token*, Token*);
void sqliteSrcListAddAlias(SrcList*, Token*);
void sqliteSrcListAssignCursors(Parse*, SrcList*);
void sqliteIdListDelete(IdList*);
void sqliteSrcListDelete(SrcList*);
void sqliteCreateIndex(Parse*, Token*, Token*, IdList*, int, Token*, Token*);
void sqliteDropIndex(Parse*, Token*);
void sqliteCreateIndex(Parse*,Token*,SrcList*,IdList*,int,Token*,Token*);
void sqliteDropIndex(Parse*, SrcList*);
void sqliteAddKeyType(Vdbe*, ExprList*);
void sqliteAddIdxKeyType(Vdbe*, Index*);
int sqliteSelect(Parse*, Select*, int, int, Select*, int, int*);
@@ -941,20 +1167,23 @@ Select *sqliteSelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*,
int,int,int);
void sqliteSelectDelete(Select*);
void sqliteSelectUnbind(Select*);
Table *sqliteTableNameToTable(Parse*, const char*);
SrcList *sqliteTableTokenToSrcList(Parse*, Token*);
void sqliteDeleteFrom(Parse*, Token*, Expr*);
void sqliteUpdate(Parse*, Token*, ExprList*, Expr*, int);
WhereInfo *sqliteWhereBegin(Parse*, int, SrcList*, Expr*, int, ExprList**);
Table *sqliteSrcListLookup(Parse*, SrcList*);
int sqliteIsReadOnly(Parse*, Table*, int);
void sqliteDeleteFrom(Parse*, SrcList*, Expr*);
void sqliteUpdate(Parse*, SrcList*, ExprList*, Expr*, int);
WhereInfo *sqliteWhereBegin(Parse*, SrcList*, Expr*, int, ExprList**);
void sqliteWhereEnd(WhereInfo*);
void sqliteExprCode(Parse*, Expr*);
int sqliteExprCodeExprList(Parse*, ExprList*, int);
void sqliteExprIfTrue(Parse*, Expr*, int, int);
void sqliteExprIfFalse(Parse*, Expr*, int, int);
Table *sqliteFindTable(sqlite*,const char*);
Index *sqliteFindIndex(sqlite*,const char*);
Table *sqliteFindTable(sqlite*,const char*, const char*);
Table *sqliteLocateTable(Parse*,const char*, const char*);
Index *sqliteFindIndex(sqlite*,const char*, const char*);
void sqliteUnlinkAndDeleteIndex(sqlite*,Index*);
void sqliteCopy(Parse*, Token*, Token*, Token*, int);
void sqliteCopy(Parse*, SrcList*, Token*, Token*, int);
void sqliteVacuum(Parse*, Token*);
int sqliteRunVacuum(char**, sqlite*);
int sqliteGlobCompare(const unsigned char*,const unsigned char*);
int sqliteLikeCompare(const unsigned char*,const unsigned char*);
char *sqliteTableNameFromToken(Token*);
@@ -962,11 +1191,12 @@ int sqliteExprCheck(Parse*, Expr*, int, int*);
int sqliteExprType(Expr*);
int sqliteExprCompare(Expr*, Expr*);
int sqliteFuncId(Token*);
int sqliteExprResolveIds(Parse*, int, SrcList*, ExprList*, Expr*);
int sqliteExprResolveIds(Parse*, SrcList*, ExprList*, Expr*);
int sqliteExprAnalyzeAggregates(Parse*, Expr*);
Vdbe *sqliteGetVdbe(Parse*);
int sqliteRandomByte(void);
int sqliteRandomInteger(void);
void sqliteRandomness(int, void*);
void sqliteRollbackAll(sqlite*);
void sqliteCodeVerifySchema(Parse*, int);
void sqliteBeginTransaction(Parse*, int);
void sqliteCommitTransaction(Parse*);
void sqliteRollbackTransaction(Parse*);
@@ -976,7 +1206,8 @@ int sqliteIsRowid(const char*);
void sqliteGenerateRowDelete(sqlite*, Vdbe*, Table*, int, int);
void sqliteGenerateRowIndexDelete(sqlite*, Vdbe*, Table*, int, char*);
void sqliteGenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
void sqliteCompleteInsertion(Parse*, Table*, int, char*, int, int);
void sqliteCompleteInsertion(Parse*, Table*, int, char*, int, int, int);
int sqliteOpenTableAndIndices(Parse*, Table*, int);
void sqliteBeginWriteOperation(Parse*, int, int);
void sqliteEndWriteOperation(Parse*);
Expr *sqliteExprDup(Expr*);
@@ -987,17 +1218,20 @@ IdList *sqliteIdListDup(IdList*);
Select *sqliteSelectDup(Select*);
FuncDef *sqliteFindFunction(sqlite*,const char*,int,int,int);
void sqliteRegisterBuiltinFunctions(sqlite*);
void sqliteRegisterDateTimeFunctions(sqlite*);
int sqliteSafetyOn(sqlite*);
int sqliteSafetyOff(sqlite*);
int sqliteSafetyCheck(sqlite*);
void sqliteChangeCookie(sqlite*, Vdbe*);
void sqliteCreateTrigger(Parse*, Token*, int, int, IdList*, Token*,
int, Expr*, TriggerStep*, Token*);
void sqliteDropTrigger(Parse*, Token*, int);
void sqliteBeginTrigger(Parse*, Token*,int,int,IdList*,SrcList*,int,Expr*,int);
void sqliteFinishTrigger(Parse*, TriggerStep*, Token*);
void sqliteDropTrigger(Parse*, SrcList*);
void sqliteDropTriggerPtr(Parse*, Trigger*, int);
int sqliteTriggersExist(Parse* , Trigger* , int , int , int, ExprList*);
int sqliteCodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int,
int, int);
void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
void sqliteDeleteTriggerStep(TriggerStep*);
TriggerStep *sqliteTriggerSelectStep(Select*);
TriggerStep *sqliteTriggerInsertStep(Token*, IdList*, ExprList*, Select*, int);
TriggerStep *sqliteTriggerUpdateStep(Token*, ExprList*, Expr*, int);
@@ -1006,3 +1240,27 @@ void sqliteDeleteTrigger(Trigger*);
int sqliteJoinType(Parse*, Token*, Token*, Token*);
void sqliteCreateForeignKey(Parse*, IdList*, Token*, IdList*, int);
void sqliteDeferForeignKey(Parse*, int);
#ifndef SQLITE_OMIT_AUTHORIZATION
void sqliteAuthRead(Parse*,Expr*,SrcList*);
int sqliteAuthCheck(Parse*,int, const char*, const char*, const char*);
void sqliteAuthContextPush(Parse*, AuthContext*, const char*);
void sqliteAuthContextPop(AuthContext*);
#else
# define sqliteAuthRead(a,b,c)
# define sqliteAuthCheck(a,b,c,d,e) SQLITE_OK
# define sqliteAuthContextPush(a,b,c)
# define sqliteAuthContextPop(a) ((void)(a))
#endif
void sqliteAttach(Parse*, Token*, Token*, Token*);
void sqliteDetach(Parse*, Token*);
int sqliteBtreeFactory(const sqlite *db, const char *zFilename,
int mode, int nPg, Btree **ppBtree);
int sqliteFixInit(DbFixer*, Parse*, int, const char*, const Token*);
int sqliteFixSrcList(DbFixer*, SrcList*);
int sqliteFixSelect(DbFixer*, Select*);
int sqliteFixExpr(DbFixer*, Expr*);
int sqliteFixExprList(DbFixer*, ExprList*);
int sqliteFixTriggerStep(DbFixer*, TriggerStep*);
double sqliteAtoF(const char *z, const char **);
char *sqlite_snprintf(int,char*,const char*,...);
int sqliteFitsIn32Bits(const char *);
+5 -2
View File
@@ -85,7 +85,8 @@ static int sqlite_get_table_cb(void *pArg, int nCol, char **argv, char **colv){
}
}else if( p->nColumn!=nCol ){
sqliteSetString(&p->zErrMsg,
"sqlite_get_table() called with two or more incompatible queries", 0);
"sqlite_get_table() called with two or more incompatible queries",
(char*)0);
p->rc = SQLITE_ERROR;
return 1;
}
@@ -172,10 +173,11 @@ int sqlite_get_table(
if( res.nAlloc>res.nData ){
char **azNew;
azNew = realloc( res.azResult, sizeof(char*)*(res.nData+1) );
if( res.azResult==0 ){
if( azNew==0 ){
sqlite_free_table(&res.azResult[1]);
return SQLITE_NOMEM;
}
res.nAlloc = res.nData+1;
res.azResult = azNew;
}
*pazResult = &res.azResult[1];
@@ -193,6 +195,7 @@ void sqlite_free_table(
if( azResult ){
int i, n;
azResult--;
if( azResult==0 ) return;
n = (int)azResult[0];
for(i=1; i<n; i++){ if( azResult[i] ) free(azResult[i]); }
free(azResult);
+466 -39
View File
@@ -11,7 +11,7 @@
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.42 2002/09/14 13:47:32 drh Exp $
** $Id: tclsqlite.c,v 1.59 2004/02/25 22:51:06 rdc Exp $
*/
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
@@ -51,7 +51,12 @@ struct SqliteDb {
sqlite *db; /* The "real" database structure */
Tcl_Interp *interp; /* The interpreter used for this database */
char *zBusy; /* The busy callback routine */
char *zCommit; /* The commit hook callback routine */
char *zTrace; /* The trace callback routine */
char *zProgress; /* The progress callback routine */
char *zAuth; /* The authorization callback routine */
SqlFunc *pFunc; /* List of SQL functions */
int rc; /* Return code of most recent sqlite_exec() */
};
/*
@@ -245,6 +250,35 @@ static int DbEvalCallback2(
return 0;
}
/*
** This is a second alternative callback for database queries. A the
** first column of the first row of the result is made the TCL result.
*/
static int DbEvalCallback3(
void *clientData, /* An instance of CallbackData */
int nCol, /* Number of columns in the result */
char ** azCol, /* Data for each column */
char ** azN /* Name for each column */
){
Tcl_Interp *interp = (Tcl_Interp*)clientData;
Tcl_Obj *pElem;
if( azCol==0 ) return 1;
if( nCol==0 ) return 1;
#ifdef UTF_TRANSLATION_NEEDED
{
Tcl_DString dCol;
Tcl_DStringInit(&dCol);
Tcl_ExternalToUtfDString(NULL, azCol[0], -1, &dCol);
pElem = Tcl_NewStringObj(Tcl_DStringValue(&dCol), -1);
Tcl_DStringFree(&dCol);
}
#else
pElem = Tcl_NewStringObj(azCol[0], -1);
#endif
Tcl_SetObjResult(interp, pElem);
return 1;
}
/*
** Called when the command is deleted.
*/
@@ -259,6 +293,12 @@ static void DbDeleteCmd(void *db){
if( pDb->zBusy ){
Tcl_Free(pDb->zBusy);
}
if( pDb->zTrace ){
Tcl_Free(pDb->zTrace);
}
if( pDb->zAuth ){
Tcl_Free(pDb->zAuth);
}
Tcl_Free((char*)pDb);
}
@@ -287,6 +327,54 @@ static int DbBusyHandler(void *cd, const char *zTable, int nTries){
return 1;
}
/*
** This routine is invoked as the 'progress callback' for the database.
*/
static int DbProgressHandler(void *cd){
SqliteDb *pDb = (SqliteDb*)cd;
int rc;
assert( pDb->zProgress );
rc = Tcl_Eval(pDb->interp, pDb->zProgress);
if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){
return 1;
}
return 0;
}
/*
** This routine is called by the SQLite trace handler whenever a new
** block of SQL is executed. The TCL script in pDb->zTrace is executed.
*/
static void DbTraceHandler(void *cd, const char *zSql){
SqliteDb *pDb = (SqliteDb*)cd;
Tcl_DString str;
Tcl_DStringInit(&str);
Tcl_DStringAppend(&str, pDb->zTrace, -1);
Tcl_DStringAppendElement(&str, zSql);
Tcl_Eval(pDb->interp, Tcl_DStringValue(&str));
Tcl_DStringFree(&str);
Tcl_ResetResult(pDb->interp);
}
/*
** This routine is called when a transaction is committed. The
** TCL script in pDb->zCommit is executed. If it returns non-zero or
** if it throws an exception, the transaction is rolled back instead
** of being committed.
*/
static int DbCommitHandler(void *cd){
SqliteDb *pDb = (SqliteDb*)cd;
int rc;
rc = Tcl_Eval(pDb->interp, pDb->zCommit);
if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){
return 1;
}
return 0;
}
/*
** This routine is called to evaluate an SQL function implemented
** using TCL script.
@@ -309,6 +397,78 @@ static void tclSqlFunc(sqlite_func *context, int argc, const char **argv){
sqlite_set_result_string(context, Tcl_GetStringResult(p->interp), -1);
}
}
#ifndef SQLITE_OMIT_AUTHORIZATION
/*
** This is the authentication function. It appends the authentication
** type code and the two arguments to zCmd[] then invokes the result
** on the interpreter. The reply is examined to determine if the
** authentication fails or succeeds.
*/
static int auth_callback(
void *pArg,
int code,
const char *zArg1,
const char *zArg2,
const char *zArg3,
const char *zArg4
){
char *zCode;
Tcl_DString str;
int rc;
const char *zReply;
SqliteDb *pDb = (SqliteDb*)pArg;
switch( code ){
case SQLITE_COPY : zCode="SQLITE_COPY"; break;
case SQLITE_CREATE_INDEX : zCode="SQLITE_CREATE_INDEX"; break;
case SQLITE_CREATE_TABLE : zCode="SQLITE_CREATE_TABLE"; break;
case SQLITE_CREATE_TEMP_INDEX : zCode="SQLITE_CREATE_TEMP_INDEX"; break;
case SQLITE_CREATE_TEMP_TABLE : zCode="SQLITE_CREATE_TEMP_TABLE"; break;
case SQLITE_CREATE_TEMP_TRIGGER: zCode="SQLITE_CREATE_TEMP_TRIGGER"; break;
case SQLITE_CREATE_TEMP_VIEW : zCode="SQLITE_CREATE_TEMP_VIEW"; break;
case SQLITE_CREATE_TRIGGER : zCode="SQLITE_CREATE_TRIGGER"; break;
case SQLITE_CREATE_VIEW : zCode="SQLITE_CREATE_VIEW"; break;
case SQLITE_DELETE : zCode="SQLITE_DELETE"; break;
case SQLITE_DROP_INDEX : zCode="SQLITE_DROP_INDEX"; break;
case SQLITE_DROP_TABLE : zCode="SQLITE_DROP_TABLE"; break;
case SQLITE_DROP_TEMP_INDEX : zCode="SQLITE_DROP_TEMP_INDEX"; break;
case SQLITE_DROP_TEMP_TABLE : zCode="SQLITE_DROP_TEMP_TABLE"; break;
case SQLITE_DROP_TEMP_TRIGGER : zCode="SQLITE_DROP_TEMP_TRIGGER"; break;
case SQLITE_DROP_TEMP_VIEW : zCode="SQLITE_DROP_TEMP_VIEW"; break;
case SQLITE_DROP_TRIGGER : zCode="SQLITE_DROP_TRIGGER"; break;
case SQLITE_DROP_VIEW : zCode="SQLITE_DROP_VIEW"; break;
case SQLITE_INSERT : zCode="SQLITE_INSERT"; break;
case SQLITE_PRAGMA : zCode="SQLITE_PRAGMA"; break;
case SQLITE_READ : zCode="SQLITE_READ"; break;
case SQLITE_SELECT : zCode="SQLITE_SELECT"; break;
case SQLITE_TRANSACTION : zCode="SQLITE_TRANSACTION"; break;
case SQLITE_UPDATE : zCode="SQLITE_UPDATE"; break;
case SQLITE_ATTACH : zCode="SQLITE_ATTACH"; break;
case SQLITE_DETACH : zCode="SQLITE_DETACH"; break;
default : zCode="????"; break;
}
Tcl_DStringInit(&str);
Tcl_DStringAppend(&str, pDb->zAuth, -1);
Tcl_DStringAppendElement(&str, zCode);
Tcl_DStringAppendElement(&str, zArg1 ? zArg1 : "");
Tcl_DStringAppendElement(&str, zArg2 ? zArg2 : "");
Tcl_DStringAppendElement(&str, zArg3 ? zArg3 : "");
Tcl_DStringAppendElement(&str, zArg4 ? zArg4 : "");
rc = Tcl_GlobalEval(pDb->interp, Tcl_DStringValue(&str));
Tcl_DStringFree(&str);
zReply = Tcl_GetStringResult(pDb->interp);
if( strcmp(zReply,"SQLITE_OK")==0 ){
rc = SQLITE_OK;
}else if( strcmp(zReply,"SQLITE_DENY")==0 ){
rc = SQLITE_DENY;
}else if( strcmp(zReply,"SQLITE_IGNORE")==0 ){
rc = SQLITE_IGNORE;
}else{
rc = 999;
}
return rc;
}
#endif /* SQLITE_OMIT_AUTHORIZATION */
/*
** The "sqlite" command below creates a new Tcl command for each
@@ -326,16 +486,23 @@ static void tclSqlFunc(sqlite_func *context, int argc, const char **argv){
static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
SqliteDb *pDb = (SqliteDb*)cd;
int choice;
int rc = TCL_OK;
static const char *DB_strs[] = {
"busy", "changes", "close",
"complete", "eval", "function",
"last_insert_rowid", "open_aux_file", "timeout",
"authorizer", "busy", "changes",
"close", "commit_hook", "complete",
"errorcode", "eval", "function",
"last_insert_rowid", "last_statement_changes", "onecolumn",
"progress", "rekey", "timeout",
"trace",
0
};
enum DB_enum {
DB_BUSY, DB_CHANGES, DB_CLOSE,
DB_COMPLETE, DB_EVAL, DB_FUNCTION,
DB_LAST_INSERT_ROWID, DB_OPEN_AUX_FILE, DB_TIMEOUT,
DB_AUTHORIZER, DB_BUSY, DB_CHANGES,
DB_CLOSE, DB_COMMIT_HOOK, DB_COMPLETE,
DB_ERRORCODE, DB_EVAL, DB_FUNCTION,
DB_LAST_INSERT_ROWID, DB_LAST_STATEMENT_CHANGES, DB_ONECOLUMN,
DB_PROGRESS, DB_REKEY, DB_TIMEOUT,
DB_TRACE
};
if( objc<2 ){
@@ -348,6 +515,56 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
switch( (enum DB_enum)choice ){
/* $db authorizer ?CALLBACK?
**
** Invoke the given callback to authorize each SQL operation as it is
** compiled. 5 arguments are appended to the callback before it is
** invoked:
**
** (1) The authorization type (ex: SQLITE_CREATE_TABLE, SQLITE_INSERT, ...)
** (2) First descriptive name (depends on authorization type)
** (3) Second descriptive name
** (4) Name of the database (ex: "main", "temp")
** (5) Name of trigger that is doing the access
**
** The callback should return on of the following strings: SQLITE_OK,
** SQLITE_IGNORE, or SQLITE_DENY. Any other return value is an error.
**
** If this method is invoked with no arguments, the current authorization
** callback string is returned.
*/
case DB_AUTHORIZER: {
if( objc>3 ){
Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
}else if( objc==2 ){
if( pDb->zAuth ){
Tcl_AppendResult(interp, pDb->zAuth, 0);
}
}else{
char *zAuth;
int len;
if( pDb->zAuth ){
Tcl_Free(pDb->zAuth);
}
zAuth = Tcl_GetStringFromObj(objv[2], &len);
if( zAuth && len>0 ){
pDb->zAuth = Tcl_Alloc( len + 1 );
strcpy(pDb->zAuth, zAuth);
}else{
pDb->zAuth = 0;
}
#ifndef SQLITE_OMIT_AUTHORIZATION
if( pDb->zAuth ){
pDb->interp = interp;
sqlite_set_authorizer(pDb->db, auth_callback, pDb);
}else{
sqlite_set_authorizer(pDb->db, 0, 0);
}
#endif
}
break;
}
/* $db busy ?CALLBACK?
**
** Invoke the given callback if an SQL statement attempts to open
@@ -384,6 +601,48 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
break;
}
/* $db progress ?N CALLBACK?
**
** Invoke the given callback every N virtual machine opcodes while executing
** queries.
*/
case DB_PROGRESS: {
if( objc==2 ){
if( pDb->zProgress ){
Tcl_AppendResult(interp, pDb->zProgress, 0);
}
}else if( objc==4 ){
char *zProgress;
int len;
int N;
if( TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &N) ){
return TCL_ERROR;
};
if( pDb->zProgress ){
Tcl_Free(pDb->zProgress);
}
zProgress = Tcl_GetStringFromObj(objv[3], &len);
if( zProgress && len>0 ){
pDb->zProgress = Tcl_Alloc( len + 1 );
strcpy(pDb->zProgress, zProgress);
}else{
pDb->zProgress = 0;
}
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
if( pDb->zProgress ){
pDb->interp = interp;
sqlite_progress_handler(pDb->db, N, DbProgressHandler, pDb);
}else{
sqlite_progress_handler(pDb->db, 0, 0, 0);
}
#endif
}else{
Tcl_WrongNumArgs(interp, 2, objv, "N CALLBACK");
return TCL_ERROR;
}
break;
}
/*
** $db changes
**
@@ -403,6 +662,26 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
break;
}
/*
** $db last_statement_changes
**
** Return the number of rows that were modified, inserted, or deleted by
** the last statment to complete execution (excluding changes due to
** triggers)
*/
case DB_LAST_STATEMENT_CHANGES: {
Tcl_Obj *pResult;
int lsChange;
if( objc!=2 ){
Tcl_WrongNumArgs(interp, 2, objv, "");
return TCL_ERROR;
}
lsChange = sqlite_last_statement_changes(pDb->db);
pResult = Tcl_GetObjResult(interp);
Tcl_SetIntObj(pResult, lsChange);
break;
}
/* $db close
**
** Shutdown the database
@@ -412,6 +691,43 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
break;
}
/* $db commit_hook ?CALLBACK?
**
** Invoke the given callback just before committing every SQL transaction.
** If the callback throws an exception or returns non-zero, then the
** transaction is aborted. If CALLBACK is an empty string, the callback
** is disabled.
*/
case DB_COMMIT_HOOK: {
if( objc>3 ){
Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
}else if( objc==2 ){
if( pDb->zCommit ){
Tcl_AppendResult(interp, pDb->zCommit, 0);
}
}else{
char *zCommit;
int len;
if( pDb->zCommit ){
Tcl_Free(pDb->zCommit);
}
zCommit = Tcl_GetStringFromObj(objv[2], &len);
if( zCommit && len>0 ){
pDb->zCommit = Tcl_Alloc( len + 1 );
strcpy(pDb->zCommit, zCommit);
}else{
pDb->zCommit = 0;
}
if( pDb->zCommit ){
pDb->interp = interp;
sqlite_commit_hook(pDb->db, DbCommitHandler, pDb);
}else{
sqlite_commit_hook(pDb->db, 0, 0);
}
}
break;
}
/* $db complete SQL
**
** Return TRUE if SQL is a complete SQL statement. Return FALSE if
@@ -430,6 +746,17 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
Tcl_SetBooleanObj(pResult, isComplete);
break;
}
/*
** $db errorcode
**
** Return the numeric error code that was returned by the most recent
** call to sqlite_exec().
*/
case DB_ERRORCODE: {
Tcl_SetObjResult(interp, Tcl_NewIntObj(pDb->rc));
break;
}
/*
** $db eval $sql ?array { ...code... }?
@@ -444,7 +771,6 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
CallbackData cbData;
char *zErrMsg;
char *zSql;
int rc;
#ifdef UTF_TRANSLATION_NEEDED
Tcl_DString dSql;
int i;
@@ -483,6 +809,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
rc = sqlite_exec(pDb->db, zSql, DbEvalCallback2, pList, &zErrMsg);
Tcl_SetObjResult(interp, pList);
}
pDb->rc = rc;
if( rc==SQLITE_ABORT ){
if( zErrMsg ) free(zErrMsg);
rc = cbData.tcl_rc;
@@ -556,30 +883,52 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
}
/*
** $db open_aux_file FILENAME
** $db onecolumn SQL
**
** Begin using FILENAME as the database file used to store temporary
** tables.
** Return a single column from a single row of the given SQL query.
*/
case DB_OPEN_AUX_FILE: {
const char *zFilename;
case DB_ONECOLUMN: {
char *zSql;
char *zErrMsg = 0;
int rc;
if( objc!=3 ){
Tcl_WrongNumArgs(interp, 2, objv, "FILENAME");
Tcl_WrongNumArgs(interp, 2, objv, "SQL");
return TCL_ERROR;
}
zFilename = Tcl_GetStringFromObj(objv[2], 0);
rc = sqlite_open_aux_file(pDb->db, zFilename, &zErrMsg);
if( rc!=0 ){
if( zErrMsg ){
Tcl_AppendResult(interp, zErrMsg, 0);
free(zErrMsg);
}else{
Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
}
zSql = Tcl_GetStringFromObj(objv[2], 0);
rc = sqlite_exec(pDb->db, zSql, DbEvalCallback3, interp, &zErrMsg);
if( rc==SQLITE_ABORT ){
rc = SQLITE_OK;
}else if( zErrMsg ){
Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
free(zErrMsg);
rc = TCL_ERROR;
}else if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
rc = TCL_ERROR;
}
break;
}
/*
** $db rekey KEY
**
** Change the encryption key on the currently open database.
*/
case DB_REKEY: {
int nKey;
void *pKey;
if( objc!=3 ){
Tcl_WrongNumArgs(interp, 2, objv, "KEY");
return TCL_ERROR;
}
pKey = Tcl_GetByteArrayFromObj(objv[2], &nKey);
#ifdef SQLITE_HAS_CODEC
rc = sqlite_rekey(pDb->db, pKey, nKey);
if( rc ){
Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
rc = TCL_ERROR;
}
#endif
break;
}
@@ -598,12 +947,49 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
sqlite_busy_timeout(pDb->db, ms);
break;
}
/* $db trace ?CALLBACK?
**
** Make arrangements to invoke the CALLBACK routine for each SQL statement
** that is executed. The text of the SQL is appended to CALLBACK before
** it is executed.
*/
case DB_TRACE: {
if( objc>3 ){
Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
}else if( objc==2 ){
if( pDb->zTrace ){
Tcl_AppendResult(interp, pDb->zTrace, 0);
}
}else{
char *zTrace;
int len;
if( pDb->zTrace ){
Tcl_Free(pDb->zTrace);
}
zTrace = Tcl_GetStringFromObj(objv[2], &len);
if( zTrace && len>0 ){
pDb->zTrace = Tcl_Alloc( len + 1 );
strcpy(pDb->zTrace, zTrace);
}else{
pDb->zTrace = 0;
}
if( pDb->zTrace ){
pDb->interp = interp;
sqlite_trace(pDb->db, DbTraceHandler, pDb);
}else{
sqlite_trace(pDb->db, 0, 0);
}
}
break;
}
} /* End of the SWITCH statement */
return TCL_OK;
return rc;
}
/*
** sqlite DBNAME FILENAME ?MODE?
** sqlite DBNAME FILENAME ?MODE? ?-key KEY?
**
** This is the main Tcl command. When the "sqlite" Tcl command is
** invoked, this routine runs to process that command.
@@ -623,23 +1009,44 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
** Return the encoding used by LIKE and GLOB operators. Choices
** are UTF-8 and iso8859.
**
** sqlite -version
**
** Return the version number of the SQLite library.
**
** sqlite -tcl-uses-utf
**
** Return "1" if compiled with a Tcl uses UTF-8. Return "0" if
** not. Used by tests to make sure the library was compiled
** correctly.
*/
static int DbMain(void *cd, Tcl_Interp *interp, int argc, char **argv){
static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
int mode;
SqliteDb *p;
void *pKey = 0;
int nKey = 0;
const char *zArg;
char *zErrMsg;
const char *zFile;
char zBuf[80];
if( argc==2 ){
if( strcmp(argv[1],"-encoding")==0 ){
if( objc==2 ){
zArg = Tcl_GetStringFromObj(objv[1], 0);
if( strcmp(zArg,"-encoding")==0 ){
Tcl_AppendResult(interp,sqlite_encoding,0);
return TCL_OK;
}
if( strcmp(argv[1],"-tcl-uses-utf")==0 ){
if( strcmp(zArg,"-version")==0 ){
Tcl_AppendResult(interp,sqlite_version,0);
return TCL_OK;
}
if( strcmp(zArg,"-has-codec")==0 ){
#ifdef SQLITE_HAS_CODEC
Tcl_AppendResult(interp,"1",0);
#else
Tcl_AppendResult(interp,"0",0);
#endif
return TCL_OK;
}
if( strcmp(zArg,"-tcl-uses-utf")==0 ){
#ifdef TCL_UTF_MAX
Tcl_AppendResult(interp,"1",0);
#else
@@ -648,14 +1055,26 @@ static int DbMain(void *cd, Tcl_Interp *interp, int argc, char **argv){
return TCL_OK;
}
}
if( argc!=3 && argc!=4 ){
Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0],
" HANDLE FILENAME ?MODE?\"", 0);
if( objc==5 || objc==6 ){
zArg = Tcl_GetStringFromObj(objv[objc-2], 0);
if( strcmp(zArg,"-key")==0 ){
pKey = Tcl_GetByteArrayFromObj(objv[objc-1], &nKey);
objc -= 2;
}
}
if( objc!=3 && objc!=4 ){
Tcl_WrongNumArgs(interp, 1, objv,
#ifdef SQLITE_HAS_CODEC
"HANDLE FILENAME ?-key CODEC-KEY?"
#else
"HANDLE FILENAME ?MODE?"
#endif
);
return TCL_ERROR;
}
if( argc==3 ){
if( objc==3 ){
mode = 0666;
}else if( Tcl_GetInt(interp, argv[3], &mode)!=TCL_OK ){
}else if( Tcl_GetIntFromObj(interp, objv[3], &mode)!=TCL_OK ){
return TCL_ERROR;
}
zErrMsg = 0;
@@ -665,14 +1084,20 @@ static int DbMain(void *cd, Tcl_Interp *interp, int argc, char **argv){
return TCL_ERROR;
}
memset(p, 0, sizeof(*p));
p->db = sqlite_open(argv[2], mode, &zErrMsg);
zFile = Tcl_GetStringFromObj(objv[2], 0);
#ifdef SQLITE_HAS_CODEC
p->db = sqlite_open_encrypted(zFile, pKey, nKey, 0, &zErrMsg);
#else
p->db = sqlite_open(zFile, mode, &zErrMsg);
#endif
if( p->db==0 ){
Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
Tcl_Free((char*)p);
free(zErrMsg);
return TCL_ERROR;
}
Tcl_CreateObjCommand(interp, argv[1], DbObjCmd, (char*)p, DbDeleteCmd);
zArg = Tcl_GetStringFromObj(objv[1], 0);
Tcl_CreateObjCommand(interp, zArg, DbObjCmd, (char*)p, DbDeleteCmd);
/* The return value is the value of the sqlite* pointer
*/
@@ -714,13 +1139,13 @@ static int DbMain(void *cd, Tcl_Interp *interp, int argc, char **argv){
*/
int Sqlite_Init(Tcl_Interp *interp){
Tcl_InitStubs(interp, "8.0", 0);
Tcl_CreateCommand(interp, "sqlite", (Tcl_CmdProc*)DbMain, 0, 0);
Tcl_CreateObjCommand(interp, "sqlite", (Tcl_ObjCmdProc*)DbMain, 0, 0);
Tcl_PkgProvide(interp, "sqlite", "2.0");
return TCL_OK;
}
int Tclsqlite_Init(Tcl_Interp *interp){
Tcl_InitStubs(interp, "8.0", 0);
Tcl_CreateCommand(interp, "sqlite", (Tcl_CmdProc*)DbMain, 0, 0);
Tcl_CreateObjCommand(interp, "sqlite", (Tcl_ObjCmdProc*)DbMain, 0, 0);
Tcl_PkgProvide(interp, "sqlite", "2.0");
return TCL_OK;
}
@@ -780,10 +1205,12 @@ int TCLSH_MAIN(int argc, char **argv){
extern int Sqlitetest1_Init(Tcl_Interp*);
extern int Sqlitetest2_Init(Tcl_Interp*);
extern int Sqlitetest3_Init(Tcl_Interp*);
extern int Sqlitetest4_Init(Tcl_Interp*);
extern int Md5_Init(Tcl_Interp*);
Sqlitetest1_Init(interp);
Sqlitetest2_Init(interp);
Sqlitetest3_Init(interp);
Sqlitetest4_Init(interp);
Md5_Init(interp);
}
#endif
+495 -11
View File
@@ -13,13 +13,74 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.13 2002/08/31 18:53:08 drh Exp $
** $Id: test1.c,v 1.36.2.1 2004/05/07 00:57:06 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>
#if OS_WIN
# define PTR_FMT "%x"
#else
# define PTR_FMT "%p"
#endif
/*
** Decode a pointer to an sqlite object.
*/
static int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite **ppDb){
if( sscanf(zA, PTR_FMT, (void**)ppDb)!=1 &&
(zA[0]!='0' || zA[1]!='x' || sscanf(&zA[2], PTR_FMT, (void**)ppDb)!=1)
){
Tcl_AppendResult(interp, "\"", zA, "\" is not a valid pointer value", 0);
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Decode a pointer to an sqlite_vm object.
*/
static int getVmPointer(Tcl_Interp *interp, const char *zArg, sqlite_vm **ppVm){
if( sscanf(zArg, PTR_FMT, (void**)ppVm)!=1 ){
Tcl_AppendResult(interp, "\"", zArg, "\" is not a valid pointer value", 0);
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Generate a text representation of a pointer that can be understood
** by the getDbPointer and getVmPointer routines above.
**
** The problem is, on some machines (Solaris) if you do a printf with
** "%p" you cannot turn around and do a scanf with the same "%p" and
** get your pointer back. You have to prepend a "0x" before it will
** work. Or at least that is what is reported to me (drh). But this
** behavior varies from machine to machine. The solution used her is
** to test the string right after it is generated to see if it can be
** understood by scanf, and if not, try prepending an "0x" to see if
** that helps. If nothing works, a fatal error is generated.
*/
static int makePointerStr(Tcl_Interp *interp, char *zPtr, void *p){
void *p2;
sprintf(zPtr, PTR_FMT, p);
if( sscanf(zPtr, PTR_FMT, &p2)!=1 || p2!=p ){
sprintf(zPtr, "0x" PTR_FMT, p);
if( sscanf(zPtr, PTR_FMT, &p2)!=1 || p2!=p ){
Tcl_AppendResult(interp, "unable to convert a pointer to a string "
"in the file " __FILE__ " in function makePointerStr(). Please "
"report this problem to the SQLite mailing list or as a new but "
"report. Please provide detailed information about how you compiled "
"SQLite and what computer you are running on.", 0);
return TCL_ERROR;
}
}
return TCL_OK;
}
/*
** Usage: sqlite_open filename
**
@@ -45,7 +106,7 @@ static int sqlite_test_open(
free(zErr);
return TCL_ERROR;
}
sprintf(zBuf,"%d",(int)db);
if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR;
Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK;
}
@@ -91,7 +152,7 @@ static int test_exec_printf(
" DB FORMAT STRING", 0);
return TCL_ERROR;
}
db = (sqlite*)strtol(argv[1], 0, 0);
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
Tcl_DStringInit(&str);
rc = sqlite_exec_printf(db, argv[2], exec_printf_cb, &str, &zErr, argv[3]);
sprintf(zBuf, "%d", rc);
@@ -102,6 +163,30 @@ static int test_exec_printf(
return TCL_OK;
}
/*
** Usage: sqlite_mprintf_z_test SEPARATOR ARG0 ARG1 ...
**
** Test the %z format of mprintf(). Use multiple mprintf() calls to
** concatenate arg0 through argn using separator as the separator.
** Return the result.
*/
static int test_mprintf_z(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
char *zResult = 0;
int i;
for(i=2; i<argc; i++){
zResult = sqliteMPrintf("%z%s%s", zResult, argv[1], argv[i]);
}
Tcl_AppendResult(interp, zResult, 0);
sqliteFree(zResult);
return TCL_OK;
}
/*
** Usage: sqlite_get_table_printf DB FORMAT STRING
**
@@ -128,7 +213,7 @@ static int test_get_table_printf(
" DB FORMAT STRING", 0);
return TCL_ERROR;
}
db = (sqlite*)strtol(argv[1], 0, 0);
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
Tcl_DStringInit(&str);
rc = sqlite_get_table_printf(db, argv[2], &aResult, &nRow, &nCol,
&zErr, argv[3]);
@@ -169,7 +254,7 @@ static int test_last_rowid(
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB\"", 0);
return TCL_ERROR;
}
db = (sqlite*)strtol(argv[1], 0, 0);
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
sprintf(zBuf, "%d", sqlite_last_insert_rowid(db));
Tcl_AppendResult(interp, zBuf, 0);
return SQLITE_OK;
@@ -192,7 +277,7 @@ static int sqlite_test_close(
" FILENAME\"", 0);
return TCL_ERROR;
}
db = (sqlite*)strtol(argv[1], 0, 0);
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
sqlite_close(db);
return TCL_OK;
}
@@ -211,16 +296,72 @@ static void ifnullFunc(sqlite_func *context, int argc, const char **argv){
}
}
/*
** A structure into which to accumulate text.
*/
struct dstr {
int nAlloc; /* Space allocated */
int nUsed; /* Space used */
char *z; /* The space */
};
/*
** Append text to a dstr
*/
static void dstrAppend(struct dstr *p, const char *z, int divider){
int n = strlen(z);
if( p->nUsed + n + 2 > p->nAlloc ){
char *zNew;
p->nAlloc = p->nAlloc*2 + n + 200;
zNew = sqliteRealloc(p->z, p->nAlloc);
if( zNew==0 ){
sqliteFree(p->z);
memset(p, 0, sizeof(*p));
return;
}
p->z = zNew;
}
if( divider && p->nUsed>0 ){
p->z[p->nUsed++] = divider;
}
memcpy(&p->z[p->nUsed], z, n+1);
p->nUsed += n;
}
/*
** Invoked for each callback from sqliteExecFunc
*/
static int execFuncCallback(void *pData, int argc, char **argv, char **NotUsed){
struct dstr *p = (struct dstr*)pData;
int i;
for(i=0; i<argc; i++){
if( argv[i]==0 ){
dstrAppend(p, "NULL", ' ');
}else{
dstrAppend(p, argv[i], ' ');
}
}
return 0;
}
/*
** Implementation of the x_sqlite_exec() function. This function takes
** a single argument and attempts to execute that argument as SQL code.
** This is illegal and should set the SQLITE_MISUSE flag on the database.
**
** 2004-Jan-07: We have changed this to make it legal to call sqlite_exec()
** from within a function call.
**
** This routine simulates the effect of having two threads attempt to
** use the same database at the same time.
*/
static void sqliteExecFunc(sqlite_func *context, int argc, const char **argv){
sqlite_exec((sqlite*)sqlite_user_data(context), argv[0], 0, 0, 0);
struct dstr x;
memset(&x, 0, sizeof(x));
sqlite_exec((sqlite*)sqlite_user_data(context), argv[0],
execFuncCallback, &x, 0);
sqlite_set_result_string(context, x.z, x.nUsed);
sqliteFree(x.z);
}
/*
@@ -251,7 +392,7 @@ static int test_create_function(
" FILENAME\"", 0);
return TCL_ERROR;
}
db = (sqlite*)strtol(argv[1], 0, 0);
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
sqlite_create_function(db, "x_coalesce", -1, ifnullFunc, 0);
sqlite_create_function(db, "x_sqlite_exec", 1, sqliteExecFunc, db);
return TCL_OK;
@@ -300,7 +441,7 @@ static int test_create_aggregate(
" FILENAME\"", 0);
return TCL_ERROR;
}
db = (sqlite*)strtol(argv[1], 0, 0);
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
sqlite_create_aggregate(db, "x_count", 0, countStep, countFinalize, 0);
sqlite_create_aggregate(db, "x_count", 1, countStep, countFinalize, 0);
return TCL_OK;
@@ -391,6 +532,36 @@ static int sqlite_mprintf_double(
return TCL_OK;
}
/*
** Usage: sqlite_mprintf_str FORMAT DOUBLE DOUBLE
**
** Call mprintf with a single double argument which is the product of the
** two arguments given above. This is used to generate overflow and underflow
** doubles to test that they are converted properly.
*/
static int sqlite_mprintf_scaled(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
int i;
double r[2];
char *z;
if( argc!=4 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" FORMAT DOUBLE DOUBLE\"", 0);
return TCL_ERROR;
}
for(i=2; i<4; i++){
if( Tcl_GetDouble(interp, argv[i], &r[i-2]) ) return TCL_ERROR;
}
z = sqlite_mprintf(argv[1], r[0]*r[1]);
Tcl_AppendResult(interp, z, 0);
sqlite_freemem(z);
return TCL_OK;
}
/*
** Usage: sqlite_malloc_fail N
**
@@ -469,7 +640,7 @@ static void testFunc(sqlite_func *context, int argc, const char **argv){
}else if( sqliteStrICmp(argv[0],"int")==0 ){
sqlite_set_result_int(context, atoi(argv[1]));
}else if( sqliteStrICmp(argv[0],"double")==0 ){
sqlite_set_result_double(context, atof(argv[1]));
sqlite_set_result_double(context, sqliteAtoF(argv[1], 0));
}else{
sqlite_set_result_error(context,"first argument should be one of: "
"string int double", -1);
@@ -497,7 +668,7 @@ static int test_register_func(
" DB FUNCTION-NAME", 0);
return TCL_ERROR;
}
db = (sqlite*)strtol(argv[1], 0, 0);
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
rc = sqlite_create_function(db, argv[2], -1, testFunc, 0);
if( rc!=0 ){
Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
@@ -506,11 +677,305 @@ static int test_register_func(
return TCL_OK;
}
/*
** This SQLite callback records the datatype of all columns.
**
** The pArg argument is really a pointer to a TCL interpreter. The
** column names are inserted as the result of this interpreter.
**
** This routine returns non-zero which causes the query to abort.
*/
static int rememberDataTypes(void *pArg, int nCol, char **argv, char **colv){
int i;
Tcl_Interp *interp = (Tcl_Interp*)pArg;
Tcl_Obj *pList, *pElem;
if( colv[nCol+1]==0 ){
return 1;
}
pList = Tcl_NewObj();
for(i=0; i<nCol; i++){
pElem = Tcl_NewStringObj(colv[i+nCol] ? colv[i+nCol] : "NULL", -1);
Tcl_ListObjAppendElement(interp, pList, pElem);
}
Tcl_SetObjResult(interp, pList);
return 1;
}
/*
** Invoke an SQL statement but ignore all the data in the result. Instead,
** return a list that consists of the datatypes of the various columns.
**
** This only works if "PRAGMA show_datatypes=on" has been executed against
** the database connection.
*/
static int sqlite_datatypes(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
sqlite *db;
int rc;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" DB SQL", 0);
return TCL_ERROR;
}
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
rc = sqlite_exec(db, argv[2], rememberDataTypes, interp, 0);
if( rc!=0 && rc!=SQLITE_ABORT ){
Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: sqlite_compile DB SQL ?TAILVAR?
**
** Attempt to compile an SQL statement. Return a pointer to the virtual
** machine used to execute that statement. Unprocessed SQL is written
** into TAILVAR.
*/
static int test_compile(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
sqlite *db;
sqlite_vm *vm;
int rc;
char *zErr = 0;
const char *zTail;
char zBuf[50];
if( argc!=3 && argc!=4 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" DB SQL TAILVAR", 0);
return TCL_ERROR;
}
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
rc = sqlite_compile(db, argv[2], argc==4 ? &zTail : 0, &vm, &zErr);
if( argc==4 ) Tcl_SetVar(interp, argv[3], zTail, 0);
if( rc ){
assert( vm==0 );
sprintf(zBuf, "(%d) ", rc);
Tcl_AppendResult(interp, zBuf, zErr, 0);
sqlite_freemem(zErr);
return TCL_ERROR;
}
if( vm ){
if( makePointerStr(interp, zBuf, vm) ) return TCL_ERROR;
Tcl_AppendResult(interp, zBuf, 0);
}
return TCL_OK;
}
/*
** Usage: sqlite_step VM ?NVAR? ?VALUEVAR? ?COLNAMEVAR?
**
** Step a virtual machine. Return a the result code as a string.
** Column results are written into three variables.
*/
static int test_step(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
sqlite_vm *vm;
int rc, i;
const char **azValue = 0;
const char **azColName = 0;
int N = 0;
char *zRc;
char zBuf[50];
if( argc<2 || argc>5 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" VM NVAR VALUEVAR COLNAMEVAR", 0);
return TCL_ERROR;
}
if( getVmPointer(interp, argv[1], &vm) ) return TCL_ERROR;
rc = sqlite_step(vm, argc>=3?&N:0, argc>=4?&azValue:0, argc==5?&azColName:0);
if( argc>=3 ){
sprintf(zBuf, "%d", N);
Tcl_SetVar(interp, argv[2], zBuf, 0);
}
if( argc>=4 ){
Tcl_SetVar(interp, argv[3], "", 0);
if( azValue ){
for(i=0; i<N; i++){
Tcl_SetVar(interp, argv[3], azValue[i] ? azValue[i] : "",
TCL_APPEND_VALUE | TCL_LIST_ELEMENT);
}
}
}
if( argc==5 ){
Tcl_SetVar(interp, argv[4], "", 0);
if( azColName ){
for(i=0; i<N*2; i++){
Tcl_SetVar(interp, argv[4], azColName[i] ? azColName[i] : "",
TCL_APPEND_VALUE | TCL_LIST_ELEMENT);
}
}
}
switch( rc ){
case SQLITE_DONE: zRc = "SQLITE_DONE"; break;
case SQLITE_BUSY: zRc = "SQLITE_BUSY"; break;
case SQLITE_ROW: zRc = "SQLITE_ROW"; break;
case SQLITE_ERROR: zRc = "SQLITE_ERROR"; break;
case SQLITE_MISUSE: zRc = "SQLITE_MISUSE"; break;
default: zRc = "unknown"; break;
}
Tcl_AppendResult(interp, zRc, 0);
return TCL_OK;
}
/*
** Usage: sqlite_finalize VM
**
** Shutdown a virtual machine.
*/
static int test_finalize(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
sqlite_vm *vm;
int rc;
char *zErrMsg = 0;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" VM\"", 0);
return TCL_ERROR;
}
if( getVmPointer(interp, argv[1], &vm) ) return TCL_ERROR;
rc = sqlite_finalize(vm, &zErrMsg);
if( rc ){
char zBuf[50];
sprintf(zBuf, "(%d) ", rc);
Tcl_AppendResult(interp, zBuf, zErrMsg, 0);
sqlite_freemem(zErrMsg);
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: sqlite_reset VM
**
** Reset a virtual machine and prepare it to be run again.
*/
static int test_reset(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
sqlite_vm *vm;
int rc;
char *zErrMsg = 0;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" VM\"", 0);
return TCL_ERROR;
}
if( getVmPointer(interp, argv[1], &vm) ) return TCL_ERROR;
rc = sqlite_reset(vm, &zErrMsg);
if( rc ){
char zBuf[50];
sprintf(zBuf, "(%d) ", rc);
Tcl_AppendResult(interp, zBuf, zErrMsg, 0);
sqlite_freemem(zErrMsg);
return TCL_ERROR;
}
return TCL_OK;
}
/*
** This is the "static_bind_value" that variables are bound to when
** the FLAG option of sqlite_bind is "static"
*/
static char *sqlite_static_bind_value = 0;
/*
** Usage: sqlite_bind VM IDX VALUE FLAGS
**
** Sets the value of the IDX-th occurance of "?" in the original SQL
** string. VALUE is the new value. If FLAGS=="null" then VALUE is
** ignored and the value is set to NULL. If FLAGS=="static" then
** the value is set to the value of a static variable named
** "sqlite_static_bind_value". If FLAGS=="normal" then a copy
** of the VALUE is made.
*/
static int test_bind(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
sqlite_vm *vm;
int rc;
int idx;
if( argc!=5 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" VM IDX VALUE (null|static|normal)\"", 0);
return TCL_ERROR;
}
if( getVmPointer(interp, argv[1], &vm) ) return TCL_ERROR;
if( Tcl_GetInt(interp, argv[2], &idx) ) return TCL_ERROR;
if( strcmp(argv[4],"null")==0 ){
rc = sqlite_bind(vm, idx, 0, 0, 0);
}else if( strcmp(argv[4],"static")==0 ){
rc = sqlite_bind(vm, idx, sqlite_static_bind_value, -1, 0);
}else if( strcmp(argv[4],"normal")==0 ){
rc = sqlite_bind(vm, idx, argv[3], -1, 1);
}else{
Tcl_AppendResult(interp, "4th argument should be "
"\"null\" or \"static\" or \"normal\"", 0);
return TCL_ERROR;
}
if( rc ){
char zBuf[50];
sprintf(zBuf, "(%d) ", rc);
Tcl_AppendResult(interp, zBuf, sqlite_error_string(rc), 0);
return TCL_ERROR;
}
return TCL_OK;
}
/*
** Usage: breakpoint
**
** This routine exists for one purpose - to provide a place to put a
** breakpoint with GDB that can be triggered using TCL code. The use
** for this is when a particular test fails on (say) the 1485th iteration.
** In the TCL test script, we can add code like this:
**
** if {$i==1485} breakpoint
**
** Then run testfixture in the debugger and wait for the breakpoint to
** fire. Then additional breakpoints can be set to trace down the bug.
*/
static int test_breakpoint(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
return TCL_OK; /* Do nothing */
}
/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest1_Init(Tcl_Interp *interp){
extern int sqlite_search_count;
extern int sqlite_interrupt_count;
extern int sqlite_open_file_count;
extern int sqlite_current_time;
extern int sqlite_temp_directory;
static struct {
char *zName;
Tcl_CmdProc *xProc;
@@ -518,6 +983,8 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite_mprintf_int", (Tcl_CmdProc*)sqlite_mprintf_int },
{ "sqlite_mprintf_str", (Tcl_CmdProc*)sqlite_mprintf_str },
{ "sqlite_mprintf_double", (Tcl_CmdProc*)sqlite_mprintf_double },
{ "sqlite_mprintf_scaled", (Tcl_CmdProc*)sqlite_mprintf_scaled },
{ "sqlite_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z },
{ "sqlite_open", (Tcl_CmdProc*)sqlite_test_open },
{ "sqlite_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid },
{ "sqlite_exec_printf", (Tcl_CmdProc*)test_exec_printf },
@@ -527,10 +994,17 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite_create_aggregate", (Tcl_CmdProc*)test_create_aggregate },
{ "sqlite_register_test_function", (Tcl_CmdProc*)test_register_func },
{ "sqlite_abort", (Tcl_CmdProc*)sqlite_abort },
{ "sqlite_datatypes", (Tcl_CmdProc*)sqlite_datatypes },
#ifdef MEMORY_DEBUG
{ "sqlite_malloc_fail", (Tcl_CmdProc*)sqlite_malloc_fail },
{ "sqlite_malloc_stat", (Tcl_CmdProc*)sqlite_malloc_stat },
#endif
{ "sqlite_compile", (Tcl_CmdProc*)test_compile },
{ "sqlite_step", (Tcl_CmdProc*)test_step },
{ "sqlite_finalize", (Tcl_CmdProc*)test_finalize },
{ "sqlite_bind", (Tcl_CmdProc*)test_bind },
{ "sqlite_reset", (Tcl_CmdProc*)test_reset },
{ "breakpoint", (Tcl_CmdProc*)test_breakpoint },
};
int i;
@@ -539,5 +1013,15 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
}
Tcl_LinkVar(interp, "sqlite_search_count",
(char*)&sqlite_search_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_interrupt_count",
(char*)&sqlite_interrupt_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_open_file_count",
(char*)&sqlite_open_file_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_current_time",
(char*)&sqlite_current_time, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_static_bind_value",
(char*)&sqlite_static_bind_value, TCL_LINK_STRING);
Tcl_LinkVar(interp, "sqlite_temp_directory",
(char*)&sqlite_temp_directory, TCL_LINK_STRING);
return TCL_OK;
}
+63 -6
View File
@@ -13,8 +13,9 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test2.c,v 1.10 2002/08/31 18:53:08 drh Exp $
** $Id: test2.c,v 1.16 2004/02/10 01:54:28 drh Exp $
*/
#include "os.h"
#include "sqliteInt.h"
#include "pager.h"
#include "tcl.h"
@@ -48,6 +49,7 @@ static char *errorName(int rc){
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
default: zName = "SQLITE_Unknown"; break;
}
return zName;
@@ -74,7 +76,7 @@ static int pager_open(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR;
rc = sqlitepager_open(&pPager, argv[1], nPage, 0);
rc = sqlitepager_open(&pPager, argv[1], nPage, 0, 1);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -466,8 +468,55 @@ static int page_write(
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
}
strncpy((char*)pPage, argv[2], SQLITE_PAGE_SIZE-1);
((char*)pPage)[SQLITE_PAGE_SIZE-1] = 0;
strncpy((char*)pPage, argv[2], SQLITE_USABLE_SIZE-1);
((char*)pPage)[SQLITE_USABLE_SIZE-1] = 0;
return TCL_OK;
}
/*
** Usage: fake_big_file N FILENAME
**
** Write a few bytes at the N megabyte point of FILENAME. This will
** create a large file. If the file was a valid SQLite database, then
** the next time the database is opened, SQLite will begin allocating
** new pages after N. If N is 2096 or bigger, this will test the
** ability of SQLite to write to large files.
*/
static int fake_big_file(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int rc;
int n;
off_t offset;
OsFile fd;
int readOnly = 0;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" N-MEGABYTES FILE\"", 0);
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
rc = sqliteOsOpenReadWrite(argv[2], &fd, &readOnly);
if( rc ){
Tcl_AppendResult(interp, "open failed: ", errorName(rc), 0);
return TCL_ERROR;
}
offset = n;
offset *= 1024*1024;
rc = sqliteOsSeek(&fd, offset);
if( rc ){
Tcl_AppendResult(interp, "seek failed: ", errorName(rc), 0);
return TCL_ERROR;
}
rc = sqliteOsWrite(&fd, "Hello, World!", 14);
sqliteOsClose(&fd);
if( rc ){
Tcl_AppendResult(interp, "write failed: ", errorName(rc), 0);
return TCL_ERROR;
}
return TCL_OK;
}
@@ -476,6 +525,7 @@ static int page_write(
*/
int Sqlitetest2_Init(Tcl_Interp *interp){
extern int sqlite_io_error_pending;
char zBuf[100];
static struct {
char *zName;
Tcl_CmdProc *xProc;
@@ -495,6 +545,7 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
{ "page_read", (Tcl_CmdProc*)page_read },
{ "page_write", (Tcl_CmdProc*)page_write },
{ "page_number", (Tcl_CmdProc*)page_number },
{ "fake_big_file", (Tcl_CmdProc*)fake_big_file },
};
int i;
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
@@ -503,8 +554,14 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
Tcl_LinkVar(interp, "sqlite_io_error_pending",
(char*)&sqlite_io_error_pending, TCL_LINK_INT);
#ifdef SQLITE_TEST
Tcl_LinkVar(interp, "pager_old_format",
(char*)&pager_old_format, TCL_LINK_INT);
Tcl_LinkVar(interp, "journal_format",
(char*)&journal_format, TCL_LINK_INT);
#endif
sprintf(zBuf, "%d", SQLITE_PAGE_SIZE);
Tcl_SetVar(interp, "SQLITE_PAGE_SIZE", zBuf, TCL_GLOBAL_ONLY);
sprintf(zBuf, "%d", SQLITE_PAGE_RESERVE);
Tcl_SetVar(interp, "SQLITE_PAGE_RESERVE", zBuf, TCL_GLOBAL_ONLY);
sprintf(zBuf, "%d", SQLITE_USABLE_SIZE);
Tcl_SetVar(interp, "SQLITE_USABLE_SIZE", zBuf, TCL_GLOBAL_ONLY);
return TCL_OK;
}
+76 -5
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.19 2002/08/31 18:53:08 drh Exp $
** $Id: test3.c,v 1.23 2003/04/13 18:26:52 paul Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
@@ -67,7 +67,7 @@ static int btree_open(
" FILENAME\"", 0);
return TCL_ERROR;
}
rc = sqliteBtreeOpen(argv[1], 0666, 1000, &pBt);
rc = sqliteBtreeFactory(0, argv[1], 0, 1000, &pBt);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -660,7 +660,9 @@ static int btree_insert(
/*
** Usage: btree_next ID
**
** Move the cursor to the next entry in the table.
** Move the cursor to the next entry in the table. Return 0 on success
** or 1 if the cursor was already on the last entry in the table or if
** the table is empty.
*/
static int btree_next(
void *NotUsed,
@@ -689,10 +691,45 @@ static int btree_next(
return SQLITE_OK;
}
/*
** Usage: btree_prev ID
**
** Move the cursor to the previous entry in the table. Return 0 on
** success and 1 if the cursor was already on the first entry in
** the table or if the table was empty.
*/
static int btree_prev(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
BtCursor *pCur;
int rc;
int res = 0;
char zBuf[100];
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID\"", 0);
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
rc = sqliteBtreePrevious(pCur, &res);
if( rc ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
}
sprintf(zBuf,"%d",res);
Tcl_AppendResult(interp, zBuf, 0);
return SQLITE_OK;
}
/*
** Usage: btree_first ID
**
** Move the cursor to the first entry in the table.
** Move the cursor to the first entry in the table. Return 0 if the
** cursor was left point to something and 1 if the table is empty.
*/
static int btree_first(
void *NotUsed,
@@ -721,6 +758,39 @@ static int btree_first(
return SQLITE_OK;
}
/*
** Usage: btree_last ID
**
** Move the cursor to the last entry in the table. Return 0 if the
** cursor was left point to something and 1 if the table is empty.
*/
static int btree_last(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
BtCursor *pCur;
int rc;
int res = 0;
char zBuf[100];
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID\"", 0);
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
rc = sqliteBtreeLast(pCur, &res);
if( rc ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
}
sprintf(zBuf,"%d",res);
Tcl_AppendResult(interp, zBuf, 0);
return SQLITE_OK;
}
/*
** Usage: btree_key ID
**
@@ -822,7 +892,6 @@ static int btree_payload_size(
sqliteBtreeDataSize(pCur, &n2);
sprintf(zBuf, "%d", n1+n2);
Tcl_AppendResult(interp, zBuf, 0);
free(zBuf);
return SQLITE_OK;
}
@@ -901,10 +970,12 @@ int Sqlitetest3_Init(Tcl_Interp *interp){
{ "btree_delete", (Tcl_CmdProc*)btree_delete },
{ "btree_insert", (Tcl_CmdProc*)btree_insert },
{ "btree_next", (Tcl_CmdProc*)btree_next },
{ "btree_prev", (Tcl_CmdProc*)btree_prev },
{ "btree_key", (Tcl_CmdProc*)btree_key },
{ "btree_data", (Tcl_CmdProc*)btree_data },
{ "btree_payload_size", (Tcl_CmdProc*)btree_payload_size },
{ "btree_first", (Tcl_CmdProc*)btree_first },
{ "btree_last", (Tcl_CmdProc*)btree_last },
{ "btree_cursor_dump", (Tcl_CmdProc*)btree_cursor_dump },
{ "btree_integrity_check", (Tcl_CmdProc*)btree_integrity_check },
};
+634
View File
@@ -0,0 +1,634 @@
/*
** 2003 December 18
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the the SQLite library in a multithreaded environment.
**
** $Id: test4.c,v 1.3 2004/04/23 17:04:45 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#if defined(OS_UNIX) && OS_UNIX==1 && defined(THREADSAFE) && THREADSAFE==1
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sched.h>
#include <ctype.h>
/*
** Each thread is controlled by an instance of the following
** structure.
*/
typedef struct Thread Thread;
struct Thread {
/* The first group of fields are writable by the master and read-only
** to the thread. */
char *zFilename; /* Name of database file */
void (*xOp)(Thread*); /* next operation to do */
char *zArg; /* argument usable by xOp */
int opnum; /* Operation number */
int busy; /* True if this thread is in use */
/* The next group of fields are writable by the thread but read-only to the
** master. */
int completed; /* Number of operations completed */
sqlite *db; /* Open database */
sqlite_vm *vm; /* Pending operation */
char *zErr; /* operation error */
char *zStaticErr; /* Static error message */
int rc; /* operation return code */
int argc; /* number of columns in result */
const char **argv; /* result columns */
const char **colv; /* result column names */
};
/*
** There can be as many as 26 threads running at once. Each is named
** by a capital letter: A, B, C, ..., Y, Z.
*/
#define N_THREAD 26
static Thread threadset[N_THREAD];
/*
** The main loop for a thread. Threads use busy waiting.
*/
static void *thread_main(void *pArg){
Thread *p = (Thread*)pArg;
if( p->db ){
sqlite_close(p->db);
}
p->db = sqlite_open(p->zFilename, 0, &p->zErr);
p->vm = 0;
p->completed = 1;
while( p->opnum<=p->completed ) sched_yield();
while( p->xOp ){
if( p->zErr && p->zErr!=p->zStaticErr ){
sqlite_freemem(p->zErr);
p->zErr = 0;
}
(*p->xOp)(p);
p->completed++;
while( p->opnum<=p->completed ) sched_yield();
}
if( p->vm ){
sqlite_finalize(p->vm, 0);
p->vm = 0;
}
if( p->db ){
sqlite_close(p->db);
p->db = 0;
}
if( p->zErr && p->zErr!=p->zStaticErr ){
sqlite_freemem(p->zErr);
p->zErr = 0;
}
p->completed++;
return 0;
}
/*
** Get a thread ID which is an upper case letter. Return the index.
** If the argument is not a valid thread ID put an error message in
** the interpreter and return -1.
*/
static int parse_thread_id(Tcl_Interp *interp, const char *zArg){
if( zArg==0 || zArg[0]==0 || zArg[1]!=0 || !isupper(zArg[0]) ){
Tcl_AppendResult(interp, "thread ID must be an upper case letter", 0);
return -1;
}
return zArg[0] - 'A';
}
/*
** Usage: thread_create NAME FILENAME
**
** NAME should be an upper case letter. Start the thread running with
** an open connection to the given database.
*/
static int tcl_thread_create(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
pthread_t x;
int rc;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID FILENAME", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( threadset[i].busy ){
Tcl_AppendResult(interp, "thread ", argv[1], " is already running", 0);
return TCL_ERROR;
}
threadset[i].busy = 1;
sqliteFree(threadset[i].zFilename);
threadset[i].zFilename = sqliteStrDup(argv[2]);
threadset[i].opnum = 1;
threadset[i].completed = 0;
rc = pthread_create(&x, 0, thread_main, &threadset[i]);
if( rc ){
Tcl_AppendResult(interp, "failed to create the thread", 0);
sqliteFree(threadset[i].zFilename);
threadset[i].busy = 0;
return TCL_ERROR;
}
pthread_detach(x);
return TCL_OK;
}
/*
** Wait for a thread to reach its idle state.
*/
static void thread_wait(Thread *p){
while( p->opnum>p->completed ) sched_yield();
}
/*
** Usage: thread_wait ID
**
** Wait on thread ID to reach its idle state.
*/
static int tcl_thread_wait(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
thread_wait(&threadset[i]);
return TCL_OK;
}
/*
** Stop a thread.
*/
static void stop_thread(Thread *p){
thread_wait(p);
p->xOp = 0;
p->opnum++;
thread_wait(p);
sqliteFree(p->zArg);
p->zArg = 0;
sqliteFree(p->zFilename);
p->zFilename = 0;
p->busy = 0;
}
/*
** Usage: thread_halt ID
**
** Cause a thread to shut itself down. Wait for the shutdown to be
** completed. If ID is "*" then stop all threads.
*/
static int tcl_thread_halt(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID", 0);
return TCL_ERROR;
}
if( argv[1][0]=='*' && argv[1][1]==0 ){
for(i=0; i<N_THREAD; i++){
if( threadset[i].busy ) stop_thread(&threadset[i]);
}
}else{
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
stop_thread(&threadset[i]);
}
return TCL_OK;
}
/*
** Usage: thread_argc ID
**
** Wait on the most recent thread_step to complete, then return the
** number of columns in the result set.
*/
static int tcl_thread_argc(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
char zBuf[100];
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
thread_wait(&threadset[i]);
sprintf(zBuf, "%d", threadset[i].argc);
Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK;
}
/*
** Usage: thread_argv ID N
**
** Wait on the most recent thread_step to complete, then return the
** value of the N-th columns in the result set.
*/
static int tcl_thread_argv(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
int n;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID N", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
thread_wait(&threadset[i]);
if( n<0 || n>=threadset[i].argc ){
Tcl_AppendResult(interp, "column number out of range", 0);
return TCL_ERROR;
}
Tcl_AppendResult(interp, threadset[i].argv[n], 0);
return TCL_OK;
}
/*
** Usage: thread_colname ID N
**
** Wait on the most recent thread_step to complete, then return the
** name of the N-th columns in the result set.
*/
static int tcl_thread_colname(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
int n;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID N", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR;
thread_wait(&threadset[i]);
if( n<0 || n>=threadset[i].argc ){
Tcl_AppendResult(interp, "column number out of range", 0);
return TCL_ERROR;
}
Tcl_AppendResult(interp, threadset[i].colv[n], 0);
return TCL_OK;
}
/*
** Usage: thread_result ID
**
** Wait on the most recent operation to complete, then return the
** result code from that operation.
*/
static int tcl_thread_result(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
const char *zName;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
thread_wait(&threadset[i]);
switch( threadset[i].rc ){
case SQLITE_OK: zName = "SQLITE_OK"; break;
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
default: zName = "SQLITE_Unknown"; break;
}
Tcl_AppendResult(interp, zName, 0);
return TCL_OK;
}
/*
** Usage: thread_error ID
**
** Wait on the most recent operation to complete, then return the
** error string.
*/
static int tcl_thread_error(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
thread_wait(&threadset[i]);
Tcl_AppendResult(interp, threadset[i].zErr, 0);
return TCL_OK;
}
/*
** This procedure runs in the thread to compile an SQL statement.
*/
static void do_compile(Thread *p){
if( p->db==0 ){
p->zErr = p->zStaticErr = "no database is open";
p->rc = SQLITE_ERROR;
return;
}
if( p->vm ){
sqlite_finalize(p->vm, 0);
p->vm = 0;
}
p->rc = sqlite_compile(p->db, p->zArg, 0, &p->vm, &p->zErr);
}
/*
** Usage: thread_compile ID SQL
**
** Compile a new virtual machine.
*/
static int tcl_thread_compile(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID SQL", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
thread_wait(&threadset[i]);
threadset[i].xOp = do_compile;
sqliteFree(threadset[i].zArg);
threadset[i].zArg = sqliteStrDup(argv[2]);
threadset[i].opnum++;
return TCL_OK;
}
/*
** This procedure runs in the thread to step the virtual machine.
*/
static void do_step(Thread *p){
if( p->vm==0 ){
p->zErr = p->zStaticErr = "no virtual machine available";
p->rc = SQLITE_ERROR;
return;
}
p->rc = sqlite_step(p->vm, &p->argc, &p->argv, &p->colv);
}
/*
** Usage: thread_step ID
**
** Advance the virtual machine by one step
*/
static int tcl_thread_step(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" IDL", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
thread_wait(&threadset[i]);
threadset[i].xOp = do_step;
threadset[i].opnum++;
return TCL_OK;
}
/*
** This procedure runs in the thread to finalize a virtual machine.
*/
static void do_finalize(Thread *p){
if( p->vm==0 ){
p->zErr = p->zStaticErr = "no virtual machine available";
p->rc = SQLITE_ERROR;
return;
}
p->rc = sqlite_finalize(p->vm, &p->zErr);
p->vm = 0;
}
/*
** Usage: thread_finalize ID
**
** Finalize the virtual machine.
*/
static int tcl_thread_finalize(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" IDL", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
thread_wait(&threadset[i]);
threadset[i].xOp = do_finalize;
sqliteFree(threadset[i].zArg);
threadset[i].zArg = 0;
threadset[i].opnum++;
return TCL_OK;
}
/*
** Usage: thread_swap ID ID
**
** Interchange the sqlite* pointer between two threads.
*/
static int tcl_thread_swap(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int i, j;
sqlite *temp;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID1 ID2", 0);
return TCL_ERROR;
}
i = parse_thread_id(interp, argv[1]);
if( i<0 ) return TCL_ERROR;
if( !threadset[i].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
thread_wait(&threadset[i]);
j = parse_thread_id(interp, argv[2]);
if( j<0 ) return TCL_ERROR;
if( !threadset[j].busy ){
Tcl_AppendResult(interp, "no such thread", 0);
return TCL_ERROR;
}
thread_wait(&threadset[j]);
temp = threadset[i].db;
threadset[i].db = threadset[j].db;
threadset[j].db = temp;
return TCL_OK;
}
/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest4_Init(Tcl_Interp *interp){
static struct {
char *zName;
Tcl_CmdProc *xProc;
} aCmd[] = {
{ "thread_create", (Tcl_CmdProc*)tcl_thread_create },
{ "thread_wait", (Tcl_CmdProc*)tcl_thread_wait },
{ "thread_halt", (Tcl_CmdProc*)tcl_thread_halt },
{ "thread_argc", (Tcl_CmdProc*)tcl_thread_argc },
{ "thread_argv", (Tcl_CmdProc*)tcl_thread_argv },
{ "thread_colname", (Tcl_CmdProc*)tcl_thread_colname },
{ "thread_result", (Tcl_CmdProc*)tcl_thread_result },
{ "thread_error", (Tcl_CmdProc*)tcl_thread_error },
{ "thread_compile", (Tcl_CmdProc*)tcl_thread_compile },
{ "thread_step", (Tcl_CmdProc*)tcl_thread_step },
{ "thread_finalize", (Tcl_CmdProc*)tcl_thread_finalize },
{ "thread_swap", (Tcl_CmdProc*)tcl_thread_swap },
};
int i;
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
}
return TCL_OK;
}
#else
int Sqlitetest4_Init(Tcl_Interp *interp){ return TCL_OK; }
#endif /* OS_UNIX */
+369 -189
View File
@@ -15,7 +15,7 @@
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.49 2002/08/27 14:28:30 drh Exp $
** $Id: tokenize.c,v 1.68 2004/02/14 23:59:58 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -29,119 +29,122 @@
typedef struct Keyword Keyword;
struct Keyword {
char *zName; /* The keyword name */
int len; /* Number of characters in the keyword */
int tokenType; /* The token value for this keyword */
Keyword *pNext; /* Next keyword with the same hash */
u8 tokenType; /* Token value for this keyword */
u8 len; /* Length of this keyword */
u8 iNext; /* Index in aKeywordTable[] of next with same hash */
};
/*
** These are the keywords
*/
static Keyword aKeywordTable[] = {
{ "ABORT", 0, TK_ABORT, 0 },
{ "AFTER", 0, TK_AFTER, 0 },
{ "ALL", 0, TK_ALL, 0 },
{ "AND", 0, TK_AND, 0 },
{ "AS", 0, TK_AS, 0 },
{ "ASC", 0, TK_ASC, 0 },
{ "BEFORE", 0, TK_BEFORE, 0 },
{ "BEGIN", 0, TK_BEGIN, 0 },
{ "BETWEEN", 0, TK_BETWEEN, 0 },
{ "BY", 0, TK_BY, 0 },
{ "CASCADE", 0, TK_CASCADE, 0 },
{ "CASE", 0, TK_CASE, 0 },
{ "CHECK", 0, TK_CHECK, 0 },
{ "CLUSTER", 0, TK_CLUSTER, 0 },
{ "COLLATE", 0, TK_COLLATE, 0 },
{ "COMMIT", 0, TK_COMMIT, 0 },
{ "CONFLICT", 0, TK_CONFLICT, 0 },
{ "CONSTRAINT", 0, TK_CONSTRAINT, 0 },
{ "COPY", 0, TK_COPY, 0 },
{ "CREATE", 0, TK_CREATE, 0 },
{ "CROSS", 0, TK_JOIN_KW, 0 },
{ "DEFAULT", 0, TK_DEFAULT, 0 },
{ "DEFERRED", 0, TK_DEFERRED, 0 },
{ "DEFERRABLE", 0, TK_DEFERRABLE, 0 },
{ "DELETE", 0, TK_DELETE, 0 },
{ "DELIMITERS", 0, TK_DELIMITERS, 0 },
{ "DESC", 0, TK_DESC, 0 },
{ "DISTINCT", 0, TK_DISTINCT, 0 },
{ "DROP", 0, TK_DROP, 0 },
{ "END", 0, TK_END, 0 },
{ "EACH", 0, TK_EACH, 0 },
{ "ELSE", 0, TK_ELSE, 0 },
{ "EXCEPT", 0, TK_EXCEPT, 0 },
{ "EXPLAIN", 0, TK_EXPLAIN, 0 },
{ "FAIL", 0, TK_FAIL, 0 },
{ "FOR", 0, TK_FOR, 0 },
{ "FOREIGN", 0, TK_FOREIGN, 0 },
{ "FROM", 0, TK_FROM, 0 },
{ "FULL", 0, TK_JOIN_KW, 0 },
{ "GLOB", 0, TK_GLOB, 0 },
{ "GROUP", 0, TK_GROUP, 0 },
{ "HAVING", 0, TK_HAVING, 0 },
{ "IGNORE", 0, TK_IGNORE, 0 },
{ "IMMEDIATE", 0, TK_IMMEDIATE, 0 },
{ "IN", 0, TK_IN, 0 },
{ "INDEX", 0, TK_INDEX, 0 },
{ "INITIALLY", 0, TK_INITIALLY, 0 },
{ "INNER", 0, TK_JOIN_KW, 0 },
{ "INSERT", 0, TK_INSERT, 0 },
{ "INSTEAD", 0, TK_INSTEAD, 0 },
{ "INTERSECT", 0, TK_INTERSECT, 0 },
{ "INTO", 0, TK_INTO, 0 },
{ "IS", 0, TK_IS, 0 },
{ "ISNULL", 0, TK_ISNULL, 0 },
{ "JOIN", 0, TK_JOIN, 0 },
{ "KEY", 0, TK_KEY, 0 },
{ "LEFT", 0, TK_JOIN_KW, 0 },
{ "LIKE", 0, TK_LIKE, 0 },
{ "LIMIT", 0, TK_LIMIT, 0 },
{ "MATCH", 0, TK_MATCH, 0 },
{ "NATURAL", 0, TK_JOIN_KW, 0 },
{ "NOT", 0, TK_NOT, 0 },
{ "NOTNULL", 0, TK_NOTNULL, 0 },
{ "NULL", 0, TK_NULL, 0 },
{ "OF", 0, TK_OF, 0 },
{ "OFFSET", 0, TK_OFFSET, 0 },
{ "ON", 0, TK_ON, 0 },
{ "OR", 0, TK_OR, 0 },
{ "ORDER", 0, TK_ORDER, 0 },
{ "OUTER", 0, TK_JOIN_KW, 0 },
{ "PRAGMA", 0, TK_PRAGMA, 0 },
{ "PRIMARY", 0, TK_PRIMARY, 0 },
{ "RAISE", 0, TK_RAISE, 0 },
{ "REFERENCES", 0, TK_REFERENCES, 0 },
{ "REPLACE", 0, TK_REPLACE, 0 },
{ "RESTRICT", 0, TK_RESTRICT, 0 },
{ "RIGHT", 0, TK_JOIN_KW, 0 },
{ "ROLLBACK", 0, TK_ROLLBACK, 0 },
{ "ROW", 0, TK_ROW, 0 },
{ "SELECT", 0, TK_SELECT, 0 },
{ "SET", 0, TK_SET, 0 },
{ "STATEMENT", 0, TK_STATEMENT, 0 },
{ "TABLE", 0, TK_TABLE, 0 },
{ "TEMP", 0, TK_TEMP, 0 },
{ "TEMPORARY", 0, TK_TEMP, 0 },
{ "THEN", 0, TK_THEN, 0 },
{ "TRANSACTION", 0, TK_TRANSACTION, 0 },
{ "TRIGGER", 0, TK_TRIGGER, 0 },
{ "UNION", 0, TK_UNION, 0 },
{ "UNIQUE", 0, TK_UNIQUE, 0 },
{ "UPDATE", 0, TK_UPDATE, 0 },
{ "USING", 0, TK_USING, 0 },
{ "VACUUM", 0, TK_VACUUM, 0 },
{ "VALUES", 0, TK_VALUES, 0 },
{ "VIEW", 0, TK_VIEW, 0 },
{ "WHEN", 0, TK_WHEN, 0 },
{ "WHERE", 0, TK_WHERE, 0 },
{ "ABORT", TK_ABORT, },
{ "AFTER", TK_AFTER, },
{ "ALL", TK_ALL, },
{ "AND", TK_AND, },
{ "AS", TK_AS, },
{ "ASC", TK_ASC, },
{ "ATTACH", TK_ATTACH, },
{ "BEFORE", TK_BEFORE, },
{ "BEGIN", TK_BEGIN, },
{ "BETWEEN", TK_BETWEEN, },
{ "BY", TK_BY, },
{ "CASCADE", TK_CASCADE, },
{ "CASE", TK_CASE, },
{ "CHECK", TK_CHECK, },
{ "CLUSTER", TK_CLUSTER, },
{ "COLLATE", TK_COLLATE, },
{ "COMMIT", TK_COMMIT, },
{ "CONFLICT", TK_CONFLICT, },
{ "CONSTRAINT", TK_CONSTRAINT, },
{ "COPY", TK_COPY, },
{ "CREATE", TK_CREATE, },
{ "CROSS", TK_JOIN_KW, },
{ "DATABASE", TK_DATABASE, },
{ "DEFAULT", TK_DEFAULT, },
{ "DEFERRED", TK_DEFERRED, },
{ "DEFERRABLE", TK_DEFERRABLE, },
{ "DELETE", TK_DELETE, },
{ "DELIMITERS", TK_DELIMITERS, },
{ "DESC", TK_DESC, },
{ "DETACH", TK_DETACH, },
{ "DISTINCT", TK_DISTINCT, },
{ "DROP", TK_DROP, },
{ "END", TK_END, },
{ "EACH", TK_EACH, },
{ "ELSE", TK_ELSE, },
{ "EXCEPT", TK_EXCEPT, },
{ "EXPLAIN", TK_EXPLAIN, },
{ "FAIL", TK_FAIL, },
{ "FOR", TK_FOR, },
{ "FOREIGN", TK_FOREIGN, },
{ "FROM", TK_FROM, },
{ "FULL", TK_JOIN_KW, },
{ "GLOB", TK_GLOB, },
{ "GROUP", TK_GROUP, },
{ "HAVING", TK_HAVING, },
{ "IGNORE", TK_IGNORE, },
{ "IMMEDIATE", TK_IMMEDIATE, },
{ "IN", TK_IN, },
{ "INDEX", TK_INDEX, },
{ "INITIALLY", TK_INITIALLY, },
{ "INNER", TK_JOIN_KW, },
{ "INSERT", TK_INSERT, },
{ "INSTEAD", TK_INSTEAD, },
{ "INTERSECT", TK_INTERSECT, },
{ "INTO", TK_INTO, },
{ "IS", TK_IS, },
{ "ISNULL", TK_ISNULL, },
{ "JOIN", TK_JOIN, },
{ "KEY", TK_KEY, },
{ "LEFT", TK_JOIN_KW, },
{ "LIKE", TK_LIKE, },
{ "LIMIT", TK_LIMIT, },
{ "MATCH", TK_MATCH, },
{ "NATURAL", TK_JOIN_KW, },
{ "NOT", TK_NOT, },
{ "NOTNULL", TK_NOTNULL, },
{ "NULL", TK_NULL, },
{ "OF", TK_OF, },
{ "OFFSET", TK_OFFSET, },
{ "ON", TK_ON, },
{ "OR", TK_OR, },
{ "ORDER", TK_ORDER, },
{ "OUTER", TK_JOIN_KW, },
{ "PRAGMA", TK_PRAGMA, },
{ "PRIMARY", TK_PRIMARY, },
{ "RAISE", TK_RAISE, },
{ "REFERENCES", TK_REFERENCES, },
{ "REPLACE", TK_REPLACE, },
{ "RESTRICT", TK_RESTRICT, },
{ "RIGHT", TK_JOIN_KW, },
{ "ROLLBACK", TK_ROLLBACK, },
{ "ROW", TK_ROW, },
{ "SELECT", TK_SELECT, },
{ "SET", TK_SET, },
{ "STATEMENT", TK_STATEMENT, },
{ "TABLE", TK_TABLE, },
{ "TEMP", TK_TEMP, },
{ "TEMPORARY", TK_TEMP, },
{ "THEN", TK_THEN, },
{ "TRANSACTION", TK_TRANSACTION, },
{ "TRIGGER", TK_TRIGGER, },
{ "UNION", TK_UNION, },
{ "UNIQUE", TK_UNIQUE, },
{ "UPDATE", TK_UPDATE, },
{ "USING", TK_USING, },
{ "VACUUM", TK_VACUUM, },
{ "VALUES", TK_VALUES, },
{ "VIEW", TK_VIEW, },
{ "WHEN", TK_WHEN, },
{ "WHERE", TK_WHERE, },
};
/*
** This is the hash table
*/
#define KEY_HASH_SIZE 71
static Keyword *apHashTable[KEY_HASH_SIZE];
#define KEY_HASH_SIZE 101
static u8 aiHashTable[KEY_HASH_SIZE];
/*
@@ -150,27 +153,29 @@ static Keyword *apHashTable[KEY_HASH_SIZE];
** returned. If the input is not a keyword, TK_ID is returned.
*/
int sqliteKeywordCode(const char *z, int n){
int h;
int h, i;
Keyword *p;
if( aKeywordTable[0].len==0 ){
static char needInit = 1;
if( needInit ){
/* Initialize the keyword hash table */
sqliteOsEnterMutex();
if( aKeywordTable[0].len==0 ){
int i;
int n;
n = sizeof(aKeywordTable)/sizeof(aKeywordTable[0]);
for(i=0; i<n; i++){
if( needInit ){
int nk;
nk = sizeof(aKeywordTable)/sizeof(aKeywordTable[0]);
for(i=0; i<nk; i++){
aKeywordTable[i].len = strlen(aKeywordTable[i].zName);
h = sqliteHashNoCase(aKeywordTable[i].zName, aKeywordTable[i].len);
h %= KEY_HASH_SIZE;
aKeywordTable[i].pNext = apHashTable[h];
apHashTable[h] = &aKeywordTable[i];
aKeywordTable[i].iNext = aiHashTable[h];
aiHashTable[h] = i+1;
}
needInit = 0;
}
sqliteOsLeaveMutex();
}
h = sqliteHashNoCase(z, n) % KEY_HASH_SIZE;
for(p=apHashTable[h]; p; p=p->pNext){
for(i=aiHashTable[h]; i; i=p->iNext){
p = &aKeywordTable[i-1];
if( p->len==n && sqliteStrNICmp(p->zName, z, n)==0 ){
return p->tokenType;
}
@@ -180,8 +185,12 @@ int sqliteKeywordCode(const char *z, int n){
/*
** If X is a character that can be used in an identifier then
** isIdChar[X] will be 1. Otherwise isIdChar[X] will be 0.
** If X is a character that can be used in an identifier and
** X&0x80==0 then isIdChar[X] will be 1. If X&0x80==0x80 then
** X is always an identifier character. (Hence all UTF-8
** characters can be part of an identifier). isIdChar[X] will
** be 0 for every character in the lower 128 ASCII characters
** that cannot be used as part of an identifier.
**
** In this implementation, an identifier can be a string of
** alphabetic characters, digits, and "_" plus any character
@@ -199,32 +208,22 @@ static const char isIdChar[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 8x */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 9x */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Ax */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Bx */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Cx */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Dx */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Ex */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Fx */
};
/*
** Return the length of the token that begins at z[0]. Return
** -1 if the token is (or might be) incomplete. Store the token
** type in *tokenType before returning.
** Return the length of the token that begins at z[0].
** Store the token type in *tokenType before returning.
*/
static int sqliteGetToken(const unsigned char *z, int *tokenType){
int i;
switch( *z ){
case ' ': case '\t': case '\n': case '\f': case '\r': {
for(i=1; z[i] && isspace(z[i]); i++){}
for(i=1; isspace(z[i]); i++){}
*tokenType = TK_SPACE;
return i;
}
case '-': {
if( z[1]==0 ) return -1;
if( z[1]=='-' ){
for(i=2; z[i] && z[i]!='\n'; i++){}
*tokenType = TK_COMMENT;
@@ -344,19 +343,16 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
return i;
}
case '.': {
if( !isdigit(z[1]) ){
*tokenType = TK_DOT;
return 1;
}
/* Fall thru into the next case */
*tokenType = TK_DOT;
return 1;
}
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
*tokenType = TK_INTEGER;
for(i=1; z[i] && isdigit(z[i]); i++){}
if( z[i]=='.' ){
i++;
while( z[i] && isdigit(z[i]) ){ i++; }
for(i=1; isdigit(z[i]); i++){}
if( z[i]=='.' && isdigit(z[i+1]) ){
i += 2;
while( isdigit(z[i]) ){ i++; }
*tokenType = TK_FLOAT;
}
if( (z[i]=='e' || z[i]=='E') &&
@@ -365,9 +361,7 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
)
){
i += 2;
while( z[i] && isdigit(z[i]) ){ i++; }
*tokenType = TK_FLOAT;
}else if( z[0]=='.' ){
while( isdigit(z[i]) ){ i++; }
*tokenType = TK_FLOAT;
}
return i;
@@ -377,11 +371,15 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){
*tokenType = TK_ID;
return i;
}
case '?': {
*tokenType = TK_VARIABLE;
return 1;
}
default: {
if( !isIdChar[*z] ){
if( (*z&0x80)==0 && !isIdChar[*z] ){
break;
}
for(i=1; isIdChar[z[i]]; i++){}
for(i=1; (z[i]&0x80)!=0 || isIdChar[z[i]]; i++){}
*tokenType = sqliteKeywordCode((char*)z, i);
return i;
}
@@ -401,7 +399,8 @@ int sqliteRunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
int nErr = 0;
int i;
void *pEngine;
int once = 1;
int tokenType;
int lastTokenParsed = -1;
sqlite *db = pParse->db;
extern void *sqliteParserAlloc(void*(*)(int));
extern void sqliteParserFree(void*, void(*)(void*));
@@ -412,79 +411,70 @@ int sqliteRunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
i = 0;
pEngine = sqliteParserAlloc((void*(*)(int))malloc);
if( pEngine==0 ){
sqliteSetString(pzErrMsg, "out of memory", 0);
sqliteSetString(pzErrMsg, "out of memory", (char*)0);
return 1;
}
while( sqlite_malloc_failed==0 && nErr==0 && i>=0 && zSql[i]!=0 ){
int tokenType;
if( (db->flags & SQLITE_Interrupt)!=0 ){
pParse->rc = SQLITE_INTERRUPT;
sqliteSetString(pzErrMsg, "interrupt", 0);
break;
}
pParse->sLastToken.dyn = 0;
pParse->zTail = zSql;
while( sqlite_malloc_failed==0 && zSql[i]!=0 ){
assert( i>=0 );
pParse->sLastToken.z = &zSql[i];
pParse->sLastToken.base = 1;
pParse->sLastToken.dyn = 0;
assert( pParse->sLastToken.dyn==0 );
pParse->sLastToken.n = sqliteGetToken((unsigned char*)&zSql[i], &tokenType);
i += pParse->sLastToken.n;
if( once ){
pParse->sFirstToken = pParse->sLastToken;
once = 0;
}
switch( tokenType ){
case TK_SPACE:
case TK_COMMENT: {
if( (db->flags & SQLITE_Interrupt)!=0 ){
pParse->rc = SQLITE_INTERRUPT;
sqliteSetString(pzErrMsg, "interrupt", (char*)0);
goto abort_parse;
}
break;
}
case TK_ILLEGAL:
case TK_ILLEGAL: {
sqliteSetNString(pzErrMsg, "unrecognized token: \"", -1,
pParse->sLastToken.z, pParse->sLastToken.n, "\"", 1, 0);
nErr++;
break;
default:
goto abort_parse;
}
case TK_SEMI: {
pParse->zTail = &zSql[i];
/* Fall thru into the default case */
}
default: {
sqliteParser(pEngine, tokenType, pParse->sLastToken, pParse);
if( pParse->zErrMsg && pParse->sErrToken.z ){
sqliteSetNString(pzErrMsg, "near \"", -1,
pParse->sErrToken.z, pParse->sErrToken.n,
"\": ", -1,
pParse->zErrMsg, -1,
0);
nErr++;
sqliteFree(pParse->zErrMsg);
pParse->zErrMsg = 0;
}else if( pParse->rc!=SQLITE_OK ){
sqliteSetString(pzErrMsg, sqlite_error_string(pParse->rc), 0);
nErr++;
lastTokenParsed = tokenType;
if( pParse->rc!=SQLITE_OK ){
goto abort_parse;
}
break;
}
}
}
if( zSql[i]==0 ){
sqliteParser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
sqliteParser(pEngine, 0, pParse->sLastToken, pParse);
if( pParse->zErrMsg && pParse->sErrToken.z ){
sqliteSetNString(pzErrMsg, "near \"", -1,
pParse->sErrToken.z, pParse->sErrToken.n,
"\": ", -1,
pParse->zErrMsg, -1,
0);
nErr++;
sqliteFree(pParse->zErrMsg);
pParse->zErrMsg = 0;
abort_parse:
if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
if( lastTokenParsed!=TK_SEMI ){
sqliteParser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
pParse->zTail = &zSql[i];
}
sqliteParser(pEngine, 0, pParse->sLastToken, pParse);
}
sqliteParserFree(pEngine, free);
if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
sqliteSetString(&pParse->zErrMsg, sqlite_error_string(pParse->rc),
(char*)0);
}
if( pParse->zErrMsg ){
if( pzErrMsg ){
sqliteFree(*pzErrMsg);
if( pzErrMsg && *pzErrMsg==0 ){
*pzErrMsg = pParse->zErrMsg;
}else{
sqliteFree(pParse->zErrMsg);
}
pParse->zErrMsg = 0;
if( !nErr ) nErr++;
}
if( pParse->pVdbe ){
if( pParse->pVdbe && pParse->nErr>0 ){
sqliteVdbeDelete(pParse->pVdbe);
pParse->pVdbe = 0;
}
@@ -492,8 +482,198 @@ int sqliteRunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
sqliteDeleteTable(pParse->db, pParse->pNewTable);
pParse->pNewTable = 0;
}
if( nErr>0 && pParse->rc==SQLITE_OK ){
if( pParse->pNewTrigger ){
sqliteDeleteTrigger(pParse->pNewTrigger);
pParse->pNewTrigger = 0;
}
if( nErr>0 && (pParse->rc==SQLITE_OK || pParse->rc==SQLITE_DONE) ){
pParse->rc = SQLITE_ERROR;
}
return nErr;
}
/*
** Token types used by the sqlite_complete() routine. See the header
** comments on that procedure for additional information.
*/
#define tkEXPLAIN 0
#define tkCREATE 1
#define tkTEMP 2
#define tkTRIGGER 3
#define tkEND 4
#define tkSEMI 5
#define tkWS 6
#define tkOTHER 7
/*
** Return TRUE if the given SQL string ends in a semicolon.
**
** Special handling is require for CREATE TRIGGER statements.
** Whenever the CREATE TRIGGER keywords are seen, the statement
** must end with ";END;".
**
** This implementation uses a state machine with 7 states:
**
** (0) START At the beginning or end of an SQL statement. This routine
** returns 1 if it ends in the START state and 0 if it ends
** in any other state.
**
** (1) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
** a statement.
**
** (2) CREATE The keyword CREATE has been seen at the beginning of a
** statement, possibly preceeded by EXPLAIN and/or followed by
** TEMP or TEMPORARY
**
** (3) NORMAL We are in the middle of statement which ends with a single
** semicolon.
**
** (4) TRIGGER We are in the middle of a trigger definition that must be
** ended by a semicolon, the keyword END, and another semicolon.
**
** (5) SEMI We've seen the first semicolon in the ";END;" that occurs at
** the end of a trigger definition.
**
** (6) END We've seen the ";END" of the ";END;" that occurs at the end
** of a trigger difinition.
**
** Transitions between states above are determined by tokens extracted
** from the input. The following tokens are significant:
**
** (0) tkEXPLAIN The "explain" keyword.
** (1) tkCREATE The "create" keyword.
** (2) tkTEMP The "temp" or "temporary" keyword.
** (3) tkTRIGGER The "trigger" keyword.
** (4) tkEND The "end" keyword.
** (5) tkSEMI A semicolon.
** (6) tkWS Whitespace
** (7) tkOTHER Any other SQL token.
**
** Whitespace never causes a state transition and is always ignored.
*/
int sqlite_complete(const char *zSql){
u8 state = 0; /* Current state, using numbers defined in header comment */
u8 token; /* Value of the next token */
/* The following matrix defines the transition from one state to another
** according to what token is seen. trans[state][token] returns the
** next state.
*/
static const u8 trans[7][8] = {
/* Token: */
/* State: ** EXPLAIN CREATE TEMP TRIGGER END SEMI WS OTHER */
/* 0 START: */ { 1, 2, 3, 3, 3, 0, 0, 3, },
/* 1 EXPLAIN: */ { 3, 2, 3, 3, 3, 0, 1, 3, },
/* 2 CREATE: */ { 3, 3, 2, 4, 3, 0, 2, 3, },
/* 3 NORMAL: */ { 3, 3, 3, 3, 3, 0, 3, 3, },
/* 4 TRIGGER: */ { 4, 4, 4, 4, 4, 5, 4, 4, },
/* 5 SEMI: */ { 4, 4, 4, 4, 6, 5, 5, 4, },
/* 6 END: */ { 4, 4, 4, 4, 4, 0, 6, 4, },
};
while( *zSql ){
switch( *zSql ){
case ';': { /* A semicolon */
token = tkSEMI;
break;
}
case ' ':
case '\r':
case '\t':
case '\n':
case '\f': { /* White space is ignored */
token = tkWS;
break;
}
case '/': { /* C-style comments */
if( zSql[1]!='*' ){
token = tkOTHER;
break;
}
zSql += 2;
while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
if( zSql[0]==0 ) return 0;
zSql++;
token = tkWS;
break;
}
case '-': { /* SQL-style comments from "--" to end of line */
if( zSql[1]!='-' ){
token = tkOTHER;
break;
}
while( *zSql && *zSql!='\n' ){ zSql++; }
if( *zSql==0 ) return state==0;
token = tkWS;
break;
}
case '[': { /* Microsoft-style identifiers in [...] */
zSql++;
while( *zSql && *zSql!=']' ){ zSql++; }
if( *zSql==0 ) return 0;
token = tkOTHER;
break;
}
case '"': /* single- and double-quoted strings */
case '\'': {
int c = *zSql;
zSql++;
while( *zSql && *zSql!=c ){ zSql++; }
if( *zSql==0 ) return 0;
token = tkOTHER;
break;
}
default: {
if( isIdChar[(u8)*zSql] ){
/* Keywords and unquoted identifiers */
int nId;
for(nId=1; isIdChar[(u8)zSql[nId]]; nId++){}
switch( *zSql ){
case 'c': case 'C': {
if( nId==6 && sqliteStrNICmp(zSql, "create", 6)==0 ){
token = tkCREATE;
}else{
token = tkOTHER;
}
break;
}
case 't': case 'T': {
if( nId==7 && sqliteStrNICmp(zSql, "trigger", 7)==0 ){
token = tkTRIGGER;
}else if( nId==4 && sqliteStrNICmp(zSql, "temp", 4)==0 ){
token = tkTEMP;
}else if( nId==9 && sqliteStrNICmp(zSql, "temporary", 9)==0 ){
token = tkTEMP;
}else{
token = tkOTHER;
}
break;
}
case 'e': case 'E': {
if( nId==3 && sqliteStrNICmp(zSql, "end", 3)==0 ){
token = tkEND;
}else if( nId==7 && sqliteStrNICmp(zSql, "explain", 7)==0 ){
token = tkEXPLAIN;
}else{
token = tkOTHER;
}
break;
}
default: {
token = tkOTHER;
break;
}
}
zSql += nId-1;
}else{
/* Operators and special symbols */
token = tkOTHER;
}
break;
}
}
state = trans[state][token];
zSql++;
}
return state==0;
}
+271 -278
View File
@@ -15,7 +15,7 @@
/*
** Delete a linked list of TriggerStep structures.
*/
static void sqliteDeleteTriggerStep(TriggerStep *pTriggerStep){
void sqliteDeleteTriggerStep(TriggerStep *pTriggerStep){
while( pTriggerStep ){
TriggerStep * pTmp = pTriggerStep;
pTriggerStep = pTriggerStep->pNext;
@@ -31,79 +31,98 @@ static void sqliteDeleteTriggerStep(TriggerStep *pTriggerStep){
}
/*
** This is called by the parser when it sees a CREATE TRIGGER statement. See
** comments surrounding struct Trigger in sqliteInt.h for a description of
** how triggers are stored.
** This is called by the parser when it sees a CREATE TRIGGER statement
** up to the point of the BEGIN before the trigger actions. A Trigger
** structure is generated based on the information available and stored
** in pParse->pNewTrigger. After the trigger actions have been parsed, the
** sqliteFinishTrigger() function is called to complete the trigger
** construction process.
*/
void sqliteCreateTrigger(
void sqliteBeginTrigger(
Parse *pParse, /* The parse context of the CREATE TRIGGER statement */
Token *pName, /* The name of the trigger */
int tr_tm, /* One of TK_BEFORE, TK_AFTER , TK_INSTEAD */
int tr_tm, /* One of TK_BEFORE, TK_AFTER, TK_INSTEAD */
int op, /* One of TK_INSERT, TK_UPDATE, TK_DELETE */
IdList *pColumns, /* column list if this is an UPDATE OF trigger */
Token *pTableName, /* The name of the table/view the trigger applies to */
SrcList *pTableName,/* The name of the table/view the trigger applies to */
int foreach, /* One of TK_ROW or TK_STATEMENT */
Expr *pWhen, /* WHEN clause */
TriggerStep *pStepList, /* The triggered program */
Token *pAll /* Token that describes the complete CREATE TRIGGER */
int isTemp /* True if the TEMPORARY keyword is present */
){
Trigger *nt;
Table *tab;
char *zName = 0; /* Name of the trigger */
sqlite *db = pParse->db;
int iDb; /* When database to store the trigger in */
DbFixer sFix;
/* Check that:
** 1. the trigger name does not already exist.
** 2. the table (or view) does exist.
** 2. the table (or view) does exist in the same database as the trigger.
** 3. that we are not trying to create a trigger on the sqlite_master table
** 4. That we are not trying to create an INSTEAD OF trigger on a table.
** 5. That we are not trying to create a BEFORE or AFTER trigger on a view.
*/
{
char *tmp_str = sqliteStrNDup(pName->z, pName->n);
if( sqliteHashFind(&(pParse->db->trigHash), tmp_str, pName->n + 1) ){
sqliteSetNString(&pParse->zErrMsg, "trigger ", -1,
pName->z, pName->n, " already exists", -1, 0);
sqliteFree(tmp_str);
pParse->nErr++;
goto trigger_cleanup;
}
sqliteFree(tmp_str);
if( sqlite_malloc_failed ) goto trigger_cleanup;
assert( pTableName->nSrc==1 );
if( db->init.busy
&& sqliteFixInit(&sFix, pParse, db->init.iDb, "trigger", pName)
&& sqliteFixSrcList(&sFix, pTableName)
){
goto trigger_cleanup;
}
{
char *tmp_str = sqliteStrNDup(pTableName->z, pTableName->n);
if( tmp_str==0 ) goto trigger_cleanup;
tab = sqliteFindTable(pParse->db, tmp_str);
sqliteFree(tmp_str);
if( !tab ){
sqliteSetNString(&pParse->zErrMsg, "no such table: ", -1,
pTableName->z, pTableName->n, 0);
pParse->nErr++;
goto trigger_cleanup;
}
if( sqliteStrICmp(tab->zName, MASTER_NAME)==0 ){
sqliteSetString(&pParse->zErrMsg, "cannot create trigger on system "
"table: " MASTER_NAME, 0);
pParse->nErr++;
goto trigger_cleanup;
}
if( sqliteStrICmp(tab->zName, TEMP_MASTER_NAME)==0 ){
sqliteSetString(&pParse->zErrMsg, "cannot create trigger on system "
"table: " TEMP_MASTER_NAME, 0);
pParse->nErr++;
goto trigger_cleanup;
}
if( tab->pSelect && tr_tm != TK_INSTEAD ){
sqliteSetNString(&pParse->zErrMsg, "cannot create ", -1,
(tr_tm == TK_BEFORE)?"BEFORE":"AFTER", -1, " trigger on view: ", -1
, pTableName->z, pTableName->n, 0);
goto trigger_cleanup;
}
if( !tab->pSelect && tr_tm == TK_INSTEAD ){
sqliteSetNString(&pParse->zErrMsg, "cannot create INSTEAD OF", -1,
" trigger on table: ", -1, pTableName->z, pTableName->n, 0);
goto trigger_cleanup;
}
tab = sqliteSrcListLookup(pParse, pTableName);
if( !tab ){
goto trigger_cleanup;
}
iDb = isTemp ? 1 : tab->iDb;
if( iDb>=2 && !db->init.busy ){
sqliteErrorMsg(pParse, "triggers may not be added to auxiliary "
"database %s", db->aDb[tab->iDb].zName);
goto trigger_cleanup;
}
zName = sqliteStrNDup(pName->z, pName->n);
sqliteDequote(zName);
if( sqliteHashFind(&(db->aDb[iDb].trigHash), zName,pName->n+1) ){
sqliteErrorMsg(pParse, "trigger %T already exists", pName);
goto trigger_cleanup;
}
if( sqliteStrNICmp(tab->zName, "sqlite_", 7)==0 ){
sqliteErrorMsg(pParse, "cannot create trigger on system table");
pParse->nErr++;
goto trigger_cleanup;
}
if( tab->pSelect && tr_tm != TK_INSTEAD ){
sqliteErrorMsg(pParse, "cannot create %s trigger on view: %S",
(tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
goto trigger_cleanup;
}
if( !tab->pSelect && tr_tm == TK_INSTEAD ){
sqliteErrorMsg(pParse, "cannot create INSTEAD OF"
" trigger on table: %S", pTableName, 0);
goto trigger_cleanup;
}
#ifndef SQLITE_OMIT_AUTHORIZATION
{
int code = SQLITE_CREATE_TRIGGER;
const char *zDb = db->aDb[tab->iDb].zName;
const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
if( tab->iDb==1 || isTemp ) code = SQLITE_CREATE_TEMP_TRIGGER;
if( sqliteAuthCheck(pParse, code, zName, tab->zName, zDbTrig) ){
goto trigger_cleanup;
}
if( sqliteAuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(tab->iDb), 0, zDb)){
goto trigger_cleanup;
}
}
#endif
/* INSTEAD OF triggers can only appear on views and BEGIN triggers
** cannot appear on views. So we might as well translate every
** INSTEAD OF trigger into a BEFORE trigger. It simplifies code
** elsewhere.
*/
if (tr_tm == TK_INSTEAD){
tr_tm = TK_BEFORE;
}
@@ -111,23 +130,59 @@ void sqliteCreateTrigger(
/* Build the Trigger object */
nt = (Trigger*)sqliteMalloc(sizeof(Trigger));
if( nt==0 ) goto trigger_cleanup;
nt->name = sqliteStrNDup(pName->z, pName->n);
nt->table = sqliteStrNDup(pTableName->z, pTableName->n);
nt->name = zName;
zName = 0;
nt->table = sqliteStrDup(pTableName->a[0].zName);
if( sqlite_malloc_failed ) goto trigger_cleanup;
nt->iDb = iDb;
nt->iTabDb = tab->iDb;
nt->op = op;
nt->tr_tm = tr_tm;
nt->pWhen = sqliteExprDup(pWhen);
sqliteExprDelete(pWhen);
nt->pColumns = sqliteIdListDup(pColumns);
sqliteIdListDelete(pColumns);
nt->foreach = foreach;
sqliteTokenCopy(&nt->nameToken,pName);
assert( pParse->pNewTrigger==0 );
pParse->pNewTrigger = nt;
trigger_cleanup:
sqliteFree(zName);
sqliteSrcListDelete(pTableName);
sqliteIdListDelete(pColumns);
sqliteExprDelete(pWhen);
}
/*
** This routine is called after all of the trigger actions have been parsed
** in order to complete the process of building the trigger.
*/
void sqliteFinishTrigger(
Parse *pParse, /* Parser context */
TriggerStep *pStepList, /* The triggered program */
Token *pAll /* Token that describes the complete CREATE TRIGGER */
){
Trigger *nt = 0; /* The trigger whose construction is finishing up */
sqlite *db = pParse->db; /* The database */
DbFixer sFix;
if( pParse->nErr || pParse->pNewTrigger==0 ) goto triggerfinish_cleanup;
nt = pParse->pNewTrigger;
pParse->pNewTrigger = 0;
nt->step_list = pStepList;
while( pStepList ){
pStepList->pTrig = nt;
pStepList = pStepList->pNext;
}
if( sqliteFixInit(&sFix, pParse, nt->iDb, "trigger", &nt->nameToken)
&& sqliteFixTriggerStep(&sFix, nt->step_list) ){
goto triggerfinish_cleanup;
}
/* if we are not initializing, and this trigger is not on a TEMP table,
** build the sqlite_master entry
*/
if( !pParse->initFlag ){
static VdbeOp insertTrig[] = {
if( !db->init.busy ){
static VdbeOpList insertTrig[] = {
{ OP_NewRecno, 0, 0, 0 },
{ OP_String, 0, 0, "trigger" },
{ OP_String, 0, 0, 0 }, /* 2: trigger name */
@@ -142,40 +197,35 @@ void sqliteCreateTrigger(
/* Make an entry in the sqlite_master table */
v = sqliteGetVdbe(pParse);
if( v==0 ) goto trigger_cleanup;
if( v==0 ) goto triggerfinish_cleanup;
sqliteBeginWriteOperation(pParse, 0, 0);
sqliteOpenMasterTable(v, tab->isTemp);
sqliteOpenMasterTable(v, nt->iDb);
addr = sqliteVdbeAddOpList(v, ArraySize(insertTrig), insertTrig);
sqliteVdbeChangeP3(v, addr, tab->isTemp ? TEMP_MASTER_NAME : MASTER_NAME,
P3_STATIC);
sqliteVdbeChangeP3(v, addr+2, nt->name, 0);
sqliteVdbeChangeP3(v, addr+3, nt->table, 0);
sqliteVdbeChangeP3(v, addr+5, pAll->z, pAll->n);
if( !tab->isTemp ){
sqliteChangeCookie(pParse->db, v);
if( nt->iDb==0 ){
sqliteChangeCookie(db, v);
}
sqliteVdbeAddOp(v, OP_Close, 0, 0);
sqliteEndWriteOperation(pParse);
}
if( !pParse->explain ){
/* Stick it in the hash-table */
sqliteHashInsert(&(pParse->db->trigHash), nt->name, pName->n + 1, nt);
/* Attach it to the table object */
nt->pNext = tab->pTrigger;
tab->pTrigger = nt;
return;
}else{
sqliteFree(nt->name);
sqliteFree(nt->table);
sqliteFree(nt);
Table *pTab;
sqliteHashInsert(&db->aDb[nt->iDb].trigHash,
nt->name, strlen(nt->name)+1, nt);
pTab = sqliteLocateTable(pParse, nt->table, db->aDb[nt->iTabDb].zName);
assert( pTab!=0 );
nt->pNext = pTab->pTrigger;
pTab->pTrigger = nt;
nt = 0;
}
trigger_cleanup:
sqliteIdListDelete(pColumns);
sqliteExprDelete(pWhen);
triggerfinish_cleanup:
sqliteDeleteTrigger(nt);
sqliteDeleteTrigger(pParse->pNewTrigger);
pParse->pNewTrigger = 0;
sqliteDeleteTriggerStep(pStepList);
}
@@ -312,48 +362,123 @@ TriggerStep *sqliteTriggerDeleteStep(Token *pTableName, Expr *pWhere){
** Recursively delete a Trigger structure
*/
void sqliteDeleteTrigger(Trigger *pTrigger){
if( pTrigger==0 ) return;
sqliteDeleteTriggerStep(pTrigger->step_list);
sqliteFree(pTrigger->name);
sqliteFree(pTrigger->table);
sqliteExprDelete(pTrigger->pWhen);
sqliteIdListDelete(pTrigger->pColumns);
if( pTrigger->nameToken.dyn ) sqliteFree((char*)pTrigger->nameToken.z);
sqliteFree(pTrigger);
}
/*
* This function is called to drop a trigger from the database schema.
*
* This may be called directly from the parser, or from within
* sqliteDropTable(). In the latter case the "nested" argument is true.
* This may be called directly from the parser and therefore identifies
* the trigger by name. The sqliteDropTriggerPtr() routine does the
* same job as this routine except it take a spointer to the trigger
* instead of the trigger name.
*
* Note that this function does not delete the trigger entirely. Instead it
* removes it from the internal schema and places it in the trigDrop hash
* table. This is so that the trigger can be restored into the database schema
* if the transaction is rolled back.
*/
void sqliteDropTrigger(Parse *pParse, Token *pName, int nested){
char *zName;
void sqliteDropTrigger(Parse *pParse, SrcList *pName){
Trigger *pTrigger;
int i;
const char *zDb;
const char *zName;
int nName;
sqlite *db = pParse->db;
if( sqlite_malloc_failed ) goto drop_trigger_cleanup;
assert( pName->nSrc==1 );
zDb = pName->a[0].zDatabase;
zName = pName->a[0].zName;
nName = strlen(zName);
for(i=0; i<db->nDb; i++){
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
if( zDb && sqliteStrICmp(db->aDb[j].zName, zDb) ) continue;
pTrigger = sqliteHashFind(&(db->aDb[j].trigHash), zName, nName+1);
if( pTrigger ) break;
}
if( !pTrigger ){
sqliteErrorMsg(pParse, "no such trigger: %S", pName, 0);
goto drop_trigger_cleanup;
}
sqliteDropTriggerPtr(pParse, pTrigger, 0);
drop_trigger_cleanup:
sqliteSrcListDelete(pName);
}
/*
** Drop a trigger given a pointer to that trigger. If nested is false,
** then also generate code to remove the trigger from the SQLITE_MASTER
** table.
*/
void sqliteDropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){
Table *pTable;
Vdbe *v;
sqlite *db = pParse->db;
zName = sqliteStrNDup(pName->z, pName->n);
/* ensure that the trigger being dropped exists */
pTrigger = sqliteHashFind(&(pParse->db->trigHash), zName, pName->n + 1);
if( !pTrigger ){
sqliteSetNString(&pParse->zErrMsg, "no such trigger: ", -1,
zName, -1, 0);
sqliteFree(zName);
assert( pTrigger->iDb<db->nDb );
if( pTrigger->iDb>=2 ){
sqliteErrorMsg(pParse, "triggers may not be removed from "
"auxiliary database %s", db->aDb[pTrigger->iDb].zName);
return;
}
pTable = sqliteFindTable(db, pTrigger->table,db->aDb[pTrigger->iTabDb].zName);
assert(pTable);
assert( pTable->iDb==pTrigger->iDb || pTrigger->iDb==1 );
#ifndef SQLITE_OMIT_AUTHORIZATION
{
int code = SQLITE_DROP_TRIGGER;
const char *zDb = db->aDb[pTrigger->iDb].zName;
const char *zTab = SCHEMA_TABLE(pTrigger->iDb);
if( pTrigger->iDb ) code = SQLITE_DROP_TEMP_TRIGGER;
if( sqliteAuthCheck(pParse, code, pTrigger->name, pTable->zName, zDb) ||
sqliteAuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
return;
}
}
#endif
/* Generate code to destroy the database record of the trigger.
*/
if( pTable!=0 && !nested && (v = sqliteGetVdbe(pParse))!=0 ){
int base;
static VdbeOpList dropTrigger[] = {
{ OP_Rewind, 0, ADDR(9), 0},
{ OP_String, 0, 0, 0}, /* 1 */
{ OP_Column, 0, 1, 0},
{ OP_Ne, 0, ADDR(8), 0},
{ OP_String, 0, 0, "trigger"},
{ OP_Column, 0, 0, 0},
{ OP_Ne, 0, ADDR(8), 0},
{ OP_Delete, 0, 0, 0},
{ OP_Next, 0, ADDR(1), 0}, /* 8 */
};
sqliteBeginWriteOperation(pParse, 0, 0);
sqliteOpenMasterTable(v, pTrigger->iDb);
base = sqliteVdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
sqliteVdbeChangeP3(v, base+1, pTrigger->name, 0);
if( pTrigger->iDb==0 ){
sqliteChangeCookie(db, v);
}
sqliteVdbeAddOp(v, OP_Close, 0, 0);
sqliteEndWriteOperation(pParse);
}
/*
* If this is not an "explain", then delete the trigger structure.
*/
if( !pParse->explain ){
pTable = sqliteFindTable(pParse->db, pTrigger->table);
assert(pTable);
const char *zName = pTrigger->name;
int nName = strlen(zName);
if( pTable->pTrigger == pTrigger ){
pTable->pTrigger = pTrigger->pNext;
}else{
@@ -367,37 +492,9 @@ void sqliteDropTrigger(Parse *pParse, Token *pName, int nested){
}
assert(cc);
}
sqliteHashInsert(&(pParse->db->trigHash), zName, pName->n + 1, NULL);
sqliteHashInsert(&(db->aDb[pTrigger->iDb].trigHash), zName, nName+1, 0);
sqliteDeleteTrigger(pTrigger);
}
/* Generate code to destroy the database record of the trigger.
*/
if( pTable!=0 && !nested && (v = sqliteGetVdbe(pParse))!=0 ){
int base;
static VdbeOp dropTrigger[] = {
{ OP_Rewind, 0, ADDR(8), 0},
{ OP_String, 0, 0, 0}, /* 1 */
{ OP_MemStore, 1, 1, 0},
{ OP_MemLoad, 1, 0, 0}, /* 3 */
{ OP_Column, 0, 1, 0},
{ OP_Ne, 0, ADDR(7), 0},
{ OP_Delete, 0, 0, 0},
{ OP_Next, 0, ADDR(3), 0}, /* 7 */
};
sqliteBeginWriteOperation(pParse, 0, 0);
sqliteOpenMasterTable(v, pTable->isTemp);
base = sqliteVdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
sqliteVdbeChangeP3(v, base+1, zName, 0);
if( !pTable->isTemp ){
sqliteChangeCookie(pParse->db, v);
}
sqliteVdbeAddOp(v, OP_Close, 0, 0);
sqliteEndWriteOperation(pParse);
}
sqliteFree(zName);
}
/*
@@ -466,6 +563,36 @@ int sqliteTriggersExist(
return 0;
}
/*
** Convert the pStep->target token into a SrcList and return a pointer
** to that SrcList.
**
** This routine adds a specific database name, if needed, to the target when
** forming the SrcList. This prevents a trigger in one database from
** referring to a target in another database. An exception is when the
** trigger is in TEMP in which case it can refer to any other database it
** wants.
*/
static SrcList *targetSrcList(
Parse *pParse, /* The parsing context */
TriggerStep *pStep /* The trigger containing the target token */
){
Token sDb; /* Dummy database name token */
int iDb; /* Index of the database to use */
SrcList *pSrc; /* SrcList to be returned */
iDb = pStep->pTrig->iDb;
if( iDb==0 || iDb>=2 ){
assert( iDb<pParse->db->nDb );
sDb.z = pParse->db->aDb[iDb].zName;
sDb.n = strlen(sDb.z);
pSrc = sqliteSrcListAppend(0, &sDb, &pStep->target);
} else {
pSrc = sqliteSrcListAppend(0, &pStep->target, 0);
}
return pSrc;
}
/*
** Generate VDBE code for zero or more statements inside the body of a
** trigger.
@@ -480,6 +607,7 @@ static int codeTriggerProgram(
while( pTriggerStep ){
int saveNTab = pParse->nTab;
orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
pParse->trigStack->orconf = orconf;
switch( pTriggerStep->op ){
@@ -492,24 +620,29 @@ static int codeTriggerProgram(
break;
}
case TK_UPDATE: {
SrcList *pSrc;
pSrc = targetSrcList(pParse, pTriggerStep);
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
sqliteUpdate(pParse, &pTriggerStep->target,
sqliteUpdate(pParse, pSrc,
sqliteExprListDup(pTriggerStep->pExprList),
sqliteExprDup(pTriggerStep->pWhere), orconf);
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
break;
}
case TK_INSERT: {
sqliteInsert(pParse, &pTriggerStep->target,
sqliteExprListDup(pTriggerStep->pExprList),
sqliteSelectDup(pTriggerStep->pSelect),
sqliteIdListDup(pTriggerStep->pIdList), orconf);
SrcList *pSrc;
pSrc = targetSrcList(pParse, pTriggerStep);
sqliteInsert(pParse, pSrc,
sqliteExprListDup(pTriggerStep->pExprList),
sqliteSelectDup(pTriggerStep->pSelect),
sqliteIdListDup(pTriggerStep->pIdList), orconf);
break;
}
case TK_DELETE: {
SrcList *pSrc;
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
sqliteDeleteFrom(pParse, &pTriggerStep->target,
sqliteExprDup(pTriggerStep->pWhere));
pSrc = targetSrcList(pParse, pTriggerStep);
sqliteDeleteFrom(pParse, pSrc, sqliteExprDup(pTriggerStep->pWhere));
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
break;
}
@@ -558,7 +691,7 @@ int sqliteCodeRowTrigger(
TriggerStack * pTriggerStack;
assert(op == TK_UPDATE || op == TK_INSERT || op == TK_DELETE);
assert(tr_tm == TK_BEFORE || tr_tm == TK_AFTER);
assert(tr_tm == TK_BEFORE || tr_tm == TK_AFTER );
assert(newIdx != -1 || oldIdx != -1);
@@ -587,9 +720,9 @@ int sqliteCodeRowTrigger(
int endTrigger;
SrcList dummyTablist;
Expr * whenExpr;
AuthContext sContext;
dummyTablist.nSrc = 0;
dummyTablist.a = 0;
/* Push an entry on to the trigger stack */
pTriggerStack->pTrigger = pTrigger;
@@ -599,11 +732,12 @@ int sqliteCodeRowTrigger(
pTriggerStack->pNext = pParse->trigStack;
pTriggerStack->ignoreJump = ignoreJump;
pParse->trigStack = pTriggerStack;
sqliteAuthContextPush(pParse, &sContext, pTrigger->name);
/* code the WHEN clause */
endTrigger = sqliteVdbeMakeLabel(pParse->pVdbe);
whenExpr = sqliteExprDup(pTrigger->pWhen);
if( sqliteExprResolveIds(pParse, 0, &dummyTablist, 0, whenExpr) ){
if( sqliteExprResolveIds(pParse, &dummyTablist, 0, whenExpr) ){
pParse->trigStack = pParse->trigStack->pNext;
sqliteFree(pTriggerStack);
sqliteExprDelete(whenExpr);
@@ -612,10 +746,13 @@ int sqliteCodeRowTrigger(
sqliteExprIfFalse(pParse, whenExpr, endTrigger, 1);
sqliteExprDelete(whenExpr);
sqliteVdbeAddOp(pParse->pVdbe, OP_ContextPush, 0, 0);
codeTriggerProgram(pParse, pTrigger->step_list, orconf);
sqliteVdbeAddOp(pParse->pVdbe, OP_ContextPop, 0, 0);
/* Pop the entry off the trigger stack */
pParse->trigStack = pParse->trigStack->pNext;
sqliteAuthContextPop(&sContext);
sqliteFree(pTriggerStack);
sqliteVdbeResolveLabel(pParse->pVdbe, endTrigger);
@@ -625,147 +762,3 @@ int sqliteCodeRowTrigger(
return 0;
}
/*
* This function is called to code ON UPDATE and ON DELETE triggers on
* views.
*
* This function deletes the data pointed at by the pWhere and pChanges
* arguments before it completes.
*/
void sqliteViewTriggers(
Parse *pParse,
Table *pTab, /* The view to code triggers on */
Expr *pWhere, /* The WHERE clause of the statement causing triggers*/
int orconf, /* The ON CONFLICT policy specified as part of the
statement causing these triggers */
ExprList *pChanges /* If this is an statement causing triggers to fire
is an UPDATE, then this list holds the columns
to update and the expressions to update them to.
See comments for sqliteUpdate(). */
){
int oldIdx = -1;
int newIdx = -1;
int *aXRef = 0;
Vdbe *v;
int endOfLoop;
int startOfLoop;
Select theSelect;
Token tblNameToken;
assert(pTab->pSelect);
tblNameToken.z = pTab->zName;
tblNameToken.n = strlen(pTab->zName);
theSelect.isDistinct = 0;
theSelect.pEList = sqliteExprListAppend(0, sqliteExpr(TK_ALL, 0, 0, 0), 0);
theSelect.pSrc = sqliteSrcListAppend(0, &tblNameToken);
theSelect.pWhere = pWhere; pWhere = 0;
theSelect.pGroupBy = 0;
theSelect.pHaving = 0;
theSelect.pOrderBy = 0;
theSelect.op = TK_SELECT; /* ?? */
theSelect.pPrior = 0;
theSelect.nLimit = -1;
theSelect.nOffset = -1;
theSelect.zSelect = 0;
theSelect.base = 0;
v = sqliteGetVdbe(pParse);
assert(v);
sqliteBeginWriteOperation(pParse, 1, 0);
/* Allocate temp tables */
oldIdx = pParse->nTab++;
sqliteVdbeAddOp(v, OP_OpenTemp, oldIdx, 0);
if( pChanges ){
newIdx = pParse->nTab++;
sqliteVdbeAddOp(v, OP_OpenTemp, newIdx, 0);
}
/* Snapshot the view */
if( sqliteSelect(pParse, &theSelect, SRT_Table, oldIdx, 0, 0, 0) ){
goto trigger_cleanup;
}
/* loop thru the view snapshot, executing triggers for each row */
endOfLoop = sqliteVdbeMakeLabel(v);
sqliteVdbeAddOp(v, OP_Rewind, oldIdx, endOfLoop);
/* Loop thru the view snapshot, executing triggers for each row */
startOfLoop = sqliteVdbeCurrentAddr(v);
/* Build the updated row if required */
if( pChanges ){
int ii;
aXRef = sqliteMalloc( sizeof(int) * pTab->nCol );
if( aXRef==0 ) goto trigger_cleanup;
for(ii = 0; ii < pTab->nCol; ii++){
aXRef[ii] = -1;
}
for(ii=0; ii<pChanges->nExpr; ii++){
int jj;
if( sqliteExprResolveIds(pParse, oldIdx, theSelect.pSrc , 0,
pChanges->a[ii].pExpr) ){
goto trigger_cleanup;
}
if( sqliteExprCheck(pParse, pChanges->a[ii].pExpr, 0, 0) )
goto trigger_cleanup;
for(jj=0; jj<pTab->nCol; jj++){
if( sqliteStrICmp(pTab->aCol[jj].zName, pChanges->a[ii].zName)==0 ){
aXRef[jj] = ii;
break;
}
}
if( jj>=pTab->nCol ){
sqliteSetString(&pParse->zErrMsg, "no such column: ",
pChanges->a[ii].zName, 0);
pParse->nErr++;
goto trigger_cleanup;
}
}
sqliteVdbeAddOp(v, OP_Integer, 13, 0);
for(ii = 0; ii<pTab->nCol; ii++){
if( aXRef[ii] < 0 ){
sqliteVdbeAddOp(v, OP_Column, oldIdx, ii);
}else{
sqliteExprCode(pParse, pChanges->a[aXRef[ii]].pExpr);
}
}
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
sqliteVdbeAddOp(v, OP_Rewind, newIdx, 0);
sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE,
pTab, newIdx, oldIdx, orconf, endOfLoop);
sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER,
pTab, newIdx, oldIdx, orconf, endOfLoop);
}else{
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_BEFORE, pTab, -1, oldIdx,
orconf, endOfLoop);
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1, oldIdx,
orconf, endOfLoop);
}
sqliteVdbeAddOp(v, OP_Next, oldIdx, startOfLoop);
sqliteVdbeResolveLabel(v, endOfLoop);
sqliteEndWriteOperation(pParse);
trigger_cleanup:
sqliteFree(aXRef);
sqliteExprListDelete(pChanges);
sqliteExprDelete(pWhere);
sqliteExprListDelete(theSelect.pEList);
sqliteSrcListDelete(theSelect.pSrc);
sqliteExprDelete(theSelect.pWhere);
return;
}
+235 -178
View File
@@ -12,87 +12,85 @@
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
**
** $Id: update.c,v 1.50 2002/09/14 13:47:32 drh Exp $
** $Id: update.c,v 1.70.2.1 2004/04/29 16:16:29 drh Exp $
*/
#include "sqliteInt.h"
/*
** Process an UPDATE statement.
**
** UPDATE OR IGNORE table_wxyz SET a=b, c=d WHERE e<5 AND f NOT NULL;
** \_______/ \________/ \______/ \________________/
* onError pTabList pChanges pWhere
*/
void sqliteUpdate(
Parse *pParse, /* The parser context */
Token *pTableName, /* The table in which we should change things */
SrcList *pTabList, /* The table in which we should change things */
ExprList *pChanges, /* Things to be changed */
Expr *pWhere, /* The WHERE clause. May be null */
int onError /* How to handle constraint errors */
){
int i, j; /* Loop counters */
Table *pTab; /* The table to be updated */
SrcList *pTabList = 0; /* Fake FROM clause containing only pTab */
int addr; /* VDBE instruction address of the start of the loop */
int loopStart; /* VDBE instruction address of the start of the loop */
int jumpInst; /* Addr of VDBE instruction to jump out of loop */
WhereInfo *pWInfo; /* Information about the WHERE clause */
Vdbe *v; /* The virtual database engine */
Index *pIdx; /* For looping over indices */
int nIdx; /* Number of indices that need updating */
int nIdxTotal; /* Total number of indices */
int base; /* Index of first available table cursor */
int iCur; /* VDBE Cursor number of pTab */
sqlite *db; /* The database structure */
Index **apIdx = 0; /* An array of indices that need updating too */
char *aIdxUsed = 0; /* aIdxUsed[i] if the i-th index is used */
char *aIdxUsed = 0; /* aIdxUsed[i]==1 if the i-th index is used */
int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
** an expression for the i-th column of the table.
** aXRef[i]==-1 if the i-th column is not changed. */
int openOp; /* Opcode used to open tables */
int chngRecno; /* True if the record number is being changed */
Expr *pRecnoExpr; /* Expression defining the new record number */
int openAll; /* True if all indices need to be opened */
int isView; /* Trying to update a view */
int iStackDepth; /* Index of memory cell holding stack depth */
AuthContext sContext; /* The authorization context */
int row_triggers_exist = 0;
int before_triggers; /* True if there are any BEFORE triggers */
int after_triggers; /* True if there are any AFTER triggers */
int row_triggers_exist = 0; /* True if any row triggers exist */
int newIdx = -1; /* index of trigger "new" temp table */
int oldIdx = -1; /* index of trigger "old" temp table */
sContext.pParse = 0;
if( pParse->nErr || sqlite_malloc_failed ) goto update_cleanup;
db = pParse->db;
assert( pTabList->nSrc==1 );
iStackDepth = pParse->nMem++;
/* Check for the special case of a VIEW with one or more ON UPDATE triggers
* defined
*/
{
char *zTab = sqliteTableNameFromToken(pTableName);
if( zTab != 0 ){
pTab = sqliteFindTable(pParse->db, zTab);
if( pTab ){
row_triggers_exist =
sqliteTriggersExist(pParse, pTab->pTrigger,
TK_UPDATE, TK_BEFORE, TK_ROW, pChanges) ||
sqliteTriggersExist(pParse, pTab->pTrigger,
TK_UPDATE, TK_AFTER, TK_ROW, pChanges);
}
sqliteFree(zTab);
if( row_triggers_exist && pTab->pSelect ){
/* Just fire VIEW triggers */
sqliteViewTriggers(pParse, pTab, pWhere, onError, pChanges);
return;
}
/* Locate the table which we want to update.
*/
pTab = sqliteSrcListLookup(pParse, pTabList);
if( pTab==0 ) goto update_cleanup;
before_triggers = sqliteTriggersExist(pParse, pTab->pTrigger,
TK_UPDATE, TK_BEFORE, TK_ROW, pChanges);
after_triggers = sqliteTriggersExist(pParse, pTab->pTrigger,
TK_UPDATE, TK_AFTER, TK_ROW, pChanges);
row_triggers_exist = before_triggers || after_triggers;
isView = pTab->pSelect!=0;
if( sqliteIsReadOnly(pParse, pTab, before_triggers) ){
goto update_cleanup;
}
if( isView ){
if( sqliteViewGetColumnNames(pParse, pTab) ){
goto update_cleanup;
}
}
/* Locate the table which we want to update. This table has to be
** put in an SrcList structure because some of the subroutines we
** will be calling are designed to work with multiple tables and expect
** an SrcList* parameter instead of just a Table* parameter.
*/
pTabList = sqliteTableTokenToSrcList(pParse, pTableName);
if( pTabList==0 ) goto update_cleanup;
pTab = pTabList->a[0].pTab;
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
aXRef = sqliteMalloc( sizeof(int) * pTab->nCol );
if( aXRef==0 ) goto update_cleanup;
for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
/* If there are FOR EACH ROW triggers, allocate temp tables */
/* If there are FOR EACH ROW triggers, allocate cursors for the
** special OLD and NEW tables
*/
if( row_triggers_exist ){
newIdx = pParse->nTab++;
oldIdx = pParse->nTab++;
@@ -103,26 +101,20 @@ void sqliteUpdate(
** need to occur right after the database cursor. So go ahead and
** allocate enough space, just in case.
*/
base = pParse->nTab++;
pTabList->a[0].iCursor = iCur = pParse->nTab++;
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
pParse->nTab++;
}
/* Resolve the column names in all the expressions in both the
** WHERE clause and in the new values. Also find the column index
** for each column to be updated in the pChanges array.
/* Resolve the column names in all the expressions of the
** of the UPDATE statement. Also find the column index
** for each column to be updated in the pChanges array. For each
** column to be updated, make sure we have authorization to change
** that column.
*/
if( pWhere ){
if( sqliteExprResolveIds(pParse, base, pTabList, 0, pWhere) ){
goto update_cleanup;
}
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
goto update_cleanup;
}
}
chngRecno = 0;
for(i=0; i<pChanges->nExpr; i++){
if( sqliteExprResolveIds(pParse, base, pTabList, 0, pChanges->a[i].pExpr) ){
if( sqliteExprResolveIds(pParse, pTabList, 0, pChanges->a[i].pExpr) ){
goto update_cleanup;
}
if( sqliteExprCheck(pParse, pChanges->a[i].pExpr, 0, 0) ){
@@ -139,11 +131,26 @@ void sqliteUpdate(
}
}
if( j>=pTab->nCol ){
sqliteSetString(&pParse->zErrMsg, "no such column: ",
pChanges->a[i].zName, 0);
pParse->nErr++;
goto update_cleanup;
if( sqliteIsRowid(pChanges->a[i].zName) ){
chngRecno = 1;
pRecnoExpr = pChanges->a[i].pExpr;
}else{
sqliteErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
goto update_cleanup;
}
}
#ifndef SQLITE_OMIT_AUTHORIZATION
{
int rc;
rc = sqliteAuthCheck(pParse, SQLITE_UPDATE, pTab->zName,
pTab->aCol[j].zName, db->aDb[pTab->iDb].zName);
if( rc==SQLITE_DENY ){
goto update_cleanup;
}else if( rc==SQLITE_IGNORE ){
aXRef[j] = -1;
}
}
#endif
}
/* Allocate memory for the array apIdx[] and fill it with pointers to every
@@ -182,15 +189,43 @@ void sqliteUpdate(
}
}
/* Resolve the column names in all the expressions in the
** WHERE clause.
*/
if( pWhere ){
if( sqliteExprResolveIds(pParse, pTabList, 0, pWhere) ){
goto update_cleanup;
}
if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
goto update_cleanup;
}
}
/* Start the view context
*/
if( isView ){
sqliteAuthContextPush(pParse, &sContext, pTab->zName);
}
/* Begin generating code.
*/
v = sqliteGetVdbe(pParse);
if( v==0 ) goto update_cleanup;
sqliteBeginWriteOperation(pParse, 1, !row_triggers_exist && pTab->isTemp);
sqliteBeginWriteOperation(pParse, 1, pTab->iDb);
/* If we are trying to update a view, construct that view into
** a temporary table.
*/
if( isView ){
Select *pView;
pView = sqliteSelectDup(pTab->pSelect);
sqliteSelect(pParse, pView, SRT_TempTable, iCur, 0, 0, 0);
sqliteSelectDelete(pView);
}
/* Begin the database scan
*/
pWInfo = sqliteWhereBegin(pParse, base, pTabList, pWhere, 1, 0);
pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 1, 0);
if( pWInfo==0 ) goto update_cleanup;
/* Remember the index of every item to be updated.
@@ -208,153 +243,175 @@ void sqliteUpdate(
}
if( row_triggers_exist ){
int ii;
sqliteVdbeAddOp(v, OP_OpenTemp, oldIdx, 0);
sqliteVdbeAddOp(v, OP_OpenTemp, newIdx, 0);
/* Create pseudo-tables for NEW and OLD
*/
sqliteVdbeAddOp(v, OP_OpenPseudo, oldIdx, 0);
sqliteVdbeAddOp(v, OP_OpenPseudo, newIdx, 0);
/* The top of the update loop for when there are triggers.
*/
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
sqliteVdbeAddOp(v, OP_StackDepth, 0, 0);
sqliteVdbeAddOp(v, OP_MemStore, iStackDepth, 1);
loopStart = sqliteVdbeAddOp(v, OP_MemLoad, iStackDepth, 0);
sqliteVdbeAddOp(v, OP_StackReset, 0, 0);
jumpInst = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
/* Open a cursor and make it point to the record that is
** being updated.
*/
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
sqliteVdbeAddOp(v, (pTab->isTemp?OP_OpenAux:OP_Open), base, pTab->tnum);
sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
sqliteVdbeAddOp(v, OP_Integer, 13, 0);
for(ii = 0; ii < pTab->nCol; ii++){
if( ii == pTab->iPKey ){
sqliteVdbeAddOp(v, OP_Recno, base, 0);
}else{
sqliteVdbeAddOp(v, OP_Column, base, ii);
}
if( !isView ){
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqliteVdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
}
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
/* Generate the OLD table
*/
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
sqliteVdbeAddOp(v, OP_RowData, iCur, 0);
sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
sqliteVdbeAddOp(v, OP_Integer, 13, 0);
for(ii = 0; ii < pTab->nCol; ii++){
if( aXRef[ii] < 0 ){
if( ii == pTab->iPKey ){
sqliteVdbeAddOp(v, OP_Recno, base, 0);
}else{
sqliteVdbeAddOp(v, OP_Column, base, ii);
}
/* Generate the NEW table
*/
if( chngRecno ){
sqliteExprCode(pParse, pRecnoExpr);
}else{
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
}
for(i=0; i<pTab->nCol; i++){
if( i==pTab->iPKey ){
sqliteVdbeAddOp(v, OP_String, 0, 0);
continue;
}
j = aXRef[i];
if( j<0 ){
sqliteVdbeAddOp(v, OP_Column, iCur, i);
}else{
sqliteExprCode(pParse, pChanges->a[aXRef[ii]].pExpr);
sqliteExprCode(pParse, pChanges->a[j].pExpr);
}
}
sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
sqliteVdbeAddOp(v, OP_Close, base, 0);
sqliteVdbeAddOp(v, OP_Rewind, oldIdx, 0);
sqliteVdbeAddOp(v, OP_Rewind, newIdx, 0);
if( !isView ){
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
}
/* Fire the BEFORE and INSTEAD OF triggers
*/
if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, pTab,
newIdx, oldIdx, onError, addr) ){
newIdx, oldIdx, onError, loopStart) ){
goto update_cleanup;
}
}
/* Rewind the list of records that need to be updated and
** open every index that needs updating. Note that if any
** index could potentially invoke a REPLACE conflict resolution
** action, then we need to open all indices because we might need
** to be deleting some records.
*/
openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite;
sqliteVdbeAddOp(v, openOp, base, pTab->tnum);
if( onError==OE_Replace ){
openAll = 1;
}else{
openAll = 0;
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
if( pIdx->onError==OE_Replace ){
openAll = 1;
break;
if( !isView ){
/*
** Open every index that needs updating. Note that if any
** index could potentially invoke a REPLACE conflict resolution
** action, then we need to open all indices because we might need
** to be deleting some records.
*/
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqliteVdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum);
if( onError==OE_Replace ){
openAll = 1;
}else{
openAll = 0;
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
if( pIdx->onError==OE_Replace ){
openAll = 1;
break;
}
}
}
}
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
if( openAll || aIdxUsed[i] ){
sqliteVdbeAddOp(v, openOp, base+i+1, pIdx->tnum);
assert( pParse->nTab>base+i+1 );
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
if( openAll || aIdxUsed[i] ){
sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
sqliteVdbeAddOp(v, OP_OpenWrite, iCur+i+1, pIdx->tnum);
assert( pParse->nTab>iCur+i+1 );
}
}
}
/* Loop over every record that needs updating. We have to load
** the old data for each record to be updated because some columns
** might not change and we will need to copy the old value.
** Also, the old data is needed to delete the old index entires.
** So make the cursor point at the old record.
*/
if( !row_triggers_exist ){
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
addr = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
}
sqliteVdbeAddOp(v, OP_NotExists, base, addr);
/* If the record number will change, push the record number as it
** will be after the update. (The old record number is currently
** on top of the stack.)
*/
if( chngRecno ){
sqliteExprCode(pParse, pRecnoExpr);
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
}
/* Compute new data for this record.
*/
for(i=0; i<pTab->nCol; i++){
if( i==pTab->iPKey ){
sqliteVdbeAddOp(v, OP_String, 0, 0);
continue;
/* Loop over every record that needs updating. We have to load
** the old data for each record to be updated because some columns
** might not change and we will need to copy the old value.
** Also, the old data is needed to delete the old index entires.
** So make the cursor point at the old record.
*/
if( !row_triggers_exist ){
sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
jumpInst = loopStart = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
}
j = aXRef[i];
if( j<0 ){
sqliteVdbeAddOp(v, OP_Column, base, i);
}else{
sqliteExprCode(pParse, pChanges->a[j].pExpr);
sqliteVdbeAddOp(v, OP_NotExists, iCur, loopStart);
/* If the record number will change, push the record number as it
** will be after the update. (The old record number is currently
** on top of the stack.)
*/
if( chngRecno ){
sqliteExprCode(pParse, pRecnoExpr);
sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
}
/* Compute new data for this record.
*/
for(i=0; i<pTab->nCol; i++){
if( i==pTab->iPKey ){
sqliteVdbeAddOp(v, OP_String, 0, 0);
continue;
}
j = aXRef[i];
if( j<0 ){
sqliteVdbeAddOp(v, OP_Column, iCur, i);
}else{
sqliteExprCode(pParse, pChanges->a[j].pExpr);
}
}
/* Do constraint checks
*/
sqliteGenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1,
onError, loopStart);
/* Delete the old indices for the current record.
*/
sqliteGenerateRowIndexDelete(db, v, pTab, iCur, aIdxUsed);
/* If changing the record number, delete the old record.
*/
if( chngRecno ){
sqliteVdbeAddOp(v, OP_Delete, iCur, 0);
}
/* Create the new index entries and the new record.
*/
sqliteCompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, -1);
}
/* Do constraint checks
*/
sqliteGenerateConstraintChecks(pParse, pTab, base, aIdxUsed, chngRecno, 1,
onError, addr);
/* Delete the old indices for the current record.
*/
sqliteGenerateRowIndexDelete(db, v, pTab, base, aIdxUsed);
/* If changing the record number, delete the old record.
*/
if( chngRecno ){
sqliteVdbeAddOp(v, OP_Delete, base, 0);
}
/* Create the new index entries and the new record.
*/
sqliteCompleteInsertion(pParse, pTab, base, aIdxUsed, chngRecno, 1);
/* Increment the row counter
*/
if( db->flags & SQLITE_CountRows && !pParse->trigStack){
sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
}
/* If there are triggers, close all the cursors after each iteration
** through the loop. The fire the after triggers.
*/
if( row_triggers_exist ){
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
if( openAll || aIdxUsed[i] )
sqliteVdbeAddOp(v, OP_Close, base+i+1, 0);
if( !isView ){
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
if( openAll || aIdxUsed[i] )
sqliteVdbeAddOp(v, OP_Close, iCur+i+1, 0);
}
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
pParse->nTab = iCur;
}
sqliteVdbeAddOp(v, OP_Close, base, 0);
pParse->nTab = base;
if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, pTab,
newIdx, oldIdx, onError, addr) ){
newIdx, oldIdx, onError, loopStart) ){
goto update_cleanup;
}
}
@@ -362,37 +419,37 @@ void sqliteUpdate(
/* Repeat the above with the next record to be updated, until
** all record selected by the WHERE clause have been updated.
*/
sqliteVdbeAddOp(v, OP_Goto, 0, addr);
sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
sqliteVdbeAddOp(v, OP_Goto, 0, loopStart);
sqliteVdbeChangeP2(v, jumpInst, sqliteVdbeCurrentAddr(v));
sqliteVdbeAddOp(v, OP_ListReset, 0, 0);
/* Close all tables if there were no FOR EACH ROW triggers */
if( !row_triggers_exist ){
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
if( openAll || aIdxUsed[i] ){
sqliteVdbeAddOp(v, OP_Close, base+i+1, 0);
sqliteVdbeAddOp(v, OP_Close, iCur+i+1, 0);
}
}
sqliteVdbeAddOp(v, OP_Close, base, 0);
pParse->nTab = base;
sqliteVdbeAddOp(v, OP_Close, iCur, 0);
pParse->nTab = iCur;
}else{
sqliteVdbeAddOp(v, OP_Close, newIdx, 0);
sqliteVdbeAddOp(v, OP_Close, oldIdx, 0);
}
sqliteVdbeAddOp(v, OP_SetCounts, 0, 0);
sqliteEndWriteOperation(pParse);
/*
** Return the number of rows that were changed.
*/
if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
sqliteVdbeAddOp(v, OP_ColumnCount, 1, 0);
sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
sqliteVdbeChangeP3(v, -1, "rows updated", P3_STATIC);
sqliteVdbeOp3(v, OP_ColumnName, 0, 1, "rows updated", P3_STATIC);
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
}
update_cleanup:
sqliteAuthContextPop(&sContext);
sqliteFree(apIdx);
sqliteFree(aXRef);
sqliteSrcListDelete(pTabList);
+226 -255
View File
@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.50 2002/08/26 19:55:08 drh Exp $
** $Id: util.c,v 1.74 2004/02/22 17:49:34 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -43,15 +43,19 @@ int sqlite_iMallocFail; /* Fail sqliteMalloc() after this many calls */
static int memcnt = 0;
#endif
/*
** Number of 32-bit guard words
*/
#define N_GUARD 1
/*
** Allocate new memory and set it to zero. Return NULL if
** no memory is available.
*/
void *sqliteMalloc_(int n, char *zFile, int line){
void *sqliteMalloc_(int n, int bZero, char *zFile, int line){
void *p;
int *pi;
int k;
int i, k;
if( sqlite_iMallocFail>=0 ){
sqlite_iMallocFail--;
if( sqlite_iMallocFail==0 ){
@@ -66,17 +70,17 @@ void *sqliteMalloc_(int n, char *zFile, int line){
}
if( n==0 ) return 0;
k = (n+sizeof(int)-1)/sizeof(int);
pi = malloc( (3+k)*sizeof(int));
pi = malloc( (N_GUARD*2+1+k)*sizeof(int));
if( pi==0 ){
sqlite_malloc_failed++;
return 0;
}
sqlite_nMalloc++;
pi[0] = 0xdead1122;
pi[1] = n;
pi[k+2] = 0xdead3344;
p = &pi[2];
memset(p, 0, n);
for(i=0; i<N_GUARD; i++) pi[i] = 0xdead1122;
pi[N_GUARD] = n;
for(i=0; i<N_GUARD; i++) pi[k+1+N_GUARD+i] = 0xdead3344;
p = &pi[N_GUARD+1];
memset(p, bZero==0, n);
#if MEMORY_DEBUG>1
fprintf(stderr,"%06d malloc %d bytes at 0x%x from %s:%d\n",
++memcnt, n, (int)p, zFile,line);
@@ -84,26 +88,52 @@ void *sqliteMalloc_(int n, char *zFile, int line){
return p;
}
/*
** Check to see if the given pointer was obtained from sqliteMalloc()
** and is able to hold at least N bytes. Raise an exception if this
** is not the case.
**
** This routine is used for testing purposes only.
*/
void sqliteCheckMemory(void *p, int N){
int *pi = p;
int n, i, k;
pi -= N_GUARD+1;
for(i=0; i<N_GUARD; i++){
assert( pi[i]==0xdead1122 );
}
n = pi[N_GUARD];
assert( N>=0 && N<n );
k = (n+sizeof(int)-1)/sizeof(int);
for(i=0; i<N_GUARD; i++){
assert( pi[k+N_GUARD+1+i]==0xdead3344 );
}
}
/*
** Free memory previously obtained from sqliteMalloc()
*/
void sqliteFree_(void *p, char *zFile, int line){
if( p ){
int *pi, k, n;
int *pi, i, k, n;
pi = p;
pi -= 2;
pi -= N_GUARD+1;
sqlite_nFree++;
if( pi[0]!=0xdead1122 ){
fprintf(stderr,"Low-end memory corruption at 0x%x\n", (int)p);
return;
for(i=0; i<N_GUARD; i++){
if( pi[i]!=0xdead1122 ){
fprintf(stderr,"Low-end memory corruption at 0x%x\n", (int)p);
return;
}
}
n = pi[1];
n = pi[N_GUARD];
k = (n+sizeof(int)-1)/sizeof(int);
if( pi[k+2]!=0xdead3344 ){
fprintf(stderr,"High-end memory corruption at 0x%x\n", (int)p);
return;
for(i=0; i<N_GUARD; i++){
if( pi[k+N_GUARD+1+i]!=0xdead3344 ){
fprintf(stderr,"High-end memory corruption at 0x%x\n", (int)p);
return;
}
}
memset(pi, 0xff, (k+3)*sizeof(int));
memset(pi, 0xff, (k+N_GUARD*2+1)*sizeof(int));
#if MEMORY_DEBUG>1
fprintf(stderr,"%06d free %d bytes at 0x%x from %s:%d\n",
++memcnt, n, (int)p, zFile,line);
@@ -118,42 +148,45 @@ void sqliteFree_(void *p, char *zFile, int line){
** works just like sqliteFree().
*/
void *sqliteRealloc_(void *oldP, int n, char *zFile, int line){
int *oldPi, *pi, k, oldN, oldK;
int *oldPi, *pi, i, k, oldN, oldK;
void *p;
if( oldP==0 ){
return sqliteMalloc_(n,zFile,line);
return sqliteMalloc_(n,1,zFile,line);
}
if( n==0 ){
sqliteFree_(oldP,zFile,line);
return 0;
}
oldPi = oldP;
oldPi -= 2;
oldPi -= N_GUARD+1;
if( oldPi[0]!=0xdead1122 ){
fprintf(stderr,"Low-end memory corruption in realloc at 0x%x\n", (int)p);
fprintf(stderr,"Low-end memory corruption in realloc at 0x%x\n", (int)oldP);
return 0;
}
oldN = oldPi[1];
oldN = oldPi[N_GUARD];
oldK = (oldN+sizeof(int)-1)/sizeof(int);
if( oldPi[oldK+2]!=0xdead3344 ){
fprintf(stderr,"High-end memory corruption in realloc at 0x%x\n", (int)p);
return 0;
for(i=0; i<N_GUARD; i++){
if( oldPi[oldK+N_GUARD+1+i]!=0xdead3344 ){
fprintf(stderr,"High-end memory corruption in realloc at 0x%x\n",
(int)oldP);
return 0;
}
}
k = (n + sizeof(int) - 1)/sizeof(int);
pi = malloc( (k+3)*sizeof(int) );
pi = malloc( (k+N_GUARD*2+1)*sizeof(int) );
if( pi==0 ){
sqlite_malloc_failed++;
return 0;
}
pi[0] = 0xdead1122;
pi[1] = n;
pi[k+2] = 0xdead3344;
p = &pi[2];
for(i=0; i<N_GUARD; i++) pi[i] = 0xdead1122;
pi[N_GUARD] = n;
for(i=0; i<N_GUARD; i++) pi[k+N_GUARD+1+i] = 0xdead3344;
p = &pi[N_GUARD+1];
memcpy(p, oldP, n>oldN ? oldN : n);
if( n>oldN ){
memset(&((char*)p)[oldN], 0, n-oldN);
}
memset(oldPi, 0, (oldK+3)*sizeof(int));
memset(oldPi, 0xab, (oldK+N_GUARD+2)*sizeof(int));
free(oldPi);
#if MEMORY_DEBUG>1
fprintf(stderr,"%06d realloc %d to %d bytes at 0x%x to 0x%x at %s:%d\n",
@@ -190,14 +223,14 @@ void sqliteStrRealloc(char **pz){
char *sqliteStrDup_(const char *z, char *zFile, int line){
char *zNew;
if( z==0 ) return 0;
zNew = sqliteMalloc_(strlen(z)+1, zFile, line);
zNew = sqliteMalloc_(strlen(z)+1, 0, zFile, line);
if( zNew ) strcpy(zNew, z);
return zNew;
}
char *sqliteStrNDup_(const char *z, int n, char *zFile, int line){
char *zNew;
if( z==0 ) return 0;
zNew = sqliteMalloc_(n+1, zFile, line);
zNew = sqliteMalloc_(n+1, 0, zFile, line);
if( zNew ){
memcpy(zNew, z, n);
zNew[n] = 0;
@@ -214,15 +247,27 @@ char *sqliteStrNDup_(const char *z, int n, char *zFile, int line){
/*
** Allocate new memory and set it to zero. Return NULL if
** no memory is available.
** no memory is available. See also sqliteMallocRaw().
*/
void *sqliteMalloc(int n){
void *p = malloc(n);
if( p==0 ){
sqlite_malloc_failed++;
return 0;
void *p;
if( (p = malloc(n))==0 ){
if( n>0 ) sqlite_malloc_failed++;
}else{
memset(p, 0, n);
}
return p;
}
/*
** Allocate new memory but do not set it to zero. Return NULL if
** no memory is available. See also sqliteMalloc().
*/
void *sqliteMallocRaw(int n){
void *p;
if( (p = malloc(n))==0 ){
if( n>0 ) sqlite_malloc_failed++;
}
memset(p, 0, n);
return p;
}
@@ -262,14 +307,14 @@ void *sqliteRealloc(void *p, int n){
char *sqliteStrDup(const char *z){
char *zNew;
if( z==0 ) return 0;
zNew = sqliteMalloc(strlen(z)+1);
zNew = sqliteMallocRaw(strlen(z)+1);
if( zNew ) strcpy(zNew, z);
return zNew;
}
char *sqliteStrNDup(const char *z, int n){
char *zNew;
if( z==0 ) return 0;
zNew = sqliteMalloc(n+1);
zNew = sqliteMallocRaw(n+1);
if( zNew ){
memcpy(zNew, z, n);
zNew[n] = 0;
@@ -282,7 +327,8 @@ char *sqliteStrNDup(const char *z, int n){
** Create a string from the 2nd and subsequent arguments (up to the
** first NULL argument), store the string in memory obtained from
** sqliteMalloc() and make the pointer indicated by the 1st argument
** point to that string.
** point to that string. The 1st argument must either be NULL or
** point to memory obtained from sqliteMalloc().
*/
void sqliteSetString(char **pz, const char *zFirst, ...){
va_list ap;
@@ -298,7 +344,7 @@ void sqliteSetString(char **pz, const char *zFirst, ...){
}
va_end(ap);
sqliteFree(*pz);
*pz = zResult = sqliteMalloc( nByte );
*pz = zResult = sqliteMallocRaw( nByte );
if( zResult==0 ){
return;
}
@@ -320,7 +366,9 @@ void sqliteSetString(char **pz, const char *zFirst, ...){
/*
** Works like sqliteSetString, but each string is now followed by
** a length integer which specifies how much of the source string
** to copy (in bytes). -1 means use the whole string.
** to copy (in bytes). -1 means use the whole string. The 1st
** argument must either be NULL or point to memory obtained from
** sqliteMalloc().
*/
void sqliteSetNString(char **pz, ...){
va_list ap;
@@ -339,7 +387,7 @@ void sqliteSetNString(char **pz, ...){
}
va_end(ap);
sqliteFree(*pz);
*pz = zResult = sqliteMalloc( nByte + 1 );
*pz = zResult = sqliteMallocRaw( nByte + 1 );
if( zResult==0 ) return;
va_start(ap, pz);
while( (z = va_arg(ap, const char*))!=0 ){
@@ -357,6 +405,25 @@ void sqliteSetNString(char **pz, ...){
va_end(ap);
}
/*
** Add an error message to pParse->zErrMsg and increment pParse->nErr.
** The following formatting characters are allowed:
**
** %s Insert a string
** %z A string that should be freed after use
** %d Insert an integer
** %T Insert a token
** %S Insert the first element of a SrcList
*/
void sqliteErrorMsg(Parse *pParse, const char *zFormat, ...){
va_list ap;
pParse->nErr++;
sqliteFree(pParse->zErrMsg);
va_start(ap, zFormat);
pParse->zErrMsg = sqliteVMPrintf(zFormat, ap);
va_end(ap);
}
/*
** Convert an SQL-style quoted string into a normal string by removing
** the quote characters. The conversion is done in-place. If the
@@ -425,8 +492,7 @@ int sqliteHashNoCase(const char *z, int n){
h = (h<<3) ^ h ^ UpperToLower[(unsigned char)*z++];
n--;
}
if( h<0 ) h = -h;
return h;
return h & 0x7fffffff;
}
/*
@@ -448,198 +514,16 @@ int sqliteStrNICmp(const char *zLeft, const char *zRight, int N){
return N<0 ? 0 : *a - *b;
}
#if 0 /* NOT USED */
/*
** The sortStrCmp() function below is used to order elements according
** to the ORDER BY clause of a SELECT. The sort order is a little different
** from what one might expect. This note attempts to describe what is
** going on.
**
** We want the main string comparision function used for sorting to
** sort both numbers and alphanumeric words into the correct sequence.
** The same routine should do both without prior knowledge of which
** type of text the input represents. It should even work for strings
** which are a mixture of text and numbers. (It does not work for
** numeric substrings in exponential notation, however.)
**
** To accomplish this, we keep track of a state number while scanning
** the two strings. The states are as follows:
**
** 1 Beginning of word
** 2 Arbitrary text
** 3 Integer
** 4 Negative integer
** 5 Real number
** 6 Negative real
**
** The scan begins in state 1, beginning of word. Transitions to other
** states are determined by characters seen, as shown in the following
** chart:
**
** Current State Character Seen New State
** -------------------- -------------- -------------------
** 0 Beginning of word "-" 3 Negative integer
** digit 2 Integer
** space 0 Beginning of word
** otherwise 1 Arbitrary text
**
** 1 Arbitrary text space 0 Beginning of word
** digit 2 Integer
** otherwise 1 Arbitrary text
**
** 2 Integer space 0 Beginning of word
** "." 4 Real number
** digit 2 Integer
** otherwise 1 Arbitrary text
**
** 3 Negative integer space 0 Beginning of word
** "." 5 Negative Real num
** digit 3 Negative integer
** otherwise 1 Arbitrary text
**
** 4 Real number space 0 Beginning of word
** digit 4 Real number
** otherwise 1 Arbitrary text
**
** 5 Negative real num space 0 Beginning of word
** digit 5 Negative real num
** otherwise 1 Arbitrary text
**
** To implement this state machine, we first classify each character
** into on of the following categories:
**
** 0 Text
** 1 Space
** 2 Digit
** 3 "-"
** 4 "."
**
** Given an arbitrary character, the array charClass[] maps that character
** into one of the atove categories.
*/
static const unsigned char charClass[] = {
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
/* 0x */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0,
/* 1x */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 2x */ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 0,
/* 3x */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0,
/* 4x */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 5x */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 6x */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 7x */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 8x */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 9x */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* Ax */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* Bx */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* Cx */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* Dx */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* Ex */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* Fx */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
#define N_CHAR_CLASS 5
/*
** Given the current state number (0 thru 5), this array figures
** the new state number given the character class.
*/
static const unsigned char stateMachine[] = {
/* Text, Space, Digit, "-", "." */
1, 0, 2, 3, 1, /* State 0: Beginning of word */
1, 0, 2, 1, 1, /* State 1: Arbitrary text */
1, 0, 2, 1, 4, /* State 2: Integer */
1, 0, 3, 1, 5, /* State 3: Negative integer */
1, 0, 4, 1, 1, /* State 4: Real number */
1, 0, 5, 1, 1, /* State 5: Negative real num */
};
/* This routine does a comparison of two strings. Case is used only
** if useCase!=0. Numeric substrings compare in numerical order for the
** most part but this routine does not understand exponential notation.
*/
static int sortStrCmp(const char *atext, const char *btext, int useCase){
register unsigned char *a, *b, *map, ca, cb;
int result;
register int cclass = 0;
a = (unsigned char *)atext;
b = (unsigned char *)btext;
if( useCase ){
do{
if( (ca= *a++)!=(cb= *b++) ) break;
cclass = stateMachine[cclass*N_CHAR_CLASS + charClass[ca]];
}while( ca!=0 );
}else{
map = UpperToLower;
do{
if( (ca=map[*a++])!=(cb=map[*b++]) ) break;
cclass = stateMachine[cclass*N_CHAR_CLASS + charClass[ca]];
}while( ca!=0 );
if( ca>='[' && ca<='`' ) cb = b[-1];
if( cb>='[' && cb<='`' ) ca = a[-1];
}
switch( cclass ){
case 0:
case 1: {
if( isdigit(ca) && isdigit(cb) ){
cclass = 2;
}
break;
}
default: {
break;
}
}
switch( cclass ){
case 2:
case 3: {
if( isdigit(ca) ){
if( isdigit(cb) ){
int acnt, bcnt;
acnt = bcnt = 0;
while( isdigit(*a++) ) acnt++;
while( isdigit(*b++) ) bcnt++;
result = acnt - bcnt;
if( result==0 ) result = ca-cb;
}else{
result = 1;
}
}else if( isdigit(cb) ){
result = -1;
}else if( ca=='.' ){
result = 1;
}else if( cb=='.' ){
result = -1;
}else{
result = ca - cb;
cclass = 2;
}
if( cclass==3 ) result = -result;
break;
}
case 0:
case 1:
case 4: {
result = ca - cb;
break;
}
case 5: {
result = cb - ca;
};
}
return result;
}
#endif /* NOT USED */
/*
** Return TRUE if z is a pure numeric string. Return FALSE if the
** string contains any character which is not part of a number.
**
** Am empty string is considered numeric.
** Am empty string is considered non-numeric.
*/
static int sqliteIsNumber(const char *z){
int sqliteIsNumber(const char *z){
if( *z=='-' || *z=='+' ) z++;
if( !isdigit(*z) ){
return *z==0;
return 0;
}
z++;
while( isdigit(*z) ){ z++; }
@@ -647,16 +531,98 @@ static int sqliteIsNumber(const char *z){
z++;
if( !isdigit(*z) ) return 0;
while( isdigit(*z) ){ z++; }
if( *z=='e' || *z=='E' ){
z++;
if( *z=='+' || *z=='-' ) z++;
if( !isdigit(*z) ) return 0;
while( isdigit(*z) ){ z++; }
}
}
if( *z=='e' || *z=='E' ){
z++;
if( *z=='+' || *z=='-' ) z++;
if( !isdigit(*z) ) return 0;
while( isdigit(*z) ){ z++; }
}
return *z==0;
}
/*
** The string z[] is an ascii representation of a real number.
** Convert this string to a double.
**
** This routine assumes that z[] really is a valid number. If it
** is not, the result is undefined.
**
** This routine is used instead of the library atof() function because
** the library atof() might want to use "," as the decimal point instead
** of "." depending on how locale is set. But that would cause problems
** for SQL. So this routine always uses "." regardless of locale.
*/
double sqliteAtoF(const char *z, const char **pzEnd){
int sign = 1;
LONGDOUBLE_TYPE v1 = 0.0;
if( *z=='-' ){
sign = -1;
z++;
}else if( *z=='+' ){
z++;
}
while( isdigit(*z) ){
v1 = v1*10.0 + (*z - '0');
z++;
}
if( *z=='.' ){
LONGDOUBLE_TYPE divisor = 1.0;
z++;
while( isdigit(*z) ){
v1 = v1*10.0 + (*z - '0');
divisor *= 10.0;
z++;
}
v1 /= divisor;
}
if( *z=='e' || *z=='E' ){
int esign = 1;
int eval = 0;
LONGDOUBLE_TYPE scale = 1.0;
z++;
if( *z=='-' ){
esign = -1;
z++;
}else if( *z=='+' ){
z++;
}
while( isdigit(*z) ){
eval = eval*10 + *z - '0';
z++;
}
while( eval>=64 ){ scale *= 1.0e+64; eval -= 64; }
while( eval>=16 ){ scale *= 1.0e+16; eval -= 16; }
while( eval>=4 ){ scale *= 1.0e+4; eval -= 4; }
while( eval>=1 ){ scale *= 1.0e+1; eval -= 1; }
if( esign<0 ){
v1 /= scale;
}else{
v1 *= scale;
}
}
if( pzEnd ) *pzEnd = z;
return sign<0 ? -v1 : v1;
}
/*
** The string zNum represents an integer. There might be some other
** information following the integer too, but that part is ignored.
** If the integer that the prefix of zNum represents will fit in a
** 32-bit signed integer, return TRUE. Otherwise return FALSE.
**
** This routine returns FALSE for the string -2147483648 even that
** that number will, in theory fit in a 32-bit integer. But positive
** 2147483648 will not fit in 32 bits. So it seems safer to return
** false.
*/
int sqliteFitsIn32Bits(const char *zNum){
int i, c;
if( *zNum=='-' || *zNum=='+' ) zNum++;
for(i=0; (c=zNum[i])>='0' && c<='9'; i++){}
return i<10 || (i==10 && memcmp(zNum,"2147483647",10)<=0);
}
/* This comparison routine is what we use for comparison operations
** between numeric values in an SQL expression. "Numeric" is a little
** bit misleading here. What we mean is that the strings have a
@@ -685,8 +651,8 @@ int sqliteCompare(const char *atext, const char *btext){
result = -1;
}else{
double rA, rB;
rA = atof(atext);
rB = atof(btext);
rA = sqliteAtoF(atext, 0);
rB = sqliteAtoF(btext, 0);
if( rA<rB ){
result = -1;
}else if( rA>rB ){
@@ -745,10 +711,9 @@ int sqliteCompare(const char *atext, const char *btext){
** 2.6.3 and earlier.
*/
int sqliteSortCompare(const char *a, const char *b){
int len;
int res = 0;
int isNumA, isNumB;
int dir;
int dir = 0;
while( res==0 && *a && *b ){
if( a[0]=='N' || b[0]=='N' ){
@@ -779,8 +744,8 @@ int sqliteSortCompare(const char *a, const char *b){
res = -1;
break;
}
rA = atof(&a[1]);
rB = atof(&b[1]);
rA = sqliteAtoF(&a[1], 0);
rB = sqliteAtoF(&b[1], 0);
if( rA<rB ){
res = -1;
break;
@@ -797,9 +762,8 @@ int sqliteSortCompare(const char *a, const char *b){
if( res ) break;
}
}
len = strlen(&a[1]) + 2;
a += len;
b += len;
a += strlen(&a[1]) + 2;
b += strlen(&b[1]) + 2;
}
if( dir=='-' || dir=='D' ) res = -res;
return res;
@@ -993,7 +957,6 @@ sqliteGlobCompare(const unsigned char *zPattern, const unsigned char *zString){
zPattern++;
}
if( c==0 ) return 1;
c = UpperToLower[c];
if( c=='[' ){
while( *zString && sqliteGlobCompare(&zPattern[1],zString)==0 ){
sqliteNextChar(zString);
@@ -1118,16 +1081,23 @@ sqliteLikeCompare(const unsigned char *zPattern, const unsigned char *zString){
** But usually the problem will be seen. The result will be an
** error which can be used to debug the application that is
** using SQLite incorrectly.
**
** Ticket #202: If db->magic is not a valid open value, take care not
** to modify the db structure at all. It could be that db is a stale
** pointer. In other words, it could be that there has been a prior
** call to sqlite_close(db) and db has been deallocated. And we do
** not want to write into deallocated memory.
*/
int sqliteSafetyOn(sqlite *db){
if( db->magic==SQLITE_MAGIC_OPEN ){
db->magic = SQLITE_MAGIC_BUSY;
return 0;
}else{
}else if( db->magic==SQLITE_MAGIC_BUSY || db->magic==SQLITE_MAGIC_ERROR
|| db->want_to_close ){
db->magic = SQLITE_MAGIC_ERROR;
db->flags |= SQLITE_Interrupt;
return 1;
}
return 1;
}
/*
@@ -1139,11 +1109,12 @@ int sqliteSafetyOff(sqlite *db){
if( db->magic==SQLITE_MAGIC_BUSY ){
db->magic = SQLITE_MAGIC_OPEN;
return 0;
}else{
}else if( db->magic==SQLITE_MAGIC_OPEN || db->magic==SQLITE_MAGIC_ERROR
|| db->want_to_close ){
db->magic = SQLITE_MAGIC_ERROR;
db->flags |= SQLITE_Interrupt;
return 1;
}
return 1;
}
/*
@@ -1156,7 +1127,7 @@ int sqliteSafetyOff(sqlite *db){
** at the wrong time or in the wrong sequence.
*/
int sqliteSafetyCheck(sqlite *db){
if( db->recursionDepth ){
if( db->pVdbe!=0 ){
db->magic = SQLITE_MAGIC_ERROR;
return 1;
}
+327
View File
@@ -0,0 +1,327 @@
/*
** 2003 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the VACUUM command.
**
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
**
** $Id: vacuum.c,v 1.13.2.2 2004/06/04 19:07:54 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
/*
** A structure for holding a dynamic string - a string that can grow
** without bound.
*/
typedef struct dynStr dynStr;
struct dynStr {
char *z; /* Text of the string in space obtained from sqliteMalloc() */
int nAlloc; /* Amount of space allocated to z[] */
int nUsed; /* Next unused slot in z[] */
};
/*
** A structure that holds the vacuum context
*/
typedef struct vacuumStruct vacuumStruct;
struct vacuumStruct {
sqlite *dbOld; /* Original database */
sqlite *dbNew; /* New database */
char **pzErrMsg; /* Write errors here */
int rc; /* Set to non-zero on an error */
const char *zTable; /* Name of a table being copied */
const char *zPragma; /* Pragma to execute with results */
dynStr s1, s2; /* Two dynamic strings */
};
#if !defined(SQLITE_OMIT_VACUUM) || SQLITE_OMIT_VACUUM
/*
** Append text to a dynamic string
*/
static void appendText(dynStr *p, const char *zText, int nText){
if( nText<0 ) nText = strlen(zText);
if( p->z==0 || p->nUsed + nText + 1 >= p->nAlloc ){
char *zNew;
p->nAlloc = p->nUsed + nText + 1000;
zNew = sqliteRealloc(p->z, p->nAlloc);
if( zNew==0 ){
sqliteFree(p->z);
memset(p, 0, sizeof(*p));
return;
}
p->z = zNew;
}
memcpy(&p->z[p->nUsed], zText, nText+1);
p->nUsed += nText;
}
/*
** Append text to a dynamic string, having first put the text in quotes.
*/
static void appendQuoted(dynStr *p, const char *zText){
int i, j;
appendText(p, "'", 1);
for(i=j=0; zText[i]; i++){
if( zText[i]=='\'' ){
appendText(p, &zText[j], i-j+1);
j = i + 1;
appendText(p, "'", 1);
}
}
if( j<i ){
appendText(p, &zText[j], i-j);
}
appendText(p, "'", 1);
}
/*
** Execute statements of SQL. If an error occurs, write the error
** message into *pzErrMsg and return non-zero.
*/
static int execsql(char **pzErrMsg, sqlite *db, const char *zSql){
char *zErrMsg = 0;
int rc;
/* printf("***** executing *****\n%s\n", zSql); */
rc = sqlite_exec(db, zSql, 0, 0, &zErrMsg);
if( zErrMsg ){
sqliteSetString(pzErrMsg, zErrMsg, (char*)0);
sqlite_freemem(zErrMsg);
}
return rc;
}
/*
** This is the second stage callback. Each invocation contains all the
** data for a single row of a single table in the original database. This
** routine must write that information into the new database.
*/
static int vacuumCallback2(void *pArg, int argc, char **argv, char **NotUsed){
vacuumStruct *p = (vacuumStruct*)pArg;
const char *zSep = "(";
int i;
if( argv==0 ) return 0;
p->s2.nUsed = 0;
appendText(&p->s2, "INSERT INTO ", -1);
appendQuoted(&p->s2, p->zTable);
appendText(&p->s2, " VALUES", -1);
for(i=0; i<argc; i++){
appendText(&p->s2, zSep, 1);
zSep = ",";
if( argv[i]==0 ){
appendText(&p->s2, "NULL", 4);
}else{
appendQuoted(&p->s2, argv[i]);
}
}
appendText(&p->s2,")", 1);
p->rc = execsql(p->pzErrMsg, p->dbNew, p->s2.z);
return p->rc;
}
/*
** This is the first stage callback. Each invocation contains three
** arguments where are taken from the SQLITE_MASTER table of the original
** database: (1) the entry type, (2) the entry name, and (3) the SQL for
** the entry. In all cases, execute the SQL of the third argument.
** For tables, run a query to select all entries in that table and
** transfer them to the second-stage callback.
*/
static int vacuumCallback1(void *pArg, int argc, char **argv, char **NotUsed){
vacuumStruct *p = (vacuumStruct*)pArg;
int rc = 0;
assert( argc==3 );
if( argv==0 ) return 0;
assert( argv[0]!=0 );
assert( argv[1]!=0 );
assert( argv[2]!=0 );
rc = execsql(p->pzErrMsg, p->dbNew, argv[2]);
if( rc==SQLITE_OK && strcmp(argv[0],"table")==0 ){
char *zErrMsg = 0;
p->s1.nUsed = 0;
appendText(&p->s1, "SELECT * FROM ", -1);
appendQuoted(&p->s1, argv[1]);
p->zTable = argv[1];
rc = sqlite_exec(p->dbOld, p->s1.z, vacuumCallback2, p, &zErrMsg);
if( zErrMsg ){
sqliteSetString(p->pzErrMsg, zErrMsg, (char*)0);
sqlite_freemem(zErrMsg);
}
}
if( rc!=SQLITE_ABORT ) p->rc = rc;
return rc;
}
/*
** This callback is used to transfer PRAGMA settings from one database
** to the other. The value in argv[0] should be passed to a pragma
** identified by ((vacuumStruct*)pArg)->zPragma.
*/
static int vacuumCallback3(void *pArg, int argc, char **argv, char **NotUsed){
vacuumStruct *p = (vacuumStruct*)pArg;
char zBuf[200];
assert( argc==1 );
if( argv==0 ) return 0;
assert( argv[0]!=0 );
assert( strlen(p->zPragma)<100 );
assert( strlen(argv[0])<30 );
sprintf(zBuf,"PRAGMA %s=%s;", p->zPragma, argv[0]);
p->rc = execsql(p->pzErrMsg, p->dbNew, zBuf);
return p->rc;
}
/*
** Generate a random name of 20 character in length.
*/
static void randomName(unsigned char *zBuf){
static const unsigned char zChars[] =
"abcdefghijklmnopqrstuvwxyz"
"0123456789";
int i;
sqliteRandomness(20, zBuf);
for(i=0; i<20; i++){
zBuf[i] = zChars[ zBuf[i]%(sizeof(zChars)-1) ];
}
}
#endif
/*
** The non-standard VACUUM command is used to clean up the database,
** collapse free space, etc. It is modelled after the VACUUM command
** in PostgreSQL.
**
** In version 1.0.x of SQLite, the VACUUM command would call
** gdbm_reorganize() on all the database tables. But beginning
** with 2.0.0, SQLite no longer uses GDBM so this command has
** become a no-op.
*/
void sqliteVacuum(Parse *pParse, Token *pTableName){
Vdbe *v = sqliteGetVdbe(pParse);
sqliteVdbeAddOp(v, OP_Vacuum, 0, 0);
return;
}
/*
** This routine implements the OP_Vacuum opcode of the VDBE.
*/
int sqliteRunVacuum(char **pzErrMsg, sqlite *db){
#if !defined(SQLITE_OMIT_VACUUM) || SQLITE_OMIT_VACUUM
const char *zFilename; /* full pathname of the database file */
int nFilename; /* number of characters in zFilename[] */
char *zTemp = 0; /* a temporary file in same directory as zFilename */
sqlite *dbNew = 0; /* The new vacuumed database */
int rc = SQLITE_OK; /* Return code from service routines */
int i; /* Loop counter */
char *zErrMsg; /* Error message */
vacuumStruct sVac; /* Information passed to callbacks */
/* These are all of the pragmas that need to be transferred over
** to the new database */
static const char *zPragma[] = {
"default_synchronous",
"default_cache_size",
/* "default_temp_store", */
};
if( db->flags & SQLITE_InTrans ){
sqliteSetString(pzErrMsg, "cannot VACUUM from within a transaction",
(char*)0);
return SQLITE_ERROR;
}
if( db->flags & SQLITE_Interrupt ){
return SQLITE_INTERRUPT;
}
memset(&sVac, 0, sizeof(sVac));
/* Get the full pathname of the database file and create two
** temporary filenames in the same directory as the original file.
*/
zFilename = sqliteBtreeGetFilename(db->aDb[0].pBt);
if( zFilename==0 ){
/* This only happens with the in-memory database. VACUUM is a no-op
** there, so just return */
return SQLITE_OK;
}
nFilename = strlen(zFilename);
zTemp = sqliteMalloc( nFilename+100 );
if( zTemp==0 ) return SQLITE_NOMEM;
strcpy(zTemp, zFilename);
for(i=0; i<10; i++){
zTemp[nFilename] = '-';
randomName((unsigned char*)&zTemp[nFilename+1]);
if( !sqliteOsFileExists(zTemp) ) break;
}
if( i>=10 ){
sqliteSetString(pzErrMsg, "unable to create a temporary database file "
"in the same directory as the original database", (char*)0);
goto end_of_vacuum;
}
dbNew = sqlite_open(zTemp, 0, &zErrMsg);
if( dbNew==0 ){
sqliteSetString(pzErrMsg, "unable to open a temporary database at ",
zTemp, " - ", zErrMsg, (char*)0);
goto end_of_vacuum;
}
if( (rc = execsql(pzErrMsg, db, "BEGIN"))!=0 ) goto end_of_vacuum;
if( (rc = execsql(pzErrMsg, dbNew, "PRAGMA synchronous=off; BEGIN"))!=0 ){
goto end_of_vacuum;
}
sVac.dbOld = db;
sVac.dbNew = dbNew;
sVac.pzErrMsg = pzErrMsg;
for(i=0; rc==SQLITE_OK && i<sizeof(zPragma)/sizeof(zPragma[0]); i++){
char zBuf[200];
assert( strlen(zPragma[i])<100 );
sprintf(zBuf, "PRAGMA %s;", zPragma[i]);
sVac.zPragma = zPragma[i];
rc = sqlite_exec(db, zBuf, vacuumCallback3, &sVac, &zErrMsg);
}
if( rc==SQLITE_OK ){
rc = sqlite_exec(db,
"SELECT type, name, sql FROM sqlite_master "
"WHERE sql NOT NULL AND type!='view' "
"UNION ALL "
"SELECT type, name, sql FROM sqlite_master "
"WHERE sql NOT NULL AND type=='view'",
vacuumCallback1, &sVac, &zErrMsg);
}
if( rc==SQLITE_OK ){
rc = sqliteBtreeCopyFile(db->aDb[0].pBt, dbNew->aDb[0].pBt);
sqlite_exec(db, "COMMIT", 0, 0, 0);
sqliteResetInternalSchema(db, 0);
}
end_of_vacuum:
if( rc && zErrMsg!=0 ){
sqliteSetString(pzErrMsg, "unable to vacuum database - ",
zErrMsg, (char*)0);
}
sqlite_exec(db, "ROLLBACK", 0, 0, 0);
if( (dbNew && (dbNew->flags & SQLITE_Interrupt))
|| (db->flags & SQLITE_Interrupt) ){
rc = SQLITE_INTERRUPT;
}
if( dbNew ) sqlite_close(dbNew);
sqliteOsDelete(zTemp);
sqliteFree(zTemp);
sqliteFree(sVac.s1.z);
sqliteFree(sVac.s2.z);
if( zErrMsg ) sqlite_freemem(zErrMsg);
if( rc==SQLITE_ABORT && sVac.rc!=SQLITE_INTERRUPT ) sVac.rc = SQLITE_ERROR;
return sVac.rc;
#endif
}
+1830 -2236
View File
File diff suppressed because it is too large Load Diff
+31 -9
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.60 2002/09/08 00:04:53 drh Exp $
** $Id: vdbe.h,v 1.71 2004/02/22 20:05:02 drh Exp $
*/
#ifndef _SQLITE_VDBE_H_
#define _SQLITE_VDBE_H_
@@ -34,21 +34,37 @@ typedef struct Vdbe Vdbe;
** as an instance of the following structure:
*/
struct VdbeOp {
int opcode; /* What operation to perform */
u8 opcode; /* What operation to perform */
int p1; /* First operand */
int p2; /* Second parameter (often the jump destination) */
char *p3; /* Third parameter */
int p3type; /* P3_STATIC, P3_DYNAMIC or P3_POINTER */
#ifdef VDBE_PROFILE
int cnt; /* Number of times this instruction was executed */
long long cycles; /* Total time spend executing this instruction */
#endif
};
typedef struct VdbeOp VdbeOp;
/*
** A smaller version of VdbeOp used for the VdbeAddOpList() function because
** it takes up less space.
*/
struct VdbeOpList {
u8 opcode; /* What operation to perform */
signed char p1; /* First operand */
short int p2; /* Second parameter (often the jump destination) */
char *p3; /* Third parameter */
};
typedef struct VdbeOpList VdbeOpList;
/*
** Allowed values of VdbeOp.p3type
*/
#define P3_NOTUSED 0 /* The P3 parameter is not used */
#define P3_DYNAMIC 1 /* Pointer to a string obtained from sqliteMalloc() */
#define P3_STATIC (-1) /* Pointer to a static string */
#define P3_POINTER (-2) /* P3 is a pointer to some structure or object */
#define P3_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
#define P3_STATIC (-2) /* Pointer to a static string */
#define P3_POINTER (-3) /* P3 is a pointer to some structure or object */
/*
** The following macro converts a relative address in the p2 field
@@ -71,20 +87,26 @@ typedef struct VdbeOp VdbeOp;
Vdbe *sqliteVdbeCreate(sqlite*);
void sqliteVdbeCreateCallback(Vdbe*, int*);
int sqliteVdbeAddOp(Vdbe*,int,int,int);
int sqliteVdbeAddOpList(Vdbe*, int nOp, VdbeOp const *aOp);
int sqliteVdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
int sqliteVdbeCode(Vdbe*,...);
int sqliteVdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
void sqliteVdbeChangeP1(Vdbe*, int addr, int P1);
void sqliteVdbeChangeP2(Vdbe*, int addr, int P2);
void sqliteVdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
void sqliteVdbeDequoteP3(Vdbe*, int addr);
int sqliteVdbeFindOp(Vdbe*, int, int);
VdbeOp *sqliteVdbeGetOp(Vdbe*, int);
int sqliteVdbeMakeLabel(Vdbe*);
void sqliteVdbeDelete(Vdbe*);
int sqliteVdbeExec(Vdbe*,sqlite_callback,void*,char**,void*,
int(*)(void*,const char*,int));
int sqliteVdbeList(Vdbe*,sqlite_callback,void*,char**);
void sqliteVdbeMakeReady(Vdbe*,int,int);
int sqliteVdbeExec(Vdbe*);
int sqliteVdbeList(Vdbe*);
int sqliteVdbeFinalize(Vdbe*,char**);
void sqliteVdbeResolveLabel(Vdbe*, int);
int sqliteVdbeCurrentAddr(Vdbe*);
void sqliteVdbeTrace(Vdbe*,FILE*);
void sqliteVdbeCompressSpace(Vdbe*,int);
int sqliteVdbeReset(Vdbe*,char **);
int sqliteVdbeSetVariables(Vdbe*,int,const char**);
#endif
+303
View File
@@ -0,0 +1,303 @@
/*
** 2003 September 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This is the header file for information that is private to the
** VDBE. This information used to all be at the top of the single
** source code file "vdbe.c". When that file became too big (over
** 6000 lines long) it was split up into several smaller files and
** this header information was factored out.
*/
/*
** When converting from the native format to the key format and back
** again, in addition to changing the byte order we invert the high-order
** bit of the most significant byte. This causes negative numbers to
** sort before positive numbers in the memcmp() function.
*/
#define keyToInt(X) (sqliteVdbeByteSwap(X) ^ 0x80000000)
#define intToKey(X) (sqliteVdbeByteSwap((X) ^ 0x80000000))
/*
** The makefile scans this source file and creates the following
** array of string constants which are the names of all VDBE opcodes.
** This array is defined in a separate source code file named opcode.c
** which is automatically generated by the makefile.
*/
extern char *sqliteOpcodeNames[];
/*
** SQL is translated into a sequence of instructions to be
** executed by a virtual machine. Each instruction is an instance
** of the following structure.
*/
typedef struct VdbeOp Op;
/*
** Boolean values
*/
typedef unsigned char Bool;
/*
** A cursor is a pointer into a single BTree within a database file.
** The cursor can seek to a BTree entry with a particular key, or
** loop over all entries of the Btree. You can also insert new BTree
** entries or retrieve the key or data from the entry that the cursor
** is currently pointing to.
**
** Every cursor that the virtual machine has open is represented by an
** instance of the following structure.
**
** If the Cursor.isTriggerRow flag is set it means that this cursor is
** really a single row that represents the NEW or OLD pseudo-table of
** a row trigger. The data for the row is stored in Cursor.pData and
** the rowid is in Cursor.iKey.
*/
struct Cursor {
BtCursor *pCursor; /* The cursor structure of the backend */
int lastRecno; /* Last recno from a Next or NextIdx operation */
int nextRowid; /* Next rowid returned by OP_NewRowid */
Bool recnoIsValid; /* True if lastRecno is valid */
Bool keyAsData; /* The OP_Column command works on key instead of data */
Bool atFirst; /* True if pointing to first entry */
Bool useRandomRowid; /* Generate new record numbers semi-randomly */
Bool nullRow; /* True if pointing to a row with no data */
Bool nextRowidValid; /* True if the nextRowid field is valid */
Bool pseudoTable; /* This is a NEW or OLD pseudo-tables of a trigger */
Bool deferredMoveto; /* A call to sqliteBtreeMoveto() is needed */
int movetoTarget; /* Argument to the deferred sqliteBtreeMoveto() */
Btree *pBt; /* Separate file holding temporary table */
int nData; /* Number of bytes in pData */
char *pData; /* Data for a NEW or OLD pseudo-table */
int iKey; /* Key for the NEW or OLD pseudo-table row */
};
typedef struct Cursor Cursor;
/*
** A sorter builds a list of elements to be sorted. Each element of
** the list is an instance of the following structure.
*/
typedef struct Sorter Sorter;
struct Sorter {
int nKey; /* Number of bytes in the key */
char *zKey; /* The key by which we will sort */
int nData; /* Number of bytes in the data */
char *pData; /* The data associated with this key */
Sorter *pNext; /* Next in the list */
};
/*
** Number of buckets used for merge-sort.
*/
#define NSORT 30
/*
** Number of bytes of string storage space available to each stack
** layer without having to malloc. NBFS is short for Number of Bytes
** For Strings.
*/
#define NBFS 32
/*
** A single level of the stack or a single memory cell
** is an instance of the following structure.
*/
struct Mem {
int i; /* Integer value */
int n; /* Number of characters in string value, including '\0' */
int flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
double r; /* Real value */
char *z; /* String value */
char zShort[NBFS]; /* Space for short strings */
};
typedef struct Mem Mem;
/*
** Allowed values for Mem.flags
*/
#define MEM_Null 0x0001 /* Value is NULL */
#define MEM_Str 0x0002 /* Value is a string */
#define MEM_Int 0x0004 /* Value is an integer */
#define MEM_Real 0x0008 /* Value is a real number */
#define MEM_Dyn 0x0010 /* Need to call sqliteFree() on Mem.z */
#define MEM_Static 0x0020 /* Mem.z points to a static string */
#define MEM_Ephem 0x0040 /* Mem.z points to an ephemeral string */
#define MEM_Short 0x0080 /* Mem.z points to Mem.zShort */
/* The following MEM_ value appears only in AggElem.aMem.s.flag fields.
** It indicates that the corresponding AggElem.aMem.z points to a
** aggregate function context that needs to be finalized.
*/
#define MEM_AggCtx 0x0100 /* Mem.z points to an agg function context */
/*
** The "context" argument for a installable function. A pointer to an
** instance of this structure is the first argument to the routines used
** implement the SQL functions.
**
** There is a typedef for this structure in sqlite.h. So all routines,
** even the public interface to SQLite, can use a pointer to this structure.
** But this file is the only place where the internal details of this
** structure are known.
**
** This structure is defined inside of vdbe.c because it uses substructures
** (Mem) which are only defined there.
*/
struct sqlite_func {
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
Mem s; /* The return value is stored here */
void *pAgg; /* Aggregate context */
u8 isError; /* Set to true for an error */
u8 isStep; /* Current in the step function */
int cnt; /* Number of times that the step function has been called */
};
/*
** An Agg structure describes an Aggregator. Each Agg consists of
** zero or more Aggregator elements (AggElem). Each AggElem contains
** a key and one or more values. The values are used in processing
** aggregate functions in a SELECT. The key is used to implement
** the GROUP BY clause of a select.
*/
typedef struct Agg Agg;
typedef struct AggElem AggElem;
struct Agg {
int nMem; /* Number of values stored in each AggElem */
AggElem *pCurrent; /* The AggElem currently in focus */
HashElem *pSearch; /* The hash element for pCurrent */
Hash hash; /* Hash table of all aggregate elements */
FuncDef **apFunc; /* Information about aggregate functions */
};
struct AggElem {
char *zKey; /* The key to this AggElem */
int nKey; /* Number of bytes in the key, including '\0' at end */
Mem aMem[1]; /* The values for this AggElem */
};
/*
** A Set structure is used for quick testing to see if a value
** is part of a small set. Sets are used to implement code like
** this:
** x.y IN ('hi','hoo','hum')
*/
typedef struct Set Set;
struct Set {
Hash hash; /* A set is just a hash table */
HashElem *prev; /* Previously accessed hash elemen */
};
/*
** A Keylist is a bunch of keys into a table. The keylist can
** grow without bound. The keylist stores the ROWIDs of database
** records that need to be deleted or updated.
*/
typedef struct Keylist Keylist;
struct Keylist {
int nKey; /* Number of slots in aKey[] */
int nUsed; /* Next unwritten slot in aKey[] */
int nRead; /* Next unread slot in aKey[] */
Keylist *pNext; /* Next block of keys */
int aKey[1]; /* One or more keys. Extra space allocated as needed */
};
/*
** A Context stores the last insert rowid, the last statement change count,
** and the current statement change count (i.e. changes since last statement).
** Elements of Context structure type make up the ContextStack, which is
** updated by the ContextPush and ContextPop opcodes (used by triggers)
*/
typedef struct Context Context;
struct Context {
int lastRowid; /* Last insert rowid (from db->lastRowid) */
int lsChange; /* Last statement change count (from db->lsChange) */
int csChange; /* Current statement change count (from db->csChange) */
};
/*
** An instance of the virtual machine. This structure contains the complete
** state of the virtual machine.
**
** The "sqlite_vm" structure pointer that is returned by sqlite_compile()
** is really a pointer to an instance of this structure.
*/
struct Vdbe {
sqlite *db; /* The whole database */
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
FILE *trace; /* Write an execution trace here, if not NULL */
int nOp; /* Number of instructions in the program */
int nOpAlloc; /* Number of slots allocated for aOp[] */
Op *aOp; /* Space to hold the virtual machine's program */
int nLabel; /* Number of labels used */
int nLabelAlloc; /* Number of slots allocated in aLabel[] */
int *aLabel; /* Space to hold the labels */
Mem *aStack; /* The operand stack, except string values */
Mem *pTos; /* Top entry in the operand stack */
char **zArgv; /* Text values used by the callback */
char **azColName; /* Becomes the 4th parameter to callbacks */
int nCursor; /* Number of slots in aCsr[] */
Cursor *aCsr; /* One element of this array for each open cursor */
Sorter *pSort; /* A linked list of objects to be sorted */
FILE *pFile; /* At most one open file handler */
int nField; /* Number of file fields */
char **azField; /* Data for each file field */
int nVar; /* Number of entries in azVariable[] */
char **azVar; /* Values for the OP_Variable opcode */
int *anVar; /* Length of each value in azVariable[] */
u8 *abVar; /* TRUE if azVariable[i] needs to be sqliteFree()ed */
char *zLine; /* A single line from the input file */
int nLineAlloc; /* Number of spaces allocated for zLine */
int magic; /* Magic number for sanity checking */
int nMem; /* Number of memory locations currently allocated */
Mem *aMem; /* The memory locations */
Agg agg; /* Aggregate information */
int nSet; /* Number of sets allocated */
Set *aSet; /* An array of sets */
int nCallback; /* Number of callbacks invoked so far */
Keylist *pList; /* A list of ROWIDs */
int keylistStackDepth; /* The size of the "keylist" stack */
Keylist **keylistStack; /* The stack used by opcodes ListPush & ListPop */
int contextStackDepth; /* The size of the "context" stack */
Context *contextStack; /* Stack used by opcodes ContextPush & ContextPop*/
int pc; /* The program counter */
int rc; /* Value to return */
unsigned uniqueCnt; /* Used by OP_MakeRecord when P2!=0 */
int errorAction; /* Recovery action to do in case of an error */
int undoTransOnError; /* If error, either ROLLBACK or COMMIT */
int inTempTrans; /* True if temp database is transactioned */
int returnStack[100]; /* Return address stack for OP_Gosub & OP_Return */
int returnDepth; /* Next unused element in returnStack[] */
int nResColumn; /* Number of columns in one row of the result set */
char **azResColumn; /* Values for one row of result */
int popStack; /* Pop the stack this much on entry to VdbeExec() */
char *zErrMsg; /* Error message written here */
u8 explain; /* True if EXPLAIN present on SQL command */
};
/*
** The following are allowed values for Vdbe.magic
*/
#define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */
#define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */
#define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */
#define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */
/*
** Function prototypes
*/
void sqliteVdbeCleanupCursor(Cursor*);
void sqliteVdbeSorterReset(Vdbe*);
void sqliteVdbeAggReset(Agg*);
void sqliteVdbeKeylistFree(Keylist*);
void sqliteVdbePopStack(Vdbe*,int);
int sqliteVdbeCursorMoveto(Cursor*);
int sqliteVdbeByteSwap(int);
#if !defined(NDEBUG) || defined(VDBE_PROFILE)
void sqliteVdbePrintOp(FILE*, int, Op*);
#endif
+1061
View File
File diff suppressed because it is too large Load Diff
+250 -158
View File
@@ -10,10 +10,9 @@
**
*************************************************************************
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements. Also found here are subroutines
** to generate VDBE code to evaluate expressions.
** the WHERE clause of SQL statements.
**
** $Id: where.c,v 1.64 2002/08/28 03:01:01 drh Exp $
** $Id: where.c,v 1.89 2004/02/22 20:05:02 drh Exp $
*/
#include "sqliteInt.h"
@@ -35,6 +34,21 @@ struct ExprInfo {
unsigned prereqAll; /* Bitmask of tables referenced by p */
};
/*
** An instance of the following structure keeps track of a mapping
** between VDBE cursor numbers and bitmasks. The VDBE cursor numbers
** are small integers contained in SrcList_item.iCursor and Expr.iTable
** fields. For any given WHERE clause, we want to track which cursors
** are being used, so we assign a single bit in a 32-bit word to track
** that cursor. Then a 32-bit integer is able to show the set of all
** cursors being used.
*/
typedef struct ExprMaskSet ExprMaskSet;
struct ExprMaskSet {
int n; /* Number of assigned cursor values */
int ix[32]; /* Cursor assigned to each bit */
};
/*
** Determine the number of elements in an array.
*/
@@ -60,43 +74,67 @@ static int exprSplit(int nSlot, ExprInfo *aSlot, Expr *pExpr){
aSlot[0].p = pExpr->pLeft;
cnt = 1 + exprSplit(nSlot-1, &aSlot[1], pExpr->pRight);
}else{
cnt = exprSplit(nSlot, aSlot, pExpr->pRight);
cnt += exprSplit(nSlot-cnt, &aSlot[cnt], pExpr->pLeft);
cnt = exprSplit(nSlot, aSlot, pExpr->pLeft);
cnt += exprSplit(nSlot-cnt, &aSlot[cnt], pExpr->pRight);
}
return cnt;
}
/*
** Initialize an expression mask set
*/
#define initMaskSet(P) memset(P, 0, sizeof(*P))
/*
** Return the bitmask for the given cursor. Assign a new bitmask
** if this is the first time the cursor has been seen.
*/
static int getMask(ExprMaskSet *pMaskSet, int iCursor){
int i;
for(i=0; i<pMaskSet->n; i++){
if( pMaskSet->ix[i]==iCursor ) return 1<<i;
}
if( i==pMaskSet->n && i<ARRAYSIZE(pMaskSet->ix) ){
pMaskSet->n++;
pMaskSet->ix[i] = iCursor;
return 1<<i;
}
return 0;
}
/*
** Destroy an expression mask set
*/
#define freeMaskSet(P) /* NO-OP */
/*
** This routine walks (recursively) an expression tree and generates
** a bitmask indicating which tables are used in that expression
** tree. Bit 0 of the mask is set if table base+0 is used. Bit 1
** is set if table base+1 is used. And so forth.
** tree.
**
** In order for this routine to work, the calling function must have
** previously invoked sqliteExprResolveIds() on the expression. See
** the header comment on that routine for additional information.
**
** "base" is the cursor number (the value of the iTable field) that
** corresponds to the first entry in the list of tables that appear
** in the FROM clause of a SELECT. For UPDATE and DELETE statements
** there is just a single table with "base" as the cursor number.
** The sqliteExprResolveIds() routines looks for column names and
** sets their opcodes to TK_COLUMN and their Expr.iTable fields to
** the VDBE cursor number of the table.
*/
static int exprTableUsage(int base, Expr *p){
static int exprTableUsage(ExprMaskSet *pMaskSet, Expr *p){
unsigned int mask = 0;
if( p==0 ) return 0;
if( p->op==TK_COLUMN ){
return 1<< (p->iTable - base);
return getMask(pMaskSet, p->iTable);
}
if( p->pRight ){
mask = exprTableUsage(base, p->pRight);
mask = exprTableUsage(pMaskSet, p->pRight);
}
if( p->pLeft ){
mask |= exprTableUsage(base, p->pLeft);
mask |= exprTableUsage(pMaskSet, p->pLeft);
}
if( p->pList ){
int i;
for(i=0; i<p->pList->nExpr; i++){
mask |= exprTableUsage(base, p->pList->a[i].pExpr);
mask |= exprTableUsage(pMaskSet, p->pList->a[i].pExpr);
}
}
return mask;
@@ -126,25 +164,22 @@ static int allowedOp(int op){
** "p" field filled in. The job of this routine is to analyze the
** subexpression and populate all the other fields of the ExprInfo
** structure.
**
** "base" is the cursor number (the value of the iTable field) that
** corresponds to the first entry in the table list.
*/
static void exprAnalyze(int base, ExprInfo *pInfo){
static void exprAnalyze(ExprMaskSet *pMaskSet, ExprInfo *pInfo){
Expr *pExpr = pInfo->p;
pInfo->prereqLeft = exprTableUsage(base, pExpr->pLeft);
pInfo->prereqRight = exprTableUsage(base, pExpr->pRight);
pInfo->prereqAll = exprTableUsage(base, pExpr);
pInfo->prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft);
pInfo->prereqRight = exprTableUsage(pMaskSet, pExpr->pRight);
pInfo->prereqAll = exprTableUsage(pMaskSet, pExpr);
pInfo->indexable = 0;
pInfo->idxLeft = -1;
pInfo->idxRight = -1;
if( allowedOp(pExpr->op) && (pInfo->prereqRight & pInfo->prereqLeft)==0 ){
if( pExpr->pRight && pExpr->pRight->op==TK_COLUMN ){
pInfo->idxRight = pExpr->pRight->iTable - base;
pInfo->idxRight = pExpr->pRight->iTable;
pInfo->indexable = 1;
}
if( pExpr->pLeft->op==TK_COLUMN ){
pInfo->idxLeft = pExpr->pLeft->iTable - base;
pInfo->idxLeft = pExpr->pLeft->iTable;
pInfo->indexable = 1;
}
}
@@ -162,23 +197,37 @@ static void exprAnalyze(int base, ExprInfo *pInfo){
**
** If there are two or more indices that generate the correct sort order
** and pPreferredIdx is one of those indices, then return pPreferredIdx.
**
** nEqCol is the number of columns of pPreferredIdx that are used as
** equality constraints. Any index returned must have exactly this same
** set of columns. The ORDER BY clause only matches index columns beyond the
** the first nEqCol columns.
**
** All terms of the ORDER BY clause must be either ASC or DESC. The
** *pbRev value is set to 1 if the ORDER BY clause is all DESC and it is
** set to 0 if the ORDER BY clause is all ASC.
*/
static Index *findSortingIndex(
Table *pTab, /* The table to be sorted */
int base, /* Cursor number for pTab */
ExprList *pOrderBy, /* The ORDER BY clause */
Index *pPreferredIdx /* Use this index, if possible and not NULL */
Index *pPreferredIdx, /* Use this index, if possible and not NULL */
int nEqCol, /* Number of index columns used with == constraints */
int *pbRev /* Set to 1 if ORDER BY is DESC */
){
int i;
int i, j;
Index *pMatch;
Index *pIdx;
int sortOrder;
assert( pOrderBy!=0 );
assert( pOrderBy->nExpr>0 );
sortOrder = pOrderBy->a[0].sortOrder & SQLITE_SO_DIRMASK;
for(i=0; i<pOrderBy->nExpr; i++){
Expr *p;
if( (pOrderBy->a[i].sortOrder & SQLITE_SO_DIRMASK)!=SQLITE_SO_ASC ){
/* Indices can only be used for ascending sort order */
if( (pOrderBy->a[i].sortOrder & SQLITE_SO_DIRMASK)!=sortOrder ){
/* Indices can only be used if all ORDER BY terms are either
** DESC or ASC. Indices cannot be used on a mixture. */
return 0;
}
if( (pOrderBy->a[i].sortOrder & SQLITE_SO_TYPEMASK)!=SQLITE_SO_UNK ){
@@ -192,22 +241,31 @@ static Index *findSortingIndex(
return 0;
}
}
/* If we get this far, it means the ORDER BY clause consists only of
** ascending columns in the left-most table of the FROM clause. Now
** check for a matching index.
*/
pMatch = 0;
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
if( pIdx->nColumn<pOrderBy->nExpr ) continue;
for(i=0; i<pOrderBy->nExpr; i++){
if( pOrderBy->a[i].pExpr->iColumn!=pIdx->aiColumn[i] ) break;
int nExpr = pOrderBy->nExpr;
if( pIdx->nColumn < nEqCol || pIdx->nColumn < nExpr ) continue;
for(i=j=0; i<nEqCol; i++){
if( pPreferredIdx->aiColumn[i]!=pIdx->aiColumn[i] ) break;
if( j<nExpr && pOrderBy->a[j].pExpr->iColumn==pIdx->aiColumn[i] ){ j++; }
}
if( i>=pOrderBy->nExpr ){
if( i<nEqCol ) continue;
for(i=0; i+j<nExpr; i++){
if( pOrderBy->a[i+j].pExpr->iColumn!=pIdx->aiColumn[i+nEqCol] ) break;
}
if( i+j>=nExpr ){
pMatch = pIdx;
if( pIdx==pPreferredIdx ) break;
}
}
if( pMatch && pbRev ){
*pbRev = sortOrder==SQLITE_SO_DESC;
}
return pMatch;
}
@@ -238,9 +296,9 @@ static Index *findSortingIndex(
** end /
**
** There are Btree cursors associated with each table. t1 uses cursor
** "base". t2 uses cursor "base+1". And so forth. This routine generates
** the code to open those cursors. sqliteWhereEnd() generates the code
** to close them.
** number pTabList->a[0].iCursor. t2 uses the cursor pTabList->a[1].iCursor.
** And so forth. This routine generates code to open those VDBE cursors
** and sqliteWhereEnd() generates the code to close them.
**
** If the WHERE clause is empty, the foreach loops must each scan their
** entire tables. Thus a three-way join is an O(N^3) operation. But if
@@ -290,7 +348,6 @@ static Index *findSortingIndex(
*/
WhereInfo *sqliteWhereBegin(
Parse *pParse, /* The parser context */
int base, /* VDBE cursor index for left-most table in pTabList */
SrcList *pTabList, /* A list of all tables to be scanned */
Expr *pWhere, /* The WHERE clause */
int pushKey, /* If TRUE, leave the table key on the stack */
@@ -299,11 +356,11 @@ WhereInfo *sqliteWhereBegin(
int i; /* Loop counter */
WhereInfo *pWInfo; /* Will become the return value of this function */
Vdbe *v = pParse->pVdbe; /* The virtual database engine */
int brk, cont; /* Addresses used during code generation */
int *aOrder; /* Order in which pTabList entries are searched */
int brk, cont = 0; /* Addresses used during code generation */
int nExpr; /* Number of subexpressions in the WHERE clause */
int loopMask; /* One bit set for each outer loop */
int haveKey; /* True if KEY is on the stack */
ExprMaskSet maskSet; /* The expression mask set */
int iDirectEq[32]; /* Term of the form ROWID==X for the N-th table */
int iDirectLt[32]; /* Term of the form ROWID<X or ROWID<=X */
int iDirectGt[32]; /* Term of the form ROWID>X or ROWID>=X */
@@ -319,39 +376,32 @@ WhereInfo *sqliteWhereBegin(
** array fills up, the last entry might point to an expression which
** contains additional unfactored AND operators.
*/
initMaskSet(&maskSet);
memset(aExpr, 0, sizeof(aExpr));
nExpr = exprSplit(ARRAYSIZE(aExpr), aExpr, pWhere);
if( nExpr==ARRAYSIZE(aExpr) ){
char zBuf[50];
sprintf(zBuf, "%d", ARRAYSIZE(aExpr)-1);
sqliteSetString(&pParse->zErrMsg, "WHERE clause too complex - no more "
"than ", zBuf, " terms allowed", 0);
pParse->nErr++;
sqliteErrorMsg(pParse, "WHERE clause too complex - no more "
"than %d terms allowed", (int)ARRAYSIZE(aExpr)-1);
return 0;
}
/* Allocate space for aOrder[] */
aOrder = sqliteMalloc( sizeof(int) * pTabList->nSrc );
/* Allocate and initialize the WhereInfo structure that will become the
** return value.
*/
pWInfo = sqliteMalloc( sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel));
if( sqlite_malloc_failed ){
sqliteFree(aOrder);
sqliteFree(pWInfo);
return 0;
}
pWInfo->pParse = pParse;
pWInfo->pTabList = pTabList;
pWInfo->base = base;
pWInfo->peakNTab = pWInfo->savedNTab = pParse->nTab;
pWInfo->iBreak = sqliteVdbeMakeLabel(v);
/* Special case: a WHERE clause that is constant. Evaluate the
** expression and either jump over all of the code or fall thru.
*/
if( pWhere && sqliteExprIsConstant(pWhere) ){
if( pWhere && (pTabList->nSrc==0 || sqliteExprIsConstant(pWhere)) ){
sqliteExprIfFalse(pParse, pWhere, pWInfo->iBreak, 1);
pWhere = 0;
}
@@ -359,7 +409,7 @@ WhereInfo *sqliteWhereBegin(
/* Analyze all of the subexpressions.
*/
for(i=0; i<nExpr; i++){
exprAnalyze(base, &aExpr[i]);
exprAnalyze(&maskSet, &aExpr[i]);
/* If we are executing a trigger body, remove all references to
** new.* and old.* tables from the prerequisite masks.
@@ -367,13 +417,13 @@ WhereInfo *sqliteWhereBegin(
if( pParse->trigStack ){
int x;
if( (x = pParse->trigStack->newIdx) >= 0 ){
int mask = ~(1 << (x - base));
int mask = ~getMask(&maskSet, x);
aExpr[i].prereqRight &= mask;
aExpr[i].prereqLeft &= mask;
aExpr[i].prereqAll &= mask;
}
if( (x = pParse->trigStack->oldIdx) >= 0 ){
int mask = ~(1 << (x - base));
int mask = ~getMask(&maskSet, x);
aExpr[i].prereqRight &= mask;
aExpr[i].prereqLeft &= mask;
aExpr[i].prereqAll &= mask;
@@ -381,19 +431,6 @@ WhereInfo *sqliteWhereBegin(
}
}
/* Figure out a good nesting order for the tables. aOrder[0] will
** be the index in pTabList of the outermost table. aOrder[1] will
** be the first nested loop and so on. aOrder[pTabList->nSrc-1] will
** be the innermost loop.
**
** Someday we will put in a good algorithm here to reorder the loops
** for an effiecient query. But for now, just use whatever order the
** tables appear in in the pTabList.
*/
for(i=0; i<pTabList->nSrc; i++){
aOrder[i] = i;
}
/* Figure out what index to use (if any) for each nested loop.
** Make pWInfo->a[i].pIdx point to the index to use for the i-th nested
** loop where i==0 is the outer loop and i==pTabList->nSrc-1 is the inner
@@ -413,8 +450,9 @@ WhereInfo *sqliteWhereBegin(
loopMask = 0;
for(i=0; i<pTabList->nSrc && i<ARRAYSIZE(iDirectEq); i++){
int j;
int idx = aOrder[i];
Table *pTab = pTabList->a[idx].pTab;
int iCur = pTabList->a[i].iCursor; /* The cursor for this table */
int mask = getMask(&maskSet, iCur); /* Cursor mask for this table */
Table *pTab = pTabList->a[i].pTab;
Index *pIdx;
Index *pBestIdx = 0;
int bestScore = 0;
@@ -424,12 +462,15 @@ WhereInfo *sqliteWhereBegin(
** set iDirectEq[i] to the index of the term. For terms of the
** form ROWID<expr or ROWID<=expr set iDirectLt[i] to the term index.
** For terms like ROWID>expr or ROWID>=expr set iDirectGt[i].
**
** (Added:) Treat ROWID IN expr like ROWID=expr.
*/
pWInfo->a[i].iCur = -1;
iDirectEq[i] = -1;
iDirectLt[i] = -1;
iDirectGt[i] = -1;
for(j=0; j<nExpr; j++){
if( aExpr[j].idxLeft==idx && aExpr[j].p->pLeft->iColumn<0
if( aExpr[j].idxLeft==iCur && aExpr[j].p->pLeft->iColumn<0
&& (aExpr[j].prereqRight & loopMask)==aExpr[j].prereqRight ){
switch( aExpr[j].p->op ){
case TK_IN:
@@ -440,7 +481,7 @@ WhereInfo *sqliteWhereBegin(
case TK_GT: iDirectGt[i] = j; break;
}
}
if( aExpr[j].idxRight==idx && aExpr[j].p->pRight->iColumn<0
if( aExpr[j].idxRight==iCur && aExpr[j].p->pRight->iColumn<0
&& (aExpr[j].prereqLeft & loopMask)==aExpr[j].prereqLeft ){
switch( aExpr[j].p->op ){
case TK_EQ: iDirectEq[i] = j; break;
@@ -452,7 +493,7 @@ WhereInfo *sqliteWhereBegin(
}
}
if( iDirectEq[i]>=0 ){
loopMask |= 1<<idx;
loopMask |= mask;
pWInfo->a[i].pIdx = 0;
continue;
}
@@ -463,17 +504,18 @@ WhereInfo *sqliteWhereBegin(
**
** The best index is determined as follows. For each of the
** left-most terms that is fixed by an equality operator, add
** 4 to the score. The right-most term of the index may be
** 8 to the score. The right-most term of the index may be
** constrained by an inequality. Add 1 if for an "x<..." constraint
** and add 2 for an "x>..." constraint. Chose the index that
** gives the best score.
**
** This scoring system is designed so that the score can later be
** used to determine how the index is used. If the score&3 is 0
** used to determine how the index is used. If the score&7 is 0
** then all constraints are equalities. If score&1 is not 0 then
** there is an inequality used as a termination key. (ex: "x<...")
** If score&2 is not 0 then there is an inequality used as the
** start key. (ex: "x>...");
** start key. (ex: "x>..."). A score or 4 is the special case
** of an IN operator constraint. (ex: "x IN ...").
**
** The IN operator (as in "<expr> IN (...)") is treated the same as
** an equality comparison except that it can only be used on the
@@ -490,7 +532,7 @@ WhereInfo *sqliteWhereBegin(
if( pIdx->nColumn>32 ) continue; /* Ignore indices too many columns */
for(j=0; j<nExpr; j++){
if( aExpr[j].idxLeft==idx
if( aExpr[j].idxLeft==iCur
&& (aExpr[j].prereqRight & loopMask)==aExpr[j].prereqRight ){
int iColumn = aExpr[j].p->pLeft->iColumn;
int k;
@@ -525,7 +567,7 @@ WhereInfo *sqliteWhereBegin(
}
}
}
if( aExpr[j].idxRight==idx
if( aExpr[j].idxRight==iCur
&& (aExpr[j].prereqLeft & loopMask)==aExpr[j].prereqLeft ){
int iColumn = aExpr[j].p->pRight->iColumn;
int k;
@@ -557,15 +599,19 @@ WhereInfo *sqliteWhereBegin(
}
}
}
/* The following loop ends with nEq set to the number of columns
** on the left of the index with == constraints.
*/
for(nEq=0; nEq<pIdx->nColumn; nEq++){
m = (1<<(nEq+1))-1;
if( (m & eqMask)!=m ) break;
}
score = nEq*4;
score = nEq*8; /* Base score is 8 times number of == constraints */
m = 1<<nEq;
if( m & ltMask ) score++;
if( m & gtMask ) score+=2;
if( score==0 && inMask ) score = 4;
if( m & ltMask ) score++; /* Increase score for a < constraint */
if( m & gtMask ) score+=2; /* Increase score for a > constraint */
if( score==0 && inMask ) score = 4; /* Default score for IN constraint */
if( score>bestScore ){
pBestIdx = pIdx;
bestScore = score;
@@ -573,12 +619,11 @@ WhereInfo *sqliteWhereBegin(
}
pWInfo->a[i].pIdx = pBestIdx;
pWInfo->a[i].score = bestScore;
loopMask |= 1<<idx;
pWInfo->a[i].bRev = 0;
loopMask |= mask;
if( pBestIdx ){
pWInfo->a[i].iCur = pParse->nTab++;
pWInfo->peakNTab = pParse->nTab;
}else{
pWInfo->a[i].iCur = -1;
}
}
@@ -589,15 +634,14 @@ WhereInfo *sqliteWhereBegin(
Index *pSortIdx;
Index *pIdx;
Table *pTab;
int bRev = 0;
pTab = pTabList->a[0].pTab;
pIdx = pWInfo->a[0].pIdx;
if( pIdx && pWInfo->a[0].score==4 ){
/* If there is already an index on the left-most column and it is
** an equality index, then either sorting is not helpful, or the
** index is an IN operator, in which case the index does not give
** the correct sort order. Either way, pretend that no suitable
** index is found.
/* If there is already an IN index on the left-most table,
** it will not give the correct sort order.
** So, pretend that no suitable index is found.
*/
pSortIdx = 0;
}else if( iDirectEq[0]>=0 || iDirectLt[0]>=0 || iDirectGt[0]>=0 ){
@@ -606,7 +650,9 @@ WhereInfo *sqliteWhereBegin(
*/
pSortIdx = 0;
}else{
pSortIdx = findSortingIndex(pTab, base, *ppOrderBy, pIdx);
int nEqCol = (pWInfo->a[0].score+4)/8;
pSortIdx = findSortingIndex(pTab, pTabList->a[0].iCursor,
*ppOrderBy, pIdx, nEqCol, &bRev);
}
if( pSortIdx && (pIdx==0 || pIdx==pSortIdx) ){
if( pIdx==0 ){
@@ -614,6 +660,7 @@ WhereInfo *sqliteWhereBegin(
pWInfo->a[0].iCur = pParse->nTab++;
pWInfo->peakNTab = pParse->nTab;
}
pWInfo->a[0].bRev = bRev;
*ppOrderBy = 0;
}
}
@@ -621,22 +668,18 @@ WhereInfo *sqliteWhereBegin(
/* Open all tables in the pTabList and all indices used by those tables.
*/
for(i=0; i<pTabList->nSrc; i++){
int openOp;
Table *pTab;
Index *pIx;
pTab = pTabList->a[i].pTab;
if( pTab->isTransient || pTab->pSelect ) continue;
openOp = pTab->isTemp ? OP_OpenAux : OP_Open;
sqliteVdbeAddOp(v, openOp, base+i, pTab->tnum);
sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
if( i==0 && !pParse->schemaVerified &&
(pParse->db->flags & SQLITE_InTrans)==0 ){
sqliteVdbeAddOp(v, OP_VerifyCookie, pParse->db->schema_cookie, 0);
pParse->schemaVerified = 1;
}
if( pWInfo->a[i].pIdx!=0 ){
sqliteVdbeAddOp(v, openOp, pWInfo->a[i].iCur, pWInfo->a[i].pIdx->tnum);
sqliteVdbeChangeP3(v, -1, pWInfo->a[i].pIdx->zName, P3_STATIC);
sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqliteVdbeOp3(v, OP_OpenRead, pTabList->a[i].iCursor, pTab->tnum,
pTab->zName, P3_STATIC);
sqliteCodeVerifySchema(pParse, pTab->iDb);
if( (pIx = pWInfo->a[i].pIdx)!=0 ){
sqliteVdbeAddOp(v, OP_Integer, pIx->iDb, 0);
sqliteVdbeOp3(v, OP_OpenRead, pWInfo->a[i].iCur, pIx->tnum, pIx->zName,0);
}
}
@@ -645,12 +688,12 @@ WhereInfo *sqliteWhereBegin(
loopMask = 0;
for(i=0; i<pTabList->nSrc; i++){
int j, k;
int idx = aOrder[i];
int iCur = pTabList->a[i].iCursor;
Index *pIdx;
WhereLevel *pLevel = &pWInfo->a[i];
/* If this is the right table of a LEFT OUTER JOIN, allocate and
** initialize a memory cell that record if this table matches any
** initialize a memory cell that records if this table matches any
** row of the left table of the join.
*/
if( i>0 && (pTabList->a[i-1].jointype & JT_LEFT)!=0 ){
@@ -671,9 +714,9 @@ WhereInfo *sqliteWhereBegin(
k = iDirectEq[i];
assert( k<nExpr );
assert( aExpr[k].p!=0 );
assert( aExpr[k].idxLeft==idx || aExpr[k].idxRight==idx );
assert( aExpr[k].idxLeft==iCur || aExpr[k].idxRight==iCur );
brk = pLevel->brk = sqliteVdbeMakeLabel(v);
if( aExpr[k].idxLeft==idx ){
if( aExpr[k].idxLeft==iCur ){
Expr *pX = aExpr[k].p;
if( pX->op!=TK_IN ){
sqliteExprCode(pParse, aExpr[k].p->pRight);
@@ -697,7 +740,7 @@ WhereInfo *sqliteWhereBegin(
cont = pLevel->cont = sqliteVdbeMakeLabel(v);
sqliteVdbeAddOp(v, OP_MustBeInt, 1, brk);
haveKey = 0;
sqliteVdbeAddOp(v, OP_NotExists, base+idx, brk);
sqliteVdbeAddOp(v, OP_NotExists, iCur, brk);
pLevel->op = OP_Noop;
}else if( pIdx!=0 && pLevel->score>0 && pLevel->score%4==0 ){
/* Case 2: There is an index and all terms of the WHERE clause that
@@ -705,13 +748,13 @@ WhereInfo *sqliteWhereBegin(
*/
int start;
int testOp;
int nColumn = pLevel->score/4;
int nColumn = (pLevel->score+4)/8;
brk = pLevel->brk = sqliteVdbeMakeLabel(v);
for(j=0; j<nColumn; j++){
for(k=0; k<nExpr; k++){
Expr *pX = aExpr[k].p;
if( pX==0 ) continue;
if( aExpr[k].idxLeft==idx
if( aExpr[k].idxLeft==iCur
&& (aExpr[k].prereqRight & loopMask)==aExpr[k].prereqRight
&& pX->pLeft->iColumn==pIdx->aiColumn[j]
){
@@ -738,7 +781,7 @@ WhereInfo *sqliteWhereBegin(
break;
}
}
if( aExpr[k].idxRight==idx
if( aExpr[k].idxRight==iCur
&& aExpr[k].p->op==TK_EQ
&& (aExpr[k].prereqLeft & loopMask)==aExpr[k].prereqLeft
&& aExpr[k].p->pRight->iColumn==pIdx->aiColumn[j]
@@ -751,9 +794,12 @@ WhereInfo *sqliteWhereBegin(
}
pLevel->iMem = pParse->nMem++;
cont = pLevel->cont = sqliteVdbeMakeLabel(v);
sqliteVdbeAddOp(v, OP_NotNull, -nColumn, sqliteVdbeCurrentAddr(v)+3);
sqliteVdbeAddOp(v, OP_Pop, nColumn, 0);
sqliteVdbeAddOp(v, OP_Goto, 0, brk);
sqliteVdbeAddOp(v, OP_MakeKey, nColumn, 0);
sqliteAddIdxKeyType(v, pIdx);
if( nColumn==pIdx->nColumn ){
if( nColumn==pIdx->nColumn || pLevel->bRev ){
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 0);
testOp = OP_IdxGT;
}else{
@@ -762,17 +808,29 @@ WhereInfo *sqliteWhereBegin(
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
testOp = OP_IdxGE;
}
sqliteVdbeAddOp(v, OP_MoveTo, pLevel->iCur, brk);
start = sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
sqliteVdbeAddOp(v, testOp, pLevel->iCur, brk);
if( pLevel->bRev ){
/* Scan in reverse order */
sqliteVdbeAddOp(v, OP_IncrKey, 0, 0);
sqliteVdbeAddOp(v, OP_MoveLt, pLevel->iCur, brk);
start = sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
sqliteVdbeAddOp(v, OP_IdxLT, pLevel->iCur, brk);
pLevel->op = OP_Prev;
}else{
/* Scan in the forward order */
sqliteVdbeAddOp(v, OP_MoveTo, pLevel->iCur, brk);
start = sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
sqliteVdbeAddOp(v, testOp, pLevel->iCur, brk);
pLevel->op = OP_Next;
}
sqliteVdbeAddOp(v, OP_RowKey, pLevel->iCur, 0);
sqliteVdbeAddOp(v, OP_IdxIsNull, nColumn, cont);
sqliteVdbeAddOp(v, OP_IdxRecno, pLevel->iCur, 0);
if( i==pTabList->nSrc-1 && pushKey ){
haveKey = 1;
}else{
sqliteVdbeAddOp(v, OP_MoveTo, base+idx, 0);
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
haveKey = 0;
}
pLevel->op = OP_Next;
pLevel->p1 = pLevel->iCur;
pLevel->p2 = start;
}else if( i<ARRAYSIZE(iDirectLt) && (iDirectLt[i]>=0 || iDirectGt[i]>=0) ){
@@ -787,34 +845,32 @@ WhereInfo *sqliteWhereBegin(
k = iDirectGt[i];
assert( k<nExpr );
assert( aExpr[k].p!=0 );
assert( aExpr[k].idxLeft==idx || aExpr[k].idxRight==idx );
if( aExpr[k].idxLeft==idx ){
assert( aExpr[k].idxLeft==iCur || aExpr[k].idxRight==iCur );
if( aExpr[k].idxLeft==iCur ){
sqliteExprCode(pParse, aExpr[k].p->pRight);
}else{
sqliteExprCode(pParse, aExpr[k].p->pLeft);
}
sqliteVdbeAddOp(v, OP_MustBeInt, 1, brk);
if( aExpr[k].p->op==TK_LT || aExpr[k].p->op==TK_GT ){
sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
}
sqliteVdbeAddOp(v, OP_MoveTo, base+idx, brk);
sqliteVdbeAddOp(v, OP_ForceInt,
aExpr[k].p->op==TK_LT || aExpr[k].p->op==TK_GT, brk);
sqliteVdbeAddOp(v, OP_MoveTo, iCur, brk);
aExpr[k].p = 0;
}else{
sqliteVdbeAddOp(v, OP_Rewind, base+idx, brk);
sqliteVdbeAddOp(v, OP_Rewind, iCur, brk);
}
if( iDirectLt[i]>=0 ){
k = iDirectLt[i];
assert( k<nExpr );
assert( aExpr[k].p!=0 );
assert( aExpr[k].idxLeft==idx || aExpr[k].idxRight==idx );
if( aExpr[k].idxLeft==idx ){
assert( aExpr[k].idxLeft==iCur || aExpr[k].idxRight==iCur );
if( aExpr[k].idxLeft==iCur ){
sqliteExprCode(pParse, aExpr[k].p->pRight);
}else{
sqliteExprCode(pParse, aExpr[k].p->pLeft);
}
sqliteVdbeAddOp(v, OP_MustBeInt, 1, sqliteVdbeCurrentAddr(v)+1);
/* sqliteVdbeAddOp(v, OP_MustBeInt, 0, sqliteVdbeCurrentAddr(v)+1); */
pLevel->iMem = pParse->nMem++;
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 0);
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
if( aExpr[k].p->op==TK_LT || aExpr[k].p->op==TK_GT ){
testOp = OP_Ge;
}else{
@@ -824,10 +880,10 @@ WhereInfo *sqliteWhereBegin(
}
start = sqliteVdbeCurrentAddr(v);
pLevel->op = OP_Next;
pLevel->p1 = base+idx;
pLevel->p1 = iCur;
pLevel->p2 = start;
if( testOp!=OP_Noop ){
sqliteVdbeAddOp(v, OP_Recno, base+idx, 0);
sqliteVdbeAddOp(v, OP_Recno, iCur, 0);
sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
sqliteVdbeAddOp(v, testOp, 0, brk);
}
@@ -840,10 +896,10 @@ WhereInfo *sqliteWhereBegin(
brk = pLevel->brk = sqliteVdbeMakeLabel(v);
cont = pLevel->cont = sqliteVdbeMakeLabel(v);
sqliteVdbeAddOp(v, OP_Rewind, base+idx, brk);
sqliteVdbeAddOp(v, OP_Rewind, iCur, brk);
start = sqliteVdbeCurrentAddr(v);
pLevel->op = OP_Next;
pLevel->p1 = base+idx;
pLevel->p1 = iCur;
pLevel->p2 = start;
haveKey = 0;
}else{
@@ -859,7 +915,7 @@ WhereInfo *sqliteWhereBegin(
** to force the output order to conform to an ORDER BY.
*/
int score = pLevel->score;
int nEqColumn = score/4;
int nEqColumn = score/8;
int start;
int leFlag, geFlag;
int testOp;
@@ -869,7 +925,7 @@ WhereInfo *sqliteWhereBegin(
for(j=0; j<nEqColumn; j++){
for(k=0; k<nExpr; k++){
if( aExpr[k].p==0 ) continue;
if( aExpr[k].idxLeft==idx
if( aExpr[k].idxLeft==iCur
&& aExpr[k].p->op==TK_EQ
&& (aExpr[k].prereqRight & loopMask)==aExpr[k].prereqRight
&& aExpr[k].p->pLeft->iColumn==pIdx->aiColumn[j]
@@ -878,7 +934,7 @@ WhereInfo *sqliteWhereBegin(
aExpr[k].p = 0;
break;
}
if( aExpr[k].idxRight==idx
if( aExpr[k].idxRight==iCur
&& aExpr[k].p->op==TK_EQ
&& (aExpr[k].prereqLeft & loopMask)==aExpr[k].prereqLeft
&& aExpr[k].p->pRight->iColumn==pIdx->aiColumn[j]
@@ -898,15 +954,23 @@ WhereInfo *sqliteWhereBegin(
sqliteVdbeAddOp(v, OP_Dup, nEqColumn-1, 0);
}
/* Labels for the beginning and end of the loop
*/
cont = pLevel->cont = sqliteVdbeMakeLabel(v);
brk = pLevel->brk = sqliteVdbeMakeLabel(v);
/* Generate the termination key. This is the key value that
** will end the search. There is no termination key if there
** are no equality terms and no "X<..." term.
**
** 2002-Dec-04: On a reverse-order scan, the so-called "termination"
** key computed here really ends up being the start key.
*/
if( (score & 1)!=0 ){
for(k=0; k<nExpr; k++){
Expr *pExpr = aExpr[k].p;
if( pExpr==0 ) continue;
if( aExpr[k].idxLeft==idx
if( aExpr[k].idxLeft==iCur
&& (pExpr->op==TK_LT || pExpr->op==TK_LE)
&& (aExpr[k].prereqRight & loopMask)==aExpr[k].prereqRight
&& pExpr->pLeft->iColumn==pIdx->aiColumn[j]
@@ -916,7 +980,7 @@ WhereInfo *sqliteWhereBegin(
aExpr[k].p = 0;
break;
}
if( aExpr[k].idxRight==idx
if( aExpr[k].idxRight==iCur
&& (pExpr->op==TK_GT || pExpr->op==TK_GE)
&& (aExpr[k].prereqLeft & loopMask)==aExpr[k].prereqLeft
&& pExpr->pRight->iColumn==pIdx->aiColumn[j]
@@ -933,13 +997,23 @@ WhereInfo *sqliteWhereBegin(
leFlag = 1;
}
if( testOp!=OP_Noop ){
int nCol = nEqColumn + (score & 1);
pLevel->iMem = pParse->nMem++;
sqliteVdbeAddOp(v, OP_MakeKey, nEqColumn + (score & 1), 0);
sqliteVdbeAddOp(v, OP_NotNull, -nCol, sqliteVdbeCurrentAddr(v)+3);
sqliteVdbeAddOp(v, OP_Pop, nCol, 0);
sqliteVdbeAddOp(v, OP_Goto, 0, brk);
sqliteVdbeAddOp(v, OP_MakeKey, nCol, 0);
sqliteAddIdxKeyType(v, pIdx);
if( leFlag ){
sqliteVdbeAddOp(v, OP_IncrKey, 0, 0);
}
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
if( pLevel->bRev ){
sqliteVdbeAddOp(v, OP_MoveLt, pLevel->iCur, brk);
}else{
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
}
}else if( pLevel->bRev ){
sqliteVdbeAddOp(v, OP_Last, pLevel->iCur, brk);
}
/* Generate the start key. This is the key that defines the lower
@@ -947,12 +1021,15 @@ WhereInfo *sqliteWhereBegin(
** equality terms and if there is no "X>..." term. In
** that case, generate a "Rewind" instruction in place of the
** start key search.
**
** 2002-Dec-04: In the case of a reverse-order search, the so-called
** "start" key really ends up being used as the termination key.
*/
if( (score & 2)!=0 ){
for(k=0; k<nExpr; k++){
Expr *pExpr = aExpr[k].p;
if( pExpr==0 ) continue;
if( aExpr[k].idxLeft==idx
if( aExpr[k].idxLeft==iCur
&& (pExpr->op==TK_GT || pExpr->op==TK_GE)
&& (aExpr[k].prereqRight & loopMask)==aExpr[k].prereqRight
&& pExpr->pLeft->iColumn==pIdx->aiColumn[j]
@@ -962,7 +1039,7 @@ WhereInfo *sqliteWhereBegin(
aExpr[k].p = 0;
break;
}
if( aExpr[k].idxRight==idx
if( aExpr[k].idxRight==iCur
&& (pExpr->op==TK_LT || pExpr->op==TK_LE)
&& (aExpr[k].prereqLeft & loopMask)==aExpr[k].prereqLeft
&& pExpr->pRight->iColumn==pIdx->aiColumn[j]
@@ -976,15 +1053,25 @@ WhereInfo *sqliteWhereBegin(
}else{
geFlag = 1;
}
brk = pLevel->brk = sqliteVdbeMakeLabel(v);
cont = pLevel->cont = sqliteVdbeMakeLabel(v);
if( nEqColumn>0 || (score&2)!=0 ){
sqliteVdbeAddOp(v, OP_MakeKey, nEqColumn + ((score&2)!=0), 0);
int nCol = nEqColumn + ((score&2)!=0);
sqliteVdbeAddOp(v, OP_NotNull, -nCol, sqliteVdbeCurrentAddr(v)+3);
sqliteVdbeAddOp(v, OP_Pop, nCol, 0);
sqliteVdbeAddOp(v, OP_Goto, 0, brk);
sqliteVdbeAddOp(v, OP_MakeKey, nCol, 0);
sqliteAddIdxKeyType(v, pIdx);
if( !geFlag ){
sqliteVdbeAddOp(v, OP_IncrKey, 0, 0);
}
sqliteVdbeAddOp(v, OP_MoveTo, pLevel->iCur, brk);
if( pLevel->bRev ){
pLevel->iMem = pParse->nMem++;
sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
testOp = OP_IdxLT;
}else{
sqliteVdbeAddOp(v, OP_MoveTo, pLevel->iCur, brk);
}
}else if( pLevel->bRev ){
testOp = OP_Noop;
}else{
sqliteVdbeAddOp(v, OP_Rewind, pLevel->iCur, brk);
}
@@ -998,21 +1085,23 @@ WhereInfo *sqliteWhereBegin(
sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
sqliteVdbeAddOp(v, testOp, pLevel->iCur, brk);
}
sqliteVdbeAddOp(v, OP_RowKey, pLevel->iCur, 0);
sqliteVdbeAddOp(v, OP_IdxIsNull, nEqColumn + (score & 1), cont);
sqliteVdbeAddOp(v, OP_IdxRecno, pLevel->iCur, 0);
if( i==pTabList->nSrc-1 && pushKey ){
haveKey = 1;
}else{
sqliteVdbeAddOp(v, OP_MoveTo, base+idx, 0);
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
haveKey = 0;
}
/* Record the instruction used to terminate the loop.
*/
pLevel->op = OP_Next;
pLevel->op = pLevel->bRev ? OP_Prev : OP_Next;
pLevel->p1 = pLevel->iCur;
pLevel->p2 = start;
}
loopMask |= 1<<idx;
loopMask |= getMask(&maskSet, iCur);
/* Insert code to test every subexpression that can be completely
** computed using the current set of tables.
@@ -1020,10 +1109,12 @@ WhereInfo *sqliteWhereBegin(
for(j=0; j<nExpr; j++){
if( aExpr[j].p==0 ) continue;
if( (aExpr[j].prereqAll & loopMask)!=aExpr[j].prereqAll ) continue;
if( pLevel->iLeftJoin && aExpr[j].p->isJoinExpr==0 ) continue;
if( pLevel->iLeftJoin && !ExprHasProperty(aExpr[j].p,EP_FromJoin) ){
continue;
}
if( haveKey ){
haveKey = 0;
sqliteVdbeAddOp(v, OP_MoveTo, base+idx, 0);
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
}
sqliteExprIfFalse(pParse, aExpr[j].p, cont, 1);
aExpr[j].p = 0;
@@ -1046,7 +1137,7 @@ WhereInfo *sqliteWhereBegin(
** no outer joins with DELETE and UPDATE.
*/
haveKey = 0;
sqliteVdbeAddOp(v, OP_MoveTo, base+idx, 0);
sqliteVdbeAddOp(v, OP_MoveTo, iCur, 0);
}
sqliteExprIfFalse(pParse, aExpr[j].p, cont, 1);
aExpr[j].p = 0;
@@ -1055,9 +1146,9 @@ WhereInfo *sqliteWhereBegin(
}
pWInfo->iContinue = cont;
if( pushKey && !haveKey ){
sqliteVdbeAddOp(v, OP_Recno, base, 0);
sqliteVdbeAddOp(v, OP_Recno, pTabList->a[0].iCursor, 0);
}
sqliteFree(aOrder);
freeMaskSet(&maskSet);
return pWInfo;
}
@@ -1068,7 +1159,6 @@ WhereInfo *sqliteWhereBegin(
void sqliteWhereEnd(WhereInfo *pWInfo){
Vdbe *v = pWInfo->pParse->pVdbe;
int i;
int base = pWInfo->base;
WhereLevel *pLevel;
SrcList *pTabList = pWInfo->pTabList;
@@ -1086,7 +1176,7 @@ void sqliteWhereEnd(WhereInfo *pWInfo){
int addr;
addr = sqliteVdbeAddOp(v, OP_MemLoad, pLevel->iLeftJoin, 0);
sqliteVdbeAddOp(v, OP_NotNull, 1, addr+4 + (pLevel->iCur>=0));
sqliteVdbeAddOp(v, OP_NullRow, base+i, 0);
sqliteVdbeAddOp(v, OP_NullRow, pTabList->a[i].iCursor, 0);
if( pLevel->iCur>=0 ){
sqliteVdbeAddOp(v, OP_NullRow, pLevel->iCur, 0);
}
@@ -1095,9 +1185,11 @@ void sqliteWhereEnd(WhereInfo *pWInfo){
}
sqliteVdbeResolveLabel(v, pWInfo->iBreak);
for(i=0; i<pTabList->nSrc; i++){
if( pTabList->a[i].pTab->isTransient ) continue;
Table *pTab = pTabList->a[i].pTab;
assert( pTab!=0 );
if( pTab->isTransient || pTab->pSelect ) continue;
pLevel = &pWInfo->a[i];
sqliteVdbeAddOp(v, OP_Close, base+i, 0);
sqliteVdbeAddOp(v, OP_Close, pTabList->a[i].iCursor, 0);
if( pLevel->pIdx!=0 ){
sqliteVdbeAddOp(v, OP_Close, pLevel->iCur, 0);
}
+27 -1
View File
@@ -10,7 +10,7 @@
#***********************************************************************
# This file runs all tests.
#
# $Id: all.test,v 1.17 2002/08/24 18:24:57 drh Exp $
# $Id: all.test,v 1.19 2003/02/16 22:21:33 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -23,6 +23,24 @@ if {[file exists ./sqlite_test_count]} {
set COUNT 4
}
if {[llength $argv]>0} {
foreach {name value} $argv {
switch -- $name {
-count {
set COUNT $value
}
-quick {
set ISQUICK $value
}
default {
puts stderr "Unknown option: $name"
exit
}
}
}
}
set argv {}
# LeakList will hold a list of the number of unfreed mallocs after
# each round of the test. This number should be constant. If it
# grows, it may mean there is a memory leak in the library.
@@ -49,6 +67,12 @@ for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} {
set tail [file tail $testfile]
if {[lsearch -exact $EXCLUDE $tail]>=0} continue
source $testfile
catch {db close}
if {$sqlite_open_file_count>0} {
puts "$tail did not close all files: $sqlite_open_file_count"
incr nErr
lappend ::failList $tail
}
}
if {[info exists Leak]} {
lappend LeakList $Leak
@@ -80,4 +104,6 @@ if {$LeakList!=""} {
catch {source $testdir/misuse.test}
catch {source $testdir/malloc.test}
catch {db close}
set sqlite_open_file_count 0
really_finish_test
+586
View File
@@ -0,0 +1,586 @@
# 2003 April 4
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is testing the ATTACH and DETACH commands
# and related functionality.
#
# $Id: attach.test,v 1.13 2004/02/14 01:39:50 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
for {set i 2} {$i<=15} {incr i} {
file delete -force test$i.db
file delete -force test$i.db-journal
}
do_test attach-1.1 {
execsql {
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,2);
INSERT INTO t1 VALUES(3,4);
SELECT * FROM t1;
}
} {1 2 3 4}
do_test attach-1.2 {
sqlite db2 test2.db
execsql {
CREATE TABLE t2(x,y);
INSERT INTO t2 VALUES(1,'x');
INSERT INTO t2 VALUES(2,'y');
SELECT * FROM t2;
} db2
} {1 x 2 y}
do_test attach-1.3 {
execsql {
ATTACH DATABASE 'test2.db' AS two;
SELECT * FROM two.t2;
}
} {1 x 2 y}
do_test attach-1.4 {
execsql {
SELECT * FROM t2;
}
} {1 x 2 y}
do_test attach-1.5 {
execsql {
DETACH DATABASE two;
SELECT * FROM t1;
}
} {1 2 3 4}
do_test attach-1.6 {
catchsql {
SELECT * FROM t2;
}
} {1 {no such table: t2}}
do_test attach-1.7 {
catchsql {
SELECT * FROM two.t2;
}
} {1 {no such table: two.t2}}
do_test attach-1.8 {
catchsql {
ATTACH DATABASE 'test3.db' AS three;
}
} {1 {cannot attach empty database: three}}
do_test attach-1.9 {
catchsql {
SELECT * FROM three.sqlite_master;
}
} {1 {no such table: three.sqlite_master}}
do_test attach-1.10 {
catchsql {
DETACH DATABASE three;
}
} {1 {no such database: three}}
do_test attach-1.11 {
execsql {
ATTACH 'test.db' AS db2;
ATTACH 'test.db' AS db3;
ATTACH 'test.db' AS db4;
ATTACH 'test.db' AS db5;
ATTACH 'test.db' AS db6;
ATTACH 'test.db' AS db7;
ATTACH 'test.db' AS db8;
ATTACH 'test.db' AS db9;
}
} {}
proc db_list {db} {
set list {}
foreach {idx name file} [execsql {PRAGMA database_list} $db] {
lappend list $idx $name
}
return $list
}
do_test attach-1.11b {
db_list db
} {0 main 1 temp 2 db2 3 db3 4 db4 5 db5 6 db6 7 db7 8 db8 9 db9}
do_test attach-1.12 {
catchsql {
ATTACH 'test.db' as db2;
}
} {1 {database db2 is already in use}}
do_test attach-1.13 {
catchsql {
ATTACH 'test.db' as db5;
}
} {1 {database db5 is already in use}}
do_test attach-1.14 {
catchsql {
ATTACH 'test.db' as db9;
}
} {1 {database db9 is already in use}}
do_test attach-1.15 {
catchsql {
ATTACH 'test.db' as main;
}
} {1 {database main is already in use}}
do_test attach-1.16 {
catchsql {
ATTACH 'test.db' as temp;
}
} {1 {database temp is already in use}}
do_test attach-1.17 {
catchsql {
ATTACH 'test.db' as MAIN;
}
} {1 {database MAIN is already in use}}
do_test attach-1.18 {
catchsql {
ATTACH 'test.db' as db10;
ATTACH 'test.db' as db11;
}
} {0 {}}
do_test attach-1.19 {
catchsql {
ATTACH 'test.db' as db12;
}
} {1 {too many attached databases - max 10}}
do_test attach-1.20.1 {
execsql {
DETACH db5;
}
db_list db
} {0 main 1 temp 2 db2 3 db3 4 db4 5 db11 6 db6 7 db7 8 db8 9 db9 10 db10}
integrity_check attach-1.20.2
do_test attach-1.21 {
catchsql {
ATTACH 'test.db' as db12;
}
} {0 {}}
do_test attach-1.22 {
catchsql {
ATTACH 'test.db' as db13;
}
} {1 {too many attached databases - max 10}}
do_test attach-1.23 {
catchsql {
DETACH db14;
}
} {1 {no such database: db14}}
do_test attach-1.24 {
catchsql {
DETACH db12;
}
} {0 {}}
do_test attach-1.25 {
catchsql {
DETACH db12;
}
} {1 {no such database: db12}}
do_test attach-1.26 {
catchsql {
DETACH main;
}
} {1 {cannot detach database main}}
do_test attach-1.27 {
catchsql {
DETACH Temp;
}
} {1 {cannot detach database Temp}}
do_test attach-1.28 {
catchsql {
DETACH db11;
DETACH db10;
DETACH db9;
DETACH db8;
DETACH db7;
DETACH db6;
DETACH db4;
DETACH db3;
DETACH db2;
}
} {0 {}}
do_test attach-1.29 {
db_list db
} {0 main 1 temp}
do_test attach-2.1 {
execsql {
CREATE TABLE tx(x1,x2,y1,y2);
CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
INSERT INTO tx(x1,x2,y1,y2) VALUES(OLD.x,NEW.x,OLD.y,NEW.y);
END;
SELECT * FROM tx;
} db2;
} {}
do_test attach-2.2 {
execsql {
UPDATE t2 SET x=x+10;
SELECT * FROM tx;
} db2;
} {1 11 x x 2 12 y y}
do_test attach-2.3 {
execsql {
CREATE TABLE tx(x1,x2,y1,y2);
SELECT * FROM tx;
}
} {}
do_test attach-2.4 {
execsql {
ATTACH 'test2.db' AS db2;
}
} {}
do_test attach-2.5 {
execsql {
UPDATE db2.t2 SET x=x+10;
SELECT * FROM db2.tx;
}
} {1 11 x x 2 12 y y 11 21 x x 12 22 y y}
do_test attach-2.6 {
execsql {
SELECT * FROM main.tx;
}
} {}
do_test attach-2.7 {
execsql {
SELECT type, name, tbl_name FROM db2.sqlite_master;
}
} {table t2 t2 table tx tx trigger r1 t2}
do_test attach-2.8 {
db_list db
} {0 main 1 temp 2 db2}
do_test attach-2.9 {
execsql {
CREATE INDEX i2 ON t2(x);
SELECT * FROM t2 WHERE x>5;
} db2
} {21 x 22 y}
do_test attach-2.10 {
execsql {
SELECT type, name, tbl_name FROM sqlite_master;
} db2
} {table t2 t2 table tx tx trigger r1 t2 index i2 t2}
#do_test attach-2.11 {
# catchsql {
# SELECT * FROM t2 WHERE x>5;
# }
#} {1 {database schema has changed}}
do_test attach-2.12 {
db_list db
} {0 main 1 temp 2 db2}
do_test attach-2.13 {
catchsql {
SELECT * FROM t2 WHERE x>5;
}
} {0 {21 x 22 y}}
do_test attach-2.14 {
execsql {
SELECT type, name, tbl_name FROM sqlite_master;
}
} {table t1 t1 table tx tx}
do_test attach-2.15 {
execsql {
SELECT type, name, tbl_name FROM db2.sqlite_master;
}
} {table t2 t2 table tx tx trigger r1 t2 index i2 t2}
do_test attach-2.16 {
db close
sqlite db test.db
execsql {
ATTACH 'test2.db' AS db2;
SELECT type, name, tbl_name FROM db2.sqlite_master;
}
} {table t2 t2 table tx tx trigger r1 t2 index i2 t2}
do_test attach-3.1 {
db close
db2 close
sqlite db test.db
sqlite db2 test2.db
execsql {
SELECT * FROM t1
}
} {1 2 3 4}
do_test attach-3.2 {
catchsql {
SELECT * FROM t2
}
} {1 {no such table: t2}}
do_test attach-3.3 {
catchsql {
ATTACH DATABASE 'test2.db' AS db2;
SELECT * FROM t2
}
} {0 {21 x 22 y}}
# Even though main has a transaction, test2.db should not be locked.
do_test attach-3.4 {
execsql BEGIN
catchsql {
SELECT * FROM t2;
} db2;
} {0 {21 x 22 y}}
# Reading from db2 should not lock test2.db
do_test attach-3.5 {
execsql {SELECT * FROM t2}
catchsql {
SELECT * FROM t2;
} db2;
} {0 {21 x 22 y}}
# Making a change to db2 causes test2.ddb to become locked.
do_test attach-3.6 {
execsql {
UPDATE t2 SET x=x+1 WHERE x=50;
}
catchsql {
SELECT * FROM t2;
} db2;
} {1 {database is locked}}
do_test attach-3.7 {
execsql ROLLBACK
execsql {SELECT * FROM t2} db2
} {21 x 22 y}
do_test attach-3.8 {
execsql BEGIN
execsql BEGIN db2
catchsql {SELECT * FROM t2}
} {1 {database is locked}}
do_test attach-3.9 {
catchsql {SELECT * FROM t2} db2
} {0 {21 x 22 y}}
do_test attach-3.10 {
execsql {SELECT * FROM t1}
} {1 2 3 4}
do_test attach-3.11 {
catchsql {UPDATE t1 SET a=a+1}
} {0 {}}
do_test attach-3.12 {
execsql {SELECT * FROM t1}
} {2 2 4 4}
do_test attach-3.13 {
catchsql {UPDATE t2 SET x=x+1 WHERE x=50}
} {1 {database is locked}}
do_test attach-3.14 {
# Unable to reinitialize the schema tables because the aux database
# is still locked.
catchsql {SELECT * FROM t1}
} {1 {database is locked}}
do_test attach-3.15 {
execsql COMMIT db2
execsql {SELECT * FROM t1}
} {1 2 3 4}
# Ticket #323
do_test attach-4.1 {
execsql {DETACH db2}
db2 close
sqlite db2 test2.db
execsql {
CREATE TABLE t3(x,y);
CREATE UNIQUE INDEX t3i1 ON t3(x);
INSERT INTO t3 VALUES(1,2);
SELECT * FROM t3;
} db2;
} {1 2}
do_test attach-4.2 {
execsql {
CREATE TABLE t3(a,b);
CREATE UNIQUE INDEX t3i1b ON t3(a);
INSERT INTO t3 VALUES(9,10);
SELECT * FROM t3;
}
} {9 10}
do_test attach-4.3 {
execsql {
ATTACH DATABASE 'test2.db' AS db2;
SELECT * FROM db2.t3;
}
} {1 2}
do_test attach-4.4 {
execsql {
SELECT * FROM main.t3;
}
} {9 10}
do_test attach-4.5 {
execsql {
INSERT INTO db2.t3 VALUES(9,10);
SELECT * FROM db2.t3;
}
} {1 2 9 10}
do_test attach-4.6 {
execsql {
DETACH db2;
}
execsql {
CREATE TABLE t4(x);
CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN
INSERT INTO t4 VALUES('db2.' || NEW.x);
END;
INSERT INTO t3 VALUES(6,7);
SELECT * FROM t4;
} db2
} {db2.6}
do_test attach-4.7 {
execsql {
CREATE TABLE t4(y);
CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN
INSERT INTO t4 VALUES('main.' || NEW.a);
END;
INSERT INTO main.t3 VALUES(11,12);
SELECT * FROM main.t4;
}
} {main.11}
do_test attach-4.8 {
execsql {
ATTACH DATABASE 'test2.db' AS db2;
INSERT INTO db2.t3 VALUES(13,14);
SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4;
}
} {db2.6 db2.13 main.11}
do_test attach-4.9 {
execsql {
INSERT INTO main.t3 VALUES(15,16);
SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4;
}
} {db2.6 db2.13 main.11 main.15}
do_test attach-4.10 {
execsql {
DETACH DATABASE db2;
}
execsql {
CREATE VIEW v3 AS SELECT x*100+y FROM t3;
SELECT * FROM v3;
} db2
} {102 910 607 1314}
do_test attach-4.11 {
execsql {
CREATE VIEW v3 AS SELECT a*100+b FROM t3;
SELECT * FROM v3;
}
} {910 1112 1516}
do_test attach-4.12 {
execsql {
ATTACH DATABASE 'test2.db' AS db2;
SELECT * FROM db2.v3;
}
} {102 910 607 1314}
do_test attach-4.13 {
execsql {
SELECT * FROM main.v3;
}
} {910 1112 1516}
# Tests for the sqliteFix...() routines in attach.c
#
do_test attach-5.1 {
db close
sqlite db test.db
db2 close
file delete -force test2.db
sqlite db2 test2.db
catchsql {
ATTACH DATABASE 'test.db' AS orig;
CREATE TRIGGER r1 AFTER INSERT ON orig.t1 BEGIN;
SELECT 'no-op';
END;
} db2
} {1 {triggers may not be added to auxiliary database orig}}
do_test attach-5.2 {
catchsql {
CREATE TABLE t5(x,y);
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op';
END;
} db2
} {0 {}}
do_test attach-5.3 {
catchsql {
DROP TRIGGER r5;
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' FROM orig.t1;
END;
} db2
} {1 {trigger r5 cannot reference objects in database orig}}
do_test attach-5.4 {
catchsql {
CREATE TEMP TABLE t6(p,q,r);
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' FROM temp.t6;
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.5 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' || (SELECT * FROM temp.t6);
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.6 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' FROM t1 WHERE x<(SELECT min(x) FROM temp.t6);
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.7 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' FROM t1 GROUP BY 1 HAVING x<(SELECT min(x) FROM temp.t6);
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.7 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT max(1,x,(SELECT min(x) FROM temp.t6)) FROM t1;
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.8 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
INSERT INTO t1 VALUES((SELECT min(x) FROM temp.t6),5);
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.9 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
DELETE FROM t1 WHERE x<(SELECT min(x) FROM temp.t6);
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
# Check to make sure we get a sensible error if unable to open
# the file that we are trying to attach.
#
do_test attach-6.1 {
catchsql {
ATTACH DATABASE 'no-such-file' AS nosuch;
}
} {1 {cannot attach empty database: nosuch}}
file delete -force no-such-file
if {$tcl_platform(platform)=="unix"} {
do_test attach-6.2 {
sqlite dbx cannot-read
dbx eval {CREATE TABLE t1(a,b,c)}
dbx close
file attributes cannot-read -permission 0000
catchsql {
ATTACH DATABASE 'cannot-read' AS noread;
}
} {1 {unable to open database: cannot-read}}
file delete -force cannot-read
}
for {set i 2} {$i<=15} {incr i} {
catch {db$i close}
}
file delete -force test2.db
finish_test
+146
View File
@@ -0,0 +1,146 @@
# 2003 July 1
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is testing the ATTACH and DETACH commands
# and related functionality.
#
# $Id: attach2.test,v 1.5 2004/02/12 15:31:22 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Ticket #354
#
do_test attach2-1.1 {
db eval {
CREATE TABLE t1(a,b);
CREATE INDEX x1 ON t1(a);
}
file delete -force test2.db
file delete -force test2.db-journal
sqlite db2 test2.db
db2 eval {
CREATE TABLE t1(a,b);
CREATE INDEX x1 ON t1(a);
}
catchsql {
ATTACH 'test2.db' AS t2;
}
} {0 {}}
# Ticket #514
#
proc db_list {db} {
set list {}
foreach {idx name file} [execsql {PRAGMA database_list} $db] {
lappend list $idx $name
}
return $list
}
db eval {DETACH t2}
do_test attach2-2.1 {
# lock test2.db then try to attach it. Should get an error.
db2 eval {BEGIN}
catchsql {
ATTACH 'test2.db' AS t2;
}
} {1 {database is locked}}
do_test attach2-2.2 {
# make sure test2.db did not get attached.
db_list db
} {0 main 1 temp}
do_test attach2-2.3 {
# unlock test2.db and try to attach again. should work this time.
db2 eval {COMMIT}
catchsql {
ATTACH 'test2.db' AS t2;
}
} {0 {}}
do_test attach2-2.4 {
db_list db
} {0 main 1 temp 2 t2}
do_test attach2-2.5 {
catchsql {
SELECT name FROM t2.sqlite_master;
}
} {0 {t1 x1}}
do_test attach2-2.6 {
# lock test2.db and try to read from it. should get an error.
db2 eval BEGIN
catchsql {
SELECT name FROM t2.sqlite_master;
}
} {1 {database is locked}}
do_test attach2-2.7 {
# but we can still read from test1.db even though test2.db is locked.
catchsql {
SELECT name FROM main.sqlite_master;
}
} {0 {t1 x1}}
do_test attach2-2.8 {
# start a transaction on test.db even though test2.db is locked.
catchsql {
BEGIN;
INSERT INTO t1 VALUES(8,9);
}
} {0 {}}
do_test attach2-2.9 {
execsql {
SELECT * FROM t1
}
} {8 9}
do_test attach2-2.10 {
# now try to write to test2.db. the write should fail
catchsql {
INSERT INTO t2.t1 VALUES(1,2);
}
} {1 {database is locked}}
do_test attach2-2.11 {
# when the write failed in the previous test, the transaction should
# have rolled back.
db2 eval ROLLBACK
execsql {
SELECT * FROM t1
}
} {}
do_test attach2-2.12 {
catchsql {
COMMIT
}
} {1 {cannot commit - no transaction is active}}
# Ticket #574: Make sure it works usingi the non-callback API
#
do_test attach2-3.1 {
db close
set DB [sqlite db test.db]
set rc [catch {sqlite_compile $DB "ATTACH 'test2.db' AS t2" TAIL} VM]
if {$rc} {lappend rc $VM}
sqlite_finalize $VM
set rc
} {0}
do_test attach2-3.2 {
set rc [catch {sqlite_compile $DB "DETACH t2" TAIL} VM]
if {$rc} {lappend rc $VM}
sqlite_finalize $VM
set rc
} {0}
db close
for {set i 2} {$i<=15} {incr i} {
catch {db$i close}
}
file delete -force test2.db
finish_test
+1892
View File
File diff suppressed because it is too large Load Diff
+177
View File
@@ -0,0 +1,177 @@
# 2002 November 30
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script testing the ability of SQLite to handle database
# files larger than 4GB.
#
# $Id: bigfile.test,v 1.3 2003/12/19 12:31:22 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# These tests only work for Tcl version 8.4 and later. Prior to 8.4,
# Tcl was unable to handle large files.
#
scan $::tcl_version %f vx
if {$vx<8.4} return
# This is the md5 checksum of all the data in table t1 as created
# by the first test. We will use this number to make sure that data
# never changes.
#
set MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf}
do_test bigfile-1.1 {
execsql {
BEGIN;
CREATE TABLE t1(x);
INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz');
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
COMMIT;
}
execsql {
SELECT md5sum(x) FROM t1;
}
} $::MAGIC_SUM
# Try to create a large file - a file that is larger than 2^32 bytes.
# If this fails, it means that the system being tested does not support
# large files. So skip all of the remaining tests in this file.
#
db close
if {[catch {fake_big_file 4096 test.db}]} {
puts "**** Unable to create a file larger than 4096 MB. *****"
finish_test
return
}
do_test bigfile-1.2 {
sqlite db test.db
execsql {
SELECT md5sum(x) FROM t1;
}
} $::MAGIC_SUM
# The previous test may fail on some systems because they are unable
# to handle large files. If that is so, then skip all of the following
# tests. We will know the above test failed because the "db" command
# does not exist.
#
if {[llength [info command db]]>0} {
do_test bigfile-1.3 {
execsql {
CREATE TABLE t2 AS SELECT * FROM t1;
SELECT md5sum(x) FROM t2;
}
} $::MAGIC_SUM
do_test bigfile-1.4 {
db close
sqlite db test.db
execsql {
SELECT md5sum(x) FROM t1;
}
} $::MAGIC_SUM
do_test bigfile-1.5 {
execsql {
SELECT md5sum(x) FROM t2;
}
} $::MAGIC_SUM
db close
if {[catch {fake_big_file 8192 test.db}]} {
puts "**** Unable to create a file larger than 8192 MB. *****"
finish_test
return
}
do_test bigfile-1.6 {
sqlite db test.db
execsql {
SELECT md5sum(x) FROM t1;
}
} $::MAGIC_SUM
do_test bigfile-1.7 {
execsql {
CREATE TABLE t3 AS SELECT * FROM t1;
SELECT md5sum(x) FROM t3;
}
} $::MAGIC_SUM
do_test bigfile-1.8 {
db close
sqlite db test.db
execsql {
SELECT md5sum(x) FROM t1;
}
} $::MAGIC_SUM
do_test bigfile-1.9 {
execsql {
SELECT md5sum(x) FROM t2;
}
} $::MAGIC_SUM
do_test bigfile-1.10 {
execsql {
SELECT md5sum(x) FROM t3;
}
} $::MAGIC_SUM
db close
if {[catch {fake_big_file 16384 test.db}]} {
puts "**** Unable to create a file larger than 16384 MB. *****"
finish_test
return
}
do_test bigfile-1.11 {
sqlite db test.db
execsql {
SELECT md5sum(x) FROM t1;
}
} $::MAGIC_SUM
do_test bigfile-1.12 {
execsql {
CREATE TABLE t4 AS SELECT * FROM t1;
SELECT md5sum(x) FROM t4;
}
} $::MAGIC_SUM
do_test bigfile-1.13 {
db close
sqlite db test.db
execsql {
SELECT md5sum(x) FROM t1;
}
} $::MAGIC_SUM
do_test bigfile-1.14 {
execsql {
SELECT md5sum(x) FROM t2;
}
} $::MAGIC_SUM
do_test bigfile-1.15 {
execsql {
SELECT md5sum(x) FROM t3;
}
} $::MAGIC_SUM
do_test bigfile-1.16 {
execsql {
SELECT md5sum(x) FROM t3;
}
} $::MAGIC_SUM
} ;# End of the "if( db command exists )"
finish_test
+72
View File
@@ -0,0 +1,72 @@
# 2003 September 6
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script testing the sqlite_bind API.
#
# $Id: bind.test,v 1.1 2003/09/06 22:45:21 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test bind-1.1 {
db close
set DB [sqlite db test.db]
execsql {CREATE TABLE t1(a,b,c)}
set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
set TAIL
} {}
do_test bind-1.2 {
sqlite_step $VM N VALUES COLNAMES
} {SQLITE_DONE}
do_test bind-1.3 {
execsql {SELECT rowid, * FROM t1}
} {1 {} {} {}}
do_test bind-1.4 {
sqlite_reset $VM
sqlite_bind $VM 1 {test value 1} normal
sqlite_step $VM N VALUES COLNAMES
} SQLITE_DONE
do_test bind-1.5 {
execsql {SELECT rowid, * FROM t1}
} {1 {} {} {} 2 {test value 1} {} {}}
do_test bind-1.6 {
sqlite_reset $VM
sqlite_bind $VM 3 {'test value 2'} normal
sqlite_step $VM N VALUES COLNAMES
} SQLITE_DONE
do_test bind-1.7 {
execsql {SELECT rowid, * FROM t1}
} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}}
do_test bind-1.8 {
sqlite_reset $VM
set sqlite_static_bind_value 123
sqlite_bind $VM 1 {} static
sqlite_bind $VM 2 {abcdefg} normal
sqlite_bind $VM 3 {} null
execsql {DELETE FROM t1}
sqlite_step $VM N VALUES COLNAMES
execsql {SELECT rowid, * FROM t1}
} {1 123 abcdefg {}}
do_test bind-1.9 {
sqlite_reset $VM
sqlite_bind $VM 1 {456} normal
sqlite_step $VM N VALUES COLNAMES
execsql {SELECT rowid, * FROM t1}
} {1 123 abcdefg {} 2 456 abcdefg {}}
do_test bind-1.99 {
sqlite_finalize $VM
} {}
finish_test
+10 -9
View File
@@ -11,13 +11,14 @@
# This file implements regression tests for SQLite library. The
# focus of this script is btree database backend
#
# $Id: btree.test,v 1.13 2002/09/02 12:14:51 drh Exp $
# $Id: btree.test,v 1.15 2004/02/10 01:54:28 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {[info commands btree_open]!=""} {
if {[info commands btree_open]!="" && $SQLITE_PAGE_SIZE==1024
&& $SQLITE_USABLE_SIZE==1024} {
# Basic functionality. Open and close a database.
#
@@ -359,30 +360,30 @@ do_test btree-4.9 {
#
do_test btree-5.1 {
btree_get_meta $::b1
} {0 0 0 0}
} {0 0 0 0 0 0 0 0 0 0}
do_test btree-5.2 {
set rc [catch {btree_update_meta $::b1 1 2 3 4} msg]
set rc [catch {btree_update_meta $::b1 1 2 3 4 5 6 7 8 9 10} msg]
lappend rc $msg
} {1 SQLITE_ERROR}
do_test btree-5.3 {
btree_begin_transaction $::b1
set rc [catch {btree_update_meta $::b1 1 2 3 4} msg]
set rc [catch {btree_update_meta $::b1 1 2 3 4 5 6 7 8 9 10} msg]
lappend rc $msg
} {0 {}}
do_test btree-5.4 {
btree_get_meta $::b1
} {0 2 3 4}
} {0 2 3 4 5 6 7 8 9 10}
do_test btree-5.5 {
btree_close_cursor $::c1
btree_rollback $::b1
btree_get_meta $::b1
} {0 0 0 0}
} {0 0 0 0 0 0 0 0 0 0}
do_test btree-5.6 {
btree_begin_transaction $::b1
btree_update_meta $::b1 999 10 20 30
btree_update_meta $::b1 999 10 20 30 40 50 60 70 80 90
btree_commit $::b1
btree_get_meta $::b1
} {0 10 20 30}
} {0 10 20 30 40 50 60 70 80 90}
proc select_all {cursor} {
set r {}
+14 -6
View File
@@ -20,7 +20,7 @@
# cursor pointing at the first entry past the one that was deleted.
# This test is designed to verify that behavior.
#
# $Id: btree3.test,v 1.1 2001/11/23 00:24:12 drh Exp $
# $Id: btree3.test,v 1.2 2002/12/04 13:40:27 drh Exp $
set testdir [file dirname $argv0]
@@ -47,7 +47,7 @@ for {set k 2} {$k<=10} {incr k} {
set jkey [format %02d $j]
btree_clear_table $::b1 2
set ::c1 [btree_cursor $::b1 2 1]
for {set i 1} {$i<=$k+1} {incr i} {
for {set i 1} {$i<=$k} {incr i} {
set key [format %02d $i]
do_test btree3-$k.$j.1.$i {
btree_insert $::c1 $::key $::data
@@ -61,10 +61,18 @@ for {set k 2} {$k<=10} {incr k} {
do_test btree3-$k.$j.3 {
btree_delete $::c1
} {}
do_test btree3-$k.$j.4 {
btree_next $::c1
btree_key $::c1
} [format %02d [expr $j+1]]
if {$j<$k} {
do_test btree3-$k.$j.4 {
btree_next $::c1
btree_key $::c1
} [format %02d [expr $j+1]]
}
if {$j>1} {
do_test btree3-$k.$j.5 {
btree_prev $::c1
btree_key $::c1
} [format %02d [expr $j-1]]
}
btree_close_cursor $::c1
}
}
+84
View File
@@ -0,0 +1,84 @@
# 2001 November 22
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is btree database backend
#
# In particular, this file tests a small part of the Delete logic
# for the BTree backend. When a row is deleted from a table, the
# cursor is suppose to be left pointing at either the previous or
# next entry in that table. If the cursor is left pointing at the
# next entry, then the next Next operation is ignored. So the
# sequence of operations (Delete, Next) should always leave the
# cursor pointing at the first entry past the one that was deleted.
# This test is designed to verify that behavior.
#
# $Id: btree3rb.test,v 1.1 2003/04/20 23:45:23 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {[info commands btree_open]!=""} {
# Open a test database.
#
set b1 [btree_open :memory:]
btree_begin_transaction $::b1
# Insert a few one records
#
set data {abcdefghijklmnopqrstuvwxyz0123456789}
append data $data
append data $data
append data $data
append data $data
for {set k 2} {$k<=20} {incr k} {
for {set j 1} {$j<=$k} {incr j} {
set jkey [format %02d $j]
btree_clear_table $::b1 2
set ::c1 [btree_cursor $::b1 2 1]
for {set i 1} {$i<=$k} {incr i} {
set key [format %02d $i]
do_test btree3rb-$k.$j.1.$i {
btree_insert $::c1 $::key $::data
} {}
# btree_tree_dump $::b1 2
}
do_test btree3rb-$k.$j.2 {
btree_move_to $::c1 $::jkey
btree_key $::c1
} $::jkey
do_test btree3rb-$k.$j.3 {
btree_delete $::c1
} {}
if {$j<$k} {
do_test btree3rb-$k.$j.4 {
btree_next $::c1
btree_key $::c1
} [format %02d [expr $j+1]]
}
if {$j>1} {
do_test btree3rb-$k.$j.5 {
btree_prev $::c1
btree_key $::c1
} [format %02d [expr $j-1]]
}
btree_close_cursor $::c1
}
}
btree_rollback $::b1
#btree_pager_ref_dump $::b1
btree_close $::b1
} ;# end if( not mem: and has pager_open command );
finish_test
+98
View File
@@ -0,0 +1,98 @@
# 2002 December 03
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is btree database backend
#
# This file focuses on testing the sqliteBtreeNext() and
# sqliteBtreePrevious() procedures and making sure they are able
# to step through an entire table from either direction.
#
# $Id: btree4.test,v 1.1 2002/12/04 13:40:27 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {[info commands btree_open]!=""} {
# Open a test database.
#
file delete -force test1.bt
file delete -force test1.bt-journal
set b1 [btree_open test1.bt]
btree_begin_transaction $::b1
set data {abcdefghijklmnopqrstuvwxyz0123456789}
append data $data
append data $data
append data $data
append data $data
foreach N {10 100 1000} {
btree_clear_table $::b1 2
set ::c1 [btree_cursor $::b1 2 1]
do_test btree4-$N.1 {
for {set i 1} {$i<=$N} {incr i} {
btree_insert $::c1 [format k-%05d $i] $::data-$i
}
btree_first $::c1
btree_key $::c1
} {k-00001}
do_test btree4-$N.2 {
btree_data $::c1
} $::data-1
for {set i 2} {$i<=$N} {incr i} {
do_test btree-$N.3.$i.1 {
btree_next $::c1
} 0
do_test btree-$N.3.$i.2 {
btree_key $::c1
} [format k-%05d $i]
do_test btree-$N.3.$i.3 {
btree_data $::c1
} $::data-$i
}
do_test btree4-$N.4 {
btree_next $::c1
} 1
do_test btree4-$N.5 {
btree_last $::c1
} 0
do_test btree4-$N.6 {
btree_key $::c1
} [format k-%05d $N]
do_test btree4-$N.7 {
btree_data $::c1
} $::data-$N
for {set i [expr {$N-1}]} {$i>=1} {incr i -1} {
do_test btree4-$N.8.$i.1 {
btree_prev $::c1
} 0
do_test btree4-$N.8.$i.2 {
btree_key $::c1
} [format k-%05d $i]
do_test btree4-$N.8.$i.3 {
btree_data $::c1
} $::data-$i
}
do_test btree4-$N.9 {
btree_prev $::c1
} 1
btree_close_cursor $::c1
}
btree_rollback $::b1
btree_pager_ref_dump $::b1
btree_close $::b1
} ;# end if( not mem: and has pager_open command );
finish_test
+95
View File
@@ -0,0 +1,95 @@
# 2002 December 03
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is btree database backend
#
# This file focuses on testing the sqliteBtreeNext() and
# sqliteBtreePrevious() procedures and making sure they are able
# to step through an entire table from either direction.
#
# $Id: btree4rb.test,v 1.1 2003/04/20 23:45:23 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {[info commands btree_open]!=""} {
# Open a test database.
#
set b1 [btree_open :memory:]
btree_begin_transaction $::b1
set data {abcdefghijklmnopqrstuvwxyz0123456789}
append data $data
append data $data
append data $data
append data $data
foreach N {10 100 1000} {
btree_clear_table $::b1 2
set ::c1 [btree_cursor $::b1 2 1]
do_test btree4rb-$N.1 {
for {set i 1} {$i<=$N} {incr i} {
btree_insert $::c1 [format k-%05d $i] $::data-$i
}
btree_first $::c1
btree_key $::c1
} {k-00001}
do_test btree4rb-$N.2 {
btree_data $::c1
} $::data-1
for {set i 2} {$i<=$N} {incr i} {
do_test btree-$N.3.$i.1 {
btree_next $::c1
} 0
do_test btree-$N.3.$i.2 {
btree_key $::c1
} [format k-%05d $i]
do_test btree-$N.3.$i.3 {
btree_data $::c1
} $::data-$i
}
do_test btree4rb-$N.4 {
btree_next $::c1
} 1
do_test btree4rb-$N.5 {
btree_last $::c1
} 0
do_test btree4rb-$N.6 {
btree_key $::c1
} [format k-%05d $N]
do_test btree4rb-$N.7 {
btree_data $::c1
} $::data-$N
for {set i [expr {$N-1}]} {$i>=1} {incr i -1} {
do_test btree4rb-$N.8.$i.1 {
btree_prev $::c1
} 0
do_test btree4rb-$N.8.$i.2 {
btree_key $::c1
} [format k-%05d $i]
do_test btree4rb-$N.8.$i.3 {
btree_data $::c1
} $::data-$i
}
do_test btree4rb-$N.9 {
btree_prev $::c1
} 1
btree_close_cursor $::c1
}
btree_rollback $::b1
btree_close $::b1
} ;# end if( not mem: and has pager_open command );
finish_test
+475
View File
@@ -0,0 +1,475 @@
# 2003 January 29
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script testing the callback-free C/C++ API.
#
# $Id: capi2.test,v 1.10 2003/08/05 13:13:38 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Check basic functionality
#
do_test capi2-1.1 {
db close
set DB [sqlite db test.db]
execsql {CREATE TABLE t1(a,b,c)}
set VM [sqlite_compile $DB {SELECT name, rowid FROM sqlite_master} TAIL]
set TAIL
} {}
do_test capi2-1.2 {
sqlite_step $VM N VALUES COLNAMES
} {SQLITE_ROW}
do_test capi2-1.3 {
set N
} {2}
do_test capi2-1.4 {
set VALUES
} {t1 1}
do_test capi2-1.5 {
set COLNAMES
} {name rowid text INTEGER}
do_test capi2-1.6 {
set N x
set VALUES y
set COLNAMES z
sqlite_step $VM N VALUES COLNAMES
} {SQLITE_DONE}
do_test capi2-1.7 {
list $N $VALUES $COLNAMES
} {2 {} {name rowid text INTEGER}}
do_test capi2-1.8 {
set N x
set VALUES y
set COLNAMES z
sqlite_step $VM N VALUES COLNAMES
} {SQLITE_MISUSE}
do_test capi2-1.9 {
list $N $VALUES $COLNAMES
} {0 {} {}}
do_test capi2-1.10 {
sqlite_finalize $VM
} {}
# Check to make sure that the "tail" of a multi-statement SQL script
# is returned by sqlite_compile.
#
do_test capi2-2.1 {
set SQL {
SELECT name, rowid FROM sqlite_master;
SELECT name, rowid FROM sqlite_temp_master;
-- A comment at the end
}
set VM [sqlite_compile $DB $SQL SQL]
set SQL
} {
SELECT name, rowid FROM sqlite_temp_master;
-- A comment at the end
}
do_test capi2-2.2 {
set r [sqlite_step $VM n val colname]
lappend r $n $val $colname
} {SQLITE_ROW 2 {t1 1} {name rowid text INTEGER}}
do_test capi2-2.3 {
set r [sqlite_step $VM n val colname]
lappend r $n $val $colname
} {SQLITE_DONE 2 {} {name rowid text INTEGER}}
do_test capi2-2.4 {
sqlite_finalize $VM
} {}
do_test capi2-2.5 {
set VM [sqlite_compile $DB $SQL SQL]
set SQL
} {
-- A comment at the end
}
do_test capi2-2.6 {
set r [sqlite_step $VM n val colname]
lappend r $n $val $colname
} {SQLITE_DONE 2 {} {name rowid text INTEGER}}
do_test capi2-2.7 {
sqlite_finalize $VM
} {}
do_test capi2-2.8 {
set VM [sqlite_compile $DB $SQL SQL]
list $SQL $VM
} {{} {}}
# Check the error handling.
#
do_test capi2-3.1 {
set rc [catch {
sqlite_compile $DB {select bogus from sqlite_master} TAIL
} msg]
lappend rc $msg $TAIL
} {1 {(1) no such column: bogus} {}}
do_test capi2-3.2 {
set rc [catch {
sqlite_compile $DB {select bogus from } TAIL
} msg]
lappend rc $msg $TAIL
} {1 {(1) near " ": syntax error} {}}
do_test capi2-3.3 {
set rc [catch {
sqlite_compile $DB {;;;;select bogus from sqlite_master} TAIL
} msg]
lappend rc $msg $TAIL
} {1 {(1) no such column: bogus} {}}
do_test capi2-3.4 {
set rc [catch {
sqlite_compile $DB {select bogus from sqlite_master;x;} TAIL
} msg]
lappend rc $msg $TAIL
} {1 {(1) no such column: bogus} {x;}}
do_test capi2-3.5 {
set rc [catch {
sqlite_compile $DB {select bogus from sqlite_master;;;x;} TAIL
} msg]
lappend rc $msg $TAIL
} {1 {(1) no such column: bogus} {;;x;}}
do_test capi2-3.6 {
set rc [catch {
sqlite_compile $DB {select 5/0} TAIL
} VM]
lappend rc $TAIL
} {0 {}}
do_test capi2-3.7 {
set N {}
set VALUE {}
set COLNAME {}
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 {{}} {5/0 NUMERIC}}
do_test capi2-3.8 {
sqlite_finalize $VM
} {}
do_test capi2-3.9 {
execsql {CREATE UNIQUE INDEX i1 ON t1(a)}
set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(1,2,3)} TAIL]
set TAIL
} {}
do_test capi2-3.9b {db changes} {0}
do_test capi2-3.10 {
set N {}
set VALUE {}
set COLNAME {}
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_DONE 0 {} {}}
do_test capi2-3.10b {db changes} {1}
do_test capi2-3.11 {
sqlite_finalize $VM
} {}
do_test capi2-3.11b {db changes} {1}
do_test capi2-3.12 {
list [catch {sqlite_finalize $VM} msg] [set msg]
} {1 {(21) library routine called out of sequence}}
do_test capi2-3.13 {
set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(1,3,4)} TAIL]
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ERROR 0 {} {}}
do_test capi2-3.13b {db changes} {0}
do_test capi2-3.14 {
list [catch {sqlite_finalize $VM} msg] [set msg]
} {1 {(19) column a is not unique}}
do_test capi2-3.15 {
set VM [sqlite_compile $DB {CREATE TABLE t2(a NOT NULL, b)} TAIL]
set TAIL
} {}
do_test capi2-3.16 {
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_DONE 0 {} {}}
do_test capi2-3.17 {
list [catch {sqlite_finalize $VM} msg] [set msg]
} {0 {}}
do_test capi2-3.18 {
set VM [sqlite_compile $DB {INSERT INTO t2 VALUES(NULL,2)} TAIL]
list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ERROR 0 {} {}}
do_test capi2-3.19 {
list [catch {sqlite_finalize $VM} msg] [set msg]
} {1 {(19) t2.a may not be NULL}}
# Two or more virtual machines exists at the same time.
#
do_test capi2-4.1 {
set VM1 [sqlite_compile $DB {INSERT INTO t2 VALUES(1,2)} TAIL]
set TAIL
} {}
do_test capi2-4.2 {
set VM2 [sqlite_compile $DB {INSERT INTO t2 VALUES(2,3)} TAIL]
set TAIL
} {}
do_test capi2-4.3 {
set VM3 [sqlite_compile $DB {INSERT INTO t2 VALUES(3,4)} TAIL]
set TAIL
} {}
do_test capi2-4.4 {
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_DONE 0 {} {}}
do_test capi2-4.5 {
execsql {SELECT * FROM t2 ORDER BY a}
} {2 3}
do_test capi2-4.6 {
list [catch {sqlite_finalize $VM2} msg] [set msg]
} {0 {}}
do_test capi2-4.7 {
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_DONE 0 {} {}}
do_test capi2-4.8 {
execsql {SELECT * FROM t2 ORDER BY a}
} {2 3 3 4}
do_test capi2-4.9 {
list [catch {sqlite_finalize $VM3} msg] [set msg]
} {0 {}}
do_test capi2-4.10 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_DONE 0 {} {}}
do_test capi2-4.11 {
execsql {SELECT * FROM t2 ORDER BY a}
} {1 2 2 3 3 4}
do_test capi2-4.12 {
list [catch {sqlite_finalize $VM1} msg] [set msg]
} {0 {}}
# Interleaved SELECTs
#
do_test capi2-5.1 {
set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
set VM2 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
set VM3 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 2 {2 3} {a b {} {}}}
do_test capi2-5.2 {
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 2 {2 3} {a b {} {}}}
do_test capi2-5.3 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 2 {3 4} {a b {} {}}}
do_test capi2-5.4 {
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 2 {2 3} {a b {} {}}}
do_test capi2-5.5 {
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 2 {3 4} {a b {} {}}}
do_test capi2-5.6 {
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 2 {1 2} {a b {} {}}}
do_test capi2-5.7 {
list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_DONE 2 {} {a b {} {}}}
do_test capi2-5.8 {
list [catch {sqlite_finalize $VM3} msg] [set msg]
} {0 {}}
do_test capi2-5.9 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 2 {1 2} {a b {} {}}}
do_test capi2-5.10 {
list [catch {sqlite_finalize $VM1} msg] [set msg]
} {0 {}}
do_test capi2-5.11 {
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 2 {3 4} {a b {} {}}}
do_test capi2-5.12 {
list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 2 {1 2} {a b {} {}}}
do_test capi2-5.11 {
list [catch {sqlite_finalize $VM2} msg] [set msg]
} {0 {}}
# Check for proper SQLITE_BUSY returns.
#
do_test capi2-6.1 {
execsql {
BEGIN;
CREATE TABLE t3(x counter);
INSERT INTO t3 VALUES(1);
INSERT INTO t3 VALUES(2);
INSERT INTO t3 SELECT x+2 FROM t3;
INSERT INTO t3 SELECT x+4 FROM t3;
INSERT INTO t3 SELECT x+8 FROM t3;
COMMIT;
}
set VM1 [sqlite_compile $DB {SELECT * FROM t3} TAIL]
sqlite db2 test.db
execsql {BEGIN} db2
} {}
do_test capi2-6.2 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_BUSY 0 {} {}}
do_test capi2-6.3 {
execsql {COMMIT} db2
} {}
do_test capi2-6.4 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 1 {x counter}}
do_test capi2-6.5 {
catchsql {BEGIN} db2
} {1 {database is locked}}
do_test capi2-6.6 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 2 {x counter}}
do_test capi2-6.7 {
execsql {SELECT * FROM t2} db2
} {2 3 3 4 1 2}
do_test capi2-6.8 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 3 {x counter}}
do_test capi2-6.9 {
execsql {SELECT * FROM t2}
} {2 3 3 4 1 2}
do_test capi2-6.10 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 4 {x counter}}
do_test capi2-6.11 {
execsql {BEGIN}
} {}
do_test capi2-6.12 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 5 {x counter}}
# execsql {pragma vdbe_trace=on}
do_test capi2-6.13 {
catchsql {UPDATE t3 SET x=x+1}
} {1 {database table is locked}}
do_test capi2-6.14 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 6 {x counter}}
# puts [list [catch {sqlite_finalize $VM1} msg] [set msg]]; exit
do_test capi2-6.15 {
execsql {SELECT * FROM t1}
} {1 2 3}
do_test capi2-6.16 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 7 {x counter}}
do_test capi2-6.17 {
catchsql {UPDATE t1 SET b=b+1}
} {0 {}}
do_test capi2-6.18 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 8 {x counter}}
do_test capi2-6.19 {
execsql {SELECT * FROM t1}
} {1 3 3}
do_test capi2-6.20 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 9 {x counter}}
do_test capi2-6.21 {
execsql {ROLLBACK; SELECT * FROM t1}
} {1 2 3}
do_test capi2-6.22 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 10 {x counter}}
do_test capi2-6.23 {
execsql {BEGIN TRANSACTION ON CONFLICT ROLLBACK;}
} {}
do_test capi2-6.24 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 11 {x counter}}
do_test capi2-6.25 {
execsql {
INSERT INTO t1 VALUES(2,3,4);
SELECT * FROM t1;
}
} {1 2 3 2 3 4}
do_test capi2-6.26 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 12 {x counter}}
do_test capi2-6.27 {
catchsql {
INSERT INTO t1 VALUES(2,4,5);
SELECT * FROM t1;
}
} {1 {column a is not unique}}
do_test capi2-6.28 {
list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
} {SQLITE_ROW 1 13 {x counter}}
do_test capi2-6.99 {
list [catch {sqlite_finalize $VM1} msg] [set msg]
} {0 {}}
catchsql {ROLLBACK}
do_test capi2-7.1 {
stepsql $DB {
SELECT * FROM t1
}
} {0 1 2 3}
do_test capi2-7.2 {
stepsql $DB {
PRAGMA count_changes=on
}
} {0}
do_test capi2-7.3 {
stepsql $DB {
UPDATE t1 SET a=a+10;
}
} {0 1}
do_test capi2-7.4 {
stepsql $DB {
INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1;
}
} {0 1}
do_test capi2-7.4b {db changes} {1}
do_test capi2-7.5 {
stepsql $DB {
UPDATE t1 SET a=a+10;
}
} {0 2}
do_test capi2-7.5b {db changes} {2}
do_test capi2-7.6 {
stepsql $DB {
SELECT * FROM t1;
}
} {0 21 2 3 22 3 4}
do_test capi2-7.7 {
stepsql $DB {
INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1;
}
} {0 2}
do_test capi2-7.8 {
db changes
} {2}
do_test capi2-7.9 {
stepsql $DB {
SELECT * FROM t1;
}
} {0 21 2 3 22 3 4 23 4 5 24 5 6}
do_test capi2-7.10 {
stepsql $DB {
UPDATE t1 SET a=a-20;
SELECT * FROM t1;
}
} {0 4 1 2 3 2 3 4 3 4 5 4 5 6}
do_test capi2-7.11 {
db changes
} {0}
do_test capi2-7.12 {
set x [stepsql $DB {EXPLAIN SELECT * FROM t1}]
lindex $x 0
} {0}
# Ticket #261 - make sure we can finalize before the end of a query.
#
do_test capi2-8.1 {
set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
sqlite_finalize $VM1
} {}
# Tickets #384 and #385 - make sure the TAIL argument to sqlite_compile
# and all of the return pointers in sqlite_step can be null.
#
do_test capi2-9.1 {
set VM1 [sqlite_compile $DB {SELECT * FROM t2}]
sqlite_step $VM1
sqlite_finalize $VM1
} {}
db2 close
finish_test
+57 -26
View File
@@ -13,7 +13,7 @@
# This file implements tests for the conflict resolution extension
# to SQLite.
#
# $Id: conflict.test,v 1.14 2002/08/18 20:28:07 drh Exp $
# $Id: conflict.test,v 1.19 2003/08/05 13:13:39 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -138,7 +138,7 @@ do_test conflict-3.0 {
execsql {
DROP TABLE t1;
DROP TABLE t2;
CREATE TABLE t1(a, b, c INTEGER PRIMARY KEY, UNIQUE(a,b));
CREATE TABLE t1(a, b, c INTEGER, PRIMARY KEY(c), UNIQUE(a,b));
CREATE TABLE t2(x);
SELECT c FROM t1 ORDER BY c;
}
@@ -220,11 +220,15 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
9 FAIL {} {INSERT OR IGNORE} 0 3 1
10 ABORT {} {INSERT OR REPLACE} 0 4 1
11 ROLLBACK {} {INSERT OR IGNORE } 0 3 1
12 REPLACE IGNORE INSERT 0 4 1
13 IGNORE REPLACE INSERT 0 3 1
14 FAIL IGNORE INSERT 1 {} 1
15 ABORT REPLACE INSERT 1 {} 1
16 ROLLBACK IGNORE INSERT 1 {} {}
12 REPLACE IGNORE INSERT 0 3 1
13 IGNORE REPLACE INSERT 0 4 1
14 FAIL IGNORE INSERT 0 3 1
15 ABORT REPLACE INSERT 0 4 1
16 ROLLBACK IGNORE INSERT 0 3 1
12 IGNORE REPLACE INSERT 0 4 1
13 IGNORE FAIL INSERT 1 {} 1
14 IGNORE ABORT INSERT 1 {} 1
15 IGNORE ROLLBACK INSERT 1 {} {}
} {
do_test conflict-4.$i {
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
@@ -285,10 +289,10 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
19 {} FAIL INSERT 1 {} 1
20 {} ABORT INSERT 1 {} 1
21 {} ROLLBACK INSERT 1 {} {}
22 REPLACE FAIL INSERT 0 5 1
23 IGNORE ROLLBACK INSERT 0 {} 1
22 REPLACE FAIL INSERT 1 {} 1
23 IGNORE ROLLBACK INSERT 1 {} {}
} {
if {$t0} {set t1 {constraint failed}}
if {$t0} {set t1 {t1.c may not be NULL}}
do_test conflict-5.$i {
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
@@ -353,10 +357,13 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
19 {} FAIL UPDATE 1 {6 7 3 4} 1
20 {} ABORT UPDATE 1 {1 2 3 4} 1
21 {} ROLLBACK UPDATE 1 {1 2 3 4} 0
22 REPLACE FAIL UPDATE 0 {7 6 9} 1
23 IGNORE ROLLBACK UPDATE 0 {6 7 3 9} 1
22 REPLACE IGNORE UPDATE 0 {6 7 3 9} 1
23 IGNORE REPLACE UPDATE 0 {7 6 9} 1
24 REPLACE FAIL UPDATE 1 {6 7 3 4} 1
25 IGNORE ABORT UPDATE 1 {1 2 3 4} 1
26 REPLACE ROLLBACK UPDATE 1 {1 2 3 4} 0
} {
if {$t0} {set t1 {constraint failed}}
if {$t0} {set t1 {column a is not unique}}
do_test conflict-6.$i {
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
@@ -532,13 +539,13 @@ do_test conflict-9.5 {
INSERT INTO t2 VALUES(3,1,3,3,3);
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column b is not unique}}
do_test conflict-9.6 {
catchsql {
UPDATE t2 SET b=b+1 WHERE b=1;
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column b is not unique}}
do_test conflict-9.7 {
catchsql {
BEGIN;
@@ -546,19 +553,19 @@ do_test conflict-9.7 {
INSERT INTO t2 VALUES(3,1,3,3,3);
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column b is not unique}}
do_test conflict-9.8 {
execsql {COMMIT}
execsql {SELECT * FROM t3}
} {2}
do_test conflict-9.6 {
do_test conflict-9.9 {
catchsql {
BEGIN;
UPDATE t3 SET x=x+1;
UPDATE t2 SET b=b+1 WHERE b=1;
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column b is not unique}}
do_test conflict-9.10 {
execsql {COMMIT}
execsql {SELECT * FROM t3}
@@ -568,13 +575,13 @@ do_test conflict-9.11 {
INSERT INTO t2 VALUES(3,3,3,1,3);
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column d is not unique}}
do_test conflict-9.12 {
catchsql {
UPDATE t2 SET d=d+1 WHERE d=1;
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column d is not unique}}
do_test conflict-9.13 {
catchsql {
BEGIN;
@@ -582,7 +589,7 @@ do_test conflict-9.13 {
INSERT INTO t2 VALUES(3,3,3,1,3);
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column d is not unique}}
do_test conflict-9.14 {
execsql {COMMIT}
execsql {SELECT * FROM t3}
@@ -594,7 +601,7 @@ do_test conflict-9.15 {
UPDATE t2 SET d=d+1 WHERE d=1;
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column d is not unique}}
do_test conflict-9.16 {
execsql {COMMIT}
execsql {SELECT * FROM t3}
@@ -604,13 +611,13 @@ do_test conflict-9.17 {
INSERT INTO t2 VALUES(3,3,3,3,1);
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column e is not unique}}
do_test conflict-9.18 {
catchsql {
UPDATE t2 SET e=e+1 WHERE e=1;
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column e is not unique}}
do_test conflict-9.19 {
catchsql {
BEGIN;
@@ -618,7 +625,7 @@ do_test conflict-9.19 {
INSERT INTO t2 VALUES(3,3,3,3,1);
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column e is not unique}}
do_test conflict-9.20 {
catch {execsql {COMMIT}}
execsql {SELECT * FROM t3}
@@ -630,7 +637,7 @@ do_test conflict-9.21 {
UPDATE t2 SET e=e+1 WHERE e=1;
SELECT * FROM t2;
}
} {1 {constraint failed}}
} {1 {column e is not unique}}
do_test conflict-9.22 {
catch {execsql {COMMIT}}
execsql {SELECT * FROM t3}
@@ -660,4 +667,28 @@ do_test conflict-9.26 {
execsql {SELECT * FROM t3}
} {6}
do_test conflict-10.1 {
catchsql {
DELETE FROM t1;
BEGIN ON CONFLICT ROLLBACK;
INSERT INTO t1 VALUES(1,2);
INSERT INTO t1 VALUES(1,3);
COMMIT;
}
execsql {SELECT * FROM t1}
} {}
do_test conflict-10.2 {
catchsql {
CREATE TABLE t4(x);
CREATE UNIQUE INDEX t4x ON t4(x);
BEGIN ON CONFLICT ROLLBACK;
INSERT INTO t4 VALUES(1);
INSERT INTO t4 VALUES(1);
COMMIT;
}
execsql {SELECT * FROM t4}
} {}
integrity_check conflict-99.0
finish_test
+15 -3
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the COPY statement.
#
# $Id: copy.test,v 1.12 2002/07/30 17:20:41 drh Exp $
# $Id: copy.test,v 1.17 2004/02/17 18:26:57 dougcurrie Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -40,6 +40,7 @@ puts $f "11|22|33"
puts $f "22|33|11"
close $f
set f [open dataX.txt w]
fconfigure $f -translation binary
puts -nonewline $f "11|22|33\r"
puts -nonewline $f "22|33|44\r\n"
puts -nonewline $f "33|44|55\n"
@@ -158,6 +159,17 @@ do_test copy-3.2 {
}
} {1 {hello
world} 2 {hello world}}
do_test copy-3.3 {
set fd [open data6.txt w]
puts $fd "1:hello\\b\\f\\n\\r\\t\\vworld"
puts $fd "2:hello world"
close $fd
execsql {
DELETE FROM t1;
COPY t1 FROM 'data6.txt' USING DELIMITERS ':';
SELECT * FROM t1 ORDER BY a;
}
} [list 1 "hello\b\f\n\r\t\vworld" 2 "hello world"]
# Test the embedded NULL logic.
#
@@ -196,7 +208,7 @@ do_test copy-5.2 {
COPY t1 FROM 'data6.txt' USING DELIMITERS '|';
SELECT * FROM t1;
}
} {1 {constraint failed}}
} {1 {column b is not unique}}
do_test copy-5.3 {
set fd [open data6.txt w]
puts $fd "33|22|44"
@@ -247,7 +259,7 @@ integrity_check copy-7.1
# Cleanup
#
file delete -force data1.txt data2.txt data3.txt data4.txt data5.txt \
#file delete -force data1.txt data2.txt data3.txt data4.txt data5.txt \
data6.txt dataX.txt
finish_test
+96
View File
@@ -0,0 +1,96 @@
/*
** This program tests the ability of SQLite database to recover from a crash.
** This program runs under Unix only, but the results are applicable to all
** systems.
**
** The main process first constructs a test database, then starts creating
** subprocesses that write to that database. Each subprocess is killed off,
** without a chance to clean up its database connection, after a random
** delay. This killing of the subprocesses simulates a crash or power
** failure. The next subprocess to open the database should rollback
** whatever operation was in process at the time of the simulated crash.
**
** If any problems are encountered, an error is reported and the test stops.
** If no problems are seen after a large number of tests, we assume that
** the rollback mechanism is working.
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include "sqlite.h"
static void do_some_sql(int parent){
char *zErr;
int rc = SQLITE_OK;
sqlite *db;
int cnt = 0;
static char zBig[] =
"-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
if( access("./test.db-journal",0)==0 ){
/*printf("pid %d: journal exists. rollback will be required\n",getpid());*/ unlink("test.db-saved");
system("cp test.db test.db-saved");
unlink("test.db-journal-saved");
system("cp test.db-journal test.db-journal-saved");
}
db = sqlite_open("./test.db", 0, &zErr);
if( db==0 ){
printf("ERROR: %s\n", zErr);
if( strcmp(zErr,"database disk image is malformed")==0 ){
kill(parent, SIGKILL);
}
exit(1);
}
srand(getpid());
while( rc==SQLITE_OK ){
cnt++;
rc = sqlite_exec_printf(db,
"INSERT INTO t1 VALUES(%d,'%d%s')", 0, 0, &zErr,
rand(), rand(), zBig);
}
if( rc!=SQLITE_OK ){
printf("ERROR #%d: %s\n", rc, zErr);
if( rc==SQLITE_CORRUPT ){
kill(parent, SIGKILL);
}
}
printf("pid %d: cnt=%d\n", getpid(), cnt);
}
int main(int argc, char **argv){
int i;
sqlite *db;
char *zErr;
int status;
int parent = getpid();
unlink("test.db");
unlink("test.db-journal");
db = sqlite_open("test.db", 0, &zErr);
if( db==0 ){
printf("Cannot initialize: %s\n", zErr);
return 1;
}
sqlite_exec(db, "CREATE TABLE t1(a,b)", 0, 0, 0);
sqlite_close(db);
for(i=0; i<10000; i++){
int pid = fork();
if( pid==0 ){
sched_yield();
do_some_sql(parent);
return 0;
}
printf("test %d, pid=%d\n", i, pid);
usleep(rand()%10000 + 1000);
kill(pid, SIGKILL);
waitpid(pid, &status, 0);
}
return 0;
}
+244
View File
@@ -0,0 +1,244 @@
# 2003 October 31
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this file is testing date and time functions.
#
# $Id: date.test,v 1.7 2004/02/29 01:08:18 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
proc datetest {tnum expr result} {
do_test date-$tnum [subst {
execsql "SELECT coalesce($expr,'NULL')"
}] [list $result]
}
datetest 1.1 julianday('2000-01-01') 2451544.5
datetest 1.2 julianday('1970-01-01') 2440587.5
datetest 1.3 julianday('1910-04-20') 2418781.5
datetest 1.4 julianday('1986-02-09') 2446470.5
datetest 1.5 julianday('12:00:00') 2451545
datetest 1.6 {julianday('2000-01-01 12:00:00')} 2451545
datetest 1.7 {julianday('2000-01-01 12:00')} 2451545
datetest 1.8 julianday('bogus') NULL
datetest 1.9 julianday('1999-12-31') 2451543.5
datetest 1.10 julianday('1999-12-32') NULL
datetest 1.11 julianday('1999-13-01') NULL
datetest 1.12 julianday('2003-02-31') 2452701.5
datetest 1.13 julianday('2003-03-03') 2452701.5
datetest 1.14 julianday('+2000-01-01') NULL
datetest 1.15 julianday('200-01-01') NULL
datetest 1.16 julianday('2000-1-01') NULL
datetest 1.17 julianday('2000-01-1') NULL
datetest 1.18 {julianday('2000-01-01 12:00:00')} 2451545
datetest 1.19 {julianday('2000-01-01 12:00:00.1')} 2451545.00000116
datetest 1.20 {julianday('2000-01-01 12:00:00.01')} 2451545.00000012
datetest 1.21 {julianday('2000-01-01 12:00:00.001')} 2451545.00000001
datetest 1.22 {julianday('2000-01-01 12:00:00.')} NULL
datetest 1.23 julianday(12345.6) 12345.6
datetest 1.24 {julianday('2001-01-01 12:00:00 bogus')} NULL
datetest 1.25 {julianday('2001-01-01 bogus')} NULL
datetest 2.1 datetime(0,'unixepoch') {1970-01-01 00:00:00}
datetest 2.2 datetime(946684800,'unixepoch') {2000-01-01 00:00:00}
datetest 2.3 {date('2003-10-22','weekday 0')} 2003-10-26
datetest 2.4 {date('2003-10-22','weekday 1')} 2003-10-27
datetest 2.5 {date('2003-10-22','weekday 2')} 2003-10-28
datetest 2.6 {date('2003-10-22','weekday 3')} 2003-10-22
datetest 2.7 {date('2003-10-22','weekday 4')} 2003-10-23
datetest 2.8 {date('2003-10-22','weekday 5')} 2003-10-24
datetest 2.9 {date('2003-10-22','weekday 6')} 2003-10-25
datetest 2.10 {date('2003-10-22','weekday 7')} NULL
datetest 2.11 {date('2003-10-22','weekday 5.5')} NULL
datetest 2.12 {datetime('2003-10-22 12:34','weekday 0')} {2003-10-26 12:34:00}
datetest 2.13 {datetime('2003-10-22 12:34','start of month')} \
{2003-10-01 00:00:00}
datetest 2.14 {datetime('2003-10-22 12:34','start of year')} \
{2003-01-01 00:00:00}
datetest 2.15 {datetime('2003-10-22 12:34','start of day')} \
{2003-10-22 00:00:00}
datetest 2.16 time('12:34:56.43') 12:34:56
datetest 2.17 {datetime('2003-10-22 12:34','1 day')} {2003-10-23 12:34:00}
datetest 2.18 {datetime('2003-10-22 12:34','+1 day')} {2003-10-23 12:34:00}
datetest 2.19 {datetime('2003-10-22 12:34','+1.25 day')} {2003-10-23 18:34:00}
datetest 2.20 {datetime('2003-10-22 12:34','-1.0 day')} {2003-10-21 12:34:00}
datetest 2.21 {datetime('2003-10-22 12:34','1 month')} {2003-11-22 12:34:00}
datetest 2.22 {datetime('2003-10-22 12:34','11 month')} {2004-09-22 12:34:00}
datetest 2.23 {datetime('2003-10-22 12:34','-13 month')} {2002-09-22 12:34:00}
datetest 2.24 {datetime('2003-10-22 12:34','1.5 months')} {2003-12-07 12:34:00}
datetest 2.25 {datetime('2003-10-22 12:34','-5 years')} {1998-10-22 12:34:00}
datetest 2.26 {datetime('2003-10-22 12:34','+10.5 minutes')} \
{2003-10-22 12:44:30}
datetest 2.27 {datetime('2003-10-22 12:34','-1.25 hours')} \
{2003-10-22 11:19:00}
datetest 2.28 {datetime('2003-10-22 12:34','11.25 seconds')} \
{2003-10-22 12:34:11}
datetest 2.29 {datetime('2003-10-22 12:24','+5 bogus')} NULL
datetest 3.1 {strftime('%d','2003-10-31 12:34:56.432')} 31
datetest 3.2 {strftime('%f','2003-10-31 12:34:56.432')} 56.432
datetest 3.3 {strftime('%H','2003-10-31 12:34:56.432')} 12
datetest 3.4 {strftime('%j','2003-10-31 12:34:56.432')} 304
datetest 3.5 {strftime('%J','2003-10-31 12:34:56.432')} 2452944.024264259
datetest 3.6 {strftime('%m','2003-10-31 12:34:56.432')} 10
datetest 3.7 {strftime('%M','2003-10-31 12:34:56.432')} 34
datetest 3.8 {strftime('%s','2003-10-31 12:34:56.432')} 1067603696
datetest 3.9 {strftime('%S','2003-10-31 12:34:56.432')} 56
datetest 3.10 {strftime('%w','2003-10-31 12:34:56.432')} 5
datetest 3.11 {strftime('%W','2003-10-31 12:34:56.432')} 44
datetest 3.12 {strftime('%Y','2003-10-31 12:34:56.432')} 2003
datetest 3.13 {strftime('%%','2003-10-31 12:34:56.432')} %
datetest 3.14 {strftime('%_','2003-10-31 12:34:56.432')} NULL
datetest 3.15 {strftime('%Y-%m-%d','2003-10-31')} 2003-10-31
proc repeat {n txt} {
set x {}
while {$n>0} {
append x $txt
incr n -1
}
return $x
}
datetest 3.16 "strftime('[repeat 200 %Y]','2003-10-31')" [repeat 200 2003]
datetest 3.17 "strftime('[repeat 200 abc%m123]','2003-10-31')" \
[repeat 200 abc10123]
set now [clock format [clock seconds] -format "%Y-%m-%d" -gmt 1]
datetest 4.1 {date('now')} $now
datetest 5.1 {datetime('1994-04-16 14:00:00 -05:00')} {1994-04-16 09:00:00}
datetest 5.2 {datetime('1994-04-16 14:00:00 +05:15')} {1994-04-16 19:15:00}
datetest 5.3 {datetime('1994-04-16 05:00:00 -08:30')} {1994-04-15 20:30:00}
datetest 5.4 {datetime('1994-04-16 14:00:00 +11:55')} {1994-04-17 01:55:00}
# localtime->utc and utc->localtime conversions. These tests only work
# if the localtime is in the US Eastern Time (the time in Charlotte, NC
# and in New York.)
#
if {[clock scan [clock format 0 -format {%b %d, %Y %H:%M:%S}] -gmt 1]==-18000} {
datetest 6.1 {datetime('2000-10-29 05:59:00','localtime')}\
{2000-10-29 01:59:00}
datetest 6.2 {datetime('2000-10-29 06:00:00','localtime')}\
{2000-10-29 01:00:00}
datetest 6.3 {datetime('2000-04-02 06:59:00','localtime')}\
{2000-04-02 01:59:00}
datetest 6.4 {datetime('2000-04-02 07:00:00','localtime')}\
{2000-04-02 03:00:00}
datetest 6.5 {datetime('2000-10-29 01:59:00','utc')} {2000-10-29 05:59:00}
datetest 6.6 {datetime('2000-10-29 02:00:00','utc')} {2000-10-29 07:00:00}
datetest 6.7 {datetime('2000-04-02 01:59:00','utc')} {2000-04-02 06:59:00}
datetest 6.8 {datetime('2000-04-02 02:00:00','utc')} {2000-04-02 06:00:00}
datetest 6.10 {datetime('2000-01-01 12:00:00','localtime')} \
{2000-01-01 07:00:00}
datetest 6.11 {datetime('1969-01-01 12:00:00','localtime')} \
{1969-01-01 07:00:00}
datetest 6.12 {datetime('2039-01-01 12:00:00','localtime')} \
{2039-01-01 07:00:00}
datetest 6.13 {datetime('2000-07-01 12:00:00','localtime')} \
{2000-07-01 08:00:00}
datetest 6.14 {datetime('1969-07-01 12:00:00','localtime')} \
{1969-07-01 07:00:00}
datetest 6.15 {datetime('2039-07-01 12:00:00','localtime')} \
{2039-07-01 07:00:00}
set sqlite_current_time \
[db eval {SELECT strftime('%s','2000-07-01 12:34:56')}]
datetest 6.16 {datetime('now','localtime')} {2000-07-01 08:34:56}
set sqlite_current_time 0
}
# Date-time functions that contain NULL arguments return a NULL
# result.
#
datetest 7.1 {datetime(null)} NULL
datetest 7.2 {datetime('now',null)} NULL
datetest 7.3 {datetime('now','localtime',null)} NULL
datetest 7.4 {time(null)} NULL
datetest 7.5 {time('now',null)} NULL
datetest 7.6 {time('now','localtime',null)} NULL
datetest 7.7 {date(null)} NULL
datetest 7.8 {date('now',null)} NULL
datetest 7.9 {date('now','localtime',null)} NULL
datetest 7.10 {julianday(null)} NULL
datetest 7.11 {julianday('now',null)} NULL
datetest 7.12 {julianday('now','localtime',null)} NULL
datetest 7.13 {strftime(null,'now')} NULL
datetest 7.14 {strftime('%s',null)} NULL
datetest 7.15 {strftime('%s','now',null)} NULL
datetest 7.16 {strftime('%s','now','localtime',null)} NULL
# Test modifiers when the date begins as a julian day number - to
# make sure the HH:MM:SS is preserved. Ticket #551.
#
set sqlite_current_time [db eval {SELECT strftime('%s','2003-10-22 12:34:00')}]
datetest 8.1 {datetime('now','weekday 0')} {2003-10-26 12:34:00}
datetest 8.2 {datetime('now','weekday 1')} {2003-10-27 12:34:00}
datetest 8.3 {datetime('now','weekday 2')} {2003-10-28 12:34:00}
datetest 8.4 {datetime('now','weekday 3')} {2003-10-22 12:34:00}
datetest 8.5 {datetime('now','start of month')} {2003-10-01 00:00:00}
datetest 8.6 {datetime('now','start of year')} {2003-01-01 00:00:00}
datetest 8.7 {datetime('now','start of day')} {2003-10-22 00:00:00}
datetest 8.8 {datetime('now','1 day')} {2003-10-23 12:34:00}
datetest 8.9 {datetime('now','+1 day')} {2003-10-23 12:34:00}
datetest 8.10 {datetime('now','+1.25 day')} {2003-10-23 18:34:00}
datetest 8.11 {datetime('now','-1.0 day')} {2003-10-21 12:34:00}
datetest 8.12 {datetime('now','1 month')} {2003-11-22 12:34:00}
datetest 8.13 {datetime('now','11 month')} {2004-09-22 12:34:00}
datetest 8.14 {datetime('now','-13 month')} {2002-09-22 12:34:00}
datetest 8.15 {datetime('now','1.5 months')} {2003-12-07 12:34:00}
datetest 8.16 {datetime('now','-5 years')} {1998-10-22 12:34:00}
datetest 8.17 {datetime('now','+10.5 minutes')} {2003-10-22 12:44:30}
datetest 8.18 {datetime('now','-1.25 hours')} {2003-10-22 11:19:00}
datetest 8.19 {datetime('now','11.25 seconds')} {2003-10-22 12:34:11}
set sqlite_current_time 0
# Negative years work. Example: '-4713-11-26' is JD 1.5.
#
datetest 9.1 {julianday('-4713-11-24 12:00:00')} {0}
datetest 9.2 {julianday(datetime(5))} {5}
datetest 9.3 {julianday(datetime(10))} {10}
datetest 9.4 {julianday(datetime(100))} {100}
datetest 9.5 {julianday(datetime(1000))} {1000}
datetest 9.6 {julianday(datetime(10000))} {10000}
datetest 9.7 {julianday(datetime(100000))} {100000}
# datetime() with just an HH:MM:SS correctly inserts the date 2000-01-01.
#
datetest 10.1 {datetime('01:02:03')} {2000-01-01 01:02:03}
datetest 10.2 {date('01:02:03')} {2000-01-01}
datetest 10.3 {strftime('%Y-%m-%d %H:%M','01:02:03')} {2000-01-01 01:02}
# Test the new HH:MM:SS modifier
#
datetest 11.1 {datetime('2004-02-28 20:00:00', '-01:20:30')} \
{2004-02-28 18:39:30}
datetest 11.2 {datetime('2004-02-28 20:00:00', '+12:30:00')} \
{2004-02-29 08:30:00}
datetest 11.3 {datetime('2004-02-28 20:00:00', '+12:30')} \
{2004-02-29 08:30:00}
datetest 11.4 {datetime('2004-02-28 20:00:00', '12:30')} \
{2004-02-29 08:30:00}
datetest 11.5 {datetime('2004-02-28 20:00:00', '-12:00')} \
{2004-02-28 08:00:00}
datetest 11.6 {datetime('2004-02-28 20:00:00', '-12:01')} \
{2004-02-28 07:59:00}
datetest 11.7 {datetime('2004-02-28 20:00:00', '-11:59')} \
{2004-02-28 08:01:00}
datetest 11.8 {datetime('2004-02-28 20:00:00', '11:59')} \
{2004-02-29 07:59:00}
datetest 11.9 {datetime('2004-02-28 20:00:00', '12:01')} \
{2004-02-29 08:01:00}
finish_test
+47 -1
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the DELETE FROM statement.
#
# $Id: delete.test,v 1.11 2002/07/19 18:52:41 drh Exp $
# $Id: delete.test,v 1.13 2003/06/15 23:42:25 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -60,6 +60,8 @@ do_test delete-3.1.6 {
do_test delete-3.1.7 {
execsql {SELECT * FROM table1 ORDER BY f1}
} {1 2 4 16}
integrity_check delete-3.2
# Semantic errors in the WHERE clause
#
@@ -73,6 +75,7 @@ do_test delete-4.2 {
set v [catch {execsql {DELETE FROM table2 WHERE xyzzy(f1+4)}} msg]
lappend v $msg
} {1 {no such function: xyzzy}}
integrity_check delete-4.3
# Lots of deletes
#
@@ -142,6 +145,8 @@ do_test delete-5.7 {
execsql "DELETE FROM table1 WHERE f1!=48"
execsql {SELECT f1 FROM table1 ORDER BY f1}
} {48}
integrity_check delete-5.8
# Delete large quantities of data. We want to test the List overflow
# mechanism in the vdbe.
@@ -192,6 +197,7 @@ do_test delete-6.10 {
execsql {INSERT INTO table2 VALUES(2,3)}
execsql {SELECT f1 FROM table2}
} {2}
integrity_check delete-6.11
do_test delete-7.1 {
execsql {
@@ -240,6 +246,46 @@ do_test delete-7.6 {
DELETE FROM t4;
}
} {4 4}
integrity_check delete-7.7
# Make sure error messages are consistent when attempting to delete
# from a read-only database. Ticket #304.
#
do_test delete-8.0 {
execsql {
PRAGMA count_changes=OFF;
INSERT INTO t3 VALUES(123);
SELECT * FROM t3;
}
} {123}
db close
catch {file attributes test.db -permissions 0444}
catch {file attributes test.db -readonly 1}
sqlite db test.db
do_test delete-8.1 {
catchsql {
DELETE FROM t3;
}
} {1 {attempt to write a readonly database}}
do_test delete-8.2 {
execsql {SELECT * FROM t3}
} {123}
do_test delete-8.3 {
catchsql {
DELETE FROM t3 WHERE 1;
}
} {1 {attempt to write a readonly database}}
do_test delete-8.4 {
execsql {SELECT * FROM t3}
} {123}
do_test delete-8.5 {
catchsql {
DELETE FROM t3 WHERE a<100;
}
} {0 {}}
do_test delete-8.6 {
execsql {SELECT * FROM t3}
} {123}
integrity_check delete-8.7
finish_test
+47 -3
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing expressions.
#
# $Id: expr.test,v 1.27 2002/08/15 01:26:11 drh Exp $
# $Id: expr.test,v 1.31 2004/03/03 01:51:25 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -68,7 +68,9 @@ test_expr expr-1.39 {i1=1} {+i1} {1}
test_expr expr-1.40 {i1=1, i2=2} {+(i2+i1)} {3}
test_expr expr-1.41 {i1=1, i2=2} {-(i2+i1)} {-3}
test_expr expr-1.42 {i1=1, i2=2} {i1|i2} {3}
test_expr expr-1.42b {i1=1, i2=2} {4|2} {6}
test_expr expr-1.43 {i1=1, i2=2} {i1&i2} {0}
test_expr expr-1.43b {i1=1, i2=2} {4&5} {4}
test_expr expr-1.44 {i1=1} {~i1} {-2}
test_expr expr-1.45 {i1=1, i2=3} {i1<<i2} {8}
test_expr expr-1.46 {i1=32, i2=3} {i1>>i2} {4}
@@ -126,6 +128,8 @@ test_expr expr-1.96 {i1=NULL, i2=3} {coalesce(i1<<i2,99)} 99
test_expr expr-1.97 {i1=32, i2=NULL} {coalesce(i1>>i2,99)} 99
test_expr expr-1.98 {i1=NULL, i2=NULL} {coalesce(i1|i2,99)} 99
test_expr expr-1.99 {i1=32, i2=NULL} {coalesce(i1&i2,99)} 99
test_expr expr-1.100 {i1=1, i2=''} {i1=i2} 0
test_expr expr-1.101 {i1=0, i2=''} {i1=i2} 0
test_expr expr-2.1 {r1=1.23, r2=2.34} {r1+r2} 3.57
test_expr expr-2.2 {r1=1.23, r2=2.34} {r1-r2} -1.11
@@ -299,8 +303,12 @@ test_expr expr-6.17 {t1='abc', t2='a[A-Dc]c'} {t1 GLOB t2} 0
test_expr expr-6.18 {t1='abc', t2='a[^A-Dc]c'} {t1 GLOB t2} 1
test_expr expr-6.19 {t1='abc', t2='a[]b]c'} {t1 GLOB t2} 1
test_expr expr-6.20 {t1='abc', t2='a[^]b]c'} {t1 GLOB t2} 0
test_expr expr-6.21 {t1='abcdefg', t2='a*[de]g'} {t1 GLOB t2} 0
test_expr expr-6.22 {t1='abcdefg', t2='a*[^de]g'} {t1 GLOB t2} 1
test_expr expr-6.21a {t1='abcdefg', t2='a*[de]g'} {t1 GLOB t2} 0
test_expr expr-6.21b {t1='abcdefg', t2='a*[df]g'} {t1 GLOB t2} 1
test_expr expr-6.21c {t1='abcdefg', t2='a*[d-h]g'} {t1 GLOB t2} 1
test_expr expr-6.21d {t1='abcdefg', t2='a*[b-e]g'} {t1 GLOB t2} 0
test_expr expr-6.22a {t1='abcdefg', t2='a*[^de]g'} {t1 GLOB t2} 1
test_expr expr-6.22b {t1='abcdefg', t2='a*[^def]g'} {t1 GLOB t2} 0
test_expr expr-6.23 {t1='abcdefg', t2='a*?g'} {t1 GLOB t2} 1
test_expr expr-6.24 {t1='ac', t2='a*c'} {t1 GLOB t2} 1
test_expr expr-6.25 {t1='ac', t2='a*?c'} {t1 GLOB t2} 0
@@ -327,6 +335,35 @@ if {"\u1234"!="u1234" && [sqlite -encoding]=="UTF-8"} {
test_expr expr-6.41 "t1='a\u1234b', t2='a\[a-\u1233\]b'" {t1 GLOB t2} 0
}
test_expr expr-6.51 {t1='ABC', t2='xyz'} {t1 GLOB t2} 0
test_expr expr-6.52 {t1='ABC', t2='abc'} {t1 GLOB t2} 0
test_expr expr-6.53 {t1='ABC', t2='a?c'} {t1 GLOB t2} 0
test_expr expr-6.54 {t1='ABC', t2='A?C'} {t1 GLOB t2} 1
test_expr expr-6.55 {t1='ABC', t2='abc?'} {t1 GLOB t2} 0
test_expr expr-6.56 {t1='ABC', t2='a*c'} {t1 GLOB t2} 0
test_expr expr-6.57 {t1='ABC', t2='A*C'} {t1 GLOB t2} 1
test_expr expr-6.58 {t1='ABxyzzyC', t2='A*C'} {t1 GLOB t2} 1
test_expr expr-6.59 {t1='ABxyzzy', t2='A*C'} {t1 GLOB t2} 0
test_expr expr-6.60 {t1='ABxyzzyCx', t2='A*C'} {t1 GLOB t2} 0
test_expr expr-6.61 {t1='ABC', t2='xyz'} {t1 NOT GLOB t2} 1
test_expr expr-6.62 {t1='ABC', t2='ABC'} {t1 NOT GLOB t2} 0
test_expr expr-6.63 {t1='ABC', t2='A[Bx]C'} {t1 GLOB t2} 1
test_expr expr-6.64 {t1='ABC', t2='A[Cx]C'} {t1 GLOB t2} 0
test_expr expr-6.65 {t1='ABC', t2='A[A-D]C'} {t1 GLOB t2} 1
test_expr expr-6.66 {t1='ABC', t2='A[^A-D]C'} {t1 GLOB t2} 0
test_expr expr-6.67 {t1='ABC', t2='A[a-dC]C'} {t1 GLOB t2} 0
test_expr expr-6.68 {t1='ABC', t2='A[^a-dC]C'} {t1 GLOB t2} 1
test_expr expr-6.69a {t1='ABC', t2='A[]B]C'} {t1 GLOB t2} 1
test_expr expr-6.69b {t1='A]C', t2='A[]B]C'} {t1 GLOB t2} 1
test_expr expr-6.70a {t1='ABC', t2='A[^]B]C'} {t1 GLOB t2} 0
test_expr expr-6.70b {t1='AxC', t2='A[^]B]C'} {t1 GLOB t2} 1
test_expr expr-6.70c {t1='A]C', t2='A[^]B]C'} {t1 GLOB t2} 0
test_expr expr-6.71 {t1='ABCDEFG', t2='A*[DE]G'} {t1 GLOB t2} 0
test_expr expr-6.72 {t1='ABCDEFG', t2='A*[^DE]G'} {t1 GLOB t2} 1
test_expr expr-6.73 {t1='ABCDEFG', t2='A*?G'} {t1 GLOB t2} 1
test_expr expr-6.74 {t1='AC', t2='A*C'} {t1 GLOB t2} 1
test_expr expr-6.75 {t1='AC', t2='A*?C'} {t1 GLOB t2} 0
# Theses tests are for when SQLite assumes iso8859 characters.
#
if {[sqlite -encoding]=="iso8859"} {
@@ -472,4 +509,11 @@ test_expr2 expr-7.57 {((a>0 IS NULL OR 0) AND 1) OR 0} {{}}
test_expr2 expr-7.58 {(a||'')<='1'} {1}
test_expr2 expr-7.59 {LIKE('10%',b)} {10 20}
test_expr2 expr-7.60 {LIKE('_4',b)} {6}
test_expr2 expr-7.61 {GLOB('1?',a)} {10 11 12 13 14 15 16 17 18 19}
test_expr2 expr-7.62 {GLOB('1*4',b)} {10 14}
test_expr2 expr-7.63 {GLOB('*1[456]',b)} {4}
finish_test
+10 -1
View File
@@ -38,7 +38,16 @@ do_test fkey1-1.1 {
);
}
} {}
do_test fkey1-1.2 {
execsql {
CREATE TABLE t3(
a INTEGER REFERENCES t2,
b INTEGER REFERENCES t1,
FOREIGN KEY (a,b) REFERENCES t2(x,y)
);
}
} {}
finish_test
+24 -2
View File
@@ -12,7 +12,7 @@
# focus of this file is testing the the library is able to correctly
# handle file-format 3 (version 2.6.x) databases.
#
# $Id: format3.test,v 1.1 2002/08/31 16:52:45 drh Exp $
# $Id: format3.test,v 1.4 2003/12/23 02:17:35 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -638,6 +638,11 @@ do_test format3-10.13 {
cksort {
SELECT * FROM t3 WHERE a>0 ORDER BY a DESC LIMIT 3
}
} {100 1 10201 99 2 10000 98 3 9801 nosort}
do_test format3-10.13.1 {
cksort {
SELECT * FROM t3 WHERE a>0 ORDER BY a+1 DESC LIMIT 3
}
} {100 1 10201 99 2 10000 98 3 9801 sort}
do_test format3-10.14 {
cksort {
@@ -681,7 +686,7 @@ do_test format3-11.2 {
execsql {SELECT '0'==0.0}
} {1}
do_test format3-11.3 {
execsql {SELECT '12345678901234567890'=='12345678901234567891'}
execsql {SELECT '123456789012345678901'=='123456789012345678900'}
} {1}
do_test format3-11.4 {
execsql {
@@ -713,4 +718,21 @@ do_test format3-11.7 {
}
} {0 0}
# Make sure attempts to attach a format 3 database fail.
#
do_test format3-12.1 {
file delete -force test2.db
sqlite db2 test2.db
catchsql {
CREATE TABLE t8(x,y);
ATTACH DATABASE 'test.db' AS format3;
} db2;
} {1 {incompatible file format in auxiliary database: format3}}
do_test format3-12.2 {
catchsql {
ATTACH DATABASE 'test2.db' AS test2;
}
} {1 {cannot attach auxiliary databases to an older format master database}}
db2 close
finish_test
+9 -1
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing built-in functions.
#
# $Id: func.test,v 1.15 2002/08/13 23:02:58 drh Exp $
# $Id: func.test,v 1.16 2002/11/04 19:32:26 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -329,4 +329,12 @@ do_test func-10.5 {
}
} {1.234}
# Test the built-in sqlite_version(*) SQL function.
#
do_test func-11.1 {
execsql {
SELECT sqlite_version(*);
}
} [sqlite -version]
finish_test
+83
View File
@@ -0,0 +1,83 @@
# 2004 Jan 14
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for TCL interface to the
# SQLite library.
#
# The focus of the tests in this file is the following interface:
#
# sqlite_commit_hook
#
# $Id: hook.test,v 1.3 2004/01/15 02:44:03 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test hook-1.2 {
db commit_hook
} {}
do_test hook-3.1 {
set commit_cnt 0
proc commit_hook {} {
incr ::commit_cnt
return 0
}
db commit_hook ::commit_hook
db commit_hook
} {::commit_hook}
do_test hook-3.2 {
set commit_cnt
} {0}
do_test hook-3.3 {
execsql {
CREATE TABLE t2(a,b);
}
set commit_cnt
} {1}
do_test hook-3.4 {
execsql {
INSERT INTO t2 VALUES(1,2);
INSERT INTO t2 SELECT a+1, b+1 FROM t2;
INSERT INTO t2 SELECT a+2, b+2 FROM t2;
}
set commit_cnt
} {4}
do_test hook-3.5 {
set commit_cnt {}
proc commit_hook {} {
set ::commit_cnt [execsql {SELECT * FROM t2}]
return 0
}
execsql {
INSERT INTO t2 VALUES(5,6);
}
set commit_cnt
} {1 2 2 3 3 4 4 5 5 6}
do_test hook-3.6 {
set commit_cnt {}
proc commit_hook {} {
set ::commit_cnt [execsql {SELECT * FROM t2}]
return 1
}
catchsql {
INSERT INTO t2 VALUES(6,7);
}
} {1 {constraint failed}}
do_test hook-3.7 {
set commit_cnt
} {1 2 2 3 3 4 4 5 5 6 6 7}
do_test hook-3.8 {
execsql {SELECT * FROM t2}
} {1 2 2 3 3 4 4 5 5 6}
finish_test
+76 -3
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the IN and BETWEEN operator.
#
# $Id: in.test,v 1.7 2002/07/01 00:31:36 drh Exp $
# $Id: in.test,v 1.11 2004/01/15 03:30:25 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -84,9 +84,9 @@ do_test in-2.8 {
execsql {SELECT a FROM t1 WHERE b IN (8*2,64/2) ORDER BY b}
} {4 5}
do_test in-2.9 {
set v [catch {execsql {SELECT a FROM t1 WHERE b IN (xyz(5,10),20)}} msg]
set v [catch {execsql {SELECT a FROM t1 WHERE b IN (max(5,10),20)}} msg]
lappend v $msg
} {1 {no such function: xyz}}
} {1 {right-hand side of IN operator must be constant}}
do_test in-2.10 {
set v [catch {execsql {SELECT a FROM t1 WHERE min(0,b IN (a,30))}} msg]
lappend v $msg
@@ -227,4 +227,77 @@ do_test in-6.10 {
}
} {4 6 8 10}
# Tests of IN operator against empty sets. (Ticket #185)
#
do_test in-7.1 {
execsql {
SELECT a FROM t1 WHERE a IN ();
}
} {}
do_test in-7.2 {
execsql {
SELECT a FROM t1 WHERE a IN (5);
}
} {5}
do_test in-7.3 {
execsql {
SELECT a FROM t1 WHERE a NOT IN () ORDER BY a;
}
} {5 6 7 8 hello}
do_test in-7.4 {
execsql {
SELECT a FROM t1 WHERE a IN (5) AND b IN ();
}
} {}
do_test in-7.5 {
execsql {
SELECT a FROM t1 WHERE a IN (5) AND b NOT IN ();
}
} {5}
do_test in-7.6 {
execsql {
SELECT a FROM ta WHERE a IN ();
}
} {}
do_test in-7.7 {
execsql {
SELECT a FROM ta WHERE a NOT IN ();
}
} {1 2 3 4 6 8 10}
do_test in-8.1 {
execsql {
SELECT b FROM t1 WHERE a IN ('hello','there')
}
} {world}
do_test in-8.2 {
execsql {
SELECT b FROM t1 WHERE a IN ("hello",'there')
}
} {world}
# Test constructs of the form: expr IN tablename
#
do_test in-9.1 {
execsql {
CREATE TABLE t4 AS SELECT a FROM tb;
SELECT * FROM t4;
}
} {1 2 3 5 7 9 11}
do_test in-9.2 {
execsql {
SELECT b FROM t1 WHERE a IN t4;
}
} {32 128}
do_test in-9.3 {
execsql {
SELECT b FROM t1 WHERE a NOT IN t4;
}
} {64 256 world}
do_test in-9.4 {
catchsql {
SELECT b FROM t1 WHERE a NOT IN tb;
}
} {1 {only a single result allowed for a SELECT that is part of an expression}}
finish_test
+40 -6
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the CREATE INDEX statement.
#
# $Id: index.test,v 1.20 2002/08/13 23:02:58 drh Exp $
# $Id: index.test,v 1.24 2003/09/27 00:41:28 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -154,13 +154,14 @@ do_test index-4.13 {
execsql {DROP TABLE test1}
execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name}
} {}
integrity_check index-4.14
# Do not allow indices to be added to sqlite_master
#
do_test index-5.1 {
set v [catch {execsql {CREATE INDEX index1 ON sqlite_master(name)}} msg]
lappend v $msg
} {1 {table sqlite_master may not have new indices added}}
} {1 {table sqlite_master may not be indexed}}
do_test index-5.2 {
execsql {SELECT name FROM sqlite_master WHERE type!='meta'}
} {}
@@ -199,6 +200,8 @@ do_test index-6.4 {
SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name;
}
} {}
integrity_check index-6.5
# Create a primary key
#
@@ -222,6 +225,7 @@ do_test index-7.4 {
execsql {DROP table test1}
execsql {SELECT name FROM sqlite_master WHERE type!='meta'}
} {}
integrity_check index-7.5
# Make sure we cannot drop a non-existant index.
#
@@ -242,6 +246,7 @@ do_test index-9.2 {
execsql {CREATE INDEX idx1 ON tab1(a)}
execsql {SELECT name FROM sqlite_master WHERE tbl_name='tab1' ORDER BY name}
} {idx1 tab1}
integrity_check index-9.3
# Allow more than one entry with the same key.
#
@@ -312,6 +317,7 @@ do_test index-10.8 {
SELECT b FROM t1 ORDER BY b;
}
} {0}
integrity_check index-10.9
# Automatically create an index when we specify a primary key.
#
@@ -330,6 +336,8 @@ do_test index-11.1 {
set sqlite_search_count 0
concat [execsql {SELECT c FROM t3 WHERE b==10}] $sqlite_search_count
} {0.10 3}
integrity_check index-11.2
# Numeric strings should compare as if they were numbers. So even if the
# strings are not character-by-character the same, if they represent the
@@ -380,6 +388,7 @@ do_test index-12.7 {
SELECT a FROM t4 WHERE a>-0.5 ORDER BY b
}
} {0.0 0.00 abc +1.0 0 00000}
integrity_check index-12.8
# Make sure we cannot drop an automatically created index.
#
@@ -414,6 +423,7 @@ do_test index-13.4 {
SELECT * FROM t5;
}
} {1 2 3 a b c}
integrity_check index-13.5
# Check the sort order of data in an index.
#
@@ -463,22 +473,46 @@ do_test index-14.8 {
execsql {
SELECT c FROM t6 WHERE a<'abc';
}
} {3 5 2 1}
} {5 2 1}
do_test index-14.9 {
execsql {
SELECT c FROM t6 WHERE a<='abc';
}
} {3 5 2 1 4}
} {5 2 1 4}
do_test index-14.10 {
execsql {
SELECT c FROM t6 WHERE a<='';
}
} {3 5 2 1}
} {5 2 1}
do_test index-14.11 {
execsql {
SELECT c FROM t6 WHERE a<'';
}
} {3 5}
} {5}
integrity_check index-14.12
do_test index-15.1 {
execsql {
DELETE FROM t1;
SELECT * FROM t1;
}
} {}
do_test index-15.2 {
execsql {
INSERT INTO t1 VALUES('1.234e5',1);
INSERT INTO t1 VALUES('12.33e04',2);
INSERT INTO t1 VALUES('12.35E4',3);
INSERT INTO t1 VALUES('12.34e',4);
INSERT INTO t1 VALUES('12.32e+4',5);
INSERT INTO t1 VALUES('12.36E+04',6);
INSERT INTO t1 VALUES('12.36E+',7);
INSERT INTO t1 VALUES('+123.10000E+0003',8);
INSERT INTO t1 VALUES('+',9);
INSERT INTO t1 VALUES('+12347.E+02',10);
INSERT INTO t1 VALUES('+12347E+02',11);
SELECT b FROM t1 ORDER BY a;
}
} {8 5 2 1 3 6 11 9 10 4 7}
integrity_check index-15.1
finish_test
+81 -2
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the INSERT statement.
#
# $Id: insert.test,v 1.11 2002/06/25 13:16:04 drh Exp $
# $Id: insert.test,v 1.15 2003/06/15 23:42:25 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -202,6 +202,85 @@ do_test insert-4.7 {
}
} {1 3 99}
# Test
# Test the ability to insert from a temporary table into itself.
# Ticket #275.
#
do_test insert-5.1 {
execsql {
CREATE TEMP TABLE t4(x);
INSERT INTO t4 VALUES(1);
SELECT * FROM t4;
}
} {1}
do_test insert-5.2 {
execsql {
INSERT INTO t4 SELECT x+1 FROM t4;
SELECT * FROM t4;
}
} {1 2}
do_test insert-5.3 {
# verify that a temporary table is used to copy t4 to t4
set x [execsql {
EXPLAIN INSERT INTO t4 SELECT x+2 FROM t4;
}]
expr {[lsearch $x OpenTemp]>0}
} {1}
do_test insert-5.4 {
# Verify that table "test1" begins on page 3. This should be the same
# page number used by "t4" above.
execsql {
SELECT rootpage FROM sqlite_master WHERE name='test1';
}
} {3}
do_test insert-5.5 {
# Verify that "t4" begins on page 3.
execsql {
SELECT rootpage FROM sqlite_temp_master WHERE name='t4';
}
} {3}
do_test insert-5.6 {
# This should not use an intermediate temporary table.
execsql {
INSERT INTO t4 SELECT one FROM test1 WHERE three=7;
SELECT * FROM t4
}
} {1 2 8}
do_test insert-5.7 {
# verify that no temporary table is used to copy test1 to t4
set x [execsql {
EXPLAIN INSERT INTO t4 SELECT one FROM test1;
}]
expr {[lsearch $x OpenTemp]>0}
} {0}
# Ticket #334: REPLACE statement corrupting indices.
#
do_test insert-6.1 {
execsql {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE);
INSERT INTO t1 VALUES(1,2);
INSERT INTO t1 VALUES(2,3);
SELECT b FROM t1 WHERE b=2;
}
} {2}
do_test insert-6.2 {
execsql {
REPLACE INTO t1 VALUES(1,4);
SELECT b FROM t1 WHERE b=2;
}
} {}
do_test insert-6.3 {
execsql {
UPDATE OR REPLACE t1 SET a=2 WHERE b=4;
SELECT * FROM t1 WHERE b=4;
}
} {2 4}
do_test insert-6.4 {
execsql {
SELECT * FROM t1 WHERE b=3;
}
} {}
integrity_check insert-99.0
finish_test
+167
View File
@@ -0,0 +1,167 @@
# 2004 Feb 8
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is the sqlite_interrupt() API.
#
# $Id: interrupt.test,v 1.4.2.1 2004/05/10 20:27:42 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Compute a checksum on the entire database.
#
proc cksum {{db db}} {
set txt [$db eval {SELECT name, type, sql FROM sqlite_master}]\n
foreach tbl [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
append txt [$db eval "SELECT * FROM $tbl"]\n
}
foreach prag {default_synchronous default_cache_size} {
append txt $prag-[$db eval "PRAGMA $prag"]\n
}
set cksum [string length $txt]-[md5 $txt]
# puts $cksum-[file size test.db]
return $cksum
}
# This routine attempts to execute the sql in $sql. It triggers an
# interrupt a progressively later and later points during the processing
# and checks to make sure SQLITE_INTERRUPT is returned. Eventually,
# the routine completes successfully.
#
proc interrupt_test {testid sql result {initcnt 0} {maxcnt 1000000}} {
set orig_sum [cksum]
set i $initcnt
global sqlite_interrupt_count
while {$i<$maxcnt} {
incr i
set sqlite_interrupt_count $i
do_test $testid.$i.1 [format {
set ::r [catchsql %s]
set ::code [db errorcode]
expr {$::code==0 || $::code==9}
} [list $sql]] 1
if {$::code==9} {
do_test $testid.$i.2 {
cksum
} $orig_sum
} elseif {$sqlite_interrupt_count>0} {
do_test $testid.$i.99 {
set ::r
} [list 0 $result]
break
}
}
set sqlite_interrupt_count 0
}
do_test interrupt-1.1 {
execsql {
CREATE TABLE t1(a,b);
SELECT name FROM sqlite_master;
}
} {t1}
interrupt_test interrupt-1.2 {DROP TABLE t1} {} 1 14
do_test interrupt-1.3 {
execsql {
SELECT name FROM sqlite_master;
}
} {}
integrity_check interrupt-1.4
do_test interrrupt-2.1 {
execsql {
BEGIN;
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,randstr(300,400));
INSERT INTO t1 SELECT a+1, randstr(300,400) FROM t1;
INSERT INTO t1 SELECT a+2, a || '-' || b FROM t1;
INSERT INTO t1 SELECT a+4, a || '-' || b FROM t1;
INSERT INTO t1 SELECT a+8, a || '-' || b FROM t1;
INSERT INTO t1 SELECT a+16, a || '-' || b FROM t1;
INSERT INTO t1 SELECT a+32, a || '-' || b FROM t1;
COMMIT;
UPDATE t1 SET b=substr(b,-5,5);
SELECT count(*) from t1;
}
} 64
set origsize [file size test.db]
set cksum [db eval {SELECT md5sum(a || b) FROM t1}]
interrupt_test interrupt-2.2 {VACUUM} {} 100
do_test interrupt-2.3 {
execsql {
SELECT md5sum(a || b) FROM t1;
}
} $cksum
do_test interrupt-2.4 {
expr {$::origsize>[file size test.db]}
} 1
integrity_check interrupt-2.5
# Ticket #594. If an interrupt occurs in the middle of a transaction
# and that transaction is later rolled back, the internal schema tables do
# not reset.
#
for {set i 1} {$i<50} {incr i 5} {
do_test interrupt-3.$i.1 {
execsql {
BEGIN;
CREATE TEMP TABLE t2(x,y);
SELECT name FROM sqlite_temp_master;
}
} {t2}
do_test interrupt-3.$i.2 {
set ::sqlite_interrupt_count $::i
catchsql {
INSERT INTO t2 SELECT * FROM t1;
}
} {1 interrupted}
do_test interrupt-3.$i.3 {
execsql {
SELECT name FROM sqlite_temp_master;
}
} {t2}
do_test interrupt-3.$i.4 {
catchsql {
ROLLBACK
}
} {0 {}}
do_test interrupt-3.$i.5 {
catchsql {SELECT name FROM sqlite_temp_master};
execsql {
SELECT name FROM sqlite_temp_master;
}
} {}
}
# There are reports of a memory leak if an interrupt occurs during
# the beginning of a complex query - before the first callback. We
# will try to reproduce it here:
#
execsql {
CREATE TABLE t2(a,b,c);
INSERT INTO t2 SELECT round(a/10), randstr(50,80), randstr(50,60) FROM t1;
}
set sql {
SELECT max(min(b,c)), min(max(b,c)), a FROM t2 GROUP BY a ORDER BY a;
}
set sqlite_interrupt_count 1000000
execsql $sql
set max_count [expr {1000000-$sqlite_interrupt_count}]
for {set i 1} {$i<$max_count-5} {incr i 1} {
do_test interrupt-4.$i.1 {
set ::sqlite_interrupt_count $::i
catchsql $sql
} {1 interrupted}
}
finish_test
+11 -3
View File
@@ -13,7 +13,7 @@
# This file implements tests for the special processing associated
# with INTEGER PRIMARY KEY columns.
#
# $Id: intpkey.test,v 1.11 2002/08/15 01:26:11 drh Exp $
# $Id: intpkey.test,v 1.14 2003/06/15 23:42:25 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -76,7 +76,7 @@ do_test intpkey-1.6 {
INSERT INTO t1 VALUES(5,'second','entry');
}} msg]
lappend r $msg
} {1 {constraint failed}}
} {1 {PRIMARY KEY must be unique}}
do_test intpkey-1.7 {
execsql {
SELECT rowid, * FROM t1;
@@ -128,12 +128,18 @@ do_test intpkey-1.12 {
# Try to insert a non-integer value into the primary key field. This
# should result in a data type mismatch.
#
do_test intpkey-1.13 {
do_test intpkey-1.13.1 {
set r [catch {execsql {
INSERT INTO t1 VALUES('x','y','z');
}} msg]
lappend r $msg
} {1 {datatype mismatch}}
do_test intpkey-1.13.2 {
set r [catch {execsql {
INSERT INTO t1 VALUES('','y','z');
}} msg]
lappend r $msg
} {1 {datatype mismatch}}
do_test intpkey-1.14 {
set r [catch {execsql {
INSERT INTO t1 VALUES(3.4,'y','z');
@@ -476,4 +482,6 @@ do_test intpkey-11.1 {
}
} {}
integrity_check intpkey-12.1
finish_test
+62 -1
View File
@@ -15,7 +15,7 @@
# The tests in this file use special facilities that are only
# available in the SQLite test fixture.
#
# $Id: ioerr.test,v 1.1 2001/10/12 17:30:05 drh Exp $
# $Id: ioerr.test,v 1.3 2003/04/25 15:37:59 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -26,6 +26,7 @@ for {set n 1} {$go} {incr n} {
set ::sqlite_io_error_pending 0
db close
catch {file delete -force test.db}
catch {file delete -force test.db-journal}
sqlite db test.db
execsql {SELECT * FROM sqlite_master}
} {}
@@ -55,5 +56,65 @@ for {set n 1} {$go} {incr n} {
}
set ::sqlite_io_error_pending 0
proc cksum {{db db}} {
set txt [$db eval {SELECT name, type, sql FROM sqlite_master}]\n
foreach tbl [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
append txt [$db eval "SELECT * FROM $tbl"]\n
}
foreach prag {default_synchronous default_cache_size} {
append txt $prag-[$db eval "PRAGMA $prag"]\n
}
set cksum [string length $txt]-[md5 $txt]
# puts $cksum-[file size test.db]
return $cksum
}
set ::go 1
for {set n 1} {$go} {incr n} {
do_test ioerr-2.$n.1 {
set ::sqlite_io_error_pending 0
db close
catch {file delete -force test.db}
catch {file delete -force test.db-journal}
sqlite db test.db
execsql {
BEGIN;
CREATE TABLE t1(a, b, c);
INSERT INTO t1 VALUES(1, randstr(5,50), randstr(5,50));
INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1;
INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;
INSERT INTO t1 SELECT a+8, b||'-'||rowid, c||'-'||rowid FROM t1;
INSERT INTO t1 SELECT a+16, b||'-'||rowid, c||'-'||rowid FROM t1;
INSERT INTO t1 SELECT a+32, b||'-'||rowid, c||'-'||rowid FROM t1;
INSERT INTO t1 SELECT a+64, b||'-'||rowid, c||'-'||rowid FROM t1;
INSERT INTO t1 SELECT a+128, b||'-'||rowid, c||'-'||rowid FROM t1;
CREATE TABLE t2 AS SELECT * FROM t1;
CREATE TABLE t3 AS SELECT * FROM t1;
COMMIT;
DROP TABLE t2;
}
set ::cksum [cksum]
execsql {
SELECT name FROM sqlite_master WHERE type='table'
}
} {t1 t3}
do_test ioerr-2.$n.2 [subst {
set ::sqlite_io_error_pending $n
}] $n
do_test ioerr-2.$n.3 {
set r [catch {db eval {
VACUUM;
}} msg]
# puts "error_pending=$::sqlite_io_error_pending"
# if {$r} {puts $msg}
set ::go [expr {$::sqlite_io_error_pending<=0}]
expr {$::sqlite_io_error_pending>0 || $r!=0}
set ::sqlite_io_error_pending 0
db close
sqlite db test.db
cksum
} $cksum
}
set ::sqlite_io_error_pending 0
finish_test
+107 -1
View File
@@ -12,7 +12,7 @@
#
# This file implements tests for joins, including outer joins.
#
# $Id: join.test,v 1.5 2002/07/31 19:50:28 drh Exp $
# $Id: join.test,v 1.11 2003/09/27 13:39:40 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -283,5 +283,111 @@ do_test join-4.10 {
}
} {}
do_test join-5.1 {
execsql {
BEGIN;
create table centros (id integer primary key, centro);
INSERT INTO centros VALUES(1,'xxx');
create table usuarios (id integer primary key, nombre, apellidos,
idcentro integer);
INSERT INTO usuarios VALUES(1,'a','aa',1);
INSERT INTO usuarios VALUES(2,'b','bb',1);
INSERT INTO usuarios VALUES(3,'c','cc',NULL);
create index idcentro on usuarios (idcentro);
END;
select usuarios.id, usuarios.nombre, centros.centro from
usuarios left outer join centros on usuarios.idcentro = centros.id;
}
} {1 a xxx 2 b xxx 3 c {}}
# A test for ticket #247.
#
do_test join-7.1 {
execsql {
CREATE TABLE t7 (x, y);
INSERT INTO t7 VALUES ("pa1", 1);
INSERT INTO t7 VALUES ("pa2", NULL);
INSERT INTO t7 VALUES ("pa3", NULL);
INSERT INTO t7 VALUES ("pa4", 2);
INSERT INTO t7 VALUES ("pa30", 131);
INSERT INTO t7 VALUES ("pa31", 130);
INSERT INTO t7 VALUES ("pa28", NULL);
CREATE TABLE t8 (a integer primary key, b);
INSERT INTO t8 VALUES (1, "pa1");
INSERT INTO t8 VALUES (2, "pa4");
INSERT INTO t8 VALUES (3, NULL);
INSERT INTO t8 VALUES (4, NULL);
INSERT INTO t8 VALUES (130, "pa31");
INSERT INTO t8 VALUES (131, "pa30");
SELECT coalesce(t8.a,999) from t7 LEFT JOIN t8 on y=a;
}
} {1 999 999 2 131 130 999}
# Make sure a left join where the right table is really a view that
# is itself a join works right. Ticket #306.
#
do_test join-8.1 {
execsql {
BEGIN;
CREATE TABLE t9(a INTEGER PRIMARY KEY, b);
INSERT INTO t9 VALUES(1,11);
INSERT INTO t9 VALUES(2,22);
CREATE TABLE t10(x INTEGER PRIMARY KEY, y);
INSERT INTO t10 VALUES(1,2);
INSERT INTO t10 VALUES(3,3);
CREATE TABLE t11(p INTEGER PRIMARY KEY, q);
INSERT INTO t11 VALUES(2,111);
INSERT INTO t11 VALUES(3,333);
CREATE VIEW v10_11 AS SELECT x, q FROM t10, t11 WHERE t10.y=t11.p;
COMMIT;
SELECT * FROM t9 LEFT JOIN v10_11 ON( a=x );
}
} {1 11 1 111 2 22 {} {}}
do_test join-8.2 {
execsql {
SELECT * FROM t9 LEFT JOIN (SELECT x, q FROM t10, t11 WHERE t10.y=t11.p)
ON( a=x);
}
} {1 11 1 111 2 22 {} {}}
do_test join-8.3 {
execsql {
SELECT * FROM v10_11 LEFT JOIN t9 ON( a=x );
}
} {1 111 1 11 3 333 {} {}}
# Ticket #350 describes a scenario where LEFT OUTER JOIN does not
# function correctly if the right table in the join is really
# subquery.
#
# To test the problem, we generate the same LEFT OUTER JOIN in two
# separate selects but with on using a subquery and the other calling
# the table directly. Then connect the two SELECTs using an EXCEPT.
# Both queries should generate the same results so the answer should
# be an empty set.
#
do_test join-9.1 {
execsql {
BEGIN;
CREATE TABLE t12(a,b);
INSERT INTO t12 VALUES(1,11);
INSERT INTO t12 VALUES(2,22);
CREATE TABLE t13(b,c);
INSERT INTO t13 VALUES(22,222);
COMMIT;
SELECT * FROM t12 NATURAL LEFT JOIN t13
EXCEPT
SELECT * FROM t12 NATURAL LEFT JOIN (SELECT * FROM t13 WHERE b>0);
}
} {}
do_test join-9.2 {
execsql {
CREATE VIEW v13 AS SELECT * FROM t13 WHERE b>0;
SELECT * FROM t12 NATURAL LEFT JOIN t13
EXCEPT
SELECT * FROM t12 NATURAL LEFT JOIN v13;
}
} {}
finish_test
+73
View File
@@ -0,0 +1,73 @@
# 2002 May 24
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for joins, including outer joins.
#
# $Id: join2.test,v 1.1 2004/01/24 20:18:13 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test join2-1.1 {
execsql {
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,11);
INSERT INTO t1 VALUES(2,22);
INSERT INTO t1 VALUES(3,33);
SELECT * FROM t1;
}
} {1 11 2 22 3 33}
do_test join2-1.2 {
execsql {
CREATE TABLE t2(b,c);
INSERT INTO t2 VALUES(11,111);
INSERT INTO t2 VALUES(33,333);
INSERT INTO t2 VALUES(44,444);
SELECT * FROM t2;
}
} {11 111 33 333 44 444};
do_test join2-1.3 {
execsql {
CREATE TABLE t3(c,d);
INSERT INTO t3 VALUES(111,1111);
INSERT INTO t3 VALUES(444,4444);
INSERT INTO t3 VALUES(555,5555);
SELECT * FROM t3;
}
} {111 1111 444 4444 555 5555}
do_test join2-1.4 {
execsql {
SELECT * FROM
t1 NATURAL JOIN t2 NATURAL JOIN t3
}
} {1 11 111 1111}
do_test join2-1.5 {
execsql {
SELECT * FROM
t1 NATURAL JOIN t2 NATURAL LEFT OUTER JOIN t3
}
} {1 11 111 1111 3 33 333 {}}
do_test join2-1.6 {
execsql {
SELECT * FROM
t1 NATURAL LEFT OUTER JOIN t2 NATURAL JOIN t3
}
} {1 11 111 1111}
do_test join2-1.6 {
execsql {
SELECT * FROM
t1 NATURAL LEFT OUTER JOIN (t2 NATURAL JOIN t3)
}
} {1 11 111 1111 2 22 {} {} 3 33 {} {}}
finish_test
+319
View File
@@ -0,0 +1,319 @@
# 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.
#
#***********************************************************************
#
# Tests to make sure that value returned by last_insert_rowid() (LIRID)
# is updated properly, especially inside triggers
#
# Note 1: insert into table is now the only statement which changes LIRID
# Note 2: upon entry into before or instead of triggers,
# LIRID is unchanged (rather than -1)
# Note 3: LIRID is changed within the context of a trigger,
# but is restored once the trigger exits
# Note 4: LIRID is not changed by an insert into a view (since everything
# is done within instead of trigger context)
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# ----------------------------------------------------------------------------
# 1.x - basic tests (no triggers)
# LIRID changed properly after an insert into a table
do_test lastinsert-1.1 {
catchsql {
create table t1 (k integer primary key);
insert into t1 values (1);
insert into t1 values (NULL);
insert into t1 values (NULL);
select last_insert_rowid();
}
} {0 3}
# LIRID unchanged after an update on a table
do_test lastinsert-1.2 {
catchsql {
update t1 set k=4 where k=2;
select last_insert_rowid();
}
} {0 3}
# LIRID unchanged after a delete from a table
do_test lastinsert-1.3 {
catchsql {
delete from t1 where k=4;
select last_insert_rowid();
}
} {0 3}
# LIRID unchanged after create table/view statements
do_test lastinsert-1.4 {
catchsql {
create table t2 (k integer primary key, val1, val2, val3);
create view v as select * from t1;
select last_insert_rowid();
}
} {0 3}
# ----------------------------------------------------------------------------
# 2.x - tests with after insert trigger
# LIRID changed properly after an insert into table containing an after trigger
do_test lastinsert-2.1 {
catchsql {
delete from t2;
create trigger r1 after insert on t1 for each row begin
insert into t2 values (NEW.k*2, last_insert_rowid(), NULL, NULL);
update t2 set k=k+10, val2=100+last_insert_rowid();
update t2 set val3=1000+last_insert_rowid();
end;
insert into t1 values (13);
select last_insert_rowid();
}
} {0 13}
# LIRID equals NEW.k upon entry into after insert trigger
do_test lastinsert-2.2 {
catchsql {
select val1 from t2;
}
} {0 13}
# LIRID changed properly by insert within context of after insert trigger
do_test lastinsert-2.3 {
catchsql {
select val2 from t2;
}
} {0 126}
# LIRID unchanged by update within context of after insert trigger
do_test lastinsert-2.4 {
catchsql {
select val3 from t2;
}
} {0 1026}
# ----------------------------------------------------------------------------
# 3.x - tests with after update trigger
# LIRID not changed after an update onto a table containing an after trigger
do_test lastinsert-3.1 {
catchsql {
delete from t2;
drop trigger r1;
create trigger r1 after update on t1 for each row begin
insert into t2 values (NEW.k*2, last_insert_rowid(), NULL, NULL);
update t2 set k=k+10, val2=100+last_insert_rowid();
update t2 set val3=1000+last_insert_rowid();
end;
update t1 set k=14 where k=3;
select last_insert_rowid();
}
} {0 13}
# LIRID unchanged upon entry into after update trigger
do_test lastinsert-3.2 {
catchsql {
select val1 from t2;
}
} {0 13}
# LIRID changed properly by insert within context of after update trigger
do_test lastinsert-3.3 {
catchsql {
select val2 from t2;
}
} {0 128}
# LIRID unchanged by update within context of after update trigger
do_test lastinsert-3.4 {
catchsql {
select val3 from t2;
}
} {0 1028}
# ----------------------------------------------------------------------------
# 4.x - tests with instead of insert trigger
# LIRID not changed after an insert into view containing an instead of trigger
do_test lastinsert-4.1 {
catchsql {
delete from t2;
drop trigger r1;
create trigger r1 instead of insert on v for each row begin
insert into t2 values (NEW.k*2, last_insert_rowid(), NULL, NULL);
update t2 set k=k+10, val2=100+last_insert_rowid();
update t2 set val3=1000+last_insert_rowid();
end;
insert into v values (15);
select last_insert_rowid();
}
} {0 13}
# LIRID unchanged upon entry into instead of trigger
do_test lastinsert-4.2 {
catchsql {
select val1 from t2;
}
} {0 13}
# LIRID changed properly by insert within context of instead of trigger
do_test lastinsert-4.3 {
catchsql {
select val2 from t2;
}
} {0 130}
# LIRID unchanged by update within context of instead of trigger
do_test lastinsert-4.4 {
catchsql {
select val3 from t2;
}
} {0 1030}
# ----------------------------------------------------------------------------
# 5.x - tests with before delete trigger
# LIRID not changed after a delete on a table containing a before trigger
do_test lastinsert-5.1 {
catchsql {
delete from t2;
drop trigger r1;
create trigger r1 before delete on t1 for each row begin
insert into t2 values (77, last_insert_rowid(), NULL, NULL);
update t2 set k=k+10, val2=100+last_insert_rowid();
update t2 set val3=1000+last_insert_rowid();
end;
delete from t1 where k=1;
select last_insert_rowid();
}
} {0 13}
# LIRID unchanged upon entry into delete trigger
do_test lastinsert-5.2 {
catchsql {
select val1 from t2;
}
} {0 13}
# LIRID changed properly by insert within context of delete trigger
do_test lastinsert-5.3 {
catchsql {
select val2 from t2;
}
} {0 177}
# LIRID unchanged by update within context of delete trigger
do_test lastinsert-5.4 {
catchsql {
select val3 from t2;
}
} {0 1077}
# ----------------------------------------------------------------------------
# 6.x - tests with instead of update trigger
# LIRID not changed after an update on a view containing an instead of trigger
do_test lastinsert-6.1 {
catchsql {
delete from t2;
drop trigger r1;
create trigger r1 instead of update on v for each row begin
insert into t2 values (NEW.k*2, last_insert_rowid(), NULL, NULL);
update t2 set k=k+10, val2=100+last_insert_rowid();
update t2 set val3=1000+last_insert_rowid();
end;
update v set k=16 where k=14;
select last_insert_rowid();
}
} {0 13}
# LIRID unchanged upon entry into instead of trigger
do_test lastinsert-6.2 {
catchsql {
select val1 from t2;
}
} {0 13}
# LIRID changed properly by insert within context of instead of trigger
do_test lastinsert-6.3 {
catchsql {
select val2 from t2;
}
} {0 132}
# LIRID unchanged by update within context of instead of trigger
do_test lastinsert-6.4 {
catchsql {
select val3 from t2;
}
} {0 1032}
# ----------------------------------------------------------------------------
# 7.x - complex tests with temporary tables and nested instead of triggers
do_test lastinsert-7.1 {
catchsql {
drop table t1; drop table t2; drop trigger r1;
create temp table t1 (k integer primary key);
create temp table t2 (k integer primary key);
create temp view v1 as select * from t1;
create temp view v2 as select * from t2;
create temp table rid (k integer primary key, rin, rout);
insert into rid values (1, NULL, NULL);
insert into rid values (2, NULL, NULL);
create temp trigger r1 instead of insert on v1 for each row begin
update rid set rin=last_insert_rowid() where k=1;
insert into t1 values (100+NEW.k);
insert into v2 values (100+last_insert_rowid());
update rid set rout=last_insert_rowid() where k=1;
end;
create temp trigger r2 instead of insert on v2 for each row begin
update rid set rin=last_insert_rowid() where k=2;
insert into t2 values (1000+NEW.k);
update rid set rout=last_insert_rowid() where k=2;
end;
insert into t1 values (77);
select last_insert_rowid();
}
} {0 77}
do_test lastinsert-7.2 {
catchsql {
insert into v1 values (5);
select last_insert_rowid();
}
} {0 77}
do_test lastinsert-7.3 {
catchsql {
select rin from rid where k=1;
}
} {0 77}
do_test lastinsert-7.4 {
catchsql {
select rout from rid where k=1;
}
} {0 105}
do_test lastinsert-7.5 {
catchsql {
select rin from rid where k=2;
}
} {0 105}
do_test lastinsert-7.6 {
catchsql {
select rout from rid where k=2;
}
} {0 1205}
finish_test
+244
View File
@@ -0,0 +1,244 @@
# 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.
#
#***********************************************************************
#
# Tests to make sure that value returned by last_statement_change_count()
# (LSCC) is updated properly, especially inside triggers
#
# Note 1: LSCC remains constant within a statement and only updates once
# the statement is finished (triggers count as part of statement)
# Note 2: LSCC is changed within the context of a trigger
# much like last_insert_rowid() (see lastinsert.test),
# but is restored once the trigger exits
# Note 3: LSCC is not changed by a change to a view (since everything
# is done within instead of trigger context)
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# ----------------------------------------------------------------------------
# 1.x - basic tests (no triggers)
# LSCC set properly after insert
do_test laststmtchanges-1.1 {
catchsql {
create table t0 (x);
insert into t0 values (1);
insert into t0 values (1);
insert into t0 values (2);
insert into t0 values (2);
insert into t0 values (1);
insert into t0 values (1);
insert into t0 values (1);
insert into t0 values (2);
select last_statement_change_count();
}
} {0 1}
# LSCC set properly after update
do_test laststmtchanges-1.2 {
catchsql {
update t0 set x=3 where x=1;
select last_statement_change_count();
}
} {0 5}
# LSCC unchanged within an update statement
do_test laststmtchanges-1.3 {
catchsql {
update t0 set x=x+last_statement_change_count() where x=3;
select count() from t0 where x=8;
}
} {0 5}
# LSCC set properly after update on table where no rows changed
do_test laststmtchanges-1.4 {
catchsql {
update t0 set x=77 where x=88;
select last_statement_change_count();
}
} {0 0}
# LSCC set properly after delete from table
do_test laststmtchanges-1.5 {
catchsql {
delete from t0 where x=2;
select last_statement_change_count();
}
} {0 3}
# ----------------------------------------------------------------------------
# 2.x - tests with after insert trigger
# LSCC changed properly after insert into table containing after trigger
do_test laststmtchanges-2.1 {
catchsql {
create table t1 (k integer primary key);
create table t2 (k integer primary key, v1, v2);
create trigger r1 after insert on t1 for each row begin
insert into t2 values (NULL, last_statement_change_count(), NULL);
update t0 set x=x;
update t2 set v2=last_statement_change_count();
end;
insert into t1 values (77);
select last_statement_change_count();
}
} {0 1}
# LSCC unchanged upon entry into after insert trigger
do_test laststmtchanges-2.2 {
catchsql {
select v1 from t2;
}
} {0 3}
# LSCC changed properly by update within context of after insert trigger
do_test laststmtchanges-2.3 {
catchsql {
select v2 from t2;
}
} {0 5}
# ----------------------------------------------------------------------------
# 3.x - tests with after update trigger
# LSCC changed properly after update into table containing after trigger
do_test laststmtchanges-3.1 {
catchsql {
drop trigger r1;
delete from t2; delete from t2;
create trigger r1 after update on t1 for each row begin
insert into t2 values (NULL, last_statement_change_count(), NULL);
delete from t0 where oid=1 or oid=2;
update t2 set v2=last_statement_change_count();
end;
update t1 set k=k;
select last_statement_change_count();
}
} {0 1}
# LSCC unchanged upon entry into after update trigger
do_test laststmtchanges-3.2 {
catchsql {
select v1 from t2;
}
} {0 0}
# LSCC changed properly by delete within context of after update trigger
do_test laststmtchanges-3.3 {
catchsql {
select v2 from t2;
}
} {0 2}
# ----------------------------------------------------------------------------
# 4.x - tests with before delete trigger
# LSCC changed properly on delete from table containing before trigger
do_test laststmtchanges-4.1 {
catchsql {
drop trigger r1;
delete from t2; delete from t2;
create trigger r1 before delete on t1 for each row begin
insert into t2 values (NULL, last_statement_change_count(), NULL);
insert into t0 values (5);
update t2 set v2=last_statement_change_count();
end;
delete from t1;
select last_statement_change_count();
}
} {0 1}
# LSCC unchanged upon entry into before delete trigger
do_test laststmtchanges-4.2 {
catchsql {
select v1 from t2;
}
} {0 0}
# LSCC changed properly by insert within context of before delete trigger
do_test laststmtchanges-4.3 {
catchsql {
select v2 from t2;
}
} {0 1}
# ----------------------------------------------------------------------------
# 5.x - complex tests with temporary tables and nested instead of triggers
do_test laststmtchanges-5.1 {
catchsql {
drop table t0; drop table t1; drop table t2;
create temp table t0(x);
create temp table t1 (k integer primary key);
create temp table t2 (k integer primary key);
create temp view v1 as select * from t1;
create temp view v2 as select * from t2;
create temp table n1 (k integer primary key, n);
create temp table n2 (k integer primary key, n);
insert into t0 values (1);
insert into t0 values (2);
insert into t0 values (1);
insert into t0 values (1);
insert into t0 values (1);
insert into t0 values (2);
insert into t0 values (2);
insert into t0 values (1);
create temp trigger r1 instead of insert on v1 for each row begin
insert into n1 values (NULL, last_statement_change_count());
update t0 set x=x*10 where x=1;
insert into n1 values (NULL, last_statement_change_count());
insert into t1 values (NEW.k);
insert into n1 values (NULL, last_statement_change_count());
update t0 set x=x*10 where x=0;
insert into v2 values (100+NEW.k);
insert into n1 values (NULL, last_statement_change_count());
end;
create temp trigger r2 instead of insert on v2 for each row begin
insert into n2 values (NULL, last_statement_change_count());
insert into t2 values (1000+NEW.k);
insert into n2 values (NULL, last_statement_change_count());
update t0 set x=x*100 where x=0;
insert into n2 values (NULL, last_statement_change_count());
delete from t0 where x=2;
insert into n2 values (NULL, last_statement_change_count());
end;
insert into t1 values (77);
select last_statement_change_count();
}
} {0 1}
do_test laststmtchanges-5.2 {
catchsql {
delete from t1 where k=88;
select last_statement_change_count();
}
} {0 0}
do_test laststmtchanges-5.3 {
catchsql {
insert into v1 values (5);
select last_statement_change_count();
}
} {0 0}
do_test laststmtchanges-5.4 {
catchsql {
select n from n1;
}
} {0 {0 5 1 0}}
do_test laststmtchanges-5.5 {
catchsql {
select n from n2;
}
} {0 {0 1 0 3}}
finish_test
+144 -4
View File
@@ -12,7 +12,7 @@
# focus of this file is testing the LIMIT ... OFFSET ... clause
# of SELECT statements.
#
# $Id: limit.test,v 1.6 2002/09/08 17:23:45 drh Exp $
# $Id: limit.test,v 1.11 2004/03/08 13:26:18 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -37,15 +37,24 @@ do_test limit-1.0 {
do_test limit-1.1 {
execsql {SELECT count(*) FROM t1 LIMIT 5}
} {32}
do_test limit-1.2 {
do_test limit-1.2.1 {
execsql {SELECT x FROM t1 ORDER BY x LIMIT 5}
} {0 1 2 3 4}
do_test limit-1.2.2 {
execsql {SELECT x FROM t1 ORDER BY x LIMIT 5 OFFSET 2}
} {2 3 4 5 6}
do_test limit-1.2.3 {
execsql {SELECT x FROM t1 ORDER BY x LIMIT 2, 5}
} {2 3 4 5 6}
do_test limit-1.3 {
execsql {SELECT x FROM t1 ORDER BY x LIMIT 5 OFFSET 5}
} {5 6 7 8 9}
do_test limit-1.4 {
do_test limit-1.4.1 {
execsql {SELECT x FROM t1 ORDER BY x LIMIT 50 OFFSET 30}
} {30 31}
do_test limit-1.4.2 {
execsql {SELECT x FROM t1 ORDER BY x LIMIT 30, 50}
} {30 31}
do_test limit-1.5 {
execsql {SELECT x FROM t1 ORDER BY x LIMIT 50 OFFSET 50}
} {}
@@ -84,7 +93,8 @@ do_test limit-3.1 {
do_test limit-4.1 {
execsql {
BEGIN;
CREATE TABLE t3 AS SELECT x FROM t1 ORDER BY x LIMIT 10 OFFSET 1;
CREATE TABLE t3(x);
INSERT INTO t3 SELECT x FROM t1 ORDER BY x LIMIT 10 OFFSET 1;
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
@@ -154,4 +164,134 @@ do_test limit-5.5 {
}
} {1000 1528204 593161 0 3107 505 1005}
# There is some contraversy about whether LIMIT 0 should be the same as
# no limit at all or if LIMIT 0 should result in zero output rows.
#
do_test limit-6.1 {
execsql {
BEGIN;
CREATE TABLE t6(a);
INSERT INTO t6 VALUES(1);
INSERT INTO t6 VALUES(2);
INSERT INTO t6 SELECT a+2 FROM t6;
COMMIT;
SELECT * FROM t6;
}
} {1 2 3 4}
do_test limit-6.2 {
execsql {
SELECT * FROM t6 LIMIT -1 OFFSET -1;
}
} {1 2 3 4}
do_test limit-6.3 {
execsql {
SELECT * FROM t6 LIMIT 2 OFFSET -123;
}
} {1 2}
do_test limit-6.4 {
execsql {
SELECT * FROM t6 LIMIT -432 OFFSET 2;
}
} {3 4}
do_test limit-6.5 {
execsql {
SELECT * FROM t6 LIMIT -1
}
} {1 2 3 4}
do_test limit-6.6 {
execsql {
SELECT * FROM t6 LIMIT -1 OFFSET 1
}
} {2 3 4}
do_test limit-6.7 {
execsql {
SELECT * FROM t6 LIMIT 0
}
} {}
do_test limit-6.8 {
execsql {
SELECT * FROM t6 LIMIT 0 OFFSET 1
}
} {}
# Make sure LIMIT works well with compound SELECT statements.
# Ticket #393
#
do_test limit-7.1.1 {
catchsql {
SELECT x FROM t2 LIMIT 5 UNION ALL SELECT a FROM t6;
}
} {1 {LIMIT clause should come after UNION ALL not before}}
do_test limit-7.1.2 {
catchsql {
SELECT x FROM t2 LIMIT 5 UNION SELECT a FROM t6;
}
} {1 {LIMIT clause should come after UNION not before}}
do_test limit-7.1.3 {
catchsql {
SELECT x FROM t2 LIMIT 5 EXCEPT SELECT a FROM t6 LIMIT 3;
}
} {1 {LIMIT clause should come after EXCEPT not before}}
do_test limit-7.1.4 {
catchsql {
SELECT x FROM t2 LIMIT 0,5 INTERSECT SELECT a FROM t6;
}
} {1 {LIMIT clause should come after INTERSECT not before}}
do_test limit-7.2 {
execsql {
SELECT x FROM t2 UNION ALL SELECT a FROM t6 LIMIT 5;
}
} {31 30 1 2 3}
do_test limit-7.3 {
execsql {
SELECT x FROM t2 UNION ALL SELECT a FROM t6 LIMIT 3 OFFSET 1;
}
} {30 1 2}
do_test limit-7.4 {
execsql {
SELECT x FROM t2 UNION ALL SELECT a FROM t6 ORDER BY 1 LIMIT 3 OFFSET 1;
}
} {2 3 4}
do_test limit-7.5 {
execsql {
SELECT x FROM t2 UNION SELECT x+2 FROM t2 LIMIT 2 OFFSET 1;
}
} {31 32}
do_test limit-7.6 {
execsql {
SELECT x FROM t2 UNION SELECT x+2 FROM t2 ORDER BY 1 DESC LIMIT 2 OFFSET 1;
}
} {32 31}
do_test limit-7.7 {
execsql {
SELECT a+9 FROM t6 EXCEPT SELECT y FROM t2 LIMIT 2;
}
} {11 12}
do_test limit-7.8 {
execsql {
SELECT a+9 FROM t6 EXCEPT SELECT y FROM t2 ORDER BY 1 DESC LIMIT 2;
}
} {13 12}
do_test limit-7.9 {
execsql {
SELECT a+26 FROM t6 INTERSECT SELECT x FROM t2 LIMIT 1;
}
} {30}
do_test limit-7.10 {
execsql {
SELECT a+27 FROM t6 INTERSECT SELECT x FROM t2 LIMIT 1;
}
} {30}
do_test limit-7.11 {
execsql {
SELECT a+27 FROM t6 INTERSECT SELECT x FROM t2 LIMIT 1 OFFSET 1;
}
} {31}
do_test limit-7.12 {
execsql {
SELECT a+27 FROM t6 INTERSECT SELECT x FROM t2
ORDER BY 1 DESC LIMIT 1 OFFSET 1;
}
} {30}
finish_test
+24 -9
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is database locks.
#
# $Id: lock.test,v 1.18 2002/09/14 13:47:33 drh Exp $
# $Id: lock.test,v 1.20 2004/02/14 16:31:04 drh Exp $
set testdir [file dirname $argv0]
@@ -33,11 +33,11 @@ do_test lock-1.3 {
execsql {CREATE TABLE t1(a int, b int)}
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
} {t1}
do_test lock-1.4 {
catchsql {
SELECT name FROM sqlite_master WHERE type='table' ORDER BY name
} db2
} {1 {database schema has changed}}
#do_test lock-1.4 {
# catchsql {
# SELECT name FROM sqlite_master WHERE type='table' ORDER BY name
# } db2
#} {1 {database schema has changed}}
do_test lock-1.5 {
catchsql {
SELECT name FROM sqlite_master WHERE type='table' ORDER BY name
@@ -75,9 +75,12 @@ do_test lock-1.13 {
execsql {INSERT INTO t2 VALUES(8,9)}
execsql {SELECT * FROM t2}
} {8 9}
do_test lock-1.14 {
do_test lock-1.14.1 {
catchsql {SELECT * FROM t2} db2
} {1 {no such table: t2}}
do_test lock-1.14.2 {
catchsql {SELECT * FROM t1} db2
} {1 {database schema has changed}}
} {0 {2 1}}
do_test lock-1.15 {
catchsql {SELECT * FROM t2} db2
} {0 {8 9}}
@@ -232,7 +235,19 @@ do_test lock-2.7 {
lappend r $msg
lappend r $::callback_value
} {0 {} {1 2 3}}
integrity_check lock-2.8
# Test the built-in busy timeout handler
#
do_test lock-2.8 {
db2 timeout 400
execsql BEGIN
catchsql BEGIN db2
} {1 {database is locked}}
do_test lock-2.9 {
db2 timeout 0
execsql COMMIT
} {}
integrity_check lock-2.10
# Try to start two transactions in a row
#
+83 -9
View File
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is exercising the code in main.c.
#
# $Id: main.test,v 1.11 2002/05/15 14:17:45 drh Exp $
# $Id: main.test,v 1.14 2003/05/04 17:58:27 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -24,12 +24,12 @@ do_test main-1.1 {
do_test main-1.2 {
db complete {
}
} {0}
} {1}
do_test main-1.3 {
db complete {
-- a comment ;
}
} {0}
} {1}
do_test main-1.4 {
db complete {
-- a comment ;
@@ -138,19 +138,46 @@ do_test main-1.26 {
UPDATE pqr SET a=5;
}
} {0}
do_test main-1.27 {
do_test main-1.27.1 {
db complete {
CREATE -- a comment
TRIGGERX xyz AFTER DELETE backend BEGIN
UPDATE pqr SET a=5;
}
} {1}
do_test main-1.27.2 {
db complete {
CREATE/**/TRIGGER xyz AFTER DELETE backend BEGIN
UPDATE pqr SET a=5;
}
} {0}
do_test main-1.27.3 {
db complete {
/* */ EXPLAIN -- A comment
CREATE/**/TRIGGER xyz AFTER DELETE backend BEGIN
UPDATE pqr SET a=5;
}
} {0}
do_test main-1.27.4 {
db complete {
BOGUS token
CREATE TRIGGER xyz AFTER DELETE backend BEGIN
UPDATE pqr SET a=5;
}
} {1}
do_test main-1.27.5 {
db complete {
EXPLAIN
CREATE TEMP TRIGGER xyz AFTER DELETE backend BEGIN
UPDATE pqr SET a=5;
}
} {0}
do_test main-1.28 {
db complete {
CREATE TEMP TRIGGER xyz AFTER DELETE backend BEGIN
UPDATE pqr SET a=5;
}
} {1}
} {0}
do_test main-1.29 {
db complete {
CREATE TRIGGER xyz AFTER DELETE backend BEGIN
@@ -158,6 +185,53 @@ do_test main-1.29 {
EXPLAIN select * from xyz;
}
} {0}
do_test main-1.30 {
db complete {
CREATE TABLE /* In comment ; */
}
} {0}
do_test main-1.31 {
db complete {
CREATE TABLE /* In comment ; */ hi;
}
} {1}
do_test main-1.31 {
db complete {
CREATE TABLE /* In comment ; */;
}
} {1}
do_test main-1.32 {
db complete {
stuff;
/*
CREATE TABLE
multiple lines
of text
*/
}
} {1}
do_test main-1.33 {
db complete {
/*
CREATE TABLE
multiple lines
of text;
}
} {0}
do_test main-1.34 {
db complete {
/*
CREATE TABLE
multiple lines "*/
of text;
}
} {1}
do_test main-1.35 {
db complete {hi /**/ there;}
} {1}
do_test main-1.36 {
db complete {hi there/***/;}
} {1}
# Try to open a database with a corrupt database file.
@@ -198,16 +272,16 @@ do_test main-3.3 {
sqlite db testdb
execsql {
create table T1(X REAL);
insert into T1 values(.5);
insert into T1 values(0.5);
insert into T1 values(0.5e2);
insert into T1 values(0.5e-002);
insert into T1 values(5e-002);
insert into T1 values(-5.0e-2);
insert into T1 values(-5.1e-2);
insert into T1 values(.5e2);
insert into T1 values(.5E+02);
insert into T1 values(0.5e2);
insert into T1 values(0.5E+02);
insert into T1 values(5E+02);
insert into T1 values(5.E+03);
insert into T1 values(5.0E+03);
select x*10 from T1 order by x*5;
}
} {-0.51 -0.5 0.05 0.5 5 500 500 500 5000 50000}
+2 -2
View File
@@ -14,14 +14,14 @@
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.5 2002/05/23 02:09:05 drh Exp $
# $Id: malloc.test,v 1.6 2004/02/14 01:39:50 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_fail]==""} {
if {[info command sqlite_malloc_stat]==""} {
puts "Skipping malloc tests: not compiled with -DMEMORY_DEBUG..."
finish_test
return
+396
View File
@@ -0,0 +1,396 @@
# 2001 September 15
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is in-memory database backend.
#
# $Id: memdb.test,v 1.6 2003/08/05 13:13:39 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# In the following sequence of tests, compute the MD5 sum of the content
# of a table, make lots of modifications to that table, then do a rollback.
# Verify that after the rollback, the MD5 checksum is unchanged.
#
# These tests were browed from trans.tcl.
#
do_test memdb-1.1 {
db close
sqlite db :memory:
# sqlite db test.db
execsql {
BEGIN;
CREATE TABLE t3(x TEXT);
INSERT INTO t3 VALUES(randstr(10,400));
INSERT INTO t3 VALUES(randstr(10,400));
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
INSERT INTO t3 SELECT randstr(10,400) FROM t3;
COMMIT;
SELECT count(*) FROM t3;
}
} {1024}
# The following procedure computes a "signature" for table "t3". If
# T3 changes in any way, the signature should change.
#
# This is used to test ROLLBACK. We gather a signature for t3, then
# make lots of changes to t3, then rollback and take another signature.
# The two signatures should be the same.
#
proc signature {{fn {}}} {
set rx [db eval {SELECT x FROM t3}]
# set r1 [md5 $rx\n]
if {$fn!=""} {
# set fd [open $fn w]
# puts $fd $rx
# close $fd
}
# set r [db eval {SELECT count(*), md5sum(x) FROM t3}]
# puts "SIG($fn)=$r1"
return [list [string length $rx] $rx]
}
# Do rollbacks. Make sure the signature does not change.
#
set limit 10
for {set i 2} {$i<=$limit} {incr i} {
set ::sig [signature one]
# puts "sig=$sig"
set cnt [lindex $::sig 0]
set ::journal_format [expr {($i%3)+1}]
if {$i%2==0} {
execsql {PRAGMA synchronous=FULL}
} else {
execsql {PRAGMA synchronous=NORMAL}
}
do_test memdb-1.$i.1-$cnt {
execsql {
BEGIN;
DELETE FROM t3 WHERE random()%10!=0;
INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
ROLLBACK;
}
set sig2 [signature two]
} $sig
# puts "sig2=$sig2"
# if {$sig2!=$sig} exit
do_test memdb-1.$i.2-$cnt {
execsql {
BEGIN;
DELETE FROM t3 WHERE random()%10!=0;
INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
DELETE FROM t3 WHERE random()%10!=0;
INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
ROLLBACK;
}
signature
} $sig
if {$i<$limit} {
do_test memdb-1.$i.9-$cnt {
execsql {
INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0;
}
} {}
}
set ::pager_old_format 0
}
do_test memdb-2.1 {
execsql {
PRAGMA integrity_check
}
} {ok}
do_test memdb-3.1 {
execsql {
CREATE TABLE t4(a,b,c,d);
BEGIN;
INSERT INTO t4 VALUES(1,2,3,4);
SELECT * FROM t4;
}
} {1 2 3 4}
do_test memdb-3.2 {
execsql {
SELECT name FROM sqlite_master WHERE type='table';
}
} {t3 t4}
do_test memdb-3.3 {
execsql {
DROP TABLE t4;
SELECT name FROM sqlite_master WHERE type='table';
}
} {t3}
do_test memdb-3.4 {
execsql {
ROLLBACK;
SELECT name FROM sqlite_master WHERE type='table';
}
} {t3 t4}
# Create tables for the first group of tests.
#
do_test memdb-4.0 {
execsql {
CREATE TABLE t1(a, b, c, UNIQUE(a,b));
CREATE TABLE t2(x);
SELECT c FROM t1 ORDER BY c;
}
} {}
# Six columns of configuration data as follows:
#
# i The reference number of the test
# conf The conflict resolution algorithm on the BEGIN statement
# cmd An INSERT or REPLACE command to execute against table t1
# t0 True if there is an error from $cmd
# t1 Content of "c" column of t1 assuming no error in $cmd
# t2 Content of "x" column of t2
#
foreach {i conf cmd t0 t1 t2} {
1 {} INSERT 1 {} 1
2 {} {INSERT OR IGNORE} 0 3 1
3 {} {INSERT OR REPLACE} 0 4 1
4 {} REPLACE 0 4 1
5 {} {INSERT OR FAIL} 1 {} 1
6 {} {INSERT OR ABORT} 1 {} 1
7 {} {INSERT OR ROLLBACK} 1 {} {}
8 IGNORE INSERT 0 3 1
9 IGNORE {INSERT OR IGNORE} 0 3 1
10 IGNORE {INSERT OR REPLACE} 0 4 1
11 IGNORE REPLACE 0 4 1
12 IGNORE {INSERT OR FAIL} 1 {} 1
13 IGNORE {INSERT OR ABORT} 1 {} 1
14 IGNORE {INSERT OR ROLLBACK} 1 {} {}
15 REPLACE INSERT 0 4 1
16 FAIL INSERT 1 {} 1
17 ABORT INSERT 1 {} 1
18 ROLLBACK INSERT 1 {} {}
} {
do_test memdb-4.$i {
if {$conf!=""} {set conf "ON CONFLICT $conf"}
set r0 [catch {execsql [subst {
DELETE FROM t1;
DELETE FROM t2;
INSERT INTO t1 VALUES(1,2,3);
BEGIN $conf;
INSERT INTO t2 VALUES(1);
$cmd INTO t1 VALUES(1,2,4);
}]} r1]
catch {execsql {COMMIT}}
if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
set r2 [execsql {SELECT x FROM t2}]
list $r0 $r1 $r2
} [list $t0 $t1 $t2]
}
do_test memdb-5.0 {
execsql {
DROP TABLE t2;
DROP TABLE t3;
CREATE TABLE t2(a,b,c);
INSERT INTO t2 VALUES(1,2,1);
INSERT INTO t2 VALUES(2,3,2);
INSERT INTO t2 VALUES(3,4,1);
INSERT INTO t2 VALUES(4,5,4);
SELECT c FROM t2 ORDER BY b;
CREATE TABLE t3(x);
INSERT INTO t3 VALUES(1);
}
} {1 2 1 4}
# Six columns of configuration data as follows:
#
# i The reference number of the test
# conf1 The conflict resolution algorithm on the UNIQUE constraint
# conf2 The conflict resolution algorithm on the BEGIN statement
# cmd An UPDATE command to execute against table t1
# t0 True if there is an error from $cmd
# t1 Content of "b" column of t1 assuming no error in $cmd
# t2 Content of "x" column of t3
#
foreach {i conf1 conf2 cmd t0 t1 t2} {
1 {} {} UPDATE 1 {6 7 8 9} 1
2 REPLACE {} UPDATE 0 {7 6 9} 1
3 IGNORE {} UPDATE 0 {6 7 3 9} 1
4 FAIL {} UPDATE 1 {6 7 3 4} 1
5 ABORT {} UPDATE 1 {1 2 3 4} 1
6 ROLLBACK {} UPDATE 1 {1 2 3 4} 0
7 REPLACE {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
8 IGNORE {} {UPDATE OR REPLACE} 0 {7 6 9} 1
9 FAIL {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
10 ABORT {} {UPDATE OR REPLACE} 0 {7 6 9} 1
11 ROLLBACK {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
12 {} {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
13 {} {} {UPDATE OR REPLACE} 0 {7 6 9} 1
14 {} {} {UPDATE OR FAIL} 1 {6 7 3 4} 1
15 {} {} {UPDATE OR ABORT} 1 {1 2 3 4} 1
16 {} {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0
17 {} IGNORE UPDATE 0 {6 7 3 9} 1
18 {} REPLACE UPDATE 0 {7 6 9} 1
19 {} FAIL UPDATE 1 {6 7 3 4} 1
20 {} ABORT UPDATE 1 {1 2 3 4} 1
21 {} ROLLBACK UPDATE 1 {1 2 3 4} 0
22 REPLACE IGNORE UPDATE 0 {6 7 3 9} 1
23 IGNORE REPLACE UPDATE 0 {7 6 9} 1
24 REPLACE FAIL UPDATE 1 {6 7 3 4} 1
25 IGNORE ABORT UPDATE 1 {1 2 3 4} 1
26 REPLACE ROLLBACK UPDATE 1 {1 2 3 4} 0
} {
if {$t0} {set t1 {column a is not unique}}
do_test memdb-5.$i {
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
set r0 [catch {execsql [subst {
DROP TABLE t1;
CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1);
INSERT INTO t1 SELECT * FROM t2;
UPDATE t3 SET x=0;
BEGIN $conf2;
$cmd t3 SET x=1;
$cmd t1 SET b=b*2;
$cmd t1 SET a=c+5;
}]} r1]
catch {execsql {COMMIT}}
if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]}
set r2 [execsql {SELECT x FROM t3}]
list $r0 $r1 $r2
} [list $t0 $t1 $t2]
}
do_test memdb-6.1 {
execsql {
SELECT * FROM t2;
}
} {1 2 1 2 3 2 3 4 1 4 5 4}
do_test memdb-6.2 {
execsql {
BEGIN;
DROP TABLE t2;
SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
}
} {t1 t3 t4}
do_test memdb-6.3 {
execsql {
ROLLBACK;
SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
}
} {t1 t2 t3 t4}
do_test memdb-6.4 {
execsql {
SELECT * FROM t2;
}
} {1 2 1 2 3 2 3 4 1 4 5 4}
do_test memdb-6.5 {
execsql {
SELECT a FROM t2 UNION SELECT b FROM t2 ORDER BY 1;
}
} {1 2 3 4 5}
do_test memdb-6.6 {
execsql {
CREATE INDEX i2 ON t2(c);
SELECT a FROM t2 ORDER BY c;
}
} {1 3 2 4}
do_test memdb-6.6 {
execsql {
SELECT a FROM t2 ORDER BY c DESC;
}
} {4 2 3 1}
do_test memdb-6.7 {
execsql {
BEGIN;
CREATE TABLE t5(x,y);
INSERT INTO t5 VALUES(1,2);
SELECT * FROM t5;
}
} {1 2}
do_test memdb-6.8 {
execsql {
SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
}
} {t1 t2 t3 t4 t5}
do_test memdb-6.9 {
execsql {
ROLLBACK;
SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
}
} {t1 t2 t3 t4}
do_test memdb-6.10 {
execsql {
CREATE TABLE t5(x PRIMARY KEY, y UNIQUE);
SELECT * FROM t5;
}
} {}
do_test memdb-6.11 {
execsql {
SELECT * FROM t5 ORDER BY y DESC;
}
} {}
do_test memdb-6.12 {
execsql {
INSERT INTO t5 VALUES(1,2);
INSERT INTO t5 VALUES(3,4);
REPLACE INTO t5 VALUES(1,4);
SELECT rowid,* FROM t5;
}
} {3 1 4}
do_test memdb-6.13 {
execsql {
DELETE FROM t5 WHERE x>5;
SELECT * FROM t5;
}
} {1 4}
do_test memdb-6.14 {
execsql {
DELETE FROM t5 WHERE y<3;
SELECT * FROM t5;
}
} {1 4}
do_test memdb-6.15 {
execsql {
DELETE FROM t5 WHERE x>0;
SELECT * FROM t5;
}
} {}
do_test memdb-7.1 {
execsql {
CREATE TABLE t6(x);
INSERT INTO t6 VALUES(1);
INSERT INTO t6 SELECT x+1 FROM t6;
INSERT INTO t6 SELECT x+2 FROM t6;
INSERT INTO t6 SELECT x+4 FROM t6;
INSERT INTO t6 SELECT x+8 FROM t6;
INSERT INTO t6 SELECT x+16 FROM t6;
INSERT INTO t6 SELECT x+32 FROM t6;
INSERT INTO t6 SELECT x+64 FROM t6;
INSERT INTO t6 SELECT x+128 FROM t6;
SELECT count(*) FROM (SELECT DISTINCT x FROM t6);
}
} {256}
for {set i 1} {$i<=256} {incr i} {
do_test memdb-7.2.$i {
execsql "DELETE FROM t6 WHERE x=\
(SELECT x FROM t6 ORDER BY random() LIMIT 1)"
execsql {SELECT count(*) FROM t6}
} [expr {256-$i}]
}
finish_test

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