From 8752c51169d38eef6ab161befdea02e603028d3d Mon Sep 17 00:00:00 2001 From: nnuanyang Date: Wed, 30 Aug 2023 20:01:49 -0700 Subject: [PATCH] mysql_error bug --- src/common/backend/utils/error/elog.cpp | 45 ++++++- src/common/pl/plpgsql/src/pl_exec.cpp | 38 +++--- src/include/utils/elog.h | 2 + src/include/utils/plpgsql.h | 2 +- src/test/regress/expected/mysql_condition.out | 48 +++++-- src/test/regress/expected/mysql_resignal.out | 120 +++++++++--------- src/test/regress/expected/mysql_signal.out | 120 +++++++++--------- src/test/regress/sql/mysql_condition.sql | 13 ++ 8 files changed, 234 insertions(+), 154 deletions(-) diff --git a/src/common/backend/utils/error/elog.cpp b/src/common/backend/utils/error/elog.cpp index 24fa62bf1..a255eb3a5 100644 --- a/src/common/backend/utils/error/elog.cpp +++ b/src/common/backend/utils/error/elog.cpp @@ -494,6 +494,7 @@ bool errstart(int elevel, const char* filename, int lineno, const char* funcname edata->table_name = NULL; edata->column_name = NULL; edata->cursor_name = NULL; + edata->mysql_errno = NULL; t_thrd.log_cxt.recursion_depth--; return true; @@ -729,6 +730,8 @@ void errfinish(int dummy, ...) pfree(edata->column_name); if (edata->cursor_name) pfree(edata->cursor_name); + if (edata->mysql_errno) + pfree(edata->mysql_errno); t_thrd.log_cxt.errordata_stack_depth--; /* Exit error-handling context */ @@ -1665,6 +1668,27 @@ int signal_cursor_name(const char *cursor_name) return 0; /* return value does not matter */ } +/* + * signal_mysql_errno --- add mysql_errno to the current error + */ +int signal_mysql_errno(const char *mysql_errno) +{ + ErrorData* edata = &t_thrd.log_cxt.errordata[t_thrd.log_cxt.errordata_stack_depth]; + + /* we don't bother incrementing t_thrd.log_cxt.recursion_depth */ + CHECK_STACK_DEPTH(); + + if (edata->mysql_errno != NULL) { + pfree(edata->mysql_errno); + edata->mysql_errno = NULL; + } + + if (mysql_errno != NULL) { + edata->mysql_errno = MemoryContextStrdup(ErrorContext, mysql_errno); + } + + return 0; /* return value does not matter */ +} /* * ErrOutToClient --- sets whether to send error output to client or not. */ @@ -2030,6 +2054,8 @@ ErrorData* CopyErrorData(void) newedata->column_name = pstrdup(newedata->column_name); if (newedata->cursor_name) newedata->cursor_name = pstrdup(newedata->cursor_name); + if (newedata->mysql_errno) + newedata->mysql_errno = pstrdup(newedata->mysql_errno); return newedata; } @@ -2058,6 +2084,7 @@ void UpdateErrorData(ErrorData* edata, ErrorData* newData) FREE_POINTER(edata->table_name); FREE_POINTER(edata->column_name); FREE_POINTER(edata->cursor_name); + FREE_POINTER(edata->mysql_errno); MemoryContext oldcontext = MemoryContextSwitchTo(ErrorContext); edata->elevel = newData->elevel; @@ -2089,6 +2116,7 @@ void UpdateErrorData(ErrorData* edata, ErrorData* newData) edata->table_name = pstrdup(newData->table_name); edata->column_name = pstrdup(newData->column_name); edata->cursor_name = pstrdup(newData->cursor_name); + edata->mysql_errno = pstrdup(newData->mysql_errno); MemoryContextSwitchTo(oldcontext); } @@ -2172,6 +2200,10 @@ void FreeErrorData(ErrorData* edata) pfree(edata->cursor_name); edata->cursor_name = NULL; } + if (edata->mysql_errno) { + pfree(edata->mysql_errno); + edata->mysql_errno = NULL; + } pfree(edata); } @@ -2283,6 +2315,8 @@ void ReThrowError(ErrorData* edata) newedata->column_name = pstrdup(newedata->column_name); if (newedata->cursor_name) newedata->cursor_name = pstrdup(newedata->cursor_name); + if (newedata->mysql_errno) + newedata->mysql_errno = pstrdup(newedata->mysql_errno); t_thrd.log_cxt.recursion_depth--; if (DB_IS_CMPT(B_FORMAT)) { @@ -5639,6 +5673,9 @@ static char* mask_Password_internal(const char* query_string) if (NULL != edata->cursor_name) { pfree_ext(edata->cursor_name); } + if (NULL != edata->mysql_errno) { + pfree_ext(edata->mysql_errno); + } t_thrd.log_cxt.errordata_stack_depth--; } } @@ -6012,10 +6049,10 @@ void pushErrorData(ErrorData *edata) dolphinErrorData->class_origin = pstrdup(edata->class_origin); dolphinErrorData->subclass_origin = pstrdup(edata->subclass_origin); dolphinErrorData->sqlstatestr = pstrdup(edata->sqlstate); - char sqlerrcode [128]; - int ret = sprintf_s(sqlerrcode, 128, "%d", edata->sqlerrcode); - securec_check_ss_c(ret, "\0", "\0"); - dolphinErrorData->errorcode = pstrdup(sqlerrcode); + if (edata->mysql_errno == NULL) + dolphinErrorData->errorcode = pstrdup(plpgsql_get_sqlstate(edata->sqlerrcode)); + else + dolphinErrorData->errorcode = pstrdup(edata->mysql_errno); } else { dolphinErrorData->class_origin = pstrdup(class_origin); dolphinErrorData->subclass_origin = pstrdup(subclass_origin); diff --git a/src/common/pl/plpgsql/src/pl_exec.cpp b/src/common/pl/plpgsql/src/pl_exec.cpp index 5e8bb96f3..680f65415 100644 --- a/src/common/pl/plpgsql/src/pl_exec.cpp +++ b/src/common/pl/plpgsql/src/pl_exec.cpp @@ -4118,7 +4118,8 @@ static int exec_stmt(PLpgSQL_execstate* estate, PLpgSQL_stmt* stmt, bool resigna if ((enum PLpgSQL_stmt_types)stmt->cmd_type == PLPGSQL_STMT_BLOCK) { if (estate->handler_level == estate->block_level) { copyDiffErrorDataArea(u_sess->dolphin_errdata_ctx.errorDataArea, u_sess->dolphin_errdata_ctx.lastErrorDataArea, estate->cur_error); - copyErrorDataArea(u_sess->dolphin_errdata_ctx.lastErrorDataArea, u_sess->dolphin_errdata_ctx.errorDataArea); + if (u_sess->dolphin_errdata_ctx.lastErrorDataArea->current_edata_count != 0) + copyErrorDataArea(u_sess->dolphin_errdata_ctx.lastErrorDataArea, u_sess->dolphin_errdata_ctx.errorDataArea); u_sess->dolphin_errdata_ctx.handler_active = false; } else if (!u_sess->dolphin_errdata_ctx.handler_active) { copyErrorDataArea(u_sess->dolphin_errdata_ctx.errorDataArea, u_sess->dolphin_errdata_ctx.lastErrorDataArea); @@ -4406,7 +4407,7 @@ static int exec_stmt_b_getdiag(PLpgSQL_execstate* estate, PLpgSQL_stmt_getdiag* edata->sqlerrcode = ERRCODE_INVALID_CONDITION_NUMBER; edata->message = "Invalid condition number"; edata->class_origin = edata->sqlstate = edata->subclass_origin = edata->cons_catalog = edata->cons_schema = NULL; - edata->cons_name = edata->catalog_name = edata->schema_name = edata->table_name = edata->column_name = edata->cursor_name = NULL; + edata->cons_name = edata->catalog_name = edata->schema_name = edata->table_name = edata->column_name = edata->cursor_name = edata->mysql_errno = NULL; copyErrorDataArea(u_sess->dolphin_errdata_ctx.lastErrorDataArea, u_sess->dolphin_errdata_ctx.errorDataArea); pushErrorData(edata); pfree_ext(edata); @@ -6380,6 +6381,7 @@ static void exec_get_condition_information(PLpgSQL_execstate* estate, PLpgSQL_st PLpgSQL_condition_info_item *con_item) { ListCell *lc = NULL; + int code = 0; foreach (lc, stmt->cond_info_item) { PLpgSQL_signal_info_item *item = (PLpgSQL_signal_info_item *)lfirst(lc); @@ -6408,12 +6410,13 @@ static void exec_get_condition_information(PLpgSQL_execstate* estate, PLpgSQL_st con_item->message_text = pstrdup(extval); break; case PLPGSQL_MYSQL_ERRNO: - con_item->sqlerrcode = pg_atoi(extval, sizeof(int32), false); - if (con_item->sqlerrcode <= 0 || con_item->sqlerrcode > MYSQL_ERRNO_MAX) { + code = pg_atoi(extval, sizeof(int32), false); + if (code <= 0 || code > MYSQL_ERRNO_MAX) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("Variable '%s' can't be set to the value of '%s'", item->con_name, extval))); } + con_item->sqlerrcode = pstrdup(extval); break; case PLPGSQL_CONSTRAINT_CATALOG: con_item->constraint_catalog = pstrdup(extval); @@ -6451,10 +6454,10 @@ static void exec_get_condition_information(PLpgSQL_execstate* estate, PLpgSQL_st return; } -static void StoreSignalError(int elevel, PLpgSQL_condition_info_item *con_item, bool is_warning_throw, int is_signal) +static void StoreSignalError(int elevel, int code, PLpgSQL_condition_info_item *con_item, bool is_warning_throw, int is_signal) { ereport(elevel, - (errcode(con_item->sqlerrcode ? con_item->sqlerrcode : 0), + (errcode(code), errmsg_internal("%s", con_item->message_text), (con_item->sqlstate != NULL) ? signal_returnd_sqlstate(con_item->sqlstate) : 0, (con_item->class_origin != NULL) ? signal_class_origin(con_item->class_origin) : 0, @@ -6467,6 +6470,7 @@ static void StoreSignalError(int elevel, PLpgSQL_condition_info_item *con_item, (con_item->table_name != NULL) ? signal_table_name(con_item->table_name) : 0, (con_item->column_name != NULL) ? signal_column_name(con_item->column_name) : 0, (con_item->cursor_name != NULL) ? signal_cursor_name(con_item->cursor_name) : 0, + (con_item->sqlerrcode != NULL) ? signal_mysql_errno(con_item->sqlerrcode) : 0, signal_is_warnings_throw(is_warning_throw), signal_is_signal(is_signal))); @@ -6486,6 +6490,7 @@ static void exec_free_con_item(PLpgSQL_condition_info_item *con_item) FREE_POINTER(con_item->table_name); FREE_POINTER(con_item->column_name); FREE_POINTER(con_item->cursor_name); + FREE_POINTER(con_item->sqlerrcode); FREE_POINTER(con_item); } @@ -6502,7 +6507,6 @@ static int exec_stmt_signal(PLpgSQL_execstate* estate, PLpgSQL_stmt_signal* stmt bool is_warning_throw = false;; PLpgSQL_condition_info_item *con_item = (PLpgSQL_condition_info_item *)palloc0(sizeof(PLpgSQL_condition_info_item)); - con_item->sqlerrcode = stmt->sqlerrstate; /* sqlsate is not null */ if (sqlstate == NULL) { @@ -6515,20 +6519,20 @@ static int exec_stmt_signal(PLpgSQL_execstate* estate, PLpgSQL_stmt_signal* stmt if (sqlstate[0] == '0' && sqlstate[1] == '1') { con_item->message_text = pstrdup("Unhandled user-defined warning condition"); - con_item->sqlerrcode = MAKE_SQLSTATE('0', '1', '0', '0', '0'); + con_item->sqlerrcode = pstrdup("01000"); elevel = WARNING; is_warning_throw = is_declare_handler; } else if (sqlstate[0] == '0' && sqlstate[1] == '2') { con_item->message_text = pstrdup("Unhandled user-defined not found condition"); - con_item->sqlerrcode = MAKE_SQLSTATE('0', '2', '0', '0', '0'); + con_item->sqlerrcode = pstrdup("02000"); } else { con_item->message_text = pstrdup("Unhandled user-defined exception condition"); - con_item->sqlerrcode = MAKE_SQLSTATE('0', '3', '0', '0', '0'); + con_item->sqlerrcode = pstrdup("03000"); } exec_get_condition_information(estate, stmt, con_item); - StoreSignalError(elevel, con_item, is_warning_throw, PLpgSQL_signal_resignal::PLPGSQL_SIGNAL); + StoreSignalError(elevel, stmt->sqlerrstate, con_item, is_warning_throw, PLpgSQL_signal_resignal::PLPGSQL_SIGNAL); exec_free_con_item(con_item); return PLPGSQL_RC_OK; @@ -6550,7 +6554,7 @@ static int exec_stmt_resignal(PLpgSQL_execstate* estate, PLpgSQL_stmt_signal* st PLpgSQL_condition_info_item *con_item = (PLpgSQL_condition_info_item *)palloc0(sizeof(PLpgSQL_condition_info_item)); con_item->message_text = pstrdup(cur_errdata->message); - con_item->sqlerrcode = cur_errdata->sqlerrcode; + con_item->sqlerrcode = pstrdup(cur_errdata->mysql_errno); if (sqlstate != NULL) { has_sqlstate = true; con_item->sqlstate = pstrdup(sqlstate); @@ -6560,22 +6564,22 @@ static int exec_stmt_resignal(PLpgSQL_execstate* estate, PLpgSQL_stmt_signal* st if (sqlstate != NULL) { if (sqlstate[0] == '0' && sqlstate[1] == '1') { - con_item->sqlerrcode = MAKE_SQLSTATE('0', '1', '0', '0', '0'); + con_item->sqlerrcode = pstrdup("01000"); elevel = WARNING; is_warning_throw = is_declare_handler; } else if (sqlstate[0] == '0' && sqlstate[1] == '2') { - con_item->sqlerrcode = MAKE_SQLSTATE('0', '2', '0', '0', '0'); + con_item->sqlerrcode = pstrdup("02000"); } else { - con_item->sqlerrcode = MAKE_SQLSTATE('0', '3', '0', '0', '0'); + con_item->sqlerrcode = pstrdup("03000"); } } exec_get_condition_information(estate, stmt, con_item); if (has_sqlstate) { - StoreSignalError(elevel, con_item, is_warning_throw, PLpgSQL_signal_resignal::PLPGSQL_RESIGNAL_WITH_SQLSTATE); + StoreSignalError(elevel, cur_errdata->sqlerrcode, con_item, is_warning_throw, PLpgSQL_signal_resignal::PLPGSQL_RESIGNAL_WITH_SQLSTATE); } else { - StoreSignalError(elevel, con_item, is_warning_throw, PLpgSQL_signal_resignal::PLPGSQL_RESIGNAL_WITHOUT_SQLSTATE); + StoreSignalError(elevel, cur_errdata->sqlerrcode, con_item, is_warning_throw, PLpgSQL_signal_resignal::PLPGSQL_RESIGNAL_WITHOUT_SQLSTATE); } exec_free_con_item(con_item); diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index bc24df861..78a474dc0 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -260,6 +260,7 @@ extern int signal_schema_name(const char *schema_name); extern int signal_table_name(const char *table_name); extern int signal_column_name(const char *column_name); extern int signal_cursor_name(const char *cursor_name); +extern int signal_mysql_errno(const char *mysql_errno); extern int signal_is_signal(int is_signal); extern void save_error_message(void); @@ -535,6 +536,7 @@ typedef struct ErrorData { char* table_name; /* table_name for signal/resignal */ char* column_name; /* column_name for signal/resignal */ char* cursor_name; /* cursor_name for signal/resignal */ + char* mysql_errno; /* mysql_errno for signal/resignal */ bool is_warnings_throw; int is_signal; } ErrorData; diff --git a/src/include/utils/plpgsql.h b/src/include/utils/plpgsql.h index 22f4e7a99..b579514f4 100644 --- a/src/include/utils/plpgsql.h +++ b/src/include/utils/plpgsql.h @@ -972,7 +972,7 @@ typedef struct { /* condition information item name for signal/resignal */ char *table_name; char *column_name; char *cursor_name; - int sqlerrcode; /* mysql_errno */ + char *sqlerrcode; /* mysql_errno */ } PLpgSQL_condition_info_item; typedef struct { /* siganl_information_item */ diff --git a/src/test/regress/expected/mysql_condition.out b/src/test/regress/expected/mysql_condition.out index 596c2f440..e8fa6682b 100644 --- a/src/test/regress/expected/mysql_condition.out +++ b/src/test/regress/expected/mysql_condition.out @@ -973,9 +973,10 @@ call prc(); (1 row) show warnings; - level | code | message --------+------+--------- -(0 rows) + level | code | message +-------+-------+-------------------------------------------------------- + Error | 23502 | null value in column "c1" violates not-null constraint +(1 row) select @retSqlstate, @msg; @retsqlstate | @msg @@ -1234,13 +1235,13 @@ select @num1,@num2,@num3,@num4; select @msg1,@errno1; @msg1 | @errno1 ------------------------------------------+--------- - Unhandled user-defined warning condition | 64 + Unhandled user-defined warning condition | 01000 (1 row) select @msg2,@errno2; @msg2 | @errno2 ------------------------------------------+--------- - Unhandled user-defined warning condition | 64 + Unhandled user-defined warning condition | 01000 (1 row) select @msg3,@errno3; @@ -1302,13 +1303,13 @@ select @num1,@num2,@num3,@num4; select @msg1,@errno1; @msg1 | @errno1 ------------------------------------------+--------- - Unhandled user-defined warning condition | 64 + Unhandled user-defined warning condition | 01000 (1 row) select @msg2,@errno2; @msg2 | @errno2 ------------------------------------------+--------- - Unhandled user-defined warning condition | 64 + Unhandled user-defined warning condition | 01000 (1 row) select @msg3,@errno3; @@ -1320,7 +1321,7 @@ select @msg3,@errno3; select @msg4,@errno4; @msg4 | @errno4 ------------------------------------------+--------- - Unhandled user-defined warning condition | 64 + Unhandled user-defined warning condition | 01000 (1 row) CREATE or replace PROCEDURE p1() IS @@ -1370,13 +1371,13 @@ select @num1,@num2,@num3,@num4; select @msg1,@errno1; @msg1 | @errno1 ------------------------------------------+--------- - Unhandled user-defined warning condition | 64 + Unhandled user-defined warning condition | 01000 (1 row) select @msg2,@errno2; @msg2 | @errno2 ------------------------------------------+--------- - Unhandled user-defined warning condition | 64 + Unhandled user-defined warning condition | 01000 (1 row) select @msg3,@errno3; @@ -1388,7 +1389,7 @@ select @msg3,@errno3; select @msg4,@errno4; @msg4 | @errno4 ------------------------------------------+--------- - Unhandled user-defined warning condition | 64 + Unhandled user-defined warning condition | 01000 (1 row) drop procedure p1; @@ -1473,7 +1474,7 @@ SELECT @returned_sqlstate; @class_origin | @subclass_origin | @constraint_catalog | @constraint_schema | @constraint_name | @catalog_name | @schema_name | @table_name | @column_name | @cursor_name | @message_text | @mysql_errno | @returned_sqlstate ---------------+------------------+---------------------+--------------------+------------------+---------------+--------------+-------------+--------------+--------------+-----------------+--------------+-------------------- - (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | inout parameter | 64 | 01234 + (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | inout parameter | 01000 | 01234 (1 row) set @class_origin='',@subclass_origin='',@returned_sqlstate='',@message_text= '',@mysql_errno='',@constraint_catalog='',@constraint_schema='',@constraint_name='',@catalog_name='',@schema_name='',@table_name='',@column_name='',@cursor_name=''; @@ -1669,6 +1670,29 @@ CONTEXT: referenced column: stacked_diagnostics_test (1 row) +CREATE OR REPLACE PROCEDURE p_resig1() IS +begin +DECLARE EXIT HANDLER FOR SQLSTATE '42P01' +BEGIN +RESIGNAL; +END; +DROP TABLE t1; +end; +/ +call p_resig1(); + p_resig1 +---------- + +(1 row) + +get diagnostics condition 1 @p1 = CLASS_ORIGIN,@p2 = SUBCLASS_ORIGIN,@p3 = MESSAGE_TEXT,@p4 = MYSQL_ERRNO,@p5 = CONSTRAINT_CATALOG,@p6 = CONSTRAINT_SCHEMA, +@p7 = CONSTRAINT_NAME,@p8 = CATALOG_NAME,@p9 = SCHEMA_NAME,@p10 = TABLE_NAME,@p11 = COLUMN_NAME,@p12 = CURSOR_NAME; +select @p1,@p2,@p3,@p4; + @p1 | @p2 | @p3 | @p4 +-----+-----+-----+----- + | | | +(1 row) + \c regression -- test access to exception data create function zero_divide() returns int as $$ diff --git a/src/test/regress/expected/mysql_resignal.out b/src/test/regress/expected/mysql_resignal.out index c4a7f82f3..255b8f767 100644 --- a/src/test/regress/expected/mysql_resignal.out +++ b/src/test/regress/expected/mysql_resignal.out @@ -355,9 +355,9 @@ call p1(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p1() line 4 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) DROP TABLE IF EXISTS t1; @@ -375,9 +375,9 @@ call p1(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p1() line 4 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) CREATE OR REPLACE PROCEDURE p1() IS @@ -398,9 +398,9 @@ CONTEXT: PL/pgSQL function p1() line 4 at RESIGNAL (1 row) show warnings; - level | code | message ----------+------+------------------------------------------ - Warning | 64 | Unhandled user-defined warning condition + level | code | message +---------+-------+------------------------------------------ + Warning | 01000 | Unhandled user-defined warning condition (1 row) CREATE OR REPLACE PROCEDURE p1() IS @@ -416,9 +416,9 @@ call p1(); ERROR: Unhandled user-defined not found condition CONTEXT: PL/pgSQL function p1() line 4 at RESIGNAL show warnings; - level | code | message --------+------+-------------------------------------------- - Error | 128 | Unhandled user-defined not found condition + level | code | message +-------+-------+-------------------------------------------- + Error | 02000 | Unhandled user-defined not found condition (1 row) DROP TABLE IF EXISTS t1; @@ -437,9 +437,9 @@ call p1(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p1() line 5 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) DROP TABLE IF EXISTS t1; @@ -642,7 +642,7 @@ show warnings; level | code | message -------+-------+--------------------------- Error | 42P01 | table "t1" does not exist - Error | 192 | table is not defined + Error | 03000 | table is not defined (2 rows) DROP TABLE IF EXISTS t1; @@ -663,7 +663,7 @@ show warnings; level | code | message -------+-------+--------------------------- Error | 42P01 | table "t1" does not exist - Error | 192 | table "t1" does not exist + Error | 03000 | table "t1" does not exist (2 rows) DROP TABLE IF EXISTS t1; @@ -684,7 +684,7 @@ show warnings; level | code | message -------+-------+--------------------------- Error | 42P01 | table "t1" does not exist - Error | 192 | table "t1" does not exist + Error | 03000 | table "t1" does not exist (2 rows) DROP TABLE IF EXISTS t1; @@ -1045,10 +1045,10 @@ CONTEXT: PL/pgSQL function p1() line 3 at RESIGNAL (1 row) show warnings; - level | code | message ----------+------+------------------------------------------ - Warning | 64 | Unhandled user-defined warning condition - Warning | 1 | this is warnings + level | code | message +---------+-------+------------------------------------------ + Warning | 01000 | Unhandled user-defined warning condition + Warning | 1 | this is warnings (2 rows) CREATE OR REPLACE PROCEDURE p1(a out text) IS @@ -1335,8 +1335,8 @@ show warnings; level | code | message ---------+-------+--------------------------- Error | 42P01 | table "t1" does not exist - Warning | 64 | column is not defined2222 - Warning | 64 | column is not defined + Warning | 01000 | column is not defined2222 + Warning | 01000 | column is not defined (3 rows) DROP TABLE IF EXISTS t1; @@ -1366,8 +1366,8 @@ show warnings; level | code | message ---------+-------+--------------------------- Error | 42P01 | table "t1" does not exist - Warning | 64 | column is not defined2222 - Warning | 64 | column is not defined + Warning | 01000 | column is not defined2222 + Warning | 01000 | column is not defined (3 rows) DROP TABLE IF EXISTS t1; @@ -1397,8 +1397,8 @@ show warnings; level | code | message ---------+-------+--------------------------- Error | 42P01 | table "t1" does not exist - Error | 192 | column is not defined2222 - Warning | 64 | column is not defined + Error | 03000 | column is not defined2222 + Warning | 01000 | column is not defined (3 rows) DROP TABLE IF EXISTS t1; @@ -1516,8 +1516,8 @@ show warnings; level | code | message ---------+-------+--------------------------- Error | 42P01 | table "t1" does not exist - Warning | 64 | column is not defined2222 - Warning | 64 | column is not defined + Warning | 01000 | column is not defined2222 + Warning | 01000 | column is not defined (3 rows) DROP TABLE IF EXISTS t1; @@ -1607,9 +1607,9 @@ call p2(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p2() line 6 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) select @a, @error_count; @@ -1638,9 +1638,9 @@ call p2(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p2() line 6 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) select @a, @error_count; @@ -1732,9 +1732,9 @@ call p2(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p2() line 6 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) select @a, @error_count; @@ -1763,9 +1763,9 @@ call p2(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p2() line 6 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) select @a, @error_count; @@ -1794,9 +1794,9 @@ call p2(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p2() line 6 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) select @a, @error_count; @@ -1825,9 +1825,9 @@ call p2(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p2() line 6 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) select @a, @error_count; @@ -1856,9 +1856,9 @@ call p2(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p2() line 6 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) select @a, @error_count; @@ -1887,9 +1887,9 @@ call p2(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p2() line 6 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) select @a, @error_count; @@ -1918,9 +1918,9 @@ call p2(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p2() line 6 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) select @a, @error_count; @@ -1949,9 +1949,9 @@ call p2(); ERROR: table "t1" does not exist CONTEXT: PL/pgSQL function p2() line 6 at RESIGNAL show warnings; - level | code | message --------+----------+--------------------------- - Error | 16908420 | table "t1" does not exist + level | code | message +-------+-------+--------------------------- + Error | 42P01 | table "t1" does not exist (1 row) select @a, @error_count; diff --git a/src/test/regress/expected/mysql_signal.out b/src/test/regress/expected/mysql_signal.out index ec5a527fa..239846df6 100644 --- a/src/test/regress/expected/mysql_signal.out +++ b/src/test/regress/expected/mysql_signal.out @@ -137,9 +137,9 @@ CONTEXT: PL/pgSQL function p1() line 2 at SIGNAL (1 row) show warnings; - level | code | message ----------+------+------------------------------------------ - Warning | 64 | Unhandled user-defined warning condition + level | code | message +---------+-------+------------------------------------------ + Warning | 01000 | Unhandled user-defined warning condition (1 row) CREATE OR REPLACE PROCEDURE p1() IS @@ -151,9 +151,9 @@ call p1(); ERROR: Unhandled user-defined not found condition CONTEXT: PL/pgSQL function p1() line 2 at SIGNAL show warnings; - level | code | message --------+------+-------------------------------------------- - Error | 128 | Unhandled user-defined not found condition + level | code | message +-------+-------+-------------------------------------------- + Error | 02000 | Unhandled user-defined not found condition (1 row) CREATE OR REPLACE PROCEDURE p1() IS @@ -165,9 +165,9 @@ call p1(); ERROR: Unhandled user-defined exception condition CONTEXT: PL/pgSQL function p1() line 2 at SIGNAL show warnings; - level | code | message --------+------+-------------------------------------------- - Error | 192 | Unhandled user-defined exception condition + level | code | message +-------+-------+-------------------------------------------- + Error | 03000 | Unhandled user-defined exception condition (1 row) CREATE OR REPLACE PROCEDURE p1() IS @@ -179,9 +179,9 @@ call p1(); ERROR: Unhandled user-defined exception condition CONTEXT: PL/pgSQL function p1() line 2 at SIGNAL show warnings; - level | code | message --------+------+-------------------------------------------- - Error | 192 | Unhandled user-defined exception condition + level | code | message +-------+-------+-------------------------------------------- + Error | 03000 | Unhandled user-defined exception condition (1 row) -- parse error @@ -219,9 +219,9 @@ call p1(); ERROR: Unhandled user-defined exception condition CONTEXT: PL/pgSQL function p1() line 3 at SIGNAL show warnings; - level | code | message --------+------+-------------------------------------------- - Error | 192 | Unhandled user-defined exception condition + level | code | message +-------+-------+-------------------------------------------- + Error | 03000 | Unhandled user-defined exception condition (1 row) CREATE OR REPLACE PROCEDURE p1() IS @@ -239,9 +239,9 @@ CONTEXT: PL/pgSQL function p1() line 3 at SIGNAL (1 row) show warnings; - level | code | message ----------+------+------------------------------------------ - Warning | 64 | Unhandled user-defined warning condition + level | code | message +---------+-------+------------------------------------------ + Warning | 01000 | Unhandled user-defined warning condition (1 row) CREATE OR REPLACE PROCEDURE p1() IS @@ -254,9 +254,9 @@ call p1(); ERROR: Unhandled user-defined not found condition CONTEXT: PL/pgSQL function p1() line 3 at SIGNAL show warnings; - level | code | message --------+------+-------------------------------------------- - Error | 128 | Unhandled user-defined not found condition + level | code | message +-------+-------+-------------------------------------------- + Error | 02000 | Unhandled user-defined not found condition (1 row) -- parse_error @@ -280,9 +280,9 @@ CONTEXT: PL/pgSQL function p1() line 2 at SIGNAL ERROR: Unhandled user-defined not found condition CONTEXT: PL/pgSQL function p1() line 3 at SIGNAL show warnings; - level | code | message --------+------+-------------------------------------------- - Error | 128 | Unhandled user-defined not found condition + level | code | message +-------+-------+-------------------------------------------- + Error | 02000 | Unhandled user-defined not found condition (1 row) -- 2.signa with SQLSTATE and signal_information_item @@ -629,9 +629,9 @@ call p1(0); ERROR: Unhandled user-defined exception condition CONTEXT: PL/pgSQL function p1() line 2 at SIGNAL show warnings; - level | code | message --------+------+-------------------------------------------- - Error | 192 | Unhandled user-defined exception condition + level | code | message +-------+-------+-------------------------------------------- + Error | 03000 | Unhandled user-defined exception condition (1 row) DROP TABLE IF EXISTS t1; @@ -647,9 +647,9 @@ call p1(0); ERROR: Unhandled user-defined exception condition CONTEXT: PL/pgSQL function p1() line 2 at SIGNAL show warnings; - level | code | message --------+------+-------------------------------------------- - Error | 192 | Unhandled user-defined exception condition + level | code | message +-------+-------+-------------------------------------------- + Error | 03000 | Unhandled user-defined exception condition (1 row) DROP TABLE IF EXISTS t1; @@ -665,9 +665,9 @@ call p1(0); ERROR: the table is not exist CONTEXT: PL/pgSQL function p1() line 2 at SIGNAL show warnings; - level | code | message --------+------+------------------------ - Error | 192 | the table is not exist + level | code | message +-------+-------+------------------------ + Error | 03000 | the table is not exist (1 row) DROP TABLE IF EXISTS t1; @@ -709,9 +709,9 @@ call p1(0); ERROR: Unhandled user-defined exception condition CONTEXT: PL/pgSQL function p1() line 5 at SIGNAL show warnings; - level | code | message --------+------+-------------------------------------------- - Error | 192 | Unhandled user-defined exception condition + level | code | message +-------+-------+-------------------------------------------- + Error | 03000 | Unhandled user-defined exception condition (1 row) DROP TABLE IF EXISTS t1; @@ -1214,9 +1214,9 @@ CONTEXT: PL/pgSQL function p1() line 6 at SIGNAL (1 row) show warnings; - level | code | message ----------+------+----------------------- - Warning | 64 | column is not defined + level | code | message +---------+-------+----------------------- + Warning | 01000 | column is not defined (1 row) DROP TABLE IF EXISTS t1; @@ -1243,9 +1243,9 @@ CONTEXT: PL/pgSQL function p1() line 6 at SIGNAL (1 row) show warnings; - level | code | message ----------+------+----------------------- - Warning | 64 | column is not defined + level | code | message +---------+-------+----------------------- + Warning | 01000 | column is not defined (1 row) DROP TABLE IF EXISTS t1; @@ -1272,9 +1272,9 @@ CONTEXT: PL/pgSQL function p1() line 6 at SIGNAL (1 row) show warnings; - level | code | message ----------+------+----------------------- - Warning | 64 | column is not defined + level | code | message +---------+-------+----------------------- + Warning | 01000 | column is not defined (1 row) DROP TABLE IF EXISTS t1; @@ -1389,9 +1389,9 @@ CONTEXT: PL/pgSQL function p1() line 6 at SIGNAL (1 row) show warnings; - level | code | message ----------+------+----------------------- - Warning | 64 | column is not defined + level | code | message +---------+-------+----------------------- + Warning | 01000 | column is not defined (1 row) DROP TABLE IF EXISTS t1; @@ -1452,9 +1452,9 @@ call p2(); ERROR: an error occurred CONTEXT: PL/pgSQL function p2() line 4 at SIGNAL show warnings; - level | code | message --------+------+------------------- - Error | 192 | an error occurred + level | code | message +-------+-------+------------------- + Error | 03000 | an error occurred (1 row) CREATE OR REPLACE PROCEDURE p2(pval int) IS @@ -1481,27 +1481,27 @@ CONTEXT: PL/pgSQL function p2(integer) line 4 at SIGNAL (1 row) show warnings; - level | code | message ----------+------+------------------------------------------ - Warning | 64 | Unhandled user-defined warning condition + level | code | message +---------+-------+------------------------------------------ + Warning | 01000 | Unhandled user-defined warning condition (1 row) call p2(1); ERROR: an error occurred for 1 CONTEXT: PL/pgSQL function p2(integer) line 6 at SIGNAL show warnings; - level | code | message --------+------+------------------------- - Error | 192 | an error occurred for 1 + level | code | message +-------+-------+------------------------- + Error | 03000 | an error occurred for 1 (1 row) call p2(2); ERROR: an error occurred for 2 CONTEXT: PL/pgSQL function p2(integer) line 8 at SIGNAL show warnings; - level | code | message --------+------+------------------------- - Error | 192 | an error occurred for 2 + level | code | message +-------+-------+------------------------- + Error | 03000 | an error occurred for 2 (1 row) call p2(3); diff --git a/src/test/regress/sql/mysql_condition.sql b/src/test/regress/sql/mysql_condition.sql index f40ee0072..f208d80b0 100644 --- a/src/test/regress/sql/mysql_condition.sql +++ b/src/test/regress/sql/mysql_condition.sql @@ -1094,6 +1094,19 @@ end; $$ language plpgsql; select stacked_diagnostics_test(); +CREATE OR REPLACE PROCEDURE p_resig1() IS +begin +DECLARE EXIT HANDLER FOR SQLSTATE '42P01' +BEGIN +RESIGNAL; +END; +DROP TABLE t1; +end; +/ +call p_resig1(); +get diagnostics condition 1 @p1 = CLASS_ORIGIN,@p2 = SUBCLASS_ORIGIN,@p3 = MESSAGE_TEXT,@p4 = MYSQL_ERRNO,@p5 = CONSTRAINT_CATALOG,@p6 = CONSTRAINT_SCHEMA, +@p7 = CONSTRAINT_NAME,@p8 = CATALOG_NAME,@p9 = SCHEMA_NAME,@p10 = TABLE_NAME,@p11 = COLUMN_NAME,@p12 = CURSOR_NAME; +select @p1,@p2,@p3,@p4; \c regression -- test access to exception data create function zero_divide() returns int as $$