| OLD | NEW |
| 1 # 2010 September 20 | 1 # 2010 September 20 |
| 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 #*********************************************************************** |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 CREATE TEMP TABLE t6(x, y); | 42 CREATE TEMP TABLE t6(x, y); |
| 43 | 43 |
| 44 CREATE TABLE aux.t1(a, b); | 44 CREATE TABLE aux.t1(a, b); |
| 45 CREATE TABLE aux.t5(a, b); | 45 CREATE TABLE aux.t5(a, b); |
| 46 } {} | 46 } {} |
| 47 | 47 |
| 48 proc do_update_tests {args} { | 48 proc do_update_tests {args} { |
| 49 uplevel do_select_tests $args | 49 uplevel do_select_tests $args |
| 50 } | 50 } |
| 51 | 51 |
| 52 # EVIDENCE-OF: R-05685-44205 -- syntax diagram update-stmt | 52 # -- syntax diagram update-stmt |
| 53 # | 53 # |
| 54 do_update_tests e_update-0 { | 54 do_update_tests e_update-0 { |
| 55 1 "UPDATE t1 SET a=10" {} | 55 1 "UPDATE t1 SET a=10" {} |
| 56 2 "UPDATE t1 SET a=10, b=5" {} | 56 2 "UPDATE t1 SET a=10, b=5" {} |
| 57 3 "UPDATE t1 SET a=10 WHERE b=5" {} | 57 3 "UPDATE t1 SET a=10 WHERE b=5" {} |
| 58 4 "UPDATE t1 SET b=5,a=10 WHERE 1" {} | 58 4 "UPDATE t1 SET b=5,a=10 WHERE 1" {} |
| 59 5 "UPDATE main.t1 SET a=10" {} | 59 5 "UPDATE main.t1 SET a=10" {} |
| 60 6 "UPDATE main.t1 SET a=10, b=5" {} | 60 6 "UPDATE main.t1 SET a=10, b=5" {} |
| 61 7 "UPDATE main.t1 SET a=10 WHERE b=5" {} | 61 7 "UPDATE main.t1 SET a=10 WHERE b=5" {} |
| 62 9 "UPDATE OR ROLLBACK t1 SET a=10" {} | 62 9 "UPDATE OR ROLLBACK t1 SET a=10" {} |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 5 "UPDATE t2 SET a = 3 WHERE c = 4" | 226 5 "UPDATE t2 SET a = 3 WHERE c = 4" |
| 227 {3 1 4 1 5 9 1 2 2} | 227 {3 1 4 1 5 9 1 2 2} |
| 228 | 228 |
| 229 6 "UPDATE t2 SET a = b WHERE rowid>2" | 229 6 "UPDATE t2 SET a = b WHERE rowid>2" |
| 230 {3 1 4 1 5 9 2 2 2} | 230 {3 1 4 1 5 9 2 2 2} |
| 231 | 231 |
| 232 6 "UPDATE t2 SET b=6, c=5 WHERE a=b AND b=c" | 232 6 "UPDATE t2 SET b=6, c=5 WHERE a=b AND b=c" |
| 233 {3 1 4 1 5 9 2 6 5} | 233 {3 1 4 1 5 9 2 6 5} |
| 234 } | 234 } |
| 235 | 235 |
| 236 # EVIDENCE-OF: R-09060-20018 If a single column-name appears more than | 236 # EVIDENCE-OF: R-34751-18293 If a single column-name appears more than |
| 237 # once in the list of assignment expressions, all but the rightmost | 237 # once in the list of assignment expressions, all but the rightmost |
| 238 # occurence is ignored. | 238 # occurrence is ignored. |
| 239 # | 239 # |
| 240 do_update_tests e_update-1.6 -query { | 240 do_update_tests e_update-1.6 -query { |
| 241 SELECT * FROM t2 | 241 SELECT * FROM t2 |
| 242 } { | 242 } { |
| 243 1 "UPDATE t2 SET c=5, c=6, c=7 WHERE rowid=1" {3 1 7 1 5 9 2 6 5} | 243 1 "UPDATE t2 SET c=5, c=6, c=7 WHERE rowid=1" {3 1 7 1 5 9 2 6 5} |
| 244 2 "UPDATE t2 SET c=7, c=6, c=5 WHERE rowid=1" {3 1 5 1 5 9 2 6 5} | 244 2 "UPDATE t2 SET c=7, c=6, c=5 WHERE rowid=1" {3 1 5 1 5 9 2 6 5} |
| 245 3 "UPDATE t2 SET c=5, b=6, c=7 WHERE rowid=1" {3 6 7 1 5 9 2 6 5} | 245 3 "UPDATE t2 SET c=5, b=6, c=7 WHERE rowid=1" {3 6 7 1 5 9 2 6 5} |
| 246 } | 246 } |
| 247 | 247 |
| 248 # EVIDENCE-OF: R-36239-04077 The scalar expressions may refer to columns | 248 # EVIDENCE-OF: R-36239-04077 The scalar expressions may refer to columns |
| (...skipping 22 matching lines...) Expand all Loading... |
| 271 # | 271 # |
| 272 do_execsql_test e_update-1.8.0 { | 272 do_execsql_test e_update-1.8.0 { |
| 273 DELETE FROM t3; | 273 DELETE FROM t3; |
| 274 INSERT INTO t3 VALUES(1, 'one'); | 274 INSERT INTO t3 VALUES(1, 'one'); |
| 275 INSERT INTO t3 VALUES(2, 'two'); | 275 INSERT INTO t3 VALUES(2, 'two'); |
| 276 INSERT INTO t3 VALUES(3, 'three'); | 276 INSERT INTO t3 VALUES(3, 'three'); |
| 277 INSERT INTO t3 VALUES(4, 'four'); | 277 INSERT INTO t3 VALUES(4, 'four'); |
| 278 } {} | 278 } {} |
| 279 foreach {tn sql error ac data } { | 279 foreach {tn sql error ac data } { |
| 280 1 "UPDATE t3 SET b='one' WHERE a=3" | 280 1 "UPDATE t3 SET b='one' WHERE a=3" |
| 281 {column b is not unique} 1 {1 one 2 two 3 three 4 four} | 281 {UNIQUE constraint failed: t3.b} 1 {1 one 2 two 3 three 4 four} |
| 282 | 282 |
| 283 2 "UPDATE OR REPLACE t3 SET b='one' WHERE a=3" | 283 2 "UPDATE OR REPLACE t3 SET b='one' WHERE a=3" |
| 284 {} 1 {2 two 3 one 4 four} | 284 {} 1 {2 two 3 one 4 four} |
| 285 | 285 |
| 286 3 "UPDATE OR FAIL t3 SET b='three'" | 286 3 "UPDATE OR FAIL t3 SET b='three'" |
| 287 {column b is not unique} 1 {2 three 3 one 4 four} | 287 {UNIQUE constraint failed: t3.b} 1 {2 three 3 one 4 four} |
| 288 | 288 |
| 289 4 "UPDATE OR IGNORE t3 SET b='three' WHERE a=3" | 289 4 "UPDATE OR IGNORE t3 SET b='three' WHERE a=3" |
| 290 {} 1 {2 three 3 one 4 four} | 290 {} 1 {2 three 3 one 4 four} |
| 291 | 291 |
| 292 5 "UPDATE OR ABORT t3 SET b='three' WHERE a=3" | 292 5 "UPDATE OR ABORT t3 SET b='three' WHERE a=3" |
| 293 {column b is not unique} 1 {2 three 3 one 4 four} | 293 {UNIQUE constraint failed: t3.b} 1 {2 three 3 one 4 four} |
| 294 | 294 |
| 295 6 "BEGIN" {} 0 {2 three 3 one 4 four} | 295 6 "BEGIN" {} 0 {2 three 3 one 4 four} |
| 296 | 296 |
| 297 7 "UPDATE t3 SET b='three' WHERE a=3" | 297 7 "UPDATE t3 SET b='three' WHERE a=3" |
| 298 {column b is not unique} 0 {2 three 3 one 4 four} | 298 {UNIQUE constraint failed: t3.b} 0 {2 three 3 one 4 four} |
| 299 | 299 |
| 300 8 "UPDATE OR ABORT t3 SET b='three' WHERE a=3" | 300 8 "UPDATE OR ABORT t3 SET b='three' WHERE a=3" |
| 301 {column b is not unique} 0 {2 three 3 one 4 four} | 301 {UNIQUE constraint failed: t3.b} 0 {2 three 3 one 4 four} |
| 302 | 302 |
| 303 9 "UPDATE OR FAIL t3 SET b='two'" | 303 9 "UPDATE OR FAIL t3 SET b='two'" |
| 304 {column b is not unique} 0 {2 two 3 one 4 four} | 304 {UNIQUE constraint failed: t3.b} 0 {2 two 3 one 4 four} |
| 305 | 305 |
| 306 10 "UPDATE OR IGNORE t3 SET b='four' WHERE a=3" | 306 10 "UPDATE OR IGNORE t3 SET b='four' WHERE a=3" |
| 307 {} 0 {2 two 3 one 4 four} | 307 {} 0 {2 two 3 one 4 four} |
| 308 | 308 |
| 309 11 "UPDATE OR REPLACE t3 SET b='four' WHERE a=3" | 309 11 "UPDATE OR REPLACE t3 SET b='four' WHERE a=3" |
| 310 {} 0 {2 two 3 four} | 310 {} 0 {2 two 3 four} |
| 311 | 311 |
| 312 12 "UPDATE OR ROLLBACK t3 SET b='four'" | 312 12 "UPDATE OR ROLLBACK t3 SET b='four'" |
| 313 {column b is not unique} 1 {2 three 3 one 4 four} | 313 {UNIQUE constraint failed: t3.b} 1 {2 three 3 one 4 four} |
| 314 } { | 314 } { |
| 315 do_catchsql_test e_update-1.8.$tn.1 $sql [list [expr {$error!=""}] $error] | 315 do_catchsql_test e_update-1.8.$tn.1 $sql [list [expr {$error!=""}] $error] |
| 316 do_execsql_test e_update-1.8.$tn.2 {SELECT * FROM t3} [list {*}$data] | 316 do_execsql_test e_update-1.8.$tn.2 {SELECT * FROM t3} [list {*}$data] |
| 317 do_test e_update-1.8.$tn.3 {sqlite3_get_autocommit db} $ac | 317 do_test e_update-1.8.$tn.3 {sqlite3_get_autocommit db} $ac |
| 318 } | 318 } |
| 319 | 319 |
| 320 | 320 |
| 321 | 321 |
| 322 # EVIDENCE-OF: R-12123-54095 The table-name specified as part of an | 322 # EVIDENCE-OF: R-12123-54095 The table-name specified as part of an |
| 323 # UPDATE statement within a trigger body must be unqualified. | 323 # UPDATE statement within a trigger body must be unqualified. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } {} | 374 } {} |
| 375 | 375 |
| 376 # EVIDENCE-OF: R-29512-54644 If the table to which the trigger is | 376 # EVIDENCE-OF: R-29512-54644 If the table to which the trigger is |
| 377 # attached is in the TEMP database, then the unqualified name of the | 377 # attached is in the TEMP database, then the unqualified name of the |
| 378 # table being updated is resolved in the same way as it is for a | 378 # table being updated is resolved in the same way as it is for a |
| 379 # top-level statement (by searching first the TEMP database, then the | 379 # top-level statement (by searching first the TEMP database, then the |
| 380 # main database, then any other databases in the order they were | 380 # main database, then any other databases in the order they were |
| 381 # attached). | 381 # attached). |
| 382 # | 382 # |
| 383 do_execsql_test e_update-2.3.0 { | 383 do_execsql_test e_update-2.3.0 { |
| 384 SELECT 'main', tbl_name FROM main.sqlite_master WHERE type = 'table' | 384 SELECT 'main', tbl_name FROM main.sqlite_master WHERE type = 'table'; |
| 385 UNION ALL | 385 SELECT 'temp', tbl_name FROM sqlite_temp_master WHERE type = 'table'; |
| 386 SELECT 'temp', tbl_name FROM sqlite_temp_master WHERE type = 'table' | 386 SELECT 'aux', tbl_name FROM aux.sqlite_master WHERE type = 'table'; |
| 387 UNION ALL | |
| 388 SELECT 'aux', tbl_name FROM aux.sqlite_master WHERE type = 'table' | |
| 389 } [list {*}{ | 387 } [list {*}{ |
| 390 main t1 | 388 main t1 |
| 391 main t2 | 389 main t2 |
| 392 main t3 | 390 main t3 |
| 393 main t6 | 391 main t6 |
| 394 temp t4 | 392 temp t4 |
| 395 temp t6 | 393 temp t6 |
| 396 aux t1 | 394 aux t1 |
| 397 aux t5 | 395 aux t5 |
| 398 }] | 396 }] |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 UPDATE t1 SET a=a+1 LIMIT 10 OFFSET 2; | 486 UPDATE t1 SET a=a+1 LIMIT 10 OFFSET 2; |
| 489 END; | 487 END; |
| 490 } {LIMIT} | 488 } {LIMIT} |
| 491 } | 489 } |
| 492 | 490 |
| 493 # EVIDENCE-OF: R-59581-44104 If SQLite is built with the | 491 # EVIDENCE-OF: R-59581-44104 If SQLite is built with the |
| 494 # SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option then the syntax | 492 # SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option then the syntax |
| 495 # of the UPDATE statement is extended with optional ORDER BY and LIMIT | 493 # of the UPDATE statement is extended with optional ORDER BY and LIMIT |
| 496 # clauses | 494 # clauses |
| 497 # | 495 # |
| 498 # EVIDENCE-OF: R-08948-01887 -- syntax diagram update-stmt-limited | 496 # -- syntax diagram update-stmt-limited |
| 499 # | 497 # |
| 500 do_update_tests e_update-3.0 { | 498 do_update_tests e_update-3.0 { |
| 501 1 "UPDATE t1 SET a=b LIMIT 5" {} | 499 1 "UPDATE t1 SET a=b LIMIT 5" {} |
| 502 2 "UPDATE t1 SET a=b LIMIT 5-1 OFFSET 2+2" {} | 500 2 "UPDATE t1 SET a=b LIMIT 5-1 OFFSET 2+2" {} |
| 503 3 "UPDATE t1 SET a=b LIMIT 2+2, 16/4" {} | 501 3 "UPDATE t1 SET a=b LIMIT 2+2, 16/4" {} |
| 504 4 "UPDATE t1 SET a=b ORDER BY a LIMIT 5" {} | 502 4 "UPDATE t1 SET a=b ORDER BY a LIMIT 5" {} |
| 505 5 "UPDATE t1 SET a=b ORDER BY a LIMIT 5-1 OFFSET 2+2" {} | 503 5 "UPDATE t1 SET a=b ORDER BY a LIMIT 5-1 OFFSET 2+2" {} |
| 506 6 "UPDATE t1 SET a=b ORDER BY a LIMIT 2+2, 16/4" {} | 504 6 "UPDATE t1 SET a=b ORDER BY a LIMIT 2+2, 16/4" {} |
| 507 7 "UPDATE t1 SET a=b WHERE a>2 LIMIT 5" {} | 505 7 "UPDATE t1 SET a=b WHERE a>2 LIMIT 5" {} |
| 508 8 "UPDATE t1 SET a=b WHERE a>2 LIMIT 5-1 OFFSET 2+2" {} | 506 8 "UPDATE t1 SET a=b WHERE a>2 LIMIT 5-1 OFFSET 2+2" {} |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 1 "UPDATE t7 SET s = q ORDER BY r LIMIT -1" {1 2 3 4 5 6 7 8 9 10} | 596 1 "UPDATE t7 SET s = q ORDER BY r LIMIT -1" {1 2 3 4 5 6 7 8 9 10} |
| 599 2 "UPDATE t7 SET s = q ORDER BY r ASC LIMIT -1" {1 2 3 4 5 6 7 8 9 10} | 597 2 "UPDATE t7 SET s = q ORDER BY r ASC LIMIT -1" {1 2 3 4 5 6 7 8 9 10} |
| 600 3 "UPDATE t7 SET s = q ORDER BY r DESC LIMIT -1" {1 2 3 4 5 6 7 8 9 10} | 598 3 "UPDATE t7 SET s = q ORDER BY r DESC LIMIT -1" {1 2 3 4 5 6 7 8 9 10} |
| 601 4 "UPDATE t7 SET s = q ORDER BY q DESC LIMIT 5" {6 7 8 9 10} | 599 4 "UPDATE t7 SET s = q ORDER BY q DESC LIMIT 5" {6 7 8 9 10} |
| 602 } | 600 } |
| 603 | 601 |
| 604 | 602 |
| 605 } ;# ifcapable update_delete_limit | 603 } ;# ifcapable update_delete_limit |
| 606 | 604 |
| 607 finish_test | 605 finish_test |
| 608 | |
| OLD | NEW |