Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vuvova committed Dec 21, 2015
1 parent de7636e commit ad5db17
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 67 deletions.
49 changes: 21 additions & 28 deletions sql/field_conv.cc
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}


Expand Down
4 changes: 0 additions & 4 deletions sql/handler.cc
Expand Up @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions sql/item.cc
Expand Up @@ -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);


/**
Expand Down Expand Up @@ -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)
Expand All @@ -8173,18 +8173,16 @@ 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,
view->view_name.str);
}
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);
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_base.cc
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions sql/sql_insert.cc
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
14 changes: 9 additions & 5 deletions sql/sql_load.cc
Expand Up @@ -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");

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 1 addition & 14 deletions sql/sql_trigger.cc
Expand Up @@ -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.

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions sql/sql_trigger.h
Expand Up @@ -197,8 +197,6 @@ class Table_triggers_list: public Sql_alloc
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);
Expand Down

0 comments on commit ad5db17

Please sign in to comment.