1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-06 15:49:35 +03:00

Fix some foreign key constraint related problems that occur when a row refers to itself.

FossilOrigin-Name: 9e503e2d0428c9e8df878c7c6594790232cca4e0
This commit is contained in:
dan
2009-09-28 11:54:21 +00:00
parent 432cc5b9f3
commit 9277efa3d5
5 changed files with 171 additions and 55 deletions

View File

@@ -445,17 +445,19 @@ void sqlite3Update(
aRegIdx, (chngRowid?regOldRowid:0), 1, onError, addr, 0);
/* Do FK constraint checks. */
sqlite3FkCheck(pParse, pTab, pChanges, regOldRowid, regNewRowid);
sqlite3FkCheck(pParse, pTab, pChanges, regOldRowid, 0);
/* Delete the index entries associated with the current record. */
j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regOldRowid);
sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, aRegIdx);
/* If changing the record number, delete the old record. */
if( chngRowid ){
if( hasFK || chngRowid ){
sqlite3VdbeAddOp2(v, OP_Delete, iCur, 0);
}
sqlite3VdbeJumpHere(v, j1);
sqlite3FkCheck(pParse, pTab, pChanges, 0, regNewRowid);
/* Insert the new index entries and the new record. */
sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid, aRegIdx, 1, 0, 0);