summaryrefslogtreecommitdiff
path: root/sql/field.cc
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2016-07-22 13:44:58 +0200
committerSergei Golubchik <serg@mariadb.org>2016-08-27 16:59:12 +0200
commit266563ad775fca38dbb5c76a5100fef49515ffda (patch)
treee94b6621fbdde62b2ab9dd1d3af48db866468a9a /sql/field.cc
parent73a220aac3842da0ab8d51fa9961a18b03c45001 (diff)
downloadmariadb-git-266563ad775fca38dbb5c76a5100fef49515ffda.tar.gz
fix: CREATE TABLE (col TIMESTAMP(6) DEFAULT NOW(2))
That is, when the precision of DEFAULT NOW() is less than the precision of the column, do not convert it to unireg_check, use the new approach where DEFAULT is tryly an expression.
Diffstat (limited to 'sql/field.cc')
-rw-r--r--sql/field.cc58
1 files changed, 21 insertions, 37 deletions
diff --git a/sql/field.cc b/sql/field.cc
index b8816c59d9f..73e6b4edc3c 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -9863,59 +9863,43 @@ bool Column_definition::check(THD *thd)
}
}
}
+
if (default_value && (flags & AUTO_INCREMENT_FLAG))
{
my_error(ER_INVALID_DEFAULT, MYF(0), field_name);
DBUG_RETURN(1);
}
- if (default_value && !default_value->expr_item->basic_const_item())
+ if (default_value && !default_value->expr_item->basic_const_item() &&
+ mysql_type_to_time_type(sql_type) == MYSQL_TIMESTAMP_DATETIME &&
+ default_value->expr_item->type() == Item::FUNC_ITEM)
{
- Item *def_expr= default_value->expr_item;
-
- unireg_check= Field::NONE;
/*
- NOW() for TIMESTAMP and DATETIME fields are handled as in MariaDB 10.1
- by marking them in unireg_check.
+ Special case: NOW() for TIMESTAMP and DATETIME fields are handled
+ as in MariaDB 10.1 by marking them in unireg_check.
*/
- if (def_expr->type() == Item::FUNC_ITEM &&
- (static_cast<Item_func*>(def_expr)->functype() ==
- Item_func::NOW_FUNC &&
- (mysql_type_to_time_type(sql_type) == MYSQL_TIMESTAMP_DATETIME)))
+ Item_func *fn= static_cast<Item_func*>(default_value->expr_item);
+ if (fn->functype() == Item_func::NOW_FUNC &&
+ (fn->decimals == 0 || fn->decimals >= length))
{
- /*
- We are not checking the number of decimals for timestamps
- to allow one to write (for historical reasons)
- TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP
- Instead we are going to use the number of decimals specifed by the
- column.
- */
default_value= 0;
- unireg_check= (on_update ?
- Field::TIMESTAMP_DNUN_FIELD : // for insertions and for updates.
- Field::TIMESTAMP_DN_FIELD); // only for insertions.
+ unireg_check= Field::TIMESTAMP_DN_FIELD;
}
- else if (on_update)
- unireg_check= Field::TIMESTAMP_UN_FIELD; // function default for updates
- }
- else
- {
- /* No function default for insertions. Either NULL or a constant. */
- if (on_update)
- unireg_check= Field::TIMESTAMP_UN_FIELD; // function default for updates
- else
- unireg_check= ((flags & AUTO_INCREMENT_FLAG) ?
- Field::NEXT_NUMBER : // Automatic increment.
- Field::NONE);
}
- if (on_update &&
- (mysql_type_to_time_type(sql_type) != MYSQL_TIMESTAMP_DATETIME ||
- on_update->decimals < length))
+ if (on_update)
{
- my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name);
- DBUG_RETURN(TRUE);
+ if (mysql_type_to_time_type(sql_type) != MYSQL_TIMESTAMP_DATETIME ||
+ on_update->decimals < length)
+ {
+ my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name);
+ DBUG_RETURN(TRUE);
+ }
+ unireg_check= unireg_check == Field::NONE ? Field::TIMESTAMP_UN_FIELD
+ : Field::TIMESTAMP_DNUN_FIELD;
}
+ else if (flags & AUTO_INCREMENT_FLAG)
+ unireg_check= Field::NEXT_NUMBER;
sign_len= flags & UNSIGNED_FLAG ? 0 : 1;