/ Check-in [d596f513]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Improvements to testing of sqlite_interrupt. More checking for interrupt inside of VACUUM. (CVS 1344)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | version_2
Files: files | file ages | folders
SHA1: d596f513c3acfe0d297dc3f5c66f4b0ea2d12a34
User & Date: drh 2004-05-10 20:27:41
Context
2004-06-04
19:07
Calling sqlite_interrupt() while VACUUM is running should not cause an error. (CVS 1529) check-in: 1cf94a7c user: drh tags: version_2
2004-05-10
20:27
Improvements to testing of sqlite_interrupt. More checking for interrupt inside of VACUUM. (CVS 1344) check-in: d596f513 user: drh tags: version_2
2004-05-07
01:46
Fix a memory leak in DETACH when using the codec. (CVS 1317) check-in: c4bd99b7 user: drh tags: version_2
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.13 2004/03/10 18:57:32 drh Exp $
           17  +** $Id: vacuum.c,v 1.13.2.1 2004/05/10 20:27:41 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. 
................................................................................
   234    234        /* "default_temp_store", */
   235    235     };
   236    236   
   237    237     if( db->flags & SQLITE_InTrans ){
   238    238       sqliteSetString(pzErrMsg, "cannot VACUUM from within a transaction", 
   239    239          (char*)0);
   240    240       return SQLITE_ERROR;
          241  +  }
          242  +  if( db->flags & SQLITE_Interrupt ){
          243  +    return SQLITE_INTERRUPT;
   241    244     }
   242    245     memset(&sVac, 0, sizeof(sVac));
   243    246   
   244    247     /* Get the full pathname of the database file and create two
   245    248     ** temporary filenames in the same directory as the original file.
   246    249     */
   247    250     zFilename = sqliteBtreeGetFilename(db->aDb[0].pBt);
................................................................................
   304    307   
   305    308   end_of_vacuum:
   306    309     if( rc && zErrMsg!=0 ){
   307    310       sqliteSetString(pzErrMsg, "unable to vacuum database - ", 
   308    311          zErrMsg, (char*)0);
   309    312     }
   310    313     sqlite_exec(db, "ROLLBACK", 0, 0, 0);
          314  +  if( (dbNew && (dbNew->flags & SQLITE_Interrupt)) 
          315  +         || (db->flags & SQLITE_Interrupt) ){
          316  +    rc = SQLITE_INTERRUPT;
          317  +  }
   311    318     if( dbNew ) sqlite_close(dbNew);
   312    319     sqliteOsDelete(zTemp);
   313    320     sqliteFree(zTemp);
   314    321     sqliteFree(sVac.s1.z);
   315    322     sqliteFree(sVac.s2.z);
   316    323     if( zErrMsg ) sqlite_freemem(zErrMsg);
   317         -  if( rc==SQLITE_ABORT ) sVac.rc = SQLITE_ERROR;
          324  +  if( rc==SQLITE_ABORT && sVac.rc==SQLITE_OK ) sVac.rc = SQLITE_ERROR;
   318    325     return sVac.rc;
   319    326   #endif
   320    327   }

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.268.2.1 2004/04/29 16:16:30 drh Exp $
           46  +** $Id: vdbe.c,v 1.268.2.2 2004/05/10 20:27:41 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include "vdbeInt.h"
    52     52   
    53     53   /*
................................................................................
    58     58   ** help verify the correct operation of the library.
    59     59   */
    60     60   int sqlite_search_count = 0;
    61     61   
    62     62   /*
    63     63   ** When this global variable is positive, it gets decremented once before
    64     64   ** each instruction in the VDBE.  When reaches zero, the SQLITE_Interrupt
    65         -** of the db.flags field is set in order to simulate and interrupt.
           65  +** of the db.flags field is set in order to simulate an interrupt.
    66     66   **
    67     67   ** This facility is used for testing purposes only.  It does not function
    68     68   ** in an ordinary build.
    69     69   */
    70     70   int sqlite_interrupt_count = 0;
    71     71   
    72     72   /*
................................................................................
  4861   4861       }
  4862   4862   #endif
  4863   4863     }  /* The end of the for(;;) loop the loops through opcodes */
  4864   4864   
  4865   4865     /* If we reach this point, it means that execution is finished.
  4866   4866     */
  4867   4867   vdbe_halt:
         4868  +  CHECK_FOR_INTERRUPT
  4868   4869     if( rc ){
  4869   4870       p->rc = rc;
  4870   4871       rc = SQLITE_ERROR;
  4871   4872     }else{
  4872   4873       rc = SQLITE_DONE;
  4873   4874     }
  4874   4875     p->magic = VDBE_MAGIC_HALT;

Changes to test/interrupt.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 script is the sqlite_interrupt() API.
    13     13   #
    14         -# $Id: interrupt.test,v 1.4 2004/02/18 16:57:23 drh Exp $
           14  +# $Id: interrupt.test,v 1.4.2.1 2004/05/10 20:27:42 drh Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Compute a checksum on the entire database.
    21     21   #
................................................................................
    33     33   }
    34     34   
    35     35   # This routine attempts to execute the sql in $sql.  It triggers an
    36     36   # interrupt a progressively later and later points during the processing
    37     37   # and checks to make sure SQLITE_INTERRUPT is returned.  Eventually,
    38     38   # the routine completes successfully.
    39     39   #
    40         -proc interrupt_test {testid sql result {initcnt 0}} {
           40  +proc interrupt_test {testid sql result {initcnt 0} {maxcnt 1000000}} {
    41     41     set orig_sum [cksum]
    42     42     set i $initcnt
    43         -  while 1 {
           43  +  global sqlite_interrupt_count
           44  +  while {$i<$maxcnt} {
    44     45       incr i
    45         -    set ::sqlite_interrupt_count $i
           46  +    set sqlite_interrupt_count $i
    46     47       do_test $testid.$i.1 [format {
    47     48         set ::r [catchsql %s]
    48     49         set ::code [db errorcode]
    49     50         expr {$::code==0 || $::code==9}
    50     51       } [list $sql]] 1
    51     52       if {$::code==9} {
    52     53         do_test $testid.$i.2 {
    53     54           cksum
    54     55         } $orig_sum
    55         -    } else {
           56  +    } elseif {$sqlite_interrupt_count>0} {
    56     57         do_test $testid.$i.99 {
    57     58           set ::r
    58     59         } [list 0 $result]
    59     60         break
    60     61       }
    61     62     }
    62         -  set ::sqlite_interrupt_count 0
           63  +  set sqlite_interrupt_count 0
    63     64   }
    64     65   
    65     66   do_test interrupt-1.1 {
    66     67     execsql {
    67     68       CREATE TABLE t1(a,b);
    68     69       SELECT name FROM sqlite_master;
    69     70     }
    70     71   } {t1}
    71         -interrupt_test interrupt-1.2 {DROP TABLE t1} {}
           72  +interrupt_test interrupt-1.2 {DROP TABLE t1} {} 1 14
    72     73   do_test interrupt-1.3 {
    73     74     execsql {
    74     75       SELECT name FROM sqlite_master;
    75     76     }
    76     77   } {}
    77     78   integrity_check interrupt-1.4
    78     79   
................................................................................
   157    158   set max_count [expr {1000000-$sqlite_interrupt_count}]
   158    159   for {set i 1} {$i<$max_count-5} {incr i 1} {
   159    160     do_test interrupt-4.$i.1 {
   160    161       set ::sqlite_interrupt_count $::i
   161    162       catchsql $sql
   162    163     } {1 interrupted}
   163    164   }
          165  +
   164    166   
   165    167   finish_test