aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2024-05-08 17:42:13 +0000
committerdrh <>2024-05-08 17:42:13 +0000
commit788ade3487252c4de2da94a2b8f9ec7ebdd83c95 (patch)
treec821b9cd566a89f4d32ea6288d7bd69a35e781ec /src
parent538ad6ce58c47e48f2c85abfcb31c968e615fc40 (diff)
downloadsqlite-788ade3487252c4de2da94a2b8f9ec7ebdd83c95.tar.gz
sqlite-788ade3487252c4de2da94a2b8f9ec7ebdd83c95.zip
Allow arbitrary expressions as the second argument to RAISE().
FossilOrigin-Name: 003e1c8c27824cb917b3869bdf9000f32ff0b6887a2aff8516712cfe865cf34d
Diffstat (limited to 'src')
-rw-r--r--src/expr.c9
-rw-r--r--src/fkey.c3
-rw-r--r--src/parse.y4
-rw-r--r--src/treeview.c3
-rw-r--r--src/vdbe.c26
5 files changed, 29 insertions, 16 deletions
diff --git a/src/expr.c b/src/expr.c
index a5272df7c..2157cf4ed 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -5306,15 +5306,14 @@ expr_code_doover:
}
assert( !ExprHasProperty(pExpr, EP_IntValue) );
if( pExpr->affExpr==OE_Ignore ){
- sqlite3VdbeAddOp4(
- v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
+ sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, OE_Ignore);
VdbeCoverage(v);
}else{
- sqlite3HaltConstraint(pParse,
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
+ sqlite3VdbeAddOp3(v, OP_Halt,
pParse->pTriggerTab ? SQLITE_CONSTRAINT_TRIGGER : SQLITE_ERROR,
- pExpr->affExpr, pExpr->u.zToken, 0, 0);
+ pExpr->affExpr, r1);
}
-
break;
}
#endif
diff --git a/src/fkey.c b/src/fkey.c
index bace1ae5e..1efdc0bba 100644
--- a/src/fkey.c
+++ b/src/fkey.c
@@ -1328,7 +1328,8 @@ static Trigger *fkActionTrigger(
SrcList *pSrc;
Expr *pRaise;
- pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
+ pRaise = sqlite3Expr(db, TK_STRING, "FOREIGN KEY constraint failed"),
+ pRaise = sqlite3PExpr(pParse, TK_RAISE, pRaise, 0);
if( pRaise ){
pRaise->affExpr = OE_Abort;
}
diff --git a/src/parse.y b/src/parse.y
index 071e10abd..90277f9c0 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -1658,8 +1658,8 @@ expr(A) ::= RAISE LP IGNORE RP. {
A->affExpr = OE_Ignore;
}
}
-expr(A) ::= RAISE LP raisetype(T) COMMA nm(Z) RP. {
- A = sqlite3ExprAlloc(pParse->db, TK_RAISE, &Z, 1);
+expr(A) ::= RAISE LP raisetype(T) COMMA expr(Z) RP. {
+ A = sqlite3PExpr(pParse, TK_RAISE, Z, 0);
if( A ) {
A->affExpr = (char)T;
}
diff --git a/src/treeview.c b/src/treeview.c
index d3346b468..586106cad 100644
--- a/src/treeview.c
+++ b/src/treeview.c
@@ -818,7 +818,8 @@ void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
case OE_Ignore: zType = "ignore"; break;
}
assert( !ExprHasProperty(pExpr, EP_IntValue) );
- sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
+ sqlite3TreeViewLine(pView, "RAISE %s", zType);
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
break;
}
#endif
diff --git a/src/vdbe.c b/src/vdbe.c
index d8b471de2..f06a71da4 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -1214,7 +1214,7 @@ case OP_HaltIfNull: { /* in3 */
/* no break */ deliberate_fall_through
}
-/* Opcode: Halt P1 P2 * P4 P5
+/* Opcode: Halt P1 P2 P3 P4 P5
**
** Exit immediately. All open cursors, etc are closed
** automatically.
@@ -1227,18 +1227,22 @@ case OP_HaltIfNull: { /* in3 */
** then back out all changes that have occurred during this execution of the
** VDBE, but do not rollback the transaction.
**
-** If P4 is not null then it is an error message string.
+** If P3 is not zero and P4 is NULL, then P3 is a register that holds the
+** text of an error message.
**
-** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
+** If P3 is zero and P4 is not null then the error message string is held
+** in P4.
+**
+** P5 is a value between 1 and 4, inclusive, then the P4 error message
+** string is modified as follows:
**
-** 0: (no change)
** 1: NOT NULL constraint failed: P4
** 2: UNIQUE constraint failed: P4
** 3: CHECK constraint failed: P4
** 4: FOREIGN KEY constraint failed: P4
**
-** If P5 is not zero and P4 is NULL, then everything after the ":" is
-** omitted.
+** If P3 is zero and P5 is not zero and P4 is NULL, then everything after
+** the ":" is omitted.
**
** There is an implied "Halt 0 0 0" instruction inserted at the very end of
** every program. So a jump past the last instruction of the program
@@ -1251,6 +1255,9 @@ case OP_Halt: {
#ifdef SQLITE_DEBUG
if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); }
#endif
+ assert( pOp->p4type==P4_NOTUSED
+ || pOp->p4type==P4_STATIC
+ || pOp->p4type==P4_DYNAMIC );
/* A deliberately coded "OP_Halt SQLITE_INTERNAL * * * *" opcode indicates
** something is wrong with the code generator. Raise an assertion in order
@@ -1281,7 +1288,12 @@ case OP_Halt: {
p->errorAction = (u8)pOp->p2;
assert( pOp->p5<=4 );
if( p->rc ){
- if( pOp->p5 ){
+ if( pOp->p3>0 && pOp->p4type==P4_NOTUSED ){
+ const char *zErr;
+ assert( pOp->p3<=(p->nMem + 1 - p->nCursor) );
+ zErr = sqlite3ValueText(&aMem[pOp->p3], SQLITE_UTF8);
+ sqlite3VdbeError(p, "%s", zErr);
+ }else if( pOp->p5 ){
static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
"FOREIGN KEY" };
testcase( pOp->p5==1 );