OLD | NEW |
1 # 2010 September 21 | 1 # 2010 September 21 |
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 # | 11 # |
12 # This file implements tests to verify that the "testable statements" in | 12 # This file implements tests to verify that the "testable statements" in |
13 # the lang_delete.html document are correct. | 13 # the lang_delete.html document are correct. |
14 # | 14 # |
15 set testdir [file dirname $argv0] | 15 set testdir [file dirname $argv0] |
16 source $testdir/tester.tcl | 16 source $testdir/tester.tcl |
17 | 17 |
| 18 ifcapable !compound { |
| 19 finish_test |
| 20 return |
| 21 } |
| 22 |
18 proc do_delete_tests {args} { | 23 proc do_delete_tests {args} { |
19 uplevel do_select_tests $args | 24 uplevel do_select_tests $args |
20 } | 25 } |
21 | 26 |
22 do_execsql_test e_delete-0.0 { | 27 do_execsql_test e_delete-0.0 { |
23 CREATE TABLE t1(a, b); | 28 CREATE TABLE t1(a, b); |
24 CREATE INDEX i1 ON t1(a); | 29 CREATE INDEX i1 ON t1(a); |
25 } {} | 30 } {} |
26 | 31 |
27 # EVIDENCE-OF: R-24177-52883 -- syntax diagram delete-stmt | 32 # -- syntax diagram delete-stmt |
28 # | 33 # -- syntax diagram qualified-table-name |
29 # EVIDENCE-OF: R-12802-60464 -- syntax diagram qualified-table-name | |
30 # | 34 # |
31 do_delete_tests e_delete-0.1 { | 35 do_delete_tests e_delete-0.1 { |
32 1 "DELETE FROM t1" {} | 36 1 "DELETE FROM t1" {} |
33 2 "DELETE FROM t1 INDEXED BY i1" {} | 37 2 "DELETE FROM t1 INDEXED BY i1" {} |
34 3 "DELETE FROM t1 NOT INDEXED" {} | 38 3 "DELETE FROM t1 NOT INDEXED" {} |
35 4 "DELETE FROM main.t1" {} | 39 4 "DELETE FROM main.t1" {} |
36 5 "DELETE FROM main.t1 INDEXED BY i1" {} | 40 5 "DELETE FROM main.t1 INDEXED BY i1" {} |
37 6 "DELETE FROM main.t1 NOT INDEXED" {} | 41 6 "DELETE FROM main.t1 NOT INDEXED" {} |
38 7 "DELETE FROM t1 WHERE a>2" {} | 42 7 "DELETE FROM t1 WHERE a>2" {} |
39 8 "DELETE FROM t1 INDEXED BY i1 WHERE a>2" {} | 43 8 "DELETE FROM t1 INDEXED BY i1 WHERE a>2" {} |
(...skipping 240 matching lines...) Loading... |
280 DELETE FROM t8 ORDER BY a LIMIT 5; | 284 DELETE FROM t8 ORDER BY a LIMIT 5; |
281 END; | 285 END; |
282 } {ORDER} | 286 } {ORDER} |
283 } | 287 } |
284 | 288 |
285 # EVIDENCE-OF: R-40026-10531 If SQLite is compiled with the | 289 # EVIDENCE-OF: R-40026-10531 If SQLite is compiled with the |
286 # SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option, then the syntax | 290 # SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option, then the syntax |
287 # of the DELETE statement is extended by the addition of optional ORDER | 291 # of the DELETE statement is extended by the addition of optional ORDER |
288 # BY and LIMIT clauses: | 292 # BY and LIMIT clauses: |
289 # | 293 # |
290 # EVIDENCE-OF: R-45897-01670 -- syntax diagram delete-stmt-limited | 294 # -- syntax diagram delete-stmt-limited |
291 # | 295 # |
292 do_delete_tests e_delete-3.1 { | 296 do_delete_tests e_delete-3.1 { |
293 1 "DELETE FROM t1 LIMIT 5" {} | 297 1 "DELETE FROM t1 LIMIT 5" {} |
294 2 "DELETE FROM t1 LIMIT 5-1 OFFSET 2+2" {} | 298 2 "DELETE FROM t1 LIMIT 5-1 OFFSET 2+2" {} |
295 3 "DELETE FROM t1 LIMIT 2+2, 16/4" {} | 299 3 "DELETE FROM t1 LIMIT 2+2, 16/4" {} |
296 4 "DELETE FROM t1 ORDER BY x LIMIT 5" {} | 300 4 "DELETE FROM t1 ORDER BY x LIMIT 5" {} |
297 5 "DELETE FROM t1 ORDER BY x LIMIT 5-1 OFFSET 2+2" {} | 301 5 "DELETE FROM t1 ORDER BY x LIMIT 5-1 OFFSET 2+2" {} |
298 6 "DELETE FROM t1 ORDER BY x LIMIT 2+2, 16/4" {} | 302 6 "DELETE FROM t1 ORDER BY x LIMIT 2+2, 16/4" {} |
299 7 "DELETE FROM t1 WHERE x>2 LIMIT 5" {} | 303 7 "DELETE FROM t1 WHERE x>2 LIMIT 5" {} |
300 8 "DELETE FROM t1 WHERE x>2 LIMIT 5-1 OFFSET 2+2" {} | 304 8 "DELETE FROM t1 WHERE x>2 LIMIT 5-1 OFFSET 2+2" {} |
(...skipping 132 matching lines...) Loading... |
433 SELECT a FROM t1 | 437 SELECT a FROM t1 |
434 } { | 438 } { |
435 1 "DELETE FROM t1 LIMIT 2" {3 4 5} | 439 1 "DELETE FROM t1 LIMIT 2" {3 4 5} |
436 2 "DELETE FROM t1 LIMIT 3" {4 5} | 440 2 "DELETE FROM t1 LIMIT 3" {4 5} |
437 3 "DELETE FROM t1 LIMIT 1 OFFSET 0" {2 3 4 5} | 441 3 "DELETE FROM t1 LIMIT 1 OFFSET 0" {2 3 4 5} |
438 4 "DELETE FROM t1 LIMIT 1 OFFSET 1" {1 3 4 5} | 442 4 "DELETE FROM t1 LIMIT 1 OFFSET 1" {1 3 4 5} |
439 5 "DELETE FROM t1 LIMIT 1 OFFSET 2" {1 2 4 5} | 443 5 "DELETE FROM t1 LIMIT 1 OFFSET 2" {1 2 4 5} |
440 } | 444 } |
441 | 445 |
442 | 446 |
443 # EVIDENCE-OF: R-26627-30313 The ORDER BY clause on an DELETE statement | 447 # EVIDENCE-OF: R-07548-13422 The ORDER BY clause on a DELETE statement |
444 # is used only to determine which rows fall within the LIMIT. The order | 448 # is used only to determine which rows fall within the LIMIT. The order |
445 # in which rows are deleted is arbitrary and is not influenced by the | 449 # in which rows are deleted is arbitrary and is not influenced by the |
446 # ORDER BY clause. | 450 # ORDER BY clause. |
447 # | 451 # |
448 # In practice, rows are always deleted in rowid order. | 452 # In practice, rows are always deleted in rowid order. |
449 # | 453 # |
450 do_delete_tests e_delete-3.10 -repair { | 454 do_delete_tests e_delete-3.10 -repair { |
451 rebuild_t1 | 455 rebuild_t1 |
452 catchsql { DROP TABLE t1log } | 456 catchsql { DROP TABLE t1log } |
453 execsql { | 457 execsql { |
454 CREATE TABLE t1log(x); | 458 CREATE TABLE t1log(x); |
455 CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN | 459 CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN |
456 INSERT INTO t1log VALUES(old.a); | 460 INSERT INTO t1log VALUES(old.a); |
457 END; | 461 END; |
458 } | 462 } |
459 } -query { | 463 } -query { |
460 SELECT x FROM t1log | 464 SELECT x FROM t1log |
461 } { | 465 } { |
462 1 "DELETE FROM t1 ORDER BY a DESC LIMIT 2" {4 5} | 466 1 "DELETE FROM t1 ORDER BY a DESC LIMIT 2" {4 5} |
463 2 "DELETE FROM t1 ORDER BY a DESC LIMIT -1" {1 2 3 4 5} | 467 2 "DELETE FROM t1 ORDER BY a DESC LIMIT -1" {1 2 3 4 5} |
464 3 "DELETE FROM t1 ORDER BY a ASC LIMIT 2" {1 2} | 468 3 "DELETE FROM t1 ORDER BY a ASC LIMIT 2" {1 2} |
465 4 "DELETE FROM t1 ORDER BY a ASC LIMIT -1" {1 2 3 4 5} | 469 4 "DELETE FROM t1 ORDER BY a ASC LIMIT -1" {1 2 3 4 5} |
466 } | 470 } |
467 | 471 |
468 } | 472 } |
469 | 473 |
470 finish_test | 474 finish_test |
OLD | NEW |