| OLD | NEW |
| 1 # 2012 December 17 | 1 # 2012 December 17 |
| 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 tests the PRAGMA foreign_key_check command. | 13 # This file tests the PRAGMA foreign_key_check command. |
| 14 # | 14 # |
| 15 # EVIDENCE-OF: R-05426-18119 PRAGMA foreign_key_check; PRAGMA | 15 # EVIDENCE-OF: R-15402-03103 PRAGMA schema.foreign_key_check; PRAGMA |
| 16 # foreign_key_check(table-name); | 16 # schema.foreign_key_check(table-name); |
| 17 # |
| 18 # EVIDENCE-OF: R-23918-17301 The foreign_key_check pragma checks the |
| 19 # database, or the table called "table-name", for foreign key |
| 20 # constraints that are violated and returns one row of output for each |
| 21 # violation. |
| 17 | 22 |
| 18 set testdir [file dirname $argv0] | 23 set testdir [file dirname $argv0] |
| 19 source $testdir/tester.tcl | 24 source $testdir/tester.tcl |
| 20 set testprefix fkey5 | 25 set testprefix fkey5 |
| 21 | 26 |
| 22 ifcapable {!foreignkey} { | 27 ifcapable {!foreignkey} { |
| 23 finish_test | 28 finish_test |
| 24 return | 29 return |
| 25 } | 30 } |
| 26 | 31 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 72 |
| 68 PRAGMA foreign_key_check; | 73 PRAGMA foreign_key_check; |
| 69 } | 74 } |
| 70 } {} | 75 } {} |
| 71 do_test fkey5-1.2 { | 76 do_test fkey5-1.2 { |
| 72 db eval { | 77 db eval { |
| 73 INSERT INTO c1 VALUES(90),(87),(88); | 78 INSERT INTO c1 VALUES(90),(87),(88); |
| 74 PRAGMA foreign_key_check; | 79 PRAGMA foreign_key_check; |
| 75 } | 80 } |
| 76 } {c1 87 p1 0 c1 90 p1 0} | 81 } {c1 87 p1 0 c1 90 p1 0} |
| 82 do_test fkey5-1.2b { |
| 83 db eval { |
| 84 PRAGMA main.foreign_key_check; |
| 85 } |
| 86 } {c1 87 p1 0 c1 90 p1 0} |
| 87 do_test fkey5-1.2c { |
| 88 db eval { |
| 89 PRAGMA temp.foreign_key_check; |
| 90 } |
| 91 } {} |
| 77 do_test fkey5-1.3 { | 92 do_test fkey5-1.3 { |
| 78 db eval { | 93 db eval { |
| 79 PRAGMA foreign_key_check(c1); | 94 PRAGMA foreign_key_check(c1); |
| 80 } | 95 } |
| 81 } {c1 87 p1 0 c1 90 p1 0} | 96 } {c1 87 p1 0 c1 90 p1 0} |
| 82 do_test fkey5-1.4 { | 97 do_test fkey5-1.4 { |
| 83 db eval { | 98 db eval { |
| 84 PRAGMA foreign_key_check(c2); | 99 PRAGMA foreign_key_check(c2); |
| 85 } | 100 } |
| 86 } {} | 101 } {} |
| 102 do_test fkey5-1.5 { |
| 103 db eval { |
| 104 PRAGMA main.foreign_key_check(c2); |
| 105 } |
| 106 } {} |
| 107 do_test fkey5-1.6 { |
| 108 catchsql { |
| 109 PRAGMA temp.foreign_key_check(c2); |
| 110 } |
| 111 } {1 {no such table: temp.c2}} |
| 87 | 112 |
| 88 # EVIDENCE-OF: R-45728-08709 There are four columns in each result row. | 113 # EVIDENCE-OF: R-45728-08709 There are four columns in each result row. |
| 89 # | 114 # |
| 90 # EVIDENCE-OF: R-55672-01620 The first column is the name of the table | 115 # EVIDENCE-OF: R-55672-01620 The first column is the name of the table |
| 91 # that contains the REFERENCES clause. | 116 # that contains the REFERENCES clause. |
| 92 # | 117 # |
| 93 # EVIDENCE-OF: R-25219-25618 The second column is the rowid of the row | 118 # EVIDENCE-OF: R-25219-25618 The second column is the rowid of the row |
| 94 # that contains the invalid REFERENCES clause. | 119 # that contains the invalid REFERENCES clause. |
| 95 # | 120 # |
| 96 # EVIDENCE-OF: R-40482-20265 The third column is the name of the table | 121 # EVIDENCE-OF: R-40482-20265 The third column is the name of the table |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 PRAGMA foreign_key_check; | 270 PRAGMA foreign_key_check; |
| 246 } | 271 } |
| 247 } {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0} | 272 } {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0} |
| 248 do_test fkey5-6.5 { | 273 do_test fkey5-6.5 { |
| 249 db eval { | 274 db eval { |
| 250 PRAGMA foreign_key_check(c12); | 275 PRAGMA foreign_key_check(c12); |
| 251 } | 276 } |
| 252 } {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0} | 277 } {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0} |
| 253 | 278 |
| 254 do_test fkey5-7.1 { | 279 do_test fkey5-7.1 { |
| 280 set res {} |
| 255 db eval { | 281 db eval { |
| 256 INSERT OR IGNORE INTO c13 SELECT * FROM c12; | 282 INSERT OR IGNORE INTO c13 SELECT * FROM c12; |
| 257 INSERT OR IGNORE INTO C14 SELECT * FROM c12; | 283 INSERT OR IGNORE INTO C14 SELECT * FROM c12; |
| 258 DELETE FROM c12; | 284 DELETE FROM c12; |
| 259 PRAGMA foreign_key_check; | 285 PRAGMA foreign_key_check; |
| 286 } { |
| 287 lappend res [list $table $rowid $fkid $parent] |
| 260 } | 288 } |
| 261 } {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0 c13 1 p3 0 c13 2 p3 0 c13 3 p3 0 c13 4 p3 0
c13 5 p3 0 c13 6 p3 0} | 289 lsort $res |
| 290 } {{c13 1 0 p3} {c13 2 0 p3} {c13 3 0 p3} {c13 4 0 p3} {c13 5 0 p3} {c13 6 0 p3}
{c14 1 0 p4} {c14 3 0 p4} {c14 6 0 p4}} |
| 262 do_test fkey5-7.2 { | 291 do_test fkey5-7.2 { |
| 263 db eval { | 292 db eval { |
| 264 PRAGMA foreign_key_check(c14); | 293 PRAGMA foreign_key_check(c14); |
| 265 } | 294 } |
| 266 } {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0} | 295 } {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0} |
| 267 do_test fkey5-7.3 { | 296 do_test fkey5-7.3 { |
| 268 db eval { | 297 db eval { |
| 269 PRAGMA foreign_key_check(c13); | 298 PRAGMA foreign_key_check(c13); |
| 270 } | 299 } |
| 271 } {c13 1 p3 0 c13 2 p3 0 c13 3 p3 0 c13 4 p3 0 c13 5 p3 0 c13 6 p3 0} | 300 } {c13 1 p3 0 c13 2 p3 0 c13 3 p3 0 c13 4 p3 0 c13 5 p3 0 c13 6 p3 0} |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 INSERT INTO k2 VALUES('one', NULL); | 383 INSERT INTO k2 VALUES('one', NULL); |
| 355 PRAGMA foreign_key_check(k2); | 384 PRAGMA foreign_key_check(k2); |
| 356 } {} | 385 } {} |
| 357 do_execsql_test 9.4 { | 386 do_execsql_test 9.4 { |
| 358 INSERT INTO k2 VALUES('six', 'seven'); | 387 INSERT INTO k2 VALUES('six', 'seven'); |
| 359 PRAGMA foreign_key_check(k2); | 388 PRAGMA foreign_key_check(k2); |
| 360 } {k2 3 s1 0} | 389 } {k2 3 s1 0} |
| 361 | 390 |
| 362 | 391 |
| 363 finish_test | 392 finish_test |
| OLD | NEW |