Commit bf2a2444 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-22854 Garbage returned with SELECT CASE..DEFAULT(timestamp_field_with_now_as_default)

Item_default_value did not override val_native(), so the inherited
Item_field::val_native() was called. As a result Item_default_value::calculate()
was not called and Item_field::val_native() was called on a Field
with a non-initialized ptr.

Implementing Item_default_value::val_native() properly.
parent 86c50a25
...@@ -1308,5 +1308,17 @@ Warnings: ...@@ -1308,5 +1308,17 @@ Warnings:
Warning 1292 Incorrect datetime value: '2010-00-01 00:00:00' Warning 1292 Incorrect datetime value: '2010-00-01 00:00:00'
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-22854 Garbage returned with SELECT CASE..DEFAULT(timestamp_field_with_now_as_default)
#
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30.456789');
CREATE TABLE t1 (a TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP);
INSERT INTO t1 VALUES ('2019-02-23 11:31:04'),('2023-02-09 00:00:00');
SELECT CASE WHEN a THEN DEFAULT(a) END FROM t1;
CASE WHEN a THEN DEFAULT(a) END
2001-01-01 10:20:30.456
2001-01-01 10:20:30.456
DROP TABLE t1;
SET timestamp=DEFAULT;
#
# End of 10.4 tests # End of 10.4 tests
# #
...@@ -863,6 +863,18 @@ SELECT * FROM t1 WHERE c='2010-00-01 00:00:00'; ...@@ -863,6 +863,18 @@ SELECT * FROM t1 WHERE c='2010-00-01 00:00:00';
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-22854 Garbage returned with SELECT CASE..DEFAULT(timestamp_field_with_now_as_default)
--echo #
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30.456789');
CREATE TABLE t1 (a TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP);
INSERT INTO t1 VALUES ('2019-02-23 11:31:04'),('2023-02-09 00:00:00');
SELECT CASE WHEN a THEN DEFAULT(a) END FROM t1;
DROP TABLE t1;
SET timestamp=DEFAULT;
--echo # --echo #
--echo # End of 10.4 tests --echo # End of 10.4 tests
--echo # --echo #
...@@ -9338,6 +9338,12 @@ void Item_default_value::calculate() ...@@ -9338,6 +9338,12 @@ void Item_default_value::calculate()
DEBUG_SYNC(field->table->in_use, "after_Item_default_value_calculate"); DEBUG_SYNC(field->table->in_use, "after_Item_default_value_calculate");
} }
bool Item_default_value::val_native(THD *thd, Native *to)
{
calculate();
return Item_field::val_native(thd, to);
}
String *Item_default_value::val_str(String *str) String *Item_default_value::val_str(String *str)
{ {
calculate(); calculate();
......
...@@ -6320,6 +6320,7 @@ class Item_default_value : public Item_field ...@@ -6320,6 +6320,7 @@ class Item_default_value : public Item_field
longlong val_int(); longlong val_int();
my_decimal *val_decimal(my_decimal *decimal_value); my_decimal *val_decimal(my_decimal *decimal_value);
bool get_date(THD *thd, MYSQL_TIME *ltime,date_mode_t fuzzydate); bool get_date(THD *thd, MYSQL_TIME *ltime,date_mode_t fuzzydate);
bool val_native(THD *thd, Native *to);
bool send(Protocol *protocol, st_value *buffer); bool send(Protocol *protocol, st_value *buffer);
int save_in_field(Field *field_arg, bool no_conversions); int save_in_field(Field *field_arg, bool no_conversions);
bool save_in_param(THD *thd, Item_param *param) bool save_in_param(THD *thd, Item_param *param)
......
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