mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
More fixes for test cases.
FossilOrigin-Name: 85d9f23be1e8673dbda42e43b9b23332ada9225f
This commit is contained in:
30
manifest
30
manifest
@@ -1,5 +1,5 @@
|
||||
C Fix\ssome\sauthorization\scallback\sproblems.
|
||||
D 2009-08-31T08:22:46
|
||||
C More\sfixes\sfor\stest\scases.
|
||||
D 2009-08-31T15:27:28
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 73ddeec9dd10b85876c5c2ce1fdce627e1dcc7f8
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@@ -113,15 +113,15 @@ F src/build.c 212476dc971756e7f7429e677059fafc678afbd5
|
||||
F src/callback.c 9bc0ae998f15207d3115224979331c0aafc9bcc3
|
||||
F src/complete.c 5ad5c6cd4548211867c204c41a126d73a9fbcea0
|
||||
F src/date.c ab5f7137656652a48434d64f96bdcdc823bb23b3
|
||||
F src/delete.c 5b7c810b7e70e1c4abe1d2532f97003565b14b61
|
||||
F src/expr.c ac30c21eef64684b5709d01f06dc3fb72eee1fdc
|
||||
F src/delete.c 6b95963dabd558d45385e9b5be1fb4aa7ba7fa62
|
||||
F src/expr.c d95a040f0633d0f33b7c7123ad09463dcb828538
|
||||
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
|
||||
F src/func.c e536218d193b8d326aab91120bc4c6f28aa2b606
|
||||
F src/global.c 271952d199a8cc59d4ce840b3bbbfd2f30c8ba32
|
||||
F src/hash.c ebcaa921ffd9d86f7ea5ae16a0a29d1c871130a7
|
||||
F src/hash.h 35b216c13343d0b4f87d9f21969ac55ad72174e1
|
||||
F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb
|
||||
F src/insert.c 5b548c8070b492269f7dab999a0e2b4ae21516e2
|
||||
F src/insert.c 845f0f5aee678e131e3e944bb2ceea25b915bb1b
|
||||
F src/journal.c e00df0c0da8413ab6e1bb7d7cab5665d4a9000d0
|
||||
F src/legacy.c 303b4ffcf1ae652fcf5ef635846c563c254564f6
|
||||
F src/lempar.c 0c4d1ab0a5ef2b0381eb81a732c54f68f27a574d
|
||||
@@ -154,16 +154,16 @@ F src/pcache.c c92ffd4f3e1279b3766854c6d18b5bf4aac0d1fa
|
||||
F src/pcache.h 435ef324197f79391f9c92b71d7f92b548ad7a36
|
||||
F src/pcache1.c 211295a9ff6a5b30f1ca50516731a5cf3e9bf82c
|
||||
F src/pragma.c 6b1fa9f180d88b3f905cebd593ef6aef9334be43
|
||||
F src/prepare.c 49739b385c4cd0667cfa9941c41bf6d4f8edc157
|
||||
F src/prepare.c 1be1832c0dea54dda436f8269e51372b7d0660af
|
||||
F src/printf.c 508a1c59433353552b6553cba175eaa7331f8fc1
|
||||
F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
|
||||
F src/resolve.c 5909b3e2fb7e05fc2695cd250a4f672ea2dc1499
|
||||
F src/resolve.c 522d6804a058937db9a7c6fd50ec0845abfff84c
|
||||
F src/rowset.c c64dafba1f9fd876836c8db8682966b9d197eb1f
|
||||
F src/select.c 56ecb073e6f6696173ad80493aa14355225b6e53
|
||||
F src/shell.c db2643650b9268df89a4bedca3f1c6d9e786f1bb
|
||||
F src/sqlite.h.in 9d03ceaad971882482c158c0e3d39d361c2c18a1
|
||||
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
|
||||
F src/sqliteInt.h d87eb4976edacb68fb9b7557163ae0def733354b
|
||||
F src/sqliteInt.h 9036e5d0162426f94fa3989c537167586d731bef
|
||||
F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d
|
||||
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
|
||||
F src/table.c cc86ad3d6ad54df7c63a3e807b5783c90411a08d
|
||||
@@ -200,12 +200,12 @@ F src/test_tclvar.c 9e42fa59d3d2f064b7ab8628e7ab2dc8a9fe93d4
|
||||
F src/test_thread.c b8a1ab7ca1a632f18e8a361880d5d65eeea08eac
|
||||
F src/test_wsd.c 3ae5101de6cbfda2720152ab659ea84079719241
|
||||
F src/tokenize.c af8a56e6a50c5042fc305bfa796275e9bf26ff2b
|
||||
F src/trigger.c 2b0bdab4807cc0795afd8b7c88b503674994a43d
|
||||
F src/update.c 574464e0049eb289ab863c583f84474b5b76cd39
|
||||
F src/trigger.c d652d3a073d17bfa9bd9af88350206a81ef08d71
|
||||
F src/update.c 12ffd68c2f241c730d5e051eb29b23e90682ff8a
|
||||
F src/utf.c 3ca2c9461b8e942c68da28bfccd448663f536a6f
|
||||
F src/util.c efb5f8e533d4beef545cf765cab5f7920b4c75f9
|
||||
F src/vacuum.c 3fe0eebea6d2311c1c2ab2962887d11f7a4dcfb0
|
||||
F src/vdbe.c 5e9d870ec390fbc329f11424b121681e8da5d75c
|
||||
F src/vdbe.c 69890b64d5f7a5ef0e5f0479baa79cb65da4e018
|
||||
F src/vdbe.h 080fe6bc1264438becb8bf9b9f3c84074c336b78
|
||||
F src/vdbeInt.h 1291908344bcbaa8cf47de86d7108cb92c3a71a3
|
||||
F src/vdbeapi.c 8d5013ab6104be757c208a70ffb191cc27d2b688
|
||||
@@ -662,7 +662,7 @@ F test/tkt3918.test e6cdf6bfcfe9ba939d86a4238a9dc55d6eec5d42
|
||||
F test/tkt3922.test 022ace32c049e3964f68492c12eb803e8e4856d8
|
||||
F test/tkt3929.test 6a4c3baefb4e75127356b7d675b5df42c35c00d1
|
||||
F test/tkt3935.test e15261fedb9e30a4305a311da614a5d8e693c767
|
||||
F test/tkt3992.test 2ba939cc646eaa46761dfd55f975cad69bf4e254
|
||||
F test/tkt3992.test 88bd3d596b4b5ce4cbdf5b2f564d1321276ee097
|
||||
F test/tkt3997.test a335fa41ca3985660a139df7b734a26ef53284bd
|
||||
F test/tkt4018.test 7c2c9ba4df489c676a0a7a0e809a1fb9b2185bd1
|
||||
F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
|
||||
@@ -748,7 +748,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
|
||||
P 6e09e28751a7071969ef9f3445f4092d2c28f358
|
||||
R 81cbde85639275506b291e783c709236
|
||||
P 8a746fbfd51f70f56e25ade59df49d2dc03c131c
|
||||
R c8861b3298b0eed46e58ea3f1386cd62
|
||||
U dan
|
||||
Z 54e813eac61f6f88a2d6f341a5499c38
|
||||
Z 83f9b1037a455c2681b775be9c2fdcd7
|
||||
|
@@ -1 +1 @@
|
||||
8a746fbfd51f70f56e25ade59df49d2dc03c131c
|
||||
85d9f23be1e8673dbda42e43b9b23332ada9225f
|
@@ -391,12 +391,11 @@ void sqlite3DeleteFrom(
|
||||
** data required by the old.* references in the trigger bodies. */
|
||||
if( pTrigger ){
|
||||
u32 mask = 0; /* Mask of OLD.* columns in use */
|
||||
u32 dummy = 0; /* Unused. Initialized to prevent valgrind error. */
|
||||
pParse->nMem += pTab->nCol;
|
||||
|
||||
/* Open the pseudo-table used to store OLD if there are triggers. */
|
||||
sqlite3TriggerUses(
|
||||
pParse, pTrigger, TK_DELETE, 0, pTab, OE_Default, &mask, &dummy);
|
||||
mask = sqlite3TriggerOldmask(
|
||||
pParse, pTrigger, TK_DELETE, 0, pTab, OE_Default);
|
||||
|
||||
/* If the record is no longer present in the table, jump to the
|
||||
** next iteration of the loop through the contents of the fifo.
|
||||
|
@@ -2559,13 +2559,19 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
}
|
||||
|
||||
case TK_TRIGGER: {
|
||||
int iVal = pExpr->iTable * (pExpr->pTab->nCol+1) + 1 + pExpr->iColumn;
|
||||
Table *pTab = pExpr->pTab;
|
||||
int iVal = pExpr->iTable * (pTab->nCol+1) + 1 + pExpr->iColumn;
|
||||
sqlite3VdbeAddOp2(v, OP_Param, iVal, target);
|
||||
VdbeComment((v, "%s.%s -> $%d",
|
||||
(pExpr->iTable ? "new" : "old"),
|
||||
(pExpr->iColumn<0 ? "rowid" : pExpr->pTab->aCol[pExpr->iColumn].zName),
|
||||
target
|
||||
));
|
||||
if( pExpr->iColumn>=0
|
||||
&& pTab->aCol[pExpr->iColumn].affinity==SQLITE_AFF_REAL
|
||||
){
|
||||
sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -979,8 +979,7 @@ void sqlite3Insert(
|
||||
keyColumn>=0, 0, onError, endOfLoop, &isReplace
|
||||
);
|
||||
sqlite3CompleteInsertion(
|
||||
pParse, pTab, baseCur, regIns, aRegIdx, 0,
|
||||
(tmask&TRIGGER_AFTER) ? newIdx : -1, appendFlag, isReplace==0
|
||||
pParse, pTab, baseCur, regIns, aRegIdx, 0, appendFlag, isReplace==0
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1376,7 +1375,6 @@ void sqlite3CompleteInsertion(
|
||||
int regRowid, /* Range of content */
|
||||
int *aRegIdx, /* Register used by each index. 0 for unused indices */
|
||||
int isUpdate, /* True for UPDATE, False for INSERT */
|
||||
int newIdx, /* Index of NEW table for triggers. -1 if none */
|
||||
int appendBias, /* True if this is likely to be an append */
|
||||
int useSeekResult /* True to set the USESEEKRESULT flag on OP_[Idx]Insert */
|
||||
){
|
||||
|
@@ -676,9 +676,9 @@ static int sqlite3Prepare(
|
||||
sqlite3Error(db, rc, 0);
|
||||
}
|
||||
|
||||
while( pParse->pCodedTrigger ){
|
||||
CodedTrigger *pT = pParse->pCodedTrigger;
|
||||
pParse->pCodedTrigger = pT->pNext;
|
||||
while( pParse->pTriggerPrg ){
|
||||
TriggerPrg *pT = pParse->pTriggerPrg;
|
||||
pParse->pTriggerPrg = pT->pNext;
|
||||
sqlite3VdbeProgramDelete(db, pT->pProgram, 0);
|
||||
sqlite3DbFree(db, pT);
|
||||
}
|
||||
|
@@ -225,15 +225,12 @@ static int lookupName(
|
||||
*/
|
||||
if( zDb==0 && zTab!=0 && cnt==0 && pParse->pTriggerTab!=0 ){
|
||||
Table *pTab = 0;
|
||||
u32 *piColMask = 0;
|
||||
if( pParse->triggerOp!=TK_DELETE && sqlite3StrICmp("new",zTab) == 0 ){
|
||||
pExpr->iTable = 1;
|
||||
pTab = pParse->pTriggerTab;
|
||||
piColMask = &(pParse->newmask);
|
||||
}else if( pParse->triggerOp!=TK_INSERT && sqlite3StrICmp("old",zTab)==0 ){
|
||||
pExpr->iTable = 0;
|
||||
pTab = pParse->pTriggerTab;
|
||||
piColMask = &(pParse->oldmask);
|
||||
}
|
||||
|
||||
if( pTab ){
|
||||
@@ -246,13 +243,6 @@ static int lookupName(
|
||||
for(iCol=0; iCol<pTab->nCol; iCol++){
|
||||
Column *pCol = &pTab->aCol[iCol];
|
||||
if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
|
||||
testcase( iCol==31 );
|
||||
testcase( iCol==32 );
|
||||
if( iCol>=32 ){
|
||||
*piColMask = 0xffffffff;
|
||||
}else{
|
||||
*piColMask |= ((u32)1)<<iCol;
|
||||
}
|
||||
if( iCol==pTab->iPKey ){
|
||||
iCol = -1;
|
||||
}
|
||||
@@ -264,6 +254,10 @@ static int lookupName(
|
||||
cnt++;
|
||||
if( iCol<0 ){
|
||||
pExpr->affinity = SQLITE_AFF_INTEGER;
|
||||
}else if( pExpr->iTable==0 ){
|
||||
testcase( iCol==31 );
|
||||
testcase( iCol==32 );
|
||||
pParse->oldmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
|
||||
}
|
||||
pExpr->iColumn = iCol;
|
||||
pExpr->pTab = pTab;
|
||||
|
@@ -611,7 +611,7 @@ typedef struct StrAccum StrAccum;
|
||||
typedef struct Table Table;
|
||||
typedef struct TableLock TableLock;
|
||||
typedef struct Token Token;
|
||||
typedef struct TriggerStack TriggerStack;
|
||||
typedef struct TriggerPrg TriggerPrg;
|
||||
typedef struct TriggerStep TriggerStep;
|
||||
typedef struct Trigger Trigger;
|
||||
typedef struct UnpackedRecord UnpackedRecord;
|
||||
@@ -1577,7 +1577,8 @@ struct Expr {
|
||||
*********************************************************************/
|
||||
|
||||
int iTable; /* TK_COLUMN: cursor number of table holding column
|
||||
** TK_REGISTER: register number */
|
||||
** TK_REGISTER: register number
|
||||
** TK_TRIGGER: 1 -> new, 0 -> old */
|
||||
i16 iColumn; /* TK_COLUMN: column index. -1 for rowid */
|
||||
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
|
||||
i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
|
||||
@@ -2016,14 +2017,25 @@ struct AutoincInfo {
|
||||
# define SQLITE_N_COLCACHE 10
|
||||
#endif
|
||||
|
||||
typedef struct CodedTrigger CodedTrigger;
|
||||
struct CodedTrigger {
|
||||
SubProgram *pProgram;
|
||||
Trigger *pTrigger;
|
||||
u32 oldmask; /* Mask of old.* columns accessed */
|
||||
u32 newmask; /* Mask of new.* columns accessed */
|
||||
/*
|
||||
** At least one instance of the following structure is created for each
|
||||
** trigger that may be fired while parsing an INSERT, UPDATE or DELETE
|
||||
** statement. All such objects are stored in the linked list headed at
|
||||
** Parse.pTriggerPrg and deleted once statement compilation has been
|
||||
** completed.
|
||||
**
|
||||
** A Vdbe sub-program that implements the body and WHEN clause of trigger
|
||||
** TriggerPrg.pTrigger, assuming a default ON CONFLICT clause of
|
||||
** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable.
|
||||
** The Parse.pTriggerPrg list never contains two entries with the same
|
||||
** values for both pTrigger and orconf.
|
||||
*/
|
||||
struct TriggerPrg {
|
||||
Trigger *pTrigger; /* Trigger this program was coded from */
|
||||
int orconf; /* Default ON CONFLICT policy */
|
||||
CodedTrigger *pNext;
|
||||
SubProgram *pProgram; /* Program implementing pTrigger/orconf */
|
||||
u32 oldmask; /* Mask of old.* columns accessed */
|
||||
TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -2112,9 +2124,6 @@ struct Parse {
|
||||
const char *zTail; /* All SQL text past the last semicolon parsed */
|
||||
Table *pNewTable; /* A table being constructed by CREATE TABLE */
|
||||
Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
|
||||
#if 0
|
||||
TriggerStack *trigStack; /* Trigger actions being coded */
|
||||
#endif
|
||||
const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
Token sArg; /* Complete text of a module argument */
|
||||
@@ -2124,7 +2133,7 @@ struct Parse {
|
||||
#endif
|
||||
int nHeight; /* Expression tree height of current sub-select */
|
||||
Table *pZombieTab; /* List of Table objects to delete after code gen */
|
||||
CodedTrigger *pCodedTrigger; /* Linked list of coded triggers */
|
||||
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
|
||||
};
|
||||
|
||||
#ifdef SQLITE_OMIT_VIRTUALTABLE
|
||||
@@ -2241,45 +2250,6 @@ struct TriggerStep {
|
||||
TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
|
||||
};
|
||||
|
||||
/*
|
||||
* An instance of struct TriggerStack stores information required during code
|
||||
* generation of a single trigger program. While the trigger program is being
|
||||
* coded, its associated TriggerStack instance is pointed to by the
|
||||
* "pTriggerStack" member of the Parse structure.
|
||||
*
|
||||
* The pTab member points to the table that triggers are being coded on. The
|
||||
* newIdx member contains the index of the vdbe cursor that points at the temp
|
||||
* table that stores the new.* references. If new.* references are not valid
|
||||
* for the trigger being coded (for example an ON DELETE trigger), then newIdx
|
||||
* is set to -1. The oldIdx member is analogous to newIdx, for old.* references.
|
||||
*
|
||||
* The ON CONFLICT policy to be used for the trigger program steps is stored
|
||||
* as the orconf member. If this is OE_Default, then the ON CONFLICT clause
|
||||
* specified for individual triggers steps is used.
|
||||
*
|
||||
* struct TriggerStack has a "pNext" member, to allow linked lists to be
|
||||
* constructed. When coding nested triggers (triggers fired by other triggers)
|
||||
* each nested trigger stores its parent trigger's TriggerStack as the "pNext"
|
||||
* pointer. Once the nested trigger has been coded, the pNext value is restored
|
||||
* to the pTriggerStack member of the Parse stucture and coding of the parent
|
||||
* trigger continues.
|
||||
*
|
||||
* Before a nested trigger is coded, the linked list pointed to by the
|
||||
* pTriggerStack is scanned to ensure that the trigger is not about to be coded
|
||||
* recursively. If this condition is detected, the nested trigger is not coded.
|
||||
*/
|
||||
struct TriggerStack {
|
||||
Table *pTab; /* Table that triggers are currently being coded on */
|
||||
int newIdx; /* Index of vdbe cursor to "new" temp table */
|
||||
int oldIdx; /* Index of vdbe cursor to "old" temp table */
|
||||
u32 newColMask;
|
||||
u32 oldColMask;
|
||||
int orconf; /* Current orconf policy */
|
||||
int ignoreJump; /* where to jump to for a RAISE(IGNORE) */
|
||||
Trigger *pTrigger; /* The trigger currently being coded */
|
||||
TriggerStack *pNext; /* Next trigger down on the trigger stack */
|
||||
};
|
||||
|
||||
/*
|
||||
** The following structure contains information used by the sqliteFix...
|
||||
** routines as they walk the parse tree to make database references
|
||||
@@ -2674,7 +2644,7 @@ void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int*);
|
||||
int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int);
|
||||
void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int,
|
||||
int*,int,int,int,int,int*);
|
||||
void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int,int,int);
|
||||
void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int);
|
||||
int sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
|
||||
void sqlite3BeginWriteOperation(Parse*, int, int);
|
||||
Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
|
||||
@@ -2721,7 +2691,7 @@ void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
|
||||
TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*);
|
||||
void sqlite3DeleteTrigger(sqlite3*, Trigger*);
|
||||
void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
|
||||
void sqlite3TriggerUses(Parse*,Trigger*,int,ExprList*,Table*,int,u32*,u32*);
|
||||
u32 sqlite3TriggerOldmask(Parse*,Trigger*,int,ExprList*,Table*,int);
|
||||
#else
|
||||
# define sqlite3TriggersExist(B,C,D,E,F) 0
|
||||
# define sqlite3DeleteTrigger(A,B)
|
||||
|
105
src/trigger.c
105
src/trigger.c
@@ -681,7 +681,6 @@ static int codeTriggerProgram(
|
||||
assert( pParse->pRoot );
|
||||
assert( pStep!=0 );
|
||||
assert( v!=0 );
|
||||
/* sqlite3VdbeAddOp2(v, OP_ContextPush, 0, 0); */
|
||||
while( pStep ){
|
||||
/* Figure out the ON CONFLICT policy that will be used for this step
|
||||
** of the trigger program. If the statement that caused this trigger
|
||||
@@ -698,10 +697,6 @@ static int codeTriggerProgram(
|
||||
*/
|
||||
pParse->orconf = (orconfin==OE_Default)?pStep->orconf:orconfin;
|
||||
|
||||
if( pStep->op!=TK_SELECT ){
|
||||
sqlite3VdbeAddOp1(v, OP_ResetCount, 0);
|
||||
}
|
||||
|
||||
switch( pStep->op ){
|
||||
case TK_UPDATE: {
|
||||
sqlite3Update(pParse,
|
||||
@@ -743,7 +738,6 @@ static int codeTriggerProgram(
|
||||
}
|
||||
pStep = pStep->pNext;
|
||||
}
|
||||
/* sqlite3VdbeAddOp2(v, OP_ContextPop, 0, 0); */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -782,7 +776,7 @@ static void transferParseError(Parse *pTo, Parse *pFrom){
|
||||
}
|
||||
}
|
||||
|
||||
static CodedTrigger *codeRowTrigger(
|
||||
static TriggerPrg *codeRowTrigger(
|
||||
Parse *pRoot, /* Root parse context */
|
||||
Parse *pParse, /* Current parse context */
|
||||
Trigger *pTrigger, /* Trigger to code */
|
||||
@@ -791,28 +785,27 @@ static CodedTrigger *codeRowTrigger(
|
||||
int orconf
|
||||
){
|
||||
sqlite3 *db = pParse->db;
|
||||
CodedTrigger *pC;
|
||||
TriggerPrg *pPrg;
|
||||
Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
|
||||
Vdbe *v; /* Temporary VM */
|
||||
AuthContext sContext; /* Auth context for sub-vdbe */
|
||||
NameContext sNC; /* Name context for sub-vdbe */
|
||||
SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
|
||||
Parse *pSubParse; /* Parse context for sub-vdbe */
|
||||
int iEndTrigger = 0; /* Label to jump to if WHEN is false */
|
||||
|
||||
pC = sqlite3DbMallocZero(db, sizeof(CodedTrigger));
|
||||
if( !pC ) return 0;
|
||||
pC->pNext = pRoot->pCodedTrigger;
|
||||
pRoot->pCodedTrigger = pC;
|
||||
pC->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
|
||||
pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
|
||||
if( !pPrg ) return 0;
|
||||
pPrg->pNext = pRoot->pTriggerPrg;
|
||||
pRoot->pTriggerPrg = pPrg;
|
||||
pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
|
||||
if( !pProgram ) return 0;
|
||||
pProgram->nRef = 1;
|
||||
pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
|
||||
if( !pSubParse ) return 0;
|
||||
|
||||
pC->pProgram = pProgram;
|
||||
pC->pTrigger = pTrigger;
|
||||
pC->orconf = orconf;
|
||||
pPrg->pProgram = pProgram;
|
||||
pPrg->pTrigger = pTrigger;
|
||||
pPrg->orconf = orconf;
|
||||
|
||||
memset(&sNC, 0, sizeof(sNC));
|
||||
sNC.pParse = pSubParse;
|
||||
@@ -865,8 +858,7 @@ static CodedTrigger *codeRowTrigger(
|
||||
pProgram->nMem = pSubParse->nMem;
|
||||
pProgram->nCsr = pSubParse->nTab;
|
||||
pProgram->token = (void *)pTrigger;
|
||||
pC->oldmask = pSubParse->oldmask;
|
||||
pC->newmask = pSubParse->newmask;
|
||||
pPrg->oldmask = pSubParse->oldmask;
|
||||
sqlite3VdbeDelete(v);
|
||||
|
||||
while( pSubParse->pAinc ){
|
||||
@@ -877,36 +869,36 @@ static CodedTrigger *codeRowTrigger(
|
||||
}
|
||||
sqlite3StackFree(db, pSubParse);
|
||||
|
||||
return pC;
|
||||
return pPrg;
|
||||
}
|
||||
|
||||
static CodedTrigger *getRowTrigger(
|
||||
static TriggerPrg *getRowTrigger(
|
||||
Parse *pParse,
|
||||
Trigger *pTrigger, /* Trigger to code */
|
||||
int op, /* One of TK_UPDATE, TK_INSERT, TK_DELETE */
|
||||
Table *pTab, /* The table to code triggers from */
|
||||
int orconf
|
||||
){
|
||||
CodedTrigger *pC;
|
||||
TriggerPrg *pPrg;
|
||||
Parse *pRoot = pParse;
|
||||
|
||||
/* It may be that this trigger has already been coded (or is in the
|
||||
** process of being coded). If this is the case, then an entry with
|
||||
** a matching CodedTrigger.pTrigger field will be present somewhere
|
||||
** in the Parse.pCodedTrigger list. Search for such an entry. */
|
||||
** a matching TriggerPrg.pTrigger field will be present somewhere
|
||||
** in the Parse.pTriggerPrg list. Search for such an entry. */
|
||||
if( pParse->pRoot ){
|
||||
pRoot = pParse->pRoot;
|
||||
}
|
||||
for(pC=pRoot->pCodedTrigger;
|
||||
pC && (pC->pTrigger!=pTrigger || pC->orconf!=orconf);
|
||||
pC=pC->pNext
|
||||
for(pPrg=pRoot->pTriggerPrg;
|
||||
pPrg && (pPrg->pTrigger!=pTrigger || pPrg->orconf!=orconf);
|
||||
pPrg=pPrg->pNext
|
||||
);
|
||||
|
||||
if( !pC ){
|
||||
pC = codeRowTrigger(pRoot, pParse, pTrigger, op, pTab, orconf);
|
||||
if( !pPrg ){
|
||||
pPrg = codeRowTrigger(pRoot, pParse, pTrigger, op, pTab, orconf);
|
||||
}
|
||||
|
||||
return pC;
|
||||
return pPrg;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -969,45 +961,64 @@ void sqlite3CodeRowTrigger(
|
||||
&& checkColumnOverlap(p->pColumns,pChanges)
|
||||
){
|
||||
Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */
|
||||
CodedTrigger *pC;
|
||||
pC = getRowTrigger(pParse, p, op, pTab, orconf);
|
||||
assert( pC || pParse->nErr || pParse->db->mallocFailed );
|
||||
TriggerPrg *pPrg;
|
||||
pPrg = getRowTrigger(pParse, p, op, pTab, orconf);
|
||||
assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
|
||||
|
||||
/* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
|
||||
** is a pointer to the sub-vdbe containing the trigger program. */
|
||||
if( pC ){
|
||||
if( pPrg ){
|
||||
sqlite3VdbeAddOp3(v, OP_Program, oldIdx, ignoreJump, ++pParse->nMem);
|
||||
pC->pProgram->nRef++;
|
||||
sqlite3VdbeChangeP4(v, -1, (const char *)pC->pProgram, P4_SUBPROGRAM);
|
||||
pPrg->pProgram->nRef++;
|
||||
sqlite3VdbeChangeP4(v, -1, (const char *)pPrg->pProgram, P4_SUBPROGRAM);
|
||||
VdbeComment((v, "Call: %s.%s", p->zName, onErrorText(orconf)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sqlite3TriggerUses(
|
||||
/*
|
||||
** Triggers fired by UPDATE or DELETE statements may access values stored
|
||||
** in the old.* pseudo-table. This function returns a 32-bit bitmask
|
||||
** indicating which columns of the old.* table actually are used by
|
||||
** triggers. This information may be used by the caller to avoid having
|
||||
** to load the entire old.* record into memory when executing an UPDATE
|
||||
** or DELETE command.
|
||||
**
|
||||
** Bit 0 of the returned mask is set if the left-most column of the
|
||||
** table may be accessed using an old.<col> reference. Bit 1 is set if
|
||||
** the second leftmost column value is required, and so on. If there
|
||||
** are more than 32 columns in the table, and at least one of the columns
|
||||
** with an index greater than 32 may be accessed, 0xffffffff is returned.
|
||||
**
|
||||
** It is not possible to determine if the old.rowid column is accessed
|
||||
** by triggers. The caller must always assume that it is.
|
||||
**
|
||||
** There is no equivalent function for new.* references.
|
||||
*/
|
||||
u32 sqlite3TriggerOldmask(
|
||||
Parse *pParse, /* Parse context */
|
||||
Trigger *pTrigger, /* List of triggers on table pTab */
|
||||
int op, /* One of TK_UPDATE, TK_INSERT, TK_DELETE */
|
||||
int op, /* Either TK_UPDATE or TK_DELETE */
|
||||
ExprList *pChanges, /* Changes list for any UPDATE OF triggers */
|
||||
Table *pTab, /* The table to code triggers from */
|
||||
int orconf, /* Default ON CONFLICT policy for trigger steps */
|
||||
u32 *piOldColMask, /* OUT: Mask of columns used from the OLD.* table */
|
||||
u32 *piNewColMask /* OUT: Mask of columns used from the NEW.* table */
|
||||
int orconf /* Default ON CONFLICT policy for trigger steps */
|
||||
){
|
||||
u32 mask = 0;
|
||||
Trigger *p;
|
||||
assert(op==TK_UPDATE || op==TK_INSERT || op==TK_DELETE);
|
||||
|
||||
assert(op==TK_UPDATE || op==TK_DELETE);
|
||||
for(p=pTrigger; p; p=p->pNext){
|
||||
if( p->op==op && checkColumnOverlap(p->pColumns,pChanges) ){
|
||||
CodedTrigger *pC;
|
||||
pC = getRowTrigger(pParse, p, op, pTab, orconf);
|
||||
if( pC ){
|
||||
*piOldColMask |= pC->oldmask;
|
||||
*piNewColMask |= pC->newmask;
|
||||
TriggerPrg *pPrg;
|
||||
pPrg = getRowTrigger(pParse, p, op, pTab, orconf);
|
||||
if( pPrg ){
|
||||
mask |= pPrg->oldmask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
|
||||
|
44
src/update.c
44
src/update.c
@@ -120,8 +120,7 @@ void sqlite3Update(
|
||||
int isView; /* Trying to update a view */
|
||||
Trigger *pTrigger; /* List of triggers on pTab, if required */
|
||||
#endif
|
||||
u32 old_col_mask = 0; /* Mask of OLD.* columns in use */
|
||||
u32 new_col_mask = 0; /* Mask of NEW.* columns in use */
|
||||
u32 oldmask = 0; /* Mask of OLD.* columns in use */
|
||||
|
||||
/* Register Allocations */
|
||||
int regRowCount = 0; /* A count of rows changed */
|
||||
@@ -290,10 +289,9 @@ void sqlite3Update(
|
||||
sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
|
||||
}
|
||||
|
||||
/* If there are any triggers, set old_col_mask and new_col_mask. */
|
||||
sqlite3TriggerUses(pParse,
|
||||
pTrigger, TK_UPDATE, pChanges, pTab, onError, &old_col_mask, &new_col_mask
|
||||
);
|
||||
/* If there are any triggers, set oldmask and new_col_mask. */
|
||||
oldmask = sqlite3TriggerOldmask(
|
||||
pParse, pTrigger, TK_UPDATE, pChanges, pTab, onError);
|
||||
|
||||
/* If we are trying to update a view, realize that view into
|
||||
** a ephemeral table.
|
||||
@@ -384,7 +382,7 @@ void sqlite3Update(
|
||||
** with the required old.* column data. */
|
||||
if( pTrigger ){
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( aXRef[i]<0 || old_col_mask==0xffffffff || (old_col_mask & (1<<i)) ){
|
||||
if( aXRef[i]<0 || oldmask==0xffffffff || (oldmask & (1<<i)) ){
|
||||
sqlite3VdbeAddOp3(v, OP_Column, iCur, i, regOld+i);
|
||||
sqlite3ColumnDefault(v, pTab, i, regOld+i);
|
||||
}else{
|
||||
@@ -423,23 +421,14 @@ void sqlite3Update(
|
||||
}
|
||||
}
|
||||
|
||||
/* If this is not a view, create the record that will be inserted into
|
||||
** the table (assuming no constraint checks fail). A side effect of
|
||||
** creating the record is applying affinity transformations to the
|
||||
** array of registers populated by the block above. This needs to be
|
||||
** done before the BEFORE triggers are fired. */
|
||||
#if 0
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp3(v, OP_MakeRecord, regNew, pTab->nCol, regRec);
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
sqlite3ExprCacheAffinityChange(pParse, regNew, pTab->nCol);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Fire any BEFORE UPDATE triggers. This happens before constraints are
|
||||
** verified. One could argue that this is wrong. */
|
||||
if( pTrigger ){
|
||||
sqlite3VdbeAddOp2(v, OP_Affinity, regNew, pTab->nCol);
|
||||
sqlite3TableAffinityStr(v, pTab);
|
||||
sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
|
||||
TRIGGER_BEFORE, pTab, -1, regOldRowid, onError, addr);
|
||||
}
|
||||
|
||||
if( !isView ){
|
||||
|
||||
@@ -458,20 +447,7 @@ void sqlite3Update(
|
||||
sqlite3VdbeJumpHere(v, j1);
|
||||
|
||||
/* Insert the new index entries and the new record. */
|
||||
sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid, aRegIdx, 1, -1, 0, 0);
|
||||
|
||||
#if 0
|
||||
for(i=0; i<nIdx; i++){
|
||||
if( aRegIdx[i] ){
|
||||
sqlite3VdbeAddOp2(v, OP_IdxInsert, iCur+1+i, aRegIdx[i]);
|
||||
}
|
||||
}
|
||||
sqlite3VdbeAddOp3(v, OP_Insert, iCur, regRec, regNewRowid);
|
||||
if( !pParse->nested ){
|
||||
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
|
||||
sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_ISUPDATE);
|
||||
}
|
||||
#endif
|
||||
sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid, aRegIdx, 1, 0, 0);
|
||||
}
|
||||
|
||||
/* Increment the row counter
|
||||
|
@@ -847,15 +847,23 @@ case OP_HaltIfNull: { /* in3 */
|
||||
*/
|
||||
case OP_Halt: {
|
||||
if( pOp->p1==SQLITE_OK && p->pFrame ){
|
||||
/* Halt the sub-program. Return control to the parent frame. */
|
||||
VdbeFrame *pFrame = p->pFrame;
|
||||
p->pFrame = pFrame->pParent;
|
||||
p->nFrame--;
|
||||
sqlite3VdbeSetChanges(db, p->nChange);
|
||||
pc = sqlite3VdbeFrameRestore(pFrame);
|
||||
if( pOp->p2==OE_Ignore ){
|
||||
/* Instruction pc is the OP_Program that invoked the sub-program
|
||||
** currently being halted. If the p2 instruction of this OP_Halt
|
||||
** instruction is set to OE_Ignore, then the sub-program is throwing
|
||||
** an IGNORE exception. In this case jump to the address specified
|
||||
** as the p2 of the calling OP_Program. */
|
||||
pc = p->aOp[pc].p2-1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
p->rc = pOp->p1;
|
||||
p->errorAction = (u8)pOp->p2;
|
||||
p->pc = pc;
|
||||
@@ -4846,6 +4854,7 @@ case OP_Program: { /* jump */
|
||||
pFrame->pParent = p->pFrame;
|
||||
pFrame->lastRowid = db->lastRowid;
|
||||
pFrame->nChange = p->nChange;
|
||||
p->nChange = 0;
|
||||
p->pFrame = pFrame;
|
||||
p->aMem = &VdbeFrameMem(pFrame)[-1];
|
||||
p->nMem = pFrame->nChildMem;
|
||||
|
@@ -29,7 +29,6 @@ do_test tkt3992-1.1 {
|
||||
INSERT INTO parameters2(mountcnt, version) VALUES(1, 1.0);
|
||||
}
|
||||
} {}
|
||||
puts [execsql { SELECT *,typeof(mountcnt),typeof(version) FROM parameters1 }]
|
||||
|
||||
do_test tkt3992-1.2 {
|
||||
execsql {
|
||||
@@ -39,12 +38,8 @@ do_test tkt3992-1.2 {
|
||||
} {2 1.0}
|
||||
|
||||
do_test tkt3992-1.3 {
|
||||
explain { UPDATE parameters2 SET mountcnt = mountcnt + 1 }
|
||||
breakpoint
|
||||
execsql {
|
||||
pragma vdbe_trace = 1;
|
||||
UPDATE parameters2 SET mountcnt = mountcnt + 1;
|
||||
pragma vdbe_trace = 0;
|
||||
SELECT * FROM parameters2;
|
||||
}
|
||||
} {2 1.0}
|
||||
|
Reference in New Issue
Block a user