mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-33790 Incorrect DEFAULT expression evaluated in UPDATE
The problem was that Item_default_value::associate_with_target_field assigned passed as argument field as an argument which changed argument in case of default() call with certain field (i.e. deault(field)). There is no way to get wrong field in constructor so we will not reassign parameter.
This commit is contained in:
@ -3145,3 +3145,28 @@ a b c
|
||||
2 2010-10-10 10:10:10 x
|
||||
drop table t1;
|
||||
set timestamp=default;
|
||||
#
|
||||
# MDEV-33790: Incorrect DEFAULT expression evaluated in UPDATE
|
||||
#
|
||||
create table t1 (
|
||||
a int,
|
||||
b timestamp default '2010-10-10 10:10:10' on update now(),
|
||||
c varchar(100) default 'x');
|
||||
create table t2 (a int primary key);
|
||||
insert t1 (a) values (1),(2);
|
||||
insert t2 (a) values (1),(2);
|
||||
select * from t1;
|
||||
a b c
|
||||
1 2010-10-10 10:10:10 x
|
||||
2 2010-10-10 10:10:10 x
|
||||
set timestamp=unix_timestamp('2011-11-11 11-11-11');
|
||||
update t1,t2 set b=default, c=default(b) where t1.a=1 and t1.a= t2.a;
|
||||
select * from t1;
|
||||
a b c
|
||||
1 2010-10-10 10:10:10 2010-10-10 10:10:10
|
||||
2 2010-10-10 10:10:10 x
|
||||
drop table t1, t2;
|
||||
set timestamp=default;
|
||||
#
|
||||
# End of 10.4 tests
|
||||
#
|
||||
|
@ -67,3 +67,26 @@ update t1 set b=default, c=default(b) where a=1;
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
set timestamp=default;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-33790: Incorrect DEFAULT expression evaluated in UPDATE
|
||||
--echo #
|
||||
|
||||
create table t1 (
|
||||
a int,
|
||||
b timestamp default '2010-10-10 10:10:10' on update now(),
|
||||
c varchar(100) default 'x');
|
||||
create table t2 (a int primary key);
|
||||
insert t1 (a) values (1),(2);
|
||||
insert t2 (a) values (1),(2);
|
||||
|
||||
select * from t1;
|
||||
set timestamp=unix_timestamp('2011-11-11 11-11-11');
|
||||
update t1,t2 set b=default, c=default(b) where t1.a=1 and t1.a= t2.a;
|
||||
select * from t1;
|
||||
drop table t1, t2;
|
||||
set timestamp=default;
|
||||
|
||||
--echo #
|
||||
--echo # End of 10.4 tests
|
||||
--echo #
|
||||
|
10
sql/item.cc
10
sql/item.cc
@ -9748,11 +9748,15 @@ Item *Item_default_value::transform(THD *thd, Item_transformer transformer,
|
||||
}
|
||||
|
||||
|
||||
bool Item_default_value::associate_with_target_field(THD *thd,
|
||||
Item_field *field)
|
||||
bool Item_default_value::
|
||||
associate_with_target_field(THD *thd,
|
||||
Item_field *field __attribute__((unused)))
|
||||
{
|
||||
m_associated= true;
|
||||
arg= field;
|
||||
/*
|
||||
arg set correctly in constructor (can also differ from field if
|
||||
it is function with an argument)
|
||||
*/
|
||||
return tie_field(thd);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user