1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-10 01:02:56 +03:00

Fixed behaviour of last_insert_rowid() with triggers and add last_statement_change_count() function that works correctly with triggers. (CVS 1251)

FossilOrigin-Name: 3383413a53bff0fef0765144de3bb9a298a5bb5c
This commit is contained in:
rdc
2004-02-20 22:53:38 +00:00
parent fcabd4641e
commit b0c374ffbb
12 changed files with 163 additions and 38 deletions

View File

@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.214 2004/02/20 14:50:58 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.215 2004/02/20 22:53:39 rdc Exp $
*/
#include "config.h"
#include "sqlite.h"
@@ -309,6 +309,24 @@ struct Db {
** are stored. If 1, then a file is created to hold those tables. If
** 2, then they are held in memory. 0 means use the default value in
** the TEMP_STORE macro.
**
** The sqlite.lastRowid records the last insert rowid generated by an
** insert statement. Inserts on views do not affect its value. Each
** trigger has its own context, so that lastRowid can be updated inside
** triggers as usual. The previous value will be restored once the trigger
** exits. Upon entering a before or instead of trigger, lastRowid is no
** longer (since after version 2.8.12) reset to -1.
**
** The sqlite.nChange does not count changes within triggers and keeps no
** context. It is reset at start of sqlite_exec.
** The sqlite.lsChange represents the number of changes made by the last
** insert, update, or delete statement. It remains constant throughout the
** length of a statement and is then updated by OP_SetCounts. It keeps a
** context stack just like lastRowid so that the count of changes
** within a trigger is not seen outside the trigger. Changes to views do not
** affect the value of lsChange.
** The sqlite.csChange keeps track of the number of current changes (since
** the last statement) and is used to update sqlite_lsChange.
*/
struct sqlite {
int nDb; /* Number of backends currently in use */
@@ -328,10 +346,12 @@ struct sqlite {
void *pCommitArg; /* Argument to xCommitCallback() */
int (*xCommitCallback)(void*);/* Invoked at every commit. */
Hash aFunc; /* All functions that can be in SQL exprs */
int lastRowid; /* ROWID of most recent insert */
int lastRowid; /* ROWID of most recent insert (see above) */
int priorNewRowid; /* Last randomly generated ROWID */
int magic; /* Magic number for detect library misuse */
int nChange; /* Number of rows changed */
int nChange; /* Number of rows changed (see above) */
int lsChange; /* Last statement change count (see above) */
int csChange; /* Current statement change count (see above) */
struct sqliteInitInfo { /* Information used during initialization */
int iDb; /* When back is being initialized */
int newTnum; /* Rootpage of table being initialized */
@@ -907,6 +927,13 @@ struct AuthContext {
Parse *pParse; /* The Parse structure */
};
/*
** Bitfield flags for P2 value in OP_PutIntKey and OP_Delete
*/
#define OPFLAG_NCHANGE 1 /* Set to update db->nChange */
#define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */
#define OPFLAG_CSCHANGE 4 /* Set to update db->csChange */
/*
* Each trigger present in the database schema is stored as an instance of
* struct Trigger.