mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
cleanup
* move common code to a new set_bad_null_error() function * move repeated comparison out of the loop * remove unused code * unused method Table_triggers_list::set_table * redundant condition (if (table) after table was dereferenced) * add an assert
This commit is contained in:
@ -116,8 +116,25 @@ static void do_outer_field_to_null_str(Copy_field *copy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
static int set_bad_null_error(Field *field, int err)
|
||||||
set_field_to_null(Field *field)
|
{
|
||||||
|
switch (field->table->in_use->count_cuted_fields) {
|
||||||
|
case CHECK_FIELD_WARN:
|
||||||
|
field->set_warning(Sql_condition::WARN_LEVEL_WARN, err, 1);
|
||||||
|
/* fall through */
|
||||||
|
case CHECK_FIELD_IGNORE:
|
||||||
|
return 0;
|
||||||
|
case CHECK_FIELD_ERROR_FOR_NULL:
|
||||||
|
if (!field->table->in_use->no_errors)
|
||||||
|
my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
DBUG_ASSERT(0); // impossible
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int set_field_to_null(Field *field)
|
||||||
{
|
{
|
||||||
if (field->table->null_catch_flags & CHECK_ROW_FOR_NULLS_TO_REJECT)
|
if (field->table->null_catch_flags & CHECK_ROW_FOR_NULLS_TO_REJECT)
|
||||||
{
|
{
|
||||||
@ -131,19 +148,7 @@ set_field_to_null(Field *field)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
field->reset();
|
field->reset();
|
||||||
switch (field->table->in_use->count_cuted_fields) {
|
return set_bad_null_error(field, WARN_DATA_TRUNCATED);
|
||||||
case CHECK_FIELD_WARN:
|
|
||||||
field->set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
|
|
||||||
/* fall through */
|
|
||||||
case CHECK_FIELD_IGNORE:
|
|
||||||
return 0;
|
|
||||||
case CHECK_FIELD_ERROR_FOR_NULL:
|
|
||||||
if (!field->table->in_use->no_errors)
|
|
||||||
my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
DBUG_ASSERT(0); // impossible
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -200,19 +205,7 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions)
|
|||||||
field->table->auto_increment_field_not_null= FALSE;
|
field->table->auto_increment_field_not_null= FALSE;
|
||||||
return 0; // field is set in fill_record()
|
return 0; // field is set in fill_record()
|
||||||
}
|
}
|
||||||
switch (field->table->in_use->count_cuted_fields) {
|
return set_bad_null_error(field, ER_BAD_NULL_ERROR);
|
||||||
case CHECK_FIELD_WARN:
|
|
||||||
field->set_warning(Sql_condition::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
|
|
||||||
/* fall through */
|
|
||||||
case CHECK_FIELD_IGNORE:
|
|
||||||
return 0;
|
|
||||||
case CHECK_FIELD_ERROR_FOR_NULL:
|
|
||||||
if (!field->table->in_use->no_errors)
|
|
||||||
my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
DBUG_ASSERT(0); // impossible
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -532,10 +532,6 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
|
|||||||
hton->discover_table_existence= full_discover_for_existence;
|
hton->discover_table_existence= full_discover_for_existence;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
the switch below and hton->state should be removed when
|
|
||||||
command-line options for plugins will be implemented
|
|
||||||
*/
|
|
||||||
switch (hton->state) {
|
switch (hton->state) {
|
||||||
case SHOW_OPTION_NO:
|
case SHOW_OPTION_NO:
|
||||||
break;
|
break;
|
||||||
|
14
sql/item.cc
14
sql/item.cc
@ -44,8 +44,7 @@
|
|||||||
|
|
||||||
const String my_null_string("NULL", 4, default_charset_info);
|
const String my_null_string("NULL", 4, default_charset_info);
|
||||||
|
|
||||||
static int save_field_in_field(Field *from, bool *null_value,
|
static int save_field_in_field(Field *, bool *, Field *, bool);
|
||||||
Field *to, bool no_conversions);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8159,7 +8158,8 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
|
|||||||
{
|
{
|
||||||
if (!arg)
|
if (!arg)
|
||||||
{
|
{
|
||||||
THD *thd= field_arg->table->in_use;
|
TABLE *table= field_arg->table;
|
||||||
|
THD *thd= table->in_use;
|
||||||
|
|
||||||
if (field_arg->flags & NO_DEFAULT_VALUE_FLAG &&
|
if (field_arg->flags & NO_DEFAULT_VALUE_FLAG &&
|
||||||
field_arg->real_type() != MYSQL_TYPE_ENUM)
|
field_arg->real_type() != MYSQL_TYPE_ENUM)
|
||||||
@ -8173,9 +8173,8 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
|
|||||||
|
|
||||||
if (context->error_processor == &view_error_processor)
|
if (context->error_processor == &view_error_processor)
|
||||||
{
|
{
|
||||||
TABLE_LIST *view= field_arg->table->pos_in_table_list->top_table();
|
TABLE_LIST *view= table->pos_in_table_list->top_table();
|
||||||
push_warning_printf(thd,
|
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
|
||||||
Sql_condition::WARN_LEVEL_WARN,
|
|
||||||
ER_NO_DEFAULT_FOR_VIEW_FIELD,
|
ER_NO_DEFAULT_FOR_VIEW_FIELD,
|
||||||
ER_THD(thd, ER_NO_DEFAULT_FOR_VIEW_FIELD),
|
ER_THD(thd, ER_NO_DEFAULT_FOR_VIEW_FIELD),
|
||||||
view->view_db.str,
|
view->view_db.str,
|
||||||
@ -8183,8 +8182,7 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
push_warning_printf(thd,
|
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
|
||||||
Sql_condition::WARN_LEVEL_WARN,
|
|
||||||
ER_NO_DEFAULT_FOR_FIELD,
|
ER_NO_DEFAULT_FOR_FIELD,
|
||||||
ER_THD(thd, ER_NO_DEFAULT_FOR_FIELD),
|
ER_THD(thd, ER_NO_DEFAULT_FOR_FIELD),
|
||||||
field_arg->field_name);
|
field_arg->field_name);
|
||||||
|
@ -8853,7 +8853,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, List<Item> &fields,
|
|||||||
Re-calculate virtual fields to cater for cases when base columns are
|
Re-calculate virtual fields to cater for cases when base columns are
|
||||||
updated by the triggers.
|
updated by the triggers.
|
||||||
*/
|
*/
|
||||||
if (!result && triggers && table)
|
if (!result && triggers)
|
||||||
{
|
{
|
||||||
List_iterator_fast<Item> f(fields);
|
List_iterator_fast<Item> f(fields);
|
||||||
Item *fld;
|
Item *fld;
|
||||||
|
@ -113,9 +113,9 @@ static bool check_view_insertability(THD *thd, TABLE_LIST *view);
|
|||||||
@returns false if success.
|
@returns false if success.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool check_view_single_update(List<Item> &fields, List<Item> *values,
|
static bool check_view_single_update(List<Item> &fields, List<Item> *values,
|
||||||
TABLE_LIST *view, table_map *map,
|
TABLE_LIST *view, table_map *map,
|
||||||
bool insert)
|
bool insert)
|
||||||
{
|
{
|
||||||
/* it is join view => we need to find the table for update */
|
/* it is join view => we need to find the table for update */
|
||||||
List_iterator_fast<Item> it(fields);
|
List_iterator_fast<Item> it(fields);
|
||||||
@ -1476,8 +1476,8 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
|
|||||||
thd->abort_on_warning= saved_abort_on_warning;
|
thd->abort_on_warning= saved_abort_on_warning;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
res= setup_fields(thd, 0, update_values, MARK_COLUMNS_READ, 0, 0);
|
res= setup_fields(thd, 0, update_values, MARK_COLUMNS_READ, 0, 0);
|
||||||
|
|
||||||
if (!res && duplic == DUP_UPDATE)
|
if (!res && duplic == DUP_UPDATE)
|
||||||
{
|
{
|
||||||
|
@ -767,7 +767,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
|
|||||||
List_iterator_fast<Item> it(fields_vars);
|
List_iterator_fast<Item> it(fields_vars);
|
||||||
Item_field *sql_field;
|
Item_field *sql_field;
|
||||||
TABLE *table= table_list->table;
|
TABLE *table= table_list->table;
|
||||||
bool err, progress_reports;
|
bool err, progress_reports, auto_increment_field_not_null=false;
|
||||||
ulonglong counter, time_to_report_progress;
|
ulonglong counter, time_to_report_progress;
|
||||||
DBUG_ENTER("read_fixed_length");
|
DBUG_ENTER("read_fixed_length");
|
||||||
|
|
||||||
@ -777,6 +777,12 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
|
|||||||
if ((thd->progress.max_counter= read_info.file_length()) == ~(my_off_t) 0)
|
if ((thd->progress.max_counter= read_info.file_length()) == ~(my_off_t) 0)
|
||||||
progress_reports= 0;
|
progress_reports= 0;
|
||||||
|
|
||||||
|
while ((sql_field= (Item_field*) it++))
|
||||||
|
{
|
||||||
|
if (table->field[sql_field->field->field_index] == table->next_number_field)
|
||||||
|
auto_increment_field_not_null= true;
|
||||||
|
}
|
||||||
|
|
||||||
while (!read_info.read_fixed_length())
|
while (!read_info.read_fixed_length())
|
||||||
{
|
{
|
||||||
if (thd->killed)
|
if (thd->killed)
|
||||||
@ -819,8 +825,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
|
|||||||
while ((sql_field= (Item_field*) it++))
|
while ((sql_field= (Item_field*) it++))
|
||||||
{
|
{
|
||||||
Field *field= sql_field->field;
|
Field *field= sql_field->field;
|
||||||
if (field == table->next_number_field)
|
table->auto_increment_field_not_null= auto_increment_field_not_null;
|
||||||
table->auto_increment_field_not_null= TRUE;
|
|
||||||
/*
|
/*
|
||||||
No fields specified in fields_vars list can be null in this format.
|
No fields specified in fields_vars list can be null in this format.
|
||||||
Mark field as not null, we should do this for each row because of
|
Mark field as not null, we should do this for each row because of
|
||||||
@ -874,8 +879,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
|
|||||||
(table->default_field && table->update_default_fields()))
|
(table->default_field && table->update_default_fields()))
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
|
|
||||||
switch (table_list->view_check_option(thd,
|
switch (table_list->view_check_option(thd, ignore_check_option_errors)) {
|
||||||
ignore_check_option_errors)) {
|
|
||||||
case VIEW_CHECK_SKIP:
|
case VIEW_CHECK_SKIP:
|
||||||
read_info.next_line();
|
read_info.next_line();
|
||||||
goto continue_loop;
|
goto continue_loop;
|
||||||
|
@ -1100,20 +1100,6 @@ bool Table_triggers_list::prepare_record1_accessors(TABLE *table)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Adjust Table_triggers_list with new TABLE pointer.
|
|
||||||
|
|
||||||
@param new_table new pointer to TABLE instance
|
|
||||||
*/
|
|
||||||
|
|
||||||
void Table_triggers_list::set_table(TABLE *new_table)
|
|
||||||
{
|
|
||||||
trigger_table= new_table;
|
|
||||||
for (Field **field= new_table->triggers->record1_field ; *field ; field++)
|
|
||||||
(*field)->init(new_table);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Check whenever .TRG file for table exist and load all triggers it contains.
|
Check whenever .TRG file for table exist and load all triggers it contains.
|
||||||
|
|
||||||
@ -2125,6 +2111,7 @@ bool Table_triggers_list::process_triggers(THD *thd,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
DBUG_ASSERT(event == TRG_EVENT_DELETE);
|
||||||
new_field= record1_field;
|
new_field= record1_field;
|
||||||
old_field= trigger_table->field;
|
old_field= trigger_table->field;
|
||||||
}
|
}
|
||||||
|
@ -197,8 +197,6 @@ public:
|
|||||||
bodies[TRG_EVENT_DELETE][TRG_ACTION_AFTER]);
|
bodies[TRG_EVENT_DELETE][TRG_ACTION_AFTER]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_table(TABLE *new_table);
|
|
||||||
|
|
||||||
void mark_fields_used(trg_event_type event);
|
void mark_fields_used(trg_event_type event);
|
||||||
|
|
||||||
void set_parse_error_message(char *error_message);
|
void set_parse_error_message(char *error_message);
|
||||||
|
Reference in New Issue
Block a user