Skip to content

Commit b73b736

Browse files
committed
refactor THD::raise_condition() family
to remove Sql_condition* raise_condition(const Sql_condition *cond) { Sql_condition *raised= raise_condition(cond->get_sql_errno(), cond->get_sqlstate(), cond->get_level(), *cond, cond->get_message_text()); return raised; }
1 parent a398fcb commit b73b736

File tree

10 files changed

+79
-120
lines changed

10 files changed

+79
-120
lines changed

sql/mysqld.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3269,7 +3269,7 @@ void my_message_sql(uint error, const char *str, myf MyFlags)
32693269
{
32703270
if (unlikely(MyFlags & ME_FATAL))
32713271
thd->is_fatal_error= 1;
3272-
(void) thd->raise_condition(error, NULL, level, str);
3272+
(void) thd->raise_condition(error, "\0\0\0\0\0", level, str);
32733273
}
32743274
else
32753275
mysql_audit_general(0, MYSQL_AUDIT_GENERAL_ERROR, error, str);

sql/sql_class.cc

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -965,10 +965,8 @@ Internal_error_handler *THD::pop_internal_handler()
965965
void THD::raise_error(uint sql_errno)
966966
{
967967
const char* msg= ER_THD(this, sql_errno);
968-
(void) raise_condition(sql_errno,
969-
NULL,
970-
Sql_condition::WARN_LEVEL_ERROR,
971-
msg);
968+
(void) raise_condition(sql_errno, "\0\0\0\0\0",
969+
Sql_condition::WARN_LEVEL_ERROR, msg);
972970
}
973971

974972
void THD::raise_error_printf(uint sql_errno, ...)
@@ -981,20 +979,16 @@ void THD::raise_error_printf(uint sql_errno, ...)
981979
va_start(args, sql_errno);
982980
my_vsnprintf(ebuff, sizeof(ebuff), format, args);
983981
va_end(args);
984-
(void) raise_condition(sql_errno,
985-
NULL,
986-
Sql_condition::WARN_LEVEL_ERROR,
987-
ebuff);
982+
(void) raise_condition(sql_errno, "\0\0\0\0\0",
983+
Sql_condition::WARN_LEVEL_ERROR, ebuff);
988984
DBUG_VOID_RETURN;
989985
}
990986

991987
void THD::raise_warning(uint sql_errno)
992988
{
993989
const char* msg= ER_THD(this, sql_errno);
994-
(void) raise_condition(sql_errno,
995-
NULL,
996-
Sql_condition::WARN_LEVEL_WARN,
997-
msg);
990+
(void) raise_condition(sql_errno, "\0\0\0\0\0",
991+
Sql_condition::WARN_LEVEL_WARN, msg);
998992
}
999993

1000994
void THD::raise_warning_printf(uint sql_errno, ...)
@@ -1007,10 +1001,8 @@ void THD::raise_warning_printf(uint sql_errno, ...)
10071001
va_start(args, sql_errno);
10081002
my_vsnprintf(ebuff, sizeof(ebuff), format, args);
10091003
va_end(args);
1010-
(void) raise_condition(sql_errno,
1011-
NULL,
1012-
Sql_condition::WARN_LEVEL_WARN,
1013-
ebuff);
1004+
(void) raise_condition(sql_errno, "\0\0\0\0\0",
1005+
Sql_condition::WARN_LEVEL_WARN, ebuff);
10141006
DBUG_VOID_RETURN;
10151007
}
10161008

@@ -1021,10 +1013,8 @@ void THD::raise_note(uint sql_errno)
10211013
if (!(variables.option_bits & OPTION_SQL_NOTES))
10221014
DBUG_VOID_RETURN;
10231015
const char* msg= ER_THD(this, sql_errno);
1024-
(void) raise_condition(sql_errno,
1025-
NULL,
1026-
Sql_condition::WARN_LEVEL_NOTE,
1027-
msg);
1016+
(void) raise_condition(sql_errno, "\0\0\0\0\0",
1017+
Sql_condition::WARN_LEVEL_NOTE, msg);
10281018
DBUG_VOID_RETURN;
10291019
}
10301020

@@ -1040,21 +1030,20 @@ void THD::raise_note_printf(uint sql_errno, ...)
10401030
va_start(args, sql_errno);
10411031
my_vsnprintf(ebuff, sizeof(ebuff), format, args);
10421032
va_end(args);
1043-
(void) raise_condition(sql_errno,
1044-
NULL,
1045-
Sql_condition::WARN_LEVEL_NOTE,
1046-
ebuff);
1033+
(void) raise_condition(sql_errno, "\0\0\0\0\0",
1034+
Sql_condition::WARN_LEVEL_NOTE, ebuff);
10471035
DBUG_VOID_RETURN;
10481036
}
10491037

1050-
Sql_condition* THD::raise_condition(uint sql_errno,
1051-
const char* sqlstate,
1052-
Sql_condition::enum_warning_level level,
1053-
const Sql_user_condition_identity &ucid,
1054-
const char* msg)
1038+
Sql_condition* THD::raise_condition(const Sql_condition *cond)
10551039
{
1040+
uint sql_errno= cond->get_sql_errno();
1041+
const char *sqlstate= cond->get_sqlstate();
1042+
Sql_condition::enum_warning_level level= cond->get_level();
1043+
const char *msg= cond->get_message_text();
1044+
10561045
Diagnostics_area *da= get_stmt_da();
1057-
Sql_condition *cond= NULL;
1046+
Sql_condition *raised= NULL;
10581047
DBUG_ENTER("THD::raise_condition");
10591048
DBUG_ASSERT(level < Sql_condition::WARN_LEVEL_END);
10601049

@@ -1082,22 +1071,18 @@ Sql_condition* THD::raise_condition(uint sql_errno,
10821071
sql_errno= ER_UNKNOWN_ERROR;
10831072
if (msg == NULL)
10841073
msg= ER_THD(this, sql_errno);
1085-
if (sqlstate == NULL)
1074+
if (!*sqlstate)
10861075
sqlstate= mysql_errno_to_sqlstate(sql_errno);
10871076

1088-
if ((level == Sql_condition::WARN_LEVEL_WARN) &&
1089-
really_abort_on_warning())
1077+
if ((level == Sql_condition::WARN_LEVEL_WARN) && really_abort_on_warning())
10901078
{
1091-
/*
1092-
FIXME:
1093-
push_warning and strict SQL_MODE case.
1094-
*/
1079+
/* FIXME: push_warning and strict SQL_MODE case. */
10951080
level= Sql_condition::WARN_LEVEL_ERROR;
10961081
}
10971082

10981083
if (!is_fatal_error &&
1099-
handle_condition(sql_errno, sqlstate, &level, msg, &cond))
1100-
DBUG_RETURN(cond);
1084+
handle_condition(sql_errno, sqlstate, &level, msg, &raised))
1085+
goto ret;
11011086

11021087
switch (level) {
11031088
case Sql_condition::WARN_LEVEL_NOTE:
@@ -1122,8 +1107,7 @@ Sql_condition* THD::raise_condition(uint sql_errno,
11221107
With wsrep we allow converting BF abort error to warning if
11231108
errors are ignored.
11241109
*/
1125-
if (!is_fatal_error &&
1126-
no_errors &&
1110+
if (!is_fatal_error && no_errors &&
11271111
(wsrep_trx().bf_aborted() || wsrep_retry_counter))
11281112
{
11291113
WSREP_DEBUG("BF abort error converted to warning");
@@ -1134,7 +1118,7 @@ Sql_condition* THD::raise_condition(uint sql_errno,
11341118
if (!da->is_error())
11351119
{
11361120
set_row_count_func(-1);
1137-
da->set_error_status(sql_errno, msg, sqlstate, ucid, cond);
1121+
da->set_error_status(sql_errno, msg, sqlstate, *cond, raised);
11381122
}
11391123
}
11401124
}
@@ -1149,10 +1133,13 @@ Sql_condition* THD::raise_condition(uint sql_errno,
11491133
if (likely(!(is_fatal_error && (sql_errno == EE_OUTOFMEMORY ||
11501134
sql_errno == ER_OUTOFMEMORY))))
11511135
{
1152-
cond= da->push_warning(this, sql_errno, sqlstate, level, ucid, msg,
1153-
da->current_row_for_warning());
1136+
raised= da->push_warning(this, sql_errno, sqlstate, level, *cond, msg,
1137+
cond->m_row_number);
11541138
}
1155-
DBUG_RETURN(cond);
1139+
ret:
1140+
if (raised)
1141+
raised->copy_opt_attributes(cond);
1142+
DBUG_RETURN(raised);
11561143
}
11571144

11581145
extern "C"

sql/sql_class.h

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4801,45 +4801,17 @@ class THD: public THD_count, /* this must be first */
48014801
@param msg the condition message text
48024802
@return The condition raised, or NULL
48034803
*/
4804-
Sql_condition*
4805-
raise_condition(uint sql_errno,
4806-
const char* sqlstate,
4807-
Sql_condition::enum_warning_level level,
4808-
const char* msg)
4804+
Sql_condition* raise_condition(uint sql_errno, const char* sqlstate,
4805+
Sql_condition::enum_warning_level level, const char* msg)
48094806
{
4810-
return raise_condition(sql_errno, sqlstate, level,
4811-
Sql_user_condition_identity(), msg);
4807+
Sql_condition cond(NULL, // don't strdup the msg
4808+
Sql_condition_identity(sql_errno, sqlstate, level,
4809+
Sql_user_condition_identity()),
4810+
msg, get_stmt_da()->current_row_for_warning());
4811+
return raise_condition(&cond);
48124812
}
48134813

4814-
/**
4815-
Raise a generic or a user defined SQL condition.
4816-
@param ucid - the user condition identity
4817-
(or an empty identity if not a user condition)
4818-
@param sql_errno - the condition error number
4819-
@param sqlstate - the condition SQLSTATE
4820-
@param level - the condition level
4821-
@param msg - the condition message text
4822-
@return The condition raised, or NULL
4823-
*/
4824-
Sql_condition*
4825-
raise_condition(uint sql_errno,
4826-
const char* sqlstate,
4827-
Sql_condition::enum_warning_level level,
4828-
const Sql_user_condition_identity &ucid,
4829-
const char* msg);
4830-
4831-
Sql_condition*
4832-
raise_condition(const Sql_condition *cond)
4833-
{
4834-
Sql_condition *raised= raise_condition(cond->get_sql_errno(),
4835-
cond->get_sqlstate(),
4836-
cond->get_level(),
4837-
*cond/*Sql_user_condition_identity*/,
4838-
cond->get_message_text());
4839-
if (raised)
4840-
raised->copy_opt_attributes(cond);
4841-
return raised;
4842-
}
4814+
Sql_condition* raise_condition(const Sql_condition *cond);
48434815

48444816
private:
48454817
void push_warning_truncated_priv(Sql_condition::enum_warning_level level,

sql/sql_error.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Sql_condition::set_builtin_message_text(const char* str)
217217
*/
218218
const char* copy;
219219

220-
copy= strdup_root(m_mem_root, str);
220+
copy= m_mem_root ? strdup_root(m_mem_root, str) : str;
221221
m_message_text.set(copy, strlen(copy), error_message_charset_info);
222222
DBUG_ASSERT(! m_message_text.is_alloced());
223223
}
@@ -727,7 +727,7 @@ void push_warning(THD *thd, Sql_condition::enum_warning_level level,
727727
if (level == Sql_condition::WARN_LEVEL_ERROR)
728728
level= Sql_condition::WARN_LEVEL_WARN;
729729

730-
(void) thd->raise_condition(code, NULL, level, msg);
730+
(void) thd->raise_condition(code, "\0\0\0\0\0", level, msg);
731731

732732
/* Make sure we also count warnings pushed after calling set_ok_status(). */
733733
thd->get_stmt_da()->increment_warning();

sql/sql_error.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ class Sql_condition : public Sql_alloc,
443443
const char *msg, ulong current_row_for_warning)
444444
: Sql_condition_identity(value), m_mem_root(mem_root)
445445
{
446-
DBUG_ASSERT(mem_root != NULL);
447446
DBUG_ASSERT(value.get_sql_errno() != 0);
448447
DBUG_ASSERT(msg != NULL);
449448
set_builtin_message_text(msg);
@@ -746,10 +745,8 @@ class Warning_info
746745
747746
@return a pointer to the added SQL-condition.
748747
*/
749-
Sql_condition *push_warning(THD *thd,
750-
const Sql_condition_identity *identity,
751-
const char* msg,
752-
ulong current_row_number);
748+
Sql_condition *push_warning(THD *thd, const Sql_condition_identity *identity,
749+
const char* msg, ulong current_row_number);
753750

754751
/**
755752
Add a new SQL-condition to the current list and increment the respective

storage/connect/bsonudf.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/*********************************************************************************/
1010
#include <my_global.h>
1111
#include <mysqld.h>
12+
#include <mysqld_error.h>
1213
#include <mysql.h>
1314
#include <sql_error.h>
1415
#include <stdio.h>
@@ -22,7 +23,7 @@
2223

2324
#define MEMFIX 4096
2425
#if defined(connect_EXPORTS)
25-
#define PUSH_WARNING(M) push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, M)
26+
#define PUSH_WARNING(M) push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, M)
2627
#else
2728
#define PUSH_WARNING(M) htrc(M)
2829
#endif

0 commit comments

Comments
 (0)