Commit 2c198770 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-34061 unix_timestamp(coalesce(timestamp_column)) returns NULL on '1970-01-01 00:00:00.000001'

Field_timestampf::val_native() checked only the
first four bytes to detect zero dates.
That was not enough. Fixing the code to check all packed_length()
bytes to detect zero dates.
parent 1cdf2237
......@@ -1398,5 +1398,16 @@ DROP TABLE t2, t1;
SET time_zone=DEFAULT;
SET sql_mode=DEFAULT;
#
# MDEV-34061 unix_timestamp(coalesce(timestamp_column)) returns NULL on '1970-01-01 00:00:00.000001'
#
SET time_zone='+00:00';
CREATE TABLE t1 (a TIMESTAMP(6) NULL);
INSERT INTO t1 VALUES ('1970-01-01 00:00:00.000001');
SELECT unix_timestamp(a) AS c1, unix_timestamp(coalesce(a)) AS c2 FROM t1;
c1 c2
0.000001 0.000001
DROP TABLE t1;
SET time_zone=DEFAULT;
#
# End of 10.5 tests
#
......@@ -940,6 +940,17 @@ DROP TABLE t2, t1;
SET time_zone=DEFAULT;
SET sql_mode=DEFAULT;
--echo #
--echo # MDEV-34061 unix_timestamp(coalesce(timestamp_column)) returns NULL on '1970-01-01 00:00:00.000001'
--echo #
SET time_zone='+00:00';
CREATE TABLE t1 (a TIMESTAMP(6) NULL);
INSERT INTO t1 VALUES ('1970-01-01 00:00:00.000001');
SELECT unix_timestamp(a) AS c1, unix_timestamp(coalesce(a)) AS c2 FROM t1;
DROP TABLE t1;
SET time_zone=DEFAULT;
--echo #
--echo # End of 10.5 tests
--echo #
......@@ -5698,8 +5698,10 @@ my_time_t Field_timestampf::get_timestamp(const uchar *pos,
bool Field_timestampf::val_native(Native *to)
{
DBUG_ASSERT(marked_for_read());
char zero[8]= "\0\0\0\0\0\0\0";
DBUG_ASSERT(pack_length () <= sizeof(zero));
// Check if it's '0000-00-00 00:00:00' rather than a real timestamp
if (ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0)
if (!memcmp(ptr, zero, pack_length()))
{
to->length(0);
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment