diff options
author | Sergei Golubchik <serg@mariadb.org> | 2015-12-16 12:12:01 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2015-12-21 21:30:46 +0100 |
commit | ad5db17e882fea36dcae6f6e61996b5f9bf28962 (patch) | |
tree | 06fa978199bd8fb09874de989984381e28bb4715 /sql | |
parent | de7636e1470848bb5d92437b7c6c7b9c4d6caedc (diff) | |
download | mariadb-git-ad5db17e882fea36dcae6f6e61996b5f9bf28962.tar.gz |
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
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field_conv.cc | 49 | ||||
-rw-r--r-- | sql/handler.cc | 4 | ||||
-rw-r--r-- | sql/item.cc | 14 | ||||
-rw-r--r-- | sql/sql_base.cc | 2 | ||||
-rw-r--r-- | sql/sql_insert.cc | 10 | ||||
-rw-r--r-- | sql/sql_load.cc | 14 | ||||
-rw-r--r-- | sql/sql_trigger.cc | 15 | ||||
-rw-r--r-- | sql/sql_trigger.h | 2 |
8 files changed, 43 insertions, 67 deletions
diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 0ad8cee0c3b..df4730a50ce 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -116,24 +116,11 @@ static void do_outer_field_to_null_str(Copy_field *copy) } -int -set_field_to_null(Field *field) +static int set_bad_null_error(Field *field, int err) { - if (field->table->null_catch_flags & CHECK_ROW_FOR_NULLS_TO_REJECT) - { - field->table->null_catch_flags|= REJECT_ROW_DUE_TO_NULL_FIELDS; - return -1; - } - if (field->real_maybe_null()) - { - field->set_null(); - field->reset(); - return 0; - } - field->reset(); switch (field->table->in_use->count_cuted_fields) { case CHECK_FIELD_WARN: - field->set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1); + field->set_warning(Sql_condition::WARN_LEVEL_WARN, err, 1); /* fall through */ case CHECK_FIELD_IGNORE: return 0; @@ -147,6 +134,24 @@ set_field_to_null(Field *field) } +int set_field_to_null(Field *field) +{ + if (field->table->null_catch_flags & CHECK_ROW_FOR_NULLS_TO_REJECT) + { + field->table->null_catch_flags|= REJECT_ROW_DUE_TO_NULL_FIELDS; + return -1; + } + if (field->real_maybe_null()) + { + field->set_null(); + field->reset(); + return 0; + } + field->reset(); + return set_bad_null_error(field, WARN_DATA_TRUNCATED); +} + + /** Set field to NULL or TIMESTAMP or to next auto_increment number. @@ -200,19 +205,7 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions) field->table->auto_increment_field_not_null= FALSE; return 0; // field is set in fill_record() } - switch (field->table->in_use->count_cuted_fields) { - 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; + return set_bad_null_error(field, ER_BAD_NULL_ERROR); } diff --git a/sql/handler.cc b/sql/handler.cc index 193d36a1122..bd415122388 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -532,10 +532,6 @@ int ha_initialize_handlerton(st_plugin_int *plugin) 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) { case SHOW_OPTION_NO: break; diff --git a/sql/item.cc b/sql/item.cc index 0f10ccbd88c..e3c93a8da61 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -44,8 +44,7 @@ const String my_null_string("NULL", 4, default_charset_info); -static int save_field_in_field(Field *from, bool *null_value, - Field *to, bool no_conversions); +static int save_field_in_field(Field *, bool *, Field *, bool); /** @@ -8159,7 +8158,8 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions) { 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 && 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) { - TABLE_LIST *view= field_arg->table->pos_in_table_list->top_table(); - push_warning_printf(thd, - Sql_condition::WARN_LEVEL_WARN, + TABLE_LIST *view= table->pos_in_table_list->top_table(); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NO_DEFAULT_FOR_VIEW_FIELD, ER_THD(thd, ER_NO_DEFAULT_FOR_VIEW_FIELD), view->view_db.str, @@ -8183,8 +8182,7 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions) } else { - push_warning_printf(thd, - Sql_condition::WARN_LEVEL_WARN, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NO_DEFAULT_FOR_FIELD, ER_THD(thd, ER_NO_DEFAULT_FOR_FIELD), field_arg->field_name); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 90ba0451e30..1ab496325a8 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -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 updated by the triggers. */ - if (!result && triggers && table) + if (!result && triggers) { List_iterator_fast<Item> f(fields); Item *fld; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index a04cbb573e1..04e18403f78 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -113,9 +113,9 @@ static bool check_view_insertability(THD *thd, TABLE_LIST *view); @returns false if success. */ -bool check_view_single_update(List<Item> &fields, List<Item> *values, - TABLE_LIST *view, table_map *map, - bool insert) +static bool check_view_single_update(List<Item> &fields, List<Item> *values, + TABLE_LIST *view, table_map *map, + bool insert) { /* it is join view => we need to find the table for update */ 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; } - if (!res) - res= setup_fields(thd, 0, update_values, MARK_COLUMNS_READ, 0, 0); + if (!res) + res= setup_fields(thd, 0, update_values, MARK_COLUMNS_READ, 0, 0); if (!res && duplic == DUP_UPDATE) { diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 9cf82c1c6d0..aed26bd2fa5 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -767,7 +767,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, List_iterator_fast<Item> it(fields_vars); Item_field *sql_field; 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; 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) 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()) { 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++)) { Field *field= sql_field->field; - if (field == table->next_number_field) - table->auto_increment_field_not_null= TRUE; + table->auto_increment_field_not_null= auto_increment_field_not_null; /* 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 @@ -874,8 +879,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, (table->default_field && table->update_default_fields())) DBUG_RETURN(1); - switch (table_list->view_check_option(thd, - ignore_check_option_errors)) { + switch (table_list->view_check_option(thd, ignore_check_option_errors)) { case VIEW_CHECK_SKIP: read_info.next_line(); goto continue_loop; diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 58fd7aeb7dc..bea19f1329c 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -1101,20 +1101,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. @param thd current thread context @@ -2125,6 +2111,7 @@ bool Table_triggers_list::process_triggers(THD *thd, } else { + DBUG_ASSERT(event == TRG_EVENT_DELETE); new_field= record1_field; old_field= trigger_table->field; } diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h index 7dfe8939945..1885720bf8b 100644 --- a/sql/sql_trigger.h +++ b/sql/sql_trigger.h @@ -197,8 +197,6 @@ public: bodies[TRG_EVENT_DELETE][TRG_ACTION_AFTER]); } - void set_table(TABLE *new_table); - void mark_fields_used(trg_event_type event); void set_parse_error_message(char *error_message); |