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

When ALTER TABLE RENAME TO is used to change the name of a table that is the parent table of a foreign key constraint, modify that foreign key constraint to use the new table name.

FossilOrigin-Name: b4a10c39e726dc190e9597e382baddc034294114
This commit is contained in:
dan
2009-09-26 17:51:48 +00:00
parent 0ff297eaa7
commit 432cc5b9f3
6 changed files with 207 additions and 24 deletions

View File

@@ -517,7 +517,7 @@ static void fkScanChildren(
** NULL pointer (as there are no FK constraints for which t2 is the parent
** table).
*/
static FKey *fkRefering(Table *pTab){
FKey *sqlite3FkReferences(Table *pTab){
int nName = sqlite3Strlen30(pTab->zName);
return (FKey *)sqlite3HashFind(&pTab->pSchema->fkeyHash, pTab->zName, nName);
}
@@ -645,7 +645,7 @@ void sqlite3FkCheck(
}
/* Loop through all the foreign key constraints that refer to this table */
for(pFKey = fkRefering(pTab); pFKey; pFKey=pFKey->pNextTo){
for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
int iGoto; /* Address of OP_Goto instruction */
Index *pIdx = 0; /* Foreign key index for pFKey */
SrcList *pSrc;
@@ -740,7 +740,7 @@ u32 sqlite3FkOldmask(
for(p=pTab->pFKey; p; p=p->pNextFrom){
for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
}
for(p=fkRefering(pTab); p; p=p->pNextTo){
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
Index *pIdx = 0;
locateFkeyIndex(0, pTab, p, &pIdx, 0);
if( pIdx ){
@@ -767,7 +767,7 @@ int sqlite3FkRequired(
ExprList *pChanges /* Non-NULL for UPDATE operations */
){
if( pParse->db->flags&SQLITE_ForeignKeys ){
if( fkRefering(pTab) || pTab->pFKey ) return 1;
if( sqlite3FkReferences(pTab) || pTab->pFKey ) return 1;
}
return 0;
}
@@ -968,7 +968,7 @@ void sqlite3FkActions(
** trigger sub-program. */
if( pParse->db->flags&SQLITE_ForeignKeys ){
FKey *pFKey; /* Iterator variable */
for(pFKey = fkRefering(pTab); pFKey; pFKey=pFKey->pNextTo){
for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
Trigger *pAction = fkActionTrigger(pParse, pTab, pFKey, pChanges);
if( pAction ){
sqlite3CodeRowTriggerDirect(pParse, pAction, pTab, regOld, OE_Abort, 0);