Commit 6164157b authored by Jan Lindström's avatar Jan Lindström

MDEV-7254: Assigned expression is evaluated twice when updating

column TIMESTAMP NOT NULL
      
Analysis: Problem was that value->is_null() function is called
even when user had explicitly set the value for timestamp
field. Calling this function had the side effect that
expression was evaluated twice.
      
Fix: (by Sergei Golubchik) check instead value->null_value.
parent 813af4cd
...@@ -645,3 +645,47 @@ MAX(dt) = '2011-01-06 12:34:30' ...@@ -645,3 +645,47 @@ MAX(dt) = '2011-01-06 12:34:30'
1 1
DROP TABLE t1; DROP TABLE t1;
End of 5.5 tests End of 5.5 tests
#
# MDEV-7254: Assigned expression is evaluated twice when updating column TIMESTAMP NOT NULL
#
create table t1(value timestamp not null);
set @a:=0;
create function f1 () returns timestamp
begin
set @a = @a + 1;
return NULL;
end//
set timestamp=12340;
insert t1 values (f1());
select @a, value from t1;
@a value
1 1970-01-01 05:25:40
set timestamp=12350;
update t1 set value = f1();
select @a, value from t1;
@a value
2 1970-01-01 05:25:50
drop table t1;
drop function f1;
set timestamp=0;
create table t1(value timestamp null);
set @a:=0;
create function f1 () returns timestamp
begin
set @a = @a + 1;
return NULL;
end//
set timestamp=12340;
insert t1 values (f1());
select @a, value from t1;
@a value
1 NULL
set timestamp=12350;
update t1 set value = f1();
select @a, value from t1;
@a value
2 NULL
drop table t1;
drop function f1;
set timestamp=0;
End of 10.0 tests
...@@ -446,3 +446,48 @@ SELECT MAX(dt) = '2011-01-06 12:34:30' FROM t1; ...@@ -446,3 +446,48 @@ SELECT MAX(dt) = '2011-01-06 12:34:30' FROM t1;
DROP TABLE t1; DROP TABLE t1;
--echo End of 5.5 tests --echo End of 5.5 tests
--echo #
--echo # MDEV-7254: Assigned expression is evaluated twice when updating column TIMESTAMP NOT NULL
--echo #
create table t1(value timestamp not null);
set @a:=0;
delimiter //;
create function f1 () returns timestamp
begin
set @a = @a + 1;
return NULL;
end//
delimiter ;//
set timestamp=12340;
insert t1 values (f1());
select @a, value from t1;
set timestamp=12350;
update t1 set value = f1();
select @a, value from t1;
drop table t1;
drop function f1;
set timestamp=0;
# Verify no regressions to TIMESTAMP NULL
create table t1(value timestamp null);
set @a:=0;
delimiter //;
create function f1 () returns timestamp
begin
set @a = @a + 1;
return NULL;
end//
delimiter ;//
set timestamp=12340;
insert t1 values (f1());
select @a, value from t1;
set timestamp=12350;
update t1 set value = f1();
select @a, value from t1;
drop table t1;
drop function f1;
set timestamp=0;
--echo End of 10.0 tests
...@@ -4899,7 +4899,7 @@ void Field_timestamp::set_explicit_default(Item *value) ...@@ -4899,7 +4899,7 @@ void Field_timestamp::set_explicit_default(Item *value)
{ {
if (((value->type() == Item::DEFAULT_VALUE_ITEM && if (((value->type() == Item::DEFAULT_VALUE_ITEM &&
!((Item_default_value*)value)->arg) || !((Item_default_value*)value)->arg) ||
(!maybe_null() && value->is_null()))) (!maybe_null() && value->null_value)))
return; return;
set_has_explicit_value(); set_has_explicit_value();
} }
......
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