diff options
author | Monty <monty@mariadb.org> | 2015-07-06 20:24:14 +0300 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2015-07-06 20:24:14 +0300 |
commit | 7332af49e4ce125a5e316e7e0c82d44df4af54c4 (patch) | |
tree | 179f863cbb314d7610bf12e1b0ffb785d6ea26e9 /sql | |
parent | 8d4d185a08cd758d552d233c26f68af4caa28388 (diff) | |
download | mariadb-git-7332af49e4ce125a5e316e7e0c82d44df4af54c4.tar.gz |
- Renaming variables so that they don't shadow others (After this patch one can compile with -Wshadow and get much fewer warnings)
- Changed ER(ER_...) to ER_THD(thd, ER_...) when thd was known or if there was many calls to current_thd in the same function.
- Changed ER(ER_..) to ER_THD_OR_DEFAULT(current_thd, ER...) in some places where current_thd is not necessary defined.
- Removing calls to current_thd when we have access to thd
Part of this is optimization (not calling current_thd when not needed),
but part is bug fixing for error condition when current_thd is not defined
(For example on startup and end of mysqld)
Notable renames done as otherwise a lot of functions would have to be changed:
- In JOIN structure renamed:
examined_rows -> join_examined_rows
record_count -> join_record_count
- In Field, renamed new_field() to make_new_field()
Other things:
- Added DBUG_ASSERT(thd == tmp_thd) in Item_singlerow_subselect() just to be safe.
- Removed old 'tab' prefix in JOIN_TAB::save_explain_data() and use members directly
- Added 'thd' as argument to a few functions to avoid calling current_thd.
Diffstat (limited to 'sql')
94 files changed, 1513 insertions, 1239 deletions
diff --git a/sql/create_options.cc b/sql/create_options.cc index c3796710f78..66515be05b8 100644 --- a/sql/create_options.cc +++ b/sql/create_options.cc @@ -88,7 +88,7 @@ static bool report_wrong_value(THD *thd, const char *name, const char *val, } push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_BAD_OPTION_VALUE, - ER(ER_BAD_OPTION_VALUE), val, name); + ER_THD(thd, ER_BAD_OPTION_VALUE), val, name); return 0; } @@ -111,7 +111,8 @@ static bool report_unknown_option(THD *thd, engine_option_value *val, } push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_UNKNOWN_OPTION, ER(ER_UNKNOWN_OPTION), val->name.str); + ER_UNKNOWN_OPTION, ER_THD(thd, ER_UNKNOWN_OPTION), + val->name.str); DBUG_RETURN(FALSE); } diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index 2ace83ca751..8b3412eb732 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -1451,7 +1451,8 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action) const bool save_abort_on_warning= thd->abort_on_warning; thd->abort_on_warning= false; push_warning(thd, Sql_condition::WARN_LEVEL_WARN, - ER_DEBUG_SYNC_TIMEOUT, ER(ER_DEBUG_SYNC_TIMEOUT)); + ER_DEBUG_SYNC_TIMEOUT, + ER_THD(thd, ER_DEBUG_SYNC_TIMEOUT)); thd->abort_on_warning= save_abort_on_warning; DBUG_EXECUTE_IF("debug_sync_abort_on_timeout", DBUG_ABORT();); break; diff --git a/sql/derror.cc b/sql/derror.cc index 7ac068300f9..bc4b89493aa 100644 --- a/sql/derror.cc +++ b/sql/derror.cc @@ -244,20 +244,20 @@ static void init_myfunc_errs() init_glob_errs(); /* Initiate english errors */ if (!(specialflag & SPECIAL_ENGLISH)) { - EE(EE_FILENOTFOUND) = ER(ER_FILE_NOT_FOUND); - EE(EE_CANTCREATEFILE) = ER(ER_CANT_CREATE_FILE); - EE(EE_READ) = ER(ER_ERROR_ON_READ); - EE(EE_WRITE) = ER(ER_ERROR_ON_WRITE); - EE(EE_BADCLOSE) = ER(ER_ERROR_ON_CLOSE); - EE(EE_OUTOFMEMORY) = ER(ER_OUTOFMEMORY); - EE(EE_DELETE) = ER(ER_CANT_DELETE_FILE); - EE(EE_LINK) = ER(ER_ERROR_ON_RENAME); - EE(EE_EOFERR) = ER(ER_UNEXPECTED_EOF); - EE(EE_CANTLOCK) = ER(ER_CANT_LOCK); - EE(EE_DIR) = ER(ER_CANT_READ_DIR); - EE(EE_STAT) = ER(ER_CANT_GET_STAT); - EE(EE_GETWD) = ER(ER_CANT_GET_WD); - EE(EE_SETWD) = ER(ER_CANT_SET_WD); - EE(EE_DISK_FULL) = ER(ER_DISK_FULL); + EE(EE_FILENOTFOUND) = ER_DEFAULT(ER_FILE_NOT_FOUND); + EE(EE_CANTCREATEFILE) = ER_DEFAULT(ER_CANT_CREATE_FILE); + EE(EE_READ) = ER_DEFAULT(ER_ERROR_ON_READ); + EE(EE_WRITE) = ER_DEFAULT(ER_ERROR_ON_WRITE); + EE(EE_BADCLOSE) = ER_DEFAULT(ER_ERROR_ON_CLOSE); + EE(EE_OUTOFMEMORY) = ER_DEFAULT(ER_OUTOFMEMORY); + EE(EE_DELETE) = ER_DEFAULT(ER_CANT_DELETE_FILE); + EE(EE_LINK) = ER_DEFAULT(ER_ERROR_ON_RENAME); + EE(EE_EOFERR) = ER_DEFAULT(ER_UNEXPECTED_EOF); + EE(EE_CANTLOCK) = ER_DEFAULT(ER_CANT_LOCK); + EE(EE_DIR) = ER_DEFAULT(ER_CANT_READ_DIR); + EE(EE_STAT) = ER_DEFAULT(ER_CANT_GET_STAT); + EE(EE_GETWD) = ER_DEFAULT(ER_CANT_GET_WD); + EE(EE_SETWD) = ER_DEFAULT(ER_CANT_SET_WD); + EE(EE_DISK_FULL) = ER_DEFAULT(ER_DISK_FULL); } } diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index 571652de861..9e1ee6f30f9 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -610,7 +610,7 @@ Event_timed::load_from_row(THD *thd, TABLE *table) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_EVENT_INVALID_CREATION_CTX, - ER(ER_EVENT_INVALID_CREATION_CTX), + ER_THD(thd, ER_EVENT_INVALID_CREATION_CTX), (const char *) dbname.str, (const char *) name.str); } diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc index 53b3e96c323..e39f727800a 100644 --- a/sql/event_db_repository.cc +++ b/sql/event_db_repository.cc @@ -695,7 +695,8 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data, { *event_already_exists= true; push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_EVENT_ALREADY_EXISTS, ER(ER_EVENT_ALREADY_EXISTS), + ER_EVENT_ALREADY_EXISTS, + ER_THD(thd, ER_EVENT_ALREADY_EXISTS), parse_data->name.str); ret= 0; goto end; @@ -922,7 +923,7 @@ Event_db_repository::drop_event(THD *thd, LEX_STRING db, LEX_STRING name, } push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), + ER_SP_DOES_NOT_EXIST, ER_THD(thd, ER_SP_DOES_NOT_EXIST), "Event", name.str); ret= 0; diff --git a/sql/event_parse_data.cc b/sql/event_parse_data.cc index c2b460f02ab..6c123c8e641 100644 --- a/sql/event_parse_data.cc +++ b/sql/event_parse_data.cc @@ -129,7 +129,7 @@ Event_parse_data::check_if_in_the_past(THD *thd, my_time_t ltime_utc) case SQLCOM_CREATE_EVENT: push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_EVENT_CANNOT_CREATE_IN_THE_PAST, - ER(ER_EVENT_CANNOT_CREATE_IN_THE_PAST)); + ER_THD(thd, ER_EVENT_CANNOT_CREATE_IN_THE_PAST)); break; case SQLCOM_ALTER_EVENT: my_error(ER_EVENT_CANNOT_ALTER_IN_THE_PAST, MYF(0)); @@ -146,7 +146,7 @@ Event_parse_data::check_if_in_the_past(THD *thd, my_time_t ltime_utc) status_changed= true; push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_EVENT_EXEC_TIME_IN_THE_PAST, - ER(ER_EVENT_EXEC_TIME_IN_THE_PAST)); + ER_THD(thd, ER_EVENT_EXEC_TIME_IN_THE_PAST)); } } diff --git a/sql/field.cc b/sql/field.cc index 3fcae19237b..81334aff39c 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1073,15 +1073,15 @@ static void push_numerical_conversion_warning(THD* thd, const char* str, const char* field_name="UNKNOWN", ulong row_num=0) { - char buf[MY_MAX(MY_MAX(DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE, - LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE), - DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE)]; + char buf[MY_MAX(MY_MAX(DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE, + LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE), + DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE)]; - String tmp(buf, sizeof(buf), cs); - tmp.copy(str, length, cs); - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - error, ER(error), typestr, tmp.c_ptr(), - field_name, row_num); + String tmp(buf, sizeof(buf), cs); + tmp.copy(str, length, cs); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + error, ER_THD(thd, error), typestr, tmp.c_ptr(), + field_name, row_num); } @@ -1958,8 +1958,8 @@ bool Field::optimize_range(uint idx, uint part) } -Field *Field::new_field(MEM_ROOT *root, TABLE *new_table, - bool keep_type __attribute__((unused))) +Field *Field::make_new_field(MEM_ROOT *root, TABLE *new_table, + bool keep_type __attribute__((unused))) { Field *tmp; if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of()))) @@ -1988,7 +1988,7 @@ Field *Field::new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_null_ptr, uint new_null_bit) { Field *tmp; - if ((tmp= new_field(root, new_table, table == new_table))) + if ((tmp= make_new_field(root, new_table, table == new_table))) { tmp->ptr= new_ptr; tmp->null_ptr= new_null_ptr; @@ -2935,7 +2935,7 @@ int Field_new_decimal::store_decimal(const my_decimal *decimal_value) } -int Field_new_decimal::store_time_dec(MYSQL_TIME *ltime, uint dec) +int Field_new_decimal::store_time_dec(MYSQL_TIME *ltime, uint dec_arg) { my_decimal decimal_value; return store_value(date2my_decimal(ltime, &decimal_value)); @@ -3131,7 +3131,7 @@ Field_new_decimal::unpack(uchar* to, const uchar *from, const uchar *from_end, return from+len; } -int Field_num::store_time_dec(MYSQL_TIME *ltime, uint dec) +int Field_num::store_time_dec(MYSQL_TIME *ltime, uint dec_arg) { longlong v= TIME_to_ulonglong(ltime); if (ltime->neg == 0) @@ -4396,7 +4396,7 @@ int Field_real::store_decimal(const my_decimal *dm) return store(dbl); } -int Field_real::store_time_dec(MYSQL_TIME *ltime, uint dec) +int Field_real::store_time_dec(MYSQL_TIME *ltime, uint dec_arg) { return store(TIME_to_double(ltime)); } @@ -4421,10 +4421,11 @@ longlong Field_double::val_int(void) res= double_to_longlong(j, 0, &error); if (error) { + THD *thd= get_thd(); ErrConvDouble err(j); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER", + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", err.ptr()); } return res; @@ -5495,7 +5496,7 @@ bool Field_time::check_zero_in_date_with_warn(ulonglong fuzzydate) THD *thd= get_thd(); push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, - ER(ER_WARN_DATA_OUT_OF_RANGE), field_name, + ER_THD(thd, ER_WARN_DATA_OUT_OF_RANGE), field_name, thd->get_stmt_da()->current_row_for_warning()); return true; } @@ -5760,7 +5761,7 @@ int Field_year::store(longlong nr, bool unsigned_val) } -int Field_year::store_time_dec(MYSQL_TIME *ltime, uint dec) +int Field_year::store_time_dec(MYSQL_TIME *ltime, uint dec_arg) { ErrConvTime str(ltime); if (Field_year::store(ltime->year, 0)) @@ -6540,17 +6541,18 @@ double Field_string::val_real(void) char *end; CHARSET_INFO *cs= charset(); double result; + THD *thd= get_thd(); result= my_strntod(cs,(char*) ptr,field_length,&end,&error); - if (!get_thd()->no_errors && + if (!thd->no_errors && (error || (field_length != (uint32)(end - (char*) ptr) && !check_if_only_end_space(cs, end, (char*) ptr + field_length)))) { ErrConvString err((char*) ptr, field_length, cs); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE", + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "DOUBLE", err.ptr()); } return result; @@ -6564,17 +6566,18 @@ longlong Field_string::val_int(void) char *end; CHARSET_INFO *cs= charset(); longlong result; + THD *thd= get_thd(); result= my_strntoll(cs, (char*) ptr,field_length,10,&end,&error); - if (!get_thd()->no_errors && + if (!thd->no_errors && (error || (field_length != (uint32)(end - (char*) ptr) && !check_if_only_end_space(cs, end, (char*) ptr + field_length)))) { ErrConvString err((char*) ptr, field_length, cs); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", err.ptr()); } return result; @@ -6603,14 +6606,15 @@ String *Field_string::val_str(String *val_buffer __attribute__((unused)), my_decimal *Field_string::val_decimal(my_decimal *decimal_value) { ASSERT_COLUMN_MARKED_FOR_READ; + THD *thd; int err= str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr, field_length, charset(), decimal_value); - if (!get_thd()->no_errors && err) + if (err && !(thd= get_thd())->no_errors) { ErrConvString errmsg((char*) ptr, field_length, charset()); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "DECIMAL", errmsg.ptr()); } @@ -6877,12 +6881,12 @@ uint Field_string::get_key_image(uchar *buff, uint length, imagetype type_arg) } -Field *Field_string::new_field(MEM_ROOT *root, TABLE *new_table, - bool keep_type) +Field *Field_string::make_new_field(MEM_ROOT *root, TABLE *new_table, + bool keep_type) { Field *field; if (type() != MYSQL_TYPE_VAR_STRING || keep_type) - field= Field::new_field(root, new_table, keep_type); + field= Field::make_new_field(root, new_table, keep_type); else if ((field= new Field_varstring(field_length, maybe_null(), field_name, new_table->s, charset()))) { @@ -6893,10 +6897,11 @@ Field *Field_string::new_field(MEM_ROOT *root, TABLE *new_table, */ field->init(new_table); /* - Normally orig_table is different from table only if field was created - via ::new_field. Here we alter the type of field, so ::new_field is - not applicable. But we still need to preserve the original field - metadata for the client-server protocol. + Normally orig_table is different from table only if field was + created via ::make_new_field. Here we alter the type of field, + so ::make_new_field is not applicable. But we still need to + preserve the original field metadata for the client-server + protocol. */ field->orig_table= orig_table; } @@ -7262,7 +7267,8 @@ uint Field_varstring::max_packed_col_length(uint max_length) return (max_length > 255 ? 2 : 1)+max_length; } -uint Field_varstring::get_key_image(uchar *buff, uint length, imagetype type) +uint Field_varstring::get_key_image(uchar *buff, uint length, + imagetype type_arg) { uint f_length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr); uint local_char_length= length / field_charset->mbmaxlen; @@ -7316,11 +7322,12 @@ int Field_varstring::cmp_binary(const uchar *a_ptr, const uchar *b_ptr, } -Field *Field_varstring::new_field(MEM_ROOT *root, TABLE *new_table, - bool keep_type) +Field *Field_varstring::make_new_field(MEM_ROOT *root, TABLE *new_table, + bool keep_type) { - Field_varstring *res= (Field_varstring*) Field::new_field(root, new_table, - keep_type); + Field_varstring *res= (Field_varstring*) Field::make_new_field(root, + new_table, + keep_type); if (res) res->length_bytes= length_bytes; return res; @@ -7995,7 +8002,7 @@ void Field_geom::sql_type(String &res) const int Field_geom::store(double nr) { my_message(ER_CANT_CREATE_GEOMETRY_OBJECT, - ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); + ER_THD(get_thd(), ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); return -1; } @@ -8003,7 +8010,7 @@ int Field_geom::store(double nr) int Field_geom::store(longlong nr, bool unsigned_val) { my_message(ER_CANT_CREATE_GEOMETRY_OBJECT, - ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); + ER_THD(get_thd(), ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); return -1; } @@ -8011,7 +8018,7 @@ int Field_geom::store(longlong nr, bool unsigned_val) int Field_geom::store_decimal(const my_decimal *) { my_message(ER_CANT_CREATE_GEOMETRY_OBJECT, - ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); + ER_THD(get_thd(), ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); return -1; } @@ -8038,10 +8045,13 @@ int Field_geom::store(const char *from, uint length, CHARSET_INFO *cs) (uint32) geom_type != wkb_type) { my_printf_error(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, - ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), MYF(0), - Geometry::ci_collection[geom_type]->m_name.str, - Geometry::ci_collection[wkb_type]->m_name.str, field_name, - (ulong) table->in_use->get_stmt_da()->current_row_for_warning()); + ER_THD(get_thd(), ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), + MYF(0), + Geometry::ci_collection[geom_type]->m_name.str, + Geometry::ci_collection[wkb_type]->m_name.str, + field_name, + (ulong) table->in_use->get_stmt_da()-> + current_row_for_warning()); goto err_exit; } @@ -8058,7 +8068,7 @@ int Field_geom::store(const char *from, uint length, CHARSET_INFO *cs) err: my_message(ER_CANT_CREATE_GEOMETRY_OBJECT, - ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); + ER_THD(get_thd(), ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); err_exit: bzero(ptr, Field_blob::pack_length()); return -1; @@ -8261,10 +8271,11 @@ void Field_enum::sql_type(String &res) const } -Field *Field_enum::new_field(MEM_ROOT *root, TABLE *new_table, - bool keep_type) +Field *Field_enum::make_new_field(MEM_ROOT *root, TABLE *new_table, + bool keep_type) { - Field_enum *res= (Field_enum*) Field::new_field(root, new_table, keep_type); + Field_enum *res= (Field_enum*) Field::make_new_field(root, new_table, + keep_type); if (res) res->typelib= copy_typelib(root, typelib); return res; @@ -8889,9 +8900,9 @@ uint Field_bit::get_key_image(uchar *buff, uint length, imagetype type_arg) *buff++= bits; length--; } - uint data_length = MY_MIN(length, bytes_in_rec); - memcpy(buff, ptr, data_length); - return data_length + 1; + uint tmp_data_length = MY_MIN(length, bytes_in_rec); + memcpy(buff, ptr, tmp_data_length); + return tmp_data_length + 1; } @@ -9107,8 +9118,8 @@ void Field_bit::set_default() { if (bit_len > 0) { - my_ptrdiff_t const offset= table->s->default_values - table->record[0]; - uchar bits= get_rec_bits(bit_ptr + offset, bit_ofs, bit_len); + my_ptrdiff_t const col_offset= table->s->default_values - table->record[0]; + uchar bits= get_rec_bits(bit_ptr + col_offset, bit_ofs, bit_len); set_rec_bits(bits, bit_ptr, bit_ofs, bit_len); } Field::set_default(); @@ -9544,7 +9555,7 @@ bool Create_field::check(THD *thd) */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_BLOB_CANT_HAVE_DEFAULT, - ER(ER_BLOB_CANT_HAVE_DEFAULT), + ER_THD(thd, ER_BLOB_CANT_HAVE_DEFAULT), field_name); } def= 0; @@ -10026,11 +10037,12 @@ Create_field::Create_field(Field *old_field,Field *orig_field) case MYSQL_TYPE_YEAR: if (length != 4) { + THD *thd= current_thd; char buff[sizeof("YEAR()") + MY_INT64_NUM_DECIMAL_DIGITS + 1]; my_snprintf(buff, sizeof(buff), "YEAR(%lu)", length); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_NOTE, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_WARN_DEPRECATED_SYNTAX, - ER(ER_WARN_DEPRECATED_SYNTAX), + ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX), buff, "YEAR(4)"); } break; @@ -10076,9 +10088,6 @@ Create_field::Create_field(Field *old_field,Field *orig_field) } if (!default_now) // Give a constant default { - char buff[MAX_FIELD_WIDTH]; - String tmp(buff,sizeof(buff), charset); - /* Get the value from default_values */ my_ptrdiff_t diff= orig_field->table->default_values_offset(); orig_field->move_field_offset(diff); // Points now at default_values @@ -10200,11 +10209,11 @@ Field::set_warning(Sql_condition::enum_warning_level level, uint code, If this field was created only for type conversion purposes it will have table == NULL. */ - THD *thd= table ? table->in_use : current_thd; + THD *thd= get_thd(); if (thd->count_cuted_fields) { thd->cuted_fields+= cut_increment; - push_warning_printf(thd, level, code, ER(code), field_name, + push_warning_printf(thd, level, code, ER_THD(thd, code), field_name, thd->get_stmt_da()->current_row_for_warning()); return 0; } @@ -10243,14 +10252,14 @@ void Field::set_datetime_warning(Sql_condition::enum_warning_level level, } -void Field::set_warning_truncated_wrong_value(const char *type, +void Field::set_warning_truncated_wrong_value(const char *type_arg, const char *value) { THD *thd= get_thd(); push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, - ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), - type, value, field_name, + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), + type_arg, value, field_name, static_cast<ulong>(thd->get_stmt_da()-> current_row_for_warning())); } @@ -10317,7 +10326,7 @@ bool Field::validate_value_in_record_with_warn(THD *thd, const uchar *record) val_str(&tmp, ptr_in_record(record)); push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_INVALID_DEFAULT_VALUE_FOR_FIELD, - ER(ER_INVALID_DEFAULT_VALUE_FOR_FIELD), + ER_THD(thd, ER_INVALID_DEFAULT_VALUE_FOR_FIELD), ErrConvString(&tmp).ptr(), field_name); } dbug_tmp_restore_column_map(table->read_set, old_map); diff --git a/sql/field.h b/sql/field.h index da353f70745..8c4219513a9 100644 --- a/sql/field.h +++ b/sql/field.h @@ -17,7 +17,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* - Because of the function new_field() all field classes that have static + Because of the function make_new_field() all field classes that have static variables must declare the size_of() member function. */ @@ -732,7 +732,8 @@ public: null_bit= p_null_bit; } - inline THD *get_thd() const { return table ? table->in_use : current_thd; } + inline THD *get_thd() const + { return likely(table) ? table->in_use : current_thd; } enum { LAST_NULL_BYTE_UNDEF= 0 @@ -765,8 +766,8 @@ public: virtual void sort_string(uchar *buff,uint length)=0; virtual bool optimize_range(uint idx, uint part); virtual void free() {} - virtual Field *new_field(MEM_ROOT *root, TABLE *new_table, - bool keep_type); + virtual Field *make_new_field(MEM_ROOT *root, TABLE *new_table, + bool keep_type); virtual Field *new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, uint32 length, uchar *new_null_ptr, uint new_null_bit); @@ -2415,7 +2416,7 @@ public: enum_field_types real_type() const { return MYSQL_TYPE_STRING; } bool has_charset(void) const { return charset() == &my_charset_bin ? FALSE : TRUE; } - Field *new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type); + Field *make_new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type); virtual uint get_key_image(uchar *buff,uint length, imagetype type); private: int do_save_field_metadata(uchar *first_byte); @@ -2493,7 +2494,7 @@ public: enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; } bool has_charset(void) const { return charset() == &my_charset_bin ? FALSE : TRUE; } - Field *new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type); + Field *make_new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type); Field *new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, uint32 length, uchar *new_null_ptr, uint new_null_bit); @@ -2740,7 +2741,7 @@ public: { flags|=ENUM_FLAG; } - Field *new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type); + Field *make_new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type); enum_field_types type() const { return MYSQL_TYPE_STRING; } enum Item_result cmp_type () const { return INT_RESULT; } enum ha_base_keytype key_type() const; diff --git a/sql/filesort.cc b/sql/filesort.cc index cacc63cd70e..12085d9f733 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -409,7 +409,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length, "%s: %s", MYF(0), ER_THD(thd, ER_FILSORT_ABORT), - kill_errno ? ER(kill_errno) : + kill_errno ? ER_THD(thd, kill_errno) : thd->killed == ABORT_QUERY ? "" : thd->get_stmt_da()->message()); diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index f0b0c0b324a..eedf9458485 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -8018,7 +8018,8 @@ void ha_partition::print_error(int error, myf errflag) table->s->table_name.str, str.c_ptr_safe()); - max_length= (MYSQL_ERRMSG_SIZE - (uint) strlen(ER(ER_ROW_IN_WRONG_PARTITION))); + max_length= (MYSQL_ERRMSG_SIZE - + (uint) strlen(ER_THD(thd, ER_ROW_IN_WRONG_PARTITION))); if (str.length() >= max_length) { str.length(max_length-4); @@ -8822,7 +8823,7 @@ int ha_partition::indexes_are_disabled(void) @retval != 0 Error */ -int ha_partition::check_misplaced_rows(uint read_part_id, bool repair) +int ha_partition::check_misplaced_rows(uint read_part_id, bool do_repair) { int result= 0; uint32 correct_part_id; @@ -8833,7 +8834,7 @@ int ha_partition::check_misplaced_rows(uint read_part_id, bool repair) DBUG_ASSERT(m_file); - if (repair) + if (do_repair) { /* We must read the full row, if we need to move it! */ bitmap_set_all(table->read_set); @@ -8878,7 +8879,7 @@ int ha_partition::check_misplaced_rows(uint read_part_id, bool repair) if (correct_part_id != read_part_id) { num_misplaced_rows++; - if (!repair) + if (!do_repair) { /* Check. */ print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, "error", diff --git a/sql/handler.cc b/sql/handler.cc index 879e7381d2d..82a2e784aa0 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1192,7 +1192,7 @@ int ha_prepare(THD *thd) else { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_GET_ERRNO, ER(ER_GET_ERRNO), + ER_GET_ERRNO, ER_THD(thd, ER_GET_ERRNO), HA_ERR_WRONG_COMMAND, ha_resolve_storage_engine_name(ht)); @@ -1306,7 +1306,7 @@ int ha_commit_trans(THD *thd, bool all) DBUG_EXECUTE_IF("warn_during_ha_commit_trans", push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARNING_NOT_COMPLETE_ROLLBACK, - ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));); + ER_THD(thd, ER_WARNING_NOT_COMPLETE_ROLLBACK));); DBUG_PRINT("info", ("all: %d thd->in_sub_stmt: %d ha_info: %p is_real_trans: %d", @@ -1685,7 +1685,7 @@ int ha_rollback_trans(THD *thd, bool all) !thd->slave_thread && thd->killed < KILL_CONNECTION) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARNING_NOT_COMPLETE_ROLLBACK, - ER(ER_WARNING_NOT_COMPLETE_ROLLBACK)); + ER_THD(thd, ER_WARNING_NOT_COMPLETE_ROLLBACK)); (void) RUN_HOOK(transaction, after_rollback, (thd, FALSE)); DBUG_RETURN(error); } @@ -3286,7 +3286,9 @@ void print_keydup_error(TABLE *table, KEY *key, const char *msg, myf errflag) void print_keydup_error(TABLE *table, KEY *key, myf errflag) { - print_keydup_error(table, key, ER(ER_DUP_ENTRY_WITH_KEY_NAME), errflag); + print_keydup_error(table, key, + ER_THD(table->in_use, ER_DUP_ENTRY_WITH_KEY_NAME), + errflag); } @@ -4282,13 +4284,13 @@ handler::ha_drop_table(const char *name) */ int -handler::ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info) +handler::ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info_arg) { DBUG_ASSERT(m_lock_type == F_UNLCK); mark_trx_read_write(); - int error= create(name, form, info); + int error= create(name, form, info_arg); if (!error && - !(info->options & (HA_LEX_CREATE_TMP_TABLE | HA_CREATE_TMP_ALTER))) + !(info_arg->options & (HA_LEX_CREATE_TMP_TABLE | HA_CREATE_TMP_ALTER))) mysql_audit_create_table(form); return error; } @@ -4301,7 +4303,8 @@ handler::ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info) */ int -handler::ha_create_partitioning_metadata(const char *name, const char *old_name, +handler::ha_create_partitioning_metadata(const char *name, + const char *old_name, int action_flag) { /* @@ -4325,12 +4328,13 @@ handler::ha_create_partitioning_metadata(const char *name, const char *old_name, int handler::ha_change_partitions(HA_CREATE_INFO *create_info, - const char *path, - ulonglong * const copied, - ulonglong * const deleted, - const uchar *pack_frm_data, - size_t pack_frm_len) -{ /* + const char *path, + ulonglong * const copied, + ulonglong * const deleted, + const uchar *pack_frm_data, + size_t pack_frm_len) +{ + /* Must have at least RDLCK or be a TMP table. Read lock is needed to read from current partitions and write lock will be taken on new partitions. */ diff --git a/sql/handler.h b/sql/handler.h index 279bfafd3b9..749c1aaf497 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1740,10 +1740,10 @@ struct Table_specification_st: public HA_CREATE_INFO, HA_CREATE_INFO::init(); DDL_options_st::init(); } - void init(DDL_options_st::Options options) + void init(DDL_options_st::Options options_arg) { HA_CREATE_INFO::init(); - DDL_options_st::init(options); + DDL_options_st::init(options_arg); } /* Quick initialization, for parser. diff --git a/sql/item.cc b/sql/item.cc index 3b1f8b77e82..a6a1d6a5cb8 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -278,10 +278,11 @@ my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value) res->ptr(), res->length(), res->charset(), decimal_value) & E_DEC_BAD_NUM) { + THD *thd= current_thd; ErrConvString err(res); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL", + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "DECIMAL", err.ptr()); } return decimal_value; @@ -488,7 +489,7 @@ uint Item::decimal_precision() const } -uint Item::temporal_precision(enum_field_types type) +uint Item::temporal_precision(enum_field_types type_arg) { if (const_item() && result_type() == STRING_RESULT && !is_temporal_type(field_type())) @@ -498,7 +499,7 @@ uint Item::temporal_precision(enum_field_types type) MYSQL_TIME_STATUS status; DBUG_ASSERT(fixed); if ((tmp= val_str(&buf)) && - !(type == MYSQL_TYPE_TIME ? + !(type_arg == MYSQL_TYPE_TIME ? str_to_time(tmp->charset(), tmp->ptr(), tmp->length(), <ime, TIME_TIME_ONLY, &status) : str_to_datetime(tmp->charset(), tmp->ptr(), tmp->length(), @@ -962,16 +963,19 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) if (str != str_start && !is_autogenerated_name) { char buff[SAFE_NAME_LEN]; + THD *thd= current_thd; + strmake(buff, str_start, MY_MIN(sizeof(buff)-1, length + (int) (str-str_start))); if (length == 0) - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_NAME_BECOMES_EMPTY, + ER_THD(thd, ER_NAME_BECOMES_EMPTY), buff); else - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_REMOVED_SPACES, ER_THD(thd, ER_REMOVED_SPACES), buff); } if (!my_charset_same(cs, system_charset_info)) @@ -2596,11 +2600,11 @@ bool Item_field::is_null_result() bool Item_field::eq(const Item *item, bool binary_cmp) const { - Item *real_item= ((Item *) item)->real_item(); - if (real_item->type() != FIELD_ITEM) + Item *real_item2= ((Item *) item)->real_item(); + if (real_item2->type() != FIELD_ITEM) return 0; - Item_field *item_field= (Item_field*) real_item; + Item_field *item_field= (Item_field*) real_item2; if (item_field->field && field) return item_field->field == field; /* @@ -2964,14 +2968,15 @@ double_from_string_with_check(CHARSET_INFO *cs, const char *cptr, if (error || (end != end_of_num && !check_if_only_end_space(cs, end_of_num, end))) { + THD *thd= current_thd; ErrConvString err(cptr, end - cptr, cs); /* We can use err.ptr() here as ErrConvString is guranteed to put an end \0 here. */ - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE", + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "DOUBLE", err.ptr()); } return tmp; @@ -3005,11 +3010,12 @@ longlong_from_string_with_check(CHARSET_INFO *cs, const char *cptr, (err > 0 || (end != end_of_num && !check_if_only_end_space(cs, end_of_num, end)))) { - ErrConvString err(cptr, end - cptr, cs); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + ErrConvString err_str(cptr, end - cptr, cs); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER", - err.ptr()); + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", + err_str.ptr()); } return tmp; } @@ -4280,11 +4286,12 @@ static bool mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current, if (thd->lex->describe & DESCRIBE_EXTENDED) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_WARN_FIELD_RESOLVED, ER(ER_WARN_FIELD_RESOLVED), - db_name, (db_name[0] ? "." : ""), - table_name, (table_name [0] ? "." : ""), - resolved_item->field_name, - current->select_number, last->select_number); + ER_WARN_FIELD_RESOLVED, + ER_THD(thd,ER_WARN_FIELD_RESOLVED), + db_name, (db_name[0] ? "." : ""), + table_name, (table_name [0] ? "." : ""), + resolved_item->field_name, + current->select_number, last->select_number); } return FALSE; } @@ -4527,9 +4534,10 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select) !((*group_by_ref)->eq(*select_ref, 0))) { ambiguous_fields= TRUE; - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR, - ER(ER_NON_UNIQ_ERROR), ref->full_name(), - current_thd->where); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_NON_UNIQ_ERROR, + ER_THD(thd,ER_NON_UNIQ_ERROR), ref->full_name(), + thd->where); } } @@ -5023,7 +5031,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference) { /* The column to which we link isn't valid. */ my_error(ER_BAD_FIELD_ERROR, MYF(0), (*res)->name, - current_thd->where); + thd->where); return(1); } @@ -5040,8 +5048,8 @@ bool Item_field::fix_fields(THD *thd, Item **reference) Item_ref *rf= new Item_ref(context, db_name,table_name,field_name); if (!rf) return 1; - bool ret= rf->fix_fields(thd, (Item **) &rf) || rf->check_cols(1); - if (ret) + bool err= rf->fix_fields(thd, (Item **) &rf) || rf->check_cols(1); + if (err) return TRUE; SELECT_LEX *select= thd->lex->current_select; @@ -5437,12 +5445,12 @@ Item *Item_field::replace_equal_field(uchar *arg) REPLACE_EQUAL_FIELD_ARG* param= (REPLACE_EQUAL_FIELD_ARG*)arg; if (item_equal && item_equal == param->item_equal) { - Item *const_item= item_equal->get_const(); - if (const_item) + Item *const_item2= item_equal->get_const(); + if (const_item2) { - if (!has_compatible_context(const_item)) + if (!has_compatible_context(const_item2)) return this; - return const_item; + return const_item2; } Item_field *subst= (Item_field *)(item_equal->get_first(param->context_tab, this)); @@ -5554,8 +5562,10 @@ String *Item::check_well_formed_result(String *str, bool send_error) { str->length(wlen); } - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_INVALID_CHARACTER_STRING, - ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_INVALID_CHARACTER_STRING, + ER_THD(thd, ER_INVALID_CHARACTER_STRING), cs->csname, + hexbuf); } return str; } @@ -5576,7 +5586,7 @@ String_copier_for_item::copy_with_warn(CHARSET_INFO *dstcs, String *dst, ErrConvString err(pos, src_length - (pos - src), &my_charset_bin); push_warning_printf(m_thd, Sql_condition::WARN_LEVEL_WARN, ER_INVALID_CHARACTER_STRING, - ER(ER_INVALID_CHARACTER_STRING), + ER_THD(m_thd, ER_INVALID_CHARACTER_STRING), srccs == &my_charset_bin ? dstcs->csname : srccs->csname, err.ptr()); @@ -5591,7 +5601,7 @@ String_copier_for_item::copy_with_warn(CHARSET_INFO *dstcs, String *dst, octet2hex(buf, pos, mblen); push_warning_printf(m_thd, Sql_condition::WARN_LEVEL_WARN, ER_CANNOT_CONVERT_CHARACTER, - ER(ER_CANNOT_CONVERT_CHARACTER), + ER_THD(m_thd, ER_CANNOT_CONVERT_CHARACTER), srccs->csname, buf, dstcs->csname); return m_thd->is_strict_mode(); } @@ -6806,7 +6816,7 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) { /* The current reference cannot be resolved in this query. */ my_error(ER_BAD_FIELD_ERROR,MYF(0), - this->full_name(), current_thd->where); + this->full_name(), thd->where); goto error; } @@ -6954,7 +6964,7 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) { /* The item was not a table field and not a reference */ my_error(ER_BAD_FIELD_ERROR, MYF(0), - this->full_name(), current_thd->where); + this->full_name(), thd->where); goto error; } /* Should be checked in resolve_ref_in_select_and_group(). */ @@ -7934,12 +7944,13 @@ bool Item_outer_ref::fix_fields(THD *thd, Item **reference) } -void Item_outer_ref::fix_after_pullout(st_select_lex *new_parent, Item **ref) +void Item_outer_ref::fix_after_pullout(st_select_lex *new_parent, + Item **ref_arg) { if (get_depended_from() == new_parent) { - *ref= outer_ref; - (*ref)->fix_after_pullout(new_parent, ref); + *ref_arg= outer_ref; + (*ref_arg)->fix_after_pullout(new_parent, ref_arg); } } @@ -7973,12 +7984,12 @@ bool Item_outer_ref::check_inner_refs_processor(uchar *arg) { List_iterator_fast<Item_outer_ref> *it= ((List_iterator_fast<Item_outer_ref> *) arg); - Item_outer_ref *ref; - while ((ref= (*it)++)) + Item_outer_ref *tmp_ref; + while ((tmp_ref= (*it)++)) { - if (ref == this) + if (tmp_ref == this) { - ref->found_in_group_by= 1; + tmp_ref->found_in_group_by= 1; break; } } @@ -8218,38 +8229,39 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions) { if (!arg) { + THD *thd= field_arg->table->in_use; + if (field_arg->flags & NO_DEFAULT_VALUE_FLAG && field_arg->real_type() != MYSQL_TYPE_ENUM) { if (field_arg->reset()) { my_message(ER_CANT_CREATE_GEOMETRY_OBJECT, - ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); + ER_THD(thd, ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0)); return -1; } if (context->error_processor == &view_error_processor) { TABLE_LIST *view= field_arg->table->pos_in_table_list->top_table(); - push_warning_printf(field_arg->table->in_use, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NO_DEFAULT_FOR_VIEW_FIELD, - ER(ER_NO_DEFAULT_FOR_VIEW_FIELD), + ER_THD(thd, ER_NO_DEFAULT_FOR_VIEW_FIELD), view->view_db.str, view->view_name.str); } else { - push_warning_printf(field_arg->table->in_use, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NO_DEFAULT_FOR_FIELD, - ER(ER_NO_DEFAULT_FOR_FIELD), + ER_THD(thd, ER_NO_DEFAULT_FOR_FIELD), field_arg->field_name); } return 1; } field_arg->set_default(); - THD *thd= field_arg->table->in_use; return !field_arg->is_null_in_record(field_arg->table->s->default_values) && field_arg->validate_value_in_record_with_warn(thd, @@ -8998,10 +9010,10 @@ int Item_cache_temporal::save_in_field(Field *field, bool no_conversions) } -void Item_cache_temporal::store_packed(longlong val_arg, Item *example) +void Item_cache_temporal::store_packed(longlong val_arg, Item *example_arg) { /* An explicit values is given, save it. */ - store(example); + store(example_arg); value_cached= true; value= val_arg; null_value= false; diff --git a/sql/item.h b/sql/item.h index 44649bf293a..8f1adea7a35 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1758,9 +1758,9 @@ protected: { my_string_metadata_get(this, str->charset(), str->ptr(), str->length()); } - Metadata(const String *str, uint repertoire) + Metadata(const String *str, uint repertoire_arg) { - MY_STRING_METADATA::repertoire= repertoire; + MY_STRING_METADATA::repertoire= repertoire_arg; MY_STRING_METADATA::char_length= str->numchars(); } uint repertoire() const { return MY_STRING_METADATA::repertoire; } @@ -2385,7 +2385,7 @@ public: cond_equal_ref); } bool is_result_field() { return false; } - void set_result_field(Field *field) {} + void set_result_field(Field *field_arg) {} void save_in_result_field(bool no_conversions) { } Item *get_tmp_table_item(THD *thd); bool collect_item_field_processor(uchar * arg); @@ -2985,9 +2985,9 @@ public: Item_string_with_introducer(const char *str, uint length, CHARSET_INFO *cs) :Item_string(str, length, cs) { } - Item_string_with_introducer(const char *name, + Item_string_with_introducer(const char *name_arg, const char *str, uint length, CHARSET_INFO *tocs) - :Item_string(name, str, length, tocs) + :Item_string(name_arg, str, length, tocs) { } virtual bool is_cs_specified() const { @@ -4329,7 +4329,7 @@ public: class Item_copy_string : public Item_copy { public: - Item_copy_string (Item *item) : Item_copy(item) {} + Item_copy_string (Item *item_arg) : Item_copy(item_arg) {} String *val_str(String*); my_decimal *val_decimal(my_decimal *); @@ -4365,7 +4365,7 @@ public: class Item_copy_uint : public Item_copy_int { public: - Item_copy_uint (Item *item) : Item_copy_int(item) + Item_copy_uint (Item *item_arg) : Item_copy_int(item_arg) { unsigned_flag= 1; } @@ -4576,7 +4576,7 @@ public: (this->*processor)(args); } bool check_partition_func_processor(uchar *int_arg) {return TRUE;} - bool check_vcol_func_processor(uchar *arg) + bool check_vcol_func_processor(uchar *arg_arg) { return trace_unsupported_by_check_vcol_func_processor("values"); } diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index caa645d0794..5a344a647b7 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -5079,6 +5079,8 @@ void Regexp_processor_pcre::pcre_exec_warn(int rc) const { char buf[64]; const char *errmsg= NULL; + THD *thd= current_thd; + /* Make a descriptive message only for those pcre_exec() error codes that can actually happen in MariaDB. @@ -5103,8 +5105,8 @@ void Regexp_processor_pcre::pcre_exec_warn(int rc) const my_snprintf(buf, sizeof(buf), "pcre_exec: Internal error (%d)", rc); errmsg= buf; } - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_REGEXP_ERROR, ER(ER_REGEXP_ERROR), errmsg); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_REGEXP_ERROR, ER_THD(thd, ER_REGEXP_ERROR), errmsg); } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index ceab59737cf..6cdabd05601 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -1593,7 +1593,7 @@ public: m_subpatterns_needed(0) {} int default_regex_flags(); - void init(CHARSET_INFO *data_charset, int extra_flags, uint nsubpatterns) + void init(CHARSET_INFO *data_charset, int extra_flags, uint nsubpatterns_arg) { m_library_flags= default_regex_flags() | extra_flags | (data_charset != &my_charset_bin ? @@ -1607,7 +1607,7 @@ public: m_conversion_is_needed= (data_charset != &my_charset_bin) && !my_charset_same(data_charset, m_library_charset); - m_subpatterns_needed= nsubpatterns; + m_subpatterns_needed= nsubpatterns_arg; } void fix_owner(Item_func *owner, Item *subject_arg, Item *pattern_arg); bool compile(String *pattern, bool send_error); diff --git a/sql/item_func.cc b/sql/item_func.cc index 684724b1a9b..524c124a510 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -693,12 +693,12 @@ void Item_func::count_real_length() @retval False on success, true on error. */ -bool Item_func::count_string_result_length(enum_field_types field_type, +bool Item_func::count_string_result_length(enum_field_types field_type_arg, Item **items, uint nitems) { if (agg_arg_charsets(collation, items, nitems, MY_COLL_ALLOW_CONV, 1)) return true; - if (is_temporal_type(field_type)) + if (is_temporal_type(field_type_arg)) count_datetime_length(items, nitems); else { @@ -714,7 +714,7 @@ void Item_func::signal_divide_by_null() THD *thd= current_thd; if (thd->variables.sql_mode & MODE_ERROR_FOR_DIVISION_BY_ZERO) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_DIVISION_BY_ZERO, - ER(ER_DIVISION_BY_ZERO)); + ER_THD(thd, ER_DIVISION_BY_ZERO)); null_value= 1; } @@ -1149,10 +1149,11 @@ longlong Item_func_signed::val_int_from_str(int *error) value= cs->cset->strtoll10(cs, start, &end, error); if (*error > 0 || end != start+ length) { + THD *thd= current_thd; ErrConvString err(res); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER", + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", err.ptr()); } return value; @@ -1311,9 +1312,10 @@ my_decimal *Item_decimal_typecast::val_decimal(my_decimal *dec) return dec; err: - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, - ER(ER_WARN_DATA_OUT_OF_RANGE), + ER_THD(thd, ER_WARN_DATA_OUT_OF_RANGE), name, 1L); return dec; } @@ -1352,10 +1354,11 @@ double Item_double_typecast::val_real() if ((error= truncate_double(&tmp, max_length, decimals, 0, DBL_MAX))) { - push_warning_printf(current_thd, + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, - ER(ER_WARN_DATA_OUT_OF_RANGE), + ER_THD(thd, ER_WARN_DATA_OUT_OF_RANGE), name, 1); if (error < 0) { @@ -2912,8 +2915,9 @@ bool Item_func_min_max::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) for (uint i=0; i < arg_count ; i++) { Item **arg= args + i; - bool is_null; - longlong res= get_datetime_value(thd, &arg, 0, compare_as_dates, &is_null); + bool is_null_tmp; + longlong res= get_datetime_value(thd, &arg, 0, compare_as_dates, + &is_null_tmp); /* Check if we need to stop (because of error or KILL) and stop the loop */ if (thd->is_error() || args[i]->null_value) @@ -3614,7 +3618,7 @@ udf_handler::fix_fields(THD *thd, Item_func_or_sum *func, if (error) { my_error(ER_CANT_INITIALIZE_UDF, MYF(0), - u_d->name.str, ER(ER_UNKNOWN_ERROR)); + u_d->name.str, ER_THD(thd, ER_UNKNOWN_ERROR)); DBUG_RETURN(TRUE); } DBUG_RETURN(FALSE); @@ -4446,7 +4450,7 @@ longlong Item_func_benchmark::val_int() char buff[MAX_FIELD_WIDTH]; String tmp(buff,sizeof(buff), &my_charset_bin); my_decimal tmp_decimal; - THD *thd=current_thd; + THD *thd= current_thd; ulonglong loop_count; loop_count= (ulonglong) args[0]->val_int(); @@ -4458,8 +4462,9 @@ longlong Item_func_benchmark::val_int() { char buff[22]; llstr(((longlong) loop_count), buff); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WRONG_VALUE_FOR_TYPE, + ER_THD(thd, ER_WRONG_VALUE_FOR_TYPE), "count", buff, "benchmark"); } @@ -6482,8 +6487,9 @@ Item_func_sp::Item_func_sp(Name_resolution_context *context_arg, sp_name *name) Item_func_sp::Item_func_sp(Name_resolution_context *context_arg, - sp_name *name, List<Item> &list) - :Item_func(list), context(context_arg), m_name(name), m_sp(NULL),sp_result_field(NULL) + sp_name *name_arg, List<Item> &list) + :Item_func(list), context(context_arg), m_name(name_arg), m_sp(NULL), + sp_result_field(NULL) { maybe_null= 1; m_name->init_qname(current_thd); diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index 710df57c5f4..55e69c68adb 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -908,10 +908,11 @@ String *Item_func_spatial_collection::val_str(String *str) } if (str->length() > current_thd->variables.max_allowed_packet) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), - func_name(), current_thd->variables.max_allowed_packet); + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), thd->variables.max_allowed_packet); goto err; } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index d46261e6509..b31b95babb8 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -284,10 +284,14 @@ String *Item_func_sha2::val_str_ascii(String *str) #endif default: if (!args[1]->const_item()) - push_warning_printf(current_thd, + { + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WRONG_PARAMETERS_TO_NATIVE_FCT, - ER(ER_WRONG_PARAMETERS_TO_NATIVE_FCT), "sha2"); + ER_THD(thd, ER_WRONG_PARAMETERS_TO_NATIVE_FCT), + "sha2"); + } null_value= TRUE; return NULL; } @@ -308,11 +312,12 @@ String *Item_func_sha2::val_str_ascii(String *str) return str; #else - push_warning_printf(current_thd, - Sql_condition::WARN_LEVEL_WARN, - ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), - "sha2", "--with-ssl"); + THD *thd= current_thd; + push_warning_printf(thd, + Sql_condition::WARN_LEVEL_WARN, + ER_FEATURE_DISABLED, + ER_THD(thd, ER_FEATURE_DISABLED), + "sha2", "--with-ssl"); null_value= TRUE; return (String *) NULL; #endif /* defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) */ @@ -346,21 +351,24 @@ void Item_func_sha2::fix_length_and_dec() break; #endif default: - push_warning_printf(current_thd, - Sql_condition::WARN_LEVEL_WARN, - ER_WRONG_PARAMETERS_TO_NATIVE_FCT, - ER(ER_WRONG_PARAMETERS_TO_NATIVE_FCT), "sha2"); + THD *thd= current_thd; + push_warning_printf(thd, + Sql_condition::WARN_LEVEL_WARN, + ER_WRONG_PARAMETERS_TO_NATIVE_FCT, + ER_THD(thd, ER_WRONG_PARAMETERS_TO_NATIVE_FCT), + "sha2"); } CHARSET_INFO *cs= get_checksum_charset(args[0]->collation.collation->csname); args[0]->collation.set(cs, DERIVATION_COERCIBLE); #else - push_warning_printf(current_thd, - Sql_condition::WARN_LEVEL_WARN, - ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), - "sha2", "--with-ssl"); + THD *thd= current_thd; + push_warning_printf(thd, + Sql_condition::WARN_LEVEL_WARN, + ER_FEATURE_DISABLED, + ER_THD(thd, ER_FEATURE_DISABLED), + "sha2", "--with-ssl"); #endif /* defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) */ } @@ -462,10 +470,12 @@ String *Item_func_to_base64::val_str_ascii(String *str) null_value= 1; // NULL input, too long input, or OOM. if (too_long) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(), - current_thd->variables.max_allowed_packet); + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), + thd->variables.max_allowed_packet); } return 0; } @@ -505,10 +515,12 @@ String *Item_func_from_base64::val_str(String *str) ((uint) (length= base64_needed_decoded_length((int) res->length())) > current_thd->variables.max_allowed_packet)) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(), - current_thd->variables.max_allowed_packet); + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), + thd->variables.max_allowed_packet); goto err; } @@ -519,8 +531,9 @@ String *Item_func_from_base64::val_str(String *str) (char *) tmp_value.ptr(), &end_ptr, 0)) < 0 || end_ptr < res->ptr() + res->length()) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_BAD_BASE64_DATA, ER(ER_BAD_BASE64_DATA), + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_BAD_BASE64_DATA, ER_THD(thd, ER_BAD_BASE64_DATA), end_ptr - res->ptr()); goto err; } @@ -650,10 +663,12 @@ String *Item_func_concat::val_str(String *str) if (res->length()+res2->length() > current_thd->variables.max_allowed_packet) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(), - current_thd->variables.max_allowed_packet); + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), + thd->variables.max_allowed_packet); goto null; } if (!is_const && res->alloced_length() >= res->length()+res2->length()) @@ -856,12 +871,14 @@ String *Item_func_des_encrypt::val_str(String *str) return &tmp_value; error: - push_warning_printf(current_thd,Sql_condition::WARN_LEVEL_WARN, - code, ER(code), - "des_encrypt"); + THD *thd= current_thd; + push_warning_printf(thd,Sql_condition::WARN_LEVEL_WARN, + code, ER_THD(thd, code), + "des_encrypt"); #else - push_warning_printf(current_thd,Sql_condition::WARN_LEVEL_WARN, - ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_FEATURE_DISABLED, ER_THD(thd, ER_FEATURE_DISABLED), "des_encrypt", "--with-ssl"); #endif /* defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) */ null_value=1; @@ -934,14 +951,20 @@ String *Item_func_des_decrypt::val_str(String *str) return &tmp_value; error: - push_warning_printf(current_thd,Sql_condition::WARN_LEVEL_WARN, - code, ER(code), - "des_decrypt"); + { + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + code, ER_THD(thd, code), + "des_decrypt"); + } wrong_key: #else - push_warning_printf(current_thd,Sql_condition::WARN_LEVEL_WARN, - ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), - "des_decrypt", "--with-ssl"); + { + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_FEATURE_DISABLED, ER_THD(thd, ER_FEATURE_DISABLED), + "des_decrypt", "--with-ssl"); + } #endif /* defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) */ null_value=1; return 0; @@ -961,6 +984,7 @@ String *Item_func_concat_ws::val_str(String *str) *sep_str, *res, *res2,*use_as_buff; uint i; bool is_const= 0; + THD *thd= 0; null_value=0; if (!(sep_str= args[0]->val_str(&tmp_sep_str))) @@ -988,12 +1012,13 @@ String *Item_func_concat_ws::val_str(String *str) continue; // Skip NULL if (res->length() + sep_str->length() + res2->length() > - current_thd->variables.max_allowed_packet) + (thd ? thd : (thd= current_thd))->variables.max_allowed_packet) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(), - current_thd->variables.max_allowed_packet); + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), + thd->variables.max_allowed_packet); goto null; } if (!is_const && res->alloced_length() >= @@ -1193,6 +1218,7 @@ String *Item_func_replace::val_str(String *str) register uint32 l; bool binary_cmp; #endif + THD *thd= 0; null_value=0; res=args[0]->val_str(str); @@ -1240,49 +1266,52 @@ redo: end= strend ? strend - from_length + 1 : NULL; while (ptr < end) { - if (*ptr == *search) + if (*ptr == *search) + { + register char *i,*j; + i=(char*) ptr+1; j=(char*) search+1; + while (j != search_end) + if (*i++ != *j++) goto skip; + offset= (int) (ptr-res->ptr()); + if (res->length()-from_length + to_length > + (thd ? thd : (thd= current_thd))->variables.max_allowed_packet) { - register char *i,*j; - i=(char*) ptr+1; j=(char*) search+1; - while (j != search_end) - if (*i++ != *j++) goto skip; - offset= (int) (ptr-res->ptr()); - if (res->length()-from_length + to_length > - current_thd->variables.max_allowed_packet) - { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), - func_name(), - current_thd->variables.max_allowed_packet); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_ALLOWED_PACKET_OVERFLOWED, + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), + thd->variables.max_allowed_packet); - goto null; - } - if (!alloced) - { - alloced=1; - res=copy_if_not_alloced(str,res,res->length()+to_length); - } - res->replace((uint) offset,from_length,*res3); - offset+=(int) to_length; - goto redo; + goto null; } -skip: - if ((l=my_ismbchar(res->charset(), ptr,strend))) ptr+=l; - else ++ptr; + if (!alloced) + { + alloced=1; + res=copy_if_not_alloced(str,res,res->length()+to_length); + } + res->replace((uint) offset,from_length,*res3); + offset+=(int) to_length; + goto redo; + } + skip: + if ((l=my_ismbchar(res->charset(), ptr,strend))) ptr+=l; + else ++ptr; } } else #endif /* USE_MB */ + { + THD *thd= current_thd; do { if (res->length()-from_length + to_length > - current_thd->variables.max_allowed_packet) + thd->variables.max_allowed_packet) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(), - current_thd->variables.max_allowed_packet); + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), + thd->variables.max_allowed_packet); goto null; } if (!alloced) @@ -1294,6 +1323,7 @@ skip: offset+=(int) to_length; } while ((offset=res->strstr(*res2,(uint) offset)) >= 0); + } return res; null: @@ -1547,14 +1577,17 @@ String *Item_func_insert::val_str(String *str) if (length > res->length() - start) length= res->length() - start; - if ((ulonglong) (res->length() - length + res2->length()) > - (ulonglong) current_thd->variables.max_allowed_packet) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), - func_name(), current_thd->variables.max_allowed_packet); - goto null; + THD *thd= current_thd; + if ((ulonglong) (res->length() - length + res2->length()) > + (ulonglong) thd->variables.max_allowed_packet) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_ALLOWED_PACKET_OVERFLOWED, + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), thd->variables.max_allowed_packet); + goto null; + } } res=copy_if_not_alloced(str,res,res->length()); res->replace((uint32) start,(uint32) length,*res2); @@ -2575,9 +2608,10 @@ MY_LOCALE *Item_func_format::get_locale(Item *item) if (!locale_name || !(lc= my_locale_by_name(locale_name->c_ptr_safe()))) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_LOCALE, - ER(ER_UNKNOWN_LOCALE), + ER_THD(thd, ER_UNKNOWN_LOCALE), locale_name ? locale_name->c_ptr_safe() : "NULL"); lc= &my_locale_en_US; } @@ -2962,14 +2996,18 @@ String *Item_func_repeat::val_str(String *str) if (count == 1) // To avoid reallocs return res; length=res->length(); + // Safe length check - if (length > current_thd->variables.max_allowed_packet / (uint) count) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), - func_name(), current_thd->variables.max_allowed_packet); - goto err; + THD *thd= current_thd; + if (length > thd->variables.max_allowed_packet / (uint) count) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_ALLOWED_PACKET_OVERFLOWED, + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), thd->variables.max_allowed_packet); + goto err; + } } tot_length= length*(uint) count; if (!(res= alloc_buffer(res,str,&tmp_value,tot_length))) @@ -3035,16 +3073,18 @@ String *Item_func_space::val_str(String *str) // Safe length check tot_length= (uint) count * cs->mbminlen; - if (tot_length > current_thd->variables.max_allowed_packet) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), - func_name(), - current_thd->variables.max_allowed_packet); - goto err; - } - + THD *thd= current_thd; + if (tot_length > thd->variables.max_allowed_packet) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_ALLOWED_PACKET_OVERFLOWED, + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), + thd->variables.max_allowed_packet); + goto err; + } + } if (str->alloc(tot_length)) goto err; str->length(tot_length); @@ -3165,13 +3205,16 @@ String *Item_func_rpad::val_str(String *str) pad_char_length= rpad->numchars(); byte_count= count * collation.collation->mbmaxlen; - if ((ulonglong) byte_count > current_thd->variables.max_allowed_packet) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), - func_name(), current_thd->variables.max_allowed_packet); - goto err; + THD *thd= current_thd; + if ((ulonglong) byte_count > thd->variables.max_allowed_packet) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_ALLOWED_PACKET_OVERFLOWED, + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), thd->variables.max_allowed_packet); + goto err; + } } if (args[2]->null_value || !pad_char_length) goto err; @@ -3273,13 +3316,16 @@ String *Item_func_lpad::val_str(String *str) pad_char_length= pad->numchars(); byte_count= count * collation.collation->mbmaxlen; - if ((ulonglong) byte_count > current_thd->variables.max_allowed_packet) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), - func_name(), current_thd->variables.max_allowed_packet); - goto err; + THD *thd= current_thd; + if ((ulonglong) byte_count > thd->variables.max_allowed_packet) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_ALLOWED_PACKET_OVERFLOWED, + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), thd->variables.max_allowed_packet); + goto err; + } } if (args[2]->null_value || !pad_char_length || @@ -3550,15 +3596,18 @@ String *Item_func_weight_string::val_str(String *str) tmp_length= cs->coll->strnxfrmlen(cs, char_length * cs->mbmaxlen); } - if(tmp_length > current_thd->variables.max_allowed_packet) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(), - current_thd->variables.max_allowed_packet); - goto nl; + THD *thd= current_thd; + if (tmp_length > current_thd->variables.max_allowed_packet) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_ALLOWED_PACKET_OVERFLOWED, + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), + thd->variables.max_allowed_packet); + goto nl; + } } - if (tmp_value.alloc(tmp_length)) goto nl; @@ -3744,13 +3793,17 @@ String *Item_load_file::val_str(String *str) /* my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), file_name->c_ptr()); */ goto err; } - if (stat_info.st_size > (long) current_thd->variables.max_allowed_packet) + { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), - func_name(), current_thd->variables.max_allowed_packet); - goto err; + THD *thd= current_thd; + if (stat_info.st_size > (long) thd->variables.max_allowed_packet) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_ALLOWED_PACKET_OVERFLOWED, + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), + func_name(), thd->variables.max_allowed_packet); + goto err; + } } if (tmp_value.alloc((size_t)stat_info.st_size)) goto err; @@ -3829,7 +3882,8 @@ String* Item_func_export_set::val_str(String* str) } null_value= false; - const ulong max_allowed_packet= current_thd->variables.max_allowed_packet; + THD *thd= current_thd; + const ulong max_allowed_packet= thd->variables.max_allowed_packet; const uint num_separators= num_set_values > 0 ? num_set_values - 1 : 0; const ulonglong max_total_length= num_set_values * MY_MAX(yes->length(), no->length()) + @@ -3837,9 +3891,9 @@ String* Item_func_export_set::val_str(String* str) if (unlikely(max_total_length > max_allowed_packet)) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(), max_allowed_packet); null_value= true; return NULL; @@ -4043,9 +4097,10 @@ longlong Item_func_uncompressed_length::val_int() */ if (res->length() <= 4) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_ZLIB_Z_DATA_ERROR, - ER(ER_ZLIB_Z_DATA_ERROR)); + ER_THD(thd, ER_ZLIB_Z_DATA_ERROR)); null_value= 1; return 0; } @@ -4119,8 +4174,10 @@ String *Item_func_compress::val_str(String *str) if ((err= my_compress_buffer(body, &new_size, (const uchar *)res->ptr(), res->length())) != Z_OK) { + THD *thd= current_thd; code= err==Z_MEM_ERROR ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_BUF_ERROR; - push_warning(current_thd,Sql_condition::WARN_LEVEL_WARN,code,ER(code)); + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, code, + ER_THD(thd, code)); null_value= 1; return 0; } @@ -4158,9 +4215,10 @@ String *Item_func_uncompress::val_str(String *str) /* If length is less than 4 bytes, data is corrupt */ if (res->length() <= 4) { - push_warning_printf(current_thd,Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_ZLIB_Z_DATA_ERROR, - ER(ER_ZLIB_Z_DATA_ERROR)); + ER_THD(thd, ER_ZLIB_Z_DATA_ERROR)); goto err; } @@ -4168,10 +4226,11 @@ String *Item_func_uncompress::val_str(String *str) new_size= uint4korr(res->ptr()) & 0x3FFFFFFF; if (new_size > current_thd->variables.max_allowed_packet) { - push_warning_printf(current_thd,Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + push_warning_printf(thd,Sql_condition::WARN_LEVEL_WARN, ER_TOO_BIG_FOR_UNCOMPRESS, - ER(ER_TOO_BIG_FOR_UNCOMPRESS), - static_cast<int>(current_thd->variables. + ER_THD(thd, ER_TOO_BIG_FOR_UNCOMPRESS), + static_cast<int>(thd->variables. max_allowed_packet)); goto err; } @@ -4187,7 +4246,10 @@ String *Item_func_uncompress::val_str(String *str) code= ((err == Z_BUF_ERROR) ? ER_ZLIB_Z_BUF_ERROR : ((err == Z_MEM_ERROR) ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_DATA_ERROR)); - push_warning(current_thd,Sql_condition::WARN_LEVEL_WARN,code,ER(code)); + { + THD *thd= current_thd; + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, code, ER_THD(thd, code)); + } err: null_value= 1; @@ -4877,11 +4939,12 @@ longlong Item_dyncol_get::val_int() num= double_to_longlong(val.x.double_value, unsigned_flag, &error); if (error) { + THD *thd= current_thd; char buff[30]; sprintf(buff, "%lg", val.x.double_value); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_DATA_OVERFLOW, - ER(ER_DATA_OVERFLOW), + ER_THD(thd, ER_DATA_OVERFLOW), buff, unsigned_flag ? "UNSIGNED INT" : "INT"); } @@ -4896,12 +4959,13 @@ longlong Item_dyncol_get::val_int() num= my_strtoll10(val.x.string.value.str, &end, &error); if (end != org_end || error > 0) { + THD *thd= current_thd; char buff[80]; strmake(buff, val.x.string.value.str, MY_MIN(sizeof(buff)-1, val.x.string.value.length)); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_BAD_DATA, - ER(ER_BAD_DATA), + ER_THD(thd, ER_BAD_DATA), buff, unsigned_flag ? "UNSIGNED INT" : "INT"); } @@ -4960,12 +5024,13 @@ double Item_dyncol_get::val_real() if (end != (char*) val.x.string.value.str + val.x.string.value.length || error) { + THD *thd= current_thd; char buff[80]; strmake(buff, val.x.string.value.str, MY_MIN(sizeof(buff)-1, val.x.string.value.length)); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_BAD_DATA, - ER(ER_BAD_DATA), + ER_THD(thd, ER_BAD_DATA), buff, "DOUBLE"); } return res; @@ -5021,9 +5086,10 @@ my_decimal *Item_dyncol_get::val_decimal(my_decimal *decimal_value) val.x.string.value.length)); if (rc != E_DEC_OK) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_BAD_DATA, - ER(ER_BAD_DATA), + ER_THD(thd, ER_BAD_DATA), buff, "DECIMAL"); } break; diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index ca1f3966da2..9a8c79966d0 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -520,8 +520,8 @@ private: protected: SQL_CRYPT sql_crypt; public: - Item_func_encode(Item *a, Item *seed): - Item_str_func(a, seed) {} + Item_func_encode(Item *a, Item *seed_arg): + Item_str_func(a, seed_arg) {} String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "encode"; } @@ -536,7 +536,7 @@ private: class Item_func_decode :public Item_func_encode { public: - Item_func_decode(Item *a, Item *seed): Item_func_encode(a, seed) {} + Item_func_decode(Item *a, Item *seed_arg): Item_func_encode(a, seed_arg) {} const char *func_name() const { return "decode"; } protected: void crypto_transform(String *); @@ -1176,8 +1176,8 @@ public: class Item_func_dyncol_add: public Item_func_dyncol_create { public: - Item_func_dyncol_add(List<Item> &args, DYNCALL_CREATE_DEF *dfs) - :Item_func_dyncol_create(args, dfs) + Item_func_dyncol_add(List<Item> &args_arg, DYNCALL_CREATE_DEF *dfs) + :Item_func_dyncol_create(args_arg, dfs) {} const char *func_name() const{ return "column_add"; } String *val_str(String *); diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index fa398dc6e21..cad44a2f4e7 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1105,7 +1105,8 @@ Item_singlerow_subselect::select_transformer(JOIN *join) if (thd->lex->describe) { char warn_buff[MYSQL_ERRMSG_SIZE]; - sprintf(warn_buff, ER(ER_SELECT_REDUCED), select_lex->select_number); + sprintf(warn_buff, ER_THD(thd, ER_SELECT_REDUCED), + select_lex->select_number); push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_SELECT_REDUCED, warn_buff); } @@ -1193,14 +1194,16 @@ void Item_singlerow_subselect::fix_length_and_dec() Item* Item_singlerow_subselect::expr_cache_insert_transformer(uchar *thd_arg) { - THD *thd= (THD*) thd_arg; + THD *tmp_thd= (THD*) thd_arg; DBUG_ENTER("Item_singlerow_subselect::expr_cache_insert_transformer"); + DBUG_ASSERT(thd == tmp_thd); + if (expr_cache) DBUG_RETURN(expr_cache); - if (expr_cache_is_needed(thd) && - (expr_cache= set_expr_cache(thd))) + if (expr_cache_is_needed(tmp_thd) && + (expr_cache= set_expr_cache(tmp_thd))) DBUG_RETURN(expr_cache); DBUG_RETURN(this); } @@ -1489,14 +1492,15 @@ void Item_in_subselect::fix_length_and_dec() Item* Item_exists_subselect::expr_cache_insert_transformer(uchar *thd_arg) { - THD *thd= (THD*) thd_arg; + THD *tmp_thd= (THD*) thd_arg; DBUG_ENTER("Item_exists_subselect::expr_cache_insert_transformer"); + DBUG_ASSERT(thd == tmp_thd); if (expr_cache) DBUG_RETURN(expr_cache); - if (substype() == EXISTS_SUBS && expr_cache_is_needed(thd) && - (expr_cache= set_expr_cache(thd))) + if (substype() == EXISTS_SUBS && expr_cache_is_needed(tmp_thd) && + (expr_cache= set_expr_cache(tmp_thd))) DBUG_RETURN(expr_cache); DBUG_RETURN(this); } @@ -1784,7 +1788,8 @@ Item_in_subselect::single_value_transformer(JOIN *join) if (thd->lex->describe) { char warn_buff[MYSQL_ERRMSG_SIZE]; - sprintf(warn_buff, ER(ER_SELECT_REDUCED), select_lex->select_number); + sprintf(warn_buff, ER_THD(thd, ER_SELECT_REDUCED), + select_lex->select_number); push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_SELECT_REDUCED, warn_buff); } @@ -4581,7 +4586,7 @@ subselect_hash_sj_engine::get_strategy_using_data() void subselect_hash_sj_engine::choose_partial_match_strategy( bool has_non_null_key, bool has_covering_null_row, - MY_BITMAP *partial_match_key_parts) + MY_BITMAP *partial_match_key_parts_arg) { ulonglong pm_buff_size; @@ -4632,7 +4637,7 @@ subselect_hash_sj_engine::choose_partial_match_strategy( { pm_buff_size= rowid_merge_buff_size(has_non_null_key, has_covering_null_row, - partial_match_key_parts); + partial_match_key_parts_arg); if (pm_buff_size > thd->variables.rowid_merge_buff_size) strategy= PARTIAL_MATCH_SCAN; } diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 6628a1bf86b..01d454d62f0 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -1036,9 +1036,9 @@ public: Name_resolution_context *semi_join_conds_context; - subselect_hash_sj_engine(THD *thd, Item_subselect *in_predicate, + subselect_hash_sj_engine(THD *thd_arg, Item_subselect *in_predicate, subselect_single_select_engine *old_engine) - : subselect_engine(thd, in_predicate, NULL), + : subselect_engine(thd_arg, in_predicate, NULL), tmp_table(NULL), is_materialized(FALSE), materialize_engine(old_engine), materialize_join(NULL), semi_join_conds(NULL), lookup_engine(NULL), count_partial_match_columns(0), count_null_only_columns(0), diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 8cf498f4b56..65f5d834bbd 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -76,7 +76,7 @@ bool Item_sum::init_sum_func_check(THD *thd) } if (!(thd->lex->allow_sum_func & curr_sel->name_visibility_map)) { - my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), + my_message(ER_INVALID_GROUP_FUNC_USE, ER_THD(thd, ER_INVALID_GROUP_FUNC_USE), MYF(0)); return TRUE; } @@ -200,7 +200,8 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref) invalid= aggr_level <= max_sum_func_level; if (invalid) { - my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), + my_message(ER_INVALID_GROUP_FUNC_USE, + ER_THD(thd, ER_INVALID_GROUP_FUNC_USE), MYF(0)); return TRUE; } @@ -281,7 +282,7 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref) !sel->group_list.elements) { my_message(ER_MIX_OF_GROUP_FUNC_AND_FIELDS, - ER(ER_MIX_OF_GROUP_FUNC_AND_FIELDS), MYF(0)); + ER_THD(thd, ER_MIX_OF_GROUP_FUNC_AND_FIELDS), MYF(0)); return TRUE; } } @@ -3112,6 +3113,7 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)), CHARSET_INFO *cs= item->collation.collation; const char *ptr= result->ptr(); uint add_length; + THD *thd= current_thd; /* It's ok to use item->result.length() as the fourth argument as this is never used to limit the length of the data. @@ -3124,8 +3126,9 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)), &well_formed_error); result->length(old_length + add_length); item->warning_for_row= TRUE; - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_CUT_VALUE_GROUP_CONCAT, ER(ER_CUT_VALUE_GROUP_CONCAT), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_CUT_VALUE_GROUP_CONCAT, + ER_THD(thd, ER_CUT_VALUE_GROUP_CONCAT), item->row_count); return 1; @@ -3297,7 +3300,7 @@ void Item_func_group_concat::cleanup() } -Field *Item_func_group_concat::make_string_field(TABLE *table) +Field *Item_func_group_concat::make_string_field(TABLE *table_arg) { Field *field; DBUG_ASSERT(collation.collation); @@ -3306,10 +3309,11 @@ Field *Item_func_group_concat::make_string_field(TABLE *table) maybe_null, name, collation.collation, TRUE); else field= new Field_varstring(max_length, - maybe_null, name, table->s, collation.collation); + maybe_null, name, table_arg->s, + collation.collation); if (field) - field->init(table); + field->init(table_arg); return field; } diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index d82e4aabb35..0b87302781f 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -426,7 +426,8 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, { if (!my_isspace(&my_charset_latin1,*val)) { - make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, + make_truncated_value_warning(current_thd, + Sql_condition::WARN_LEVEL_WARN, val_begin, length, cached_timestamp_type, NullS); break; @@ -437,10 +438,12 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, err: { + THD *thd= current_thd; char buff[128]; strmake(buff, val_begin, MY_MIN(length, sizeof(buff)-1)); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WRONG_VALUE_FOR_TYPE, + ER_THD(thd, ER_WRONG_VALUE_FOR_TYPE), date_time_type, buff, "str_to_date"); } DBUG_RETURN(1); @@ -1299,10 +1302,11 @@ bool get_interval_value(Item *args,interval_type int_type, INTERVAL *interval) interval->neg= my_decimal2seconds(val, &second, &second_part); if (second == LONGLONG_MAX) { + THD *thd= current_thd; ErrConvDecimal err(val); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL", + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "DECIMAL", err.ptr()); return true; } @@ -2361,14 +2365,15 @@ void Item_char_typecast::check_truncation_with_warn(String *src, uint dstlen) { if (dstlen < src->length()) { + THD *thd= current_thd; char char_type[40]; + ErrConvString err(src); my_snprintf(char_type, sizeof(char_type), "%s(%lu)", cast_cs == &my_charset_bin ? "BINARY" : "CHAR", (ulong) cast_length); - ErrConvString err(src); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), char_type, + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), char_type, err.ptr()); } } @@ -2404,13 +2409,15 @@ uint Item_char_typecast::adjusted_length_with_warn(uint length) { if (length <= current_thd->variables.max_allowed_packet) return length; - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_ALLOWED_PACKET_OVERFLOWED, - ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), + ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), cast_cs == &my_charset_bin ? "cast_as_binary" : func_name(), - current_thd->variables.max_allowed_packet); - return current_thd->variables.max_allowed_packet; + thd->variables.max_allowed_packet); + return thd->variables.max_allowed_packet; } diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc index 24441cd80e8..94925216dd7 100644 --- a/sql/item_xmlfunc.cc +++ b/sql/item_xmlfunc.cc @@ -2854,14 +2854,15 @@ bool Item_xml_str_func::XML::parse() /* Execute XML parser */ if ((rc= my_xml_parse(&p, m_raw_ptr->ptr(), m_raw_ptr->length())) != MY_XML_OK) { + THD *thd= current_thd; char buf[128]; my_snprintf(buf, sizeof(buf)-1, "parse error at line %d pos %lu: %s", my_xml_error_lineno(&p) + 1, (ulong) my_xml_error_pos(&p) + 1, my_xml_error_string(&p)); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WRONG_VALUE, - ER(ER_WRONG_VALUE), "XML", buf); + ER_THD(thd, ER_WRONG_VALUE), "XML", buf); m_raw_ptr= (String *) 0; } my_xml_parser_free(&p); diff --git a/sql/item_xmlfunc.h b/sql/item_xmlfunc.h index 637f505e12e..5b699869b2e 100644 --- a/sql/item_xmlfunc.h +++ b/sql/item_xmlfunc.h @@ -69,11 +69,11 @@ protected: }; Item *nodeset_func; XML xml; - bool get_xml(XML *xml, bool cache= false) + bool get_xml(XML *xml_arg, bool cache= false) { - if (!cache && xml->cached()) - return xml->raw() == 0; - return xml->parse(args[0], cache); + if (!cache && xml_arg->cached()) + return xml_arg->raw() == 0; + return xml_arg->parse(args[0], cache); } public: Item_xml_str_func(Item *a, Item *b): diff --git a/sql/lock.cc b/sql/lock.cc index a2f7df04de5..946a089fadc 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -826,7 +826,7 @@ bool lock_schema_name(THD *thd, const char *db) if (thd->locked_tables_mode) { my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, - ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); + ER_THD(thd, ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); return TRUE; } @@ -882,7 +882,7 @@ bool lock_object_name(THD *thd, MDL_key::enum_mdl_namespace mdl_type, if (thd->locked_tables_mode) { my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, - ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); + ER_THD(thd, ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); return TRUE; } diff --git a/sql/log.cc b/sql/log.cc index 35f6184f81a..3010e5c22a3 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -266,9 +266,9 @@ public: return m_pending; } - void set_pending(Rows_log_event *const pending) + void set_pending(Rows_log_event *const pending_arg) { - m_pending= pending; + m_pending= pending_arg; } void set_incident(void) @@ -636,7 +636,7 @@ void Log_to_csv_event_handler::cleanup() bool Log_to_csv_event_handler:: log_general(THD *thd, my_hrtime_t event_time, const char *user_host, - uint user_host_len, int thread_id, + uint user_host_len, int thread_id_arg, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len, CHARSET_INFO *client_cs) @@ -717,7 +717,7 @@ bool Log_to_csv_event_handler:: /* do a write */ if (table->field[1]->store(user_host, user_host_len, client_cs) || - table->field[2]->store((longlong) thread_id, TRUE) || + table->field[2]->store((longlong) thread_id_arg, TRUE) || table->field[3]->store((longlong) global_system_variables.server_id, TRUE) || table->field[4]->store(command_type, command_type_len, client_cs)) @@ -1046,7 +1046,7 @@ bool Log_to_file_event_handler:: bool Log_to_file_event_handler:: log_general(THD *thd, my_hrtime_t event_time, const char *user_host, - uint user_host_len, int thread_id, + uint user_host_len, int thread_id_arg, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len, CHARSET_INFO *client_cs) @@ -1055,7 +1055,7 @@ bool Log_to_file_event_handler:: thd->push_internal_handler(&error_handler); bool retval= mysql_log.write(hrtime_to_time(event_time), user_host, user_host_len, - thread_id, command_type, command_type_len, + thread_id_arg, command_type, command_type_len, sql_text, sql_text_len); thd->pop_internal_handler(); return retval; @@ -2125,11 +2125,11 @@ void MYSQL_BIN_LOG::set_write_error(THD *thd, bool is_transactional) { if (is_transactional) { - my_message(ER_TRANS_CACHE_FULL, ER(ER_TRANS_CACHE_FULL), MYF(MY_WME)); + my_message(ER_TRANS_CACHE_FULL, ER_THD(thd, ER_TRANS_CACHE_FULL), MYF(MY_WME)); } else { - my_message(ER_STMT_CACHE_FULL, ER(ER_STMT_CACHE_FULL), MYF(MY_WME)); + my_message(ER_STMT_CACHE_FULL, ER_THD(thd, ER_STMT_CACHE_FULL), MYF(MY_WME)); } } else @@ -2708,8 +2708,9 @@ int MYSQL_LOG::generate_new_name(char *new_name, const char *log_name) if (DBUG_EVALUATE_IF("binlog_inject_new_name_error", TRUE, FALSE) || find_uniq_filename(new_name)) { - if (current_thd) - my_printf_error(ER_NO_UNIQUE_LOGFILE, ER(ER_NO_UNIQUE_LOGFILE), + THD *thd= current_thd; + if (thd) + my_printf_error(ER_NO_UNIQUE_LOGFILE, ER_THD(thd, ER_NO_UNIQUE_LOGFILE), MYF(ME_FATALERROR), log_name); sql_print_error(ER_DEFAULT(ER_NO_UNIQUE_LOGFILE), log_name); return 1; @@ -2792,7 +2793,7 @@ void MYSQL_QUERY_LOG::reopen_file() */ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host, - uint user_host_len, int thread_id, + uint user_host_len, int thread_id_arg, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len) { @@ -2831,7 +2832,7 @@ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host, goto err; /* command_type, thread_id */ - length= my_snprintf(buff, 32, "%5ld ", (long) thread_id); + length= my_snprintf(buff, 32, "%5ld ", (long) thread_id_arg); if (my_b_write(&log_file, (uchar*) buff, length)) goto err; @@ -3051,7 +3052,7 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time, if (! write_error) { write_error= 1; - sql_print_error(ER(ER_ERROR_ON_WRITE), name, error); + sql_print_error(ER_THD(thd, ER_ERROR_ON_WRITE), name, error); } } } @@ -3913,7 +3914,7 @@ err: 1 error */ -bool MYSQL_BIN_LOG::reset_logs(THD* thd, bool create_new_log, +bool MYSQL_BIN_LOG::reset_logs(THD *thd, bool create_new_log, rpl_gtid *init_state, uint32 init_state_len) { LOG_INFO linfo; @@ -4030,7 +4031,7 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd, bool create_new_log, { uint errcode= purge_log_get_error_code(err); sql_print_error("Failed to locate old binlog or relay log files"); - my_message(errcode, ER(errcode), MYF(0)); + my_message(errcode, ER_THD(thd, errcode), MYF(0)); error= 1; goto err; } @@ -4041,8 +4042,9 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd, bool create_new_log, { if (my_errno == ENOENT) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_LOG_PURGE_NO_FILE, + ER_THD(thd, ER_LOG_PURGE_NO_FILE), linfo.log_file_name); sql_print_information("Failed to delete file '%s'", linfo.log_file_name); @@ -4051,7 +4053,7 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd, bool create_new_log, } else { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_BINLOG_PURGE_FATAL_ERR, "a problem with deleting %s; " "consider examining correspondence " @@ -4080,8 +4082,9 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd, bool create_new_log, { if (my_errno == ENOENT) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_LOG_PURGE_NO_FILE, + ER_THD(thd, ER_LOG_PURGE_NO_FILE), index_file_name); sql_print_information("Failed to delete file '%s'", index_file_name); @@ -4090,7 +4093,7 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd, bool create_new_log, } else { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_BINLOG_PURGE_FATAL_ERR, "a problem with deleting %s; " "consider examining correspondence " @@ -4555,7 +4558,7 @@ int MYSQL_BIN_LOG::purge_index_entry(THD *thd, ulonglong *decrease_log_space, if (thd) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE), + ER_LOG_PURGE_NO_FILE, ER_THD(thd, ER_LOG_PURGE_NO_FILE), log_info.log_file_name); } sql_print_information("Failed to execute mysql_file_stat on file '%s'", @@ -4627,7 +4630,7 @@ int MYSQL_BIN_LOG::purge_index_entry(THD *thd, ulonglong *decrease_log_space, if (thd) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE), + ER_LOG_PURGE_NO_FILE, ER_THD(thd, ER_LOG_PURGE_NO_FILE), log_info.log_file_name); } sql_print_information("Failed to delete file '%s'", @@ -4699,7 +4702,6 @@ int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time) LOG_INFO log_info; MY_STAT stat_area; THD *thd= current_thd; - DBUG_ENTER("purge_logs_before_date"); mysql_mutex_lock(&LOCK_index); @@ -4765,24 +4767,24 @@ err: bool -MYSQL_BIN_LOG::can_purge_log(const char *log_file_name) +MYSQL_BIN_LOG::can_purge_log(const char *log_file_name_arg) { xid_count_per_binlog *b; - if (is_active(log_file_name)) + if (is_active(log_file_name_arg)) return false; mysql_mutex_lock(&LOCK_xid_list); { I_List_iterator<xid_count_per_binlog> it(binlog_xid_count_list); while ((b= it++) && - 0 != strncmp(log_file_name+dirname_length(log_file_name), + 0 != strncmp(log_file_name_arg+dirname_length(log_file_name_arg), b->binlog_name, b->binlog_name_len)) ; } mysql_mutex_unlock(&LOCK_xid_list); if (b) return false; - return !log_in_use(log_file_name); + return !log_in_use(log_file_name_arg); } #endif /* HAVE_REPLICATION */ @@ -4901,8 +4903,8 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock) uint close_flag; bool delay_close= false; File UNINIT_VAR(old_file); - DBUG_ENTER("MYSQL_BIN_LOG::new_file_impl"); + if (!is_open()) { DBUG_PRINT("info",("log is closed")); @@ -4949,7 +4951,9 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock) { DBUG_EXECUTE_IF("fault_injection_new_file_rotate_event", errno=2;); close_on_error= TRUE; - my_printf_error(ER_ERROR_ON_WRITE, ER(ER_CANT_OPEN_FILE), MYF(ME_FATALERROR), name, errno); + my_printf_error(ER_ERROR_ON_WRITE, + ER_THD_OR_DEFAULT(current_thd, ER_CANT_OPEN_FILE), + MYF(ME_FATALERROR), name, errno); goto end; } bytes_written += r.data_written; @@ -5010,7 +5014,8 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock) /* handle reopening errors */ if (error) { - my_printf_error(ER_CANT_OPEN_FILE, ER(ER_CANT_OPEN_FILE), + my_printf_error(ER_CANT_OPEN_FILE, + ER_THD_OR_DEFAULT(current_thd, ER_CANT_OPEN_FILE), MYF(ME_FATALERROR), file_to_open, error); close_on_error= TRUE; } @@ -5638,7 +5643,7 @@ MYSQL_BIN_LOG::write_gtid_event(THD *thd, bool standalone, { rpl_gtid gtid; uint32 domain_id; - uint32 server_id; + uint32 local_server_id; uint64 seq_no; int err; DBUG_ENTER("write_gtid_event"); @@ -5654,7 +5659,7 @@ MYSQL_BIN_LOG::write_gtid_event(THD *thd, bool standalone, #ifdef WITH_WSREP } #endif /* WITH_WSREP */ - server_id= thd->variables.server_id; + local_server_id= thd->variables.server_id; seq_no= thd->variables.gtid_seq_no; if (thd->variables.option_bits & OPTION_GTID_BEGIN) @@ -5674,7 +5679,7 @@ MYSQL_BIN_LOG::write_gtid_event(THD *thd, bool standalone, { /* Use the specified sequence number. */ gtid.domain_id= domain_id; - gtid.server_id= server_id; + gtid.server_id= local_server_id; gtid.seq_no= seq_no; err= rpl_global_gtid_binlog_state.update(>id, opt_gtid_strict_mode); if (err && thd->get_stmt_da()->sql_errno()==ER_GTID_STRICT_OUT_OF_ORDER) @@ -5684,7 +5689,7 @@ MYSQL_BIN_LOG::write_gtid_event(THD *thd, bool standalone, { /* Allocate the next sequence number for the GTID. */ err= rpl_global_gtid_binlog_state.update_with_next_gtid(domain_id, - server_id, >id); + local_server_id, >id); seq_no= gtid.seq_no; } if (err) @@ -5712,7 +5717,7 @@ MYSQL_BIN_LOG::write_state_to_file() char buf[FN_REFLEN]; int err; bool opened= false; - bool inited= false; + bool log_inited= false; fn_format(buf, opt_bin_logname, mysql_data_home, ".state", MY_UNPACK_FILENAME); @@ -5727,10 +5732,10 @@ MYSQL_BIN_LOG::write_state_to_file() if ((err= init_io_cache(&cache, file_no, IO_SIZE, WRITE_CACHE, 0, 0, MYF(MY_WME|MY_WAIT_IF_FULL)))) goto err; - inited= true; + log_inited= true; if ((err= rpl_global_gtid_binlog_state.write_to_iocache(&cache))) goto err; - inited= false; + log_inited= false; if ((err= end_io_cache(&cache))) goto err; if ((err= mysql_file_sync(file_no, MYF(MY_WME|MY_SYNC_FILESIZE)))) @@ -5739,7 +5744,7 @@ MYSQL_BIN_LOG::write_state_to_file() err: sql_print_error("Error writing binlog state to file '%s'.\n", buf); - if (inited) + if (log_inited) end_io_cache(&cache); end: if (opened) @@ -5765,7 +5770,7 @@ MYSQL_BIN_LOG::read_state_from_file() char buf[FN_REFLEN]; int err; bool opened= false; - bool inited= false; + bool log_inited= false; fn_format(buf, opt_bin_logname, mysql_data_home, ".state", MY_UNPACK_FILENAME); @@ -5792,7 +5797,7 @@ MYSQL_BIN_LOG::read_state_from_file() if ((err= init_io_cache(&cache, file_no, IO_SIZE, READ_CACHE, 0, 0, MYF(MY_WME|MY_WAIT_IF_FULL)))) goto err; - inited= true; + log_inited= true; if ((err= rpl_global_gtid_binlog_state.read_from_iocache(&cache))) goto err; goto end; @@ -5800,7 +5805,7 @@ MYSQL_BIN_LOG::read_state_from_file() err: sql_print_error("Error reading binlog GTID state from file '%s'.\n", buf); end: - if (inited) + if (log_inited) end_io_cache(&cache); if (opened) mysql_file_close(file_no, MYF(0)); @@ -5838,11 +5843,11 @@ MYSQL_BIN_LOG::is_empty_state() bool -MYSQL_BIN_LOG::find_in_binlog_state(uint32 domain_id, uint32 server_id, +MYSQL_BIN_LOG::find_in_binlog_state(uint32 domain_id, uint32 server_id_arg, rpl_gtid *out_gtid) { rpl_gtid *gtid; - if ((gtid= rpl_global_gtid_binlog_state.find(domain_id, server_id))) + if ((gtid= rpl_global_gtid_binlog_state.find(domain_id, server_id_arg))) *out_gtid= *gtid; return gtid != NULL; } @@ -5872,11 +5877,13 @@ MYSQL_BIN_LOG::bump_seq_no_counter_if_needed(uint32 domain_id, uint64 seq_no) bool -MYSQL_BIN_LOG::check_strict_gtid_sequence(uint32 domain_id, uint32 server_id, +MYSQL_BIN_LOG::check_strict_gtid_sequence(uint32 domain_id, + uint32 server_id_arg, uint64 seq_no) { return rpl_global_gtid_binlog_state.check_strict_sequence(domain_id, - server_id, seq_no); + server_id_arg, + seq_no); } @@ -5965,11 +5972,12 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate) prev_binlog_id= current_binlog_id; DBUG_EXECUTE_IF("binlog_force_commit_id", { - const LEX_STRING name= { C_STRING_WITH_LEN("commit_id") }; + const LEX_STRING commit_name= { C_STRING_WITH_LEN("commit_id") }; bool null_value; user_var_entry *entry= (user_var_entry*) my_hash_search(&thd->user_vars, - (uchar*) name.str, name.length); + (uchar*) commit_name.str, + commit_name.length); commit_id= entry->val_int(&null_value); }); if (write_gtid_event(thd, true, using_trans, commit_id)) @@ -6808,11 +6816,10 @@ bool MYSQL_BIN_LOG::write_incident(THD *thd) } void -MYSQL_BIN_LOG::write_binlog_checkpoint_event_already_locked(const char *name, - uint len) +MYSQL_BIN_LOG::write_binlog_checkpoint_event_already_locked(const char *name_arg, uint len) { my_off_t offset; - Binlog_checkpoint_log_event ev(name, len); + Binlog_checkpoint_log_event ev(name_arg, len); /* Note that we must sync the binlog checkpoint to disk. Otherwise a subsequent log purge could delete binlogs that XA recovery @@ -7044,7 +7051,8 @@ MYSQL_BIN_LOG::queue_for_group_commit(group_commit_entry *orig_entry) wfc->wakeup_error= orig_entry->thd->killed_errno(); if (!wfc->wakeup_error) wfc->wakeup_error= ER_QUERY_INTERRUPTED; - my_message(wfc->wakeup_error, ER(wfc->wakeup_error), MYF(0)); + my_message(wfc->wakeup_error, + ER_THD(orig_entry->thd, wfc->wakeup_error), MYF(0)); DBUG_RETURN(-1); } } @@ -7411,11 +7419,12 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) commit_id= (last_in_queue == leader ? 0 : (uint64)leader->thd->query_id); DBUG_EXECUTE_IF("binlog_force_commit_id", { - const LEX_STRING name= { C_STRING_WITH_LEN("commit_id") }; + const LEX_STRING commit_name= { C_STRING_WITH_LEN("commit_id") }; bool null_value; user_var_entry *entry= (user_var_entry*) my_hash_search(&leader->thd->user_vars, - (uchar*) name.str, name.length); + (uchar*) commit_name.str, + commit_name.length); commit_id= entry->val_int(&null_value); }); /* @@ -8045,7 +8054,8 @@ void MYSQL_BIN_LOG::close(uint exiting) if (mysql_file_close(index_file.file, MYF(0)) < 0 && ! write_error) { write_error= 1; - sql_print_error(ER(ER_ERROR_ON_WRITE), index_file_name, errno); + sql_print_error(ER_THD_OR_DEFAULT(current_thd, ER_ERROR_ON_WRITE), + index_file_name, errno); } } log_state= (exiting & LOG_CLOSE_TO_BE_OPENED) ? LOG_TO_BE_OPENED : LOG_CLOSED; @@ -8272,7 +8282,8 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer, Add tag for slaves so that the user can see from which connection the error originates. */ - tag_length= my_snprintf(tag, sizeof(tag), ER(ER_MASTER_LOG_PREFIX), + tag_length= my_snprintf(tag, sizeof(tag), + ER_THD(thd, ER_MASTER_LOG_PREFIX), (int) thd->connection_name.length, thd->connection_name.str); } @@ -9465,7 +9476,7 @@ binlog_background_thread(void *arg __attribute__((unused))) while (queue) { THD_STAGE_INFO(thd, stage_binlog_processing_checkpoint_notify); - DEBUG_SYNC(current_thd, "binlog_background_thread_before_mark_xid_done"); + DEBUG_SYNC(thd, "binlog_background_thread_before_mark_xid_done"); /* Grab next pointer first, as mark_xid_done() may free the element. */ next= queue->next_in_queue; mysql_bin_log.mark_xid_done(queue->binlog_id, true); diff --git a/sql/log_event.cc b/sql/log_event.cc index 7594a6f7f10..6d03dca69f9 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1562,7 +1562,7 @@ Log_event* Log_event::read_log_event(const char* buf, uint event_len, DBUG_RETURN(NULL); #else *error= ER(ER_BINLOG_READ_EVENT_CHECKSUM_FAILURE); - sql_print_error("%s", ER(ER_BINLOG_READ_EVENT_CHECKSUM_FAILURE)); + sql_print_error("%s", *error); DBUG_RETURN(NULL); #endif } @@ -4355,15 +4355,15 @@ compare_errors: !ignored_error_code(expected_error)) { rli->report(ERROR_LEVEL, 0, rgi->gtid_info(), - "Query caused different errors on master and slave. " - "Error on master: message (format)='%s' error code=%d ; " - "Error on slave: actual message='%s', error code=%d. " - "Default database: '%s'. Query: '%s'", - ER_SAFE(expected_error), - expected_error, - actual_error ? thd->get_stmt_da()->message() : "no error", - actual_error, - print_slave_db_safe(db), query_arg); + "Query caused different errors on master and slave. " + "Error on master: message (format)='%s' error code=%d ; " + "Error on slave: actual message='%s', error code=%d. " + "Default database: '%s'. Query: '%s'", + ER_SAFE_THD(thd, expected_error), + expected_error, + actual_error ? thd->get_stmt_da()->message() : "no error", + actual_error, + print_slave_db_safe(db), query_arg); thd->is_slave_error= 1; } /* @@ -6006,7 +6006,7 @@ error: else { sql_errno=ER_UNKNOWN_ERROR; - err=ER(sql_errno); + err= ER_THD(thd, sql_errno); } rli->report(ERROR_LEVEL, sql_errno, rgi->gtid_info(), "\ Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'", @@ -6026,7 +6026,7 @@ Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'", print_slave_db_safe(remember_db)); rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, rgi->gtid_info(), - ER(ER_SLAVE_FATAL_ERROR), buf); + ER_THD(thd, ER_SLAVE_FATAL_ERROR), buf); DBUG_RETURN(1); } @@ -9090,7 +9090,7 @@ Execute_load_query_log_event::do_apply_event(rpl_group_info *rgi) if (buf == NULL) { rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, rgi->gtid_info(), - ER(ER_SLAVE_FATAL_ERROR), "Not enough memory"); + ER_THD(rgi->thd, ER_SLAVE_FATAL_ERROR), "Not enough memory"); return 1; } @@ -10986,13 +10986,14 @@ int Table_map_log_event::do_apply_event(rpl_group_info *rgi) if (thd->slave_thread) rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, rgi->gtid_info(), - ER(ER_SLAVE_FATAL_ERROR), buf); + ER_THD(thd, ER_SLAVE_FATAL_ERROR), buf); else /* For the cases in which a 'BINLOG' statement is set to execute in a user session */ - my_printf_error(ER_SLAVE_FATAL_ERROR, ER(ER_SLAVE_FATAL_ERROR), + my_printf_error(ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), MYF(0), buf); } @@ -12622,7 +12623,7 @@ Incident_log_event::do_apply_event(rpl_group_info *rgi) } rli->report(ERROR_LEVEL, ER_SLAVE_INCIDENT, NULL, - ER(ER_SLAVE_INCIDENT), + ER_THD(rgi->thd, ER_SLAVE_INCIDENT), description(), m_message.length > 0 ? m_message.str : "<none>"); DBUG_RETURN(1); diff --git a/sql/mdl.cc b/sql/mdl.cc index dc18dea1b5a..383cc042432 100644 --- a/sql/mdl.cc +++ b/sql/mdl.cc @@ -336,6 +336,7 @@ public: virtual bool needs_notification(const MDL_ticket *ticket) const = 0; virtual bool conflicting_locks(const MDL_ticket *ticket) const = 0; virtual bitmap_t hog_lock_types_bitmap() const = 0; + virtual ~MDL_lock_strategy() {} }; diff --git a/sql/mdl.h b/sql/mdl.h index f7a5d160e53..a80de5a4e71 100644 --- a/sql/mdl.h +++ b/sql/mdl.h @@ -334,24 +334,25 @@ public: @param name Name of of the object @param key Where to store the the MDL key. */ - void mdl_key_init(enum_mdl_namespace mdl_namespace, - const char *db, const char *name) + void mdl_key_init(enum_mdl_namespace mdl_namespace_arg, + const char *db, const char *name_arg) { - m_ptr[0]= (char) mdl_namespace; + m_ptr[0]= (char) mdl_namespace_arg; /* It is responsibility of caller to ensure that db and object names are not longer than NAME_LEN. Still we play safe and try to avoid buffer overruns. */ DBUG_ASSERT(strlen(db) <= NAME_LEN); - DBUG_ASSERT(strlen(name) <= NAME_LEN); + DBUG_ASSERT(strlen(name_arg) <= NAME_LEN); m_db_name_length= static_cast<uint16>(strmake(m_ptr + 1, db, NAME_LEN) - m_ptr - 1); - m_length= static_cast<uint16>(strmake(m_ptr + m_db_name_length + 2, name, + m_length= static_cast<uint16>(strmake(m_ptr + m_db_name_length + 2, + name_arg, NAME_LEN) - m_ptr + 1); m_hash_value= my_hash_sort(&my_charset_bin, (uchar*) m_ptr + 1, m_length - 1); - DBUG_ASSERT(mdl_namespace == USER_LOCK || ok_for_lower_case_names(db)); + DBUG_ASSERT(mdl_namespace_arg == USER_LOCK || ok_for_lower_case_names(db)); } void mdl_key_init(const MDL_key *rhs) { diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc index d4f1ae19bc6..5ec3fe7ff28 100644 --- a/sql/my_decimal.cc +++ b/sql/my_decimal.cc @@ -41,26 +41,29 @@ int decimal_operation_results(int result, const char *value, const char *type) { + /* Avoid calling current_thd on default path */ + if (likely(result == E_DEC_OK)) + return(result); + + THD *thd= current_thd; switch (result) { - case E_DEC_OK: - break; case E_DEC_TRUNCATED: - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_DATA_TRUNCATED, ER(ER_DATA_TRUNCATED), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_DATA_TRUNCATED, ER_THD(thd, ER_DATA_TRUNCATED), value, type); break; case E_DEC_OVERFLOW: - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_DATA_OVERFLOW, ER(ER_DATA_OVERFLOW), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_DATA_OVERFLOW, ER_THD(thd, ER_DATA_OVERFLOW), value, type); break; case E_DEC_DIV_ZERO: - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO)); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_DIVISION_BY_ZERO, ER_THD(thd, ER_DIVISION_BY_ZERO)); break; case E_DEC_BAD_NUM: - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_BAD_DATA, ER(ER_BAD_DATA), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_BAD_DATA, ER_THD(thd, ER_BAD_DATA), value, type); break; case E_DEC_OOM: diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 09680e87e45..7361c8443c4 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2066,7 +2066,8 @@ int QUICK_ROR_INTERSECT_SELECT::init() 1 error */ -int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler, MEM_ROOT *alloc) +int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler, + MEM_ROOT *local_alloc) { handler *save_file= file, *org_file; my_bool org_key_read; @@ -2094,7 +2095,7 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler, MEM_ROOT *alloc DBUG_RETURN(0); } - if (!(file= head->file->clone(head->s->normalized_path.str, alloc))) + if (!(file= head->file->clone(head->s->normalized_path.str, local_alloc))) { /* Manually set the error flag. Note: there seems to be quite a few @@ -2182,7 +2183,7 @@ failure: other error code */ int QUICK_ROR_INTERSECT_SELECT::init_ror_merged_scan(bool reuse_handler, - MEM_ROOT *alloc) + MEM_ROOT *local_alloc) { List_iterator_fast<QUICK_SELECT_WITH_RECORD> quick_it(quick_selects); QUICK_SELECT_WITH_RECORD *cur; @@ -2199,7 +2200,7 @@ int QUICK_ROR_INTERSECT_SELECT::init_ror_merged_scan(bool reuse_handler, There is no use of this->file. Use it for the first of merged range selects. */ - int error= quick->init_ror_merged_scan(TRUE, alloc); + int error= quick->init_ror_merged_scan(TRUE, local_alloc); if (error) DBUG_RETURN(error); quick->file->extra(HA_EXTRA_KEYREAD_PRESERVE_FIELDS); @@ -2211,7 +2212,7 @@ int QUICK_ROR_INTERSECT_SELECT::init_ror_merged_scan(bool reuse_handler, const MY_BITMAP * const save_read_set= quick->head->read_set; const MY_BITMAP * const save_write_set= quick->head->write_set; #endif - if (quick->init_ror_merged_scan(FALSE, alloc)) + if (quick->init_ror_merged_scan(FALSE, local_alloc)) DBUG_RETURN(1); quick->file->extra(HA_EXTRA_KEYREAD_PRESERVE_FIELDS); @@ -2273,11 +2274,13 @@ int QUICK_ROR_INTERSECT_SELECT::reset() */ bool -QUICK_ROR_INTERSECT_SELECT::push_quick_back(MEM_ROOT *alloc, QUICK_RANGE_SELECT *quick) +QUICK_ROR_INTERSECT_SELECT::push_quick_back(MEM_ROOT *local_alloc, + QUICK_RANGE_SELECT *quick) { QUICK_SELECT_WITH_RECORD *qr; if (!(qr= new QUICK_SELECT_WITH_RECORD) || - !(qr->key_tuple= (uchar*)alloc_root(alloc, quick->max_used_key_length))) + !(qr->key_tuple= (uchar*)alloc_root(local_alloc, + quick->max_used_key_length))) return TRUE; qr->quick= quick; return quick_selects.push_back(qr); @@ -8187,11 +8190,10 @@ SEL_TREE *Item_equal::get_mm_tree(RANGE_OPT_PARAM *param, Item **cond_ptr) while (it++) { Field *field= it.get_curr_field(); - Item_result cmp_type= field->cmp_type(); if (!((ref_tables | field->table->map) & param_comp)) { tree= get_mm_parts(param, this, field, Item_func::EQ_FUNC, - value, cmp_type); + value, field->cmp_type()); ftree= !ftree ? tree : tree_and(param, ftree, tree); } } @@ -11669,7 +11671,7 @@ int QUICK_ROR_INTERSECT_SELECT::get_next() if ((error= quick->get_next())) { /* On certain errors like deadlock, trx might be rolled back.*/ - if (!current_thd->transaction_rollback_request) + if (!thd->transaction_rollback_request) quick_with_last_rowid->file->unlock_row(); DBUG_RETURN(error); } @@ -11697,7 +11699,7 @@ int QUICK_ROR_INTERSECT_SELECT::get_next() if ((error= quick->get_next())) { /* On certain errors like deadlock, trx might be rolled back.*/ - if (!current_thd->transaction_rollback_request) + if (!thd->transaction_rollback_request) quick_with_last_rowid->file->unlock_row(); DBUG_RETURN(error); } @@ -12330,28 +12332,30 @@ void QUICK_SELECT_I::add_key_name(String *str, bool *first) } -Explain_quick_select* QUICK_RANGE_SELECT::get_explain(MEM_ROOT *alloc) +Explain_quick_select* QUICK_RANGE_SELECT::get_explain(MEM_ROOT *local_alloc) { Explain_quick_select *res; - if ((res= new (alloc) Explain_quick_select(QS_TYPE_RANGE))) - res->range.set(alloc, &head->key_info[index], max_used_key_length); + if ((res= new (local_alloc) Explain_quick_select(QS_TYPE_RANGE))) + res->range.set(local_alloc, &head->key_info[index], max_used_key_length); return res; } -Explain_quick_select* QUICK_GROUP_MIN_MAX_SELECT::get_explain(MEM_ROOT *alloc) +Explain_quick_select* +QUICK_GROUP_MIN_MAX_SELECT::get_explain(MEM_ROOT *local_alloc) { Explain_quick_select *res; - if ((res= new (alloc) Explain_quick_select(QS_TYPE_GROUP_MIN_MAX))) - res->range.set(alloc, &head->key_info[index], max_used_key_length); + if ((res= new (local_alloc) Explain_quick_select(QS_TYPE_GROUP_MIN_MAX))) + res->range.set(local_alloc, &head->key_info[index], max_used_key_length); return res; } -Explain_quick_select* QUICK_INDEX_SORT_SELECT::get_explain(MEM_ROOT *alloc) +Explain_quick_select* +QUICK_INDEX_SORT_SELECT::get_explain(MEM_ROOT *local_alloc) { Explain_quick_select *res; - if (!(res= new (alloc) Explain_quick_select(get_type()))) + if (!(res= new (local_alloc) Explain_quick_select(get_type()))) return NULL; QUICK_RANGE_SELECT *quick; @@ -12359,7 +12363,7 @@ Explain_quick_select* QUICK_INDEX_SORT_SELECT::get_explain(MEM_ROOT *alloc) List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects); while ((quick= it++)) { - if ((child_explain= quick->get_explain(alloc))) + if ((child_explain= quick->get_explain(local_alloc))) res->children.push_back(child_explain); else return NULL; @@ -12367,7 +12371,7 @@ Explain_quick_select* QUICK_INDEX_SORT_SELECT::get_explain(MEM_ROOT *alloc) if (pk_quick_select) { - if ((child_explain= pk_quick_select->get_explain(alloc))) + if ((child_explain= pk_quick_select->get_explain(local_alloc))) res->children.push_back(child_explain); else return NULL; @@ -12381,17 +12385,18 @@ Explain_quick_select* QUICK_INDEX_SORT_SELECT::get_explain(MEM_ROOT *alloc) first */ -Explain_quick_select* QUICK_INDEX_INTERSECT_SELECT::get_explain(MEM_ROOT *alloc) +Explain_quick_select* +QUICK_INDEX_INTERSECT_SELECT::get_explain(MEM_ROOT *local_alloc) { Explain_quick_select *res; Explain_quick_select *child_explain; - if (!(res= new (alloc) Explain_quick_select(get_type()))) + if (!(res= new (local_alloc) Explain_quick_select(get_type()))) return NULL; if (pk_quick_select) { - if ((child_explain= pk_quick_select->get_explain(alloc))) + if ((child_explain= pk_quick_select->get_explain(local_alloc))) res->children.push_back(child_explain); else return NULL; @@ -12401,7 +12406,7 @@ Explain_quick_select* QUICK_INDEX_INTERSECT_SELECT::get_explain(MEM_ROOT *alloc) List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects); while ((quick= it++)) { - if ((child_explain= quick->get_explain(alloc))) + if ((child_explain= quick->get_explain(local_alloc))) res->children.push_back(child_explain); else return NULL; @@ -12410,19 +12415,20 @@ Explain_quick_select* QUICK_INDEX_INTERSECT_SELECT::get_explain(MEM_ROOT *alloc) } -Explain_quick_select* QUICK_ROR_INTERSECT_SELECT::get_explain(MEM_ROOT *alloc) +Explain_quick_select* +QUICK_ROR_INTERSECT_SELECT::get_explain(MEM_ROOT *local_alloc) { Explain_quick_select *res; Explain_quick_select *child_explain; - if (!(res= new (alloc) Explain_quick_select(get_type()))) + if (!(res= new (local_alloc) Explain_quick_select(get_type()))) return NULL; QUICK_SELECT_WITH_RECORD *qr; List_iterator_fast<QUICK_SELECT_WITH_RECORD> it(quick_selects); while ((qr= it++)) { - if ((child_explain= qr->quick->get_explain(alloc))) + if ((child_explain= qr->quick->get_explain(local_alloc))) res->children.push_back(child_explain); else return NULL; @@ -12430,7 +12436,7 @@ Explain_quick_select* QUICK_ROR_INTERSECT_SELECT::get_explain(MEM_ROOT *alloc) if (cpk_quick) { - if ((child_explain= cpk_quick->get_explain(alloc))) + if ((child_explain= cpk_quick->get_explain(local_alloc))) res->children.push_back(child_explain); else return NULL; @@ -12439,19 +12445,20 @@ Explain_quick_select* QUICK_ROR_INTERSECT_SELECT::get_explain(MEM_ROOT *alloc) } -Explain_quick_select* QUICK_ROR_UNION_SELECT::get_explain(MEM_ROOT *alloc) +Explain_quick_select* +QUICK_ROR_UNION_SELECT::get_explain(MEM_ROOT *local_alloc) { Explain_quick_select *res; Explain_quick_select *child_explain; - if (!(res= new (alloc) Explain_quick_select(get_type()))) + if (!(res= new (local_alloc) Explain_quick_select(get_type()))) return NULL; QUICK_SELECT_I *quick; List_iterator_fast<QUICK_SELECT_I> it(quick_selects); while ((quick= it++)) { - if ((child_explain= quick->get_explain(alloc))) + if ((child_explain= quick->get_explain(local_alloc))) res->children.push_back(child_explain); else return NULL; diff --git a/sql/opt_range.h b/sql/opt_range.h index e81a536c2b6..c29b09a6359 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -665,8 +665,8 @@ protected: int read_keys_and_merge(); public: - QUICK_INDEX_MERGE_SELECT(THD *thd, TABLE *table) - :QUICK_INDEX_SORT_SELECT(thd, table) {} + QUICK_INDEX_MERGE_SELECT(THD *thd_arg, TABLE *table) + :QUICK_INDEX_SORT_SELECT(thd_arg, table) {} int get_next(); int get_type() { return QS_TYPE_INDEX_MERGE; } @@ -679,8 +679,8 @@ protected: int read_keys_and_merge(); public: - QUICK_INDEX_INTERSECT_SELECT(THD *thd, TABLE *table) - :QUICK_INDEX_SORT_SELECT(thd, table) {} + QUICK_INDEX_INTERSECT_SELECT(THD *thd_arg, TABLE *table) + :QUICK_INDEX_SORT_SELECT(thd_arg, table) {} key_map filtered_scans; int get_next(); diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index c0d0fa3c7f3..d56fb7c3a9b 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -5494,7 +5494,7 @@ bool JOIN::choose_subquery_plan(table_map join_tables) unmodified, and with injected IN->EXISTS predicates. */ inner_read_time_1= inner_join->best_read; - inner_record_count_1= inner_join->record_count; + inner_record_count_1= inner_join->join_record_count; if (in_to_exists_where && const_tables != table_count) { diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 0d26563d45e..9ba0c5d60cd 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -1572,11 +1572,13 @@ static void warn_if_dir_in_part_elem(THD *thd, partition_element *part_elem) { if (part_elem->data_file_name) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED), + WARN_OPTION_IGNORED, + ER_THD(thd, WARN_OPTION_IGNORED), "DATA DIRECTORY"); if (part_elem->index_file_name) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED), + WARN_OPTION_IGNORED, + ER_THD(thd, WARN_OPTION_IGNORED), "INDEX DIRECTORY"); part_elem->data_file_name= part_elem->index_file_name= NULL; } @@ -1849,16 +1851,17 @@ void partition_info::print_no_partition_found(TABLE *table_arg, myf errflag) char buf[100]; char *buf_ptr= (char*)&buf; TABLE_LIST table_list; + THD *thd= current_thd; bzero(&table_list, sizeof(table_list)); table_list.db= table_arg->s->db.str; table_list.table_name= table_arg->s->table_name.str; - if (check_single_table_access(current_thd, + if (check_single_table_access(thd, SELECT_ACL, &table_list, TRUE)) { my_message(ER_NO_PARTITION_FOR_GIVEN_VALUE, - ER(ER_NO_PARTITION_FOR_GIVEN_VALUE_SILENT), errflag); + ER_THD(thd, ER_NO_PARTITION_FOR_GIVEN_VALUE_SILENT), errflag); } else { diff --git a/sql/protocol.cc b/sql/protocol.cc index 5970568b66c..05e970c01dc 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -868,7 +868,7 @@ bool Protocol::send_result_set_metadata(List<Item> *list, uint flags) DBUG_RETURN(prepare_for_send(list->elements)); err: - my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), + my_message(ER_OUT_OF_RESOURCES, ER_THD(thd, ER_OUT_OF_RESOURCES), MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } diff --git a/sql/rpl_injector.h b/sql/rpl_injector.h index 98788955e24..6be3d7cf4ec 100644 --- a/sql/rpl_injector.h +++ b/sql/rpl_injector.h @@ -117,8 +117,8 @@ public: class table { public: - table(TABLE *table, bool is_transactional) - : m_table(table), m_is_transactional(is_transactional) + table(TABLE *table, bool is_transactional_arg) + : m_table(table), m_is_transactional(is_transactional_arg) { } diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index fc9578cbc6d..e347376762d 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -1093,7 +1093,8 @@ bool Master_info_index::init_all_master_info() else { /* Master_info already in HASH */ - sql_print_error(ER(ER_CONNECTION_ALREADY_EXISTS), + sql_print_error(ER_THD_OR_DEFAULT(current_thd, + ER_CONNECTION_ALREADY_EXISTS), (int) connection_name.length, connection_name.str); unlock_slave_threads(mi); delete mi; @@ -1110,7 +1111,8 @@ bool Master_info_index::init_all_master_info() Sql_condition::WARN_LEVEL_NOTE)) { /* Master_info was already registered */ - sql_print_error(ER(ER_CONNECTION_ALREADY_EXISTS), + sql_print_error(ER_THD_OR_DEFAULT(current_thd, + ER_CONNECTION_ALREADY_EXISTS), (int) connection_name.length, connection_name.str); unlock_slave_threads(mi); delete mi; @@ -1455,7 +1457,7 @@ bool Master_info_index::start_all_slaves(THD *thd) } else push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_SLAVE_STARTED, ER(ER_SLAVE_STARTED), + ER_SLAVE_STARTED, ER_THD(thd, ER_SLAVE_STARTED), (int) mi->connection_name.length, mi->connection_name.str); } @@ -1500,7 +1502,7 @@ bool Master_info_index::stop_all_slaves(THD *thd) } else push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_SLAVE_STOPPED, ER(ER_SLAVE_STOPPED), + ER_SLAVE_STOPPED, ER_THD(thd, ER_SLAVE_STOPPED), (int) mi->connection_name.length, mi->connection_name.str); } diff --git a/sql/rpl_record.cc b/sql/rpl_record.cc index 8c694602c74..7a412b25af3 100644 --- a/sql/rpl_record.cc +++ b/sql/rpl_record.cc @@ -290,9 +290,12 @@ unpack_row(rpl_group_info *rgi, } else { + THD *thd= f->table->in_use; + f->set_default(); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_BAD_NULL_ERROR, ER(ER_BAD_NULL_ERROR), + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_BAD_NULL_ERROR, + ER_THD(thd, ER_BAD_NULL_ERROR), f->field_name); } } @@ -465,11 +468,12 @@ int prepare_record(TABLE *const table, const uint skip, const bool check) if ((f->flags & NO_DEFAULT_VALUE_FLAG) && (f->real_type() != MYSQL_TYPE_ENUM)) { + THD *thd= f->table->in_use; f->set_default(); - push_warning_printf(current_thd, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NO_DEFAULT_FOR_FIELD, - ER(ER_NO_DEFAULT_FOR_FIELD), + ER_THD(thd, ER_NO_DEFAULT_FOR_FIELD), f->field_name); } } diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index 146bf3b0c0e..9672c883b76 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -879,16 +879,19 @@ table_def::compatible_with(THD *thd, rpl_group_info *rgi, col, field->field_name)); DBUG_ASSERT(col < size() && col < table->s->fields); DBUG_ASSERT(table->s->db.str && table->s->table_name.str); + DBUG_ASSERT(table->in_use); const char *db_name= table->s->db.str; const char *tbl_name= table->s->table_name.str; char source_buf[MAX_FIELD_WIDTH]; char target_buf[MAX_FIELD_WIDTH]; String source_type(source_buf, sizeof(source_buf), &my_charset_latin1); String target_type(target_buf, sizeof(target_buf), &my_charset_latin1); + THD *thd= table->in_use; + show_sql_type(type(col), field_metadata(col), &source_type, field->charset()); field->sql_type(target_type); rli->report(ERROR_LEVEL, ER_SLAVE_CONVERSION_FAILED, rgi->gtid_info(), - ER(ER_SLAVE_CONVERSION_FAILED), + ER_THD(thd, ER_SLAVE_CONVERSION_FAILED), col, db_name, tbl_name, source_type.c_ptr_safe(), target_type.c_ptr_safe()); return false; @@ -1018,10 +1021,12 @@ TABLE *table_def::create_conversion_table(THD *thd, rpl_group_info *rgi, err: if (conv_table == NULL) + { rli->report(ERROR_LEVEL, ER_SLAVE_CANT_CREATE_CONVERSION, rgi->gtid_info(), - ER(ER_SLAVE_CANT_CREATE_CONVERSION), + ER_THD(thd, ER_SLAVE_CANT_CREATE_CONVERSION), target_table->s->db.str, target_table->s->table_name.str); + } DBUG_RETURN(conv_table); } #endif /* MYSQL_CLIENT */ diff --git a/sql/set_var.cc b/sql/set_var.cc index c65ca3d59b7..22922563802 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -402,7 +402,7 @@ void sys_var::do_deprecated_warning(THD *thd) : ER_WARN_DEPRECATED_SYNTAX; if (thd) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_DEPRECATED_SYNTAX, ER(errmsg), + ER_WARN_DEPRECATED_SYNTAX, ER_THD(thd, errmsg), buf1, deprecation_substitute); else sql_print_warning(ER_DEFAULT(errmsg), buf1, deprecation_substitute); @@ -440,7 +440,7 @@ bool throw_bounds_warning(THD *thd, const char *name, } push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), name, buf); + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), name, buf); } return false; } @@ -460,7 +460,7 @@ bool throw_bounds_warning(THD *thd, const char *name, bool fixed, double v) } push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), name, buf); + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), name, buf); } return false; } @@ -836,7 +836,8 @@ int set_var_user::update(THD *thd) if (user_var_item->update()) { /* Give an error if it's not given already */ - my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0)); + my_message(ER_SET_CONSTANTS_ONLY, ER_THD(thd, ER_SET_CONSTANTS_ONLY), + MYF(0)); return -1; } return 0; diff --git a/sql/slave.cc b/sql/slave.cc index 76af09cb71d..78b0da2faa3 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1111,14 +1111,14 @@ static bool sql_slave_killed(rpl_group_info *rgi) else { rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, rgi->gtid_info(), - ER(ER_SLAVE_FATAL_ERROR), msg_stopped); + ER_THD(thd, ER_SLAVE_FATAL_ERROR), msg_stopped); } } else { ret= TRUE; rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, rgi->gtid_info(), - ER(ER_SLAVE_FATAL_ERROR), + ER_THD(thd, ER_SLAVE_FATAL_ERROR), msg_stopped); } } @@ -1404,7 +1404,7 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) "Master reported unrecognized MySQL version: %s", mysql->server_version); err_code= ER_SLAVE_FATAL_ERROR; - sprintf(err_buff, ER(err_code), err_buff2); + sprintf(err_buff, ER_DEFAULT(err_code), err_buff2); } else { @@ -1420,7 +1420,7 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) "Master reported unrecognized MySQL version: %s", mysql->server_version); err_code= ER_SLAVE_FATAL_ERROR; - sprintf(err_buff, ER(err_code), err_buff2); + sprintf(err_buff, ER_DEFAULT(err_code), err_buff2); break; case 3: mi->rli.relay_log.description_event_for_queue= new @@ -1460,7 +1460,7 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) { errmsg= "default Format_description_log_event"; err_code= ER_SLAVE_CREATE_EVENT_FAILURE; - sprintf(err_buff, ER(err_code), errmsg); + sprintf(err_buff, ER_DEFAULT(err_code), errmsg); goto err; } @@ -1590,7 +1590,7 @@ MySQL server ids; these ids must be different for replication to work (or \ the --replicate-same-server-id option must be used on slave but this does \ not always make sense; please check the manual before using it)."; err_code= ER_SLAVE_FATAL_ERROR; - sprintf(err_buff, ER(err_code), errmsg); + sprintf(err_buff, ER_DEFAULT(err_code), errmsg); goto err; } } @@ -1626,7 +1626,7 @@ maybe it is a *VERY OLD MASTER*."); { errmsg= "Slave configured with server id filtering could not detect the master server id."; err_code= ER_SLAVE_FATAL_ERROR; - sprintf(err_buff, ER(err_code), errmsg); + sprintf(err_buff, ER_DEFAULT(err_code), errmsg); goto err; } @@ -1665,7 +1665,7 @@ maybe it is a *VERY OLD MASTER*."); different values for the COLLATION_SERVER global variable. The values must \ be equal for the Statement-format replication to work"; err_code= ER_SLAVE_FATAL_ERROR; - sprintf(err_buff, ER(err_code), errmsg); + sprintf(err_buff, ER_DEFAULT(err_code), errmsg); goto err; } } @@ -1728,7 +1728,7 @@ inconsistency if replicated data deals with collation."); different values for the TIME_ZONE global variable. The values must \ be equal for the Statement-format replication to work"; err_code= ER_SLAVE_FATAL_ERROR; - sprintf(err_buff, ER(err_code), errmsg); + sprintf(err_buff, ER_DEFAULT(err_code), errmsg); goto err; } } @@ -2350,7 +2350,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi) rli->ign_master_log_name_end[0]= 0; if (unlikely(!(bool)rev)) mi->report(ERROR_LEVEL, ER_SLAVE_CREATE_EVENT_FAILURE, NULL, - ER(ER_SLAVE_CREATE_EVENT_FAILURE), + ER_THD(thd, ER_SLAVE_CREATE_EVENT_FAILURE), "Rotate_event (out of memory?)," " SHOW SLAVE STATUS may be inaccurate"); } @@ -2361,7 +2361,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi) rli->ign_gtids.reset(); if (unlikely(!(bool)glev)) mi->report(ERROR_LEVEL, ER_SLAVE_CREATE_EVENT_FAILURE, NULL, - ER(ER_SLAVE_CREATE_EVENT_FAILURE), + ER_THD(thd, ER_SLAVE_CREATE_EVENT_FAILURE), "Gtid_list_event (out of memory?)," " gtid_slave_pos may be inaccurate"); } @@ -2374,7 +2374,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi) rev->server_id= 0; // don't be ignored by slave SQL thread if (unlikely(rli->relay_log.append(rev))) mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, - ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE), + ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), "failed to write a Rotate event" " to the relay log, SHOW SLAVE STATUS may be" " inaccurate"); @@ -2387,7 +2387,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi) glev->set_artificial_event(); // Don't mess up Exec_Master_Log_Pos if (unlikely(rli->relay_log.append(glev))) mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, - ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE), + ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), "failed to write a Gtid_list event to the relay log, " "gtid_slave_pos may be inaccurate"); delete glev; @@ -2791,10 +2791,9 @@ static bool send_show_master_info_data(THD *thd, Master_info *mi, bool full, protocol->store(mi->using_gtid_astext(mi->using_gtid), &my_charset_bin); // Gtid_IO_Pos { - char buff[30]; - String tmp(buff, sizeof(buff), system_charset_info); - mi->gtid_current_pos.to_string(&tmp); - protocol->store(tmp.ptr(), tmp.length(), &my_charset_bin); + String tmp2(buf, sizeof(buf), system_charset_info); + mi->gtid_current_pos.to_string(&tmp2); + protocol->store(tmp2.ptr(), tmp2.length(), &my_charset_bin); } // Replicate_Do_Domain_Ids & Replicate_Ignore_Domain_Ids @@ -3672,7 +3671,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli, } mysql_mutex_unlock(&rli->data_lock); rli->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_READ_FAILURE, NULL, - ER(ER_SLAVE_RELAY_LOG_READ_FAILURE), "\ + ER_THD(thd, ER_SLAVE_RELAY_LOG_READ_FAILURE), "\ Could not parse relay log event entry. The possible reasons are: the master's \ binary log is corrupted (you can check this by running 'mysqlbinlog' on the \ binary log), the slave's relay log is corrupted (you can check this by running \ @@ -3767,7 +3766,7 @@ static int try_to_reconnect(THD *thd, MYSQL *mysql, Master_info *mi, if (messages[SLAVE_RECON_MSG_COMMAND][0]) { mi->report(WARNING_LEVEL, ER_SLAVE_MASTER_COM_FAILURE, NULL, - ER(ER_SLAVE_MASTER_COM_FAILURE), + ER_THD(thd, ER_SLAVE_MASTER_COM_FAILURE), messages[SLAVE_RECON_MSG_COMMAND], buf); } else @@ -3874,14 +3873,15 @@ pthread_handler_t handle_slave_io(void *arg) if (RUN_HOOK(binlog_relay_io, thread_start, (thd, mi))) { mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, NULL, - ER(ER_SLAVE_FATAL_ERROR), "Failed to run 'thread_start' hook"); + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Failed to run 'thread_start' hook"); goto err; } if (!(mi->mysql = mysql = mysql_init(NULL))) { mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, NULL, - ER(ER_SLAVE_FATAL_ERROR), "error in mysql_init()"); + ER_THD(thd, ER_SLAVE_FATAL_ERROR), "error in mysql_init()"); goto err; } @@ -4067,14 +4067,14 @@ slave_max_allowed_packet", goto err; case ER_MASTER_FATAL_ERROR_READING_BINLOG: mi->report(ERROR_LEVEL, ER_MASTER_FATAL_ERROR_READING_BINLOG, NULL, - ER(ER_MASTER_FATAL_ERROR_READING_BINLOG), + ER_THD(thd, ER_MASTER_FATAL_ERROR_READING_BINLOG), mysql_error_number, mysql_error(mysql)); goto err; case ER_OUT_OF_RESOURCES: sql_print_error("\ Stopping slave I/O thread due to out-of-memory error from master"); mi->report(ERROR_LEVEL, ER_OUT_OF_RESOURCES, NULL, - "%s", ER(ER_OUT_OF_RESOURCES)); + "%s", ER_THD(thd, ER_OUT_OF_RESOURCES)); goto err; } if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings, @@ -4091,7 +4091,7 @@ Stopping slave I/O thread due to out-of-memory error from master"); event_len, &event_buf, &event_len))) { mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, NULL, - ER(ER_SLAVE_FATAL_ERROR), + ER_THD(thd, ER_SLAVE_FATAL_ERROR), "Failed to run 'after_read_event' hook"); goto err; } @@ -4102,7 +4102,7 @@ Stopping slave I/O thread due to out-of-memory error from master"); if (queue_event(mi, event_buf, event_len)) { mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, - ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE), + ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), "could not queue event from master"); goto err; } @@ -4111,7 +4111,7 @@ Stopping slave I/O thread due to out-of-memory error from master"); (thd, mi, event_buf, event_len, synced))) { mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, NULL, - ER(ER_SLAVE_FATAL_ERROR), + ER_THD(thd, ER_SLAVE_FATAL_ERROR), "Failed to run 'after_queue_event' hook"); goto err; } @@ -4943,7 +4943,7 @@ static int process_io_create_file(Master_info* mi, Create_file_log_event* cev) if (unlikely(mi->rli.relay_log.append(&xev))) { mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, - ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE), + ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), "error writing Exec_load event to relay log"); goto err; } @@ -4957,7 +4957,7 @@ static int process_io_create_file(Master_info* mi, Create_file_log_event* cev) if (unlikely(mi->rli.relay_log.append(cev))) { mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, - ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE), + ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), "error writing Create_file event to relay log"); goto err; } @@ -4972,7 +4972,7 @@ static int process_io_create_file(Master_info* mi, Create_file_log_event* cev) if (unlikely(mi->rli.relay_log.append(&aev))) { mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, - ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE), + ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), "error writing Append_block event to relay log"); goto err; } @@ -6017,7 +6017,7 @@ err: handle_slave_io() prints it on return. */ if (error && error != ER_SLAVE_RELAY_LOG_WRITE_FAILURE) - mi->report(ERROR_LEVEL, error, NULL, ER(error), + mi->report(ERROR_LEVEL, error, NULL, ER_DEFAULT(error), error_msg.ptr()); DBUG_RETURN(error); @@ -6178,7 +6178,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi, if (mi->user == NULL || mi->user[0] == 0) { mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, NULL, - ER(ER_SLAVE_FATAL_ERROR), + ER_THD(thd, ER_SLAVE_FATAL_ERROR), "Invalid (empty) username when attempting to " "connect to the master server. Connection attempt " "terminated."); diff --git a/sql/sp.cc b/sql/sp.cc index 9fd17b0582d..46970bafdfc 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -317,7 +317,7 @@ Stored_routine_creation_ctx::load_from_db(THD *thd, push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_SR_INVALID_CREATION_CTX, - ER(ER_SR_INVALID_CREATION_CTX), + ER_THD(thd, ER_SR_INVALID_CREATION_CTX), (const char *) db_name, (const char *) sr_name); } @@ -1063,10 +1063,11 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp) else if (lex->create_info.if_not_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_SP_ALREADY_EXISTS, ER(ER_SP_ALREADY_EXISTS), - type == TYPE_ENUM_FUNCTION ? - "FUNCTION" : "PROCEDURE", - lex->spname->m_name.str); + ER_SP_ALREADY_EXISTS, + ER_THD(thd, ER_SP_ALREADY_EXISTS), + type == TYPE_ENUM_FUNCTION ? + "FUNCTION" : "PROCEDURE", + lex->spname->m_name.str); ret= SP_OK; @@ -1193,7 +1194,7 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp) access == SP_MODIFIES_SQL_DATA) { my_message(ER_BINLOG_UNSAFE_ROUTINE, - ER(ER_BINLOG_UNSAFE_ROUTINE), MYF(0)); + ER_THD(thd, ER_BINLOG_UNSAFE_ROUTINE), MYF(0)); ret= SP_INTERNAL_ERROR; goto done; } @@ -1201,7 +1202,7 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp) if (!(thd->security_ctx->master_access & SUPER_ACL)) { my_message(ER_BINLOG_CREATE_ROUTINE_NEED_SUPER, - ER(ER_BINLOG_CREATE_ROUTINE_NEED_SUPER), MYF(0)); + ER_THD(thd, ER_BINLOG_CREATE_ROUTINE_NEED_SUPER), MYF(0)); ret= SP_INTERNAL_ERROR; goto done; } @@ -1401,7 +1402,7 @@ sp_update_routine(THD *thd, stored_procedure_type type, sp_name *name, if (!is_deterministic) { my_message(ER_BINLOG_UNSAFE_ROUTINE, - ER(ER_BINLOG_UNSAFE_ROUTINE), MYF(0)); + ER_THD(thd, ER_BINLOG_UNSAFE_ROUTINE), MYF(0)); ret= SP_INTERNAL_ERROR; goto err; } diff --git a/sql/sp_head.cc b/sql/sp_head.cc index b637b04059c..777775e6e39 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -540,7 +540,7 @@ check_routine_name(LEX_STRING *ident) my_error(ER_SP_WRONG_NAME, MYF(0), ident->str); return TRUE; } - if (check_string_char_length(ident, "", NAME_CHAR_LEN, + if (check_string_char_length(ident, 0, NAME_CHAR_LEN, system_charset_info, 1)) { my_error(ER_TOO_LONG_IDENT, MYF(0), ident->str); @@ -3851,7 +3851,7 @@ sp_instr_error::execute(THD *thd, uint *nextp) { DBUG_ENTER("sp_instr_error::execute"); - my_message(m_errcode, ER(m_errcode), MYF(0)); + my_message(m_errcode, ER_THD(thd, m_errcode), MYF(0)); *nextp= m_ip+1; DBUG_RETURN(-1); } diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 08aedc3b780..b24da0ab239 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -451,7 +451,8 @@ int sp_cursor::open(THD *thd) { if (server_side_cursor) { - my_message(ER_SP_CURSOR_ALREADY_OPEN, ER(ER_SP_CURSOR_ALREADY_OPEN), + my_message(ER_SP_CURSOR_ALREADY_OPEN, + ER_THD(thd, ER_SP_CURSOR_ALREADY_OPEN), MYF(0)); return -1; } @@ -465,7 +466,8 @@ int sp_cursor::close(THD *thd) { if (! server_side_cursor) { - my_message(ER_SP_CURSOR_NOT_OPEN, ER(ER_SP_CURSOR_NOT_OPEN), MYF(0)); + my_message(ER_SP_CURSOR_NOT_OPEN, ER_THD(thd, ER_SP_CURSOR_NOT_OPEN), + MYF(0)); return -1; } destroy(); @@ -484,20 +486,21 @@ int sp_cursor::fetch(THD *thd, List<sp_variable> *vars) { if (! server_side_cursor) { - my_message(ER_SP_CURSOR_NOT_OPEN, ER(ER_SP_CURSOR_NOT_OPEN), MYF(0)); + my_message(ER_SP_CURSOR_NOT_OPEN, ER_THD(thd, ER_SP_CURSOR_NOT_OPEN), + MYF(0)); return -1; } if (vars->elements != result.get_field_count()) { my_message(ER_SP_WRONG_NO_OF_FETCH_ARGS, - ER(ER_SP_WRONG_NO_OF_FETCH_ARGS), MYF(0)); + ER_THD(thd, ER_SP_WRONG_NO_OF_FETCH_ARGS), MYF(0)); return -1; } DBUG_EXECUTE_IF("bug23032_emit_warning", push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, - ER(ER_UNKNOWN_ERROR));); + ER_THD(thd, ER_UNKNOWN_ERROR));); result.set_spvar_list(vars); @@ -511,7 +514,7 @@ int sp_cursor::fetch(THD *thd, List<sp_variable> *vars) */ if (! server_side_cursor->is_open()) { - my_message(ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA), MYF(0)); + my_message(ER_SP_FETCH_NO_DATA, ER_THD(thd, ER_SP_FETCH_NO_DATA), MYF(0)); return -1; } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index ad0c3976070..92ea944df0c 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1219,7 +1219,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables) char *end = strnmov(tmp_name, host.db, sizeof(tmp_name)); if (end >= tmp_name + sizeof(tmp_name)) { - sql_print_warning(ER(ER_WRONG_DB_NAME), host.db); + sql_print_warning(ER_THD(thd, ER_WRONG_DB_NAME), host.db); continue; } my_casedn_str(files_charset_info, host.db); @@ -1556,7 +1556,7 @@ static bool acl_load(THD *thd, TABLE_LIST *tables) char *end = strnmov(tmp_name, db.db, sizeof(tmp_name)); if (end >= tmp_name + sizeof(tmp_name)) { - sql_print_warning(ER(ER_WRONG_DB_NAME), db.db); + sql_print_warning(ER_THD(thd, ER_WRONG_DB_NAME), db.db); continue; } my_casedn_str(files_charset_info, db.db); @@ -2695,7 +2695,8 @@ static int check_alter_user(THD *thd, const char *host, const char *user) if (IF_WSREP((!WSREP(thd) || !thd->wsrep_applier), 1) && !thd->slave_thread && !thd->security_ctx->priv_user[0]) { - my_message(ER_PASSWORD_ANONYMOUS_USER, ER(ER_PASSWORD_ANONYMOUS_USER), + my_message(ER_PASSWORD_ANONYMOUS_USER, + ER_THD(thd, ER_PASSWORD_ANONYMOUS_USER), MYF(0)); goto end; } @@ -2801,7 +2802,8 @@ bool change_password(THD *thd, LEX_USER *user) if (!(acl_user= find_user_exact(user->host.str, user->user.str))) { mysql_mutex_unlock(&acl_cache->lock); - my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); + my_message(ER_PASSWORD_NO_MATCH, + ER_THD(thd, ER_PASSWORD_NO_MATCH), MYF(0)); goto end; } @@ -2816,7 +2818,8 @@ bool change_password(THD *thd, LEX_USER *user) } else push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_SET_PASSWORD_AUTH_PLUGIN, ER(ER_SET_PASSWORD_AUTH_PLUGIN)); + ER_SET_PASSWORD_AUTH_PLUGIN, + ER_THD(thd, ER_SET_PASSWORD_AUTH_PLUGIN)); if (update_user_table(thd, tables[USER_TABLE].table, safe_str(acl_user->host.hostname), @@ -2925,7 +2928,8 @@ int acl_set_default_role(THD *thd, const char *host, const char *user, if (!(acl_user= find_user_exact(host, user))) { mysql_mutex_unlock(&acl_cache->lock); - my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); + my_message(ER_PASSWORD_NO_MATCH, ER_THD(thd, ER_PASSWORD_NO_MATCH), + MYF(0)); goto end; } @@ -2961,7 +2965,8 @@ int acl_set_default_role(THD *thd, const char *host, const char *user, HA_READ_KEY_EXACT)) { mysql_mutex_unlock(&acl_cache->lock); - my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); + my_message(ER_PASSWORD_NO_MATCH, ER_THD(thd, ER_PASSWORD_NO_MATCH), + MYF(0)); goto end; } store_record(table, record[1]); @@ -3291,7 +3296,7 @@ static bool update_user_table(THD *thd, TABLE *table, (uchar *) user_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)) { - my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), + my_message(ER_PASSWORD_NO_MATCH, ER_THD(thd, ER_PASSWORD_NO_MATCH), MYF(0)); /* purecov: deadcode */ DBUG_RETURN(1); /* purecov: deadcode */ } @@ -3652,7 +3657,8 @@ static int replace_db_table(TABLE *table, const char *db, /* The user could be a role, check if the user is registered as a role */ if (!combo.host.length && !find_acl_role(combo.user.str)) { - my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); + my_message(ER_PASSWORD_NO_MATCH, ER_THD(table->in_use, + ER_PASSWORD_NO_MATCH), MYF(0)); DBUG_RETURN(-1); } } @@ -3919,7 +3925,8 @@ replace_proxies_priv_table(THD *thd, TABLE *table, const LEX_USER *user, /* Check if there is such a user in user table in memory? */ if (!find_user_wild(user->host.str,user->user.str)) { - my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); + my_message(ER_PASSWORD_NO_MATCH, + ER_THD(thd, ER_PASSWORD_NO_MATCH), MYF(0)); DBUG_RETURN(-1); } @@ -4584,7 +4591,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, { if (!combo.host.length && !find_acl_role(combo.user.str)) { - my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), + my_message(ER_PASSWORD_NO_MATCH, ER_THD(thd, ER_PASSWORD_NO_MATCH), MYF(0)); /* purecov: deadcode */ DBUG_RETURN(-1); /* purecov: deadcode */ } @@ -5744,7 +5751,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, if (rights & ~TABLE_ACLS) { - my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE), + my_message(ER_ILLEGAL_GRANT_FOR_TABLE, + ER_THD(thd, ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); DBUG_RETURN(TRUE); } @@ -5989,7 +5997,8 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, if (rights & ~PROC_ACLS) { - my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE), + my_message(ER_ILLEGAL_GRANT_FOR_TABLE, + ER_THD(thd, ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); DBUG_RETURN(TRUE); } @@ -7160,7 +7169,7 @@ bool check_column_grant_in_table_ref(THD *thd, TABLE_LIST * table_ref, return FALSE; } table_ref->belong_to_view->allowed_show= FALSE; - my_message(ER_VIEW_NO_EXPLAIN, ER(ER_VIEW_NO_EXPLAIN), MYF(0)); + my_message(ER_VIEW_NO_EXPLAIN, ER_THD(thd, ER_VIEW_NO_EXPLAIN), MYF(0)); return TRUE; } } @@ -9434,11 +9443,13 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list, bool handle_as_role) binlog= true; if (handle_as_role) push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_ROLE_CREATE_EXISTS, ER(ER_ROLE_CREATE_EXISTS), + ER_ROLE_CREATE_EXISTS, + ER_THD(thd, ER_ROLE_CREATE_EXISTS), user_name->user.str); else push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_USER_CREATE_EXISTS, ER(ER_USER_CREATE_EXISTS), + ER_USER_CREATE_EXISTS, + ER_THD(thd, ER_USER_CREATE_EXISTS), user_name->user.str, user_name->host.str); continue; } @@ -9573,11 +9584,13 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list, bool handle_as_role) // "DROP USER IF EXISTS user1" for a non-existing user or role if (handle_as_role) push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_ROLE_DROP_EXISTS, ER(ER_ROLE_DROP_EXISTS), + ER_ROLE_DROP_EXISTS, + ER_THD(thd, ER_ROLE_DROP_EXISTS), user_name->user.str); else push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_USER_DROP_EXISTS, ER(ER_USER_DROP_EXISTS), + ER_USER_DROP_EXISTS, + ER_THD(thd, ER_USER_DROP_EXISTS), user_name->user.str, user_name->host.str); binlog= true; continue; @@ -9928,8 +9941,8 @@ bool mysql_revoke_all(THD *thd, List <LEX_USER> &list) mysql_mutex_unlock(&acl_cache->lock); if (result) - my_message(ER_REVOKE_GRANTS, ER(ER_REVOKE_GRANTS), MYF(0)); - + my_message(ER_REVOKE_GRANTS, ER_THD(thd, ER_REVOKE_GRANTS), MYF(0)); + result= result | write_bin_log(thd, FALSE, thd->query(), thd->query_length()); @@ -11162,12 +11175,12 @@ static void login_failed_error(THD *thd) my_error(access_denied_error_code(thd->password), MYF(0), thd->main_security_ctx.user, thd->main_security_ctx.host_or_ip, - thd->password ? ER(ER_YES) : ER(ER_NO)); + thd->password ? ER_THD(thd, ER_YES) : ER_THD(thd, ER_NO)); general_log_print(thd, COM_CONNECT, - ER(access_denied_error_code(thd->password)), + ER_THD(thd, access_denied_error_code(thd->password)), thd->main_security_ctx.user, thd->main_security_ctx.host_or_ip, - thd->password ? ER(ER_YES) : ER(ER_NO)); + thd->password ? ER_THD(thd, ER_YES) : ER_THD(thd, ER_NO)); status_var_increment(thd->status_var.access_denied_errors); /* Log access denied messages to the error log when log-warnings = 2 @@ -11176,10 +11189,10 @@ static void login_failed_error(THD *thd) */ if (global_system_variables.log_warnings > 1) { - sql_print_warning(ER(access_denied_error_code(thd->password)), + sql_print_warning(ER_THD(thd, access_denied_error_code(thd->password)), thd->main_security_ctx.user, thd->main_security_ctx.host_or_ip, - thd->password ? ER(ER_YES) : ER(ER_NO)); + thd->password ? ER_THD(thd, ER_YES) : ER_THD(thd, ER_NO)); } } @@ -11320,14 +11333,16 @@ static bool secure_auth(THD *thd) my_error(ER_SERVER_IS_IN_SECURE_AUTH_MODE, MYF(0), thd->security_ctx->user, thd->security_ctx->host_or_ip); - general_log_print(thd, COM_CONNECT, ER(ER_SERVER_IS_IN_SECURE_AUTH_MODE), + general_log_print(thd, COM_CONNECT, + ER_THD(thd, ER_SERVER_IS_IN_SECURE_AUTH_MODE), thd->security_ctx->user, thd->security_ctx->host_or_ip); } else { my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0)); - general_log_print(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE)); + general_log_print(thd, COM_CONNECT, + ER_THD(thd, ER_NOT_SUPPORTED_AUTH_MODE)); } return 1; } @@ -11399,7 +11414,8 @@ static bool send_plugin_request_packet(MPVIO_EXT *mpvio, if (switch_from_short_to_long_scramble) { my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0)); - general_log_print(mpvio->thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE)); + general_log_print(mpvio->thd, COM_CONNECT, + ER_THD(mpvio->thd, ER_NOT_SUPPORTED_AUTH_MODE)); DBUG_RETURN (1); } @@ -11476,7 +11492,8 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio) DBUG_ASSERT(my_strcasecmp(system_charset_info, mpvio->acl_user->plugin.str, old_password_plugin_name.str)); my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0)); - general_log_print(mpvio->thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE)); + general_log_print(mpvio->thd, COM_CONNECT, + ER_THD(mpvio->thd, ER_NOT_SUPPORTED_AUTH_MODE)); DBUG_RETURN (1); } @@ -11550,7 +11567,8 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length) if (passwd >= end) { - my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd, ER_UNKNOWN_COM_ERROR), + MYF(0)); DBUG_RETURN (1); } @@ -11574,7 +11592,8 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length) */ if (db >= end) { - my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd, ER_UNKNOWN_COM_ERROR), + MYF(0)); DBUG_RETURN (1); } @@ -11632,7 +11651,8 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length) { if (next_field >= end) { - my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd, ER_UNKNOWN_COM_ERROR), + MYF(0)); DBUG_RETURN(1); } client_plugin= fix_plugin_ptr(next_field); @@ -11656,11 +11676,12 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length) } } - if ((mpvio->thd->client_capabilities & CLIENT_CONNECT_ATTRS) && + if ((thd->client_capabilities & CLIENT_CONNECT_ATTRS) && read_client_connect_attrs(&next_field, end, - mpvio->thd->charset())) + thd->charset())) { - my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd, ER_UNKNOWN_COM_ERROR), + MYF(0)); DBUG_RETURN(packet_error); } diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index 5b64a792016..d917bd69f72 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -496,7 +496,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, protocol->store(operator_name, system_charset_info); protocol->store(STRING_WITH_LEN("error"), system_charset_info); length= my_snprintf(buff, sizeof(buff), - ER(ER_DROP_PARTITION_NON_EXISTENT), + ER_THD(thd, ER_DROP_PARTITION_NON_EXISTENT), table_name); protocol->store(buff, length, system_charset_info); if(protocol->write()) @@ -545,12 +545,13 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, DBUG_PRINT("admin", ("open table failed")); if (thd->get_stmt_da()->is_warning_info_empty()) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, - ER_CHECK_NO_SUCH_TABLE, ER(ER_CHECK_NO_SUCH_TABLE)); + ER_CHECK_NO_SUCH_TABLE, + ER_THD(thd, ER_CHECK_NO_SUCH_TABLE)); /* if it was a view will check md5 sum */ if (table->view && view_check(thd, table, check_opt) == HA_ADMIN_WRONG_CHECKSUM) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, - ER_VIEW_CHECKSUM, ER(ER_VIEW_CHECKSUM)); + ER_VIEW_CHECKSUM, ER_THD(thd, ER_VIEW_CHECKSUM)); if (thd->get_stmt_da()->is_error() && table_not_corrupt_error(thd->get_stmt_da()->sql_errno())) result_code= HA_ADMIN_FAILED; @@ -584,7 +585,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, protocol->store(table_name, system_charset_info); protocol->store(operator_name, system_charset_info); protocol->store(STRING_WITH_LEN("error"), system_charset_info); - length= my_snprintf(buff, sizeof(buff), ER(ER_OPEN_AS_READONLY), + length= my_snprintf(buff, sizeof(buff), ER_THD(thd, ER_OPEN_AS_READONLY), table_name); protocol->store(buff, length, system_charset_info); trans_commit_stmt(thd); @@ -813,7 +814,8 @@ send_result_message: { char buf[MYSQL_ERRMSG_SIZE]; size_t length=my_snprintf(buf, sizeof(buf), - ER(ER_CHECK_NOT_IMPLEMENTED), operator_name); + ER_THD(thd, ER_CHECK_NOT_IMPLEMENTED), + operator_name); protocol->store(STRING_WITH_LEN("note"), system_charset_info); protocol->store(buf, length, system_charset_info); } @@ -823,7 +825,8 @@ send_result_message: { char buf[MYSQL_ERRMSG_SIZE]; size_t length= my_snprintf(buf, sizeof(buf), - ER(ER_BAD_TABLE_ERROR), table_name); + ER_THD(thd, ER_BAD_TABLE_ERROR), + table_name); protocol->store(STRING_WITH_LEN("note"), system_charset_info); protocol->store(buf, length, system_charset_info); } @@ -968,7 +971,8 @@ send_result_message: case HA_ADMIN_WRONG_CHECKSUM: { protocol->store(STRING_WITH_LEN("note"), system_charset_info); - protocol->store(ER(ER_VIEW_CHECKSUM), strlen(ER(ER_VIEW_CHECKSUM)), + protocol->store(ER_THD(thd, ER_VIEW_CHECKSUM), + strlen(ER_THD(thd, ER_VIEW_CHECKSUM)), system_charset_info); break; } @@ -983,10 +987,12 @@ send_result_message: protocol->store(STRING_WITH_LEN("error"), system_charset_info); if (what_to_upgrade) - length= my_snprintf(buf, sizeof(buf), ER(ER_TABLE_NEEDS_UPGRADE), + length= my_snprintf(buf, sizeof(buf), + ER_THD(thd, ER_TABLE_NEEDS_UPGRADE), what_to_upgrade, table->table_name); else - length= my_snprintf(buf, sizeof(buf), ER(ER_TABLE_NEEDS_REBUILD), + length= my_snprintf(buf, sizeof(buf), + ER_THD(thd, ER_TABLE_NEEDS_REBUILD), table->table_name); protocol->store(buf, length, system_charset_info); fatal_error=1; diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc index e413361191d..bff45e089a4 100644 --- a/sql/sql_alter.cc +++ b/sql/sql_alter.cc @@ -294,11 +294,11 @@ bool Sql_cmd_alter_table::execute(THD *thd) /* Don't yet allow changing of symlinks with ALTER TABLE */ if (create_info.data_file_name) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED), + WARN_OPTION_IGNORED, ER_THD(thd, WARN_OPTION_IGNORED), "DATA DIRECTORY"); if (create_info.index_file_name) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED), + WARN_OPTION_IGNORED, ER_THD(thd, WARN_OPTION_IGNORED), "INDEX DIRECTORY"); create_info.data_file_name= create_info.index_file_name= NULL; diff --git a/sql/sql_array.h b/sql/sql_array.h index da95e99daa4..159951e26a6 100644 --- a/sql/sql_array.h +++ b/sql/sql_array.h @@ -36,16 +36,16 @@ template <typename Element_type> class Bounds_checked_array public: Bounds_checked_array() : m_array(NULL), m_size(0) {} - Bounds_checked_array(Element_type *el, size_t size) - : m_array(el), m_size(size) + Bounds_checked_array(Element_type *el, size_t size_arg) + : m_array(el), m_size(size_arg) {} void reset() { m_array= NULL; m_size= 0; } - void reset(Element_type *array, size_t size) + void reset(Element_type *array_arg, size_t size_arg) { - m_array= array; - m_size= size; + m_array= array_arg; + m_size= size_arg; } /** diff --git a/sql/sql_base.cc b/sql/sql_base.cc index cadf2a98cce..4fe9bc14c57 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4297,7 +4297,8 @@ lock_table_names(THD *thd, const DDL_options_st &options, if (options.if_not_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + ER_TABLE_EXISTS_ERROR, + ER_THD(thd, ER_TABLE_EXISTS_ERROR), tables_start->table_name); } else @@ -8713,7 +8714,7 @@ err_no_arena: */ bool -fill_record(THD * thd, TABLE *table_arg, List<Item> &fields, List<Item> &values, +fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values, bool ignore_errors) { List_iterator_fast<Item> f(fields),v(values); @@ -8767,13 +8768,13 @@ fill_record(THD * thd, TABLE *table_arg, List<Item> &fields, List<Item> &values, { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN, - ER(ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN), + ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN), rfield->field_name, table->s->table_name.str); } if ((!rfield->vcol_info || rfield->stored_in_db) && (value->save_in_field(rfield, 0)) < 0 && !ignore_errors) { - my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0)); + my_message(ER_UNKNOWN_ERROR, ER_THD(thd, ER_UNKNOWN_ERROR), MYF(0)); goto err; } rfield->set_explicit_default(value); @@ -8919,7 +8920,7 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values, { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN, - ER(ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN), + ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN), field->field_name, table->s->table_name.str); } diff --git a/sql/sql_bitmap.h b/sql/sql_bitmap.h index 55b2d7eefd9..229c4dc8379 100644 --- a/sql/sql_bitmap.h +++ b/sql/sql_bitmap.h @@ -168,7 +168,7 @@ public: class Iterator : public Table_map_iterator { public: - Iterator(Bitmap<64> &bmp) : Table_map_iterator(bmp.map) {} + Iterator(Bitmap<64> &map2) : Table_map_iterator(map2.map) {} }; uint bits_set() { diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 163078babbf..fda4f5848be 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1137,7 +1137,7 @@ Internal_error_handler *THD::pop_internal_handler() void THD::raise_error(uint sql_errno) { - const char* msg= ER(sql_errno); + const char* msg= ER_THD(this, sql_errno); (void) raise_condition(sql_errno, NULL, Sql_condition::WARN_LEVEL_ERROR, @@ -1150,7 +1150,7 @@ void THD::raise_error_printf(uint sql_errno, ...) char ebuff[MYSQL_ERRMSG_SIZE]; DBUG_ENTER("THD::raise_error_printf"); DBUG_PRINT("my", ("nr: %d errno: %d", sql_errno, errno)); - const char* format= ER(sql_errno); + const char* format= ER_THD(this, sql_errno); va_start(args, sql_errno); my_vsnprintf(ebuff, sizeof(ebuff), format, args); va_end(args); @@ -1163,7 +1163,7 @@ void THD::raise_error_printf(uint sql_errno, ...) void THD::raise_warning(uint sql_errno) { - const char* msg= ER(sql_errno); + const char* msg= ER_THD(this, sql_errno); (void) raise_condition(sql_errno, NULL, Sql_condition::WARN_LEVEL_WARN, @@ -1176,7 +1176,7 @@ void THD::raise_warning_printf(uint sql_errno, ...) char ebuff[MYSQL_ERRMSG_SIZE]; DBUG_ENTER("THD::raise_warning_printf"); DBUG_PRINT("enter", ("warning: %u", sql_errno)); - const char* format= ER(sql_errno); + const char* format= ER_THD(this, sql_errno); va_start(args, sql_errno); my_vsnprintf(ebuff, sizeof(ebuff), format, args); va_end(args); @@ -1193,7 +1193,7 @@ void THD::raise_note(uint sql_errno) DBUG_PRINT("enter", ("code: %d", sql_errno)); if (!(variables.option_bits & OPTION_SQL_NOTES)) DBUG_VOID_RETURN; - const char* msg= ER(sql_errno); + const char* msg= ER_THD(this, sql_errno); (void) raise_condition(sql_errno, NULL, Sql_condition::WARN_LEVEL_NOTE, @@ -1209,7 +1209,7 @@ void THD::raise_note_printf(uint sql_errno, ...) DBUG_PRINT("enter",("code: %u", sql_errno)); if (!(variables.option_bits & OPTION_SQL_NOTES)) DBUG_VOID_RETURN; - const char* format= ER(sql_errno); + const char* format= ER_THD(this, sql_errno); va_start(args, sql_errno); my_vsnprintf(ebuff, sizeof(ebuff), format, args); va_end(args); @@ -1243,7 +1243,7 @@ Sql_condition* THD::raise_condition(uint sql_errno, if (sql_errno == 0) sql_errno= ER_UNKNOWN_ERROR; if (msg == NULL) - msg= ER(sql_errno); + msg= ER_THD(this, sql_errno); if (sqlstate == NULL) sqlstate= mysql_errno_to_sqlstate(sql_errno); @@ -2954,7 +2954,7 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u) */ push_warning(thd, Sql_condition::WARN_LEVEL_WARN, WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED, - ER(WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED)); + ER_THD(thd, WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED)); } field_term_length=exchange->field_term->length(); field_term_char= field_term_length ? @@ -2984,7 +2984,8 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u) field_term_length && strchr(NUMERIC_CHARS, field_term_char))) { push_warning(thd, Sql_condition::WARN_LEVEL_WARN, - ER_AMBIGUOUS_FIELD_TERM, ER(ER_AMBIGUOUS_FIELD_TERM)); + ER_AMBIGUOUS_FIELD_TERM, + ER_THD(thd, ER_AMBIGUOUS_FIELD_TERM)); is_ambiguous_field_term= TRUE; } else @@ -3061,7 +3062,7 @@ int select_export::send_data(List<Item> &items) res->charset(), 6); push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, - ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), "string", printable_buff, item->name, static_cast<long>(row_count)); } @@ -3071,7 +3072,8 @@ int select_export::send_data(List<Item> &items) result is longer than UINT_MAX32 and doesn't fit into String */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_DATA_TRUNCATED, ER(WARN_DATA_TRUNCATED), + WARN_DATA_TRUNCATED, + ER_THD(thd, WARN_DATA_TRUNCATED), item->full_name(), static_cast<long>(row_count)); } cvt_str.length(bytes); @@ -3271,7 +3273,7 @@ int select_dump::send_data(List<Item> &items) if (row_count++ > 1) { - my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0)); + my_message(ER_TOO_MANY_ROWS, ER_THD(thd, ER_TOO_MANY_ROWS), MYF(0)); goto err; } while ((item=li++)) @@ -3300,7 +3302,7 @@ int select_singlerow_subselect::send_data(List<Item> &items) Item_singlerow_subselect *it= (Item_singlerow_subselect *)item; if (it->assigned()) { - my_message(ER_SUBQUERY_NO_1_ROW, ER(ER_SUBQUERY_NO_1_ROW), + my_message(ER_SUBQUERY_NO_1_ROW, ER_THD(thd, ER_SUBQUERY_NO_1_ROW), MYF(current_thd->lex->ignore ? ME_JUST_WARNING : 0)); DBUG_RETURN(1); } @@ -3473,7 +3475,7 @@ int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u) if (var_list.elements != list.elements) { my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT, - ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0)); + ER_THD(thd, ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0)); return 1; } return 0; @@ -3827,7 +3829,7 @@ int select_dumpvar::send_data(List<Item> &items) } if (row_count++) { - my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0)); + my_message(ER_TOO_MANY_ROWS, ER_THD(thd, ER_TOO_MANY_ROWS), MYF(0)); DBUG_RETURN(1); } while ((mv= var_li++) && (item= it++)) @@ -3842,7 +3844,7 @@ bool select_dumpvar::send_eof() { if (! row_count) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, - ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA)); + ER_SP_FETCH_NO_DATA, ER_THD(thd, ER_SP_FETCH_NO_DATA)); /* Don't send EOF if we're in error condition (which implies we've already sent or are sending an error) @@ -5742,7 +5744,8 @@ int THD::decide_logging_format(TABLE_LIST *tables) unsafe_type++) if (unsafe_flags & (1 << unsafe_type)) my_error((error= ER_BINLOG_UNSAFE_AND_STMT_ENGINE), MYF(0), - ER(LEX::binlog_stmt_unsafe_errcode[unsafe_type])); + ER_THD(this, + LEX::binlog_stmt_unsafe_errcode[unsafe_type])); } /* log in statement format! */ } @@ -5782,7 +5785,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) DBUG_PRINT("info", ("Scheduling warning to be issued by " "binlog_query: '%s'", - ER(ER_BINLOG_UNSAFE_STATEMENT))); + ER_THD(this, ER_BINLOG_UNSAFE_STATEMENT))); DBUG_PRINT("info", ("binlog_unsafe_warning_flags: 0x%x", binlog_unsafe_warning_flags)); } @@ -6349,13 +6352,13 @@ static void reset_binlog_unsafe_suppression(ulonglong now) /** Auxiliary function to print warning in the error log. */ -static void print_unsafe_warning_to_log(int unsafe_type, char* buf, - char* query) +static void print_unsafe_warning_to_log(THD *thd, int unsafe_type, char* buf, + char* query) { DBUG_ENTER("print_unsafe_warning_in_log"); - sprintf(buf, ER(ER_BINLOG_UNSAFE_STATEMENT), - ER(LEX::binlog_stmt_unsafe_errcode[unsafe_type])); - sql_print_warning(ER(ER_MESSAGE_AND_STATEMENT), buf, query); + sprintf(buf, ER_THD(thd, ER_BINLOG_UNSAFE_STATEMENT), + ER_THD(thd, LEX::binlog_stmt_unsafe_errcode[unsafe_type])); + sql_print_warning(ER_THD(thd, ER_MESSAGE_AND_STATEMENT), buf, query); DBUG_VOID_RETURN; } @@ -6483,11 +6486,11 @@ void THD::issue_unsafe_warnings() { push_warning_printf(this, Sql_condition::WARN_LEVEL_NOTE, ER_BINLOG_UNSAFE_STATEMENT, - ER(ER_BINLOG_UNSAFE_STATEMENT), - ER(LEX::binlog_stmt_unsafe_errcode[unsafe_type])); + ER_THD(this, ER_BINLOG_UNSAFE_STATEMENT), + ER_THD(this, LEX::binlog_stmt_unsafe_errcode[unsafe_type])); if (global_system_variables.log_warnings > 0 && !protect_against_unsafe_warning_flood(unsafe_type)) - print_unsafe_warning_to_log(unsafe_type, buf, query()); + print_unsafe_warning_to_log(this, unsafe_type, buf, query()); } } DBUG_VOID_RETURN; @@ -6868,7 +6871,7 @@ wait_for_commit::wait_for_prior_commit2(THD *thd) wakeup_error= thd->killed_errno(); if (!wakeup_error) wakeup_error= ER_QUERY_INTERRUPTED; - my_message(wakeup_error, ER(wakeup_error), MYF(0)); + my_message(wakeup_error, ER_THD(thd, wakeup_error), MYF(0)); thd->EXIT_COND(&old_stage); /* Must do the DEBUG_SYNC() _after_ exit_cond(), as DEBUG_SYNC is not safe to diff --git a/sql/sql_class.h b/sql/sql_class.h index 37b1dd9d43d..b9415f3c13b 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1786,7 +1786,7 @@ struct wait_for_commit return wakeup_error; } } - void wakeup_subsequent_commits(int wakeup_error) + void wakeup_subsequent_commits(int wakeup_error_arg) { /* Do the check inline, so only the wakeup case takes the cost of a function @@ -1801,7 +1801,7 @@ struct wait_for_commit prevent a waiter from arriving just after releasing the lock. */ if (subsequent_commits_list) - wakeup_subsequent_commits2(wakeup_error); + wakeup_subsequent_commits2(wakeup_error_arg); } void unregister_wait_for_prior_commit() { @@ -3377,7 +3377,7 @@ public: { int err= killed_errno(); if (err) - my_message(err, ER(err), MYF(0)); + my_message(err, ER_THD(this, err), MYF(0)); } /* return TRUE if we will abort query if we make a warning now */ inline bool really_abort_on_warning() @@ -4617,9 +4617,10 @@ private: public: /* Number of rows in the union */ ha_rows send_records; - select_union_direct(THD *thd_arg, select_result *result, - SELECT_LEX *last_select_lex): - select_union(thd_arg), result(result), last_select_lex(last_select_lex), + select_union_direct(THD *thd_arg, select_result *result_arg, + SELECT_LEX *last_select_lex_arg): + select_union(thd_arg), result(result_arg), + last_select_lex(last_select_lex_arg), done_send_result_set_metadata(false), done_initialize_tables(false), limit_found_rows(0) { send_records= 0; } diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 1108d6dde86..f6e37f07e60 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -1166,7 +1166,7 @@ void end_connection(THD *thd) } if (!thd->killed && (net->error && net->vio != 0)) - thd->print_aborted_warning(1, ER(ER_UNKNOWN_ERROR)); + thd->print_aborted_warning(1, ER_THD(thd, ER_UNKNOWN_ERROR)); } diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 475afa882f8..74cbc336896 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -430,7 +430,7 @@ bool load_db_opt(THD *thd, const char *path, Schema_specification_st *create) get_charset_by_name(pos+1, MYF(0)))) { sql_print_error("Error while loading database options: '%s':",path); - sql_print_error(ER(ER_UNKNOWN_CHARACTER_SET),pos+1); + sql_print_error(ER_THD(thd, ER_UNKNOWN_CHARACTER_SET),pos+1); create->default_table_charset= default_charset_info; } } @@ -440,7 +440,7 @@ bool load_db_opt(THD *thd, const char *path, Schema_specification_st *create) MYF(0)))) { sql_print_error("Error while loading database options: '%s':",path); - sql_print_error(ER(ER_UNKNOWN_COLLATION),pos+1); + sql_print_error(ER_THD(thd, ER_UNKNOWN_COLLATION),pos+1); create->default_table_charset= default_charset_info; } } @@ -624,7 +624,8 @@ mysql_create_db_internal(THD *thd, char *db, else if (options.if_not_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS), db); + ER_DB_CREATE_EXISTS, ER_THD(thd, ER_DB_CREATE_EXISTS), + db); affected_rows= 0; goto not_silent; } @@ -852,7 +853,8 @@ mysql_rm_db_internal(THD *thd,char *db, bool if_exists, bool silent) else { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_DB_DROP_EXISTS, ER(ER_DB_DROP_EXISTS), db); + ER_DB_DROP_EXISTS, ER_THD(thd, ER_DB_DROP_EXISTS), + db); error= false; goto update_binlog; } @@ -1460,7 +1462,7 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch) } else { - my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); + my_message(ER_NO_DB_ERROR, ER_THD(thd, ER_NO_DB_ERROR), MYF(0)); DBUG_RETURN(TRUE); } @@ -1535,7 +1537,7 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch) sctx->priv_user, sctx->priv_host, new_db_file_name.str); - general_log_print(thd, COM_INIT_DB, ER(ER_DBACCESS_DENIED_ERROR), + general_log_print(thd, COM_INIT_DB, ER_THD(thd, ER_DBACCESS_DENIED_ERROR), sctx->priv_user, sctx->priv_host, new_db_file_name.str); my_free(new_db_file_name.str); DBUG_RETURN(TRUE); @@ -1551,7 +1553,7 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch) /* Throw a warning and free new_db_file_name. */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR), + ER_BAD_DB_ERROR, ER_THD(thd, ER_BAD_DB_ERROR), new_db_file_name.str); my_free(new_db_file_name.str); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index ac4aa40d55b..9eeddd30849 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -312,7 +312,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (safe_update && const_cond) { my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, - ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); + ER_THD(thd, ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); DBUG_RETURN(TRUE); } @@ -437,7 +437,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, delete select; free_underlaid_joins(thd, select_lex); my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, - ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); + ER_THD(thd, ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); DBUG_RETURN(TRUE); } } diff --git a/sql/sql_error.h b/sql/sql_error.h index 7308a574e1d..111495fa566 100644 --- a/sql/sql_error.h +++ b/sql/sql_error.h @@ -440,7 +440,7 @@ private: ulonglong id() const { return m_warn_id; } /** Set id of the warning information area. */ - void id(ulonglong id) { m_warn_id= id; } + void id(ulonglong id_arg) { m_warn_id= id_arg; } /** Do we have any errors and warnings that we can *show*? */ bool is_empty() const { return m_warn_list.is_empty(); } @@ -501,8 +501,8 @@ private: - GET DIAGNOSTICS @param read_only the read only property to set. */ - void set_read_only(bool read_only) - { m_read_only= read_only; } + void set_read_only(bool read_only_arg) + { m_read_only= read_only_arg; } /** Read only status. @@ -670,7 +670,7 @@ public: /** True if status information is sent to the client. */ bool is_sent() const { return m_is_sent; } - void set_is_sent(bool is_sent) { m_is_sent= is_sent; } + void set_is_sent(bool is_sent_arg) { m_is_sent= is_sent_arg; } void set_ok_status(ulonglong affected_rows, ulonglong last_insert_id, @@ -793,8 +793,8 @@ public: bool is_warning_info_read_only() const { return get_warning_info()->is_read_only(); } - void set_warning_info_read_only(bool read_only) - { get_warning_info()->set_read_only(read_only); } + void set_warning_info_read_only(bool read_only_arg) + { get_warning_info()->set_read_only(read_only_arg); } ulong error_count() const { return get_warning_info()->error_count(); } @@ -815,13 +815,14 @@ public: { return get_warning_info()->push_warning(thd, sql_condition); } Sql_condition *push_warning(THD *thd, - uint sql_errno, + uint sql_errno_arg, const char* sqlstate, Sql_condition::enum_warning_level level, const char* msg) { return get_warning_info()->push_warning(thd, - sql_errno, sqlstate, level, msg); + sql_errno_arg, sqlstate, level, + msg); } void mark_sql_conditions_for_removal() diff --git a/sql/sql_help.cc b/sql/sql_help.cc index 9ba833df491..50ce8a51f01 100644 --- a/sql/sql_help.cc +++ b/sql/sql_help.cc @@ -297,7 +297,7 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, find_type(primary_key_name, &relations->s->keynames, FIND_TYPE_NO_PREFIX) - 1) < 0) { - my_message(ER_CORRUPT_HELP_DB, ER(ER_CORRUPT_HELP_DB), MYF(0)); + my_message(ER_CORRUPT_HELP_DB, ER_THD(thd, ER_CORRUPT_HELP_DB), MYF(0)); DBUG_RETURN(-1); } rtopic_id= find_fields[help_relation_help_topic_id].field; @@ -308,7 +308,7 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, { if (topics->file->inited) topics->file->ha_index_end(); - my_message(ER_CORRUPT_HELP_DB, ER(ER_CORRUPT_HELP_DB), MYF(0)); + my_message(ER_CORRUPT_HELP_DB, ER_THD(thd, ER_CORRUPT_HELP_DB), MYF(0)); DBUG_RETURN(-1); } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 1a02b1d87fa..fbdb53a4514 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1149,12 +1149,12 @@ values_loop_end: ha_rows updated=((thd->client_capabilities & CLIENT_FOUND_ROWS) ? info.touched : info.updated); if (ignore) - sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records, + sprintf(buff, ER_THD(thd, ER_INSERT_INFO), (ulong) info.records, (lock_type == TL_WRITE_DELAYED) ? (ulong) 0 : (ulong) (info.records - info.copied), (long) thd->get_stmt_da()->current_statement_warn_count()); else - sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records, + sprintf(buff, ER_THD(thd, ER_INSERT_INFO), (ulong) info.records, (ulong) (info.deleted + updated), (long) thd->get_stmt_da()->current_statement_warn_count()); ::my_ok(thd, info.copied + info.deleted + updated, id, buff); @@ -1941,7 +1941,7 @@ int check_that_all_fields_are_given_values(THD *thd, TABLE *entry, { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NO_DEFAULT_FOR_VIEW_FIELD, - ER(ER_NO_DEFAULT_FOR_VIEW_FIELD), + ER_THD(thd, ER_NO_DEFAULT_FOR_VIEW_FIELD), table_list->view_db.str, table_list->view_name.str); } @@ -1949,7 +1949,7 @@ int check_that_all_fields_are_given_values(THD *thd, TABLE *entry, { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NO_DEFAULT_FOR_FIELD, - ER(ER_NO_DEFAULT_FOR_FIELD), + ER_THD(thd, ER_NO_DEFAULT_FOR_FIELD), (*field)->field_name); } err= 1; @@ -2386,7 +2386,8 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd) kill_delayed_threads_for_table(). */ if (!thd.is_error()) - my_message(ER_QUERY_INTERRUPTED, ER(ER_QUERY_INTERRUPTED), MYF(0)); + my_message(ER_QUERY_INTERRUPTED, ER_THD(&thd, ER_QUERY_INTERRUPTED), + MYF(0)); else my_message(thd.get_stmt_da()->sql_errno(), thd.get_stmt_da()->message(), MYF(0)); @@ -2449,7 +2450,8 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd) found_next_number_field= table->found_next_number_field; for (org_field= table->field; *org_field; org_field++, field++) { - if (!(*field= (*org_field)->new_field(client_thd->mem_root, copy, 1))) + if (!(*field= (*org_field)->make_new_field(client_thd->mem_root, copy, + 1))) goto error; (*field)->orig_table= copy; // Remove connection (*field)->move_field_offset(adjust_ptrs); // Point at copy->record[0] @@ -3763,11 +3765,11 @@ bool select_insert::send_eof() char buff[160]; if (info.ignore) - sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records, + sprintf(buff, ER_THD(thd, ER_INSERT_INFO), (ulong) info.records, (ulong) (info.records - info.copied), (long) thd->get_stmt_da()->current_statement_warn_count()); else - sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records, + sprintf(buff, ER_THD(thd, ER_INSERT_INFO), (ulong) info.records, (ulong) (info.deleted+info.updated), (long) thd->get_stmt_da()->current_statement_warn_count()); row_count= info.copied + info.deleted + diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 2e820e7a923..fba95e978e8 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -2868,21 +2868,21 @@ public: return false; } // Add a key as a part of CREATE TABLE or ALTER TABLE - bool add_key(Key::Keytype type, const LEX_STRING &name, + bool add_key(Key::Keytype key_type, const LEX_STRING &key_name, ha_key_alg algorithm, DDL_options_st ddl) { if (check_add_key(ddl) || - !(last_key= new Key(type, name, algorithm, false, ddl))) + !(last_key= new Key(key_type, key_name, algorithm, false, ddl))) return true; alter_info.key_list.push_back(last_key); return false; } // Add a key for a CREATE INDEX statement - bool add_create_index(Key::Keytype type, const LEX_STRING &name, + bool add_create_index(Key::Keytype key_type, const LEX_STRING &key_name, ha_key_alg algorithm, DDL_options_st ddl) { if (check_create_options(ddl) || - !(last_key= new Key(type, name, algorithm, false, ddl))) + !(last_key= new Key(key_type, key_name, algorithm, false, ddl))) return true; alter_info.key_list.push_back(last_key); return false; diff --git a/sql/sql_list.h b/sql/sql_list.h index e8fd5c66e0b..6f01b64df70 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -48,8 +48,8 @@ public: { /* never called */ } static void operator delete[](void *ptr, size_t size) { TRASH(ptr, size); } #ifdef HAVE_valgrind - bool dummy; - inline Sql_alloc() :dummy(0) {} + bool dummy_for_valgrind; + inline Sql_alloc() :dummy_for_valgrind(0) {} inline ~Sql_alloc() {} #else inline Sql_alloc() {} diff --git a/sql/sql_load.cc b/sql/sql_load.cc index e0e0d66ccb7..1c08df22755 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -200,7 +200,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, if (escaped->length() > 1 || enclosed->length() > 1) { - my_message(ER_WRONG_FIELD_TERMINATORS,ER(ER_WRONG_FIELD_TERMINATORS), + my_message(ER_WRONG_FIELD_TERMINATORS, + ER_THD(thd, ER_WRONG_FIELD_TERMINATORS), MYF(0)); DBUG_RETURN(TRUE); } @@ -212,7 +213,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, { push_warning(thd, Sql_condition::WARN_LEVEL_WARN, WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED, - ER(WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED)); + ER_THD(thd, WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED)); } if (open_and_lock_tables(thd, table_list, TRUE, 0)) @@ -323,7 +324,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, } if (use_blobs && !ex->line_term->length() && !field_term->length()) { - my_message(ER_BLOBS_AND_NO_TERMINATED,ER(ER_BLOBS_AND_NO_TERMINATED), + my_message(ER_BLOBS_AND_NO_TERMINATED, + ER_THD(thd, ER_BLOBS_AND_NO_TERMINATED), MYF(0)); DBUG_RETURN(TRUE); } @@ -572,7 +574,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, error= -1; // Error on read goto err; } - sprintf(name, ER(ER_LOAD_INFO), (ulong) info.records, (ulong) info.deleted, + sprintf(name, ER_THD(thd, ER_LOAD_INFO), + (ulong) info.records, (ulong) info.deleted, (ulong) (info.records - info.copied), (long) thd->get_stmt_da()->current_statement_warn_count()); @@ -818,7 +821,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, thd->cuted_fields++; /* Not enough fields */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_TOO_FEW_RECORDS, - ER(ER_WARN_TOO_FEW_RECORDS), + ER_THD(thd, ER_WARN_TOO_FEW_RECORDS), thd->get_stmt_da()->current_row_for_warning()); /* Timestamp fields that are NOT NULL are autoupdated if there is no @@ -848,7 +851,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, thd->cuted_fields++; /* To long row */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_TOO_MANY_RECORDS, - ER(ER_WARN_TOO_MANY_RECORDS), + ER_THD(thd, ER_WARN_TOO_MANY_RECORDS), thd->get_stmt_da()->current_row_for_warning()); } @@ -884,7 +887,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, thd->cuted_fields++; /* To long row */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_TOO_MANY_RECORDS, - ER(ER_WARN_TOO_MANY_RECORDS), + ER_THD(thd, ER_WARN_TOO_MANY_RECORDS), thd->get_stmt_da()->current_row_for_warning()); } thd->get_stmt_da()->inc_current_row_for_warning(); @@ -1061,7 +1064,7 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, thd->cuted_fields++; push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_TOO_FEW_RECORDS, - ER(ER_WARN_TOO_FEW_RECORDS), + ER_THD(thd, ER_WARN_TOO_FEW_RECORDS), thd->get_stmt_da()->current_row_for_warning()); } else if (item->type() == Item::STRING_ITEM) @@ -1107,7 +1110,8 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, { thd->cuted_fields++; /* To long row */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_TOO_MANY_RECORDS, ER(ER_WARN_TOO_MANY_RECORDS), + ER_WARN_TOO_MANY_RECORDS, + ER_THD(thd, ER_WARN_TOO_MANY_RECORDS), thd->get_stmt_da()->current_row_for_warning()); if (thd->killed) DBUG_RETURN(1); @@ -1248,7 +1252,7 @@ read_xml_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, thd->cuted_fields++; push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_TOO_FEW_RECORDS, - ER(ER_WARN_TOO_FEW_RECORDS), + ER_THD(thd, ER_WARN_TOO_FEW_RECORDS), thd->get_stmt_da()->current_row_for_warning()); } else diff --git a/sql/sql_locale.cc b/sql/sql_locale.cc index d918d5c9cf4..bdda5f1b5ef 100644 --- a/sql/sql_locale.cc +++ b/sql/sql_locale.cc @@ -3494,7 +3494,8 @@ MY_LOCALE *my_locale_by_name(const char *name) { // Send a warning to the client push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX), + ER_WARN_DEPRECATED_SYNTAX, + ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX), name, locale->name); } else diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f0b2cc042a6..d5cfb1e6eca 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1374,7 +1374,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, */ if (thd->failed_com_change_user >= 3) { - my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd,ER_UNKNOWN_COM_ERROR), + MYF(0)); auth_rc= 1; } else @@ -1563,7 +1564,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } case COM_FIELD_LIST: // This isn't actually needed #ifdef DONT_ALLOW_SHOW_COMMANDS - my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + my_message(ER_NOT_ALLOWED_COMMAND, ER_THD(thd, ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ break; #else @@ -1592,7 +1593,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, /* Check given table name length. */ if (packet_length - arg_length > NAME_LEN + 1 || arg_length > SAFE_NAME_LEN) { - my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd, ER_UNKNOWN_COM_ERROR), + MYF(0)); break; } thd->convert_string(&table_name, system_charset_info, @@ -1869,7 +1871,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, my_eof(thd); break; default: - my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd, ER_UNKNOWN_COM_ERROR), + MYF(0)); break; } break; @@ -1888,7 +1891,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, case COM_DELAYED_INSERT: case COM_END: default: - my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd, ER_UNKNOWN_COM_ERROR), + MYF(0)); break; } @@ -2055,7 +2059,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, case SCH_SCHEMATA: #if defined(DONT_ALLOW_SHOW_COMMANDS) my_message(ER_NOT_ALLOWED_COMMAND, - ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ + ER_THD(thd, ER_NOT_ALLOWED_COMMAND), MYF(0)); DBUG_RETURN(1); #else break; @@ -2068,7 +2072,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, case SCH_EVENTS: #ifdef DONT_ALLOW_SHOW_COMMANDS my_message(ER_NOT_ALLOWED_COMMAND, - ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ + ER_THD(thd, ER_NOT_ALLOWED_COMMAND), MYF(0)); DBUG_RETURN(1); #else { @@ -2097,7 +2101,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, { #ifdef DONT_ALLOW_SHOW_COMMANDS my_message(ER_NOT_ALLOWED_COMMAND, - ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ + ER_THD(thd, ER_NOT_ALLOWED_COMMAND), MYF(0)); DBUG_RETURN(1); #else DBUG_ASSERT(table_ident); @@ -2277,7 +2281,7 @@ bool sp_process_definer(THD *thd) push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_NO_SUCH_USER, - ER(ER_NO_SUCH_USER), + ER_THD(thd, ER_NO_SUCH_USER), lex->definer->user.str, lex->definer->host.str); } @@ -2549,7 +2553,8 @@ mysql_execute_command(THD *thd) if (all_tables_not_ok(thd, all_tables)) { /* we warn the slave SQL thread */ - my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); + my_message(ER_SLAVE_IGNORED_TABLE, ER_THD(thd, ER_SLAVE_IGNORED_TABLE), + MYF(0)); } for (table=all_tables; table; table=table->next_global) @@ -2576,7 +2581,8 @@ mysql_execute_command(THD *thd) all_tables_not_ok(thd, all_tables)) { /* we warn the slave SQL thread */ - my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); + my_message(ER_SLAVE_IGNORED_TABLE, ER_THD(thd, ER_SLAVE_IGNORED_TABLE), + MYF(0)); DBUG_RETURN(0); } /* @@ -2880,7 +2886,7 @@ mysql_execute_command(THD *thd) */ if (lex->sroutines.records || lex->query_tables->next_global) { - my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), + my_message(ER_SET_CONSTANTS_ONLY, ER_THD(thd, ER_SET_CONSTANTS_ONLY), MYF(0)); goto error; } @@ -2890,7 +2896,7 @@ mysql_execute_command(THD *thd) (!(*it)->fixed && (*it)->fix_fields(lex->thd, it)) || (*it)->check_cols(1)) { - my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), + my_message(ER_SET_CONSTANTS_ONLY, ER_THD(thd, ER_SET_CONSTANTS_ONLY), MYF(0)); goto error; } @@ -3535,7 +3541,7 @@ end_with_restore_list: thd->global_read_lock.is_acquired()) { my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, - ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); + ER_THD(thd, ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); goto error; } @@ -3564,7 +3570,7 @@ end_with_restore_list: thd->global_read_lock.is_acquired()) { my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, - ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); + ER_THD(thd, ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); goto error; } mysql_mutex_lock(&LOCK_active_mi); @@ -3584,7 +3590,7 @@ end_with_restore_list: #ifndef EMBEDDED_LIBRARY case SQLCOM_SHOW_BINLOGS: #ifdef DONT_ALLOW_SHOW_COMMANDS - my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + my_message(ER_NOT_ALLOWED_COMMAND, ER_THD(thd, ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ goto error; #else @@ -3600,7 +3606,7 @@ end_with_restore_list: { DBUG_ASSERT(first_table == all_tables && first_table != 0); #ifdef DONT_ALLOW_SHOW_COMMANDS - my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + my_message(ER_NOT_ALLOWED_COMMAND, ER_THD(thd, ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ goto error; #else @@ -4191,7 +4197,7 @@ end_with_restore_list: break; case SQLCOM_SHOW_ENGINE_LOGS: #ifdef DONT_ALLOW_SHOW_COMMANDS - my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + my_message(ER_NOT_ALLOWED_COMMAND, ER_THD(thd, ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ goto error; #else @@ -4224,7 +4230,7 @@ end_with_restore_list: if (!(thd->client_capabilities & CLIENT_LOCAL_FILES) || !opt_local_infile) { - my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); + my_message(ER_NOT_ALLOWED_COMMAND, ER_THD(thd, ER_NOT_ALLOWED_COMMAND), MYF(0)); goto error; } } @@ -4346,7 +4352,7 @@ end_with_restore_list: if (!rpl_filter->db_ok(lex->name.str) || !rpl_filter->db_ok_with_wild_table(lex->name.str)) { - my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); + my_message(ER_SLAVE_IGNORED_TABLE, ER_THD(thd, ER_SLAVE_IGNORED_TABLE), MYF(0)); break; } } @@ -4381,7 +4387,7 @@ end_with_restore_list: if (!rpl_filter->db_ok(lex->name.str) || !rpl_filter->db_ok_with_wild_table(lex->name.str)) { - my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); + my_message(ER_SLAVE_IGNORED_TABLE, ER_THD(thd, ER_SLAVE_IGNORED_TABLE), MYF(0)); break; } } @@ -4403,7 +4409,7 @@ end_with_restore_list: !rpl_filter->db_ok_with_wild_table(db->str)) { res= 1; - my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); + my_message(ER_SLAVE_IGNORED_TABLE, ER_THD(thd, ER_SLAVE_IGNORED_TABLE), MYF(0)); break; } } @@ -4448,7 +4454,7 @@ end_with_restore_list: if (!rpl_filter->db_ok(db->str) || !rpl_filter->db_ok_with_wild_table(db->str)) { - my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); + my_message(ER_SLAVE_IGNORED_TABLE, ER_THD(thd, ER_SLAVE_IGNORED_TABLE), MYF(0)); break; } } @@ -4630,7 +4636,7 @@ end_with_restore_list: hostname_requires_resolving(user->host.str)) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_HOSTNAME_WONT_WORK, - ER(ER_WARN_HOSTNAME_WONT_WORK)); + ER_THD(thd, ER_WARN_HOSTNAME_WONT_WORK)); /* GRANT/REVOKE PROXY has the target user as a first entry in the list. @@ -4683,7 +4689,7 @@ end_with_restore_list: { if (lex->columns.elements || (lex->type && lex->type != TYPE_ENUM_PROXY)) { - my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE), + my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER_THD(thd, ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); goto error; } @@ -4793,7 +4799,7 @@ end_with_restore_list: Item *it= (Item *)lex->value_list.head(); if ((!it->fixed && it->fix_fields(lex->thd, &it)) || it->check_cols(1)) { - my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), + my_message(ER_SET_CONSTANTS_ONLY, ER_THD(thd, ER_SET_CONSTANTS_ONLY), MYF(0)); goto error; } @@ -5092,7 +5098,7 @@ end_with_restore_list: if (sp_grant_privileges(thd, lex->sphead->m_db.str, name, lex->sql_command == SQLCOM_CREATE_PROCEDURE)) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, - ER_PROC_AUTO_GRANT_FAIL, ER(ER_PROC_AUTO_GRANT_FAIL)); + ER_PROC_AUTO_GRANT_FAIL, ER_THD(thd, ER_PROC_AUTO_GRANT_FAIL)); thd->clear_error(); } @@ -5258,7 +5264,7 @@ create_sp_error: if (lex->if_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), + ER_SP_DOES_NOT_EXIST, ER_THD(thd, ER_SP_DOES_NOT_EXIST), "FUNCTION (UDF)", lex->spname->m_name.str); res= FALSE; my_ok(thd); @@ -5313,7 +5319,7 @@ create_sp_error: { push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_PROC_AUTO_REVOKE_FAIL, - ER(ER_PROC_AUTO_REVOKE_FAIL)); + ER_THD(thd, ER_PROC_AUTO_REVOKE_FAIL)); /* If this happens, an error should have been reported. */ goto error; } @@ -5329,7 +5335,7 @@ create_sp_error: { res= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), + ER_SP_DOES_NOT_EXIST, ER_THD(thd, ER_SP_DOES_NOT_EXIST), SP_COM_STRING(lex), lex->spname->m_qname.str); if (!res) my_ok(thd); @@ -5511,7 +5517,6 @@ create_sp_error: } case SQLCOM_CREATE_SERVER: { - LEX *lex= thd->lex; DBUG_PRINT("info", ("case SQLCOM_CREATE_SERVER")); if (check_global_access(thd, SUPER_ACL)) @@ -5523,7 +5528,6 @@ create_sp_error: case SQLCOM_ALTER_SERVER: { int error; - LEX *lex= thd->lex; DBUG_PRINT("info", ("case SQLCOM_ALTER_SERVER")); if (check_global_access(thd, SUPER_ACL)) @@ -5542,7 +5546,6 @@ create_sp_error: case SQLCOM_DROP_SERVER: { int err_code; - LEX *lex= thd->lex; DBUG_PRINT("info", ("case SQLCOM_DROP_SERVER")); if (check_global_access(thd, SUPER_ACL)) @@ -5956,7 +5959,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, { DBUG_PRINT("error",("No database")); if (!no_errors) - my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), + my_message(ER_NO_DB_ERROR, ER_THD(thd, ER_NO_DB_ERROR), MYF(0)); /* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ } @@ -6042,8 +6045,8 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, sctx->priv_user, sctx->priv_host, (thd->password ? - ER(ER_YES) : - ER(ER_NO))); /* purecov: tested */ + ER_THD(thd, ER_YES) : + ER_THD(thd, ER_NO))); /* purecov: tested */ } DBUG_RETURN(TRUE); /* purecov: tested */ } @@ -6686,7 +6689,7 @@ bool check_stack_overrun(THD *thd, long margin, */ char* ebuff= new char[MYSQL_ERRMSG_SIZE]; if (ebuff) { - my_snprintf(ebuff, MYSQL_ERRMSG_SIZE, ER(ER_STACK_OVERRUN_NEED_MORE), + my_snprintf(ebuff, MYSQL_ERRMSG_SIZE, ER_THD(thd, ER_STACK_OVERRUN_NEED_MORE), stack_used, my_thread_stack_size, margin); my_message(ER_STACK_OVERRUN_NEED_MORE, ebuff, MYF(ME_FATALERROR)); delete [] ebuff; @@ -7354,7 +7357,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (table->sel) { my_message(ER_DERIVED_MUST_HAVE_ALIAS, - ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0)); + ER_THD(thd, ER_DERIVED_MUST_HAVE_ALIAS), MYF(0)); DBUG_RETURN(0); } if (!(alias_str= (char*) thd->memdup(alias_str,table->table.length+1))) @@ -8079,9 +8082,9 @@ static uint kill_threads_for_user(THD *thd, LEX_USER *user, mysql_mutex_unlock(&LOCK_thread_count); if (!threads_to_kill.is_empty()) { - List_iterator_fast<THD> it(threads_to_kill); + List_iterator_fast<THD> it2(threads_to_kill); THD *next_ptr; - THD *ptr= it++; + THD *ptr= it2++; do { ptr->awake(kill_signal); @@ -8093,7 +8096,7 @@ static uint kill_threads_for_user(THD *thd, LEX_USER *user, Since the operation "it++" dereferences the "next" pointer of the previous list node, we need to do this while holding LOCK_thd_data. */ - next_ptr= it++; + next_ptr= it2++; mysql_mutex_unlock(&ptr->LOCK_thd_data); (*rows)++; } while ((ptr= next_ptr)); @@ -8289,7 +8292,7 @@ bool multi_update_precheck(THD *thd, TABLE_LIST *tables) if (select_lex->item_list.elements != lex->value_list.elements) { - my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); + my_message(ER_WRONG_VALUE_COUNT, ER_THD(thd, ER_WRONG_VALUE_COUNT), MYF(0)); DBUG_RETURN(TRUE); } /* @@ -8400,7 +8403,7 @@ bool multi_delete_precheck(THD *thd, TABLE_LIST *tables) if ((thd->variables.option_bits & OPTION_SAFE_UPDATES) && !select_lex->where) { my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, - ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); + ER_THD(thd, ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); DBUG_RETURN(TRUE); } DBUG_RETURN(FALSE); @@ -8525,7 +8528,7 @@ bool update_precheck(THD *thd, TABLE_LIST *tables) DBUG_ENTER("update_precheck"); if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements) { - my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); + my_message(ER_WRONG_VALUE_COUNT, ER_THD(thd, ER_WRONG_VALUE_COUNT), MYF(0)); DBUG_RETURN(TRUE); } DBUG_RETURN(check_one_table_access(thd, UPDATE_ACL, tables)); @@ -8585,7 +8588,7 @@ bool insert_precheck(THD *thd, TABLE_LIST *tables) if (lex->update_list.elements != lex->value_list.elements) { - my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); + my_message(ER_WRONG_VALUE_COUNT, ER_THD(thd, ER_WRONG_VALUE_COUNT), MYF(0)); DBUG_RETURN(TRUE); } DBUG_RETURN(FALSE); @@ -8894,7 +8897,8 @@ LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name) Check that byte length of a string does not exceed some limit. @param str string to be checked - @param err_msg error message to be displayed if the string is too long + @param err_msg Number of error message to be displayed if the string + is too long. 0 if empty error message. @param max_length max length @retval @@ -8906,13 +8910,14 @@ LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name) The function is not used in existing code but can be useful later? */ -bool check_string_byte_length(LEX_STRING *str, const char *err_msg, +bool check_string_byte_length(LEX_STRING *str, uint err_msg, uint max_byte_length) { if (str->length <= max_byte_length) return FALSE; - my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_byte_length); + my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, + err_msg ? ER(err_msg) : "", max_byte_length); return TRUE; } @@ -8924,7 +8929,8 @@ bool check_string_byte_length(LEX_STRING *str, const char *err_msg, SYNOPSIS check_string_char_length() str string to be checked - err_msg error message to be displayed if the string is too long + err_msg Number of error message to be displayed if the string + is too long. 0 if empty error message. max_char_length max length in symbols cs string charset @@ -8934,7 +8940,7 @@ bool check_string_byte_length(LEX_STRING *str, const char *err_msg, */ -bool check_string_char_length(LEX_STRING *str, const char *err_msg, +bool check_string_char_length(LEX_STRING *str, uint err_msg, uint max_char_length, CHARSET_INFO *cs, bool no_error) { @@ -8942,13 +8948,15 @@ bool check_string_char_length(LEX_STRING *str, const char *err_msg, uint res= cs->cset->well_formed_len(cs, str->str, str->str + str->length, max_char_length, &well_formed_error); - if (!well_formed_error && str->length == res) + if (!well_formed_error && str->length == res) return FALSE; if (!no_error) { ErrConvString err(str->str, str->length, cs); - my_error(ER_WRONG_STRING_LENGTH, MYF(0), err.ptr(), err_msg, max_char_length); + my_error(ER_WRONG_STRING_LENGTH, MYF(0), err.ptr(), + err_msg ? ER(err_msg) : "", + max_char_length); } return TRUE; } @@ -9056,7 +9064,7 @@ bool check_host_name(LEX_STRING *str) { const char *name= str->str; const char *end= str->str + str->length; - if (check_string_byte_length(str, ER(ER_HOSTNAME), HOSTNAME_LENGTH)) + if (check_string_byte_length(str, ER_HOSTNAME, HOSTNAME_LENGTH)) return TRUE; while (name != end) diff --git a/sql/sql_parse.h b/sql/sql_parse.h index 76e1b7a797a..d85bb87a4fb 100644 --- a/sql/sql_parse.h +++ b/sql/sql_parse.h @@ -70,9 +70,9 @@ LEX_USER *create_default_definer(THD *thd, bool role); LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name); LEX_USER *get_current_user(THD *thd, LEX_USER *user, bool lock=true); bool sp_process_definer(THD *thd); -bool check_string_byte_length(LEX_STRING *str, const char *err_msg, +bool check_string_byte_length(LEX_STRING *str, uint err_msg, uint max_byte_length); -bool check_string_char_length(LEX_STRING *str, const char *err_msg, +bool check_string_char_length(LEX_STRING *str, uint err_msg, uint max_char_length, CHARSET_INFO *cs, bool no_error); CHARSET_INFO* merge_charset_and_collation(CHARSET_INFO *cs, CHARSET_INFO *cl); diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 703ae52dc12..d0212163ffe 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1030,7 +1030,7 @@ static bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table, else push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR, - ER(ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR)); + ER_THD(thd, ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR)); } if ((!is_sub_part) && (error= check_signed_flag(part_info))) @@ -4485,7 +4485,7 @@ static int fast_end_partition(THD *thd, ulonglong copied, query_cache_invalidate3(thd, table_list, 0); - my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO), + my_snprintf(tmp_name, sizeof(tmp_name), ER_THD(thd, ER_INSERT_INFO), (ulong) (copied + deleted), (ulong) deleted, (ulong) 0); diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 595c371f515..a43b8c7484a 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -738,7 +738,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report) plugin directory are used (to make this even remotely secure). */ if (check_valid_path(dl->str, dl->length) || - check_string_char_length((LEX_STRING *) dl, "", NAME_CHAR_LEN, + check_string_char_length((LEX_STRING *) dl, 0, NAME_CHAR_LEN, system_charset_info, 1) || plugin_dir_len + dl->length + 1 >= FN_REFLEN) { @@ -1818,7 +1818,8 @@ static void plugin_load(MEM_ROOT *tmp_root) mysql_mutex_unlock(&LOCK_plugin); } if (error > 0) - sql_print_error(ER(ER_GET_ERRNO), my_errno, table->file->table_type()); + sql_print_error(ER_THD(new_thd, ER_GET_ERRNO), my_errno, + table->file->table_type()); end_read_record(&read_record_info); table->m_needs_reopen= TRUE; // Force close to free memory close_mysql_tables(new_thd); @@ -2069,7 +2070,8 @@ static bool finalize_install(THD *thd, TABLE *table, const LEX_STRING *name, { if (global_system_variables.log_warnings) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_CANT_INITIALIZE_UDF, ER(ER_CANT_INITIALIZE_UDF), + ER_CANT_INITIALIZE_UDF, + ER_THD(thd, ER_CANT_INITIALIZE_UDF), name->str, "Plugin is disabled"); } @@ -2202,7 +2204,7 @@ static bool do_uninstall(THD *thd, TABLE *table, const LEX_STRING *name) plugin->state= PLUGIN_IS_DELETED; if (plugin->ref_count) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_PLUGIN_BUSY, ER(WARN_PLUGIN_BUSY)); + WARN_PLUGIN_BUSY, ER_THD(thd, WARN_PLUGIN_BUSY)); else reap_needed= true; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index ea16b862b11..9c0cce9e575 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2144,7 +2144,7 @@ static bool check_prepared_statement(Prepared_statement *stmt) case SQLCOM_CREATE_VIEW: if (lex->create_view_mode == VIEW_ALTER) { - my_message(ER_UNSUPPORTED_PS, ER(ER_UNSUPPORTED_PS), MYF(0)); + my_message(ER_UNSUPPORTED_PS, ER_THD(thd, ER_UNSUPPORTED_PS), MYF(0)); goto error; } res= mysql_test_create_view(stmt); @@ -2227,7 +2227,7 @@ static bool check_prepared_statement(Prepared_statement *stmt) if (!(sql_command_flags[sql_command] & CF_STATUS_COMMAND)) { /* All other statements are not supported yet. */ - my_message(ER_UNSUPPORTED_PS, ER(ER_UNSUPPORTED_PS), MYF(0)); + my_message(ER_UNSUPPORTED_PS, ER_THD(thd, ER_UNSUPPORTED_PS), MYF(0)); goto error; } break; @@ -2253,7 +2253,8 @@ static bool init_param_array(Prepared_statement *stmt) if (stmt->param_count > (uint) UINT_MAX16) { /* Error code to be defined in 5.0 */ - my_message(ER_PS_MANY_PARAM, ER(ER_PS_MANY_PARAM), MYF(0)); + my_message(ER_PS_MANY_PARAM, ER_THD(stmt->thd, ER_PS_MANY_PARAM), + MYF(0)); return TRUE; } Item_param **to; @@ -2999,7 +3000,7 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length) /* Error will be sent in execute call */ stmt->state= Query_arena::STMT_ERROR; stmt->last_errno= ER_WRONG_ARGUMENTS; - sprintf(stmt->last_error, ER(ER_WRONG_ARGUMENTS), + sprintf(stmt->last_error, ER_THD(thd, ER_WRONG_ARGUMENTS), "mysqld_stmt_send_long_data"); DBUG_VOID_RETURN; } diff --git a/sql/sql_priv.h b/sql/sql_priv.h index 7ba027d2380..b09a6c84c83 100644 --- a/sql/sql_priv.h +++ b/sql/sql_priv.h @@ -51,9 +51,9 @@ compile_time_assert(MYSQL_VERSION_ID < VerHi * 10000 + VerLo * 100); \ if (((THD *) Thd) != NULL) \ push_warning_printf(((THD *) Thd), Sql_condition::WARN_LEVEL_WARN, \ - ER_WARN_DEPRECATED_SYNTAX, \ - ER(ER_WARN_DEPRECATED_SYNTAX), \ - (Old), (New)); \ + ER_WARN_DEPRECATED_SYNTAX, \ + ER_THD(((THD *) Thd), ER_WARN_DEPRECATED_SYNTAX), \ + (Old), (New)); \ else \ sql_print_warning("The syntax '%s' is deprecated and will be removed " \ "in a future release. Please use %s instead.", \ @@ -79,8 +79,8 @@ do { \ if (((THD *) Thd) != NULL) \ push_warning_printf(((THD *) Thd), Sql_condition::WARN_LEVEL_WARN, \ - ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT, \ - ER(ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT), \ + ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT, \ + ER_THD(((THD *) Thd), ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT), \ (Old)); \ else \ sql_print_warning("'%s' is deprecated and will be removed " \ diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 6496e1895fb..d9cf0344cdf 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -62,7 +62,7 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) if (thd->locked_tables_mode || thd->in_active_multi_stmt_transaction()) { my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, - ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); + ER_THD(thd, ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); DBUG_RETURN(1); } diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 0ea61320a5a..5b748c04096 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -559,7 +559,7 @@ bool purge_error_message(THD* thd, int res) if ((errcode= purge_log_get_error_code(res)) != 0) { - my_message(errcode, ER(errcode), MYF(0)); + my_message(errcode, ER_THD(thd, errcode), MYF(0)); return TRUE; } my_ok(thd); @@ -3099,14 +3099,15 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) if (!opt_skip_slave_start) push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_MISSING_SKIP_SLAVE, - ER(ER_MISSING_SKIP_SLAVE)); + ER_THD(thd, ER_MISSING_SKIP_SLAVE)); } mysql_mutex_unlock(&mi->rli.data_lock); } else if (thd->lex->mi.pos || thd->lex->mi.relay_log_pos) - push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_UNTIL_COND_IGNORED, - ER(ER_UNTIL_COND_IGNORED)); + push_warning(thd, + Sql_condition::WARN_LEVEL_NOTE, ER_UNTIL_COND_IGNORED, + ER_THD(thd, ER_UNTIL_COND_IGNORED)); if (!slave_errno) slave_errno = start_slave_threads(0 /*no mutex */, @@ -3123,7 +3124,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) { /* no error if all threads are already started, only a warning */ push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_SLAVE_WAS_RUNNING, - ER(ER_SLAVE_WAS_RUNNING)); + ER_THD(thd, ER_SLAVE_WAS_RUNNING)); } err: @@ -3190,14 +3191,14 @@ int stop_slave(THD* thd, Master_info* mi, bool net_report ) //no error if both threads are already stopped, only a warning slave_errno= 0; push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_SLAVE_WAS_NOT_RUNNING, - ER(ER_SLAVE_WAS_NOT_RUNNING)); + ER_THD(thd, ER_SLAVE_WAS_NOT_RUNNING)); } unlock_slave_threads(mi); if (slave_errno) { if (net_report) - my_message(slave_errno, ER(slave_errno), MYF(0)); + my_message(slave_errno, ER_THD(thd, slave_errno), MYF(0)); DBUG_RETURN(1); } @@ -3590,7 +3591,8 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) lex_mi->ssl_cert || lex_mi->ssl_cipher || lex_mi->ssl_key || lex_mi->ssl_verify_server_cert || lex_mi->ssl_crl || lex_mi->ssl_crlpath) push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_SLAVE_IGNORED_SSL_PARAMS, ER(ER_SLAVE_IGNORED_SSL_PARAMS)); + ER_SLAVE_IGNORED_SSL_PARAMS, + ER_THD(thd, ER_SLAVE_IGNORED_SSL_PARAMS)); #endif if (lex_mi->relay_log_name) @@ -3775,7 +3777,8 @@ int reset_master(THD* thd, rpl_gtid *init_state, uint32 init_state_len) if (!mysql_bin_log.is_open()) { my_message(ER_FLUSH_MASTER_BINLOG_CLOSED, - ER(ER_FLUSH_MASTER_BINLOG_CLOSED), MYF(ME_BELL+ME_WAITTANG)); + ER_THD(thd, ER_FLUSH_MASTER_BINLOG_CLOSED), + MYF(ME_BELL+ME_WAITTANG)); return 1; } @@ -4313,7 +4316,7 @@ rpl_gtid_pos_check(THD *thd, char *str, size_t len) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_MASTER_GTID_POS_MISSING_DOMAIN, - ER(ER_MASTER_GTID_POS_MISSING_DOMAIN), + ER_THD(thd, ER_MASTER_GTID_POS_MISSING_DOMAIN), binlog_gtid->domain_id, binlog_gtid->domain_id, binlog_gtid->server_id, binlog_gtid->seq_no); gave_missing_warning= true; @@ -4333,7 +4336,7 @@ rpl_gtid_pos_check(THD *thd, char *str, size_t len) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_MASTER_GTID_POS_CONFLICTS_WITH_BINLOG, - ER(ER_MASTER_GTID_POS_CONFLICTS_WITH_BINLOG), + ER_THD(thd, ER_MASTER_GTID_POS_CONFLICTS_WITH_BINLOG), slave_gtid->domain_id, slave_gtid->server_id, slave_gtid->seq_no, binlog_gtid->domain_id, binlog_gtid->server_id, binlog_gtid->seq_no); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index da994538b6b..abd9d3123f5 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -383,7 +383,7 @@ bool handle_select(THD *thd, LEX *lex, select_result *result, */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT, - ER(ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT), + ER_THD(thd, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT), thd->accessed_rows_and_keys, thd->lex->limit_rows_examined->val_uint()); thd->reset_killed(); @@ -914,7 +914,7 @@ JOIN::prepare(Item ***rref_pointer_array, select_lex->agg_func_used()) { my_message(ER_MIX_OF_GROUP_FUNC_AND_FIELDS, - ER(ER_MIX_OF_GROUP_FUNC_AND_FIELDS), MYF(0)); + ER_THD(thd, ER_MIX_OF_GROUP_FUNC_AND_FIELDS), MYF(0)); DBUG_RETURN(-1); } { @@ -936,14 +936,14 @@ JOIN::prepare(Item ***rref_pointer_array, { if (!test_if_subpart(procedure->group,group_list)) { /* purecov: inspected */ - my_message(ER_DIFF_GROUPS_PROC, ER(ER_DIFF_GROUPS_PROC), + my_message(ER_DIFF_GROUPS_PROC, ER_THD(thd, ER_DIFF_GROUPS_PROC), MYF(0)); /* purecov: inspected */ goto err; /* purecov: inspected */ } } if (order && (procedure->flags & PROC_NO_SORT)) { /* purecov: inspected */ - my_message(ER_ORDER_WITH_PROC, ER(ER_ORDER_WITH_PROC), + my_message(ER_ORDER_WITH_PROC, ER_THD(thd, ER_ORDER_WITH_PROC), MYF(0)); /* purecov: inspected */ goto err; /* purecov: inspected */ } @@ -1001,7 +1001,7 @@ bool JOIN::prepare_stage2() #ifdef RESTRICTED_GROUP if (implicit_grouping) { - my_message(ER_WRONG_SUM_SELECT,ER(ER_WRONG_SUM_SELECT),MYF(0)); + my_message(ER_WRONG_SUM_SELECT,ER_THD(thd, ER_WRONG_SUM_SELECT),MYF(0)); goto err; } #endif @@ -1064,6 +1064,7 @@ JOIN::optimize_inner() { ulonglong select_opts_for_readinfo; uint no_jbuf_after; + JOIN_TAB *tab; DBUG_ENTER("JOIN::optimize"); do_send_rows = (unit->select_limit_cnt) ? 1 : 0; @@ -1397,7 +1398,7 @@ TODO: make view to decide if it is possible to write to WHERE directly or make S best_read > (double) thd->variables.max_join_size && !(select_options & SELECT_DESCRIBE)) { /* purecov: inspected */ - my_message(ER_TOO_BIG_SELECT, ER(ER_TOO_BIG_SELECT), MYF(0)); + my_message(ER_TOO_BIG_SELECT, ER_THD(thd, ER_TOO_BIG_SELECT), MYF(0)); error= -1; DBUG_RETURN(1); } @@ -1460,7 +1461,6 @@ TODO: make view to decide if it is possible to write to WHERE directly or make S Perform the optimization on fields evaluation mentioned above for all on expressions. */ - JOIN_TAB *tab; for (tab= first_linear_tab(this, WITH_BUSH_ROOTS, WITHOUT_CONST_TABLES); tab; tab= next_linear_tab(this, tab, WITH_BUSH_ROOTS)) { @@ -1665,8 +1665,9 @@ TODO: make view to decide if it is possible to write to WHERE directly or make S because in this case we can just create a temporary table that holds LIMIT rows and stop when this table is full. */ - JOIN_TAB *tab= &join_tab[const_tables]; bool all_order_fields_used; + + tab= &join_tab[const_tables]; if (order) { skip_sort_order= test_if_skip_sort_order(tab, order, select_limit, 1, @@ -2158,11 +2159,11 @@ bool JOIN::setup_subquery_caches() thd->change_item_tree(li.ref(), new_item); } } - for (ORDER *group= group_list; group ; group= group->next) + for (ORDER *tmp_group= group_list; tmp_group ; tmp_group= tmp_group->next) { - *group->item= - (*group->item)->transform(&Item::expr_cache_insert_transformer, - (uchar*) thd); + *tmp_group->item= + (*tmp_group->item)->transform(&Item::expr_cache_insert_transformer, + (uchar*) thd); } } if (select_lex->expr_cache_may_be_used[NO_MATTER]) @@ -2575,11 +2576,11 @@ void JOIN::exec_inner() if (order && join_tab) { bool made_call= false; - SQL_SELECT *select= join_tab[const_tables].select; + SQL_SELECT *tmp_select= join_tab[const_tables].select; if ((order != group_list || !(select_options & SELECT_BIG_RESULT) || - (select && select->quick && - select->quick->get_type() == + (tmp_select && tmp_select->quick && + tmp_select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX)) && (const_tables == table_count || ((simple_order || skip_sort_order) && @@ -2624,7 +2625,7 @@ void JOIN::exec_inner() must be accumulated in examined_row_count. Hence every join iteration must count from zero. */ - curr_join->examined_rows= 0; + curr_join->join_examined_rows= 0; /* Create a tmp table if distinct or if the sort is too complicated */ if (need_tmp) @@ -3121,7 +3122,7 @@ void JOIN::exec_inner() } /* Accumulate the counts from all join iterations of all join parts. */ - thd->inc_examined_row_count(curr_join->examined_rows); + thd->inc_examined_row_count(curr_join->join_examined_rows); DBUG_PRINT("counts", ("thd->examined_row_count: %lu", (ulong) thd->get_examined_row_count())); @@ -3617,7 +3618,8 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, if (s->dependent & s->table->map) { join->table_count=0; // Don't use join->table - my_message(ER_WRONG_OUTER_JOIN, ER(ER_WRONG_OUTER_JOIN), MYF(0)); + my_message(ER_WRONG_OUTER_JOIN, + ER_THD(join->thd, ER_WRONG_OUTER_JOIN), MYF(0)); goto error; } s->key_dependent= s->dependent; @@ -4089,7 +4091,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, { memcpy((uchar*) join->best_positions,(uchar*) join->positions, sizeof(POSITION)*join->const_tables); - join->record_count= 1.0; + join->join_record_count= 1.0; join->best_read=1.0; } @@ -4124,10 +4126,10 @@ error: Dangling TABLE::reginfo.join_tab may cause part_of_refkey to choke. */ { - TABLE_LIST *table; - List_iterator<TABLE_LIST> ti(tables_list); - while ((table= ti++)) - table->table->reginfo.join_tab= NULL; + TABLE_LIST *tmp_table; + List_iterator<TABLE_LIST> ti2(tables_list); + while ((tmp_table= ti2++)) + tmp_table->table->reginfo.join_tab= NULL; } DBUG_RETURN (1); } @@ -4838,9 +4840,9 @@ Item_equal::add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, table_map usable_tables, SARGABLE_PARAM **sargables) { - Item *const_item= get_const(); + Item *const_item2= get_const(); Item_equal_fields_iterator it(*this); - if (const_item) + if (const_item2) { /* @@ -4852,7 +4854,7 @@ Item_equal::add_key_fields(JOIN *join, KEY_FIELD **key_fields, { Field *equal_field= it.get_curr_field(); add_key_field(join, key_fields, *and_level, this, equal_field, - TRUE, &const_item, 1, usable_tables, sargables); + TRUE, &const_item2, 1, usable_tables, sargables); } } else @@ -5950,7 +5952,6 @@ best_access_path(JOIN *join, } else { - uint key_parts= table->actual_n_key_parts(keyinfo); if (!(records= keyinfo->actual_rec_per_key(key_parts-1))) { /* Prefer longer keys */ records= @@ -6875,7 +6876,7 @@ optimize_straight_join(JOIN *join, table_map join_tables) read_time+= record_count; // We have to make a temp table memcpy((uchar*) join->best_positions, (uchar*) join->positions, sizeof(POSITION)*idx); - join->record_count= record_count; + join->join_record_count= record_count; join->best_read= read_time - 0.001; } @@ -7279,7 +7280,6 @@ double table_multi_eq_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, if (item_equal->get_const()) continue; - Field *fld; bool adjust_sel= FALSE; Item_equal_fields_iterator fi(*item_equal); while((fi++) && !adjust_sel) @@ -7345,7 +7345,7 @@ double table_multi_eq_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, while ((fi++)) { double curr_eq_fld_sel; - fld= fi.get_curr_field(); + Field *fld= fi.get_curr_field(); if (!fld->table->map & ~(table_bit | rem_tables)) continue; curr_eq_fld_sel= get_column_avg_frequency(fld) / @@ -7857,7 +7857,7 @@ best_extension_by_limited_search(JOIN *join, { memcpy((uchar*) join->best_positions, (uchar*) join->positions, sizeof(POSITION) * (idx + 1)); - join->record_count= partial_join_cardinality; + join->join_record_count= partial_join_cardinality; join->best_read= current_read_time - 0.001; } DBUG_EXECUTE("opt", print_plan(join, idx+1, @@ -9393,7 +9393,8 @@ make_outerjoin_info(JOIN *join) } } - for (JOIN_TAB *tab= first_linear_tab(join, WITH_BUSH_ROOTS, WITHOUT_CONST_TABLES); tab; + for (tab= first_linear_tab(join, WITH_BUSH_ROOTS, WITHOUT_CONST_TABLES); + tab; tab= next_linear_tab(join, tab, WITH_BUSH_ROOTS)) { TABLE *table= tab->table; @@ -9684,10 +9685,11 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) Because of QUICK_GROUP_MIN_MAX_SELECT there may be a select without a cond, so neutralize the hack above. */ - if (!(tmp= add_found_match_trig_cond(first_inner_tab, tmp, 0))) + COND *tmp_cond; + if (!(tmp_cond= add_found_match_trig_cond(first_inner_tab, tmp, 0))) DBUG_RETURN(1); - sel->cond= tmp; - tab->set_select_cond(tmp, __LINE__); + sel->cond= tmp_cond; + tab->set_select_cond(tmp_cond, __LINE__); /* Push condition to storage engine if this is enabled and the condition is not guarded */ if (tab->table) @@ -9698,7 +9700,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) !first_inner_tab) { COND *push_cond= - make_cond_for_table(thd, tmp, current_map, current_map, + make_cond_for_table(thd, tmp_cond, current_map, current_map, -1, FALSE, FALSE); if (push_cond) { @@ -9883,17 +9885,18 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) if (*join_tab->on_expr_ref) { JOIN_TAB *cond_tab= join_tab->first_inner; - COND *tmp= make_cond_for_table(thd, *join_tab->on_expr_ref, - join->const_table_map, - (table_map) 0, -1, FALSE, FALSE); - if (!tmp) + COND *tmp_cond= make_cond_for_table(thd, *join_tab->on_expr_ref, + join->const_table_map, + (table_map) 0, -1, FALSE, FALSE); + if (!tmp_cond) continue; - tmp= new Item_func_trig_cond(tmp, &cond_tab->not_null_compl); - if (!tmp) + tmp_cond= new Item_func_trig_cond(tmp_cond, &cond_tab->not_null_compl); + if (!tmp_cond) DBUG_RETURN(1); - tmp->quick_fix_field(); - cond_tab->select_cond= !cond_tab->select_cond ? tmp : - new Item_cond_and(cond_tab->select_cond,tmp); + tmp_cond->quick_fix_field(); + cond_tab->select_cond= !cond_tab->select_cond ? tmp_cond : + new Item_cond_and(cond_tab->select_cond, + tmp_cond); if (!cond_tab->select_cond) DBUG_RETURN(1); cond_tab->select_cond->quick_fix_field(); @@ -9925,23 +9928,26 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) start_from= tab->bush_root_tab? tab->bush_root_tab->bush_children->start : join->join_tab + join->const_tables; - for (JOIN_TAB *tab= start_from; tab <= last_tab; tab++) + for (JOIN_TAB *inner_tab= start_from; + inner_tab <= last_tab; + inner_tab++) { - DBUG_ASSERT(tab->table); - current_map= tab->table->map; + DBUG_ASSERT(inner_tab->table); + current_map= inner_tab->table->map; used_tables2|= current_map; /* psergey: have put the -1 below. It's bad, will need to fix it. */ COND *tmp_cond= make_cond_for_table(thd, on_expr, used_tables2, - current_map, /*(tab - first_tab)*/ -1, + current_map, + /*(inner_tab - first_tab)*/ -1, FALSE, FALSE); bool is_sjm_lookup_tab= FALSE; - if (tab->bush_children) + if (inner_tab->bush_children) { /* - 'tab' is an SJ-Materialization tab, i.e. we have a join order - like this: + 'inner_tab' is an SJ-Materialization tab, i.e. we have a join + order like this: ot1 sjm_tab LEFT JOIN ot2 ot3 ^ ^ @@ -9961,19 +9967,21 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) would be true anyway. */ SJ_MATERIALIZATION_INFO *sjm= - tab->bush_children->start->emb_sj_nest->sj_mat_info; + inner_tab->bush_children->start->emb_sj_nest->sj_mat_info; if (sjm->is_used && !sjm->is_sj_scan) is_sjm_lookup_tab= TRUE; } - if (tab == first_inner_tab && tab->on_precond && !is_sjm_lookup_tab) - add_cond_and_fix(thd, &tmp_cond, tab->on_precond); + if (inner_tab == first_inner_tab && inner_tab->on_precond && + !is_sjm_lookup_tab) + add_cond_and_fix(thd, &tmp_cond, inner_tab->on_precond); if (tmp_cond && !is_sjm_lookup_tab) { - JOIN_TAB *cond_tab= tab < first_inner_tab ? first_inner_tab : tab; - Item **sel_cond_ref= tab < first_inner_tab ? - &first_inner_tab->on_precond : - &tab->select_cond; + JOIN_TAB *cond_tab= (inner_tab < first_inner_tab ? + first_inner_tab : inner_tab); + Item **sel_cond_ref= (inner_tab < first_inner_tab ? + &first_inner_tab->on_precond : + &inner_tab->select_cond); /* First add the guards for match variables of all embedding outer join operations. @@ -10201,21 +10209,21 @@ void JOIN::drop_unused_derived_keys() tab= next_linear_tab(this, tab, WITH_BUSH_ROOTS)) { - TABLE *table=tab->table; - if (!table) + TABLE *tmp_tbl= tab->table; + if (!tmp_tbl) continue; - if (!table->pos_in_table_list->is_materialized_derived()) + if (!tmp_tbl->pos_in_table_list->is_materialized_derived()) continue; - if (table->max_keys > 1) - table->use_index(tab->ref.key); - if (table->s->keys) + if (tmp_tbl->max_keys > 1) + tmp_tbl->use_index(tab->ref.key); + if (tmp_tbl->s->keys) { if (tab->ref.key >= 0) tab->ref.key= 0; else - table->s->keys= 0; + tmp_tbl->s->keys= 0; } - tab->keys= (key_map) (table->s->keys ? 1 : 0); + tab->keys= (key_map) (tmp_tbl->s->keys ? 1 : 0); } } @@ -10994,17 +11002,17 @@ void JOIN_TAB::remove_redundant_bnl_scan_conds() Item *scan_item; while ((pushed_item= pushed_cond_li++)) { - bool found= false; + bool found_cond= false; scan_cond_li.rewind(); while ((scan_item= scan_cond_li++)) { if (pushed_item->eq(scan_item, 0)) { - found= true; + found_cond= true; break; } } - if (!found) + if (!found_cond) reduced_select_cond->add(pushed_item); } } @@ -11381,7 +11389,8 @@ bool error_if_full_join(JOIN *join) if (tab->type == JT_ALL && (!tab->select || !tab->select->quick)) { my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, - ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); + ER_THD(join->thd, + ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); return(1); } } @@ -12849,9 +12858,9 @@ COND *Item_cond_and::build_equal_items(THD *thd, cond_equal.upper_levels= inherited; List<Item> eq_list; - List<Item> *args= argument_list(); + List<Item> *cond_args= argument_list(); - List_iterator<Item> li(*args); + List_iterator<Item> li(*cond_args); Item *item; DBUG_ASSERT(!cond_equal_ref || !cond_equal_ref[0]); @@ -12876,7 +12885,7 @@ COND *Item_cond_and::build_equal_items(THD *thd, Check if we eliminated all the predicates of the level, e.g. (a=a AND b=b AND a=a). */ - if (!args->elements && + if (!cond_args->elements && !cond_equal.current_level.elements && !eq_list.elements) return new (thd->mem_root) Item_int((longlong) 1, 1); @@ -12909,14 +12918,14 @@ COND *Item_cond_and::build_equal_items(THD *thd, /* This replacement happens only for standalone equalities */ /* This is ok with PS/SP as the replacement is done for - arguments of an AND/OR item, which are restored for each + cond_args of an AND/OR item, which are restored for each execution of PS/SP. */ li.replace(new_item); } } - args->append(&eq_list); - args->append((List<Item> *)&cond_equal.current_level); + cond_args->append(&eq_list); + cond_args->append((List<Item> *)&cond_equal.current_level); update_used_tables(); if (cond_equal_ref) *cond_equal_ref= &m_cond_equal; @@ -12929,9 +12938,9 @@ COND *Item_cond::build_equal_items(THD *thd, bool link_item_fields, COND_EQUAL **cond_equal_ref) { - List<Item> *args= argument_list(); + List<Item> *cond_args= argument_list(); - List_iterator<Item> li(*args); + List_iterator<Item> li(*cond_args); Item *item; DBUG_ASSERT(!cond_equal_ref || !cond_equal_ref[0]); @@ -13014,7 +13023,7 @@ COND *Item_func_eq::build_equal_items(THD *thd, */ Item_cond_and *and_cond= new Item_cond_and(eq_list); and_cond->quick_fix_field(); - List<Item> *args= and_cond->argument_list(); + List<Item> *cond_args= and_cond->argument_list(); List_iterator_fast<Item_equal> it(cond_equal.current_level); while ((item_equal= it++)) { @@ -13025,7 +13034,7 @@ COND *Item_func_eq::build_equal_items(THD *thd, } and_cond->m_cond_equal.copy(cond_equal); cond_equal.current_level= and_cond->m_cond_equal.current_level; - args->append((List<Item> *)&cond_equal.current_level); + cond_args->append((List<Item> *)&cond_equal.current_level); and_cond->update_used_tables(); if (cond_equal_ref) *cond_equal_ref= &and_cond->m_cond_equal; @@ -13789,14 +13798,14 @@ static void update_const_equal_items(THD *thd, COND *cond, JOIN_TAB *tab, */ if (!possible_keys.is_clear_all()) { - TABLE *tab= field->table; + TABLE *field_tab= field->table; KEYUSE *use; - for (use= stat->keyuse; use && use->table == tab; use++) + for (use= stat->keyuse; use && use->table == field_tab; use++) if (const_key && !use->is_for_hash_join() && possible_keys.is_set(use->key) && - tab->key_info[use->key].key_part[use->keypart].field == + field_tab->key_info[use->key].key_part[use->keypart].field == field) - tab->const_key_parts[use->key]|= use->keypart_map; + field_tab->const_key_parts[use->key]|= use->keypart_map; } } } @@ -15023,7 +15032,7 @@ bool cond_is_datetime_is_null(Item *cond) COND * Item_cond::remove_eq_conds(THD *thd, Item::cond_result *cond_value, - bool top_level) + bool top_level_arg) { bool and_level= functype() == Item_func::COND_AND_FUNC; List<Item> *cond_arg_list= argument_list(); @@ -15237,7 +15246,7 @@ Item_cond::remove_eq_conds(THD *thd, Item::cond_result *cond_value, COND * -Item::remove_eq_conds(THD *thd, Item::cond_result *cond_value, bool top_level) +Item::remove_eq_conds(THD *thd, Item::cond_result *cond_value, bool top_level_arg) { if (const_item() && !is_expensive()) { @@ -15251,7 +15260,7 @@ Item::remove_eq_conds(THD *thd, Item::cond_result *cond_value, bool top_level) COND * Item_bool_func2::remove_eq_conds(THD *thd, Item::cond_result *cond_value, - bool top_level) + bool top_level_arg) { if (const_item() && !is_expensive()) { @@ -15293,7 +15302,7 @@ Item_bool_func2::remove_eq_conds(THD *thd, Item::cond_result *cond_value, COND * Item_func_isnull::remove_eq_conds(THD *thd, Item::cond_result *cond_value, - bool top_level) + bool top_level_arg) { if (args[0]->type() == Item::FIELD_ITEM) { @@ -15367,7 +15376,7 @@ Item_func_isnull::remove_eq_conds(THD *thd, Item::cond_result *cond_value, WHERE auto_increment IS NULL AND something_else */ - if (top_level) // "auto_increment_column IS NULL" is the only condition + if (top_level_arg) // "auto_increment_column IS NULL" is the only condition { if (field->flags & AUTO_INCREMENT_FLAG && !field->table->maybe_null && (thd->variables.option_bits & OPTION_AUTO_IS_NULL) && @@ -15402,7 +15411,7 @@ Item_func_isnull::remove_eq_conds(THD *thd, Item::cond_result *cond_value, } } } - return Item::remove_eq_conds(thd, cond_value, top_level); + return Item::remove_eq_conds(thd, cond_value, top_level_arg); } @@ -15583,8 +15592,8 @@ Field *create_tmp_field_from_field(THD *thd, Field *org_field, org_field->field_name, table->s, org_field->charset()); else - new_field= org_field->new_field(thd->mem_root, table, - table == org_field->table); + new_field= org_field->make_new_field(thd->mem_root, table, + table == org_field->table); if (new_field) { new_field->init(table); @@ -17678,8 +17687,8 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure) here. join->send_records is increased on success in end_send(), so we don't touch it here. */ - join->examined_rows++; - DBUG_ASSERT(join->examined_rows <= 1); + join->join_examined_rows++; + DBUG_ASSERT(join->join_examined_rows <= 1); } else if (join->send_row_on_empty_set()) { @@ -18272,9 +18281,9 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab, of the newly activated predicates is evaluated as false (See above join->return_tab= tab). */ - join->examined_rows++; + join->join_examined_rows++; DBUG_PRINT("counts", ("join->examined_rows++: %lu found: %d", - (ulong) join->examined_rows, (int) found)); + (ulong) join->join_examined_rows, (int) found)); if (found) { @@ -18309,7 +18318,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab, The condition pushed down to the table join_tab rejects all rows with the beginning coinciding with the current partial join. */ - join->examined_rows++; + join->join_examined_rows++; join->thd->get_stmt_da()->inc_current_row_for_warning(); join_tab->read_record.unlock_row(join_tab); } @@ -20697,11 +20706,11 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, if (select && // psergey: why doesn't this use a quick? table->quick_keys.is_set(best_key) && best_key != ref_key) { - key_map map; - map.clear_all(); // Force the creation of quick select - map.set_bit(best_key); // only best_key. + key_map tmp_map; + tmp_map.clear_all(); // Force the creation of quick select + tmp_map.set_bit(best_key); // only best_key. select->quick= 0; - select->test_quick_select(join->thd, map, 0, + select->test_quick_select(join->thd, tmp_map, 0, join->select_options & OPTION_FOUND_ROWS ? HA_POS_ERROR : join->unit->select_limit_cnt, @@ -21125,7 +21134,7 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order, if (err) goto err; - tab->join->examined_rows+=examined_rows; + tab->join->join_examined_rows+= examined_rows; DBUG_RETURN(filesort_retval == HA_POS_ERROR); err: DBUG_RETURN(-1); @@ -21307,7 +21316,8 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, } if (copy_blobs(first_field)) { - my_message(ER_OUTOFMEMORY, ER(ER_OUTOFMEMORY), MYF(ME_FATALERROR)); + my_message(ER_OUTOFMEMORY, ER_THD(thd,ER_OUTOFMEMORY), + MYF(ME_FATALERROR)); error=0; goto err; } @@ -21725,9 +21735,9 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR, - ER(ER_NON_UNIQ_ERROR), + ER_THD(thd, ER_NON_UNIQ_ERROR), ((Item_ident*) order_item)->field_name, - current_thd->where); + thd->where); } } @@ -22451,7 +22461,8 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param, saved value */ field= item->field; - item->result_field=field->new_field(thd->mem_root,field->table, 1); + item->result_field=field->make_new_field(thd->mem_root, + field->table, 1); /* We need to allocate one extra byte for null handling and another extra byte to not get warnings from purify in @@ -23609,35 +23620,31 @@ void JOIN_TAB::update_explain_data(uint idx) } -void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tables, +void JOIN_TAB::save_explain_data(Explain_table_access *eta, + table_map prefix_tables, bool distinct, JOIN_TAB *first_top_tab) { int quick_type; CHARSET_INFO *cs= system_charset_info; - - JOIN_TAB *tab= this; - THD *thd=join->thd; - - TABLE *table=tab->table; - TABLE_LIST *table_list= tab->table->pos_in_table_list; + THD *thd= join->thd; + TABLE_LIST *table_list= table->pos_in_table_list; + QUICK_SELECT_I *cur_quick= NULL; my_bool key_read; char table_name_buffer[SAFE_NAME_LEN]; KEY *key_info= 0; uint key_len= 0; quick_type= -1; - QUICK_SELECT_I *quick= NULL; - explain_plan= eta; eta->key.clear(); eta->quick_info= NULL; - tab->tracker= &eta->tracker; - tab->jbuf_tracker= &eta->jbuf_tracker; + tracker= &eta->tracker; + jbuf_tracker= &eta->jbuf_tracker; /* Enable the table access time tracker only for "ANALYZE stmt" */ if (thd->lex->analyze_stmt) - tab->table->file->set_time_tracker(&eta->op_tracker); + table->file->set_time_tracker(&eta->op_tracker); /* No need to save id and select_type here, they are kept in Explain_select */ @@ -23650,9 +23657,9 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab table->derived_select_number); eta->table_name.copy(table_name_buffer, len, cs); } - else if (tab->bush_children) + else if (bush_children) { - JOIN_TAB *ctab= tab->bush_children->start; + JOIN_TAB *ctab= bush_children->start; /* table */ int len= my_snprintf(table_name_buffer, sizeof(table_name_buffer)-1, @@ -23706,19 +23713,19 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab } /* "type" column */ - enum join_type tab_type= tab->type; - if ((tab->type == JT_ALL || tab->type == JT_HASH) && - tab->select && tab->select->quick && tab->use_quick != 2) + enum join_type tab_type= type; + if ((type == JT_ALL || type == JT_HASH) && + select && select->quick && use_quick != 2) { - quick= tab->select->quick; - quick_type= tab->select->quick->get_type(); + cur_quick= select->quick; + quick_type= cur_quick->get_type(); if ((quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE) || (quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_INTERSECT) || (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT) || (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION)) - tab_type= tab->type == JT_ALL ? JT_INDEX_MERGE : JT_HASH_INDEX_MERGE; + tab_type= type == JT_ALL ? JT_INDEX_MERGE : JT_HASH_INDEX_MERGE; else - tab_type= tab->type == JT_ALL ? JT_RANGE : JT_HASH_RANGE; + tab_type= type == JT_ALL ? JT_RANGE : JT_HASH_RANGE; } eta->type= tab_type; @@ -23726,45 +23733,45 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab // psergey-todo: why does this use thd MEM_ROOT??? Doesn't this // break ANALYZE ? thd->mem_root will be freed, and after that we will // attempt to print the query plan? - append_possible_keys(thd->mem_root, eta->possible_keys, table, tab->keys); + append_possible_keys(thd->mem_root, eta->possible_keys, table, keys); // psergey-todo: ^ check for error return code /* Build "key", "key_len", and "ref" */ if (tab_type == JT_NEXT) { - key_info= table->key_info+tab->index; + key_info= table->key_info+index; key_len= key_info->key_length; } - else if (tab->ref.key_parts) + else if (ref.key_parts) { - key_info= tab->get_keyinfo_by_key_no(tab->ref.key); - key_len= tab->ref.key_length; + key_info= get_keyinfo_by_key_no(ref.key); + key_len= ref.key_length; } /* In STRAIGHT_JOIN queries, there can be join tabs with JT_CONST type that still have quick selects. */ - if (tab->select && tab->select->quick && tab_type != JT_CONST) + if (select && select->quick && tab_type != JT_CONST) { - eta->quick_info= tab->select->quick->get_explain(thd->mem_root); + eta->quick_info= select->quick->get_explain(thd->mem_root); } if (key_info) /* 'index' or 'ref' access */ { eta->key.set(thd->mem_root, key_info, key_len); - if (tab->ref.key_parts && tab_type != JT_FT) + if (ref.key_parts && tab_type != JT_FT) { - store_key **ref=tab->ref.key_copy; - for (uint kp= 0; kp < tab->ref.key_parts; kp++) + store_key **key_ref= ref.key_copy; + for (uint kp= 0; kp < ref.key_parts; kp++) { - if ((key_part_map(1) << kp) & tab->ref.const_ref_part_map) + if ((key_part_map(1) << kp) & ref.const_ref_part_map) eta->ref_list.append_str(thd->mem_root, "const"); else { - eta->ref_list.append_str(thd->mem_root, (*ref)->name()); - ref++; + eta->ref_list.append_str(thd->mem_root, (*key_ref)->name()); + key_ref++; } } } @@ -23773,8 +23780,8 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab if (tab_type == JT_HASH_NEXT) /* full index scan + hash join */ { eta->hash_next_key.set(thd->mem_root, - & table->key_info[tab->index], - table->key_info[tab->index].key_length); + & table->key_info[index], + table->key_info[index].key_length); // psergey-todo: ^ is the above correct? are we necessarily joining on all // columns? } @@ -23824,7 +23831,7 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab } else { - double examined_rows= tab->get_examined_rows(); + double examined_rows= get_examined_rows(); eta->rows_set= true; eta->rows= (ha_rows) examined_rows; @@ -23833,9 +23840,9 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab float f= 0.0; if (examined_rows) { - double pushdown_cond_selectivity= tab->cond_selectivity; + double pushdown_cond_selectivity= cond_selectivity; if (pushdown_cond_selectivity == 1.0) - f= (float) (100.0 * tab->records_read / examined_rows); + f= (float) (100.0 * records_read / examined_rows); else f= (float) (100.0 * pushdown_cond_selectivity); } @@ -23847,32 +23854,32 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab /* Build "Extra" field and save it */ key_read=table->key_read; if ((tab_type == JT_NEXT || tab_type == JT_CONST) && - table->covering_keys.is_set(tab->index)) + table->covering_keys.is_set(index)) key_read=1; if (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT && - !((QUICK_ROR_INTERSECT_SELECT*)quick)->need_to_fetch_row) + !((QUICK_ROR_INTERSECT_SELECT*)cur_quick)->need_to_fetch_row) key_read=1; - if (tab->info) + if (info) { - eta->push_extra(tab->info); + eta->push_extra(info); } - else if (tab->packed_info & TAB_INFO_HAVE_VALUE) + else if (packed_info & TAB_INFO_HAVE_VALUE) { - if (tab->packed_info & TAB_INFO_USING_INDEX) + if (packed_info & TAB_INFO_USING_INDEX) eta->push_extra(ET_USING_INDEX); - if (tab->packed_info & TAB_INFO_USING_WHERE) + if (packed_info & TAB_INFO_USING_WHERE) eta->push_extra(ET_USING_WHERE); - if (tab->packed_info & TAB_INFO_FULL_SCAN_ON_NULL) + if (packed_info & TAB_INFO_FULL_SCAN_ON_NULL) eta->push_extra(ET_FULL_SCAN_ON_NULL_KEY); } else { uint keyno= MAX_KEY; - if (tab->ref.key_parts) - keyno= tab->ref.key; - else if (tab->select && quick) - keyno = quick->index; + if (ref.key_parts) + keyno= ref.key; + else if (select && cur_quick) + keyno = cur_quick->index; if (keyno != MAX_KEY && keyno == table->file->pushed_idx_cond_keyno && table->file->pushed_idx_cond) @@ -23880,7 +23887,7 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab eta->push_extra(ET_USING_INDEX_CONDITION); eta->pushed_index_cond= table->file->pushed_idx_cond; } - else if (tab->cache_idx_cond) + else if (cache_idx_cond) eta->push_extra(ET_USING_INDEX_CONDITION_BKA); if (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION || @@ -23890,22 +23897,22 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab { eta->push_extra(ET_USING); } - if (tab->select) + if (select) { - if (tab->use_quick == 2) + if (use_quick == 2) { eta->push_extra(ET_RANGE_CHECKED_FOR_EACH_RECORD); eta->range_checked_fer= new (thd->mem_root) Explain_range_checked_fer; if (eta->range_checked_fer) eta->range_checked_fer-> - append_possible_keys_stat(thd->mem_root, table, tab->keys); + append_possible_keys_stat(thd->mem_root, table, keys); } - else if (tab->select->cond || - (tab->cache_select && tab->cache_select->cond)) + else if (select->cond || + (cache_select && cache_select->cond)) { - const COND *pushed_cond= tab->table->file->pushed_cond; + const COND *pushed_cond= table->file->pushed_cond; - if ((tab->table->file->ha_table_flags() & + if ((table->file->ha_table_flags() & HA_CAN_TABLE_CONDITION_PUSHDOWN) && pushed_cond) { @@ -23913,8 +23920,8 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab } else { - eta->where_cond= tab->select->cond; - eta->cache_cond= tab->cache_select? tab->cache_select->cond : NULL; + eta->where_cond= select->cond; + eta->cache_cond= cache_select? cache_select->cond : NULL; eta->push_extra(ET_USING_WHERE); } } @@ -23945,7 +23952,7 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab if (quick_type == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX) { QUICK_GROUP_MIN_MAX_SELECT *qgs= - (QUICK_GROUP_MIN_MAX_SELECT *) tab->select->quick; + (QUICK_GROUP_MIN_MAX_SELECT *) select->quick; eta->push_extra(ET_USING_INDEX_FOR_GROUP_BY); eta->loose_scan_is_scanning= qgs->loose_scan_is_scanning(); } @@ -23957,7 +23964,7 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab if (quick_type == QUICK_SELECT_I::QS_TYPE_RANGE) { - explain_append_mrr_info((QUICK_RANGE_SELECT*)(tab->select->quick), + explain_append_mrr_info((QUICK_RANGE_SELECT*)(select->quick), &eta->mrr_type); if (eta->mrr_type.length() > 0) eta->push_extra(ET_USING_MRR); @@ -23965,30 +23972,30 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab if (distinct & test_all_bits(prefix_tables, join->select_list_used_tables)) eta->push_extra(ET_DISTINCT); - if (tab->loosescan_match_tab) + if (loosescan_match_tab) { eta->push_extra(ET_LOOSESCAN); } - if (tab->first_weedout_table) + if (first_weedout_table) { eta->start_dups_weedout= true; eta->push_extra(ET_START_TEMPORARY); } - if (tab->check_weed_out_table) + if (check_weed_out_table) { eta->push_extra(ET_END_TEMPORARY); eta->end_dups_weedout= true; } - else if (tab->do_firstmatch) + else if (do_firstmatch) { - if (tab->do_firstmatch == /*join->join_tab*/ first_top_tab - 1) + if (do_firstmatch == /*join->join_tab*/ first_top_tab - 1) eta->push_extra(ET_FIRST_MATCH); else { eta->push_extra(ET_FIRST_MATCH); - TABLE *prev_table=tab->do_firstmatch->table; + TABLE *prev_table=do_firstmatch->table; if (prev_table->derived_select_number) { char namebuf[NAME_LEN]; @@ -24003,9 +24010,9 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab } } - for (uint part= 0; part < tab->ref.key_parts; part++) + for (uint part= 0; part < ref.key_parts; part++) { - if (tab->ref.cond_guards[part]) + if (ref.cond_guards[part]) { eta->push_extra(ET_FULL_SCAN_ON_NULL_KEY); eta->full_scan_on_null_key= true; @@ -24013,10 +24020,10 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab } } - if (tab->cache) + if (cache) { eta->push_extra(ET_USING_JOIN_BUFFER); - tab->cache->save_explain_data(&eta->bka_type); + cache->save_explain_data(&eta->bka_type); } } @@ -24043,7 +24050,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table, const char *message) { JOIN *join= this; /* Legacy: this code used to be a non-member function */ - int error= 0; + int cur_error= 0; DBUG_ENTER("JOIN::save_explain_data_intern"); DBUG_PRINT("info", ("Select 0x%lx, type %s, message %s", (ulong)join->select_lex, join->select_lex->type, @@ -24106,12 +24113,12 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table, tab= next_explain_order_tab(join, tab)) { JOIN_TAB *saved_join_tab= NULL; - TABLE *table=tab->table; + TABLE *cur_table= tab->table; /* Don't show eliminated tables */ - if (table->map & join->eliminated_tables) + if (cur_table->map & join->eliminated_tables) { - used_tables|=table->map; + used_tables|= cur_table->map; continue; } @@ -24159,14 +24166,14 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table, tab= saved_join_tab; // For next iteration - used_tables|=table->map; + used_tables|= cur_table->map; } output->add_node(xpl_sel); } - for (SELECT_LEX_UNIT *unit= join->select_lex->first_inner_unit(); - unit; - unit= unit->next_unit()) + for (SELECT_LEX_UNIT *tmp_unit= join->select_lex->first_inner_unit(); + tmp_unit; + tmp_unit= tmp_unit->next_unit()) { /* Display subqueries only if @@ -24174,17 +24181,18 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table, elimination. (2) they are not merged derived tables */ - if (!(unit->item && unit->item->eliminated) && // (1) - (!unit->derived || unit->derived->is_materialized_derived())) // (2) + if (!(tmp_unit->item && tmp_unit->item->eliminated) && // (1) + (!tmp_unit->derived || + tmp_unit->derived->is_materialized_derived())) // (2) { - explain->add_child(unit->first_select()->select_number); + explain->add_child(tmp_unit->first_select()->select_number); } } - if (!error && select_lex->is_top_level_node()) + if (!cur_error && select_lex->is_top_level_node()) output->query_plan_ready(); - DBUG_RETURN(error); + DBUG_RETURN(cur_error); } @@ -24433,7 +24441,7 @@ static void print_join(THD *thd, { if (!(*t2)->sj_inner_tables) { - TABLE_LIST *tmp= *t2; + tmp= *t2; *t2= *table; *table= tmp; break; diff --git a/sql/sql_select.h b/sql/sql_select.h index 9528442ecf2..57b8658bdf1 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1049,7 +1049,7 @@ public: table_map outer_join; /* Bitmap of tables used in the select list items */ table_map select_list_used_tables; - ha_rows send_records,found_records,examined_rows; + ha_rows send_records,found_records,join_examined_rows; /* LIMIT for the JOIN operation. When not using aggregation or DISITNCT, this @@ -1122,7 +1122,7 @@ public: reexecutions. This value is equal to the multiplication of all join->positions[i].records_read of a JOIN. */ - double record_count; + double join_record_count; List<Item> *fields; List<Cached_item> group_fields, group_fields_cache; TABLE *tmp_table; @@ -1337,7 +1337,7 @@ public: send_records= 0; found_records= 0; fetch_limit= HA_POS_ERROR; - examined_rows= 0; + join_examined_rows= 0; exec_tmp_table1= 0; exec_tmp_table2= 0; sortorder= 0; diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index 297972f6dc4..0138c3e5a3b 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -1007,7 +1007,7 @@ int create_server(THD *thd, LEX_SERVER_OPTIONS *server_options) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_FOREIGN_SERVER_EXISTS, - ER(ER_FOREIGN_SERVER_EXISTS), + ER_THD(thd, ER_FOREIGN_SERVER_EXISTS), server_options->server_name.str); error= 0; goto end; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 802c4195d8e..8188f73a680 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1002,13 +1002,13 @@ public: failed is not available at this point. The only way for us to check is by reconstructing the actual error message and see if it's the same. */ - char* get_view_access_denied_message() + char* get_view_access_denied_message(THD *thd) { if (!m_view_access_denied_message_ptr) { m_view_access_denied_message_ptr= m_view_access_denied_message; my_snprintf(m_view_access_denied_message, MYSQL_ERRMSG_SIZE, - ER(ER_TABLEACCESS_DENIED_ERROR), "SHOW VIEW", + ER_THD(thd, ER_TABLEACCESS_DENIED_ERROR), "SHOW VIEW", m_sctx->priv_user, m_sctx->host_or_ip, m_top_view->get_table_name()); } @@ -1033,7 +1033,7 @@ public: switch (sql_errno) { case ER_TABLEACCESS_DENIED_ERROR: - if (!strcmp(get_view_access_denied_message(), message)) + if (!strcmp(get_view_access_denied_message(thd), message)) { /* Access to top view is not granted, don't interfere. */ is_handled= FALSE; @@ -1053,7 +1053,7 @@ public: are missing. */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_VIEW_INVALID, - ER(ER_VIEW_INVALID), + ER_THD(thd, ER_VIEW_INVALID), m_top_view->get_db_name(), m_top_view->get_table_name()); is_handled= TRUE; @@ -1228,7 +1228,7 @@ bool mysqld_show_create_db(THD *thd, LEX_STRING *dbname, status_var_increment(thd->status_var.access_denied_errors); my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), sctx->priv_user, sctx->host_or_ip, dbname->str); - general_log_print(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), + general_log_print(thd,COM_INIT_DB,ER_THD(thd, ER_DBACCESS_DENIED_ERROR), sctx->priv_user, sctx->host_or_ip, orig_dbname->str); DBUG_RETURN(TRUE); } @@ -4361,7 +4361,7 @@ static int fill_schema_table_from_frm(THD *thd, TABLE_LIST *tables, push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_I_S_SKIPPED_TABLE, - ER(ER_WARN_I_S_SKIPPED_TABLE), + ER_THD(thd, ER_WARN_I_S_SKIPPED_TABLE), table_list.db, table_list.table_name); return 0; } diff --git a/sql/sql_signal.cc b/sql/sql_signal.cc index f9933e68595..e3cf3f74318 100644 --- a/sql/sql_signal.cc +++ b/sql/sql_signal.cc @@ -89,11 +89,11 @@ void Set_signal_information::clear() memset(m_item, 0, sizeof(m_item)); } -void Sql_cmd_common_signal::assign_defaults( - Sql_condition *cond, - bool set_level_code, - Sql_condition::enum_warning_level level, - int sqlcode) +void +Sql_cmd_common_signal::assign_defaults(Sql_condition *cond, + bool set_level_code, + Sql_condition::enum_warning_level level, + int sqlcode) { if (set_level_code) { diff --git a/sql/sql_string.h b/sql/sql_string.h index 518b8e5ba4b..547ad54149b 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -226,13 +226,13 @@ public: } LEX_STRING lex_string() const { - LEX_STRING lex_string = { (char*) ptr(), length() }; - return lex_string; + LEX_STRING str = { (char*) ptr(), length() }; + return str; } LEX_CSTRING lex_cstring() const { - LEX_CSTRING lex_cstring = { ptr(), length() }; - return lex_cstring; + LEX_CSTRING skr = { ptr(), length() }; + return skr; } void set(String &str,uint32 offset,uint32 arg_length) @@ -285,15 +285,15 @@ public: bool set_real(double num,uint decimals, CHARSET_INFO *cs); /* Move handling of buffer from some other object to String */ - void reassociate(char *ptr, uint32 length, uint32 alloced_length, + void reassociate(char *ptr_arg, uint32 length_arg, uint32 alloced_length_arg, CHARSET_INFO *cs) { free(); - Ptr= ptr; - str_length= length; - Alloced_length= alloced_length; + Ptr= ptr_arg; + str_length= length_arg; + Alloced_length= alloced_length_arg; str_charset= cs; - alloced= ptr != 0; + alloced= ptr_arg != 0; } /* @@ -477,7 +477,7 @@ public: } bool append_hex(const char *src, uint32 srclen) { - for (const char *end= src + srclen ; src != end ; src++) + for (const char *src_end= src + srclen ; src != src_end ; src++) { if (append(_dig_vec_lower[((uchar) *src) >> 4]) || append(_dig_vec_lower[((uchar) *src) & 0x0F])) @@ -613,7 +613,7 @@ public: return TRUE; if (charset()->mbminlen > 1) return FALSE; - for (const char *c= ptr(), *end= c + length(); c < end; c++) + for (const char *c= ptr(), *c_end= c + length(); c < c_end; c++) { if (!my_isascii(*c)) return FALSE; @@ -655,10 +655,10 @@ public: { length(0); } - StringBuffer(const char *str, size_t length, CHARSET_INFO *cs) + StringBuffer(const char *str, size_t length_arg, CHARSET_INFO *cs) : String(buff, buff_sz, cs) { - set(str, length, cs); + set(str, length_arg, cs); } }; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 774fbaf4406..d359727fa47 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2418,7 +2418,8 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, tbl_name.append('.'); tbl_name.append(table->table_name); push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), + ER_BAD_TABLE_ERROR, + ER_THD(thd, ER_BAD_TABLE_ERROR), tbl_name.c_ptr_safe()); } else @@ -2514,7 +2515,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, DBUG_EXECUTE_IF("bug43138", my_printf_error(ER_BAD_TABLE_ERROR, - ER(ER_BAD_TABLE_ERROR), MYF(0), + ER_THD(thd, ER_BAD_TABLE_ERROR), MYF(0), table->table_name);); } DEBUG_SYNC(thd, "rm_table_no_locks_before_binlog"); @@ -2526,10 +2527,11 @@ err: { DBUG_ASSERT(errors); if (errors == 1 && was_view) - my_printf_error(ER_IT_IS_A_VIEW, ER(ER_IT_IS_A_VIEW), MYF(0), + my_printf_error(ER_IT_IS_A_VIEW, ER_THD(thd, ER_IT_IS_A_VIEW), MYF(0), wrong_tables.c_ptr_safe()); else if (errors > 1 || !thd->is_error()) - my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), + my_printf_error(ER_BAD_TABLE_ERROR, ER_THD(thd, ER_BAD_TABLE_ERROR), + MYF(0), wrong_tables.c_ptr_safe()); error= 1; } @@ -2816,7 +2818,7 @@ bool check_duplicates_in_interval(const char *set_or_name, } push_warning_printf(thd,Sql_condition::WARN_LEVEL_NOTE, ER_DUPLICATED_VALUE_IN_TYPE, - ER(ER_DUPLICATED_VALUE_IN_TYPE), + ER_THD(thd, ER_DUPLICATED_VALUE_IN_TYPE), name, err.ptr(), set_or_name); (*dup_val_count)++; } @@ -3163,7 +3165,7 @@ static void check_duplicate_key(THD *thd, if (all_columns_are_identical) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_DUP_INDEX, ER(ER_DUP_INDEX), + ER_DUP_INDEX, ER_THD(thd, ER_DUP_INDEX), key_info->name, thd->lex->query_tables->db, thd->lex->query_tables->table_name); @@ -3521,7 +3523,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, } if (auto_increment > 1) { - my_message(ER_WRONG_AUTO_KEY, ER(ER_WRONG_AUTO_KEY), MYF(0)); + my_message(ER_WRONG_AUTO_KEY, ER_THD(thd, ER_WRONG_AUTO_KEY), MYF(0)); DBUG_RETURN(TRUE); } if (auto_increment && @@ -3576,7 +3578,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, my_error(ER_WRONG_FK_DEF, MYF(0), (fk_key->name.str ? fk_key->name.str : "foreign key without name"), - ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF)); + ER_THD(thd, ER_KEY_REF_DO_NOT_MATCH_TABLE_REF)); DBUG_RETURN(TRUE); } continue; @@ -3588,7 +3590,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, my_error(ER_TOO_MANY_KEY_PARTS,MYF(0),tmp); DBUG_RETURN(TRUE); } - if (check_string_char_length(&key->name, "", NAME_CHAR_LEN, + if (check_string_char_length(&key->name, 0, NAME_CHAR_LEN, system_charset_info, 1)) { my_error(ER_TOO_LONG_IDENT, MYF(0), key->name.str); @@ -3789,7 +3791,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, column->field_name.str, dup_column->field_name.str)) { my_printf_error(ER_DUP_FIELDNAME, - ER(ER_DUP_FIELDNAME),MYF(0), + ER_THD(thd, ER_DUP_FIELDNAME),MYF(0), column->field_name.str); DBUG_RETURN(TRUE); } @@ -3897,7 +3899,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, if (key->type == Key::SPATIAL) { my_message(ER_SPATIAL_CANT_HAVE_NULL, - ER(ER_SPATIAL_CANT_HAVE_NULL), MYF(0)); + ER_THD(thd, ER_SPATIAL_CANT_HAVE_NULL), MYF(0)); DBUG_RETURN(TRUE); } } @@ -3929,8 +3931,9 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, { /* not a critical problem */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_TOO_LONG_KEY, ER(ER_TOO_LONG_KEY), - key_part_length); + ER_TOO_LONG_KEY, + ER_THD(thd, ER_TOO_LONG_KEY), + key_part_length); /* Align key length to multibyte char boundary */ key_part_length-= key_part_length % sql_field->charset->mbmaxlen; } @@ -3956,7 +3959,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, // and is this a 'unique' key? (key_info->flags & HA_NOSAME)))) { - my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0)); + my_message(ER_WRONG_SUB_KEY, ER_THD(thd, ER_WRONG_SUB_KEY), MYF(0)); DBUG_RETURN(TRUE); } else if (!(file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS)) @@ -3976,8 +3979,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, { /* not a critical problem */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_TOO_LONG_KEY, ER(ER_TOO_LONG_KEY), - key_part_length); + ER_TOO_LONG_KEY, ER_THD(thd, ER_TOO_LONG_KEY), + key_part_length); /* Align key length to multibyte char boundary */ key_part_length-= key_part_length % sql_field->charset->mbmaxlen; } @@ -4016,7 +4019,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, { if (primary_key) { - my_message(ER_MULTIPLE_PRI_KEY, ER(ER_MULTIPLE_PRI_KEY), + my_message(ER_MULTIPLE_PRI_KEY, ER_THD(thd, ER_MULTIPLE_PRI_KEY), MYF(0)); DBUG_RETURN(TRUE); } @@ -4069,12 +4072,13 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, if (!unique_key && !primary_key && (file->ha_table_flags() & HA_REQUIRE_PRIMARY_KEY)) { - my_message(ER_REQUIRES_PRIMARY_KEY, ER(ER_REQUIRES_PRIMARY_KEY), MYF(0)); + my_message(ER_REQUIRES_PRIMARY_KEY, ER_THD(thd, ER_REQUIRES_PRIMARY_KEY), + MYF(0)); DBUG_RETURN(TRUE); } if (auto_increment > 0) { - my_message(ER_WRONG_AUTO_KEY, ER(ER_WRONG_AUTO_KEY), MYF(0)); + my_message(ER_WRONG_AUTO_KEY, ER_THD(thd, ER_WRONG_AUTO_KEY), MYF(0)); DBUG_RETURN(TRUE); } /* Sort keys in optimized order */ @@ -4121,7 +4125,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, if (create_info->transactional) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_ILLEGAL_HA_CREATE_OPTION, - ER(ER_ILLEGAL_HA_CREATE_OPTION), + ER_THD(thd, ER_ILLEGAL_HA_CREATE_OPTION), file->engine_name()->str, "TRANSACTIONAL=1"); @@ -4165,7 +4169,8 @@ bool validate_comment_length(THD *thd, LEX_STRING *comment, size_t max_len, DBUG_RETURN(true); } push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, err_code, - ER(err_code), name, static_cast<ulong>(max_len)); + ER_THD(thd, err_code), name, + static_cast<ulong>(max_len)); comment->length= tmp_len; } DBUG_RETURN(false); @@ -4236,9 +4241,11 @@ static bool prepare_blob_field(THD *thd, Create_field *sql_field) } sql_field->sql_type= MYSQL_TYPE_BLOB; sql_field->flags|= BLOB_FLAG; - my_snprintf(warn_buff, sizeof(warn_buff), ER(ER_AUTO_CONVERT), sql_field->field_name, - (sql_field->charset == &my_charset_bin) ? "VARBINARY" : "VARCHAR", - (sql_field->charset == &my_charset_bin) ? "BLOB" : "TEXT"); + my_snprintf(warn_buff, sizeof(warn_buff), ER_THD(thd, ER_AUTO_CONVERT), + sql_field->field_name, + (sql_field->charset == &my_charset_bin) ? "VARBINARY" : + "VARCHAR", + (sql_field->charset == &my_charset_bin) ? "BLOB" : "TEXT"); push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_AUTO_CONVERT, warn_buff); } @@ -4626,11 +4633,13 @@ int create_table_impl(THD *thd, { if (create_info->data_file_name) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED), + WARN_OPTION_IGNORED, + ER_THD(thd, WARN_OPTION_IGNORED), "DATA DIRECTORY"); if (create_info->index_file_name) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED), + WARN_OPTION_IGNORED, + ER_THD(thd, WARN_OPTION_IGNORED), "INDEX DIRECTORY"); create_info->data_file_name= create_info->index_file_name= 0; } @@ -4867,7 +4876,8 @@ err: warn: error= -1; push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + ER_TABLE_EXISTS_ERROR, + ER_THD(thd, ER_TABLE_EXISTS_ERROR), alias); goto err; } @@ -5669,8 +5679,8 @@ handle_if_exists_options(THD *thd, TABLE *table, Alter_info *alter_info) continue; drop_create_field: push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_DUP_FIELDNAME, ER(ER_DUP_FIELDNAME), - sql_field->field_name); + ER_DUP_FIELDNAME, ER_THD(thd, ER_DUP_FIELDNAME), + sql_field->field_name); it.remove(); if (alter_info->create_list.is_empty()) { @@ -5706,8 +5716,9 @@ drop_create_field: if (*f_ptr == NULL) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), - sql_field->change, table->s->table_name.str); + ER_BAD_FIELD_ERROR, + ER_THD(thd, ER_BAD_FIELD_ERROR), + sql_field->change, table->s->table_name.str); it.remove(); if (alter_info->create_list.is_empty()) { @@ -5801,8 +5812,9 @@ drop_create_field: if (remove_drop) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_CANT_DROP_FIELD_OR_KEY, ER(ER_CANT_DROP_FIELD_OR_KEY), - drop->name); + ER_CANT_DROP_FIELD_OR_KEY, + ER_THD(thd, ER_CANT_DROP_FIELD_OR_KEY), + drop->name); drop_it.remove(); if (alter_info->drop_list.is_empty()) alter_info->flags&= ~(Alter_info::ALTER_DROP_COLUMN | @@ -5890,7 +5902,8 @@ remove_key: if (key->if_not_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_DUP_KEYNAME, ER(ER_DUP_KEYNAME), keyname); + ER_DUP_KEYNAME, ER_THD(thd, ER_DUP_KEYNAME), + keyname); key_it.remove(); if (key->type == Key::FOREIGN_KEY) { @@ -5934,8 +5947,9 @@ remove_key: if (!tab_part_info->has_unique_name(pe)) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_SAME_NAME_PARTITION, ER(ER_SAME_NAME_PARTITION), - pe->partition_name); + ER_SAME_NAME_PARTITION, + ER_THD(thd, ER_SAME_NAME_PARTITION), + pe->partition_name); alter_info->flags&= ~Alter_info::ALTER_ADD_PARTITION; thd->lex->part_info= NULL; break; @@ -5963,8 +5977,9 @@ remove_key: if (!part_elem) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_DROP_PARTITION_NON_EXISTENT, - ER(ER_DROP_PARTITION_NON_EXISTENT), "DROP"); + ER_DROP_PARTITION_NON_EXISTENT, + ER_THD(thd, ER_DROP_PARTITION_NON_EXISTENT), + "DROP"); names_it.remove(); } } @@ -6764,12 +6779,14 @@ bool alter_table_manage_keys(TABLE *table, int indexes_were_disabled, if (error == HA_ERR_WRONG_COMMAND) { - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_NOTE, - ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), + THD *thd= table->in_use; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, + ER_ILLEGAL_HA, ER_THD(thd, ER_ILLEGAL_HA), table->file->table_type(), table->s->db.str, table->s->table_name.str); error= 0; - } else if (error) + } + else if (error) table->file->print_error(error, MYF(0)); DBUG_RETURN(error); @@ -7485,7 +7502,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, } if (!new_create_list.elements) { - my_message(ER_CANT_REMOVE_ALL_FIELDS, ER(ER_CANT_REMOVE_ALL_FIELDS), + my_message(ER_CANT_REMOVE_ALL_FIELDS, + ER_THD(thd, ER_CANT_REMOVE_ALL_FIELDS), MYF(0)); goto err; } @@ -7963,7 +7981,7 @@ static bool fk_prepare_copy_alter_table(THD *thd, TABLE *table, case FK_COLUMN_RENAMED: my_error(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON, MYF(0), "ALGORITHM=COPY", - ER(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_FK_RENAME), + ER_THD(thd, ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_FK_RENAME), "ALGORITHM=INPLACE"); DBUG_RETURN(true); case FK_COLUMN_DROPPED: @@ -8029,7 +8047,7 @@ static bool fk_prepare_copy_alter_table(THD *thd, TABLE *table, case FK_COLUMN_RENAMED: my_error(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON, MYF(0), "ALGORITHM=COPY", - ER(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_FK_RENAME), + ER_THD(thd, ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_FK_RENAME), "ALGORITHM=INPLACE"); DBUG_RETURN(true); case FK_COLUMN_DROPPED: @@ -8438,7 +8456,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (alter_info->flags == 0) { my_snprintf(alter_ctx.tmp_name, sizeof(alter_ctx.tmp_name), - ER(ER_INSERT_INFO), 0L, 0L, + ER_THD(thd, ER_INSERT_INFO), 0L, 0L, thd->get_stmt_da()->current_statement_warn_count()); my_ok(thd, 0L, 0L, alter_ctx.tmp_name); DBUG_RETURN(false); @@ -8502,7 +8520,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, { my_error(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON, MYF(0), "LOCK=NONE/SHARED/EXCLUSIVE", - ER(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_PARTITION), + ER_THD(thd, ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_PARTITION), "LOCK=DEFAULT"); DBUG_RETURN(true); } @@ -8511,7 +8529,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, { my_error(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON, MYF(0), "ALGORITHM=COPY/INPLACE", - ER(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_PARTITION), + ER_THD(thd, ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_PARTITION), "ALGORITHM=DEFAULT"); DBUG_RETURN(true); } @@ -8840,7 +8858,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, { my_error(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON, MYF(0), "LOCK=NONE", - ER(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_COPY), + ER_THD(thd, ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_COPY), "LOCK=SHARED"); goto err_new_table_cleanup; } @@ -9119,7 +9137,7 @@ end_inplace: end_temporary: my_snprintf(alter_ctx.tmp_name, sizeof(alter_ctx.tmp_name), - ER(ER_INSERT_INFO), + ER_THD(thd, ER_INSERT_INFO), (ulong) (copied + deleted), (ulong) deleted, (ulong) thd->get_stmt_da()->current_statement_warn_count()); my_ok(thd, copied + deleted, 0L, alter_ctx.tmp_name); @@ -9462,11 +9480,11 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, uint key_nr= to->file->get_dup_key(error); if ((int) key_nr >= 0) { - const char *err_msg= ER(ER_DUP_ENTRY_WITH_KEY_NAME); + const char *err_msg= ER_THD(thd, ER_DUP_ENTRY_WITH_KEY_NAME); if (key_nr == 0 && (to->key_info[0].key_part[0].field->flags & AUTO_INCREMENT_FLAG)) - err_msg= ER(ER_DUP_ENTRY_AUTOINCREMENT_CASE); + err_msg= ER_THD(thd, ER_DUP_ENTRY_AUTOINCREMENT_CASE); print_keydup_error(to, key_nr == MAX_KEY ? NULL : &to->key_info[key_nr], err_msg, MYF(0)); @@ -9790,7 +9808,7 @@ static bool check_engine(THD *thd, const char *db_name, { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_WARN_USING_OTHER_HANDLER, - ER(ER_WARN_USING_OTHER_HANDLER), + ER_THD(thd, ER_WARN_USING_OTHER_HANDLER), ha_resolve_storage_engine_name(*new_engine), table_name); } diff --git a/sql/sql_tablespace.cc b/sql/sql_tablespace.cc index 2991b16350c..8b9e14e5a18 100644 --- a/sql/sql_tablespace.cc +++ b/sql/sql_tablespace.cc @@ -38,7 +38,7 @@ int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info) if (ts_info->storage_engine != 0) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_USING_OTHER_HANDLER, - ER(ER_WARN_USING_OTHER_HANDLER), + ER_THD(thd, ER_WARN_USING_OTHER_HANDLER), hton_name(hton)->str, ts_info->tablespace_name ? ts_info->tablespace_name : ts_info->logfile_group_name); @@ -68,7 +68,7 @@ int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_ILLEGAL_HA_CREATE_OPTION, - ER(ER_ILLEGAL_HA_CREATE_OPTION), + ER_THD(thd, ER_ILLEGAL_HA_CREATE_OPTION), hton_name(hton)->str, "TABLESPACE or LOGFILE GROUP"); } diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 267b183562b..199ce19450e 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -877,18 +877,18 @@ void make_truncated_value_warning(THD *thd, } if (field_name) cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff), - ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), type_str, sval->ptr(), field_name, (ulong) thd->get_stmt_da()->current_row_for_warning()); else { if (time_type > MYSQL_TIMESTAMP_ERROR) cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff), - ER(ER_TRUNCATED_WRONG_VALUE), + ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), type_str, sval->ptr()); else cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff), - ER(ER_WRONG_VALUE), type_str, sval->ptr()); + ER_THD(thd, ER_WRONG_VALUE), type_str, sval->ptr()); } push_warning(thd, level, ER_TRUNCATED_WRONG_VALUE, warn_buff); @@ -1011,11 +1011,14 @@ bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, return 0; // Ok invalid_date: - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_DATETIME_FUNCTION_OVERFLOW, - ER(ER_DATETIME_FUNCTION_OVERFLOW), - ltime->time_type == MYSQL_TIMESTAMP_TIME ? - "time" : "datetime"); + { + THD *thd= current_thd; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_DATETIME_FUNCTION_OVERFLOW, + ER_THD(thd, ER_DATETIME_FUNCTION_OVERFLOW), + ltime->time_type == MYSQL_TIMESTAMP_TIME ? + "time" : "datetime"); + } null_date: return 1; } diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 54a68da28c9..58fd7aeb7dc 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -159,7 +159,7 @@ Trigger_creation_ctx::create(THD *thd, push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRG_INVALID_CREATION_CTX, - ER(ER_TRG_INVALID_CREATION_CTX), + ER_THD(thd, ER_TRG_INVALID_CREATION_CTX), (const char *) db_name, (const char *) table_name); } @@ -340,11 +340,11 @@ public: m_trigger_name= &thd->lex->spname->m_name; if (m_trigger_name) my_snprintf(m_message, sizeof(m_message), - ER(ER_ERROR_IN_TRIGGER_BODY), + ER_THD(thd, ER_ERROR_IN_TRIGGER_BODY), m_trigger_name->str, message); else my_snprintf(m_message, sizeof(m_message), - ER(ER_ERROR_IN_UNKNOWN_TRIGGER_BODY), message); + ER_THD(thd, ER_ERROR_IN_UNKNOWN_TRIGGER_BODY), message); return true; } return false; @@ -801,7 +801,8 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, else if (lex->create_info.if_not_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_TRG_ALREADY_EXISTS, ER(ER_TRG_ALREADY_EXISTS), + ER_TRG_ALREADY_EXISTS, + ER_THD(thd, ER_TRG_ALREADY_EXISTS), trigname_buff); LEX_STRING trg_definer_tmp; build_trig_stmt_query(thd, tables, stmt_query, @@ -1042,7 +1043,8 @@ bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables, } } - my_message(ER_TRG_DOES_NOT_EXIST, ER(ER_TRG_DOES_NOT_EXIST), MYF(0)); + my_message(ER_TRG_DOES_NOT_EXIST, ER_THD(thd, ER_TRG_DOES_NOT_EXIST), + MYF(0)); return 1; } @@ -1086,8 +1088,8 @@ bool Table_triggers_list::prepare_record1_accessors(TABLE *table) QQ: it is supposed that it is ok to use this function for field cloning... */ - if (!(*old_fld= (*fld)->new_field(&table->mem_root, table, - table == (*fld)->table))) + if (!(*old_fld= (*fld)->make_new_field(&table->mem_root, table, + table == (*fld)->table))) return 1; (*old_fld)->move_field_offset((my_ptrdiff_t)(table->record[1] - table->record[0])); @@ -1275,7 +1277,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRG_NO_CREATION_CTX, - ER(ER_TRG_NO_CREATION_CTX), + ER_THD(thd, ER_TRG_NO_CREATION_CTX), (const char*) db, (const char*) table_name); @@ -1458,7 +1460,8 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_TRG_NO_DEFINER, ER(ER_TRG_NO_DEFINER), + ER_TRG_NO_DEFINER, + ER_THD(thd, ER_TRG_NO_DEFINER), (const char*) db, (const char*) sp->m_name.str); @@ -1732,7 +1735,7 @@ bool add_table_for_trigger(THD *thd, push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_TRG_DOES_NOT_EXIST, - ER(ER_TRG_DOES_NOT_EXIST)); + ER_THD(thd, ER_TRG_DOES_NOT_EXIST)); *table= NULL; @@ -2327,13 +2330,14 @@ process_unknown_string(const char *&unknown_key, uchar* base, unknown_key[INVALID_SQL_MODES_LENGTH] == '=' && !memcmp(unknown_key, STRING_WITH_LEN("sql_modes"))) { + THD *thd= current_thd; const char *ptr= unknown_key + INVALID_SQL_MODES_LENGTH + 1; DBUG_PRINT("info", ("sql_modes affected by BUG#14090 detected")); - push_warning_printf(current_thd, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_OLD_FILE_FORMAT, - ER(ER_OLD_FILE_FORMAT), + ER_THD(thd, ER_OLD_FILE_FORMAT), (char *)path, "TRIGGER"); if (get_file_options_ulllist(ptr, end, unknown_key, base, &sql_modes_parameters, mem_root)) @@ -2368,13 +2372,14 @@ process_unknown_string(const char *&unknown_key, uchar* base, unknown_key[INVALID_TRIGGER_TABLE_LENGTH] == '=' && !memcmp(unknown_key, STRING_WITH_LEN("trigger_table"))) { + THD *thd= current_thd; const char *ptr= unknown_key + INVALID_TRIGGER_TABLE_LENGTH + 1; DBUG_PRINT("info", ("trigger_table affected by BUG#15921 detected")); - push_warning_printf(current_thd, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_OLD_FILE_FORMAT, - ER(ER_OLD_FILE_FORMAT), + ER_THD(thd, ER_OLD_FILE_FORMAT), (char *)path, "TRIGGER"); if (!(ptr= parse_escaped_string(ptr, end, mem_root, trigger_table_value))) diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index d266e8f6bc7..d962df6257d 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -90,10 +90,11 @@ static char *init_syms(udf_func *tmp, char *nm) */ if (!tmp->func_init && !tmp->func_deinit && tmp->type != UDFTYPE_AGGREGATE) { + THD *thd= current_thd; if (!opt_allow_suspicious_udfs) return nm; - if (current_thd->variables.log_warnings) - sql_print_warning(ER(ER_CANT_FIND_DL_ENTRY), nm); + if (thd->variables.log_warnings) + sql_print_warning(ER_THD(thd, ER_CANT_FIND_DL_ENTRY), nm); } return 0; } @@ -207,7 +208,7 @@ void udf_init() On windows we must check both FN_LIBCHAR and '/'. */ if (check_valid_path(dl_name, strlen(dl_name)) || - check_string_char_length(&name, "", NAME_CHAR_LEN, + check_string_char_length(&name, 0, NAME_CHAR_LEN, system_charset_info, 1)) { sql_print_error("Invalid row in mysql.func table for function '%.64s'", @@ -232,7 +233,8 @@ void udf_init() if (!(dl= dlopen(dlpath, RTLD_NOW))) { /* Print warning to log */ - sql_print_error(ER(ER_CANT_OPEN_LIBRARY), tmp->dl, errno, dlerror()); + sql_print_error(ER_THD(new_thd, ER_CANT_OPEN_LIBRARY), + tmp->dl, errno, dlerror()); /* Keep the udf in the hash so that we can remove it later */ continue; } @@ -243,7 +245,7 @@ void udf_init() char buf[SAFE_NAME_LEN+16], *missing; if ((missing= init_syms(tmp, buf))) { - sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), missing); + sql_print_error(ER_THD(new_thd, ER_CANT_FIND_DL_ENTRY), missing); del_udf(tmp); if (new_dl) dlclose(dl); @@ -481,7 +483,8 @@ int mysql_create_function(THD *thd,udf_func *udf) udf->name.str, "UDFs are unavailable with the --skip-grant-tables option"); else - my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); + my_message(ER_OUT_OF_RESOURCES, ER_THD(thd, ER_OUT_OF_RESOURCES), + MYF(0)); DBUG_RETURN(1); } @@ -492,10 +495,10 @@ int mysql_create_function(THD *thd,udf_func *udf) */ if (check_valid_path(udf->dl, strlen(udf->dl))) { - my_message(ER_UDF_NO_PATHS, ER(ER_UDF_NO_PATHS), MYF(0)); + my_message(ER_UDF_NO_PATHS, ER_THD(thd, ER_UDF_NO_PATHS), MYF(0)); DBUG_RETURN(1); } - if (check_string_char_length(&udf->name, "", NAME_CHAR_LEN, + if (check_string_char_length(&udf->name, 0, NAME_CHAR_LEN, system_charset_info, 1)) { my_error(ER_TOO_LONG_IDENT, MYF(0), udf->name.str); @@ -519,7 +522,7 @@ int mysql_create_function(THD *thd,udf_func *udf) else if (thd->lex->create_info.if_not_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_UDF_EXISTS, - ER(ER_UDF_EXISTS), udf->name.str); + ER_THD(thd, ER_UDF_EXISTS), udf->name.str); goto done; } @@ -615,7 +618,8 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) if (opt_noacl) my_error(ER_FUNCTION_NOT_DEFINED, MYF(0), udf_name->str); else - my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); + my_message(ER_OUT_OF_RESOURCES, ER_THD(thd, ER_OUT_OF_RESOURCES), + MYF(0)); DBUG_RETURN(1); } @@ -631,7 +635,8 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) if (thd->lex->check_exists) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_FUNCTION_NOT_DEFINED, ER(ER_FUNCTION_NOT_DEFINED), + ER_FUNCTION_NOT_DEFINED, + ER_THD(thd, ER_FUNCTION_NOT_DEFINED), udf_name->str); goto done; } diff --git a/sql/sql_union.cc b/sql/sql_union.cc index f7df0fd1538..80c576bb993 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -495,7 +495,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, if (types.elements != sl->item_list.elements) { my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT, - ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT),MYF(0)); + ER_THD(thd, ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT),MYF(0)); goto err; } List_iterator_fast<Item> it(sl->item_list); @@ -886,7 +886,7 @@ bool st_select_lex_unit::exec() */ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT, - ER(ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT), + ER_THD(thd, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT), thd->accessed_rows_and_keys, thd->lex->limit_rows_examined->val_uint()); thd->reset_killed(); @@ -985,7 +985,7 @@ bool st_select_lex_unit::exec() } else { - join->examined_rows= 0; + join->join_examined_rows= 0; saved_error= join->reinit(); join->exec(); } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 171a63a0a6e..e889ce0b669 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -447,7 +447,7 @@ int mysql_update(THD *thd, if (safe_update && !using_limit) { my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, - ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); + ER_THD(thd, ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); goto err; } } @@ -1017,7 +1017,7 @@ int mysql_update(THD *thd, if (error < 0 && !thd->lex->analyze_stmt) { char buff[MYSQL_ERRMSG_SIZE]; - my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), (ulong) found, + my_snprintf(buff, sizeof(buff), ER_THD(thd, ER_UPDATE_INFO), (ulong) found, (ulong) updated, (ulong) thd->get_stmt_da()->current_statement_warn_count()); my_ok(thd, (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated, @@ -1650,7 +1650,7 @@ int multi_update::prepare(List<Item> ¬_used_values, if (!tables_to_update) { - my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0)); + my_message(ER_NO_TABLES_USED, ER_THD(thd, ER_NO_TABLES_USED), MYF(0)); DBUG_RETURN(1); } @@ -2549,7 +2549,7 @@ bool multi_update::send_eof() { id= thd->arg_of_last_insert_id_function ? thd->first_successful_insert_id_in_prev_stmt : 0; - my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), + my_snprintf(buff, sizeof(buff), ER_THD(thd, ER_UPDATE_INFO), (ulong) found, (ulong) updated, (ulong) thd->cuted_fields); ::my_ok(thd, (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated, id, buff); diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 1dadad9dd17..f66eda06199 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -533,7 +533,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, if (lex->view_list.elements != select_lex->item_list.elements) { - my_message(ER_VIEW_WRONG_LIST, ER(ER_VIEW_WRONG_LIST), MYF(0)); + my_message(ER_VIEW_WRONG_LIST, ER_THD(thd, ER_VIEW_WRONG_LIST), MYF(0)); res= TRUE; goto err; } @@ -939,7 +939,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, !lex->can_be_merged()) { push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_VIEW_MERGE, - ER(ER_WARN_VIEW_MERGE)); + ER_THD(thd, ER_WARN_VIEW_MERGE)); lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED; } view->algorithm= lex->create_view_algorithm; @@ -1002,7 +1002,8 @@ loop_out: if (lex->create_info.if_not_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + ER_TABLE_EXISTS_ERROR, + ER_THD(thd, ER_TABLE_EXISTS_ERROR), view->table_name); DBUG_RETURN(0); } @@ -1232,7 +1233,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, !table->definer.user.length && !table->definer.host.length); push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_VIEW_FRM_NO_USER, ER(ER_VIEW_FRM_NO_USER), + ER_VIEW_FRM_NO_USER, ER_THD(thd, ER_VIEW_FRM_NO_USER), table->db, table->table_name); get_default_definer(thd, &table->definer, false); } @@ -1413,7 +1414,8 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, check_table_access(thd, SHOW_VIEW_ACL, &view_no_suid, FALSE, UINT_MAX, TRUE)) { - my_message(ER_VIEW_NO_EXPLAIN, ER(ER_VIEW_NO_EXPLAIN), MYF(0)); + my_message(ER_VIEW_NO_EXPLAIN, ER_THD(thd, ER_VIEW_NO_EXPLAIN), + MYF(0)); goto err; } } @@ -1644,7 +1646,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_VIEW_ORDERBY_IGNORED, - ER(ER_VIEW_ORDERBY_IGNORED), + ER_THD(thd, ER_VIEW_ORDERBY_IGNORED), table->db, table->table_name); } } @@ -1757,7 +1759,8 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) if (thd->lex->if_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), + ER_BAD_TABLE_ERROR, + ER_THD(thd, ER_BAD_TABLE_ERROR), name); continue; } @@ -1937,7 +1940,8 @@ bool check_key_in_view(THD *thd, TABLE_LIST *view) { /* update allowed, but issue warning */ push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_WARN_VIEW_WITHOUT_KEY, ER(ER_WARN_VIEW_WITHOUT_KEY)); + ER_WARN_VIEW_WITHOUT_KEY, + ER_THD(thd, ER_WARN_VIEW_WITHOUT_KEY)); DBUG_RETURN(FALSE); } /* prohibit update */ diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 1d31df4d000..55041b1e172 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -93,11 +93,11 @@ int yylex(void *yylval, void *yythd); YYABORT; \ } while (0) -#define MYSQL_YYABORT_UNLESS(A) \ - if (!(A)) \ - { \ - my_parse_error(ER(ER_SYNTAX_ERROR));\ - MYSQL_YYABORT; \ +#define MYSQL_YYABORT_UNLESS(A) \ + if (!(A)) \ + { \ + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR));\ + MYSQL_YYABORT; \ } /* @@ -152,13 +152,13 @@ void my_parse_error(const char *s, const char *yytext=0) /* Push an error into the error stack */ ErrConvString err(yytext, strlen(yytext), thd->variables.character_set_client); - my_printf_error(ER_PARSE_ERROR, ER(ER_PARSE_ERROR), MYF(0), s, + my_printf_error(ER_PARSE_ERROR, ER_THD(thd, ER_PARSE_ERROR), MYF(0), s, err.ptr(), lip->yylineno); } void LEX::parse_error() { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); } @@ -193,7 +193,7 @@ void MYSQLerror(THD *thd, const char *s) /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */ if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0) - s= ER(ER_SYNTAX_ERROR); + s= ER_THD(thd, ER_SYNTAX_ERROR); my_parse_error(s); } @@ -673,7 +673,7 @@ bool add_select_to_union_list(LEX *lex, bool is_union_distinct, } if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(lex->thd, ER_SYNTAX_ERROR)); return TRUE; } /* This counter shouldn't be incremented for UNION parts */ @@ -701,7 +701,7 @@ bool setup_select_in_parentheses(LEX *lex) /* if (sel->set_braces(1)) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(lex->thd, ER_SYNTAX_ERROR)); return TRUE; } */ @@ -711,7 +711,7 @@ bool setup_select_in_parentheses(LEX *lex) sel->master_unit()->first_select()->linkage == UNION_TYPE) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(lex->thd, ER_SYNTAX_ERROR)); return TRUE; } if (sel->linkage == UNION_TYPE && @@ -860,11 +860,12 @@ static void add_key_to_list(LEX *lex, LEX_STRING *field_name, lex->alter_info.key_list.push_back(key); } -void LEX::init_last_field(Create_field *field, const char *name, CHARSET_INFO *cs) +void LEX::init_last_field(Create_field *field, const char *field_name, + CHARSET_INFO *cs) { last_field= field; - field->field_name= name; + field->field_name= field_name; /* reset LEX fields that are used in Create_field::set_and_check() */ length= 0; @@ -872,9 +873,9 @@ void LEX::init_last_field(Create_field *field, const char *name, CHARSET_INFO *c charset= cs; } -void LEX::set_last_field_type(enum enum_field_types type) +void LEX::set_last_field_type(enum enum_field_types field_type) { - last_field->sql_type= type; + last_field->sql_type= field_type; last_field->create_if_not_exists= check_exists; last_field->charset= charset; @@ -2000,7 +2001,7 @@ query: if (!thd->bootstrap && (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT))) { - my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0)); + my_message(ER_EMPTY_QUERY, ER_THD(thd, ER_EMPTY_QUERY), MYF(0)); MYSQL_YYABORT; } thd->lex->sql_command= SQLCOM_EMPTY_QUERY; @@ -2289,7 +2290,7 @@ master_def: { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX, - ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX)); + ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX)); } if (Lex->mi.heartbeat_period < 0.001) { @@ -2297,7 +2298,7 @@ master_def: { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN, - ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN)); + ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN)); Lex->mi.heartbeat_period= 0.0; } Lex->mi.heartbeat_opt= LEX_MASTER_INFO::LEX_MI_DISABLE; @@ -2473,7 +2474,7 @@ create: lex->create_info.use_default_db_type(thd); push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_USING_OTHER_HANDLER, - ER(ER_WARN_USING_OTHER_HANDLER), + ER_THD(thd, ER_WARN_USING_OTHER_HANDLER), hton_name(lex->create_info.db_type)->str, $5->table.str); } @@ -2990,13 +2991,13 @@ sp_decls: if (($2.vars || $2.conds) && ($1.curs || $1.hndlrs)) { /* Variable or condition following cursor or handler */ my_message(ER_SP_VARCOND_AFTER_CURSHNDLR, - ER(ER_SP_VARCOND_AFTER_CURSHNDLR), MYF(0)); + ER_THD(thd, ER_SP_VARCOND_AFTER_CURSHNDLR), MYF(0)); MYSQL_YYABORT; } if ($2.curs && $1.hndlrs) { /* Cursor following handler */ my_message(ER_SP_CURSOR_AFTER_HANDLER, - ER(ER_SP_CURSOR_AFTER_HANDLER), MYF(0)); + ER_THD(thd, ER_SP_CURSOR_AFTER_HANDLER), MYF(0)); MYSQL_YYABORT; } $$.vars= $1.vars + $2.vars; @@ -3191,7 +3192,7 @@ sp_cursor_stmt: if (lex->result) { - my_message(ER_SP_BAD_CURSOR_SELECT, ER(ER_SP_BAD_CURSOR_SELECT), + my_message(ER_SP_BAD_CURSOR_SELECT, ER_THD(thd, ER_SP_BAD_CURSOR_SELECT), MYF(0)); MYSQL_YYABORT; } @@ -3224,7 +3225,7 @@ sp_hcond_element: if (ctx->check_duplicate_handler($1)) { - my_message(ER_SP_DUP_HANDLER, ER(ER_SP_DUP_HANDLER), MYF(0)); + my_message(ER_SP_DUP_HANDLER, ER_THD(thd, ER_SP_DUP_HANDLER), MYF(0)); MYSQL_YYABORT; } else @@ -3413,7 +3414,7 @@ signal_allowed_expr: SIGNAL/RESIGNAL ... SET <signal condition item name> = @foo := expr */ - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -3746,7 +3747,7 @@ sp_proc_stmt_return: if (sp->m_type != TYPE_ENUM_FUNCTION) { - my_message(ER_SP_BADRETURN, ER(ER_SP_BADRETURN), MYF(0)); + my_message(ER_SP_BADRETURN, ER_THD(thd, ER_SP_BADRETURN), MYF(0)); MYSQL_YYABORT; } else @@ -4079,7 +4080,7 @@ case_stmt_specification: BACKPATCH: Creating target label for the jump to after END CASE (instruction 12 in the example) */ - Lex->spcont->push_label(current_thd, empty_lex_str, Lex->sphead->instructions()); + Lex->spcont->push_label(thd, empty_lex_str, Lex->sphead->instructions()); } case_stmt_body else_clause_opt @@ -4908,7 +4909,7 @@ partition_entry: LEX *lex= Lex; if (!lex->part_info) { - my_parse_error(ER(ER_PARTITION_ENTRY_ERROR)); + my_parse_error(ER_THD(thd, ER_PARTITION_ENTRY_ERROR)); MYSQL_YYABORT; } /* @@ -4963,7 +4964,7 @@ opt_key_algo: Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_55; break; default: - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -5092,7 +5093,7 @@ part_func_expr: lex->safe_to_cache_query= 1; if (not_corr_func) { - my_parse_error(ER(ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR)); + my_parse_error(ER_THD(thd, ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR)); MYSQL_YYABORT; } $$=$1; @@ -5141,7 +5142,7 @@ part_defs: if (part_info->num_parts != count_curr_parts) { - my_parse_error(ER(ER_PARTITION_WRONG_NO_PART_ERROR)); + my_parse_error(ER_THD(thd, ER_PARTITION_WRONG_NO_PART_ERROR)); MYSQL_YYABORT; } } @@ -5259,7 +5260,7 @@ part_func_max: part_info->num_columns != 1U) { part_info->print_debug("Kilroy II", NULL); - my_parse_error(ER(ER_PARTITION_COLUMN_LIST_ERROR)); + my_parse_error(ER_THD(thd, ER_PARTITION_COLUMN_LIST_ERROR)); MYSQL_YYABORT; } else @@ -5290,7 +5291,7 @@ part_values_in: part_info->num_columns > MAX_REF_PARTS) { part_info->print_debug("Kilroy III", NULL); - my_parse_error(ER(ER_PARTITION_COLUMN_LIST_ERROR)); + my_parse_error(ER_THD(thd, ER_PARTITION_COLUMN_LIST_ERROR)); MYSQL_YYABORT; } /* @@ -5311,7 +5312,7 @@ part_values_in: partition_info *part_info= Lex->part_info; if (part_info->num_columns < 2U) { - my_parse_error(ER(ER_ROW_SINGLE_PARTITION_FIELD_ERROR)); + my_parse_error(ER_THD(thd, ER_ROW_SINGLE_PARTITION_FIELD_ERROR)); MYSQL_YYABORT; } } @@ -5352,7 +5353,7 @@ part_value_item: error. */ part_info->print_debug("Kilroy I", NULL); - my_parse_error(ER(ER_PARTITION_COLUMN_LIST_ERROR)); + my_parse_error(ER_THD(thd, ER_PARTITION_COLUMN_LIST_ERROR)); MYSQL_YYABORT; } part_info->curr_list_object= 0; @@ -5370,7 +5371,7 @@ part_value_expr_item: partition_info *part_info= Lex->part_info; if (part_info->part_type == LIST_PARTITION) { - my_parse_error(ER(ER_MAXVALUE_IN_VALUES_IN)); + my_parse_error(ER_THD(thd, ER_MAXVALUE_IN_VALUES_IN)); MYSQL_YYABORT; } if (part_info->add_max_value()) @@ -5386,7 +5387,7 @@ part_value_expr_item: if (!lex->safe_to_cache_query) { - my_parse_error(ER(ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR)); + my_parse_error(ER_THD(thd, ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR)); MYSQL_YYABORT; } if (part_info->add_column_list_value(thd, part_expr)) @@ -5408,7 +5409,7 @@ opt_sub_partition: We come here when we have defined subpartitions on the first partition but not on all the subsequent partitions. */ - my_parse_error(ER(ER_PARTITION_WRONG_NO_SUBPART_ERROR)); + my_parse_error(ER_THD(thd, ER_PARTITION_WRONG_NO_SUBPART_ERROR)); MYSQL_YYABORT; } } @@ -5420,7 +5421,7 @@ opt_sub_partition: if (part_info->num_subparts != part_info->count_curr_subparts) { - my_parse_error(ER(ER_PARTITION_WRONG_NO_SUBPART_ERROR)); + my_parse_error(ER_THD(thd, ER_PARTITION_WRONG_NO_SUBPART_ERROR)); MYSQL_YYABORT; } } @@ -5428,7 +5429,7 @@ opt_sub_partition: { if (part_info->partitions.elements > 1) { - my_parse_error(ER(ER_PARTITION_WRONG_NO_SUBPART_ERROR)); + my_parse_error(ER_THD(thd, ER_PARTITION_WRONG_NO_SUBPART_ERROR)); MYSQL_YYABORT; } part_info->num_subparts= part_info->count_curr_subparts; @@ -5462,7 +5463,7 @@ sub_part_definition: the second partition (the current partition processed have already been put into the partitions list. */ - my_parse_error(ER(ER_PARTITION_WRONG_NO_SUBPART_ERROR)); + my_parse_error(ER_THD(thd, ER_PARTITION_WRONG_NO_SUBPART_ERROR)); MYSQL_YYABORT; } if (!sub_p_elem || @@ -5672,7 +5673,7 @@ create_table_option: Lex->create_info.table_options|= HA_OPTION_PACK_KEYS; break; default: - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS; @@ -5693,7 +5694,7 @@ create_table_option: Lex->create_info.stats_auto_recalc= HA_STATS_AUTO_RECALC_ON; break; default: - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } Lex->create_info.used_fields|= HA_CREATE_USED_STATS_AUTO_RECALC; @@ -5713,7 +5714,7 @@ create_table_option: Lex->create_info.table_options|= HA_OPTION_STATS_PERSISTENT; break; default: - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } Lex->create_info.used_fields|= HA_CREATE_USED_STATS_PERSISTENT; @@ -5736,7 +5737,7 @@ create_table_option: we can store the higher bits from stats_sample_pages in .frm too. */ if ($3 == 0 || $3 > 0xffff) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } Lex->create_info.stats_sample_pages=$3; @@ -5906,7 +5907,7 @@ storage_engines: $$= 0; push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_STORAGE_ENGINE, - ER(ER_UNKNOWN_STORAGE_ENGINE), + ER_THD(thd, ER_UNKNOWN_STORAGE_ENGINE), $1.str); } } @@ -6083,7 +6084,7 @@ field_spec: LEX *lex=Lex; Create_field *f= new Create_field(); - if (check_string_char_length(&$1, "", NAME_CHAR_LEN, + if (check_string_char_length(&$1, 0, NAME_CHAR_LEN, system_charset_info, 1)) { my_error(ER_TOO_LONG_IDENT, MYF(0), $1.str); @@ -6176,7 +6177,7 @@ parse_vcol_expr: */ if (!Lex->parse_vcol_expr) { - my_message(ER_SYNTAX_ERROR, ER(ER_SYNTAX_ERROR), MYF(0)); + my_message(ER_SYNTAX_ERROR, ER_THD(thd, ER_SYNTAX_ERROR), MYF(0)); MYSQL_YYABORT; } } @@ -6296,7 +6297,7 @@ field_type: my_snprintf(buff, sizeof(buff), "YEAR(%lu)", length); push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_WARN_DEPRECATED_SYNTAX, - ER(ER_WARN_DEPRECATED_SYNTAX), + ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX), buff, "YEAR(4)"); } } @@ -6721,7 +6722,7 @@ ws_nweights: { if ($2 == 0) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -7230,7 +7231,7 @@ alter: { if (!($7 || $8 || $9 || $10 || $11)) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } /* @@ -7845,7 +7846,7 @@ start: if (($3 & MYSQL_START_TRANS_OPT_READ_WRITE) && ($3 & MYSQL_START_TRANS_OPT_READ_ONLY)) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } lex->start_transaction_opt= $3; @@ -7917,7 +7918,7 @@ slave_until: (lex->mi.relay_log_name && lex->mi.relay_log_pos))) { my_message(ER_BAD_SLAVE_UNTIL_COND, - ER(ER_BAD_SLAVE_UNTIL_COND), MYF(0)); + ER_THD(thd, ER_BAD_SLAVE_UNTIL_COND), MYF(0)); MYSQL_YYABORT; } } @@ -10017,7 +10018,7 @@ function_call_generic: { if (lex->current_select->inc_in_sum_expr()) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -10360,7 +10361,7 @@ variable_aux: /* disallow "SELECT @@global.global.variable" */ if ($3.str && $4.str && check_reserved_words(&$3)) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } if (!($$= get_system_var(thd, $2, $3, $4))) @@ -10416,7 +10417,7 @@ in_sum_expr: LEX *lex= Lex; if (lex->current_select->inc_in_sum_expr()) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -10543,7 +10544,7 @@ table_ref: LEX *lex= Lex; if (!($$= lex->current_select->nest_last_join(lex->thd))) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -10761,7 +10762,7 @@ table_factor: { if (sel->set_braces(1)) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -10833,7 +10834,7 @@ table_factor: Tables with or without joins within parentheses cannot have aliases, and we ruled out derived tables above. */ - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } else @@ -10869,7 +10870,7 @@ select_derived_union: { if ($1 && $2) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -10892,7 +10893,7 @@ select_derived_union: { if ($1 != NULL) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -10906,13 +10907,13 @@ select_init2_derived: SELECT_LEX * sel= lex->current_select; if (lex->current_select->set_braces(0)) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } if (sel->linkage == UNION_TYPE && sel->master_unit()->first_select()->braces) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -10952,7 +10953,7 @@ select_derived: MYSQL_YYABORT; if (!$3 && $$) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -10965,7 +10966,7 @@ select_derived2: if (!lex->expr_allows_subselect || lex->sql_command == (int)SQLCOM_PURGE) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || @@ -11002,7 +11003,7 @@ select_derived_init: if (!sel->embedding || sel->end_nested_join(lex->thd)) { /* we are not in parentheses */ - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } embedding= Select->embedding; @@ -11515,8 +11516,8 @@ delete_limit_clause: Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT); sel->explicit_limit= 1; } - | LIMIT ROWS_SYM EXAMINED_SYM { my_parse_error(ER(ER_SYNTAX_ERROR)); MYSQL_YYABORT; } - | LIMIT limit_option ROWS_SYM EXAMINED_SYM { my_parse_error(ER(ER_SYNTAX_ERROR)); MYSQL_YYABORT; } + | LIMIT ROWS_SYM EXAMINED_SYM { my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } + | LIMIT limit_option ROWS_SYM EXAMINED_SYM { my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } ; int_num: @@ -11560,7 +11561,7 @@ real_ulonglong_num: dec_num_error: dec_num - { my_parse_error(ER(ER_ONLY_INTEGERS_ALLOWED)); } + { my_parse_error(ER_THD(thd, ER_ONLY_INTEGERS_ALLOWED)); } ; dec_num: @@ -12718,12 +12719,12 @@ show_param: ST_SCHEMA_TABLE *table= find_schema_table(thd, $1.str); if (!table || !table->old_format) { - my_parse_error(ER(ER_SYNTAX_ERROR), $2); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR), $2); MYSQL_YYABORT; } if (lex->wild && table->idx_field1 < 0) { - my_parse_error(ER(ER_SYNTAX_ERROR), $3); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR), $3); MYSQL_YYABORT; } if (make_schema_select(thd, Lex->current_select, table)) @@ -12929,7 +12930,7 @@ flush_lock: { if (Lex->query_tables == NULL) // Table list can't be empty { - my_parse_error(ER(ER_NO_TABLES_USED)); + my_parse_error(ER_THD(thd, ER_NO_TABLES_USED)); MYSQL_YYABORT; } Lex->type|= REFRESH_FOR_EXPORT; @@ -13000,7 +13001,7 @@ flush_option: ST_SCHEMA_TABLE *table= find_schema_table(thd, $1.str); if (!table || !table->reset_table) { - my_parse_error(ER(ER_SYNTAX_ERROR), $2); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR), $2); MYSQL_YYABORT; } Lex->view_list.push_back( @@ -13454,7 +13455,7 @@ param_marker: item= new (thd->mem_root) Item_param(lip->get_tok_start() - query_start); if (!($$= item) || lex->param_list.push_back(item)) { - my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); + my_message(ER_OUT_OF_RESOURCES, ER_THD(thd, ER_OUT_OF_RESOURCES), MYF(0)); MYSQL_YYABORT; } } @@ -13747,7 +13748,7 @@ simple_ident_q: DBUG_ASSERT(!new_row || (lex->trg_chistics.event == TRG_EVENT_INSERT || lex->trg_chistics.event == TRG_EVENT_UPDATE)); - const bool read_only= + const bool tmp_read_only= !(new_row && lex->trg_chistics.action_time == TRG_ACTION_BEFORE); trg_fld= new (thd->mem_root) Item_trigger_field(thd, Lex->current_context(), @@ -13756,7 +13757,7 @@ simple_ident_q: Item_trigger_field::OLD_ROW, $3.str, SELECT_ACL, - read_only); + tmp_read_only); if (trg_fld == NULL) MYSQL_YYABORT; @@ -14034,7 +14035,7 @@ user_maybe_role: $$->plugin= empty_lex_str; $$->auth= empty_lex_str; - if (check_string_char_length(&$$->user, ER(ER_USERNAME), + if (check_string_char_length(&$$->user, ER_USERNAME, username_char_length, system_charset_info, 0)) MYSQL_YYABORT; @@ -14048,7 +14049,7 @@ user_maybe_role: $$->plugin= empty_lex_str; $$->auth= empty_lex_str; - if (check_string_char_length(&$$->user, ER(ER_USERNAME), + if (check_string_char_length(&$$->user, ER_USERNAME, username_char_length, system_charset_info, 0) || check_host_name(&$$->host)) @@ -14645,7 +14646,7 @@ option_value_following_option_type: Not in trigger assigning value to new row, and option_type preceding local variable is illegal. */ - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } } @@ -14726,7 +14727,7 @@ option_value_no_option_type: if (spc && spc->find_variable(names, false)) my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), names.str); else - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } @@ -14830,7 +14831,7 @@ internal_variable_name: LEX *lex= Lex; if (check_reserved_words(&$1)) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } if (lex->sphead && lex->sphead->m_type == TYPE_ENUM_TRIGGER && @@ -15177,7 +15178,7 @@ revoke_command: LEX *lex= Lex; if (lex->columns.elements) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } lex->sql_command= SQLCOM_REVOKE; @@ -15188,7 +15189,7 @@ revoke_command: LEX *lex= Lex; if (lex->columns.elements) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } lex->sql_command= SQLCOM_REVOKE; @@ -15239,7 +15240,7 @@ grant_command: LEX *lex= Lex; if (lex->columns.elements) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } lex->sql_command= SQLCOM_GRANT; @@ -15251,7 +15252,7 @@ grant_command: LEX *lex= Lex; if (lex->columns.elements) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } lex->sql_command= SQLCOM_GRANT; @@ -15324,7 +15325,7 @@ grant_role: $$->plugin= empty_lex_str; $$->auth= empty_lex_str; - if (check_string_char_length(&$$->user, ER(ER_USERNAME), + if (check_string_char_length(&$$->user, ER_USERNAME, username_char_length, system_charset_info, 0)) MYSQL_YYABORT; @@ -15452,7 +15453,7 @@ grant_ident: else if (lex->columns.elements) { my_message(ER_ILLEGAL_GRANT_FOR_TABLE, - ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); + ER_THD(thd, ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); MYSQL_YYABORT; } } @@ -15465,7 +15466,7 @@ grant_ident: else if (lex->columns.elements) { my_message(ER_ILLEGAL_GRANT_FOR_TABLE, - ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); + ER_THD(thd, ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); MYSQL_YYABORT; } } @@ -15478,7 +15479,7 @@ grant_ident: else if (lex->columns.elements) { my_message(ER_ILLEGAL_GRANT_FOR_TABLE, - ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); + ER_THD(thd, ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); MYSQL_YYABORT; } } @@ -15880,7 +15881,7 @@ subselect_start: if (!lex->expr_allows_subselect || lex->sql_command == (int)SQLCOM_PURGE) { - my_parse_error(ER(ER_SYNTAX_ERROR)); + my_parse_error(ER_THD(thd, ER_SYNTAX_ERROR)); MYSQL_YYABORT; } /* @@ -16330,7 +16331,7 @@ sf_tail: push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_NATIVE_FCT_NAME_COLLISION, - ER(ER_NATIVE_FCT_NAME_COLLISION), + ER_THD(thd, ER_NATIVE_FCT_NAME_COLLISION), sp->m_name.str); } sp->restore_thd_mem_root(thd); diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 889a88db98b..561b2e1ab9f 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -1267,7 +1267,8 @@ static bool check_max_allowed_packet(sys_var *self, THD *thd, set_var *var) if (val < (longlong) global_system_variables.net_buffer_length) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_OPTION_BELOW_LIMIT, ER(WARN_OPTION_BELOW_LIMIT), + WARN_OPTION_BELOW_LIMIT, + ER_THD(thd, WARN_OPTION_BELOW_LIMIT), "max_allowed_packet", "net_buffer_length"); } return false; @@ -2171,7 +2172,8 @@ static bool check_net_buffer_length(sys_var *self, THD *thd, set_var *var) if (val > (longlong) global_system_variables.max_allowed_packet) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_OPTION_BELOW_LIMIT, ER(WARN_OPTION_BELOW_LIMIT), + WARN_OPTION_BELOW_LIMIT, + ER_THD(thd, WARN_OPTION_BELOW_LIMIT), "max_allowed_packet", "net_buffer_length"); } return false; @@ -2355,7 +2357,7 @@ static bool fix_optimizer_switch(sys_var *self, THD *thd, if (sv->optimizer_switch & deprecated_ENGINE_CONDITION_PUSHDOWN) push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT, - ER(ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT), + ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT), "engine_condition_pushdown=on"); return false; } @@ -2702,7 +2704,7 @@ static bool fix_query_cache_size(sys_var *self, THD *thd, enum_var_type type) */ if (query_cache_size != new_cache_size) push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_QC_RESIZE, ER(ER_WARN_QC_RESIZE), + ER_WARN_QC_RESIZE, ER_THD(thd, ER_WARN_QC_RESIZE), query_cache_size, new_cache_size); query_cache_size= new_cache_size; diff --git a/sql/table.cc b/sql/table.cc index 1f9247e28f2..5b31ea0de3e 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -150,7 +150,7 @@ View_creation_ctx * View_creation_ctx::create(THD *thd, { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_VIEW_NO_CREATION_CTX, - ER(ER_VIEW_NO_CREATION_CTX), + ER_THD(thd, ER_VIEW_NO_CREATION_CTX), (const char *) view->db, (const char *) view->table_name); @@ -184,7 +184,7 @@ View_creation_ctx * View_creation_ctx::create(THD *thd, push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_VIEW_INVALID_CREATION_CTX, - ER(ER_VIEW_INVALID_CREATION_CTX), + ER_THD(thd, ER_VIEW_INVALID_CREATION_CTX), (const char *) view->db, (const char *) view->table_name); } @@ -2740,8 +2740,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, We are using only a prefix of the column as a key: Create a new field for the key part that matches the index */ - field= key_part->field=field->new_field(&outparam->mem_root, - outparam, 0); + field= key_part->field=field->make_new_field(&outparam->mem_root, + outparam, 0); field->field_length= key_part->length; } } @@ -3694,13 +3694,14 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def) if (table->s->fields != table_def->count) { + THD *thd= current_thd; DBUG_PRINT("info", ("Column count has changed, checking the definition")); /* previous MySQL version */ if (MYSQL_VERSION_ID > table->s->mysql_version) { report_error(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE, - ER(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE), + ER_THD(thd, ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE), table->alias.c_ptr(), table_def->count, table->s->fields, static_cast<int>(table->s->mysql_version), MYSQL_VERSION_ID); @@ -3709,7 +3710,7 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def) else if (MYSQL_VERSION_ID == table->s->mysql_version) { report_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2, - ER(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2), + ER_THD(thd, ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2), table->s->db.str, table->s->table_name.str, table_def->count, table->s->fields); DBUG_RETURN(TRUE); @@ -4680,7 +4681,8 @@ int TABLE_LIST::view_check_option(THD *thd, bool ignore_failure) if (ignore_failure) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_VIEW_CHECK_FAILED, ER(ER_VIEW_CHECK_FAILED), + ER_VIEW_CHECK_FAILED, + ER_THD(thd, ER_VIEW_CHECK_FAILED), main_view->view_db.str, main_view->view_name.str); return(VIEW_CHECK_SKIP); } @@ -4976,7 +4978,7 @@ bool TABLE_LIST::prepare_view_security_context(THD *thd) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_NO_SUCH_USER, - ER(ER_NO_SUCH_USER), + ER_THD(thd, ER_NO_SUCH_USER), definer.user.str, definer.host.str); } else @@ -4996,7 +4998,8 @@ bool TABLE_LIST::prepare_view_security_context(THD *thd) my_error(ER_ACCESS_DENIED_ERROR, MYF(0), thd->security_ctx->priv_user, thd->security_ctx->priv_host, - (thd->password ? ER(ER_YES) : ER(ER_NO))); + (thd->password ? ER_THD(thd, ER_YES) : + ER_THD(thd, ER_NO))); } DBUG_RETURN(TRUE); } diff --git a/sql/table_cache.h b/sql/table_cache.h index 4dea5a98772..2c5b0fc45a2 100644 --- a/sql/table_cache.h +++ b/sql/table_cache.h @@ -54,9 +54,9 @@ public: TDC_element() {} - TDC_element(const char *key, uint key_length) : m_key_length(key_length) + TDC_element(const char *key_arg, uint key_length) : m_key_length(key_length) { - memcpy(m_key, key, key_length); + memcpy(m_key, key_arg, key_length); } diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc index 9786f1a6942..b82d29e51f4 100644 --- a/sql/thr_malloc.cc +++ b/sql/thr_malloc.cc @@ -54,8 +54,7 @@ extern "C" { /* Skip writing to the error log to avoid mtr complaints */ DBUG_EXECUTE_IF("simulate_out_of_memory", return;); - sql_print_error("%s", ER(ER_OUT_OF_RESOURCES)); - + sql_print_error("%s", ER_THD_OR_DEFAULT(thd, ER_OUT_OF_RESOURCES)); } } diff --git a/sql/transaction.cc b/sql/transaction.cc index 8f0cbcc5eb4..8b188709ce6 100644 --- a/sql/transaction.cc +++ b/sql/transaction.cc @@ -657,7 +657,7 @@ bool trans_rollback_to_savepoint(THD *thd, LEX_STRING name) !thd->slave_thread) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARNING_NOT_COMPLETE_ROLLBACK, - ER(ER_WARNING_NOT_COMPLETE_ROLLBACK)); + ER_THD(thd, ER_WARNING_NOT_COMPLETE_ROLLBACK)); thd->transaction.savepoints= sv; diff --git a/sql/unireg.cc b/sql/unireg.cc index 7e4a64189d9..ad35368a755 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -501,7 +501,7 @@ static bool pack_header(THD *thd, uchar *forminfo, if (create_fields.elements > MAX_FIELDS) { - my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0)); + my_message(ER_TOO_MANY_FIELDS, ER_THD(thd, ER_TOO_MANY_FIELDS), MYF(0)); DBUG_RETURN(1); } @@ -631,7 +631,7 @@ static bool pack_header(THD *thd, uchar *forminfo, n_length+int_length+com_length+vcol_info_length > 65535L || int_count > 255) { - my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0)); + my_message(ER_TOO_MANY_FIELDS, ER_THD(thd, ER_TOO_MANY_FIELDS), MYF(0)); DBUG_RETURN(1); } @@ -825,9 +825,11 @@ static bool pack_fields(uchar *buff, List<Create_field> &create_fields, } } - if(!sep) /* disaster, enum uses all characters, none left as separator */ + if (!sep) { - my_message(ER_WRONG_FIELD_TERMINATORS,ER(ER_WRONG_FIELD_TERMINATORS), + /* disaster, enum uses all characters, none left as separator */ + my_message(ER_WRONG_FIELD_TERMINATORS, + ER(ER_WRONG_FIELD_TERMINATORS), MYF(0)); DBUG_RETURN(1); } @@ -974,9 +976,11 @@ static bool make_empty_rec(THD *thd, uchar *buff, uint table_options, regfield->store((longlong) 1, TRUE); } else if (type == Field::YES) // Old unireg type - regfield->store(ER(ER_YES),(uint) strlen(ER(ER_YES)),system_charset_info); + regfield->store(ER_THD(thd, ER_YES),(uint) strlen(ER_THD(thd, ER_YES)), + system_charset_info); else if (type == Field::NO) // Old unireg type - regfield->store(ER(ER_NO), (uint) strlen(ER(ER_NO)),system_charset_info); + regfield->store(ER_THD(thd, ER_NO), (uint) strlen(ER_THD(thd, ER_NO)), + system_charset_info); else regfield->reset(); } diff --git a/sql/unireg.h b/sql/unireg.h index 25335d11e4a..8e73fd8da18 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -49,6 +49,7 @@ #define ER(X) CURRENT_THD_ERRMSGS[(X) - ER_ERROR_FIRST] #define ER_DEFAULT(X) DEFAULT_ERRMSGS[(X) - ER_ERROR_FIRST] #define ER_SAFE(X) (((X) >= ER_ERROR_FIRST && (X) <= ER_ERROR_LAST) ? ER(X) : "Invalid error code") +#define ER_SAFE_THD(T,X) (((X) >= ER_ERROR_FIRST && (X) <= ER_ERROR_LAST) ? ER_THD(T,X) : "Invalid error code") #define ER_THD(thd,X) ((thd)->variables.lc_messages->errmsgs->errmsgs[(X) - \ ER_ERROR_FIRST]) #define ER_THD_OR_DEFAULT(thd,X) ((thd) ? ER_THD(thd, X) : ER_DEFAULT(X)) |