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