diff options
author | Alexander Barkov <bar@mariadb.com> | 2018-10-01 12:34:03 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2018-10-01 12:34:03 +0400 |
commit | e5aebc1408f1413f6251400956da872c9b4f51b6 (patch) | |
tree | a69ac2523b4fea8915cb62490c9033da7cb154f8 /sql-common | |
parent | f79bab3ae68393cb2f36fa83546e8ea02b7d0420 (diff) | |
download | mariadb-git-e5aebc1408f1413f6251400956da872c9b4f51b6.tar.gz |
A cleanup for MDEV-17317 Add THD* parameter into Item::get_date() and stricter data type control to "fuzzydate"
Fixing C++ function check_date() to get the "fuzzydate" as
date_mode_t rather than ulonglong, so conversion from
date_time_t to ulonglong is now done inside C++ check_date(),
and no conversion is needed in the callers' code.
As an additional safety, modified the code not to pass
TIME_FUZZY_DATE to the low level C functions:
- check_date()
- str_to_datetime()
- str_to_time()
- number_to_datetime()
because TIME_FUZZY_DATE is known only on the C++ level,
C functions do not know it.
Soon we'll be adding more flags into the C++ level (i.e. to date_time_t),
e.g. for rounding. It's a good idea to prevent passing C++ specific
flags into pure C routines before this change.
Asserts were added into the affected C functions to verify
that the caller passed only known C level flags.
Diffstat (limited to 'sql-common')
-rw-r--r-- | sql-common/my_time.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 0ad6d64a1b9..2841d33f7fd 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -58,6 +58,20 @@ uint calc_days_in_year(uint year) 366 : 365); } + +#ifndef DBUG_OFF + +static const ulonglong C_KNOWN_FLAGS= C_TIME_NO_ZERO_IN_DATE | + C_TIME_NO_ZERO_DATE | + C_TIME_INVALID_DATES | + C_TIME_TIME_ONLY | + C_TIME_DATETIME_ONLY; + +#define C_FLAGS_OK(flags) (((flags) & ~C_KNOWN_FLAGS) == 0) + +#endif + + /** @brief Check datetime value for validity according to flags. @@ -82,6 +96,7 @@ uint calc_days_in_year(uint year) my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date, ulonglong flags, int *was_cut) { + DBUG_ASSERT(C_FLAGS_OK(flags)); if (ltime->time_type == MYSQL_TIMESTAMP_TIME) return FALSE; if (not_zero_date) @@ -298,6 +313,7 @@ str_to_datetime(const char *str, size_t length, MYSQL_TIME *l_time, const char *end=str+length, *pos; uint number_of_fields= 0, digits, year_length, not_zero_date; DBUG_ENTER("str_to_datetime"); + DBUG_ASSERT(C_FLAGS_OK(flags)); bzero(l_time, sizeof(*l_time)); if (flags & C_TIME_TIME_ONLY) @@ -464,6 +480,7 @@ my_bool str_to_time(const char *str, size_t length, MYSQL_TIME *l_time, const char *end=str+length, *end_of_days; my_bool found_days,found_hours, neg= 0; uint UNINIT_VAR(state); + DBUG_ASSERT(C_FLAGS_OK(fuzzydate)); my_time_status_init(status); for (; str != end && my_isspace(&my_charset_latin1,*str) ; str++) @@ -1209,6 +1226,7 @@ longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res, ulonglong flags, int *was_cut) { long part1,part2; + DBUG_ASSERT(C_FLAGS_OK(flags)); *was_cut= 0; time_res->time_type=MYSQL_TIMESTAMP_DATE; |