Commit ad5db17e authored by Sergei Golubchik's avatar Sergei Golubchik

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
parent de7636e1
......@@ -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);
}
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -113,7 +113,7 @@ 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,
static bool check_view_single_update(List<Item> &fields, List<Item> *values,
TABLE_LIST *view, table_map *map,
bool insert)
{
......
......@@ -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;
......
......@@ -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.
......@@ -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;
}
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment