small code cleanup taken from MySQL 5.6

This commit is contained in:
Sergei Golubchik 2012-12-16 21:45:45 +01:00
parent fe7c2aaeea
commit 4923d19b7c
12 changed files with 29 additions and 60 deletions

View File

@ -9004,9 +9004,7 @@ bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type,
A default other than '' is always an error, and any non-NULL
specified default is an error in strict mode.
*/
if (res->length() || (thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)))
if (res->length() || thd->is_strict_mode())
{
my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
fld_name); /* purecov: inspected */

View File

@ -5514,8 +5514,7 @@ String *Item::check_well_formed_result(String *str, bool send_error)
cs->csname, hexbuf);
return 0;
}
if ((thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
if (thd->is_strict_mode())
{
null_value= 1;
str= 0;

View File

@ -124,9 +124,7 @@ bool Item_str_func::fix_fields(THD *thd, Item **ref)
In Item_str_func::check_well_formed_result() we may set null_value
flag on the same condition as in test() below.
*/
maybe_null= (maybe_null ||
test(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)));
maybe_null= maybe_null || thd->is_strict_mode();
return res;
}

View File

@ -311,7 +311,7 @@ bool throw_bounds_warning(THD *thd, const char *name,
else
llstr(v, buf);
if (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES)
if (thd->is_strict_mode())
{
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buf);
return true;
@ -331,7 +331,7 @@ bool throw_bounds_warning(THD *thd, const char *name, bool fixed, double v)
my_gcvt(v, MY_GCVT_ARG_DOUBLE, sizeof(buf) - 1, buf, NULL);
if (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES)
if (thd->is_strict_mode())
{
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buf);
return true;

View File

@ -385,9 +385,7 @@ sp_eval_expr(THD *thd, Field *result_field, Item **expr_item_ptr)
*/
thd->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
thd->abort_on_warning=
thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES);
thd->abort_on_warning= thd->is_strict_mode();
thd->transaction.stmt.modified_non_trans_table= FALSE;
/* Save the value in the field. Convert the value if needed. */

View File

@ -2564,6 +2564,11 @@ public:
mysql_mutex_unlock(&mysys_var->mutex);
return;
}
inline bool is_strict_mode() const
{
return variables.sql_mode & (MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES);
}
inline my_time_t query_start() { query_start_used=1; return start_time; }
inline ulong query_start_sec_part()
{ query_start_sec_part_used=1; return start_time_sec_part; }
@ -3337,7 +3342,7 @@ my_eof(THD *thd)
const my_bool strict_date_checking= 0;
inline ulong sql_mode_for_dates(THD *thd)
inline ulonglong sql_mode_for_dates(THD *thd)
{
if (strict_date_checking)
return (thd->variables.sql_mode &
@ -3346,7 +3351,7 @@ inline ulong sql_mode_for_dates(THD *thd)
return (thd->variables.sql_mode & MODE_INVALID_DATES);
}
inline ulong sql_mode_for_dates()
inline ulonglong sql_mode_for_dates()
{
return sql_mode_for_dates(current_thd);
}

View File

@ -790,9 +790,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
FALSE,
(fields.elements || !value_count ||
table_list->view != 0),
!ignore && (thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES))))
!ignore && thd->is_strict_mode()))
goto abort;
/* mysql_prepare_insert set table_list->table if it was not set */
@ -904,9 +902,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
}
}
thd->abort_on_warning= (!ignore && (thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)));
thd->abort_on_warning= !ignore && thd->is_strict_mode();
prepare_triggers_for_insert_stmt(table);
@ -3339,9 +3335,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
if (!res && fields->elements)
{
bool saved_abort_on_warning= thd->abort_on_warning;
thd->abort_on_warning= !info.ignore && (thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES));
thd->abort_on_warning= !info.ignore && thd->is_strict_mode();
res= check_that_all_fields_are_given_values(thd, table_list->table,
table_list);
thd->abort_on_warning= saved_abort_on_warning;
@ -3456,10 +3450,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
if (info.handle_duplicates == DUP_UPDATE)
table->file->extra(HA_EXTRA_INSERT_WITH_UPDATE);
thd->abort_on_warning= (!info.ignore &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)));
thd->abort_on_warning= !info.ignore && thd->is_strict_mode();
res= (table_list->prepare_where(thd, 0, TRUE) ||
table_list->prepare_check_option(thd));
@ -4076,10 +4067,7 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
table->file->extra(HA_EXTRA_INSERT_WITH_UPDATE);
if (thd->locked_tables_mode <= LTM_LOCK_TABLES)
table->file->ha_start_bulk_insert((ha_rows) 0);
thd->abort_on_warning= (!info.ignore &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)));
thd->abort_on_warning= !info.ignore && thd->is_strict_mode();
if (check_that_all_fields_are_given_values(thd, table, table_list))
DBUG_RETURN(1);
table->mark_columns_needed_for_insert();

View File

@ -487,10 +487,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
table->file->ha_start_bulk_insert((ha_rows) 0);
table->copy_blobs=1;
thd->abort_on_warning= (!ignore &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)));
thd->abort_on_warning= !ignore && thd->is_strict_mode();
thd_progress_init(thd, 2);
if (ex->filetype == FILETYPE_XML) /* load xml */

View File

@ -243,8 +243,7 @@ static int assign_condition_item(MEM_ROOT *mem_root, const char* name, THD *thd,
truncated= assign_fixed_string(mem_root, & my_charset_utf8_bin, 64, ci, str);
if (truncated)
{
if (thd->variables.sql_mode & (MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES))
if (thd->is_strict_mode())
{
thd->raise_error_printf(ER_COND_ITEM_TOO_LONG, name);
DBUG_RETURN(1);
@ -348,8 +347,7 @@ int Signal_common::eval_signal_informations(THD *thd, MYSQL_ERROR *cond)
& utf8_text, str);
if (truncated)
{
if (thd->variables.sql_mode & (MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES))
if (thd->is_strict_mode())
{
thd->raise_error_printf(ER_COND_ITEM_TOO_LONG,
"MESSAGE_TEXT");

View File

@ -2552,8 +2552,7 @@ bool check_duplicates_in_interval(const char *set_or_name,
{
THD *thd= current_thd;
ErrConvString err(*cur_value, *cur_length, cs);
if ((current_thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
if (current_thd->is_strict_mode())
{
my_error(ER_DUPLICATED_VALUE_IN_TYPE, MYF(0),
name, err.ptr(), set_or_name);
@ -3734,8 +3733,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
if (tmp_len < key->key_create_info.comment.length)
{
if ((thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
if (thd->is_strict_mode())
{
my_error(ER_TOO_LONG_INDEX_COMMENT, MYF(0),
key_info->name, static_cast<ulong>(INDEX_COMMENT_MAXLEN));
@ -3873,8 +3871,7 @@ static bool prepare_blob_field(THD *thd, Create_field *sql_field)
/* Convert long VARCHAR columns to TEXT or BLOB */
char warn_buff[MYSQL_ERRMSG_SIZE];
if (sql_field->def || (thd->variables.sql_mode & (MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)))
if (sql_field->def || thd->is_strict_mode())
{
my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), sql_field->field_name,
static_cast<ulong>(MAX_FIELD_VARCHARLENGTH /
@ -7354,9 +7351,7 @@ copy_data_between_tables(THD *thd, TABLE *from,TABLE *to,
alter_table_manage_keys(to, from->file->indexes_are_disabled(), keys_onoff);
/* We can abort alter table for any table type */
thd->abort_on_warning= !ignore && test(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES));
thd->abort_on_warning= !ignore && thd->is_strict_mode();
from->file->info(HA_STATUS_VARIABLE);
to->file->ha_start_bulk_insert(from->file->stats.records);

View File

@ -643,10 +643,7 @@ int mysql_update(THD *thd,
THD_STAGE_INFO(thd, stage_updating);
transactional_table= table->file->has_transactions();
thd->abort_on_warning= test(!ignore &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)));
thd->abort_on_warning= !ignore && thd->is_strict_mode();
if (table->triggers &&
table->triggers->has_triggers(TRG_EVENT_UPDATE,
TRG_ACTION_AFTER))
@ -1391,9 +1388,7 @@ bool mysql_multi_update(THD *thd,
DBUG_RETURN(TRUE);
}
thd->abort_on_warning= test(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES));
thd->abort_on_warning= thd->is_strict_mode();
List<Item> total_list;

View File

@ -241,8 +241,7 @@ bool mysql_create_frm(THD *thd, const char *file_name,
(real_table_name= field->field->table->s->table_name.str))
break;
}
if ((thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
if (thd->is_strict_mode())
{
my_error(ER_TOO_LONG_TABLE_COMMENT, MYF(0),
real_table_name, static_cast<ulong>(TABLE_COMMENT_MAXLEN));
@ -707,8 +706,7 @@ static bool pack_header(uchar *forminfo, enum legacy_db_type table_type,
COLUMN_COMMENT_MAXLEN);
if (tmp_len < field->comment.length)
{
if ((current_thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
if (current_thd->is_strict_mode())
{
my_error(ER_TOO_LONG_FIELD_COMMENT, MYF(0), field->field_name,
static_cast<ulong>(COLUMN_COMMENT_MAXLEN));