1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

New opcode OP_ChngCntRow used to output the result of PRAGMA change_count.

Only this new opcode, and not OP_ResultRow, checks for foreign key errors.
Faster performance, and now also works with RETURNING.

FossilOrigin-Name: 154fc2b15465c7c92a1af0a93851421aec42a81bab54840a9701f2c78068e14e
This commit is contained in:
drh
2021-01-31 15:50:36 +00:00
parent 662fe79647
commit 18e5607211
6 changed files with 33 additions and 22 deletions

View File

@@ -1445,6 +1445,26 @@ case OP_IntCopy: { /* out2 */
break;
}
/* Opcode: ChngCntRow P1 P2 * * *
** Synopsis: output=r[P1]
**
** Output value in register P1 as the chance count for a DML statement,
** due to the "PRAGMA count_changes=ON" setting. Or, if there was a
** foreign key error in the statement, trigger the error now.
**
** This opcode is a variant of OP_ResultRow that checks the foreign key
** immediate constraint count and throws an error if the count is
** non-zero. The P2 opcode must be 1.
*/
case OP_ChngCntRow: {
assert( pOp->p2==1 );
if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){
goto abort_due_to_error;
}
/* Fall through to the next case, OP_String */
/* no break */ deliberate_fall_through
}
/* Opcode: ResultRow P1 P2 * * *
** Synopsis: output=r[P1@P2]
**
@@ -1461,15 +1481,6 @@ case OP_ResultRow: {
assert( pOp->p1>0 );
assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
/* If this statement has violated immediate foreign key constraints, do
** not return the number of rows modified. And do not RELEASE the statement
** transaction. It needs to be rolled back. */
if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
assert( db->flags&SQLITE_CountRows );
assert( p->usesStmtJournal );
goto abort_due_to_error;
}
/* Invalidate all ephemeral cursor row caches */
p->cacheCtr = (p->cacheCtr + 2)|1;