modernc.org/cc@v1.0.1/v2/testdata/_sqlite/ext/rbu/rbusave.test (about)

     1  # 2015 August 14
     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  if {![info exists testdir]} {
    14    set testdir [file join [file dirname [info script]] .. .. test]
    15  }
    16  source $testdir/tester.tcl
    17  set ::testprefix rbusave
    18  
    19  do_execsql_test 1.0 {
    20    CREATE TABLE t1(a PRIMARY KEY, b, c) WITHOUT ROWID;
    21    CREATE TABLE t2(a INTEGER PRIMARY KEY, b, c);
    22    CREATE INDEX i1 ON t1(b);
    23    CREATE INDEX i2 ON t2(c, b);
    24  
    25    INSERT INTO t1 VALUES(1, 1, 1);
    26    INSERT INTO t1 VALUES(2, 2, 2);
    27    INSERT INTO t1 VALUES(3, 3, 3);
    28  
    29    INSERT INTO t2 VALUES(1, 1, 1);
    30    INSERT INTO t2 VALUES(2, 2, 2);
    31    INSERT INTO t2 VALUES(3, 3, 3);
    32  }
    33  
    34  do_test 1.1 {
    35    forcedelete test.db2
    36    sqlite3 db2 test.db2
    37    db2 eval {
    38      CREATE TABLE data_t1(a, b, c, rbu_control);
    39      INSERT INTO data_t1 VALUES(4, 4, 4, 0);
    40      INSERT INTO data_t1 VALUES(2, NULL, NULL, 1);
    41      INSERT INTO data_t1 VALUES(1, 'one', NULL, '.x.');
    42  
    43      CREATE TABLE data_t2(a, b, c, rbu_control);
    44      INSERT INTO data_t2 VALUES(4, 4, 4, 0);
    45      INSERT INTO data_t2 VALUES(2, NULL, NULL, 1);
    46      INSERT INTO data_t2 VALUES(1, 'one', NULL, '.x.');
    47    }
    48  } {}
    49  
    50  proc test_to_bak {} {
    51    foreach f {
    52      test.db test.db-wal test.db-oal test.db-journal 
    53      test.db2 test.db2-wal test.db2-oal test.db2-journal 
    54    } {
    55      set t [string map {test bak} $f]
    56      forcedelete $t
    57      if {[file exists $f]} { forcecopy $f $t }
    58    }
    59  }
    60  
    61  do_test 1.2 {
    62    test_to_bak
    63    sqlite3rbu rrr bak.db bak.db2
    64    set nStep 0
    65    while {[rrr step]=="SQLITE_OK"} {incr nStep}
    66    set res2 [rrr close]
    67  } {SQLITE_DONE}
    68  
    69  
    70  sqlite3rbu rbu test.db test.db2
    71  set res "SQLITE_OK"
    72  for {set i 1} {$res=="SQLITE_OK"} {incr i} {
    73    set res [rbu step]
    74  
    75    do_test 1.3.$i.1 {
    76      rbu savestate
    77      test_to_bak
    78      sqlite3rbu rrr bak.db bak.db2
    79      set nRem 0
    80      while {[rrr step]=="SQLITE_OK"} {incr nRem}
    81      set res2 [rrr close]
    82    } {SQLITE_DONE}
    83  
    84    do_test 1.3.$i.3 { expr $nRem+$i } [expr {$nStep + ($res=="SQLITE_DONE")}]
    85  
    86    do_test 1.3.$i.3 {
    87      sqlite3 bak bak.db
    88      bak eval {
    89        SELECT * FROM t1;
    90        SELECT * FROM t2;
    91      }
    92    } {1 one 1 3 3 3 4 4 4 1 one 1 3 3 3 4 4 4}
    93  
    94    bak close
    95  }
    96  
    97  do_test 1.4 { rbu close } {SQLITE_DONE}
    98  
    99  do_execsql_test 1.5 {
   100    SELECT * FROM t1;
   101    SELECT * FROM t2;
   102  } {1 one 1 3 3 3 4 4 4 1 one 1 3 3 3 4 4 4}
   103  
   104  finish_test
   105