1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-26765 UNIX_TIMESTAMP(CURRENT_TIME()) return null ?!?

Problem:

UNIX_TIMESTAMP() called for a expression of the TIME data type
returned NULL.

Inside Type_handler_timestamp_common::Item_val_native_with_conversion
the call for item->get_date() did not convert TIME to DATETIME
automatically (because it does not have to, by design).
As a result, Type_handler_timestamp_common::TIME_to_native() received
a MYSQL_TIME value with zero date 0000-00-00 and therefore returned "true"
(indicating SQL NULL value).

Fix:

Removing the call for item->get_date().
Instantiating Datetime(item) instead.
This forces automatic TIME to DATETIME conversion
(unless @@old_mode is zero_date_time_cast).
This commit is contained in:
Alexander Barkov
2023-03-29 11:56:44 +04:00
parent 113bef50e3
commit 03b4a2d6e5
5 changed files with 104 additions and 3 deletions

View File

@ -8619,13 +8619,13 @@ Type_handler_timestamp_common::Item_val_native_with_conversion(THD *thd,
Item *item,
Native *to) const
{
MYSQL_TIME ltime;
if (item->type_handler()->type_handler_for_native_format() ==
&type_handler_timestamp2)
return item->val_native(thd, to);
Datetime dt(thd, item, Datetime::Options(TIME_NO_ZERO_IN_DATE, thd));
return
item->get_date(thd, &ltime, Datetime::Options(TIME_NO_ZERO_IN_DATE, thd)) ||
TIME_to_native(thd, &ltime, to, item->datetime_precision(thd));
!dt.is_valid_datetime() ||
TIME_to_native(thd, dt.get_mysql_time(), to, item->datetime_precision(thd));
}
bool Type_handler_null::union_element_finalize(Item_type_holder *item) const