gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/pager2.test (about)

     1  # 2010 June 15
     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  
    13  set testdir [file dirname $argv0]
    14  source $testdir/tester.tcl
    15  source $testdir/lock_common.tcl
    16  source $testdir/malloc_common.tcl
    17  
    18  set otn 0
    19  testvfs tv -default 1
    20  foreach code [list {
    21    set s 512
    22  } {
    23    set s 1024
    24    set sql { PRAGMA journal_mode = memory }
    25  } {
    26    set s 1024
    27    set sql { 
    28      PRAGMA journal_mode = memory;
    29      PRAGMA locking_mode = exclusive;
    30    }
    31  } {
    32    set s 2048
    33    tv devchar safe_append
    34  } {
    35    set s 4096
    36  } {
    37    set s 4096
    38    set sql { PRAGMA journal_mode = WAL }
    39  } {
    40    set s 4096
    41    set sql { PRAGMA auto_vacuum = 1 }
    42  } {
    43    set s 8192
    44    set sql { PRAGMA synchronous = off }
    45  }] {
    46  
    47    incr otn
    48    set sql ""
    49    tv devchar {}
    50    eval $code
    51    tv sectorsize $s
    52    
    53    do_test pager2-1.$otn.0 {
    54      faultsim_delete_and_reopen
    55      execsql $sql
    56      execsql {
    57        PRAGMA cache_size = 10;
    58        CREATE TABLE t1(i INTEGER PRIMARY KEY, j blob);
    59      }
    60    } {}
    61  
    62    set tn 0
    63    set lowpoint 0
    64    foreach x {
    65      100 x 0 100
    66    x
    67      70 22 96 59 96 50 22 56 21 16 37 64 43 40  0 38 22 38 55  0  6   
    68      43 62 32 93 54 18 13 29 45 66 29 25 61 31 53 82 75 25 96 86 10 69   
    69       2 29  6 60 80 95 42 82 85 50 68 96 90 39 78 69 87 97 48 74 65 43   
    70    x
    71      86 34 26 50 41 85 58 44 89 22  6 51 45 46 58 32 97  6  1 12 32  2   
    72      69 39 48 71 33 31  5 58 90 43 24 54 12  9 18 57  4 38 91 42 27 45   
    73      50 38 56 29 10  0 26 37 83  1 78 15 47 30 75 62 46 29 68  5 30  4   
    74      27 96 33 95 79 75 56 10 29 70 32 75 52 88  5 36 50 57 46 63 88 65   
    75    x
    76      44 95 64 20 24 35 69 61 61  2 35 92 42 46 23 98 78  1 38 72 79 35   
    77      94 37 13 59  5 93 27 58 80 75 58  7 67 13 10 76 84  4  8 70 81 45   
    78       8 41 98  5 60 26 92 29 91 90  2 62 40  4  5 22 80 15 83 76 52 88   
    79      29  5 68 73 72  7 54 17 89 32 81 94 51 28 53 71  8 42 54 59 70 79   
    80    x
    81    } {
    82      incr tn
    83      set now [db one {SELECT count(i) FROM t1}]
    84      if {$x == "x"} {
    85        execsql { COMMIT ; BEGIN }
    86        set lowpoint $now
    87        do_test pager2.1.$otn.$tn { 
    88          sqlite3 db2 test.db
    89          execsql {
    90            SELECT COALESCE(max(i), 0) FROM t1;
    91            PRAGMA integrity_check;
    92          } 
    93        } [list $lowpoint ok]
    94        db2 close
    95      } else {
    96        if {$now > $x } {
    97          if { $x>=$lowpoint } {
    98            execsql "ROLLBACK TO sp_$x"
    99          } else {
   100            execsql "DELETE FROM t1 WHERE i>$x"
   101            set lowpoint $x
   102          }
   103        } elseif {$now < $x} {
   104          for {set k $now} {$k < $x} {incr k} {
   105            execsql "SAVEPOINT sp_$k"
   106            execsql { INSERT INTO t1(j) VALUES(randomblob(1500)) }
   107          }
   108        }
   109        do_execsql_test pager2.1.$otn.$tn { 
   110          SELECT COALESCE(max(i), 0) FROM t1;
   111          PRAGMA integrity_check;
   112        } [list $x ok]
   113      }
   114    }
   115  }
   116  db close
   117  tv delete
   118  
   119  
   120  #-------------------------------------------------------------------------
   121  # pager2-2.1: Test a ROLLBACK with journal_mode=off.
   122  # pager2-2.2: Test shrinking the database (auto-vacuum) with 
   123  #             journal_mode=off
   124  #
   125  do_test pager2-2.1 {
   126    faultsim_delete_and_reopen
   127    execsql {
   128      CREATE TABLE t1(a, b);
   129      PRAGMA journal_mode = off;
   130      BEGIN;
   131        INSERT INTO t1 VALUES(1, 2);
   132      ROLLBACK;
   133      SELECT * FROM t1;
   134    }
   135  } {off}
   136  do_test pager2-2.2 {
   137    faultsim_delete_and_reopen
   138    execsql {
   139      PRAGMA auto_vacuum = incremental;
   140      PRAGMA page_size = 1024;
   141      PRAGMA journal_mode = off;
   142      CREATE TABLE t1(a, b);
   143      INSERT INTO t1 VALUES(zeroblob(5000), zeroblob(5000));
   144      DELETE FROM t1;
   145      PRAGMA incremental_vacuum;
   146    }
   147    file size test.db
   148  } {3072}
   149  
   150  #-------------------------------------------------------------------------
   151  # Test that shared in-memory databases seem to work.
   152  #
   153  db close
   154  do_test pager2-3.1 {
   155    forcedelete test.db
   156    sqlite3_shutdown
   157    sqlite3_config_uri 1
   158  
   159    sqlite3 db1 {file:test.db?mode=memory&cache=shared}
   160    sqlite3 db2 {file:test.db?mode=memory&cache=shared}
   161    sqlite3 db3 test.db
   162  
   163    db1 eval { CREATE TABLE t1(a, b) }
   164    db2 eval { INSERT INTO t1 VALUES(1, 2) }
   165    list [catch { db3 eval { INSERT INTO t1 VALUES(3, 4) } } msg] $msg
   166  } {1 {no such table: t1}}
   167  
   168  finish_test