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

     1  # 2016 March 7
     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  # Tests for RBU focused on the REPLACE operation (rbu_control column
    12  # contains integer value 2).
    13  #
    14  
    15  source [file join [file dirname [info script]] rbu_common.tcl]
    16  set ::testprefix rbuC
    17  
    18  #-------------------------------------------------------------------------
    19  # This test is actually of an UPDATE directive. Just to establish that
    20  # these work with UNIQUE indexes before preceding to REPLACE.
    21  #
    22  do_execsql_test 1.0 {
    23    CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b, c UNIQUE);
    24    INSERT INTO t1 VALUES(1, 'a', 'b', 'c');
    25  }
    26  
    27  forcedelete rbu.db
    28  do_execsql_test 1.1 {
    29    ATTACH 'rbu.db' AS rbu;
    30    CREATE TABLE rbu.data_t1(i, a, b, c, rbu_control);
    31    INSERT INTO data_t1 VALUES(1, 'a', 'b', 'c', '.xxx');
    32  }
    33  
    34  do_test 1.2 {
    35    step_rbu test.db rbu.db
    36  } {SQLITE_DONE}
    37  
    38  do_execsql_test 1.3 {
    39    SELECT * FROM t1
    40  } {
    41    1 a b c
    42  }
    43  
    44  #-------------------------------------------------------------------------
    45  #
    46  foreach {tn schema} {
    47    1 {
    48      CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b, c UNIQUE);
    49      CREATE INDEX t1a ON t1(a);
    50    }
    51    2 {
    52      CREATE TABLE t1(i PRIMARY KEY, a, b, c UNIQUE);
    53      CREATE INDEX t1a ON t1(a);
    54    }
    55    3 {
    56      CREATE TABLE t1(i PRIMARY KEY, a, b, c UNIQUE) WITHOUT ROWID;
    57      CREATE INDEX t1a ON t1(a);
    58    }
    59  } {
    60    reset_db
    61    forcedelete rbu.db
    62    execsql $schema
    63  
    64    do_execsql_test 2.$tn.0 {
    65      INSERT INTO t1 VALUES(1, 'a', 'b', 'c');
    66      INSERT INTO t1 VALUES(2, 'b', 'c', 'd');
    67      INSERT INTO t1 VALUES(3, 'c', 'd', 'e');
    68    }
    69    
    70    do_execsql_test 2.$tn.1 {
    71      ATTACH 'rbu.db' AS rbu;
    72      CREATE TABLE rbu.data_t1(i, a, b, c, rbu_control);
    73      INSERT INTO data_t1 VALUES(1, 1, 2, 3, 2);
    74      INSERT INTO data_t1 VALUES(3, 'c', 'd', 'e', 2);
    75      INSERT INTO data_t1 VALUES(4, 'd', 'e', 'f', 2);
    76    }
    77    
    78    do_test 2.$tn.2 {
    79      step_rbu test.db rbu.db
    80    } {SQLITE_DONE}
    81    
    82    do_execsql_test 2.$tn.3 {
    83      SELECT * FROM t1 ORDER BY i
    84    } {
    85      1 1 2 3
    86      2 b c d
    87      3 c d e
    88      4 d e f
    89    }
    90    
    91    integrity_check 2.$tn.4
    92  }
    93  
    94  foreach {tn schema} {
    95    1 {
    96      CREATE TABLE t1(a, b, c UNIQUE);
    97      CREATE INDEX t1a ON t1(a);
    98    }
    99  
   100    2 {
   101      CREATE VIRTUAL TABLE t1 USING fts5(a, b, c);
   102    }
   103  } {
   104    if {$tn==2} { ifcapable !fts5 break }
   105    reset_db
   106    forcedelete rbu.db
   107    execsql $schema
   108  
   109    do_execsql_test 3.$tn.0 {
   110      INSERT INTO t1 VALUES('a', 'b', 'c');
   111      INSERT INTO t1 VALUES('b', 'c', 'd');
   112      INSERT INTO t1 VALUES('c', 'd', 'e');
   113    }
   114    
   115    do_execsql_test 3.$tn.1 {
   116      ATTACH 'rbu.db' AS rbu;
   117      CREATE TABLE rbu.data_t1(rbu_rowid, a, b, c, rbu_control);
   118      INSERT INTO data_t1 VALUES(1, 1, 2, 3, 2);
   119      INSERT INTO data_t1 VALUES(3, 'c', 'd', 'e', 2);
   120      INSERT INTO data_t1 VALUES(4, 'd', 'e', 'f', 2);
   121    }
   122    
   123    do_test 3.$tn.2 {
   124      step_rbu test.db rbu.db
   125    } {SQLITE_DONE}
   126    
   127    do_execsql_test 3.$tn.3 {
   128      SELECT rowid, * FROM t1 ORDER BY 1
   129    } {
   130      1 1 2 3
   131      2 b c d
   132      3 c d e
   133      4 d e f
   134    }
   135    
   136    integrity_check 3.$tn.4
   137  }
   138  
   139  
   140  
   141  finish_test
   142