3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # The focus of this file is vector assignments in the SET clause of
12 # an UPDATE statement.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set ::testprefix rowvalue7
20 CREATE TABLE t1(a,b,c,d);
21 CREATE INDEX t1x ON t1(a,b);
22 INSERT INTO t1(a,b,c,d) VALUES(1,2,0,0),(3,4,0,0),(5,6,0,0);
23 CREATE TABLE t2(w,x,y,z);
24 CREATE INDEX t2x ON t2(w,x);
25 INSERT INTO t2(w,x,y,z) VALUES(1,2,11,22),(8,9,88,99),(3,5,33,55),(5,6,55,66);
27 SELECT *,'|' FROM t1 ORDER BY a;
28 } {1 2 0 0 | 3 4 0 0 | 5 6 0 0 |}
31 UPDATE t1 SET (c,d) = (SELECT y,z FROM t2 WHERE (w,x)=(a,b));
32 SELECT *,'|' FROM t1 ORDER BY a;
33 } {1 2 11 22 | 3 4 {} {} | 5 6 55 66 |}
36 UPDATE t1 SET (c,d) = (SELECT y,z FROM t2 WHERE w=a);
37 SELECT *,'|' FROM t1 ORDER BY a;
38 } {1 2 11 22 | 3 4 33 55 | 5 6 55 66 |}
41 UPDATE t1 SET (c) = 99 WHERE a=3;
42 SELECT *,'|' FROM t1 ORDER BY a;
43 } {1 2 11 22 | 3 4 99 55 | 5 6 55 66 |}
46 UPDATE t1 SET b = 8, (c,d) = (SELECT 123,456) WHERE a=3;
47 SELECT *,'|' FROM t1 ORDER BY a;
48 } {1 2 11 22 | 3 8 123 456 | 5 6 55 66 |}
50 do_catchsql_test 2.1 {
51 UPDATE t1 SET (c,d) = (SELECT x,y,z FROM t2 WHERE w=a);
52 } {1 {2 columns assigned 3 values}}
54 do_catchsql_test 2.2 {
55 UPDATE t1 SET (b,c,d) = (SELECT x,y FROM t2 WHERE w=a);
56 } {1 {3 columns assigned 2 values}}
59 # ticket https://www.sqlite.org/src/info/78acc9d40f0786e8
61 do_catchsql_test 3.0 {
62 DROP TABLE IF EXISTS t1;
64 INSERT INTO t1 VALUES(1,2);
65 UPDATE t1 SET (a,a,a,b)=(SELECT 99,100);
66 } {1 {4 columns assigned 2 values}}