Commit c754cc84 authored by Ramil Kalimullin's avatar Ramil Kalimullin

Manual merge.

parents e545d470 0781a302
...@@ -629,21 +629,21 @@ SELECT DISTINCT @v5:= fruit_id, @v6:= fruit_name INTO @v7, @v8 FROM t1 WHERE ...@@ -629,21 +629,21 @@ SELECT DISTINCT @v5:= fruit_id, @v6:= fruit_name INTO @v7, @v8 FROM t1 WHERE
fruit_name = 'APPLE'; fruit_name = 'APPLE';
SELECT @v5, @v6, @v7, @v8; SELECT @v5, @v6, @v7, @v8;
@v5 @v6 @v7 @v8 @v5 @v6 @v7 @v8
3 PEAR 3 PEAR 2 APPLE 2 APPLE
SELECT DISTINCT @v5 + fruit_id, CONCAT(@v6, fruit_name) INTO @v9, @v10 FROM t1 SELECT DISTINCT @v5 + fruit_id, CONCAT(@v6, fruit_name) INTO @v9, @v10 FROM t1
WHERE fruit_name = 'APPLE'; WHERE fruit_name = 'APPLE';
SELECT @v5, @v6, @v7, @v8, @v9, @v10; SELECT @v5, @v6, @v7, @v8, @v9, @v10;
@v5 @v6 @v7 @v8 @v9 @v10 @v5 @v6 @v7 @v8 @v9 @v10
3 PEAR 3 PEAR 5 PEARAPPLE 2 APPLE 2 APPLE 4 APPLEAPPLE
SELECT DISTINCT @v11:= @v5 + fruit_id, @v12:= CONCAT(@v6, fruit_name) INTO SELECT DISTINCT @v11:= @v5 + fruit_id, @v12:= CONCAT(@v6, fruit_name) INTO
@v13, @v14 FROM t1 WHERE fruit_name = 'APPLE'; @v13, @v14 FROM t1 WHERE fruit_name = 'APPLE';
SELECT @v11, @v12, @v13, @v14; SELECT @v11, @v12, @v13, @v14;
@v11 @v12 @v13 @v14 @v11 @v12 @v13 @v14
6 PEARPEAR 6 PEARPEAR 4 APPLEAPPLE 4 APPLEAPPLE
SELECT DISTINCT @v13, @v14 INTO @v15, @v16 FROM t1 WHERE fruit_name = 'APPLE'; SELECT DISTINCT @v13, @v14 INTO @v15, @v16 FROM t1 WHERE fruit_name = 'APPLE';
SELECT @v15, @v16; SELECT @v15, @v16;
@v15 @v16 @v15 @v16
6 PEARPEAR 4 APPLEAPPLE
SELECT DISTINCT 2 + 2, 'Bob' INTO @v17, @v18 FROM t1 WHERE fruit_name = SELECT DISTINCT 2 + 2, 'Bob' INTO @v17, @v18 FROM t1 WHERE fruit_name =
'APPLE'; 'APPLE';
SELECT @v17, @v18; SELECT @v17, @v18;
......
...@@ -399,6 +399,17 @@ select @lastid != id, @lastid, @lastid := id from t1; ...@@ -399,6 +399,17 @@ select @lastid != id, @lastid, @lastid := id from t1;
0 3 3 0 3 3
1 3 4 1 3 4
drop table t1; drop table t1;
CREATE TABLE t1(a INT, b INT);
INSERT INTO t1 VALUES (0, 0), (2, 1), (2, 3), (1, 1), (30, 20);
SELECT a, b INTO @a, @b FROM t1 WHERE a=2 AND b=3 GROUP BY a, b;
SELECT @a, @b;
@a @b
2 3
SELECT a, b FROM t1 WHERE a=2 AND b=3 GROUP BY a, b;
a b
2 3
DROP TABLE t1;
End of 5.0 tests
CREATE TABLE t1 (i INT); CREATE TABLE t1 (i INT);
CREATE TRIGGER t_after_insert AFTER INSERT ON t1 FOR EACH ROW SET @bug42188 = 10; CREATE TRIGGER t_after_insert AFTER INSERT ON t1 FOR EACH ROW SET @bug42188 = 10;
INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (1);
......
...@@ -285,6 +285,18 @@ set @lastid=-1; ...@@ -285,6 +285,18 @@ set @lastid=-1;
select @lastid != id, @lastid, @lastid := id from t1; select @lastid != id, @lastid, @lastid := id from t1;
drop table t1; drop table t1;
#
# Bug#42009: SELECT into variable gives different results to direct SELECT
#
CREATE TABLE t1(a INT, b INT);
INSERT INTO t1 VALUES (0, 0), (2, 1), (2, 3), (1, 1), (30, 20);
SELECT a, b INTO @a, @b FROM t1 WHERE a=2 AND b=3 GROUP BY a, b;
SELECT @a, @b;
SELECT a, b FROM t1 WHERE a=2 AND b=3 GROUP BY a, b;
DROP TABLE t1;
--echo End of 5.0 tests
# #
# Bug#42188: crash and/or memory corruption with user variables in trigger # Bug#42188: crash and/or memory corruption with user variables in trigger
# #
......
...@@ -4177,6 +4177,41 @@ Item_func_set_user_var::check(bool use_result_field) ...@@ -4177,6 +4177,41 @@ Item_func_set_user_var::check(bool use_result_field)
} }
/**
@brief Evaluate and store item's result.
This function is invoked on "SELECT ... INTO @var ...".
@param item An item to get value from.
*/
void Item_func_set_user_var::save_item_result(Item *item)
{
DBUG_ENTER("Item_func_set_user_var::save_item_result");
switch (cached_result_type) {
case REAL_RESULT:
save_result.vreal= item->val_result();
break;
case INT_RESULT:
save_result.vint= item->val_int_result();
unsigned_flag= item->unsigned_flag;
break;
case STRING_RESULT:
save_result.vstr= item->str_result(&value);
break;
case DECIMAL_RESULT:
save_result.vdec= item->val_decimal_result(&decimal_buff);
break;
case ROW_RESULT:
default:
// Should never happen
DBUG_ASSERT(0);
break;
}
DBUG_VOID_RETURN;
}
/** /**
This functions is invoked on This functions is invoked on
SET \@variable or \@variable:= expression. SET \@variable or \@variable:= expression.
......
...@@ -1341,6 +1341,7 @@ public: ...@@ -1341,6 +1341,7 @@ public:
bool send(Protocol *protocol, String *str_arg); bool send(Protocol *protocol, String *str_arg);
void make_field(Send_field *tmp_field); void make_field(Send_field *tmp_field);
bool check(bool use_result_field); bool check(bool use_result_field);
void save_item_result(Item *item);
bool update(); bool update();
enum Item_result result_type () const { return cached_result_type; } enum Item_result result_type () const { return cached_result_type; }
bool fix_fields(THD *thd, Item **ref); bool fix_fields(THD *thd, Item **ref);
......
...@@ -2599,7 +2599,7 @@ bool select_dumpvar::send_data(List<Item> &items) ...@@ -2599,7 +2599,7 @@ bool select_dumpvar::send_data(List<Item> &items)
{ {
Item_func_set_user_var *suv= new Item_func_set_user_var(mv->s, item); Item_func_set_user_var *suv= new Item_func_set_user_var(mv->s, item);
suv->fix_fields(thd, 0); suv->fix_fields(thd, 0);
suv->check(0); suv->save_item_result(item);
suv->update(); suv->update();
} }
} }
......
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