]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Miscellaneous code simplifications and cleanup and test coverage
authordrh <drh@noemail.net>
Sat, 19 Jan 2008 20:11:25 +0000 (20:11 +0000)
committerdrh <drh@noemail.net>
Sat, 19 Jan 2008 20:11:25 +0000 (20:11 +0000)
enhancements. (CVS 4730)

FossilOrigin-Name: af129b6d158cc90ce9752dd6383c1de47f7b3e43

16 files changed:
manifest
manifest.uuid
mkopcodeh.awk
src/test1.c
src/vdbe.c
src/vdbeaux.c
src/where.c
test/all.test
test/cast.test
test/expr.test
test/hook.test
test/incrvacuum.test
test/misc3.test
test/rowid.test
test/softheap1.test
test/tester.tcl

index 49aa4ce22d0a5906984fb000817722434ccd3cba..b3e40c6d3f2fc27ad7a073ad13d398d3ffb8b1de 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Cleanup\sand\ssimplification\sof\sconstraint\sprocessing.\s\sSimplifications\nto\sthe\sVM\sfor\sbetter\stest\scoverage.\s(CVS\s4729)
-D 2008-01-19T03:35:59
+C Miscellaneous\scode\ssimplifications\sand\scleanup\sand\stest\scoverage\nenhancements.\s(CVS\s4730)
+D 2008-01-19T20:11:26
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -69,7 +69,7 @@ F mkdll.sh 5f8438dcac98e795d7df6529159a1ec566de0183
 F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
 F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb
 F mkopcodec.awk 3fb9bf077053c968451f4dd03d11661ac373f9d1
-F mkopcodeh.awk 89fab7d28a5ec5313f6ca985d87a31a97ef14bcb
+F mkopcodeh.awk 513946ce4429bf2723aef0d640eb4d2493deb68e
 F mkso.sh 24bde4c09e6fe80f718db3c31c068f45e13a2f2c
 F publish.sh 1c0658c63d70f182a8f5e17cc28422f1b237f51d
 F publish_osx.sh eca87df1e3d43d128d97d3261fd48b3d6877996e
@@ -140,7 +140,7 @@ F src/sqliteInt.h 9c3384439e402016037115ad143ed0c3adbd1c93
 F src/sqliteLimit.h ee4430f88f69bf63527967bb35ca52af7b0ccb1e
 F src/table.c 1aeb9eab57b4235db86fe15a35dec76fb445a9c4
 F src/tclsqlite.c 9923abeffc9b3d7dad58e92b319661521f60debf
-F src/test1.c 64912c1e65bdc3eccf3b80c5cc092b163831b367
+F src/test1.c cf222abaa6de1919bfd0c8ede4d280e4e368302b
 F src/test2.c 77b34303883b9d722c65a6879bb0163a400e3789
 F src/test3.c df62cd5c971dc1ae0be0a1842f9df3390934e7a6
 F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071
@@ -168,19 +168,19 @@ F src/update.c 31edd9c9764e80753930bd5f9b43e0edb404636f
 F src/utf.c ef4b7d83bae533b76c3e1bf635b113fdad86a736
 F src/util.c deda8c5a400530e1c27c03619cc4cd1a06fc5281
 F src/vacuum.c 3f34f278809bf3eb0b62ec46ff779e9c385b28f0
-F src/vdbe.c 986d1b4034e271c67f8cab0e03a5e459cb288ad7
+F src/vdbe.c 65a3ad903f1c7a0f6e557fdc7671c3cb2d70fa12
 F src/vdbe.h 58a7d931ffb704e034b2a725981cfa5bd406fad9
 F src/vdbeInt.h 835e6f0337ce89d705ef9a162338788808adc4b7
 F src/vdbeapi.c cb8c427a3ab646490c83204a98e94eff03ee2e89
-F src/vdbeaux.c 0d2a9730195d40f7d1156731bc69f240927255c5
+F src/vdbeaux.c e73c4ca5c8a66abfb06b5b543afe2819b55e35bf
 F src/vdbeblob.c e386d49d8354aa5a58f0a7f2794303442c149120
 F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6
 F src/vdbemem.c e15122efe8868e400c2aba8ea101588944e83317
 F src/vtab.c 9924e37cf7f5c527aeabb5da025874af505fb91d
-F src/where.c 0cc6052f73aef0d2ce59505d7ae06d6fbf696025
+F src/where.c 0c18a6d88d78886fd5f3c11ef2cf001321acd918
 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
-F test/all.test ee350b9ab15b175fc0a8fb51bf2141ed3a3b9cba
+F test/all.test d12210212bada2bde6d5aeb90969b86c1aa977d2
 F test/alter.test 345648dcd1801cc0287cd996076db512d1dcdabe
 F test/alter2.test 9d9850064b5c572991ea744a88ea650045f4ac6a
 F test/alter3.test 8ce6b9c5605b3cfe7b901f454ecaf174c4f93e31
@@ -222,7 +222,7 @@ F test/capi2.test cc64df7560a96f848f919ea2926c60acf639684b
 F test/capi3.test 432fabf9c6402ed8ff1ae291e01f0e04b64df3ea
 F test/capi3b.test 664eb55318132f292f2c436f90906f578cad6b97
 F test/capi3c.test 0b089837ee65a17dd73ea171c4dee5d7ea79dabb
-F test/cast.test c4780b58b569bab4947458195410ae8791ac216b
+F test/cast.test ce8f14fc80f70b30ed984480cc0d8914a459e8f9
 F test/check.test 024ed399600b799160378cf9d9f436bdf5dfd184
 F test/collate1.test e3eaa48c21e150814be1a7b852d2a8af24458d04
 F test/collate2.test 701d9651c5707024fd86a20649af9ea55e2c0eb8
@@ -262,7 +262,7 @@ F test/enc3.test 9331988b9d72decec96995c90637e87b00d747a5
 F test/exclusive.test ebaf72ce9ff8f7ab3a09bf8f58fd65393dfff386
 F test/exclusive2.test d13bf66753dca46e61241d35d36ab7c868b0d313
 F test/exclusive3.test 0e49c35b7e7cb8e7280b4ce3f0359d30b207d2ff
-F test/expr.test 31082f3f68aa0d07d1d49088d45ed18f4b792486
+F test/expr.test 6e666e5f47fbe6c23295d8c9f2b6c28109bf9ba8
 F test/filefmt.test 053b622009fbbb74dd37921ffad374d852c13cd8
 F test/fkey1.test dcb4f28eb22d5141f15161d6bdca9a4f58c95729
 F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb
@@ -320,14 +320,14 @@ F test/fuzz.test 62fc19dd36a427777fd671b569df07166548628a
 F test/fuzz2.test ea38692ce2da99ad79fe0be5eb1a452c1c4d37bb
 F test/fuzz_common.tcl ff4bc2dfc465f6878f8e2d819620914365382731
 F test/fuzz_malloc.test 166b58dfd77cc04f6afeeaef0cfc1087abf134d1
-F test/hook.test 3870abead2ee75d2c03585c916256ca8b5584679
+F test/hook.test e17d4ed2843ba4ef9b234aa63e6f056bf88f9a19
 F test/icu.test e6bfae7f625c88fd14df6f540fe835bdfc1e4329
 F test/in.test 763a29007a4850d611ac4441bfa488fb9969ad30
 F test/in2.test b1f447f4f0f67e9f83ff931e7e2e30873f9ea055
 F test/in3.test 2f829007cc8d25d17b859f7fe882ef2bd2e2eb49
 F test/incrblob.test 854c23b7ff8dd3822f675936b22c094655b3c739
 F test/incrblob_err.test 5273097dc7c97f9b7008423a6ffd5c80d21923cb
-F test/incrvacuum.test 1ed44535e89a0fa10c48c1aa0a3d48ee72bcc733
+F test/incrvacuum.test 9f49457edc25229e43ed29849d4ce4c3e67387b0
 F test/incrvacuum2.test a958e378c193c4012cb3787804d863487f1dfad1
 F test/incrvacuum_ioerr.test cb331403b8dea3c5bae6163861ff25037b0df56a
 F test/index.test cbf301cdb2da43e4eac636c3400c2439af1834ad
@@ -386,7 +386,7 @@ F test/minmax2.test 33504c01a03bd99226144e4b03f7631a274d66e0
 F test/minmax3.test 5b89f055df7ed03334e96eec0efb804afb7de638
 F test/misc1.test 1b89c02c4a33b49dee4cd1d20d161aaaba719075
 F test/misc2.test 1ee89298de9c16b61454658b24999c403e86afe4
-F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
+F test/misc3.test 7952978e14c0a1b52c6fc983af0f4d785d57f065
 F test/misc4.test 91e8ed25c092c2bb4e0bb01864631e2930f8d7de
 F test/misc5.test b0b4b7e0dd5d40335c8e849e5738d11a40bddc7c
 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
@@ -411,7 +411,7 @@ F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
 F test/rdonly.test b34db316525440d3b42c32e83942c02c37d28ef0
 F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b
 F test/rollback.test 0bd29070ba2f76da939347773fbda53337ebd61c
-F test/rowid.test d125991eea1ffdea800d48471afd8fc4acc10b01
+F test/rowid.test 1c8fc43c60d273e6ea44dfb992db587f3164312c
 F test/safety.test 4a06934e45d03b8b50ebcd8d174eb0367d2fd851
 F test/schema.test a8b000723375fd42c68d310091bdbd744fde647c
 F test/schema2.test 35e1c9696443d6694c8980c411497c2b5190d32e
@@ -431,7 +431,7 @@ F test/shared_err.test 202ce115a4bfab2b41da5d4c9431f68a474134a6
 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
 F test/sidedelete.test 736ac1da08b3b1aa62df97fef2fcdb1b660111b9
 F test/soak.test 64f9b27fbcdec43335a88c546ce1983e6ba40d7b
-F test/softheap1.test 29cbdb847e63ffef3af5da1e3cd15f44ee11d770
+F test/softheap1.test c9146eda576eedb62192b771293a2115d9af8456
 F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
 F test/speed1.test 22e1b27af0683ed44dcd2f93ed817a9c3e65084a
 F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded
@@ -446,7 +446,7 @@ F test/table.test 13b1c2e2fb4727b35ee1fb7641fc469214fd2455
 F test/tableapi.test 92651a95c23cf955e92407928e640536402fa3cc
 F test/tclsqlite.test 3fac87cb1059c46b8fa8a60b553f4f1adb0fb6d9
 F test/temptable.test 19b851b9e3e64d91e9867619b2a3f5fffee6e125
-F test/tester.tcl 493be4c2f8f4ea561d91c448b37da2d30fedb3f9
+F test/tester.tcl 6a6600646341b910f2fbfd02db1ef0274479366c
 F test/thread001.test 8fbd9559da0bbdc273e00318c7fd66c162020af7
 F test/thread002.test 2c4ad2c386f60f6fe268cd91c769ee35b3c1fd0b
 F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
@@ -607,7 +607,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 5aef5b0dd8e44a56f84fbc6f843016bca5101987
-R 07faac02e9ea2890001493a3c96130c4
+P d9ebe9d78c558af050c44ac4437ce0ef8193a4a8
+R 94e60cf83c5be7070b2e0c99c104b013
 U drh
-Z 11b35796b0f55998b3b3bad35c703ebb
+Z 37d21009eb42b23cbb42db5cde98321f
index 0cef15c1014068b0e9ae801c7198448a4d21f36a..fe3ace84f0f72df0fe01167dcef3c171f2ca5019 100644 (file)
@@ -1 +1 @@
-d9ebe9d78c558af050c44ac4437ce0ef8193a4a8
\ No newline at end of file
+af129b6d158cc90ce9752dd6383c1de47f7b3e43
\ No newline at end of file
index 2f92d2ef28f28e35eec9872dfa82d340d3196149..796a7afe7a499d9c9608161327ece9d3f08a5ffd 100644 (file)
@@ -88,6 +88,8 @@ END {
   max = 0
   print "/* Automatically generated.  Do not edit */"
   print "/* See the mkopcodeh.awk script for details */"
+  op["OP_Noop"] = -1;
+  op["OP_Explain"] = -1;
   for(name in op){
     if( op[name]<0 ){
       cnt++
index b5ad630bf3fe4d63368abe194a78cace3bea0c38..018593bee7f1366323f96cb86046ab6594c74aac 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test1.c,v 1.282 2008/01/16 17:46:38 drh Exp $
+** $Id: test1.c,v 1.283 2008/01/19 20:11:26 drh Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -4220,8 +4220,49 @@ static int vfs_unlink_test(
   Tcl_Obj *CONST objv[]  /* Command arguments */
 ){
   int i;
+  sqlite3_vfs *pMain;
   sqlite3_vfs *apVfs[20];
+  sqlite3_vfs one, two;
 
+  sqlite3_vfs_unregister(0);   /* Unregister of NULL is harmless */
+  one.zName = "__one";
+  two.zName = "__two";
+
+  /* Calling sqlite3_vfs_register with 2nd argument of 0 does not
+  ** change the default VFS
+  */
+  pMain = sqlite3_vfs_find(0);
+  sqlite3_vfs_register(&one, 0);
+  assert( pMain==0 || pMain==sqlite3_vfs_find(0) );
+  sqlite3_vfs_register(&two, 0);
+  assert( pMain==0 || pMain==sqlite3_vfs_find(0) );
+
+  /* We can find a VFS by its name */
+  assert( sqlite3_vfs_find("__one")==&one );
+  assert( sqlite3_vfs_find("__two")==&two );
+
+  /* Calling sqlite_vfs_register with non-zero second parameter changes the
+  ** default VFS, even if the 1st parameter is an existig VFS that is
+  ** previously registered as the non-default.
+  */
+  sqlite3_vfs_register(&one, 1);
+  assert( sqlite3_vfs_find("__one")==&one );
+  assert( sqlite3_vfs_find("__two")==&two );
+  assert( sqlite3_vfs_find(0)==&one );
+  sqlite3_vfs_register(&two, 1);
+  assert( sqlite3_vfs_find("__one")==&one );
+  assert( sqlite3_vfs_find("__two")==&two );
+  assert( sqlite3_vfs_find(0)==&two );
+  if( pMain ){
+    sqlite3_vfs_register(pMain, 1);
+    assert( sqlite3_vfs_find("__one")==&one );
+    assert( sqlite3_vfs_find("__two")==&two );
+    assert( sqlite3_vfs_find(0)==pMain );
+  }
+  
+  /* Unlink the default VFS.  Repeat until there are no more VFSes
+  ** registered.
+  */
   for(i=0; i<sizeof(apVfs)/sizeof(apVfs[0]); i++){
     apVfs[i] = sqlite3_vfs_find(0);
     if( apVfs[i] ){
@@ -4231,6 +4272,8 @@ static int vfs_unlink_test(
     }
   }
   assert( 0==sqlite3_vfs_find(0) );
+
+  /* Relink all VFSes in reverse order. */  
   for(i=sizeof(apVfs)/sizeof(apVfs[0])-1; i>=0; i--){
     if( apVfs[i] ){
       sqlite3_vfs_register(apVfs[i], 1);
@@ -4238,6 +4281,21 @@ static int vfs_unlink_test(
       assert( apVfs[i]==sqlite3_vfs_find(apVfs[i]->zName) );
     }
   }
+
+  /* Unregister out sample VFSes. */
+  sqlite3_vfs_unregister(&one);
+  sqlite3_vfs_unregister(&two);
+
+  /* Unregistering a VFS that is not currently registered is harmless */
+  sqlite3_vfs_unregister(&one);
+  sqlite3_vfs_unregister(&two);
+  assert( sqlite3_vfs_find("__one")==0 );
+  assert( sqlite3_vfs_find("__two")==0 );
+
+  /* We should be left with the original default VFS back as the
+  ** original */
+  assert( sqlite3_vfs_find(0)==pMain );
+
   return TCL_OK;
 }
 
index 76c505e15db94be2adc0d0190b77eecffcc3fdf4..9f606a045ab58d6e93b55a7ffe0176f020e27276 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.700 2008/01/19 03:35:59 drh Exp $
+** $Id: vdbe.c,v 1.701 2008/01/19 20:11:26 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -2697,6 +2697,13 @@ case OP_Close: {
 ** If there are no records greater than or equal to the key and P2 
 ** is not zero, then jump to P2.
 **
+** A special feature of this opcode (and different from the
+** related OP_MoveGt, OP_MoveLt, and OP_MoveLe) is that if P2 is
+** zero and P1 is an SQL table (a b-tree with integer keys) then
+** the seek is deferred until it is actually needed.  It might be
+** the case that the cursor is never accessed.  By deferring the
+** seek, we avoid unnecessary seeks.
+**
 ** See also: Found, NotFound, Distinct, MoveLt, MoveGt, MoveLe
 */
 /* Opcode: MoveGt P1 P2 P3 * *
@@ -2704,7 +2711,7 @@ case OP_Close: {
 ** Use the value in register P3 as a key.  Reposition
 ** cursor P1 so that it points to the smallest entry that is greater
 ** than the key in register P3.
-** If there are no records greater than the key and P2 is not zero,
+** If there are no records greater than the key 
 ** then jump to P2.
 **
 ** See also: Found, NotFound, Distinct, MoveLt, MoveGe, MoveLe
@@ -2714,7 +2721,7 @@ case OP_Close: {
 ** Use the value in register P3 as a key.  Reposition
 ** cursor P1 so that it points to the largest entry that is less
 ** than the key in register P3.
-** If there are no records less than the key and P2 is not zero,
+** If there are no records less than the key
 ** then jump to P2.
 **
 ** See also: Found, NotFound, Distinct, MoveGt, MoveGe, MoveLe
@@ -2724,7 +2731,7 @@ case OP_Close: {
 ** Use the value in register P3 as a key.  Reposition
 ** cursor P1 so that it points to the largest entry that is less than
 ** or equal to the key.
-** If there are no records less than or eqal to the key and P2 is not zero,
+** If there are no records less than or eqal to the key
 ** then jump to P2.
 **
 ** See also: Found, NotFound, Distinct, MoveGt, MoveGe, MoveLt
@@ -2746,8 +2753,10 @@ case OP_MoveGt: {       /* jump, in3 */
     *pC->pIncrKey = oc==OP_MoveGt || oc==OP_MoveLe;
     if( pC->isTable ){
       i64 iKey = sqlite3VdbeIntValue(pIn3);
-      if( pOp->p2==0 && pOp->opcode==OP_MoveGe ){
+      if( pOp->p2==0 ){
+        assert( pOp->opcode==OP_MoveGe );
         pC->movetoTarget = iKey;
+        pC->rowidIsValid = 0;
         pC->deferredMoveto = 1;
         break;
       }
@@ -2793,12 +2802,9 @@ case OP_MoveGt: {       /* jump, in3 */
         res = sqlite3BtreeEof(pC->pCursor);
       }
     }
+    assert( pOp->p2>0 );
     if( res ){
-      if( pOp->p2>0 ){
-        pc = pOp->p2 - 1;
-      }else{
-        pC->nullRow = 1;
-      }
+      pc = pOp->p2 - 1;
     }
   }
   break;
@@ -3006,7 +3012,7 @@ case OP_NotExists: {        /* jump, in3 */
     ** running ioerr.test and similar failure-recovery test scripts.) */
     if( res!=0 ){
       pc = pOp->p2 - 1;
-      pC->rowidIsValid = 0;
+      assert( pC->rowidIsValid==0 );
     }
   }
   break;
@@ -3156,19 +3162,17 @@ case OP_NewRowid: {           /* out2-prerelease */
       v = db->priorNewRowid;
       cnt = 0;
       do{
-        if( v==0 || cnt>2 ){
+        if( cnt==0 && (v&0xffffff)==v ){
+          v++;
+        }else{
           sqlite3Randomness(sizeof(v), &v);
           if( cnt<5 ) v &= 0xffffff;
-        }else{
-          unsigned char r;
-          sqlite3Randomness(1, &r);
-          v += r + 1;
         }
         if( v==0 ) continue;
         x = intToKey(v);
         rx = sqlite3BtreeMoveto(pC->pCursor, 0, (u64)x, 0, &res);
         cnt++;
-      }while( cnt<1000 && rx==SQLITE_OK && res==0 );
+      }while( cnt<100 && rx==SQLITE_OK && res==0 );
       db->priorNewRowid = v;
       if( rx==SQLITE_OK && res==0 ){
         rc = SQLITE_FULL;
@@ -3294,46 +3298,45 @@ case OP_Insert: {
 ** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is
 ** incremented (otherwise not).
 **
-** If P1 is a pseudo-table, then this instruction is a no-op.
+** P1 must not be pseudo-table.  It has to be a real table with
+** multiple rows.
+**
+** If P4 is not NULL, then it is the name of the table that P1 is
+** pointing to.  The update hook will be invoked, if it exists.
+** If P4 is not NULL then the P1 cursor must have been positioned
+** using OP_NotFound prior to invoking this opcode.
 */
 case OP_Delete: {
   int i = pOp->p1;
+  i64 iKey;
   Cursor *pC;
+
   assert( i>=0 && i<p->nCursor );
   pC = p->apCsr[i];
   assert( pC!=0 );
-  if( pC->pCursor!=0 ){
-    i64 iKey;
+  assert( pC->pCursor!=0 );  /* Only valid for real tables, no pseudotables */
 
-    /* If the update-hook will be invoked, set iKey to the rowid of the
-    ** row being deleted.
-    */
-    if( db->xUpdateCallback && pOp->p4.z ){
-      assert( pC->isTable );
-      if( pC->rowidIsValid ){
-        iKey = pC->lastRowid;
-      }else{
-        rc = sqlite3BtreeKeySize(pC->pCursor, &iKey);
-        if( rc ){
-          goto abort_due_to_error;
-        }
-        iKey = keyToInt(iKey);
-      }
-    }
+  /* If the update-hook will be invoked, set iKey to the rowid of the
+  ** row being deleted.
+  */
+  if( db->xUpdateCallback && pOp->p4.z ){
+    assert( pC->isTable );
+    assert( pC->rowidIsValid );  /* lastRowid set by previous OP_NotFound */
+    iKey = pC->lastRowid;
+  }
 
-    rc = sqlite3VdbeCursorMoveto(pC);
-    if( rc ) goto abort_due_to_error;
-    rc = sqlite3BtreeDelete(pC->pCursor);
-    pC->nextRowidValid = 0;
-    pC->cacheStatus = CACHE_STALE;
+  rc = sqlite3VdbeCursorMoveto(pC);
+  if( rc ) goto abort_due_to_error;
+  rc = sqlite3BtreeDelete(pC->pCursor);
+  pC->nextRowidValid = 0;
+  pC->cacheStatus = CACHE_STALE;
 
-    /* Invoke the update-hook if required. */
-    if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
-      const char *zDb = db->aDb[pC->iDb].zName;
-      const char *zTbl = pOp->p4.z;
-      db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, iKey);
-      assert( pC->iDb>=0 );
-    }
+  /* Invoke the update-hook if required. */
+  if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
+    const char *zDb = db->aDb[pC->iDb].zName;
+    const char *zTbl = pOp->p4.z;
+    db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, iKey);
+    assert( pC->iDb>=0 );
   }
   if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
   break;
@@ -4713,10 +4716,19 @@ case OP_Trace: {
 }
 #endif
 
-/* An other opcode is illegal...
+
+/* Opcode: Noop * * * * *
+**
+** Do nothing.  This instruction is often useful as a jump
+** destination.
+*/
+/*
+** The magic Explain opcode are only inserted when explain==2 (which
+** is to say when the EXPLAIN QUERY PLAN syntax is used.)
+** This opcode records information from the optimizer.  It is the
+** the same as a no-op.  This opcodesnever appears in a real VM program.
 */
-default: {
-  assert( 0 );
+default: {          /* This is really OP_Noop and OP_Explain */
   break;
 }
 
index 66160ef54f456124eca6f0873356b783950ad20c..ecb74b4678b99f33fe75e791deff23c54bd107c5 100644 (file)
@@ -511,14 +511,16 @@ void sqlite3VdbeChangeToNoop(Vdbe *p, int addr, int N){
 */
 void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
   Op *pOp;
-  assert( p==0 || p->magic==VDBE_MAGIC_INIT );
-  if( p==0 || p->aOp==0 || p->db->mallocFailed ){
+  assert( p!=0 );
+  assert( p->magic==VDBE_MAGIC_INIT );
+  if( p->aOp==0 || p->db->mallocFailed ){
     if (n != P4_KEYINFO) {
       freeP4(n, (void*)*(char**)&zP4);
     }
     return;
   }
-  if( addr<0 || addr>=p->nOp ){
+  assert( addr<p->nOp );
+  if( addr<0 ){
     addr = p->nOp - 1;
     if( addr<0 ) return;
   }
@@ -540,13 +542,19 @@ void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
     pKeyInfo = sqlite3_malloc( nByte );
     pOp->p4.pKeyInfo = pKeyInfo;
     if( pKeyInfo ){
-      unsigned char *aSortOrder;
       memcpy(pKeyInfo, zP4, nByte);
+      /* In the current implementation, P4_KEYINFO is only ever used on
+      ** KeyInfo structures that have no aSortOrder component.  Elements
+      ** with an aSortOrder always use P4_KEYINFO_HANDOFF.  So we do not
+      ** need to bother with duplicating the aSortOrder. */
+      assert( pKeyInfo->aSortOrder==0 );
+#if 0
       aSortOrder = pKeyInfo->aSortOrder;
       if( aSortOrder ){
         pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
         memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
       }
+#endif
       pOp->p4type = P4_KEYINFO;
     }else{
       p->db->mallocFailed = 1;
index a1c48f1e92fab564e6da986a02f5d17ed13b94cb..1ad296e1332f4213b47ea925b45e4aa7efbb8851 100644 (file)
@@ -16,7 +16,7 @@
 ** so is applicable.  Because this module is responsible for selecting
 ** indices, you might also think of this module as the "query optimizer".
 **
-** $Id: where.c,v 1.283 2008/01/17 16:22:15 drh Exp $
+** $Id: where.c,v 1.284 2008/01/19 20:11:26 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -2556,7 +2556,7 @@ WhereInfo *sqlite3WhereBegin(
       }
       if( !omitTable ){
         sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, r1);
-        sqlite3VdbeAddOp3(v, OP_MoveGe, iCur, 0, r1);
+        sqlite3VdbeAddOp3(v, OP_MoveGe, iCur, 0, r1);  /* Deferred seek */
       }
       sqlite3ReleaseTempReg(pParse, r1);
 
@@ -2631,7 +2631,7 @@ WhereInfo *sqlite3WhereBegin(
       if( !omitTable ){
         r1 = sqlite3GetTempReg(pParse);
         sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, r1);
-        sqlite3VdbeAddOp3(v, OP_MoveGe, iCur, 0, r1);
+        sqlite3VdbeAddOp3(v, OP_MoveGe, iCur, 0, r1);  /* Deferred seek */
         sqlite3ReleaseTempReg(pParse, r1);
       }
       pLevel->p1 = iIdxCur;
index 03a24d865392fd44e1d400a63441e7db94766b4d..d0dd79a63e6c593990b325958c21a629d6fdbf0f 100644 (file)
@@ -10,7 +10,7 @@
 #***********************************************************************
 # This file runs all tests.
 #
-# $Id: all.test,v 1.52 2007/11/27 14:46:42 drh Exp $
+# $Id: all.test,v 1.53 2008/01/19 20:11:26 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -92,6 +92,7 @@ for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} {
     set tail [file tail $testfile]
     if {[lsearch -exact $EXCLUDE $tail]>=0} continue
     if {[llength $INCLUDE]>0 && [lsearch -exact $INCLUDE $tail]<0} continue
+    reset_prng_state
     source $testfile
     catch {db close}
     if {$sqlite_open_file_count>0} {
index fc0f74b70b9a3b2c3a48f668f445fef11c1bbc56..10db5f8522da6c0e4eea208c02fcf6e0aca5f3a7 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the CAST operator.
 #
-# $Id: cast.test,v 1.8 2007/08/13 15:18:28 drh Exp $
+# $Id: cast.test,v 1.9 2008/01/19 20:11:26 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -183,6 +183,38 @@ do_test cast-1.53 {
   execsql {SELECT CAST('123.5abc' AS integer)}
 } 123
 
+do_test case-1.60 {
+  execsql {SELECT CAST(null AS REAL)}
+} {{}}
+do_test case-1.61 {
+  execsql {SELECT typeof(CAST(null AS REAL))}
+} {null}
+do_test case-1.62 {
+  execsql {SELECT CAST(1 AS REAL)}
+} {1.0}
+do_test case-1.63 {
+  execsql {SELECT typeof(CAST(1 AS REAL))}
+} {real}
+do_test case-1.64 {
+  execsql {SELECT CAST('1' AS REAL)}
+} {1.0}
+do_test case-1.65 {
+  execsql {SELECT typeof(CAST('1' AS REAL))}
+} {real}
+do_test case-1.66 {
+  execsql {SELECT CAST('abc' AS REAL)}
+} {0.0}
+do_test case-1.67 {
+  execsql {SELECT typeof(CAST('abc' AS REAL))}
+} {real}
+do_test case-1.68 {
+  execsql {SELECT CAST(x'31' AS REAL)}
+} {1.0}
+do_test case-1.69 {
+  execsql {SELECT typeof(CAST(x'31' AS REAL))}
+} {real}
+
+
 # Ticket #1662.  Ignore leading spaces in numbers when casting.
 #
 do_test cast-2.1 {
index 0f03fd9f6ca1da75feb8cd5ed950c3f63b6c2b04..3fb6adf2ca7ca287d50db06e127489347ab681f1 100644 (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.60 2008/01/16 18:20:42 danielk1977 Exp $
+# $Id: expr.test,v 1.61 2008/01/19 20:11:26 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -72,6 +72,7 @@ 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.44b {i1=NULL} {~i1} {{}}
 test_expr expr-1.45 {i1=1, i2=3} {i1<<i2} {8}
 test_expr expr-1.46 {i1=32, i2=3} {i1>>i2} {4}
 test_expr expr-1.47 {i1=9999999999, i2=8888888888} {i1<i2} 0
@@ -141,6 +142,8 @@ test_expr expr-1.105 {i1=0} {(-9223372036854775808.0 / -1)>1} 1
 
 test_expr expr-1.106 {i1=0} {(1<<63)/-1} -9223372036854775808
 test_expr expr-1.107 {i1=0} {(1<<63)%-1} 0
+test_expr expr-1.108 {i1=0} {1%0} {{}}
+test_expr expr-1.109 {i1=0} {1/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
@@ -169,6 +172,8 @@ test_expr expr-2.23 {r1=1.23, r2=2.34} {max(r1,r2,r1+r2,r1-r2)} {3.57}
 test_expr expr-2.24 {r1=25.0, r2=11.0} {r1%r2} 3.0
 test_expr expr-2.25 {r1=1.23, r2=NULL} {coalesce(r1+r2,99.0)} 99.0
 test_expr expr-2.26 {r1=1e300, r2=1e300} {coalesce((r1*r2)*0.0,99.0)} 99.0
+test_expr expr-2.27 {r1=1.1, r2=0.0} {r1/r2} {{}}
+test_expr expr-2.28 {r1=1.1, r2=0.0} {r1%r2} {{}}
 
 test_expr expr-3.1 {t1='abc', t2='xyz'} {t1<t2} 1
 test_expr expr-3.2 {t1='xyz', t2='abc'} {t1<t2} 0
index f70a73df24a0f05a5ef57a8e212d38b48fcf5b62..39892b32315eaffb545bc0a81bdca6cb2f00da56 100644 (file)
@@ -17,7 +17,7 @@
 #      sqlite_update_hook    (tests hook-4-*)
 #      sqlite_rollback_hook  (tests hook-5.*)
 #
-# $Id: hook.test,v 1.12 2007/10/09 08:29:32 danielk1977 Exp $
+# $Id: hook.test,v 1.13 2008/01/19 20:11:26 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -137,6 +137,24 @@ do_test hook-4.1.2 {
     DELETE main t1 4 \
 ]
 
+# Update hook is not invoked for changes to sqlite_master
+#
+do_test hook-4.1.3 {
+  set ::update_hook {}
+  execsql {
+    CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN SELECT RAISE(IGNORE); END;
+  }
+  set ::update_hook
+} {}
+do_test hook-4.1.4 {
+  set ::update_hook {}
+  execsql {
+    DROP TRIGGER r1;
+  }
+  set ::update_hook
+} {}
+
+
 set ::update_hook {}
 ifcapable trigger {
   do_test hook-4.2.1 {
index ace4245fc0ef8de5f8a8e01092d632d7e07e77b0..c50ee269dc4a0224b2738e8479a8d4f66f9b481d 100644 (file)
@@ -14,7 +14,7 @@
 # Note: There are also some tests for incremental vacuum and IO 
 # errors in incrvacuum_ioerr.test.
 #
-# $Id: incrvacuum.test,v 1.16 2007/12/13 21:54:11 drh Exp $
+# $Id: incrvacuum.test,v 1.17 2008/01/19 20:11:26 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -549,7 +549,6 @@ do_test incrvacuum-10.4 {
 } {22}
 
 do_test incrvacuum-10.5 {
-breakpoint
   execsql {
     PRAGMA incremental_vacuum("+3");
   }
@@ -572,6 +571,19 @@ do_test incrvacuum-10.7 {
   expr [file size test.db] / 1024
 } {1}
 
+do_test incrvacuum-10.8 {
+  execsql {
+    CREATE TABLE t1(x);
+    INSERT INTO t1 VALUES(hex(randomblob(1000)));
+    DROP TABLE t1;
+  }
+  # A negative number means free all possible space.
+  execsql {
+    PRAGMA incremental_vacuum=-1;
+  }
+  expr [file size test.db] / 1024
+} {1}
+
 #----------------------------------------------------------------
 # Test that if we set the auto_vacuum mode to 'incremental', then
 # create a database, thereafter that database defaults to incremental 
index cd76335a5b584e7ec48128b7450561a04993f25d..01d525af45c760e5b6f004e5e4182ab8eb135003 100644 (file)
@@ -13,7 +13,7 @@
 # This file implements tests for miscellanous features that were
 # left out of other test files.
 #
-# $Id: misc3.test,v 1.16 2005/01/21 03:12:16 danielk1977 Exp $
+# $Id: misc3.test,v 1.17 2008/01/19 20:11:26 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -258,6 +258,26 @@ ifcapable {explain} {
     execsql {BEGIN; EXPLAIN ROLLBACK}
     catchsql {ROLLBACK}
   } {0 {}}
+
+  # Do some additional EXPLAIN operations to exercise the displayP4 logic.
+  do_test misc3-6.10 {
+    set x [execsql {
+      CREATE TABLE ex1(a INTEGER, b TEXT DEFAULT "hello", c);
+      CREATE UNIQUE INDEX ex1i1 ON ex1(a);
+      EXPLAIN REINDEX;
+    }]
+    regexp { IsUnique \d+ \d+ \d+ \d+ } $x
+  } {1}
+  do_test misc3-6.11 {
+    set x [execsql {
+      EXPLAIN SELECT a+123456789012, b*4.5678, c FROM ex1 ORDER BY a, b DESC
+    }]
+    set y [regexp { 123456789012 } $x]
+    lappend y [regexp { 4.5678 } $x]
+    lappend y [regexp { hello } $x]
+    lappend y [regexp {,-BINARY} $x]
+  } {1 1 1 1}
+
 }
 
 ifcapable {trigger} {
index 9048cc8d100a6ea18199fe6d6357a5a79eb91ddb..24dcd2a657d0b164740805de71f0898e81337c28 100644 (file)
@@ -12,7 +12,7 @@
 # focus of this file is testing the magic ROWID column that is
 # found on all tables.
 #
-# $Id: rowid.test,v 1.19 2007/04/25 11:32:30 drh Exp $
+# $Id: rowid.test,v 1.20 2008/01/19 20:11:26 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -657,6 +657,12 @@ do_test rowid-11.4 {
 # Test the automatic generation of rowids when the table already contains
 # a rowid with the maximum value.
 #
+# Once the the maximum rowid is taken, rowids are normally chosen at
+# random.  By by reseting the random number generator, we can cause
+# the rowid guessing loop to collide with prior rowids, and test the
+# loop out to its limit of 100 iterations.  After 100 collisions, the
+# rowid guesser gives up and reports SQLITE_FULL.
+#
 do_test rowid-12.1 {
   execsql {
     CREATE TABLE t7(x INTEGER PRIMARY KEY, y);
@@ -665,10 +671,31 @@ do_test rowid-12.1 {
   }
 } {a}
 do_test rowid-12.2 {
+  db close
+  sqlite3 db test.db
+  save_prng_state
   execsql {
     INSERT INTO t7 VALUES(NULL,'b');
-    SELECT y FROM t7;
+    SELECT x, y FROM t7;
+  }
+} {1 b 9223372036854775807 a}
+execsql {INSERT INTO t7 VALUES(2,'y');}
+for {set i 1} {$i<=101} {incr i} {
+  do_test rowid-12.3.$i {
+    restore_prng_state
+    execsql {
+      INSERT INTO t7 VALUES(NULL,'x');
+      INSERT OR IGNORE INTO t7 VALUES(last_insert_rowid()+1,'y');
+      SELECT count(*) FROM t7 WHERE y=='x';
+    }
+  } $i
+}
+do_test rowid-12.4 {
+  restore_prng_state
+  catchsql {
+    INSERT INTO t7 VALUES(NULL,'x');
   }
-} {b a}
+} {1 {database or disk is full}}
+
 
 finish_test
index 62b9251bd2c68ea8a70689ae69a9c8d2d679ddb3..f71fa9a8a7e07f4bab81e8de8edc87e9a523bc34 100644 (file)
@@ -13,7 +13,7 @@
 # A database corruption bug that occurs in auto_vacuum mode when
 # the soft_heap_limit is set low enough to be triggered.
 #
-# $Id: softheap1.test,v 1.3 2007/09/12 17:01:45 danielk1977 Exp $
+# $Id: softheap1.test,v 1.4 2008/01/19 20:11:26 drh Exp $
 
 
 set testdir [file dirname $argv0]
@@ -24,6 +24,8 @@ ifcapable !integrityck {
   return
 }
 
+sqlite3_soft_heap_limit -1
+sqlite3_soft_heap_limit 0
 sqlite3_soft_heap_limit 5000
 do_test softheap1-1.1 {
   execsql {
index 6c9aaeebbeeaee67708c039c651d222fb23b48e0..8adfbb795e3c63eb5d96d00bd71cec4a65be2de8 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements some common TCL routines used for regression
 # testing the SQLite library
 #
-# $Id: tester.tcl,v 1.101 2008/01/17 02:36:28 drh Exp $
+# $Id: tester.tcl,v 1.102 2008/01/19 20:11:26 drh Exp $
 
 
 set tcl_precision 15
@@ -221,7 +221,8 @@ proc finalize_testing {} {
       sqlite3_memdebug_dump ./memusage.txt
     }
   }
-  puts "Maximum memory usage: [sqlite3_memory_highwater] bytes"
+  puts "Maximum memory usage: [sqlite3_memory_highwater 1] bytes"
+  puts "Current memory usage: [sqlite3_memory_highwater] bytes"
   foreach f [glob -nocomplain test.db-*-journal] {
     file delete -force $f
   }