Simplifications and clarification to update callback handling in the
OP_Delete and OP_Insert opcodes.
FossilOrigin-Name: 47887ef89ed60ddb869d65e0957c1c4b2115f169
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 8500403..d789cc0 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -2927,9 +2927,6 @@
/*
** Bitfield flags for P5 value in various opcodes.
-**
-** Note that the values for ISNOOP and LENGTHARG are the same. But as
-** those bits are never used on the same opcode, the overlap is harmless.
*/
#define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
/* Also used in P2 (not P5) of OP_Delete */
@@ -2938,7 +2935,9 @@
#define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
#define OPFLAG_APPEND 0x08 /* This is likely to be an append */
#define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
+#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
#define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */
+#endif
#define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
#define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
#define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
diff --git a/src/vdbe.c b/src/vdbe.c
index 787d2b7..84a5087 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -4317,6 +4317,7 @@
assert( pC->iDb>=0 );
zDb = db->aDb[pC->iDb].zName;
pTab = pOp->p4.pTab;
+ assert( HasRowid(pTab) );
op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
}else{
pTab = 0; /* Not needed. Silence a comiler warning. */
@@ -4328,7 +4329,6 @@
if( db->xPreUpdateCallback
&& pOp->p4type==P4_TABLE
&& !(pOp->p5 & OPFLAG_ISUPDATE)
- && HasRowid(pTab)
){
sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, iKey, pOp->p2);
}
@@ -4357,7 +4357,7 @@
/* Invoke the update-hook if required. */
if( rc ) goto abort_due_to_error;
- if( db->xUpdateCallback && op && HasRowid(pTab) ){
+ if( db->xUpdateCallback && op ){
db->xUpdateCallback(db->pUpdateArg, op, zDb, pTab->zName, iKey);
}
break;
@@ -4428,11 +4428,12 @@
** of p4.pTab. Finally, if p5 is true, indicating that this cursor was
** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
** VdbeCursor.movetoTarget to the current rowid. */
- if( pOp->p4.pTab && HAS_UPDATE_HOOK(db) ){
+ if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
assert( pC->iDb>=0 );
+ assert( pOp->p4.pTab!=0 );
zDb = db->aDb[pC->iDb].zName;
pTab = pOp->p4.pTab;
- if( pOp->p5 && pC->isTable ){
+ if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
sqlite3BtreeKeySize(pC->uc.pCursor, &pC->movetoTarget);
}
}else{
@@ -4450,9 +4451,8 @@
pOp->p3
);
}
-#endif
-
if( opflags & OPFLAG_ISNOOP ) break;
+#endif
/* Only flags that can be set are SAVEPOISTION and AUXDELETE */
assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_AUXDELETE))==0 );
@@ -4480,7 +4480,7 @@
/* Invoke the update-hook if required. */
if( opflags & OPFLAG_NCHANGE ){
p->nChange++;
- if( rc==SQLITE_OK && db->xUpdateCallback && HasRowid(pTab) ){
+ if( db->xUpdateCallback && HasRowid(pTab) ){
db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, pTab->zName,
pC->movetoTarget);
assert( pC->iDb>=0 );