mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Do not allow triggers that run as part of REPLACE conflict resolution
during an UPDATE to modify the the table being updated. Otherwise, those triggers might delete content out from under the update operation, leading to all kinds of problems. Ticket [314cc133e5ada126] FossilOrigin-Name: db4b7e1dc399c1f16b827ac087aa37c0815f4b2f41f1ffad59963eead2ab5562
This commit is contained in:
@ -380,15 +380,15 @@ ifcapable trigger {
|
||||
INSERT INTO t0 VALUES(0, NULL);
|
||||
}
|
||||
|
||||
do_execsql_test 13.1.1 {
|
||||
do_catchsql_test 13.1.1 {
|
||||
UPDATE OR REPLACE t0 SET c1 = 1;
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
|
||||
integrity_check 13.1.2
|
||||
|
||||
do_execsql_test 13.1.3 {
|
||||
SELECT * FROM t0
|
||||
} {}
|
||||
} {1 {} 0 {}}
|
||||
|
||||
do_execsql_test 13.2.0 {
|
||||
CREATE TABLE t2 (a PRIMARY KEY, b UNIQUE, c UNIQUE) WITHOUT ROWID;
|
||||
@ -400,15 +400,15 @@ ifcapable trigger {
|
||||
INSERT INTO t2 VALUES(2, 2, 2);
|
||||
}
|
||||
|
||||
do_execsql_test 13.2.1 {
|
||||
do_catchsql_test 13.2.1 {
|
||||
UPDATE OR REPLACE t2 SET c = 0;
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
|
||||
integrity_check 13.2.2
|
||||
|
||||
do_execsql_test 13.2.3 {
|
||||
SELECT * FROM t2
|
||||
} {}
|
||||
} {1 1 1 2 2 2}
|
||||
|
||||
do_execsql_test 13.3.0 {
|
||||
CREATE TABLE t1(a, b);
|
||||
|
@ -701,4 +701,33 @@ do_execsql_test update-19.10 {
|
||||
SELECT * FROM t1;
|
||||
} {2 2}
|
||||
|
||||
# 2019-12-29 ticket https://www.sqlite.org/src/info/314cc133e5ada126
|
||||
# REPLACE conflict resolution during an UPDATE causes a DELETE trigger
|
||||
# to fire. If that DELETE trigger subsequently modifies the row
|
||||
# being updated, bad things can happen. Prevent this by prohibiting
|
||||
# triggers from making changes to the table being updated while doing
|
||||
# REPLACE conflict resolution on the UPDATE.
|
||||
#
|
||||
# See also tickets:
|
||||
# https://www.sqlite.org/src/info/c1e19e12046d23fe 2019-10-25
|
||||
# https://www.sqlite.org/src/info/a8a4847a2d96f5de 2019-10-16
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test update-20.10 {
|
||||
PRAGMA recursive_triggers = true;
|
||||
CREATE TABLE t1(a UNIQUE ON CONFLICT REPLACE, b);
|
||||
INSERT INTO t1(a,b) VALUES(4,12),(9,13);
|
||||
CREATE INDEX i0 ON t1(b);
|
||||
CREATE TRIGGER tr0 DELETE ON t1 BEGIN
|
||||
UPDATE t1 SET b = a;
|
||||
END;
|
||||
PRAGMA integrity_check;
|
||||
} {ok}
|
||||
do_catchsql_test update-20.20 {
|
||||
UPDATE t1 SET a=0;
|
||||
} {1 {constraint failed}}
|
||||
do_execsql_test update-20.30 {
|
||||
PRAGMA integrity_check;
|
||||
} {ok}
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user