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

     1  # 2015 June 02
     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  # This file implements regression tests for the sessions module.
    13  # Specifically, it tests that operations on tables without primary keys
    14  # are ignored.
    15  #
    16  
    17  
    18  
    19  if {![info exists testdir]} {
    20    set testdir [file join [file dirname [info script]] .. .. test]
    21  } 
    22  source [file join [file dirname [info script]] session_common.tcl]
    23  source $testdir/tester.tcl
    24  ifcapable !session {finish_test; return}
    25  set testprefix sessionE
    26  
    27  #
    28  # Test plan:
    29  #
    30  #    1.*: Test that non-PK tables are not auto-attached.
    31  #    2.*: Test that explicitly attaching a non-PK table is a no-op.
    32  #    3.*: Test that sqlite3session_diff() on a non-PK table is a no-op.
    33  #
    34  
    35  
    36  #--------------------------------------------------------------------------
    37  reset_db
    38  do_execsql_test 1.0 {
    39    CREATE TABLE t1(a, b);
    40    CREATE TABLE t2(a PRIMARY KEY, b);
    41  }
    42  do_test 1.1 {
    43    sqlite3session S db main
    44    S attach *
    45    execsql {
    46      INSERT INTO t1 VALUES(1, 2);
    47      INSERT INTO t2 VALUES(1, 2);
    48    }
    49  } {}
    50  do_changeset_test 1.2 S {
    51    {INSERT t2 0 X. {} {i 1 i 2}}
    52  }
    53  S delete
    54  
    55  reset_db
    56  do_execsql_test 2.0 {
    57    CREATE TABLE t1(a, b);
    58    CREATE TABLE t2(a PRIMARY KEY, b);
    59  }
    60  do_test 2.1 {
    61    sqlite3session S db main
    62    S attach t1
    63    S attach t2
    64    execsql {
    65      INSERT INTO t1 VALUES(3, 4);
    66      INSERT INTO t2 VALUES(3, 4);
    67      INSERT INTO t1 VALUES(5, 6);
    68      INSERT INTO t2 VALUES(5, 6);
    69    }
    70  } {}
    71  do_changeset_test 2.2 S {
    72    {INSERT t2 0 X. {} {i 3 i 4}}
    73    {INSERT t2 0 X. {} {i 5 i 6}}
    74  }
    75  S delete
    76  
    77  reset_db
    78  forcedelete test.db2
    79  do_execsql_test 3.0 {
    80    ATTACH 'test.db2' AS aux;
    81    CREATE TABLE aux.t1(a, b);
    82    CREATE TABLE aux.t2(a PRIMARY KEY, b);
    83  
    84    CREATE TABLE t1(a, b);
    85    CREATE TABLE t2(a PRIMARY KEY, b);
    86  
    87    INSERT INTO t1 VALUES(1, 2);
    88    INSERT INTO t2 VALUES(3, 4);
    89  }
    90  do_test 3.1 {
    91    sqlite3session S db main
    92    S attach t1
    93    S diff aux t1
    94  
    95    S attach t2
    96    S diff aux t2
    97  } {}
    98  do_changeset_test 3.2 S {
    99    {INSERT t2 0 X. {} {i 3 i 4}}
   100  }
   101  do_execsql_test 3.3 {
   102    INSERT INTO t1 VALUES(5, 6);
   103    INSERT INTO t2 VALUES(7, 8);
   104  }
   105  do_changeset_test 3.4 S {
   106    {INSERT t2 0 X. {} {i 3 i 4}}
   107    {INSERT t2 0 X. {} {i 7 i 8}}
   108  }
   109  
   110  
   111  S delete
   112  
   113  finish_test
   114  
   115