summaryrefslogtreecommitdiff
path: root/sql/field.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/field.cc')
-rw-r--r--sql/field.cc97
1 files changed, 52 insertions, 45 deletions
diff --git a/sql/field.cc b/sql/field.cc
index fbb2ad79ba9..acf0af095a1 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1713,6 +1713,33 @@ int Field::store(const char *to, uint length, CHARSET_INFO *cs,
}
+static int timestamp_to_TIME(THD *thd, MYSQL_TIME *ltime, my_time_t ts,
+ ulong sec_part, ulonglong fuzzydate)
+{
+ thd->time_zone_used= 1;
+ if (ts == 0 && sec_part == 0)
+ {
+ if (fuzzydate & TIME_NO_ZERO_DATE)
+ return 1;
+ set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
+ }
+ else
+ {
+ thd->variables.time_zone->gmt_sec_to_TIME(ltime, ts);
+ ltime->second_part= sec_part;
+ }
+ return 0;
+}
+
+
+int Field::store_timestamp(my_time_t ts, ulong sec_part)
+{
+ MYSQL_TIME ltime;
+ THD *thd= get_thd();
+ timestamp_to_TIME(thd, &ltime, ts, sec_part, 0);
+ return store_time_dec(&ltime, decimals());
+}
+
/**
Pack the field into a format suitable for storage and transfer.
@@ -4810,6 +4837,13 @@ Field_timestamp::Field_timestamp(uchar *ptr_arg, uint32 len_arg,
}
+int Field_timestamp::save_in_field(Field *to)
+{
+ ulong sec_part;
+ my_time_t ts= get_timestamp(&sec_part);
+ return to->store_timestamp(ts, sec_part);
+}
+
my_time_t Field_timestamp::get_timestamp(const uchar *pos,
ulong *sec_part) const
{
@@ -4936,6 +4970,22 @@ int Field_timestamp::store(longlong nr, bool unsigned_val)
}
+int Field_timestamp::store_timestamp(my_time_t ts, ulong sec_part)
+{
+ store_TIME(ts, sec_part);
+ if (ts == 0 && sec_part == 0 &&
+ get_thd()->variables.sql_mode & TIME_NO_ZERO_DATE)
+ {
+ ErrConvString s(
+ STRING_WITH_LEN("0000-00-00 00:00:00.000000") - (decimals() ? 6 - decimals() : 7),
+ system_charset_info);
+ set_datetime_warning(WARN_DATA_TRUNCATED, &s, MYSQL_TIMESTAMP_DATETIME, 1);
+ return 1;
+ }
+ return 0;
+}
+
+
double Field_timestamp::val_real(void)
{
return (double) Field_timestamp::val_int();
@@ -5039,22 +5089,9 @@ Field_timestamp::validate_value_in_record(THD *thd, const uchar *record) const
bool Field_timestamp::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
- THD *thd= get_thd();
- thd->time_zone_used= 1;
ulong sec_part;
- my_time_t temp= get_timestamp(&sec_part);
- if (temp == 0 && sec_part == 0)
- { /* Zero time is "000000" */
- if (fuzzydate & TIME_NO_ZERO_DATE)
- return 1;
- set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
- }
- else
- {
- thd->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)temp);
- ltime->second_part= sec_part;
- }
- return 0;
+ my_time_t ts= get_timestamp(&sec_part);
+ return timestamp_to_TIME(get_thd(), ltime, ts, sec_part, fuzzydate);
}
@@ -5104,36 +5141,6 @@ int Field_timestamp::set_time()
return 0;
}
-/**
- Mark the field as having an explicit default value.
-
- @param value if available, the value that the field is being set to
- @returns whether the explicit default bit was set
-
- @note
- Fields that have an explicit default value should not be updated
- automatically via the DEFAULT or ON UPDATE functions. The functions
- that deal with data change functionality (INSERT/UPDATE/LOAD),
- determine if there is an explicit value for each field before performing
- the data change, and call this method to mark the field.
-
- For timestamp columns, the only case where a column is not marked
- as been given a value are:
- - It's explicitly assigned with DEFAULT
- - We assign NULL to a timestamp field that is defined as NOT NULL.
- This is how MySQL has worked since it's start.
-*/
-
-bool Field_timestamp::set_explicit_default(Item *value)
-{
- if (((value->type() == Item::DEFAULT_VALUE_ITEM &&
- !((Item_default_value*)value)->arg) ||
- (!maybe_null() && value->null_value)))
- return false;
- set_has_explicit_value();
- return true;
-}
-
#ifdef NOT_USED
static void store_native(ulonglong num, uchar *to, uint bytes)
{