]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make sure the value of an INTEGER PRIMARY KEY column supplied to triggers
authordrh <drh@noemail.net>
Fri, 14 May 2010 19:24:02 +0000 (19:24 +0000)
committerdrh <drh@noemail.net>
Fri, 14 May 2010 19:24:02 +0000 (19:24 +0000)
and especially to FK constraints really contains the ROWID and not the
NULL that is stored in the column itself.  Ticket [dd08e5a988d00dec].

FossilOrigin-Name: 636f86095eb1f4bdcfb0c9ed846c4c6b3589c10b

manifest
manifest.uuid
src/delete.c
src/expr.c
src/sqliteInt.h
src/update.c
test/fkey2.test

index 22d9593528375d76db43ecefc17a39d045d11346..01b78cce0f000d86aeacc3d64c6768d761b28b4b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Simplifications\sto\sthe\sSHM\simplementation\sin\sos_unix.c,\staking\sadvantage\nof\sthe\sremoval\sof\sthe\sLinuxThreads\smess.
-D 2010-05-14T14:52:25
+C Make\ssure\sthe\svalue\sof\san\sINTEGER\sPRIMARY\sKEY\scolumn\ssupplied\sto\striggers\nand\sespecially\sto\sFK\sconstraints\sreally\scontains\sthe\sROWID\sand\snot\sthe\nNULL\sthat\sis\sstored\sin\sthe\scolumn\sitself.\s\sTicket\s[dd08e5a988d00dec].
+D 2010-05-14T19:24:02
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -122,8 +122,8 @@ F src/callback.c 01843bdf4b0420fd28046525d150fcd9802931a9
 F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
 F src/ctime.c 51553a859994d01d8bf3500747f66a890c459774
 F src/date.c 5dd8448a0bfea8d31fb14cff487d0c06ff8c8b20
-F src/delete.c 610dc008e88a9599f905f5cbe9577ac9c36e0581
-F src/expr.c 110e5eddc8c2b02f2d1b4a5afccf0ff9f7b69ef1
+F src/delete.c 41cb4f78557810eecc167b7e2317de7e12d20929
+F src/expr.c 7b1df28226b8a2bb2b9d7c794a42818a81f5edd8
 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
 F src/fkey.c e2116672a6bd610dc888e27df292ebc7999c9bb0
 F src/func.c 0c28599430856631216b6c0131c51c89bf516026
@@ -173,7 +173,7 @@ F src/select.c c03d8a0565febcde8c6a12c5d77d065fddae889b
 F src/shell.c fd4ccdb37c3b68de0623eb938a649e0990710714
 F src/sqlite.h.in a86bb87f5c9e97ed286a70d515d6c19de031f382
 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
-F src/sqliteInt.h 9819b45610abeca390176243a9a31758c1f0ac7a
+F src/sqliteInt.h c1ca9bed7c963343f90edaf0ec31b8ff4b43fb01
 F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3
 F src/status.c 4df6fe7dce2d256130b905847c6c60055882bdbe
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -214,7 +214,7 @@ F src/test_vfs.c 3601f9b6d46cb6daf0697d60c76bf8e18b90b123
 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
 F src/tokenize.c 25ceb0f0a746ea1d0f9553787f3f0a56853cfaeb
 F src/trigger.c 8927588cb9e6d47f933b53bfe74200fbb504100d
-F src/update.c c0dc6b75ad28b76b619042d934f337b02acee208
+F src/update.c 9859f2056c7739a1db0d9774ccb6c2f0cee6d1de
 F src/utf.c 1baeeac91707a4df97ccc6141ec0f808278af685
 F src/util.c 32aebf04c10e51ad3977a928b7416bed671b620b
 F src/vacuum.c b17355fc10cef0875626932ec2f1fa1deb0daa48
@@ -353,7 +353,7 @@ F test/expr.test 9f521ae22f00e074959f72ce2e55d46b9ed23f68
 F test/filectrl.test 8923a6dc7630f31c8a9dd3d3d740aa0922df7bf8
 F test/filefmt.test 84e3d0fe9f12d0d2ac852465c6f8450aea0d6f43
 F test/fkey1.test 01c7de578e11747e720c2d9aeef27f239853c4da
-F test/fkey2.test d5e065ede294ab52affe2116d54dc85a09301354
+F test/fkey2.test 4369be5ef6262187af326a0767a50e63f160f1cf
 F test/fkey3.test 42f88d6048d8dc079e2a8cf7baad1cc1483a7620
 F test/fkey_malloc.test a5ede29bd2f6e56dea78c3d43fb86dd696c068c8
 F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb
@@ -816,14 +816,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P e294b696ba91512b1ca5547774c51ea07b4cb5bc
-R 21f94067ad533c60202276014029d639
+P d1debe5def82a6bc72f11b8787176ac60259630f
+R 050c60fa4d892a7b2d52c45498e15391
 U drh
-Z 433a8524a713de9ce43e3d2748510f46
+Z 800f87a99cec58a270644d7a36670051
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFL7WOsoxKgR168RlERAjJgAJ9zjWsl8oBYzeTvVFGM58MGDrdXDwCfV8pN
-CnLKIoKp0Sl7DOCRB0tGSS8=
-=V8Bz
+iD8DBQFL7aNWoxKgR168RlERAhV/AJ99pDB7OqRYPjLFIkwJw1HsJ/f2MACfX7vp
+okTP4QL6PRs5aDsOujLqck0=
+=rg7a
 -----END PGP SIGNATURE-----
index f3ccfbe4cd759cc5effe9e9bda76679cbf07ff66..6d75b5b6b9ddaffb4e7259bbeed12dbdacb64aaa 100644 (file)
@@ -1 +1 @@
-d1debe5def82a6bc72f11b8787176ac60259630f
\ No newline at end of file
+636f86095eb1f4bdcfb0c9ed846c4c6b3589c10b
\ No newline at end of file
index 9e99a4d462fb012f5e7cd5d7e44d964dcd959f0c..9608dc2f534d34955e5a6f6b7415ca9fbc6e5c6c 100644 (file)
@@ -508,9 +508,7 @@ void sqlite3GenerateRowDelete(
     sqlite3VdbeAddOp2(v, OP_Copy, iRowid, iOld);
     for(iCol=0; iCol<pTab->nCol; iCol++){
       if( mask==0xffffffff || mask&(1<<iCol) ){
-        int iTarget = iOld + iCol + 1;
-        sqlite3VdbeAddOp3(v, OP_Column, iCur, iCol, iTarget);
-        sqlite3ColumnDefault(v, pTab, iCol, iTarget);
+        sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol, iOld+iCol+1);
       }
     }
 
index f82f6d4292da5b88b7eae9b25098c57cc0879019..b776979619ebc26aba8f77d11884653406e96038 100644 (file)
@@ -2082,6 +2082,27 @@ static void sqlite3ExprCachePinRegister(Parse *pParse, int iReg){
   }
 }
 
+/*
+** Generate code to extract the value of the iCol-th column of a table.
+*/
+void sqlite3ExprCodeGetColumnOfTable(
+  Vdbe *v,        /* The VDBE under construction */
+  Table *pTab,    /* The table containing the value */
+  int iTabCur,    /* The cursor for this table */
+  int iCol,       /* Index of the column to extract */
+  int regOut      /* Extract the valud into this register */
+){
+  if( iCol<0 || iCol==pTab->iPKey ){
+    sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
+  }else{
+    int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
+    sqlite3VdbeAddOp3(v, op, iTabCur, iCol, regOut);
+  }
+  if( iCol>=0 ){
+    sqlite3ColumnDefault(v, pTab, iCol, regOut);
+  }
+}
+
 /*
 ** Generate code that will extract the iColumn-th column from
 ** table pTab and store the column value in a register.  An effort
@@ -2110,13 +2131,7 @@ int sqlite3ExprCodeGetColumn(
     }
   }  
   assert( v!=0 );
-  if( iColumn<0 ){
-    sqlite3VdbeAddOp2(v, OP_Rowid, iTable, iReg);
-  }else if( ALWAYS(pTab!=0) ){
-    int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
-    sqlite3VdbeAddOp3(v, op, iTable, iColumn, iReg);
-    sqlite3ColumnDefault(v, pTab, iColumn, iReg);
-  }
+  sqlite3ExprCodeGetColumnOfTable(v, pTab, iTable, iColumn, iReg);
   sqlite3ExprCacheStore(pParse, iTable, iColumn, iReg);
   return iReg;
 }
index 2eae78f609f9a46217610812105fb503cba1af72..2fa474c605bdfc92ce3af1c7cbc89dfa14973193 100644 (file)
@@ -2669,6 +2669,7 @@ void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
 WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u16);
 void sqlite3WhereEnd(WhereInfo*);
 int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int);
+void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
 void sqlite3ExprCodeMove(Parse*, int, int, int);
 void sqlite3ExprCodeCopy(Parse*, int, int, int);
 void sqlite3ExprCacheStore(Parse*, int, int, int);
index 66bf8ca9ffdc44412ced0cff3b0f492e99d4d1e7..3c82c27045613aa8a984e5e6e9fd7127f4fe1c49 100644 (file)
@@ -8,7 +8,7 @@
 **    May you find forgiveness for yourself and forgive others.
 **    May you share freely, never taking more than you give.
 **
-*************************************************************************
+sqlite*************************************************************************
 ** This file contains C code routines that are called by the parser
 ** to handle UPDATE statements.
 */
@@ -396,8 +396,7 @@ void sqlite3Update(
     );
     for(i=0; i<pTab->nCol; i++){
       if( aXRef[i]<0 || oldmask==0xffffffff || (oldmask & (1<<i)) ){
-        sqlite3VdbeAddOp3(v, OP_Column, iCur, i, regOld+i);
-        sqlite3ColumnDefault(v, pTab, i, regOld+i);
+        sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i);
       }else{
         sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i);
       }
index e67bcb53ba95f6f1dcf65aa93bebd8f9c7da6b2b..acbc51601212a2cf6e6bb414ea2e59be272bcbcd 100644 (file)
@@ -77,6 +77,9 @@ ifcapable {!foreignkey||!trigger} {
 # fkey2-genfkey.*: Tests that were used with the shell tool .genfkey
 #            command. Recycled to test the built-in implementation.
 #
+# fkey2-dd08e5.*:  Tests to verify that ticket dd08e5a988d00decc4a543daa8d
+#                  has been fixed.
+#
 
 
 execsql { PRAGMA foreign_keys = on }
@@ -1800,4 +1803,46 @@ do_test fkey2-genfkey.3.6 {
   }
 } {hello {} {}}
 
+#-------------------------------------------------------------------------
+# Verify that ticket dd08e5a988d00decc4a543daa8dbbfab9c577ad8 has been
+# fixed.
+#
+do_test fkey2-dd08e5.1.1 {
+  execsql {
+    PRAGMA foreign_keys=ON;
+    CREATE TABLE tdd08(a INTEGER PRIMARY KEY, b);
+    CREATE UNIQUE INDEX idd08 ON tdd08(a,b);
+    INSERT INTO tdd08 VALUES(200,300);
+
+    CREATE TABLE tdd08_b(w,x,y, FOREIGN KEY(x,y) REFERENCES tdd08(a,b));
+    INSERT INTO tdd08_b VALUES(100,200,300);
+  }
+} {}
+do_test fkey2-dd08e5.1.2 {
+  catchsql {
+    DELETE FROM tdd08;
+  }
+} {1 {foreign key constraint failed}}
+do_test fkey2-dd08e5.1.3 {
+  execsql {
+    SELECT * FROM tdd08;
+  }
+} {200 300}
+do_test fkey2-dd08e5.1.4 {
+  catchsql {
+    INSERT INTO tdd08_b VALUES(400,500,300);
+  }
+} {1 {foreign key constraint failed}}
+do_test fkey2-dd08e5.1.5 {
+  catchsql {
+    UPDATE tdd08_b SET x=x+1;
+  }
+} {1 {foreign key constraint failed}}
+do_test fkey2-dd08e5.1.6 {
+  catchsql {
+    UPDATE tdd08 SET a=a+1;
+  }
+} {1 {foreign key constraint failed}}
+
+
 finish_test