summaryrefslogtreecommitdiff
path: root/sql/field.cc
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2015-06-01 15:51:25 +0200
committerSergei Golubchik <serg@mariadb.org>2015-06-01 15:51:25 +0200
commit5091a4ba755250ed8e35f4f5a39a118d476cd8f1 (patch)
tree370ba468d78204544b56e9d967d8d09e1317a1ed /sql/field.cc
parent84eaf0911f311acba797c265ef7508ab6c108b35 (diff)
parent0880284bf715b4916cc735e19b76d1062c2bfdcf (diff)
downloadmariadb-git-5091a4ba755250ed8e35f4f5a39a118d476cd8f1.tar.gz
Merge tag 'mariadb-10.0.19' into 10.1
Diffstat (limited to 'sql/field.cc')
-rw-r--r--sql/field.cc69
1 files changed, 43 insertions, 26 deletions
diff --git a/sql/field.cc b/sql/field.cc
index e99f48dd078..fe673469269 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -10039,35 +10039,52 @@ Create_field::Create_field(Field *old_field,Field *orig_field)
char_length= length;
/*
- Copy the default value from the column object orig_field, if:
- 1) The column has a constant default value.
- 2) The column type is not a BLOB type.
- 3) The original column (old_field) was properly initialized with a record
- buffer pointer.
- 4) The original column doesn't have a default function to auto-initialize
- the column on INSERT
+ Copy the default (constant/function) from the column object orig_field, if
+ supplied. We do this if all these conditions are met:
+
+ - The column allows a default.
+
+ - The column type is not a BLOB type.
+
+ - The original column (old_field) was properly initialized with a record
+ buffer pointer.
*/
- if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) && // 1) 2)
- old_field->ptr && orig_field && // 3)
- !old_field->has_insert_default_function()) // 4)
- {
- char buff[MAX_FIELD_WIDTH];
- String tmp(buff,sizeof(buff), charset);
- my_ptrdiff_t diff;
-
- /* 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 (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
+ old_field->ptr != NULL &&
+ orig_field != NULL)
+ {
+ bool default_now= false;
+ if (real_type_with_now_as_default(sql_type))
{
- char buff[MAX_FIELD_WIDTH], *pos;
- String tmp(buff, sizeof(buff), charset), *res;
- res= orig_field->val_str(&tmp);
- pos= (char*) sql_strmake(res->ptr(), res->length());
- def= new Item_string(pos, res->length(), charset);
+ // The SQL type of the new field allows a function default:
+ default_now= orig_field->has_insert_default_function();
+ bool update_now= orig_field->has_update_default_function();
+
+ if (default_now && update_now)
+ unireg_check= Field::TIMESTAMP_DNUN_FIELD;
+ else if (default_now)
+ unireg_check= Field::TIMESTAMP_DN_FIELD;
+ else if (update_now)
+ unireg_check= Field::TIMESTAMP_UN_FIELD;
+ }
+ if (!default_now) // Give a constant default
+ {
+ char buff[MAX_FIELD_WIDTH];
+ String tmp(buff,sizeof(buff), charset);
+
+ /* 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())
+ {
+ char buff[MAX_FIELD_WIDTH], *pos;
+ String tmp(buff, sizeof(buff), charset), *res;
+ res= orig_field->val_str(&tmp);
+ pos= (char*) sql_strmake(res->ptr(), res->length());
+ def= new Item_string(pos, res->length(), charset);
+ }
+ orig_field->move_field_offset(-diff); // Back to record[0]
}
- orig_field->move_field_offset(-diff); // Back to record[0]
}
}