1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-16 23:02:26 +03:00

Fix a problem with ON DELETE SET DEFAULT actions.

FossilOrigin-Name: 9406995055f53639b0af46985c7b0a24a80308ae
This commit is contained in:
dan
2009-09-22 16:08:58 +00:00
parent 29c7f9caac
commit 934ce300a0
4 changed files with 50 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
C Fix\san\sOOM\srelated\scrash\sin\sfkey.c. C Fix\sa\sproblem\swith\sON\sDELETE\sSET\sDEFAULT\sactions.
D 2009-09-22T15:53:48 D 2009-09-22T16:08:58
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 4ca3f1dd6efa2075bcb27f4dc43eef749877740d F Makefile.in 4ca3f1dd6efa2075bcb27f4dc43eef749877740d
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -116,7 +116,7 @@ F src/date.c 657ff12ca0f1195b531561afacbb38b772d16638
F src/delete.c 15499f5d10047d38e68ce991b3f88cbddb6e0931 F src/delete.c 15499f5d10047d38e68ce991b3f88cbddb6e0931
F src/expr.c 638b599adad562d41c3bf90f542f9419664aa7b8 F src/expr.c 638b599adad562d41c3bf90f542f9419664aa7b8
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
F src/fkey.c 2c20574e7cfed8f01d944009c5f035c0bd25bbf0 F src/fkey.c db2225a0d7d2bfe1ffd4b694d7ca7f3e994a6a88
F src/func.c e536218d193b8d326aab91120bc4c6f28aa2b606 F src/func.c e536218d193b8d326aab91120bc4c6f28aa2b606
F src/global.c 271952d199a8cc59d4ce840b3bbbfd2f30c8ba32 F src/global.c 271952d199a8cc59d4ce840b3bbbfd2f30c8ba32
F src/hash.c ebcaa921ffd9d86f7ea5ae16a0a29d1c871130a7 F src/hash.c ebcaa921ffd9d86f7ea5ae16a0a29d1c871130a7
@@ -330,7 +330,7 @@ F test/expr.test 80f3cf99f786ffbac19d2b0083673e7fc797030f
F test/filectrl.test 8923a6dc7630f31c8a9dd3d3d740aa0922df7bf8 F test/filectrl.test 8923a6dc7630f31c8a9dd3d3d740aa0922df7bf8
F test/filefmt.test 84e3d0fe9f12d0d2ac852465c6f8450aea0d6f43 F test/filefmt.test 84e3d0fe9f12d0d2ac852465c6f8450aea0d6f43
F test/fkey1.test 01c7de578e11747e720c2d9aeef27f239853c4da F test/fkey1.test 01c7de578e11747e720c2d9aeef27f239853c4da
F test/fkey2.test 968812cf06dc4d41ff44d7f73c3a7de64c4d7b36 F test/fkey2.test b752d0290886063b42b96584eca5ddeada4c3db1
F test/fkey_malloc.test 9926c3b4fd5f7edeb2025359d35452e733a2fbba F test/fkey_malloc.test 9926c3b4fd5f7edeb2025359d35452e733a2fbba
F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb
F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7 F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7
@@ -753,7 +753,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 216bcda7d2818efda55849d5cb84aa483bc6429b P 635d6a775a3f192d4292738905f5e01bc956a712
R a5adfa0091a131eefdfdfb2dd488fa3e R adb59c314ed6e84fb5e109c808025d01
U dan U dan
Z 09ca6593e06ce2c3dfaca1d68f6c10bc Z ca9f75785688b952325cd06be253de5b

View File

@@ -1 +1 @@
635d6a775a3f192d4292738905f5e01bc956a712 9406995055f53639b0af46985c7b0a24a80308ae

View File

@@ -683,7 +683,7 @@ static Trigger *fkActionTrigger(
sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol) sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
, 0); , 0);
}else if( action==OE_SetDflt ){ }else if( action==OE_SetDflt ){
Expr *pDflt = pIdx ? 0 : pTab->aCol[pIdx->aiColumn[i]].pDflt; Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
if( pDflt ){ if( pDflt ){
pNew = sqlite3ExprDup(db, pDflt, 0); pNew = sqlite3ExprDup(db, pDflt, 0);
}else{ }else{

View File

@@ -47,6 +47,8 @@ ifcapable {!foreignkey||!trigger} {
# fkey2-8.*: Test that enabling/disabling foreign key support while a # fkey2-8.*: Test that enabling/disabling foreign key support while a
# transaction is active is not possible. # transaction is active is not possible.
# #
# fkey2-9.*: Test SET DEFAULT actions.
#
# fkey2-genfkey.*: Tests that were used with the shell tool .genfkey # fkey2-genfkey.*: Tests that were used with the shell tool .genfkey
# command. Recycled to test the built-in implementation. # command. Recycled to test the built-in implementation.
# #
@@ -477,6 +479,45 @@ fkey2-8-test 14 { PRAGMA foreign_keys = yes } 1
fkey2-8-test 15 { PRAGMA foreign_keys = false } 0 fkey2-8-test 15 { PRAGMA foreign_keys = false } 0
fkey2-8-test 16 { PRAGMA foreign_keys = true } 1 fkey2-8-test 16 { PRAGMA foreign_keys = true } 1
#-------------------------------------------------------------------------
# The following tests, fkey2-9.*, test SET DEFAULT actions.
#
drop_all_tables
do_test fkey2-9.1.1 {
execsql {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
CREATE TABLE t2(
c INTEGER PRIMARY KEY,
d INTEGER DEFAULT 1 REFERENCES t1 ON DELETE SET DEFAULT
);
DELETE FROM t1;
}
} {}
do_test fkey2-9.1.2 {
execsql {
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
INSERT INTO t2 VALUES(1, 2);
SELECT * FROM t2;
DELETE FROM t1 WHERE a = 2;
SELECT * FROM t2;
}
} {1 2 1 1}
do_test fkey2-9.1.3 {
execsql {
INSERT INTO t1 VALUES(2, 'two');
UPDATE t2 SET d = 2;
DELETE FROM t1 WHERE a = 1;
SELECT * FROM t2;
}
} {1 2}
do_test fkey2-9.1.4 {
execsql { SELECT * FROM t1 }
} {2 two}
do_test fkey2-9.1.5 {
catchsql { DELETE FROM t1 }
} {1 {foreign key constraint failed}}
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# The following block of tests, those prefixed with "fkey2-genfkey.", are # The following block of tests, those prefixed with "fkey2-genfkey.", are
# the same tests that were used to test the ".genfkey" command provided # the same tests that were used to test the ".genfkey" command provided