]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Coverage tests for vacuum.c (CVS 1776)
authordanielk1977 <danielk1977@noemail.net>
Wed, 30 Jun 2004 09:49:22 +0000 (09:49 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Wed, 30 Jun 2004 09:49:22 +0000 (09:49 +0000)
FossilOrigin-Name: 152e9940b919a53fcd0da4091dbf75ab8ef15b38

manifest
manifest.uuid
src/attach.c
src/main.c
src/pager.c
src/parse.y
src/pragma.c
src/vacuum.c
src/vdbe.c
test/malloc.test
test/vacuum.test

index 54e81350224a69c5979a1eb9622d809a95517fd8..f14466915f38f70641448c411a64e158b2ea8290 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fixes\sfor\scompiler\swarnings.\sAlso\smore\scoverage.\s(CVS\s1775)
-D 2004-06-30T08:20:16
+C Coverage\stests\sfor\svacuum.c\s(CVS\s1776)
+D 2004-06-30T09:49:23
 F Makefile.in cb7a9889c38723f72b2506c4236ff30a05ff172b
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -24,7 +24,7 @@ F spec.template a38492f1c1dd349fc24cb0565e08afc53045304b
 F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
 F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
 F sqlite3.def 26f4e7b0a3fbaa55701e020fdec429f1594e2866
-F src/attach.c 678ded370e4b4d5bf03e9566404a42a8dcf5eef9
+F src/attach.c 132498271187144919de139673ad648b8e82c77e
 F src/auth.c 60db23b98bb94c8b0178180faaf49dc116674217
 F src/btree.c 3ed3c19e43bb243f502ee614f6ad0a52e53362a7
 F src/btree.h 934d0ad30b5b419e9291a11da878be349df2277e
@@ -38,7 +38,7 @@ F src/hash.c 148e3512f1b4e90f8477f852c70b36a137b116a7
 F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb
 F src/insert.c d99ffe87e1e1397f4233afcd06841d52d6b17b18
 F src/legacy.c ad23746f15f67e34577621b1875f639c94839e1f
-F src/main.c 95a915b2fe9bd879aa47f80472654f11e033b7a6
+F src/main.c adb17bee0606a685d8872bdac9f23464e2c6a748
 F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
 F src/os.h d1780e0db95cad01f213d48da22ab490eb4fd345
 F src/os_common.h fe9604754116bd2f2702d58f82d2d8b89998cb21
@@ -50,10 +50,10 @@ F src/os_unix.c 7df6ae05faa5b84164193d3694cb71b66661bbf3
 F src/os_unix.h 00c1f82b526ab2fb7ee5ddd555ea4ed68363c93a
 F src/os_win.c 84549f6cc815237533c5d0eb3697352b03478d96
 F src/os_win.h babd4e912967c6b09088cfe38a45e8005a07ba44
-F src/pager.c c1d5212e7cac86bc1a29d01a30d9dbbdb545dfd8
+F src/pager.c 7f30e724959a04011dd077a923ea16b53561ee6c
 F src/pager.h 269b6cfc114dba0148203446e41dd19f9647dd53
-F src/parse.y e19e066e726a31d7b2d3e6475bdf55f7e339f8a3
-F src/pragma.c 0ecbe7ccf78ad893f5011516845c9e2f74faa21a
+F src/parse.y 51c8e696276c409618e66a4ccf316fcff245506e
+F src/pragma.c 8326df8c400f573eb43004dfb8e53e5102acb3e4
 F src/printf.c 3090c8ff397d549bc0de09b16d8ab7fd37a0c3f7
 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
 F src/select.c f02a65af34231031896e8442161cb5251e191e75
@@ -72,8 +72,8 @@ F src/trigger.c 6aaf6d79cc2157c70a06031dd1531707d644cfb4
 F src/update.c b66b1896c9da54678ba3eff2bf0b4d291a95986a
 F src/utf.c f03535db72bfa09e24202ccdd245f21d2fc65f0a
 F src/util.c b267d0fe10cffa3301fe9fab6592a6808a38bce6
-F src/vacuum.c 4aede0a7048d8b71a43f45cc15359e16eddc8a2e
-F src/vdbe.c 6950e25d93346b03404d2fc383883ff9fa2e5966
+F src/vacuum.c b8546f4921719458cc537b9e736df52a8256399c
+F src/vdbe.c 4629151c9995b8b6a895c42de8808df1969bdcc7
 F src/vdbe.h 75b241c02431b9c0f16eaa9cdbb34146c6287f52
 F src/vdbeInt.h d83fd7389838453d8392915c21f432014afc99cf
 F src/vdbeapi.c ba3722f45db3d3c3509bf5d24f4f868f4c64449d
@@ -130,7 +130,7 @@ F test/limit.test 60d7f856ee7846f7130dee67f10f0e726cd70b5d
 F test/lock.test 1dbf1d06b0a7eb36237b4f107cfb3da9726b449e
 F test/lock2.test 4108cabaa108a142e5eed83de3b13b6e579c12cf
 F test/main.test e8c4d9ca6d1e5f5e55e6550d31aec488883b2ed9
-F test/malloc.test a78617ce8258388e4835f4834a3a2c0d4282a7ec
+F test/malloc.test 769b240d89a7ef3320d88919fdb6765f9395a51f
 F test/memdb.test b8a13fa79f006bd087bbcf135ce8eb62056a6027
 F test/memleak.test 26571a04575461f39a7cf97a2ee2f7fb2f519ddb
 F test/minmax.test 3f87d1d49f7e9aa9ae80d35c47a1f5b034557899
@@ -175,7 +175,7 @@ F test/types2.test 5d725fcb68dbd032c6d4950d568d75fa33872687
 F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b
 F test/update.test b29bd9061a1150426dab6959806fcc73a41b1217
 F test/utf16.test 459c2f5ab80c60092c603630a348c32d6e59c558
-F test/vacuum.test 3922b97f958986a9ab198c30480f54361087a06f
+F test/vacuum.test 0416ace6131f3003d1e823f04ac0bb5b53315431
 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
 F test/view.test b42c98499ae9fbf578cd7a4b020d23057c8825fb
 F test/where.test 9c5752b807b78078fab8da6f52e689832579ca20
@@ -232,7 +232,7 @@ F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075
 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
 F www/version3.tcl 563ba3ac02f64da27ab17f3edbe8e56bfd0293fb
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P d256c14943968e7adf4b73988cac6af941c9b12d
-R 4f61ce2de075aff0c8e8c9f0f47fa953
+P fa19c77bf045787faa4cdc40bcfbd9eeae8594ae
+R 6e782cee555b8abc4fb19017e23b5110
 U danielk1977
-Z eeffb6cff58a960d2f9806fbf7046f4d
+Z 135637c42a81cf49b10a663d51dc227f
index 1757642141b39b6d5e838a7a42a4b12bfb785a18..ad2dc7166b9a835cf22a7f1d7da6742554035fea 100644 (file)
@@ -1 +1 @@
-fa19c77bf045787faa4cdc40bcfbd9eeae8594ae
\ No newline at end of file
+152e9940b919a53fcd0da4091dbf75ab8ef15b38
\ No newline at end of file
index c67468baec9aa22f006e2283567c7cab56e77d52..dcefb22346690babb5b493515589fe0fddadbd44 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to implement the ATTACH and DETACH commands.
 **
-** $Id: attach.c,v 1.20 2004/06/29 08:59:35 danielk1977 Exp $
+** $Id: attach.c,v 1.21 2004/06/30 09:49:23 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -31,6 +31,7 @@ void sqlite3Attach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey)
   Vdbe *v;
 
   v = sqlite3GetVdbe(pParse);
+  if( !v ) return;
   sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
   if( pParse->explain ) return;
   db = pParse->db;
@@ -140,6 +141,7 @@ void sqlite3Detach(Parse *pParse, Token *pDbname){
   Db *pDb = 0;
 
   v = sqlite3GetVdbe(pParse);
+  if( !v ) return;
   sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
   if( pParse->explain ) return;
   db = pParse->db;
index c2cb938f7b3870913995e7d15a1b636687287f2c..4909688da7b8e6766ad29d79babbed917ee98cd7 100644 (file)
@@ -14,7 +14,7 @@
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: main.c,v 1.242 2004/06/29 13:18:24 danielk1977 Exp $
+** $Id: main.c,v 1.243 2004/06/30 09:49:24 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -963,6 +963,10 @@ int sqlite3_prepare(
   char *zErrMsg = 0;
   int rc = SQLITE_OK;
 
+  if( sqlite3_malloc_failed ){
+    return SQLITE_NOMEM;
+  }
+
   assert( ppStmt );
   *ppStmt = 0;
   if( sqlite3SafetyOn(db) ){
index 085cf9f85e08cb63d4dbef283fa37d1c2114228b..94bdbda61cbcc5473792b1c12aad996efcc22e47 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.147 2004/06/28 04:52:30 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.148 2004/06/30 09:49:24 danielk1977 Exp $
 */
 #include "os.h"         /* Must be first to enable large file support */
 #include "sqliteInt.h"
@@ -2317,7 +2317,7 @@ static int pager_open_journal(Pager *pPager){
     pPager->aInJournal = 0;
     sqlite3OsUnlock(&pPager->fd, SHARED_LOCK);
     pPager->state = PAGER_SHARED;
-    return SQLITE_CANTOPEN;
+    return rc;
   }
   sqlite3OsOpenDirectory(pPager->zDirectory, &pPager->jfd);
   pPager->journalOpen = 1;
index 567d2280084db0861b9be99c9ca3e0883ea159a6..756b0c20d4a54707db8ec552ccd3688e0cac5ea6 100644 (file)
@@ -14,7 +14,7 @@
 ** the parser.  Lemon will also generate a header file containing
 ** numeric codes for all of the tokens.
 **
-** @(#) $Id: parse.y,v 1.128 2004/06/26 06:37:07 danielk1977 Exp $
+** @(#) $Id: parse.y,v 1.129 2004/06/30 09:49:24 danielk1977 Exp $
 */
 %token_prefix TK_
 %token_type {Token}
@@ -442,7 +442,7 @@ sortlist(A) ::= sortlist(X) COMMA sortitem(Y) collate(C) sortorder(Z). {
 }
 sortlist(A) ::= sortitem(Y) collate(C) sortorder(Z). {
   A = sqlite3ExprListAppend(0,Y,C.n>0?&C:0);
-  if( A ) A->a[0].sortOrder = Z;
+  if( A && A->a ) A->a[0].sortOrder = Z;
 }
 sortitem(A) ::= expr(X).   {A = X;}
 
index c685b811b87b04a6756560ad227fca584b15c5fd..411672a41694ed8c3731c7841104ce98d791acd3 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to implement the PRAGMA command.
 **
-** $Id: pragma.c,v 1.56 2004/06/29 08:59:35 danielk1977 Exp $
+** $Id: pragma.c,v 1.57 2004/06/30 09:49:24 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -148,6 +148,7 @@ void sqlite3Pragma(
   if( iDb<0 ) return;
 
   zLeft = sqlite3NameFromToken(pId);
+  if( !zLeft ) return;
   if( minusFlag ){
     zRight = 0;
     sqlite3SetNString(&zRight, "-", 1, pValue->z, pValue->n, 0);
index e2a26eaf909e3123ed8121db7bb7ebf8a4e5e632..79783d655db57c30ef9a6cf7d938f924ef210bf3 100644 (file)
@@ -14,7 +14,7 @@
 ** Most of the code in this file may be omitted by defining the
 ** SQLITE_OMIT_VACUUM macro.
 **
-** $Id: vacuum.c,v 1.25 2004/06/30 06:30:26 danielk1977 Exp $
+** $Id: vacuum.c,v 1.26 2004/06/30 09:49:24 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -82,7 +82,9 @@ static int execExecSql(sqlite3 *db, const char *zSql){
 */
 void sqlite3Vacuum(Parse *pParse, Token *pTableName){
   Vdbe *v = sqlite3GetVdbe(pParse);
-  sqlite3VdbeAddOp(v, OP_Vacuum, 0, 0);
+  if( v ){
+    sqlite3VdbeAddOp(v, OP_Vacuum, 0, 0);
+  }
   return;
 }
 
@@ -110,9 +112,13 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
   ** temporary filename in the same directory as the original file.
   */
   zFilename = sqlite3BtreeGetFilename(db->aDb[0].pBt);
-  if( zFilename==0 ){
-    /* The in-memory database. Do nothing. */
-    goto end_of_vacuum;
+  assert( zFilename );
+  if( zFilename[0]=='\0' ){
+    /* The in-memory database. Do nothing. Return directly to avoid causing
+    ** an error trying to DETACH the vacuum_db (which never got attached)
+    ** in the exit-handler.
+    */
+    return SQLITE_OK;
   }
   nFilename = strlen(zFilename);
   zTemp = sqliteMalloc( nFilename+100 );
@@ -121,11 +127,11 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
     goto end_of_vacuum;
   }
   strcpy(zTemp, zFilename);
-  for(i=0; i<10; i++){
+  i = 0;
+  do {
     zTemp[nFilename] = '-';
     randomName((unsigned char*)&zTemp[nFilename+1]);
-    if( !sqlite3OsFileExists(zTemp) ) break;
-  }
+  } while( i<10 && sqlite3OsFileExists(zTemp) );
 
   /* Attach the temporary database as 'vacuum_db'. The synchronous pragma
   ** can be set to 'off' for this file, as it is not recovered if a crash
@@ -136,7 +142,6 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
   ** An optimisation would be to use a non-journaled pager.
   */
   zSql = sqlite3MPrintf("ATTACH '%s' AS vacuum_db;", zTemp);
-  execSql(db, "PRAGMA vacuum_db.synchronous = off;");
   if( !zSql ){
     rc = SQLITE_NOMEM;
     goto end_of_vacuum;
@@ -145,6 +150,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite *db){
   sqliteFree(zSql);
   zSql = 0;
   if( rc!=SQLITE_OK ) goto end_of_vacuum;
+  execSql(db, "PRAGMA vacuum_db.synchronous = off;");
 
   /* Begin a transaction */
   rc = execSql(db, "BEGIN;");
@@ -231,7 +237,11 @@ end_of_vacuum:
   ** is closed by the DETACH.
   */
   db->autoCommit = 1;
-  execSql(db, "DETACH vacuum_db;");
+  if( rc==SQLITE_OK ){
+    rc = execSql(db, "DETACH vacuum_db;");
+  }else{
+    execSql(db, "DETACH vacuum_db;");
+  }
   if( zTemp ){
     sqlite3OsDelete(zTemp);
     sqliteFree(zTemp);
index 4fe0fe984206813328e3286f4cdd8eacac3081ee..13689f809067e319013b9e776eae9847ac192994 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.397 2004/06/30 06:30:26 danielk1977 Exp $
+** $Id: vdbe.c,v 1.398 2004/06/30 09:49:24 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -1248,6 +1248,7 @@ case OP_Function: {
   if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
   (*ctx.pFunc->xFunc)(&ctx, n, apVal);
   if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
+  if( sqlite3_malloc_failed ) goto no_mem;
   popStack(&pTos, n);
 
   /* If any auxilary data functions have been called by this user function,
index 319d8ad676d59dfb4f2a9010ccc1fd5603d3b5bf..ee9ae0274a06f0792463399178b194375b318552 100644 (file)
@@ -14,7 +14,7 @@
 # special feature is used to see what happens in the library if a malloc
 # were to really fail due to an out-of-memory situation.
 #
-# $Id: malloc.test,v 1.9 2004/06/26 13:51:34 danielk1977 Exp $
+# $Id: malloc.test,v 1.10 2004/06/30 09:49:24 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -263,5 +263,52 @@ do_test malloc-5.X {
   set sqlite_open_file_count
 } {0}
 
+for {set go 1; set i 1} {$go} {incr i} {
+  do_test malloc-6.$i {
+     sqlite_malloc_fail 0
+     catch {db close}
+     catch {file delete -force test.db}
+     catch {file delete -force test.db-journal}
+     sqlite3 db test.db
+     execsql {
+         BEGIN TRANSACTION;
+         CREATE TABLE t1(a);
+         INSERT INTO t1 VALUES(1);
+         INSERT INTO t1 SELECT a*2 FROM t1;
+         INSERT INTO t1 SELECT a*2 FROM t1;
+         INSERT INTO t1 SELECT a*2 FROM t1;
+         INSERT INTO t1 SELECT a*2 FROM t1;
+         INSERT INTO t1 SELECT a*2 FROM t1;
+         INSERT INTO t1 SELECT a*2 FROM t1;
+         INSERT INTO t1 SELECT a*2 FROM t1;
+         INSERT INTO t1 SELECT a*2 FROM t1;
+         INSERT INTO t1 SELECT a*2 FROM t1;
+         INSERT INTO t1 SELECT a*2 FROM t1;
+         DELETE FROM t1 where rowid%5 = 0;
+         COMMIT;
+     }
+     sqlite_malloc_fail $i
+     set v [catch {execsql {
+       VACUUM;
+     }} msg]
+     set leftover [lindex [sqlite_malloc_stat] 2]
+     if {$leftover>0} {
+       if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v  Message=$msg"}
+       set ::go 0
+       set v {1 1}
+     } else {
+       set v2 [expr {$msg=="" || $msg=="out of memory"}]
+       if {!$v2} {puts "\nError message returned: $msg"}
+       lappend v $v2
+     }
+  } {1 1}
+}
+
+# Ensure that no file descriptors were leaked.
+do_test malloc-6.X {
+  catch {db close}
+  set sqlite_open_file_count
+} {0}
+
 sqlite_malloc_fail 0
 finish_test
index d0aaa7bb36c52eb5a220edec36f5e9b85fc52e67..61c1028e809c57d6e8c154749f422682dc4dcd6e 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the VACUUM statement.
 #
-# $Id: vacuum.test,v 1.21 2004/06/19 00:16:32 drh Exp $
+# $Id: vacuum.test,v 1.22 2004/06/30 09:49:24 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -200,4 +200,13 @@ do_test vacuum-6.4 {
   }
 } {1}
 
+# Check what happens when an in-memory database is vacuumed.
+do_test vacuum-7.0 {
+  sqlite3 db2 :memory:
+  execsql {
+    CREATE TABLE t1(t);
+    VACUUM;
+  } db2
+} {}
+
 # finish_test