Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: third_party/sqlite/sqlite-src-3080704/test/conflict2.test

Issue 883353008: [sql] Import reference version of SQLite 3.8.7.4. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Hold back encoding change which is messing up patch. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 2002 January 29 1 # 2013-11-04
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
11 # This file implements regression tests for SQLite library. 11 # This file implements regression tests for SQLite library.
12 # 12 #
13 # This file implements tests for the conflict resolution extension 13 # This file implements tests for the conflict resolution extension
14 # to SQLite. 14 # in WITHOUT ROWID tables
15 # 15 #
16 # $Id: conflict.test,v 1.32 2009/04/30 09:10:38 danielk1977 Exp $
17 16
18 set testdir [file dirname $argv0] 17 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl 18 source $testdir/tester.tcl
20 19
21 ifcapable !conflict { 20 ifcapable !conflict {
22 finish_test 21 finish_test
23 return 22 return
24 } 23 }
25 24
26 # Create tables for the first group of tests. 25 # Create tables for the first group of tests.
27 # 26 #
28 do_test conflict-1.0 { 27 do_test conflict2-1.0 {
29 execsql { 28 execsql {
30 CREATE TABLE t1(a, b, c, UNIQUE(a,b)); 29 CREATE TABLE t1(a, b, c, PRIMARY KEY(a,b)) WITHOUT rowid;
31 CREATE TABLE t2(x); 30 CREATE TABLE t2(x);
32 SELECT c FROM t1 ORDER BY c; 31 SELECT c FROM t1 ORDER BY c;
33 } 32 }
34 } {} 33 } {}
35 34
36 # Six columns of configuration data as follows: 35 # Six columns of configuration data as follows:
37 # 36 #
38 # i The reference number of the test 37 # i The reference number of the test
39 # cmd An INSERT or REPLACE command to execute against table t1 38 # cmd An INSERT or REPLACE command to execute against table t1
40 # t0 True if there is an error from $cmd 39 # t0 True if there is an error from $cmd
41 # t1 Content of "c" column of t1 assuming no error in $cmd 40 # t1 Content of "c" column of t1 assuming no error in $cmd
42 # t2 Content of "x" column of t2 41 # t2 Content of "x" column of t2
43 # t3 Number of temporary files created by this test 42 # t3 Number of temporary files created by this test
44 # 43 #
45 foreach {i cmd t0 t1 t2 t3} { 44 foreach {i cmd t0 t1 t2 t3} {
46 1 INSERT 1 {} 1 0 45 1 INSERT 1 {} 1 0
47 2 {INSERT OR IGNORE} 0 3 1 0 46 2 {INSERT OR IGNORE} 0 3 1 0
48 3 {INSERT OR REPLACE} 0 4 1 0 47 3 {INSERT OR REPLACE} 0 4 1 0
49 4 REPLACE 0 4 1 0 48 4 REPLACE 0 4 1 0
50 5 {INSERT OR FAIL} 1 {} 1 0 49 5 {INSERT OR FAIL} 1 {} 1 0
51 6 {INSERT OR ABORT} 1 {} 1 0 50 6 {INSERT OR ABORT} 1 {} 1 0
52 7 {INSERT OR ROLLBACK} 1 {} {} 0 51 7 {INSERT OR ROLLBACK} 1 {} {} 0
53 } { 52 } {
54 do_test conflict-1.$i { 53 do_test conflict2-1.$i {
55 set ::sqlite_opentemp_count 0 54 set ::sqlite_opentemp_count 0
56 set r0 [catch {execsql [subst { 55 set r0 [catch {execsql [subst {
57 DELETE FROM t1; 56 DELETE FROM t1;
58 DELETE FROM t2; 57 DELETE FROM t2;
59 INSERT INTO t1 VALUES(1,2,3); 58 INSERT INTO t1 VALUES(1,2,3);
60 BEGIN; 59 BEGIN;
61 INSERT INTO t2 VALUES(1); 60 INSERT INTO t2 VALUES(1);
62 $cmd INTO t1 VALUES(1,2,4); 61 $cmd INTO t1 VALUES(1,2,4);
63 }]} r1] 62 }]} r1]
64 catch {execsql {COMMIT}} 63 catch {execsql {COMMIT}}
65 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} 64 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
66 set r2 [execsql {SELECT x FROM t2}] 65 set r2 [execsql {SELECT x FROM t2}]
67 set r3 $::sqlite_opentemp_count 66 set r3 $::sqlite_opentemp_count
68 list $r0 $r1 $r2 $r3 67 list $r0 $r1 $r2 $r3
69 } [list $t0 $t1 $t2 $t3] 68 } [list $t0 $t1 $t2 $t3]
70 } 69 }
71 70
72 # Create tables for the first group of tests. 71 # Create tables for the first group of tests.
73 # 72 #
74 do_test conflict-2.0 { 73 do_test conflict2-2.0 {
75 execsql { 74 execsql {
76 DROP TABLE t1; 75 DROP TABLE t1;
77 DROP TABLE t2; 76 DROP TABLE t2;
78 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(a,b)); 77 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(a,b)) WITHOUT rowid;
79 CREATE TABLE t2(x); 78 CREATE TABLE t2(x);
80 SELECT c FROM t1 ORDER BY c; 79 SELECT c FROM t1 ORDER BY c;
81 } 80 }
82 } {} 81 } {}
83 82
84 # Six columns of configuration data as follows: 83 # Six columns of configuration data as follows:
85 # 84 #
86 # i The reference number of the test 85 # i The reference number of the test
87 # cmd An INSERT or REPLACE command to execute against table t1 86 # cmd An INSERT or REPLACE command to execute against table t1
88 # t0 True if there is an error from $cmd 87 # t0 True if there is an error from $cmd
89 # t1 Content of "c" column of t1 assuming no error in $cmd 88 # t1 Content of "c" column of t1 assuming no error in $cmd
90 # t2 Content of "x" column of t2 89 # t2 Content of "x" column of t2
91 # 90 #
92 foreach {i cmd t0 t1 t2} { 91 foreach {i cmd t0 t1 t2} {
93 1 INSERT 1 {} 1 92 1 INSERT 1 {} 1
94 2 {INSERT OR IGNORE} 0 3 1 93 2 {INSERT OR IGNORE} 0 3 1
95 3 {INSERT OR REPLACE} 0 4 1 94 3 {INSERT OR REPLACE} 0 4 1
96 4 REPLACE 0 4 1 95 4 REPLACE 0 4 1
97 5 {INSERT OR FAIL} 1 {} 1 96 5 {INSERT OR FAIL} 1 {} 1
98 6 {INSERT OR ABORT} 1 {} 1 97 6 {INSERT OR ABORT} 1 {} 1
99 7 {INSERT OR ROLLBACK} 1 {} {} 98 7 {INSERT OR ROLLBACK} 1 {} {}
100 } { 99 } {
101 do_test conflict-2.$i { 100 do_test conflict2-2.$i {
102 set r0 [catch {execsql [subst { 101 set r0 [catch {execsql [subst {
103 DELETE FROM t1; 102 DELETE FROM t1;
104 DELETE FROM t2; 103 DELETE FROM t2;
105 INSERT INTO t1 VALUES(1,2,3); 104 INSERT INTO t1 VALUES(1,2,3);
106 BEGIN; 105 BEGIN;
107 INSERT INTO t2 VALUES(1); 106 INSERT INTO t2 VALUES(1);
108 $cmd INTO t1 VALUES(1,2,4); 107 $cmd INTO t1 VALUES(1,2,4);
109 }]} r1] 108 }]} r1]
110 catch {execsql {COMMIT}} 109 catch {execsql {COMMIT}}
111 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} 110 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
112 set r2 [execsql {SELECT x FROM t2}] 111 set r2 [execsql {SELECT x FROM t2}]
113 list $r0 $r1 $r2 112 list $r0 $r1 $r2
114 } [list $t0 $t1 $t2] 113 } [list $t0 $t1 $t2]
115 } 114 }
116 115
117 # Create tables for the first group of tests. 116 # Create tables for the first group of tests.
118 # 117 #
119 do_test conflict-3.0 { 118 do_test conflict2-3.0 {
120 execsql { 119 execsql {
121 DROP TABLE t1; 120 DROP TABLE t1;
122 DROP TABLE t2; 121 DROP TABLE t2;
123 CREATE TABLE t1(a, b, c INTEGER, PRIMARY KEY(c), UNIQUE(a,b)); 122 CREATE TABLE t1(a, b, c INTEGER, PRIMARY KEY(c), UNIQUE(a,b)) WITHOUT rowid;
124 CREATE TABLE t2(x); 123 CREATE TABLE t2(x);
125 SELECT c FROM t1 ORDER BY c; 124 SELECT c FROM t1 ORDER BY c;
126 } 125 }
127 } {} 126 } {}
128 127
129 # Six columns of configuration data as follows: 128 # Six columns of configuration data as follows:
130 # 129 #
131 # i The reference number of the test 130 # i The reference number of the test
132 # cmd An INSERT or REPLACE command to execute against table t1 131 # cmd An INSERT or REPLACE command to execute against table t1
133 # t0 True if there is an error from $cmd 132 # t0 True if there is an error from $cmd
134 # t1 Content of "c" column of t1 assuming no error in $cmd 133 # t1 Content of "c" column of t1 assuming no error in $cmd
135 # t2 Content of "x" column of t2 134 # t2 Content of "x" column of t2
136 # 135 #
137 foreach {i cmd t0 t1 t2} { 136 foreach {i cmd t0 t1 t2} {
138 1 INSERT 1 {} 1 137 1 INSERT 1 {} 1
139 2 {INSERT OR IGNORE} 0 3 1 138 2 {INSERT OR IGNORE} 0 3 1
140 3 {INSERT OR REPLACE} 0 4 1 139 3 {INSERT OR REPLACE} 0 4 1
141 4 REPLACE 0 4 1 140 4 REPLACE 0 4 1
142 5 {INSERT OR FAIL} 1 {} 1 141 5 {INSERT OR FAIL} 1 {} 1
143 6 {INSERT OR ABORT} 1 {} 1 142 6 {INSERT OR ABORT} 1 {} 1
144 7 {INSERT OR ROLLBACK} 1 {} {} 143 7 {INSERT OR ROLLBACK} 1 {} {}
145 } { 144 } {
146 do_test conflict-3.$i { 145 do_test conflict2-3.$i {
147 set r0 [catch {execsql [subst { 146 set r0 [catch {execsql [subst {
148 DELETE FROM t1; 147 DELETE FROM t1;
149 DELETE FROM t2; 148 DELETE FROM t2;
150 INSERT INTO t1 VALUES(1,2,3); 149 INSERT INTO t1 VALUES(1,2,3);
151 BEGIN; 150 BEGIN;
152 INSERT INTO t2 VALUES(1); 151 INSERT INTO t2 VALUES(1);
153 $cmd INTO t1 VALUES(1,2,4); 152 $cmd INTO t1 VALUES(1,2,4);
154 }]} r1] 153 }]} r1]
155 catch {execsql {COMMIT}} 154 catch {execsql {COMMIT}}
156 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} 155 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
157 set r2 [execsql {SELECT x FROM t2}] 156 set r2 [execsql {SELECT x FROM t2}]
158 list $r0 $r1 $r2 157 list $r0 $r1 $r2
159 } [list $t0 $t1 $t2] 158 } [list $t0 $t1 $t2]
160 } 159 }
161 160
162 do_test conflict-4.0 { 161 do_test conflict2-4.0 {
163 execsql { 162 execsql {
164 DROP TABLE t2; 163 DROP TABLE t2;
165 CREATE TABLE t2(x); 164 CREATE TABLE t2(x);
166 SELECT x FROM t2; 165 SELECT x FROM t2;
167 } 166 }
168 } {} 167 } {}
169 168
170 # Six columns of configuration data as follows: 169 # Six columns of configuration data as follows:
171 # 170 #
172 # i The reference number of the test 171 # i The reference number of the test
173 # conf1 The conflict resolution algorithm on the UNIQUE constraint 172 # conf1 The conflict resolution algorithm on the UNIQUE constraint
174 # cmd An INSERT or REPLACE command to execute against table t1 173 # cmd An INSERT or REPLACE command to execute against table t1
175 # t0 True if there is an error from $cmd 174 # t0 True if there is an error from $cmd
176 # t1 Content of "c" column of t1 assuming no error in $cmd 175 # t1 Content of "c" column of t1 assuming no error in $cmd
177 # t2 Content of "x" column of t2 176 # t2 Content of "x" column of t2
178 # 177 #
179 foreach {i conf1 cmd t0 t1 t2} { 178 foreach {i conf1 cmd t0 t1 t2} {
180 1 {} INSERT 1 {} 1 179 1 {} INSERT 1 {} 1
181 2 REPLACE INSERT 0 4 1 180 2 REPLACE INSERT 0 4 1
182 3 IGNORE INSERT 0 3 1 181 3 IGNORE INSERT 0 3 1
183 4 FAIL INSERT 1 {} 1 182 4 FAIL INSERT 1 {} 1
184 5 ABORT INSERT 1 {} 1 183 5 ABORT INSERT 1 {} 1
185 6 ROLLBACK INSERT 1 {} {} 184 6 ROLLBACK INSERT 1 {} {}
186 7 REPLACE {INSERT OR IGNORE} 0 3 1 185 7 REPLACE {INSERT OR IGNORE} 0 3 1
187 8 IGNORE {INSERT OR REPLACE} 0 4 1 186 8 IGNORE {INSERT OR REPLACE} 0 4 1
188 9 FAIL {INSERT OR IGNORE} 0 3 1 187 9 FAIL {INSERT OR IGNORE} 0 3 1
189 10 ABORT {INSERT OR REPLACE} 0 4 1 188 10 ABORT {INSERT OR REPLACE} 0 4 1
190 11 ROLLBACK {INSERT OR IGNORE } 0 3 1 189 11 ROLLBACK {INSERT OR IGNORE } 0 3 1
191 } { 190 } {
192 do_test conflict-4.$i { 191 do_test conflict2-4.$i {
193 if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} 192 if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
194 set r0 [catch {execsql [subst { 193 set r0 [catch {execsql [subst {
195 DROP TABLE t1; 194 DROP TABLE t1;
196 CREATE TABLE t1(a,b,c,UNIQUE(a,b) $conf1); 195 CREATE TABLE t1(a,b,c,PRIMARY KEY(a,b) $conf1) WITHOUT rowid;
197 DELETE FROM t2; 196 DELETE FROM t2;
198 INSERT INTO t1 VALUES(1,2,3); 197 INSERT INTO t1 VALUES(1,2,3);
199 BEGIN; 198 BEGIN;
200 INSERT INTO t2 VALUES(1); 199 INSERT INTO t2 VALUES(1);
201 $cmd INTO t1 VALUES(1,2,4); 200 $cmd INTO t1 VALUES(1,2,4);
202 }]} r1] 201 }]} r1]
203 catch {execsql {COMMIT}} 202 catch {execsql {COMMIT}}
204 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} 203 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
205 set r2 [execsql {SELECT x FROM t2}] 204 set r2 [execsql {SELECT x FROM t2}]
206 list $r0 $r1 $r2 205 list $r0 $r1 $r2
207 } [list $t0 $t1 $t2] 206 } [list $t0 $t1 $t2]
208 } 207 }
209 208
210 do_test conflict-5.0 { 209 do_test conflict2-5.0 {
211 execsql { 210 execsql {
212 DROP TABLE t2; 211 DROP TABLE t2;
213 CREATE TABLE t2(x); 212 CREATE TABLE t2(x);
214 SELECT x FROM t2; 213 SELECT x FROM t2;
215 } 214 }
216 } {} 215 } {}
217 216
218 # Six columns of configuration data as follows: 217 # Six columns of configuration data as follows:
219 # 218 #
220 # i The reference number of the test 219 # i The reference number of the test
(...skipping 14 matching lines...) Expand all
235 8 IGNORE {INSERT OR REPLACE} 0 5 1 234 8 IGNORE {INSERT OR REPLACE} 0 5 1
236 9 FAIL {INSERT OR IGNORE} 0 {} 1 235 9 FAIL {INSERT OR IGNORE} 0 {} 1
237 10 ABORT {INSERT OR REPLACE} 0 5 1 236 10 ABORT {INSERT OR REPLACE} 0 5 1
238 11 ROLLBACK {INSERT OR IGNORE} 0 {} 1 237 11 ROLLBACK {INSERT OR IGNORE} 0 {} 1
239 12 {} {INSERT OR IGNORE} 0 {} 1 238 12 {} {INSERT OR IGNORE} 0 {} 1
240 13 {} {INSERT OR REPLACE} 0 5 1 239 13 {} {INSERT OR REPLACE} 0 5 1
241 14 {} {INSERT OR FAIL} 1 {} 1 240 14 {} {INSERT OR FAIL} 1 {} 1
242 15 {} {INSERT OR ABORT} 1 {} 1 241 15 {} {INSERT OR ABORT} 1 {} 1
243 16 {} {INSERT OR ROLLBACK} 1 {} {} 242 16 {} {INSERT OR ROLLBACK} 1 {} {}
244 } { 243 } {
245 if {$t0} {set t1 {t1.c may not be NULL}} 244 if {$t0} {set t1 {NOT NULL constraint failed: t1.c}}
246 do_test conflict-5.$i { 245 do_test conflict2-5.$i {
247 if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} 246 if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
248 set r0 [catch {execsql [subst { 247 set r0 [catch {execsql [subst {
249 DROP TABLE t1; 248 DROP TABLE t1;
250 CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5); 249 CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5);
251 DELETE FROM t2; 250 DELETE FROM t2;
252 BEGIN; 251 BEGIN;
253 INSERT INTO t2 VALUES(1); 252 INSERT INTO t2 VALUES(1);
254 $cmd INTO t1 VALUES(1,2,NULL); 253 $cmd INTO t1 VALUES(1,2,NULL);
255 }]} r1] 254 }]} r1]
256 catch {execsql {COMMIT}} 255 catch {execsql {COMMIT}}
257 if {!$r0} {set r1 [execsql {SELECT c FROM t1}]} 256 if {!$r0} {set r1 [execsql {SELECT c FROM t1}]}
258 set r2 [execsql {SELECT x FROM t2}] 257 set r2 [execsql {SELECT x FROM t2}]
259 list $r0 $r1 $r2 258 list $r0 $r1 $r2
260 } [list $t0 $t1 $t2] 259 } [list $t0 $t1 $t2]
261 } 260 }
262 261
263 do_test conflict-6.0 { 262 do_test conflict2-6.0 {
264 execsql { 263 execsql {
265 DROP TABLE t2; 264 DROP TABLE t2;
266 CREATE TABLE t2(a,b,c); 265 CREATE TABLE t2(a,b,c);
267 INSERT INTO t2 VALUES(1,2,1); 266 INSERT INTO t2 VALUES(1,2,1);
268 INSERT INTO t2 VALUES(2,3,2); 267 INSERT INTO t2 VALUES(2,3,2);
269 INSERT INTO t2 VALUES(3,4,1); 268 INSERT INTO t2 VALUES(3,4,1);
270 INSERT INTO t2 VALUES(4,5,4); 269 INSERT INTO t2 VALUES(4,5,4);
271 SELECT c FROM t2 ORDER BY b; 270 SELECT c FROM t2 ORDER BY b;
272 CREATE TABLE t3(x); 271 CREATE TABLE t3(x);
273 INSERT INTO t3 VALUES(1); 272 INSERT INTO t3 VALUES(1);
(...skipping 15 matching lines...) Expand all
289 # of the following tests use large quantities of data, t3 is always 0. 288 # of the following tests use large quantities of data, t3 is always 0.
290 # 289 #
291 foreach {i conf1 cmd t0 t1 t2 t3 t4} { 290 foreach {i conf1 cmd t0 t1 t2 t3 t4} {
292 1 {} UPDATE 1 {6 7 8 9} 1 0 1 291 1 {} UPDATE 1 {6 7 8 9} 1 0 1
293 2 REPLACE UPDATE 0 {7 6 9} 1 0 0 292 2 REPLACE UPDATE 0 {7 6 9} 1 0 0
294 3 IGNORE UPDATE 0 {6 7 3 9} 1 0 0 293 3 IGNORE UPDATE 0 {6 7 3 9} 1 0 0
295 4 FAIL UPDATE 1 {6 7 3 4} 1 0 0 294 4 FAIL UPDATE 1 {6 7 3 4} 1 0 0
296 5 ABORT UPDATE 1 {1 2 3 4} 1 0 1 295 5 ABORT UPDATE 1 {1 2 3 4} 1 0 1
297 6 ROLLBACK UPDATE 1 {1 2 3 4} 0 0 0 296 6 ROLLBACK UPDATE 1 {1 2 3 4} 0 0 0
298 7 REPLACE {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 297 7 REPLACE {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0
299 8 IGNORE {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 298 8 IGNORE {UPDATE OR REPLACE} 0 {7 6 9} 1 0 1
300 9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 299 9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0
301 10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 300 10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 0 1
302 11 ROLLBACK {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 301 11 ROLLBACK {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0
303 12 {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 302 12 {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0
304 13 {} {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 303 13 {} {UPDATE OR REPLACE} 0 {7 6 9} 1 0 1
305 14 {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 0 0 304 14 {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 0 0
306 15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 0 1 305 15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 0 1
307 16 {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 0 0 306 16 {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 0 0
308 } { 307 } {
309 if {$t0} {set t1 {column a is not unique}} 308
309 # When using in-memory journals, no temporary files are required for
310 # statement journals.
311 if {[permutation] == "inmemory_journal"} { set t4 0 }
312
313 if {$t0} {set t1 {UNIQUE constraint failed: t1.a}}
310 if {[info exists TEMP_STORE] && $TEMP_STORE==3} { 314 if {[info exists TEMP_STORE] && $TEMP_STORE==3} {
311 set t3 0 315 set t3 0
312 } else { 316 } else {
313 set t3 [expr {$t3+$t4}] 317 set t3 [expr {$t3+$t4}]
314 } 318 }
315 do_test conflict-6.$i { 319 do_test conflict2-6.$i {
316 db close 320 db close
317 sqlite3 db test.db 321 sqlite3 db test.db
318 if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} 322 if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
319 execsql {pragma temp_store=file} 323 execsql {pragma temp_store=file}
320 set ::sqlite_opentemp_count 0 324 set ::sqlite_opentemp_count 0
321 set r0 [catch {execsql [subst { 325 set r0 [catch {execsql [subst {
322 DROP TABLE t1; 326 DROP TABLE t1;
323 CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1); 327 CREATE TABLE t1(a,b,c, PRIMARY KEY(a) $conf1) WITHOUT rowid;
324 INSERT INTO t1 SELECT * FROM t2; 328 INSERT INTO t1 SELECT * FROM t2;
325 UPDATE t3 SET x=0; 329 UPDATE t3 SET x=0;
326 BEGIN; 330 BEGIN;
327 $cmd t3 SET x=1; 331 $cmd t3 SET x=1;
328 $cmd t1 SET b=b*2; 332 $cmd t1 SET b=b*2;
329 $cmd t1 SET a=c+5; 333 $cmd t1 SET a=c+5;
330 }]} r1] 334 }]} r1]
331 catch {execsql {COMMIT}} 335 catch {execsql {COMMIT}}
332 if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]} 336 if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]}
333 set r2 [execsql {SELECT x FROM t3}] 337 set r2 [execsql {SELECT x FROM t3}]
334 list $r0 $r1 $r2 $::sqlite_opentemp_count 338 list $r0 $r1 $r2 $::sqlite_opentemp_count
335 } [list $t0 $t1 $t2 $t3] 339 } [list $t0 $t1 $t2 $t3]
336 } 340 }
337 341
338 # Test to make sure a lot of IGNOREs don't cause a stack overflow 342 # Test to make sure a lot of IGNOREs don't cause a stack overflow
339 # 343 #
340 do_test conflict-7.1 { 344 do_test conflict2-7.1 {
341 execsql { 345 execsql {
342 DROP TABLE t1; 346 DROP TABLE t1;
343 DROP TABLE t2; 347 DROP TABLE t2;
344 DROP TABLE t3; 348 DROP TABLE t3;
345 CREATE TABLE t1(a unique, b); 349 CREATE TABLE t1(a PRIMARY KEY, b) without rowid;
346 } 350 }
347 for {set i 1} {$i<=50} {incr i} { 351 for {set i 1} {$i<=50} {incr i} {
348 execsql "INSERT into t1 values($i,[expr {$i+1}]);" 352 execsql "INSERT into t1 values($i,[expr {$i+1}]);"
349 } 353 }
350 execsql { 354 execsql {
351 SELECT count(*), min(a), max(b) FROM t1; 355 SELECT count(*), min(a), max(b) FROM t1;
352 } 356 }
353 } {50 1 51} 357 } {50 1 51}
354 do_test conflict-7.2 { 358 do_test conflict2-7.2 {
355 execsql { 359 execsql {
356 PRAGMA count_changes=on; 360 PRAGMA count_changes=on;
357 UPDATE OR IGNORE t1 SET a=1000; 361 UPDATE OR IGNORE t1 SET a=1000;
358 } 362 }
359 } {1} 363 } {1}
360 do_test conflict-7.2.1 { 364 do_test conflict2-7.2.1 {
361 db changes 365 db changes
362 } {1} 366 } {1}
363 do_test conflict-7.3 { 367 do_test conflict2-7.3 {
364 execsql { 368 execsql {
365 SELECT b FROM t1 WHERE a=1000; 369 SELECT b FROM t1 WHERE a=1000;
366 } 370 }
367 } {2} 371 } {2}
368 do_test conflict-7.4 { 372 do_test conflict2-7.4 {
369 execsql { 373 execsql {
370 SELECT count(*) FROM t1; 374 SELECT count(*) FROM t1;
371 } 375 }
372 } {50} 376 } {50}
373 do_test conflict-7.5 { 377 do_test conflict2-7.5 {
374 execsql { 378 execsql {
375 PRAGMA count_changes=on; 379 PRAGMA count_changes=on;
376 UPDATE OR REPLACE t1 SET a=1001; 380 UPDATE OR REPLACE t1 SET a=1001;
377 } 381 }
378 } {50} 382 } {50}
379 do_test conflict-7.5.1 { 383 do_test conflict2-7.5.1 {
380 db changes 384 db changes
381 } {50} 385 } {50}
382 do_test conflict-7.6 { 386 do_test conflict2-7.7 {
383 execsql {
384 SELECT b FROM t1 WHERE a=1001;
385 }
386 } {51}
387 do_test conflict-7.7 {
388 execsql { 387 execsql {
389 SELECT count(*) FROM t1; 388 SELECT count(*) FROM t1;
390 } 389 }
391 } {1} 390 } {1}
392 391
393 # Update for version 3: A SELECT statement no longer resets the change 392 # Update for version 3: A SELECT statement no longer resets the change
394 # counter (Test result changes from 0 to 50). 393 # counter (Test result changes from 0 to 50).
395 do_test conflict-7.7.1 { 394 do_test conflict2-7.7.1 {
396 db changes 395 db changes
397 } {50} 396 } {50}
398 397
399 # Make sure the row count is right for rows that are ignored on 398 # Make sure the row count is right for rows that are ignored on
400 # an insert. 399 # an insert.
401 # 400 #
402 do_test conflict-8.1 { 401 do_test conflict2-8.1 {
403 execsql { 402 execsql {
404 DELETE FROM t1; 403 DELETE FROM t1;
405 INSERT INTO t1 VALUES(1,2); 404 INSERT INTO t1 VALUES(1,2);
406 } 405 }
407 execsql { 406 execsql {
408 INSERT OR IGNORE INTO t1 VALUES(2,3); 407 INSERT OR IGNORE INTO t1 VALUES(2,3);
409 } 408 }
410 } {1} 409 } {1}
411 do_test conflict-8.1.1 { 410 do_test conflict2-8.1.1 {
412 db changes 411 db changes
413 } {1} 412 } {1}
414 do_test conflict-8.2 { 413 do_test conflict2-8.2 {
415 execsql { 414 execsql {
416 INSERT OR IGNORE INTO t1 VALUES(2,4); 415 INSERT OR IGNORE INTO t1 VALUES(2,4);
417 } 416 }
418 } {0} 417 } {0}
419 do_test conflict-8.2.1 { 418 do_test conflict2-8.2.1 {
420 db changes 419 db changes
421 } {0} 420 } {0}
422 do_test conflict-8.3 { 421 do_test conflict2-8.3 {
423 execsql { 422 execsql {
424 INSERT OR REPLACE INTO t1 VALUES(2,4); 423 INSERT OR REPLACE INTO t1 VALUES(2,4);
425 } 424 }
426 } {1} 425 } {1}
427 do_test conflict-8.3.1 { 426 do_test conflict2-8.3.1 {
428 db changes 427 db changes
429 } {1} 428 } {1}
430 do_test conflict-8.4 { 429 do_test conflict2-8.4 {
431 execsql { 430 execsql {
432 INSERT OR IGNORE INTO t1 SELECT * FROM t1; 431 INSERT OR IGNORE INTO t1 SELECT * FROM t1;
433 } 432 }
434 } {0} 433 } {0}
435 do_test conflict-8.4.1 { 434 do_test conflict2-8.4.1 {
436 db changes 435 db changes
437 } {0} 436 } {0}
438 do_test conflict-8.5 { 437 do_test conflict2-8.5 {
439 execsql { 438 execsql {
440 INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1; 439 INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1;
441 } 440 }
442 } {2} 441 } {2}
443 do_test conflict-8.5.1 { 442 do_test conflict2-8.5.1 {
444 db changes 443 db changes
445 } {2} 444 } {2}
446 do_test conflict-8.6 { 445 do_test conflict2-8.6 {
447 execsql { 446 execsql {
448 INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1; 447 INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1;
449 } 448 }
450 } {3} 449 } {3}
451 do_test conflict-8.6.1 { 450 do_test conflict2-8.6.1 {
452 db changes 451 db changes
453 } {3} 452 } {3}
454 453
455 integrity_check conflict-8.99 454 integrity_check conflict2-8.99
456 455
457 do_test conflict-9.1 { 456 do_test conflict2-9.1 {
458 execsql { 457 execsql {
459 PRAGMA count_changes=0; 458 PRAGMA count_changes=0;
460 CREATE TABLE t2( 459 CREATE TABLE t2(
461 a INTEGER UNIQUE ON CONFLICT IGNORE, 460 a INTEGER PRIMARY KEY ON CONFLICT IGNORE,
462 b INTEGER UNIQUE ON CONFLICT FAIL, 461 b INTEGER UNIQUE ON CONFLICT FAIL,
463 c INTEGER UNIQUE ON CONFLICT REPLACE, 462 c INTEGER UNIQUE ON CONFLICT REPLACE,
464 d INTEGER UNIQUE ON CONFLICT ABORT, 463 d INTEGER UNIQUE ON CONFLICT ABORT,
465 e INTEGER UNIQUE ON CONFLICT ROLLBACK 464 e INTEGER UNIQUE ON CONFLICT ROLLBACK
466 ); 465 ) WITHOUT rowid;
467 CREATE TABLE t3(x); 466 CREATE TABLE t3(x);
468 INSERT INTO t3 VALUES(1); 467 INSERT INTO t3 VALUES(1);
469 SELECT * FROM t3; 468 SELECT * FROM t3;
470 } 469 }
471 } {1} 470 } {1}
472 do_test conflict-9.2 { 471 do_test conflict2-9.2 {
473 catchsql { 472 catchsql {
474 INSERT INTO t2 VALUES(1,1,1,1,1); 473 INSERT INTO t2 VALUES(1,1,1,1,1);
475 INSERT INTO t2 VALUES(2,2,2,2,2); 474 INSERT INTO t2 VALUES(2,2,2,2,2);
476 SELECT * FROM t2; 475 SELECT * FROM t2;
477 } 476 }
478 } {0 {1 1 1 1 1 2 2 2 2 2}} 477 } {0 {1 1 1 1 1 2 2 2 2 2}}
479 do_test conflict-9.3 { 478 do_test conflict2-9.3 {
480 catchsql { 479 catchsql {
481 INSERT INTO t2 VALUES(1,3,3,3,3); 480 INSERT INTO t2 VALUES(1,3,3,3,3);
482 SELECT * FROM t2; 481 SELECT * FROM t2;
483 } 482 }
484 } {0 {1 1 1 1 1 2 2 2 2 2}} 483 } {0 {1 1 1 1 1 2 2 2 2 2}}
485 do_test conflict-9.4 { 484 do_test conflict2-9.4 {
486 catchsql { 485 catchsql {
487 UPDATE t2 SET a=a+1 WHERE a=1; 486 UPDATE t2 SET a=a+1 WHERE a=1;
488 SELECT * FROM t2; 487 SELECT * FROM t2;
489 } 488 }
490 } {0 {1 1 1 1 1 2 2 2 2 2}} 489 } {0 {1 1 1 1 1 2 2 2 2 2}}
491 do_test conflict-9.5 { 490 do_test conflict2-9.5 {
492 catchsql { 491 catchsql {
493 INSERT INTO t2 VALUES(3,1,3,3,3); 492 INSERT INTO t2 VALUES(3,1,3,3,3);
494 SELECT * FROM t2; 493 }
495 } 494 } {1 {UNIQUE constraint failed: t2.b}}
496 } {1 {column b is not unique}} 495 do_test conflict2-9.5b {
497 do_test conflict-9.6 { 496 db eval {SELECT * FROM t2;}
497 } {1 1 1 1 1 2 2 2 2 2}
498 do_test conflict2-9.6 {
498 catchsql { 499 catchsql {
499 UPDATE t2 SET b=b+1 WHERE b=1; 500 UPDATE t2 SET b=b+1 WHERE b=1;
500 SELECT * FROM t2; 501 SELECT * FROM t2;
501 } 502 }
502 } {1 {column b is not unique}} 503 } {1 {UNIQUE constraint failed: t2.b}}
503 do_test conflict-9.7 { 504 do_test conflict2-9.6b {
505 db eval {SELECT * FROM t2;}
506 } {1 1 1 1 1 2 2 2 2 2}
507 do_test conflict2-9.7 {
504 catchsql { 508 catchsql {
505 BEGIN; 509 BEGIN;
506 UPDATE t3 SET x=x+1; 510 UPDATE t3 SET x=x+1;
507 INSERT INTO t2 VALUES(3,1,3,3,3); 511 INSERT INTO t2 VALUES(3,1,3,3,3);
508 SELECT * FROM t2; 512 SELECT * FROM t2;
509 } 513 }
510 } {1 {column b is not unique}} 514 } {1 {UNIQUE constraint failed: t2.b}}
511 do_test conflict-9.8 { 515 do_test conflict2-9.8 {
512 execsql {COMMIT} 516 execsql {COMMIT}
513 execsql {SELECT * FROM t3} 517 execsql {SELECT * FROM t3}
514 } {2} 518 } {2}
515 do_test conflict-9.9 { 519 do_test conflict2-9.9 {
516 catchsql { 520 catchsql {
517 BEGIN; 521 BEGIN;
518 UPDATE t3 SET x=x+1; 522 UPDATE t3 SET x=x+1;
519 UPDATE t2 SET b=b+1 WHERE b=1; 523 UPDATE t2 SET b=b+1 WHERE b=1;
520 SELECT * FROM t2; 524 SELECT * FROM t2;
521 } 525 }
522 } {1 {column b is not unique}} 526 } {1 {UNIQUE constraint failed: t2.b}}
523 do_test conflict-9.10 { 527 do_test conflict2-9.10 {
524 execsql {COMMIT} 528 execsql {COMMIT}
525 execsql {SELECT * FROM t3} 529 execsql {SELECT * FROM t3}
526 } {3} 530 } {3}
527 do_test conflict-9.11 { 531 do_test conflict2-9.11 {
528 catchsql { 532 catchsql {
529 INSERT INTO t2 VALUES(3,3,3,1,3); 533 INSERT INTO t2 VALUES(3,3,3,1,3);
530 SELECT * FROM t2; 534 SELECT * FROM t2;
531 } 535 }
532 } {1 {column d is not unique}} 536 } {1 {UNIQUE constraint failed: t2.d}}
533 do_test conflict-9.12 { 537 do_test conflict2-9.12 {
534 catchsql { 538 catchsql {
535 UPDATE t2 SET d=d+1 WHERE d=1; 539 UPDATE t2 SET d=d+1 WHERE d=1;
536 SELECT * FROM t2; 540 SELECT * FROM t2;
537 } 541 }
538 } {1 {column d is not unique}} 542 } {1 {UNIQUE constraint failed: t2.d}}
539 do_test conflict-9.13 { 543 do_test conflict2-9.13 {
540 catchsql { 544 catchsql {
541 BEGIN; 545 BEGIN;
542 UPDATE t3 SET x=x+1; 546 UPDATE t3 SET x=x+1;
543 INSERT INTO t2 VALUES(3,3,3,1,3); 547 INSERT INTO t2 VALUES(3,3,3,1,3);
544 SELECT * FROM t2; 548 SELECT * FROM t2;
545 } 549 }
546 } {1 {column d is not unique}} 550 } {1 {UNIQUE constraint failed: t2.d}}
547 do_test conflict-9.14 { 551 do_test conflict2-9.14 {
548 execsql {COMMIT} 552 execsql {COMMIT}
549 execsql {SELECT * FROM t3} 553 execsql {SELECT * FROM t3}
550 } {4} 554 } {4}
551 do_test conflict-9.15 { 555 do_test conflict2-9.15 {
552 catchsql { 556 catchsql {
553 BEGIN; 557 BEGIN;
554 UPDATE t3 SET x=x+1; 558 UPDATE t3 SET x=x+1;
555 UPDATE t2 SET d=d+1 WHERE d=1; 559 UPDATE t2 SET d=d+1 WHERE d=1;
556 SELECT * FROM t2; 560 SELECT * FROM t2;
557 } 561 }
558 } {1 {column d is not unique}} 562 } {1 {UNIQUE constraint failed: t2.d}}
559 do_test conflict-9.16 { 563 do_test conflict2-9.16 {
560 execsql {COMMIT} 564 execsql {COMMIT}
561 execsql {SELECT * FROM t3} 565 execsql {SELECT * FROM t3}
562 } {5} 566 } {5}
563 do_test conflict-9.17 { 567 do_test conflict2-9.17 {
564 catchsql { 568 catchsql {
565 INSERT INTO t2 VALUES(3,3,3,3,1); 569 INSERT INTO t2 VALUES(3,3,3,3,1);
566 SELECT * FROM t2; 570 SELECT * FROM t2;
567 } 571 }
568 } {1 {column e is not unique}} 572 } {1 {UNIQUE constraint failed: t2.e}}
569 do_test conflict-9.18 { 573 do_test conflict2-9.18 {
570 catchsql { 574 catchsql {
571 UPDATE t2 SET e=e+1 WHERE e=1; 575 UPDATE t2 SET e=e+1 WHERE e=1;
572 SELECT * FROM t2; 576 SELECT * FROM t2;
573 } 577 }
574 } {1 {column e is not unique}} 578 } {1 {UNIQUE constraint failed: t2.e}}
575 do_test conflict-9.19 { 579 do_test conflict2-9.19 {
576 catchsql { 580 catchsql {
577 BEGIN; 581 BEGIN;
578 UPDATE t3 SET x=x+1; 582 UPDATE t3 SET x=x+1;
579 INSERT INTO t2 VALUES(3,3,3,3,1); 583 INSERT INTO t2 VALUES(3,3,3,3,1);
580 SELECT * FROM t2; 584 SELECT * FROM t2;
581 } 585 }
582 } {1 {column e is not unique}} 586 } {1 {UNIQUE constraint failed: t2.e}}
583 do_test conflict-9.20 { 587 verify_ex_errcode conflict2-9.21b SQLITE_CONSTRAINT_UNIQUE
588 do_test conflict2-9.20 {
584 catch {execsql {COMMIT}} 589 catch {execsql {COMMIT}}
585 execsql {SELECT * FROM t3} 590 execsql {SELECT * FROM t3}
586 } {5} 591 } {5}
587 do_test conflict-9.21 { 592 do_test conflict2-9.21 {
588 catchsql { 593 catchsql {
589 BEGIN; 594 BEGIN;
590 UPDATE t3 SET x=x+1; 595 UPDATE t3 SET x=x+1;
591 UPDATE t2 SET e=e+1 WHERE e=1; 596 UPDATE t2 SET e=e+1 WHERE e=1;
592 SELECT * FROM t2; 597 SELECT * FROM t2;
593 } 598 }
594 } {1 {column e is not unique}} 599 } {1 {UNIQUE constraint failed: t2.e}}
595 do_test conflict-9.22 { 600 verify_ex_errcode conflict2-9.21b SQLITE_CONSTRAINT_UNIQUE
601 do_test conflict2-9.22 {
596 catch {execsql {COMMIT}} 602 catch {execsql {COMMIT}}
597 execsql {SELECT * FROM t3} 603 execsql {SELECT * FROM t3}
598 } {5} 604 } {5}
599 do_test conflict-9.23 { 605 do_test conflict2-9.23 {
600 catchsql { 606 catchsql {
601 INSERT INTO t2 VALUES(3,3,1,3,3); 607 INSERT INTO t2 VALUES(3,3,1,3,3);
602 SELECT * FROM t2; 608 SELECT * FROM t2;
603 } 609 }
604 } {0 {2 2 2 2 2 3 3 1 3 3}} 610 } {0 {2 2 2 2 2 3 3 1 3 3}}
605 do_test conflict-9.24 { 611 do_test conflict2-9.24 {
606 catchsql { 612 catchsql {
607 UPDATE t2 SET c=c-1 WHERE c=2; 613 UPDATE t2 SET c=c-1 WHERE c=2;
608 SELECT * FROM t2; 614 SELECT * FROM t2;
609 } 615 }
610 } {0 {2 2 1 2 2}} 616 } {0 {2 2 1 2 2}}
611 do_test conflict-9.25 { 617 do_test conflict2-9.25 {
612 catchsql { 618 catchsql {
613 BEGIN; 619 BEGIN;
614 UPDATE t3 SET x=x+1; 620 UPDATE t3 SET x=x+1;
615 INSERT INTO t2 VALUES(3,3,1,3,3); 621 INSERT INTO t2 VALUES(3,3,1,3,3);
616 SELECT * FROM t2; 622 SELECT * FROM t2;
617 } 623 }
618 } {0 {3 3 1 3 3}} 624 } {0 {3 3 1 3 3}}
619 do_test conflict-9.26 { 625 do_test conflict2-9.26 {
620 catch {execsql {COMMIT}} 626 catch {execsql {COMMIT}}
621 execsql {SELECT * FROM t3} 627 execsql {SELECT * FROM t3}
622 } {6} 628 } {6}
623 629
624 do_test conflict-10.1 { 630 do_test conflict2-10.1 {
625 catchsql { 631 catchsql {
626 DELETE FROM t1; 632 DELETE FROM t1;
627 BEGIN; 633 BEGIN;
628 INSERT OR ROLLBACK INTO t1 VALUES(1,2); 634 INSERT OR ROLLBACK INTO t1 VALUES(1,2);
629 INSERT OR ROLLBACK INTO t1 VALUES(1,3); 635 INSERT OR ROLLBACK INTO t1 VALUES(1,3);
630 COMMIT; 636 COMMIT;
631 } 637 }
632 execsql {SELECT * FROM t1} 638 execsql {SELECT * FROM t1}
633 } {} 639 } {}
634 do_test conflict-10.2 { 640 do_test conflict2-10.2 {
635 catchsql { 641 catchsql {
636 CREATE TABLE t4(x); 642 CREATE TABLE t4(x);
637 CREATE UNIQUE INDEX t4x ON t4(x); 643 CREATE UNIQUE INDEX t4x ON t4(x);
638 BEGIN; 644 BEGIN;
639 INSERT OR ROLLBACK INTO t4 VALUES(1); 645 INSERT OR ROLLBACK INTO t4 VALUES(1);
640 INSERT OR ROLLBACK INTO t4 VALUES(1); 646 INSERT OR ROLLBACK INTO t4 VALUES(1);
641 COMMIT; 647 COMMIT;
642 } 648 }
643 execsql {SELECT * FROM t4} 649 execsql {SELECT * FROM t4}
644 } {} 650 } {}
645 651
646 # Ticket #1171. Make sure statement rollbacks do not 652 # Ticket #1171. Make sure statement rollbacks do not
647 # damage the database. 653 # damage the database.
648 # 654 #
649 do_test conflict-11.1 { 655 do_test conflict2-11.1 {
650 execsql { 656 execsql {
651 -- Create a database object (pages 2, 3 of the file) 657 -- Create a database object (pages 2, 3 of the file)
652 BEGIN; 658 BEGIN;
653 CREATE TABLE abc(a UNIQUE, b, c); 659 CREATE TABLE abc(a PRIMARY KEY, b, c) WITHOUT rowid;
654 INSERT INTO abc VALUES(1, 2, 3); 660 INSERT INTO abc VALUES(1, 2, 3);
655 INSERT INTO abc VALUES(4, 5, 6); 661 INSERT INTO abc VALUES(4, 5, 6);
656 INSERT INTO abc VALUES(7, 8, 9); 662 INSERT INTO abc VALUES(7, 8, 9);
657 COMMIT; 663 COMMIT;
658 } 664 }
659 665
660 666
661 # Set a small cache size so that changes will spill into 667 # Set a small cache size so that changes will spill into
662 # the database file. 668 # the database file.
663 execsql { 669 execsql {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 # Rollback the database. Verify that the state of the ABC table 701 # Rollback the database. Verify that the state of the ABC table
696 # is unchanged from the beginning of the transaction. In other words, 702 # is unchanged from the beginning of the transaction. In other words,
697 # make sure the DELETE on table ABC that occurred within the transaction 703 # make sure the DELETE on table ABC that occurred within the transaction
698 # had no effect. 704 # had no effect.
699 # 705 #
700 execsql { 706 execsql {
701 ROLLBACK; 707 ROLLBACK;
702 SELECT * FROM abc; 708 SELECT * FROM abc;
703 } 709 }
704 } {1 2 3 4 5 6 7 8 9} 710 } {1 2 3 4 5 6 7 8 9}
705 integrity_check conflict-11.2 711 integrity_check conflict2-11.2
706 712
707 # Repeat test conflict-11.1 but this time commit. 713 # Repeat test conflict2-11.1 but this time commit.
708 # 714 #
709 do_test conflict-11.3 { 715 do_test conflict2-11.3 {
710 execsql { 716 execsql {
711 BEGIN; 717 BEGIN;
712 -- Make sure the pager is in EXCLUSIVE state. 718 -- Make sure the pager is in EXCLUSIVE state.
713 UPDATE abc SET a=a+1; 719 UPDATE abc SET a=a+1;
714 CREATE TABLE def(d, e, f); 720 CREATE TABLE def(d, e, f);
715 INSERT INTO def VALUES 721 INSERT INTO def VALUES
716 ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); 722 ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz');
717 INSERT INTO def SELECT * FROM def; 723 INSERT INTO def SELECT * FROM def;
718 INSERT INTO def SELECT * FROM def; 724 INSERT INTO def SELECT * FROM def;
719 INSERT INTO def SELECT * FROM def; 725 INSERT INTO def SELECT * FROM def;
720 INSERT INTO def SELECT * FROM def; 726 INSERT INTO def SELECT * FROM def;
721 INSERT INTO def SELECT * FROM def; 727 INSERT INTO def SELECT * FROM def;
722 INSERT INTO def SELECT * FROM def; 728 INSERT INTO def SELECT * FROM def;
723 INSERT INTO def SELECT * FROM def; 729 INSERT INTO def SELECT * FROM def;
724 DELETE FROM abc WHERE a = 4; 730 DELETE FROM abc WHERE a = 4;
725 } 731 }
726 catchsql { 732 catchsql {
727 INSERT INTO abc SELECT 10, 20, 30 FROM def; 733 INSERT INTO abc SELECT 10, 20, 30 FROM def;
728 } 734 }
729 execsql { 735 execsql {
730 ROLLBACK; 736 ROLLBACK;
731 SELECT * FROM abc; 737 SELECT * FROM abc;
732 } 738 }
733 } {1 2 3 4 5 6 7 8 9} 739 } {1 2 3 4 5 6 7 8 9}
734 # Repeat test conflict-11.1 but this time commit. 740 # Repeat test conflict2-11.1 but this time commit.
735 # 741 #
736 do_test conflict-11.5 { 742 do_test conflict2-11.5 {
737 execsql { 743 execsql {
738 BEGIN; 744 BEGIN;
739 -- Make sure the pager is in EXCLUSIVE state. 745 -- Make sure the pager is in EXCLUSIVE state.
740 CREATE TABLE def(d, e, f); 746 CREATE TABLE def(d, e, f);
741 INSERT INTO def VALUES 747 INSERT INTO def VALUES
742 ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); 748 ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz');
743 INSERT INTO def SELECT * FROM def; 749 INSERT INTO def SELECT * FROM def;
744 INSERT INTO def SELECT * FROM def; 750 INSERT INTO def SELECT * FROM def;
745 INSERT INTO def SELECT * FROM def; 751 INSERT INTO def SELECT * FROM def;
746 INSERT INTO def SELECT * FROM def; 752 INSERT INTO def SELECT * FROM def;
747 INSERT INTO def SELECT * FROM def; 753 INSERT INTO def SELECT * FROM def;
748 INSERT INTO def SELECT * FROM def; 754 INSERT INTO def SELECT * FROM def;
749 INSERT INTO def SELECT * FROM def; 755 INSERT INTO def SELECT * FROM def;
750 DELETE FROM abc WHERE a = 4; 756 DELETE FROM abc WHERE a = 4;
751 } 757 }
752 catchsql { 758 catchsql {
753 INSERT INTO abc SELECT 10, 20, 30 FROM def; 759 INSERT INTO abc SELECT 10, 20, 30 FROM def;
754 } 760 }
755 execsql { 761 execsql {
756 COMMIT; 762 COMMIT;
757 SELECT * FROM abc; 763 SELECT * FROM abc;
758 } 764 }
759 } {1 2 3 7 8 9} 765 } {1 2 3 7 8 9}
760 integrity_check conflict-11.6 766 integrity_check conflict2-11.6
761 767
762 # Make sure UPDATE OR REPLACE works on tables that have only 768 # Make sure UPDATE OR REPLACE works on tables that have only
763 # an INTEGER PRIMARY KEY. 769 # an INTEGER PRIMARY KEY.
764 # 770 #
765 do_test conflict-12.1 { 771 do_test conflict2-12.1 {
766 execsql { 772 execsql {
767 CREATE TABLE t5(a INTEGER PRIMARY KEY, b text); 773 CREATE TABLE t5(a INTEGER PRIMARY KEY, b text) WITHOUT rowid;
768 INSERT INTO t5 VALUES(1,'one'); 774 INSERT INTO t5 VALUES(1,'one');
769 INSERT INTO t5 VALUES(2,'two'); 775 INSERT INTO t5 VALUES(2,'two');
770 SELECT * FROM t5 776 SELECT * FROM t5
771 } 777 }
772 } {1 one 2 two} 778 } {1 one 2 two}
773 do_test conflict-12.2 { 779 do_test conflict2-12.2 {
774 execsql { 780 execsql {
775 UPDATE OR IGNORE t5 SET a=a+1 WHERE a=1; 781 UPDATE OR IGNORE t5 SET a=a+1 WHERE a=1;
776 SELECT * FROM t5; 782 SELECT * FROM t5;
777 } 783 }
778 } {1 one 2 two} 784 } {1 one 2 two}
779 do_test conflict-12.3 { 785 do_test conflict2-12.3 {
780 catchsql { 786 catchsql {
781 UPDATE t5 SET a=a+1 WHERE a=1; 787 UPDATE t5 SET a=a+1 WHERE a=1;
782 } 788 }
783 } {1 {PRIMARY KEY must be unique}} 789 } {1 {UNIQUE constraint failed: t5.a}}
784 do_test conflict-12.4 { 790 verify_ex_errcode conflict2-12.3b SQLITE_CONSTRAINT_PRIMARYKEY
791 do_test conflict2-12.4 {
785 execsql { 792 execsql {
786 UPDATE OR REPLACE t5 SET a=a+1 WHERE a=1; 793 UPDATE OR REPLACE t5 SET a=a+1 WHERE a=1;
787 SELECT * FROM t5; 794 SELECT * FROM t5;
788 } 795 }
789 } {2 one} 796 } {2 one}
790 797
791 798
792 # Ticket [c38baa3d969eab7946dc50ba9d9b4f0057a19437] 799 # Ticket [c38baa3d969eab7946dc50ba9d9b4f0057a19437]
793 # REPLACE works like ABORT on a CHECK constraint. 800 # REPLACE works like ABORT on a CHECK constraint.
794 # 801 #
795 do_test conflict-13.1 { 802 do_test conflict2-13.1 {
796 execsql { 803 execsql {
797 CREATE TABLE t13(a CHECK(a!=2)); 804 CREATE TABLE t13(a PRIMARY KEY CHECK(a!=2)) WITHOUT rowid;
798 BEGIN; 805 BEGIN;
799 REPLACE INTO t13 VALUES(1); 806 REPLACE INTO t13 VALUES(1);
800 } 807 }
801 catchsql { 808 catchsql {
802 REPLACE INTO t13 VALUES(2); 809 REPLACE INTO t13 VALUES(2);
803 } 810 }
804 } {1 {constraint failed}} 811 } {1 {CHECK constraint failed: t13}}
805 do_test conflict-13.2 { 812 verify_ex_errcode conflict2-13.1b SQLITE_CONSTRAINT_CHECK
813 do_test conflict2-13.2 {
806 execsql { 814 execsql {
807 REPLACE INTO t13 VALUES(3); 815 REPLACE INTO t13 VALUES(3);
808 COMMIT; 816 COMMIT;
809 SELECT * FROM t13; 817 SELECT * FROM t13;
810 } 818 }
811 } {1 3} 819 } {1 3}
812 820
821 # Test for an unreleased bug in the REPLACE conflict resolution
822 # discovered on 2013-11-09.
823 #
824 do_execsql_test conflict2-14.1 {
825 DROP TABLE IF EXISTS t1;
826 CREATE TABLE t1(
827 x TEXT PRIMARY KEY NOT NULL,
828 y TEXT NOT NULL,
829 z INTEGER
830 );
831 INSERT INTO t1 VALUES('alpha','beta',1);
832 CREATE UNIQUE INDEX t1xy ON t1(x,y);
833 REPLACE INTO t1(x,y,z) VALUES('alpha','gamma',1);
834 PRAGMA integrity_check;
835 SELECT x,y FROM t1 INDEXED BY t1xy;
836 SELECT x,y,z FROM t1 NOT INDEXED;
837 } {ok alpha gamma alpha gamma 1}
838 do_execsql_test conflict2-14.2 {
839 DROP TABLE IF EXISTS t1;
840 CREATE TABLE t1(
841 x TEXT PRIMARY KEY NOT NULL,
842 y TEXT NOT NULL,
843 z INTEGER
844 ) WITHOUT ROWID;
845 INSERT INTO t1 VALUES('alpha','beta',1);
846 CREATE UNIQUE INDEX t1xy ON t1(x,y);
847 REPLACE INTO t1(x,y,z) VALUES('alpha','gamma',1);
848 PRAGMA integrity_check;
849 SELECT x,y FROM t1 INDEXED BY t1xy;
850 SELECT x,y,z FROM t1 NOT INDEXED;
851 } {ok alpha gamma alpha gamma 1}
852
853
813 854
814 finish_test 855 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3080704/test/conflict.test ('k') | third_party/sqlite/sqlite-src-3080704/test/conflict3.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698