From: dan Date: Wed, 23 Sep 2009 18:07:22 +0000 (+0000) Subject: Fix a problem with FK constraints that implicitly map to a composite primary key. X-Git-Tag: fts3-refactor~158 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8a2fff7a78bf28bc64bfe240b2464ebec8dee91d;p=thirdparty%2Fsqlite.git Fix a problem with FK constraints that implicitly map to a composite primary key. FossilOrigin-Name: e0a48d53110130de75602603f524539e421a9dba --- diff --git a/manifest b/manifest index 4a9243c204..e05eb89d5b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\sthe\sfkey_malloc.test\sscript. -D 2009-09-23T17:31:19 +C Fix\sa\sproblem\swith\sFK\sconstraints\sthat\simplicitly\smap\sto\sa\scomposite\sprimary\skey. +D 2009-09-23T18:07:22 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 c7f3f718bd5c392344ec8694a41c1824f30cf375 F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff -F src/fkey.c 89232758416a48783adbb3b48ab447432e817370 +F src/fkey.c a1c293cca23700bae7924396055c8d6a14f711c2 F src/func.c e536218d193b8d326aab91120bc4c6f28aa2b606 F src/global.c 271952d199a8cc59d4ce840b3bbbfd2f30c8ba32 F src/hash.c ebcaa921ffd9d86f7ea5ae16a0a29d1c871130a7 @@ -208,7 +208,7 @@ F src/util.c 59d4e9456bf1fe581f415a783fa0cee6115c8f35 F src/vacuum.c 869d08eaab64e2a4eaf4ef9ea34b851892b65a75 F src/vdbe.c a5da14fe8d89f9ad2cd4911a9d7df79c74a6b84c F src/vdbe.h 7d5075e3fa4e5587a9be8d5e503857c825490cef -F src/vdbeInt.h 03336c0364c94267de615b9cd7768e7264f324ac +F src/vdbeInt.h 7afb76c0296f9a2310e565803fa66798ef47e9d5 F src/vdbeapi.c 524d79eb17bbcbe31c37c908b8e01edc5c684a90 F src/vdbeaux.c 32d77382469c20aa5a971a8794deb1eafa8d5cb6 F src/vdbeblob.c 3ba0f7ba1b3afce2d37a18e4f437992d430f0eae @@ -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 1a32149cc3c722058f4ed4c81edadeb6ce5bc9e4 -R ceb76eab6b554987479ec64881a5bee7 +P 0ce1efa46080f379089b03706daeac96c4add0f9 +R c55088d555c926efecaa92adc93e4c6b U dan -Z 43e72436acd6bfae46680c9ceeafa3ce +Z 26aaed3e9a02b590739916db40d12d2e diff --git a/manifest.uuid b/manifest.uuid index 3223ea8d18..36766fa06c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0ce1efa46080f379089b03706daeac96c4add0f9 \ No newline at end of file +e0a48d53110130de75602603f524539e421a9dba \ No newline at end of file diff --git a/src/fkey.c b/src/fkey.c index d79b7fb562..efd0e788ab 100644 --- a/src/fkey.c +++ b/src/fkey.c @@ -21,8 +21,8 @@ ** -------------------------- ** ** Foreign keys in SQLite come in two flavours: deferred and immediate. -** If an immediate foreign key constraint is violated, an OP_Halt is -** executed and the current statement transaction rolled back. If a +** If an immediate foreign key constraint is violated, SQLITE_CONSTRAINT +** is returned and the current statement transaction rolled back. If a ** deferred foreign key constraint is violated, no action is taken ** immediately. However if the application attempts to commit the ** transaction before fixing the constraint violation, the attempt fails. @@ -49,26 +49,24 @@ ** INSERT operations: ** ** I.1) For each FK for which the table is the child table, search -** the parent table for a match. If none is found, throw an -** exception for an immediate FK, or increment the counter for a -** deferred FK. +** the parent table for a match. If none is found increment the +** constraint counter. ** -** I.2) For each deferred FK for which the table is the parent table, +** I.2) For each FK for which the table is the parent table, ** search the child table for rows that correspond to the new ** row in the parent table. Decrement the counter for each row ** found (as the constraint is now satisfied). ** ** DELETE operations: ** -** D.1) For each deferred FK for which the table is the child table, +** D.1) For each FK for which the table is the child table, ** search the parent table for a row that corresponds to the ** deleted row in the child table. If such a row is not found, ** decrement the counter. ** ** D.2) For each FK for which the table is the parent table, search ** the child table for rows that correspond to the deleted row -** in the parent table. For each found, throw an exception for an -** immediate FK, or increment the counter for a deferred FK. +** in the parent table. For each found increment the counter. ** ** UPDATE operations: ** @@ -224,7 +222,10 @@ static int locateFkeyIndex( ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be ** identified by the test (Index.autoIndex==2). */ if( pIdx->autoIndex==2 ){ - if( aiCol ) memcpy(aiCol, pIdx->aiColumn, sizeof(int)*nCol); + if( aiCol ){ + int i; + for(i=0; iaCol[i].iFrom; + } break; } }else{ diff --git a/src/vdbeInt.h b/src/vdbeInt.h index b24b3fb429..91c3ad25d4 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -390,9 +390,9 @@ int sqlite3VdbeReleaseBuffers(Vdbe *p); #endif #ifndef SQLITE_OMIT_FOREIGN_KEY -int sqlite3VdbeCheckDeferred(Vdbe *); +int sqlite3VdbeCheckFk(Vdbe *, int); #else -# define sqlite3VdbeCheckDeferred(p) 0 +# define sqlite3VdbeCheckFk(p,i) 0 #endif #ifndef SQLITE_OMIT_SHARED_CACHE