Commit 091f6773 authored by Alexander Barkov's avatar Alexander Barkov

Removing duplicate code: Adding a protected method

Field_temporal_with_date::validate_for_get_date()
and reusing it in a few places.
parent f5ddffd8
......@@ -5985,11 +5985,7 @@ bool Field_newdate::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate)
ltime->year= (tmp >> 9);
ltime->time_type= MYSQL_TIMESTAMP_DATE;
ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0;
if (!tmp)
return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day)
return fuzzydate & TIME_NO_ZERO_IN_DATE;
return 0;
return validate_for_get_date(tmp, ltime, fuzzydate);
}
......@@ -6113,11 +6109,7 @@ bool Field_datetime::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
ltime->day= (int) (part1%100);
ltime->month= (int) (part1/100%100);
ltime->year= (int) (part1/10000);
if (!tmp)
return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day)
return fuzzydate & TIME_NO_ZERO_IN_DATE;
return 0;
return validate_for_get_date(tmp, ltime, fuzzydate);
}
int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr)
......@@ -6235,11 +6227,7 @@ bool Field_datetime_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
ulonglong packed= read_bigendian(ptr, Field_datetime_hires::pack_length());
unpack_time(sec_part_unshift(packed, dec), ltime);
if (!packed)
return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day)
return fuzzydate & TIME_NO_ZERO_IN_DATE;
return 0;
return validate_for_get_date(packed, ltime, fuzzydate);
}
uint32 Field_datetime_hires::pack_length() const
......@@ -6282,11 +6270,7 @@ bool Field_datetimef::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
longlong tmp= my_datetime_packed_from_binary(ptr, dec);
TIME_from_longlong_datetime_packed(ltime, tmp);
if (!tmp)
return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day)
return fuzzydate & TIME_NO_ZERO_IN_DATE;
return false;
return validate_for_get_date(tmp, ltime, fuzzydate);
}
......
......@@ -1681,6 +1681,15 @@ class Field_temporal_with_date: public Field_temporal {
int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str,
int was_cut, int have_smth_to_conv);
virtual void store_TIME(MYSQL_TIME *ltime) = 0;
bool validate_for_get_date(bool not_zero_date, const MYSQL_TIME *ltime,
ulonglong fuzzydate)
{
if (!not_zero_date)
return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day)
return fuzzydate & TIME_NO_ZERO_IN_DATE;
return false;
}
public:
Field_temporal_with_date(uchar *ptr_arg, uint32 len_arg,
uchar *null_ptr_arg, uchar null_bit_arg,
......
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