From: dan Date: Tue, 22 Sep 2009 16:08:58 +0000 (+0000) Subject: Fix a problem with ON DELETE SET DEFAULT actions. X-Git-Tag: fts3-refactor~172 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=934ce300a0fbeceb739434a37caa231655aabec5;p=thirdparty%2Fsqlite.git Fix a problem with ON DELETE SET DEFAULT actions. FossilOrigin-Name: 9406995055f53639b0af46985c7b0a24a80308ae --- diff --git a/manifest b/manifest index 2e4d3f3375..852780318b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sOOM\srelated\scrash\sin\sfkey.c. -D 2009-09-22T15:53:48 +C Fix\sa\sproblem\swith\sON\sDELETE\sSET\sDEFAULT\sactions. +D 2009-09-22T16:08:58 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 4ca3f1dd6efa2075bcb27f4dc43eef749877740d F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -116,7 +116,7 @@ F src/date.c 657ff12ca0f1195b531561afacbb38b772d16638 F src/delete.c 15499f5d10047d38e68ce991b3f88cbddb6e0931 F src/expr.c 638b599adad562d41c3bf90f542f9419664aa7b8 F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff -F src/fkey.c 2c20574e7cfed8f01d944009c5f035c0bd25bbf0 +F src/fkey.c db2225a0d7d2bfe1ffd4b694d7ca7f3e994a6a88 F src/func.c e536218d193b8d326aab91120bc4c6f28aa2b606 F src/global.c 271952d199a8cc59d4ce840b3bbbfd2f30c8ba32 F src/hash.c ebcaa921ffd9d86f7ea5ae16a0a29d1c871130a7 @@ -330,7 +330,7 @@ F test/expr.test 80f3cf99f786ffbac19d2b0083673e7fc797030f F test/filectrl.test 8923a6dc7630f31c8a9dd3d3d740aa0922df7bf8 F test/filefmt.test 84e3d0fe9f12d0d2ac852465c6f8450aea0d6f43 F test/fkey1.test 01c7de578e11747e720c2d9aeef27f239853c4da -F test/fkey2.test 968812cf06dc4d41ff44d7f73c3a7de64c4d7b36 +F test/fkey2.test b752d0290886063b42b96584eca5ddeada4c3db1 F test/fkey_malloc.test 9926c3b4fd5f7edeb2025359d35452e733a2fbba F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7 @@ -753,7 +753,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 216bcda7d2818efda55849d5cb84aa483bc6429b -R a5adfa0091a131eefdfdfb2dd488fa3e +P 635d6a775a3f192d4292738905f5e01bc956a712 +R adb59c314ed6e84fb5e109c808025d01 U dan -Z 09ca6593e06ce2c3dfaca1d68f6c10bc +Z ca9f75785688b952325cd06be253de5b diff --git a/manifest.uuid b/manifest.uuid index 5c8fa6ff80..fd62f8684a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -635d6a775a3f192d4292738905f5e01bc956a712 \ No newline at end of file +9406995055f53639b0af46985c7b0a24a80308ae \ No newline at end of file diff --git a/src/fkey.c b/src/fkey.c index 77babe54c5..ceb5bedcef 100644 --- a/src/fkey.c +++ b/src/fkey.c @@ -683,7 +683,7 @@ static Trigger *fkActionTrigger( sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol) , 0); }else if( action==OE_SetDflt ){ - Expr *pDflt = pIdx ? 0 : pTab->aCol[pIdx->aiColumn[i]].pDflt; + Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt; if( pDflt ){ pNew = sqlite3ExprDup(db, pDflt, 0); }else{ diff --git a/test/fkey2.test b/test/fkey2.test index b8606e3007..8c6936e185 100644 --- a/test/fkey2.test +++ b/test/fkey2.test @@ -47,6 +47,8 @@ ifcapable {!foreignkey||!trigger} { # fkey2-8.*: Test that enabling/disabling foreign key support while a # transaction is active is not possible. # +# fkey2-9.*: Test SET DEFAULT actions. +# # fkey2-genfkey.*: Tests that were used with the shell tool .genfkey # 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 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 same tests that were used to test the ".genfkey" command provided