1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

Removing duplicate code: Adding a protected method

Field_temporal_with_date::validate_for_get_date()
and reusing it in a few places.
This commit is contained in:
Alexander Barkov
2015-06-18 22:16:44 +04:00
parent f5ddffd83e
commit 091f67738e
2 changed files with 13 additions and 20 deletions

View File

@@ -5985,11 +5985,7 @@ bool Field_newdate::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate)
ltime->year= (tmp >> 9); ltime->year= (tmp >> 9);
ltime->time_type= MYSQL_TIMESTAMP_DATE; ltime->time_type= MYSQL_TIMESTAMP_DATE;
ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0; ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0;
if (!tmp) return validate_for_get_date(tmp, ltime, fuzzydate);
return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day)
return fuzzydate & TIME_NO_ZERO_IN_DATE;
return 0;
} }
@@ -6113,11 +6109,7 @@ bool Field_datetime::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
ltime->day= (int) (part1%100); ltime->day= (int) (part1%100);
ltime->month= (int) (part1/100%100); ltime->month= (int) (part1/100%100);
ltime->year= (int) (part1/10000); ltime->year= (int) (part1/10000);
if (!tmp) return validate_for_get_date(tmp, ltime, fuzzydate);
return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day)
return fuzzydate & TIME_NO_ZERO_IN_DATE;
return 0;
} }
int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr) 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()); ulonglong packed= read_bigendian(ptr, Field_datetime_hires::pack_length());
unpack_time(sec_part_unshift(packed, dec), ltime); unpack_time(sec_part_unshift(packed, dec), ltime);
if (!packed) return validate_for_get_date(packed, ltime, fuzzydate);
return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day)
return fuzzydate & TIME_NO_ZERO_IN_DATE;
return 0;
} }
uint32 Field_datetime_hires::pack_length() const 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); longlong tmp= my_datetime_packed_from_binary(ptr, dec);
TIME_from_longlong_datetime_packed(ltime, tmp); TIME_from_longlong_datetime_packed(ltime, tmp);
if (!tmp) return validate_for_get_date(tmp, ltime, fuzzydate);
return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day)
return fuzzydate & TIME_NO_ZERO_IN_DATE;
return false;
} }

View File

@@ -1681,6 +1681,15 @@ protected:
int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str, int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str,
int was_cut, int have_smth_to_conv); int was_cut, int have_smth_to_conv);
virtual void store_TIME(MYSQL_TIME *ltime) = 0; 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: public:
Field_temporal_with_date(uchar *ptr_arg, uint32 len_arg, Field_temporal_with_date(uchar *ptr_arg, uint32 len_arg,
uchar *null_ptr_arg, uchar null_bit_arg, uchar *null_ptr_arg, uchar null_bit_arg,