1a1251bc4Sdrh# 2016-08-18 2a1251bc4Sdrh# 3a1251bc4Sdrh# The author disclaims copyright to this source code. In place of 4a1251bc4Sdrh# a legal notice, here is a blessing: 5a1251bc4Sdrh# 6a1251bc4Sdrh# May you do good and not evil. 7a1251bc4Sdrh# May you find forgiveness for yourself and forgive others. 8a1251bc4Sdrh# May you share freely, never taking more than you give. 9a1251bc4Sdrh# 10a1251bc4Sdrh#*********************************************************************** 11a1251bc4Sdrh# The focus of this file is vector assignments in the SET clause of 12a1251bc4Sdrh# an UPDATE statement. 13a1251bc4Sdrh# 14a1251bc4Sdrh 15a1251bc4Sdrhset testdir [file dirname $argv0] 16a1251bc4Sdrhsource $testdir/tester.tcl 17a1251bc4Sdrhset ::testprefix rowvalue7 18a1251bc4Sdrh 19a1251bc4Sdrhdo_execsql_test 1.1 { 20a1251bc4Sdrh CREATE TABLE t1(a,b,c,d); 21a1251bc4Sdrh CREATE INDEX t1x ON t1(a,b); 22a1251bc4Sdrh INSERT INTO t1(a,b,c,d) VALUES(1,2,0,0),(3,4,0,0),(5,6,0,0); 23a1251bc4Sdrh CREATE TABLE t2(w,x,y,z); 24a1251bc4Sdrh CREATE INDEX t2x ON t2(w,x); 25a1251bc4Sdrh INSERT INTO t2(w,x,y,z) VALUES(1,2,11,22),(8,9,88,99),(3,5,33,55),(5,6,55,66); 26a1251bc4Sdrh 27a1251bc4Sdrh SELECT *,'|' FROM t1 ORDER BY a; 28a1251bc4Sdrh} {1 2 0 0 | 3 4 0 0 | 5 6 0 0 |} 29a1251bc4Sdrh 30a1251bc4Sdrhdo_execsql_test 1.2 { 31a1251bc4Sdrh UPDATE t1 SET (c,d) = (SELECT y,z FROM t2 WHERE (w,x)=(a,b)); 32a1251bc4Sdrh SELECT *,'|' FROM t1 ORDER BY a; 33a1251bc4Sdrh} {1 2 11 22 | 3 4 {} {} | 5 6 55 66 |} 34a1251bc4Sdrh 35a1251bc4Sdrhdo_execsql_test 1.3 { 36a1251bc4Sdrh UPDATE t1 SET (c,d) = (SELECT y,z FROM t2 WHERE w=a); 37a1251bc4Sdrh SELECT *,'|' FROM t1 ORDER BY a; 38a1251bc4Sdrh} {1 2 11 22 | 3 4 33 55 | 5 6 55 66 |} 39a1251bc4Sdrh 40a1251bc4Sdrhdo_execsql_test 1.4 { 41a1251bc4Sdrh UPDATE t1 SET (c) = 99 WHERE a=3; 42a1251bc4Sdrh SELECT *,'|' FROM t1 ORDER BY a; 43a1251bc4Sdrh} {1 2 11 22 | 3 4 99 55 | 5 6 55 66 |} 44a1251bc4Sdrh 45a1251bc4Sdrhdo_execsql_test 1.5 { 4666860af3Sdrh UPDATE t1 SET b = 8, (c,d) = (SELECT 123,456) WHERE a=3; 47a1251bc4Sdrh SELECT *,'|' FROM t1 ORDER BY a; 48a1251bc4Sdrh} {1 2 11 22 | 3 8 123 456 | 5 6 55 66 |} 49a1251bc4Sdrh 50a1251bc4Sdrhdo_catchsql_test 2.1 { 51a1251bc4Sdrh UPDATE t1 SET (c,d) = (SELECT x,y,z FROM t2 WHERE w=a); 52a1251bc4Sdrh} {1 {2 columns assigned 3 values}} 53a1251bc4Sdrh 54a1251bc4Sdrhdo_catchsql_test 2.2 { 55a1251bc4Sdrh UPDATE t1 SET (b,c,d) = (SELECT x,y FROM t2 WHERE w=a); 56a1251bc4Sdrh} {1 {3 columns assigned 2 values}} 57a1251bc4Sdrh 58*554a9dc7Sdrh# 2019-08-26 59*554a9dc7Sdrh# ticket https://www.sqlite.org/src/info/78acc9d40f0786e8 60*554a9dc7Sdrh# 61*554a9dc7Sdrhdo_catchsql_test 3.0 { 62*554a9dc7Sdrh DROP TABLE IF EXISTS t1; 63*554a9dc7Sdrh CREATE TABLE t1(a,b); 64*554a9dc7Sdrh INSERT INTO t1 VALUES(1,2); 65*554a9dc7Sdrh UPDATE t1 SET (a,a,a,b)=(SELECT 99,100); 66*554a9dc7Sdrh} {1 {4 columns assigned 2 values}} 67*554a9dc7Sdrh 68a1251bc4Sdrhfinish_test 69