drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 1 | # 2013-11-05 |
| 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 | # This file implements regression tests for SQLite library. |
| 12 | # |
| 13 | # This file implements tests for the conflict resolution extension |
| 14 | # to SQLite. |
| 15 | # |
| 16 | # This file focuses on making sure that combinations of REPLACE, |
| 17 | # IGNORE, and FAIL conflict resolution play well together. |
| 18 | # |
| 19 | |
| 20 | set testdir [file dirname $argv0] |
| 21 | source $testdir/tester.tcl |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 22 | set testprefix conflict3 |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 23 | |
| 24 | ifcapable !conflict { |
| 25 | finish_test |
| 26 | return |
| 27 | } |
| 28 | |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 29 | do_execsql_test 1.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 30 | CREATE TABLE t1( |
| 31 | a INTEGER PRIMARY KEY ON CONFLICT REPLACE, |
| 32 | b UNIQUE ON CONFLICT IGNORE, |
| 33 | c UNIQUE ON CONFLICT FAIL |
| 34 | ); |
| 35 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 36 | SELECT a,b,c FROM t1 ORDER BY a; |
| 37 | } {1 2 3 2 3 4} |
| 38 | |
| 39 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 40 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 41 | do_execsql_test 1.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 42 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 43 | SELECT a,b,c FROM t1 ORDER BY a; |
| 44 | } {1 2 3 2 3 4} |
| 45 | |
| 46 | # Insert two rows where the second conflicts on C. The first row show go |
| 47 | # and and then there should be a constraint error. |
| 48 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 49 | do_test 1.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 50 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 51 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 52 | do_execsql_test 1.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 53 | SELECT a,b,c FROM t1 ORDER BY a; |
| 54 | } {1 2 3 2 3 4 4 5 6} |
| 55 | |
| 56 | # Replete the tests above, but this time on a table non-INTEGER primary key. |
| 57 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 58 | do_execsql_test 2.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 59 | DROP TABLE t1; |
| 60 | CREATE TABLE t1( |
| 61 | a INT PRIMARY KEY ON CONFLICT REPLACE, |
| 62 | b UNIQUE ON CONFLICT IGNORE, |
| 63 | c UNIQUE ON CONFLICT FAIL |
| 64 | ); |
| 65 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 66 | SELECT a,b,c FROM t1 ORDER BY a; |
| 67 | } {1 2 3 2 3 4} |
| 68 | |
| 69 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 70 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 71 | do_execsql_test 2.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 72 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 73 | SELECT a,b,c FROM t1 ORDER BY a; |
| 74 | } {1 2 3 2 3 4} |
| 75 | |
| 76 | # Insert two rows where the second conflicts on C. The first row show go |
| 77 | # and and then there should be a constraint error. |
| 78 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 79 | do_test 2.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 80 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 81 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 82 | do_execsql_test 2.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 83 | SELECT a,b,c FROM t1 ORDER BY a; |
| 84 | } {1 2 3 2 3 4 4 5 6} |
| 85 | |
| 86 | # Replete again on a WITHOUT ROWID table. |
| 87 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 88 | do_execsql_test 3.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 89 | DROP TABLE t1; |
| 90 | CREATE TABLE t1( |
| 91 | a INT PRIMARY KEY ON CONFLICT REPLACE, |
| 92 | b UNIQUE ON CONFLICT IGNORE, |
| 93 | c UNIQUE ON CONFLICT FAIL |
| 94 | ) WITHOUT ROWID; |
| 95 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 96 | SELECT a,b,c FROM t1 ORDER BY a; |
| 97 | } {1 2 3 2 3 4} |
| 98 | |
| 99 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 100 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 101 | do_execsql_test 3.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 102 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 103 | SELECT a,b,c FROM t1 ORDER BY a; |
| 104 | } {1 2 3 2 3 4} |
| 105 | |
| 106 | # Insert two rows where the second conflicts on C. The first row show go |
| 107 | # and and then there should be a constraint error. |
| 108 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 109 | do_test 3.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 110 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 111 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 112 | do_execsql_test 3.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 113 | SELECT a,b,c FROM t1 ORDER BY a; |
| 114 | } {1 2 3 2 3 4 4 5 6} |
| 115 | |
| 116 | # Arrange the table rows in a different order and repeat. |
| 117 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 118 | do_execsql_test 4.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 119 | DROP TABLE t1; |
| 120 | CREATE TABLE t1( |
| 121 | b UNIQUE ON CONFLICT IGNORE, |
| 122 | c UNIQUE ON CONFLICT FAIL, |
| 123 | a INT PRIMARY KEY ON CONFLICT REPLACE |
| 124 | ) WITHOUT ROWID; |
| 125 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 126 | SELECT a,b,c FROM t1 ORDER BY a; |
| 127 | } {1 2 3 2 3 4} |
| 128 | |
| 129 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 130 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 131 | do_execsql_test 4.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 132 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 133 | SELECT a,b,c FROM t1 ORDER BY a; |
| 134 | } {1 2 3 2 3 4} |
| 135 | |
| 136 | # Insert two rows where the second conflicts on C. The first row show go |
| 137 | # and and then there should be a constraint error. |
| 138 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 139 | do_test 4.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 140 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 141 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 142 | do_execsql_test 4.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 143 | SELECT a,b,c FROM t1 ORDER BY a; |
| 144 | } {1 2 3 2 3 4 4 5 6} |
| 145 | |
| 146 | # Arrange the table rows in a different order and repeat. |
| 147 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 148 | do_execsql_test 5.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 149 | DROP TABLE t1; |
| 150 | CREATE TABLE t1( |
| 151 | b UNIQUE ON CONFLICT IGNORE, |
| 152 | a INT PRIMARY KEY ON CONFLICT REPLACE, |
| 153 | c UNIQUE ON CONFLICT FAIL |
| 154 | ); |
| 155 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 156 | SELECT a,b,c FROM t1 ORDER BY a; |
| 157 | } {1 2 3 2 3 4} |
| 158 | |
| 159 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 160 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 161 | do_execsql_test 5.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 162 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 163 | SELECT a,b,c FROM t1 ORDER BY a; |
| 164 | } {1 2 3 2 3 4} |
| 165 | |
| 166 | # Insert two rows where the second conflicts on C. The first row show go |
| 167 | # and and then there should be a constraint error. |
| 168 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 169 | do_test 5.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 170 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 171 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 172 | do_execsql_test 5.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 173 | SELECT a,b,c FROM t1 ORDER BY a; |
| 174 | } {1 2 3 2 3 4 4 5 6} |
| 175 | |
| 176 | # Arrange the table rows in a different order and repeat. |
| 177 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 178 | do_execsql_test 6.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 179 | DROP TABLE t1; |
| 180 | CREATE TABLE t1( |
| 181 | c UNIQUE ON CONFLICT FAIL, |
| 182 | a INT PRIMARY KEY ON CONFLICT REPLACE, |
| 183 | b UNIQUE ON CONFLICT IGNORE |
| 184 | ); |
| 185 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 186 | SELECT a,b,c FROM t1 ORDER BY a; |
| 187 | } {1 2 3 2 3 4} |
| 188 | |
| 189 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 190 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 191 | do_execsql_test 6.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 192 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 193 | SELECT a,b,c FROM t1 ORDER BY a; |
| 194 | } {1 2 3 2 3 4} |
| 195 | |
| 196 | # Insert two rows where the second conflicts on C. The first row show go |
| 197 | # and and then there should be a constraint error. |
| 198 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 199 | do_test 6.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 200 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 201 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 202 | do_execsql_test 6.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 203 | SELECT a,b,c FROM t1 ORDER BY a; |
| 204 | } {1 2 3 2 3 4 4 5 6} |
| 205 | |
| 206 | # Change which column is the PRIMARY KEY |
| 207 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 208 | do_execsql_test 7.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 209 | DROP TABLE t1; |
| 210 | CREATE TABLE t1( |
| 211 | a UNIQUE ON CONFLICT REPLACE, |
| 212 | b INTEGER PRIMARY KEY ON CONFLICT IGNORE, |
| 213 | c UNIQUE ON CONFLICT FAIL |
| 214 | ); |
| 215 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 216 | SELECT a,b,c FROM t1 ORDER BY a; |
| 217 | } {1 2 3 2 3 4} |
| 218 | |
| 219 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 220 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 221 | do_execsql_test 7.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 222 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 223 | SELECT a,b,c FROM t1 ORDER BY a; |
| 224 | } {1 2 3 2 3 4} |
| 225 | |
| 226 | # Insert two rows where the second conflicts on C. The first row show go |
| 227 | # and and then there should be a constraint error. |
| 228 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 229 | do_test 7.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 230 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 231 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 232 | do_execsql_test 7.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 233 | SELECT a,b,c FROM t1 ORDER BY a; |
| 234 | } {1 2 3 2 3 4 4 5 6} |
| 235 | |
| 236 | # Change which column is the PRIMARY KEY |
| 237 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 238 | do_execsql_test 8.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 239 | DROP TABLE t1; |
| 240 | CREATE TABLE t1( |
| 241 | a UNIQUE ON CONFLICT REPLACE, |
| 242 | b INT PRIMARY KEY ON CONFLICT IGNORE, |
| 243 | c UNIQUE ON CONFLICT FAIL |
| 244 | ); |
| 245 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 246 | SELECT a,b,c FROM t1 ORDER BY a; |
| 247 | } {1 2 3 2 3 4} |
| 248 | |
| 249 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 250 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 251 | do_execsql_test 8.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 252 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 253 | SELECT a,b,c FROM t1 ORDER BY a; |
| 254 | } {1 2 3 2 3 4} |
| 255 | |
| 256 | # Insert two rows where the second conflicts on C. The first row show go |
| 257 | # and and then there should be a constraint error. |
| 258 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 259 | do_test 8.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 260 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 261 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 262 | do_execsql_test 8.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 263 | SELECT a,b,c FROM t1 ORDER BY a; |
| 264 | } {1 2 3 2 3 4 4 5 6} |
| 265 | |
| 266 | # Change which column is the PRIMARY KEY |
| 267 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 268 | do_execsql_test 9.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 269 | DROP TABLE t1; |
| 270 | CREATE TABLE t1( |
| 271 | a UNIQUE ON CONFLICT REPLACE, |
| 272 | b INT PRIMARY KEY ON CONFLICT IGNORE, |
| 273 | c UNIQUE ON CONFLICT FAIL |
| 274 | ) WITHOUT ROWID; |
| 275 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 276 | SELECT a,b,c FROM t1 ORDER BY a; |
| 277 | } {1 2 3 2 3 4} |
| 278 | |
| 279 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 280 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 281 | do_execsql_test 9.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 282 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 283 | SELECT a,b,c FROM t1 ORDER BY a; |
| 284 | } {1 2 3 2 3 4} |
| 285 | |
| 286 | # Insert two rows where the second conflicts on C. The first row show go |
| 287 | # and and then there should be a constraint error. |
| 288 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 289 | do_test 9.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 290 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 291 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 292 | do_execsql_test 9.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 293 | SELECT a,b,c FROM t1 ORDER BY a; |
| 294 | } {1 2 3 2 3 4 4 5 6} |
| 295 | |
| 296 | # Change which column is the PRIMARY KEY |
| 297 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 298 | do_execsql_test 10.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 299 | DROP TABLE t1; |
| 300 | CREATE TABLE t1( |
| 301 | a UNIQUE ON CONFLICT REPLACE, |
| 302 | b UNIQUE ON CONFLICT IGNORE, |
| 303 | c INTEGER PRIMARY KEY ON CONFLICT FAIL |
| 304 | ); |
| 305 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 306 | SELECT a,b,c FROM t1 ORDER BY a; |
| 307 | } {1 2 3 2 3 4} |
| 308 | |
| 309 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 310 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 311 | do_execsql_test 10.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 312 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 313 | SELECT a,b,c FROM t1 ORDER BY a; |
| 314 | } {1 2 3 2 3 4} |
| 315 | |
| 316 | # Insert two rows where the second conflicts on C. The first row show go |
| 317 | # and and then there should be a constraint error. |
| 318 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 319 | do_test 10.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 320 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 321 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 322 | do_execsql_test 10.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 323 | SELECT a,b,c FROM t1 ORDER BY a; |
| 324 | } {1 2 3 2 3 4 4 5 6} |
| 325 | |
| 326 | # Change which column is the PRIMARY KEY |
| 327 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 328 | do_execsql_test 11.1 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 329 | DROP TABLE t1; |
| 330 | CREATE TABLE t1( |
| 331 | a UNIQUE ON CONFLICT REPLACE, |
| 332 | b UNIQUE ON CONFLICT IGNORE, |
| 333 | c PRIMARY KEY ON CONFLICT FAIL |
| 334 | ) WITHOUT ROWID; |
| 335 | INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); |
| 336 | SELECT a,b,c FROM t1 ORDER BY a; |
| 337 | } {1 2 3 2 3 4} |
| 338 | |
| 339 | # Insert a row that conflicts on column B. The insert should be ignored. |
| 340 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 341 | do_execsql_test 11.2 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 342 | INSERT INTO t1(a,b,c) VALUES(3,2,5); |
| 343 | SELECT a,b,c FROM t1 ORDER BY a; |
| 344 | } {1 2 3 2 3 4} |
| 345 | |
| 346 | # Insert two rows where the second conflicts on C. The first row show go |
| 347 | # and and then there should be a constraint error. |
| 348 | # |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 349 | do_test 11.3 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 350 | catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} |
| 351 | } {1 {UNIQUE constraint failed: t1.c}} |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 352 | do_execsql_test 11.4 { |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 353 | SELECT a,b,c FROM t1 ORDER BY a; |
| 354 | } {1 2 3 2 3 4 4 5 6} |
| 355 | |
dan | 874080b | 2017-05-01 18:12:56 +0000 | [diff] [blame] | 356 | # Check that ticket [f68dc596c4] has been fixed. |
| 357 | # |
| 358 | do_execsql_test 12.1 { |
| 359 | CREATE TABLE t2(a INTEGER PRIMARY KEY, b TEXT); |
| 360 | INSERT INTO t2 VALUES(111, '111'); |
| 361 | } |
| 362 | do_execsql_test 12.2 { |
| 363 | REPLACE INTO t2 VALUES(NULL, '112'), (111, '111B'); |
| 364 | } |
| 365 | do_execsql_test 12.3 { |
| 366 | SELECT * FROM t2; |
| 367 | } {111 111B 112 112} |
| 368 | |
drh | 8d1b82e | 2013-11-05 19:41:32 +0000 | [diff] [blame] | 369 | |
| 370 | finish_test |