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

MDEV-34069 Zero datetime reinterprets as '1970-01-01 00:00:00' on field_datetime=field_timestamp

The code in Field_timestamp::save_in_field() did not catch
zero datetime and stored it to the other field like a usual value
using store_timestamp_dec(), which knows nothing about zero date and
treats {tv_sec=0, tv_usec=0} as a normal timeval value corresponding to
'1970-01-01 00:00:00 +00:00'.

Fixing the code to catch the special combination (ts==0 && sec_pat==0) and
store it using store_time_dec() with a zero datetime passed as an argument.
This commit is contained in:
Alexander Barkov
2024-05-04 22:34:14 +04:00
parent 88f49da8e0
commit 1cdf22374b
3 changed files with 52 additions and 0 deletions

View File

@ -5184,6 +5184,8 @@ int Field_timestamp::save_in_field(Field *to)
{
ulong sec_part;
my_time_t ts= get_timestamp(&sec_part);
if (!ts && !sec_part)
return to->store_time_dec(Datetime::zero().get_mysql_time(), decimals());
return to->store_timestamp_dec(Timeval(ts, sec_part), decimals());
}