OLD | NEW |
1 # 2010 September 18 | 1 # 2010 September 18 |
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 # The majority of this file implements tests to verify that the "testable | 12 # The majority of this file implements tests to verify that the "testable |
13 # statements" in the lang_insert.html document are correct. | 13 # statements" in the lang_insert.html document are correct. |
14 # | 14 # |
15 # Also, it contains tests to verify the statements in (the very short) | 15 # Also, it contains tests to verify the statements in (the very short) |
16 # lang_replace.html. | 16 # lang_replace.html. |
17 # | 17 # |
18 set testdir [file dirname $argv0] | 18 set testdir [file dirname $argv0] |
19 source $testdir/tester.tcl | 19 source $testdir/tester.tcl |
20 | 20 |
| 21 ifcapable !compound { |
| 22 finish_test |
| 23 return |
| 24 } |
| 25 |
21 # Organization of tests: | 26 # Organization of tests: |
22 # | 27 # |
23 # e_insert-0.*: Test the syntax diagram. | 28 # e_insert-0.*: Test the syntax diagram. |
24 # | 29 # |
25 # e_insert-1.*: Test statements of the form "INSERT ... VALUES(...)". | 30 # e_insert-1.*: Test statements of the form "INSERT ... VALUES(...)". |
26 # | 31 # |
27 # e_insert-2.*: Test statements of the form "INSERT ... SELECT ...". | 32 # e_insert-2.*: Test statements of the form "INSERT ... SELECT ...". |
28 # | 33 # |
29 # e_insert-3.*: Test statements of the form "INSERT ... DEFAULT VALUES". | 34 # e_insert-3.*: Test statements of the form "INSERT ... DEFAULT VALUES". |
30 # | 35 # |
31 # e_insert-4.*: Test statements regarding the conflict clause. | 36 # e_insert-4.*: Test statements regarding the conflict clause. |
32 # | 37 # |
33 # e_insert-5.*: Test that the qualified table name and "DEFAULT VALUES" | 38 # e_insert-5.*: Test that the qualified table name and "DEFAULT VALUES" |
34 # syntaxes do not work in trigger bodies. | 39 # syntaxes do not work in trigger bodies. |
35 # | 40 # |
36 | 41 |
37 do_execsql_test e_insert-0.0 { | 42 do_execsql_test e_insert-0.0 { |
38 CREATE TABLE a1(a, b); | 43 CREATE TABLE a1(a, b); |
39 CREATE TABLE a2(a, b, c DEFAULT 'xyz'); | 44 CREATE TABLE a2(a, b, c DEFAULT 'xyz'); |
40 CREATE TABLE a3(x DEFAULT 1.0, y DEFAULT 'string', z); | 45 CREATE TABLE a3(x DEFAULT 1.0, y DEFAULT 'string', z); |
41 CREATE TABLE a4(c UNIQUE, d); | 46 CREATE TABLE a4(c UNIQUE, d); |
42 } {} | 47 } {} |
43 | 48 |
44 proc do_insert_tests {args} { | 49 proc do_insert_tests {args} { |
45 uplevel do_select_tests $args | 50 uplevel do_select_tests $args |
46 } | 51 } |
47 | 52 |
48 # EVIDENCE-OF: R-41448-54465 -- syntax diagram insert-stmt | 53 # -- syntax diagram insert-stmt |
49 # | 54 # |
50 do_insert_tests e_insert-0 { | 55 do_insert_tests e_insert-0 { |
51 1 "INSERT INTO a1 DEFAULT VALUES" {} | 56 1 "INSERT INTO a1 DEFAULT VALUES" {} |
52 2 "INSERT INTO main.a1 DEFAULT VALUES" {} | 57 2 "INSERT INTO main.a1 DEFAULT VALUES" {} |
53 3 "INSERT OR ROLLBACK INTO main.a1 DEFAULT VALUES" {} | 58 3 "INSERT OR ROLLBACK INTO main.a1 DEFAULT VALUES" {} |
54 4 "INSERT OR ROLLBACK INTO a1 DEFAULT VALUES" {} | 59 4 "INSERT OR ROLLBACK INTO a1 DEFAULT VALUES" {} |
55 5 "INSERT OR ABORT INTO main.a1 DEFAULT VALUES" {} | 60 5 "INSERT OR ABORT INTO main.a1 DEFAULT VALUES" {} |
56 6 "INSERT OR ABORT INTO a1 DEFAULT VALUES" {} | 61 6 "INSERT OR ABORT INTO a1 DEFAULT VALUES" {} |
57 7 "INSERT OR REPLACE INTO main.a1 DEFAULT VALUES" {} | 62 7 "INSERT OR REPLACE INTO main.a1 DEFAULT VALUES" {} |
58 8 "INSERT OR REPLACE INTO a1 DEFAULT VALUES" {} | 63 8 "INSERT OR REPLACE INTO a1 DEFAULT VALUES" {} |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 61 "INSERT OR ABORT INTO main.a1 (b, a) SELECT c, b FROM a2" {} | 116 61 "INSERT OR ABORT INTO main.a1 (b, a) SELECT c, b FROM a2" {} |
112 62 "INSERT OR ABORT INTO a1 (b, a) SELECT c, b FROM a2" {} | 117 62 "INSERT OR ABORT INTO a1 (b, a) SELECT c, b FROM a2" {} |
113 63 "INSERT OR REPLACE INTO main.a1 (b, a) SELECT c, b FROM a2" {} | 118 63 "INSERT OR REPLACE INTO main.a1 (b, a) SELECT c, b FROM a2" {} |
114 64 "INSERT OR REPLACE INTO a1 (b, a) SELECT c, b FROM a2" {} | 119 64 "INSERT OR REPLACE INTO a1 (b, a) SELECT c, b FROM a2" {} |
115 65 "INSERT OR FAIL INTO main.a1 (b, a) SELECT c, b FROM a2" {} | 120 65 "INSERT OR FAIL INTO main.a1 (b, a) SELECT c, b FROM a2" {} |
116 66 "INSERT OR FAIL INTO a1 (b, a) SELECT c, b FROM a2" {} | 121 66 "INSERT OR FAIL INTO a1 (b, a) SELECT c, b FROM a2" {} |
117 67 "INSERT OR FAIL INTO main.a1 (b, a) SELECT c, b FROM a2" {} | 122 67 "INSERT OR FAIL INTO main.a1 (b, a) SELECT c, b FROM a2" {} |
118 68 "INSERT OR IGNORE INTO a1 (b, a) SELECT c, b FROM a2" {} | 123 68 "INSERT OR IGNORE INTO a1 (b, a) SELECT c, b FROM a2" {} |
119 69 "REPLACE INTO a1 (b, a) SELECT c, b FROM a2" {} | 124 69 "REPLACE INTO a1 (b, a) SELECT c, b FROM a2" {} |
120 70 "REPLACE INTO main.a1 (b, a) SELECT c, b FROM a2" {} | 125 70 "REPLACE INTO main.a1 (b, a) SELECT c, b FROM a2" {} |
| 126 71 "INSERT INTO a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 127 72 "INSERT INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 128 73 "INSERT OR ROLLBACK INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 129 74 "INSERT OR ROLLBACK INTO a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 130 75 "INSERT OR ABORT INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 131 76 "INSERT OR ABORT INTO a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 132 77 "INSERT OR REPLACE INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 133 78 "INSERT OR REPLACE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 134 79 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 135 80 "INSERT OR FAIL INTO a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 136 81 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 137 82 "INSERT OR IGNORE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 138 83 "REPLACE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} |
| 139 84 "REPLACE INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} |
121 } | 140 } |
122 | 141 |
123 delete_all_data | 142 delete_all_data |
124 | 143 |
125 # EVIDENCE-OF: R-20288-20462 The first form (with the "VALUES" keyword) | 144 # EVIDENCE-OF: R-21490-41092 The first form (with the "VALUES" keyword) |
126 # creates a single new row in an existing table. | 145 # creates one or more new rows in an existing table. |
127 # | 146 # |
128 do_insert_tests e_insert-1.1 { | 147 do_insert_tests e_insert-1.1 { |
129 0 "SELECT count(*) FROM a2" {0} | 148 0 "SELECT count(*) FROM a2" {0} |
130 | 149 |
131 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} | 150 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} |
132 1b "SELECT count(*) FROM a2" {1} | 151 1b "SELECT count(*) FROM a2" {1} |
133 | 152 |
134 2a "INSERT INTO a2(a, b) VALUES(1, 2)" {} | 153 2a "INSERT INTO a2(a, b) VALUES(1, 2)" {} |
135 2b "SELECT count(*) FROM a2" {2} | 154 2b "SELECT count(*) FROM a2" {2} |
| 155 |
| 156 3a "INSERT INTO a2(a) VALUES(3),(4)" {} |
| 157 3b "SELECT count(*) FROM a2" {4} |
136 } | 158 } |
137 | 159 |
138 # EVIDENCE-OF: R-36040-20870 If no column-list is specified then the | 160 # EVIDENCE-OF: R-53616-44976 If no column-list is specified then the |
139 # number of values must be the same as the number of columns in the | 161 # number of values inserted into each row must be the same as the number |
140 # table. | 162 # of columns in the table. |
141 # | 163 # |
142 # A test in the block above verifies that if the VALUES list has the | 164 # A test in the block above verifies that if the VALUES list has the |
143 # correct number of columns (for table a2, 3 columns) works. So these | 165 # correct number of columns (for table a2, 3 columns) works. So these |
144 # tests just show that other values cause an error. | 166 # tests just show that other values cause an error. |
145 # | 167 # |
146 do_insert_tests e_insert-1.2 -error { | 168 do_insert_tests e_insert-1.2 -error { |
147 table %s has %d columns but %d values were supplied | 169 table %s has %d columns but %d values were supplied |
148 } { | 170 } { |
149 1 "INSERT INTO a2 VALUES(1)" {a2 3 1} | 171 1 "INSERT INTO a2 VALUES(1)" {a2 3 1} |
150 2 "INSERT INTO a2 VALUES(1,2)" {a2 3 2} | 172 2 "INSERT INTO a2 VALUES(1,2)" {a2 3 2} |
151 3 "INSERT INTO a2 VALUES(1,2,3,4)" {a2 3 4} | 173 3 "INSERT INTO a2 VALUES(1,2,3,4)" {a2 3 4} |
152 4 "INSERT INTO a2 VALUES(1,2,3,4,5)" {a2 3 5} | 174 4 "INSERT INTO a2 VALUES(1,2,3,4,5)" {a2 3 5} |
153 } | 175 } |
154 | 176 |
155 # EVIDENCE-OF: R-52422-65517 In this case the result of evaluting the | 177 # EVIDENCE-OF: R-29730-42609 In this case the result of evaluating the |
156 # left-most expression in the VALUES list is inserted into the left-most | 178 # left-most expression from each term of the VALUES list is inserted |
157 # column of the new row, and so on. | 179 # into the left-most column of each new row, and so forth for each |
| 180 # subsequent expression. |
158 # | 181 # |
159 delete_all_data | 182 delete_all_data |
160 do_insert_tests e_insert-1.3 { | 183 do_insert_tests e_insert-1.3 { |
161 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} | 184 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} |
162 1b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {1 2 3} | 185 1b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {1 2 3} |
163 | 186 |
164 2a "INSERT INTO a2 VALUES('abc', NULL, 3*3+1)" {} | 187 2a "INSERT INTO a2 VALUES('abc', NULL, 3*3+1)" {} |
165 2b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {abc {} 10} | 188 2b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {abc {} 10} |
166 | 189 |
167 3a "INSERT INTO a2 VALUES((SELECT count(*) FROM a2), 'x', 'y')" {} | 190 3a "INSERT INTO a2 VALUES((SELECT count(*) FROM a2), 'x', 'y')" {} |
168 3b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {2 x y} | 191 3b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {2 x y} |
169 } | 192 } |
170 | 193 |
171 # EVIDENCE-OF: R-62524-00361 If a column-list is specified, then the | 194 # EVIDENCE-OF: R-09234-17933 If a column-list is specified, then the |
172 # number of values must match the number of specified columns. | 195 # number of values in each term of the VALUE list must match the number |
| 196 # of specified columns. |
173 # | 197 # |
174 do_insert_tests e_insert-1.4 -error { | 198 do_insert_tests e_insert-1.4 -error { |
175 %d values for %d columns | 199 %d values for %d columns |
176 } { | 200 } { |
177 1 "INSERT INTO a2(a, b, c) VALUES(1)" {1 3} | 201 1 "INSERT INTO a2(a, b, c) VALUES(1)" {1 3} |
178 2 "INSERT INTO a2(a, b, c) VALUES(1,2)" {2 3} | 202 2 "INSERT INTO a2(a, b, c) VALUES(1,2)" {2 3} |
179 3 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4)" {4 3} | 203 3 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4)" {4 3} |
180 4 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4,5)" {5 3} | 204 4 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4,5)" {5 3} |
181 | 205 |
182 5 "INSERT INTO a2(c, a) VALUES(1)" {1 2} | 206 5 "INSERT INTO a2(c, a) VALUES(1)" {1 2} |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 # This is a dup of R-23110-47146. Therefore it is also verified | 364 # This is a dup of R-23110-47146. Therefore it is also verified |
341 # by e_select-4.2.*. This requirement is the only one from | 365 # by e_select-4.2.*. This requirement is the only one from |
342 # lang_replace.html. | 366 # lang_replace.html. |
343 # | 367 # |
344 do_execsql_test e_insert-4.1.0 { | 368 do_execsql_test e_insert-4.1.0 { |
345 INSERT INTO a4 VALUES(1, 'a'); | 369 INSERT INTO a4 VALUES(1, 'a'); |
346 INSERT INTO a4 VALUES(2, 'a'); | 370 INSERT INTO a4 VALUES(2, 'a'); |
347 INSERT INTO a4 VALUES(3, 'a'); | 371 INSERT INTO a4 VALUES(3, 'a'); |
348 } {} | 372 } {} |
349 foreach {tn sql error ac data } { | 373 foreach {tn sql error ac data } { |
350 1.1 "INSERT INTO a4 VALUES(2,'b')" {column c is not unique} 1 {1 a 2 a 3 a} | 374 1.1 "INSERT INTO a4 VALUES(2,'b')" {UNIQUE constraint failed: a4.c} 1 {1 a
2 a 3 a} |
351 1.2 "INSERT OR REPLACE INTO a4 VALUES(2, 'b')" {} 1 {1 a 3 a 2 b} | 375 1.2 "INSERT OR REPLACE INTO a4 VALUES(2, 'b')" {} 1 {1 a 3 a 2 b} |
352 1.3 "INSERT OR IGNORE INTO a4 VALUES(3, 'c')" {} 1 {1 a 3 a 2 b} | 376 1.3 "INSERT OR IGNORE INTO a4 VALUES(3, 'c')" {} 1 {1 a 3 a 2 b} |
353 1.4 "BEGIN" {} 0 {1 a 3 a 2 b} | 377 1.4 "BEGIN" {} 0 {1 a 3 a 2 b} |
354 1.5 "INSERT INTO a4 VALUES(1, 'd')" {column c is not unique} 0 {1 a 3 a 2 b} | 378 1.5 "INSERT INTO a4 VALUES(1, 'd')" {UNIQUE constraint failed: a4.c} 0 {1 a
3 a 2 b} |
355 1.6 "INSERT OR ABORT INTO a4 VALUES(1, 'd')" | 379 1.6 "INSERT OR ABORT INTO a4 VALUES(1, 'd')" |
356 {column c is not unique} 0 {1 a 3 a 2 b} | 380 {UNIQUE constraint failed: a4.c} 0 {1 a 3 a 2 b} |
357 1.7 "INSERT OR ROLLBACK INTO a4 VALUES(1, 'd')" | 381 1.7 "INSERT OR ROLLBACK INTO a4 VALUES(1, 'd')" |
358 {column c is not unique} 1 {1 a 3 a 2 b} | 382 {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b} |
359 1.8 "INSERT INTO a4 SELECT 4, 'e' UNION ALL SELECT 3, 'e'" | 383 1.8 "INSERT INTO a4 SELECT 4, 'e' UNION ALL SELECT 3, 'e'" |
360 {column c is not unique} 1 {1 a 3 a 2 b} | 384 {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b} |
361 1.9 "INSERT OR FAIL INTO a4 SELECT 4, 'e' UNION ALL SELECT 3, 'e'" | 385 1.9 "INSERT OR FAIL INTO a4 SELECT 4, 'e' UNION ALL SELECT 3, 'e'" |
362 {column c is not unique} 1 {1 a 3 a 2 b 4 e} | 386 {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b 4 e} |
363 | 387 |
364 2.1 "INSERT INTO a4 VALUES(2,'f')" | 388 2.1 "INSERT INTO a4 VALUES(2,'f')" |
365 {column c is not unique} 1 {1 a 3 a 2 b 4 e} | 389 {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b 4 e} |
366 2.2 "REPLACE INTO a4 VALUES(2, 'f')" {} 1 {1 a 3 a 4 e 2 f} | 390 2.2 "REPLACE INTO a4 VALUES(2, 'f')" {} 1 {1 a 3 a 4 e 2 f} |
367 } { | 391 } { |
368 do_catchsql_test e_insert-4.1.$tn.1 $sql [list [expr {$error!=""}] $error] | 392 do_catchsql_test e_insert-4.1.$tn.1 $sql [list [expr {$error!=""}] $error] |
369 do_execsql_test e_insert-4.1.$tn.2 {SELECT * FROM a4} [list {*}$data] | 393 do_execsql_test e_insert-4.1.$tn.2 {SELECT * FROM a4} [list {*}$data] |
370 do_test e_insert-4.1.$tn.3 {sqlite3_get_autocommit db} $ac | 394 do_test e_insert-4.1.$tn.3 {sqlite3_get_autocommit db} $ac |
371 } | 395 } |
372 | 396 |
373 # EVIDENCE-OF: R-64196-02418 The optional "database-name." prefix on the | 397 # EVIDENCE-OF: R-64196-02418 The optional "database-name." prefix on the |
374 # table-name is support for top-level INSERT statements only. | 398 # table-name is support for top-level INSERT statements only. |
375 # | 399 # |
(...skipping 21 matching lines...) Expand all Loading... |
397 do_catchsql_test e_insert-5.2.1 { | 421 do_catchsql_test e_insert-5.2.1 { |
398 CREATE TRIGGER AFTER UPDATE ON a1 BEGIN | 422 CREATE TRIGGER AFTER UPDATE ON a1 BEGIN |
399 INSERT INTO a4 DEFAULT VALUES; | 423 INSERT INTO a4 DEFAULT VALUES; |
400 END; | 424 END; |
401 } {1 {near "DEFAULT": syntax error}} | 425 } {1 {near "DEFAULT": syntax error}} |
402 | 426 |
403 | 427 |
404 delete_all_data | 428 delete_all_data |
405 | 429 |
406 finish_test | 430 finish_test |
OLD | NEW |