diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.h | 22 | ||||
-rw-r--r-- | sql/sql_base.cc | 4 | ||||
-rw-r--r-- | sql/sql_insert.cc | 7 | ||||
-rw-r--r-- | sql/sql_table.cc | 4 | ||||
-rw-r--r-- | sql/sql_update.cc | 16 | ||||
-rw-r--r-- | sql/table.cc | 28 | ||||
-rw-r--r-- | sql/table.h | 3 |
7 files changed, 33 insertions, 51 deletions
diff --git a/sql/field.h b/sql/field.h index c82febd956e..73c36affce0 100644 --- a/sql/field.h +++ b/sql/field.h @@ -992,14 +992,6 @@ public: } bool set_explicit_default(Item *value); - /** - Evaluates the @c UPDATE default function, if one exists, and stores the - result in the record buffer. If no such function exists for the column, - or the function is not valid for the column's data type, invoking this - function has no effect. - */ - virtual int evaluate_update_default_function() { return 0; } - virtual bool binary() const { return 1; } virtual bool zero_pack() const { return 1; } virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } @@ -2519,13 +2511,6 @@ public: void sql_type(String &str) const; bool zero_pack() const { return 0; } int set_time(); - int evaluate_update_default_function() - { - int res= 0; - if (has_update_default_function()) - res= set_time(); - return res; - } /* Get TIMESTAMP field value as seconds since begging of Unix Epoch */ virtual my_time_t get_timestamp(const uchar *pos, ulong *sec_part) const; my_time_t get_timestamp(ulong *sec_part) const @@ -2954,13 +2939,6 @@ public: bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) { return Field_datetime::get_TIME(ltime, ptr, fuzzydate); } int set_time(); - int evaluate_update_default_function() - { - int res= 0; - if (has_update_default_function()) - res= set_time(); - return res; - } uchar *pack(uchar* to, const uchar *from, uint max_length __attribute__((unused))) { diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 662ba3f6b30..14740274b87 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -8072,7 +8072,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values, } if (!update && table_arg->default_field && - table_arg->update_default_fields(0, ignore_errors)) + table_arg->update_default_fields(ignore_errors)) goto err; /* Update virtual fields */ if (table_arg->vfield && @@ -8317,7 +8317,7 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values, all_fields_have_values &= field->set_explicit_default(value); } if (!all_fields_have_values && table->default_field && - table->update_default_fields(0, ignore_errors)) + table->update_default_fields(ignore_errors)) goto err; /* Update virtual fields */ thd->abort_on_warning= FALSE; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 78564f28c31..550851bd215 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1796,10 +1796,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) be updated as if this is an UPDATE. */ if (different_records && table->default_field) - { - if (table->update_default_fields(1, info->ignore)) - goto err; - } + table->evaluate_update_default_function(); /* CHECK OPTION for VIEW ... ON DUPLICATE KEY UPDATE ... */ res= info->table_list->view_check_option(table->in_use, info->ignore); @@ -3762,7 +3759,7 @@ int select_insert::send_data(List<Item> &values) thd->count_cuted_fields= CHECK_FIELD_WARN; // Calculate cuted fields store_values(values); - if (table->default_field && table->update_default_fields(0, info.ignore)) + if (table->default_field && table->update_default_fields(info.ignore)) DBUG_RETURN(1); thd->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL; if (thd->is_error()) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 33589b3044d..761e14e31d0 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -9455,7 +9455,7 @@ do_continue:; /* Check that we can call default functions with default field values */ altered_table->reset_default_fields(); if (altered_table->default_field && - altered_table->update_default_fields(0, 1)) + altered_table->update_default_fields(true)) goto err_new_table_cleanup; // Ask storage engine whether to use copy or in-place @@ -10138,7 +10138,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, } prev_insert_id= to->file->next_insert_id; if (to->default_field) - to->update_default_fields(0, ignore); + to->update_default_fields(ignore); if (to->vfield) to->update_virtual_fields(to->file, VCOL_UPDATE_FOR_WRITE); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 1d1c38f59d6..4f129eb995a 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -761,11 +761,8 @@ int mysql_update(THD *thd, if (!can_compare_record || compare_record(table)) { - if (table->default_field && table->update_default_fields(1, ignore)) - { - error= 1; - break; - } + if (table->default_field) + table->evaluate_update_default_function(); if ((res= table_list->view_check_option(thd, ignore)) != VIEW_CHECK_OK) { @@ -2156,8 +2153,8 @@ int multi_update::send_data(List<Item> ¬_used_values) { int error; - if (table->default_field && table->update_default_fields(1, ignore)) - DBUG_RETURN(1); + if (table->default_field) + table->evaluate_update_default_function(); if ((error= cur_table->view_check_option(thd, ignore)) != VIEW_CHECK_OK) @@ -2482,9 +2479,8 @@ int multi_update::do_updates() if (!can_compare_record || compare_record(table)) { int error; - if (table->default_field && - (error= table->update_default_fields(1, ignore))) - goto err2; + if (table->default_field) + table->evaluate_update_default_function(); if (table->vfield && table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE)) goto err2; diff --git a/sql/table.cc b/sql/table.cc index 07858ab270a..e39b73b2f4b 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -7736,7 +7736,7 @@ int TABLE::update_virtual_field(Field *vf) ignore_errors == 0. If set then an error was generated. */ -int TABLE::update_default_fields(bool update_command, bool ignore_errors) +int TABLE::update_default_fields(bool ignore_errors) { Query_arena backup_arena; Field **field_ptr; @@ -7756,14 +7756,9 @@ int TABLE::update_default_fields(bool update_command, bool ignore_errors) */ if (!field->has_explicit_value()) { - if (!update_command) - { - if (field->default_value && - (field->default_value->flags || field->flags & BLOB_FLAG)) - res|= (field->default_value->expr->save_in_field(field, 0) < 0); - } - else - res|= field->evaluate_update_default_function(); + if (field->default_value && + (field->default_value->flags || field->flags & BLOB_FLAG)) + res|= (field->default_value->expr->save_in_field(field, 0) < 0); if (!ignore_errors && res) { my_error(ER_CALCULATING_DEFAULT_VALUE, MYF(0), field->field_name); @@ -7776,6 +7771,21 @@ int TABLE::update_default_fields(bool update_command, bool ignore_errors) DBUG_RETURN(res); } +void TABLE::evaluate_update_default_function() +{ + DBUG_ENTER("TABLE::evaluate_update_default_function"); + + if (s->has_update_default_function) + for (Field **field_ptr= default_field; *field_ptr ; field_ptr++) + { + Field *field= (*field_ptr); + if (!field->has_explicit_value() && field->has_update_default_function()) + field->set_time(); + } + DBUG_VOID_RETURN; +} + + /** Reset markers that fields are being updated */ diff --git a/sql/table.h b/sql/table.h index 8f6a9e7aa86..f10e00562dc 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1453,7 +1453,8 @@ public: ulong actual_key_flags(KEY *keyinfo); int update_virtual_field(Field *vf); int update_virtual_fields(handler *h, enum_vcol_update_mode update_mode); - int update_default_fields(bool update, bool ignore_errors); + int update_default_fields(bool ignore_errors); + void evaluate_update_default_function(); void reset_default_fields(); inline ha_rows stat_records() { return used_stat_records; } |