mirror of
https://github.com/MariaDB/server.git
synced 2025-01-28 01:34:17 +01:00
cleanup: RAII helper for changing thd->count_cuted_rows
This commit is contained in:
parent
08b0b70daa
commit
00f54b56b1
12 changed files with 42 additions and 64 deletions
12
sql/field.cc
12
sql/field.cc
|
@ -1867,21 +1867,15 @@ bool Field::compatible_field_size(uint field_metadata,
|
|||
int Field::store(const char *to, size_t length, CHARSET_INFO *cs,
|
||||
enum_check_fields check_level)
|
||||
{
|
||||
int res;
|
||||
THD *thd= get_thd();
|
||||
enum_check_fields old_check_level= thd->count_cuted_fields;
|
||||
thd->count_cuted_fields= check_level;
|
||||
res= store(to, length, cs);
|
||||
thd->count_cuted_fields= old_check_level;
|
||||
return res;
|
||||
Check_level_instant_set check_level_save(get_thd(), check_level);
|
||||
return store(to, length, cs);
|
||||
}
|
||||
|
||||
|
||||
int Field::store_timestamp(my_time_t ts, ulong sec_part)
|
||||
{
|
||||
MYSQL_TIME ltime;
|
||||
THD *thd= get_thd();
|
||||
thd->timestamp_to_TIME(<ime, ts, sec_part, 0);
|
||||
get_thd()->timestamp_to_TIME(<ime, ts, sec_part, 0);
|
||||
return store_time_dec(<ime, decimals());
|
||||
}
|
||||
|
||||
|
|
|
@ -3292,7 +3292,6 @@ int handler::update_auto_increment()
|
|||
THD *thd= table->in_use;
|
||||
struct system_variables *variables= &thd->variables;
|
||||
int result=0, tmp;
|
||||
enum enum_check_fields save_count_cuted_fields;
|
||||
DBUG_ENTER("handler::update_auto_increment");
|
||||
|
||||
/*
|
||||
|
@ -3434,10 +3433,10 @@ int handler::update_auto_increment()
|
|||
nr, append ? nb_reserved_values : 0));
|
||||
|
||||
/* Store field without warning (Warning will be printed by insert) */
|
||||
save_count_cuted_fields= thd->count_cuted_fields;
|
||||
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
|
||||
tmp= table->next_number_field->store((longlong)nr, TRUE);
|
||||
thd->count_cuted_fields= save_count_cuted_fields;
|
||||
{
|
||||
Check_level_instant_set check_level_save(thd, CHECK_FIELD_IGNORE);
|
||||
tmp= table->next_number_field->store((longlong)nr, TRUE);
|
||||
}
|
||||
|
||||
if (unlikely(tmp)) // Out of range value in store
|
||||
{
|
||||
|
|
11
sql/item.cc
11
sql/item.cc
|
@ -1620,18 +1620,13 @@ int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
|
|||
int res;
|
||||
TABLE *table= field->table;
|
||||
THD *thd= table->in_use;
|
||||
enum_check_fields tmp= thd->count_cuted_fields;
|
||||
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
|
||||
sql_mode_t sql_mode= thd->variables.sql_mode;
|
||||
Check_level_instant_set check_level_save(thd, CHECK_FIELD_IGNORE);
|
||||
Sql_mode_save sql_mode(thd);
|
||||
thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
|
||||
thd->variables.sql_mode|= MODE_INVALID_DATES;
|
||||
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
|
||||
|
||||
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
|
||||
res= save_in_field(field, no_conversions);
|
||||
|
||||
thd->count_cuted_fields= tmp;
|
||||
dbug_tmp_restore_column_map(table->write_set, old_map);
|
||||
thd->variables.sql_mode= sql_mode;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -343,19 +343,18 @@ static bool convert_const_to_int(THD *thd, Item_field *field_item,
|
|||
if ((*item)->const_item() && !(*item)->is_expensive())
|
||||
{
|
||||
TABLE *table= field->table;
|
||||
sql_mode_t orig_sql_mode= thd->variables.sql_mode;
|
||||
enum_check_fields orig_count_cuted_fields= thd->count_cuted_fields;
|
||||
Sql_mode_save sql_mode(thd);
|
||||
Check_level_instant_set check_level_save(thd, CHECK_FIELD_IGNORE);
|
||||
my_bitmap_map *old_maps[2] = { NULL, NULL };
|
||||
ulonglong UNINIT_VAR(orig_field_val); /* original field value if valid */
|
||||
|
||||
/* table->read_set may not be set if we come here from a CREATE TABLE */
|
||||
if (table && table->read_set)
|
||||
dbug_tmp_use_all_columns(table, old_maps,
|
||||
dbug_tmp_use_all_columns(table, old_maps,
|
||||
table->read_set, table->write_set);
|
||||
/* For comparison purposes allow invalid dates like 2000-01-32 */
|
||||
thd->variables.sql_mode= (orig_sql_mode & ~MODE_NO_ZERO_DATE) |
|
||||
thd->variables.sql_mode= (thd->variables.sql_mode & ~MODE_NO_ZERO_DATE) |
|
||||
MODE_INVALID_DATES;
|
||||
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
|
||||
|
||||
/*
|
||||
Store the value of the field/constant because the call to save_in_field
|
||||
|
@ -392,8 +391,6 @@ static bool convert_const_to_int(THD *thd, Item_field *field_item,
|
|||
/* orig_field_val must be a valid value that can be restored back. */
|
||||
DBUG_ASSERT(!result);
|
||||
}
|
||||
thd->variables.sql_mode= orig_sql_mode;
|
||||
thd->count_cuted_fields= orig_count_cuted_fields;
|
||||
if (table && table->read_set)
|
||||
dbug_tmp_restore_column_maps(table->read_set, table->write_set, old_maps);
|
||||
}
|
||||
|
|
|
@ -1180,8 +1180,6 @@ Sp_handler::sp_create_routine(THD *thd, const sp_head *sp) const
|
|||
|
||||
CHARSET_INFO *db_cs= get_default_db_collation(thd, sp->m_db.str);
|
||||
|
||||
enum_check_fields saved_count_cuted_fields;
|
||||
|
||||
bool store_failed= FALSE;
|
||||
DBUG_ENTER("sp_create_routine");
|
||||
DBUG_PRINT("enter", ("type: %s name: %.*s",
|
||||
|
@ -1215,8 +1213,7 @@ Sp_handler::sp_create_routine(THD *thd, const sp_head *sp) const
|
|||
/* Reset sql_mode during data dictionary operations. */
|
||||
thd->variables.sql_mode= 0;
|
||||
|
||||
saved_count_cuted_fields= thd->count_cuted_fields;
|
||||
thd->count_cuted_fields= CHECK_FIELD_WARN;
|
||||
Check_level_instant_set check_level_save(thd, CHECK_FIELD_WARN);
|
||||
|
||||
if (!(table= open_proc_table_for_update(thd)))
|
||||
{
|
||||
|
@ -1476,7 +1473,6 @@ log:
|
|||
ret= FALSE;
|
||||
|
||||
done:
|
||||
thd->count_cuted_fields= saved_count_cuted_fields;
|
||||
thd->variables.sql_mode= saved_mode;
|
||||
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
|
||||
DBUG_RETURN(ret);
|
||||
|
|
|
@ -6581,6 +6581,23 @@ class Switch_to_definer_security_ctx
|
|||
};
|
||||
|
||||
|
||||
class Check_level_instant_set
|
||||
{
|
||||
THD *m_thd;
|
||||
enum_check_fields m_check_level;
|
||||
public:
|
||||
Check_level_instant_set(THD *thd, enum_check_fields temporary_value)
|
||||
:m_thd(thd), m_check_level(thd->count_cuted_fields)
|
||||
{
|
||||
thd->count_cuted_fields= temporary_value;
|
||||
}
|
||||
~Check_level_instant_set()
|
||||
{
|
||||
m_thd->count_cuted_fields= m_check_level;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
This class resembles the SQL Standard schema qualified object name:
|
||||
<schema qualified name> ::= [ <schema name> <period> ] <qualified identifier>
|
||||
|
|
|
@ -23313,8 +23313,7 @@ cmp_buffer_with_ref(THD *thd, TABLE *table, TABLE_REF *tab_ref)
|
|||
bool
|
||||
cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref)
|
||||
{
|
||||
enum enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
|
||||
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
|
||||
Check_level_instant_set check_level_save(thd, CHECK_FIELD_IGNORE);
|
||||
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
|
||||
bool result= 0;
|
||||
|
||||
|
@ -23326,7 +23325,6 @@ cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref)
|
|||
break;
|
||||
}
|
||||
}
|
||||
thd->count_cuted_fields= save_count_cuted_fields;
|
||||
dbug_tmp_restore_column_map(table->write_set, old_map);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1872,18 +1872,11 @@ public:
|
|||
{
|
||||
enum store_key_result result;
|
||||
THD *thd= to_field->table->in_use;
|
||||
enum_check_fields saved_count_cuted_fields= thd->count_cuted_fields;
|
||||
sql_mode_t orig_sql_mode= thd->variables.sql_mode;
|
||||
Check_level_instant_set check_level_save(thd, CHECK_FIELD_IGNORE);
|
||||
Sql_mode_save sql_mode(thd);
|
||||
thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
|
||||
thd->variables.sql_mode|= MODE_INVALID_DATES;
|
||||
|
||||
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
|
||||
|
||||
result= copy_inner();
|
||||
|
||||
thd->count_cuted_fields= saved_count_cuted_fields;
|
||||
thd->variables.sql_mode= orig_sql_mode;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -3695,7 +3695,7 @@ static bool show_status_array(THD *thd, const char *wild,
|
|||
char name_buffer[NAME_CHAR_LEN];
|
||||
int len;
|
||||
SHOW_VAR tmp, *var;
|
||||
enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
|
||||
Check_level_instant_set check_level_save(thd, CHECK_FIELD_IGNORE);
|
||||
bool res= FALSE;
|
||||
CHARSET_INFO *charset= system_charset_info;
|
||||
DBUG_ENTER("show_status_array");
|
||||
|
@ -3818,7 +3818,6 @@ static bool show_status_array(THD *thd, const char *wild,
|
|||
}
|
||||
}
|
||||
end:
|
||||
thd->count_cuted_fields= save_count_cuted_fields;
|
||||
DBUG_RETURN(res);
|
||||
}
|
||||
|
||||
|
@ -4543,8 +4542,7 @@ fill_schema_table_by_open(THD *thd, MEM_ROOT *mem_root,
|
|||
Open_tables_backup *open_tables_state_backup,
|
||||
bool can_deadlock)
|
||||
{
|
||||
Query_arena i_s_arena(mem_root,
|
||||
Query_arena::STMT_CONVENTIONAL_EXECUTION),
|
||||
Query_arena i_s_arena(mem_root, Query_arena::STMT_CONVENTIONAL_EXECUTION),
|
||||
backup_arena, *old_arena;
|
||||
LEX *old_lex= thd->lex, temp_lex, *lex;
|
||||
LEX_CSTRING db_name, table_name;
|
||||
|
@ -5058,12 +5056,9 @@ end:
|
|||
class Warnings_only_error_handler : public Internal_error_handler
|
||||
{
|
||||
public:
|
||||
bool handle_condition(THD *thd,
|
||||
uint sql_errno,
|
||||
const char* sqlstate,
|
||||
bool handle_condition(THD *thd, uint sql_errno, const char* sqlstate,
|
||||
Sql_condition::enum_warning_level *level,
|
||||
const char* msg,
|
||||
Sql_condition ** cond_hdl)
|
||||
const char* msg, Sql_condition ** cond_hdl)
|
||||
{
|
||||
if (sql_errno == ER_TRG_NO_DEFINER || sql_errno == ER_TRG_NO_CREATION_CTX)
|
||||
return true;
|
||||
|
|
|
@ -2831,7 +2831,6 @@ int read_statistics_for_table(THD *thd, TABLE *table, TABLE_LIST *stat_tables)
|
|||
Field **field_ptr;
|
||||
KEY *key_info, *key_info_end;
|
||||
TABLE_SHARE *table_share= table->s;
|
||||
enum_check_fields old_check_level= thd->count_cuted_fields;
|
||||
|
||||
DBUG_ENTER("read_statistics_for_table");
|
||||
DEBUG_SYNC(thd, "statistics_mem_alloc_start1");
|
||||
|
@ -2847,7 +2846,7 @@ int read_statistics_for_table(THD *thd, TABLE *table, TABLE_LIST *stat_tables)
|
|||
}
|
||||
|
||||
/* Don't write warnings for internal field conversions */
|
||||
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
|
||||
Check_level_instant_set check_level_save(thd, CHECK_FIELD_IGNORE);
|
||||
|
||||
/* Read statistics from the statistical table table_stats */
|
||||
Table_statistics *read_stats= table_share->stats_cb.table_stats;
|
||||
|
@ -2929,7 +2928,6 @@ int read_statistics_for_table(THD *thd, TABLE *table, TABLE_LIST *stat_tables)
|
|||
}
|
||||
}
|
||||
|
||||
thd->count_cuted_fields= old_check_level;
|
||||
table_share->stats_cb.end_stats_load();
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
|
|
@ -9939,16 +9939,14 @@ do_continue:;
|
|||
if (use_inplace)
|
||||
{
|
||||
table->s->frm_image= &frm;
|
||||
enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
|
||||
/*
|
||||
Set the truncated column values of thd as warning
|
||||
for alter table.
|
||||
*/
|
||||
thd->count_cuted_fields = CHECK_FIELD_WARN;
|
||||
Check_level_instant_set check_level_save(thd, CHECK_FIELD_WARN);
|
||||
int res= mysql_inplace_alter_table(thd, table_list, table, altered_table,
|
||||
&ha_alter_info, inplace_supported,
|
||||
&target_mdl_request, &alter_ctx);
|
||||
thd->count_cuted_fields= save_count_cuted_fields;
|
||||
my_free(const_cast<uchar*>(frm.str));
|
||||
|
||||
if (res)
|
||||
|
|
|
@ -1032,7 +1032,6 @@ static bool make_empty_rec(THD *thd, uchar *buff, uint table_options,
|
|||
TABLE table;
|
||||
TABLE_SHARE share;
|
||||
Create_field *field;
|
||||
enum_check_fields old_count_cuted_fields= thd->count_cuted_fields;
|
||||
DBUG_ENTER("make_empty_rec");
|
||||
|
||||
/* We need a table to generate columns for default values */
|
||||
|
@ -1051,7 +1050,7 @@ static bool make_empty_rec(THD *thd, uchar *buff, uint table_options,
|
|||
null_pos= buff;
|
||||
|
||||
List_iterator<Create_field> it(create_fields);
|
||||
thd->count_cuted_fields= CHECK_FIELD_WARN; // To find wrong default values
|
||||
Check_level_instant_set check_level_save(thd, CHECK_FIELD_WARN);
|
||||
while ((field=it++))
|
||||
{
|
||||
/* regfield don't have to be deleted as it's allocated on THD::mem_root */
|
||||
|
@ -1131,6 +1130,5 @@ static bool make_empty_rec(THD *thd, uchar *buff, uint table_options,
|
|||
*(null_pos + null_count / 8)|= ~(((uchar) 1 << (null_count & 7)) - 1);
|
||||
|
||||
err:
|
||||
thd->count_cuted_fields= old_count_cuted_fields;
|
||||
DBUG_RETURN(error);
|
||||
} /* make_empty_rec */
|
||||
|
|
Loading…
Add table
Reference in a new issue