aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/delete.c8
-rw-r--r--src/expr.c26
-rw-r--r--src/insert.c8
-rw-r--r--src/parse.y17
-rw-r--r--src/sqliteInt.h6
-rw-r--r--src/tokenize.c3
-rw-r--r--src/trigger.c22
-rw-r--r--src/update.c6
-rw-r--r--src/vdbe.c6
9 files changed, 76 insertions, 26 deletions
diff --git a/src/delete.c b/src/delete.c
index f48a528eb..779b572cc 100644
--- a/src/delete.c
+++ b/src/delete.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle DELETE FROM statements.
**
-** $Id: delete.c,v 1.36 2002/05/24 02:04:33 drh Exp $
+** $Id: delete.c,v 1.37 2002/06/11 02:25:41 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -237,7 +237,8 @@ void sqliteDeleteFrom(
sqliteVdbeAddOp(v, OP_Rewind, oldIdx, 0);
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_BEFORE, pTab, -1,
- oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default);
+ oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
+ addr);
}
/* Open cursors for the table we are deleting from and all its
@@ -271,7 +272,8 @@ void sqliteDeleteFrom(
}
sqliteVdbeAddOp(v, OP_Close, base, 0);
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1,
- oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default);
+ oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
+ addr);
}
/* End of the delete loop */
diff --git a/src/expr.c b/src/expr.c
index fdd1ad428..2d017aa52 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
-** $Id: expr.c,v 1.70 2002/06/09 01:16:01 drh Exp $
+** $Id: expr.c,v 1.71 2002/06/11 02:25:41 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -204,7 +204,7 @@ SrcList *sqliteSrcListDup(SrcList *p){
if( pNew==0 ) return 0;
pNew->nSrc = p->nSrc;
pNew->a = sqliteMalloc( p->nSrc*sizeof(p->a[0]) );
- if( pNew->a==0 ) return 0;
+ if( pNew->a==0 && p->nSrc != 0 ) return 0;
for(i=0; i<p->nSrc; i++){
pNew->a[i].zName = sqliteStrDup(p->a[i].zName);
pNew->a[i].zAlias = sqliteStrDup(p->a[i].zAlias);
@@ -1014,6 +1014,28 @@ void sqliteExprCode(Parse *pParse, Expr *pExpr){
sqliteVdbeAddOp(v, OP_String, 0, 0);
}
sqliteVdbeResolveLabel(v, expr_end_label);
+ break;
+ }
+ case TK_RAISE: {
+ if( !pParse->trigStack ){
+ sqliteSetNString(&pParse->zErrMsg,
+ "RAISE() may only be used within a trigger-program", -1, 0);
+ pParse->nErr++;
+ return;
+ }
+ if( pExpr->iColumn == OE_Rollback ||
+ pExpr->iColumn == OE_Abort ||
+ pExpr->iColumn == OE_Fail ){
+ char * msg = sqliteStrNDup(pExpr->token.z, pExpr->token.n);
+ sqliteVdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn);
+ sqliteDequote(msg);
+ sqliteVdbeChangeP3(v, -1, msg, 0);
+ sqliteFree(msg);
+ } else {
+ assert( pExpr->iColumn == OE_Ignore );
+ sqliteVdbeAddOp(v, OP_Goto, 0, pParse->trigStack->ignoreJump);
+ sqliteVdbeChangeP3(v, -1, "(IGNORE jump)", -1);
+ }
}
break;
}
diff --git a/src/insert.c b/src/insert.c
index 7032da349..73ed0563a 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
-** $Id: insert.c,v 1.60 2002/06/06 18:54:40 drh Exp $
+** $Id: insert.c,v 1.61 2002/06/11 02:25:42 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -235,6 +235,7 @@ void sqliteInsert(
iCont = sqliteVdbeCurrentAddr(v);
}
+ endOfLoop = sqliteVdbeMakeLabel(v);
if( row_triggers_exist ){
/* build the new.* reference row */
@@ -262,7 +263,7 @@ void sqliteInsert(
/* Fire BEFORE triggers */
if( sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab, newIdx, -1,
- onError) ){
+ onError, endOfLoop) ){
goto insert_cleanup;
}
@@ -336,7 +337,6 @@ void sqliteInsert(
/* Generate code to check constraints and generate index keys and
** do the insertion.
*/
- endOfLoop = sqliteVdbeMakeLabel(v);
sqliteGenerateConstraintChecks(pParse, pTab, base, 0,0,0,onError,endOfLoop);
sqliteCompleteInsertion(pParse, pTab, base, 0,0,0);
@@ -358,7 +358,7 @@ void sqliteInsert(
/* Code AFTER triggers */
if( sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_AFTER, pTab, newIdx, -1,
- onError) ){
+ onError, endOfLoop) ){
goto insert_cleanup;
}
}
diff --git a/src/parse.y b/src/parse.y
index f7f965e9b..489c9fd1e 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -14,7 +14,7 @@
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
-** @(#) $Id: parse.y,v 1.72 2002/06/06 19:04:16 drh Exp $
+** @(#) $Id: parse.y,v 1.73 2002/06/11 02:25:42 danielk1977 Exp $
*/
%token_prefix TK_
%token_type {Token}
@@ -120,7 +120,7 @@ id(A) ::= ID(X). {A = X;}
ABORT AFTER ASC BEFORE BEGIN CASCADE CLUSTER CONFLICT
COPY DEFERRED DELIMITERS DESC EACH END EXPLAIN FAIL FOR
FULL IGNORE IMMEDIATE INITIALLY INSTEAD MATCH JOIN KEY
- OF OFFSET PARTIAL PRAGMA REPLACE RESTRICT ROW STATEMENT
+ OF OFFSET PARTIAL PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT
TEMP TRIGGER VACUUM VIEW.
// And "ids" is an identifer-or-string.
@@ -756,6 +756,19 @@ trigger_cmd(A) ::= DELETE FROM ids(X) where_opt(Y).
// SELECT
trigger_cmd(A) ::= select(X). {A = sqliteTriggerSelectStep(X); }
+// The special RAISE expression that may occur in trigger programs
+expr(A) ::= RAISE(X) LP IGNORE RP(Y). { A = sqliteExpr(TK_RAISE, 0, 0, 0);
+ A->iColumn = OE_Ignore; sqliteExprSpan(A, &X, &Y);}
+expr(A) ::= RAISE(X) LP ROLLBACK COMMA ids(Z) RP(Y).
+{ A = sqliteExpr(TK_RAISE, 0, 0, &Z);
+ A->iColumn = OE_Rollback; sqliteExprSpan(A, &X, &Y);}
+expr(A) ::= RAISE(X) LP ABORT COMMA ids(Z) RP(Y).
+{ A = sqliteExpr(TK_RAISE, 0, 0, &Z);
+ A->iColumn = OE_Abort; sqliteExprSpan(A, &X, &Y);}
+expr(A) ::= RAISE(X) LP FAIL COMMA ids(Z) RP(Y).
+{ A = sqliteExpr(TK_RAISE, 0, 0, &Z);
+ A->iColumn = OE_Fail; sqliteExprSpan(A, &X, &Y);}
+
//////////////////////// DROP TRIGGER statement //////////////////////////////
cmd ::= DROP TRIGGER ids(X). {
sqliteDropTrigger(pParse,&X,0);
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 4e2352375..85886448c 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.122 2002/06/09 10:14:19 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.123 2002/06/11 02:25:42 danielk1977 Exp $
*/
#include "sqlite.h"
#include "hash.h"
@@ -764,6 +764,7 @@ struct TriggerStack {
int newIdx; /* Index of vdbe cursor to "new" temp table */
int oldIdx; /* Index of vdbe cursor to "old" temp table */
int orconf; /* Current orconf policy */
+ int ignoreJump; /* where to jump to for a RAISE(IGNORE) */
Trigger *pTrigger;
TriggerStack *pNext;
@@ -895,7 +896,8 @@ void sqliteCreateTrigger(Parse*, Token*, int, int, IdList*, Token*,
int, Expr*, TriggerStep*, char const*,int);
void sqliteDropTrigger(Parse*, Token*, int);
int sqliteTriggersExist(Parse* , Trigger* , int , int , int, ExprList*);
-int sqliteCodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int, int);
+int sqliteCodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int,
+ int, int);
void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
TriggerStep *sqliteTriggerSelectStep(Select*);
TriggerStep *sqliteTriggerInsertStep(Token*, IdList*, ExprList*, Select*, int);
diff --git a/src/tokenize.c b/src/tokenize.c
index 5be1b3354..ba88164b5 100644
--- a/src/tokenize.c
+++ b/src/tokenize.c
@@ -15,7 +15,7 @@
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
-** $Id: tokenize.c,v 1.44 2002/06/02 18:19:00 drh Exp $
+** $Id: tokenize.c,v 1.45 2002/06/11 02:25:42 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -105,6 +105,7 @@ static Keyword aKeywordTable[] = {
{ "PARTIAL", 0, TK_PARTIAL, 0 },
{ "PRAGMA", 0, TK_PRAGMA, 0 },
{ "PRIMARY", 0, TK_PRIMARY, 0 },
+ { "RAISE", 0, TK_RAISE, 0 },
{ "REFERENCES", 0, TK_REFERENCES, 0 },
{ "REPLACE", 0, TK_REPLACE, 0 },
{ "RESTRICT", 0, TK_RESTRICT, 0 },
diff --git a/src/trigger.c b/src/trigger.c
index cf31f1727..95e8fc9f8 100644
--- a/src/trigger.c
+++ b/src/trigger.c
@@ -480,14 +480,18 @@ static int codeTriggerProgram(
pParse->trigStack->orconf = orconf;
switch( pTriggerStep->op ){
case TK_SELECT: {
- sqliteSelect(pParse, pTriggerStep->pSelect, SRT_Discard, 0, 0, 0, 0);
+ Select * ss = sqliteSelectDup(pTriggerStep->pSelect);
+ assert(ss);
+ assert(ss->pSrc);
+ sqliteSelect(pParse, ss, SRT_Discard, 0, 0, 0, 0);
+ sqliteSelectDelete(ss);
break;
}
case TK_UPDATE: {
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
sqliteUpdate(pParse, &pTriggerStep->target,
- sqliteExprListDup(pTriggerStep->pExprList),
- sqliteExprDup(pTriggerStep->pWhere), orconf);
+ sqliteExprListDup(pTriggerStep->pExprList),
+ sqliteExprDup(pTriggerStep->pWhere), orconf);
sqliteVdbeAddOp(pParse->pVdbe, OP_ListPop, 0, 0);
break;
}
@@ -543,7 +547,8 @@ int sqliteCodeRowTrigger(
Table *pTab, /* The table to code triggers from */
int newIdx, /* The indice of the "new" row to access */
int oldIdx, /* The indice of the "old" row to access */
- int orconf /* ON CONFLICT policy */
+ int orconf, /* ON CONFLICT policy */
+ int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
){
Trigger * pTrigger;
TriggerStack * pTriggerStack;
@@ -588,6 +593,7 @@ int sqliteCodeRowTrigger(
pTriggerStack->oldIdx = oldIdx;
pTriggerStack->pTab = pTab;
pTriggerStack->pNext = pParse->trigStack;
+ pTriggerStack->ignoreJump = ignoreJump;
pParse->trigStack = pTriggerStack;
/* code the WHEN clause */
@@ -735,14 +741,14 @@ void sqliteViewTriggers(
sqliteVdbeAddOp(v, OP_Rewind, newIdx, 0);
sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE,
- pTab, newIdx, oldIdx, orconf);
+ pTab, newIdx, oldIdx, orconf, endOfLoop);
sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER,
- pTab, newIdx, oldIdx, orconf);
+ pTab, newIdx, oldIdx, orconf, endOfLoop);
}else{
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_BEFORE, pTab, -1, oldIdx,
- orconf);
+ orconf, endOfLoop);
sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1, oldIdx,
- orconf);
+ orconf, endOfLoop);
}
sqliteVdbeAddOp(v, OP_Next, oldIdx, startOfLoop);
diff --git a/src/update.c b/src/update.c
index f4f5c66ce..fcfe71712 100644
--- a/src/update.c
+++ b/src/update.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
**
-** $Id: update.c,v 1.43 2002/05/24 02:04:34 drh Exp $
+** $Id: update.c,v 1.44 2002/06/11 02:25:42 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -243,7 +243,7 @@ void sqliteUpdate(
sqliteVdbeAddOp(v, OP_Rewind, newIdx, 0);
if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, pTab,
- newIdx, oldIdx, onError) ){
+ newIdx, oldIdx, onError, addr) ){
goto update_cleanup;
}
}
@@ -350,7 +350,7 @@ void sqliteUpdate(
pParse->nTab = base;
if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, pTab,
- newIdx, oldIdx, onError) ){
+ newIdx, oldIdx, onError, addr) ){
goto update_cleanup;
}
}
diff --git a/src/vdbe.c b/src/vdbe.c
index 16b247caa..a838c8d06 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -30,7 +30,7 @@
** But other routines are also provided to help in building up
** a program instruction by instruction.
**
-** $Id: vdbe.c,v 1.154 2002/06/08 23:25:09 drh Exp $
+** $Id: vdbe.c,v 1.155 2002/06/11 02:25:42 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -1395,6 +1395,10 @@ case OP_Halt: {
if( pOp->p1!=SQLITE_OK ){
rc = pOp->p1;
errorAction = pOp->p2;
+ if( pOp->p3 ){
+ sqliteSetString(pzErrMsg, pOp->p3, 0);
+ goto cleanup;
+ }
goto abort_due_to_error;
}else{
pc = p->nOp-1;