From 4e1f0efb4de9a6bb53b0979d9a5b700a77253277 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 4 Jan 2017 20:13:51 +0000 Subject: [PATCH] Possible fix for 30027b61. There may still be problems surrounding foreign key processing. FossilOrigin-Name: 71ccb1f4c490fdebc7008e884384e7809b849742 --- manifest | 18 +++++++----- manifest.uuid | 2 +- src/insert.c | 8 ++++-- test/triggerF.test | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 test/triggerF.test diff --git a/manifest b/manifest index e7b721c8dd..a9b1e4263e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Adjust\sfilename\screation\sin\stest_sqllog.c\sso\sthat\sit\suses\sleading\szeros\son\ncounters,\sso\sthat\sfiles\sappear\sin\sorder\swhen\ssorted\slexicographically. -D 2017-01-04T14:53:53.255 +C Possible\sfix\sfor\s30027b61.\sThere\smay\sstill\sbe\sproblems\ssurrounding\sforeign\skey\nprocessing. +D 2017-01-04T20:13:51.856 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da @@ -350,7 +350,7 @@ F src/hash.c 63d0ee752a3b92d4695b2b1f5259c4621b2cfebd F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4 F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 91ba5d0143e66479081536ebbaff1850ec9f57d9 +F src/insert.c 1e0c2b61265518a31929a10ca28102a7911d2e69 F src/legacy.c 75d3023be8f0d2b99d60f905090341a03358c58e F src/loadext.c 5d6642d141c07d366e43d359e94ec9de47add41d F src/main.c e207b81542d13b9f13d61e78ca441f9781f055b0 @@ -1336,6 +1336,7 @@ F test/triggerB.test 56780c031b454abac2340dbb3b71ac5c56c3d7fe F test/triggerC.test 302d8995f5ffe63bbc15053abb3ef7a39cf5a092 F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650 F test/triggerE.test 15fa63f1097db1f83dd62d121616006978063d1f +F test/triggerF.test 55b1eb13433997faac3a4948c1d8252f6c8c636b F test/tt3_checkpoint.c 9e75cf7c1c364f52e1c47fd0f14c4340a9db0fe1 F test/tt3_index.c 39eec10a35f57672225be4d182862152896dee4a F test/tt3_lookaside1.c 0377e202c3c2a50d688cb65ba203afeda6fafeb9 @@ -1541,7 +1542,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 82e4001b8caef7b31967f3edcbc1a545c081bdbc -R 3e81c0bc63e48e38a06c9f06294caaaf -U drh -Z 0ca8dd088b039fc660aef4a4ad2583af +P 8d670973595bd01ffc9b2ab53b965e6d6d22c573 +R 18f979ea5ceac35d70bae9aad4eb77f0 +T *branch * replace-fix +T *sym-replace-fix * +T -sym-trunk * +U dan +Z a4497840837bb26a5ad3bdf1e588e388 diff --git a/manifest.uuid b/manifest.uuid index 6f5e8babb5..56c42e692c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d670973595bd01ffc9b2ab53b965e6d6d22c573 \ No newline at end of file +71ccb1f4c490fdebc7008e884384e7809b849742 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 27e05d4de6..2cc0457a99 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1550,8 +1550,12 @@ void sqlite3GenerateConstraintChecks( } if( ix==0 && pPk==pIdx && onError==OE_Replace && pPk->pNext==0 ){ - sqlite3VdbeResolveLabel(v, addrUniqueOk); - continue; + if( 0==(db->flags&SQLITE_RecTriggers) + || 0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0) + ){ + sqlite3VdbeResolveLabel(v, addrUniqueOk); + continue; + } } diff --git a/test/triggerF.test b/test/triggerF.test new file mode 100644 index 0000000000..d5e3565edd --- /dev/null +++ b/test/triggerF.test @@ -0,0 +1,72 @@ +# 2017 January 4 +# +# The author disclaims copyright to this source code. In place of +# a legal notice', here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix triggerF +ifcapable {!trigger} { + finish_test + return +} + + +foreach {tn sql log} { + 1 { } { } + + 2 { + CREATE TRIGGER trd AFTER DELETE ON t1 BEGIN + INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); + END; + } {1one2 2two1 3three1} + + 3 { + CREATE TRIGGER trd BEFORE DELETE ON t1 BEGIN + INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); + END; + } {1one3 2two2 3three2} + + 4 { + CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN + INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); + END; + CREATE TRIGGER tr2 BEFORE DELETE ON t1 BEGIN + INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); + END; + } {1one3 1one2 2two2 2two1 3three2 3three1} + +} { + reset_db + do_execsql_test 1.$tn.0 { + PRAGMA recursive_triggers = on; + CREATE TABLE t1(a INT PRIMARY KEY, b) WITHOUT ROWID; + CREATE TABLE log(t); + } + + execsql $sql + + do_execsql_test 1.$tn.1 { + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t1 VALUES(3, 'three'); + + DELETE FROM t1 WHERE a=1; + INSERT OR REPLACE INTO t1 VALUES(2, 'three'); + UPDATE OR REPLACE t1 SET a=3 WHERE a=2; + } + + do_execsql_test 1.$tn.2 { + SELECT * FROM log ORDER BY rowid; + } $log +} + +finish_test + -- 2.47.2