/ Check-in [3563e9cf]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3563e9cf9d6b20f09e92deb21fdda93bcd8fb583
User & Date: drh 2003-08-15 13:24:52
Context
2003-08-16
12:37
Do not delete tables with the same name when dropping triggers. Ticket #430. (CVS 1074) check-in: ef58f163 user: drh tags: trunk
2003-08-15
13:24
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) check-in: 3563e9cf user: drh tags: trunk
2003-08-13
11:29
Update the NULL-handling chart with new information about Firebird. (CVS 1072) check-in: 17bdfeb2 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vacuum.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the VACUUM command.
    13     13   **
    14     14   ** Most of the code in this file may be omitted by defining the
    15     15   ** SQLITE_OMIT_VACUUM macro.
    16     16   **
    17         -** $Id: vacuum.c,v 1.7 2003/05/13 00:21:59 drh Exp $
           17  +** $Id: vacuum.c,v 1.8 2003/08/15 13:24:52 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   
    22     22   /*
    23     23   ** A structure for holding a dynamic string - a string that can grow
    24     24   ** without bound. 
................................................................................
   107    107   */
   108    108   static int vacuumCallback2(void *pArg, int argc, char **argv, char **NotUsed){
   109    109     vacuumStruct *p = (vacuumStruct*)pArg;
   110    110     int rc = 0;
   111    111     const char *zSep = "(";
   112    112     int i;
   113    113   
          114  +  if( argv==0 ) return 0;
   114    115     p->s2.nUsed = 0;
   115    116     appendText(&p->s2, "INSERT INTO ", -1);
   116    117     appendQuoted(&p->s2, p->zTable);
   117    118     appendText(&p->s2, " VALUES", -1);
   118    119     for(i=0; i<argc; i++){
   119    120       appendText(&p->s2, zSep, 1);
   120    121       zSep = ",";
................................................................................
   137    138   ** For tables, run a query to select all entries in that table and 
   138    139   ** transfer them to the second-stage callback.
   139    140   */
   140    141   static int vacuumCallback1(void *pArg, int argc, char **argv, char **NotUsed){
   141    142     vacuumStruct *p = (vacuumStruct*)pArg;
   142    143     int rc = 0;
   143    144     assert( argc==3 );
          145  +  if( argv==0 ) return 0;
   144    146     assert( argv[0]!=0 );
   145    147     assert( argv[1]!=0 );
   146    148     assert( argv[2]!=0 );
   147    149     rc = execsql(p->pParse, p->dbNew, argv[2]);
   148    150     if( rc==SQLITE_OK && strcmp(argv[0],"table")==0 ){
   149    151       char *zErrMsg = 0;
   150    152       p->s1.nUsed = 0;
................................................................................
   165    167   ** identified by ((vacuumStruct*)pArg)->zPragma.
   166    168   */
   167    169   static int vacuumCallback3(void *pArg, int argc, char **argv, char **NotUsed){
   168    170     vacuumStruct *p = (vacuumStruct*)pArg;
   169    171     int rc = 0;
   170    172     char zBuf[200];
   171    173     assert( argc==1 );
          174  +  if( argv==0 ) return 0;
   172    175     assert( argv[0]!=0 );
   173    176     assert( strlen(p->zPragma)<100 );
   174    177     assert( strlen(argv[0])<30 );
   175    178     sprintf(zBuf,"PRAGMA %s=%s;", p->zPragma, argv[0]);
   176    179     rc = execsql(p->pParse, p->dbNew, zBuf);
   177    180     return rc;
   178    181   }

Changes to test/vacuum.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing the VACUUM statement.
    13     13   #
    14         -# $Id: vacuum.test,v 1.10 2003/04/25 13:28:03 drh Exp $
           14  +# $Id: vacuum.test,v 1.11 2003/08/15 13:24:53 drh Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   proc cksum {{db db}} {
    20     20     set txt [$db eval {SELECT name, type, sql FROM sqlite_master}]\n
    21     21     foreach tbl [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
................................................................................
   116    116     cksum
   117    117   } $cksum
   118    118   do_test vacuum-2.4 {
   119    119     catch {db2 eval {SELECT count(*) FROM sqlite_master}}
   120    120     cksum db2
   121    121   } $cksum
   122    122   
          123  +# Ticket #427.  Make sure VACUUM works when the EMPTY_RESULT_CALLBACKS
          124  +# pragma is turned on.
          125  +#
          126  +do_test vacuum-3.1 {
          127  +  db close
          128  +  file delete test.db
          129  +  sqlite db test.db
          130  +  execsql {
          131  +    PRAGMA empty_result_callbacks=on;
          132  +    VACUUM;
          133  +  }
          134  +} {}
   123    135   
   124    136   catch {db2 close}
   125    137   
   126    138   # finish_test