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

Allow arbitrary expressions as the second argument to RAISE().

FossilOrigin-Name: 003e1c8c27824cb917b3869bdf9000f32ff0b6887a2aff8516712cfe865cf34d
This commit is contained in:
drh
2024-05-08 17:42:13 +00:00
parent 538ad6ce58
commit 788ade3487
9 changed files with 59 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sa\shyperlink\stypo\sin\ssession\sdocumentation. C Allow\sarbitrary\sexpressions\sas\sthe\ssecond\sargument\sto\sRAISE().
D 2024-05-08T11:51:56.927 D 2024-05-08T17:42:13.761
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -703,9 +703,9 @@ F src/date.c 126ba2ab10aeb2e7ba6e089b5f07b747c0625b8287f78b60da346eda8d23c875
F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782
F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43
F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500
F src/expr.c 3428b046cb731be83770eaa34317d0ae5bdf8f5e7c3a0abd57528d0a03a8f9f9 F src/expr.c dff4775b9aa9e6a397b37dda601207c6c0024df8cb5ec43e66fd07f5efd9bd6c
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00 F src/fkey.c 852f93c0ef995e0c2b8983059a2b97151c194cc8259e21f5bc2b7ac508348c2a
F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f F src/func.c 283d4f3b2751a1d9339fd93a8a013d1948fd5f4474a3cab0955eb4fafd445d0f
F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90 F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90
F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220
@@ -742,7 +742,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
F src/pager.c 9beb80f6e330dd63c5d8ba0f7a7f3a55fff22067a68d424949c389bfc6fa0c56 F src/pager.c 9beb80f6e330dd63c5d8ba0f7a7f3a55fff22067a68d424949c389bfc6fa0c56
F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a
F src/parse.y 50516253433303673ff6b009983bb246d1527415e5a9af22acc51b0eedb9a10d F src/parse.y de2da0ffd33f6532c1640e7c6a6c6d8ac5ae85b0dbb0b1d7c3194d243a4c1e6a
F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75
F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5
F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00
@@ -816,14 +816,14 @@ F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c
F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd68 F src/tokenize.c 3f703cacdab728d7741e5a6ac242006d74fe1c2754d4f03ed889d7253259bd68
F src/treeview.c 4f9ba6c1c7c9893fc046fdb0bc1f6bdec7660122b1ae37e51fb9b64c286caafd F src/treeview.c 5538cc0e88cb87c55e26326c7a02d5fe45deaeb2edbd5436af7a674ed6491ff2
F src/trigger.c 0858f75818ed1580332db274f1032bcc5effe567cb132df5c5be8b1d800ca97f F src/trigger.c 0858f75818ed1580332db274f1032bcc5effe567cb132df5c5be8b1d800ca97f
F src/update.c 732404a04d1737ef14bb6ec6b84f74edf28b3c102a92ae46b4855438a710efe7 F src/update.c 732404a04d1737ef14bb6ec6b84f74edf28b3c102a92ae46b4855438a710efe7
F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65
F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e
F src/util.c 4d6d7ebfe6772a1b950c97bbb1d1a72ad4874617ec498ab8aa73b7f5a43e44bb F src/util.c 4d6d7ebfe6772a1b950c97bbb1d1a72ad4874617ec498ab8aa73b7f5a43e44bb
F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104
F src/vdbe.c 3b1793c5d2235ae89b01ef051a33d7d2ad3704c71799653b112686735ad401ff F src/vdbe.c 2fdfe0535fa517fb4590144121c040c5703db318e7479d6d62ba6ab2e699e001
F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f
F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c
F src/vdbeapi.c 80235ac380e9467fec1cb0883354d841f2a771976e766995f7e0c77f845406df F src/vdbeapi.c 80235ac380e9467fec1cb0883354d841f2a771976e766995f7e0c77f845406df
@@ -997,7 +997,7 @@ F test/collate9.test 3adcc799229545940df2f25308dd1ad65869145a
F test/collateA.test b8218ab90d1fa5c59dcf156efabb1b2599c580d6 F test/collateA.test b8218ab90d1fa5c59dcf156efabb1b2599c580d6
F test/collateB.test 1e68906951b846570f29f20102ed91d29e634854ee47454d725f2151ecac0b95 F test/collateB.test 1e68906951b846570f29f20102ed91d29e634854ee47454d725f2151ecac0b95
F test/colmeta.test 2c765ea61ee37bc43bbe6d6047f89004e6508eb1 F test/colmeta.test 2c765ea61ee37bc43bbe6d6047f89004e6508eb1
F test/colname.test 87ad5458bb8709312dac0d6755fd30e8e4ca83298d0a9ef6e5c24277a3c3390e F test/colname.test 387e880eeac0889900f7b3e9703c375515f5d323f71fd4f2bb5428a4ac8e2023
F test/columncount.test 6fe99c2f35738b0129357a1cf3fa483f76140f4cd8a89014c88c33c876d2638f F test/columncount.test 6fe99c2f35738b0129357a1cf3fa483f76140f4cd8a89014c88c33c876d2638f
F test/conflict.test b705cddf025a675d3c13d62fa78ab1e2696fb8e07a3d7cccce1596ff8b301492 F test/conflict.test b705cddf025a675d3c13d62fa78ab1e2696fb8e07a3d7cccce1596ff8b301492
F test/conflict2.test 5557909ce683b1073982f5d1b61dfb1d41e369533bfdaf003180c5bc87282dd1 F test/conflict2.test 5557909ce683b1073982f5d1b61dfb1d41e369533bfdaf003180c5bc87282dd1
@@ -1866,7 +1866,7 @@ F test/trans.test 45f6f9ab6f66a7b5744f1caac06b558f95da62501916906cf55586a896f9f4
F test/trans2.test 62bd045bfc7a1c14c5ba83ba64d21ade31583f76 F test/trans2.test 62bd045bfc7a1c14c5ba83ba64d21ade31583f76
F test/trans3.test 91a100e5412b488e22a655fe423a14c26403ab94 F test/trans3.test 91a100e5412b488e22a655fe423a14c26403ab94
F test/transitive1.test f8ee983600b33d167da1885657f064aec404e1c0d0bc8765fdf163f4c749237a F test/transitive1.test f8ee983600b33d167da1885657f064aec404e1c0d0bc8765fdf163f4c749237a
F test/trigger1.test 02cc64dc98278816c1c1ed8e472e18db8edbad88f37018bf46223e9614831963 F test/trigger1.test 2834f8830a1ae338d95c2e3ea0c2a7bc4cda126cdeb715004cf0fd071892e44f
F test/trigger2.test 30fcb3a6aa6782020d47968735ee6086ed795f73a7affa9406c8d5a36e7b5265 F test/trigger2.test 30fcb3a6aa6782020d47968735ee6086ed795f73a7affa9406c8d5a36e7b5265
F test/trigger3.test aa640bb2bbb03edd5ff69c055117ea088f121945 F test/trigger3.test aa640bb2bbb03edd5ff69c055117ea088f121945
F test/trigger4.test 74700b76ebf3947b2f7a92405141eb2cf2a5d359 F test/trigger4.test 74700b76ebf3947b2f7a92405141eb2cf2a5d359
@@ -2189,8 +2189,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P e29decb8b1991bb586f41fd74bbaa4d6c4bd63e22617145828b2500d697d7869 P 42d67c6fed3a5f21d7b71515aca471ba61d387e620022735a2e7929fa3a237cf
R bd6c2a6994b109d4181b29475acc71ca R 2f3bd2a16acd125a41b6775ce57250d9
T *branch * enhanced-raise
T *sym-enhanced-raise *
T -sym-trunk *
U drh U drh
Z b1677682f99b4b1ca04906a7901df3be Z 0fd130dec139b10d531d7d8015ffe4ed
# Remove this line to create a well-formed Fossil manifest. # Remove this line to create a well-formed Fossil manifest.

View File

@@ -1 +1 @@
42d67c6fed3a5f21d7b71515aca471ba61d387e620022735a2e7929fa3a237cf 003e1c8c27824cb917b3869bdf9000f32ff0b6887a2aff8516712cfe865cf34d

View File

@@ -5306,15 +5306,14 @@ expr_code_doover:
} }
assert( !ExprHasProperty(pExpr, EP_IntValue) ); assert( !ExprHasProperty(pExpr, EP_IntValue) );
if( pExpr->affExpr==OE_Ignore ){ if( pExpr->affExpr==OE_Ignore ){
sqlite3VdbeAddOp4( sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, OE_Ignore);
v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
VdbeCoverage(v); VdbeCoverage(v);
}else{ }else{
sqlite3HaltConstraint(pParse, r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
sqlite3VdbeAddOp3(v, OP_Halt,
pParse->pTriggerTab ? SQLITE_CONSTRAINT_TRIGGER : SQLITE_ERROR, pParse->pTriggerTab ? SQLITE_CONSTRAINT_TRIGGER : SQLITE_ERROR,
pExpr->affExpr, pExpr->u.zToken, 0, 0); pExpr->affExpr, r1);
} }
break; break;
} }
#endif #endif

View File

@@ -1328,7 +1328,8 @@ static Trigger *fkActionTrigger(
SrcList *pSrc; SrcList *pSrc;
Expr *pRaise; 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 ){ if( pRaise ){
pRaise->affExpr = OE_Abort; pRaise->affExpr = OE_Abort;
} }

View File

@@ -1658,8 +1658,8 @@ expr(A) ::= RAISE LP IGNORE RP. {
A->affExpr = OE_Ignore; A->affExpr = OE_Ignore;
} }
} }
expr(A) ::= RAISE LP raisetype(T) COMMA nm(Z) RP. { expr(A) ::= RAISE LP raisetype(T) COMMA expr(Z) RP. {
A = sqlite3ExprAlloc(pParse->db, TK_RAISE, &Z, 1); A = sqlite3PExpr(pParse, TK_RAISE, Z, 0);
if( A ) { if( A ) {
A->affExpr = (char)T; A->affExpr = (char)T;
} }

View File

@@ -818,7 +818,8 @@ void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
case OE_Ignore: zType = "ignore"; break; case OE_Ignore: zType = "ignore"; break;
} }
assert( !ExprHasProperty(pExpr, EP_IntValue) ); 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; break;
} }
#endif #endif

View File

@@ -1214,7 +1214,7 @@ case OP_HaltIfNull: { /* in3 */
/* no break */ deliberate_fall_through /* 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 ** Exit immediately. All open cursors, etc are closed
** automatically. ** automatically.
@@ -1227,18 +1227,22 @@ case OP_HaltIfNull: { /* in3 */
** then back out all changes that have occurred during this execution of the ** then back out all changes that have occurred during this execution of the
** VDBE, but do not rollback the transaction. ** 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 ** 1: NOT NULL constraint failed: P4
** 2: UNIQUE constraint failed: P4 ** 2: UNIQUE constraint failed: P4
** 3: CHECK constraint failed: P4 ** 3: CHECK constraint failed: P4
** 4: FOREIGN KEY constraint failed: P4 ** 4: FOREIGN KEY constraint failed: P4
** **
** If P5 is not zero and P4 is NULL, then everything after the ":" is ** If P3 is zero and P5 is not zero and P4 is NULL, then everything after
** omitted. ** the ":" is omitted.
** **
** There is an implied "Halt 0 0 0" instruction inserted at the very end of ** 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 ** every program. So a jump past the last instruction of the program
@@ -1251,6 +1255,9 @@ case OP_Halt: {
#ifdef SQLITE_DEBUG #ifdef SQLITE_DEBUG
if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); } if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); }
#endif #endif
assert( pOp->p4type==P4_NOTUSED
|| pOp->p4type==P4_STATIC
|| pOp->p4type==P4_DYNAMIC );
/* A deliberately coded "OP_Halt SQLITE_INTERNAL * * * *" opcode indicates /* A deliberately coded "OP_Halt SQLITE_INTERNAL * * * *" opcode indicates
** something is wrong with the code generator. Raise an assertion in order ** something is wrong with the code generator. Raise an assertion in order
@@ -1281,7 +1288,12 @@ case OP_Halt: {
p->errorAction = (u8)pOp->p2; p->errorAction = (u8)pOp->p2;
assert( pOp->p5<=4 ); assert( pOp->p5<=4 );
if( p->rc ){ 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", static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
"FOREIGN KEY" }; "FOREIGN KEY" };
testcase( pOp->p5==1 ); testcase( pOp->p5==1 );

View File

@@ -424,7 +424,7 @@ do_catchsql_test colname-9.400 {
# #
do_catchsql_test colname-9.410 { do_catchsql_test colname-9.410 {
CREATE TABLE t5 AS SELECT RAISE(abort,a); CREATE TABLE t5 AS SELECT RAISE(abort,a);
} {1 {RAISE() may only be used within a trigger-program}} } {1 {no such column: a}}
# Make sure the quotation marks get removed from the column names # Make sure the quotation marks get removed from the column names
# when constructing a new table from an aggregate SELECT. # when constructing a new table from an aggregate SELECT.

View File

@@ -838,4 +838,17 @@ do_catchsql_test trigger1-23.1 {
END; END;
} {1 {near "#1": syntax error}} } {1 {near "#1": syntax error}}
# 2024-05-08 Allow arbitrary expressions as the 2nd argument to RAISE().
#
do_catchsql_test trigger1-24.1 {
CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
SELECT raise(abort,format('attempt to insert %d where is not a power of 2',new.a))
WHERE (new.a & (new.a-1))!=0;
END;
INSERT INTO t1 VALUES(0),(1),(2),(4),(8),(65536);
} {0 {}}
do_catchsql_test trigger1-24.2 {
INSERT INTO t1 VALUES(9876);
} {1 {attempt to insert 9876 where is not a power of 2}}
finish_test finish_test