Skip to content

Commit

Permalink
MDEV-8372 Use helper methods introduced in MDEV-7824 all around the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Barkov committed Sep 15, 2015
1 parent 3079bd4 commit 3a0df3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
8 changes: 3 additions & 5 deletions sql/field.cc
Expand Up @@ -10434,16 +10434,14 @@ Create_field::Create_field(THD *thd, Field *old_field, Field *orig_field)
if (!default_now) // Give a constant default
{
/* Get the value from default_values */
my_ptrdiff_t diff= orig_field->table->default_values_offset();
orig_field->move_field_offset(diff); // Points now at default_values
if (!orig_field->is_real_null())
const uchar *dv= orig_field->table->s->default_values;
if (!orig_field->is_null_in_record(dv))
{
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());
def= new (thd->mem_root) Item_string(thd, pos, res->length(), charset);
}
orig_field->move_field_offset(-diff); // Back to record[0]
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions sql/sql_select.cc
Expand Up @@ -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
by the Item_field object from which 'field' has been created.
*/
my_ptrdiff_t diff;
Field *orig_field= default_field[i];
const Field *orig_field= default_field[i];
/* Get the value from default_values */
diff= (my_ptrdiff_t) (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())
if (orig_field->is_null_in_record(orig_field->table->s->default_values))
field->set_null();
else
{
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])
Expand Down

0 comments on commit 3a0df3c

Please sign in to comment.