diff options
author | Sergei Golubchik <serg@mariadb.org> | 2019-03-17 13:06:41 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2019-03-17 13:06:41 +0100 |
commit | b64fde8f38515dc39e019de26db7624cc0ea7046 (patch) | |
tree | 0478ea4c3ddeee290f6d381a47efa4f9aded9c0b /sql/item_timefunc.cc | |
parent | a89ee3cd154a67df2231f034fd8339f9225dbe64 (diff) | |
parent | 1f020299f816263e347c852eb2a494b5ef1cbf0d (diff) | |
download | mariadb-git-b64fde8f38515dc39e019de26db7624cc0ea7046.tar.gz |
Merge branch '10.2' into 10.3
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r-- | sql/item_timefunc.cc | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 25fecd0a134..2339c6afbdc 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -456,7 +456,7 @@ err: Create a formated date/time value in a string. */ -static bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time, +static bool make_date_time(const LEX_CSTRING &format, MYSQL_TIME *l_time, timestamp_type type, const MY_LOCALE *locale, String *str) { @@ -471,7 +471,7 @@ static bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time, if (l_time->neg) str->append('-'); - end= (ptr= format->format.str) + format->format.length; + end= (ptr= format.str) + format.length; for (; ptr != end ; ptr++) { if (*ptr != '%' || ptr+1 == end) @@ -591,7 +591,7 @@ static bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time, str->append_with_prefill(intbuff, length, 2, '0'); break; case 'j': - if (type == MYSQL_TIMESTAMP_TIME) + if (type == MYSQL_TIMESTAMP_TIME || !l_time->month || !l_time->year) return 1; length= (uint) (int10_to_str(calc_daynr(l_time->year,l_time->month, l_time->day) - @@ -1992,6 +1992,7 @@ uint Item_func_date_format::format_length(const String *format) String *Item_func_date_format::val_str(String *str) { + StringBuffer<64> format_buffer; String *format; MYSQL_TIME l_time; uint size; @@ -2001,7 +2002,7 @@ String *Item_func_date_format::val_str(String *str) if ((null_value= args[0]->get_date(&l_time, is_time_format ? TIME_TIME_ONLY : 0))) return 0; - if (!(format = args[1]->val_str(str)) || !format->length()) + if (!(format= args[1]->val_str(&format_buffer)) || !format->length()) goto null_date; if (!is_time_format && !(lc= locale) && !(lc= args[2]->locale_from_val_str())) @@ -2015,18 +2016,13 @@ String *Item_func_date_format::val_str(String *str) if (size < MAX_DATE_STRING_REP_LENGTH) size= MAX_DATE_STRING_REP_LENGTH; - if (format == str) - str= &value; // Save result here + DBUG_ASSERT(format != str); if (str->alloc(size)) goto null_date; - DATE_TIME_FORMAT date_time_format; - date_time_format.format.str= (char*) format->ptr(); - date_time_format.format.length= format->length(); - /* Create the result string */ str->set_charset(collation.collation); - if (!make_date_time(&date_time_format, &l_time, + if (!make_date_time(format->lex_cstring(), &l_time, is_time_format ? MYSQL_TIMESTAMP_TIME : MYSQL_TIMESTAMP_DATE, lc, str)) |