Commit 3a0df3cf authored by Alexander Barkov's avatar Alexander Barkov

MDEV-8372 Use helper methods introduced in MDEV-7824 all around the code

parent 3079bd43
...@@ -10434,16 +10434,14 @@ Create_field::Create_field(THD *thd, Field *old_field, Field *orig_field) ...@@ -10434,16 +10434,14 @@ Create_field::Create_field(THD *thd, Field *old_field, Field *orig_field)
if (!default_now) // Give a constant default if (!default_now) // Give a constant default
{ {
/* Get the value from default_values */ /* Get the value from default_values */
my_ptrdiff_t diff= orig_field->table->default_values_offset(); const uchar *dv= orig_field->table->s->default_values;
orig_field->move_field_offset(diff); // Points now at default_values if (!orig_field->is_null_in_record(dv))
if (!orig_field->is_real_null())
{ {
StringBuffer<MAX_FIELD_WIDTH> tmp(charset); StringBuffer<MAX_FIELD_WIDTH> tmp(charset);
String *res= orig_field->val_str(&tmp); String *res= orig_field->val_str(&tmp, orig_field->ptr_in_record(dv));
char *pos= (char*) sql_strmake(res->ptr(), res->length()); char *pos= (char*) sql_strmake(res->ptr(), res->length());
def= new (thd->mem_root) Item_string(thd, pos, res->length(), charset); def= new (thd->mem_root) Item_string(thd, pos, res->length(), charset);
} }
orig_field->move_field_offset(-diff); // Back to record[0]
} }
} }
} }
......
...@@ -16571,20 +16571,17 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields, ...@@ -16571,20 +16571,17 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
inherit the default value that is defined for the field referred inherit the default value that is defined for the field referred
by the Item_field object from which 'field' has been created. by the Item_field object from which 'field' has been created.
*/ */
my_ptrdiff_t diff; const Field *orig_field= default_field[i];
Field *orig_field= default_field[i];
/* Get the value from default_values */ /* Get the value from default_values */
diff= (my_ptrdiff_t) (orig_field->table->s->default_values- if (orig_field->is_null_in_record(orig_field->table->s->default_values))
orig_field->table->record[0]);
orig_field->move_field_offset(diff); // Points now at default_values
if (orig_field->is_real_null())
field->set_null(); field->set_null();
else else
{ {
field->set_notnull(); field->set_notnull();
memcpy(field->ptr, orig_field->ptr, field->pack_length()); memcpy(field->ptr,
orig_field->ptr_in_record(orig_field->table->s->default_values),
field->pack_length());
} }
orig_field->move_field_offset(-diff); // Back to record[0]
} }
if (from_field[i]) if (from_field[i])
......
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