mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Add the SQLITE_CHANGESETAPPLY_FKNOACTION flag to sqlite3session.h, for passing to sqlite3changeset_apply_v2() to cause all foreign key constraints to behave as if they were declared NO ACTION.
FossilOrigin-Name: fc9f82ea084159eaf3dd1757b96d17d1201b00c4e06455a7dcd8067172b25f28
This commit is contained in:
11
src/fkey.c
11
src/fkey.c
@@ -853,7 +853,7 @@ static int fkParentIsModified(
|
||||
*/
|
||||
static int isSetNullAction(Parse *pParse, FKey *pFKey){
|
||||
Parse *pTop = sqlite3ParseToplevel(pParse);
|
||||
if( pTop->pTriggerPrg ){
|
||||
if( pTop->pTriggerPrg && 0==(pTop->db->flags & SQLITE_FkNoAction) ){
|
||||
Trigger *p = pTop->pTriggerPrg->pTrigger;
|
||||
if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull)
|
||||
|| (p==pFKey->apTrigger[1] && pFKey->aAction[1]==OE_SetNull)
|
||||
@@ -1052,6 +1052,8 @@ void sqlite3FkCheck(
|
||||
}
|
||||
if( regOld!=0 ){
|
||||
int eAction = pFKey->aAction[aChange!=0];
|
||||
if( (db->flags & SQLITE_FkNoAction) ) eAction = OE_None;
|
||||
|
||||
fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1);
|
||||
/* If this is a deferred FK constraint, or a CASCADE or SET NULL
|
||||
** action applies, then any foreign key violations caused by
|
||||
@@ -1167,7 +1169,11 @@ int sqlite3FkRequired(
|
||||
/* Check if any parent key columns are being modified. */
|
||||
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
|
||||
if( fkParentIsModified(pTab, p, aChange, chngRowid) ){
|
||||
if( p->aAction[1]!=OE_None ) return 2;
|
||||
if( (pParse->db->flags & SQLITE_FkNoAction)==0
|
||||
&& p->aAction[1]!=OE_None
|
||||
){
|
||||
return 2;
|
||||
}
|
||||
bHaveFK = 1;
|
||||
}
|
||||
}
|
||||
@@ -1217,6 +1223,7 @@ static Trigger *fkActionTrigger(
|
||||
int iAction = (pChanges!=0); /* 1 for UPDATE, 0 for DELETE */
|
||||
|
||||
action = pFKey->aAction[iAction];
|
||||
if( (db->flags & SQLITE_FkNoAction) ) action = OE_None;
|
||||
if( action==OE_Restrict && (db->flags & SQLITE_DeferFKs) ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1845,6 +1845,7 @@ struct sqlite3 {
|
||||
/* the count using a callback. */
|
||||
#define SQLITE_CorruptRdOnly HI(0x00002) /* Prohibit writes due to error */
|
||||
#define SQLITE_ReadUncommit HI(0x00004) /* READ UNCOMMITTED in shared-cache */
|
||||
#define SQLITE_FkNoAction HI(0x00008) /* Treat all FK as NO ACTION */
|
||||
|
||||
/* Flags used only if debugging */
|
||||
#ifdef SQLITE_DEBUG
|
||||
|
||||
Reference in New Issue
Block a user