github.com/jdgcs/sqlite3@v1.12.1-0.20210908114423-bc5f96e4dd51/testdata/tcl/tkt3918.test (about)

     1  # 2009 June 17
     2  #
     3  # The author disclaims copyright to this source code.  In place of
     4  # a legal notice, here is a blessing:
     5  #
     6  #    May you do good and not evil.
     7  #    May you find forgiveness for yourself and forgive others.
     8  #    May you share freely, never taking more than you give.
     9  #
    10  #***********************************************************************
    11  #
    12  # $Id: tkt3918.test,v 1.1 2009/06/17 11:13:28 danielk1977 Exp $
    13  
    14  set testdir [file dirname $argv0]
    15  source $testdir/tester.tcl
    16  
    17  do_test tkt3918.1 {
    18    execsql {
    19      PRAGMA page_size = 1024;
    20      PRAGMA auto_vacuum = incremental;
    21      CREATE TABLE t1(i, x);
    22    }
    23  } {}
    24  do_test tkt3918.2 {
    25    execsql {
    26      INSERT INTO t1 VALUES(1, randstr(1000,1000));
    27      INSERT INTO t1 VALUES(2, zeroblob(248*1020 + 100));
    28      INSERT INTO t1 VALUES(3, zeroblob(2*1020 + 100));
    29    }
    30  } {}
    31  
    32  # This set of statements sets up the free list so that the
    33  # first free-list trunk page contains only a single leaf.
    34  # The leaf page is also the last page in the database. The
    35  # second free-list trunk page contains, amongst other things,
    36  # page number 4.
    37  do_test tkt3918.3 {
    38    execsql {
    39      DELETE FROM t1 WHERE i = 2;
    40      DELETE FROM t1 WHERE i = 1;
    41      DELETE FROM t1 WHERE i = 3;
    42    }
    43  } {}
    44  
    45  # Incrementally vacuum the database to reduce its size by a single
    46  # page. This will remove the single leaf from the first page in
    47  # the linked list of free-list trunk pages.
    48  do_test tkt3918.4 {
    49    execsql { PRAGMA incremental_vacuum = 1 }
    50  } {}
    51  
    52  # Create another table. This operation will attempt to extract 
    53  # page 4 from the database free-list. Bug 3918 caused sqlite to
    54  # incorrectly report corruption here.
    55  do_test tkt3918.5 {
    56    execsql { CREATE TABLE t2(a, b) }
    57  } {}
    58  
    59  finish_test