If an AFTER DELETE trigger fires when a conflict row is deleted by REPLACE
conflict resolution, make sure the conflict really has been resolved and that the trigger did not recreate the row before continuing. Ticket [a8a4847a2d96f5de] FossilOrigin-Name: eea1e7aa57e74c4329003f4550168e2aed9e33d2301a3ba84b10781a9cebbc1b
This commit is contained in:
parent
4ec3e820a0
commit
2da8d6fe74
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C Formatting\schange\son\sa\smulti-line\sconditional,\sfor\simproved\sclarity.\nNo\slogic\schanges.
|
||||
D 2019-10-15T19:01:55.901
|
||||
C If\san\sAFTER\sDELETE\strigger\sfires\swhen\sa\sconflict\srow\sis\sdeleted\sby\sREPLACE\nconflict\sresolution,\smake\ssure\sthe\sconflict\sreally\shas\sbeen\sresolved\sand\sthat\nthe\strigger\sdid\snot\srecreate\sthe\srow\sbefore\scontinuing.\nTicket\s[a8a4847a2d96f5de]
|
||||
D 2019-10-16T14:56:03.686
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -486,7 +486,7 @@ F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19
|
||||
F src/hash.h 9d56a9079d523b648774c1784b74b89bd93fac7b365210157482e4319a468f38
|
||||
F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da
|
||||
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
|
||||
F src/insert.c 40557ebd69f4115e7a273f9304a8ab637a47ce44f3c6923396928f023967b5e8
|
||||
F src/insert.c d9cb78faa39180915ed940f0dcb3b168002f72e4f4926081a9553719fd12f6a1
|
||||
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
||||
F src/loadext.c 4ddc65ae13c0d93db0ceedc8b14a28c8c260513448b0eb8c5a2ac375e3b6a85d
|
||||
F src/main.c 3e01f6a1c96643381b5f9d79e4ff7f2520bc5712197746fb0852283e78cccf66
|
||||
@ -1060,7 +1060,7 @@ F test/indexexpr1.test c26c8b352311c1deb30642cd0379e5cb94e416c7e9e0885e92d9e0155
|
||||
F test/indexexpr2.test b580f378423bca443ffab47ada677203cfcf8a60f48a8aa20065f27c8f7739b5
|
||||
F test/indexfault.test 98d78a8ff1f5335628b62f886a1cb7c7dac1ef6d48fa39c51ec871c87dce9811
|
||||
F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7
|
||||
F test/insert.test 72004f6a900a25bd3f1ce9a72e73d02749644666a8ce6d6d2dba061137e5aa63
|
||||
F test/insert.test c0e1b23f6359e06316b3a49f7747c5d65c0b6473619011e4fb86f6801edba6df
|
||||
F test/insert2.test 4d14b8f1b810a41995f6286b64a6943215d52208
|
||||
F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30
|
||||
F test/insert4.test 7802ada6ba8738661b9f6c0e26858d3375b40cc7180289fd350644cd7a08fec9
|
||||
@ -1847,7 +1847,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P bc751fb64d5b08e5ca4c85cd1c6fbf09590fa9dad7e176ba373082ea373655b5
|
||||
R 3dc274e5f048c65fb3fe7dfe730dc64a
|
||||
P 7248e3476511ecd317f54edcfe1e87443bfdcc1b10c89c7734eefcabafec6c0b
|
||||
R ba1e81530d1e44a95d6e773164db4f87
|
||||
U drh
|
||||
Z a66229c65bafcb1e69be0fef5ecdca35
|
||||
Z 2617114f912aef1c01f5243e59a012d0
|
||||
|
@ -1 +1 @@
|
||||
7248e3476511ecd317f54edcfe1e87443bfdcc1b10c89c7734eefcabafec6c0b
|
||||
eea1e7aa57e74c4329003f4550168e2aed9e33d2301a3ba84b10781a9cebbc1b
|
@ -1582,6 +1582,8 @@ void sqlite3GenerateConstraintChecks(
|
||||
sqlite3MultiWrite(pParse);
|
||||
sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
|
||||
regNewData, 1, 0, OE_Replace, 1, -1);
|
||||
sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
|
||||
sqlite3RowidConstraint(pParse, OE_Abort, pTab);
|
||||
}else{
|
||||
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
assert( HasRowid(pTab) );
|
||||
@ -1829,16 +1831,23 @@ void sqlite3GenerateConstraintChecks(
|
||||
}
|
||||
default: {
|
||||
Trigger *pTrigger = 0;
|
||||
int bRetryConstraintCheck = 0;
|
||||
assert( onError==OE_Replace );
|
||||
if( db->flags&SQLITE_RecTriggers ){
|
||||
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
|
||||
}
|
||||
if( pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0) ){
|
||||
sqlite3MultiWrite(pParse);
|
||||
bRetryConstraintCheck = 1;
|
||||
}
|
||||
sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
|
||||
regR, nPkField, 0, OE_Replace,
|
||||
(pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
|
||||
if( bRetryConstraintCheck ){
|
||||
sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
|
||||
regIdx, pIdx->nKeyCol); VdbeCoverage(v);
|
||||
sqlite3UniqueConstraint(pParse, OE_Abort, pIdx);
|
||||
}
|
||||
seenReplace = 1;
|
||||
break;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
# 2001 September 15
|
||||
# 2001-09-15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
@ -11,7 +11,6 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the INSERT statement.
|
||||
#
|
||||
# $Id: insert.test,v 1.31 2007/04/05 11:25:59 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -458,7 +457,7 @@ do_execsql_test insert-14.1 {
|
||||
SELECT x FROM t14;
|
||||
} {1}
|
||||
|
||||
integrity_check insert-99.0
|
||||
integrity_check insert-14.2
|
||||
|
||||
# 2019-08-12.
|
||||
#
|
||||
@ -475,5 +474,53 @@ do_execsql_test insert-15.1 {
|
||||
SELECT a, length(b) FROM t1;
|
||||
} {4 33000}
|
||||
|
||||
# 2019-10-16
|
||||
# ticket https://www.sqlite.org/src/info/a8a4847a2d96f5de
|
||||
# On a REPLACE INTO, if an AFTER trigger adds back the conflicting
|
||||
# row, you can end up with the wrong number of rows in an index.
|
||||
#
|
||||
db close
|
||||
sqlite3 db :memory:
|
||||
do_catchsql_test insert-16.1 {
|
||||
PRAGMA recursive_triggers = true;
|
||||
CREATE TABLE t0(c0,c1);
|
||||
CREATE UNIQUE INDEX i0 ON t0(c0);
|
||||
INSERT INTO t0(c0,c1) VALUES(123,1);
|
||||
CREATE TRIGGER tr0 AFTER DELETE ON t0
|
||||
BEGIN
|
||||
INSERT INTO t0 VALUES(123,2);
|
||||
END;
|
||||
REPLACE INTO t0(c0,c1) VALUES(123,3);
|
||||
} {1 {UNIQUE constraint failed: t0.c0}}
|
||||
do_execsql_test insert-16.2 {
|
||||
SELECT * FROM t0;
|
||||
} {123 1}
|
||||
integrity_check insert-16.3
|
||||
do_catchsql_test insert-16.4 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
|
||||
CREATE INDEX t1b ON t1(b);
|
||||
INSERT INTO t1 VALUES(1, 'one');
|
||||
CREATE TRIGGER tr3 AFTER DELETE ON t1 BEGIN
|
||||
INSERT INTO t1 VALUES(1, 'three');
|
||||
END;
|
||||
REPLACE INTO t1 VALUES(1, 'two');
|
||||
} {1 {UNIQUE constraint failed: t1.a}}
|
||||
integrity_check insert-16.5
|
||||
do_catchsql_test insert-16.6 {
|
||||
PRAGMA foreign_keys = 1;
|
||||
CREATE TABLE p1(a, b UNIQUE);
|
||||
CREATE TABLE c1(c, d REFERENCES p1(b) ON DELETE CASCADE);
|
||||
CREATE TRIGGER tr6 AFTER DELETE ON c1 BEGIN
|
||||
INSERT INTO p1 VALUES(4, 1);
|
||||
END;
|
||||
INSERT INTO p1 VALUES(1, 1);
|
||||
INSERT INTO c1 VALUES(2, 1);
|
||||
REPLACE INTO p1 VALUES(3, 1);
|
||||
} {1 {UNIQUE constraint failed: p1.b}}
|
||||
integrity_check insert-16.7
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
Loading…
Reference in New Issue
Block a user