diff --git a/doc/sql.extensions/README.context_variables b/doc/sql.extensions/README.context_variables index 6ce54c6d09..8eb7f3b149 100644 --- a/doc/sql.extensions/README.context_variables +++ b/doc/sql.extensions/README.context_variables @@ -170,20 +170,30 @@ SQLSTATE (FB 2.5) 1. SQLSTATE always evaluates to NULL outside the exception handling block. -EXCEPTION (FB 4.0) +RDB$ERROR (FB 4.0) ------------------ Function: - Returns name of the active user-defined exception. + Returns specific context of the active exception. Author: Dmitry Yemanov Syntax rules: - EXCEPTION + RDB$ERROR ( context ) + context ::= { GDSCODE | SQLCODE | SQLSTATE | EXCEPTION | MESSAGE } + + GDSCODE, SQLCODE, SQLSTATE - see above + + EXCEPTION : VARCHAR(63) CHARACTER SET UTF8 + Returns name of the active user-defined exception + or NULL if active exception is a system one + + MESSAGE : VARCHAR(1024) CHARACTER SET UTF8 + Returns interpreted text for the active exception Type: - VARCHAR(63) CHARACTER SET UTF8 + Depends on context Scope: PSQL, context of the exception handling block. @@ -192,41 +202,8 @@ EXCEPTION (FB 4.0) BEGIN ... WHEN ANY DO - IF (EXCEPTION IS NOT NULL) - EXECUTE PROCEDURE P_USR_EXCEPTION(EXCEPTION); - ELSE - EXECUTE PROCEDURE P_SYS_EXCEPTION; + EXECUTE PROCEDURE P_LOG_EXCEPTION(RDB$ERROR(MESSAGE)); END Note(s): - 1. EXCEPTION always contains NULL outside the exception handling block. - 2. If system exception is thrown, EXCEPTION also contains NULL. - - -ERROR_MESSAGE (FB 4.0) ----------------------- - - Function: - Returns interpreted text for the active exception. - - Author: - Dmitry Yemanov - - Syntax rules: - ERROR_MESSAGE - - Type: - VARCHAR(1024) CHARACTER SET UTF8 - - Scope: - PSQL, context of the exception handling block. - - Example(s): - BEGIN - ... - WHEN ANY DO - EXECUTE PROCEDURE P_LOG_EXCEPTION(ERROR_MESSAGE); - END - - Note(s): - 1. ERROR_MESSAGE always contains NULL outside the exception handling block. + RDB$ERROR always contains NULL outside the exception handling block. diff --git a/src/dsql/ExprNodes.cpp b/src/dsql/ExprNodes.cpp index f0d4ec0fe1..bddbfce0fc 100644 --- a/src/dsql/ExprNodes.cpp +++ b/src/dsql/ExprNodes.cpp @@ -6125,7 +6125,9 @@ const InternalInfoNode::InfoAttr InternalInfoNode::INFO_TYPE_ATTRIBUTES[MAX_INFO {"SQLCODE", DsqlCompilerScratch::FLAG_BLOCK}, {"ROW_COUNT", DsqlCompilerScratch::FLAG_BLOCK}, {"INSERTING/UPDATING/DELETING", DsqlCompilerScratch::FLAG_TRIGGER}, - {"SQLSTATE", DsqlCompilerScratch::FLAG_BLOCK} + {"SQLSTATE", DsqlCompilerScratch::FLAG_BLOCK}, + {"EXCEPTION", DsqlCompilerScratch::FLAG_BLOCK}, + {"MESSAGE", DsqlCompilerScratch::FLAG_BLOCK} }; InternalInfoNode::InternalInfoNode(MemoryPool& pool, ValueExprNode* aArg) diff --git a/src/dsql/parse-conflicts.txt b/src/dsql/parse-conflicts.txt index 0819e55618..b0587cd258 100644 --- a/src/dsql/parse-conflicts.txt +++ b/src/dsql/parse-conflicts.txt @@ -1 +1 @@ -44 shift/reduce conflicts, 583 reduce/reduce conflicts. +44 shift/reduce conflicts, 17 reduce/reduce conflicts. diff --git a/src/dsql/parse.y b/src/dsql/parse.y index 0025a7296c..66098b9a17 100644 --- a/src/dsql/parse.y +++ b/src/dsql/parse.y @@ -593,7 +593,7 @@ using namespace Firebird; %token CUME_DIST %token DEFINER -%token ERROR_MESSAGE +%token MESSAGE %token EXCLUDE %token FOLLOWING %token INVOKER @@ -603,6 +603,7 @@ using namespace Firebird; %token PRECEDING %token PRIVILEGE %token RANGE +%token RDB_ERROR %token RDB_ROLE_IN_USE %token RDB_SYSTEM_PRIVILEGE %token SECURITY @@ -6952,12 +6953,25 @@ internal_info { $$ = newNode(MAKE_const_slong(INFO_TYPE_SQLSTATE)); } | ROW_COUNT { $$ = newNode(MAKE_const_slong(INFO_TYPE_ROWS_AFFECTED)); } - | EXCEPTION - { $$ = newNode(MAKE_const_slong(INFO_TYPE_EXCEPTION)); } - | ERROR_MESSAGE - { $$ = newNode(MAKE_const_slong(INFO_TYPE_ERROR_MSG)); } + | RDB_ERROR '(' error_context ')' + { $$ = newNode(MAKE_const_slong($3)); } ; +%type error_context +error_context + : GDSCODE + { $$ = INFO_TYPE_GDSCODE; } + | SQLCODE + { $$ = INFO_TYPE_SQLCODE; } + | SQLSTATE + { $$ = INFO_TYPE_SQLSTATE; } + | EXCEPTION + { $$ = INFO_TYPE_EXCEPTION; } + | MESSAGE + { $$ = INFO_TYPE_ERROR_MSG; } + ; + + %type sql_string sql_string : STRING // string in current charset @@ -8088,16 +8102,17 @@ non_reserved_word | TRUSTED | CUME_DIST // added in FB 4.0 | DEFINER - | ERROR_MESSAGE | EXCLUDE | FOLLOWING | INVOKER + | MESSAGE | NTILE | OTHERS | PERCENT_RANK | PRECEDING | PRIVILEGE | RANGE + | RDB_ERROR | RDB_ROLE_IN_USE | RDB_SYSTEM_PRIVILEGE | SECURITY diff --git a/src/yvalve/keywords.cpp b/src/yvalve/keywords.cpp index ebac6911ac..12abc49e17 100644 --- a/src/yvalve/keywords.cpp +++ b/src/yvalve/keywords.cpp @@ -182,7 +182,6 @@ static const TOK tokens[] = {TOK_END, "END", false}, {TOK_ENGINE, "ENGINE", true}, {TOK_ENTRY_POINT, "ENTRY_POINT", false}, - {TOK_ERROR_MESSAGE, "ERROR_MESSAGE", true}, {TOK_ESCAPE, "ESCAPE", false}, {TOK_EXCEPTION, "EXCEPTION", false}, {TOK_EXCLUDE, "EXCLUDE", false}, @@ -269,6 +268,7 @@ static const TOK tokens[] = {TOK_MAXIMUM, "MAX", false}, {TOK_MAXVALUE, "MAXVALUE", false}, {TOK_MERGE, "MERGE", false}, + {TOK_MESSAGE, "MESSAGE", true}, {TOK_MILLISECOND, "MILLISECOND", false}, {TOK_MIDDLENAME, "MIDDLENAME", false}, {TOK_MINIMUM, "MIN", false}, @@ -336,6 +336,7 @@ static const TOK tokens[] = {TOK_RANGE, "RANGE", false}, {TOK_RANK, "RANK", false}, {TOK_DB_KEY, "RDB$DB_KEY", false}, + {TOK_RDB_ERROR, "RDB$ERROR", true}, {TOK_RDB_GET_CONTEXT, "RDB$GET_CONTEXT", true}, {TOK_RDB_RECORD_VERSION, "RDB$RECORD_VERSION", false}, {TOK_RDB_ROLE_IN_USE, "RDB$ROLE_IN_USE", true},