Using more of Sql_mode_save. Adding a similar class for THD::abort_on_warnings.

This commit is contained in:
Alexander Barkov 2019-05-28 10:26:08 +04:00
parent c0cd662b98
commit d1d6fe9abf
17 changed files with 65 additions and 71 deletions

View File

@ -1451,12 +1451,10 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
if (unlikely(error == ETIMEDOUT || error == ETIME)) if (unlikely(error == ETIMEDOUT || error == ETIME))
{ {
// We should not make the statement fail, even if in strict mode. // We should not make the statement fail, even if in strict mode.
const bool save_abort_on_warning= thd->abort_on_warning; Abort_on_warning_instant_set aws(thd, false);
thd->abort_on_warning= false;
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
ER_DEBUG_SYNC_TIMEOUT, ER_DEBUG_SYNC_TIMEOUT,
ER_THD(thd, 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_ASSERT(0);); DBUG_EXECUTE_IF("debug_sync_abort_on_timeout", DBUG_ASSERT(0););
break; break;
} }

View File

@ -1061,7 +1061,6 @@ Event_db_repository::load_named_event(THD *thd, const LEX_CSTRING *dbname,
Event_basic *etn) Event_basic *etn)
{ {
bool ret; bool ret;
ulonglong saved_mode= thd->variables.sql_mode;
Open_tables_backup open_tables_backup; Open_tables_backup open_tables_backup;
TABLE_LIST event_table; TABLE_LIST event_table;
@ -1072,7 +1071,7 @@ Event_db_repository::load_named_event(THD *thd, const LEX_CSTRING *dbname,
event_table.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_EVENT_NAME, 0, TL_READ); event_table.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_EVENT_NAME, 0, TL_READ);
/* Reset sql_mode during data dictionary operations. */ /* Reset sql_mode during data dictionary operations. */
thd->variables.sql_mode= 0; Sql_mode_instant_set sms(thd, 0);
/* /*
We don't use open_event_table() here to make sure that SHOW We don't use open_event_table() here to make sure that SHOW
@ -1097,7 +1096,6 @@ Event_db_repository::load_named_event(THD *thd, const LEX_CSTRING *dbname,
close_system_tables(thd, &open_tables_backup); close_system_tables(thd, &open_tables_backup);
} }
thd->variables.sql_mode= saved_mode;
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }

View File

@ -11230,8 +11230,7 @@ bool Field::val_str_nopad(MEM_ROOT *mem_root, LEX_CSTRING *to)
StringBuffer<MAX_FIELD_WIDTH> str; StringBuffer<MAX_FIELD_WIDTH> str;
bool rc= false; bool rc= false;
THD *thd= get_thd(); THD *thd= get_thd();
sql_mode_t sql_mode_backup= thd->variables.sql_mode; Sql_mode_instant_remove sms(thd, MODE_PAD_CHAR_TO_FULL_LENGTH);
thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
val_str(&str); val_str(&str);
if (!(to->length= str.length())) if (!(to->length= str.length()))
@ -11239,6 +11238,5 @@ bool Field::val_str_nopad(MEM_ROOT *mem_root, LEX_CSTRING *to)
else if ((rc= !(to->str= strmake_root(mem_root, str.ptr(), str.length())))) else if ((rc= !(to->str= strmake_root(mem_root, str.ptr(), str.length()))))
to->length= 0; to->length= 0;
thd->variables.sql_mode= sql_mode_backup;
return rc; return rc;
} }

View File

@ -4256,7 +4256,7 @@ int ha_partition::write_row(uchar * buf)
bool have_auto_increment= table->next_number_field && buf == table->record[0]; bool have_auto_increment= table->next_number_field && buf == table->record[0];
my_bitmap_map *old_map; my_bitmap_map *old_map;
THD *thd= ha_thd(); THD *thd= ha_thd();
sql_mode_t saved_sql_mode= thd->variables.sql_mode; Sql_mode_save sms(thd);
bool saved_auto_inc_field_not_null= table->auto_increment_field_not_null; bool saved_auto_inc_field_not_null= table->auto_increment_field_not_null;
DBUG_ENTER("ha_partition::write_row"); DBUG_ENTER("ha_partition::write_row");
DBUG_PRINT("enter", ("partition this: %p", this)); DBUG_PRINT("enter", ("partition this: %p", this));
@ -4322,7 +4322,6 @@ int ha_partition::write_row(uchar * buf)
reenable_binlog(thd); reenable_binlog(thd);
exit: exit:
thd->variables.sql_mode= saved_sql_mode;
table->auto_increment_field_not_null= saved_auto_inc_field_not_null; table->auto_increment_field_not_null= saved_auto_inc_field_not_null;
DBUG_RETURN(error); DBUG_RETURN(error);
} }

View File

@ -1411,7 +1411,7 @@ int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
THD *thd= table->in_use; THD *thd= table->in_use;
enum_check_fields tmp= thd->count_cuted_fields; enum_check_fields tmp= thd->count_cuted_fields;
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set); my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
sql_mode_t sql_mode= thd->variables.sql_mode; Sql_mode_save sms(thd);
thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE); thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
thd->variables.sql_mode|= MODE_INVALID_DATES; thd->variables.sql_mode|= MODE_INVALID_DATES;
thd->count_cuted_fields= CHECK_FIELD_IGNORE; thd->count_cuted_fields= CHECK_FIELD_IGNORE;
@ -1420,7 +1420,6 @@ int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
thd->count_cuted_fields= tmp; thd->count_cuted_fields= tmp;
dbug_tmp_restore_column_map(table->write_set, old_map); dbug_tmp_restore_column_map(table->write_set, old_map);
thd->variables.sql_mode= sql_mode;
return res; return res;
} }

View File

@ -2146,7 +2146,6 @@ bool partition_info::fix_column_value_functions(THD *thd,
{ {
uchar *val_ptr; uchar *val_ptr;
uint len= field->pack_length(); uint len= field->pack_length();
sql_mode_t save_sql_mode;
bool save_got_warning; bool save_got_warning;
if (!(column_item= get_column_item(column_item, field))) if (!(column_item= get_column_item(column_item, field)))
@ -2154,20 +2153,17 @@ bool partition_info::fix_column_value_functions(THD *thd,
result= TRUE; result= TRUE;
goto end; goto end;
} }
save_sql_mode= thd->variables.sql_mode; Sql_mode_instant_set sms(thd, 0);
thd->variables.sql_mode= 0;
save_got_warning= thd->got_warning; save_got_warning= thd->got_warning;
thd->got_warning= 0; thd->got_warning= 0;
if (column_item->save_in_field(field, TRUE) || if (column_item->save_in_field(field, TRUE) ||
thd->got_warning) thd->got_warning)
{ {
my_error(ER_WRONG_TYPE_COLUMN_VALUE_ERROR, MYF(0)); my_error(ER_WRONG_TYPE_COLUMN_VALUE_ERROR, MYF(0));
thd->variables.sql_mode= save_sql_mode;
result= TRUE; result= TRUE;
goto end; goto end;
} }
thd->got_warning= save_got_warning; thd->got_warning= save_got_warning;
thd->variables.sql_mode= save_sql_mode;
if (!(val_ptr= (uchar*) thd->memdup(field->ptr, len))) if (!(val_ptr= (uchar*) thd->memdup(field->ptr, len)))
{ {
result= TRUE; result= TRUE;

View File

@ -683,7 +683,7 @@ Sp_handler::db_find_routine(THD *thd,
longlong modified; longlong modified;
Sp_chistics chistics; Sp_chistics chistics;
bool saved_time_zone_used= thd->time_zone_used; bool saved_time_zone_used= thd->time_zone_used;
sql_mode_t sql_mode, saved_mode= thd->variables.sql_mode; sql_mode_t sql_mode;
Open_tables_backup open_tables_state_backup; Open_tables_backup open_tables_state_backup;
Stored_program_creation_ctx *creation_ctx; Stored_program_creation_ctx *creation_ctx;
AUTHID definer; AUTHID definer;
@ -698,7 +698,7 @@ Sp_handler::db_find_routine(THD *thd,
DBUG_RETURN(SP_OPEN_TABLE_FAILED); DBUG_RETURN(SP_OPEN_TABLE_FAILED);
/* Reset sql_mode during data dictionary operations. */ /* Reset sql_mode during data dictionary operations. */
thd->variables.sql_mode= 0; Sql_mode_instant_set sms(thd, 0);
if ((ret= db_find_routine_aux(thd, name, table)) != SP_OK) if ((ret= db_find_routine_aux(thd, name, table)) != SP_OK)
goto done; goto done;
@ -755,7 +755,6 @@ Sp_handler::db_find_routine(THD *thd,
thd->time_zone_used= saved_time_zone_used; thd->time_zone_used= saved_time_zone_used;
if (table) if (table)
close_system_tables(thd, &open_tables_state_backup); close_system_tables(thd, &open_tables_state_backup);
thd->variables.sql_mode= saved_mode;
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
@ -1524,8 +1523,7 @@ Sp_handler_package::show_create_sp(THD *thd, String *buf,
const DDL_options_st ddl_options, const DDL_options_st ddl_options,
sql_mode_t sql_mode) const sql_mode_t sql_mode) const
{ {
sql_mode_t old_sql_mode= thd->variables.sql_mode; Sql_mode_instant_set sms(thd, sql_mode);
thd->variables.sql_mode= sql_mode;
bool rc= bool rc=
buf->append(STRING_WITH_LEN("CREATE ")) || buf->append(STRING_WITH_LEN("CREATE ")) ||
(ddl_options.or_replace() && (ddl_options.or_replace() &&
@ -1542,7 +1540,6 @@ Sp_handler_package::show_create_sp(THD *thd, String *buf,
append_package_chistics(buf, chistics) || append_package_chistics(buf, chistics) ||
buf->append(" ", 1) || buf->append(" ", 1) ||
buf->append(body.str, body.length); buf->append(body.str, body.length);
thd->variables.sql_mode= old_sql_mode;
return rc; return rc;
} }
@ -2914,7 +2911,6 @@ Sp_handler::show_create_sp(THD *thd, String *buf,
const DDL_options_st ddl_options, const DDL_options_st ddl_options,
sql_mode_t sql_mode) const sql_mode_t sql_mode) const
{ {
sql_mode_t old_sql_mode= thd->variables.sql_mode;
size_t agglen= (chistics.agg_type == GROUP_AGGREGATE)? 10 : 0; size_t agglen= (chistics.agg_type == GROUP_AGGREGATE)? 10 : 0;
LEX_CSTRING tmp; LEX_CSTRING tmp;
@ -2925,7 +2921,7 @@ Sp_handler::show_create_sp(THD *thd, String *buf,
agglen + USER_HOST_BUFF_SIZE)) agglen + USER_HOST_BUFF_SIZE))
return true; return true;
thd->variables.sql_mode= sql_mode; Sql_mode_instant_set sms(thd, sql_mode);
buf->append(STRING_WITH_LEN("CREATE ")); buf->append(STRING_WITH_LEN("CREATE "));
if (ddl_options.or_replace()) if (ddl_options.or_replace())
buf->append(STRING_WITH_LEN("OR REPLACE ")); buf->append(STRING_WITH_LEN("OR REPLACE "));
@ -2976,7 +2972,6 @@ Sp_handler::show_create_sp(THD *thd, String *buf,
append_suid(buf, chistics.suid); append_suid(buf, chistics.suid);
append_comment(buf, chistics.comment); append_comment(buf, chistics.comment);
buf->append(body.str, body.length); // Not \0 terminated buf->append(body.str, body.length); // Not \0 terminated
thd->variables.sql_mode= old_sql_mode;
return false; return false;
} }

View File

@ -3819,10 +3819,8 @@ sp_instr_set_trigger_field::execute(THD *thd, uint *nextp)
int int
sp_instr_set_trigger_field::exec_core(THD *thd, uint *nextp) sp_instr_set_trigger_field::exec_core(THD *thd, uint *nextp)
{ {
bool sav_abort_on_warning= thd->abort_on_warning; Abort_on_warning_instant_set aws(thd, thd->is_strict_mode() && !thd->lex->ignore);
thd->abort_on_warning= thd->is_strict_mode() && !thd->lex->ignore;
const int res= (trigger_field->set_value(thd, &value) ? -1 : 0); const int res= (trigger_field->set_value(thd, &value) ? -1 : 0);
thd->abort_on_warning= sav_abort_on_warning;
*nextp = m_ip+1; *nextp = m_ip+1;
return res; return res;
} }

View File

@ -7607,10 +7607,9 @@ static bool grant_load(THD *thd,
TABLE *t_table, *c_table, *p_table; TABLE *t_table, *c_table, *p_table;
bool check_no_resolve= specialflag & SPECIAL_NO_RESOLVE; bool check_no_resolve= specialflag & SPECIAL_NO_RESOLVE;
MEM_ROOT *save_mem_root= thd->mem_root; MEM_ROOT *save_mem_root= thd->mem_root;
sql_mode_t old_sql_mode= thd->variables.sql_mode;
DBUG_ENTER("grant_load"); DBUG_ENTER("grant_load");
thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH; Sql_mode_instant_remove sms(thd, MODE_PAD_CHAR_TO_FULL_LENGTH);
(void) my_hash_init(&column_priv_hash, &my_charset_utf8_bin, (void) my_hash_init(&column_priv_hash, &my_charset_utf8_bin,
0,0,0, (my_hash_get_key) get_grant_table, 0,0,0, (my_hash_get_key) get_grant_table,
@ -7735,7 +7734,6 @@ end_unlock:
t_table->file->ha_index_end(); t_table->file->ha_index_end();
thd->mem_root= save_mem_root; thd->mem_root= save_mem_root;
end_index_init: end_index_init:
thd->variables.sql_mode= old_sql_mode;
DBUG_RETURN(return_val); DBUG_RETURN(return_val);
} }
@ -10722,7 +10720,6 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list, bool handle_as_role)
LEX_USER *user_name, *tmp_user_name; LEX_USER *user_name, *tmp_user_name;
List_iterator <LEX_USER> user_list(list); List_iterator <LEX_USER> user_list(list);
bool binlog= false; bool binlog= false;
sql_mode_t old_sql_mode= thd->variables.sql_mode;
DBUG_ENTER("mysql_drop_user"); DBUG_ENTER("mysql_drop_user");
DBUG_PRINT("entry", ("Handle as %s", handle_as_role ? "role" : "user")); DBUG_PRINT("entry", ("Handle as %s", handle_as_role ? "role" : "user"));
@ -10734,7 +10731,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list, bool handle_as_role)
if ((result= tables.open_and_lock(thd, tables_to_open, TL_WRITE))) if ((result= tables.open_and_lock(thd, tables_to_open, TL_WRITE)))
DBUG_RETURN(result != 1); DBUG_RETURN(result != 1);
thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH; Sql_mode_instant_remove sms(thd, MODE_PAD_CHAR_TO_FULL_LENGTH);
mysql_rwlock_wrlock(&LOCK_grant); mysql_rwlock_wrlock(&LOCK_grant);
mysql_mutex_lock(&acl_cache->lock); mysql_mutex_lock(&acl_cache->lock);
@ -10809,7 +10806,6 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list, bool handle_as_role)
result |= write_bin_log(thd, FALSE, thd->query(), thd->query_length()); result |= write_bin_log(thd, FALSE, thd->query(), thd->query_length());
mysql_rwlock_unlock(&LOCK_grant); mysql_rwlock_unlock(&LOCK_grant);
thd->variables.sql_mode= old_sql_mode;
DBUG_RETURN(result); DBUG_RETURN(result);
} }

View File

@ -6677,6 +6677,45 @@ class Sql_mode_save
}; };
class Sql_mode_instant_set: public Sql_mode_save
{
public:
Sql_mode_instant_set(THD *thd, sql_mode_t temporary_value)
:Sql_mode_save(thd)
{
thd->variables.sql_mode= temporary_value;
}
};
class Sql_mode_instant_remove: public Sql_mode_save
{
public:
Sql_mode_instant_remove(THD *thd, sql_mode_t temporary_remove_flags)
:Sql_mode_save(thd)
{
thd->variables.sql_mode&= ~temporary_remove_flags;
}
};
class Abort_on_warning_instant_set
{
THD *m_thd;
bool m_save_abort_on_warning;
public:
Abort_on_warning_instant_set(THD *thd, bool temporary_value)
:m_thd(thd), m_save_abort_on_warning(thd->abort_on_warning)
{
thd->abort_on_warning= temporary_value;
}
~Abort_on_warning_instant_set()
{
m_thd->abort_on_warning= m_save_abort_on_warning;
}
};
/** /**
This class resembles the SQL Standard schema qualified object name: This class resembles the SQL Standard schema qualified object name:
<schema qualified name> ::= [ <schema name> <period> ] <qualified identifier> <schema qualified name> ::= [ <schema name> <period> ] <qualified identifier>

View File

@ -856,9 +856,7 @@ error2:
bool mysqld_help(THD *thd, const char *mask) bool mysqld_help(THD *thd, const char *mask)
{ {
sql_mode_t sql_mode_backup= thd->variables.sql_mode; Sql_mode_instant_remove sms(thd, MODE_PAD_CHAR_TO_FULL_LENGTH);
thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
bool rc= mysqld_help_internal(thd, mask); bool rc= mysqld_help_internal(thd, mask);
thd->variables.sql_mode= sql_mode_backup;
return rc; return rc;
} }

View File

@ -3655,10 +3655,8 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
if (!res && fields->elements) if (!res && fields->elements)
{ {
bool saved_abort_on_warning= thd->abort_on_warning; Abort_on_warning_instant_set aws(thd, !info.ignore && thd->is_strict_mode());
thd->abort_on_warning= !info.ignore && thd->is_strict_mode();
res= check_that_all_fields_are_given_values(thd, table_list->table, table_list); res= check_that_all_fields_are_given_values(thd, table_list->table, table_list);
thd->abort_on_warning= saved_abort_on_warning;
} }
if (info.handle_duplicates == DUP_UPDATE && !res) if (info.handle_duplicates == DUP_UPDATE && !res)

View File

@ -2584,11 +2584,9 @@ char *generate_partition_syntax_for_frm(THD *thd, partition_info *part_info,
HA_CREATE_INFO *create_info, HA_CREATE_INFO *create_info,
Alter_info *alter_info) Alter_info *alter_info)
{ {
sql_mode_t old_mode= thd->variables.sql_mode; Sql_mode_instant_remove sms(thd, MODE_ANSI_QUOTES);
thd->variables.sql_mode &= ~MODE_ANSI_QUOTES;
char *res= generate_partition_syntax(thd, part_info, buf_length, char *res= generate_partition_syntax(thd, part_info, buf_length,
true, create_info, alter_info); true, create_info, alter_info);
thd->variables.sql_mode= old_mode;
return res; return res;
} }

View File

@ -4499,12 +4499,11 @@ Prepared_statement::reprepare()
TRUE, &cur_db_changed))) TRUE, &cur_db_changed)))
return TRUE; return TRUE;
sql_mode_t save_sql_mode= thd->variables.sql_mode; Sql_mode_instant_set sms(thd, m_sql_mode);
thd->variables.sql_mode= m_sql_mode;
error= ((name.str && copy.set_name(&name)) || error= ((name.str && copy.set_name(&name)) ||
copy.prepare(query(), query_length()) || copy.prepare(query(), query_length()) ||
validate_metadata(&copy)); validate_metadata(&copy));
thd->variables.sql_mode= save_sql_mode;
if (cur_db_changed) if (cur_db_changed)
mysql_change_db(thd, (LEX_CSTRING*) &saved_cur_db_name, TRUE); mysql_change_db(thd, (LEX_CSTRING*) &saved_cur_db_name, TRUE);

View File

@ -10408,14 +10408,12 @@ err_new_table_cleanup:
/* Shouldn't get here. */ /* Shouldn't get here. */
DBUG_ASSERT(0); DBUG_ASSERT(0);
} }
bool save_abort_on_warning= thd->abort_on_warning; Abort_on_warning_instant_set aws(thd, true);
thd->abort_on_warning= true;
thd->push_warning_truncated_value_for_field(Sql_condition::WARN_LEVEL_WARN, thd->push_warning_truncated_value_for_field(Sql_condition::WARN_LEVEL_WARN,
f_type, f_val, f_type, f_val,
new_table->s, new_table->s,
alter_ctx.datetime_field-> alter_ctx.datetime_field->
field_name.str); field_name.str);
thd->abort_on_warning= save_abort_on_warning;
} }
if (new_table) if (new_table)
@ -10620,14 +10618,12 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
to->file->ha_table_flags() & HA_TABLE_SCAN_ON_INDEX) to->file->ha_table_flags() & HA_TABLE_SCAN_ON_INDEX)
{ {
char warn_buff[MYSQL_ERRMSG_SIZE]; char warn_buff[MYSQL_ERRMSG_SIZE];
bool save_abort_on_warning= thd->abort_on_warning; Abort_on_warning_instant_set aws(thd, false);
thd->abort_on_warning= false;
my_snprintf(warn_buff, sizeof(warn_buff), my_snprintf(warn_buff, sizeof(warn_buff),
"ORDER BY ignored as there is a user-defined clustered index" "ORDER BY ignored as there is a user-defined clustered index"
" in the table '%-.192s'", from->s->table_name.str); " in the table '%-.192s'", from->s->table_name.str);
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
warn_buff); warn_buff);
thd->abort_on_warning= save_abort_on_warning;
} }
else else
{ {

View File

@ -926,16 +926,13 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
view_query.length(0); view_query.length(0);
is_query.length(0); is_query.length(0);
{ {
sql_mode_t sql_mode= thd->variables.sql_mode & MODE_ANSI_QUOTES; Sql_mode_instant_remove sms(thd, MODE_ANSI_QUOTES);
thd->variables.sql_mode&= ~MODE_ANSI_QUOTES;
lex->unit.print(&view_query, enum_query_type(QT_VIEW_INTERNAL | lex->unit.print(&view_query, enum_query_type(QT_VIEW_INTERNAL |
QT_ITEM_ORIGINAL_FUNC_NULLIF)); QT_ITEM_ORIGINAL_FUNC_NULLIF));
lex->unit.print(&is_query, enum_query_type(QT_TO_SYSTEM_CHARSET | lex->unit.print(&is_query, enum_query_type(QT_TO_SYSTEM_CHARSET |
QT_WITHOUT_INTRODUCERS | QT_WITHOUT_INTRODUCERS |
QT_ITEM_ORIGINAL_FUNC_NULLIF)); QT_ITEM_ORIGINAL_FUNC_NULLIF));
thd->variables.sql_mode|= sql_mode;
} }
DBUG_PRINT("info", ("View: %.*s", view_query.length(), view_query.ptr())); DBUG_PRINT("info", ("View: %.*s", view_query.length(), view_query.ptr()));

View File

@ -1077,7 +1077,6 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table,
Field **vfield_ptr= table->vfield; Field **vfield_ptr= table->vfield;
Field **dfield_ptr= table->default_field; Field **dfield_ptr= table->default_field;
Virtual_column_info **check_constraint_ptr= table->check_constraints; Virtual_column_info **check_constraint_ptr= table->check_constraints;
sql_mode_t saved_mode= thd->variables.sql_mode;
Query_arena backup_arena; Query_arena backup_arena;
Virtual_column_info *vcol= 0; Virtual_column_info *vcol= 0;
StringBuffer<MAX_FIELD_WIDTH> expr_str; StringBuffer<MAX_FIELD_WIDTH> expr_str;
@ -1103,7 +1102,7 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table,
thd->stmt_arena= table->expr_arena; thd->stmt_arena= table->expr_arena;
thd->update_charset(&my_charset_utf8mb4_general_ci, table->s->table_charset); thd->update_charset(&my_charset_utf8mb4_general_ci, table->s->table_charset);
expr_str.append(&parse_vcol_keyword); expr_str.append(&parse_vcol_keyword);
thd->variables.sql_mode &= ~MODE_NO_BACKSLASH_ESCAPES; Sql_mode_instant_remove sms(thd, MODE_NO_BACKSLASH_ESCAPES);
while (pos < end) while (pos < end)
{ {
@ -1271,7 +1270,6 @@ end:
thd->stmt_arena= backup_stmt_arena_ptr; thd->stmt_arena= backup_stmt_arena_ptr;
if (save_character_set_client) if (save_character_set_client)
thd->update_charset(save_character_set_client, save_collation); thd->update_charset(save_character_set_client, save_collation);
thd->variables.sql_mode= saved_mode;
DBUG_RETURN(res); DBUG_RETURN(res);
} }
@ -3063,7 +3061,6 @@ static bool sql_unusable_for_discovery(THD *thd, handlerton *engine,
int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write, int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write,
const char *sql, size_t sql_length) const char *sql, size_t sql_length)
{ {
sql_mode_t saved_mode= thd->variables.sql_mode;
CHARSET_INFO *old_cs= thd->variables.character_set_client; CHARSET_INFO *old_cs= thd->variables.character_set_client;
Parser_state parser_state; Parser_state parser_state;
bool error; bool error;
@ -3091,7 +3088,7 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write,
if (parser_state.init(thd, sql_copy, sql_length)) if (parser_state.init(thd, sql_copy, sql_length))
DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_RETURN(HA_ERR_OUT_OF_MEM);
thd->variables.sql_mode= MODE_NO_ENGINE_SUBSTITUTION | MODE_NO_DIR_IN_CREATE; Sql_mode_instant_set sms(thd, MODE_NO_ENGINE_SUBSTITUTION | MODE_NO_DIR_IN_CREATE);
thd->variables.character_set_client= system_charset_info; thd->variables.character_set_client= system_charset_info;
tmp_disable_binlog(thd); tmp_disable_binlog(thd);
old_lex= thd->lex; old_lex= thd->lex;
@ -3140,7 +3137,6 @@ ret:
if (arena) if (arena)
thd->restore_active_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
reenable_binlog(thd); reenable_binlog(thd);
thd->variables.sql_mode= saved_mode;
thd->variables.character_set_client= old_cs; thd->variables.character_set_client= old_cs;
if (unlikely(thd->is_error() || error)) if (unlikely(thd->is_error() || error))
{ {
@ -4390,21 +4386,17 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res)
StringBuffer<MAX_FIELD_WIDTH> str; StringBuffer<MAX_FIELD_WIDTH> str;
bool rc; bool rc;
THD *thd= field->get_thd(); THD *thd= field->get_thd();
sql_mode_t sql_mode_backup= thd->variables.sql_mode; Sql_mode_instant_remove sms(thd, MODE_PAD_CHAR_TO_FULL_LENGTH);
thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
field->val_str(&str); field->val_str(&str);
if ((rc= !str.length() || if ((rc= !str.length() ||
!(to= strmake_root(mem, str.ptr(), str.length())))) !(to= strmake_root(mem, str.ptr(), str.length()))))
{ {
res->length(0); res->length(0);
goto ex; return rc;
} }
res->set(to, str.length(), field->charset()); res->set(to, str.length(), field->charset());
return false;
ex:
thd->variables.sql_mode= sql_mode_backup;
return rc;
} }