Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/session/sessionrowid.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / session / sessionrowid.test` 282 lines ยท 6869 bytes Raw Blame History 1 # 2011 Mar 16 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 # The focus of this file is testing the session module. 13 # 14 15 if {![info exists testdir]} { 16 set testdir [file join [file dirname [info script]] .. .. test] 17 } 18 source [file join [file dirname [info script]] session_common.tcl] 19 source $testdir/tester.tcl 20 ifcapable !session {finish_test; return} 21 22 set testprefix sessionrowid 23 24 do_execsql_test 0.0 { 25 CREATE TABLE t1(a, b); 26 } 27 28 foreach {tn rowid bEmpty} { 29 1 0 1 30 2 1 0 31 3 -1 1 32 } { 33 do_test 0.$tn { 34 sqlite3session S db main 35 if {$rowid>=0} { S object_config rowid $rowid } 36 S attach t1 37 execsql { INSERT INTO t1 VALUES(1, 2); } 38 expr [string length [S changeset]]==0 39 } $bEmpty 40 S delete 41 } 42 43 #------------------------------------------------------------------------- 44 reset_db 45 do_execsql_test 1.0 { 46 CREATE TABLE t1(a, b); 47 } 48 49 do_iterator_test 1.1 t1 { 50 INSERT INTO t1 VALUES('i', 'one'); 51 } { 52 {INSERT t1 0 X.. {} {i 1 t i t one}} 53 } 54 55 do_execsql_test 1.2 { 56 SELECT rowid, * FROM t1 57 } {1 i one} 58 59 do_iterator_test 1.3 t1 { 60 UPDATE t1 SET b='two' 61 } { 62 {UPDATE t1 0 X.. {i 1 {} {} t one} {{} {} {} {} t two}} 63 } 64 65 do_iterator_test 1.4 t1 { 66 DELETE FROM t1; 67 } { 68 {DELETE t1 0 X.. {i 1 t i t two} {}} 69 } 70 71 do_iterator_test 1.5 t1 { 72 INSERT INTO t1(rowid, a, b) VALUES(14, 'hello', 'world'); 73 INSERT INTO t1(rowid, a, b) VALUES(NULL, 'yes', 'no'); 74 INSERT INTO t1(rowid, a, b) VALUES(-123, 'ii', 'iii'); 75 } { 76 {INSERT t1 0 X.. {} {i -123 t ii t iii}} 77 {INSERT t1 0 X.. {} {i 15 t yes t no}} 78 {INSERT t1 0 X.. {} {i 14 t hello t world}} 79 } 80 81 do_iterator_test 1.6 t1 { 82 UPDATE t1 SET a='deluxe' WHERE rowid=14; 83 DELETE FROM t1 WHERE rowid=-123; 84 INSERT INTO t1 VALUES('x', 'xi'); 85 } { 86 {DELETE t1 0 X.. {i -123 t ii t iii} {}} 87 {UPDATE t1 0 X.. {i 14 t hello {} {}} {{} {} t deluxe {} {}}} 88 {INSERT t1 0 X.. {} {i 16 t x t xi}} 89 } 90 91 #------------------------------------------------------------------------- 92 reset_db 93 forcedelete test.db2 94 sqlite3 db2 test.db2 95 96 do_execsql_test 2.0 { 97 CREATE TABLE t1(a, b); 98 } 99 do_execsql_test -db db2 2.0.1 { 100 CREATE TABLE t1(a, b); 101 } 102 103 proc xConflict {args} { 104 puts "CONFLICT!" 105 return "OMIT" 106 } 107 108 do_test 2.1 { 109 set C [changeset_from_sql { 110 INSERT INTO t1 VALUES('abc', 'def'); 111 }] 112 sqlite3changeset_apply db2 $C xConflict 113 execsql { SELECT * FROM t1 } db2 114 } {abc def} 115 do_test 2.2 { 116 set C [changeset_from_sql { 117 UPDATE t1 SET b='hello' 118 }] 119 sqlite3changeset_apply db2 $C xConflict 120 execsql { SELECT * FROM t1 } db2 121 } {abc hello} 122 do_test 2.3 { 123 set C [changeset_from_sql { 124 DELETE FROM t1 WHERE b='hello' 125 }] 126 sqlite3changeset_apply db2 $C xConflict 127 execsql { SELECT * FROM t1 } db2 128 } {} 129 130 do_test 2.4 { 131 do_then_apply_sql { 132 INSERT INTO t1 VALUES('i', 'one'); 133 INSERT INTO t1 VALUES('ii', 'two'); 134 INSERT INTO t1 VALUES('iii', 'three'); 135 INSERT INTO t1 VALUES('iv', 'four'); 136 } 137 compare_db db db2 138 } {} 139 140 do_test 2.5 { 141 do_then_apply_sql { 142 DELETE FROM t1 WHERE a='ii'; 143 UPDATE t1 SET b='THREE' WHERE a='iii'; 144 UPDATE t1 SET a='III' WHERE a='iii'; 145 INSERT INTO t1 VALUES('v', 'five'); 146 } 147 compare_db db db2 148 } {} 149 150 do_execsql_test 2.6 {SELECT * FROM t1} {i one III THREE iv four v five} 151 do_execsql_test -db db2 2.7 {SELECT * FROM t1} {i one III THREE iv four v five} 152 153 #------------------------------------------------------------------------- 154 db2 close 155 reset_db 156 forcedelete test.db2 157 sqlite3 db2 test.db2 158 159 set init_sql { 160 CREATE TABlE t4(a, b); 161 CREATE INDEX t4a ON t4(a); 162 CREATE UNIQUE INDEX t4b ON t4(b); 163 } 164 165 do_execsql_test 3.0 $init_sql 166 do_execsql_test -db db2 3.0a $init_sql 167 168 do_execsql_test -db db2 3.1 { 169 INSERT INTO t4(rowid, a, b) VALUES(43, 'hello', 'world'); 170 } 171 do_conflict_test 3.2 -sql { 172 INSERT INTO t4(rowid, a, b) VALUES(43, 'abc', 'def'); 173 } -tables t4 -conflicts { 174 {INSERT t4 CONFLICT {i 43 t abc t def} {i 43 t hello t world}} 175 } 176 do_execsql_test -db db2 3.3 { 177 SELECT * FROM t4 178 } {hello world} 179 180 do_execsql_test 3.4 { DELETE FROM t4 } 181 do_conflict_test 3.5 -sql { 182 INSERT INTO t4(rowid, a, b) VALUES(43, 'abc', 'def'); 183 } -tables t4 -conflicts { 184 {INSERT t4 CONFLICT {i 43 t abc t def} {i 43 t hello t world}} 185 } -policy REPLACE 186 do_execsql_test -db db2 3.6 { 187 SELECT * FROM t4 188 } {abc def} 189 190 do_execsql_test 3.7 { DELETE FROM t4 } 191 do_conflict_test 3.8 -sql { 192 INSERT INTO t4(rowid, a, b) VALUES(45, 'xyz', 'def'); 193 } -tables t4 -conflicts { 194 {INSERT t4 CONSTRAINT {i 45 t xyz t def}} 195 } 196 do_execsql_test -db db2 3.9 { 197 SELECT * FROM t4 198 } {abc def} 199 200 201 do_execsql_test -db db 3.10a { DELETE FROM t4 } 202 do_execsql_test -db db2 3.10b { DELETE FROM t4 } 203 204 do_execsql_test -db db 3.11a { 205 INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'one'); 206 INSERT INTO t4(rowid, a, b) VALUES(222, 'two', 'two'); 207 } 208 do_execsql_test -db db2 3.11b { 209 INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'blip'); 210 } 211 212 do_conflict_test 3.12 -sql { 213 DELETE FROM t4 WHERE a='one'; 214 } -tables t4 -conflicts { 215 {DELETE t4 DATA {i 111 t one t one} {i 111 t one t blip}} 216 } 217 do_execsql_test -db db2 3.13 { 218 SELECT * FROM t4 219 } {one blip} 220 221 do_conflict_test 3.14 -sql { 222 DELETE FROM t4 WHERE a='two'; 223 } -tables t4 -conflicts { 224 {DELETE t4 NOTFOUND {i 222 t two t two}} 225 } 226 do_execsql_test -db db2 3.15 { 227 SELECT * FROM t4 228 } {one blip} 229 230 do_execsql_test -db db 3.16a { DELETE FROM t4 } 231 do_execsql_test -db db2 3.16b { DELETE FROM t4 } 232 233 do_execsql_test -db db 3.17a { 234 INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'one'); 235 INSERT INTO t4(rowid, a, b) VALUES(222, 'two', 'two'); 236 } 237 do_execsql_test -db db2 3.17b { 238 INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'blip'); 239 } 240 241 do_conflict_test 3.18 -sql { 242 UPDATE t4 SET b='xyz' WHERE a='one' 243 } -tables t4 -conflicts { 244 {UPDATE t4 DATA {i 111 {} {} t one} {{} {} {} {} t xyz} {i 111 t one t blip}} 245 } 246 do_execsql_test -db db2 3.19 { 247 SELECT * FROM t4 248 } {one blip} 249 250 do_conflict_test 3.20 -sql { 251 UPDATE t4 SET b='123' WHERE a='two' 252 } -tables t4 -conflicts { 253 {UPDATE t4 NOTFOUND {i 222 {} {} t two} {{} {} {} {} t 123}} 254 } 255 do_execsql_test -db db2 3.21 { 256 SELECT * FROM t4 257 } {one blip} 258 db2 close 259 260 #-------------------------------------------------------------------------- 261 breakpoint 262 do_diff_test 4.0 { 263 CREATE TABLE t1(x, y); 264 CREATE TABLE aux.t1(x, y); 265 INSERT INTO t1 VALUES(1, 2); 266 } 267 268 do_diff_test 4.1 { 269 CREATE TABLE t1(x, y); 270 CREATE TABLE aux.t1(x, y); 271 INSERT INTO aux.t1 VALUES(1, 2); 272 } 273 274 do_diff_test 4.2 { 275 CREATE TABLE t1(x, y); 276 CREATE TABLE aux.t1(x, y); 277 INSERT INTO t1(rowid, x, y) VALUES(413, 'hello', 'there'); 278 INSERT INTO aux.t1(rowid, x, y) VALUES(413, 'hello', 'world'); 279 } 280 281 finish_test 282