Skip to content

Commit c99f976

Browse files
committed
MDEV-19166 Assertion `!is_zero_datetime()' failed in Timestamp_or_zero_datetime::tv
1 parent e244652 commit c99f976

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

mysql-test/main/type_temporal_innodb.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,16 @@ CREATE TABLE tbl SELECT * FROM t1 WHERE t1.c1 = (SELECT c2 FROM t2 WHERE pk = 6)
172172
ERROR 22007: Truncated incorrect datetime value: '0000-00-00 00:00:00'
173173
DROP TABLE t1,t2;
174174
SET sql_mode=DEFAULT;
175+
#
176+
# MDEV-19166 Assertion `!is_zero_datetime()' failed in Timestamp_or_zero_datetime::tv
177+
#
178+
CREATE TABLE t1 (f TIMESTAMP DEFAULT 0) ENGINE=InnoDB;
179+
INSERT INTO t1 VALUES ('2024-02-29');
180+
SELECT * FROM t1 WHERE SUBSTR(1 FROM BIT_LENGTH(f) FOR DEFAULT(f));
181+
f
182+
Warnings:
183+
Warning 1292 Truncated incorrect INTEGER value: ''
184+
DROP TABLE t1;
185+
#
186+
# End of 10.4 tests
187+
#

mysql-test/main/type_temporal_innodb.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,18 @@ CREATE TABLE tbl SELECT * FROM t1 WHERE t1.c1 = (SELECT c2 FROM t2 WHERE pk = 6)
8181
# ^^^ there is no column c2 in table t2
8282
DROP TABLE t1,t2;
8383
SET sql_mode=DEFAULT;
84+
85+
86+
--echo #
87+
--echo # MDEV-19166 Assertion `!is_zero_datetime()' failed in Timestamp_or_zero_datetime::tv
88+
--echo #
89+
90+
CREATE TABLE t1 (f TIMESTAMP DEFAULT 0) ENGINE=InnoDB;
91+
INSERT INTO t1 VALUES ('2024-02-29');
92+
SELECT * FROM t1 WHERE SUBSTR(1 FROM BIT_LENGTH(f) FOR DEFAULT(f));
93+
DROP TABLE t1;
94+
95+
96+
--echo #
97+
--echo # End of 10.4 tests
98+
--echo #

sql/item.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9909,7 +9909,7 @@ Datetime Item_cache_timestamp::to_datetime(THD *thd)
99099909
null_value= true;
99109910
return Datetime();
99119911
}
9912-
return Datetime(thd, Timestamp_or_zero_datetime(m_native).tv());
9912+
return m_native.to_datetime(thd);
99139913
}
99149914

99159915

sql/item_timefunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ bool Item_func_unix_timestamp::get_timestamp_value(my_time_t *seconds,
12201220
Timestamp_or_zero_datetime_native_null native(current_thd, args[0], true);
12211221
if ((null_value= native.is_null() || native.is_zero_datetime()))
12221222
return true;
1223-
Timestamp_or_zero_datetime tm(native);
1223+
Timestamp tm(native);
12241224
*seconds= tm.tv().tv_sec;
12251225
*second_part= tm.tv().tv_usec;
12261226
return false;

sql/sql_type.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,6 +2377,10 @@ class Timestamp: protected Timeval
23772377
}
23782378
bool to_TIME(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) const;
23792379
bool to_native(Native *to, uint decimals) const;
2380+
Datetime to_datetime(THD *thd) const
2381+
{
2382+
return Datetime(thd, *this);
2383+
}
23802384
long fraction_remainder(uint dec) const
23812385
{
23822386
return my_time_fraction_remainder(tv_usec, dec);
@@ -2417,7 +2421,7 @@ class Timestamp: protected Timeval
24172421
- real TIMESTAMP (seconds and microseconds since epoch), or
24182422
- zero datetime '0000-00-00 00:00:00.000000'
24192423
*/
2420-
class Timestamp_or_zero_datetime: public Timestamp
2424+
class Timestamp_or_zero_datetime: protected Timestamp
24212425
{
24222426
bool m_is_zero_datetime;
24232427
public:
@@ -2434,14 +2438,11 @@ class Timestamp_or_zero_datetime: public Timestamp
24342438
Timestamp_or_zero_datetime(THD *thd, const MYSQL_TIME *ltime, uint *err_code);
24352439
Datetime to_datetime(THD *thd) const
24362440
{
2437-
return Datetime(thd, *this);
2441+
if (is_zero_datetime())
2442+
return Datetime();
2443+
return Timestamp::to_datetime(thd);
24382444
}
24392445
bool is_zero_datetime() const { return m_is_zero_datetime; }
2440-
const struct timeval &tv() const
2441-
{
2442-
DBUG_ASSERT(!is_zero_datetime());
2443-
return Timestamp::tv();
2444-
}
24452446
void trunc(uint decimals)
24462447
{
24472448
if (!is_zero_datetime())
@@ -2487,7 +2488,7 @@ class Timestamp_or_zero_datetime_native:
24872488
{
24882489
return is_zero_datetime() ?
24892490
Datetime() :
2490-
Datetime(thd, Timestamp_or_zero_datetime(*this).tv());
2491+
Datetime(thd, Timestamp(*this).tv());
24912492
}
24922493
bool is_zero_datetime() const
24932494
{

0 commit comments

Comments
 (0)